@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
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { zodAdapter, type ZodLikeSchema } from "@procedures/client";
|
|
13
|
+
import type {
|
|
14
|
+
ServerStartInput,
|
|
15
|
+
ServerStartOutput,
|
|
16
|
+
ServerStatusInput,
|
|
17
|
+
ServerStatusOutput,
|
|
18
|
+
ServerStopInput,
|
|
19
|
+
ServerStopOutput,
|
|
20
|
+
} from "./types.js";
|
|
21
|
+
|
|
22
|
+
const port = z.number().int().min(1).max(65535);
|
|
23
|
+
|
|
24
|
+
export const serverStartInputSchema: ZodLikeSchema<ServerStartInput> = zodAdapter<ServerStartInput>(
|
|
25
|
+
z.object({
|
|
26
|
+
port: port.optional().describe("The port to listen on (default: 3000)"),
|
|
27
|
+
host: z.string().min(1).optional().describe("The host to bind to (default: 127.0.0.1)"),
|
|
28
|
+
transport: z.enum(["http", "websocket", "both"]).optional().describe("The transport (default: http)"),
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const serverStopInputSchema: ZodLikeSchema<ServerStopInput> = zodAdapter<ServerStopInput>(
|
|
33
|
+
z.object({
|
|
34
|
+
port: port.optional().describe("The port of the server to stop (default: all servers)"),
|
|
35
|
+
force: z.boolean().optional().describe("Stop with SIGKILL instead of SIGTERM"),
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const serverStatusInputSchema: ZodLikeSchema<ServerStatusInput> = zodAdapter<ServerStatusInput>(
|
|
40
|
+
z.object({
|
|
41
|
+
port: port.optional().describe("The port of the server (default: all servers)"),
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export const ServerStartOutputSchema: z.ZodType<ServerStartOutput> = 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
|
+
|
|
54
|
+
export const ServerStopOutputSchema: z.ZodType<ServerStopOutput> = z.looseObject({
|
|
55
|
+
success: z.boolean().describe("True when the server stopped"),
|
|
56
|
+
message: z.string().describe("A message about the result"),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const ServerStatusOutputSchema: z.ZodType<ServerStatusOutput> = z.looseObject({
|
|
60
|
+
running: z.boolean().describe("True when a server runs"),
|
|
61
|
+
pid: z.number().optional().describe("The process id of the server"),
|
|
62
|
+
port: z.number().optional().describe("The port of the server"),
|
|
63
|
+
endpoint: z.string().optional().describe("The URL of the server"),
|
|
64
|
+
transport: z.string().optional().describe("The transport of the server"),
|
|
65
|
+
startedAt: z.string().optional().describe("The start time (ISO 8601)"),
|
|
66
|
+
uptime: z.string().optional().describe("The time since the start, as text"),
|
|
67
|
+
logFile: z.string().optional().describe("The log file of the server"),
|
|
68
|
+
message: z.string().describe("A message about the result"),
|
|
69
|
+
});
|
package/src/types.ts
CHANGED
|
@@ -23,6 +23,13 @@ export interface ServerConfig {
|
|
|
23
23
|
token: string | null | undefined;
|
|
24
24
|
/** The procedures to serve (`--expose`): exact keys or `prefix.*`. Empty: every procedure. */
|
|
25
25
|
expose: string[];
|
|
26
|
+
/**
|
|
27
|
+
* The topic patterns of the remote events (`--events`): exact names, prefixes (`orders.*`) or
|
|
28
|
+
* `*`. Empty: the server serves no topic, and each subscription gets `TOPIC_NOT_FOUND`.
|
|
29
|
+
*/
|
|
30
|
+
events?: string[] | undefined;
|
|
31
|
+
/** The folder that confines each path of the `fs.*` procedures (`--fs-root`). Undefined: no root. */
|
|
32
|
+
fsRoot?: string | undefined;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
export interface ServerCreateResult {
|
|
@@ -30,3 +37,79 @@ export interface ServerCreateResult {
|
|
|
30
37
|
endpoints: Array<{ type: string; address: string }>;
|
|
31
38
|
procedureCount: number;
|
|
32
39
|
}
|
|
40
|
+
|
|
41
|
+
// =============================================================================
|
|
42
|
+
// server.start Types (from @procedures/peer)
|
|
43
|
+
// =============================================================================
|
|
44
|
+
|
|
45
|
+
export interface ServerStartInput {
|
|
46
|
+
/** Port to listen on */
|
|
47
|
+
port?: number | undefined;
|
|
48
|
+
/** Host to bind to */
|
|
49
|
+
host?: string | undefined;
|
|
50
|
+
/** Transport type */
|
|
51
|
+
transport?: "http" | "websocket" | "both" | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ServerStartOutput {
|
|
55
|
+
/** Whether start succeeded */
|
|
56
|
+
success: boolean;
|
|
57
|
+
/** Process ID of server */
|
|
58
|
+
pid?: number | undefined;
|
|
59
|
+
/** Port server is running on */
|
|
60
|
+
port?: number | undefined;
|
|
61
|
+
/** Endpoint URL */
|
|
62
|
+
endpoint?: string | undefined;
|
|
63
|
+
/** Log file path */
|
|
64
|
+
logFile?: string | undefined;
|
|
65
|
+
/** Status message */
|
|
66
|
+
message: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// =============================================================================
|
|
70
|
+
// server.stop Types (from @procedures/peer)
|
|
71
|
+
// =============================================================================
|
|
72
|
+
|
|
73
|
+
export interface ServerStopInput {
|
|
74
|
+
/** Port of server to stop (stops all if omitted) */
|
|
75
|
+
port?: number | undefined;
|
|
76
|
+
/** Force kill with SIGKILL instead of SIGTERM */
|
|
77
|
+
force?: boolean | undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ServerStopOutput {
|
|
81
|
+
/** Whether stop succeeded */
|
|
82
|
+
success: boolean;
|
|
83
|
+
/** Status message */
|
|
84
|
+
message: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// =============================================================================
|
|
88
|
+
// server.status Types (from @procedures/peer)
|
|
89
|
+
// =============================================================================
|
|
90
|
+
|
|
91
|
+
export interface ServerStatusInput {
|
|
92
|
+
/** Port to check (shows all if omitted) */
|
|
93
|
+
port?: number | undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ServerStatusOutput {
|
|
97
|
+
/** Whether server is running */
|
|
98
|
+
running: boolean;
|
|
99
|
+
/** Process ID */
|
|
100
|
+
pid?: number | undefined;
|
|
101
|
+
/** Port */
|
|
102
|
+
port?: number | undefined;
|
|
103
|
+
/** Endpoint URL */
|
|
104
|
+
endpoint?: string | undefined;
|
|
105
|
+
/** Transport type */
|
|
106
|
+
transport?: string | undefined;
|
|
107
|
+
/** When server started (ISO string) */
|
|
108
|
+
startedAt?: string | undefined;
|
|
109
|
+
/** Human-readable uptime */
|
|
110
|
+
uptime?: string | undefined;
|
|
111
|
+
/** Log file path */
|
|
112
|
+
logFile?: string | undefined;
|
|
113
|
+
/** Status message */
|
|
114
|
+
message: string;
|
|
115
|
+
}
|