devflare 1.0.0-next.14 → 1.0.0-next.16
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/LLM.md +9360 -1784
- package/README.md +391 -32
- package/bin/devflare.js +17 -7
- package/dist/account-0w8wdzjv.js +475 -0
- package/dist/account-eygq6qx7.js +475 -0
- package/dist/account-fw8nafav.js +475 -0
- package/dist/account-pzq69nys.js +475 -0
- package/dist/account-s66jb15j.js +475 -0
- package/dist/api-d6ekexs5.js +25 -0
- package/dist/bridge/index.d.ts +1 -1
- package/dist/bridge/index.d.ts.map +1 -1
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/bridge/protocol.d.ts +1 -1
- package/dist/bridge/protocol.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +0 -4
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/serialization.d.ts.map +1 -1
- package/dist/bridge/server.d.ts +1 -1
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/browser-shim/handler.d.ts +1 -1
- package/dist/browser-shim/handler.d.ts.map +1 -1
- package/dist/browser.d.ts +1651 -34
- package/dist/browser.d.ts.map +1 -1
- package/dist/build-1kmkwqgh.js +53 -0
- package/dist/build-506kjhcm.js +53 -0
- package/dist/build-66866ahs.js +53 -0
- package/dist/build-g1adm3ww.js +53 -0
- package/dist/build-p3r3117t.js +53 -0
- package/dist/bundler/do-bundler.d.ts.map +1 -1
- package/dist/bundler/rolldown-shared.d.ts +24 -0
- package/dist/bundler/rolldown-shared.d.ts.map +1 -0
- package/dist/bundler/worker-bundler.d.ts +0 -1
- package/dist/bundler/worker-bundler.d.ts.map +1 -1
- package/dist/cli/command-utils.d.ts +18 -0
- package/dist/cli/command-utils.d.ts.map +1 -0
- package/dist/cli/commands/account.d.ts +1 -1
- package/dist/cli/commands/account.d.ts.map +1 -1
- package/dist/cli/commands/build-artifacts.d.ts +27 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts +4 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/doctor.d.ts.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/login.d.ts +4 -0
- package/dist/cli/commands/login.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
- package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/family.d.ts +10 -0
- package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/render.d.ts +8 -0
- package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/theme.d.ts +10 -0
- package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/types.d.ts +70 -0
- package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
- package/dist/cli/commands/previews.d.ts +4 -0
- package/dist/cli/commands/previews.d.ts.map +1 -0
- package/dist/cli/commands/productions.d.ts +4 -0
- package/dist/cli/commands/productions.d.ts.map +1 -0
- package/dist/cli/commands/token.d.ts +4 -0
- package/dist/cli/commands/token.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
- package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/generator.d.ts +44 -0
- package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/models.d.ts +27 -0
- package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/commands/worker.d.ts +4 -0
- package/dist/cli/commands/worker.d.ts.map +1 -0
- package/dist/cli/config-path.d.ts +2 -1
- package/dist/cli/config-path.d.ts.map +1 -1
- package/dist/cli/deploy-strategy.d.ts +17 -0
- package/dist/cli/deploy-strategy.d.ts.map +1 -0
- package/dist/cli/deploy-target.d.ts +17 -0
- package/dist/cli/deploy-target.d.ts.map +1 -0
- package/dist/cli/generated-artifacts.d.ts +12 -0
- package/dist/cli/generated-artifacts.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/account.d.ts +3 -0
- package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/core.d.ts +4 -0
- package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/index.d.ts +3 -0
- package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/misc.d.ts +3 -0
- package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/previews.d.ts +3 -0
- package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/productions.d.ts +3 -0
- package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
- package/dist/cli/help-pages/render.d.ts +12 -0
- package/dist/cli/help-pages/render.d.ts.map +1 -0
- package/dist/cli/help-pages/shared.d.ts +15 -0
- package/dist/cli/help-pages/shared.d.ts.map +1 -0
- package/dist/cli/help-pages/types.d.ts +23 -0
- package/dist/cli/help-pages/types.d.ts.map +1 -0
- package/dist/cli/help.d.ts +6 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/preview-bindings.d.ts +42 -0
- package/dist/cli/preview-bindings.d.ts.map +1 -0
- package/dist/cli/preview.d.ts +11 -0
- package/dist/cli/preview.d.ts.map +1 -0
- package/dist/cli/ui.d.ts +37 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/workspace-build-guard.d.ts +14 -0
- package/dist/cli/workspace-build-guard.d.ts.map +1 -0
- package/dist/cloudflare/account-core.d.ts +6 -0
- package/dist/cloudflare/account-core.d.ts.map +1 -0
- package/dist/cloudflare/account-resources.d.ts +40 -0
- package/dist/cloudflare/account-resources.d.ts.map +1 -0
- package/dist/cloudflare/account-status.d.ts +11 -0
- package/dist/cloudflare/account-status.d.ts.map +1 -0
- package/dist/cloudflare/account-workers.d.ts +14 -0
- package/dist/cloudflare/account-workers.d.ts.map +1 -0
- package/dist/cloudflare/account.d.ts +7 -64
- package/dist/cloudflare/account.d.ts.map +1 -1
- package/dist/cloudflare/api.d.ts +4 -0
- package/dist/cloudflare/api.d.ts.map +1 -1
- package/dist/cloudflare/index.d.ts +57 -2
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/kv-namespace.d.ts +3 -0
- package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
- package/dist/cloudflare/preferences.d.ts.map +1 -1
- package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
- package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-records.d.ts +61 -0
- package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-store.d.ts +14 -0
- package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-types.d.ts +103 -0
- package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry.d.ts +42 -0
- package/dist/cloudflare/preview-registry.d.ts.map +1 -0
- package/dist/cloudflare/registry-schema.d.ts +253 -0
- package/dist/cloudflare/registry-schema.d.ts.map +1 -0
- package/dist/cloudflare/tokens.d.ts +18 -0
- package/dist/cloudflare/tokens.d.ts.map +1 -0
- package/dist/cloudflare/types.d.ts +122 -5
- package/dist/cloudflare/types.d.ts.map +1 -1
- package/dist/cloudflare/usage.d.ts.map +1 -1
- package/dist/config/compiler.d.ts +4 -0
- package/dist/config/compiler.d.ts.map +1 -1
- package/dist/config/framework-providers.d.ts +9 -0
- package/dist/config/framework-providers.d.ts.map +1 -0
- package/dist/config/index.d.ts +5 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts +1 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/preview-resources.d.ts +77 -0
- package/dist/config/preview-resources.d.ts.map +1 -0
- package/dist/config/preview.d.ts +31 -0
- package/dist/config/preview.d.ts.map +1 -0
- package/dist/config/ref.d.ts +0 -22
- package/dist/config/ref.d.ts.map +1 -1
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resource-resolution.d.ts +60 -0
- package/dist/config/resource-resolution.d.ts.map +1 -0
- package/dist/config/schema-bindings.d.ts +693 -0
- package/dist/config/schema-bindings.d.ts.map +1 -0
- package/dist/config/schema-build.d.ts +67 -0
- package/dist/config/schema-build.d.ts.map +1 -0
- package/dist/config/schema-env.d.ts +1341 -0
- package/dist/config/schema-env.d.ts.map +1 -0
- package/dist/config/schema-normalization.d.ts +64 -0
- package/dist/config/schema-normalization.d.ts.map +1 -0
- package/dist/config/schema-runtime.d.ts +230 -0
- package/dist/config/schema-runtime.d.ts.map +1 -0
- package/dist/config/schema.d.ts +640 -3669
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config-entry.d.ts +5 -0
- package/dist/config-entry.d.ts.map +1 -0
- package/dist/config-fjwke42y.js +59 -0
- package/dist/config-hwdqjse7.js +59 -0
- package/dist/config-pxvewrhv.js +59 -0
- package/dist/config-q0g5qdga.js +59 -0
- package/dist/decorators/durable-object.d.ts.map +1 -1
- package/dist/deploy-7nmzc9r8.js +609 -0
- package/dist/deploy-csfhdr64.js +691 -0
- package/dist/deploy-ex4g5avz.js +621 -0
- package/dist/deploy-jnb0bhka.js +609 -0
- package/dist/deploy-tp0g6qdp.js +609 -0
- package/dist/deploy-ykpcjkc2.js +690 -0
- package/dist/{dev-c1xc1gq9.js → dev-2pd33m28.js} +392 -348
- package/dist/dev-7ef5e2j1.js +2409 -0
- package/dist/dev-8nssqatr.js +2409 -0
- package/dist/dev-grznx8fn.js +2409 -0
- package/dist/dev-server/d1-migrations.d.ts +14 -0
- package/dist/dev-server/d1-migrations.d.ts.map +1 -0
- package/dist/dev-server/gateway-script.d.ts +8 -0
- package/dist/dev-server/gateway-script.d.ts.map +1 -0
- package/dist/dev-server/runtime-stdio.d.ts.map +1 -1
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/dev-server/vite-process.d.ts +14 -0
- package/dist/dev-server/vite-process.d.ts.map +1 -0
- package/dist/dev-server/vite-utils.d.ts +1 -1
- package/dist/dev-server/vite-utils.d.ts.map +1 -1
- package/dist/dev-server/worker-source-watcher.d.ts +11 -0
- package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
- package/dist/dev-server/worker-surface-paths.d.ts +6 -0
- package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
- package/dist/{doctor-z4ffybce.js → doctor-04ammrrh.js} +67 -31
- package/dist/doctor-fmjj65mc.js +245 -0
- package/dist/doctor-fzkznce1.js +245 -0
- package/dist/doctor-sa5xv1bz.js +245 -0
- package/dist/index-091sh1ma.js +1229 -0
- package/dist/index-0apbm26n.js +788 -0
- package/dist/index-0eqksag4.js +418 -0
- package/dist/{index-dr6sbp8d.js → index-0kfzdywd.js} +15 -2
- package/dist/index-0w826dsr.js +379 -0
- package/dist/{index-rfhx0yd5.js → index-11m5a8wd.js} +110 -32
- package/dist/{index-xxwbb2nt.js → index-1sp39f2f.js} +114 -58
- package/dist/index-2jnrqbny.js +1301 -0
- package/dist/index-2pb7b9mw.js +378 -0
- package/dist/{index-0kzg8wed.js → index-2x53aqjm.js} +1071 -890
- package/dist/index-3ke5d2vn.js +1229 -0
- package/dist/index-43dq8yx8.js +788 -0
- package/dist/index-4rrttqj5.js +378 -0
- package/dist/index-4v9bc2pc.js +1367 -0
- package/dist/index-61jsjnsv.js +280 -0
- package/dist/index-6jef5emv.js +176 -0
- package/dist/index-6psz1h4c.js +788 -0
- package/dist/index-72mve6vh.js +168 -0
- package/dist/{index-zbvmtcn2.js → index-74198nxd.js} +179 -77
- package/dist/index-7g8zyws4.js +192 -0
- package/dist/index-7kcxjhta.js +456 -0
- package/dist/index-7v583xan.js +418 -0
- package/dist/index-7x0ybbtx.js +133 -0
- package/dist/index-816krz9p.js +52 -0
- package/dist/index-82f1z98k.js +41 -0
- package/dist/index-8t5nb4qx.js +133 -0
- package/dist/index-9az6s7ad.js +52 -0
- package/dist/{index-59df49vn.js → index-9ba1etyz.js} +29 -51
- package/dist/{index-001mw014.js → index-9fbtk7gv.js} +134 -248
- package/dist/index-9n6djthj.js +490 -0
- package/dist/index-aabgympv.js +39 -0
- package/dist/index-b8m6883k.js +74 -0
- package/dist/{index-5yxg30va.js → index-cgbvmse6.js} +15 -6
- package/dist/index-d8etnfef.js +1229 -0
- package/dist/index-e9yw4d6y.js +133 -0
- package/dist/index-epw1jxz5.js +1204 -0
- package/dist/index-f85s8gj3.js +2649 -0
- package/dist/index-fe2ngvh7.js +1229 -0
- package/dist/index-fvsadj32.js +192 -0
- package/dist/index-gs4y9gdf.js +456 -0
- package/dist/{index-fef08w43.js → index-h18pxvzs.js} +7 -6
- package/dist/index-hfj1a2c4.js +2649 -0
- package/dist/{index-8gtqgb3q.js → index-hjy8ctpc.js} +14 -92
- package/dist/index-htzf0py1.js +1204 -0
- package/dist/index-j185x270.js +897 -0
- package/dist/index-jb75kwa4.js +519 -0
- package/dist/index-jwd8pcb2.js +897 -0
- package/dist/index-k29yjhv0.js +52 -0
- package/dist/index-k6vq6kkt.js +456 -0
- package/dist/{index-vky23txa.js → index-m3fmw6mx.js} +2 -2
- package/dist/index-maxpsfk8.js +402 -0
- package/dist/index-mbdmrner.js +402 -0
- package/dist/index-mea5bc45.js +418 -0
- package/dist/index-mqekt778.js +185 -0
- package/dist/index-na3mnm1k.js +74 -0
- package/dist/index-p03n4qet.js +1367 -0
- package/dist/index-p296ban8.js +191 -0
- package/dist/index-pnbs1b8k.js +280 -0
- package/dist/index-q4kaz181.js +1207 -0
- package/dist/index-ry131z23.js +378 -0
- package/dist/index-sgb7c8nm.js +402 -0
- package/dist/index-sqrksgb2.js +133 -0
- package/dist/index-stgn34cr.js +148 -0
- package/dist/{index-v8vvsn9x.js → index-t08te69w.js} +1 -18
- package/dist/index-thna1tkd.js +280 -0
- package/dist/index-v5nmqthy.js +74 -0
- package/dist/{index-n932ytmq.js → index-vt4yxkmf.js} +2 -2
- package/dist/index-wyq6c6yj.js +402 -0
- package/dist/index-wztc9stx.js +418 -0
- package/dist/index-x9cwdxw5.js +456 -0
- package/dist/index-xk9djfjp.js +519 -0
- package/dist/index-yc0gcchc.js +418 -0
- package/dist/index-yqbxjysa.js +897 -0
- package/dist/index-yzddwp02.js +788 -0
- package/dist/index-zfhq6s96.js +74 -0
- package/dist/index-zt22fe2j.js +54 -0
- package/dist/index-zyt5byt6.js +2649 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/{init-na2atvz2.js → init-r4hnxan3.js} +24 -17
- package/dist/login-2hnz4m4n.js +77 -0
- package/dist/login-5bsxxpvc.js +77 -0
- package/dist/login-6tzvczw2.js +77 -0
- package/dist/login-bhaw72zc.js +77 -0
- package/dist/login-x8tgckqm.js +77 -0
- package/dist/previews-3rn8mz2c.js +1168 -0
- package/dist/previews-d487qde5.js +1200 -0
- package/dist/previews-gm3z0syj.js +1168 -0
- package/dist/previews-j9ymq4ys.js +1169 -0
- package/dist/previews-q031mx34.js +1168 -0
- package/dist/productions-120xg0aq.js +505 -0
- package/dist/productions-5ev5qweg.js +505 -0
- package/dist/productions-me3tdvr9.js +505 -0
- package/dist/productions-p5rbgp2f.js +505 -0
- package/dist/productions-x9p0pym1.js +505 -0
- package/dist/runtime/context-events.d.ts +13 -0
- package/dist/runtime/context-events.d.ts.map +1 -0
- package/dist/runtime/context-types.d.ts +82 -0
- package/dist/runtime/context-types.d.ts.map +1 -0
- package/dist/runtime/context.d.ts +6 -267
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/exports.d.ts +3 -3
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/middleware.d.ts +8 -38
- package/dist/runtime/middleware.d.ts.map +1 -1
- package/dist/src/browser.js +23 -14
- package/dist/src/cli/index.js +3 -1
- package/dist/src/cloudflare/index.js +49 -2
- package/dist/src/config-entry.js +14 -0
- package/dist/src/index.js +33 -20
- package/dist/src/runtime/index.js +3 -9
- package/dist/src/sveltekit/index.js +10 -7
- package/dist/src/test/index.js +16 -18
- package/dist/src/vite/index.js +7 -4
- package/dist/sveltekit/platform.d.ts +1 -1
- package/dist/sveltekit/platform.d.ts.map +1 -1
- package/dist/test/cf.d.ts +10 -10
- package/dist/test/email.d.ts.map +1 -1
- package/dist/test/index.d.ts +1 -6
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/queue.d.ts.map +1 -1
- package/dist/test/remote-ai.d.ts.map +1 -1
- package/dist/test/remote-cloudflare.d.ts +13 -0
- package/dist/test/remote-cloudflare.d.ts.map +1 -0
- package/dist/test/remote-vectorize.d.ts.map +1 -1
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/test/scheduled.d.ts.map +1 -1
- package/dist/test/should-skip.d.ts +0 -18
- package/dist/test/should-skip.d.ts.map +1 -1
- package/dist/test/simple-context-durable-objects.d.ts +6 -0
- package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
- package/dist/test/simple-context-gateway-script.d.ts +2 -0
- package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
- package/dist/test/simple-context-paths.d.ts +40 -0
- package/dist/test/simple-context-paths.d.ts.map +1 -0
- package/dist/test/simple-context.d.ts +1 -23
- package/dist/test/simple-context.d.ts.map +1 -1
- package/dist/test/tail.d.ts.map +1 -1
- package/dist/test/worker.d.ts.map +1 -1
- package/dist/token-kedhcret.js +419 -0
- package/dist/token-m8jmnjwk.js +419 -0
- package/dist/{types-sffr9681.js → types-0sqwkp7x.js} +244 -139
- package/dist/types-1gwr2ex6.js +572 -0
- package/dist/types-6e5yx6km.js +572 -0
- package/dist/types-p0gckpn6.js +572 -0
- package/dist/utils/send-email.d.ts.map +1 -1
- package/dist/vite/config-file.d.ts.map +1 -1
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/worker-0srh2jfr.js +513 -0
- package/dist/worker-4xrfd10a.js +513 -0
- package/dist/worker-entry/composed-worker.d.ts +0 -7
- package/dist/worker-entry/composed-worker.d.ts.map +1 -1
- package/dist/worker-entry/surface-paths.d.ts +15 -0
- package/dist/worker-entry/surface-paths.d.ts.map +1 -0
- package/dist/worker-qtam8grz.js +513 -0
- package/dist/worker-qzm0b7br.js +513 -0
- package/dist/worker-y9ha6g44.js +513 -0
- package/package.json +17 -10
- package/R2.md +0 -200
- package/dist/account-8psavtg6.js +0 -420
- package/dist/build-n639efmn.js +0 -101
- package/dist/deploy-zvnq6xh7.js +0 -117
- package/dist/index-2q3pmzrx.js +0 -90
- package/dist/index-f4q0jbnj.js +0 -195
- package/dist/index-n7rs26ft.js +0 -77
- package/dist/index-tfyxa77h.js +0 -850
- package/dist/index-wyf3s77s.js +0 -343
- package/dist/test/multi-worker-context.d.ts +0 -114
- package/dist/test/multi-worker-context.d.ts.map +0 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLocalD1DatabaseIdentifier,
|
|
3
|
+
getLocalKVNamespaceIdentifier,
|
|
4
|
+
normalizeDOBinding
|
|
5
|
+
} from "./index-6psz1h4c.js";
|
|
6
|
+
import {
|
|
7
|
+
__require
|
|
8
|
+
} from "./index-37x76zdn.js";
|
|
9
|
+
|
|
10
|
+
// src/bridge/miniflare.ts
|
|
11
|
+
function generateGatewayScript() {
|
|
12
|
+
return `
|
|
13
|
+
// Gateway Worker — Provides RPC access to all bindings
|
|
14
|
+
export default {
|
|
15
|
+
async fetch(request, env, ctx) {
|
|
16
|
+
const url = new URL(request.url)
|
|
17
|
+
|
|
18
|
+
// Health check
|
|
19
|
+
if (url.pathname === '/_devflare/health') {
|
|
20
|
+
return new Response(JSON.stringify({ status: 'ok', bindings: Object.keys(env) }), {
|
|
21
|
+
headers: { 'Content-Type': 'application/json' }
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// RPC endpoint
|
|
26
|
+
if (url.pathname === '/_devflare/rpc' && request.method === 'POST') {
|
|
27
|
+
try {
|
|
28
|
+
const { method, params } = await request.json()
|
|
29
|
+
const result = await executeRpc(env, method, params)
|
|
30
|
+
return new Response(JSON.stringify({ ok: true, result }), {
|
|
31
|
+
headers: { 'Content-Type': 'application/json' }
|
|
32
|
+
})
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return new Response(JSON.stringify({
|
|
35
|
+
ok: false,
|
|
36
|
+
error: { code: 'RPC_ERROR', message: error.message }
|
|
37
|
+
}), {
|
|
38
|
+
status: 500,
|
|
39
|
+
headers: { 'Content-Type': 'application/json' }
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return new Response('Devflare Gateway', { status: 200 })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function executeRpc(env, method, params) {
|
|
49
|
+
const [bindingName, ...methodPath] = method.split('.')
|
|
50
|
+
const binding = env[bindingName]
|
|
51
|
+
const RAW_EMAIL = 'EmailMessage::raw'
|
|
52
|
+
|
|
53
|
+
if (!binding) {
|
|
54
|
+
throw new Error(\`Binding "\${bindingName}" not found\`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const methodName = methodPath.join('.')
|
|
58
|
+
|
|
59
|
+
// KV operations
|
|
60
|
+
if (methodName === 'get') return binding.get(params[0], params[1])
|
|
61
|
+
if (methodName === 'put') return binding.put(params[0], params[1], params[2])
|
|
62
|
+
if (methodName === 'delete') return binding.delete(params[0])
|
|
63
|
+
if (methodName === 'list') return binding.list(params[0])
|
|
64
|
+
if (methodName === 'getWithMetadata') return binding.getWithMetadata(params[0], params[1])
|
|
65
|
+
|
|
66
|
+
// R2 operations
|
|
67
|
+
if (methodName === 'head') return binding.head(params[0])
|
|
68
|
+
if (methodName === 'r2.get') return serializeR2Object(await binding.get(params[0], params[1]))
|
|
69
|
+
if (methodName === 'r2.put') return serializeR2Object(await binding.put(params[0], params[1], params[2]))
|
|
70
|
+
if (methodName === 'r2.delete') return binding.delete(params[0])
|
|
71
|
+
if (methodName === 'r2.list') return serializeR2Objects(await binding.list(params[0]))
|
|
72
|
+
|
|
73
|
+
// D1 operations
|
|
74
|
+
if (methodName === 'exec') return binding.exec(params[0])
|
|
75
|
+
if (methodName === 'batch') {
|
|
76
|
+
const statements = params[0].map(s => binding.prepare(s.sql).bind(...(s.bindings || [])))
|
|
77
|
+
return binding.batch(statements)
|
|
78
|
+
}
|
|
79
|
+
if (methodName.startsWith('stmt.')) {
|
|
80
|
+
const [, stmtMethod] = methodName.split('.')
|
|
81
|
+
const [sql, ...bindings] = params
|
|
82
|
+
const stmt = binding.prepare(sql).bind(...bindings.slice(0, -1))
|
|
83
|
+
|
|
84
|
+
if (stmtMethod === 'first') return stmt.first(bindings[bindings.length - 1])
|
|
85
|
+
if (stmtMethod === 'all') return stmt.all()
|
|
86
|
+
if (stmtMethod === 'run') return stmt.run()
|
|
87
|
+
if (stmtMethod === 'raw') return stmt.raw(bindings[bindings.length - 1])
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// DO operations
|
|
91
|
+
if (methodName === 'idFromName') {
|
|
92
|
+
const id = binding.idFromName(params[0])
|
|
93
|
+
return { __type: 'DOId', hex: id.toString() }
|
|
94
|
+
}
|
|
95
|
+
if (methodName === 'idFromString') {
|
|
96
|
+
const id = binding.idFromString(params[0])
|
|
97
|
+
return { __type: 'DOId', hex: id.toString() }
|
|
98
|
+
}
|
|
99
|
+
if (methodName === 'newUniqueId') {
|
|
100
|
+
const id = binding.newUniqueId(params[0])
|
|
101
|
+
return { __type: 'DOId', hex: id.toString() }
|
|
102
|
+
}
|
|
103
|
+
if (methodName === 'stub.fetch') {
|
|
104
|
+
const [, doId, serializedReq] = params
|
|
105
|
+
const id = binding.idFromString(doId.hex)
|
|
106
|
+
const stub = binding.get(id)
|
|
107
|
+
const response = await stub.fetch(new Request(serializedReq.url, {
|
|
108
|
+
method: serializedReq.method,
|
|
109
|
+
headers: serializedReq.headers,
|
|
110
|
+
body: serializedReq.body?.type === 'bytes' ? atob(serializedReq.body.data) : undefined
|
|
111
|
+
}))
|
|
112
|
+
return serializeResponse(response)
|
|
113
|
+
}
|
|
114
|
+
if (methodName === 'stub.rpc') {
|
|
115
|
+
// DO RPC: Call a method on the DO instance
|
|
116
|
+
const [, doId, rpcMethod, rpcParams] = params
|
|
117
|
+
const id = binding.idFromString(doId.hex)
|
|
118
|
+
const stub = binding.get(id)
|
|
119
|
+
|
|
120
|
+
// Use fetch to call the RPC endpoint
|
|
121
|
+
const response = await stub.fetch(new Request('http://do/_rpc', {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
headers: { 'Content-Type': 'application/json' },
|
|
124
|
+
body: JSON.stringify({ method: rpcMethod, params: rpcParams })
|
|
125
|
+
}))
|
|
126
|
+
|
|
127
|
+
const result = await response.json()
|
|
128
|
+
if (!result.ok) throw new Error(result.error?.message || 'RPC failed')
|
|
129
|
+
return result.result
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Queue operations
|
|
133
|
+
if (methodName === 'send') return binding.send(params[0], params[1])
|
|
134
|
+
if (methodName === 'sendBatch') return binding.sendBatch(params[0], params[1])
|
|
135
|
+
|
|
136
|
+
// Send Email operations
|
|
137
|
+
if (methodName === 'email.send') {
|
|
138
|
+
const message = params[0]
|
|
139
|
+
if (message && typeof message === 'object' && 'from' in message && 'to' in message && 'raw' in message) {
|
|
140
|
+
return binding.send({
|
|
141
|
+
from: message.from,
|
|
142
|
+
to: message.to,
|
|
143
|
+
[RAW_EMAIL]: createEmailMessageRaw(message.raw)
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
return binding.send(message)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Generic fallback
|
|
150
|
+
if (typeof binding[methodName] === 'function') {
|
|
151
|
+
return binding[methodName](...params)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
throw new Error(\`Unknown method: \${method}\`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function createEmailMessageRaw(raw) {
|
|
158
|
+
if (typeof raw === 'string' || raw instanceof ReadableStream) {
|
|
159
|
+
return raw
|
|
160
|
+
}
|
|
161
|
+
if (raw instanceof ArrayBuffer || raw instanceof Uint8Array) {
|
|
162
|
+
return new Response(raw).body
|
|
163
|
+
}
|
|
164
|
+
throw new Error('Unsupported EmailMessage raw payload')
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function serializeResponse(response) {
|
|
168
|
+
return {
|
|
169
|
+
status: response.status,
|
|
170
|
+
statusText: response.statusText,
|
|
171
|
+
headers: [...response.headers.entries()],
|
|
172
|
+
body: null // Will be streamed separately for large bodies
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function serializeR2Object(obj) {
|
|
177
|
+
if (!obj) return null
|
|
178
|
+
return {
|
|
179
|
+
key: obj.key,
|
|
180
|
+
version: obj.version,
|
|
181
|
+
size: obj.size,
|
|
182
|
+
etag: obj.etag,
|
|
183
|
+
httpEtag: obj.httpEtag,
|
|
184
|
+
uploaded: obj.uploaded?.toISOString(),
|
|
185
|
+
httpMetadata: obj.httpMetadata,
|
|
186
|
+
customMetadata: obj.customMetadata
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function serializeR2Objects(result) {
|
|
191
|
+
if (!result) return null
|
|
192
|
+
return {
|
|
193
|
+
objects: result.objects.map(serializeR2Object),
|
|
194
|
+
truncated: result.truncated,
|
|
195
|
+
cursor: result.cursor,
|
|
196
|
+
delimitedPrefixes: result.delimitedPrefixes
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
function hasNamedBindings(bindings) {
|
|
202
|
+
if (!bindings) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (Array.isArray(bindings)) {
|
|
206
|
+
return bindings.length > 0;
|
|
207
|
+
}
|
|
208
|
+
return Object.keys(bindings).length > 0;
|
|
209
|
+
}
|
|
210
|
+
function resolvePersistPath(options) {
|
|
211
|
+
if (!options.persist) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (typeof options.persist === "string" && options.persist.trim().length > 0) {
|
|
215
|
+
return options.persist;
|
|
216
|
+
}
|
|
217
|
+
return options.persistPath ?? ".devflare/data";
|
|
218
|
+
}
|
|
219
|
+
async function loadMiniflareRuntime() {
|
|
220
|
+
return await import("miniflare");
|
|
221
|
+
}
|
|
222
|
+
function createBaseMiniflareConfig(options, runtime) {
|
|
223
|
+
return {
|
|
224
|
+
modules: true,
|
|
225
|
+
script: generateGatewayScript(),
|
|
226
|
+
port: options.port ?? 8787,
|
|
227
|
+
host: "127.0.0.1",
|
|
228
|
+
log: options.verbose ? new runtime.Log(runtime.LogLevel.DEBUG) : new runtime.Log(runtime.LogLevel.WARN),
|
|
229
|
+
compatibilityDate: options.compatibilityDate ?? "2024-01-01",
|
|
230
|
+
compatibilityFlags: options.compatibilityFlags ?? []
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function applyKVNamespaceConfig(config, kvNamespaces, persistPath) {
|
|
234
|
+
if (!hasNamedBindings(kvNamespaces)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
config.kvNamespaces = kvNamespaces;
|
|
238
|
+
if (persistPath) {
|
|
239
|
+
config.kvPersist = `${persistPath}/kv`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function applyR2BucketConfig(config, r2Buckets, persistPath) {
|
|
243
|
+
if (!hasNamedBindings(r2Buckets)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
config.r2Buckets = r2Buckets;
|
|
247
|
+
if (persistPath) {
|
|
248
|
+
config.r2Persist = `${persistPath}/r2`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function applyD1DatabaseConfig(config, d1Databases, persistPath) {
|
|
252
|
+
if (!hasNamedBindings(d1Databases)) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
config.d1Databases = d1Databases;
|
|
256
|
+
if (persistPath) {
|
|
257
|
+
config.d1Persist = `${persistPath}/d1`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function applyDurableObjectConfig(config, durableObjects, persistPath) {
|
|
261
|
+
if (!durableObjects) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
config.durableObjects = durableObjects;
|
|
265
|
+
if (persistPath) {
|
|
266
|
+
config.durableObjectsPersist = `${persistPath}/do`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function applySendEmailConfig(config, sendEmail) {
|
|
270
|
+
if (!sendEmail) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
config.email = {
|
|
274
|
+
send_email: Object.entries(sendEmail).map(([name, emailConfig]) => ({
|
|
275
|
+
name,
|
|
276
|
+
...emailConfig.destinationAddress && {
|
|
277
|
+
destination_address: emailConfig.destinationAddress
|
|
278
|
+
},
|
|
279
|
+
...emailConfig.allowedDestinationAddresses && {
|
|
280
|
+
allowed_destination_addresses: emailConfig.allowedDestinationAddresses
|
|
281
|
+
},
|
|
282
|
+
...emailConfig.allowedSenderAddresses && {
|
|
283
|
+
allowed_sender_addresses: emailConfig.allowedSenderAddresses
|
|
284
|
+
}
|
|
285
|
+
}))
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function applyBindingsConfig(config, bindings) {
|
|
289
|
+
if (!bindings || Object.keys(bindings).length === 0) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
config.bindings = bindings;
|
|
293
|
+
}
|
|
294
|
+
function applyQueueConfig(config, queues) {
|
|
295
|
+
if (!queues?.length) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
config.queueProducers = Object.fromEntries(queues.map((queueName) => [queueName, { queueName }]));
|
|
299
|
+
}
|
|
300
|
+
function createMiniflareConfig(options, runtime) {
|
|
301
|
+
const persistPath = resolvePersistPath(options);
|
|
302
|
+
const config = createBaseMiniflareConfig(options, runtime);
|
|
303
|
+
applyKVNamespaceConfig(config, options.kvNamespaces, persistPath);
|
|
304
|
+
applyR2BucketConfig(config, options.r2Buckets, persistPath);
|
|
305
|
+
applyD1DatabaseConfig(config, options.d1Databases, persistPath);
|
|
306
|
+
applyDurableObjectConfig(config, options.durableObjects, persistPath);
|
|
307
|
+
applySendEmailConfig(config, options.sendEmail);
|
|
308
|
+
applyBindingsConfig(config, options.bindings);
|
|
309
|
+
applyQueueConfig(config, options.queues);
|
|
310
|
+
return config;
|
|
311
|
+
}
|
|
312
|
+
function createMiniflareInstanceHandle(mf) {
|
|
313
|
+
return {
|
|
314
|
+
ready: Promise.resolve(),
|
|
315
|
+
async dispose() {
|
|
316
|
+
await mf.dispose();
|
|
317
|
+
},
|
|
318
|
+
async getBindings() {
|
|
319
|
+
return mf.getBindings();
|
|
320
|
+
},
|
|
321
|
+
getKVNamespace: mf.getKVNamespace.bind(mf),
|
|
322
|
+
getR2Bucket: mf.getR2Bucket.bind(mf),
|
|
323
|
+
getD1Database: mf.getD1Database.bind(mf),
|
|
324
|
+
getDurableObjectNamespace: mf.getDurableObjectNamespace.bind(mf),
|
|
325
|
+
dispatchFetch: mf.dispatchFetch.bind(mf),
|
|
326
|
+
_mf: mf
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
async function startMiniflare(options = {}) {
|
|
330
|
+
const runtime = await loadMiniflareRuntime();
|
|
331
|
+
const mf = new runtime.Miniflare(createMiniflareConfig(options, runtime));
|
|
332
|
+
await mf.ready;
|
|
333
|
+
return createMiniflareInstanceHandle(mf);
|
|
334
|
+
}
|
|
335
|
+
async function startMiniflareFromConfig(config, options = {}) {
|
|
336
|
+
const bindings = config.bindings ?? {};
|
|
337
|
+
const mfOptions = {
|
|
338
|
+
...options,
|
|
339
|
+
compatibilityDate: config.compatibilityDate,
|
|
340
|
+
compatibilityFlags: config.compatibilityFlags,
|
|
341
|
+
kvNamespaces: bindings.kv ? Object.fromEntries(Object.entries(bindings.kv).map(([bindingName, bindingConfig]) => {
|
|
342
|
+
return [bindingName, getLocalKVNamespaceIdentifier(bindingConfig)];
|
|
343
|
+
})) : undefined,
|
|
344
|
+
r2Buckets: bindings.r2 ? bindings.r2 : undefined,
|
|
345
|
+
d1Databases: bindings.d1 ? Object.fromEntries(Object.entries(bindings.d1).map(([bindingName, bindingConfig]) => {
|
|
346
|
+
return [bindingName, getLocalD1DatabaseIdentifier(bindingConfig)];
|
|
347
|
+
})) : undefined,
|
|
348
|
+
queues: bindings.queues?.consumers?.map((c) => c.queue),
|
|
349
|
+
sendEmail: bindings.sendEmail ? bindings.sendEmail : undefined,
|
|
350
|
+
bindings: config.vars,
|
|
351
|
+
durableObjects: bindings.durableObjects ? Object.fromEntries(Object.entries(bindings.durableObjects).map(([bindingName, doConfig]) => {
|
|
352
|
+
const normalized = normalizeDOBinding(doConfig);
|
|
353
|
+
return [
|
|
354
|
+
bindingName,
|
|
355
|
+
{
|
|
356
|
+
className: normalized.className,
|
|
357
|
+
scriptPath: normalized.scriptName
|
|
358
|
+
}
|
|
359
|
+
];
|
|
360
|
+
})) : undefined
|
|
361
|
+
};
|
|
362
|
+
return startMiniflare(mfOptions);
|
|
363
|
+
}
|
|
364
|
+
var globalMiniflare = null;
|
|
365
|
+
async function getMiniflare(options) {
|
|
366
|
+
if (!globalMiniflare) {
|
|
367
|
+
globalMiniflare = await startMiniflare(options);
|
|
368
|
+
}
|
|
369
|
+
return globalMiniflare;
|
|
370
|
+
}
|
|
371
|
+
async function stopMiniflare() {
|
|
372
|
+
if (globalMiniflare) {
|
|
373
|
+
await globalMiniflare.dispose();
|
|
374
|
+
globalMiniflare = null;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export { startMiniflare, startMiniflareFromConfig, getMiniflare, stopMiniflare };
|