@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# @procedures/server
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a47bee6: The hosts can confine the file procedures to a root (roadmap R33).
|
|
8
|
+
|
|
9
|
+
- `confineFsProcedures(registry, root)` of `@procedures/fs` replaces the handler of each `fs.*` procedure of a registry with the handler of `createFsModule({ root })`. It adds no procedure. A nested `fs.*` call of another procedure is confined too. The root must be a folder that exists.
|
|
10
|
+
- `mark --fs-root <folder>` confines the `fs.*` procedures of each mode and host of `mark`: a command, the REPL, `--server`, `serve` and `mcp`. Give the flag before the command.
|
|
11
|
+
- A `mark` command uses a CLI server only when the server has the same root. The lockfile of `@procedures/peer` has the new field `fsRoot`, and `findServer()` compares it.
|
|
12
|
+
- `procedure-server --fs-root <folder>` and `mark serve --fs-root <folder>` confine the procedures of the server.
|
|
13
|
+
- The MCP server reads `MCP_FS_ROOT`, and `mark mcp` has the flag `--fs-root`. `fs` is not a tool namespace, so the tools do not change.
|
|
14
|
+
- A path outside the root gives `FORBIDDEN` with the reason `outside-root`. A procedure that reads files with `node:fs`, or that starts a program, is not confined.
|
|
15
|
+
- `@procedures/lib/cli-flags` has the global flags `--fs-root` and `--events`, and the field `repeatable`.
|
|
16
|
+
- a47bee6: The hosts serve the remote events (`documentation/EVENTS.md`).
|
|
17
|
+
|
|
18
|
+
- `hostPolicy()` takes the option `events`: the topic rule, with an optional bus, `allow` function and buffer. `procedureServerOptions()` gives it to the `ProcedureServer`, which pins `events.subscribe`. `HostPolicy` has the new field `events`.
|
|
19
|
+
- `procedure-server` and `mark serve` have the option `--events <patterns>`. The option is repeatable, and it takes comma-separated patterns: exact names, prefixes (`orders.*`) or `*`. `parseTopicPatterns()` checks them.
|
|
20
|
+
- `mark --server` has the same option `--events`.
|
|
21
|
+
- These hosts always serve `events.subscribe`. Without `--events`, they serve no topic, and each subscription gets `TOPIC_NOT_FOUND`. The bus is the global bus, which is also the `ctx.bus` of their procedures.
|
|
22
|
+
- The MCP server serves no events, because its transport carries only MCP.
|
|
23
|
+
- `mark --port`, `--host`, `--transport` and `--events` without `--server` are an error now, also before `serve` and `mcp`. Before, `mark --port 4000 serve` ignored `--port`.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [0f75644]
|
|
28
|
+
- Updated dependencies [09e5566]
|
|
29
|
+
- Updated dependencies [ab77f75]
|
|
30
|
+
- Updated dependencies [a47bee6]
|
|
31
|
+
- Updated dependencies [a47bee6]
|
|
32
|
+
- Updated dependencies [bc74091]
|
|
33
|
+
- @procedures/client@0.5.0
|
|
34
|
+
- @procedures/peer@0.5.0
|
|
35
|
+
|
|
36
|
+
## 0.4.0
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- d42d716: `server.start`, `server.stop` and `server.status` moved from `@procedures/peer` to `@procedures/server`, the package of the host. Their names, schemas and effects stay the same. They manage the background server of the `mark` CLI.
|
|
41
|
+
|
|
42
|
+
In this version, `@procedures/server` has a `./module` entry, a `./register` entry and the `client.procedures` field, so `mark server start`, `mark server stop` and `mark server status` keep working. The registry of `procedure-server` and `mark serve` has the module of the peer package and the module of the server package, as before.
|
|
43
|
+
|
|
44
|
+
The module of `@procedures/peer` does not register the three procedures any more, and `@procedures/peer/procedures` does not export them. The lockfiles stay in `@procedures/peer/lockfile`.
|
|
45
|
+
|
|
46
|
+
`connect()` of `@procedures/peer` takes `WebSocketTransport` from `@procedures/client/node`, not from the root of `@procedures/client`. Thus a peer connection in Node uses the `WebSocket` class of `ws`, and a drop ends the socket at once with `terminate()`.
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [d919678]
|
|
51
|
+
- Updated dependencies [057d69a]
|
|
52
|
+
- Updated dependencies [b2a1a1e]
|
|
53
|
+
- Updated dependencies [057d69a]
|
|
54
|
+
- Updated dependencies [057d69a]
|
|
55
|
+
- Updated dependencies [057d69a]
|
|
56
|
+
- Updated dependencies [057d69a]
|
|
57
|
+
- Updated dependencies [057d69a]
|
|
58
|
+
- Updated dependencies [afd6a19]
|
|
59
|
+
- Updated dependencies [057d69a]
|
|
60
|
+
- Updated dependencies [d42d716]
|
|
61
|
+
- Updated dependencies [4e751da]
|
|
62
|
+
- @procedures/client@0.4.0
|
|
63
|
+
- @procedures/peer@0.4.0
|
|
64
|
+
|
|
3
65
|
## 0.3.0
|
|
4
66
|
|
|
5
67
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
- [Architecture](#architecture)
|
|
16
16
|
- [Quick Start](#quick-start)
|
|
17
17
|
- [CLI Reference](#cli-reference)
|
|
18
|
+
- [Procedures](#procedures)
|
|
18
19
|
- [Examples](#examples)
|
|
19
20
|
- [Integration](#integration)
|
|
20
21
|
- [Requirements](#requirements)
|
|
@@ -162,12 +163,37 @@ procedure-server -p @procedures/mongo/register -t http,websocket
|
|
|
162
163
|
| `--token` | - | `SERVER_TOKEN`, or a random token that the server prints | The token that every request sends: `Authorization: Bearer <token>`, or `?token=` for WebSocket |
|
|
163
164
|
| `--no-token` | - | - | Serve without a token (only on a trusted host) |
|
|
164
165
|
| `--expose` | `-e` | every loaded procedure | Comma-separated procedures to serve: exact keys (`git.status`) or prefixes (`git.*`) |
|
|
166
|
+
| `--events` | - | no topics | The topics of the event bus that a peer can subscribe to. Exact names (`orders.created`), prefixes (`orders.*`) or `*`. Repeat the option, or separate the patterns with commas. |
|
|
167
|
+
| `--fs-root` | - | no root | The folder that confines each path of the `fs.*` procedures, also in their nested calls |
|
|
165
168
|
| `--verbose` | `-v` | - | Verbose output |
|
|
166
169
|
| `--help` | `-h` | - | Show help |
|
|
167
170
|
|
|
168
|
-
`mark serve` takes the same options and starts the same server.
|
|
171
|
+
`mark serve` takes the same options and starts the same server. `mark --fs-root <folder> serve` gives the root to the server too.
|
|
169
172
|
|
|
170
|
-
|
|
173
|
+
### Remote events
|
|
174
|
+
|
|
175
|
+
The server always serves the procedure `events.subscribe` ([EVENTS.md](../documentation/EVENTS.md)). The `--events` patterns are its topic rule:
|
|
176
|
+
|
|
177
|
+
- Without `--events`, the rule is empty. Each subscription gets `TOPIC_NOT_FOUND`.
|
|
178
|
+
- The `--expose` list does not apply to `events.subscribe`. The topic rule is its expose rule.
|
|
179
|
+
- The bus is the global bus of the process. The procedures of the server get it as `ctx.bus`, so a procedure publishes with `ctx.bus.emit()`.
|
|
180
|
+
- The token applies to a subscription as to each call. The server has no capability, so it permits each subscription to a topic of the rule.
|
|
181
|
+
- A subscriber uses WebSocket (`transport.subscribe()`) or HTTP with NDJSON (`subscribeRemote()`).
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
procedure-server -p ./my-procedures.js -t http,websocket --events "orders.*" --events audit.created
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### The root of the file procedures
|
|
188
|
+
|
|
189
|
+
With `--fs-root <folder>`, the server starts `confineFsProcedures()` of `@procedures/fs` after it builds its registry (roadmap R33):
|
|
190
|
+
|
|
191
|
+
- Each `fs.*` procedure refuses a path outside the folder with `FORBIDDEN` and the reason `outside-root`. A relative path starts at the folder.
|
|
192
|
+
- A nested `fs.*` call of another procedure is confined too.
|
|
193
|
+
- The server does not start when the folder does not exist, or when it cannot load `@procedures/fs`.
|
|
194
|
+
- A procedure that reads files with `node:fs`, or that starts a program, is not confined. The [README of the MCP server](../impl-mcp-dev/README.md) lists them.
|
|
195
|
+
|
|
196
|
+
The server has a registry of its own (roadmap 3.1): the `server.*` procedures and the `./module` entry of each `--procedures` package. The `server.*` procedures come from two modules: the module of `@procedures/peer` (`server.create`, `server.call` and the others) and the module of this package. Two servers in one process serve only their own packages. `pkg/register`, the form of the old examples, gives the module of `pkg`. A package without a `./module` entry still works: the server takes the procedures that its import registers. The token, the `--expose` list and the browser checks come from `hostPolicy()` of `@procedures/client`.
|
|
171
197
|
|
|
172
198
|
### Transport Configuration
|
|
173
199
|
|
|
@@ -192,6 +218,22 @@ graph TB
|
|
|
192
218
|
|
|
193
219
|
---
|
|
194
220
|
|
|
221
|
+
## Procedures
|
|
222
|
+
|
|
223
|
+
The package has three procedures. They manage the background server of the `mark` CLI (`mark --server`). In version 0.3.0 and before, they were in `@procedures/peer`. Their names did not change.
|
|
224
|
+
|
|
225
|
+
| Procedure | Function |
|
|
226
|
+
|---|---|
|
|
227
|
+
| `server.start` | Start the CLI server as a background process. It writes `~/.mark/server.log`. |
|
|
228
|
+
| `server.stop` | Stop the CLI servers of the lockfiles, or the server of one port. A process that does not answer as the peer of its lockfile gets no signal. |
|
|
229
|
+
| `server.status` | Give the state of the CLI servers. It deletes the lockfile of a server that does not answer. |
|
|
230
|
+
|
|
231
|
+
- `import "@procedures/server/register"` registers them in the global registry. The package root and the `./module` entry register nothing.
|
|
232
|
+
- `mark` finds the package from its `client.procedures` field: `mark server start`, `mark server stop` and `mark server status` run them.
|
|
233
|
+
- The lockfiles stay in `@procedures/peer` (`@procedures/peer/lockfile`), because the peer of `mark --server` writes them.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
195
237
|
## Examples
|
|
196
238
|
|
|
197
239
|
### MongoDB Server
|