@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,118 @@
|
|
|
1
|
+
import { a as errorContractSnapshotHashMismatch, g as errorInvalidJson, o as errorContractSnapshotMissing } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import { join, relative } from "pathe";
|
|
3
|
+
import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex } from "@prisma/orm-framework/components/control";
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { canonicalizeJson } from "@prisma/orm-framework/components/utils";
|
|
7
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
8
|
+
//#region ../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-sf5nP4mb.mjs
|
|
9
|
+
const CONTRACT_JSON_FILE = "contract.json";
|
|
10
|
+
const CONTRACT_DTS_FILE = "contract.d.ts";
|
|
11
|
+
function hasErrnoCode(error, code) {
|
|
12
|
+
return error instanceof Error && blindCast(error).code === code;
|
|
13
|
+
}
|
|
14
|
+
async function directoryExists(p) {
|
|
15
|
+
try {
|
|
16
|
+
return (await stat(p)).isDirectory();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (hasErrnoCode(error, "ENOENT")) return false;
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function contractSnapshotDir(migrationsDir, storageHash) {
|
|
23
|
+
return join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex(storageHash));
|
|
24
|
+
}
|
|
25
|
+
async function writeContractSnapshot(migrationsDir, storageHash, input) {
|
|
26
|
+
const dir = contractSnapshotDir(migrationsDir, storageHash);
|
|
27
|
+
const actualStorageHash = blindCast(input.contractJson).storage?.storageHash;
|
|
28
|
+
if (actualStorageHash !== storageHash) throw errorContractSnapshotHashMismatch(storageHash, typeof actualStorageHash === "string" ? actualStorageHash : String(actualStorageHash), dir);
|
|
29
|
+
if (await directoryExists(dir)) return {
|
|
30
|
+
written: false,
|
|
31
|
+
dir
|
|
32
|
+
};
|
|
33
|
+
const tmpDir = join(join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME), `.tmp-${storageHashHex(storageHash)}-${Date.now()}-${randomBytes(4).toString("hex")}`);
|
|
34
|
+
await mkdir(tmpDir, { recursive: true });
|
|
35
|
+
const jsonContent = `${canonicalizeJson(input.contractJson)}\n`;
|
|
36
|
+
const dtsContent = input.contractDts.endsWith("\n") ? input.contractDts : `${input.contractDts}\n`;
|
|
37
|
+
try {
|
|
38
|
+
await writeFile(join(tmpDir, CONTRACT_JSON_FILE), jsonContent);
|
|
39
|
+
await writeFile(join(tmpDir, CONTRACT_DTS_FILE), dtsContent);
|
|
40
|
+
await rename(tmpDir, dir);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
await rm(tmpDir, {
|
|
43
|
+
recursive: true,
|
|
44
|
+
force: true
|
|
45
|
+
});
|
|
46
|
+
if (hasErrnoCode(error, "EEXIST") || hasErrnoCode(error, "ENOTEMPTY")) return {
|
|
47
|
+
written: false,
|
|
48
|
+
dir
|
|
49
|
+
};
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
written: true,
|
|
54
|
+
dir
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function readContractSnapshotJson(migrationsDir, storageHash) {
|
|
58
|
+
const jsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);
|
|
59
|
+
let raw;
|
|
60
|
+
try {
|
|
61
|
+
raw = await readFile(jsonPath, "utf-8");
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (hasErrnoCode(error, "ENOENT")) throw errorContractSnapshotMissing(storageHash, jsonPath);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(raw);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw errorInvalidJson(jsonPath, e instanceof Error ? e.message : String(e));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Tolerant read: a missing store entry (ENOENT), an unparseable
|
|
74
|
+
* `contract.json`, the JSON literal `null`, or a `storageHash` that isn't a
|
|
75
|
+
* well-formed 64-hex value all resolve to `undefined` rather than
|
|
76
|
+
* throwing — parity with the catch-all tolerance of the pre-store
|
|
77
|
+
* `readEndContractJson` (`io.ts`), which never validated the hash it was
|
|
78
|
+
* keyed by either. Any other fs error (e.g. `EACCES` on a present-but-
|
|
79
|
+
* unreadable file) propagates rather than silently loading a contract-less
|
|
80
|
+
* package.
|
|
81
|
+
*/
|
|
82
|
+
async function readContractSnapshotJsonTolerant(migrationsDir, storageHash) {
|
|
83
|
+
let jsonPath;
|
|
84
|
+
try {
|
|
85
|
+
jsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);
|
|
86
|
+
} catch {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = await readFile(jsonPath, "utf-8");
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (hasErrnoCode(error, "ENOENT")) return;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const parsed = JSON.parse(raw);
|
|
98
|
+
return parsed === null ? void 0 : parsed;
|
|
99
|
+
} catch {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function readContractSnapshotDts(migrationsDir, storageHash) {
|
|
104
|
+
const dtsPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_DTS_FILE);
|
|
105
|
+
try {
|
|
106
|
+
return await readFile(dtsPath, "utf-8");
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (hasErrnoCode(error, "ENOENT")) throw errorContractSnapshotMissing(storageHash, dtsPath);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function snapshotsImportPathFrom(packageDir, migrationsDir) {
|
|
113
|
+
return relative(packageDir, join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME)).split("\\").join("/");
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { snapshotsImportPathFrom as a, readContractSnapshotJsonTolerant as i, readContractSnapshotDts as n, writeContractSnapshot as o, readContractSnapshotJson as r, contractSnapshotDir as t };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs","names":[],"sources":["../../../../1-framework/3-tooling/migration/dist/contract-snapshot-store-sf5nP4mb.mjs"],"sourcesContent":["import { a as errorContractSnapshotHashMismatch, g as errorInvalidJson, o as errorContractSnapshotMissing } from \"./errors-IpZm1Skp.mjs\";\nimport { join, relative } from \"pathe\";\nimport { mkdir, readFile, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { randomBytes } from \"node:crypto\";\nimport { CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex } from \"@internal/framework-components/control\";\nimport { canonicalizeJson } from \"@internal/framework-components/utils\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/contract-snapshot-store.ts\nconst CONTRACT_JSON_FILE = \"contract.json\";\nconst CONTRACT_DTS_FILE = \"contract.d.ts\";\nfunction hasErrnoCode(error, code) {\n\treturn error instanceof Error && blindCast(error).code === code;\n}\nasync function directoryExists(p) {\n\ttry {\n\t\treturn (await stat(p)).isDirectory();\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) return false;\n\t\tthrow error;\n\t}\n}\nfunction contractSnapshotDir(migrationsDir, storageHash) {\n\treturn join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME, storageHashHex(storageHash));\n}\nasync function writeContractSnapshot(migrationsDir, storageHash, input) {\n\tconst dir = contractSnapshotDir(migrationsDir, storageHash);\n\tconst actualStorageHash = blindCast(input.contractJson).storage?.storageHash;\n\tif (actualStorageHash !== storageHash) throw errorContractSnapshotHashMismatch(storageHash, typeof actualStorageHash === \"string\" ? actualStorageHash : String(actualStorageHash), dir);\n\tif (await directoryExists(dir)) return {\n\t\twritten: false,\n\t\tdir\n\t};\n\tconst tmpDir = join(join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME), `.tmp-${storageHashHex(storageHash)}-${Date.now()}-${randomBytes(4).toString(\"hex\")}`);\n\tawait mkdir(tmpDir, { recursive: true });\n\tconst jsonContent = `${canonicalizeJson(input.contractJson)}\\n`;\n\tconst dtsContent = input.contractDts.endsWith(\"\\n\") ? input.contractDts : `${input.contractDts}\\n`;\n\ttry {\n\t\tawait writeFile(join(tmpDir, CONTRACT_JSON_FILE), jsonContent);\n\t\tawait writeFile(join(tmpDir, CONTRACT_DTS_FILE), dtsContent);\n\t\tawait rename(tmpDir, dir);\n\t} catch (error) {\n\t\tawait rm(tmpDir, {\n\t\t\trecursive: true,\n\t\t\tforce: true\n\t\t});\n\t\tif (hasErrnoCode(error, \"EEXIST\") || hasErrnoCode(error, \"ENOTEMPTY\")) return {\n\t\t\twritten: false,\n\t\t\tdir\n\t\t};\n\t\tthrow error;\n\t}\n\treturn {\n\t\twritten: true,\n\t\tdir\n\t};\n}\nasync function readContractSnapshotJson(migrationsDir, storageHash) {\n\tconst jsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);\n\tlet raw;\n\ttry {\n\t\traw = await readFile(jsonPath, \"utf-8\");\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) throw errorContractSnapshotMissing(storageHash, jsonPath);\n\t\tthrow error;\n\t}\n\ttry {\n\t\treturn JSON.parse(raw);\n\t} catch (e) {\n\t\tthrow errorInvalidJson(jsonPath, e instanceof Error ? e.message : String(e));\n\t}\n}\n/**\n* Tolerant read: a missing store entry (ENOENT), an unparseable\n* `contract.json`, the JSON literal `null`, or a `storageHash` that isn't a\n* well-formed 64-hex value all resolve to `undefined` rather than\n* throwing — parity with the catch-all tolerance of the pre-store\n* `readEndContractJson` (`io.ts`), which never validated the hash it was\n* keyed by either. Any other fs error (e.g. `EACCES` on a present-but-\n* unreadable file) propagates rather than silently loading a contract-less\n* package.\n*/\nasync function readContractSnapshotJsonTolerant(migrationsDir, storageHash) {\n\tlet jsonPath;\n\ttry {\n\t\tjsonPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_JSON_FILE);\n\t} catch {\n\t\treturn;\n\t}\n\tlet raw;\n\ttry {\n\t\traw = await readFile(jsonPath, \"utf-8\");\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) return;\n\t\tthrow error;\n\t}\n\ttry {\n\t\tconst parsed = JSON.parse(raw);\n\t\treturn parsed === null ? void 0 : parsed;\n\t} catch {\n\t\treturn;\n\t}\n}\nasync function readContractSnapshotDts(migrationsDir, storageHash) {\n\tconst dtsPath = join(contractSnapshotDir(migrationsDir, storageHash), CONTRACT_DTS_FILE);\n\ttry {\n\t\treturn await readFile(dtsPath, \"utf-8\");\n\t} catch (error) {\n\t\tif (hasErrnoCode(error, \"ENOENT\")) throw errorContractSnapshotMissing(storageHash, dtsPath);\n\t\tthrow error;\n\t}\n}\nfunction snapshotsImportPathFrom(packageDir, migrationsDir) {\n\treturn relative(packageDir, join(migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME)).split(\"\\\\\").join(\"/\");\n}\n//#endregion\nexport { snapshotsImportPathFrom as a, readContractSnapshotJsonTolerant as i, readContractSnapshotDts as n, writeContractSnapshot as o, readContractSnapshotJson as r, contractSnapshotDir as t };\n\n//# sourceMappingURL=contract-snapshot-store-sf5nP4mb.mjs.map"],"mappings":"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"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { t as MigrationToolsError } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
3
|
+
import { N as errorUnexpected, Z as mapMigrationToolsError, it as resolveContractPath, nt as readContractEnvelope, t as CliStructuredError$1 } from "./command-helpers-CAoXqAY9-DWUBcTXM.mjs";
|
|
4
|
+
import { s as loadContractSpaceAggregate } from "./aggregate-B4mhR4Sk.mjs";
|
|
5
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { createControlStack } from "@prisma/orm-framework/components/control";
|
|
8
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
9
|
+
//#region ../../../1-framework/3-tooling/cli/dist/contract-space-aggregate-loader-CFH-336b.mjs
|
|
10
|
+
/**
|
|
11
|
+
* Project the CLI's `Config.extensions` array into the canonical
|
|
12
|
+
* {@link ExtensionPackInput} shape. The single `as ExtensionPackLike`
|
|
13
|
+
* structural cast in the CLI lives inside this function.
|
|
14
|
+
*/
|
|
15
|
+
function toExtensionInputs(extensions) {
|
|
16
|
+
return extensions.map((raw) => {
|
|
17
|
+
const pack = raw;
|
|
18
|
+
if (pack.contractSpace === void 0) return {
|
|
19
|
+
id: pack.id,
|
|
20
|
+
targetId: pack.targetId
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
id: pack.id,
|
|
24
|
+
targetId: pack.targetId,
|
|
25
|
+
contractSpace: {
|
|
26
|
+
contractJson: pack.contractSpace.contractJson,
|
|
27
|
+
headRef: pack.contractSpace.headRef,
|
|
28
|
+
migrations: pack.contractSpace.migrations ?? []
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Minimal aggregate-loader projection that extracts `id` + `targetId`
|
|
35
|
+
* from raw extension pack descriptors **without invoking any
|
|
36
|
+
* `contractSpace` accessor**. Inspects the own-property descriptor so
|
|
37
|
+
* that getter-backed `contractSpace` declarations are detected but
|
|
38
|
+
* never called.
|
|
39
|
+
*
|
|
40
|
+
* Inclusion semantics match {@link toDeclaredExtensions}: a data
|
|
41
|
+
* property whose value is explicitly `undefined` is treated as "no
|
|
42
|
+
* contract-space declaration" and skipped, mirroring the
|
|
43
|
+
* `pack.contractSpace === undefined` check used on canonicalised
|
|
44
|
+
* inputs. Prototype-chain `contractSpace` properties (no own
|
|
45
|
+
* descriptor) are also skipped.
|
|
46
|
+
*
|
|
47
|
+
* This variant must be used by `buildContractSpaceAggregate` so that
|
|
48
|
+
* the aggregate path (including `db verify`) never reads
|
|
49
|
+
* `contractSpace.contractJson` from extension descriptors — the loader
|
|
50
|
+
* always reads the contract from on-disk artefacts instead.
|
|
51
|
+
*/
|
|
52
|
+
function toDeclaredExtensionsFromRaw(extensions) {
|
|
53
|
+
const entries = [];
|
|
54
|
+
for (const raw of extensions) {
|
|
55
|
+
if (typeof raw !== "object" || raw === null) continue;
|
|
56
|
+
const descriptor = Object.getOwnPropertyDescriptor(raw, "contractSpace");
|
|
57
|
+
if (descriptor === void 0) continue;
|
|
58
|
+
if ("value" in descriptor && descriptor.value === void 0) continue;
|
|
59
|
+
const pack = raw;
|
|
60
|
+
entries.push({
|
|
61
|
+
id: pack.id,
|
|
62
|
+
targetId: pack.targetId
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
|
+
const CONTRACT_SPACES_DOCS_URL = "https://pris.ly/contract-spaces";
|
|
68
|
+
function contractSpaceViolationError(summary, options) {
|
|
69
|
+
return new CliStructuredError$1("MIGRATION.CONTRACT_SPACE_VIOLATION", summary, {
|
|
70
|
+
why: options.why,
|
|
71
|
+
fix: options.fix,
|
|
72
|
+
docsUrl: CONTRACT_SPACES_DOCS_URL,
|
|
73
|
+
meta: { violations: options.violations }
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build the `MIGRATION.CONTRACT_SPACE_VIOLATION` structured-error envelope for a contract-space
|
|
78
|
+
* target mismatch. Shared between the declared-extension precheck (the
|
|
79
|
+
* descriptor's configured target disagrees with the project target) and
|
|
80
|
+
* the on-disk-contract check surfaced by `checkIntegrity`.
|
|
81
|
+
*/
|
|
82
|
+
function targetMismatchError(spaceId, expected, actual) {
|
|
83
|
+
return contractSpaceViolationError(`Contract-space target mismatch for "${spaceId}"`, {
|
|
84
|
+
why: `Space "${spaceId}" targets "${actual}" but the project's adapter targets "${expected}".`,
|
|
85
|
+
fix: "Update the extension descriptor to target the configured database, or change the project adapter.",
|
|
86
|
+
violations: [{
|
|
87
|
+
kind: "targetMismatch",
|
|
88
|
+
spaceId,
|
|
89
|
+
expected,
|
|
90
|
+
actual
|
|
91
|
+
}]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Human-readable detail for an integrity violation, used as the `why`
|
|
96
|
+
* of the `integrityFailure` envelope. Mirrors the messages the prior
|
|
97
|
+
* throw-on-load loader produced so downstream consumers see the same
|
|
98
|
+
* text for the same on-disk state.
|
|
99
|
+
*/
|
|
100
|
+
function describeIntegrityViolation(violation) {
|
|
101
|
+
switch (violation.kind) {
|
|
102
|
+
case "hashMismatch": return `Migration "${violation.dirName}" stored hash "${violation.stored}" does not match computed hash "${violation.computed}".`;
|
|
103
|
+
case "providedInvariantsMismatch": return `Migration "${violation.dirName}" providedInvariants in migration.json disagrees with ops.json.`;
|
|
104
|
+
case "packageUnloadable": return `Migration "${violation.dirName}" could not be loaded: ${violation.detail}`;
|
|
105
|
+
case "sameSourceAndTarget": return `Migration "${violation.dirName}" has source equal to target (${violation.hash}) with no data invariant — a true no-op self-edge.`;
|
|
106
|
+
case "headRefMissing": return `Head ref \`refs/head.json\` is missing for contract space "${violation.spaceId}".`;
|
|
107
|
+
case "headRefNotInGraph": return `Head ref ${violation.hash} for contract space "${violation.spaceId}" is not present in the migration graph.`;
|
|
108
|
+
case "refUnreadable": return `Ref "${violation.refName}" for contract space "${violation.spaceId}" is unreadable: ${violation.detail}`;
|
|
109
|
+
case "duplicateMigrationHash": return `Multiple migrations in space "${violation.spaceId}" share migrationHash "${violation.migrationHash}" (${violation.dirNames.join(", ")}).`;
|
|
110
|
+
default: {
|
|
111
|
+
const spaceId = "spaceId" in violation ? violation.spaceId : "*";
|
|
112
|
+
return `Integrity violation "${violation.kind}" for contract space "${spaceId}".`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Map the integrity violations `checkIntegrity` reports into a single
|
|
118
|
+
* CLI structured-error envelope, preserving the error codes the prior
|
|
119
|
+
* throw-on-load loader emitted: `MIGRATION.CONTRACT_SPACE_LAYOUT_VIOLATION`
|
|
120
|
+
* (layout drift, bundled) and `MIGRATION.CONTRACT_SPACE_VIOLATION` (target /
|
|
121
|
+
* disjointness / contract-validation / structural integrity). Returns
|
|
122
|
+
* `null` when there is nothing to refuse on.
|
|
123
|
+
*
|
|
124
|
+
* Precedence reproduces the prior loader's first-failure ordering:
|
|
125
|
+
* layout drift first (every offence bundled into one envelope), then
|
|
126
|
+
* target mismatch, then disjointness, then a contract-validation
|
|
127
|
+
* failure, then any remaining structural integrity violation.
|
|
128
|
+
*/
|
|
129
|
+
function mapIntegrityViolations(violations) {
|
|
130
|
+
if (violations.length === 0) return null;
|
|
131
|
+
const layout = violations.filter((v) => v.kind === "orphanSpaceDir" || v.kind === "declaredButUnmigrated");
|
|
132
|
+
if (layout.length > 0) {
|
|
133
|
+
const lines = layout.map((v) => `- [${v.kind}] ${v.spaceId}`);
|
|
134
|
+
return new CliStructuredError$1("MIGRATION.CONTRACT_SPACE_LAYOUT_VIOLATION", layout.length === 1 ? "Contract-space layout violation detected" : `Contract-space layout violations detected (${layout.length})`, {
|
|
135
|
+
why: `The on-disk \`migrations/\` directory and your \`extensions\` declaration are not in agreement.\n${lines.join("\n")}`,
|
|
136
|
+
fix: "Declare the extension in `extensions` and re-emit its contract-space artefacts, or remove the orphan `migrations/<space>` directory.",
|
|
137
|
+
docsUrl: CONTRACT_SPACES_DOCS_URL,
|
|
138
|
+
meta: { violations: layout }
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const targetMismatch = violations.find((v) => v.kind === "targetMismatch");
|
|
142
|
+
if (targetMismatch && targetMismatch.kind === "targetMismatch") return targetMismatchError(targetMismatch.spaceId, targetMismatch.expected, targetMismatch.actual);
|
|
143
|
+
const disjointness = violations.find((v) => v.kind === "disjointness");
|
|
144
|
+
if (disjointness && disjointness.kind === "disjointness") return contractSpaceViolationError(`Contract-space disjointness violation: storage element "${disjointness.element}" claimed by multiple spaces`, {
|
|
145
|
+
why: `Spaces ${disjointness.claimedBy.map((s) => `"${s}"`).join(", ")} all claim the storage element "${disjointness.element}". Each storage element must be owned by exactly one contract space.`,
|
|
146
|
+
fix: "Update the conflicting contracts so each storage element is claimed by exactly one space.",
|
|
147
|
+
violations: [disjointness]
|
|
148
|
+
});
|
|
149
|
+
const contractUnreadable = violations.find((v) => v.kind === "contractUnreadable");
|
|
150
|
+
if (contractUnreadable && contractUnreadable.kind === "contractUnreadable") return contractSpaceViolationError(`Contract-space contract validation failed for "${contractUnreadable.spaceId}"`, {
|
|
151
|
+
why: contractUnreadable.detail,
|
|
152
|
+
fix: "Re-emit the extension contract with `prisma-next contract emit`, or fix the extension pack descriptor producing the invalid contract.",
|
|
153
|
+
violations: [contractUnreadable]
|
|
154
|
+
});
|
|
155
|
+
const structural = violations[0];
|
|
156
|
+
return contractSpaceViolationError(`Contract-space integrity failure for "${"spaceId" in structural ? structural.spaceId : "*"}"`, {
|
|
157
|
+
why: describeIntegrityViolation(structural),
|
|
158
|
+
fix: "Re-emit the affected migration package(s) or restore the on-disk `migrations/` directory from version control.",
|
|
159
|
+
violations: [structural]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function declaredExtensionsFromInputs(extensions) {
|
|
163
|
+
return toDeclaredExtensionsFromRaw(extensions);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Reject extension descriptors whose configured target disagrees with
|
|
167
|
+
* the project target before any on-disk read.
|
|
168
|
+
*/
|
|
169
|
+
function refuseDeclaredExtensionTargetMismatch(inputs) {
|
|
170
|
+
for (const declared of declaredExtensionsFromInputs(inputs.extensions)) if (declared.targetId !== inputs.targetId) return targetMismatchError(declared.id, inputs.targetId, declared.targetId);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Load the tolerant {@link ContractSpaceAggregate} once at the CLI
|
|
175
|
+
* surface. Construction never throws on disk content; callers query
|
|
176
|
+
* {@link ContractSpaceAggregate.app} / extension facets instead of
|
|
177
|
+
* re-reading `migrations/`.
|
|
178
|
+
*/
|
|
179
|
+
async function loadContractSpaceAggregateForCli(inputs) {
|
|
180
|
+
const targetFailure = refuseDeclaredExtensionTargetMismatch(inputs);
|
|
181
|
+
if (targetFailure) return notOk(targetFailure);
|
|
182
|
+
return ok(await loadContractSpaceAggregate({
|
|
183
|
+
migrationsDir: inputs.migrationsDir,
|
|
184
|
+
deserializeContract: inputs.deserializeContract,
|
|
185
|
+
appContract: inputs.appContract
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Run `checkIntegrity` on a loaded aggregate and map violations into
|
|
190
|
+
* the contract-space refusal envelope, or return `null` when the model
|
|
191
|
+
* is acceptable for the requested check scope.
|
|
192
|
+
*/
|
|
193
|
+
function refuseContractSpaceIntegrity(aggregate, options) {
|
|
194
|
+
return mapIntegrityViolations(aggregate.checkIntegrity(options));
|
|
195
|
+
}
|
|
196
|
+
const PACKAGE_CORRUPTION_KINDS = /* @__PURE__ */ new Set([
|
|
197
|
+
"hashMismatch",
|
|
198
|
+
"providedInvariantsMismatch",
|
|
199
|
+
"packageUnloadable"
|
|
200
|
+
]);
|
|
201
|
+
/**
|
|
202
|
+
* Reader-subset integrity refusal for `migration status`: package
|
|
203
|
+
* corruptions only (`hashMismatch`, `providedInvariantsMismatch`,
|
|
204
|
+
* `packageUnloadable`).
|
|
205
|
+
*/
|
|
206
|
+
function refusePackageCorruptionOnAggregate(aggregate) {
|
|
207
|
+
return mapIntegrityViolations(aggregate.checkIntegrity().filter((v) => PACKAGE_CORRUPTION_KINDS.has(v.kind)));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Construct the tolerant {@link ContractSpaceAggregate} at the CLI
|
|
211
|
+
* surface and apply the explicit integrity refusal.
|
|
212
|
+
*
|
|
213
|
+
* App-space migration packages are read from `migrations/<app>/` by the
|
|
214
|
+
* loader itself; callers no longer thread them through.
|
|
215
|
+
*/
|
|
216
|
+
async function buildContractSpaceAggregate(inputs) {
|
|
217
|
+
const declaredExtensions = declaredExtensionsFromInputs(inputs.extensions);
|
|
218
|
+
const loaded = await loadContractSpaceAggregateForCli(inputs);
|
|
219
|
+
if (!loaded.ok) return loaded;
|
|
220
|
+
const failure = refuseContractSpaceIntegrity(loaded.value, {
|
|
221
|
+
declaredExtensions,
|
|
222
|
+
checkContracts: true
|
|
223
|
+
});
|
|
224
|
+
if (failure) return notOk(failure);
|
|
225
|
+
return ok(loaded.value);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Build a minimal app {@link Contract} carrying only the project's
|
|
229
|
+
* contract-identity (`storage.storageHash` + `target` / `targetFamily`)
|
|
230
|
+
* when the real `contract.json` is absent or undeserializable.
|
|
231
|
+
*
|
|
232
|
+
* `loadContractSpaceAggregate` requires an `appContract` to synthesise the
|
|
233
|
+
* app space's head ref from its storage hash. Read commands query only that
|
|
234
|
+
* hash and the target — never `models` — so an empty-`models` stand-in is
|
|
235
|
+
* sufficient for them. It is *not* a valid contract for any consumer that
|
|
236
|
+
* reads schema, which is why this is confined to the read-aggregate path.
|
|
237
|
+
*/
|
|
238
|
+
function appContractStandInFromIdentity(args) {
|
|
239
|
+
return blindCast({
|
|
240
|
+
storage: { storageHash: args.contractHash },
|
|
241
|
+
schemaVersion: "0.0.0",
|
|
242
|
+
target: args.targetId,
|
|
243
|
+
targetFamily: args.targetFamily,
|
|
244
|
+
models: {},
|
|
245
|
+
profileHash: EMPTY_CONTRACT_HASH
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
async function loadContractRawSafely(config) {
|
|
249
|
+
try {
|
|
250
|
+
const raw = await readFile(resolveContractPath(config), "utf-8");
|
|
251
|
+
return JSON.parse(raw);
|
|
252
|
+
} catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Tolerant {@link ContractSpaceAggregate} assembly for read-only CLI
|
|
258
|
+
* commands. No integrity gate — callers query `aggregate.app` (or other
|
|
259
|
+
* facets) without re-reading `migrations/`. When `contract.json` is absent
|
|
260
|
+
* or undeserializable, the app contract falls back to an identity-only
|
|
261
|
+
* stand-in ({@link appContractStandInFromIdentity}), so these commands
|
|
262
|
+
* load without requiring a readable contract.
|
|
263
|
+
*/
|
|
264
|
+
async function buildReadAggregate(config, options) {
|
|
265
|
+
let contractHash = EMPTY_CONTRACT_HASH;
|
|
266
|
+
try {
|
|
267
|
+
contractHash = (await readContractEnvelope(config)).storageHash;
|
|
268
|
+
} catch {}
|
|
269
|
+
try {
|
|
270
|
+
const contractRawForAggregate = await loadContractRawSafely(config);
|
|
271
|
+
const stack = createControlStack(config);
|
|
272
|
+
const familyInstance = config.family.create(stack);
|
|
273
|
+
const deserializeContract = (json) => familyInstance.deserializeContract(json);
|
|
274
|
+
let appContractForLoad = appContractStandInFromIdentity({
|
|
275
|
+
contractHash,
|
|
276
|
+
targetId: config.target.id,
|
|
277
|
+
targetFamily: config.target.familyId
|
|
278
|
+
});
|
|
279
|
+
if (contractRawForAggregate !== null) try {
|
|
280
|
+
appContractForLoad = deserializeContract(contractRawForAggregate);
|
|
281
|
+
} catch {}
|
|
282
|
+
const loaded = await loadContractSpaceAggregateForCli({
|
|
283
|
+
targetId: config.target.id,
|
|
284
|
+
migrationsDir: options.migrationsDir,
|
|
285
|
+
appContract: appContractForLoad,
|
|
286
|
+
extensions: config.extensions ?? [],
|
|
287
|
+
deserializeContract
|
|
288
|
+
});
|
|
289
|
+
if (!loaded.ok) return loaded;
|
|
290
|
+
return ok({
|
|
291
|
+
aggregate: loaded.value,
|
|
292
|
+
contractHash
|
|
293
|
+
});
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
296
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read migrations directory: ${error instanceof Error ? error.message : String(error)}` }));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
export { refuseContractSpaceIntegrity as a, toExtensionInputs as c, loadContractSpaceAggregateForCli as i, buildReadAggregate as n, refusePackageCorruptionOnAggregate as o, loadContractRawSafely as r, toDeclaredExtensionsFromRaw as s, buildContractSpaceAggregate as t };
|
|
301
|
+
|
|
302
|
+
//# sourceMappingURL=contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs","names":["CliStructuredError"],"sources":["../../../../1-framework/3-tooling/cli/dist/contract-space-aggregate-loader-CFH-336b.mjs"],"sourcesContent":["import { F as CliStructuredError, a as readContractEnvelope, ct as errorUnexpected, lt as mapMigrationToolsError, o as resolveContractPath } from \"./command-helpers-CAoXqAY9.mjs\";\nimport { notOk, ok } from \"@internal/utils/result\";\nimport { readFile } from \"node:fs/promises\";\nimport { createControlStack } from \"@internal/framework-components/control\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { loadContractSpaceAggregate } from \"@internal/migration-tools/aggregate\";\nimport { EMPTY_CONTRACT_HASH } from \"@internal/migration-tools/constants\";\nimport { MigrationToolsError } from \"@internal/migration-tools/errors\";\n//#region src/utils/extension-pack-inputs.ts\n/**\n* Project the CLI's `Config.extensions` array into the canonical\n* {@link ExtensionPackInput} shape. The single `as ExtensionPackLike`\n* structural cast in the CLI lives inside this function.\n*/\nfunction toExtensionInputs(extensions) {\n\treturn extensions.map((raw) => {\n\t\tconst pack = raw;\n\t\tif (pack.contractSpace === void 0) return {\n\t\t\tid: pack.id,\n\t\t\ttargetId: pack.targetId\n\t\t};\n\t\treturn {\n\t\t\tid: pack.id,\n\t\t\ttargetId: pack.targetId,\n\t\t\tcontractSpace: {\n\t\t\t\tcontractJson: pack.contractSpace.contractJson,\n\t\t\t\theadRef: pack.contractSpace.headRef,\n\t\t\t\tmigrations: pack.contractSpace.migrations ?? []\n\t\t\t}\n\t\t};\n\t});\n}\n/**\n* Minimal aggregate-loader projection that extracts `id` + `targetId`\n* from raw extension pack descriptors **without invoking any\n* `contractSpace` accessor**. Inspects the own-property descriptor so\n* that getter-backed `contractSpace` declarations are detected but\n* never called.\n*\n* Inclusion semantics match {@link toDeclaredExtensions}: a data\n* property whose value is explicitly `undefined` is treated as \"no\n* contract-space declaration\" and skipped, mirroring the\n* `pack.contractSpace === undefined` check used on canonicalised\n* inputs. Prototype-chain `contractSpace` properties (no own\n* descriptor) are also skipped.\n*\n* This variant must be used by `buildContractSpaceAggregate` so that\n* the aggregate path (including `db verify`) never reads\n* `contractSpace.contractJson` from extension descriptors — the loader\n* always reads the contract from on-disk artefacts instead.\n*/\nfunction toDeclaredExtensionsFromRaw(extensions) {\n\tconst entries = [];\n\tfor (const raw of extensions) {\n\t\tif (typeof raw !== \"object\" || raw === null) continue;\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(raw, \"contractSpace\");\n\t\tif (descriptor === void 0) continue;\n\t\tif (\"value\" in descriptor && descriptor.value === void 0) continue;\n\t\tconst pack = raw;\n\t\tentries.push({\n\t\t\tid: pack.id,\n\t\t\ttargetId: pack.targetId\n\t\t});\n\t}\n\treturn entries;\n}\n//#endregion\n//#region src/utils/contract-space-aggregate-loader.ts\nconst CONTRACT_SPACES_DOCS_URL = \"https://pris.ly/contract-spaces\";\nfunction contractSpaceViolationError(summary, options) {\n\treturn new CliStructuredError(\"MIGRATION.CONTRACT_SPACE_VIOLATION\", summary, {\n\t\twhy: options.why,\n\t\tfix: options.fix,\n\t\tdocsUrl: CONTRACT_SPACES_DOCS_URL,\n\t\tmeta: { violations: options.violations }\n\t});\n}\n/**\n* Build the `MIGRATION.CONTRACT_SPACE_VIOLATION` structured-error envelope for a contract-space\n* target mismatch. Shared between the declared-extension precheck (the\n* descriptor's configured target disagrees with the project target) and\n* the on-disk-contract check surfaced by `checkIntegrity`.\n*/\nfunction targetMismatchError(spaceId, expected, actual) {\n\treturn contractSpaceViolationError(`Contract-space target mismatch for \"${spaceId}\"`, {\n\t\twhy: `Space \"${spaceId}\" targets \"${actual}\" but the project's adapter targets \"${expected}\".`,\n\t\tfix: \"Update the extension descriptor to target the configured database, or change the project adapter.\",\n\t\tviolations: [{\n\t\t\tkind: \"targetMismatch\",\n\t\t\tspaceId,\n\t\t\texpected,\n\t\t\tactual\n\t\t}]\n\t});\n}\n/**\n* Human-readable detail for an integrity violation, used as the `why`\n* of the `integrityFailure` envelope. Mirrors the messages the prior\n* throw-on-load loader produced so downstream consumers see the same\n* text for the same on-disk state.\n*/\nfunction describeIntegrityViolation(violation) {\n\tswitch (violation.kind) {\n\t\tcase \"hashMismatch\": return `Migration \"${violation.dirName}\" stored hash \"${violation.stored}\" does not match computed hash \"${violation.computed}\".`;\n\t\tcase \"providedInvariantsMismatch\": return `Migration \"${violation.dirName}\" providedInvariants in migration.json disagrees with ops.json.`;\n\t\tcase \"packageUnloadable\": return `Migration \"${violation.dirName}\" could not be loaded: ${violation.detail}`;\n\t\tcase \"sameSourceAndTarget\": return `Migration \"${violation.dirName}\" has source equal to target (${violation.hash}) with no data invariant — a true no-op self-edge.`;\n\t\tcase \"headRefMissing\": return `Head ref \\`refs/head.json\\` is missing for contract space \"${violation.spaceId}\".`;\n\t\tcase \"headRefNotInGraph\": return `Head ref ${violation.hash} for contract space \"${violation.spaceId}\" is not present in the migration graph.`;\n\t\tcase \"refUnreadable\": return `Ref \"${violation.refName}\" for contract space \"${violation.spaceId}\" is unreadable: ${violation.detail}`;\n\t\tcase \"duplicateMigrationHash\": return `Multiple migrations in space \"${violation.spaceId}\" share migrationHash \"${violation.migrationHash}\" (${violation.dirNames.join(\", \")}).`;\n\t\tdefault: {\n\t\t\tconst spaceId = \"spaceId\" in violation ? violation.spaceId : \"*\";\n\t\t\treturn `Integrity violation \"${violation.kind}\" for contract space \"${spaceId}\".`;\n\t\t}\n\t}\n}\n/**\n* Map the integrity violations `checkIntegrity` reports into a single\n* CLI structured-error envelope, preserving the error codes the prior\n* throw-on-load loader emitted: `MIGRATION.CONTRACT_SPACE_LAYOUT_VIOLATION`\n* (layout drift, bundled) and `MIGRATION.CONTRACT_SPACE_VIOLATION` (target /\n* disjointness / contract-validation / structural integrity). Returns\n* `null` when there is nothing to refuse on.\n*\n* Precedence reproduces the prior loader's first-failure ordering:\n* layout drift first (every offence bundled into one envelope), then\n* target mismatch, then disjointness, then a contract-validation\n* failure, then any remaining structural integrity violation.\n*/\nfunction mapIntegrityViolations(violations) {\n\tif (violations.length === 0) return null;\n\tconst layout = violations.filter((v) => v.kind === \"orphanSpaceDir\" || v.kind === \"declaredButUnmigrated\");\n\tif (layout.length > 0) {\n\t\tconst lines = layout.map((v) => `- [${v.kind}] ${v.spaceId}`);\n\t\treturn new CliStructuredError(\"MIGRATION.CONTRACT_SPACE_LAYOUT_VIOLATION\", layout.length === 1 ? \"Contract-space layout violation detected\" : `Contract-space layout violations detected (${layout.length})`, {\n\t\t\twhy: `The on-disk \\`migrations/\\` directory and your \\`extensions\\` declaration are not in agreement.\\n${lines.join(\"\\n\")}`,\n\t\t\tfix: \"Declare the extension in `extensions` and re-emit its contract-space artefacts, or remove the orphan `migrations/<space>` directory.\",\n\t\t\tdocsUrl: CONTRACT_SPACES_DOCS_URL,\n\t\t\tmeta: { violations: layout }\n\t\t});\n\t}\n\tconst targetMismatch = violations.find((v) => v.kind === \"targetMismatch\");\n\tif (targetMismatch && targetMismatch.kind === \"targetMismatch\") return targetMismatchError(targetMismatch.spaceId, targetMismatch.expected, targetMismatch.actual);\n\tconst disjointness = violations.find((v) => v.kind === \"disjointness\");\n\tif (disjointness && disjointness.kind === \"disjointness\") return contractSpaceViolationError(`Contract-space disjointness violation: storage element \"${disjointness.element}\" claimed by multiple spaces`, {\n\t\twhy: `Spaces ${disjointness.claimedBy.map((s) => `\"${s}\"`).join(\", \")} all claim the storage element \"${disjointness.element}\". Each storage element must be owned by exactly one contract space.`,\n\t\tfix: \"Update the conflicting contracts so each storage element is claimed by exactly one space.\",\n\t\tviolations: [disjointness]\n\t});\n\tconst contractUnreadable = violations.find((v) => v.kind === \"contractUnreadable\");\n\tif (contractUnreadable && contractUnreadable.kind === \"contractUnreadable\") return contractSpaceViolationError(`Contract-space contract validation failed for \"${contractUnreadable.spaceId}\"`, {\n\t\twhy: contractUnreadable.detail,\n\t\tfix: \"Re-emit the extension contract with `prisma-next contract emit`, or fix the extension pack descriptor producing the invalid contract.\",\n\t\tviolations: [contractUnreadable]\n\t});\n\tconst structural = violations[0];\n\treturn contractSpaceViolationError(`Contract-space integrity failure for \"${\"spaceId\" in structural ? structural.spaceId : \"*\"}\"`, {\n\t\twhy: describeIntegrityViolation(structural),\n\t\tfix: \"Re-emit the affected migration package(s) or restore the on-disk `migrations/` directory from version control.\",\n\t\tviolations: [structural]\n\t});\n}\nfunction declaredExtensionsFromInputs(extensions) {\n\treturn toDeclaredExtensionsFromRaw(extensions);\n}\n/**\n* Reject extension descriptors whose configured target disagrees with\n* the project target before any on-disk read.\n*/\nfunction refuseDeclaredExtensionTargetMismatch(inputs) {\n\tfor (const declared of declaredExtensionsFromInputs(inputs.extensions)) if (declared.targetId !== inputs.targetId) return targetMismatchError(declared.id, inputs.targetId, declared.targetId);\n\treturn null;\n}\n/**\n* Load the tolerant {@link ContractSpaceAggregate} once at the CLI\n* surface. Construction never throws on disk content; callers query\n* {@link ContractSpaceAggregate.app} / extension facets instead of\n* re-reading `migrations/`.\n*/\nasync function loadContractSpaceAggregateForCli(inputs) {\n\tconst targetFailure = refuseDeclaredExtensionTargetMismatch(inputs);\n\tif (targetFailure) return notOk(targetFailure);\n\treturn ok(await loadContractSpaceAggregate({\n\t\tmigrationsDir: inputs.migrationsDir,\n\t\tdeserializeContract: inputs.deserializeContract,\n\t\tappContract: inputs.appContract\n\t}));\n}\n/**\n* Run `checkIntegrity` on a loaded aggregate and map violations into\n* the contract-space refusal envelope, or return `null` when the model\n* is acceptable for the requested check scope.\n*/\nfunction refuseContractSpaceIntegrity(aggregate, options) {\n\treturn mapIntegrityViolations(aggregate.checkIntegrity(options));\n}\nconst PACKAGE_CORRUPTION_KINDS = /* @__PURE__ */ new Set([\n\t\"hashMismatch\",\n\t\"providedInvariantsMismatch\",\n\t\"packageUnloadable\"\n]);\n/**\n* Reader-subset integrity refusal for `migration status`: package\n* corruptions only (`hashMismatch`, `providedInvariantsMismatch`,\n* `packageUnloadable`).\n*/\nfunction refusePackageCorruptionOnAggregate(aggregate) {\n\treturn mapIntegrityViolations(aggregate.checkIntegrity().filter((v) => PACKAGE_CORRUPTION_KINDS.has(v.kind)));\n}\n/**\n* Construct the tolerant {@link ContractSpaceAggregate} at the CLI\n* surface and apply the explicit integrity refusal.\n*\n* App-space migration packages are read from `migrations/<app>/` by the\n* loader itself; callers no longer thread them through.\n*/\nasync function buildContractSpaceAggregate(inputs) {\n\tconst declaredExtensions = declaredExtensionsFromInputs(inputs.extensions);\n\tconst loaded = await loadContractSpaceAggregateForCli(inputs);\n\tif (!loaded.ok) return loaded;\n\tconst failure = refuseContractSpaceIntegrity(loaded.value, {\n\t\tdeclaredExtensions,\n\t\tcheckContracts: true\n\t});\n\tif (failure) return notOk(failure);\n\treturn ok(loaded.value);\n}\n/**\n* Build a minimal app {@link Contract} carrying only the project's\n* contract-identity (`storage.storageHash` + `target` / `targetFamily`)\n* when the real `contract.json` is absent or undeserializable.\n*\n* `loadContractSpaceAggregate` requires an `appContract` to synthesise the\n* app space's head ref from its storage hash. Read commands query only that\n* hash and the target — never `models` — so an empty-`models` stand-in is\n* sufficient for them. It is *not* a valid contract for any consumer that\n* reads schema, which is why this is confined to the read-aggregate path.\n*/\nfunction appContractStandInFromIdentity(args) {\n\treturn blindCast({\n\t\tstorage: { storageHash: args.contractHash },\n\t\tschemaVersion: \"0.0.0\",\n\t\ttarget: args.targetId,\n\t\ttargetFamily: args.targetFamily,\n\t\tmodels: {},\n\t\tprofileHash: EMPTY_CONTRACT_HASH\n\t});\n}\nasync function loadContractRawSafely(config) {\n\ttry {\n\t\tconst raw = await readFile(resolveContractPath(config), \"utf-8\");\n\t\treturn JSON.parse(raw);\n\t} catch {\n\t\treturn null;\n\t}\n}\n/**\n* Tolerant {@link ContractSpaceAggregate} assembly for read-only CLI\n* commands. No integrity gate — callers query `aggregate.app` (or other\n* facets) without re-reading `migrations/`. When `contract.json` is absent\n* or undeserializable, the app contract falls back to an identity-only\n* stand-in ({@link appContractStandInFromIdentity}), so these commands\n* load without requiring a readable contract.\n*/\nasync function buildReadAggregate(config, options) {\n\tlet contractHash = EMPTY_CONTRACT_HASH;\n\ttry {\n\t\tcontractHash = (await readContractEnvelope(config)).storageHash;\n\t} catch {}\n\ttry {\n\t\tconst contractRawForAggregate = await loadContractRawSafely(config);\n\t\tconst stack = createControlStack(config);\n\t\tconst familyInstance = config.family.create(stack);\n\t\tconst deserializeContract = (json) => familyInstance.deserializeContract(json);\n\t\tlet appContractForLoad = appContractStandInFromIdentity({\n\t\t\tcontractHash,\n\t\t\ttargetId: config.target.id,\n\t\t\ttargetFamily: config.target.familyId\n\t\t});\n\t\tif (contractRawForAggregate !== null) try {\n\t\t\tappContractForLoad = deserializeContract(contractRawForAggregate);\n\t\t} catch {}\n\t\tconst loaded = await loadContractSpaceAggregateForCli({\n\t\t\ttargetId: config.target.id,\n\t\t\tmigrationsDir: options.migrationsDir,\n\t\t\tappContract: appContractForLoad,\n\t\t\textensions: config.extensions ?? [],\n\t\t\tdeserializeContract\n\t\t});\n\t\tif (!loaded.ok) return loaded;\n\t\treturn ok({\n\t\t\taggregate: loaded.value,\n\t\t\tcontractHash\n\t\t});\n\t} catch (error) {\n\t\tif (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n\t\treturn notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read migrations directory: ${error instanceof Error ? error.message : String(error)}` }));\n\t}\n}\n//#endregion\nexport { refuseContractSpaceIntegrity as a, toExtensionInputs as c, loadContractSpaceAggregateForCli as i, buildReadAggregate as n, refusePackageCorruptionOnAggregate as o, loadContractRawSafely as r, toDeclaredExtensionsFromRaw as s, buildContractSpaceAggregate as t };\n\n//# sourceMappingURL=contract-space-aggregate-loader-CFH-336b.mjs.map"],"mappings":"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"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { t as MigrationToolsError } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import { B as formatMigrationJson, D as errorRunnerFailed, N as errorUnexpected, O as errorRuntime$1, V as formatMigrationPlanOutput, Z as mapMigrationToolsError, at as resolveMigrationPaths, ct as setCommandExamples, d as errorContractValidationFailed, o as createTerminalUI, ot as sanitizeErrorMessage, q as handleResult, st as setCommandDescriptions, t as CliStructuredError$1, tt as parseGlobalFlagsOrExit, x as errorMigrationPlanningFailed, z as formatMigrationApplyOutput } from "./command-helpers-CAoXqAY9-DWUBcTXM.mjs";
|
|
3
|
+
import { n as prepareMigrationContext, t as addMigrationCommandOptions } from "./migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs";
|
|
4
|
+
import { i as readContractIR, n as computeRefAdvancementName, t as buildRefAdvancementFields } from "./ref-advancement-CSPMoQs3-fEipZrdu.mjs";
|
|
5
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
6
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
7
|
+
import { assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
8
|
+
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
9
|
+
import { Command } from "commander";
|
|
10
|
+
//#region ../../../1-framework/3-tooling/cli/dist/commands/db-init.mjs
|
|
11
|
+
/**
|
|
12
|
+
* Maps a DbInitFailure to a CliStructuredError for consistent error handling.
|
|
13
|
+
*/
|
|
14
|
+
function mapDbInitFailure(failure) {
|
|
15
|
+
if (failure.code === "PLANNING_FAILED") return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });
|
|
16
|
+
if (failure.code === "MIGRATION.MARKER_ORIGIN_MISMATCH") {
|
|
17
|
+
const mismatchParts = [];
|
|
18
|
+
if (failure.marker?.storageHash !== failure.destination?.storageHash && failure.marker?.storageHash && failure.destination?.storageHash) mismatchParts.push(`storageHash (marker: ${failure.marker.storageHash}, destination: ${failure.destination.storageHash})`);
|
|
19
|
+
if (failure.marker?.profileHash !== failure.destination?.profileHash && failure.marker?.profileHash && failure.destination?.profileHash) mismatchParts.push(`profileHash (marker: ${failure.marker.profileHash}, destination: ${failure.destination.profileHash})`);
|
|
20
|
+
return errorRuntime$1(`Existing database signature does not match plan destination.${mismatchParts.length > 0 ? ` Mismatch in ${mismatchParts.join(" and ")}.` : ""}`, {
|
|
21
|
+
why: "Database has an existing signature (marker) that does not match the target contract",
|
|
22
|
+
fix: "If bootstrapping, drop/reset the database then re-run `prisma-next db init`; otherwise reconcile schema/marker using your migration workflow",
|
|
23
|
+
meta: {
|
|
24
|
+
code: "MIGRATION.MARKER_ORIGIN_MISMATCH",
|
|
25
|
+
...ifDefined("markerStorageHash", failure.marker?.storageHash),
|
|
26
|
+
...ifDefined("destinationStorageHash", failure.destination?.storageHash),
|
|
27
|
+
...ifDefined("markerProfileHash", failure.marker?.profileHash),
|
|
28
|
+
...ifDefined("destinationProfileHash", failure.destination?.profileHash)
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (failure.code === "RUNNER_FAILED") {
|
|
33
|
+
const fix = (typeof failure.meta?.["runnerErrorCode"] === "string" ? failure.meta["runnerErrorCode"] : void 0) === "MIGRATION.LEGACY_MARKER_SHAPE" ? "Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `prisma-next db init` to recreate it with the current per-space schema." : "Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run `prisma-next db init`";
|
|
34
|
+
return errorRunnerFailed(failure.summary, {
|
|
35
|
+
why: failure.why ?? "Migration runner failed",
|
|
36
|
+
fix,
|
|
37
|
+
...failure.meta ? { meta: {
|
|
38
|
+
code: "RUNNER_FAILED",
|
|
39
|
+
...failure.meta
|
|
40
|
+
} } : { meta: { code: "RUNNER_FAILED" } }
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const exhaustive = failure.code;
|
|
44
|
+
return assertNever(exhaustive, `Unhandled DbInitFailure code: ${String(exhaustive)}`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Executes the db init command and returns a structured Result.
|
|
48
|
+
*/
|
|
49
|
+
async function executeDbInitCommand(options, flags, ui, startTime) {
|
|
50
|
+
const ctxResult = await prepareMigrationContext(options, flags, ui, {
|
|
51
|
+
commandName: "db init",
|
|
52
|
+
description: "Bootstrap a database to match the current contract",
|
|
53
|
+
url: "https://pris.ly/db-init"
|
|
54
|
+
});
|
|
55
|
+
if (!ctxResult.ok) return ctxResult;
|
|
56
|
+
const { client, config, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;
|
|
57
|
+
const { migrationsDir, refsDir } = resolveMigrationPaths(options.config, config);
|
|
58
|
+
try {
|
|
59
|
+
await client.connect(dbConnection);
|
|
60
|
+
const result = await client.dbInit({
|
|
61
|
+
contract: contractJson,
|
|
62
|
+
mode: options.dryRun ? "plan" : "apply",
|
|
63
|
+
migrationsDir,
|
|
64
|
+
onProgress
|
|
65
|
+
});
|
|
66
|
+
if (!result.ok) return notOk(mapDbInitFailure(result.failure));
|
|
67
|
+
const advancementHash = result.value.mode === "apply" ? result.value.marker?.storageHash ?? result.value.destination.storageHash : result.value.destination.storageHash;
|
|
68
|
+
let refAdvancementFields = {
|
|
69
|
+
advancedRef: null,
|
|
70
|
+
plannedAdvanceRef: null
|
|
71
|
+
};
|
|
72
|
+
if (computeRefAdvancementName({
|
|
73
|
+
...ifDefined("advanceRef", options.advanceRef),
|
|
74
|
+
...ifDefined("db", options.db)
|
|
75
|
+
}) !== null) try {
|
|
76
|
+
const contractIR = await readContractIR(contractJson, contractPathAbsolute);
|
|
77
|
+
refAdvancementFields = await buildRefAdvancementFields({
|
|
78
|
+
...ifDefined("advanceRef", options.advanceRef),
|
|
79
|
+
...ifDefined("db", options.db),
|
|
80
|
+
refsDir,
|
|
81
|
+
migrationsDir,
|
|
82
|
+
contractIR,
|
|
83
|
+
mode: result.value.mode,
|
|
84
|
+
hash: advancementHash
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
return ok({
|
|
91
|
+
ok: true,
|
|
92
|
+
mode: result.value.mode,
|
|
93
|
+
plan: {
|
|
94
|
+
targetId: ctxResult.value.config.target.targetId,
|
|
95
|
+
destination: {
|
|
96
|
+
storageHash: result.value.destination.storageHash,
|
|
97
|
+
...ifDefined("profileHash", result.value.destination.profileHash)
|
|
98
|
+
},
|
|
99
|
+
operations: result.value.plan.operations.map((op) => ({
|
|
100
|
+
id: op.id,
|
|
101
|
+
label: op.label,
|
|
102
|
+
operationClass: op.operationClass
|
|
103
|
+
})),
|
|
104
|
+
...ifDefined("preview", result.value.plan.preview)
|
|
105
|
+
},
|
|
106
|
+
...result.value.execution ? { execution: {
|
|
107
|
+
operationsPlanned: result.value.execution.operationsPlanned,
|
|
108
|
+
operationsExecuted: result.value.execution.operationsExecuted
|
|
109
|
+
} } : {},
|
|
110
|
+
...result.value.marker ? { marker: {
|
|
111
|
+
storageHash: result.value.marker.storageHash,
|
|
112
|
+
...ifDefined("profileHash", result.value.marker.profileHash)
|
|
113
|
+
} } : {},
|
|
114
|
+
...ifDefined("perSpace", result.value.perSpace),
|
|
115
|
+
advancedRef: refAdvancementFields.advancedRef,
|
|
116
|
+
plannedAdvanceRef: refAdvancementFields.plannedAdvanceRef,
|
|
117
|
+
summary: result.value.summary,
|
|
118
|
+
timings: { total: Date.now() - startTime }
|
|
119
|
+
});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (CliStructuredError$1.is(error)) return notOk(error);
|
|
122
|
+
if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));
|
|
123
|
+
const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
|
|
124
|
+
return notOk(errorUnexpected(safeMessage, { why: `Unexpected error during db init: ${safeMessage}` }));
|
|
125
|
+
} finally {
|
|
126
|
+
await client.close();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function createDbInitCommand() {
|
|
130
|
+
const command = new Command("init");
|
|
131
|
+
setCommandDescriptions(command, "Bootstrap a database to match the current contract and sign it", "Initializes a database to match your emitted contract using additive-only operations.\nCreates any missing tables, columns, indexes, and constraints defined in your contract.\nLeaves existing compatible structures in place, surfaces conflicts when destructive changes\nwould be required, and signs the database to track contract state. Use --dry-run to\npreview changes without applying.");
|
|
132
|
+
setCommandExamples(command, ["prisma-next db init --db $DATABASE_URL", "prisma-next db init --db $DATABASE_URL --dry-run"]);
|
|
133
|
+
addMigrationCommandOptions(command);
|
|
134
|
+
command.option("--advance-ref <name>", "Ref to advance to the post-command contract hash");
|
|
135
|
+
command.action(async (options) => {
|
|
136
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
137
|
+
const startTime = Date.now();
|
|
138
|
+
const ui = createTerminalUI(flags);
|
|
139
|
+
const exitCode = handleResult(await executeDbInitCommand(options, flags, ui, startTime), flags, ui, (dbInitResult) => {
|
|
140
|
+
if (flags.json) ui.output(formatMigrationJson(dbInitResult));
|
|
141
|
+
else {
|
|
142
|
+
const output = dbInitResult.mode === "plan" ? formatMigrationPlanOutput(dbInitResult, flags) : formatMigrationApplyOutput(dbInitResult, flags);
|
|
143
|
+
if (output) ui.log(output);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
process.exit(exitCode);
|
|
147
|
+
});
|
|
148
|
+
return command;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { createDbInitCommand as t };
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=db-init-Vbkb_TKZ.mjs.map
|