void 0.1.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT_PROMPT.md +15 -0
- package/README.md +62 -123
- package/dist/auth-BdsJ0Aff.d.mts +43 -0
- package/dist/auth-cmd-Dx8oPKZC.mjs +43 -0
- package/dist/auth-migrations-BAtAck2g.mjs +117 -0
- package/dist/better-auth-shared-C9_GHSkR.d.mts +71 -0
- package/dist/better-auth-shared-CdYmQGry.mjs +163 -0
- package/dist/cache-W82I8ihI.mjs +47 -0
- package/dist/cancel-deploy-BOBTqqh0.mjs +59 -0
- package/dist/cf-access-Dee5cXxL.mjs +22 -0
- package/dist/chunk-DJd-R1mw.mjs +34 -0
- package/dist/cli/cli.d.mts +1 -0
- package/dist/cli/cli.mjs +1807 -0
- package/dist/client-snXOjrp1.mjs +565 -0
- package/dist/collect-CjeZgz5D.mjs +55 -0
- package/dist/config-BIa9HwVX.mjs +573 -0
- package/dist/config-BzM9Dy7T.mjs +37 -0
- package/dist/config-CvHtTM0q.mjs +30 -0
- package/dist/create-project-BIA15W7z.mjs +90 -0
- package/dist/db-DsRoMcfN.mjs +895 -0
- package/dist/defer-DcxEsVH1.mjs +49 -0
- package/dist/delete-DAP6yDc7.mjs +64 -0
- package/dist/deploy-BPKblFx6.mjs +2424 -0
- package/dist/discover-B7FkXBLB.mjs +40 -0
- package/dist/dist-DUyXJLkq.mjs +2667 -0
- package/dist/dist-Dayj3gCK.mjs +1287 -0
- package/dist/domain-BGofcQ6I.mjs +79 -0
- package/dist/dotenv-DwO4ti0Z.mjs +173 -0
- package/dist/drizzle-NnudE_UN.mjs +232 -0
- package/dist/env-CyG3tvU0.mjs +301 -0
- package/dist/env-helpers-Dr9Y7RnE.d.mts +52 -0
- package/dist/env-raw-BDL4TvdN.mjs +32 -0
- package/dist/env-types-DknSA4SO.mjs +64 -0
- package/dist/env-validation-DJKjR_8q.mjs +163 -0
- package/dist/fetch-error-BQ8sZ5Nd.mjs +266 -0
- package/dist/fetch-error-CVZ5CGA-.d.mts +20 -0
- package/dist/gen-U0Ktr4Zd.mjs +761 -0
- package/dist/handler-B0ds0OHJ.d.mts +269 -0
- package/dist/head-P-egrtFE.d.mts +45 -0
- package/dist/headers-DCXc7mDs.mjs +279 -0
- package/dist/index.d.mts +32 -0
- package/dist/index.mjs +4695 -0
- package/dist/init-C7wS5iGP.mjs +2625 -0
- package/dist/link-p2R6NbgN.mjs +49 -0
- package/dist/list-Bfel-QLc.mjs +113 -0
- package/dist/log-DXdqnmhF.mjs +26 -0
- package/dist/login-CkcXUiIu.mjs +72 -0
- package/dist/logs-DmkrRvx6.mjs +98 -0
- package/dist/magic-string.es-D6g9UnIy.mjs +1011 -0
- package/dist/mcp-CaQzfeUi.mjs +373 -0
- package/dist/node-DDfXj10V.mjs +54 -0
- package/dist/output-BwlcIYSR.mjs +139 -0
- package/dist/pages/client.d.mts +198 -0
- package/dist/pages/client.mjs +980 -0
- package/dist/pages/head-client.d.mts +15 -0
- package/dist/pages/head-client.mjs +90 -0
- package/dist/pages/head.d.mts +2 -0
- package/dist/pages/head.mjs +112 -0
- package/dist/pages/index.d.mts +38 -0
- package/dist/pages/index.mjs +76 -0
- package/dist/pages/islands-plugin.d.mts +50 -0
- package/dist/pages/islands-plugin.mjs +195 -0
- package/dist/pages/prefetch.d.mts +31 -0
- package/dist/pages/prefetch.mjs +90 -0
- package/dist/pages/protocol.d.mts +3 -0
- package/dist/pages/protocol.mjs +193 -0
- package/dist/pages/serialize.d.mts +10 -0
- package/dist/pages/serialize.mjs +14 -0
- package/dist/pathe.M-eThtNZ-D-kmWkCS.mjs +150 -0
- package/dist/plugin-inference-oZ6Ybu2_.mjs +2447 -0
- package/dist/prepare-BAtWufvm.mjs +99 -0
- package/dist/preset-D4I73kT4.mjs +221 -0
- package/dist/project-TqORyHn8.mjs +72 -0
- package/dist/project-cmd-B7lQp3F3.mjs +67 -0
- package/dist/project-slug-CKam8lF9.mjs +11 -0
- package/dist/project-tsconfig-DfkESbDL.mjs +63 -0
- package/dist/protocol-BWzXs2A2.d.mts +34 -0
- package/dist/providers-B3aMxWzP.mjs +67 -0
- package/dist/resolve-project-Br5BR03U.mjs +29 -0
- package/dist/rollback-gyC59l7U.mjs +92 -0
- package/dist/route-types-DReF1gUY.mjs +255 -0
- package/dist/routes-stub.d.mts +55 -0
- package/dist/routes-stub.mjs +1 -0
- package/dist/runner-6Ep3fNQu.mjs +123 -0
- package/dist/runner-pg-D0wWHYnr.mjs +57 -0
- package/dist/runtime/ai.d.mts +127 -0
- package/dist/runtime/ai.mjs +348 -0
- package/dist/runtime/auth-client-react.d.mts +8 -0
- package/dist/runtime/auth-client-react.mjs +6 -0
- package/dist/runtime/auth-client-solid.d.mts +8 -0
- package/dist/runtime/auth-client-solid.mjs +6 -0
- package/dist/runtime/auth-client-svelte.d.mts +8 -0
- package/dist/runtime/auth-client-svelte.mjs +6 -0
- package/dist/runtime/auth-client-vue.d.mts +8 -0
- package/dist/runtime/auth-client-vue.mjs +6 -0
- package/dist/runtime/auth-client.d.mts +8 -0
- package/dist/runtime/auth-client.mjs +6 -0
- package/dist/runtime/auth.d.mts +2 -0
- package/dist/runtime/auth.mjs +22 -0
- package/dist/runtime/better-auth-pg.d.mts +11 -0
- package/dist/runtime/better-auth-pg.mjs +51 -0
- package/dist/runtime/better-auth.d.mts +11 -0
- package/dist/runtime/better-auth.mjs +33 -0
- package/dist/runtime/client.d.mts +6 -0
- package/dist/runtime/client.mjs +5 -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 +30 -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/env-helpers.d.mts +2 -0
- package/dist/runtime/env-helpers.mjs +173 -0
- package/dist/runtime/env-public-client.d.mts +22 -0
- package/dist/runtime/env-public-client.mjs +54 -0
- package/dist/runtime/env-public.d.mts +143 -0
- package/dist/runtime/env-public.mjs +366 -0
- package/dist/runtime/env.d.mts +13 -0
- package/dist/runtime/env.mjs +51 -0
- package/dist/runtime/fetch-stream.d.mts +51 -0
- package/dist/runtime/fetch-stream.mjs +81 -0
- package/dist/runtime/fetch.d.mts +59 -0
- package/dist/runtime/fetch.mjs +18 -0
- package/dist/runtime/handler.d.mts +3 -0
- package/dist/runtime/handler.mjs +85 -0
- package/dist/runtime/isr.d.mts +26 -0
- package/dist/runtime/isr.mjs +43 -0
- package/dist/runtime/kv.d.mts +48 -0
- package/dist/runtime/kv.mjs +106 -0
- package/dist/runtime/log.d.mts +24 -0
- package/dist/runtime/log.mjs +31 -0
- package/dist/runtime/migration-handler-pg.d.mts +6 -0
- package/dist/runtime/migration-handler-pg.mjs +85 -0
- package/dist/runtime/migration-handler.d.mts +19 -0
- package/dist/runtime/migration-handler.mjs +92 -0
- package/dist/runtime/queues.d.mts +7 -0
- package/dist/runtime/queues.mjs +8 -0
- package/dist/runtime/remote/binding-handler.d.mts +15 -0
- package/dist/runtime/remote/binding-handler.mjs +208 -0
- package/dist/runtime/remote/index.d.mts +8 -0
- package/dist/runtime/remote/index.mjs +461 -0
- package/dist/runtime/response.d.mts +14 -0
- package/dist/runtime/response.mjs +30 -0
- package/dist/runtime/sandbox.d.mts +17 -0
- package/dist/runtime/sandbox.mjs +19 -0
- package/dist/runtime/schema-d1.d.mts +1 -0
- package/dist/runtime/schema-d1.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 +30 -0
- package/dist/runtime/seed.mjs +6 -0
- package/dist/runtime/storage.d.mts +7 -0
- package/dist/runtime/storage.mjs +14 -0
- package/dist/runtime/validator.d.mts +2 -0
- package/dist/runtime/validator.mjs +72 -0
- package/dist/runtime/ws-server.d.mts +26 -0
- package/dist/runtime/ws-server.mjs +296 -0
- package/dist/runtime/ws.d.mts +123 -0
- package/dist/runtime/ws.mjs +103 -0
- package/dist/scan-Ba4hFwlH.mjs +324 -0
- package/dist/scan-C6HMEIdW.mjs +318 -0
- package/dist/secret-CeRSukgM.mjs +109 -0
- package/dist/skills-ipldjlKE.mjs +62 -0
- package/dist/standard-schema-9CRjx-uR.d.mts +42 -0
- package/dist/subcommand-prompt-BKjuNAPb.mjs +349 -0
- package/dist/sveltekit.d.mts +20 -0
- package/dist/sveltekit.mjs +61 -0
- package/dist/types-mHOEwpW4.d.mts +57 -0
- package/dist/validate-CaMavMxu.mjs +146 -0
- package/dist/yarn-pnp-BFqMV_bl.mjs +196 -0
- package/getting-started-prompt.txt +26 -0
- package/package.json +322 -30
- package/schema.json +364 -0
- package/skills/migrate-vite-cloudflare-to-void/SKILL.md +175 -0
- package/skills/void/SKILL.md +75 -0
- package/skills/void/command/void.md +7 -0
- package/skills/void/docs/guide/ai.md +235 -0
- package/skills/void/docs/guide/app-types.md +103 -0
- package/skills/void/docs/guide/auth.md +257 -0
- package/skills/void/docs/guide/database/d1.md +106 -0
- package/skills/void/docs/guide/database/postgresql.md +106 -0
- package/skills/void/docs/guide/database.md +418 -0
- package/skills/void/docs/guide/deployment.md +98 -0
- package/skills/void/docs/guide/edge/headers.md +79 -0
- package/skills/void/docs/guide/edge/prerendering.md +83 -0
- package/skills/void/docs/guide/edge/redirects.md +116 -0
- package/skills/void/docs/guide/edge/revalidation.md +131 -0
- package/skills/void/docs/guide/edge/rewrites.md +354 -0
- package/skills/void/docs/guide/edge/static-assets.md +72 -0
- package/skills/void/docs/guide/env-vars.md +298 -0
- package/skills/void/docs/guide/index.md +80 -0
- package/skills/void/docs/guide/jobs.md +91 -0
- package/skills/void/docs/guide/kv.md +107 -0
- package/skills/void/docs/guide/pages-routing/actions-and-forms.md +419 -0
- package/skills/void/docs/guide/pages-routing/head.md +130 -0
- package/skills/void/docs/guide/pages-routing/islands.md +405 -0
- package/skills/void/docs/guide/pages-routing/layouts.md +362 -0
- package/skills/void/docs/guide/pages-routing/loaders.md +267 -0
- package/skills/void/docs/guide/pages-routing/markdown.md +625 -0
- package/skills/void/docs/guide/pages-routing/overview.md +236 -0
- package/skills/void/docs/guide/pages-routing/view-transitions.md +140 -0
- package/skills/void/docs/guide/queues.md +140 -0
- package/skills/void/docs/guide/quickstart.md +233 -0
- package/skills/void/docs/guide/remote-dev.md +67 -0
- package/skills/void/docs/guide/sandboxes.md +82 -0
- package/skills/void/docs/guide/server-routing.md +246 -0
- package/skills/void/docs/guide/ssg.md +74 -0
- package/skills/void/docs/guide/ssr.md +105 -0
- package/skills/void/docs/guide/storage.md +67 -0
- package/skills/void/docs/guide/type-safety.md +179 -0
- package/skills/void/docs/guide/typed-fetch.md +113 -0
- package/skills/void/docs/guide/websockets.md +190 -0
- package/skills/void/docs/index.md +48 -0
- package/skills/void/docs/integrations/agents.md +84 -0
- package/skills/void/docs/integrations/cloudflare.md +284 -0
- package/skills/void/docs/integrations/frameworks/analog.md +182 -0
- package/skills/void/docs/integrations/frameworks/astro.md +197 -0
- package/skills/void/docs/integrations/frameworks/nuxt.md +164 -0
- package/skills/void/docs/integrations/frameworks/overview.md +136 -0
- package/skills/void/docs/integrations/frameworks/react-router.md +137 -0
- package/skills/void/docs/integrations/frameworks/sveltekit.md +191 -0
- package/skills/void/docs/integrations/frameworks/tanstack-start.md +140 -0
- package/skills/void/docs/integrations/hono.md +97 -0
- package/skills/void/docs/integrations/nodejs-bun-deno.md +210 -0
- package/skills/void/docs/node_modules/@iconify/vue/README.md +408 -0
- package/skills/void/docs/node_modules/@iconify/vue/offline/readme.md +5 -0
- package/skills/void/docs/node_modules/@voidzero-dev/vitepress-theme/README.md +103 -0
- package/skills/void/docs/node_modules/oxc-minify/README.md +78 -0
- package/skills/void/docs/node_modules/reka-ui/README.md +80 -0
- package/skills/void/docs/node_modules/vitepress/README.md +28 -0
- package/skills/void/docs/node_modules/vitepress/template/api-examples.md +49 -0
- package/skills/void/docs/node_modules/vitepress/template/index.md +28 -0
- package/skills/void/docs/node_modules/vitepress/template/markdown-examples.md +85 -0
- package/skills/void/docs/node_modules/vitepress-plugin-group-icons/README.md +101 -0
- package/skills/void/docs/node_modules/void/AGENTS.md +204 -0
- package/skills/void/docs/node_modules/void/AGENT_PROMPT.md +15 -0
- package/skills/void/docs/node_modules/void/README.md +89 -0
- package/skills/void/docs/node_modules/void/node_modules/@clack/prompts/CHANGELOG.md +591 -0
- package/skills/void/docs/node_modules/void/node_modules/@clack/prompts/README.md +375 -0
- package/skills/void/docs/node_modules/void/node_modules/@cloudflare/sandbox/README.md +174 -0
- package/skills/void/docs/node_modules/void/node_modules/@cloudflare/vite-plugin/README.md +37 -0
- package/skills/void/docs/node_modules/void/node_modules/@cloudflare/workers-types/README.md +135 -0
- package/skills/void/docs/node_modules/void/node_modules/@electric-sql/pglite/README.md +189 -0
- package/skills/void/docs/node_modules/void/node_modules/@hono/oauth-providers/CHANGELOG.md +143 -0
- package/skills/void/docs/node_modules/void/node_modules/@hono/oauth-providers/README.md +1272 -0
- package/skills/void/docs/node_modules/void/node_modules/@napi-rs/keyring/README.md +19 -0
- package/skills/void/docs/node_modules/void/node_modules/@types/better-sqlite3/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@types/node/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@types/pg/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@typescript/native-preview/README.md +22 -0
- package/skills/void/docs/node_modules/void/node_modules/@typescript/native-preview/vendor/vscode-jsonrpc/README.md +69 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/README.md +152 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/@shikijs/engine-javascript/README.md +9 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/@shikijs/transformers/README.md +9 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/@types/node/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/gray-matter/CHANGELOG.md +24 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/gray-matter/README.md +565 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-exit/README.md +124 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-anchor/README.md +600 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-attrs/README.md +386 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-container/README.md +95 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-emoji/README.md +101 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/pathe/README.md +73 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/shiki/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/tinyglobby/README.md +25 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/tsdown/README.md +55 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/vite/LICENSE.md +2230 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/vite/README.md +20 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/vue/README.md +58 -0
- package/skills/void/docs/node_modules/void/node_modules/arktype/README.md +165 -0
- package/skills/void/docs/node_modules/void/node_modules/better-auth/LICENSE.md +20 -0
- package/skills/void/docs/node_modules/void/node_modules/better-auth/README.md +32 -0
- package/skills/void/docs/node_modules/void/node_modules/better-sqlite3/README.md +99 -0
- package/skills/void/docs/node_modules/void/node_modules/blake3-jit/README.md +108 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-arktype/README.md +51 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-kit/README.md +79 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-orm/README.md +44 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-valibot/README.md +51 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-zod/README.md +65 -0
- package/skills/void/docs/node_modules/void/node_modules/es-module-lexer/README.md +390 -0
- package/skills/void/docs/node_modules/void/node_modules/estree-walker/README.md +48 -0
- package/skills/void/docs/node_modules/void/node_modules/hono/README.md +85 -0
- package/skills/void/docs/node_modules/void/node_modules/ignore/README.md +452 -0
- package/skills/void/docs/node_modules/void/node_modules/jsonc-parser/CHANGELOG.md +76 -0
- package/{LICENSE → skills/void/docs/node_modules/void/node_modules/jsonc-parser/LICENSE.md} +21 -21
- package/skills/void/docs/node_modules/void/node_modules/jsonc-parser/README.md +364 -0
- package/skills/void/docs/node_modules/void/node_modules/jsonc-parser/SECURITY.md +41 -0
- package/skills/void/docs/node_modules/void/node_modules/magic-string/README.md +325 -0
- package/skills/void/docs/node_modules/void/node_modules/ofetch/README.md +398 -0
- package/skills/void/docs/node_modules/void/node_modules/pathe/README.md +73 -0
- package/skills/void/docs/node_modules/void/node_modules/pg/README.md +95 -0
- package/skills/void/docs/node_modules/void/node_modules/pglite-server/LICENSE.md +21 -0
- package/skills/void/docs/node_modules/void/node_modules/pglite-server/README.md +135 -0
- package/skills/void/docs/node_modules/void/node_modules/picocolors/README.md +21 -0
- package/skills/void/docs/node_modules/void/node_modules/tinyglobby/README.md +25 -0
- package/skills/void/docs/node_modules/void/node_modules/tsdown/README.md +55 -0
- package/skills/void/docs/node_modules/void/node_modules/valibot/LICENSE.md +9 -0
- package/skills/void/docs/node_modules/void/node_modules/valibot/README.md +94 -0
- package/skills/void/docs/node_modules/void/node_modules/vite/LICENSE.md +2230 -0
- package/skills/void/docs/node_modules/void/node_modules/vite/README.md +20 -0
- package/skills/void/docs/node_modules/void/node_modules/wrangler/README.md +63 -0
- package/skills/void/docs/node_modules/void/node_modules/zod/README.md +191 -0
- package/skills/void/docs/node_modules/void/skills/migrate-vite-cloudflare-to-void/SKILL.md +175 -0
- package/skills/void/docs/node_modules/void/skills/void/SKILL.md +75 -0
- package/skills/void/docs/node_modules/void/skills/void/command/void.md +7 -0
- package/skills/void/docs/reference/api.md +917 -0
- package/skills/void/docs/reference/cli.md +561 -0
- package/skills/void/docs/reference/config.md +408 -0
- package/skills/void/docs/reference/resource-inference.md +149 -0
- package/skills/void/docs/reference/structure.md +176 -0
- package/.npmignore +0 -29
- package/.travis.yml +0 -9
- package/favicon.ico +0 -0
- package/index.js +0 -14
- package/lib/Job.js +0 -150
- package/lib/Void.js +0 -99
- package/lib/scan.js +0 -19
- package/test/credentials.js +0 -20
- package/test/job.js +0 -64
- package/test/static/dir1/test6.html +0 -0
- package/test/static/dir2/test7.html +0 -0
- package/test/static/dir2/test8.html +0 -0
- package/test/static/dir2/test9.html +0 -0
- package/test/static/test1.html +0 -0
- package/test/static/test2.html +0 -0
- package/test/static/test3.html +0 -0
- package/test/void.js +0 -31
- /package/{test/static/dir1/test4.html → skills/void/docs/integrations/auth-providers.md} +0 -0
- /package/{test/static/dir1/test5.html → skills/void/docs/integrations/payment-processors.md} +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { convertReturnValue } from "./response.mjs";
|
|
2
|
+
import { runValidation } from "./validator.mjs";
|
|
3
|
+
import { i as ValidationError, n as defer } from "../defer-DcxEsVH1.mjs";
|
|
4
|
+
//#region src/runtime/handler.ts
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when `c.rewrite()` is called with a destination whose final path
|
|
7
|
+
* segment ends in a known static-asset extension (e.g. `/hero.png`,
|
|
8
|
+
* `/app.css`). Runtime rewrites only reach routes and SSR entries inside
|
|
9
|
+
* the worker — static asset handlers run in front of the worker, so a
|
|
10
|
+
* `c.rewrite()` into an asset path re-enters the Hono router, matches
|
|
11
|
+
* nothing, and returns a 404. Fail at the call site so users reach for
|
|
12
|
+
* static `routing.rewrites` instead of debugging a mystery 404.
|
|
13
|
+
*/
|
|
14
|
+
var VoidAssetRewriteError = class extends Error {
|
|
15
|
+
name = "VoidAssetRewriteError";
|
|
16
|
+
constructor(destination) {
|
|
17
|
+
super(`c.rewrite() cannot re-dispatch to a static asset path (${JSON.stringify(destination)}). Runtime rewrites only reach routes and SSR entries inside the worker — static asset handlers run in front of the worker. To rewrite into an asset, use a static \`routing.rewrites\` rule in void.json or a \`200!\` entry in _redirects. See https://void.dev/guide/edge/rewrites#runtime-rewrites-cannot-reach-static-assets`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function defineHandler(...args) {
|
|
21
|
+
if (args.length === 1) return args[0];
|
|
22
|
+
const middlewares = args.slice(0, -1);
|
|
23
|
+
const handler = args[args.length - 1];
|
|
24
|
+
return (async (c) => {
|
|
25
|
+
let index = 0;
|
|
26
|
+
const dispatch = async () => {
|
|
27
|
+
if (index < middlewares.length) {
|
|
28
|
+
const mw = middlewares[index++];
|
|
29
|
+
const res = await mw(c, dispatch);
|
|
30
|
+
if (res instanceof Response) c.res = res;
|
|
31
|
+
} else c.res = convertReturnValue(await handler(c));
|
|
32
|
+
};
|
|
33
|
+
await dispatch();
|
|
34
|
+
return c.res;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
(function(_defineHandler) {
|
|
38
|
+
function withValidator(validators) {
|
|
39
|
+
return (handler) => {
|
|
40
|
+
return (async (c) => {
|
|
41
|
+
const result = await runValidation(validators, c);
|
|
42
|
+
if (!result.ok) return result.response;
|
|
43
|
+
return convertReturnValue(await handler(c, result.input));
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
_defineHandler.withValidator = withValidator;
|
|
48
|
+
})(defineHandler || (defineHandler = {}));
|
|
49
|
+
/**
|
|
50
|
+
* Identity function that provides type inference for middleware.
|
|
51
|
+
* At runtime it simply returns the function passed to it.
|
|
52
|
+
*/
|
|
53
|
+
function defineMiddleware(handler) {
|
|
54
|
+
return handler;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Identity function that provides type inference for scheduled jobs.
|
|
58
|
+
* At runtime it simply returns the function passed to it.
|
|
59
|
+
*/
|
|
60
|
+
function defineScheduled(handler) {
|
|
61
|
+
return handler;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Identity function that provides type inference for SSR render entry.
|
|
65
|
+
* The second argument includes asset tags for client scripts/styles.
|
|
66
|
+
*/
|
|
67
|
+
function defineRender(handler) {
|
|
68
|
+
return handler;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Identity function that provides type inference for page `head()` exports.
|
|
72
|
+
* At runtime it simply returns the function passed to it.
|
|
73
|
+
*/
|
|
74
|
+
function defineHead(handler) {
|
|
75
|
+
return handler;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Identity function that provides type inference for queue consumers.
|
|
79
|
+
* At runtime it simply returns the function passed to it.
|
|
80
|
+
*/
|
|
81
|
+
function defineQueue(handler) {
|
|
82
|
+
return handler;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { ValidationError, VoidAssetRewriteError, defer, defineHandler, defineHead, defineMiddleware, defineQueue, defineRender, defineScheduled };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/runtime/isr.d.ts
|
|
2
|
+
interface RevalidateOptions {
|
|
3
|
+
paths?: Array<string>;
|
|
4
|
+
all?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Revalidate ISR-cached pages on demand.
|
|
8
|
+
*
|
|
9
|
+
* In production, calls the platform proxy via service binding which forwards
|
|
10
|
+
* to the API for R2 deletion + edge cache purge. In local dev, this is a
|
|
11
|
+
* no-op (no ISR cache to purge).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { revalidate } from "void/isr";
|
|
16
|
+
*
|
|
17
|
+
* // Revalidate specific paths
|
|
18
|
+
* await revalidate({ paths: ["/", "/blog/hello"] });
|
|
19
|
+
*
|
|
20
|
+
* // Revalidate all ISR pages
|
|
21
|
+
* await revalidate({ all: true });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function revalidate(options: RevalidateOptions): Promise<void>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { RevalidateOptions, revalidate };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { i as getRawRuntimeEnv } from "../env-raw-BDL4TvdN.mjs";
|
|
2
|
+
//#region src/runtime/isr.ts
|
|
3
|
+
/**
|
|
4
|
+
* Revalidate ISR-cached pages on demand.
|
|
5
|
+
*
|
|
6
|
+
* In production, calls the platform proxy via service binding which forwards
|
|
7
|
+
* to the API for R2 deletion + edge cache purge. In local dev, this is a
|
|
8
|
+
* no-op (no ISR cache to purge).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { revalidate } from "void/isr";
|
|
13
|
+
*
|
|
14
|
+
* // Revalidate specific paths
|
|
15
|
+
* await revalidate({ paths: ["/", "/blog/hello"] });
|
|
16
|
+
*
|
|
17
|
+
* // Revalidate all ISR pages
|
|
18
|
+
* await revalidate({ all: true });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
async function revalidate(options) {
|
|
22
|
+
const rawEnv = getRawRuntimeEnv();
|
|
23
|
+
const proxy = rawEnv.__VOID_PROXY;
|
|
24
|
+
if (!proxy) return;
|
|
25
|
+
const projectId = rawEnv.__PROJECT_ID;
|
|
26
|
+
const token = rawEnv.__VOID_PROXY_TOKEN;
|
|
27
|
+
if (!projectId || !token) throw new Error("isr: Revalidation requires __PROJECT_ID and __VOID_PROXY_TOKEN bindings.");
|
|
28
|
+
const response = await proxy.fetch("https://proxy/revalidate", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "content-type": "application/json" },
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
projectId,
|
|
33
|
+
aiToken: token,
|
|
34
|
+
...options
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const text = await response.text();
|
|
39
|
+
throw new Error(`isr: Revalidation failed with ${response.status}: '${text}'.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { revalidate };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/runtime/kv.d.ts
|
|
2
|
+
interface PutOptions {
|
|
3
|
+
ttl?: number;
|
|
4
|
+
expiration?: number;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface ListOptions {
|
|
8
|
+
prefix?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
cursor?: string;
|
|
11
|
+
}
|
|
12
|
+
interface ListKey<M = unknown> {
|
|
13
|
+
name: string;
|
|
14
|
+
expiration?: number;
|
|
15
|
+
metadata?: M;
|
|
16
|
+
}
|
|
17
|
+
interface ListResult<M = unknown> {
|
|
18
|
+
keys: Array<ListKey<M>>;
|
|
19
|
+
list_complete: boolean;
|
|
20
|
+
cursor?: string;
|
|
21
|
+
}
|
|
22
|
+
interface KVMap<T> {
|
|
23
|
+
get(key: string): Promise<T | null>;
|
|
24
|
+
put(key: string, value: T, options?: PutOptions): Promise<void>;
|
|
25
|
+
delete(key: string): Promise<void>;
|
|
26
|
+
list<M = unknown>(options?: Omit<ListOptions, "prefix">): Promise<ListResult<M>>;
|
|
27
|
+
getWithMetadata<M = unknown>(key: string): Promise<{
|
|
28
|
+
value: T | null;
|
|
29
|
+
metadata: M | null;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
interface KVClient {
|
|
33
|
+
get<T = string>(key: string): Promise<T | null>;
|
|
34
|
+
put(key: string, value: unknown, options?: PutOptions): Promise<void>;
|
|
35
|
+
delete(key: string): Promise<void>;
|
|
36
|
+
list<M = unknown>(options?: ListOptions): Promise<ListResult<M>>;
|
|
37
|
+
getWithMetadata<T = string, M = unknown>(key: string): Promise<{
|
|
38
|
+
value: T | null;
|
|
39
|
+
metadata: M | null;
|
|
40
|
+
}>;
|
|
41
|
+
map<T = unknown>(prefix: string): KVMap<T>;
|
|
42
|
+
}
|
|
43
|
+
/** Create a KV client for a specific KVNamespace instance. */
|
|
44
|
+
declare function createKV(namespace: KVNamespace): KVClient;
|
|
45
|
+
/** Default KV client — resolves `KV` from the active runtime environment. */
|
|
46
|
+
declare const kv: KVClient;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { KVClient, KVMap, ListKey, ListOptions, ListResult, PutOptions, createKV, kv };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { requireRuntimeBinding } from "./env.mjs";
|
|
2
|
+
//#region src/runtime/kv.ts
|
|
3
|
+
function parseValue(raw) {
|
|
4
|
+
if (raw === null) return null;
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(raw);
|
|
7
|
+
} catch {
|
|
8
|
+
return raw;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function serializeValue(value) {
|
|
12
|
+
if (typeof value === "string") return value;
|
|
13
|
+
return JSON.stringify(value);
|
|
14
|
+
}
|
|
15
|
+
function getListCursor(result) {
|
|
16
|
+
return typeof result.cursor === "string" ? result.cursor : void 0;
|
|
17
|
+
}
|
|
18
|
+
function createKVMap(getNS, prefix) {
|
|
19
|
+
const prefixed = (key) => `${prefix}:${key}`;
|
|
20
|
+
return {
|
|
21
|
+
async get(key) {
|
|
22
|
+
return parseValue(await getNS().get(prefixed(key)));
|
|
23
|
+
},
|
|
24
|
+
async put(key, value, options) {
|
|
25
|
+
const opts = {};
|
|
26
|
+
if (options?.ttl) opts.expirationTtl = options.ttl;
|
|
27
|
+
if (options?.expiration) opts.expiration = options.expiration;
|
|
28
|
+
if (options?.metadata) opts.metadata = options.metadata;
|
|
29
|
+
await getNS().put(prefixed(key), serializeValue(value), opts);
|
|
30
|
+
},
|
|
31
|
+
async delete(key) {
|
|
32
|
+
await getNS().delete(prefixed(key));
|
|
33
|
+
},
|
|
34
|
+
async list(options) {
|
|
35
|
+
const result = await getNS().list({
|
|
36
|
+
prefix: `${prefix}:`,
|
|
37
|
+
limit: options?.limit,
|
|
38
|
+
cursor: options?.cursor
|
|
39
|
+
});
|
|
40
|
+
const stripLen = prefix.length + 1;
|
|
41
|
+
return {
|
|
42
|
+
keys: result.keys.map((k) => ({
|
|
43
|
+
...k,
|
|
44
|
+
name: k.name.slice(stripLen)
|
|
45
|
+
})),
|
|
46
|
+
list_complete: result.list_complete,
|
|
47
|
+
cursor: getListCursor(result)
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
async getWithMetadata(key) {
|
|
51
|
+
const result = await getNS().getWithMetadata(prefixed(key));
|
|
52
|
+
const metadata = result.metadata;
|
|
53
|
+
return {
|
|
54
|
+
value: parseValue(result.value),
|
|
55
|
+
metadata
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function createKVClient(getNS) {
|
|
61
|
+
return {
|
|
62
|
+
async get(key) {
|
|
63
|
+
return parseValue(await getNS().get(key));
|
|
64
|
+
},
|
|
65
|
+
async put(key, value, options) {
|
|
66
|
+
const opts = {};
|
|
67
|
+
if (options?.ttl) opts.expirationTtl = options.ttl;
|
|
68
|
+
if (options?.expiration) opts.expiration = options.expiration;
|
|
69
|
+
if (options?.metadata) opts.metadata = options.metadata;
|
|
70
|
+
await getNS().put(key, serializeValue(value), opts);
|
|
71
|
+
},
|
|
72
|
+
async delete(key) {
|
|
73
|
+
await getNS().delete(key);
|
|
74
|
+
},
|
|
75
|
+
async list(options) {
|
|
76
|
+
const result = await getNS().list({
|
|
77
|
+
prefix: options?.prefix,
|
|
78
|
+
limit: options?.limit,
|
|
79
|
+
cursor: options?.cursor
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
keys: result.keys,
|
|
83
|
+
list_complete: result.list_complete,
|
|
84
|
+
cursor: getListCursor(result)
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
async getWithMetadata(key) {
|
|
88
|
+
const result = await getNS().getWithMetadata(key);
|
|
89
|
+
return {
|
|
90
|
+
value: parseValue(result.value),
|
|
91
|
+
metadata: result.metadata
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
map(prefix) {
|
|
95
|
+
return createKVMap(getNS, prefix);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Create a KV client for a specific KVNamespace instance. */
|
|
100
|
+
function createKV(namespace) {
|
|
101
|
+
return createKVClient(() => namespace);
|
|
102
|
+
}
|
|
103
|
+
/** Default KV client — resolves `KV` from the active runtime environment. */
|
|
104
|
+
const kv = createKVClient(() => requireRuntimeBinding("KV"));
|
|
105
|
+
//#endregion
|
|
106
|
+
export { createKV, kv };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/runtime/log.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Structured logger that emits each entry as a single stringified-JSON line
|
|
4
|
+
* to `console.error/warn/info`. The shape `{ msg, ...fields }` is a stable
|
|
5
|
+
* contract: Cloudflare Tail captures each call as one `logs[]` entry with
|
|
6
|
+
* the right `level`, and platform-side log filtering can match on `msg` or
|
|
7
|
+
* any custom field.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { logger } from "void/log";
|
|
12
|
+
*
|
|
13
|
+
* logger.error("websocket failed", { jobId, attempt: 3 });
|
|
14
|
+
* logger.info("user signed in", { userId });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
type Fields = Record<string, unknown>;
|
|
18
|
+
declare const logger: {
|
|
19
|
+
error(message: string, fields?: Fields): void;
|
|
20
|
+
warn(message: string, fields?: Fields): void;
|
|
21
|
+
info(message: string, fields?: Fields): void;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { logger };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/runtime/log.ts
|
|
2
|
+
function format(message, fields) {
|
|
3
|
+
try {
|
|
4
|
+
const payload = Object.create(null);
|
|
5
|
+
payload.msg = message;
|
|
6
|
+
if (fields) for (const [key, value] of Object.entries(fields)) {
|
|
7
|
+
if (key === "msg" || key === "toJSON" || key === "__proto__" || key === "constructor") continue;
|
|
8
|
+
if (typeof value === "function") continue;
|
|
9
|
+
payload[key] = value;
|
|
10
|
+
}
|
|
11
|
+
return JSON.stringify(payload);
|
|
12
|
+
} catch {
|
|
13
|
+
return JSON.stringify({
|
|
14
|
+
msg: message,
|
|
15
|
+
error: "log: fields not serializable"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const logger = {
|
|
20
|
+
error(message, fields) {
|
|
21
|
+
console.error(format(message, fields));
|
|
22
|
+
},
|
|
23
|
+
warn(message, fields) {
|
|
24
|
+
console.warn(format(message, fields));
|
|
25
|
+
},
|
|
26
|
+
info(message, fields) {
|
|
27
|
+
console.info(format(message, fields));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { logger };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MigrationEntry } from "./migration-handler.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/migration-handler-pg.d.ts
|
|
4
|
+
declare function createMigrationHandler(env: Record<string, unknown>, migrations: Array<MigrationEntry>, _dialect: "sqlite" | "postgresql", runAuthMigrations?: () => Promise<void>): (request: Request) => Promise<Response>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createMigrationHandler };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//#region src/runtime/migration-handler-pg.ts
|
|
2
|
+
function createMigrationHandler(env, migrations, _dialect, runAuthMigrations) {
|
|
3
|
+
return async (request) => {
|
|
4
|
+
const token = request.headers.get("x-void-internal");
|
|
5
|
+
if (!token || token !== env.__VOID_PROXY_TOKEN) return Response.json({
|
|
6
|
+
ok: false,
|
|
7
|
+
error: "unauthorized",
|
|
8
|
+
migrations: []
|
|
9
|
+
}, { status: 401 });
|
|
10
|
+
try {
|
|
11
|
+
const result = await runPgMigrations(env, migrations);
|
|
12
|
+
if (result.ok && runAuthMigrations) await runAuthMigrations();
|
|
13
|
+
return Response.json(result);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
return Response.json({
|
|
16
|
+
ok: false,
|
|
17
|
+
error: err instanceof Error ? err.message : String(err),
|
|
18
|
+
migrations: []
|
|
19
|
+
}, { status: 500 });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function runPgMigrations(env, migrations) {
|
|
24
|
+
const hyperdrive = env.HYPERDRIVE;
|
|
25
|
+
if (!hyperdrive?.connectionString) return {
|
|
26
|
+
ok: false,
|
|
27
|
+
error: "no HYPERDRIVE binding found",
|
|
28
|
+
migrations: []
|
|
29
|
+
};
|
|
30
|
+
const { Client } = await import("pg");
|
|
31
|
+
const client = new Client({ connectionString: hyperdrive.connectionString });
|
|
32
|
+
await client.connect();
|
|
33
|
+
try {
|
|
34
|
+
await client.query(`CREATE TABLE IF NOT EXISTS _void_migrations (
|
|
35
|
+
name TEXT PRIMARY KEY,
|
|
36
|
+
applied_at TEXT NOT NULL
|
|
37
|
+
)`);
|
|
38
|
+
const { rows } = await client.query("SELECT name FROM _void_migrations");
|
|
39
|
+
const applied = new Set(rows.map((r) => r.name));
|
|
40
|
+
const migrationResults = [];
|
|
41
|
+
for (const m of migrations) {
|
|
42
|
+
if (applied.has(m.name)) {
|
|
43
|
+
migrationResults.push({
|
|
44
|
+
name: m.name,
|
|
45
|
+
applied: false,
|
|
46
|
+
durationMs: 0
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const start = Date.now();
|
|
51
|
+
try {
|
|
52
|
+
await client.query("BEGIN");
|
|
53
|
+
await client.query(m.sql);
|
|
54
|
+
await client.query("INSERT INTO _void_migrations (name, applied_at) VALUES ($1, $2)", [m.name, (/* @__PURE__ */ new Date()).toISOString()]);
|
|
55
|
+
await client.query("COMMIT");
|
|
56
|
+
migrationResults.push({
|
|
57
|
+
name: m.name,
|
|
58
|
+
applied: true,
|
|
59
|
+
durationMs: Date.now() - start
|
|
60
|
+
});
|
|
61
|
+
} catch (err) {
|
|
62
|
+
await client.query("ROLLBACK");
|
|
63
|
+
migrationResults.push({
|
|
64
|
+
name: m.name,
|
|
65
|
+
applied: false,
|
|
66
|
+
durationMs: Date.now() - start,
|
|
67
|
+
error: err instanceof Error ? err.message : String(err)
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
migrations: migrationResults,
|
|
72
|
+
error: `migration ${m.name} failed`
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
ok: true,
|
|
78
|
+
migrations: migrationResults
|
|
79
|
+
};
|
|
80
|
+
} finally {
|
|
81
|
+
await client.end();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createMigrationHandler };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/runtime/migration-handler.d.ts
|
|
2
|
+
interface MigrationEntry {
|
|
3
|
+
name: string;
|
|
4
|
+
sql: string;
|
|
5
|
+
}
|
|
6
|
+
interface MigrationResult {
|
|
7
|
+
name: string;
|
|
8
|
+
applied: boolean;
|
|
9
|
+
durationMs: number;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
interface MigrationResponse {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
migrations: Array<MigrationResult>;
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
declare function createMigrationHandler(env: Record<string, unknown>, migrations: Array<MigrationEntry> | undefined, _dialect: "sqlite" | "postgresql", runAuthMigrations?: () => Promise<void>): (request: Request) => Promise<Response>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { MigrationEntry, MigrationResponse, MigrationResult, createMigrationHandler };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//#region src/runtime/migration-handler.ts
|
|
2
|
+
function createMigrationHandler(env, migrations, _dialect, runAuthMigrations) {
|
|
3
|
+
return async (request) => {
|
|
4
|
+
const token = request.headers.get("x-void-internal");
|
|
5
|
+
if (!token || token !== env.__VOID_PROXY_TOKEN) return Response.json({
|
|
6
|
+
ok: false,
|
|
7
|
+
error: "unauthorized",
|
|
8
|
+
migrations: []
|
|
9
|
+
}, { status: 401 });
|
|
10
|
+
try {
|
|
11
|
+
const db = env.DB;
|
|
12
|
+
if (!db) return Response.json({
|
|
13
|
+
ok: false,
|
|
14
|
+
error: "no D1 binding found",
|
|
15
|
+
migrations: []
|
|
16
|
+
}, { status: 500 });
|
|
17
|
+
const result = await runD1Migrations(db, migrations ?? []);
|
|
18
|
+
if (result.ok && runAuthMigrations) await runAuthMigrations();
|
|
19
|
+
return Response.json(result);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return Response.json({
|
|
22
|
+
ok: false,
|
|
23
|
+
error: err instanceof Error ? err.message : String(err),
|
|
24
|
+
migrations: []
|
|
25
|
+
}, { status: 500 });
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One-time migration: rename legacy `_migrations` table to `_void_migrations`.
|
|
31
|
+
* Copies all rows from the old table to the new one, then drops the old table.
|
|
32
|
+
*/
|
|
33
|
+
async function upgradeTrackingTable(db) {
|
|
34
|
+
const { results } = await db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='_migrations'").all();
|
|
35
|
+
if (!results || results.length === 0) return;
|
|
36
|
+
await db.batch([
|
|
37
|
+
db.prepare(`CREATE TABLE IF NOT EXISTS _void_migrations (
|
|
38
|
+
name TEXT PRIMARY KEY,
|
|
39
|
+
applied_at TEXT NOT NULL
|
|
40
|
+
)`),
|
|
41
|
+
db.prepare(`INSERT OR IGNORE INTO _void_migrations (name, applied_at) SELECT name, applied_at FROM _migrations`),
|
|
42
|
+
db.prepare(`DROP TABLE _migrations`)
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
async function runD1Migrations(db, migrations) {
|
|
46
|
+
await db.prepare(`CREATE TABLE IF NOT EXISTS _void_migrations (
|
|
47
|
+
name TEXT PRIMARY KEY,
|
|
48
|
+
applied_at TEXT NOT NULL
|
|
49
|
+
)`).run();
|
|
50
|
+
await upgradeTrackingTable(db);
|
|
51
|
+
const { results } = await db.prepare("SELECT name FROM _void_migrations").all();
|
|
52
|
+
const applied = new Set((results ?? []).map((r) => r.name));
|
|
53
|
+
const migrationResults = [];
|
|
54
|
+
for (const m of migrations) {
|
|
55
|
+
if (applied.has(m.name)) {
|
|
56
|
+
migrationResults.push({
|
|
57
|
+
name: m.name,
|
|
58
|
+
applied: false,
|
|
59
|
+
durationMs: 0
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const start = Date.now();
|
|
64
|
+
try {
|
|
65
|
+
const statements = m.sql.split(";").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
66
|
+
await db.batch([...statements.map((s) => db.prepare(s)), db.prepare("INSERT INTO _void_migrations (name, applied_at) VALUES (?, ?)").bind(m.name, (/* @__PURE__ */ new Date()).toISOString())]);
|
|
67
|
+
migrationResults.push({
|
|
68
|
+
name: m.name,
|
|
69
|
+
applied: true,
|
|
70
|
+
durationMs: Date.now() - start
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
migrationResults.push({
|
|
74
|
+
name: m.name,
|
|
75
|
+
applied: false,
|
|
76
|
+
durationMs: Date.now() - start,
|
|
77
|
+
error: err instanceof Error ? err.message : String(err)
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
migrations: migrationResults,
|
|
82
|
+
error: `migration ${m.name} failed`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
migrations: migrationResults
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { createMigrationHandler };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/runtime/queues.d.ts
|
|
2
|
+
/** Stub interface augmented by generated .void/queues.d.ts */
|
|
3
|
+
interface QueueMap {}
|
|
4
|
+
/** Typed queue producers — resolves `QUEUE_*` bindings from the active runtime environment. */
|
|
5
|
+
declare const queues: QueueMap;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { QueueMap, queues };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { requireRuntimeBinding } from "./env.mjs";
|
|
2
|
+
//#region src/runtime/queues.ts
|
|
3
|
+
/** Typed queue producers — resolves `QUEUE_*` bindings from the active runtime environment. */
|
|
4
|
+
const queues = new Proxy({}, { get(_, name) {
|
|
5
|
+
return requireRuntimeBinding(`QUEUE_${name.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`);
|
|
6
|
+
} });
|
|
7
|
+
//#endregion
|
|
8
|
+
export { queues };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/remote/binding-handler.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Hono app that handles `/__void/*` routes for native binding access.
|
|
6
|
+
* Deployed user workers expose this so the proxy can dispatch D1/KV/R2 operations
|
|
7
|
+
* via Workers for Platforms instead of the Cloudflare REST API (~1-5ms vs ~50-200ms).
|
|
8
|
+
*
|
|
9
|
+
* Authenticated via `x-void-internal` header against `env.__VOID_PROXY_TOKEN`.
|
|
10
|
+
* Response formats match the proxy's existing REST API responses so the
|
|
11
|
+
* ProxyClient doesn't need changes.
|
|
12
|
+
*/
|
|
13
|
+
declare function createBindingHandler(env: Record<string, unknown>): Hono;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createBindingHandler };
|