@procedures/server 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,15 @@
1
+ # @procedures/server
2
+
3
+ ## 0.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0cf4bea]
8
+ - Updated dependencies [44d3e30]
9
+ - Updated dependencies [76d0d64]
10
+ - @procedures/client@0.2.0
11
+ - @procedures/peer@0.2.0
12
+
13
+ ## 0.1.0
14
+
15
+ The first release on npm. The packages of the client monorepo have one version together.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Mark Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,309 @@
1
- # Temporary Holding Version
1
+ # @procedures/server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@procedures/server?color=2346c4&label=npm)](https://www.npmjs.com/package/@procedures/server)
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D22-green.svg)](https://nodejs.org/)
8
+
9
+ > General procedure server - run any procedure packages via HTTP or WebSocket transports.
10
+
11
+ ## Table of Contents
12
+
13
+ - [Overview](#overview)
14
+ - [Installation](#installation)
15
+ - [Architecture](#architecture)
16
+ - [Quick Start](#quick-start)
17
+ - [CLI Reference](#cli-reference)
18
+ - [Examples](#examples)
19
+ - [Integration](#integration)
20
+ - [Requirements](#requirements)
21
+ - [License](#license)
22
+
23
+ ---
24
+
25
+ ## Overview
26
+
27
+ **server** is a CLI tool that runs procedure packages as HTTP/WebSocket servers:
28
+
29
+ - **Universal** - Run any combination of procedure packages
30
+ - **Multi-Transport** - HTTP, WebSocket, or both simultaneously
31
+ - **Dogfooding** - Uses `server.create` procedure internally
32
+ - **Zero Config** - Sensible defaults, fully configurable
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ npm install -g @procedures/server
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Architecture
45
+
46
+ ### System Overview
47
+
48
+ ```mermaid
49
+ graph TB
50
+ subgraph "CLI Entry"
51
+ CLI[server CLI]
52
+ Args[--procedures, --transport, --port]
53
+ end
54
+
55
+ subgraph "server package"
56
+ Parse[Parse Arguments]
57
+ Call[client.call]
58
+ end
59
+
60
+ subgraph "client-server"
61
+ Create[server.create]
62
+ Peer[Peer Instance]
63
+ end
64
+
65
+ subgraph "Transports"
66
+ HTTP[HTTP Transport<br/>:3000/api]
67
+ WS[WebSocket Transport<br/>ws://]
68
+ end
69
+
70
+ subgraph "Procedure Packages"
71
+ Mongo[client-mongo<br/>mongo.*]
72
+ FS[client-fs<br/>fs.*]
73
+ Git[client-git<br/>git.*]
74
+ end
75
+
76
+ CLI --> Parse
77
+ Args --> Parse
78
+ Parse --> Call
79
+ Call --> Create
80
+ Create --> Peer
81
+ Peer --> HTTP
82
+ Peer --> WS
83
+ HTTP --> Mongo
84
+ HTTP --> FS
85
+ WS --> Git
86
+ ```
87
+
88
+ ### Request Flow
89
+
90
+ ```mermaid
91
+ sequenceDiagram
92
+ participant Client as HTTP Client
93
+ participant HTTP as HTTP Transport
94
+ participant Peer as Peer Server
95
+ participant Registry as PROCEDURE_REGISTRY
96
+ participant Handler as Procedure Handler
97
+
98
+ Client->>HTTP: POST /api/mongo.documents.find
99
+ HTTP->>Peer: route(path, input)
100
+ Peer->>Registry: get(["mongo", "documents", "find"])
101
+ Registry-->>Peer: Procedure
102
+ Peer->>Handler: handler(input, ctx)
103
+ Handler-->>Peer: Result
104
+ Peer-->>HTTP: Response
105
+ HTTP-->>Client: JSON Response
106
+ ```
107
+
108
+ ### Dogfooding Pattern
109
+
110
+ ```mermaid
111
+ graph LR
112
+ subgraph "server CLI"
113
+ Entry[Entry Point]
114
+ ParseArgs[Parse CLI Args]
115
+ end
116
+
117
+ subgraph "Procedure Call"
118
+ Call["client.call(['server', 'create'], {...})"]
119
+ end
120
+
121
+ subgraph "client-server"
122
+ ServerCreate[server.create procedure]
123
+ PeerManager[Peer Manager]
124
+ end
125
+
126
+ Entry --> ParseArgs
127
+ ParseArgs --> Call
128
+ Call --> ServerCreate
129
+ ServerCreate --> PeerManager
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Quick Start
135
+
136
+ ```bash
137
+ # Start MongoDB procedure server
138
+ procedure-server --procedures @procedures/mongo/register --port 3000
139
+
140
+ # Start with multiple procedure packages
141
+ procedure-server -p @procedures/fs/register,@procedures/git/register
142
+
143
+ # Start with multiple transports
144
+ procedure-server -p @procedures/mongo/register -t http,websocket
145
+ ```
146
+
147
+ ---
148
+
149
+ ## CLI Reference
150
+
151
+ ### Options
152
+
153
+ | Option | Alias | Default | Description |
154
+ |--------|-------|---------|-------------|
155
+ | `--procedures` | `-p` | - | Comma-separated procedure packages to load |
156
+ | `--transport` | `-t` | `http` | Transports: http, websocket, local |
157
+ | `--port` | - | `3000` | Port for the primary transport |
158
+ | `--host` | - | `127.0.0.1` | Host to bind to. `0.0.0.0` serves every loaded procedure to the network |
159
+ | `--base-path` | - | `/api` | Base path for HTTP transport |
160
+ | `--cors` | - | off | Enable CORS |
161
+ | `--no-cors` | - | - | Disable CORS |
162
+ | `--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
+ | `--no-token` | - | - | Serve without a token (only on a trusted host) |
164
+ | `--expose` | `-e` | every loaded procedure | Comma-separated procedures to serve: exact keys (`git.status`) or prefixes (`git.*`) |
165
+ | `--verbose` | `-v` | - | Verbose output |
166
+ | `--help` | `-h` | - | Show help |
167
+
168
+ `mark serve` takes the same options and starts the same server.
169
+
170
+ The server has a registry of its own (roadmap 3.1): the `server.*` procedures and the `./module` entry of each `--procedures` 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
+
172
+ ### Transport Configuration
173
+
174
+ ```mermaid
175
+ graph TB
176
+ subgraph "HTTP Transport"
177
+ HTTPOpts["--transport http<br/>--port 3000<br/>--base-path /api<br/>--cors"]
178
+ end
179
+
180
+ subgraph "WebSocket Transport"
181
+ WSOpts["--transport websocket<br/>--port 3001"]
182
+ end
183
+
184
+ subgraph "Both Transports"
185
+ BothOpts["--transport http,websocket<br/>--port 3000"]
186
+ end
187
+
188
+ HTTPOpts --> Result1["http://0.0.0.0:3000/api"]
189
+ WSOpts --> Result2["ws://0.0.0.0:3001"]
190
+ BothOpts --> Result3["http + ws on :3000"]
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Examples
196
+
197
+ ### MongoDB Server
198
+
199
+ ```bash
200
+ procedure-server --procedures @procedures/mongo/register --port 3000
201
+ ```
202
+
203
+ **Output:**
204
+ ```
205
+ Starting procedure server...
206
+ Loading: @procedures/mongo/register
207
+
208
+ Server started!
209
+ Server ID: server-1703694523456
210
+ Procedures: 16
211
+
212
+ Endpoints:
213
+ [http] http://0.0.0.0:3000/api
214
+
215
+ Press Ctrl+C to stop the server.
216
+ ```
217
+
218
+ ### Multi-Package Server
219
+
220
+ ```bash
221
+ procedure-server -p @procedures/fs/register,@procedures/git/register \
222
+ -t http,websocket \
223
+ --port 3000
224
+ ```
225
+
226
+ ### Calling Procedures
227
+
228
+ ```bash
229
+ # HTTP call
230
+ curl -X POST http://localhost:3000/api/mongo.documents.find \
231
+ -H "Content-Type: application/json" \
232
+ -d '{"collection": "users", "filter": {"active": true}}'
233
+
234
+ # Response
235
+ {"documents": [{"_id": "...", "name": "Alice"}], "count": 1}
236
+ ```
237
+
238
+ ---
239
+
240
+ ## Integration
241
+
242
+ ### Replacing Domain-Specific Servers
243
+
244
+ The `server` package replaces domain-specific server packages:
245
+
246
+ ```bash
247
+ # OLD (deprecated)
248
+ npx @mark1russell7/server-mongo
249
+
250
+ # NEW (general)
251
+ npx procedure-server --procedures @procedures/mongo/register
252
+ ```
253
+
254
+ ### With client-server
255
+
256
+ The server CLI uses `server.create` procedure internally:
257
+
258
+ ```typescript
259
+ // What the CLI does internally:
260
+ await client.exec(["server", "create"], {
261
+ transports: [{ type: "http", port: 3000, cors: true }],
262
+ autoRegister: true,
263
+ });
264
+ ```
265
+
266
+ ### Package Hierarchy
267
+
268
+ ```mermaid
269
+ graph BT
270
+ subgraph "CLI"
271
+ Server[server<br/>CLI entry point]
272
+ end
273
+
274
+ subgraph "Procedure Layer"
275
+ ClientServer[client-server<br/>server.create]
276
+ end
277
+
278
+ subgraph "Core"
279
+ Client[client<br/>Peer, Transport]
280
+ end
281
+
282
+ subgraph "Procedure Packages"
283
+ Mongo[client-mongo]
284
+ FS[client-fs]
285
+ Git[client-git]
286
+ end
287
+
288
+ Server --> ClientServer
289
+ ClientServer --> Client
290
+ Mongo --> Client
291
+ FS --> Client
292
+ Git --> Client
293
+ ```
294
+
295
+ ---
296
+
297
+ ## Requirements
298
+
299
+ - **Node.js** >= 22
300
+ - **Dependencies:**
301
+ - `@procedures/client`
302
+ - `@procedures/peer`
303
+ - One or more procedure packages
304
+
305
+ ---
306
+
307
+ ## License
308
+
309
+ MIT