@nimbus-sh/worker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +219 -0
- package/dist/_shared/bytes.d.ts +18 -0
- package/dist/_shared/bytes.d.ts.map +1 -0
- package/dist/_shared/bytes.js +17 -0
- package/dist/_shared/cache-stats.d.ts +146 -0
- package/dist/_shared/cache-stats.d.ts.map +1 -0
- package/dist/_shared/cache-stats.js +162 -0
- package/dist/_shared/exports-resolver.d.ts +76 -0
- package/dist/_shared/exports-resolver.d.ts.map +1 -0
- package/dist/_shared/exports-resolver.js +284 -0
- package/dist/_shared/install-phase.d.ts +47 -0
- package/dist/_shared/install-phase.d.ts.map +1 -0
- package/dist/_shared/install-phase.js +1 -0
- package/dist/_shared/real-node-imports.d.ts +38 -0
- package/dist/_shared/real-node-imports.d.ts.map +1 -0
- package/dist/_shared/real-node-imports.js +46 -0
- package/dist/_shared/retry.d.ts +93 -0
- package/dist/_shared/retry.d.ts.map +1 -0
- package/dist/_shared/retry.js +161 -0
- package/dist/_shared/session-id.d.ts +39 -0
- package/dist/_shared/session-id.d.ts.map +1 -0
- package/dist/_shared/session-id.js +127 -0
- package/dist/_shared/session-router.d.ts +104 -0
- package/dist/_shared/session-router.d.ts.map +1 -0
- package/dist/_shared/session-router.js +165 -0
- package/dist/_shared/w7-frame.d.ts +93 -0
- package/dist/_shared/w7-frame.d.ts.map +1 -0
- package/dist/_shared/w7-frame.js +402 -0
- package/dist/auth/index.d.ts +16 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +15 -0
- package/dist/auth/middleware.d.ts +85 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +150 -0
- package/dist/auth/token.d.ts +96 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +226 -0
- package/dist/auth/types.d.ts +141 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +114 -0
- package/dist/bindings/d1.d.ts +102 -0
- package/dist/bindings/d1.d.ts.map +1 -0
- package/dist/bindings/d1.js +549 -0
- package/dist/bindings/kv.d.ts +82 -0
- package/dist/bindings/kv.d.ts.map +1 -0
- package/dist/bindings/kv.js +290 -0
- package/dist/bindings/r2.d.ts +137 -0
- package/dist/bindings/r2.d.ts.map +1 -0
- package/dist/bindings/r2.js +379 -0
- package/dist/cirrus-npm-cjs.generated.d.ts +17 -0
- package/dist/cirrus-npm-cjs.generated.d.ts.map +1 -0
- package/dist/cirrus-npm-cjs.generated.js +41 -0
- package/dist/cirrus-plugin-react.generated.d.ts +34 -0
- package/dist/cirrus-plugin-react.generated.d.ts.map +1 -0
- package/dist/cirrus-plugin-react.generated.js +33 -0
- package/dist/constants.d.ts +34 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +116 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts +41 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -0
- package/dist/esbuild-wasm-bundle.generated.js +40 -0
- package/dist/facets/cirrus-real.d.ts +147 -0
- package/dist/facets/cirrus-real.d.ts.map +1 -0
- package/dist/facets/cirrus-real.js +981 -0
- package/dist/facets/inner-do-registry.d.ts +41 -0
- package/dist/facets/inner-do-registry.d.ts.map +1 -0
- package/dist/facets/inner-do-registry.js +51 -0
- package/dist/facets/manager.d.ts +314 -0
- package/dist/facets/manager.d.ts.map +1 -0
- package/dist/facets/manager.js +2681 -0
- package/dist/facets/process.d.ts +318 -0
- package/dist/facets/process.d.ts.map +1 -0
- package/dist/facets/process.js +567 -0
- package/dist/facets/real-vite-fs-shim.d.ts +151 -0
- package/dist/facets/real-vite-fs-shim.d.ts.map +1 -0
- package/dist/facets/real-vite-fs-shim.js +1279 -0
- package/dist/facets/real-vite-hmr.d.ts +142 -0
- package/dist/facets/real-vite-hmr.d.ts.map +1 -0
- package/dist/facets/real-vite-hmr.js +476 -0
- package/dist/facets/vite-dev-server.d.ts +293 -0
- package/dist/facets/vite-dev-server.d.ts.map +1 -0
- package/dist/facets/vite-dev-server.js +2580 -0
- package/dist/facets/wasm-swap-registry.d.ts +261 -0
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -0
- package/dist/facets/wasm-swap-registry.js +551 -0
- package/dist/facets/ws-terminal.d.ts +107 -0
- package/dist/facets/ws-terminal.d.ts.map +1 -0
- package/dist/facets/ws-terminal.js +207 -0
- package/dist/git/commands.d.ts +13 -0
- package/dist/git/commands.d.ts.map +1 -0
- package/dist/git/commands.js +633 -0
- package/dist/git/network-facet.d.ts +61 -0
- package/dist/git/network-facet.d.ts.map +1 -0
- package/dist/git/network-facet.js +700 -0
- package/dist/git-bundle.generated.d.ts +16 -0
- package/dist/git-bundle.generated.d.ts.map +1 -0
- package/dist/git-bundle.generated.js +15 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/loaders/child-process/spawn-facet.d.ts +90 -0
- package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -0
- package/dist/loaders/child-process/spawn-facet.js +103 -0
- package/dist/loaders/child-process/spawn-pool.d.ts +110 -0
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -0
- package/dist/loaders/child-process/spawn-pool.js +161 -0
- package/dist/loaders/fanout-pool.d.ts +195 -0
- package/dist/loaders/fanout-pool.d.ts.map +1 -0
- package/dist/loaders/fanout-pool.js +326 -0
- package/dist/loaders/generated-workers.d.ts +26 -0
- package/dist/loaders/generated-workers.d.ts.map +1 -0
- package/dist/loaders/generated-workers.js +25 -0
- package/dist/loaders/index.d.ts +15 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +13 -0
- package/dist/loaders/loader-pool.d.ts +273 -0
- package/dist/loaders/loader-pool.d.ts.map +1 -0
- package/dist/loaders/loader-pool.js +624 -0
- package/dist/loaders/npm-resolve-preamble.d.ts +34 -0
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -0
- package/dist/loaders/npm-resolve-preamble.js +237 -0
- package/dist/loaders/pre-bundle-preamble.d.ts +41 -0
- package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -0
- package/dist/loaders/pre-bundle-preamble.js +114 -0
- package/dist/loaders/vendor/codegen.d.ts +24 -0
- package/dist/loaders/vendor/codegen.d.ts.map +1 -0
- package/dist/loaders/vendor/codegen.js +44 -0
- package/dist/loaders/vendor/errors.d.ts +24 -0
- package/dist/loaders/vendor/errors.d.ts.map +1 -0
- package/dist/loaders/vendor/errors.js +46 -0
- package/dist/loaders/vendor/index.d.ts +16 -0
- package/dist/loaders/vendor/index.d.ts.map +1 -0
- package/dist/loaders/vendor/index.js +11 -0
- package/dist/loaders/vendor/pool.d.ts +88 -0
- package/dist/loaders/vendor/pool.d.ts.map +1 -0
- package/dist/loaders/vendor/pool.js +353 -0
- package/dist/loaders/vendor/primitives.d.ts +11 -0
- package/dist/loaders/vendor/primitives.d.ts.map +1 -0
- package/dist/loaders/vendor/primitives.js +33 -0
- package/dist/loaders/vendor/serialize.d.ts +3 -0
- package/dist/loaders/vendor/serialize.d.ts.map +1 -0
- package/dist/loaders/vendor/serialize.js +25 -0
- package/dist/loaders/vendor/types.d.ts +60 -0
- package/dist/loaders/vendor/types.d.ts.map +1 -0
- package/dist/loaders/vendor/types.js +4 -0
- package/dist/npm/cache.d.ts +136 -0
- package/dist/npm/cache.d.ts.map +1 -0
- package/dist/npm/cache.js +429 -0
- package/dist/npm/install-batch-facet.d.ts +129 -0
- package/dist/npm/install-batch-facet.d.ts.map +1 -0
- package/dist/npm/install-batch-facet.js +598 -0
- package/dist/npm/install-facet.d.ts +29 -0
- package/dist/npm/install-facet.d.ts.map +1 -0
- package/dist/npm/install-facet.js +9 -0
- package/dist/npm/installer.d.ts +239 -0
- package/dist/npm/installer.d.ts.map +1 -0
- package/dist/npm/installer.js +2022 -0
- package/dist/npm/npx-install.d.ts +74 -0
- package/dist/npm/npx-install.d.ts.map +1 -0
- package/dist/npm/npx-install.js +302 -0
- package/dist/npm/pre-bundle-facet.d.ts +168 -0
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -0
- package/dist/npm/pre-bundle-facet.js +653 -0
- package/dist/npm/r2-cache.d.ts +286 -0
- package/dist/npm/r2-cache.d.ts.map +1 -0
- package/dist/npm/r2-cache.js +506 -0
- package/dist/npm/resolve-facet.d.ts +202 -0
- package/dist/npm/resolve-facet.d.ts.map +1 -0
- package/dist/npm/resolve-facet.js +833 -0
- package/dist/npm/resolve-one-facet.d.ts +204 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -0
- package/dist/npm/resolve-one-facet.js +437 -0
- package/dist/npm/resolver.d.ts +109 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/resolver.js +899 -0
- package/dist/npm/tarball-stream.d.ts +85 -0
- package/dist/npm/tarball-stream.d.ts.map +1 -0
- package/dist/npm/tarball-stream.js +205 -0
- package/dist/npm/tarball.d.ts +51 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/npm/tarball.js +185 -0
- package/dist/observability/diag-counters.d.ts +292 -0
- package/dist/observability/diag-counters.d.ts.map +1 -0
- package/dist/observability/diag-counters.js +302 -0
- package/dist/observability/heap-estimate.d.ts +166 -0
- package/dist/observability/heap-estimate.d.ts.map +1 -0
- package/dist/observability/heap-estimate.js +192 -0
- package/dist/observability/heavy-alloc-coord.d.ts +95 -0
- package/dist/observability/heavy-alloc-coord.d.ts.map +1 -0
- package/dist/observability/heavy-alloc-coord.js +149 -0
- package/dist/observability/oom-classify.d.ts +56 -0
- package/dist/observability/oom-classify.d.ts.map +1 -0
- package/dist/observability/oom-classify.js +118 -0
- package/dist/observability/oom-discriminator.d.ts +192 -0
- package/dist/observability/oom-discriminator.d.ts.map +1 -0
- package/dist/observability/oom-discriminator.js +233 -0
- package/dist/real-vite-bundle.generated.d.ts +46 -0
- package/dist/real-vite-bundle.generated.d.ts.map +1 -0
- package/dist/real-vite-bundle.generated.js +53 -0
- package/dist/replica/routing.d.ts +171 -0
- package/dist/replica/routing.d.ts.map +1 -0
- package/dist/replica/routing.js +288 -0
- package/dist/replica/suspension.d.ts +36 -0
- package/dist/replica/suspension.d.ts.map +1 -0
- package/dist/replica/suspension.js +49 -0
- package/dist/router/index.d.ts +156 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +220 -0
- package/dist/runtime/assets-loader.d.ts +71 -0
- package/dist/runtime/assets-loader.d.ts.map +1 -0
- package/dist/runtime/assets-loader.js +128 -0
- package/dist/runtime/barrel-detect.d.ts +46 -0
- package/dist/runtime/barrel-detect.d.ts.map +1 -0
- package/dist/runtime/barrel-detect.js +73 -0
- package/dist/runtime/barrel-synthesizer.d.ts +181 -0
- package/dist/runtime/barrel-synthesizer.d.ts.map +1 -0
- package/dist/runtime/barrel-synthesizer.js +541 -0
- package/dist/runtime/bun-repl.d.ts +46 -0
- package/dist/runtime/bun-repl.d.ts.map +1 -0
- package/dist/runtime/bun-repl.js +326 -0
- package/dist/runtime/bun-runner.d.ts +66 -0
- package/dist/runtime/bun-runner.d.ts.map +1 -0
- package/dist/runtime/bun-runner.js +219 -0
- package/dist/runtime/clang-runner.d.ts +38 -0
- package/dist/runtime/clang-runner.d.ts.map +1 -0
- package/dist/runtime/clang-runner.js +1033 -0
- package/dist/runtime/comment-strip.d.ts +37 -0
- package/dist/runtime/comment-strip.d.ts.map +1 -0
- package/dist/runtime/comment-strip.js +74 -0
- package/dist/runtime/esbuild-service.d.ts +201 -0
- package/dist/runtime/esbuild-service.d.ts.map +1 -0
- package/dist/runtime/esbuild-service.js +1444 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts +87 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -0
- package/dist/runtime/esbuild-wasm-bytes.js +131 -0
- package/dist/runtime/framework-detect.d.ts +71 -0
- package/dist/runtime/framework-detect.d.ts.map +1 -0
- package/dist/runtime/framework-detect.js +178 -0
- package/dist/runtime/long-running-handle.d.ts +133 -0
- package/dist/runtime/long-running-handle.d.ts.map +1 -0
- package/dist/runtime/long-running-handle.js +192 -0
- package/dist/runtime/node-repl.d.ts +36 -0
- package/dist/runtime/node-repl.d.ts.map +1 -0
- package/dist/runtime/node-repl.js +293 -0
- package/dist/runtime/node-runner.d.ts +111 -0
- package/dist/runtime/node-runner.d.ts.map +1 -0
- package/dist/runtime/node-runner.js +194 -0
- package/dist/runtime/node-shims.d.ts +24 -0
- package/dist/runtime/node-shims.d.ts.map +1 -0
- package/dist/runtime/node-shims.js +3019 -0
- package/dist/runtime/package-manager.d.ts +118 -0
- package/dist/runtime/package-manager.d.ts.map +1 -0
- package/dist/runtime/package-manager.js +420 -0
- package/dist/runtime/port-registry.d.ts +80 -0
- package/dist/runtime/port-registry.d.ts.map +1 -0
- package/dist/runtime/port-registry.js +166 -0
- package/dist/runtime/process-logs-api.d.ts +102 -0
- package/dist/runtime/process-logs-api.d.ts.map +1 -0
- package/dist/runtime/process-logs-api.js +253 -0
- package/dist/runtime/process-logs.d.ts +311 -0
- package/dist/runtime/process-logs.d.ts.map +1 -0
- package/dist/runtime/process-logs.js +656 -0
- package/dist/runtime/process-table.d.ts +65 -0
- package/dist/runtime/process-table.d.ts.map +1 -0
- package/dist/runtime/process-table.js +107 -0
- package/dist/runtime/project-detect.d.ts +21 -0
- package/dist/runtime/project-detect.d.ts.map +1 -0
- package/dist/runtime/project-detect.js +46 -0
- package/dist/runtime/python-repl.d.ts +66 -0
- package/dist/runtime/python-repl.d.ts.map +1 -0
- package/dist/runtime/python-repl.js +563 -0
- package/dist/runtime/python-runner.d.ts +50 -0
- package/dist/runtime/python-runner.d.ts.map +1 -0
- package/dist/runtime/python-runner.js +870 -0
- package/dist/runtime/repl-session.d.ts +160 -0
- package/dist/runtime/repl-session.d.ts.map +1 -0
- package/dist/runtime/repl-session.js +393 -0
- package/dist/runtime/require-resolver.d.ts +52 -0
- package/dist/runtime/require-resolver.d.ts.map +1 -0
- package/dist/runtime/require-resolver.js +690 -0
- package/dist/runtime/router-basename.d.ts +36 -0
- package/dist/runtime/router-basename.d.ts.map +1 -0
- package/dist/runtime/router-basename.js +310 -0
- package/dist/runtime/ruby-repl.d.ts +43 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -0
- package/dist/runtime/ruby-repl.js +229 -0
- package/dist/runtime/ruby-runner.d.ts +62 -0
- package/dist/runtime/ruby-runner.d.ts.map +1 -0
- package/dist/runtime/ruby-runner.js +737 -0
- package/dist/runtime/runtime-catalog.d.ts +99 -0
- package/dist/runtime/runtime-catalog.d.ts.map +1 -0
- package/dist/runtime/runtime-catalog.js +183 -0
- package/dist/runtime/runtime-registry.d.ts +136 -0
- package/dist/runtime/runtime-registry.d.ts.map +1 -0
- package/dist/runtime/runtime-registry.js +318 -0
- package/dist/runtime/streams.d.ts +13 -0
- package/dist/runtime/streams.d.ts.map +1 -0
- package/dist/runtime/streams.js +402 -0
- package/dist/runtime/wasi-instance.d.ts +190 -0
- package/dist/runtime/wasi-instance.d.ts.map +1 -0
- package/dist/runtime/wasi-instance.js +2044 -0
- package/dist/runtime/wasm-runner.d.ts +117 -0
- package/dist/runtime/wasm-runner.d.ts.map +1 -0
- package/dist/runtime/wasm-runner.js +705 -0
- package/dist/session/bindings.d.ts +168 -0
- package/dist/session/bindings.d.ts.map +1 -0
- package/dist/session/bindings.js +524 -0
- package/dist/session/ctx-exports.d.ts +16 -0
- package/dist/session/ctx-exports.d.ts.map +1 -0
- package/dist/session/ctx-exports.js +22 -0
- package/dist/session/diag.d.ts +62 -0
- package/dist/session/diag.d.ts.map +1 -0
- package/dist/session/diag.js +118 -0
- package/dist/session/fs-watch.d.ts +132 -0
- package/dist/session/fs-watch.d.ts.map +1 -0
- package/dist/session/fs-watch.js +255 -0
- package/dist/session/helpers.d.ts +150 -0
- package/dist/session/helpers.d.ts.map +1 -0
- package/dist/session/helpers.js +472 -0
- package/dist/session/hibernation.d.ts +145 -0
- package/dist/session/hibernation.d.ts.map +1 -0
- package/dist/session/hibernation.js +385 -0
- package/dist/session/init-phases.d.ts +87 -0
- package/dist/session/init-phases.d.ts.map +1 -0
- package/dist/session/init-phases.js +137 -0
- package/dist/session/init.d.ts +46 -0
- package/dist/session/init.d.ts.map +1 -0
- package/dist/session/init.js +3579 -0
- package/dist/session/keys.d.ts +56 -0
- package/dist/session/keys.d.ts.map +1 -0
- package/dist/session/keys.js +55 -0
- package/dist/session/nimbus-session.d.ts +434 -0
- package/dist/session/nimbus-session.d.ts.map +1 -0
- package/dist/session/nimbus-session.js +1084 -0
- package/dist/session/programmatic.d.ts +105 -0
- package/dist/session/programmatic.d.ts.map +1 -0
- package/dist/session/programmatic.js +326 -0
- package/dist/session/replica-routes.d.ts +68 -0
- package/dist/session/replica-routes.d.ts.map +1 -0
- package/dist/session/replica-routes.js +77 -0
- package/dist/session/routes.d.ts +29 -0
- package/dist/session/routes.d.ts.map +1 -0
- package/dist/session/routes.js +1331 -0
- package/dist/session/rpc.d.ts +323 -0
- package/dist/session/rpc.d.ts.map +1 -0
- package/dist/session/rpc.js +808 -0
- package/dist/session/state-store.d.ts +210 -0
- package/dist/session/state-store.d.ts.map +1 -0
- package/dist/session/state-store.js +459 -0
- package/dist/session/supervisor-rpc.d.ts +269 -0
- package/dist/session/supervisor-rpc.d.ts.map +1 -0
- package/dist/session/supervisor-rpc.js +437 -0
- package/dist/session/ws-hibernation-config.d.ts +64 -0
- package/dist/session/ws-hibernation-config.d.ts.map +1 -0
- package/dist/session/ws-hibernation-config.js +89 -0
- package/dist/session/ws.d.ts +95 -0
- package/dist/session/ws.d.ts.map +1 -0
- package/dist/session/ws.js +395 -0
- package/dist/shell/features.d.ts +410 -0
- package/dist/shell/features.d.ts.map +1 -0
- package/dist/shell/features.js +1885 -0
- package/dist/shell/unix-commands.d.ts +15 -0
- package/dist/shell/unix-commands.d.ts.map +1 -0
- package/dist/shell/unix-commands.js +3703 -0
- package/dist/stubs/lifo-ui.d.ts +10 -0
- package/dist/stubs/lifo-ui.d.ts.map +1 -0
- package/dist/stubs/lifo-ui.js +1 -0
- package/dist/tailwind-play.generated.d.ts +19 -0
- package/dist/tailwind-play.generated.d.ts.map +1 -0
- package/dist/tailwind-play.generated.js +18 -0
- package/dist/vfs/dev-provider.d.ts +64 -0
- package/dist/vfs/dev-provider.d.ts.map +1 -0
- package/dist/vfs/dev-provider.js +191 -0
- package/dist/vfs/events.d.ts +51 -0
- package/dist/vfs/events.d.ts.map +1 -0
- package/dist/vfs/events.js +127 -0
- package/dist/vfs/path.d.ts +30 -0
- package/dist/vfs/path.d.ts.map +1 -0
- package/dist/vfs/path.js +41 -0
- package/dist/vfs/seed-project.d.ts +62 -0
- package/dist/vfs/seed-project.d.ts.map +1 -0
- package/dist/vfs/seed-project.js +1045 -0
- package/dist/vfs/sqlite-vfs.d.ts +435 -0
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -0
- package/dist/vfs/sqlite-vfs.js +1670 -0
- package/dist/vfs/symlink-registry.d.ts +64 -0
- package/dist/vfs/symlink-registry.d.ts.map +1 -0
- package/dist/vfs/symlink-registry.js +137 -0
- package/dist/wrangler/nimbus-wrangler.d.ts +157 -0
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -0
- package/dist/wrangler/nimbus-wrangler.js +931 -0
- package/package.json +77 -0
- package/public/_assets/cirrus-plugin-react.bundle.js +70740 -0
- package/public/_assets/esbuild-0.24.2.wasm +0 -0
- package/public/_assets/real-vite-bundle.js +101478 -0
- package/public/_assets/rollup.wasm +0 -0
- package/public/favicon.svg +8 -0
- package/public/index.html +565 -0
- package/public/s/index.html +2379 -0
- package/scripts/bundle-esbuild-wasm.mjs +244 -0
- package/scripts/bundle-facet-workers.mjs +137 -0
- package/scripts/bundle-git.mjs +118 -0
- package/scripts/bundle-npm-cjs.mjs +363 -0
- package/scripts/bundle-plugin-react.mjs +480 -0
- package/scripts/bundle-real-vite.mjs +959 -0
- package/scripts/bundle-runtime.mjs +600 -0
- package/scripts/bundle-tailwind-play.mjs +130 -0
- package/scripts/patch-lifo-ui.mjs +131 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { WorkerLoader } from './types.js';
|
|
2
|
+
import type { WorkerCodeOptions } from './codegen.js';
|
|
3
|
+
export interface ResilienceOptions {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
/** Retry attempts after initial failure. 0 = no retries (default). */
|
|
6
|
+
retries?: number;
|
|
7
|
+
/** Base delay (ms) between retries. Doubles each attempt. Default: 100. */
|
|
8
|
+
retryDelay?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface PoolOptions {
|
|
11
|
+
workerOptions?: WorkerCodeOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Bindings forwarded to dynamic workers (KV, R2, AI, D1, etc.).
|
|
14
|
+
* When set, each function receives an `env` object as its last argument.
|
|
15
|
+
*/
|
|
16
|
+
bindings?: Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Values injected as module-level constants into every generated worker.
|
|
19
|
+
* Must be JSON-serializable.
|
|
20
|
+
*/
|
|
21
|
+
context?: Record<string, unknown>;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
retries?: number;
|
|
24
|
+
retryDelay?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SubmitOptions extends ResilienceOptions {
|
|
27
|
+
/** Per-call context. Merged with (and overrides) pool-level context. */
|
|
28
|
+
context?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export type OnErrorStrategy = 'throw' | 'skip' | 'null';
|
|
31
|
+
export interface MapOptions extends ResilienceOptions {
|
|
32
|
+
concurrency?: number;
|
|
33
|
+
context?: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Per-item failure handling:
|
|
36
|
+
* - `'throw'` (default): reject on first failure.
|
|
37
|
+
* - `'skip'`: omit failed items from results.
|
|
38
|
+
* - `'null'`: replace failed items with `null`.
|
|
39
|
+
*/
|
|
40
|
+
onError?: OnErrorStrategy;
|
|
41
|
+
}
|
|
42
|
+
export interface PmapOptions {
|
|
43
|
+
chunks?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface StreamOptions extends ResilienceOptions {
|
|
46
|
+
concurrency?: number;
|
|
47
|
+
context?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
export interface StreamResult<T> {
|
|
50
|
+
index: number;
|
|
51
|
+
value: T;
|
|
52
|
+
}
|
|
53
|
+
export interface ScatterOptions extends ResilienceOptions {
|
|
54
|
+
context?: Record<string, unknown>;
|
|
55
|
+
onError?: OnErrorStrategy;
|
|
56
|
+
}
|
|
57
|
+
export declare class WorkerPool {
|
|
58
|
+
#private;
|
|
59
|
+
constructor(loader: WorkerLoader, opts?: PoolOptions);
|
|
60
|
+
submit<T>(fn: (...args: any[]) => T, ...rest: unknown[]): Promise<Awaited<T>>;
|
|
61
|
+
map<T, R>(fn: (item: T) => R, items: T[], opts?: MapOptions): Promise<Awaited<R>[]>;
|
|
62
|
+
/** Tree-parallel reduce: O(log n) depth instead of O(n). */
|
|
63
|
+
reduce<T>(fn: (a: T, b: T) => T, items: T[], initial: T): Promise<Awaited<T>>;
|
|
64
|
+
/**
|
|
65
|
+
* Chunked parallel map. Returns a curried function that splits input
|
|
66
|
+
* into chunks and maps each chunk on a separate isolate.
|
|
67
|
+
*/
|
|
68
|
+
pmap<T, R>(fn: (batch: T[]) => R[]): (items: T[], opts?: PmapOptions) => Promise<Awaited<R>[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Sequential pipeline where each stage runs on its own isolate.
|
|
71
|
+
* Output of one stage feeds into the next.
|
|
72
|
+
*/
|
|
73
|
+
pipe<A, B>(f1: (a: A) => B): (input: A) => Promise<Awaited<B>>;
|
|
74
|
+
pipe<A, B, C>(f1: (a: A) => B, f2: (b: Awaited<B>) => C): (input: A) => Promise<Awaited<C>>;
|
|
75
|
+
pipe<A, B, C, D>(f1: (a: A) => B, f2: (b: Awaited<B>) => C, f3: (c: Awaited<C>) => D): (input: A) => Promise<Awaited<D>>;
|
|
76
|
+
pipe<A, B, C, D, E>(f1: (a: A) => B, f2: (b: Awaited<B>) => C, f3: (c: Awaited<C>) => D, f4: (d: Awaited<D>) => E): (input: A) => Promise<Awaited<E>>;
|
|
77
|
+
pipe<A, B, C, D, E, F>(f1: (a: A) => B, f2: (b: Awaited<B>) => C, f3: (c: Awaited<C>) => D, f4: (d: Awaited<D>) => E, f5: (e: Awaited<E>) => F): (input: A) => Promise<Awaited<F>>;
|
|
78
|
+
pipe(...fns: ((...args: any[]) => any)[]): (input: any) => Promise<any>;
|
|
79
|
+
scatter<T, R>(fn: (items: T[]) => R, items: T[], chunks: number, opts?: ScatterOptions): Promise<Awaited<R>[]>;
|
|
80
|
+
gather<T>(promises: Promise<T>[]): Promise<T[]>;
|
|
81
|
+
mapStream<T, R>(fn: (item: T) => R, items: T[], opts?: StreamOptions): AsyncIterable<StreamResult<Awaited<R>>>;
|
|
82
|
+
/**
|
|
83
|
+
* Ordered streaming map: yields values in original input order,
|
|
84
|
+
* buffering out-of-order completions internally.
|
|
85
|
+
*/
|
|
86
|
+
mapOrdered<T, R>(fn: (item: T) => R, items: T[], opts?: StreamOptions): AsyncIterable<Awaited<R>>;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/loaders/vendor/pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAyB,MAAM,cAAc,CAAC;AAU7E,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAElC;;;OAGG;IACH,QAAQ,C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C,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC;IAajE,OAAO,CAAC,CAAC,EAAE,CAAC,EAChB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EACrB,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAkDlB,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAM9C,SAAS,CAAC,CAAC,EAAE,CAAC,EACnB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,EAClB,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,CAAC,EAAE,aAAa,GACnB,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IA6D1C;;;OAGG;IACI,UAAU,CAAC,CAAC,EAAE,CAAC,EACpB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,EAClB,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,CAAC,EAAE,aAAa,GACnB,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CA0C7B"}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { buildWorkerCode } from './codegen.js';
|
|
2
|
+
import { serializeFunction, hashSource } from './serialize.js';
|
|
3
|
+
import { ExecutionError, BindingError, TimeoutError, RetryExhaustedError, } from './errors.js';
|
|
4
|
+
export class WorkerPool {
|
|
5
|
+
#loader;
|
|
6
|
+
#workerOpts;
|
|
7
|
+
#bindings;
|
|
8
|
+
#poolContext;
|
|
9
|
+
#defaultTimeout;
|
|
10
|
+
#defaultRetries;
|
|
11
|
+
#defaultRetryDelay;
|
|
12
|
+
#counter = 0;
|
|
13
|
+
constructor(loader, opts) {
|
|
14
|
+
if (!loader || typeof loader.get !== 'function') {
|
|
15
|
+
throw new BindingError('WorkerPool requires a Worker Loader binding. ' +
|
|
16
|
+
'Add `[[worker_loaders]]` to your wrangler.toml and pass `env.LOADER`.');
|
|
17
|
+
}
|
|
18
|
+
this.#loader = loader;
|
|
19
|
+
this.#bindings = opts?.bindings;
|
|
20
|
+
this.#poolContext = opts?.context;
|
|
21
|
+
this.#defaultTimeout = opts?.timeout;
|
|
22
|
+
this.#defaultRetries = opts?.retries ?? 0;
|
|
23
|
+
this.#defaultRetryDelay = opts?.retryDelay ?? 100;
|
|
24
|
+
// Merge bindings into workerOptions.env so the dynamic worker
|
|
25
|
+
// receives them as `this.env` (the Worker Loader pattern).
|
|
26
|
+
if (opts?.bindings) {
|
|
27
|
+
const existingEnv = opts?.workerOptions?.env ?? {};
|
|
28
|
+
this.#workerOpts = {
|
|
29
|
+
...opts?.workerOptions,
|
|
30
|
+
env: { ...existingEnv, ...opts.bindings },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.#workerOpts = opts?.workerOptions;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
#mergeContext(perCall) {
|
|
38
|
+
if (!this.#poolContext && !perCall)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (!this.#poolContext)
|
|
41
|
+
return perCall;
|
|
42
|
+
if (!perCall)
|
|
43
|
+
return this.#poolContext;
|
|
44
|
+
return { ...this.#poolContext, ...perCall };
|
|
45
|
+
}
|
|
46
|
+
#sourceOpts(perCallContext) {
|
|
47
|
+
const context = this.#mergeContext(perCallContext);
|
|
48
|
+
const passEnv = !!this.#bindings;
|
|
49
|
+
if (!context && !passEnv)
|
|
50
|
+
return undefined;
|
|
51
|
+
return { context, passEnv };
|
|
52
|
+
}
|
|
53
|
+
#resolveResilience(perCall) {
|
|
54
|
+
return {
|
|
55
|
+
timeout: perCall?.timeout ?? this.#defaultTimeout,
|
|
56
|
+
retries: perCall?.retries ?? this.#defaultRetries,
|
|
57
|
+
retryDelay: perCall?.retryDelay ?? this.#defaultRetryDelay,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Core dispatch
|
|
61
|
+
async #dispatch(fnSource, fnHash, args, perCallContext) {
|
|
62
|
+
const id = `cfp:${fnHash}:${this.#counter++}`;
|
|
63
|
+
const workerCode = buildWorkerCode(fnSource, this.#workerOpts, this.#sourceOpts(perCallContext));
|
|
64
|
+
const stub = this.#loader.get(id, async () => workerCode);
|
|
65
|
+
const entrypoint = stub.getEntrypoint();
|
|
66
|
+
try {
|
|
67
|
+
return await entrypoint.execute(...args);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof Error) {
|
|
71
|
+
throw new ExecutionError(err.message, err.stack);
|
|
72
|
+
}
|
|
73
|
+
throw new ExecutionError(String(err));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async #dispatchWithResilience(fnSource, fnHash, args, resilience, perCallContext) {
|
|
77
|
+
const { timeout, retries, retryDelay } = this.#resolveResilience(resilience);
|
|
78
|
+
const maxAttempts = 1 + (retries ?? 0);
|
|
79
|
+
let lastError;
|
|
80
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
81
|
+
try {
|
|
82
|
+
const taskPromise = this.#dispatch(fnSource, fnHash, args, perCallContext);
|
|
83
|
+
if (timeout !== undefined && timeout > 0) {
|
|
84
|
+
const result = await Promise.race([
|
|
85
|
+
taskPromise,
|
|
86
|
+
new Promise((_, reject) => setTimeout(() => reject(new TimeoutError(timeout)), timeout)),
|
|
87
|
+
]);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
return await taskPromise;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
94
|
+
if (attempt < maxAttempts - 1) {
|
|
95
|
+
const delay = (retryDelay ?? 100) * Math.pow(2, attempt);
|
|
96
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (maxAttempts > 1) {
|
|
101
|
+
throw new RetryExhaustedError(maxAttempts, lastError);
|
|
102
|
+
}
|
|
103
|
+
throw lastError;
|
|
104
|
+
}
|
|
105
|
+
#prepare(fn) {
|
|
106
|
+
const fnSource = serializeFunction(fn);
|
|
107
|
+
const fnHash = hashSource(fnSource);
|
|
108
|
+
return { fnSource, fnHash };
|
|
109
|
+
}
|
|
110
|
+
// Public API
|
|
111
|
+
async submit(fn, ...rest) {
|
|
112
|
+
// Last element of `rest` may be a SubmitOptions object.
|
|
113
|
+
let args;
|
|
114
|
+
let opts;
|
|
115
|
+
const last = rest[rest.length - 1];
|
|
116
|
+
if (rest.length > 0 && isSubmitOptions(last)) {
|
|
117
|
+
opts = last;
|
|
118
|
+
args = rest.slice(0, -1);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
args = rest;
|
|
122
|
+
}
|
|
123
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
124
|
+
return this.#dispatchWithResilience(fnSource, fnHash, args, opts ?? {}, opts?.context);
|
|
125
|
+
}
|
|
126
|
+
async map(fn, items, opts) {
|
|
127
|
+
if (items.length === 0)
|
|
128
|
+
return [];
|
|
129
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
130
|
+
const concurrency = opts?.concurrency ?? items.length;
|
|
131
|
+
const onError = opts?.onError ?? 'throw';
|
|
132
|
+
const resilience = {
|
|
133
|
+
timeout: opts?.timeout,
|
|
134
|
+
retries: opts?.retries,
|
|
135
|
+
retryDelay: opts?.retryDelay,
|
|
136
|
+
};
|
|
137
|
+
if (onError === 'throw' && concurrency >= items.length) {
|
|
138
|
+
return Promise.all(items.map((item) => this.#dispatchWithResilience(fnSource, fnHash, [item], resilience, opts?.context)));
|
|
139
|
+
}
|
|
140
|
+
// Bounded concurrency and/or partial failure handling.
|
|
141
|
+
const settled = new Array(items.length);
|
|
142
|
+
let cursor = 0;
|
|
143
|
+
const runNext = async () => {
|
|
144
|
+
while (cursor < items.length) {
|
|
145
|
+
const idx = cursor++;
|
|
146
|
+
try {
|
|
147
|
+
const value = await this.#dispatchWithResilience(fnSource, fnHash, [items[idx]], resilience, opts?.context);
|
|
148
|
+
settled[idx] = { ok: true, value };
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
if (onError === 'throw')
|
|
152
|
+
throw err;
|
|
153
|
+
settled[idx] = {
|
|
154
|
+
ok: false,
|
|
155
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => runNext()));
|
|
161
|
+
if (onError === 'null') {
|
|
162
|
+
return settled.map((s) => (s.ok ? s.value : null));
|
|
163
|
+
}
|
|
164
|
+
return settled.filter((s) => s.ok).map((s) => s.value);
|
|
165
|
+
}
|
|
166
|
+
/** Tree-parallel reduce: O(log n) depth instead of O(n). */
|
|
167
|
+
async reduce(fn, items, initial) {
|
|
168
|
+
if (items.length === 0)
|
|
169
|
+
return initial;
|
|
170
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
171
|
+
let current = [initial, ...items];
|
|
172
|
+
while (current.length > 1) {
|
|
173
|
+
const tasks = [];
|
|
174
|
+
const carryForward = [];
|
|
175
|
+
for (let i = 0; i < current.length; i += 2) {
|
|
176
|
+
if (i + 1 < current.length) {
|
|
177
|
+
tasks.push(this.#dispatch(fnSource, fnHash, [current[i], current[i + 1]]));
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
carryForward.push({ index: tasks.length, value: current[i] });
|
|
181
|
+
tasks.push(Promise.resolve(current[i]));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const round = await Promise.all(tasks);
|
|
185
|
+
current = round;
|
|
186
|
+
}
|
|
187
|
+
return current[0];
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Chunked parallel map. Returns a curried function that splits input
|
|
191
|
+
* into chunks and maps each chunk on a separate isolate.
|
|
192
|
+
*/
|
|
193
|
+
pmap(fn) {
|
|
194
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
195
|
+
return async (items, opts) => {
|
|
196
|
+
if (items.length === 0)
|
|
197
|
+
return [];
|
|
198
|
+
const numChunks = opts?.chunks ?? items.length;
|
|
199
|
+
const chunkSize = Math.ceil(items.length / numChunks);
|
|
200
|
+
const chunks = [];
|
|
201
|
+
for (let i = 0; i < items.length; i += chunkSize) {
|
|
202
|
+
chunks.push(items.slice(i, i + chunkSize));
|
|
203
|
+
}
|
|
204
|
+
const chunkResults = await Promise.all(chunks.map((chunk) => this.#dispatch(fnSource, fnHash, [chunk])));
|
|
205
|
+
return chunkResults.flat();
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
pipe(...fns) {
|
|
209
|
+
const stages = fns.map((fn) => this.#prepare(fn));
|
|
210
|
+
return async (input) => {
|
|
211
|
+
let value = input;
|
|
212
|
+
for (const { fnSource, fnHash } of stages) {
|
|
213
|
+
value = await this.#dispatch(fnSource, fnHash, [value]);
|
|
214
|
+
}
|
|
215
|
+
return value;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
async scatter(fn, items, chunks, opts) {
|
|
219
|
+
if (items.length === 0)
|
|
220
|
+
return [];
|
|
221
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
222
|
+
const chunkSize = Math.ceil(items.length / chunks);
|
|
223
|
+
const batches = [];
|
|
224
|
+
for (let i = 0; i < items.length; i += chunkSize) {
|
|
225
|
+
batches.push(items.slice(i, i + chunkSize));
|
|
226
|
+
}
|
|
227
|
+
const onError = opts?.onError ?? 'throw';
|
|
228
|
+
const resilience = {
|
|
229
|
+
timeout: opts?.timeout,
|
|
230
|
+
retries: opts?.retries,
|
|
231
|
+
retryDelay: opts?.retryDelay,
|
|
232
|
+
};
|
|
233
|
+
if (onError === 'throw') {
|
|
234
|
+
return Promise.all(batches.map((batch) => this.#dispatchWithResilience(fnSource, fnHash, [batch], resilience, opts?.context)));
|
|
235
|
+
}
|
|
236
|
+
const results = await Promise.all(batches.map(async (batch) => {
|
|
237
|
+
try {
|
|
238
|
+
const value = await this.#dispatchWithResilience(fnSource, fnHash, [batch], resilience, opts?.context);
|
|
239
|
+
return { ok: true, value };
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
return {
|
|
243
|
+
ok: false,
|
|
244
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}));
|
|
248
|
+
if (onError === 'null') {
|
|
249
|
+
return results.map((r) => (r.ok ? r.value : null));
|
|
250
|
+
}
|
|
251
|
+
return results.filter((r) => r.ok).map((r) => r.value);
|
|
252
|
+
}
|
|
253
|
+
async gather(promises) {
|
|
254
|
+
return Promise.all(promises);
|
|
255
|
+
}
|
|
256
|
+
// Streaming iterators
|
|
257
|
+
async *mapStream(fn, items, opts) {
|
|
258
|
+
if (items.length === 0)
|
|
259
|
+
return;
|
|
260
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
261
|
+
const concurrency = opts?.concurrency ?? items.length;
|
|
262
|
+
const resilience = {
|
|
263
|
+
timeout: opts?.timeout,
|
|
264
|
+
retries: opts?.retries,
|
|
265
|
+
retryDelay: opts?.retryDelay,
|
|
266
|
+
};
|
|
267
|
+
// Channel: pre-allocate a promise per item. Producers resolve them
|
|
268
|
+
// in completion order; the consumer awaits them sequentially.
|
|
269
|
+
const queue = [];
|
|
270
|
+
for (let i = 0; i < items.length; i++) {
|
|
271
|
+
let resolve;
|
|
272
|
+
let reject;
|
|
273
|
+
const promise = new Promise((res, rej) => {
|
|
274
|
+
resolve = res;
|
|
275
|
+
reject = rej;
|
|
276
|
+
});
|
|
277
|
+
queue.push({ resolve, reject, promise });
|
|
278
|
+
}
|
|
279
|
+
let completionSlot = 0;
|
|
280
|
+
let cursor = 0;
|
|
281
|
+
const dispatchNext = async () => {
|
|
282
|
+
while (cursor < items.length) {
|
|
283
|
+
const itemIdx = cursor++;
|
|
284
|
+
const slot = completionSlot++;
|
|
285
|
+
try {
|
|
286
|
+
const value = await this.#dispatchWithResilience(fnSource, fnHash, [items[itemIdx]], resilience, opts?.context);
|
|
287
|
+
queue[slot].resolve({ index: itemIdx, value });
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
queue[slot].reject(err instanceof Error ? err : new Error(String(err)));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const workers = Array.from({ length: Math.min(concurrency, items.length) }, () => dispatchNext());
|
|
295
|
+
for (let i = 0; i < items.length; i++) {
|
|
296
|
+
yield await queue[i].promise;
|
|
297
|
+
}
|
|
298
|
+
await Promise.all(workers);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Ordered streaming map: yields values in original input order,
|
|
302
|
+
* buffering out-of-order completions internally.
|
|
303
|
+
*/
|
|
304
|
+
async *mapOrdered(fn, items, opts) {
|
|
305
|
+
if (items.length === 0)
|
|
306
|
+
return;
|
|
307
|
+
const { fnSource, fnHash } = this.#prepare(fn);
|
|
308
|
+
const concurrency = opts?.concurrency ?? items.length;
|
|
309
|
+
const resilience = {
|
|
310
|
+
timeout: opts?.timeout,
|
|
311
|
+
retries: opts?.retries,
|
|
312
|
+
retryDelay: opts?.retryDelay,
|
|
313
|
+
};
|
|
314
|
+
// One promise per item, indexed by original position.
|
|
315
|
+
// Lets us yield in order regardless of completion order.
|
|
316
|
+
const slots = new Array(items.length);
|
|
317
|
+
let cursor = 0;
|
|
318
|
+
const dispatchNext = async () => {
|
|
319
|
+
while (cursor < items.length) {
|
|
320
|
+
const idx = cursor++;
|
|
321
|
+
slots[idx] = this.#dispatchWithResilience(fnSource, fnHash, [items[idx]], resilience, opts?.context);
|
|
322
|
+
await slots[idx].catch(() => { });
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
const workers = Array.from({ length: Math.min(concurrency, items.length) }, () => dispatchNext());
|
|
326
|
+
for (let i = 0; i < items.length; i++) {
|
|
327
|
+
// Spin-wait for slot assignment if a slow worker hasn't dispatched yet.
|
|
328
|
+
while (slots[i] === undefined) {
|
|
329
|
+
await new Promise((r) => setTimeout(r, 1));
|
|
330
|
+
}
|
|
331
|
+
yield await slots[i];
|
|
332
|
+
}
|
|
333
|
+
await Promise.all(workers);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Heuristic: detect whether the last argument to submit() is a SubmitOptions
|
|
338
|
+
* object rather than a regular argument. Checks for a plain object with at
|
|
339
|
+
* least one recognized option key.
|
|
340
|
+
*/
|
|
341
|
+
function isSubmitOptions(value) {
|
|
342
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
if (value instanceof Date || value instanceof RegExp || value instanceof Map) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
const keys = Object.keys(value);
|
|
349
|
+
const optionKeys = new Set([
|
|
350
|
+
'timeout', 'retries', 'retryDelay', 'context',
|
|
351
|
+
]);
|
|
352
|
+
return keys.length > 0 && keys.some((k) => optionKeys.has(k));
|
|
353
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Pure<F> = F & {
|
|
2
|
+
readonly __pure: true;
|
|
3
|
+
};
|
|
4
|
+
export declare function pure<F extends Function>(fn: F): Pure<F>;
|
|
5
|
+
export declare function isPure(fn: Function): fn is Pure<typeof fn>;
|
|
6
|
+
/**
|
|
7
|
+
* Identity function that signals a value is intended as a serializable
|
|
8
|
+
* constant for remote execution. No-op at runtime.
|
|
9
|
+
*/
|
|
10
|
+
export declare function constant<T>(value: T): T;
|
|
11
|
+
//# sourceMappingURL=primitives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../src/loaders/vendor/primitives.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC;AAEpD,wBAAgB,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CA+BvD;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,QAAQ,GAAG,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAE1D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEvC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SerializationError } from './errors.js';
|
|
2
|
+
export function pure(fn) {
|
|
3
|
+
if (typeof fn !== 'function') {
|
|
4
|
+
throw new SerializationError(`pure() expected a function, got ${typeof fn}`);
|
|
5
|
+
}
|
|
6
|
+
const source = fn.toString();
|
|
7
|
+
if (source.includes('[native code]')) {
|
|
8
|
+
throw new SerializationError(`pure(): cannot brand native function "${fn.name || '(anonymous)'}"`);
|
|
9
|
+
}
|
|
10
|
+
if (/\bthis\b/.test(source)) {
|
|
11
|
+
throw new SerializationError(`pure(): function "${fn.name || '(anonymous)'}" references \`this\`, ` +
|
|
12
|
+
'which is not available in a remote isolate. Remove `this` usage or ' +
|
|
13
|
+
'pass the value as an explicit argument.');
|
|
14
|
+
}
|
|
15
|
+
const branded = fn;
|
|
16
|
+
Object.defineProperty(branded, '__pure', {
|
|
17
|
+
value: true,
|
|
18
|
+
writable: false,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
configurable: false,
|
|
21
|
+
});
|
|
22
|
+
return branded;
|
|
23
|
+
}
|
|
24
|
+
export function isPure(fn) {
|
|
25
|
+
return fn.__pure === true;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Identity function that signals a value is intended as a serializable
|
|
29
|
+
* constant for remote execution. No-op at runtime.
|
|
30
|
+
*/
|
|
31
|
+
export function constant(value) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/loaders/vendor/serialize.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAyBtD;AAGD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMjD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SerializationError } from './errors.js';
|
|
2
|
+
export function serializeFunction(fn) {
|
|
3
|
+
if (typeof fn !== 'function') {
|
|
4
|
+
throw new SerializationError(`Expected a function, got ${typeof fn}`);
|
|
5
|
+
}
|
|
6
|
+
const source = fn.toString();
|
|
7
|
+
if (source.includes('[native code]')) {
|
|
8
|
+
throw new SerializationError(`Cannot serialize native function: ${fn.name || '(anonymous)'}. ` +
|
|
9
|
+
'Only user-defined functions can be dispatched to remote isolates.');
|
|
10
|
+
}
|
|
11
|
+
// `this` has no receiver in the remote isolate — reject it early.
|
|
12
|
+
if (/\bthis\b/.test(source)) {
|
|
13
|
+
throw new SerializationError(`Function "${fn.name || '(anonymous)'}" references \`this\`, which is ` +
|
|
14
|
+
'not available in a remote isolate. Pass values as explicit arguments instead.');
|
|
15
|
+
}
|
|
16
|
+
return source;
|
|
17
|
+
}
|
|
18
|
+
// djb2 hash — fast, deterministic, not cryptographic. Used only for loader cache key differentiation.
|
|
19
|
+
export function hashSource(source) {
|
|
20
|
+
let hash = 5381;
|
|
21
|
+
for (let i = 0; i < source.length; i++) {
|
|
22
|
+
hash = ((hash << 5) + hash + source.charCodeAt(i)) | 0;
|
|
23
|
+
}
|
|
24
|
+
return (hash >>> 0).toString(36);
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface JsModule {
|
|
2
|
+
js: string;
|
|
3
|
+
}
|
|
4
|
+
export interface CjsModule {
|
|
5
|
+
cjs: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PyModule {
|
|
8
|
+
py: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TextModule {
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DataModule {
|
|
14
|
+
data: ArrayBuffer;
|
|
15
|
+
}
|
|
16
|
+
export interface JsonModule {
|
|
17
|
+
json: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Plain string = type inferred from file extension (.js or .py). */
|
|
20
|
+
export type ModuleContent = string | JsModule | CjsModule | PyModule | TextModule | DataModule | JsonModule;
|
|
21
|
+
export interface WorkerCode {
|
|
22
|
+
compatibilityDate: string;
|
|
23
|
+
compatibilityFlags?: string[];
|
|
24
|
+
allowExperimental?: boolean;
|
|
25
|
+
mainModule: string;
|
|
26
|
+
modules: Record<string, ModuleContent>;
|
|
27
|
+
env?: Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Network access control:
|
|
30
|
+
* - `undefined`: inherit parent's network access.
|
|
31
|
+
* - `null`: block all outbound (fetch/connect throw).
|
|
32
|
+
* - A service stub: redirect outbound through that binding.
|
|
33
|
+
*/
|
|
34
|
+
globalOutbound?: ServiceStub | null;
|
|
35
|
+
tails?: ServiceStub[];
|
|
36
|
+
}
|
|
37
|
+
export interface ServiceStub {
|
|
38
|
+
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
39
|
+
}
|
|
40
|
+
export interface EntrypointOptions {
|
|
41
|
+
props?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export interface WorkerStub {
|
|
44
|
+
getEntrypoint(): EntrypointStub;
|
|
45
|
+
getEntrypoint(name: string, opts?: EntrypointOptions): EntrypointStub;
|
|
46
|
+
}
|
|
47
|
+
export interface EntrypointStub {
|
|
48
|
+
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
49
|
+
execute(...args: unknown[]): Promise<unknown>;
|
|
50
|
+
}
|
|
51
|
+
export type GetCodeCallback = () => Promise<WorkerCode>;
|
|
52
|
+
export interface WorkerLoader {
|
|
53
|
+
/**
|
|
54
|
+
* Load or reuse an isolate by ID. Same ID + same code may reuse an isolate;
|
|
55
|
+
* different IDs always get fresh isolates. `getCodeCallback` must return
|
|
56
|
+
* the same content for the same ID.
|
|
57
|
+
*/
|
|
58
|
+
get(id: string, getCodeCallback: GetCodeCallback): WorkerStub;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/loaders/vendor/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ;IAAG,EAAE,EAAE,MAAM,CAAA;CAAE;AACxC,MAAM,WAAW,SAAS;IAAG,GAAG,EAAE,MAAM,CAAA;CAAE;AAC1C,MAAM,WAAW,QAAQ;IAAG,EAAE,EAAE,MAAM,CAAA;CAAE;AACxC,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,MAAM,CAAA;CAAE;AAC5C,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,WAAW,CAAA;CAAE;AACjD,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,OAAO,CAAA;CAAE;AAE7C,qEAAqE;AACrE,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAEf,MAAM,WAAW,UAAU;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,iBAAiB,CAAC,EAAE,O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