@orkestrel/router 0.0.2 → 0.0.3
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 +33 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -17,11 +17,40 @@ npm install @orkestrel/router
|
|
|
17
17
|
- ESM-only (no CommonJS build)
|
|
18
18
|
- Server and browser environments both supported
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createDispatcher, createRouter } from '@orkestrel/router'
|
|
24
|
+
|
|
25
|
+
const router = createRouter<{ readonly page: string }>()
|
|
26
|
+
router.add({ path: '/users/:id', meta: { page: 'profile' } })
|
|
27
|
+
router.match('/users/7') // { path: '/users/:id', params: { id: '7' }, meta: { page: 'profile' } }
|
|
28
|
+
|
|
29
|
+
const dispatcher = createDispatcher<{ readonly userId: string }>({
|
|
30
|
+
routes: [
|
|
31
|
+
{
|
|
32
|
+
method: 'GET',
|
|
33
|
+
path: '/users/:id',
|
|
34
|
+
handler: (_request, context) => Response.json(context.params),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
})
|
|
38
|
+
const response = await dispatcher.handle(new Request('http://x/users/7'), { userId: 'me' })
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`Router` is the shared registry-and-match engine — literal-over-param-over-wildcard
|
|
42
|
+
precedence, trailing-slash folding, and tolerant percent-decoding — that both `Dispatcher`
|
|
43
|
+
(fetch-standard, method-dimensioned) and the browser `Navigator` compose. Path params are
|
|
44
|
+
inferred at the type level from the literal pattern via `PathParams`, and `route()` pins a
|
|
45
|
+
`RouteInput`'s path so literal inference survives across call sites. The `./browser` entry
|
|
46
|
+
adds `createNavigator` for headless History/hash navigation; the `./server` entry adds
|
|
47
|
+
`buildRequest` / `sendResponse` / `createListener` for `node:http`.
|
|
48
|
+
|
|
49
|
+
## Guide
|
|
21
50
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
For the full surface — the core `Router`, the `Dispatcher`, the browser `Navigator`, and the
|
|
52
|
+
`node:http` server adapter — see
|
|
53
|
+
[`guides/src/router.md`](guides/src/router.md).
|
|
25
54
|
|
|
26
55
|
## Package
|
|
27
56
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orkestrel/router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A typed request router for the @orkestrel line — server and browser environments. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"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)\"",
|
|
63
63
|
"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}\"",
|
|
64
64
|
"lint": "oxlint --config .oxlintrc.json --fix .",
|
|
65
|
-
"check": "tsc --noEmit --project tsconfig.json",
|
|
65
|
+
"check": "tsc --noEmit --project tsconfig.json && npm run check:src",
|
|
66
66
|
"check:src": "npm run check:src:core && npm run check:src:browser && npm run check:src:server",
|
|
67
67
|
"check:src:core": "tsc --noEmit -p configs/src/tsconfig.core.json",
|
|
68
68
|
"check:src:browser": "tsc --noEmit -p configs/src/tsconfig.browser.json",
|
|
@@ -81,16 +81,16 @@
|
|
|
81
81
|
"build:src:core": "vite build --config configs/src/vite.core.config.ts && npm run copy dist/src/core/index.d.ts dist/src/core/index.d.cts",
|
|
82
82
|
"build:src:browser": "vite build --config configs/src/vite.browser.config.ts",
|
|
83
83
|
"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",
|
|
84
|
-
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run
|
|
84
|
+
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@orkestrel/abort": "^0.0.
|
|
88
|
-
"@orkestrel/contract": "^0.0.
|
|
89
|
-
"@orkestrel/emitter": "^0.0.
|
|
87
|
+
"@orkestrel/abort": "^0.0.2",
|
|
88
|
+
"@orkestrel/contract": "^0.0.2",
|
|
89
|
+
"@orkestrel/emitter": "^0.0.2"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@microsoft/api-extractor": "^7.58.
|
|
93
|
-
"@orkestrel/guide": "^0.0.
|
|
92
|
+
"@microsoft/api-extractor": "^7.58.11",
|
|
93
|
+
"@orkestrel/guide": "^0.0.2",
|
|
94
94
|
"@types/node": "^26.1.1",
|
|
95
95
|
"@vitest/browser-playwright": "^4.1.10",
|
|
96
96
|
"oxfmt": "^0.59.0",
|
|
@@ -101,6 +101,6 @@
|
|
|
101
101
|
"vitest": "^4.1.10"
|
|
102
102
|
},
|
|
103
103
|
"engines": {
|
|
104
|
-
"node": ">=
|
|
104
|
+
"node": ">=22"
|
|
105
105
|
}
|
|
106
106
|
}
|