@orkestrel/router 0.0.1

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.
@@ -0,0 +1,31 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ /**
3
+ * Options for `buildRequest` — how to derive the built `Request`'s origin.
4
+ *
5
+ * @remarks
6
+ * - `origin` — an explicit scheme + host to build the request URL against
7
+ * (`https://api.example.com`). Omitted ⇒ derived from the connection: the
8
+ * socket's `encrypted` presence picks `https`/`http`, and the `Host`
9
+ * header supplies the host (absent `Host` ⇒ `localhost`).
10
+ */
11
+ export interface RequestOptions {
12
+ readonly origin?: string;
13
+ }
14
+ /**
15
+ * A `node:http` request handler — the function `createListener` returns,
16
+ * matching `http.createServer`'s handler signature.
17
+ *
18
+ * @remarks
19
+ * Invoked once per incoming message with the raw `IncomingMessage`/
20
+ * `ServerResponse` pair; never returns a value (writes the response as a
21
+ * side effect).
22
+ */
23
+ export type ListenerFunction = (request: IncomingMessage, response: ServerResponse) => void;
24
+ /**
25
+ * Derives a consumer's opaque per-request `TState` from the raw
26
+ * `IncomingMessage` — the `state` argument `createListener` threads into
27
+ * `dispatcher.handle`.
28
+ *
29
+ * @typeParam TState - The consumer's opaque per-request state type
30
+ */
31
+ export type StateFunction<TState> = (message: IncomingMessage) => TState;
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@orkestrel/router",
3
+ "version": "0.0.1",
4
+ "description": "A typed request router for the @orkestrel line — server and browser environments. Part of the @orkestrel line.",
5
+ "keywords": [
6
+ "browser",
7
+ "router",
8
+ "routing",
9
+ "server",
10
+ "typescript",
11
+ "url"
12
+ ],
13
+ "homepage": "https://github.com/orkestrel/router#readme",
14
+ "bugs": "https://github.com/orkestrel/router/issues",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/orkestrel/router.git"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./dist/src/core/index.js",
27
+ "types": "./dist/src/core/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/src/core/index.d.ts",
31
+ "import": "./dist/src/core/index.js",
32
+ "default": "./dist/src/core/index.js"
33
+ },
34
+ "./browser": {
35
+ "types": "./dist/src/browser/index.d.ts",
36
+ "import": "./dist/src/browser/index.js",
37
+ "default": "./dist/src/browser/index.js"
38
+ },
39
+ "./server": {
40
+ "types": "./dist/src/server/index.d.ts",
41
+ "require": "./dist/src/server/index.cjs",
42
+ "default": "./dist/src/server/index.cjs"
43
+ },
44
+ "./package.json": "./package.json"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "clean": "node -e \"try{require('node:fs').rmSync('dist',{recursive:true,force:true})}catch{}\"",
51
+ "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)\"",
52
+ "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}\"",
53
+ "lint": "oxlint --config .oxlintrc.json --fix .",
54
+ "check": "tsc --noEmit --project tsconfig.json",
55
+ "check:src": "npm run check:src:core && npm run check:src:browser && npm run check:src:server",
56
+ "check:src:core": "tsc --noEmit -p configs/src/tsconfig.core.json",
57
+ "check:src:browser": "tsc --noEmit -p configs/src/tsconfig.browser.json",
58
+ "check:src:server": "tsc --noEmit -p configs/src/tsconfig.server.json",
59
+ "format": "oxfmt --config .oxfmtrc.json --write .",
60
+ "format:check": "oxfmt --config .oxfmtrc.json --check .",
61
+ "lint:check": "oxlint --config .oxlintrc.json .",
62
+ "test": "npm run test:src && npm run test:guides",
63
+ "test:src": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:core --project src:browser --project src:server",
64
+ "test:src:core": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:core",
65
+ "test:src:browser": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:browser",
66
+ "test:src:server": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:server",
67
+ "test:guides": "vitest run --config vite.config.ts --reporter=dot --project guides",
68
+ "build": "npm run clean && npm run build:src",
69
+ "build:src": "npm run build:src:core && npm run build:src:browser && npm run build:src:server",
70
+ "build:src:core": "vite build --config configs/src/vite.core.config.ts && tsc -p configs/src/tsconfig.core.json",
71
+ "build:src:browser": "vite build --config configs/src/vite.browser.config.ts && tsc -p configs/src/tsconfig.browser.json",
72
+ "build:src:server": "vite build --config configs/src/vite.server.config.ts && tsc -p configs/src/tsconfig.server.json",
73
+ "prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run check && npm run build && npm test"
74
+ },
75
+ "dependencies": {
76
+ "@orkestrel/abort": "^0.0.1",
77
+ "@orkestrel/contract": "^0.0.1",
78
+ "@orkestrel/emitter": "^0.0.1"
79
+ },
80
+ "devDependencies": {
81
+ "@orkestrel/guide": "^0.0.1",
82
+ "@types/node": "^26.1.1",
83
+ "@vitest/browser-playwright": "^4.1.10",
84
+ "oxfmt": "^0.58.0",
85
+ "oxlint": "^1.73.0",
86
+ "typescript": "^6.0.3",
87
+ "vite": "^8.1.4",
88
+ "vitest": "^4.1.10"
89
+ },
90
+ "engines": {
91
+ "node": ">=24"
92
+ }
93
+ }