@procedures/server 0.3.0 → 0.5.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 +62 -0
- package/README.md +44 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +53 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/module.d.ts +24 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +29 -0
- package/dist/module.js.map +1 -0
- package/dist/procedures/server.start.d.ts +17 -0
- package/dist/procedures/server.start.d.ts.map +1 -0
- package/dist/procedures/server.start.js +183 -0
- package/dist/procedures/server.start.js.map +1 -0
- package/dist/procedures/server.status.d.ts +15 -0
- package/dist/procedures/server.status.d.ts.map +1 -0
- package/dist/procedures/server.status.js +118 -0
- package/dist/procedures/server.status.js.map +1 -0
- package/dist/procedures/server.stop.d.ts +14 -0
- package/dist/procedures/server.stop.d.ts.map +1 -0
- package/dist/procedures/server.stop.js +98 -0
- package/dist/procedures/server.stop.js.map +1 -0
- package/dist/register.d.ts +7 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +9 -0
- package/dist/register.js.map +1 -0
- package/dist/run.d.ts +5 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +48 -3
- package/dist/run.js.map +1 -1
- package/dist/schemas.d.ts +19 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +48 -0
- package/dist/schemas.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -7
- package/src/config.ts +52 -1
- package/src/index.ts +27 -2
- package/src/module.ts +33 -0
- package/src/procedures/server.start.ts +213 -0
- package/src/procedures/server.status.ts +141 -0
- package/src/procedures/server.stop.ts +123 -0
- package/src/register.ts +11 -0
- package/src/run.ts +52 -3
- package/src/schemas.ts +69 -0
- package/src/types.ts +83 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: server.stop
|
|
3
|
+
* Stops the running CLI server daemon
|
|
4
|
+
*
|
|
5
|
+
* The procedure came from `@procedures/peer`: it belongs to the host.
|
|
6
|
+
*/
|
|
7
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
8
|
+
import { checkServer, readAllLockfiles, readLockfileForPort, removeLockfileForPort } from "@procedures/peer/lockfile";
|
|
9
|
+
import { ServerStopOutputSchema, serverStopInputSchema } from "../schemas.js";
|
|
10
|
+
const serverStopOutputSchema = zodAdapter(ServerStopOutputSchema);
|
|
11
|
+
/**
|
|
12
|
+
* Kill process by PID
|
|
13
|
+
*/
|
|
14
|
+
function killProcess(pid, signal = "SIGTERM") {
|
|
15
|
+
try {
|
|
16
|
+
process.kill(pid, signal);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const serverStopProcedure = createProcedure()
|
|
24
|
+
.path(["server", "stop"])
|
|
25
|
+
.input(serverStopInputSchema)
|
|
26
|
+
.output(serverStopOutputSchema)
|
|
27
|
+
.meta({
|
|
28
|
+
description: "Stop running CLI server",
|
|
29
|
+
// It stops the servers of the lockfiles and deletes their lockfiles
|
|
30
|
+
effects: { reads: ["fs", "server"], writes: ["fs", "server"], idempotent: true },
|
|
31
|
+
args: [],
|
|
32
|
+
shorts: { port: "p" },
|
|
33
|
+
})
|
|
34
|
+
.handler(async (input) => {
|
|
35
|
+
const force = input.force ?? false;
|
|
36
|
+
const signal = force ? "SIGKILL" : "SIGTERM";
|
|
37
|
+
// Get target servers
|
|
38
|
+
let targets;
|
|
39
|
+
if (input.port !== undefined) {
|
|
40
|
+
const lockfile = readLockfileForPort(input.port);
|
|
41
|
+
targets = lockfile ? [lockfile] : [];
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
targets = readAllLockfiles();
|
|
45
|
+
}
|
|
46
|
+
if (targets.length === 0) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
message: input.port
|
|
50
|
+
? `No server found on port ${input.port}`
|
|
51
|
+
: "No servers running",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const results = [];
|
|
55
|
+
let allSuccess = true;
|
|
56
|
+
for (const lockfile of targets) {
|
|
57
|
+
const { pid, port } = lockfile;
|
|
58
|
+
// Signal the PID only when the server answers as the peer of this lockfile: Windows reuses
|
|
59
|
+
// PIDs, and before, a stale lockfile made this kill an unrelated process (deep dive CLI-4)
|
|
60
|
+
const state = await checkServer(lockfile);
|
|
61
|
+
if (state !== "alive") {
|
|
62
|
+
removeLockfileForPort(port);
|
|
63
|
+
results.push(state === "dead"
|
|
64
|
+
? `Port ${port}: cleaned up stale lockfile`
|
|
65
|
+
: `Port ${port}: another process answers on this port; nothing stopped (stale lockfile removed)`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const sent = killProcess(pid, signal);
|
|
69
|
+
if (!sent) {
|
|
70
|
+
allSuccess = false;
|
|
71
|
+
results.push(`Port ${port}: failed to send ${signal} to PID ${pid}`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Wait for process to die
|
|
75
|
+
const maxWait = force ? 500 : 5000;
|
|
76
|
+
const startTime = Date.now();
|
|
77
|
+
let stopped = false;
|
|
78
|
+
while (Date.now() - startTime < maxWait) {
|
|
79
|
+
if ((await checkServer(lockfile, 300)) === "dead") {
|
|
80
|
+
removeLockfileForPort(port);
|
|
81
|
+
results.push(`Port ${port}: stopped (PID ${pid})`);
|
|
82
|
+
stopped = true;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
86
|
+
}
|
|
87
|
+
if (!stopped) {
|
|
88
|
+
allSuccess = false;
|
|
89
|
+
results.push(`Port ${port}: PID ${pid} did not stop${force ? "" : " (try --force)"}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
success: allSuccess,
|
|
94
|
+
message: results.join("\n"),
|
|
95
|
+
};
|
|
96
|
+
})
|
|
97
|
+
.build();
|
|
98
|
+
//# sourceMappingURL=server.stop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.stop.js","sourceRoot":"","sources":["../../src/procedures/server.stop.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAgC,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,qBAAqB,EAAqB,MAAM,2BAA2B,CAAC;AACzI,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAI9E,MAAM,sBAAsB,GAAG,UAAU,CAAmB,sBAAsB,CAAC,CAAC;AAMpF;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW,EAAE,MAAM,GAAmB,SAAS;IAClE,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAI5B,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;KACxB,KAAK,CAAC,qBAAqB,CAAC;KAC5B,MAAM,CAAC,sBAAsB,CAAC;KAC9B,IAAI,CAAC;IACJ,WAAW,EAAE,yBAAyB;IACtC,oEAAoE;IACpE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,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BAAgB,EAAE,CAAC,CAAC;QACxF,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,UAAU;QACnB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;KAC5B,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/server in the global registry:
|
|
3
|
+
* `import "@procedures/server/register"`. The package root and the `./module` entry register
|
|
4
|
+
* nothing (ARCHITECTURE-PROPOSALS-2026-10, P9).
|
|
5
|
+
*/
|
|
6
|
+
export * from "./module.js";
|
|
7
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,aAAa,CAAC"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/server in the global registry:
|
|
3
|
+
* `import "@procedures/server/register"`. The package root and the `./module` entry register
|
|
4
|
+
* nothing (ARCHITECTURE-PROPOSALS-2026-10, P9).
|
|
5
|
+
*/
|
|
6
|
+
import { registerServerProcedures } from "./module.js";
|
|
7
|
+
export * from "./module.js";
|
|
8
|
+
registerServerProcedures();
|
|
9
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,cAAc,aAAa,CAAC;AAE5B,wBAAwB,EAAE,CAAC"}
|
package/dist/run.d.ts
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* the host policy of the core (`hostPolicy()`): the token, the `--expose` list and the browser
|
|
7
7
|
* checks. A package without a module entry still works: the server imports it and takes the
|
|
8
8
|
* procedures that the import added to the global registry.
|
|
9
|
+
*
|
|
10
|
+
* The server always serves `events.subscribe` (`documentation/EVENTS.md`). Its topic rule is the
|
|
11
|
+
* `--events` patterns, and no topic without them. `--fs-root` confines the `fs.*` procedures.
|
|
9
12
|
*/
|
|
10
13
|
import { type HostPolicy, type ProcedureModule, type ProcedureRegistry } from "@procedures/client";
|
|
11
14
|
import { type Peer, type PeerEndpoint } from "@procedures/peer";
|
|
@@ -26,6 +29,8 @@ export interface RunningServer {
|
|
|
26
29
|
token: string | undefined;
|
|
27
30
|
/** True when the token is random, for this run */
|
|
28
31
|
generatedToken: boolean;
|
|
32
|
+
/** The absolute path of the root of the `fs.*` procedures (`--fs-root`), or undefined. */
|
|
33
|
+
fsRoot?: string | undefined;
|
|
29
34
|
}
|
|
30
35
|
/** The options of `startServer()` and `runServer()`. */
|
|
31
36
|
export interface ServerRunOptions {
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EAML,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAc,KAAK,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAI5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA+C/C;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,GAAE,SAAS,MAAM,EAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,CAclI;AA8BD,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,kDAAkD;IAClD,cAAc,EAAE,OAAO,CAAC;IACxB,0FAA0F;IAC1F,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAWD,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,4GAA4G;IAC5G,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CAC7C;AAED,iGAAiG;AACjG,wBAAsB,WAAW,CAC/B,MAAM,EAAE,YAAY,EACpB,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAkB,EACzC,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,aAAa,CAAC,CA8CxB;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyD7F"}
|
package/dist/run.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* the host policy of the core (`hostPolicy()`): the token, the `--expose` list and the browser
|
|
7
7
|
* checks. A package without a module entry still works: the server imports it and takes the
|
|
8
8
|
* procedures that the import added to the global registry.
|
|
9
|
+
*
|
|
10
|
+
* The server always serves `events.subscribe` (`documentation/EVENTS.md`). Its topic rule is the
|
|
11
|
+
* `--events` patterns, and no topic without them. `--fs-root` confines the `fs.*` procedures.
|
|
9
12
|
*/
|
|
10
13
|
import { randomBytes } from "node:crypto";
|
|
11
14
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -13,8 +16,9 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
|
13
16
|
import { pathToFileURL } from "node:url";
|
|
14
17
|
import { PROCEDURE_REGISTRY, createRegistry, hostPolicy, pathToKey, } from "@procedures/client";
|
|
15
18
|
import { createPeer } from "@procedures/peer";
|
|
16
|
-
import
|
|
19
|
+
import peerModule from "@procedures/peer/module";
|
|
17
20
|
import { parseConfig } from "./config.js";
|
|
21
|
+
import { serverModule } from "./module.js";
|
|
18
22
|
import { seconds } from "@procedures/client";
|
|
19
23
|
/** A package name and the subpath after it: "@a/b/register" gives ["@a/b", "./register"]. */
|
|
20
24
|
function splitSpec(spec) {
|
|
@@ -90,6 +94,24 @@ async function importedModule(name, target) {
|
|
|
90
94
|
const added = PROCEDURE_REGISTRY.getAll().filter((procedure) => !before.has(pathToKey(procedure.path)));
|
|
91
95
|
return { name, procedures: added };
|
|
92
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* This function confines the `fs.*` procedures of the registry to the root of `--fs-root`, with
|
|
99
|
+
* `confineFsProcedures()` of `@procedures/fs` (roadmap R33). The package resolves from the
|
|
100
|
+
* folders of `resolveFrom`, then from this package. Without it, the server does not start.
|
|
101
|
+
*/
|
|
102
|
+
async function confineFs(registry, root, resolveFrom) {
|
|
103
|
+
const target = importTarget("@procedures/fs", "./module", resolveFrom) ?? "@procedures/fs/module";
|
|
104
|
+
let confine;
|
|
105
|
+
try {
|
|
106
|
+
confine = (await import(target)).confineFsProcedures;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw new Error(`--fs-root needs the package @procedures/fs: ${error instanceof Error ? error.message : String(error)}`);
|
|
110
|
+
}
|
|
111
|
+
if (typeof confine !== "function")
|
|
112
|
+
throw new Error("--fs-root needs @procedures/fs 0.5.0 or later (confineFsProcedures)");
|
|
113
|
+
return confine(registry, root);
|
|
114
|
+
}
|
|
93
115
|
/** The token of a configuration: `--token`, else `SERVER_TOKEN`, else a random one. `--no-token`: none. */
|
|
94
116
|
function tokenOf(config) {
|
|
95
117
|
const envToken = process.env["SERVER_TOKEN"] || undefined;
|
|
@@ -103,7 +125,9 @@ function tokenOf(config) {
|
|
|
103
125
|
}
|
|
104
126
|
/** This function starts the server of a configuration. It returns when the transports listen. */
|
|
105
127
|
export async function startServer(config, log = console.log, options = {}) {
|
|
106
|
-
|
|
128
|
+
// The server.* procedures: those of the peer package (server.create, server.call and the
|
|
129
|
+
// others), and server.start, server.stop and server.status of this package
|
|
130
|
+
const modules = [peerModule, serverModule];
|
|
107
131
|
for (const spec of config.procedures) {
|
|
108
132
|
if (config.verbose)
|
|
109
133
|
log(` Loading: ${spec}`);
|
|
@@ -117,12 +141,20 @@ export async function startServer(config, log = console.log, options = {}) {
|
|
|
117
141
|
const registry = createRegistry(...modules);
|
|
118
142
|
if (config.verbose)
|
|
119
143
|
log(` Registered procedures: ${registry.getAll().length}`);
|
|
144
|
+
// --fs-root: each fs.* procedure of the registry confines its paths, also for a nested call
|
|
145
|
+
const confined = config.fsRoot === undefined ? undefined : await confineFs(registry, config.fsRoot, options.resolveFrom ?? [process.cwd()]);
|
|
146
|
+
if (confined && config.verbose)
|
|
147
|
+
log(` Confined to ${confined.root}: ${confined.procedures.length} fs procedures`);
|
|
120
148
|
// A token by default: the server serves every procedure it loads, and any local program
|
|
121
149
|
// could call it. `--no-token` turns this off on purpose.
|
|
122
150
|
const { token, generated } = tokenOf(config);
|
|
123
151
|
const policy = hostPolicy({
|
|
124
152
|
...(config.expose.length > 0 ? { expose: config.expose } : {}),
|
|
125
153
|
...(token !== undefined ? { token } : {}),
|
|
154
|
+
// The remote events (EVENTS.md): the server always pins events.subscribe. Without --events,
|
|
155
|
+
// the topic rule is empty, so each subscription gets TOPIC_NOT_FOUND. The bus is the global
|
|
156
|
+
// bus, which is also the ctx.bus of the procedures.
|
|
157
|
+
events: { topics: config.events ?? [] },
|
|
126
158
|
});
|
|
127
159
|
const peer = await createPeer({
|
|
128
160
|
id: `peer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
@@ -131,7 +163,15 @@ export async function startServer(config, log = console.log, options = {}) {
|
|
|
131
163
|
policy,
|
|
132
164
|
});
|
|
133
165
|
await peer.start();
|
|
134
|
-
return {
|
|
166
|
+
return {
|
|
167
|
+
peer,
|
|
168
|
+
registry,
|
|
169
|
+
policy,
|
|
170
|
+
endpoints: peer.getEndpoints(),
|
|
171
|
+
token,
|
|
172
|
+
generatedToken: generated,
|
|
173
|
+
...(confined ? { fsRoot: confined.root } : {}),
|
|
174
|
+
};
|
|
135
175
|
}
|
|
136
176
|
/**
|
|
137
177
|
* The `server` CLI: parse the options, start the server, print where it listens, and keep the
|
|
@@ -162,6 +202,11 @@ export async function runServer(argv, options = {}) {
|
|
|
162
202
|
if (config.expose.length > 0) {
|
|
163
203
|
console.log(`Serves only: ${config.expose.join(", ")}`);
|
|
164
204
|
}
|
|
205
|
+
const events = config.events ?? [];
|
|
206
|
+
console.log(events.length > 0 ? `Event topics (events.subscribe): ${events.join(", ")}` : "Event topics: none (--events adds them)");
|
|
207
|
+
if (running.fsRoot !== undefined) {
|
|
208
|
+
console.log(`File root: ${running.fsRoot} (fs.* refuses each path outside it)`);
|
|
209
|
+
}
|
|
165
210
|
console.log("\nPress Ctrl+C to stop the server.");
|
|
166
211
|
// The peer stops before the process exits, with a limit of 10 seconds. A failed stop exits
|
|
167
212
|
// with 1, and a second signal exits at once (roadmap R5).
|
package/dist/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL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I,CAAC,CAAC,CAAC,CAAC;QAC9B,QAAQ,GAAG,IAAI,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAClC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;QAClD,0DAA0D;QAC1D,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAC3C,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EACrB,CAAC,KAAc,EAAE,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5G,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAE5B,yBAAyB;IACzB,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE;QACrB,yCAAyC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The input and output schemas of `server.start`, `server.stop` and `server.status`.
|
|
3
|
+
*
|
|
4
|
+
* The three procedures came from `@procedures/peer`: they manage the background server of the
|
|
5
|
+
* `mark` CLI, and this package holds the host. The input schemas validate each field, so the
|
|
6
|
+
* help of `mark server start` lists the options, and the port "abc" fails before the
|
|
7
|
+
* handler. The output schemas are loose objects: a field that a schema does not name stays in
|
|
8
|
+
* the result.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { type ZodLikeSchema } from "@procedures/client";
|
|
12
|
+
import type { ServerStartInput, ServerStartOutput, ServerStatusInput, ServerStatusOutput, ServerStopInput, ServerStopOutput } from "./types.js";
|
|
13
|
+
export declare const serverStartInputSchema: ZodLikeSchema<ServerStartInput>;
|
|
14
|
+
export declare const serverStopInputSchema: ZodLikeSchema<ServerStopInput>;
|
|
15
|
+
export declare const serverStatusInputSchema: ZodLikeSchema<ServerStatusInput>;
|
|
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
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAIpB,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,gBAAgB,CAMlE,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,eAAe,CAKhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,aAAa,CAAC,iBAAiB,CAIpE,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAO/D,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAG7D,CAAC;AAEH,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAUjE,CAAC"}
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The input and output schemas of `server.start`, `server.stop` and `server.status`.
|
|
3
|
+
*
|
|
4
|
+
* The three procedures came from `@procedures/peer`: they manage the background server of the
|
|
5
|
+
* `mark` CLI, and this package holds the host. The input schemas validate each field, so the
|
|
6
|
+
* help of `mark server start` lists the options, and the port "abc" fails before the
|
|
7
|
+
* handler. The output schemas are loose objects: a field that a schema does not name stays in
|
|
8
|
+
* the result.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { zodAdapter } from "@procedures/client";
|
|
12
|
+
const port = z.number().int().min(1).max(65535);
|
|
13
|
+
export const serverStartInputSchema = zodAdapter(z.object({
|
|
14
|
+
port: port.optional().describe("The port to listen on (default: 3000)"),
|
|
15
|
+
host: z.string().min(1).optional().describe("The host to bind to (default: 127.0.0.1)"),
|
|
16
|
+
transport: z.enum(["http", "websocket", "both"]).optional().describe("The transport (default: http)"),
|
|
17
|
+
}));
|
|
18
|
+
export const serverStopInputSchema = zodAdapter(z.object({
|
|
19
|
+
port: port.optional().describe("The port of the server to stop (default: all servers)"),
|
|
20
|
+
force: z.boolean().optional().describe("Stop with SIGKILL instead of SIGTERM"),
|
|
21
|
+
}));
|
|
22
|
+
export const serverStatusInputSchema = zodAdapter(z.object({
|
|
23
|
+
port: port.optional().describe("The port of the server (default: all servers)"),
|
|
24
|
+
}));
|
|
25
|
+
export const ServerStartOutputSchema = z.looseObject({
|
|
26
|
+
success: z.boolean().describe("True when the server started"),
|
|
27
|
+
pid: z.number().optional().describe("The process id of the server"),
|
|
28
|
+
port: z.number().optional().describe("The port of the server"),
|
|
29
|
+
endpoint: z.string().optional().describe("The URL of the server"),
|
|
30
|
+
logFile: z.string().optional().describe("The log file of the server"),
|
|
31
|
+
message: z.string().describe("A message about the result"),
|
|
32
|
+
});
|
|
33
|
+
export const ServerStopOutputSchema = z.looseObject({
|
|
34
|
+
success: z.boolean().describe("True when the server stopped"),
|
|
35
|
+
message: z.string().describe("A message about the result"),
|
|
36
|
+
});
|
|
37
|
+
export const ServerStatusOutputSchema = z.looseObject({
|
|
38
|
+
running: z.boolean().describe("True when a server runs"),
|
|
39
|
+
pid: z.number().optional().describe("The process id of the server"),
|
|
40
|
+
port: z.number().optional().describe("The port of the server"),
|
|
41
|
+
endpoint: z.string().optional().describe("The URL of the server"),
|
|
42
|
+
transport: z.string().optional().describe("The transport of the server"),
|
|
43
|
+
startedAt: z.string().optional().describe("The start time (ISO 8601)"),
|
|
44
|
+
uptime: z.string().optional().describe("The time since the start, as text"),
|
|
45
|
+
logFile: z.string().optional().describe("The log file of the server"),
|
|
46
|
+
message: z.string().describe("A message about the result"),
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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,CAAC,MAAM,sBAAsB,GAAoC,UAAU,CAC/E,CAAC,CAAC,MAAM,CAAC;IACP,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;IACvE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;IACvF,SAAS,EAAE,CAAC,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ose`): exact keys or `prefix.*`. Empty: every procedure. */
|
|
23
23
|
expose: string[];
|
|
24
|
+
/**
|
|
25
|
+
* The topic patterns of the remote events (`--events`): exact names, prefixes (`orders.*`) or
|
|
26
|
+
* `*`. Empty: the server serves no topic, and each subscription gets `TOPIC_NOT_FOUND`.
|
|
27
|
+
*/
|
|
28
|
+
events?: string[] | undefined;
|
|
29
|
+
/** The folder that confines each path of the `fs.*` procedures (`--fs-root`). Undefined: no root. */
|
|
30
|
+
fsRoot?: string | undefined;
|
|
24
31
|
}
|
|
25
32
|
export interface ServerCreateResult {
|
|
26
33
|
serverId: string;
|
|
@@ -30,4 +37,62 @@ export interface ServerCreateResult {
|
|
|
30
37
|
}>;
|
|
31
38
|
procedureCount: number;
|
|
32
39
|
}
|
|
40
|
+
export interface ServerStartInput {
|
|
41
|
+
/** Port to listen on */
|
|
42
|
+
port?: number | undefined;
|
|
43
|
+
/** Host to bind to */
|
|
44
|
+
host?: string | undefined;
|
|
45
|
+
/** Transport type */
|
|
46
|
+
transport?: "http" | "websocket" | "both" | undefined;
|
|
47
|
+
}
|
|
48
|
+
export interface ServerStartOutput {
|
|
49
|
+
/** Whether start succeeded */
|
|
50
|
+
success: boolean;
|
|
51
|
+
/** Process ID of server */
|
|
52
|
+
pid?: number | undefined;
|
|
53
|
+
/** Port server is running on */
|
|
54
|
+
port?: number | undefined;
|
|
55
|
+
/** Endpoint URL */
|
|
56
|
+
endpoint?: string | undefined;
|
|
57
|
+
/** Log file path */
|
|
58
|
+
logFile?: string | undefined;
|
|
59
|
+
/** Status message */
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ServerStopInput {
|
|
63
|
+
/** Port of server to stop (stops all if omitted) */
|
|
64
|
+
port?: number | undefined;
|
|
65
|
+
/** Force kill with SIGKILL instead of SIGTERM */
|
|
66
|
+
force?: boolean | undefined;
|
|
67
|
+
}
|
|
68
|
+
export interface ServerStopOutput {
|
|
69
|
+
/** Whether stop succeeded */
|
|
70
|
+
success: boolean;
|
|
71
|
+
/** Status message */
|
|
72
|
+
message: string;
|
|
73
|
+
}
|
|
74
|
+
export interface ServerStatusInput {
|
|
75
|
+
/** Port to check (shows all if omitted) */
|
|
76
|
+
port?: number | undefined;
|
|
77
|
+
}
|
|
78
|
+
export interface ServerStatusOutput {
|
|
79
|
+
/** Whether server is running */
|
|
80
|
+
running: boolean;
|
|
81
|
+
/** Process ID */
|
|
82
|
+
pid?: number | undefined;
|
|
83
|
+
/** Port */
|
|
84
|
+
port?: number | undefined;
|
|
85
|
+
/** Endpoint URL */
|
|
86
|
+
endpoint?: string | undefined;
|
|
87
|
+
/** Transport type */
|
|
88
|
+
transport?: string | undefined;
|
|
89
|
+
/** When server started (ISO string) */
|
|
90
|
+
startedAt?: string | undefined;
|
|
91
|
+
/** Human-readable uptime */
|
|
92
|
+
uptime?: string | undefined;
|
|
93
|
+
/** Log file path */
|
|
94
|
+
logFile?: string | undefined;
|
|
95
|
+
/** Status message */
|
|
96
|
+
message: string;
|
|
97
|
+
}
|
|
33
98
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,OAAO,EAAE,OAAO,C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,MAAM,GAAG,SAAS,CAAC;IAC/B,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/server",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "A standalone procedure server: load procedure packages and serve them over HTTP and WebSocket with a token and an expose list.",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"description": "A standalone procedure server: load procedure packages and serve them over HTTP and WebSocket with a token and an expose list. Its procedures server.start, server.stop and server.status manage the background server of the mark CLI.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"server",
|
|
8
8
|
"rpc",
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./module": {
|
|
33
|
+
"types": "./dist/module.d.ts",
|
|
34
|
+
"import": "./dist/module.js"
|
|
35
|
+
},
|
|
36
|
+
"./register": {
|
|
37
|
+
"types": "./dist/register.d.ts",
|
|
38
|
+
"import": "./dist/register.js"
|
|
31
39
|
}
|
|
32
40
|
},
|
|
33
41
|
"bin": {
|
|
@@ -41,7 +49,9 @@
|
|
|
41
49
|
"!src/**/__tests__",
|
|
42
50
|
"CHANGELOG.md"
|
|
43
51
|
],
|
|
44
|
-
"sideEffects":
|
|
52
|
+
"sideEffects": [
|
|
53
|
+
"./dist/register.js"
|
|
54
|
+
],
|
|
45
55
|
"engines": {
|
|
46
56
|
"node": ">=22"
|
|
47
57
|
},
|
|
@@ -50,15 +60,20 @@
|
|
|
50
60
|
"provenance": true
|
|
51
61
|
},
|
|
52
62
|
"dependencies": {
|
|
53
|
-
"@procedures/client": "0.
|
|
54
|
-
"@procedures/peer": "0.
|
|
63
|
+
"@procedures/client": "0.5.0",
|
|
64
|
+
"@procedures/peer": "0.5.0",
|
|
65
|
+
"zod": "^4.6.5"
|
|
55
66
|
},
|
|
56
67
|
"devDependencies": {
|
|
57
|
-
"typescript": "^7.0.2",
|
|
58
|
-
"@types/node": "^22.0.0",
|
|
59
68
|
"@mark1russell7/cue": "^1.0.0",
|
|
69
|
+
"@procedures/fs": "0.5.0",
|
|
70
|
+
"@types/node": "^22.0.0",
|
|
71
|
+
"typescript": "^7.0.2",
|
|
60
72
|
"vitest": "^5.0.3"
|
|
61
73
|
},
|
|
74
|
+
"client": {
|
|
75
|
+
"procedures": "./dist/register.js"
|
|
76
|
+
},
|
|
62
77
|
"scripts": {
|
|
63
78
|
"build": "tsc -b",
|
|
64
79
|
"typecheck": "tsc --noEmit",
|
package/src/config.ts
CHANGED
|
@@ -20,6 +20,29 @@ function parsePort(value: string): number {
|
|
|
20
20
|
return port;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/** The number of characters of a topic name (`MAX_TOPIC_LENGTH` of the core). */
|
|
24
|
+
const MAX_TOPIC_LENGTH = 256;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This function gives the topic patterns of an `--events` value: comma-separated exact names
|
|
28
|
+
* (`orders.created`), prefixes (`orders.*`) or `*` (`documentation/EVENTS.md`). A `*` is
|
|
29
|
+
* permitted only at the end of a pattern. The patterns are the topic rule of `topicMatcher()`.
|
|
30
|
+
*/
|
|
31
|
+
export function parseTopicPatterns(value: string): string[] {
|
|
32
|
+
const patterns = value
|
|
33
|
+
.split(",")
|
|
34
|
+
.map((pattern) => pattern.trim())
|
|
35
|
+
.filter((pattern) => pattern.length > 0);
|
|
36
|
+
if (patterns.length === 0) throw new Error("--events needs a topic pattern: an exact name, a prefix such as orders.*, or *");
|
|
37
|
+
for (const pattern of patterns) {
|
|
38
|
+
if (pattern.length > MAX_TOPIC_LENGTH) throw new Error(`The topic pattern "${pattern.slice(0, 40)}..." has more than ${MAX_TOPIC_LENGTH} characters`);
|
|
39
|
+
if (pattern.slice(0, -1).includes("*")) {
|
|
40
|
+
throw new Error(`Invalid topic pattern: "${pattern}". A * is permitted only at the end (orders.* or *).`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return patterns;
|
|
44
|
+
}
|
|
45
|
+
|
|
23
46
|
/**
|
|
24
47
|
* Parse command line arguments into server configuration.
|
|
25
48
|
*
|
|
@@ -40,6 +63,8 @@ export function parseConfig(argv: string[]): ServerConfig {
|
|
|
40
63
|
let verbose = false;
|
|
41
64
|
let serverToken: string | null | undefined;
|
|
42
65
|
const expose: string[] = [];
|
|
66
|
+
const events: string[] = [];
|
|
67
|
+
let fsRoot: string | undefined;
|
|
43
68
|
|
|
44
69
|
for (let i = 0; i < argv.length; i++) {
|
|
45
70
|
const token = argv[i]!;
|
|
@@ -98,6 +123,15 @@ export function parseConfig(argv: string[]): ServerConfig {
|
|
|
98
123
|
case "-e":
|
|
99
124
|
expose.push(...value().split(",").map((p) => p.trim()).filter((p) => p.length > 0));
|
|
100
125
|
break;
|
|
126
|
+
case "--events":
|
|
127
|
+
// Repeatable: each value adds its patterns to the topic rule
|
|
128
|
+
for (const pattern of parseTopicPatterns(value())) {
|
|
129
|
+
if (!events.includes(pattern)) events.push(pattern);
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
case "--fs-root":
|
|
133
|
+
fsRoot = value();
|
|
134
|
+
break;
|
|
101
135
|
case "--verbose":
|
|
102
136
|
case "-v":
|
|
103
137
|
verbose = true;
|
|
@@ -136,7 +170,7 @@ export function parseConfig(argv: string[]): ServerConfig {
|
|
|
136
170
|
return { type };
|
|
137
171
|
});
|
|
138
172
|
|
|
139
|
-
return { procedures, transports, verbose, token: serverToken, expose };
|
|
173
|
+
return { procedures, transports, verbose, token: serverToken, expose, events, ...(fsRoot !== undefined ? { fsRoot } : {}) };
|
|
140
174
|
}
|
|
141
175
|
|
|
142
176
|
function printHelp(): void {
|
|
@@ -176,6 +210,17 @@ OPTIONS:
|
|
|
176
210
|
(git.status) or prefixes (git.*)
|
|
177
211
|
Default: every loaded procedure
|
|
178
212
|
|
|
213
|
+
--events <patterns> The topics of the event bus that a peer can
|
|
214
|
+
subscribe to with events.subscribe: exact names
|
|
215
|
+
(orders.created), prefixes (orders.*) or *.
|
|
216
|
+
Repeatable, or comma-separated.
|
|
217
|
+
Default: no topics (TOPIC_NOT_FOUND)
|
|
218
|
+
|
|
219
|
+
--fs-root <folder> Confine each path of the fs.* procedures to this
|
|
220
|
+
folder, also the paths of their nested calls
|
|
221
|
+
from other procedures. A path outside gives
|
|
222
|
+
FORBIDDEN (outside-root). Default: no root
|
|
223
|
+
|
|
179
224
|
--verbose, -v Verbose output
|
|
180
225
|
|
|
181
226
|
--help, -h Show this help
|
|
@@ -189,5 +234,11 @@ EXAMPLES:
|
|
|
189
234
|
|
|
190
235
|
# Start with both HTTP and WebSocket
|
|
191
236
|
procedure-server -p @procedures/mongo/register -t http,websocket
|
|
237
|
+
|
|
238
|
+
# Serve the topics orders.* to subscribers over WebSocket
|
|
239
|
+
procedure-server -p ./my-procedures.js -t websocket --events "orders.*"
|
|
240
|
+
|
|
241
|
+
# Confine the file procedures to one folder
|
|
242
|
+
procedure-server -p @procedures/fs --fs-root ./data
|
|
192
243
|
`);
|
|
193
244
|
}
|