@prisma/orm-target-postgres 8.0.0-rc.2-dev.2 → 8.0.0-rc.20
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/README.md +4 -6
- package/dist/adapter-5qylEP__.d.mts +403 -0
- package/dist/adapter-5qylEP__.d.mts.map +1 -0
- package/dist/{adapter-B0xsc80z-sYcF0RVF.mjs → adapter-svGTIjA2-1p-Iw8D2.mjs} +24 -30
- package/dist/adapter-svGTIjA2-1p-Iw8D2.mjs.map +1 -0
- package/dist/adapter.d.mts +11 -13
- package/dist/adapter.mjs +7 -8
- package/dist/adapter__adapter.d.mts +2 -2
- package/dist/adapter__adapter.mjs +3 -2
- package/dist/adapter__column-types.d.mts +2 -2
- package/dist/adapter__column-types.mjs +2 -2
- package/dist/adapter__control.d.mts +4 -5
- package/dist/adapter__control.mjs +11 -423
- package/dist/adapter__control.mjs.map +1 -1
- package/dist/adapter__runtime.d.mts +1 -1
- package/dist/adapter__runtime.mjs +29 -19
- package/dist/adapter__runtime.mjs.map +1 -1
- package/dist/adapter__sql-renderer.d.mts +1 -1
- package/dist/adapter__sql-renderer.mjs +1 -1
- package/dist/adapter__types.d.mts +4 -3
- package/dist/aggregates-CEqqEg8k.d.mts +318 -0
- package/dist/aggregates-CEqqEg8k.d.mts.map +1 -0
- package/dist/{aggregates-Dh6HPdvC.mjs → aggregates-Dw-lAutX.mjs} +105 -40
- package/dist/aggregates-Dw-lAutX.mjs.map +1 -0
- package/dist/authoring-DWd5pnnV-BBX7P1wT.d.mts +52 -0
- package/dist/authoring-DWd5pnnV-BBX7P1wT.d.mts.map +1 -0
- package/dist/authoring-SbdvmVJh-nQ7YliD_.mjs +1342 -0
- package/dist/authoring-SbdvmVJh-nQ7YliD_.mjs.map +1 -0
- package/dist/autoincrement-widths-DonNJgfS-CCvZ4u1W.mjs +58 -0
- package/dist/autoincrement-widths-DonNJgfS-CCvZ4u1W.mjs.map +1 -0
- package/dist/{canonicalize-CQlxSR4D-MnrT5gtW.d.mts → canonicalize-B-xvDOdd-G3yUeKj4.d.mts} +7 -3
- package/dist/canonicalize-B-xvDOdd-G3yUeKj4.d.mts.map +1 -0
- package/dist/{canonicalize-CrN3u_xM-D4MrOqcB.mjs → canonicalize-RdxoUHao-FTTkizfe.mjs} +15 -3
- package/dist/canonicalize-RdxoUHao-FTTkizfe.mjs.map +1 -0
- package/dist/check-expressions-7uCCP01t-DtX2Vak9.mjs +48 -0
- package/dist/check-expressions-7uCCP01t-DtX2Vak9.mjs.map +1 -0
- package/dist/{check-expressions-DRgG8RN5-DiA-22aC.d.mts → check-expressions-CtTzM58x-LloO-5Vf.d.mts} +14 -13
- package/dist/check-expressions-CtTzM58x-LloO-5Vf.d.mts.map +1 -0
- package/dist/{codec-descriptor-LT7BpQta-BaDM8UQQ.mjs → codec-descriptor-DoR-cTFZ-BlG5Gj-X.mjs} +12 -21
- package/dist/codec-descriptor-DoR-cTFZ-BlG5Gj-X.mjs.map +1 -0
- package/dist/codec-descriptor-Fb3UoQGb.d.mts +1 -0
- package/dist/codec-descriptor-d1ByNBEk-DhrtS_5y.d.mts +47 -0
- package/dist/codec-descriptor-d1ByNBEk-DhrtS_5y.d.mts.map +1 -0
- package/dist/codec-ids-BMhEpFwv-B8Zh0s_Q.mjs +41 -0
- package/dist/codec-ids-BMhEpFwv-B8Zh0s_Q.mjs.map +1 -0
- package/dist/codec-ids-C6II64Wy-CPYTqDTT.d.mts +41 -0
- package/dist/codec-ids-C6II64Wy-CPYTqDTT.d.mts.map +1 -0
- package/dist/codec-ids-CcB5uBNf.d.mts +1 -0
- package/dist/codec-registry-D7XslgPe-DTZnVB8W.mjs +61 -0
- package/dist/codec-registry-D7XslgPe-DTZnVB8W.mjs.map +1 -0
- package/dist/codec-type-map-Fj5xCgwT-BeCXgfuR.d.mts +53 -0
- package/dist/codec-type-map-Fj5xCgwT-BeCXgfuR.d.mts.map +1 -0
- package/dist/codec-types-BBACckHa.d.mts +2 -0
- package/dist/codec-types-Ct_4iTVc-3tFJcIBo.d.mts +84 -0
- package/dist/codec-types-Ct_4iTVc-3tFJcIBo.d.mts.map +1 -0
- package/dist/codecs-CADK7dCR-C8WToYQb.d.mts +724 -0
- package/dist/codecs-CADK7dCR-C8WToYQb.d.mts.map +1 -0
- package/dist/codecs-CRl9-i_r-Co-bgYl3.mjs +1743 -0
- package/dist/codecs-CRl9-i_r-Co-bgYl3.mjs.map +1 -0
- package/dist/codecs-CoEpEqjM.d.mts +31 -0
- package/dist/codecs-CoEpEqjM.d.mts.map +1 -0
- package/dist/column-types-B4zsV-u3.mjs +106 -0
- package/dist/column-types-B4zsV-u3.mjs.map +1 -0
- package/dist/column-types-Bs2V0j8T.d.mts +164 -0
- package/dist/column-types-Bs2V0j8T.d.mts.map +1 -0
- package/dist/{control-adapter-DFr4gS-r-DM3KcZdQ.mjs → contract-contributions-Xz2FpyfI-CeQZqHKf.mjs} +489 -292
- package/dist/contract-contributions-Xz2FpyfI-CeQZqHKf.mjs.map +1 -0
- package/dist/{contract-free-DzpGxLfb.d.mts → contract-free-B6-wuc6M.d.mts} +36 -6
- package/dist/contract-free-B6-wuc6M.d.mts.map +1 -0
- package/dist/{contract-free-aQ4nT-_R.mjs → contract-free-o7olebm9.mjs} +13 -9
- package/dist/contract-free-o7olebm9.mjs.map +1 -0
- package/dist/control--HupSPoV.d.mts +847 -0
- package/dist/control--HupSPoV.d.mts.map +1 -0
- package/dist/{control-BaUpALVp.d.mts → control-CQEjh4P7.d.mts} +2 -2
- package/dist/control-CQEjh4P7.d.mts.map +1 -0
- package/dist/{control-DLTOAEHj.d.mts → control-D4cTcpcJ.d.mts} +22 -48
- package/dist/control-D4cTcpcJ.d.mts.map +1 -0
- package/dist/{control-Y6FxMu3o.mjs → control-DZQwENIP.mjs} +21 -9
- package/dist/control-DZQwENIP.mjs.map +1 -0
- package/dist/{control-policy-B53lnBCT-B9K9Cj1x.mjs → control-policy-DtU5u9Dm-44r_OF94.mjs} +444 -218
- package/dist/control-policy-DtU5u9Dm-44r_OF94.mjs.map +1 -0
- package/dist/{data-transform-ChZzy2dP-CxVCat_8.mjs → data-transform-h9agBu_c-RlC5A7aY.mjs} +12 -5
- package/dist/data-transform-h9agBu_c-RlC5A7aY.mjs.map +1 -0
- package/dist/{data-transform-Ck5FbyNO-BNE7QlAo.d.mts → data-transform-nGy9rz87-CE3DGlgn.d.mts} +15 -4
- package/dist/data-transform-nGy9rz87-CE3DGlgn.d.mts.map +1 -0
- package/dist/data-transform-nqkqNIb8.d.mts +1 -0
- package/dist/data-type-entries-gQW3-KSb-BIl8vgus.mjs +128 -0
- package/dist/data-type-entries-gQW3-KSb-BIl8vgus.mjs.map +1 -0
- package/dist/data-types--7V9yY1G.d.mts +99 -0
- package/dist/data-types--7V9yY1G.d.mts.map +1 -0
- package/dist/data-types-Chx0mjTP-DczU4S9b.mjs +950 -0
- package/dist/data-types-Chx0mjTP-DczU4S9b.mjs.map +1 -0
- package/dist/date-time-now-generators-CMkXVbMG-C-GjhReE.d.mts +45 -0
- package/dist/date-time-now-generators-CMkXVbMG-C-GjhReE.d.mts.map +1 -0
- package/dist/ddl-B7Rqlz6D-B7dRDgYb.mjs +647 -0
- package/dist/ddl-B7Rqlz6D-B7dRDgYb.mjs.map +1 -0
- package/dist/ddl-B8nQZTWN.d.mts +1 -0
- package/dist/default-constraint-names-Cz9Yoeim-sUzOGvIm.mjs +18 -0
- package/dist/default-constraint-names-Cz9Yoeim-sUzOGvIm.mjs.map +1 -0
- package/dist/default-normalizer-BqK6XxdC-2OUb2ybG.mjs +311 -0
- package/dist/default-normalizer-BqK6XxdC-2OUb2ybG.mjs.map +1 -0
- package/dist/default-normalizer-DO-cH75Q.d.mts +25 -0
- package/dist/default-normalizer-DO-cH75Q.d.mts.map +1 -0
- package/dist/descriptor-meta-BkD3nXF_-CZaNqC6r.mjs +36 -0
- package/dist/descriptor-meta-BkD3nXF_-CZaNqC6r.mjs.map +1 -0
- package/dist/descriptor-meta-DaFDNnHQ-QjiiAEtC.mjs +64 -0
- package/dist/descriptor-meta-DaFDNnHQ-QjiiAEtC.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-Dft1L7eE-D8vpOz_Z.mjs +15 -0
- package/dist/descriptor-meta-runtime-Dft1L7eE-D8vpOz_Z.mjs.map +1 -0
- package/dist/{diff-database-schema-DsoNznGC.d.mts → diff-database-schema-BxzhZaVN.d.mts} +12 -7
- package/dist/diff-database-schema-BxzhZaVN.d.mts.map +1 -0
- package/dist/{diff-database-schema-DKq76rCk-uehceHYz.mjs → diff-database-schema-DAEzWtzU-DoyVgKqh.mjs} +38 -18
- package/dist/diff-database-schema-DAEzWtzU-DoyVgKqh.mjs.map +1 -0
- package/dist/driver.d.mts +3 -3
- package/dist/driver.mjs +3 -2
- package/dist/driver__control.d.mts +1 -1
- package/dist/driver__control.mjs +1 -1
- package/dist/driver__runtime.d.mts +2 -2
- package/dist/driver__runtime.mjs +2 -639
- package/dist/errors-BrhQYgdL-IvZHPjwL.mjs +103 -0
- package/dist/errors-BrhQYgdL-IvZHPjwL.mjs.map +1 -0
- package/dist/{errors-CU4xIwwk.d.mts → errors-D3Mj-x0o.d.mts} +3 -3
- package/dist/errors-D3Mj-x0o.d.mts.map +1 -0
- package/dist/full-text-BYg7EVX2.mjs +39 -0
- package/dist/full-text-BYg7EVX2.mjs.map +1 -0
- package/dist/full-text-SDbfxrE_.d.mts +26 -0
- package/dist/full-text-SDbfxrE_.d.mts.map +1 -0
- package/dist/full-text-collection-method-BFd2u2cs-Ba3OiWM3.d.mts +27 -0
- package/dist/full-text-collection-method-BFd2u2cs-Ba3OiWM3.d.mts.map +1 -0
- package/dist/full-text-index-authoring-CN1L9C1k.d.mts +7 -0
- package/dist/full-text-index-authoring-CN1L9C1k.d.mts.map +1 -0
- package/dist/full-text-index-definition-BPxQQBuC-VLyQ1kEL.mjs +195 -0
- package/dist/full-text-index-definition-BPxQQBuC-VLyQ1kEL.mjs.map +1 -0
- package/dist/full-text-index-definition-D5iBWLss-BEpqiucV.d.mts +71 -0
- package/dist/full-text-index-definition-D5iBWLss-BEpqiucV.d.mts.map +1 -0
- package/dist/full-text-parsers-CFFxiOrp-CrZ7VI1m.mjs +139 -0
- package/dist/full-text-parsers-CFFxiOrp-CrZ7VI1m.mjs.map +1 -0
- package/dist/full-text-search-document-Doy5TF7c-aMWM_1KB.mjs +54 -0
- package/dist/full-text-search-document-Doy5TF7c-aMWM_1KB.mjs.map +1 -0
- package/dist/index-types-BihjrAAq-C2VnfAyF.mjs +14 -0
- package/dist/index-types-BihjrAAq-C2VnfAyF.mjs.map +1 -0
- package/dist/indexes-BYf6nXVv-BXwLw7fO.d.mts +60 -0
- package/dist/indexes-BYf6nXVv-BXwLw7fO.d.mts.map +1 -0
- package/dist/infer-psl-contract-BSSHcuRi-ChdFSviw.mjs +1143 -0
- package/dist/infer-psl-contract-BSSHcuRi-ChdFSviw.mjs.map +1 -0
- package/dist/{issue-planner-Biq9Ls7e.d.mts → issue-planner-D-On52xP.d.mts} +39 -9
- package/dist/issue-planner-D-On52xP.d.mts.map +1 -0
- package/dist/list-decoder-BcrLExnx-DlCwavhu.d.mts +7 -0
- package/dist/list-decoder-BcrLExnx-DlCwavhu.d.mts.map +1 -0
- package/dist/marker-lock-BviIbusV.d.mts +11 -0
- package/dist/marker-lock-BviIbusV.d.mts.map +1 -0
- package/dist/marker-lock-DFc1Tfv5-BkBKBRE3.mjs +11 -0
- package/dist/marker-lock-DFc1Tfv5-BkBKBRE3.mjs.map +1 -0
- package/dist/{migration-PTHAY9Cv.mjs → migration-Be_iuIpn.mjs} +5 -4
- package/dist/migration-Be_iuIpn.mjs.map +1 -0
- package/dist/migration-D4lMmLVj.d.mts +26 -0
- package/dist/migration-D4lMmLVj.d.mts.map +1 -0
- package/dist/{namespace-ids-xtp_ZY86-Cpp8PTxD.mjs → namespace-ids-xtp_ZY86-Cxc0dBbO.mjs} +2 -2
- package/dist/namespace-ids-xtp_ZY86-Cxc0dBbO.mjs.map +1 -0
- package/dist/native-type-normalizer-BaGa9eeb.d.mts +30 -0
- package/dist/native-type-normalizer-BaGa9eeb.d.mts.map +1 -0
- package/dist/native-type-normalizer-Cn-RGt_E.mjs +24 -0
- package/dist/native-type-normalizer-Cn-RGt_E.mjs.map +1 -0
- package/dist/{nodes-DAvDJLvJ-BBdvFXNa.mjs → nodes-G8VTh4PM-DNvIhHag.mjs} +78 -7
- package/dist/nodes-G8VTh4PM-DNvIhHag.mjs.map +1 -0
- package/dist/{nodes-BU-V-aZA-RqwPH68u.d.mts → nodes-s0Oe37jT-Cw3BU2gL.d.mts} +82 -29
- package/dist/nodes-s0Oe37jT-Cw3BU2gL.d.mts.map +1 -0
- package/dist/op-factory-call-CRaVUOb_.d.mts +1 -0
- package/dist/{op-factory-call-H6zeDGLe-_1pAftJk.mjs → op-factory-call-gGX-mZu--0QUG5xH4.mjs} +1014 -258
- package/dist/op-factory-call-gGX-mZu--0QUG5xH4.mjs.map +1 -0
- package/dist/{op-factory-call-BAeyLFYf-BAgG1h1C.d.mts → op-factory-call-nLHvNx0O-BTBhGbOF.d.mts} +169 -111
- package/dist/op-factory-call-nLHvNx0O-BTBhGbOF.d.mts.map +1 -0
- package/dist/operation-types--Wa_cv45-RoRnL1Dn.d.mts +192 -0
- package/dist/operation-types--Wa_cv45-RoRnL1Dn.d.mts.map +1 -0
- package/dist/operation-types-OXILTAOX.d.mts +1 -0
- package/dist/pack-2CYw2w-b.d.mts +1573 -0
- package/dist/pack-2CYw2w-b.d.mts.map +1 -0
- package/dist/{planner-CT-7zSfk.d.mts → planner-AD3Dt57t.d.mts} +23 -51
- package/dist/planner-AD3Dt57t.d.mts.map +1 -0
- package/dist/planner-VuR6URu3-CCUT2Osx.mjs +954 -0
- package/dist/planner-VuR6URu3-CCUT2Osx.mjs.map +1 -0
- package/dist/planner-ddl-builders-CPM3y7cQ.d.mts +16 -0
- package/dist/planner-ddl-builders-CPM3y7cQ.d.mts.map +1 -0
- package/dist/planner-ddl-builders-cYnH52gC-BWifb_M6.mjs +28 -0
- package/dist/planner-ddl-builders-cYnH52gC-BWifb_M6.mjs.map +1 -0
- package/dist/planner-identity-values-Dsq989Lh.d.mts +26 -0
- package/dist/planner-identity-values-Dsq989Lh.d.mts.map +1 -0
- package/dist/planner-identity-values-QstrMJ2U-CcpaRVPY.mjs +70 -0
- package/dist/planner-identity-values-QstrMJ2U-CcpaRVPY.mjs.map +1 -0
- package/dist/planner-produced-postgres-migration-BBUwtjA_.d.mts +1 -0
- package/dist/{planner-produced-postgres-migration-D5m8nK6s-CbZ4hlbv.mjs → planner-produced-postgres-migration-BZclL_xO-uflxtYuP.mjs} +5 -5
- package/dist/planner-produced-postgres-migration-BZclL_xO-uflxtYuP.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-BaviT8KK-Yo9kw6rs.d.mts → planner-produced-postgres-migration-DyIXJ3MR-DHO5wn_X.d.mts} +4 -4
- package/dist/planner-produced-postgres-migration-DyIXJ3MR-DHO5wn_X.d.mts.map +1 -0
- package/dist/{planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs → planner-schema-lookup-BbUY9oVy.mjs} +2 -2
- package/dist/planner-schema-lookup-BbUY9oVy.mjs.map +1 -0
- package/dist/{planner-schema-lookup-C4DHAddq.d.mts → planner-schema-lookup-ceCNOGFf.d.mts} +2 -2
- package/dist/planner-schema-lookup-ceCNOGFf.d.mts.map +1 -0
- package/dist/planner-sql-checks-D-K44J19-CzvrqzNB.mjs +151 -0
- package/dist/planner-sql-checks-D-K44J19-CzvrqzNB.mjs.map +1 -0
- package/dist/planner-sql-checks-Ed-WGtge-D9ByMrW4.d.mts +37 -0
- package/dist/planner-sql-checks-Ed-WGtge-D9ByMrW4.d.mts.map +1 -0
- package/dist/planner-sql-checks-rEjFx_Jv.d.mts +1 -0
- package/dist/planner-target-details-CUEF0s90-6g-mOgTI.mjs +14 -0
- package/dist/planner-target-details-CUEF0s90-6g-mOgTI.mjs.map +1 -0
- package/dist/{planner-target-details-HkP4RrRO-_xPQVPF0.d.mts → planner-target-details-HkP4RrRO-D6VtK0jY.d.mts} +2 -2
- package/dist/planner-target-details-HkP4RrRO-D6VtK0jY.d.mts.map +1 -0
- package/dist/postgres-codec-traits-CnP5Bjxp-Dxdgv0TI.mjs +11 -0
- package/dist/postgres-codec-traits-CnP5Bjxp-Dxdgv0TI.mjs.map +1 -0
- package/dist/{postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts → postgres-contract-view-BFzIDwwN-hL3QLe_b.d.mts} +2 -2
- package/dist/postgres-contract-view-BFzIDwwN-hL3QLe_b.d.mts.map +1 -0
- package/dist/{postgres-contract-view-B8ykf2cO-T2LvWVFZ.mjs → postgres-contract-view-BO2elRMz-BqMBzJoJ.mjs} +27 -14
- package/dist/postgres-contract-view-BO2elRMz-BqMBzJoJ.mjs.map +1 -0
- package/dist/{postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts → postgres-database-schema-node-Cv8usVNX-BmvGozi4.d.mts} +4 -4
- package/dist/postgres-database-schema-node-Cv8usVNX-BmvGozi4.d.mts.map +1 -0
- package/dist/postgres-migration-BSWmeRLo-CUfVTUf0.mjs +1312 -0
- package/dist/postgres-migration-BSWmeRLo-CUfVTUf0.mjs.map +1 -0
- package/dist/{postgres-migration-BNsrwlxh-CwI5BqAu.d.mts → postgres-migration-C5deJ3Ne-C4Jxu-e6.d.mts} +135 -15
- package/dist/postgres-migration-C5deJ3Ne-C4Jxu-e6.d.mts.map +1 -0
- package/dist/{postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs → postgres-native-enum-CdP3b_-R-DgG3pi5p.mjs} +2 -2
- package/dist/postgres-native-enum-CdP3b_-R-DgG3pi5p.mjs.map +1 -0
- package/dist/postgres-object-name-FPikIvOw-B8FfJI7z.mjs +23 -0
- package/dist/postgres-object-name-FPikIvOw-B8FfJI7z.mjs.map +1 -0
- package/dist/{postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts → postgres-rls-policy-CnDxf3z9-BjpVyUnK.d.mts} +2 -2
- package/dist/postgres-rls-policy-CnDxf3z9-BjpVyUnK.d.mts.map +1 -0
- package/dist/{postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs → postgres-role-schema-node-B8Z5i5D--BzOKm4N1.mjs} +3 -3
- package/dist/postgres-role-schema-node-B8Z5i5D--BzOKm4N1.mjs.map +1 -0
- package/dist/{postgres-schema-CF0yHESb-D7n2X21R.mjs → postgres-schema-C6w1rzOF-D1fdwqRx.mjs} +14 -12
- package/dist/postgres-schema-C6w1rzOF-D1fdwqRx.mjs.map +1 -0
- package/dist/{postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts → postgres-schema-Xsjt3RKO-bis-SVSB.d.mts} +4 -4
- package/dist/postgres-schema-Xsjt3RKO-bis-SVSB.d.mts.map +1 -0
- package/dist/{postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs → postgres-table-schema-node-BBkitBQh-Dll8iaZT.mjs} +2 -2
- package/dist/postgres-table-schema-node-BBkitBQh-Dll8iaZT.mjs.map +1 -0
- package/dist/prisma7-binding-BjiLA9F7.mjs +307 -0
- package/dist/prisma7-binding-BjiLA9F7.mjs.map +1 -0
- package/dist/prisma7-binding-a56klfkc.d.mts +1651 -0
- package/dist/prisma7-binding-a56klfkc.d.mts.map +1 -0
- package/dist/{render-ops-DOsRP0Po-BKn_c_Ia.mjs → render-ops-BgqtCw9Z-T8BPTX85.mjs} +17 -10
- package/dist/render-ops-BgqtCw9Z-T8BPTX85.mjs.map +1 -0
- package/dist/{render-ops-DPwhZt2W.d.mts → render-ops-Bl84i7ut.d.mts} +3 -3
- package/dist/render-ops-Bl84i7ut.d.mts.map +1 -0
- package/dist/{render-typescript-6sCFvMBh.d.mts → render-typescript-BysdXYpH.d.mts} +2 -2
- package/dist/render-typescript-BysdXYpH.d.mts.map +1 -0
- package/dist/{render-typescript-Dqp1Spgn-B128r1qw.mjs → render-typescript-Dqp1Spgn-B4mJhuVr.mjs} +2 -2
- package/dist/render-typescript-Dqp1Spgn-B4mJhuVr.mjs.map +1 -0
- package/dist/resolve-ddl-schema-D3VNPMSm-BuB6NyOI.mjs +34 -0
- package/dist/resolve-ddl-schema-D3VNPMSm-BuB6NyOI.mjs.map +1 -0
- package/dist/{runtime-lHBKgjB9.d.mts → runtime-C0VXuM0b.d.mts} +4 -3
- package/dist/runtime-C0VXuM0b.d.mts.map +1 -0
- package/dist/runtime-CXfxy5ED.mjs +660 -0
- package/dist/runtime-CXfxy5ED.mjs.map +1 -0
- package/dist/{runtime-_TfO66h5.d.mts → runtime-Ci_toEDZ.d.mts} +12 -4
- package/dist/runtime-Ci_toEDZ.d.mts.map +1 -0
- package/dist/{runtime-DOXznQe0.d.mts → runtime-DtjW0GP_.d.mts} +4 -4
- package/dist/runtime-DtjW0GP_.d.mts.map +1 -0
- package/dist/{schema-ir-annotations-DuuYh0gl.d.mts → schema-ir-annotations-BygaWBiC.d.mts} +2 -2
- package/dist/schema-ir-annotations-BygaWBiC.d.mts.map +1 -0
- package/dist/{schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts → schema-node-kinds-C52Bb1ve-DmxQRPPS.d.mts} +2 -2
- package/dist/schema-node-kinds-C52Bb1ve-DmxQRPPS.d.mts.map +1 -0
- package/dist/{normalize-error-CNjgVO71-CLlZ3CuJ.mjs → server-text-types-DeNPQpv5-DqX0h8WF.mjs} +45 -3
- package/dist/server-text-types-DeNPQpv5-DqX0h8WF.mjs.map +1 -0
- package/dist/{sql-renderer-ComgusFq-BBlqM1fw.mjs → sql-renderer-BdWJPa5F-Ct0CPlXc.mjs} +113 -123
- package/dist/sql-renderer-BdWJPa5F-Ct0CPlXc.mjs.map +1 -0
- package/dist/{sql-renderer-BgC0ZgLS.d.mts → sql-renderer-BiBhge7D.d.mts} +9 -7
- package/dist/sql-renderer-BiBhge7D.d.mts.map +1 -0
- package/dist/{sql-utils-DuzN3JZg-DiXy4Vah.mjs → sql-utils-Bnw3JbWf-BN0gcjZB.mjs} +31 -8
- package/dist/sql-utils-Bnw3JbWf-BN0gcjZB.mjs.map +1 -0
- package/dist/{sql-utils-DW6fkczF.d.mts → sql-utils-CnnGiZBc.d.mts} +12 -4
- package/dist/sql-utils-CnnGiZBc.d.mts.map +1 -0
- package/dist/{table-source-ikHOZmhD-DriY1Lcr.d.mts → table-source-ikHOZmhD-vYcblBYv.d.mts} +2 -2
- package/dist/table-source-ikHOZmhD-vYcblBYv.d.mts.map +1 -0
- package/dist/target.d.mts +61 -49
- package/dist/target.mjs +45 -36
- package/dist/target__aggregates.d.mts +1 -1
- package/dist/target__aggregates.mjs +1 -1
- package/dist/target__codec-descriptor.d.mts +2 -2
- package/dist/target__codec-descriptor.mjs +1 -1
- package/dist/target__codec-ids.d.mts +3 -3
- package/dist/target__codec-ids.mjs +2 -2
- package/dist/target__codec-types.d.mts +4 -4
- package/dist/target__codecs.d.mts +4 -3
- package/dist/target__codecs.mjs +3 -3
- package/dist/target__contract-free.d.mts +3 -3
- package/dist/target__contract-free.mjs +4 -4
- package/dist/target__control.d.mts +4 -2
- package/dist/target__control.mjs +2501 -2
- package/dist/target__control.mjs.map +1 -0
- package/dist/target__data-transform.d.mts +2 -2
- package/dist/target__data-transform.mjs +1 -1
- package/dist/target__data-types.d.mts +2 -0
- package/dist/target__data-types.mjs +3 -0
- package/dist/target__ddl.d.mts +4 -4
- package/dist/target__ddl.mjs +2 -2
- package/dist/target__default-normalizer.d.mts +2 -2
- package/dist/target__default-normalizer.mjs +2 -2
- package/dist/target__diff-database-schema.d.mts +1 -1
- package/dist/target__diff-database-schema.mjs +1 -1
- package/dist/target__errors.d.mts +1 -1
- package/dist/target__errors.mjs +1 -1
- package/dist/target__full-text-index-authoring.d.mts +3 -0
- package/dist/target__full-text-index-authoring.mjs +3 -0
- package/dist/target__full-text.d.mts +4 -0
- package/dist/target__full-text.mjs +3 -0
- package/dist/target__issue-planner.d.mts +1 -1
- package/dist/target__issue-planner.mjs +1 -1
- package/dist/target__marker-lock.d.mts +2 -0
- package/dist/target__marker-lock.mjs +2 -0
- package/dist/target__migration.d.mts +4 -4
- package/dist/target__migration.mjs +5 -5
- package/dist/target__native-type-normalizer.d.mts +2 -2
- package/dist/target__native-type-normalizer.mjs +2 -2
- package/dist/target__op-factory-call.d.mts +3 -3
- package/dist/target__op-factory-call.mjs +2 -2
- package/dist/target__operation-types.d.mts +4 -0
- package/dist/target__pack.d.mts +3 -2
- package/dist/target__pack.mjs +1 -1
- package/dist/target__planner-ddl-builders.d.mts +2 -2
- package/dist/target__planner-ddl-builders.mjs +2 -2
- package/dist/target__planner-identity-values.d.mts +1 -1
- package/dist/target__planner-identity-values.mjs +1 -1
- package/dist/target__planner-produced-postgres-migration.d.mts +2 -2
- package/dist/target__planner-produced-postgres-migration.mjs +1 -1
- package/dist/target__planner-schema-lookup.d.mts +1 -1
- package/dist/target__planner-schema-lookup.mjs +1 -1
- package/dist/target__planner-sql-checks.d.mts +3 -2
- package/dist/target__planner-sql-checks.mjs +2 -2
- package/dist/target__planner-target-details.d.mts +1 -1
- package/dist/target__planner.d.mts +1 -1
- package/dist/target__planner.mjs +2 -2
- package/dist/target__prisma7-binding.d.mts +2 -0
- package/dist/target__prisma7-binding.mjs +2 -0
- package/dist/target__render-ops.d.mts +1 -1
- package/dist/target__render-ops.mjs +1 -1
- package/dist/target__render-typescript.d.mts +1 -1
- package/dist/target__render-typescript.mjs +1 -1
- package/dist/target__rls-canonicalize.d.mts +2 -2
- package/dist/target__rls-canonicalize.mjs +2 -2
- package/dist/target__runtime.d.mts +6 -3
- package/dist/target__runtime.mjs +193 -4
- package/dist/target__runtime.mjs.map +1 -1
- package/dist/target__schema-ir-annotations.d.mts +1 -1
- package/dist/target__schema-ir-annotations.mjs +1 -1
- package/dist/target__sql-utils.d.mts +3 -2
- package/dist/target__sql-utils.mjs +4 -2
- package/dist/target__types.d.mts +7 -7
- package/dist/target__types.mjs +5 -5
- package/dist/types-AvjnIUna.d.mts +2 -0
- package/dist/types-D6lgKhE5-D1J9YJnd.d.mts +28 -0
- package/dist/types-D6lgKhE5-D1J9YJnd.d.mts.map +1 -0
- package/dist/{types-CjGjPLr5.d.mts → types-DOmgp_12.d.mts} +8 -8
- package/dist/types-DOmgp_12.d.mts.map +1 -0
- package/dist/{types-ue6jkJyF-BQJzjx1P.d.mts → types-ue6jkJyF-D79DmBTl.d.mts} +2 -2
- package/dist/types-ue6jkJyF-D79DmBTl.d.mts.map +1 -0
- package/package.json +22 -14
- package/dist/adapter-B0xsc80z-sYcF0RVF.mjs.map +0 -1
- package/dist/adapter-CPesdzv0.d.mts +0 -26
- package/dist/adapter-CPesdzv0.d.mts.map +0 -1
- package/dist/adapter__operation-types.d.mts +0 -2
- package/dist/aggregates-CgqNfj2O.d.mts +0 -10
- package/dist/aggregates-CgqNfj2O.d.mts.map +0 -1
- package/dist/aggregates-Dh6HPdvC.mjs.map +0 -1
- package/dist/authoring-BOpdZa2N-ClrLFiXw.mjs +0 -773
- package/dist/authoring-BOpdZa2N-ClrLFiXw.mjs.map +0 -1
- package/dist/canonicalize-CQlxSR4D-MnrT5gtW.d.mts.map +0 -1
- package/dist/canonicalize-CrN3u_xM-D4MrOqcB.mjs.map +0 -1
- package/dist/check-expressions-5vhxWaFy-CBcjFeur.mjs +0 -41
- package/dist/check-expressions-5vhxWaFy-CBcjFeur.mjs.map +0 -1
- package/dist/check-expressions-DRgG8RN5-DiA-22aC.d.mts.map +0 -1
- package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts +0 -37
- package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts.map +0 -1
- package/dist/codec-descriptor-Bg-_412t.d.mts +0 -1
- package/dist/codec-descriptor-LT7BpQta-BaDM8UQQ.mjs.map +0 -1
- package/dist/codec-ids-Bqu_IwO0-DKOdPizQ.d.mts +0 -35
- package/dist/codec-ids-Bqu_IwO0-DKOdPizQ.d.mts.map +0 -1
- package/dist/codec-ids-C5Rkltkw-DMf87l9s.mjs +0 -35
- package/dist/codec-ids-C5Rkltkw-DMf87l9s.mjs.map +0 -1
- package/dist/codec-ids-DJ6j6pZc.d.mts +0 -1
- package/dist/codec-types-BRU4F-7t-BaJbKF_i.d.mts +0 -84
- package/dist/codec-types-BRU4F-7t-BaJbKF_i.d.mts.map +0 -1
- package/dist/codec-types-bX63JRLf.d.mts +0 -2
- package/dist/codecs-B1HgsJZ2.mjs +0 -15
- package/dist/codecs-B1HgsJZ2.mjs.map +0 -1
- package/dist/codecs-BmPCJWqb-DveZGJvm.mjs +0 -1680
- package/dist/codecs-BmPCJWqb-DveZGJvm.mjs.map +0 -1
- package/dist/codecs-D8tLswBi-_nbo-Z8x.d.mts +0 -638
- package/dist/codecs-D8tLswBi-_nbo-Z8x.d.mts.map +0 -1
- package/dist/codecs-DmCKO7dg.d.mts +0 -15
- package/dist/codecs-DmCKO7dg.d.mts.map +0 -1
- package/dist/column-types-BH-MU6uU.d.mts +0 -108
- package/dist/column-types-BH-MU6uU.d.mts.map +0 -1
- package/dist/column-types-Bh92dNjD.mjs +0 -126
- package/dist/column-types-Bh92dNjD.mjs.map +0 -1
- package/dist/contract-free-DzpGxLfb.d.mts.map +0 -1
- package/dist/contract-free-aQ4nT-_R.mjs.map +0 -1
- package/dist/control-2F195jJk.d.mts +0 -11
- package/dist/control-2F195jJk.d.mts.map +0 -1
- package/dist/control-BaUpALVp.d.mts.map +0 -1
- package/dist/control-DLTOAEHj.d.mts.map +0 -1
- package/dist/control-V7OkAC55.mjs +0 -1459
- package/dist/control-V7OkAC55.mjs.map +0 -1
- package/dist/control-Y6FxMu3o.mjs.map +0 -1
- package/dist/control-adapter-DFr4gS-r-DM3KcZdQ.mjs.map +0 -1
- package/dist/control-policy-B53lnBCT-B9K9Cj1x.mjs.map +0 -1
- package/dist/data-transform-BSM7TQpE.d.mts +0 -1
- package/dist/data-transform-ChZzy2dP-CxVCat_8.mjs.map +0 -1
- package/dist/data-transform-Ck5FbyNO-BNE7QlAo.d.mts.map +0 -1
- package/dist/ddl-B4Rh8ntj.d.mts +0 -1
- package/dist/ddl-CNQJds-C-WfZ3y4y8.mjs +0 -395
- package/dist/ddl-CNQJds-C-WfZ3y4y8.mjs.map +0 -1
- package/dist/default-normalizer-B36TOul4.d.mts +0 -31
- package/dist/default-normalizer-B36TOul4.d.mts.map +0 -1
- package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs +0 -253
- package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs.map +0 -1
- package/dist/descriptor-meta-KVX21fsl-DBDoB4eg.mjs +0 -354
- package/dist/descriptor-meta-KVX21fsl-DBDoB4eg.mjs.map +0 -1
- package/dist/descriptor-meta-rilAH3ep-dAmiVLpe.mjs +0 -30
- package/dist/descriptor-meta-rilAH3ep-dAmiVLpe.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs +0 -13
- package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs.map +0 -1
- package/dist/diff-database-schema-DKq76rCk-uehceHYz.mjs.map +0 -1
- package/dist/diff-database-schema-DsoNznGC.d.mts.map +0 -1
- package/dist/driver__runtime.mjs.map +0 -1
- package/dist/errors-CU4xIwwk.d.mts.map +0 -1
- package/dist/errors-DKjQzNaN-DFcF1thx.mjs +0 -39
- package/dist/errors-DKjQzNaN-DFcF1thx.mjs.map +0 -1
- package/dist/issue-planner-Biq9Ls7e.d.mts.map +0 -1
- package/dist/migration-PTHAY9Cv.mjs.map +0 -1
- package/dist/migration-aFeTWTOJ.d.mts +0 -25
- package/dist/migration-aFeTWTOJ.d.mts.map +0 -1
- package/dist/namespace-ids-xtp_ZY86-Cpp8PTxD.mjs.map +0 -1
- package/dist/native-type-normalizer-DqJlOTeX.d.mts +0 -19
- package/dist/native-type-normalizer-DqJlOTeX.d.mts.map +0 -1
- package/dist/native-type-normalizer-yvd3tqv-.mjs +0 -38
- package/dist/native-type-normalizer-yvd3tqv-.mjs.map +0 -1
- package/dist/nodes-BU-V-aZA-RqwPH68u.d.mts.map +0 -1
- package/dist/nodes-DAvDJLvJ-BBdvFXNa.mjs.map +0 -1
- package/dist/normalize-error-CNjgVO71-CLlZ3CuJ.mjs.map +0 -1
- package/dist/op-factory-call-BAeyLFYf-BAgG1h1C.d.mts.map +0 -1
- package/dist/op-factory-call-BTU8I_x0.d.mts +0 -1
- package/dist/op-factory-call-H6zeDGLe-_1pAftJk.mjs.map +0 -1
- package/dist/operation-types-BfRocNI8.d.mts +0 -22
- package/dist/operation-types-BfRocNI8.d.mts.map +0 -1
- package/dist/pack-CySS3DQU.d.mts +0 -626
- package/dist/pack-CySS3DQU.d.mts.map +0 -1
- package/dist/planner-CT-7zSfk.d.mts.map +0 -1
- package/dist/planner-D0uogzvT-1WyGIC5p.mjs +0 -671
- package/dist/planner-D0uogzvT-1WyGIC5p.mjs.map +0 -1
- package/dist/planner-ddl-builders-Chxh-LEQ-DXvwOeeA.mjs +0 -102
- package/dist/planner-ddl-builders-Chxh-LEQ-DXvwOeeA.mjs.map +0 -1
- package/dist/planner-ddl-builders-ijp60-JO.d.mts +0 -19
- package/dist/planner-ddl-builders-ijp60-JO.d.mts.map +0 -1
- package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs +0 -90
- package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs.map +0 -1
- package/dist/planner-identity-values-TfEhnoWa.d.mts +0 -25
- package/dist/planner-identity-values-TfEhnoWa.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-BaviT8KK-Yo9kw6rs.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-D5m8nK6s-CbZ4hlbv.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-D6C0T2xV.d.mts +0 -1
- package/dist/planner-schema-lookup-C4DHAddq.d.mts.map +0 -1
- package/dist/planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs.map +0 -1
- package/dist/planner-sql-checks-CFgbRTJw.d.mts +0 -20
- package/dist/planner-sql-checks-CFgbRTJw.d.mts.map +0 -1
- package/dist/planner-sql-checks-ftgzvIO9-BTtBg2Vz.mjs +0 -152
- package/dist/planner-sql-checks-ftgzvIO9-BTtBg2Vz.mjs.map +0 -1
- package/dist/planner-target-details-HkP4RrRO-_xPQVPF0.d.mts.map +0 -1
- package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs +0 -15
- package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs.map +0 -1
- package/dist/postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts.map +0 -1
- package/dist/postgres-contract-view-B8ykf2cO-T2LvWVFZ.mjs.map +0 -1
- package/dist/postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts.map +0 -1
- package/dist/postgres-migration-BNsrwlxh-CwI5BqAu.d.mts.map +0 -1
- package/dist/postgres-migration-Dbq3RGfZ-aMnwfEAb.mjs +0 -205
- package/dist/postgres-migration-Dbq3RGfZ-aMnwfEAb.mjs.map +0 -1
- package/dist/postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs.map +0 -1
- package/dist/postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts.map +0 -1
- package/dist/postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs.map +0 -1
- package/dist/postgres-schema-CF0yHESb-D7n2X21R.mjs.map +0 -1
- package/dist/postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts.map +0 -1
- package/dist/postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs.map +0 -1
- package/dist/render-ops-DOsRP0Po-BKn_c_Ia.mjs.map +0 -1
- package/dist/render-ops-DPwhZt2W.d.mts.map +0 -1
- package/dist/render-typescript-6sCFvMBh.d.mts.map +0 -1
- package/dist/render-typescript-Dqp1Spgn-B128r1qw.mjs.map +0 -1
- package/dist/resolve-ddl-schema-CoaeNP35-C-UZldpj.mjs +0 -22
- package/dist/resolve-ddl-schema-CoaeNP35-C-UZldpj.mjs.map +0 -1
- package/dist/runtime-DOXznQe0.d.mts.map +0 -1
- package/dist/runtime-_TfO66h5.d.mts.map +0 -1
- package/dist/runtime-lHBKgjB9.d.mts.map +0 -1
- package/dist/schema-ir-annotations-DuuYh0gl.d.mts.map +0 -1
- package/dist/schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts.map +0 -1
- package/dist/sql-renderer-BgC0ZgLS.d.mts.map +0 -1
- package/dist/sql-renderer-ComgusFq-BBlqM1fw.mjs.map +0 -1
- package/dist/sql-utils-DW6fkczF.d.mts.map +0 -1
- package/dist/sql-utils-DuzN3JZg-DiXy4Vah.mjs.map +0 -1
- package/dist/table-source-ikHOZmhD-DriY1Lcr.d.mts.map +0 -1
- package/dist/types-B-4d5_4a.d.mts +0 -1
- package/dist/types-CjGjPLr5.d.mts.map +0 -1
- package/dist/types-CkryN1AS-BcQRGsDn.d.mts +0 -27
- package/dist/types-CkryN1AS-BcQRGsDn.d.mts.map +0 -1
- package/dist/types-ue6jkJyF-BQJzjx1P.d.mts.map +0 -1
- /package/dist/{adapter__operation-types.mjs → target__operation-types.mjs} +0 -0
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
import { c as postgresError } from "./errors-BrhQYgdL-IvZHPjwL.mjs";
|
|
2
|
+
import { i as quoteIdentifier } from "./sql-utils-Bnw3JbWf-BN0gcjZB.mjs";
|
|
3
|
+
import { INT32_RANGE, INT64_RANGE, asFloat, asNumeralText, assembleDataTypes, castUnchanged, dateTimeStoredText, decimalTextEqualityKey, readJsonBoolean, readJsonFloat, readJsonInteger, readJsonIntegerText, readJsonMatching, readJsonString, refuseJsonValue, refuseWrongShape, storedNumeralText } from "@prisma/orm-framework/components/codec";
|
|
4
|
+
import { isStructuredError, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
5
|
+
import { counted, withoutTrailing } from "@prisma/orm-framework/utils/text";
|
|
6
|
+
import { sqlDataType, sqlRawDataType } from "@prisma/orm-family-sql/contract/data-type";
|
|
7
|
+
import { type } from "arktype";
|
|
8
|
+
//#region ../../../3-targets/postgres/1-target/dist/data-types-Chx0mjTP.mjs
|
|
9
|
+
/**
|
|
10
|
+
* Whether text fits `length` characters, counted as PostgreSQL counts them: code points. A `character` value is padded with spaces, and spaces past its length are dropped, so they do not count.
|
|
11
|
+
*/
|
|
12
|
+
function fitsCharacterLength(text, length, blankPadded) {
|
|
13
|
+
const significant = blankPadded ? withoutTrailing(text, " ") : text;
|
|
14
|
+
return significant.length <= length || [...significant].length <= length;
|
|
15
|
+
}
|
|
16
|
+
/** The uuid input PostgreSQL reads: 32 hex digits in either case, a hyphen allowed after any group of four but the last, and the whole optionally in braces. */
|
|
17
|
+
const UUID_INPUT = /^(?:\{[0-9a-f]{4}(?:-?[0-9a-f]{4}){7}\}|[0-9a-f]{4}(?:-?[0-9a-f]{4}){7})$/i;
|
|
18
|
+
/**
|
|
19
|
+
* Text in any form PostgreSQL reads as a UUID (either case, a hyphen after any group of four digits, optionally in braces), written the way PostgreSQL writes it; `undefined` for text it does not read as one.
|
|
20
|
+
*/
|
|
21
|
+
function storedUuid(text) {
|
|
22
|
+
if (!UUID_INPUT.test(text)) return void 0;
|
|
23
|
+
const hex = text.replace(/[{}-]/g, "").toLowerCase();
|
|
24
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
25
|
+
}
|
|
26
|
+
/** The largest finite float4. */
|
|
27
|
+
const FLOAT4_MAX = 34028234663852886e22;
|
|
28
|
+
/** Whether float4 holds a finite number: it neither overflows to an infinity nor rounds to 0, both of which PostgreSQL refuses. */
|
|
29
|
+
function fitsFloat4(value) {
|
|
30
|
+
const single = Math.fround(value);
|
|
31
|
+
return Number.isFinite(single) && (value === 0 || single !== 0);
|
|
32
|
+
}
|
|
33
|
+
const ISO_DURATION = /^P(?!$)(-?\d+Y)?(-?\d+M)?(-?\d+D)?(?:T(?!$)(-?\d+H)?(-?\d+M)?(-?\d+(?:\.\d+)?S)?)?$/;
|
|
34
|
+
const MICROS_PER_SECOND = 1000000n;
|
|
35
|
+
/**
|
|
36
|
+
* Converts a fractional-seconds digit string to microseconds, rounding rather
|
|
37
|
+
* than truncating past the sixth digit.
|
|
38
|
+
*
|
|
39
|
+
* PostgreSQL rounds: `INTERVAL '1.1234567 seconds'` is `1.123457`, and
|
|
40
|
+
* `'1.9999999 seconds'` carries into `2`. Truncating here made the parsed value
|
|
41
|
+
* disagree with the database for any input past microsecond resolution.
|
|
42
|
+
*
|
|
43
|
+
* Ties round toward positive infinity, matching `Math.round` on the sibling path
|
|
44
|
+
* that reads the driver's component object — so the two agree. PostgreSQL's own
|
|
45
|
+
* tie behaviour is unobservable, because it parses the literal into a double
|
|
46
|
+
* first and an exact half never survives that.
|
|
47
|
+
*/
|
|
48
|
+
const microsFromFraction = (fraction, negative) => {
|
|
49
|
+
if (fraction === "") return 0n;
|
|
50
|
+
const kept = BigInt(fraction.slice(0, 6).padEnd(6, "0"));
|
|
51
|
+
const rest = fraction.slice(6).replace(/0+$/, "");
|
|
52
|
+
if (rest === "") return kept;
|
|
53
|
+
const half = rest[0] === "5" && rest.length === 1;
|
|
54
|
+
return rest > "5" || half && !negative ? kept + 1n : kept;
|
|
55
|
+
};
|
|
56
|
+
const MICROS_PER_DAY = 86400n * MICROS_PER_SECOND;
|
|
57
|
+
/** The key two stored intervals share exactly when PostgreSQL holds them equal: their total length in microseconds, a month counting as 30 days and a day as 24 hours. */
|
|
58
|
+
function intervalEqualityKey(json) {
|
|
59
|
+
const { months, days, micros } = intervalFieldsOf(String(json));
|
|
60
|
+
return ((BigInt(months) * 30n + BigInt(days)) * MICROS_PER_DAY + micros).toString();
|
|
61
|
+
}
|
|
62
|
+
const intervalFieldsOf = (text) => {
|
|
63
|
+
const match = ISO_DURATION.exec(text);
|
|
64
|
+
if (match === null) throw postgresError("RUNTIME.DECODE_FAILED", `pg/interval@1 value must be an ISO-8601 duration, got ${text}`, { meta: {
|
|
65
|
+
codecId: "pg/interval@1",
|
|
66
|
+
received: text
|
|
67
|
+
} });
|
|
68
|
+
const [, years, months, days, hours, minutes, seconds] = match;
|
|
69
|
+
const wholeNumber = (part) => part === void 0 ? 0 : Number(part.slice(0, -1));
|
|
70
|
+
const secondsLiteral = seconds === void 0 ? "0" : seconds.slice(0, -1);
|
|
71
|
+
const negative = secondsLiteral.startsWith("-");
|
|
72
|
+
const [whole = "0", fraction = ""] = secondsLiteral.replace("-", "").split(".");
|
|
73
|
+
const magnitude = BigInt(whole) * MICROS_PER_SECOND + microsFromFraction(fraction, negative);
|
|
74
|
+
return {
|
|
75
|
+
months: wholeNumber(years) * 12 + wholeNumber(months),
|
|
76
|
+
days: wholeNumber(days),
|
|
77
|
+
micros: BigInt(wholeNumber(hours)) * 3600n * MICROS_PER_SECOND + BigInt(wholeNumber(minutes)) * 60n * MICROS_PER_SECOND + (negative ? -magnitude : magnitude)
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const secondsText = (micros) => {
|
|
81
|
+
const sign = micros < 0n ? "-" : "";
|
|
82
|
+
const magnitude = micros < 0n ? -micros : micros;
|
|
83
|
+
const whole = magnitude / MICROS_PER_SECOND % 60n;
|
|
84
|
+
const fraction = magnitude % MICROS_PER_SECOND;
|
|
85
|
+
return `${sign}${whole}${fraction === 0n ? "" : `.${fraction.toString().padStart(6, "0").replace(/0+$/, "")}`}`;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Renders {@link PgInterval} the way PostgreSQL spells an interval under
|
|
89
|
+
* `IntervalStyle = 'iso_8601'`: zero components omitted, `T` present only when a
|
|
90
|
+
* time component is, each component carrying its own sign, and an all-zero
|
|
91
|
+
* interval written `PT0S`.
|
|
92
|
+
*/
|
|
93
|
+
const formatIsoDuration = ({ months, days, micros }) => {
|
|
94
|
+
const years = Math.trunc(months / 12);
|
|
95
|
+
const restMonths = months % 12;
|
|
96
|
+
const sign = micros < 0n ? "-" : "";
|
|
97
|
+
const magnitude = micros < 0n ? -micros : micros;
|
|
98
|
+
const hours = magnitude / (3600n * MICROS_PER_SECOND);
|
|
99
|
+
const minutes = magnitude / (60n * MICROS_PER_SECOND) % 60n;
|
|
100
|
+
const hasSeconds = magnitude % (60n * MICROS_PER_SECOND) !== 0n;
|
|
101
|
+
const parts = [
|
|
102
|
+
years === 0 ? "" : `${years}Y`,
|
|
103
|
+
restMonths === 0 ? "" : `${restMonths}M`,
|
|
104
|
+
days === 0 ? "" : `${days}D`
|
|
105
|
+
];
|
|
106
|
+
const time = [
|
|
107
|
+
hours === 0n ? "" : `${sign}${hours}H`,
|
|
108
|
+
minutes === 0n ? "" : `${sign}${minutes}M`,
|
|
109
|
+
hasSeconds ? `${secondsText(micros)}S` : ""
|
|
110
|
+
].join("");
|
|
111
|
+
const rendered = `P${parts.join("")}${time === "" ? "" : `T${time}`}`;
|
|
112
|
+
return rendered === "P" ? "PT0S" : rendered;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* An interval as PostgreSQL prints it under `IntervalStyle = 'postgres'`: `1 year 2 mons 3 days
|
|
116
|
+
* 04:05:06.5`, `-1 years -2 mons +3 days -04:00:00`, `00:00:00`.
|
|
117
|
+
*/
|
|
118
|
+
const POSTGRES_INTERVAL = /^(?:([+-]?\d+) years? ?)?(?:([+-]?\d+) mons? ?)?(?:([+-]?\d+) days? ?)?(?:([+-])?(\d+):(\d{2}):(\d{2})(?:\.(\d+))?)?$/;
|
|
119
|
+
function postgresIntervalFields(text) {
|
|
120
|
+
const match = POSTGRES_INTERVAL.exec(text);
|
|
121
|
+
if (match === null || text === "" || text.endsWith(" ")) return void 0;
|
|
122
|
+
const [, years = "0", months = "0", days = "0", sign, hours = "0", minutes = "0", seconds = "0"] = match;
|
|
123
|
+
const fraction = match[8] ?? "";
|
|
124
|
+
const magnitude = (BigInt(hours) * 3600n + BigInt(minutes) * 60n + BigInt(seconds)) * MICROS_PER_SECOND + microsFromFraction(fraction, sign === "-");
|
|
125
|
+
return {
|
|
126
|
+
months: Number(years) * 12 + Number(months),
|
|
127
|
+
days: Number(days),
|
|
128
|
+
micros: sign === "-" ? -magnitude : magnitude
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function intervalRefused(message) {
|
|
132
|
+
throw structuredError("CONTRACT.CAST_REFUSED", message, {
|
|
133
|
+
why: "pg/interval stores one form for each interval (ADR 254), and reads ISO 8601 durations and the text PostgreSQL prints.",
|
|
134
|
+
fix: "Write an ISO 8601 duration, as the message shows."
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The stored form of `pg/interval` (ADR 254), from an ISO 8601 duration or the text PostgreSQL
|
|
139
|
+
* prints under `IntervalStyle = 'postgres'`.
|
|
140
|
+
*/
|
|
141
|
+
function pgIntervalStoredText(text) {
|
|
142
|
+
const fractionDigits = /\.(\d+)/.exec(text)?.[1]?.length ?? 0;
|
|
143
|
+
if (fractionDigits > 6) intervalRefused(`"${text}" has ${fractionDigits} digits after the decimal point, but pg/interval holds microseconds, so at most 6. Round it, as in "PT1.123456S".`);
|
|
144
|
+
if (ISO_DURATION.test(text)) return formatIsoDuration(intervalFieldsOf(text));
|
|
145
|
+
const fields = postgresIntervalFields(text);
|
|
146
|
+
if (fields === void 0) intervalRefused(`pg/interval cannot read "${text}". Write an ISO 8601 duration, as in "P1Y2M3DT4H5M6S".`);
|
|
147
|
+
return formatIsoDuration(fields);
|
|
148
|
+
}
|
|
149
|
+
const BASE64_TEXT = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
150
|
+
/** Reads base64 with or without padding bits set; {@link spellPgByteaJson} writes the base64 `pg/bytea` stores. */
|
|
151
|
+
const readPgByteaJson = (owner, json) => readJsonMatching(owner, json, BASE64_TEXT, "a base64 string");
|
|
152
|
+
/** The base64 of the same bytes with padding bits zero, as `Buffer` writes it. */
|
|
153
|
+
const spellPgByteaJson = (json) => typeof json === "string" ? Buffer.from(json, "base64").toString("base64") : json;
|
|
154
|
+
const BYTEA_TEXT = /^\\x(?:[0-9A-Fa-f]{2})*$/;
|
|
155
|
+
/** The base64 `pg/bytea` stores for the hex text PostgreSQL prints, `\x68656c6c6f`. The `bytea` tag reads its body with this. */
|
|
156
|
+
function pgByteaFromHexText(text) {
|
|
157
|
+
if (!BYTEA_TEXT.test(text)) throw structuredError("CONTRACT.CAST_REFUSED", `"${text}" is not the hex text PostgreSQL prints for bytea, which is \\x followed by two hexadecimal digits for each byte, as in \\x68656c6c6f.`, {
|
|
158
|
+
why: "The bytea tag reads bytes as the hex text PostgreSQL prints under bytea_output = hex.",
|
|
159
|
+
fix: "Write the bytes in hex after \\x, as in bytea`\\x68656c6c6f`."
|
|
160
|
+
});
|
|
161
|
+
return Buffer.from(text.slice(2), "hex").toString("base64");
|
|
162
|
+
}
|
|
163
|
+
/** The hex text PostgreSQL prints for the base64 `pg/bytea` stores. */
|
|
164
|
+
function pgByteaHexText(base64) {
|
|
165
|
+
return `\\x${Buffer.from(base64, "base64").toString("hex")}`;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* PostgreSQL's year text (ADR 254, "Date and time types"). PostgreSQL reads and prints no signed year: a year after 9999 is written without its sign and leading zeros, `10000-01-01`, and a year at or before ISO year 0000 with a ` BC` suffix and PostgreSQL's year number, which has no year 0, so ISO year 0000 is `0001 BC` and -000043 is `0044 BC`. Every Postgres date and time codec and tag converts years through these two functions.
|
|
169
|
+
*/
|
|
170
|
+
const POSTGRES_YEAR = /^(\d{4,6})(-.*?)( BC)?$/;
|
|
171
|
+
const ISO_YEAR = /^([+-]\d{6}|\d{4})(-.*)$/;
|
|
172
|
+
const BC_SUFFIX = " BC";
|
|
173
|
+
/** ISO 8601 text, with a four-digit or signed six-digit year, from text PostgreSQL prints. Text with no year, ISO text and `0000 BC`, which does not exist, stay as they are. */
|
|
174
|
+
function isoYearText(text) {
|
|
175
|
+
const match = POSTGRES_YEAR.exec(text);
|
|
176
|
+
if (match === null) return text;
|
|
177
|
+
const [, digits = "", rest = "", bc] = match;
|
|
178
|
+
const year = Number(digits);
|
|
179
|
+
if (bc !== void 0) {
|
|
180
|
+
if (year === 0) return text;
|
|
181
|
+
return `${isoYear(1 - year)}${rest}`;
|
|
182
|
+
}
|
|
183
|
+
return digits.length > 4 ? `${isoYear(year)}${rest}` : text;
|
|
184
|
+
}
|
|
185
|
+
/** The text PostgreSQL reads for ISO 8601 text with a four-digit or signed six-digit year. Text with no year stays as it is. */
|
|
186
|
+
function postgresYearText(text) {
|
|
187
|
+
const match = ISO_YEAR.exec(text);
|
|
188
|
+
if (match === null) return text;
|
|
189
|
+
const [, yearDigits = "", rest = ""] = match;
|
|
190
|
+
const year = Number(yearDigits);
|
|
191
|
+
if (year > 9999) return `${year}${rest}`;
|
|
192
|
+
if (year >= 1) return `${String(year).padStart(4, "0")}${rest}`;
|
|
193
|
+
return `${String(1 - year).padStart(4, "0")}${rest}${BC_SUFFIX}`;
|
|
194
|
+
}
|
|
195
|
+
function isoYear(year) {
|
|
196
|
+
if (year >= 0 && year <= 9999) return String(year).padStart(4, "0");
|
|
197
|
+
return `${year < 0 ? "-" : "+"}${String(Math.abs(year)).padStart(6, "0")}`;
|
|
198
|
+
}
|
|
199
|
+
const DIGIT = /^[0-9]$/;
|
|
200
|
+
const HEX_DIGIT = /^[0-9a-fA-F]$/;
|
|
201
|
+
const isDigit = (ch) => ch !== void 0 && DIGIT.test(ch);
|
|
202
|
+
/**
|
|
203
|
+
* Text PostgreSQL reads as an `inet` value, written the way PostgreSQL prints it: an IPv4 address in
|
|
204
|
+
* four decimal octets, an IPv6 address in lower-case hex with its longest run of zero groups written
|
|
205
|
+
* `::`, and the prefix length only when it is shorter than the whole address. `undefined` for text
|
|
206
|
+
* PostgreSQL does not read as an `inet` value.
|
|
207
|
+
*/
|
|
208
|
+
function storedInet(text) {
|
|
209
|
+
if (text.includes(":")) {
|
|
210
|
+
const value = readIpv6(text);
|
|
211
|
+
return value === void 0 ? void 0 : printIpv6(value);
|
|
212
|
+
}
|
|
213
|
+
const value = readIpv4(text);
|
|
214
|
+
return value === void 0 ? void 0 : printIpv4(value);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* PostgreSQL's `inet_net_pton_ipv4`: one to four decimal octets, each up to 255 and leading zeros
|
|
218
|
+
* allowed, then an optional `/` and prefix length up to 32. Without a prefix length all four octets
|
|
219
|
+
* are required; with one, the octets written must cover it.
|
|
220
|
+
*/
|
|
221
|
+
function readIpv4(text) {
|
|
222
|
+
const octets = [];
|
|
223
|
+
let index = 0;
|
|
224
|
+
let ch = text[index++];
|
|
225
|
+
while (isDigit(ch)) {
|
|
226
|
+
let octet = 0;
|
|
227
|
+
do {
|
|
228
|
+
octet = octet * 10 + Number(ch);
|
|
229
|
+
if (octet > 255) return void 0;
|
|
230
|
+
ch = text[index++];
|
|
231
|
+
} while (isDigit(ch));
|
|
232
|
+
if (octets.length === 4) return void 0;
|
|
233
|
+
octets.push(octet);
|
|
234
|
+
if (ch === void 0 || ch === "/") break;
|
|
235
|
+
if (ch !== ".") return void 0;
|
|
236
|
+
ch = text[index++];
|
|
237
|
+
}
|
|
238
|
+
let bits = -1;
|
|
239
|
+
if (ch === "/" && isDigit(text[index]) && octets.length > 0) {
|
|
240
|
+
ch = text[index++];
|
|
241
|
+
bits = 0;
|
|
242
|
+
do {
|
|
243
|
+
bits = bits * 10 + Number(ch);
|
|
244
|
+
ch = text[index++];
|
|
245
|
+
} while (isDigit(ch));
|
|
246
|
+
if (ch !== void 0 || bits > 32) return void 0;
|
|
247
|
+
}
|
|
248
|
+
if (ch !== void 0) return void 0;
|
|
249
|
+
if (bits === -1) {
|
|
250
|
+
if (octets.length !== 4) return void 0;
|
|
251
|
+
bits = 32;
|
|
252
|
+
}
|
|
253
|
+
if (octets.length === 0 || Math.floor(bits / 8) > octets.length) return void 0;
|
|
254
|
+
return {
|
|
255
|
+
bytes: [
|
|
256
|
+
...octets,
|
|
257
|
+
0,
|
|
258
|
+
0,
|
|
259
|
+
0,
|
|
260
|
+
0
|
|
261
|
+
].slice(0, 4),
|
|
262
|
+
bits
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/** PostgreSQL's `getbits`: a prefix length up to 128, with no leading zero. */
|
|
266
|
+
function readBits(text) {
|
|
267
|
+
let bits = 0;
|
|
268
|
+
let digits = 0;
|
|
269
|
+
for (const ch of text) {
|
|
270
|
+
if (!isDigit(ch)) return void 0;
|
|
271
|
+
if (digits++ !== 0 && bits === 0) return void 0;
|
|
272
|
+
bits = bits * 10 + Number(ch);
|
|
273
|
+
if (bits > 128) return void 0;
|
|
274
|
+
}
|
|
275
|
+
return digits === 0 ? void 0 : bits;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* PostgreSQL's `getv4`, for the IPv4 tail of an IPv6 address: up to four decimal octets with no
|
|
279
|
+
* leading zeros, and an optional prefix length. Octets left out are zero.
|
|
280
|
+
*/
|
|
281
|
+
function readIpv4Tail(text) {
|
|
282
|
+
const octets = [];
|
|
283
|
+
let octet = 0;
|
|
284
|
+
let digits = 0;
|
|
285
|
+
for (const [index, ch] of [...text].entries()) {
|
|
286
|
+
if (isDigit(ch)) {
|
|
287
|
+
if (digits++ !== 0 && octet === 0) return void 0;
|
|
288
|
+
octet = octet * 10 + Number(ch);
|
|
289
|
+
if (octet > 255) return void 0;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (ch !== "." && ch !== "/") return void 0;
|
|
293
|
+
if (octets.length > 3) return void 0;
|
|
294
|
+
octets.push(octet);
|
|
295
|
+
if (ch === "/") {
|
|
296
|
+
const bits = readBits(text.slice(index + 1));
|
|
297
|
+
return bits === void 0 ? void 0 : {
|
|
298
|
+
octets,
|
|
299
|
+
bits
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
octet = 0;
|
|
303
|
+
digits = 0;
|
|
304
|
+
}
|
|
305
|
+
if (digits === 0 || octets.length > 3) return void 0;
|
|
306
|
+
return {
|
|
307
|
+
octets: [...octets, octet],
|
|
308
|
+
bits: void 0
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* PostgreSQL's `inet_cidr_pton_ipv6`: up to eight groups of one to four hex digits in either case,
|
|
313
|
+
* one `::` standing for a run of zero groups, an optional IPv4 tail, and an optional prefix length.
|
|
314
|
+
*/
|
|
315
|
+
function readIpv6(text) {
|
|
316
|
+
const bytes = new Array(16).fill(0);
|
|
317
|
+
let filled = 0;
|
|
318
|
+
let compressedAt;
|
|
319
|
+
let index = 0;
|
|
320
|
+
if (text[0] === ":") {
|
|
321
|
+
if (text[1] !== ":") return void 0;
|
|
322
|
+
index = 1;
|
|
323
|
+
}
|
|
324
|
+
let tokenStart = index;
|
|
325
|
+
let sawHexDigit = false;
|
|
326
|
+
let group = 0;
|
|
327
|
+
let groupDigits = 0;
|
|
328
|
+
let bits = 128;
|
|
329
|
+
while (index < text.length) {
|
|
330
|
+
const ch = text[index++] ?? "";
|
|
331
|
+
if (HEX_DIGIT.test(ch)) {
|
|
332
|
+
group = group << 4 | Number.parseInt(ch, 16);
|
|
333
|
+
if (++groupDigits > 4) return void 0;
|
|
334
|
+
sawHexDigit = true;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (ch === ":") {
|
|
338
|
+
tokenStart = index;
|
|
339
|
+
if (!sawHexDigit) {
|
|
340
|
+
if (compressedAt !== void 0) return void 0;
|
|
341
|
+
compressedAt = filled;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (index >= text.length || filled + 2 > 16) return void 0;
|
|
345
|
+
bytes[filled++] = group >> 8;
|
|
346
|
+
bytes[filled++] = group & 255;
|
|
347
|
+
sawHexDigit = false;
|
|
348
|
+
group = 0;
|
|
349
|
+
groupDigits = 0;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (ch === "." && filled + 4 <= 16) {
|
|
353
|
+
const tail = readIpv4Tail(text.slice(tokenStart));
|
|
354
|
+
if (tail !== void 0) {
|
|
355
|
+
tail.octets.forEach((octet, offset) => {
|
|
356
|
+
bytes[filled + offset] = octet;
|
|
357
|
+
});
|
|
358
|
+
filled += 4;
|
|
359
|
+
sawHexDigit = false;
|
|
360
|
+
bits = tail.bits ?? bits;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (ch === "/") {
|
|
365
|
+
const prefix = readBits(text.slice(index));
|
|
366
|
+
if (prefix !== void 0) {
|
|
367
|
+
bits = prefix;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (sawHexDigit) {
|
|
374
|
+
if (filled + 2 > 16) return void 0;
|
|
375
|
+
bytes[filled++] = group >> 8;
|
|
376
|
+
bytes[filled++] = group & 255;
|
|
377
|
+
}
|
|
378
|
+
if (compressedAt !== void 0) {
|
|
379
|
+
if (filled === 16) return void 0;
|
|
380
|
+
const shifted = bytes.slice(compressedAt, filled);
|
|
381
|
+
bytes.fill(0, compressedAt, filled);
|
|
382
|
+
bytes.splice(16 - shifted.length, shifted.length, ...shifted);
|
|
383
|
+
filled = 16;
|
|
384
|
+
}
|
|
385
|
+
return filled === 16 ? {
|
|
386
|
+
bytes,
|
|
387
|
+
bits
|
|
388
|
+
} : void 0;
|
|
389
|
+
}
|
|
390
|
+
function printIpv4({ bytes, bits }) {
|
|
391
|
+
const address = bytes.join(".");
|
|
392
|
+
return bits === 32 ? address : `${address}/${bits}`;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* PostgreSQL's `inet_net_ntop_ipv6`: the first longest run of two or more zero groups is written
|
|
396
|
+
* `::`, and an address whose first five groups are zero followed by `ffff`, or whose first six are
|
|
397
|
+
* zero, ends in dotted IPv4.
|
|
398
|
+
*/
|
|
399
|
+
function printIpv6({ bytes, bits }) {
|
|
400
|
+
const groups = Array.from({ length: 8 }, (_, i) => (bytes[2 * i] ?? 0) << 8 | (bytes[2 * i + 1] ?? 0));
|
|
401
|
+
const zeroRun = longestZeroRun(groups);
|
|
402
|
+
let text = "";
|
|
403
|
+
for (let i = 0; i < 8; i++) {
|
|
404
|
+
if (zeroRun !== void 0 && i >= zeroRun.start && i < zeroRun.start + zeroRun.length) {
|
|
405
|
+
if (i === zeroRun.start) text += ":";
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (i !== 0) text += ":";
|
|
409
|
+
if (i === 6 && zeroRun?.start === 0 && (zeroRun.length === 6 || zeroRun.length === 5 && groups[5] === 65535)) {
|
|
410
|
+
text += bytes.slice(12).join(".");
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
text += (groups[i] ?? 0).toString(16);
|
|
414
|
+
}
|
|
415
|
+
if (zeroRun !== void 0 && zeroRun.start + zeroRun.length === 8) text += ":";
|
|
416
|
+
return bits === 128 ? text : `${text}/${bits}`;
|
|
417
|
+
}
|
|
418
|
+
function longestZeroRun(groups) {
|
|
419
|
+
let best;
|
|
420
|
+
let current;
|
|
421
|
+
for (const [i, group] of groups.entries()) {
|
|
422
|
+
if (group === 0) {
|
|
423
|
+
current = current === void 0 ? {
|
|
424
|
+
start: i,
|
|
425
|
+
length: 1
|
|
426
|
+
} : {
|
|
427
|
+
...current,
|
|
428
|
+
length: current.length + 1
|
|
429
|
+
};
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
if (current !== void 0 && (best === void 0 || current.length > best.length)) best = current;
|
|
433
|
+
current = void 0;
|
|
434
|
+
}
|
|
435
|
+
if (current !== void 0 && (best === void 0 || current.length > best.length)) best = current;
|
|
436
|
+
return best !== void 0 && best.length >= 2 ? best : void 0;
|
|
437
|
+
}
|
|
438
|
+
const written = (text) => ({
|
|
439
|
+
text,
|
|
440
|
+
written: true
|
|
441
|
+
});
|
|
442
|
+
const catalog = (text) => ({
|
|
443
|
+
text,
|
|
444
|
+
catalog: true
|
|
445
|
+
});
|
|
446
|
+
const writtenAndCatalog = (text) => ({
|
|
447
|
+
text,
|
|
448
|
+
written: true,
|
|
449
|
+
catalog: true
|
|
450
|
+
});
|
|
451
|
+
const claimsOnly = (text) => ({ text });
|
|
452
|
+
const anyJson = (json) => json;
|
|
453
|
+
const readString = (id) => (json) => readJsonString(id, json);
|
|
454
|
+
/** A parameter a type declares as a whole number, or undefined when the column does not set it. */
|
|
455
|
+
function integerParam(params, name) {
|
|
456
|
+
const value = params[name];
|
|
457
|
+
return typeof value === "number" ? value : void 0;
|
|
458
|
+
}
|
|
459
|
+
/** A decimal numeral: an optional minus sign, digits, and an optional fraction. */
|
|
460
|
+
const DECIMAL_NUMERAL_TEXT = /^-?\d+(?:\.\d+)?$/;
|
|
461
|
+
/**
|
|
462
|
+
* Numeric text in the form PostgreSQL *prints*, which is narrower than the form it accepts.
|
|
463
|
+
*
|
|
464
|
+
* `numeric` reads `+123`, `.5`, `1.`, `1e5`, `0x1f`, `1_000`, `007`, `-0` and whitespace-padded input, but prints every one of them in a single normalised form — `123`, `0.5`, `1`, `100000`, `31`, `1000`, `7`, `0`. A value in any other form is one the database never returns: `1e5` reads back as `100000`.
|
|
465
|
+
*
|
|
466
|
+
* `NaN`, `Infinity` and `-Infinity` are genuine `numeric` values, which PostgreSQL emits into JSON as strings.
|
|
467
|
+
*/
|
|
468
|
+
const STORED_NUMERIC_TEXT = /^(?:(?!-0(?:\.0+)?$)-?(?:0|[1-9]\d*)(?:\.\d+)?|NaN|-?Infinity)$/;
|
|
469
|
+
/**
|
|
470
|
+
* Whether stored numeric text is a value `numeric(precision, scale)` stores without rounding: a whole number of units of 10^-scale, and at most `precision` digits once counted in those units. A negative scale rounds to tens, hundreds and so on, and a scale above the precision allows only values below 1. NaN fits; an infinity does not.
|
|
471
|
+
*/
|
|
472
|
+
function fitsNumeric(text, precision, scale) {
|
|
473
|
+
if (text === "NaN") return true;
|
|
474
|
+
if (text.endsWith("Infinity")) return false;
|
|
475
|
+
const [whole = "", fraction = ""] = text.replace(/^-/, "").split(".");
|
|
476
|
+
const significantFraction = withoutTrailing(fraction, "0");
|
|
477
|
+
const digits = `${whole}${significantFraction}`.replace(/^0+/, "");
|
|
478
|
+
if (digits === "") return true;
|
|
479
|
+
const shift = scale - significantFraction.length;
|
|
480
|
+
if (shift >= 0) return digits.length + shift <= precision;
|
|
481
|
+
const units = withoutTrailing(digits, "0");
|
|
482
|
+
if (digits.length - units.length < -shift) return false;
|
|
483
|
+
return digits.length + shift <= precision;
|
|
484
|
+
}
|
|
485
|
+
const readNumeric = (json, params) => {
|
|
486
|
+
if (typeof json !== "string" || !STORED_NUMERIC_TEXT.test(json)) {
|
|
487
|
+
const printed = typeof json === "string" && DECIMAL_NUMERAL_TEXT.test(json) ? storedNumeralText(json) : void 0;
|
|
488
|
+
return refuseJsonValue("pg/numeric", printed === void 0 ? "a decimal string" : `"${printed}", as PostgreSQL writes this value`, json);
|
|
489
|
+
}
|
|
490
|
+
const precision = integerParam(params, "precision");
|
|
491
|
+
if (precision === void 0) return json;
|
|
492
|
+
const scale = integerParam(params, "scale") ?? 0;
|
|
493
|
+
if (!fitsNumeric(json, precision, scale)) return refuseJsonValue("pg/numeric", `a decimal string that numeric(${precision}, ${scale}) stores without rounding`, json);
|
|
494
|
+
return json;
|
|
495
|
+
};
|
|
496
|
+
/** A value of `numeric(precision, scale)` is written as PostgreSQL prints it: with exactly `scale` fraction digits, none for a scale of 0 or below. */
|
|
497
|
+
const spellNumeric = (json, params) => {
|
|
498
|
+
if (integerParam(params, "precision") === void 0 || typeof json !== "string" || json === "NaN") return json;
|
|
499
|
+
const scale = integerParam(params, "scale") ?? 0;
|
|
500
|
+
const [whole = "", fraction = ""] = json.split(".");
|
|
501
|
+
return scale <= 0 ? whole : `${whole}.${fraction.slice(0, scale).padEnd(scale, "0")}`;
|
|
502
|
+
};
|
|
503
|
+
const readFloat4 = (json) => {
|
|
504
|
+
const value = readJsonFloat("pg/float4", json);
|
|
505
|
+
if (Number.isFinite(value) && !fitsFloat4(value)) return refuseJsonValue("pg/float4", `a number float4 holds, at most ${FLOAT4_MAX} in magnitude and not so small that it becomes 0, or the text NaN, Infinity or -Infinity`, json);
|
|
506
|
+
return json;
|
|
507
|
+
};
|
|
508
|
+
/** A `character` value is spelled without the spaces that pad it to its length, as the application reads it. */
|
|
509
|
+
const spellCharacter = (json) => typeof json === "string" ? withoutTrailing(json, " ") : json;
|
|
510
|
+
/** A `character` column holds its length in characters, and one with no length is `character(1)`; the spaces that pad a value to its length do not count. */
|
|
511
|
+
const readCharacter = (json, params) => {
|
|
512
|
+
const length = integerParam(params, "length") ?? 1;
|
|
513
|
+
if (!fitsCharacterLength(readJsonString("pg/char", json), length, true)) return refuseJsonValue("pg/char", `a string of at most ${counted(length, "character")} before any trailing spaces`, json);
|
|
514
|
+
return json;
|
|
515
|
+
};
|
|
516
|
+
/** A `character varying` column with a length holds at most that many characters. */
|
|
517
|
+
const readCharacterVarying = (json, params) => {
|
|
518
|
+
const length = integerParam(params, "length");
|
|
519
|
+
const text = readJsonString("pg/varchar", json);
|
|
520
|
+
if (length !== void 0 && !fitsCharacterLength(text, length, false)) return refuseJsonValue("pg/varchar", `a string of at most ${counted(length, "character")}`, json);
|
|
521
|
+
return json;
|
|
522
|
+
};
|
|
523
|
+
const BIT_STRING = /^[01]*$/;
|
|
524
|
+
/** A `bit` column holds exactly its length in bits, and one with no length is `bit(1)`. */
|
|
525
|
+
const readBit = (json, params) => {
|
|
526
|
+
const length = integerParam(params, "length") ?? 1;
|
|
527
|
+
if (readJsonMatching("pg/bit", json, BIT_STRING, "a string of 0 and 1 digits").length !== length) return refuseJsonValue("pg/bit", `a string of exactly ${counted(length, "bit")}`, json);
|
|
528
|
+
return json;
|
|
529
|
+
};
|
|
530
|
+
/** A `bit varying` column with a length holds at most that many bits. */
|
|
531
|
+
const readBitVarying = (json, params) => {
|
|
532
|
+
const length = integerParam(params, "length");
|
|
533
|
+
const bits = readJsonMatching("pg/varbit", json, BIT_STRING, "a string of 0 and 1 digits");
|
|
534
|
+
if (length !== void 0 && bits.length > length) return refuseJsonValue("pg/varbit", `a string of at most ${counted(length, "bit")}`, json);
|
|
535
|
+
return json;
|
|
536
|
+
};
|
|
537
|
+
/** A `text[]` may hold NULL elements, which PostgreSQL writes as JSON `null`. */
|
|
538
|
+
const readTextArray = (json) => {
|
|
539
|
+
const expected = "an array of strings and nulls";
|
|
540
|
+
if (!Array.isArray(json)) return refuseJsonValue("pg/text-array", expected, json);
|
|
541
|
+
for (const entry of json) if (entry !== null && typeof entry !== "string") return refuseJsonValue("pg/text-array", expected, entry);
|
|
542
|
+
return json;
|
|
543
|
+
};
|
|
544
|
+
/** Reads a UUID in any spelling PostgreSQL reads; `spellUuid` gives it the one it stores. */
|
|
545
|
+
const readUuid = (json) => typeof json === "string" && storedUuid(json) !== void 0 ? json : refuseJsonValue("pg/uuid", "a UUID in a spelling PostgreSQL reads: 32 hexadecimal digits in either case, with or without a hyphen after any group of four, optionally in braces", json);
|
|
546
|
+
/** A UUID is stored as PostgreSQL prints it: lower case, hyphenated 8-4-4-4-12. */
|
|
547
|
+
const spellUuid = (json) => typeof json === "string" ? storedUuid(json) ?? json : json;
|
|
548
|
+
/** Reads an address in any spelling PostgreSQL reads; `spellInet` gives it the one it stores. */
|
|
549
|
+
const readInet = (json) => typeof json === "string" && storedInet(json) !== void 0 ? json : refuseJsonValue("pg/inet", "an IP address or network in a spelling PostgreSQL reads, as in 10.0.0.1 or 2001:db8::/32", json);
|
|
550
|
+
/** An address is stored as PostgreSQL prints it. */
|
|
551
|
+
const spellInet = (json) => typeof json === "string" ? storedInet(json) ?? json : json;
|
|
552
|
+
/** The fraction digits of a second the date, time and interval types hold when a column sets no precision: microseconds. */
|
|
553
|
+
const MICROSECOND_DIGITS = 6;
|
|
554
|
+
/**
|
|
555
|
+
* A value with more fraction digits of a second than the column's `precision`, or than microseconds when it sets none, which PostgreSQL would round, is refused rather than rounded. Trailing zeros of a fraction are not digits of the value.
|
|
556
|
+
*/
|
|
557
|
+
function refuseFinerThanPrecision(typeId, json, fraction, params) {
|
|
558
|
+
const precision = integerParam(params, "precision") ?? MICROSECOND_DIGITS;
|
|
559
|
+
if (withoutTrailing(fraction ?? "", "0").length <= precision) return json;
|
|
560
|
+
return refuseJsonValue(typeId, `a value with at most ${counted(precision, "fraction digit")} of a second, which precision ${precision} holds without rounding`, json);
|
|
561
|
+
}
|
|
562
|
+
/** What `storedText` writes for `text`, or why it cannot read it. */
|
|
563
|
+
function storedSpelling(storedText, text) {
|
|
564
|
+
try {
|
|
565
|
+
return { stored: storedText(text) };
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (isStructuredError(error) && error.code === "CONTRACT.CAST_REFUSED") return { reason: error.message };
|
|
568
|
+
throw error;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Reads a value of a date or time type (ADR 254, "Date and time types") in any spelling its tag reads, and refuses other text. A value with more fraction digits than the column's precision is refused rather than rounded. `spellStoredDateTime` gives the value its one stored spelling.
|
|
573
|
+
*/
|
|
574
|
+
const readStoredDateTime = (typeId, storedText, description, fraction) => (json, params) => {
|
|
575
|
+
if (typeof json !== "string") return refuseJsonValue(typeId, description, json);
|
|
576
|
+
const spelling = storedSpelling(storedText, json);
|
|
577
|
+
if ("reason" in spelling) return refuseJsonValue(typeId, `${description}: ${spelling.reason}`, json);
|
|
578
|
+
refuseFinerThanPrecision(typeId, json, fraction.exec(spelling.stored)?.[1], params);
|
|
579
|
+
return json;
|
|
580
|
+
};
|
|
581
|
+
/** The stored spelling of a date or time value: what `storedText` writes. */
|
|
582
|
+
const spellStoredDateTime = (storedText) => (json) => {
|
|
583
|
+
if (typeof json !== "string") return json;
|
|
584
|
+
const spelling = storedSpelling(storedText, json);
|
|
585
|
+
return "stored" in spelling ? spelling.stored : json;
|
|
586
|
+
};
|
|
587
|
+
const SECONDS_FRACTION = /:\d{2}\.(\d+)/;
|
|
588
|
+
const INTERVAL_SECONDS_FRACTION = /\d\.(\d+)S$/;
|
|
589
|
+
/** The precision and scale of `numeric`. PostgreSQL 15 and later take a negative scale and one above the precision. */
|
|
590
|
+
const pgNumericParams = type({
|
|
591
|
+
"precision?": "number.integer >= 1 & number.integer <= 1000",
|
|
592
|
+
"scale?": "number.integer >= -1000 & number.integer <= 1000"
|
|
593
|
+
}).narrow((params, ctx) => params.scale === void 0 || params.precision !== void 0 || ctx.reject({
|
|
594
|
+
path: ["scale"],
|
|
595
|
+
message: "scale requires a precision"
|
|
596
|
+
}));
|
|
597
|
+
/** The length of `char` and `varchar`. */
|
|
598
|
+
const pgCharacterLengthParams = type({ "length?": "number.integer >= 1 & number.integer <= 10485760" });
|
|
599
|
+
/** The length of `bit` and `bit varying`. */
|
|
600
|
+
const pgBitLengthParams = type({ "length?": "number.integer >= 1 & number.integer <= 83886080" });
|
|
601
|
+
/** The fractional-second precision of the time, timestamp and interval types. */
|
|
602
|
+
const pgPrecisionParams = type({ "precision?": "number.integer >= 0 & number.integer <= 6" });
|
|
603
|
+
const pgEnumParams = type({ typeName: "string > 0" });
|
|
604
|
+
/** A type with no parameters that is written and reported by its own name. */
|
|
605
|
+
const namedOnly = (id, name, read, casts = {}) => sqlDataType(id, {
|
|
606
|
+
texts: [writtenAndCatalog(name)],
|
|
607
|
+
read,
|
|
608
|
+
casts
|
|
609
|
+
});
|
|
610
|
+
const withDefaultLength = (params) => params.length === void 0 ? {
|
|
611
|
+
...params,
|
|
612
|
+
length: 1
|
|
613
|
+
} : params;
|
|
614
|
+
const pgText = namedOnly("pg/text", "text", readString("pg/text"));
|
|
615
|
+
const pgTextArray = sqlDataType("pg/text-array", { read: readTextArray });
|
|
616
|
+
/** The enum's `typeName`: its name in `public` or with no schema, its schema-qualified name elsewhere. */
|
|
617
|
+
function qualifiedEnumName(reported) {
|
|
618
|
+
const name = reported.name ?? "";
|
|
619
|
+
return reported.schema === void 0 || reported.schema === "public" ? name : `${reported.schema}.${name}`;
|
|
620
|
+
}
|
|
621
|
+
const pgEnum = sqlDataType("pg/enum", {
|
|
622
|
+
params: pgEnumParams,
|
|
623
|
+
read: readString("pg/enum"),
|
|
624
|
+
claimsKind: "enum",
|
|
625
|
+
render: ({ typeName }) => {
|
|
626
|
+
const dot = typeName.indexOf(".");
|
|
627
|
+
return dot === -1 ? quoteIdentifier(typeName) : `${quoteIdentifier(typeName.slice(0, dot))}.${quoteIdentifier(typeName.slice(dot + 1))}`;
|
|
628
|
+
},
|
|
629
|
+
fromReported: (reported) => ({ typeName: qualifiedEnumName(reported) })
|
|
630
|
+
});
|
|
631
|
+
const pgInt2 = sqlDataType("pg/int2", {
|
|
632
|
+
texts: [written("int2"), catalog("smallint")],
|
|
633
|
+
read: (json) => readJsonInteger("pg/int2", json, {
|
|
634
|
+
min: -32768,
|
|
635
|
+
max: 32767
|
|
636
|
+
})
|
|
637
|
+
});
|
|
638
|
+
const pgBool = sqlDataType("pg/bool", {
|
|
639
|
+
texts: [written("bool"), catalog("boolean")],
|
|
640
|
+
read: (json) => readJsonBoolean("pg/bool", json)
|
|
641
|
+
});
|
|
642
|
+
const pgJson = namedOnly("pg/json", "json", anyJson);
|
|
643
|
+
const pgTsquery = namedOnly("pg/tsquery", "tsquery", readString("pg/tsquery"));
|
|
644
|
+
const pgInt4 = sqlDataType("pg/int4", {
|
|
645
|
+
texts: [
|
|
646
|
+
written("int4"),
|
|
647
|
+
catalog("integer"),
|
|
648
|
+
claimsOnly("int")
|
|
649
|
+
],
|
|
650
|
+
read: (json) => readJsonInteger("pg/int4", json, INT32_RANGE),
|
|
651
|
+
casts: { [pgInt2.id]: castUnchanged }
|
|
652
|
+
});
|
|
653
|
+
const pgInt8 = sqlDataType("pg/int8", {
|
|
654
|
+
texts: [written("int8"), catalog("bigint")],
|
|
655
|
+
read: (json) => {
|
|
656
|
+
readJsonIntegerText("pg/int8", json, INT64_RANGE);
|
|
657
|
+
return json;
|
|
658
|
+
},
|
|
659
|
+
casts: {
|
|
660
|
+
[pgInt2.id]: asNumeralText,
|
|
661
|
+
[pgInt4.id]: asNumeralText
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
const pgNumeric = sqlDataType("pg/numeric", {
|
|
665
|
+
params: pgNumericParams,
|
|
666
|
+
texts: [
|
|
667
|
+
writtenAndCatalog("numeric"),
|
|
668
|
+
written("numeric({precision})"),
|
|
669
|
+
writtenAndCatalog("numeric({precision},{scale})"),
|
|
670
|
+
claimsOnly("decimal"),
|
|
671
|
+
claimsOnly("decimal({precision})"),
|
|
672
|
+
claimsOnly("decimal({precision},{scale})")
|
|
673
|
+
],
|
|
674
|
+
read: readNumeric,
|
|
675
|
+
spell: spellNumeric,
|
|
676
|
+
equalityKey: decimalTextEqualityKey,
|
|
677
|
+
normalize: (params) => params.precision !== void 0 && params.scale === void 0 ? {
|
|
678
|
+
...params,
|
|
679
|
+
scale: 0
|
|
680
|
+
} : params,
|
|
681
|
+
casts: {
|
|
682
|
+
[pgInt2.id]: asNumeralText,
|
|
683
|
+
[pgInt4.id]: asNumeralText,
|
|
684
|
+
[pgInt8.id]: castUnchanged
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
/** `float4` stores a single-precision float, so a magnitude past about 3.4e38, or one it would round to 0, does not fit. */
|
|
688
|
+
const asFloat4 = (value) => {
|
|
689
|
+
const converted = asFloat(value);
|
|
690
|
+
if (typeof converted !== "number" || fitsFloat4(converted)) return converted;
|
|
691
|
+
throw structuredError("CONTRACT.CAST_REFUSED", `${converted} is out of range: float4 holds a nonzero magnitude from about 1.4e-45 to 3.4e38.`, {
|
|
692
|
+
why: "float4 stores a single-precision float, which overflows past about 3.4e38 and rounds a magnitude below about 1.4e-45 to 0.",
|
|
693
|
+
fix: "Use a number float4 holds, or a float8 or numeric column."
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
const floatCastsOf = (cast) => ({
|
|
697
|
+
[pgInt2.id]: cast,
|
|
698
|
+
[pgInt4.id]: cast,
|
|
699
|
+
[pgInt8.id]: cast,
|
|
700
|
+
[pgNumeric.id]: cast
|
|
701
|
+
});
|
|
702
|
+
const pgFloat4 = sqlDataType("pg/float4", {
|
|
703
|
+
texts: [written("float4"), catalog("real")],
|
|
704
|
+
read: readFloat4,
|
|
705
|
+
casts: floatCastsOf(asFloat4)
|
|
706
|
+
});
|
|
707
|
+
const pgFloat8 = sqlDataType("pg/float8", {
|
|
708
|
+
texts: [
|
|
709
|
+
written("float8"),
|
|
710
|
+
catalog("double precision"),
|
|
711
|
+
claimsOnly("float")
|
|
712
|
+
],
|
|
713
|
+
read: (json) => {
|
|
714
|
+
readJsonFloat("pg/float8", json);
|
|
715
|
+
return json;
|
|
716
|
+
},
|
|
717
|
+
casts: floatCastsOf(asFloat)
|
|
718
|
+
});
|
|
719
|
+
const pgJsonb = namedOnly("pg/jsonb", "jsonb", anyJson, { [pgJson.id]: castUnchanged });
|
|
720
|
+
/** Why no enum can use a codec of `pg/jsonb`, which every such codec gives as its `enumRefusal`. */
|
|
721
|
+
const pgJsonbEnumRefusal = "A CHECK lists a string member as SQL text, which PostgreSQL reads as the JSON text of a document rather than as a string, and a number member as a number, which PostgreSQL cannot compare with jsonb, so no CHECK can compare a value with the members. No enum can use a jsonb codec; use a text enum instead.";
|
|
722
|
+
const fromText = { [pgText.id]: castUnchanged };
|
|
723
|
+
const pgChar = sqlDataType("pg/char", {
|
|
724
|
+
params: pgCharacterLengthParams,
|
|
725
|
+
texts: [
|
|
726
|
+
written("character"),
|
|
727
|
+
writtenAndCatalog("character({length})"),
|
|
728
|
+
claimsOnly("char"),
|
|
729
|
+
claimsOnly("char({length})")
|
|
730
|
+
],
|
|
731
|
+
read: readCharacter,
|
|
732
|
+
spell: spellCharacter,
|
|
733
|
+
normalize: withDefaultLength,
|
|
734
|
+
casts: fromText
|
|
735
|
+
});
|
|
736
|
+
const pgVarchar = sqlDataType("pg/varchar", {
|
|
737
|
+
params: pgCharacterLengthParams,
|
|
738
|
+
texts: [
|
|
739
|
+
writtenAndCatalog("character varying"),
|
|
740
|
+
writtenAndCatalog("character varying({length})"),
|
|
741
|
+
claimsOnly("varchar"),
|
|
742
|
+
claimsOnly("varchar({length})")
|
|
743
|
+
],
|
|
744
|
+
read: readCharacterVarying,
|
|
745
|
+
casts: fromText
|
|
746
|
+
});
|
|
747
|
+
/** Text in any form PostgreSQL reads as a UUID, written the way PostgreSQL writes it, so the contract holds the value the database reports. */
|
|
748
|
+
const asUuid = (value) => {
|
|
749
|
+
if (typeof value !== "string") return refuseWrongShape(value, "text");
|
|
750
|
+
const uuid = storedUuid(value);
|
|
751
|
+
if (uuid !== void 0) return uuid;
|
|
752
|
+
throw structuredError("CONTRACT.CAST_REFUSED", `${JSON.stringify(value)} is not a UUID: PostgreSQL reads 32 hexadecimal digits, with a hyphen after any group of four and optionally in braces.`, {
|
|
753
|
+
why: "A uuid column takes only text PostgreSQL reads as a UUID.",
|
|
754
|
+
fix: "Write a UUID such as a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11."
|
|
755
|
+
});
|
|
756
|
+
};
|
|
757
|
+
const pgUuid = sqlDataType("pg/uuid", {
|
|
758
|
+
texts: [writtenAndCatalog("uuid")],
|
|
759
|
+
read: readUuid,
|
|
760
|
+
spell: spellUuid,
|
|
761
|
+
casts: { [pgText.id]: asUuid }
|
|
762
|
+
});
|
|
763
|
+
const pgBit = sqlDataType("pg/bit", {
|
|
764
|
+
params: pgBitLengthParams,
|
|
765
|
+
texts: [written("bit"), writtenAndCatalog("bit({length})")],
|
|
766
|
+
read: readBit,
|
|
767
|
+
normalize: withDefaultLength,
|
|
768
|
+
casts: fromText
|
|
769
|
+
});
|
|
770
|
+
const pgVarbit = sqlDataType("pg/varbit", {
|
|
771
|
+
params: pgBitLengthParams,
|
|
772
|
+
texts: [
|
|
773
|
+
writtenAndCatalog("bit varying"),
|
|
774
|
+
writtenAndCatalog("bit varying({length})"),
|
|
775
|
+
claimsOnly("varbit"),
|
|
776
|
+
claimsOnly("varbit({length})")
|
|
777
|
+
],
|
|
778
|
+
read: readBitVarying,
|
|
779
|
+
casts: fromText
|
|
780
|
+
});
|
|
781
|
+
const INFINITIES = /* @__PURE__ */ new Set(["infinity", "-infinity"]);
|
|
782
|
+
/**
|
|
783
|
+
* The stored form of a date or time type (ADR 254), from ISO 8601 or the text PostgreSQL prints.
|
|
784
|
+
* `infinity` and `-infinity` are values of the types that hold them.
|
|
785
|
+
*/
|
|
786
|
+
function postgresDateTime(options, holdsInfinity) {
|
|
787
|
+
return (text) => holdsInfinity && INFINITIES.has(text) ? text : dateTimeStoredText(isoYearText(text), options, text);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Each range is what PostgreSQL and every codec of the type hold: PostgreSQL starts at 4714-11-24
|
|
791
|
+
* BC, and the `Temporal` and `Date` codecs end at +275760-09-13.
|
|
792
|
+
*/
|
|
793
|
+
const pgDateStoredText = postgresDateTime({
|
|
794
|
+
shape: "date",
|
|
795
|
+
ownerId: "pg/date",
|
|
796
|
+
range: {
|
|
797
|
+
earliest: "-004713-11-24",
|
|
798
|
+
latest: "+275760-09-13"
|
|
799
|
+
}
|
|
800
|
+
}, true);
|
|
801
|
+
const pgTimeStoredText = postgresDateTime({
|
|
802
|
+
shape: "time",
|
|
803
|
+
ownerId: "pg/time"
|
|
804
|
+
}, false);
|
|
805
|
+
const pgTimetzStoredText = postgresDateTime({
|
|
806
|
+
shape: "timeWithOffset",
|
|
807
|
+
ownerId: "pg/timetz",
|
|
808
|
+
maxOffsetHours: 15
|
|
809
|
+
}, false);
|
|
810
|
+
const pgTimestampStoredText = postgresDateTime({
|
|
811
|
+
shape: "dateTime",
|
|
812
|
+
ownerId: "pg/timestamp",
|
|
813
|
+
range: {
|
|
814
|
+
earliest: "-004713-11-24T00:00:00",
|
|
815
|
+
latest: "+275760-09-13T23:59:59.999999"
|
|
816
|
+
}
|
|
817
|
+
}, true);
|
|
818
|
+
const pgTimestamptzStoredText = postgresDateTime({
|
|
819
|
+
shape: "instant",
|
|
820
|
+
ownerId: "pg/timestamptz",
|
|
821
|
+
range: {
|
|
822
|
+
earliest: "-004713-11-24T00:00:00Z",
|
|
823
|
+
latest: "+275760-09-13T00:00:00Z"
|
|
824
|
+
}
|
|
825
|
+
}, true);
|
|
826
|
+
/** A cast that takes text and gives the value `read` makes of it. */
|
|
827
|
+
const castFromText = (read) => (value) => typeof value === "string" ? read(value) : refuseWrongShape(value, "text");
|
|
828
|
+
const pgTimetz = sqlDataType("pg/timetz", {
|
|
829
|
+
read: readStoredDateTime("pg/timetz", pgTimetzStoredText, "a time of day with its UTC offset, as in \"12:34:56+02:00\" or \"12:34:56Z\"", SECONDS_FRACTION),
|
|
830
|
+
spell: spellStoredDateTime(pgTimetzStoredText),
|
|
831
|
+
params: pgPrecisionParams,
|
|
832
|
+
texts: [
|
|
833
|
+
written("timetz"),
|
|
834
|
+
written("timetz({precision})"),
|
|
835
|
+
catalog("time with time zone"),
|
|
836
|
+
catalog("time({precision}) with time zone")
|
|
837
|
+
]
|
|
838
|
+
});
|
|
839
|
+
const pgInterval = sqlDataType("pg/interval", {
|
|
840
|
+
read: readStoredDateTime("pg/interval", pgIntervalStoredText, "an ISO 8601 duration, as in \"P1Y2M3DT4H5M6.5S\"", INTERVAL_SECONDS_FRACTION),
|
|
841
|
+
spell: spellStoredDateTime(pgIntervalStoredText),
|
|
842
|
+
equalityKey: intervalEqualityKey,
|
|
843
|
+
params: pgPrecisionParams,
|
|
844
|
+
texts: [writtenAndCatalog("interval"), writtenAndCatalog("interval({precision})")]
|
|
845
|
+
});
|
|
846
|
+
const pgBytea = sqlDataType("pg/bytea", {
|
|
847
|
+
read: (json) => readPgByteaJson("pg/bytea", json),
|
|
848
|
+
spell: spellPgByteaJson,
|
|
849
|
+
texts: [writtenAndCatalog("bytea")]
|
|
850
|
+
});
|
|
851
|
+
/** Text PostgreSQL reads as an IP address, written the way PostgreSQL writes it, so the contract holds the value the database reports. */
|
|
852
|
+
function pgInetStoredText(text) {
|
|
853
|
+
const inet = storedInet(text);
|
|
854
|
+
if (inet !== void 0) return inet;
|
|
855
|
+
throw structuredError("CONTRACT.CAST_REFUSED", `${JSON.stringify(text)} is not an IP address: PostgreSQL reads an IPv4 address in decimal octets or an IPv6 address in hexadecimal groups, either optionally followed by / and a prefix length.`, {
|
|
856
|
+
why: "An inet column takes only text PostgreSQL reads as an IP address.",
|
|
857
|
+
fix: "Write an address such as 192.168.0.1 or 2001:db8::1/64."
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
const pgInet = sqlDataType("pg/inet", {
|
|
861
|
+
read: readInet,
|
|
862
|
+
spell: spellInet,
|
|
863
|
+
texts: [writtenAndCatalog("inet")],
|
|
864
|
+
casts: { [pgText.id]: castFromText(pgInetStoredText) }
|
|
865
|
+
});
|
|
866
|
+
const pgDate = sqlDataType("pg/date", {
|
|
867
|
+
read: readStoredDateTime("pg/date", pgDateStoredText, "a date, as in \"2024-01-01\", or infinity or -infinity", SECONDS_FRACTION),
|
|
868
|
+
spell: spellStoredDateTime(pgDateStoredText),
|
|
869
|
+
texts: [writtenAndCatalog("date")]
|
|
870
|
+
});
|
|
871
|
+
const pgTime = sqlDataType("pg/time", {
|
|
872
|
+
read: readStoredDateTime("pg/time", pgTimeStoredText, "a time of day, as in \"12:34:56\"", SECONDS_FRACTION),
|
|
873
|
+
spell: spellStoredDateTime(pgTimeStoredText),
|
|
874
|
+
params: pgPrecisionParams,
|
|
875
|
+
texts: [
|
|
876
|
+
written("time"),
|
|
877
|
+
written("time({precision})"),
|
|
878
|
+
catalog("time without time zone"),
|
|
879
|
+
catalog("time({precision}) without time zone")
|
|
880
|
+
]
|
|
881
|
+
});
|
|
882
|
+
const pgTimestamp = sqlDataType("pg/timestamp", {
|
|
883
|
+
read: readStoredDateTime("pg/timestamp", pgTimestampStoredText, "a date and time of day, as in \"2024-01-01T12:34:56\", or infinity or -infinity", SECONDS_FRACTION),
|
|
884
|
+
spell: spellStoredDateTime(pgTimestampStoredText),
|
|
885
|
+
params: pgPrecisionParams,
|
|
886
|
+
texts: [
|
|
887
|
+
written("timestamp"),
|
|
888
|
+
written("timestamp({precision})"),
|
|
889
|
+
catalog("timestamp without time zone"),
|
|
890
|
+
catalog("timestamp({precision}) without time zone")
|
|
891
|
+
]
|
|
892
|
+
});
|
|
893
|
+
const pgTimestamptz = sqlDataType("pg/timestamptz", {
|
|
894
|
+
read: readStoredDateTime("pg/timestamptz", pgTimestamptzStoredText, "an instant in UTC, as in \"2024-01-01T00:00:00Z\", or infinity or -infinity", SECONDS_FRACTION),
|
|
895
|
+
spell: spellStoredDateTime(pgTimestamptzStoredText),
|
|
896
|
+
params: pgPrecisionParams,
|
|
897
|
+
texts: [
|
|
898
|
+
written("timestamptz"),
|
|
899
|
+
written("timestamptz({precision})"),
|
|
900
|
+
catalog("timestamp with time zone"),
|
|
901
|
+
catalog("timestamp({precision}) with time zone")
|
|
902
|
+
]
|
|
903
|
+
});
|
|
904
|
+
/** Every data type this target registers. */
|
|
905
|
+
const postgresDataTypes = [
|
|
906
|
+
pgText,
|
|
907
|
+
pgTextArray,
|
|
908
|
+
pgEnum,
|
|
909
|
+
pgInt2,
|
|
910
|
+
pgBool,
|
|
911
|
+
pgJson,
|
|
912
|
+
pgTsquery,
|
|
913
|
+
pgInt4,
|
|
914
|
+
pgInt8,
|
|
915
|
+
pgNumeric,
|
|
916
|
+
pgFloat4,
|
|
917
|
+
pgFloat8,
|
|
918
|
+
pgJsonb,
|
|
919
|
+
pgChar,
|
|
920
|
+
pgVarchar,
|
|
921
|
+
pgUuid,
|
|
922
|
+
pgInet,
|
|
923
|
+
pgBit,
|
|
924
|
+
pgVarbit,
|
|
925
|
+
pgTimetz,
|
|
926
|
+
pgInterval,
|
|
927
|
+
pgBytea,
|
|
928
|
+
pgDate,
|
|
929
|
+
pgTime,
|
|
930
|
+
pgTimestamp,
|
|
931
|
+
pgTimestamptz,
|
|
932
|
+
sqlRawDataType
|
|
933
|
+
];
|
|
934
|
+
/** A lookup of the data types this target registers. */
|
|
935
|
+
function createPostgresBuiltinDataTypeLookup() {
|
|
936
|
+
return assembleDataTypes([{
|
|
937
|
+
id: "postgres",
|
|
938
|
+
dataTypes: postgresDataTypes
|
|
939
|
+
}]).lookup;
|
|
940
|
+
}
|
|
941
|
+
/** Postgres's text data types: `text`, `character(n)` and `character varying(n)`. */
|
|
942
|
+
const postgresTextDataTypes = [
|
|
943
|
+
pgText.id,
|
|
944
|
+
pgChar.id,
|
|
945
|
+
pgVarchar.id
|
|
946
|
+
];
|
|
947
|
+
//#endregion
|
|
948
|
+
export { qualifiedEnumName as $, pgJsonb as A, pgTimestampStoredText as B, pgInet as C, pgInterval as D, pgInt8 as E, pgText as F, pgTsquery as G, pgTimestamptzStoredText as H, pgTextArray as I, pgVarchar as J, pgUuid as K, pgTime as L, pgNumeric as M, pgNumericParams as N, pgIntervalStoredText as O, pgPrecisionParams as P, postgresYearText as Q, pgTimeStoredText as R, pgFloat8 as S, pgInt4 as T, pgTimetz as U, pgTimestamptz as V, pgTimetzStoredText as W, postgresIntervalFields as X, postgresDataTypes as Y, postgresTextDataTypes as Z, pgDate as _, formatIsoDuration as a, pgEnumParams as b, microsFromFraction as c, pgBool as d, pgBytea as f, pgCharacterLengthParams as g, pgChar as h, createPostgresBuiltinDataTypeLookup as i, pgJsonbEnumRefusal as j, pgJson as k, pgBit as l, pgByteaHexText as m, ISO_DURATION as n, intervalFieldsOf as o, pgByteaFromHexText as p, pgVarbit as q, MICROS_PER_SECOND as r, isoYearText as s, BYTEA_TEXT as t, pgBitLengthParams as u, pgDateStoredText as v, pgInt2 as w, pgFloat4 as x, pgEnum as y, pgTimestamp as z };
|
|
949
|
+
|
|
950
|
+
//# sourceMappingURL=data-types-Chx0mjTP-DczU4S9b.mjs.map
|