@procedures/peer 0.2.3 → 0.4.0
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 +75 -0
- package/README.md +3 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/connection/index.d.ts +3 -2
- package/dist/connection/index.d.ts.map +1 -1
- package/dist/connection/index.js +6 -2
- package/dist/connection/index.js.map +1 -1
- package/dist/discovery/index.d.ts +4 -2
- package/dist/discovery/index.d.ts.map +1 -1
- package/dist/discovery/index.js +22 -34
- package/dist/discovery/index.js.map +1 -1
- package/dist/input-schemas.d.ts +5 -7
- package/dist/input-schemas.d.ts.map +1 -1
- package/dist/input-schemas.js +4 -15
- package/dist/input-schemas.js.map +1 -1
- package/dist/module.d.ts +2 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +2 -7
- package/dist/module.js.map +1 -1
- package/dist/output-schemas.d.ts +1 -4
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +0 -23
- package/dist/output-schemas.js.map +1 -1
- package/dist/peer/index.d.ts +16 -3
- package/dist/peer/index.d.ts.map +1 -1
- package/dist/peer/index.js +45 -6
- package/dist/peer/index.js.map +1 -1
- package/dist/procedures/index.d.ts +0 -6
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +1 -3
- package/dist/procedures/index.js.map +1 -1
- package/dist/procedures/manifest.generate.d.ts.map +1 -1
- package/dist/procedures/manifest.generate.js +10 -33
- package/dist/procedures/manifest.generate.js.map +1 -1
- package/dist/procedures/server.call.d.ts.map +1 -1
- package/dist/procedures/server.call.js +8 -3
- package/dist/procedures/server.call.js.map +1 -1
- package/dist/procedures/server.connect.d.ts.map +1 -1
- package/dist/procedures/server.connect.js +3 -1
- package/dist/procedures/server.connect.js.map +1 -1
- package/dist/types.d.ts +2 -58
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/connection/index.ts +8 -5
- package/src/discovery/index.ts +26 -35
- package/src/input-schemas.ts +4 -27
- package/src/module.ts +2 -7
- package/src/output-schemas.ts +0 -29
- package/src/peer/index.ts +70 -7
- package/src/procedures/index.ts +1 -8
- package/src/procedures/manifest.generate.ts +10 -33
- package/src/procedures/server.call.ts +8 -3
- package/src/procedures/server.connect.ts +3 -1
- package/src/types.ts +2 -76
- package/dist/procedures/server.start.d.ts +0 -14
- package/dist/procedures/server.start.d.ts.map +0 -1
- package/dist/procedures/server.start.js +0 -182
- package/dist/procedures/server.start.js.map +0 -1
- package/dist/procedures/server.status.d.ts +0 -13
- package/dist/procedures/server.status.d.ts.map +0 -1
- package/dist/procedures/server.status.js +0 -118
- package/dist/procedures/server.status.js.map +0 -1
- package/dist/procedures/server.stop.d.ts +0 -12
- package/dist/procedures/server.stop.d.ts.map +0 -1
- package/dist/procedures/server.stop.js +0 -98
- package/dist/procedures/server.stop.js.map +0 -1
- package/src/procedures/server.start.ts +0 -212
- package/src/procedures/server.status.ts +0 -141
- package/src/procedures/server.stop.ts +0 -123
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Client } from "@procedures/client";
|
|
8
8
|
import type { TransportType, PeerConnection } from "../types.js";
|
|
9
|
+
import { type Duration } from "@procedures/client";
|
|
9
10
|
export interface ConnectOptions {
|
|
10
11
|
/** Remote address (URL) */
|
|
11
12
|
address: string;
|
|
12
13
|
/** Transport type (auto-detected from URL if not specified) */
|
|
13
14
|
transport?: TransportType;
|
|
14
|
-
/**
|
|
15
|
-
timeout?:
|
|
15
|
+
/** The time limit of the connection, for example `seconds(10)` */
|
|
16
|
+
timeout?: Duration;
|
|
16
17
|
/** Local peer ID to identify ourselves */
|
|
17
18
|
localPeerId?: string;
|
|
18
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,MAAM,EAKP,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAM,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAMvD,MAAM,WAAW,cAAc;IAC7B,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,kEAAkE;IAClE,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,oBAAoB;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,uBAAuB;IACvB,MAAM,EAAE,cAAc,CAAC;IACvB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AASD;;GAEG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAgC1E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAE1E;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOvE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C"}
|
package/dist/connection/index.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* Manages outbound connections to remote peers.
|
|
5
5
|
* Uses Client + Transport for bidirectional RPC.
|
|
6
6
|
*/
|
|
7
|
-
import { Client, HttpTransport,
|
|
7
|
+
import { Client, HttpTransport, defaultUrlPattern, postOnlyStrategy, } from "@procedures/client";
|
|
8
|
+
// The Node entry: its WebSocketTransport uses the ws class, so a drop ends the socket at once with
|
|
9
|
+
// terminate(). The peer package runs in Node only.
|
|
10
|
+
import { WebSocketTransport } from "@procedures/client/node";
|
|
11
|
+
import { ms } from "@procedures/client";
|
|
8
12
|
// =============================================================================
|
|
9
13
|
// Connection Manager
|
|
10
14
|
// =============================================================================
|
|
@@ -105,7 +109,7 @@ function createClient(address, transport, timeout) {
|
|
|
105
109
|
return new Client({
|
|
106
110
|
transport: new WebSocketTransport({
|
|
107
111
|
url: address,
|
|
108
|
-
connectionTimeout: timeout ?? 10000,
|
|
112
|
+
connectionTimeout: timeout ?? ms(10000),
|
|
109
113
|
reconnect: {
|
|
110
114
|
enabled: true,
|
|
111
115
|
maxAttempts: 3,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,MAAM,EACN,aAAa,EACb,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,oBAAoB,CAAC;AAC5B,mGAAmG;AACnG,mDAAmD;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,OAAO,EAAE,EAAE,EAAiB,MAAM,oBAAoB,CAAC;AA4BvD,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,yBAAyB;AACzB,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAuB;IACnD,MAAM,YAAY,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,E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,EAAE,IAAI,kBAAkB,CAAC;oBAChC,GAAG,EAAE,OAAO;oBACZ,iBAAiB,EAAE,OAAO,IAAI,EAAE,CAAC,KAAK,CAAC;oBACvC,SAAS,EAAE;wBACT,OAAO,EAAE,IAAI;wBACb,WAAW,EAAE,CAAC;qBACf;iBACF,CAAC;aACH,CAAC,CAAC;QAEL,KAAK,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;QAElF;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,kBAAkB,CAC/B,MAAc,EACd,WAAoB;IAEpB,IAAI,CAAC;QACH,iDAAiD;QACjD,MAAM,OAAO,GAAwB,EAAE,CAAC;QACxC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC;QAC/B,CAAC;QAED,8BAA8B;QAC9B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAIhC,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,EAChD,OAAO,CACR,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;SAChC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,8CAA8C;QAC9C,wDAAwD;QACxD,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,EAAE;SACf,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Implements procedure discovery protocol for peers.
|
|
5
5
|
* Peers exchange procedure manifests on connection.
|
|
6
6
|
*/
|
|
7
|
-
import { type Effects, type Procedure, type ProcedureRegistry, type ProcedureRegistryLike } from "@procedures/client";
|
|
7
|
+
import { type Effects, type Procedure, type ProcedureRegistry, type ProcedureRegistryLike, type ProcedureEntry, type ProcedurePath } from "@procedures/client";
|
|
8
8
|
import type { ProcedureInfo, ProcedureAnnounceMessage } from "../types.js";
|
|
9
9
|
interface DiscoveryAnnounceInput {
|
|
10
10
|
/** Optional peer ID of the connecting peer */
|
|
@@ -22,7 +22,9 @@ export declare const discoveryAnnounceProcedure: Procedure<DiscoveryAnnounceInpu
|
|
|
22
22
|
/**
|
|
23
23
|
* Get procedure info for all registered procedures of a registry (default: the global registry)
|
|
24
24
|
*/
|
|
25
|
-
export declare function getProcedureInfos(registry?: ProcedureRegistryLike): ProcedureInfo[];
|
|
25
|
+
export declare function getProcedureInfos(registry?: ProcedureRegistryLike, expose?: (path: ProcedurePath) => boolean): ProcedureInfo[];
|
|
26
|
+
/** The ProcedureInfo of a manifest entry: the form that the peers exchange. */
|
|
27
|
+
export declare function infoOf(entry: ProcedureEntry): ProcedureInfo;
|
|
26
28
|
/**
|
|
27
29
|
* Watch for procedure changes in a registry (default: the global registry)
|
|
28
30
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,SAAS,EAEd,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,SAAS,EAEd,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAK1B,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAMrB,UAAU,sBAAsB;IAC9B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AASD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,CAChD,sBAAsB,EACtB,wBAAwB,EACxB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CA6BpD,CAAC;AAMX;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,GAAE,qBAA0C,EACpD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,GACxC,aAAa,EAAE,CAGjB;AAED,+EAA+E;AAC/E,wBAAgB,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,aAAa,CAM3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,EAAE,IAAI,EAAE,aAAa,KAAK,IAAI,EACzE,QAAQ,GAAE,iBAAsC,GAC/C,MAAM,IAAI,CAuBZ"}
|
package/dist/discovery/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Implements procedure discovery protocol for peers.
|
|
5
5
|
* Peers exchange procedure manifests on connection.
|
|
6
6
|
*/
|
|
7
|
-
import { createProcedure, PROCEDURE_REGISTRY, REGISTRY_READ_EFFECTS, } from "@procedures/client";
|
|
7
|
+
import { createProcedure, PROCEDURE_REGISTRY, REGISTRY_READ_EFFECTS, describeRegistry, } from "@procedures/client";
|
|
8
8
|
import { schema } from "../schema.js";
|
|
9
9
|
// =============================================================================
|
|
10
10
|
// Discovery Procedure
|
|
@@ -25,26 +25,14 @@ export const discoveryAnnounceProcedure = createProcedure()
|
|
|
25
25
|
effects: REGISTRY_READ_EFFECTS,
|
|
26
26
|
})
|
|
27
27
|
.handler(async (_input, ctx) => {
|
|
28
|
-
// The procedures of the registry that serves this
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const meta = proc.metadata;
|
|
35
|
-
return !meta?.internal;
|
|
36
|
-
})
|
|
37
|
-
.map((proc) => {
|
|
38
|
-
const meta = proc.metadata;
|
|
39
|
-
const info = {
|
|
40
|
-
path: proc.path,
|
|
41
|
-
};
|
|
42
|
-
if (meta?.description !== undefined) {
|
|
43
|
-
info.description = meta.description;
|
|
44
|
-
}
|
|
45
|
-
// TODO: Generate JSON schema from input/output schemas
|
|
46
|
-
return info;
|
|
28
|
+
// The one manifest of the core (roadmap R17): the procedures of the registry that serves this
|
|
29
|
+
// call and that the host exposes, with their JSON Schemas, without the internal ones.
|
|
30
|
+
// Before, the announce gave no schemas and listed the procedures that the host hides.
|
|
31
|
+
const manifest = describeRegistry(ctx?.registry ?? PROCEDURE_REGISTRY, {
|
|
32
|
+
...(ctx?.expose ? { expose: ctx.expose } : {}),
|
|
33
|
+
include: (proc) => !proc.metadata?.internal,
|
|
47
34
|
});
|
|
35
|
+
const procedureInfos = manifest.procedures.map(infoOf);
|
|
48
36
|
// Generate a peer ID based on process (could be configured)
|
|
49
37
|
const peerId = `peer-${process.pid}-${Date.now().toString(36)}`;
|
|
50
38
|
return {
|
|
@@ -60,20 +48,20 @@ export const discoveryAnnounceProcedure = createProcedure()
|
|
|
60
48
|
/**
|
|
61
49
|
* Get procedure info for all registered procedures of a registry (default: the global registry)
|
|
62
50
|
*/
|
|
63
|
-
export function getProcedureInfos(registry = PROCEDURE_REGISTRY) {
|
|
64
|
-
|
|
65
|
-
return procedures
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
export function getProcedureInfos(registry = PROCEDURE_REGISTRY, expose) {
|
|
52
|
+
// The one manifest of the core (roadmap R17), without the schemas
|
|
53
|
+
return describeRegistry(registry, { schemas: false, ...(expose ? { expose } : {}) }).procedures.map(infoOf);
|
|
54
|
+
}
|
|
55
|
+
/** The ProcedureInfo of a manifest entry: the form that the peers exchange. */
|
|
56
|
+
export function infoOf(entry) {
|
|
57
|
+
const info = { path: [...entry.path] };
|
|
58
|
+
if (entry.description !== undefined)
|
|
59
|
+
info.description = entry.description;
|
|
60
|
+
if (entry.input)
|
|
61
|
+
info.inputSchema = entry.input;
|
|
62
|
+
if (entry.output)
|
|
63
|
+
info.outputSchema = entry.output;
|
|
64
|
+
return info;
|
|
77
65
|
}
|
|
78
66
|
/**
|
|
79
67
|
* Watch for procedure changes in a registry (default: the global registry)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EAMf,kBAAkB,EAClB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EAMf,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,GAIjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAetC,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF,MAAM,4BAA4B,GAAG,MAAM,EAA0B,CAAC;AACtE,MAAM,6BAA6B,GAAG,MAAM,EAA4B,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAInC,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;KAChC,KAAK,CAAC,4BAA4B,CAAC;KACnC,MAAM,CAAC,6BAA6B,CAAC;KACrC,IAAI,CAAC;IACJ,WAAW,EAAE,4CAA4C;IACzD,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,qBAAqB;CAC/B,CAAC;KACD,OAAO,CAA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package/dist/input-schemas.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Input schemas of the `server.*` and `manifest.*` procedures.
|
|
2
|
+
* Input schemas of the `server.*` and `manifest.*` procedures of the peer package.
|
|
3
3
|
*
|
|
4
|
-
* Before, these procedures used pass-through schemas: `mark server
|
|
4
|
+
* Before, these procedures used pass-through schemas: `mark server create --help` listed no
|
|
5
5
|
* options, and a port such as "abc" reached the handler. Each schema now validates its input,
|
|
6
|
-
* and the CLI help shows the fields.
|
|
6
|
+
* and the CLI help shows the fields. The schemas of `server.start`, `server.stop` and
|
|
7
|
+
* `server.status` are in `@procedures/server`.
|
|
7
8
|
*/
|
|
8
9
|
import { type ZodLikeSchema } from "@procedures/client";
|
|
9
|
-
import type { ManifestGenerateInput, ServerConnectInput, ServerCreateInput, ServerDisconnectInput
|
|
10
|
+
import type { ManifestGenerateInput, ServerConnectInput, ServerCreateInput, ServerDisconnectInput } from "./types.js";
|
|
10
11
|
import type { ServerCallInput } from "./procedures/server.call.js";
|
|
11
12
|
import type { ServerConnectionsInput } from "./procedures/server.connections.js";
|
|
12
13
|
export declare const serverCreateInputSchema: ZodLikeSchema<ServerCreateInput>;
|
|
13
|
-
export declare const serverStartInputSchema: ZodLikeSchema<ServerStartInput>;
|
|
14
|
-
export declare const serverStopInputSchema: ZodLikeSchema<ServerStopInput>;
|
|
15
|
-
export declare const serverStatusInputSchema: ZodLikeSchema<ServerStatusInput>;
|
|
16
14
|
export declare const serverConnectInputSchema: ZodLikeSchema<ServerConnectInput>;
|
|
17
15
|
export declare const serverDisconnectInputSchema: ZodLikeSchema<ServerDisconnectInput>;
|
|
18
16
|
export declare const serverCallInputSchema: ZodLikeSchema<ServerCallInput>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-schemas.d.ts","sourceRoot":"","sources":["../src/input-schemas.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"input-schemas.d.ts","sourceRoot":"","sources":["../src/input-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AA0BjF,eAAO,MAAM,uBAAuB,EAAE,aAAa,CAAC,iBAAiB,CAapE,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,aAAa,CAAC,kBAAkB,CAMtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,aAAa,CAAC,qBAAqB,CAI5E,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,eAAe,CAahE,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,aAAa,CAAC,sBAAsB,CAC7B,CAAC;AAEnD,eAAO,MAAM,2BAA2B,EAAE,aAAa,CAAC,qBAAqB,CAM5E,CAAC"}
|
package/dist/input-schemas.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Input schemas of the `server.*` and `manifest.*` procedures.
|
|
2
|
+
* Input schemas of the `server.*` and `manifest.*` procedures of the peer package.
|
|
3
3
|
*
|
|
4
|
-
* Before, these procedures used pass-through schemas: `mark server
|
|
4
|
+
* Before, these procedures used pass-through schemas: `mark server create --help` listed no
|
|
5
5
|
* options, and a port such as "abc" reached the handler. Each schema now validates its input,
|
|
6
|
-
* and the CLI help shows the fields.
|
|
6
|
+
* and the CLI help shows the fields. The schemas of `server.start`, `server.stop` and
|
|
7
|
+
* `server.status` are in `@procedures/server`.
|
|
7
8
|
*/
|
|
8
9
|
import { z } from "zod";
|
|
9
10
|
import { zodAdapter } from "@procedures/client";
|
|
@@ -39,18 +40,6 @@ export const serverCreateInputSchema = zodAdapter(z.object({
|
|
|
39
40
|
.optional()
|
|
40
41
|
.describe("The procedures to serve: exact keys (git.status) or prefixes (git.*). Default: every procedure"),
|
|
41
42
|
}));
|
|
42
|
-
export const serverStartInputSchema = zodAdapter(z.object({
|
|
43
|
-
port: port.optional().describe("The port to listen on (default: 3000)"),
|
|
44
|
-
host: z.string().min(1).optional().describe("The host to bind to (default: 127.0.0.1)"),
|
|
45
|
-
transport: z.enum(["http", "websocket", "both"]).optional().describe("The transport (default: http)"),
|
|
46
|
-
}));
|
|
47
|
-
export const serverStopInputSchema = zodAdapter(z.object({
|
|
48
|
-
port: port.optional().describe("The port of the server to stop (default: all servers)"),
|
|
49
|
-
force: z.boolean().optional().describe("Stop with SIGKILL instead of SIGTERM"),
|
|
50
|
-
}));
|
|
51
|
-
export const serverStatusInputSchema = zodAdapter(z.object({
|
|
52
|
-
port: port.optional().describe("The port of the server (default: all servers)"),
|
|
53
|
-
}));
|
|
54
43
|
export const serverConnectInputSchema = zodAdapter(z.object({
|
|
55
44
|
address: z.string().min(1).describe("The address of the remote peer"),
|
|
56
45
|
transport: z.enum(["http", "websocket", "local"]).optional().describe("The transport to use"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-schemas.js","sourceRoot":"","sources":["../src/input-schemas.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"input-schemas.js","sourceRoot":"","sources":["../src/input-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AAUpE,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAEhD,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM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IAAI,CAAC,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IAC5G,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;IACzF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;CAC/E,CAAC,CACH,CAAC"}
|
package/dist/module.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type AnyProcedure, type ProcedureModule, type ProcedureRegistry } from "@procedures/client";
|
|
10
10
|
/**
|
|
11
|
-
* All server procedures
|
|
11
|
+
* All server procedures. `server.start`, `server.stop` and `server.status` manage the background
|
|
12
|
+
* server of the `mark` CLI: they are in `@procedures/server`, the package of the host.
|
|
12
13
|
*/
|
|
13
14
|
export declare const procedures: readonly AnyProcedure[];
|
|
14
15
|
/**
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAgB,KAAK,eAAe,EAAuC,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAgB,KAAK,eAAe,EAAuC,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAWxJ;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,YAAY,EAQ7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,eAAmE,CAAC;eAEhF,YAAY;AAE3B;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,iBAAsC,GAAG,IAAI,CAE/F"}
|
package/dist/module.js
CHANGED
|
@@ -13,13 +13,11 @@ import { serverConnectProcedure } from "./procedures/server.connect.js";
|
|
|
13
13
|
import { serverDisconnectProcedure } from "./procedures/server.disconnect.js";
|
|
14
14
|
import { manifestGenerateProcedure } from "./procedures/manifest.generate.js";
|
|
15
15
|
import { discoveryAnnounceProcedure } from "./discovery/index.js";
|
|
16
|
-
import { serverStartProcedure } from "./procedures/server.start.js";
|
|
17
|
-
import { serverStopProcedure } from "./procedures/server.stop.js";
|
|
18
|
-
import { serverStatusProcedure } from "./procedures/server.status.js";
|
|
19
16
|
import { serverCallProcedure } from "./procedures/server.call.js";
|
|
20
17
|
import { serverConnectionsProcedure } from "./procedures/server.connections.js";
|
|
21
18
|
/**
|
|
22
|
-
* All server procedures
|
|
19
|
+
* All server procedures. `server.start`, `server.stop` and `server.status` manage the background
|
|
20
|
+
* server of the `mark` CLI: they are in `@procedures/server`, the package of the host.
|
|
23
21
|
*/
|
|
24
22
|
export const procedures = [
|
|
25
23
|
serverCreateProcedure,
|
|
@@ -27,9 +25,6 @@ export const procedures = [
|
|
|
27
25
|
serverDisconnectProcedure,
|
|
28
26
|
manifestGenerateProcedure,
|
|
29
27
|
discoveryAnnounceProcedure,
|
|
30
|
-
serverStartProcedure,
|
|
31
|
-
serverStopProcedure,
|
|
32
|
-
serverStatusProcedure,
|
|
33
28
|
serverCallProcedure,
|
|
34
29
|
serverConnectionsProcedure,
|
|
35
30
|
];
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAqB,YAAY,EAAwB,kBAAkB,EAAE,eAAe,EAA0B,MAAM,oBAAoB,CAAC;AAExJ,wBAAwB;AACxB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,QAAQ,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/output-schemas.d.ts
CHANGED
|
@@ -6,16 +6,13 @@
|
|
|
6
6
|
* the compiler checks it against the type.
|
|
7
7
|
*/
|
|
8
8
|
import { z } from "zod";
|
|
9
|
-
import type { ManifestGenerateOutput, ServerConnectOutput, ServerCreateOutput, ServerDisconnectOutput
|
|
9
|
+
import type { ManifestGenerateOutput, ServerConnectOutput, ServerCreateOutput, ServerDisconnectOutput } from "./types.js";
|
|
10
10
|
import type { ServerCallOutput } from "./procedures/server.call.js";
|
|
11
11
|
import type { ServerConnectionsOutput } from "./procedures/server.connections.js";
|
|
12
12
|
export declare const ServerCreateOutputSchema: z.ZodType<ServerCreateOutput>;
|
|
13
13
|
export declare const ServerConnectOutputSchema: z.ZodType<ServerConnectOutput>;
|
|
14
14
|
export declare const ServerDisconnectOutputSchema: z.ZodType<ServerDisconnectOutput>;
|
|
15
15
|
export declare const ManifestGenerateOutputSchema: z.ZodType<ManifestGenerateOutput>;
|
|
16
|
-
export declare const ServerStartOutputSchema: z.ZodType<ServerStartOutput>;
|
|
17
|
-
export declare const ServerStopOutputSchema: z.ZodType<ServerStopOutput>;
|
|
18
|
-
export declare const ServerStatusOutputSchema: z.ZodType<ServerStatusOutput>;
|
|
19
16
|
export declare const ServerCallOutputSchema: z.ZodType<ServerCallOutput>;
|
|
20
17
|
export declare const ServerConnectionsOutputSchema: z.ZodType<ServerConnectionsOutput>;
|
|
21
18
|
//# sourceMappingURL=output-schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-schemas.d.ts","sourceRoot":"","sources":["../src/output-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"output-schemas.d.ts","sourceRoot":"","sources":["../src/output-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AASlF,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAWjE,CAAC;AAEH,eAAO,MAAM,yBAAyB,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAInE,CAAC;AAEH,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAEzE,CAAC;AAEH,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAWzE,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAI7D,CAAC;AAEH,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAa3E,CAAC"}
|
package/dist/output-schemas.js
CHANGED
|
@@ -42,29 +42,6 @@ export const ManifestGenerateOutputSchema = z.looseObject({
|
|
|
42
42
|
typescript: z.string().optional().describe("The TypeScript declarations, for the typescript format"),
|
|
43
43
|
filesWritten: z.array(z.string()).optional().describe("The files that the call wrote, with outputDir"),
|
|
44
44
|
});
|
|
45
|
-
export const ServerStartOutputSchema = z.looseObject({
|
|
46
|
-
success: z.boolean().describe("True when the server started"),
|
|
47
|
-
pid: z.number().optional().describe("The process id of the server"),
|
|
48
|
-
port: z.number().optional().describe("The port of the server"),
|
|
49
|
-
endpoint: z.string().optional().describe("The URL of the server"),
|
|
50
|
-
logFile: z.string().optional().describe("The log file of the server"),
|
|
51
|
-
message: z.string().describe("A message about the result"),
|
|
52
|
-
});
|
|
53
|
-
export const ServerStopOutputSchema = z.looseObject({
|
|
54
|
-
success: z.boolean().describe("True when the server stopped"),
|
|
55
|
-
message: z.string().describe("A message about the result"),
|
|
56
|
-
});
|
|
57
|
-
export const ServerStatusOutputSchema = z.looseObject({
|
|
58
|
-
running: z.boolean().describe("True when a server runs"),
|
|
59
|
-
pid: z.number().optional().describe("The process id of the server"),
|
|
60
|
-
port: z.number().optional().describe("The port of the server"),
|
|
61
|
-
endpoint: z.string().optional().describe("The URL of the server"),
|
|
62
|
-
transport: z.string().optional().describe("The transport of the server"),
|
|
63
|
-
startedAt: z.string().optional().describe("The start time (ISO 8601)"),
|
|
64
|
-
uptime: z.string().optional().describe("The time since the start, as text"),
|
|
65
|
-
logFile: z.string().optional().describe("The log file of the server"),
|
|
66
|
-
message: z.string().describe("A message about the result"),
|
|
67
|
-
});
|
|
68
45
|
export const ServerCallOutputSchema = z.looseObject({
|
|
69
46
|
result: z.unknown().describe("The result of the remote procedure"),
|
|
70
47
|
connectionId: z.string().describe("The connection that the call used"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-schemas.js","sourceRoot":"","sources":["../src/output-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"output-schemas.js","sourceRoot":"","sources":["../src/output-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,MAAM,aAAa,GAAG,CAAC,CAAC,WAAW,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IACxD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE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AE,CAAC;SACX,KAAK,CACJ,CAAC,CAAC,WAAW,CAAC;QACZ,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0BAA0B,CAAC;QAC7D,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;QAC9D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QACjE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yDAAyD,CAAC;QACrF,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6CAA6C,CAAC;QACxF,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;KACrF,CAAC,CACH;SACA,QAAQ,CAAC,sBAAsB,CAAC;CACpC,CAAC,CAAC"}
|
package/dist/peer/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Transport-agnostic peer implementation for bidirectional RPC.
|
|
5
5
|
*/
|
|
6
|
-
import { ProcedureServer, type ProcedureRegistry, type HostPolicy } from "@procedures/client";
|
|
7
|
-
import type { ProcedurePath } from "@procedures/client";
|
|
6
|
+
import { ProcedureServer, type ProcedureRegistry, Client, type HostPolicy } from "@procedures/client";
|
|
7
|
+
import type { ProcedurePath, StopOptions } from "@procedures/client";
|
|
8
8
|
import type { TransportConfig, TransportType } from "../types.js";
|
|
9
9
|
export interface PeerOptions {
|
|
10
10
|
/** Unique peer ID */
|
|
@@ -17,6 +17,11 @@ export interface PeerOptions {
|
|
|
17
17
|
registry?: ProcedureRegistry;
|
|
18
18
|
/** The procedures that the peer serves (see `exposeRule`). Without it, the peer serves every procedure. */
|
|
19
19
|
expose?: ((path: ProcedurePath) => boolean) | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The peer counts the calls of each procedure, and `host.metrics` gives the counts (roadmap
|
|
22
|
+
* R19). The default is true.
|
|
23
|
+
*/
|
|
24
|
+
metrics?: boolean | undefined;
|
|
20
25
|
/**
|
|
21
26
|
* The policy of the host (`hostPolicy()` of the core, roadmap 2.3): the expose rule, the call
|
|
22
27
|
* rule, the interceptors (a time limit), the token of each network transport that has none of
|
|
@@ -34,11 +39,19 @@ export interface Peer {
|
|
|
34
39
|
/** Start all transports */
|
|
35
40
|
start(): Promise<void>;
|
|
36
41
|
/** Stop all transports */
|
|
37
|
-
|
|
42
|
+
/** Stop the peer. With `grace`, the calls in flight have that time to end (roadmap R14). */
|
|
43
|
+
stop(options?: StopOptions): Promise<void>;
|
|
38
44
|
/** Get active endpoints */
|
|
39
45
|
getEndpoints(): PeerEndpoint[];
|
|
40
46
|
/** Get underlying server */
|
|
41
47
|
getServer(): ProcedureServer;
|
|
48
|
+
/** The ids of the WebSocket connections of the clients (roadmap R24). */
|
|
49
|
+
connections(): string[];
|
|
50
|
+
/**
|
|
51
|
+
* A client of one connected client (roadmap R24): its calls go to the procedures that the client
|
|
52
|
+
* serves (the `serve` option of its WebSocketTransport), over the same WebSocket.
|
|
53
|
+
*/
|
|
54
|
+
clientFor(connectionId: string): Client;
|
|
42
55
|
}
|
|
43
56
|
/**
|
|
44
57
|
* Create a new peer instance
|
package/dist/peer/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/peer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EAGf,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/peer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EAGf,KAAK,iBAAiB,EAQtB,MAAM,EAEN,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,aAAa,E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er/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Transport-agnostic peer implementation for bidirectional RPC.
|
|
5
5
|
*/
|
|
6
|
-
import { ProcedureServer, HttpServerTransport, WebSocketServerTransport, PROCEDURE_REGISTRY, rpcServerUrlStrategy, defaultServerUrlStrategy, defaultUrlPattern, procedureServerOptions, } from "@procedures/client";
|
|
6
|
+
import { ProcedureServer, HttpServerTransport, WebSocketServerTransport, PROCEDURE_REGISTRY, rpcServerUrlStrategy, defaultServerUrlStrategy, defaultUrlPattern, procedureServerOptions, hostProcedures, metricsInterceptor, Client, } from "@procedures/client";
|
|
7
7
|
import { bearerToken, hostAllowed, originAllowed, tokenMatches } from "./security.js";
|
|
8
8
|
/**
|
|
9
9
|
* URL strategy that matches the client's defaultUrlPattern
|
|
@@ -30,6 +30,10 @@ class PeerImpl {
|
|
|
30
30
|
transports;
|
|
31
31
|
endpoints = [];
|
|
32
32
|
started = false;
|
|
33
|
+
/** The WebSocket transports of the peer: the calls to its clients go over them (R24) */
|
|
34
|
+
wsTransports = [];
|
|
35
|
+
/** The HTTP servers that the peer made for its WebSocket transports: `stop()` closes them */
|
|
36
|
+
ownedServers = [];
|
|
33
37
|
registry;
|
|
34
38
|
startTime = Date.now();
|
|
35
39
|
/** The browser checks of the policy (an origin rule here replaces the peer's own rule). */
|
|
@@ -43,13 +47,25 @@ class PeerImpl {
|
|
|
43
47
|
: { ...transport, token: policy.token });
|
|
44
48
|
this.registry = options.registry ?? PROCEDURE_REGISTRY;
|
|
45
49
|
this.browser = policy?.browser ?? {};
|
|
46
|
-
// Create procedure server
|
|
50
|
+
// Create procedure server. The metrics interceptor counts each call for host.metrics (R19).
|
|
51
|
+
const metrics = options.metrics === false ? undefined : metricsInterceptor();
|
|
52
|
+
const serverOptions = policy ? procedureServerOptions(policy, this.registry) : {};
|
|
53
|
+
const interceptors = [...(serverOptions.interceptors ?? []), ...(metrics ? [metrics.interceptor] : [])];
|
|
47
54
|
this.server = new ProcedureServer({
|
|
48
|
-
...
|
|
55
|
+
...serverOptions,
|
|
56
|
+
...(interceptors.length > 0 ? { interceptors } : {}),
|
|
49
57
|
autoRegister: options.autoRegister ?? true,
|
|
50
58
|
registry: this.registry,
|
|
51
59
|
...(options.expose ? { expose: options.expose } : {}),
|
|
52
60
|
});
|
|
61
|
+
// host.health, host.info and host.metrics: pinned on the server, not in the registry (R19)
|
|
62
|
+
this.server.registerProcedures(hostProcedures({
|
|
63
|
+
id: this.id,
|
|
64
|
+
startedAt: this.startTime,
|
|
65
|
+
server: this.server,
|
|
66
|
+
endpoints: () => this.getEndpoints(),
|
|
67
|
+
...(metrics ? { metrics } : {}),
|
|
68
|
+
}));
|
|
53
69
|
}
|
|
54
70
|
async start() {
|
|
55
71
|
if (this.started)
|
|
@@ -88,7 +104,9 @@ class PeerImpl {
|
|
|
88
104
|
// Dynamic import to avoid bundling express if not used
|
|
89
105
|
const express = (await import("express")).default;
|
|
90
106
|
const app = express();
|
|
91
|
-
|
|
107
|
+
// No body parser here: the transport reads the body itself, with bodyLimit, and accepts each
|
|
108
|
+
// JSON value (roadmap R5). Before, the strict parser of express refused a bare value (a
|
|
109
|
+
// number, a string, null) with 400, and its limit of 100 kB replaced bodyLimit.
|
|
92
110
|
const port = config.port ?? 3000;
|
|
93
111
|
// Loopback by default so the full procedure registry (incl. shell.run / fs.write) is not
|
|
94
112
|
// served unauthenticated on all interfaces. Pass host: "0.0.0.0" to expose on the LAN
|
|
@@ -149,6 +167,7 @@ class PeerImpl {
|
|
|
149
167
|
allowedOrigins: this.browser.allowedOrigins ?? ((origin) => originAllowed(origin, config.corsOrigins)),
|
|
150
168
|
...(this.browser.allowedHosts ? { allowedHosts: this.browser.allowedHosts } : {}),
|
|
151
169
|
allowGet: this.browser.allowGet ?? config.urlStrategy === "rest",
|
|
170
|
+
...(config.bodyLimit !== undefined ? { bodyLimit: config.bodyLimit } : {}),
|
|
152
171
|
});
|
|
153
172
|
this.server.addTransport(httpTransport);
|
|
154
173
|
await httpTransport.start();
|
|
@@ -203,17 +222,28 @@ class PeerImpl {
|
|
|
203
222
|
httpServer.close();
|
|
204
223
|
throw error;
|
|
205
224
|
}
|
|
225
|
+
this.ownedServers.push(httpServer);
|
|
226
|
+
this.wsTransports.push(wsTransport);
|
|
206
227
|
this.endpoints.push({
|
|
207
228
|
type: "websocket",
|
|
208
229
|
address: `ws://${host === "0.0.0.0" ? "localhost" : host}:${port}${path}`,
|
|
209
230
|
});
|
|
210
231
|
}
|
|
211
|
-
async stop() {
|
|
232
|
+
async stop(options = {}) {
|
|
212
233
|
if (!this.started)
|
|
213
234
|
return;
|
|
214
|
-
await this.server.stop();
|
|
235
|
+
await this.server.stop(options);
|
|
236
|
+
// The HTTP servers of the WebSocket transports: before, they stayed open, so the port stayed
|
|
237
|
+
// bound after stop() (roadmap R5)
|
|
238
|
+
const owned = this.ownedServers;
|
|
239
|
+
this.ownedServers = [];
|
|
240
|
+
await Promise.all(owned.map((httpServer) => new Promise((resolve) => {
|
|
241
|
+
httpServer.close(() => resolve());
|
|
242
|
+
httpServer.closeAllConnections();
|
|
243
|
+
})));
|
|
215
244
|
this.started = false;
|
|
216
245
|
this.endpoints = [];
|
|
246
|
+
this.wsTransports = [];
|
|
217
247
|
}
|
|
218
248
|
getEndpoints() {
|
|
219
249
|
return [...this.endpoints];
|
|
@@ -221,6 +251,15 @@ class PeerImpl {
|
|
|
221
251
|
getServer() {
|
|
222
252
|
return this.server;
|
|
223
253
|
}
|
|
254
|
+
connections() {
|
|
255
|
+
return this.wsTransports.flatMap((transport) => transport.getTrackedConnections().map((connection) => connection.id));
|
|
256
|
+
}
|
|
257
|
+
clientFor(connectionId) {
|
|
258
|
+
const transport = this.wsTransports.find((ws) => ws.getTrackedConnection(connectionId) !== undefined);
|
|
259
|
+
if (!transport)
|
|
260
|
+
throw new Error(`Connection not found: ${connectionId}`);
|
|
261
|
+
return new Client({ transport: transport.transportFor(connectionId), throwOnError: true });
|
|
262
|
+
}
|
|
224
263
|
}
|
|
225
264
|
// =============================================================================
|
|
226
265
|
// Factory
|