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,208 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
//#region src/runtime/remote/binding-handler.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Hono app that handles `/__void/*` routes for native binding access.
|
|
5
|
+
* Deployed user workers expose this so the proxy can dispatch D1/KV/R2 operations
|
|
6
|
+
* via Workers for Platforms instead of the Cloudflare REST API (~1-5ms vs ~50-200ms).
|
|
7
|
+
*
|
|
8
|
+
* Authenticated via `x-void-internal` header against `env.__VOID_PROXY_TOKEN`.
|
|
9
|
+
* Response formats match the proxy's existing REST API responses so the
|
|
10
|
+
* ProxyClient doesn't need changes.
|
|
11
|
+
*/
|
|
12
|
+
function createBindingHandler(env) {
|
|
13
|
+
const app = new Hono();
|
|
14
|
+
app.use("*", async (c, next) => {
|
|
15
|
+
const token = c.req.header("x-void-internal");
|
|
16
|
+
const expected = env.__VOID_PROXY_TOKEN;
|
|
17
|
+
if (!token || !expected || token !== expected) return c.json({ error: "unauthorized" }, 403);
|
|
18
|
+
await next();
|
|
19
|
+
});
|
|
20
|
+
app.post("/d1/query", async (c) => {
|
|
21
|
+
const body = await c.req.json();
|
|
22
|
+
if (!body.binding || !body.sql) return c.json({ error: "binding and sql required" }, 400);
|
|
23
|
+
const db = env[body.binding];
|
|
24
|
+
if (!db) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
25
|
+
const stmt = db.prepare(body.sql).bind(...body.params ?? []);
|
|
26
|
+
switch (body.method) {
|
|
27
|
+
case "first": {
|
|
28
|
+
const row = await stmt.first();
|
|
29
|
+
return c.json(row);
|
|
30
|
+
}
|
|
31
|
+
case "raw": {
|
|
32
|
+
const raw = await stmt.raw({ columnNames: true });
|
|
33
|
+
const columns = raw.length > 0 ? raw[0] : [];
|
|
34
|
+
const results = raw.slice(1);
|
|
35
|
+
return c.json({
|
|
36
|
+
columns,
|
|
37
|
+
results,
|
|
38
|
+
meta: {}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
case "run": {
|
|
42
|
+
const result = await stmt.run();
|
|
43
|
+
return c.json({
|
|
44
|
+
success: true,
|
|
45
|
+
meta: result.meta
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
default: {
|
|
49
|
+
const result = await stmt.all();
|
|
50
|
+
return c.json({
|
|
51
|
+
results: result.results,
|
|
52
|
+
success: true,
|
|
53
|
+
meta: result.meta
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
app.post("/d1/batch", async (c) => {
|
|
59
|
+
const body = await c.req.json();
|
|
60
|
+
if (!body.binding || !Array.isArray(body.statements)) return c.json({ error: "binding and statements required" }, 400);
|
|
61
|
+
const db = env[body.binding];
|
|
62
|
+
if (!db) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
63
|
+
const stmts = body.statements.map((s) => db.prepare(s.sql).bind(...s.params ?? []));
|
|
64
|
+
const results = await db.batch(stmts);
|
|
65
|
+
return c.json(results.map((r) => ({
|
|
66
|
+
results: r.results,
|
|
67
|
+
success: true,
|
|
68
|
+
meta: r.meta
|
|
69
|
+
})));
|
|
70
|
+
});
|
|
71
|
+
app.post("/kv/get", async (c) => {
|
|
72
|
+
const body = await c.req.json();
|
|
73
|
+
if (!body.binding || !body.key) return c.json({ error: "binding and key required" }, 400);
|
|
74
|
+
const kv = env[body.binding];
|
|
75
|
+
if (!kv) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
76
|
+
const type = body.type ?? "text";
|
|
77
|
+
if (type === "json") {
|
|
78
|
+
const val = await kv.get(body.key, "json");
|
|
79
|
+
return c.json(val);
|
|
80
|
+
}
|
|
81
|
+
if (type === "arrayBuffer") {
|
|
82
|
+
const val = await kv.get(body.key, "arrayBuffer");
|
|
83
|
+
if (val === null) return c.json(null);
|
|
84
|
+
return new Response(val, { headers: { "content-type": "application/octet-stream" } });
|
|
85
|
+
}
|
|
86
|
+
if (type === "stream") {
|
|
87
|
+
const val = await kv.get(body.key, "stream");
|
|
88
|
+
if (val === null) return c.json(null);
|
|
89
|
+
return new Response(val, { headers: { "content-type": "application/octet-stream" } });
|
|
90
|
+
}
|
|
91
|
+
const val = await kv.get(body.key, "text");
|
|
92
|
+
if (val === null) return c.json(null);
|
|
93
|
+
return c.json(val);
|
|
94
|
+
});
|
|
95
|
+
app.post("/kv/put", async (c) => {
|
|
96
|
+
const body = await c.req.json();
|
|
97
|
+
if (!body.binding || !body.key) return c.json({ error: "binding and key required" }, 400);
|
|
98
|
+
const kv = env[body.binding];
|
|
99
|
+
if (!kv) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
100
|
+
const opts = {};
|
|
101
|
+
if (body.expiration) opts.expiration = body.expiration;
|
|
102
|
+
if (body.expiration_ttl) opts.expirationTtl = body.expiration_ttl;
|
|
103
|
+
let value;
|
|
104
|
+
if (body.base64 && typeof body.value === "string") {
|
|
105
|
+
const binary = atob(body.value);
|
|
106
|
+
const bytes = new Uint8Array(binary.length);
|
|
107
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
108
|
+
value = bytes.buffer;
|
|
109
|
+
} else value = typeof body.value === "string" ? body.value : JSON.stringify(body.value);
|
|
110
|
+
await kv.put(body.key, value, opts);
|
|
111
|
+
return c.json({ success: true });
|
|
112
|
+
});
|
|
113
|
+
app.post("/kv/delete", async (c) => {
|
|
114
|
+
const body = await c.req.json();
|
|
115
|
+
if (!body.binding || !body.key) return c.json({ error: "binding and key required" }, 400);
|
|
116
|
+
const kv = env[body.binding];
|
|
117
|
+
if (!kv) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
118
|
+
await kv.delete(body.key);
|
|
119
|
+
return c.json({ success: true });
|
|
120
|
+
});
|
|
121
|
+
app.post("/kv/list", async (c) => {
|
|
122
|
+
const body = await c.req.json();
|
|
123
|
+
if (!body.binding) return c.json({ error: "binding required" }, 400);
|
|
124
|
+
const kv = env[body.binding];
|
|
125
|
+
if (!kv) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
126
|
+
const opts = {};
|
|
127
|
+
if (body.prefix) opts.prefix = body.prefix;
|
|
128
|
+
if (body.limit) opts.limit = body.limit;
|
|
129
|
+
if (body.cursor) opts.cursor = body.cursor;
|
|
130
|
+
const result = await kv.list(opts);
|
|
131
|
+
return c.json({
|
|
132
|
+
keys: result.keys,
|
|
133
|
+
list_complete: result.list_complete,
|
|
134
|
+
cursor: result.list_complete ? null : result.cursor
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
app.post("/r2/get", async (c) => {
|
|
138
|
+
const body = await c.req.json();
|
|
139
|
+
if (!body.binding || !body.key) return c.json({ error: "binding and key required" }, 400);
|
|
140
|
+
const bucket = env[body.binding];
|
|
141
|
+
if (!bucket) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
142
|
+
const obj = await bucket.get(body.key);
|
|
143
|
+
if (!obj) return c.json(null);
|
|
144
|
+
const headers = new Headers();
|
|
145
|
+
headers.set("content-type", obj.httpMetadata?.contentType ?? "application/octet-stream");
|
|
146
|
+
if (obj.size !== void 0) headers.set("content-length", String(obj.size));
|
|
147
|
+
if (obj.httpEtag) headers.set("etag", obj.httpEtag);
|
|
148
|
+
return new Response(obj.body, { headers });
|
|
149
|
+
});
|
|
150
|
+
app.post("/r2/put", async (c) => {
|
|
151
|
+
const body = await c.req.json();
|
|
152
|
+
if (!body.binding || !body.key) return c.json({ error: "binding and key required" }, 400);
|
|
153
|
+
const bucket = env[body.binding];
|
|
154
|
+
if (!bucket) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
155
|
+
const data = body.base64 ? Uint8Array.from(atob(body.base64), (ch) => ch.charCodeAt(0)) : new TextEncoder().encode(body.value ?? "");
|
|
156
|
+
await bucket.put(body.key, data, { httpMetadata: { contentType: body.contentType ?? "application/octet-stream" } });
|
|
157
|
+
return c.json({ success: true });
|
|
158
|
+
});
|
|
159
|
+
app.post("/r2/delete", async (c) => {
|
|
160
|
+
const body = await c.req.json();
|
|
161
|
+
if (!body.binding) return c.json({ error: "binding required" }, 400);
|
|
162
|
+
const keys = body.keys ? body.keys : body.key ? [body.key] : [];
|
|
163
|
+
if (keys.length === 0) return c.json({ error: "key or keys required" }, 400);
|
|
164
|
+
const bucket = env[body.binding];
|
|
165
|
+
if (!bucket) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
166
|
+
await bucket.delete(keys);
|
|
167
|
+
return c.json({ success: true });
|
|
168
|
+
});
|
|
169
|
+
app.post("/r2/list", async (c) => {
|
|
170
|
+
const body = await c.req.json();
|
|
171
|
+
if (!body.binding) return c.json({ error: "binding required" }, 400);
|
|
172
|
+
const bucket = env[body.binding];
|
|
173
|
+
if (!bucket) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
174
|
+
const opts = {};
|
|
175
|
+
if (body.prefix) opts.prefix = body.prefix;
|
|
176
|
+
if (body.limit) opts.limit = body.limit;
|
|
177
|
+
if (body.cursor) opts.cursor = body.cursor;
|
|
178
|
+
if (body.delimiter) opts.delimiter = body.delimiter;
|
|
179
|
+
const result = await bucket.list(opts);
|
|
180
|
+
return c.json({
|
|
181
|
+
objects: result.objects.map((o) => ({
|
|
182
|
+
key: o.key,
|
|
183
|
+
size: o.size,
|
|
184
|
+
lastModified: o.uploaded?.toISOString() ?? ""
|
|
185
|
+
})),
|
|
186
|
+
truncated: result.truncated,
|
|
187
|
+
cursor: result.truncated ? result.cursor : null
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
app.post("/r2/head", async (c) => {
|
|
191
|
+
const body = await c.req.json();
|
|
192
|
+
if (!body.binding || !body.key) return c.json({ error: "binding and key required" }, 400);
|
|
193
|
+
const bucket = env[body.binding];
|
|
194
|
+
if (!bucket) return c.json({ error: `unknown binding "${body.binding}"` }, 404);
|
|
195
|
+
const obj = await bucket.head(body.key);
|
|
196
|
+
if (!obj) return c.json(null);
|
|
197
|
+
return c.json({
|
|
198
|
+
key: body.key,
|
|
199
|
+
size: obj.size,
|
|
200
|
+
etag: obj.httpEtag ?? "",
|
|
201
|
+
lastModified: obj.uploaded?.toISOString() ?? "",
|
|
202
|
+
contentType: obj.httpMetadata?.contentType ?? "application/octet-stream"
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
return app;
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { createBindingHandler };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/runtime/remote/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Replace local D1/KV/R2 bindings with proxy-backed versions.
|
|
4
|
+
* Called from the generated worker entry point when `__VOID_REMOTE` is set.
|
|
5
|
+
*/
|
|
6
|
+
declare function createRemoteEnv(env: Record<string, unknown>): Record<string, unknown>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createRemoteEnv };
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { t as cfAccessHeaders } from "../../cf-access-Dee5cXxL.mjs";
|
|
2
|
+
//#region src/runtime/remote/client.ts
|
|
3
|
+
/**
|
|
4
|
+
* HTTP client for the remote bindings proxy (proxy.void.cloud).
|
|
5
|
+
*
|
|
6
|
+
* Used by ProxyD1Database, ProxyKVNamespace, and ProxyR2Bucket to forward
|
|
7
|
+
* binding operations to the platform proxy during local development.
|
|
8
|
+
*/
|
|
9
|
+
var ProxyClient = class {
|
|
10
|
+
authHeaders;
|
|
11
|
+
constructor(proxyUrl, token, projectId, env = {}) {
|
|
12
|
+
this.proxyUrl = proxyUrl;
|
|
13
|
+
this.projectId = projectId;
|
|
14
|
+
this.authHeaders = {
|
|
15
|
+
Authorization: `Bearer ${token}`,
|
|
16
|
+
...cfAccessHeaders(env)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Send a JSON POST request to the proxy and return the response.
|
|
21
|
+
* Injects `projectId` into the body and `Authorization` header.
|
|
22
|
+
* Throws on non-OK responses.
|
|
23
|
+
*/
|
|
24
|
+
async fetch(path, body) {
|
|
25
|
+
const res = await globalThis.fetch(`${this.proxyUrl}${path}`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: {
|
|
28
|
+
...this.authHeaders,
|
|
29
|
+
"Content-Type": "application/json"
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
...body,
|
|
33
|
+
projectId: this.projectId
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
if (!res.ok) {
|
|
37
|
+
const text = await res.text().catch(() => res.statusText);
|
|
38
|
+
throw new Error(`remote: Proxy request failed with ${res.status}: '${text}'.`);
|
|
39
|
+
}
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Send a request to the proxy and return the raw Response (for streaming).
|
|
44
|
+
* Injects `Authorization` header and `projectId` into the JSON body.
|
|
45
|
+
* Throws on non-OK responses.
|
|
46
|
+
*/
|
|
47
|
+
async stream(path, init) {
|
|
48
|
+
let body = init.body;
|
|
49
|
+
if (typeof body === "string") try {
|
|
50
|
+
const parsed = JSON.parse(body);
|
|
51
|
+
body = JSON.stringify({
|
|
52
|
+
...parsed,
|
|
53
|
+
projectId: this.projectId
|
|
54
|
+
});
|
|
55
|
+
} catch {}
|
|
56
|
+
const res = await globalThis.fetch(`${this.proxyUrl}${path}`, {
|
|
57
|
+
...init,
|
|
58
|
+
headers: {
|
|
59
|
+
...init.headers,
|
|
60
|
+
...this.authHeaders
|
|
61
|
+
},
|
|
62
|
+
body
|
|
63
|
+
});
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
const text = await res.text().catch(() => res.statusText);
|
|
66
|
+
throw new Error(`remote: Proxy request failed with ${res.status}: '${text}'.`);
|
|
67
|
+
}
|
|
68
|
+
return res;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/runtime/remote/d1.ts
|
|
73
|
+
/**
|
|
74
|
+
* D1Database implementation backed by the remote proxy.
|
|
75
|
+
* Used during local development when `remote: true` is set in void.json.
|
|
76
|
+
*/
|
|
77
|
+
var ProxyD1Database = class {
|
|
78
|
+
constructor(client, binding) {
|
|
79
|
+
this.client = client;
|
|
80
|
+
this.binding = binding;
|
|
81
|
+
}
|
|
82
|
+
prepare(sql) {
|
|
83
|
+
return new ProxyD1PreparedStatement(this.client, this.binding, sql);
|
|
84
|
+
}
|
|
85
|
+
async batch(stmts) {
|
|
86
|
+
const statements = stmts.map((s) => ({
|
|
87
|
+
sql: s._sql,
|
|
88
|
+
params: s._params
|
|
89
|
+
}));
|
|
90
|
+
return await (await this.client.fetch("/d1/batch", {
|
|
91
|
+
binding: this.binding,
|
|
92
|
+
statements
|
|
93
|
+
})).json();
|
|
94
|
+
}
|
|
95
|
+
async exec(sql) {
|
|
96
|
+
const data = await (await this.client.fetch("/d1/query", {
|
|
97
|
+
binding: this.binding,
|
|
98
|
+
sql,
|
|
99
|
+
method: "run"
|
|
100
|
+
})).json();
|
|
101
|
+
return {
|
|
102
|
+
count: data.meta?.changes ?? 0,
|
|
103
|
+
duration: data.meta?.duration ?? 0
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
dump() {
|
|
107
|
+
throw new Error("dump() is not supported with remote bindings");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* D1PreparedStatement implementation backed by the remote proxy.
|
|
112
|
+
* Accumulates SQL and params synchronously; terminal methods (all, first, run, raw) make the HTTP call.
|
|
113
|
+
*/
|
|
114
|
+
var ProxyD1PreparedStatement = class {
|
|
115
|
+
/** @internal */
|
|
116
|
+
_sql;
|
|
117
|
+
/** @internal */
|
|
118
|
+
_params;
|
|
119
|
+
constructor(client, binding, sql) {
|
|
120
|
+
this.client = client;
|
|
121
|
+
this.binding = binding;
|
|
122
|
+
this._sql = sql;
|
|
123
|
+
this._params = [];
|
|
124
|
+
}
|
|
125
|
+
bind(...values) {
|
|
126
|
+
this._params = values;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
async all() {
|
|
130
|
+
return await (await this.client.fetch("/d1/query", {
|
|
131
|
+
binding: this.binding,
|
|
132
|
+
sql: this._sql,
|
|
133
|
+
params: this._params,
|
|
134
|
+
method: "all"
|
|
135
|
+
})).json();
|
|
136
|
+
}
|
|
137
|
+
async first(col) {
|
|
138
|
+
const row = await (await this.client.fetch("/d1/query", {
|
|
139
|
+
binding: this.binding,
|
|
140
|
+
sql: this._sql,
|
|
141
|
+
params: this._params,
|
|
142
|
+
method: "first"
|
|
143
|
+
})).json();
|
|
144
|
+
if (row === null) return null;
|
|
145
|
+
if (col) return row[col];
|
|
146
|
+
return row;
|
|
147
|
+
}
|
|
148
|
+
async run() {
|
|
149
|
+
return await (await this.client.fetch("/d1/query", {
|
|
150
|
+
binding: this.binding,
|
|
151
|
+
sql: this._sql,
|
|
152
|
+
params: this._params,
|
|
153
|
+
method: "run"
|
|
154
|
+
})).json();
|
|
155
|
+
}
|
|
156
|
+
async raw(options) {
|
|
157
|
+
const data = await (await this.client.fetch("/d1/query", {
|
|
158
|
+
binding: this.binding,
|
|
159
|
+
sql: this._sql,
|
|
160
|
+
params: this._params,
|
|
161
|
+
method: "raw"
|
|
162
|
+
})).json();
|
|
163
|
+
if (options?.columnNames) return [data.columns, ...data.results];
|
|
164
|
+
return data.results;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/runtime/remote/kv.ts
|
|
169
|
+
/**
|
|
170
|
+
* KVNamespace implementation backed by the remote proxy.
|
|
171
|
+
* Used during local development when `remote: true` is set in void.json.
|
|
172
|
+
*/
|
|
173
|
+
var ProxyKVNamespace = class {
|
|
174
|
+
normalizeGetOptions(options) {
|
|
175
|
+
if (typeof options === "string") return options;
|
|
176
|
+
if (options?.type === "json" || options?.type === "text" || options?.type === "arrayBuffer" || options?.type === "stream") return { type: options.type };
|
|
177
|
+
}
|
|
178
|
+
constructor(client, binding) {
|
|
179
|
+
this.client = client;
|
|
180
|
+
this.binding = binding;
|
|
181
|
+
}
|
|
182
|
+
async get(key, options) {
|
|
183
|
+
const type = typeof options === "string" ? options : options?.type ?? "text";
|
|
184
|
+
const res = await this.client.fetch("/kv/get", {
|
|
185
|
+
binding: this.binding,
|
|
186
|
+
key,
|
|
187
|
+
type
|
|
188
|
+
});
|
|
189
|
+
const ct = res.headers.get("content-type") ?? "";
|
|
190
|
+
if (type === "arrayBuffer" || type === "stream") {
|
|
191
|
+
if (ct.includes("application/json")) {
|
|
192
|
+
const data = await res.json();
|
|
193
|
+
if (data === null) return null;
|
|
194
|
+
const encoded = new TextEncoder().encode(JSON.stringify(data));
|
|
195
|
+
return type === "arrayBuffer" ? encoded.buffer : new ReadableStream({ start(controller) {
|
|
196
|
+
controller.enqueue(encoded);
|
|
197
|
+
controller.close();
|
|
198
|
+
} });
|
|
199
|
+
}
|
|
200
|
+
if (type === "arrayBuffer") return res.arrayBuffer();
|
|
201
|
+
return res.body;
|
|
202
|
+
}
|
|
203
|
+
return res.json();
|
|
204
|
+
}
|
|
205
|
+
async getWithMetadata(key, options) {
|
|
206
|
+
const normalized = this.normalizeGetOptions(options);
|
|
207
|
+
let value;
|
|
208
|
+
switch (typeof normalized === "string" ? normalized : normalized?.type) {
|
|
209
|
+
case "json":
|
|
210
|
+
value = await this.get(key, "json");
|
|
211
|
+
break;
|
|
212
|
+
case "text":
|
|
213
|
+
value = await this.get(key, "text");
|
|
214
|
+
break;
|
|
215
|
+
case "arrayBuffer":
|
|
216
|
+
value = await this.get(key, "arrayBuffer");
|
|
217
|
+
break;
|
|
218
|
+
case "stream":
|
|
219
|
+
value = await this.get(key, "stream");
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
value = await this.get(key);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
value,
|
|
227
|
+
metadata: null,
|
|
228
|
+
cacheStatus: null
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
async put(key, value, options) {
|
|
232
|
+
let serializedValue;
|
|
233
|
+
let isBase64 = false;
|
|
234
|
+
if (typeof value === "string") serializedValue = value;
|
|
235
|
+
else if (value instanceof ArrayBuffer) {
|
|
236
|
+
const bytes = new Uint8Array(value);
|
|
237
|
+
let binary = "";
|
|
238
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
239
|
+
serializedValue = btoa(binary);
|
|
240
|
+
isBase64 = true;
|
|
241
|
+
} else {
|
|
242
|
+
const reader = value.getReader();
|
|
243
|
+
const chunks = [];
|
|
244
|
+
while (true) {
|
|
245
|
+
const { done, value: chunk } = await reader.read();
|
|
246
|
+
if (done) break;
|
|
247
|
+
chunks.push(chunk);
|
|
248
|
+
}
|
|
249
|
+
const total = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
250
|
+
const merged = new Uint8Array(total);
|
|
251
|
+
let offset = 0;
|
|
252
|
+
for (const chunk of chunks) {
|
|
253
|
+
merged.set(chunk, offset);
|
|
254
|
+
offset += chunk.length;
|
|
255
|
+
}
|
|
256
|
+
let binary = "";
|
|
257
|
+
for (const byte of merged) binary += String.fromCharCode(byte);
|
|
258
|
+
serializedValue = btoa(binary);
|
|
259
|
+
isBase64 = true;
|
|
260
|
+
}
|
|
261
|
+
const body = {
|
|
262
|
+
binding: this.binding,
|
|
263
|
+
key,
|
|
264
|
+
value: serializedValue,
|
|
265
|
+
...isBase64 && { base64: true }
|
|
266
|
+
};
|
|
267
|
+
if (options?.expiration) body.expiration = options.expiration;
|
|
268
|
+
if (options?.expirationTtl) body.expiration_ttl = options.expirationTtl;
|
|
269
|
+
if (options?.metadata) body.metadata = options.metadata;
|
|
270
|
+
await this.client.fetch("/kv/put", body);
|
|
271
|
+
}
|
|
272
|
+
async delete(key) {
|
|
273
|
+
await this.client.fetch("/kv/delete", {
|
|
274
|
+
binding: this.binding,
|
|
275
|
+
key
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
async list(options) {
|
|
279
|
+
return await (await this.client.fetch("/kv/list", {
|
|
280
|
+
binding: this.binding,
|
|
281
|
+
prefix: options?.prefix,
|
|
282
|
+
limit: options?.limit,
|
|
283
|
+
cursor: options?.cursor
|
|
284
|
+
})).json();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/runtime/remote/r2.ts
|
|
289
|
+
/**
|
|
290
|
+
* R2Bucket implementation backed by the remote proxy.
|
|
291
|
+
* Used during local development when `remote: true` is set in void.json.
|
|
292
|
+
*/
|
|
293
|
+
var ProxyR2Bucket = class {
|
|
294
|
+
constructor(client, binding) {
|
|
295
|
+
this.client = client;
|
|
296
|
+
this.binding = binding;
|
|
297
|
+
}
|
|
298
|
+
async head(key) {
|
|
299
|
+
const data = await (await this.client.fetch("/r2/head", {
|
|
300
|
+
binding: this.binding,
|
|
301
|
+
key
|
|
302
|
+
})).json();
|
|
303
|
+
if (!data) return null;
|
|
304
|
+
return makeR2Object(data);
|
|
305
|
+
}
|
|
306
|
+
async get(key) {
|
|
307
|
+
const res = await this.client.stream("/r2/get", {
|
|
308
|
+
method: "POST",
|
|
309
|
+
headers: { "Content-Type": "application/json" },
|
|
310
|
+
body: JSON.stringify({
|
|
311
|
+
binding: this.binding,
|
|
312
|
+
key
|
|
313
|
+
})
|
|
314
|
+
});
|
|
315
|
+
if ((res.headers.get("content-type") ?? "").includes("application/json")) {
|
|
316
|
+
if (await res.clone().json() === null) return null;
|
|
317
|
+
}
|
|
318
|
+
return makeR2ObjectBody(key, res);
|
|
319
|
+
}
|
|
320
|
+
async put(key, value, options) {
|
|
321
|
+
let base64;
|
|
322
|
+
let textValue;
|
|
323
|
+
if (typeof value === "string") textValue = value;
|
|
324
|
+
else if (value === null) textValue = "";
|
|
325
|
+
else if (value instanceof ArrayBuffer) base64 = arrayBufferToBase64(value);
|
|
326
|
+
else if (ArrayBuffer.isView(value)) base64 = arrayBufferToBase64(value.buffer);
|
|
327
|
+
else if (value instanceof Blob) base64 = arrayBufferToBase64(await value.arrayBuffer());
|
|
328
|
+
else {
|
|
329
|
+
const reader = value.getReader();
|
|
330
|
+
const chunks = [];
|
|
331
|
+
while (true) {
|
|
332
|
+
const { done, value: chunk } = await reader.read();
|
|
333
|
+
if (done) break;
|
|
334
|
+
chunks.push(chunk);
|
|
335
|
+
}
|
|
336
|
+
const total = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
337
|
+
const merged = new Uint8Array(total);
|
|
338
|
+
let offset = 0;
|
|
339
|
+
for (const chunk of chunks) {
|
|
340
|
+
merged.set(chunk, offset);
|
|
341
|
+
offset += chunk.length;
|
|
342
|
+
}
|
|
343
|
+
base64 = arrayBufferToBase64(merged.buffer);
|
|
344
|
+
}
|
|
345
|
+
const body = {
|
|
346
|
+
binding: this.binding,
|
|
347
|
+
key
|
|
348
|
+
};
|
|
349
|
+
if (base64) body.base64 = base64;
|
|
350
|
+
else body.value = textValue;
|
|
351
|
+
if (options?.httpMetadata) {
|
|
352
|
+
const meta = options.httpMetadata;
|
|
353
|
+
if (meta instanceof Headers) body.contentType = meta.get("content-type") ?? void 0;
|
|
354
|
+
else body.contentType = meta.contentType;
|
|
355
|
+
}
|
|
356
|
+
if (options?.customMetadata) body.customMetadata = options.customMetadata;
|
|
357
|
+
await this.client.fetch("/r2/put", body);
|
|
358
|
+
return makeR2Object({
|
|
359
|
+
key,
|
|
360
|
+
size: 0,
|
|
361
|
+
etag: "",
|
|
362
|
+
lastModified: (/* @__PURE__ */ new Date()).toISOString(),
|
|
363
|
+
contentType: "application/octet-stream"
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
async delete(keys) {
|
|
367
|
+
const body = { binding: this.binding };
|
|
368
|
+
if (Array.isArray(keys)) body.keys = keys;
|
|
369
|
+
else body.key = keys;
|
|
370
|
+
await this.client.fetch("/r2/delete", body);
|
|
371
|
+
}
|
|
372
|
+
async list(options) {
|
|
373
|
+
const data = await (await this.client.fetch("/r2/list", {
|
|
374
|
+
binding: this.binding,
|
|
375
|
+
prefix: options?.prefix,
|
|
376
|
+
limit: options?.limit,
|
|
377
|
+
cursor: options?.cursor,
|
|
378
|
+
delimiter: options?.delimiter
|
|
379
|
+
})).json();
|
|
380
|
+
return {
|
|
381
|
+
objects: data.objects.map((o) => makeR2Object({
|
|
382
|
+
key: o.key,
|
|
383
|
+
size: o.size,
|
|
384
|
+
etag: "",
|
|
385
|
+
lastModified: o.lastModified,
|
|
386
|
+
contentType: "application/octet-stream"
|
|
387
|
+
})),
|
|
388
|
+
truncated: data.truncated,
|
|
389
|
+
cursor: data.cursor ?? void 0,
|
|
390
|
+
delimitedPrefixes: []
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
createMultipartUpload() {
|
|
394
|
+
throw new Error("createMultipartUpload() is not supported with remote bindings");
|
|
395
|
+
}
|
|
396
|
+
resumeMultipartUpload() {
|
|
397
|
+
throw new Error("resumeMultipartUpload() is not supported with remote bindings");
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
function arrayBufferToBase64(buffer) {
|
|
401
|
+
const bytes = new Uint8Array(buffer);
|
|
402
|
+
let binary = "";
|
|
403
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
404
|
+
return btoa(binary);
|
|
405
|
+
}
|
|
406
|
+
function makeR2Object(data) {
|
|
407
|
+
return {
|
|
408
|
+
key: data.key,
|
|
409
|
+
version: "",
|
|
410
|
+
size: data.size,
|
|
411
|
+
etag: data.etag,
|
|
412
|
+
httpEtag: data.etag ? `"${data.etag}"` : "",
|
|
413
|
+
checksums: { toJSON: () => ({}) },
|
|
414
|
+
uploaded: new Date(data.lastModified || Date.now()),
|
|
415
|
+
httpMetadata: { contentType: data.contentType },
|
|
416
|
+
customMetadata: {},
|
|
417
|
+
storageClass: "Standard",
|
|
418
|
+
range: void 0,
|
|
419
|
+
writeHttpMetadata(_headers) {}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function makeR2ObjectBody(key, res) {
|
|
423
|
+
const size = parseInt(res.headers.get("content-length") ?? "0");
|
|
424
|
+
const etag = res.headers.get("etag") ?? "";
|
|
425
|
+
const contentType = res.headers.get("content-type") ?? "application/octet-stream";
|
|
426
|
+
return {
|
|
427
|
+
...makeR2Object({
|
|
428
|
+
key,
|
|
429
|
+
size,
|
|
430
|
+
etag,
|
|
431
|
+
lastModified: res.headers.get("last-modified") ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
432
|
+
contentType
|
|
433
|
+
}),
|
|
434
|
+
body: res.body,
|
|
435
|
+
get bodyUsed() {
|
|
436
|
+
return res.bodyUsed;
|
|
437
|
+
},
|
|
438
|
+
arrayBuffer: () => res.arrayBuffer(),
|
|
439
|
+
bytes: async () => new Uint8Array(await res.arrayBuffer()),
|
|
440
|
+
text: () => res.text(),
|
|
441
|
+
json: () => res.json(),
|
|
442
|
+
blob: () => res.blob()
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/runtime/remote/index.ts
|
|
447
|
+
/**
|
|
448
|
+
* Replace local D1/KV/R2 bindings with proxy-backed versions.
|
|
449
|
+
* Called from the generated worker entry point when `__VOID_REMOTE` is set.
|
|
450
|
+
*/
|
|
451
|
+
function createRemoteEnv(env) {
|
|
452
|
+
const client = new ProxyClient(env.__VOID_PROXY_URL, env.__VOID_TOKEN, env.__VOID_PROJECT_ID, env);
|
|
453
|
+
return {
|
|
454
|
+
...env,
|
|
455
|
+
...env.DB != null && { DB: new ProxyD1Database(client, "DB") },
|
|
456
|
+
...env.KV != null && { KV: new ProxyKVNamespace(client, "KV") },
|
|
457
|
+
...env.STORAGE != null && { STORAGE: new ProxyR2Bucket(client, "STORAGE") }
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
export { createRemoteEnv };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/runtime/response.d.ts
|
|
2
|
+
/** Returns true if the value is a Response that was created by convertReturnValue. */
|
|
3
|
+
declare function isConvertedResponse(value: unknown): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Convert a handler's return value to a Web Response.
|
|
6
|
+
*
|
|
7
|
+
* - Response → passthrough
|
|
8
|
+
* - null/undefined → 204 No Content
|
|
9
|
+
* - string → text/html
|
|
10
|
+
* - object/array → JSON
|
|
11
|
+
*/
|
|
12
|
+
declare function convertReturnValue(value: unknown): Response;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { convertReturnValue, isConvertedResponse };
|