1 | import { Module } from './module';
|
2 | import { register, resolve, onResolve } from './global-injector'
|
3 | import * as jsonrpc from '@akala/json-rpc-ws'
|
4 | import { chain } from './chain'
|
5 | export { Module };
|
6 | export * from './promiseHelpers';
|
7 | export { each as eachAsync, NextFunction } from './eachAsync';
|
8 | export { each, grep } from './each';
|
9 | export * from './router';
|
10 | import log from 'debug';
|
11 |
|
12 | export function noop() { };
|
13 |
|
14 | export function extend<T, U>(target: T, other: U): T & U;
|
15 | export function extend<T, U, V>(target: T, other1: U, other2: V): T & U & V;
|
16 | export function extend<T, U, V, W>(target: T, other1: U, other2: V, other3: W): T & U & V & W;
|
17 | export function extend<T, U, V, W, X>(target: T, other1: U, other2: V, other3: W, other43: X): T & U & V & W & X;
|
18 | export function extend(target: any, ...args)
|
19 | {
|
20 | args.forEach(function (arg)
|
21 | {
|
22 | if (typeof (arg) == 'object' && arg)
|
23 | Object.keys(arg).forEach(function (key)
|
24 | {
|
25 | var a = typeof (target[key]);
|
26 | switch (typeof (target[key]))
|
27 | {
|
28 | case 'object':
|
29 | extend(target[key], arg[key]);
|
30 | break;
|
31 | default:
|
32 | target[key] = arg[key];
|
33 | break;
|
34 | }
|
35 | });
|
36 | });
|
37 | return target;
|
38 | }
|
39 |
|
40 | export { log }
|
41 |
|
42 | export function module(name: string, ...dependencies: string[]): Module
|
43 | export function module(name: string, ...dependencies: Module[]): Module
|
44 | export function module(name: string, ...dependencies: (Module | string)[]): Module
|
45 | {
|
46 | if (dependencies && dependencies.length)
|
47 | return new Module(name, dependencies.map(m => typeof (m) == 'string' ? module(m) : m));
|
48 | return new Module(name);
|
49 | }
|
50 |
|
51 | export interface Translator
|
52 | {
|
53 | (key: string): string;
|
54 | (format: string, ...parameters: any[]): string;
|
55 | }
|
56 |
|
57 | export async function createSocket(namespace: string)
|
58 | {
|
59 | var resolveUrl = await onResolve<(url: string) => string>('$resolveUrl');
|
60 | if (!resolveUrl)
|
61 | throw new Error('no url resolver could be found');
|
62 | return await new Promise<jsonrpc.SocketAdapter>((resolve, reject) =>
|
63 | {
|
64 | var socket = jsonrpc.ws.connect(resolveUrl(namespace));
|
65 |
|
66 | socket.once('open', function ()
|
67 | {
|
68 | resolve(socket);
|
69 | });
|
70 |
|
71 | socket.once('error', function (err)
|
72 | {
|
73 | reject(err);
|
74 | });
|
75 | });
|
76 | }
|
77 |
|
\ | No newline at end of file |