@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,1316 @@
|
|
|
1
|
+
import { a as CodecRef$1 } from "./codec-types-MOaceoPi-C5eL2sao.mjs";
|
|
2
|
+
import { a as StorageTable, r as StorageColumn } from "./storage-table-BBaAmanc-BwR37LMA.mjs";
|
|
3
|
+
import { c as SqlStorage } from "./sql-storage-B0QwiTg6-B8DVctJm.mjs";
|
|
4
|
+
import { a as ExtractCodecTypes, c as ExtractQueryOperationTypes, s as ExtractFieldOutputTypes } from "./types-CuDrWc5v-ISVXBmBs.mjs";
|
|
5
|
+
import "./types-BchwQpmO.mjs";
|
|
6
|
+
import { a as AndExpr, h as BinaryExpr, it as OrderByItem, o as AnyExpression, rt as OrExpr, tt as NullCheckExpr, yt as WhereArg } from "./types-DIBA80mc-wf5wLmON.mjs";
|
|
7
|
+
import "./ast-DSuzmsWn.mjs";
|
|
8
|
+
import { a as Expression } from "./expression-DIf8F4Mc.mjs";
|
|
9
|
+
import { r as ExecutionContext } from "./query-lane-context-DtdVMqoz-C2Tj5QHA.mjs";
|
|
10
|
+
import "./query-lane-context-Bz8XJZ45.mjs";
|
|
11
|
+
import { o as ComputeColumnJsType, y as RuntimeScope } from "./types-Dl20lxky-DC_jdA0T.mjs";
|
|
12
|
+
import "./types-DMxc5KZa.mjs";
|
|
13
|
+
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
14
|
+
import { AnnotationValue, AsyncIterableResult, MetaBuilder, OperationKind } from "@prisma/orm-framework/components/runtime";
|
|
15
|
+
import { SimplifyDeep } from "@prisma/orm-framework/utils/simplify-deep";
|
|
16
|
+
//#region ../../../3-extensions/sql-orm-client/dist/index.d.mts
|
|
17
|
+
//#region src/types.d.ts
|
|
18
|
+
type AggregateFn = 'count' | 'sum' | 'avg' | 'min' | 'max';
|
|
19
|
+
interface IncludeScalar<Result> extends RowSelection<Result> {
|
|
20
|
+
readonly kind: 'includeScalar';
|
|
21
|
+
readonly fn: AggregateFn;
|
|
22
|
+
readonly column?: string;
|
|
23
|
+
readonly state: CollectionState;
|
|
24
|
+
}
|
|
25
|
+
interface IncludeRowsBranch {
|
|
26
|
+
readonly kind: 'rows';
|
|
27
|
+
readonly state: CollectionState;
|
|
28
|
+
}
|
|
29
|
+
interface IncludeScalarBranch {
|
|
30
|
+
readonly kind: 'scalar';
|
|
31
|
+
readonly selector: IncludeScalar<unknown>;
|
|
32
|
+
}
|
|
33
|
+
type IncludeCombineBranch = IncludeRowsBranch | IncludeScalarBranch;
|
|
34
|
+
interface IncludeCombine<ResultShape extends Record<string, unknown>> extends RowSelection<ResultShape> {
|
|
35
|
+
readonly kind: 'includeCombine';
|
|
36
|
+
readonly branches: Readonly<Record<string, IncludeCombineBranch>>;
|
|
37
|
+
}
|
|
38
|
+
interface IncludeThroughDescriptor {
|
|
39
|
+
readonly table: string;
|
|
40
|
+
/** Namespace the junction table lives in, as declared in the contract. */
|
|
41
|
+
readonly namespaceId: string;
|
|
42
|
+
/** FK columns in the junction table that point to the parent. */
|
|
43
|
+
readonly parentColumns: readonly string[];
|
|
44
|
+
/** FK columns in the junction table that point to the target (child). */
|
|
45
|
+
readonly childColumns: readonly string[];
|
|
46
|
+
/** PK columns in the target table that the junction's childColumns reference. */
|
|
47
|
+
readonly targetColumns: readonly string[];
|
|
48
|
+
/** Resolved column names in the parent table that junction.parentColumns reference. */
|
|
49
|
+
readonly parentLocalColumns: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
interface IncludeExpr {
|
|
52
|
+
readonly relationName: string;
|
|
53
|
+
readonly relatedModelName: string;
|
|
54
|
+
readonly relatedNamespaceId: string;
|
|
55
|
+
readonly relatedTableName: string;
|
|
56
|
+
readonly localTableName: string;
|
|
57
|
+
readonly targetColumn: string;
|
|
58
|
+
readonly localColumn: string;
|
|
59
|
+
readonly cardinality: RelationCardinalityTag | undefined;
|
|
60
|
+
readonly through?: IncludeThroughDescriptor;
|
|
61
|
+
readonly nested: CollectionState;
|
|
62
|
+
readonly scalar: IncludeScalar<unknown> | undefined;
|
|
63
|
+
readonly combine: Readonly<Record<string, IncludeCombineBranch>> | undefined;
|
|
64
|
+
}
|
|
65
|
+
interface CollectionState {
|
|
66
|
+
readonly filters: readonly AnyExpression[];
|
|
67
|
+
readonly includes: readonly IncludeExpr[];
|
|
68
|
+
readonly orderBy: readonly OrderByItem[] | undefined;
|
|
69
|
+
readonly cursor: Readonly<Record<string, unknown>> | undefined;
|
|
70
|
+
readonly distinct: readonly string[] | undefined;
|
|
71
|
+
readonly distinctOn: readonly string[] | undefined;
|
|
72
|
+
readonly selectedFields: readonly string[] | undefined;
|
|
73
|
+
readonly limit: number | undefined;
|
|
74
|
+
readonly offset: number | undefined;
|
|
75
|
+
readonly variantName: string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Annotations attached to this query at terminal-call time.
|
|
78
|
+
* Populated transiently by terminal methods (`first`, `all`, `create`,
|
|
79
|
+
* etc.) just before dispatch — `Collection` itself has no chainable
|
|
80
|
+
* `.annotate()`. Stored as a `Map<namespace, AnnotationValue>` so
|
|
81
|
+
* duplicate namespaces last-write-win. Empty on a fresh state.
|
|
82
|
+
*/
|
|
83
|
+
readonly annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;
|
|
84
|
+
}
|
|
85
|
+
declare function emptyState(): CollectionState;
|
|
86
|
+
interface CollectionTypeState {
|
|
87
|
+
readonly hasOrderBy: boolean;
|
|
88
|
+
readonly hasWhere: boolean;
|
|
89
|
+
readonly hasUniqueFilter: boolean;
|
|
90
|
+
readonly variantName: string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The namespace coordinate this collection resolves at — set by the
|
|
93
|
+
* `orm.<ns>.<Model>` facet so the create/update/where input types (and the
|
|
94
|
+
* read row) resolve the model's fields within its namespace. `never` for a
|
|
95
|
+
* directly-constructed collection (resolution falls back to the model's own
|
|
96
|
+
* `storage.namespaceId`). Carried in the type state so it survives chaining
|
|
97
|
+
* (`.where(...)`, `.variant(...)`, …) automatically.
|
|
98
|
+
*/
|
|
99
|
+
readonly nsId: string;
|
|
100
|
+
}
|
|
101
|
+
type RelationCardinalityTag = '1:1' | 'N:1' | '1:N' | 'N:M';
|
|
102
|
+
type DefaultCollectionTypeState = {
|
|
103
|
+
readonly hasOrderBy: false;
|
|
104
|
+
readonly hasWhere: false;
|
|
105
|
+
readonly hasUniqueFilter: false;
|
|
106
|
+
readonly variantName: undefined;
|
|
107
|
+
readonly nsId: never;
|
|
108
|
+
};
|
|
109
|
+
type WithNsId<State extends CollectionTypeState, NsId extends string> = Omit<State, 'nsId'> & {
|
|
110
|
+
readonly nsId: NsId;
|
|
111
|
+
};
|
|
112
|
+
interface RuntimeConnection extends RuntimeScope {
|
|
113
|
+
release?(): Promise<void>;
|
|
114
|
+
transaction?(): Promise<RuntimeTransaction>;
|
|
115
|
+
}
|
|
116
|
+
interface RuntimeTransaction extends RuntimeScope {
|
|
117
|
+
commit?(): Promise<void>;
|
|
118
|
+
rollback?(): Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
interface RuntimeQueryable extends RuntimeScope {
|
|
121
|
+
connection?(): Promise<RuntimeConnection>;
|
|
122
|
+
transaction?(): Promise<RuntimeTransaction>;
|
|
123
|
+
}
|
|
124
|
+
interface CollectionContext<TContract extends Contract<SqlStorage>> {
|
|
125
|
+
readonly runtime: RuntimeQueryable;
|
|
126
|
+
readonly context: ExecutionContext<TContract>;
|
|
127
|
+
}
|
|
128
|
+
type ComparisonMethodFns<T> = {
|
|
129
|
+
eq(value: T): AnyExpression;
|
|
130
|
+
neq(value: T): AnyExpression;
|
|
131
|
+
gt(value: T): AnyExpression;
|
|
132
|
+
lt(value: T): AnyExpression;
|
|
133
|
+
gte(value: T): AnyExpression;
|
|
134
|
+
lte(value: T): AnyExpression;
|
|
135
|
+
like(pattern: string): AnyExpression;
|
|
136
|
+
in(values: readonly T[]): AnyExpression;
|
|
137
|
+
notIn(values: readonly T[]): AnyExpression;
|
|
138
|
+
isNull(): AnyExpression;
|
|
139
|
+
isNotNull(): AnyExpression;
|
|
140
|
+
asc(): OrderByItem;
|
|
141
|
+
desc(): OrderByItem;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Trait-gated comparison methods. Only methods whose required traits are all present in `Traits` are included.
|
|
145
|
+
*
|
|
146
|
+
* - `traits: []` → always available (isNull, isNotNull)
|
|
147
|
+
*/
|
|
148
|
+
type ComparisonMethods<T, Traits> = { [K in keyof ComparisonMethodsMeta as [ComparisonMethodsMeta[K]['traits'][number]] extends [Traits] ? K : never]: ComparisonMethodFns<T>[K]; };
|
|
149
|
+
type QueryOperationReturnTraits<Returns, TCodecTypes extends Record<string, unknown>> = Returns extends {
|
|
150
|
+
readonly codecId: infer Id extends string;
|
|
151
|
+
} ? Id extends keyof TCodecTypes ? TCodecTypes[Id] extends {
|
|
152
|
+
readonly traits: infer Traits;
|
|
153
|
+
} ? Traits : never : never : never;
|
|
154
|
+
type QueryOperationReturnJsType<Returns, TCodecTypes extends Record<string, unknown>> = Returns extends {
|
|
155
|
+
readonly codecId: infer Id extends string;
|
|
156
|
+
readonly nullable: infer N;
|
|
157
|
+
} ? Id extends keyof TCodecTypes ? TCodecTypes[Id] extends {
|
|
158
|
+
readonly output: infer O;
|
|
159
|
+
} ? N extends true ? O | null : O : unknown : unknown : unknown;
|
|
160
|
+
type IsBooleanReturn<Returns, TCodecTypes extends Record<string, unknown>> = Returns extends {
|
|
161
|
+
readonly codecId: infer Id extends string;
|
|
162
|
+
} ? Id extends keyof TCodecTypes ? TCodecTypes[Id] extends {
|
|
163
|
+
readonly traits: infer T;
|
|
164
|
+
} ? 'boolean' extends T ? true : false : false : false : false;
|
|
165
|
+
/**
|
|
166
|
+
* Extract the `{codecId, nullable}` spec carried inside an `Expression<T>`. Used to recover the op's return spec from its impl signature so the pre-existing `QueryOperationReturn*` helpers can consume it unchanged.
|
|
167
|
+
*/
|
|
168
|
+
type SpecOf<E> = E extends Expression<infer T> ? T : never;
|
|
169
|
+
type ImplReturnSpec<Impl> = Impl extends ((...args: never[]) => infer Ret) ? SpecOf<Ret> : never;
|
|
170
|
+
/**
|
|
171
|
+
* Builds the ORM column-method signature for an operation.
|
|
172
|
+
*
|
|
173
|
+
* - User args: drops the impl's first parameter (the column is bound at access time) and forwards the rest unchanged. Each remaining arg keeps its authored `CodecExpression` / `TraitExpression` shape — so callers can pass a raw JS value, another column handle (which itself implements `Expression`), or `null` when nullable.
|
|
174
|
+
* - Return: predicate ops (boolean-traited return) yield `AnyExpression`; non-predicate ops yield `ComparisonMethods<JsType, Traits>` of the return codec.
|
|
175
|
+
*/
|
|
176
|
+
type QueryOperationMethod<Op, TCodecTypes extends Record<string, unknown>> = Op extends {
|
|
177
|
+
readonly impl: (...args: never[]) => unknown;
|
|
178
|
+
} ? Op['impl'] extends ((first: never, ...rest: infer UserArgs extends readonly unknown[]) => unknown) ? ImplReturnSpec<Op['impl']> extends (infer Returns) ? IsBooleanReturn<Returns, TCodecTypes> extends true ? (...args: UserArgs) => AnyExpression : (...args: UserArgs) => ComparisonMethods<QueryOperationReturnJsType<Returns, TCodecTypes>, QueryOperationReturnTraits<Returns, TCodecTypes>> : never : never : never;
|
|
179
|
+
/**
|
|
180
|
+
* Tests whether an operation's `self` dispatch hint reaches a field with the given codec identity. Codec hints match by identity; trait hints match when every required trait is present in the field codec's trait set.
|
|
181
|
+
*/
|
|
182
|
+
type OpMatchesField<Op, CodecId extends string, CT extends Record<string, unknown>> = Op extends {
|
|
183
|
+
readonly self: infer Self;
|
|
184
|
+
} ? Self extends {
|
|
185
|
+
readonly codecId: CodecId;
|
|
186
|
+
} ? true : Self extends {
|
|
187
|
+
readonly traits: infer RequiredTraits extends readonly string[];
|
|
188
|
+
} ? CodecId extends keyof CT ? CT[CodecId] extends {
|
|
189
|
+
readonly traits: infer FieldTraits;
|
|
190
|
+
} ? [RequiredTraits[number]] extends [FieldTraits] ? true : false : false : false : false : false;
|
|
191
|
+
type FieldOperations<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string> = FieldCodecId<TContract, ModelName, FieldName> extends (infer CodecId extends string) ? ExtractQueryOperationTypes<TContract> extends (infer AllOps) ? { [OpName in keyof AllOps & string as OpMatchesField<AllOps[OpName], CodecId, ExtractCodecTypes<TContract>> extends true ? OpName : never]: QueryOperationMethod<AllOps[OpName], ExtractCodecTypes<TContract>>; } : unknown : unknown;
|
|
192
|
+
/**
|
|
193
|
+
* Declares trait requirements and runtime factory for each comparison method.
|
|
194
|
+
*
|
|
195
|
+
* - `traits: []` means "no trait required" — always available
|
|
196
|
+
* - Multi-trait: `traits: ['equality', 'order']` means BOTH traits are required
|
|
197
|
+
*/
|
|
198
|
+
declare const COMPARISON_METHODS_META: {
|
|
199
|
+
readonly eq: {
|
|
200
|
+
readonly traits: readonly ["equality"];
|
|
201
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
202
|
+
};
|
|
203
|
+
readonly neq: {
|
|
204
|
+
readonly traits: readonly ["equality"];
|
|
205
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
206
|
+
};
|
|
207
|
+
readonly in: {
|
|
208
|
+
readonly traits: readonly ["equality"];
|
|
209
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (values: readonly unknown[]) => BinaryExpr;
|
|
210
|
+
};
|
|
211
|
+
readonly notIn: {
|
|
212
|
+
readonly traits: readonly ["equality"];
|
|
213
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (values: readonly unknown[]) => BinaryExpr;
|
|
214
|
+
};
|
|
215
|
+
readonly gt: {
|
|
216
|
+
readonly traits: readonly ["order"];
|
|
217
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
218
|
+
};
|
|
219
|
+
readonly lt: {
|
|
220
|
+
readonly traits: readonly ["order"];
|
|
221
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
222
|
+
};
|
|
223
|
+
readonly gte: {
|
|
224
|
+
readonly traits: readonly ["order"];
|
|
225
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
226
|
+
};
|
|
227
|
+
readonly lte: {
|
|
228
|
+
readonly traits: readonly ["order"];
|
|
229
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
230
|
+
};
|
|
231
|
+
readonly like: {
|
|
232
|
+
readonly traits: readonly ["textual"];
|
|
233
|
+
readonly create: (left: AnyExpression, codec: CodecRef$1 | undefined) => (value: unknown) => BinaryExpr | NullCheckExpr;
|
|
234
|
+
};
|
|
235
|
+
readonly asc: {
|
|
236
|
+
readonly traits: readonly ["order"];
|
|
237
|
+
readonly create: (left: AnyExpression) => () => OrderByItem;
|
|
238
|
+
};
|
|
239
|
+
readonly desc: {
|
|
240
|
+
readonly traits: readonly ["order"];
|
|
241
|
+
readonly create: (left: AnyExpression) => () => OrderByItem;
|
|
242
|
+
};
|
|
243
|
+
readonly isNull: {
|
|
244
|
+
readonly traits: readonly [];
|
|
245
|
+
readonly create: (left: AnyExpression) => () => NullCheckExpr;
|
|
246
|
+
};
|
|
247
|
+
readonly isNotNull: {
|
|
248
|
+
readonly traits: readonly [];
|
|
249
|
+
readonly create: (left: AnyExpression) => () => NullCheckExpr;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
type ComparisonMethodsMeta = typeof COMPARISON_METHODS_META;
|
|
253
|
+
type RelationPredicate<TContract extends Contract<SqlStorage>, ModelName extends string> = (model: ModelAccessor<TContract, ModelName>) => AnyExpression;
|
|
254
|
+
type RelationPredicateInput<TContract extends Contract<SqlStorage>, ModelName extends string> = RelationPredicate<TContract, ModelName> | Record<string, unknown>;
|
|
255
|
+
type RelationFilterAccessor<TContract extends Contract<SqlStorage>, RelatedModelName extends string> = {
|
|
256
|
+
some(predicate?: RelationPredicateInput<TContract, RelatedModelName>): AnyExpression;
|
|
257
|
+
every(predicate: RelationPredicateInput<TContract, RelatedModelName>): AnyExpression;
|
|
258
|
+
none(predicate?: RelationPredicateInput<TContract, RelatedModelName>): AnyExpression;
|
|
259
|
+
};
|
|
260
|
+
type ScalarModelAccessor<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = { [K in keyof FieldsOf<TContract, ModelName, NsId> & string]: Expression<{
|
|
261
|
+
codecId: FieldCodecId<TContract, ModelName, K, NsId>;
|
|
262
|
+
nullable: FieldNullable<TContract, ModelName, K, NsId>;
|
|
263
|
+
}> & ComparisonMethods<FieldJsType<TContract, ModelName, K, NsId>, FieldTraits<TContract, ModelName, K, NsId>> & FieldOperations<TContract, ModelName, K>; };
|
|
264
|
+
type RelationModelAccessor<TContract extends Contract<SqlStorage>, ModelName extends string> = { [K in RelationNames<TContract, ModelName>]: RelationFilterAccessor<TContract, RelatedModelName<TContract, ModelName, K> & string>; };
|
|
265
|
+
type ModelAccessor<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ScalarModelAccessor<TContract, ModelName, NsId> & RelationModelAccessor<TContract, ModelName>;
|
|
266
|
+
/**
|
|
267
|
+
* The predicate accessor for a collection narrowed to a variant. When a real
|
|
268
|
+
* variant is selected its (possibly MTI) fields and relations are merged onto
|
|
269
|
+
* the base accessor so `t.variant('Feature').where(x => x.priority…)` and
|
|
270
|
+
* `t.variant('Feature').where(x => x.assignee.some(…))` type-check; with no
|
|
271
|
+
* variant the accessor is the plain base `ModelAccessor` and is unchanged.
|
|
272
|
+
*/
|
|
273
|
+
type VariantAwareModelAccessor<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName extends string | undefined, NsId extends string = never> = [VariantName] extends [string] ? VariantName extends VariantNames<TContract, ModelName, NsId> ? ScalarModelAccessor<TContract, ModelName, NsId> & ScalarModelAccessor<TContract, VariantName, NsId> & RelationModelAccessor<TContract, ModelName> & RelationModelAccessor<TContract, VariantName> : ModelAccessor<TContract, ModelName, NsId> : ModelAccessor<TContract, ModelName, NsId>;
|
|
274
|
+
/**
|
|
275
|
+
* The flat default row of a single model: its own declared fields mapped to
|
|
276
|
+
* their JS types, with no variant flattening. Use this when you want exactly
|
|
277
|
+
* one model's fields (e.g. building the variant pieces, create/update inputs,
|
|
278
|
+
* column-name maps).
|
|
279
|
+
*
|
|
280
|
+
* Contrast with {@link InferRootRow}, which is the *read-shape* of a root
|
|
281
|
+
* collection: for a polymorphic base it discriminates over the variants and
|
|
282
|
+
* flattens each variant's own `DefaultModelRow` onto the base. `InferRootRow`
|
|
283
|
+
* is built from `DefaultModelRow`, not the other way around, so it can't be
|
|
284
|
+
* re-expressed in terms of `InferRootRow`.
|
|
285
|
+
*/
|
|
286
|
+
type DefaultModelRow<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = { [K in keyof FieldsOf<TContract, ModelName, NsId> & string]: FieldJsType<TContract, ModelName, K, NsId>; };
|
|
287
|
+
type Simplify<T> = { [K in keyof T]: T[K]; } & {};
|
|
288
|
+
type VariantRow<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
289
|
+
readonly discriminator: {
|
|
290
|
+
readonly field: infer DiscField extends string;
|
|
291
|
+
};
|
|
292
|
+
readonly variants: infer V;
|
|
293
|
+
} ? V extends Record<string, {
|
|
294
|
+
readonly value: string;
|
|
295
|
+
}> ? { [VK in keyof V]: VK extends string & CollectionModelName<TContract> ? Simplify<Omit<DefaultModelRow<TContract, ModelName, NsId>, DiscField> & DefaultModelRow<TContract, VK, NsId> & Record<DiscField, V[VK]['value']>> : never; }[keyof V] : DefaultModelRow<TContract, ModelName, NsId> : DefaultModelRow<TContract, ModelName, NsId>;
|
|
296
|
+
type InferRootRow<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = VariantRow<TContract, ModelName, NsId>;
|
|
297
|
+
type VariantNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
298
|
+
readonly variants: infer V extends Record<string, unknown>;
|
|
299
|
+
} ? keyof V & string : never;
|
|
300
|
+
type VariantModelRow<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
301
|
+
readonly discriminator: {
|
|
302
|
+
readonly field: infer DiscField extends string;
|
|
303
|
+
};
|
|
304
|
+
readonly variants: infer V;
|
|
305
|
+
} ? V extends Record<string, {
|
|
306
|
+
readonly value: string;
|
|
307
|
+
}> ? VariantName extends keyof V & string & CollectionModelName<TContract> ? Simplify<Omit<DefaultModelRow<TContract, ModelName, NsId>, DiscField> & DefaultModelRow<TContract, VariantName, NsId> & Record<DiscField, V[VariantName]['value']>> : DefaultModelRow<TContract, ModelName, NsId> : DefaultModelRow<TContract, ModelName, NsId> : DefaultModelRow<TContract, ModelName, NsId>;
|
|
308
|
+
declare const aggregateResultBrand: unique symbol;
|
|
309
|
+
interface AggregateSelector<Result> {
|
|
310
|
+
readonly kind: 'aggregate';
|
|
311
|
+
readonly fn: AggregateFn;
|
|
312
|
+
readonly column?: string;
|
|
313
|
+
readonly [aggregateResultBrand]?: Result;
|
|
314
|
+
}
|
|
315
|
+
type AggregateSpec = Record<string, AggregateSelector<unknown>>;
|
|
316
|
+
type AggregateResult<Spec extends AggregateSpec> = { [K in keyof Spec]: Spec[K] extends AggregateSelector<infer Result> ? Result : never; };
|
|
317
|
+
interface AggregateBuilder<TContract extends Contract<SqlStorage>, ModelName extends string> {
|
|
318
|
+
count(): AggregateSelector<number>;
|
|
319
|
+
sum<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): AggregateSelector<number | null>;
|
|
320
|
+
avg<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): AggregateSelector<number | null>;
|
|
321
|
+
min<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): AggregateSelector<number | null>;
|
|
322
|
+
max<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): AggregateSelector<number | null>;
|
|
323
|
+
}
|
|
324
|
+
type HavingComparisonMethods<T> = Pick<ComparisonMethods<T, 'equality' | 'order'>, 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte'>;
|
|
325
|
+
interface HavingBuilder<TContract extends Contract<SqlStorage>, ModelName extends string> {
|
|
326
|
+
count(): HavingComparisonMethods<number>;
|
|
327
|
+
sum<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): HavingComparisonMethods<number | null>;
|
|
328
|
+
avg<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): HavingComparisonMethods<number | null>;
|
|
329
|
+
min<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): HavingComparisonMethods<number | null>;
|
|
330
|
+
max<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): HavingComparisonMethods<number | null>;
|
|
331
|
+
}
|
|
332
|
+
type ShorthandWhereFilter<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = Partial<{ [K in keyof DefaultModelRow<TContract, ModelName, NsId> & string]: DefaultModelRow<TContract, ModelName, NsId>[K] | null | undefined; }>;
|
|
333
|
+
type NamespaceModelsOf<TContract extends Contract<SqlStorage>, NsId extends string> = NsId extends keyof TContract['domain']['namespaces'] ? TContract['domain']['namespaces'][NsId]['models'] extends (infer M extends Record<string, unknown>) ? M : Record<string, never> : Record<string, never>;
|
|
334
|
+
type ScannedModelDef<TContract extends Contract<SqlStorage>, ModelName extends string> = { [Ns in keyof TContract['domain']['namespaces']]: ModelName extends keyof TContract['domain']['namespaces'][Ns]['models'] ? TContract['domain']['namespaces'][Ns]['models'][ModelName] : never; }[keyof TContract['domain']['namespaces']];
|
|
335
|
+
type ModelDef<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = [NsId] extends [never] ? ScannedModelDef<TContract, ModelName> : ModelName extends keyof NamespaceModelsOf<TContract, NsId> ? NamespaceModelsOf<TContract, NsId>[ModelName] : never;
|
|
336
|
+
type NamespaceContainingTable<TContract extends Contract<SqlStorage>, TableName extends string> = { [K in keyof TContract['storage']['namespaces'] & string]: TContract['storage']['namespaces'][K] extends {
|
|
337
|
+
readonly entries: {
|
|
338
|
+
readonly table: infer Tables;
|
|
339
|
+
};
|
|
340
|
+
} ? TableName extends keyof Tables ? K : never : never; }[keyof TContract['storage']['namespaces'] & string];
|
|
341
|
+
type ResolvedNsId<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = [NsId] extends [never] ? ModelDef<TContract, ModelName> extends {
|
|
342
|
+
readonly storage: {
|
|
343
|
+
readonly namespaceId: infer N extends string;
|
|
344
|
+
};
|
|
345
|
+
} ? N : ModelDef<TContract, ModelName> extends {
|
|
346
|
+
readonly storage: {
|
|
347
|
+
readonly table: infer T extends string;
|
|
348
|
+
};
|
|
349
|
+
} ? NamespaceContainingTable<TContract, T> : never : NsId;
|
|
350
|
+
type FieldsOf<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
351
|
+
readonly fields: infer F;
|
|
352
|
+
} ? F extends Record<string, unknown> ? F : Record<string, never> : Record<string, never>;
|
|
353
|
+
type ModelStorageFields<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
354
|
+
readonly storage: {
|
|
355
|
+
readonly fields: infer Fields;
|
|
356
|
+
};
|
|
357
|
+
} ? Fields extends Record<string, {
|
|
358
|
+
readonly column: string;
|
|
359
|
+
}> ? Fields : never : never;
|
|
360
|
+
type ModelFieldToColumnMap<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelStorageFields<TContract, ModelName, NsId> extends (infer Fields) ? Fields extends Record<string, {
|
|
361
|
+
readonly column: string;
|
|
362
|
+
}> ? { readonly [F in keyof Fields]: Fields[F]['column']; } : never : never;
|
|
363
|
+
type FieldToColumnMapSafe<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelFieldToColumnMap<TContract, ModelName, NsId> extends Record<string, string> ? ModelFieldToColumnMap<TContract, ModelName, NsId> : never;
|
|
364
|
+
type ModelTableName<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
365
|
+
readonly storage: {
|
|
366
|
+
readonly table: infer T extends string;
|
|
367
|
+
};
|
|
368
|
+
} ? T : never;
|
|
369
|
+
type FieldColumnName<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = (FieldToColumnMapSafe<TContract, ModelName, NsId> extends never ? FieldName : FieldName extends keyof FieldToColumnMapSafe<TContract, ModelName, NsId> ? FieldToColumnMapSafe<TContract, ModelName, NsId>[FieldName] : FieldName) & string;
|
|
370
|
+
type NamespaceTableDef<TContract extends Contract<SqlStorage>, TableName extends string, NsId extends string = never> = [NsId] extends [never] ? { [K in keyof TContract['storage']['namespaces']]: TContract['storage']['namespaces'][K] extends {
|
|
371
|
+
readonly entries: {
|
|
372
|
+
readonly table: infer Tables;
|
|
373
|
+
};
|
|
374
|
+
} ? TableName extends keyof Tables ? Tables[TableName] : never : never; }[keyof TContract['storage']['namespaces']] : NsId extends keyof TContract['storage']['namespaces'] ? TContract['storage']['namespaces'][NsId] extends {
|
|
375
|
+
readonly entries: {
|
|
376
|
+
readonly table: infer Tables;
|
|
377
|
+
};
|
|
378
|
+
} ? TableName extends keyof Tables ? Tables[TableName] : never : never : never;
|
|
379
|
+
type ResolvedStorageColumn<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = ModelTableName<TContract, ModelName, NsId> extends (infer TableName extends string) ? FieldColumnName<TContract, ModelName, FieldName, NsId> extends (infer ColName extends string) ? NamespaceTableDef<TContract, TableName, ResolvedNsId<TContract, ModelName, NsId>> extends {
|
|
380
|
+
readonly columns: infer Columns;
|
|
381
|
+
} ? ColName extends keyof Columns ? Columns[ColName] extends StorageColumn ? Columns[ColName] : never : never : never : never : never;
|
|
382
|
+
type FieldStorageJsType<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = ResolvedStorageColumn<TContract, ModelName, FieldName, NsId> extends (infer Col extends StorageColumn) ? Col extends StorageColumn ? ComputeColumnJsType<TContract, ResolvedNsId<TContract, ModelName, NsId>, ModelTableName<TContract, ModelName, NsId> & string, FieldColumnName<TContract, ModelName, FieldName, NsId> & string, ExtractCodecTypes<TContract>> : never : never;
|
|
383
|
+
type NamespaceFieldOutputType<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = ResolvedNsId<TContract, ModelName, NsId> extends (infer Ns extends string) ? ExtractFieldOutputTypes<TContract> extends (infer Outputs) ? Ns extends keyof Outputs ? Outputs[Ns] extends (infer NamespaceOutputs) ? ModelName extends keyof NamespaceOutputs ? NamespaceOutputs[ModelName] extends (infer ModelOutputs) ? FieldName extends keyof ModelOutputs ? ModelOutputs[FieldName] : never : never : never : never : never : never : never;
|
|
384
|
+
type FieldJsType<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = [NamespaceFieldOutputType<TContract, ModelName, FieldName, NsId>] extends [never] ? [FieldStorageJsType<TContract, ModelName, FieldName, NsId>] extends [never] ? unknown : FieldStorageJsType<TContract, ModelName, FieldName, NsId> : NamespaceFieldOutputType<TContract, ModelName, FieldName, NsId>;
|
|
385
|
+
type FieldStorageColumn<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = ResolvedStorageColumn<TContract, ModelName, FieldName, NsId>;
|
|
386
|
+
type FieldCodecId<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = FieldStorageColumn<TContract, ModelName, FieldName, NsId> extends {
|
|
387
|
+
readonly codecId: infer Id extends string;
|
|
388
|
+
} ? Id : never;
|
|
389
|
+
type FieldNullable<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = FieldStorageColumn<TContract, ModelName, FieldName, NsId> extends {
|
|
390
|
+
readonly nullable: infer N extends boolean;
|
|
391
|
+
} ? N : false;
|
|
392
|
+
type FieldTraits<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = FieldCodecId<TContract, ModelName, FieldName, NsId> extends (infer Id extends string) ? Id extends keyof ExtractCodecTypes<TContract> ? ExtractCodecTypes<TContract>[Id] extends {
|
|
393
|
+
readonly traits: infer T;
|
|
394
|
+
} ? T : never : never : never;
|
|
395
|
+
type NumericFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = { [K in keyof DefaultModelRow<TContract, ModelName, NsId> & string]: 'numeric' extends FieldTraits<TContract, ModelName, K, NsId> ? K : never; }[keyof DefaultModelRow<TContract, ModelName, NsId> & string];
|
|
396
|
+
type ExecutionDefaultEntry<TContract extends Contract<SqlStorage>> = TContract['execution'] extends {
|
|
397
|
+
readonly mutations: {
|
|
398
|
+
readonly defaults: infer Defaults;
|
|
399
|
+
};
|
|
400
|
+
} ? Defaults extends ReadonlyArray<unknown> ? Defaults[number] : never : never;
|
|
401
|
+
type HasExecutionCreateDefault<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = [Extract<ExecutionDefaultEntry<TContract>, {
|
|
402
|
+
readonly ref: {
|
|
403
|
+
readonly table: ModelTableName<TContract, ModelName, NsId>;
|
|
404
|
+
readonly column: FieldColumnName<TContract, ModelName, FieldName, NsId>;
|
|
405
|
+
} & ([NsId] extends [never] ? unknown : {
|
|
406
|
+
readonly namespace: NsId;
|
|
407
|
+
});
|
|
408
|
+
readonly onCreate?: unknown;
|
|
409
|
+
}>] extends [never] ? false : true;
|
|
410
|
+
type IsOptionalCreateField<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string, NsId extends string = never> = FieldStorageColumn<TContract, ModelName, FieldName, NsId> extends (infer Column) ? Column extends StorageColumn ? Column['nullable'] extends true ? true : Column extends {
|
|
411
|
+
readonly default: unknown;
|
|
412
|
+
} ? true : HasExecutionCreateDefault<TContract, ModelName, FieldName, NsId> : HasExecutionCreateDefault<TContract, ModelName, FieldName, NsId> : HasExecutionCreateDefault<TContract, ModelName, FieldName, NsId>;
|
|
413
|
+
type CreateFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = keyof DefaultModelRow<TContract, ModelName, NsId> & string;
|
|
414
|
+
type RequiredCreateFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = { [K in CreateFieldNames<TContract, ModelName, NsId>]-?: IsOptionalCreateField<TContract, ModelName, K, NsId> extends true ? never : K; }[CreateFieldNames<TContract, ModelName, NsId>];
|
|
415
|
+
type OptionalCreateFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = { [K in CreateFieldNames<TContract, ModelName, NsId>]-?: IsOptionalCreateField<TContract, ModelName, K, NsId> extends true ? K : never; }[CreateFieldNames<TContract, ModelName, NsId>];
|
|
416
|
+
type CreateInput<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = Pick<DefaultModelRow<TContract, ModelName, NsId>, RequiredCreateFieldNames<TContract, ModelName, NsId>> & Partial<Pick<DefaultModelRow<TContract, ModelName, NsId>, OptionalCreateFieldNames<TContract, ModelName, NsId>>> & RelationMutationFields<TContract, ModelName, 'create'>;
|
|
417
|
+
type IsPolymorphicBase<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
418
|
+
readonly discriminator: unknown;
|
|
419
|
+
readonly variants: Record<string, unknown>;
|
|
420
|
+
} ? true : false;
|
|
421
|
+
type DiscriminatorFieldName<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
422
|
+
readonly discriminator: {
|
|
423
|
+
readonly field: infer F extends string;
|
|
424
|
+
};
|
|
425
|
+
} ? F : never;
|
|
426
|
+
type VariantCreateInput<TContract extends Contract<SqlStorage>, BaseModelName extends string, VariantName extends string, NsId extends string = never> = Omit<CreateInput<TContract, BaseModelName, NsId>, DiscriminatorFieldName<TContract, BaseModelName, NsId>> & CreateInput<TContract, VariantName, NsId>;
|
|
427
|
+
type ResolvedCreateInput<TContract extends Contract<SqlStorage>, ModelName extends string, VName extends string | undefined, NsId extends string = never> = IsPolymorphicBase<TContract, ModelName, NsId> extends true ? VName extends string ? VariantCreateInput<TContract, ModelName, VName, NsId> : never : CreateInput<TContract, ModelName, NsId>;
|
|
428
|
+
type ModelStorageTableDef<TContract extends Contract<SqlStorage>, ModelName extends string> = ModelTableName<TContract, ModelName> extends (infer TableName extends string) ? NamespaceTableDef<TContract, TableName> : never;
|
|
429
|
+
type PrimaryKeyConstraintColumns<TContract extends Contract<SqlStorage>, ModelName extends string> = ModelStorageTableDef<TContract, ModelName> extends {
|
|
430
|
+
readonly primaryKey: {
|
|
431
|
+
readonly columns: infer Columns extends readonly string[];
|
|
432
|
+
};
|
|
433
|
+
} ? Columns : never;
|
|
434
|
+
type UniqueConstraintColumns<TContract extends Contract<SqlStorage>, ModelName extends string> = ModelStorageTableDef<TContract, ModelName> extends {
|
|
435
|
+
readonly uniques: infer Uniques;
|
|
436
|
+
} ? Uniques extends ReadonlyArray<infer Unique> ? Unique extends {
|
|
437
|
+
readonly columns: infer Columns extends readonly string[];
|
|
438
|
+
} ? Columns : never : never : never;
|
|
439
|
+
type FieldNameForColumn<TContract extends Contract<SqlStorage>, ModelName extends string, ColumnName extends string> = { [K in keyof DefaultModelRow<TContract, ModelName> & string]: FieldColumnName<TContract, ModelName, K> extends ColumnName ? K : never; }[keyof DefaultModelRow<TContract, ModelName> & string] extends (infer Matched) ? Matched extends string ? Matched : ColumnName : ColumnName;
|
|
440
|
+
type RowValueForField<TContract extends Contract<SqlStorage>, ModelName extends string, FieldName extends string> = FieldName extends keyof DefaultModelRow<TContract, ModelName> ? DefaultModelRow<TContract, ModelName>[FieldName] : unknown;
|
|
441
|
+
type CriterionFromConstraintColumns<TContract extends Contract<SqlStorage>, ModelName extends string, Columns extends readonly string[]> = string extends Columns[number] ? Record<string, unknown> : { [C in Columns[number] as FieldNameForColumn<TContract, ModelName, C>]: RowValueForField<TContract, ModelName, FieldNameForColumn<TContract, ModelName, C>>; };
|
|
442
|
+
type ConstraintColumnsUnion<TContract extends Contract<SqlStorage>, ModelName extends string> = PrimaryKeyConstraintColumns<TContract, ModelName> | UniqueConstraintColumns<TContract, ModelName>;
|
|
443
|
+
type UniqueConstraintCriterion<TContract extends Contract<SqlStorage>, ModelName extends string> = ConstraintColumnsUnion<TContract, ModelName> extends (infer Columns) ? Columns extends readonly string[] ? CriterionFromConstraintColumns<TContract, ModelName, Columns> : never : never;
|
|
444
|
+
type RelationConnectCriterion<TContract extends Contract<SqlStorage>, ModelName extends string> = [UniqueConstraintCriterion<TContract, ModelName>] extends [never] ? Record<string, unknown> : UniqueConstraintCriterion<TContract, ModelName>;
|
|
445
|
+
interface RelationMutationCreate<TContract extends Contract<SqlStorage>, ModelName extends string> {
|
|
446
|
+
readonly kind: 'create';
|
|
447
|
+
readonly data: readonly MutationCreateInput<TContract, ModelName>[];
|
|
448
|
+
}
|
|
449
|
+
interface RelationMutationConnect<TContract extends Contract<SqlStorage>, ModelName extends string> {
|
|
450
|
+
readonly kind: 'connect';
|
|
451
|
+
readonly criteria: readonly RelationConnectCriterion<TContract, ModelName>[];
|
|
452
|
+
}
|
|
453
|
+
interface RelationMutationDisconnect<TContract extends Contract<SqlStorage>, ModelName extends string> {
|
|
454
|
+
readonly kind: 'disconnect';
|
|
455
|
+
readonly criteria?: readonly RelationConnectCriterion<TContract, ModelName>[];
|
|
456
|
+
}
|
|
457
|
+
type RelationMutation<TContract extends Contract<SqlStorage>, ModelName extends string> = RelationMutationCreate<TContract, ModelName> | RelationMutationConnect<TContract, ModelName> | RelationMutationDisconnect<TContract, ModelName>;
|
|
458
|
+
type RelationThrough<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string> = RelationsOf<TContract, ModelName> extends (infer Rels extends Record<string, unknown>) ? RelName extends keyof Rels ? Rels[RelName] extends {
|
|
459
|
+
readonly through: infer Through extends {
|
|
460
|
+
readonly table: string;
|
|
461
|
+
readonly parentColumns: readonly string[];
|
|
462
|
+
readonly childColumns: readonly string[];
|
|
463
|
+
};
|
|
464
|
+
} ? Through : never : never : never;
|
|
465
|
+
type HasJunctionThrough<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string> = [RelationThrough<TContract, ModelName, RelName>] extends [never] ? false : true;
|
|
466
|
+
/**
|
|
467
|
+
* Resolves a storage table name to its owning domain model by scanning the
|
|
468
|
+
* model map for the model whose `storage.table` and `storage.namespaceId`
|
|
469
|
+
* match. Junction tables (e.g. `user_roles`) surface their generated model
|
|
470
|
+
* (e.g. `UserRole`) so the junction's own field nullability/defaults can be
|
|
471
|
+
* inspected.
|
|
472
|
+
*/
|
|
473
|
+
type ModelNameForTable<TContract extends Contract<SqlStorage>, NamespaceId extends string, TableName extends string> = { [M in keyof NamespaceModelsOf<TContract, NamespaceId> & string]: NamespaceModelsOf<TContract, NamespaceId>[M] extends {
|
|
474
|
+
readonly storage: {
|
|
475
|
+
readonly namespaceId: NamespaceId;
|
|
476
|
+
readonly table: TableName;
|
|
477
|
+
};
|
|
478
|
+
} ? M : never; }[keyof NamespaceModelsOf<TContract, NamespaceId> & string];
|
|
479
|
+
/**
|
|
480
|
+
* A junction field is a *payload* field when its backing column is neither a
|
|
481
|
+
* parent-side nor a child-side foreign-key column of the join. Those payload
|
|
482
|
+
* fields are the ones the relation API can't populate from `create`/`connect`.
|
|
483
|
+
*/
|
|
484
|
+
type JunctionPayloadFieldNames<TContract extends Contract<SqlStorage>, JunctionModel extends string, JoinColumns extends string, NsId extends string = never> = { [F in CreateFieldNames<TContract, JunctionModel, NsId>]: FieldColumnName<TContract, JunctionModel, F, NsId> extends JoinColumns ? never : F; }[CreateFieldNames<TContract, JunctionModel, NsId>];
|
|
485
|
+
/**
|
|
486
|
+
* True when the relation's junction carries at least one required payload
|
|
487
|
+
* column — a non-join column that is not nullable and has no default. Such a
|
|
488
|
+
* relation can't be populated through nested `create`, so its create input is
|
|
489
|
+
* disabled at the type level (mirroring the runtime guard in
|
|
490
|
+
* `mutation-executor.ts`).
|
|
491
|
+
*/
|
|
492
|
+
type HasRequiredJunctionPayload<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string> = RelationThrough<TContract, ModelName, RelName> extends (infer Through extends {
|
|
493
|
+
readonly table: string;
|
|
494
|
+
readonly namespaceId: string;
|
|
495
|
+
readonly parentColumns: readonly string[];
|
|
496
|
+
readonly childColumns: readonly string[];
|
|
497
|
+
}) ? ModelNameForTable<TContract, Through['namespaceId'], Through['table']> extends (infer JunctionModel extends string) ? JunctionPayloadFieldNames<TContract, JunctionModel, Through['parentColumns'][number] | Through['childColumns'][number], Through['namespaceId']> extends (infer PayloadFields extends string) ? { [F in PayloadFields]: IsOptionalCreateField<TContract, JunctionModel, F, Through['namespaceId']> extends true ? never : F; }[PayloadFields] extends never ? false : true : false : false : false;
|
|
498
|
+
type DisconnectMutator<TContract extends Contract<SqlStorage>, ModelName extends string, BareDisconnectDisabled extends boolean> = BareDisconnectDisabled extends true ? (criteria: readonly RelationConnectCriterion<TContract, ModelName>[]) => RelationMutationDisconnect<TContract, ModelName> : {
|
|
499
|
+
(): RelationMutationDisconnect<TContract, ModelName>;
|
|
500
|
+
(criteria: readonly RelationConnectCriterion<TContract, ModelName>[]): RelationMutationDisconnect<TContract, ModelName>;
|
|
501
|
+
};
|
|
502
|
+
interface RelationMutator<TContract extends Contract<SqlStorage>, ModelName extends string, LinkWritesDisabled extends boolean = false, BareDisconnectDisabled extends boolean = false, DisconnectDisabled extends boolean = false> {
|
|
503
|
+
create(data: LinkWritesDisabled extends true ? never : MutationCreateInput<TContract, ModelName>): RelationMutationCreate<TContract, ModelName>;
|
|
504
|
+
create(data: LinkWritesDisabled extends true ? never : readonly MutationCreateInput<TContract, ModelName>[]): RelationMutationCreate<TContract, ModelName>;
|
|
505
|
+
connect(criterion: LinkWritesDisabled extends true ? never : RelationConnectCriterion<TContract, ModelName>): RelationMutationConnect<TContract, ModelName>;
|
|
506
|
+
connect(criteria: LinkWritesDisabled extends true ? never : readonly RelationConnectCriterion<TContract, ModelName>[]): RelationMutationConnect<TContract, ModelName>;
|
|
507
|
+
readonly disconnect: DisconnectDisabled extends true ? (criteria: never) => RelationMutationDisconnect<TContract, ModelName> : DisconnectMutator<TContract, ModelName, BareDisconnectDisabled>;
|
|
508
|
+
}
|
|
509
|
+
type RelationMutationCallback<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends RelationNames<TContract, ModelName>, Context extends 'create' | 'update' = 'update'> = (mutator: RelationMutator<TContract, RelatedModelName<TContract, ModelName, RelName> & string, HasRequiredJunctionPayload<TContract, ModelName, RelName>, HasJunctionThrough<TContract, ModelName, RelName>, Context extends 'create' ? true : false>) => RelationMutation<TContract, RelatedModelName<TContract, ModelName, RelName> & string>;
|
|
510
|
+
type RelationMutationFields<TContract extends Contract<SqlStorage>, ModelName extends string, Context extends 'create' | 'update' = 'update'> = Partial<{ [K in RelationNames<TContract, ModelName>]: RelationMutationCallback<TContract, ModelName, K, Context>; }>;
|
|
511
|
+
type AllModelRelationEntries<TContract extends Contract<SqlStorage>> = { [Ns in keyof TContract['domain']['namespaces']]: { [M in keyof TContract['domain']['namespaces'][Ns]['models']]: TContract['domain']['namespaces'][Ns]['models'][M] extends {
|
|
512
|
+
readonly relations: infer R extends Record<string, unknown>;
|
|
513
|
+
} ? R[keyof R] : never; }[keyof TContract['domain']['namespaces'][Ns]['models']]; }[keyof TContract['domain']['namespaces']];
|
|
514
|
+
type RelationDefWithTargetFields = {
|
|
515
|
+
readonly to: {
|
|
516
|
+
readonly model: string;
|
|
517
|
+
};
|
|
518
|
+
readonly on: {
|
|
519
|
+
readonly targetFields: readonly string[];
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
type ChildForeignKeyFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string> = Extract<AllModelRelationEntries<TContract>, RelationDefWithTargetFields> extends (infer Relation) ? Relation extends {
|
|
523
|
+
readonly to: {
|
|
524
|
+
readonly model: ModelName;
|
|
525
|
+
};
|
|
526
|
+
readonly on: {
|
|
527
|
+
readonly targetFields: infer Fields extends readonly string[];
|
|
528
|
+
};
|
|
529
|
+
} ? Fields[number] : never : never;
|
|
530
|
+
type NestedOptionalCreateFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = OptionalCreateFieldNames<TContract, ModelName, NsId> | Extract<ChildForeignKeyFieldNames<TContract, ModelName>, CreateFieldNames<TContract, ModelName, NsId>>;
|
|
531
|
+
type NestedRequiredCreateFieldNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = Exclude<CreateFieldNames<TContract, ModelName, NsId>, NestedOptionalCreateFieldNames<TContract, ModelName, NsId>>;
|
|
532
|
+
type NestedCreateInput<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = Pick<DefaultModelRow<TContract, ModelName, NsId>, NestedRequiredCreateFieldNames<TContract, ModelName, NsId>> & Partial<Pick<DefaultModelRow<TContract, ModelName, NsId>, NestedOptionalCreateFieldNames<TContract, ModelName, NsId>>>;
|
|
533
|
+
type AtLeastOne<T> = keyof T extends never ? never : { [K in keyof T]-?: Pick<T, K> & Partial<Omit<T, K>>; }[keyof T];
|
|
534
|
+
type MutationCreateInput<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = NestedCreateInput<TContract, ModelName, NsId> & RelationMutationFields<TContract, ModelName, 'create'>;
|
|
535
|
+
type MutationCreateInputWithRelations<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = NestedCreateInput<TContract, ModelName, NsId> & AtLeastOne<RelationMutationFields<TContract, ModelName, 'create'>>;
|
|
536
|
+
type MutationUpdateInput<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = Partial<DefaultModelRow<TContract, ModelName, NsId>> & RelationMutationFields<TContract, ModelName, 'update'>;
|
|
537
|
+
type ModelRelations<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ModelDef<TContract, ModelName, NsId> extends {
|
|
538
|
+
readonly relations: infer R;
|
|
539
|
+
} ? R extends Record<string, unknown> ? R : Record<string, never> : Record<string, never>;
|
|
540
|
+
type ExactRecord<T> = T extends Record<string, unknown> ? string extends keyof T ? Record<string, never> : T : Record<string, never>;
|
|
541
|
+
type RelationsOf<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = ExactRecord<ModelRelations<TContract, ModelName, NsId>>;
|
|
542
|
+
type RelationNames<TContract extends Contract<SqlStorage>, ModelName extends string, NsId extends string = never> = (string extends keyof RelationsOf<TContract, ModelName, NsId> ? never : { [K in keyof RelationsOf<TContract, ModelName, NsId>]: RelationsOf<TContract, ModelName, NsId>[K] extends never ? never : K; }[keyof RelationsOf<TContract, ModelName, NsId>]) & string;
|
|
543
|
+
type IsUnion<T, Whole = T> = T extends Whole ? ([Whole] extends [T] ? false : true) : never;
|
|
544
|
+
type IsSingletonString<T> = [T] extends [string] ? string extends T ? false : IsUnion<T> extends true ? false : true : false;
|
|
545
|
+
type SelectedVariantNames<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName, NsId extends string> = [VariantName] extends [string] ? string extends VariantName ? VariantNames<TContract, ModelName, NsId> : VariantName : never;
|
|
546
|
+
type VariantDeclaredRelationKeys<TContract extends Contract<SqlStorage>, VariantName extends string, NsId extends string> = VariantName extends string ? keyof RelationsOf<TContract, VariantName, NsId> : never;
|
|
547
|
+
type SelectedVariantDeclaredRelationKeys<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName, NsId extends string> = VariantDeclaredRelationKeys<TContract, SelectedVariantNames<TContract, ModelName, VariantName, NsId>, NsId>;
|
|
548
|
+
type VariantAwareIncludeRelationNames<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName, NsId extends string = never> = IsSingletonString<VariantName> extends true ? RelationNames<TContract, Extract<VariantName, string>, NsId> | Exclude<RelationNames<TContract, ModelName, NsId>, keyof RelationsOf<TContract, Extract<VariantName, string>, NsId>> : [VariantName] extends [string] ? Exclude<RelationNames<TContract, ModelName, NsId>, SelectedVariantDeclaredRelationKeys<TContract, ModelName, VariantName, NsId>> : RelationNames<TContract, ModelName, NsId>;
|
|
549
|
+
type IncludeRelationOwner<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName, RelName extends string, NsId extends string = never> = IsSingletonString<VariantName> extends true ? RelName extends keyof RelationsOf<TContract, Extract<VariantName, string>, NsId> ? Extract<VariantName, string> : ModelName : ModelName;
|
|
550
|
+
type RelationModelName<Relation> = Relation extends {
|
|
551
|
+
readonly to: {
|
|
552
|
+
readonly model: infer To extends string;
|
|
553
|
+
};
|
|
554
|
+
} ? To : never;
|
|
555
|
+
type RelatedModelName<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string, NsId extends string = never> = RelationsOf<TContract, ModelName, NsId> extends (infer Rels) ? Rels extends Record<string, unknown> ? RelName extends keyof Rels ? RelationModelName<Rels[RelName]> : never : never : never;
|
|
556
|
+
type RelationTargetNamespace<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string, NsId extends string = never> = [NsId] extends [never] ? never : RelationsOf<TContract, ModelName, NsId> extends (infer Rels) ? Rels extends Record<string, unknown> ? RelName extends keyof Rels ? Rels[RelName] extends {
|
|
557
|
+
readonly to: {
|
|
558
|
+
readonly namespace: infer N extends string;
|
|
559
|
+
};
|
|
560
|
+
} ? N : never : never : never : never;
|
|
561
|
+
type RelationCardinalityFromRelation<Relation> = Relation extends {
|
|
562
|
+
readonly cardinality: infer Cardinality extends RelationCardinalityTag;
|
|
563
|
+
} ? Cardinality : '1:N';
|
|
564
|
+
type RelationCardinality<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string, NsId extends string = never> = RelationsOf<TContract, ModelName, NsId> extends (infer Rels) ? Rels extends Record<string, unknown> ? RelName extends keyof Rels ? RelationCardinalityFromRelation<Rels[RelName]> : '1:N' : '1:N' : '1:N';
|
|
565
|
+
type RelationLocalFieldColumns<TContract extends Contract<SqlStorage>, ModelName extends string, Relation> = Relation extends {
|
|
566
|
+
readonly on: {
|
|
567
|
+
readonly localFields: infer Fields extends readonly string[];
|
|
568
|
+
};
|
|
569
|
+
} ? MapFieldsToColumns<TContract, ModelName, Fields> : readonly [];
|
|
570
|
+
type MapFieldsToColumns<TContract extends Contract<SqlStorage>, ModelName extends string, Fields extends readonly string[]> = Fields extends readonly [infer Head extends string, ...infer Tail extends string[]] ? readonly [FieldColumnName<TContract, ModelName, Head>, ...MapFieldsToColumns<TContract, ModelName, Tail>] : readonly [];
|
|
571
|
+
type AnyColumnNullable<Columns extends Record<string, StorageColumn>, ColNames extends readonly string[]> = ColNames extends readonly [infer Head extends string, ...infer Tail extends string[]] ? Head extends keyof Columns ? Columns[Head]['nullable'] extends true ? true : AnyColumnNullable<Columns, Tail> : true : false;
|
|
572
|
+
type HasForeignKeyForCols<FKs extends readonly unknown[], Cols extends readonly string[]> = FKs extends readonly [infer Head, ...infer Tail extends unknown[]] ? Head extends {
|
|
573
|
+
readonly source: {
|
|
574
|
+
readonly columns: Cols;
|
|
575
|
+
};
|
|
576
|
+
} ? true : HasForeignKeyForCols<Tail, Cols> : false;
|
|
577
|
+
type IsFkSideOfRelation<Table extends StorageTable, ParentCols extends readonly string[]> = Table extends {
|
|
578
|
+
readonly foreignKeys: infer FKs extends readonly unknown[];
|
|
579
|
+
} ? HasForeignKeyForCols<FKs, ParentCols> : false;
|
|
580
|
+
type IsToOneRelationNullable<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string, NsId extends string = never> = ModelTableName<TContract, ModelName, NsId> extends (infer TableName extends string) ? NamespaceTableDef<TContract, TableName, ResolvedNsId<TContract, ModelName, NsId>> extends (infer Table extends StorageTable) ? RelationsOf<TContract, ModelName, NsId> extends (infer Rels extends Record<string, unknown>) ? RelName extends keyof Rels ? RelationLocalFieldColumns<TContract, ModelName, Rels[RelName]> extends (infer Cols extends readonly string[]) ? IsFkSideOfRelation<Table, Cols> extends true ? AnyColumnNullable<Table['columns'], Cols> : true : true : true : true : true : true;
|
|
581
|
+
type IncludeRelationValue<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string, IncludedRow, NsId extends string = never> = RelationCardinality<TContract, ModelName, RelName, NsId> extends '1:1' | 'N:1' ? IsToOneRelationNullable<TContract, ModelName, RelName, NsId> extends true ? IncludedRow | null : IncludedRow : IncludedRow[];
|
|
582
|
+
type CollectionModelName<TContract extends Contract<SqlStorage>> = { [Ns in keyof TContract['domain']['namespaces']]: keyof TContract['domain']['namespaces'][Ns]['models'] & string; }[keyof TContract['domain']['namespaces']];
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/collection-internal-types.d.ts
|
|
585
|
+
interface CollectionInit<TContract extends Contract<SqlStorage>> {
|
|
586
|
+
readonly tableName?: string | undefined;
|
|
587
|
+
readonly namespaceId: string;
|
|
588
|
+
readonly state?: CollectionState | undefined;
|
|
589
|
+
readonly registry?: ReadonlyMap<string, CollectionConstructor<TContract>> | undefined;
|
|
590
|
+
readonly includeRefinementMode?: boolean | undefined;
|
|
591
|
+
}
|
|
592
|
+
type CollectionConstructor<TContract extends Contract<SqlStorage>> = new (ctx: CollectionContext<TContract>, modelName: string, options?: CollectionInit<TContract>) => Collection<TContract, string, unknown, CollectionTypeState>;
|
|
593
|
+
type WithWhereState<State extends CollectionTypeState> = Omit<State, 'hasWhere'> & {
|
|
594
|
+
readonly hasWhere: true;
|
|
595
|
+
};
|
|
596
|
+
type WithOrderByState<State extends CollectionTypeState> = Omit<State, 'hasOrderBy'> & {
|
|
597
|
+
readonly hasOrderBy: true;
|
|
598
|
+
};
|
|
599
|
+
type WithVariantState<State extends CollectionTypeState, V extends string> = Omit<State, 'variantName'> & {
|
|
600
|
+
readonly variantName: V;
|
|
601
|
+
};
|
|
602
|
+
type IncludedRelationsForRow<TContract extends Contract<SqlStorage>, ModelName extends string, Row> = Omit<Row, keyof DefaultModelRow<TContract, ModelName>>;
|
|
603
|
+
type IncludeRefinementTerminals = 'all' | 'first' | 'aggregate' | 'groupBy' | 'create' | 'createAll' | 'createAndCount' | 'update' | 'updateAll' | 'updateAndCount' | 'delete' | 'deleteAll' | 'deleteAndCount' | 'upsert';
|
|
604
|
+
type IncludeRefinementScalarMethods = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'combine';
|
|
605
|
+
type IncludeRefinementCollection<TContract extends Contract<SqlStorage>, ModelName extends string, Row, State extends CollectionTypeState, IsToMany extends boolean> = Omit<Collection<TContract, ModelName, Row, State>, IncludeRefinementTerminals | (IsToMany extends true ? never : IncludeRefinementScalarMethods)>;
|
|
606
|
+
type IsToManyRelation<TContract extends Contract<SqlStorage>, ModelName extends string, RelName extends string, NsId extends string = never> = RelationCardinality<TContract, ModelName, RelName, NsId> extends '1:N' | 'N:M' ? true : false;
|
|
607
|
+
type IncludeRefinementResult<TContract extends Contract<SqlStorage>, RelatedName extends string, IsToMany extends boolean> = IncludeRefinementCollection<TContract, RelatedName, unknown, CollectionTypeState, IsToMany> | (IsToMany extends true ? IncludeScalar<unknown> | IncludeCombine<Record<string, unknown>> : never);
|
|
608
|
+
declare const RowType: unique symbol;
|
|
609
|
+
interface RowSelection<T> {
|
|
610
|
+
[RowType]: T;
|
|
611
|
+
}
|
|
612
|
+
type IncludeRefinementValue<TContract extends Contract<SqlStorage>, ParentModelName extends string, RelName extends string, DefaultIncludedRow, RefinedResult, NsId extends string = never> = RefinedResult extends RowSelection<infer V> ? RefinedResult extends {
|
|
613
|
+
readonly kind: 'includeScalar' | 'includeCombine';
|
|
614
|
+
} ? V : IncludeRelationValue<TContract, ParentModelName, RelName, V, NsId> : IncludeRelationValue<TContract, ParentModelName, RelName, DefaultIncludedRow, NsId>;
|
|
615
|
+
//#endregion
|
|
616
|
+
//#region src/grouped-collection.d.ts
|
|
617
|
+
interface GroupedCollectionInit {
|
|
618
|
+
readonly tableName: string;
|
|
619
|
+
readonly namespaceId: string;
|
|
620
|
+
readonly baseFilters: readonly AnyExpression[];
|
|
621
|
+
readonly groupByFields: readonly string[];
|
|
622
|
+
readonly groupByColumns: readonly string[];
|
|
623
|
+
readonly havingFilters: readonly AnyExpression[];
|
|
624
|
+
}
|
|
625
|
+
type GroupByFieldName<TContract extends Contract<SqlStorage>, ModelName extends string> = keyof DefaultModelRow<TContract, ModelName> & string;
|
|
626
|
+
declare class GroupedCollection<TContract extends Contract<SqlStorage>, ModelName extends string, GroupFields extends readonly GroupByFieldName<TContract, ModelName>[]> {
|
|
627
|
+
readonly ctx: CollectionContext<TContract>;
|
|
628
|
+
private readonly contract;
|
|
629
|
+
readonly modelName: ModelName;
|
|
630
|
+
readonly tableName: string;
|
|
631
|
+
readonly namespaceId: string;
|
|
632
|
+
readonly baseFilters: readonly AnyExpression[];
|
|
633
|
+
readonly groupByFields: readonly string[];
|
|
634
|
+
readonly groupByColumns: readonly string[];
|
|
635
|
+
readonly havingFilters: readonly AnyExpression[];
|
|
636
|
+
constructor(ctx: CollectionContext<TContract>, modelName: ModelName, options: GroupedCollectionInit);
|
|
637
|
+
having(predicate: (having: HavingBuilder<TContract, ModelName>) => AnyExpression): GroupedCollection<TContract, ModelName, GroupFields>;
|
|
638
|
+
/**
|
|
639
|
+
* Read terminal: run a grouped aggregate query.
|
|
640
|
+
*
|
|
641
|
+
* Accepts an optional `configure` callback that receives a
|
|
642
|
+
* `MetaBuilder<'read'>` for attaching typed annotations.
|
|
643
|
+
* Annotations are merged into the compiled plan's `meta.annotations`.
|
|
644
|
+
*/
|
|
645
|
+
aggregate<Spec extends AggregateSpec>(fn: (aggregate: AggregateBuilder<TContract, ModelName>) => Spec, configure?: (meta: MetaBuilder<'read'>) => void): Promise<Array<SimplifyDeep<Pick<DefaultModelRow<TContract, ModelName>, GroupFields[number]> & AggregateResult<Spec>>>>;
|
|
646
|
+
}
|
|
647
|
+
//#endregion
|
|
648
|
+
//#region src/collection.d.ts
|
|
649
|
+
type WhereDirectInput = WhereArg;
|
|
650
|
+
declare class Collection<TContract extends Contract<SqlStorage>, ModelName extends string, Row = SimplifyDeep<InferRootRow<TContract, ModelName>>, State extends CollectionTypeState = DefaultCollectionTypeState> implements RowSelection<Row> {
|
|
651
|
+
#private;
|
|
652
|
+
readonly [RowType]: Row;
|
|
653
|
+
/** @internal */
|
|
654
|
+
readonly ctx: CollectionContext<TContract>;
|
|
655
|
+
/** @internal */
|
|
656
|
+
private readonly contract;
|
|
657
|
+
/** @internal */
|
|
658
|
+
readonly modelName: ModelName;
|
|
659
|
+
/** @internal */
|
|
660
|
+
readonly tableName: string;
|
|
661
|
+
/** @internal */
|
|
662
|
+
readonly namespaceId: string;
|
|
663
|
+
/** @internal */
|
|
664
|
+
readonly state: CollectionState;
|
|
665
|
+
/** @internal */
|
|
666
|
+
readonly registry: ReadonlyMap<string, CollectionConstructor<TContract>>;
|
|
667
|
+
/** @internal */
|
|
668
|
+
readonly includeRefinementMode: boolean;
|
|
669
|
+
constructor(ctx: CollectionContext<TContract>, modelName: ModelName, options: CollectionInit<TContract>);
|
|
670
|
+
/**
|
|
671
|
+
* Narrow the collection with a `WHERE` predicate. Returns a new
|
|
672
|
+
* collection — chain further builders or run a terminal on it.
|
|
673
|
+
*
|
|
674
|
+
* Accepts a callback receiving a typed model accessor, a raw
|
|
675
|
+
* `WhereArg` expression, or a shorthand field/value object. Multiple
|
|
676
|
+
* calls are AND-combined.
|
|
677
|
+
*
|
|
678
|
+
* ```typescript
|
|
679
|
+
* // Callback form with column-level operators:
|
|
680
|
+
* const matches = await db.orm.User.where((u) => u.email.eq('alice@example.com')).all();
|
|
681
|
+
*
|
|
682
|
+
* // Shorthand object form:
|
|
683
|
+
* const user = await db.orm.User.where({ id: 1, active: true }).first();
|
|
684
|
+
*
|
|
685
|
+
* // Chained AND — still a builder, run a terminal to execute:
|
|
686
|
+
* const adults = await db.orm.User.where({ active: true }).where((u) => u.age.gt(18)).all();
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
where(fn: (model: VariantAwareModelAccessor<TContract, ModelName, State['variantName'], State['nsId']>) => WhereDirectInput): Collection<TContract, ModelName, Row, WithWhereState<State>>;
|
|
690
|
+
where(input: WhereDirectInput): Collection<TContract, ModelName, Row, WithWhereState<State>>;
|
|
691
|
+
where(fn: (model: VariantAwareModelAccessor<TContract, ModelName, State['variantName'], State['nsId']>) => WhereArg): Collection<TContract, ModelName, Row, WithWhereState<State>>;
|
|
692
|
+
where(filters: ShorthandWhereFilter<TContract, ModelName, State['nsId']>): Collection<TContract, ModelName, Row, WithWhereState<State>>;
|
|
693
|
+
/**
|
|
694
|
+
* Narrow a polymorphic model to a specific variant. The returned
|
|
695
|
+
* collection has the variant's row shape and a discriminator filter
|
|
696
|
+
* is automatically applied. Chaining `.variant(...)` again replaces
|
|
697
|
+
* the previous variant filter.
|
|
698
|
+
*
|
|
699
|
+
* ```typescript
|
|
700
|
+
* // Read only admin users (STI):
|
|
701
|
+
* const admins = await db.orm.User.variant('Admin').all();
|
|
702
|
+
*
|
|
703
|
+
* // Iterate the rows:
|
|
704
|
+
* for await (const admin of db.orm.User.variant('Admin').all()) {
|
|
705
|
+
* console.log(admin.role);
|
|
706
|
+
* }
|
|
707
|
+
*
|
|
708
|
+
* // Insert under a variant — discriminator is injected automatically:
|
|
709
|
+
* await db.orm.User.variant('Admin').create({ name: 'Ada', role: 'super' });
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
variant<V extends VariantNames<TContract, ModelName>>(variantName: V): Collection<TContract, ModelName, VariantModelRow<TContract, ModelName, V>, WithVariantState<WithWhereState<State>, V>>;
|
|
713
|
+
/**
|
|
714
|
+
* Eagerly load a related model. The relation appears on every
|
|
715
|
+
* returned row under its declared name; to-one relations are mapped
|
|
716
|
+
* to a single object (or `null`), to-many relations to an array.
|
|
717
|
+
*
|
|
718
|
+
* An optional refinement callback receives a child collection that
|
|
719
|
+
* can be further constrained, projected, ordered, paginated, or
|
|
720
|
+
* reduced to scalars via `count()`/`sum()`/etc. or to multiple
|
|
721
|
+
* sub-aggregates via `combine()`.
|
|
722
|
+
*
|
|
723
|
+
* ```typescript
|
|
724
|
+
* // Simple include — every user comes back with its posts array:
|
|
725
|
+
* const users = await db.orm.User.include('posts').all();
|
|
726
|
+
*
|
|
727
|
+
* // Refine the related collection:
|
|
728
|
+
* const withRecent = await db.orm.User.include('posts', (posts) =>
|
|
729
|
+
* posts.where({ published: true }).orderBy((p) => p.createdAt.desc()).take(5),
|
|
730
|
+
* ).all();
|
|
731
|
+
*
|
|
732
|
+
* // Reduce a to-many relation to a scalar value:
|
|
733
|
+
* const withCounts = await db.orm.User.include('posts', (posts) => posts.count()).all();
|
|
734
|
+
*
|
|
735
|
+
* // Multiple sub-views via combine():
|
|
736
|
+
* const overview = await db.orm.User.include('posts', (posts) =>
|
|
737
|
+
* posts.combine({ recent: posts.take(3), total: posts.count() }),
|
|
738
|
+
* ).all();
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
include<RelName extends VariantAwareIncludeRelationNames<TContract, ModelName, State['variantName'], State['nsId']>, RelationOwner extends string = IncludeRelationOwner<TContract, ModelName, State['variantName'], RelName, State['nsId']> & string, RelatedName extends RelatedModelName<TContract, RelationOwner, RelName, State['nsId']> & string = RelatedModelName<TContract, RelationOwner, RelName, State['nsId']> & string, TargetNs extends string = RelationTargetNamespace<TContract, RelationOwner, RelName, State['nsId']>, IsToMany extends boolean = IsToManyRelation<TContract, RelationOwner, RelName, State['nsId']>, RefinedResult extends IncludeRefinementResult<TContract, RelatedName, IsToMany> = IncludeRefinementCollection<TContract, RelatedName, SimplifyDeep<InferRootRow<TContract, RelatedName, TargetNs>>, CollectionTypeState, IsToMany>>(relationName: RelName, refineFn?: (collection: IncludeRefinementCollection<TContract, RelatedName, SimplifyDeep<InferRootRow<TContract, RelatedName, TargetNs>>, DefaultCollectionTypeState, IsToMany>) => RefinedResult): Collection<TContract, ModelName, SimplifyDeep<Row & { [K in RelName]: IncludeRefinementValue<TContract, RelationOwner, K, SimplifyDeep<InferRootRow<TContract, RelatedName, TargetNs>>, RefinedResult, State['nsId']>; }>, State>;
|
|
742
|
+
/**
|
|
743
|
+
* Project the row down to a subset of scalar fields. Previously
|
|
744
|
+
* included relations are preserved on the resulting row shape; only
|
|
745
|
+
* scalar columns are narrowed.
|
|
746
|
+
*
|
|
747
|
+
* ```typescript
|
|
748
|
+
* const summaries = await db.orm.User.select('id', 'email').all();
|
|
749
|
+
* // typeof summaries[number] === { id: ...; email: ... }
|
|
750
|
+
*
|
|
751
|
+
* for await (const row of db.orm.User.select('id', 'email').all()) {
|
|
752
|
+
* console.log(row.id, row.email);
|
|
753
|
+
* }
|
|
754
|
+
* ```
|
|
755
|
+
*/
|
|
756
|
+
select<Fields extends readonly [keyof DefaultModelRow<TContract, ModelName> & string, ...(keyof DefaultModelRow<TContract, ModelName> & string)[]]>(...fields: Fields): Collection<TContract, ModelName, SimplifyDeep<Pick<DefaultModelRow<TContract, ModelName>, Fields[number]> & IncludedRelationsForRow<TContract, ModelName, Row>>, State>;
|
|
757
|
+
/**
|
|
758
|
+
* Append an `ORDER BY` clause. Pass a single selector callback or an
|
|
759
|
+
* array of callbacks; each receives a typed model accessor whose
|
|
760
|
+
* columns expose `.asc()` and `.desc()`. Multiple calls append to the
|
|
761
|
+
* existing list (left-to-right ordering preserved).
|
|
762
|
+
*
|
|
763
|
+
* Calling `orderBy(...)` unlocks `cursor(...)` and `distinctOn(...)`,
|
|
764
|
+
* which both require a defined sort order.
|
|
765
|
+
*
|
|
766
|
+
* ```typescript
|
|
767
|
+
* const newest = await db.orm.User.orderBy((u) => u.createdAt.desc()).all();
|
|
768
|
+
*
|
|
769
|
+
* const byName = await db.orm.User
|
|
770
|
+
* .orderBy([(u) => u.lastName.asc(), (u) => u.firstName.asc()])
|
|
771
|
+
* .all();
|
|
772
|
+
* ```
|
|
773
|
+
*/
|
|
774
|
+
orderBy(selection: ((model: VariantAwareModelAccessor<TContract, ModelName, State['variantName']>) => OrderByItem) | ReadonlyArray<(model: VariantAwareModelAccessor<TContract, ModelName, State['variantName']>) => OrderByItem>): Collection<TContract, ModelName, Row, WithOrderByState<State>>;
|
|
775
|
+
/**
|
|
776
|
+
* Switch to grouped-aggregate mode. Returns a `GroupedCollection`
|
|
777
|
+
* whose `.aggregate(...)` terminal produces one row per group with
|
|
778
|
+
* the chosen key columns plus the requested aggregates.
|
|
779
|
+
*
|
|
780
|
+
* ```typescript
|
|
781
|
+
* const stats = await db.orm.Post
|
|
782
|
+
* .where({ published: true })
|
|
783
|
+
* .groupBy('userId')
|
|
784
|
+
* .aggregate((agg) => ({ count: agg.count(), totalViews: agg.sum('views') }));
|
|
785
|
+
* // [{ userId: 1, count: 3, totalViews: 120 }, ...]
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
groupBy<Fields extends readonly [keyof DefaultModelRow<TContract, ModelName> & string, ...(keyof DefaultModelRow<TContract, ModelName> & string)[]]>(...fields: Fields): GroupedCollection<TContract, ModelName, Fields>;
|
|
789
|
+
/**
|
|
790
|
+
* Scalar reducer — reduces a to-many relation to the number of
|
|
791
|
+
* related rows. Use inside an `include(...)` refinement callback as
|
|
792
|
+
* `include(..., (rel) => rel.count())`; throws if called elsewhere.
|
|
793
|
+
* The parent row's relation field becomes that count instead of an
|
|
794
|
+
* array.
|
|
795
|
+
*
|
|
796
|
+
* ```typescript
|
|
797
|
+
* const users = await db.orm.User.include('posts', (posts) => posts.count()).all();
|
|
798
|
+
* // each user row: { ...user, posts: number }
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
count(): IncludeScalar<number>;
|
|
802
|
+
/**
|
|
803
|
+
* Scalar reducer — reduces a to-many relation to the sum of `field`
|
|
804
|
+
* across related rows. Returns `null` when there are no related
|
|
805
|
+
* rows. Use inside an `include(...)` refinement callback; throws if
|
|
806
|
+
* called elsewhere.
|
|
807
|
+
*
|
|
808
|
+
* ```typescript
|
|
809
|
+
* const users = await db.orm.User.include('posts', (posts) => posts.sum('views')).all();
|
|
810
|
+
* // each user row: { ...user, posts: number | null }
|
|
811
|
+
* ```
|
|
812
|
+
*/
|
|
813
|
+
sum<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): IncludeScalar<number | null>;
|
|
814
|
+
/**
|
|
815
|
+
* Scalar reducer — reduces a to-many relation to the average of
|
|
816
|
+
* `field` across related rows. Returns `null` when there are no
|
|
817
|
+
* related rows. Use inside an `include(...)` refinement callback;
|
|
818
|
+
* throws if called elsewhere.
|
|
819
|
+
*
|
|
820
|
+
* ```typescript
|
|
821
|
+
* const users = await db.orm.User.include('posts', (posts) => posts.avg('views')).all();
|
|
822
|
+
* // each user row: { ...user, posts: number | null }
|
|
823
|
+
* ```
|
|
824
|
+
*/
|
|
825
|
+
avg<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): IncludeScalar<number | null>;
|
|
826
|
+
/**
|
|
827
|
+
* Scalar reducer — reduces a to-many relation to the minimum value
|
|
828
|
+
* of `field` across related rows. Returns `null` when there are no
|
|
829
|
+
* related rows. Use inside an `include(...)` refinement callback;
|
|
830
|
+
* throws if called elsewhere.
|
|
831
|
+
*
|
|
832
|
+
* ```typescript
|
|
833
|
+
* const users = await db.orm.User.include('posts', (posts) => posts.min('views')).all();
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
min<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): IncludeScalar<number | null>;
|
|
837
|
+
/**
|
|
838
|
+
* Scalar reducer — reduces a to-many relation to the maximum value
|
|
839
|
+
* of `field` across related rows. Returns `null` when there are no
|
|
840
|
+
* related rows. Use inside an `include(...)` refinement callback;
|
|
841
|
+
* throws if called elsewhere.
|
|
842
|
+
*
|
|
843
|
+
* ```typescript
|
|
844
|
+
* const users = await db.orm.User.include('posts', (posts) => posts.max('views')).all();
|
|
845
|
+
* ```
|
|
846
|
+
*/
|
|
847
|
+
max<FieldName extends NumericFieldNames<TContract, ModelName>>(field: FieldName): IncludeScalar<number | null>;
|
|
848
|
+
/**
|
|
849
|
+
* Produce multiple named sub-views of a to-many relation in a
|
|
850
|
+
* single `include(...)`. Each branch is either another refined
|
|
851
|
+
* collection (mapped to a row array on the parent) or a scalar
|
|
852
|
+
* reducer such as `count()`/`sum(...)`. Only valid inside an
|
|
853
|
+
* `include(...)` refinement callback for to-many relations.
|
|
854
|
+
*
|
|
855
|
+
* ```typescript
|
|
856
|
+
* const users = await db.orm.User.include('posts', (posts) =>
|
|
857
|
+
* posts.combine({
|
|
858
|
+
* recent: posts.where({ published: true }).take(3),
|
|
859
|
+
* total: posts.count(),
|
|
860
|
+
* averageViews: posts.avg('views'),
|
|
861
|
+
* }),
|
|
862
|
+
* ).all();
|
|
863
|
+
* // each user row: {
|
|
864
|
+
* // ...user,
|
|
865
|
+
* // posts: { recent: Post[]; total: number; averageViews: number | null };
|
|
866
|
+
* // }
|
|
867
|
+
* ```
|
|
868
|
+
*/
|
|
869
|
+
combine<Spec extends Record<string, Collection<TContract, ModelName, unknown, CollectionTypeState> | IncludeScalar<unknown>>>(spec: Spec): IncludeCombine<{ [K in keyof Spec]: Spec[K] extends IncludeScalar<infer ScalarResult> ? ScalarResult : Spec[K] extends Collection<TContract, ModelName, infer BranchRow, CollectionTypeState> ? BranchRow[] : never; }>;
|
|
870
|
+
/**
|
|
871
|
+
* Resume pagination from a known cursor position. Requires a prior
|
|
872
|
+
* `orderBy(...)` so the cursor has a stable basis; provide a value
|
|
873
|
+
* for every column referenced by the active `orderBy(...)` so each
|
|
874
|
+
* ordered axis has a defined boundary.
|
|
875
|
+
*
|
|
876
|
+
* ```typescript
|
|
877
|
+
* const page1 = await db.orm.Post
|
|
878
|
+
* .orderBy((p) => p.createdAt.desc())
|
|
879
|
+
* .take(20)
|
|
880
|
+
* .all();
|
|
881
|
+
*
|
|
882
|
+
* const last = page1[page1.length - 1]!;
|
|
883
|
+
* const page2 = await db.orm.Post
|
|
884
|
+
* .orderBy((p) => p.createdAt.desc())
|
|
885
|
+
* .cursor({ createdAt: last.createdAt })
|
|
886
|
+
* .take(20)
|
|
887
|
+
* .all();
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
cursor(cursorValues: State['hasOrderBy'] extends true ? Partial<Record<keyof DefaultModelRow<TContract, ModelName> & string, unknown>> : never): Collection<TContract, ModelName, Row, State>;
|
|
891
|
+
/**
|
|
892
|
+
* Emit `SELECT DISTINCT` keyed on the given fields. Replaces any
|
|
893
|
+
* previous `distinct(...)` / `distinctOn(...)` selection.
|
|
894
|
+
*
|
|
895
|
+
* ```typescript
|
|
896
|
+
* const groups = await db.orm.User.distinct('country', 'role').all();
|
|
897
|
+
* ```
|
|
898
|
+
*/
|
|
899
|
+
distinct<Fields extends readonly [keyof DefaultModelRow<TContract, ModelName> & string, ...(keyof DefaultModelRow<TContract, ModelName> & string)[]]>(...fields: Fields): Collection<TContract, ModelName, Row, State>;
|
|
900
|
+
/**
|
|
901
|
+
* Emit `SELECT DISTINCT ON (fields)` — keep the first row per
|
|
902
|
+
* distinct key according to the current `orderBy(...)`. Requires a
|
|
903
|
+
* prior `orderBy(...)`; replaces any previous `distinct(...)` /
|
|
904
|
+
* `distinctOn(...)` selection.
|
|
905
|
+
*
|
|
906
|
+
* ```typescript
|
|
907
|
+
* // Latest post per user:
|
|
908
|
+
* const latestPerUser = await db.orm.Post
|
|
909
|
+
* .orderBy([(p) => p.userId.asc(), (p) => p.createdAt.desc()])
|
|
910
|
+
* .distinctOn('userId')
|
|
911
|
+
* .all();
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
distinctOn<Fields extends readonly [keyof DefaultModelRow<TContract, ModelName> & string, ...(keyof DefaultModelRow<TContract, ModelName> & string)[]]>(...fields: State['hasOrderBy'] extends true ? Fields : never): Collection<TContract, ModelName, Row, State>;
|
|
915
|
+
/**
|
|
916
|
+
* Apply `LIMIT n`. Replaces any previous limit set on this collection.
|
|
917
|
+
*
|
|
918
|
+
* ```typescript
|
|
919
|
+
* const firstTen = await db.orm.User.orderBy((u) => u.id.asc()).take(10).all();
|
|
920
|
+
* ```
|
|
921
|
+
*/
|
|
922
|
+
take(n: number): Collection<TContract, ModelName, Row, State>;
|
|
923
|
+
/**
|
|
924
|
+
* Apply `OFFSET n`. Replaces any previous offset set on this collection.
|
|
925
|
+
*
|
|
926
|
+
* ```typescript
|
|
927
|
+
* const page2 = await db.orm.User
|
|
928
|
+
* .orderBy((u) => u.id.asc())
|
|
929
|
+
* .skip(10)
|
|
930
|
+
* .take(10)
|
|
931
|
+
* .all();
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
skip(n: number): Collection<TContract, ModelName, Row, State>;
|
|
935
|
+
/**
|
|
936
|
+
* Read terminal: execute the query and stream every matching row.
|
|
937
|
+
*
|
|
938
|
+
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
939
|
+
* resolves to `Row[]` (so `await` collects all rows into an array)
|
|
940
|
+
* AND an async iterable (so `for await` streams rows as they
|
|
941
|
+
* arrive, without buffering the whole result set in memory). Pick
|
|
942
|
+
* whichever fits the caller. A single result can only be consumed
|
|
943
|
+
* once.
|
|
944
|
+
*
|
|
945
|
+
* Streaming is the default and the expected execution model. The
|
|
946
|
+
* only scenarios that fall back to buffering internally before
|
|
947
|
+
* yielding are drivers that cannot expose a cursor to the
|
|
948
|
+
* underlying database, and — for queries with `include(...)` —
|
|
949
|
+
* targets whose SQL dialect supports neither lateral joins nor
|
|
950
|
+
* correlated subqueries (so child rows cannot be stitched in a
|
|
951
|
+
* single streaming query). These are implementation details below
|
|
952
|
+
* the public API; the iteration shape itself is genuinely
|
|
953
|
+
* streaming whenever the driver and plan allow it.
|
|
954
|
+
*
|
|
955
|
+
* ```typescript
|
|
956
|
+
* // Thenable — collect to an array:
|
|
957
|
+
* const users = await db.orm.User.all();
|
|
958
|
+
* for (const user of users) console.log(user.id);
|
|
959
|
+
*
|
|
960
|
+
* // Async iterable — stream rows as they arrive:
|
|
961
|
+
* for await (const user of db.orm.User.all()) {
|
|
962
|
+
* console.log(user.id);
|
|
963
|
+
* }
|
|
964
|
+
* ```
|
|
965
|
+
*
|
|
966
|
+
* Accepts an optional `configure` callback that receives a
|
|
967
|
+
* `MetaBuilder<'read'>` so the caller can attach typed user
|
|
968
|
+
* annotations to the executed plan. `meta.annotate(...)` enforces
|
|
969
|
+
* applicability at the type level and at runtime; annotations are
|
|
970
|
+
* merged into `plan.meta.annotations` at compile time.
|
|
971
|
+
*
|
|
972
|
+
* ```typescript
|
|
973
|
+
* await db.orm.User.all((meta) => meta.annotate(cacheAnnotation({ ttl: 60 })));
|
|
974
|
+
* ```
|
|
975
|
+
*/
|
|
976
|
+
all(configure?: (meta: MetaBuilder<'read'>) => void): AsyncIterableResult<Row>;
|
|
977
|
+
/**
|
|
978
|
+
* Read terminal: return the first matching row, or `null` if none
|
|
979
|
+
* match. Optionally accepts a filter (callback or shorthand object)
|
|
980
|
+
* followed by a `configure` callback for typed read annotations.
|
|
981
|
+
*
|
|
982
|
+
* To attach annotations without further narrowing, pass `undefined`
|
|
983
|
+
* as the filter (or chain `.where(...)` first):
|
|
984
|
+
*
|
|
985
|
+
* ```typescript
|
|
986
|
+
* // No filter — first row in the collection:
|
|
987
|
+
* const someone = await db.orm.User.first();
|
|
988
|
+
*
|
|
989
|
+
* // Shorthand filter:
|
|
990
|
+
* const alice = await db.orm.User.first({ email: 'alice@example.com' });
|
|
991
|
+
*
|
|
992
|
+
* // Callback filter:
|
|
993
|
+
* const old = await db.orm.User.first((u) => u.age.gt(60));
|
|
994
|
+
*
|
|
995
|
+
* // Annotate without filtering further:
|
|
996
|
+
* await db.orm.User.first(undefined, (meta) =>
|
|
997
|
+
* meta.annotate(cacheAnnotation({ ttl: 60 })),
|
|
998
|
+
* );
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
first(): Promise<Row | null>;
|
|
1002
|
+
first(filter: undefined, configure: (meta: MetaBuilder<'read'>) => void): Promise<Row | null>;
|
|
1003
|
+
first(filter: (model: VariantAwareModelAccessor<TContract, ModelName, State['variantName'], State['nsId']>) => WhereArg, configure?: (meta: MetaBuilder<'read'>) => void): Promise<Row | null>;
|
|
1004
|
+
first(filter: ShorthandWhereFilter<TContract, ModelName, State['nsId']>, configure?: (meta: MetaBuilder<'read'>) => void): Promise<Row | null>;
|
|
1005
|
+
/**
|
|
1006
|
+
* Read terminal: run an aggregate query (count, sum, avg, min, max)
|
|
1007
|
+
* built via the `AggregateBuilder` callback. Returns one object
|
|
1008
|
+
* with the requested aggregate values keyed by the aliases supplied
|
|
1009
|
+
* in the spec.
|
|
1010
|
+
*
|
|
1011
|
+
* ```typescript
|
|
1012
|
+
* const stats = await db.orm.Post
|
|
1013
|
+
* .where({ published: true })
|
|
1014
|
+
* .aggregate((agg) => ({
|
|
1015
|
+
* total: agg.count(),
|
|
1016
|
+
* averageViews: agg.avg('views'),
|
|
1017
|
+
* maxViews: agg.max('views'),
|
|
1018
|
+
* }));
|
|
1019
|
+
* // { total: 42, averageViews: 17.3, maxViews: 9001 }
|
|
1020
|
+
* ```
|
|
1021
|
+
*
|
|
1022
|
+
* Accepts an optional `configure` callback that receives a
|
|
1023
|
+
* `MetaBuilder<'read'>` for attaching typed annotations.
|
|
1024
|
+
* Annotations are merged into the compiled plan's `meta.annotations`.
|
|
1025
|
+
*/
|
|
1026
|
+
aggregate<Spec extends AggregateSpec>(fn: (aggregate: AggregateBuilder<TContract, ModelName>) => Spec, configure?: (meta: MetaBuilder<'read'>) => void): Promise<AggregateResult<Spec>>;
|
|
1027
|
+
/**
|
|
1028
|
+
* Write terminal: insert one row and return it (with any configured
|
|
1029
|
+
* `select(...)` / `include(...)` projections applied to the returned
|
|
1030
|
+
* shape).
|
|
1031
|
+
*
|
|
1032
|
+
* Related rows can be created or linked through relation callbacks
|
|
1033
|
+
* on parent/child-owned relations (one-to-one or one-to-many).
|
|
1034
|
+
* The callback receives a mutator exposing `create(...)` and
|
|
1035
|
+
* `connect(...)`; `disconnect(...)` is only supported in nested
|
|
1036
|
+
* `update(...)` mutations. Many-to-many relations are not yet
|
|
1037
|
+
* supported as nested-mutation targets.
|
|
1038
|
+
*
|
|
1039
|
+
* ```typescript
|
|
1040
|
+
* // Simple insert:
|
|
1041
|
+
* const user = await db.orm.User.create({
|
|
1042
|
+
* email: 'alice@example.com',
|
|
1043
|
+
* name: 'Alice',
|
|
1044
|
+
* });
|
|
1045
|
+
*
|
|
1046
|
+
* // Nested create on a child-owned to-many relation:
|
|
1047
|
+
* const author = await db.orm.User.create({
|
|
1048
|
+
* email: 'bob@example.com',
|
|
1049
|
+
* posts: (posts) => posts.create([
|
|
1050
|
+
* { title: 'Hello' },
|
|
1051
|
+
* { title: 'World' },
|
|
1052
|
+
* ]),
|
|
1053
|
+
* });
|
|
1054
|
+
*
|
|
1055
|
+
* // Connect a child-owned post to an existing parent author:
|
|
1056
|
+
* const reply = await db.orm.Post.create({
|
|
1057
|
+
* title: 'Re: Hello',
|
|
1058
|
+
* author: (author) => author.connect({ id: 1 }),
|
|
1059
|
+
* });
|
|
1060
|
+
* ```
|
|
1061
|
+
*
|
|
1062
|
+
* Accepts an optional `configure` callback that receives a
|
|
1063
|
+
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
1064
|
+
* Annotations are merged into the compiled mutation plan's
|
|
1065
|
+
* `meta.annotations`.
|
|
1066
|
+
*
|
|
1067
|
+
* Note: when the input contains nested-mutation callbacks, the
|
|
1068
|
+
* operation is executed as a graph of internal queries via
|
|
1069
|
+
* `withMutationScope`. In that path, annotations apply to the
|
|
1070
|
+
* logical `create()` call but do not currently flow into each
|
|
1071
|
+
* constituent SQL statement issued for the related rows.
|
|
1072
|
+
*/
|
|
1073
|
+
create(data: ResolvedCreateInput<TContract, ModelName, State['variantName'], State['nsId']>, configure?: (meta: MetaBuilder<'write'>) => void): Promise<Row>;
|
|
1074
|
+
create(data: MutationCreateInputWithRelations<TContract, ModelName, State['nsId']>, configure?: (meta: MetaBuilder<'write'>) => void): Promise<Row>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Write terminal: insert many rows and stream the inserted rows.
|
|
1077
|
+
*
|
|
1078
|
+
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
1079
|
+
* resolves to `Row[]` AND an async iterable that streams inserted
|
|
1080
|
+
* rows as they arrive. Use whichever shape fits the caller — but
|
|
1081
|
+
* only consume it once. Streaming is the default; some
|
|
1082
|
+
* driver/plan combinations may still buffer internally before
|
|
1083
|
+
* yielding.
|
|
1084
|
+
*
|
|
1085
|
+
* ```typescript
|
|
1086
|
+
* // Thenable — collect all inserted rows into an array:
|
|
1087
|
+
* const created = await db.orm.User.createAll([
|
|
1088
|
+
* { email: 'a@example.com' },
|
|
1089
|
+
* { email: 'b@example.com' },
|
|
1090
|
+
* ]);
|
|
1091
|
+
*
|
|
1092
|
+
* // Async iterable — stream inserted rows as they arrive:
|
|
1093
|
+
* for await (const row of db.orm.User.createAll(seedUsers)) {
|
|
1094
|
+
* console.log('inserted', row.id);
|
|
1095
|
+
* }
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* Accepts an optional `configure` callback that receives a
|
|
1099
|
+
* `MetaBuilder<'write'>` for attaching typed annotations to the
|
|
1100
|
+
* compiled insert plan.
|
|
1101
|
+
*/
|
|
1102
|
+
createAll(data: readonly ResolvedCreateInput<TContract, ModelName, State['variantName'], State['nsId']>[], configure?: (meta: MetaBuilder<'write'>) => void): AsyncIterableResult<Row>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Write terminal: insert many rows without materializing the
|
|
1105
|
+
* inserted rows, returning the number of inserted records.
|
|
1106
|
+
*
|
|
1107
|
+
* Prefer `createAll(...)` when you need the returned rows; prefer
|
|
1108
|
+
* this when you only need to know how many rows were inserted (the
|
|
1109
|
+
* compiled plan skips `RETURNING`).
|
|
1110
|
+
*
|
|
1111
|
+
* ```typescript
|
|
1112
|
+
* const inserted = await db.orm.User.createAndCount([
|
|
1113
|
+
* { email: 'a@example.com' },
|
|
1114
|
+
* { email: 'b@example.com' },
|
|
1115
|
+
* ]);
|
|
1116
|
+
* // inserted === 2
|
|
1117
|
+
* ```
|
|
1118
|
+
*
|
|
1119
|
+
* Not supported on MTI variants — use `createAll(...)` instead.
|
|
1120
|
+
*/
|
|
1121
|
+
createAndCount(data: readonly ResolvedCreateInput<TContract, ModelName, State['variantName']>[], configure?: (meta: MetaBuilder<'write'>) => void): Promise<number>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Write terminal: insert a row, or update the existing row on
|
|
1124
|
+
* conflict. Returns the resulting row (the inserted one or the
|
|
1125
|
+
* updated/existing one).
|
|
1126
|
+
*
|
|
1127
|
+
* `conflictOn` selects which unique constraint drives the conflict
|
|
1128
|
+
* resolution — omit to use the model's primary key.
|
|
1129
|
+
*
|
|
1130
|
+
* ```typescript
|
|
1131
|
+
* // Insert-or-update on email uniqueness:
|
|
1132
|
+
* await db.orm.User.upsert({
|
|
1133
|
+
* create: { email: 'alice@example.com', name: 'Alice' },
|
|
1134
|
+
* update: { name: 'Alice (updated)' },
|
|
1135
|
+
* conflictOn: { email: 'alice@example.com' },
|
|
1136
|
+
* });
|
|
1137
|
+
*
|
|
1138
|
+
* // Conditional create — `update: {}` keeps the existing row
|
|
1139
|
+
* // unchanged. `conflictOn` must reference the constraint that
|
|
1140
|
+
* // makes the row "already exist"; omit only when the conflict is
|
|
1141
|
+
* // on the primary key. On conflict,
|
|
1142
|
+
* // `ON CONFLICT DO NOTHING RETURNING ...` may return zero rows,
|
|
1143
|
+
* // so a follow-up reload is issued to fetch and return the
|
|
1144
|
+
* // existing row.
|
|
1145
|
+
* await db.orm.User.upsert({
|
|
1146
|
+
* create: { email: 'alice@example.com', name: 'Alice' },
|
|
1147
|
+
* update: {},
|
|
1148
|
+
* conflictOn: { email: 'alice@example.com' },
|
|
1149
|
+
* });
|
|
1150
|
+
* ```
|
|
1151
|
+
*
|
|
1152
|
+
* Not supported on MTI variants.
|
|
1153
|
+
*/
|
|
1154
|
+
upsert(input: {
|
|
1155
|
+
create: ResolvedCreateInput<TContract, ModelName, State['variantName']>;
|
|
1156
|
+
update: Partial<DefaultModelRow<TContract, ModelName>>;
|
|
1157
|
+
conflictOn?: UniqueConstraintCriterion<TContract, ModelName>;
|
|
1158
|
+
}, configure?: (meta: MetaBuilder<'write'>) => void): Promise<Row>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Write terminal: update matching rows and return the first one (or
|
|
1161
|
+
* `null` when no row matched). Requires a prior `.where(...)` —
|
|
1162
|
+
* calling `update(...)` on an unfiltered collection is a type error.
|
|
1163
|
+
*
|
|
1164
|
+
* Related rows can be created or relinked through relation
|
|
1165
|
+
* callbacks on parent/child-owned relations (one-to-one or
|
|
1166
|
+
* one-to-many). The callback receives a mutator exposing
|
|
1167
|
+
* `create(...)`, `connect(...)`, and `disconnect(...)`. Nested
|
|
1168
|
+
* updates against existing related rows, and many-to-many relations
|
|
1169
|
+
* as nested-mutation targets, are not supported through this API.
|
|
1170
|
+
*
|
|
1171
|
+
* ```typescript
|
|
1172
|
+
* // Update one row by id:
|
|
1173
|
+
* const updated = await db.orm.User
|
|
1174
|
+
* .where({ id: 1 })
|
|
1175
|
+
* .update({ name: 'Alice Renamed' });
|
|
1176
|
+
*
|
|
1177
|
+
* // Update + relink — runs as a graph of internal mutations:
|
|
1178
|
+
* await db.orm.User
|
|
1179
|
+
* .where({ id: 1 })
|
|
1180
|
+
* .update({
|
|
1181
|
+
* name: 'Alice',
|
|
1182
|
+
* posts: (posts) => posts.connect([{ id: 5 }]),
|
|
1183
|
+
* });
|
|
1184
|
+
* ```
|
|
1185
|
+
*
|
|
1186
|
+
* Accepts an optional `configure` callback that receives a
|
|
1187
|
+
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
1188
|
+
*
|
|
1189
|
+
* Note: when the input contains nested-mutation callbacks, the
|
|
1190
|
+
* operation is executed as a graph of internal queries via
|
|
1191
|
+
* `withMutationScope`. In that path, annotations apply to the logical
|
|
1192
|
+
* `update()` call but do not currently flow into each constituent SQL
|
|
1193
|
+
* statement issued for the related rows.
|
|
1194
|
+
*/
|
|
1195
|
+
update(data: State['hasWhere'] extends true ? MutationUpdateInput<TContract, ModelName, State['nsId']> : never, configure?: (meta: MetaBuilder<'write'>) => void): Promise<Row | null>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Write terminal: update every matching row and stream the updated
|
|
1198
|
+
* rows. Requires a prior `.where(...)` filter.
|
|
1199
|
+
*
|
|
1200
|
+
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
1201
|
+
* resolves to `Row[]` AND an async iterable that streams updated
|
|
1202
|
+
* rows as they arrive. Use whichever fits; a result can only be
|
|
1203
|
+
* consumed once. Streaming is the default; some driver/plan
|
|
1204
|
+
* combinations may still buffer internally before yielding.
|
|
1205
|
+
*
|
|
1206
|
+
* ```typescript
|
|
1207
|
+
* // Thenable — collect updated rows into an array:
|
|
1208
|
+
* const updated = await db.orm.Post
|
|
1209
|
+
* .where({ published: false })
|
|
1210
|
+
* .updateAll({ published: true });
|
|
1211
|
+
*
|
|
1212
|
+
* // Async iterable — stream updated rows as they arrive:
|
|
1213
|
+
* for await (const row of db.orm.Post.where({ draft: true }).updateAll({ draft: false })) {
|
|
1214
|
+
* console.log('published', row.id);
|
|
1215
|
+
* }
|
|
1216
|
+
* ```
|
|
1217
|
+
*
|
|
1218
|
+
* Accepts an optional `configure` callback that receives a
|
|
1219
|
+
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
1220
|
+
*/
|
|
1221
|
+
updateAll(data: State['hasWhere'] extends true ? Partial<DefaultModelRow<TContract, ModelName, State['nsId']>> : never, configure?: (meta: MetaBuilder<'write'>) => void): AsyncIterableResult<Row>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Write terminal: update every matching row without returning them,
|
|
1224
|
+
* resolving to the count of rows that were updated. Requires a prior
|
|
1225
|
+
* `.where(...)` filter.
|
|
1226
|
+
*
|
|
1227
|
+
* Prefer `updateAll(...)` when you need the updated rows; prefer
|
|
1228
|
+
* this when you only need the affected-row count.
|
|
1229
|
+
*
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* const count = await db.orm.Post
|
|
1232
|
+
* .where({ published: false })
|
|
1233
|
+
* .updateAndCount({ published: true });
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
updateAndCount(data: State['hasWhere'] extends true ? Partial<DefaultModelRow<TContract, ModelName, State['nsId']>> : never, configure?: (meta: MetaBuilder<'write'>) => void): Promise<number>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Write terminal: delete matching rows and return the first deleted
|
|
1239
|
+
* row (or `null` when no row matched). Requires a prior `.where(...)`
|
|
1240
|
+
* — calling `delete()` on an unfiltered collection is a type error.
|
|
1241
|
+
*
|
|
1242
|
+
* ```typescript
|
|
1243
|
+
* const deleted = await db.orm.User.where({ id: 1 }).delete();
|
|
1244
|
+
* if (deleted) console.log('deleted', deleted.email);
|
|
1245
|
+
* ```
|
|
1246
|
+
*
|
|
1247
|
+
* Accepts an optional `configure` callback that receives a
|
|
1248
|
+
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
1249
|
+
*/
|
|
1250
|
+
delete(this: State['hasWhere'] extends true ? Collection<TContract, ModelName, Row, State> : never, configure?: (meta: MetaBuilder<'write'>) => void): Promise<Row | null>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Write terminal: delete every matching row and stream the deleted
|
|
1253
|
+
* rows. Requires a prior `.where(...)` filter.
|
|
1254
|
+
*
|
|
1255
|
+
* The returned `AsyncIterableResult<Row>` is BOTH a thenable that
|
|
1256
|
+
* resolves to `Row[]` AND an async iterable that streams deleted
|
|
1257
|
+
* rows as they arrive. Use whichever fits; a result can only be
|
|
1258
|
+
* consumed once. Streaming is the default; some driver/plan
|
|
1259
|
+
* combinations may still buffer internally before yielding.
|
|
1260
|
+
*
|
|
1261
|
+
* ```typescript
|
|
1262
|
+
* // Thenable — collect the deleted rows into an array:
|
|
1263
|
+
* const deleted = await db.orm.Post.where({ archived: true }).deleteAll();
|
|
1264
|
+
*
|
|
1265
|
+
* // Async iterable — stream deleted rows as they arrive:
|
|
1266
|
+
* for await (const row of db.orm.Post.where({ archived: true }).deleteAll()) {
|
|
1267
|
+
* console.log('removed', row.id);
|
|
1268
|
+
* }
|
|
1269
|
+
* ```
|
|
1270
|
+
*
|
|
1271
|
+
* Accepts an optional `configure` callback that receives a
|
|
1272
|
+
* `MetaBuilder<'write'>` for attaching typed annotations.
|
|
1273
|
+
*/
|
|
1274
|
+
deleteAll(this: State['hasWhere'] extends true ? Collection<TContract, ModelName, Row, State> : never, configure?: (meta: MetaBuilder<'write'>) => void): AsyncIterableResult<Row>;
|
|
1275
|
+
/**
|
|
1276
|
+
* Write terminal: delete every matching row without returning them,
|
|
1277
|
+
* resolving to the count of rows that were deleted. Requires a prior
|
|
1278
|
+
* `.where(...)` filter.
|
|
1279
|
+
*
|
|
1280
|
+
* Prefer `deleteAll(...)` when you need the deleted rows; prefer
|
|
1281
|
+
* this when you only need the affected-row count.
|
|
1282
|
+
*
|
|
1283
|
+
* ```typescript
|
|
1284
|
+
* const removed = await db.orm.Post.where({ archived: true }).deleteAndCount();
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
deleteAndCount(this: State['hasWhere'] extends true ? Collection<TContract, ModelName, Row, State> : never, configure?: (meta: MetaBuilder<'write'>) => void): Promise<number>;
|
|
1288
|
+
}
|
|
1289
|
+
//#endregion
|
|
1290
|
+
//#region src/filters.d.ts
|
|
1291
|
+
declare function and(...exprs: AnyExpression[]): AndExpr;
|
|
1292
|
+
declare function or(...exprs: AnyExpression[]): OrExpr;
|
|
1293
|
+
declare function not(expr: AnyExpression): AnyExpression;
|
|
1294
|
+
declare function all(): AnyExpression;
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/model-accessor.d.ts
|
|
1297
|
+
declare function createModelAccessor<TContract extends Contract<SqlStorage>, ModelName extends string, VariantName extends string | undefined = undefined>(context: ExecutionContext<TContract>, namespaceId: string, modelName: ModelName, variantName?: VariantName): VariantAwareModelAccessor<TContract, ModelName, VariantName>;
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region src/orm.d.ts
|
|
1300
|
+
interface OrmOptions<TContract extends Contract<SqlStorage>, Collections extends Partial<Record<string, AnyCollectionClass>>> {
|
|
1301
|
+
readonly runtime: RuntimeQueryable;
|
|
1302
|
+
readonly collections?: Collections;
|
|
1303
|
+
readonly context: ExecutionContext<TContract>;
|
|
1304
|
+
}
|
|
1305
|
+
type ModelNames<TContract extends Contract<SqlStorage>> = CollectionModelName<TContract>;
|
|
1306
|
+
type AnyCollectionClass = new (...args: never[]) => object;
|
|
1307
|
+
type CustomCollectionForKey<Collections extends Partial<Record<string, AnyCollectionClass>>, Key extends string> = Key extends keyof Collections ? Collections[Key] extends AnyCollectionClass ? InstanceType<Collections[Key]> : never : never;
|
|
1308
|
+
type ModelCollection<TContract extends Contract<SqlStorage>, Collections extends Partial<Record<string, AnyCollectionClass>>, NsId extends string, ModelName extends ModelNames<TContract>> = [CustomCollectionForKey<Collections, ModelName>] extends [never] ? Collection<TContract, ModelName, InferRootRow<TContract, ModelName, NsId>, WithNsId<DefaultCollectionTypeState, NsId>> : CustomCollectionForKey<Collections, ModelName>;
|
|
1309
|
+
type NamespaceModelNames<TContract extends Contract<SqlStorage>, NsId extends keyof TContract['domain']['namespaces']> = keyof TContract['domain']['namespaces'][NsId]['models'] & string & ModelNames<TContract>;
|
|
1310
|
+
type OrmNamespace<TContract extends Contract<SqlStorage>, Collections extends Partial<Record<string, AnyCollectionClass>>, NsId extends keyof TContract['domain']['namespaces']> = { [K in NamespaceModelNames<TContract, NsId>]: ModelCollection<TContract, Collections, NsId & string, K>; };
|
|
1311
|
+
type NamespacedClientMap<TContract extends Contract<SqlStorage>, Collections extends Partial<Record<string, AnyCollectionClass>>> = { [Ns in keyof TContract['domain']['namespaces']]: OrmNamespace<TContract, Collections, Ns>; };
|
|
1312
|
+
type OrmClient<TContract extends Contract<SqlStorage>, Collections extends Partial<Record<string, AnyCollectionClass>>> = NamespacedClientMap<TContract, Collections>;
|
|
1313
|
+
declare function orm<TContract extends Contract<SqlStorage>, Collections extends Partial<Record<string, AnyCollectionClass>> = Record<never, never>>(options: OrmOptions<TContract, Collections>): OrmClient<TContract, Collections>;
|
|
1314
|
+
//#endregion
|
|
1315
|
+
export { type AggregateBuilder, type AggregateResult, type AggregateSpec, Collection, type CollectionContext, type CollectionModelName, type CollectionState, type CollectionTypeState, type ComparisonMethods, type CreateInput, type DefaultCollectionTypeState, type DefaultModelRow, GroupedCollection, type IncludeExpr, type ModelAccessor, type NumericFieldNames, type OrmOptions, type RelatedModelName, type RelationFilterAccessor, type RelationMutator, type RelationNames, type RelationPredicate, type RelationPredicateInput, type RelationsOf, type RuntimeQueryable, type ShorthandWhereFilter, type UniqueConstraintCriterion, all, and, createModelAccessor, emptyState, not, or, orm };
|
|
1316
|
+
//# sourceMappingURL=orm-client.d.mts.map
|