@nifrajs/core 2.14.1 → 3.2.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 (226) hide show
  1. package/README.md +25 -0
  2. package/dist/assurance.d.ts +16 -8
  3. package/dist/assurance.d.ts.map +1 -1
  4. package/dist/assurance.js +33 -0
  5. package/dist/assurance.js.map +1 -1
  6. package/dist/durable-adapters.d.ts.map +1 -1
  7. package/dist/durable-adapters.js +26 -3
  8. package/dist/durable-adapters.js.map +1 -1
  9. package/dist/durable-approval.d.ts +56 -0
  10. package/dist/durable-approval.d.ts.map +1 -0
  11. package/dist/durable-approval.js +233 -0
  12. package/dist/durable-approval.js.map +1 -0
  13. package/dist/durable-effect.d.ts +42 -0
  14. package/dist/durable-effect.d.ts.map +1 -0
  15. package/dist/durable-effect.js +234 -0
  16. package/dist/durable-effect.js.map +1 -0
  17. package/dist/durable-execution.d.ts +8 -346
  18. package/dist/durable-execution.d.ts.map +1 -1
  19. package/dist/durable-execution.js +7 -1150
  20. package/dist/durable-execution.js.map +1 -1
  21. package/dist/durable-saga.d.ts +94 -0
  22. package/dist/durable-saga.d.ts.map +1 -0
  23. package/dist/durable-saga.js +550 -0
  24. package/dist/durable-saga.js.map +1 -0
  25. package/dist/edge-kit.d.ts +27 -0
  26. package/dist/edge-kit.d.ts.map +1 -0
  27. package/dist/edge-kit.js +24 -0
  28. package/dist/edge-kit.js.map +1 -0
  29. package/dist/errors.d.ts +1 -1
  30. package/dist/errors.d.ts.map +1 -1
  31. package/dist/errors.js.map +1 -1
  32. package/dist/index.d.ts +23 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +18 -2
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal/durable-approval-protocol.d.ts +1 -1
  37. package/dist/internal/durable-approval-protocol.d.ts.map +1 -1
  38. package/dist/internal/durable-effect-protocol.d.ts +1 -1
  39. package/dist/internal/durable-effect-protocol.d.ts.map +1 -1
  40. package/dist/internal/durable-saga-protocol.d.ts +1 -1
  41. package/dist/internal/durable-saga-protocol.d.ts.map +1 -1
  42. package/dist/internal/durable-shared.d.ts +26 -0
  43. package/dist/internal/durable-shared.d.ts.map +1 -0
  44. package/dist/internal/durable-shared.js +131 -0
  45. package/dist/internal/durable-shared.js.map +1 -0
  46. package/dist/internal/durable-types.d.ts +159 -0
  47. package/dist/internal/durable-types.d.ts.map +1 -0
  48. package/dist/internal/durable-types.js +2 -0
  49. package/dist/internal/durable-types.js.map +1 -0
  50. package/dist/internal/route-compiler.d.ts +61 -0
  51. package/dist/internal/route-compiler.d.ts.map +1 -0
  52. package/dist/internal/route-compiler.js +121 -0
  53. package/dist/internal/route-compiler.js.map +1 -0
  54. package/dist/internal/route-execution.d.ts +17 -9
  55. package/dist/internal/route-execution.d.ts.map +1 -1
  56. package/dist/internal/route-execution.js +4 -18
  57. package/dist/internal/route-execution.js.map +1 -1
  58. package/dist/internal/route-lanes.d.ts +35 -0
  59. package/dist/internal/route-lanes.d.ts.map +1 -0
  60. package/dist/internal/route-lanes.js +150 -0
  61. package/dist/internal/route-lanes.js.map +1 -0
  62. package/dist/internal/route-program.d.ts +67 -0
  63. package/dist/internal/route-program.d.ts.map +1 -0
  64. package/dist/internal/route-program.js +199 -0
  65. package/dist/internal/route-program.js.map +1 -0
  66. package/dist/response-observer.d.ts +25 -0
  67. package/dist/response-observer.d.ts.map +1 -0
  68. package/dist/response-observer.js +40 -0
  69. package/dist/response-observer.js.map +1 -0
  70. package/dist/security/baseline.d.ts +68 -0
  71. package/dist/security/baseline.d.ts.map +1 -0
  72. package/dist/security/baseline.js +118 -0
  73. package/dist/security/baseline.js.map +1 -0
  74. package/dist/server/bare-error-lane.d.ts +26 -0
  75. package/dist/server/bare-error-lane.d.ts.map +1 -0
  76. package/dist/server/bare-error-lane.js +60 -0
  77. package/dist/server/bare-error-lane.js.map +1 -0
  78. package/dist/server/body-lane.d.ts +13 -0
  79. package/dist/server/body-lane.d.ts.map +1 -0
  80. package/dist/server/body-lane.js +134 -0
  81. package/dist/server/body-lane.js.map +1 -0
  82. package/dist/server/body.d.ts +7 -0
  83. package/dist/server/body.d.ts.map +1 -1
  84. package/dist/server/body.js +7 -0
  85. package/dist/server/body.js.map +1 -1
  86. package/dist/server/bridge-markers.d.ts +25 -0
  87. package/dist/server/bridge-markers.d.ts.map +1 -0
  88. package/dist/server/bridge-markers.js +25 -0
  89. package/dist/server/bridge-markers.js.map +1 -0
  90. package/dist/server/context.d.ts +6 -1
  91. package/dist/server/context.d.ts.map +1 -1
  92. package/dist/server/contract.d.ts +40 -14
  93. package/dist/server/contract.d.ts.map +1 -1
  94. package/dist/server/contract.js +7 -0
  95. package/dist/server/contract.js.map +1 -1
  96. package/dist/server/cookies.d.ts.map +1 -1
  97. package/dist/server/cookies.js +16 -2
  98. package/dist/server/cookies.js.map +1 -1
  99. package/dist/server/header-case.d.ts.map +1 -1
  100. package/dist/server/header-case.js +2 -1
  101. package/dist/server/header-case.js.map +1 -1
  102. package/dist/server/http.d.ts +36 -3
  103. package/dist/server/http.d.ts.map +1 -1
  104. package/dist/server/http.js +49 -3
  105. package/dist/server/http.js.map +1 -1
  106. package/dist/server/install.d.ts +6 -8
  107. package/dist/server/install.d.ts.map +1 -1
  108. package/dist/server/install.js +7 -0
  109. package/dist/server/install.js.map +1 -1
  110. package/dist/server/node-outcome-hook.d.ts +2 -1
  111. package/dist/server/node-outcome-hook.d.ts.map +1 -1
  112. package/dist/server/node-outcome-hook.js.map +1 -1
  113. package/dist/server/node-outcome.d.ts +17 -2
  114. package/dist/server/node-outcome.d.ts.map +1 -1
  115. package/dist/server/node-outcome.js +37 -3
  116. package/dist/server/node-outcome.js.map +1 -1
  117. package/dist/server/plugin.d.ts +2 -2
  118. package/dist/server/plugin.d.ts.map +1 -1
  119. package/dist/server/plugin.js +6 -1
  120. package/dist/server/plugin.js.map +1 -1
  121. package/dist/server/query.d.ts +7 -1
  122. package/dist/server/query.d.ts.map +1 -1
  123. package/dist/server/query.js +8 -3
  124. package/dist/server/query.js.map +1 -1
  125. package/dist/server/registry.d.ts +40 -12
  126. package/dist/server/registry.d.ts.map +1 -1
  127. package/dist/server/request-context.d.ts +2 -13
  128. package/dist/server/request-context.d.ts.map +1 -1
  129. package/dist/server/request-context.js +18 -159
  130. package/dist/server/request-context.js.map +1 -1
  131. package/dist/server/respond.d.ts.map +1 -1
  132. package/dist/server/respond.js +58 -4
  133. package/dist/server/respond.js.map +1 -1
  134. package/dist/server/response-contract-lane.d.ts.map +1 -1
  135. package/dist/server/response-contract-lane.js +5 -2
  136. package/dist/server/response-contract-lane.js.map +1 -1
  137. package/dist/server/response-observer-runtime.d.ts +20 -0
  138. package/dist/server/response-observer-runtime.d.ts.map +1 -0
  139. package/dist/server/response-observer-runtime.js +95 -0
  140. package/dist/server/response-observer-runtime.js.map +1 -0
  141. package/dist/server/runtime-core.d.ts +76 -0
  142. package/dist/server/runtime-core.d.ts.map +1 -1
  143. package/dist/server/runtime-core.js +42 -1
  144. package/dist/server/runtime-core.js.map +1 -1
  145. package/dist/server/server-types.d.ts +6 -1
  146. package/dist/server/server-types.d.ts.map +1 -1
  147. package/dist/server/server.d.ts +158 -116
  148. package/dist/server/server.d.ts.map +1 -1
  149. package/dist/server/server.js +707 -844
  150. package/dist/server/server.js.map +1 -1
  151. package/dist/server/validation.d.ts +5 -0
  152. package/dist/server/validation.d.ts.map +1 -0
  153. package/dist/server/validation.js +13 -0
  154. package/dist/server/validation.js.map +1 -0
  155. package/dist/server/websocket.d.ts +20 -4
  156. package/dist/server/websocket.d.ts.map +1 -1
  157. package/dist/server/websocket.js +81 -11
  158. package/dist/server/websocket.js.map +1 -1
  159. package/dist/server/ws-bun.d.ts +12 -4
  160. package/dist/server/ws-bun.d.ts.map +1 -1
  161. package/dist/server/ws-bun.js +50 -16
  162. package/dist/server/ws-bun.js.map +1 -1
  163. package/dist/server/ws-hook.d.ts +3 -2
  164. package/dist/server/ws-hook.d.ts.map +1 -1
  165. package/dist/server.d.ts +3 -2
  166. package/dist/server.d.ts.map +1 -1
  167. package/dist/server.js +2 -1
  168. package/dist/server.js.map +1 -1
  169. package/dist/single-copy-register.d.ts +2 -0
  170. package/dist/single-copy-register.d.ts.map +1 -0
  171. package/dist/single-copy-register.js +24 -0
  172. package/dist/single-copy-register.js.map +1 -0
  173. package/dist/single-copy.d.ts +156 -0
  174. package/dist/single-copy.d.ts.map +1 -0
  175. package/dist/single-copy.js +472 -0
  176. package/dist/single-copy.js.map +1 -0
  177. package/package.json +28 -3
  178. package/src/assurance.ts +58 -1
  179. package/src/durable-adapters.ts +20 -0
  180. package/src/durable-approval.ts +281 -0
  181. package/src/durable-effect.ts +300 -0
  182. package/src/durable-execution.ts +8 -1627
  183. package/src/durable-saga.ts +744 -0
  184. package/src/edge-kit.ts +27 -0
  185. package/src/errors.ts +1 -0
  186. package/src/index.ts +129 -2
  187. package/src/internal/durable-approval-protocol.ts +1 -1
  188. package/src/internal/durable-effect-protocol.ts +1 -1
  189. package/src/internal/durable-saga-protocol.ts +1 -1
  190. package/src/internal/durable-shared.ts +157 -0
  191. package/src/internal/durable-types.ts +194 -0
  192. package/src/internal/route-compiler.ts +234 -0
  193. package/src/internal/route-execution.ts +53 -96
  194. package/src/internal/route-lanes.ts +221 -0
  195. package/src/internal/route-program.ts +404 -0
  196. package/src/response-observer.ts +64 -0
  197. package/src/security/baseline.ts +172 -0
  198. package/src/server/bare-error-lane.ts +77 -0
  199. package/src/server/body-lane.ts +203 -0
  200. package/src/server/body.ts +8 -0
  201. package/src/server/bridge-markers.ts +24 -0
  202. package/src/server/context.ts +6 -1
  203. package/src/server/contract.ts +70 -20
  204. package/src/server/cookies.ts +16 -2
  205. package/src/server/header-case.ts +3 -1
  206. package/src/server/http.ts +53 -3
  207. package/src/server/install.ts +14 -0
  208. package/src/server/node-outcome-hook.ts +2 -1
  209. package/src/server/node-outcome.ts +44 -3
  210. package/src/server/plugin.ts +11 -5
  211. package/src/server/query.ts +10 -4
  212. package/src/server/registry.ts +71 -16
  213. package/src/server/request-context.ts +13 -216
  214. package/src/server/respond.ts +71 -3
  215. package/src/server/response-contract-lane.ts +6 -2
  216. package/src/server/response-observer-runtime.ts +135 -0
  217. package/src/server/runtime-core.ts +124 -1
  218. package/src/server/server-types.ts +6 -1
  219. package/src/server/server.ts +1446 -1485
  220. package/src/server/validation.ts +19 -0
  221. package/src/server/websocket.ts +127 -17
  222. package/src/server/ws-bun.ts +67 -15
  223. package/src/server/ws-hook.ts +3 -2
  224. package/src/server.ts +8 -2
  225. package/src/single-copy-register.ts +24 -0
  226. package/src/single-copy.ts +526 -0
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Registration-compiled general route program.
3
+ *
4
+ * This is deliberately a data-and-control-flow compiler, not source generation: user functions and
5
+ * schemas remain opaque references and no request value is ever converted into executable code. The
6
+ * program is frozen at registration so the request path walks one immutable stage sequence instead
7
+ * of rediscovering which lifecycle features are present.
8
+ */
9
+ import { CONTEXT_SET, EMPTY_RESPONSE_CONTROLS, isResponseResult, } from "../server/runtime-core.js";
10
+ /** Build the immutable stage sequence once, while the server is still configurable. */
11
+ export function compileRouteProgram(input) {
12
+ const stages = [];
13
+ const validationStages = [];
14
+ const schema = input.schema;
15
+ if (schema?.headers !== undefined) {
16
+ const stage = { kind: "headers", schema: schema.headers };
17
+ stages.push(stage);
18
+ validationStages.push(stage);
19
+ }
20
+ if (schema?.params !== undefined) {
21
+ const stage = { kind: "params", schema: schema.params };
22
+ stages.push(stage);
23
+ validationStages.push(stage);
24
+ }
25
+ if (schema?.body !== undefined) {
26
+ const stage = { kind: "body", schema: schema.body };
27
+ stages.push(stage);
28
+ validationStages.push(stage);
29
+ }
30
+ if (schema?.query !== undefined) {
31
+ const stage = { kind: "query", schema: schema.query };
32
+ stages.push(stage);
33
+ validationStages.push(stage);
34
+ }
35
+ for (const derive of input.derives)
36
+ stages.push({ kind: "derive", run: derive });
37
+ for (const before of input.beforeHandle)
38
+ stages.push({ kind: "before", run: before });
39
+ stages.push({ kind: "handler", run: input.handler });
40
+ for (const after of input.afterHandle)
41
+ stages.push({ kind: "after", run: after });
42
+ return Object.freeze({
43
+ stages: Object.freeze(stages),
44
+ validationStages: Object.freeze(validationStages),
45
+ derives: Object.freeze([...input.derives]),
46
+ beforeHandle: Object.freeze([...input.beforeHandle]),
47
+ afterHandle: Object.freeze([...input.afterHandle]),
48
+ onError: Object.freeze([...input.onError]),
49
+ handler: input.handler,
50
+ decorations: Object.freeze({ ...input.decorations }),
51
+ hasDecorations: input.hasDecorations,
52
+ bodySchema: input.bodySchema,
53
+ bodyLimit: input.bodyLimit,
54
+ responseContract: input.responseContract,
55
+ });
56
+ }
57
+ function responseSet(ctx) {
58
+ return ctx[CONTEXT_SET]() ?? EMPTY_RESPONSE_CONTROLS;
59
+ }
60
+ function isEarly(value) {
61
+ return value instanceof Response || isResponseResult(value);
62
+ }
63
+ /** Execute the general program. The first synchronous stage sequence stays synchronous. */
64
+ export function executeRouteProgram(runtime, entry, program, source, ctx, finalize, wrapResponse) {
65
+ const host = runtime;
66
+ try {
67
+ if (program.hasDecorations)
68
+ Object.assign(ctx, program.decorations);
69
+ return runSync(host, entry, program, source, ctx, finalize, wrapResponse, 0, undefined);
70
+ }
71
+ catch (error) {
72
+ return host.handleProgramError(entry, error, ctx, finalize, wrapResponse);
73
+ }
74
+ }
75
+ function runSync(host, entry, program, source, ctx, finalize, wrapResponse, validationIndex, initial) {
76
+ const validations = program.validationStages;
77
+ for (let i = validationIndex; i < validations.length; i++) {
78
+ const stage = validations[i];
79
+ const outcome = stage.kind === "body"
80
+ ? host.readProgramBody(entry, source, ctx)
81
+ : host.validateProgramStage(entry, stage, source, ctx);
82
+ if (outcome instanceof Promise) {
83
+ return continueProgram(host, entry, program, source, ctx, finalize, wrapResponse, { kind: "validation", next: i + 1 }, outcome, initial);
84
+ }
85
+ if (outcome !== undefined)
86
+ return wrapResponse(outcome);
87
+ }
88
+ return runHooksSync(host, entry, program, source, ctx, finalize, wrapResponse, 0, 0, 0, initial);
89
+ }
90
+ function runHooksSync(host, entry, program, source, ctx, finalize, wrapResponse, deriveIndex, beforeIndex, afterIndex, initial) {
91
+ for (let i = deriveIndex; i < program.derives.length; i++) {
92
+ const outcome = program.derives[i](ctx);
93
+ if (outcome instanceof Promise) {
94
+ return continueProgram(host, entry, program, source, ctx, finalize, wrapResponse, { kind: "derive", next: i + 1 }, outcome, initial);
95
+ }
96
+ if (isEarly(outcome))
97
+ return finalize(outcome, responseSet(ctx));
98
+ Object.assign(ctx, outcome);
99
+ }
100
+ for (let i = beforeIndex; i < program.beforeHandle.length; i++) {
101
+ const outcome = program.beforeHandle[i](ctx);
102
+ if (outcome instanceof Promise) {
103
+ return continueProgram(host, entry, program, source, ctx, finalize, wrapResponse, { kind: "before", next: i + 1 }, outcome, initial);
104
+ }
105
+ if (outcome !== undefined)
106
+ return finalize(outcome, responseSet(ctx));
107
+ }
108
+ const output = program.handler(ctx);
109
+ if (output instanceof Promise) {
110
+ return continueProgram(host, entry, program, source, ctx, finalize, wrapResponse, { kind: "handler" }, output, initial);
111
+ }
112
+ let result = output;
113
+ for (let i = afterIndex; i < program.afterHandle.length; i++) {
114
+ const outcome = program.afterHandle[i](result, ctx);
115
+ if (outcome instanceof Promise) {
116
+ return continueProgram(host, entry, program, source, ctx, finalize, wrapResponse, { kind: "after", next: i + 1 }, outcome, result);
117
+ }
118
+ result = outcome;
119
+ }
120
+ return host.finishProgramResult(entry, ctx, result, finalize, wrapResponse);
121
+ }
122
+ async function continueProgram(host, entry, program, source, ctx, finalize, wrapResponse, pendingPhase, pending, initial) {
123
+ try {
124
+ const settled = await pending;
125
+ let result = initial;
126
+ if (pendingPhase.kind === "validation") {
127
+ if (settled !== undefined)
128
+ return wrapResponse(settled);
129
+ }
130
+ else if (pendingPhase.kind === "derive") {
131
+ if (isEarly(settled))
132
+ return finalize(settled, responseSet(ctx));
133
+ Object.assign(ctx, settled);
134
+ }
135
+ else if (pendingPhase.kind === "before") {
136
+ if (settled !== undefined)
137
+ return finalize(settled, responseSet(ctx));
138
+ }
139
+ else if (pendingPhase.kind === "handler") {
140
+ result = settled;
141
+ }
142
+ else {
143
+ result = settled;
144
+ }
145
+ return await runAsyncStages(host, entry, program, source, ctx, finalize, wrapResponse, pendingPhase, result);
146
+ }
147
+ catch (error) {
148
+ return await host.handleProgramError(entry, error, ctx, finalize, wrapResponse);
149
+ }
150
+ }
151
+ async function runAsyncStages(host, entry, program, source, ctx, finalize, wrapResponse, pendingPhase, result) {
152
+ try {
153
+ if (pendingPhase.kind === "validation") {
154
+ const validations = program.validationStages;
155
+ for (let i = pendingPhase.next; i < validations.length; i++) {
156
+ const stage = validations[i];
157
+ const outcome = stage.kind === "body"
158
+ ? await host.readProgramBody(entry, source, ctx)
159
+ : host.validateProgramStage(entry, stage, source, ctx);
160
+ const settled = outcome instanceof Promise ? await outcome : outcome;
161
+ if (settled !== undefined)
162
+ return wrapResponse(settled);
163
+ }
164
+ }
165
+ const deriveStart = pendingPhase.kind === "derive" ? pendingPhase.next : 0;
166
+ if (pendingPhase.kind === "validation" || pendingPhase.kind === "derive") {
167
+ for (let i = deriveStart; i < program.derives.length; i++) {
168
+ const outcome = program.derives[i](ctx);
169
+ const settled = outcome instanceof Promise ? await outcome : outcome;
170
+ if (isEarly(settled))
171
+ return finalize(settled, responseSet(ctx));
172
+ Object.assign(ctx, settled);
173
+ }
174
+ }
175
+ const beforeStart = pendingPhase.kind === "before" ? pendingPhase.next : 0;
176
+ if (pendingPhase.kind === "validation" ||
177
+ pendingPhase.kind === "derive" ||
178
+ pendingPhase.kind === "before") {
179
+ for (let i = beforeStart; i < program.beforeHandle.length; i++) {
180
+ const outcome = program.beforeHandle[i](ctx);
181
+ const settled = outcome instanceof Promise ? await outcome : outcome;
182
+ if (settled !== undefined)
183
+ return finalize(settled, responseSet(ctx));
184
+ }
185
+ const output = program.handler(ctx);
186
+ result = output instanceof Promise ? await output : output;
187
+ }
188
+ const afterStart = pendingPhase.kind === "after" ? pendingPhase.next : 0;
189
+ for (let i = afterStart; i < program.afterHandle.length; i++) {
190
+ const outcome = program.afterHandle[i](result, ctx);
191
+ result = outcome instanceof Promise ? await outcome : outcome;
192
+ }
193
+ return await host.finishProgramResult(entry, ctx, result, finalize, wrapResponse);
194
+ }
195
+ catch (error) {
196
+ return await host.handleProgramError(entry, error, ctx, finalize, wrapResponse);
197
+ }
198
+ }
199
+ //# sourceMappingURL=route-program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-program.js","sourceRoot":"","sources":["../../src/internal/route-program.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,gBAAgB,GAEjB,MAAM,2BAA2B,CAAA;AAkDlC,uFAAuF;AACvF,MAAM,UAAU,mBAAmB,CAAC,KAAwB;IAC1D,MAAM,MAAM,GAAwB,EAAE,CAAA;IACtC,MAAM,gBAAgB,GAAkE,EAAE,CAAA;IAC1F,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;IAC3B,IAAI,MAAM,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAW,CAAA;QAClE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClB,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IACD,IAAI,MAAM,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAW,CAAA;QAChE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClB,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IACD,IAAI,MAAM,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,KA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,CAAA;QACxE,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;YACpD,MAAM,GAAG,OAAO,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;QAC/D,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAA;IACnF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,MAAM,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAA;IACjF,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { AnyServer } from "./server/server.js";
2
+ export type { ResponseBodyHook, ResponseHeadersHook, ResponseObserverMethods, ResponseObserverRuntime, } from "./server/response-observer-runtime.js";
3
+ /** A server shape with the opt-in response observation methods installed. */
4
+ export type ResponseObserverServer<S extends AnyServer> = S & import("./server/response-observer-runtime.js").ResponseObserverMethods;
5
+ /** A plugin that enables response header, body, and raw-response observation methods. */
6
+ export type ResponseObserverPlugin = (<S extends AnyServer>(app: S) => ResponseObserverServer<S>) & {
7
+ readonly pluginName?: string;
8
+ };
9
+ /**
10
+ * Enable the response observation methods on a server.
11
+ *
12
+ * The default server does not carry the header, body, or raw-response observation adapters. Apply
13
+ * this plugin before using those methods:
14
+ *
15
+ * ```ts
16
+ * import { responseObserver } from "@nifrajs/core/response-observer"
17
+ * const app = server().use(responseObserver()).onResponseHeaders((headers) => {
18
+ * headers.set("cache-control", "no-store")
19
+ * })
20
+ * ```
21
+ */
22
+ export declare function responseObserver(): ResponseObserverPlugin;
23
+ /** Attach the opt-in observer runtime to a middleware bundle that uses response observation. */
24
+ export declare function withResponseObserver<T extends object>(middleware: T): T;
25
+ //# sourceMappingURL=response-observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-observer.d.ts","sourceRoot":"","sources":["../src/response-observer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,uCAAuC,CAAA;AAE9C,6EAA6E;AAC7E,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,GACzD,OAAO,uCAAuC,EAAE,uBAAuB,CAAA;AAEzE,yFAAyF;AACzF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC,SAAS,SAAS,EACxD,GAAG,EAAE,CAAC,KACH,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAElE;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,sBAAsB,CAiBzD;AAED,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,CAOvE"}
@@ -0,0 +1,40 @@
1
+ import { INSTALL_RESPONSE_OBSERVER } from "./server/install.js";
2
+ import { createResponseObserverRuntime, } from "./server/response-observer-runtime.js";
3
+ /**
4
+ * Enable the response observation methods on a server.
5
+ *
6
+ * The default server does not carry the header, body, or raw-response observation adapters. Apply
7
+ * this plugin before using those methods:
8
+ *
9
+ * ```ts
10
+ * import { responseObserver } from "@nifrajs/core/response-observer"
11
+ * const app = server().use(responseObserver()).onResponseHeaders((headers) => {
12
+ * headers.set("cache-control", "no-store")
13
+ * })
14
+ * ```
15
+ */
16
+ export function responseObserver() {
17
+ const apply = (app) => {
18
+ const install = app[INSTALL_RESPONSE_OBSERVER];
19
+ if (typeof install !== "function") {
20
+ throw new TypeError("[nifra] responseObserver() requires a compatible Server");
21
+ }
22
+ const methods = install.call(app, createResponseObserverRuntime());
23
+ if (methods === null || typeof methods !== "object") {
24
+ throw new TypeError("[nifra] responseObserver() failed to install its methods");
25
+ }
26
+ Object.assign(app, methods);
27
+ return app;
28
+ };
29
+ return Object.assign(apply, { pluginName: "nifra:response-observer" });
30
+ }
31
+ /** Attach the opt-in observer runtime to a middleware bundle that uses response observation. */
32
+ export function withResponseObserver(middleware) {
33
+ Object.defineProperty(middleware, INSTALL_RESPONSE_OBSERVER, {
34
+ value: createResponseObserverRuntime(),
35
+ enumerable: false,
36
+ configurable: false,
37
+ });
38
+ return middleware;
39
+ }
40
+ //# sourceMappingURL=response-observer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-observer.js","sourceRoot":"","sources":["../src/response-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,6BAA6B,GAE9B,MAAM,uCAAuC,CAAA;AAmB9C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,KAAK,GAAG,CAAsB,GAAM,EAA6B,EAAE;QACvE,MAAM,OAAO,GAAI,GAA0C,CAAC,yBAAyB,CAAC,CAAA;QACtF,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,IAAI,SAAS,CAAC,yDAAyD,CAAC,CAAA;QAChF,CAAC;QACD,MAAM,OAAO,GAAI,OAAyD,CAAC,IAAI,CAC7E,GAAG,EACH,6BAA6B,EAAE,CAChC,CAAA;QACD,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YACpD,MAAM,IAAI,SAAS,CAAC,0DAA0D,CAAC,CAAA;QACjF,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC3B,OAAO,GAAgC,CAAA;IACzC,CAAC,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,yBAAyB,EAAE,CAAC,CAAA;AACxE,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,oBAAoB,CAAmB,UAAa;IAClE,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,yBAAyB,EAAE;QAC3D,KAAK,EAAE,6BAA6B,EAAE;QACtC,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAA;IACF,OAAO,UAAU,CAAA;AACnB,CAAC"}
@@ -0,0 +1,68 @@
1
+ import type { AssurancePolicy } from "../assurance.js";
2
+ /**
3
+ * How much a {@link securityBaseline} demands. Each level is a superset of the one before it, so
4
+ * raising the level only ever adds findings.
5
+ *
6
+ * - `"essential"` - the invariants that hold for ANY app and never false-positive on a reasonable
7
+ * one: a body read must be bounded, an unlimited body may never claim to be bounded, an agent tool
8
+ * ingress must be bounded, and an authenticated state change must prove CSRF. Every required piece
9
+ * of evidence here is either published by the core from the route schema or only demanded when the
10
+ * route already opted into the risk (CSRF is required only where authentication is present). Safe to
11
+ * adopt on day one.
12
+ * - `"standard"` (default) - essential, plus: a route the app itself classified as `pii` or higher
13
+ * must be authenticated, whether it reads or writes. High signal, low noise - it fires only on
14
+ * routes the application already labelled sensitive.
15
+ * - `"strict"` - standard, plus the opinionated, higher-friction requirements: every route must carry
16
+ * a response contract, every read must carry security headers, and every mutation must be rate
17
+ * limited. These need middleware the app has to install, so they are opt-in rather than default.
18
+ */
19
+ export type SecurityBaselineLevel = "essential" | "standard" | "strict";
20
+ /** Tuning for {@link securityBaseline}. Every knob only ever tightens the policy. */
21
+ export interface SecurityBaselineOptions {
22
+ /** How much the baseline demands. Default `"standard"`. See {@link SecurityBaselineLevel}. */
23
+ readonly level?: SecurityBaselineLevel;
24
+ /**
25
+ * How to treat a route no rule matched. Default `"ignore"` so the baseline is purely additive - it
26
+ * asserts the invariants below and stays silent on everything else, which lets a project adopt it
27
+ * without first classifying its whole route table. Set `"error"` to make an unclassified route a
28
+ * finding, turning the baseline into a closed allow-list (recommended once the table is covered).
29
+ */
30
+ readonly unmatched?: "error" | "ignore";
31
+ /**
32
+ * Require that a matched route's evidence was installed by runtime enforcement (middleware/plugin
33
+ * or framework policy) rather than asserted inline on `schema.assurance`. Default `true`: an author
34
+ * label is not proof, and a security baseline that accepts labels is theater. Set `false` only to
35
+ * stage adoption before guards emit runtime evidence.
36
+ */
37
+ readonly requireRuntimeProvenance?: boolean;
38
+ }
39
+ /**
40
+ * A first-match-wins security policy that turns the recurring audit finding classes into machine
41
+ * checked route invariants. Composed only from the public assurance engine, so it inherits its
42
+ * fail-closed evaluation, provenance checks, and selector validation - no bespoke evaluator.
43
+ *
44
+ * The rules are ordered most-specific-first because assurance evaluation is first-match-wins: each
45
+ * route is owned by exactly one rule, so that rule carries the FULL requirement bundle for its class
46
+ * (a body-carrying mutation proves bounded-body AND CSRF in one rule, not two). Raising the `level`
47
+ * widens those bundles; it never reorders them.
48
+ *
49
+ * Coverage by level (see {@link SecurityBaselineLevel} for the rationale):
50
+ *
51
+ * | invariant | essential | standard | strict |
52
+ * | --- | :-: | :-: | :-: |
53
+ * | unlimited body can never be "bounded" (F-001) | ✓ | ✓ | ✓ |
54
+ * | every body read is bounded | ✓ | ✓ | ✓ |
55
+ * | agent tool ingress is bounded | ✓ | ✓ | ✓ |
56
+ * | authenticated mutation proves CSRF | ✓ | ✓ | ✓ |
57
+ * | pii+ route is authenticated | | ✓ | ✓ |
58
+ * | every route carries a response contract | | | ✓ |
59
+ * | every read carries security headers | | | ✓ |
60
+ * | every mutation is rate limited | | | ✓ |
61
+ *
62
+ * The baseline deliberately does not select on `access`/`zone` capabilities: those selectors require
63
+ * capability definitions and would make the preset refuse an app that declares none. Extend the
64
+ * returned policy's `rules` for capability- or path-specific requirements; put more specific rules
65
+ * before these so they own their routes first.
66
+ */
67
+ export declare function securityBaseline(options?: SecurityBaselineOptions): AssurancePolicy;
68
+ //# sourceMappingURL=baseline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseline.d.ts","sourceRoot":"","sources":["../../src/security/baseline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,iBAAiB,CAAA;AAGrE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAA;AAEvE,qFAAqF;AACrF,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,qBAAqB,CAAA;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,OAAO,CAAA;CAC5C;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,eAAe,CAgGvF"}
@@ -0,0 +1,118 @@
1
+ import { NIFRA_ASSURANCE_IDS } from "../internal/route-assurance.js";
2
+ const MUTATING = ["POST", "PUT", "PATCH", "DELETE"];
3
+ const READING = ["GET", "HEAD"];
4
+ /** The classification threshold above which the baseline demands authentication. */
5
+ const SENSITIVE = "pii";
6
+ /**
7
+ * A first-match-wins security policy that turns the recurring audit finding classes into machine
8
+ * checked route invariants. Composed only from the public assurance engine, so it inherits its
9
+ * fail-closed evaluation, provenance checks, and selector validation - no bespoke evaluator.
10
+ *
11
+ * The rules are ordered most-specific-first because assurance evaluation is first-match-wins: each
12
+ * route is owned by exactly one rule, so that rule carries the FULL requirement bundle for its class
13
+ * (a body-carrying mutation proves bounded-body AND CSRF in one rule, not two). Raising the `level`
14
+ * widens those bundles; it never reorders them.
15
+ *
16
+ * Coverage by level (see {@link SecurityBaselineLevel} for the rationale):
17
+ *
18
+ * | invariant | essential | standard | strict |
19
+ * | --- | :-: | :-: | :-: |
20
+ * | unlimited body can never be "bounded" (F-001) | ✓ | ✓ | ✓ |
21
+ * | every body read is bounded | ✓ | ✓ | ✓ |
22
+ * | agent tool ingress is bounded | ✓ | ✓ | ✓ |
23
+ * | authenticated mutation proves CSRF | ✓ | ✓ | ✓ |
24
+ * | pii+ route is authenticated | | ✓ | ✓ |
25
+ * | every route carries a response contract | | | ✓ |
26
+ * | every read carries security headers | | | ✓ |
27
+ * | every mutation is rate limited | | | ✓ |
28
+ *
29
+ * The baseline deliberately does not select on `access`/`zone` capabilities: those selectors require
30
+ * capability definitions and would make the preset refuse an app that declares none. Extend the
31
+ * returned policy's `rules` for capability- or path-specific requirements; put more specific rules
32
+ * before these so they own their routes first.
33
+ */
34
+ export function securityBaseline(options = {}) {
35
+ const level = options.level ?? "standard";
36
+ const strict = level === "strict";
37
+ const authSensitive = level !== "essential";
38
+ const provenance = options.requireRuntimeProvenance === false ? "any" : "runtime";
39
+ const A = NIFRA_ASSURANCE_IDS;
40
+ // Evidence the app must install middleware for, gated to the levels that assume that cost.
41
+ const contract = strict ? [A.RESPONSE_CONTRACT] : [];
42
+ const headers = strict ? [A.SECURITY_HEADERS] : [];
43
+ const rateLimit = strict ? [A.RATE_LIMITED] : [];
44
+ const authed = authSensitive ? [A.AUTHENTICATED] : [];
45
+ const rules = [
46
+ // The static twin of the config-time rejection: a schema route that opted into `bodyLimit:
47
+ // "unlimited"` can never carry `nifra.body-bounded` (the core withholds it), so requiring it is a
48
+ // standing ban. Owns the unlimited case before any body rule below can soften it. (F-001.)
49
+ {
50
+ name: "banned-unlimited-body",
51
+ match: { hasBody: true, bodyLimit: "unlimited" },
52
+ require: [A.BODY_BOUNDED],
53
+ },
54
+ // Agent tool ingress buffers attacker-influenced arguments; it must be bounded. Not CSRF-guarded:
55
+ // tool calls are token-authenticated machine traffic, not ambient-cookie browser posts.
56
+ {
57
+ name: "tool-ingress-bounded",
58
+ match: { tools: true, hasBody: true },
59
+ require: [A.BODY_BOUNDED, ...contract],
60
+ requireProvenance: provenance,
61
+ },
62
+ ];
63
+ // Sensitive mutations, split by body shape so bounded-body is required only where a body exists.
64
+ // Emitted only when a level adds a requirement beyond the generic mutation rules, otherwise they
65
+ // would be redundant duplicates that only slow evaluation.
66
+ if (authSensitive || strict) {
67
+ rules.push({
68
+ name: "sensitive-mutation-body",
69
+ match: { methods: [...MUTATING], hasBody: true, classificationAtLeast: SENSITIVE },
70
+ require: [A.BODY_BOUNDED, ...authed, ...contract, ...rateLimit],
71
+ requireCsrfWithAuthenticated: true,
72
+ requireProvenance: provenance,
73
+ }, {
74
+ name: "sensitive-mutation",
75
+ match: { methods: [...MUTATING], classificationAtLeast: SENSITIVE },
76
+ require: [...authed, ...contract, ...rateLimit],
77
+ requireCsrfWithAuthenticated: true,
78
+ requireProvenance: provenance,
79
+ });
80
+ }
81
+ rules.push({
82
+ name: "mutation-body",
83
+ match: { methods: [...MUTATING], hasBody: true },
84
+ require: [A.BODY_BOUNDED, ...contract, ...rateLimit],
85
+ requireCsrfWithAuthenticated: true,
86
+ requireProvenance: provenance,
87
+ }, {
88
+ name: "mutation",
89
+ match: { methods: [...MUTATING] },
90
+ require: [...contract, ...rateLimit],
91
+ requireCsrfWithAuthenticated: true,
92
+ requireProvenance: provenance,
93
+ });
94
+ if (authSensitive || strict) {
95
+ rules.push({
96
+ name: "sensitive-read",
97
+ match: { methods: [...READING], classificationAtLeast: SENSITIVE },
98
+ require: [...authed, ...contract, ...headers],
99
+ requireProvenance: provenance,
100
+ });
101
+ }
102
+ // The catch-all read rule. At essential/standard its requirement bundle is empty, so it is a pure
103
+ // classification that simply marks reads as covered - which matters only under `unmatched: "error"`,
104
+ // where an unowned route would otherwise fail. At strict it demands the response + header contract.
105
+ rules.push({
106
+ name: "read",
107
+ match: { methods: [...READING] },
108
+ require: [...contract, ...headers],
109
+ ...(strict ? { requireProvenance: provenance } : {}),
110
+ });
111
+ return {
112
+ rules,
113
+ unmatched: options.unmatched ?? "ignore",
114
+ // A wrong import reflecting zero routes must fail, not silently pass a security gate.
115
+ allowEmpty: false,
116
+ };
117
+ }
118
+ //# sourceMappingURL=baseline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseline.js","sourceRoot":"","sources":["../../src/security/baseline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAyCpE,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAA;AAC5D,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,CAAU,CAAA;AACxC,oFAAoF;AACpF,MAAM,SAAS,GAAG,KAAc,CAAA;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAmC,EAAE;IACpE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAA;IACzC,MAAM,MAAM,GAAG,KAAK,KAAK,QAAQ,CAAA;IACjC,MAAM,aAAa,GAAG,KAAK,KAAK,WAAW,CAAA;IAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IAEjF,MAAM,CAAC,GAAG,mBAAmB,CAAA;IAC7B,2FAA2F;IAC3F,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACpD,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAClD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC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AAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC,CAAA;IAEF,OAAO;QACL,KAAK;QACL,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,QAAQ;QACxC,sFAAsF;QACtF,UAAU,EAAE,KAAK;KAClB,CAAA;AACH,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Logger } from "./logger.js";
2
+ import { type ResponseResult } from "./runtime-core.js";
3
+ import type { CtxSet, RawContext } from "./server.js";
4
+ /** How much of a thrown error's own text reaches the log sink. Mirrors `Server`'s option. */
5
+ export type ErrorLogDetail = "full" | "message" | "none";
6
+ /**
7
+ * Render a value thrown on the bare lane. Three shapes, in the order the lane means them:
8
+ * - a bare `Response` is the app answering directly - passed through untouched;
9
+ * - a thrown `status(...)` is control flow, still plain data: rendered through the same `finalize`
10
+ * a RETURNED one takes, with the request's `c.set`, so it costs what the return costs;
11
+ * - anything else is a real fault: logged once, then a bodyless 500 (never the caller's error text).
12
+ *
13
+ * `responseSet` and `logError` are injected rather than imported so this file keeps no runtime edge
14
+ * back to `server.ts` (`responseSet` reaches into the context's set symbol; `logError` closes over the
15
+ * server's logger). Both run only on the throw path, so the closures cost nothing on the hot lane.
16
+ */
17
+ export declare function renderBareError<T>(err: unknown, ctx: RawContext, finalize: (result: unknown, set: CtxSet, ctx: RawContext) => T, wrapResponse: (response: Response | ResponseResult) => T, responseSet: (ctx: RawContext) => CtxSet, logError: (err: unknown, ctx: RawContext) => void, internalError: () => T): T;
18
+ /**
19
+ * Write an unhandled request error to the log. An error's own text can quote the input that produced
20
+ * it, so how much of it reaches the sink is the app's call (`detail`). The default keeps it: a 500
21
+ * with no message and no stack is an incident nobody can diagnose, and the framework already ships
22
+ * the narrower instrument for the leak - a redacting logger with `valuePatterns`. `"none"` is there
23
+ * for an untrusted sink.
24
+ */
25
+ export declare function emitRequestErrorLog(logger: Logger, detail: ErrorLogDetail, err: unknown, ctx: RawContext): void;
26
+ //# sourceMappingURL=bare-error-lane.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bare-error-lane.d.ts","sourceRoot":"","sources":["../../src/server/bare-error-lane.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,6FAA6F;AAC7F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAA;AAExD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,UAAU,EACf,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,KAAK,CAAC,EAC9D,YAAY,EAAE,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,KAAK,CAAC,EACxD,WAAW,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,MAAM,EACxC,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,KAAK,IAAI,EACjD,aAAa,EAAE,MAAM,CAAC,GACrB,CAAC,CAKH;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,UAAU,GACd,IAAI,CAWN"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The bare lane's ERROR rendering, as free functions the kernel delegates to.
3
+ *
4
+ * ## Why this is a lane module and not methods on `Server`
5
+ *
6
+ * These are the cold half of the bare request lane: what happens when a handler (or a `derive`)
7
+ * throws, rather than returns. The success half stays on the class - it reads request-lifecycle
8
+ * state and is the async-frame-skip hot path - but the error half needs none of that class state:
9
+ * `renderBareError` is pure control-flow routing, and `emitRequestErrorLog` needs only the logger
10
+ * and the detail policy, both of which are config fixed at construction. Passing those two in keeps
11
+ * this file free of any runtime dependency back on `server.ts`, so there is no import cycle: the
12
+ * `RawContext`/`CtxSet` imports are type-only and erased (the same shape `edge.ts` already relies on).
13
+ *
14
+ * A single source of truth for the thrown-value contract matters because it is a security surface:
15
+ * an unhandled throw must render as a 500 with no caller-controlled body, and the amount of the
16
+ * error's own text that reaches the log sink is the app's `errorLogDetail` call, not an accident of
17
+ * which lane caught it. Both the generic bare lane and the fused body runner route here, so that
18
+ * decision lives in exactly one place.
19
+ */
20
+ import { pathnameOf } from "./http.js";
21
+ import { isResponseResult } from "./runtime-core.js";
22
+ /**
23
+ * Render a value thrown on the bare lane. Three shapes, in the order the lane means them:
24
+ * - a bare `Response` is the app answering directly - passed through untouched;
25
+ * - a thrown `status(...)` is control flow, still plain data: rendered through the same `finalize`
26
+ * a RETURNED one takes, with the request's `c.set`, so it costs what the return costs;
27
+ * - anything else is a real fault: logged once, then a bodyless 500 (never the caller's error text).
28
+ *
29
+ * `responseSet` and `logError` are injected rather than imported so this file keeps no runtime edge
30
+ * back to `server.ts` (`responseSet` reaches into the context's set symbol; `logError` closes over the
31
+ * server's logger). Both run only on the throw path, so the closures cost nothing on the hot lane.
32
+ */
33
+ export function renderBareError(err, ctx, finalize, wrapResponse, responseSet, logError, internalError) {
34
+ if (err instanceof Response)
35
+ return wrapResponse(err);
36
+ if (isResponseResult(err))
37
+ return finalize(err, responseSet(ctx), ctx);
38
+ logError(err, ctx);
39
+ return internalError();
40
+ }
41
+ /**
42
+ * Write an unhandled request error to the log. An error's own text can quote the input that produced
43
+ * it, so how much of it reaches the sink is the app's call (`detail`). The default keeps it: a 500
44
+ * with no message and no stack is an incident nobody can diagnose, and the framework already ships
45
+ * the narrower instrument for the leak - a redacting logger with `valuePatterns`. `"none"` is there
46
+ * for an untrusted sink.
47
+ */
48
+ export function emitRequestErrorLog(logger, detail, err, ctx) {
49
+ logger.error("unhandled request error", {
50
+ method: ctx.req.method,
51
+ path: pathnameOf(ctx.req.url),
52
+ name: err instanceof Error ? err.name : "Error",
53
+ // `detail`, not `message`: the logger uses `message` for its own first argument, so a field of
54
+ // that name is silently overwritten and the thrown error's own text never reaches the sink. It
55
+ // survived only incidentally inside `stack`, and was lost outright for a non-Error throw.
56
+ ...(detail === "none" ? {} : { detail: err instanceof Error ? err.message : String(err) }),
57
+ ...(detail === "full" && err instanceof Error ? { stack: err.stack } : {}),
58
+ });
59
+ }
60
+ //# sourceMappingURL=bare-error-lane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bare-error-lane.js","sourceRoot":"","sources":["../../src/server/bare-error-lane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,gBAAgB,EAAuB,MAAM,mBAAmB,CAAA;AAMzE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAY,EACZ,GAAe,EACf,QAA8D,EAC9D,YAAwD,EACxD,WAAwC,EACxC,QAAiD,EACjD,aAAsB;IAEtB,IAAI,GAAG,YAAY,QAAQ;QAAE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAA;IACrD,IAAI,gBAAgB,CAAC,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;IACtE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAClB,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,MAAsB,EACtB,GAAY,EACZ,GAAe;IAEf,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE;QACtC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM;QACtB,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QAC7B,IAAI,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;QAC/C,+FAA+F;QAC/F,+FAA+F;QAC/F,0FAA0F;QAC1F,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1F,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3E,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type ProtoPoisoning } from "./proto-guard.js";
2
+ import { type ResponseResult } from "./runtime-core.js";
3
+ import type { MaybePromise, RequestSource } from "./server.js";
4
+ type JsonResultContinuation<T> = (result: unknown | ResponseResult) => T | Promise<T>;
5
+ type JsonErrorContinuation<T> = (error: unknown) => T | Promise<T>;
6
+ /** Read a JSON source with the declared-length precheck, delivered-byte recheck, streaming cap, and
7
+ * prototype-poisoning guard in one lane. */
8
+ export declare function readBoundedJsonSource(req: RequestSource, maxBytes: number, protoPoisoning?: ProtoPoisoning): Promise<unknown | ResponseResult>;
9
+ export declare function readBoundedJsonSource<T>(req: RequestSource, maxBytes: number, protoPoisoning: ProtoPoisoning, onResult: JsonResultContinuation<T>, onError: JsonErrorContinuation<T>): Promise<T>;
10
+ /** The shared content-type dispatcher around the JSON and urlencoded lanes. */
11
+ export declare function readBodyFramed<T>(source: RequestSource, maxBodyBytes: number, protoPoisoning: ProtoPoisoning, onParsed: (parsed: unknown) => MaybePromise<T>, wrapResponse: (response: Response | ResponseResult) => T, onError: (err: unknown) => MaybePromise<T>): Promise<T>;
12
+ export {};
13
+ //# sourceMappingURL=body-lane.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-lane.d.ts","sourceRoot":"","sources":["../../src/server/body-lane.ts"],"names":[],"mappings":"AAOA,OAAO,EAAoB,KAAK,cAAc,EAAoB,MAAM,kBAAkB,CAAA;AAE1F,OAAO,EAKL,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE9D,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,cAAc,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AACrF,KAAK,qBAAqB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAYlE;4CAC4C;AAC5C,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,aAAa,EAClB,QAAQ,EAAE,MAAM,EAChB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,CAAA;AACpC,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,GAAG,EAAE,aAAa,EAClB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,EACnC,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,CAAC,CAAC,CAAA;AA+Hb,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,aAAa,EACrB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,YAAY,CAAC,CAAC,CAAC,EAC9C,YAAY,EAAE,CAAC,QAAQ,EAAE,QAAQ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