@adaptivestone/framework 5.6.1 → 5.7.0

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +75 -0
  3. package/dist/clusterRunner.js +2 -1
  4. package/dist/clusterRunner.js.map +1 -1
  5. package/dist/codegen/astEmit.js +7 -0
  6. package/dist/codegen/astEmit.js.map +1 -1
  7. package/dist/codegen/astExtract.d.ts +3 -0
  8. package/dist/codegen/astExtract.js +1 -0
  9. package/dist/codegen/astExtract.js.map +1 -1
  10. package/dist/codegen/astResolve.d.ts +2 -0
  11. package/dist/codegen/astResolve.js +1 -0
  12. package/dist/codegen/astResolve.js.map +1 -1
  13. package/dist/codegen/emit.js +1 -1
  14. package/dist/codegen/index.js +1 -1
  15. package/dist/codegen/index.js.map +1 -1
  16. package/dist/config/http.js +5 -2
  17. package/dist/config/http.js.map +1 -1
  18. package/dist/controllers/Auth.d.ts +22 -14
  19. package/dist/controllers/Auth.js +38 -72
  20. package/dist/controllers/Auth.js.map +1 -1
  21. package/dist/controllers/Auth.routes.gen.d.ts +1 -1
  22. package/dist/controllers/Auth.routes.gen.js +1 -1
  23. package/dist/controllers/Health.d.ts +8 -5
  24. package/dist/controllers/Health.js +11 -6
  25. package/dist/controllers/Health.js.map +1 -1
  26. package/dist/controllers/Health.routes.gen.d.ts +1 -1
  27. package/dist/controllers/Health.routes.gen.js +1 -1
  28. package/dist/controllers/Home.d.ts +3 -2
  29. package/dist/controllers/Home.js +6 -2
  30. package/dist/controllers/Home.js.map +1 -1
  31. package/dist/controllers/Home.routes.gen.d.ts +1 -1
  32. package/dist/controllers/Home.routes.gen.js +1 -1
  33. package/dist/controllers/index.js +39 -29
  34. package/dist/controllers/index.js.map +1 -1
  35. package/dist/helpers/crypto.d.ts +6 -0
  36. package/dist/helpers/crypto.js +18 -4
  37. package/dist/helpers/crypto.js.map +1 -1
  38. package/dist/helpers/logger.d.ts +3 -1
  39. package/dist/helpers/logger.js +11 -1
  40. package/dist/helpers/logger.js.map +1 -1
  41. package/dist/helpers/passwordPolicy.d.ts +23 -0
  42. package/dist/helpers/passwordPolicy.js +62 -0
  43. package/dist/helpers/passwordPolicy.js.map +1 -0
  44. package/dist/helpers/redis/redisConnection.d.ts +1 -0
  45. package/dist/helpers/redis/redisConnection.js +1 -0
  46. package/dist/helpers/redis/redisConnection.js.map +1 -1
  47. package/dist/helpers/yup.d.ts +11 -5
  48. package/dist/helpers/yup.js +12 -6
  49. package/dist/helpers/yup.js.map +1 -1
  50. package/dist/locales/ru/translation.json +31 -0
  51. package/dist/models/User.d.ts +5 -4
  52. package/dist/models/User.js +0 -3
  53. package/dist/models/User.js.map +1 -1
  54. package/dist/models/UserOld.d.ts +2 -0
  55. package/dist/models/UserOld.js +9 -3
  56. package/dist/models/UserOld.js.map +1 -1
  57. package/dist/server.d.ts +22 -2
  58. package/dist/server.js +83 -14
  59. package/dist/server.js.map +1 -1
  60. package/dist/services/http/ExpressResponseWriter.d.ts +30 -0
  61. package/dist/services/http/ExpressResponseWriter.js +447 -0
  62. package/dist/services/http/ExpressResponseWriter.js.map +1 -0
  63. package/dist/services/http/HttpServer.d.ts +16 -10
  64. package/dist/services/http/HttpServer.js +71 -23
  65. package/dist/services/http/HttpServer.js.map +1 -1
  66. package/dist/services/http/ResponseWriter.d.ts +11 -0
  67. package/dist/services/http/ResponseWriter.js +2 -0
  68. package/dist/services/http/ResponseWriter.js.map +1 -0
  69. package/dist/services/http/builtInResponse.d.ts +26 -0
  70. package/dist/services/http/builtInResponse.js +70 -0
  71. package/dist/services/http/builtInResponse.js.map +1 -0
  72. package/dist/services/http/builtinErrorHandlers.d.ts +52 -5
  73. package/dist/services/http/builtinErrorHandlers.js +86 -5
  74. package/dist/services/http/builtinErrorHandlers.js.map +1 -1
  75. package/dist/services/http/files.d.ts +21 -8
  76. package/dist/services/http/files.js +2 -18
  77. package/dist/services/http/files.js.map +1 -1
  78. package/dist/services/http/httpErrors.d.ts +40 -2
  79. package/dist/services/http/httpErrors.js +50 -2
  80. package/dist/services/http/httpErrors.js.map +1 -1
  81. package/dist/services/http/middleware/RateLimiter.d.ts +1 -0
  82. package/dist/services/http/middleware/RateLimiter.js +36 -13
  83. package/dist/services/http/middleware/RateLimiter.js.map +1 -1
  84. package/dist/services/http/middleware/RequestParser.d.ts +5 -2
  85. package/dist/services/http/middleware/RequestParser.js +43 -25
  86. package/dist/services/http/middleware/RequestParser.js.map +1 -1
  87. package/dist/services/http/responses.d.ts +114 -0
  88. package/dist/services/http/responses.js +191 -0
  89. package/dist/services/http/responses.js.map +1 -0
  90. package/dist/services/http/routing/ExpressAdapter.d.ts +4 -1
  91. package/dist/services/http/routing/ExpressAdapter.js +82 -9
  92. package/dist/services/http/routing/ExpressAdapter.js.map +1 -1
  93. package/dist/services/validate/drivers/YupDriver.js +44 -6
  94. package/dist/services/validate/drivers/YupDriver.js.map +1 -1
  95. package/package.json +2 -2
@@ -0,0 +1,447 @@
1
+ import { Readable } from 'node:stream';
2
+ import { finished } from 'node:stream/promises';
3
+ import { describeThrown } from '../../helpers/logger.js';
4
+ import { HttpResponse, } from './responses.js';
5
+ /** Framing headers Node sets itself; a native response's copies are dropped. */
6
+ const HOP_BY_HOP_HEADERS = new Set([
7
+ 'connection',
8
+ 'keep-alive',
9
+ 'proxy-connection',
10
+ 'te',
11
+ 'trailer',
12
+ 'transfer-encoding',
13
+ 'upgrade',
14
+ ]);
15
+ /** The codings `fetch` decodes; a body in any other is passed on still encoded. */
16
+ const FETCH_DECODED_CODINGS = new Set([
17
+ 'gzip',
18
+ 'x-gzip',
19
+ 'deflate',
20
+ 'br',
21
+ 'zstd',
22
+ ]);
23
+ /** Headers that describe the encoded bytes, wrong once `fetch` decoded them. */
24
+ const ENCODED_BODY_HEADERS = [
25
+ 'content-encoding',
26
+ 'content-length',
27
+ 'content-digest',
28
+ 'repr-digest',
29
+ 'digest',
30
+ 'content-md5',
31
+ ];
32
+ /**
33
+ * Renders `HttpResponse` values through Express, so JSON, text and bytes get
34
+ * the same serialization, `ETag` and conditional-GET handling as `res.json` /
35
+ * `res.send`. Headers the request already carries (security headers, CORS)
36
+ * stay: a descriptor header replaces one of the same name, except
37
+ * `set-cookie` (appended) and `vary` (merged). A write that fails before
38
+ * anything is sent (a body `JSON.stringify` rejects, a stream that fails
39
+ * before its first chunk) restores the status and headers it found, so the
40
+ * error response that follows carries none of the descriptor's.
41
+ */
42
+ export class ExpressResponseWriter {
43
+ #transform;
44
+ #onTransformError;
45
+ constructor(options = {}) {
46
+ this.#transform = options.transform;
47
+ this.#onTransformError = options.onTransformError ?? (() => { });
48
+ }
49
+ async write(response, req, res) {
50
+ const { statusCode, statusMessage } = res;
51
+ const headers = res.getHeaders();
52
+ try {
53
+ const final = this.#transformed(response, req);
54
+ const replaced = final === response ? undefined : bodySource(response);
55
+ if (replaced instanceof Readable) {
56
+ // The replacement may read it late; an error before then must not crash.
57
+ absorbErrors(replaced);
58
+ }
59
+ try {
60
+ await render(final, req, res);
61
+ }
62
+ finally {
63
+ // After rendering: a replacement may wrap the original and read it.
64
+ if (final !== response) {
65
+ discardReplacedBody(response, final);
66
+ }
67
+ }
68
+ }
69
+ catch (err) {
70
+ if (!res.headersSent) {
71
+ for (const name of res.getHeaderNames()) {
72
+ res.removeHeader(name);
73
+ }
74
+ for (const [name, value] of Object.entries(headers)) {
75
+ if (value !== undefined) {
76
+ res.setHeader(name, value);
77
+ }
78
+ }
79
+ res.statusCode = statusCode;
80
+ res.statusMessage = statusMessage;
81
+ }
82
+ throw err;
83
+ }
84
+ }
85
+ /** A broken transform must not take the API down: report it, send the original. */
86
+ #transformed(response, req) {
87
+ if (!this.#transform) {
88
+ return response;
89
+ }
90
+ try {
91
+ // Typed as a response, but it is project code: check what came back.
92
+ const transformed = this.#transform(response, {
93
+ req: req,
94
+ });
95
+ if (HttpResponse.is(transformed)) {
96
+ return transformed;
97
+ }
98
+ const isThenable = typeof transformed?.then === 'function';
99
+ if (isThenable) {
100
+ // Reported below. The late response is not sent, nor stopped: its body
101
+ // may read the original's source. A Node stream body's error cannot
102
+ // crash; a rejection must not surface as unhandled.
103
+ Promise.resolve(transformed)
104
+ .then((late) => {
105
+ const body = HttpResponse.is(late) ? bodySource(late) : undefined;
106
+ if (body instanceof Readable) {
107
+ absorbErrors(body);
108
+ }
109
+ })
110
+ .catch(() => { });
111
+ }
112
+ const got = isThenable
113
+ ? 'a Promise (it must be synchronous)'
114
+ : transformed === null
115
+ ? 'null'
116
+ : typeof transformed;
117
+ this.#onTransformError(`transformResponse returned ${got}, not an HttpResponse; the original response was sent`);
118
+ }
119
+ catch (err) {
120
+ this.#onTransformError(`transformResponse threw; the original response was sent: ${describeThrown(err)}`);
121
+ }
122
+ return response;
123
+ }
124
+ }
125
+ async function render(response, req, res) {
126
+ switch (response.kind) {
127
+ case 'json':
128
+ start(res, response.status, response.headers);
129
+ res.setHeader('Content-Type', response.contentType);
130
+ res.json(response.body);
131
+ return;
132
+ case 'text':
133
+ start(res, response.status, response.headers);
134
+ res.setHeader('Content-Type', response.contentType);
135
+ res.send(response.body);
136
+ return;
137
+ case 'bytes': {
138
+ start(res, response.status, response.headers);
139
+ res.setHeader('Content-Type', response.contentType);
140
+ const { body } = response;
141
+ // `res.send` serializes anything but a Buffer as JSON.
142
+ res.send(Buffer.from(body.buffer, body.byteOffset, body.byteLength));
143
+ return;
144
+ }
145
+ case 'empty':
146
+ start(res, response.status, response.headers);
147
+ endWithoutBody(req, res);
148
+ return;
149
+ case 'redirect':
150
+ applyHeaders(res, response.headers);
151
+ res.redirect(response.status, response.location);
152
+ return;
153
+ case 'stream':
154
+ return writeStream(req, res, response.body, () => {
155
+ start(res, response.status, response.headers);
156
+ res.setHeader('Content-Type', response.contentType);
157
+ });
158
+ case 'native': {
159
+ const native = response.response;
160
+ // Dropped too: the fields `Connection` names (RFC 9110 7.6.1), and the
161
+ // encoding, length and digest headers of a fetched response (non-empty
162
+ // `url`) whose body `fetch` decoded: it has a body, is not a 206, and
163
+ // every coding it names is one that `fetch` decodes. Bun's `fetch`
164
+ // decodes a single coding only; it passes stacked codings on encoded.
165
+ const dropped = new Set((native.headers.get('connection') ?? '')
166
+ .split(',')
167
+ .map((name) => name.trim().toLowerCase()));
168
+ const codings = (native.headers.get('content-encoding') ?? '')
169
+ .split(',')
170
+ .map((coding) => coding.trim().toLowerCase());
171
+ if (native.url &&
172
+ native.body &&
173
+ native.status !== 206 &&
174
+ (codings.length === 1 || process.versions.bun === undefined) &&
175
+ codings.every((coding) => FETCH_DECODED_CODINGS.has(coding))) {
176
+ for (const name of ENCODED_BODY_HEADERS) {
177
+ dropped.add(name);
178
+ }
179
+ }
180
+ const commit = () => {
181
+ start(res, native.status, [...native.headers].filter(([name]) => !HOP_BY_HOP_HEADERS.has(name) && !dropped.has(name)));
182
+ if (native.statusText) {
183
+ res.statusMessage = native.statusText;
184
+ }
185
+ };
186
+ if (!native.body) {
187
+ commit();
188
+ endWithoutBody(req, res);
189
+ return;
190
+ }
191
+ return writeStream(req, res, native.body, commit);
192
+ }
193
+ }
194
+ }
195
+ /**
196
+ * End a response that has no body. A 204 or 304 drops its content headers; a
197
+ * 205 states a zero length and drops a `Transfer-Encoding`. Any other status
198
+ * keeps its `Transfer-Encoding`; outside HEAD a `Content-Length` (stated or
199
+ * already on `res`) becomes 0, so the client does not wait for bytes, and
200
+ * HEAD keeps its headers as given.
201
+ */
202
+ function endWithoutBody(req, res) {
203
+ if (res.statusCode === 204 || res.statusCode === 304) {
204
+ res.removeHeader('Content-Type');
205
+ res.removeHeader('Content-Length');
206
+ res.removeHeader('Transfer-Encoding');
207
+ }
208
+ else if (res.statusCode === 205) {
209
+ res.setHeader('Content-Length', '0');
210
+ // Only when set: removing an absent one changes the framing on some runtimes.
211
+ if (res.getHeader('Transfer-Encoding') !== undefined) {
212
+ res.removeHeader('Transfer-Encoding');
213
+ }
214
+ }
215
+ else if (req.method !== 'HEAD' &&
216
+ res.getHeader('Content-Length') !== undefined) {
217
+ res.setHeader('Content-Length', '0');
218
+ }
219
+ res.end();
220
+ }
221
+ function start(res, status, headers) {
222
+ res.status(status);
223
+ applyHeaders(res, headers);
224
+ }
225
+ function applyHeaders(res, headers) {
226
+ for (const [name, value] of headers) {
227
+ if (name === 'set-cookie') {
228
+ res.append('Set-Cookie', value);
229
+ }
230
+ else if (name === 'vary') {
231
+ // Name by name: an empty or loosely spaced list must not fail the response.
232
+ const names = value
233
+ .split(',')
234
+ .map((field) => field.trim())
235
+ .filter(Boolean);
236
+ if (names.length > 0) {
237
+ try {
238
+ res.vary(names.join(', '));
239
+ }
240
+ catch {
241
+ // Not a list of field names: sent as given, replacing an earlier one.
242
+ res.setHeader('Vary', value);
243
+ }
244
+ }
245
+ }
246
+ else {
247
+ res.setHeader(name, value);
248
+ }
249
+ }
250
+ }
251
+ /** The byte source a response would read, if any. */
252
+ function bodySource(response) {
253
+ if (response.kind === 'stream') {
254
+ return response.body;
255
+ }
256
+ if (response.kind === 'native') {
257
+ return response.response.body ?? undefined;
258
+ }
259
+ return undefined;
260
+ }
261
+ /** A transform that replaced a streaming response: stop the source it dropped. */
262
+ function discardReplacedBody(original, replacement) {
263
+ const dropped = bodySource(original);
264
+ if (dropped && dropped !== bodySource(replacement)) {
265
+ cancelSource(dropped);
266
+ }
267
+ }
268
+ /** Stop a byte source that will not be read. A failure to stop is ignored. */
269
+ function cancelSource(body) {
270
+ try {
271
+ if (body instanceof Readable) {
272
+ destroyNodeSource(body);
273
+ return;
274
+ }
275
+ const stopped = body instanceof ReadableStream
276
+ ? body.cancel()
277
+ : body[Symbol.asyncIterator]().return?.();
278
+ Promise.resolve(stopped).catch(() => { });
279
+ }
280
+ catch {
281
+ // A source that throws while stopping is already broken; nothing more to do.
282
+ }
283
+ }
284
+ /** Iterator.return() neither closes an unread Node stream nor interrupts a pending read. */
285
+ function destroyNodeSource(body) {
286
+ // An asynchronous open/_destroy can still fail after cancellation. Nothing
287
+ // consumes those errors once the response is discarded (not even an iterator
288
+ // for HEAD). Even a closed source may still have an error queued for emission.
289
+ absorbErrors(body);
290
+ body.destroy();
291
+ }
292
+ /**
293
+ * @internal A response that will not be sent: an unread Node stream body is
294
+ * destroyed; one being read keeps running, but its error cannot crash.
295
+ */
296
+ export function releaseUnsentBody(response) {
297
+ const body = bodySource(response);
298
+ if (body instanceof Readable) {
299
+ if (body.readableFlowing === null) {
300
+ destroyNodeSource(body);
301
+ }
302
+ else {
303
+ absorbErrors(body);
304
+ }
305
+ }
306
+ }
307
+ /** A no-op `'error'` listener, removed once the stream closes; readers still see the error. */
308
+ function absorbErrors(body) {
309
+ void finished(body, { cleanup: true }).catch(() => { });
310
+ }
311
+ /** A `ReadableStream` read through its reader, so a disconnect cancels a pending read at once. */
312
+ function iterate(body) {
313
+ if (body instanceof ReadableStream) {
314
+ const reader = body.getReader();
315
+ return {
316
+ next: () => reader.read(),
317
+ return: async () => {
318
+ await reader.cancel();
319
+ return { done: true, value: undefined };
320
+ },
321
+ };
322
+ }
323
+ const source = body[Symbol.asyncIterator]();
324
+ if (body instanceof Readable) {
325
+ return {
326
+ next: () => source.next(),
327
+ return: async () => {
328
+ destroyNodeSource(body);
329
+ return source.return?.() ?? { done: true, value: undefined };
330
+ },
331
+ };
332
+ }
333
+ return source;
334
+ }
335
+ const DISCONNECTED = Symbol('disconnected');
336
+ /**
337
+ * Send a byte source. Nothing is committed until the first chunk arrives, so
338
+ * an error before it rejects with `res` untouched. After that, an error
339
+ * destroys the response and rejects. A client disconnect stops the source
340
+ * and resolves, also while a chunk is still pending — Node's `pipeline` keeps
341
+ * waiting on a pending read after the client has gone, so each read is raced
342
+ * against the disconnect here.
343
+ */
344
+ async function writeStream(req, res, body, commit) {
345
+ const source = iterate(body);
346
+ let stopped = false;
347
+ const stop = () => {
348
+ if (stopped) {
349
+ return;
350
+ }
351
+ stopped = true;
352
+ try {
353
+ Promise.resolve(source.return?.()).catch(() => { });
354
+ }
355
+ catch {
356
+ // A source that throws while stopping is already broken; nothing more to do.
357
+ }
358
+ };
359
+ if (req.method === 'HEAD' || res.destroyed) {
360
+ stop();
361
+ if (!res.destroyed) {
362
+ commit();
363
+ res.end();
364
+ }
365
+ return;
366
+ }
367
+ // One short-lived waiter per wait (read or drain), released when that wait ends. A single
368
+ // shared "closed" promise would keep one reaction per chunk alive until the client leaves,
369
+ // so a long stream would grow without bound.
370
+ let gone = false;
371
+ let wake;
372
+ const untilClosed = () => gone
373
+ ? Promise.resolve(DISCONNECTED)
374
+ : new Promise((resolve) => {
375
+ wake = resolve;
376
+ });
377
+ /** Wait for `work` or the disconnect, whichever comes first. */
378
+ const orClosed = async (work) => {
379
+ try {
380
+ return await Promise.race([work, untilClosed()]);
381
+ }
382
+ finally {
383
+ wake = undefined;
384
+ }
385
+ };
386
+ const onClose = () => {
387
+ gone = true;
388
+ stop();
389
+ wake?.(DISCONNECTED);
390
+ };
391
+ // A transport error is followed by 'close', which ends the write.
392
+ const onError = () => { };
393
+ res.once('close', onClose);
394
+ res.on('error', onError);
395
+ /** The next chunk, or `undefined` once the client has gone. */
396
+ const read = async () => {
397
+ const pending = source.next();
398
+ const step = await orClosed(Promise.resolve(pending));
399
+ if (step === DISCONNECTED || res.destroyed) {
400
+ // The chunk may still arrive (or fail) later; nobody reads it.
401
+ Promise.resolve(pending).catch(() => { });
402
+ stop();
403
+ return undefined;
404
+ }
405
+ return step;
406
+ };
407
+ try {
408
+ let step = await read();
409
+ if (!step) {
410
+ return;
411
+ }
412
+ commit();
413
+ while (!step.done) {
414
+ if (!res.write(step.value)) {
415
+ const drained = await orClosed(once(res, 'drain'));
416
+ if (drained === DISCONNECTED) {
417
+ return;
418
+ }
419
+ }
420
+ step = await read();
421
+ if (!step) {
422
+ return;
423
+ }
424
+ }
425
+ res.end();
426
+ }
427
+ catch (err) {
428
+ // Stop the source on any failure: a generator suspended at `yield` keeps
429
+ // its `finally` (and what it holds) until returned.
430
+ stop();
431
+ if (res.headersSent) {
432
+ res.destroy();
433
+ }
434
+ throw err;
435
+ }
436
+ finally {
437
+ res.off('close', onClose);
438
+ res.off('error', onError);
439
+ }
440
+ }
441
+ /** Resolves on the first `event`; the caller races it against the disconnect. */
442
+ function once(res, event) {
443
+ return new Promise((resolve) => {
444
+ res.once(event, () => resolve());
445
+ });
446
+ }
447
+ //# sourceMappingURL=ExpressResponseWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpressResponseWriter.js","sourceRoot":"","sources":["../../../src/services/http/ExpressResponseWriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIzD,OAAO,EAEL,YAAY,GAEb,MAAM,gBAAgB,CAAC;AASxB,gFAAgF;AAChF,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC;IACtD,YAAY;IACZ,YAAY;IACZ,kBAAkB;IAClB,IAAI;IACJ,SAAS;IACT,mBAAmB;IACnB,SAAS;CACV,CAAC,CAAC;AAEH,mFAAmF;AACnF,MAAM,qBAAqB,GAAwB,IAAI,GAAG,CAAC;IACzD,MAAM;IACN,QAAQ;IACR,SAAS;IACT,IAAI;IACJ,MAAM;CACP,CAAC,CAAC;AAEH,gFAAgF;AAChF,MAAM,oBAAoB,GAAG;IAC3B,kBAAkB;IAClB,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,QAAQ;IACR,aAAa;CACd,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,OAAO,qBAAqB;IAGvB,UAAU,CAAyB;IAEnC,iBAAiB,CAA4B;IAEtD,YAAY,OAAO,GAAiC,EAAE;QACpD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,C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AM,GAAG,CAAC;IACZ,CAAC;YAAS,CAAC;QACT,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,iFAAiF;AACjF,SAAS,IAAI,CAAC,GAAa,EAAE,KAAc;IACzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,9 +1,10 @@
1
1
  import type { Server } from 'node:http';
2
2
  import type { Express, Request } from 'express';
3
3
  import Base from '../../modules/Base.ts';
4
- import type { IApp } from '../../server.ts';
4
+ import type { IApp, TransformResponseHook } from '../../server.ts';
5
5
  import type { TI18n } from '../i18n/types.ts';
6
- import { type ErrorHandlerFn, type ErrorHandlerResult, type ErrorLogLevel, type RegistrableError } from './builtinErrorHandlers.ts';
6
+ import { type ErrorHandlerFn, type ErrorLogLevel, type RegistrableError, type ResolvedError } from './builtinErrorHandlers.ts';
7
+ import { ExpressResponseWriter } from './ExpressResponseWriter.ts';
7
8
  import { RouteRegistry } from './routing/RouteRegistry.ts';
8
9
  export interface FrameworkRequest extends Request {
9
10
  appInfo: {
@@ -23,7 +24,11 @@ declare class HttpServer extends Base {
23
24
  express: Express;
24
25
  httpServer: Server;
25
26
  routeRegistry: RouteRegistry;
26
- constructor(app: IApp);
27
+ /** Renders route handlers' `HttpResponse` values and the framework's own responses. */
28
+ readonly responseWriter: ExpressResponseWriter;
29
+ constructor(app: IApp, options?: {
30
+ transformResponse?: TransformResponseHook;
31
+ });
27
32
  /**
28
33
  * Start accepting connections; resolves once the port is bound. Called by
29
34
  * `startServer` after routes, the 404 page and the error handler are
@@ -50,14 +55,15 @@ declare class HttpServer extends Base {
50
55
  /**
51
56
  * Resolve a thrown error through the registry: consumer tier first, then
52
57
  * built-ins; first `instanceof` match returning non-null wins. A handler
53
- * that itself throws aborts the walk (logged here at `error`; the caller
54
- * falls through to its 500) — never a crash loop. Returns null when no entry
55
- * produced a response. Called by the route-handler and validation catches
56
- * and by the final sink, which receives middleware errors.
58
+ * that itself throws, or returns a result that is not a valid response,
59
+ * aborts the walk (logged here at `error`; the caller answers its 500, even
60
+ * where it has a fallback response) — never a crash loop. Returns null when no entry produced a response.
61
+ * `response` is what gets sent; `status`/`body`/`headers` repeat a
62
+ * `{ status, body }` result (for an `HttpResponse` result: its status and
63
+ * JSON body). Called by the route-handler and validation catches and by the
64
+ * final sink, which receives middleware errors.
57
65
  */
58
- resolveError(err: unknown, req: FrameworkRequest): Promise<(ErrorHandlerResult & {
59
- logLevel: ErrorLogLevel;
60
- }) | null>;
66
+ resolveError(err: unknown, req: FrameworkRequest): Promise<ResolvedError | null>;
61
67
  /**
62
68
  * Add handle for 404 error
63
69
  */