@akala/pm 3.4.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +1 -6
- package/commands.json +137 -88
- package/dist/commands/bridge.js +2 -2
- package/dist/commands/bridge.js.map +1 -1
- package/dist/commands/proxy.d.ts +3 -0
- package/dist/commands/proxy.js +14 -0
- package/dist/commands/proxy.js.map +1 -0
- package/dist/container.d.ts +16 -12
- package/dist/fork.js +1 -2
- package/dist/fork.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +28 -42
- package/dist/index.js.map +1 -1
- package/dist/sidecar.d.ts +4 -0
- package/dist/sidecar.js +47 -0
- package/dist/sidecar.js.map +1 -0
- package/dist/state.d.ts +1 -1
- package/package.json +3 -3
- package/src/commands/bridge.json +18 -0
- package/src/commands/bridge.ts +2 -2
- package/src/commands/proxy.json +15 -0
- package/src/commands/proxy.ts +14 -0
- package/src/container.ts +16 -12
- package/src/fork.ts +1 -2
- package/src/index.ts +6 -51
- package/src/sidecar.ts +54 -0
- package/src/state.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgJ;AAChJ,6BAA6B;AAC7B,sCAAqC;AAUrC,MAAa,aAAc,SAAQ,KAAK;IAIA;IAFpB,IAAI,GAAG,UAAU,CAAC;IAElC,YAAY,OAAe,EAAS,EAAW;QAE3C,KAAK,CAAC,OAAO,CAAC,CAAC;QAFiB,OAAE,GAAF,EAAE,CAAS;IAG/C,CAAC;IAEM,MAAM;QAET,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,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AE,IAAI,CAAuB,CAAC;QAEtF,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAA2B,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACpR,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AARD,0BAQC;AAEY,QAAA,aAAa,GAA4B,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAkBzF,2DAA4C;AAGnC,wBAHF,cAAa,CAGE;AAFtB,qDAAsD;AACpC,2BADX,iBAAgB,CACW;AAAzB,wFADkB,iBAAO,OAClB"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { ConnectionPreference } from "@akala/commands";
|
2
|
+
import { SideCarConnectionPreference, Sidecar } from "./index";
|
3
|
+
export default function (options?: Omit<ConnectionPreference, 'metadata'> | SideCarConnectionPreference | Omit<ConnectionPreference, 'metadata'> & SideCarConnectionPreference, noCache?: boolean): Sidecar;
|
4
|
+
export declare function sidecar(options?: Omit<ConnectionPreference, 'metadata'> | SideCarConnectionPreference | Omit<ConnectionPreference, 'metadata'> & SideCarConnectionPreference, noCache?: boolean): Sidecar;
|
package/dist/sidecar.js
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.sidecar = void 0;
|
4
|
+
const commands_1 = require("@akala/commands");
|
5
|
+
const index_1 = require("./index");
|
6
|
+
let instance;
|
7
|
+
function default_1(options, noCache) {
|
8
|
+
return instance || (instance = sidecar(options, noCache));
|
9
|
+
}
|
10
|
+
exports.default = default_1;
|
11
|
+
function sidecar(options, noCache) {
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
13
|
+
return new Proxy({}, {
|
14
|
+
get(target, property) {
|
15
|
+
if (typeof (property) !== 'string')
|
16
|
+
return Reflect.get(target, property);
|
17
|
+
const orders = options && options[property] && options[property].orders || index_1.defaultOrders;
|
18
|
+
if (!options)
|
19
|
+
options = {};
|
20
|
+
if (typeof options.preferRemote == 'undefined')
|
21
|
+
options.preferRemote = !process.connected;
|
22
|
+
if (noCache || typeof (target[property]) == 'undefined')
|
23
|
+
Object.defineProperty(target, property, {
|
24
|
+
value: (0, index_1.connect)(property).then(async (meta) => {
|
25
|
+
try {
|
26
|
+
const c = await (0, commands_1.connectByPreference)(await meta.connect, Object.assign({ metadata: meta.container }, options, options && options[property]), ...orders);
|
27
|
+
return c.container;
|
28
|
+
}
|
29
|
+
catch (e) {
|
30
|
+
if (e && e.statusCode == 404 || !meta.connect) {
|
31
|
+
return await (0, index_1.connect)('pm').then(async (meta) => {
|
32
|
+
const c = await (0, commands_1.connectByPreference)(await meta.connect, Object.assign({ metadata: meta.container }, options, options && options[property]), ...orders);
|
33
|
+
await c.container.dispatch('proxy', property);
|
34
|
+
(0, commands_1.registerCommands)((await c.container.dispatch('$metadata', true)).commands, c.processor, c.container);
|
35
|
+
return c.container;
|
36
|
+
});
|
37
|
+
}
|
38
|
+
throw e;
|
39
|
+
}
|
40
|
+
})
|
41
|
+
});
|
42
|
+
return target[property];
|
43
|
+
}
|
44
|
+
});
|
45
|
+
}
|
46
|
+
exports.sidecar = sidecar;
|
47
|
+
//# sourceMappingURL=sidecar.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"s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
"version": "3.5.1",
|
8
8
|
"scripts": {
|
9
9
|
"test": "echo 1",
|
10
10
|
"generate": "ac generate dist/commands commands.json",
|
@@ -20,8 +20,8 @@
|
|
20
20
|
"homepage": "https://akala.js.org/pm",
|
21
21
|
"dependencies": {
|
22
22
|
"@akala/cli": "^2.1.8",
|
23
|
-
"@akala/commands": "^3.
|
24
|
-
"@akala/config": "^1.1.
|
23
|
+
"@akala/commands": "^3.3.1",
|
24
|
+
"@akala/config": "^1.1.21",
|
25
25
|
"@akala/core": "^9.0.4",
|
26
26
|
"@akala/json-rpc-ws": "^9.5.0",
|
27
27
|
"reflect-metadata": "^0.1.13",
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://raw.githubusercontent.com/npenin/akala/master/packages/commands/command-schema.json",
|
3
|
+
"fs": {
|
4
|
+
"inject": [
|
5
|
+
"param.0",
|
6
|
+
"param.1"
|
7
|
+
]
|
8
|
+
},
|
9
|
+
"jsonrpc": {
|
10
|
+
"inject": [
|
11
|
+
"param.0",
|
12
|
+
"socket"
|
13
|
+
]
|
14
|
+
},
|
15
|
+
"": {
|
16
|
+
"inject": []
|
17
|
+
}
|
18
|
+
}
|
package/src/commands/bridge.ts
CHANGED
@@ -4,6 +4,6 @@ import State from "../state";
|
|
4
4
|
|
5
5
|
export default function (this: State, connectionId: string, socket: SocketAdapter)
|
6
6
|
{
|
7
|
-
this.
|
8
|
-
socket.pipe(this.
|
7
|
+
this.bridges[connectionId].pipe(socket);
|
8
|
+
socket.pipe(this.bridges[connectionId]);
|
9
9
|
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { ErrorWithStatus } from "@akala/cli";
|
2
|
+
import { SocketAdapter } from "@akala/json-rpc-ws";
|
3
|
+
import { randomUUID } from "crypto";
|
4
|
+
import State from "../state";
|
5
|
+
|
6
|
+
export default async function (this: State, name: string, socket: SocketAdapter)
|
7
|
+
{
|
8
|
+
var cp = this.processes[name];
|
9
|
+
if (!cp)
|
10
|
+
throw new ErrorWithStatus(404, `There is no such process with name ${name}`);
|
11
|
+
const connectionId = randomUUID();
|
12
|
+
this.bridges[connectionId] = socket;
|
13
|
+
await cp.dispatch('$bridge', connectionId);
|
14
|
+
}
|
package/src/container.ts
CHANGED
@@ -5,18 +5,20 @@ namespace commands
|
|
5
5
|
{
|
6
6
|
export interface container
|
7
7
|
{
|
8
|
-
dispatch (cmd:'connect', ...args: [Argument0<typeof import('./commands/connect').default>, Argument1<typeof import('./commands/connect').default>]): ReturnType<typeof import('./commands/connect').default>
|
9
|
-
dispatch (cmd:'config', ...args: [Argument0<typeof import('./commands/config').default>, Argument1<typeof import('./commands/config').default>]): ReturnType<typeof import('./commands/config').default>
|
10
|
-
dispatch (cmd:'install', ...args: [Argument0<typeof import('./commands/install').default>]): ReturnType<typeof import('./commands/install').default>
|
11
8
|
dispatch (cmd:'$init', ...args: [Argument1<typeof import('./commands/$init').default>]): ReturnType<typeof import('./commands/$init').default>
|
9
|
+
dispatch (cmd:'bridge', ...args: [Argument0<typeof import('./commands/bridge').default>, Argument1<typeof import('./commands/bridge').default>]): ReturnType<typeof import('./commands/bridge').default>
|
10
|
+
dispatch (cmd:'config', ...args: [Argument0<typeof import('./commands/config').default>, Argument1<typeof import('./commands/config').default>]): ReturnType<typeof import('./commands/config').default>
|
11
|
+
dispatch (cmd:'connect', ...args: [Argument0<typeof import('./commands/connect').default>, Argument1<typeof import('./commands/connect').default>]): ReturnType<typeof import('./commands/connect').default>
|
12
12
|
dispatch (cmd:'discover', ...args: [Argument0<typeof import('./commands/discover').default>, Argument1<typeof import('./commands/discover').default>]): ReturnType<typeof import('./commands/discover').default>
|
13
|
+
dispatch (cmd:'install', ...args: [Argument0<typeof import('./commands/install').default>]): ReturnType<typeof import('./commands/install').default>
|
13
14
|
dispatch (cmd:'link', ...args: [Argument0<typeof import('./commands/link').default>, Argument1<typeof import('./commands/link').default>]): ReturnType<typeof import('./commands/link').default>
|
14
|
-
dispatch (cmd:'ls', ...args: []): ReturnType<typeof import('./commands/ls').default>
|
15
|
-
dispatch (cmd:'name', ...args: [Argument0<typeof import('./commands/name').default>]): ReturnType<typeof import('./commands/name').default>
|
16
15
|
dispatch (cmd:'log', ...args: [Argument0<typeof import('./commands/log').default>]): ReturnType<typeof import('./commands/log').default>
|
17
|
-
dispatch (cmd:'
|
16
|
+
dispatch (cmd:'ls', ...args: []): ReturnType<typeof import('./commands/ls').default>
|
18
17
|
dispatch (cmd:'map', ...args: [Argument0<typeof import('./commands/map').default>, Argument1<typeof import('./commands/map').default>, Argument2<typeof import('./commands/map').default>, Argument3<typeof import('./commands/map').default>]): ReturnType<typeof import('./commands/map').default>
|
18
|
+
dispatch (cmd:'name', ...args: [Argument0<typeof import('./commands/name').default>]): ReturnType<typeof import('./commands/name').default>
|
19
|
+
dispatch (cmd:'proxy', ...args: [Argument0<typeof import('./commands/proxy').default>, Argument1<typeof import('./commands/proxy').default>]): ReturnType<typeof import('./commands/proxy').default>
|
19
20
|
dispatch (cmd:'ready', ...args: []): ReturnType<typeof import('./commands/ready').default>
|
21
|
+
dispatch (cmd:'reload-metadata', ...args: [Argument0<typeof import('./commands/reload-metadata').default>]): ReturnType<typeof import('./commands/reload-metadata').default>
|
20
22
|
dispatch (cmd:'start', ...args: [Argument1<typeof import('./commands/start').default>, Argument2<typeof import('./commands/start').default>]): ReturnType<typeof import('./commands/start').default>
|
21
23
|
dispatch (cmd:'status', ...args: [Argument0<typeof import('./commands/status').default>]): ReturnType<typeof import('./commands/status').default>
|
22
24
|
dispatch (cmd:'stop', ...args: [Argument0<typeof import('./commands/stop').default>]): ReturnType<typeof import('./commands/stop').default>
|
@@ -25,18 +27,20 @@ namespace commands
|
|
25
27
|
}
|
26
28
|
export interface proxy
|
27
29
|
{
|
28
|
-
'connect'(...args: [Argument0<typeof import('./commands/connect').default>, Argument1<typeof import('./commands/connect').default>]): ReturnType<typeof import('./commands/connect').default>
|
29
|
-
'config'(...args: [Argument0<typeof import('./commands/config').default>, Argument1<typeof import('./commands/config').default>]): ReturnType<typeof import('./commands/config').default>
|
30
|
-
'install'(...args: [Argument0<typeof import('./commands/install').default>]): ReturnType<typeof import('./commands/install').default>
|
31
30
|
'$init'(...args: [Argument1<typeof import('./commands/$init').default>]): ReturnType<typeof import('./commands/$init').default>
|
31
|
+
'bridge'(...args: [Argument0<typeof import('./commands/bridge').default>, Argument1<typeof import('./commands/bridge').default>]): ReturnType<typeof import('./commands/bridge').default>
|
32
|
+
'config'(...args: [Argument0<typeof import('./commands/config').default>, Argument1<typeof import('./commands/config').default>]): ReturnType<typeof import('./commands/config').default>
|
33
|
+
'connect'(...args: [Argument0<typeof import('./commands/connect').default>, Argument1<typeof import('./commands/connect').default>]): ReturnType<typeof import('./commands/connect').default>
|
32
34
|
'discover'(...args: [Argument0<typeof import('./commands/discover').default>, Argument1<typeof import('./commands/discover').default>]): ReturnType<typeof import('./commands/discover').default>
|
35
|
+
'install'(...args: [Argument0<typeof import('./commands/install').default>]): ReturnType<typeof import('./commands/install').default>
|
33
36
|
'link'(...args: [Argument0<typeof import('./commands/link').default>, Argument1<typeof import('./commands/link').default>]): ReturnType<typeof import('./commands/link').default>
|
34
|
-
'ls'(...args: []): ReturnType<typeof import('./commands/ls').default>
|
35
|
-
'name'(...args: [Argument0<typeof import('./commands/name').default>]): ReturnType<typeof import('./commands/name').default>
|
36
37
|
'log'(...args: [Argument0<typeof import('./commands/log').default>]): ReturnType<typeof import('./commands/log').default>
|
37
|
-
'
|
38
|
+
'ls'(...args: []): ReturnType<typeof import('./commands/ls').default>
|
38
39
|
'map'(...args: [Argument0<typeof import('./commands/map').default>, Argument1<typeof import('./commands/map').default>, Argument2<typeof import('./commands/map').default>, Argument3<typeof import('./commands/map').default>]): ReturnType<typeof import('./commands/map').default>
|
40
|
+
'name'(...args: [Argument0<typeof import('./commands/name').default>]): ReturnType<typeof import('./commands/name').default>
|
41
|
+
'proxy'(...args: [Argument0<typeof import('./commands/proxy').default>, Argument1<typeof import('./commands/proxy').default>]): ReturnType<typeof import('./commands/proxy').default>
|
39
42
|
'ready'(...args: []): ReturnType<typeof import('./commands/ready').default>
|
43
|
+
'reload-metadata'(...args: [Argument0<typeof import('./commands/reload-metadata').default>]): ReturnType<typeof import('./commands/reload-metadata').default>
|
40
44
|
'start'(...args: [Argument1<typeof import('./commands/start').default>, Argument2<typeof import('./commands/start').default>]): ReturnType<typeof import('./commands/start').default>
|
41
45
|
'status'(...args: [Argument0<typeof import('./commands/status').default>]): ReturnType<typeof import('./commands/status').default>
|
42
46
|
'stop'(...args: [Argument0<typeof import('./commands/stop').default>]): ReturnType<typeof import('./commands/stop').default>
|
package/src/fork.ts
CHANGED
@@ -9,8 +9,7 @@ import { Socket } from 'net';
|
|
9
9
|
import { logger, Logger, module as coreModule } from '@akala/core';
|
10
10
|
import program, { buildCliContextFromProcess, NamespaceMiddleware } from '@akala/cli';
|
11
11
|
import { Stats } from 'fs';
|
12
|
-
import { registerCommands, SelfDefinedCommand } from '@akala/commands';
|
13
|
-
import { parseMetadata } from '@akala/commands/src/serve-metadata';
|
12
|
+
import { registerCommands, SelfDefinedCommand, parseMetadata } from '@akala/commands';
|
14
13
|
|
15
14
|
var isPm = false;
|
16
15
|
|
package/src/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Container, Metadata, NetSocketAdapter, Processors, registerCommands, ServeMetadata, ConnectionPreference, Cli } from "@akala/commands";
|
2
2
|
import { Socket } from "net";
|
3
3
|
import { module } from "@akala/core";
|
4
4
|
|
@@ -54,57 +54,9 @@ export function connect(name: string): Promise<{ connect: Promise<ServeMetadata>
|
|
54
54
|
})();
|
55
55
|
}
|
56
56
|
|
57
|
-
const defaultOrders: (keyof ServeMetadata)[] = ['ssocket', 'socket', 'wss', 'ws'];
|
57
|
+
export const defaultOrders: (keyof ServeMetadata)[] = ['ssocket', 'socket', 'wss', 'ws'];
|
58
58
|
|
59
|
-
type SideCarConnectionPreference = { [key in keyof SidecarMap]?: Partial<ConnectionPreference> & { orders?: (keyof ServeMetadata)[] } };
|
60
|
-
|
61
|
-
export function sidecar(options?: Omit<ConnectionPreference, 'metadata'> | SideCarConnectionPreference | Omit<ConnectionPreference, 'metadata'> & SideCarConnectionPreference, noCache?: boolean): Sidecar
|
62
|
-
{
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
64
|
-
return new Proxy<Sidecar>({} as any, {
|
65
|
-
get(target, property)
|
66
|
-
{
|
67
|
-
if (typeof (property) !== 'string')
|
68
|
-
return Reflect.get(target, property);
|
69
|
-
|
70
|
-
const orders = options && options[property] && options[property].orders || defaultOrders;
|
71
|
-
if (!options)
|
72
|
-
options = {};
|
73
|
-
if (typeof options.preferRemote == 'undefined')
|
74
|
-
options.preferRemote = !process.connected;
|
75
|
-
if (noCache || typeof (target[property]) == 'undefined')
|
76
|
-
Object.defineProperty(target, property, {
|
77
|
-
value: connect(property).then(async meta =>
|
78
|
-
{
|
79
|
-
try
|
80
|
-
{
|
81
|
-
const c = await connectByPreference(await meta.connect, Object.assign({ metadata: meta.container }, options, options && options[property]), ...orders);
|
82
|
-
return c.container;
|
83
|
-
}
|
84
|
-
catch (e)
|
85
|
-
{
|
86
|
-
if (e && e.statusCode == 404 || !meta.connect)
|
87
|
-
{
|
88
|
-
var c = new Container(meta.container.name, null, module('@akala/pm').resolve('container').processor);
|
89
|
-
c.processor.useMiddleware(0, {
|
90
|
-
handle(origin, cmd, param)
|
91
|
-
{
|
92
|
-
if (cmd.name.startsWith(meta.container.name + '.'))
|
93
|
-
return undefined;
|
94
|
-
return c.processor.handle(origin, Object.assign({}, cmd, { name: meta.container.name + '.' + cmd.name }), param);
|
95
|
-
}
|
96
|
-
});
|
97
|
-
meta.container.commands.forEach(cmd => c.register(cmd));
|
98
|
-
return c;
|
99
|
-
}
|
100
|
-
throw e;
|
101
|
-
}
|
102
|
-
})
|
103
|
-
});
|
104
|
-
return target[property];
|
105
|
-
}
|
106
|
-
});
|
107
|
-
}
|
59
|
+
export type SideCarConnectionPreference = { [key in keyof SidecarMap]?: Partial<ConnectionPreference> & { orders?: (keyof ServeMetadata)[] } };
|
108
60
|
|
109
61
|
export interface ContainerLite
|
110
62
|
{
|
@@ -119,5 +71,8 @@ export interface SidecarMap
|
|
119
71
|
pm: pmContainer
|
120
72
|
}
|
121
73
|
|
74
|
+
|
122
75
|
import getRandomName from './commands/name';
|
76
|
+
import sidecarSingleton, { sidecar } from "./sidecar";
|
77
|
+
export { sidecar, sidecarSingleton };
|
123
78
|
export { getRandomName };
|
package/src/sidecar.ts
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
import { connectByPreference, Container, ConnectionPreference, registerCommands } from "@akala/commands";
|
2
|
+
import { module } from "@akala/core";
|
3
|
+
import { SideCarConnectionPreference, Sidecar, defaultOrders, connect } from "./index";
|
4
|
+
|
5
|
+
let instance: Sidecar;
|
6
|
+
|
7
|
+
export default function (options?: Omit<ConnectionPreference, 'metadata'> | SideCarConnectionPreference | Omit<ConnectionPreference, 'metadata'> & SideCarConnectionPreference, noCache?: boolean): Sidecar
|
8
|
+
{
|
9
|
+
return instance || (instance = sidecar(options, noCache));
|
10
|
+
}
|
11
|
+
|
12
|
+
export function sidecar(options?: Omit<ConnectionPreference, 'metadata'> | SideCarConnectionPreference | Omit<ConnectionPreference, 'metadata'> & SideCarConnectionPreference, noCache?: boolean): Sidecar
|
13
|
+
{
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
15
|
+
return new Proxy<Sidecar>({} as any, {
|
16
|
+
get(target, property)
|
17
|
+
{
|
18
|
+
if (typeof (property) !== 'string')
|
19
|
+
return Reflect.get(target, property);
|
20
|
+
|
21
|
+
const orders = options && options[property] && options[property].orders || defaultOrders;
|
22
|
+
if (!options)
|
23
|
+
options = {};
|
24
|
+
if (typeof options.preferRemote == 'undefined')
|
25
|
+
options.preferRemote = !process.connected;
|
26
|
+
if (noCache || typeof (target[property]) == 'undefined')
|
27
|
+
Object.defineProperty(target, property, {
|
28
|
+
value: connect(property).then(async (meta) =>
|
29
|
+
{
|
30
|
+
try
|
31
|
+
{
|
32
|
+
const c = await connectByPreference(await meta.connect, Object.assign({ metadata: meta.container }, options, options && options[property]), ...orders);
|
33
|
+
return c.container;
|
34
|
+
}
|
35
|
+
catch (e)
|
36
|
+
{
|
37
|
+
if (e && e.statusCode == 404 || !meta.connect)
|
38
|
+
{
|
39
|
+
return await connect('pm').then(async (meta) =>
|
40
|
+
{
|
41
|
+
const c = await connectByPreference(await meta.connect, Object.assign({ metadata: meta.container }, options, options && options[property]), ...orders);
|
42
|
+
await c.container.dispatch('proxy', property);
|
43
|
+
registerCommands((await c.container.dispatch('$metadata', true)).commands, c.processor, c.container);
|
44
|
+
return c.container;
|
45
|
+
});
|
46
|
+
}
|
47
|
+
throw e;
|
48
|
+
}
|
49
|
+
})
|
50
|
+
});
|
51
|
+
return target[property];
|
52
|
+
}
|
53
|
+
});
|
54
|
+
}
|
package/src/state.ts
CHANGED
@@ -9,7 +9,7 @@ export default interface State
|
|
9
9
|
processes: { [key: string]: RunningContainer };
|
10
10
|
isDaemon: boolean;
|
11
11
|
config: ProxyConfiguration<StateConfiguration>
|
12
|
-
|
12
|
+
bridges: { [key: string]: SocketAdapter }
|
13
13
|
}
|
14
14
|
|
15
15
|
export interface StateConfiguration
|