@orkestrel/server 0.0.4 → 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/package.json +11 -11
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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orkestrel/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A typed HTTP server for the @orkestrel line — composes the @orkestrel/router dispatcher behind a managed lifecycle. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"copy": "node -e \"const fs=require('node:fs'),p=require('node:path'),a=process.argv[1],b=process.argv[2];fs.mkdirSync(p.dirname(b),{recursive:true});fs.cpSync(a,b,{force:true});console.log('Copied: '+a+' to '+b)\"",
|
|
48
48
|
"tmp:txt": "node -e \"const fs=require('node:fs'),p=require('node:path');function walk(d){for(const e of fs.readdirSync(d,{withFileTypes:true})){const f=p.join(d,e.name);if(e.isDirectory()){walk(f)}else if(!e.name.endsWith('.md')&&!e.name.endsWith('.txt')){const t=f+'.txt';if(!fs.existsSync(t)){fs.renameSync(f,t)}else{console.warn('Skipping '+f+' — target exists: '+t)}}}}try{walk('tmp')}catch(e){if(e.code!=='ENOENT')throw e}\"",
|
|
49
49
|
"lint": "oxlint --config .oxlintrc.json --fix .",
|
|
50
|
-
"check": "tsc --noEmit --project tsconfig.json",
|
|
50
|
+
"check": "tsc --noEmit --project tsconfig.json && npm run check:src",
|
|
51
51
|
"check:src": "npm run check:src:server",
|
|
52
52
|
"check:src:server": "tsc --noEmit -p configs/src/tsconfig.server.json",
|
|
53
53
|
"format": "oxfmt --config .oxfmtrc.json --write .",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"build": "npm run clean && npm run build:src",
|
|
61
61
|
"build:src": "npm run build:src:server",
|
|
62
62
|
"build:src:server": "vite build --config configs/src/vite.server.config.ts && npm run copy dist/src/server/index.d.ts dist/src/server/index.d.cts",
|
|
63
|
-
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run
|
|
63
|
+
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@orkestrel/abort": "^0.0.
|
|
67
|
-
"@orkestrel/contract": "^0.0.
|
|
68
|
-
"@orkestrel/emitter": "^0.0.
|
|
69
|
-
"@orkestrel/router": "^0.0.
|
|
70
|
-
"@orkestrel/timeout": "^0.0.
|
|
66
|
+
"@orkestrel/abort": "^0.0.2",
|
|
67
|
+
"@orkestrel/contract": "^0.0.2",
|
|
68
|
+
"@orkestrel/emitter": "^0.0.2",
|
|
69
|
+
"@orkestrel/router": "^0.0.3",
|
|
70
|
+
"@orkestrel/timeout": "^0.0.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@microsoft/api-extractor": "^7.58.
|
|
74
|
-
"@orkestrel/guide": "^0.0.
|
|
73
|
+
"@microsoft/api-extractor": "^7.58.11",
|
|
74
|
+
"@orkestrel/guide": "^0.0.2",
|
|
75
75
|
"@types/node": "^26.1.1",
|
|
76
76
|
"@vitest/browser-playwright": "^4.1.10",
|
|
77
77
|
"oxfmt": "^0.59.0",
|
|
@@ -82,6 +82,6 @@
|
|
|
82
82
|
"vitest": "^4.1.10"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
|
-
"node": ">=
|
|
85
|
+
"node": ">=22"
|
|
86
86
|
}
|
|
87
87
|
}
|