@prisma/orm-toolchain 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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-DcwUnadt-B6Qoh0ot.mjs +597 -0
- package/dist/migration-check-DcwUnadt-B6Qoh0ot.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-CE7cQLDq-B1jDVmqG.mjs +444 -0
- package/dist/migration-status-CE7cQLDq-B1jDVmqG.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-CfGSxH5b-BSjB3nZS.d.mts +192 -0
- package/dist/schemas-CfGSxH5b-BSjB3nZS.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 +122 -0
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
import { M as errorRefNotResolvable, N as errorSpaceHeadRefMissing, i as errorContractDeserializationFailed, p as errorHashNotInGraph, r as errorBundleNotFoundForGraphNode, t as MigrationToolsError } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import { n as readContractSnapshotDts, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs";
|
|
3
|
+
import { s as readMigrationsDir } from "./io-C8TdyBKt-DloEBi70.mjs";
|
|
4
|
+
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
5
|
+
import { l as reconstructGraph, o as findPathWithDecision } from "./migration-graph-CBf9ORe7-B4xAF8GN.mjs";
|
|
6
|
+
import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs";
|
|
7
|
+
import { n as isGraphNode } from "./graph-membership-DW6nnbyQ-Bp2KcVwR.mjs";
|
|
8
|
+
import { a as readRefsTolerant, r as readRef, t as HEAD_REF_NAME } from "./refs-BDbB9BRB-D6Za3Q49.mjs";
|
|
9
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
10
|
+
import { join } from "pathe";
|
|
11
|
+
import { issueOutcome } from "@prisma/orm-framework/components/control";
|
|
12
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
13
|
+
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
14
|
+
import { UNBOUND_NAMESPACE_ID, coordinateKey, elementCoordinates, entityAt } from "@prisma/orm-framework/components/ir";
|
|
15
|
+
import { effectiveControlPolicy } from "@prisma/orm-framework/contract/types";
|
|
16
|
+
//#region ../../../1-framework/3-tooling/migration/dist/exports/aggregate.mjs
|
|
17
|
+
function contractAtMemoKey(hash, refName) {
|
|
18
|
+
return `${hash}\0${refName ?? ""}`;
|
|
19
|
+
}
|
|
20
|
+
function deserializeContractAtPath(filePath, contractJson, deserializeContract) {
|
|
21
|
+
try {
|
|
22
|
+
return deserializeContract(contractJson);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (MigrationToolsError.is(error)) throw error;
|
|
25
|
+
throw errorContractDeserializationFailed(filePath, error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function readContractSnapshotEntry(migrationsDir, hash, deserializeContract) {
|
|
29
|
+
const contractJson = await readContractSnapshotJson(migrationsDir, hash);
|
|
30
|
+
return {
|
|
31
|
+
contractJson,
|
|
32
|
+
contractDts: await readContractSnapshotDts(migrationsDir, hash),
|
|
33
|
+
contract: deserializeContractAtPath(join(contractSnapshotDir(migrationsDir, hash), "contract.json"), contractJson, deserializeContract)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function resolveContractAt(args) {
|
|
37
|
+
const { hash, opts, refsDir, migrationsDir, packages, graph, deserializeContract } = args;
|
|
38
|
+
const refName = opts?.refName;
|
|
39
|
+
if (refName !== void 0) {
|
|
40
|
+
let refEntry;
|
|
41
|
+
try {
|
|
42
|
+
refEntry = await readRef(refsDir, refName);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (MigrationToolsError.is(error) && error.code === "MIGRATION.UNKNOWN_REF") refEntry = void 0;
|
|
45
|
+
else throw error;
|
|
46
|
+
}
|
|
47
|
+
if (refEntry) {
|
|
48
|
+
const { contractJson, contractDts, contract } = await readContractSnapshotEntry(migrationsDir, refEntry.hash, deserializeContract);
|
|
49
|
+
return {
|
|
50
|
+
hash: refEntry.hash,
|
|
51
|
+
contractJson,
|
|
52
|
+
contractDts,
|
|
53
|
+
contract,
|
|
54
|
+
provenance: "ref"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (isGraphNode(hash, graph)) return resolveGraphNodeContractAt({
|
|
58
|
+
hash,
|
|
59
|
+
migrationsDir,
|
|
60
|
+
packages,
|
|
61
|
+
deserializeContract,
|
|
62
|
+
explicitLabel: refName
|
|
63
|
+
});
|
|
64
|
+
throw errorRefNotResolvable(refName);
|
|
65
|
+
}
|
|
66
|
+
if (isGraphNode(hash, graph)) return resolveGraphNodeContractAt({
|
|
67
|
+
hash,
|
|
68
|
+
migrationsDir,
|
|
69
|
+
packages,
|
|
70
|
+
deserializeContract
|
|
71
|
+
});
|
|
72
|
+
throw errorHashNotInGraph(hash, graph);
|
|
73
|
+
}
|
|
74
|
+
async function resolveGraphNodeContractAt(args) {
|
|
75
|
+
const { hash, migrationsDir, packages, deserializeContract, explicitLabel } = args;
|
|
76
|
+
if (!packages.find((pkg) => pkg.metadata.to === hash)) throw errorBundleNotFoundForGraphNode(hash, explicitLabel);
|
|
77
|
+
const { contractJson, contractDts, contract } = await readContractSnapshotEntry(migrationsDir, hash, deserializeContract);
|
|
78
|
+
return {
|
|
79
|
+
hash,
|
|
80
|
+
contractJson,
|
|
81
|
+
contractDts,
|
|
82
|
+
contract,
|
|
83
|
+
provenance: "graph-node"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resolve a contract space's head ref, asserting it is present. The apply/verify
|
|
88
|
+
* engine only runs after `checkIntegrity` has refused on `headRefMissing`,
|
|
89
|
+
* so a space reaching the planner / verifier without a head ref is a
|
|
90
|
+
* programming error (the integrity gate was skipped), not a user-facing
|
|
91
|
+
* state. The app space's head ref is always synthesised, so this only
|
|
92
|
+
* ever guards an ungated extension space.
|
|
93
|
+
*/
|
|
94
|
+
function requireHeadRef(space) {
|
|
95
|
+
if (space.headRef === null) throw new InternalError(`Contract space "${space.spaceId}" has no head ref; the integrity gate must refuse a missing head ref before planning or verifying.`);
|
|
96
|
+
return space.headRef;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Build a {@link AggregateContractSpace} with lazily-memoised `graph()`,
|
|
100
|
+
* `contract()`, and `contractAt()` facets.
|
|
101
|
+
*
|
|
102
|
+
* `graph()` reconstructs the migration graph from `packages` on first
|
|
103
|
+
* call and caches it. `contract()` calls `resolveContract` on first call
|
|
104
|
+
* and caches the result; a throwing `resolveContract` (e.g. a missing or
|
|
105
|
+
* undeserializable on-disk contract) re-throws on each call rather than
|
|
106
|
+
* caching a value — `checkIntegrity` surfaces that as `contractUnreadable`.
|
|
107
|
+
* `contractAt()` materializes the contract at an arbitrary graph node with
|
|
108
|
+
* the same resolution order as plan-time ref resolution: the ref's pointer
|
|
109
|
+
* plus the store entry keyed by the pointer's hash first (when
|
|
110
|
+
* `opts.refName` is set), else the contract snapshot store entry keyed by
|
|
111
|
+
* the matching package's `to` hash.
|
|
112
|
+
*/
|
|
113
|
+
function createAggregateContractSpace(args) {
|
|
114
|
+
const { spaceId, packages, refs, headRef, refsDir, migrationsDir, resolveContract, deserializeContract } = args;
|
|
115
|
+
let graphMemo;
|
|
116
|
+
let contractMemo;
|
|
117
|
+
const contractAtMemo = /* @__PURE__ */ new Map();
|
|
118
|
+
function spaceGraph() {
|
|
119
|
+
graphMemo ??= reconstructGraph(packages);
|
|
120
|
+
return graphMemo;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
spaceId,
|
|
124
|
+
packages,
|
|
125
|
+
refs,
|
|
126
|
+
headRef,
|
|
127
|
+
graph: spaceGraph,
|
|
128
|
+
contract() {
|
|
129
|
+
contractMemo ??= resolveContract();
|
|
130
|
+
return contractMemo;
|
|
131
|
+
},
|
|
132
|
+
async contractAt(hash, opts) {
|
|
133
|
+
const key = contractAtMemoKey(hash, opts?.refName);
|
|
134
|
+
const cached = contractAtMemo.get(key);
|
|
135
|
+
if (cached) return cached;
|
|
136
|
+
const result = await resolveContractAt({
|
|
137
|
+
hash,
|
|
138
|
+
opts,
|
|
139
|
+
refsDir,
|
|
140
|
+
migrationsDir,
|
|
141
|
+
packages,
|
|
142
|
+
graph: spaceGraph(),
|
|
143
|
+
deserializeContract
|
|
144
|
+
});
|
|
145
|
+
contractAtMemo.set(key, result);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Collect the union of every namespace declared across all contract spaces of an
|
|
152
|
+
* aggregate (app + extensions) and return a minimal object with the shape
|
|
153
|
+
* `{ storage: { namespaces } }` suitable for passing to
|
|
154
|
+
* `familyInstance.introspect`.
|
|
155
|
+
*
|
|
156
|
+
* Callers invoke this after the integrity gate (`buildContractSpaceAggregate`
|
|
157
|
+
* with `checkContracts: true`), so every `space.contract()` call is safe —
|
|
158
|
+
* no try/catch is needed here.
|
|
159
|
+
*/
|
|
160
|
+
function collectAggregateNamespaces(aggregate) {
|
|
161
|
+
const merged = {};
|
|
162
|
+
for (const space of aggregate.spaces()) for (const [key, ns] of Object.entries(space.contract().storage.namespaces)) {
|
|
163
|
+
const existing = merged[key];
|
|
164
|
+
merged[key] = existing === void 0 ? ns : mergeNamespaceEntries(existing, ns);
|
|
165
|
+
}
|
|
166
|
+
return { storage: { namespaces: merged } };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Union two contract spaces' declarations for the same namespace id, per
|
|
170
|
+
* entity kind. Two spaces may legitimately share a namespace (e.g. both
|
|
171
|
+
* declaring tables in `public`); element-level disjointness is enforced by
|
|
172
|
+
* `checkIntegrity`, so the kind maps never collide on a name — replacing the
|
|
173
|
+
* whole namespace would silently drop the earlier space's entities.
|
|
174
|
+
*/
|
|
175
|
+
function mergeNamespaceEntries(a, b) {
|
|
176
|
+
const entries = { ...a.entries };
|
|
177
|
+
for (const [entityKind, kindMap] of Object.entries(b.entries)) entries[entityKind] = {
|
|
178
|
+
...entries[entityKind],
|
|
179
|
+
...kindMap
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
...a,
|
|
183
|
+
entries
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Assemble a {@link ContractSpaceAggregate} value from its contract spaces and a
|
|
188
|
+
* `checkIntegrity` implementation. The query methods (`listSpaces` /
|
|
189
|
+
* `hasSpace` / `space` / `spaces`) are derived here so every aggregate —
|
|
190
|
+
* loader-built or test-built — shares one query surface: `app` first,
|
|
191
|
+
* then `extensions` in the order supplied (the loader sorts them
|
|
192
|
+
* lex-ascending by `spaceId`).
|
|
193
|
+
*/
|
|
194
|
+
function createContractSpaceAggregate(args) {
|
|
195
|
+
const { targetId, app, extensions, checkIntegrity } = args;
|
|
196
|
+
const ordered = [app, ...extensions];
|
|
197
|
+
const byId = new Map(ordered.map((m) => [m.spaceId, m]));
|
|
198
|
+
const spaceDeclares = (space, coordinate) => {
|
|
199
|
+
const key = coordinateKey(coordinate);
|
|
200
|
+
for (const coord of elementCoordinates(space.contract().storage)) if (coordinateKey(coord) === key) return true;
|
|
201
|
+
return false;
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
targetId,
|
|
205
|
+
app,
|
|
206
|
+
extensions,
|
|
207
|
+
listSpaces: () => ordered.map((m) => m.spaceId),
|
|
208
|
+
hasSpace: (id) => byId.has(id),
|
|
209
|
+
space: (id) => byId.get(id),
|
|
210
|
+
spaces: () => ordered,
|
|
211
|
+
declaresEntity: (coordinate) => ordered.some((space) => spaceDeclares(space, coordinate)),
|
|
212
|
+
declaringSpaces: (coordinate) => ordered.filter((space) => spaceDeclares(space, coordinate)).map((s) => s.spaceId),
|
|
213
|
+
checkIntegrity
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function isControlPolicy(value) {
|
|
217
|
+
return value === "managed" || value === "tolerated" || value === "external" || value === "observed";
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* True when every storage element the contract declares resolves to the
|
|
221
|
+
* `external` control policy (ADR 224) — element-level `control` first, the
|
|
222
|
+
* contract's `defaultControlPolicy` otherwise. A contract with no storage
|
|
223
|
+
* elements is vacuously all-external.
|
|
224
|
+
*
|
|
225
|
+
* This is the precondition for advancing a contract space's marker without
|
|
226
|
+
* any migrations (the declared-state resolution the db-init aggregate
|
|
227
|
+
* planner and `migrate` share): only when nothing in the space is
|
|
228
|
+
* Prisma-Next-managed can the storage structure be correct without a
|
|
229
|
+
* migration having produced it. Any space that declares a managed element
|
|
230
|
+
* but ships no migration graph is an authoring bug and must fail loudly.
|
|
231
|
+
*/
|
|
232
|
+
function allStorageElementsExternal(contract) {
|
|
233
|
+
for (const coordinate of elementCoordinates(contract.storage)) {
|
|
234
|
+
const entity = entityAt(contract.storage, coordinate);
|
|
235
|
+
const declared = entity !== null && typeof entity === "object" ? blindCast(entity).control : void 0;
|
|
236
|
+
if (effectiveControlPolicy(isControlPolicy(declared) ? declared : void 0, contract.defaultControlPolicy) !== "external") return false;
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Walk the loaded model and return **every** integrity violation — never
|
|
242
|
+
* bailing at the first. Structurally-derivable violations (load-time
|
|
243
|
+
* problems, self-edges, missing / unreachable head refs) are always
|
|
244
|
+
* produced; layout-drift checks require `declaredExtensions`, and
|
|
245
|
+
* contract / target / disjointness checks require `checkContracts`.
|
|
246
|
+
*/
|
|
247
|
+
function computeIntegrityViolations(input, opts) {
|
|
248
|
+
const violations = [];
|
|
249
|
+
for (const { space, problems, refProblems, headRefProblem, isApp } of input.spaces) {
|
|
250
|
+
const { spaceId } = space;
|
|
251
|
+
for (const problem of problems) violations.push(loadProblemToViolation(spaceId, problem));
|
|
252
|
+
for (const refProblem of refProblems) violations.push({
|
|
253
|
+
kind: "refUnreadable",
|
|
254
|
+
spaceId,
|
|
255
|
+
refName: refProblem.refName,
|
|
256
|
+
detail: refProblem.detail
|
|
257
|
+
});
|
|
258
|
+
if (headRefProblem !== null) violations.push({
|
|
259
|
+
kind: "refUnreadable",
|
|
260
|
+
spaceId,
|
|
261
|
+
refName: headRefProblem.refName,
|
|
262
|
+
detail: headRefProblem.detail
|
|
263
|
+
});
|
|
264
|
+
for (const pkg of space.packages) {
|
|
265
|
+
const from = pkg.metadata.from ?? "empty";
|
|
266
|
+
const isSelfEdge = from === pkg.metadata.to;
|
|
267
|
+
const hasDataOp = pkg.ops.some((op) => op.operationClass === "data");
|
|
268
|
+
if (isSelfEdge && !hasDataOp) violations.push({
|
|
269
|
+
kind: "sameSourceAndTarget",
|
|
270
|
+
spaceId,
|
|
271
|
+
dirName: pkg.dirName,
|
|
272
|
+
hash: from
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
violations.push(...duplicateMigrationHashViolations(spaceId, space.packages));
|
|
276
|
+
if (!isApp && headRefProblem === null) {
|
|
277
|
+
if (space.headRef === null) violations.push({
|
|
278
|
+
kind: "headRefMissing",
|
|
279
|
+
spaceId
|
|
280
|
+
});
|
|
281
|
+
else if (space.packages.length > 0 && !headRefPresentInGraph(space, space.headRef.hash)) violations.push({
|
|
282
|
+
kind: "headRefNotInGraph",
|
|
283
|
+
spaceId,
|
|
284
|
+
hash: space.headRef.hash
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (opts?.declaredExtensions !== void 0) violations.push(...layoutViolations(input.spaces, opts.declaredExtensions));
|
|
289
|
+
if (opts?.checkContracts === true) violations.push(...contractViolations(input));
|
|
290
|
+
return violations;
|
|
291
|
+
}
|
|
292
|
+
function loadProblemToViolation(spaceId, problem) {
|
|
293
|
+
switch (problem.kind) {
|
|
294
|
+
case "hashMismatch": return {
|
|
295
|
+
kind: "hashMismatch",
|
|
296
|
+
spaceId,
|
|
297
|
+
dirName: problem.dirName,
|
|
298
|
+
stored: problem.stored,
|
|
299
|
+
computed: problem.computed
|
|
300
|
+
};
|
|
301
|
+
case "providedInvariantsMismatch": return {
|
|
302
|
+
kind: "providedInvariantsMismatch",
|
|
303
|
+
spaceId,
|
|
304
|
+
dirName: problem.dirName
|
|
305
|
+
};
|
|
306
|
+
case "packageUnloadable": return {
|
|
307
|
+
kind: "packageUnloadable",
|
|
308
|
+
spaceId,
|
|
309
|
+
dirName: problem.dirName,
|
|
310
|
+
detail: problem.detail
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function duplicateMigrationHashViolations(spaceId, packages) {
|
|
315
|
+
const dirNamesByHash = /* @__PURE__ */ new Map();
|
|
316
|
+
for (const pkg of packages) {
|
|
317
|
+
const hash = pkg.metadata.migrationHash;
|
|
318
|
+
const dirNames = dirNamesByHash.get(hash);
|
|
319
|
+
if (dirNames) dirNames.push(pkg.dirName);
|
|
320
|
+
else dirNamesByHash.set(hash, [pkg.dirName]);
|
|
321
|
+
}
|
|
322
|
+
const out = [];
|
|
323
|
+
for (const [migrationHash, dirNames] of dirNamesByHash) if (dirNames.length > 1) out.push({
|
|
324
|
+
kind: "duplicateMigrationHash",
|
|
325
|
+
spaceId,
|
|
326
|
+
migrationHash,
|
|
327
|
+
dirNames: [...dirNames].sort()
|
|
328
|
+
});
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Whether a space's head-ref hash is present in its reconstructed graph.
|
|
333
|
+
* An empty graph is reachable only by the empty-contract sentinel.
|
|
334
|
+
*/
|
|
335
|
+
function headRefPresentInGraph(space, headHash) {
|
|
336
|
+
const graph = space.graph();
|
|
337
|
+
if (graph.nodes.size === 0) return headHash === EMPTY_CONTRACT_HASH;
|
|
338
|
+
return graph.nodes.has(headHash);
|
|
339
|
+
}
|
|
340
|
+
function layoutViolations(spaces, declaredExtensions) {
|
|
341
|
+
const out = [];
|
|
342
|
+
const extensionSpaceIds = new Set(spaces.filter((s) => !s.isApp).map((s) => s.space.spaceId));
|
|
343
|
+
const declaredIds = new Set(declaredExtensions.map((d) => d.id));
|
|
344
|
+
for (const id of [...extensionSpaceIds].sort()) if (!declaredIds.has(id)) out.push({
|
|
345
|
+
kind: "orphanSpaceDir",
|
|
346
|
+
spaceId: id
|
|
347
|
+
});
|
|
348
|
+
for (const id of [...declaredIds].sort()) if (!extensionSpaceIds.has(id)) out.push({
|
|
349
|
+
kind: "declaredButUnmigrated",
|
|
350
|
+
spaceId: id
|
|
351
|
+
});
|
|
352
|
+
return out;
|
|
353
|
+
}
|
|
354
|
+
function contractViolations(input) {
|
|
355
|
+
const out = [];
|
|
356
|
+
const elementClaimedBy = /* @__PURE__ */ new Map();
|
|
357
|
+
const elementLabel = /* @__PURE__ */ new Map();
|
|
358
|
+
for (const { space } of input.spaces) {
|
|
359
|
+
let contract;
|
|
360
|
+
try {
|
|
361
|
+
contract = space.contract();
|
|
362
|
+
} catch (error) {
|
|
363
|
+
out.push({
|
|
364
|
+
kind: "contractUnreadable",
|
|
365
|
+
spaceId: space.spaceId,
|
|
366
|
+
detail: detailOf$1(error)
|
|
367
|
+
});
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (contract.target !== input.targetId) out.push({
|
|
371
|
+
kind: "targetMismatch",
|
|
372
|
+
spaceId: space.spaceId,
|
|
373
|
+
expected: input.targetId,
|
|
374
|
+
actual: contract.target
|
|
375
|
+
});
|
|
376
|
+
for (const coordinate of elementCoordinates(contract.storage)) {
|
|
377
|
+
const key = coordinateKey(coordinate);
|
|
378
|
+
const claimers = elementClaimedBy.get(key);
|
|
379
|
+
if (claimers) claimers.push(space.spaceId);
|
|
380
|
+
else {
|
|
381
|
+
elementClaimedBy.set(key, [space.spaceId]);
|
|
382
|
+
elementLabel.set(key, `${coordinate.namespaceId}.${coordinate.entityName}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const disjointness = [];
|
|
387
|
+
for (const [key, claimedBy] of elementClaimedBy) if (claimedBy.length > 1) {
|
|
388
|
+
const element = elementLabel.get(key) ?? key;
|
|
389
|
+
disjointness.push({
|
|
390
|
+
kind: "disjointness",
|
|
391
|
+
element,
|
|
392
|
+
claimedBy: [...claimedBy].sort()
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
disjointness.sort((a, b) => a.kind === "disjointness" && b.kind === "disjointness" ? a.element.localeCompare(b.element) : 0);
|
|
396
|
+
out.push(...disjointness);
|
|
397
|
+
return out;
|
|
398
|
+
}
|
|
399
|
+
function detailOf$1(error) {
|
|
400
|
+
if (MigrationToolsError.is(error)) return error.why;
|
|
401
|
+
if (error instanceof Error) return error.message;
|
|
402
|
+
return String(error);
|
|
403
|
+
}
|
|
404
|
+
function buildFabricatedMigrationEdge(args) {
|
|
405
|
+
return {
|
|
406
|
+
dirName: "",
|
|
407
|
+
migrationHash: args.destinationStorageHash,
|
|
408
|
+
from: args.currentMarkerStorageHash ?? "",
|
|
409
|
+
to: args.destinationStorageHash,
|
|
410
|
+
operationCount: args.operationCount,
|
|
411
|
+
...args.destinationContractJson !== void 0 ? { destinationContractJson: args.destinationContractJson } : {}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Build a tolerant, queryable {@link ContractSpaceAggregate} from on-disk
|
|
416
|
+
* migration state plus the caller's live app contract.
|
|
417
|
+
*
|
|
418
|
+
* Building **never throws on disk content**: a hash- or
|
|
419
|
+
* invariants-mismatched package is retained, an unparseable package is
|
|
420
|
+
* omitted, a missing extension head ref leaves `headRef: null`, and an
|
|
421
|
+
* unreadable on-disk contract defers its failure to `space.contract()`.
|
|
422
|
+
* Every such problem is judged by {@link ContractSpaceAggregate.checkIntegrity}
|
|
423
|
+
* rather than aborting the load. The only rejections are catastrophic I/O
|
|
424
|
+
* (a `migrations/` that exists but is unreadable for reasons other than
|
|
425
|
+
* absence).
|
|
426
|
+
*
|
|
427
|
+
* The app space's head ref is synthesised from the live contract's
|
|
428
|
+
* storage hash (the app contract is authored independently of the
|
|
429
|
+
* migration graph), and `app.contract()` returns the supplied contract.
|
|
430
|
+
* Extension spaces read their contract, refs, and head ref from disk.
|
|
431
|
+
*/
|
|
432
|
+
async function loadContractSpaceAggregate(input) {
|
|
433
|
+
const { migrationsDir, deserializeContract, appContract } = input;
|
|
434
|
+
const targetId = appContract.target;
|
|
435
|
+
const appState = await loadAppSpace(migrationsDir, appContract, deserializeContract);
|
|
436
|
+
const extensionStates = await loadExtensionSpaces(migrationsDir, deserializeContract);
|
|
437
|
+
const spaces = [appState, ...extensionStates];
|
|
438
|
+
return createContractSpaceAggregate({
|
|
439
|
+
targetId,
|
|
440
|
+
app: appState.space,
|
|
441
|
+
extensions: extensionStates.map((state) => state.space),
|
|
442
|
+
checkIntegrity: (opts) => computeIntegrityViolations({
|
|
443
|
+
targetId,
|
|
444
|
+
spaces
|
|
445
|
+
}, opts)
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
async function loadAppSpace(migrationsDir, appContract, deserializeContract) {
|
|
449
|
+
const spaceDir = spaceMigrationDirectory(migrationsDir, APP_SPACE_ID$1);
|
|
450
|
+
const { packages, problems } = await readMigrationsDir(spaceDir, { migrationsDir });
|
|
451
|
+
const { refs, problems: refProblems } = await readRefsTolerant(spaceRefsDirectory(spaceDir));
|
|
452
|
+
return {
|
|
453
|
+
space: createAggregateContractSpace({
|
|
454
|
+
spaceId: APP_SPACE_ID$1,
|
|
455
|
+
packages,
|
|
456
|
+
refs,
|
|
457
|
+
headRef: {
|
|
458
|
+
hash: appContract.storage.storageHash,
|
|
459
|
+
invariants: []
|
|
460
|
+
},
|
|
461
|
+
refsDir: spaceRefsDirectory(spaceDir),
|
|
462
|
+
migrationsDir,
|
|
463
|
+
resolveContract: () => appContract,
|
|
464
|
+
deserializeContract
|
|
465
|
+
}),
|
|
466
|
+
problems,
|
|
467
|
+
refProblems,
|
|
468
|
+
headRefProblem: null,
|
|
469
|
+
isApp: true
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
async function loadExtensionSpaces(migrationsDir, deserializeContract) {
|
|
473
|
+
const extensionIds = (await listContractSpaceDirectories(migrationsDir)).filter((name) => name !== APP_SPACE_ID$1).filter(isValidSpaceId).sort();
|
|
474
|
+
const states = [];
|
|
475
|
+
for (const spaceId of extensionIds) states.push(await loadExtensionSpace(migrationsDir, spaceId, deserializeContract));
|
|
476
|
+
return states;
|
|
477
|
+
}
|
|
478
|
+
async function loadExtensionSpace(migrationsDir, spaceId, deserializeContract) {
|
|
479
|
+
const spaceDir = spaceMigrationDirectory(migrationsDir, spaceId);
|
|
480
|
+
const { packages, problems } = await readMigrationsDir(spaceDir, { migrationsDir });
|
|
481
|
+
const { refs, problems: refProblems } = await readRefsTolerant(spaceRefsDirectory(spaceDir));
|
|
482
|
+
const { headRef, problem: headRefProblem } = await readHeadRefTolerant(migrationsDir, spaceId);
|
|
483
|
+
const rawContract = await readRawContractDeferred(migrationsDir, spaceId, headRef);
|
|
484
|
+
return {
|
|
485
|
+
space: createAggregateContractSpace({
|
|
486
|
+
spaceId,
|
|
487
|
+
packages,
|
|
488
|
+
refs,
|
|
489
|
+
headRef,
|
|
490
|
+
refsDir: spaceRefsDirectory(spaceDir),
|
|
491
|
+
migrationsDir,
|
|
492
|
+
resolveContract: () => deserializeContract(rawContract()),
|
|
493
|
+
deserializeContract
|
|
494
|
+
}),
|
|
495
|
+
problems,
|
|
496
|
+
refProblems,
|
|
497
|
+
headRefProblem,
|
|
498
|
+
isApp: false
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Read an extension's head ref, distinguishing a *genuinely absent*
|
|
503
|
+
* `head.json` (`headRef: null`, no problem — judged `headRefMissing`)
|
|
504
|
+
* from one that *exists but cannot be parsed* (`headRef: null` plus a
|
|
505
|
+
* problem — judged `refUnreadable`, not `headRefMissing`).
|
|
506
|
+
* `readContractSpaceHeadRef` already returns `null` only for ENOENT and
|
|
507
|
+
* throws for unparseable / schema-invalid content, so the throw is the
|
|
508
|
+
* corruption signal. Construction never throws on disk content.
|
|
509
|
+
*/
|
|
510
|
+
function isToleratedRefHeadReadError(error) {
|
|
511
|
+
if (MigrationToolsError.is(error)) return true;
|
|
512
|
+
if (!(error instanceof Error)) return false;
|
|
513
|
+
const code = error.code;
|
|
514
|
+
return code === "ENOENT" || code === "EISDIR";
|
|
515
|
+
}
|
|
516
|
+
async function readHeadRefTolerant(migrationsDir, spaceId) {
|
|
517
|
+
try {
|
|
518
|
+
return {
|
|
519
|
+
headRef: await readContractSpaceHeadRef(migrationsDir, spaceId),
|
|
520
|
+
problem: null
|
|
521
|
+
};
|
|
522
|
+
} catch (error) {
|
|
523
|
+
if (!isToleratedRefHeadReadError(error)) throw error;
|
|
524
|
+
return {
|
|
525
|
+
headRef: null,
|
|
526
|
+
problem: {
|
|
527
|
+
refName: HEAD_REF_NAME,
|
|
528
|
+
detail: detailOf(error)
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function detailOf(error) {
|
|
534
|
+
return error instanceof Error ? error.message : String(error);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Read the raw contract snapshot-store entry eagerly (cheap I/O) but defer
|
|
538
|
+
* its (throwing) failure to call time, so a missing or unparseable store
|
|
539
|
+
* entry becomes a `contract()` throw — surfaced as `contractUnreadable` —
|
|
540
|
+
* rather than a construction failure. When `headRef` is absent there is no
|
|
541
|
+
* hash to resolve against the store, so the deferred call always throws;
|
|
542
|
+
* `checkIntegrity` already reports that case as `headRefMissing`, and a
|
|
543
|
+
* `checkContracts` pass surfaces the same space as `contractUnreadable`.
|
|
544
|
+
*/
|
|
545
|
+
async function readRawContractDeferred(migrationsDir, spaceId, headRef) {
|
|
546
|
+
if (headRef === null) return () => {
|
|
547
|
+
throw errorSpaceHeadRefMissing(spaceId);
|
|
548
|
+
};
|
|
549
|
+
try {
|
|
550
|
+
const raw = await readContractSnapshotJson(migrationsDir, headRef.hash);
|
|
551
|
+
return () => raw;
|
|
552
|
+
} catch (error) {
|
|
553
|
+
return () => {
|
|
554
|
+
throw error;
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Plan a migration for a single contract space from a diff against the full
|
|
560
|
+
* live schema, delegating to the family's `createPlanner(...).plan(...)`.
|
|
561
|
+
*
|
|
562
|
+
* The planner diffs the whole introspected schema, so it sees other contract
|
|
563
|
+
* spaces' tables as "extras"; the orchestration hands the planner the
|
|
564
|
+
* aggregate as an ownership oracle so it can ask, per extra, whether any
|
|
565
|
+
* space owns it — a sibling-owned table is left untouched, so the planner
|
|
566
|
+
* never emits a destructive drop for it, and this strategy holds no ownership
|
|
567
|
+
* logic of its own. The schema is never pruned before planning: cross-space
|
|
568
|
+
* foreign keys need every sibling table visible to the diff.
|
|
569
|
+
*
|
|
570
|
+
* The produced plan's `targetId` is set from `aggregateTargetId`
|
|
571
|
+
* (the aggregate's ambient target). The family's planner does not
|
|
572
|
+
* stamp `targetId` on the produced plan; the aggregate planner is
|
|
573
|
+
* the single point that knows the target.
|
|
574
|
+
*
|
|
575
|
+
* Used by:
|
|
576
|
+
*
|
|
577
|
+
* - The app space by default (CLI policy
|
|
578
|
+
* `ignoreGraphFor: { app.spaceId }`).
|
|
579
|
+
* - Any extension space whose `headRef.invariants` is empty and whose
|
|
580
|
+
* graph is non-empty (the all-external, zero-migration-package case is
|
|
581
|
+
* handled directly by the aggregate planner without calling this).
|
|
582
|
+
*/
|
|
583
|
+
async function planFromDiff(input) {
|
|
584
|
+
const plannerResult = await input.migrations.createPlanner(input.adapter).plan({
|
|
585
|
+
contract: input.space.contract(),
|
|
586
|
+
schema: input.schemaIntrospection,
|
|
587
|
+
policy: input.operationPolicy,
|
|
588
|
+
fromContract: null,
|
|
589
|
+
frameworkComponents: input.frameworkComponents,
|
|
590
|
+
spaceId: input.space.spaceId,
|
|
591
|
+
ownership: input.ownership,
|
|
592
|
+
snapshotsImportPath: ""
|
|
593
|
+
});
|
|
594
|
+
if (plannerResult.kind === "failure") return {
|
|
595
|
+
kind: "failure",
|
|
596
|
+
conflicts: plannerResult.conflicts
|
|
597
|
+
};
|
|
598
|
+
const producedPlan = plannerResult.plan;
|
|
599
|
+
const plan = new Proxy(producedPlan, {
|
|
600
|
+
get(target, prop) {
|
|
601
|
+
if (prop === "targetId") return input.aggregateTargetId;
|
|
602
|
+
return Reflect.get(target, prop, target);
|
|
603
|
+
},
|
|
604
|
+
has(target, prop) {
|
|
605
|
+
if (prop === "targetId") return true;
|
|
606
|
+
return Reflect.has(target, prop);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
const destinationStorageHash = producedPlan.destination.storageHash;
|
|
610
|
+
const producedOps = await Promise.all(producedPlan.operations);
|
|
611
|
+
const destinationContract = input.space.contract();
|
|
612
|
+
return {
|
|
613
|
+
kind: "ok",
|
|
614
|
+
result: {
|
|
615
|
+
plan,
|
|
616
|
+
displayOps: producedOps,
|
|
617
|
+
destinationContract,
|
|
618
|
+
strategy: "plan-from-diff",
|
|
619
|
+
...plannerResult.warnings && plannerResult.warnings.length > 0 ? { warnings: plannerResult.warnings } : {},
|
|
620
|
+
migrationEdges: [buildFabricatedMigrationEdge({
|
|
621
|
+
currentMarkerStorageHash: input.currentMarker?.storageHash,
|
|
622
|
+
destinationStorageHash,
|
|
623
|
+
operationCount: producedOps.length,
|
|
624
|
+
destinationContractJson: destinationContract
|
|
625
|
+
})]
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Resolve a contract space's hydrated migration graph to the path from the
|
|
631
|
+
* live marker to `space.headRef.hash`, covering every required invariant.
|
|
632
|
+
*
|
|
633
|
+
* Pure synchronous function — no I/O. The aggregate's loader has
|
|
634
|
+
* already integrity-checked every package and reconstructed the graph;
|
|
635
|
+
* this resolves the path by looking up ops by `migrationHash` and
|
|
636
|
+
* assembles a `MigrationPlan` with `targetId` set from the aggregate (no
|
|
637
|
+
* placeholder cast).
|
|
638
|
+
*
|
|
639
|
+
* Required invariants are computed as `headRef.invariants \ marker.invariants`
|
|
640
|
+
* — the marker already declares some invariants satisfied; the path
|
|
641
|
+
* only needs to provide the remainder. Mirrors today's
|
|
642
|
+
* `computeExtensionSpaceApplyPath` semantics.
|
|
643
|
+
*/
|
|
644
|
+
function resolveRecordedPath(input) {
|
|
645
|
+
const { aggregateTargetId, space, currentMarker, refName } = input;
|
|
646
|
+
const headRef = requireHeadRef(space);
|
|
647
|
+
const graph = space.graph();
|
|
648
|
+
const packagesByMigrationHash = new Map(space.packages.map((pkg) => [pkg.metadata.migrationHash, pkg]));
|
|
649
|
+
const fromHash = currentMarker?.storageHash ?? "empty";
|
|
650
|
+
const markerInvariants = new Set(currentMarker?.invariants ?? []);
|
|
651
|
+
const required = new Set(headRef.invariants.filter((id) => !markerInvariants.has(id)));
|
|
652
|
+
const outcome = findPathWithDecision(graph, fromHash, headRef.hash, {
|
|
653
|
+
required,
|
|
654
|
+
...refName !== void 0 ? { refName } : {}
|
|
655
|
+
});
|
|
656
|
+
if (outcome.kind === "unreachable") return { kind: "unreachable" };
|
|
657
|
+
if (outcome.kind === "unsatisfiable") return {
|
|
658
|
+
kind: "unsatisfiable",
|
|
659
|
+
missing: outcome.missing
|
|
660
|
+
};
|
|
661
|
+
const pathOps = [];
|
|
662
|
+
const providedInvariantsSet = /* @__PURE__ */ new Set();
|
|
663
|
+
const edgeRefs = [];
|
|
664
|
+
for (const edge of outcome.decision.selectedPath) {
|
|
665
|
+
const pkg = packagesByMigrationHash.get(edge.migrationHash);
|
|
666
|
+
if (!pkg) throw new InternalError(`Migration package missing for edge ${edge.migrationHash} in space "${space.spaceId}". The hydrated migration graph and packagesByMigrationHash map are out of sync — this should be unreachable; report.`);
|
|
667
|
+
for (const op of pkg.ops) pathOps.push(op);
|
|
668
|
+
for (const invariant of pkg.metadata.providedInvariants) providedInvariantsSet.add(invariant);
|
|
669
|
+
edgeRefs.push({
|
|
670
|
+
migrationHash: edge.migrationHash,
|
|
671
|
+
dirName: edge.dirName,
|
|
672
|
+
from: edge.from,
|
|
673
|
+
to: edge.to,
|
|
674
|
+
operationCount: pkg.ops.length,
|
|
675
|
+
...pkg.endContractJson !== void 0 ? { destinationContractJson: pkg.endContractJson } : {}
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
kind: "ok",
|
|
680
|
+
result: {
|
|
681
|
+
plan: {
|
|
682
|
+
targetId: aggregateTargetId,
|
|
683
|
+
spaceId: space.spaceId,
|
|
684
|
+
origin: currentMarker === null ? null : { storageHash: currentMarker.storageHash },
|
|
685
|
+
destination: { storageHash: headRef.hash },
|
|
686
|
+
operations: pathOps,
|
|
687
|
+
providedInvariants: [...providedInvariantsSet].sort()
|
|
688
|
+
},
|
|
689
|
+
displayOps: pathOps,
|
|
690
|
+
destinationContract: space.contract(),
|
|
691
|
+
strategy: "resolve-recorded-path",
|
|
692
|
+
migrationEdges: edgeRefs,
|
|
693
|
+
pathDecision: outcome.decision
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Plan a migration across every contract space of a {@link ContractSpaceAggregate}.
|
|
699
|
+
*
|
|
700
|
+
* Per-space operation selection, in order; first match wins:
|
|
701
|
+
*
|
|
702
|
+
* 1. If `callerPolicy.ignoreGraphFor.has(space.spaceId)`:
|
|
703
|
+
* - If `space.headRef.invariants` is empty → `planFromDiff`.
|
|
704
|
+
* - Else → `policyConflict` (a diff-fabricated plan cannot satisfy
|
|
705
|
+
* authored invariants).
|
|
706
|
+
* 2. Else if `space.graph()` is non-empty AND `resolveRecordedPath`
|
|
707
|
+
* succeeds → its result.
|
|
708
|
+
* 3. Else if `space.graph()` is non-empty but unresolvable →
|
|
709
|
+
* `extensionPathUnreachable` / `extensionPathUnsatisfiable`.
|
|
710
|
+
* 4. Else (empty graph — the space ships no migration packages at all,
|
|
711
|
+
* e.g. an all-external extension space like Supabase's `auth`/`storage`)
|
|
712
|
+
* if `space.headRef.invariants` is empty → declare the no-op state
|
|
713
|
+
* directly (zero ops, destination = head ref) without invoking the
|
|
714
|
+
* family planner.
|
|
715
|
+
* 5. Else → `extensionPathUnsatisfiable` (an empty graph cannot satisfy
|
|
716
|
+
* non-empty invariants).
|
|
717
|
+
*
|
|
718
|
+
* Output `applyOrder` is `[...aggregate.extensions.map(spaceId), aggregate.app.spaceId]`
|
|
719
|
+
* — extensions alphabetical, then app — matching today's
|
|
720
|
+
* `concatenateSpaceApplyInputs` ordering. This preserves
|
|
721
|
+
* `MigrationRunnerFailure.failingSpace` attribution byte-for-byte.
|
|
722
|
+
*
|
|
723
|
+
* Every emitted `MigrationPlan` has `targetId = aggregate.targetId`.
|
|
724
|
+
* No placeholder cast; no patch step.
|
|
725
|
+
*/
|
|
726
|
+
async function planMigration(input) {
|
|
727
|
+
const { aggregate, currentDBState, callerPolicy } = input;
|
|
728
|
+
const perSpace = /* @__PURE__ */ new Map();
|
|
729
|
+
const orderedSpaces = [...aggregate.extensions, aggregate.app];
|
|
730
|
+
for (const space of orderedSpaces) {
|
|
731
|
+
const currentMarker = currentDBState.markersBySpaceId.get(space.spaceId) ?? null;
|
|
732
|
+
const headRef = requireHeadRef(space);
|
|
733
|
+
const ignoreGraph = callerPolicy.ignoreGraphFor.has(space.spaceId);
|
|
734
|
+
const invariantsRequired = headRef.invariants.length > 0;
|
|
735
|
+
if (ignoreGraph && invariantsRequired) return notOk({
|
|
736
|
+
kind: "policyConflict",
|
|
737
|
+
spaceId: space.spaceId,
|
|
738
|
+
detail: `\`callerPolicy.ignoreGraphFor\` requested for space "${space.spaceId}", but the contract space declares non-empty head-ref invariants (${headRef.invariants.join(", ")}). A plan built directly from the contract IR cannot satisfy authored invariants — the graph must be walked. Either remove "${space.spaceId}" from \`ignoreGraphFor\` or amend the on-disk head ref to declare zero invariants.`
|
|
739
|
+
});
|
|
740
|
+
if (ignoreGraph) {
|
|
741
|
+
const diffOutcome = await planFromDiff({
|
|
742
|
+
aggregateTargetId: aggregate.targetId,
|
|
743
|
+
currentMarker,
|
|
744
|
+
space,
|
|
745
|
+
ownership: aggregate,
|
|
746
|
+
schemaIntrospection: currentDBState.schemaIntrospection,
|
|
747
|
+
adapter: input.adapter,
|
|
748
|
+
migrations: input.migrations,
|
|
749
|
+
frameworkComponents: input.frameworkComponents,
|
|
750
|
+
operationPolicy: input.operationPolicy
|
|
751
|
+
});
|
|
752
|
+
if (diffOutcome.kind === "failure") return notOk({
|
|
753
|
+
kind: "planFromDiffFailed",
|
|
754
|
+
spaceId: space.spaceId,
|
|
755
|
+
conflicts: diffOutcome.conflicts
|
|
756
|
+
});
|
|
757
|
+
perSpace.set(space.spaceId, diffOutcome.result);
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
if (space.graph().nodes.size > 0) {
|
|
761
|
+
const resolved = resolveRecordedPath({
|
|
762
|
+
aggregateTargetId: aggregate.targetId,
|
|
763
|
+
space,
|
|
764
|
+
currentMarker
|
|
765
|
+
});
|
|
766
|
+
if (resolved.kind === "ok") {
|
|
767
|
+
perSpace.set(space.spaceId, resolved.result);
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
if (resolved.kind === "unreachable") return notOk({
|
|
771
|
+
kind: "extensionPathUnreachable",
|
|
772
|
+
spaceId: space.spaceId,
|
|
773
|
+
target: headRef.hash
|
|
774
|
+
});
|
|
775
|
+
return notOk({
|
|
776
|
+
kind: "extensionPathUnsatisfiable",
|
|
777
|
+
spaceId: space.spaceId,
|
|
778
|
+
missingInvariants: resolved.missing
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
if (invariantsRequired) return notOk({
|
|
782
|
+
kind: "extensionPathUnsatisfiable",
|
|
783
|
+
spaceId: space.spaceId,
|
|
784
|
+
missingInvariants: [...headRef.invariants].sort()
|
|
785
|
+
});
|
|
786
|
+
if (!allStorageElementsExternal(space.contract())) return notOk({
|
|
787
|
+
kind: "extensionPathUnreachable",
|
|
788
|
+
spaceId: space.spaceId,
|
|
789
|
+
target: headRef.hash
|
|
790
|
+
});
|
|
791
|
+
perSpace.set(space.spaceId, {
|
|
792
|
+
plan: {
|
|
793
|
+
targetId: aggregate.targetId,
|
|
794
|
+
spaceId: space.spaceId,
|
|
795
|
+
origin: currentMarker === null ? null : { storageHash: currentMarker.storageHash },
|
|
796
|
+
destination: { storageHash: headRef.hash },
|
|
797
|
+
operations: []
|
|
798
|
+
},
|
|
799
|
+
displayOps: [],
|
|
800
|
+
destinationContract: space.contract(),
|
|
801
|
+
strategy: "declared-state",
|
|
802
|
+
migrationEdges: [buildFabricatedMigrationEdge({
|
|
803
|
+
currentMarkerStorageHash: currentMarker?.storageHash,
|
|
804
|
+
destinationStorageHash: headRef.hash,
|
|
805
|
+
operationCount: 0
|
|
806
|
+
})]
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
return ok({
|
|
810
|
+
perSpace,
|
|
811
|
+
applyOrder: [...aggregate.extensions.map((m) => m.spaceId), aggregate.app.spaceId]
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
function pathIsUnder(path, prefix) {
|
|
815
|
+
if (path.length < prefix.length) return false;
|
|
816
|
+
return prefix.every((segment, i) => path[i] === segment);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Whether an issue's subject is a WHOLE top-level entity — as opposed to
|
|
820
|
+
* something nested under one (e.g. a field, an index, or a policy). Calls
|
|
821
|
+
* the injected `classify` capability, which resolves this from the issue's
|
|
822
|
+
* node `nodeKind` (this aggregate never reaches into the node itself).
|
|
823
|
+
* Absent `classify` (or a `classify` that returns nothing for this issue —
|
|
824
|
+
* a family that doesn't classify) falls back to path shape: a
|
|
825
|
+
* top-level entity's path is exactly its own name (one segment), so
|
|
826
|
+
* anything deeper is nested.
|
|
827
|
+
*/
|
|
828
|
+
function isWholeEntityIssue(issue, classify) {
|
|
829
|
+
const granularity = classify?.(issue);
|
|
830
|
+
if (granularity !== void 0) return granularity === "entity";
|
|
831
|
+
return issue.path.length === 1;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* A contract space's contract-satisfaction view. Strips the top-level entity
|
|
835
|
+
* extras — the `not-expected` findings on whole-entity nodes (plus the
|
|
836
|
+
* findings the differ's total descent reported under those entities). Those
|
|
837
|
+
* belong to the standalone unclaimed-elements list
|
|
838
|
+
* ({@link collectExtraElementCoordinates}), never a space's own verdict.
|
|
839
|
+
*
|
|
840
|
+
* Nested `not-expected` findings (an extra field on the space's own
|
|
841
|
+
* declared entity…) and structural findings (an undeclared policy) are
|
|
842
|
+
* the space's **own drift** and stay.
|
|
843
|
+
*
|
|
844
|
+
* The verdict recomputes from the surviving list: the per-space result is
|
|
845
|
+
* issue-based (`ok` ⇔ the list is empty), so a space whose only failures
|
|
846
|
+
* were top-level extras passes after the strip.
|
|
847
|
+
*/
|
|
848
|
+
function stripExtraFindings(result, classify) {
|
|
849
|
+
const droppedTablePaths = result.schema.issues.filter((issue) => issueOutcome(issue) === "not-expected" && isWholeEntityIssue(issue, classify)).map((issue) => issue.path);
|
|
850
|
+
const issues = result.schema.issues.filter((issue) => {
|
|
851
|
+
if (issueOutcome(issue) !== "not-expected") return true;
|
|
852
|
+
if (classify?.(issue) === "structural") return true;
|
|
853
|
+
return !droppedTablePaths.some((prefix) => pathIsUnder(issue.path, prefix));
|
|
854
|
+
});
|
|
855
|
+
if (issues.length === result.schema.issues.length) return result;
|
|
856
|
+
const ok = issues.length === 0;
|
|
857
|
+
const { code: staleCode, ...envelope } = result;
|
|
858
|
+
return {
|
|
859
|
+
...envelope,
|
|
860
|
+
ok,
|
|
861
|
+
...ok ? {} : { code: result.code ?? "CONTRACT.MARKER_REQUIRED" },
|
|
862
|
+
summary: ok ? "Database schema satisfies contract" : result.summary,
|
|
863
|
+
schema: {
|
|
864
|
+
issues,
|
|
865
|
+
...result.schema.warnings !== void 0 ? { warnings: result.schema.warnings } : {}
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* The schema-IR entity coordinate a `not-expected` `SchemaDiffIssue`
|
|
871
|
+
* addresses, when its subject is a whole top-level entity. A nested leaf
|
|
872
|
+
* (a field, an index, a policy on an undeclared entity) has no entity of
|
|
873
|
+
* its own to report here.
|
|
874
|
+
*
|
|
875
|
+
* The whole-entity's name is the last path segment: the differ builds each
|
|
876
|
+
* path from its nodes' ids, so at a whole-entity finding the last segment is
|
|
877
|
+
* exactly the entity name — for every family, whether or not it stamps a
|
|
878
|
+
* granularity. The namespace segment only exists for namespace-qualified
|
|
879
|
+
* paths (`['database', namespaceId, entityName]`); single-namespace families
|
|
880
|
+
* (a flat `['database', entityName]`, or a bare `[entityName]`) have no
|
|
881
|
+
* separate segment, so every entity they declare implicitly shares one
|
|
882
|
+
* namespace — the same sentinel the aggregate's own coordinate walk uses
|
|
883
|
+
* for those families.
|
|
884
|
+
*
|
|
885
|
+
* `entityKind` is asked from the injected `classifyEntityKind` capability —
|
|
886
|
+
* this module never names a family entity kind itself. Absent a classifier
|
|
887
|
+
* (the classifier-absent path-shape fallback, e.g. a document family) the
|
|
888
|
+
* coordinate carries {@link UNCLASSIFIED_ENTITY_KIND}: no ownership
|
|
889
|
+
* consumer queries `declaresEntity` for a family in that state today, so
|
|
890
|
+
* nothing reads the value as true.
|
|
891
|
+
*/
|
|
892
|
+
function schemaDiffIssueCoordinate(issue, classify, classifyEntityKind) {
|
|
893
|
+
if (!isWholeEntityIssue(issue, classify)) return void 0;
|
|
894
|
+
const entityName = issue.path[issue.path.length - 1];
|
|
895
|
+
if (entityName === void 0) return void 0;
|
|
896
|
+
return {
|
|
897
|
+
namespaceId: issue.path.length === 3 ? issue.path[1] ?? UNBOUND_NAMESPACE_ID : UNBOUND_NAMESPACE_ID,
|
|
898
|
+
entityKind: classifyEntityKind?.(issue) ?? "unclassified-entity",
|
|
899
|
+
entityName
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* The schema-IR entity coordinates of every live element this contract
|
|
904
|
+
* space's diff reports as `not-expected`, deduplicated. The verifier gathers
|
|
905
|
+
* these across all spaces and keeps only the coordinates no contract space
|
|
906
|
+
* declares — the standalone unclaimed-elements list, reported once for the
|
|
907
|
+
* whole database.
|
|
908
|
+
*/
|
|
909
|
+
function collectExtraElementCoordinates(result, classify, classifyEntityKind) {
|
|
910
|
+
const seen = /* @__PURE__ */ new Map();
|
|
911
|
+
for (const issue of result.schema.issues) {
|
|
912
|
+
if (issueOutcome(issue) !== "not-expected") continue;
|
|
913
|
+
const coordinate = schemaDiffIssueCoordinate(issue, classify, classifyEntityKind);
|
|
914
|
+
if (coordinate === void 0) continue;
|
|
915
|
+
seen.set(coordinateKey(coordinate), coordinate);
|
|
916
|
+
}
|
|
917
|
+
return [...seen.values()];
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Verify a {@link ContractSpaceAggregate} against the live database
|
|
921
|
+
* state. Bundles two checks:
|
|
922
|
+
*
|
|
923
|
+
* - `markerCheck` per contract space: compare the live marker row against the
|
|
924
|
+
* space's `headRef.hash` + `headRef.invariants`. Absence is a
|
|
925
|
+
* distinct kind, not an error (callers — `db verify` strict vs
|
|
926
|
+
* `db init` precondition — choose how to interpret it).
|
|
927
|
+
* - `schemaCheck`: two distinct outputs from the per-space diffs.
|
|
928
|
+
* `perSpace` — each space verified against the **full**
|
|
929
|
+
* introspected schema, then its extras stripped, leaving the space's
|
|
930
|
+
* declared nodes (its contract-satisfaction view; verdict is
|
|
931
|
+
* missing/mismatch only). `unclaimed` — the extras gathered
|
|
932
|
+
* across every space, deduplicated, and filtered to the names no contract
|
|
933
|
+
* space declares (via the passive aggregate's ownership query); reported
|
|
934
|
+
* once for the database. No schema is pruned before verifying.
|
|
935
|
+
*
|
|
936
|
+
* `markerCheck.orphanMarkers` lists every marker row whose `space` is
|
|
937
|
+
* not a contract space of the aggregate. `db verify` callers reject orphans;
|
|
938
|
+
* future tooling may not.
|
|
939
|
+
*
|
|
940
|
+
* Pure synchronous function; no I/O. The caller (CLI) gathers
|
|
941
|
+
* `markersBySpaceId` and `schemaIntrospection` ahead of the call.
|
|
942
|
+
*/
|
|
943
|
+
function verifyMigration(input) {
|
|
944
|
+
try {
|
|
945
|
+
return runVerifyMigration(input);
|
|
946
|
+
} catch (error) {
|
|
947
|
+
return notOk({
|
|
948
|
+
kind: "introspectionFailure",
|
|
949
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
function runVerifyMigration(input) {
|
|
954
|
+
const { aggregate, markersBySpaceId, schemaIntrospection, mode, verifySchemaForSpace, classifySubjectGranularity, classifyEntityKind } = input;
|
|
955
|
+
const allSpaces = [aggregate.app, ...aggregate.extensions];
|
|
956
|
+
const aggregateSpaceIds = new Set(allSpaces.map((m) => m.spaceId));
|
|
957
|
+
const markerPerSpace = /* @__PURE__ */ new Map();
|
|
958
|
+
for (const space of allSpaces) {
|
|
959
|
+
const marker = markersBySpaceId.get(space.spaceId) ?? null;
|
|
960
|
+
if (marker === null) {
|
|
961
|
+
markerPerSpace.set(space.spaceId, { kind: "absent" });
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
const headRef = requireHeadRef(space);
|
|
965
|
+
if (marker.storageHash !== headRef.hash) {
|
|
966
|
+
markerPerSpace.set(space.spaceId, {
|
|
967
|
+
kind: "hashMismatch",
|
|
968
|
+
markerHash: marker.storageHash,
|
|
969
|
+
expected: headRef.hash
|
|
970
|
+
});
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
const markerInvariants = new Set(marker.invariants);
|
|
974
|
+
const missing = headRef.invariants.filter((id) => !markerInvariants.has(id));
|
|
975
|
+
if (missing.length > 0) {
|
|
976
|
+
markerPerSpace.set(space.spaceId, {
|
|
977
|
+
kind: "missingInvariants",
|
|
978
|
+
missing: [...missing].sort()
|
|
979
|
+
});
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
markerPerSpace.set(space.spaceId, { kind: "ok" });
|
|
983
|
+
}
|
|
984
|
+
const orphanMarkers = [];
|
|
985
|
+
for (const [spaceId, row] of markersBySpaceId) if (row !== null && !aggregateSpaceIds.has(spaceId)) orphanMarkers.push({
|
|
986
|
+
spaceId,
|
|
987
|
+
row
|
|
988
|
+
});
|
|
989
|
+
orphanMarkers.sort((a, b) => a.spaceId.localeCompare(b.spaceId));
|
|
990
|
+
const schemaPerSpace = /* @__PURE__ */ new Map();
|
|
991
|
+
const extraCoordinates = /* @__PURE__ */ new Map();
|
|
992
|
+
for (const space of allSpaces) {
|
|
993
|
+
const result = verifySchemaForSpace(schemaIntrospection, space, mode);
|
|
994
|
+
schemaPerSpace.set(space.spaceId, stripExtraFindings(result, classifySubjectGranularity));
|
|
995
|
+
for (const coordinate of collectExtraElementCoordinates(result, classifySubjectGranularity, classifyEntityKind)) extraCoordinates.set(coordinateKey(coordinate), coordinate);
|
|
996
|
+
}
|
|
997
|
+
const unclaimed = [...new Set([...extraCoordinates.values()].filter((coordinate) => !aggregate.declaresEntity(coordinate)).map((coordinate) => coordinate.entityName))].sort((a, b) => a.localeCompare(b));
|
|
998
|
+
return ok({
|
|
999
|
+
markerCheck: {
|
|
1000
|
+
perSpace: markerPerSpace,
|
|
1001
|
+
orphanMarkers
|
|
1002
|
+
},
|
|
1003
|
+
schemaCheck: {
|
|
1004
|
+
perSpace: schemaPerSpace,
|
|
1005
|
+
unclaimed
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
//#endregion
|
|
1010
|
+
export { createAggregateContractSpace as a, loadProblemToViolation as c, resolveRecordedPath as d, verifyMigration as f, computeIntegrityViolations as i, planMigration as l, buildFabricatedMigrationEdge as n, createContractSpaceAggregate as o, collectAggregateNamespaces as r, loadContractSpaceAggregate as s, allStorageElementsExternal as t, requireHeadRef as u };
|
|
1011
|
+
|
|
1012
|
+
//# sourceMappingURL=aggregate-B4mhR4Sk.mjs.map
|