@nimbus-sh/worker 0.9.0 → 0.11.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/NOTICE.md +5 -0
- package/README.md +10 -0
- package/dist/_shared/session-router.d.ts +7 -0
- package/dist/_shared/session-router.d.ts.map +1 -1
- package/dist/_shared/session-router.js +7 -0
- package/dist/bindings/body.d.ts +6 -0
- package/dist/bindings/body.d.ts.map +1 -0
- package/dist/bindings/body.js +37 -0
- package/dist/bindings/kv.d.ts +0 -2
- package/dist/bindings/kv.d.ts.map +1 -1
- package/dist/bindings/kv.js +3 -42
- package/dist/bindings/r2.d.ts +0 -2
- package/dist/bindings/r2.d.ts.map +1 -1
- package/dist/bindings/r2.js +4 -44
- package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
- package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
- package/dist/esbuild-cli-artifact.generated.js +17 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts +24 -24
- package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
- package/dist/esbuild-wasm-bundle.generated.js +24 -24
- package/dist/facets/cirrus-real.d.ts.map +1 -1
- package/dist/facets/cirrus-real.js +11 -6
- package/dist/facets/compose.d.ts +11 -7
- package/dist/facets/compose.d.ts.map +1 -1
- package/dist/facets/compose.js +8 -31
- package/dist/facets/data-plan.d.ts +79 -0
- package/dist/facets/data-plan.d.ts.map +1 -0
- package/dist/facets/data-plan.js +477 -0
- package/dist/facets/esbuild-bundle-pool.d.ts +1 -1
- package/dist/facets/esbuild-bundle-pool.js +3 -3
- package/dist/facets/esbuild-transform.d.ts +38 -8
- package/dist/facets/esbuild-transform.d.ts.map +1 -1
- package/dist/facets/esbuild-transform.js +219 -19
- package/dist/facets/exec-telemetry.d.ts +7 -3
- package/dist/facets/exec-telemetry.d.ts.map +1 -1
- package/dist/facets/manager.d.ts +198 -69
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +1276 -652
- package/dist/facets/opencode-staging.d.ts +0 -2
- package/dist/facets/opencode-staging.d.ts.map +1 -1
- package/dist/facets/opencode-staging.js +5 -11
- package/dist/facets/process.d.ts +4 -0
- package/dist/facets/process.d.ts.map +1 -1
- package/dist/facets/process.js +3 -0
- package/dist/facets/read-profile.d.ts +149 -0
- package/dist/facets/read-profile.d.ts.map +1 -0
- package/dist/facets/read-profile.js +483 -0
- package/dist/facets/real-vite-hmr.d.ts +2 -0
- package/dist/facets/real-vite-hmr.d.ts.map +1 -1
- package/dist/facets/real-vite-hmr.js +3 -2
- package/dist/facets/resident-identity.d.ts +0 -1
- package/dist/facets/resident-identity.d.ts.map +1 -1
- package/dist/facets/resident-identity.js +0 -3
- package/dist/facets/wasm-swap-registry.d.ts +34 -25
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
- package/dist/facets/wasm-swap-registry.js +62 -56
- package/dist/facets/ws-terminal.d.ts +4 -4
- package/dist/facets/ws-terminal.d.ts.map +1 -1
- package/dist/facets/ws-terminal.js +4 -5
- package/dist/git/commands.d.ts +33 -10
- package/dist/git/commands.d.ts.map +1 -1
- package/dist/git/commands.js +1891 -197
- package/dist/git/network-facet.d.ts +12 -2
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +69 -18
- package/dist/git/unified-diff.d.ts +74 -0
- package/dist/git/unified-diff.d.ts.map +1 -0
- package/dist/git/unified-diff.js +676 -0
- package/dist/git-bundle.generated.d.ts +7 -11
- package/dist/git-bundle.generated.d.ts.map +1 -1
- package/dist/git-bundle.generated.js +7 -11
- package/dist/hosted/commands.d.ts.map +1 -1
- package/dist/hosted/commands.js +64 -245
- package/dist/hosted/runtime.d.ts +22 -15
- package/dist/hosted/runtime.d.ts.map +1 -1
- package/dist/hosted/runtime.js +72 -14
- package/dist/hosted/services.d.ts +8 -1
- package/dist/hosted/services.d.ts.map +1 -1
- package/dist/hosted/services.js +12 -13
- package/dist/hosted/session.d.ts +165 -0
- package/dist/hosted/session.d.ts.map +1 -0
- package/dist/hosted/session.js +132 -0
- package/dist/loaders/generated-workers.d.ts +6 -3
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +8 -5
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
- package/dist/loaders/npm-resolve-preamble.js +0 -27
- package/dist/loaders/pre-bundle-preamble.d.ts +6 -3
- package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
- package/dist/loaders/pre-bundle-preamble.js +13 -8
- package/dist/node-shims-artifact.generated.d.ts +13 -4
- package/dist/node-shims-artifact.generated.d.ts.map +1 -1
- package/dist/node-shims-artifact.generated.js +16 -7
- package/dist/npm/bin-links.d.ts +3 -1
- package/dist/npm/bin-links.d.ts.map +1 -1
- package/dist/npm/bin-links.js +32 -8
- package/dist/npm/cache.d.ts +11 -1
- package/dist/npm/cache.d.ts.map +1 -1
- package/dist/npm/cache.js +21 -7
- package/dist/npm/install-batch-facet.d.ts +4 -2
- package/dist/npm/install-batch-facet.d.ts.map +1 -1
- package/dist/npm/install-batch-facet.js +32 -18
- package/dist/npm/installer.d.ts +23 -3
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +330 -131
- package/dist/npm/npx-install.d.ts +3 -1
- package/dist/npm/npx-install.d.ts.map +1 -1
- package/dist/npm/npx-install.js +4 -1
- package/dist/npm/package-lock.d.ts +32 -0
- package/dist/npm/package-lock.d.ts.map +1 -0
- package/dist/npm/package-lock.js +65 -0
- package/dist/npm/placement.d.ts +16 -0
- package/dist/npm/placement.d.ts.map +1 -0
- package/dist/npm/placement.js +33 -0
- package/dist/npm/pre-bundle-facet.d.ts +1 -30
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
- package/dist/npm/pre-bundle-facet.js +3 -5
- package/dist/npm/r2-cache.d.ts +12 -6
- package/dist/npm/r2-cache.d.ts.map +1 -1
- package/dist/npm/r2-cache.js +34 -16
- package/dist/npm/resolve-one-facet.d.ts +3 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +15 -3
- package/dist/npm/resolver.d.ts +11 -13
- package/dist/npm/resolver.d.ts.map +1 -1
- package/dist/npm/resolver.js +12 -25
- package/dist/opencode-artifact.generated.js +2 -2
- package/dist/replica/routing.d.ts +2 -38
- package/dist/replica/routing.d.ts.map +1 -1
- package/dist/replica/routing.js +3 -55
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +15 -2
- package/dist/router/public-directory.d.ts +18 -0
- package/dist/router/public-directory.d.ts.map +1 -1
- package/dist/router/public-directory.js +1 -1
- package/dist/router/remote-api.d.ts +3 -1
- package/dist/router/remote-api.d.ts.map +1 -1
- package/dist/router/remote-api.js +42 -79
- package/dist/runtime/bash-repl.js +2 -2
- package/dist/runtime/bun-repl.d.ts.map +1 -1
- package/dist/runtime/bun-repl.js +2 -13
- package/dist/runtime/cpython-resident.d.ts.map +1 -1
- package/dist/runtime/cpython-resident.js +2 -10
- package/dist/runtime/esbuild-wasm-bytes.d.ts +37 -18
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/esbuild-wasm-bytes.js +66 -92
- package/dist/runtime/facet-loader-host.d.ts.map +1 -1
- package/dist/runtime/facet-loader-host.js +0 -7
- package/dist/runtime/git-bundle-artifact.d.ts +17 -0
- package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
- package/dist/runtime/git-bundle-artifact.js +25 -0
- package/dist/runtime/node-repl.d.ts.map +1 -1
- package/dist/runtime/node-repl.js +2 -13
- package/dist/runtime/node-shims-artifact.d.ts +22 -23
- package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
- package/dist/runtime/node-shims-artifact.js +48 -78
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +2358 -996
- package/dist/runtime/opencode-artifact.d.ts.map +1 -1
- package/dist/runtime/opencode-artifact.js +17 -53
- package/dist/runtime/opencode-facet-runner.d.ts +3 -6
- package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
- package/dist/runtime/opencode-facet-runner.js +45 -10
- package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/opentui-wasm-bytes.js +16 -49
- package/dist/runtime/package-manager.d.ts +0 -2
- package/dist/runtime/package-manager.d.ts.map +1 -1
- package/dist/runtime/package-manager.js +0 -3
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +4 -35
- package/dist/runtime/repl-session.d.ts +10 -0
- package/dist/runtime/repl-session.d.ts.map +1 -1
- package/dist/runtime/repl-session.js +7 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -1
- package/dist/runtime/ruby-repl.js +2 -2
- package/dist/runtime/ruby-resident.d.ts.map +1 -1
- package/dist/runtime/ruby-resident.js +41 -51
- package/dist/runtime/runtime-catalog.d.ts +10 -3
- package/dist/runtime/runtime-catalog.d.ts.map +1 -1
- package/dist/runtime/runtime-catalog.js +125 -15
- package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
- package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/sqlite-wasm-bytes.js +21 -57
- package/dist/runtime/staged-source.d.ts +67 -0
- package/dist/runtime/staged-source.d.ts.map +1 -0
- package/dist/runtime/staged-source.js +113 -0
- package/dist/runtime/wasi/preamble.d.ts +0 -22
- package/dist/runtime/wasi/preamble.d.ts.map +1 -1
- package/dist/runtime/wasi/preamble.js +98 -1425
- package/dist/runtime-catalog.generated.js +1 -1
- package/dist/session/agent.d.ts +14 -2
- package/dist/session/agent.d.ts.map +1 -1
- package/dist/session/agent.js +57 -19
- package/dist/session/ai.d.ts +0 -11
- package/dist/session/ai.d.ts.map +1 -1
- package/dist/session/ai.js +0 -4
- package/dist/session/fs-watch.d.ts +0 -11
- package/dist/session/fs-watch.d.ts.map +1 -1
- package/dist/session/fs-watch.js +0 -21
- package/dist/session/hibernation.d.ts +68 -2
- package/dist/session/hibernation.d.ts.map +1 -1
- package/dist/session/hibernation.js +95 -1
- package/dist/session/init-phases.d.ts +1 -2
- package/dist/session/init-phases.d.ts.map +1 -1
- package/dist/session/init-phases.js +1 -2
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +7 -20
- package/dist/session/keys.d.ts +0 -3
- package/dist/session/keys.d.ts.map +1 -1
- package/dist/session/keys.js +0 -3
- package/dist/session/legacy-reset.d.ts +11 -0
- package/dist/session/legacy-reset.d.ts.map +1 -0
- package/dist/session/legacy-reset.js +16 -0
- package/dist/session/nimbus-session.d.ts +50 -16
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +77 -71
- package/dist/session/npm-install-port.d.ts.map +1 -1
- package/dist/session/npm-install-port.js +2 -0
- package/dist/session/programmatic.d.ts +13 -18
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +53 -39
- package/dist/session/replica-routes.d.ts +2 -3
- package/dist/session/replica-routes.d.ts.map +1 -1
- package/dist/session/replica-routes.js +3 -10
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +11 -12
- package/dist/session/rpc.d.ts +108 -21
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +194 -39
- package/dist/session/start-real-vite.js +2 -2
- package/dist/session/state-store.d.ts +1 -17
- package/dist/session/state-store.d.ts.map +1 -1
- package/dist/session/state-store.js +3 -53
- package/dist/session/supervisor-op.d.ts +7 -0
- package/dist/session/supervisor-op.d.ts.map +1 -1
- package/dist/session/supervisor-op.js +6 -1
- package/dist/session/supervisor-rpc.d.ts +116 -19
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +194 -84
- package/dist/session/vite-command.d.ts.map +1 -1
- package/dist/session/vite-command.js +17 -14
- package/dist/session/ws.d.ts.map +1 -1
- package/dist/session/ws.js +20 -8
- package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
- package/dist/shell/npm-bin-entrypoints.js +30 -5
- package/dist/vfs/facet-resident-limits.d.ts +33 -0
- package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
- package/dist/vfs/facet-resident-limits.js +33 -0
- package/dist/vfs/facet-resident-store.d.ts +2 -10
- package/dist/vfs/facet-resident-store.d.ts.map +1 -1
- package/dist/vfs/facet-resident-store.js +1594 -219
- package/dist/workspace-host.d.ts +3 -1
- package/dist/workspace-host.d.ts.map +1 -1
- package/dist/workspace-host.js +2 -0
- package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
- package/dist/wrangler/nimbus-wrangler.js +8 -22
- package/package.json +34 -7
- package/public/_assets/esbuild-0.24.2.js +2380 -0
- package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
- package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
- package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
- package/public/_assets/runtime/{node-shims-acaa037e6d26ec0d.js → node-shims-06565b121555c194.js} +2879 -992
- package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
- package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
- package/scripts/build-opencode-attach-entry.mjs +51 -1
- package/scripts/bundle-esbuild-wasm.mjs +55 -39
- package/scripts/bundle-facet-workers.mjs +159 -10
- package/scripts/bundle-git.mjs +88 -27
- package/scripts/bundle-node-shims.mjs +72 -46
- package/scripts/bundle-runtime.mjs +18 -421
- package/scripts/cf-git-patch.mjs +137 -0
- package/scripts/patch-install-deps.mjs +49 -96
- package/scripts/runtime-specs.mjs +435 -0
- package/vendor/git-http.generated.d.ts +82 -0
- package/vendor/git-upstream.generated.d.ts +4378 -0
- package/vendor/git.LICENSE +7 -0
- package/vendor/git.generated.d.mts +21 -0
- package/vendor/git.generated.mjs +103 -0
- package/dist/replica/suspension.d.ts +0 -36
- package/dist/replica/suspension.d.ts.map +0 -1
- package/dist/replica/suspension.js +0 -49
- package/dist/runtime/static-server.d.ts +0 -3
- package/dist/runtime/static-server.d.ts.map +0 -1
- package/dist/runtime/static-server.js +0 -133
- package/scripts/clean-dist.mjs +0 -7
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* replica-suspension.ts — W12 — global replica-suspension counter.
|
|
3
|
-
*
|
|
4
|
-
* Per [~lambros/Feedback for DO read replication API](https://wiki.cfdata.org/display/~lambros/Feedback+for+DO+read+replication+API+based+on+D1+read+replication+beta)
|
|
5
|
-
* (cited in CF research §G.4), DO read replicas error with "Network
|
|
6
|
-
* connection lost" during high-volume writes. The recommended mitigation
|
|
7
|
-
* is to disable replicas before a write burst (npm install, git clone)
|
|
8
|
-
* and re-enable after.
|
|
9
|
-
*
|
|
10
|
-
* This module exposes a refcount-style suspend/release API. The counter
|
|
11
|
-
* is checked by `shouldDelegateToPrimary` (in `replica-routing.ts`):
|
|
12
|
-
* when `replicasSuspended() === true`, the replica forwards everything
|
|
13
|
-
* to the primary regardless of route policy.
|
|
14
|
-
*
|
|
15
|
-
* Phase 1 of W12 ships the module + the in-DO consultation. Phase 2
|
|
16
|
-
* (W12.5 if measured demand) wires the npm-installer / git-clone hooks.
|
|
17
|
-
* Today's behaviour: counter stays at 0 → replicas serve normally; the
|
|
18
|
-
* SPEC error path is observed as a graceful-degrade (replica's primary
|
|
19
|
-
* stub returns the error and the user sees a 5xx, same as today's
|
|
20
|
-
* single-region behaviour).
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Increment the suspension count. Returns a release function that
|
|
24
|
-
* decrements once (subsequent calls are no-ops). Suspends are nestable;
|
|
25
|
-
* any holder keeping the count > 0 keeps replicas suspended.
|
|
26
|
-
*/
|
|
27
|
-
export declare function suspendReplicas(): () => void;
|
|
28
|
-
/** Are any holders currently suspending replicas? */
|
|
29
|
-
export declare function replicasSuspended(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Test-only escape hatch. Resets the counter to 0. Production code MUST
|
|
32
|
-
* NOT call this — use only the suspend/release pair to keep semantics
|
|
33
|
-
* tight. Exported under a `_` prefix and namespaced for tests.
|
|
34
|
-
*/
|
|
35
|
-
export declare function _resetSuspensionForTests(): void;
|
|
36
|
-
//# sourceMappingURL=suspension.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suspension.d.ts","sourceRoot":"","sources":["../../src/replica/suspension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,IAAI,CAQ5C;AAED,qDAAqD;AACrD,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* replica-suspension.ts — W12 — global replica-suspension counter.
|
|
3
|
-
*
|
|
4
|
-
* Per [~lambros/Feedback for DO read replication API](https://wiki.cfdata.org/display/~lambros/Feedback+for+DO+read+replication+API+based+on+D1+read+replication+beta)
|
|
5
|
-
* (cited in CF research §G.4), DO read replicas error with "Network
|
|
6
|
-
* connection lost" during high-volume writes. The recommended mitigation
|
|
7
|
-
* is to disable replicas before a write burst (npm install, git clone)
|
|
8
|
-
* and re-enable after.
|
|
9
|
-
*
|
|
10
|
-
* This module exposes a refcount-style suspend/release API. The counter
|
|
11
|
-
* is checked by `shouldDelegateToPrimary` (in `replica-routing.ts`):
|
|
12
|
-
* when `replicasSuspended() === true`, the replica forwards everything
|
|
13
|
-
* to the primary regardless of route policy.
|
|
14
|
-
*
|
|
15
|
-
* Phase 1 of W12 ships the module + the in-DO consultation. Phase 2
|
|
16
|
-
* (W12.5 if measured demand) wires the npm-installer / git-clone hooks.
|
|
17
|
-
* Today's behaviour: counter stays at 0 → replicas serve normally; the
|
|
18
|
-
* SPEC error path is observed as a graceful-degrade (replica's primary
|
|
19
|
-
* stub returns the error and the user sees a 5xx, same as today's
|
|
20
|
-
* single-region behaviour).
|
|
21
|
-
*/
|
|
22
|
-
let _suspendCount = 0;
|
|
23
|
-
/**
|
|
24
|
-
* Increment the suspension count. Returns a release function that
|
|
25
|
-
* decrements once (subsequent calls are no-ops). Suspends are nestable;
|
|
26
|
-
* any holder keeping the count > 0 keeps replicas suspended.
|
|
27
|
-
*/
|
|
28
|
-
export function suspendReplicas() {
|
|
29
|
-
_suspendCount++;
|
|
30
|
-
let released = false;
|
|
31
|
-
return () => {
|
|
32
|
-
if (released)
|
|
33
|
-
return;
|
|
34
|
-
released = true;
|
|
35
|
-
_suspendCount = Math.max(0, _suspendCount - 1);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/** Are any holders currently suspending replicas? */
|
|
39
|
-
export function replicasSuspended() {
|
|
40
|
-
return _suspendCount > 0;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Test-only escape hatch. Resets the counter to 0. Production code MUST
|
|
44
|
-
* NOT call this — use only the suspend/release pair to keep semantics
|
|
45
|
-
* tight. Exported under a `_` prefix and namespaced for tests.
|
|
46
|
-
*/
|
|
47
|
-
export function _resetSuspensionForTests() {
|
|
48
|
-
_suspendCount = 0;
|
|
49
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static-server.d.ts","sourceRoot":"","sources":["../../src/runtime/static-server.ts"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK7E;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAyH/D"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
function jsString(value) {
|
|
2
|
-
return JSON.stringify(value);
|
|
3
|
-
}
|
|
4
|
-
export function parsePort(value, fallback) {
|
|
5
|
-
if (!value)
|
|
6
|
-
return fallback;
|
|
7
|
-
const n = Number(value);
|
|
8
|
-
if (!Number.isInteger(n) || n <= 0 || n >= 65536)
|
|
9
|
-
return fallback;
|
|
10
|
-
return n;
|
|
11
|
-
}
|
|
12
|
-
export function createLiveStaticServerCode(root) {
|
|
13
|
-
const normalizedRoot = root.replace(/^\/+/, '').replace(/\/+$/, '') || 'home/user';
|
|
14
|
-
return `
|
|
15
|
-
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
16
|
-
|
|
17
|
-
const ROOT = ${jsString(normalizedRoot)};
|
|
18
|
-
const TEXT_TYPES = {
|
|
19
|
-
".html": "text/html; charset=utf-8",
|
|
20
|
-
".htm": "text/html; charset=utf-8",
|
|
21
|
-
".css": "text/css; charset=utf-8",
|
|
22
|
-
".js": "text/javascript; charset=utf-8",
|
|
23
|
-
".mjs": "text/javascript; charset=utf-8",
|
|
24
|
-
".json": "application/json; charset=utf-8",
|
|
25
|
-
".txt": "text/plain; charset=utf-8",
|
|
26
|
-
".md": "text/markdown; charset=utf-8",
|
|
27
|
-
".svg": "image/svg+xml; charset=utf-8",
|
|
28
|
-
".wasm": "application/wasm",
|
|
29
|
-
".png": "image/png",
|
|
30
|
-
".jpg": "image/jpeg",
|
|
31
|
-
".jpeg": "image/jpeg",
|
|
32
|
-
".gif": "image/gif",
|
|
33
|
-
".webp": "image/webp",
|
|
34
|
-
".ico": "image/x-icon",
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function disposeRpcResult(value) {
|
|
38
|
-
if ((typeof value !== "object" && typeof value !== "function") || value === null) return;
|
|
39
|
-
const dispose = value[Symbol.dispose];
|
|
40
|
-
if (typeof dispose === "function") { try { dispose.call(value); } catch {} }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function useRpcResult(promise, use) {
|
|
44
|
-
const value = await promise;
|
|
45
|
-
try { return await use(value); }
|
|
46
|
-
finally { disposeRpcResult(value); }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function cleanPath(pathname) {
|
|
50
|
-
const parts = [];
|
|
51
|
-
for (const raw of pathname.split("/")) {
|
|
52
|
-
if (!raw || raw === ".") continue;
|
|
53
|
-
if (raw === "..") { parts.pop(); continue; }
|
|
54
|
-
parts.push(raw);
|
|
55
|
-
}
|
|
56
|
-
return parts.join("/");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function joinRoot(rel) {
|
|
60
|
-
return rel ? ROOT + "/" + rel : ROOT;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function contentType(path) {
|
|
64
|
-
const idx = path.lastIndexOf(".");
|
|
65
|
-
const ext = idx >= 0 ? path.slice(idx).toLowerCase() : "";
|
|
66
|
-
return TEXT_TYPES[ext] || "application/octet-stream";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function htmlEscape(s) {
|
|
70
|
-
return String(s).replace(/[&<>"]/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[ch]));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function resolveFile(supervisor, rel) {
|
|
74
|
-
const base = joinRoot(rel);
|
|
75
|
-
const stat = await useRpcResult(supervisor.stat(base), (result) => result);
|
|
76
|
-
const isDirectory = stat && (stat.type === "directory" || stat.isDir || stat.isDirectory);
|
|
77
|
-
if (stat && !isDirectory) return { path: base, stat };
|
|
78
|
-
if (isDirectory) {
|
|
79
|
-
for (const index of ["index.html", "index.htm"]) {
|
|
80
|
-
const candidate = base.replace(/\\/+$/, "") + "/" + index;
|
|
81
|
-
const s = await useRpcResult(supervisor.stat(candidate), (result) => result);
|
|
82
|
-
if (s && !(s.type === "directory" || s.isDir || s.isDirectory)) return { path: candidate, stat: s };
|
|
83
|
-
}
|
|
84
|
-
return { directory: base };
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function renderDirectory(supervisor, path, rel, url) {
|
|
90
|
-
const entries = await useRpcResult(supervisor.readdir(path), (result) => result);
|
|
91
|
-
const rows = entries
|
|
92
|
-
.sort((a, b) => (a.type === b.type ? a.name.localeCompare(b.name) : a.type === "directory" ? -1 : 1))
|
|
93
|
-
.map((entry) => {
|
|
94
|
-
const suffix = entry.type === "directory" ? "/" : "";
|
|
95
|
-
const href = new URL(url);
|
|
96
|
-
href.pathname = href.pathname.replace(/\\/?$/, "/") + encodeURIComponent(entry.name) + suffix;
|
|
97
|
-
return '<li><a href="' + href.pathname + href.search + '">' + htmlEscape(entry.name + suffix) + '</a></li>';
|
|
98
|
-
})
|
|
99
|
-
.join("");
|
|
100
|
-
return new Response(
|
|
101
|
-
'<!doctype html><meta charset="utf-8"><title>Index of /' + htmlEscape(rel) + '</title>' +
|
|
102
|
-
'<h1>Index of /' + htmlEscape(rel) + '</h1><ul>' + rows + '</ul>',
|
|
103
|
-
{ headers: { "Content-Type": "text/html; charset=utf-8" } }
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default class NimbusStaticServer extends WorkerEntrypoint {
|
|
108
|
-
async fetch(request) {
|
|
109
|
-
return this.handleHttpRequest(request);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async handleHttpRequest(request) {
|
|
113
|
-
const supervisor = this.env && this.env.SUPERVISOR;
|
|
114
|
-
if (!supervisor) {
|
|
115
|
-
return new Response("Nimbus static server: SUPERVISOR binding missing", { status: 500 });
|
|
116
|
-
}
|
|
117
|
-
const url = new URL(request.url);
|
|
118
|
-
const rel = cleanPath(decodeURIComponent(url.pathname));
|
|
119
|
-
const resolved = await resolveFile(supervisor, rel);
|
|
120
|
-
if (!resolved) return new Response("Not found", { status: 404 });
|
|
121
|
-
if (resolved.directory) return renderDirectory(supervisor, resolved.directory, rel, url);
|
|
122
|
-
const bytes = await useRpcResult(supervisor.readFileBytes(resolved.path), (result) => result);
|
|
123
|
-
if (!bytes) return new Response("Not found", { status: 404 });
|
|
124
|
-
return new Response(bytes, {
|
|
125
|
-
headers: {
|
|
126
|
-
"Content-Type": contentType(resolved.path),
|
|
127
|
-
"Cache-Control": "no-store",
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
`;
|
|
133
|
-
}
|
package/scripts/clean-dist.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs';
|
|
2
|
-
import { dirname, resolve } from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
|
|
5
|
-
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
-
|
|
7
|
-
rmSync(resolve(packageRoot, 'dist'), { recursive: true, force: true });
|