@procedures/mark 0.4.0 → 0.6.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.
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Runs the CLI as a persistent server, exposing all ecosystem procedures
5
5
  * via HTTP. The server has the registry of mark (the module of each package, roadmap 3.1) and
6
- * the host policy of the core (roadmap 2.3): the token in the lockfile.
6
+ * the host policy of the core (roadmap 2.3): the token in the lockfile, and the topics of
7
+ * `--events`. With `--fs-root`, the `fs.*` procedures confine each path to the root.
7
8
  */
8
9
 
9
10
  import { print } from "./print.js";
@@ -17,6 +18,13 @@ export interface ServerModeOptions {
17
18
  host?: string;
18
19
  transport?: "http" | "websocket" | "both";
19
20
  verbose?: boolean;
21
+ /**
22
+ * The topic patterns of the remote events (`--events`, `documentation/EVENTS.md`). Empty or no
23
+ * value: the server serves no topic, and each subscription gets `TOPIC_NOT_FOUND`.
24
+ */
25
+ events?: readonly string[] | undefined;
26
+ /** The folder that confines each path of the `fs.*` procedures (`--fs-root`). */
27
+ fsRoot?: string | undefined;
20
28
  }
21
29
 
22
30
  interface ServerCreateResult {
@@ -75,7 +83,7 @@ export async function startServerMode(options: ServerModeOptions): Promise<void>
75
83
  if (verbose) {
76
84
  print.info("Loading ecosystem procedures...");
77
85
  }
78
- const { registry } = await loadEcosystemRegistry(verbose);
86
+ const { registry, fsRoot } = await loadEcosystemRegistry(verbose, true, { fsRoot: options.fsRoot });
79
87
 
80
88
  // Build transport config
81
89
  const transports = buildTransports(options);
@@ -91,14 +99,17 @@ export async function startServerMode(options: ServerModeOptions): Promise<void>
91
99
  }
92
100
 
93
101
  // The host policy of the core (roadmap 2.3): the token of each transport. The server of mark
94
- // serves every procedure of the workspace to its one user, so it has no expose list.
102
+ // serves every procedure of the workspace to its one user, so it has no expose list. It always
103
+ // serves events.subscribe (EVENTS.md): the topic rule is the --events patterns, else empty.
104
+ // The bus is the global bus, which is also the ctx.bus of the procedures.
105
+ const events = [...(options.events ?? [])];
95
106
  const { hostPolicy } = await import("@procedures/client");
96
107
  const { createPeer } = await import("@procedures/peer");
97
108
  const peer = await createPeer({
98
109
  id: `peer-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
99
110
  transports,
100
111
  registry,
101
- policy: hostPolicy({ token }),
112
+ policy: hostPolicy({ token, events: { topics: events } }),
102
113
  });
103
114
  await peer.start();
104
115
  const result: ServerCreateResult = {
@@ -119,6 +130,8 @@ export async function startServerMode(options: ServerModeOptions): Promise<void>
119
130
  cwd: process.cwd(),
120
131
  build: currentBuild(),
121
132
  peerId: result.serverId,
133
+ // A client uses this server only with the same --fs-root (or none)
134
+ ...(fsRoot !== undefined ? { fsRoot } : {}),
122
135
  });
123
136
 
124
137
  print.success("\nCLI Server running!");
@@ -130,6 +143,10 @@ export async function startServerMode(options: ServerModeOptions): Promise<void>
130
143
  for (const endpoint of result.endpoints) {
131
144
  print.info(` [${endpoint.type}] ${endpoint.address}`);
132
145
  }
146
+ print.info(events.length > 0 ? `\nEvent topics (events.subscribe): ${events.join(", ")}` : "\nEvent topics: none (--events adds them)");
147
+ if (fsRoot !== undefined) {
148
+ print.info(`File root: ${fsRoot} (fs.* refuses each path outside it)`);
149
+ }
133
150
  print.info("\nPress Ctrl+C to stop.");
134
151
 
135
152
  // Handle shutdown: the peer stops (its requests end and its ports close) before the process