@usetoki/toki 0.1.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.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/app.d.ts +137 -0
- package/dist/app.js +608 -0
- package/dist/app.js.map +1 -0
- package/dist/cookies.d.ts +17 -0
- package/dist/cookies.js +54 -0
- package/dist/cookies.js.map +1 -0
- package/dist/forms.d.ts +13 -0
- package/dist/forms.js +64 -0
- package/dist/forms.js.map +1 -0
- package/dist/group.d.ts +19 -0
- package/dist/group.js +51 -0
- package/dist/group.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/inject.d.ts +19 -0
- package/dist/inject.js +56 -0
- package/dist/inject.js.map +1 -0
- package/dist/jwt.d.ts +57 -0
- package/dist/jwt.js +128 -0
- package/dist/jwt.js.map +1 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +45 -0
- package/dist/logger.js.map +1 -0
- package/dist/middleware.d.ts +38 -0
- package/dist/middleware.js +133 -0
- package/dist/middleware.js.map +1 -0
- package/dist/native.d.ts +81 -0
- package/dist/native.js +38 -0
- package/dist/native.js.map +1 -0
- package/dist/pipeline.d.ts +16 -0
- package/dist/pipeline.js +125 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/request.d.ts +65 -0
- package/dist/request.js +170 -0
- package/dist/request.js.map +1 -0
- package/dist/response.d.ts +33 -0
- package/dist/response.js +92 -0
- package/dist/response.js.map +1 -0
- package/dist/schema.d.ts +45 -0
- package/dist/schema.js +179 -0
- package/dist/schema.js.map +1 -0
- package/dist/static.d.ts +20 -0
- package/dist/static.js +105 -0
- package/dist/static.js.map +1 -0
- package/dist/types.d.ts +88 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +63 -0
package/dist/app.js
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import { joinPaths, RouteGroup } from "./group.js";
|
|
2
|
+
import { inject } from "./inject.js";
|
|
3
|
+
import { resolveLogger } from "./logger.js";
|
|
4
|
+
import { corsHeaders, corsPreflight } from "./middleware.js";
|
|
5
|
+
import { native, } from "./native.js";
|
|
6
|
+
import { contentTypeMatcher, isThenable, materialize, runAfter, runBefore, runSerialization, validationStep, } from "./pipeline.js";
|
|
7
|
+
import { TokiRequest } from "./request.js";
|
|
8
|
+
import { isStreamResponse, isTokiResponse, reply, toNative } from "./response.js";
|
|
9
|
+
import { buildStaticEntries } from "./static.js";
|
|
10
|
+
const NO_MIDDLEWARE = [];
|
|
11
|
+
// must match `not_found_index` in Zig
|
|
12
|
+
const NOT_FOUND_INDEX = 0xffffffff;
|
|
13
|
+
// pause a stream producer once the connection's write backlog passes this (1 MiB)
|
|
14
|
+
const STREAM_HIGH_WATER = 1 << 20;
|
|
15
|
+
function streamHeaderBlock(stream, staged) {
|
|
16
|
+
let headers = "";
|
|
17
|
+
for (const [name, value] of staged) {
|
|
18
|
+
headers += `${name}: ${value}\r\n`;
|
|
19
|
+
}
|
|
20
|
+
headers += `Content-Type: ${stream.contentType}\r\n`;
|
|
21
|
+
for (const [name, value] of stream.headers) {
|
|
22
|
+
headers += `${name}: ${value}\r\n`;
|
|
23
|
+
}
|
|
24
|
+
return headers;
|
|
25
|
+
}
|
|
26
|
+
function asArray(value) {
|
|
27
|
+
return value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encapsulated registration scope: own hooks, middleware, request decorators,
|
|
31
|
+
* error handler, and path prefix. Routes here run the hook chains of this scope
|
|
32
|
+
* and all ancestors. The root app ({@link Toki}) is itself a scope; {@link
|
|
33
|
+
* Scope.register} creates children.
|
|
34
|
+
*/
|
|
35
|
+
export class Scope {
|
|
36
|
+
parent;
|
|
37
|
+
prefix;
|
|
38
|
+
onRequest = [];
|
|
39
|
+
preParsing = [];
|
|
40
|
+
middleware = [];
|
|
41
|
+
preValidation = [];
|
|
42
|
+
preHandler = [];
|
|
43
|
+
preSerialization = [];
|
|
44
|
+
onResponse = [];
|
|
45
|
+
onSend = [];
|
|
46
|
+
onTimeout = [];
|
|
47
|
+
requestDecorators = {};
|
|
48
|
+
contentTypeParsers = [];
|
|
49
|
+
plugins = [];
|
|
50
|
+
errorHandler;
|
|
51
|
+
constructor(parent, prefix) {
|
|
52
|
+
this.parent = parent;
|
|
53
|
+
this.prefix = prefix;
|
|
54
|
+
}
|
|
55
|
+
get root() {
|
|
56
|
+
return this.parent ? this.parent.root : this;
|
|
57
|
+
}
|
|
58
|
+
get log() {
|
|
59
|
+
return this.root._logger;
|
|
60
|
+
}
|
|
61
|
+
get(path, a, b) {
|
|
62
|
+
return this.#add("GET", path, a, b);
|
|
63
|
+
}
|
|
64
|
+
post(path, a, b) {
|
|
65
|
+
return this.#add("POST", path, a, b);
|
|
66
|
+
}
|
|
67
|
+
put(path, a, b) {
|
|
68
|
+
return this.#add("PUT", path, a, b);
|
|
69
|
+
}
|
|
70
|
+
patch(path, a, b) {
|
|
71
|
+
return this.#add("PATCH", path, a, b);
|
|
72
|
+
}
|
|
73
|
+
delete(path, a, b) {
|
|
74
|
+
return this.#add("DELETE", path, a, b);
|
|
75
|
+
}
|
|
76
|
+
head(path, handler) {
|
|
77
|
+
return this.#add("HEAD", path, handler);
|
|
78
|
+
}
|
|
79
|
+
options(path, handler) {
|
|
80
|
+
return this.#add("OPTIONS", path, handler);
|
|
81
|
+
}
|
|
82
|
+
route(method, path, handler) {
|
|
83
|
+
return this.#add(method, path, handler);
|
|
84
|
+
}
|
|
85
|
+
#add(method, path, a, b) {
|
|
86
|
+
const [options, handler] = typeof a === "function" ? [{}, a] : [a, b];
|
|
87
|
+
this.root._pushRoute({
|
|
88
|
+
method,
|
|
89
|
+
path: joinPaths(this.prefix, path),
|
|
90
|
+
handler,
|
|
91
|
+
options,
|
|
92
|
+
groupMiddleware: NO_MIDDLEWARE,
|
|
93
|
+
scope: this,
|
|
94
|
+
});
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/** Add middleware; runs before every handler in this scope and descendants. */
|
|
98
|
+
use(middleware) {
|
|
99
|
+
this.middleware.push(middleware);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
addHook(name, fn) {
|
|
103
|
+
switch (name) {
|
|
104
|
+
case "onResponse":
|
|
105
|
+
this.onResponse.push(fn);
|
|
106
|
+
break;
|
|
107
|
+
case "onSend":
|
|
108
|
+
this.onSend.push(fn);
|
|
109
|
+
break;
|
|
110
|
+
case "preParsing":
|
|
111
|
+
this.preParsing.push(fn);
|
|
112
|
+
break;
|
|
113
|
+
case "preValidation":
|
|
114
|
+
this.preValidation.push(fn);
|
|
115
|
+
break;
|
|
116
|
+
case "preHandler":
|
|
117
|
+
this.preHandler.push(fn);
|
|
118
|
+
break;
|
|
119
|
+
case "preSerialization":
|
|
120
|
+
this.preSerialization.push(fn);
|
|
121
|
+
break;
|
|
122
|
+
case "onTimeout":
|
|
123
|
+
this.onTimeout.push(fn);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
this.onRequest.push(fn);
|
|
127
|
+
}
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/** Set the error handler for routes in this scope (alias: `onError`). */
|
|
131
|
+
setErrorHandler(handler) {
|
|
132
|
+
this.errorHandler = handler;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
onError(handler) {
|
|
136
|
+
return this.setErrorHandler(handler);
|
|
137
|
+
}
|
|
138
|
+
/** Attach a property to every request handled in this scope. */
|
|
139
|
+
decorateRequest(name, value) {
|
|
140
|
+
this.requestDecorators[name] = value;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Register a body parser for one or more content types, consulted by
|
|
145
|
+
* `req.parseBody()`. `type` matches case-insensitively as a prefix (e.g.
|
|
146
|
+
* `"application/xml"`), a `RegExp`, or `"*"` for any. A child scope overrides
|
|
147
|
+
* an ancestor for the same type.
|
|
148
|
+
*/
|
|
149
|
+
addContentTypeParser(type, parser) {
|
|
150
|
+
const tests = Array.isArray(type) ? type : [type];
|
|
151
|
+
for (const t of tests) {
|
|
152
|
+
this.contentTypeParsers.push({ test: contentTypeMatcher(t), parser });
|
|
153
|
+
}
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/** Attach a property to the application instance (app-global, not encapsulated). */
|
|
157
|
+
decorate(name, value) {
|
|
158
|
+
this.root._decorate(name, value);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/** Set the handler for unmatched routes (app-global). */
|
|
162
|
+
setNotFoundHandler(handler) {
|
|
163
|
+
this.root._setNotFound(handler);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/** Enable CORS: stage headers on every response and answer preflight `OPTIONS`. */
|
|
167
|
+
cors(options = {}) {
|
|
168
|
+
this.use(corsHeaders(options));
|
|
169
|
+
this.options("/*", corsPreflight(options));
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
/** Serve files under `dir` at `urlPrefix` (joined with this scope's prefix). */
|
|
173
|
+
static(urlPrefix, dir, options) {
|
|
174
|
+
this.root._mountStatic(joinPaths(this.prefix, urlPrefix), dir, options);
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
/** Register a prefixed group of routes with its own middleware. */
|
|
178
|
+
group(prefix, build) {
|
|
179
|
+
const group = new RouteGroup(prefix, (method, path, handler, middleware) => {
|
|
180
|
+
this.root._pushRoute({
|
|
181
|
+
method,
|
|
182
|
+
path: joinPaths(this.prefix, path),
|
|
183
|
+
handler,
|
|
184
|
+
options: {},
|
|
185
|
+
groupMiddleware: middleware,
|
|
186
|
+
scope: this,
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
build(group);
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Register a plugin into a fresh child scope. The plugin receives that scope as
|
|
194
|
+
* its `instance`; routes/hooks/decorators it adds are encapsulated there (and
|
|
195
|
+
* inherited by its own children), not leaked to the parent. Async plugins load
|
|
196
|
+
* during {@link Toki.ready}. `opts.prefix` mounts the plugin's routes under a path.
|
|
197
|
+
*/
|
|
198
|
+
register(plugin, opts = {}) {
|
|
199
|
+
const prefix = joinPaths(this.prefix, typeof opts.prefix === "string" ? opts.prefix : "/");
|
|
200
|
+
this.plugins.push({ plugin, opts, scope: new Scope(this, prefix) });
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The application. Register routes (optionally with a validation schema and
|
|
206
|
+
* route-scoped hooks), global hooks, middleware, and plugins, then
|
|
207
|
+
* {@link Toki.listen}. The pipeline stays synchronous until a step returns a
|
|
208
|
+
* `Promise`, keeping the common sync request on the fast path.
|
|
209
|
+
*/
|
|
210
|
+
export class Toki extends Scope {
|
|
211
|
+
#routes = [];
|
|
212
|
+
#onReady = [];
|
|
213
|
+
#onClose = [];
|
|
214
|
+
#staticMounts = [];
|
|
215
|
+
#loggerInstance;
|
|
216
|
+
#requestTimeoutMs;
|
|
217
|
+
#notFoundHandler;
|
|
218
|
+
#compiled = [];
|
|
219
|
+
#compiledNotFound;
|
|
220
|
+
#booted = false;
|
|
221
|
+
#boundPort = 0;
|
|
222
|
+
#listening = false;
|
|
223
|
+
constructor(options = {}) {
|
|
224
|
+
super(undefined, "");
|
|
225
|
+
this.#loggerInstance = resolveLogger(options.logger);
|
|
226
|
+
this.#requestTimeoutMs = options.requestTimeoutMs ?? 0;
|
|
227
|
+
}
|
|
228
|
+
/** @internal */
|
|
229
|
+
get _logger() {
|
|
230
|
+
return this.#loggerInstance;
|
|
231
|
+
}
|
|
232
|
+
/** @internal */
|
|
233
|
+
_pushRoute(route) {
|
|
234
|
+
this.#routes.push(route);
|
|
235
|
+
}
|
|
236
|
+
/** @internal */
|
|
237
|
+
_decorate(name, value) {
|
|
238
|
+
this[name] = value;
|
|
239
|
+
}
|
|
240
|
+
/** @internal */
|
|
241
|
+
_setNotFound(handler) {
|
|
242
|
+
this.#notFoundHandler = handler;
|
|
243
|
+
}
|
|
244
|
+
/** @internal */
|
|
245
|
+
_mountStatic(prefix, dir, options) {
|
|
246
|
+
this.#staticMounts.push({ prefix, dir, ...(options ? { options } : {}) });
|
|
247
|
+
}
|
|
248
|
+
/** Run `fn` once at {@link Toki.listen}, before serving. */
|
|
249
|
+
onReady(fn) {
|
|
250
|
+
this.#onReady.push(fn);
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
/** Run `fn` when the server closes. */
|
|
254
|
+
onClose(fn) {
|
|
255
|
+
this.#onClose.push(fn);
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
/** Load all registered plugins, awaiting async ones. Call before {@link Toki.listen}
|
|
259
|
+
* when any plugin is async; `listen` loads sync plugins on its own. */
|
|
260
|
+
async ready() {
|
|
261
|
+
if (this.#booted) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
await loadPluginsAsync(this);
|
|
265
|
+
this.#booted = true;
|
|
266
|
+
}
|
|
267
|
+
/** Bind `port` and serve. Returns a handle whose `close()` stops the server. */
|
|
268
|
+
listen(port, options = {}) {
|
|
269
|
+
this.#bootSync();
|
|
270
|
+
for (const ready of this.#onReady) {
|
|
271
|
+
this.#runLifecycle(ready, "onReady");
|
|
272
|
+
}
|
|
273
|
+
this.#compileAll();
|
|
274
|
+
const methods = this.#routes.map((r) => r.method);
|
|
275
|
+
const paths = this.#routes.map((r) => r.path);
|
|
276
|
+
const staticEntries = this.#staticMounts.flatMap((mount) => buildStaticEntries(mount.prefix, mount.dir, mount.options));
|
|
277
|
+
const serverOptions = {
|
|
278
|
+
...options,
|
|
279
|
+
notFound: this.#compiledNotFound !== undefined,
|
|
280
|
+
};
|
|
281
|
+
if (options.rateLimit) {
|
|
282
|
+
serverOptions.rateLimitMax = options.rateLimit.max;
|
|
283
|
+
serverOptions.rateLimitWindowMs = options.rateLimit.windowMs;
|
|
284
|
+
}
|
|
285
|
+
this.#boundPort = native.listen(port, methods, paths, (raw) => this.#dispatch(raw), staticEntries, serverOptions);
|
|
286
|
+
this.#listening = true;
|
|
287
|
+
return {
|
|
288
|
+
close: () => {
|
|
289
|
+
for (const fn of this.#onClose) {
|
|
290
|
+
this.#runLifecycle(fn, "onClose");
|
|
291
|
+
}
|
|
292
|
+
this.#listening = false;
|
|
293
|
+
native.close();
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Inject a request in-process for testing. Sends a real request over loopback so
|
|
299
|
+
* the full native path runs, auto-binding an ephemeral port when not already
|
|
300
|
+
* listening. Returns the captured response.
|
|
301
|
+
*/
|
|
302
|
+
async inject(options) {
|
|
303
|
+
if (!this.#listening) {
|
|
304
|
+
this.listen(0, { host: "127.0.0.1" });
|
|
305
|
+
}
|
|
306
|
+
return inject(this.#boundPort, options);
|
|
307
|
+
}
|
|
308
|
+
/** Loads sync plugins; throws if any plugin is async (call `ready()` first). */
|
|
309
|
+
#bootSync() {
|
|
310
|
+
if (this.#booted) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
loadPluginsSync(this);
|
|
314
|
+
this.#booted = true;
|
|
315
|
+
}
|
|
316
|
+
#compileAll() {
|
|
317
|
+
this.#compiled = this.#routes.map((route) => this.#compile(route));
|
|
318
|
+
this.#compiledNotFound =
|
|
319
|
+
this.#notFoundHandler !== undefined
|
|
320
|
+
? this.#compileNotFound(this.#notFoundHandler)
|
|
321
|
+
: undefined;
|
|
322
|
+
}
|
|
323
|
+
// resolve a route's chains by walking scope ancestry (root → leaf). order:
|
|
324
|
+
// onRequest → use → group → preValidation → (validation) → preHandler → handler →
|
|
325
|
+
// onResponse → onSend, each phase running outer scopes before inner ones.
|
|
326
|
+
#compile(route) {
|
|
327
|
+
const chain = ancestry(route.scope);
|
|
328
|
+
const before = [];
|
|
329
|
+
for (const s of chain)
|
|
330
|
+
before.push(...s.onRequest);
|
|
331
|
+
for (const s of chain)
|
|
332
|
+
before.push(...s.preParsing);
|
|
333
|
+
for (const s of chain)
|
|
334
|
+
before.push(...s.middleware);
|
|
335
|
+
before.push(...route.groupMiddleware);
|
|
336
|
+
for (const s of chain)
|
|
337
|
+
before.push(...s.preValidation);
|
|
338
|
+
before.push(...asArray(route.options.preValidation));
|
|
339
|
+
if (route.options.schema) {
|
|
340
|
+
before.push(validationStep(route.options.schema));
|
|
341
|
+
}
|
|
342
|
+
for (const s of chain)
|
|
343
|
+
before.push(...s.preHandler);
|
|
344
|
+
before.push(...asArray(route.options.preHandler));
|
|
345
|
+
const after = [];
|
|
346
|
+
for (const s of chain)
|
|
347
|
+
after.push(...s.onResponse);
|
|
348
|
+
for (const s of chain)
|
|
349
|
+
after.push(...s.onSend);
|
|
350
|
+
const serialization = [];
|
|
351
|
+
for (const s of chain)
|
|
352
|
+
serialization.push(...s.preSerialization);
|
|
353
|
+
serialization.push(...asArray(route.options.preSerialization));
|
|
354
|
+
// parsers resolve nearest-scope-first (leaf → root)
|
|
355
|
+
const parsers = [];
|
|
356
|
+
for (let i = chain.length - 1; i >= 0; i--)
|
|
357
|
+
parsers.push(...chain[i].contentTypeParsers);
|
|
358
|
+
const onTimeout = [];
|
|
359
|
+
for (const s of chain)
|
|
360
|
+
onTimeout.push(...s.onTimeout);
|
|
361
|
+
const decorators = Object.assign({}, ...chain.map((s) => s.requestDecorators));
|
|
362
|
+
let errorHandler;
|
|
363
|
+
for (const s of chain) {
|
|
364
|
+
if (s.errorHandler)
|
|
365
|
+
errorHandler = s.errorHandler;
|
|
366
|
+
}
|
|
367
|
+
const compiled = {
|
|
368
|
+
handler: route.handler,
|
|
369
|
+
before,
|
|
370
|
+
after,
|
|
371
|
+
serialization,
|
|
372
|
+
onTimeout,
|
|
373
|
+
parsers,
|
|
374
|
+
decorators,
|
|
375
|
+
};
|
|
376
|
+
const withError = errorHandler ? { ...compiled, errorHandler } : compiled;
|
|
377
|
+
return route.options.schema?.response
|
|
378
|
+
? { ...withError, responseSchemas: route.options.schema.response }
|
|
379
|
+
: withError;
|
|
380
|
+
}
|
|
381
|
+
// not-found handler runs the root chains, defaults to 404
|
|
382
|
+
#compileNotFound(handler) {
|
|
383
|
+
return {
|
|
384
|
+
handler,
|
|
385
|
+
before: [
|
|
386
|
+
...this.onRequest,
|
|
387
|
+
...this.preParsing,
|
|
388
|
+
...this.middleware,
|
|
389
|
+
...this.preValidation,
|
|
390
|
+
...this.preHandler,
|
|
391
|
+
],
|
|
392
|
+
after: [...this.onResponse, ...this.onSend],
|
|
393
|
+
serialization: [...this.preSerialization],
|
|
394
|
+
onTimeout: [...this.onTimeout],
|
|
395
|
+
parsers: [...this.contentTypeParsers],
|
|
396
|
+
decorators: this.requestDecorators,
|
|
397
|
+
...(this.errorHandler ? { errorHandler: this.errorHandler } : {}),
|
|
398
|
+
defaultStatus: 404,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
#dispatch(raw) {
|
|
402
|
+
const route = raw.routeIndex === NOT_FOUND_INDEX ? this.#compiledNotFound : this.#compiled[raw.routeIndex];
|
|
403
|
+
if (route === undefined) {
|
|
404
|
+
return toNative(reply.empty(raw.routeIndex === NOT_FOUND_INDEX ? 404 : 500));
|
|
405
|
+
}
|
|
406
|
+
const req = new TokiRequest(raw, { log: this.#loggerInstance, parsers: route.parsers });
|
|
407
|
+
Object.assign(req, route.decorators);
|
|
408
|
+
try {
|
|
409
|
+
const outcome = this.#run(req, route);
|
|
410
|
+
if (isThenable(outcome)) {
|
|
411
|
+
const id = raw.dispatchId;
|
|
412
|
+
const timer = this.#armTimeout(id, req, route);
|
|
413
|
+
void Promise.resolve(outcome)
|
|
414
|
+
.then((result) => {
|
|
415
|
+
if (timer)
|
|
416
|
+
clearTimeout(timer);
|
|
417
|
+
this.#submit(id, req, result);
|
|
418
|
+
}, (error) => {
|
|
419
|
+
if (timer)
|
|
420
|
+
clearTimeout(timer);
|
|
421
|
+
this.#submit(id, req, this.#handleError(req, error, route.errorHandler));
|
|
422
|
+
})
|
|
423
|
+
.catch((error) => {
|
|
424
|
+
// last resort: a throw inside #submit itself (e.g. native call failed)
|
|
425
|
+
req.log.error("dispatch settle failed", { error: String(error) });
|
|
426
|
+
});
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
if (isStreamResponse(outcome)) {
|
|
430
|
+
// engine suspends the connection only on the `undefined` we return below,
|
|
431
|
+
// so drive the stream on the next microtask, not now
|
|
432
|
+
const id = raw.dispatchId;
|
|
433
|
+
queueMicrotask(() => this.#driveSafe(id, req, outcome));
|
|
434
|
+
return undefined;
|
|
435
|
+
}
|
|
436
|
+
return toNative(outcome, req.stagedResponseHeaders);
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
return this.#safeToNative(this.#handleError(req, error, route.errorHandler), req);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
#submit(id, req, result) {
|
|
443
|
+
if (isStreamResponse(result)) {
|
|
444
|
+
this.#driveSafe(id, req, result);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
native.submitResponse(id, this.#safeToNative(result, req));
|
|
448
|
+
}
|
|
449
|
+
// #drive owns its own try/finally, but startStream can throw before it; never let
|
|
450
|
+
// a stream turn into an unhandled rejection.
|
|
451
|
+
#driveSafe(id, req, stream) {
|
|
452
|
+
void this.#drive(id, req, stream).catch((error) => {
|
|
453
|
+
req.log.error("stream drive failed", { error: String(error) });
|
|
454
|
+
try {
|
|
455
|
+
native.endStream(id);
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
// connection already gone
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
// run an onReady/onClose hook without letting a sync throw or async rejection escape
|
|
463
|
+
#runLifecycle(fn, name) {
|
|
464
|
+
try {
|
|
465
|
+
const result = fn();
|
|
466
|
+
if (isThenable(result)) {
|
|
467
|
+
void result.catch((error) => this.#loggerInstance.error(`${name} hook failed`, { error: String(error) }));
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
this.#loggerInstance.error(`${name} hook failed`, { error: String(error) });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
// arm a timeout for an async dispatch: run onTimeout hooks and reply 408 if the
|
|
475
|
+
// handler hasn't settled in time. caller clears the returned timer on settle.
|
|
476
|
+
#armTimeout(id, req, route) {
|
|
477
|
+
if (this.#requestTimeoutMs <= 0) {
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
480
|
+
const timer = setTimeout(() => {
|
|
481
|
+
for (const hook of route.onTimeout) {
|
|
482
|
+
try {
|
|
483
|
+
void hook(req);
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
// a timeout hook must not break the timeout response
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// no-op if the handler already settled (its dispatch id is consumed)
|
|
490
|
+
this.#submit(id, req, reply.text("Request Timeout", 408));
|
|
491
|
+
}, this.#requestTimeoutMs);
|
|
492
|
+
// a pending timeout must not keep the process alive
|
|
493
|
+
timer.unref?.();
|
|
494
|
+
return timer;
|
|
495
|
+
}
|
|
496
|
+
async #drive(id, req, stream) {
|
|
497
|
+
native.startStream(id, stream.status, streamHeaderBlock(stream, req.stagedResponseHeaders));
|
|
498
|
+
const encoder = new TextEncoder();
|
|
499
|
+
try {
|
|
500
|
+
for await (const chunk of stream.source) {
|
|
501
|
+
const bytes = typeof chunk === "string" ? encoder.encode(chunk) : chunk;
|
|
502
|
+
if (bytes.length === 0) {
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
const backlog = native.writeStreamChunk(id, bytes);
|
|
506
|
+
if (backlog < 0) {
|
|
507
|
+
return; // connection gone; endStream (in finally) is a no-op
|
|
508
|
+
}
|
|
509
|
+
if (backlog > STREAM_HIGH_WATER) {
|
|
510
|
+
await new Promise((resolve) => setTimeout(resolve, 1)); // let the socket drain
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
catch (error) {
|
|
515
|
+
req.log.error("stream source failed", { error: String(error) });
|
|
516
|
+
}
|
|
517
|
+
finally {
|
|
518
|
+
native.endStream(id);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
#safeToNative(result, req) {
|
|
522
|
+
try {
|
|
523
|
+
return toNative(result, req.stagedResponseHeaders);
|
|
524
|
+
}
|
|
525
|
+
catch {
|
|
526
|
+
return toNative(reply.empty(500));
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
#run(req, route) {
|
|
530
|
+
const short = runBefore(route.before, req, 0);
|
|
531
|
+
if (isThenable(short)) {
|
|
532
|
+
return short.then((value) => this.#afterBefore(req, route, value));
|
|
533
|
+
}
|
|
534
|
+
return this.#afterBefore(req, route, short);
|
|
535
|
+
}
|
|
536
|
+
#afterBefore(req, route, shortCircuit) {
|
|
537
|
+
const result = shortCircuit !== undefined ? shortCircuit : route.handler(req);
|
|
538
|
+
if (isThenable(result)) {
|
|
539
|
+
return result.then((value) => this.#afterHandler(req, route, value));
|
|
540
|
+
}
|
|
541
|
+
return this.#afterHandler(req, route, result);
|
|
542
|
+
}
|
|
543
|
+
#afterHandler(req, route, result) {
|
|
544
|
+
// a stream has no materialized body, so it skips serialization, materialization,
|
|
545
|
+
// and response hooks; the dispatcher drives it
|
|
546
|
+
if (isStreamResponse(result)) {
|
|
547
|
+
return result;
|
|
548
|
+
}
|
|
549
|
+
// preSerialization only sees plain values bound for JSON, not a built reply or string
|
|
550
|
+
if (route.serialization.length > 0 && !isTokiResponse(result) && typeof result !== "string") {
|
|
551
|
+
const transformed = runSerialization(route.serialization, req, result, 0);
|
|
552
|
+
if (isThenable(transformed)) {
|
|
553
|
+
return transformed.then((value) => this.#finishResponse(req, route, value));
|
|
554
|
+
}
|
|
555
|
+
return this.#finishResponse(req, route, transformed);
|
|
556
|
+
}
|
|
557
|
+
return this.#finishResponse(req, route, result);
|
|
558
|
+
}
|
|
559
|
+
#finishResponse(req, route, result) {
|
|
560
|
+
const res = materialize(result, route);
|
|
561
|
+
if (route.after.length === 0) {
|
|
562
|
+
return res;
|
|
563
|
+
}
|
|
564
|
+
return runAfter(route.after, req, res, 0);
|
|
565
|
+
}
|
|
566
|
+
#handleError(req, error, errorHandler) {
|
|
567
|
+
req.log.error("request handler threw", { error: String(error) });
|
|
568
|
+
if (errorHandler !== undefined) {
|
|
569
|
+
try {
|
|
570
|
+
return errorHandler(req, error);
|
|
571
|
+
}
|
|
572
|
+
catch {
|
|
573
|
+
// error handler itself threw; fall through to the default
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return reply.text("Internal Server Error", 500);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
/** Create a new application. */
|
|
580
|
+
export function createApp(options) {
|
|
581
|
+
return new Toki(options);
|
|
582
|
+
}
|
|
583
|
+
// scope and all ancestors, ordered root → leaf
|
|
584
|
+
function ancestry(scope) {
|
|
585
|
+
const chain = [];
|
|
586
|
+
for (let s = scope; s; s = s.parent) {
|
|
587
|
+
chain.unshift(s);
|
|
588
|
+
}
|
|
589
|
+
return chain;
|
|
590
|
+
}
|
|
591
|
+
// load a scope's plugins depth-first; throws on the first async plugin
|
|
592
|
+
function loadPluginsSync(scope) {
|
|
593
|
+
for (const entry of scope.plugins) {
|
|
594
|
+
const result = entry.plugin(entry.scope, entry.opts);
|
|
595
|
+
if (isThenable(result)) {
|
|
596
|
+
throw new Error("async plugin registered — call `await app.ready()` before `listen()`");
|
|
597
|
+
}
|
|
598
|
+
loadPluginsSync(entry.scope);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
// load a scope's plugins depth-first, awaiting each
|
|
602
|
+
async function loadPluginsAsync(scope) {
|
|
603
|
+
for (const entry of scope.plugins) {
|
|
604
|
+
await entry.plugin(entry.scope, entry.opts);
|
|
605
|
+
await loadPluginsAsync(entry.scope);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608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KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,CAAC;QACD,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED,oDAAoD;AACpD,KAAK,UAAU,gBAAgB,CAAC,KAAY;IAC1C,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Options for a `Set-Cookie` header. */
|
|
2
|
+
export interface CookieOptions {
|
|
3
|
+
path?: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
/** Lifetime in seconds. */
|
|
6
|
+
maxAge?: number;
|
|
7
|
+
expires?: Date;
|
|
8
|
+
httpOnly?: boolean;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
11
|
+
/** Chrome's cookie partitioning. */
|
|
12
|
+
partitioned?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Parses a `Cookie` header into a name → value map. Duplicate names: first wins. */
|
|
15
|
+
export declare function parseCookies(header: string): Readonly<Record<string, string | undefined>>;
|
|
16
|
+
/** Serializes one `Set-Cookie` header value. Throws on an invalid name. */
|
|
17
|
+
export declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|