@builtbyfriends/bwf 0.0.0-stage → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS_TEMPLATE.md +4 -0
- package/LICENSE +22 -0
- package/README.md +48 -2
- package/dist/account-cmd-Cj0I2_bJ.mjs +45 -0
- package/dist/agents-BLiMq9E1.mjs +113 -0
- package/dist/application-analysis-C9Ck2Yeg.mjs +1498 -0
- package/dist/application-routing-DbR-W5lG.mjs +25 -0
- package/dist/atomic-write-DA6eD1Kp.mjs +17 -0
- package/dist/auth-BKsUmWbT.d.mts +77 -0
- package/dist/auth-DkvoW5hB.mjs +33 -0
- package/dist/auth-aKyIWkdS.mjs +1 -0
- package/dist/auth-client-6-Ft9i9T.d.mts +5 -0
- package/dist/auth-client-DwCdwKbw.mjs +5 -0
- package/dist/auth-client-react-CJdeErvM.mjs +5 -0
- package/dist/auth-client-react-DvQLe5Zb.d.mts +5 -0
- package/dist/auth-link-D-DddkCQ.mjs +26 -0
- package/dist/auth-migrations-DDeifS3v.mjs +206 -0
- package/dist/auth-router-tWzIwf8f.mjs +66 -0
- package/dist/auth-xnkmpZUl.mjs +311 -0
- package/dist/base64-ikl9yBy3.mjs +15 -0
- package/dist/better-auth-shared-Br6TNaYJ.mjs +473 -0
- package/dist/better-auth-shared-CsBNvPOU.d.mts +56 -0
- package/dist/build-cmd-BnZezraT.mjs +153 -0
- package/dist/build-output-dir-Clj_unKN.mjs +402 -0
- package/dist/cancel-deploy-DKAj5U1Z.mjs +57 -0
- package/dist/cf-access-Bhz9wX6p.mjs +131 -0
- package/dist/cf-access-CUP5L08W.mjs +67 -0
- package/dist/cf-build-output-DA6uJomQ.mjs +1 -0
- package/dist/cf-build-output-DNQTwMNU.mjs +438 -0
- package/dist/cf-command-values-2kOtxMo1.mjs +26 -0
- package/dist/cf-config-migrate-COOCi4Ge.mjs +330 -0
- package/dist/cf-worker-settings-CIh4t_yG.mjs +41 -0
- package/dist/cli/cli.d.mts +1 -0
- package/dist/cli/cli.mjs +88 -0
- package/dist/cli/cloudflare-operation-process.d.mts +1 -0
- package/dist/cli/cloudflare-operation-process.mjs +1284 -0
- package/dist/cli/env-schema-probe.d.mts +43 -0
- package/dist/cli/env-schema-probe.mjs +165 -0
- package/dist/cli-main-HeXRQml6.mjs +1846 -0
- package/dist/client-D3D5RM5h.mjs +940 -0
- package/dist/client-VF2Nzc7Z.mjs +1 -0
- package/dist/cloudflare-auth-jb-1e43r.mjs +152 -0
- package/dist/cloudflare-cmd-B62t8Fm-.mjs +59 -0
- package/dist/cloudflare-config-i8yanry0.mjs +186 -0
- package/dist/cloudflare-connect-x7IsYghw.mjs +55 -0
- package/dist/cloudflare-operations-BeK7bhnP.mjs +627 -0
- package/dist/cloudflare-operations-C3Uu0Emj.mjs +1 -0
- package/dist/cloudflare-process-Cc6oiJqk.mjs +309 -0
- package/dist/cloudflare-user-output-CqONaAbP.mjs +19 -0
- package/dist/collect-8i0wU63d.mjs +1 -0
- package/dist/collect-C6Blu9yw.mjs +48 -0
- package/dist/config-CN_RFRkS.mjs +86 -0
- package/dist/config-D5G-Tx6o.mjs +1 -0
- package/dist/config-DOaFIK3w.mjs +88 -0
- package/dist/config-entry.d.mts +202 -0
- package/dist/config-entry.mjs +6 -0
- package/dist/config-tNx0HlFv.mjs +516 -0
- package/dist/connect-hLPNppu3.mjs +84 -0
- package/dist/create-project-B35ux-LA.mjs +126 -0
- package/dist/create-project-tJ1KwNss.mjs +1 -0
- package/dist/database-provider-DkZo4VwN.mjs +5 -0
- package/dist/database-provider.d.mts +25 -0
- package/dist/database-provider.mjs +1 -0
- package/dist/db-BH_md90k.mjs +1735 -0
- package/dist/delete-BSKI7V23.mjs +65 -0
- package/dist/deploy-C8KHBNsh.mjs +6512 -0
- package/dist/deploy-DCZBr7Ey.mjs +2 -0
- package/dist/deploy.d.mts +31 -0
- package/dist/deploy.mjs +118 -0
- package/dist/dev-inbox-I0nqTCdf.mjs +216 -0
- package/dist/discover-DJPmQcL5.mjs +36 -0
- package/dist/discover-EVuydEoM.mjs +1 -0
- package/dist/dist-B6eN80gc.mjs +1612 -0
- package/dist/dist-Cp4b1_T9.mjs +1 -0
- package/dist/dist-DMYe8CZJ.mjs +48 -0
- package/dist/dist-STQXl8ck.mjs +1878 -0
- package/dist/domain-C4ZhEiFG.mjs +149 -0
- package/dist/dotenv-4NdUCXbB.mjs +156 -0
- package/dist/drizzle-DqVFXtlc.mjs +306 -0
- package/dist/drizzle-Ds5P0n-S.mjs +1 -0
- package/dist/edge.d.mts +2 -0
- package/dist/edge.mjs +1 -0
- package/dist/email-B3TWga7x.mjs +742 -0
- package/dist/email-C_ATvNIG.mjs +2865 -0
- package/dist/email-cloudflare-DuAc9zny.mjs +854 -0
- package/dist/email-protocol-CZ0bAkI8.mjs +81 -0
- package/dist/env-CTAo8ifZ.mjs +73 -0
- package/dist/env-DUyTzroe.mjs +88 -0
- package/dist/env-Dl4Wggec.mjs +71 -0
- package/dist/env-helpers-BX0APszT.mjs +135 -0
- package/dist/env-helpers-U56xuFgL.d.mts +20 -0
- package/dist/env-mask-BsHxq3R8.mjs +46 -0
- package/dist/env-public-Cw_xPi1D.d.mts +119 -0
- package/dist/env-raw-Bo6TtrHU.mjs +41 -0
- package/dist/env-types-Bg-dTh8u.mjs +56 -0
- package/dist/env-validation-BufZConV.mjs +488 -0
- package/dist/env-validation-DPqDo4DU.mjs +1 -0
- package/dist/fetch-CBgyyhzm.d.mts +87 -0
- package/dist/fetch-error-DmlRM6e4.mjs +264 -0
- package/dist/fetch-stream-2GUN3YN1.mjs +102 -0
- package/dist/fetch-stream-bUXynOyZ.d.mts +32 -0
- package/dist/fetch-tpPiSK10.mjs +25 -0
- package/dist/gen-dc13IRXh.mjs +509 -0
- package/dist/gen-kQqhFyOP.mjs +1 -0
- package/dist/generate-BgtlYpKg.mjs +1 -0
- package/dist/generate-Da9mWKzU.mjs +80 -0
- package/dist/generated-wrangler-config-CoDaaFsA.mjs +17 -0
- package/dist/git-metadata-Cukp5kV5.mjs +82 -0
- package/dist/github-cmd-DT5Onu6E.mjs +690 -0
- package/dist/handler-CJ7DiiRF.mjs +161 -0
- package/dist/handler-CVsIfRv7.d.mts +279 -0
- package/dist/help-Bpv6Qeqn.mjs +1946 -0
- package/dist/help-CfZ4Bsw5.mjs +1 -0
- package/dist/inbound-CqubE-9T.d.mts +311 -0
- package/dist/inbound-lHugZPuK.mjs +509 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.mjs +4163 -0
- package/dist/info-CLQoCenb.mjs +109 -0
- package/dist/init-DRUR0j8C.mjs +2486 -0
- package/dist/limits-CMmYT2l8.d.mts +16 -0
- package/dist/limits-D27Lp6FP.mjs +46 -0
- package/dist/link-DinwJnon.mjs +52 -0
- package/dist/list-B84t4BhW.mjs +130 -0
- package/dist/live-Dui0-aj_.d.mts +105 -0
- package/dist/live-saC8barp.mjs +410 -0
- package/dist/load-user-env-g0ahkZcj.mjs +34 -0
- package/dist/local-d1-C3EeOV7-.mjs +103 -0
- package/dist/log-JDnPc0cF.mjs +23 -0
- package/dist/login-Bl5lH8nH.mjs +87 -0
- package/dist/login-DoI7AsbY.mjs +1 -0
- package/dist/logs-CaT2N2f7.mjs +129 -0
- package/dist/migrate-CbGscX-V.mjs +125 -0
- package/dist/migrate-Ce3JKLVs.mjs +1 -0
- package/dist/migration-handler-22qiuWPq.mjs +469 -0
- package/dist/migration-handler-Bb2BJh6g.d.mts +38 -0
- package/dist/mime-BMUN_QKG.mjs +1004 -0
- package/dist/mysql-migration-sql-CNuBSqdx.mjs +239 -0
- package/dist/neon-CJzQSycr.mjs +52 -0
- package/dist/node-tfv-3v0V.mjs +64 -0
- package/dist/operator-ai-logging-Ay7M4KWw.mjs +121 -0
- package/dist/operator-args-BFg32YyY.mjs +722 -0
- package/dist/operator-auth-DdYZYEkO.mjs +47 -0
- package/dist/operator-client-DBujdELO.mjs +82 -0
- package/dist/operator-cmd-C73WWJBl.mjs +443 -0
- package/dist/operator-cmd-CdZytuAF.mjs +1 -0
- package/dist/output-Bb34lF0w.mjs +173 -0
- package/dist/output-CVolXKC1.mjs +1 -0
- package/dist/package-DO4d3Qz5.mjs +1444 -0
- package/dist/package-json-DvS6IFRv.mjs +43 -0
- package/dist/pg-DoyPxa_X.mjs +15 -0
- package/dist/picocolors-D1NxSLw-.mjs +71 -0
- package/dist/plan-BHNt1QhK.mjs +1 -0
- package/dist/plan-DX4_-OM5.mjs +58 -0
- package/dist/platform-args-NI_vfWvD.mjs +538 -0
- package/dist/platform-args-ZC1-A1N9.mjs +1 -0
- package/dist/platform-auth-config-d-lY5-aY.mjs +371 -0
- package/dist/platform-auth-protection-Dhw7lUCk.mjs +231 -0
- package/dist/platform-auth-recovery-DaCc0tlx.mjs +309 -0
- package/dist/platform-cmd-5Ry-C9im.mjs +193 -0
- package/dist/platform-cmd-5oZq91lI.mjs +1 -0
- package/dist/platform-discovery-Bxg9aZXU.mjs +40 -0
- package/dist/platform-domain-DLVdGvGG.mjs +256 -0
- package/dist/platform-lifecycle-CUgjipXO.mjs +1 -0
- package/dist/platform-lifecycle-fRt5VMls.mjs +8928 -0
- package/dist/platform-management-5hEsRfR2.mjs +1 -0
- package/dist/platform-management-Djh1hzLP.mjs +1607 -0
- package/dist/platform-plans-config-CkbUKFpm.mjs +447 -0
- package/dist/platform-recovery-Cghx7FCR.mjs +96 -0
- package/dist/platform-registry-x1m9HBxf.mjs +450 -0
- package/dist/platform-runtime-logs-kkoiYFpF.mjs +72 -0
- package/dist/platform-setup-SfwCwnZg.mjs +306 -0
- package/dist/prepare-B9mB47T5.mjs +84 -0
- package/dist/prepare-DNIq07so.mjs +13 -0
- package/dist/prepare-LHkyJqxi.mjs +1 -0
- package/dist/project-CC7eN00D.mjs +141 -0
- package/dist/project-DcSd4BeI.mjs +1 -0
- package/dist/project-cmd-DTF19-fC.mjs +109 -0
- package/dist/project-paths-iXHKRTTQ.mjs +159 -0
- package/dist/project-slug-BUy0lmyR.mjs +1 -0
- package/dist/project-slug-CO6ci9XG.mjs +7 -0
- package/dist/project-team-CvdLhDF2.mjs +129 -0
- package/dist/project-token-CwZdUEGu.mjs +70 -0
- package/dist/project-tsconfig-P9X952KG.mjs +98 -0
- package/dist/project-zero-trust-CKDoPdN1.mjs +64 -0
- package/dist/providers-Cd3c7wi0.mjs +64 -0
- package/dist/providers-Df69hb_X.d.mts +5 -0
- package/dist/provision-DGlFJ3T9.mjs +1 -0
- package/dist/provision-mYVLuQiy.mjs +1814 -0
- package/dist/queues-Bc3FsBQT.d.mts +5 -0
- package/dist/r2-conditions-DSLmkiR5.mjs +60 -0
- package/dist/requests-DNhfyF3l.mjs +52 -0
- package/dist/resolve-project-BCsAMDRA.mjs +47 -0
- package/dist/resolve-project-DhU9_lIo.mjs +1 -0
- package/dist/resource-name-DlJ9QXzg.mjs +10 -0
- package/dist/response-HmNjB30w.mjs +29 -0
- package/dist/rollback-BvCHol52.mjs +150 -0
- package/dist/rolldown-runtime-uD8oG6U2.mjs +24 -0
- package/dist/route-types-CRWhr93D.mjs +592 -0
- package/dist/route-url-BIDZT78M.mjs +58 -0
- package/dist/route-url-Bla3Upsy.d.mts +42 -0
- package/dist/routes-stub.d.mts +24 -0
- package/dist/routes-stub.mjs +1 -0
- package/dist/routing-assets-CSheDWWM.mjs +54 -0
- package/dist/rpc-DcByS_q0.d.mts +39 -0
- package/dist/rpc-DtxIN9Tv.mjs +19 -0
- package/dist/runner-CPerdjIl.mjs +163 -0
- package/dist/runner-CUNtS5x7.mjs +1 -0
- package/dist/runner-mysql-7aA5hGoM.mjs +145 -0
- package/dist/runner-mysql-DrMKw203.mjs +1 -0
- package/dist/runner-pg-2pjltt0t.mjs +1 -0
- package/dist/runner-pg-mYc75KfH.mjs +61 -0
- package/dist/runtime/ai.d.mts +50 -0
- package/dist/runtime/ai.mjs +455 -0
- package/dist/runtime/auth-client-react.d.mts +2 -0
- package/dist/runtime/auth-client-react.mjs +1 -0
- package/dist/runtime/auth-client.d.mts +2 -0
- package/dist/runtime/auth-client.mjs +1 -0
- package/dist/runtime/auth.d.mts +2 -0
- package/dist/runtime/auth.mjs +1 -0
- package/dist/runtime/better-auth-mysql.d.mts +5 -0
- package/dist/runtime/better-auth-mysql.mjs +21 -0
- package/dist/runtime/better-auth-pg.d.mts +5 -0
- package/dist/runtime/better-auth-pg.mjs +21 -0
- package/dist/runtime/better-auth.d.mts +6 -0
- package/dist/runtime/better-auth.mjs +22 -0
- package/dist/runtime/client-react.d.mts +5 -0
- package/dist/runtime/client-react.mjs +5 -0
- package/dist/runtime/client.d.mts +5 -0
- package/dist/runtime/client.mjs +5 -0
- package/dist/runtime/db-mysql.d.mts +2 -0
- package/dist/runtime/db-mysql.mjs +1 -0
- package/dist/runtime/db-pg.d.mts +2 -0
- package/dist/runtime/db-pg.mjs +1 -0
- package/dist/runtime/db.d.mts +17 -0
- package/dist/runtime/db.mjs +36 -0
- package/dist/runtime/drizzle-arktype.d.mts +1 -0
- package/dist/runtime/drizzle-arktype.mjs +2 -0
- package/dist/runtime/drizzle-valibot.d.mts +1 -0
- package/dist/runtime/drizzle-valibot.mjs +2 -0
- package/dist/runtime/drizzle-zod.d.mts +1 -0
- package/dist/runtime/drizzle-zod.mjs +2 -0
- package/dist/runtime/durable.d.mts +64 -0
- package/dist/runtime/durable.mjs +165 -0
- package/dist/runtime/email/testing.d.mts +108 -0
- package/dist/runtime/email/testing.mjs +268 -0
- package/dist/runtime/email-protocol.d.mts +25 -0
- package/dist/runtime/email-protocol.mjs +1 -0
- package/dist/runtime/email.d.mts +26 -0
- package/dist/runtime/email.mjs +524 -0
- package/dist/runtime/env-public-client.d.mts +19 -0
- package/dist/runtime/env-public-client.mjs +55 -0
- package/dist/runtime/env-public.d.mts +4 -0
- package/dist/runtime/env-public.mjs +277 -0
- package/dist/runtime/env.d.mts +12 -0
- package/dist/runtime/env.mjs +1 -0
- package/dist/runtime/fetch-server.d.mts +6 -0
- package/dist/runtime/fetch-server.mjs +29 -0
- package/dist/runtime/fetch-stream.d.mts +3 -0
- package/dist/runtime/fetch-stream.mjs +3 -0
- package/dist/runtime/fetch.d.mts +2 -0
- package/dist/runtime/fetch.mjs +3 -0
- package/dist/runtime/handler.d.mts +3 -0
- package/dist/runtime/handler.mjs +1 -0
- package/dist/runtime/kv.d.mts +45 -0
- package/dist/runtime/kv.mjs +103 -0
- package/dist/runtime/limits.d.mts +2 -0
- package/dist/runtime/limits.mjs +1 -0
- package/dist/runtime/live-client.d.mts +40 -0
- package/dist/runtime/live-client.mjs +282 -0
- package/dist/runtime/live-server.d.mts +11 -0
- package/dist/runtime/live-server.mjs +419 -0
- package/dist/runtime/live.d.mts +3 -0
- package/dist/runtime/live.mjs +1 -0
- package/dist/runtime/log.d.mts +24 -0
- package/dist/runtime/log.mjs +57 -0
- package/dist/runtime/migration-handler-mysql.d.mts +2 -0
- package/dist/runtime/migration-handler-mysql.mjs +111 -0
- package/dist/runtime/migration-handler-pg.d.mts +2 -0
- package/dist/runtime/migration-handler-pg.mjs +94 -0
- package/dist/runtime/migration-handler.d.mts +2 -0
- package/dist/runtime/migration-handler.mjs +1 -0
- package/dist/runtime/procedure.d.mts +27 -0
- package/dist/runtime/procedure.mjs +36 -0
- package/dist/runtime/procedures.d.mts +24 -0
- package/dist/runtime/procedures.mjs +56 -0
- package/dist/runtime/queues.d.mts +2 -0
- package/dist/runtime/queues.mjs +8 -0
- package/dist/runtime/remote/binding-handler.d.mts +11 -0
- package/dist/runtime/remote/binding-handler.mjs +227 -0
- package/dist/runtime/remote/index.d.mts +12 -0
- package/dist/runtime/remote/index.mjs +467 -0
- package/dist/runtime/response.d.mts +11 -0
- package/dist/runtime/response.mjs +1 -0
- package/dist/runtime/route-url.d.mts +2 -0
- package/dist/runtime/route-url.mjs +1 -0
- package/dist/runtime/routing.d.mts +53 -0
- package/dist/runtime/routing.mjs +425 -0
- package/dist/runtime/rpc-react.d.mts +16 -0
- package/dist/runtime/rpc-react.mjs +50 -0
- package/dist/runtime/rpc.d.mts +2 -0
- package/dist/runtime/rpc.mjs +1 -0
- package/dist/runtime/sandbox-container.d.mts +3 -0
- package/dist/runtime/sandbox-container.mjs +1 -0
- package/dist/runtime/sandbox.d.mts +5 -0
- package/dist/runtime/sandbox.mjs +196 -0
- package/dist/runtime/schema-d1.d.mts +1 -0
- package/dist/runtime/schema-d1.mjs +2 -0
- package/dist/runtime/schema-mysql.d.mts +1 -0
- package/dist/runtime/schema-mysql.mjs +2 -0
- package/dist/runtime/schema-pg.d.mts +1 -0
- package/dist/runtime/schema-pg.mjs +2 -0
- package/dist/runtime/seed.d.mts +34 -0
- package/dist/runtime/seed.mjs +5 -0
- package/dist/runtime/sse-client.d.mts +31 -0
- package/dist/runtime/sse-client.mjs +42 -0
- package/dist/runtime/sse.d.mts +32 -0
- package/dist/runtime/sse.mjs +1 -0
- package/dist/runtime/storage.d.mts +4 -0
- package/dist/runtime/storage.mjs +13 -0
- package/dist/runtime/validator.d.mts +2 -0
- package/dist/runtime/validator.mjs +1 -0
- package/dist/runtime/ws-server.d.mts +26 -0
- package/dist/runtime/ws-server.mjs +297 -0
- package/dist/runtime/ws.d.mts +2 -0
- package/dist/runtime/ws.mjs +108 -0
- package/dist/sandbox-CWDjoEG2.d.mts +50 -0
- package/dist/sandbox-container-BqamdFCx.d.mts +73 -0
- package/dist/sandbox-container-d1AHLpgn.mjs +291 -0
- package/dist/secret-DCF9RXTc.mjs +146 -0
- package/dist/skills-Dr3AjuBF.mjs +63 -0
- package/dist/sqlite-validation-CLJXXN93.mjs +24 -0
- package/dist/sse-CxR30yMF.mjs +174 -0
- package/dist/standard-schema-CuDawHOC.d.mts +40 -0
- package/dist/static-asset-marker-mWMX2dLa.mjs +38 -0
- package/dist/subcommand-prompt-B9yUo--u.mjs +370 -0
- package/dist/terminal-log-text-DNsWJREL.mjs +31 -0
- package/dist/types-D7-4tBu7.d.mts +1 -0
- package/dist/untrusted-env-lL7RkYiC.mjs +50 -0
- package/dist/validate-B-zsjhiz.mjs +162 -0
- package/dist/validate-DbqGdPPY.mjs +1 -0
- package/dist/validator-8-NZs2Xr.mjs +168 -0
- package/dist/version-metadata-DsSoNsKJ.mjs +23 -0
- package/dist/wrangler-DU784Dkf.mjs +1452 -0
- package/dist/wrangler-Rr9_76DQ.mjs +1 -0
- package/dist/ws-Q_osq9VK.d.mts +137 -0
- package/dist/yarn-pnp-DgWbE7z5.mjs +91 -0
- package/docs/guide/ai.md +273 -0
- package/docs/guide/app-types.md +101 -0
- package/docs/guide/auth.md +255 -0
- package/docs/guide/database/d1.md +86 -0
- package/docs/guide/database/mysql.md +72 -0
- package/docs/guide/database/postgresql.md +94 -0
- package/docs/guide/database.md +454 -0
- package/docs/guide/deployment.md +124 -0
- package/docs/guide/durable-state.md +192 -0
- package/docs/guide/edge/headers.md +47 -0
- package/docs/guide/edge/redirects.md +85 -0
- package/docs/guide/edge/rewrites.md +119 -0
- package/docs/guide/edge/static-assets.md +94 -0
- package/docs/guide/email/domains.md +119 -0
- package/docs/guide/email/receiving.md +142 -0
- package/docs/guide/email/sending.md +262 -0
- package/docs/guide/email.md +23 -0
- package/docs/guide/env-vars.md +115 -0
- package/docs/guide/index.md +37 -0
- package/docs/guide/jobs.md +80 -0
- package/docs/guide/kv.md +100 -0
- package/docs/guide/live.md +181 -0
- package/docs/guide/platform/administration/access.md +165 -0
- package/docs/guide/platform/administration/connected-apps.md +84 -0
- package/docs/guide/platform/administration/email.md +169 -0
- package/docs/guide/platform/administration/operations.md +100 -0
- package/docs/guide/platform/administration/plans.md +156 -0
- package/docs/guide/platform/administration/projects.md +74 -0
- package/docs/guide/platform/administration/zero-trust.md +205 -0
- package/docs/guide/platform/development/local.md +122 -0
- package/docs/guide/platform/development/runtime.md +115 -0
- package/docs/guide/platform/development/schema-ci.md +44 -0
- package/docs/guide/platform/installation/ci.md +62 -0
- package/docs/guide/platform/installation/credentials.md +140 -0
- package/docs/guide/platform/installation/domains.md +120 -0
- package/docs/guide/platform/installation/first-deployment.md +95 -0
- package/docs/guide/platform/installation/maintenance.md +250 -0
- package/docs/guide/platform/installation/prerequisites.md +176 -0
- package/docs/guide/platform/installation/setup.md +300 -0
- package/docs/guide/platform/installation/uninstall.md +110 -0
- package/docs/guide/platform-administration.md +19 -0
- package/docs/guide/platform-development.md +16 -0
- package/docs/guide/procedures.md +48 -0
- package/docs/guide/project-collaboration.md +99 -0
- package/docs/guide/queues.md +149 -0
- package/docs/guide/quickstart.md +129 -0
- package/docs/guide/remote-dev.md +67 -0
- package/docs/guide/sandboxes.md +134 -0
- package/docs/guide/self-hosted-platform.md +45 -0
- package/docs/guide/server-routing.md +283 -0
- package/docs/guide/sse.md +174 -0
- package/docs/guide/storage.md +82 -0
- package/docs/guide/testing.md +64 -0
- package/docs/guide/type-safety.md +270 -0
- package/docs/guide/typed-fetch.md +98 -0
- package/docs/guide/websockets.md +230 -0
- package/docs/index.md +102 -0
- package/docs/integrations/agents.md +38 -0
- package/docs/integrations/cloudflare.md +241 -0
- package/docs/integrations/hono.md +127 -0
- package/docs/reference/api/auth.md +195 -0
- package/docs/reference/api/client.md +90 -0
- package/docs/reference/api/database.md +118 -0
- package/docs/reference/api/deploy.md +63 -0
- package/docs/reference/api/durable.md +47 -0
- package/docs/reference/api/env.md +51 -0
- package/docs/reference/api/handlers.md +189 -0
- package/docs/reference/api/plugin.md +40 -0
- package/docs/reference/api/resources.md +116 -0
- package/docs/reference/api/rewrites.md +111 -0
- package/docs/reference/api/types.md +126 -0
- package/docs/reference/api.md +71 -0
- package/docs/reference/cli/auth.md +87 -0
- package/docs/reference/cli/database.md +159 -0
- package/docs/reference/cli/deploy.md +117 -0
- package/docs/reference/cli/domains.md +42 -0
- package/docs/reference/cli/email.md +145 -0
- package/docs/reference/cli/generate.md +113 -0
- package/docs/reference/cli/github.md +181 -0
- package/docs/reference/cli/platform-config.md +93 -0
- package/docs/reference/cli/platform-email.md +81 -0
- package/docs/reference/cli/platform-installation.md +166 -0
- package/docs/reference/cli/platform-operations.md +90 -0
- package/docs/reference/cli/platform-users.md +159 -0
- package/docs/reference/cli/platform-zero-trust.md +60 -0
- package/docs/reference/cli/platform.md +78 -0
- package/docs/reference/cli/project.md +208 -0
- package/docs/reference/cli/secrets.md +79 -0
- package/docs/reference/cli/setup.md +88 -0
- package/docs/reference/cli.md +115 -0
- package/docs/reference/config.md +478 -0
- package/docs/reference/resource-inference.md +72 -0
- package/docs/reference/structure.md +138 -0
- package/package.json +389 -3
- package/sandbox.Dockerfile +4 -0
- package/schema.json +353 -0
- package/skills/bwf/SKILL.md +100 -0
- package/skills/migrate-vite-cloudflare-to-bwf/SKILL.md +53 -0
- package/templates/assets/bwf.svg +5 -0
- package/templates/assets/icons.svg +49 -0
- package/templates/assets/react.svg +1 -0
- package/templates/assets/stack.svg +35 -0
|
@@ -0,0 +1,1498 @@
|
|
|
1
|
+
import { r as findBwfAuthConfig } from "./config-CN_RFRkS.mjs";
|
|
2
|
+
import { l as getDatabaseDialect, p as resolveBindingNames } from "./config-tNx0HlFv.mjs";
|
|
3
|
+
import { a as join, i as isAbsolute, l as toSlash, s as relative, t as basename } from "./dist-DMYe8CZJ.mjs";
|
|
4
|
+
import { a as globSync, i as scanEmailHandlersSync } from "./email-C_ATvNIG.mjs";
|
|
5
|
+
import { n as resourceNameWords, t as isResourceName } from "./resource-name-DlJ9QXzg.mjs";
|
|
6
|
+
import { t as collectMigrations } from "./collect-C6Blu9yw.mjs";
|
|
7
|
+
import { n as readProjectPaths, r as resolveProjectPaths } from "./project-paths-iXHKRTTQ.mjs";
|
|
8
|
+
import { r as bwfWarn } from "./log-JDnPc0cF.mjs";
|
|
9
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
10
|
+
import { parseSync } from "vite";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { isSandboxRegistryImage } from "@builtbyfriends/deploy-core";
|
|
13
|
+
// src/application-features.ts
|
|
14
|
+
/** Apply explicitly named overrides while preserving unrelated source features. */
|
|
15
|
+
function applyBindingOverrides(inferred, overrides) {
|
|
16
|
+
const bindings = { ...inferred };
|
|
17
|
+
if (overrides) for (const [key, inferredKey] of Object.entries({
|
|
18
|
+
db: "needsD1",
|
|
19
|
+
kv: "needsKV",
|
|
20
|
+
storage: "needsR2",
|
|
21
|
+
ai: "needsAI",
|
|
22
|
+
email: "needsEmail"
|
|
23
|
+
})) {
|
|
24
|
+
const value = overrides[key];
|
|
25
|
+
if (value !== void 0) bindings[inferredKey] = Boolean(value);
|
|
26
|
+
}
|
|
27
|
+
return bindings;
|
|
28
|
+
}
|
|
29
|
+
/** Shared database requirement for development and both deployment targets. */
|
|
30
|
+
function needsApplicationDatabase(bindings, migrationCount) {
|
|
31
|
+
return bindings.needsD1 || bindings.needsAuth || migrationCount > 0;
|
|
32
|
+
}
|
|
33
|
+
// src/shared/route-extensions.ts
|
|
34
|
+
const ROUTE_EXTENSIONS = [
|
|
35
|
+
"ts",
|
|
36
|
+
"tsx",
|
|
37
|
+
"js",
|
|
38
|
+
"jsx",
|
|
39
|
+
"mjs",
|
|
40
|
+
"mts"
|
|
41
|
+
];
|
|
42
|
+
new Set(ROUTE_EXTENSIONS.map((ext) => `.${ext}`));
|
|
43
|
+
// src/shared/convention-files.ts
|
|
44
|
+
const WELL_KNOWN_DIR = ".well-known";
|
|
45
|
+
/** Include the convention directory's .well-known files when it is inside the scan directory. */
|
|
46
|
+
function conventionFileGlobs(scanDir, pattern, conventionDir = scanDir) {
|
|
47
|
+
const patterns = [pattern];
|
|
48
|
+
const conventionRelative = relative(scanDir, conventionDir);
|
|
49
|
+
if (conventionRelative !== ".." && !conventionRelative.startsWith("../")) patterns.push(join(conventionRelative, WELL_KNOWN_DIR, pattern));
|
|
50
|
+
return patterns;
|
|
51
|
+
}
|
|
52
|
+
function isConventionPath(filePath) {
|
|
53
|
+
return filePath.replace(/\\/g, "/").split("/").every((segment, index) => !segment.startsWith("_") && (!segment.startsWith(".") || index === 0 && segment === WELL_KNOWN_DIR));
|
|
54
|
+
}
|
|
55
|
+
/** Whether a path relative to routes/ participates in HTTP or WebSocket routing. */
|
|
56
|
+
function isRouteFile(filePath) {
|
|
57
|
+
return isConventionPath(filePath) && ROUTE_EXTENSIONS.some((ext) => filePath.endsWith(`.${ext}`));
|
|
58
|
+
}
|
|
59
|
+
/** Handler files under `dir`, relative to it, skipping paths with a `_`-prefixed segment. */
|
|
60
|
+
function listFilesWithExtensions(dir, extensions) {
|
|
61
|
+
const suffix = `*.{${extensions.join(",")}}`;
|
|
62
|
+
return globSync(conventionFileGlobs(dir, `**/${suffix}`), { cwd: dir }).filter(isConventionPath);
|
|
63
|
+
}
|
|
64
|
+
/** Cron and queue handlers with .ts, .mts, .js, or .mjs extensions. */
|
|
65
|
+
function listConventionFiles(dir) {
|
|
66
|
+
return listFilesWithExtensions(dir, [
|
|
67
|
+
"ts",
|
|
68
|
+
"mts",
|
|
69
|
+
"js",
|
|
70
|
+
"mjs"
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
/** HTTP and WebSocket handlers, also allowing .tsx and .jsx for JSX. */
|
|
74
|
+
function listRouteFiles(dir) {
|
|
75
|
+
return listFilesWithExtensions(dir, ROUTE_EXTENSIONS);
|
|
76
|
+
}
|
|
77
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
78
|
+
/**
|
|
79
|
+
* @typedef { import('estree').Node} Node
|
|
80
|
+
* @typedef {{
|
|
81
|
+
* skip: () => void;
|
|
82
|
+
* remove: () => void;
|
|
83
|
+
* replace: (node: Node) => void;
|
|
84
|
+
* }} WalkerContext
|
|
85
|
+
*/
|
|
86
|
+
var WalkerBase = class {
|
|
87
|
+
constructor() {
|
|
88
|
+
/** @type {boolean} */
|
|
89
|
+
this.should_skip = false;
|
|
90
|
+
/** @type {boolean} */
|
|
91
|
+
this.should_remove = false;
|
|
92
|
+
/** @type {Node | null} */
|
|
93
|
+
this.replacement = null;
|
|
94
|
+
/** @type {WalkerContext} */
|
|
95
|
+
this.context = {
|
|
96
|
+
skip: () => this.should_skip = true,
|
|
97
|
+
remove: () => this.should_remove = true,
|
|
98
|
+
replace: (node) => this.replacement = node
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @template {Node} Parent
|
|
103
|
+
* @param {Parent | null | undefined} parent
|
|
104
|
+
* @param {keyof Parent | null | undefined} prop
|
|
105
|
+
* @param {number | null | undefined} index
|
|
106
|
+
* @param {Node} node
|
|
107
|
+
*/
|
|
108
|
+
replace(parent, prop, index, node) {
|
|
109
|
+
if (parent && prop) {
|
|
110
|
+
if (index != null)
|
|
111
|
+
/** @type {Array<Node>} */ parent[prop][index] = node;
|
|
112
|
+
else
|
|
113
|
+
/** @type {Node} */ parent[prop] = node;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @template {Node} Parent
|
|
118
|
+
* @param {Parent | null | undefined} parent
|
|
119
|
+
* @param {keyof Parent | null | undefined} prop
|
|
120
|
+
* @param {number | null | undefined} index
|
|
121
|
+
*/
|
|
122
|
+
remove(parent, prop, index) {
|
|
123
|
+
if (parent && prop) {
|
|
124
|
+
if (index !== null && index !== void 0)
|
|
125
|
+
/** @type {Array<Node>} */ parent[prop].splice(index, 1);
|
|
126
|
+
else delete parent[prop];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
131
|
+
/**
|
|
132
|
+
* @typedef { import('estree').Node} Node
|
|
133
|
+
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
|
134
|
+
* @typedef {(
|
|
135
|
+
* this: WalkerContext,
|
|
136
|
+
* node: Node,
|
|
137
|
+
* parent: Node | null,
|
|
138
|
+
* key: string | number | symbol | null | undefined,
|
|
139
|
+
* index: number | null | undefined
|
|
140
|
+
* ) => void} SyncHandler
|
|
141
|
+
*/
|
|
142
|
+
var SyncWalker = class extends WalkerBase {
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
* @param {SyncHandler} [enter]
|
|
146
|
+
* @param {SyncHandler} [leave]
|
|
147
|
+
*/
|
|
148
|
+
constructor(enter, leave) {
|
|
149
|
+
super();
|
|
150
|
+
/** @type {boolean} */
|
|
151
|
+
this.should_skip = false;
|
|
152
|
+
/** @type {boolean} */
|
|
153
|
+
this.should_remove = false;
|
|
154
|
+
/** @type {Node | null} */
|
|
155
|
+
this.replacement = null;
|
|
156
|
+
/** @type {WalkerContext} */
|
|
157
|
+
this.context = {
|
|
158
|
+
skip: () => this.should_skip = true,
|
|
159
|
+
remove: () => this.should_remove = true,
|
|
160
|
+
replace: (node) => this.replacement = node
|
|
161
|
+
};
|
|
162
|
+
/** @type {SyncHandler | undefined} */
|
|
163
|
+
this.enter = enter;
|
|
164
|
+
/** @type {SyncHandler | undefined} */
|
|
165
|
+
this.leave = leave;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @template {Node} Parent
|
|
169
|
+
* @param {Node} node
|
|
170
|
+
* @param {Parent | null} parent
|
|
171
|
+
* @param {keyof Parent} [prop]
|
|
172
|
+
* @param {number | null} [index]
|
|
173
|
+
* @returns {Node | null}
|
|
174
|
+
*/
|
|
175
|
+
visit(node, parent, prop, index) {
|
|
176
|
+
if (node) {
|
|
177
|
+
if (this.enter) {
|
|
178
|
+
const _should_skip = this.should_skip;
|
|
179
|
+
const _should_remove = this.should_remove;
|
|
180
|
+
const _replacement = this.replacement;
|
|
181
|
+
this.should_skip = false;
|
|
182
|
+
this.should_remove = false;
|
|
183
|
+
this.replacement = null;
|
|
184
|
+
this.enter.call(this.context, node, parent, prop, index);
|
|
185
|
+
if (this.replacement) {
|
|
186
|
+
node = this.replacement;
|
|
187
|
+
this.replace(parent, prop, index, node);
|
|
188
|
+
}
|
|
189
|
+
if (this.should_remove) this.remove(parent, prop, index);
|
|
190
|
+
const skipped = this.should_skip;
|
|
191
|
+
const removed = this.should_remove;
|
|
192
|
+
this.should_skip = _should_skip;
|
|
193
|
+
this.should_remove = _should_remove;
|
|
194
|
+
this.replacement = _replacement;
|
|
195
|
+
if (skipped) return node;
|
|
196
|
+
if (removed) return null;
|
|
197
|
+
}
|
|
198
|
+
/** @type {keyof Node} */
|
|
199
|
+
let key;
|
|
200
|
+
for (key in node) {
|
|
201
|
+
/** @type {unknown} */
|
|
202
|
+
const value = node[key];
|
|
203
|
+
if (value && typeof value === "object") {
|
|
204
|
+
if (Array.isArray(value)) {
|
|
205
|
+
const nodes = value;
|
|
206
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
207
|
+
const item = nodes[i];
|
|
208
|
+
if (isNode(item)) {
|
|
209
|
+
if (!this.visit(item, node, key, i)) i--;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} else if (isNode(value)) this.visit(value, node, key, null);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (this.leave) {
|
|
216
|
+
const _replacement = this.replacement;
|
|
217
|
+
const _should_remove = this.should_remove;
|
|
218
|
+
this.replacement = null;
|
|
219
|
+
this.should_remove = false;
|
|
220
|
+
this.leave.call(this.context, node, parent, prop, index);
|
|
221
|
+
if (this.replacement) {
|
|
222
|
+
node = this.replacement;
|
|
223
|
+
this.replace(parent, prop, index, node);
|
|
224
|
+
}
|
|
225
|
+
if (this.should_remove) this.remove(parent, prop, index);
|
|
226
|
+
const removed = this.should_remove;
|
|
227
|
+
this.replacement = _replacement;
|
|
228
|
+
this.should_remove = _should_remove;
|
|
229
|
+
if (removed) return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return node;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Ducktype a node.
|
|
237
|
+
*
|
|
238
|
+
* @param {unknown} value
|
|
239
|
+
* @returns {value is Node}
|
|
240
|
+
*/
|
|
241
|
+
function isNode(value) {
|
|
242
|
+
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
243
|
+
}
|
|
244
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
245
|
+
/**
|
|
246
|
+
* @typedef {import('estree').Node} Node
|
|
247
|
+
* @typedef {import('./sync.js').SyncHandler} SyncHandler
|
|
248
|
+
* @typedef {import('./async.js').AsyncHandler} AsyncHandler
|
|
249
|
+
*/
|
|
250
|
+
/**
|
|
251
|
+
* @param {Node} ast
|
|
252
|
+
* @param {{
|
|
253
|
+
* enter?: SyncHandler
|
|
254
|
+
* leave?: SyncHandler
|
|
255
|
+
* }} walker
|
|
256
|
+
* @returns {Node | null}
|
|
257
|
+
*/
|
|
258
|
+
function walk(ast, { enter, leave }) {
|
|
259
|
+
return new SyncWalker(enter, leave).visit(ast, null);
|
|
260
|
+
}
|
|
261
|
+
// src/shared/ast.ts
|
|
262
|
+
function isIdentifier(node) {
|
|
263
|
+
return node?.type === "Identifier" && typeof node.name === "string";
|
|
264
|
+
}
|
|
265
|
+
function isLiteral(node) {
|
|
266
|
+
return node?.type === "Literal";
|
|
267
|
+
}
|
|
268
|
+
/** Module export names may be identifiers or string literals, independently of the local name. */
|
|
269
|
+
function moduleExportName(node) {
|
|
270
|
+
if (isIdentifier(node)) return node.name;
|
|
271
|
+
return isLiteral(node) && typeof node.value === "string" ? node.value : void 0;
|
|
272
|
+
}
|
|
273
|
+
function isMemberExpression(node) {
|
|
274
|
+
return node?.type === "MemberExpression";
|
|
275
|
+
}
|
|
276
|
+
function isCallExpression(node) {
|
|
277
|
+
return node?.type === "CallExpression";
|
|
278
|
+
}
|
|
279
|
+
function isObjectExpression(node) {
|
|
280
|
+
return node?.type === "ObjectExpression";
|
|
281
|
+
}
|
|
282
|
+
// src/shared/ast-bindings.ts
|
|
283
|
+
/** Names introduced by a binding pattern, excluding keys and default expressions. */
|
|
284
|
+
function bindingNames(node) {
|
|
285
|
+
if (isIdentifier(node)) return [node.name];
|
|
286
|
+
if (node?.type === "ObjectPattern") return (node.properties ?? []).flatMap((property) => bindingNames(property.type === "RestElement" ? property.argument : property.value));
|
|
287
|
+
if (node?.type === "ArrayPattern") return (node.elements ?? []).flatMap(bindingNames);
|
|
288
|
+
if (node?.type === "AssignmentPattern" || node?.type === "RestElement") return bindingNames(node.left ?? node.argument);
|
|
289
|
+
if (node?.type === "TSParameterProperty") return bindingNames(node.parameter);
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
const FUNCTIONS = /* @__PURE__ */ new Set([
|
|
293
|
+
"FunctionDeclaration",
|
|
294
|
+
"FunctionExpression",
|
|
295
|
+
"ArrowFunctionExpression"
|
|
296
|
+
]);
|
|
297
|
+
/**
|
|
298
|
+
* Resolve lexical bindings after collecting declarations, including hoisted and later bindings.
|
|
299
|
+
* A visitor can collect references in the same pass; return true to retain a node's scope.
|
|
300
|
+
* Names can limit binding collection when only specific imports need resolution.
|
|
301
|
+
*/
|
|
302
|
+
function bindingResolver(program, options) {
|
|
303
|
+
const scopes = /* @__PURE__ */ new WeakMap();
|
|
304
|
+
const outerScopes = /* @__PURE__ */ new WeakMap();
|
|
305
|
+
let scope = { varScope: true };
|
|
306
|
+
const declare = (pattern, declaration, target = scope) => {
|
|
307
|
+
for (const name of bindingNames(pattern)) if (!options?.names || options.names.has(name)) (target.bindings ??= /* @__PURE__ */ new Map()).set(name, declaration);
|
|
308
|
+
};
|
|
309
|
+
walk(program, {
|
|
310
|
+
enter(raw, rawParent, key) {
|
|
311
|
+
const node = raw;
|
|
312
|
+
const parent = rawParent;
|
|
313
|
+
const outerScope = scope;
|
|
314
|
+
if (parent?.type === "SwitchStatement" && key === "discriminant") scope = scope.parent;
|
|
315
|
+
if ([
|
|
316
|
+
"FunctionDeclaration",
|
|
317
|
+
"ClassDeclaration",
|
|
318
|
+
"TSEnumDeclaration",
|
|
319
|
+
"TSModuleDeclaration"
|
|
320
|
+
].includes(node.type)) declare(node.id, node);
|
|
321
|
+
const isFunction = FUNCTIONS.has(node.type);
|
|
322
|
+
if (isFunction || node.type === "BlockStatement" || node.type === "StaticBlock" || node.type === "CatchClause" || node.type === "ForStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "SwitchStatement" || node.type === "ClassDeclaration" || node.type === "ClassExpression" || node.type === "TSModuleDeclaration") scope = {
|
|
323
|
+
parent: scope,
|
|
324
|
+
varScope: isFunction || node.type === "StaticBlock" || node.type === "TSModuleDeclaration" || node.type === "BlockStatement" && !!parent && FUNCTIONS.has(parent.type)
|
|
325
|
+
};
|
|
326
|
+
if (scope !== outerScope) outerScopes.set(node, outerScope);
|
|
327
|
+
if (!options?.visit || options.visit(node)) scopes.set(node, scope);
|
|
328
|
+
if (isFunction) {
|
|
329
|
+
if (node.type === "FunctionExpression") declare(node.id, node);
|
|
330
|
+
for (const parameter of node.params ?? []) declare(parameter, parameter);
|
|
331
|
+
} else if (node.type === "ClassDeclaration" || node.type === "ClassExpression") declare(node.id, node);
|
|
332
|
+
else if (node.type === "CatchClause") declare(node.param, node);
|
|
333
|
+
else if (node.type === "ImportDeclaration" && node.importKind !== "type") {
|
|
334
|
+
for (const specifier of node.specifiers ?? []) if (specifier.importKind !== "type") declare(specifier.local, specifier);
|
|
335
|
+
} else if (node.type === "VariableDeclaration") {
|
|
336
|
+
let target = scope;
|
|
337
|
+
if (node.kind === "var") while (!target.varScope && target.parent) target = target.parent;
|
|
338
|
+
for (const declaration of node.declarations ?? []) declare(declaration.id, declaration, target);
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
leave(raw) {
|
|
342
|
+
const outer = outerScopes.get(raw);
|
|
343
|
+
if (outer) scope = outer;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
return (node, name) => {
|
|
347
|
+
let current = scopes.get(node);
|
|
348
|
+
while (current) {
|
|
349
|
+
const binding = current.bindings?.get(name);
|
|
350
|
+
if (binding) return binding;
|
|
351
|
+
current = current.parent;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
// src/shared/static-exports.ts
|
|
356
|
+
const LINE_TERMINATORS = /* @__PURE__ */ new Set([
|
|
357
|
+
"\n",
|
|
358
|
+
"\r",
|
|
359
|
+
"\u2028",
|
|
360
|
+
"\u2029"
|
|
361
|
+
]);
|
|
362
|
+
/**
|
|
363
|
+
* Whether `export` is followed by `*` once whitespace and comments are skipped,
|
|
364
|
+
* so a comment between the two still counts. True only means the source needs
|
|
365
|
+
* parsing: the text may sit in a string or comment. This is a scan because a
|
|
366
|
+
* regular expression that skips repeated comments can backtrack exponentially.
|
|
367
|
+
*/
|
|
368
|
+
function mayExportAll(source) {
|
|
369
|
+
for (let index = source.indexOf("export"); index !== -1; index = source.indexOf("export", index + 1)) {
|
|
370
|
+
let cursor = index + 6;
|
|
371
|
+
while (cursor < source.length) if (/\s/.test(source[cursor])) cursor += 1;
|
|
372
|
+
else if (source.startsWith("/*", cursor)) {
|
|
373
|
+
const end = source.indexOf("*/", cursor + 2);
|
|
374
|
+
cursor = end === -1 ? source.length : end + 2;
|
|
375
|
+
} else if (source.startsWith("//", cursor)) {
|
|
376
|
+
cursor += 2;
|
|
377
|
+
while (cursor < source.length && !LINE_TERMINATORS.has(source[cursor])) cursor += 1;
|
|
378
|
+
} else break;
|
|
379
|
+
if (source[cursor] === "*") return true;
|
|
380
|
+
}
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
const VALUE_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
384
|
+
"FunctionDeclaration",
|
|
385
|
+
"ClassDeclaration",
|
|
386
|
+
"TSEnumDeclaration"
|
|
387
|
+
]);
|
|
388
|
+
/** Read how a parsed module exports `names` without evaluating user code. Type-only exports are skipped. */
|
|
389
|
+
function staticExports(program, names) {
|
|
390
|
+
const result = {
|
|
391
|
+
initializers: /* @__PURE__ */ new Map(),
|
|
392
|
+
unreadable: /* @__PURE__ */ new Set(),
|
|
393
|
+
exportsAll: false
|
|
394
|
+
};
|
|
395
|
+
const markUnreadable = (name) => {
|
|
396
|
+
if (name !== void 0 && names.has(name)) result.unreadable.add(name);
|
|
397
|
+
};
|
|
398
|
+
for (const statement of program.body ?? []) {
|
|
399
|
+
if (statement.type === "ExportAllDeclaration") {
|
|
400
|
+
const exported = statement;
|
|
401
|
+
if (exported.exportKind === "type") continue;
|
|
402
|
+
if (exported.exported) markUnreadable(moduleExportName(exported.exported));
|
|
403
|
+
else result.exportsAll = true;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
407
|
+
const exported = statement;
|
|
408
|
+
if (exported.exportKind === "type") continue;
|
|
409
|
+
for (const specifier of exported.specifiers ?? []) if (specifier.exportKind !== "type") markUnreadable(moduleExportName(specifier.exported));
|
|
410
|
+
const declaration = exported.declaration;
|
|
411
|
+
if (declaration?.type === "VariableDeclaration") {
|
|
412
|
+
const variables = declaration;
|
|
413
|
+
for (const variable of variables.declarations ?? []) {
|
|
414
|
+
if (variables.kind === "const" && isIdentifier(variable.id) && variable.init) {
|
|
415
|
+
if (names.has(variable.id.name)) result.initializers.set(variable.id.name, variable.init);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
for (const name of bindingNames(variable.id)) markUnreadable(name);
|
|
419
|
+
}
|
|
420
|
+
} else if (declaration && VALUE_DECLARATIONS.has(declaration.type)) {
|
|
421
|
+
const id = declaration.id;
|
|
422
|
+
markUnreadable(isIdentifier(id) ? id.name : void 0);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
/** Parse a module and read how it exports `names` without evaluating user code. */
|
|
428
|
+
function readStaticExports(filename, source, names) {
|
|
429
|
+
return staticExports(parseSync(filename, source).program, names);
|
|
430
|
+
}
|
|
431
|
+
function unwrapStaticExpression(node) {
|
|
432
|
+
while (node && [
|
|
433
|
+
"ParenthesizedExpression",
|
|
434
|
+
"TSAsExpression",
|
|
435
|
+
"TSSatisfiesExpression",
|
|
436
|
+
"TSTypeAssertion"
|
|
437
|
+
].includes(node.type)) node = node.expression;
|
|
438
|
+
return node;
|
|
439
|
+
}
|
|
440
|
+
function staticLiteral(node) {
|
|
441
|
+
node = unwrapStaticExpression(node);
|
|
442
|
+
if (node?.type === "Literal") return node.value;
|
|
443
|
+
if (node?.type === "TemplateLiteral") {
|
|
444
|
+
const expressions = node.expressions;
|
|
445
|
+
const quasis = node.quasis;
|
|
446
|
+
if (expressions?.length === 0 && quasis?.length === 1) return quasis[0]?.value?.cooked;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// src/crons/scan.ts
|
|
450
|
+
function extractJobName(filePath) {
|
|
451
|
+
return filePath.replace(/\.[^.]+$/, "");
|
|
452
|
+
}
|
|
453
|
+
function extractCronExpressions(source, filePath) {
|
|
454
|
+
const initializer = unwrapStaticExpression(readStaticExports(filePath, source, /* @__PURE__ */ new Set(["cron"])).initializers.get("cron"));
|
|
455
|
+
if (!initializer) throw new Error(`cron: Invalid job file '${filePath}'. Add \`export const cron = "<schedule>"\`.`);
|
|
456
|
+
const values = initializer.type === "ArrayExpression" ? initializer.elements ?? [] : [initializer];
|
|
457
|
+
if (values.length === 0) throw new Error(`cron: Invalid job file '${filePath}'. Cron array cannot be empty.`);
|
|
458
|
+
return values.map((value) => {
|
|
459
|
+
const cron = staticLiteral(value ?? void 0);
|
|
460
|
+
if (typeof cron !== "string" || !cron.trim()) throw new Error(`cron: Invalid job file '${filePath}'. Cron expression must be a nonempty string literal.`);
|
|
461
|
+
return cron.trim();
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function scanJobsSync(cronsDir) {
|
|
465
|
+
return listConventionFiles(cronsDir).sort((leftFilePath, rightFilePath) => leftFilePath.localeCompare(rightFilePath)).map((filePath) => {
|
|
466
|
+
const source = readFileSync(join(cronsDir, filePath), "utf-8");
|
|
467
|
+
return {
|
|
468
|
+
filePath,
|
|
469
|
+
name: extractJobName(filePath),
|
|
470
|
+
crons: extractCronExpressions(source, filePath)
|
|
471
|
+
};
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
// src/shared/resource-definition.ts
|
|
475
|
+
/** Inspect default helper definitions without running application code. */
|
|
476
|
+
function readResourceDefinition(filename, source, helpers) {
|
|
477
|
+
let program;
|
|
478
|
+
try {
|
|
479
|
+
program = parseSync(filename, source).program;
|
|
480
|
+
} catch {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
const constants = /* @__PURE__ */ new Map();
|
|
484
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
485
|
+
const importedHelpers = /* @__PURE__ */ new Map();
|
|
486
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
487
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
488
|
+
function recordBindings(node) {
|
|
489
|
+
if (isIdentifier(node)) bindings.add(node.name);
|
|
490
|
+
else if (node?.type === "ObjectPattern") for (const property of node.properties ?? []) recordBindings(property.type === "RestElement" ? property.argument : property.value);
|
|
491
|
+
else if (node?.type === "ArrayPattern") for (const element of node.elements ?? []) recordBindings(element);
|
|
492
|
+
else if (node?.type === "AssignmentPattern" || node?.type === "RestElement") recordBindings(node.left ?? node.argument);
|
|
493
|
+
}
|
|
494
|
+
for (const statement of program.body ?? []) {
|
|
495
|
+
if (statement.type === "ImportDeclaration") {
|
|
496
|
+
const declaration = statement;
|
|
497
|
+
const source = declaration.source.value;
|
|
498
|
+
const supported = source === "@builtbyfriends/bwf/ws" ? /* @__PURE__ */ new Set(["defineRoom", "defineWebSocket"]) : source === "@builtbyfriends/bwf/durable" ? /* @__PURE__ */ new Set(["defineDurableState", "defineDurableObject"]) : /* @__PURE__ */ new Set();
|
|
499
|
+
for (const specifier of declaration.specifiers ?? []) {
|
|
500
|
+
const local = specifier.local;
|
|
501
|
+
recordBindings(local);
|
|
502
|
+
if (specifier.type === "ImportNamespaceSpecifier") namespaces.set(specifier.local.name, supported);
|
|
503
|
+
else if (specifier.type === "ImportSpecifier") {
|
|
504
|
+
const named = specifier;
|
|
505
|
+
const imported = isIdentifier(named.imported) ? named.imported.name : staticLiteral(named.imported);
|
|
506
|
+
if (typeof imported === "string" && supported.has(imported) && helpers.has(imported)) importedHelpers.set(named.local.name, imported);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
512
|
+
recordBindings(declaration?.id);
|
|
513
|
+
if (declaration?.type !== "VariableDeclaration") continue;
|
|
514
|
+
for (const variable of declaration.declarations ?? []) {
|
|
515
|
+
recordBindings(variable.id);
|
|
516
|
+
if (isIdentifier(variable.id) && variable.init) {
|
|
517
|
+
definitions.set(variable.id.name, variable.init);
|
|
518
|
+
if (declaration.kind === "const") constants.set(variable.id.name, variable.init);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function resolve(node, seen = /* @__PURE__ */ new Set()) {
|
|
523
|
+
node = unwrapStaticExpression(node);
|
|
524
|
+
if (!isIdentifier(node) || !constants.has(node.name) || seen.has(node.name)) return node;
|
|
525
|
+
seen.add(node.name);
|
|
526
|
+
return resolve(constants.get(node.name), seen);
|
|
527
|
+
}
|
|
528
|
+
function isStaticUndefined(node) {
|
|
529
|
+
node = resolve(node);
|
|
530
|
+
return isIdentifier(node) && node.name === "undefined" && !bindings.has(node.name);
|
|
531
|
+
}
|
|
532
|
+
function readName(options, seen = /* @__PURE__ */ new Set()) {
|
|
533
|
+
options = resolve(options);
|
|
534
|
+
if (!isObjectExpression(options) || seen.has(options)) return { present: false };
|
|
535
|
+
seen.add(options);
|
|
536
|
+
let name = { present: false };
|
|
537
|
+
for (const property of options.properties ?? []) {
|
|
538
|
+
if (property.type === "SpreadElement") {
|
|
539
|
+
const spread = resolve(property.argument);
|
|
540
|
+
if (isObjectExpression(spread)) {
|
|
541
|
+
const spreadName = readName(spread, seen);
|
|
542
|
+
if (spreadName.present) name = spreadName;
|
|
543
|
+
} else if (name.value !== void 0) throw new Error(`${filename}: resource name cannot be overridden by a dynamic spread.`);
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
if (property.type !== "Property") continue;
|
|
547
|
+
const key = property.key;
|
|
548
|
+
const keyName = !property.computed && isIdentifier(key) ? key.name : staticLiteral(key);
|
|
549
|
+
if (keyName !== "name") {
|
|
550
|
+
if (property.computed && keyName === void 0 && name.value !== void 0) throw new Error(`${filename}: resource name cannot be overridden by a dynamic key.`);
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const valueNode = property.value;
|
|
554
|
+
if (isStaticUndefined(valueNode)) {
|
|
555
|
+
name = { present: true };
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const value = staticLiteral(resolve(valueNode));
|
|
559
|
+
if (!isResourceName(value)) throw new Error(`${filename}: resource name must be a static string containing a word starting with a letter.`);
|
|
560
|
+
name = {
|
|
561
|
+
present: true,
|
|
562
|
+
value
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
seen.delete(options);
|
|
566
|
+
return name;
|
|
567
|
+
}
|
|
568
|
+
const statement = program.body?.find((node) => node.type === "ExportDefaultDeclaration");
|
|
569
|
+
const declaration = unwrapStaticExpression(statement?.declaration);
|
|
570
|
+
const call = resolve(isIdentifier(declaration) ? definitions.get(declaration.name) : declaration);
|
|
571
|
+
if (!isCallExpression(call)) return null;
|
|
572
|
+
const callee = resolve(call.callee);
|
|
573
|
+
let helper;
|
|
574
|
+
if (isIdentifier(callee)) helper = importedHelpers.get(callee.name) ?? (helpers.has(callee.name) ? callee.name : void 0);
|
|
575
|
+
else if (isMemberExpression(callee) && isIdentifier(callee.object)) {
|
|
576
|
+
const property = !callee.computed && isIdentifier(callee.property) ? callee.property.name : staticLiteral(callee.property);
|
|
577
|
+
if (typeof property === "string" && helpers.has(property) && namespaces.get(callee.object.name)?.has(property)) helper = property;
|
|
578
|
+
}
|
|
579
|
+
if (!helper) return null;
|
|
580
|
+
const options = resolve(call.arguments?.[0]);
|
|
581
|
+
const name = readName(options).value;
|
|
582
|
+
return {
|
|
583
|
+
helper,
|
|
584
|
+
options,
|
|
585
|
+
...name === void 0 ? {} : { name }
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
// src/durable/scan.ts
|
|
589
|
+
const MODULE_PATTERN = /\.(?:[cm]?[jt]s)$/;
|
|
590
|
+
function inferDurableResourceName(filePath) {
|
|
591
|
+
return filePath.replace(/\\/g, "/").split("/").pop().replace(MODULE_PATTERN, "");
|
|
592
|
+
}
|
|
593
|
+
const DURABLE_HELPERS = /* @__PURE__ */ new Set(["defineDurableState", "defineDurableObject"]);
|
|
594
|
+
function deriveDurableResourceIdentity(name) {
|
|
595
|
+
const parts = resourceNameWords(name);
|
|
596
|
+
const classBase = parts.map((part) => part[0].toUpperCase() + part.slice(1)).join("");
|
|
597
|
+
return {
|
|
598
|
+
bindingName: parts.join("_").toUpperCase(),
|
|
599
|
+
className: `${classBase}DurableObject`,
|
|
600
|
+
migrationTag: `void-durable-${parts.join("-").toLowerCase()}-v1`
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function scanDurableObjectModules(root) {
|
|
604
|
+
const directory = join(root, "durable-objects");
|
|
605
|
+
if (!existsSync(directory)) return [];
|
|
606
|
+
const modules = readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && MODULE_PATTERN.test(entry.name) && !entry.name.endsWith(".d.ts")).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
607
|
+
const filePath = join(directory, entry.name);
|
|
608
|
+
const name = readResourceDefinition(filePath, readFileSync(filePath, "utf-8"), DURABLE_HELPERS)?.name;
|
|
609
|
+
const resourceName = name ?? inferDurableResourceName(entry.name);
|
|
610
|
+
if (resourceNameWords(resourceName).length === 0) throw new Error(`durable: cannot derive a name from durable-objects/${entry.name}.`);
|
|
611
|
+
return {
|
|
612
|
+
filePath,
|
|
613
|
+
...deriveDurableResourceIdentity(resourceName),
|
|
614
|
+
...name === void 0 ? {} : { name }
|
|
615
|
+
};
|
|
616
|
+
});
|
|
617
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
618
|
+
const classes = /* @__PURE__ */ new Set();
|
|
619
|
+
for (const module of modules) {
|
|
620
|
+
if (bindings.has(module.bindingName) || classes.has(module.className)) throw new Error(`durable: duplicate generated name for '${module.filePath}'. Choose a different resource name or rename one of the durable-objects files.`);
|
|
621
|
+
bindings.add(module.bindingName);
|
|
622
|
+
classes.add(module.className);
|
|
623
|
+
}
|
|
624
|
+
return modules;
|
|
625
|
+
}
|
|
626
|
+
// src/shared/module-references.ts
|
|
627
|
+
/** Runtime imports and re-exports, in source order, including empty export lists. */
|
|
628
|
+
function staticModuleReferences(parsed, code) {
|
|
629
|
+
const { staticImports, staticExports } = parsed.module;
|
|
630
|
+
if (!(/\bexport\s*(?:\/|\{\s*(?:\}|\/))/.test(code) || staticImports.some((item) => item.entries.length === 0 && code.slice(item.start, item.moduleRequest.start).trim() !== "import"))) return [...staticImports.filter((item) => item.entries.length === 0 || item.entries.some((entry) => !entry.isType)).map((item) => ({
|
|
631
|
+
source: item.moduleRequest.value,
|
|
632
|
+
start: item.start,
|
|
633
|
+
end: item.end
|
|
634
|
+
})), ...staticExports.flatMap((item) => {
|
|
635
|
+
const entry = item.entries.find((entry) => !entry.isType && entry.moduleRequest);
|
|
636
|
+
return entry?.moduleRequest ? [{
|
|
637
|
+
source: entry.moduleRequest.value,
|
|
638
|
+
start: item.start,
|
|
639
|
+
end: item.end
|
|
640
|
+
}] : [];
|
|
641
|
+
})].sort((a, b) => a.start - b.start);
|
|
642
|
+
return parsed.program.body.flatMap((statement) => {
|
|
643
|
+
if (statement.type !== "ImportDeclaration" && statement.type !== "ExportNamedDeclaration" && statement.type !== "ExportAllDeclaration") return [];
|
|
644
|
+
if (!statement.source || "importKind" in statement && statement.importKind === "type" || "exportKind" in statement && statement.exportKind === "type" || "specifiers" in statement && statement.specifiers.length > 0 && statement.specifiers.every((specifier) => "importKind" in specifier && specifier.importKind === "type" || "exportKind" in specifier && specifier.exportKind === "type")) return [];
|
|
645
|
+
return [{
|
|
646
|
+
source: statement.source.value,
|
|
647
|
+
start: statement.start,
|
|
648
|
+
end: statement.end
|
|
649
|
+
}];
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
// src/inference/client-auth.ts
|
|
653
|
+
const CLIENT_MODULES = /* @__PURE__ */ new Set(["@builtbyfriends/bwf/client", "@builtbyfriends/bwf/client/react"]);
|
|
654
|
+
function name(node) {
|
|
655
|
+
return isIdentifier(node) ? node.name : staticLiteral(node);
|
|
656
|
+
}
|
|
657
|
+
function propertyName(node) {
|
|
658
|
+
const key = node.property ?? node.key;
|
|
659
|
+
return node.computed ? staticLiteral(key) : name(key);
|
|
660
|
+
}
|
|
661
|
+
/** Detect runtime auth imports and namespace reads without confusing aliases or type names. */
|
|
662
|
+
function inferClientAuth(parsed, code) {
|
|
663
|
+
let hasNamespace = false;
|
|
664
|
+
for (const statement of parsed.module.staticImports) {
|
|
665
|
+
if (!CLIENT_MODULES.has(statement.moduleRequest.value)) continue;
|
|
666
|
+
for (const entry of statement.entries) if (!entry.isType) {
|
|
667
|
+
if (entry.importName.name === "auth") return true;
|
|
668
|
+
hasNamespace ||= entry.importName.kind === "NamespaceObject";
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
for (const statement of parsed.module.staticExports) for (const entry of statement.entries) if (!entry.isType && entry.moduleRequest && CLIENT_MODULES.has(entry.moduleRequest.value)) {
|
|
672
|
+
if (entry.importName.name === "auth" || entry.importName.kind === "All" || entry.importName.kind === "AllButDefault") return true;
|
|
673
|
+
}
|
|
674
|
+
if (!hasNamespace && parsed.module.dynamicImports.length === 0 || !/\bauth\b|\\(?:u|x|h|[0-7\r\n\u2028\u2029])/.test(code)) return false;
|
|
675
|
+
return inferNamespaceAuth(parsed.program);
|
|
676
|
+
}
|
|
677
|
+
function inferNamespaceAuth(program) {
|
|
678
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
679
|
+
for (const statement of program.body ?? []) {
|
|
680
|
+
const source = staticLiteral(statement.source);
|
|
681
|
+
if (typeof source !== "string" || !CLIENT_MODULES.has(source)) continue;
|
|
682
|
+
if (statement.importKind === "type" || statement.exportKind === "type") continue;
|
|
683
|
+
if (statement.type === "ExportAllDeclaration") return true;
|
|
684
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
685
|
+
if (specifier.importKind === "type" || specifier.exportKind === "type") continue;
|
|
686
|
+
if (statement.type === "ImportDeclaration") {
|
|
687
|
+
if (specifier.type === "ImportNamespaceSpecifier") namespaces.add(specifier);
|
|
688
|
+
else if (name(specifier.imported) === "auth") return true;
|
|
689
|
+
} else if (statement.type === "ExportNamedDeclaration" && name(specifier.local) === "auth") return true;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const reads = [];
|
|
693
|
+
const resolve = bindingResolver(program, { visit(node) {
|
|
694
|
+
if (isMemberExpression(node) && propertyName(node) === "auth") reads.push(node.object);
|
|
695
|
+
else if ([
|
|
696
|
+
"VariableDeclarator",
|
|
697
|
+
"AssignmentExpression",
|
|
698
|
+
"AssignmentPattern"
|
|
699
|
+
].includes(node.type)) {
|
|
700
|
+
const pattern = node.id ?? node.left;
|
|
701
|
+
const value = node.init ?? node.right;
|
|
702
|
+
if (pattern?.type === "ObjectPattern" && (pattern.properties ?? []).some((property) => property.type === "Property" && propertyName(property) === "auth")) reads.push(value);
|
|
703
|
+
}
|
|
704
|
+
return isIdentifier(node);
|
|
705
|
+
} });
|
|
706
|
+
const namespaceValues = /* @__PURE__ */ new Map();
|
|
707
|
+
function isClientNamespace(node) {
|
|
708
|
+
const aliases = [];
|
|
709
|
+
let found = false;
|
|
710
|
+
while (node = unwrapStaticExpression(node)) {
|
|
711
|
+
if (node.type === "AwaitExpression") {
|
|
712
|
+
node = node.argument;
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (node.type === "ImportExpression") {
|
|
716
|
+
const source = staticLiteral(node.source);
|
|
717
|
+
found = typeof source === "string" && CLIENT_MODULES.has(source);
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
if (!isIdentifier(node)) break;
|
|
721
|
+
const binding = resolve(node, node.name);
|
|
722
|
+
if (binding && namespaces.has(binding)) {
|
|
723
|
+
found = true;
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
if (binding?.type !== "VariableDeclarator" || !isIdentifier(binding.id)) break;
|
|
727
|
+
const cached = namespaceValues.get(binding);
|
|
728
|
+
if (cached !== void 0) {
|
|
729
|
+
found = cached;
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
namespaceValues.set(binding, false);
|
|
733
|
+
aliases.push(binding);
|
|
734
|
+
node = binding.init;
|
|
735
|
+
}
|
|
736
|
+
for (const alias of aliases) namespaceValues.set(alias, found);
|
|
737
|
+
return found;
|
|
738
|
+
}
|
|
739
|
+
return reads.some(isClientNamespace);
|
|
740
|
+
}
|
|
741
|
+
// src/inference/walk.ts
|
|
742
|
+
const ENV_BINDING_RE = /\benv\b|\\(?:u|x|[0-7\r\n\u2028\u2029])/;
|
|
743
|
+
const RESOURCE_BINDING_RE = /\b(?:DB\b|KV\b|STORAGE\b|AI\b|SANDBOX\b|QUEUE_)|\\(?:u|x|[0-7A-Z_\r\n\u2028\u2029])/;
|
|
744
|
+
/**
|
|
745
|
+
* Infer which Cloudflare bindings a source file uses.
|
|
746
|
+
*
|
|
747
|
+
* Read Vite's module metadata, then walk the AST only for potential env bindings.
|
|
748
|
+
*/
|
|
749
|
+
function inferBindingsFromSource(code, filename) {
|
|
750
|
+
const result = {
|
|
751
|
+
needsD1: false,
|
|
752
|
+
needsKV: false,
|
|
753
|
+
needsR2: false,
|
|
754
|
+
needsAuth: false,
|
|
755
|
+
needsQueues: false,
|
|
756
|
+
needsAI: false,
|
|
757
|
+
needsSandbox: false,
|
|
758
|
+
needsLive: false,
|
|
759
|
+
needsEmail: false
|
|
760
|
+
};
|
|
761
|
+
let parsed;
|
|
762
|
+
try {
|
|
763
|
+
parsed = parseSync(filename, code);
|
|
764
|
+
if (parsed.errors.length > 0) return result;
|
|
765
|
+
} catch {
|
|
766
|
+
return result;
|
|
767
|
+
}
|
|
768
|
+
let hasClientModule = false;
|
|
769
|
+
function recordModuleReference(source) {
|
|
770
|
+
if (CLIENT_MODULES.has(source)) hasClientModule = true;
|
|
771
|
+
switch (source) {
|
|
772
|
+
case "@builtbyfriends/bwf/db":
|
|
773
|
+
result.needsD1 = true;
|
|
774
|
+
break;
|
|
775
|
+
case "@builtbyfriends/bwf/kv":
|
|
776
|
+
result.needsKV = true;
|
|
777
|
+
break;
|
|
778
|
+
case "@builtbyfriends/bwf/storage":
|
|
779
|
+
result.needsR2 = true;
|
|
780
|
+
break;
|
|
781
|
+
case "@builtbyfriends/bwf/auth":
|
|
782
|
+
result.needsAuth = true;
|
|
783
|
+
break;
|
|
784
|
+
case "@builtbyfriends/bwf/queues":
|
|
785
|
+
result.needsQueues = true;
|
|
786
|
+
break;
|
|
787
|
+
case "@builtbyfriends/bwf/ai":
|
|
788
|
+
result.needsAI = true;
|
|
789
|
+
break;
|
|
790
|
+
case "@builtbyfriends/bwf/sandbox":
|
|
791
|
+
result.needsSandbox = true;
|
|
792
|
+
break;
|
|
793
|
+
case "@builtbyfriends/bwf/email":
|
|
794
|
+
result.needsEmail = true;
|
|
795
|
+
break;
|
|
796
|
+
case "@builtbyfriends/bwf/live": result.needsLive = true;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
for (const reference of staticModuleReferences(parsed, code)) recordModuleReference(reference.source);
|
|
800
|
+
for (const reference of parsed.module.dynamicImports) {
|
|
801
|
+
const argument = code.slice(reference.moduleRequest.start, reference.moduleRequest.end);
|
|
802
|
+
const expression = parseSync(filename, `(${argument})`).program.body[0];
|
|
803
|
+
const source = expression?.type === "ExpressionStatement" ? staticLiteral(expression.expression) : void 0;
|
|
804
|
+
if (typeof source === "string") recordModuleReference(source);
|
|
805
|
+
}
|
|
806
|
+
if (hasClientModule) result.needsAuth ||= inferClientAuth(parsed, code);
|
|
807
|
+
if (!ENV_BINDING_RE.test(code) || !RESOURCE_BINDING_RE.test(code)) return result;
|
|
808
|
+
function propertyName(node) {
|
|
809
|
+
const key = node.property ?? node.key;
|
|
810
|
+
const name = !node.computed && isIdentifier(key) ? key.name : staticLiteral(key);
|
|
811
|
+
return typeof name === "string" ? name : void 0;
|
|
812
|
+
}
|
|
813
|
+
function isEnv(node) {
|
|
814
|
+
node = unwrapStaticExpression(node);
|
|
815
|
+
return isIdentifier(node) && node.name === "env" || isMemberExpression(node) && propertyName(node) === "env";
|
|
816
|
+
}
|
|
817
|
+
function recordBinding(name) {
|
|
818
|
+
switch (name) {
|
|
819
|
+
case "DB":
|
|
820
|
+
result.needsD1 = true;
|
|
821
|
+
break;
|
|
822
|
+
case "KV":
|
|
823
|
+
result.needsKV = true;
|
|
824
|
+
break;
|
|
825
|
+
case "STORAGE":
|
|
826
|
+
result.needsR2 = true;
|
|
827
|
+
break;
|
|
828
|
+
case "AI":
|
|
829
|
+
result.needsAI = true;
|
|
830
|
+
break;
|
|
831
|
+
case "SANDBOX":
|
|
832
|
+
result.needsSandbox = true;
|
|
833
|
+
break;
|
|
834
|
+
default: if (name?.startsWith("QUEUE_")) result.needsQueues = true;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
function inspectPattern(pattern, fromEnv = false) {
|
|
838
|
+
if (pattern?.type === "AssignmentPattern") inspectPattern(pattern.left, fromEnv || isEnv(pattern.right));
|
|
839
|
+
else if (pattern?.type === "ObjectPattern") for (const property of pattern.properties ?? []) {
|
|
840
|
+
if (property.type !== "Property") continue;
|
|
841
|
+
const name = propertyName(property);
|
|
842
|
+
if (fromEnv) recordBinding(name);
|
|
843
|
+
inspectPattern(property.value, name === "env");
|
|
844
|
+
}
|
|
845
|
+
else if (pattern?.type === "ArrayPattern") for (const element of pattern.elements ?? []) inspectPattern(element);
|
|
846
|
+
}
|
|
847
|
+
walk(parsed.program, { enter(node) {
|
|
848
|
+
const current = node;
|
|
849
|
+
if (isMemberExpression(current) && isEnv(current.object)) recordBinding(propertyName(current));
|
|
850
|
+
else if (current.type === "VariableDeclarator" || current.type === "AssignmentExpression") inspectPattern(current.id ?? current.left, isEnv(current.init ?? current.right));
|
|
851
|
+
else if ([
|
|
852
|
+
"FunctionDeclaration",
|
|
853
|
+
"FunctionExpression",
|
|
854
|
+
"ArrowFunctionExpression"
|
|
855
|
+
].includes(current.type)) for (const parameter of current.params ?? []) inspectPattern(parameter);
|
|
856
|
+
} });
|
|
857
|
+
return result;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Merge multiple InferredBindings into a single result (union).
|
|
861
|
+
*/
|
|
862
|
+
function mergeBindings(bindings) {
|
|
863
|
+
return {
|
|
864
|
+
needsD1: bindings.some((b) => b.needsD1),
|
|
865
|
+
needsKV: bindings.some((b) => b.needsKV),
|
|
866
|
+
needsR2: bindings.some((b) => b.needsR2),
|
|
867
|
+
needsAuth: bindings.some((b) => b.needsAuth),
|
|
868
|
+
needsQueues: bindings.some((b) => b.needsQueues),
|
|
869
|
+
needsAI: bindings.some((b) => b.needsAI),
|
|
870
|
+
needsSandbox: bindings.some((b) => b.needsSandbox),
|
|
871
|
+
needsLive: bindings.some((b) => b.needsLive),
|
|
872
|
+
needsEmail: bindings.some((b) => b.needsEmail)
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
// src/router/parse-filename.ts
|
|
876
|
+
const ENV_SUFFIXES = ["dev", "prod"];
|
|
877
|
+
function parsePath(relativePath, isWebSocketRoute) {
|
|
878
|
+
const filePath = relativePath;
|
|
879
|
+
let path = relativePath.replace(/\\/g, "/");
|
|
880
|
+
for (const ext of ROUTE_EXTENSIONS) if (path.endsWith(`.${ext}`)) {
|
|
881
|
+
path = path.slice(0, -(ext.length + 1));
|
|
882
|
+
break;
|
|
883
|
+
}
|
|
884
|
+
if (isWebSocketRoute && path.endsWith(".ws")) path = path.slice(0, -3);
|
|
885
|
+
const segments = path.split("/");
|
|
886
|
+
let filename = segments.pop();
|
|
887
|
+
let env = null;
|
|
888
|
+
for (const suffix of ENV_SUFFIXES) if (filename.endsWith(`.${suffix}`)) {
|
|
889
|
+
env = suffix;
|
|
890
|
+
filename = filename.slice(0, -(suffix.length + 1));
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
segments.push(filename);
|
|
894
|
+
if (segments[segments.length - 1] === "index") segments.pop();
|
|
895
|
+
const filtered = segments.filter((s) => !s.startsWith("(") || !s.endsWith(")"));
|
|
896
|
+
const params = [];
|
|
897
|
+
let catchAll = false;
|
|
898
|
+
return {
|
|
899
|
+
pattern: "/" + filtered.map((segment) => {
|
|
900
|
+
if (segment.startsWith("[...") && segment.endsWith("]")) {
|
|
901
|
+
const paramName = segment.slice(4, -1);
|
|
902
|
+
catchAll = true;
|
|
903
|
+
if (paramName) {
|
|
904
|
+
params.push(paramName);
|
|
905
|
+
return `:${paramName}{.+}`;
|
|
906
|
+
}
|
|
907
|
+
return "*";
|
|
908
|
+
}
|
|
909
|
+
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
910
|
+
const paramName = segment.slice(1, -1);
|
|
911
|
+
params.push(paramName);
|
|
912
|
+
return `:${paramName}`;
|
|
913
|
+
}
|
|
914
|
+
return segment;
|
|
915
|
+
}).join("/"),
|
|
916
|
+
methods: [],
|
|
917
|
+
params,
|
|
918
|
+
catchAll,
|
|
919
|
+
env,
|
|
920
|
+
filePath
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Parse a route filename (relative to routes/) into a RouteDefinition.
|
|
925
|
+
*
|
|
926
|
+
* Rules (applied in order):
|
|
927
|
+
* 1. Strip file extension (.ts, .tsx, .js, .jsx, .mts, .mjs)
|
|
928
|
+
* 2. Check for env suffix (.dev, .prod) → strip and record
|
|
929
|
+
* 3. Strip trailing "index" segment
|
|
930
|
+
* 4. Remove route group directories: (groupname)
|
|
931
|
+
* 5. Convert [param] → :param, [...param] → :param{.+}, [...] → *
|
|
932
|
+
* 6. Prefix with /
|
|
933
|
+
*/
|
|
934
|
+
function parseRouteFilename(relativePath) {
|
|
935
|
+
return parsePath(relativePath, false);
|
|
936
|
+
}
|
|
937
|
+
/** Parse a `.ws.*` route filename into a regular route definition. */
|
|
938
|
+
function parseWebSocketFilename(relativePath) {
|
|
939
|
+
return parsePath(relativePath, true);
|
|
940
|
+
}
|
|
941
|
+
function isRouteEnabledForEnvironment(route, environment) {
|
|
942
|
+
return environment === void 0 || route.env === null || route.env === environment;
|
|
943
|
+
}
|
|
944
|
+
// src/router/route-order.ts
|
|
945
|
+
/**
|
|
946
|
+
* Classify one segment of a route pattern. `*` and `:name{.+}` match the rest of the path,
|
|
947
|
+
* `:name` matches one segment, and anything else matches as written. Pages match with the
|
|
948
|
+
* same rules on the client (see `patternToRegex`), so ranking and matching agree.
|
|
949
|
+
*/
|
|
950
|
+
function routeSegmentKind(segment) {
|
|
951
|
+
if (segment === "*") return "rest";
|
|
952
|
+
if (segment.length < 2 || segment[0] !== ":") return "static";
|
|
953
|
+
const name = segment.endsWith("{.+}") ? segment.slice(1, -4) : "";
|
|
954
|
+
return name && !name.includes("{") && !name.includes("}") ? "rest" : "param";
|
|
955
|
+
}
|
|
956
|
+
const SEGMENT_RANK = {
|
|
957
|
+
static: 0,
|
|
958
|
+
param: 1,
|
|
959
|
+
rest: 2
|
|
960
|
+
};
|
|
961
|
+
/**
|
|
962
|
+
* Order routes so that, of any two that match the same URL, the more specific one comes first.
|
|
963
|
+
* Hono and the Pages client matcher both use the first match.
|
|
964
|
+
*
|
|
965
|
+
* Catch-all routes come last and fully static routes first. Otherwise the first segment that
|
|
966
|
+
* differs decides: static before `:param` before catch-all. Parameter names never decide, so
|
|
967
|
+
* `/:lang/about` ranks ahead of `/:category/:item`. Two different static segments can't match
|
|
968
|
+
* the same URL, so their text only keeps the order stable.
|
|
969
|
+
*/
|
|
970
|
+
function compareRouteSpecificity(a, b) {
|
|
971
|
+
if (a.catchAll !== b.catchAll) return a.catchAll ? 1 : -1;
|
|
972
|
+
const aSegments = a.pattern.split("/");
|
|
973
|
+
const bSegments = b.pattern.split("/");
|
|
974
|
+
const aKinds = aSegments.map(routeSegmentKind);
|
|
975
|
+
const bKinds = bSegments.map(routeSegmentKind);
|
|
976
|
+
const aStatic = aKinds.every((kind) => kind === "static");
|
|
977
|
+
if (aStatic !== bKinds.every((kind) => kind === "static")) return aStatic ? -1 : 1;
|
|
978
|
+
const shared = Math.min(aSegments.length, bSegments.length);
|
|
979
|
+
for (let i = 0; i < shared; i++) {
|
|
980
|
+
const rank = SEGMENT_RANK[aKinds[i]] - SEGMENT_RANK[bKinds[i]];
|
|
981
|
+
if (rank !== 0) return rank;
|
|
982
|
+
if (aKinds[i] === "static" && aSegments[i] !== bSegments[i]) return compareText(aSegments[i], bSegments[i]);
|
|
983
|
+
}
|
|
984
|
+
return aSegments.length - bSegments.length || compareText(a.pattern, b.pattern);
|
|
985
|
+
}
|
|
986
|
+
function compareText(left, right) {
|
|
987
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
988
|
+
}
|
|
989
|
+
// src/router/websocket.ts
|
|
990
|
+
const WEBSOCKET_ROUTE_RE = new RegExp(`(?:\\.(?:dev|prod))?\\.ws\\.(?:${ROUTE_EXTENSIONS.join("|")})$`);
|
|
991
|
+
function isWebSocketRouteFile(filePath) {
|
|
992
|
+
return WEBSOCKET_ROUTE_RE.test(filePath.replace(/\\/g, "/"));
|
|
993
|
+
}
|
|
994
|
+
function identifierWords(segment) {
|
|
995
|
+
return segment.replace(/^\(\s*|\s*\)$/g, "").replace(/^\[\.\.\.(.+)\]$/, "$1").replace(/^\[(.+)\]$/, "$1").replace(/\.ws$/, "").replace(/\.(dev|prod)$/, "").replace(/[^a-zA-Z0-9]+/g, " ").split(" ").filter(Boolean);
|
|
996
|
+
}
|
|
997
|
+
function deriveWebSocketClassNameFromName(name) {
|
|
998
|
+
return resourceNameWords(name).map((part) => part[0].toUpperCase() + part.slice(1)).join("") + "Ws";
|
|
999
|
+
}
|
|
1000
|
+
function inferWebSocketResourceName(filePath) {
|
|
1001
|
+
let normalized = filePath.replace(/\\/g, "/");
|
|
1002
|
+
const extension = ROUTE_EXTENSIONS.find((ext) => normalized.endsWith(`.${ext}`));
|
|
1003
|
+
if (extension) normalized = normalized.slice(0, -(extension.length + 1));
|
|
1004
|
+
const parts = normalized.split("/").filter((segment) => segment.length > 0 && !(segment.startsWith("(") && segment.endsWith(")"))).flatMap(identifierWords);
|
|
1005
|
+
return parts.length > 0 ? parts.join("-") : "WebSocket";
|
|
1006
|
+
}
|
|
1007
|
+
function deriveWebSocketClassName(filePath) {
|
|
1008
|
+
return deriveWebSocketClassNameFromName(inferWebSocketResourceName(filePath));
|
|
1009
|
+
}
|
|
1010
|
+
function getPropertyName(node) {
|
|
1011
|
+
if (!node) return null;
|
|
1012
|
+
if (isIdentifier(node)) return node.name;
|
|
1013
|
+
if (isLiteral(node) && typeof node.value === "string") return node.value;
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
1016
|
+
const WEBSOCKET_HELPERS = /* @__PURE__ */ new Set(["defineRoom", "defineWebSocket"]);
|
|
1017
|
+
function detectWebSocketDefinition(absPath) {
|
|
1018
|
+
const definition = readResourceDefinition(absPath, readFileSync(absPath, "utf-8"), WEBSOCKET_HELPERS);
|
|
1019
|
+
if (!definition) return null;
|
|
1020
|
+
const hasAuthGate = isObjectExpression(definition.options) && (definition.options.properties ?? []).some((property) => property.type === "Property" && getPropertyName(property.key) === "onBeforeConnect");
|
|
1021
|
+
return {
|
|
1022
|
+
mode: definition.helper === "defineRoom" ? "room" : "socket",
|
|
1023
|
+
hasAuthGate,
|
|
1024
|
+
...definition.name === void 0 ? {} : { name: definition.name }
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
function buildWebSocketRoute(root, filePath, paths = readProjectPaths(root)) {
|
|
1028
|
+
const parsed = parseWebSocketFilename(filePath);
|
|
1029
|
+
const info = detectWebSocketDefinition(join(paths.routesDir, filePath));
|
|
1030
|
+
const className = info?.name === void 0 ? deriveWebSocketClassName(filePath) : deriveWebSocketClassNameFromName(info.name);
|
|
1031
|
+
return {
|
|
1032
|
+
...parsed,
|
|
1033
|
+
className,
|
|
1034
|
+
bindingName: className,
|
|
1035
|
+
mode: info?.mode ?? "socket",
|
|
1036
|
+
hasAuthGate: info?.hasAuthGate ?? false,
|
|
1037
|
+
...info?.name === void 0 ? {} : { name: info.name }
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
function parseWebSocketFiles(root, files, paths = readProjectPaths(root), environment) {
|
|
1041
|
+
const routes = files.filter((f) => isWebSocketRouteFile(f)).filter((filePath) => isRouteEnabledForEnvironment(parseWebSocketFilename(filePath), environment)).map((filePath) => buildWebSocketRoute(root, filePath, paths)).sort(compareRouteSpecificity);
|
|
1042
|
+
const byClass = /* @__PURE__ */ new Map();
|
|
1043
|
+
for (const route of routes) {
|
|
1044
|
+
const previous = byClass.get(route.className) ?? [];
|
|
1045
|
+
if (previous.some((other) => other.env === null || route.env === null || other.env === route.env)) throw new Error(`websocket: duplicate generated name '${route.className}' for '${route.filePath}'. Choose a different resource name or rename one of the WebSocket route files.`);
|
|
1046
|
+
previous.push(route);
|
|
1047
|
+
byClass.set(route.className, previous);
|
|
1048
|
+
}
|
|
1049
|
+
return routes;
|
|
1050
|
+
}
|
|
1051
|
+
function scanWebSocketRoutesSync(root, paths = readProjectPaths(root), environment) {
|
|
1052
|
+
return parseWebSocketFiles(root, listRouteFiles(paths.routesDir), paths, environment);
|
|
1053
|
+
}
|
|
1054
|
+
function isWebSocketPatternFile(filePath) {
|
|
1055
|
+
return isWebSocketRouteFile(filePath);
|
|
1056
|
+
}
|
|
1057
|
+
// src/shared/source-analysis-cache.ts
|
|
1058
|
+
/**
|
|
1059
|
+
* How long after a file changes its stat is trusted to identify its contents.
|
|
1060
|
+
* Some file systems keep coarse timestamps (FAT: 2 s, HFS+: 1 s, ext4: one
|
|
1061
|
+
* kernel tick) and Linux reuses inodes, so a second write inside that window
|
|
1062
|
+
* can leave the signature unchanged. Like Git's racily clean index entries,
|
|
1063
|
+
* values derived from recently changed files are recomputed on the next read.
|
|
1064
|
+
*/
|
|
1065
|
+
const RACY_WINDOW_MS = 3e3;
|
|
1066
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1067
|
+
/**
|
|
1068
|
+
* Derive a value from a source file, reusing it while the file is unchanged.
|
|
1069
|
+
* A dev server rescans every source file on each file event, and several
|
|
1070
|
+
* plugins scan the same pages, but only edited files need to be read and
|
|
1071
|
+
* parsed again. `kind` separates analyses of the same file. `derive` must be a
|
|
1072
|
+
* pure function of the source, and callers must not mutate its result.
|
|
1073
|
+
*/
|
|
1074
|
+
function deriveFromSource(path, kind, derive) {
|
|
1075
|
+
const key = toSlash(path);
|
|
1076
|
+
const stat = statSync(key, {
|
|
1077
|
+
bigint: true,
|
|
1078
|
+
throwIfNoEntry: false
|
|
1079
|
+
});
|
|
1080
|
+
if (!stat) return derive(readFileSync(key, "utf-8"));
|
|
1081
|
+
const signature = `${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
1082
|
+
const changedAt = Number((stat.mtimeNs > stat.ctimeNs ? stat.mtimeNs : stat.ctimeNs) / 1000000n);
|
|
1083
|
+
const trusted = Date.now() - changedAt > RACY_WINDOW_MS;
|
|
1084
|
+
const entry = entries.get(key);
|
|
1085
|
+
if (trusted && entry?.signature === signature && entry.derived.has(kind)) return entry.derived.get(kind);
|
|
1086
|
+
const value = derive(readFileSync(key, "utf-8"));
|
|
1087
|
+
if (!trusted) entries.delete(key);
|
|
1088
|
+
else if (entry?.signature === signature) entry.derived.set(kind, value);
|
|
1089
|
+
else entries.set(key, {
|
|
1090
|
+
signature,
|
|
1091
|
+
derived: /* @__PURE__ */ new Map([[kind, value]])
|
|
1092
|
+
});
|
|
1093
|
+
return value;
|
|
1094
|
+
}
|
|
1095
|
+
/** Forget values derived from a file. Dev servers call this for watcher events. */
|
|
1096
|
+
function invalidateSourceAnalysis(path) {
|
|
1097
|
+
entries.delete(toSlash(path));
|
|
1098
|
+
}
|
|
1099
|
+
// src/plugin-inference.ts
|
|
1100
|
+
const SOURCE_GLOB = "**/*.{ts,tsx,mts,js,jsx,mjs}";
|
|
1101
|
+
/**
|
|
1102
|
+
* Directories to scan for binding inference in bwf app mode.
|
|
1103
|
+
*
|
|
1104
|
+
* `email` is included so a `sendEmail()` call from inside an inbound handler
|
|
1105
|
+
* (`email/<addr>.ts`) registers `needsEmail = true`. Otherwise the manifest
|
|
1106
|
+
* flag and the dev-inbox plugin would miss those callsites.
|
|
1107
|
+
*/
|
|
1108
|
+
const DEFAULT_SCAN_DIRS = [
|
|
1109
|
+
"routes",
|
|
1110
|
+
"middleware",
|
|
1111
|
+
"queues",
|
|
1112
|
+
"crons",
|
|
1113
|
+
"procedures",
|
|
1114
|
+
"email",
|
|
1115
|
+
"durable-objects",
|
|
1116
|
+
"src"
|
|
1117
|
+
];
|
|
1118
|
+
/**
|
|
1119
|
+
* Synchronously infer which Cloudflare bindings the project needs
|
|
1120
|
+
* by scanning route/middleware/source files with oxc-parser.
|
|
1121
|
+
*
|
|
1122
|
+
* Without an environment this scans the full source superset, which is used
|
|
1123
|
+
* during plugin construction for binding-name reservation and plugin setup.
|
|
1124
|
+
*
|
|
1125
|
+
* @param scanDirs - Override the default scan directories
|
|
1126
|
+
*/
|
|
1127
|
+
function inferProjectBindings(root, options, scanDirs) {
|
|
1128
|
+
const paths = options?.paths ?? readProjectPaths(root);
|
|
1129
|
+
const dirs = scanDirs ?? (paths.sourceDir ? [paths.sourceDir, "durable-objects"] : DEFAULT_SCAN_DIRS);
|
|
1130
|
+
const allBindings = [];
|
|
1131
|
+
const scannedFiles = /* @__PURE__ */ new Set();
|
|
1132
|
+
const routesPrefix = `${toSlash(paths.routesDir).replace(/\/$/, "")}/`;
|
|
1133
|
+
const scanSourceFiles = (dirPath) => globSync(conventionFileGlobs(dirPath, SOURCE_GLOB, paths.routesDir), {
|
|
1134
|
+
cwd: dirPath,
|
|
1135
|
+
absolute: true
|
|
1136
|
+
});
|
|
1137
|
+
const addFile = (file) => {
|
|
1138
|
+
const normalizedFile = toSlash(file);
|
|
1139
|
+
if (scannedFiles.has(normalizedFile)) return;
|
|
1140
|
+
scannedFiles.add(normalizedFile);
|
|
1141
|
+
const routePath = normalizedFile.startsWith(routesPrefix) ? normalizedFile.slice(routesPrefix.length) : void 0;
|
|
1142
|
+
if (options?.environment && routePath !== void 0 && isRouteFile(routePath)) {
|
|
1143
|
+
if (!isRouteEnabledForEnvironment(isWebSocketPatternFile(routePath) ? parseWebSocketFilename(routePath) : parseRouteFilename(routePath), options.environment)) return;
|
|
1144
|
+
}
|
|
1145
|
+
allBindings.push(deriveFromSource(file, "bindings", (code) => inferBindingsFromSource(code, file.split("/").pop() ?? "unknown.ts")));
|
|
1146
|
+
};
|
|
1147
|
+
for (const dir of dirs) {
|
|
1148
|
+
const dirPath = join(root, dir);
|
|
1149
|
+
let files;
|
|
1150
|
+
try {
|
|
1151
|
+
files = scanSourceFiles(dirPath);
|
|
1152
|
+
} catch {
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
for (const file of files) addFile(file);
|
|
1156
|
+
}
|
|
1157
|
+
const dirsSet = new Set(dirs);
|
|
1158
|
+
const srcRel = paths.sourceDir ? paths.sourceDir : "src";
|
|
1159
|
+
if (!dirsSet.has(srcRel)) {
|
|
1160
|
+
const srcPath = paths.sourceDir ? paths.sourceRoot : join(root, "src");
|
|
1161
|
+
let srcFiles;
|
|
1162
|
+
try {
|
|
1163
|
+
srcFiles = scanSourceFiles(srcPath);
|
|
1164
|
+
} catch {
|
|
1165
|
+
srcFiles = [];
|
|
1166
|
+
}
|
|
1167
|
+
for (const file of srcFiles) addFile(file);
|
|
1168
|
+
}
|
|
1169
|
+
return applyBindingOverrides(mergeBindings(allBindings), options?.bindings);
|
|
1170
|
+
}
|
|
1171
|
+
// src/procedures/scan.ts
|
|
1172
|
+
function procedurePrefix(filePath) {
|
|
1173
|
+
const segments = filePath.replace(/\.[^.]+$/, "").split("/");
|
|
1174
|
+
if (segments.at(-1) === "index") segments.pop();
|
|
1175
|
+
return segments.join(".");
|
|
1176
|
+
}
|
|
1177
|
+
/** Every procedure module. Files and folders starting with `_` are shared helpers. */
|
|
1178
|
+
function scanProceduresSync(proceduresDir) {
|
|
1179
|
+
return listConventionFiles(proceduresDir).sort((a, b) => a.localeCompare(b)).map((filePath) => ({
|
|
1180
|
+
filePath,
|
|
1181
|
+
prefix: procedurePrefix(filePath)
|
|
1182
|
+
}));
|
|
1183
|
+
}
|
|
1184
|
+
/** The app's name and version from package.json, for OpenAPI and the analytics dataset. */
|
|
1185
|
+
function readAppIdentity(root) {
|
|
1186
|
+
try {
|
|
1187
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
1188
|
+
return {
|
|
1189
|
+
name: typeof pkg.name === "string" ? pkg.name : "app",
|
|
1190
|
+
version: typeof pkg.version === "string" ? pkg.version : "0.0.0"
|
|
1191
|
+
};
|
|
1192
|
+
} catch {
|
|
1193
|
+
return {
|
|
1194
|
+
name: "app",
|
|
1195
|
+
version: "0.0.0"
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
// src/queues/scan.ts
|
|
1200
|
+
function extractName(filePath) {
|
|
1201
|
+
return filePath.replace(/\.[^.]+$/, "").replaceAll("/", "-");
|
|
1202
|
+
}
|
|
1203
|
+
function deriveQueueBindingName(name) {
|
|
1204
|
+
return "QUEUE_" + name.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1205
|
+
}
|
|
1206
|
+
const OPTION_NAMES = [
|
|
1207
|
+
"maxBatchSize",
|
|
1208
|
+
"maxBatchTimeout",
|
|
1209
|
+
"maxRetries",
|
|
1210
|
+
"retryDelay"
|
|
1211
|
+
];
|
|
1212
|
+
const OPTION_NAME_SET = new Set(OPTION_NAMES);
|
|
1213
|
+
/** Queue files already warned about `export *`; a dev server rescans queues on every change. */
|
|
1214
|
+
const warnedExportAll = /* @__PURE__ */ new Set();
|
|
1215
|
+
/**
|
|
1216
|
+
* Consumer options configure Cloudflare before any queue code runs, so they are
|
|
1217
|
+
* read from the source. Reject exports whose value the source does not show,
|
|
1218
|
+
* instead of deploying Cloudflare's defaults.
|
|
1219
|
+
*/
|
|
1220
|
+
function readOptionInitializers(absPath, filePath, source) {
|
|
1221
|
+
if (!OPTION_NAMES.some((option) => source.includes(option)) && !mayExportAll(source)) return /* @__PURE__ */ new Map();
|
|
1222
|
+
const exports = readStaticExports(absPath, source, OPTION_NAME_SET);
|
|
1223
|
+
const unreadable = OPTION_NAMES.find((option) => exports.unreadable.has(option));
|
|
1224
|
+
if (unreadable) throw new Error(`queue: ${unreadable} in '${filePath}' must be declared in the queue file as \`export const ${unreadable} = <integer>\`. Re-exported options and other export forms are not read.`);
|
|
1225
|
+
if (exports.exportsAll && OPTION_NAMES.some((option) => !exports.initializers.has(option)) && !warnedExportAll.has(absPath)) {
|
|
1226
|
+
warnedExportAll.add(absPath);
|
|
1227
|
+
bwfWarn(`queue: '${filePath}' uses \`export * from\`. bwf does not read consumer options through it, so declare them in the queue file with \`export const\`. Re-export other names individually to remove this warning.`);
|
|
1228
|
+
}
|
|
1229
|
+
return exports.initializers;
|
|
1230
|
+
}
|
|
1231
|
+
function scanQueuesSync(queuesDir) {
|
|
1232
|
+
const definitions = listConventionFiles(queuesDir).sort().map((filePath) => {
|
|
1233
|
+
const absPath = join(queuesDir, filePath);
|
|
1234
|
+
const source = readFileSync(absPath, "utf-8");
|
|
1235
|
+
const name = extractName(filePath);
|
|
1236
|
+
const options = readOptionInitializers(absPath, filePath, source);
|
|
1237
|
+
const optionValue = (option) => {
|
|
1238
|
+
const initializer = options.get(option);
|
|
1239
|
+
if (!initializer) return;
|
|
1240
|
+
const value = staticLiteral(initializer);
|
|
1241
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) throw new Error(`queue: ${option} in '${filePath}' must be a nonnegative integer literal.`);
|
|
1242
|
+
return value;
|
|
1243
|
+
};
|
|
1244
|
+
return {
|
|
1245
|
+
filePath,
|
|
1246
|
+
name,
|
|
1247
|
+
bindingName: deriveQueueBindingName(name),
|
|
1248
|
+
maxBatchSize: optionValue("maxBatchSize"),
|
|
1249
|
+
maxBatchTimeout: optionValue("maxBatchTimeout"),
|
|
1250
|
+
maxRetries: optionValue("maxRetries"),
|
|
1251
|
+
retryDelay: optionValue("retryDelay")
|
|
1252
|
+
};
|
|
1253
|
+
});
|
|
1254
|
+
const filesByName = /* @__PURE__ */ new Map();
|
|
1255
|
+
for (const definition of definitions) {
|
|
1256
|
+
const matchingFiles = filesByName.get(definition.name) ?? [];
|
|
1257
|
+
matchingFiles.push(definition.filePath);
|
|
1258
|
+
filesByName.set(definition.name, matchingFiles);
|
|
1259
|
+
}
|
|
1260
|
+
const collisions = [...filesByName].filter(([, matchingFiles]) => matchingFiles.length > 1).sort(([leftName], [rightName]) => leftName < rightName ? -1 : leftName > rightName ? 1 : 0).map(([name, matchingFiles]) => ` ${JSON.stringify(name)}: ${matchingFiles.map((file) => JSON.stringify(file)).join(", ")}`);
|
|
1261
|
+
if (collisions.length > 0) throw new Error([
|
|
1262
|
+
"queue: Multiple queue files resolve to the same queue name:",
|
|
1263
|
+
...collisions,
|
|
1264
|
+
"Rename the conflicting files so each queue has a unique name."
|
|
1265
|
+
].join("\n"));
|
|
1266
|
+
return definitions;
|
|
1267
|
+
}
|
|
1268
|
+
// src/router/detect-exports.ts
|
|
1269
|
+
const HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
1270
|
+
"GET",
|
|
1271
|
+
"POST",
|
|
1272
|
+
"PUT",
|
|
1273
|
+
"PATCH",
|
|
1274
|
+
"DELETE",
|
|
1275
|
+
"OPTIONS",
|
|
1276
|
+
"HEAD"
|
|
1277
|
+
]);
|
|
1278
|
+
/**
|
|
1279
|
+
* Detect which HTTP method names are exported from a route file.
|
|
1280
|
+
* Scans top-level named exports for identifiers matching HTTP methods.
|
|
1281
|
+
*/
|
|
1282
|
+
function detectHttpExports(absPath) {
|
|
1283
|
+
const code = readFileSync(absPath, "utf-8");
|
|
1284
|
+
const filename = basename(absPath);
|
|
1285
|
+
let parsed;
|
|
1286
|
+
try {
|
|
1287
|
+
parsed = parseSync(filename, code);
|
|
1288
|
+
} catch {
|
|
1289
|
+
return [];
|
|
1290
|
+
}
|
|
1291
|
+
const methods = [];
|
|
1292
|
+
const program = parsed.program;
|
|
1293
|
+
for (const node of program.body ?? []) if (node.type === "ExportNamedDeclaration") {
|
|
1294
|
+
const declarationNode = node;
|
|
1295
|
+
if (declarationNode.exportKind === "type") continue;
|
|
1296
|
+
const decl = declarationNode.declaration;
|
|
1297
|
+
if (decl) {
|
|
1298
|
+
if (decl.type === "VariableDeclaration") for (const declarator of decl.declarations ?? []) methods.push(...bindingNames(declarator.id).filter((name) => HTTP_METHODS.has(name)));
|
|
1299
|
+
else if (decl.type === "FunctionDeclaration") {
|
|
1300
|
+
const fn = decl;
|
|
1301
|
+
if (isIdentifier(fn.id) && HTTP_METHODS.has(fn.id.name)) methods.push(fn.id.name);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if (declarationNode.specifiers) for (const spec of declarationNode.specifiers) {
|
|
1305
|
+
if (spec.exportKind === "type") continue;
|
|
1306
|
+
const exported = moduleExportName(spec.exported);
|
|
1307
|
+
if (exported && HTTP_METHODS.has(exported)) methods.push(exported);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return methods;
|
|
1311
|
+
}
|
|
1312
|
+
// src/router/scan.ts
|
|
1313
|
+
function parseMiddlewareDefinitions(files) {
|
|
1314
|
+
return files.filter((f) => !f.startsWith("_")).map((f) => {
|
|
1315
|
+
const match = f.split("/").pop().match(/^(\d+)\./);
|
|
1316
|
+
return {
|
|
1317
|
+
order: match ? parseInt(match[1], 10) : Infinity,
|
|
1318
|
+
filePath: f
|
|
1319
|
+
};
|
|
1320
|
+
}).sort((a, b) => a.order - b.order);
|
|
1321
|
+
}
|
|
1322
|
+
/** Add HTTP methods to the inventories already resolved for this application phase. */
|
|
1323
|
+
async function scanRoutes(options) {
|
|
1324
|
+
const { paths, inventory } = options;
|
|
1325
|
+
const routes = inventory.routes.map((route) => {
|
|
1326
|
+
const methods = detectHttpExports(join(paths.routesDir, route.filePath));
|
|
1327
|
+
if (methods.includes("HEAD")) throw new Error(`routes: '${route.filePath}' exports HEAD. HEAD requests are answered by the GET handler; remove the HEAD export.`);
|
|
1328
|
+
return {
|
|
1329
|
+
...route,
|
|
1330
|
+
methods
|
|
1331
|
+
};
|
|
1332
|
+
}).sort(compareRouteSpecificity);
|
|
1333
|
+
return {
|
|
1334
|
+
...inventory,
|
|
1335
|
+
routes
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
function scanMiddlewareSync(root, paths = readProjectPaths(root)) {
|
|
1339
|
+
return parseMiddlewareDefinitions(globSync("**/*.{ts,mts,js,mjs}", { cwd: paths.middlewareDir }));
|
|
1340
|
+
}
|
|
1341
|
+
function scanRoutePatternsSync(root, paths = readProjectPaths(root), environment) {
|
|
1342
|
+
return listRouteFiles(paths.routesDir).filter((f) => !isWebSocketPatternFile(f)).map((f) => parseRouteFilename(f)).filter((route) => isRouteEnabledForEnvironment(route, environment)).sort(compareRouteSpecificity);
|
|
1343
|
+
}
|
|
1344
|
+
const DEFAULT_SANDBOX_CLASS_NAME = "SandboxV1";
|
|
1345
|
+
const DEFAULT_SANDBOX_CONTAINER_NAME = "void-sandbox-v1";
|
|
1346
|
+
const SANDBOX_MIGRATION_TAG = "void-sandbox-v2";
|
|
1347
|
+
/** True when the container is attached to the app's own Durable Object, not bwf's `SandboxV1`. */
|
|
1348
|
+
function isSandboxAttached(sandbox) {
|
|
1349
|
+
return sandbox?.durableObject !== void 0;
|
|
1350
|
+
}
|
|
1351
|
+
function isSandboxEnabled(config) {
|
|
1352
|
+
return config.sandbox !== void 0 && config.sandbox !== false;
|
|
1353
|
+
}
|
|
1354
|
+
function getDefaultSandboxImage() {
|
|
1355
|
+
return fileURLToPath(new URL("../../sandbox.Dockerfile", import.meta.resolve("@builtbyfriends/bwf/sandbox")));
|
|
1356
|
+
}
|
|
1357
|
+
function getDefaultSandboxPlatformImage() {
|
|
1358
|
+
return "cloudflare/debian-trixie";
|
|
1359
|
+
}
|
|
1360
|
+
function isLocalSandboxImage(image) {
|
|
1361
|
+
return isAbsolute(image) || image.startsWith("./") || image.startsWith("../") || image.toLowerCase().includes("dockerfile");
|
|
1362
|
+
}
|
|
1363
|
+
function requiresSandboxPlatformImage(config) {
|
|
1364
|
+
if (typeof config.sandbox !== "object" || config.sandbox === null) return false;
|
|
1365
|
+
return typeof config.sandbox.image === "string" && isLocalSandboxImage(config.sandbox.image) && config.sandbox.platformImage === void 0;
|
|
1366
|
+
}
|
|
1367
|
+
function resolveSandboxConfig(config, root = process.cwd()) {
|
|
1368
|
+
const raw = typeof config.sandbox === "object" ? config.sandbox : {};
|
|
1369
|
+
const image = raw.image ?? getDefaultSandboxImage();
|
|
1370
|
+
const imageBuildContext = raw.imageBuildContext;
|
|
1371
|
+
const platformImage = raw.platformImage ?? (raw.image && !isLocalSandboxImage(raw.image) ? raw.image : getDefaultSandboxPlatformImage());
|
|
1372
|
+
if (!isLocalSandboxImage(image) && !isSandboxRegistryImage(image)) throw new Error("sandbox.image must be a Dockerfile or a digest-pinned Cloudflare registry image (registry.cloudflare.com/<account>/<image>@sha256:<digest>).");
|
|
1373
|
+
if (platformImage !== getDefaultSandboxPlatformImage() && !isSandboxRegistryImage(platformImage)) throw new Error("sandbox.platformImage must be a digest-pinned Cloudflare registry image (registry.cloudflare.com/<account>/<image>@sha256:<digest>).");
|
|
1374
|
+
if (raw.durableObject !== void 0 && (raw.binding !== void 0 || raw.className !== void 0)) throw new Error("sandbox.durableObject sets the binding and class from the durable-objects/ module. Remove sandbox.binding and sandbox.className.");
|
|
1375
|
+
const attached = raw.durableObject === void 0 ? void 0 : deriveDurableResourceIdentity(raw.durableObject);
|
|
1376
|
+
return {
|
|
1377
|
+
...raw.durableObject !== void 0 && { durableObject: raw.durableObject },
|
|
1378
|
+
binding: attached?.bindingName ?? raw.binding ?? "SANDBOX",
|
|
1379
|
+
className: attached?.className ?? raw.className ?? "SandboxV1",
|
|
1380
|
+
containerName: raw.containerName ?? DEFAULT_SANDBOX_CONTAINER_NAME,
|
|
1381
|
+
image: resolveSandboxImage(image, root),
|
|
1382
|
+
platformImage,
|
|
1383
|
+
...imageBuildContext && { imageBuildContext: isAbsolute(imageBuildContext) ? imageBuildContext : join(root, imageBuildContext) },
|
|
1384
|
+
...raw.instanceType && { instanceType: raw.instanceType }
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
function resolveSandboxImage(image, root) {
|
|
1388
|
+
if (!isLocalSandboxImage(image) || isAbsolute(image)) return image;
|
|
1389
|
+
return join(root, image);
|
|
1390
|
+
}
|
|
1391
|
+
function sandboxContainerConfig(sandbox) {
|
|
1392
|
+
return {
|
|
1393
|
+
name: sandbox.containerName,
|
|
1394
|
+
class_name: sandbox.className,
|
|
1395
|
+
scheduling_policy: "durable_object",
|
|
1396
|
+
images: { default: isLocalSandboxImage(sandbox.image) ? {
|
|
1397
|
+
dockerfile: sandbox.image,
|
|
1398
|
+
...sandbox.imageBuildContext && { build_context: sandbox.imageBuildContext }
|
|
1399
|
+
} : { image: sandbox.image } }
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
/** Resolve the final local storage kind without recreating a renamed or deleted class. */
|
|
1403
|
+
function resolveSandboxMigrationStorage(migrations, className) {
|
|
1404
|
+
const storage = /* @__PURE__ */ new Map();
|
|
1405
|
+
for (const migration of migrations) {
|
|
1406
|
+
for (const name of migration.new_classes ?? []) storage.set(name, "legacy-kv");
|
|
1407
|
+
for (const name of migration.new_sqlite_classes ?? []) storage.set(name, "sqlite");
|
|
1408
|
+
for (const rename of migration.renamed_classes ?? []) {
|
|
1409
|
+
const sqlite = storage.get(rename.from);
|
|
1410
|
+
storage.delete(rename.from);
|
|
1411
|
+
storage.set(rename.to, sqlite ?? "unknown");
|
|
1412
|
+
}
|
|
1413
|
+
for (const transfer of migration.transferred_classes ?? []) storage.set(transfer.to, "unknown");
|
|
1414
|
+
for (const name of migration.deleted_classes ?? []) storage.delete(name);
|
|
1415
|
+
}
|
|
1416
|
+
return storage.get(className);
|
|
1417
|
+
}
|
|
1418
|
+
function hasSandboxSqliteMigration(migrations, className) {
|
|
1419
|
+
return resolveSandboxMigrationStorage(migrations, className) === "sqlite";
|
|
1420
|
+
}
|
|
1421
|
+
/** Refuse namespace reuse before either uploader can change a live Worker. */
|
|
1422
|
+
function assertSandboxNamespaceConfig(config, sandbox) {
|
|
1423
|
+
const containers = Array.isArray(config.containers) ? config.containers : [];
|
|
1424
|
+
const durable = config.durable_objects;
|
|
1425
|
+
const binding = durable?.bindings?.find((entry) => entry.name === sandbox.binding);
|
|
1426
|
+
if (binding && (binding.script_name !== void 0 || binding.environment !== void 0)) throw new Error(`sandbox: binding '${sandbox.binding}' must reference the local '${sandbox.className}' class. Choose another sandbox.binding name to preserve the existing external Durable Object.`);
|
|
1427
|
+
const migrations = Array.isArray(config.migrations) ? config.migrations : [];
|
|
1428
|
+
const storage = resolveSandboxMigrationStorage(migrations, sandbox.className);
|
|
1429
|
+
if (storage === "legacy-kv" || storage === "unknown") throw new Error(`sandbox: class '${sandbox.className}' needs SQLite storage, but its existing namespace has ${storage} storage. Preserve the existing migration history and choose a fresh Worker name or a new sandbox.className and sandbox.binding.`);
|
|
1430
|
+
if (storage !== "sqlite" && migrations.some((migration) => migration.tag === "void-sandbox-v2")) throw new Error(`sandbox: migration tag '${SANDBOX_MIGRATION_TAG}' is already configured for another class. Keep the existing history and choose a fresh Worker for Sandbox.`);
|
|
1431
|
+
if (containers.some((container) => container.class_name === sandbox.className && container.scheduling_policy !== "durable_object") || durable?.bindings?.some((binding) => binding.name === sandbox.binding && binding.class_name !== sandbox.className)) throw new Error("Sandbox SDK 1.0 needs a new Durable Object namespace. Back up existing Sandbox data and deploy to a fresh Worker name with the new Sandbox configuration; remove legacy Sandbox bindings, containers, and migrations from that new Worker configuration. See https://developers.cloudflare.com/containers/guides/migrate-to-durable-object-scheduling-policy/.");
|
|
1432
|
+
}
|
|
1433
|
+
// src/application-analysis.ts
|
|
1434
|
+
/**
|
|
1435
|
+
* Discover application source features once for a consumer's environment.
|
|
1436
|
+
* Resource ids, generated provider configuration and migration history remain
|
|
1437
|
+
* the responsibility of the target consuming this analysis.
|
|
1438
|
+
*/
|
|
1439
|
+
function analyzeApplicationSync(root, options) {
|
|
1440
|
+
const { config, environment } = options;
|
|
1441
|
+
const paths = resolveProjectPaths(root, config);
|
|
1442
|
+
const inferred = inferProjectBindings(root, {
|
|
1443
|
+
paths,
|
|
1444
|
+
environment,
|
|
1445
|
+
bindings: config.inference?.bindings
|
|
1446
|
+
}, config.inference?.scanDirs);
|
|
1447
|
+
const authConfigPath = findBwfAuthConfig(root, paths);
|
|
1448
|
+
const authEnabled = inferred.needsAuth || authConfigPath !== null || config.auth !== void 0;
|
|
1449
|
+
const bindings = {
|
|
1450
|
+
...inferred,
|
|
1451
|
+
needsAuth: authEnabled,
|
|
1452
|
+
needsSandbox: inferred.needsSandbox || isSandboxEnabled(config)
|
|
1453
|
+
};
|
|
1454
|
+
const dialect = getDatabaseDialect(config);
|
|
1455
|
+
const migrations = collectMigrations(paths.migrationsDir);
|
|
1456
|
+
const jobs = scanJobsSync(paths.cronsDir);
|
|
1457
|
+
const queues = scanQueuesSync(paths.queuesDir);
|
|
1458
|
+
const procedures = scanProceduresSync(paths.proceduresDir);
|
|
1459
|
+
const allWebsockets = scanWebSocketRoutesSync(root, paths);
|
|
1460
|
+
const websockets = allWebsockets.filter((route) => isRouteEnabledForEnvironment(route, environment));
|
|
1461
|
+
const durableObjects = scanDurableObjectModules(root);
|
|
1462
|
+
const email = scanEmailHandlersSync(paths.sourceRoot);
|
|
1463
|
+
const overrides = config.inference?.bindings;
|
|
1464
|
+
const bindingReason = (key, label, inferredReason) => overrides?.[key] ? `inference.bindings.${key} enables ${label}` : inferredReason;
|
|
1465
|
+
const reasons = {
|
|
1466
|
+
database: [],
|
|
1467
|
+
kv: bindings.needsKV ? [bindingReason("kv", "KV", "app uses env.KV")] : [],
|
|
1468
|
+
r2: bindings.needsR2 ? [bindingReason("storage", "R2", "app uses env.STORAGE (R2)")] : []
|
|
1469
|
+
};
|
|
1470
|
+
const databaseName = dialect === "sqlite" ? "a D1 database" : "a Hyperdrive database";
|
|
1471
|
+
if (bindings.needsD1) reasons.database.push(bindingReason("db", databaseName, dialect === "sqlite" ? "app uses env.DB (D1)" : "app uses a database"));
|
|
1472
|
+
if (authEnabled) reasons.database.push(`auth requires ${databaseName}`);
|
|
1473
|
+
if (migrations.length > 0) reasons.database.push(`checked-in migrations need ${databaseName}`);
|
|
1474
|
+
return {
|
|
1475
|
+
root,
|
|
1476
|
+
config,
|
|
1477
|
+
environment,
|
|
1478
|
+
paths,
|
|
1479
|
+
bindings,
|
|
1480
|
+
authConfigPath,
|
|
1481
|
+
authEnabled,
|
|
1482
|
+
dialect,
|
|
1483
|
+
bindingNames: resolveBindingNames(config.inference?.bindings),
|
|
1484
|
+
needsDatabase: needsApplicationDatabase(bindings, migrations.length),
|
|
1485
|
+
migrations,
|
|
1486
|
+
jobs,
|
|
1487
|
+
queues,
|
|
1488
|
+
procedures,
|
|
1489
|
+
websockets,
|
|
1490
|
+
allWebsockets,
|
|
1491
|
+
durableObjects,
|
|
1492
|
+
email,
|
|
1493
|
+
routes: scanRoutePatternsSync(root, paths, environment),
|
|
1494
|
+
middleware: scanMiddlewareSync(root, paths),
|
|
1495
|
+
reasons
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
export { isIdentifier as C, needsApplicationDatabase as D, applyBindingOverrides as E, bindingResolver as S, isMemberExpression as T, isRouteEnabledForEnvironment as _, hasSandboxSqliteMigration as a, inferDurableResourceName as b, resolveSandboxConfig as c, scanQueuesSync as d, readAppIdentity as f, inferWebSocketResourceName as g, deriveWebSocketClassNameFromName as h, assertSandboxNamespaceConfig as i, sandboxContainerConfig as l, invalidateSourceAnalysis as m, DEFAULT_SANDBOX_CLASS_NAME as n, isSandboxAttached as o, DEFAULT_SCAN_DIRS as p, SANDBOX_MIGRATION_TAG as r, requiresSandboxPlatformImage as s, analyzeApplicationSync as t, scanRoutes as u, inferBindingsFromSource as v, isLiteral as w, scanJobsSync as x, deriveDurableResourceIdentity as y };
|