everything-dev 1.53.2 → 2.0.0-rc.1
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 +627 -199
- 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 +616 -197
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-contract.cjs","names":["fetchJsonOrNull","fetchResponse","buildAuthTypesGenContent"],"sources":["../src/api-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport { buildAuthTypesGenContent } from \"./auth-types-gen\";\nimport { fetchJsonOrNull, fetchResponse } from \"./http-client\";\nimport type { JsonObject, RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport interface ApiPluginManifest {\n schemaVersion: 1;\n kind: \"every-plugin/manifest\";\n plugin: {\n name: string;\n version: string;\n };\n runtime: {\n remoteEntry: string;\n };\n contract?: {\n kind: \"orpc\";\n types: {\n path: string;\n exportName: string;\n typeName: string;\n sha256?: string;\n };\n };\n additionalExports?: Array<{\n path: string;\n exports: string[];\n sha256?: string;\n }>;\n plugins?: Array<{\n key: string;\n name: string;\n url: string;\n dependsOn?: string[];\n secrets?: string[];\n variables?: JsonObject;\n }>;\n dependsOn?: string[];\n}\n\ninterface ContractSource {\n key: string;\n importName: string;\n sourceFilePath: string;\n generatedPath?: string;\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction trimTrailingSlash(input: string): string {\n return input.replace(/\\/$/, \"\");\n}\n\nfunction sanitizeIdentifier(input: string): string {\n return input.replace(/[^A-Za-z0-9_]/g, \"_\").replace(/^[^A-Za-z_]+/, \"_\");\n}\n\nfunction toImportPath(fromFile: string, targetFile: string): string {\n const rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nfunction writeFileIfChanged(filePath: string, content: string) {\n try {\n if (readFileSync(filePath, \"utf8\") === content) return false;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, content);\n return true;\n}\n\nfunction getApiPluginManifestUrl(apiBaseUrl: string): string {\n return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;\n}\n\nexport async function fetchApiPluginManifest(apiBaseUrl: string): Promise<ApiPluginManifest> {\n const url = getApiPluginManifestUrl(apiBaseUrl);\n const manifest = await fetchJsonOrNull<ApiPluginManifest>(url, { retries: 0 });\n if (!manifest) {\n throw new Error(`Failed to fetch API plugin manifest from ${url}`);\n }\n if (manifest.schemaVersion !== 1 || manifest.kind !== \"every-plugin/manifest\") {\n throw new Error(\"Unsupported API plugin manifest format\");\n }\n\n return manifest;\n}\n\nfunction localApiContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"api\", \"src\", \"contract.ts\");\n return {\n key: \"api\",\n importName: \"BaseApiContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nfunction localAuthContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"plugins\", \"auth\", \"src\", \"contract.ts\");\n return {\n key: \"auth\",\n importName: \"authContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nasync function remoteContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n name: string;\n baseUrl: string;\n generatedSubdir: string;\n}): Promise<ContractSource> {\n const manifest = await fetchApiPluginManifest(opts.baseUrl);\n if (!manifest.contract) {\n throw new Error(\n `Plugin manifest for ${manifest.plugin.name} does not advertise contract types`,\n );\n }\n\n const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${manifest.contract.types.path.replace(/^\\.\\//, \"\")}`;\n const contractResponse = await fetchResponse(contractUrl);\n if (!contractResponse.ok) {\n throw new Error(\n `Failed to fetch contract types from ${contractUrl}: ${contractResponse.status} ${contractResponse.statusText}`,\n );\n }\n\n const contractTypes = await contractResponse.text();\n if (manifest.contract.types.sha256 && manifest.contract.types.sha256 !== sha256(contractTypes)) {\n throw new Error(\"Fetched contract types failed checksum verification\");\n }\n\n const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, \"contract.d.ts\");\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, contractTypes);\n\n return {\n key: opts.name,\n importName: `${sanitizeIdentifier(opts.name)}Contract`,\n sourceFilePath: generatedPath,\n generatedPath,\n };\n}\n\nasync function fetchAuthExportTypes(opts: {\n baseUrl: string;\n runtimeDir: string;\n manifest: ApiPluginManifest;\n}): Promise<string | null> {\n if (!opts.manifest.additionalExports || opts.manifest.additionalExports.length === 0) {\n return null;\n }\n\n const authExportEntry = opts.manifest.additionalExports.find(\n (entry) => entry.path.includes(\"auth-export\") || entry.path.endsWith(\"auth-export.d.ts\"),\n );\n\n if (!authExportEntry) {\n return null;\n }\n\n const exportUrl = `${trimTrailingSlash(opts.baseUrl)}/${authExportEntry.path.replace(/^\\.\\//, \"\")}`;\n const response = await fetchResponse(exportUrl);\n if (!response.ok) {\n console.warn(\n `[API Contract] Failed to fetch auth export types from ${exportUrl}: ${response.status}`,\n );\n return null;\n }\n\n const content = await response.text();\n if (authExportEntry.sha256 && authExportEntry.sha256 !== sha256(content)) {\n console.warn(`[API Contract] Auth export types checksum mismatch for ${exportUrl}`);\n return null;\n }\n\n const generatedPath = join(opts.runtimeDir, \"auth\", \"auth-export.d.ts\");\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, content);\n\n return generatedPath;\n}\n\nasync function resolveContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n key: string;\n source: RuntimePluginConfig | { url: string; localPath?: string; name: string } | null;\n baseUrl: string;\n generatedSubdir: string;\n localSourceFactory?: (configDir: string) => ContractSource;\n}): Promise<ContractSource> {\n if (opts.key === \"api\") {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"BaseApiContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return localApiContractSource(opts.configDir);\n }\n }\n\n if (opts.key === \"auth\" && opts.localSourceFactory) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"authContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return opts.localSourceFactory(opts.configDir);\n }\n }\n\n if (\n opts.source &&\n \"localPath\" in opts.source &&\n opts.source.localPath != null &&\n opts.source.localPath !== \"\"\n ) {\n return {\n key: opts.key,\n importName: `${sanitizeIdentifier(opts.key)}Contract`,\n sourceFilePath: join(opts.source.localPath, \"src\", \"contract.ts\"),\n };\n }\n\n return remoteContractSource({\n configDir: opts.configDir,\n runtimeDir: opts.runtimeDir,\n name: opts.key,\n baseUrl: opts.baseUrl,\n generatedSubdir: opts.generatedSubdir,\n });\n}\n\nfunction writePluginClientGen(opts: {\n configDir: string;\n pluginKey: string;\n depSources: ContractSource[];\n}) {\n const pluginSrcDir = join(opts.configDir, \"plugins\", opts.pluginKey, \"src\");\n if (!existsSync(pluginSrcDir)) return;\n\n const targetPath = join(pluginSrcDir, \"lib\", \"plugins-client.gen.ts\");\n const lines: string[] = [];\n\n for (const source of opts.depSources) {\n const importPath = toImportPath(targetPath, source.sourceFilePath);\n lines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n lines.push('import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";');\n lines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n lines.push(\"\");\n\n if (opts.depSources.length === 0) {\n lines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n lines.push(\"export type PluginsClient = {\");\n for (const source of opts.depSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n lines.push(` ${key}: ClientFactory<${source.importName}>;`);\n }\n lines.push(\"};\");\n }\n\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileIfChanged(targetPath, `${lines.join(\"\\n\")}\\n`);\n}\n\nexport function writeGeneratedFiles(opts: {\n configDir: string;\n sources: ContractSource[];\n pluginKeys: string[];\n authSource: ContractSource | null;\n authExportPath?: string | null;\n apiDependsOn?: string[];\n pluginDependsOn?: Record<string, string[]>;\n}) {\n const hasLocalApiWorkspace = existsSync(join(opts.configDir, \"api\", \"src\"));\n const baseSource = opts.sources.find((source) => source.key === \"api\");\n const pluginSources = opts.pluginKeys\n .map((key) => opts.sources.find((entry) => entry.key === key))\n .filter((source): source is ContractSource => Boolean(source));\n\n if (!baseSource) {\n throw new Error(\"API contract source is required to generate the aggregate contract\");\n }\n\n // --- Generate ui/src/lib/api-types.gen.ts ---\n const uiContractPath = join(opts.configDir, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\");\n const uiLines: string[] = [];\n\n for (const source of opts.sources) {\n const importPath = toImportPath(uiContractPath, source.sourceFilePath);\n uiLines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n uiLines.push(\"\");\n\n const compositeParts: string[] = [];\n if (opts.authSource) {\n compositeParts.push(`auth: ${opts.authSource.importName}`);\n }\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);\n compositeParts.push(`${key}: ${source.importName}`);\n }\n\n if (compositeParts.length === 0) {\n uiLines.push(`export type ApiContract = ${baseSource.importName};`);\n } else {\n uiLines.push(`export type ApiContract = ${baseSource.importName} & {`);\n for (const part of compositeParts) {\n uiLines.push(` ${part};`);\n }\n uiLines.push(\"};\");\n }\n mkdirSync(dirname(uiContractPath), { recursive: true });\n writeFileIfChanged(uiContractPath, `${uiLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/lib/plugins-types.gen.ts ---\n // Filtered by apiDependsOn when explicit; includes all plugins + auth when implicit\n if (hasLocalApiWorkspace) {\n const pluginsClientPath = join(opts.configDir, \"api\", \"src\", \"lib\", \"plugins-types.gen.ts\");\n const pluginsClientLines: string[] = [];\n\n const allPluginSources = [...pluginSources];\n if (opts.authSource) {\n allPluginSources.push({ ...opts.authSource, key: \"auth\" });\n }\n\n const apiDepSources = opts.apiDependsOn?.length\n ? allPluginSources.filter((s) => opts.apiDependsOn!.includes(s.key))\n : allPluginSources;\n\n const unresolvedDepKeys =\n opts.apiDependsOn?.filter((depKey) => !allPluginSources.some((s) => s.key === depKey)) ?? [];\n\n for (const source of apiDepSources) {\n const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);\n pluginsClientLines.push(\n `import type { ContractType as ${source.importName} } from \"${importPath}\";`,\n );\n }\n\n pluginsClientLines.push(\n 'import type { ContractRouterClient, AnyContractRouter } from \"@orpc/contract\";',\n );\n pluginsClientLines.push(\n \"type ClientFactory<C extends AnyContractRouter> = (context?: Record<string, unknown>) => ContractRouterClient<C>;\",\n );\n pluginsClientLines.push(\"\");\n\n if (apiDepSources.length === 0 && unresolvedDepKeys.length === 0) {\n pluginsClientLines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n pluginsClientLines.push(\"export type PluginsClient = {\");\n for (const source of apiDepSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n pluginsClientLines.push(` ${key}: ClientFactory<${source.importName}>;`);\n }\n for (const key of unresolvedDepKeys) {\n const keyStr = /^[$A-Z_][0-9A-Z_$]*$/i.test(key) ? key : JSON.stringify(key);\n pluginsClientLines.push(` ${keyStr}?: ClientFactory<AnyContractRouter>;`);\n }\n pluginsClientLines.push(\"};\");\n }\n\n mkdirSync(dirname(pluginsClientPath), { recursive: true });\n writeFileIfChanged(pluginsClientPath, `${pluginsClientLines.join(\"\\n\")}\\n`);\n }\n\n // --- Generate per-plugin plugins-client.gen.ts ---\n const allSourcesForLookup = [...pluginSources];\n if (opts.authSource) {\n allSourcesForLookup.push({ ...opts.authSource, key: \"auth\" });\n }\n\n for (const pluginKey of opts.pluginKeys) {\n const deps = opts.pluginDependsOn?.[pluginKey];\n if (!deps?.length) continue;\n\n const depSources = deps\n .map((depKey) => allSourcesForLookup.find((s) => s.key === depKey))\n .filter((s): s is ContractSource => Boolean(s));\n\n writePluginClientGen({\n configDir: opts.configDir,\n pluginKey,\n depSources,\n });\n }\n\n // --- Generate */src/lib/auth-types.gen.ts ---\n const authTypeTargets = [join(opts.configDir, \"ui\", \"src\", \"lib\", \"auth-types.gen.ts\")];\n const apiLibDir = join(opts.configDir, \"api\", \"src\", \"lib\");\n if (existsSync(apiLibDir)) {\n authTypeTargets.push(join(apiLibDir, \"auth-types.gen.ts\"));\n }\n const hostLibDir = join(opts.configDir, \"host\", \"src\", \"lib\");\n if (existsSync(join(opts.configDir, \"host\", \"src\"))) {\n authTypeTargets.push(join(hostLibDir, \"auth-types.gen.ts\"));\n }\n\n // Per-plugin auth-types.gen.ts\n for (const key of opts.pluginKeys) {\n const pluginLibDir = join(opts.configDir, \"plugins\", key, \"src\", \"lib\");\n if (existsSync(join(opts.configDir, \"plugins\", key, \"src\"))) {\n authTypeTargets.push(join(pluginLibDir, \"auth-types.gen.ts\"));\n }\n }\n\n if (opts.authExportPath) {\n for (const authTypesPath of authTypeTargets) {\n const exportImportPath = toImportPath(authTypesPath, opts.authExportPath);\n const contractImportPath = toImportPath(\n authTypesPath,\n join(dirname(opts.authExportPath), \"contract.d.ts\"),\n );\n mkdirSync(dirname(authTypesPath), { recursive: true });\n writeFileIfChanged(\n authTypesPath,\n buildAuthTypesGenContent(exportImportPath, contractImportPath),\n );\n }\n } else if (opts.authSource) {\n for (const authTypesPath of authTypeTargets) {\n const exportImportPath = toImportPath(\n authTypesPath,\n join(opts.configDir, \".bos\", \"generated\", \"auth\", \"auth-export.d.ts\"),\n );\n const contractImportPath = toImportPath(\n authTypesPath,\n join(opts.configDir, \".bos\", \"generated\", \"auth\", \"contract.d.ts\"),\n );\n mkdirSync(dirname(authTypesPath), { recursive: true });\n writeFileIfChanged(\n authTypesPath,\n buildAuthTypesGenContent(exportImportPath, contractImportPath),\n );\n }\n }\n\n return uiContractPath;\n}\n\nexport interface ContractBridgeStatus {\n key: string;\n source: \"local\" | \"remote\" | \"skipped\" | \"failed\";\n url?: string;\n localPath?: string;\n error?: string;\n}\n\nexport async function syncApiContractBridge(opts: {\n configDir: string;\n runtimeConfig: RuntimeConfig;\n apiBaseUrl: string;\n}): Promise<{\n bridgePath: string;\n generatedPath: string | null;\n manifest: ApiPluginManifest | null;\n source: \"local\" | \"remote\";\n status: ContractBridgeStatus[];\n}> {\n const runtimeDir = join(opts.configDir, \".bos\", \"generated\");\n const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {}).sort(([a], [b]) =>\n a.localeCompare(b),\n );\n const sources: ContractSource[] = [];\n const status: ContractBridgeStatus[] = [];\n let manifest: ApiPluginManifest | null = null;\n let generatedPath: string | null = null;\n let authSource: ContractSource | null = null;\n let authExportPath: string | null = null;\n const excludedPluginKeys = new Set<string>();\n\n try {\n const baseSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"api\",\n source: opts.runtimeConfig.api,\n baseUrl: opts.apiBaseUrl,\n generatedSubdir: \"api\",\n });\n sources.push(baseSource);\n status.push({\n key: \"api\",\n source: opts.runtimeConfig.api.source,\n url: opts.runtimeConfig.api.source !== \"local\" ? opts.apiBaseUrl : undefined,\n localPath:\n opts.runtimeConfig.api.source === \"local\" ? opts.runtimeConfig.api.localPath : undefined,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.warn(`[API Contract] Failed to resolve api contract: ${message}`);\n status.push({\n key: \"api\",\n source: \"failed\",\n url: opts.apiBaseUrl || undefined,\n error: message,\n });\n }\n\n if (opts.runtimeConfig.auth) {\n try {\n authSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"auth\",\n source: opts.runtimeConfig.auth,\n baseUrl: opts.runtimeConfig.auth.url,\n generatedSubdir: \"auth\",\n localSourceFactory: localAuthContractSource,\n });\n sources.push(authSource);\n status.push({\n key: \"auth\",\n source: opts.runtimeConfig.auth.source,\n url: opts.runtimeConfig.auth.source !== \"local\" ? opts.runtimeConfig.auth.url : undefined,\n localPath:\n opts.runtimeConfig.auth.source === \"local\"\n ? opts.runtimeConfig.auth.localPath\n : undefined,\n });\n if (authSource.generatedPath) {\n generatedPath = authSource.generatedPath;\n }\n\n if (opts.runtimeConfig.auth.url && opts.runtimeConfig.auth.source !== \"local\") {\n try {\n const authManifest = await fetchApiPluginManifest(opts.runtimeConfig.auth.url);\n const fetchedAuthExportPath = await fetchAuthExportTypes({\n baseUrl: opts.runtimeConfig.auth.url,\n runtimeDir,\n manifest: authManifest,\n });\n if (fetchedAuthExportPath) {\n authExportPath = fetchedAuthExportPath;\n }\n } catch (error) {\n console.warn(\n `[API Contract] Failed to fetch auth additional exports: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n if (!authExportPath) {\n const localAuthExport = join(opts.configDir, \"plugins\", \"auth\", \"src\", \"auth-export.ts\");\n if (existsSync(localAuthExport)) {\n authExportPath = localAuthExport;\n } else {\n const generatedAuthExport = join(runtimeDir, \"auth\", \"auth-export.d.ts\");\n if (existsSync(generatedAuthExport)) {\n authExportPath = generatedAuthExport;\n }\n }\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.warn(`[API Contract] Failed to resolve auth contract: ${message}`);\n status.push({\n key: \"auth\",\n source: \"failed\",\n url: opts.runtimeConfig.auth.url || undefined,\n error: message,\n });\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n if (!plugin.url && !plugin.localPath) {\n console.warn(\n `[API Contract] Skipping plugin \"${key}\" — no URL resolved (local path missing and no production URL configured)`,\n );\n status.push({ key, source: \"skipped\" });\n excludedPluginKeys.add(key);\n }\n }\n\n const resolvablePlugins = pluginEntries.filter(([key]) => !excludedPluginKeys.has(key));\n\n const pluginResults = await Promise.allSettled(\n resolvablePlugins.map(async ([key, plugin]) => {\n const source = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key,\n source: plugin,\n baseUrl: plugin.url,\n generatedSubdir: `plugins/${key}`,\n });\n return {\n key,\n source,\n plugin,\n };\n }),\n );\n\n pluginResults.forEach((result, index) => {\n const [key, plugin] = resolvablePlugins[index];\n if (result.status === \"fulfilled\") {\n sources.push(result.value.source);\n status.push({\n key,\n source: plugin.source,\n url: plugin.source !== \"local\" ? plugin.url : undefined,\n localPath: plugin.source === \"local\" ? plugin.localPath : undefined,\n });\n if (result.value.source.generatedPath) {\n generatedPath = result.value.source.generatedPath;\n }\n } else {\n const message =\n result.reason instanceof Error ? result.reason.message : String(result.reason);\n console.warn(`[API Contract] Failed to resolve plugin \"${key}\": ${message}`);\n status.push({ key, source: \"failed\", url: plugin.url || undefined, error: message });\n excludedPluginKeys.add(key);\n }\n });\n\n const apiStatus = status.find((s) => s.key === \"api\");\n if (apiStatus?.source === \"failed\") {\n throw new Error(\n `Cannot generate contract types without api contract: ${apiStatus.error ?? \"unknown error\"}`,\n );\n }\n\n const allPluginKeys = pluginEntries\n .filter(([key]) => !excludedPluginKeys.has(key))\n .map(([key]) => key);\n\n const pluginDependsOn: Record<string, string[]> = {};\n for (const [key, plugin] of pluginEntries) {\n if (!excludedPluginKeys.has(key) && plugin.dependsOn?.length) {\n pluginDependsOn[key] = plugin.dependsOn;\n }\n }\n\n writeGeneratedFiles({\n configDir: opts.configDir,\n sources,\n pluginKeys: allPluginKeys,\n authSource,\n authExportPath,\n apiDependsOn: opts.runtimeConfig.api.dependsOn,\n pluginDependsOn,\n });\n\n if (opts.runtimeConfig.api.source !== \"local\") {\n manifest = await fetchApiPluginManifest(opts.apiBaseUrl);\n }\n\n return {\n bridgePath: join(opts.configDir, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\"),\n generatedPath,\n manifest,\n source: opts.runtimeConfig.api.source,\n status,\n };\n}\n"],"mappings":";;;;;;;AAiDA,SAAS,OAAO,OAAuB;CACrC,mCAAkB,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK;AACxD;AAEA,SAAS,kBAAkB,OAAuB;CAChD,OAAO,MAAM,QAAQ,OAAO,EAAE;AAChC;AAEA,SAAS,mBAAmB,OAAuB;CACjD,OAAO,MAAM,QAAQ,kBAAkB,GAAG,CAAC,CAAC,QAAQ,gBAAgB,GAAG;AACzE;AAEA,SAAS,aAAa,UAAkB,YAA4B;CAClE,MAAM,qDAAuB,QAAQ,GAAG,UAAU,CAAC,CAAC,QAAQ,OAAO,GAAG;CACtE,OAAO,IAAI,WAAW,GAAG,IAAI,MAAM,KAAK;AAC1C;AAEA,SAAS,mBAAmB,UAAkB,SAAiB;CAC7D,IAAI;EACF,8BAAiB,UAAU,MAAM,MAAM,SAAS,OAAO;CACzD,QAAQ,CAER;CAEA,2BAAc,UAAU,OAAO;CAC/B,OAAO;AACT;AAEA,SAAS,wBAAwB,YAA4B;CAC3D,OAAO,GAAG,kBAAkB,UAAU,E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Q,KAAK;CACpD,IAAI,WAAW,WAAW,UACxB,MAAM,IAAI,MACR,wDAAwD,UAAU,SAAS,iBAC7E;CAGF,MAAM,gBAAgB,cACnB,QAAQ,CAAC,SAAS,CAAC,mBAAmB,IAAI,GAAG,CAAC,CAAC,CAC/C,KAAK,CAAC,SAAS,GAAG;CAErB,MAAM,kBAA4C,CAAC;CACnD,KAAK,MAAM,CAAC,KAAK,WAAW,eAC1B,IAAI,CAAC,mBAAmB,IAAI,GAAG,KAAK,OAAO,WAAW,QACpD,gBAAgB,OAAO,OAAO;CAIlC,oBAAoB;EAClB,WAAW,KAAK;EAChB;EACA,YAAY;EACZ;EACA;EACA,cAAc,KAAK,cAAc,IAAI;EACrC;CACF,CAAC;CAED,IAAI,KAAK,cAAc,IAAI,WAAW,SACpC,WAAW,MAAM,uBAAuB,KAAK,UAAU;CAGzD,OAAO;EACL,gCAAiB,KAAK,WAAW,MAAM,OAAO,OAAO,kBAAkB;EACvE;EACA;EACA,QAAQ,KAAK,cAAc,IAAI;EAC/B;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"api-contract.cjs","names":["Schema","Context","Layer","Effect","fetchJsonOrNull","fetchResponse","join","dirname","ManagedRuntime","createHash","relative","readFileSync","existsSync","buildAuthTypesGenContent","buildAuthExportStub","readdirSync","isAuthMirrorPluginEntry"],"sources":["../src/api-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport { Context, Effect, Layer, ManagedRuntime, Schema } from \"effect\";\nimport { buildAuthExportStub, buildAuthTypesGenContent } from \"./auth-types-gen\";\nimport { fetchJsonOrNull, fetchResponse } from \"./http-client\";\nimport { isAuthMirrorPluginEntry } from \"./service-descriptor\";\nimport type { JsonObject, RuntimeConfig, RuntimePluginConfig } from \"./types\";\n\nexport interface ApiPluginManifest {\n schemaVersion: 1;\n kind: \"every-plugin/manifest\";\n plugin: {\n name: string;\n version: string;\n };\n runtime: {\n remoteEntry: string;\n };\n contract?: {\n kind: \"orpc\";\n types: {\n path: string;\n exportName: string;\n typeName: string;\n sha256?: string;\n };\n };\n additionalExports?: Array<{\n path: string;\n exports: string[];\n sha256?: string;\n }>;\n plugins?: Array<{\n key: string;\n name: string;\n url: string;\n dependsOn?: string[];\n secrets?: string[];\n variables?: JsonObject;\n }>;\n dependsOn?: string[];\n}\n\nexport class ApiManifestFetchError extends Schema.TaggedError<ApiManifestFetchError>()(\n \"ApiManifestFetchError\",\n { url: Schema.String, message: Schema.String },\n) {}\n\nexport class ApiManifestFormatError extends Schema.TaggedError<ApiManifestFormatError>()(\n \"ApiManifestFormatError\",\n { url: Schema.String, message: Schema.String },\n) {}\n\nexport class MissingContractTypesError extends Schema.TaggedError<MissingContractTypesError>()(\n \"MissingContractTypesError\",\n { pluginName: Schema.String, message: Schema.String },\n) {}\n\nexport class ContractTypesFetchError extends Schema.TaggedError<ContractTypesFetchError>()(\n \"ContractTypesFetchError\",\n { url: Schema.String, message: Schema.String },\n) {}\n\nexport class ContractTypesChecksumError extends Schema.TaggedError<ContractTypesChecksumError>()(\n \"ContractTypesChecksumError\",\n { url: Schema.String, message: Schema.String },\n) {}\n\nexport class AuthExportFetchError extends Schema.TaggedError<AuthExportFetchError>()(\n \"AuthExportFetchError\",\n { url: Schema.String, message: Schema.String },\n) {}\n\nexport type ApiContractError =\n | ApiManifestFetchError\n | ApiManifestFormatError\n | MissingContractTypesError\n | ContractTypesFetchError\n | ContractTypesChecksumError;\n\nexport class ApiContractResolver extends Context.Service<\n ApiContractResolver,\n {\n manifest: (\n apiBaseUrl: string,\n ) => Effect.Effect<ApiPluginManifest, ApiManifestFetchError | ApiManifestFormatError>;\n contractSource: (opts: {\n baseUrl: string;\n runtimeDir: string;\n name: string;\n generatedSubdir: string;\n }) => Effect.Effect<ContractSource, ApiContractError>;\n authExportTypes: (opts: {\n baseUrl: string;\n runtimeDir: string;\n manifest: ApiPluginManifest;\n }) => Effect.Effect<string | null, AuthExportFetchError>;\n }\n>()(\"everything-dev/api-contract/ApiContractResolver\") {\n static readonly layer: Layer.Layer<ApiContractResolver> = Layer.effect(\n ApiContractResolver,\n Effect.sync(() => {\n const manifest = Effect.fn(\"ApiContractResolver.manifest\")(function* (\n apiBaseUrl: string,\n ): Effect.fn.Return<ApiPluginManifest, ApiManifestFetchError | ApiManifestFormatError> {\n const url = getApiPluginManifestUrl(apiBaseUrl);\n const fetched = yield* Effect.tryPromise({\n try: () => fetchJsonOrNull<ApiPluginManifest>(url, { retries: 2 }),\n catch: () =>\n new ApiManifestFetchError({\n url,\n message: `Failed to fetch API plugin manifest from ${url}`,\n }),\n });\n if (!fetched) {\n return yield* new ApiManifestFetchError({\n url,\n message: `Failed to fetch API plugin manifest from ${url}`,\n });\n }\n if (fetched.schemaVersion !== 1 || fetched.kind !== \"every-plugin/manifest\") {\n return yield* new ApiManifestFormatError({\n url,\n message: \"Unsupported API plugin manifest format\",\n });\n }\n return fetched;\n });\n\n const writeContractTypes = Effect.fn(\"ApiContractResolver.writeContractTypes\")(\n function* (opts: {\n contractUrl: string;\n manifest: ApiPluginManifest;\n runtimeDir: string;\n generatedSubdir: string;\n name: string;\n }): Effect.fn.Return<ContractSource, ContractTypesFetchError | ContractTypesChecksumError> {\n const contractResponse = yield* Effect.tryPromise({\n try: () => fetchResponse(opts.contractUrl),\n catch: () =>\n new ContractTypesFetchError({\n url: opts.contractUrl,\n message: `Failed to fetch contract types from ${opts.contractUrl}`,\n }),\n });\n if (!contractResponse.ok) {\n return yield* new ContractTypesFetchError({\n url: opts.contractUrl,\n message: `Failed to fetch contract types from ${opts.contractUrl}: ${contractResponse.status} ${contractResponse.statusText}`,\n });\n }\n\n const contractTypes = yield* Effect.tryPromise({\n try: () => contractResponse.text(),\n catch: () =>\n new ContractTypesFetchError({\n url: opts.contractUrl,\n message: `Failed to fetch contract types from ${opts.contractUrl}`,\n }),\n });\n if (\n opts.manifest.contract?.types.sha256 &&\n opts.manifest.contract.types.sha256 !== sha256(contractTypes)\n ) {\n return yield* new ContractTypesChecksumError({\n url: opts.contractUrl,\n message: \"Fetched contract types failed checksum verification\",\n });\n }\n\n const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, \"contract.d.ts\");\n yield* Effect.sync(() => {\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, contractTypes);\n });\n\n return {\n key: opts.name,\n importName: `${sanitizeIdentifier(opts.name)}Contract`,\n sourceFilePath: generatedPath,\n generatedPath,\n };\n },\n );\n\n const contractSource = Effect.fn(\"ApiContractResolver.contractSource\")(function* (opts: {\n baseUrl: string;\n runtimeDir: string;\n name: string;\n generatedSubdir: string;\n }): Effect.fn.Return<ContractSource, ApiContractError> {\n const fetchedManifest = yield* manifest(opts.baseUrl);\n if (!fetchedManifest.contract) {\n return yield* new MissingContractTypesError({\n pluginName: fetchedManifest.plugin.name,\n message: `Plugin manifest for ${fetchedManifest.plugin.name} does not advertise contract types`,\n });\n }\n const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${fetchedManifest.contract.types.path.replace(/^\\.\\//, \"\")}`;\n return yield* writeContractTypes({\n contractUrl,\n manifest: fetchedManifest,\n runtimeDir: opts.runtimeDir,\n generatedSubdir: opts.generatedSubdir,\n name: opts.name,\n });\n });\n\n const authExportTypes = Effect.fn(\"ApiContractResolver.authExportTypes\")(function* (opts: {\n baseUrl: string;\n runtimeDir: string;\n manifest: ApiPluginManifest;\n }): Effect.fn.Return<string | null, AuthExportFetchError> {\n const exports = opts.manifest.additionalExports ?? [];\n const entry = exports.find(\n (candidate) =>\n candidate.path.includes(\"auth-export\") || candidate.path.endsWith(\"auth-export.d.ts\"),\n );\n if (!entry) return null;\n\n const exportUrl = `${trimTrailingSlash(opts.baseUrl)}/${entry.path.replace(/^\\.\\//, \"\")}`;\n const response = yield* Effect.tryPromise({\n try: () => fetchResponse(exportUrl),\n catch: () =>\n new AuthExportFetchError({\n url: exportUrl,\n message: `Failed to fetch auth export types from ${exportUrl}`,\n }),\n });\n if (!response.ok) {\n return yield* new AuthExportFetchError({\n url: exportUrl,\n message: `Failed to fetch auth export types from ${exportUrl}: ${response.status}`,\n });\n }\n\n const content = yield* Effect.tryPromise({\n try: () => response.text(),\n catch: () =>\n new AuthExportFetchError({\n url: exportUrl,\n message: `Failed to fetch auth export types from ${exportUrl}`,\n }),\n });\n if (entry.sha256 && entry.sha256 !== sha256(content)) {\n return yield* new AuthExportFetchError({\n url: exportUrl,\n message: `Auth export types checksum mismatch for ${exportUrl}`,\n });\n }\n\n const generatedPath = join(opts.runtimeDir, \"auth\", \"auth-export.d.ts\");\n yield* Effect.sync(() => {\n mkdirSync(dirname(generatedPath), { recursive: true });\n writeFileIfChanged(generatedPath, content);\n });\n return generatedPath;\n });\n\n return ApiContractResolver.of({ manifest, contractSource, authExportTypes });\n }),\n );\n}\n\nlet resolverRuntime: ManagedRuntime.ManagedRuntime<ApiContractResolver, never> | null = null;\n\nfunction getResolver(): ManagedRuntime.ManagedRuntime<ApiContractResolver, never> {\n if (!resolverRuntime) {\n resolverRuntime = ManagedRuntime.make(ApiContractResolver.layer);\n }\n return resolverRuntime;\n}\n\n/** Test seam: dispose the cached resolver runtime. */\nexport function disposeApiContractResolver(): Promise<void> {\n if (!resolverRuntime) return Promise.resolve();\n const runtime = resolverRuntime;\n resolverRuntime = null;\n return runtime.dispose();\n}\n\ninterface ContractSource {\n key: string;\n importName: string;\n sourceFilePath: string;\n generatedPath?: string;\n}\n\nfunction sha256(input: string): string {\n return createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction trimTrailingSlash(input: string): string {\n return input.replace(/\\/$/, \"\");\n}\n\nfunction sanitizeIdentifier(input: string): string {\n return input.replace(/[^A-Za-z0-9_]/g, \"_\").replace(/^[^A-Za-z_]+/, \"_\");\n}\n\nfunction toImportPath(fromFile: string, targetFile: string): string {\n const rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nfunction writeFileIfChanged(filePath: string, content: string) {\n try {\n if (readFileSync(filePath, \"utf8\") === content) return false;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, content);\n return true;\n}\n\nfunction getApiPluginManifestUrl(apiBaseUrl: string): string {\n return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;\n}\n\nexport async function fetchApiPluginManifest(apiBaseUrl: string): Promise<ApiPluginManifest> {\n return getResolver()\n .runPromise(\n Effect.gen(function* () {\n const resolver = yield* ApiContractResolver;\n return yield* resolver.manifest(apiBaseUrl);\n }),\n )\n .catch((error: ApiManifestFetchError | ApiManifestFormatError) => {\n throw new Error(error.message);\n });\n}\n\nfunction localApiContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"api\", \"src\", \"contract.ts\");\n if (!existsSync(sourcePath)) {\n // Never emit an import to a missing file — fail loudly so the caller\n // marks this source failed instead of generating a broken typecheck.\n throw new Error(\n `local api contract not found at api/src/contract.ts — restore the file or configure a reachable api URL`,\n );\n }\n return {\n key: \"api\",\n importName: \"BaseApiContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nfunction localAuthContractSource(configDir: string): ContractSource {\n const sourcePath = join(configDir, \"plugins\", \"auth\", \"src\", \"contract.ts\");\n if (!existsSync(sourcePath)) {\n throw new Error(\n `local auth contract not found at plugins/auth/src/contract.ts — restore the file or configure a reachable auth URL`,\n );\n }\n return {\n key: \"auth\",\n importName: \"authContract\",\n sourceFilePath: sourcePath,\n };\n}\n\nasync function remoteContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n name: string;\n baseUrl: string;\n generatedSubdir: string;\n}): Promise<ContractSource> {\n return getResolver()\n .runPromise(\n Effect.gen(function* () {\n const resolver = yield* ApiContractResolver;\n return yield* resolver.contractSource({\n baseUrl: opts.baseUrl,\n runtimeDir: opts.runtimeDir,\n name: opts.name,\n generatedSubdir: opts.generatedSubdir,\n });\n }),\n )\n .catch((error: ApiContractError) => {\n throw new Error(error.message);\n });\n}\n\nasync function fetchAuthExportTypes(opts: {\n baseUrl: string;\n runtimeDir: string;\n manifest: ApiPluginManifest;\n}): Promise<string | null> {\n return getResolver()\n .runPromise(\n Effect.gen(function* () {\n const resolver = yield* ApiContractResolver;\n return yield* resolver.authExportTypes({\n baseUrl: opts.baseUrl,\n runtimeDir: opts.runtimeDir,\n manifest: opts.manifest,\n });\n }),\n )\n .catch((error: AuthExportFetchError) => {\n console.warn(`[API Contract] ${error.message}`);\n return null;\n });\n}\n\nasync function resolveContractSource(opts: {\n configDir: string;\n runtimeDir: string;\n key: string;\n source: RuntimePluginConfig | { url: string; localPath?: string; name: string } | null;\n baseUrl: string;\n generatedSubdir: string;\n localSourceFactory?: (configDir: string) => ContractSource;\n}): Promise<ContractSource> {\n if (opts.key === \"api\") {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"BaseApiContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return localApiContractSource(opts.configDir);\n }\n }\n\n if (opts.key === \"auth\" && opts.localSourceFactory) {\n const localPath = opts.source && \"localPath\" in opts.source ? opts.source.localPath : undefined;\n if (localPath != null && localPath !== \"\") {\n return {\n key: opts.key,\n importName: \"authContract\",\n sourceFilePath: join(localPath, \"src\", \"contract.ts\"),\n };\n }\n\n if (!opts.baseUrl) {\n return opts.localSourceFactory(opts.configDir);\n }\n }\n\n if (\n opts.source &&\n \"localPath\" in opts.source &&\n opts.source.localPath != null &&\n opts.source.localPath !== \"\"\n ) {\n return {\n key: opts.key,\n importName: `${sanitizeIdentifier(opts.key)}Contract`,\n sourceFilePath: join(opts.source.localPath, \"src\", \"contract.ts\"),\n };\n }\n\n return remoteContractSource({\n configDir: opts.configDir,\n runtimeDir: opts.runtimeDir,\n name: opts.key,\n baseUrl: opts.baseUrl,\n generatedSubdir: opts.generatedSubdir,\n });\n}\n\nfunction writePluginClientGen(opts: {\n configDir: string;\n pluginKey: string;\n depSources: ContractSource[];\n localPath: string;\n}) {\n const pluginSrcDir = join(opts.localPath, \"src\");\n if (!existsSync(pluginSrcDir)) return;\n\n const targetPath = join(pluginSrcDir, \"lib\", \"plugins-client.gen.ts\");\n const lines: string[] = [];\n\n for (const source of opts.depSources) {\n const importPath = toImportPath(targetPath, source.sourceFilePath);\n lines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n lines.push('import type { RouterContractClient, RouterContract } from \"@orpc/contract\";');\n lines.push('import type { ContractedRouter } from \"@orpc/server\";');\n lines.push(\n \"type PluginClientEntry<C extends RouterContract> = {\\n client: (context?: Record<string, unknown>) => RouterContractClient<C>;\\n router: ContractedRouter<C, any>;\\n};\",\n );\n lines.push(\"\");\n\n if (opts.depSources.length === 0) {\n lines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n lines.push(\"export type PluginsClient = {\");\n for (const source of opts.depSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n lines.push(` ${key}: PluginClientEntry<${source.importName}>;`);\n }\n lines.push(\"};\");\n }\n\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileIfChanged(targetPath, `${lines.join(\"\\n\")}\\n`);\n}\n\nexport function writeGeneratedFiles(opts: {\n configDir: string;\n sources: ContractSource[];\n pluginKeys: string[];\n authSource: ContractSource | null;\n authExportPath?: string | null;\n apiDependsOn?: string[];\n pluginDependsOn?: Record<string, string[]>;\n pluginLocalPaths?: Record<string, string>;\n authLocalPath?: string;\n authDependsOn?: string[];\n}) {\n const hasLocalApiWorkspace = existsSync(join(opts.configDir, \"api\", \"src\"));\n const baseSource = opts.sources.find((source) => source.key === \"api\");\n const pluginSources = opts.pluginKeys\n .map((key) => opts.sources.find((entry) => entry.key === key))\n .filter((source): source is ContractSource => Boolean(source));\n\n if (!baseSource) {\n throw new Error(\"API contract source is required to generate the aggregate contract\");\n }\n\n // --- Generate ui/src/lib/api-types.gen.ts ---\n const uiContractPath = join(opts.configDir, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\");\n const uiLines: string[] = [];\n\n for (const source of opts.sources) {\n const importPath = toImportPath(uiContractPath, source.sourceFilePath);\n uiLines.push(`import type { ContractType as ${source.importName} } from \"${importPath}\";`);\n }\n\n uiLines.push(\"\");\n\n const compositeParts: string[] = [];\n if (opts.authSource) {\n compositeParts.push(`auth: ${opts.authSource.importName}`);\n }\n for (const source of pluginSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);\n compositeParts.push(`${key}: ${source.importName}`);\n }\n\n if (compositeParts.length === 0) {\n uiLines.push(`export type ApiContract = ${baseSource.importName};`);\n } else {\n uiLines.push(`export type ApiContract = ${baseSource.importName} & {`);\n for (const part of compositeParts) {\n uiLines.push(` ${part};`);\n }\n uiLines.push(\"};\");\n }\n mkdirSync(dirname(uiContractPath), { recursive: true });\n writeFileIfChanged(uiContractPath, `${uiLines.join(\"\\n\")}\\n`);\n\n // --- Generate api/src/lib/plugins-types.gen.ts ---\n // Filtered by apiDependsOn when explicit; includes all plugins + auth when implicit\n if (hasLocalApiWorkspace) {\n const pluginsClientPath = join(opts.configDir, \"api\", \"src\", \"lib\", \"plugins-types.gen.ts\");\n const pluginsClientLines: string[] = [];\n\n const allPluginSources = [...pluginSources];\n if (opts.authSource) {\n allPluginSources.push({ ...opts.authSource, key: \"auth\" });\n }\n\n const apiDepSources = opts.apiDependsOn?.length\n ? allPluginSources.filter((s) => opts.apiDependsOn!.includes(s.key))\n : allPluginSources;\n\n const unresolvedDepKeys =\n opts.apiDependsOn?.filter((depKey) => !allPluginSources.some((s) => s.key === depKey)) ?? [];\n\n for (const source of apiDepSources) {\n const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);\n pluginsClientLines.push(\n `import type { ContractType as ${source.importName} } from \"${importPath}\";`,\n );\n }\n\n pluginsClientLines.push(\n 'import type { RouterContractClient, RouterContract } from \"@orpc/contract\";',\n );\n pluginsClientLines.push('import type { ContractedRouter } from \"@orpc/server\";');\n pluginsClientLines.push(\n \"type PluginClientEntry<C extends RouterContract> = {\\n client: (context?: Record<string, unknown>) => RouterContractClient<C>;\\n router: ContractedRouter<C, any>;\\n};\",\n );\n pluginsClientLines.push(\"\");\n\n if (apiDepSources.length === 0 && unresolvedDepKeys.length === 0) {\n pluginsClientLines.push(\"export type PluginsClient = Record<string, never>;\");\n } else {\n pluginsClientLines.push(\"export type PluginsClient = {\");\n for (const source of apiDepSources) {\n const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key)\n ? source.key\n : JSON.stringify(source.key);\n pluginsClientLines.push(` ${key}: PluginClientEntry<${source.importName}>;`);\n }\n for (const key of unresolvedDepKeys) {\n const keyStr = /^[$A-Z_][0-9A-Z_$]*$/i.test(key) ? key : JSON.stringify(key);\n pluginsClientLines.push(` ${keyStr}?: PluginClientEntry<RouterContract>;`);\n }\n pluginsClientLines.push(\"};\");\n }\n\n mkdirSync(dirname(pluginsClientPath), { recursive: true });\n writeFileIfChanged(pluginsClientPath, `${pluginsClientLines.join(\"\\n\")}\\n`);\n }\n\n // --- Generate per-plugin plugins-client.gen.ts ---\n const allSourcesForLookup = [...pluginSources];\n if (opts.authSource) {\n allSourcesForLookup.push({ ...opts.authSource, key: \"auth\" });\n }\n\n for (const pluginKey of opts.pluginKeys) {\n const localPath = opts.pluginLocalPaths?.[pluginKey];\n if (!localPath) continue;\n\n const deps = opts.pluginDependsOn?.[pluginKey] ?? [];\n const depSources = deps\n .map((depKey) => allSourcesForLookup.find((s) => s.key === depKey))\n .filter((s): s is ContractSource => Boolean(s));\n\n writePluginClientGen({\n configDir: opts.configDir,\n pluginKey,\n depSources,\n localPath,\n });\n }\n\n if (opts.authLocalPath) {\n const deps = opts.authDependsOn ?? [];\n const depSources = deps\n .map((depKey) => allSourcesForLookup.find((s) => s.key === depKey))\n .filter((s): s is ContractSource => Boolean(s));\n\n writePluginClientGen({\n configDir: opts.configDir,\n pluginKey: \"auth\",\n depSources,\n localPath: opts.authLocalPath,\n });\n }\n\n // --- Generate */src/lib/auth-types.gen.ts ---\n const authTypeTargets = [join(opts.configDir, \"ui\", \"src\", \"lib\", \"auth-types.gen.ts\")];\n const apiLibDir = join(opts.configDir, \"api\", \"src\", \"lib\");\n if (existsSync(apiLibDir)) {\n authTypeTargets.push(join(apiLibDir, \"auth-types.gen.ts\"));\n }\n const hostLibDir = join(opts.configDir, \"host\", \"src\", \"lib\");\n if (existsSync(join(opts.configDir, \"host\", \"src\"))) {\n authTypeTargets.push(join(hostLibDir, \"auth-types.gen.ts\"));\n }\n\n // Per-plugin auth-types.gen.ts\n for (const key of opts.pluginKeys) {\n const localPath = opts.pluginLocalPaths?.[key];\n if (!localPath) continue;\n const pluginSrcDir = join(localPath, \"src\");\n if (existsSync(pluginSrcDir)) {\n authTypeTargets.push(join(pluginSrcDir, \"lib\", \"auth-types.gen.ts\"));\n }\n }\n\n if (opts.authExportPath) {\n for (const authTypesPath of authTypeTargets) {\n const exportImportPath = toImportPath(authTypesPath, opts.authExportPath);\n const contractImportPath = toImportPath(\n authTypesPath,\n join(dirname(opts.authExportPath), \"contract.d.ts\"),\n );\n mkdirSync(dirname(authTypesPath), { recursive: true });\n writeFileIfChanged(\n authTypesPath,\n buildAuthTypesGenContent(exportImportPath, contractImportPath),\n );\n }\n } else if (opts.authSource) {\n const generatedAuthExportPath = join(\n opts.configDir,\n \".bos\",\n \"generated\",\n \"auth\",\n \"auth-export.d.ts\",\n );\n mkdirSync(dirname(generatedAuthExportPath), { recursive: true });\n if (!existsSync(generatedAuthExportPath)) {\n writeFileIfChanged(generatedAuthExportPath, buildAuthExportStub());\n }\n\n for (const authTypesPath of authTypeTargets) {\n const exportImportPath = toImportPath(authTypesPath, generatedAuthExportPath);\n const contractImportPath = toImportPath(\n authTypesPath,\n join(opts.configDir, \".bos\", \"generated\", \"auth\", \"contract.d.ts\"),\n );\n mkdirSync(dirname(authTypesPath), { recursive: true });\n writeFileIfChanged(\n authTypesPath,\n buildAuthTypesGenContent(exportImportPath, contractImportPath),\n );\n }\n }\n\n // --- Sweep stale per-plugin generated files ---\n // A plugin that flips local → remote (or is removed) must not keep gen\n // files importing local source paths, and a removed remote plugin must not\n // keep its fetched contract. Only exact generated paths are removed —\n // never app source.\n const localPluginKeys = new Set(Object.keys(opts.pluginLocalPaths ?? {}));\n if (opts.authLocalPath) localPluginKeys.add(\"auth\");\n const pluginsRoot = join(opts.configDir, \"plugins\");\n if (existsSync(pluginsRoot)) {\n for (const entry of readdirSync(pluginsRoot, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name.startsWith(\"_\") || localPluginKeys.has(entry.name))\n continue;\n for (const genName of [\"plugins-client.gen.ts\", \"auth-types.gen.ts\"]) {\n const genPath = join(pluginsRoot, entry.name, \"src\", \"lib\", genName);\n if (existsSync(genPath)) rmSync(genPath);\n }\n }\n }\n const generatedPluginsRoot = join(opts.configDir, \".bos\", \"generated\", \"plugins\");\n if (existsSync(generatedPluginsRoot)) {\n const configuredKeys = new Set(opts.sources.map((source) => source.key));\n for (const entry of readdirSync(generatedPluginsRoot, { withFileTypes: true })) {\n if (!entry.isDirectory() || configuredKeys.has(entry.name)) continue;\n rmSync(join(generatedPluginsRoot, entry.name), { recursive: true, force: true });\n }\n }\n\n return uiContractPath;\n}\n\nexport interface ContractBridgeStatus {\n key: string;\n source: \"local\" | \"remote\" | \"skipped\" | \"failed\";\n url?: string;\n localPath?: string;\n error?: string;\n}\n\nexport async function syncApiContractBridge(opts: {\n configDir: string;\n runtimeConfig: RuntimeConfig;\n apiBaseUrl: string;\n}): Promise<{\n bridgePath: string;\n generatedPath: string | null;\n manifest: ApiPluginManifest | null;\n source: \"local\" | \"remote\";\n status: ContractBridgeStatus[];\n}> {\n const runtimeDir = join(opts.configDir, \".bos\", \"generated\");\n const isAuthMirrorEntry = (key: string, plugin: RuntimePluginConfig) =>\n isAuthMirrorPluginEntry(opts.runtimeConfig.auth, key, plugin);\n const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {})\n .filter(([key, plugin]) => !isAuthMirrorEntry(key, plugin))\n .sort(([a], [b]) => a.localeCompare(b));\n const sources: ContractSource[] = [];\n const status: ContractBridgeStatus[] = [];\n let manifest: ApiPluginManifest | null = null;\n let generatedPath: string | null = null;\n let authSource: ContractSource | null = null;\n let authExportPath: string | null = null;\n const excludedPluginKeys = new Set<string>();\n\n try {\n const baseSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"api\",\n source: opts.runtimeConfig.api,\n baseUrl: opts.apiBaseUrl,\n generatedSubdir: \"api\",\n });\n sources.push(baseSource);\n status.push({\n key: \"api\",\n source: opts.runtimeConfig.api.source,\n url: opts.runtimeConfig.api.source !== \"local\" ? opts.apiBaseUrl : undefined,\n localPath:\n opts.runtimeConfig.api.source === \"local\" ? opts.runtimeConfig.api.localPath : undefined,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.warn(`[API Contract] Failed to resolve api contract: ${message}`);\n status.push({\n key: \"api\",\n source: \"failed\",\n url: opts.apiBaseUrl || undefined,\n error: message,\n });\n }\n\n if (opts.runtimeConfig.auth) {\n try {\n authSource = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key: \"auth\",\n source: opts.runtimeConfig.auth,\n baseUrl: opts.runtimeConfig.auth.url,\n generatedSubdir: \"auth\",\n localSourceFactory: localAuthContractSource,\n });\n sources.push(authSource);\n status.push({\n key: \"auth\",\n source: opts.runtimeConfig.auth.source,\n url: opts.runtimeConfig.auth.source !== \"local\" ? opts.runtimeConfig.auth.url : undefined,\n localPath:\n opts.runtimeConfig.auth.source === \"local\"\n ? opts.runtimeConfig.auth.localPath\n : undefined,\n });\n if (authSource.generatedPath) {\n generatedPath = authSource.generatedPath;\n }\n\n if (opts.runtimeConfig.auth.url && opts.runtimeConfig.auth.source !== \"local\") {\n try {\n const authManifest = await fetchApiPluginManifest(opts.runtimeConfig.auth.url);\n const fetchedAuthExportPath = await fetchAuthExportTypes({\n baseUrl: opts.runtimeConfig.auth.url,\n runtimeDir,\n manifest: authManifest,\n });\n if (fetchedAuthExportPath) {\n authExportPath = fetchedAuthExportPath;\n }\n } catch (error) {\n console.warn(\n `[API Contract] Failed to fetch auth additional exports: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n if (!authExportPath) {\n const localAuthExport = join(opts.configDir, \"plugins\", \"auth\", \"src\", \"auth-export.ts\");\n if (existsSync(localAuthExport)) {\n authExportPath = localAuthExport;\n } else {\n const generatedAuthExport = join(runtimeDir, \"auth\", \"auth-export.d.ts\");\n if (existsSync(generatedAuthExport)) {\n authExportPath = generatedAuthExport;\n }\n }\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.warn(`[API Contract] Failed to resolve auth contract: ${message}`);\n status.push({\n key: \"auth\",\n source: \"failed\",\n url: opts.runtimeConfig.auth.url || undefined,\n error: message,\n });\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n if (!plugin.url && !plugin.localPath) {\n console.warn(\n `[API Contract] Skipping plugin \"${key}\" — no URL resolved (local path missing and no production URL configured)`,\n );\n status.push({ key, source: \"skipped\" });\n excludedPluginKeys.add(key);\n }\n }\n\n const resolvablePlugins = pluginEntries.filter(([key]) => !excludedPluginKeys.has(key));\n\n const pluginResults = await Promise.allSettled(\n resolvablePlugins.map(async ([key, plugin]) => {\n const source = await resolveContractSource({\n configDir: opts.configDir,\n runtimeDir,\n key,\n source: plugin,\n baseUrl: plugin.url,\n generatedSubdir: `plugins/${key}`,\n });\n return {\n key,\n source,\n plugin,\n };\n }),\n );\n\n pluginResults.forEach((result, index) => {\n const [key, plugin] = resolvablePlugins[index]!;\n if (result.status === \"fulfilled\") {\n sources.push(result.value.source);\n status.push({\n key,\n source: plugin.source,\n url: plugin.source !== \"local\" ? plugin.url : undefined,\n localPath: plugin.source === \"local\" ? plugin.localPath : undefined,\n });\n if (result.value.source.generatedPath) {\n generatedPath = result.value.source.generatedPath;\n }\n } else {\n const message =\n result.reason instanceof Error ? result.reason.message : String(result.reason);\n console.warn(`[API Contract] Failed to resolve plugin \"${key}\": ${message}`);\n status.push({ key, source: \"failed\", url: plugin.url || undefined, error: message });\n excludedPluginKeys.add(key);\n }\n });\n\n const apiStatus = status.find((s) => s.key === \"api\");\n if (apiStatus?.source === \"failed\") {\n throw new Error(\n `Cannot generate contract types without api contract: ${apiStatus.error ?? \"unknown error\"}`,\n );\n }\n\n const allPluginKeys = pluginEntries\n .filter(([key]) => !excludedPluginKeys.has(key))\n .map(([key]) => key);\n\n const pluginDependsOn: Record<string, string[]> = {};\n const pluginLocalPaths: Record<string, string> = {};\n for (const [key, plugin] of pluginEntries) {\n if (excludedPluginKeys.has(key)) continue;\n if (plugin.dependsOn?.length) {\n pluginDependsOn[key] = plugin.dependsOn;\n }\n if (plugin.localPath) {\n pluginLocalPaths[key] = plugin.localPath;\n }\n }\n\n writeGeneratedFiles({\n configDir: opts.configDir,\n sources,\n pluginKeys: allPluginKeys,\n authSource,\n authExportPath,\n apiDependsOn: opts.runtimeConfig.api.dependsOn,\n pluginDependsOn,\n pluginLocalPaths,\n authLocalPath:\n opts.runtimeConfig.auth?.source === \"local\" ? opts.runtimeConfig.auth.localPath : undefined,\n authDependsOn: opts.runtimeConfig.auth?.dependsOn,\n });\n\n if (opts.runtimeConfig.api.source !== \"local\") {\n manifest = await fetchApiPluginManifest(opts.apiBaseUrl);\n }\n\n return {\n bridgePath: join(opts.configDir, \"ui\", \"src\", \"lib\", \"api-types.gen.ts\"),\n generatedPath,\n manifest,\n source: opts.runtimeConfig.api.source,\n status,\n };\n}\n"],"mappings":";;;;;;;;;AA4CA,IAAa,wBAAb,cAA2CA,cAAO,YAAmC,CAAC,CACpF,yBACA;CAAE,KAAKA,cAAO;CAAQ,SAASA,cAAO;AAAO,CAC/C,CAAC,CAAC,CAAC;AAE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Y;EACZ;EACA;EACA,cAAc,KAAK,cAAc,IAAI;EACrC;EACA;EACA,eACE,KAAK,cAAc,MAAM,WAAW,UAAU,KAAK,cAAc,KAAK,YAAY;EACpF,eAAe,KAAK,cAAc,MAAM;CAC1C,CAAC;CAED,IAAI,KAAK,cAAc,IAAI,WAAW,SACpC,WAAW,MAAM,uBAAuB,KAAK,UAAU;CAGzD,OAAO;EACL,gBAAYN,gBAAK,KAAK,WAAW,MAAM,OAAO,OAAO,kBAAkB;EACvE;EACA;EACA,QAAQ,KAAK,cAAc,IAAI;EAC/B;CACF;AACF"}
|
package/dist/api-contract.mjs
CHANGED
|
@@ -1,10 +1,152 @@
|
|
|
1
|
-
import { buildAuthTypesGenContent } from "./auth-types-gen.mjs";
|
|
1
|
+
import { buildAuthExportStub, buildAuthTypesGenContent } from "./auth-types-gen.mjs";
|
|
2
2
|
import { fetchJsonOrNull, fetchResponse } from "./http-client.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { isAuthMirrorPluginEntry } from "./service-descriptor.mjs";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
5
|
import { dirname, join, relative } from "node:path";
|
|
6
|
+
import { Context, Effect, Layer, ManagedRuntime, Schema } from "effect";
|
|
5
7
|
import { createHash } from "node:crypto";
|
|
6
8
|
|
|
7
9
|
//#region src/api-contract.ts
|
|
10
|
+
var ApiManifestFetchError = class extends Schema.TaggedError()("ApiManifestFetchError", {
|
|
11
|
+
url: Schema.String,
|
|
12
|
+
message: Schema.String
|
|
13
|
+
}) {};
|
|
14
|
+
var ApiManifestFormatError = class extends Schema.TaggedError()("ApiManifestFormatError", {
|
|
15
|
+
url: Schema.String,
|
|
16
|
+
message: Schema.String
|
|
17
|
+
}) {};
|
|
18
|
+
var MissingContractTypesError = class extends Schema.TaggedError()("MissingContractTypesError", {
|
|
19
|
+
pluginName: Schema.String,
|
|
20
|
+
message: Schema.String
|
|
21
|
+
}) {};
|
|
22
|
+
var ContractTypesFetchError = class extends Schema.TaggedError()("ContractTypesFetchError", {
|
|
23
|
+
url: Schema.String,
|
|
24
|
+
message: Schema.String
|
|
25
|
+
}) {};
|
|
26
|
+
var ContractTypesChecksumError = class extends Schema.TaggedError()("ContractTypesChecksumError", {
|
|
27
|
+
url: Schema.String,
|
|
28
|
+
message: Schema.String
|
|
29
|
+
}) {};
|
|
30
|
+
var AuthExportFetchError = class extends Schema.TaggedError()("AuthExportFetchError", {
|
|
31
|
+
url: Schema.String,
|
|
32
|
+
message: Schema.String
|
|
33
|
+
}) {};
|
|
34
|
+
var ApiContractResolver = class ApiContractResolver extends Context.Service()("everything-dev/api-contract/ApiContractResolver") {
|
|
35
|
+
static layer = Layer.effect(ApiContractResolver, Effect.sync(() => {
|
|
36
|
+
const manifest = Effect.fn("ApiContractResolver.manifest")(function* (apiBaseUrl) {
|
|
37
|
+
const url = getApiPluginManifestUrl(apiBaseUrl);
|
|
38
|
+
const fetched = yield* Effect.tryPromise({
|
|
39
|
+
try: () => fetchJsonOrNull(url, { retries: 2 }),
|
|
40
|
+
catch: () => new ApiManifestFetchError({
|
|
41
|
+
url,
|
|
42
|
+
message: `Failed to fetch API plugin manifest from ${url}`
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
if (!fetched) return yield* new ApiManifestFetchError({
|
|
46
|
+
url,
|
|
47
|
+
message: `Failed to fetch API plugin manifest from ${url}`
|
|
48
|
+
});
|
|
49
|
+
if (fetched.schemaVersion !== 1 || fetched.kind !== "every-plugin/manifest") return yield* new ApiManifestFormatError({
|
|
50
|
+
url,
|
|
51
|
+
message: "Unsupported API plugin manifest format"
|
|
52
|
+
});
|
|
53
|
+
return fetched;
|
|
54
|
+
});
|
|
55
|
+
const writeContractTypes = Effect.fn("ApiContractResolver.writeContractTypes")(function* (opts) {
|
|
56
|
+
const contractResponse = yield* Effect.tryPromise({
|
|
57
|
+
try: () => fetchResponse(opts.contractUrl),
|
|
58
|
+
catch: () => new ContractTypesFetchError({
|
|
59
|
+
url: opts.contractUrl,
|
|
60
|
+
message: `Failed to fetch contract types from ${opts.contractUrl}`
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
if (!contractResponse.ok) return yield* new ContractTypesFetchError({
|
|
64
|
+
url: opts.contractUrl,
|
|
65
|
+
message: `Failed to fetch contract types from ${opts.contractUrl}: ${contractResponse.status} ${contractResponse.statusText}`
|
|
66
|
+
});
|
|
67
|
+
const contractTypes = yield* Effect.tryPromise({
|
|
68
|
+
try: () => contractResponse.text(),
|
|
69
|
+
catch: () => new ContractTypesFetchError({
|
|
70
|
+
url: opts.contractUrl,
|
|
71
|
+
message: `Failed to fetch contract types from ${opts.contractUrl}`
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
if (opts.manifest.contract?.types.sha256 && opts.manifest.contract.types.sha256 !== sha256(contractTypes)) return yield* new ContractTypesChecksumError({
|
|
75
|
+
url: opts.contractUrl,
|
|
76
|
+
message: "Fetched contract types failed checksum verification"
|
|
77
|
+
});
|
|
78
|
+
const generatedPath = join(opts.runtimeDir, opts.generatedSubdir, "contract.d.ts");
|
|
79
|
+
yield* Effect.sync(() => {
|
|
80
|
+
mkdirSync(dirname(generatedPath), { recursive: true });
|
|
81
|
+
writeFileIfChanged(generatedPath, contractTypes);
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
key: opts.name,
|
|
85
|
+
importName: `${sanitizeIdentifier(opts.name)}Contract`,
|
|
86
|
+
sourceFilePath: generatedPath,
|
|
87
|
+
generatedPath
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
const contractSource = Effect.fn("ApiContractResolver.contractSource")(function* (opts) {
|
|
91
|
+
const fetchedManifest = yield* manifest(opts.baseUrl);
|
|
92
|
+
if (!fetchedManifest.contract) return yield* new MissingContractTypesError({
|
|
93
|
+
pluginName: fetchedManifest.plugin.name,
|
|
94
|
+
message: `Plugin manifest for ${fetchedManifest.plugin.name} does not advertise contract types`
|
|
95
|
+
});
|
|
96
|
+
const contractUrl = `${trimTrailingSlash(opts.baseUrl)}/${fetchedManifest.contract.types.path.replace(/^\.\//, "")}`;
|
|
97
|
+
return yield* writeContractTypes({
|
|
98
|
+
contractUrl,
|
|
99
|
+
manifest: fetchedManifest,
|
|
100
|
+
runtimeDir: opts.runtimeDir,
|
|
101
|
+
generatedSubdir: opts.generatedSubdir,
|
|
102
|
+
name: opts.name
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
const authExportTypes = Effect.fn("ApiContractResolver.authExportTypes")(function* (opts) {
|
|
106
|
+
const entry = (opts.manifest.additionalExports ?? []).find((candidate) => candidate.path.includes("auth-export") || candidate.path.endsWith("auth-export.d.ts"));
|
|
107
|
+
if (!entry) return null;
|
|
108
|
+
const exportUrl = `${trimTrailingSlash(opts.baseUrl)}/${entry.path.replace(/^\.\//, "")}`;
|
|
109
|
+
const response = yield* Effect.tryPromise({
|
|
110
|
+
try: () => fetchResponse(exportUrl),
|
|
111
|
+
catch: () => new AuthExportFetchError({
|
|
112
|
+
url: exportUrl,
|
|
113
|
+
message: `Failed to fetch auth export types from ${exportUrl}`
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
if (!response.ok) return yield* new AuthExportFetchError({
|
|
117
|
+
url: exportUrl,
|
|
118
|
+
message: `Failed to fetch auth export types from ${exportUrl}: ${response.status}`
|
|
119
|
+
});
|
|
120
|
+
const content = yield* Effect.tryPromise({
|
|
121
|
+
try: () => response.text(),
|
|
122
|
+
catch: () => new AuthExportFetchError({
|
|
123
|
+
url: exportUrl,
|
|
124
|
+
message: `Failed to fetch auth export types from ${exportUrl}`
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
if (entry.sha256 && entry.sha256 !== sha256(content)) return yield* new AuthExportFetchError({
|
|
128
|
+
url: exportUrl,
|
|
129
|
+
message: `Auth export types checksum mismatch for ${exportUrl}`
|
|
130
|
+
});
|
|
131
|
+
const generatedPath = join(opts.runtimeDir, "auth", "auth-export.d.ts");
|
|
132
|
+
yield* Effect.sync(() => {
|
|
133
|
+
mkdirSync(dirname(generatedPath), { recursive: true });
|
|
134
|
+
writeFileIfChanged(generatedPath, content);
|
|
135
|
+
});
|
|
136
|
+
return generatedPath;
|
|
137
|
+
});
|
|
138
|
+
return ApiContractResolver.of({
|
|
139
|
+
manifest,
|
|
140
|
+
contractSource,
|
|
141
|
+
authExportTypes
|
|
142
|
+
});
|
|
143
|
+
}));
|
|
144
|
+
};
|
|
145
|
+
let resolverRuntime = null;
|
|
146
|
+
function getResolver() {
|
|
147
|
+
if (!resolverRuntime) resolverRuntime = ManagedRuntime.make(ApiContractResolver.layer);
|
|
148
|
+
return resolverRuntime;
|
|
149
|
+
}
|
|
8
150
|
function sha256(input) {
|
|
9
151
|
return createHash("sha256").update(input).digest("hex");
|
|
10
152
|
}
|
|
@@ -29,63 +171,53 @@ function getApiPluginManifestUrl(apiBaseUrl) {
|
|
|
29
171
|
return `${trimTrailingSlash(apiBaseUrl)}/plugin.manifest.json`;
|
|
30
172
|
}
|
|
31
173
|
async function fetchApiPluginManifest(apiBaseUrl) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
174
|
+
return getResolver().runPromise(Effect.gen(function* () {
|
|
175
|
+
return yield* (yield* ApiContractResolver).manifest(apiBaseUrl);
|
|
176
|
+
})).catch((error) => {
|
|
177
|
+
throw new Error(error.message);
|
|
178
|
+
});
|
|
37
179
|
}
|
|
38
180
|
function localApiContractSource(configDir) {
|
|
181
|
+
const sourcePath = join(configDir, "api", "src", "contract.ts");
|
|
182
|
+
if (!existsSync(sourcePath)) throw new Error(`local api contract not found at api/src/contract.ts — restore the file or configure a reachable api URL`);
|
|
39
183
|
return {
|
|
40
184
|
key: "api",
|
|
41
185
|
importName: "BaseApiContract",
|
|
42
|
-
sourceFilePath:
|
|
186
|
+
sourceFilePath: sourcePath
|
|
43
187
|
};
|
|
44
188
|
}
|
|
45
189
|
function localAuthContractSource(configDir) {
|
|
190
|
+
const sourcePath = join(configDir, "plugins", "auth", "src", "contract.ts");
|
|
191
|
+
if (!existsSync(sourcePath)) throw new Error(`local auth contract not found at plugins/auth/src/contract.ts — restore the file or configure a reachable auth URL`);
|
|
46
192
|
return {
|
|
47
193
|
key: "auth",
|
|
48
194
|
importName: "authContract",
|
|
49
|
-
sourceFilePath:
|
|
195
|
+
sourceFilePath: sourcePath
|
|
50
196
|
};
|
|
51
197
|
}
|
|
52
198
|
async function remoteContractSource(opts) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
key: opts.name,
|
|
65
|
-
importName: `${sanitizeIdentifier(opts.name)}Contract`,
|
|
66
|
-
sourceFilePath: generatedPath,
|
|
67
|
-
generatedPath
|
|
68
|
-
};
|
|
199
|
+
return getResolver().runPromise(Effect.gen(function* () {
|
|
200
|
+
return yield* (yield* ApiContractResolver).contractSource({
|
|
201
|
+
baseUrl: opts.baseUrl,
|
|
202
|
+
runtimeDir: opts.runtimeDir,
|
|
203
|
+
name: opts.name,
|
|
204
|
+
generatedSubdir: opts.generatedSubdir
|
|
205
|
+
});
|
|
206
|
+
})).catch((error) => {
|
|
207
|
+
throw new Error(error.message);
|
|
208
|
+
});
|
|
69
209
|
}
|
|
70
210
|
async function fetchAuthExportTypes(opts) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const content = await response.text();
|
|
81
|
-
if (authExportEntry.sha256 && authExportEntry.sha256 !== sha256(content)) {
|
|
82
|
-
console.warn(`[API Contract] Auth export types checksum mismatch for ${exportUrl}`);
|
|
211
|
+
return getResolver().runPromise(Effect.gen(function* () {
|
|
212
|
+
return yield* (yield* ApiContractResolver).authExportTypes({
|
|
213
|
+
baseUrl: opts.baseUrl,
|
|
214
|
+
runtimeDir: opts.runtimeDir,
|
|
215
|
+
manifest: opts.manifest
|
|
216
|
+
});
|
|
217
|
+
})).catch((error) => {
|
|
218
|
+
console.warn(`[API Contract] ${error.message}`);
|
|
83
219
|
return null;
|
|
84
|
-
}
|
|
85
|
-
const generatedPath = join(opts.runtimeDir, "auth", "auth-export.d.ts");
|
|
86
|
-
mkdirSync(dirname(generatedPath), { recursive: true });
|
|
87
|
-
writeFileIfChanged(generatedPath, content);
|
|
88
|
-
return generatedPath;
|
|
220
|
+
});
|
|
89
221
|
}
|
|
90
222
|
async function resolveContractSource(opts) {
|
|
91
223
|
if (opts.key === "api") {
|
|
@@ -120,7 +252,7 @@ async function resolveContractSource(opts) {
|
|
|
120
252
|
});
|
|
121
253
|
}
|
|
122
254
|
function writePluginClientGen(opts) {
|
|
123
|
-
const pluginSrcDir = join(opts.
|
|
255
|
+
const pluginSrcDir = join(opts.localPath, "src");
|
|
124
256
|
if (!existsSync(pluginSrcDir)) return;
|
|
125
257
|
const targetPath = join(pluginSrcDir, "lib", "plugins-client.gen.ts");
|
|
126
258
|
const lines = [];
|
|
@@ -128,15 +260,16 @@ function writePluginClientGen(opts) {
|
|
|
128
260
|
const importPath = toImportPath(targetPath, source.sourceFilePath);
|
|
129
261
|
lines.push(`import type { ContractType as ${source.importName} } from "${importPath}";`);
|
|
130
262
|
}
|
|
131
|
-
lines.push("import type {
|
|
132
|
-
lines.push("type
|
|
263
|
+
lines.push("import type { RouterContractClient, RouterContract } from \"@orpc/contract\";");
|
|
264
|
+
lines.push("import type { ContractedRouter } from \"@orpc/server\";");
|
|
265
|
+
lines.push("type PluginClientEntry<C extends RouterContract> = {\n client: (context?: Record<string, unknown>) => RouterContractClient<C>;\n router: ContractedRouter<C, any>;\n};");
|
|
133
266
|
lines.push("");
|
|
134
267
|
if (opts.depSources.length === 0) lines.push("export type PluginsClient = Record<string, never>;");
|
|
135
268
|
else {
|
|
136
269
|
lines.push("export type PluginsClient = {");
|
|
137
270
|
for (const source of opts.depSources) {
|
|
138
271
|
const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);
|
|
139
|
-
lines.push(` ${key}:
|
|
272
|
+
lines.push(` ${key}: PluginClientEntry<${source.importName}>;`);
|
|
140
273
|
}
|
|
141
274
|
lines.push("};");
|
|
142
275
|
}
|
|
@@ -183,19 +316,20 @@ function writeGeneratedFiles(opts) {
|
|
|
183
316
|
const importPath = toImportPath(pluginsClientPath, source.sourceFilePath);
|
|
184
317
|
pluginsClientLines.push(`import type { ContractType as ${source.importName} } from "${importPath}";`);
|
|
185
318
|
}
|
|
186
|
-
pluginsClientLines.push("import type {
|
|
187
|
-
pluginsClientLines.push("type
|
|
319
|
+
pluginsClientLines.push("import type { RouterContractClient, RouterContract } from \"@orpc/contract\";");
|
|
320
|
+
pluginsClientLines.push("import type { ContractedRouter } from \"@orpc/server\";");
|
|
321
|
+
pluginsClientLines.push("type PluginClientEntry<C extends RouterContract> = {\n client: (context?: Record<string, unknown>) => RouterContractClient<C>;\n router: ContractedRouter<C, any>;\n};");
|
|
188
322
|
pluginsClientLines.push("");
|
|
189
323
|
if (apiDepSources.length === 0 && unresolvedDepKeys.length === 0) pluginsClientLines.push("export type PluginsClient = Record<string, never>;");
|
|
190
324
|
else {
|
|
191
325
|
pluginsClientLines.push("export type PluginsClient = {");
|
|
192
326
|
for (const source of apiDepSources) {
|
|
193
327
|
const key = /^[$A-Z_][0-9A-Z_$]*$/i.test(source.key) ? source.key : JSON.stringify(source.key);
|
|
194
|
-
pluginsClientLines.push(` ${key}:
|
|
328
|
+
pluginsClientLines.push(` ${key}: PluginClientEntry<${source.importName}>;`);
|
|
195
329
|
}
|
|
196
330
|
for (const key of unresolvedDepKeys) {
|
|
197
331
|
const keyStr = /^[$A-Z_][0-9A-Z_$]*$/i.test(key) ? key : JSON.stringify(key);
|
|
198
|
-
pluginsClientLines.push(` ${keyStr}?:
|
|
332
|
+
pluginsClientLines.push(` ${keyStr}?: PluginClientEntry<RouterContract>;`);
|
|
199
333
|
}
|
|
200
334
|
pluginsClientLines.push("};");
|
|
201
335
|
}
|
|
@@ -208,13 +342,23 @@ function writeGeneratedFiles(opts) {
|
|
|
208
342
|
key: "auth"
|
|
209
343
|
});
|
|
210
344
|
for (const pluginKey of opts.pluginKeys) {
|
|
211
|
-
const
|
|
212
|
-
if (!
|
|
213
|
-
const depSources =
|
|
345
|
+
const localPath = opts.pluginLocalPaths?.[pluginKey];
|
|
346
|
+
if (!localPath) continue;
|
|
347
|
+
const depSources = (opts.pluginDependsOn?.[pluginKey] ?? []).map((depKey) => allSourcesForLookup.find((s) => s.key === depKey)).filter((s) => Boolean(s));
|
|
214
348
|
writePluginClientGen({
|
|
215
349
|
configDir: opts.configDir,
|
|
216
350
|
pluginKey,
|
|
217
|
-
depSources
|
|
351
|
+
depSources,
|
|
352
|
+
localPath
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (opts.authLocalPath) {
|
|
356
|
+
const depSources = (opts.authDependsOn ?? []).map((depKey) => allSourcesForLookup.find((s) => s.key === depKey)).filter((s) => Boolean(s));
|
|
357
|
+
writePluginClientGen({
|
|
358
|
+
configDir: opts.configDir,
|
|
359
|
+
pluginKey: "auth",
|
|
360
|
+
depSources,
|
|
361
|
+
localPath: opts.authLocalPath
|
|
218
362
|
});
|
|
219
363
|
}
|
|
220
364
|
const authTypeTargets = [join(opts.configDir, "ui", "src", "lib", "auth-types.gen.ts")];
|
|
@@ -223,8 +367,10 @@ function writeGeneratedFiles(opts) {
|
|
|
223
367
|
const hostLibDir = join(opts.configDir, "host", "src", "lib");
|
|
224
368
|
if (existsSync(join(opts.configDir, "host", "src"))) authTypeTargets.push(join(hostLibDir, "auth-types.gen.ts"));
|
|
225
369
|
for (const key of opts.pluginKeys) {
|
|
226
|
-
const
|
|
227
|
-
if (
|
|
370
|
+
const localPath = opts.pluginLocalPaths?.[key];
|
|
371
|
+
if (!localPath) continue;
|
|
372
|
+
const pluginSrcDir = join(localPath, "src");
|
|
373
|
+
if (existsSync(pluginSrcDir)) authTypeTargets.push(join(pluginSrcDir, "lib", "auth-types.gen.ts"));
|
|
228
374
|
}
|
|
229
375
|
if (opts.authExportPath) for (const authTypesPath of authTypeTargets) {
|
|
230
376
|
const exportImportPath = toImportPath(authTypesPath, opts.authExportPath);
|
|
@@ -232,17 +378,44 @@ function writeGeneratedFiles(opts) {
|
|
|
232
378
|
mkdirSync(dirname(authTypesPath), { recursive: true });
|
|
233
379
|
writeFileIfChanged(authTypesPath, buildAuthTypesGenContent(exportImportPath, contractImportPath));
|
|
234
380
|
}
|
|
235
|
-
else if (opts.authSource)
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
381
|
+
else if (opts.authSource) {
|
|
382
|
+
const generatedAuthExportPath = join(opts.configDir, ".bos", "generated", "auth", "auth-export.d.ts");
|
|
383
|
+
mkdirSync(dirname(generatedAuthExportPath), { recursive: true });
|
|
384
|
+
if (!existsSync(generatedAuthExportPath)) writeFileIfChanged(generatedAuthExportPath, buildAuthExportStub());
|
|
385
|
+
for (const authTypesPath of authTypeTargets) {
|
|
386
|
+
const exportImportPath = toImportPath(authTypesPath, generatedAuthExportPath);
|
|
387
|
+
const contractImportPath = toImportPath(authTypesPath, join(opts.configDir, ".bos", "generated", "auth", "contract.d.ts"));
|
|
388
|
+
mkdirSync(dirname(authTypesPath), { recursive: true });
|
|
389
|
+
writeFileIfChanged(authTypesPath, buildAuthTypesGenContent(exportImportPath, contractImportPath));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const localPluginKeys = new Set(Object.keys(opts.pluginLocalPaths ?? {}));
|
|
393
|
+
if (opts.authLocalPath) localPluginKeys.add("auth");
|
|
394
|
+
const pluginsRoot = join(opts.configDir, "plugins");
|
|
395
|
+
if (existsSync(pluginsRoot)) for (const entry of readdirSync(pluginsRoot, { withFileTypes: true })) {
|
|
396
|
+
if (!entry.isDirectory() || entry.name.startsWith("_") || localPluginKeys.has(entry.name)) continue;
|
|
397
|
+
for (const genName of ["plugins-client.gen.ts", "auth-types.gen.ts"]) {
|
|
398
|
+
const genPath = join(pluginsRoot, entry.name, "src", "lib", genName);
|
|
399
|
+
if (existsSync(genPath)) rmSync(genPath);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const generatedPluginsRoot = join(opts.configDir, ".bos", "generated", "plugins");
|
|
403
|
+
if (existsSync(generatedPluginsRoot)) {
|
|
404
|
+
const configuredKeys = new Set(opts.sources.map((source) => source.key));
|
|
405
|
+
for (const entry of readdirSync(generatedPluginsRoot, { withFileTypes: true })) {
|
|
406
|
+
if (!entry.isDirectory() || configuredKeys.has(entry.name)) continue;
|
|
407
|
+
rmSync(join(generatedPluginsRoot, entry.name), {
|
|
408
|
+
recursive: true,
|
|
409
|
+
force: true
|
|
410
|
+
});
|
|
411
|
+
}
|
|
240
412
|
}
|
|
241
413
|
return uiContractPath;
|
|
242
414
|
}
|
|
243
415
|
async function syncApiContractBridge(opts) {
|
|
244
416
|
const runtimeDir = join(opts.configDir, ".bos", "generated");
|
|
245
|
-
const
|
|
417
|
+
const isAuthMirrorEntry = (key, plugin) => isAuthMirrorPluginEntry(opts.runtimeConfig.auth, key, plugin);
|
|
418
|
+
const pluginEntries = Object.entries(opts.runtimeConfig.plugins ?? {}).filter(([key, plugin]) => !isAuthMirrorEntry(key, plugin)).sort(([a], [b]) => a.localeCompare(b));
|
|
246
419
|
const sources = [];
|
|
247
420
|
const status = [];
|
|
248
421
|
let manifest = null;
|
|
@@ -372,7 +545,12 @@ async function syncApiContractBridge(opts) {
|
|
|
372
545
|
if (apiStatus?.source === "failed") throw new Error(`Cannot generate contract types without api contract: ${apiStatus.error ?? "unknown error"}`);
|
|
373
546
|
const allPluginKeys = pluginEntries.filter(([key]) => !excludedPluginKeys.has(key)).map(([key]) => key);
|
|
374
547
|
const pluginDependsOn = {};
|
|
375
|
-
|
|
548
|
+
const pluginLocalPaths = {};
|
|
549
|
+
for (const [key, plugin] of pluginEntries) {
|
|
550
|
+
if (excludedPluginKeys.has(key)) continue;
|
|
551
|
+
if (plugin.dependsOn?.length) pluginDependsOn[key] = plugin.dependsOn;
|
|
552
|
+
if (plugin.localPath) pluginLocalPaths[key] = plugin.localPath;
|
|
553
|
+
}
|
|
376
554
|
writeGeneratedFiles({
|
|
377
555
|
configDir: opts.configDir,
|
|
378
556
|
sources,
|
|
@@ -380,7 +558,10 @@ async function syncApiContractBridge(opts) {
|
|
|
380
558
|
authSource,
|
|
381
559
|
authExportPath,
|
|
382
560
|
apiDependsOn: opts.runtimeConfig.api.dependsOn,
|
|
383
|
-
pluginDependsOn
|
|
561
|
+
pluginDependsOn,
|
|
562
|
+
pluginLocalPaths,
|
|
563
|
+
authLocalPath: opts.runtimeConfig.auth?.source === "local" ? opts.runtimeConfig.auth.localPath : void 0,
|
|
564
|
+
authDependsOn: opts.runtimeConfig.auth?.dependsOn
|
|
384
565
|
});
|
|
385
566
|
if (opts.runtimeConfig.api.source !== "local") manifest = await fetchApiPluginManifest(opts.apiBaseUrl);
|
|
386
567
|
return {
|
|
@@ -393,5 +574,5 @@ async function syncApiContractBridge(opts) {
|
|
|
393
574
|
}
|
|
394
575
|
|
|
395
576
|
//#endregion
|
|
396
|
-
export { fetchApiPluginManifest, syncApiContractBridge, writeGeneratedFiles };
|
|
577
|
+
export { ApiContractResolver, ApiManifestFetchError, ApiManifestFormatError, AuthExportFetchError, ContractTypesChecksumError, ContractTypesFetchError, MissingContractTypesError, fetchApiPluginManifest, syncApiContractBridge, writeGeneratedFiles };
|
|
397
578
|
//# sourceMappingURL=api-contract.mjs.map
|