devflare 1.0.0-next.16 → 1.0.0-next.18
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 +688 -229
- package/README.md +70 -8
- package/bin/devflare.js +1 -1
- package/dist/{account-fw8nafav.js → account-0evqkmnc.js} +8 -8
- package/dist/{account-0w8wdzjv.js → account-0v11zbzk.js} +9 -9
- package/dist/{account-eygq6qx7.js → account-2w85efas.js} +9 -9
- package/dist/{account-pzq69nys.js → account-61gw9s7t.js} +9 -9
- package/dist/account-65sk9q34.js +475 -0
- package/dist/account-77vx7q2f.js +475 -0
- package/dist/account-7z38mgqf.js +475 -0
- package/dist/account-8wgprpbt.js +475 -0
- package/dist/account-9gt3tej1.js +475 -0
- package/dist/account-dtndtbad.js +475 -0
- package/dist/account-e95v7f4s.js +475 -0
- package/dist/account-fbyyptg7.js +475 -0
- package/dist/account-gnzhz1c9.js +475 -0
- package/dist/account-m6jq6fnp.js +475 -0
- package/dist/account-mvnfagh9.js +475 -0
- package/dist/account-p0crq2gh.js +475 -0
- package/dist/account-qkcevx7a.js +475 -0
- package/dist/account-txwqg1rx.js +475 -0
- package/dist/account-w5n5bjh2.js +475 -0
- package/dist/account-zd61t0ey.js +475 -0
- package/dist/api-11gkk043.js +33 -0
- package/dist/api-2n6dd2ws.js +33 -0
- package/dist/api-dbxvch9h.js +33 -0
- package/dist/api-p9hf69kr.js +33 -0
- package/dist/api-r10j00ev.js +33 -0
- package/dist/api-senf2569.js +33 -0
- package/dist/api-swcgnp72.js +33 -0
- package/dist/{api-d6ekexs5.js → api-th82mps4.js} +3 -1
- package/dist/bridge/client.d.ts +29 -6
- package/dist/bridge/client.d.ts.map +1 -1
- package/dist/bridge/gateway-runtime.d.ts +8 -0
- package/dist/bridge/gateway-runtime.d.ts.map +1 -0
- package/dist/bridge/index.d.ts +2 -2
- package/dist/bridge/index.d.ts.map +1 -1
- package/dist/bridge/log.d.ts +5 -0
- package/dist/bridge/log.d.ts.map +1 -0
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +7 -5
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/serialization.d.ts +36 -16
- package/dist/bridge/serialization.d.ts.map +1 -1
- package/dist/bridge/server.d.ts +1 -0
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/bridge/v2/body-streams.d.ts +53 -0
- package/dist/bridge/v2/body-streams.d.ts.map +1 -0
- package/dist/bridge/v2/codec.d.ts +106 -0
- package/dist/bridge/v2/codec.d.ts.map +1 -0
- package/dist/bridge/v2/control-messages.d.ts +51 -0
- package/dist/bridge/v2/control-messages.d.ts.map +1 -0
- package/dist/bridge/v2/frames.d.ts +109 -0
- package/dist/bridge/v2/frames.d.ts.map +1 -0
- package/dist/bridge/v2/index.d.ts +11 -0
- package/dist/bridge/v2/index.d.ts.map +1 -0
- package/dist/bridge/v2/legacy-protocol.d.ts +146 -0
- package/dist/bridge/v2/legacy-protocol.d.ts.map +1 -0
- package/dist/bridge/v2/legacy-serialization.d.ts +103 -0
- package/dist/bridge/v2/legacy-serialization.d.ts.map +1 -0
- package/dist/bridge/v2/serialization.d.ts +48 -0
- package/dist/bridge/v2/serialization.d.ts.map +1 -0
- package/dist/bridge/v2/transport.d.ts +31 -0
- package/dist/bridge/v2/transport.d.ts.map +1 -0
- package/dist/bridge/v2/value-codec.d.ts +61 -0
- package/dist/bridge/v2/value-codec.d.ts.map +1 -0
- package/dist/bridge/v2/value-serialization.d.ts +103 -0
- package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
- package/dist/bridge/v2/wire.d.ts +170 -0
- package/dist/bridge/v2/wire.d.ts.map +1 -0
- package/dist/bridge/v2/ws-relay.d.ts +53 -0
- package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
- package/dist/browser-shim/server.d.ts +63 -0
- package/dist/browser-shim/server.d.ts.map +1 -1
- package/dist/browser.d.ts +396 -38
- package/dist/browser.d.ts.map +1 -1
- package/dist/{src/browser.js → browser.js} +19 -33
- package/dist/build-07mjrvsn.js +53 -0
- package/dist/build-0rfr8k1s.js +53 -0
- package/dist/build-1313sg73.js +52 -0
- package/dist/build-1hnntbks.js +53 -0
- package/dist/build-1r3myv0k.js +53 -0
- package/dist/build-28561w5v.js +54 -0
- package/dist/build-50yqpwb3.js +54 -0
- package/dist/build-55z8psd6.js +53 -0
- package/dist/build-5b9wj2p0.js +53 -0
- package/dist/build-5frhzh1m.js +53 -0
- package/dist/{build-p3r3117t.js → build-6ye9vnab.js} +8 -9
- package/dist/build-8gv18jrq.js +52 -0
- package/dist/build-9bgqypy6.js +53 -0
- package/dist/{build-506kjhcm.js → build-9em4ymqn.js} +12 -13
- package/dist/build-eh3x12qc.js +52 -0
- package/dist/build-emhyycp7.js +53 -0
- package/dist/build-f1m9jn7b.js +53 -0
- package/dist/build-ffe72jjv.js +54 -0
- package/dist/build-fx90y6za.js +53 -0
- package/dist/build-h31egsze.js +53 -0
- package/dist/build-hpczwagb.js +53 -0
- package/dist/{build-1kmkwqgh.js → build-hpkbanpw.js} +16 -15
- package/dist/build-j2re91xe.js +54 -0
- package/dist/{build-66866ahs.js → build-j78389rg.js} +12 -13
- package/dist/build-m3kckn5g.js +53 -0
- package/dist/build-mf3thcjm.js +53 -0
- package/dist/build-n3n5bv37.js +52 -0
- package/dist/build-ngfy4v5x.js +53 -0
- package/dist/build-pr843h0d.js +52 -0
- package/dist/build-qyg2b45p.js +52 -0
- package/dist/build-r6884kyt.js +53 -0
- package/dist/build-re370wkf.js +53 -0
- package/dist/build-vvndgwg0.js +52 -0
- package/dist/build-wp559jkf.js +54 -0
- package/dist/{build-g1adm3ww.js → build-x4r67275.js} +12 -13
- package/dist/build-xp4pfhvv.js +52 -0
- package/dist/build-y489r2h9.js +54 -0
- package/dist/build-y6g4bvx5.js +52 -0
- package/dist/build-yvn0yhwx.js +52 -0
- package/dist/build-z4vmhs5c.js +53 -0
- package/dist/bundler/defaults.d.ts +23 -0
- package/dist/bundler/defaults.d.ts.map +1 -0
- package/dist/bundler/do-bundler.d.ts.map +1 -1
- package/dist/bundler/index.d.ts +1 -0
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/rolldown-shared.d.ts +29 -0
- package/dist/bundler/rolldown-shared.d.ts.map +1 -1
- package/dist/bundler/worker-bundler.d.ts.map +1 -1
- package/dist/bundler/worker-compat.d.ts.map +1 -1
- package/dist/cli/build-manifest.d.ts +54 -0
- package/dist/cli/build-manifest.d.ts.map +1 -0
- package/dist/cli/commands/build-artifacts.d.ts +13 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -1
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/dependencies.d.ts +1 -0
- package/dist/cli/dependencies.d.ts.map +1 -1
- package/dist/cli/deploy-strategy.d.ts +3 -3
- package/dist/cli/deploy-strategy.d.ts.map +1 -1
- package/dist/cli/help-pages/pages/core.d.ts.map +1 -1
- package/dist/cli/index.js +12 -0
- package/dist/cli/preview-bindings.d.ts +8 -1
- package/dist/cli/preview-bindings.d.ts.map +1 -1
- package/dist/cli/preview.d.ts +1 -2
- package/dist/cli/preview.d.ts.map +1 -1
- package/dist/cloudflare/account-resources.d.ts.map +1 -1
- package/dist/cloudflare/api.d.ts +67 -3
- package/dist/cloudflare/api.d.ts.map +1 -1
- package/dist/cloudflare/auth.d.ts.map +1 -1
- package/dist/{src/cloudflare → cloudflare}/index.js +7 -7
- package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
- package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
- package/dist/cloudflare/kv-namespace.d.ts +2 -1
- package/dist/cloudflare/kv-namespace.d.ts.map +1 -1
- package/dist/cloudflare/preferences.d.ts +7 -0
- package/dist/cloudflare/preferences.d.ts.map +1 -1
- package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
- package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-records.d.ts +3 -60
- package/dist/cloudflare/preview-registry-records.d.ts.map +1 -1
- package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
- package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
- package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
- package/dist/cloudflare/preview-urls.d.ts +3 -0
- package/dist/cloudflare/preview-urls.d.ts.map +1 -0
- package/dist/cloudflare/tokens.d.ts +23 -0
- package/dist/cloudflare/tokens.d.ts.map +1 -1
- package/dist/cloudflare/types.d.ts +1 -1
- package/dist/cloudflare/types.d.ts.map +1 -1
- package/dist/cloudflare/usage.d.ts +30 -2
- package/dist/cloudflare/usage.d.ts.map +1 -1
- package/dist/config/binding-resolution-helpers.d.ts +36 -0
- package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
- package/dist/config/compatibility.d.ts +3 -0
- package/dist/config/compatibility.d.ts.map +1 -0
- package/dist/config/compiler.d.ts +61 -20
- package/dist/config/compiler.d.ts.map +1 -1
- package/dist/config/deploy-resources.d.ts +58 -0
- package/dist/config/deploy-resources.d.ts.map +1 -0
- package/dist/config/index.d.ts +5 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/preview-resources.d.ts +6 -0
- package/dist/config/preview-resources.d.ts.map +1 -1
- package/dist/config/preview.d.ts.map +1 -1
- package/dist/config/ref.d.ts +14 -1
- package/dist/config/ref.d.ts.map +1 -1
- package/dist/config/resolve-phased.d.ts +72 -0
- package/dist/config/resolve-phased.d.ts.map +1 -0
- package/dist/config/resolve.d.ts +7 -0
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resource-resolution.d.ts +26 -6
- package/dist/config/resource-resolution.d.ts.map +1 -1
- package/dist/config/schema-bindings.d.ts +262 -0
- package/dist/config/schema-bindings.d.ts.map +1 -1
- package/dist/config/schema-env.d.ts +375 -39
- package/dist/config/schema-env.d.ts.map +1 -1
- package/dist/config/schema-normalization.d.ts +26 -2
- package/dist/config/schema-normalization.d.ts.map +1 -1
- package/dist/config/schema.d.ts +994 -63
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/service-bindings-validation.d.ts +36 -0
- package/dist/config/service-bindings-validation.d.ts.map +1 -0
- package/dist/{config-hwdqjse7.js → config-1japnjmx.js} +5 -5
- package/dist/{config-q0g5qdga.js → config-287wjn1m.js} +6 -6
- package/dist/{config-fjwke42y.js → config-4x6vq82e.js} +6 -6
- package/dist/{config-pxvewrhv.js → config-5n0avhcx.js} +6 -6
- package/dist/config-70s2ap5j.js +59 -0
- package/dist/config-7hge8ze6.js +59 -0
- package/dist/config-7rbp7aek.js +59 -0
- package/dist/config-b8xbbmta.js +59 -0
- package/dist/config-baee5690.js +59 -0
- package/dist/config-bczpc1ey.js +59 -0
- package/dist/{src/config-entry.js → config-entry.js} +3 -3
- package/dist/config-fhmwzaw6.js +59 -0
- package/dist/config-g9vkfa4x.js +59 -0
- package/dist/config-gpexkzth.js +59 -0
- package/dist/config-nspw7sgv.js +59 -0
- package/dist/config-ntm4x9wt.js +59 -0
- package/dist/config-nv6hfpg6.js +59 -0
- package/dist/config-pjc33wew.js +59 -0
- package/dist/config-pnz2e8s3.js +59 -0
- package/dist/config-qts6nh6g.js +59 -0
- package/dist/config-sg2xrdt4.js +59 -0
- package/dist/config-vzwckat3.js +59 -0
- package/dist/config-x90dkmm7.js +59 -0
- package/dist/{src/decorators → decorators}/index.js +2 -2
- package/dist/deploy-1s6nv5rp.js +921 -0
- package/dist/{deploy-ykpcjkc2.js → deploy-30ph1rrd.js} +263 -32
- package/dist/{deploy-ex4g5avz.js → deploy-39dmfn9d.js} +338 -38
- package/dist/deploy-44n2pshy.js +1016 -0
- package/dist/deploy-45qxpsfe.js +921 -0
- package/dist/deploy-64e57w1g.js +1040 -0
- package/dist/deploy-82j43vta.js +1040 -0
- package/dist/deploy-99m8qhpa.js +1041 -0
- package/dist/deploy-9twkd32f.js +1040 -0
- package/dist/deploy-a2eq2c1n.js +1040 -0
- package/dist/{deploy-csfhdr64.js → deploy-a3pb1qs5.js} +259 -29
- package/dist/deploy-agbtfm04.js +921 -0
- package/dist/{deploy-jnb0bhka.js → deploy-aswbtbf3.js} +361 -49
- package/dist/deploy-bqf3kxy5.js +972 -0
- package/dist/deploy-fv4z648h.js +921 -0
- package/dist/deploy-gsybda2f.js +1038 -0
- package/dist/deploy-h17nzysm.js +921 -0
- package/dist/deploy-hc89h4wg.js +1045 -0
- package/dist/deploy-jey5pnqn.js +1040 -0
- package/dist/deploy-jv0yfqvk.js +1040 -0
- package/dist/deploy-kn3z6spd.js +941 -0
- package/dist/deploy-m22xmz9w.js +921 -0
- package/dist/deploy-nefp2njy.js +1038 -0
- package/dist/deploy-ppp8pg6w.js +1038 -0
- package/dist/deploy-qah2eag6.js +1041 -0
- package/dist/deploy-qdq2gpad.js +1045 -0
- package/dist/deploy-r1yf8913.js +1038 -0
- package/dist/deploy-r8nam9rr.js +1038 -0
- package/dist/deploy-rrm4a0xw.js +921 -0
- package/dist/deploy-s0tfnc12.js +1040 -0
- package/dist/deploy-s636ks9k.js +1041 -0
- package/dist/deploy-sany8t54.js +1045 -0
- package/dist/deploy-skqn61j3.js +1038 -0
- package/dist/deploy-smv2870h.js +921 -0
- package/dist/deploy-sp16nxs5.js +972 -0
- package/dist/deploy-sr805bvq.js +921 -0
- package/dist/deploy-t9dehmn0.js +1041 -0
- package/dist/deploy-taxt7njz.js +1041 -0
- package/dist/deploy-tnfvfh9m.js +1040 -0
- package/dist/deploy-w5f8db4s.js +1040 -0
- package/dist/deploy-wsxcectr.js +921 -0
- package/dist/deploy-xyfbhj3v.js +1038 -0
- package/dist/deploy-yv1y5xaa.js +921 -0
- package/dist/deploy-z3ejw37k.js +1040 -0
- package/dist/{dev-8nssqatr.js → dev-02tgdc4f.js} +199 -448
- package/dist/dev-0tqhveye.js +2314 -0
- package/dist/dev-3dj2gkfq.js +2314 -0
- package/dist/dev-3e0etsww.js +2314 -0
- package/dist/dev-47dk7c13.js +2314 -0
- package/dist/dev-4a2a31cm.js +2314 -0
- package/dist/dev-4w1stcn8.js +2427 -0
- package/dist/dev-5wkh1z4a.js +2188 -0
- package/dist/dev-6t22zmey.js +2350 -0
- package/dist/dev-89p1sdv7.js +2395 -0
- package/dist/dev-8d1gxjky.js +2427 -0
- package/dist/dev-8yawx3cv.js +2314 -0
- package/dist/dev-9h4p8a0c.js +2393 -0
- package/dist/dev-9xmttj4c.js +2314 -0
- package/dist/dev-at6gy2td.js +2427 -0
- package/dist/dev-bkbz97z0.js +2314 -0
- package/dist/{dev-grznx8fn.js → dev-ct3344kv.js} +199 -448
- package/dist/{dev-7ef5e2j1.js → dev-dg8dh5c1.js} +123 -298
- package/dist/dev-dr5jb965.js +2427 -0
- package/dist/dev-e4sjqtbq.js +2314 -0
- package/dist/dev-ecq26mg4.js +2350 -0
- package/dist/dev-ef237vgp.js +2324 -0
- package/dist/dev-enbdg4st.js +2314 -0
- package/dist/dev-jcrxg8hq.js +2160 -0
- package/dist/dev-jk0gqges.js +2432 -0
- package/dist/dev-k62936am.js +2314 -0
- package/dist/dev-k8ptbvrs.js +2160 -0
- package/dist/dev-kqm107h4.js +2422 -0
- package/dist/dev-n0gx7eya.js +2350 -0
- package/dist/dev-n23m6rtb.js +2314 -0
- package/dist/dev-ny8fmkzg.js +2432 -0
- package/dist/dev-p1c65cga.js +2386 -0
- package/dist/dev-p4fjbb4h.js +2395 -0
- package/dist/dev-pnfcv79z.js +2160 -0
- package/dist/dev-qnrrv5ey.js +2393 -0
- package/dist/dev-qqysg50t.js +2427 -0
- package/dist/dev-r9f3n11q.js +2410 -0
- package/dist/dev-s0815dw4.js +2427 -0
- package/dist/dev-s4tpkg60.js +2314 -0
- package/dist/dev-s82fcesg.js +2314 -0
- package/dist/dev-s9sz53me.js +2401 -0
- package/dist/dev-sdka7z0d.js +2427 -0
- package/dist/dev-server/d1-migrations.d.ts +22 -0
- package/dist/dev-server/d1-migrations.d.ts.map +1 -1
- package/dist/dev-server/dev-server-state.d.ts +56 -0
- package/dist/dev-server/dev-server-state.d.ts.map +1 -0
- package/dist/dev-server/gateway-script.d.ts +14 -1
- package/dist/dev-server/gateway-script.d.ts.map +1 -1
- package/dist/dev-server/miniflare-bindings.d.ts +16 -0
- package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
- package/dist/dev-server/miniflare-dev-config.d.ts +30 -0
- package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
- package/dist/dev-server/miniflare-worker-config.d.ts +44 -0
- package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
- package/dist/dev-server/reload-queue.d.ts +13 -0
- package/dist/dev-server/reload-queue.d.ts.map +1 -0
- package/dist/dev-server/server-startup-helpers.d.ts +84 -0
- package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/dev-server/vite-utils.d.ts +18 -0
- package/dist/dev-server/vite-utils.d.ts.map +1 -1
- package/dist/dev-server/worker-source-watcher.d.ts +6 -0
- package/dist/dev-server/worker-source-watcher.d.ts.map +1 -1
- package/dist/dev-t3tjscah.js +2350 -0
- package/dist/dev-t50kdb1j.js +2338 -0
- package/dist/dev-t5xf55pt.js +2314 -0
- package/dist/dev-t63c44bb.js +2314 -0
- package/dist/dev-wg3d38sy.js +2433 -0
- package/dist/dev-wh4rfgsh.js +2427 -0
- package/dist/{dev-2pd33m28.js → dev-wjh8gdd1.js} +200 -325
- package/dist/dev-xzxy9qvq.js +2314 -0
- package/dist/dev-yymaq4ph.js +2392 -0
- package/dist/dev-zg2w2ve3.js +2422 -0
- package/dist/dev-zsb2xk1x.js +2427 -0
- package/dist/dev-zty3yhzg.js +2324 -0
- package/dist/{doctor-04ammrrh.js → doctor-3mqavqg3.js} +10 -10
- package/dist/{doctor-fzkznce1.js → doctor-5nek32fz.js} +10 -10
- package/dist/{doctor-sa5xv1bz.js → doctor-7ra1w0sk.js} +10 -10
- package/dist/doctor-ak830a0k.js +245 -0
- package/dist/doctor-bye3cs8a.js +245 -0
- package/dist/{doctor-fmjj65mc.js → doctor-c5m9pmwq.js} +8 -8
- package/dist/doctor-cqfkgxvw.js +245 -0
- package/dist/doctor-e1h9mhzp.js +245 -0
- package/dist/doctor-fmqsrafk.js +245 -0
- package/dist/doctor-hgs7wr5g.js +245 -0
- package/dist/doctor-j8ytsy94.js +245 -0
- package/dist/doctor-mcmkgp6e.js +245 -0
- package/dist/doctor-qb6m2exc.js +245 -0
- package/dist/doctor-qq4tsh8q.js +245 -0
- package/dist/doctor-tecv869a.js +245 -0
- package/dist/doctor-wg0245pe.js +245 -0
- package/dist/doctor-z3jfqxtz.js +245 -0
- package/dist/durable-object-4hey8fgy.js +13 -0
- package/dist/durable-object-v3gsnybk.js +13 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index-0krb65s3.js +215 -0
- package/dist/index-0mantew0.js +513 -0
- package/dist/{index-p03n4qet.js → index-0mezg6ar.js} +26 -21
- package/dist/{index-mqekt778.js → index-0tk2rs0q.js} +1 -1
- package/dist/{index-h18pxvzs.js → index-124e9t4t.js} +1 -1
- package/dist/{index-na3mnm1k.js → index-1546yrn0.js} +2 -2
- package/dist/index-15fpa5tx.js +232 -0
- package/dist/{index-jb75kwa4.js → index-18mp5v50.js} +33 -14
- package/dist/{index-4v9bc2pc.js → index-195tc6qh.js} +26 -21
- package/dist/{index-0kfzdywd.js → index-1bg8w2gf.js} +1 -1
- package/dist/index-1d4jg11n.js +542 -0
- package/dist/index-1e2qtrmj.js +188 -0
- package/dist/{index-v5nmqthy.js → index-1ghhgb9d.js} +2 -2
- package/dist/index-1nhd9nkd.js +232 -0
- package/dist/{index-6psz1h4c.js → index-1wn8mjep.js} +116 -96
- package/dist/index-1xhd5czz.js +185 -0
- package/dist/index-2a2g4fwp.js +993 -0
- package/dist/{index-fvsadj32.js → index-2bmtj21z.js} +2 -2
- package/dist/{index-816krz9p.js → index-2dpmd14d.js} +1 -1
- package/dist/{index-3ke5d2vn.js → index-2fa0afdp.js} +173 -30
- package/dist/{index-d8etnfef.js → index-2rcrefqd.js} +173 -30
- package/dist/index-2t2m5148.js +1372 -0
- package/dist/index-2vbzamev.js +437 -0
- package/dist/index-2vdep9h0.js +993 -0
- package/dist/{index-zfhq6s96.js → index-2y90j9cz.js} +2 -2
- package/dist/index-33ep0z9x.js +385 -0
- package/dist/index-37jgbaw6.js +1372 -0
- package/dist/index-380ncsqc.js +977 -0
- package/dist/{index-thna1tkd.js → index-3e1x39fc.js} +111 -26
- package/dist/index-3e7by9sy.js +223 -0
- package/dist/{index-xk9djfjp.js → index-3egad6wm.js} +34 -15
- package/dist/index-3f8rzmjw.js +232 -0
- package/dist/index-3vd4r37r.js +1372 -0
- package/dist/index-3vgn5e89.js +1682 -0
- package/dist/index-3x7k3t0f.js +513 -0
- package/dist/index-3xfe2dst.js +399 -0
- package/dist/index-464j1zb4.js +513 -0
- package/dist/{index-pnbs1b8k.js → index-48rxsj95.js} +110 -25
- package/dist/index-4bezcdd1.js +385 -0
- package/dist/index-4fp11z9e.js +973 -0
- package/dist/{index-m3fmw6mx.js → index-4knecthc.js} +2 -2
- package/dist/index-502y7w13.js +538 -0
- package/dist/index-50mxxb4q.js +185 -0
- package/dist/index-5achzspr.js +185 -0
- package/dist/index-5ef3jmv7.js +1372 -0
- package/dist/index-5eswe8yv.js +844 -0
- package/dist/index-5gevxfgs.js +513 -0
- package/dist/index-5gmf048z.js +817 -0
- package/dist/index-5jtkxpjf.js +971 -0
- package/dist/{index-72mve6vh.js → index-5m85bd9x.js} +1 -1
- package/dist/{index-4rrttqj5.js → index-5n5nn0a8.js} +62 -176
- package/dist/index-5p3bgjwr.js +808 -0
- package/dist/index-5vzcszr2.js +1230 -0
- package/dist/index-5w77r4w9.js +513 -0
- package/dist/index-62srkqcm.js +168 -0
- package/dist/index-63cgqe43.js +1372 -0
- package/dist/index-65e7xx1a.js +19 -0
- package/dist/index-65qrje14.js +185 -0
- package/dist/index-66sx3b3v.js +385 -0
- package/dist/{index-b8m6883k.js → index-678j0n13.js} +2 -2
- package/dist/{index-epw1jxz5.js → index-6ftrth7n.js} +194 -180
- package/dist/index-6g90pvxa.js +215 -0
- package/dist/index-6j4m5x2d.js +1372 -0
- package/dist/{index-7v583xan.js → index-6jwpke14.js} +13 -46
- package/dist/index-6knsjvxh.js +1372 -0
- package/dist/index-6kwq6yf8.js +979 -0
- package/dist/index-6mg4yvc6.js +74 -0
- package/dist/{index-e9yw4d6y.js → index-6phry941.js} +5 -5
- package/dist/index-6r59wbek.js +232 -0
- package/dist/index-6sf815ps.js +74 -0
- package/dist/index-6zd89k6y.js +1230 -0
- package/dist/{index-ry131z23.js → index-71rwg0cn.js} +62 -176
- package/dist/index-75ex2m0x.js +695 -0
- package/dist/{index-htzf0py1.js → index-79exzs3q.js} +194 -180
- package/dist/{index-1sp39f2f.js → index-7bxj118m.js} +62 -176
- package/dist/index-7c6np4mq.js +397 -0
- package/dist/{index-7x0ybbtx.js → index-7cm339qz.js} +5 -5
- package/dist/index-7e359eb5.js +895 -0
- package/dist/index-7eqyr4j8.js +70 -0
- package/dist/index-7k278fgz.js +273 -0
- package/dist/index-7kazxkjt.js +1372 -0
- package/dist/index-7m0x8m9r.js +844 -0
- package/dist/index-7p74smg8.js +1372 -0
- package/dist/index-7q8fke3k.js +188 -0
- package/dist/index-7qk6eafn.js +1682 -0
- package/dist/{index-yzddwp02.js → index-7vbjt6ba.js} +110 -93
- package/dist/{index-7kcxjhta.js → index-7z4b0vgd.js} +19 -5
- package/dist/index-82xn4azv.js +74 -0
- package/dist/index-83wns7cz.js +70 -0
- package/dist/index-852945d4.js +413 -0
- package/dist/{index-8t5nb4qx.js → index-86rvj79f.js} +5 -5
- package/dist/index-88tcq0t4.js +542 -0
- package/dist/{index-q4kaz181.js → index-8evn52g1.js} +279 -268
- package/dist/index-8jkf4nsd.js +695 -0
- package/dist/{index-sqrksgb2.js → index-8nx4ce3e.js} +7 -7
- package/dist/index-8q1bcnrh.js +1372 -0
- package/dist/index-8t5gynct.js +971 -0
- package/dist/index-905svbb6.js +470 -0
- package/dist/index-94cb0sac.js +1372 -0
- package/dist/index-95mmvbw7.js +538 -0
- package/dist/index-97x94h0m.js +438 -0
- package/dist/index-9an9qqr1.js +728 -0
- package/dist/index-9d125myk.js +1372 -0
- package/dist/index-9gg0kqw0.js +470 -0
- package/dist/index-9ryw7mcw.js +971 -0
- package/dist/index-a3e13a7m.js +478 -0
- package/dist/index-a6j44jmr.js +1372 -0
- package/dist/index-a75ejnvt.js +1711 -0
- package/dist/index-ab2nck1h.js +1372 -0
- package/dist/index-abrqnq3e.js +488 -0
- package/dist/index-afjbpgb1.js +1218 -0
- package/dist/index-at89fpde.js +470 -0
- package/dist/{index-cgbvmse6.js → index-awr0tp6p.js} +1 -1
- package/dist/index-b1be9bdh.js +1372 -0
- package/dist/index-b1xs3wc4.js +513 -0
- package/dist/index-b50x7seh.js +513 -0
- package/dist/{index-9az6s7ad.js → index-b5ra8w3q.js} +1 -1
- package/dist/index-b64sbzgv.js +884 -0
- package/dist/index-b7r8ntpm.js +1372 -0
- package/dist/index-ba9gyy13.js +513 -0
- package/dist/{index-k29yjhv0.js → index-bb66mn7p.js} +1 -1
- package/dist/index-bc5pvbbd.js +1193 -0
- package/dist/index-bj0mk3dw.js +74 -0
- package/dist/index-bj3a8dr0.js +1372 -0
- package/dist/index-bk3eez1g.js +513 -0
- package/dist/index-btjx137w.js +774 -0
- package/dist/index-btrfqp9h.js +133 -0
- package/dist/index-bx6gangy.js +402 -0
- package/dist/index-c0tc0yts.js +471 -0
- package/dist/{index-6jef5emv.js → index-c0whkev9.js} +27 -3
- package/dist/index-ca96qkva.js +1372 -0
- package/dist/index-cdtzkedk.js +993 -0
- package/dist/index-cejgenma.js +1372 -0
- package/dist/index-cp8jt5pr.js +52 -0
- package/dist/index-cpz69pek.js +1372 -0
- package/dist/{index-gs4y9gdf.js → index-crrdegk5.js} +2 -2
- package/dist/index-cskszwkx.js +1372 -0
- package/dist/index-cxf22a0s.js +74 -0
- package/dist/index-cy3c3w81.js +270 -0
- package/dist/index-d5dgb1j6.js +74 -0
- package/dist/index-da397xcx.js +1372 -0
- package/dist/index-damyy8bw.js +1372 -0
- package/dist/{index-x9cwdxw5.js → index-dd6fwwmq.js} +3 -3
- package/dist/index-dh1954bp.js +52 -0
- package/dist/index-djp2wd1f.js +1372 -0
- package/dist/{index-0apbm26n.js → index-dmbdj6va.js} +111 -94
- package/dist/index-dmf76tac.js +1372 -0
- package/dist/index-dphr32gc.js +420 -0
- package/dist/index-dxh2qyyw.js +52 -0
- package/dist/index-dzayfxjy.js +492 -0
- package/dist/index-e05q77kt.js +397 -0
- package/dist/index-e11b1fb2.js +495 -0
- package/dist/index-e3zvspqj.js +968 -0
- package/dist/index-e4tzzbn9.js +1372 -0
- package/dist/index-e5ct1gwb.js +1372 -0
- package/dist/index-e7ptcz1a.js +1372 -0
- package/dist/index-e7wt0203.js +513 -0
- package/dist/{index-61jsjnsv.js → index-ebwsvf9t.js} +110 -25
- package/dist/index-ed73jn3d.js +185 -0
- package/dist/index-ed7n5d07.js +185 -0
- package/dist/index-ejs2a4kd.js +513 -0
- package/dist/index-esjrgt3y.js +467 -0
- package/dist/index-ev03khsd.js +513 -0
- package/dist/index-f1gsqm54.js +168 -0
- package/dist/index-f90314kt.js +52 -0
- package/dist/index-f9mhsept.js +185 -0
- package/dist/index-fa6zwffw.js +70 -0
- package/dist/index-fama7kpt.js +52 -0
- package/dist/index-fgk87mk2.js +1067 -0
- package/dist/index-fkyvxe4b.js +968 -0
- package/dist/index-g0h40xke.js +513 -0
- package/dist/index-g0rqh52c.js +385 -0
- package/dist/{index-0eqksag4.js → index-g170d619.js} +13 -46
- package/dist/index-g3qtxkms.js +881 -0
- package/dist/index-gactvqcs.js +467 -0
- package/dist/index-gaew61v4.js +470 -0
- package/dist/index-gba371j7.js +542 -0
- package/dist/index-gegyyfnw.js +1372 -0
- package/dist/index-get7he2s.js +133 -0
- package/dist/index-gn5wy09x.js +205 -0
- package/dist/{index-2pb7b9mw.js → index-gtbgzwfs.js} +62 -176
- package/dist/index-gtpz0gkz.js +185 -0
- package/dist/index-h1s66pmp.js +52 -0
- package/dist/{index-11m5a8wd.js → index-h8r2d8y5.js} +112 -26
- package/dist/index-heeqwrfd.js +385 -0
- package/dist/{index-7g8zyws4.js → index-hheb5dyt.js} +2 -2
- package/dist/index-hjz2x9nq.js +441 -0
- package/dist/index-hkex7ns5.js +513 -0
- package/dist/index-hmbctwv6.js +517 -0
- package/dist/index-hpzasdhw.js +513 -0
- package/dist/index-hqdr9wdm.js +74 -0
- package/dist/index-hrvz8d26.js +1372 -0
- package/dist/index-hyvhnf6r.js +971 -0
- package/dist/index-j2kc5rbv.js +895 -0
- package/dist/index-j2xdxwsz.js +133 -0
- package/dist/index-j47hhb3r.js +694 -0
- package/dist/index-j5aphr5x.js +185 -0
- package/dist/index-j68v36q1.js +188 -0
- package/dist/index-j7cf22x7.js +968 -0
- package/dist/index-j7xxrbnr.js +694 -0
- package/dist/index-jptqxkew.js +470 -0
- package/dist/index-jsymy3mb.js +781 -0
- package/dist/index-jwvy32xk.js +188 -0
- package/dist/index-jxe1b19v.js +133 -0
- package/dist/index-jz96ry5g.js +513 -0
- package/dist/index-k6wtsgs1.js +971 -0
- package/dist/index-kawa49m8.js +371 -0
- package/dist/index-key4e5c9.js +168 -0
- package/dist/index-khbmdrn2.js +884 -0
- package/dist/index-kpzfwex6.js +264 -0
- package/dist/index-kse4gn99.js +74 -0
- package/dist/index-ktscz0r2.js +264 -0
- package/dist/index-kybmjvad.js +1212 -0
- package/dist/index-kzm9cea8.js +185 -0
- package/dist/index-m2d74gqg.js +808 -0
- package/dist/index-m56w7mjt.js +513 -0
- package/dist/index-m95ha3n4.js +264 -0
- package/dist/index-ma151p8g.js +264 -0
- package/dist/index-mg8vwqxf.js +514 -0
- package/dist/index-mhdsywhs.js +264 -0
- package/dist/index-mjgx910r.js +895 -0
- package/dist/index-mkrmaea3.js +185 -0
- package/dist/index-mkxnyyjn.js +264 -0
- package/dist/index-mp5mrst6.js +1372 -0
- package/dist/index-ms15cr86.js +513 -0
- package/dist/index-mt99xkc6.js +133 -0
- package/dist/index-mttv6k25.js +881 -0
- package/dist/index-myxfx52v.js +385 -0
- package/dist/index-mzw7732t.js +74 -0
- package/dist/index-n3mjwz22.js +188 -0
- package/dist/index-n3yksgz0.js +1372 -0
- package/dist/{index-9n6djthj.js → index-n4jr3dmk.js} +32 -38
- package/dist/index-n5drt64b.js +74 -0
- package/dist/index-n8frmffg.js +264 -0
- package/dist/index-n8k8chde.js +694 -0
- package/dist/index-na796ka6.js +994 -0
- package/dist/index-nbs4q0qg.js +1218 -0
- package/dist/index-newpq2zf.js +968 -0
- package/dist/index-nexg9p7j.js +1271 -0
- package/dist/index-nfm8tb5n.js +74 -0
- package/dist/index-nga2tg9z.js +1372 -0
- package/dist/{index-43dq8yx8.js → index-ngbzr9gz.js} +111 -94
- package/dist/index-nh90nk7j.js +380 -0
- package/dist/index-njnmfxm5.js +1372 -0
- package/dist/index-nqma24j3.js +385 -0
- package/dist/index-ntddf5d9.js +993 -0
- package/dist/index-nte9n8w9.js +538 -0
- package/dist/index-ntxp7ke1.js +264 -0
- package/dist/index-nwxnmw41.js +264 -0
- package/dist/index-p1xe5eem.js +513 -0
- package/dist/{index-wztc9stx.js → index-p477xm52.js} +13 -46
- package/dist/index-p8nmkrgw.js +470 -0
- package/dist/{index-yqbxjysa.js → index-p97s12vf.js} +50 -43
- package/dist/index-p9hvv0yd.js +401 -0
- package/dist/index-pac7wv88.js +307 -0
- package/dist/index-ptp2pfq1.js +52 -0
- package/dist/index-pyeycp3f.js +74 -0
- package/dist/index-q23xf3vr.js +479 -0
- package/dist/index-q34rvh5a.js +247 -0
- package/dist/{index-j185x270.js → index-q5errwrj.js} +53 -46
- package/dist/{index-2jnrqbny.js → index-q5nhzc9m.js} +4 -88
- package/dist/index-q8f4kawk.js +204 -0
- package/dist/index-qer8zv2r.js +997 -0
- package/dist/index-qhyy018y.js +467 -0
- package/dist/index-qmhdydwy.js +70 -0
- package/dist/index-qpmvca5j.js +470 -0
- package/dist/index-qr96vaj1.js +52 -0
- package/dist/{index-74198nxd.js → index-qtyhg3dn.js} +53 -46
- package/dist/index-qye17gq5.js +264 -0
- package/dist/index-r0839f5k.js +133 -0
- package/dist/index-r1rqg72v.js +1372 -0
- package/dist/index-rbckga8p.js +971 -0
- package/dist/index-rbxb5x2w.js +1372 -0
- package/dist/index-rck779bj.js +739 -0
- package/dist/index-rfn2gt5f.js +1658 -0
- package/dist/index-rg21w26a.js +470 -0
- package/dist/index-rgcz45t0.js +1372 -0
- package/dist/index-rhnd376q.js +133 -0
- package/dist/index-rjc5z3w6.js +971 -0
- package/dist/index-rkhtayd6.js +385 -0
- package/dist/index-rm8srzmv.js +371 -0
- package/dist/index-rmhk5j03.js +968 -0
- package/dist/index-rp4t86bt.js +993 -0
- package/dist/index-rpq5ktdy.js +264 -0
- package/dist/index-rpsmhdd4.js +1218 -0
- package/dist/index-rqpakjyr.js +470 -0
- package/dist/index-rttk33x6.js +232 -0
- package/dist/index-rwa82e89.js +385 -0
- package/dist/index-rz185crv.js +695 -0
- package/dist/index-s22verzj.js +1218 -0
- package/dist/index-s2s3g1nt.js +133 -0
- package/dist/index-s7ytytth.js +781 -0
- package/dist/index-sefnpzwa.js +185 -0
- package/dist/index-sgxw0xzd.js +513 -0
- package/dist/index-stc0caq6.js +1009 -0
- package/dist/index-svz82w9h.js +513 -0
- package/dist/index-sx49e8x9.js +884 -0
- package/dist/index-sxadwvw9.js +185 -0
- package/dist/index-sxn223fz.js +1372 -0
- package/dist/index-sy0c2mh0.js +1372 -0
- package/dist/index-syeh1hca.js +264 -0
- package/dist/index-t18wyhgf.js +418 -0
- package/dist/index-t4fhcx1n.js +71 -0
- package/dist/index-td4hbgj5.js +1372 -0
- package/dist/{index-hjy8ctpc.js → index-tkvt9mmq.js} +47 -14
- package/dist/index-tmmcf4m6.js +808 -0
- package/dist/index-tpgs5v64.js +366 -0
- package/dist/index-tt4fsv91.js +412 -0
- package/dist/{index-t08te69w.js → index-tte89s31.js} +28 -11
- package/dist/index-tvjg7swe.js +1372 -0
- package/dist/index-txndxr4w.js +513 -0
- package/dist/index-tyh5jc55.js +990 -0
- package/dist/index-tyt0wa52.js +470 -0
- package/dist/index-tyt3wcfr.js +1372 -0
- package/dist/index-v3znz08m.js +968 -0
- package/dist/index-v78xbj6n.js +808 -0
- package/dist/index-v915brjk.js +1372 -0
- package/dist/index-v922fmsx.js +52 -0
- package/dist/index-v9w1bbfe.js +842 -0
- package/dist/index-vbbgtm8p.js +513 -0
- package/dist/{index-k6vq6kkt.js → index-vcjgrmzj.js} +3 -3
- package/dist/{index-9ba1etyz.js → index-vdewcg1r.js} +204 -54
- package/dist/index-vhqww6tt.js +307 -0
- package/dist/index-vse8620z.js +1372 -0
- package/dist/index-vtjp46c3.js +52 -0
- package/dist/{index-jwd8pcb2.js → index-vxhxk8mf.js} +53 -46
- package/dist/index-w3azfsa0.js +695 -0
- package/dist/index-w4tq35dn.js +52 -0
- package/dist/index-w5qxvxzq.js +991 -0
- package/dist/index-w5sedpqn.js +986 -0
- package/dist/index-waha3chv.js +1230 -0
- package/dist/index-wdxww0kj.js +1006 -0
- package/dist/index-wdy5y07x.js +1372 -0
- package/dist/index-wf9pnh6j.js +385 -0
- package/dist/index-wnnbbbkt.js +1192 -0
- package/dist/index-wvcmvtjf.js +1372 -0
- package/dist/index-x0jbntp0.js +470 -0
- package/dist/index-x6scc3nx.js +70 -0
- package/dist/index-x8e2wsbv.js +971 -0
- package/dist/index-xec4p3v5.js +560 -0
- package/dist/index-xgfyxpfs.js +1218 -0
- package/dist/index-xm9hp9xc.js +1372 -0
- package/dist/index-xp7zkxcx.js +1372 -0
- package/dist/index-xrbj0ebk.js +185 -0
- package/dist/index-xskax7r3.js +50 -0
- package/dist/index-xvk5n96q.js +694 -0
- package/dist/index-xy1jvt4w.js +1229 -0
- package/dist/index-xzg9hhf3.js +470 -0
- package/dist/index-xzpg0kaz.js +70 -0
- package/dist/index-y3q6qvv3.js +316 -0
- package/dist/index-y44ts1dk.js +52 -0
- package/dist/index-y5nt1wjb.js +971 -0
- package/dist/index-y82b8w14.js +1372 -0
- package/dist/index-yb07t3c5.js +1372 -0
- package/dist/index-yc3xz3vm.js +431 -0
- package/dist/index-yeaqrevg.js +1372 -0
- package/dist/index-ygwsd1nn.js +438 -0
- package/dist/index-yhdavjk7.js +371 -0
- package/dist/index-yjhns95b.js +188 -0
- package/dist/index-yk23p7he.js +1372 -0
- package/dist/index-ykfgpsmm.js +190 -0
- package/dist/index-ymz3cfab.js +968 -0
- package/dist/index-yq9g1sq7.js +264 -0
- package/dist/index-ys5q9ch9.js +366 -0
- package/dist/index-yt0n4p46.js +973 -0
- package/dist/index-ytq1t9jx.js +232 -0
- package/dist/index-ywmtmf3b.js +513 -0
- package/dist/index-yzb44q6d.js +1372 -0
- package/dist/index-z043xk61.js +133 -0
- package/dist/index-z0gsf674.js +431 -0
- package/dist/index-z32n0ndp.js +1372 -0
- package/dist/index-z4qgk76w.js +1372 -0
- package/dist/{index-yc0gcchc.js → index-z8njfj2g.js} +11 -44
- package/dist/{index-0w826dsr.js → index-z9fjnwa8.js} +21 -3
- package/dist/{index-1xpj0m4r.js → index-z9gy8w6b.js} +1 -1
- package/dist/index-zapkc14c.js +264 -0
- package/dist/index-zes6w8yr.js +185 -0
- package/dist/index-zgrqest7.js +695 -0
- package/dist/index-zsngz131.js +1372 -0
- package/dist/index-zxhc6sb0.js +192 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -0
- package/dist/{init-r4hnxan3.js → init-wfh63bfz.js} +1 -1
- package/dist/{login-5bsxxpvc.js → login-1amyp1jy.js} +10 -10
- package/dist/{login-bhaw72zc.js → login-1cdwn1dj.js} +11 -11
- package/dist/{login-2hnz4m4n.js → login-456h8jk3.js} +11 -11
- package/dist/{login-6tzvczw2.js → login-4n470c4j.js} +11 -11
- package/dist/login-4sh7s849.js +77 -0
- package/dist/login-5dmkf0pz.js +77 -0
- package/dist/login-88tp4gbb.js +77 -0
- package/dist/login-b51faqpc.js +77 -0
- package/dist/login-bxyjqmbj.js +77 -0
- package/dist/login-c4649qss.js +77 -0
- package/dist/login-d80a2qxd.js +77 -0
- package/dist/login-dp0napaz.js +77 -0
- package/dist/login-j3r6z2t4.js +77 -0
- package/dist/login-jkfkdjg4.js +77 -0
- package/dist/login-kch6f2yj.js +77 -0
- package/dist/login-pmqh94ws.js +77 -0
- package/dist/login-rc82x5j8.js +77 -0
- package/dist/login-tvppwyx2.js +77 -0
- package/dist/login-w76jx22q.js +77 -0
- package/dist/login-ze7y36rc.js +77 -0
- package/dist/{previews-gm3z0syj.js → previews-02jmcwft.js} +140 -94
- package/dist/previews-31bq82km.js +1225 -0
- package/dist/{previews-j9ymq4ys.js → previews-62pcvvpe.js} +140 -95
- package/dist/{previews-3rn8mz2c.js → previews-76fxkp59.js} +140 -94
- package/dist/previews-844bp6kf.js +1214 -0
- package/dist/previews-8amn46qv.js +1214 -0
- package/dist/previews-a5xbkksy.js +1214 -0
- package/dist/previews-bgnryzav.js +1214 -0
- package/dist/previews-bkhv9dnr.js +1214 -0
- package/dist/previews-c2c64z5m.js +1214 -0
- package/dist/previews-e4wgscsb.js +1214 -0
- package/dist/previews-ew4reetn.js +1214 -0
- package/dist/previews-hzqke1fg.js +1214 -0
- package/dist/previews-j8wa3sge.js +1214 -0
- package/dist/previews-k5n6vhpm.js +1214 -0
- package/dist/previews-n4sdyxa5.js +1214 -0
- package/dist/previews-npwrwb0b.js +1214 -0
- package/dist/previews-q8ph9wbe.js +1214 -0
- package/dist/previews-rfswrh7q.js +1214 -0
- package/dist/previews-s0y5yp8s.js +1214 -0
- package/dist/previews-s5b6mnz5.js +1214 -0
- package/dist/{previews-d487qde5.js → previews-sdte4984.js} +23 -23
- package/dist/previews-t5tdm6t0.js +1225 -0
- package/dist/previews-tk7vpzj9.js +1214 -0
- package/dist/previews-tqt4pk27.js +1214 -0
- package/dist/previews-vqg4psk2.js +1225 -0
- package/dist/{productions-x9p0pym1.js → productions-4abj58kx.js} +12 -12
- package/dist/{productions-5ev5qweg.js → productions-4dpec71r.js} +13 -13
- package/dist/{productions-120xg0aq.js → productions-4nedsanh.js} +13 -13
- package/dist/{productions-p5rbgp2f.js → productions-5c58yafp.js} +13 -13
- package/dist/{productions-me3tdvr9.js → productions-5xq5cjhx.js} +13 -13
- package/dist/productions-6dr0bmd7.js +505 -0
- package/dist/productions-8f6s8dqr.js +505 -0
- package/dist/productions-a2hcwwzf.js +505 -0
- package/dist/productions-b7svyjp7.js +505 -0
- package/dist/productions-bf2cnr05.js +505 -0
- package/dist/productions-dkgry3gv.js +505 -0
- package/dist/productions-eqh105tk.js +505 -0
- package/dist/productions-etvcm7yf.js +505 -0
- package/dist/productions-f1zpbmjz.js +505 -0
- package/dist/productions-j14pvx93.js +505 -0
- package/dist/productions-j7s1ywvg.js +505 -0
- package/dist/productions-jp3v3q3p.js +505 -0
- package/dist/productions-m9p42amj.js +505 -0
- package/dist/productions-mxbneawa.js +505 -0
- package/dist/productions-np4exh9p.js +505 -0
- package/dist/productions-rr1hqgda.js +505 -0
- package/dist/productions-rtf9ksgg.js +505 -0
- package/dist/productions-w2nzftcz.js +505 -0
- package/dist/productions-wbks5h7e.js +505 -0
- package/dist/productions-y99ayk6h.js +505 -0
- package/dist/productions-zpqyw5gm.js +505 -0
- package/dist/runtime/context-events.d.ts.map +1 -1
- package/dist/runtime/context.d.ts +8 -1
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/exports.d.ts +1 -4
- package/dist/runtime/exports.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/{src/runtime → runtime}/index.js +22 -7
- package/dist/runtime/middleware.d.ts +55 -0
- package/dist/runtime/middleware.d.ts.map +1 -1
- package/dist/runtime/router/index.d.ts +7 -0
- package/dist/runtime/router/index.d.ts.map +1 -0
- package/dist/runtime/router/types.d.ts +24 -0
- package/dist/runtime/router/types.d.ts.map +1 -0
- package/dist/runtime/validation.d.ts +9 -1
- package/dist/runtime/validation.d.ts.map +1 -1
- package/dist/{src/sveltekit → sveltekit}/index.js +36 -71
- package/dist/sveltekit/platform.d.ts +10 -0
- package/dist/sveltekit/platform.d.ts.map +1 -1
- package/dist/test/binding-hints.d.ts +11 -0
- package/dist/test/binding-hints.d.ts.map +1 -0
- package/dist/test/bridge-context.d.ts +7 -0
- package/dist/test/bridge-context.d.ts.map +1 -1
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.d.ts.map +1 -1
- package/dist/{index-2x53aqjm.js → test/index.js} +836 -774
- package/dist/test/simple-context-bindings.d.ts +13 -0
- package/dist/test/simple-context-bindings.d.ts.map +1 -0
- package/dist/test/simple-context-env.d.ts +35 -0
- package/dist/test/simple-context-env.d.ts.map +1 -0
- package/dist/test/simple-context-gateway-script.d.ts.map +1 -1
- package/dist/test/simple-context-handlers.d.ts +12 -0
- package/dist/test/simple-context-handlers.d.ts.map +1 -0
- package/dist/test/simple-context-lifecycle.d.ts +32 -0
- package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
- package/dist/test/simple-context-mfconfig.d.ts +7 -0
- package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
- package/dist/test/simple-context-multi-worker.d.ts +16 -0
- package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
- package/dist/test/simple-context-runtime.d.ts +19 -0
- package/dist/test/simple-context-runtime.d.ts.map +1 -0
- package/dist/test/simple-context-startup.d.ts +11 -0
- package/dist/test/simple-context-startup.d.ts.map +1 -0
- package/dist/test/simple-context-transport.d.ts +14 -0
- package/dist/test/simple-context-transport.d.ts.map +1 -0
- package/dist/test/simple-context.d.ts +6 -3
- package/dist/test/simple-context.d.ts.map +1 -1
- package/dist/test/utilities.d.ts +13 -5
- package/dist/test/utilities.d.ts.map +1 -1
- package/dist/test/worker.d.ts +1 -1
- package/dist/test/worker.d.ts.map +1 -1
- package/dist/{token-kedhcret.js → token-3b9wws58.js} +3 -3
- package/dist/{token-m8jmnjwk.js → token-47kcz18j.js} +3 -3
- package/dist/token-exz78pth.js +419 -0
- package/dist/token-fcthx92c.js +419 -0
- package/dist/token-grwp8z4q.js +419 -0
- package/dist/token-jkmm44z2.js +419 -0
- package/dist/token-qxtvzm3b.js +419 -0
- package/dist/token-rq8mvtz9.js +419 -0
- package/dist/token-sct51r47.js +419 -0
- package/dist/token-sfgxcgen.js +419 -0
- package/dist/transform/durable-object.d.ts.map +1 -1
- package/dist/transform/worker-entrypoint.d.ts +5 -0
- package/dist/transform/worker-entrypoint.d.ts.map +1 -1
- package/dist/types-0qv4xces.js +572 -0
- package/dist/types-2nvrs9jg.js +572 -0
- package/dist/types-2pbe8kzw.js +572 -0
- package/dist/types-2zyt0m43.js +572 -0
- package/dist/types-4xxer9ep.js +572 -0
- package/dist/{types-6e5yx6km.js → types-5t5y7a5n.js} +9 -9
- package/dist/{types-1gwr2ex6.js → types-5wd2rygw.js} +9 -9
- package/dist/types-7j3ykgx7.js +572 -0
- package/dist/types-8g78x34n.js +572 -0
- package/dist/types-e6d336q3.js +572 -0
- package/dist/types-hqh2fx0x.js +572 -0
- package/dist/types-j12xmdnd.js +572 -0
- package/dist/types-jqn26et3.js +572 -0
- package/dist/types-n0mxbq26.js +572 -0
- package/dist/types-naz9hvw5.js +572 -0
- package/dist/{types-p0gckpn6.js → types-qjcd1jks.js} +7 -7
- package/dist/types-r9zb8sw1.js +572 -0
- package/dist/types-rv5xwgsn.js +572 -0
- package/dist/types-t39njdqx.js +572 -0
- package/dist/types-tkgch3xv.js +572 -0
- package/dist/{types-0sqwkp7x.js → types-vvtb7rrh.js} +9 -9
- package/dist/types-w1grncdj.js +572 -0
- package/dist/types-wmw49exb.js +572 -0
- package/dist/types-ymxz9jga.js +572 -0
- package/dist/utils/resolve-package.d.ts.map +1 -1
- package/dist/utils/send-email.js +19 -0
- package/dist/vite/config-file.d.ts.map +1 -1
- package/dist/{src/vite → vite}/index.js +12 -11
- package/dist/vite/plugin-config-hook.d.ts +28 -0
- package/dist/vite/plugin-config-hook.d.ts.map +1 -0
- package/dist/vite/plugin-context.d.ts +25 -0
- package/dist/vite/plugin-context.d.ts.map +1 -0
- package/dist/vite/plugin-durable-objects.d.ts +18 -0
- package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
- package/dist/vite/plugin-programmatic.d.ts +44 -0
- package/dist/vite/plugin-programmatic.d.ts.map +1 -0
- package/dist/vite/plugin-transform.d.ts +41 -0
- package/dist/vite/plugin-transform.d.ts.map +1 -0
- package/dist/vite/plugin.d.ts +6 -39
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/{worker-y9ha6g44.js → worker-18ceqscc.js} +11 -11
- package/dist/{worker-0srh2jfr.js → worker-1yqpwte2.js} +12 -12
- package/dist/{worker-qtam8grz.js → worker-2aw27zxy.js} +12 -12
- package/dist/{worker-4xrfd10a.js → worker-45tp4a8f.js} +12 -12
- package/dist/worker-68zttchg.js +513 -0
- package/dist/worker-729cf3fh.js +513 -0
- package/dist/worker-aydzxt4f.js +513 -0
- package/dist/worker-ejdxma7k.js +513 -0
- package/dist/worker-entry/composed-worker.d.ts +1 -0
- package/dist/worker-entry/composed-worker.d.ts.map +1 -1
- package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
- package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
- package/dist/worker-entry/extensions.d.ts +5 -0
- package/dist/worker-entry/extensions.d.ts.map +1 -0
- package/dist/worker-entry/routes.d.ts +1 -1
- package/dist/worker-entry/routes.d.ts.map +1 -1
- package/dist/worker-entry/surface-paths.d.ts +13 -4
- package/dist/worker-entry/surface-paths.d.ts.map +1 -1
- package/dist/worker-entrypoint-4xp7msd7.js +16 -0
- package/dist/worker-entrypoint-f1v9y4s8.js +15 -0
- package/dist/{worker-qzm0b7br.js → worker-f6xqjg65.js} +12 -12
- package/dist/worker-fdnn62de.js +513 -0
- package/dist/worker-frnh95rg.js +513 -0
- package/dist/worker-k55nfrmp.js +513 -0
- package/dist/worker-kqc6w7ry.js +513 -0
- package/dist/worker-ksvcq8be.js +513 -0
- package/dist/worker-mjzfstv5.js +513 -0
- package/dist/worker-p4rtsndj.js +513 -0
- package/dist/worker-p6d53qan.js +513 -0
- package/dist/worker-qh2qbv97.js +513 -0
- package/dist/worker-r234vnv9.js +513 -0
- package/dist/worker-r47bv7gt.js +513 -0
- package/dist/worker-s4nvbqsm.js +513 -0
- package/dist/worker-ttj7vwce.js +513 -0
- package/dist/worker-wv4jdneg.js +513 -0
- package/dist/worker-xcbscr75.js +513 -0
- package/dist/worker-ywwkf3cp.js +513 -0
- package/dist/worker-z8wtk0sh.js +513 -0
- package/package.json +138 -123
- package/dist/account-s66jb15j.js +0 -475
- package/dist/browser-shim/worker.d.ts +0 -14
- package/dist/browser-shim/worker.d.ts.map +0 -1
- package/dist/deploy-7nmzc9r8.js +0 -609
- package/dist/deploy-tp0g6qdp.js +0 -609
- package/dist/index-091sh1ma.js +0 -1229
- package/dist/index-f85s8gj3.js +0 -2649
- package/dist/index-fe2ngvh7.js +0 -1229
- package/dist/index-hfj1a2c4.js +0 -2649
- package/dist/index-maxpsfk8.js +0 -402
- package/dist/index-mbdmrner.js +0 -402
- package/dist/index-mea5bc45.js +0 -418
- package/dist/index-sgb7c8nm.js +0 -402
- package/dist/index-vt4yxkmf.js +0 -470
- package/dist/index-wyq6c6yj.js +0 -402
- package/dist/index-zyt5byt6.js +0 -2649
- package/dist/login-x8tgckqm.js +0 -77
- package/dist/previews-q031mx34.js +0 -1168
- package/dist/src/cli/index.js +0 -12
- package/dist/src/index.js +0 -144
- package/dist/src/test/index.js +0 -77
package/dist/index-hfj1a2c4.js
DELETED
|
@@ -1,2649 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getRemoteModeStatus,
|
|
3
|
-
isRemoteModeActive
|
|
4
|
-
} from "./index-d8bdkx2h.js";
|
|
5
|
-
import {
|
|
6
|
-
discoverEntrypointsSync
|
|
7
|
-
} from "./index-zt22fe2j.js";
|
|
8
|
-
import {
|
|
9
|
-
canProceedWithTest
|
|
10
|
-
} from "./index-7g8zyws4.js";
|
|
11
|
-
import {
|
|
12
|
-
transformWorkerEntrypoint
|
|
13
|
-
} from "./index-wfbfz02q.js";
|
|
14
|
-
import {
|
|
15
|
-
resolvePackageSpecifier
|
|
16
|
-
} from "./index-82f1z98k.js";
|
|
17
|
-
import {
|
|
18
|
-
__clearTestContext,
|
|
19
|
-
__setTestContext
|
|
20
|
-
} from "./index-m3fmw6mx.js";
|
|
21
|
-
import {
|
|
22
|
-
createRouteResolve,
|
|
23
|
-
invokeFetchModule,
|
|
24
|
-
matchFetchRoute,
|
|
25
|
-
resolveFetchHandler
|
|
26
|
-
} from "./index-hjy8ctpc.js";
|
|
27
|
-
import {
|
|
28
|
-
createEmailEvent,
|
|
29
|
-
createFetchEvent,
|
|
30
|
-
createQueueEvent,
|
|
31
|
-
createScheduledEvent,
|
|
32
|
-
createTailEvent,
|
|
33
|
-
runWithContext,
|
|
34
|
-
runWithEventContext
|
|
35
|
-
} from "./index-cgbvmse6.js";
|
|
36
|
-
import {
|
|
37
|
-
discoverRoutes
|
|
38
|
-
} from "./index-1p814k7s.js";
|
|
39
|
-
import {
|
|
40
|
-
DEFAULT_DO_PATTERN,
|
|
41
|
-
findFiles,
|
|
42
|
-
findFilesSync
|
|
43
|
-
} from "./index-rbht7m9r.js";
|
|
44
|
-
import {
|
|
45
|
-
findDurableObjectClasses
|
|
46
|
-
} from "./index-9wt9x09k.js";
|
|
47
|
-
import {
|
|
48
|
-
startMiniflare,
|
|
49
|
-
startMiniflareFromConfig
|
|
50
|
-
} from "./index-1sp39f2f.js";
|
|
51
|
-
import {
|
|
52
|
-
BridgeClient,
|
|
53
|
-
createEnvProxy,
|
|
54
|
-
setBindingHints
|
|
55
|
-
} from "./index-9ba1etyz.js";
|
|
56
|
-
import {
|
|
57
|
-
createLocalSendEmailBinding,
|
|
58
|
-
wrapEnvSendEmailBindings
|
|
59
|
-
} from "./index-h18pxvzs.js";
|
|
60
|
-
import {
|
|
61
|
-
getLocalD1DatabaseIdentifier,
|
|
62
|
-
loadConfig,
|
|
63
|
-
normalizeDOBinding,
|
|
64
|
-
resolveConfigPath
|
|
65
|
-
} from "./index-43dq8yx8.js";
|
|
66
|
-
import {
|
|
67
|
-
getEffectiveAccountId,
|
|
68
|
-
getPrimaryAccount
|
|
69
|
-
} from "./index-xk9djfjp.js";
|
|
70
|
-
import {
|
|
71
|
-
getApiToken,
|
|
72
|
-
isAuthenticated
|
|
73
|
-
} from "./index-0w826dsr.js";
|
|
74
|
-
import {
|
|
75
|
-
__require
|
|
76
|
-
} from "./index-37x76zdn.js";
|
|
77
|
-
|
|
78
|
-
// src/test/simple-context.ts
|
|
79
|
-
import { dirname as dirname4, join as join9, resolve as resolve2 } from "path";
|
|
80
|
-
|
|
81
|
-
// src/test/remote-cloudflare.ts
|
|
82
|
-
function createRemoteCloudflareClient(accountId) {
|
|
83
|
-
let resolvedAccountId = null;
|
|
84
|
-
async function getAccountId() {
|
|
85
|
-
if (accountId) {
|
|
86
|
-
return accountId;
|
|
87
|
-
}
|
|
88
|
-
if (resolvedAccountId) {
|
|
89
|
-
return resolvedAccountId;
|
|
90
|
-
}
|
|
91
|
-
const primary = await getPrimaryAccount();
|
|
92
|
-
if (!primary) {
|
|
93
|
-
throw new Error("No Cloudflare account found. Run: bunx wrangler login");
|
|
94
|
-
}
|
|
95
|
-
const { accountId: effectiveId } = await getEffectiveAccountId(primary.id);
|
|
96
|
-
resolvedAccountId = effectiveId;
|
|
97
|
-
return effectiveId;
|
|
98
|
-
}
|
|
99
|
-
async function getToken() {
|
|
100
|
-
const token = await getApiToken();
|
|
101
|
-
if (!token) {
|
|
102
|
-
throw new Error("Not authenticated. Run: bunx wrangler login");
|
|
103
|
-
}
|
|
104
|
-
return token;
|
|
105
|
-
}
|
|
106
|
-
async function jsonRequest(options) {
|
|
107
|
-
const [acctId, token] = await Promise.all([getAccountId(), getToken()]);
|
|
108
|
-
const response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${acctId}${options.path}`, {
|
|
109
|
-
method: options.method,
|
|
110
|
-
headers: {
|
|
111
|
-
Authorization: `Bearer ${token}`,
|
|
112
|
-
"Content-Type": options.contentType ?? "application/json"
|
|
113
|
-
},
|
|
114
|
-
body: options.body
|
|
115
|
-
});
|
|
116
|
-
if (!response.ok) {
|
|
117
|
-
const errorText = await response.text();
|
|
118
|
-
throw new Error(`${options.serviceLabel} API error (${response.status}): ${errorText}`);
|
|
119
|
-
}
|
|
120
|
-
const result = await response.json();
|
|
121
|
-
if (!result.success) {
|
|
122
|
-
const message = result.errors?.[0]?.message || `Unknown ${options.serviceLabel} error`;
|
|
123
|
-
throw new Error(`${options.serviceLabel} API error: ${message}`);
|
|
124
|
-
}
|
|
125
|
-
return result.result;
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
getAccountId,
|
|
129
|
-
getToken,
|
|
130
|
-
jsonRequest
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/test/remote-ai.ts
|
|
135
|
-
function createRemoteAI(accountId) {
|
|
136
|
-
const cloudflare = createRemoteCloudflareClient(accountId);
|
|
137
|
-
const ai = {
|
|
138
|
-
async run(model, inputs) {
|
|
139
|
-
return cloudflare.jsonRequest({
|
|
140
|
-
method: "POST",
|
|
141
|
-
path: `/ai/run/${model}`,
|
|
142
|
-
serviceLabel: "AI",
|
|
143
|
-
body: JSON.stringify(inputs)
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
gateway(_gatewayId) {
|
|
147
|
-
console.warn("AI Gateway is not supported in remote test mode");
|
|
148
|
-
return ai;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return ai;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/test/remote-vectorize.ts
|
|
155
|
-
function createRemoteVectorize(indexName, accountId) {
|
|
156
|
-
const cloudflare = createRemoteCloudflareClient(accountId);
|
|
157
|
-
async function apiRequest(method, endpoint, body) {
|
|
158
|
-
return cloudflare.jsonRequest({
|
|
159
|
-
method,
|
|
160
|
-
path: `/vectorize/v2/indexes/${indexName}${endpoint}`,
|
|
161
|
-
serviceLabel: "Vectorize",
|
|
162
|
-
body: body ? JSON.stringify(body) : undefined
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
async function ndjsonRequest(endpoint, vectors) {
|
|
166
|
-
const ndjson = vectors.map((v) => JSON.stringify(v)).join(`
|
|
167
|
-
`);
|
|
168
|
-
return cloudflare.jsonRequest({
|
|
169
|
-
method: "POST",
|
|
170
|
-
path: `/vectorize/v2/indexes/${indexName}${endpoint}`,
|
|
171
|
-
serviceLabel: "Vectorize",
|
|
172
|
-
contentType: "application/x-ndjson",
|
|
173
|
-
body: ndjson
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
const vectorize = {
|
|
177
|
-
async describe() {
|
|
178
|
-
return apiRequest("GET", "");
|
|
179
|
-
},
|
|
180
|
-
async query(vector, options) {
|
|
181
|
-
const vectorArray = Array.isArray(vector) ? vector : Array.from(vector);
|
|
182
|
-
return apiRequest("POST", "/query", {
|
|
183
|
-
vector: vectorArray,
|
|
184
|
-
topK: options?.topK ?? 10,
|
|
185
|
-
returnValues: options?.returnValues ?? false,
|
|
186
|
-
returnMetadata: options?.returnMetadata ?? "none",
|
|
187
|
-
namespace: options?.namespace,
|
|
188
|
-
filter: options?.filter
|
|
189
|
-
});
|
|
190
|
-
},
|
|
191
|
-
async insert(vectors) {
|
|
192
|
-
const result = await ndjsonRequest("/insert", vectors);
|
|
193
|
-
return {
|
|
194
|
-
count: result.count,
|
|
195
|
-
ids: result.ids || vectors.map((v) => v.id)
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
async upsert(vectors) {
|
|
199
|
-
const result = await ndjsonRequest("/upsert", vectors);
|
|
200
|
-
return {
|
|
201
|
-
count: result.count,
|
|
202
|
-
ids: result.ids || vectors.map((v) => v.id)
|
|
203
|
-
};
|
|
204
|
-
},
|
|
205
|
-
async deleteByIds(ids) {
|
|
206
|
-
const result = await apiRequest("POST", "/delete-by-ids", { ids });
|
|
207
|
-
return {
|
|
208
|
-
count: result.count,
|
|
209
|
-
ids
|
|
210
|
-
};
|
|
211
|
-
},
|
|
212
|
-
async getByIds(ids) {
|
|
213
|
-
return apiRequest("POST", "/get-by-ids", { ids });
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
return vectorize;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/test/resolve-service-bindings.ts
|
|
220
|
-
import { dirname, join, resolve } from "path";
|
|
221
|
-
import { existsSync, readFileSync } from "fs";
|
|
222
|
-
function getBunRuntime() {
|
|
223
|
-
const g = globalThis;
|
|
224
|
-
if (typeof g.Bun === "object" && g.Bun !== null) {
|
|
225
|
-
return g.Bun;
|
|
226
|
-
}
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
function discoverDOFilesSync(dir) {
|
|
230
|
-
const classToPath = new Map;
|
|
231
|
-
try {
|
|
232
|
-
const files = findFilesSync(DEFAULT_DO_PATTERN, { cwd: dir });
|
|
233
|
-
for (const filePath of files) {
|
|
234
|
-
try {
|
|
235
|
-
const code = readFileSync(filePath, "utf-8");
|
|
236
|
-
const classNames = findDurableObjectClasses(code);
|
|
237
|
-
for (const className of classNames) {
|
|
238
|
-
if (!classToPath.has(className)) {
|
|
239
|
-
classToPath.set(className, filePath);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
} catch {}
|
|
243
|
-
}
|
|
244
|
-
} catch {}
|
|
245
|
-
return classToPath;
|
|
246
|
-
}
|
|
247
|
-
var bundleCache = new Map;
|
|
248
|
-
function clearBundleCache() {
|
|
249
|
-
bundleCache.clear();
|
|
250
|
-
}
|
|
251
|
-
function findDefaultServiceWorkerEntrypoint(refConfigDir) {
|
|
252
|
-
for (const candidate of ["src/worker.ts", "src/worker.js"]) {
|
|
253
|
-
const absolutePath = resolve(refConfigDir, candidate);
|
|
254
|
-
if (existsSync(absolutePath)) {
|
|
255
|
-
return absolutePath;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
function hasServiceBindings(config) {
|
|
261
|
-
const services = config.bindings?.services;
|
|
262
|
-
if (!services)
|
|
263
|
-
return false;
|
|
264
|
-
return Object.keys(services).length > 0;
|
|
265
|
-
}
|
|
266
|
-
async function resolveServiceBindings(config, configDir) {
|
|
267
|
-
const services = config.bindings?.services;
|
|
268
|
-
if (!services) {
|
|
269
|
-
return { workers: [], primaryServiceBindings: {} };
|
|
270
|
-
}
|
|
271
|
-
const workersByName = new Map;
|
|
272
|
-
const primaryServiceBindings = {};
|
|
273
|
-
for (const [bindingName, binding] of Object.entries(services)) {
|
|
274
|
-
const workerBinding = binding;
|
|
275
|
-
const ref = workerBinding.__ref;
|
|
276
|
-
if (ref) {
|
|
277
|
-
if ("__import" in ref && typeof ref.__import === "function") {
|
|
278
|
-
await ref.resolve();
|
|
279
|
-
}
|
|
280
|
-
const workerName = ref.name;
|
|
281
|
-
const entrypoint = workerBinding.entrypoint;
|
|
282
|
-
if (!workersByName.has(workerName)) {
|
|
283
|
-
const worker = await resolveRefWorker(ref, entrypoint, configDir);
|
|
284
|
-
if (worker) {
|
|
285
|
-
workersByName.set(workerName, worker);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
primaryServiceBindings[bindingName] = {
|
|
289
|
-
name: workerName,
|
|
290
|
-
...entrypoint && { entrypoint }
|
|
291
|
-
};
|
|
292
|
-
} else {
|
|
293
|
-
primaryServiceBindings[bindingName] = {
|
|
294
|
-
name: workerBinding.service,
|
|
295
|
-
...workerBinding.entrypoint && { entrypoint: workerBinding.entrypoint }
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return {
|
|
300
|
-
workers: [...workersByName.values()],
|
|
301
|
-
primaryServiceBindings
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
async function resolveRefWorker(ref, _entrypoint, parentConfigDir) {
|
|
305
|
-
const config = ref.config;
|
|
306
|
-
if (!config)
|
|
307
|
-
return null;
|
|
308
|
-
const configPath = ref.configPath;
|
|
309
|
-
if (!configPath || configPath === "<resolved>") {
|
|
310
|
-
console.warn(`[devflare] Cannot resolve worker "${ref.name}" - configPath not available`);
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
const refConfigDir = resolve(parentConfigDir, dirname(configPath));
|
|
314
|
-
const entrypoints = [];
|
|
315
|
-
const workerEntrypointPath = findDefaultServiceWorkerEntrypoint(refConfigDir);
|
|
316
|
-
if (workerEntrypointPath) {
|
|
317
|
-
entrypoints.push({
|
|
318
|
-
path: workerEntrypointPath,
|
|
319
|
-
className: "Worker",
|
|
320
|
-
isWorkerTs: true
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
if (config.files?.entrypoints !== false) {
|
|
324
|
-
const discoveredEntrypoints = discoverEntrypointsSync(refConfigDir, typeof config.files?.entrypoints === "string" ? config.files.entrypoints : undefined);
|
|
325
|
-
for (const ep of discoveredEntrypoints) {
|
|
326
|
-
entrypoints.push({
|
|
327
|
-
path: ep.filePath,
|
|
328
|
-
className: ep.className,
|
|
329
|
-
isWorkerTs: false
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
if (entrypoints.length === 0) {
|
|
334
|
-
console.warn(`[devflare] Worker "${ref.name}" has no entry points`);
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
const script = await bundleAllEntrypoints(entrypoints, ref.name);
|
|
338
|
-
if (!script)
|
|
339
|
-
return null;
|
|
340
|
-
return {
|
|
341
|
-
name: ref.name,
|
|
342
|
-
script,
|
|
343
|
-
modules: true,
|
|
344
|
-
compatibilityDate: config.compatibilityDate ?? "2025-01-01"
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
async function bundleAllEntrypoints(entrypoints, workerName) {
|
|
348
|
-
const cacheKey = entrypoints.map((ep) => `${ep.path}::${ep.className}`).join("|");
|
|
349
|
-
const cached = bundleCache.get(cacheKey);
|
|
350
|
-
if (cached) {
|
|
351
|
-
return cached;
|
|
352
|
-
}
|
|
353
|
-
const bun = getBunRuntime();
|
|
354
|
-
if (!bun) {
|
|
355
|
-
console.warn("[devflare] Bun runtime required for bundling worker scripts");
|
|
356
|
-
return null;
|
|
357
|
-
}
|
|
358
|
-
try {
|
|
359
|
-
const { readFileSync: readFileSync2, writeFileSync, mkdirSync, unlinkSync } = await import("fs");
|
|
360
|
-
const imports = [];
|
|
361
|
-
const exports = [];
|
|
362
|
-
let defaultExportClass = null;
|
|
363
|
-
for (let i = 0;i < entrypoints.length; i++) {
|
|
364
|
-
const ep = entrypoints[i];
|
|
365
|
-
const sourceCode = readFileSync2(ep.path, "utf-8");
|
|
366
|
-
if (ep.isWorkerTs) {
|
|
367
|
-
const result = transformWorkerEntrypoint(sourceCode, ep.path, {
|
|
368
|
-
className: ep.className,
|
|
369
|
-
injectContext: false
|
|
370
|
-
});
|
|
371
|
-
if (result) {
|
|
372
|
-
const tempDir2 = join(dirname(ep.path), ".devflare");
|
|
373
|
-
mkdirSync(tempDir2, { recursive: true });
|
|
374
|
-
const tempPath = join(tempDir2, `__${ep.className}_${i}.ts`);
|
|
375
|
-
writeFileSync(tempPath, result.code);
|
|
376
|
-
imports.push(`import { ${ep.className} } from '${tempPath.replace(/\\/g, "/")}'`);
|
|
377
|
-
exports.push(ep.className);
|
|
378
|
-
if (!defaultExportClass) {
|
|
379
|
-
defaultExportClass = ep.className;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
} else {
|
|
383
|
-
imports.push(`import { ${ep.className} } from '${ep.path.replace(/\\/g, "/")}'`);
|
|
384
|
-
exports.push(ep.className);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
const defaultExport = defaultExportClass ? `
|
|
388
|
-
export default ${defaultExportClass}` : "";
|
|
389
|
-
const entryCode = `
|
|
390
|
-
${imports.join(`
|
|
391
|
-
`)}
|
|
392
|
-
export { ${exports.join(", ")} }${defaultExport}
|
|
393
|
-
`;
|
|
394
|
-
const tempDir = join(dirname(entrypoints[0].path), ".devflare");
|
|
395
|
-
mkdirSync(tempDir, { recursive: true });
|
|
396
|
-
const entryPath = join(tempDir, `__entry_${workerName}.ts`);
|
|
397
|
-
writeFileSync(entryPath, entryCode);
|
|
398
|
-
try {
|
|
399
|
-
const result = await bun.build({
|
|
400
|
-
entrypoints: [entryPath],
|
|
401
|
-
target: "browser",
|
|
402
|
-
format: "esm",
|
|
403
|
-
minify: false,
|
|
404
|
-
external: ["cloudflare:workers", "cloudflare:*"]
|
|
405
|
-
});
|
|
406
|
-
if (!result.success) {
|
|
407
|
-
console.warn(`[devflare] Failed to bundle worker "${workerName}": ${result.logs.join(`
|
|
408
|
-
`)}`);
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
411
|
-
const bundledCode = await result.outputs[0].text();
|
|
412
|
-
bundleCache.set(cacheKey, bundledCode);
|
|
413
|
-
return bundledCode;
|
|
414
|
-
} finally {
|
|
415
|
-
try {
|
|
416
|
-
unlinkSync(entryPath);
|
|
417
|
-
} catch {}
|
|
418
|
-
}
|
|
419
|
-
} catch (error) {
|
|
420
|
-
console.warn(`[devflare] Error bundling worker "${workerName}":`, error);
|
|
421
|
-
return null;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
function hasCrossWorkerDOs(config) {
|
|
425
|
-
const dos = config.bindings?.durableObjects;
|
|
426
|
-
if (!dos)
|
|
427
|
-
return false;
|
|
428
|
-
for (const doConfig of Object.values(dos)) {
|
|
429
|
-
const normalized = normalizeDOBinding(doConfig);
|
|
430
|
-
if (normalized.__ref)
|
|
431
|
-
return true;
|
|
432
|
-
}
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
async function resolveDOBindings(config, configDir) {
|
|
436
|
-
const dos = config.bindings?.durableObjects;
|
|
437
|
-
if (!dos) {
|
|
438
|
-
return { workers: [], crossWorkerDOBindings: {} };
|
|
439
|
-
}
|
|
440
|
-
const workersByName = new Map;
|
|
441
|
-
const crossWorkerDOBindings = {};
|
|
442
|
-
for (const [bindingName, rawDoConfig] of Object.entries(dos)) {
|
|
443
|
-
const hasRef = typeof rawDoConfig === "object" && "__ref" in rawDoConfig;
|
|
444
|
-
if (!hasRef) {
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
const ref = rawDoConfig.__ref;
|
|
448
|
-
if ("__import" in ref && typeof ref.__import === "function") {
|
|
449
|
-
await ref.resolve();
|
|
450
|
-
}
|
|
451
|
-
const doConfig = normalizeDOBinding(rawDoConfig);
|
|
452
|
-
const workerName = ref.name;
|
|
453
|
-
if (!workersByName.has(workerName)) {
|
|
454
|
-
const worker = await resolveDORefWorker(ref, configDir);
|
|
455
|
-
if (worker) {
|
|
456
|
-
workersByName.set(workerName, worker);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
crossWorkerDOBindings[bindingName] = {
|
|
460
|
-
className: doConfig.className,
|
|
461
|
-
scriptName: workerName
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
return {
|
|
465
|
-
workers: [...workersByName.values()],
|
|
466
|
-
crossWorkerDOBindings
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
async function resolveDORefWorker(ref, parentConfigDir) {
|
|
470
|
-
const config = ref.config;
|
|
471
|
-
if (!config)
|
|
472
|
-
return null;
|
|
473
|
-
const configPath = ref.configPath;
|
|
474
|
-
if (!configPath || configPath === "<resolved>") {
|
|
475
|
-
console.warn(`[devflare] Cannot resolve DO worker "${ref.name}" - configPath not available`);
|
|
476
|
-
return null;
|
|
477
|
-
}
|
|
478
|
-
const resolvedConfigPath = resolvePackageSpecifier(configPath, parentConfigDir);
|
|
479
|
-
const refConfigDir = dirname(resolvedConfigPath);
|
|
480
|
-
const dosConfig = config.bindings?.durableObjects;
|
|
481
|
-
if (!dosConfig || Object.keys(dosConfig).length === 0) {
|
|
482
|
-
console.warn(`[devflare] Referenced worker "${ref.name}" has no Durable Objects`);
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
const discoveredDOs = discoverDOFilesSync(refConfigDir);
|
|
486
|
-
const doClasses = [];
|
|
487
|
-
for (const [bindingName, rawDoConfig] of Object.entries(dosConfig)) {
|
|
488
|
-
const doConfig = normalizeDOBinding(rawDoConfig);
|
|
489
|
-
const className = doConfig.className;
|
|
490
|
-
const scriptName = doConfig.scriptName;
|
|
491
|
-
if (scriptName) {
|
|
492
|
-
const scriptPath = resolve(refConfigDir, "src", scriptName);
|
|
493
|
-
if (!existsSync(scriptPath)) {
|
|
494
|
-
const altPath = resolve(refConfigDir, scriptName);
|
|
495
|
-
if (!existsSync(altPath)) {
|
|
496
|
-
console.warn(`[devflare] DO script not found: ${scriptPath} or ${altPath}`);
|
|
497
|
-
continue;
|
|
498
|
-
}
|
|
499
|
-
doClasses.push({ bindingName, className, scriptPath: altPath });
|
|
500
|
-
} else {
|
|
501
|
-
doClasses.push({ bindingName, className, scriptPath });
|
|
502
|
-
}
|
|
503
|
-
} else {
|
|
504
|
-
const discoveredPath = discoveredDOs.get(className);
|
|
505
|
-
if (discoveredPath) {
|
|
506
|
-
doClasses.push({ bindingName, className, scriptPath: discoveredPath });
|
|
507
|
-
} else {
|
|
508
|
-
console.warn(`[devflare] DO "${bindingName}" (class: ${className}) not found in do.*.ts files in "${ref.name}"`);
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if (doClasses.length === 0) {
|
|
514
|
-
console.warn(`[devflare] No valid DO classes found in "${ref.name}"`);
|
|
515
|
-
return null;
|
|
516
|
-
}
|
|
517
|
-
const script = await bundleDOClasses(doClasses, ref.name);
|
|
518
|
-
if (!script)
|
|
519
|
-
return null;
|
|
520
|
-
const durableObjects = {};
|
|
521
|
-
for (const do_ of doClasses) {
|
|
522
|
-
durableObjects[do_.bindingName] = do_.className;
|
|
523
|
-
}
|
|
524
|
-
return {
|
|
525
|
-
name: ref.name,
|
|
526
|
-
script,
|
|
527
|
-
modules: true,
|
|
528
|
-
compatibilityDate: config.compatibilityDate ?? "2025-01-01",
|
|
529
|
-
durableObjects
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
async function bundleDOClasses(doClasses, workerName) {
|
|
533
|
-
const cacheKey = `do:${doClasses.map((d) => `${d.scriptPath}::${d.className}`).join("|")}`;
|
|
534
|
-
const cached = bundleCache.get(cacheKey);
|
|
535
|
-
if (cached)
|
|
536
|
-
return cached;
|
|
537
|
-
const bun = getBunRuntime();
|
|
538
|
-
if (!bun) {
|
|
539
|
-
console.warn("[devflare] Bun runtime required for bundling DO classes");
|
|
540
|
-
return null;
|
|
541
|
-
}
|
|
542
|
-
try {
|
|
543
|
-
const { writeFileSync, mkdirSync, unlinkSync } = await import("fs");
|
|
544
|
-
const imports = doClasses.map((d) => `import { ${d.className} } from '${d.scriptPath.replace(/\\/g, "/")}'`).join(`
|
|
545
|
-
`);
|
|
546
|
-
const exports = doClasses.map((d) => d.className).join(", ");
|
|
547
|
-
const entryCode = `
|
|
548
|
-
${imports}
|
|
549
|
-
|
|
550
|
-
// Re-export DO classes for Miniflare binding
|
|
551
|
-
export { ${exports} }
|
|
552
|
-
|
|
553
|
-
// Default export with fetch handler
|
|
554
|
-
export default {
|
|
555
|
-
async fetch(request, env) {
|
|
556
|
-
return new Response('DO Worker: ${workerName}')
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
`;
|
|
560
|
-
const tempDir = join(dirname(doClasses[0].scriptPath), ".devflare");
|
|
561
|
-
mkdirSync(tempDir, { recursive: true });
|
|
562
|
-
const entryPath = join(tempDir, `__do_entry_${workerName}.ts`);
|
|
563
|
-
writeFileSync(entryPath, entryCode);
|
|
564
|
-
try {
|
|
565
|
-
const result = await bun.build({
|
|
566
|
-
entrypoints: [entryPath],
|
|
567
|
-
target: "browser",
|
|
568
|
-
format: "esm",
|
|
569
|
-
minify: false,
|
|
570
|
-
external: ["cloudflare:workers", "cloudflare:*"]
|
|
571
|
-
});
|
|
572
|
-
if (!result.success) {
|
|
573
|
-
console.warn(`[devflare] Failed to bundle DO worker "${workerName}": ${result.logs.join(`
|
|
574
|
-
`)}`);
|
|
575
|
-
return null;
|
|
576
|
-
}
|
|
577
|
-
const bundledCode = await result.outputs[0].text();
|
|
578
|
-
bundleCache.set(cacheKey, bundledCode);
|
|
579
|
-
return bundledCode;
|
|
580
|
-
} finally {
|
|
581
|
-
try {
|
|
582
|
-
unlinkSync(entryPath);
|
|
583
|
-
} catch {}
|
|
584
|
-
}
|
|
585
|
-
} catch (error) {
|
|
586
|
-
console.warn(`[devflare] Error bundling DO worker "${workerName}":`, error);
|
|
587
|
-
return null;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// src/test/simple-context-durable-objects.ts
|
|
592
|
-
import { mkdirSync, writeFileSync } from "fs";
|
|
593
|
-
import { readFile } from "fs/promises";
|
|
594
|
-
import { dirname as dirname3, join as join3 } from "path";
|
|
595
|
-
|
|
596
|
-
// src/test/simple-context-gateway-script.ts
|
|
597
|
-
function buildGatewayScript(bundledCode, wrappers) {
|
|
598
|
-
return `
|
|
599
|
-
// Bundled transport + DO classes
|
|
600
|
-
${bundledCode}
|
|
601
|
-
|
|
602
|
-
// DO Wrappers with RPC
|
|
603
|
-
${wrappers}
|
|
604
|
-
|
|
605
|
-
// Transport encoding helper
|
|
606
|
-
const __transportEncoders = typeof transport !== 'undefined' ? transport : {}
|
|
607
|
-
|
|
608
|
-
function __encodeTransport(value) {
|
|
609
|
-
if (value === null || value === undefined) return value
|
|
610
|
-
|
|
611
|
-
// Try each encoder
|
|
612
|
-
for (const [typeName, transporter] of Object.entries(__transportEncoders)) {
|
|
613
|
-
const encoded = transporter.encode(value)
|
|
614
|
-
if (encoded !== false && encoded !== undefined) {
|
|
615
|
-
return { __transport: typeName, value: encoded }
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
// Recursively encode arrays and objects
|
|
620
|
-
if (Array.isArray(value)) {
|
|
621
|
-
return value.map(__encodeTransport)
|
|
622
|
-
}
|
|
623
|
-
if (typeof value === 'object') {
|
|
624
|
-
const result = {}
|
|
625
|
-
for (const [k, v] of Object.entries(value)) {
|
|
626
|
-
result[k] = __encodeTransport(v)
|
|
627
|
-
}
|
|
628
|
-
return result
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
return value
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// Gateway with WebSocket RPC
|
|
635
|
-
export default {
|
|
636
|
-
async fetch(request, env) {
|
|
637
|
-
if (request.headers.get('Upgrade') === 'websocket') {
|
|
638
|
-
const { 0: client, 1: server } = new WebSocketPair()
|
|
639
|
-
server.accept()
|
|
640
|
-
server.addEventListener('message', async (e) => {
|
|
641
|
-
try {
|
|
642
|
-
const m = JSON.parse(e.data)
|
|
643
|
-
if (m.t === 'rpc.call') {
|
|
644
|
-
const result = await executeRpc(env, m.method, m.params)
|
|
645
|
-
server.send(JSON.stringify({ t: 'rpc.ok', id: m.id, result }))
|
|
646
|
-
}
|
|
647
|
-
} catch (error) {
|
|
648
|
-
server.send(JSON.stringify({ t: 'rpc.err', id: 'unknown', error: { code: 'RPC_ERROR', message: error.message } }))
|
|
649
|
-
}
|
|
650
|
-
})
|
|
651
|
-
return new Response(null, { status: 101, webSocket: client })
|
|
652
|
-
}
|
|
653
|
-
return new Response('Gateway')
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
async function executeRpc(env, method, params) {
|
|
658
|
-
const [bindingName, ...rest] = method.split('.')
|
|
659
|
-
const op = rest.join('.')
|
|
660
|
-
const binding = env[bindingName]
|
|
661
|
-
const RAW_EMAIL = 'EmailMessage::raw'
|
|
662
|
-
if (!binding) throw new Error('Binding not found: ' + bindingName)
|
|
663
|
-
|
|
664
|
-
// KV operations
|
|
665
|
-
if (op === 'get') return binding.get(params[0], params[1])
|
|
666
|
-
if (op === 'put') return binding.put(params[0], params[1], params[2])
|
|
667
|
-
if (op === 'delete') return binding.delete(params[0])
|
|
668
|
-
if (op === 'list') return binding.list(params[0])
|
|
669
|
-
if (op === 'getWithMetadata') return binding.getWithMetadata(params[0], params[1])
|
|
670
|
-
|
|
671
|
-
// R2 operations
|
|
672
|
-
if (op === 'r2.get') return binding.get(params[0], params[1])
|
|
673
|
-
if (op === 'r2.put') return binding.put(params[0], params[1], params[2])
|
|
674
|
-
if (op === 'r2.delete') return binding.delete(params[0])
|
|
675
|
-
if (op === 'r2.list') return binding.list(params[0])
|
|
676
|
-
if (op === 'head') return binding.head(params[0])
|
|
677
|
-
|
|
678
|
-
// D1 operations
|
|
679
|
-
if (op === 'exec') return binding.exec(params[0])
|
|
680
|
-
if (op === 'dump') return binding.dump()
|
|
681
|
-
if (op === 'batch') {
|
|
682
|
-
const stmts = params[0].map(s => {
|
|
683
|
-
const stmt = binding.prepare(s.sql)
|
|
684
|
-
return s.bindings?.length ? stmt.bind(...s.bindings) : stmt
|
|
685
|
-
})
|
|
686
|
-
return binding.batch(stmts)
|
|
687
|
-
}
|
|
688
|
-
if (op === 'prepare.run') return binding.prepare(params[0]).bind(...(params[1] || [])).run()
|
|
689
|
-
if (op === 'prepare.all') return binding.prepare(params[0]).bind(...(params[1] || [])).all()
|
|
690
|
-
if (op === 'prepare.first') return binding.prepare(params[0]).bind(...(params[1] || [])).first(params[2])
|
|
691
|
-
if (op === 'prepare.raw') return binding.prepare(params[0]).bind(...(params[1] || [])).raw({ columnNames: params[2] })
|
|
692
|
-
|
|
693
|
-
// Send email operations
|
|
694
|
-
if (op === 'email.send') {
|
|
695
|
-
return binding.send(__normalizeEmailMessage(params[0]))
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
// DO operations
|
|
699
|
-
if (op === 'idFromName') {
|
|
700
|
-
return { __type: 'DOId', hex: binding.idFromName(params[0]).toString() }
|
|
701
|
-
}
|
|
702
|
-
if (op === 'stub.rpc') {
|
|
703
|
-
const [, idSerialized, rpcMethod, rpcParams] = params
|
|
704
|
-
const stub = binding.get(binding.idFromString(idSerialized.hex))
|
|
705
|
-
|
|
706
|
-
if (typeof stub[rpcMethod] === 'function') {
|
|
707
|
-
let result = await stub[rpcMethod](...(rpcParams || []))
|
|
708
|
-
result = __encodeTransport(result)
|
|
709
|
-
return result
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
const response = await stub.fetch(new Request('http://do/_rpc', {
|
|
713
|
-
method: 'POST',
|
|
714
|
-
headers: { 'Content-Type': 'application/json' },
|
|
715
|
-
body: JSON.stringify({ method: rpcMethod, params: rpcParams || [] })
|
|
716
|
-
}))
|
|
717
|
-
|
|
718
|
-
const payload = await response.json()
|
|
719
|
-
if (!response.ok || !payload?.ok) {
|
|
720
|
-
throw new Error(payload?.error?.message || ('DO RPC failed with status ' + response.status))
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
return payload.result
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
throw new Error('Unknown operation: ' + method)
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function __createEmailMessageRaw(raw) {
|
|
730
|
-
if (typeof raw === 'string' || raw instanceof ReadableStream) {
|
|
731
|
-
return raw
|
|
732
|
-
}
|
|
733
|
-
if (raw instanceof Uint8Array || raw instanceof ArrayBuffer) {
|
|
734
|
-
return new Response(raw).body
|
|
735
|
-
}
|
|
736
|
-
throw new Error('Unsupported EmailMessage raw payload')
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
function __buildRawEmail(message) {
|
|
740
|
-
const lines = []
|
|
741
|
-
const messageId = '<' + Date.now() + '-' + Math.random().toString(36).slice(2) + '@devflare.dev>'
|
|
742
|
-
|
|
743
|
-
lines.push('From: ' + message.from)
|
|
744
|
-
lines.push('To: ' + (Array.isArray(message.to) ? message.to.join(', ') : message.to))
|
|
745
|
-
lines.push('Date: ' + new Date().toUTCString())
|
|
746
|
-
lines.push('Message-ID: ' + messageId)
|
|
747
|
-
|
|
748
|
-
if (message.subject) lines.push('Subject: ' + message.subject)
|
|
749
|
-
if (message.replyTo) lines.push('Reply-To: ' + String(message.replyTo))
|
|
750
|
-
if (message.cc) lines.push('Cc: ' + (Array.isArray(message.cc) ? message.cc.join(', ') : message.cc))
|
|
751
|
-
if (message.bcc) lines.push('Bcc: ' + (Array.isArray(message.bcc) ? message.bcc.join(', ') : message.bcc))
|
|
752
|
-
|
|
753
|
-
for (const [key, value] of Object.entries(message.headers || {})) {
|
|
754
|
-
lines.push(key + ': ' + value)
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
lines.push('MIME-Version: 1.0')
|
|
758
|
-
lines.push('Content-Type: ' + (message.html ? 'text/html' : 'text/plain') + '; charset=UTF-8')
|
|
759
|
-
lines.push('')
|
|
760
|
-
lines.push(String(message.html ?? message.text ?? '').replace(/\\r?\\n/g, '\\r\\n'))
|
|
761
|
-
|
|
762
|
-
return lines.join('\\r\\n')
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
function __normalizeEmailMessage(message) {
|
|
766
|
-
if (!message || typeof message !== 'object' || !('from' in message) || !('to' in message)) {
|
|
767
|
-
return message
|
|
768
|
-
}
|
|
769
|
-
if ('EmailMessage::raw' in message) {
|
|
770
|
-
return message
|
|
771
|
-
}
|
|
772
|
-
if ('raw' in message && message.raw !== undefined) {
|
|
773
|
-
return {
|
|
774
|
-
from: message.from,
|
|
775
|
-
to: message.to,
|
|
776
|
-
[RAW_EMAIL]: __createEmailMessageRaw(message.raw)
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
return {
|
|
780
|
-
from: message.from,
|
|
781
|
-
to: message.to,
|
|
782
|
-
[RAW_EMAIL]: __createEmailMessageRaw(__buildRawEmail(message))
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
`;
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
// src/test/simple-context-paths.ts
|
|
789
|
-
import { existsSync as existsSync2 } from "fs";
|
|
790
|
-
import { createServer } from "net";
|
|
791
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
792
|
-
import { fileURLToPath } from "url";
|
|
793
|
-
var DEFAULT_TRANSPORT_ENTRY_FILES = [
|
|
794
|
-
"src/transport.ts",
|
|
795
|
-
"src/transport.js",
|
|
796
|
-
"src/transport.mts",
|
|
797
|
-
"src/transport.mjs"
|
|
798
|
-
];
|
|
799
|
-
var CURRENT_PACKAGE_ROOT = findPackageRoot(dirname2(fileURLToPath(import.meta.url)));
|
|
800
|
-
function getBunRuntime2() {
|
|
801
|
-
const g = globalThis;
|
|
802
|
-
if (typeof g.Bun === "object" && g.Bun !== null) {
|
|
803
|
-
return g.Bun;
|
|
804
|
-
}
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
function getCallerDirectory() {
|
|
808
|
-
const stackCallerDirectory = getStackCallerDirectory();
|
|
809
|
-
if (stackCallerDirectory) {
|
|
810
|
-
return stackCallerDirectory;
|
|
811
|
-
}
|
|
812
|
-
return process.cwd();
|
|
813
|
-
}
|
|
814
|
-
function getStackCallerDirectory() {
|
|
815
|
-
const originalPrepare = Error.prepareStackTrace;
|
|
816
|
-
Error.prepareStackTrace = (_, stack) => stack;
|
|
817
|
-
try {
|
|
818
|
-
const err = new Error;
|
|
819
|
-
const stack = err.stack;
|
|
820
|
-
for (const site of stack ?? []) {
|
|
821
|
-
const filename = site.getFileName?.();
|
|
822
|
-
if (filename && !isInsideCurrentPackage(filename) && !filename.includes("simple-context") && !filename.includes("node_modules") && !filename.includes("[") && existsSync2(filename)) {
|
|
823
|
-
return dirname2(filename);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
} finally {
|
|
827
|
-
Error.prepareStackTrace = originalPrepare;
|
|
828
|
-
}
|
|
829
|
-
return null;
|
|
830
|
-
}
|
|
831
|
-
function findPackageRoot(startDir) {
|
|
832
|
-
let currentDir = startDir;
|
|
833
|
-
while (true) {
|
|
834
|
-
if (existsSync2(join2(currentDir, "package.json"))) {
|
|
835
|
-
return currentDir;
|
|
836
|
-
}
|
|
837
|
-
const parentDir = dirname2(currentDir);
|
|
838
|
-
if (parentDir === currentDir) {
|
|
839
|
-
return startDir;
|
|
840
|
-
}
|
|
841
|
-
currentDir = parentDir;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
function isInsideCurrentPackage(filePath) {
|
|
845
|
-
const normalizedFilePath = filePath.replace(/\\/g, "/");
|
|
846
|
-
const normalizedPackageRoot = CURRENT_PACKAGE_ROOT.replace(/\\/g, "/");
|
|
847
|
-
return normalizedFilePath === normalizedPackageRoot || normalizedFilePath.startsWith(`${normalizedPackageRoot}/`);
|
|
848
|
-
}
|
|
849
|
-
async function findNearestConfig(startDir) {
|
|
850
|
-
let currentDir = startDir;
|
|
851
|
-
while (true) {
|
|
852
|
-
const configPath = await resolveConfigPath(currentDir);
|
|
853
|
-
if (configPath) {
|
|
854
|
-
return configPath;
|
|
855
|
-
}
|
|
856
|
-
const parentDir = dirname2(currentDir);
|
|
857
|
-
if (parentDir === currentDir) {
|
|
858
|
-
return null;
|
|
859
|
-
}
|
|
860
|
-
currentDir = parentDir;
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
async function getAvailablePort() {
|
|
864
|
-
return await new Promise((resolvePort, reject) => {
|
|
865
|
-
const server = createServer();
|
|
866
|
-
server.once("error", reject);
|
|
867
|
-
server.listen(0, "127.0.0.1", () => {
|
|
868
|
-
const address = server.address();
|
|
869
|
-
if (!address || typeof address === "string") {
|
|
870
|
-
server.close(() => reject(new Error("Could not determine an available port")));
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
873
|
-
const { port } = address;
|
|
874
|
-
server.close((error) => {
|
|
875
|
-
if (error) {
|
|
876
|
-
reject(error);
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
resolvePort(port);
|
|
880
|
-
});
|
|
881
|
-
});
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
function resolveTransportFile(configDir, configuredPath) {
|
|
885
|
-
if (typeof configuredPath === "string") {
|
|
886
|
-
return configuredPath;
|
|
887
|
-
}
|
|
888
|
-
if (configuredPath === null) {
|
|
889
|
-
return null;
|
|
890
|
-
}
|
|
891
|
-
for (const defaultEntry of DEFAULT_TRANSPORT_ENTRY_FILES) {
|
|
892
|
-
if (existsSync2(join2(configDir, defaultEntry))) {
|
|
893
|
-
return defaultEntry;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
return null;
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
// src/test/simple-context-durable-objects.ts
|
|
900
|
-
function findExportedClasses(code) {
|
|
901
|
-
const classes = [];
|
|
902
|
-
const classPattern = /export\s+class\s+(\w+)/g;
|
|
903
|
-
let match;
|
|
904
|
-
while ((match = classPattern.exec(code)) !== null) {
|
|
905
|
-
classes.push(match[1]);
|
|
906
|
-
}
|
|
907
|
-
return classes;
|
|
908
|
-
}
|
|
909
|
-
function classSupportsNativeDurableObjectRpc(code, className) {
|
|
910
|
-
const nativeRpcPattern = new RegExp(`export\\s+class\\s+${className}\\s+extends\\s+DurableObject\\b`);
|
|
911
|
-
return nativeRpcPattern.test(code);
|
|
912
|
-
}
|
|
913
|
-
function toGeneratedIdentifier(value) {
|
|
914
|
-
const normalized = value.replace(/[^A-Za-z0-9_$]/g, "_");
|
|
915
|
-
return /^[A-Za-z_$]/.test(normalized) ? normalized : `_${normalized}`;
|
|
916
|
-
}
|
|
917
|
-
async function discoverLocalDurableObjectClasses(config, configDir) {
|
|
918
|
-
const classToFilePath = new Map;
|
|
919
|
-
const doPatternConfig = config.files?.durableObjects;
|
|
920
|
-
const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
|
|
921
|
-
if (doPatternConfig === false) {
|
|
922
|
-
return classToFilePath;
|
|
923
|
-
}
|
|
924
|
-
const doFiles = await findFiles(doPattern, { cwd: configDir });
|
|
925
|
-
for (const filePath of doFiles) {
|
|
926
|
-
try {
|
|
927
|
-
const code = await readFile(filePath, "utf-8");
|
|
928
|
-
const classNames = findExportedClasses(code);
|
|
929
|
-
for (const className of classNames) {
|
|
930
|
-
classToFilePath.set(className, {
|
|
931
|
-
filePath,
|
|
932
|
-
nativeRpc: classSupportsNativeDurableObjectRpc(code, className)
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
} catch {}
|
|
936
|
-
}
|
|
937
|
-
return classToFilePath;
|
|
938
|
-
}
|
|
939
|
-
async function resolveLocalDurableObjects(config, configDir) {
|
|
940
|
-
const doConfig = {};
|
|
941
|
-
const doInfos = [];
|
|
942
|
-
const classToFilePath = await discoverLocalDurableObjectClasses(config, configDir);
|
|
943
|
-
for (const [name, rawDoInfo] of Object.entries(config.bindings?.durableObjects ?? {})) {
|
|
944
|
-
const doInfo = normalizeDOBinding(rawDoInfo);
|
|
945
|
-
if (doInfo.__ref) {
|
|
946
|
-
continue;
|
|
947
|
-
}
|
|
948
|
-
let scriptPath;
|
|
949
|
-
let nativeRpc = false;
|
|
950
|
-
if (doInfo.scriptName) {
|
|
951
|
-
scriptPath = join3(configDir, "src", doInfo.scriptName);
|
|
952
|
-
try {
|
|
953
|
-
const code = await readFile(scriptPath, "utf-8");
|
|
954
|
-
nativeRpc = classSupportsNativeDurableObjectRpc(code, doInfo.className);
|
|
955
|
-
} catch {
|
|
956
|
-
nativeRpc = false;
|
|
957
|
-
}
|
|
958
|
-
} else {
|
|
959
|
-
const discoveredClass = classToFilePath.get(doInfo.className);
|
|
960
|
-
if (!discoveredClass) {
|
|
961
|
-
throw new Error(`Durable object ${name} (className: '${doInfo.className}') not found.
|
|
962
|
-
` + `Either:
|
|
963
|
-
` + ` 1. Set files.durableObjects pattern in config (e.g., 'src/do.*.ts')
|
|
964
|
-
` + ` 2. Use explicit scriptName: { className: '${doInfo.className}', scriptName: 'do.file.ts' }`);
|
|
965
|
-
}
|
|
966
|
-
scriptPath = discoveredClass.filePath;
|
|
967
|
-
nativeRpc = discoveredClass.nativeRpc;
|
|
968
|
-
}
|
|
969
|
-
const runtimeClassName = nativeRpc ? doInfo.className : `__Devflare${toGeneratedIdentifier(name)}RpcWrapper`;
|
|
970
|
-
doConfig[name] = runtimeClassName;
|
|
971
|
-
doInfos.push({
|
|
972
|
-
name,
|
|
973
|
-
className: doInfo.className,
|
|
974
|
-
scriptPath,
|
|
975
|
-
nativeRpc,
|
|
976
|
-
runtimeClassName
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
return {
|
|
980
|
-
doConfig,
|
|
981
|
-
doInfos
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
function buildWrapperCode(doInfos) {
|
|
985
|
-
return doInfos.filter((info) => !info.nativeRpc).map((info) => `
|
|
986
|
-
export class ${info.runtimeClassName} {
|
|
987
|
-
constructor(state, env) {
|
|
988
|
-
this.__instance = new ${info.className}(state, env)
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
async fetch(request) {
|
|
992
|
-
const url = new URL(request.url)
|
|
993
|
-
if (request.method !== 'POST' || url.pathname !== '/_rpc') {
|
|
994
|
-
return new Response('Not found', { status: 404 })
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
try {
|
|
998
|
-
const payload = await request.json()
|
|
999
|
-
const method = payload?.method
|
|
1000
|
-
const params = Array.isArray(payload?.params) ? payload.params : []
|
|
1001
|
-
const target = this.__instance?.[method]
|
|
1002
|
-
|
|
1003
|
-
if (typeof target !== 'function') {
|
|
1004
|
-
return new Response(JSON.stringify({
|
|
1005
|
-
ok: false,
|
|
1006
|
-
error: { message: 'Method not found: ' + String(method) }
|
|
1007
|
-
}), {
|
|
1008
|
-
status: 404,
|
|
1009
|
-
headers: { 'Content-Type': 'application/json' }
|
|
1010
|
-
})
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
let result = await target.apply(this.__instance, params)
|
|
1014
|
-
result = __encodeTransport(result)
|
|
1015
|
-
|
|
1016
|
-
return new Response(JSON.stringify({ ok: true, result }), {
|
|
1017
|
-
headers: { 'Content-Type': 'application/json' }
|
|
1018
|
-
})
|
|
1019
|
-
} catch (error) {
|
|
1020
|
-
return new Response(JSON.stringify({
|
|
1021
|
-
ok: false,
|
|
1022
|
-
error: { message: error instanceof Error ? error.message : String(error) }
|
|
1023
|
-
}), {
|
|
1024
|
-
status: 500,
|
|
1025
|
-
headers: { 'Content-Type': 'application/json' }
|
|
1026
|
-
})
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
}`.trim()).join(`
|
|
1030
|
-
|
|
1031
|
-
`);
|
|
1032
|
-
}
|
|
1033
|
-
async function bundleDurableObjectModules(configDir, doInfos, transportFile) {
|
|
1034
|
-
const virtualImports = [];
|
|
1035
|
-
const virtualExports = [];
|
|
1036
|
-
if (transportFile) {
|
|
1037
|
-
const transportPath = join3(configDir, transportFile);
|
|
1038
|
-
virtualImports.push(`import { transport } from '${transportPath.replace(/\\/g, "/")}'`);
|
|
1039
|
-
virtualExports.push("export { transport }");
|
|
1040
|
-
}
|
|
1041
|
-
for (const info of doInfos) {
|
|
1042
|
-
virtualImports.push(`import { ${info.className} } from '${info.scriptPath.replace(/\\/g, "/")}'`);
|
|
1043
|
-
virtualExports.push(`export { ${info.className} }`);
|
|
1044
|
-
}
|
|
1045
|
-
if (virtualImports.length === 0) {
|
|
1046
|
-
return "";
|
|
1047
|
-
}
|
|
1048
|
-
const virtualEntry = [...virtualImports, "", ...virtualExports].join(`
|
|
1049
|
-
`);
|
|
1050
|
-
const virtualPath = join3(configDir, ".devflare", "__test_entry.ts");
|
|
1051
|
-
mkdirSync(dirname3(virtualPath), { recursive: true });
|
|
1052
|
-
writeFileSync(virtualPath, virtualEntry);
|
|
1053
|
-
const bun = getBunRuntime2();
|
|
1054
|
-
if (!bun) {
|
|
1055
|
-
throw new Error("Bun runtime is required for createTestContext with Durable Objects");
|
|
1056
|
-
}
|
|
1057
|
-
const result = await bun.build({
|
|
1058
|
-
entrypoints: [virtualPath],
|
|
1059
|
-
target: "browser",
|
|
1060
|
-
format: "esm",
|
|
1061
|
-
minify: false,
|
|
1062
|
-
external: ["cloudflare:workers", "cloudflare:*"]
|
|
1063
|
-
});
|
|
1064
|
-
if (!result.success) {
|
|
1065
|
-
throw new Error(`Failed to bundle test entry: ${result.logs.join(`
|
|
1066
|
-
`)}`);
|
|
1067
|
-
}
|
|
1068
|
-
return await result.outputs[0].text();
|
|
1069
|
-
}
|
|
1070
|
-
async function buildDurableObjectGateway(config, configDir, transportFile) {
|
|
1071
|
-
if (!config.bindings?.durableObjects) {
|
|
1072
|
-
return {
|
|
1073
|
-
script: buildGatewayScript("", "")
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
const { doConfig, doInfos } = await resolveLocalDurableObjects(config, configDir);
|
|
1077
|
-
const bundledCode = await bundleDurableObjectModules(configDir, doInfos, transportFile);
|
|
1078
|
-
const wrapperCode = buildWrapperCode(doInfos);
|
|
1079
|
-
return {
|
|
1080
|
-
durableObjects: doConfig,
|
|
1081
|
-
script: buildGatewayScript(bundledCode, wrapperCode)
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
// src/test/email.ts
|
|
1086
|
-
import { join as join4 } from "path";
|
|
1087
|
-
var miniflarePort = 8787;
|
|
1088
|
-
var emailListeners = [];
|
|
1089
|
-
var sentEmails = [];
|
|
1090
|
-
var emailHandlerPath = null;
|
|
1091
|
-
var configDir = null;
|
|
1092
|
-
var testEnvGetter = null;
|
|
1093
|
-
function configureEmail(options = {}) {
|
|
1094
|
-
if (options.port) {
|
|
1095
|
-
miniflarePort = options.port;
|
|
1096
|
-
}
|
|
1097
|
-
emailHandlerPath = options.handlerPath ?? emailHandlerPath;
|
|
1098
|
-
configDir = options.configDir ?? configDir;
|
|
1099
|
-
testEnvGetter = options.getEnv ?? testEnvGetter;
|
|
1100
|
-
}
|
|
1101
|
-
function buildRawEmail(options) {
|
|
1102
|
-
if (options.raw) {
|
|
1103
|
-
return options.raw;
|
|
1104
|
-
}
|
|
1105
|
-
const lines = [];
|
|
1106
|
-
const messageId = `<${Date.now()}-${Math.random().toString(36).slice(2)}@devflare.dev>`;
|
|
1107
|
-
const date = new Date().toUTCString();
|
|
1108
|
-
lines.push(`From: ${options.from}`);
|
|
1109
|
-
lines.push(`To: ${options.to}`);
|
|
1110
|
-
lines.push(`Date: ${date}`);
|
|
1111
|
-
lines.push(`Message-ID: ${messageId}`);
|
|
1112
|
-
if (options.subject) {
|
|
1113
|
-
lines.push(`Subject: ${options.subject}`);
|
|
1114
|
-
}
|
|
1115
|
-
if (options.headers) {
|
|
1116
|
-
for (const [key, value] of Object.entries(options.headers)) {
|
|
1117
|
-
lines.push(`${key}: ${value}`);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
lines.push("MIME-Version: 1.0");
|
|
1121
|
-
lines.push("Content-Type: text/plain; charset=UTF-8");
|
|
1122
|
-
lines.push("");
|
|
1123
|
-
lines.push(options.body ?? "");
|
|
1124
|
-
return lines.join(`\r
|
|
1125
|
-
`);
|
|
1126
|
-
}
|
|
1127
|
-
function createEmailHeaders(rawEmail) {
|
|
1128
|
-
const headers = new Headers;
|
|
1129
|
-
const lines = rawEmail.split(/\r?\n/);
|
|
1130
|
-
for (const line of lines) {
|
|
1131
|
-
if (!line.trim()) {
|
|
1132
|
-
break;
|
|
1133
|
-
}
|
|
1134
|
-
const colonIndex = line.indexOf(":");
|
|
1135
|
-
if (colonIndex <= 0) {
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
headers.append(line.slice(0, colonIndex).trim(), line.slice(colonIndex + 1).trim());
|
|
1139
|
-
}
|
|
1140
|
-
return headers;
|
|
1141
|
-
}
|
|
1142
|
-
function createRawEmailStream(rawEmail) {
|
|
1143
|
-
return new ReadableStream({
|
|
1144
|
-
start(controller) {
|
|
1145
|
-
controller.enqueue(new TextEncoder().encode(rawEmail));
|
|
1146
|
-
controller.close();
|
|
1147
|
-
}
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
function resolveEmailHandler(module) {
|
|
1151
|
-
if (typeof module.default === "function") {
|
|
1152
|
-
return module.default;
|
|
1153
|
-
}
|
|
1154
|
-
if (module.default && typeof module.default.email === "function") {
|
|
1155
|
-
return module.default.email.bind(module.default);
|
|
1156
|
-
}
|
|
1157
|
-
if (typeof module.email === "function") {
|
|
1158
|
-
return module.email;
|
|
1159
|
-
}
|
|
1160
|
-
return null;
|
|
1161
|
-
}
|
|
1162
|
-
function getRecordedRawContent(raw) {
|
|
1163
|
-
if (typeof raw === "string") {
|
|
1164
|
-
return raw;
|
|
1165
|
-
}
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
async function send(options) {
|
|
1169
|
-
const raw = buildRawEmail(options);
|
|
1170
|
-
if (emailHandlerPath && configDir && testEnvGetter) {
|
|
1171
|
-
const absolutePath = join4(configDir, emailHandlerPath);
|
|
1172
|
-
const handlerModule = await import(absolutePath);
|
|
1173
|
-
const emailHandler = resolveEmailHandler(handlerModule);
|
|
1174
|
-
if (!emailHandler) {
|
|
1175
|
-
throw new Error(`Email handler at "${emailHandlerPath}" must export a default function or named "email" export.
|
|
1176
|
-
NaN`);
|
|
1177
|
-
}
|
|
1178
|
-
const waitUntilPromises = [];
|
|
1179
|
-
const ctx = {
|
|
1180
|
-
waitUntil(promise) {
|
|
1181
|
-
waitUntilPromises.push(promise);
|
|
1182
|
-
},
|
|
1183
|
-
passThroughOnException() {},
|
|
1184
|
-
props: {}
|
|
1185
|
-
};
|
|
1186
|
-
const runtimeEnv = testEnvGetter();
|
|
1187
|
-
const timestamp = new Date;
|
|
1188
|
-
const message = {
|
|
1189
|
-
from: options.from,
|
|
1190
|
-
to: options.to,
|
|
1191
|
-
headers: createEmailHeaders(raw),
|
|
1192
|
-
raw: createRawEmailStream(raw),
|
|
1193
|
-
rawSize: raw.length,
|
|
1194
|
-
setReject(reason) {
|
|
1195
|
-
throw new Error(`Email rejected: ${reason}`);
|
|
1196
|
-
},
|
|
1197
|
-
async forward(rcptTo) {
|
|
1198
|
-
recordSentEmail({
|
|
1199
|
-
type: "forward",
|
|
1200
|
-
from: options.from,
|
|
1201
|
-
to: rcptTo,
|
|
1202
|
-
raw,
|
|
1203
|
-
timestamp
|
|
1204
|
-
});
|
|
1205
|
-
},
|
|
1206
|
-
async reply(message2) {
|
|
1207
|
-
recordSentEmail({
|
|
1208
|
-
type: "reply",
|
|
1209
|
-
from: message2.from ?? options.to,
|
|
1210
|
-
to: message2.to ?? options.from,
|
|
1211
|
-
raw: getRecordedRawContent(message2.raw),
|
|
1212
|
-
timestamp
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
};
|
|
1216
|
-
const emailEvent = createEmailEvent(message, runtimeEnv, ctx);
|
|
1217
|
-
await runWithEventContext(emailEvent, () => emailHandler(emailEvent));
|
|
1218
|
-
await Promise.all(waitUntilPromises);
|
|
1219
|
-
return new Response(JSON.stringify({ ok: true, from: options.from, to: options.to }), {
|
|
1220
|
-
headers: { "Content-Type": "application/json" }
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
const url = new URL(`http://localhost:${miniflarePort}/cdn-cgi/handler/email`);
|
|
1224
|
-
url.searchParams.set("from", options.from);
|
|
1225
|
-
url.searchParams.set("to", options.to);
|
|
1226
|
-
const response = await fetch(url.toString(), {
|
|
1227
|
-
method: "POST",
|
|
1228
|
-
headers: {
|
|
1229
|
-
"Content-Type": "text/plain"
|
|
1230
|
-
},
|
|
1231
|
-
body: raw
|
|
1232
|
-
});
|
|
1233
|
-
return response;
|
|
1234
|
-
}
|
|
1235
|
-
function onReceive(callback) {
|
|
1236
|
-
emailListeners.push(callback);
|
|
1237
|
-
return () => {
|
|
1238
|
-
emailListeners = emailListeners.filter((cb) => cb !== callback);
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
function getSentEmails() {
|
|
1242
|
-
return [...sentEmails];
|
|
1243
|
-
}
|
|
1244
|
-
function clearSentEmails() {
|
|
1245
|
-
sentEmails = [];
|
|
1246
|
-
}
|
|
1247
|
-
function recordSentEmail(email) {
|
|
1248
|
-
sentEmails.push(email);
|
|
1249
|
-
for (const listener of emailListeners) {
|
|
1250
|
-
try {
|
|
1251
|
-
listener(email);
|
|
1252
|
-
} catch (error) {
|
|
1253
|
-
console.error("[devflare/test] Email listener error:", error);
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
function resetEmailState() {
|
|
1258
|
-
miniflarePort = 8787;
|
|
1259
|
-
emailHandlerPath = null;
|
|
1260
|
-
configDir = null;
|
|
1261
|
-
testEnvGetter = null;
|
|
1262
|
-
emailListeners = [];
|
|
1263
|
-
sentEmails = [];
|
|
1264
|
-
}
|
|
1265
|
-
var email = {
|
|
1266
|
-
send,
|
|
1267
|
-
onReceive,
|
|
1268
|
-
getSentEmails,
|
|
1269
|
-
clearSentEmails
|
|
1270
|
-
};
|
|
1271
|
-
|
|
1272
|
-
// src/test/queue.ts
|
|
1273
|
-
import { join as join5 } from "path";
|
|
1274
|
-
var queueHandlerPath = null;
|
|
1275
|
-
var configDir2 = null;
|
|
1276
|
-
var testEnvGetter2 = null;
|
|
1277
|
-
function configureQueue(options) {
|
|
1278
|
-
queueHandlerPath = options.handlerPath;
|
|
1279
|
-
configDir2 = options.configDir;
|
|
1280
|
-
testEnvGetter2 = options.getEnv;
|
|
1281
|
-
}
|
|
1282
|
-
function resetQueueState() {
|
|
1283
|
-
queueHandlerPath = null;
|
|
1284
|
-
configDir2 = null;
|
|
1285
|
-
testEnvGetter2 = null;
|
|
1286
|
-
}
|
|
1287
|
-
function createMessage(options) {
|
|
1288
|
-
const id = options.id ?? crypto.randomUUID();
|
|
1289
|
-
const timestamp = options.timestamp ?? new Date;
|
|
1290
|
-
const attempts = options.attempts ?? 1;
|
|
1291
|
-
let state = "pending";
|
|
1292
|
-
return {
|
|
1293
|
-
id,
|
|
1294
|
-
timestamp,
|
|
1295
|
-
body: options.body,
|
|
1296
|
-
attempts,
|
|
1297
|
-
ack() {
|
|
1298
|
-
state = "acked";
|
|
1299
|
-
},
|
|
1300
|
-
retry(opts) {
|
|
1301
|
-
state = "retried";
|
|
1302
|
-
},
|
|
1303
|
-
retryAll() {
|
|
1304
|
-
state = "retried";
|
|
1305
|
-
},
|
|
1306
|
-
get _state() {
|
|
1307
|
-
return state;
|
|
1308
|
-
}
|
|
1309
|
-
};
|
|
1310
|
-
}
|
|
1311
|
-
function createMessageBatch(messages) {
|
|
1312
|
-
return {
|
|
1313
|
-
queue: "test-queue",
|
|
1314
|
-
messages,
|
|
1315
|
-
ackAll() {
|
|
1316
|
-
for (const msg of messages) {
|
|
1317
|
-
msg.ack();
|
|
1318
|
-
}
|
|
1319
|
-
},
|
|
1320
|
-
retryAll() {
|
|
1321
|
-
for (const msg of messages) {
|
|
1322
|
-
msg.retry();
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
};
|
|
1326
|
-
}
|
|
1327
|
-
async function trigger(messages) {
|
|
1328
|
-
if (!queueHandlerPath) {
|
|
1329
|
-
throw new Error("Queue handler not configured. Make sure your devflare.config.ts has files.queue set, " + "and the file exists at the specified path (default: src/queue.ts)");
|
|
1330
|
-
}
|
|
1331
|
-
if (!configDir2 || !testEnvGetter2) {
|
|
1332
|
-
throw new Error("Queue helper not initialized. Call createTestContext() before using cf.queue.trigger()");
|
|
1333
|
-
}
|
|
1334
|
-
const absolutePath = join5(configDir2, queueHandlerPath);
|
|
1335
|
-
const handlerModule = await import(absolutePath);
|
|
1336
|
-
const queueHandler = handlerModule.default ?? handlerModule.queue;
|
|
1337
|
-
if (typeof queueHandler !== "function") {
|
|
1338
|
-
throw new Error(`Queue handler at "${queueHandlerPath}" must export a default function or named "queue" export.
|
|
1339
|
-
NaN`);
|
|
1340
|
-
}
|
|
1341
|
-
const normalizedMessages = messages.map((msg) => {
|
|
1342
|
-
if (typeof msg === "object" && msg !== null && "body" in msg) {
|
|
1343
|
-
return msg;
|
|
1344
|
-
}
|
|
1345
|
-
return { body: msg };
|
|
1346
|
-
});
|
|
1347
|
-
const mockMessages = normalizedMessages.map((opts) => createMessage(opts));
|
|
1348
|
-
const batch = createMessageBatch(mockMessages);
|
|
1349
|
-
const waitUntilPromises = [];
|
|
1350
|
-
const ctx = {
|
|
1351
|
-
waitUntil(promise) {
|
|
1352
|
-
waitUntilPromises.push(promise);
|
|
1353
|
-
},
|
|
1354
|
-
passThroughOnException() {},
|
|
1355
|
-
props: {}
|
|
1356
|
-
};
|
|
1357
|
-
const env = testEnvGetter2();
|
|
1358
|
-
const queueEvent = createQueueEvent(batch, env, ctx);
|
|
1359
|
-
await runWithEventContext(queueEvent, () => queueHandler(queueEvent));
|
|
1360
|
-
await Promise.all(waitUntilPromises);
|
|
1361
|
-
const acked = [];
|
|
1362
|
-
const retried = [];
|
|
1363
|
-
const failed = [];
|
|
1364
|
-
for (const msg of mockMessages) {
|
|
1365
|
-
switch (msg._state) {
|
|
1366
|
-
case "acked":
|
|
1367
|
-
acked.push(msg.id);
|
|
1368
|
-
break;
|
|
1369
|
-
case "retried":
|
|
1370
|
-
retried.push(msg.id);
|
|
1371
|
-
break;
|
|
1372
|
-
case "failed":
|
|
1373
|
-
failed.push(msg.id);
|
|
1374
|
-
break;
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
return {
|
|
1378
|
-
acked,
|
|
1379
|
-
retried,
|
|
1380
|
-
failed,
|
|
1381
|
-
total: mockMessages.length
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
|
-
async function send2(message) {
|
|
1385
|
-
return trigger([message]);
|
|
1386
|
-
}
|
|
1387
|
-
var queue = {
|
|
1388
|
-
trigger,
|
|
1389
|
-
send: send2
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
// src/test/scheduled.ts
|
|
1393
|
-
import { join as join6 } from "path";
|
|
1394
|
-
var scheduledHandlerPath = null;
|
|
1395
|
-
var configDir3 = null;
|
|
1396
|
-
var testEnvGetter3 = null;
|
|
1397
|
-
function configureScheduled(options) {
|
|
1398
|
-
scheduledHandlerPath = options.handlerPath;
|
|
1399
|
-
configDir3 = options.configDir;
|
|
1400
|
-
testEnvGetter3 = options.getEnv;
|
|
1401
|
-
}
|
|
1402
|
-
function resetScheduledState() {
|
|
1403
|
-
scheduledHandlerPath = null;
|
|
1404
|
-
configDir3 = null;
|
|
1405
|
-
testEnvGetter3 = null;
|
|
1406
|
-
}
|
|
1407
|
-
async function trigger2(cronOrOptions) {
|
|
1408
|
-
if (!scheduledHandlerPath) {
|
|
1409
|
-
throw new Error("Scheduled handler not configured. Make sure your devflare.config.ts has files.scheduled set, " + "and the file exists at the specified path (default: src/scheduled.ts)");
|
|
1410
|
-
}
|
|
1411
|
-
if (!configDir3 || !testEnvGetter3) {
|
|
1412
|
-
throw new Error("Scheduled helper not initialized. Call createTestContext() before using cf.scheduled.trigger()");
|
|
1413
|
-
}
|
|
1414
|
-
const options = typeof cronOrOptions === "string" ? { cron: cronOrOptions } : cronOrOptions ?? {};
|
|
1415
|
-
const cron = options.cron ?? "* * * * *";
|
|
1416
|
-
const scheduledTime = options.scheduledTime instanceof Date ? options.scheduledTime.getTime() : options.scheduledTime ?? Date.now();
|
|
1417
|
-
const absolutePath = join6(configDir3, scheduledHandlerPath);
|
|
1418
|
-
const handlerModule = await import(absolutePath);
|
|
1419
|
-
const scheduledHandler = handlerModule.default ?? handlerModule.scheduled;
|
|
1420
|
-
if (typeof scheduledHandler !== "function") {
|
|
1421
|
-
throw new Error(`Scheduled handler at "${scheduledHandlerPath}" must export a default function or named "scheduled" export.
|
|
1422
|
-
NaN`);
|
|
1423
|
-
}
|
|
1424
|
-
const controller = {
|
|
1425
|
-
scheduledTime,
|
|
1426
|
-
cron,
|
|
1427
|
-
noRetry() {}
|
|
1428
|
-
};
|
|
1429
|
-
const waitUntilPromises = [];
|
|
1430
|
-
const ctx = {
|
|
1431
|
-
waitUntil(promise) {
|
|
1432
|
-
waitUntilPromises.push(promise);
|
|
1433
|
-
},
|
|
1434
|
-
passThroughOnException() {},
|
|
1435
|
-
props: {}
|
|
1436
|
-
};
|
|
1437
|
-
const env = testEnvGetter3();
|
|
1438
|
-
const scheduledEvent = createScheduledEvent(controller, env, ctx);
|
|
1439
|
-
try {
|
|
1440
|
-
await runWithEventContext(scheduledEvent, () => scheduledHandler(scheduledEvent));
|
|
1441
|
-
await Promise.all(waitUntilPromises);
|
|
1442
|
-
return {
|
|
1443
|
-
success: true,
|
|
1444
|
-
cron,
|
|
1445
|
-
scheduledTime
|
|
1446
|
-
};
|
|
1447
|
-
} catch (error) {
|
|
1448
|
-
return {
|
|
1449
|
-
success: false,
|
|
1450
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1451
|
-
cron,
|
|
1452
|
-
scheduledTime
|
|
1453
|
-
};
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
var scheduled = {
|
|
1457
|
-
trigger: trigger2
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
|
-
// src/test/tail.ts
|
|
1461
|
-
import { join as join7 } from "path";
|
|
1462
|
-
var tailHandlerPath = null;
|
|
1463
|
-
var configDir4 = null;
|
|
1464
|
-
var testEnvGetter4 = null;
|
|
1465
|
-
function configureTail(options) {
|
|
1466
|
-
tailHandlerPath = options.handlerPath;
|
|
1467
|
-
configDir4 = options.configDir;
|
|
1468
|
-
testEnvGetter4 = options.getEnv;
|
|
1469
|
-
}
|
|
1470
|
-
function resetTailState() {
|
|
1471
|
-
tailHandlerPath = null;
|
|
1472
|
-
configDir4 = null;
|
|
1473
|
-
testEnvGetter4 = null;
|
|
1474
|
-
}
|
|
1475
|
-
function createTraceItem(options) {
|
|
1476
|
-
return {
|
|
1477
|
-
scriptName: options.scriptName ?? "test-worker",
|
|
1478
|
-
outcome: options.outcome ?? "ok",
|
|
1479
|
-
eventTimestamp: options.eventTimestamp ?? Date.now(),
|
|
1480
|
-
event: options.event ?? {
|
|
1481
|
-
request: {
|
|
1482
|
-
url: "https://example.com/",
|
|
1483
|
-
method: "GET"
|
|
1484
|
-
}
|
|
1485
|
-
},
|
|
1486
|
-
logs: options.logs ?? [],
|
|
1487
|
-
exceptions: options.exceptions ?? [],
|
|
1488
|
-
diagnosticsChannelEvents: options.diagnosticsChannelEvents ?? [],
|
|
1489
|
-
scriptVersion: options.scriptVersion ?? { id: "test-version" },
|
|
1490
|
-
dispatchNamespace: options.dispatchNamespace,
|
|
1491
|
-
scriptTags: options.scriptTags ?? []
|
|
1492
|
-
};
|
|
1493
|
-
}
|
|
1494
|
-
async function trigger3(items) {
|
|
1495
|
-
if (!tailHandlerPath) {
|
|
1496
|
-
throw new Error("Tail handler not configured. Add a src/tail.ts file exporting tail(), " + "or configure a tail handler before calling cf.tail.trigger().");
|
|
1497
|
-
}
|
|
1498
|
-
if (!configDir4 || !testEnvGetter4) {
|
|
1499
|
-
throw new Error("Tail helper not initialized. Call createTestContext() before using cf.tail.trigger()");
|
|
1500
|
-
}
|
|
1501
|
-
const traceItems = items.map((item) => {
|
|
1502
|
-
if ("eventTimestamp" in item && "outcome" in item && "scriptName" in item) {
|
|
1503
|
-
return item;
|
|
1504
|
-
}
|
|
1505
|
-
return createTraceItem(item);
|
|
1506
|
-
});
|
|
1507
|
-
const absolutePath = join7(configDir4, tailHandlerPath);
|
|
1508
|
-
const handlerModule = await import(absolutePath);
|
|
1509
|
-
const tailHandler = handlerModule.default ?? handlerModule.tail;
|
|
1510
|
-
if (typeof tailHandler !== "function") {
|
|
1511
|
-
throw new Error(`Tail handler at "${tailHandlerPath}" must export a default function or named "tail" export.
|
|
1512
|
-
NaN`);
|
|
1513
|
-
}
|
|
1514
|
-
const waitUntilPromises = [];
|
|
1515
|
-
const ctx = {
|
|
1516
|
-
waitUntil(promise) {
|
|
1517
|
-
waitUntilPromises.push(promise);
|
|
1518
|
-
},
|
|
1519
|
-
passThroughOnException() {},
|
|
1520
|
-
props: {}
|
|
1521
|
-
};
|
|
1522
|
-
const env = testEnvGetter4();
|
|
1523
|
-
const tailEvent = createTailEvent(traceItems, env, ctx);
|
|
1524
|
-
try {
|
|
1525
|
-
await runWithEventContext(tailEvent, () => tailHandler(tailEvent));
|
|
1526
|
-
await Promise.all(waitUntilPromises);
|
|
1527
|
-
return {
|
|
1528
|
-
success: true,
|
|
1529
|
-
itemCount: traceItems.length
|
|
1530
|
-
};
|
|
1531
|
-
} catch (error) {
|
|
1532
|
-
return {
|
|
1533
|
-
success: false,
|
|
1534
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1535
|
-
itemCount: traceItems.length
|
|
1536
|
-
};
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
function create(options = {}) {
|
|
1540
|
-
return createTraceItem(options);
|
|
1541
|
-
}
|
|
1542
|
-
var tail = {
|
|
1543
|
-
trigger: trigger3,
|
|
1544
|
-
create
|
|
1545
|
-
};
|
|
1546
|
-
|
|
1547
|
-
// src/test/worker.ts
|
|
1548
|
-
import { join as join8 } from "path";
|
|
1549
|
-
var fetchHandlerPath = null;
|
|
1550
|
-
var configDir5 = null;
|
|
1551
|
-
var testEnvGetter5 = null;
|
|
1552
|
-
var fileRoutes = [];
|
|
1553
|
-
function configureWorker(options) {
|
|
1554
|
-
fetchHandlerPath = options.handlerPath;
|
|
1555
|
-
fileRoutes = options.routes ?? [];
|
|
1556
|
-
configDir5 = options.configDir;
|
|
1557
|
-
testEnvGetter5 = options.getEnv;
|
|
1558
|
-
}
|
|
1559
|
-
function resetWorkerState() {
|
|
1560
|
-
fetchHandlerPath = null;
|
|
1561
|
-
fileRoutes = [];
|
|
1562
|
-
configDir5 = null;
|
|
1563
|
-
testEnvGetter5 = null;
|
|
1564
|
-
}
|
|
1565
|
-
async function fetch2(request, options) {
|
|
1566
|
-
if (!fetchHandlerPath && fileRoutes.length === 0) {
|
|
1567
|
-
throw new Error("Fetch handler not configured. Make sure your devflare.config.ts has files.fetch set or a routes directory is available, " + "and that the corresponding files exist (defaults: src/fetch.ts and src/routes/**).");
|
|
1568
|
-
}
|
|
1569
|
-
if (!configDir5 || !testEnvGetter5) {
|
|
1570
|
-
throw new Error("Worker helper not initialized. Call createTestContext() before using cf.worker.fetch()");
|
|
1571
|
-
}
|
|
1572
|
-
const workerConfigDir = configDir5;
|
|
1573
|
-
const getEnv = testEnvGetter5;
|
|
1574
|
-
let req;
|
|
1575
|
-
if (typeof request === "string") {
|
|
1576
|
-
const url = request.startsWith("http") ? request : `http://localhost${request.startsWith("/") ? "" : "/"}${request}`;
|
|
1577
|
-
const headers = new Headers(options?.headers);
|
|
1578
|
-
let body;
|
|
1579
|
-
if (options?.body !== undefined) {
|
|
1580
|
-
if (typeof options.body === "string") {
|
|
1581
|
-
body = options.body;
|
|
1582
|
-
} else {
|
|
1583
|
-
body = JSON.stringify(options.body);
|
|
1584
|
-
if (!headers.has("Content-Type")) {
|
|
1585
|
-
headers.set("Content-Type", "application/json");
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
req = new Request(url, {
|
|
1590
|
-
method: options?.method ?? "GET",
|
|
1591
|
-
headers,
|
|
1592
|
-
body
|
|
1593
|
-
});
|
|
1594
|
-
} else {
|
|
1595
|
-
req = request;
|
|
1596
|
-
}
|
|
1597
|
-
const handlerModule = fetchHandlerPath ? await import(join8(workerConfigDir, fetchHandlerPath)) : {};
|
|
1598
|
-
const routeModules = await Promise.all(fileRoutes.map(async (route) => {
|
|
1599
|
-
return {
|
|
1600
|
-
...route,
|
|
1601
|
-
module: await import(join8(workerConfigDir, route.filePath))
|
|
1602
|
-
};
|
|
1603
|
-
}));
|
|
1604
|
-
const methodExports = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "ALL"];
|
|
1605
|
-
const hasMethodHandler = methodExports.some((method) => {
|
|
1606
|
-
return typeof handlerModule[method] === "function" || typeof handlerModule.default?.[method] === "function";
|
|
1607
|
-
});
|
|
1608
|
-
if (!resolveFetchHandler(handlerModule) && !hasMethodHandler && routeModules.length === 0) {
|
|
1609
|
-
throw new Error(`Fetch handler at "${fetchHandlerPath}" must export one of:
|
|
1610
|
-
- request-wide "handle" middleware
|
|
1611
|
-
- named "fetch"
|
|
1612
|
-
- default fetch handler
|
|
1613
|
-
- HTTP method exports such as "GET" or "POST"`);
|
|
1614
|
-
}
|
|
1615
|
-
const waitUntilPromises = [];
|
|
1616
|
-
const ctx = {
|
|
1617
|
-
waitUntil(promise) {
|
|
1618
|
-
waitUntilPromises.push(promise);
|
|
1619
|
-
},
|
|
1620
|
-
passThroughOnException() {},
|
|
1621
|
-
props: {}
|
|
1622
|
-
};
|
|
1623
|
-
const env = getEnv();
|
|
1624
|
-
const initialRouteMatch = routeModules.length > 0 ? matchFetchRoute(routeModules, req) : null;
|
|
1625
|
-
const fetchEvent = createFetchEvent(req, env, ctx, {
|
|
1626
|
-
params: initialRouteMatch?.params ?? {}
|
|
1627
|
-
});
|
|
1628
|
-
const response = await runWithEventContext(fetchEvent, () => invokeFetchModule(handlerModule, fetchEvent, routeModules.length > 0 ? createRouteResolve(routeModules, fetchEvent) : undefined));
|
|
1629
|
-
return response;
|
|
1630
|
-
}
|
|
1631
|
-
async function get(path, headers) {
|
|
1632
|
-
return fetch2(path, { method: "GET", headers });
|
|
1633
|
-
}
|
|
1634
|
-
async function post(path, body, headers) {
|
|
1635
|
-
return fetch2(path, { method: "POST", body, headers });
|
|
1636
|
-
}
|
|
1637
|
-
async function put(path, body, headers) {
|
|
1638
|
-
return fetch2(path, { method: "PUT", body, headers });
|
|
1639
|
-
}
|
|
1640
|
-
async function del(path, headers) {
|
|
1641
|
-
return fetch2(path, { method: "DELETE", headers });
|
|
1642
|
-
}
|
|
1643
|
-
async function patch(path, body, headers) {
|
|
1644
|
-
return fetch2(path, { method: "PATCH", body, headers });
|
|
1645
|
-
}
|
|
1646
|
-
var worker = {
|
|
1647
|
-
fetch: fetch2,
|
|
1648
|
-
get,
|
|
1649
|
-
post,
|
|
1650
|
-
put,
|
|
1651
|
-
delete: del,
|
|
1652
|
-
patch
|
|
1653
|
-
};
|
|
1654
|
-
|
|
1655
|
-
// src/test/simple-context.ts
|
|
1656
|
-
var globalClient = null;
|
|
1657
|
-
var globalMiniflare = null;
|
|
1658
|
-
var globalEnvProxy = null;
|
|
1659
|
-
var globalTransportDecode = null;
|
|
1660
|
-
var globalRemoteBindings = null;
|
|
1661
|
-
var globalMiniflareBindings = null;
|
|
1662
|
-
var TEST_CONTEXT_STARTUP_RETRY_ATTEMPTS = 3;
|
|
1663
|
-
var TEST_CONTEXT_STARTUP_RETRY_DELAY_MS = 75;
|
|
1664
|
-
var TEST_CONTEXT_BRIDGE_CONNECT_RETRY_ATTEMPTS = 8;
|
|
1665
|
-
var TEST_CONTEXT_BRIDGE_CONNECT_RETRY_DELAY_MS = 150;
|
|
1666
|
-
function isRetriableTestContextStartupError(error) {
|
|
1667
|
-
if (!(error instanceof Error)) {
|
|
1668
|
-
return false;
|
|
1669
|
-
}
|
|
1670
|
-
const message = error.message.toLowerCase();
|
|
1671
|
-
return message.includes("websocket connection failed") || message.includes("connection timeout: ws://") || message.includes("econnrefused") || message.includes("eaddrinuse") || message.includes("address already in use");
|
|
1672
|
-
}
|
|
1673
|
-
async function waitForTestContextStartupRetry() {
|
|
1674
|
-
await new Promise((resolve3) => setTimeout(resolve3, TEST_CONTEXT_STARTUP_RETRY_DELAY_MS));
|
|
1675
|
-
}
|
|
1676
|
-
async function waitForBridgeClientRetry() {
|
|
1677
|
-
await new Promise((resolve3) => setTimeout(resolve3, TEST_CONTEXT_BRIDGE_CONNECT_RETRY_DELAY_MS));
|
|
1678
|
-
}
|
|
1679
|
-
function shouldPreferBridgeBinding(hint) {
|
|
1680
|
-
return hint === "do" || hint === "service";
|
|
1681
|
-
}
|
|
1682
|
-
async function connectBridgeClientWithRetry(url) {
|
|
1683
|
-
let lastError;
|
|
1684
|
-
for (let attempt = 1;attempt <= TEST_CONTEXT_BRIDGE_CONNECT_RETRY_ATTEMPTS; attempt++) {
|
|
1685
|
-
const client = new BridgeClient({ url });
|
|
1686
|
-
try {
|
|
1687
|
-
await client.connect();
|
|
1688
|
-
return client;
|
|
1689
|
-
} catch (error) {
|
|
1690
|
-
lastError = error;
|
|
1691
|
-
client.disconnect();
|
|
1692
|
-
if (attempt >= TEST_CONTEXT_BRIDGE_CONNECT_RETRY_ATTEMPTS || !isRetriableTestContextStartupError(error)) {
|
|
1693
|
-
throw error;
|
|
1694
|
-
}
|
|
1695
|
-
await waitForBridgeClientRetry();
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
throw lastError instanceof Error ? lastError : new Error("Bridge-backed test context could not connect to the WebSocket gateway.");
|
|
1699
|
-
}
|
|
1700
|
-
async function startBridgeBackedTestContext(mfConfig) {
|
|
1701
|
-
const { Miniflare } = await import("miniflare");
|
|
1702
|
-
for (let attempt = 1;attempt <= TEST_CONTEXT_STARTUP_RETRY_ATTEMPTS; attempt++) {
|
|
1703
|
-
const port = await getAvailablePort();
|
|
1704
|
-
let miniflare = null;
|
|
1705
|
-
let client = null;
|
|
1706
|
-
try {
|
|
1707
|
-
miniflare = new Miniflare({
|
|
1708
|
-
...mfConfig,
|
|
1709
|
-
port
|
|
1710
|
-
});
|
|
1711
|
-
await miniflare.ready;
|
|
1712
|
-
const miniflareBindings = wrapEnvSendEmailBindings(await miniflare.getBindings());
|
|
1713
|
-
client = await connectBridgeClientWithRetry(`ws://localhost:${port}`);
|
|
1714
|
-
return {
|
|
1715
|
-
port,
|
|
1716
|
-
client,
|
|
1717
|
-
miniflare,
|
|
1718
|
-
miniflareBindings
|
|
1719
|
-
};
|
|
1720
|
-
} catch (error) {
|
|
1721
|
-
client?.disconnect();
|
|
1722
|
-
if (miniflare) {
|
|
1723
|
-
try {
|
|
1724
|
-
await miniflare.dispose();
|
|
1725
|
-
} catch {}
|
|
1726
|
-
}
|
|
1727
|
-
if (attempt >= TEST_CONTEXT_STARTUP_RETRY_ATTEMPTS || !isRetriableTestContextStartupError(error)) {
|
|
1728
|
-
throw error;
|
|
1729
|
-
}
|
|
1730
|
-
await waitForTestContextStartupRetry();
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
throw new Error("Bridge-backed test context startup exhausted all retry attempts.");
|
|
1734
|
-
}
|
|
1735
|
-
async function createTestContext(configPath) {
|
|
1736
|
-
const callerDir = getCallerDirectory();
|
|
1737
|
-
let absolutePath;
|
|
1738
|
-
if (configPath) {
|
|
1739
|
-
absolutePath = resolve2(callerDir, configPath);
|
|
1740
|
-
} else {
|
|
1741
|
-
const found = await findNearestConfig(callerDir);
|
|
1742
|
-
if (!found) {
|
|
1743
|
-
throw new Error(`Could not find a devflare config file. Searched upward from: ${callerDir}
|
|
1744
|
-
Expected one of: devflare.config.ts, devflare.config.mts, devflare.config.js, devflare.config.mjs
|
|
1745
|
-
Either create a config file or provide an explicit path: createTestContext('./path/to/config.ts')`);
|
|
1746
|
-
}
|
|
1747
|
-
absolutePath = found;
|
|
1748
|
-
}
|
|
1749
|
-
const configDir6 = dirname4(absolutePath);
|
|
1750
|
-
const config = await loadConfig({
|
|
1751
|
-
cwd: configDir6,
|
|
1752
|
-
configFile: absolutePath.split(/[/\\]/).pop()
|
|
1753
|
-
});
|
|
1754
|
-
globalRemoteBindings = {};
|
|
1755
|
-
if (isRemoteModeActive()) {
|
|
1756
|
-
if (config.bindings?.ai) {
|
|
1757
|
-
const aiBindingName = config.bindings.ai.binding || "AI";
|
|
1758
|
-
globalRemoteBindings[aiBindingName] = createRemoteAI(config.accountId);
|
|
1759
|
-
}
|
|
1760
|
-
if (config.bindings?.vectorize) {
|
|
1761
|
-
for (const [name, vectorConfig] of Object.entries(config.bindings.vectorize)) {
|
|
1762
|
-
globalRemoteBindings[name] = createRemoteVectorize(vectorConfig.indexName, config.accountId);
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
if (config.vars) {
|
|
1767
|
-
for (const [key, value] of Object.entries(config.vars)) {
|
|
1768
|
-
globalRemoteBindings[key] = value;
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
if (config.bindings?.sendEmail) {
|
|
1772
|
-
for (const [name, binding] of Object.entries(config.bindings.sendEmail)) {
|
|
1773
|
-
globalRemoteBindings[name] = createLocalSendEmailBinding(binding);
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
const hints = {};
|
|
1777
|
-
if (config.bindings?.kv) {
|
|
1778
|
-
for (const name of Object.keys(config.bindings.kv)) {
|
|
1779
|
-
hints[name] = "kv";
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
if (config.bindings?.r2) {
|
|
1783
|
-
for (const name of Object.keys(config.bindings.r2)) {
|
|
1784
|
-
hints[name] = "r2";
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
if (config.bindings?.d1) {
|
|
1788
|
-
for (const name of Object.keys(config.bindings.d1)) {
|
|
1789
|
-
hints[name] = "d1";
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
if (config.bindings?.durableObjects) {
|
|
1793
|
-
for (const name of Object.keys(config.bindings.durableObjects)) {
|
|
1794
|
-
hints[name] = "do";
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
if (config.bindings?.services) {
|
|
1798
|
-
for (const name of Object.keys(config.bindings.services)) {
|
|
1799
|
-
hints[name] = "service";
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
if (config.bindings?.sendEmail) {
|
|
1803
|
-
for (const name of Object.keys(config.bindings.sendEmail)) {
|
|
1804
|
-
hints[name] = "sendEmail";
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
const needsMultiWorkerForServices = hasServiceBindings(config);
|
|
1808
|
-
const needsMultiWorkerForDOs = hasCrossWorkerDOs(config);
|
|
1809
|
-
const needsMultiWorker = needsMultiWorkerForServices || needsMultiWorkerForDOs;
|
|
1810
|
-
let serviceBindingResolution = null;
|
|
1811
|
-
let doBindingResolution = null;
|
|
1812
|
-
if (needsMultiWorkerForServices) {
|
|
1813
|
-
serviceBindingResolution = await resolveServiceBindings(config, configDir6);
|
|
1814
|
-
}
|
|
1815
|
-
if (needsMultiWorkerForDOs) {
|
|
1816
|
-
doBindingResolution = await resolveDOBindings(config, configDir6);
|
|
1817
|
-
}
|
|
1818
|
-
const localWorkerBindings = config.vars ?? {};
|
|
1819
|
-
const mfConfig = {
|
|
1820
|
-
modules: true
|
|
1821
|
-
};
|
|
1822
|
-
if (config.bindings?.kv) {
|
|
1823
|
-
mfConfig.kvNamespaces = Object.keys(config.bindings.kv);
|
|
1824
|
-
}
|
|
1825
|
-
if (config.bindings?.r2) {
|
|
1826
|
-
mfConfig.r2Buckets = Object.keys(config.bindings.r2);
|
|
1827
|
-
}
|
|
1828
|
-
if (config.bindings?.d1) {
|
|
1829
|
-
mfConfig.d1Databases = Object.fromEntries(Object.entries(config.bindings.d1).map(([bindingName, bindingConfig]) => {
|
|
1830
|
-
return [bindingName, getLocalD1DatabaseIdentifier(bindingConfig)];
|
|
1831
|
-
}));
|
|
1832
|
-
}
|
|
1833
|
-
if (config.bindings?.queues?.producers) {
|
|
1834
|
-
const queueProducers = {};
|
|
1835
|
-
for (const [bindingName, queueName] of Object.entries(config.bindings.queues.producers)) {
|
|
1836
|
-
queueProducers[bindingName] = { queueName };
|
|
1837
|
-
}
|
|
1838
|
-
mfConfig.queueProducers = queueProducers;
|
|
1839
|
-
}
|
|
1840
|
-
if (Object.keys(localWorkerBindings).length > 0) {
|
|
1841
|
-
mfConfig.bindings = localWorkerBindings;
|
|
1842
|
-
}
|
|
1843
|
-
if (config.bindings?.sendEmail) {
|
|
1844
|
-
mfConfig.email = {
|
|
1845
|
-
send_email: Object.entries(config.bindings.sendEmail).map(([name, binding]) => ({
|
|
1846
|
-
name,
|
|
1847
|
-
...binding.destinationAddress && {
|
|
1848
|
-
destination_address: binding.destinationAddress
|
|
1849
|
-
},
|
|
1850
|
-
...binding.allowedDestinationAddresses && {
|
|
1851
|
-
allowed_destination_addresses: binding.allowedDestinationAddresses
|
|
1852
|
-
},
|
|
1853
|
-
...binding.allowedSenderAddresses && {
|
|
1854
|
-
allowed_sender_addresses: binding.allowedSenderAddresses
|
|
1855
|
-
}
|
|
1856
|
-
}))
|
|
1857
|
-
};
|
|
1858
|
-
}
|
|
1859
|
-
const transportFile = resolveTransportFile(configDir6, config.files?.transport);
|
|
1860
|
-
if (transportFile) {
|
|
1861
|
-
const transportPath = join9(configDir6, transportFile);
|
|
1862
|
-
const transportModule = await import(transportPath);
|
|
1863
|
-
if (!transportModule.transport) {
|
|
1864
|
-
console.warn(`[devflare] Warning: Transport file "${transportFile}" does not export a named "transport" object.
|
|
1865
|
-
Expected: export const transport = { ... }
|
|
1866
|
-
Transport encoding/decoding will be disabled.`);
|
|
1867
|
-
} else {
|
|
1868
|
-
globalTransportDecode = new Map;
|
|
1869
|
-
for (const [typeName, transporter] of Object.entries(transportModule.transport)) {
|
|
1870
|
-
const t = transporter;
|
|
1871
|
-
globalTransportDecode.set(typeName, t.decode);
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
const gateway = await buildDurableObjectGateway(config, configDir6, transportFile);
|
|
1876
|
-
mfConfig.script = gateway.script;
|
|
1877
|
-
if (gateway.durableObjects) {
|
|
1878
|
-
mfConfig.durableObjects = gateway.durableObjects;
|
|
1879
|
-
}
|
|
1880
|
-
const hasMultiWorkerServices = serviceBindingResolution && serviceBindingResolution.workers.length > 0;
|
|
1881
|
-
const hasMultiWorkerDOs = doBindingResolution && doBindingResolution.workers.length > 0;
|
|
1882
|
-
if (hasMultiWorkerServices || hasMultiWorkerDOs) {
|
|
1883
|
-
const primaryDurableObjects = {
|
|
1884
|
-
...mfConfig.durableObjects || {},
|
|
1885
|
-
...doBindingResolution?.crossWorkerDOBindings || {}
|
|
1886
|
-
};
|
|
1887
|
-
const primaryWorker = {
|
|
1888
|
-
name: config.name ?? "primary",
|
|
1889
|
-
modules: true,
|
|
1890
|
-
script: mfConfig.script,
|
|
1891
|
-
compatibilityDate: config.compatibilityDate ?? "2025-01-01",
|
|
1892
|
-
...mfConfig.kvNamespaces && { kvNamespaces: mfConfig.kvNamespaces },
|
|
1893
|
-
...mfConfig.r2Buckets && { r2Buckets: mfConfig.r2Buckets },
|
|
1894
|
-
...mfConfig.d1Databases && { d1Databases: mfConfig.d1Databases },
|
|
1895
|
-
...mfConfig.email && { email: mfConfig.email },
|
|
1896
|
-
...Object.keys(primaryDurableObjects).length > 0 && { durableObjects: primaryDurableObjects },
|
|
1897
|
-
...serviceBindingResolution?.primaryServiceBindings && { serviceBindings: serviceBindingResolution.primaryServiceBindings }
|
|
1898
|
-
};
|
|
1899
|
-
const additionalWorkers = [
|
|
1900
|
-
...serviceBindingResolution?.workers || [],
|
|
1901
|
-
...doBindingResolution?.workers || []
|
|
1902
|
-
];
|
|
1903
|
-
const workersByName = new Map;
|
|
1904
|
-
for (const worker2 of additionalWorkers) {
|
|
1905
|
-
if (!workersByName.has(worker2.name)) {
|
|
1906
|
-
workersByName.set(worker2.name, worker2);
|
|
1907
|
-
continue;
|
|
1908
|
-
}
|
|
1909
|
-
const existing = workersByName.get(worker2.name);
|
|
1910
|
-
if (worker2.durableObjects) {
|
|
1911
|
-
existing.durableObjects = {
|
|
1912
|
-
...existing.durableObjects || {},
|
|
1913
|
-
...worker2.durableObjects
|
|
1914
|
-
};
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
const workers = [primaryWorker, ...workersByName.values()];
|
|
1918
|
-
delete mfConfig.script;
|
|
1919
|
-
delete mfConfig.modules;
|
|
1920
|
-
delete mfConfig.kvNamespaces;
|
|
1921
|
-
delete mfConfig.r2Buckets;
|
|
1922
|
-
delete mfConfig.d1Databases;
|
|
1923
|
-
delete mfConfig.durableObjects;
|
|
1924
|
-
mfConfig.workers = workers;
|
|
1925
|
-
}
|
|
1926
|
-
let activePort;
|
|
1927
|
-
if (hasMultiWorkerServices || hasMultiWorkerDOs) {
|
|
1928
|
-
const { Miniflare } = await import("miniflare");
|
|
1929
|
-
activePort = await getAvailablePort();
|
|
1930
|
-
globalMiniflare = new Miniflare({
|
|
1931
|
-
...mfConfig,
|
|
1932
|
-
port: activePort
|
|
1933
|
-
});
|
|
1934
|
-
await globalMiniflare.ready;
|
|
1935
|
-
globalMiniflareBindings = wrapEnvSendEmailBindings(await globalMiniflare.getBindings());
|
|
1936
|
-
} else {
|
|
1937
|
-
const startedBridgeBackedTestContext = await startBridgeBackedTestContext(mfConfig);
|
|
1938
|
-
activePort = startedBridgeBackedTestContext.port;
|
|
1939
|
-
globalMiniflare = startedBridgeBackedTestContext.miniflare;
|
|
1940
|
-
globalMiniflareBindings = startedBridgeBackedTestContext.miniflareBindings;
|
|
1941
|
-
globalClient = startedBridgeBackedTestContext.client;
|
|
1942
|
-
}
|
|
1943
|
-
const disposeContext = async () => {
|
|
1944
|
-
if (globalClient) {
|
|
1945
|
-
await globalClient.disconnect();
|
|
1946
|
-
globalClient = null;
|
|
1947
|
-
}
|
|
1948
|
-
if (globalMiniflare) {
|
|
1949
|
-
await globalMiniflare.dispose();
|
|
1950
|
-
globalMiniflare = null;
|
|
1951
|
-
}
|
|
1952
|
-
globalEnvProxy = null;
|
|
1953
|
-
globalTransportDecode = null;
|
|
1954
|
-
globalRemoteBindings = null;
|
|
1955
|
-
globalMiniflareBindings = null;
|
|
1956
|
-
resetQueueState();
|
|
1957
|
-
resetScheduledState();
|
|
1958
|
-
resetWorkerState();
|
|
1959
|
-
resetTailState();
|
|
1960
|
-
resetEmailState();
|
|
1961
|
-
__clearTestContext();
|
|
1962
|
-
};
|
|
1963
|
-
const getTestEnv = () => {
|
|
1964
|
-
return new Proxy({}, {
|
|
1965
|
-
get(_, prop) {
|
|
1966
|
-
if (globalRemoteBindings && prop in globalRemoteBindings) {
|
|
1967
|
-
return globalRemoteBindings[prop];
|
|
1968
|
-
}
|
|
1969
|
-
if (hints[prop] === "sendEmail" && globalEnvProxy && prop in globalEnvProxy) {
|
|
1970
|
-
return globalEnvProxy[prop];
|
|
1971
|
-
}
|
|
1972
|
-
if (globalMiniflareBindings && prop in globalMiniflareBindings) {
|
|
1973
|
-
return globalMiniflareBindings[prop];
|
|
1974
|
-
}
|
|
1975
|
-
if (globalEnvProxy && prop in globalEnvProxy) {
|
|
1976
|
-
return globalEnvProxy[prop];
|
|
1977
|
-
}
|
|
1978
|
-
return;
|
|
1979
|
-
},
|
|
1980
|
-
has(_, prop) {
|
|
1981
|
-
return Boolean(globalRemoteBindings && prop in globalRemoteBindings || globalMiniflareBindings && prop in globalMiniflareBindings || globalEnvProxy && prop in globalEnvProxy);
|
|
1982
|
-
}
|
|
1983
|
-
});
|
|
1984
|
-
};
|
|
1985
|
-
const queuePath = config.files?.queue;
|
|
1986
|
-
const scheduledPath = config.files?.scheduled;
|
|
1987
|
-
const fetchPath = config.files?.fetch;
|
|
1988
|
-
const emailPath = config.files?.email;
|
|
1989
|
-
const DEFAULT_FETCH_PATH = "src/fetch.ts";
|
|
1990
|
-
const DEFAULT_QUEUE_PATH = "src/queue.ts";
|
|
1991
|
-
const DEFAULT_SCHEDULED_PATH = "src/scheduled.ts";
|
|
1992
|
-
const DEFAULT_EMAIL_PATH = "src/email.ts";
|
|
1993
|
-
const DEFAULT_TAIL_PATH = "src/tail.ts";
|
|
1994
|
-
const resolvePath = async (configValue, defaultPath) => {
|
|
1995
|
-
if (typeof configValue === "string") {
|
|
1996
|
-
return configValue;
|
|
1997
|
-
}
|
|
1998
|
-
if (configValue === false) {
|
|
1999
|
-
return null;
|
|
2000
|
-
}
|
|
2001
|
-
const defaultAbsolute = join9(configDir6, defaultPath);
|
|
2002
|
-
try {
|
|
2003
|
-
const fs = await import("fs/promises");
|
|
2004
|
-
await fs.access(defaultAbsolute);
|
|
2005
|
-
return defaultPath;
|
|
2006
|
-
} catch {
|
|
2007
|
-
return null;
|
|
2008
|
-
}
|
|
2009
|
-
};
|
|
2010
|
-
const [resolvedFetchPath, resolvedQueuePath, resolvedScheduledPath, resolvedEmailPath, resolvedTailPath, resolvedRoutes] = await Promise.all([
|
|
2011
|
-
resolvePath(fetchPath, DEFAULT_FETCH_PATH),
|
|
2012
|
-
resolvePath(queuePath, DEFAULT_QUEUE_PATH),
|
|
2013
|
-
resolvePath(scheduledPath, DEFAULT_SCHEDULED_PATH),
|
|
2014
|
-
resolvePath(emailPath, DEFAULT_EMAIL_PATH),
|
|
2015
|
-
resolvePath(undefined, DEFAULT_TAIL_PATH),
|
|
2016
|
-
discoverRoutes(configDir6, config)
|
|
2017
|
-
]);
|
|
2018
|
-
configureQueue({
|
|
2019
|
-
handlerPath: resolvedQueuePath,
|
|
2020
|
-
configDir: configDir6,
|
|
2021
|
-
getEnv: getTestEnv
|
|
2022
|
-
});
|
|
2023
|
-
configureScheduled({
|
|
2024
|
-
handlerPath: resolvedScheduledPath,
|
|
2025
|
-
configDir: configDir6,
|
|
2026
|
-
getEnv: getTestEnv
|
|
2027
|
-
});
|
|
2028
|
-
configureWorker({
|
|
2029
|
-
handlerPath: resolvedFetchPath,
|
|
2030
|
-
routes: resolvedRoutes?.routes.map((route) => ({
|
|
2031
|
-
filePath: route.filePath,
|
|
2032
|
-
routePath: route.routePath,
|
|
2033
|
-
segments: route.segments
|
|
2034
|
-
})) ?? [],
|
|
2035
|
-
configDir: configDir6,
|
|
2036
|
-
getEnv: getTestEnv
|
|
2037
|
-
});
|
|
2038
|
-
configureTail({
|
|
2039
|
-
handlerPath: resolvedTailPath,
|
|
2040
|
-
configDir: configDir6,
|
|
2041
|
-
getEnv: getTestEnv
|
|
2042
|
-
});
|
|
2043
|
-
configureEmail({
|
|
2044
|
-
port: activePort,
|
|
2045
|
-
handlerPath: resolvedEmailPath,
|
|
2046
|
-
configDir: configDir6,
|
|
2047
|
-
getEnv: getTestEnv
|
|
2048
|
-
});
|
|
2049
|
-
if (hasMultiWorkerServices || hasMultiWorkerDOs) {
|
|
2050
|
-
setBindingHints(hints);
|
|
2051
|
-
const envAccessor2 = new Proxy({}, {
|
|
2052
|
-
get(_, prop) {
|
|
2053
|
-
if (globalRemoteBindings && prop in globalRemoteBindings) {
|
|
2054
|
-
return globalRemoteBindings[prop];
|
|
2055
|
-
}
|
|
2056
|
-
if (globalMiniflareBindings && prop in globalMiniflareBindings) {
|
|
2057
|
-
return globalMiniflareBindings[prop];
|
|
2058
|
-
}
|
|
2059
|
-
return;
|
|
2060
|
-
},
|
|
2061
|
-
has(_, prop) {
|
|
2062
|
-
return Boolean(globalRemoteBindings && prop in globalRemoteBindings || globalMiniflareBindings && prop in globalMiniflareBindings);
|
|
2063
|
-
}
|
|
2064
|
-
});
|
|
2065
|
-
__setTestContext(envAccessor2, disposeContext);
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
const bridgeClient = globalClient;
|
|
2069
|
-
if (!bridgeClient) {
|
|
2070
|
-
throw new Error("Bridge-backed test context did not initialize a client.");
|
|
2071
|
-
}
|
|
2072
|
-
setBindingHints(hints);
|
|
2073
|
-
globalEnvProxy = createEnvProxy({
|
|
2074
|
-
client: bridgeClient,
|
|
2075
|
-
transformResult: (result) => decodeTransport(result)
|
|
2076
|
-
});
|
|
2077
|
-
const envAccessor = new Proxy({}, {
|
|
2078
|
-
get(_, prop) {
|
|
2079
|
-
const hint = hints[prop];
|
|
2080
|
-
const prefersBridgeBinding = shouldPreferBridgeBinding(hint);
|
|
2081
|
-
if (globalRemoteBindings && prop in globalRemoteBindings) {
|
|
2082
|
-
return globalRemoteBindings[prop];
|
|
2083
|
-
}
|
|
2084
|
-
if (!prefersBridgeBinding && globalMiniflareBindings && prop in globalMiniflareBindings) {
|
|
2085
|
-
return globalMiniflareBindings[prop];
|
|
2086
|
-
}
|
|
2087
|
-
if (globalEnvProxy) {
|
|
2088
|
-
return globalEnvProxy[prop];
|
|
2089
|
-
}
|
|
2090
|
-
if (prefersBridgeBinding && globalMiniflareBindings && prop in globalMiniflareBindings) {
|
|
2091
|
-
return globalMiniflareBindings[prop];
|
|
2092
|
-
}
|
|
2093
|
-
return;
|
|
2094
|
-
},
|
|
2095
|
-
has(_, prop) {
|
|
2096
|
-
return Boolean(globalRemoteBindings && prop in globalRemoteBindings || globalMiniflareBindings && prop in globalMiniflareBindings || globalEnvProxy !== null);
|
|
2097
|
-
}
|
|
2098
|
-
});
|
|
2099
|
-
__setTestContext(envAccessor, disposeContext);
|
|
2100
|
-
}
|
|
2101
|
-
function decodeTransport(value) {
|
|
2102
|
-
if (!globalTransportDecode || value === null || typeof value !== "object") {
|
|
2103
|
-
return value;
|
|
2104
|
-
}
|
|
2105
|
-
if ("__transport" in value) {
|
|
2106
|
-
const encoded = value;
|
|
2107
|
-
const decoder = globalTransportDecode.get(encoded.__transport);
|
|
2108
|
-
if (decoder) {
|
|
2109
|
-
return decoder(encoded.value);
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
if (Array.isArray(value)) {
|
|
2113
|
-
return value.map(decodeTransport);
|
|
2114
|
-
}
|
|
2115
|
-
const result = {};
|
|
2116
|
-
for (const [k, v] of Object.entries(value)) {
|
|
2117
|
-
result[k] = decodeTransport(v);
|
|
2118
|
-
}
|
|
2119
|
-
return result;
|
|
2120
|
-
}
|
|
2121
|
-
// src/test/cf.ts
|
|
2122
|
-
var cf = {
|
|
2123
|
-
email,
|
|
2124
|
-
queue,
|
|
2125
|
-
scheduled,
|
|
2126
|
-
worker,
|
|
2127
|
-
tail
|
|
2128
|
-
};
|
|
2129
|
-
// src/test/should-skip.ts
|
|
2130
|
-
var REMOTE_ONLY_SERVICES = new Set([
|
|
2131
|
-
"ai",
|
|
2132
|
-
"vectorize"
|
|
2133
|
-
]);
|
|
2134
|
-
var skipResults = new Map;
|
|
2135
|
-
var EXPECTED_ERROR_PATTERNS = [
|
|
2136
|
-
"ECONNREFUSED",
|
|
2137
|
-
"ETIMEDOUT",
|
|
2138
|
-
"ENOTFOUND",
|
|
2139
|
-
"fetch failed",
|
|
2140
|
-
"network",
|
|
2141
|
-
"401",
|
|
2142
|
-
"403",
|
|
2143
|
-
"429",
|
|
2144
|
-
"500",
|
|
2145
|
-
"502",
|
|
2146
|
-
"503",
|
|
2147
|
-
"504",
|
|
2148
|
-
"rate limit",
|
|
2149
|
-
"unauthorized",
|
|
2150
|
-
"forbidden",
|
|
2151
|
-
"timeout"
|
|
2152
|
-
];
|
|
2153
|
-
function isExpectedError(error) {
|
|
2154
|
-
if (!(error instanceof Error))
|
|
2155
|
-
return false;
|
|
2156
|
-
const msg = error.message.toLowerCase();
|
|
2157
|
-
return EXPECTED_ERROR_PATTERNS.some((pattern) => msg.includes(pattern.toLowerCase()));
|
|
2158
|
-
}
|
|
2159
|
-
async function computeSkip(service) {
|
|
2160
|
-
try {
|
|
2161
|
-
if (REMOTE_ONLY_SERVICES.has(service) && !isRemoteModeActive()) {
|
|
2162
|
-
const status = getRemoteModeStatus();
|
|
2163
|
-
console.log(`⏭️ ${service.toUpperCase()} tests skipped: Remote-only service.
|
|
2164
|
-
` + ` Enable with: ${status.isEnabled ? "" : "devflare remote enable"}
|
|
2165
|
-
` + ` Or set: DEVFLARE_REMOTE=1
|
|
2166
|
-
` + ` See: https://github.com/ArthurvdVenne/devflare#remote-testing`);
|
|
2167
|
-
return true;
|
|
2168
|
-
}
|
|
2169
|
-
const isAuth = await isAuthenticated();
|
|
2170
|
-
if (!isAuth) {
|
|
2171
|
-
console.log(`⏭️ ${service.toUpperCase()} tests skipped: Not authenticated. Run: bunx wrangler login
|
|
2172
|
-
` + ` See: https://github.com/ArthurvdVenne/devflare#authentication`);
|
|
2173
|
-
return true;
|
|
2174
|
-
}
|
|
2175
|
-
const primary = await getPrimaryAccount();
|
|
2176
|
-
if (!primary) {
|
|
2177
|
-
console.log(`⏭️ ${service.toUpperCase()} tests skipped: No Cloudflare account found
|
|
2178
|
-
` + ` See: https://github.com/ArthurvdVenne/devflare#authentication`);
|
|
2179
|
-
return true;
|
|
2180
|
-
}
|
|
2181
|
-
const { accountId } = await getEffectiveAccountId(primary.id);
|
|
2182
|
-
try {
|
|
2183
|
-
const { allowed, reason } = await canProceedWithTest(accountId, service);
|
|
2184
|
-
if (!allowed) {
|
|
2185
|
-
console.log(`⏭️ ${service.toUpperCase()} tests skipped: ${reason}`);
|
|
2186
|
-
return true;
|
|
2187
|
-
}
|
|
2188
|
-
} catch {}
|
|
2189
|
-
return false;
|
|
2190
|
-
} catch (error) {
|
|
2191
|
-
if (isExpectedError(error)) {
|
|
2192
|
-
const message = error instanceof Error ? error.message : "Unknown error";
|
|
2193
|
-
console.log(`⏭️ ${service.toUpperCase()} tests skipped: ${message}`);
|
|
2194
|
-
return true;
|
|
2195
|
-
}
|
|
2196
|
-
throw error;
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
function getSkipResult(service) {
|
|
2200
|
-
let result = skipResults.get(service);
|
|
2201
|
-
if (!result) {
|
|
2202
|
-
result = computeSkip(service);
|
|
2203
|
-
skipResults.set(service, result);
|
|
2204
|
-
}
|
|
2205
|
-
return result;
|
|
2206
|
-
}
|
|
2207
|
-
var shouldSkip = {
|
|
2208
|
-
get ai() {
|
|
2209
|
-
return getSkipResult("ai");
|
|
2210
|
-
},
|
|
2211
|
-
get vectorize() {
|
|
2212
|
-
return getSkipResult("vectorize");
|
|
2213
|
-
},
|
|
2214
|
-
get workers() {
|
|
2215
|
-
return getSkipResult("workers");
|
|
2216
|
-
},
|
|
2217
|
-
get kv() {
|
|
2218
|
-
return getSkipResult("kv");
|
|
2219
|
-
},
|
|
2220
|
-
get d1() {
|
|
2221
|
-
return getSkipResult("d1");
|
|
2222
|
-
},
|
|
2223
|
-
get r2() {
|
|
2224
|
-
return getSkipResult("r2");
|
|
2225
|
-
},
|
|
2226
|
-
get queues() {
|
|
2227
|
-
return getSkipResult("queues");
|
|
2228
|
-
},
|
|
2229
|
-
get durableObjects() {
|
|
2230
|
-
return getSkipResult("durable_objects");
|
|
2231
|
-
}
|
|
2232
|
-
};
|
|
2233
|
-
// src/test/utilities.ts
|
|
2234
|
-
function createMockTestContext(options = {}) {
|
|
2235
|
-
const waitUntilPromises = [];
|
|
2236
|
-
const ctx = {
|
|
2237
|
-
waitUntil(promise) {
|
|
2238
|
-
waitUntilPromises.push(promise);
|
|
2239
|
-
},
|
|
2240
|
-
passThroughOnException() {},
|
|
2241
|
-
props: {}
|
|
2242
|
-
};
|
|
2243
|
-
return {
|
|
2244
|
-
env: options.env ?? {},
|
|
2245
|
-
ctx,
|
|
2246
|
-
request: options.request ?? null,
|
|
2247
|
-
waitUntilPromises
|
|
2248
|
-
};
|
|
2249
|
-
}
|
|
2250
|
-
async function withTestContext(options, handler) {
|
|
2251
|
-
const testCtx = createMockTestContext(options);
|
|
2252
|
-
return runWithContext(testCtx.env, testCtx.ctx, options.request ?? null, handler, options.type ?? "fetch");
|
|
2253
|
-
}
|
|
2254
|
-
function createMockKV(initialData = {}) {
|
|
2255
|
-
const store = new Map(Object.entries(initialData));
|
|
2256
|
-
const metadata = new Map;
|
|
2257
|
-
return {
|
|
2258
|
-
async get(key, options) {
|
|
2259
|
-
const value = store.get(key);
|
|
2260
|
-
if (value === null || value === undefined)
|
|
2261
|
-
return null;
|
|
2262
|
-
const type = typeof options === "string" ? options : options?.type ?? "text";
|
|
2263
|
-
switch (type) {
|
|
2264
|
-
case "json":
|
|
2265
|
-
return JSON.parse(value);
|
|
2266
|
-
case "arrayBuffer":
|
|
2267
|
-
return new TextEncoder().encode(value).buffer;
|
|
2268
|
-
case "stream":
|
|
2269
|
-
return new ReadableStream({
|
|
2270
|
-
start(controller) {
|
|
2271
|
-
controller.enqueue(new TextEncoder().encode(value));
|
|
2272
|
-
controller.close();
|
|
2273
|
-
}
|
|
2274
|
-
});
|
|
2275
|
-
default:
|
|
2276
|
-
return value;
|
|
2277
|
-
}
|
|
2278
|
-
},
|
|
2279
|
-
async put(key, value, options) {
|
|
2280
|
-
if (typeof value === "string") {
|
|
2281
|
-
store.set(key, value);
|
|
2282
|
-
} else if (value instanceof ArrayBuffer) {
|
|
2283
|
-
store.set(key, new TextDecoder().decode(value));
|
|
2284
|
-
} else {
|
|
2285
|
-
const reader = value.getReader();
|
|
2286
|
-
const chunks = [];
|
|
2287
|
-
let done = false;
|
|
2288
|
-
while (!done) {
|
|
2289
|
-
const result = await reader.read();
|
|
2290
|
-
done = result.done;
|
|
2291
|
-
if (result.value)
|
|
2292
|
-
chunks.push(result.value);
|
|
2293
|
-
}
|
|
2294
|
-
const combined = new Uint8Array(chunks.reduce((acc, c) => acc + c.length, 0));
|
|
2295
|
-
let offset = 0;
|
|
2296
|
-
for (const chunk of chunks) {
|
|
2297
|
-
combined.set(chunk, offset);
|
|
2298
|
-
offset += chunk.length;
|
|
2299
|
-
}
|
|
2300
|
-
store.set(key, new TextDecoder().decode(combined));
|
|
2301
|
-
}
|
|
2302
|
-
},
|
|
2303
|
-
async delete(key) {
|
|
2304
|
-
store.delete(key);
|
|
2305
|
-
},
|
|
2306
|
-
async list(options) {
|
|
2307
|
-
const prefix = options?.prefix ?? "";
|
|
2308
|
-
const limit = options?.limit ?? 1000;
|
|
2309
|
-
const keys = Array.from(store.keys()).filter((key) => key.startsWith(prefix)).slice(0, limit).map((name) => ({ name }));
|
|
2310
|
-
return {
|
|
2311
|
-
keys,
|
|
2312
|
-
list_complete: keys.length < limit,
|
|
2313
|
-
cursor: undefined
|
|
2314
|
-
};
|
|
2315
|
-
},
|
|
2316
|
-
async getWithMetadata(key, options) {
|
|
2317
|
-
return {
|
|
2318
|
-
value: store.get(key) ?? null,
|
|
2319
|
-
metadata: metadata.get(key) ?? null
|
|
2320
|
-
};
|
|
2321
|
-
}
|
|
2322
|
-
};
|
|
2323
|
-
}
|
|
2324
|
-
function createMockD1(mockResults = []) {
|
|
2325
|
-
let boundValues = [];
|
|
2326
|
-
let currentResults = [...mockResults];
|
|
2327
|
-
const createStatement = () => ({
|
|
2328
|
-
bind(...values) {
|
|
2329
|
-
boundValues = values;
|
|
2330
|
-
return this;
|
|
2331
|
-
},
|
|
2332
|
-
async first(column) {
|
|
2333
|
-
const row = currentResults[0];
|
|
2334
|
-
if (!row)
|
|
2335
|
-
return null;
|
|
2336
|
-
if (column)
|
|
2337
|
-
return row[column];
|
|
2338
|
-
return row;
|
|
2339
|
-
},
|
|
2340
|
-
async all() {
|
|
2341
|
-
return {
|
|
2342
|
-
results: currentResults,
|
|
2343
|
-
success: true,
|
|
2344
|
-
meta: { duration: 0, changes: 0, last_row_id: 0 }
|
|
2345
|
-
};
|
|
2346
|
-
},
|
|
2347
|
-
async run() {
|
|
2348
|
-
return {
|
|
2349
|
-
results: [],
|
|
2350
|
-
success: true,
|
|
2351
|
-
meta: { duration: 0, changes: 1, last_row_id: 1 }
|
|
2352
|
-
};
|
|
2353
|
-
},
|
|
2354
|
-
async raw(options) {
|
|
2355
|
-
return currentResults.map((row) => Object.values(row));
|
|
2356
|
-
}
|
|
2357
|
-
});
|
|
2358
|
-
return {
|
|
2359
|
-
prepare(query) {
|
|
2360
|
-
return createStatement();
|
|
2361
|
-
},
|
|
2362
|
-
async exec(query) {
|
|
2363
|
-
return {
|
|
2364
|
-
results: [],
|
|
2365
|
-
success: true,
|
|
2366
|
-
meta: { duration: 0, changes: 0, last_row_id: 0 }
|
|
2367
|
-
};
|
|
2368
|
-
},
|
|
2369
|
-
async batch(statements) {
|
|
2370
|
-
return statements.map(() => ({
|
|
2371
|
-
results: [],
|
|
2372
|
-
success: true,
|
|
2373
|
-
meta: { duration: 0, changes: 0, last_row_id: 0 }
|
|
2374
|
-
}));
|
|
2375
|
-
},
|
|
2376
|
-
async dump() {
|
|
2377
|
-
return new ArrayBuffer(0);
|
|
2378
|
-
},
|
|
2379
|
-
withSession(constraintOrBookmark) {
|
|
2380
|
-
return this;
|
|
2381
|
-
}
|
|
2382
|
-
};
|
|
2383
|
-
}
|
|
2384
|
-
function createMockR2() {
|
|
2385
|
-
const store = new Map;
|
|
2386
|
-
const createR2Object = (key, content, metadata) => {
|
|
2387
|
-
const encoder = new TextEncoder;
|
|
2388
|
-
const data = encoder.encode(content);
|
|
2389
|
-
return {
|
|
2390
|
-
key,
|
|
2391
|
-
version: "1",
|
|
2392
|
-
size: data.length,
|
|
2393
|
-
etag: `"${key}-etag"`,
|
|
2394
|
-
httpEtag: `"${key}-etag"`,
|
|
2395
|
-
uploaded: new Date,
|
|
2396
|
-
httpMetadata: metadata ?? {},
|
|
2397
|
-
customMetadata: {},
|
|
2398
|
-
checksums: {},
|
|
2399
|
-
storageClass: "Standard",
|
|
2400
|
-
body: new ReadableStream({
|
|
2401
|
-
start(controller) {
|
|
2402
|
-
controller.enqueue(data);
|
|
2403
|
-
controller.close();
|
|
2404
|
-
}
|
|
2405
|
-
}),
|
|
2406
|
-
bodyUsed: false,
|
|
2407
|
-
async arrayBuffer() {
|
|
2408
|
-
return new Uint8Array(data).buffer;
|
|
2409
|
-
},
|
|
2410
|
-
async text() {
|
|
2411
|
-
return content;
|
|
2412
|
-
},
|
|
2413
|
-
async json() {
|
|
2414
|
-
return JSON.parse(content);
|
|
2415
|
-
},
|
|
2416
|
-
async blob() {
|
|
2417
|
-
return new Blob([data]);
|
|
2418
|
-
},
|
|
2419
|
-
writeHttpMetadata(headers) {}
|
|
2420
|
-
};
|
|
2421
|
-
};
|
|
2422
|
-
return {
|
|
2423
|
-
async put(key, value, options) {
|
|
2424
|
-
let content;
|
|
2425
|
-
if (typeof value === "string") {
|
|
2426
|
-
content = value;
|
|
2427
|
-
} else if (value instanceof ArrayBuffer) {
|
|
2428
|
-
content = new TextDecoder().decode(value);
|
|
2429
|
-
} else if (value instanceof Blob) {
|
|
2430
|
-
content = await value.text();
|
|
2431
|
-
} else if (value === null) {
|
|
2432
|
-
content = "";
|
|
2433
|
-
} else {
|
|
2434
|
-
const reader = value.getReader();
|
|
2435
|
-
const chunks = [];
|
|
2436
|
-
let done = false;
|
|
2437
|
-
while (!done) {
|
|
2438
|
-
const result = await reader.read();
|
|
2439
|
-
done = result.done;
|
|
2440
|
-
if (result.value) {
|
|
2441
|
-
chunks.push(new TextDecoder().decode(result.value));
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
content = chunks.join("");
|
|
2445
|
-
}
|
|
2446
|
-
store.set(key, { content });
|
|
2447
|
-
return createR2Object(key, content);
|
|
2448
|
-
},
|
|
2449
|
-
async get(key, options) {
|
|
2450
|
-
const item = store.get(key);
|
|
2451
|
-
if (!item)
|
|
2452
|
-
return null;
|
|
2453
|
-
return createR2Object(key, item.content, item.metadata);
|
|
2454
|
-
},
|
|
2455
|
-
async head(key) {
|
|
2456
|
-
const item = store.get(key);
|
|
2457
|
-
if (!item)
|
|
2458
|
-
return null;
|
|
2459
|
-
return {
|
|
2460
|
-
key,
|
|
2461
|
-
version: "1",
|
|
2462
|
-
size: new TextEncoder().encode(item.content).length,
|
|
2463
|
-
etag: `"${key}-etag"`,
|
|
2464
|
-
httpEtag: `"${key}-etag"`,
|
|
2465
|
-
uploaded: new Date,
|
|
2466
|
-
httpMetadata: item.metadata ?? {},
|
|
2467
|
-
customMetadata: {},
|
|
2468
|
-
checksums: {},
|
|
2469
|
-
storageClass: "Standard",
|
|
2470
|
-
writeHttpMetadata(headers) {}
|
|
2471
|
-
};
|
|
2472
|
-
},
|
|
2473
|
-
async delete(keys) {
|
|
2474
|
-
const keyArray = Array.isArray(keys) ? keys : [keys];
|
|
2475
|
-
for (const key of keyArray) {
|
|
2476
|
-
store.delete(key);
|
|
2477
|
-
}
|
|
2478
|
-
},
|
|
2479
|
-
async list(options) {
|
|
2480
|
-
const objects = Array.from(store.entries()).map(([key, { content, metadata }]) => createR2Object(key, content, metadata));
|
|
2481
|
-
return {
|
|
2482
|
-
objects,
|
|
2483
|
-
truncated: false,
|
|
2484
|
-
delimitedPrefixes: []
|
|
2485
|
-
};
|
|
2486
|
-
},
|
|
2487
|
-
async createMultipartUpload(key, options) {
|
|
2488
|
-
throw new Error("Multipart upload not implemented in mock");
|
|
2489
|
-
},
|
|
2490
|
-
async resumeMultipartUpload(key, uploadId) {
|
|
2491
|
-
throw new Error("Multipart upload not implemented in mock");
|
|
2492
|
-
}
|
|
2493
|
-
};
|
|
2494
|
-
}
|
|
2495
|
-
function createMockQueue() {
|
|
2496
|
-
const messages = [];
|
|
2497
|
-
return {
|
|
2498
|
-
async send(message, options) {
|
|
2499
|
-
messages.push({ body: message, options });
|
|
2500
|
-
},
|
|
2501
|
-
async sendBatch(batch) {
|
|
2502
|
-
messages.push(...batch);
|
|
2503
|
-
},
|
|
2504
|
-
_getMessages() {
|
|
2505
|
-
return messages;
|
|
2506
|
-
}
|
|
2507
|
-
};
|
|
2508
|
-
}
|
|
2509
|
-
function createMockEnv(options = {}) {
|
|
2510
|
-
const env2 = {};
|
|
2511
|
-
if (options.kv) {
|
|
2512
|
-
for (const name of options.kv) {
|
|
2513
|
-
env2[name] = createMockKV();
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
if (options.d1) {
|
|
2517
|
-
for (const name of options.d1) {
|
|
2518
|
-
env2[name] = createMockD1();
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
if (options.r2) {
|
|
2522
|
-
for (const name of options.r2) {
|
|
2523
|
-
env2[name] = createMockR2();
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
if (options.queues) {
|
|
2527
|
-
for (const name of options.queues) {
|
|
2528
|
-
env2[name] = createMockQueue();
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
if (options.vars) {
|
|
2532
|
-
Object.assign(env2, options.vars);
|
|
2533
|
-
}
|
|
2534
|
-
if (options.secrets) {
|
|
2535
|
-
Object.assign(env2, options.secrets);
|
|
2536
|
-
}
|
|
2537
|
-
if (options.custom) {
|
|
2538
|
-
Object.assign(env2, options.custom);
|
|
2539
|
-
}
|
|
2540
|
-
return env2;
|
|
2541
|
-
}
|
|
2542
|
-
// src/test/bridge-context.ts
|
|
2543
|
-
var globalTestContext = null;
|
|
2544
|
-
async function createBridgeTestContext(options = {}) {
|
|
2545
|
-
if (globalTestContext) {
|
|
2546
|
-
await globalTestContext.stop();
|
|
2547
|
-
}
|
|
2548
|
-
let config = options.config;
|
|
2549
|
-
if (options.configPath && !config) {
|
|
2550
|
-
config = await loadConfig({ cwd: options.configPath.replace(/[/\\][^/\\]+$/, ""), configFile: options.configPath.split(/[/\\]/).pop() });
|
|
2551
|
-
}
|
|
2552
|
-
let miniflare;
|
|
2553
|
-
if (config) {
|
|
2554
|
-
miniflare = await startMiniflareFromConfig(config, {
|
|
2555
|
-
...options.miniflare,
|
|
2556
|
-
port: options.port ?? 8787,
|
|
2557
|
-
persist: options.persist ?? false,
|
|
2558
|
-
verbose: options.verbose ?? false
|
|
2559
|
-
});
|
|
2560
|
-
} else {
|
|
2561
|
-
miniflare = await startMiniflare({
|
|
2562
|
-
...options.miniflare,
|
|
2563
|
-
port: options.port ?? 8787,
|
|
2564
|
-
persist: options.persist ?? false,
|
|
2565
|
-
verbose: options.verbose ?? false
|
|
2566
|
-
});
|
|
2567
|
-
}
|
|
2568
|
-
const bindings = wrapEnvSendEmailBindings(await miniflare.getBindings());
|
|
2569
|
-
if (config?.bindings) {
|
|
2570
|
-
const hints = {};
|
|
2571
|
-
if (config.bindings.kv) {
|
|
2572
|
-
Object.keys(config.bindings.kv).forEach((name) => {
|
|
2573
|
-
hints[name] = "kv";
|
|
2574
|
-
});
|
|
2575
|
-
}
|
|
2576
|
-
if (config.bindings.r2) {
|
|
2577
|
-
Object.keys(config.bindings.r2).forEach((name) => {
|
|
2578
|
-
hints[name] = "r2";
|
|
2579
|
-
});
|
|
2580
|
-
}
|
|
2581
|
-
if (config.bindings.d1) {
|
|
2582
|
-
Object.keys(config.bindings.d1).forEach((name) => {
|
|
2583
|
-
hints[name] = "d1";
|
|
2584
|
-
});
|
|
2585
|
-
}
|
|
2586
|
-
if (config.bindings.durableObjects) {
|
|
2587
|
-
Object.keys(config.bindings.durableObjects).forEach((name) => {
|
|
2588
|
-
hints[name] = "do";
|
|
2589
|
-
});
|
|
2590
|
-
}
|
|
2591
|
-
if (config.bindings.queues?.consumers) {
|
|
2592
|
-
config.bindings.queues.consumers.forEach((c) => {
|
|
2593
|
-
hints[c.queue] = "queue";
|
|
2594
|
-
});
|
|
2595
|
-
}
|
|
2596
|
-
if (config.bindings.ai)
|
|
2597
|
-
hints[config.bindings.ai.binding] = "ai";
|
|
2598
|
-
if (config.bindings.sendEmail) {
|
|
2599
|
-
Object.keys(config.bindings.sendEmail).forEach((name) => {
|
|
2600
|
-
hints[name] = "sendEmail";
|
|
2601
|
-
});
|
|
2602
|
-
}
|
|
2603
|
-
setBindingHints(hints);
|
|
2604
|
-
}
|
|
2605
|
-
const ctx = {
|
|
2606
|
-
env: bindings,
|
|
2607
|
-
miniflare,
|
|
2608
|
-
async stop() {
|
|
2609
|
-
await miniflare.dispose();
|
|
2610
|
-
globalTestContext = null;
|
|
2611
|
-
},
|
|
2612
|
-
async reset() {
|
|
2613
|
-
for (const [name, binding] of Object.entries(bindings)) {
|
|
2614
|
-
if (isKVNamespace(binding)) {
|
|
2615
|
-
const kv = binding;
|
|
2616
|
-
const { keys } = await kv.list();
|
|
2617
|
-
for (const key of keys) {
|
|
2618
|
-
await kv.delete(key.name);
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
};
|
|
2624
|
-
globalTestContext = ctx;
|
|
2625
|
-
return ctx;
|
|
2626
|
-
}
|
|
2627
|
-
async function stopBridgeTestContext() {
|
|
2628
|
-
if (globalTestContext) {
|
|
2629
|
-
await globalTestContext.stop();
|
|
2630
|
-
}
|
|
2631
|
-
}
|
|
2632
|
-
function getBridgeTestContext() {
|
|
2633
|
-
if (!globalTestContext) {
|
|
2634
|
-
throw new Error("Bridge test context not initialized. Call createBridgeTestContext() in beforeAll().");
|
|
2635
|
-
}
|
|
2636
|
-
return globalTestContext;
|
|
2637
|
-
}
|
|
2638
|
-
var testEnv = new Proxy({}, {
|
|
2639
|
-
get(target, prop) {
|
|
2640
|
-
if (typeof prop !== "string")
|
|
2641
|
-
return;
|
|
2642
|
-
const ctx = getBridgeTestContext();
|
|
2643
|
-
return ctx.env[prop];
|
|
2644
|
-
}
|
|
2645
|
-
});
|
|
2646
|
-
function isKVNamespace(binding) {
|
|
2647
|
-
return typeof binding === "object" && binding !== null && "get" in binding && "put" in binding && "delete" in binding && "list" in binding;
|
|
2648
|
-
}
|
|
2649
|
-
export { clearBundleCache, hasServiceBindings, resolveServiceBindings, hasCrossWorkerDOs, resolveDOBindings, email, queue, scheduled, tail, worker, createTestContext, cf, shouldSkip, createMockTestContext, withTestContext, createMockKV, createMockD1, createMockR2, createMockQueue, createMockEnv, createBridgeTestContext, stopBridgeTestContext, getBridgeTestContext, testEnv };
|