everything-dev 1.53.2 → 2.0.0-rc.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 +2 -11
- package/dist/_virtual/_rolldown/runtime.cjs +17 -2
- package/dist/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/api/auth-middleware.cjs +161 -0
- package/dist/api/auth-middleware.cjs.map +1 -0
- package/dist/api/auth-middleware.d.cts +69 -0
- package/dist/api/auth-middleware.d.mts +69 -0
- package/dist/api/auth-middleware.mjs +160 -0
- package/dist/api/auth-middleware.mjs.map +1 -0
- package/dist/api-contract.cjs +250 -62
- package/dist/api-contract.cjs.map +1 -1
- package/dist/api-contract.mjs +246 -65
- package/dist/api-contract.mjs.map +1 -1
- package/dist/app.cjs +99 -26
- package/dist/app.cjs.map +1 -1
- package/dist/app.d.cts +3 -0
- package/dist/app.d.mts +3 -0
- package/dist/app.mjs +100 -27
- package/dist/app.mjs.map +1 -1
- package/dist/auth-login.cjs +163 -0
- package/dist/auth-login.cjs.map +1 -0
- package/dist/auth-login.mjs +162 -0
- package/dist/auth-login.mjs.map +1 -0
- package/dist/auth-session.cjs +64 -0
- package/dist/auth-session.cjs.map +1 -0
- package/dist/auth-session.mjs +58 -0
- package/dist/auth-session.mjs.map +1 -0
- package/dist/auth-types-gen.cjs +0 -1
- package/dist/auth-types-gen.cjs.map +1 -1
- package/dist/build.cjs +37 -173
- package/dist/build.cjs.map +1 -1
- package/dist/build.mjs +37 -171
- package/dist/build.mjs.map +1 -1
- package/dist/bundle-cache.cjs +74 -0
- package/dist/bundle-cache.cjs.map +1 -0
- package/dist/bundle-cache.d.cts +27 -0
- package/dist/bundle-cache.d.mts +27 -0
- package/dist/bundle-cache.mjs +68 -0
- package/dist/bundle-cache.mjs.map +1 -0
- package/dist/bundle-fs-resolve.cjs +209 -0
- package/dist/bundle-fs-resolve.cjs.map +1 -0
- package/dist/bundle-fs-resolve.d.cts +76 -0
- package/dist/bundle-fs-resolve.d.mts +76 -0
- package/dist/bundle-fs-resolve.mjs +202 -0
- package/dist/bundle-fs-resolve.mjs.map +1 -0
- package/dist/cdn-deploy.cjs +126 -0
- package/dist/cdn-deploy.cjs.map +1 -0
- package/dist/cdn-deploy.mjs +124 -0
- package/dist/cdn-deploy.mjs.map +1 -0
- package/dist/cli/db-doctor.cjs +19 -19
- package/dist/cli/db-doctor.cjs.map +1 -1
- package/dist/cli/db-doctor.mjs +18 -18
- package/dist/cli/db-doctor.mjs.map +1 -1
- package/dist/cli/db-repair.cjs +9 -32
- package/dist/cli/db-repair.cjs.map +1 -1
- package/dist/cli/db-repair.mjs +9 -32
- package/dist/cli/db-repair.mjs.map +1 -1
- package/dist/cli/framework-version.cjs +7 -3
- package/dist/cli/framework-version.cjs.map +1 -1
- package/dist/cli/framework-version.mjs +7 -3
- package/dist/cli/framework-version.mjs.map +1 -1
- package/dist/cli/infra.cjs +159 -251
- package/dist/cli/infra.cjs.map +1 -1
- package/dist/cli/infra.mjs +154 -242
- package/dist/cli/infra.mjs.map +1 -1
- package/dist/cli/init.cjs +624 -196
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts +61 -8
- package/dist/cli/init.d.mts +61 -8
- package/dist/cli/init.mjs +613 -194
- package/dist/cli/init.mjs.map +1 -1
- package/dist/cli/parse.cjs +8 -7
- package/dist/cli/parse.cjs.map +1 -1
- package/dist/cli/parse.mjs +9 -7
- package/dist/cli/parse.mjs.map +1 -1
- package/dist/cli/prompts.cjs +14 -1
- package/dist/cli/prompts.cjs.map +1 -1
- package/dist/cli/prompts.mjs +14 -1
- package/dist/cli/prompts.mjs.map +1 -1
- package/dist/cli/prune.cjs +220 -0
- package/dist/cli/prune.cjs.map +1 -0
- package/dist/cli/prune.mjs +220 -0
- package/dist/cli/prune.mjs.map +1 -0
- package/dist/cli/snapshot.cjs +2 -1
- package/dist/cli/snapshot.cjs.map +1 -1
- package/dist/cli/snapshot.mjs +2 -1
- package/dist/cli/snapshot.mjs.map +1 -1
- package/dist/cli/status.cjs +5 -4
- package/dist/cli/status.cjs.map +1 -1
- package/dist/cli/status.mjs +6 -5
- package/dist/cli/status.mjs.map +1 -1
- package/dist/cli/sync.cjs +156 -58
- package/dist/cli/sync.cjs.map +1 -1
- package/dist/cli/sync.mjs +158 -63
- package/dist/cli/sync.mjs.map +1 -1
- package/dist/cli/timing.cjs +0 -1
- package/dist/cli/timing.cjs.map +1 -1
- package/dist/cli/upgrade.cjs +95 -69
- package/dist/cli/upgrade.cjs.map +1 -1
- package/dist/cli/upgrade.mjs +97 -72
- package/dist/cli/upgrade.mjs.map +1 -1
- package/dist/cli/utils/helpers.cjs.map +1 -1
- package/dist/cli.cjs +320 -72
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +316 -68
- package/dist/cli.mjs.map +1 -1
- package/dist/code-artifacts.cjs +76 -8
- package/dist/code-artifacts.cjs.map +1 -1
- package/dist/code-artifacts.mjs +76 -10
- package/dist/code-artifacts.mjs.map +1 -1
- package/dist/commands/build.cjs +65 -0
- package/dist/commands/build.cjs.map +1 -0
- package/dist/commands/build.mjs +65 -0
- package/dist/commands/build.mjs.map +1 -0
- package/dist/commands/config.cjs +77 -0
- package/dist/commands/config.cjs.map +1 -0
- package/dist/commands/config.d.cts +8 -0
- package/dist/commands/config.d.mts +8 -0
- package/dist/commands/config.mjs +74 -0
- package/dist/commands/config.mjs.map +1 -0
- package/dist/commands/db.cjs +107 -0
- package/dist/commands/db.cjs.map +1 -0
- package/dist/commands/db.mjs +107 -0
- package/dist/commands/db.mjs.map +1 -0
- package/dist/commands/deploy.cjs +336 -0
- package/dist/commands/deploy.cjs.map +1 -0
- package/dist/commands/deploy.mjs +334 -0
- package/dist/commands/deploy.mjs.map +1 -0
- package/dist/commands/dev.cjs +75 -0
- package/dist/commands/dev.cjs.map +1 -0
- package/dist/commands/dev.mjs +73 -0
- package/dist/commands/dev.mjs.map +1 -0
- package/dist/commands/init.cjs +234 -0
- package/dist/commands/init.cjs.map +1 -0
- package/dist/commands/init.mjs +231 -0
- package/dist/commands/init.mjs.map +1 -0
- package/dist/commands/keys.cjs +255 -0
- package/dist/commands/keys.cjs.map +1 -0
- package/dist/commands/keys.mjs +253 -0
- package/dist/commands/keys.mjs.map +1 -0
- package/dist/commands/ops.cjs +199 -0
- package/dist/commands/ops.cjs.map +1 -0
- package/dist/commands/ops.mjs +197 -0
- package/dist/commands/ops.mjs.map +1 -0
- package/dist/commands/plugins.cjs +211 -0
- package/dist/commands/plugins.cjs.map +1 -0
- package/dist/commands/plugins.mjs +211 -0
- package/dist/commands/plugins.mjs.map +1 -0
- package/dist/commands/shared.cjs +8 -0
- package/dist/commands/shared.cjs.map +1 -0
- package/dist/commands/shared.d.cts +6 -0
- package/dist/commands/shared.d.mts +6 -0
- package/dist/commands/shared.mjs +8 -0
- package/dist/commands/shared.mjs.map +1 -0
- package/dist/commands/upgrade.cjs +325 -0
- package/dist/commands/upgrade.cjs.map +1 -0
- package/dist/commands/upgrade.mjs +323 -0
- package/dist/commands/upgrade.mjs.map +1 -0
- package/dist/components/dev-render.cjs +340 -0
- package/dist/components/dev-render.cjs.map +1 -0
- package/dist/components/dev-render.mjs +332 -0
- package/dist/components/dev-render.mjs.map +1 -0
- package/dist/config.cjs +460 -221
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +491 -48
- package/dist/config.d.mts +491 -48
- package/dist/config.mjs +439 -212
- package/dist/config.mjs.map +1 -1
- package/dist/contract.cjs +327 -50
- package/dist/contract.cjs.map +1 -1
- package/dist/contract.d.cts +1951 -1062
- package/dist/contract.d.mts +1951 -1062
- package/dist/contract.meta.cjs +107 -12
- package/dist/contract.meta.cjs.map +1 -1
- package/dist/contract.meta.d.cts +166 -8
- package/dist/contract.meta.d.mts +166 -8
- package/dist/contract.meta.mjs +107 -11
- package/dist/contract.meta.mjs.map +1 -1
- package/dist/contract.mjs +580 -327
- package/dist/contract.mjs.map +1 -1
- package/dist/dag.cjs +5 -3
- package/dist/dag.cjs.map +1 -1
- package/dist/dag.mjs +6 -3
- package/dist/dag.mjs.map +1 -1
- package/dist/db/binding.cjs +80 -0
- package/dist/db/binding.cjs.map +1 -0
- package/dist/db/binding.d.cts +39 -0
- package/dist/db/binding.d.mts +39 -0
- package/dist/db/binding.mjs +78 -0
- package/dist/db/binding.mjs.map +1 -0
- package/dist/db/bindings.cjs +78 -0
- package/dist/db/bindings.cjs.map +1 -0
- package/dist/db/bindings.d.cts +34 -0
- package/dist/db/bindings.d.mts +34 -0
- package/dist/db/bindings.mjs +76 -0
- package/dist/db/bindings.mjs.map +1 -0
- package/dist/db/core.cjs +204 -0
- package/dist/db/core.cjs.map +1 -0
- package/dist/db/core.d.cts +69 -0
- package/dist/db/core.d.mts +69 -0
- package/dist/db/core.mjs +192 -0
- package/dist/db/core.mjs.map +1 -0
- package/dist/db/driver.cjs +167 -0
- package/dist/db/driver.cjs.map +1 -0
- package/dist/db/driver.d.cts +50 -0
- package/dist/db/driver.d.mts +50 -0
- package/dist/db/driver.mjs +165 -0
- package/dist/db/driver.mjs.map +1 -0
- package/dist/db/drizzle-kit.cjs +177 -0
- package/dist/db/drizzle-kit.cjs.map +1 -0
- package/dist/db/drizzle-kit.d.cts +25 -0
- package/dist/db/drizzle-kit.d.mts +25 -0
- package/dist/db/drizzle-kit.mjs +175 -0
- package/dist/db/drizzle-kit.mjs.map +1 -0
- package/dist/db/errors.cjs +27 -0
- package/dist/db/errors.cjs.map +1 -0
- package/dist/db/errors.d.cts +16 -0
- package/dist/db/errors.d.mts +16 -0
- package/dist/db/errors.mjs +26 -0
- package/dist/db/errors.mjs.map +1 -0
- package/dist/db/identity.cjs +55 -0
- package/dist/db/identity.cjs.map +1 -0
- package/dist/db/identity.d.cts +40 -0
- package/dist/db/identity.d.mts +40 -0
- package/dist/db/identity.mjs +53 -0
- package/dist/db/identity.mjs.map +1 -0
- package/dist/db/index.cjs +43 -0
- package/dist/db/index.d.cts +9 -0
- package/dist/db/index.d.mts +9 -0
- package/dist/db/index.mjs +10 -0
- package/dist/db/run-migrations.cjs +343 -0
- package/dist/db/run-migrations.cjs.map +1 -0
- package/dist/db/run-migrations.d.cts +87 -0
- package/dist/db/run-migrations.d.mts +87 -0
- package/dist/db/run-migrations.mjs +341 -0
- package/dist/db/run-migrations.mjs.map +1 -0
- package/dist/delegate-signer.cjs +85 -0
- package/dist/delegate-signer.cjs.map +1 -0
- package/dist/delegate-signer.mjs +84 -0
- package/dist/delegate-signer.mjs.map +1 -0
- package/dist/deploy-diff.cjs +119 -0
- package/dist/deploy-diff.cjs.map +1 -0
- package/dist/deploy-diff.mjs +109 -0
- package/dist/deploy-diff.mjs.map +1 -0
- package/dist/descriptor/constructors.cjs +49 -0
- package/dist/descriptor/constructors.cjs.map +1 -0
- package/dist/descriptor/constructors.d.cts +27 -0
- package/dist/descriptor/constructors.d.mts +27 -0
- package/dist/descriptor/constructors.mjs +45 -0
- package/dist/descriptor/constructors.mjs.map +1 -0
- package/dist/descriptor/index.cjs +24 -0
- package/dist/descriptor/index.d.cts +5 -0
- package/dist/descriptor/index.d.mts +5 -0
- package/dist/descriptor/index.mjs +6 -0
- package/dist/descriptor/resolve.cjs +258 -0
- package/dist/descriptor/resolve.cjs.map +1 -0
- package/dist/descriptor/resolve.d.cts +50 -0
- package/dist/descriptor/resolve.d.mts +50 -0
- package/dist/descriptor/resolve.mjs +252 -0
- package/dist/descriptor/resolve.mjs.map +1 -0
- package/dist/descriptor/schema.cjs +109 -0
- package/dist/descriptor/schema.cjs.map +1 -0
- package/dist/descriptor/schema.d.cts +217 -0
- package/dist/descriptor/schema.d.mts +217 -0
- package/dist/descriptor/schema.mjs +102 -0
- package/dist/descriptor/schema.mjs.map +1 -0
- package/dist/descriptor/serialize.cjs +45 -0
- package/dist/descriptor/serialize.cjs.map +1 -0
- package/dist/descriptor/serialize.d.cts +7 -0
- package/dist/descriptor/serialize.d.mts +7 -0
- package/dist/descriptor/serialize.mjs +45 -0
- package/dist/descriptor/serialize.mjs.map +1 -0
- package/dist/dev-log-pipeline.cjs +273 -0
- package/dist/dev-log-pipeline.cjs.map +1 -0
- package/dist/dev-log-pipeline.mjs +267 -0
- package/dist/dev-log-pipeline.mjs.map +1 -0
- package/dist/dev-logs.cjs +39 -8
- package/dist/dev-logs.cjs.map +1 -1
- package/dist/dev-logs.mjs +37 -9
- package/dist/dev-logs.mjs.map +1 -1
- package/dist/dev-program.cjs +405 -0
- package/dist/dev-program.cjs.map +1 -0
- package/dist/dev-program.d.cts +10 -0
- package/dist/dev-program.d.mts +10 -0
- package/dist/dev-program.mjs +395 -0
- package/dist/dev-program.mjs.map +1 -0
- package/dist/dev-session-data.d.cts +27 -0
- package/dist/dev-session-data.d.mts +27 -0
- package/dist/dev-session.cjs +178 -105
- package/dist/dev-session.cjs.map +1 -1
- package/dist/dev-session.mjs +180 -105
- package/dist/dev-session.mjs.map +1 -1
- package/dist/env/process-env.cjs +16 -0
- package/dist/env/process-env.cjs.map +1 -0
- package/dist/env/process-env.mjs +13 -0
- package/dist/env/process-env.mjs.map +1 -0
- package/dist/env/project-env.cjs +144 -0
- package/dist/env/project-env.cjs.map +1 -0
- package/dist/env/project-env.d.cts +1 -0
- package/dist/env/project-env.d.mts +1 -0
- package/dist/env/project-env.mjs +132 -0
- package/dist/env/project-env.mjs.map +1 -0
- package/dist/fastkv.cjs +59 -12
- package/dist/fastkv.cjs.map +1 -1
- package/dist/fastkv.d.cts +42 -6
- package/dist/fastkv.d.mts +42 -6
- package/dist/fastkv.mjs +58 -13
- package/dist/fastkv.mjs.map +1 -1
- package/dist/fingerprint.cjs +57 -0
- package/dist/fingerprint.cjs.map +1 -0
- package/dist/fingerprint.d.cts +14 -0
- package/dist/fingerprint.d.mts +14 -0
- package/dist/fingerprint.mjs +55 -0
- package/dist/fingerprint.mjs.map +1 -0
- package/dist/http-client.cjs +17 -17
- package/dist/http-client.cjs.map +1 -1
- package/dist/http-client.mjs +17 -17
- package/dist/http-client.mjs.map +1 -1
- package/dist/image-deploy.cjs +186 -0
- package/dist/image-deploy.cjs.map +1 -0
- package/dist/image-deploy.mjs +182 -0
- package/dist/image-deploy.mjs.map +1 -0
- package/dist/index.cjs +66 -18
- package/dist/index.d.cts +8 -7
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +6 -5
- package/dist/infra/docker.cjs +77 -0
- package/dist/infra/docker.cjs.map +1 -0
- package/dist/infra/docker.d.cts +10 -0
- package/dist/infra/docker.d.mts +10 -0
- package/dist/infra/docker.mjs +69 -0
- package/dist/infra/docker.mjs.map +1 -0
- package/dist/infra/materializer.cjs +74 -0
- package/dist/infra/materializer.cjs.map +1 -0
- package/dist/infra/materializer.mjs +70 -0
- package/dist/infra/materializer.mjs.map +1 -0
- package/dist/infra/planner.cjs +135 -103
- package/dist/infra/planner.cjs.map +1 -1
- package/dist/infra/planner.mjs +137 -104
- package/dist/infra/planner.mjs.map +1 -1
- package/dist/infra/port-ownership.cjs +57 -0
- package/dist/infra/port-ownership.cjs.map +1 -0
- package/dist/infra/port-ownership.mjs +57 -0
- package/dist/infra/port-ownership.mjs.map +1 -0
- package/dist/infra/preflight.cjs +45 -33
- package/dist/infra/preflight.cjs.map +1 -1
- package/dist/infra/preflight.d.cts +1 -0
- package/dist/infra/preflight.d.mts +1 -0
- package/dist/infra/preflight.mjs +46 -34
- package/dist/infra/preflight.mjs.map +1 -1
- package/dist/infra/types.cjs.map +1 -1
- package/dist/infra/types.d.cts +2 -0
- package/dist/infra/types.d.mts +2 -0
- package/dist/infra/types.mjs.map +1 -1
- package/dist/integrity.cjs +50 -61
- package/dist/integrity.cjs.map +1 -1
- package/dist/integrity.d.cts +16 -10
- package/dist/integrity.d.mts +16 -10
- package/dist/integrity.mjs +50 -59
- package/dist/integrity.mjs.map +1 -1
- package/dist/internal/manifest-normalizer.cjs +8 -2
- package/dist/internal/manifest-normalizer.cjs.map +1 -1
- package/dist/internal/manifest-normalizer.mjs +9 -3
- package/dist/internal/manifest-normalizer.mjs.map +1 -1
- package/dist/merge.cjs +19 -1
- package/dist/merge.cjs.map +1 -1
- package/dist/merge.d.cts +1 -1
- package/dist/merge.d.mts +1 -1
- package/dist/merge.mjs +19 -2
- package/dist/merge.mjs.map +1 -1
- package/dist/mf.cjs +190 -3
- package/dist/mf.cjs.map +1 -1
- package/dist/mf.d.cts +24 -2
- package/dist/mf.d.mts +24 -2
- package/dist/mf.mjs +189 -4
- package/dist/mf.mjs.map +1 -1
- package/dist/near-cli.cjs +59 -91
- package/dist/near-cli.cjs.map +1 -1
- package/dist/near-cli.mjs +58 -90
- package/dist/near-cli.mjs.map +1 -1
- package/dist/near-signer.cjs +73 -0
- package/dist/near-signer.cjs.map +1 -0
- package/dist/near-signer.mjs +70 -0
- package/dist/near-signer.mjs.map +1 -0
- package/dist/network.cjs +0 -1
- package/dist/network.cjs.map +1 -1
- package/dist/orchestrator.cjs +256 -87
- package/dist/orchestrator.cjs.map +1 -1
- package/dist/orchestrator.mjs +248 -87
- package/dist/orchestrator.mjs.map +1 -1
- package/dist/platform-deploy.cjs +81 -0
- package/dist/platform-deploy.cjs.map +1 -0
- package/dist/platform-deploy.mjs +80 -0
- package/dist/platform-deploy.mjs.map +1 -0
- package/dist/plugin.cjs +54 -1389
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +6 -896
- package/dist/plugin.d.mts +6 -896
- package/dist/plugin.mjs +53 -1387
- package/dist/plugin.mjs.map +1 -1
- package/dist/process-kill.cjs +44 -0
- package/dist/process-kill.cjs.map +1 -0
- package/dist/process-kill.mjs +43 -0
- package/dist/process-kill.mjs.map +1 -0
- package/dist/process-registry.cjs +64 -9
- package/dist/process-registry.cjs.map +1 -1
- package/dist/process-registry.mjs +61 -10
- package/dist/process-registry.mjs.map +1 -1
- package/dist/progress.cjs +45 -0
- package/dist/progress.cjs.map +1 -0
- package/dist/progress.d.cts +13 -0
- package/dist/progress.d.mts +13 -0
- package/dist/progress.mjs +42 -0
- package/dist/progress.mjs.map +1 -0
- package/dist/publish.cjs +513 -79
- package/dist/publish.cjs.map +1 -1
- package/dist/publish.mjs +515 -82
- package/dist/publish.mjs.map +1 -1
- package/dist/registry-use.cjs +41 -0
- package/dist/registry-use.cjs.map +1 -0
- package/dist/registry-use.mjs +40 -0
- package/dist/registry-use.mjs.map +1 -0
- package/dist/resolution/session.cjs +335 -0
- package/dist/resolution/session.cjs.map +1 -0
- package/dist/resolution/session.d.cts +105 -0
- package/dist/resolution/session.d.mts +105 -0
- package/dist/resolution/session.mjs +331 -0
- package/dist/resolution/session.mjs.map +1 -0
- package/dist/rollback.cjs +131 -0
- package/dist/rollback.cjs.map +1 -0
- package/dist/rollback.mjs +128 -0
- package/dist/rollback.mjs.map +1 -0
- package/dist/sdk.cjs +7 -7
- package/dist/sdk.d.cts +3 -3
- package/dist/sdk.d.mts +3 -3
- package/dist/sdk.mjs +2 -2
- package/dist/service-descriptor.cjs +67 -34
- package/dist/service-descriptor.cjs.map +1 -1
- package/dist/service-descriptor.d.cts +4 -1
- package/dist/service-descriptor.d.mts +3 -0
- package/dist/service-descriptor.mjs +63 -35
- package/dist/service-descriptor.mjs.map +1 -1
- package/dist/shared-deps.cjs +17 -16
- package/dist/shared-deps.cjs.map +1 -1
- package/dist/shared-deps.mjs +17 -16
- package/dist/shared-deps.mjs.map +1 -1
- package/dist/start-config-source.cjs +24 -0
- package/dist/start-config-source.cjs.map +1 -0
- package/dist/start-config-source.d.cts +29 -0
- package/dist/start-config-source.d.mts +29 -0
- package/dist/start-config-source.mjs +22 -0
- package/dist/start-config-source.mjs.map +1 -0
- package/dist/storage-upload.cjs +145 -0
- package/dist/storage-upload.cjs.map +1 -0
- package/dist/storage-upload.mjs +143 -0
- package/dist/storage-upload.mjs.map +1 -0
- package/dist/types.cjs +126 -20
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +867 -585
- package/dist/types.d.mts +867 -585
- package/dist/types.mjs +307 -208
- package/dist/types.mjs.map +1 -1
- package/dist/ui/api.cjs +105 -0
- package/dist/ui/api.cjs.map +1 -0
- package/dist/ui/api.d.cts +31 -0
- package/dist/ui/api.d.mts +31 -0
- package/dist/ui/api.mjs +99 -0
- package/dist/ui/api.mjs.map +1 -0
- package/dist/ui/auth-guards.cjs +50 -0
- package/dist/ui/auth-guards.cjs.map +1 -0
- package/dist/ui/auth-guards.d.cts +39 -0
- package/dist/ui/auth-guards.d.mts +39 -0
- package/dist/ui/auth-guards.mjs +48 -0
- package/dist/ui/auth-guards.mjs.map +1 -0
- package/dist/ui/auth.cjs +197 -0
- package/dist/ui/auth.cjs.map +1 -0
- package/dist/ui/auth.d.cts +56 -0
- package/dist/ui/auth.d.mts +56 -0
- package/dist/ui/auth.mjs +179 -0
- package/dist/ui/auth.mjs.map +1 -0
- package/dist/ui/entry.cjs +16 -0
- package/dist/ui/entry.cjs.map +1 -0
- package/dist/ui/entry.d.cts +12 -0
- package/dist/ui/entry.d.mts +12 -0
- package/dist/ui/entry.mjs +15 -0
- package/dist/ui/entry.mjs.map +1 -0
- package/dist/ui/head.cjs +14 -7
- package/dist/ui/head.cjs.map +1 -1
- package/dist/ui/head.mjs +15 -7
- package/dist/ui/head.mjs.map +1 -1
- package/dist/ui/hydrate.cjs +265 -0
- package/dist/ui/hydrate.cjs.map +1 -0
- package/dist/ui/hydrate.d.cts +48 -0
- package/dist/ui/hydrate.d.mts +48 -0
- package/dist/ui/hydrate.mjs +263 -0
- package/dist/ui/hydrate.mjs.map +1 -0
- package/dist/ui/i18n.cjs +153 -0
- package/dist/ui/i18n.cjs.map +1 -0
- package/dist/ui/i18n.d.cts +29 -0
- package/dist/ui/i18n.d.mts +29 -0
- package/dist/ui/i18n.mjs +140 -0
- package/dist/ui/i18n.mjs.map +1 -0
- package/dist/ui/index.cjs +19 -1
- package/dist/ui/index.d.cts +6 -3
- package/dist/ui/index.d.mts +6 -3
- package/dist/ui/index.mjs +5 -2
- package/dist/ui/locale.cjs +53 -0
- package/dist/ui/locale.cjs.map +1 -0
- package/dist/ui/locale.d.cts +18 -0
- package/dist/ui/locale.d.mts +18 -0
- package/dist/ui/locale.mjs +49 -0
- package/dist/ui/locale.mjs.map +1 -0
- package/dist/ui/manifest/index.cjs +25 -0
- package/dist/ui/manifest/index.cjs.map +1 -0
- package/dist/ui/manifest/index.d.cts +9 -0
- package/dist/ui/manifest/index.d.mts +9 -0
- package/dist/ui/manifest/index.mjs +13 -0
- package/dist/ui/manifest/index.mjs.map +1 -0
- package/dist/ui/manifest-generator.cjs +8 -0
- package/dist/ui/manifest-generator.d.cts +1 -0
- package/dist/ui/manifest-generator.d.mts +1 -0
- package/dist/ui/manifest-generator.mjs +3 -0
- package/dist/ui/message-catalogs.cjs +8 -0
- package/dist/ui/message-catalogs.cjs.map +1 -0
- package/dist/ui/message-catalogs.d.cts +5 -0
- package/dist/ui/message-catalogs.d.mts +5 -0
- package/dist/ui/message-catalogs.mjs +8 -0
- package/dist/ui/message-catalogs.mjs.map +1 -0
- package/dist/ui/metadata.cjs +0 -1
- package/dist/ui/metadata.cjs.map +1 -1
- package/dist/ui/metadata.d.cts +1 -1
- package/dist/ui/metadata.d.mts +1 -1
- package/dist/ui/plugin-path.cjs +37 -0
- package/dist/ui/plugin-path.cjs.map +1 -0
- package/dist/ui/plugin-path.d.cts +25 -0
- package/dist/ui/plugin-path.d.mts +25 -0
- package/dist/ui/plugin-path.mjs +35 -0
- package/dist/ui/plugin-path.mjs.map +1 -0
- package/dist/ui/router-client.cjs +61 -0
- package/dist/ui/router-client.cjs.map +1 -0
- package/dist/ui/router-client.d.cts +20 -0
- package/dist/ui/router-client.d.mts +20 -0
- package/dist/ui/router-client.mjs +60 -0
- package/dist/ui/router-client.mjs.map +1 -0
- package/dist/ui/router-defaults.cjs +48 -0
- package/dist/ui/router-defaults.cjs.map +1 -0
- package/dist/ui/router-defaults.d.cts +8 -0
- package/dist/ui/router-defaults.d.mts +8 -0
- package/dist/ui/router-defaults.mjs +45 -0
- package/dist/ui/router-defaults.mjs.map +1 -0
- package/dist/ui/router-error.cjs +70 -0
- package/dist/ui/router-error.cjs.map +1 -0
- package/dist/ui/router-error.d.cts +19 -0
- package/dist/ui/router-error.d.mts +19 -0
- package/dist/ui/router-error.mjs +69 -0
- package/dist/ui/router-error.mjs.map +1 -0
- package/dist/ui/router-server.cjs +153 -0
- package/dist/ui/router-server.cjs.map +1 -0
- package/dist/ui/router-server.d.cts +38 -0
- package/dist/ui/router-server.d.mts +38 -0
- package/dist/ui/router-server.mjs +152 -0
- package/dist/ui/router-server.mjs.map +1 -0
- package/dist/ui/router.cjs +4 -16
- package/dist/ui/router.cjs.map +1 -1
- package/dist/ui/router.mjs +4 -15
- package/dist/ui/router.mjs.map +1 -1
- package/dist/ui/runtime.cjs +5 -1
- package/dist/ui/runtime.cjs.map +1 -1
- package/dist/ui/runtime.d.cts +2 -1
- package/dist/ui/runtime.d.mts +2 -1
- package/dist/ui/runtime.mjs +5 -1
- package/dist/ui/runtime.mjs.map +1 -1
- package/dist/ui/slot.cjs +34 -0
- package/dist/ui/slot.cjs.map +1 -0
- package/dist/ui/slot.d.cts +43 -0
- package/dist/ui/slot.d.mts +43 -0
- package/dist/ui/slot.mjs +34 -0
- package/dist/ui/slot.mjs.map +1 -0
- package/dist/ui/tenant.cjs +300 -0
- package/dist/ui/tenant.cjs.map +1 -0
- package/dist/ui/tenant.d.cts +122 -0
- package/dist/ui/tenant.d.mts +122 -0
- package/dist/ui/tenant.mjs +279 -0
- package/dist/ui/tenant.mjs.map +1 -0
- package/dist/ui/types.d.cts +32 -2
- package/dist/ui/types.d.mts +32 -2
- package/dist/ui/version-check.cjs +47 -0
- package/dist/ui/version-check.cjs.map +1 -0
- package/dist/ui/version-check.d.cts +23 -0
- package/dist/ui/version-check.d.mts +23 -0
- package/dist/ui/version-check.mjs +46 -0
- package/dist/ui/version-check.mjs.map +1 -0
- package/dist/utils/banner.cjs +2 -2
- package/dist/utils/banner.cjs.map +1 -1
- package/dist/utils/banner.mjs +2 -2
- package/dist/utils/banner.mjs.map +1 -1
- package/dist/utils/linkify.cjs +1 -1
- package/dist/utils/linkify.cjs.map +1 -1
- package/dist/utils/linkify.mjs +1 -0
- package/dist/utils/linkify.mjs.map +1 -1
- package/dist/utils/run.cjs +6 -6
- package/dist/utils/run.cjs.map +1 -1
- package/dist/utils/run.mjs +6 -6
- package/dist/utils/run.mjs.map +1 -1
- package/dist/utils/save-config.cjs +12 -0
- package/dist/utils/save-config.cjs.map +1 -1
- package/dist/utils/save-config.mjs +12 -0
- package/dist/utils/save-config.mjs.map +1 -1
- package/dist/utils/snapshot-hash.cjs +10 -0
- package/dist/utils/snapshot-hash.cjs.map +1 -0
- package/dist/utils/snapshot-hash.mjs +10 -0
- package/dist/utils/snapshot-hash.mjs.map +1 -0
- package/dist/utils/string.cjs +0 -1
- package/dist/utils/string.cjs.map +1 -1
- package/dist/utils/theme.cjs +30 -12
- package/dist/utils/theme.cjs.map +1 -1
- package/dist/utils/theme.mjs +30 -11
- package/dist/utils/theme.mjs.map +1 -1
- package/dist/version-manifest-deploy.cjs +50 -0
- package/dist/version-manifest-deploy.cjs.map +1 -0
- package/dist/version-manifest-deploy.mjs +49 -0
- package/dist/version-manifest-deploy.mjs.map +1 -0
- package/dist/version-manifest-resolve.cjs +42 -0
- package/dist/version-manifest-resolve.cjs.map +1 -0
- package/dist/version-manifest-resolve.d.cts +38 -0
- package/dist/version-manifest-resolve.d.mts +38 -0
- package/dist/version-manifest-resolve.mjs +40 -0
- package/dist/version-manifest-resolve.mjs.map +1 -0
- package/dist/version-status.cjs +18 -0
- package/dist/version-status.cjs.map +1 -0
- package/dist/version-status.d.cts +22 -0
- package/dist/version-status.d.mts +22 -0
- package/dist/version-status.mjs +17 -0
- package/dist/version-status.mjs.map +1 -0
- package/dist/workspace-catalog.cjs +53 -0
- package/dist/workspace-catalog.cjs.map +1 -0
- package/dist/workspace-catalog.mjs +51 -0
- package/dist/workspace-catalog.mjs.map +1 -0
- package/dist/workspace.cjs +237 -0
- package/dist/workspace.cjs.map +1 -0
- package/dist/workspace.mjs +233 -0
- package/dist/workspace.mjs.map +1 -0
- package/package.json +179 -27
- package/skills/add-a-route/SKILL.md +132 -0
- package/skills/api-and-auth/SKILL.md +87 -21
- package/skills/api-and-auth/references/middleware.md +1 -1
- package/skills/cli-reference/SKILL.md +48 -21
- package/skills/code-style/SKILL.md +8 -0
- package/skills/dev-workflow/SKILL.md +50 -26
- package/skills/extends-config/SKILL.md +31 -19
- package/skills/init-upgrade/SKILL.md +29 -16
- package/skills/plugin-development/SKILL.md +46 -112
- package/skills/plugin-development/references/database.md +82 -0
- package/skills/plugin-development/references/request-context.md +67 -0
- package/skills/publish-sync/SKILL.md +99 -22
- package/skills/registry/SKILL.md +82 -0
- package/skills/super-app/SKILL.md +25 -15
- package/skills/talk-to-the-app/SKILL.md +138 -0
- package/skills/ui-integration/SKILL.md +93 -11
- package/dist/cli/db-studio.cjs +0 -131
- package/dist/cli/db-studio.cjs.map +0 -1
- package/dist/cli/db-studio.mjs +0 -127
- package/dist/cli/db-studio.mjs.map +0 -1
- package/dist/cli/init.d.cts.map +0 -1
- package/dist/cli/init.d.mts.map +0 -1
- package/dist/components/dev-view.cjs +0 -309
- package/dist/components/dev-view.cjs.map +0 -1
- package/dist/components/dev-view.mjs +0 -309
- package/dist/components/dev-view.mjs.map +0 -1
- package/dist/components/streaming-view.cjs +0 -134
- package/dist/components/streaming-view.cjs.map +0 -1
- package/dist/components/streaming-view.mjs +0 -132
- package/dist/components/streaming-view.mjs.map +0 -1
- package/dist/config.d.cts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/contract.d.cts.map +0 -1
- package/dist/contract.d.mts.map +0 -1
- package/dist/contract.meta.d.cts.map +0 -1
- package/dist/contract.meta.d.mts.map +0 -1
- package/dist/dag.d.cts.map +0 -1
- package/dist/dag.d.mts.map +0 -1
- package/dist/db.cjs +0 -81
- package/dist/db.cjs.map +0 -1
- package/dist/db.d.cts +0 -30
- package/dist/db.d.cts.map +0 -1
- package/dist/db.d.mts +0 -30
- package/dist/db.d.mts.map +0 -1
- package/dist/db.mjs +0 -75
- package/dist/db.mjs.map +0 -1
- package/dist/fastkv.d.cts.map +0 -1
- package/dist/fastkv.d.mts.map +0 -1
- package/dist/integrity.d.cts.map +0 -1
- package/dist/integrity.d.mts.map +0 -1
- package/dist/merge.d.cts.map +0 -1
- package/dist/merge.d.mts.map +0 -1
- package/dist/mf.d.cts.map +0 -1
- package/dist/mf.d.mts.map +0 -1
- package/dist/plugin.d.cts.map +0 -1
- package/dist/plugin.d.mts.map +0 -1
- package/dist/service-descriptor.d.cts.map +0 -1
- package/dist/service-descriptor.d.mts.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/ui/head.d.cts.map +0 -1
- package/dist/ui/head.d.mts.map +0 -1
- package/dist/ui/metadata.d.cts.map +0 -1
- package/dist/ui/metadata.d.mts.map +0 -1
- package/dist/ui/router.d.cts.map +0 -1
- package/dist/ui/router.d.mts.map +0 -1
- package/dist/ui/runtime.d.cts.map +0 -1
- package/dist/ui/runtime.d.mts.map +0 -1
- package/dist/ui/types.d.cts.map +0 -1
- package/dist/ui/types.d.mts.map +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_config = require('./config.cjs');
|
|
4
|
+
const require_bundle_cache = require('./bundle-cache.cjs');
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_runtime.__toESM(node_path, 1);
|
|
8
|
+
let effect = require("effect");
|
|
9
|
+
let node_fs_promises = require("node:fs/promises");
|
|
10
|
+
let every_plugin_build_artifact_names = require("every-plugin/build/artifact-names");
|
|
11
|
+
|
|
12
|
+
//#region src/bundle-fs-resolve.ts
|
|
13
|
+
var BundleReadError = class extends effect.Schema.TaggedError()("BundleReadError", {
|
|
14
|
+
path: effect.Schema.String,
|
|
15
|
+
cause: effect.Schema.optional(effect.Schema.Unknown)
|
|
16
|
+
}) {};
|
|
17
|
+
const MIME_TYPES = {
|
|
18
|
+
".js": "text/javascript",
|
|
19
|
+
".mjs": "text/javascript",
|
|
20
|
+
".cjs": "text/javascript",
|
|
21
|
+
".css": "text/css",
|
|
22
|
+
".json": "application/json",
|
|
23
|
+
".map": "application/json",
|
|
24
|
+
".svg": "image/svg+xml",
|
|
25
|
+
".png": "image/png",
|
|
26
|
+
".jpg": "image/jpeg",
|
|
27
|
+
".jpeg": "image/jpeg",
|
|
28
|
+
".gif": "image/gif",
|
|
29
|
+
".webp": "image/webp",
|
|
30
|
+
".avif": "image/avif",
|
|
31
|
+
".ico": "image/x-icon",
|
|
32
|
+
".html": "text/html",
|
|
33
|
+
".htm": "text/html",
|
|
34
|
+
".webmanifest": "application/manifest+json",
|
|
35
|
+
".md": "text/markdown",
|
|
36
|
+
".ts": "text/plain",
|
|
37
|
+
".woff": "font/woff",
|
|
38
|
+
".woff2": "font/woff2",
|
|
39
|
+
".ttf": "font/ttf",
|
|
40
|
+
".otf": "font/otf",
|
|
41
|
+
".eot": "application/vnd.ms-fontobject",
|
|
42
|
+
".wasm": "application/wasm",
|
|
43
|
+
".txt": "text/plain",
|
|
44
|
+
".xml": "application/xml"
|
|
45
|
+
};
|
|
46
|
+
function bundleUrlToLocalPath(url, namespace) {
|
|
47
|
+
let parsed;
|
|
48
|
+
try {
|
|
49
|
+
parsed = new URL(url);
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
|
|
54
|
+
const prefix = `/bundles/${encodeURIComponent(namespace.account)}/${encodeURIComponent(namespace.gateway)}/`;
|
|
55
|
+
if (!parsed.pathname.startsWith(prefix)) return null;
|
|
56
|
+
let rest;
|
|
57
|
+
try {
|
|
58
|
+
rest = decodeURIComponent(parsed.pathname.slice(prefix.length));
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (!rest || rest.endsWith("/")) return null;
|
|
63
|
+
const nsDir = node_path.default.resolve(namespace.bundleDir, namespace.account, namespace.gateway);
|
|
64
|
+
const filePath = node_path.default.resolve(nsDir, rest);
|
|
65
|
+
if (filePath !== nsDir && !filePath.startsWith(nsDir + node_path.default.sep)) return null;
|
|
66
|
+
return filePath;
|
|
67
|
+
}
|
|
68
|
+
var BundleResolver = class BundleResolver extends effect.Context.Service()("everything-dev/bundle-fs-resolve/BundleResolver") {
|
|
69
|
+
static layer(namespace) {
|
|
70
|
+
const respond = effect.Effect.fn("BundleResolver.respond")(function* (url) {
|
|
71
|
+
const filePath = bundleUrlToLocalPath(url, namespace);
|
|
72
|
+
if (!filePath) return null;
|
|
73
|
+
const bytes = yield* effect.Effect.tryPromise({
|
|
74
|
+
try: () => (0, node_fs_promises.readFile)(filePath),
|
|
75
|
+
catch: (cause) => new BundleReadError({
|
|
76
|
+
path: filePath,
|
|
77
|
+
cause
|
|
78
|
+
})
|
|
79
|
+
}).pipe(effect.Effect.catchTag("BundleReadError", () => effect.Effect.succeed(null)));
|
|
80
|
+
if (bytes === null) return null;
|
|
81
|
+
const name = node_path.default.basename(filePath);
|
|
82
|
+
const contentType = MIME_TYPES[node_path.default.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
83
|
+
return new Response(new Uint8Array(bytes), { headers: {
|
|
84
|
+
"content-type": contentType,
|
|
85
|
+
"cache-control": (0, every_plugin_build_artifact_names.cacheControlOf)(name),
|
|
86
|
+
etag: `"${Buffer.from(bytes.subarray(0, 4096)).toString("base64").slice(0, 24)}"`
|
|
87
|
+
} });
|
|
88
|
+
});
|
|
89
|
+
return effect.Layer.effect(BundleResolver, effect.Effect.succeed(BundleResolver.of({ lookup: (input) => {
|
|
90
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
91
|
+
return respond(url);
|
|
92
|
+
} })));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const staleResponse = (bytes, url) => {
|
|
96
|
+
const name = url.split("?")[0].split("/").pop() ?? "";
|
|
97
|
+
const contentType = MIME_TYPES[node_path.default.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
98
|
+
return new Response(bytes.slice().buffer, {
|
|
99
|
+
status: 200,
|
|
100
|
+
headers: {
|
|
101
|
+
"content-type": contentType,
|
|
102
|
+
"x-bundle-cache": "stale"
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Installs the resolver as a global fetch interceptor — the one seam every
|
|
108
|
+
* boot-time consumer shares (config manifest discovery, contract-type
|
|
109
|
+
* fetches, orchestrator host loading, MF remoteEntry/identity probes).
|
|
110
|
+
* One layered resolution policy: staged disk → network → stale-if-error.
|
|
111
|
+
* Own-namespace URLs resolve from the staged directory and fall through to
|
|
112
|
+
* the original fetch on a miss (a partially-staged namespace boots over the
|
|
113
|
+
* wire instead of failing); a miss never touches the write-through cache —
|
|
114
|
+
* for the own namespace the staged disk IS the resilience artifact. Foreign
|
|
115
|
+
* `/bundles/…` URLs get the network with the stale-if-error cache; every
|
|
116
|
+
* other URL falls through to the original fetch untouched. Inert when
|
|
117
|
+
* neither a staged namespace nor a cache is configured.
|
|
118
|
+
*/
|
|
119
|
+
function installGlobalBundleFetch(options) {
|
|
120
|
+
const namespace = options.namespace;
|
|
121
|
+
const cacheDir = options.cacheDir;
|
|
122
|
+
const runtime = namespace ? effect.ManagedRuntime.make(BundleResolver.layer(namespace)) : null;
|
|
123
|
+
const original = globalThis.fetch;
|
|
124
|
+
const patched = (async (input, init) => {
|
|
125
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
126
|
+
if (namespace && bundleUrlToLocalPath(url, namespace)) {
|
|
127
|
+
if (!runtime) throw new Error("unreachable: resolver runtime missing");
|
|
128
|
+
const response = await runtime.runPromise(effect.Effect.gen(function* () {
|
|
129
|
+
return yield* (yield* BundleResolver).lookup(input);
|
|
130
|
+
}));
|
|
131
|
+
if (response !== null) return response;
|
|
132
|
+
return original(input, init);
|
|
133
|
+
}
|
|
134
|
+
if (cacheDir !== void 0 && require_bundle_cache.bundleCachePath(url, { cacheDir })) return (async () => {
|
|
135
|
+
try {
|
|
136
|
+
const response = await original(input, init);
|
|
137
|
+
if (response.ok) try {
|
|
138
|
+
const bytes = new Uint8Array(await response.clone().arrayBuffer());
|
|
139
|
+
await require_bundle_cache.writeBundleCache(url, bytes, { cacheDir });
|
|
140
|
+
} catch {}
|
|
141
|
+
else {
|
|
142
|
+
const cached = await require_bundle_cache.readBundleCache(url, { cacheDir });
|
|
143
|
+
if (cached) return staleResponse(cached, url);
|
|
144
|
+
}
|
|
145
|
+
return response;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
const cached = await require_bundle_cache.readBundleCache(url, { cacheDir });
|
|
148
|
+
if (cached) return staleResponse(cached, url);
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
})();
|
|
152
|
+
return original(input, init);
|
|
153
|
+
});
|
|
154
|
+
const originalPreconnect = original.preconnect;
|
|
155
|
+
if (originalPreconnect) patched.preconnect = originalPreconnect.bind(original);
|
|
156
|
+
globalThis.fetch = patched;
|
|
157
|
+
return { uninstall: async () => {
|
|
158
|
+
if (globalThis.fetch === patched) globalThis.fetch = original;
|
|
159
|
+
if (runtime) await runtime.dispose();
|
|
160
|
+
} };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Boot-time installer for the CLI: derives the own namespace from
|
|
164
|
+
* `BOS_BUNDLE_DIR` plus the runtime identity (`BOS_ACCOUNT`/`BOS_GATEWAY`
|
|
165
|
+
* registry env taking precedence over the bos.config.json fields), and the
|
|
166
|
+
* foreign-namespace cache from `BOS_BUNDLE_CACHE_DIR`. Tier auto-detection
|
|
167
|
+
* (ADR 0021): an identity whose namespace is not actually staged under the
|
|
168
|
+
* bundle dir drops to the registry tier — plain network fetch — instead of
|
|
169
|
+
* deterministically 404ing own-namespace URLs against a foreign image's
|
|
170
|
+
* staged bytes. Never throws — a missing or malformed identity leaves the
|
|
171
|
+
* default network fetch in place.
|
|
172
|
+
*/
|
|
173
|
+
function installBundleFetchFromEnv(input) {
|
|
174
|
+
const bundleDir = process.env.BOS_BUNDLE_DIR;
|
|
175
|
+
const cacheDir = process.env.BOS_BUNDLE_CACHE_DIR;
|
|
176
|
+
if (!bundleDir && cacheDir === void 0) return null;
|
|
177
|
+
let configAccount;
|
|
178
|
+
let configGateway;
|
|
179
|
+
const configPath = input.configPath;
|
|
180
|
+
if (configPath && !require_config.isAppDescriptorPath(configPath)) try {
|
|
181
|
+
const parsed = JSON.parse((0, node_fs.readFileSync)(configPath, "utf8"));
|
|
182
|
+
configAccount = parsed.account;
|
|
183
|
+
configGateway = parsed.domain;
|
|
184
|
+
} catch {}
|
|
185
|
+
const account = process.env.BOS_ACCOUNT ?? configAccount;
|
|
186
|
+
const gateway = process.env.BOS_GATEWAY ?? configGateway;
|
|
187
|
+
if (bundleDir && (!account || !gateway)) return null;
|
|
188
|
+
let namespace;
|
|
189
|
+
if (bundleDir && account && gateway) {
|
|
190
|
+
if ((0, node_fs.existsSync)(node_path.default.join(bundleDir, account, gateway))) namespace = {
|
|
191
|
+
bundleDir,
|
|
192
|
+
account,
|
|
193
|
+
gateway
|
|
194
|
+
};
|
|
195
|
+
else console.warn(`[bundles] staged namespace ${account}/${gateway} not found under ${bundleDir} — registry tier (network fetch)`);
|
|
196
|
+
}
|
|
197
|
+
return installGlobalBundleFetch({
|
|
198
|
+
namespace,
|
|
199
|
+
cacheDir: cacheDir ?? (namespace ? require_bundle_cache.bundleCacheRoot() : void 0)
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
exports.BundleReadError = BundleReadError;
|
|
205
|
+
exports.BundleResolver = BundleResolver;
|
|
206
|
+
exports.bundleUrlToLocalPath = bundleUrlToLocalPath;
|
|
207
|
+
exports.installBundleFetchFromEnv = installBundleFetchFromEnv;
|
|
208
|
+
exports.installGlobalBundleFetch = installGlobalBundleFetch;
|
|
209
|
+
//# sourceMappingURL=bundle-fs-resolve.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-fs-resolve.cjs","names":["Schema","path","Context","Effect","readFile","cacheControlOf","Layer","ManagedRuntime","bundleCachePath","writeBundleCache","readBundleCache","isAppDescriptorPath","readFileSync","existsSync","bundleCacheRoot"],"sources":["../src/bundle-fs-resolve.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Context, Effect, Layer, ManagedRuntime, Schema } from \"effect\";\nimport { cacheControlOf } from \"every-plugin/build/artifact-names\";\nimport {\n bundleCachePath,\n bundleCacheRoot,\n readBundleCache,\n writeBundleCache,\n} from \"./bundle-cache\";\nimport { isAppDescriptorPath } from \"./config\";\n\n/**\n * Local-first bundle resolution (ADR 0011 amendment; unified policy, ADR 0021\n * amendment): a self-contained runtime image stages its own namespace under\n * `BOS_BUNDLE_DIR` as `bundles/<account>/<gateway>/<workspace>/…` and consumes\n * those bytes directly from disk; a miss falls through to the network, so a\n * partially-staged namespace boots over the wire instead of failing. The\n * registry tier (children, `BOS_BUNDLE_DIR` unset) keeps the network fetch —\n * the namespace guard below only ever matches the runtime's own\n * account/gateway, never another runtime's layout.\n */\n\nexport interface BundleNamespace {\n readonly bundleDir: string;\n readonly account: string;\n readonly gateway: string;\n}\n\nexport class BundleReadError extends Schema.TaggedError<BundleReadError>()(\"BundleReadError\", {\n path: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n}) {}\n\nconst MIME_TYPES: Record<string, string> = {\n \".js\": \"text/javascript\",\n \".mjs\": \"text/javascript\",\n \".cjs\": \"text/javascript\",\n \".css\": \"text/css\",\n \".json\": \"application/json\",\n \".map\": \"application/json\",\n \".svg\": \"image/svg+xml\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".webp\": \"image/webp\",\n \".avif\": \"image/avif\",\n \".ico\": \"image/x-icon\",\n \".html\": \"text/html\",\n \".htm\": \"text/html\",\n \".webmanifest\": \"application/manifest+json\",\n \".md\": \"text/markdown\",\n \".ts\": \"text/plain\",\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".ttf\": \"font/ttf\",\n \".otf\": \"font/otf\",\n \".eot\": \"application/vnd.ms-fontobject\",\n \".wasm\": \"application/wasm\",\n \".txt\": \"text/plain\",\n \".xml\": \"application/xml\",\n};\n\nexport function bundleUrlToLocalPath(url: string, namespace: BundleNamespace): string | null {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return null;\n }\n if (parsed.protocol !== \"https:\" && parsed.protocol !== \"http:\") return null;\n\n const prefix = `/bundles/${encodeURIComponent(namespace.account)}/${encodeURIComponent(namespace.gateway)}/`;\n if (!parsed.pathname.startsWith(prefix)) return null;\n\n let rest: string;\n try {\n rest = decodeURIComponent(parsed.pathname.slice(prefix.length));\n } catch {\n return null;\n }\n if (!rest || rest.endsWith(\"/\")) return null;\n\n // BOS_BUNDLE_DIR holds `<account>/<gateway>/<workspace>/…` directly (the\n // same layout host/src/routes/bundles.ts serves) — resolve and contain\n // within the OWN namespace, never a sibling one.\n const nsDir = path.resolve(namespace.bundleDir, namespace.account, namespace.gateway);\n const filePath = path.resolve(nsDir, rest);\n if (filePath !== nsDir && !filePath.startsWith(nsDir + path.sep)) return null;\n\n return filePath;\n}\n\nexport class BundleResolver extends Context.Service<\n BundleResolver,\n {\n /** Resolve a fetch target from the staged namespace; null = miss or not our namespace — fall through to the network. */\n readonly lookup: (input: string | URL | Request) => Effect.Effect<Response | null>;\n }\n>()(\"everything-dev/bundle-fs-resolve/BundleResolver\") {\n static layer(namespace: BundleNamespace): Layer.Layer<BundleResolver> {\n const respond = Effect.fn(\"BundleResolver.respond\")(function* (\n url: string,\n ): Effect.fn.Return<Response | null, never> {\n const filePath = bundleUrlToLocalPath(url, namespace);\n if (!filePath) return null;\n const bytes = yield* Effect.tryPromise({\n try: () => readFile(filePath),\n catch: (cause) => new BundleReadError({ path: filePath, cause }),\n }).pipe(Effect.catchTag(\"BundleReadError\", () => Effect.succeed(null)));\n if (bytes === null) return null;\n const name = path.basename(filePath);\n const contentType =\n MIME_TYPES[path.extname(name).toLowerCase()] ?? \"application/octet-stream\";\n return new Response(new Uint8Array(bytes), {\n headers: {\n \"content-type\": contentType,\n \"cache-control\": cacheControlOf(name),\n etag: `\"${Buffer.from(bytes.subarray(0, 4096)).toString(\"base64\").slice(0, 24)}\"`,\n },\n });\n });\n\n return Layer.effect(\n BundleResolver,\n Effect.succeed(\n BundleResolver.of({\n lookup: (input) => {\n const url =\n typeof input === \"string\" ? input : input instanceof URL ? input.href : input.url;\n return respond(url);\n },\n }),\n ),\n );\n }\n}\n\nexport interface BundleFetchHandle {\n readonly uninstall: () => Promise<void>;\n}\n\nexport interface BundleFetchOptions {\n /** Own-namespace FS resolution — requires a staged `BOS_BUNDLE_DIR`. */\n namespace?: BundleNamespace;\n /**\n * Foreign-namespace stale-if-error cache (child tier): `/bundles/…` URLs\n * outside the own namespace write through to disk on success and serve\n * the last-known-good bytes when the origin fails. Enabled implicitly\n * when `namespace` is present (deployment contexts), or explicitly via\n * `BOS_BUNDLE_CACHE_DIR`.\n */\n cacheDir?: string;\n}\n\ntype FetchImpl = typeof globalThis.fetch;\n\nconst staleResponse = (bytes: Uint8Array, url: string): Response => {\n const name = url.split(\"?\")[0].split(\"/\").pop() ?? \"\";\n const contentType = MIME_TYPES[path.extname(name).toLowerCase()] ?? \"application/octet-stream\";\n return new Response(bytes.slice().buffer, {\n status: 200,\n headers: { \"content-type\": contentType, \"x-bundle-cache\": \"stale\" },\n });\n};\n\n/**\n * Installs the resolver as a global fetch interceptor — the one seam every\n * boot-time consumer shares (config manifest discovery, contract-type\n * fetches, orchestrator host loading, MF remoteEntry/identity probes).\n * One layered resolution policy: staged disk → network → stale-if-error.\n * Own-namespace URLs resolve from the staged directory and fall through to\n * the original fetch on a miss (a partially-staged namespace boots over the\n * wire instead of failing); a miss never touches the write-through cache —\n * for the own namespace the staged disk IS the resilience artifact. Foreign\n * `/bundles/…` URLs get the network with the stale-if-error cache; every\n * other URL falls through to the original fetch untouched. Inert when\n * neither a staged namespace nor a cache is configured.\n */\nexport function installGlobalBundleFetch(options: BundleFetchOptions): BundleFetchHandle {\n const namespace = options.namespace;\n const cacheDir = options.cacheDir;\n const runtime = namespace ? ManagedRuntime.make(BundleResolver.layer(namespace)) : null;\n const original: FetchImpl = globalThis.fetch;\n const patched = (async (input: Parameters<FetchImpl>[0], init?: Parameters<FetchImpl>[1]) => {\n const url = typeof input === \"string\" ? input : input instanceof URL ? input.href : input.url;\n\n if (namespace && bundleUrlToLocalPath(url, namespace)) {\n if (!runtime) throw new Error(\"unreachable: resolver runtime missing\");\n const response = await runtime.runPromise(\n Effect.gen(function* () {\n const resolver = yield* BundleResolver;\n return yield* resolver.lookup(input);\n }),\n );\n if (response !== null) return response;\n return original(input, init);\n }\n\n if (cacheDir !== undefined && bundleCachePath(url, { cacheDir })) {\n return (async () => {\n try {\n const response = await original(input, init);\n if (response.ok) {\n try {\n const bytes = new Uint8Array(await response.clone().arrayBuffer());\n await writeBundleCache(url, bytes, { cacheDir });\n } catch {\n // write-through is best-effort\n }\n } else {\n const cached = await readBundleCache(url, { cacheDir });\n if (cached) return staleResponse(cached, url);\n }\n return response;\n } catch (error) {\n const cached = await readBundleCache(url, { cacheDir });\n if (cached) return staleResponse(cached, url);\n throw error;\n }\n })();\n }\n\n return original(input, init);\n }) as FetchImpl;\n const originalPreconnect = (original as Partial<FetchImpl>).preconnect;\n if (originalPreconnect) {\n patched.preconnect = originalPreconnect.bind(original);\n }\n globalThis.fetch = patched;\n return {\n uninstall: async () => {\n if (globalThis.fetch === patched) {\n globalThis.fetch = original;\n }\n if (runtime) await runtime.dispose();\n },\n };\n}\n\n/**\n * Boot-time installer for the CLI: derives the own namespace from\n * `BOS_BUNDLE_DIR` plus the runtime identity (`BOS_ACCOUNT`/`BOS_GATEWAY`\n * registry env taking precedence over the bos.config.json fields), and the\n * foreign-namespace cache from `BOS_BUNDLE_CACHE_DIR`. Tier auto-detection\n * (ADR 0021): an identity whose namespace is not actually staged under the\n * bundle dir drops to the registry tier — plain network fetch — instead of\n * deterministically 404ing own-namespace URLs against a foreign image's\n * staged bytes. Never throws — a missing or malformed identity leaves the\n * default network fetch in place.\n */\nexport function installBundleFetchFromEnv(input: {\n configPath?: string | null;\n}): BundleFetchHandle | null {\n const bundleDir = process.env.BOS_BUNDLE_DIR;\n const cacheDir = process.env.BOS_BUNDLE_CACHE_DIR;\n if (!bundleDir && cacheDir === undefined) return null;\n\n let configAccount: string | undefined;\n let configGateway: string | undefined;\n const configPath = input.configPath;\n if (configPath && !isAppDescriptorPath(configPath)) {\n try {\n const parsed = JSON.parse(readFileSync(configPath, \"utf8\")) as {\n account?: string;\n domain?: string;\n };\n configAccount = parsed.account;\n configGateway = parsed.domain;\n } catch {\n // unreadable config — identity may still come from the registry env\n }\n }\n\n const account = process.env.BOS_ACCOUNT ?? configAccount;\n const gateway = process.env.BOS_GATEWAY ?? configGateway;\n if (bundleDir && (!account || !gateway)) return null;\n\n let namespace: BundleNamespace | undefined;\n if (bundleDir && account && gateway) {\n if (existsSync(path.join(bundleDir, account, gateway))) {\n namespace = { bundleDir, account, gateway };\n } else {\n console.warn(\n `[bundles] staged namespace ${account}/${gateway} not found under ${bundleDir} — registry tier (network fetch)`,\n );\n }\n }\n return installGlobalBundleFetch({\n namespace,\n cacheDir: cacheDir ?? (namespace ? bundleCacheRoot() : undefined),\n });\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,IAAa,kBAAb,cAAqCA,cAAO,YAA6B,CAAC,CAAC,mBAAmB;CAC5F,MAAMA,cAAO;CACb,OAAOA,cAAO,SAASA,cAAO,O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I,oBACF,QAAQ,aAAa,mBAAmB,KAAK,QAAQ;CAEvD,WAAW,QAAQ;CACnB,OAAO,EACL,WAAW,YAAY;EACrB,IAAI,WAAW,UAAU,SACvB,WAAW,QAAQ;EAErB,IAAI,SAAS,MAAM,QAAQ,QAAQ;CACrC,EACF;AACF;;;;;;;;;;;;AAaA,SAAgB,0BAA0B,OAEb;CAC3B,MAAM,YAAY,QAAQ,IAAI;CAC9B,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,CAAC,aAAa,aAAa,QAAW,OAAO;CAEjD,IAAI;CACJ,IAAI;CACJ,MAAM,aAAa,MAAM;CACzB,IAAI,cAAc,CAACC,mCAAoB,UAAU,GAC/C,IAAI;EACF,MAAM,SAAS,KAAK,UAAMC,sBAAa,YAAY,MAAM,CAAC;EAI1D,gBAAgB,OAAO;EACvB,gBAAgB,OAAO;CACzB,QAAQ,CAER;CAGF,MAAM,UAAU,QAAQ,IAAI,eAAe;CAC3C,MAAM,UAAU,QAAQ,IAAI,eAAe;CAC3C,IAAI,cAAc,CAAC,WAAW,CAAC,UAAU,OAAO;CAEhD,IAAI;CACJ,IAAI,aAAa,WAAW,SAAS;EACnC,QAAIC,oBAAWZ,kBAAK,KAAK,WAAW,SAAS,OAAO,CAAC,GACnD,YAAY;GAAE;GAAW;GAAS;EAAQ;OAE1C,QAAQ,KACN,8BAA8B,QAAQ,GAAG,QAAQ,mBAAmB,UAAU,iCAChF;CAEJ;CACA,OAAO,yBAAyB;EAC9B;EACA,UAAU,aAAa,YAAYa,qCAAgB,IAAI;CACzD,CAAC;AACH"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
//#region src/bundle-fs-resolve.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Local-first bundle resolution (ADR 0011 amendment; unified policy, ADR 0021
|
|
5
|
+
* amendment): a self-contained runtime image stages its own namespace under
|
|
6
|
+
* `BOS_BUNDLE_DIR` as `bundles/<account>/<gateway>/<workspace>/…` and consumes
|
|
7
|
+
* those bytes directly from disk; a miss falls through to the network, so a
|
|
8
|
+
* partially-staged namespace boots over the wire instead of failing. The
|
|
9
|
+
* registry tier (children, `BOS_BUNDLE_DIR` unset) keeps the network fetch —
|
|
10
|
+
* the namespace guard below only ever matches the runtime's own
|
|
11
|
+
* account/gateway, never another runtime's layout.
|
|
12
|
+
*/
|
|
13
|
+
interface BundleNamespace {
|
|
14
|
+
readonly bundleDir: string;
|
|
15
|
+
readonly account: string;
|
|
16
|
+
readonly gateway: string;
|
|
17
|
+
}
|
|
18
|
+
declare const BundleReadError_base: Schema.Class<BundleReadError, Schema.TaggedStruct<"BundleReadError", {
|
|
19
|
+
readonly path: Schema.String;
|
|
20
|
+
readonly cause: Schema.optional<Schema.Unknown>;
|
|
21
|
+
}>, import("effect/Cause").YieldableError>;
|
|
22
|
+
declare class BundleReadError extends BundleReadError_base {}
|
|
23
|
+
declare function bundleUrlToLocalPath(url: string, namespace: BundleNamespace): string | null;
|
|
24
|
+
declare const BundleResolver_base: Context.ServiceClass<BundleResolver, "everything-dev/bundle-fs-resolve/BundleResolver", {
|
|
25
|
+
/** Resolve a fetch target from the staged namespace; null = miss or not our namespace — fall through to the network. */
|
|
26
|
+
readonly lookup: (input: string | URL | Request) => Effect.Effect<Response | null>;
|
|
27
|
+
}>;
|
|
28
|
+
declare class BundleResolver extends BundleResolver_base {
|
|
29
|
+
static layer(namespace: BundleNamespace): Layer.Layer<BundleResolver>;
|
|
30
|
+
}
|
|
31
|
+
interface BundleFetchHandle {
|
|
32
|
+
readonly uninstall: () => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
interface BundleFetchOptions {
|
|
35
|
+
/** Own-namespace FS resolution — requires a staged `BOS_BUNDLE_DIR`. */
|
|
36
|
+
namespace?: BundleNamespace;
|
|
37
|
+
/**
|
|
38
|
+
* Foreign-namespace stale-if-error cache (child tier): `/bundles/…` URLs
|
|
39
|
+
* outside the own namespace write through to disk on success and serve
|
|
40
|
+
* the last-known-good bytes when the origin fails. Enabled implicitly
|
|
41
|
+
* when `namespace` is present (deployment contexts), or explicitly via
|
|
42
|
+
* `BOS_BUNDLE_CACHE_DIR`.
|
|
43
|
+
*/
|
|
44
|
+
cacheDir?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Installs the resolver as a global fetch interceptor — the one seam every
|
|
48
|
+
* boot-time consumer shares (config manifest discovery, contract-type
|
|
49
|
+
* fetches, orchestrator host loading, MF remoteEntry/identity probes).
|
|
50
|
+
* One layered resolution policy: staged disk → network → stale-if-error.
|
|
51
|
+
* Own-namespace URLs resolve from the staged directory and fall through to
|
|
52
|
+
* the original fetch on a miss (a partially-staged namespace boots over the
|
|
53
|
+
* wire instead of failing); a miss never touches the write-through cache —
|
|
54
|
+
* for the own namespace the staged disk IS the resilience artifact. Foreign
|
|
55
|
+
* `/bundles/…` URLs get the network with the stale-if-error cache; every
|
|
56
|
+
* other URL falls through to the original fetch untouched. Inert when
|
|
57
|
+
* neither a staged namespace nor a cache is configured.
|
|
58
|
+
*/
|
|
59
|
+
declare function installGlobalBundleFetch(options: BundleFetchOptions): BundleFetchHandle;
|
|
60
|
+
/**
|
|
61
|
+
* Boot-time installer for the CLI: derives the own namespace from
|
|
62
|
+
* `BOS_BUNDLE_DIR` plus the runtime identity (`BOS_ACCOUNT`/`BOS_GATEWAY`
|
|
63
|
+
* registry env taking precedence over the bos.config.json fields), and the
|
|
64
|
+
* foreign-namespace cache from `BOS_BUNDLE_CACHE_DIR`. Tier auto-detection
|
|
65
|
+
* (ADR 0021): an identity whose namespace is not actually staged under the
|
|
66
|
+
* bundle dir drops to the registry tier — plain network fetch — instead of
|
|
67
|
+
* deterministically 404ing own-namespace URLs against a foreign image's
|
|
68
|
+
* staged bytes. Never throws — a missing or malformed identity leaves the
|
|
69
|
+
* default network fetch in place.
|
|
70
|
+
*/
|
|
71
|
+
declare function installBundleFetchFromEnv(input: {
|
|
72
|
+
configPath?: string | null;
|
|
73
|
+
}): BundleFetchHandle | null;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { BundleFetchHandle, BundleFetchOptions, BundleNamespace, BundleReadError, BundleResolver, bundleUrlToLocalPath, installBundleFetchFromEnv, installGlobalBundleFetch };
|
|
76
|
+
//# sourceMappingURL=bundle-fs-resolve.d.cts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
//#region src/bundle-fs-resolve.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Local-first bundle resolution (ADR 0011 amendment; unified policy, ADR 0021
|
|
5
|
+
* amendment): a self-contained runtime image stages its own namespace under
|
|
6
|
+
* `BOS_BUNDLE_DIR` as `bundles/<account>/<gateway>/<workspace>/…` and consumes
|
|
7
|
+
* those bytes directly from disk; a miss falls through to the network, so a
|
|
8
|
+
* partially-staged namespace boots over the wire instead of failing. The
|
|
9
|
+
* registry tier (children, `BOS_BUNDLE_DIR` unset) keeps the network fetch —
|
|
10
|
+
* the namespace guard below only ever matches the runtime's own
|
|
11
|
+
* account/gateway, never another runtime's layout.
|
|
12
|
+
*/
|
|
13
|
+
interface BundleNamespace {
|
|
14
|
+
readonly bundleDir: string;
|
|
15
|
+
readonly account: string;
|
|
16
|
+
readonly gateway: string;
|
|
17
|
+
}
|
|
18
|
+
declare const BundleReadError_base: Schema.Class<BundleReadError, Schema.TaggedStruct<"BundleReadError", {
|
|
19
|
+
readonly path: Schema.String;
|
|
20
|
+
readonly cause: Schema.optional<Schema.Unknown>;
|
|
21
|
+
}>, import("effect/Cause").YieldableError>;
|
|
22
|
+
declare class BundleReadError extends BundleReadError_base {}
|
|
23
|
+
declare function bundleUrlToLocalPath(url: string, namespace: BundleNamespace): string | null;
|
|
24
|
+
declare const BundleResolver_base: Context.ServiceClass<BundleResolver, "everything-dev/bundle-fs-resolve/BundleResolver", {
|
|
25
|
+
/** Resolve a fetch target from the staged namespace; null = miss or not our namespace — fall through to the network. */
|
|
26
|
+
readonly lookup: (input: string | URL | Request) => Effect.Effect<Response | null>;
|
|
27
|
+
}>;
|
|
28
|
+
declare class BundleResolver extends BundleResolver_base {
|
|
29
|
+
static layer(namespace: BundleNamespace): Layer.Layer<BundleResolver>;
|
|
30
|
+
}
|
|
31
|
+
interface BundleFetchHandle {
|
|
32
|
+
readonly uninstall: () => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
interface BundleFetchOptions {
|
|
35
|
+
/** Own-namespace FS resolution — requires a staged `BOS_BUNDLE_DIR`. */
|
|
36
|
+
namespace?: BundleNamespace;
|
|
37
|
+
/**
|
|
38
|
+
* Foreign-namespace stale-if-error cache (child tier): `/bundles/…` URLs
|
|
39
|
+
* outside the own namespace write through to disk on success and serve
|
|
40
|
+
* the last-known-good bytes when the origin fails. Enabled implicitly
|
|
41
|
+
* when `namespace` is present (deployment contexts), or explicitly via
|
|
42
|
+
* `BOS_BUNDLE_CACHE_DIR`.
|
|
43
|
+
*/
|
|
44
|
+
cacheDir?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Installs the resolver as a global fetch interceptor — the one seam every
|
|
48
|
+
* boot-time consumer shares (config manifest discovery, contract-type
|
|
49
|
+
* fetches, orchestrator host loading, MF remoteEntry/identity probes).
|
|
50
|
+
* One layered resolution policy: staged disk → network → stale-if-error.
|
|
51
|
+
* Own-namespace URLs resolve from the staged directory and fall through to
|
|
52
|
+
* the original fetch on a miss (a partially-staged namespace boots over the
|
|
53
|
+
* wire instead of failing); a miss never touches the write-through cache —
|
|
54
|
+
* for the own namespace the staged disk IS the resilience artifact. Foreign
|
|
55
|
+
* `/bundles/…` URLs get the network with the stale-if-error cache; every
|
|
56
|
+
* other URL falls through to the original fetch untouched. Inert when
|
|
57
|
+
* neither a staged namespace nor a cache is configured.
|
|
58
|
+
*/
|
|
59
|
+
declare function installGlobalBundleFetch(options: BundleFetchOptions): BundleFetchHandle;
|
|
60
|
+
/**
|
|
61
|
+
* Boot-time installer for the CLI: derives the own namespace from
|
|
62
|
+
* `BOS_BUNDLE_DIR` plus the runtime identity (`BOS_ACCOUNT`/`BOS_GATEWAY`
|
|
63
|
+
* registry env taking precedence over the bos.config.json fields), and the
|
|
64
|
+
* foreign-namespace cache from `BOS_BUNDLE_CACHE_DIR`. Tier auto-detection
|
|
65
|
+
* (ADR 0021): an identity whose namespace is not actually staged under the
|
|
66
|
+
* bundle dir drops to the registry tier — plain network fetch — instead of
|
|
67
|
+
* deterministically 404ing own-namespace URLs against a foreign image's
|
|
68
|
+
* staged bytes. Never throws — a missing or malformed identity leaves the
|
|
69
|
+
* default network fetch in place.
|
|
70
|
+
*/
|
|
71
|
+
declare function installBundleFetchFromEnv(input: {
|
|
72
|
+
configPath?: string | null;
|
|
73
|
+
}): BundleFetchHandle | null;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { BundleFetchHandle, BundleFetchOptions, BundleNamespace, BundleReadError, BundleResolver, bundleUrlToLocalPath, installBundleFetchFromEnv, installGlobalBundleFetch };
|
|
76
|
+
//# sourceMappingURL=bundle-fs-resolve.d.mts.map
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { isAppDescriptorPath } from "./config.mjs";
|
|
2
|
+
import { bundleCachePath, bundleCacheRoot, readBundleCache, writeBundleCache } from "./bundle-cache.mjs";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { Context, Effect, Layer, ManagedRuntime, Schema } from "effect";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { cacheControlOf } from "every-plugin/build/artifact-names";
|
|
8
|
+
|
|
9
|
+
//#region src/bundle-fs-resolve.ts
|
|
10
|
+
var BundleReadError = class extends Schema.TaggedError()("BundleReadError", {
|
|
11
|
+
path: Schema.String,
|
|
12
|
+
cause: Schema.optional(Schema.Unknown)
|
|
13
|
+
}) {};
|
|
14
|
+
const MIME_TYPES = {
|
|
15
|
+
".js": "text/javascript",
|
|
16
|
+
".mjs": "text/javascript",
|
|
17
|
+
".cjs": "text/javascript",
|
|
18
|
+
".css": "text/css",
|
|
19
|
+
".json": "application/json",
|
|
20
|
+
".map": "application/json",
|
|
21
|
+
".svg": "image/svg+xml",
|
|
22
|
+
".png": "image/png",
|
|
23
|
+
".jpg": "image/jpeg",
|
|
24
|
+
".jpeg": "image/jpeg",
|
|
25
|
+
".gif": "image/gif",
|
|
26
|
+
".webp": "image/webp",
|
|
27
|
+
".avif": "image/avif",
|
|
28
|
+
".ico": "image/x-icon",
|
|
29
|
+
".html": "text/html",
|
|
30
|
+
".htm": "text/html",
|
|
31
|
+
".webmanifest": "application/manifest+json",
|
|
32
|
+
".md": "text/markdown",
|
|
33
|
+
".ts": "text/plain",
|
|
34
|
+
".woff": "font/woff",
|
|
35
|
+
".woff2": "font/woff2",
|
|
36
|
+
".ttf": "font/ttf",
|
|
37
|
+
".otf": "font/otf",
|
|
38
|
+
".eot": "application/vnd.ms-fontobject",
|
|
39
|
+
".wasm": "application/wasm",
|
|
40
|
+
".txt": "text/plain",
|
|
41
|
+
".xml": "application/xml"
|
|
42
|
+
};
|
|
43
|
+
function bundleUrlToLocalPath(url, namespace) {
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = new URL(url);
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
|
|
51
|
+
const prefix = `/bundles/${encodeURIComponent(namespace.account)}/${encodeURIComponent(namespace.gateway)}/`;
|
|
52
|
+
if (!parsed.pathname.startsWith(prefix)) return null;
|
|
53
|
+
let rest;
|
|
54
|
+
try {
|
|
55
|
+
rest = decodeURIComponent(parsed.pathname.slice(prefix.length));
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (!rest || rest.endsWith("/")) return null;
|
|
60
|
+
const nsDir = path.resolve(namespace.bundleDir, namespace.account, namespace.gateway);
|
|
61
|
+
const filePath = path.resolve(nsDir, rest);
|
|
62
|
+
if (filePath !== nsDir && !filePath.startsWith(nsDir + path.sep)) return null;
|
|
63
|
+
return filePath;
|
|
64
|
+
}
|
|
65
|
+
var BundleResolver = class BundleResolver extends Context.Service()("everything-dev/bundle-fs-resolve/BundleResolver") {
|
|
66
|
+
static layer(namespace) {
|
|
67
|
+
const respond = Effect.fn("BundleResolver.respond")(function* (url) {
|
|
68
|
+
const filePath = bundleUrlToLocalPath(url, namespace);
|
|
69
|
+
if (!filePath) return null;
|
|
70
|
+
const bytes = yield* Effect.tryPromise({
|
|
71
|
+
try: () => readFile(filePath),
|
|
72
|
+
catch: (cause) => new BundleReadError({
|
|
73
|
+
path: filePath,
|
|
74
|
+
cause
|
|
75
|
+
})
|
|
76
|
+
}).pipe(Effect.catchTag("BundleReadError", () => Effect.succeed(null)));
|
|
77
|
+
if (bytes === null) return null;
|
|
78
|
+
const name = path.basename(filePath);
|
|
79
|
+
const contentType = MIME_TYPES[path.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
80
|
+
return new Response(new Uint8Array(bytes), { headers: {
|
|
81
|
+
"content-type": contentType,
|
|
82
|
+
"cache-control": cacheControlOf(name),
|
|
83
|
+
etag: `"${Buffer.from(bytes.subarray(0, 4096)).toString("base64").slice(0, 24)}"`
|
|
84
|
+
} });
|
|
85
|
+
});
|
|
86
|
+
return Layer.effect(BundleResolver, Effect.succeed(BundleResolver.of({ lookup: (input) => {
|
|
87
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
88
|
+
return respond(url);
|
|
89
|
+
} })));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const staleResponse = (bytes, url) => {
|
|
93
|
+
const name = url.split("?")[0].split("/").pop() ?? "";
|
|
94
|
+
const contentType = MIME_TYPES[path.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
95
|
+
return new Response(bytes.slice().buffer, {
|
|
96
|
+
status: 200,
|
|
97
|
+
headers: {
|
|
98
|
+
"content-type": contentType,
|
|
99
|
+
"x-bundle-cache": "stale"
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Installs the resolver as a global fetch interceptor — the one seam every
|
|
105
|
+
* boot-time consumer shares (config manifest discovery, contract-type
|
|
106
|
+
* fetches, orchestrator host loading, MF remoteEntry/identity probes).
|
|
107
|
+
* One layered resolution policy: staged disk → network → stale-if-error.
|
|
108
|
+
* Own-namespace URLs resolve from the staged directory and fall through to
|
|
109
|
+
* the original fetch on a miss (a partially-staged namespace boots over the
|
|
110
|
+
* wire instead of failing); a miss never touches the write-through cache —
|
|
111
|
+
* for the own namespace the staged disk IS the resilience artifact. Foreign
|
|
112
|
+
* `/bundles/…` URLs get the network with the stale-if-error cache; every
|
|
113
|
+
* other URL falls through to the original fetch untouched. Inert when
|
|
114
|
+
* neither a staged namespace nor a cache is configured.
|
|
115
|
+
*/
|
|
116
|
+
function installGlobalBundleFetch(options) {
|
|
117
|
+
const namespace = options.namespace;
|
|
118
|
+
const cacheDir = options.cacheDir;
|
|
119
|
+
const runtime = namespace ? ManagedRuntime.make(BundleResolver.layer(namespace)) : null;
|
|
120
|
+
const original = globalThis.fetch;
|
|
121
|
+
const patched = (async (input, init) => {
|
|
122
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
123
|
+
if (namespace && bundleUrlToLocalPath(url, namespace)) {
|
|
124
|
+
if (!runtime) throw new Error("unreachable: resolver runtime missing");
|
|
125
|
+
const response = await runtime.runPromise(Effect.gen(function* () {
|
|
126
|
+
return yield* (yield* BundleResolver).lookup(input);
|
|
127
|
+
}));
|
|
128
|
+
if (response !== null) return response;
|
|
129
|
+
return original(input, init);
|
|
130
|
+
}
|
|
131
|
+
if (cacheDir !== void 0 && bundleCachePath(url, { cacheDir })) return (async () => {
|
|
132
|
+
try {
|
|
133
|
+
const response = await original(input, init);
|
|
134
|
+
if (response.ok) try {
|
|
135
|
+
const bytes = new Uint8Array(await response.clone().arrayBuffer());
|
|
136
|
+
await writeBundleCache(url, bytes, { cacheDir });
|
|
137
|
+
} catch {}
|
|
138
|
+
else {
|
|
139
|
+
const cached = await readBundleCache(url, { cacheDir });
|
|
140
|
+
if (cached) return staleResponse(cached, url);
|
|
141
|
+
}
|
|
142
|
+
return response;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
const cached = await readBundleCache(url, { cacheDir });
|
|
145
|
+
if (cached) return staleResponse(cached, url);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
})();
|
|
149
|
+
return original(input, init);
|
|
150
|
+
});
|
|
151
|
+
const originalPreconnect = original.preconnect;
|
|
152
|
+
if (originalPreconnect) patched.preconnect = originalPreconnect.bind(original);
|
|
153
|
+
globalThis.fetch = patched;
|
|
154
|
+
return { uninstall: async () => {
|
|
155
|
+
if (globalThis.fetch === patched) globalThis.fetch = original;
|
|
156
|
+
if (runtime) await runtime.dispose();
|
|
157
|
+
} };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Boot-time installer for the CLI: derives the own namespace from
|
|
161
|
+
* `BOS_BUNDLE_DIR` plus the runtime identity (`BOS_ACCOUNT`/`BOS_GATEWAY`
|
|
162
|
+
* registry env taking precedence over the bos.config.json fields), and the
|
|
163
|
+
* foreign-namespace cache from `BOS_BUNDLE_CACHE_DIR`. Tier auto-detection
|
|
164
|
+
* (ADR 0021): an identity whose namespace is not actually staged under the
|
|
165
|
+
* bundle dir drops to the registry tier — plain network fetch — instead of
|
|
166
|
+
* deterministically 404ing own-namespace URLs against a foreign image's
|
|
167
|
+
* staged bytes. Never throws — a missing or malformed identity leaves the
|
|
168
|
+
* default network fetch in place.
|
|
169
|
+
*/
|
|
170
|
+
function installBundleFetchFromEnv(input) {
|
|
171
|
+
const bundleDir = process.env.BOS_BUNDLE_DIR;
|
|
172
|
+
const cacheDir = process.env.BOS_BUNDLE_CACHE_DIR;
|
|
173
|
+
if (!bundleDir && cacheDir === void 0) return null;
|
|
174
|
+
let configAccount;
|
|
175
|
+
let configGateway;
|
|
176
|
+
const configPath = input.configPath;
|
|
177
|
+
if (configPath && !isAppDescriptorPath(configPath)) try {
|
|
178
|
+
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
179
|
+
configAccount = parsed.account;
|
|
180
|
+
configGateway = parsed.domain;
|
|
181
|
+
} catch {}
|
|
182
|
+
const account = process.env.BOS_ACCOUNT ?? configAccount;
|
|
183
|
+
const gateway = process.env.BOS_GATEWAY ?? configGateway;
|
|
184
|
+
if (bundleDir && (!account || !gateway)) return null;
|
|
185
|
+
let namespace;
|
|
186
|
+
if (bundleDir && account && gateway) {
|
|
187
|
+
if (existsSync(path.join(bundleDir, account, gateway))) namespace = {
|
|
188
|
+
bundleDir,
|
|
189
|
+
account,
|
|
190
|
+
gateway
|
|
191
|
+
};
|
|
192
|
+
else console.warn(`[bundles] staged namespace ${account}/${gateway} not found under ${bundleDir} — registry tier (network fetch)`);
|
|
193
|
+
}
|
|
194
|
+
return installGlobalBundleFetch({
|
|
195
|
+
namespace,
|
|
196
|
+
cacheDir: cacheDir ?? (namespace ? bundleCacheRoot() : void 0)
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
export { BundleReadError, BundleResolver, bundleUrlToLocalPath, installBundleFetchFromEnv, installGlobalBundleFetch };
|
|
202
|
+
//# sourceMappingURL=bundle-fs-resolve.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-fs-resolve.mjs","names":[],"sources":["../src/bundle-fs-resolve.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Context, Effect, Layer, ManagedRuntime, Schema } from \"effect\";\nimport { cacheControlOf } from \"every-plugin/build/artifact-names\";\nimport {\n bundleCachePath,\n bundleCacheRoot,\n readBundleCache,\n writeBundleCache,\n} from \"./bundle-cache\";\nimport { isAppDescriptorPath } from \"./config\";\n\n/**\n * Local-first bundle resolution (ADR 0011 amendment; unified policy, ADR 0021\n * amendment): a self-contained runtime image stages its own namespace under\n * `BOS_BUNDLE_DIR` as `bundles/<account>/<gateway>/<workspace>/…` and consumes\n * those bytes directly from disk; a miss falls through to the network, so a\n * partially-staged namespace boots over the wire instead of failing. The\n * registry tier (children, `BOS_BUNDLE_DIR` unset) keeps the network fetch —\n * the namespace guard below only ever matches the runtime's own\n * account/gateway, never another runtime's layout.\n */\n\nexport interface BundleNamespace {\n readonly bundleDir: string;\n readonly account: string;\n readonly gateway: string;\n}\n\nexport class BundleReadError extends Schema.TaggedError<BundleReadError>()(\"BundleReadError\", {\n path: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n}) {}\n\nconst MIME_TYPES: Record<string, string> = {\n \".js\": \"text/javascript\",\n \".mjs\": \"text/javascript\",\n \".cjs\": \"text/javascript\",\n \".css\": \"text/css\",\n \".json\": \"application/json\",\n \".map\": \"application/json\",\n \".svg\": \"image/svg+xml\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".webp\": \"image/webp\",\n \".avif\": \"image/avif\",\n \".ico\": \"image/x-icon\",\n \".html\": \"text/html\",\n \".htm\": \"text/html\",\n \".webmanifest\": \"application/manifest+json\",\n \".md\": \"text/markdown\",\n \".ts\": \"text/plain\",\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".ttf\": \"font/ttf\",\n \".otf\": \"font/otf\",\n \".eot\": \"application/vnd.ms-fontobject\",\n \".wasm\": \"application/wasm\",\n \".txt\": \"text/plain\",\n \".xml\": \"application/xml\",\n};\n\nexport function bundleUrlToLocalPath(url: string, namespace: BundleNamespace): string | null {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return null;\n }\n if (parsed.protocol !== \"https:\" && parsed.protocol !== \"http:\") return null;\n\n const prefix = `/bundles/${encodeURIComponent(namespace.account)}/${encodeURIComponent(namespace.gateway)}/`;\n if (!parsed.pathname.startsWith(prefix)) return null;\n\n let rest: string;\n try {\n rest = decodeURIComponent(parsed.pathname.slice(prefix.length));\n } catch {\n return null;\n }\n if (!rest || rest.endsWith(\"/\")) return null;\n\n // BOS_BUNDLE_DIR holds `<account>/<gateway>/<workspace>/…` directly (the\n // same layout host/src/routes/bundles.ts serves) — resolve and contain\n // within the OWN namespace, never a sibling one.\n const nsDir = path.resolve(namespace.bundleDir, namespace.account, namespace.gateway);\n const filePath = path.resolve(nsDir, rest);\n if (filePath !== nsDir && !filePath.startsWith(nsDir + path.sep)) return null;\n\n return filePath;\n}\n\nexport class BundleResolver extends Context.Service<\n BundleResolver,\n {\n /** Resolve a fetch target from the staged namespace; null = miss or not our namespace — fall through to the network. */\n readonly lookup: (input: string | URL | Request) => Effect.Effect<Response | null>;\n }\n>()(\"everything-dev/bundle-fs-resolve/BundleResolver\") {\n static layer(namespace: BundleNamespace): Layer.Layer<BundleResolver> {\n const respond = Effect.fn(\"BundleResolver.respond\")(function* (\n url: string,\n ): Effect.fn.Return<Response | null, never> {\n const filePath = bundleUrlToLocalPath(url, namespace);\n if (!filePath) return null;\n const bytes = yield* Effect.tryPromise({\n try: () => readFile(filePath),\n catch: (cause) => new BundleReadError({ path: filePath, cause }),\n }).pipe(Effect.catchTag(\"BundleReadError\", () => Effect.succeed(null)));\n if (bytes === null) return null;\n const name = path.basename(filePath);\n const contentType =\n MIME_TYPES[path.extname(name).toLowerCase()] ?? \"application/octet-stream\";\n return new Response(new Uint8Array(bytes), {\n headers: {\n \"content-type\": contentType,\n \"cache-control\": cacheControlOf(name),\n etag: `\"${Buffer.from(bytes.subarray(0, 4096)).toString(\"base64\").slice(0, 24)}\"`,\n },\n });\n });\n\n return Layer.effect(\n BundleResolver,\n Effect.succeed(\n BundleResolver.of({\n lookup: (input) => {\n const url =\n typeof input === \"string\" ? input : input instanceof URL ? input.href : input.url;\n return respond(url);\n },\n }),\n ),\n );\n }\n}\n\nexport interface BundleFetchHandle {\n readonly uninstall: () => Promise<void>;\n}\n\nexport interface BundleFetchOptions {\n /** Own-namespace FS resolution — requires a staged `BOS_BUNDLE_DIR`. */\n namespace?: BundleNamespace;\n /**\n * Foreign-namespace stale-if-error cache (child tier): `/bundles/…` URLs\n * outside the own namespace write through to disk on success and serve\n * the last-known-good bytes when the origin fails. Enabled implicitly\n * when `namespace` is present (deployment contexts), or explicitly via\n * `BOS_BUNDLE_CACHE_DIR`.\n */\n cacheDir?: string;\n}\n\ntype FetchImpl = typeof globalThis.fetch;\n\nconst staleResponse = (bytes: Uint8Array, url: string): Response => {\n const name = url.split(\"?\")[0].split(\"/\").pop() ?? \"\";\n const contentType = MIME_TYPES[path.extname(name).toLowerCase()] ?? \"application/octet-stream\";\n return new Response(bytes.slice().buffer, {\n status: 200,\n headers: { \"content-type\": contentType, \"x-bundle-cache\": \"stale\" },\n });\n};\n\n/**\n * Installs the resolver as a global fetch interceptor — the one seam every\n * boot-time consumer shares (config manifest discovery, contract-type\n * fetches, orchestrator host loading, MF remoteEntry/identity probes).\n * One layered resolution policy: staged disk → network → stale-if-error.\n * Own-namespace URLs resolve from the staged directory and fall through to\n * the original fetch on a miss (a partially-staged namespace boots over the\n * wire instead of failing); a miss never touches the write-through cache —\n * for the own namespace the staged disk IS the resilience artifact. Foreign\n * `/bundles/…` URLs get the network with the stale-if-error cache; every\n * other URL falls through to the original fetch untouched. Inert when\n * neither a staged namespace nor a cache is configured.\n */\nexport function installGlobalBundleFetch(options: BundleFetchOptions): BundleFetchHandle {\n const namespace = options.namespace;\n const cacheDir = options.cacheDir;\n const runtime = namespace ? ManagedRuntime.make(BundleResolver.layer(namespace)) : null;\n const original: FetchImpl = globalThis.fetch;\n const patched = (async (input: Parameters<FetchImpl>[0], init?: Parameters<FetchImpl>[1]) => {\n const url = typeof input === \"string\" ? input : input instanceof URL ? input.href : input.url;\n\n if (namespace && bundleUrlToLocalPath(url, namespace)) {\n if (!runtime) throw new Error(\"unreachable: resolver runtime missing\");\n const response = await runtime.runPromise(\n Effect.gen(function* () {\n const resolver = yield* BundleResolver;\n return yield* resolver.lookup(input);\n }),\n );\n if (response !== null) return response;\n return original(input, init);\n }\n\n if (cacheDir !== undefined && bundleCachePath(url, { cacheDir })) {\n return (async () => {\n try {\n const response = await original(input, init);\n if (response.ok) {\n try {\n const bytes = new Uint8Array(await response.clone().arrayBuffer());\n await writeBundleCache(url, bytes, { cacheDir });\n } catch {\n // write-through is best-effort\n }\n } else {\n const cached = await readBundleCache(url, { cacheDir });\n if (cached) return staleResponse(cached, url);\n }\n return response;\n } catch (error) {\n const cached = await readBundleCache(url, { cacheDir });\n if (cached) return staleResponse(cached, url);\n throw error;\n }\n })();\n }\n\n return original(input, init);\n }) as FetchImpl;\n const originalPreconnect = (original as Partial<FetchImpl>).preconnect;\n if (originalPreconnect) {\n patched.preconnect = originalPreconnect.bind(original);\n }\n globalThis.fetch = patched;\n return {\n uninstall: async () => {\n if (globalThis.fetch === patched) {\n globalThis.fetch = original;\n }\n if (runtime) await runtime.dispose();\n },\n };\n}\n\n/**\n * Boot-time installer for the CLI: derives the own namespace from\n * `BOS_BUNDLE_DIR` plus the runtime identity (`BOS_ACCOUNT`/`BOS_GATEWAY`\n * registry env taking precedence over the bos.config.json fields), and the\n * foreign-namespace cache from `BOS_BUNDLE_CACHE_DIR`. Tier auto-detection\n * (ADR 0021): an identity whose namespace is not actually staged under the\n * bundle dir drops to the registry tier — plain network fetch — instead of\n * deterministically 404ing own-namespace URLs against a foreign image's\n * staged bytes. Never throws — a missing or malformed identity leaves the\n * default network fetch in place.\n */\nexport function installBundleFetchFromEnv(input: {\n configPath?: string | null;\n}): BundleFetchHandle | null {\n const bundleDir = process.env.BOS_BUNDLE_DIR;\n const cacheDir = process.env.BOS_BUNDLE_CACHE_DIR;\n if (!bundleDir && cacheDir === undefined) return null;\n\n let configAccount: string | undefined;\n let configGateway: string | undefined;\n const configPath = input.configPath;\n if (configPath && !isAppDescriptorPath(configPath)) {\n try {\n const parsed = JSON.parse(readFileSync(configPath, \"utf8\")) as {\n account?: string;\n domain?: string;\n };\n configAccount = parsed.account;\n configGateway = parsed.domain;\n } catch {\n // unreadable config — identity may still come from the registry env\n }\n }\n\n const account = process.env.BOS_ACCOUNT ?? configAccount;\n const gateway = process.env.BOS_GATEWAY ?? configGateway;\n if (bundleDir && (!account || !gateway)) return null;\n\n let namespace: BundleNamespace | undefined;\n if (bundleDir && account && gateway) {\n if (existsSync(path.join(bundleDir, account, gateway))) {\n namespace = { bundleDir, account, gateway };\n } else {\n console.warn(\n `[bundles] staged namespace ${account}/${gateway} not found under ${bundleDir} — registry tier (network fetch)`,\n );\n }\n }\n return installGlobalBundleFetch({\n namespace,\n cacheDir: cacheDir ?? (namespace ? bundleCacheRoot() : undefined),\n });\n}\n"],"mappings":";;;;;;;;;AA8BA,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CAAC,mBAAmB;CAC5F,MAAM,OAAO;CACb,OAAO,OAAO,SAAS,OAAO,OAAO;AACvC,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAM,aAAqC;CACzC,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,gBAAgB;CAChB,OAAO;CACP,OAAO;CACP,SAAS;CACT,UAAU;CACV,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;AACV;AAEA,SAAgB,qBAAqB,KAAa,WAA2C;CAC3F,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,GAAG;CACtB,QAAQ;EACN,OAAO;CACT;CACA,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,SAAS,OAAO;CAExE,M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