viborm 1.14.2 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-namespace-DaRiTIIf.mjs → adapter-namespace-DD-BQ2Wk.mjs} +2 -2
- package/dist/{adapter-namespace-DaRiTIIf.mjs.map → adapter-namespace-DD-BQ2Wk.mjs.map} +1 -1
- package/dist/adapters.d.mts +15 -3
- package/dist/adapters.mjs +1 -1
- package/dist/{args-764KdWMr.mjs → args-BvA37zBZ.mjs} +2 -2
- package/dist/{args-764KdWMr.mjs.map → args-BvA37zBZ.mjs.map} +1 -1
- package/dist/{batch-refs-C-gx7A4-.mjs → batch-refs-BmEpMmjI.mjs} +2 -2
- package/dist/{batch-refs-C-gx7A4-.mjs.map → batch-refs-BmEpMmjI.mjs.map} +1 -1
- package/dist/bun-sql.d.mts +1 -1
- package/dist/bun-sql.mjs +1 -1
- package/dist/bun-sqlite.d.mts +1 -1
- package/dist/bun-sqlite.mjs +1 -1
- package/dist/cache/cloudflare-kv.d.mts +1 -1
- package/dist/cache/cloudflare-kv.mjs +1 -1
- package/dist/cache/memory.d.mts +1 -1
- package/dist/cache/memory.mjs +1 -1
- package/dist/cache.d.mts +2 -2
- package/dist/cache.mjs +1 -1
- package/dist/{call-Cz8XUmrl.mjs → call-BWFI7-vU.mjs} +2 -2
- package/dist/{call-Cz8XUmrl.mjs.map → call-BWFI7-vU.mjs.map} +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/client-CVCC-D1j.mjs +2 -0
- package/dist/client-CVCC-D1j.mjs.map +1 -0
- package/dist/{client-CRxfhw2y.d.mts → client-DZ39sYy2.d.mts} +2 -2
- package/dist/{client-y7TV0PRZ.mjs → client-DtPTegtA.mjs} +2 -2
- package/dist/{client-y7TV0PRZ.mjs.map → client-DtPTegtA.mjs.map} +1 -1
- package/dist/client.d.mts +3 -3
- package/dist/client.mjs +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/{confine-DqFBTUw6.mjs → confine-BGGv2du0.mjs} +2 -2
- package/dist/{confine-DqFBTUw6.mjs.map → confine-BGGv2du0.mjs.map} +1 -1
- package/dist/{coordination-6qZHx_kl.mjs → coordination-BY6Np3xV.mjs} +2 -2
- package/dist/{coordination-6qZHx_kl.mjs.map → coordination-BY6Np3xV.mjs.map} +1 -1
- package/dist/d1.d.mts +1 -1
- package/dist/d1.mjs +1 -1
- package/dist/{database-adapter-BGqvjeEy.d.mts → database-adapter-D62c-uC6.d.mts} +604 -473
- package/dist/{datetime-physical-codec-Dj-APo9f.mjs → datetime-physical-codec-BS2T81sD.mjs} +2 -2
- package/dist/{datetime-physical-codec-Dj-APo9f.mjs.map → datetime-physical-codec-BS2T81sD.mjs.map} +1 -1
- package/dist/{defaults-DwOHWI_M.mjs → defaults-CrtGVdEC.mjs} +2 -2
- package/dist/{defaults-DwOHWI_M.mjs.map → defaults-CrtGVdEC.mjs.map} +1 -1
- package/dist/{document-BVTQ-cF-.d.mts → document-o5Bd5ZoJ.d.mts} +1 -1
- package/dist/{driver-BBEmaJZy.d.mts → driver-0cdCF_KD.d.mts} +1 -1
- package/dist/{driver-BGVcgnIX.mjs → driver-D1grnHEr.mjs} +2 -2
- package/dist/{driver-BGVcgnIX.mjs.map → driver-D1grnHEr.mjs.map} +1 -1
- package/dist/{driver-BIXhOH2_.mjs → driver-Df88hu4U.mjs} +2 -2
- package/dist/{driver-BIXhOH2_.mjs.map → driver-Df88hu4U.mjs.map} +1 -1
- package/dist/driver.d.mts +1 -1
- package/dist/driver.mjs +1 -1
- package/dist/durable-object.d.mts +1 -1
- package/dist/durable-object.mjs +1 -1
- package/dist/error-mapping-DIRlrmDK.mjs +2 -0
- package/dist/error-mapping-DIRlrmDK.mjs.map +1 -0
- package/dist/every-BHEmfLOW.mjs +2 -0
- package/dist/{every-tOgQmaIE.mjs.map → every-BHEmfLOW.mjs.map} +1 -1
- package/dist/execution-context-VMQm-9CH.mjs +2 -0
- package/dist/execution-context-VMQm-9CH.mjs.map +1 -0
- package/dist/{exports-COCJ8f2f.d.mts → exports-Bzvtum3F.d.mts} +1 -1
- package/dist/geo-area-codec-BDvW7IH-.mjs +2 -0
- package/dist/{geo-area-codec-mHrM3b9A.mjs.map → geo-area-codec-BDvW7IH-.mjs.map} +1 -1
- package/dist/{hydration-A3zffFWP.mjs → hydration-D7U8HACL.mjs} +2 -2
- package/dist/{hydration-A3zffFWP.mjs.map → hydration-D7U8HACL.mjs.map} +1 -1
- package/dist/{identifier-conversion-DHYPTgzr.mjs → identifier-conversion-Ci_iaJ0b.mjs} +2 -2
- package/dist/{identifier-conversion-DHYPTgzr.mjs.map → identifier-conversion-Ci_iaJ0b.mjs.map} +1 -1
- package/dist/identifiers-BTCfD5ic.mjs +2 -0
- package/dist/identifiers-BTCfD5ic.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/instrumentation.d.mts +1 -1
- package/dist/instrumentation.mjs +1 -1
- package/dist/{introspect-Bm6xnXcG.mjs → introspect-C4T5gt9O.mjs} +2 -2
- package/dist/{introspect-Bm6xnXcG.mjs.map → introspect-C4T5gt9O.mjs.map} +1 -1
- package/dist/{json-DgMc8-GU.mjs → json-CHdgejCt.mjs} +2 -2
- package/dist/{json-DgMc8-GU.mjs.map → json-CHdgejCt.mjs.map} +1 -1
- package/dist/judge-words-DpwxOfre.mjs +2 -0
- package/dist/judge-words-DpwxOfre.mjs.map +1 -0
- package/dist/{key-hxFFCKed.mjs → key-B3xgpu0M.mjs} +2 -2
- package/dist/{key-hxFFCKed.mjs.map → key-B3xgpu0M.mjs.map} +1 -1
- package/dist/{keys-BQxM4c_a.mjs → keys-1Z6WKrnE.mjs} +1 -1
- package/dist/{keys-BQxM4c_a.mjs.map → keys-1Z6WKrnE.mjs.map} +1 -1
- package/dist/{libsql-DuGR904j.mjs → libsql-DJRsCDT_.mjs} +2 -2
- package/dist/{libsql-DuGR904j.mjs.map → libsql-DJRsCDT_.mjs.map} +1 -1
- package/dist/libsql.d.mts +1 -1
- package/dist/libsql.mjs +1 -1
- package/dist/{memory-G4cSuc6A.mjs → memory-gjKMy3Ql.mjs} +2 -2
- package/dist/{memory-G4cSuc6A.mjs.map → memory-gjKMy3Ql.mjs.map} +1 -1
- package/dist/methods-part-DoTrY6b9.mjs +2 -0
- package/dist/methods-part-DoTrY6b9.mjs.map +1 -0
- package/dist/migrations/mysql.d.mts +4 -4
- package/dist/migrations/mysql.mjs +1 -1
- package/dist/migrations/postgres.d.mts +4 -4
- package/dist/migrations/postgres.mjs +1 -1
- package/dist/migrations/snowflake.d.mts +4 -4
- package/dist/migrations/snowflake.mjs +1 -1
- package/dist/migrations/sqlite.d.mts +4 -4
- package/dist/migrations/sqlite.mjs +1 -1
- package/dist/migrations/storage/durable-object.mjs +1 -1
- package/dist/migrations/storage/r2.mjs +1 -1
- package/dist/migrations/surrealdb.d.mts +4 -4
- package/dist/migrations/surrealdb.mjs +1 -1
- package/dist/migrations/tenant.d.mts +2 -2
- package/dist/migrations/tenant.mjs +1 -1
- package/dist/migrations.d.mts +4 -4
- package/dist/migrations.mjs +1 -1
- package/dist/{mysql-BNXWfTOo.mjs → mysql-BH0Z3PlH.mjs} +2 -2
- package/dist/{mysql-BNXWfTOo.mjs.map → mysql-BH0Z3PlH.mjs.map} +1 -1
- package/dist/mysql-adapter-B06Ve3ds.mjs +2 -0
- package/dist/mysql-adapter-B06Ve3ds.mjs.map +1 -0
- package/dist/mysql2.d.mts +1 -1
- package/dist/mysql2.mjs +1 -1
- package/dist/named-statements-Bdz2GD5R.d.mts +13 -0
- package/dist/named-statements-CMj1QEyw.mjs +2 -0
- package/dist/named-statements-CMj1QEyw.mjs.map +1 -0
- package/dist/{native-types-DgjMUikz.mjs → native-types-DspZ0Z5E.mjs} +2 -2
- package/dist/{native-types-DgjMUikz.mjs.map → native-types-DspZ0Z5E.mjs.map} +1 -1
- package/dist/neon-http.d.mts +1 -1
- package/dist/neon-http.mjs +1 -1
- package/dist/{object-store-B_YMoW8u.d.mts → object-store-D5x-Yf7w.d.mts} +3 -3
- package/dist/{object-store-DS0F0yZX.mjs → object-store-WIE0DGGG.mjs} +1 -1
- package/dist/{object-store-DS0F0yZX.mjs.map → object-store-WIE0DGGG.mjs.map} +1 -1
- package/dist/{on-ylYaKuRu.mjs → on-DvrfHGje.mjs} +2 -2
- package/dist/{on-ylYaKuRu.mjs.map → on-DvrfHGje.mjs.map} +1 -1
- package/dist/on.d.mts +1 -1
- package/dist/on.mjs +1 -1
- package/dist/ordering/keys.mjs +1 -1
- package/dist/ordering.d.mts +1 -1
- package/dist/ordering.mjs +1 -1
- package/dist/pending-operation-Dq4rv-Ml.mjs +2 -0
- package/dist/pending-operation-Dq4rv-Ml.mjs.map +1 -0
- package/dist/permissions.d.mts +1 -1
- package/dist/permissions.mjs +1 -1
- package/dist/pg.d.mts +27 -1
- package/dist/pg.mjs +1 -1
- package/dist/pg.mjs.map +1 -1
- package/dist/pglite.d.mts +1 -1
- package/dist/pglite.mjs +1 -1
- package/dist/{physical-CeE2nYmI.mjs → physical-wboFLAg9.mjs} +2 -2
- package/dist/{physical-CeE2nYmI.mjs.map → physical-wboFLAg9.mjs.map} +1 -1
- package/dist/planetscale.d.mts +1 -1
- package/dist/planetscale.mjs +1 -1
- package/dist/{planner-DHjdvjwk.d.mts → planner-Ckoxeruk.d.mts} +1 -1
- package/dist/{postgres-CDdh5dSP.mjs → postgres-DQ_pO0hi.mjs} +2 -2
- package/dist/{postgres-CDdh5dSP.mjs.map → postgres-DQ_pO0hi.mjs.map} +1 -1
- package/dist/{postgres-adapter-axapXX8d.mjs → postgres-adapter-Byp7Zpop.mjs} +2 -2
- package/dist/{postgres-adapter-axapXX8d.mjs.map → postgres-adapter-Byp7Zpop.mjs.map} +1 -1
- package/dist/postgres-adapter-Ia4u0-Ht.mjs +2 -0
- package/dist/postgres-adapter-Ia4u0-Ht.mjs.map +1 -0
- package/dist/postgres-result-CiS5OWp1.mjs +2 -0
- package/dist/postgres-result-CiS5OWp1.mjs.map +1 -0
- package/dist/postgres.d.mts +17 -1
- package/dist/postgres.mjs +1 -1
- package/dist/postgres.mjs.map +1 -1
- package/dist/{provider-limits-Ccsb8PTb.mjs → provider-limits-CCOa4d1E.mjs} +2 -2
- package/dist/{provider-limits-Ccsb8PTb.mjs.map → provider-limits-CCOa4d1E.mjs.map} +1 -1
- package/dist/{provider-parameter-snapshot-BikrgKqI.mjs → provider-parameter-snapshot-C0ehKSAA.mjs} +2 -2
- package/dist/{provider-parameter-snapshot-BikrgKqI.mjs.map → provider-parameter-snapshot-C0ehKSAA.mjs.map} +1 -1
- package/dist/query-Cdy8E2jM.mjs +2 -0
- package/dist/query-Cdy8E2jM.mjs.map +1 -0
- package/dist/{query-inspection-BoG-yAln.mjs → query-inspection-C-T2ttRx.mjs} +2 -2
- package/dist/{query-inspection-BoG-yAln.mjs.map → query-inspection-C-T2ttRx.mjs.map} +1 -1
- package/dist/{raw-Dyq6Y6UX.mjs → raw-uaVIxHcE.mjs} +2 -2
- package/dist/{raw-Dyq6Y6UX.mjs.map → raw-uaVIxHcE.mjs.map} +1 -1
- package/dist/{relation-bound-ku_cMdye.mjs → relation-bound-BaU-LuuI.mjs} +1 -1
- package/dist/{relation-bound-ku_cMdye.mjs.map → relation-bound-BaU-LuuI.mjs.map} +1 -1
- package/dist/{rule-words-ZIGm7cDm.mjs → rule-words-C4lXzgW2.mjs} +2 -2
- package/dist/{rule-words-ZIGm7cDm.mjs.map → rule-words-C4lXzgW2.mjs.map} +1 -1
- package/dist/scalar-B9WizsvR.mjs +4 -0
- package/dist/scalar-B9WizsvR.mjs.map +1 -0
- package/dist/schema/introspect.d.mts +2 -2
- package/dist/schema/introspect.mjs +1 -1
- package/dist/schema/json.d.mts +2 -2
- package/dist/schema/json.mjs +1 -1
- package/dist/{schema-BYA-_bpk.mjs → schema-MB-pPNTO.mjs} +2 -2
- package/dist/schema-MB-pPNTO.mjs.map +1 -0
- package/dist/{schema-CFIaebgi.mjs → schema-TthAXPVP.mjs} +2 -2
- package/dist/{schema-CFIaebgi.mjs.map → schema-TthAXPVP.mjs.map} +1 -1
- package/dist/schema-introspection-wMVZowIF.mjs +6 -0
- package/dist/schema-introspection-wMVZowIF.mjs.map +1 -0
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +1 -1
- package/dist/select-assembly-SuVxJjps.mjs +2 -0
- package/dist/select-assembly-SuVxJjps.mjs.map +1 -0
- package/dist/{serializer-rBq3v1xr.mjs → serializer-B2kk7NAR.mjs} +5 -5
- package/dist/{serializer-rBq3v1xr.mjs.map → serializer-B2kk7NAR.mjs.map} +1 -1
- package/dist/{settled-BjyuA76m.mjs → settled-Dkk5w1vE.mjs} +2 -2
- package/dist/{settled-BjyuA76m.mjs.map → settled-Dkk5w1vE.mjs.map} +1 -1
- package/dist/{snowflake-UOCC820W.mjs → snowflake-6sBLJi34.mjs} +2 -2
- package/dist/{snowflake-UOCC820W.mjs.map → snowflake-6sBLJi34.mjs.map} +1 -1
- package/dist/snowflake.d.mts +2 -2
- package/dist/snowflake.mjs +1 -1
- package/dist/snowflake.mjs.map +1 -1
- package/dist/soft-delete.d.mts +1 -1
- package/dist/soft-delete.mjs +1 -1
- package/dist/{spans-XDUFeTzC.mjs → spans-BE-EjlZK.mjs} +1 -1
- package/dist/{spans-XDUFeTzC.mjs.map → spans-BE-EjlZK.mjs.map} +1 -1
- package/dist/sql-BGjAsoBE.mjs +2 -0
- package/dist/sql-BGjAsoBE.mjs.map +1 -0
- package/dist/{sql-Dl6nykFV.mjs → sql-CFxGrk3K.mjs} +2 -2
- package/dist/{sql-Dl6nykFV.mjs.map → sql-CFxGrk3K.mjs.map} +1 -1
- package/dist/{sql-BVZ8QefY.d.mts → sql-CXtSIPzy.d.mts} +11 -5
- package/dist/sql.d.mts +1 -1
- package/dist/sql.mjs +1 -1
- package/dist/{sqlite-adapter-Ad0d-m2t.mjs → sqlite-adapter-fIbNDvwO.mjs} +2 -2
- package/dist/{sqlite-adapter-Ad0d-m2t.mjs.map → sqlite-adapter-fIbNDvwO.mjs.map} +1 -1
- package/dist/{sqlite-utils-BRvbmlQ1.mjs → sqlite-utils-DcQct689.mjs} +2 -2
- package/dist/{sqlite-utils-BRvbmlQ1.mjs.map → sqlite-utils-DcQct689.mjs.map} +1 -1
- package/dist/sqlite3.d.mts +1 -1
- package/dist/sqlite3.mjs +1 -1
- package/dist/{standard-sql-qLcQyCtK.mjs → standard-sql-Bsf5nrla.mjs} +3 -3
- package/dist/standard-sql-Bsf5nrla.mjs.map +1 -0
- package/dist/surrealdb.d.mts +2 -2
- package/dist/surrealdb.mjs +1 -1
- package/dist/surrealdb.mjs.map +1 -1
- package/dist/{surrealql-C1dp1sWw.mjs → surrealql-DY7sgVnJ.mjs} +2 -2
- package/dist/{surrealql-C1dp1sWw.mjs.map → surrealql-DY7sgVnJ.mjs.map} +1 -1
- package/dist/{to-many-BybuKQM1.mjs → to-many-DiP6cOSQ.mjs} +2 -2
- package/dist/{to-many-BybuKQM1.mjs.map → to-many-DiP6cOSQ.mjs.map} +1 -1
- package/dist/{unit-BhHbZyuJ.mjs → unit-CSaAB0su.mjs} +2 -2
- package/dist/{unit-BhHbZyuJ.mjs.map → unit-CSaAB0su.mjs.map} +1 -1
- package/dist/{unit-words-CT0yeqfZ.mjs → unit-words-BGMVZ1MX.mjs} +2 -2
- package/dist/{unit-words-CT0yeqfZ.mjs.map → unit-words-BGMVZ1MX.mjs.map} +1 -1
- package/dist/{utils-CpAojrCj.mjs → utils-BLlgSQIo.mjs} +2 -2
- package/dist/{utils-CpAojrCj.mjs.map → utils-BLlgSQIo.mjs.map} +1 -1
- package/dist/validation-D0LG854o.mjs +2 -0
- package/dist/validation-D0LG854o.mjs.map +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/dist/{validator-CZLW7aR3.mjs → validator-CDYlO9HV.mjs} +2 -2
- package/dist/{validator-CZLW7aR3.mjs.map → validator-CDYlO9HV.mjs.map} +1 -1
- package/dist/{values-B4aj1i1f.mjs → values-Byqn5wAh.mjs} +2 -2
- package/dist/{values-B4aj1i1f.mjs.map → values-Byqn5wAh.mjs.map} +1 -1
- package/dist/version-B_ZLWzLW.mjs +2 -0
- package/dist/{version-CXGIA82S.mjs.map → version-B_ZLWzLW.mjs.map} +1 -1
- package/package.json +35 -35
- package/dist/client-DRpX3-vw.mjs +0 -2
- package/dist/client-DRpX3-vw.mjs.map +0 -1
- package/dist/error-mapping-B1-IWkCQ.mjs +0 -2
- package/dist/error-mapping-B1-IWkCQ.mjs.map +0 -1
- package/dist/every-tOgQmaIE.mjs +0 -2
- package/dist/execution-context-BXpcbyPe.mjs +0 -2
- package/dist/execution-context-BXpcbyPe.mjs.map +0 -1
- package/dist/geo-area-codec-mHrM3b9A.mjs +0 -2
- package/dist/identifiers-s00pGES8.mjs +0 -2
- package/dist/identifiers-s00pGES8.mjs.map +0 -1
- package/dist/judge-words-CzUyXtJ6.mjs +0 -2
- package/dist/judge-words-CzUyXtJ6.mjs.map +0 -1
- package/dist/methods-part-ZY0f2AV_.mjs +0 -2
- package/dist/methods-part-ZY0f2AV_.mjs.map +0 -1
- package/dist/mysql-adapter-C69j1sKh.mjs +0 -2
- package/dist/mysql-adapter-C69j1sKh.mjs.map +0 -1
- package/dist/pending-operation-C_eOFOBE.mjs +0 -2
- package/dist/pending-operation-C_eOFOBE.mjs.map +0 -1
- package/dist/postgres-adapter-Dlr3ZWd7.mjs +0 -2
- package/dist/postgres-adapter-Dlr3ZWd7.mjs.map +0 -1
- package/dist/postgres-result-DF6DmW3r.mjs +0 -2
- package/dist/postgres-result-DF6DmW3r.mjs.map +0 -1
- package/dist/query-BZVHfA0s.mjs +0 -2
- package/dist/query-BZVHfA0s.mjs.map +0 -1
- package/dist/scalar-BHCh7aUz.mjs +0 -4
- package/dist/scalar-BHCh7aUz.mjs.map +0 -1
- package/dist/schema-BYA-_bpk.mjs.map +0 -1
- package/dist/schema-introspection-D0f8cti4.mjs +0 -6
- package/dist/schema-introspection-D0f8cti4.mjs.map +0 -1
- package/dist/select-assembly-DVI7d3tf.mjs +0 -2
- package/dist/select-assembly-DVI7d3tf.mjs.map +0 -1
- package/dist/sql-3o4DOKm9.mjs +0 -2
- package/dist/sql-3o4DOKm9.mjs.map +0 -1
- package/dist/standard-sql-qLcQyCtK.mjs.map +0 -1
- package/dist/validation-CYaJ8ndO.mjs +0 -2
- package/dist/validation-CYaJ8ndO.mjs.map +0 -1
- package/dist/version-CXGIA82S.mjs +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{t}from"./validation--qS7OPmg.mjs";import{o as n}from"./value-guards-CBuxSC66.mjs";import{$ as r}from"./native-types-
|
|
2
|
-
//# sourceMappingURL=to-many-
|
|
1
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{t}from"./validation--qS7OPmg.mjs";import{o as n}from"./value-guards-CBuxSC66.mjs";import{$ as r}from"./native-types-DspZ0Z5E.mjs";import{$ as i,B as a,D as o,F as s,M as c,N as l,O as u,P as d,X as f,a as p,d as m,f as h,g,h as _,k as v,l as y,m as b,n as x,o as S,p as C,s as w,u as T}from"./scalar-B9WizsvR.mjs";import{t as E}from"./current-DBTlPsQg.mjs";const D=a.bigint();var O=class BigIntScalar extends y{rebase(e){return a.bigint({nullable:e.nullable,array:e.array,schema:e.schema})}increment(){return new BigIntScalar(g(this,{hasDefault:!0,autoGenerate:{kind:`increment`},default:void 0,disallowZero:!0,optional:!0}),this._nativeType)}};const bigInt=e=>new O(S(`bigint`,D),x(`s.bigInt`,e)),k=a.blob();var BlobScalar=class extends C{rebase(e){return a.blob({nullable:e.nullable})}array(){throw Error(`Blob scalars don't support array modifier`)}id(){throw Error(`Blob scalars cannot be used as IDs`)}unique(){throw Error(`Blob scalars cannot be unique`)}};const blob=e=>new BlobScalar(S(`blob`,k),x(`s.blob`,e)),A=a.boolean();var BooleanScalar=class extends T{rebase(e){return a.boolean({nullable:e.nullable,array:e.array})}};const boolean=e=>new BooleanScalar(S(`boolean`,A),x(`s.boolean`,e)),generated=e=>({now:w(()=>E(e)),updatedAt:w(()=>E(e))}),j={datetime:generated(`datetime`),date:generated(`date`),time:generated(`time`)},refuseList=e=>h(`s.${e.type===`datetime`?`dateTime`:e.type}`);var TemporalScalarChain=class extends p{#e(e){return this.state.array&&refuseList(this.state),m(this,{hasDefault:!0,autoGenerate:{kind:e},default:j[this.state.type][e],optional:!0})}array(){let e=this.state.autoGenerate?.kind;return(e===`now`||e===`updatedAt`)&&refuseList(this.state),super.array()}now(){return this.#e(`now`)}updatedAt(){return this.#e(`updatedAt`)}};const M=TemporalScalarChain,N=a.isoDate();var DateScalar=class extends M{rebase(e){return a.isoDate({nullable:e.nullable,array:e.array,schema:e.schema})}};const date=e=>new DateScalar(S(`date`,N),x(`s.date`,e)),P=a.isoTimestamp();var F=class DateTimeScalar extends M{rebase(e){return a.isoTimestamp({nullable:e.nullable,array:e.array,schema:e.schema})}withoutTimezone(){return new DateTimeScalar(g(this,{withTimezone:!1}),this._nativeType)}};const dateTime=e=>new F({...S(`datetime`,P),withTimezone:!0},x(`s.dateTime`,e)),I=a.isoTime();var L=class TimeScalar extends M{rebase(e){return a.isoTime({nullable:e.nullable,array:e.array,schema:e.schema})}withoutTimezone(){return new TimeScalar(g(this,{withTimezone:!1}),this._nativeType)}};const time=e=>new L({...S(`time`,I),withTimezone:!1},x(`s.time`,e));function refuse(e,n){throw new t({kind:`schema-builder`,builder:`s.decimal`,path:e},[{path:e,message:n}])}function readDecimalDescriptor(e){let t=n(e)?e.precision:void 0,r=n(e)?e.scale:void 0;return typeof t==`number`&&Number.isSafeInteger(t)&&t>=1||refuse(`descriptor.precision`,`'precision' must be an integer between 1 and the maximum safe integer`),typeof r==`number`&&Number.isSafeInteger(r)&&r>=0&&r<=t&&!Object.is(r,-0)||refuse(`descriptor.scale`,`'scale' must be an integer between 0 and precision`),Object.freeze({precision:t,scale:r})}function refuseDecimalListKey(e){let t=`a fixed-decimal list cannot be an ID, a unique field, an index member, a foreign-key member, or a relation identity member`;refuse(e,e===`array`?`A decimal key cannot become a list: ${t}`:`A decimal list cannot be declared '.${e}()': ${t}`)}function normalizeDecimalDefault(e,t){if(typeof e==`function`)return e;let n=r(t,e);return n.issues!==void 0&&refuse(`default`,`The decimal default did not satisfy its field schema`),n.value}var DecimalScalar=class extends b{rebase(e){return a.decimal({nullable:e.nullable,array:e.array,decimal:e.decimal,schema:e.schema})}again(e){return this.state.hasDefault&&typeof this.state.default!=`function`&&(e[`~`].state.default=normalizeDecimalDefault(this.state.default,e[`~`].state.base)),e}nullable(){return super.nullable()}array(){return(this.state.isId||this.state.isUnique)&&refuseDecimalListKey(`array`),this.again(super.array())}id(){return this.state.array&&refuseDecimalListKey(`id`),super.id()}unique(){return this.state.array&&refuseDecimalListKey(`unique`),super.unique()}default(e){return withValidatedDecimalDefault(this,normalizeDecimalDefault(e,this.state.base))}schema(e){return this.again(super.schema(e))}map(e){return super.map(e)}get"~"(){return{state:this.state}}};function withValidatedDecimalDefault(e,t){return new DecimalScalar(g(e,{hasDefault:!0,default:t,optional:!0}))}const buildDecimalScalar=e=>{let t=readDecimalDescriptor(e);return new DecimalScalar({...S(`decimal`,a.decimal({decimal:t})),decimal:t})},decimal=e=>buildDecimalScalar(e);var R=class EnumScalar extends _{get enumValues(){return`values`in this.state.base?this.state.base.values:[]}rebase(e){return a.enum(this.enumValues,{nullable:e.nullable,array:e.array})}nullable(){return super.nullable()}array(){return super.array()}default(e){return super.default(e)}map(e){return super.map(e)}name(e){return new EnumScalar({...this.state,enumName:e},this._nativeType)}get"~"(){return{state:this.state,nativeType:this._nativeType}}};const enumScalar=(e,t)=>new R(S(`enum`,a.enum(e)),x(`s.enum`,t)),z=a.integer();var B=class IntScalar extends y{rebase(e){return a.integer({nullable:e.nullable,array:e.array,schema:e.schema})}increment(){return new IntScalar(g(this,{hasDefault:!0,autoGenerate:{kind:`increment`},default:void 0,disallowZero:!0,optional:!0}),this._nativeType)}};const int=e=>new B(S(`int`,z),x(`s.int`,e)),V=a.json();var H=class JsonScalar extends C{rebase(e){return a.json({nullable:e.nullable,schema:e.schema})}default(e){let n=i(e);if(n===`AnyNull`||n===`DbNull`&&!this.state.nullable)throw new t({kind:`schema-builder`,builder:`s.json`,path:`default`},[{path:`default`,message:`JSON default must name a null this column can store`}]);let r=e===null&&!this.state.nullable?f:e;return new JsonScalar(g(this,{hasDefault:!0,default:r,optional:!0}),this._nativeType)}schema(e){return new JsonScalar(g(this,{schema:e,base:a.json({nullable:this.state.nullable,schema:e})}),this._nativeType)}};const json=e=>new H(S(`json`,V),x(`s.json`,e)),U=a.number();var NumberScalar=class extends y{rebase(e){return a.number({nullable:e.nullable,array:e.array,schema:e.schema})}};const number=e=>new NumberScalar(S(`number`,U),x(`s.number`,e)),W=a.point();var G=class PointScalar extends C{rebase(e){return a.point({nullable:e.nullable})}constructor(e){super(e)}default(e){return new PointScalar(g(this,{hasDefault:!0,default:normalizePointDefault(e,this.state.base),optional:!0}))}get"~"(){return{state:this.state}}};function normalizePointDefault(e,n){if(typeof e==`function`)return e;let i=r(n,e);if(!i.issues)return i.value;throw new t({kind:`schema-builder`,builder:`s.point`,path:`default`},i.issues.map(e=>({path:e.path?.join(`.`)??`default`,message:e.message})))}function point(...e){if(e.length!==0)throw new t({kind:`schema-builder`,builder:`s.point`,path:`arguments`},[{path:`arguments`,message:`s.point() takes no native type or options`}]);return new G(S(`point`,W))}const K=a.vector();var q=class VectorScalar extends C{rebase(e){return a.vector(e.dimension,{nullable:e.nullable})}dimension(e){if(!Number.isSafeInteger(e)||e<=0)throw new t({kind:`schema-builder`,builder:`s.vector`,path:`dimension`},[{path:`dimension`,message:`Vector dimension must be a positive safe integer`}]);return new VectorScalar(g(this,{dimension:e,base:a.vector(e,{nullable:this.state.nullable})}),this._nativeType)}};const vector=e=>new q(S(`vector`,K),x(`s.vector`,e));var J=class ModelToMany{#e;#t;constructor(e){this.#e=Object.freeze(e),this.#t=Object.freeze({state:this.#e,settleTarget:v(()=>this.#e.target.getter),settleJunctionModel:v(()=>this.#e.junction?.model)})}name(e){return new ModelToMany({...this.#e,name:d(`s.toMany`,e)})}through(e){let{table:t,model:n,...r}=this.#e.junction??{};return this.#n(typeof e==`function`?{...r,model:e}:{...r,table:l(`through`,e)})}source(e){return this.#n({...this.#e.junction,source:l(`source`,e)})}target(e){return this.#n({...this.#e.junction,target:l(`target`,e)})}onDelete(e){return this.#n({...this.#e.junction,onDelete:c(`onDelete`,e)})}onUpdate(e){return this.#n({...this.#e.junction,onUpdate:c(`onUpdate`,e)})}#n(e){return new ModelToMany({...this.#e,junction:Object.freeze(e)})}get"~"(){return this.#t}};function toMany(e,t){return typeof e==`function`?(arguments.length>1&&s(`s.toMany`,`options`,`A model-target relation takes exactly one argument`),new J({kind:`relation`,cardinality:`many`,target:{kind:`model`,getter:e}})):u({kind:`relation`,cardinality:`many`,target:{kind:`variants`,entries:o(`s.toMany`,e,t)}})}export{bigInt as _,json as a,DecimalScalar as c,withValidatedDecimalDefault as d,time as f,blob as g,boolean as h,number as i,buildDecimalScalar as l,date as m,vector as n,int as o,dateTime as p,point as r,enumScalar as s,toMany as t,decimal as u};
|
|
2
|
+
//# sourceMappingURL=to-many-DiP6cOSQ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-many-BybuKQM1.mjs","names":["v","v","v","#generated","v","v","v","v","next","v","v","v","v","v","v","#state","#internal","#withJunction"],"sources":["../src/schema/scalars/bigint/scalar.ts","../src/schema/scalars/blob/scalar.ts","../src/schema/scalars/boolean/scalar.ts","../src/schema/scalars/datetime/chain.ts","../src/schema/scalars/datetime/date-scalar.ts","../src/schema/scalars/datetime/scalar.ts","../src/schema/scalars/datetime/time-scalar.ts","../src/schema/scalars/decimal/descriptor.ts","../src/schema/scalars/decimal/scalar.ts","../src/schema/scalars/enum/scalar.ts","../src/schema/scalars/int/scalar.ts","../src/schema/scalars/json/scalar.ts","../src/schema/scalars/number/scalar.ts","../src/schema/scalars/point/scalar.ts","../src/schema/scalars/vector/scalar.ts","../src/schema/relation/to-many.ts"],"sourcesContent":["// BigInt Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BigIntSchema } from \"@validation/primitives/bigint\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n keyedScalarChain,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst bigIntBase = v.bigint();\n\nexport class BigIntScalar<\n State extends ScalarState<\"bigint\">,\n> extends keyedScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: BigIntSchema<\n ComputeInput<\n bigint,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n bigint,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: BigIntSchema<\n ComputeInput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => BigIntScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<bigint>>(\n schema: S\n ) => BigIntScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: BigIntSchema<\n ComputeInput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => BigIntScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.bigint({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n increment() {\n return new BigIntScalar(\n updateState(this, {\n hasDefault: true,\n autoGenerate: { kind: \"increment\" },\n default: undefined,\n disallowZero: true,\n optional: true,\n }),\n this._nativeType\n );\n }\n}\n\nexport const bigInt = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new BigIntScalar(\n createDefaultState(\"bigint\", bigIntBase),\n admitNativeType(\"s.bigInt\", nativeType)\n );\n","// Blob Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { BlobSchema } from \"@validation/primitives/blob\";\nimport v from \"@validation/primitives/v\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst blobBase = v.blob();\n\nexport class BlobScalar<\n State extends ScalarState<\"blob\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => BlobScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: BlobSchema<\n Uint8Array<ArrayBufferLike> | null,\n Uint8Array<ArrayBufferLike> | null\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => BlobScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => BlobScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.blob({\n nullable: state.nullable,\n });\n }\n\n // Blob scalars don't support array(), id(), or unique()\n array(): never {\n throw new Error(\"Blob scalars don't support array modifier\");\n }\n\n id(): never {\n throw new Error(\"Blob scalars cannot be used as IDs\");\n }\n\n unique(): never {\n throw new Error(\"Blob scalars cannot be unique\");\n }\n}\n\nexport const blob = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new BlobScalar(\n createDefaultState(\"blob\", blobBase),\n admitNativeType(\"s.blob\", nativeType)\n );\n","// Boolean Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { BooleanSchema } from \"@validation/primitives/boolean\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n listScalarChain,\n type ScalarState,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst booleanBase = v.boolean();\n\nexport class BooleanScalar<\n State extends ScalarState<\"boolean\">,\n> extends listScalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => BooleanScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: BooleanSchema<\n ComputeInput<\n boolean,\n {\n nullable: true;\n array: State[\"array\"];\n }\n >,\n ComputeOutput<\n boolean,\n {\n nullable: true;\n array: State[\"array\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => BooleanScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: BooleanSchema<\n ComputeInput<\n boolean,\n {\n nullable: State[\"nullable\"];\n array: true;\n }\n >,\n ComputeOutput<\n boolean,\n {\n nullable: State[\"nullable\"];\n array: true;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => BooleanScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => BooleanScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.boolean({\n nullable: state.nullable,\n array: state.array,\n });\n }\n}\n\nexport const boolean = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new BooleanScalar(\n createDefaultState(\"boolean\", booleanBase),\n admitNativeType(\"s.boolean\", nativeType)\n );\n","// The chain the three temporal scalars share\n\nimport {\n generatorDefault,\n KeyedScalarChain,\n next,\n refuseListGenerator,\n type ScalarState,\n type scalarChain,\n} from \"../common\";\nimport { currentTemporalValue, type TemporalKind } from \"./current\";\n\n/** The value each generator of a kind writes: one closure per kind and generator. */\nconst generated = (kind: TemporalKind) => ({\n now: generatorDefault(() => currentTemporalValue(kind)),\n updatedAt: generatorDefault(() => currentTemporalValue(kind)),\n});\nconst GENERATED = {\n datetime: generated(\"datetime\"),\n date: generated(\"date\"),\n time: generated(\"time\"),\n};\n\n/** A generator writes one value: it cannot fill a list. */\nconst refuseList = (state: ScalarState) =>\n refuseListGenerator(\n `s.${state.type === \"datetime\" ? \"dateTime\" : state.type}`\n );\n\n/** The chain of a scalar that can take the instant of the write. */\nabstract class TemporalScalarChain extends KeyedScalarChain {\n #generated(kind: \"now\" | \"updatedAt\") {\n if (this.state.array) refuseList(this.state);\n return next(this, {\n hasDefault: true,\n autoGenerate: { kind },\n default: GENERATED[this.state.type as TemporalKind][kind],\n optional: true,\n });\n }\n override array() {\n const kind = this.state.autoGenerate?.kind;\n if (kind === \"now\" || kind === \"updatedAt\") refuseList(this.state);\n return super.array();\n }\n now() {\n return this.#generated(\"now\");\n }\n updatedAt() {\n return this.#generated(\"updatedAt\");\n }\n}\n\nexport const temporalScalarChain =\n TemporalScalarChain as unknown as typeof scalarChain;\n","// Date Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IsoDateSchema } from \"@validation/primitives/iso\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type GeneratorDefaultBrand,\n type ScalarState,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\nimport { temporalScalarChain } from \"./chain\";\n\nconst dateBase = v.isoDate();\n\nexport class DateScalar<\n State extends ScalarState<\"date\">,\n> extends temporalScalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => DateScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IsoDateSchema<\n ComputeInput<\n string | Date,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => DateScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IsoDateSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => DateScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => DateScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<string>>(\n schema: S\n ) => DateScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IsoDateSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => DateScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => DateScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly now: () => DateScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"now\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly updatedAt: () => DateScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"updatedAt\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.isoDate({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n}\n\nexport const date = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new DateScalar(\n createDefaultState(\"date\", dateBase),\n admitNativeType(\"s.date\", nativeType)\n );\n","// DateTime Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IsoTimestampSchema } from \"@validation/primitives/iso\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type GeneratorDefaultBrand,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\nimport { temporalScalarChain } from \"./chain\";\n\nconst datetimeBase = v.isoTimestamp();\n\nexport class DateTimeScalar<\n State extends ScalarState<\"datetime\">,\n> extends temporalScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IsoTimestampSchema<\n ComputeInput<\n string | Date,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IsoTimestampSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<string>>(\n schema: S\n ) => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IsoTimestampSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly map: (columnName: string) => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly now: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"now\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly updatedAt: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"updatedAt\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.isoTimestamp({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n withoutTimezone() {\n return new DateTimeScalar(\n updateState(this, { withTimezone: false }),\n this._nativeType\n );\n }\n}\n\nexport const dateTime = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new DateTimeScalar(\n { ...createDefaultState(\"datetime\", datetimeBase), withTimezone: true },\n admitNativeType(\"s.dateTime\", nativeType)\n );\n","// Time Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IsoTimeSchema } from \"@validation/primitives/iso\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type GeneratorDefaultBrand,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\nimport { temporalScalarChain } from \"./chain\";\n\nconst timeBase = v.isoTime();\n\nexport class TimeScalar<\n State extends ScalarState<\"time\">,\n> extends temporalScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IsoTimeSchema<\n ComputeInput<\n string | Date,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IsoTimeSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<string>>(\n schema: S\n ) => TimeScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IsoTimeSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => TimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => TimeScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly now: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"now\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly updatedAt: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"updatedAt\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.isoTime({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n /**\n * Stores time without timezone information (the default).\n * Use an explicit native type for an existing TIMETZ column.\n *\n * Use this when:\n * - You want to store local times (e.g., \"store opens at 9:00 AM\")\n * - The time should not be converted based on timezone\n */\n withoutTimezone() {\n return new TimeScalar(\n updateState(this, { withTimezone: false }),\n this._nativeType\n );\n }\n}\n\nexport const time = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new TimeScalar(\n { ...createDefaultState(\"time\", timeBase), withTimezone: false },\n admitNativeType(\"s.time\", nativeType)\n );\n","/**\n * The definition boundary for `s.decimal({ precision, scale })`.\n *\n * A scale cannot be inferred from storage, a value, a driver, or an operation:\n * SQLite ignores the numbers in `DECIMAL(10,5)` and may put a fractional value\n * in a binary64 double. So the domain is DECLARED once, here, and every later\n * consumer — validation, DDL, binding, decoding, comparison, arithmetic,\n * migration — reads that one frozen fact off the resolved scalar.\n *\n * The descriptor is the developer's own argument, or two numbers a schema\n * document carried verbatim; neither is a hostile object, so it is read like\n * any other argument — no read-once snapshot, no key enumeration. What this\n * module owns is whether the two numbers name a domain at all.\n */\n\nimport { ValidationError } from \"@errors\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { DecimalDescriptor } from \"@validation/primitives/decimal-codec\";\nimport { validateSchema } from \"@validation/primitives/helpers\";\nimport { isRecord } from \"@validation/value-guards\";\n\n/** The one construction-time refusal of a decimal declaration. */\nfunction refuse(path: string, message: string): never {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.decimal\", path },\n [{ path, message }]\n );\n}\n\n/**\n * The frozen fixed-decimal domain the two numbers name: `precision` an integer\n * from 1 to the maximum safe integer, `scale` an integer from 0 to `precision`,\n * so \"at most `precision` total digits and at most `scale` fractional digits\"\n * is a domain with values in it.\n *\n * Its unique coverage is the schema document and an untyped JavaScript caller:\n * `read.ts` hands the numbers over as they were written, so `10.5`, `1e300` and\n * `-0` (which `JSON.parse` keeps and `JSON.stringify` loses) reach this check\n * and nothing earlier. The argument is `unknown` because the document seam\n * passes it untyped; it is read as an ordinary object, not a hostile one.\n * Whether a given PROVIDER can store the domain is a different question with a\n * different owner: the adapter answers it once when the schema is bound.\n */\nexport function readDecimalDescriptor(source: unknown): DecimalDescriptor {\n const precision = isRecord(source) ? source.precision : undefined;\n const scale = isRecord(source) ? source.scale : undefined;\n if (\n !(\n typeof precision === \"number\" &&\n Number.isSafeInteger(precision) &&\n precision >= 1\n )\n ) {\n refuse(\n \"descriptor.precision\",\n \"'precision' must be an integer between 1 and the maximum safe integer\"\n );\n }\n if (\n !(\n typeof scale === \"number\" &&\n Number.isSafeInteger(scale) &&\n scale >= 0 &&\n scale <= precision &&\n !Object.is(scale, -0)\n )\n ) {\n refuse(\n \"descriptor.scale\",\n \"'scale' must be an integer between 0 and precision\"\n );\n }\n return Object.freeze({ precision, scale });\n}\n\n/**\n * A fixed-decimal LIST is not a key, and this is where a chain that tries to\n * make one into a key stops (plan 2.1).\n *\n * Both directions are refused because the chain has two of them:\n * `.array().id()` names a list and then a key, `.id().array()` names a key and\n * then a list, and only refusing the one that comes second would leave the\n * other spelling admitted. The exclusion is the DECLARATION's, not the\n * database's: a decimal list is stored as one container value on two of three\n * providers, so a key over it would be a key over a JSON document whose\n * identity is its spelling rather than its members — and there is no member\n * arrangement that could make it addressable.\n *\n * The whole-schema rule F007 (\"an ID cannot be an array\") is untouched and\n * still owns every OTHER scalar type. This refuses earlier, at the call that\n * writes the illegal chain, and it also owns `.unique()`, which no rule in the\n * repository refuses on a list of any type.\n */\nexport function refuseDecimalListKey(\n position: \"id\" | \"unique\" | \"array\"\n): never {\n const explanation =\n \"a fixed-decimal list cannot be an ID, a unique field, an index member, a foreign-key member, or a relation identity member\";\n refuse(\n position,\n position === \"array\"\n ? `A decimal key cannot become a list: ${explanation}`\n : `A decimal list cannot be declared '.${position}()': ${explanation}`\n );\n}\n\n/**\n * A literal default, normalized through the field's complete current schema at\n * DEFINITION time, so model metadata holds the canonical logical value the DDL\n * renderer, the schema-document serializer and the create schema's trusted\n * default all read. A value outside the declared domain fails at the call that\n * wrote it, not at the first write.\n *\n * A function default keeps its closure, exactly as every other scalar's does:\n * a closure has no canonical spelling to retain, and the create schema runs the\n * field codec on each value it returns.\n */\nexport function normalizeDecimalDefault(\n value: unknown,\n schema: StandardSchemaV1<unknown, unknown>\n): unknown {\n if (typeof value === \"function\") return value;\n const result = validateSchema(schema, value);\n if (result.issues !== undefined) {\n refuse(\"default\", \"The decimal default did not satisfy its field schema\");\n }\n return result.value;\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { DecimalDescriptor } from \"@validation/primitives/decimal-codec\";\nimport type { Decimal } from \"@validation/primitives/decimal-value\";\nimport v from \"@validation/primitives/v\";\nimport type { VibSchema } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n type UpdateState,\n untypedKeyedScalarChain,\n updateState,\n} from \"../common\";\nimport {\n normalizeDecimalDefault,\n readDecimalDescriptor,\n refuseDecimalListKey,\n} from \"./descriptor\";\n\n/**\n * The shared L1 descriptor supplies the two required keys. This intersection\n * makes that surface exact for held objects too, without declaring a second L2\n * precision/scale bag.\n */\ntype KeysOfUnion<Given> = Given extends unknown ? keyof Given : never;\n\ntype ExactDomain<Given> = Given &\n Record<Exclude<KeysOfUnion<Given>, keyof DecimalDescriptor>, never>;\n\n/**\n * The type-level half of plan 2.1's list exclusion.\n *\n * A key position is refused by making the RECEIVER unassignable, which is what\n * lets the diagnostic carry the reason: TypeScript reports the missing property\n * by name, so `s.decimal({...}).array().id()` reads as \"a fixed-decimal list\n * cannot be a key\" rather than as an arity or an argument error. The scalar's\n * own type is intersected in, so inside the method body `this` is the scalar it\n * has always been and no assertion is needed to reach its state.\n *\n * `unknown` on the legal side is inert: intersecting it changes nothing, so a\n * non-list decimal keeps exactly the chain it had, and a scalar whose arity is\n * still the unresolved `boolean` is admitted — only a declared list is refused.\n */\ninterface DecimalListKeyRefusal {\n readonly \"a fixed-decimal list cannot be a key\": never;\n}\n\ntype NotAList<State extends ScalarState<\"decimal\">> =\n State[\"array\"] extends true ? DecimalListKeyRefusal : unknown;\n\ntype NotAKey<State extends ScalarState<\"decimal\">> = State[\"isId\"] extends true\n ? DecimalListKeyRefusal\n : State[\"isUnique\"] extends true\n ? DecimalListKeyRefusal\n : unknown;\n\ntype DecimalScalarState<State extends ScalarState<\"decimal\">> = State & {\n readonly decimal: DecimalDescriptor;\n};\n\nexport class DecimalScalar<\n out State extends ScalarState<\"decimal\">,\n> extends untypedKeyedScalarChain<DecimalScalarState<State>> {\n private declare readonly state: DecimalScalarState<State>;\n\n protected rebase(state: DecimalScalarState<State>): VibSchema {\n return v.decimal({\n nullable: state.nullable,\n array: state.array,\n decimal: state.decimal,\n schema: state.schema,\n });\n }\n\n /**\n * A literal default follows the base it was normalized through: a modifier\n * that rebuilds the base normalizes the default again, through the new one.\n */\n private again<Next extends { \"~\": { state: ScalarState } }>(next: Next) {\n if (this.state.hasDefault && typeof this.state.default !== \"function\") {\n next[\"~\"].state.default = normalizeDecimalDefault(\n this.state.default,\n next[\"~\"].state.base\n );\n }\n return next;\n }\n\n override nullable() {\n return super.nullable() as DecimalScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends false\n ? null\n : State[\"default\"];\n readonly optional: true;\n readonly base: ReturnType<\n typeof v.decimal<{\n nullable: true;\n array: State[\"array\"];\n decimal: DecimalDescriptor;\n schema: State[\"schema\"];\n }>\n >;\n }\n >\n >;\n }\n\n override array(this: DecimalScalar<State> & NotAKey<State>) {\n if (this.state.isId || this.state.isUnique) refuseDecimalListKey(\"array\");\n return this.again(\n super.array() as DecimalScalar<\n UpdateState<\n DecimalScalarState<State>,\n {\n readonly array: true;\n readonly base: ReturnType<\n typeof v.decimal<{\n nullable: State[\"nullable\"];\n array: true;\n decimal: DecimalDescriptor;\n schema: State[\"schema\"];\n }>\n >;\n }\n >\n >\n );\n }\n\n override id(this: DecimalScalar<State> & NotAList<State>) {\n if (this.state.array) refuseDecimalListKey(\"id\");\n return super.id() as DecimalScalar<\n UpdateState<\n DecimalScalarState<State>,\n { readonly isId: true; readonly isUnique: true }\n >\n >;\n }\n\n override unique(this: DecimalScalar<State> & NotAList<State>) {\n if (this.state.array) refuseDecimalListKey(\"unique\");\n return super.unique() as DecimalScalar<\n UpdateState<DecimalScalarState<State>, { readonly isUnique: true }>\n >;\n }\n\n /**\n * A literal default is normalized through the field codec HERE, at\n * definition time, so model metadata retains the canonical logical value and\n * a schema document round-trips to the same declaration. A value outside the\n * declared domain fails at the call that wrote it, not at the first write.\n */\n override default<V extends DefaultValueInput<State>>(value: V) {\n return withValidatedDecimalDefault(\n this,\n normalizeDecimalDefault(value, this.state.base)\n );\n }\n\n /**\n * Refine or brand the exact value. The schema observes a `Decimal` — the\n * public value type — and the declared domain validates whatever it returns\n * LAST, so a custom schema can narrow the domain but never escape it, and it\n * cannot change the value family the field reads back as.\n */\n override schema<S extends StandardSchemaV1<Decimal>>(schema: S) {\n return this.again(\n super.schema(schema) as DecimalScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly schema: S;\n readonly base: ReturnType<\n typeof v.decimal<{\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n decimal: DecimalDescriptor;\n schema: S;\n }>\n >;\n }\n >\n >\n );\n }\n\n override map(columnName: string) {\n return super.map(columnName) as DecimalScalar<\n UpdateState<this[\"~\"][\"state\"], { readonly columnName: string }>\n >;\n }\n\n get [\"~\"](): {\n state: DecimalScalarState<State>;\n nativeType?: undefined;\n } {\n return { state: this.state };\n }\n}\n\n/**\n * Store the canonical verdict of the field's current base schema.\n *\n * This is an internal schema-document seam, deliberately absent from the\n * public decimal barrel. The document interpreter already has to validate a\n * decoded default to own its J008 diagnostic; feeding that verdict back\n * through `.default()` would run the same field codec a second time.\n */\nexport function withValidatedDecimalDefault<\n State extends ScalarState<\"decimal\">,\n>(scalar: DecimalScalar<State>, value: unknown) {\n return new DecimalScalar(\n updateState(scalar, {\n hasDefault: true,\n default: value,\n optional: true,\n })\n );\n}\n\n/**\n * The one public decimal factory.\n *\n * `precision` is the maximum total digit count and `scale` the maximum\n * fractional digit count; values are multiples of `10^-scale`, and an input\n * that does not fit is refused rather than silently rounded. There is no\n * zero-argument form, no native-type override, and no second \"fixed decimal\"\n * factory: portable exact decimal arithmetic needs these two numbers, and\n * SQLite cannot supply them from storage, so they are declared once here.\n */\nexport const buildDecimalScalar = (descriptor: unknown) => {\n const domain = readDecimalDescriptor(descriptor);\n return new DecimalScalar({\n ...createDefaultState(\n \"decimal\",\n v.decimal<{ decimal: DecimalDescriptor }>({ decimal: domain })\n ),\n decimal: domain,\n });\n};\n\n/** The exact public argument surface over the untyped construction seam. */\nexport const decimal = <const D>(\n descriptor: D & NoInfer<DecimalDescriptor & ExactDomain<D>>\n) => buildDecimalScalar(descriptor);\n","// Enum Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; an enum keeps them as methods, typed on its own values\n\nimport type { EnumSchema } from \"@validation/primitives/enum\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput, VibSchema } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n type UpdateState,\n untypedListScalarChain,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\n/**\n * The values of an enum in this state. A state that names no values (the wide\n * one a model's fields are read through) has some strings, not none: a precise\n * enum is then an enum of the wide kind member by member.\n */\ntype Values<State extends ScalarState<\"enum\">> =\n State[\"base\"] extends EnumSchema<infer T, any, any> ? T : readonly string[];\n\nexport class EnumScalar<\n out State extends ScalarState<\"enum\">,\n> extends untypedListScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n\n get enumValues() {\n return (\n \"values\" in this.state.base ? this.state.base.values : []\n ) as Values<State>;\n }\n\n protected rebase(state: State): VibSchema {\n return v.enum(this.enumValues, {\n nullable: state.nullable,\n array: state.array,\n });\n }\n\n override nullable() {\n return super.nullable() as EnumScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends false\n ? null\n : State[\"default\"];\n readonly optional: true;\n readonly base: EnumSchema<\n Values<State>,\n ComputeInput<\n Values<State>[number],\n { nullable: true; array: State[\"array\"] }\n >,\n ComputeOutput<\n Values<State>[number],\n { nullable: true; array: State[\"array\"] }\n >\n >;\n }\n >\n >;\n }\n\n override array() {\n return super.array() as EnumScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly array: true;\n readonly base: EnumSchema<\n Values<State>,\n ComputeInput<\n Values<State>[number],\n { nullable: State[\"nullable\"]; array: true }\n >,\n ComputeOutput<\n Values<State>[number],\n { nullable: State[\"nullable\"]; array: true }\n >\n >;\n }\n >\n >;\n }\n\n override default<V extends DefaultValueInput<State>>(value: V) {\n return super.default(value) as EnumScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n }\n\n override map(columnName: string) {\n return super.map(columnName) as EnumScalar<\n UpdateState<this[\"~\"][\"state\"], { readonly columnName: string }>\n >;\n }\n\n /**\n * Set a custom name for the enum type in the database.\n * This allows reusing the same enum across multiple tables.\n *\n * @example\n * ```ts\n * const Status = s.enum([\"PENDING\", \"ACTIVE\"]).name(\"status\");\n *\n * const user = s.model({ status: Status });\n * const order = s.model({ status: Status }); // Same \"status\" enum type\n * ```\n */\n name(enumName: string) {\n return new EnumScalar(\n { ...this.state, enumName } as UpdateState<\n State,\n { readonly enumName: string }\n >,\n this._nativeType\n );\n }\n\n get [\"~\"]() {\n return {\n state: this.state,\n nativeType: this._nativeType,\n };\n }\n}\n\nexport const enumScalar = <\n // A readonly tuple is admitted; see `enum_` for the mutable arm.\n const T extends string[] | readonly string[],\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n values: T,\n nativeType?: NativeTypeArgument<Db, Given>\n) => {\n return new EnumScalar(\n createDefaultState(\"enum\", v.enum(values)),\n admitNativeType(\"s.enum\", nativeType)\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IntegerSchema } from \"@validation/primitives/number\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n keyedScalarChain,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst intBase = v.integer();\n\nexport class IntScalar<\n State extends ScalarState<\"int\">,\n> extends keyedScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => IntScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IntegerSchema<\n ComputeInput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => IntScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IntegerSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => IntScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => IntScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => IntScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<number>>(\n schema: S\n ) => IntScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IntegerSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => IntScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.integer({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n increment() {\n return new IntScalar(\n updateState(this, {\n hasDefault: true,\n autoGenerate: { kind: \"increment\" },\n default: undefined,\n disallowZero: true,\n optional: true,\n }),\n this._nativeType\n );\n }\n}\n\nexport const int = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new IntScalar(\n createDefaultState(\"int\", intBase),\n admitNativeType(\"s.int\", nativeType)\n );\n","import { ValidationError } from \"@errors\";\nimport {\n JsonNull,\n type JsonNullSentinel,\n jsonNullKindOf,\n} from \"@schema/json-null\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonValue } from \"@validation\";\nimport type { JsonInput, JsonSchema } from \"@validation/primitives/json\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValue,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst jsonBase = v.json();\n\nexport class JsonScalar<\n State extends ScalarState<\"json\"> = ScalarState<\"json\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => JsonScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: JsonSchema<\n ComputeInput<\n JsonInput,\n {\n nullable: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n JsonValue,\n {\n nullable: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => JsonScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.json({\n nullable: state.nullable,\n schema: state.schema,\n });\n }\n\n default<\n V extends\n | DefaultValueInput<State>\n | DefaultValue<\n JsonNullSentinel<\n State[\"nullable\"] extends true ? \"JsonNull\" | \"DbNull\" : \"JsonNull\"\n >\n >,\n >(value: V) {\n const kind = jsonNullKindOf(value);\n if (kind === \"AnyNull\" || (kind === \"DbNull\" && !this.state.nullable)) {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.json\", path: \"default\" },\n [\n {\n path: \"default\",\n message: \"JSON default must name a null this column can store\",\n },\n ]\n );\n }\n const defaultValue =\n value === null && !this.state.nullable ? JsonNull : value;\n return new JsonScalar(\n updateState(this, {\n hasDefault: true,\n default: defaultValue,\n optional: true,\n }),\n this._nativeType\n );\n }\n\n schema<S extends StandardSchemaV1<JsonInput, JsonValue>>(schema: S) {\n return new JsonScalar(\n updateState(this, {\n schema,\n base: v.json<{\n nullable: State[\"nullable\"];\n schema: S;\n }>({\n nullable: this.state.nullable,\n schema,\n }),\n }),\n this._nativeType\n );\n }\n}\n\nexport const json = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new JsonScalar(\n createDefaultState(\"json\", jsonBase),\n admitNativeType(\"s.json\", nativeType)\n );\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { NumberSchema } from \"@validation/primitives/number\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n keyedScalarChain,\n type ScalarState,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst numberBase = v.number();\n\nexport class NumberScalar<\n State extends ScalarState<\"number\">,\n> extends keyedScalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: NumberSchema<\n ComputeInput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: NumberSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => NumberScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<number>>(\n schema: S\n ) => NumberScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: NumberSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => NumberScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.number({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n}\n\nexport const number = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new NumberScalar(\n createDefaultState(\"number\", numberBase),\n admitNativeType(\"s.number\", nativeType)\n );\n","import { ValidationError } from \"@errors\";\nimport type { GeoPoint } from \"@validation/primitives/geo-point-codec\";\nimport { validateSchema } from \"@validation/primitives/helpers\";\nimport type { PointSchema } from \"@validation/primitives/point\";\nimport v from \"@validation/primitives/v\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n updateState,\n} from \"../common\";\n\nconst pointBase = v.point();\n\nexport class PointScalar<\n State extends ScalarState<\"point\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => PointScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: PointSchema<GeoPoint | null, GeoPoint | null>;\n }\n >\n >;\n declare readonly map: (columnName: string) => PointScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n\n protected rebase(state: State) {\n return v.point({\n nullable: state.nullable,\n });\n }\n\n // biome-ignore lint/complexity/noUselessConstructor: a point has no native type, so its constructor takes none\n constructor(state: State) {\n super(state);\n }\n\n default<V extends DefaultValueInput<State>>(value: V) {\n return new PointScalar(\n updateState(this, {\n hasDefault: true,\n default: normalizePointDefault(value, this.state.base),\n optional: true,\n })\n );\n }\n\n get [\"~\"](): { state: State; nativeType?: undefined } {\n return { state: this.state };\n }\n}\n\nfunction normalizePointDefault(value: unknown, schema: StateSchema): unknown {\n if (typeof value === \"function\") return value;\n const result = validateSchema(schema, value);\n if (!result.issues) return result.value;\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.point\", path: \"default\" },\n result.issues.map((issue) => ({\n path: issue.path?.join(\".\") ?? \"default\",\n message: issue.message,\n }))\n );\n}\n\ntype StateSchema = ScalarState<\"point\">[\"base\"];\n\n/** The one public GeoPoint scalar factory; EPSG:4326 is not configurable. */\nexport function point(...args: []) {\n if (args.length !== 0) {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.point\", path: \"arguments\" },\n [\n {\n path: \"arguments\",\n message: \"s.point() takes no native type or options\",\n },\n ]\n );\n }\n return new PointScalar(createDefaultState(\"point\", pointBase));\n}\n","// Vector Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport { ValidationError } from \"@errors\";\nimport v from \"@validation/primitives/v\";\nimport type { VectorSchema } from \"@validation/primitives/vector\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst vectorBase = v.vector();\n\nexport class VectorScalar<\n State extends ScalarState<\"vector\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => VectorScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: VectorSchema<number[] | null, number[] | null> & {\n dimensions?: number;\n };\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => VectorScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => VectorScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.vector(state.dimension, {\n nullable: state.nullable,\n });\n }\n\n dimension(dim: number) {\n if (!Number.isSafeInteger(dim) || dim <= 0) {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.vector\", path: \"dimension\" },\n [\n {\n path: \"dimension\",\n message: \"Vector dimension must be a positive safe integer\",\n },\n ]\n );\n }\n return new VectorScalar(\n updateState(this, {\n dimension: dim,\n base: v.vector(dim, { nullable: this.state.nullable }),\n }),\n this._nativeType\n );\n }\n}\n\nexport const vector = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new VectorScalar(\n createDefaultState(\"vector\", vectorBase),\n admitNativeType(\"s.vector\", nativeType)\n );\n","// `s.toMany` — the other of the two relation factories.\n//\n// The factory states the SLOT CARDINALITY (many) and its argument states the\n// TARGET DOMAIN. A model-target collection is junction-capable and an empty\n// collection is `[]`, so there is no `.optional()` here and no `.unique()`\n// anywhere: the paired slot cardinality owns remote uniqueness.\n\nimport {\n type ExactVariantOptions,\n type NormalizedManyEntries,\n normalizeVariantEntries,\n type VariantGetterMap,\n type VariantMapGuard,\n type VariantOptions,\n type VariantToManyRelation,\n variantToManyTerminal,\n} from \"./polymorphic\";\nimport {\n createTargetSettlement,\n normalizeJunctionActions,\n normalizeJunctionToken,\n normalizeRelationName,\n refuseRelationInput,\n} from \"./terminal\";\nimport type {\n AnyRelation,\n Getter,\n GetterOnly,\n JunctionReferentialAction,\n JunctionSideActions,\n ModelToManyState,\n OrdinaryJunctionOverrides,\n RelationInternal,\n Replace,\n} from \"./types\";\n\n// =============================================================================\n// TERMINAL CAPABILITY SURFACE\n// =============================================================================\n\n/** A junction action: the symmetric shorthand, or one action per side. */\nexport type JunctionActionDeclaration =\n | JunctionReferentialAction\n | JunctionSideActions;\n\n/** Every key any map member of `Action` declares; a bare action declares none. */\ntype DeclaredMapKeys<Action> = Action extends JunctionReferentialAction\n ? never\n : keyof Action;\n\n/**\n * `{ source, target }` is exact: a key beside the two sides is refused\n * structurally, so a map held in a variable cannot carry one past\n * excess-property checking either. The keys are gathered across a union\n * before the check, so one clean member cannot vouch for another that carries\n * an extra key.\n */\nexport type ExactJunctionActions<Action> = Record<\n Exclude<DeclaredMapKeys<Action>, keyof JunctionSideActions>,\n never\n>;\n\n/**\n * `.source()` / `.target()` after a declared model's `.through()` names one of\n * its relations, which is what `$through` keeps a link's own columns apart by.\n * On any other junction a token is only a name and the state stays as it was.\n */\ntype WithJunctionSide<State, Side extends string, Token> = State extends {\n readonly junction: { readonly model: unknown };\n}\n ? Replace<\n State,\n { readonly junction: State[\"junction\"] & { readonly [K in Side]: Token } }\n >\n : State;\n\n/**\n * A model-target collection slot.\n *\n * The junction overrides are independent, meaningful facts rather than stages of\n * one all-or-nothing value, so any subset may override its canonical default.\n * Exactly one endpoint owns all supplied overrides; the other endpoint supplies\n * none and consumes the mirrored resolved view. Whether these overrides belong\n * on the resolved physical owner is one full-schema topology rule, not a second\n * type-level guess — which is why they are offered before the inverse graph\n * exists and why the state does not carry them as a public type parameter.\n */\nexport type ModelToManyRelation<State> = {\n readonly \"~\": RelationInternal<State>;\n name<const Name extends string>(\n name: Name\n ): ModelToManyRelation<Replace<State, { readonly name: Name }>>;\n through(table: string): ModelToManyRelation<State>;\n /**\n * A declared model as the junction: its table, columns and delegate stay its\n * own and `.source()` / `.target()` name its to-one relations. The getter is\n * kept as a target's is and read only where a query asks for `$through`: the\n * junction model's relations point back here, so `.source()` naming them in\n * its own signature would resolve a circular const.\n */\n through<const G>(\n model: G & GetterOnly<G>\n ): ModelToManyRelation<\n Replace<State, { readonly junction: { readonly model: G } }>\n >;\n source<const Token extends string>(\n token: Token\n ): ModelToManyRelation<WithJunctionSide<State, \"source\", Token>>;\n target<const Token extends string>(\n token: Token\n ): ModelToManyRelation<WithJunctionSide<State, \"target\", Token>>;\n onDelete<const Action extends JunctionActionDeclaration>(\n action: Action & ExactJunctionActions<Action>\n ): ModelToManyRelation<State>;\n onUpdate<const Action extends JunctionActionDeclaration>(\n action: Action & ExactJunctionActions<Action>\n ): ModelToManyRelation<State>;\n};\n\n// =============================================================================\n// PRIVATE TERMINAL\n// =============================================================================\n\nclass ModelToMany {\n readonly #state: ModelToManyState;\n readonly #internal: RelationInternal<ModelToManyState>;\n\n constructor(state: ModelToManyState) {\n this.#state = Object.freeze(state);\n this.#internal = Object.freeze({\n state: this.#state,\n settleTarget: createTargetSettlement(() => this.#state.target.getter),\n settleJunctionModel: createTargetSettlement(\n () => this.#state.junction?.model\n ),\n });\n }\n\n name(name: string): ModelToMany {\n return new ModelToMany({\n ...this.#state,\n name: normalizeRelationName(\"s.toMany\", name),\n });\n }\n\n through(junction: unknown): ModelToMany {\n const { table, model, ...overrides } = this.#state.junction ?? {};\n return this.#withJunction(\n typeof junction === \"function\"\n ? { ...overrides, model: junction as () => any }\n : {\n ...overrides,\n table: normalizeJunctionToken(\"through\", junction),\n }\n );\n }\n\n source(token: string): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n source: normalizeJunctionToken(\"source\", token),\n });\n }\n\n target(token: string): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n target: normalizeJunctionToken(\"target\", token),\n });\n }\n\n onDelete(action: JunctionActionDeclaration): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n onDelete: normalizeJunctionActions(\"onDelete\", action),\n });\n }\n\n onUpdate(action: JunctionActionDeclaration): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n onUpdate: normalizeJunctionActions(\"onUpdate\", action),\n });\n }\n\n #withJunction(junction: OrdinaryJunctionOverrides): ModelToMany {\n return new ModelToMany({\n ...this.#state,\n junction: Object.freeze(junction),\n });\n }\n\n get \"~\"(): RelationInternal<ModelToManyState> {\n return this.#internal;\n }\n}\n\n// =============================================================================\n// FACTORY\n// =============================================================================\n\n/**\n * Declare a slot that holds a COLLECTION.\n *\n * The map overload is declared first so a variant map is never swallowed by the\n * broad getter overload. Dispatch examines only the argument representation and\n * never invokes a getter.\n */\nexport function toMany<\n const Entries extends VariantGetterMap,\n const Options extends VariantOptions<Entries> | undefined = undefined,\n>(\n variants: Entries & VariantMapGuard<Entries>,\n options?: Options & ExactVariantOptions<Options, Entries>\n): VariantToManyRelation<{\n readonly kind: \"relation\";\n readonly cardinality: \"many\";\n readonly target: {\n readonly kind: \"variants\";\n readonly entries: NormalizedManyEntries<Entries>;\n };\n}>;\nexport function toMany<const G>(getter: G & GetterOnly<G>): G extends Getter\n ? ModelToManyRelation<{\n readonly kind: \"relation\";\n readonly cardinality: \"many\";\n readonly target: { readonly kind: \"model\"; readonly getter: G };\n }>\n : never;\nexport function toMany(target: unknown, options?: unknown): AnyRelation {\n if (typeof target === \"function\") {\n // biome-ignore lint/complexity/noArguments: distinguishes omission from explicit undefined without changing the factory's public arity\n if (arguments.length > 1) {\n refuseRelationInput(\n \"s.toMany\",\n \"options\",\n \"A model-target relation takes exactly one argument\"\n );\n }\n return new ModelToMany({\n kind: \"relation\",\n cardinality: \"many\",\n target: { kind: \"model\", getter: target },\n });\n }\n return variantToManyTerminal({\n kind: \"relation\",\n cardinality: \"many\",\n target: {\n kind: \"variants\",\n entries: normalizeVariantEntries(\"s.toMany\", target, options),\n },\n });\n}\n"],"mappings":"qZAwBA,MAAM,EAAaA,EAAE,QAAQ,CAE7B,IAAa,EAAb,MAAa,qBAEH,CAAwB,CAkIhC,OAAiB,EAAc,CAC7B,OAAOA,EAAE,OAAO,CACd,SAAU,EAAM,SAChB,MAAO,EAAM,MACb,OAAQ,EAAM,OACf,CAAC,CAGJ,WAAY,CACV,OAAO,IAAI,aACT,EAAY,KAAM,CAChB,WAAY,GACZ,aAAc,CAAE,KAAM,YAAa,CACnC,QAAS,IAAA,GACT,aAAc,GACd,SAAU,GACX,CAAC,CACF,KAAK,YACN,GAIL,MAAa,OAIX,GAEA,IAAI,EACF,EAAmB,SAAU,EAAW,CACxC,EAAgB,WAAY,EAAW,CACxC,CCxKG,EAAWC,EAAE,MAAM,CAEzB,IAAa,WAAb,cAEU,CAAmB,CA+C3B,OAAi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,CACjC,OAAO,MAAA,EAAmB,CACxB,GAAG,MAAA,EAAY,SACf,OAAQ,EAAuB,SAAU,EAAM,CAChD,CAAC,CAGJ,SAAS,EAAgD,CACvD,OAAO,MAAA,EAAmB,CACxB,GAAG,MAAA,EAAY,SACf,SAAU,EAAyB,WAAY,EAAO,CACvD,CAAC,CAGJ,SAAS,EAAgD,CACvD,OAAO,MAAA,EAAmB,CACxB,GAAG,MAAA,EAAY,SACf,SAAU,EAAyB,WAAY,EAAO,CACvD,CAAC,CAGJ,GAAc,EAAkD,CAC9D,OAAO,IAAI,YAAY,CACrB,GAAG,MAAA,EACH,SAAU,OAAO,OAAO,EAAS,CAClC,CAAC,CAGJ,GAAI,KAA0C,CAC5C,OAAO,MAAA,IAoCX,SAAgB,OAAO,EAAiB,EAAgC,CAgBtE,OAfI,OAAO,GAAW,YAEhB,UAAU,OAAS,GACrB,EACE,WACA,UACA,qDACD,CAEI,IAAI,EAAY,CACrB,KAAM,WACN,YAAa,OACb,OAAQ,CAAE,KAAM,QAAS,OAAQ,EAAQ,CAC1C,CAAC,EAEG,EAAsB,CAC3B,KAAM,WACN,YAAa,OACb,OAAQ,CACN,KAAM,WACN,QAAS,EAAwB,WAAY,EAAQ,EAAQ,CAC9D,CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"to-many-DiP6cOSQ.mjs","names":["v","v","v","#generated","v","v","v","v","next","v","v","v","v","v","v","#state","#internal","#withJunction"],"sources":["../src/schema/scalars/bigint/scalar.ts","../src/schema/scalars/blob/scalar.ts","../src/schema/scalars/boolean/scalar.ts","../src/schema/scalars/datetime/chain.ts","../src/schema/scalars/datetime/date-scalar.ts","../src/schema/scalars/datetime/scalar.ts","../src/schema/scalars/datetime/time-scalar.ts","../src/schema/scalars/decimal/descriptor.ts","../src/schema/scalars/decimal/scalar.ts","../src/schema/scalars/enum/scalar.ts","../src/schema/scalars/int/scalar.ts","../src/schema/scalars/json/scalar.ts","../src/schema/scalars/number/scalar.ts","../src/schema/scalars/point/scalar.ts","../src/schema/scalars/vector/scalar.ts","../src/schema/relation/to-many.ts"],"sourcesContent":["// BigInt Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BigIntSchema } from \"@validation/primitives/bigint\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n keyedScalarChain,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst bigIntBase = v.bigint();\n\nexport class BigIntScalar<\n State extends ScalarState<\"bigint\">,\n> extends keyedScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: BigIntSchema<\n ComputeInput<\n bigint,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n bigint,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: BigIntSchema<\n ComputeInput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => BigIntScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => BigIntScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<bigint>>(\n schema: S\n ) => BigIntScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: BigIntSchema<\n ComputeInput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n bigint,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => BigIntScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.bigint({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n increment() {\n return new BigIntScalar(\n updateState(this, {\n hasDefault: true,\n autoGenerate: { kind: \"increment\" },\n default: undefined,\n disallowZero: true,\n optional: true,\n }),\n this._nativeType\n );\n }\n}\n\nexport const bigInt = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new BigIntScalar(\n createDefaultState(\"bigint\", bigIntBase),\n admitNativeType(\"s.bigInt\", nativeType)\n );\n","// Blob Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { BlobSchema } from \"@validation/primitives/blob\";\nimport v from \"@validation/primitives/v\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst blobBase = v.blob();\n\nexport class BlobScalar<\n State extends ScalarState<\"blob\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => BlobScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: BlobSchema<\n Uint8Array<ArrayBufferLike> | null,\n Uint8Array<ArrayBufferLike> | null\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => BlobScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => BlobScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.blob({\n nullable: state.nullable,\n });\n }\n\n // Blob scalars don't support array(), id(), or unique()\n array(): never {\n throw new Error(\"Blob scalars don't support array modifier\");\n }\n\n id(): never {\n throw new Error(\"Blob scalars cannot be used as IDs\");\n }\n\n unique(): never {\n throw new Error(\"Blob scalars cannot be unique\");\n }\n}\n\nexport const blob = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new BlobScalar(\n createDefaultState(\"blob\", blobBase),\n admitNativeType(\"s.blob\", nativeType)\n );\n","// Boolean Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { BooleanSchema } from \"@validation/primitives/boolean\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n listScalarChain,\n type ScalarState,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst booleanBase = v.boolean();\n\nexport class BooleanScalar<\n State extends ScalarState<\"boolean\">,\n> extends listScalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => BooleanScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: BooleanSchema<\n ComputeInput<\n boolean,\n {\n nullable: true;\n array: State[\"array\"];\n }\n >,\n ComputeOutput<\n boolean,\n {\n nullable: true;\n array: State[\"array\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => BooleanScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: BooleanSchema<\n ComputeInput<\n boolean,\n {\n nullable: State[\"nullable\"];\n array: true;\n }\n >,\n ComputeOutput<\n boolean,\n {\n nullable: State[\"nullable\"];\n array: true;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => BooleanScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => BooleanScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.boolean({\n nullable: state.nullable,\n array: state.array,\n });\n }\n}\n\nexport const boolean = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new BooleanScalar(\n createDefaultState(\"boolean\", booleanBase),\n admitNativeType(\"s.boolean\", nativeType)\n );\n","// The chain the three temporal scalars share\n\nimport {\n generatorDefault,\n KeyedScalarChain,\n next,\n refuseListGenerator,\n type ScalarState,\n type scalarChain,\n} from \"../common\";\nimport { currentTemporalValue, type TemporalKind } from \"./current\";\n\n/** The value each generator of a kind writes: one closure per kind and generator. */\nconst generated = (kind: TemporalKind) => ({\n now: generatorDefault(() => currentTemporalValue(kind)),\n updatedAt: generatorDefault(() => currentTemporalValue(kind)),\n});\nconst GENERATED = {\n datetime: generated(\"datetime\"),\n date: generated(\"date\"),\n time: generated(\"time\"),\n};\n\n/** A generator writes one value: it cannot fill a list. */\nconst refuseList = (state: ScalarState) =>\n refuseListGenerator(\n `s.${state.type === \"datetime\" ? \"dateTime\" : state.type}`\n );\n\n/** The chain of a scalar that can take the instant of the write. */\nabstract class TemporalScalarChain extends KeyedScalarChain {\n #generated(kind: \"now\" | \"updatedAt\") {\n if (this.state.array) refuseList(this.state);\n return next(this, {\n hasDefault: true,\n autoGenerate: { kind },\n default: GENERATED[this.state.type as TemporalKind][kind],\n optional: true,\n });\n }\n override array() {\n const kind = this.state.autoGenerate?.kind;\n if (kind === \"now\" || kind === \"updatedAt\") refuseList(this.state);\n return super.array();\n }\n now() {\n return this.#generated(\"now\");\n }\n updatedAt() {\n return this.#generated(\"updatedAt\");\n }\n}\n\nexport const temporalScalarChain =\n TemporalScalarChain as unknown as typeof scalarChain;\n","// Date Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IsoDateSchema } from \"@validation/primitives/iso\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type GeneratorDefaultBrand,\n type ScalarState,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\nimport { temporalScalarChain } from \"./chain\";\n\nconst dateBase = v.isoDate();\n\nexport class DateScalar<\n State extends ScalarState<\"date\">,\n> extends temporalScalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => DateScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IsoDateSchema<\n ComputeInput<\n string | Date,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => DateScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IsoDateSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => DateScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => DateScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<string>>(\n schema: S\n ) => DateScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IsoDateSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => DateScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => DateScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly now: () => DateScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"now\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly updatedAt: () => DateScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"updatedAt\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.isoDate({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n}\n\nexport const date = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new DateScalar(\n createDefaultState(\"date\", dateBase),\n admitNativeType(\"s.date\", nativeType)\n );\n","// DateTime Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IsoTimestampSchema } from \"@validation/primitives/iso\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type GeneratorDefaultBrand,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\nimport { temporalScalarChain } from \"./chain\";\n\nconst datetimeBase = v.isoTimestamp();\n\nexport class DateTimeScalar<\n State extends ScalarState<\"datetime\">,\n> extends temporalScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IsoTimestampSchema<\n ComputeInput<\n string | Date,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IsoTimestampSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<string>>(\n schema: S\n ) => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IsoTimestampSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly map: (columnName: string) => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly now: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"now\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly updatedAt: () => DateTimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"updatedAt\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.isoTimestamp({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n withoutTimezone() {\n return new DateTimeScalar(\n updateState(this, { withTimezone: false }),\n this._nativeType\n );\n }\n}\n\nexport const dateTime = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new DateTimeScalar(\n { ...createDefaultState(\"datetime\", datetimeBase), withTimezone: true },\n admitNativeType(\"s.dateTime\", nativeType)\n );\n","// Time Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IsoTimeSchema } from \"@validation/primitives/iso\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type GeneratorDefaultBrand,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\nimport { temporalScalarChain } from \"./chain\";\n\nconst timeBase = v.isoTime();\n\nexport class TimeScalar<\n State extends ScalarState<\"time\">,\n> extends temporalScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IsoTimeSchema<\n ComputeInput<\n string | Date,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IsoTimeSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<string>>(\n schema: S\n ) => TimeScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IsoTimeSchema<\n ComputeInput<\n string | Date,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n string,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => TimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => TimeScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly now: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"now\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly updatedAt: () => TimeScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly autoGenerate: {\n readonly kind: \"updatedAt\";\n };\n readonly default: (() => string) & GeneratorDefaultBrand;\n readonly optional: true;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.isoTime({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n /**\n * Stores time without timezone information (the default).\n * Use an explicit native type for an existing TIMETZ column.\n *\n * Use this when:\n * - You want to store local times (e.g., \"store opens at 9:00 AM\")\n * - The time should not be converted based on timezone\n */\n withoutTimezone() {\n return new TimeScalar(\n updateState(this, { withTimezone: false }),\n this._nativeType\n );\n }\n}\n\nexport const time = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new TimeScalar(\n { ...createDefaultState(\"time\", timeBase), withTimezone: false },\n admitNativeType(\"s.time\", nativeType)\n );\n","/**\n * The definition boundary for `s.decimal({ precision, scale })`.\n *\n * A scale cannot be inferred from storage, a value, a driver, or an operation:\n * SQLite ignores the numbers in `DECIMAL(10,5)` and may put a fractional value\n * in a binary64 double. So the domain is DECLARED once, here, and every later\n * consumer — validation, DDL, binding, decoding, comparison, arithmetic,\n * migration — reads that one frozen fact off the resolved scalar.\n *\n * The descriptor is the developer's own argument, or two numbers a schema\n * document carried verbatim; neither is a hostile object, so it is read like\n * any other argument — no read-once snapshot, no key enumeration. What this\n * module owns is whether the two numbers name a domain at all.\n */\n\nimport { ValidationError } from \"@errors\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { DecimalDescriptor } from \"@validation/primitives/decimal-codec\";\nimport { validateSchema } from \"@validation/primitives/helpers\";\nimport { isRecord } from \"@validation/value-guards\";\n\n/** The one construction-time refusal of a decimal declaration. */\nfunction refuse(path: string, message: string): never {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.decimal\", path },\n [{ path, message }]\n );\n}\n\n/**\n * The frozen fixed-decimal domain the two numbers name: `precision` an integer\n * from 1 to the maximum safe integer, `scale` an integer from 0 to `precision`,\n * so \"at most `precision` total digits and at most `scale` fractional digits\"\n * is a domain with values in it.\n *\n * Its unique coverage is the schema document and an untyped JavaScript caller:\n * `read.ts` hands the numbers over as they were written, so `10.5`, `1e300` and\n * `-0` (which `JSON.parse` keeps and `JSON.stringify` loses) reach this check\n * and nothing earlier. The argument is `unknown` because the document seam\n * passes it untyped; it is read as an ordinary object, not a hostile one.\n * Whether a given PROVIDER can store the domain is a different question with a\n * different owner: the adapter answers it once when the schema is bound.\n */\nexport function readDecimalDescriptor(source: unknown): DecimalDescriptor {\n const precision = isRecord(source) ? source.precision : undefined;\n const scale = isRecord(source) ? source.scale : undefined;\n if (\n !(\n typeof precision === \"number\" &&\n Number.isSafeInteger(precision) &&\n precision >= 1\n )\n ) {\n refuse(\n \"descriptor.precision\",\n \"'precision' must be an integer between 1 and the maximum safe integer\"\n );\n }\n if (\n !(\n typeof scale === \"number\" &&\n Number.isSafeInteger(scale) &&\n scale >= 0 &&\n scale <= precision &&\n !Object.is(scale, -0)\n )\n ) {\n refuse(\n \"descriptor.scale\",\n \"'scale' must be an integer between 0 and precision\"\n );\n }\n return Object.freeze({ precision, scale });\n}\n\n/**\n * A fixed-decimal LIST is not a key, and this is where a chain that tries to\n * make one into a key stops (plan 2.1).\n *\n * Both directions are refused because the chain has two of them:\n * `.array().id()` names a list and then a key, `.id().array()` names a key and\n * then a list, and only refusing the one that comes second would leave the\n * other spelling admitted. The exclusion is the DECLARATION's, not the\n * database's: a decimal list is stored as one container value on two of three\n * providers, so a key over it would be a key over a JSON document whose\n * identity is its spelling rather than its members — and there is no member\n * arrangement that could make it addressable.\n *\n * The whole-schema rule F007 (\"an ID cannot be an array\") is untouched and\n * still owns every OTHER scalar type. This refuses earlier, at the call that\n * writes the illegal chain, and it also owns `.unique()`, which no rule in the\n * repository refuses on a list of any type.\n */\nexport function refuseDecimalListKey(\n position: \"id\" | \"unique\" | \"array\"\n): never {\n const explanation =\n \"a fixed-decimal list cannot be an ID, a unique field, an index member, a foreign-key member, or a relation identity member\";\n refuse(\n position,\n position === \"array\"\n ? `A decimal key cannot become a list: ${explanation}`\n : `A decimal list cannot be declared '.${position}()': ${explanation}`\n );\n}\n\n/**\n * A literal default, normalized through the field's complete current schema at\n * DEFINITION time, so model metadata holds the canonical logical value the DDL\n * renderer, the schema-document serializer and the create schema's trusted\n * default all read. A value outside the declared domain fails at the call that\n * wrote it, not at the first write.\n *\n * A function default keeps its closure, exactly as every other scalar's does:\n * a closure has no canonical spelling to retain, and the create schema runs the\n * field codec on each value it returns.\n */\nexport function normalizeDecimalDefault(\n value: unknown,\n schema: StandardSchemaV1<unknown, unknown>\n): unknown {\n if (typeof value === \"function\") return value;\n const result = validateSchema(schema, value);\n if (result.issues !== undefined) {\n refuse(\"default\", \"The decimal default did not satisfy its field schema\");\n }\n return result.value;\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { DecimalDescriptor } from \"@validation/primitives/decimal-codec\";\nimport type { Decimal } from \"@validation/primitives/decimal-value\";\nimport v from \"@validation/primitives/v\";\nimport type { VibSchema } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n type UpdateState,\n untypedKeyedScalarChain,\n updateState,\n} from \"../common\";\nimport {\n normalizeDecimalDefault,\n readDecimalDescriptor,\n refuseDecimalListKey,\n} from \"./descriptor\";\n\n/**\n * The shared L1 descriptor supplies the two required keys. This intersection\n * makes that surface exact for held objects too, without declaring a second L2\n * precision/scale bag.\n */\ntype KeysOfUnion<Given> = Given extends unknown ? keyof Given : never;\n\ntype ExactDomain<Given> = Given &\n Record<Exclude<KeysOfUnion<Given>, keyof DecimalDescriptor>, never>;\n\n/**\n * The type-level half of plan 2.1's list exclusion.\n *\n * A key position is refused by making the RECEIVER unassignable, which is what\n * lets the diagnostic carry the reason: TypeScript reports the missing property\n * by name, so `s.decimal({...}).array().id()` reads as \"a fixed-decimal list\n * cannot be a key\" rather than as an arity or an argument error. The scalar's\n * own type is intersected in, so inside the method body `this` is the scalar it\n * has always been and no assertion is needed to reach its state.\n *\n * `unknown` on the legal side is inert: intersecting it changes nothing, so a\n * non-list decimal keeps exactly the chain it had, and a scalar whose arity is\n * still the unresolved `boolean` is admitted — only a declared list is refused.\n */\ninterface DecimalListKeyRefusal {\n readonly \"a fixed-decimal list cannot be a key\": never;\n}\n\ntype NotAList<State extends ScalarState<\"decimal\">> =\n State[\"array\"] extends true ? DecimalListKeyRefusal : unknown;\n\ntype NotAKey<State extends ScalarState<\"decimal\">> = State[\"isId\"] extends true\n ? DecimalListKeyRefusal\n : State[\"isUnique\"] extends true\n ? DecimalListKeyRefusal\n : unknown;\n\ntype DecimalScalarState<State extends ScalarState<\"decimal\">> = State & {\n readonly decimal: DecimalDescriptor;\n};\n\nexport class DecimalScalar<\n out State extends ScalarState<\"decimal\">,\n> extends untypedKeyedScalarChain<DecimalScalarState<State>> {\n private declare readonly state: DecimalScalarState<State>;\n\n protected rebase(state: DecimalScalarState<State>): VibSchema {\n return v.decimal({\n nullable: state.nullable,\n array: state.array,\n decimal: state.decimal,\n schema: state.schema,\n });\n }\n\n /**\n * A literal default follows the base it was normalized through: a modifier\n * that rebuilds the base normalizes the default again, through the new one.\n */\n private again<Next extends { \"~\": { state: ScalarState } }>(next: Next) {\n if (this.state.hasDefault && typeof this.state.default !== \"function\") {\n next[\"~\"].state.default = normalizeDecimalDefault(\n this.state.default,\n next[\"~\"].state.base\n );\n }\n return next;\n }\n\n override nullable() {\n return super.nullable() as DecimalScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends false\n ? null\n : State[\"default\"];\n readonly optional: true;\n readonly base: ReturnType<\n typeof v.decimal<{\n nullable: true;\n array: State[\"array\"];\n decimal: DecimalDescriptor;\n schema: State[\"schema\"];\n }>\n >;\n }\n >\n >;\n }\n\n override array(this: DecimalScalar<State> & NotAKey<State>) {\n if (this.state.isId || this.state.isUnique) refuseDecimalListKey(\"array\");\n return this.again(\n super.array() as DecimalScalar<\n UpdateState<\n DecimalScalarState<State>,\n {\n readonly array: true;\n readonly base: ReturnType<\n typeof v.decimal<{\n nullable: State[\"nullable\"];\n array: true;\n decimal: DecimalDescriptor;\n schema: State[\"schema\"];\n }>\n >;\n }\n >\n >\n );\n }\n\n override id(this: DecimalScalar<State> & NotAList<State>) {\n if (this.state.array) refuseDecimalListKey(\"id\");\n return super.id() as DecimalScalar<\n UpdateState<\n DecimalScalarState<State>,\n { readonly isId: true; readonly isUnique: true }\n >\n >;\n }\n\n override unique(this: DecimalScalar<State> & NotAList<State>) {\n if (this.state.array) refuseDecimalListKey(\"unique\");\n return super.unique() as DecimalScalar<\n UpdateState<DecimalScalarState<State>, { readonly isUnique: true }>\n >;\n }\n\n /**\n * A literal default is normalized through the field codec HERE, at\n * definition time, so model metadata retains the canonical logical value and\n * a schema document round-trips to the same declaration. A value outside the\n * declared domain fails at the call that wrote it, not at the first write.\n */\n override default<V extends DefaultValueInput<State>>(value: V) {\n return withValidatedDecimalDefault(\n this,\n normalizeDecimalDefault(value, this.state.base)\n );\n }\n\n /**\n * Refine or brand the exact value. The schema observes a `Decimal` — the\n * public value type — and the declared domain validates whatever it returns\n * LAST, so a custom schema can narrow the domain but never escape it, and it\n * cannot change the value family the field reads back as.\n */\n override schema<S extends StandardSchemaV1<Decimal>>(schema: S) {\n return this.again(\n super.schema(schema) as DecimalScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly schema: S;\n readonly base: ReturnType<\n typeof v.decimal<{\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n decimal: DecimalDescriptor;\n schema: S;\n }>\n >;\n }\n >\n >\n );\n }\n\n override map(columnName: string) {\n return super.map(columnName) as DecimalScalar<\n UpdateState<this[\"~\"][\"state\"], { readonly columnName: string }>\n >;\n }\n\n get [\"~\"](): {\n state: DecimalScalarState<State>;\n nativeType?: undefined;\n } {\n return { state: this.state };\n }\n}\n\n/**\n * Store the canonical verdict of the field's current base schema.\n *\n * This is an internal schema-document seam, deliberately absent from the\n * public decimal barrel. The document interpreter already has to validate a\n * decoded default to own its J008 diagnostic; feeding that verdict back\n * through `.default()` would run the same field codec a second time.\n */\nexport function withValidatedDecimalDefault<\n State extends ScalarState<\"decimal\">,\n>(scalar: DecimalScalar<State>, value: unknown) {\n return new DecimalScalar(\n updateState(scalar, {\n hasDefault: true,\n default: value,\n optional: true,\n })\n );\n}\n\n/**\n * The one public decimal factory.\n *\n * `precision` is the maximum total digit count and `scale` the maximum\n * fractional digit count; values are multiples of `10^-scale`, and an input\n * that does not fit is refused rather than silently rounded. There is no\n * zero-argument form, no native-type override, and no second \"fixed decimal\"\n * factory: portable exact decimal arithmetic needs these two numbers, and\n * SQLite cannot supply them from storage, so they are declared once here.\n */\nexport const buildDecimalScalar = (descriptor: unknown) => {\n const domain = readDecimalDescriptor(descriptor);\n return new DecimalScalar({\n ...createDefaultState(\n \"decimal\",\n v.decimal<{ decimal: DecimalDescriptor }>({ decimal: domain })\n ),\n decimal: domain,\n });\n};\n\n/** The exact public argument surface over the untyped construction seam. */\nexport const decimal = <const D>(\n descriptor: D & NoInfer<DecimalDescriptor & ExactDomain<D>>\n) => buildDecimalScalar(descriptor);\n","// Enum Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; an enum keeps them as methods, typed on its own values\n\nimport type { EnumSchema } from \"@validation/primitives/enum\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput, VibSchema } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n type UpdateState,\n untypedListScalarChain,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\n/**\n * The values of an enum in this state. A state that names no values (the wide\n * one a model's fields are read through) has some strings, not none: a precise\n * enum is then an enum of the wide kind member by member.\n */\ntype Values<State extends ScalarState<\"enum\">> =\n State[\"base\"] extends EnumSchema<infer T, any, any> ? T : readonly string[];\n\nexport class EnumScalar<\n out State extends ScalarState<\"enum\">,\n> extends untypedListScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n\n get enumValues() {\n return (\n \"values\" in this.state.base ? this.state.base.values : []\n ) as Values<State>;\n }\n\n protected rebase(state: State): VibSchema {\n return v.enum(this.enumValues, {\n nullable: state.nullable,\n array: state.array,\n });\n }\n\n override nullable() {\n return super.nullable() as EnumScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends false\n ? null\n : State[\"default\"];\n readonly optional: true;\n readonly base: EnumSchema<\n Values<State>,\n ComputeInput<\n Values<State>[number],\n { nullable: true; array: State[\"array\"] }\n >,\n ComputeOutput<\n Values<State>[number],\n { nullable: true; array: State[\"array\"] }\n >\n >;\n }\n >\n >;\n }\n\n override array() {\n return super.array() as EnumScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly array: true;\n readonly base: EnumSchema<\n Values<State>,\n ComputeInput<\n Values<State>[number],\n { nullable: State[\"nullable\"]; array: true }\n >,\n ComputeOutput<\n Values<State>[number],\n { nullable: State[\"nullable\"]; array: true }\n >\n >;\n }\n >\n >;\n }\n\n override default<V extends DefaultValueInput<State>>(value: V) {\n return super.default(value) as EnumScalar<\n UpdateState<\n this[\"~\"][\"state\"],\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n }\n\n override map(columnName: string) {\n return super.map(columnName) as EnumScalar<\n UpdateState<this[\"~\"][\"state\"], { readonly columnName: string }>\n >;\n }\n\n /**\n * Set a custom name for the enum type in the database.\n * This allows reusing the same enum across multiple tables.\n *\n * @example\n * ```ts\n * const Status = s.enum([\"PENDING\", \"ACTIVE\"]).name(\"status\");\n *\n * const user = s.model({ status: Status });\n * const order = s.model({ status: Status }); // Same \"status\" enum type\n * ```\n */\n name(enumName: string) {\n return new EnumScalar(\n { ...this.state, enumName } as UpdateState<\n State,\n { readonly enumName: string }\n >,\n this._nativeType\n );\n }\n\n get [\"~\"]() {\n return {\n state: this.state,\n nativeType: this._nativeType,\n };\n }\n}\n\nexport const enumScalar = <\n // A readonly tuple is admitted; see `enum_` for the mutable arm.\n const T extends string[] | readonly string[],\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n values: T,\n nativeType?: NativeTypeArgument<Db, Given>\n) => {\n return new EnumScalar(\n createDefaultState(\"enum\", v.enum(values)),\n admitNativeType(\"s.enum\", nativeType)\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { IntegerSchema } from \"@validation/primitives/number\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n keyedScalarChain,\n type ScalarState,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst intBase = v.integer();\n\nexport class IntScalar<\n State extends ScalarState<\"int\">,\n> extends keyedScalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => IntScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: IntegerSchema<\n ComputeInput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => IntScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: IntegerSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => IntScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => IntScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => IntScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<number>>(\n schema: S\n ) => IntScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: IntegerSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => IntScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.integer({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n\n increment() {\n return new IntScalar(\n updateState(this, {\n hasDefault: true,\n autoGenerate: { kind: \"increment\" },\n default: undefined,\n disallowZero: true,\n optional: true,\n }),\n this._nativeType\n );\n }\n}\n\nexport const int = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new IntScalar(\n createDefaultState(\"int\", intBase),\n admitNativeType(\"s.int\", nativeType)\n );\n","import { ValidationError } from \"@errors\";\nimport {\n JsonNull,\n type JsonNullSentinel,\n jsonNullKindOf,\n} from \"@schema/json-null\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonValue } from \"@validation\";\nimport type { JsonInput, JsonSchema } from \"@validation/primitives/json\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValue,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst jsonBase = v.json();\n\nexport class JsonScalar<\n State extends ScalarState<\"json\"> = ScalarState<\"json\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => JsonScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: JsonSchema<\n ComputeInput<\n JsonInput,\n {\n nullable: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n JsonValue,\n {\n nullable: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => JsonScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.json({\n nullable: state.nullable,\n schema: state.schema,\n });\n }\n\n default<\n V extends\n | DefaultValueInput<State>\n | DefaultValue<\n JsonNullSentinel<\n State[\"nullable\"] extends true ? \"JsonNull\" | \"DbNull\" : \"JsonNull\"\n >\n >,\n >(value: V) {\n const kind = jsonNullKindOf(value);\n if (kind === \"AnyNull\" || (kind === \"DbNull\" && !this.state.nullable)) {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.json\", path: \"default\" },\n [\n {\n path: \"default\",\n message: \"JSON default must name a null this column can store\",\n },\n ]\n );\n }\n const defaultValue =\n value === null && !this.state.nullable ? JsonNull : value;\n return new JsonScalar(\n updateState(this, {\n hasDefault: true,\n default: defaultValue,\n optional: true,\n }),\n this._nativeType\n );\n }\n\n schema<S extends StandardSchemaV1<JsonInput, JsonValue>>(schema: S) {\n return new JsonScalar(\n updateState(this, {\n schema,\n base: v.json<{\n nullable: State[\"nullable\"];\n schema: S;\n }>({\n nullable: this.state.nullable,\n schema,\n }),\n }),\n this._nativeType\n );\n }\n}\n\nexport const json = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new JsonScalar(\n createDefaultState(\"json\", jsonBase),\n admitNativeType(\"s.json\", nativeType)\n );\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { NumberSchema } from \"@validation/primitives/number\";\nimport v from \"@validation/primitives/v\";\nimport type { ComputeInput, ComputeOutput } from \"@validation/types\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n keyedScalarChain,\n type ScalarState,\n type UpdateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst numberBase = v.number();\n\nexport class NumberScalar<\n State extends ScalarState<\"number\">,\n> extends keyedScalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: NumberSchema<\n ComputeInput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: true;\n array: State[\"array\"];\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly array: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly array: true;\n readonly base: NumberSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: true;\n schema: State[\"schema\"];\n }\n >\n >;\n }\n >\n >;\n declare readonly id: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly isId: true;\n readonly isUnique: true;\n }\n >\n >;\n declare readonly unique: () => NumberScalar<\n UpdateState<\n State,\n {\n readonly isUnique: true;\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => NumberScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n declare readonly schema: <S extends StandardSchemaV1<number>>(\n schema: S\n ) => NumberScalar<\n UpdateState<\n State,\n {\n readonly schema: S;\n readonly base: NumberSchema<\n ComputeInput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >,\n ComputeOutput<\n number,\n {\n nullable: State[\"nullable\"];\n array: State[\"array\"];\n schema: S;\n }\n >\n >;\n }\n >\n >;\n declare readonly map: (columnName: string) => NumberScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.number({\n nullable: state.nullable,\n array: state.array,\n schema: state.schema,\n });\n }\n}\n\nexport const number = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new NumberScalar(\n createDefaultState(\"number\", numberBase),\n admitNativeType(\"s.number\", nativeType)\n );\n","import { ValidationError } from \"@errors\";\nimport type { GeoPoint } from \"@validation/primitives/geo-point-codec\";\nimport { validateSchema } from \"@validation/primitives/helpers\";\nimport type { PointSchema } from \"@validation/primitives/point\";\nimport v from \"@validation/primitives/v\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n updateState,\n} from \"../common\";\n\nconst pointBase = v.point();\n\nexport class PointScalar<\n State extends ScalarState<\"point\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n declare readonly nullable: () => PointScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: PointSchema<GeoPoint | null, GeoPoint | null>;\n }\n >\n >;\n declare readonly map: (columnName: string) => PointScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n\n protected rebase(state: State) {\n return v.point({\n nullable: state.nullable,\n });\n }\n\n // biome-ignore lint/complexity/noUselessConstructor: a point has no native type, so its constructor takes none\n constructor(state: State) {\n super(state);\n }\n\n default<V extends DefaultValueInput<State>>(value: V) {\n return new PointScalar(\n updateState(this, {\n hasDefault: true,\n default: normalizePointDefault(value, this.state.base),\n optional: true,\n })\n );\n }\n\n get [\"~\"](): { state: State; nativeType?: undefined } {\n return { state: this.state };\n }\n}\n\nfunction normalizePointDefault(value: unknown, schema: StateSchema): unknown {\n if (typeof value === \"function\") return value;\n const result = validateSchema(schema, value);\n if (!result.issues) return result.value;\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.point\", path: \"default\" },\n result.issues.map((issue) => ({\n path: issue.path?.join(\".\") ?? \"default\",\n message: issue.message,\n }))\n );\n}\n\ntype StateSchema = ScalarState<\"point\">[\"base\"];\n\n/** The one public GeoPoint scalar factory; EPSG:4326 is not configurable. */\nexport function point(...args: []) {\n if (args.length !== 0) {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.point\", path: \"arguments\" },\n [\n {\n path: \"arguments\",\n message: \"s.point() takes no native type or options\",\n },\n ]\n );\n }\n return new PointScalar(createDefaultState(\"point\", pointBase));\n}\n","// Vector Scalar\n// The modifiers every scalar shares are implemented once, in the chain this\n// class extends; the class types them for this scalar's own state\n\nimport { ValidationError } from \"@errors\";\nimport v from \"@validation/primitives/v\";\nimport type { VectorSchema } from \"@validation/primitives/vector\";\nimport {\n createDefaultState,\n type DefaultValueInput,\n type ScalarState,\n scalarChain,\n type UpdateState,\n updateState,\n} from \"../common\";\nimport { admitNativeType } from \"../native-catalog\";\nimport type {\n ExactNativeTypeMap,\n NativeDialect,\n NativeTypeArgument,\n NativeTypeDeclaration,\n} from \"../native-types\";\n\nconst vectorBase = v.vector();\n\nexport class VectorScalar<\n State extends ScalarState<\"vector\">,\n> extends scalarChain<State> {\n private declare readonly state: State;\n private declare readonly _nativeType: NativeTypeDeclaration | undefined;\n declare readonly nullable: () => VectorScalar<\n UpdateState<\n State,\n {\n readonly nullable: true;\n readonly hasDefault: true;\n readonly default: State[\"hasDefault\"] extends true\n ? State[\"default\"]\n : null;\n readonly optional: true;\n readonly base: VectorSchema<number[] | null, number[] | null> & {\n dimensions?: number;\n };\n }\n >\n >;\n declare readonly default: <V extends DefaultValueInput<State>>(\n value: V\n ) => VectorScalar<\n UpdateState<\n State,\n {\n readonly hasDefault: true;\n readonly default: V;\n readonly optional: true;\n }\n >\n >;\n /**\n * Maps this scalar to a custom column name in the database\n */\n declare readonly map: (columnName: string) => VectorScalar<\n UpdateState<\n State,\n {\n readonly columnName: string;\n }\n >\n >;\n declare readonly [\"~\"]: {\n state: State;\n nativeType: NativeTypeDeclaration | undefined;\n };\n\n protected rebase(state: State) {\n return v.vector(state.dimension, {\n nullable: state.nullable,\n });\n }\n\n dimension(dim: number) {\n if (!Number.isSafeInteger(dim) || dim <= 0) {\n throw new ValidationError(\n { kind: \"schema-builder\", builder: \"s.vector\", path: \"dimension\" },\n [\n {\n path: \"dimension\",\n message: \"Vector dimension must be a positive safe integer\",\n },\n ]\n );\n }\n return new VectorScalar(\n updateState(this, {\n dimension: dim,\n base: v.vector(dim, { nullable: this.state.nullable }),\n }),\n this._nativeType\n );\n }\n}\n\nexport const vector = <\n Db extends NativeDialect = never,\n const Given extends ExactNativeTypeMap<Given> = never,\n>(\n nativeType?: NativeTypeArgument<Db, Given>\n) =>\n new VectorScalar(\n createDefaultState(\"vector\", vectorBase),\n admitNativeType(\"s.vector\", nativeType)\n );\n","// `s.toMany` — the other of the two relation factories.\n//\n// The factory states the SLOT CARDINALITY (many) and its argument states the\n// TARGET DOMAIN. A model-target collection is junction-capable and an empty\n// collection is `[]`, so there is no `.optional()` here and no `.unique()`\n// anywhere: the paired slot cardinality owns remote uniqueness.\n\nimport {\n type ExactVariantOptions,\n type NormalizedManyEntries,\n normalizeVariantEntries,\n type VariantGetterMap,\n type VariantMapGuard,\n type VariantOptions,\n type VariantToManyRelation,\n variantToManyTerminal,\n} from \"./polymorphic\";\nimport {\n createTargetSettlement,\n normalizeJunctionActions,\n normalizeJunctionToken,\n normalizeRelationName,\n refuseRelationInput,\n} from \"./terminal\";\nimport type {\n AnyRelation,\n Getter,\n GetterOnly,\n JunctionReferentialAction,\n JunctionSideActions,\n ModelToManyState,\n OrdinaryJunctionOverrides,\n RelationInternal,\n Replace,\n} from \"./types\";\n\n// =============================================================================\n// TERMINAL CAPABILITY SURFACE\n// =============================================================================\n\n/** A junction action: the symmetric shorthand, or one action per side. */\nexport type JunctionActionDeclaration =\n | JunctionReferentialAction\n | JunctionSideActions;\n\n/** Every key any map member of `Action` declares; a bare action declares none. */\ntype DeclaredMapKeys<Action> = Action extends JunctionReferentialAction\n ? never\n : keyof Action;\n\n/**\n * `{ source, target }` is exact: a key beside the two sides is refused\n * structurally, so a map held in a variable cannot carry one past\n * excess-property checking either. The keys are gathered across a union\n * before the check, so one clean member cannot vouch for another that carries\n * an extra key.\n */\nexport type ExactJunctionActions<Action> = Record<\n Exclude<DeclaredMapKeys<Action>, keyof JunctionSideActions>,\n never\n>;\n\n/**\n * `.source()` / `.target()` after a declared model's `.through()` names one of\n * its relations, which is what `$through` keeps a link's own columns apart by.\n * On any other junction a token is only a name and the state stays as it was.\n */\ntype WithJunctionSide<State, Side extends string, Token> = State extends {\n readonly junction: { readonly model: unknown };\n}\n ? Replace<\n State,\n { readonly junction: State[\"junction\"] & { readonly [K in Side]: Token } }\n >\n : State;\n\n/**\n * A model-target collection slot.\n *\n * The junction overrides are independent, meaningful facts rather than stages of\n * one all-or-nothing value, so any subset may override its canonical default.\n * Exactly one endpoint owns all supplied overrides; the other endpoint supplies\n * none and consumes the mirrored resolved view. Whether these overrides belong\n * on the resolved physical owner is one full-schema topology rule, not a second\n * type-level guess — which is why they are offered before the inverse graph\n * exists and why the state does not carry them as a public type parameter.\n */\nexport type ModelToManyRelation<State> = {\n readonly \"~\": RelationInternal<State>;\n name<const Name extends string>(\n name: Name\n ): ModelToManyRelation<Replace<State, { readonly name: Name }>>;\n through(table: string): ModelToManyRelation<State>;\n /**\n * A declared model as the junction: its table, columns and delegate stay its\n * own and `.source()` / `.target()` name its to-one relations. The getter is\n * kept as a target's is and read only where a query asks for `$through`: the\n * junction model's relations point back here, so `.source()` naming them in\n * its own signature would resolve a circular const.\n */\n through<const G>(\n model: G & GetterOnly<G>\n ): ModelToManyRelation<\n Replace<State, { readonly junction: { readonly model: G } }>\n >;\n source<const Token extends string>(\n token: Token\n ): ModelToManyRelation<WithJunctionSide<State, \"source\", Token>>;\n target<const Token extends string>(\n token: Token\n ): ModelToManyRelation<WithJunctionSide<State, \"target\", Token>>;\n onDelete<const Action extends JunctionActionDeclaration>(\n action: Action & ExactJunctionActions<Action>\n ): ModelToManyRelation<State>;\n onUpdate<const Action extends JunctionActionDeclaration>(\n action: Action & ExactJunctionActions<Action>\n ): ModelToManyRelation<State>;\n};\n\n// =============================================================================\n// PRIVATE TERMINAL\n// =============================================================================\n\nclass ModelToMany {\n readonly #state: ModelToManyState;\n readonly #internal: RelationInternal<ModelToManyState>;\n\n constructor(state: ModelToManyState) {\n this.#state = Object.freeze(state);\n this.#internal = Object.freeze({\n state: this.#state,\n settleTarget: createTargetSettlement(() => this.#state.target.getter),\n settleJunctionModel: createTargetSettlement(\n () => this.#state.junction?.model\n ),\n });\n }\n\n name(name: string): ModelToMany {\n return new ModelToMany({\n ...this.#state,\n name: normalizeRelationName(\"s.toMany\", name),\n });\n }\n\n through(junction: unknown): ModelToMany {\n const { table, model, ...overrides } = this.#state.junction ?? {};\n return this.#withJunction(\n typeof junction === \"function\"\n ? { ...overrides, model: junction as () => any }\n : {\n ...overrides,\n table: normalizeJunctionToken(\"through\", junction),\n }\n );\n }\n\n source(token: string): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n source: normalizeJunctionToken(\"source\", token),\n });\n }\n\n target(token: string): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n target: normalizeJunctionToken(\"target\", token),\n });\n }\n\n onDelete(action: JunctionActionDeclaration): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n onDelete: normalizeJunctionActions(\"onDelete\", action),\n });\n }\n\n onUpdate(action: JunctionActionDeclaration): ModelToMany {\n return this.#withJunction({\n ...this.#state.junction,\n onUpdate: normalizeJunctionActions(\"onUpdate\", action),\n });\n }\n\n #withJunction(junction: OrdinaryJunctionOverrides): ModelToMany {\n return new ModelToMany({\n ...this.#state,\n junction: Object.freeze(junction),\n });\n }\n\n get \"~\"(): RelationInternal<ModelToManyState> {\n return this.#internal;\n }\n}\n\n// =============================================================================\n// FACTORY\n// =============================================================================\n\n/**\n * Declare a slot that holds a COLLECTION.\n *\n * The map overload is declared first so a variant map is never swallowed by the\n * broad getter overload. Dispatch examines only the argument representation and\n * never invokes a getter.\n */\nexport function toMany<\n const Entries extends VariantGetterMap,\n const Options extends VariantOptions<Entries> | undefined = undefined,\n>(\n variants: Entries & VariantMapGuard<Entries>,\n options?: Options & ExactVariantOptions<Options, Entries>\n): VariantToManyRelation<{\n readonly kind: \"relation\";\n readonly cardinality: \"many\";\n readonly target: {\n readonly kind: \"variants\";\n readonly entries: NormalizedManyEntries<Entries>;\n };\n}>;\nexport function toMany<const G>(getter: G & GetterOnly<G>): G extends Getter\n ? ModelToManyRelation<{\n readonly kind: \"relation\";\n readonly cardinality: \"many\";\n readonly target: { readonly kind: \"model\"; readonly getter: G };\n }>\n : never;\nexport function toMany(target: unknown, options?: unknown): AnyRelation {\n if (typeof target === \"function\") {\n // biome-ignore lint/complexity/noArguments: distinguishes omission from explicit undefined without changing the factory's public arity\n if (arguments.length > 1) {\n refuseRelationInput(\n \"s.toMany\",\n \"options\",\n \"A model-target relation takes exactly one argument\"\n );\n }\n return new ModelToMany({\n kind: \"relation\",\n cardinality: \"many\",\n target: { kind: \"model\", getter: target },\n });\n }\n return variantToManyTerminal({\n kind: \"relation\",\n cardinality: \"many\",\n target: {\n kind: \"variants\",\n entries: normalizeVariantEntries(\"s.toMany\", target, options),\n },\n });\n}\n"],"mappings":"qZAwBA,MAAM,EAAaA,EAAE,QAAQ,CAE7B,IAAa,EAAb,MAAa,qBAEH,CAAwB,CAkIhC,OAAiB,EAAc,CAC7B,OAAOA,EAAE,OAAO,CACd,SAAU,EAAM,SAChB,MAAO,EAAM,MACb,OAAQ,EAAM,OACf,CAAC,CAGJ,WAAY,CACV,OAAO,IAAI,aACT,EAAY,KAAM,CAChB,WAAY,GACZ,aAAc,CAAE,KAAM,YAAa,CACnC,QAAS,IAAA,GACT,aAAc,GACd,SAAU,GACX,CAAC,CACF,KAAK,YACN,GAIL,MAAa,OAIX,GAEA,IAAI,EACF,EAAmB,SAAU,EAAW,CACxC,EAAgB,WAAY,EAAW,CACxC,CCxKG,EAAWC,EAAE,MAAM,CAEzB,IAAa,WAAb,cAEU,CAAmB,CA+C3B,OAAiB,EAAc,CAC7B,OAAOA,EAAE,KAAK,CACZ,SAAU,EAAM,SACjB,CAAC,CAIJ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AAU,EAAM,CAChD,CAAC,CAGJ,SAAS,EAAgD,CACvD,OAAO,MAAA,EAAmB,CACxB,GAAG,MAAA,EAAY,SACf,SAAU,EAAyB,WAAY,EAAO,CACvD,CAAC,CAGJ,SAAS,EAAgD,CACvD,OAAO,MAAA,EAAmB,CACxB,GAAG,MAAA,EAAY,SACf,SAAU,EAAyB,WAAY,EAAO,CACvD,CAAC,CAGJ,GAAc,EAAkD,CAC9D,OAAO,IAAI,YAAY,CACrB,GAAG,MAAA,EACH,SAAU,OAAO,OAAO,EAAS,CAClC,CAAC,CAGJ,GAAI,KAA0C,CAC5C,OAAO,MAAA,IAoCX,SAAgB,OAAO,EAAiB,EAAgC,CAgBtE,OAfI,OAAO,GAAW,YAEhB,UAAU,OAAS,GACrB,EACE,WACA,UACA,qDACD,CAEI,IAAI,EAAY,CACrB,KAAM,WACN,YAAa,OACb,OAAQ,CAAE,KAAM,QAAS,OAAQ,EAAQ,CAC1C,CAAC,EAEG,EAAsB,CAC3B,KAAM,WACN,YAAa,OACb,OAAQ,CACN,KAAM,WACN,QAAS,EAAwB,WAAY,EAAQ,EAAQ,CAC9D,CACF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{g as t,x as n}from"./base-z-cH5ZBI.mjs";import{m as r,p as i}from"./unit-words-
|
|
2
|
-
//# sourceMappingURL=unit-
|
|
1
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{g as t,x as n}from"./base-z-cH5ZBI.mjs";import{m as r,p as i}from"./unit-words-BGMVZ1MX.mjs";function disclosed(e,r={}){return t(n(e)?e:Error(`A non-Error value failed.`),{includeSql:r.sql===!0,includeParams:r.parameters===!0})}function disclosure(e){let t={includeSql:e.sql===!0,includeParams:e.parameters===!0,includeProviderDetails:e.providerDetails===!0,includeCallsite:e.callsite===!0};return{join({next:e}){e.disclosure=t}}}function rewritePart(e){return{join({next:t,owner:n}){t.rewrites=i([...t.rewrites?.handlers??[],{extension:n.name,handler:e}])}}}function unit(e,t,n){return n?.rewrites===!0?rewritePart(e):r(e,t)}export{disclosure as n,disclosed as r,unit as t};
|
|
2
|
+
//# sourceMappingURL=unit-CSaAB0su.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit-
|
|
1
|
+
{"version":3,"file":"unit-CSaAB0su.mjs","names":["disclosed"],"sources":["../src/extensions/disclosed.ts","../src/extensions/disclosure.ts","../src/extensions/statement.ts","../src/extensions/unit.ts"],"sourcesContent":["/**\n * `disclosed(error, { sql?, parameters? })`: what a log or a span may show of\n * a failure. A `unit` handler that presents `failure(u)`, or an error another\n * extension noted, presents this copy, never the error itself: the error may\n * carry a provider's message, its stack, statement text or parameter values\n * the application's `disclosure` hides, and it may be any value at all.\n */\nimport { sanitizeErrorForLogging } from \"@errors\";\nimport { isError } from \"../errors/diagnostic-safety\";\nimport type { DisclosurePolicy } from \"./disclosure\";\n\n/**\n * A new `Error`, safe to log or to put on a span, made from `error`.\n *\n * Of an error the package made (a `VibORMError`: every error the library\n * throws), it keeps what the package recorded when it built the error: its\n * `name`, `message`, `code`, `prismaCode`, `timestamp`, the `meta` keys the\n * package knows, and its causes. Of any other `Error`, it keeps the name\n * `\"Error\"`, the message `\"Error details redacted\"`, those of its own `code`,\n * `errno`, `sqlState`, `status` and `statusCode` that have the shape of a\n * code (`ECONNRESET`, a SQLSTATE, an HTTP status), and its causes.\n *\n * It removes the stack, always, and every property not named above. A\n * cause's message, `detail` and `hint` (a provider's words) are replaced by\n * `\"Underlying error details redacted\"` unless the application's\n * `disclosure` allowed `providerDetails` when the error was built; then they\n * are kept with the credentials in URLs, `password=…`, `token=…`,\n * `secret=…` and `Bearer …` redacted. A `callsite` is kept only where the\n * application's `disclosure` allowed `callsite`. Statement text (`meta.sql`)\n * is kept only with `allow.sql`, parameter values (`meta.params`) only with\n * `allow.parameters`; what the application's `disclosure` hid is not in the\n * error at all, so `allow` can only hide more.\n *\n * Bounds: a cause seen twice (a cycle) becomes an error `\"[Circular]\"`, a\n * chain deeper than eight causes `\"[Truncated]\"`; a string is cut at 4,096\n * characters, the whole copy at 32,768.\n *\n * A value that is not an `Error` (a string, a plain object, `undefined`)\n * gives `Error: Error details redacted`, and nothing of it but its prototype\n * chain is read.\n *\n * What it reads of an `Error`: its prototype chain (`instanceof`), the\n * package's own record of it, and its own data properties through their\n * descriptors, so a getter on them never runs; `originalCause` and `cause`\n * are read as properties, so a getter there runs, at most once per error of\n * the chain and per call. Each call reads again: call it once per failure\n * and keep the copy. It never throws: what cannot be read is left out.\n */\nexport function disclosed(\n error: unknown,\n allow: Pick<DisclosurePolicy, \"sql\" | \"parameters\"> = {}\n): Error {\n // An error the package did not make shows no message: this one neither.\n const made = isError(error) ? error : new Error(\"A non-Error value failed.\");\n return sanitizeErrorForLogging(made, {\n includeSql: allow.sql === true,\n includeParams: allow.parameters === true,\n });\n}\n","/**\n * `disclosure({ sql?, parameters?, providerDetails?, callsite? })`: what an\n * error thrown by a call of the chain may carry. The core reads the chain's\n * policy where it builds an error, naming no extension; without this part,\n * an error discloses what it does by default.\n */\nimport type { DiagnosticDisclosure } from \"@errors\";\nimport type { ExtensionPart } from \"./chain\";\nimport type { AnyTarget, EmptyFacts, Part } from \"./contract\";\n\n/** What one disclosure part allows, as an error reads it. */\nexport interface DisclosurePolicy {\n readonly sql?: boolean;\n readonly parameters?: boolean;\n readonly providerDetails?: boolean;\n readonly callsite?: boolean;\n}\n\n/** What an error thrown by a call of the chain may carry. */\nexport function disclosure<T extends AnyTarget>(\n policy: DisclosurePolicy\n): Part<T, EmptyFacts>;\nexport function disclosure(policy: DisclosurePolicy): unknown {\n const disclosed: DiagnosticDisclosure = {\n includeSql: policy.sql === true,\n includeParams: policy.parameters === true,\n includeProviderDetails: policy.providerDetails === true,\n includeCallsite: policy.callsite === true,\n };\n const part: ExtensionPart = {\n join({ next }) {\n next.disclosure = disclosed;\n },\n };\n return part;\n}\n","/**\n * The rewriting units of a chain (`unit(fn, kinds, { rewrites: true })`).\n * Each is a unit around one logical statement: `statement(unit)` reads the\n * statement as the earlier rewrites left it, `next(sql)` hands on what is\n * sent (unchanged without an argument), and resolves with how the statement\n * ended. Inside the innermost `next()` the statement is rendered and sent,\n * as its own `statement` unit around the provider call. A chain with one is\n * never served by the cache, and verbatim unsafe raw queries are never\n * rewritten.\n */\nimport type { ExtensionPart } from \"./chain\";\nimport { observationOf } from \"./observation\";\nimport type { UnitHandler } from \"./unit-source\";\n\n/** The part `unit(handler, kinds, { rewrites: true })` builds. */\nexport function rewritePart(handler: UnitHandler): ExtensionPart {\n return {\n join({ next, owner }) {\n next.rewrites = observationOf([\n ...(next.rewrites?.handlers ?? []),\n { extension: owner.name, handler },\n ]);\n },\n };\n}\n","/**\n * `unit((u, next) => …, kinds?, options?)`: a function around each unit of\n * real work (an operation, a statement, a batch, a transaction, a savepoint,\n * a connection, or a unit an extension emits with `work`). Observing is\n * calling `next()` and reading how the unit ended; what the handler throws\n * fails the call. A part declared `{ rewrites: true }` sends another\n * statement: `next(sql)`, once per logical statement, before rendering.\n */\nimport type { Sql } from \"@sql\";\nimport type {\n AnyTarget,\n EmptyFacts,\n Part,\n UnitContext,\n UnitKind,\n UnitOf,\n UnitOutcome,\n} from \"./contract\";\nimport { unitLayerPart } from \"./observation\";\nimport { rewritePart } from \"./statement\";\n\n/** A function around each unit of the kinds named (every kind when absent). */\nexport function unit<\n T extends AnyTarget,\n Rewrites extends true | undefined = undefined,\n>(\n around: (\n unit: UnitOf<Rewrites>,\n next: (sql?: Sql) => Promise<UnitOutcome>\n ) => unknown,\n kinds?: readonly UnitKind[],\n options?: { readonly rewrites?: Rewrites }\n): Part<T, EmptyFacts>;\nexport function unit(\n handler: (unit: UnitContext, next: () => Promise<UnitOutcome>) => unknown,\n kinds?: readonly UnitKind[],\n options?: { readonly rewrites?: true }\n): unknown {\n return options?.rewrites === true\n ? rewritePart(handler)\n : unitLayerPart(handler, kinds);\n}\n"],"mappings":"6IAgDA,SAAgB,UACd,EACA,EAAsD,EAAE,CACjD,CAGP,OAAO,EADM,EAAQ,EAAM,CAAG,EAAY,MAAM,4BAA4B,CACvC,CACnC,WAAY,EAAM,MAAQ,GAC1B,cAAe,EAAM,aAAe,GACrC,CAAC,CCnCJ,SAAgB,WAAW,EAAmC,CAC5D,IAAMA,EAAkC,CACtC,WAAY,EAAO,MAAQ,GAC3B,cAAe,EAAO,aAAe,GACrC,uBAAwB,EAAO,kBAAoB,GACnD,gBAAiB,EAAO,WAAa,GACtC,CAMD,MAL4B,CAC1B,KAAK,CAAE,QAAQ,CACb,EAAK,WAAaA,GAErB,CClBH,SAAgB,YAAY,EAAqC,CAC/D,MAAO,CACL,KAAK,CAAE,OAAM,SAAS,CACpB,EAAK,SAAW,EAAc,CAC5B,GAAI,EAAK,UAAU,UAAY,EAAE,CACjC,CAAE,UAAW,EAAM,KAAM,UAAS,CACnC,CAAC,EAEL,CCUH,SAAgB,KACd,EACA,EACA,EACS,CACT,OAAO,GAAS,WAAa,GACzB,YAAY,EAAQ,CACpB,EAAc,EAAS,EAAM"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{U as t,V as n,g as r,z as i}from"./error-mapping-
|
|
2
|
-
//# sourceMappingURL=unit-words-
|
|
1
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{U as t,V as n,g as r,z as i}from"./error-mapping-DIRlrmDK.mjs";import{p as a}from"./validation--qS7OPmg.mjs";import{t as o}from"./sql-BGjAsoBE.mjs";import{f as s,i as c,m as l,o as u,r as d}from"./coordination-BY6Np3xV.mjs";import{t as f}from"./execution-context-VMQm-9CH.mjs";import{i as p,n as m,t as h}from"./driver-diagnostics-DW9NdckJ.mjs";var ProducedUnit=class{kind;model;operation;#e;constructor(e){this.kind=e.kind,this.model=e.model,this.operation=Object.hasOwn(e,`operation`)?e.operation:e.context?.operation,this.#e=e}static sourceOf(e){return#e in e?e.#e:void 0}};const g=new WeakMap,sourceOf=e=>ProducedUnit.sourceOf(e);function unitOf(e){let t=new ProducedUnit(e);return e.notes??=[],e.kind===`operation`&&e.context!==void 0&&g.set(e.context,e),t}function originOf(e){let t=s(e)?.of?.context;return sourceOf(e)??(t===void 0?g.get(e):g.get(t))}const nothing=()=>void 0;function runUnit(e,t,n,r){let i=unitOf(t),a,startCore=()=>(a??=attempt(()=>n(t.statement)),a),o=t.kind===`transaction`?openTransaction(t,startCore):void 0,enter=n=>{let a=e[n];return a?.kinds?.includes(t.kind)===!1?enter(n+1):a===void 0?(r?.(),o?.enter(),startCore()):around(a,i,t,()=>enter(n+1))},s=enter(0);return o===void 0?s:s.catch(o.fail)}function attempt(e){try{return e()}catch(e){return Promise.reject(e)}}async function around(e,t,n,r){let i,a,next=s=>{if(i!==void 0)return a??=unitError(e,t,`called next() more than once`),Promise.reject(a);let c=Date.now(),l=s!==void 0&&n.statement!==void 0;return l&&!(s instanceof o)?i=Promise.reject(unitError(e,t,`handed next() something not a statement`)):(l&&(n.statement=s),i=r()),i.then(()=>settle(n,c,!1,void 0),e=>settle(n,c,!0,e))},s;try{await e.handler(t,next)}catch(e){s={failure:e}}if(i===void 0)throw s?.failure??unitError(e,t,`settled without calling next()`);let c=await i;if(s!==void 0)throw s.failure;if(a!==void 0)throw a;return c}function settle(e,t,r,i){e.failed=r,e.failure=i,e.settledAt??=Date.now();let a=e.certainty?.();return{status:r?`failure`:`success`,duration:Math.max(0,e.settledAt-t),...a===void 0?{}:{certainty:a},...r&&n(e.context)?{recovered:!0}:{}}}function unitError(e,t,n){return new a(`Extension "${e.extension}" unit() for ${t.kind} ${n}.`,{meta:{method:`unit`,operation:t.operation,model:t.model}})}function openTransaction(e,t){let n,r,i,o,s=!1,c,l,u=new Promise(e=>{l=e}),openedWith=e=>{if(n=e,l?.(e),o!==void 0)return Promise.reject(o.failure);if(!s)return new Promise((e,t)=>{r=e,i=t})};e.opened=openedWith;let runIn=e=>n===void 0?(c??=t(),Promise.race([u,c.then(()=>{throw new a(`run() was called on a transaction that ended.`)})]).then(t=>t(e))):n(e);return e.run=runIn,{enter:()=>{s=!0,r?.()},fail:e=>{if(c===void 0||s)throw e;return o={failure:e},i?.(e),c.catch(nothing).then(()=>{throw e})}}}function observationOf(e){let enter=(t,n)=>{let r,i=new Promise(e=>{r=e}),a=runUnit(e,t,n,r);return a.then(r,r),{done:a,reached:i}},members=async e=>{let t=e.map(e=>e===void 0?void 0:enter(e[0],e[1]));await Promise.all(t.map(e=>e?.reached));let n=Promise.all(t.map(e=>e?.done));return n.catch(()=>void 0),{done:n,units:t}};return{handlers:e,run:(t,n)=>runUnit(e,t,n),members,together:async(e,t,n)=>{let r=[],i,a=new Promise(e=>{i=e}),{done:o,units:s}=await members(e.map((e,t)=>e===void 0?void 0:[e,e=>(r[t]=e,a)])),c=s.findIndex((e,t)=>e!==void 0&&!(t in r));if(c>=0){let e=await s[c]?.done.catch(e=>e);throw i(Promise.reject(e)),await o.catch(()=>void 0),n(c,e)}let l=t(r);i(l),a.catch(()=>void 0);try{let e=await l;return await o,e}finally{await o.catch(()=>void 0)}}}}function unitLayerPart(e,t){return{join({next:n,owner:r}){n.observation=observationOf([...n.observation?.handlers??[],{extension:r.name,handler:e,kinds:t}]),c(n,d,u)}}}function work(e,n,r){let a=l(e),o=originOf(e)?.context??t(e)??(a&&f(n.model??a.extension,n.operation,a.engine.extensionChain)),s=i(o)?.observation,c={kind:n.kind,operation:n.operation,model:n.model,context:o,notes:n.note===void 0?[]:[n.note]};return s===void 0?r(unitOf(c)):s.run(c,()=>r(unitOf(c)))}function readDriverIdentity(e){try{let t=e.adapter.namespace;return Object.freeze({dialect:e.dialect,driverName:e.driverName,...t===void 0?{}:{namespace:t}})}catch{return}}const text=e=>sourceOf(e)?.sql;function shownOf(e,t,n){let r=Reflect.get(e,t);if(Array.isArray(r)&&r!==m)return r;let i=p(n);return Reflect.set(e,t,i),i}function parameters(e){let t=sourceOf(e);return t?.batch===void 0?t?.params===void 0?void 0:shownOf(t,`shown`,t.params):t.batch.map(e=>shownOf(e,h,e.params))}function driver(e){let t=sourceOf(e)?.driver;return t===void 0?void 0:readDriverIdentity(t)}const failure=e=>sourceOf(e)?.failure,correlation=e=>sourceOf(e)?.context?.correlationId,table=e=>sourceOf(e)?.table;function statements(e){return sourceOf(e)?.batch?.map(e=>({sql:e.sql,get parameters(){return shownOf(e,h,e.params)},model:e.context?.model,operation:e.context?.operation,correlation:e.context?.correlationId}))}function origin(e){return r(e)}function statement(e){return sourceOf(e)?.statement}function run(e,t){let n=sourceOf(e)?.run;return n===void 0?Promise.reject(new a(`run() needs the transaction unit a unit() received.`)):n(t)}function note(e,t){let n=originOf(e);return n===void 0||n.failed!==void 0?!1:(n.notes?.push(t),!0)}const notes=e=>sourceOf(e)?.notes??[];export{notes as a,run as c,table as d,text as f,work as h,note as i,statement as l,unitLayerPart as m,driver as n,origin as o,observationOf as p,failure as r,parameters as s,correlation as t,statements as u};
|
|
2
|
+
//# sourceMappingURL=unit-words-BGMVZ1MX.mjs.map
|