@prisma/orm-toolchain 0.16.0-dev.36
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/LICENSE +201 -0
- package/README.md +28 -0
- package/dist/aggregate-B4mhR4Sk.mjs +1012 -0
- package/dist/aggregate-B4mhR4Sk.mjs.map +1 -0
- package/dist/aggregate-BflrjWPO.d.mts +803 -0
- package/dist/aggregate-BflrjWPO.d.mts.map +1 -0
- package/dist/bin__prisma-next.mjs +800 -0
- package/dist/bin__prisma-next.mjs.map +1 -0
- package/dist/cli-telemetry.d.mts +367 -0
- package/dist/cli-telemetry.d.mts.map +1 -0
- package/dist/cli-telemetry.mjs +48 -0
- package/dist/cli-telemetry.mjs.map +1 -0
- package/dist/cli-telemetry__sender.d.mts +1 -0
- package/dist/cli-telemetry__sender.mjs +1 -0
- package/dist/cli.d.mts +31 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +180 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/cli__commands__contract-emit.d.mts +2 -0
- package/dist/cli__commands__contract-emit.mjs +2 -0
- package/dist/cli__commands__contract-infer.d.mts +7 -0
- package/dist/cli__commands__contract-infer.d.mts.map +1 -0
- package/dist/cli__commands__contract-infer.mjs +2 -0
- package/dist/cli__commands__db-init.d.mts +7 -0
- package/dist/cli__commands__db-init.d.mts.map +1 -0
- package/dist/cli__commands__db-init.mjs +2 -0
- package/dist/cli__commands__db-schema.d.mts +7 -0
- package/dist/cli__commands__db-schema.d.mts.map +1 -0
- package/dist/cli__commands__db-schema.mjs +2 -0
- package/dist/cli__commands__db-sign.d.mts +7 -0
- package/dist/cli__commands__db-sign.d.mts.map +1 -0
- package/dist/cli__commands__db-sign.mjs +2 -0
- package/dist/cli__commands__db-update.d.mts +7 -0
- package/dist/cli__commands__db-update.d.mts.map +1 -0
- package/dist/cli__commands__db-update.mjs +2 -0
- package/dist/cli__commands__db-verify.d.mts +7 -0
- package/dist/cli__commands__db-verify.d.mts.map +1 -0
- package/dist/cli__commands__db-verify.mjs +2 -0
- package/dist/cli__commands__migrate.d.mts +66 -0
- package/dist/cli__commands__migrate.d.mts.map +1 -0
- package/dist/cli__commands__migrate.mjs +2 -0
- package/dist/cli__commands__migration-check.d.mts +64 -0
- package/dist/cli__commands__migration-check.d.mts.map +1 -0
- package/dist/cli__commands__migration-check.mjs +3 -0
- package/dist/cli__commands__migration-graph.d.mts +36 -0
- package/dist/cli__commands__migration-graph.d.mts.map +1 -0
- package/dist/cli__commands__migration-graph.mjs +2 -0
- package/dist/cli__commands__migration-list.d.mts +79 -0
- package/dist/cli__commands__migration-list.d.mts.map +1 -0
- package/dist/cli__commands__migration-list.mjs +2 -0
- package/dist/cli__commands__migration-log.d.mts +20 -0
- package/dist/cli__commands__migration-log.d.mts.map +1 -0
- package/dist/cli__commands__migration-log.mjs +2 -0
- package/dist/cli__commands__migration-new.d.mts +7 -0
- package/dist/cli__commands__migration-new.d.mts.map +1 -0
- package/dist/cli__commands__migration-new.mjs +2 -0
- package/dist/cli__commands__migration-plan.d.mts +79 -0
- package/dist/cli__commands__migration-plan.d.mts.map +1 -0
- package/dist/cli__commands__migration-plan.mjs +2 -0
- package/dist/cli__commands__migration-show.d.mts +27 -0
- package/dist/cli__commands__migration-show.d.mts.map +1 -0
- package/dist/cli__commands__migration-show.mjs +2 -0
- package/dist/cli__commands__migration-status.d.mts +55 -0
- package/dist/cli__commands__migration-status.d.mts.map +1 -0
- package/dist/cli__commands__migration-status.mjs +3 -0
- package/dist/cli__commands__ref.d.mts +34 -0
- package/dist/cli__commands__ref.d.mts.map +1 -0
- package/dist/cli__commands__ref.mjs +2 -0
- package/dist/cli__commands__telemetry.d.mts +7 -0
- package/dist/cli__commands__telemetry.d.mts.map +1 -0
- package/dist/cli__commands__telemetry.mjs +2 -0
- package/dist/cli__config-types.d.mts +2 -0
- package/dist/cli__config-types.mjs +2 -0
- package/dist/cli__control-api.d.mts +141 -0
- package/dist/cli__control-api.d.mts.map +1 -0
- package/dist/cli__control-api.mjs +4 -0
- package/dist/cli__init-output.d.mts +37 -0
- package/dist/cli__init-output.d.mts.map +1 -0
- package/dist/cli__init-output.mjs +2 -0
- package/dist/cli__migration-cli.d.mts +79 -0
- package/dist/cli__migration-cli.d.mts.map +1 -0
- package/dist/cli__migration-cli.mjs +407 -0
- package/dist/cli__migration-cli.mjs.map +1 -0
- package/dist/client-75qrAPqf-DZAVUxFa.mjs +1606 -0
- package/dist/client-75qrAPqf-DZAVUxFa.mjs.map +1 -0
- package/dist/command-helpers-CAoXqAY9-DWUBcTXM.mjs +1671 -0
- package/dist/command-helpers-CAoXqAY9-DWUBcTXM.mjs.map +1 -0
- package/dist/config-loader.d.mts +18 -0
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +2 -0
- package/dist/constants-CM-w38DQ-Cz_EXbOc.mjs +10 -0
- package/dist/constants-CM-w38DQ-Cz_EXbOc.mjs.map +1 -0
- package/dist/constants-Dkcn8Qu4.d.mts +10 -0
- package/dist/constants-Dkcn8Qu4.d.mts.map +1 -0
- package/dist/contract-at-errors-BX7w-p19-SxA8eaV2.mjs +36 -0
- package/dist/contract-at-errors-BX7w-p19-SxA8eaV2.mjs.map +1 -0
- package/dist/contract-emit-0hSjbuxp-BBOKldTZ.mjs +148 -0
- package/dist/contract-emit-0hSjbuxp-BBOKldTZ.mjs.map +1 -0
- package/dist/contract-emit-B65_UiFn.d.mts +7 -0
- package/dist/contract-emit-B65_UiFn.d.mts.map +1 -0
- package/dist/contract-emit-B6odMoem-CK3diBPk.mjs +359 -0
- package/dist/contract-emit-B6odMoem-CK3diBPk.mjs.map +1 -0
- package/dist/contract-enrichment-DrMvvY2A-DxNGeF4d.mjs +56 -0
- package/dist/contract-enrichment-DrMvvY2A-DxNGeF4d.mjs.map +1 -0
- package/dist/contract-infer-BnkqpftN-DVM2eKJ3.mjs +73 -0
- package/dist/contract-infer-BnkqpftN-DVM2eKJ3.mjs.map +1 -0
- package/dist/contract-snapshot-store-CbqynbtE.d.mts +28 -0
- package/dist/contract-snapshot-store-CbqynbtE.d.mts.map +1 -0
- package/dist/contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs +118 -0
- package/dist/contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs.map +1 -0
- package/dist/contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs +302 -0
- package/dist/contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs.map +1 -0
- package/dist/db-init-Vbkb_TKZ.mjs +153 -0
- package/dist/db-init-Vbkb_TKZ.mjs.map +1 -0
- package/dist/db-schema-ClQCu3xY.mjs +47 -0
- package/dist/db-schema-ClQCu3xY.mjs.map +1 -0
- package/dist/db-sign-jjXDgQ1u.mjs +175 -0
- package/dist/db-sign-jjXDgQ1u.mjs.map +1 -0
- package/dist/db-update-BQlrqtDD.mjs +183 -0
- package/dist/db-update-BQlrqtDD.mjs.map +1 -0
- package/dist/db-verify-CKPsRFrj-3udprZQD.mjs +396 -0
- package/dist/db-verify-CKPsRFrj-3udprZQD.mjs.map +1 -0
- package/dist/domain-type-generation-DAn9y5d2-BgoT5uKI.mjs +334 -0
- package/dist/domain-type-generation-DAn9y5d2-BgoT5uKI.mjs.map +1 -0
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts +63 -0
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts.map +1 -0
- package/dist/emitter.d.mts +75 -0
- package/dist/emitter.d.mts.map +1 -0
- package/dist/emitter.mjs +3 -0
- package/dist/emitter__domain-type-generation.d.mts +2 -0
- package/dist/emitter__domain-type-generation.mjs +2 -0
- package/dist/emitter__type-expression-safety.d.mts +6 -0
- package/dist/emitter__type-expression-safety.d.mts.map +1 -0
- package/dist/emitter__type-expression-safety.mjs +2 -0
- package/dist/errors--qsXZUtL.d.mts +72 -0
- package/dist/errors--qsXZUtL.d.mts.map +1 -0
- package/dist/errors-IpZm1Skp-BH495dRd.mjs +378 -0
- package/dist/errors-IpZm1Skp-BH495dRd.mjs.map +1 -0
- package/dist/exports-BN0vFTxG.mjs +276 -0
- package/dist/exports-BN0vFTxG.mjs.map +1 -0
- package/dist/exports-B_xhKZmC.mjs +1436 -0
- package/dist/exports-B_xhKZmC.mjs.map +1 -0
- package/dist/exports-D3-NwrMA-CadaBGQ3.mjs +154 -0
- package/dist/exports-D3-NwrMA-CadaBGQ3.mjs.map +1 -0
- package/dist/exports-Dl2aGAk7.mjs +119 -0
- package/dist/exports-Dl2aGAk7.mjs.map +1 -0
- package/dist/format-ByDm2goZ-DKLyhNHo.mjs +101 -0
- package/dist/format-ByDm2goZ-DKLyhNHo.mjs.map +1 -0
- package/dist/framework-components-CjshQKHA-Dlp6Leo5.mjs +58 -0
- package/dist/framework-components-CjshQKHA-Dlp6Leo5.mjs.map +1 -0
- package/dist/global-flags-BpoOYtNZ-CHZD3fud.d.mts +35 -0
- package/dist/global-flags-BpoOYtNZ-CHZD3fud.d.mts.map +1 -0
- package/dist/graph-bDjJ4GL9-BhFevsJS.d.mts +28 -0
- package/dist/graph-bDjJ4GL9-BhFevsJS.d.mts.map +1 -0
- package/dist/graph-membership-DW6nnbyQ-Bp2KcVwR.mjs +14 -0
- package/dist/graph-membership-DW6nnbyQ-Bp2KcVwR.mjs.map +1 -0
- package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs +64 -0
- package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs.map +1 -0
- package/dist/hash-XZYYKJ-i.d.mts +53 -0
- package/dist/hash-XZYYKJ-i.d.mts.map +1 -0
- package/dist/import-roots-B6CtsWXb.d.mts +119 -0
- package/dist/import-roots-B6CtsWXb.d.mts.map +1 -0
- package/dist/import-roots-NDOIEDVj.mjs +217 -0
- package/dist/import-roots-NDOIEDVj.mjs.map +1 -0
- package/dist/init-DHctXAI9-DSlaaYXN.mjs +2186 -0
- package/dist/init-DHctXAI9-DSlaaYXN.mjs.map +1 -0
- package/dist/inspect-live-schema-CnwYTRZ0-BErPHMni.mjs +91 -0
- package/dist/inspect-live-schema-CnwYTRZ0-BErPHMni.mjs.map +1 -0
- package/dist/invariants-B5wLrgQS.d.mts +39 -0
- package/dist/invariants-B5wLrgQS.d.mts.map +1 -0
- package/dist/invariants-lXzy6txi-DAoP4nTE.mjs +57 -0
- package/dist/invariants-lXzy6txi-DAoP4nTE.mjs.map +1 -0
- package/dist/io-C8TdyBKt-DloEBi70.mjs +313 -0
- package/dist/io-C8TdyBKt-DloEBi70.mjs.map +1 -0
- package/dist/io-DYfeLJxR.d.mts +1 -0
- package/dist/io-sr4CO9_t-C3eV_kn-.d.mts +125 -0
- package/dist/io-sr4CO9_t-C3eV_kn-.d.mts.map +1 -0
- package/dist/ledger-origin-BGRN77Oy.d.mts +6 -0
- package/dist/ledger-origin-BGRN77Oy.d.mts.map +1 -0
- package/dist/ledger-origin-D7PN4Fon.mjs +9 -0
- package/dist/ledger-origin-D7PN4Fon.mjs.map +1 -0
- package/dist/metadata-2nbOAGsV-uYNeq2Cp.d.mts +2 -0
- package/dist/metadata-BtscDay2.d.mts +1 -0
- package/dist/migrate-Cb_iv264.mjs +500 -0
- package/dist/migrate-Cb_iv264.mjs.map +1 -0
- package/dist/migration-B2ljMJim.d.mts +155 -0
- package/dist/migration-B2ljMJim.d.mts.map +1 -0
- package/dist/migration-BuUmO7It.mjs +209 -0
- package/dist/migration-BuUmO7It.mjs.map +1 -0
- package/dist/migration-check-CcG-fB8r-CDs5C9vt.mjs +597 -0
- package/dist/migration-check-CcG-fB8r-CDs5C9vt.mjs.map +1 -0
- package/dist/migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs +103 -0
- package/dist/migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs.map +1 -0
- package/dist/migration-graph-CBf9ORe7-B4xAF8GN.mjs +500 -0
- package/dist/migration-graph-CBf9ORe7-B4xAF8GN.mjs.map +1 -0
- package/dist/migration-graph-DkoCC0Qy.mjs +185 -0
- package/dist/migration-graph-DkoCC0Qy.mjs.map +1 -0
- package/dist/migration-graph-Dqndu0i5.d.mts +9 -0
- package/dist/migration-graph-Dqndu0i5.d.mts.map +1 -0
- package/dist/migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs +1945 -0
- package/dist/migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs.map +1 -0
- package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts +124 -0
- package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts.map +1 -0
- package/dist/migration-list-BFBeo1_X-c0kqYokL.mjs +228 -0
- package/dist/migration-list-BFBeo1_X-c0kqYokL.mjs.map +1 -0
- package/dist/migration-log-CS5IWcNq-BQ-32Low.mjs +220 -0
- package/dist/migration-log-CS5IWcNq-BQ-32Low.mjs.map +1 -0
- package/dist/migration-new-BurCjyaQ.mjs +168 -0
- package/dist/migration-new-BurCjyaQ.mjs.map +1 -0
- package/dist/migration-path-target-D3Sj55PI-BICblCuk.mjs +38 -0
- package/dist/migration-path-target-D3Sj55PI-BICblCuk.mjs.map +1 -0
- package/dist/migration-plan-q_L84PN1-BWE0LTH6.mjs +759 -0
- package/dist/migration-plan-q_L84PN1-BWE0LTH6.mjs.map +1 -0
- package/dist/migration-show-Bx5I5aW9.mjs +171 -0
- package/dist/migration-show-Bx5I5aW9.mjs.map +1 -0
- package/dist/migration-status-CFlzlRmu-DewBN8Ys.mjs +444 -0
- package/dist/migration-status-CFlzlRmu-DewBN8Ys.mjs.map +1 -0
- package/dist/migration-tools.d.mts +23 -0
- package/dist/migration-tools.mjs +17 -0
- package/dist/migration-tools__aggregate.d.mts +2 -0
- package/dist/migration-tools__aggregate.mjs +2 -0
- package/dist/migration-tools__constants.d.mts +2 -0
- package/dist/migration-tools__constants.mjs +2 -0
- package/dist/migration-tools__contract-snapshot-store.d.mts +2 -0
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -0
- package/dist/migration-tools__errors.d.mts +2 -0
- package/dist/migration-tools__errors.mjs +2 -0
- package/dist/migration-tools__graph.d.mts +2 -0
- package/dist/migration-tools__graph.mjs +1 -0
- package/dist/migration-tools__hash.d.mts +2 -0
- package/dist/migration-tools__hash.mjs +2 -0
- package/dist/migration-tools__invariants.d.mts +2 -0
- package/dist/migration-tools__invariants.mjs +2 -0
- package/dist/migration-tools__io.d.mts +3 -0
- package/dist/migration-tools__io.mjs +2 -0
- package/dist/migration-tools__ledger-origin.d.mts +2 -0
- package/dist/migration-tools__ledger-origin.mjs +2 -0
- package/dist/migration-tools__metadata.d.mts +3 -0
- package/dist/migration-tools__metadata.mjs +1 -0
- package/dist/migration-tools__migration-graph.d.mts +3 -0
- package/dist/migration-tools__migration-graph.mjs +3 -0
- package/dist/migration-tools__migration-ts.d.mts +2 -0
- package/dist/migration-tools__migration-ts.mjs +2 -0
- package/dist/migration-tools__migration.d.mts +2 -0
- package/dist/migration-tools__migration.mjs +2 -0
- package/dist/migration-tools__package.d.mts +3 -0
- package/dist/migration-tools__package.mjs +1 -0
- package/dist/migration-tools__ref-resolution.d.mts +2 -0
- package/dist/migration-tools__ref-resolution.mjs +2 -0
- package/dist/migration-tools__refs.d.mts +2 -0
- package/dist/migration-tools__refs.mjs +2 -0
- package/dist/migration-tools__spaces.d.mts +3 -0
- package/dist/migration-tools__spaces.mjs +3 -0
- package/dist/migration-ts-CNaAtK8C.d.mts +38 -0
- package/dist/migration-ts-CNaAtK8C.d.mts.map +1 -0
- package/dist/migration-ts-FyF55c4M.mjs +67 -0
- package/dist/migration-ts-FyF55c4M.mjs.map +1 -0
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +13 -0
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +1 -0
- package/dist/output-DWNYqZGc-D2sRgLAm.mjs +109 -0
- package/dist/output-DWNYqZGc-D2sRgLAm.mjs.map +1 -0
- package/dist/package-CfWiDNrr-ZR4HM_Iz.d.mts +21 -0
- package/dist/package-CfWiDNrr-ZR4HM_Iz.d.mts.map +1 -0
- package/dist/package-N9PPdFV_.d.mts +3 -0
- package/dist/progress-adapter-CjAeTxY_-BXYSd1eY.mjs +43 -0
- package/dist/progress-adapter-CjAeTxY_-BXYSd1eY.mjs.map +1 -0
- package/dist/project-import-root-CpwLCDLY-DkVwAnWj.mjs +99 -0
- package/dist/project-import-root-CpwLCDLY-DkVwAnWj.mjs.map +1 -0
- package/dist/publish-surface.d.mts +3 -0
- package/dist/publish-surface.mjs +3 -0
- package/dist/publish-surface__import-roots.d.mts +2 -0
- package/dist/publish-surface__import-roots.mjs +2 -0
- package/dist/publish-surface__shells.d.mts +2 -0
- package/dist/publish-surface__shells.mjs +2 -0
- package/dist/quick-reference-mongo.md +114 -0
- package/dist/quick-reference-postgres.md +93 -0
- package/dist/readme-mongo.md +35 -0
- package/dist/readme-postgres.md +34 -0
- package/dist/ref-B6cTthTi.mjs +171 -0
- package/dist/ref-B6cTthTi.mjs.map +1 -0
- package/dist/ref-advancement-CSPMoQs3-fEipZrdu.mjs +57 -0
- package/dist/ref-advancement-CSPMoQs3-fEipZrdu.mjs.map +1 -0
- package/dist/ref-resolution-BjJBWPjX.mjs +250 -0
- package/dist/ref-resolution-BjJBWPjX.mjs.map +1 -0
- package/dist/ref-resolution-COGOSL57.d.mts +127 -0
- package/dist/ref-resolution-COGOSL57.d.mts.map +1 -0
- package/dist/refs-BDbB9BRB-D6Za3Q49.mjs +241 -0
- package/dist/refs-BDbB9BRB-D6Za3Q49.mjs.map +1 -0
- package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts +43 -0
- package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts.map +1 -0
- package/dist/schemas-CeGMYFYX-h3OcU__O.d.mts +192 -0
- package/dist/schemas-CeGMYFYX-h3OcU__O.d.mts.map +1 -0
- package/dist/schemas-KhXMzNA_-CzZ7GFX_.mjs +112 -0
- package/dist/schemas-KhXMzNA_-CzZ7GFX_.mjs.map +1 -0
- package/dist/shells-BenrJHp2.mjs +602 -0
- package/dist/shells-BenrJHp2.mjs.map +1 -0
- package/dist/shells-COHV_Ozf.d.mts +135 -0
- package/dist/shells-COHV_Ozf.d.mts.map +1 -0
- package/dist/spaces-C27bA-xc.mjs +267 -0
- package/dist/spaces-C27bA-xc.mjs.map +1 -0
- package/dist/spaces-DxFj5y8l.d.mts +415 -0
- package/dist/spaces-DxFj5y8l.d.mts.map +1 -0
- package/dist/telemetry-CmbCa3Ld-CmE5zcIG.mjs +120 -0
- package/dist/telemetry-CmbCa3Ld-CmE5zcIG.mjs.map +1 -0
- package/dist/terminal-ui-BN4QOsm5-Bf3pim46.d.mts +133 -0
- package/dist/terminal-ui-BN4QOsm5-Bf3pim46.d.mts.map +1 -0
- package/dist/type-expression-safety-CgHTWypx.mjs +8 -0
- package/dist/type-expression-safety-CgHTWypx.mjs.map +1 -0
- package/dist/types-DZWEs4si-D8UlyJI0.d.mts +893 -0
- package/dist/types-DZWEs4si-D8UlyJI0.d.mts.map +1 -0
- package/dist/verify-DnVNjc5C-BGdsblBK.mjs +283 -0
- package/dist/verify-DnVNjc5C-BGdsblBK.mjs.map +1 -0
- package/dist/verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs +252 -0
- package/dist/verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs.map +1 -0
- package/dist/verify-contract-spaces-Cc1u_wJo-BilPJS2S.d.mts +136 -0
- package/dist/verify-contract-spaces-Cc1u_wJo-BilPJS2S.d.mts.map +1 -0
- package/dist/vite-plugin-contract-emit.d.mts +54 -0
- package/dist/vite-plugin-contract-emit.d.mts.map +1 -0
- package/dist/vite-plugin-contract-emit.mjs +303 -0
- package/dist/vite-plugin-contract-emit.mjs.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,1606 @@
|
|
|
1
|
+
import { O as errorNoInvariantPath } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
3
|
+
import { o as findPathWithDecision } from "./migration-graph-CBf9ORe7-B4xAF8GN.mjs";
|
|
4
|
+
import { t as CliStructuredError$1 } from "./command-helpers-CAoXqAY9-DWUBcTXM.mjs";
|
|
5
|
+
import { t as assertFrameworkComponentsCompatible } from "./framework-components-CjshQKHA-Dlp6Leo5.mjs";
|
|
6
|
+
import { t as enrichContract } from "./contract-enrichment-DrMvvY2A-DxNGeF4d.mjs";
|
|
7
|
+
import { t as emit } from "./exports-D3-NwrMA-CadaBGQ3.mjs";
|
|
8
|
+
import { d as resolveRecordedPath, f as verifyMigration, l as planMigration, n as buildFabricatedMigrationEdge, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as requireHeadRef } from "./aggregate-B4mhR4Sk.mjs";
|
|
9
|
+
import { t as buildContractSpaceAggregate } from "./contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs";
|
|
10
|
+
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
11
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
12
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
13
|
+
import { APP_SPACE_ID, createControlStack, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaSubjectClassifier, hasSchemaView } from "@prisma/orm-framework/components/control";
|
|
14
|
+
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
15
|
+
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
16
|
+
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
17
|
+
//#region ../../../1-framework/3-tooling/cli/dist/client-75qrAPqf.mjs
|
|
18
|
+
/**
|
|
19
|
+
* Strips operation objects to their public shape (id, label, operationClass).
|
|
20
|
+
* Used at the API boundary to avoid leaking internal fields (precheck, execute, postcheck, etc.).
|
|
21
|
+
*/
|
|
22
|
+
function stripOperations(operations) {
|
|
23
|
+
return operations.map((op) => ({
|
|
24
|
+
id: op.id,
|
|
25
|
+
label: op.label,
|
|
26
|
+
operationClass: op.operationClass
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Span id emitted via `onProgress` for the run phase. Stable
|
|
31
|
+
* identifier consumed by the structured-output renderer and by tests.
|
|
32
|
+
*/
|
|
33
|
+
const RUN_SPAN_ID = "apply";
|
|
34
|
+
/**
|
|
35
|
+
* Runner-driving tail shared by every run caller — `db init`,
|
|
36
|
+
* `db update`, and `migrate`. Consumes already-resolved per-space
|
|
37
|
+
* plans (the planner-vs-replay distinction is owned by the caller) and
|
|
38
|
+
* dispatches them to the runner in canonical order.
|
|
39
|
+
*
|
|
40
|
+
* Marker advancement is part of the runner's per-space transaction
|
|
41
|
+
* (the SQL family runner writes the marker as the last step of each
|
|
42
|
+
* space's transaction), so this primitive does not advance markers
|
|
43
|
+
* separately — by the time `execute` returns ok, every
|
|
44
|
+
* space's marker has been advanced to its plan's destination.
|
|
45
|
+
*
|
|
46
|
+
* Span emission (`spanStart 'apply'` / `spanEnd 'apply'`) is owned here
|
|
47
|
+
* so callers don't have to duplicate it; the `action` field on each
|
|
48
|
+
* progress event is taken from the caller's `action` argument.
|
|
49
|
+
*/
|
|
50
|
+
async function runMigration(inputs) {
|
|
51
|
+
const { aggregate, perSpacePlans, applyOrder, driver, familyInstance, migrations, frameworkComponents, policy, action, onProgress } = inputs;
|
|
52
|
+
const orderedResolutions = collectOrdered(applyOrder, perSpacePlans);
|
|
53
|
+
const runner = migrations.createRunner(familyInstance);
|
|
54
|
+
onProgress?.({
|
|
55
|
+
action,
|
|
56
|
+
kind: "spanStart",
|
|
57
|
+
spanId: RUN_SPAN_ID,
|
|
58
|
+
label: progressLabelForAction(action)
|
|
59
|
+
});
|
|
60
|
+
const perSpaceOptions = orderedResolutions.map((r) => ({
|
|
61
|
+
space: r.spaceId,
|
|
62
|
+
plan: r.entry.plan,
|
|
63
|
+
driver,
|
|
64
|
+
destinationContract: r.entry.destinationContract,
|
|
65
|
+
policy,
|
|
66
|
+
frameworkComponents,
|
|
67
|
+
migrationEdges: r.entry.migrationEdges,
|
|
68
|
+
strictVerification: false
|
|
69
|
+
}));
|
|
70
|
+
const runnerResult = await runner.execute({
|
|
71
|
+
driver,
|
|
72
|
+
perSpaceOptions
|
|
73
|
+
});
|
|
74
|
+
if (!runnerResult.ok) {
|
|
75
|
+
onProgress?.({
|
|
76
|
+
action,
|
|
77
|
+
kind: "spanEnd",
|
|
78
|
+
spanId: RUN_SPAN_ID,
|
|
79
|
+
outcome: "error"
|
|
80
|
+
});
|
|
81
|
+
return notOk({
|
|
82
|
+
summary: runnerResult.failure.summary,
|
|
83
|
+
...ifDefined("why", runnerResult.failure.why),
|
|
84
|
+
meta: {
|
|
85
|
+
...runnerResult.failure.meta ?? {},
|
|
86
|
+
failingSpace: runnerResult.failure.failingSpace,
|
|
87
|
+
runnerErrorCode: runnerResult.failure.code
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
onProgress?.({
|
|
92
|
+
action,
|
|
93
|
+
kind: "spanEnd",
|
|
94
|
+
spanId: RUN_SPAN_ID,
|
|
95
|
+
outcome: "ok"
|
|
96
|
+
});
|
|
97
|
+
return ok({
|
|
98
|
+
orderedResolutions,
|
|
99
|
+
totalOpsPlanned: runnerResult.value.perSpaceResults.reduce((sum, r) => sum + r.value.operationsPlanned, 0),
|
|
100
|
+
totalOpsExecuted: runnerResult.value.perSpaceResults.reduce((sum, r) => sum + r.value.operationsExecuted, 0),
|
|
101
|
+
perSpace: buildPerSpaceBreakdown(orderedResolutions, aggregate.app.spaceId, { includeMarkers: true })
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Project the planner's per-space resolutions into the
|
|
106
|
+
* `PerSpaceExecutionEntry[]` shape the CLI surfaces.
|
|
107
|
+
*
|
|
108
|
+
* `includeMarkers` is `true` for apply-mode (each space's marker is
|
|
109
|
+
* the `destination.storageHash` of its plan, which the runner
|
|
110
|
+
* advances as the last step of each space's transaction) and `false`
|
|
111
|
+
* for plan-mode (no marker has been written yet).
|
|
112
|
+
*
|
|
113
|
+
* Exported alongside {@link runMigration} so plan-mode callers can
|
|
114
|
+
* assemble the same per-space block without going through the runner.
|
|
115
|
+
*/
|
|
116
|
+
function buildPerSpaceBreakdown(orderedResolutions, appSpaceId, options) {
|
|
117
|
+
return orderedResolutions.map((r) => {
|
|
118
|
+
const operations = r.entry.displayOps.map((op) => ({
|
|
119
|
+
id: op.id,
|
|
120
|
+
label: op.label,
|
|
121
|
+
operationClass: op.operationClass
|
|
122
|
+
}));
|
|
123
|
+
const base = {
|
|
124
|
+
spaceId: r.spaceId,
|
|
125
|
+
kind: r.spaceId === appSpaceId ? "app" : "extension",
|
|
126
|
+
operations
|
|
127
|
+
};
|
|
128
|
+
if (!options.includeMarkers) return base;
|
|
129
|
+
return {
|
|
130
|
+
...base,
|
|
131
|
+
marker: { storageHash: r.entry.plan.destination.storageHash }
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Materialise the `applyOrder` ordering into resolved per-space
|
|
137
|
+
* entries. Throws if the planner output is missing a contract space listed
|
|
138
|
+
* in `applyOrder` — a wiring bug that should never reach runtime.
|
|
139
|
+
*
|
|
140
|
+
* Exported so callers building their own success envelopes after a
|
|
141
|
+
* plan-mode dispatch can replay the same ordering.
|
|
142
|
+
*/
|
|
143
|
+
function collectOrdered(applyOrder, perSpace) {
|
|
144
|
+
return applyOrder.map((spaceId) => {
|
|
145
|
+
const entry = perSpace.get(spaceId);
|
|
146
|
+
if (!entry) throw new InternalError(`planner output missing per-space plan for "${spaceId}"`);
|
|
147
|
+
return {
|
|
148
|
+
spaceId,
|
|
149
|
+
entry
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Action-appropriate label for the `spanStart` event the run
|
|
155
|
+
* primitive emits. `runMigration` is shared by `db init`, `db update`,
|
|
156
|
+
* and `migrate`; the span label tracks the user-visible action
|
|
157
|
+
* so structured-progress output reads naturally for each surface.
|
|
158
|
+
*/
|
|
159
|
+
function progressLabelForAction(action) {
|
|
160
|
+
switch (action) {
|
|
161
|
+
case "dbInit": return "Initialising database across spaces";
|
|
162
|
+
case "dbUpdate": return "Updating database across spaces";
|
|
163
|
+
case "migrate": return "Running migration plan across spaces";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Span IDs emitted via `onProgress` during the run flow.
|
|
168
|
+
* Stable identifiers consumed by the structured-output renderer and by
|
|
169
|
+
* tests asserting on span ids. The `apply` span itself is owned by
|
|
170
|
+
* the {@link runMigration} primitive — only the introspect / plan
|
|
171
|
+
* spans are emitted directly here.
|
|
172
|
+
*/
|
|
173
|
+
const SPAN_IDS$1 = {
|
|
174
|
+
introspect: "introspect",
|
|
175
|
+
plan: "plan"
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Loader → planner → runner pipeline shared by `db init` and `db update`.
|
|
179
|
+
*
|
|
180
|
+
* The pipeline:
|
|
181
|
+
*
|
|
182
|
+
* 1. **Load**: build a {@link ContractSpaceAggregate} from the descriptor
|
|
183
|
+
* set + on-disk on-disk artefacts. Any layout / drift / disjointness /
|
|
184
|
+
* integrity violation short-circuits with a structured error.
|
|
185
|
+
* 2. **Read DB state**: marker rows (`familyInstance.readAllMarkers`)
|
|
186
|
+
* + introspected schema (`familyInstance.introspect`).
|
|
187
|
+
* 3. **Plan**: {@link planMigration} chooses `resolveRecordedPath` vs
|
|
188
|
+
* `planFromDiff` per space according to `callerPolicy.ignoreGraphFor`.
|
|
189
|
+
* The app space is forced through `planFromDiff` (today's daily-driver
|
|
190
|
+
* behaviour); every extension space walks its on-disk graph via
|
|
191
|
+
* `resolveRecordedPath`.
|
|
192
|
+
* 4. **Apply** (when `mode === 'apply'`): every per-space `MigrationPlan`
|
|
193
|
+
* feeds into the runner's `execute` — one outer
|
|
194
|
+
* transaction across every space; failure on any space rolls back
|
|
195
|
+
* every space's writes.
|
|
196
|
+
*/
|
|
197
|
+
async function executeRun(options) {
|
|
198
|
+
const { driver, adapter, familyInstance, contract, mode, migrations, frameworkComponents, migrationsDir, extensions, targetId, policy, action, onProgress } = options;
|
|
199
|
+
const loaded = await buildContractSpaceAggregate({
|
|
200
|
+
targetId,
|
|
201
|
+
migrationsDir,
|
|
202
|
+
appContract: contract,
|
|
203
|
+
extensions,
|
|
204
|
+
deserializeContract: (json) => familyInstance.deserializeContract(json)
|
|
205
|
+
});
|
|
206
|
+
if (!loaded.ok) throw loaded.failure;
|
|
207
|
+
const aggregate = loaded.value;
|
|
208
|
+
const markerRows = await familyInstance.readAllMarkers({ driver });
|
|
209
|
+
if (mode === "apply") {
|
|
210
|
+
const orphanMarkerError = detectOrphanMarkers(aggregate, markerRows);
|
|
211
|
+
if (orphanMarkerError !== null) throw orphanMarkerError;
|
|
212
|
+
}
|
|
213
|
+
onProgress?.({
|
|
214
|
+
action,
|
|
215
|
+
kind: "spanStart",
|
|
216
|
+
spanId: SPAN_IDS$1.introspect,
|
|
217
|
+
label: "Introspecting database schema"
|
|
218
|
+
});
|
|
219
|
+
const schemaIR = await familyInstance.introspect({
|
|
220
|
+
driver,
|
|
221
|
+
contract: collectAggregateNamespaces(aggregate)
|
|
222
|
+
});
|
|
223
|
+
onProgress?.({
|
|
224
|
+
action,
|
|
225
|
+
kind: "spanEnd",
|
|
226
|
+
spanId: SPAN_IDS$1.introspect,
|
|
227
|
+
outcome: "ok"
|
|
228
|
+
});
|
|
229
|
+
onProgress?.({
|
|
230
|
+
action,
|
|
231
|
+
kind: "spanStart",
|
|
232
|
+
spanId: SPAN_IDS$1.plan,
|
|
233
|
+
label: "Planning migration"
|
|
234
|
+
});
|
|
235
|
+
const planResult = await planMigration({
|
|
236
|
+
aggregate,
|
|
237
|
+
currentDBState: {
|
|
238
|
+
markersBySpaceId: markerRows,
|
|
239
|
+
schemaIntrospection: schemaIR
|
|
240
|
+
},
|
|
241
|
+
adapter,
|
|
242
|
+
migrations,
|
|
243
|
+
frameworkComponents,
|
|
244
|
+
callerPolicy: { ignoreGraphFor: /* @__PURE__ */ new Set([aggregate.app.spaceId]) },
|
|
245
|
+
operationPolicy: policy
|
|
246
|
+
});
|
|
247
|
+
if (!planResult.ok) {
|
|
248
|
+
onProgress?.({
|
|
249
|
+
action,
|
|
250
|
+
kind: "spanEnd",
|
|
251
|
+
spanId: SPAN_IDS$1.plan,
|
|
252
|
+
outcome: "error"
|
|
253
|
+
});
|
|
254
|
+
return mapPlannerError(planResult.failure);
|
|
255
|
+
}
|
|
256
|
+
onProgress?.({
|
|
257
|
+
action,
|
|
258
|
+
kind: "spanEnd",
|
|
259
|
+
spanId: SPAN_IDS$1.plan,
|
|
260
|
+
outcome: "ok"
|
|
261
|
+
});
|
|
262
|
+
const orderedResolutions = collectOrdered(planResult.value.applyOrder, planResult.value.perSpace);
|
|
263
|
+
const plannerWarnings = aggregatePlannerWarnings(orderedResolutions);
|
|
264
|
+
const appResolution = orderedResolutions.find((r) => r.spaceId === aggregate.app.spaceId);
|
|
265
|
+
if (!appResolution) throw new InternalError("Aggregate planner returned no plan for the app space — the planner is supposed to always emit one.");
|
|
266
|
+
const appPlan = appResolution.entry.plan;
|
|
267
|
+
if (mode === "plan") {
|
|
268
|
+
const aggregateOps = orderedResolutions.flatMap((r) => r.entry.displayOps);
|
|
269
|
+
const preview = hasOperationPreview(familyInstance) ? familyInstance.toOperationPreview(aggregateOps) : void 0;
|
|
270
|
+
const perSpace = buildPerSpaceBreakdown(orderedResolutions, aggregate.app.spaceId, { includeMarkers: false });
|
|
271
|
+
const summary = `Planned ${aggregateOps.length} operation(s) across ${orderedResolutions.length} space(s)`;
|
|
272
|
+
return wrapPlanResult({
|
|
273
|
+
operations: aggregateOps,
|
|
274
|
+
destination: appPlan.destination,
|
|
275
|
+
preview,
|
|
276
|
+
perSpace,
|
|
277
|
+
summary,
|
|
278
|
+
...ifDefined("warnings", plannerWarnings)
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const applied = await runMigration({
|
|
282
|
+
aggregate,
|
|
283
|
+
perSpacePlans: planResult.value.perSpace,
|
|
284
|
+
applyOrder: planResult.value.applyOrder,
|
|
285
|
+
driver,
|
|
286
|
+
familyInstance,
|
|
287
|
+
migrations,
|
|
288
|
+
frameworkComponents,
|
|
289
|
+
policy,
|
|
290
|
+
action,
|
|
291
|
+
...ifDefined("onProgress", onProgress)
|
|
292
|
+
});
|
|
293
|
+
if (!applied.ok) return buildRunnerFailure({
|
|
294
|
+
summary: applied.failure.summary,
|
|
295
|
+
...ifDefined("why", applied.failure.why),
|
|
296
|
+
meta: applied.failure.meta,
|
|
297
|
+
...ifDefined("warnings", plannerWarnings)
|
|
298
|
+
});
|
|
299
|
+
const aggregateOps = applied.value.orderedResolutions.flatMap((r) => r.entry.displayOps);
|
|
300
|
+
const summary = action === "dbInit" ? `Applied ${applied.value.totalOpsExecuted} operation(s) across ${applied.value.orderedResolutions.length} space(s), database signed` : applied.value.totalOpsExecuted === 0 ? `Database already matches contract across ${applied.value.orderedResolutions.length} space(s), signature updated` : `Applied ${applied.value.totalOpsExecuted} operation(s) across ${applied.value.orderedResolutions.length} space(s), signature updated`;
|
|
301
|
+
return wrapApplyResult({
|
|
302
|
+
operations: aggregateOps,
|
|
303
|
+
destination: appPlan.destination,
|
|
304
|
+
operationsPlanned: applied.value.totalOpsPlanned,
|
|
305
|
+
operationsExecuted: applied.value.totalOpsExecuted,
|
|
306
|
+
perSpace: applied.value.perSpace,
|
|
307
|
+
summary,
|
|
308
|
+
...ifDefined("warnings", plannerWarnings)
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function aggregatePlannerWarnings(orderedResolutions) {
|
|
312
|
+
const warnings = orderedResolutions.flatMap((r) => r.entry.warnings ?? []);
|
|
313
|
+
return warnings.length > 0 ? warnings : void 0;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Compare the live `_prisma_marker` rows against the aggregate's
|
|
317
|
+
* declared contract spaces. Any marker row whose `space` is not a space of
|
|
318
|
+
* the aggregate is an "orphan" — typically a marker left behind by
|
|
319
|
+
* an extension that was removed from `extensions` without first
|
|
320
|
+
* cleaning up its on-disk migrations / database tables.
|
|
321
|
+
*
|
|
322
|
+
* Returns a {@link CliStructuredError} envelope (code
|
|
323
|
+
* `MIGRATION.CONTRACT_SPACE_VIOLATION`, `kind: 'orphanMarker'`) for the
|
|
324
|
+
* first orphan it finds, or `null`
|
|
325
|
+
* when every marker row maps to a declared contract space. Mirrors the M2
|
|
326
|
+
* `runContractSpaceVerifierMarkerCheck` envelope so downstream
|
|
327
|
+
* tooling (integration tests, JSON consumers) keeps asserting on the
|
|
328
|
+
* same shape.
|
|
329
|
+
*/
|
|
330
|
+
function detectOrphanMarkers(aggregate, markerRows) {
|
|
331
|
+
const aggregateSpaceIds = /* @__PURE__ */ new Set([aggregate.app.spaceId, ...aggregate.extensions.map((m) => m.spaceId)]);
|
|
332
|
+
const orphans = [];
|
|
333
|
+
for (const [spaceId, row] of markerRows) if (row !== null && row !== void 0 && !aggregateSpaceIds.has(spaceId)) orphans.push(spaceId);
|
|
334
|
+
if (orphans.length === 0) return null;
|
|
335
|
+
orphans.sort((a, b) => a.localeCompare(b));
|
|
336
|
+
return new CliStructuredError$1("MIGRATION.CONTRACT_SPACE_VIOLATION", orphans.length === 1 ? `Orphan contract-space marker detected for "${orphans[0]}"` : `Orphan contract-space markers detected for ${orphans.length} spaces`, {
|
|
337
|
+
why: `The database has \`_prisma_marker\` rows for spaces (${orphans.map((s) => `"${s}"`).join(", ")}) that are not declared in the project's \`extensions\`. The aggregate pipeline refuses to advance markers it cannot account for.`,
|
|
338
|
+
fix: "Either re-declare the missing extension(s) in `extensions` (so the aggregate owns them again), or remove the orphan marker row(s) from `_prisma_marker` once you have confirmed the corresponding tables can be safely retired.",
|
|
339
|
+
docsUrl: "https://pris.ly/contract-spaces",
|
|
340
|
+
meta: { violations: orphans.map((spaceId) => ({
|
|
341
|
+
kind: "orphanMarker",
|
|
342
|
+
spaceId
|
|
343
|
+
})) }
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function mapPlannerError(error) {
|
|
347
|
+
if (error.kind === "planFromDiffFailed") return blindCast(notOk({
|
|
348
|
+
code: "PLANNING_FAILED",
|
|
349
|
+
summary: "Migration planning failed due to conflicts",
|
|
350
|
+
conflicts: error.conflicts,
|
|
351
|
+
why: void 0,
|
|
352
|
+
meta: void 0
|
|
353
|
+
}));
|
|
354
|
+
if (error.kind === "extensionPathUnreachable") return buildRunnerFailure({
|
|
355
|
+
summary: `Cannot resolve apply path for extension space "${error.spaceId}"`,
|
|
356
|
+
why: `No path in the on-disk migration graph for extension space "${error.spaceId}" reaches the on-disk head ref hash "${error.target}".`,
|
|
357
|
+
meta: {
|
|
358
|
+
spaceId: error.spaceId,
|
|
359
|
+
target: error.target
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
if (error.kind === "extensionPathUnsatisfiable") return buildRunnerFailure({
|
|
363
|
+
summary: `Cannot resolve apply path for extension space "${error.spaceId}"`,
|
|
364
|
+
why: `On-disk migration graph for extension space "${error.spaceId}" reaches the on-disk head ref but does not cover required invariants: ${error.missingInvariants.join(", ")}.`,
|
|
365
|
+
meta: {
|
|
366
|
+
spaceId: error.spaceId,
|
|
367
|
+
missingInvariants: error.missingInvariants
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
return buildRunnerFailure({
|
|
371
|
+
summary: `Aggregate planner policy conflict for space "${error.spaceId}"`,
|
|
372
|
+
why: error.detail,
|
|
373
|
+
meta: { spaceId: error.spaceId }
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function wrapPlanResult(args) {
|
|
377
|
+
return ok({
|
|
378
|
+
mode: "plan",
|
|
379
|
+
plan: {
|
|
380
|
+
operations: stripOperations(args.operations),
|
|
381
|
+
...ifDefined("preview", args.preview)
|
|
382
|
+
},
|
|
383
|
+
destination: {
|
|
384
|
+
storageHash: args.destination.storageHash,
|
|
385
|
+
...ifDefined("profileHash", args.destination.profileHash)
|
|
386
|
+
},
|
|
387
|
+
perSpace: args.perSpace,
|
|
388
|
+
summary: args.summary,
|
|
389
|
+
...ifDefined("warnings", args.warnings)
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
function wrapApplyResult(args) {
|
|
393
|
+
return ok({
|
|
394
|
+
mode: "apply",
|
|
395
|
+
plan: { operations: stripOperations(args.operations) },
|
|
396
|
+
destination: {
|
|
397
|
+
storageHash: args.destination.storageHash,
|
|
398
|
+
...ifDefined("profileHash", args.destination.profileHash)
|
|
399
|
+
},
|
|
400
|
+
execution: {
|
|
401
|
+
operationsPlanned: args.operationsPlanned,
|
|
402
|
+
operationsExecuted: args.operationsExecuted
|
|
403
|
+
},
|
|
404
|
+
marker: args.destination.profileHash ? {
|
|
405
|
+
storageHash: args.destination.storageHash,
|
|
406
|
+
profileHash: args.destination.profileHash
|
|
407
|
+
} : { storageHash: args.destination.storageHash },
|
|
408
|
+
perSpace: args.perSpace,
|
|
409
|
+
summary: args.summary,
|
|
410
|
+
...ifDefined("warnings", args.warnings)
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function buildRunnerFailure(args) {
|
|
414
|
+
return blindCast(notOk({
|
|
415
|
+
code: "RUNNER_FAILED",
|
|
416
|
+
summary: args.summary,
|
|
417
|
+
why: args.why,
|
|
418
|
+
meta: args.meta,
|
|
419
|
+
conflicts: void 0,
|
|
420
|
+
...ifDefined("warnings", args.warnings)
|
|
421
|
+
}));
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Execute `db init` against the configured contract.
|
|
425
|
+
*
|
|
426
|
+
* Routes through the loader → planner → runner pipeline (sub-spec
|
|
427
|
+
* "Commit-by-commit § Commit 4"). Always additive-only; destructive
|
|
428
|
+
* changes belong to `db update`.
|
|
429
|
+
*/
|
|
430
|
+
async function executeDbInit(options) {
|
|
431
|
+
return await executeRun({
|
|
432
|
+
driver: options.driver,
|
|
433
|
+
adapter: options.adapter,
|
|
434
|
+
familyInstance: options.familyInstance,
|
|
435
|
+
contract: options.contract,
|
|
436
|
+
mode: options.mode,
|
|
437
|
+
migrations: options.migrations,
|
|
438
|
+
frameworkComponents: options.frameworkComponents,
|
|
439
|
+
migrationsDir: options.migrationsDir,
|
|
440
|
+
targetId: options.targetId,
|
|
441
|
+
extensions: options.extensions ?? [],
|
|
442
|
+
policy: { allowedOperationClasses: ["additive"] },
|
|
443
|
+
action: "dbInit",
|
|
444
|
+
...ifDefined("onProgress", options.onProgress)
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
const DB_UPDATE_POLICY = { allowedOperationClasses: [
|
|
448
|
+
"additive",
|
|
449
|
+
"widening",
|
|
450
|
+
"destructive"
|
|
451
|
+
] };
|
|
452
|
+
/**
|
|
453
|
+
* Execute `db update` against the configured contract.
|
|
454
|
+
*
|
|
455
|
+
* Routes through the loader → planner → runner pipeline. Destructive
|
|
456
|
+
* operations require either `acceptDataLoss: true` or a prior
|
|
457
|
+
* `mode: 'plan'` invocation that surfaces the destructive ops; the
|
|
458
|
+
* confirmation gate is implemented here so the lower-level applier
|
|
459
|
+
* remains policy-agnostic.
|
|
460
|
+
*/
|
|
461
|
+
async function executeDbUpdate(options) {
|
|
462
|
+
const sharedInputs = {
|
|
463
|
+
driver: options.driver,
|
|
464
|
+
adapter: options.adapter,
|
|
465
|
+
familyInstance: options.familyInstance,
|
|
466
|
+
contract: options.contract,
|
|
467
|
+
migrations: options.migrations,
|
|
468
|
+
frameworkComponents: options.frameworkComponents,
|
|
469
|
+
migrationsDir: options.migrationsDir,
|
|
470
|
+
targetId: options.targetId,
|
|
471
|
+
extensions: options.extensions ?? [],
|
|
472
|
+
policy: DB_UPDATE_POLICY,
|
|
473
|
+
action: "dbUpdate",
|
|
474
|
+
...ifDefined("onProgress", options.onProgress)
|
|
475
|
+
};
|
|
476
|
+
if (options.mode === "apply" && !options.acceptDataLoss) {
|
|
477
|
+
const gate = await guardDestructiveChanges(sharedInputs);
|
|
478
|
+
if (gate !== null) return gate;
|
|
479
|
+
}
|
|
480
|
+
return await executeRun({
|
|
481
|
+
...sharedInputs,
|
|
482
|
+
mode: options.mode
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Pre-plan once when running `db update apply` without `acceptDataLoss`.
|
|
487
|
+
* Surfaces destructive operations across every space; if any are
|
|
488
|
+
* planned, returns a `DESTRUCTIVE_CHANGES` failure that the CLI shows
|
|
489
|
+
* as a confirmation prompt. Returns `null` when the apply is safe to
|
|
490
|
+
* run.
|
|
491
|
+
*/
|
|
492
|
+
async function guardDestructiveChanges(sharedInputs) {
|
|
493
|
+
const planResult = await executeRun({
|
|
494
|
+
...sharedInputs,
|
|
495
|
+
mode: "plan"
|
|
496
|
+
});
|
|
497
|
+
if (!planResult.ok) return planResult;
|
|
498
|
+
const destructiveOps = planResult.value.plan.operations.filter((op) => op.operationClass === "destructive").map((op) => ({
|
|
499
|
+
id: op.id,
|
|
500
|
+
label: op.label
|
|
501
|
+
}));
|
|
502
|
+
if (destructiveOps.length === 0) return null;
|
|
503
|
+
return notOk({
|
|
504
|
+
code: "DESTRUCTIVE_CHANGES",
|
|
505
|
+
summary: `Planned ${destructiveOps.length} destructive operation(s) that require confirmation`,
|
|
506
|
+
why: "Destructive operations require confirmation — re-run with -y to accept",
|
|
507
|
+
conflicts: void 0,
|
|
508
|
+
meta: { destructiveOperations: destructiveOps }
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Span IDs emitted via `onProgress` during the aggregate verify flow.
|
|
513
|
+
* Mirrors the span identifiers used by the legacy precheck / marker-check
|
|
514
|
+
* helpers so structured-output renderers and progress tests keep working.
|
|
515
|
+
*/
|
|
516
|
+
const SPAN_IDS = {
|
|
517
|
+
introspect: "introspect",
|
|
518
|
+
verify: "verify"
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* Loader → verifier pipeline shared by `db verify` modes (`full`,
|
|
522
|
+
* `marker-only`, `schema-only`).
|
|
523
|
+
*
|
|
524
|
+
* 1. **Load**: build a {@link import('@internal/migration-tools/aggregate').ContractSpaceAggregate}
|
|
525
|
+
* from descriptors + on-disk on-disk artefacts. Layout / drift /
|
|
526
|
+
* integrity / disjointness violations short-circuit with a
|
|
527
|
+
* structured CLI error.
|
|
528
|
+
* 2. **Read DB state**: marker rows + (when `skipSchema` is `false`)
|
|
529
|
+
* schema introspection.
|
|
530
|
+
* 3. **Verify**: {@link verifyMigration} returns per-space `markerCheck` +
|
|
531
|
+
* per-space `schemaCheck` (each contract space verified against the full schema,
|
|
532
|
+
* then scoped to its own contract space). Marker mismatches map to
|
|
533
|
+
* `CliStructuredError` (code `5002`) so callers (CLI command) can render
|
|
534
|
+
* and exit. Verify results are returned to the caller verbatim.
|
|
535
|
+
*/
|
|
536
|
+
async function executeDbVerify(options) {
|
|
537
|
+
const { driver, familyInstance, onProgress, skipSchema, skipMarker } = options;
|
|
538
|
+
const loaded = await buildContractSpaceAggregate(buildLoadInputs(options));
|
|
539
|
+
if (!loaded.ok) return notOk(loaded.failure);
|
|
540
|
+
const aggregate = loaded.value;
|
|
541
|
+
const markersBySpaceId = await familyInstance.readAllMarkers({ driver });
|
|
542
|
+
const schemaIntrospection = skipSchema ? null : await runIntrospection({
|
|
543
|
+
driver,
|
|
544
|
+
familyInstance,
|
|
545
|
+
onProgress,
|
|
546
|
+
contract: collectAggregateNamespaces(aggregate)
|
|
547
|
+
});
|
|
548
|
+
const classifySubjectGranularity = hasSchemaSubjectClassifier(familyInstance) ? (issue) => familyInstance.classifySubjectGranularity(issue) : void 0;
|
|
549
|
+
const classifyEntityKind = hasSchemaSubjectClassifier(familyInstance) ? (issue) => familyInstance.classifyEntityKind(issue) : void 0;
|
|
550
|
+
emitVerifySpan(onProgress, "spanStart");
|
|
551
|
+
return finaliseVerifyResult({
|
|
552
|
+
verifyResult: verifyMigration({
|
|
553
|
+
aggregate,
|
|
554
|
+
markersBySpaceId,
|
|
555
|
+
schemaIntrospection,
|
|
556
|
+
mode: options.mode,
|
|
557
|
+
verifySchemaForSpace: createPerSpaceVerifier(options),
|
|
558
|
+
...ifDefined("classifySubjectGranularity", classifySubjectGranularity),
|
|
559
|
+
...ifDefined("classifyEntityKind", classifyEntityKind)
|
|
560
|
+
}),
|
|
561
|
+
aggregate,
|
|
562
|
+
skipMarker,
|
|
563
|
+
onProgress
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
function buildLoadInputs(options) {
|
|
567
|
+
return {
|
|
568
|
+
targetId: options.targetId,
|
|
569
|
+
migrationsDir: options.migrationsDir,
|
|
570
|
+
appContract: options.contract,
|
|
571
|
+
extensions: options.extensions,
|
|
572
|
+
deserializeContract: (json) => options.familyInstance.deserializeContract(json)
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
async function runIntrospection(args) {
|
|
576
|
+
const { driver, familyInstance, onProgress, contract } = args;
|
|
577
|
+
onProgress?.({
|
|
578
|
+
action: "dbVerify",
|
|
579
|
+
kind: "spanStart",
|
|
580
|
+
spanId: SPAN_IDS.introspect,
|
|
581
|
+
label: "Introspecting database schema"
|
|
582
|
+
});
|
|
583
|
+
try {
|
|
584
|
+
const result = await familyInstance.introspect({
|
|
585
|
+
driver,
|
|
586
|
+
contract
|
|
587
|
+
});
|
|
588
|
+
onProgress?.({
|
|
589
|
+
action: "dbVerify",
|
|
590
|
+
kind: "spanEnd",
|
|
591
|
+
spanId: SPAN_IDS.introspect,
|
|
592
|
+
outcome: "ok"
|
|
593
|
+
});
|
|
594
|
+
return result;
|
|
595
|
+
} catch (error) {
|
|
596
|
+
onProgress?.({
|
|
597
|
+
action: "dbVerify",
|
|
598
|
+
kind: "spanEnd",
|
|
599
|
+
spanId: SPAN_IDS.introspect,
|
|
600
|
+
outcome: "error"
|
|
601
|
+
});
|
|
602
|
+
throw error;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Build the per-space schema callback handed to the aggregate verifier.
|
|
607
|
+
* When `skipSchema` is true the callback short-circuits with a synthetic
|
|
608
|
+
* `ok` result so the verifier still runs the (cheap) schemaCheck loop
|
|
609
|
+
* without invoking the family's verification path.
|
|
610
|
+
*/
|
|
611
|
+
function createPerSpaceVerifier(options) {
|
|
612
|
+
const { skipSchema, familyInstance, frameworkComponents } = options;
|
|
613
|
+
return (schema, space, verifyMode) => {
|
|
614
|
+
if (skipSchema) return buildSkippedSchemaResult(space);
|
|
615
|
+
return familyInstance.verifySchema({
|
|
616
|
+
contract: space.contract(),
|
|
617
|
+
schema,
|
|
618
|
+
strict: verifyMode === "strict",
|
|
619
|
+
frameworkComponents
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function emitVerifySpan(onProgress, kind) {
|
|
624
|
+
if (kind === "spanStart") {
|
|
625
|
+
onProgress?.({
|
|
626
|
+
action: "dbVerify",
|
|
627
|
+
kind: "spanStart",
|
|
628
|
+
spanId: SPAN_IDS.verify,
|
|
629
|
+
label: "Verifying contract spaces"
|
|
630
|
+
});
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
onProgress?.({
|
|
634
|
+
action: "dbVerify",
|
|
635
|
+
kind: "spanEnd",
|
|
636
|
+
spanId: SPAN_IDS.verify,
|
|
637
|
+
outcome: kind === "spanEndOk" ? "ok" : "error"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Map an {@link VerifierOutput} to the operation's
|
|
642
|
+
* {@link ExecuteDbVerifyResult}, applying the `skipMarker` policy used
|
|
643
|
+
* by the CLI's `--schema-only` mode.
|
|
644
|
+
*/
|
|
645
|
+
function finaliseVerifyResult(args) {
|
|
646
|
+
const { verifyResult, aggregate, skipMarker, onProgress } = args;
|
|
647
|
+
if (!verifyResult.ok) {
|
|
648
|
+
emitVerifySpan(onProgress, "spanEndError");
|
|
649
|
+
return notOk(new CliStructuredError$1("MIGRATION.CONTRACT_SPACE_VIOLATION", "Aggregate verifier introspection failed", {
|
|
650
|
+
why: verifyResult.failure.detail,
|
|
651
|
+
fix: "Check database connectivity and the introspection tooling.",
|
|
652
|
+
docsUrl: "https://pris.ly/contract-spaces"
|
|
653
|
+
}));
|
|
654
|
+
}
|
|
655
|
+
const markerError = skipMarker ? null : mapMarkerCheckFailures(aggregate.app.spaceId, verifyResult.value.markerCheck);
|
|
656
|
+
if (markerError !== null) {
|
|
657
|
+
emitVerifySpan(onProgress, "spanEndError");
|
|
658
|
+
return notOk(markerError);
|
|
659
|
+
}
|
|
660
|
+
emitVerifySpan(onProgress, "spanEndOk");
|
|
661
|
+
return ok({
|
|
662
|
+
schemaResults: verifyResult.value.schemaCheck.perSpace,
|
|
663
|
+
unclaimed: verifyResult.value.schemaCheck.unclaimed,
|
|
664
|
+
spaceOrder: [aggregate.app.spaceId, ...aggregate.extensions.map((e) => e.spaceId)],
|
|
665
|
+
appSpaceId: aggregate.app.spaceId
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function buildSkippedSchemaResult(space) {
|
|
669
|
+
const contract = space.contract();
|
|
670
|
+
const headRef = requireHeadRef(space);
|
|
671
|
+
const profileHash = castAs(contract).profileHash;
|
|
672
|
+
return {
|
|
673
|
+
ok: true,
|
|
674
|
+
summary: "Schema verification skipped",
|
|
675
|
+
contract: {
|
|
676
|
+
storageHash: headRef.hash,
|
|
677
|
+
...profileHash ? { profileHash } : {}
|
|
678
|
+
},
|
|
679
|
+
target: { expected: contract.target },
|
|
680
|
+
schema: { issues: [] },
|
|
681
|
+
timings: { total: 0 }
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Translate per-space marker check failures and orphan markers into a
|
|
686
|
+
* single CLI structured error envelope. Preserves the legacy code
|
|
687
|
+
* `MIGRATION.CONTRACT_SPACE_VIOLATION` (was emitted by
|
|
688
|
+
* `runContractSpaceVerifierMarkerCheck`).
|
|
689
|
+
*/
|
|
690
|
+
function mapMarkerCheckFailures(appSpaceId, section) {
|
|
691
|
+
const violations = [];
|
|
692
|
+
for (const [spaceId, result] of section.perSpace) {
|
|
693
|
+
if (result.kind === "ok" || result.kind === "absent") continue;
|
|
694
|
+
if (result.kind === "hashMismatch") {
|
|
695
|
+
violations.push({
|
|
696
|
+
kind: "hashMismatch",
|
|
697
|
+
spaceId,
|
|
698
|
+
remediation: spaceId === appSpaceId ? "Run `prisma-next db update` to advance the marker, or roll the database back to the recorded hash." : `Apply on-disk migrations under \`migrations/${spaceId}/\` to advance the marker, or remove the conflicting marker row.`
|
|
699
|
+
});
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
if (result.kind === "missingInvariants") violations.push({
|
|
703
|
+
kind: "invariantsMismatch",
|
|
704
|
+
spaceId,
|
|
705
|
+
remediation: `Re-apply the migrations under \`migrations/${spaceId}/\` so the marker carries invariants: ${result.missing.join(", ")}.`
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
for (const orphan of section.orphanMarkers) violations.push({
|
|
709
|
+
kind: "orphanMarker",
|
|
710
|
+
spaceId: orphan.spaceId,
|
|
711
|
+
remediation: `Add the corresponding extension to \`extensions\` in \`prisma-next.config.ts\`, or delete the orphan marker row for "${orphan.spaceId}".`
|
|
712
|
+
});
|
|
713
|
+
if (violations.length === 0) return null;
|
|
714
|
+
const lines = violations.map((v) => `- [${v.kind}] ${v.spaceId}: ${v.remediation}`);
|
|
715
|
+
return new CliStructuredError$1("MIGRATION.CONTRACT_SPACE_VIOLATION", violations.length === 1 ? "Contract-space verifier found a violation" : `Contract-space verifier found violations (${violations.length})`, {
|
|
716
|
+
why: `The on-disk \`migrations/\` directory, the \`extensions\` declaration, and the live database marker rows are not in agreement.\n${lines.join("\n")}`,
|
|
717
|
+
fix: violations[0]?.remediation ?? "Review and reconcile the violations listed above.",
|
|
718
|
+
docsUrl: "https://pris.ly/contract-spaces",
|
|
719
|
+
meta: { violations }
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Apply pending migrations across every contract space (app +
|
|
724
|
+
* extensions). Replay-only: graph-walk against the on-disk graph for
|
|
725
|
+
* every contract space; no synth, no introspection.
|
|
726
|
+
*
|
|
727
|
+
* Pipeline:
|
|
728
|
+
*
|
|
729
|
+
* 1. Load aggregate from disk (loader hydrates extension graphs;
|
|
730
|
+
* caller provides app-space packages).
|
|
731
|
+
* 2. Read live marker rows per space (`familyInstance.readAllMarkers`).
|
|
732
|
+
* 3. Per space: `resolveRecordedPath` plots the path from the live
|
|
733
|
+
* marker to `space.headRef.hash` (or `refHash` for the app
|
|
734
|
+
* space when provided). An empty-graph space whose elements are ALL
|
|
735
|
+
* externally managed resolves declaratively (marker to head, zero
|
|
736
|
+
* ops), mirroring the db-init aggregate planner: such a space ships
|
|
737
|
+
* no DDL and has nothing to author. Every other empty-graph space
|
|
738
|
+
* fails loudly — "never planned" is a user-error condition for
|
|
739
|
+
* replay.
|
|
740
|
+
* 4. Hand off to {@link runMigration} (the runner-driving tail
|
|
741
|
+
* shared with `db init` / `db update`). Marker advancement is
|
|
742
|
+
* inside the per-space transaction.
|
|
743
|
+
*
|
|
744
|
+
* Encodes the replay-only contract: the app contract space must have an
|
|
745
|
+
* authored migration graph on disk before this operation can advance it.
|
|
746
|
+
*/
|
|
747
|
+
async function executeMigrate(options) {
|
|
748
|
+
const { driver, familyInstance, contract, migrations, frameworkComponents, migrationsDir, extensions, targetId, refHash, refInvariants, refName, onProgress } = options;
|
|
749
|
+
const loaded = await buildContractSpaceAggregate({
|
|
750
|
+
targetId,
|
|
751
|
+
migrationsDir,
|
|
752
|
+
appContract: contract,
|
|
753
|
+
extensions,
|
|
754
|
+
deserializeContract: (json) => familyInstance.deserializeContract(json)
|
|
755
|
+
});
|
|
756
|
+
if (!loaded.ok) throw loaded.failure;
|
|
757
|
+
const aggregate = loaded.value;
|
|
758
|
+
const markerRows = await familyInstance.readAllMarkers({ driver });
|
|
759
|
+
const allSpaces = [aggregate.app, ...aggregate.extensions];
|
|
760
|
+
const perSpacePlans = /* @__PURE__ */ new Map();
|
|
761
|
+
const atHeadResolutions = /* @__PURE__ */ new Map();
|
|
762
|
+
for (const space of allSpaces) {
|
|
763
|
+
const isAppSpace = space.spaceId === aggregate.app.spaceId;
|
|
764
|
+
const headRef = requireHeadRef(space);
|
|
765
|
+
const spaceTargetHash = isAppSpace && refHash !== void 0 ? refHash : headRef.hash;
|
|
766
|
+
const outcome = planSpacePath({
|
|
767
|
+
space,
|
|
768
|
+
aggregate,
|
|
769
|
+
targetHash: spaceTargetHash,
|
|
770
|
+
refInvariants: isAppSpace && refHash !== void 0 ? refInvariants : void 0,
|
|
771
|
+
liveMarker: markerRows.get(space.spaceId) ?? null,
|
|
772
|
+
...isAppSpace ? { refName } : {}
|
|
773
|
+
});
|
|
774
|
+
if (outcome.kind === "at-head") {
|
|
775
|
+
atHeadResolutions.set(space.spaceId, outcome.plan);
|
|
776
|
+
continue;
|
|
777
|
+
}
|
|
778
|
+
if (outcome.kind === "never-planned") return notOk(buildNeverPlannedFailure(outcome.spaceId, outcome.targetHash));
|
|
779
|
+
if (outcome.kind === "unreachable") return notOk(buildPathNotFoundFailure(outcome.spaceId, outcome.liveMarker, outcome.targetHash));
|
|
780
|
+
if (outcome.kind === "unsatisfiable") {
|
|
781
|
+
const structural = findPathWithDecision(outcome.targetSpace.graph(), outcome.liveHash, spaceTargetHash, { required: /* @__PURE__ */ new Set() });
|
|
782
|
+
const structuralPath = structural.kind === "ok" ? structural.decision.selectedPath.map((edge) => ({
|
|
783
|
+
dirName: edge.dirName,
|
|
784
|
+
migrationHash: edge.migrationHash,
|
|
785
|
+
from: edge.from,
|
|
786
|
+
to: edge.to,
|
|
787
|
+
invariants: edge.invariants
|
|
788
|
+
})) : [];
|
|
789
|
+
throw errorNoInvariantPath({
|
|
790
|
+
...outcome.refName !== void 0 ? { refName: outcome.refName } : {},
|
|
791
|
+
required: outcome.targetInvariants,
|
|
792
|
+
missing: outcome.missing,
|
|
793
|
+
structuralPath
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
perSpacePlans.set(space.spaceId, outcome.plan);
|
|
797
|
+
}
|
|
798
|
+
const canonicalOrder = [...aggregate.extensions.map((m) => m.spaceId), aggregate.app.spaceId];
|
|
799
|
+
const applyOrder = canonicalOrder.filter((spaceId) => perSpacePlans.has(spaceId));
|
|
800
|
+
if (!applyOrder.some((spaceId) => {
|
|
801
|
+
const entry = perSpacePlans.get(spaceId);
|
|
802
|
+
return entry !== void 0 && planRequiresExecution(entry);
|
|
803
|
+
})) {
|
|
804
|
+
const ordered = canonicalOrder.filter((spaceId) => perSpacePlans.has(spaceId) || atHeadResolutions.has(spaceId)).map((spaceId) => {
|
|
805
|
+
const entry = perSpacePlans.get(spaceId) ?? atHeadResolutions.get(spaceId);
|
|
806
|
+
if (entry === void 0) throw new InternalError(`Unreachable: missing per-space plan for "${spaceId}"`);
|
|
807
|
+
return {
|
|
808
|
+
spaceId,
|
|
809
|
+
entry
|
|
810
|
+
};
|
|
811
|
+
});
|
|
812
|
+
const perSpace = buildPerSpaceBreakdown(ordered, aggregate.app.spaceId, { includeMarkers: true });
|
|
813
|
+
const totalSpaces = ordered.length;
|
|
814
|
+
return ok(buildSuccess({
|
|
815
|
+
aggregate,
|
|
816
|
+
orderedResolutions: ordered,
|
|
817
|
+
perSpace,
|
|
818
|
+
totalOpsExecuted: 0,
|
|
819
|
+
summary: totalSpaces === 0 ? "Already up to date — no contract spaces are loaded" : totalSpaces === 1 ? "Already up to date" : `Already up to date across ${totalSpaces} space(s)`
|
|
820
|
+
}));
|
|
821
|
+
}
|
|
822
|
+
const applied = await runMigration({
|
|
823
|
+
aggregate,
|
|
824
|
+
perSpacePlans,
|
|
825
|
+
applyOrder,
|
|
826
|
+
driver,
|
|
827
|
+
familyInstance,
|
|
828
|
+
migrations,
|
|
829
|
+
frameworkComponents,
|
|
830
|
+
policy: { allowedOperationClasses: [
|
|
831
|
+
"additive",
|
|
832
|
+
"widening",
|
|
833
|
+
"destructive",
|
|
834
|
+
"data"
|
|
835
|
+
] },
|
|
836
|
+
action: "migrate",
|
|
837
|
+
...ifDefined("onProgress", onProgress)
|
|
838
|
+
});
|
|
839
|
+
if (!applied.ok) return notOk({
|
|
840
|
+
code: "RUNNER_FAILED",
|
|
841
|
+
summary: applied.failure.summary,
|
|
842
|
+
why: applied.failure.why,
|
|
843
|
+
meta: applied.failure.meta
|
|
844
|
+
});
|
|
845
|
+
const orderedAll = canonicalOrder.filter((spaceId) => perSpacePlans.has(spaceId) || atHeadResolutions.has(spaceId)).map((spaceId) => {
|
|
846
|
+
if (perSpacePlans.has(spaceId)) {
|
|
847
|
+
const fromRunner = applied.value.orderedResolutions.find((r) => r.spaceId === spaceId);
|
|
848
|
+
if (fromRunner !== void 0) return fromRunner;
|
|
849
|
+
}
|
|
850
|
+
const entry = atHeadResolutions.get(spaceId);
|
|
851
|
+
if (entry === void 0) throw new InternalError(`Unreachable: missing per-space plan for "${spaceId}"`);
|
|
852
|
+
return {
|
|
853
|
+
spaceId,
|
|
854
|
+
entry
|
|
855
|
+
};
|
|
856
|
+
});
|
|
857
|
+
const perSpaceAll = buildPerSpaceBreakdown(orderedAll, aggregate.app.spaceId, { includeMarkers: true });
|
|
858
|
+
const summary = `Applied ${applied.value.orderedResolutions.reduce((sum, r) => sum + r.entry.migrationEdges.length, 0)} migration(s) (${applied.value.totalOpsExecuted} operation(s)) across ${orderedAll.length} contract space(s)`;
|
|
859
|
+
return ok(buildSuccess({
|
|
860
|
+
aggregate,
|
|
861
|
+
orderedResolutions: orderedAll,
|
|
862
|
+
perSpace: perSpaceAll,
|
|
863
|
+
totalOpsExecuted: applied.value.totalOpsExecuted,
|
|
864
|
+
summary
|
|
865
|
+
}));
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Compute the graph-walk path for one contract space.
|
|
869
|
+
*
|
|
870
|
+
* Encapsulates the invariant-correct input assembly that both
|
|
871
|
+
* `executeMigrate` and `executeMigrateShowCommand` must use:
|
|
872
|
+
* - `currentMarker` carries the full live marker including `invariants`
|
|
873
|
+
* (not a stripped `{ storageHash, invariants: [] }` shell).
|
|
874
|
+
* - `targetInvariants` uses the caller-supplied `refInvariants` when a
|
|
875
|
+
* `--to` ref was resolved (not always the file head ref's invariants).
|
|
876
|
+
*
|
|
877
|
+
* Both callers map the returned `SpacePathOutcome` to their own error
|
|
878
|
+
* representation; the path-compute logic is shared and identical.
|
|
879
|
+
*
|
|
880
|
+
* @internal Exported for `executeMigrateShowCommand`.
|
|
881
|
+
*/
|
|
882
|
+
function planSpacePath({ space, aggregate, targetHash, refInvariants, liveMarker, refName }) {
|
|
883
|
+
const isAppSpace = space.spaceId === aggregate.app.spaceId;
|
|
884
|
+
const headRef = requireHeadRef(space);
|
|
885
|
+
if (space.graph().nodes.size === 0) {
|
|
886
|
+
const liveHash = liveMarker?.storageHash;
|
|
887
|
+
if (targetHash === liveHash || liveHash === void 0 && targetHash === "empty") return {
|
|
888
|
+
kind: "at-head",
|
|
889
|
+
plan: buildAtHeadResolution({
|
|
890
|
+
aggregateTargetId: aggregate.targetId,
|
|
891
|
+
space,
|
|
892
|
+
targetHash,
|
|
893
|
+
liveMarker
|
|
894
|
+
})
|
|
895
|
+
};
|
|
896
|
+
if (!isAppSpace && allStorageElementsExternal(space.contract())) {
|
|
897
|
+
if (headRef.invariants.length > 0) return {
|
|
898
|
+
kind: "unsatisfiable",
|
|
899
|
+
spaceId: space.spaceId,
|
|
900
|
+
isAppSpace,
|
|
901
|
+
missing: [...headRef.invariants].sort(),
|
|
902
|
+
targetInvariants: headRef.invariants,
|
|
903
|
+
targetSpace: space,
|
|
904
|
+
liveHash: liveHash ?? "empty",
|
|
905
|
+
refName: void 0
|
|
906
|
+
};
|
|
907
|
+
return {
|
|
908
|
+
kind: "ok",
|
|
909
|
+
plan: buildAtHeadResolution({
|
|
910
|
+
aggregateTargetId: aggregate.targetId,
|
|
911
|
+
space,
|
|
912
|
+
targetHash,
|
|
913
|
+
liveMarker
|
|
914
|
+
})
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return {
|
|
918
|
+
kind: "never-planned",
|
|
919
|
+
spaceId: space.spaceId,
|
|
920
|
+
targetHash
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
const targetInvariants = isAppSpace && refInvariants !== void 0 ? refInvariants : headRef.invariants;
|
|
924
|
+
const targetSpace = targetHash === headRef.hash && targetInvariants === headRef.invariants ? space : {
|
|
925
|
+
...space,
|
|
926
|
+
headRef: {
|
|
927
|
+
hash: targetHash,
|
|
928
|
+
invariants: targetInvariants
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
const walked = resolveRecordedPath({
|
|
932
|
+
aggregateTargetId: aggregate.targetId,
|
|
933
|
+
space: targetSpace,
|
|
934
|
+
currentMarker: liveMarker,
|
|
935
|
+
...isAppSpace && refName !== void 0 ? { refName } : {}
|
|
936
|
+
});
|
|
937
|
+
if (walked.kind === "unreachable") return {
|
|
938
|
+
kind: "unreachable",
|
|
939
|
+
spaceId: space.spaceId,
|
|
940
|
+
liveMarker,
|
|
941
|
+
targetHash
|
|
942
|
+
};
|
|
943
|
+
if (walked.kind === "unsatisfiable") {
|
|
944
|
+
const liveHash = liveMarker?.storageHash ?? "empty";
|
|
945
|
+
return {
|
|
946
|
+
kind: "unsatisfiable",
|
|
947
|
+
spaceId: space.spaceId,
|
|
948
|
+
isAppSpace,
|
|
949
|
+
missing: walked.missing,
|
|
950
|
+
targetInvariants,
|
|
951
|
+
targetSpace,
|
|
952
|
+
liveHash,
|
|
953
|
+
refName
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
return {
|
|
957
|
+
kind: "ok",
|
|
958
|
+
plan: walked.result
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Build a zero-op {@link PerSpacePlan} for an empty-graph space —
|
|
963
|
+
* either one whose live marker already matches the target (at-head), or
|
|
964
|
+
* an all-external extension space whose marker must advance to the head
|
|
965
|
+
* ref with no DDL (declared-state). Lets the apply pipeline thread the
|
|
966
|
+
* space through `perSpacePlans` -> `applyOrder` -> the success
|
|
967
|
+
* envelope's `perSpace[]` block so the result reflects every loaded
|
|
968
|
+
* space, even when there is nothing to execute.
|
|
969
|
+
*/
|
|
970
|
+
function buildAtHeadResolution(args) {
|
|
971
|
+
const { aggregateTargetId, space, targetHash, liveMarker } = args;
|
|
972
|
+
return {
|
|
973
|
+
plan: {
|
|
974
|
+
targetId: aggregateTargetId,
|
|
975
|
+
spaceId: space.spaceId,
|
|
976
|
+
origin: liveMarker === null ? null : { storageHash: liveMarker.storageHash },
|
|
977
|
+
destination: { storageHash: targetHash },
|
|
978
|
+
operations: [],
|
|
979
|
+
providedInvariants: []
|
|
980
|
+
},
|
|
981
|
+
displayOps: [],
|
|
982
|
+
destinationContract: space.contract(),
|
|
983
|
+
strategy: "declared-state",
|
|
984
|
+
migrationEdges: [buildFabricatedMigrationEdge({
|
|
985
|
+
currentMarkerStorageHash: liveMarker?.storageHash,
|
|
986
|
+
destinationStorageHash: targetHash,
|
|
987
|
+
operationCount: 0
|
|
988
|
+
})]
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* A plan needs the runner when it executes operations or advances the
|
|
993
|
+
* space's marker (a declared-state resolution has zero operations but a
|
|
994
|
+
* destination hash the live marker doesn't carry yet).
|
|
995
|
+
*/
|
|
996
|
+
function planRequiresExecution(entry) {
|
|
997
|
+
if (entry.plan.operations.length > 0) return true;
|
|
998
|
+
return entry.plan.origin?.storageHash !== entry.plan.destination.storageHash;
|
|
999
|
+
}
|
|
1000
|
+
function buildSuccess(args) {
|
|
1001
|
+
const appResolution = args.orderedResolutions.find((r) => r.spaceId === args.aggregate.app.spaceId);
|
|
1002
|
+
const appMarkerHash = appResolution?.entry.plan.destination.storageHash ?? requireHeadRef(args.aggregate.app).hash;
|
|
1003
|
+
const applied = args.orderedResolutions.flatMap((r) => {
|
|
1004
|
+
return r.entry.migrationEdges.map((edge) => ({
|
|
1005
|
+
spaceId: r.spaceId,
|
|
1006
|
+
dirName: edge.dirName,
|
|
1007
|
+
migrationHash: edge.migrationHash,
|
|
1008
|
+
from: edge.from,
|
|
1009
|
+
to: edge.to,
|
|
1010
|
+
operationsExecuted: edge.operationCount
|
|
1011
|
+
}));
|
|
1012
|
+
});
|
|
1013
|
+
const appPlan = appResolution?.entry;
|
|
1014
|
+
const pathDecision = appPlan?.pathDecision ? {
|
|
1015
|
+
fromHash: appPlan.pathDecision.fromHash,
|
|
1016
|
+
toHash: appPlan.pathDecision.toHash,
|
|
1017
|
+
alternativeCount: appPlan.pathDecision.alternativeCount,
|
|
1018
|
+
tieBreakReasons: appPlan.pathDecision.tieBreakReasons,
|
|
1019
|
+
...appPlan.pathDecision.refName !== void 0 ? { refName: appPlan.pathDecision.refName } : {},
|
|
1020
|
+
requiredInvariants: appPlan.pathDecision.requiredInvariants ?? [],
|
|
1021
|
+
satisfiedInvariants: appPlan.pathDecision.satisfiedInvariants ?? [],
|
|
1022
|
+
selectedPath: appPlan.pathDecision.selectedPath.map((entry) => ({
|
|
1023
|
+
dirName: entry.dirName,
|
|
1024
|
+
migrationHash: entry.migrationHash,
|
|
1025
|
+
from: entry.from,
|
|
1026
|
+
to: entry.to,
|
|
1027
|
+
invariants: entry.invariants
|
|
1028
|
+
}))
|
|
1029
|
+
} : void 0;
|
|
1030
|
+
return {
|
|
1031
|
+
migrationsApplied: applied.length,
|
|
1032
|
+
markerHash: appMarkerHash,
|
|
1033
|
+
applied,
|
|
1034
|
+
summary: args.summary,
|
|
1035
|
+
perSpace: args.perSpace,
|
|
1036
|
+
...pathDecision !== void 0 ? { pathDecision } : {}
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Build the `neverPlanned` failure raised when a contract space that
|
|
1041
|
+
* declares managed storage elements has no on-disk migration graph but
|
|
1042
|
+
* migrate was asked to reach a target hash. All-external spaces never reach
|
|
1043
|
+
* this: they resolve declaratively (marker advances to the head ref with
|
|
1044
|
+
* zero operations). The `why` states only the condition; the recovery
|
|
1045
|
+
* sequence is composed by `errorPathUnreachable`'s `fix`.
|
|
1046
|
+
*
|
|
1047
|
+
* @internal Exported for testing only.
|
|
1048
|
+
*/
|
|
1049
|
+
function buildNeverPlannedFailure(spaceId, targetHash) {
|
|
1050
|
+
return {
|
|
1051
|
+
code: "MIGRATION_PATH_NOT_FOUND",
|
|
1052
|
+
summary: `No on-disk migrations for contract space "${spaceId}"`,
|
|
1053
|
+
why: `migrate is replay-only: a contract space that declares managed storage elements must have an authored migration graph on disk. Space "${spaceId}" has no migrations under \`migrations/${spaceId}/\` but its head ref targets "${targetHash}".`,
|
|
1054
|
+
meta: {
|
|
1055
|
+
spaceId,
|
|
1056
|
+
target: targetHash,
|
|
1057
|
+
kind: "neverPlanned"
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Build the `pathUnreachable` failure raised when an emitted contract has no
|
|
1063
|
+
* on-disk migration edge from the current marker to the target. The `why`
|
|
1064
|
+
* states only the condition (no edge between the two named states, and migrate
|
|
1065
|
+
* replays edges rather than inventing them); the recovery sequence — plan the
|
|
1066
|
+
* edge, then re-apply — is composed by `errorPathUnreachable`'s `fix`, so the
|
|
1067
|
+
* two read as one non-redundant plan-then-apply story.
|
|
1068
|
+
*
|
|
1069
|
+
* @internal Exported for testing only.
|
|
1070
|
+
*/
|
|
1071
|
+
function buildPathNotFoundFailure(spaceId, marker, targetHash) {
|
|
1072
|
+
const fromHash = marker?.storageHash ?? "<empty>";
|
|
1073
|
+
return {
|
|
1074
|
+
code: "MIGRATION_PATH_NOT_FOUND",
|
|
1075
|
+
summary: spaceId === "app" ? "Current contract has no planned migration path" : `Current contract has no planned migration path for contract space "${spaceId}"`,
|
|
1076
|
+
why: `No migration edge connects the current state "${fromHash}" to the target "${targetHash}" in contract space "${spaceId}". The on-disk migration graph does not join the two, and migrate replays existing edges — it never invents one.`,
|
|
1077
|
+
meta: {
|
|
1078
|
+
spaceId,
|
|
1079
|
+
fromHash,
|
|
1080
|
+
targetHash,
|
|
1081
|
+
kind: "pathUnreachable"
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Creates a programmatic control client for Prisma Next operations.
|
|
1087
|
+
*
|
|
1088
|
+
* The client accepts framework component descriptors at creation time,
|
|
1089
|
+
* manages driver lifecycle via connect()/close(), and exposes domain
|
|
1090
|
+
* operations that delegate to the existing family instance methods.
|
|
1091
|
+
*
|
|
1092
|
+
* @see {@link ControlClient} for the client interface
|
|
1093
|
+
* @see README.md "Programmatic Control API" section for usage examples
|
|
1094
|
+
*/
|
|
1095
|
+
function createControlClient(options) {
|
|
1096
|
+
return new ControlClientImpl(options);
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Implementation of ControlClient.
|
|
1100
|
+
* Manages initialization and connection state, delegates operations to family instance.
|
|
1101
|
+
*/
|
|
1102
|
+
var ControlClientImpl = class {
|
|
1103
|
+
options;
|
|
1104
|
+
stack = null;
|
|
1105
|
+
driver = null;
|
|
1106
|
+
familyInstance = null;
|
|
1107
|
+
frameworkComponents = null;
|
|
1108
|
+
initialized = false;
|
|
1109
|
+
defaultConnection;
|
|
1110
|
+
constructor(options) {
|
|
1111
|
+
this.options = options;
|
|
1112
|
+
this.defaultConnection = options.connection;
|
|
1113
|
+
}
|
|
1114
|
+
init() {
|
|
1115
|
+
if (this.initialized) return;
|
|
1116
|
+
this.stack = createControlStack({
|
|
1117
|
+
family: this.options.family,
|
|
1118
|
+
target: this.options.target,
|
|
1119
|
+
adapter: this.options.adapter,
|
|
1120
|
+
driver: this.options.driver,
|
|
1121
|
+
extensions: this.options.extensions
|
|
1122
|
+
});
|
|
1123
|
+
this.familyInstance = this.options.family.create(this.stack);
|
|
1124
|
+
const rawComponents = [
|
|
1125
|
+
this.options.target,
|
|
1126
|
+
this.options.adapter,
|
|
1127
|
+
...this.options.extensions ?? []
|
|
1128
|
+
];
|
|
1129
|
+
this.frameworkComponents = assertFrameworkComponentsCompatible(this.options.family.familyId, this.options.target.targetId, rawComponents);
|
|
1130
|
+
this.initialized = true;
|
|
1131
|
+
}
|
|
1132
|
+
async connect(connection) {
|
|
1133
|
+
this.init();
|
|
1134
|
+
if (this.driver) throw new CliStructuredError("DRIVER.ALREADY_CONNECTED", "Already connected. Call close() before reconnecting.");
|
|
1135
|
+
const resolvedConnection = connection ?? this.defaultConnection;
|
|
1136
|
+
if (resolvedConnection === void 0) throw new CliStructuredError("CONFIG.DB_CONNECTION_REQUIRED", "No connection provided. Pass a connection to connect() or provide a default connection when creating the client.");
|
|
1137
|
+
if (!this.stack?.driver) throw new CliStructuredError("CONFIG.DRIVER_REQUIRED", "Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations.");
|
|
1138
|
+
this.driver = await this.stack.driver.create(resolvedConnection);
|
|
1139
|
+
}
|
|
1140
|
+
async close() {
|
|
1141
|
+
if (this.driver) {
|
|
1142
|
+
await this.driver.close();
|
|
1143
|
+
this.driver = null;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Construct the control adapter once for a migration operation and return
|
|
1148
|
+
* it, mirroring how the runtime plane builds the execution adapter once in
|
|
1149
|
+
* `createExecutionStack`. Only `dbInit` / `dbUpdate` need it (it lowers the
|
|
1150
|
+
* planner's DDL); read-only operations never build it. The descriptor is
|
|
1151
|
+
* optional on the stack — targets without migrations omit it.
|
|
1152
|
+
*/
|
|
1153
|
+
buildControlAdapter() {
|
|
1154
|
+
this.init();
|
|
1155
|
+
if (!this.stack?.adapter) throw new CliStructuredError("MIGRATION.TARGET_UNSUPPORTED", `Target "${this.options.target.targetId}" requires an adapter for migrations`);
|
|
1156
|
+
return this.stack.adapter.create(this.stack);
|
|
1157
|
+
}
|
|
1158
|
+
async ensureConnected() {
|
|
1159
|
+
this.init();
|
|
1160
|
+
if (!this.driver && this.defaultConnection !== void 0) await this.connect(this.defaultConnection);
|
|
1161
|
+
if (!this.driver || !this.familyInstance || !this.frameworkComponents) throw new CliStructuredError("DRIVER.NOT_CONNECTED", "Not connected. Call connect(connection) first.");
|
|
1162
|
+
return {
|
|
1163
|
+
driver: this.driver,
|
|
1164
|
+
familyInstance: this.familyInstance,
|
|
1165
|
+
frameworkComponents: this.frameworkComponents
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
async connectWithProgress(connection, action, onProgress) {
|
|
1169
|
+
if (connection === void 0) return;
|
|
1170
|
+
onProgress?.({
|
|
1171
|
+
action,
|
|
1172
|
+
kind: "spanStart",
|
|
1173
|
+
spanId: "connect",
|
|
1174
|
+
label: "Connecting to database..."
|
|
1175
|
+
});
|
|
1176
|
+
try {
|
|
1177
|
+
await this.connect(connection);
|
|
1178
|
+
onProgress?.({
|
|
1179
|
+
action,
|
|
1180
|
+
kind: "spanEnd",
|
|
1181
|
+
spanId: "connect",
|
|
1182
|
+
outcome: "ok"
|
|
1183
|
+
});
|
|
1184
|
+
} catch (error) {
|
|
1185
|
+
onProgress?.({
|
|
1186
|
+
action,
|
|
1187
|
+
kind: "spanEnd",
|
|
1188
|
+
spanId: "connect",
|
|
1189
|
+
outcome: "error"
|
|
1190
|
+
});
|
|
1191
|
+
throw error;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
async verify(options) {
|
|
1195
|
+
const { onProgress } = options;
|
|
1196
|
+
await this.connectWithProgress(options.connection, "verify", onProgress);
|
|
1197
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
1198
|
+
let contract;
|
|
1199
|
+
try {
|
|
1200
|
+
contract = familyInstance.deserializeContract(options.contract);
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
throw structuredError("CONTRACT.VALIDATION_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
|
|
1203
|
+
}
|
|
1204
|
+
onProgress?.({
|
|
1205
|
+
action: "verify",
|
|
1206
|
+
kind: "spanStart",
|
|
1207
|
+
spanId: "verify",
|
|
1208
|
+
label: "Verifying database marker..."
|
|
1209
|
+
});
|
|
1210
|
+
try {
|
|
1211
|
+
const result = await familyInstance.verify({
|
|
1212
|
+
driver,
|
|
1213
|
+
contract,
|
|
1214
|
+
expectedTargetId: this.options.target.targetId,
|
|
1215
|
+
contractPath: ""
|
|
1216
|
+
});
|
|
1217
|
+
onProgress?.({
|
|
1218
|
+
action: "verify",
|
|
1219
|
+
kind: "spanEnd",
|
|
1220
|
+
spanId: "verify",
|
|
1221
|
+
outcome: result.ok ? "ok" : "error"
|
|
1222
|
+
});
|
|
1223
|
+
return result;
|
|
1224
|
+
} catch (error) {
|
|
1225
|
+
onProgress?.({
|
|
1226
|
+
action: "verify",
|
|
1227
|
+
kind: "spanEnd",
|
|
1228
|
+
spanId: "verify",
|
|
1229
|
+
outcome: "error"
|
|
1230
|
+
});
|
|
1231
|
+
throw error;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
async schemaVerify(options) {
|
|
1235
|
+
const { onProgress } = options;
|
|
1236
|
+
await this.connectWithProgress(options.connection, "schemaVerify", onProgress);
|
|
1237
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
1238
|
+
let contract;
|
|
1239
|
+
try {
|
|
1240
|
+
contract = familyInstance.deserializeContract(options.contract);
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
throw structuredError("CONTRACT.VALIDATION_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
|
|
1243
|
+
}
|
|
1244
|
+
onProgress?.({
|
|
1245
|
+
action: "schemaVerify",
|
|
1246
|
+
kind: "spanStart",
|
|
1247
|
+
spanId: "schemaVerify",
|
|
1248
|
+
label: "Verifying database schema..."
|
|
1249
|
+
});
|
|
1250
|
+
try {
|
|
1251
|
+
const schema = await familyInstance.introspect({
|
|
1252
|
+
driver,
|
|
1253
|
+
contract
|
|
1254
|
+
});
|
|
1255
|
+
const result = familyInstance.verifySchema({
|
|
1256
|
+
contract,
|
|
1257
|
+
schema,
|
|
1258
|
+
strict: options.strict ?? false,
|
|
1259
|
+
frameworkComponents
|
|
1260
|
+
});
|
|
1261
|
+
onProgress?.({
|
|
1262
|
+
action: "schemaVerify",
|
|
1263
|
+
kind: "spanEnd",
|
|
1264
|
+
spanId: "schemaVerify",
|
|
1265
|
+
outcome: result.ok ? "ok" : "error"
|
|
1266
|
+
});
|
|
1267
|
+
return result;
|
|
1268
|
+
} catch (error) {
|
|
1269
|
+
onProgress?.({
|
|
1270
|
+
action: "schemaVerify",
|
|
1271
|
+
kind: "spanEnd",
|
|
1272
|
+
spanId: "schemaVerify",
|
|
1273
|
+
outcome: "error"
|
|
1274
|
+
});
|
|
1275
|
+
throw error;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
async sign(options) {
|
|
1279
|
+
const { onProgress } = options;
|
|
1280
|
+
await this.connectWithProgress(options.connection, "sign", onProgress);
|
|
1281
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
1282
|
+
let contract;
|
|
1283
|
+
try {
|
|
1284
|
+
contract = familyInstance.deserializeContract(options.contract);
|
|
1285
|
+
} catch (error) {
|
|
1286
|
+
throw structuredError("CONTRACT.VALIDATION_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
|
|
1287
|
+
}
|
|
1288
|
+
onProgress?.({
|
|
1289
|
+
action: "sign",
|
|
1290
|
+
kind: "spanStart",
|
|
1291
|
+
spanId: "sign",
|
|
1292
|
+
label: "Signing database..."
|
|
1293
|
+
});
|
|
1294
|
+
try {
|
|
1295
|
+
const result = await familyInstance.sign({
|
|
1296
|
+
driver,
|
|
1297
|
+
contract,
|
|
1298
|
+
contractPath: options.contractPath ?? "",
|
|
1299
|
+
...ifDefined("configPath", options.configPath)
|
|
1300
|
+
});
|
|
1301
|
+
onProgress?.({
|
|
1302
|
+
action: "sign",
|
|
1303
|
+
kind: "spanEnd",
|
|
1304
|
+
spanId: "sign",
|
|
1305
|
+
outcome: "ok"
|
|
1306
|
+
});
|
|
1307
|
+
return result;
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
onProgress?.({
|
|
1310
|
+
action: "sign",
|
|
1311
|
+
kind: "spanEnd",
|
|
1312
|
+
spanId: "sign",
|
|
1313
|
+
outcome: "error"
|
|
1314
|
+
});
|
|
1315
|
+
throw error;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
async dbInit(options) {
|
|
1319
|
+
const { onProgress } = options;
|
|
1320
|
+
await this.connectWithProgress(options.connection, "dbInit", onProgress);
|
|
1321
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
1322
|
+
if (!hasMigrations(this.options.target)) throw new CliStructuredError("MIGRATION.TARGET_UNSUPPORTED", `Target "${this.options.target.targetId}" does not support migrations`);
|
|
1323
|
+
const adapter = this.buildControlAdapter();
|
|
1324
|
+
let contract;
|
|
1325
|
+
try {
|
|
1326
|
+
contract = familyInstance.deserializeContract(options.contract);
|
|
1327
|
+
} catch (error) {
|
|
1328
|
+
throw structuredError("CONTRACT.VALIDATION_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
|
|
1329
|
+
}
|
|
1330
|
+
return executeDbInit({
|
|
1331
|
+
driver,
|
|
1332
|
+
adapter,
|
|
1333
|
+
familyInstance,
|
|
1334
|
+
contract,
|
|
1335
|
+
mode: options.mode,
|
|
1336
|
+
migrations: this.options.target.migrations,
|
|
1337
|
+
frameworkComponents,
|
|
1338
|
+
migrationsDir: options.migrationsDir,
|
|
1339
|
+
targetId: this.options.target.targetId,
|
|
1340
|
+
extensions: this.options.extensions ?? [],
|
|
1341
|
+
...ifDefined("onProgress", onProgress)
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
async dbUpdate(options) {
|
|
1345
|
+
const { onProgress } = options;
|
|
1346
|
+
await this.connectWithProgress(options.connection, "dbUpdate", onProgress);
|
|
1347
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
1348
|
+
if (!hasMigrations(this.options.target)) throw new CliStructuredError("MIGRATION.TARGET_UNSUPPORTED", `Target "${this.options.target.targetId}" does not support migrations`);
|
|
1349
|
+
const adapter = this.buildControlAdapter();
|
|
1350
|
+
let contract;
|
|
1351
|
+
try {
|
|
1352
|
+
contract = familyInstance.deserializeContract(options.contract);
|
|
1353
|
+
} catch (error) {
|
|
1354
|
+
throw structuredError("CONTRACT.VALIDATION_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
|
|
1355
|
+
}
|
|
1356
|
+
return executeDbUpdate({
|
|
1357
|
+
driver,
|
|
1358
|
+
adapter,
|
|
1359
|
+
familyInstance,
|
|
1360
|
+
contract,
|
|
1361
|
+
mode: options.mode,
|
|
1362
|
+
migrations: this.options.target.migrations,
|
|
1363
|
+
frameworkComponents,
|
|
1364
|
+
migrationsDir: options.migrationsDir,
|
|
1365
|
+
targetId: this.options.target.targetId,
|
|
1366
|
+
extensions: this.options.extensions ?? [],
|
|
1367
|
+
...ifDefined("acceptDataLoss", options.acceptDataLoss),
|
|
1368
|
+
...ifDefined("onProgress", onProgress)
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
async dbVerify(options) {
|
|
1372
|
+
const { onProgress } = options;
|
|
1373
|
+
await this.connectWithProgress(options.connection, "dbVerify", onProgress);
|
|
1374
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
1375
|
+
return executeDbVerify({
|
|
1376
|
+
driver,
|
|
1377
|
+
familyInstance,
|
|
1378
|
+
contract: options.contract,
|
|
1379
|
+
migrationsDir: options.migrationsDir,
|
|
1380
|
+
targetId: this.options.target.targetId,
|
|
1381
|
+
extensions: this.options.extensions ?? [],
|
|
1382
|
+
frameworkComponents,
|
|
1383
|
+
mode: options.strict ? "strict" : "lenient",
|
|
1384
|
+
skipSchema: options.skipSchema,
|
|
1385
|
+
skipMarker: options.skipMarker,
|
|
1386
|
+
...ifDefined("onProgress", onProgress)
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
async readMarker() {
|
|
1390
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
1391
|
+
return familyInstance.readMarker({
|
|
1392
|
+
driver,
|
|
1393
|
+
space: APP_SPACE_ID
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
async readAllMarkers() {
|
|
1397
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
1398
|
+
return familyInstance.readAllMarkers({ driver });
|
|
1399
|
+
}
|
|
1400
|
+
/** Reads the per-migration journal; omit `space` to return every space. */
|
|
1401
|
+
async readLedger(space) {
|
|
1402
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
1403
|
+
return familyInstance.readLedger({
|
|
1404
|
+
driver,
|
|
1405
|
+
...ifDefined("space", space)
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
async migrate(options) {
|
|
1409
|
+
const { onProgress } = options;
|
|
1410
|
+
await this.connectWithProgress(options.connection, "migrate", onProgress);
|
|
1411
|
+
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
1412
|
+
if (!hasMigrations(this.options.target)) throw new CliStructuredError("MIGRATION.TARGET_UNSUPPORTED", `Target "${this.options.target.targetId}" does not support migrations`);
|
|
1413
|
+
let contract;
|
|
1414
|
+
try {
|
|
1415
|
+
contract = familyInstance.deserializeContract(options.contract);
|
|
1416
|
+
} catch (error) {
|
|
1417
|
+
throw structuredError("CONTRACT.VALIDATION_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
|
|
1418
|
+
}
|
|
1419
|
+
return executeMigrate({
|
|
1420
|
+
driver,
|
|
1421
|
+
familyInstance,
|
|
1422
|
+
contract,
|
|
1423
|
+
migrations: this.options.target.migrations,
|
|
1424
|
+
frameworkComponents,
|
|
1425
|
+
migrationsDir: options.migrationsDir,
|
|
1426
|
+
extensions: this.options.extensions ?? [],
|
|
1427
|
+
targetId: this.options.target.targetId,
|
|
1428
|
+
...ifDefined("refHash", options.refHash),
|
|
1429
|
+
...ifDefined("refInvariants", options.refInvariants),
|
|
1430
|
+
...ifDefined("refName", options.refName),
|
|
1431
|
+
...ifDefined("onProgress", onProgress)
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
async introspect(options) {
|
|
1435
|
+
const onProgress = options?.onProgress;
|
|
1436
|
+
await this.connectWithProgress(options?.connection, "introspect", onProgress);
|
|
1437
|
+
const { driver, familyInstance } = await this.ensureConnected();
|
|
1438
|
+
options?.schema;
|
|
1439
|
+
onProgress?.({
|
|
1440
|
+
action: "introspect",
|
|
1441
|
+
kind: "spanStart",
|
|
1442
|
+
spanId: "introspect",
|
|
1443
|
+
label: "Introspecting database schema..."
|
|
1444
|
+
});
|
|
1445
|
+
try {
|
|
1446
|
+
const result = await familyInstance.introspect({ driver });
|
|
1447
|
+
onProgress?.({
|
|
1448
|
+
action: "introspect",
|
|
1449
|
+
kind: "spanEnd",
|
|
1450
|
+
spanId: "introspect",
|
|
1451
|
+
outcome: "ok"
|
|
1452
|
+
});
|
|
1453
|
+
return result;
|
|
1454
|
+
} catch (error) {
|
|
1455
|
+
onProgress?.({
|
|
1456
|
+
action: "introspect",
|
|
1457
|
+
kind: "spanEnd",
|
|
1458
|
+
spanId: "introspect",
|
|
1459
|
+
outcome: "error"
|
|
1460
|
+
});
|
|
1461
|
+
throw error;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
toSchemaView(schemaIR) {
|
|
1465
|
+
this.init();
|
|
1466
|
+
if (this.familyInstance && hasSchemaView(this.familyInstance)) return this.familyInstance.toSchemaView(schemaIR);
|
|
1467
|
+
}
|
|
1468
|
+
inferPslContract(schemaIR) {
|
|
1469
|
+
this.init();
|
|
1470
|
+
if (this.familyInstance && hasPslContractInfer(this.familyInstance)) return this.familyInstance.inferPslContract(schemaIR);
|
|
1471
|
+
}
|
|
1472
|
+
getPslBlockDescriptors() {
|
|
1473
|
+
this.init();
|
|
1474
|
+
return this.stack.authoringContributions.pslBlockDescriptors;
|
|
1475
|
+
}
|
|
1476
|
+
toOperationPreview(operations) {
|
|
1477
|
+
this.init();
|
|
1478
|
+
if (this.familyInstance && hasOperationPreview(this.familyInstance)) return this.familyInstance.toOperationPreview(operations);
|
|
1479
|
+
}
|
|
1480
|
+
async emit(options) {
|
|
1481
|
+
const { onProgress, contractConfig } = options;
|
|
1482
|
+
this.init();
|
|
1483
|
+
if (!this.familyInstance) throw new InternalError("Family instance was not initialized. This is a bug.");
|
|
1484
|
+
let contractRaw;
|
|
1485
|
+
onProgress?.({
|
|
1486
|
+
action: "emit",
|
|
1487
|
+
kind: "spanStart",
|
|
1488
|
+
spanId: "resolveSource",
|
|
1489
|
+
label: "Resolving contract source..."
|
|
1490
|
+
});
|
|
1491
|
+
try {
|
|
1492
|
+
const stack = this.stack;
|
|
1493
|
+
const sourceContext = {
|
|
1494
|
+
composedExtensions: stack.extensions.map((p) => p.id),
|
|
1495
|
+
composedExtensionContracts: stack.extensionContracts,
|
|
1496
|
+
authoringContributions: stack.authoringContributions,
|
|
1497
|
+
codecLookup: stack.codecLookup,
|
|
1498
|
+
controlMutationDefaults: stack.controlMutationDefaults,
|
|
1499
|
+
resolvedInputs: contractConfig.source.inputs ?? [],
|
|
1500
|
+
capabilities: stack.capabilities
|
|
1501
|
+
};
|
|
1502
|
+
const providerResult = await contractConfig.source.load(sourceContext);
|
|
1503
|
+
if (!providerResult.ok) {
|
|
1504
|
+
onProgress?.({
|
|
1505
|
+
action: "emit",
|
|
1506
|
+
kind: "spanEnd",
|
|
1507
|
+
spanId: "resolveSource",
|
|
1508
|
+
outcome: "error"
|
|
1509
|
+
});
|
|
1510
|
+
return notOk({
|
|
1511
|
+
code: "CONTRACT_SOURCE_INVALID",
|
|
1512
|
+
summary: providerResult.failure.summary,
|
|
1513
|
+
why: providerResult.failure.summary,
|
|
1514
|
+
meta: providerResult.failure.meta,
|
|
1515
|
+
diagnostics: providerResult.failure
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
contractRaw = providerResult.value;
|
|
1519
|
+
onProgress?.({
|
|
1520
|
+
action: "emit",
|
|
1521
|
+
kind: "spanEnd",
|
|
1522
|
+
spanId: "resolveSource",
|
|
1523
|
+
outcome: "ok"
|
|
1524
|
+
});
|
|
1525
|
+
} catch (error) {
|
|
1526
|
+
onProgress?.({
|
|
1527
|
+
action: "emit",
|
|
1528
|
+
kind: "spanEnd",
|
|
1529
|
+
spanId: "resolveSource",
|
|
1530
|
+
outcome: "error"
|
|
1531
|
+
});
|
|
1532
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1533
|
+
return notOk({
|
|
1534
|
+
code: "CONTRACT_SOURCE_INVALID",
|
|
1535
|
+
summary: "Failed to resolve contract source",
|
|
1536
|
+
why: message,
|
|
1537
|
+
diagnostics: {
|
|
1538
|
+
summary: "Contract source provider threw an exception",
|
|
1539
|
+
diagnostics: [{
|
|
1540
|
+
code: "PROVIDER_THROW",
|
|
1541
|
+
message
|
|
1542
|
+
}]
|
|
1543
|
+
},
|
|
1544
|
+
meta: void 0
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
onProgress?.({
|
|
1548
|
+
action: "emit",
|
|
1549
|
+
kind: "spanStart",
|
|
1550
|
+
spanId: "emit",
|
|
1551
|
+
label: "Emitting contract..."
|
|
1552
|
+
});
|
|
1553
|
+
try {
|
|
1554
|
+
const enrichedIR = enrichContract(contractRaw, this.frameworkComponents ?? []);
|
|
1555
|
+
const rawContractJson = this.options.target.contractSerializer.serializeContract(enrichedIR);
|
|
1556
|
+
let deserializedContract;
|
|
1557
|
+
try {
|
|
1558
|
+
deserializedContract = this.familyInstance.deserializeContract(rawContractJson);
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
onProgress?.({
|
|
1561
|
+
action: "emit",
|
|
1562
|
+
kind: "spanEnd",
|
|
1563
|
+
spanId: "emit",
|
|
1564
|
+
outcome: "error"
|
|
1565
|
+
});
|
|
1566
|
+
return notOk({
|
|
1567
|
+
code: "CONTRACT_VALIDATION_FAILED",
|
|
1568
|
+
summary: "Contract validation failed",
|
|
1569
|
+
why: error instanceof Error ? error.message : String(error),
|
|
1570
|
+
meta: void 0
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
const result = await emit(deserializedContract, this.stack, this.options.family.emission, { serializeContract: (contract) => this.options.target.contractSerializer.serializeContract(contract) });
|
|
1574
|
+
onProgress?.({
|
|
1575
|
+
action: "emit",
|
|
1576
|
+
kind: "spanEnd",
|
|
1577
|
+
spanId: "emit",
|
|
1578
|
+
outcome: "ok"
|
|
1579
|
+
});
|
|
1580
|
+
return ok({
|
|
1581
|
+
storageHash: result.storageHash,
|
|
1582
|
+
...ifDefined("executionHash", result.executionHash),
|
|
1583
|
+
profileHash: result.profileHash,
|
|
1584
|
+
contractJson: result.contractJson,
|
|
1585
|
+
contractDts: result.contractDts
|
|
1586
|
+
});
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
onProgress?.({
|
|
1589
|
+
action: "emit",
|
|
1590
|
+
kind: "spanEnd",
|
|
1591
|
+
spanId: "emit",
|
|
1592
|
+
outcome: "error"
|
|
1593
|
+
});
|
|
1594
|
+
return notOk({
|
|
1595
|
+
code: "EMIT_FAILED",
|
|
1596
|
+
summary: "Failed to emit contract",
|
|
1597
|
+
why: error instanceof Error ? error.message : String(error),
|
|
1598
|
+
meta: void 0
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
//#endregion
|
|
1604
|
+
export { planSpacePath as a, executeDbVerify as i, executeDbInit as n, executeDbUpdate as r, createControlClient as t };
|
|
1605
|
+
|
|
1606
|
+
//# sourceMappingURL=client-75qrAPqf-DZAVUxFa.mjs.map
|