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,366 @@
|
|
|
1
|
+
import { i as getRawRuntimeEnv } from "../env-raw-BDL4TvdN.mjs";
|
|
2
|
+
import { getRuntimeEnv } from "./env.mjs";
|
|
3
|
+
import { boolean, email, getSecretOverride, json, number, oneOf, string, url } from "./env-helpers.mjs";
|
|
4
|
+
//#region src/shared/env-mask.ts
|
|
5
|
+
/**
|
|
6
|
+
* Secret redaction helpers for env-validation output.
|
|
7
|
+
*
|
|
8
|
+
* Values are redacted (replaced with `<redacted>`) whenever they flow into
|
|
9
|
+
* a user-visible string — `EnvValidationError` messages, CLI reports, the
|
|
10
|
+
* dev-server warning block. The key name is never masked (the user needs
|
|
11
|
+
* it to locate the offending entry).
|
|
12
|
+
*
|
|
13
|
+
* Redaction is belt-and-braces:
|
|
14
|
+
* 1. An explicit `.secret()` / `.public()` flag on a schema entry wins.
|
|
15
|
+
* 2. Otherwise, a key-name regex (`KEY|TOKEN|SECRET|…`) redacts anything
|
|
16
|
+
* that looks like credentials.
|
|
17
|
+
* 3. Even on non-secret keys, a value that itself looks high-entropy
|
|
18
|
+
* (`sk_…`, `ghp_…`, ≥24 characters of mixed alphanumerics) is redacted
|
|
19
|
+
* — catches wrong-file typos like `PORT=sk_live_abc123`.
|
|
20
|
+
*
|
|
21
|
+
* Users can opt out of the guard for local debugging via
|
|
22
|
+
* `VOID_ENV_UNMASK=1` in the environment; that path prints a one-shot
|
|
23
|
+
* notice on stderr so the loosened output is visibly attributed.
|
|
24
|
+
*
|
|
25
|
+
* This module is a leaf — no imports from non-leaf modules, safe to reach
|
|
26
|
+
* from both the runtime (worker bundle) and the CLI host.
|
|
27
|
+
*/
|
|
28
|
+
/** Sentinel emitted in place of a redacted value. */
|
|
29
|
+
const REDACTED = "<redacted>";
|
|
30
|
+
/** Environment variable that disables redaction when set to `1`. */
|
|
31
|
+
const UNMASK_ENV_VAR = "VOID_ENV_UNMASK";
|
|
32
|
+
/**
|
|
33
|
+
* Regex matching env key names that almost always carry secrets.
|
|
34
|
+
* Case-insensitive; matched as a substring anywhere in the key.
|
|
35
|
+
*/
|
|
36
|
+
const SECRET_KEY_RE = /KEY|TOKEN|SECRET|PASSWORD|PASS(WD)?|CREDENTIAL|PRIVATE|AUTH|BEARER|APIKEY|DSN/i;
|
|
37
|
+
/** Common secret value prefixes (Stripe, GitHub, Slack, AWS, …). */
|
|
38
|
+
const SECRET_VALUE_PREFIX_RE = /^(sk|pk|ghp|xoxb|AKIA)/i;
|
|
39
|
+
/** High-entropy alphanumeric string of ≥24 chars. */
|
|
40
|
+
const HIGH_ENTROPY_RE = /^[A-Za-z0-9_\-+/=.:]{24,}$/;
|
|
41
|
+
/** `true` when the key name heuristically denotes a secret. */
|
|
42
|
+
function isLikelySecretKey(name) {
|
|
43
|
+
return SECRET_KEY_RE.test(name);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `true` when the value looks like a credential regardless of key name.
|
|
47
|
+
* Err on the side of redacting — a false positive hides one non-secret
|
|
48
|
+
* debugging hint, a false negative pastes a token into a GitHub issue.
|
|
49
|
+
*/
|
|
50
|
+
function isLikelySecretValue(value) {
|
|
51
|
+
if (typeof value !== "string" || value.length === 0) return false;
|
|
52
|
+
return SECRET_VALUE_PREFIX_RE.test(value) || HIGH_ENTROPY_RE.test(value);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Redact every occurrence of `raw` inside a validator-produced `message`
|
|
56
|
+
* when the key should be masked. Built-in helpers embed the raw value in
|
|
57
|
+
* their error strings (e.g. `Expected a number, got "not-a-number"`); we
|
|
58
|
+
* scrub those after the fact so third-party Standard Schema libraries —
|
|
59
|
+
* which have their own message format — also get reasonable redaction as
|
|
60
|
+
* long as the offending value was a secret-looking literal.
|
|
61
|
+
*/
|
|
62
|
+
function redactMessage(key, rawValue, message, options = {}) {
|
|
63
|
+
if (options.unmask) return message;
|
|
64
|
+
if (!(options.override === "secret" || options.override !== "public" && (isLikelySecretKey(key) || isLikelySecretValue(rawValue)))) return message;
|
|
65
|
+
if (typeof rawValue !== "string" || rawValue.length === 0) return message;
|
|
66
|
+
return message.split(rawValue).join(REDACTED);
|
|
67
|
+
}
|
|
68
|
+
let unmaskResolved = null;
|
|
69
|
+
let unmaskNoticeShown = false;
|
|
70
|
+
/**
|
|
71
|
+
* Resolve the effective unmask flag, consulting `process.env` exactly once
|
|
72
|
+
* per process. On the first affirmative read, we print a one-shot notice to
|
|
73
|
+
* stderr so CI logs clearly show the guard is off.
|
|
74
|
+
*/
|
|
75
|
+
function isUnmaskActive() {
|
|
76
|
+
if (unmaskResolved !== null) return unmaskResolved;
|
|
77
|
+
let active = false;
|
|
78
|
+
try {
|
|
79
|
+
active = globalThis.process?.env?.[UNMASK_ENV_VAR] === "1";
|
|
80
|
+
} catch {
|
|
81
|
+
active = false;
|
|
82
|
+
}
|
|
83
|
+
unmaskResolved = active;
|
|
84
|
+
if (active && !unmaskNoticeShown) {
|
|
85
|
+
unmaskNoticeShown = true;
|
|
86
|
+
try {
|
|
87
|
+
console.error(`[void/env] ${UNMASK_ENV_VAR}=1 is set — env validation errors will include raw values. Unset it before sharing logs.`);
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
return active;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/runtime/env-public.ts
|
|
94
|
+
/**
|
|
95
|
+
* Public env API — `void/env`.
|
|
96
|
+
*
|
|
97
|
+
* Canonical usage:
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* // env.ts at project root
|
|
101
|
+
* import { defineEnv, string, number, oneOf } from "void/env";
|
|
102
|
+
*
|
|
103
|
+
* export default defineEnv({
|
|
104
|
+
* STRIPE_KEY: string(),
|
|
105
|
+
* PORT: number().default(3000),
|
|
106
|
+
* NODE_ENV: oneOf(["development", "production"]),
|
|
107
|
+
* VITE_APP_TITLE: string(),
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // anywhere else
|
|
111
|
+
* import { env } from "void/env";
|
|
112
|
+
* env.STRIPE_KEY;
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* The `env` proxy reads from the underlying runtime env (Cloudflare worker
|
|
116
|
+
* bindings, Node `process.env`, Nuxt globals, etc.) via `getRuntimeEnv()`,
|
|
117
|
+
* and validates each key on first access using the registered schema.
|
|
118
|
+
*
|
|
119
|
+
* Bindings (`DB`, `KV`, `STORAGE`, `AI`, queue handlers) and other env keys
|
|
120
|
+
* not declared in the schema pass through unchanged.
|
|
121
|
+
*/
|
|
122
|
+
let registeredSchema = null;
|
|
123
|
+
let hasDefineEnvBeenCalled = false;
|
|
124
|
+
const validatedCache = /* @__PURE__ */ new WeakMap();
|
|
125
|
+
/**
|
|
126
|
+
* Register an env schema and return the typed `env` proxy.
|
|
127
|
+
*
|
|
128
|
+
* Calling `defineEnv` is the only required step — Void auto-discovers
|
|
129
|
+
* `env.ts` at project root, imports it, and uses the schema for runtime
|
|
130
|
+
* validation, type generation, and deploy-time secret checks.
|
|
131
|
+
*
|
|
132
|
+
* The return value is identical to the `env` export from `void/env`.
|
|
133
|
+
* Re-export it from your `env.ts` if you prefer the explicit
|
|
134
|
+
* `import { env } from "~/env"` pattern.
|
|
135
|
+
*/
|
|
136
|
+
function defineEnv(schema) {
|
|
137
|
+
registeredSchema = schema;
|
|
138
|
+
hasDefineEnvBeenCalled = true;
|
|
139
|
+
for (const map of validatedCacheValues()) map.clear();
|
|
140
|
+
bootValidationState = null;
|
|
141
|
+
return env;
|
|
142
|
+
}
|
|
143
|
+
let bootValidationState = null;
|
|
144
|
+
/**
|
|
145
|
+
* Internal: validate the entire schema against the worker's actual env on
|
|
146
|
+
* the first request per isolate. Catches bad remote-secret values and
|
|
147
|
+
* post-deploy drift that the deploy CLI can't see (it only knows secret
|
|
148
|
+
* names, not their values).
|
|
149
|
+
*
|
|
150
|
+
* Spliced into the generated worker entry by `compileWorkerEntry`. Cached
|
|
151
|
+
* after the first call so subsequent requests pay no cost.
|
|
152
|
+
*
|
|
153
|
+
* Async lifecycle: this function awaits any async Standard Schema
|
|
154
|
+
* validators (zod `refine`, arktype async narrows, etc.) and seeds the
|
|
155
|
+
* per-key cache with the resolved values. Subsequent reads via `env.X`
|
|
156
|
+
* hit the sync cache — async work only happens here, at boot. If a user
|
|
157
|
+
* accesses `env.X` for a key with an async validator *before* this
|
|
158
|
+
* function has run (e.g. during module-top-level code), the proxy will
|
|
159
|
+
* throw with guidance pointing back to this boot-time pre-validation.
|
|
160
|
+
*/
|
|
161
|
+
async function _validateEnvOnce(envValues) {
|
|
162
|
+
if (bootValidationState) {
|
|
163
|
+
if (!bootValidationState.ok) throw bootValidationState.error;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!registeredSchema) {
|
|
167
|
+
bootValidationState = { ok: true };
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const report = await validateAllEnvWithValues(registeredSchema, envValues ?? {});
|
|
171
|
+
if (report.valid) {
|
|
172
|
+
try {
|
|
173
|
+
const cacheKey = getRawRuntimeEnv();
|
|
174
|
+
let cache = validatedCache.get(cacheKey);
|
|
175
|
+
if (!cache) {
|
|
176
|
+
cache = /* @__PURE__ */ new Map();
|
|
177
|
+
validatedCache.set(cacheKey, cache);
|
|
178
|
+
cacheList.push(cache);
|
|
179
|
+
}
|
|
180
|
+
for (const [key, value] of report.values) if (!cache.has(key)) cache.set(key, value);
|
|
181
|
+
} catch {}
|
|
182
|
+
bootValidationState = { ok: true };
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const lines = ["Env validation failed at worker boot:"];
|
|
186
|
+
for (const key of report.missing) lines.push(` • ${key} is required but missing`);
|
|
187
|
+
for (const { key, messages } of report.invalid) lines.push(` • ${key}: ${messages.join("; ")}`);
|
|
188
|
+
const error = new EnvValidationError("__init__", [{ message: lines.join("\n") }]);
|
|
189
|
+
bootValidationState = {
|
|
190
|
+
ok: false,
|
|
191
|
+
error
|
|
192
|
+
};
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
function validatedCacheValues() {
|
|
196
|
+
return cacheList;
|
|
197
|
+
}
|
|
198
|
+
const cacheList = [];
|
|
199
|
+
/** Internal: framework-only access to the registered schema (for plugin/CLI). */
|
|
200
|
+
function _getRegisteredSchema() {
|
|
201
|
+
return registeredSchema;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Internal: returns `true` once `defineEnv()` has been called at least once,
|
|
205
|
+
* regardless of whether the caller passed an empty schema. Gives tooling a
|
|
206
|
+
* reliable signal — `_getRegisteredSchema()` alone can't distinguish
|
|
207
|
+
* `defineEnv({})` (an intentional empty schema) from "never called".
|
|
208
|
+
*/
|
|
209
|
+
function _hasRegisteredSchema() {
|
|
210
|
+
return hasDefineEnvBeenCalled;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Internal: extract `.default(value)` values from the registered schema as
|
|
214
|
+
* stringified env values. Used by the plugin and deploy CLI to seed worker
|
|
215
|
+
* `vars` so `c.env.X` and `process.env.X` see the same fallback that the
|
|
216
|
+
* typed `env.X` proxy returns.
|
|
217
|
+
*
|
|
218
|
+
* Detection is schema-agnostic: probe each validator with `undefined` and,
|
|
219
|
+
* if it succeeds with a non-undefined value, that value is the default.
|
|
220
|
+
* Works for our built-in `.default(...)` helpers and for any Standard
|
|
221
|
+
* Schema validator with intrinsic default behaviour. Async validators are
|
|
222
|
+
* skipped (we can't get a sync default).
|
|
223
|
+
*
|
|
224
|
+
* Keys with no default — required keys, plain `.optional()` — are omitted
|
|
225
|
+
* from the result so they don't shadow user `.env*` entries with empty
|
|
226
|
+
* strings.
|
|
227
|
+
*/
|
|
228
|
+
function _getSchemaDefaults() {
|
|
229
|
+
const defaults = {};
|
|
230
|
+
if (!registeredSchema) return defaults;
|
|
231
|
+
for (const [key, validator] of Object.entries(registeredSchema)) {
|
|
232
|
+
let result;
|
|
233
|
+
try {
|
|
234
|
+
result = validator["~standard"].validate(void 0);
|
|
235
|
+
} catch {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (result instanceof Promise) continue;
|
|
239
|
+
const r = result;
|
|
240
|
+
if (r.issues) continue;
|
|
241
|
+
if (r.value === void 0 || r.value === null) continue;
|
|
242
|
+
defaults[key] = typeof r.value === "string" ? r.value : String(r.value);
|
|
243
|
+
}
|
|
244
|
+
return defaults;
|
|
245
|
+
}
|
|
246
|
+
var EnvValidationError = class extends Error {
|
|
247
|
+
constructor(key, issues) {
|
|
248
|
+
super(`Invalid env "${key}": ${issues.map((i) => i.message).join(", ")}`);
|
|
249
|
+
this.key = key;
|
|
250
|
+
this.issues = issues;
|
|
251
|
+
this.name = "EnvValidationError";
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
function readKey(key) {
|
|
255
|
+
const rawValue = getRuntimeEnv()[key];
|
|
256
|
+
if (!registeredSchema) return rawValue;
|
|
257
|
+
const validator = registeredSchema[key];
|
|
258
|
+
if (!validator) return rawValue;
|
|
259
|
+
const cacheKey = getRawRuntimeEnv();
|
|
260
|
+
let cache = validatedCache.get(cacheKey);
|
|
261
|
+
if (!cache) {
|
|
262
|
+
cache = /* @__PURE__ */ new Map();
|
|
263
|
+
validatedCache.set(cacheKey, cache);
|
|
264
|
+
cacheList.push(cache);
|
|
265
|
+
}
|
|
266
|
+
if (cache.has(key)) return cache.get(key);
|
|
267
|
+
const result = validator["~standard"].validate(rawValue);
|
|
268
|
+
if (result instanceof Promise) throw new Error(`env: Async validator for '${key}' cannot be resolved synchronously. Proxy property access is synchronous, so async Standard Schema validators must be pre-resolved by calling \`_validateEnvOnce(env)\` at worker boot (Void splices this into the generated entry) or by awaiting \`validateAllEnv(env)\` before the first \`env.${key}\` read. Once pre-validated, the resolved value is cached and served synchronously here.`);
|
|
269
|
+
if (result.issues) {
|
|
270
|
+
const unmask = isUnmaskActive();
|
|
271
|
+
const override = getSecretOverride(validator);
|
|
272
|
+
throw new EnvValidationError(key, result.issues.map((i) => ({
|
|
273
|
+
...i,
|
|
274
|
+
message: redactMessage(key, rawValue, i.message, {
|
|
275
|
+
override,
|
|
276
|
+
unmask
|
|
277
|
+
})
|
|
278
|
+
})));
|
|
279
|
+
}
|
|
280
|
+
cache.set(key, result.value);
|
|
281
|
+
return result.value;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Typed env proxy. Reads from the runtime env, validating declared keys
|
|
285
|
+
* on first access and passing through bindings / unknown keys unchanged.
|
|
286
|
+
*
|
|
287
|
+
* Sync-only: the `get` trap must be synchronous, so validators that return
|
|
288
|
+
* a `Promise` cannot be awaited here. For async Standard Schema validators,
|
|
289
|
+
* `_validateEnvOnce()` pre-resolves them at worker boot and seeds the
|
|
290
|
+
* per-env cache; property reads then serve the cached value synchronously.
|
|
291
|
+
* If an async validator is encountered here without a prior pre-validation,
|
|
292
|
+
* the trap throws with guidance on how to resolve it.
|
|
293
|
+
*/
|
|
294
|
+
const env = new Proxy({}, {
|
|
295
|
+
get(_target, key) {
|
|
296
|
+
if (typeof key === "symbol") return;
|
|
297
|
+
return readKey(key);
|
|
298
|
+
},
|
|
299
|
+
has(_target, key) {
|
|
300
|
+
if (typeof key === "symbol") return false;
|
|
301
|
+
return Reflect.has(getRuntimeEnv(), key);
|
|
302
|
+
},
|
|
303
|
+
ownKeys() {
|
|
304
|
+
return Reflect.ownKeys(getRuntimeEnv());
|
|
305
|
+
},
|
|
306
|
+
getOwnPropertyDescriptor(_target, key) {
|
|
307
|
+
if (typeof key === "symbol") return;
|
|
308
|
+
return {
|
|
309
|
+
enumerable: true,
|
|
310
|
+
configurable: true,
|
|
311
|
+
value: readKey(String(key))
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
/**
|
|
316
|
+
* Validate an env record (e.g. merged `.env*` + remote secret list) against
|
|
317
|
+
* the registered schema. Used by the dev plugin (warnings), the deploy CLI
|
|
318
|
+
* (hard error), and `_validateEnvOnce` at worker boot.
|
|
319
|
+
*
|
|
320
|
+
* Async: awaits any validators that return a `Promise` (zod async refines,
|
|
321
|
+
* arktype narrows, etc.). Callers already run in async contexts.
|
|
322
|
+
*/
|
|
323
|
+
async function validateAllEnv(envValues) {
|
|
324
|
+
if (!registeredSchema) return {
|
|
325
|
+
valid: true,
|
|
326
|
+
missing: [],
|
|
327
|
+
invalid: [],
|
|
328
|
+
values: /* @__PURE__ */ new Map()
|
|
329
|
+
};
|
|
330
|
+
return await validateAllEnvWithValues(registeredSchema, envValues);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Internal: shared core that validates a schema against values and also
|
|
334
|
+
* returns the resolved values (for cache seeding).
|
|
335
|
+
*/
|
|
336
|
+
async function validateAllEnvWithValues(schema, envValues) {
|
|
337
|
+
const report = {
|
|
338
|
+
valid: true,
|
|
339
|
+
missing: [],
|
|
340
|
+
invalid: [],
|
|
341
|
+
values: /* @__PURE__ */ new Map()
|
|
342
|
+
};
|
|
343
|
+
const unmask = isUnmaskActive();
|
|
344
|
+
for (const [key, validator] of Object.entries(schema)) {
|
|
345
|
+
const raw = envValues[key];
|
|
346
|
+
const resultMaybe = validator["~standard"].validate(raw);
|
|
347
|
+
const result = resultMaybe instanceof Promise ? await resultMaybe : resultMaybe;
|
|
348
|
+
if (result.issues) {
|
|
349
|
+
report.valid = false;
|
|
350
|
+
if (raw === void 0 || raw === null || raw === "") report.missing.push(key);
|
|
351
|
+
else {
|
|
352
|
+
const override = getSecretOverride(validator);
|
|
353
|
+
report.invalid.push({
|
|
354
|
+
key,
|
|
355
|
+
messages: result.issues.map((i) => redactMessage(key, raw, i.message, {
|
|
356
|
+
override,
|
|
357
|
+
unmask
|
|
358
|
+
}))
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
} else report.values.set(key, result.value);
|
|
362
|
+
}
|
|
363
|
+
return report;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
export { EnvValidationError, _getRegisteredSchema, _getSchemaDefaults, _hasRegisteredSchema, _validateEnvOnce, boolean, defineEnv, email, env, json, number, oneOf, string, url, validateAllEnv };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/env-raw.d.ts
|
|
4
|
+
type RuntimeEnv = Record<string, unknown>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/runtime/env.d.ts
|
|
7
|
+
declare function withRuntimeEnv<T>(env: unknown, fn: () => T): T;
|
|
8
|
+
/** Returns the runtime env with internal platform bindings hidden. */
|
|
9
|
+
declare function getRuntimeEnv(): RuntimeEnv;
|
|
10
|
+
declare function getRuntimeBinding<T = unknown>(name: string): T | undefined;
|
|
11
|
+
declare function requireRuntimeBinding<T = unknown>(name: string): T;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { type RuntimeEnv, getRuntimeBinding, getRuntimeEnv, requireRuntimeBinding, withRuntimeEnv };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { i as getRawRuntimeEnv, n as asEnv, r as envContext, t as INTERNAL_BINDING_PREFIXES } from "../env-raw-BDL4TvdN.mjs";
|
|
2
|
+
//#region src/runtime/env.ts
|
|
3
|
+
/**
|
|
4
|
+
* Public runtime env API — exposed via "void/_env".
|
|
5
|
+
*
|
|
6
|
+
* All exports from this module are accessible to user code.
|
|
7
|
+
* Internal platform bindings (__VOID_*, __PROJECT_*) are filtered
|
|
8
|
+
* from getRuntimeEnv() and blocked in getRuntimeBinding().
|
|
9
|
+
*/
|
|
10
|
+
function withRuntimeEnv(env, fn) {
|
|
11
|
+
const resolved = asEnv(env);
|
|
12
|
+
if (!resolved) return fn();
|
|
13
|
+
return envContext.run(resolved, fn);
|
|
14
|
+
}
|
|
15
|
+
function isInternalBinding(name) {
|
|
16
|
+
return INTERNAL_BINDING_PREFIXES.some((p) => name.startsWith(p));
|
|
17
|
+
}
|
|
18
|
+
function filterEnvProxy(env) {
|
|
19
|
+
return new Proxy(env, {
|
|
20
|
+
get(target, prop, receiver) {
|
|
21
|
+
if (typeof prop === "string" && isInternalBinding(prop)) return;
|
|
22
|
+
return Reflect.get(target, prop, receiver);
|
|
23
|
+
},
|
|
24
|
+
has(target, prop) {
|
|
25
|
+
if (typeof prop === "string" && isInternalBinding(prop)) return false;
|
|
26
|
+
return Reflect.has(target, prop);
|
|
27
|
+
},
|
|
28
|
+
ownKeys(target) {
|
|
29
|
+
return Reflect.ownKeys(target).filter((key) => typeof key !== "string" || !isInternalBinding(key));
|
|
30
|
+
},
|
|
31
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
32
|
+
if (typeof prop === "string" && isInternalBinding(prop)) return;
|
|
33
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Returns the runtime env with internal platform bindings hidden. */
|
|
38
|
+
function getRuntimeEnv() {
|
|
39
|
+
return filterEnvProxy(getRawRuntimeEnv());
|
|
40
|
+
}
|
|
41
|
+
function getRuntimeBinding(name) {
|
|
42
|
+
if (isInternalBinding(name)) return;
|
|
43
|
+
return getRawRuntimeEnv()[name];
|
|
44
|
+
}
|
|
45
|
+
function requireRuntimeBinding(name) {
|
|
46
|
+
const value = getRuntimeBinding(name);
|
|
47
|
+
if (value !== void 0 && value !== null) return value;
|
|
48
|
+
throw new Error(`env: Missing Cloudflare binding '${name}'.`);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { getRuntimeBinding, getRuntimeEnv, requireRuntimeBinding, withRuntimeEnv };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { t as FetchError } from "../fetch-error-CVZ5CGA-.mjs";
|
|
2
|
+
import { RouteMap } from "void/routes";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/fetch-stream.d.ts
|
|
5
|
+
type MethodsOf<P extends keyof RouteMap> = keyof RouteMap[P] & string;
|
|
6
|
+
type InputOf<P extends keyof RouteMap, M extends MethodsOf<P>> = RouteMap[P][M] extends {
|
|
7
|
+
input: infer I;
|
|
8
|
+
} ? I : {};
|
|
9
|
+
type BodyOption<I> = "body" extends keyof I ? {
|
|
10
|
+
body: I["body" & keyof I];
|
|
11
|
+
} : {
|
|
12
|
+
body?: Record<string, unknown> | BodyInit | null;
|
|
13
|
+
};
|
|
14
|
+
type QueryOption<I> = "query" extends keyof I ? {
|
|
15
|
+
query: I["query" & keyof I];
|
|
16
|
+
} : {
|
|
17
|
+
query?: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
type ParamsOption<I> = "params" extends keyof I ? {
|
|
20
|
+
params: I["params" & keyof I];
|
|
21
|
+
} : {
|
|
22
|
+
params?: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
type StreamOptions<P extends keyof RouteMap, M extends MethodsOf<P>> = BodyOption<InputOf<P, M>> & QueryOption<InputOf<P, M>> & ParamsOption<InputOf<P, M>> & {
|
|
25
|
+
method?: M;
|
|
26
|
+
headers?: HeadersInit;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Consume an SSE endpoint as an async generator of text chunks.
|
|
32
|
+
*
|
|
33
|
+
* Parses Workers AI SSE format (`data: {"response":"chunk"}` + `data: [DONE]`)
|
|
34
|
+
* and plain text SSE (`data: some text`).
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { fetchStream } from "void/client";
|
|
38
|
+
*
|
|
39
|
+
* for await (const chunk of fetchStream("/api/ai/chat", {
|
|
40
|
+
* method: "POST",
|
|
41
|
+
* body: { messages: [{ role: "user", content: "Hello" }] },
|
|
42
|
+
* })) {
|
|
43
|
+
* output += chunk;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @yields {string} Text chunks from SSE data frames.
|
|
48
|
+
*/
|
|
49
|
+
declare function fetchStream<P extends keyof RouteMap & string, M extends MethodsOf<P> = ("POST" extends MethodsOf<P> ? "POST" : MethodsOf<P>)>(path: P, options?: StreamOptions<P, M>): AsyncGenerator<string, void, undefined>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { FetchError as StreamError, fetchStream };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { n as ofetch, t as FetchError } from "../fetch-error-BQ8sZ5Nd.mjs";
|
|
2
|
+
//#region src/runtime/fetch-stream.ts
|
|
3
|
+
/**
|
|
4
|
+
* Consume an SSE endpoint as an async generator of text chunks.
|
|
5
|
+
*
|
|
6
|
+
* Parses Workers AI SSE format (`data: {"response":"chunk"}` + `data: [DONE]`)
|
|
7
|
+
* and plain text SSE (`data: some text`).
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { fetchStream } from "void/client";
|
|
11
|
+
*
|
|
12
|
+
* for await (const chunk of fetchStream("/api/ai/chat", {
|
|
13
|
+
* method: "POST",
|
|
14
|
+
* body: { messages: [{ role: "user", content: "Hello" }] },
|
|
15
|
+
* })) {
|
|
16
|
+
* output += chunk;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @yields {string} Text chunks from SSE data frames.
|
|
21
|
+
*/
|
|
22
|
+
async function* fetchStream(path, options) {
|
|
23
|
+
let url = path;
|
|
24
|
+
if (options?.params) for (const [key, value] of Object.entries(options.params)) url = url.replace(`:${key}`, encodeURIComponent(value));
|
|
25
|
+
const body = (await ofetch.raw(url, {
|
|
26
|
+
method: options?.method ?? "POST",
|
|
27
|
+
body: options?.body,
|
|
28
|
+
query: options?.query,
|
|
29
|
+
headers: options?.headers,
|
|
30
|
+
signal: options?.signal,
|
|
31
|
+
baseURL: options?.baseURL,
|
|
32
|
+
responseType: "stream"
|
|
33
|
+
}))._data;
|
|
34
|
+
if (!body) return;
|
|
35
|
+
const reader = body.getReader();
|
|
36
|
+
const decoder = new TextDecoder();
|
|
37
|
+
let buffer = "";
|
|
38
|
+
try {
|
|
39
|
+
while (true) {
|
|
40
|
+
const { done, value } = await reader.read();
|
|
41
|
+
if (done) break;
|
|
42
|
+
buffer += decoder.decode(value, { stream: true });
|
|
43
|
+
const lines = buffer.split("\n");
|
|
44
|
+
buffer = lines.pop();
|
|
45
|
+
for (const line of lines) {
|
|
46
|
+
const trimmed = line.trim();
|
|
47
|
+
if (!trimmed || trimmed.startsWith(":")) continue;
|
|
48
|
+
if (trimmed.startsWith("data: ")) {
|
|
49
|
+
const data = trimmed.slice(6);
|
|
50
|
+
if (data === "[DONE]") return;
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(data);
|
|
53
|
+
if (typeof parsed.response === "string") {
|
|
54
|
+
yield parsed.response;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if ("response" in parsed) continue;
|
|
58
|
+
} catch {}
|
|
59
|
+
yield data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (buffer.trim()) {
|
|
64
|
+
const trimmed = buffer.trim();
|
|
65
|
+
if (trimmed.startsWith("data: ")) {
|
|
66
|
+
const data = trimmed.slice(6);
|
|
67
|
+
if (data !== "[DONE]") try {
|
|
68
|
+
const parsed = JSON.parse(data);
|
|
69
|
+
if (typeof parsed.response === "string") yield parsed.response;
|
|
70
|
+
else if (!("response" in parsed)) yield data;
|
|
71
|
+
} catch {
|
|
72
|
+
yield data;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} finally {
|
|
77
|
+
reader.releaseLock();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { FetchError as StreamError, fetchStream };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { t as FetchError } from "../fetch-error-CVZ5CGA-.mjs";
|
|
2
|
+
import { RouteMap } from "void/routes";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/fetch.d.ts
|
|
5
|
+
type MethodsOf<P extends keyof RouteMap> = keyof RouteMap[P] & string;
|
|
6
|
+
type DefaultMethod<P extends keyof RouteMap> = "GET" extends MethodsOf<P> ? "GET" : never;
|
|
7
|
+
type RouteEntry<P extends keyof RouteMap, M extends MethodsOf<P>> = RouteMap[P][M] extends {
|
|
8
|
+
input: infer I;
|
|
9
|
+
output: infer O;
|
|
10
|
+
} ? {
|
|
11
|
+
input: I;
|
|
12
|
+
output: O;
|
|
13
|
+
} : {
|
|
14
|
+
input: {};
|
|
15
|
+
output: unknown;
|
|
16
|
+
};
|
|
17
|
+
type OutputOf<P extends keyof RouteMap, M extends MethodsOf<P>> = RouteEntry<P, M>["output"];
|
|
18
|
+
type InputOf<P extends keyof RouteMap, M extends MethodsOf<P>> = RouteEntry<P, M>["input"];
|
|
19
|
+
type BodyOption<I> = "body" extends keyof I ? {
|
|
20
|
+
body: I["body" & keyof I];
|
|
21
|
+
} : {
|
|
22
|
+
body?: Record<string, unknown> | BodyInit | null;
|
|
23
|
+
};
|
|
24
|
+
type QueryOption<I> = "query" extends keyof I ? {
|
|
25
|
+
query: I["query" & keyof I];
|
|
26
|
+
} : {
|
|
27
|
+
query?: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
type ParamsOption<I> = "params" extends keyof I ? {
|
|
30
|
+
params: I["params" & keyof I];
|
|
31
|
+
} : {
|
|
32
|
+
params?: Record<string, string>;
|
|
33
|
+
};
|
|
34
|
+
type HasRequiredInput<P extends keyof RouteMap, M extends MethodsOf<P>> = "body" extends keyof InputOf<P, M> ? true : "query" extends keyof InputOf<P, M> ? true : "params" extends keyof InputOf<P, M> ? true : false;
|
|
35
|
+
type FetchOptions<P extends keyof RouteMap, M extends MethodsOf<P>> = BodyOption<InputOf<P, M>> & QueryOption<InputOf<P, M>> & ParamsOption<InputOf<P, M>> & {
|
|
36
|
+
method?: M;
|
|
37
|
+
headers?: HeadersInit;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
baseURL?: string;
|
|
40
|
+
retry?: number;
|
|
41
|
+
timeout?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Typed fetch client for Void API routes.
|
|
45
|
+
*
|
|
46
|
+
* Built on top of ofetch. Supports baseURL, retry, timeout, and all
|
|
47
|
+
* ofetch features while providing full route type safety.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { fetch } from "void/client";
|
|
51
|
+
*
|
|
52
|
+
* const users = await fetch("/api/users"); // typed!
|
|
53
|
+
* const user = await fetch("/api/users/:id", { params: { id: "1" } });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function fetch<P extends keyof RouteMap & string>(path: HasRequiredInput<P, DefaultMethod<P>> extends false ? P : never): Promise<OutputOf<P, DefaultMethod<P>>>;
|
|
57
|
+
declare function fetch<P extends keyof RouteMap & string, M extends MethodsOf<P> = DefaultMethod<P>>(path: P, options: FetchOptions<P, M>): Promise<OutputOf<P, M>>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { FetchError, fetch };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { n as ofetch, t as FetchError } from "../fetch-error-BQ8sZ5Nd.mjs";
|
|
2
|
+
//#region src/runtime/fetch.ts
|
|
3
|
+
async function fetch(path, options) {
|
|
4
|
+
let url = path;
|
|
5
|
+
if (options?.params) for (const [key, value] of Object.entries(options.params)) url = url.replace(`:${key}`, encodeURIComponent(value));
|
|
6
|
+
return ofetch(url, {
|
|
7
|
+
method: options?.method ?? "GET",
|
|
8
|
+
body: options?.body,
|
|
9
|
+
query: options?.query,
|
|
10
|
+
headers: options?.headers,
|
|
11
|
+
signal: options?.signal,
|
|
12
|
+
baseURL: options?.baseURL,
|
|
13
|
+
retry: options?.retry,
|
|
14
|
+
timeout: options?.timeout
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FetchError, fetch };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import { C as HandlerInput, S as ValidationError, _ as defineScheduled, a as QueueBatch, b as InferProps, c as RenderAssetTags, d as VoidAssetRewriteError, f as defineHandler, g as defineRender, h as defineQueue, i as CloudEnv, l as TypedHandler, m as defineMiddleware, n as CloudContext, o as QueueMessage, p as defineHead, r as CloudContextVariables, s as QueueRetryOptions, t as CloudBindings, u as TypedQueueHandler, v as Deferred, w as ValidatorSlots, x as defer } from "../handler-B0ds0OHJ.mjs";
|
|
3
|
+
export { CloudBindings, CloudContext, CloudContextVariables, CloudEnv, Deferred, HandlerInput, InferProps, QueueBatch, QueueMessage, QueueRetryOptions, RenderAssetTags, TypedHandler, TypedQueueHandler, ValidationError, ValidatorSlots, VoidAssetRewriteError, defer, defineHandler, defineHead, defineMiddleware, defineQueue, defineRender, defineScheduled };
|