@procedures/server 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 +70 -0
- package/README.md +18 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- 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.map +1 -1
- package/dist/run.js +18 -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 +58 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +19 -5
- package/src/index.ts +26 -1
- 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 +20 -3
- package/src/schemas.ts +69 -0
- package/src/types.ts +76 -0
package/dist/run.js
CHANGED
|
@@ -13,8 +13,10 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
|
13
13
|
import { pathToFileURL } from "node:url";
|
|
14
14
|
import { PROCEDURE_REGISTRY, createRegistry, hostPolicy, pathToKey, } from "@procedures/client";
|
|
15
15
|
import { createPeer } from "@procedures/peer";
|
|
16
|
-
import
|
|
16
|
+
import peerModule from "@procedures/peer/module";
|
|
17
17
|
import { parseConfig } from "./config.js";
|
|
18
|
+
import { serverModule } from "./module.js";
|
|
19
|
+
import { seconds } from "@procedures/client";
|
|
18
20
|
/** A package name and the subpath after it: "@a/b/register" gives ["@a/b", "./register"]. */
|
|
19
21
|
function splitSpec(spec) {
|
|
20
22
|
const parts = spec.split("/");
|
|
@@ -102,7 +104,9 @@ function tokenOf(config) {
|
|
|
102
104
|
}
|
|
103
105
|
/** This function starts the server of a configuration. It returns when the transports listen. */
|
|
104
106
|
export async function startServer(config, log = console.log, options = {}) {
|
|
105
|
-
|
|
107
|
+
// The server.* procedures: those of the peer package (server.create, server.call and the
|
|
108
|
+
// others), and server.start, server.stop and server.status of this package
|
|
109
|
+
const modules = [peerModule, serverModule];
|
|
106
110
|
for (const spec of config.procedures) {
|
|
107
111
|
if (config.verbose)
|
|
108
112
|
log(` Loading: ${spec}`);
|
|
@@ -162,9 +166,20 @@ export async function runServer(argv, options = {}) {
|
|
|
162
166
|
console.log(`Serves only: ${config.expose.join(", ")}`);
|
|
163
167
|
}
|
|
164
168
|
console.log("\nPress Ctrl+C to stop the server.");
|
|
169
|
+
// The peer stops before the process exits, with a limit of 10 seconds. A failed stop exits
|
|
170
|
+
// with 1, and a second signal exits at once (roadmap R5).
|
|
171
|
+
let stopping = false;
|
|
165
172
|
const stop = () => {
|
|
173
|
+
if (stopping)
|
|
174
|
+
process.exit(1);
|
|
175
|
+
stopping = true;
|
|
166
176
|
console.log("\nShutting down...");
|
|
167
|
-
|
|
177
|
+
setTimeout(() => process.exit(1), 10_000).unref();
|
|
178
|
+
// The calls in flight have 5 seconds to end (roadmap R14)
|
|
179
|
+
running.peer.stop({ grace: seconds(5) }).then(() => process.exit(0), (error) => {
|
|
180
|
+
console.error(`The server did not stop cleanly: ${error instanceof Error ? error.message : String(error)}`);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
});
|
|
168
183
|
};
|
|
169
184
|
process.on("SIGINT", stop);
|
|
170
185
|
process.on("SIGTERM", stop);
|
package/dist/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,SAAS,GAKV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAgC,MAAM,kBAAkB,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;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,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,SAAS,GAKV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAgC,MAAM,kBAAkB,CAAC;AAC5E,OAAO,UAAU,MAAM,yBAAyB,CAAC;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AAE,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.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AAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IACjE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IACxE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IACtE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IAC3E,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IACrE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;CAC3D,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -30,4 +30,62 @@ export interface ServerCreateResult {
|
|
|
30
30
|
}>;
|
|
31
31
|
procedureCount: number;
|
|
32
32
|
}
|
|
33
|
+
export interface ServerStartInput {
|
|
34
|
+
/** Port to listen on */
|
|
35
|
+
port?: number | undefined;
|
|
36
|
+
/** Host to bind to */
|
|
37
|
+
host?: string | undefined;
|
|
38
|
+
/** Transport type */
|
|
39
|
+
transport?: "http" | "websocket" | "both" | undefined;
|
|
40
|
+
}
|
|
41
|
+
export interface ServerStartOutput {
|
|
42
|
+
/** Whether start succeeded */
|
|
43
|
+
success: boolean;
|
|
44
|
+
/** Process ID of server */
|
|
45
|
+
pid?: number | undefined;
|
|
46
|
+
/** Port server is running on */
|
|
47
|
+
port?: number | undefined;
|
|
48
|
+
/** Endpoint URL */
|
|
49
|
+
endpoint?: string | undefined;
|
|
50
|
+
/** Log file path */
|
|
51
|
+
logFile?: string | undefined;
|
|
52
|
+
/** Status message */
|
|
53
|
+
message: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ServerStopInput {
|
|
56
|
+
/** Port of server to stop (stops all if omitted) */
|
|
57
|
+
port?: number | undefined;
|
|
58
|
+
/** Force kill with SIGKILL instead of SIGTERM */
|
|
59
|
+
force?: boolean | undefined;
|
|
60
|
+
}
|
|
61
|
+
export interface ServerStopOutput {
|
|
62
|
+
/** Whether stop succeeded */
|
|
63
|
+
success: boolean;
|
|
64
|
+
/** Status message */
|
|
65
|
+
message: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ServerStatusInput {
|
|
68
|
+
/** Port to check (shows all if omitted) */
|
|
69
|
+
port?: number | undefined;
|
|
70
|
+
}
|
|
71
|
+
export interface ServerStatusOutput {
|
|
72
|
+
/** Whether server is running */
|
|
73
|
+
running: boolean;
|
|
74
|
+
/** Process ID */
|
|
75
|
+
pid?: number | undefined;
|
|
76
|
+
/** Port */
|
|
77
|
+
port?: number | undefined;
|
|
78
|
+
/** Endpoint URL */
|
|
79
|
+
endpoint?: string | undefined;
|
|
80
|
+
/** Transport type */
|
|
81
|
+
transport?: string | undefined;
|
|
82
|
+
/** When server started (ISO string) */
|
|
83
|
+
startedAt?: string | undefined;
|
|
84
|
+
/** Human-readable uptime */
|
|
85
|
+
uptime?: string | undefined;
|
|
86
|
+
/** Log file path */
|
|
87
|
+
logFile?: string | undefined;
|
|
88
|
+
/** Status message */
|
|
89
|
+
message: string;
|
|
90
|
+
}
|
|
33
91
|
//# 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,EAA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AC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,mBAAmB;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,uCAAuC;IACvC,SAAS,CAAC,EAAE,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.4.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,8 +60,9 @@
|
|
|
50
60
|
"provenance": true
|
|
51
61
|
},
|
|
52
62
|
"dependencies": {
|
|
53
|
-
"@procedures/client": "0.
|
|
54
|
-
"@procedures/peer": "0.
|
|
63
|
+
"@procedures/client": "0.4.0",
|
|
64
|
+
"@procedures/peer": "0.4.0",
|
|
65
|
+
"zod": "^4.6.5"
|
|
55
66
|
},
|
|
56
67
|
"devDependencies": {
|
|
57
68
|
"typescript": "^7.0.2",
|
|
@@ -59,6 +70,9 @@
|
|
|
59
70
|
"@mark1russell7/cue": "^1.0.0",
|
|
60
71
|
"vitest": "^5.0.3"
|
|
61
72
|
},
|
|
73
|
+
"client": {
|
|
74
|
+
"procedures": "./dist/register.js"
|
|
75
|
+
},
|
|
62
76
|
"scripts": {
|
|
63
77
|
"build": "tsc -b",
|
|
64
78
|
"typecheck": "tsc --noEmit",
|
package/src/index.ts
CHANGED
|
@@ -8,4 +8,29 @@
|
|
|
8
8
|
|
|
9
9
|
export { parseConfig } from "./config.js";
|
|
10
10
|
export { runServer, startServer, loadProcedureModule, type RunningServer, type ServerRunOptions } from "./run.js";
|
|
11
|
-
export type {
|
|
11
|
+
export type {
|
|
12
|
+
ServerConfig,
|
|
13
|
+
TransportConfig,
|
|
14
|
+
ServerCreateResult,
|
|
15
|
+
ServerStartInput,
|
|
16
|
+
ServerStartOutput,
|
|
17
|
+
ServerStopInput,
|
|
18
|
+
ServerStopOutput,
|
|
19
|
+
ServerStatusInput,
|
|
20
|
+
ServerStatusOutput,
|
|
21
|
+
} from "./types.js";
|
|
22
|
+
|
|
23
|
+
// server.start, server.stop and server.status (from @procedures/peer). The root registers
|
|
24
|
+
// nothing: import "@procedures/server/register", or give the module to createRegistry().
|
|
25
|
+
export * from "./module.js";
|
|
26
|
+
export { serverStartProcedure } from "./procedures/server.start.js";
|
|
27
|
+
export { serverStopProcedure } from "./procedures/server.stop.js";
|
|
28
|
+
export { serverStatusProcedure } from "./procedures/server.status.js";
|
|
29
|
+
export {
|
|
30
|
+
serverStartInputSchema,
|
|
31
|
+
serverStopInputSchema,
|
|
32
|
+
serverStatusInputSchema,
|
|
33
|
+
ServerStartOutputSchema,
|
|
34
|
+
ServerStopOutputSchema,
|
|
35
|
+
ServerStatusOutputSchema,
|
|
36
|
+
} from "./schemas.js";
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module (no side effects): the procedures of this package as data, for `createRegistry()`.
|
|
3
|
+
*
|
|
4
|
+
* The package holds the host: the `server` CLI, `mark serve`, and the procedures that manage the
|
|
5
|
+
* background server of the `mark` CLI. `server.start`, `server.stop` and `server.status` came
|
|
6
|
+
* from `@procedures/peer`. Their names stay the same. The other `server.*` procedures
|
|
7
|
+
* (`server.create`, `server.connect` and the others) stay in the peer package.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { defineModule, registerModules, PROCEDURE_REGISTRY, type AnyProcedure, type ProcedureModule, type ProcedureRegistry } from "@procedures/client";
|
|
11
|
+
import { serverStartProcedure } from "./procedures/server.start.js";
|
|
12
|
+
import { serverStopProcedure } from "./procedures/server.stop.js";
|
|
13
|
+
import { serverStatusProcedure } from "./procedures/server.status.js";
|
|
14
|
+
|
|
15
|
+
/** The procedures of the host: `server.start`, `server.stop` and `server.status`. */
|
|
16
|
+
export const hostProcedures: readonly AnyProcedure[] = [serverStartProcedure, serverStopProcedure, serverStatusProcedure];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The module of this package, for `createRegistry()`: its procedures as data. Importing this
|
|
20
|
+
* file registers nothing. (`register.ts` registers the same procedures in the global registry.)
|
|
21
|
+
*/
|
|
22
|
+
export const serverModule: ProcedureModule = defineModule("@procedures/server", [...hostProcedures]);
|
|
23
|
+
|
|
24
|
+
export default serverModule;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This function registers the procedures of @procedures/server in a registry. The default is the
|
|
28
|
+
* global registry. Importing this file registers nothing: the `./register` entry starts this
|
|
29
|
+
* function (ARCHITECTURE-PROPOSALS-2026-10, P9).
|
|
30
|
+
*/
|
|
31
|
+
export function registerServerProcedures(registry: ProcedureRegistry = PROCEDURE_REGISTRY): void {
|
|
32
|
+
registerModules(registry, [serverModule]);
|
|
33
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: server.start
|
|
3
|
+
* Starts the CLI server as a background daemon
|
|
4
|
+
*
|
|
5
|
+
* The procedure came from `@procedures/peer`: it belongs to the host. The lockfiles stay in the
|
|
6
|
+
* peer package, because the peer of `mark --server` writes them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import * as os from "node:os";
|
|
13
|
+
import { createProcedure, zodAdapter, type Effects, type Procedure } from "@procedures/client";
|
|
14
|
+
import { checkServer, readLockfileForPort } from "@procedures/peer/lockfile";
|
|
15
|
+
import { ServerStartOutputSchema, serverStartInputSchema } from "../schemas.js";
|
|
16
|
+
import type { ServerStartInput, ServerStartOutput } from "../types.js";
|
|
17
|
+
|
|
18
|
+
const MARK_DIR = path.join(os.homedir(), ".mark");
|
|
19
|
+
const SERVERS_DIR = path.join(MARK_DIR, "servers");
|
|
20
|
+
const LOG_PATH = path.join(MARK_DIR, "server.log");
|
|
21
|
+
const LOG_PREV_PATH = path.join(MARK_DIR, "server.log.1");
|
|
22
|
+
|
|
23
|
+
const serverStartOutputSchema = zodAdapter<ServerStartOutput>(ServerStartOutputSchema);
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if process is alive
|
|
28
|
+
*/
|
|
29
|
+
function isProcessAlive(pid: number): boolean {
|
|
30
|
+
try {
|
|
31
|
+
process.kill(pid, 0);
|
|
32
|
+
return true;
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Rotate log file
|
|
40
|
+
*/
|
|
41
|
+
function rotateLog(): void {
|
|
42
|
+
try {
|
|
43
|
+
fs.mkdirSync(MARK_DIR, { recursive: true });
|
|
44
|
+
if (fs.existsSync(LOG_PATH)) {
|
|
45
|
+
fs.renameSync(LOG_PATH, LOG_PREV_PATH);
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
// Ignore rotation errors
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Find the CLI entry point
|
|
54
|
+
*/
|
|
55
|
+
function findCliPath(): string {
|
|
56
|
+
// First, try to use the currently running script if it's the CLI
|
|
57
|
+
const currentScript = process.argv[1];
|
|
58
|
+
if (currentScript) {
|
|
59
|
+
// Normalize path for cross-platform check
|
|
60
|
+
const normalized = currentScript.replace(/\\/g, "/");
|
|
61
|
+
// mark runs as dist/bin.js (its bin) or dist/cli.js
|
|
62
|
+
if (normalized.endsWith("/dist/bin.js") || normalized.endsWith("cli.js") || normalized.includes("cli/dist")) {
|
|
63
|
+
// Return absolute path
|
|
64
|
+
return path.resolve(currentScript);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Try to find the mark CLI in node_modules or as a direct path
|
|
69
|
+
const candidates = [
|
|
70
|
+
path.join(process.cwd(), "node_modules", "@procedures", "mark", "dist", "cli.js"),
|
|
71
|
+
path.join(process.cwd(), "node_modules", ".bin", "mark"),
|
|
72
|
+
// Check parent directories for monorepo setups
|
|
73
|
+
path.join(process.cwd(), "..", "cli", "dist", "cli.js"),
|
|
74
|
+
// Direct check in current directory
|
|
75
|
+
path.join(process.cwd(), "dist", "cli.js"),
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
// Check which candidate exists
|
|
79
|
+
for (const candidate of candidates) {
|
|
80
|
+
if (fs.existsSync(candidate)) {
|
|
81
|
+
return candidate;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Fallback: try mark in PATH (will fail if not installed globally)
|
|
86
|
+
return "mark";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const serverStartProcedure: Procedure<
|
|
90
|
+
ServerStartInput,
|
|
91
|
+
ServerStartOutput,
|
|
92
|
+
{ description: string; effects: Effects; args: string[]; shorts: Record<string, string> }
|
|
93
|
+
> = createProcedure()
|
|
94
|
+
.path(["server", "start"])
|
|
95
|
+
.input(serverStartInputSchema)
|
|
96
|
+
.output(serverStartOutputSchema)
|
|
97
|
+
.meta({
|
|
98
|
+
description: "Start CLI server as background daemon",
|
|
99
|
+
// The daemon loads the procedure packages of the workspace. The procedure moves server.log
|
|
100
|
+
// over server.log.1.
|
|
101
|
+
effects: { reads: ["fs", "server"], writes: ["fs", "network", "process", "server"] },
|
|
102
|
+
args: [],
|
|
103
|
+
shorts: { port: "p", host: "h" },
|
|
104
|
+
})
|
|
105
|
+
.handler(async (input: ServerStartInput): Promise<ServerStartOutput> => {
|
|
106
|
+
const port = input.port ?? 3000;
|
|
107
|
+
// Loopback by default; pass host: "0.0.0.0" to expose on the LAN deliberately.
|
|
108
|
+
// See documentation/BUGS-2026-07.md (H19).
|
|
109
|
+
const host = input.host ?? "127.0.0.1";
|
|
110
|
+
const transport = input.transport ?? "http";
|
|
111
|
+
|
|
112
|
+
// Check if server is already running on this port
|
|
113
|
+
const existing = readLockfileForPort(port);
|
|
114
|
+
if (existing && (await checkServer(existing)) === "alive") {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
message: `Server already running on port ${port} (PID ${existing.pid})`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Rotate log file
|
|
122
|
+
rotateLog();
|
|
123
|
+
|
|
124
|
+
// Ensure directories exist
|
|
125
|
+
fs.mkdirSync(SERVERS_DIR, { recursive: true });
|
|
126
|
+
|
|
127
|
+
// Open log file for writing
|
|
128
|
+
const logFd = fs.openSync(LOG_PATH, "a");
|
|
129
|
+
|
|
130
|
+
// Find CLI path
|
|
131
|
+
const cliPath = findCliPath();
|
|
132
|
+
|
|
133
|
+
// Build arguments
|
|
134
|
+
const args = ["--server", "--port", String(port), "--host", host];
|
|
135
|
+
if (transport !== "http") {
|
|
136
|
+
args.push("--transport", transport);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Determine how to spawn
|
|
140
|
+
let spawnCmd: string;
|
|
141
|
+
let spawnArgs: string[];
|
|
142
|
+
|
|
143
|
+
if (cliPath === "mark" || cliPath.endsWith(".bin/mark") || cliPath.endsWith(".bin\\mark")) {
|
|
144
|
+
// Use mark command directly
|
|
145
|
+
spawnCmd = cliPath;
|
|
146
|
+
spawnArgs = args;
|
|
147
|
+
} else {
|
|
148
|
+
// Use node to run the JS file
|
|
149
|
+
spawnCmd = process.execPath;
|
|
150
|
+
spawnArgs = [cliPath, ...args];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Spawn daemon process
|
|
154
|
+
const child = spawn(spawnCmd, spawnArgs, {
|
|
155
|
+
detached: true,
|
|
156
|
+
stdio: ["ignore", logFd, logFd],
|
|
157
|
+
env: { ...process.env },
|
|
158
|
+
cwd: process.cwd(),
|
|
159
|
+
// No console window on Windows (deep dive CLI-16)
|
|
160
|
+
windowsHide: true,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Unref so parent can exit
|
|
164
|
+
child.unref();
|
|
165
|
+
fs.closeSync(logFd);
|
|
166
|
+
|
|
167
|
+
// Poll for lockfile (server takes ~4-8s to load ecosystem)
|
|
168
|
+
const maxWait = 15000;
|
|
169
|
+
const pollInterval = 500;
|
|
170
|
+
const startTime = Date.now();
|
|
171
|
+
|
|
172
|
+
while (Date.now() - startTime < maxWait) {
|
|
173
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
174
|
+
|
|
175
|
+
// Check if child died
|
|
176
|
+
if (child.pid && !isProcessAlive(child.pid)) {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Check for lockfile
|
|
181
|
+
const lockfile = readLockfileForPort(port);
|
|
182
|
+
if (lockfile && (await checkServer(lockfile)) === "alive") {
|
|
183
|
+
return {
|
|
184
|
+
success: true,
|
|
185
|
+
pid: lockfile.pid,
|
|
186
|
+
port: lockfile.port,
|
|
187
|
+
endpoint: lockfile.endpoint,
|
|
188
|
+
logFile: LOG_PATH,
|
|
189
|
+
message: `Server started (PID ${lockfile.pid})`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Timed out waiting for lockfile, but child may still be alive
|
|
195
|
+
if (child.pid && isProcessAlive(child.pid)) {
|
|
196
|
+
return {
|
|
197
|
+
success: true,
|
|
198
|
+
pid: child.pid,
|
|
199
|
+
port,
|
|
200
|
+
endpoint: `http://${host === "0.0.0.0" ? "localhost" : host}:${port}/api`,
|
|
201
|
+
logFile: LOG_PATH,
|
|
202
|
+
message: `Server starting (PID ${child.pid}, still loading...)`,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
success: false,
|
|
208
|
+
message: `Failed to start server. Check ${LOG_PATH} for details.`,
|
|
209
|
+
};
|
|
210
|
+
})
|
|
211
|
+
.build();
|
|
212
|
+
|
|
213
|
+
export type { ServerStartInput, ServerStartOutput };
|