@prisma/orm-family-sql 0.16.0-dev.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +28 -0
- package/dist/ast-BstHjAoG.mjs +325 -0
- package/dist/ast-BstHjAoG.mjs.map +1 -0
- package/dist/ast-DSuzmsWn.d.mts +287 -0
- package/dist/ast-DSuzmsWn.d.mts.map +1 -0
- package/dist/authoring-type-constructors-Blqoa2Ua-DyCmD6mp.mjs +316 -0
- package/dist/authoring-type-constructors-Blqoa2Ua-DyCmD6mp.mjs.map +1 -0
- package/dist/build-contract-DBCz_YSs-DO0wMHai.mjs +778 -0
- package/dist/build-contract-DBCz_YSs-DO0wMHai.mjs.map +1 -0
- package/dist/builder.d.mts +3 -0
- package/dist/builder.mjs +1 -0
- package/dist/builder__runtime.d.mts +42 -0
- package/dist/builder__runtime.d.mts.map +1 -0
- package/dist/builder__runtime.mjs +955 -0
- package/dist/builder__runtime.mjs.map +1 -0
- package/dist/builder__types.d.mts +3 -0
- package/dist/builder__types.mjs +1 -0
- package/dist/canonicalization-hooks-CYnW_sGn.d.mts +10 -0
- package/dist/canonicalization-hooks-CYnW_sGn.d.mts.map +1 -0
- package/dist/canonicalization-hooks-DfIc_lOO.mjs +87 -0
- package/dist/canonicalization-hooks-DfIc_lOO.mjs.map +1 -0
- package/dist/codec-descriptor-registry-BJVJRftS.mjs +96 -0
- package/dist/codec-descriptor-registry-BJVJRftS.mjs.map +1 -0
- package/dist/codec-types-MOaceoPi-C5eL2sao.d.mts +116 -0
- package/dist/codec-types-MOaceoPi-C5eL2sao.d.mts.map +1 -0
- package/dist/config-types-47qB33rW.d.mts +21 -0
- package/dist/config-types-47qB33rW.d.mts.map +1 -0
- package/dist/config-types-N7PJc6VN.mjs +65 -0
- package/dist/config-types-N7PJc6VN.mjs.map +1 -0
- package/dist/contract-builder-MvJJrQ-5.d.mts +1306 -0
- package/dist/contract-builder-MvJJrQ-5.d.mts.map +1 -0
- package/dist/contract-builder-YjMQcvZ1.mjs +1615 -0
- package/dist/contract-builder-YjMQcvZ1.mjs.map +1 -0
- package/dist/contract-emitter.d.mts +25 -0
- package/dist/contract-emitter.d.mts.map +1 -0
- package/dist/contract-emitter.mjs +2 -0
- package/dist/contract-errors-BCN6RVI5-5IHBF_lg.mjs +9 -0
- package/dist/contract-errors-BCN6RVI5-5IHBF_lg.mjs.map +1 -0
- package/dist/contract-psl.d.mts +65 -0
- package/dist/contract-psl.d.mts.map +1 -0
- package/dist/contract-psl.mjs +2 -0
- package/dist/contract-psl__provider.d.mts +23 -0
- package/dist/contract-psl__provider.d.mts.map +1 -0
- package/dist/contract-psl__provider.mjs +105 -0
- package/dist/contract-psl__provider.mjs.map +1 -0
- package/dist/contract-ts.d.mts +3 -0
- package/dist/contract-ts.mjs +4 -0
- package/dist/contract-ts__config-types.d.mts +2 -0
- package/dist/contract-ts__config-types.mjs +2 -0
- package/dist/contract-ts__contract-builder.d.mts +2 -0
- package/dist/contract-ts__contract-builder.mjs +3 -0
- package/dist/contract-view-BMR5IWk4.mjs +39 -0
- package/dist/contract-view-BMR5IWk4.mjs.map +1 -0
- package/dist/contract-view-BbWQp6r4.d.mts +61 -0
- package/dist/contract-view-BbWQp6r4.d.mts.map +1 -0
- package/dist/contract.d.mts +26 -0
- package/dist/contract.mjs +17 -0
- package/dist/contract__canonicalization-hooks.d.mts +2 -0
- package/dist/contract__canonicalization-hooks.mjs +2 -0
- package/dist/contract__contract-view.d.mts +2 -0
- package/dist/contract__contract-view.mjs +2 -0
- package/dist/contract__entity-handle-lowering-hook.d.mts +2 -0
- package/dist/contract__entity-handle-lowering-hook.mjs +2 -0
- package/dist/contract__entity-kinds.d.mts +2 -0
- package/dist/contract__entity-kinds.mjs +2 -0
- package/dist/contract__factories.d.mts +2 -0
- package/dist/contract__factories.mjs +2 -0
- package/dist/contract__foreign-key-materialization.d.mts +2 -0
- package/dist/contract__foreign-key-materialization.mjs +2 -0
- package/dist/contract__index-naming.d.mts +2 -0
- package/dist/contract__index-naming.mjs +2 -0
- package/dist/contract__index-type-validation.d.mts +2 -0
- package/dist/contract__index-type-validation.mjs +2 -0
- package/dist/contract__index-types.d.mts +3 -0
- package/dist/contract__index-types.mjs +2 -0
- package/dist/contract__pack-types.d.mts +2 -0
- package/dist/contract__pack-types.mjs +1 -0
- package/dist/contract__referential-action-sql.d.mts +2 -0
- package/dist/contract__referential-action-sql.mjs +2 -0
- package/dist/contract__resolve-storage-table.d.mts +2 -0
- package/dist/contract__resolve-storage-table.mjs +2 -0
- package/dist/contract__types.d.mts +11 -0
- package/dist/contract__types.mjs +4 -0
- package/dist/contract__validators.d.mts +2 -0
- package/dist/contract__validators.mjs +3 -0
- package/dist/contract__value-set-derivation-hook.d.mts +2 -0
- package/dist/contract__value-set-derivation-hook.mjs +2 -0
- package/dist/control-B7iS4jv4.mjs +1326 -0
- package/dist/control-B7iS4jv4.mjs.map +1 -0
- package/dist/control-BHmsZudH.d.mts +948 -0
- package/dist/control-BHmsZudH.d.mts.map +1 -0
- package/dist/control-adapter-4y1O8Ps3.d.mts +1 -0
- package/dist/control-adapter-C99J7aEF-C-17lFY8.d.mts +191 -0
- package/dist/control-adapter-C99J7aEF-C-17lFY8.d.mts.map +1 -0
- package/dist/db-DhMsmBS--DKENDi3l.d.mts +365 -0
- package/dist/db-DhMsmBS--DKENDi3l.d.mts.map +1 -0
- package/dist/ddl-types-BMp2bWVS-D1waZJ4n.mjs +153 -0
- package/dist/ddl-types-BMp2bWVS-D1waZJ4n.mjs.map +1 -0
- package/dist/ddl-types-rrMsf77U-DGctYf-T.d.mts +149 -0
- package/dist/ddl-types-rrMsf77U-DGctYf-T.d.mts.map +1 -0
- package/dist/diff-B16bL_IR.mjs +13 -0
- package/dist/diff-B16bL_IR.mjs.map +1 -0
- package/dist/diff-DhlzHOMD.d.mts +104 -0
- package/dist/diff-DhlzHOMD.d.mts.map +1 -0
- package/dist/dist-C_q1_QR9.mjs +9 -0
- package/dist/dist-C_q1_QR9.mjs.map +1 -0
- package/dist/dist-DrScXbhq.mjs +414 -0
- package/dist/dist-DrScXbhq.mjs.map +1 -0
- package/dist/dist-x6jvtkKM.mjs +68 -0
- package/dist/dist-x6jvtkKM.mjs.map +1 -0
- package/dist/entity-handle-lowering-hook-CIvRKBfa.d.mts +92 -0
- package/dist/entity-handle-lowering-hook-CIvRKBfa.d.mts.map +1 -0
- package/dist/entity-handle-lowering-hook-DwLIKNiS.mjs +11 -0
- package/dist/entity-handle-lowering-hook-DwLIKNiS.mjs.map +1 -0
- package/dist/entity-kinds-DKxwKolf-CcsY-iYV.mjs +136 -0
- package/dist/entity-kinds-DKxwKolf-CcsY-iYV.mjs.map +1 -0
- package/dist/entity-kinds-Dh6VH4uK.d.mts +29 -0
- package/dist/entity-kinds-Dh6VH4uK.d.mts.map +1 -0
- package/dist/errors-B5g0xWro-mWH2C07F.mjs +9 -0
- package/dist/errors-B5g0xWro-mWH2C07F.mjs.map +1 -0
- package/dist/errors.d.mts +63 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +2 -0
- package/dist/expression-DIf8F4Mc.d.mts +167 -0
- package/dist/expression-DIf8F4Mc.d.mts.map +1 -0
- package/dist/expression-RUO52bJB.mjs +109 -0
- package/dist/expression-RUO52bJB.mjs.map +1 -0
- package/dist/factories-B7tA4y9D.d.mts +39 -0
- package/dist/factories-B7tA4y9D.d.mts.map +1 -0
- package/dist/factories-CDG9zBxC.mjs +77 -0
- package/dist/factories-CDG9zBxC.mjs.map +1 -0
- package/dist/family.d.mts +13 -0
- package/dist/family.mjs +12 -0
- package/dist/family__control-adapter.d.mts +3 -0
- package/dist/family__control-adapter.mjs +1 -0
- package/dist/family__control.d.mts +4 -0
- package/dist/family__control.mjs +4 -0
- package/dist/family__diff.d.mts +3 -0
- package/dist/family__diff.mjs +3 -0
- package/dist/family__ir.d.mts +2 -0
- package/dist/family__ir.mjs +3 -0
- package/dist/family__migration.d.mts +2 -0
- package/dist/family__migration.mjs +2 -0
- package/dist/family__pack.d.mts +249 -0
- package/dist/family__pack.d.mts.map +1 -0
- package/dist/family__pack.mjs +18 -0
- package/dist/family__pack.mjs.map +1 -0
- package/dist/family__psl-infer.d.mts +2 -0
- package/dist/family__psl-infer.mjs +2 -0
- package/dist/family__runtime.d.mts +3 -0
- package/dist/family__runtime.mjs +3 -0
- package/dist/family__verify.d.mts +2 -0
- package/dist/family__verify.mjs +2 -0
- package/dist/foreign-key-BSy9u4O4-BnsOe5Nf.d.mts +85 -0
- package/dist/foreign-key-BSy9u4O4-BnsOe5Nf.d.mts.map +1 -0
- package/dist/foreign-key-materialization-Ca-wRbmj.d.mts +65 -0
- package/dist/foreign-key-materialization-Ca-wRbmj.d.mts.map +1 -0
- package/dist/foreign-key-materialization-HI7BIQrG.mjs +72 -0
- package/dist/foreign-key-materialization-HI7BIQrG.mjs.map +1 -0
- package/dist/index-Bb9U36N4.d.mts +511 -0
- package/dist/index-Bb9U36N4.d.mts.map +1 -0
- package/dist/index-BgaTJRxj.d.mts +25 -0
- package/dist/index-BgaTJRxj.d.mts.map +1 -0
- package/dist/index-naming-BZWoh45T.d.mts +62 -0
- package/dist/index-naming-BZWoh45T.d.mts.map +1 -0
- package/dist/index-naming-BoGBcMmI-DiJAr66H.mjs +108 -0
- package/dist/index-naming-BoGBcMmI-DiJAr66H.mjs.map +1 -0
- package/dist/index-type-validation-COH4d78M.mjs +17 -0
- package/dist/index-type-validation-COH4d78M.mjs.map +1 -0
- package/dist/index-type-validation-DN0L2mqm.d.mts +10 -0
- package/dist/index-type-validation-DN0L2mqm.d.mts.map +1 -0
- package/dist/index-types-CNhHgKHi.d.mts +1 -0
- package/dist/index-types-DJQ_xwaE.mjs +40 -0
- package/dist/index-types-DJQ_xwaE.mjs.map +1 -0
- package/dist/index-types-DPVhsW0v-D-BikM4h.d.mts +31 -0
- package/dist/index-types-DPVhsW0v-D-BikM4h.d.mts.map +1 -0
- package/dist/interpreter-5WgpL-ax-_nqHLUTr.mjs +3526 -0
- package/dist/interpreter-5WgpL-ax-_nqHLUTr.mjs.map +1 -0
- package/dist/ir-B3bKMnGQ.d.mts +123 -0
- package/dist/ir-B3bKMnGQ.d.mts.map +1 -0
- package/dist/ir-I-xciGUH.mjs +36 -0
- package/dist/ir-I-xciGUH.mjs.map +1 -0
- package/dist/lane-query-builder.d.mts +236 -0
- package/dist/lane-query-builder.d.mts.map +1 -0
- package/dist/lane-query-builder.mjs +67 -0
- package/dist/lane-query-builder.mjs.map +1 -0
- package/dist/middleware-B4XbF4d4-tfwBl6mX.d.mts +119 -0
- package/dist/middleware-B4XbF4d4-tfwBl6mX.d.mts.map +1 -0
- package/dist/middleware-ByRsXxxq.d.mts +1 -0
- package/dist/middleware-CMr4CHNz-DHIUdxlm.mjs +80 -0
- package/dist/middleware-CMr4CHNz-DHIUdxlm.mjs.map +1 -0
- package/dist/migration-CK4oePIo.mjs +44 -0
- package/dist/migration-CK4oePIo.mjs.map +1 -0
- package/dist/migration-CW0ZJLxP.d.mts +44 -0
- package/dist/migration-CW0ZJLxP.d.mts.map +1 -0
- package/dist/naming-BwqqVcZy-BgTObIQw.mjs +177 -0
- package/dist/naming-BwqqVcZy-BgTObIQw.mjs.map +1 -0
- package/dist/naming-jLgdauLi-C84G_UHi.d.mts +133 -0
- package/dist/naming-jLgdauLi-C84G_UHi.d.mts.map +1 -0
- package/dist/operations.d.mts +2 -0
- package/dist/operations.mjs +2 -0
- package/dist/orm-client.d.mts +1316 -0
- package/dist/orm-client.d.mts.map +1 -0
- package/dist/orm-client.mjs +4544 -0
- package/dist/orm-client.mjs.map +1 -0
- package/dist/pack-types-BcLTpwbv.d.mts +14 -0
- package/dist/pack-types-BcLTpwbv.d.mts.map +1 -0
- package/dist/plan-BTD8xFfa-Dd_K-A1R.d.mts +45 -0
- package/dist/plan-BTD8xFfa-Dd_K-A1R.d.mts.map +1 -0
- package/dist/plan-CkpcgUaM.mjs +34 -0
- package/dist/plan-CkpcgUaM.mjs.map +1 -0
- package/dist/plan-Cm4jaoNM.d.mts +2 -0
- package/dist/psl-infer-6je61Z6J.d.mts +119 -0
- package/dist/psl-infer-6je61Z6J.d.mts.map +1 -0
- package/dist/psl-infer-DGftl-HW.mjs +362 -0
- package/dist/psl-infer-DGftl-HW.mjs.map +1 -0
- package/dist/query-lane-context-Bz8XJZ45.d.mts +1 -0
- package/dist/query-lane-context-DtdVMqoz-C2Tj5QHA.d.mts +94 -0
- package/dist/query-lane-context-DtdVMqoz-C2Tj5QHA.d.mts.map +1 -0
- package/dist/referential-action-sql-Csd6dA8G.d.mts +12 -0
- package/dist/referential-action-sql-Csd6dA8G.d.mts.map +1 -0
- package/dist/referential-action-sql-DSqkrySN.mjs +17 -0
- package/dist/referential-action-sql-DSqkrySN.mjs.map +1 -0
- package/dist/relational-core.d.mts +13 -0
- package/dist/relational-core.mjs +8 -0
- package/dist/relational-core__ast.d.mts +5 -0
- package/dist/relational-core__ast.mjs +5 -0
- package/dist/relational-core__codec-descriptor-registry.d.mts +39 -0
- package/dist/relational-core__codec-descriptor-registry.d.mts.map +1 -0
- package/dist/relational-core__codec-descriptor-registry.mjs +2 -0
- package/dist/relational-core__contract-free.d.mts +220 -0
- package/dist/relational-core__contract-free.d.mts.map +1 -0
- package/dist/relational-core__contract-free.mjs +393 -0
- package/dist/relational-core__contract-free.mjs.map +1 -0
- package/dist/relational-core__expression.d.mts +2 -0
- package/dist/relational-core__expression.mjs +2 -0
- package/dist/relational-core__middleware.d.mts +3 -0
- package/dist/relational-core__middleware.mjs +2 -0
- package/dist/relational-core__plan.d.mts +4 -0
- package/dist/relational-core__plan.mjs +2 -0
- package/dist/relational-core__query-lane-context.d.mts +3 -0
- package/dist/relational-core__query-lane-context.mjs +1 -0
- package/dist/relational-core__types.d.mts +3 -0
- package/dist/relational-core__types.mjs +1 -0
- package/dist/resolve-storage-table-DUwyRJmP.d.mts +21 -0
- package/dist/resolve-storage-table-DUwyRJmP.d.mts.map +1 -0
- package/dist/resolve-storage-table-DZsfnzeW.mjs +46 -0
- package/dist/resolve-storage-table-DZsfnzeW.mjs.map +1 -0
- package/dist/runtime-DNewRuec.d.mts +46 -0
- package/dist/runtime-DNewRuec.d.mts.map +1 -0
- package/dist/runtime-tIHpGCcG.mjs +55 -0
- package/dist/runtime-tIHpGCcG.mjs.map +1 -0
- package/dist/runtime.d.mts +4 -0
- package/dist/runtime.mjs +1606 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/schema-differ-DpG_gnur-g5_iks8G.d.mts +47 -0
- package/dist/schema-differ-DpG_gnur-g5_iks8G.d.mts.map +1 -0
- package/dist/schema-ir.d.mts +2 -0
- package/dist/schema-ir.mjs +2 -0
- package/dist/schema-ir__naming.d.mts +2 -0
- package/dist/schema-ir__naming.mjs +2 -0
- package/dist/schema-ir__types.d.mts +3 -0
- package/dist/schema-ir__types.mjs +2 -0
- package/dist/schema-verify-vtFZbmGq-BNfTr6fU.mjs +222 -0
- package/dist/schema-verify-vtFZbmGq-BNfTr6fU.mjs.map +1 -0
- package/dist/serialized-index-B96AwqtU-DcqcB4q_.d.mts +26 -0
- package/dist/serialized-index-B96AwqtU-DcqcB4q_.d.mts.map +1 -0
- package/dist/serialized-index-Dp5_EjXD-DMsw8jf3.mjs +64 -0
- package/dist/serialized-index-Dp5_EjXD-DMsw8jf3.mjs.map +1 -0
- package/dist/sql-contract-serializer-2oBWuxTe-B9hzBBv1.mjs +171 -0
- package/dist/sql-contract-serializer-2oBWuxTe-B9hzBBv1.mjs.map +1 -0
- package/dist/sql-execution-plan-CJmsCP7n-DoEpNn7r.d.mts +32 -0
- package/dist/sql-execution-plan-CJmsCP7n-DoEpNn7r.d.mts.map +1 -0
- package/dist/sql-index-DsI8HAeK-BJsn-jvD.d.mts +72 -0
- package/dist/sql-index-DsI8HAeK-BJsn-jvD.d.mts.map +1 -0
- package/dist/sql-node-kEz6YFZo-v2F7delx.d.mts +42 -0
- package/dist/sql-node-kEz6YFZo-v2F7delx.d.mts.map +1 -0
- package/dist/sql-storage-B0QwiTg6-B8DVctJm.d.mts +171 -0
- package/dist/sql-storage-B0QwiTg6-B8DVctJm.d.mts.map +1 -0
- package/dist/storage-table-BBaAmanc-BwR37LMA.d.mts +130 -0
- package/dist/storage-table-BBaAmanc-BwR37LMA.d.mts.map +1 -0
- package/dist/storage-table-_LWDmPfv-DFhU2dML.mjs +277 -0
- package/dist/storage-table-_LWDmPfv-DFhU2dML.mjs.map +1 -0
- package/dist/storage-value-set-BGlj5Uus-CvZD--GG.d.mts +41 -0
- package/dist/storage-value-set-BGlj5Uus-CvZD--GG.d.mts.map +1 -0
- package/dist/timestamp-now-generator-DRXygu32-DN9Qb1uI.mjs +173 -0
- package/dist/timestamp-now-generator-DRXygu32-DN9Qb1uI.mjs.map +1 -0
- package/dist/types-BchwQpmO.d.mts +16 -0
- package/dist/types-BchwQpmO.d.mts.map +1 -0
- package/dist/types-BgkZru_1-H7yfikSQ.mjs +1444 -0
- package/dist/types-BgkZru_1-H7yfikSQ.mjs.map +1 -0
- package/dist/types-CMMQS6aG.mjs +111 -0
- package/dist/types-CMMQS6aG.mjs.map +1 -0
- package/dist/types-CuDrWc5v-ISVXBmBs.d.mts +134 -0
- package/dist/types-CuDrWc5v-ISVXBmBs.d.mts.map +1 -0
- package/dist/types-CvbBw1Jo-3KQdErJY.d.mts +688 -0
- package/dist/types-CvbBw1Jo-3KQdErJY.d.mts.map +1 -0
- package/dist/types-DIBA80mc-wf5wLmON.d.mts +723 -0
- package/dist/types-DIBA80mc-wf5wLmON.d.mts.map +1 -0
- package/dist/types-DMxc5KZa.d.mts +1 -0
- package/dist/types-Dl20lxky-DC_jdA0T.d.mts +247 -0
- package/dist/types-Dl20lxky-DC_jdA0T.d.mts.map +1 -0
- package/dist/types-DmhUVq4u-BpqqjPJx.mjs +719 -0
- package/dist/types-DmhUVq4u-BpqqjPJx.mjs.map +1 -0
- package/dist/types-IqZMLrFC-DtdJNICr.d.mts +426 -0
- package/dist/types-IqZMLrFC-DtdJNICr.d.mts.map +1 -0
- package/dist/types-TvBZ2Ne9.d.mts +1 -0
- package/dist/unique-constraint-jQWfH7dg-zLWtFp99.d.mts +32 -0
- package/dist/unique-constraint-jQWfH7dg-zLWtFp99.d.mts.map +1 -0
- package/dist/util-DQQgv2j1-D6INZaRG.mjs +34 -0
- package/dist/util-DQQgv2j1-D6INZaRG.mjs.map +1 -0
- package/dist/validators-C4PItWnf.mjs +0 -0
- package/dist/validators-C4PItWnf.mjs.map +1 -0
- package/dist/validators-CxeHhHrf.d.mts +206 -0
- package/dist/validators-CxeHhHrf.d.mts.map +1 -0
- package/dist/value-set-derivation-hook-BhgGVtw0.d.mts +35 -0
- package/dist/value-set-derivation-hook-BhgGVtw0.d.mts.map +1 -0
- package/dist/value-set-derivation-hook-Di9JZ0X7.mjs +22 -0
- package/dist/value-set-derivation-hook-Di9JZ0X7.mjs.map +1 -0
- package/dist/verify-E6Dd2vYp-gYwnlhLm.mjs +86 -0
- package/dist/verify-E6Dd2vYp-gYwnlhLm.mjs.map +1 -0
- package/dist/verify-zDRnw0Rn.d.mts +26 -0
- package/dist/verify-zDRnw0Rn.d.mts.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { UNBOUND_NAMESPACE_ID, entityAt } from "@prisma/orm-framework/components/ir";
|
|
2
|
+
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
3
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
4
|
+
import { renderValueSetType, serializeNamespaceId, serializeObjectKey, serializeValue } from "@prisma/orm-toolchain/emitter/domain-type-generation";
|
|
5
|
+
import { isSafeTypeExpression } from "@prisma/orm-toolchain/emitter/type-expression-safety";
|
|
6
|
+
//#region ../../../2-sql/3-tooling/emitter/dist/index.mjs
|
|
7
|
+
function sqlEmitterError(code, message, options) {
|
|
8
|
+
return structuredError(code, message, options);
|
|
9
|
+
}
|
|
10
|
+
function sqlEmitterValidationError(message, meta) {
|
|
11
|
+
return sqlEmitterError("CONTRACT.VALIDATION_FAILED", message, {
|
|
12
|
+
why: "The contract given to the SQL emitter failed structural validation.",
|
|
13
|
+
fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
|
|
14
|
+
meta
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function serializeTypeParamsLiteral(params) {
|
|
18
|
+
if (!params || Object.keys(params).length === 0) return "Record<string, never>";
|
|
19
|
+
const entries = [];
|
|
20
|
+
for (const [key, value] of Object.entries(params)) entries.push(`readonly ${serializeObjectKey(key)}: ${serializeValue(value)}`);
|
|
21
|
+
return `{ ${entries.join("; ")} }`;
|
|
22
|
+
}
|
|
23
|
+
const sqlEmission = {
|
|
24
|
+
id: "sql",
|
|
25
|
+
validateTypes(contract, _ctx) {
|
|
26
|
+
const storage = contract.storage;
|
|
27
|
+
if (!storage?.namespaces) return;
|
|
28
|
+
const typeIdRegex = /^([^/]+)\/([^@]+)@(\d+)$/;
|
|
29
|
+
for (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const [colName, colUnknown] of Object.entries(table.columns)) {
|
|
30
|
+
const codecId = colUnknown.codecId;
|
|
31
|
+
if (!codecId) throw sqlEmitterValidationError(`Column "${colName}" in table "${tableName}" is missing codecId`, {
|
|
32
|
+
table: tableName,
|
|
33
|
+
column: colName
|
|
34
|
+
});
|
|
35
|
+
if (!codecId.match(typeIdRegex)?.[1]) throw sqlEmitterValidationError(`Column "${colName}" in table "${tableName}" has invalid codec ID format "${codecId}". Expected format: ns/name@version`, {
|
|
36
|
+
table: tableName,
|
|
37
|
+
column: colName,
|
|
38
|
+
codecId
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
validateStructure(contract) {
|
|
43
|
+
if (contract.targetFamily !== "sql") throw sqlEmitterValidationError(`Expected targetFamily "sql", got "${contract.targetFamily}"`, { targetFamily: contract.targetFamily });
|
|
44
|
+
const storage = contract.storage;
|
|
45
|
+
if (!storage?.namespaces) throw sqlEmitterValidationError("SQL contract must have storage.namespaces", {});
|
|
46
|
+
const tableNamesSeenAcrossNamespaces = /* @__PURE__ */ new Map();
|
|
47
|
+
for (const [nsId, ns] of Object.entries(storage.namespaces)) for (const tableName of Object.keys(ns.entries.table ?? {})) {
|
|
48
|
+
const existingNs = tableNamesSeenAcrossNamespaces.get(tableName);
|
|
49
|
+
if (existingNs !== void 0 && existingNs !== nsId) throw sqlEmitterError("CONTRACT.NAME_DUPLICATE", `Duplicate table name "${tableName}" in namespaces "${existingNs}" and "${nsId}"`, {
|
|
50
|
+
why: "Two SQL namespaces declare a table with the same name, which is ambiguous for emission.",
|
|
51
|
+
fix: "Rename one of the tables so every table name is unique across namespaces.",
|
|
52
|
+
meta: {
|
|
53
|
+
table: tableName,
|
|
54
|
+
namespaces: [existingNs, nsId]
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
tableNamesSeenAcrossNamespaces.set(tableName, nsId);
|
|
58
|
+
}
|
|
59
|
+
const tableNames = /* @__PURE__ */ new Set();
|
|
60
|
+
for (const ns of Object.values(storage.namespaces)) for (const t of Object.keys(ns.entries.table ?? {})) tableNames.add(t);
|
|
61
|
+
for (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {
|
|
62
|
+
const models = domainNs.models;
|
|
63
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
64
|
+
const qualifiedName = `${namespaceId}:${modelName}`;
|
|
65
|
+
if (!model.storage?.table) throw sqlEmitterValidationError(`Model "${qualifiedName}" is missing storage.table`, { model: qualifiedName });
|
|
66
|
+
if (!model.storage.namespaceId) throw sqlEmitterValidationError(`Model "${qualifiedName}" is missing storage.namespaceId`, { model: qualifiedName });
|
|
67
|
+
if (model.storage.namespaceId !== namespaceId) throw sqlEmitterValidationError(`Model "${qualifiedName}" storage.namespaceId "${model.storage.namespaceId}" does not match domain namespace "${namespaceId}"`, {
|
|
68
|
+
model: qualifiedName,
|
|
69
|
+
storageNamespaceId: model.storage.namespaceId,
|
|
70
|
+
domainNamespaceId: namespaceId
|
|
71
|
+
});
|
|
72
|
+
const tableName = model.storage.table;
|
|
73
|
+
const table = entityAt(storage, {
|
|
74
|
+
namespaceId,
|
|
75
|
+
entityKind: "table",
|
|
76
|
+
entityName: tableName
|
|
77
|
+
});
|
|
78
|
+
if (!table) throw sqlEmitterValidationError(`Model "${qualifiedName}" references non-existent table "${namespaceId}.${tableName}"`, {
|
|
79
|
+
model: qualifiedName,
|
|
80
|
+
table: `${namespaceId}.${tableName}`
|
|
81
|
+
});
|
|
82
|
+
const columnNames = new Set(Object.keys(table.columns));
|
|
83
|
+
const storageFields = model.storage.fields;
|
|
84
|
+
if (!storageFields || Object.keys(storageFields).length === 0) throw sqlEmitterValidationError(`Model "${qualifiedName}" is missing storage.fields`, { model: qualifiedName });
|
|
85
|
+
for (const [fieldName, field] of Object.entries(storageFields)) {
|
|
86
|
+
if (!field.column) throw sqlEmitterValidationError(`Model "${qualifiedName}" field "${fieldName}" is missing column property`, {
|
|
87
|
+
model: qualifiedName,
|
|
88
|
+
field: fieldName
|
|
89
|
+
});
|
|
90
|
+
if (!columnNames.has(field.column)) throw sqlEmitterValidationError(`Model "${qualifiedName}" field "${fieldName}" references non-existent column "${field.column}" in table "${tableName}"`, {
|
|
91
|
+
model: qualifiedName,
|
|
92
|
+
field: fieldName,
|
|
93
|
+
column: field.column,
|
|
94
|
+
table: tableName
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!model.relations || typeof model.relations !== "object") throw sqlEmitterValidationError(`Model "${qualifiedName}" is missing required field "relations" (must be an object)`, { model: qualifiedName });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) {
|
|
101
|
+
const columnNames = new Set(Object.keys(table.columns));
|
|
102
|
+
if (!Array.isArray(table.uniques)) throw sqlEmitterValidationError(`Table "${tableName}" is missing required field "uniques" (must be an array)`, { table: tableName });
|
|
103
|
+
if (!Array.isArray(table.indexes)) throw sqlEmitterValidationError(`Table "${tableName}" is missing required field "indexes" (must be an array)`, { table: tableName });
|
|
104
|
+
if (!Array.isArray(table.foreignKeys)) throw sqlEmitterValidationError(`Table "${tableName}" is missing required field "foreignKeys" (must be an array)`, { table: tableName });
|
|
105
|
+
if (table.primaryKey) {
|
|
106
|
+
for (const colName of table.primaryKey.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table "${tableName}" primaryKey references non-existent column "${colName}"`, {
|
|
107
|
+
table: tableName,
|
|
108
|
+
column: colName
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
for (const unique of table.uniques) for (const colName of unique.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table "${tableName}" unique constraint references non-existent column "${colName}"`, {
|
|
112
|
+
table: tableName,
|
|
113
|
+
column: colName
|
|
114
|
+
});
|
|
115
|
+
for (const index of table.indexes) for (const colName of index.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table "${tableName}" index references non-existent column "${colName}"`, {
|
|
116
|
+
table: tableName,
|
|
117
|
+
column: colName
|
|
118
|
+
});
|
|
119
|
+
for (const fk of table.foreignKeys) {
|
|
120
|
+
for (const colName of fk.source.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table "${tableName}" foreignKey references non-existent column "${colName}"`, {
|
|
121
|
+
table: tableName,
|
|
122
|
+
column: colName
|
|
123
|
+
});
|
|
124
|
+
const referencedTable = entityAt(storage, {
|
|
125
|
+
namespaceId: fk.target.namespaceId,
|
|
126
|
+
entityKind: "table",
|
|
127
|
+
entityName: fk.target.tableName
|
|
128
|
+
});
|
|
129
|
+
if (!referencedTable) throw sqlEmitterValidationError(`Table "${tableName}" foreignKey references non-existent table "${fk.target.tableName}" in namespace "${fk.target.namespaceId}"`, {
|
|
130
|
+
table: tableName,
|
|
131
|
+
targetTable: fk.target.tableName,
|
|
132
|
+
targetNamespace: fk.target.namespaceId
|
|
133
|
+
});
|
|
134
|
+
const referencedColumnNames = new Set(Object.keys(referencedTable.columns));
|
|
135
|
+
for (const colName of fk.target.columns) if (!referencedColumnNames.has(colName)) throw sqlEmitterValidationError(`Table "${tableName}" foreignKey references non-existent column "${colName}" in table "${fk.target.tableName}"`, {
|
|
136
|
+
table: tableName,
|
|
137
|
+
column: colName,
|
|
138
|
+
targetTable: fk.target.tableName
|
|
139
|
+
});
|
|
140
|
+
if (fk.source.columns.length !== fk.target.columns.length) throw sqlEmitterValidationError(`Table "${tableName}" foreignKey column count (${fk.source.columns.length}) does not match referenced column count (${fk.target.columns.length})`, {
|
|
141
|
+
table: tableName,
|
|
142
|
+
sourceColumnCount: fk.source.columns.length,
|
|
143
|
+
targetColumnCount: fk.target.columns.length
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
generateStorageType(contract, storageHashTypeName) {
|
|
149
|
+
const storage = contract.storage;
|
|
150
|
+
const namespacesType = generateStorageNamespacesType(storage.namespaces);
|
|
151
|
+
const docTypes = generateDocumentScopedStorageTypesType(storage.types);
|
|
152
|
+
return `{ readonly namespaces: ${namespacesType}${docTypes === void 0 ? "" : `; readonly types: ${docTypes}`}; readonly storageHash: ${storageHashTypeName} }`;
|
|
153
|
+
},
|
|
154
|
+
generateModelStorageType(_modelName, model) {
|
|
155
|
+
const sqlModel = model;
|
|
156
|
+
const tableName = sqlModel.storage.table;
|
|
157
|
+
const storageFields = sqlModel.storage.fields;
|
|
158
|
+
const storageParts = [`readonly table: ${serializeValue(tableName)}`, `readonly namespaceId: ${serializeValue(sqlModel.storage.namespaceId)}`];
|
|
159
|
+
if (Object.keys(storageFields).length > 0) {
|
|
160
|
+
const fieldParts = [];
|
|
161
|
+
for (const [fieldName, field] of Object.entries(storageFields)) fieldParts.push(`readonly ${serializeObjectKey(fieldName)}: { readonly column: ${serializeValue(field.column)} }`);
|
|
162
|
+
storageParts.push(`readonly fields: { ${fieldParts.join("; ")} }`);
|
|
163
|
+
}
|
|
164
|
+
return `{ ${storageParts.join("; ")} }`;
|
|
165
|
+
},
|
|
166
|
+
resolveFieldTypeParams(_modelName, fieldName, model, contract) {
|
|
167
|
+
const sqlModel = model;
|
|
168
|
+
const storageField = sqlModel.storage?.fields?.[fieldName];
|
|
169
|
+
if (!storageField) return void 0;
|
|
170
|
+
const storage = contract.storage;
|
|
171
|
+
if (!storage) return void 0;
|
|
172
|
+
const tableName = sqlModel.storage.table;
|
|
173
|
+
const storageNamespaceId = sqlModel.storage.namespaceId;
|
|
174
|
+
if (!storageNamespaceId) return void 0;
|
|
175
|
+
const table = entityAt(storage, {
|
|
176
|
+
namespaceId: storageNamespaceId,
|
|
177
|
+
entityKind: "table",
|
|
178
|
+
entityName: tableName
|
|
179
|
+
});
|
|
180
|
+
if (!table) return void 0;
|
|
181
|
+
const column = table.columns[storageField.column];
|
|
182
|
+
if (!column) return void 0;
|
|
183
|
+
if (column.typeRef) {
|
|
184
|
+
const typeInstance = storage.types?.[column.typeRef];
|
|
185
|
+
if (typeInstance === void 0) return void 0;
|
|
186
|
+
return typeInstance.typeParams;
|
|
187
|
+
}
|
|
188
|
+
return column.typeParams;
|
|
189
|
+
},
|
|
190
|
+
resolveFieldValueSet(_modelName, fieldName, model, contract) {
|
|
191
|
+
const sqlModel = blindCast(model);
|
|
192
|
+
const storageField = sqlModel.storage?.fields?.[fieldName];
|
|
193
|
+
if (!storageField) return void 0;
|
|
194
|
+
const storage = blindCast(contract.storage);
|
|
195
|
+
if (!storage) return void 0;
|
|
196
|
+
const storageNamespaceId = sqlModel.storage.namespaceId;
|
|
197
|
+
if (!storageNamespaceId) return void 0;
|
|
198
|
+
const column = entityAt(storage, {
|
|
199
|
+
namespaceId: storageNamespaceId,
|
|
200
|
+
entityKind: "table",
|
|
201
|
+
entityName: sqlModel.storage.table
|
|
202
|
+
})?.columns[storageField.column];
|
|
203
|
+
if (!column?.valueSet) return void 0;
|
|
204
|
+
const valueSet = entityAt(storage, {
|
|
205
|
+
namespaceId: column.valueSet.namespaceId,
|
|
206
|
+
entityKind: column.valueSet.entityKind,
|
|
207
|
+
entityName: column.valueSet.entityName
|
|
208
|
+
});
|
|
209
|
+
if (!valueSet) return void 0;
|
|
210
|
+
return {
|
|
211
|
+
encodedValues: valueSet.values,
|
|
212
|
+
codecId: column.codecId
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
getStorageTypeExports(contract, codecLookup) {
|
|
216
|
+
const storage = blindCast(contract.storage);
|
|
217
|
+
if (!storage?.namespaces) return void 0;
|
|
218
|
+
const outputMap = generateStorageColumnTypesMap(storage, "output", codecLookup);
|
|
219
|
+
const inputMap = generateStorageColumnTypesMap(storage, "input", codecLookup);
|
|
220
|
+
return [`export type StorageColumnTypes = ${outputMap};`, `export type StorageColumnInputTypes = ${inputMap};`].join("\n");
|
|
221
|
+
},
|
|
222
|
+
getFamilyImports(resolveImportSpecifier) {
|
|
223
|
+
return [
|
|
224
|
+
"import type {",
|
|
225
|
+
" ContractWithTypeMaps,",
|
|
226
|
+
" TypeMaps as TypeMapsType,",
|
|
227
|
+
`} from '${resolveImportSpecifier("@internal/sql-contract/types")}';`
|
|
228
|
+
];
|
|
229
|
+
},
|
|
230
|
+
getFamilyTypeAliases(options) {
|
|
231
|
+
const queryOperationAliases = (options?.queryOperationTypeImports ?? []).filter((imp) => imp.named === "QueryOperationTypes").map((imp) => `${imp.alias}<CodecTypes>`);
|
|
232
|
+
return [
|
|
233
|
+
"export type LaneCodecTypes = CodecTypes;",
|
|
234
|
+
`export type QueryOperationTypes = ${queryOperationAliases.length > 0 ? queryOperationAliases.join(" & ") : "Record<string, never>"};`,
|
|
235
|
+
"type DefaultLiteralValue<CodecId extends string, Encoded> =",
|
|
236
|
+
" CodecId extends keyof CodecTypes",
|
|
237
|
+
" ? Encoded extends CodecTypes[CodecId]['json']",
|
|
238
|
+
" ? Encoded",
|
|
239
|
+
" : CodecTypes[CodecId]['json']",
|
|
240
|
+
" : Encoded;"
|
|
241
|
+
].join("\n");
|
|
242
|
+
},
|
|
243
|
+
getTypeMapsExpression() {
|
|
244
|
+
return "TypeMapsType<CodecTypes, QueryOperationTypes, FieldOutputTypes, FieldInputTypes, StorageColumnTypes, StorageColumnInputTypes>";
|
|
245
|
+
},
|
|
246
|
+
getContractWrapper(contractBaseName, typeMapsName) {
|
|
247
|
+
return [
|
|
248
|
+
`export type Contract = ContractWithTypeMaps<${contractBaseName}, ${typeMapsName}>;`,
|
|
249
|
+
"",
|
|
250
|
+
"export type Namespaces = Contract['storage']['namespaces'];"
|
|
251
|
+
].join("\n");
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
function columnTypeParams(storage, column) {
|
|
255
|
+
if (column.typeRef) {
|
|
256
|
+
const typeInstance = storage.types?.[column.typeRef];
|
|
257
|
+
if (typeInstance === void 0) return void 0;
|
|
258
|
+
return blindCast(typeInstance).typeParams;
|
|
259
|
+
}
|
|
260
|
+
return column.typeParams;
|
|
261
|
+
}
|
|
262
|
+
function renderRefinedCodecType(column, side, params, codecLookup) {
|
|
263
|
+
if (codecLookup && params && Object.keys(params).length > 0) {
|
|
264
|
+
const rendered = side === "output" ? codecLookup.renderOutputTypeFor(column.codecId, params) : codecLookup.renderInputTypeFor?.(column.codecId, params);
|
|
265
|
+
if (rendered && isSafeTypeExpression(rendered)) return rendered;
|
|
266
|
+
}
|
|
267
|
+
return `CodecTypes[${serializeValue(column.codecId)}][${serializeValue(side)}]`;
|
|
268
|
+
}
|
|
269
|
+
function computeColumnType(storage, column, side, codecLookup) {
|
|
270
|
+
let base;
|
|
271
|
+
if (column.valueSet) {
|
|
272
|
+
const valueSet = entityAt(storage, {
|
|
273
|
+
namespaceId: column.valueSet.namespaceId,
|
|
274
|
+
entityKind: column.valueSet.entityKind,
|
|
275
|
+
entityName: column.valueSet.entityName
|
|
276
|
+
});
|
|
277
|
+
base = valueSet ? renderValueSetType(valueSet.values, column.codecId, side, codecLookup) : void 0;
|
|
278
|
+
}
|
|
279
|
+
if (base === void 0) base = renderRefinedCodecType(column, side, columnTypeParams(storage, column), codecLookup);
|
|
280
|
+
if (column.many === true) base = `ReadonlyArray<${base}>`;
|
|
281
|
+
return column.nullable ? `${base} | null` : base;
|
|
282
|
+
}
|
|
283
|
+
function generateStorageColumnTypesMap(storage, side, codecLookup) {
|
|
284
|
+
const namespaceEntries = Object.entries(storage.namespaces ?? {}).sort(([a], [b]) => a.localeCompare(b));
|
|
285
|
+
if (namespaceEntries.length === 0) return "Record<string, never>";
|
|
286
|
+
const nsParts = [];
|
|
287
|
+
for (const [nsId, ns] of namespaceEntries) {
|
|
288
|
+
const tables = blindCast(ns.entries.table ?? {});
|
|
289
|
+
const tableEntries = Object.entries(tables).sort(([a], [b]) => a.localeCompare(b));
|
|
290
|
+
const tableParts = [];
|
|
291
|
+
for (const [tableName, table] of tableEntries) {
|
|
292
|
+
const colEntries = Object.entries(table.columns).sort(([a], [b]) => a.localeCompare(b));
|
|
293
|
+
const colParts = [];
|
|
294
|
+
for (const [colName, col] of colEntries) {
|
|
295
|
+
const colType = computeColumnType(storage, col, side, codecLookup);
|
|
296
|
+
colParts.push(`readonly ${serializeObjectKey(colName)}: ${colType}`);
|
|
297
|
+
}
|
|
298
|
+
const colMap = colParts.length > 0 ? `{ ${colParts.join("; ")} }` : "{}";
|
|
299
|
+
tableParts.push(`readonly ${serializeObjectKey(tableName)}: ${colMap}`);
|
|
300
|
+
}
|
|
301
|
+
const tableMap = tableParts.length > 0 ? `{ ${tableParts.join("; ")} }` : "{}";
|
|
302
|
+
nsParts.push(`readonly ${serializeObjectKey(nsId)}: ${tableMap}`);
|
|
303
|
+
}
|
|
304
|
+
return `{ ${nsParts.join("; ")} }`;
|
|
305
|
+
}
|
|
306
|
+
function generateDocumentScopedStorageTypesType(types) {
|
|
307
|
+
if (!types || Object.keys(types).length === 0) return;
|
|
308
|
+
const typeEntries = [];
|
|
309
|
+
for (const [typeName, typeInstance] of Object.entries(types)) {
|
|
310
|
+
const codecInstanceShape = typeInstance;
|
|
311
|
+
if (typeof codecInstanceShape.codecId !== "string" || typeof codecInstanceShape.nativeType !== "string") throw sqlEmitterError("CONTRACT.TYPE_UNKNOWN", `Unknown storage type kind for "${typeName}" in document-scoped storage.types; expected a codec-instance triple.`, {
|
|
312
|
+
why: "A storage.types entry is not a codec-instance triple, so its column type cannot be emitted.",
|
|
313
|
+
fix: "Regenerate the contract from its authoring source; storage.types entries must carry codecId and nativeType.",
|
|
314
|
+
meta: { type: typeName }
|
|
315
|
+
});
|
|
316
|
+
const codecId = serializeValue(codecInstanceShape.codecId);
|
|
317
|
+
const nativeType = serializeValue(codecInstanceShape.nativeType);
|
|
318
|
+
const typeParamsStr = serializeTypeParamsLiteral(codecInstanceShape.typeParams);
|
|
319
|
+
typeEntries.push(`readonly ${typeName}: { readonly kind: 'codec-instance'; readonly codecId: ${codecId}; readonly nativeType: ${nativeType}; readonly typeParams: ${typeParamsStr} }`);
|
|
320
|
+
}
|
|
321
|
+
return `{ ${typeEntries.join("; ")} }`;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Literalizes the `valueSet` entries slot — a core SQL entity kind (alongside
|
|
325
|
+
* `table`), not a pack-contributed one, so naming it here isn't a
|
|
326
|
+
* family→target layering leak. This is the only non-`table` entries slot with
|
|
327
|
+
* a type-level consumer (`db.nativeEnums`, `packages/3-extensions/postgres`):
|
|
328
|
+
* pack-contributed slots (`role`, `policy`, `native_enum`, …) have none and
|
|
329
|
+
* are not emitted.
|
|
330
|
+
*/
|
|
331
|
+
function generateValueSetBlockType(valueSets) {
|
|
332
|
+
return `{ ${Object.entries(valueSets).sort(([a], [b]) => a.localeCompare(b)).map(([name, valueSet]) => `readonly ${serializeObjectKey(name)}: ${serializeValue(valueSet)}`).join("; ")} }`;
|
|
333
|
+
}
|
|
334
|
+
function namespaceSerializedKind(ns) {
|
|
335
|
+
const kind = ns.kind;
|
|
336
|
+
if (kind === "schema") return `readonly kind: '${ns.id === UNBOUND_NAMESPACE_ID ? "postgres-unbound-schema" : "postgres-schema"}'`;
|
|
337
|
+
if (typeof kind === "string") return `readonly kind: ${serializeValue(kind)}`;
|
|
338
|
+
throw sqlEmitterError("CONTRACT.NAMESPACE_INVALID", `Namespace '${ns.id}' has no string kind — all namespaces must be target concretions with a defined kind property.`, {
|
|
339
|
+
why: "The namespace is not a target concretion, so the emitter cannot serialize its kind.",
|
|
340
|
+
fix: "Regenerate the contract with a target pack that materializes every namespace as a target concretion.",
|
|
341
|
+
meta: { namespace: ns.id }
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
function generateTableLiteralType(table) {
|
|
345
|
+
const columns = [];
|
|
346
|
+
for (const [colName, col] of Object.entries(table.columns)) {
|
|
347
|
+
const nullable = col.nullable ? "true" : "false";
|
|
348
|
+
const nativeType = serializeValue(col.nativeType);
|
|
349
|
+
const codecId = serializeValue(col.codecId);
|
|
350
|
+
const defaultSpec = col.default ? col.default.kind === "literal" ? `; readonly default: { readonly kind: 'literal'; readonly value: DefaultLiteralValue<${codecId}, ${serializeValue(col.default.value)}> }` : `; readonly default: { readonly kind: 'function'; readonly expression: ${serializeValue(col.default.expression)} }` : "";
|
|
351
|
+
const typeParamsSpec = col.typeParams && Object.keys(col.typeParams).length > 0 ? `; readonly typeParams: ${serializeTypeParamsLiteral(col.typeParams)}` : "";
|
|
352
|
+
const typeRefSpec = col.typeRef ? `; readonly typeRef: ${serializeValue(col.typeRef)}` : "";
|
|
353
|
+
columns.push(`readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable}${defaultSpec}${typeParamsSpec}${typeRefSpec} }`);
|
|
354
|
+
}
|
|
355
|
+
const tableParts = [`columns: { ${columns.join("; ")} }`];
|
|
356
|
+
if (table.primaryKey) {
|
|
357
|
+
const pkParts = [`readonly columns: readonly [${table.primaryKey.columns.map((c) => serializeValue(c)).join(", ")}]`];
|
|
358
|
+
if (table.primaryKey.name) pkParts.push(`readonly name: ${serializeValue(table.primaryKey.name)}`);
|
|
359
|
+
tableParts.push(`primaryKey: { ${pkParts.join("; ")} }`);
|
|
360
|
+
}
|
|
361
|
+
const uniques = table.uniques.map((u) => {
|
|
362
|
+
const parts = [`readonly columns: readonly [${u.columns.map((c) => serializeValue(c)).join(", ")}]`];
|
|
363
|
+
if (u.name) parts.push(`readonly name: ${serializeValue(u.name)}`);
|
|
364
|
+
return `{ ${parts.join("; ")} }`;
|
|
365
|
+
}).join(", ");
|
|
366
|
+
tableParts.push(`uniques: readonly [${uniques}]`);
|
|
367
|
+
const indexes = table.indexes.map((i) => {
|
|
368
|
+
const parts = [`readonly name: ${serializeValue(i.name)}`];
|
|
369
|
+
if (i.prefix !== void 0) parts.push(`readonly prefix: ${serializeValue(i.prefix)}`);
|
|
370
|
+
if (i.columns !== void 0) parts.push(`readonly columns: readonly [${i.columns.map((c) => serializeValue(c)).join(", ")}]`);
|
|
371
|
+
if (i.expression !== void 0) parts.push(`readonly expression: ${serializeValue(i.expression)}`);
|
|
372
|
+
if (i.where !== void 0) parts.push(`readonly where: ${serializeValue(i.where)}`);
|
|
373
|
+
parts.push(`readonly unique: ${i.unique}`);
|
|
374
|
+
if (i.type !== void 0) parts.push(`readonly type: ${serializeValue(i.type)}`);
|
|
375
|
+
if (i.options !== void 0) parts.push(`readonly options: ${serializeValue(i.options)}`);
|
|
376
|
+
return `{ ${parts.join("; ")} }`;
|
|
377
|
+
}).join(", ");
|
|
378
|
+
tableParts.push(`indexes: readonly [${indexes}]`);
|
|
379
|
+
const fks = table.foreignKeys.map((fk) => {
|
|
380
|
+
const srcCols = fk.source.columns.map((c) => serializeValue(c)).join(", ");
|
|
381
|
+
const tgtCols = fk.target.columns.map((c) => serializeValue(c)).join(", ");
|
|
382
|
+
const srcRef = `{ readonly namespaceId: ${serializeNamespaceId(String(fk.source.namespaceId))}; readonly tableName: ${serializeValue(fk.source.tableName)}; readonly columns: readonly [${srcCols}] }`;
|
|
383
|
+
const tgtRef = `{ readonly namespaceId: ${serializeNamespaceId(String(fk.target.namespaceId))}; readonly tableName: ${serializeValue(fk.target.tableName)}; readonly columns: readonly [${tgtCols}] }`;
|
|
384
|
+
const parts = [`readonly source: ${srcRef}`, `readonly target: ${tgtRef}`];
|
|
385
|
+
if (fk.name) parts.push(`readonly name: ${serializeValue(fk.name)}`);
|
|
386
|
+
return `{ ${parts.join("; ")} }`;
|
|
387
|
+
}).join(", ");
|
|
388
|
+
tableParts.push(`foreignKeys: readonly [${fks}]`);
|
|
389
|
+
return `{ ${tableParts.join("; ")} }`;
|
|
390
|
+
}
|
|
391
|
+
function generateTablesMapType(tables) {
|
|
392
|
+
const tableEntries = [];
|
|
393
|
+
for (const [tableName, table] of Object.entries(tables).sort(([a], [b]) => a.localeCompare(b))) tableEntries.push(`readonly ${tableName}: ${generateTableLiteralType(table)}`);
|
|
394
|
+
if (tableEntries.length === 0) return "{}";
|
|
395
|
+
return `{ ${tableEntries.join("; ")} }`;
|
|
396
|
+
}
|
|
397
|
+
function generateStorageNamespacesType(namespaces) {
|
|
398
|
+
const entries = Object.entries(namespaces ?? {}).sort(([a], [b]) => a.localeCompare(b));
|
|
399
|
+
if (entries.length === 0) return "Record<string, never>";
|
|
400
|
+
const parts = [];
|
|
401
|
+
for (const [name, ns] of entries) {
|
|
402
|
+
const kindSuffix = `; ${namespaceSerializedKind(ns)}`;
|
|
403
|
+
const entriesParts = [`readonly table: ${generateTablesMapType(ns.entries.table ?? {})}`];
|
|
404
|
+
const valueSetEntries = ns.entries.valueSet;
|
|
405
|
+
if (valueSetEntries !== void 0 && Object.keys(valueSetEntries).length > 0) entriesParts.push(`readonly valueSet: ${generateValueSetBlockType(valueSetEntries)}`);
|
|
406
|
+
const entriesType = `{ ${entriesParts.join("; ")} }`;
|
|
407
|
+
parts.push(`readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}${kindSuffix}; readonly entries: ${entriesType} }`);
|
|
408
|
+
}
|
|
409
|
+
return `{ ${parts.join("; ")} }`;
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
412
|
+
export { sqlEmission as t };
|
|
413
|
+
|
|
414
|
+
//# sourceMappingURL=dist-DrScXbhq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dist-DrScXbhq.mjs","names":[],"sources":["../../../../2-sql/3-tooling/emitter/dist/index.mjs"],"sourcesContent":["import { renderValueSetType, serializeNamespaceId, serializeObjectKey, serializeValue } from \"@internal/emitter/domain-type-generation\";\nimport { isSafeTypeExpression } from \"@internal/emitter/type-expression-safety\";\nimport { UNBOUND_NAMESPACE_ID, entityAt } from \"@internal/framework-components/ir\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { structuredError } from \"@internal/utils/structured-error\";\n//#region src/errors.ts\nfunction sqlEmitterError(code, message, options) {\n\treturn structuredError(code, message, options);\n}\nfunction sqlEmitterValidationError(message, meta) {\n\treturn sqlEmitterError(\"CONTRACT.VALIDATION_FAILED\", message, {\n\t\twhy: \"The contract given to the SQL emitter failed structural validation.\",\n\t\tfix: \"Regenerate the contract from its authoring source; do not hand-edit contract JSON.\",\n\t\tmeta\n\t});\n}\n//#endregion\n//#region src/index.ts\nfunction serializeTypeParamsLiteral(params) {\n\tif (!params || Object.keys(params).length === 0) return \"Record<string, never>\";\n\tconst entries = [];\n\tfor (const [key, value] of Object.entries(params)) entries.push(`readonly ${serializeObjectKey(key)}: ${serializeValue(value)}`);\n\treturn `{ ${entries.join(\"; \")} }`;\n}\nconst sqlEmission = {\n\tid: \"sql\",\n\tvalidateTypes(contract, _ctx) {\n\t\tconst storage = contract.storage;\n\t\tif (!storage?.namespaces) return;\n\t\tconst typeIdRegex = /^([^/]+)\\/([^@]+)@(\\d+)$/;\n\t\tfor (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const [colName, colUnknown] of Object.entries(table.columns)) {\n\t\t\tconst codecId = colUnknown.codecId;\n\t\t\tif (!codecId) throw sqlEmitterValidationError(`Column \"${colName}\" in table \"${tableName}\" is missing codecId`, {\n\t\t\t\ttable: tableName,\n\t\t\t\tcolumn: colName\n\t\t\t});\n\t\t\tif (!codecId.match(typeIdRegex)?.[1]) throw sqlEmitterValidationError(`Column \"${colName}\" in table \"${tableName}\" has invalid codec ID format \"${codecId}\". Expected format: ns/name@version`, {\n\t\t\t\ttable: tableName,\n\t\t\t\tcolumn: colName,\n\t\t\t\tcodecId\n\t\t\t});\n\t\t}\n\t},\n\tvalidateStructure(contract) {\n\t\tif (contract.targetFamily !== \"sql\") throw sqlEmitterValidationError(`Expected targetFamily \"sql\", got \"${contract.targetFamily}\"`, { targetFamily: contract.targetFamily });\n\t\tconst storage = contract.storage;\n\t\tif (!storage?.namespaces) throw sqlEmitterValidationError(\"SQL contract must have storage.namespaces\", {});\n\t\tconst tableNamesSeenAcrossNamespaces = /* @__PURE__ */ new Map();\n\t\tfor (const [nsId, ns] of Object.entries(storage.namespaces)) for (const tableName of Object.keys(ns.entries.table ?? {})) {\n\t\t\tconst existingNs = tableNamesSeenAcrossNamespaces.get(tableName);\n\t\t\tif (existingNs !== void 0 && existingNs !== nsId) throw sqlEmitterError(\"CONTRACT.NAME_DUPLICATE\", `Duplicate table name \"${tableName}\" in namespaces \"${existingNs}\" and \"${nsId}\"`, {\n\t\t\t\twhy: \"Two SQL namespaces declare a table with the same name, which is ambiguous for emission.\",\n\t\t\t\tfix: \"Rename one of the tables so every table name is unique across namespaces.\",\n\t\t\t\tmeta: {\n\t\t\t\t\ttable: tableName,\n\t\t\t\t\tnamespaces: [existingNs, nsId]\n\t\t\t\t}\n\t\t\t});\n\t\t\ttableNamesSeenAcrossNamespaces.set(tableName, nsId);\n\t\t}\n\t\tconst tableNames = /* @__PURE__ */ new Set();\n\t\tfor (const ns of Object.values(storage.namespaces)) for (const t of Object.keys(ns.entries.table ?? {})) tableNames.add(t);\n\t\tfor (const [namespaceId, domainNs] of Object.entries(contract.domain.namespaces)) {\n\t\t\tconst models = domainNs.models;\n\t\t\tfor (const [modelName, model] of Object.entries(models)) {\n\t\t\t\tconst qualifiedName = `${namespaceId}:${modelName}`;\n\t\t\t\tif (!model.storage?.table) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" is missing storage.table`, { model: qualifiedName });\n\t\t\t\tif (!model.storage.namespaceId) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" is missing storage.namespaceId`, { model: qualifiedName });\n\t\t\t\tif (model.storage.namespaceId !== namespaceId) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" storage.namespaceId \"${model.storage.namespaceId}\" does not match domain namespace \"${namespaceId}\"`, {\n\t\t\t\t\tmodel: qualifiedName,\n\t\t\t\t\tstorageNamespaceId: model.storage.namespaceId,\n\t\t\t\t\tdomainNamespaceId: namespaceId\n\t\t\t\t});\n\t\t\t\tconst tableName = model.storage.table;\n\t\t\t\tconst table = entityAt(storage, {\n\t\t\t\t\tnamespaceId,\n\t\t\t\t\tentityKind: \"table\",\n\t\t\t\t\tentityName: tableName\n\t\t\t\t});\n\t\t\t\tif (!table) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" references non-existent table \"${namespaceId}.${tableName}\"`, {\n\t\t\t\t\tmodel: qualifiedName,\n\t\t\t\t\ttable: `${namespaceId}.${tableName}`\n\t\t\t\t});\n\t\t\t\tconst columnNames = new Set(Object.keys(table.columns));\n\t\t\t\tconst storageFields = model.storage.fields;\n\t\t\t\tif (!storageFields || Object.keys(storageFields).length === 0) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" is missing storage.fields`, { model: qualifiedName });\n\t\t\t\tfor (const [fieldName, field] of Object.entries(storageFields)) {\n\t\t\t\t\tif (!field.column) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" field \"${fieldName}\" is missing column property`, {\n\t\t\t\t\t\tmodel: qualifiedName,\n\t\t\t\t\t\tfield: fieldName\n\t\t\t\t\t});\n\t\t\t\t\tif (!columnNames.has(field.column)) throw sqlEmitterValidationError(`Model \"${qualifiedName}\" field \"${fieldName}\" references non-existent column \"${field.column}\" in table \"${tableName}\"`, {\n\t\t\t\t\t\tmodel: qualifiedName,\n\t\t\t\t\t\tfield: fieldName,\n\t\t\t\t\t\tcolumn: field.column,\n\t\t\t\t\t\ttable: tableName\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (!model.relations || typeof model.relations !== \"object\") throw sqlEmitterValidationError(`Model \"${qualifiedName}\" is missing required field \"relations\" (must be an object)`, { model: qualifiedName });\n\t\t\t}\n\t\t}\n\t\tfor (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) {\n\t\t\tconst columnNames = new Set(Object.keys(table.columns));\n\t\t\tif (!Array.isArray(table.uniques)) throw sqlEmitterValidationError(`Table \"${tableName}\" is missing required field \"uniques\" (must be an array)`, { table: tableName });\n\t\t\tif (!Array.isArray(table.indexes)) throw sqlEmitterValidationError(`Table \"${tableName}\" is missing required field \"indexes\" (must be an array)`, { table: tableName });\n\t\t\tif (!Array.isArray(table.foreignKeys)) throw sqlEmitterValidationError(`Table \"${tableName}\" is missing required field \"foreignKeys\" (must be an array)`, { table: tableName });\n\t\t\tif (table.primaryKey) {\n\t\t\t\tfor (const colName of table.primaryKey.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`, {\n\t\t\t\t\ttable: tableName,\n\t\t\t\t\tcolumn: colName\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const unique of table.uniques) for (const colName of unique.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`, {\n\t\t\t\ttable: tableName,\n\t\t\t\tcolumn: colName\n\t\t\t});\n\t\t\tfor (const index of table.indexes) for (const colName of index.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table \"${tableName}\" index references non-existent column \"${colName}\"`, {\n\t\t\t\ttable: tableName,\n\t\t\t\tcolumn: colName\n\t\t\t});\n\t\t\tfor (const fk of table.foreignKeys) {\n\t\t\t\tfor (const colName of fk.source.columns) if (!columnNames.has(colName)) throw sqlEmitterValidationError(`Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`, {\n\t\t\t\t\ttable: tableName,\n\t\t\t\t\tcolumn: colName\n\t\t\t\t});\n\t\t\t\tconst referencedTable = entityAt(storage, {\n\t\t\t\t\tnamespaceId: fk.target.namespaceId,\n\t\t\t\t\tentityKind: \"table\",\n\t\t\t\t\tentityName: fk.target.tableName\n\t\t\t\t});\n\t\t\t\tif (!referencedTable) throw sqlEmitterValidationError(`Table \"${tableName}\" foreignKey references non-existent table \"${fk.target.tableName}\" in namespace \"${fk.target.namespaceId}\"`, {\n\t\t\t\t\ttable: tableName,\n\t\t\t\t\ttargetTable: fk.target.tableName,\n\t\t\t\t\ttargetNamespace: fk.target.namespaceId\n\t\t\t\t});\n\t\t\t\tconst referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n\t\t\t\tfor (const colName of fk.target.columns) if (!referencedColumnNames.has(colName)) throw sqlEmitterValidationError(`Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.target.tableName}\"`, {\n\t\t\t\t\ttable: tableName,\n\t\t\t\t\tcolumn: colName,\n\t\t\t\t\ttargetTable: fk.target.tableName\n\t\t\t\t});\n\t\t\t\tif (fk.source.columns.length !== fk.target.columns.length) throw sqlEmitterValidationError(`Table \"${tableName}\" foreignKey column count (${fk.source.columns.length}) does not match referenced column count (${fk.target.columns.length})`, {\n\t\t\t\t\ttable: tableName,\n\t\t\t\t\tsourceColumnCount: fk.source.columns.length,\n\t\t\t\t\ttargetColumnCount: fk.target.columns.length\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t},\n\tgenerateStorageType(contract, storageHashTypeName) {\n\t\tconst storage = contract.storage;\n\t\tconst namespacesType = generateStorageNamespacesType(storage.namespaces);\n\t\tconst docTypes = generateDocumentScopedStorageTypesType(storage.types);\n\t\treturn `{ readonly namespaces: ${namespacesType}${docTypes === void 0 ? \"\" : `; readonly types: ${docTypes}`}; readonly storageHash: ${storageHashTypeName} }`;\n\t},\n\tgenerateModelStorageType(_modelName, model) {\n\t\tconst sqlModel = model;\n\t\tconst tableName = sqlModel.storage.table;\n\t\tconst storageFields = sqlModel.storage.fields;\n\t\tconst storageParts = [`readonly table: ${serializeValue(tableName)}`, `readonly namespaceId: ${serializeValue(sqlModel.storage.namespaceId)}`];\n\t\tif (Object.keys(storageFields).length > 0) {\n\t\t\tconst fieldParts = [];\n\t\t\tfor (const [fieldName, field] of Object.entries(storageFields)) fieldParts.push(`readonly ${serializeObjectKey(fieldName)}: { readonly column: ${serializeValue(field.column)} }`);\n\t\t\tstorageParts.push(`readonly fields: { ${fieldParts.join(\"; \")} }`);\n\t\t}\n\t\treturn `{ ${storageParts.join(\"; \")} }`;\n\t},\n\tresolveFieldTypeParams(_modelName, fieldName, model, contract) {\n\t\tconst sqlModel = model;\n\t\tconst storageField = sqlModel.storage?.fields?.[fieldName];\n\t\tif (!storageField) return void 0;\n\t\tconst storage = contract.storage;\n\t\tif (!storage) return void 0;\n\t\tconst tableName = sqlModel.storage.table;\n\t\tconst storageNamespaceId = sqlModel.storage.namespaceId;\n\t\tif (!storageNamespaceId) return void 0;\n\t\tconst table = entityAt(storage, {\n\t\t\tnamespaceId: storageNamespaceId,\n\t\t\tentityKind: \"table\",\n\t\t\tentityName: tableName\n\t\t});\n\t\tif (!table) return void 0;\n\t\tconst column = table.columns[storageField.column];\n\t\tif (!column) return void 0;\n\t\tif (column.typeRef) {\n\t\t\tconst typeInstance = storage.types?.[column.typeRef];\n\t\t\tif (typeInstance === void 0) return void 0;\n\t\t\treturn typeInstance.typeParams;\n\t\t}\n\t\treturn column.typeParams;\n\t},\n\tresolveFieldValueSet(_modelName, fieldName, model, contract) {\n\t\tconst sqlModel = blindCast(model);\n\t\tconst storageField = sqlModel.storage?.fields?.[fieldName];\n\t\tif (!storageField) return void 0;\n\t\tconst storage = blindCast(contract.storage);\n\t\tif (!storage) return void 0;\n\t\tconst storageNamespaceId = sqlModel.storage.namespaceId;\n\t\tif (!storageNamespaceId) return void 0;\n\t\tconst column = entityAt(storage, {\n\t\t\tnamespaceId: storageNamespaceId,\n\t\t\tentityKind: \"table\",\n\t\t\tentityName: sqlModel.storage.table\n\t\t})?.columns[storageField.column];\n\t\tif (!column?.valueSet) return void 0;\n\t\tconst valueSet = entityAt(storage, {\n\t\t\tnamespaceId: column.valueSet.namespaceId,\n\t\t\tentityKind: column.valueSet.entityKind,\n\t\t\tentityName: column.valueSet.entityName\n\t\t});\n\t\tif (!valueSet) return void 0;\n\t\treturn {\n\t\t\tencodedValues: valueSet.values,\n\t\t\tcodecId: column.codecId\n\t\t};\n\t},\n\tgetStorageTypeExports(contract, codecLookup) {\n\t\tconst storage = blindCast(contract.storage);\n\t\tif (!storage?.namespaces) return void 0;\n\t\tconst outputMap = generateStorageColumnTypesMap(storage, \"output\", codecLookup);\n\t\tconst inputMap = generateStorageColumnTypesMap(storage, \"input\", codecLookup);\n\t\treturn [`export type StorageColumnTypes = ${outputMap};`, `export type StorageColumnInputTypes = ${inputMap};`].join(\"\\n\");\n\t},\n\tgetFamilyImports(resolveImportSpecifier) {\n\t\treturn [\n\t\t\t\"import type {\",\n\t\t\t\" ContractWithTypeMaps,\",\n\t\t\t\" TypeMaps as TypeMapsType,\",\n\t\t\t`} from '${resolveImportSpecifier(\"@internal/sql-contract/types\")}';`\n\t\t];\n\t},\n\tgetFamilyTypeAliases(options) {\n\t\tconst queryOperationAliases = (options?.queryOperationTypeImports ?? []).filter((imp) => imp.named === \"QueryOperationTypes\").map((imp) => `${imp.alias}<CodecTypes>`);\n\t\treturn [\n\t\t\t\"export type LaneCodecTypes = CodecTypes;\",\n\t\t\t`export type QueryOperationTypes = ${queryOperationAliases.length > 0 ? queryOperationAliases.join(\" & \") : \"Record<string, never>\"};`,\n\t\t\t\"type DefaultLiteralValue<CodecId extends string, Encoded> =\",\n\t\t\t\" CodecId extends keyof CodecTypes\",\n\t\t\t\" ? Encoded extends CodecTypes[CodecId]['json']\",\n\t\t\t\" ? Encoded\",\n\t\t\t\" : CodecTypes[CodecId]['json']\",\n\t\t\t\" : Encoded;\"\n\t\t].join(\"\\n\");\n\t},\n\tgetTypeMapsExpression() {\n\t\treturn \"TypeMapsType<CodecTypes, QueryOperationTypes, FieldOutputTypes, FieldInputTypes, StorageColumnTypes, StorageColumnInputTypes>\";\n\t},\n\tgetContractWrapper(contractBaseName, typeMapsName) {\n\t\treturn [\n\t\t\t`export type Contract = ContractWithTypeMaps<${contractBaseName}, ${typeMapsName}>;`,\n\t\t\t\"\",\n\t\t\t\"export type Namespaces = Contract['storage']['namespaces'];\"\n\t\t].join(\"\\n\");\n\t}\n};\nfunction columnTypeParams(storage, column) {\n\tif (column.typeRef) {\n\t\tconst typeInstance = storage.types?.[column.typeRef];\n\t\tif (typeInstance === void 0) return void 0;\n\t\treturn blindCast(typeInstance).typeParams;\n\t}\n\treturn column.typeParams;\n}\nfunction renderRefinedCodecType(column, side, params, codecLookup) {\n\tif (codecLookup && params && Object.keys(params).length > 0) {\n\t\tconst rendered = side === \"output\" ? codecLookup.renderOutputTypeFor(column.codecId, params) : codecLookup.renderInputTypeFor?.(column.codecId, params);\n\t\tif (rendered && isSafeTypeExpression(rendered)) return rendered;\n\t}\n\treturn `CodecTypes[${serializeValue(column.codecId)}][${serializeValue(side)}]`;\n}\nfunction computeColumnType(storage, column, side, codecLookup) {\n\tlet base;\n\tif (column.valueSet) {\n\t\tconst valueSet = entityAt(storage, {\n\t\t\tnamespaceId: column.valueSet.namespaceId,\n\t\t\tentityKind: column.valueSet.entityKind,\n\t\t\tentityName: column.valueSet.entityName\n\t\t});\n\t\tbase = valueSet ? renderValueSetType(valueSet.values, column.codecId, side, codecLookup) : void 0;\n\t}\n\tif (base === void 0) base = renderRefinedCodecType(column, side, columnTypeParams(storage, column), codecLookup);\n\tif (column.many === true) base = `ReadonlyArray<${base}>`;\n\treturn column.nullable ? `${base} | null` : base;\n}\nfunction generateStorageColumnTypesMap(storage, side, codecLookup) {\n\tconst namespaceEntries = Object.entries(storage.namespaces ?? {}).sort(([a], [b]) => a.localeCompare(b));\n\tif (namespaceEntries.length === 0) return \"Record<string, never>\";\n\tconst nsParts = [];\n\tfor (const [nsId, ns] of namespaceEntries) {\n\t\tconst tables = blindCast(ns.entries.table ?? {});\n\t\tconst tableEntries = Object.entries(tables).sort(([a], [b]) => a.localeCompare(b));\n\t\tconst tableParts = [];\n\t\tfor (const [tableName, table] of tableEntries) {\n\t\t\tconst colEntries = Object.entries(table.columns).sort(([a], [b]) => a.localeCompare(b));\n\t\t\tconst colParts = [];\n\t\t\tfor (const [colName, col] of colEntries) {\n\t\t\t\tconst colType = computeColumnType(storage, col, side, codecLookup);\n\t\t\t\tcolParts.push(`readonly ${serializeObjectKey(colName)}: ${colType}`);\n\t\t\t}\n\t\t\tconst colMap = colParts.length > 0 ? `{ ${colParts.join(\"; \")} }` : \"{}\";\n\t\t\ttableParts.push(`readonly ${serializeObjectKey(tableName)}: ${colMap}`);\n\t\t}\n\t\tconst tableMap = tableParts.length > 0 ? `{ ${tableParts.join(\"; \")} }` : \"{}\";\n\t\tnsParts.push(`readonly ${serializeObjectKey(nsId)}: ${tableMap}`);\n\t}\n\treturn `{ ${nsParts.join(\"; \")} }`;\n}\nfunction generateDocumentScopedStorageTypesType(types) {\n\tif (!types || Object.keys(types).length === 0) return;\n\tconst typeEntries = [];\n\tfor (const [typeName, typeInstance] of Object.entries(types)) {\n\t\tconst codecInstanceShape = typeInstance;\n\t\tif (typeof codecInstanceShape.codecId !== \"string\" || typeof codecInstanceShape.nativeType !== \"string\") throw sqlEmitterError(\"CONTRACT.TYPE_UNKNOWN\", `Unknown storage type kind for \"${typeName}\" in document-scoped storage.types; expected a codec-instance triple.`, {\n\t\t\twhy: \"A storage.types entry is not a codec-instance triple, so its column type cannot be emitted.\",\n\t\t\tfix: \"Regenerate the contract from its authoring source; storage.types entries must carry codecId and nativeType.\",\n\t\t\tmeta: { type: typeName }\n\t\t});\n\t\tconst codecId = serializeValue(codecInstanceShape.codecId);\n\t\tconst nativeType = serializeValue(codecInstanceShape.nativeType);\n\t\tconst typeParamsStr = serializeTypeParamsLiteral(codecInstanceShape.typeParams);\n\t\ttypeEntries.push(`readonly ${typeName}: { readonly kind: 'codec-instance'; readonly codecId: ${codecId}; readonly nativeType: ${nativeType}; readonly typeParams: ${typeParamsStr} }`);\n\t}\n\treturn `{ ${typeEntries.join(\"; \")} }`;\n}\n/**\n* Literalizes the `valueSet` entries slot — a core SQL entity kind (alongside\n* `table`), not a pack-contributed one, so naming it here isn't a\n* family→target layering leak. This is the only non-`table` entries slot with\n* a type-level consumer (`db.nativeEnums`, `packages/3-extensions/postgres`):\n* pack-contributed slots (`role`, `policy`, `native_enum`, …) have none and\n* are not emitted.\n*/\nfunction generateValueSetBlockType(valueSets) {\n\treturn `{ ${Object.entries(valueSets).sort(([a], [b]) => a.localeCompare(b)).map(([name, valueSet]) => `readonly ${serializeObjectKey(name)}: ${serializeValue(valueSet)}`).join(\"; \")} }`;\n}\nfunction namespaceSerializedKind(ns) {\n\tconst kind = ns.kind;\n\tif (kind === \"schema\") return `readonly kind: '${ns.id === UNBOUND_NAMESPACE_ID ? \"postgres-unbound-schema\" : \"postgres-schema\"}'`;\n\tif (typeof kind === \"string\") return `readonly kind: ${serializeValue(kind)}`;\n\tthrow sqlEmitterError(\"CONTRACT.NAMESPACE_INVALID\", `Namespace '${ns.id}' has no string kind — all namespaces must be target concretions with a defined kind property.`, {\n\t\twhy: \"The namespace is not a target concretion, so the emitter cannot serialize its kind.\",\n\t\tfix: \"Regenerate the contract with a target pack that materializes every namespace as a target concretion.\",\n\t\tmeta: { namespace: ns.id }\n\t});\n}\nfunction generateTableLiteralType(table) {\n\tconst columns = [];\n\tfor (const [colName, col] of Object.entries(table.columns)) {\n\t\tconst nullable = col.nullable ? \"true\" : \"false\";\n\t\tconst nativeType = serializeValue(col.nativeType);\n\t\tconst codecId = serializeValue(col.codecId);\n\t\tconst defaultSpec = col.default ? col.default.kind === \"literal\" ? `; readonly default: { readonly kind: 'literal'; readonly value: DefaultLiteralValue<${codecId}, ${serializeValue(col.default.value)}> }` : `; readonly default: { readonly kind: 'function'; readonly expression: ${serializeValue(col.default.expression)} }` : \"\";\n\t\tconst typeParamsSpec = col.typeParams && Object.keys(col.typeParams).length > 0 ? `; readonly typeParams: ${serializeTypeParamsLiteral(col.typeParams)}` : \"\";\n\t\tconst typeRefSpec = col.typeRef ? `; readonly typeRef: ${serializeValue(col.typeRef)}` : \"\";\n\t\tcolumns.push(`readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable}${defaultSpec}${typeParamsSpec}${typeRefSpec} }`);\n\t}\n\tconst tableParts = [`columns: { ${columns.join(\"; \")} }`];\n\tif (table.primaryKey) {\n\t\tconst pkParts = [`readonly columns: readonly [${table.primaryKey.columns.map((c) => serializeValue(c)).join(\", \")}]`];\n\t\tif (table.primaryKey.name) pkParts.push(`readonly name: ${serializeValue(table.primaryKey.name)}`);\n\t\ttableParts.push(`primaryKey: { ${pkParts.join(\"; \")} }`);\n\t}\n\tconst uniques = table.uniques.map((u) => {\n\t\tconst parts = [`readonly columns: readonly [${u.columns.map((c) => serializeValue(c)).join(\", \")}]`];\n\t\tif (u.name) parts.push(`readonly name: ${serializeValue(u.name)}`);\n\t\treturn `{ ${parts.join(\"; \")} }`;\n\t}).join(\", \");\n\ttableParts.push(`uniques: readonly [${uniques}]`);\n\tconst indexes = table.indexes.map((i) => {\n\t\tconst parts = [`readonly name: ${serializeValue(i.name)}`];\n\t\tif (i.prefix !== void 0) parts.push(`readonly prefix: ${serializeValue(i.prefix)}`);\n\t\tif (i.columns !== void 0) parts.push(`readonly columns: readonly [${i.columns.map((c) => serializeValue(c)).join(\", \")}]`);\n\t\tif (i.expression !== void 0) parts.push(`readonly expression: ${serializeValue(i.expression)}`);\n\t\tif (i.where !== void 0) parts.push(`readonly where: ${serializeValue(i.where)}`);\n\t\tparts.push(`readonly unique: ${i.unique}`);\n\t\tif (i.type !== void 0) parts.push(`readonly type: ${serializeValue(i.type)}`);\n\t\tif (i.options !== void 0) parts.push(`readonly options: ${serializeValue(i.options)}`);\n\t\treturn `{ ${parts.join(\"; \")} }`;\n\t}).join(\", \");\n\ttableParts.push(`indexes: readonly [${indexes}]`);\n\tconst fks = table.foreignKeys.map((fk) => {\n\t\tconst srcCols = fk.source.columns.map((c) => serializeValue(c)).join(\", \");\n\t\tconst tgtCols = fk.target.columns.map((c) => serializeValue(c)).join(\", \");\n\t\tconst srcRef = `{ readonly namespaceId: ${serializeNamespaceId(String(fk.source.namespaceId))}; readonly tableName: ${serializeValue(fk.source.tableName)}; readonly columns: readonly [${srcCols}] }`;\n\t\tconst tgtRef = `{ readonly namespaceId: ${serializeNamespaceId(String(fk.target.namespaceId))}; readonly tableName: ${serializeValue(fk.target.tableName)}; readonly columns: readonly [${tgtCols}] }`;\n\t\tconst parts = [`readonly source: ${srcRef}`, `readonly target: ${tgtRef}`];\n\t\tif (fk.name) parts.push(`readonly name: ${serializeValue(fk.name)}`);\n\t\treturn `{ ${parts.join(\"; \")} }`;\n\t}).join(\", \");\n\ttableParts.push(`foreignKeys: readonly [${fks}]`);\n\treturn `{ ${tableParts.join(\"; \")} }`;\n}\nfunction generateTablesMapType(tables) {\n\tconst tableEntries = [];\n\tfor (const [tableName, table] of Object.entries(tables).sort(([a], [b]) => a.localeCompare(b))) tableEntries.push(`readonly ${tableName}: ${generateTableLiteralType(table)}`);\n\tif (tableEntries.length === 0) return \"{}\";\n\treturn `{ ${tableEntries.join(\"; \")} }`;\n}\nfunction generateStorageNamespacesType(namespaces) {\n\tconst entries = Object.entries(namespaces ?? {}).sort(([a], [b]) => a.localeCompare(b));\n\tif (entries.length === 0) return \"Record<string, never>\";\n\tconst parts = [];\n\tfor (const [name, ns] of entries) {\n\t\tconst kindSuffix = `; ${namespaceSerializedKind(ns)}`;\n\t\tconst entriesParts = [`readonly table: ${generateTablesMapType(ns.entries.table ?? {})}`];\n\t\tconst valueSetEntries = ns.entries.valueSet;\n\t\tif (valueSetEntries !== void 0 && Object.keys(valueSetEntries).length > 0) entriesParts.push(`readonly valueSet: ${generateValueSetBlockType(valueSetEntries)}`);\n\t\tconst entriesType = `{ ${entriesParts.join(\"; \")} }`;\n\t\tparts.push(`readonly ${serializeObjectKey(name)}: { readonly id: ${serializeValue(ns.id)}${kindSuffix}; readonly entries: ${entriesType} }`);\n\t}\n\treturn `{ ${parts.join(\"; \")} }`;\n}\n//#endregion\nexport { sqlEmission };\n\n//# sourceMappingURL=index.mjs.map"],"mappings":";;;;;;AAMA,SAAS,gBAAgB,MAAM,SAAS,SAAS;CAChD,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC9C;AACA,SAAS,0BAA0B,SAAS,MAAM;CACjD,OAAO,gBAAgB,8BAA8B,SAAS;EAC7D,KAAK;EACL,KAAK;EACL;CACD,CAAC;AACF;AAGA,SAAS,2BAA2B,QAAQ;CAC3C,IAAI,CAAC,UAAU,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW,GAAG,OAAO;CACxD,MAAM,UAAU,CAAC;CACjB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG,QAAQ,KAAK,YAAY,mBAAmB,GAAG,EAAE,IAAI,eAAe,KAAK,GAAG;CAC/H,OAAO,KAAK,QAAQ,KAAK,IAAI,EAAE;AAChC;AACA,MAAM,cAAc;CACnB,IAAI;CACJ,cAAc,UAAU,MAAM;EAC7B,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,SAAS,YAAY;EAC1B,MAAM,cAAc;EACpB,KAAK,MAAM,MAAM,OAAO,OAAO,QAAQ,UAAU,GAAG,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,GAAG,QAAQ,SAAS,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,SAAS,eAAe,OAAO,QAA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;EAC/J,MAAM,cAAc,KAAK,aAAa,KAAK,IAAI,EAAE;EACjD,MAAM,KAAK,YAAY,mBAAmB,IAAI,EAAE,mBAAmB,eAAe,GAAG,EAAE,IAAI,WAAW,sBAAsB,YAAY,GAAG;CAC5I;CACA,OAAO,KAAK,MAAM,KAAK,IAAI,EAAE;AAC9B"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region ../../../2-sql/1-core/errors/dist/index.mjs
|
|
2
|
+
/**
|
|
3
|
+
* SQL query error for query-related failures (syntax errors, constraint violations, permissions).
|
|
4
|
+
*/
|
|
5
|
+
var SqlQueryError = class SqlQueryError extends Error {
|
|
6
|
+
static ERROR_NAME = "SqlQueryError";
|
|
7
|
+
kind = "sql_query";
|
|
8
|
+
sqlState;
|
|
9
|
+
constraint;
|
|
10
|
+
table;
|
|
11
|
+
column;
|
|
12
|
+
detail;
|
|
13
|
+
constructor(message, options) {
|
|
14
|
+
super(message, { cause: options?.cause });
|
|
15
|
+
this.name = SqlQueryError.ERROR_NAME;
|
|
16
|
+
this.sqlState = options?.sqlState;
|
|
17
|
+
this.constraint = options?.constraint;
|
|
18
|
+
this.table = options?.table;
|
|
19
|
+
this.column = options?.column;
|
|
20
|
+
this.detail = options?.detail;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Type predicate to check if an error is a SqlQueryError.
|
|
24
|
+
*/
|
|
25
|
+
static is(error) {
|
|
26
|
+
return typeof error === "object" && error !== null && Object.hasOwn(error, "kind") && error.kind === "sql_query";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* SQLSTATE for a unique-constraint / primary-key violation — the SQL-standard
|
|
31
|
+
* `unique_violation` class. Drivers normalize their target-specific codes (e.g.
|
|
32
|
+
* Postgres `23505`, SQLite `SQLITE_CONSTRAINT_UNIQUE`/`PRIMARYKEY`) onto this
|
|
33
|
+
* value on {@link SqlQueryError.sqlState}, so consumers classify violations
|
|
34
|
+
* without knowing any target-specific error shape.
|
|
35
|
+
*/
|
|
36
|
+
const UNIQUE_VIOLATION_SQLSTATE = "23505";
|
|
37
|
+
/**
|
|
38
|
+
* Whether an error is a unique-constraint (or primary-key) violation, decided
|
|
39
|
+
* solely from the driver-normalized {@link SqlQueryError.sqlState}. Raw driver
|
|
40
|
+
* errors that were never normalized are not classified — callers run behind the
|
|
41
|
+
* driver, which always normalizes before the error escapes.
|
|
42
|
+
*/
|
|
43
|
+
function isUniqueConstraintViolation(error) {
|
|
44
|
+
return SqlQueryError.is(error) && error.sqlState === "23505";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* SQL connection error (timeouts, connection resets, etc.).
|
|
48
|
+
*/
|
|
49
|
+
var SqlConnectionError = class SqlConnectionError extends Error {
|
|
50
|
+
static ERROR_NAME = "SqlConnectionError";
|
|
51
|
+
kind = "sql_connection";
|
|
52
|
+
transient;
|
|
53
|
+
constructor(message, options) {
|
|
54
|
+
super(message, { cause: options?.cause });
|
|
55
|
+
this.name = SqlConnectionError.ERROR_NAME;
|
|
56
|
+
this.transient = options?.transient;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type predicate to check if an error is a SqlConnectionError.
|
|
60
|
+
*/
|
|
61
|
+
static is(error) {
|
|
62
|
+
return typeof error === "object" && error !== null && Object.hasOwn(error, "kind") && error.kind === "sql_connection";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { isUniqueConstraintViolation as i, SqlQueryError as n, UNIQUE_VIOLATION_SQLSTATE as r, SqlConnectionError as t };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=dist-x6jvtkKM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dist-x6jvtkKM.mjs","names":[],"sources":["../../../../2-sql/1-core/errors/dist/index.mjs"],"sourcesContent":["//#region src/errors.ts\n/**\n* SQL query error for query-related failures (syntax errors, constraint violations, permissions).\n*/\nvar SqlQueryError = class SqlQueryError extends Error {\n\tstatic ERROR_NAME = \"SqlQueryError\";\n\tkind = \"sql_query\";\n\tsqlState;\n\tconstraint;\n\ttable;\n\tcolumn;\n\tdetail;\n\tconstructor(message, options) {\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.name = SqlQueryError.ERROR_NAME;\n\t\tthis.sqlState = options?.sqlState;\n\t\tthis.constraint = options?.constraint;\n\t\tthis.table = options?.table;\n\t\tthis.column = options?.column;\n\t\tthis.detail = options?.detail;\n\t}\n\t/**\n\t* Type predicate to check if an error is a SqlQueryError.\n\t*/\n\tstatic is(error) {\n\t\treturn typeof error === \"object\" && error !== null && Object.hasOwn(error, \"kind\") && error.kind === \"sql_query\";\n\t}\n};\n/**\n* SQLSTATE for a unique-constraint / primary-key violation — the SQL-standard\n* `unique_violation` class. Drivers normalize their target-specific codes (e.g.\n* Postgres `23505`, SQLite `SQLITE_CONSTRAINT_UNIQUE`/`PRIMARYKEY`) onto this\n* value on {@link SqlQueryError.sqlState}, so consumers classify violations\n* without knowing any target-specific error shape.\n*/\nconst UNIQUE_VIOLATION_SQLSTATE = \"23505\";\n/**\n* Whether an error is a unique-constraint (or primary-key) violation, decided\n* solely from the driver-normalized {@link SqlQueryError.sqlState}. Raw driver\n* errors that were never normalized are not classified — callers run behind the\n* driver, which always normalizes before the error escapes.\n*/\nfunction isUniqueConstraintViolation(error) {\n\treturn SqlQueryError.is(error) && error.sqlState === \"23505\";\n}\n/**\n* SQL connection error (timeouts, connection resets, etc.).\n*/\nvar SqlConnectionError = class SqlConnectionError extends Error {\n\tstatic ERROR_NAME = \"SqlConnectionError\";\n\tkind = \"sql_connection\";\n\ttransient;\n\tconstructor(message, options) {\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.name = SqlConnectionError.ERROR_NAME;\n\t\tthis.transient = options?.transient;\n\t}\n\t/**\n\t* Type predicate to check if an error is a SqlConnectionError.\n\t*/\n\tstatic is(error) {\n\t\treturn typeof error === \"object\" && error !== null && Object.hasOwn(error, \"kind\") && error.kind === \"sql_connection\";\n\t}\n};\n//#endregion\nexport { SqlConnectionError, SqlQueryError, UNIQUE_VIOLATION_SQLSTATE, isUniqueConstraintViolation };\n\n//# sourceMappingURL=index.mjs.map"],"mappings":";;;;AAIA,IAAI,gBAAgB,MAAM,sBAAsB,MAAM;CACrD,OAAO,aAAa;CACpB,OAAO;CACP;CACA;CACA;CACA;CACA;CACA,YAAY,SAAS,SAAS;EAC7B,MAAM,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC;EACxC,KAAK,OAAO,cAAc;EAC1B,KAAK,WAAW,SAAS;EACzB,KAAK,aAAa,SAAS;EAC3B,KAAK,QAAQ,SAAS;EACtB,KAAK,SAAS,SAAS;EACvB,KAAK,SAAS,SAAS;CACxB;;;;CAIA,OAAO,GAAG,OAAO;EAChB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,OAAO,OAAO,MAAM,KAAK,MAAM,SAAS;CACtG;AACD;;;;;;;;AAQA,MAAM,4BAA4B;;;;;;;AAOlC,SAAS,4BAA4B,OAAO;CAC3C,OAAO,cAAc,GAAG,KAAK,KAAK,MAAM,aAAa;AACtD;;;;AAIA,IAAI,qBAAqB,MAAM,2BAA2B,MAAM;CAC/D,OAAO,aAAa;CACpB,OAAO;CACP;CACA,YAAY,SAAS,SAAS;EAC7B,MAAM,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC;EACxC,KAAK,OAAO,mBAAmB;EAC/B,KAAK,YAAY,SAAS;CAC3B;;;;CAIA,OAAO,GAAG,OAAO;EAChB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,OAAO,OAAO,MAAM,KAAK,MAAM,SAAS;CACtG;AACD"}
|