theokit 0.77.2 → 0.77.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/dist/{actions-virtual-module-UIX5YWZR.js → actions-virtual-module-CA4YEAL3.js} +3 -3
- package/dist/{actions-virtual-module-V5Q4XVL5.js → actions-virtual-module-QRTV4NHS.js} +2 -2
- package/dist/{agent-WE4WOLKC.js → agent-IBDE65UJ.js} +2 -2
- package/dist/{app-typed-client-6FQB5FQO.js → app-typed-client-ZCLFXBEC.js} +3 -3
- package/dist/{app-typed-client-JCBQGPMP.js → app-typed-client-ZCMCBS45.js} +2 -2
- package/dist/{aws-lambda-XT7ZDJ6B.js → aws-lambda-JXUPC5QM.js} +17 -6
- package/dist/aws-lambda-JXUPC5QM.js.map +1 -0
- package/dist/boot/index.js +3 -3
- package/dist/{build-DSVLRDZ6.js → build-2VOQOWZE.js} +6 -6
- package/dist/{bun-PJLDELDT.js → bun-73JZLCKU.js} +16 -5
- package/dist/bun-73JZLCKU.js.map +1 -0
- package/dist/{chunk-EQJF2EH5.js → chunk-DDWF3UUI.js} +32 -1
- package/dist/chunk-DDWF3UUI.js.map +1 -0
- package/dist/{chunk-SEDZI7JF.js → chunk-FCBRWSBH.js} +2 -2
- package/dist/{chunk-BFDEEJOK.js → chunk-GNQKV2NP.js} +1 -1
- package/dist/{chunk-BFDEEJOK.js.map → chunk-GNQKV2NP.js.map} +1 -1
- package/dist/{chunk-KQBY62AE.js → chunk-HWRZUQPE.js} +31 -25
- package/dist/chunk-HWRZUQPE.js.map +1 -0
- package/dist/{chunk-ESSUFQ3H.js → chunk-IBZITTK7.js} +11 -9
- package/dist/chunk-IBZITTK7.js.map +1 -0
- package/dist/{chunk-3TCWOHLY.js → chunk-JZLNZOEL.js} +1 -1
- package/dist/{chunk-G3DDIEYE.js → chunk-MQCXYZEV.js} +4 -2
- package/dist/chunk-MQCXYZEV.js.map +1 -0
- package/dist/{chunk-E22GPCCO.js → chunk-MSSUMKFR.js} +61 -55
- package/dist/chunk-MSSUMKFR.js.map +1 -0
- package/dist/{chunk-XLFDYTWO.js → chunk-N7KDDYDB.js} +5 -3
- package/dist/chunk-N7KDDYDB.js.map +1 -0
- package/dist/{chunk-TODO6J42.js → chunk-PV6IO25S.js} +1 -1
- package/dist/chunk-PV6IO25S.js.map +1 -0
- package/dist/{chunk-N5YHENWJ.js → chunk-SHBPXX5E.js} +2 -2
- package/dist/{chunk-HZAXFD55.js → chunk-VSK5Y4ET.js} +2 -2
- package/dist/{chunk-GNV34JMI.js → chunk-XCPM72D6.js} +2 -2
- package/dist/{chunk-7IPWHWYV.js → chunk-YM6ONZYE.js} +11 -9
- package/dist/chunk-YM6ONZYE.js.map +1 -0
- package/dist/cli/index.js +6 -6
- package/dist/{cloudflare-F7KLBOU4.js → cloudflare-6ONK5HCO.js} +11 -3
- package/dist/cloudflare-6ONK5HCO.js.map +1 -0
- package/dist/{config-support-2TER2BYD.js → config-support-ZJIRVUWZ.js} +10 -5
- package/dist/config-support-ZJIRVUWZ.js.map +1 -0
- package/dist/{deno-deploy-LJ5JQQVR.js → deno-deploy-ZM2UR5ZI.js} +16 -5
- package/dist/deno-deploy-ZM2UR5ZI.js.map +1 -0
- package/dist/{dev-F4ZY7TZX.js → dev-AE7EWSB7.js} +5 -5
- package/dist/{index-C2lcEI-4.d.ts → index-CY_llLI7.d.ts} +4 -1
- package/dist/index.js +4 -4
- package/dist/{internal-api-H3C2ID6N.js → internal-api-JFA4JI3Z.js} +3 -3
- package/dist/{internal-api-5FTPYSEQ.js → internal-api-KQQHFTCG.js} +2 -2
- package/dist/{mcp-H3TNO6YV.js → mcp-UBGNYDMW.js} +2 -2
- package/dist/{netlify-ZPQNREFH.js → netlify-GRVT3MTT.js} +53 -10
- package/dist/netlify-GRVT3MTT.js.map +1 -0
- package/dist/{node-3EV3CVWB.js → node-UYRQNJNF.js} +2 -2
- package/dist/{preview-RYN7UI45.js → preview-XQJZ75QE.js} +3 -3
- package/dist/registry-JHWY7JRY.js +34 -0
- package/dist/server/define/index.d.ts +7 -2
- package/dist/server/define/index.js +1 -1
- package/dist/server/http/index.d.ts +2 -1
- package/dist/server/http/index.js +8 -2
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +10 -10
- package/dist/{server-boundary-5ZTBC2KF.js → server-boundary-JA3UOKJS.js} +2 -2
- package/dist/{server-boundary-DTF6ZEUO.js → server-boundary-OJ6YIPQT.js} +3 -3
- package/dist/{start-Y7VVCK6Q.js → start-AE5YCDVS.js} +6 -5
- package/dist/{start-Y7VVCK6Q.js.map → start-AE5YCDVS.js.map} +1 -1
- package/dist/{static-VNN4HYRN.js → static-C7PWUTQO.js} +2 -2
- package/dist/{theo-cloud-243SPOIA.js → theo-cloud-NKZUJO3H.js} +2 -2
- package/dist/{vercel-EXKSZ2OQ.js → vercel-MRZXLOIQ.js} +19 -5
- package/dist/vercel-MRZXLOIQ.js.map +1 -0
- package/dist/vite-plugin/index.js +4 -4
- package/dist/{vite-plugin-LDZJRFKT.js → vite-plugin-JMWUVMP3.js} +4 -4
- package/package.json +3 -3
- package/dist/aws-lambda-XT7ZDJ6B.js.map +0 -1
- package/dist/bun-PJLDELDT.js.map +0 -1
- package/dist/chunk-7IPWHWYV.js.map +0 -1
- package/dist/chunk-E22GPCCO.js.map +0 -1
- package/dist/chunk-EQJF2EH5.js.map +0 -1
- package/dist/chunk-ESSUFQ3H.js.map +0 -1
- package/dist/chunk-G3DDIEYE.js.map +0 -1
- package/dist/chunk-KQBY62AE.js.map +0 -1
- package/dist/chunk-TODO6J42.js.map +0 -1
- package/dist/chunk-XLFDYTWO.js.map +0 -1
- package/dist/cloudflare-F7KLBOU4.js.map +0 -1
- package/dist/config-support-2TER2BYD.js.map +0 -1
- package/dist/deno-deploy-LJ5JQQVR.js.map +0 -1
- package/dist/netlify-ZPQNREFH.js.map +0 -1
- package/dist/registry-3D2KR7UE.js +0 -34
- package/dist/vercel-EXKSZ2OQ.js.map +0 -1
- /package/dist/{actions-virtual-module-UIX5YWZR.js.map → actions-virtual-module-CA4YEAL3.js.map} +0 -0
- /package/dist/{actions-virtual-module-V5Q4XVL5.js.map → actions-virtual-module-QRTV4NHS.js.map} +0 -0
- /package/dist/{agent-WE4WOLKC.js.map → agent-IBDE65UJ.js.map} +0 -0
- /package/dist/{app-typed-client-6FQB5FQO.js.map → app-typed-client-ZCLFXBEC.js.map} +0 -0
- /package/dist/{app-typed-client-JCBQGPMP.js.map → app-typed-client-ZCMCBS45.js.map} +0 -0
- /package/dist/{build-DSVLRDZ6.js.map → build-2VOQOWZE.js.map} +0 -0
- /package/dist/{chunk-SEDZI7JF.js.map → chunk-FCBRWSBH.js.map} +0 -0
- /package/dist/{chunk-3TCWOHLY.js.map → chunk-JZLNZOEL.js.map} +0 -0
- /package/dist/{chunk-N5YHENWJ.js.map → chunk-SHBPXX5E.js.map} +0 -0
- /package/dist/{chunk-HZAXFD55.js.map → chunk-VSK5Y4ET.js.map} +0 -0
- /package/dist/{chunk-GNV34JMI.js.map → chunk-XCPM72D6.js.map} +0 -0
- /package/dist/{dev-F4ZY7TZX.js.map → dev-AE7EWSB7.js.map} +0 -0
- /package/dist/{internal-api-H3C2ID6N.js.map → internal-api-JFA4JI3Z.js.map} +0 -0
- /package/dist/{internal-api-5FTPYSEQ.js.map → internal-api-KQQHFTCG.js.map} +0 -0
- /package/dist/{mcp-H3TNO6YV.js.map → mcp-UBGNYDMW.js.map} +0 -0
- /package/dist/{node-3EV3CVWB.js.map → node-UYRQNJNF.js.map} +0 -0
- /package/dist/{preview-RYN7UI45.js.map → preview-XQJZ75QE.js.map} +0 -0
- /package/dist/{registry-3D2KR7UE.js.map → registry-JHWY7JRY.js.map} +0 -0
- /package/dist/{server-boundary-5ZTBC2KF.js.map → server-boundary-JA3UOKJS.js.map} +0 -0
- /package/dist/{server-boundary-DTF6ZEUO.js.map → server-boundary-OJ6YIPQT.js.map} +0 -0
- /package/dist/{static-VNN4HYRN.js.map → static-C7PWUTQO.js.map} +0 -0
- /package/dist/{theo-cloud-243SPOIA.js.map → theo-cloud-NKZUJO3H.js.map} +0 -0
- /package/dist/{vite-plugin-LDZJRFKT.js.map → vite-plugin-JMWUVMP3.js.map} +0 -0
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ stays up and the next query reconnects. Attach your own, as above, to handle it
|
|
|
112
112
|
|
|
113
113
|
## Jobs
|
|
114
114
|
|
|
115
|
-
Declare a backend in `theo.config.ts` and every file route gets `ctx.queue`:
|
|
115
|
+
Declare a backend in `theo.config.ts` and every file route and server action gets `ctx.queue`:
|
|
116
116
|
|
|
117
117
|
```typescript
|
|
118
118
|
import { config } from 'theokit'
|
|
@@ -127,7 +127,7 @@ export default config()
|
|
|
127
127
|
(a 4xx, a 5xx or an aborted request discards it). A job is a file under `<serverDir>/jobs/`
|
|
128
128
|
exporting `defineJob(name, { handler })`.
|
|
129
129
|
|
|
130
|
-
A route handler's `ctx` is a `RouteContext` (from `theokit/server/define`), whose keys are
|
|
130
|
+
A route or action handler's `ctx` is a `RouteContext` (from `theokit/server/define`), whose keys are
|
|
131
131
|
`unknown` until the app declares them. `ctx.queue` is there only when `jobs.backend` is set, so
|
|
132
132
|
declare it yourself in a `.d.ts` file, together with the job names in `JobRegistry` (the scaffold's
|
|
133
133
|
`types/jobs.d.ts` has both blocks):
|
|
@@ -249,6 +249,11 @@ export default config()
|
|
|
249
249
|
.build()
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
+
The entries the `vercel`, `netlify`, `cloudflare`, `bun`, `deno-deploy` and `aws-lambda` targets
|
|
253
|
+
emit answer the same two routes. A `ready` probe is a function, which a generated entry cannot
|
|
254
|
+
carry, so on those targets `theokit build` names it as not applied and `GET /__theo/ready` answers
|
|
255
|
+
503 while it stays in the config. Remove `ready`, or build for `node`, to get a 200 there.
|
|
256
|
+
|
|
252
257
|
Cloudflare Workers, step by step: [`docs/wiki/sops/cloudflare-deploy.md`](https://github.com/usetheokit/theokit/blob/main/docs/wiki/sops/cloudflare-deploy.md).
|
|
253
258
|
|
|
254
259
|
## Licence
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-SHBPXX5E.js";
|
|
2
2
|
import "./chunk-4XZOUS5G.js";
|
|
3
3
|
import "./chunk-WSOAN4KN.js";
|
|
4
4
|
import "./chunk-ENSFCKP6.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-HWRZUQPE.js";
|
|
6
6
|
import "./chunk-36ZACTF3.js";
|
|
7
7
|
import "./chunk-P6OS7652.js";
|
|
8
8
|
import "./chunk-ZDUO4IYN.js";
|
|
@@ -236,4 +236,4 @@ export const actions = manifest
|
|
|
236
236
|
export {
|
|
237
237
|
actionsVirtualModule
|
|
238
238
|
};
|
|
239
|
-
//# sourceMappingURL=actions-virtual-module-
|
|
239
|
+
//# sourceMappingURL=actions-virtual-module-CA4YEAL3.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "tsx/esm";
|
|
3
|
-
import "./chunk-
|
|
3
|
+
import "./chunk-MSSUMKFR.js";
|
|
4
4
|
import "./chunk-4JRXZTVQ.js";
|
|
5
5
|
import "./chunk-FNJVSFEC.js";
|
|
6
6
|
import "./chunk-WSMLSIS5.js";
|
|
@@ -219,4 +219,4 @@ export const actions = manifest
|
|
|
219
219
|
export {
|
|
220
220
|
actionsVirtualModule
|
|
221
221
|
};
|
|
222
|
-
//# sourceMappingURL=actions-virtual-module-
|
|
222
|
+
//# sourceMappingURL=actions-virtual-module-QRTV4NHS.js.map
|
|
@@ -3,7 +3,7 @@ import "tsx/esm";
|
|
|
3
3
|
import {
|
|
4
4
|
agentCommand,
|
|
5
5
|
createAgentSsrLoader
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FCBRWSBH.js";
|
|
7
7
|
import "./chunk-4JRXZTVQ.js";
|
|
8
8
|
import "./chunk-FU3LEX2I.js";
|
|
9
9
|
import "./chunk-Z7CJHDLS.js";
|
|
@@ -13,4 +13,4 @@ export {
|
|
|
13
13
|
agentCommand,
|
|
14
14
|
createAgentSsrLoader
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=agent-
|
|
16
|
+
//# sourceMappingURL=agent-IBDE65UJ.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
scanControllerModules
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SHBPXX5E.js";
|
|
4
4
|
import "./chunk-4XZOUS5G.js";
|
|
5
5
|
import "./chunk-WSOAN4KN.js";
|
|
6
6
|
import "./chunk-ENSFCKP6.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-HWRZUQPE.js";
|
|
8
8
|
import "./chunk-36ZACTF3.js";
|
|
9
9
|
import "./chunk-P6OS7652.js";
|
|
10
10
|
import "./chunk-ZDUO4IYN.js";
|
|
@@ -429,4 +429,4 @@ export {
|
|
|
429
429
|
generateClientDts,
|
|
430
430
|
shouldReemitForFile
|
|
431
431
|
};
|
|
432
|
-
//# sourceMappingURL=app-typed-client-
|
|
432
|
+
//# sourceMappingURL=app-typed-client-ZCLFXBEC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "tsx/esm";
|
|
3
|
-
import "./chunk-
|
|
3
|
+
import "./chunk-MSSUMKFR.js";
|
|
4
4
|
import "./chunk-4JRXZTVQ.js";
|
|
5
5
|
import {
|
|
6
6
|
scanControllerModules
|
|
@@ -412,4 +412,4 @@ export {
|
|
|
412
412
|
generateClientDts,
|
|
413
413
|
shouldReemitForFile
|
|
414
414
|
};
|
|
415
|
-
//# sourceMappingURL=app-typed-client-
|
|
415
|
+
//# sourceMappingURL=app-typed-client-ZCMCBS45.js.map
|
|
@@ -9,20 +9,22 @@ import {
|
|
|
9
9
|
} from "./chunk-72RSCKMW.js";
|
|
10
10
|
import {
|
|
11
11
|
deployedEntryPreamble
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-N7KDDYDB.js";
|
|
13
13
|
import {
|
|
14
14
|
JSON_NOT_FOUND_RESPONSE,
|
|
15
15
|
deployedAgentsFragment,
|
|
16
16
|
deployedRateLimitFragment,
|
|
17
|
+
deployedReservedRoutesFragment,
|
|
17
18
|
deployedRuntimeConfigFragment,
|
|
18
19
|
deployedTraceFragment,
|
|
19
20
|
describeDeployedSecurityHeaders,
|
|
20
21
|
rateLimitCheckFragment,
|
|
22
|
+
reservedRouteBranch,
|
|
21
23
|
serverDirLiteral
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-DDWF3UUI.js";
|
|
23
25
|
import {
|
|
24
26
|
nodeAdapter
|
|
25
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-MQCXYZEV.js";
|
|
26
28
|
import "./chunk-WSMLSIS5.js";
|
|
27
29
|
import {
|
|
28
30
|
assertServicesUnsupported,
|
|
@@ -156,6 +158,7 @@ function awsLambdaHandlerFragment(runtimeSpread, agentsBranch, agentsHostBypass,
|
|
|
156
158
|
`}`,
|
|
157
159
|
``,
|
|
158
160
|
`async function routeRequest(event, path) {`,
|
|
161
|
+
...reservedRouteBranch("path", " "),
|
|
159
162
|
` if (!path.startsWith('/api/')${agentsHostBypass}) {`,
|
|
160
163
|
` return new Response(`,
|
|
161
164
|
` 'Static assets must be served from CloudFront or a separate static host.',`,
|
|
@@ -218,7 +221,13 @@ import { executeRoute, extractTraceIdFromRequest, TRACE_HEADER, createCorsWebHan
|
|
|
218
221
|
`// theo.config.ts to read. Non-API paths 404 here and the document is served`,
|
|
219
222
|
`// from CloudFront or another static host, so this covers the API and not the`,
|
|
220
223
|
`// page (usetheokit/theokit#412).`,
|
|
221
|
-
...deployedEntryPreamble(
|
|
224
|
+
...deployedEntryPreamble(
|
|
225
|
+
runtimeConfig,
|
|
226
|
+
agentsFragment,
|
|
227
|
+
opts,
|
|
228
|
+
"aws-lambda",
|
|
229
|
+
deployedReservedRoutesFragment(opts)
|
|
230
|
+
),
|
|
222
231
|
``,
|
|
223
232
|
`function eventV2ToRequest(event) {`,
|
|
224
233
|
` const method = event.requestContext?.http?.method ?? 'GET'`,
|
|
@@ -260,7 +269,7 @@ async function buildAwsLambda(config, cwd, deps = {}, ctx) {
|
|
|
260
269
|
const { runNodeBuild, bundleFunction, ensureDir } = resolveAwsLambdaDeps(deps);
|
|
261
270
|
assertServicesUnsupported("aws-lambda", readManifest(cwd));
|
|
262
271
|
if (config.ssrStreaming) {
|
|
263
|
-
const { assertStreamingSupported } = await import("./config-support-
|
|
272
|
+
const { assertStreamingSupported } = await import("./config-support-ZJIRVUWZ.js");
|
|
264
273
|
assertStreamingSupported(config, awsLambdaAdapter, "aws-lambda");
|
|
265
274
|
}
|
|
266
275
|
await runNodeBuild(config, cwd, ctx);
|
|
@@ -282,6 +291,8 @@ async function buildAwsLambda(config, cwd, deps = {}, ctx) {
|
|
|
282
291
|
csrf: config.security?.csrf,
|
|
283
292
|
disallowed: config.security?.disallowed,
|
|
284
293
|
cors: config.security?.cors,
|
|
294
|
+
// #1097 — a probe cannot ride as a literal; the entry fails `/__theo/ready` closed instead.
|
|
295
|
+
readyProbeDeclared: config.ready !== void 0,
|
|
285
296
|
// #425 — a selector, not a transformer, so it rides as a literal like the values above.
|
|
286
297
|
serialization: config.serialization
|
|
287
298
|
});
|
|
@@ -336,4 +347,4 @@ export {
|
|
|
336
347
|
renderAwsLambdaEntry,
|
|
337
348
|
responseToLambdaResultV2
|
|
338
349
|
};
|
|
339
|
-
//# sourceMappingURL=aws-lambda-
|
|
350
|
+
//# sourceMappingURL=aws-lambda-JXUPC5QM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/aws-lambda.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * AWS Lambda adapter. Writes to `cwd/.theokit/lambda/`. Build-time tool.\n */\nimport { mkdirSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport type { TheoConfig } from '../config/schema.js'\nimport { assertServicesUnsupported, readManifest } from '../services/index.js'\n\nimport {\n bundleDeployedFunction,\n type BundleDeployedFunctionOptions,\n} from './bundle-deployed-function.js'\nimport { deployedAgentsFragment, JSON_NOT_FOUND_RESPONSE } from './deployed-agents.js'\nimport { renderBakedRoutes, routeRuntimeLines, type BakedRoute } from './deployed-baked-routes.js'\nimport { deployedEntryPreamble } from './deployed-preamble.js'\nimport {\n deployedRateLimitFragment,\n rateLimitCheckFragment,\n type DeployedRateLimitOptions,\n} from './deployed-rate-limit.js'\nimport { deployedReservedRoutesFragment, reservedRouteBranch } from './deployed-reserved-routes.js'\nimport { deployedRuntimeConfigFragment, serverDirLiteral } from './deployed-runtime-config.js'\nimport { deployedTraceFragment } from './deployed-trace.js'\nimport { nodeAdapter } from './node.js'\nimport { describeDeployedSecurityHeaders } from './security-headers.js'\nimport type { AdapterBuildContext, DeployAdapter, DeployedEntryOptions } from './types.js'\n\nexport interface AwsLambdaBuildDeps {\n runNodeBuild?: (config: TheoConfig, cwd: string, ctx?: AdapterBuildContext) => Promise<void>\n /**\n * Seam for the bundling step, alongside `runNodeBuild`.\n *\n * The entry imports five `theokit/…` sub-paths by bare specifier, and nothing resolves them for\n * an uploaded Lambda: measured 2026-09-29, copying the written handler to a directory with no\n * `node_modules` gave `ERR_MODULE_NOT_FOUND: Cannot find package 'theokit'`. ADR 0020 names this\n * target as needing the same call Vercel got.\n */\n bundleFunction?: (options: BundleDeployedFunctionOptions) => Promise<void>\n /**\n * RETIRED by B-344, kept out rather than left accepting a value nothing reads.\n *\n * The handler is bundled now, so there is no raw write for a caller to intercept. A dep a build\n * accepts and ignores is the same defect as a renderer option it accepts and ignores — see the\n * `agentsDir` note in `netlify.ts`. Nothing in this repository stubbed it.\n */\n ensureDir?: (path: string) => void\n}\n\nexport interface RequestShape {\n method: string\n path: string\n headers: Record<string, string>\n body?: string\n}\n\nexport interface LambdaResultV2 {\n statusCode: number\n headers: Record<string, string>\n body: string\n isBase64Encoded: boolean\n}\n\nconst BINARY_CONTENT_TYPES = [\n 'application/octet-stream',\n 'application/pdf',\n 'application/zip',\n 'image/',\n 'audio/',\n 'video/',\n]\n\nfunction isBinaryContentType(contentType: string | undefined): boolean {\n if (!contentType) return false\n const ct = contentType.toLowerCase()\n return BINARY_CONTENT_TYPES.some((prefix) => ct.startsWith(prefix))\n}\n\ninterface APIGatewayProxyEventV2 {\n version: string\n requestContext: {\n http: { method: string; path: string }\n }\n headers?: Record<string, string | undefined>\n body?: string\n isBase64Encoded?: boolean\n}\n\nexport function eventV2ToRequestShape(event: APIGatewayProxyEventV2): RequestShape {\n const headers: Record<string, string> = {}\n for (const [k, v] of Object.entries(event.headers ?? {})) {\n if (v !== undefined) headers[k] = v\n }\n let body: string | undefined = event.body\n if (body !== undefined && event.isBase64Encoded) {\n body = Buffer.from(body, 'base64').toString('utf-8')\n }\n return {\n method: event.requestContext.http.method,\n path: event.requestContext.http.path,\n headers,\n body,\n }\n}\n\nexport function responseToLambdaResultV2(\n statusCode: number,\n headers: Record<string, string>,\n body: string,\n): LambdaResultV2 {\n const isBinary = isBinaryContentType(headers['content-type'])\n return {\n statusCode,\n headers,\n body: isBinary ? Buffer.from(body, 'binary').toString('base64') : body,\n isBase64Encoded: isBinary,\n }\n}\n\n// Generated-code fragments — extracted so the parent emitter stays under the\n// max-lines-per-function ceiling.\n/** The v2 result conversion, the handler, and the routing that feeds them. */\n/** The target's name, in the five places that spell it — same gate deno-deploy tripped. */\n/* The name in the places a gate does NOT read. `assertServicesUnsupported` keeps the literal:\n * `services-other-adapters-reject.test.ts:30` requires each adapter to name ITSELF there, so a\n * copy-paste carrying another adapter's name cannot hide behind a constant. */\nconst TARGET = 'aws-lambda'\n\nfunction awsLambdaHandlerFragment(\n runtimeSpread: string,\n agentsBranch: readonly string[],\n agentsHostBypass: string,\n /** B-027 — passed, not read: this is a separate function from the parent emitter. */\n rateLimit: DeployedRateLimitOptions['rateLimit'],\n): string[] {\n return [\n `// #382 — this target is DELISTED for response streaming, by construction.`,\n `// The Lambda v2 result object below carries \\`body\\` as a string, so the`,\n `// response cannot exist until the run has finished, no matter how the`,\n `// framework's shim writes it. Streaming here would require`,\n `// \\`awslambda.streamifyResponse\\` plus a Function URL in RESPONSE_STREAM`,\n `// invoke mode — neither of which this adapter emits, and which would break`,\n `// every API Gateway deployment of it. Rather than degrade in silence, a`,\n `// response that is unambiguously a stream is named in the logs below.`,\n `async function responseToV2Result(response, routePath) {`,\n ` const headers = {}`,\n ` response.headers.forEach((v, k) => { headers[k] = v })`,\n ` const ct = headers['content-type'] ?? ''`,\n ` if (ct.includes('text/event-stream')) {`,\n ` console.warn(`,\n ` '[theo][aws-lambda] ' + routePath + ' returned a streaming response (' + ct + '), ' +`,\n ` 'but the aws-lambda target buffers it whole and delivers it when the run ends. ' +`,\n ` 'This target is delisted for streaming (theokit#382). Deploy streaming routes to ' +`,\n ` 'cloudflare, vercel, netlify, bun, deno-deploy or node.'`,\n ` )`,\n ` }`,\n ` const isBinary = /^application\\\\/(octet-stream|pdf|zip)|^(image|audio|video)\\\\//.test(ct)`,\n ` if (isBinary) {`,\n ` const buf = Buffer.from(await response.arrayBuffer())`,\n ` return {`,\n ` statusCode: response.status,`,\n ` headers,`,\n ` body: buf.toString('base64'),`,\n ` isBase64Encoded: true,`,\n ` }`,\n ` }`,\n ` return {`,\n ` statusCode: response.status,`,\n ` headers,`,\n ` body: await response.text(),`,\n ` isBase64Encoded: false,`,\n ` }`,\n `}`,\n ``,\n `// Every outcome — including both 404s — is produced as a Web Response by`,\n `// routeRequest, so the security baseline is applied at ONE place and the`,\n `// v2 result object is built from headers that already carry it.`,\n ...(rateLimit === undefined\n ? []\n : [\n `import { createRateLimiterWeb } from 'theokit/server/rate-limit'`,\n `import { resolveClientIpFromRequest } from 'theokit/server/rate-limit'`,\n ``,\n ]),\n ...deployedRateLimitFragment(\n rateLimit,\n TARGET,\n // The v2 payload's own answer, with the v1 `identity.sourceIp` beside it: a v1 event carries\n // no `http` object at all, and both reads are optional-chained so neither throws on the\n // other's shape. Same treatment `:153` already gives `requestContext?.http?.path`.\n `event.requestContext?.http?.sourceIp ?? event.requestContext?.identity?.sourceIp ?? resolveClientIpFromRequest(corsRequest, TRUST_PROXY)`,\n // `corsRequest`, not `request`: the Web request this entry builds is named that (`:157`).\n 'corsRequest, event',\n ),\n ``,\n `export const handler = async (event) => {`,\n ` const path = event.requestContext?.http?.path ?? '/'`,\n ` // #409 — the same event, read as a Web Request so the CORS matcher can see the method and`,\n ` // the \\`origin\\` header. \\`eventV2ToRequest\\` reads a body already present in the event, so`,\n ` // unlike the Node targets there is no stream to drain twice.`,\n ` const corsRequest = eventV2ToRequest(event)`,\n ``,\n ` // The preflight is answered BEFORE anything routes: an OPTIONS the router handles is an`,\n ` // OPTIONS the browser never gets a CORS answer to.`,\n ` const preflight = corsPreflight(corsRequest)`,\n ...rateLimitCheckFragment(\n rateLimit,\n ' ',\n 'corsRequest, event',\n // This handler returns a Lambda v2 RESULT, not a Response. A bare `return <Response>` would\n // hand the runtime an object it does not understand.\n 'return responseToV2Result(withCors(corsRequest, withSecurityHeaders(rateLimited(limit), SECURITY_HEADERS)), path)',\n 'return responseToV2Result(withCors(corsRequest, withSecurityHeaders(unnamedCaller(), SECURITY_HEADERS)), path)',\n ),\n ` const response = preflight !== null`,\n ` ? withSecurityHeaders(preflight, SECURITY_HEADERS)`,\n ` : withCors(corsRequest, withSecurityHeaders(await routeRequest(event, path), SECURITY_HEADERS))`,\n ` return responseToV2Result(response, path)`,\n `}`,\n ``,\n `async function routeRequest(event, path) {`,\n ...reservedRouteBranch('path', ' '),\n ` if (!path.startsWith('/api/')${agentsHostBypass}) {`,\n ` return new Response(`,\n ` 'Static assets must be served from CloudFront or a separate static host.',`,\n ` { status: 404, headers: { 'content-type': 'text/plain' } },`,\n ` )`,\n ` }`,\n ``,\n ``,\n // B-235 — hoisted above the agents branch, which names `request` like every other host's.\n // It was declared below `matchRoute`, and an agent path never reaches a route match. Building\n // it here costs nothing new: the outer handler already built one for the CORS matcher, and\n // `eventV2ToRequest` reads a body the event already carries, so there is no stream to drain\n // twice.\n ` const request = eventV2ToRequest(event)`,\n ``,\n ...agentsBranch,\n ``,\n ` const match = matchRoute(path, routes)`,\n ` if (!match) return ${JSON_NOT_FOUND_RESPONSE}`,\n ``,\n ` const { req, res, toResponse } = createWebShim(request)`,\n ...deployedTraceFragment('request', ' '),\n ` const method = request.method.toUpperCase()`,\n ` return toResponse(executeRoute({ route: match.route, method, params: match.params, req, res, loadModule, serverDir, requestId, ...CSRF_CONFIG, ${runtimeSpread} }))`,\n `}`,\n ]\n}\n\nexport function renderAwsLambdaEntry(\n opts: DeployedEntryOptions & {\n /**\n * The routes, baked at build time (B-344).\n *\n * The entry used to resolve them with a runtime `scanServerRoutes` — a `readdirSync` over\n * `serverDir`. An uploaded Lambda has no source tree, so every `/api/*` answered its own JSON 404:\n * measured 2026-09-29 by bundling this entry, copying it to a directory with no `node_modules`,\n * importing it and invoking it with a synthetic API Gateway v2 event. Where a tree IS uploaded the\n * route files are TypeScript, which a plain Node runtime cannot compile — the `SyntaxError`\n * Netlify answered with before B-338. The fix #369 made for Cloudflare, B-319 for Vercel and B-338\n * for Netlify, on the fifth target, through the same emitter so the five cannot drift.\n */\n routes?: readonly BakedRoute[]\n /** The agents, for the same reason and from the same scan. */\n agents?: readonly { filePath: string; agentPath: string; name: string }[]\n contextModule?: string\n } = {},\n): string {\n const runtimeConfig = deployedRuntimeConfigFragment(opts)\n const { routeImports, routeModuleEntries, routeTableEntries } = renderBakedRoutes(\n opts.routes ?? [],\n )\n // B-235. The entry already builds a Web `Request` — `eventV2ToRequest(event)`, for the CORS\n // matcher — so the shape this branch needs was here all along. `path` rather than `url.pathname`\n // because that is the name this host reads the route from.\n // B-344 — baked, for the reason the routes are: an uploaded function has no source tree, so a\n // runtime `scanAgents` finds nothing and `createProductionLoader()` would import a path that was\n // never shipped. Vercel's own note says it best — a fallback \"would preserve a behaviour that is\n // broken by construction: an entry that scans, finds nothing, and answers 404 while looking like it\n // tried.\"\n const agentsFragment = deployedAgentsFragment(\n { kind: 'baked', agents: opts.agents ?? [], contextModule: opts.contextModule },\n {\n pathname: 'path',\n // This entry has no `url` object: `eventV2ToRequest` builds a STRING, in another function.\n // `request` is what routeRequest holds, and it carries the same absolute URL that string was.\n baseUrl: 'new URL(request.url).origin',\n notFound: JSON_NOT_FOUND_RESPONSE,\n },\n )\n return [\n `// Generated by Theo — AWS Lambda Adapter`,\n `// Use with API Gateway HTTP API v2 (default).`,\n ``,\n `import { resolve } from 'node:path'`,\n `import { matchRoute, compilePattern } from 'theokit/server/scan'\\nimport { executeRoute, extractTraceIdFromRequest, TRACE_HEADER, createCorsWebHandler } from 'theokit/server/http'`,\n ...routeImports,\n `import { createWebShim } from 'theokit/adapters/web-shim'`,\n `import { buildSecurityHeaders, withSecurityHeaders } from 'theokit/adapters/security-headers'`,\n ``,\n `const cwd = process.cwd()`,\n `const serverDir = resolve(cwd, ${serverDirLiteral(opts)})`,\n ...routeRuntimeLines(routeModuleEntries, routeTableEntries, TARGET),\n ``,\n `// #410 — the security baseline \\`theokit start\\` puts on every response,`,\n `// carried here as a literal because the deployed function has no`,\n `// theo.config.ts to read. Non-API paths 404 here and the document is served`,\n `// from CloudFront or another static host, so this covers the API and not the`,\n `// page (usetheokit/theokit#412).`,\n ...deployedEntryPreamble(\n runtimeConfig,\n agentsFragment,\n opts,\n 'aws-lambda',\n deployedReservedRoutesFragment(opts),\n ),\n ``,\n `function eventV2ToRequest(event) {`,\n ` const method = event.requestContext?.http?.method ?? 'GET'`,\n ` const path = event.requestContext?.http?.path ?? '/'`,\n ` const host = event.headers?.host ?? 'lambda'`,\n ` const qs = event.rawQueryString ? '?' + event.rawQueryString : ''`,\n ` const url = 'https://' + host + path + qs`,\n ` const headers = new Headers()`,\n ` for (const [k, v] of Object.entries(event.headers ?? {})) {`,\n ` if (v !== undefined) headers.set(k, String(v))`,\n ` }`,\n ` let body = event.body`,\n ` if (body && event.isBase64Encoded) {`,\n ` body = Buffer.from(body, 'base64')`,\n ` }`,\n ` return new Request(url, {`,\n ` method,`,\n ` headers,`,\n ` body: method === 'GET' || method === 'HEAD' ? undefined : body,`,\n ` })`,\n `}`,\n ``,\n ...awsLambdaHandlerFragment(\n runtimeConfig.executeRouteSpread,\n agentsFragment.branch,\n agentsFragment.hostBypass,\n opts.rateLimit,\n ),\n ].join('\\n')\n}\n\n/**\n * Resolve the build's effective dependencies once.\n *\n * Extracted when `buildAwsLambda` crossed the complexity ceiling after B-344 added the bundling\n * seam. The defaults are a separate concern from the build's sequence (SRP), and the sequence is\n * the part a reader comes here to follow. Same extraction as `resolveNetlifyDeps`.\n */\nfunction resolveAwsLambdaDeps(deps: AwsLambdaBuildDeps): {\n runNodeBuild: NonNullable<AwsLambdaBuildDeps['runNodeBuild']>\n bundleFunction: NonNullable<AwsLambdaBuildDeps['bundleFunction']>\n ensureDir: NonNullable<AwsLambdaBuildDeps['ensureDir']>\n} {\n return {\n runNodeBuild: deps.runNodeBuild ?? nodeAdapter.build.bind(nodeAdapter),\n bundleFunction: deps.bundleFunction ?? bundleDeployedFunction,\n ensureDir: deps.ensureDir ?? ((path: string) => mkdirSync(path, { recursive: true })),\n }\n}\n\nexport async function buildAwsLambda(\n config: TheoConfig,\n cwd: string,\n deps: AwsLambdaBuildDeps = {},\n ctx?: AdapterBuildContext,\n): Promise<void> {\n const { runNodeBuild, bundleFunction, ensureDir } = resolveAwsLambdaDeps(deps)\n // Wave 2 (T2.2) — reject polyglot services on this adapter.\n assertServicesUnsupported('aws-lambda', readManifest(cwd))\n\n // #382 — refuse by name rather than build something that cannot do what was\n // asked. `ssrStreaming` is the config's declaration that responses stream,\n // and this target is delisted for that (see `awsLambdaAdapter.streamsResponses`).\n // Kept as a guard for a DIRECT call to this function, which bypasses the CLI. The normal path is\n // refused earlier, before anything is emptied — see `assertStreamingSupported` (B-336). One message,\n // declared in one place, so the two cannot drift apart.\n if (config.ssrStreaming) {\n const { assertStreamingSupported } = await import('./config-support.js')\n assertStreamingSupported(config, awsLambdaAdapter, 'aws-lambda')\n }\n\n await runNodeBuild(config, cwd, ctx)\n\n const outputDir = resolve(cwd, '.theokit/aws')\n ensureDir(outputDir)\n\n // B-344 — scanned on the BUILD machine, like cloudflare, vercel and netlify. An absent scanner\n // emits an entry with NO routes rather than falling back to a runtime scan: that fallback is what\n // answered 404 from a bundle with no source tree.\n const scanned = ctx?.scanRoutes?.(config.serverDir)\n\n const entry = renderAwsLambdaEntry({\n routes: scanned?.routes,\n agents: scanned?.agents,\n contextModule: scanned?.contextModule,\n securityHeaders: config.security?.headers,\n // B-315 — the same shape as the B-235 note below, one option over: this build never passed\n // `serverDir`, so a project declaring `src/server` got an entry resolving `server`.\n serverDir: config.serverDir,\n // B-235 — pillar (a): the option existed and no build passed it, so a project with a\n // configured agents directory got the default `agents` on this target. Same defect\n // B-185 fixed for bun and deno, one target over.\n agentsDir: config.agentsDir,\n csrf: config.security?.csrf,\n disallowed: config.security?.disallowed,\n cors: config.security?.cors,\n // #1097 — a probe cannot ride as a literal; the entry fails `/__theo/ready` closed instead.\n readyProbeDeclared: config.ready !== undefined,\n // #425 — a selector, not a transformer, so it rides as a literal like the values above.\n serialization: config.serialization,\n })\n // B-344 — bundled, not written as source. Unlike netlify the output goes into the directory\n // itself rather than a subdirectory: Lambda's handler is `<file>.<export>` and the operator zips\n // the directory, so the bundler's chunks travel without a per-function folder. Netlify needed one\n // because its platform treats each file in the functions directory as a separate function.\n await bundleFunction({\n projectRoot: cwd,\n entrySource: entry,\n stagePath: '.theokit/aws/handler.entry.mjs',\n outDir: outputDir,\n entryFileName: 'handler.mjs',\n })\n\n // eslint-disable-next-line no-console -- CLI build progress\n console.log('\\n ✓ AWS Lambda output → .theokit/aws/handler.mjs')\n // eslint-disable-next-line no-console -- CLI build progress\n console.log(\n `${describeDeployedSecurityHeaders({\n target: TARGET,\n securityHeaders: config.security?.headers,\n mintsNonce: false,\n documentHeaders: 'platform-unmanaged',\n })}\\n`,\n )\n}\n\nexport const awsLambdaAdapter: DeployAdapter = {\n // B-342 / B-344 — measured by INVOKING the handler from a directory with no `node_modules`:\n // `ERR_MODULE_NOT_FOUND: Cannot find package 'theokit'` as source, then 404 once bundled but\n // still scanning, then 200 with routes and agents baked.\n readsSourceAtRunTime: false,\n specifiersResolvedBy: 'this-adapter',\n name: TARGET,\n // #382 — delisted for streaming, deliberately. See DeployAdapter.\n streamsResponses: false,\n streamingUnsupportedDetail:\n 'The Lambda v2 result object carries the body as a string, so nothing can leave the function ' +\n 'before the run ends. Response streaming would need awslambda.streamifyResponse plus a Function ' +\n 'URL in RESPONSE_STREAM invoke mode, which this adapter does not emit.',\n // #409 / #410 — the generated entry calls `executeRoute` with routes, loader\n // and serverDir only. CSRF, route policy, file middleware and Zod validation\n // still run because they live inside `executeRoute`; none of the remaining\n // configurable concerns reach it. Declared explicitly rather than omitted so\n // the gap is a statement in the source and not an absence.\n //\n // `securityHeaders` IS applied -- to every response this function returns.\n // The document comes from CloudFront or another static host and does not pass\n // through it (usetheokit/theokit#412).\n appliesConfig: ['securityHeaders', 'csrf', 'disallowed', 'cors', 'serialization'],\n // B-257 — per-invocation: an in-process counter does not survive, so a declared limit needs a durable store.\n enforcesRateLimit: 'with-a-store',\n build(config, cwd, ctx) {\n return buildAwsLambda(config, cwd, {}, ctx)\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AA2DxB,IAAM,uBAAuB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,oBAAoB,aAA0C;AACrE,MAAI,CAAC,YAAa,QAAO;AACzB,QAAM,KAAK,YAAY,YAAY;AACnC,SAAO,qBAAqB,KAAK,CAAC,WAAW,GAAG,WAAW,MAAM,CAAC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
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
serveReservedRoute
|
|
3
|
-
} from "../chunk-TRCJHFAX.js";
|
|
4
1
|
import {
|
|
5
2
|
envelopeCodeToStatus
|
|
6
3
|
} from "../chunk-ACKBVBUI.js";
|
|
@@ -8,6 +5,9 @@ import {
|
|
|
8
5
|
NotFoundError,
|
|
9
6
|
serverErrorToEnvelope
|
|
10
7
|
} from "../chunk-IZ3TIL6K.js";
|
|
8
|
+
import {
|
|
9
|
+
serveReservedRoute
|
|
10
|
+
} from "../chunk-TRCJHFAX.js";
|
|
11
11
|
import "../chunk-XTHN6JBX.js";
|
|
12
12
|
|
|
13
13
|
// src/server/boot.ts
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
VALID_TARGETS,
|
|
8
8
|
targetRendersDocument
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PV6IO25S.js";
|
|
10
10
|
import {
|
|
11
11
|
describeControllerArtifacts,
|
|
12
12
|
emitControllerArtifacts
|
|
@@ -348,9 +348,9 @@ async function buildCommand(options) {
|
|
|
348
348
|
`Invalid build target "${target}". Available targets: ${VALID_TARGETS.join(", ")}`
|
|
349
349
|
);
|
|
350
350
|
}
|
|
351
|
-
const { resolveAdapter, streamingTargets } = await import("./registry-
|
|
351
|
+
const { resolveAdapter, streamingTargets } = await import("./registry-JHWY7JRY.js");
|
|
352
352
|
const adapter = await resolveAdapter(target);
|
|
353
|
-
const { assertRateLimitEnforceable, assertStreamingSupported } = await import("./config-support-
|
|
353
|
+
const { assertRateLimitEnforceable, assertStreamingSupported } = await import("./config-support-ZJIRVUWZ.js");
|
|
354
354
|
assertRateLimitEnforceable(config, adapter, target);
|
|
355
355
|
assertStreamingSupported(config, adapter, target, await streamingTargets());
|
|
356
356
|
const distDirAbs = resolve2(cwd, config.distDir);
|
|
@@ -411,7 +411,7 @@ async function buildCommand(options) {
|
|
|
411
411
|
`);
|
|
412
412
|
}
|
|
413
413
|
async function runAdapterBuild(target, config, cwd, adapter) {
|
|
414
|
-
const { theoPluginAsync } = await import("./vite-plugin-
|
|
414
|
+
const { theoPluginAsync } = await import("./vite-plugin-JMWUVMP3.js");
|
|
415
415
|
const { default: react } = await import("@vitejs/plugin-react");
|
|
416
416
|
const ctx = {
|
|
417
417
|
// `react()` may return Plugin or Plugin[] depending on version; spread the
|
|
@@ -437,7 +437,7 @@ async function runAdapterBuild(target, config, cwd, adapter) {
|
|
|
437
437
|
// any test while it lived in here, because reaching it meant running the whole build.
|
|
438
438
|
scanRoutes: createBuildScanRoutes(cwd, config)
|
|
439
439
|
};
|
|
440
|
-
const { warnUnappliedConfig } = await import("./config-support-
|
|
440
|
+
const { warnUnappliedConfig } = await import("./config-support-ZJIRVUWZ.js");
|
|
441
441
|
warnUnappliedConfig(config, adapter, target, (message) => {
|
|
442
442
|
console.log(message);
|
|
443
443
|
});
|
|
@@ -506,4 +506,4 @@ function relativize3(absPath, root) {
|
|
|
506
506
|
export {
|
|
507
507
|
buildCommand
|
|
508
508
|
};
|
|
509
|
-
//# sourceMappingURL=build-
|
|
509
|
+
//# sourceMappingURL=build-2VOQOWZE.js.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-IJQQNHL7.js";
|
|
6
6
|
import {
|
|
7
7
|
deployedEntryPreamble
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-N7KDDYDB.js";
|
|
9
9
|
import {
|
|
10
10
|
planDeployedPlugins
|
|
11
11
|
} from "./chunk-C43AHOHI.js";
|
|
@@ -13,15 +13,17 @@ import {
|
|
|
13
13
|
agentsDirLiteral,
|
|
14
14
|
deployedAgentsFragment,
|
|
15
15
|
deployedRateLimitFragment,
|
|
16
|
+
deployedReservedRoutesFragment,
|
|
16
17
|
deployedRuntimeConfigFragment,
|
|
17
18
|
deployedTraceFragment,
|
|
18
19
|
describeDeployedSecurityHeaders,
|
|
19
20
|
rateLimitCheckFragment,
|
|
21
|
+
reservedRouteBranch,
|
|
20
22
|
serverDirLiteral
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-DDWF3UUI.js";
|
|
22
24
|
import {
|
|
23
25
|
nodeAdapter
|
|
24
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-MQCXYZEV.js";
|
|
25
27
|
import "./chunk-3PWQQWT6.js";
|
|
26
28
|
import "./chunk-WSMLSIS5.js";
|
|
27
29
|
import {
|
|
@@ -114,7 +116,13 @@ function renderBunEntry(port, opts = {}) {
|
|
|
114
116
|
`// the HTML document (static file + SPA fallback below), so the document gets`,
|
|
115
117
|
`// these headers too -- with a nonce-less CSP, because that HTML was written`,
|
|
116
118
|
`// at build time and carries no nonce on its script tags (EC-4).`,
|
|
117
|
-
...deployedEntryPreamble(
|
|
119
|
+
...deployedEntryPreamble(
|
|
120
|
+
runtimeConfig,
|
|
121
|
+
agentsFragment,
|
|
122
|
+
opts,
|
|
123
|
+
"bun",
|
|
124
|
+
deployedReservedRoutesFragment(opts)
|
|
125
|
+
),
|
|
118
126
|
``,
|
|
119
127
|
...deployedRateLimitFragment(opts.rateLimit, "bun", "server.requestIP(request)?.address"),
|
|
120
128
|
``,
|
|
@@ -161,6 +169,7 @@ function bunHandleRequestFragment(runtimeSpread, agentBranch, document) {
|
|
|
161
169
|
`async function handleRequest(request) {`,
|
|
162
170
|
` const url = new URL(request.url)`,
|
|
163
171
|
` const pathname = url.pathname`,
|
|
172
|
+
...reservedRouteBranch("pathname", " "),
|
|
164
173
|
``,
|
|
165
174
|
` // 1) Static assets`,
|
|
166
175
|
...document === void 0 ? [
|
|
@@ -240,6 +249,8 @@ async function buildBun(config, cwd, deps = {}, ctx) {
|
|
|
240
249
|
csrf: config.security?.csrf,
|
|
241
250
|
disallowed: config.security?.disallowed,
|
|
242
251
|
cors: config.security?.cors,
|
|
252
|
+
// #1097 — a probe cannot ride as a literal; the entry fails `/__theo/ready` closed instead.
|
|
253
|
+
readyProbeDeclared: config.ready !== void 0,
|
|
243
254
|
// #425 — a selector, not a transformer, so it rides as a literal like the values above.
|
|
244
255
|
serialization: config.serialization,
|
|
245
256
|
// #425 — the ONE concern that is not a literal. A closure cannot be baked, so a plugin
|
|
@@ -322,4 +333,4 @@ export {
|
|
|
322
333
|
bunAdapter,
|
|
323
334
|
renderBunEntry
|
|
324
335
|
};
|
|
325
|
-
//# sourceMappingURL=bun-
|
|
336
|
+
//# sourceMappingURL=bun-73JZLCKU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/bun.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * Bun deploy adapter. Writes to `cwd/.theokit/bun/`. Build-time.\n */\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport type { TheoConfig } from '../config/schema.js'\nimport type { SecurityHeadersConfig } from '../core/contracts/security-headers.js'\nimport { assertServicesUnsupported, readManifest } from '../services/index.js'\n\nimport { deployedAgentsFragment } from './deployed-agents.js'\nimport { type DeployedCorsOptions } from './deployed-cors.js'\nimport { type DeployedCsrfOptions } from './deployed-csrf.js'\nimport { readDocumentShell } from './deployed-document-shell.js'\nimport { planDeployedPlugins } from './deployed-plugins-module.js'\nimport { deployedEntryPreamble } from './deployed-preamble.js'\nimport {\n deployedRateLimitFragment,\n rateLimitCheckFragment,\n type DeployedRateLimitOptions,\n} from './deployed-rate-limit.js'\nimport { deployedReservedRoutesFragment, reservedRouteBranch } from './deployed-reserved-routes.js'\nimport type { DeployedReservedRoutesOptions } from './deployed-reserved-routes.js'\nimport {\n deployedRuntimeConfigFragment,\n agentsDirLiteral,\n serverDirLiteral,\n type DeployedRuntimeConfigOptions,\n type DeployedAgentsDirOptions,\n type DeployedServerDirOptions,\n} from './deployed-runtime-config.js'\nimport { deployedTraceFragment } from './deployed-trace.js'\nimport { nodeAdapter } from './node.js'\nimport { describeDeployedSecurityHeaders } from './security-headers.js'\nimport type { AdapterBuildContext, DeployAdapter } from './types.js'\n\nexport interface BunBuildDeps {\n runNodeBuild?: (config: TheoConfig, cwd: string, ctx?: AdapterBuildContext) => Promise<void>\n writeEntry?: (path: string, content: string) => void\n ensureDir?: (path: string) => void\n}\n\n/**\n * How a person starts the emitted entry. Printed by the build and repeated by the dev-mode guard,\n * because the guard is what someone meets after running the path the build printed without\n * `NODE_ENV` (measured 2026-10-02).\n */\nconst BUN_START_COMMAND = 'NODE_ENV=production bun .theokit/bun/server.mjs'\n\n/**\n * The module-scope refusals: this entry is production-only and Bun-only.\n *\n * Extracted from `renderBunEntry` when adding the configured-directory literal pushed it past the\n * per-function line budget. They are a cohesive block — three checks that all refuse to start —\n * and lifting them keeps the budget a signal about the renderer rather than about its preamble.\n */\nconst RUNTIME_GUARDS: readonly string[] = [\n `// EC-1: dev-mode guard`,\n `if (process.env.NODE_ENV !== 'production') {`,\n ` console.error('TheoBunAdapter is production-only: start it with \\\\'${BUN_START_COMMAND}\\\\' from the project root. For development, use \\\\'theokit dev\\\\' (Node).')`,\n ` process.exit(1)`,\n `}`,\n ``,\n `// Version check: Bun >= 1.1`,\n `if (typeof Bun === 'undefined') {`,\n ` console.error('TheoBunAdapter must run inside Bun. Got Node.js or unknown runtime.')`,\n ` process.exit(1)`,\n `}`,\n `{`,\n ` const [maj, min] = (Bun.version ?? '0.0').split('.').map(Number)`,\n ` if (maj < 1 || (maj === 1 && min < 1)) {`,\n ` console.error('TheoBunAdapter requires Bun >= 1.1; got ' + Bun.version)`,\n ` process.exit(1)`,\n ` }`,\n `}`,\n]\n\nexport function renderBunEntry(\n port: number,\n opts: {\n ssrStreaming?: boolean\n /**\n * Whether this build renders the document on the server.\n *\n * Bun is the one Web target whose own handler answers the HTML document, and it answered it from\n * `.theokit/client/index.html` — the client shell. So an `ssr: true` project was served an empty\n * `<div id=\"root\">` while the build printed `(SSR)` (B-334).\n */\n ssr?: boolean\n /** The document up to `<div id=\"root\">`, read from the built client shell. */\n htmlHead?: string\n /** The document from `<div id=\"root\">` on. */\n htmlTail?: string\n securityHeaders?: SecurityHeadersConfig\n } & DeployedAgentsDirOptions &\n DeployedCsrfOptions &\n DeployedRuntimeConfigOptions &\n DeployedServerDirOptions &\n DeployedCorsOptions &\n DeployedRateLimitOptions &\n DeployedReservedRoutesOptions = {},\n): string {\n // The whole implementation of `ssrStreaming` in this adapter used to be the text of this comment:\n // `opts.ssrStreaming` was read, and its only effect was which string landed on line 4 of the emitted\n // file. `rules/foreign-config-surfaces.md` names that exact failure — \"A surface is read, or it is\n // refused with a reason. It is never accepted and ignored\" — and it was in this adapter.\n const document =\n opts.ssr === true ? { htmlHead: opts.htmlHead, htmlTail: opts.htmlTail } : undefined\n const streamingComment =\n document !== undefined\n ? `// ssr on — the document is rendered by this handler, not read from .theokit/client`\n : `// ssr off — the document is the built client shell, served from disk`\n const runtimeConfig = deployedRuntimeConfigFragment(opts)\n const agentsFragment = deployedAgentsFragment(\n {\n kind: 'scan',\n projectRoot: 'cwd',\n loadModule: 'loadModule',\n serverDir: 'serverDir',\n agentsDirLiteral: agentsDirLiteral(opts),\n },\n {\n pathname: 'pathname',\n // B-185 — bound only when the runtime-config fragment declared the const, which is\n // exactly when a plugins module was emitted. Referencing it otherwise would emit an\n // identifier the entry never declares.\n pluginRunnerExpr:\n opts.runtimeConfigModule === undefined ? undefined : 'await THEO_PLUGIN_RUNNER',\n },\n )\n return [\n `// Generated by Theo — Bun Adapter`,\n `// Run: bun run .theokit/bun/server.mjs`,\n `// Requires Bun >= 1.1`,\n streamingComment,\n ``,\n ...RUNTIME_GUARDS,\n ``,\n `import { resolve, join } from 'node:path'`,\n `import { existsSync } from 'node:fs'`,\n // One element per emitted line, like every neighbour, and the conditional import is a spread\n // rather than an interpolated `\\n`. That is not a style preference: this line carried the\n // fragment inside a nested double-quoted string, where an escaped backslash is a backslash, so\n // the import reached the module joined by two characters and Bun refused it. A construct that\n // cannot express a malformed line beats one escaped correctly (B-325), and `sonarjs` refuses the\n // nesting outright — the lint was naming the cause.\n `import { scanServerRoutes, matchRoute, createProductionLoader } from 'theokit/server/scan'`,\n `import { executeRoute, extractTraceIdFromRequest, TRACE_HEADER, createCorsWebHandler } from 'theokit/server/http'`,\n ...(opts.rateLimit === undefined\n ? []\n : [`import { createRateLimiterWeb } from 'theokit/server/rate-limit'`]),\n `import { createWebShim } from 'theokit/adapters/web-shim'`,\n `import { buildSecurityHeaders, withSecurityHeaders } from 'theokit/adapters/security-headers'`,\n // The renderer the node build already emits for this target and nothing imported. Its own header\n // names Bun: \"Web Standards streaming entry for edge runtimes (Cloudflare, Bun, Deno, Vercel\n // Edge)\". Measured on a real build: `.theokit/server/entry-server.js` is 95513 bytes and exports\n // the render, and `.theokit/bun/server.mjs` referenced it zero times.\n ...(document === undefined\n ? []\n : [`import { renderStreamingWeb } from '../server/entry-server.js'`]),\n `// T3.2 — WS bridge for Bun runtime`,\n `import { createBunWsBridge } from 'theokit/adapters/ws-shim'`,\n `import { scanWebSocketRoutes } from 'theokit/server/scan'`,\n ``,\n `const cwd = process.cwd()`,\n `const clientDir = resolve(cwd, '.theokit/client')`,\n `const serverDir = resolve(cwd, ${serverDirLiteral(opts)})`,\n `const port = process.env.PORT ? Number(process.env.PORT) : ${port}`,\n ``,\n `// #410 — the security baseline \\`theokit start\\` puts on every response,`,\n `// carried here as a literal because the deployed process has no`,\n `// theo.config.ts to read. Bun is the one Web target whose own handler serves`,\n `// the HTML document (static file + SPA fallback below), so the document gets`,\n `// these headers too -- with a nonce-less CSP, because that HTML was written`,\n `// at build time and carries no nonce on its script tags (EC-4).`,\n ...deployedEntryPreamble(\n runtimeConfig,\n agentsFragment,\n opts,\n 'bun',\n deployedReservedRoutesFragment(opts),\n ),\n ``,\n ...deployedRateLimitFragment(opts.rateLimit, 'bun', 'server.requestIP(request)?.address'),\n ``,\n `const routes = existsSync(serverDir) ? scanServerRoutes(serverDir) : []`,\n `const wsRoutes = existsSync(serverDir) ? scanWebSocketRoutes(serverDir) : []`,\n `const loadModule = createProductionLoader()`,\n ``,\n `// Bun WebSocket config — single handler dispatches to first ws route,`,\n `// or a default no-op when none declared. Per-route routing happens above`,\n `// (the upgrade decision is made in fetch handler before Bun.serve hands off).`,\n `const wsBridge = wsRoutes.length > 0`,\n ` ? createBunWsBridge({`,\n ` onOpen: () => {},`,\n ` onMessage: (ws, data) => { ws.send(data) },`,\n ` onClose: () => {},`,\n ` })`,\n ` : { open: () => {}, message: () => {}, close: () => {} }`,\n ``,\n `function notFoundResponse() {`,\n ` return new Response(JSON.stringify({ error: { code: 'NOT_FOUND', message: 'Route not found' } }), {`,\n ` status: 404,`,\n ` headers: { 'Content-Type': 'application/json' },`,\n ` })`,\n `}`,\n ``,\n `Bun.serve({`,\n ` port,`,\n ` websocket: wsBridge,`,\n ` async fetch(request, server) {`,\n ` // #409 — the preflight is answered BEFORE anything routes: an OPTIONS the router`,\n ` // handles is an OPTIONS the browser never gets a CORS answer to.`,\n ` const preflight = corsPreflight(request)`,\n ` if (preflight !== null) return withSecurityHeaders(preflight, SECURITY_HEADERS)`,\n ...rateLimitCheckFragment(opts.rateLimit, ' '),\n ` return withCors(request, withSecurityHeaders(await handleRequest(request), SECURITY_HEADERS))`,\n ` },`,\n `})`,\n ``,\n ...bunHandleRequestFragment(runtimeConfig.executeRouteSpread, agentsFragment.branch, document),\n ].join('\\n')\n}\n\n/**\n * The request handler, as generated source.\n *\n * Extracted for the reason `vercel.ts` extracts its own fragments: the emitter is one array\n * literal, so every line the entry gains counts against `max-lines-per-function`, and #410 added\n * the CSRF literal to an emitter that was already sitting exactly at the ceiling.\n */\nfunction bunHandleRequestFragment(\n runtimeSpread: string,\n agentBranch: readonly string[],\n document: { htmlHead?: string; htmlTail?: string } | undefined,\n): string[] {\n return [\n `async function handleRequest(request) {`,\n ` const url = new URL(request.url)`,\n ` const pathname = url.pathname`,\n ...reservedRouteBranch('pathname', ' '),\n ``,\n ` // 1) Static assets`,\n ...(document === undefined\n ? [\n ` const staticPath = pathname === '/' ? '/index.html' : pathname`,\n ` const fullStatic = join(clientDir, staticPath)`,\n ` if (existsSync(fullStatic)) {`,\n ` const file = Bun.file(fullStatic)`,\n ` if (await file.exists()) return new Response(file)`,\n ` }`,\n ]\n : [\n ` // \\`/\\` is deliberately NOT mapped to index.html here: that file is the client shell,`,\n ` // and answering the document from it is what served an empty <div id=\"root\"> on an`,\n ` // ssr build. Real assets still come from disk; the document falls through to (3).`,\n ` if (pathname !== '/') {`,\n ` const fullStatic = join(clientDir, pathname)`,\n ` if (existsSync(fullStatic)) {`,\n ` const file = Bun.file(fullStatic)`,\n ` if (await file.exists()) return new Response(file)`,\n ` }`,\n ` }`,\n ]),\n ``,\n ` // 2) API routes through the full executeRoute pipeline via the shim`,\n ` if (pathname.startsWith('/api/') || __theoIsAgentCardPath(pathname)) {`,\n ...agentBranch,\n ``,\n ` const match = matchRoute(pathname, routes)`,\n ` if (!match) return notFoundResponse()`,\n ` const { req, res, toResponse } = createWebShim(request)`,\n ...deployedTraceFragment('request', ' '),\n ` const method = request.method.toUpperCase()`,\n ` // #382 — not awaited: toResponse() settles at the headers and carries`,\n ` // a live body, so Bun.serve streams while the handler writes.`,\n ` return toResponse(executeRoute({ route: match.route, method, params: match.params, req, res, loadModule, serverDir, requestId, ...CSRF_CONFIG, ${runtimeSpread} }))`,\n ` }`,\n ``,\n ...(document === undefined\n ? [\n ` // 3) SPA fallback`,\n ` const indexPath = join(clientDir, 'index.html')`,\n ` if (existsSync(indexPath)) return new Response(Bun.file(indexPath))`,\n ]\n : [\n ` // 3) The document, rendered here rather than read from disk.`,\n ` //`,\n ` // No nonce is minted: the outer wrapper applies a precomputed SECURITY_HEADERS constant,`,\n ` // so a per-request value would have to be threaded through it. That is a separate change`,\n ` // with its own blast radius, and the shell this replaces carries only external`,\n ` // <script src> tags, which \\`script-src 'self'\\` already allows.`,\n ` return await renderStreamingWeb(request, {`,\n ` htmlHead: ${JSON.stringify(document.htmlHead ?? '')},`,\n ` htmlTail: ${JSON.stringify(document.htmlTail ?? '')},`,\n ` })`,\n ]),\n ``,\n ` return notFoundResponse()`,\n `}`,\n ``,\n `console.log('Theo (Bun) listening on http://localhost:' + port)`,\n ]\n}\n\nexport async function buildBun(\n config: TheoConfig,\n cwd: string,\n deps: BunBuildDeps = {},\n ctx?: AdapterBuildContext,\n): Promise<void> {\n // Wave 2 (T2.2) — reject polyglot services on this adapter.\n assertServicesUnsupported('bun', readManifest(cwd))\n\n const runNodeBuild = deps.runNodeBuild ?? nodeAdapter.build.bind(nodeAdapter)\n await runNodeBuild(config, cwd, ctx)\n\n const outputDir = resolve(cwd, '.theokit/bun')\n const ensureDir = deps.ensureDir ?? ((p: string) => mkdirSync(p, { recursive: true }))\n ensureDir(outputDir)\n\n const pluginsPlan = planDeployedPlugins(config.plugins, 'bun')\n const entry = renderBunEntry(config.port, {\n ssrStreaming: config.ssrStreaming,\n // B-334 — the sixth time this shape has been fixed one target at a time: the renderer honoured an\n // option no build passed (B-185, B-235, B-312, B-315, B-317). Here it was worse — the option only\n // changed a comment. The shell is read HERE rather than in the emitter, because reading a file is\n // the build's job and not a string emitter's.\n ssr: config.ssr,\n ...readDocumentShell(cwd, config.ssr),\n securityHeaders: config.security?.headers,\n csrf: config.security?.csrf,\n disallowed: config.security?.disallowed,\n cors: config.security?.cors,\n // #1097 — a probe cannot ride as a literal; the entry fails `/__theo/ready` closed instead.\n readyProbeDeclared: config.ready !== undefined,\n // #425 — a selector, not a transformer, so it rides as a literal like the values above.\n serialization: config.serialization,\n // #425 — the ONE concern that is not a literal. A closure cannot be baked, so a plugin\n // declared by module specifier is imported by the emitted module instead; a constructed one\n // is refused by name at build time rather than dropped in silence.\n runtimeConfigModule: pluginsPlan?.moduleSpecifier,\n // #95 — the configured directories, which `build.ts:210` already threads into the Vite\n // plugins. Without these two lines the literals above fall to their defaults and a project\n // with a custom dir deploys an entry that resolves a directory it does not have.\n serverDir: config.serverDir,\n agentsDir: config.agentsDir,\n })\n const write =\n deps.writeEntry ??\n ((p, c) => {\n writeFileSync(p, c)\n })\n if (pluginsPlan !== undefined) {\n // Beside the entry, so the emitted import is a sibling. Written through the same seam as\n // the entry so a test that captures one captures both (#425).\n write(resolve(outputDir, 'theo.plugins.mjs'), pluginsPlan.source)\n }\n write(resolve(outputDir, 'server.mjs'), entry)\n\n // eslint-disable-next-line no-console -- CLI build progress\n console.log('\\n ✓ Bun output → .theokit/bun/server.mjs')\n // eslint-disable-next-line no-console -- CLI build progress\n console.log(` start it with: ${BUN_START_COMMAND}`)\n // eslint-disable-next-line no-console -- CLI build progress\n console.log(\n `${describeDeployedSecurityHeaders({\n target: 'bun',\n securityHeaders: config.security?.headers,\n // Bun renders the document at request time when `ssr` is on (B-334), and still mints no nonce:\n // the outer wrapper applies a precomputed SECURITY_HEADERS constant, so a per-request value\n // would have to be threaded through it.\n //\n // This used to read \"No deploy target other than the streamed Cloudflare worker renders HTML at\n // request time, so none of the rest can mint a nonce.\" True when written, false the moment B-317\n // shipped — a CONSEQUENCE of the fleet at the time, never a prohibition, which is why rendering\n // here is consistent with the intent rather than against it.\n mintsNonce: false,\n // Bun serves `.theokit/client` itself, so the document DOES pass through\n // the handler these headers are attached to.\n documentHeaders: 'handler',\n })}\\n`,\n )\n}\n\nexport const bunAdapter: DeployAdapter = {\n // The entry runs IN the project: it resolves `serverDir` against `cwd`, so `node_modules` is\n // present and the scan has a tree to read. `docs/adr/0020` leaves this target alone for exactly\n // that reason.\n readsSourceAtRunTime: true,\n specifiersResolvedBy: 'the-project-at-run-time',\n name: 'bun',\n streamsResponses: true,\n // #409 / #410 — the generated entry calls `executeRoute` with routes, loader\n // and serverDir only. CSRF, route policy, file middleware and Zod validation\n // still run because they live inside `executeRoute`; none of the remaining\n // configurable concerns reach it. Declared explicitly rather than omitted so\n // the gap is a statement in the source and not an absence.\n //\n // `securityHeaders` IS applied: the entry carries `security.headers` as a\n // literal and puts the built baseline on every response, the served document\n // included.\n servesAgents: true,\n appliesConfig: [\n 'securityHeaders',\n 'csrf',\n 'disallowed',\n 'cors',\n 'serialization',\n 'plugins',\n // #508 — bun is the first Web target to ENFORCE a declared limit rather than refuse the\n // build: `Bun.serve` is long-lived, so the in-process counter survives, and its handler\n // already receives `server`, whose `requestIP` gives the peer address without a header.\n 'rateLimit',\n ],\n // B-257 — a long-lived process: the in-process counter survives between requests.\n enforcesRateLimit: 'always',\n build(config, cwd, ctx) {\n return buildBun(config, cwd, {}, ctx)\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,WAAW,qBAAqB;AACzC,SAAS,eAAe;AA2CxB,IAAM,oBAAoB;AAS1B,IAAM,iBAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA,wEAAwE,iBAAiB;AAAA,EACzF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,eACd,MACA,OAqBkC,CAAC,GAC3B;AAKR,QAAM,WACJ,KAAK,QAAQ,OAAO,EAAE,UAAU,KAAK,UAAU,UAAU,KAAK,SAAS,IAAI;AAC7E,QAAM,mBACJ,aAAa,SACT,6FACA;AACN,QAAM,gBAAgB,8BAA8B,IAAI;AACxD,QAAM,iBAAiB;AAAA,IACrB;AAAA,MACE,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,kBAAkB,iBAAiB,IAAI;AAAA,IACzC;AAAA,IACA;AAAA,MACE,UAAU;AAAA;AAAA;AAAA;AAAA,MAIV,kBACE,KAAK,wBAAwB,SAAY,SAAY;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;A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EACF;AAAA;AAAA,EAEA,mBAAmB;AAAA,EACnB,MAAM,QAAQ,KAAK,KAAK;AACtB,WAAO,SAAS,QAAQ,KAAK,CAAC,GAAG,GAAG;AAAA,EACtC;AACF;","names":[]}
|
|
@@ -654,6 +654,35 @@ function rateLimitCheckFragment(rateLimit, indent, args = "request, server", ref
|
|
|
654
654
|
];
|
|
655
655
|
}
|
|
656
656
|
|
|
657
|
+
// src/adapters/deployed-reserved-routes.ts
|
|
658
|
+
var SERVE_FN = "__theoServeReservedRoute";
|
|
659
|
+
function deployedReservedRoutesFragment(opts, importPrefix = "") {
|
|
660
|
+
const declared = opts.readyProbeDeclared === true;
|
|
661
|
+
return {
|
|
662
|
+
imports: [
|
|
663
|
+
`import { serveReservedRoute${declared ? ", defineReadyRoute" : ""} } from '${importPrefix}theokit/server/http'`
|
|
664
|
+
],
|
|
665
|
+
declarations: [
|
|
666
|
+
`// #1097 \u2014 /__theo/health and /__theo/ready, answered by the function \`theokit start\` calls.`,
|
|
667
|
+
...declared ? [
|
|
668
|
+
`// theo.config.ts declares a \`ready\` probe. It is a closure, which a generated entry cannot`,
|
|
669
|
+
`// hold, so readiness fails closed (503) instead of answering ready on the probe's behalf.`,
|
|
670
|
+
`const __THEO_RESERVED_ROUTES = { ready: defineReadyRoute(() => false) }`
|
|
671
|
+
] : [`const __THEO_RESERVED_ROUTES = {}`],
|
|
672
|
+
`async function ${SERVE_FN}(pathname) {`,
|
|
673
|
+
` const reserved = await serveReservedRoute(pathname, __THEO_RESERVED_ROUTES)`,
|
|
674
|
+
` return reserved === null ? null : Response.json(reserved.body, { status: reserved.status })`,
|
|
675
|
+
`}`
|
|
676
|
+
]
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
function reservedRouteBranch(pathname, indent) {
|
|
680
|
+
return [
|
|
681
|
+
`${indent}const reservedResponse = await ${SERVE_FN}(${pathname})`,
|
|
682
|
+
`${indent}if (reservedResponse !== null) return reservedResponse`
|
|
683
|
+
];
|
|
684
|
+
}
|
|
685
|
+
|
|
657
686
|
// src/adapters/deployed-runtime-config.ts
|
|
658
687
|
function serverDirLiteral(opts) {
|
|
659
688
|
return JSON.stringify(opts.serverDir ?? "server");
|
|
@@ -723,9 +752,11 @@ export {
|
|
|
723
752
|
describeDeployedSecurityHeaders,
|
|
724
753
|
deployedRateLimitFragment,
|
|
725
754
|
rateLimitCheckFragment,
|
|
755
|
+
deployedReservedRoutesFragment,
|
|
756
|
+
reservedRouteBranch,
|
|
726
757
|
serverDirLiteral,
|
|
727
758
|
agentsDirLiteral,
|
|
728
759
|
deployedRuntimeConfigFragment,
|
|
729
760
|
deployedTraceFragment
|
|
730
761
|
};
|
|
731
|
-
//# sourceMappingURL=chunk-
|
|
762
|
+
//# sourceMappingURL=chunk-DDWF3UUI.js.map
|