@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 +53 -11
- package/dist/src/server/index.cjs +1697 -11
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +1584 -49
- package/dist/src/server/index.d.ts +1584 -49
- package/dist/src/server/index.js +1639 -7
- package/dist/src/server/index.js.map +1 -1
- package/package.json +17 -29
- package/dist/src/core/index.cjs +0 -1695
- package/dist/src/core/index.cjs.map +0 -1
- package/dist/src/core/index.d.cts +0 -1538
- package/dist/src/core/index.d.ts +0 -1538
- package/dist/src/core/index.js +0 -1641
- package/dist/src/core/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# @orkestrel/server
|
|
2
2
|
|
|
3
|
-
A typed HTTP server for the `@orkestrel` line — composes
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(
|
|
8
|
-
|
|
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
|
-
##
|
|
22
|
+
## Usage
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|