@orkestrel/server 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # @orkestrel/server
2
2
 
3
- A typed HTTP server for the `@orkestrel` line — composes the
4
- `@orkestrel/router` dispatcher behind a managed lifecycle over a pluggable
5
- node adapter seam. Built to sit beside `@orkestrel/contract` (validation),
6
- `@orkestrel/emitter` (observable lifecycle), and `@orkestrel/abort`
7
- (cancellation), reusing all three as it takes shape. Its middleware
8
- architecture is still under design.
3
+ A typed HTTP server for the `@orkestrel` line — composes an `@orkestrel/router`
4
+ dispatcher behind a managed lifecycle (start/stop/drain/destroy) over a node
5
+ adapter seam, with a middleware onion, response observability, and a shared
6
+ substrate for cookies, tokens, content negotiation, and SSE. Built to sit
7
+ beside `@orkestrel/router` (routing, matching, and dispatch), `@orkestrel/contract`
8
+ (validation), `@orkestrel/emitter` (observable lifecycle), and `@orkestrel/abort`
9
+ (cancellation). Part of the `@orkestrel` line.
9
10
 
10
11
  ## Install
11
12
 
@@ -18,12 +19,53 @@ npm install @orkestrel/server
18
19
  - Node.js >= 24
19
20
  - ESM-only (no CommonJS build)
20
21
 
21
- ## Status
22
+ ## Usage
22
23
 
23
- The public API is under design and not yet implemented — this package
24
- currently ships no runtime code. An upcoming `PROPOSAL.md` will define the
25
- server surface (lifecycle, middleware, node adapter) before implementation
26
- begins.
24
+ ```ts
25
+ import type { MiddlewareHandler } from '@orkestrel/server'
26
+ import { createServer } from '@orkestrel/server'
27
+ import { createDispatcher } from '@orkestrel/router'
28
+
29
+ interface State {
30
+ readonly requestId: string
31
+ }
32
+
33
+ const dispatcher = createDispatcher<State>()
34
+ dispatcher.add({
35
+ method: 'GET',
36
+ path: '/users/:id',
37
+ handler: (_request, context) =>
38
+ Response.json({ id: context.params.id, requestId: context.state.requestId }),
39
+ })
40
+
41
+ const withRequestId: MiddlewareHandler<State> = async (_request, context, next) => {
42
+ const response = await next()
43
+ response.headers.set('X-Request-ID', context.state.requestId)
44
+ return response
45
+ }
46
+
47
+ const server = createServer<State>({
48
+ dispatcher,
49
+ state: () => ({ requestId: crypto.randomUUID() }),
50
+ middleware: [withRequestId],
51
+ })
52
+ const port = await server.start()
53
+ await server.stop()
54
+ ```
55
+
56
+ A route handler reads `context.state` exactly as middleware wrote it — the
57
+ composed onion terminates in the dispatcher, so there is no second plumbing
58
+ layer between the middleware seam and the router. The package also exports
59
+ `HTTPError` and its subclasses, the `compose` middleware primitive,
60
+ cookie/token/body helpers, `Negotiator` for content negotiation, and
61
+ `openStream` for Server-Sent Events.
62
+
63
+ ## Guide
64
+
65
+ For the full surface — the middleware seam, `HTTPError` vocabulary, shared
66
+ substrate (cookies, tokens, negotiation, ETag/Range, security headers, SSE,
67
+ body pipeline), and the `Server` lifecycle entity — see
68
+ [`guides/src/server.md`](guides/src/server.md).
27
69
 
28
70
  ## Package
29
71