@prisma-next/target-postgres 0.14.0-dev.9 → 0.14.0-dev.90
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/authoring-BtsOWgI3.mjs +674 -0
- package/dist/authoring-BtsOWgI3.mjs.map +1 -0
- package/dist/canonicalize-D1F4vUnP.d.mts +48 -0
- package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-B10ZZHzw.mjs} +4 -2
- package/dist/codec-ids-B10ZZHzw.mjs.map +1 -0
- package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-CI144z7g.d.mts} +4 -2
- package/dist/codec-ids-CI144z7g.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-CTfT4U4O.d.mts} +4 -2
- package/dist/codec-types-CTfT4U4O.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-D7W9O0Xx.d.mts} +134 -4
- package/dist/codecs-D7W9O0Xx.d.mts.map +1 -0
- package/dist/codecs-DRbb26Or.mjs +955 -0
- package/dist/codecs-DRbb26Or.mjs.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +3 -757
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +33 -3
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +23 -7
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control-policy-DtbkLLGv.mjs +1285 -0
- package/dist/control-policy-DtbkLLGv.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +880 -36
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-BOWpliq8.mjs.map +1 -1
- package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-GTTOvjx_.mjs} +128 -6
- package/dist/ddl-GTTOvjx_.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +247 -1
- package/dist/default-normalizer.mjs.map +1 -0
- package/dist/descriptor-meta-CFQKLXl_.mjs +23 -0
- package/dist/descriptor-meta-CFQKLXl_.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/diff-database-schema-GncqMuSI.mjs +305 -0
- package/dist/diff-database-schema-GncqMuSI.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +46 -0
- package/dist/diff-database-schema.d.mts.map +1 -0
- package/dist/diff-database-schema.mjs +2 -0
- package/dist/errors-DO-w0EUS.mjs +35 -0
- package/dist/errors-DO-w0EUS.mjs.map +1 -0
- package/dist/errors.d.mts +11 -9
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/issue-planner.d.mts +35 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -2
- package/dist/migration.d.mts +5 -5
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
- package/dist/native-type-normalizer.mjs +37 -1
- package/dist/native-type-normalizer.mjs.map +1 -0
- package/dist/nodes-DJC5B8Id.mjs +192 -0
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/nodes-Dv5eCSq9.d.mts +170 -0
- package/dist/nodes-Dv5eCSq9.d.mts.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Bn9zDx4_.d.mts} +114 -15
- package/dist/op-factory-call-Bn9zDx4_.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-C38NzvQD.mjs} +469 -32
- package/dist/op-factory-call-C38NzvQD.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +321 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
- package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -6
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
- package/dist/planner-identity-values.d.mts +8 -2
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -2
- package/dist/planner-kql24i_F.mjs +390 -0
- package/dist/planner-kql24i_F.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BEY1T0Xm.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BEY1T0Xm.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-D7y-PEHK.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-D7y-PEHK.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-zqNfs2XZ.mjs} +5 -5
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-zqNfs2XZ.mjs.map} +1 -1
- package/dist/planner-sql-checks.d.mts +2 -2
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
- package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +72 -17
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DM8sN1Ot.mjs} +45 -41
- package/dist/postgres-contract-view-DM8sN1Ot.mjs.map +1 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DbckK1su.d.mts} +58 -9
- package/dist/postgres-migration-DbckK1su.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-arMSWU9b.mjs} +78 -45
- package/dist/postgres-migration-arMSWU9b.mjs.map +1 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs.map +1 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs +190 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-Cm4DtiGA.mjs} +200 -11
- package/dist/postgres-schema-Cm4DtiGA.mjs.map +1 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
- package/dist/render-ops.d.mts +1 -1
- package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
- package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
- package/dist/render-typescript.mjs +1 -1
- package/dist/resolve-ddl-schema-XyBaaenM.mjs +22 -0
- package/dist/resolve-ddl-schema-XyBaaenM.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +27 -0
- package/dist/rls-canonicalize.d.mts.map +1 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +6 -8
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-ir-annotations.d.mts +15 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
- package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
- package/dist/sql-utils.d.mts +8 -1
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -2
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +5 -2
- package/dist/wire-name-DbQ9-2RC.mjs +104 -0
- package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
- package/package.json +26 -20
- package/src/contract-free/checks.ts +153 -0
- package/src/contract-free/control-bootstrap.ts +20 -3
- package/src/contract-free/ddl.ts +98 -1
- package/src/core/authoring.ts +726 -2
- package/src/core/codec-helpers.ts +33 -7
- package/src/core/codec-ids.ts +2 -0
- package/src/core/codec-type-map.ts +4 -0
- package/src/core/codecs.ts +236 -12
- package/src/core/ddl/nodes.ts +185 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +12 -1
- package/src/core/entity-kinds.ts +41 -0
- package/src/core/errors.ts +14 -12
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/column-ddl-rendering.ts +117 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
- package/src/core/migrations/control-policy.ts +217 -65
- package/src/core/migrations/diff-database-schema.ts +252 -0
- package/src/core/migrations/issue-planner.ts +817 -656
- package/src/core/migrations/op-factory-call.ts +383 -23
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/dependencies.ts +2 -1
- package/src/core/migrations/operations/native-enum-types.ts +62 -0
- package/src/core/migrations/operations/rls.ts +187 -0
- package/src/core/migrations/operations/shared.ts +0 -30
- package/src/core/migrations/planner-ddl-builders.ts +31 -59
- package/src/core/migrations/planner-identity-values.ts +1 -1
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner-strategies.ts +248 -216
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +357 -67
- package/src/core/migrations/postgres-migration.ts +118 -86
- package/src/core/migrations/render-typescript.ts +42 -15
- package/src/core/migrations/resolve-ddl-schema.ts +26 -0
- package/src/core/migrations/runner.ts +11 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +46 -71
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-native-enum.ts +61 -0
- package/src/core/postgres-rls-enablement.ts +34 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +59 -0
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/postgres-schema.ts +85 -15
- package/src/core/postgres-validators.ts +34 -0
- package/src/core/psl-infer/infer-psl-contract.ts +1290 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +129 -0
- package/src/core/rls/canonicalize.ts +65 -0
- package/src/core/rls/wire-name.ts +33 -0
- package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
- package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
- package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
- package/src/core/schema-ir/schema-node-kinds.ts +122 -0
- package/src/core/sql-utils.ts +15 -2
- package/src/exports/codecs.ts +5 -0
- package/src/exports/contract-free.ts +11 -1
- package/src/exports/control.ts +27 -33
- package/src/exports/ddl.ts +8 -0
- package/src/exports/diff-database-schema.ts +7 -0
- package/src/exports/issue-planner.ts +1 -1
- package/src/exports/migration.ts +1 -0
- package/src/exports/op-factory-call.ts +4 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner-identity-values.ts +4 -1
- package/src/exports/planner.ts +1 -0
- package/src/exports/rls-canonicalize.ts +12 -0
- package/src/exports/runtime.ts +1 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/sql-utils.ts +1 -0
- package/src/exports/types.ts +37 -0
- package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
- package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
- package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
- package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
- package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
- package/dist/errors-CUk87ByX.mjs +0 -33
- package/dist/errors-CUk87ByX.mjs.map +0 -1
- package/dist/issue-planner-DL6g3CmE.mjs +0 -824
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
- package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
- package/dist/nodes-Bbhs2rwj.mjs +0 -76
- package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
- package/dist/nodes-pLeLgdis.d.mts +0 -67
- package/dist/nodes-pLeLgdis.d.mts.map +0 -1
- package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
- package/dist/planner-Bs_baQax.mjs +0 -324
- package/dist/planner-Bs_baQax.mjs.map +0 -1
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
- package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
- package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
- package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
- package/dist/render-typescript-KMgosran.mjs.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/src/core/postgres-enum-type-schema.ts +0 -17
|
@@ -71,30 +71,32 @@ export const pgNumericRenderOutputType = (typeParams: {
|
|
|
71
71
|
return `Numeric<${precision}, ${scale}>`;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
const
|
|
74
|
+
const ISO_8601_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$/;
|
|
75
|
+
const ISO_8601_TIMESTAMPTZ =
|
|
76
|
+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
76
77
|
|
|
77
|
-
export const pgTimestampEncodeJson = (value: Date): JsonValue => value.toISOString();
|
|
78
|
+
export const pgTimestampEncodeJson = (value: Date): JsonValue => value.toISOString().slice(0, -1);
|
|
78
79
|
export const pgTimestampDecodeJson = (json: JsonValue): Date => {
|
|
79
80
|
if (typeof json !== 'string') {
|
|
80
81
|
throw new Error(`Expected ISO date string for pg/timestamp@1, got ${typeof json}`);
|
|
81
82
|
}
|
|
82
|
-
if (!
|
|
83
|
+
if (!ISO_8601_TIMESTAMP.test(json)) {
|
|
83
84
|
throw new Error(`Invalid ISO date string for pg/timestamp@1: ${json}`);
|
|
84
85
|
}
|
|
85
|
-
const date = new Date(json);
|
|
86
|
+
const date = new Date(`${json}Z`);
|
|
86
87
|
if (Number.isNaN(date.getTime())) {
|
|
87
88
|
throw new Error(`Invalid ISO date string for pg/timestamp@1: ${json}`);
|
|
88
89
|
}
|
|
89
90
|
return date;
|
|
90
91
|
};
|
|
91
92
|
|
|
92
|
-
export const pgTimestamptzEncodeJson = (value: Date): JsonValue =>
|
|
93
|
+
export const pgTimestamptzEncodeJson = (value: Date): JsonValue =>
|
|
94
|
+
value.toISOString().replace(/Z$/, '+00:00');
|
|
93
95
|
export const pgTimestamptzDecodeJson = (json: JsonValue): Date => {
|
|
94
96
|
if (typeof json !== 'string') {
|
|
95
97
|
throw new Error(`Expected ISO date string for pg/timestamptz@1, got ${typeof json}`);
|
|
96
98
|
}
|
|
97
|
-
if (!
|
|
99
|
+
if (!ISO_8601_TIMESTAMPTZ.test(json)) {
|
|
98
100
|
throw new Error(`Invalid ISO date string for pg/timestamptz@1: ${json}`);
|
|
99
101
|
}
|
|
100
102
|
const date = new Date(json);
|
|
@@ -109,6 +111,30 @@ export const pgIntervalDecode = (wire: string | Record<string, unknown>): string
|
|
|
109
111
|
return JSON.stringify(wire);
|
|
110
112
|
};
|
|
111
113
|
|
|
114
|
+
export const pgByteaEncodeJson = (value: Uint8Array): JsonValue =>
|
|
115
|
+
`\\x${Buffer.from(value).toString('hex')}`;
|
|
116
|
+
|
|
117
|
+
export const pgByteaDecodeJson = (value: JsonValue): Uint8Array => {
|
|
118
|
+
if (typeof value !== 'string' || !value.startsWith('\\x')) {
|
|
119
|
+
throw new Error(`Expected Postgres bytea hex text to start with "\\x"`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const hex = value.slice(2);
|
|
123
|
+
if (hex.length % 2 !== 0) {
|
|
124
|
+
throw new Error(`Invalid Postgres bytea hex text length: ${hex.length}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
128
|
+
for (let offset = 0; offset < hex.length; offset += 2) {
|
|
129
|
+
const pair = hex.slice(offset, offset + 2);
|
|
130
|
+
if (!/^[0-9a-fA-F]{2}$/.test(pair)) {
|
|
131
|
+
throw new Error(`Invalid Postgres bytea hex pair "${pair}" at offset ${offset}`);
|
|
132
|
+
}
|
|
133
|
+
bytes[offset / 2] = Number.parseInt(pair, 16);
|
|
134
|
+
}
|
|
135
|
+
return bytes;
|
|
136
|
+
};
|
|
137
|
+
|
|
112
138
|
export const pgJsonEncode = (value: string | JsonValue): string => JSON.stringify(value);
|
|
113
139
|
export const pgJsonDecode = (wire: string | JsonValue): JsonValue =>
|
|
114
140
|
typeof wire === 'string' ? JSON.parse(wire) : wire;
|
package/src/core/codec-ids.ts
CHANGED
|
@@ -8,6 +8,7 @@ export {
|
|
|
8
8
|
} from '@prisma-next/sql-relational-core/ast';
|
|
9
9
|
export const PG_TEXT_CODEC_ID = 'pg/text@1' as const;
|
|
10
10
|
export const PG_TEXT_ARRAY_CODEC_ID = 'pg/text-array@1' as const;
|
|
11
|
+
export const PG_ENUM_CODEC_ID = 'pg/enum@1' as const;
|
|
11
12
|
export const PG_CHAR_CODEC_ID = 'pg/char@1' as const;
|
|
12
13
|
export const PG_VARCHAR_CODEC_ID = 'pg/varchar@1' as const;
|
|
13
14
|
export const PG_INT_CODEC_ID = 'pg/int@1' as const;
|
|
@@ -30,3 +31,4 @@ export const PG_JSON_CODEC_ID = 'pg/json@1' as const;
|
|
|
30
31
|
export const PG_JSONB_CODEC_ID = 'pg/jsonb@1' as const;
|
|
31
32
|
export const PG_BYTEA_CODEC_ID = 'pg/bytea@1' as const;
|
|
32
33
|
export const PG_UUID_CODEC_ID = 'pg/uuid@1' as const;
|
|
34
|
+
export const PG_INET_CODEC_ID = 'pg/inet@1' as const;
|
|
@@ -21,9 +21,11 @@ import {
|
|
|
21
21
|
pgBoolDescriptor,
|
|
22
22
|
pgByteaDescriptor,
|
|
23
23
|
pgCharDescriptor,
|
|
24
|
+
pgEnumDescriptor,
|
|
24
25
|
pgFloat4Descriptor,
|
|
25
26
|
pgFloat8Descriptor,
|
|
26
27
|
pgFloatDescriptor,
|
|
28
|
+
pgInetDescriptor,
|
|
27
29
|
pgInt2Descriptor,
|
|
28
30
|
pgInt4Descriptor,
|
|
29
31
|
pgInt8Descriptor,
|
|
@@ -50,6 +52,7 @@ export const codecDescriptorMap = {
|
|
|
50
52
|
'sql-text': sqlTextDescriptor,
|
|
51
53
|
'sql-timestamp': sqlTimestampDescriptor,
|
|
52
54
|
text: pgTextDescriptor,
|
|
55
|
+
enum: pgEnumDescriptor,
|
|
53
56
|
character: pgCharDescriptor,
|
|
54
57
|
'character varying': pgVarcharDescriptor,
|
|
55
58
|
integer: pgIntDescriptor,
|
|
@@ -69,6 +72,7 @@ export const codecDescriptorMap = {
|
|
|
69
72
|
'bit varying': pgVarbitDescriptor,
|
|
70
73
|
bytea: pgByteaDescriptor,
|
|
71
74
|
uuid: pgUuidDescriptor,
|
|
75
|
+
inet: pgInetDescriptor,
|
|
72
76
|
interval: pgIntervalDescriptor,
|
|
73
77
|
json: pgJsonDescriptor,
|
|
74
78
|
jsonb: pgJsonbDescriptor,
|
package/src/core/codecs.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Each codec ships as three artifacts:
|
|
5
5
|
*
|
|
6
6
|
* 1. A `PgXCodec` class extending {@link CodecImpl} that wraps the module-level encode/decode/encodeJson/decodeJson constants exported from `codec-helpers.ts` (the single source of truth for non-trivial runtime conversions; trivial identity passthroughs are inlined). 2. A `PgXDescriptor` class extending {@link CodecDescriptorImpl} declaring the codec id, traits, target types, params schema, meta, and (where applicable)
|
|
7
|
-
* the emit-path `renderOutputType`. 3. A per-codec column helper (`pgXColumn`) that calls `descriptor.factory(...)` directly and packages the result into a
|
|
7
|
+
* the emit-path `renderOutputType`. 3. A per-codec column helper (`pgXColumn`) that calls `descriptor.factory(...)` directly and packages the result into a framework `ColumnSpec` via the framework {@link column} packager. The helper is tied to its descriptor with `satisfies ColumnHelperFor` (and `ColumnHelperForStrict` where the resolved codec type is well-defined).
|
|
8
8
|
*
|
|
9
9
|
* After TML-2357 this is the canonical source of Postgres codec metadata and runtime behaviour — the legacy `mkCodec` / `defineCodec` carriers (and the parallel `byScalar`/`codecDescriptorDefinitions`/ `codecDescriptorList` collection exports) retired with the deletion sweep.
|
|
10
10
|
*
|
|
@@ -19,11 +19,14 @@ import {
|
|
|
19
19
|
CodecDescriptorImpl,
|
|
20
20
|
CodecImpl,
|
|
21
21
|
type CodecInstanceContext,
|
|
22
|
+
type CodecMeta,
|
|
22
23
|
type ColumnHelperFor,
|
|
23
24
|
type ColumnHelperForStrict,
|
|
24
25
|
column,
|
|
26
|
+
renderTsLiteral,
|
|
25
27
|
voidParamsSchema,
|
|
26
28
|
} from '@prisma-next/framework-components/codec';
|
|
29
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
27
30
|
import {
|
|
28
31
|
SqlCharCodec,
|
|
29
32
|
SqlFloatCodec,
|
|
@@ -40,6 +43,8 @@ import { blindCast } from '@prisma-next/utils/casts';
|
|
|
40
43
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
41
44
|
import { type as arktype } from 'arktype';
|
|
42
45
|
import {
|
|
46
|
+
pgByteaDecodeJson,
|
|
47
|
+
pgByteaEncodeJson,
|
|
43
48
|
pgIntervalDecode,
|
|
44
49
|
pgJsonbDecode,
|
|
45
50
|
pgJsonbEncode,
|
|
@@ -59,9 +64,11 @@ import {
|
|
|
59
64
|
PG_BOOL_CODEC_ID,
|
|
60
65
|
PG_BYTEA_CODEC_ID,
|
|
61
66
|
PG_CHAR_CODEC_ID,
|
|
67
|
+
PG_ENUM_CODEC_ID,
|
|
62
68
|
PG_FLOAT_CODEC_ID,
|
|
63
69
|
PG_FLOAT4_CODEC_ID,
|
|
64
70
|
PG_FLOAT8_CODEC_ID,
|
|
71
|
+
PG_INET_CODEC_ID,
|
|
65
72
|
PG_INT_CODEC_ID,
|
|
66
73
|
PG_INT2_CODEC_ID,
|
|
67
74
|
PG_INT4_CODEC_ID,
|
|
@@ -80,6 +87,8 @@ import {
|
|
|
80
87
|
PG_VARBIT_CODEC_ID,
|
|
81
88
|
PG_VARCHAR_CODEC_ID,
|
|
82
89
|
} from './codec-ids';
|
|
90
|
+
import { DEFAULT_NAMESPACE_ID } from './namespace-ids';
|
|
91
|
+
import { PostgresNativeEnum } from './postgres-native-enum';
|
|
83
92
|
|
|
84
93
|
type LengthParams = { readonly length?: number };
|
|
85
94
|
type PrecisionParams = { readonly precision?: number };
|
|
@@ -148,6 +157,9 @@ export class PgTextDescriptor extends CodecDescriptorImpl<void> {
|
|
|
148
157
|
override readonly targetTypes = ['text'] as const;
|
|
149
158
|
override readonly meta = PG_TEXT_META;
|
|
150
159
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
160
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
161
|
+
return renderTsLiteral(value);
|
|
162
|
+
}
|
|
151
163
|
override factory(): (ctx: CodecInstanceContext) => PgTextCodec {
|
|
152
164
|
return () => new PgTextCodec(this);
|
|
153
165
|
}
|
|
@@ -161,6 +173,145 @@ export const pgTextColumn = () =>
|
|
|
161
173
|
pgTextColumn satisfies ColumnHelperFor<PgTextDescriptor>;
|
|
162
174
|
pgTextColumn satisfies ColumnHelperForStrict<PgTextDescriptor>;
|
|
163
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Codec for a `pg.enum(Ref)` column bound to a native Postgres enum type.
|
|
178
|
+
* Text passthrough, identical to `pg/text@1` — encode/decode do not carry the
|
|
179
|
+
* enum's member values; membership is enforced by the native type itself, not
|
|
180
|
+
* by this codec. `renderValueLiteral` renders a member value as its TS
|
|
181
|
+
* literal, which is what drives the column's typed value-union (via
|
|
182
|
+
* `renderValueSetType` reading the column's `valueSet` ref) — the codec
|
|
183
|
+
* itself carries no params of its own; typing comes entirely from the
|
|
184
|
+
* column's value-set, not from `pg/enum@1`.
|
|
185
|
+
*
|
|
186
|
+
* A distinct codec id (rather than reusing `pg/text@1` on a plain text
|
|
187
|
+
* column) keeps native-enum columns independently identifiable — from a
|
|
188
|
+
* column's `codecId` alone, without also inspecting `nativeType` — which
|
|
189
|
+
* the managed (DDL) phase needs to target `CREATE TYPE`/`ALTER TYPE`
|
|
190
|
+
* operations at exactly the columns that use one.
|
|
191
|
+
*/
|
|
192
|
+
export class PgEnumCodec extends CodecImpl<
|
|
193
|
+
typeof PG_ENUM_CODEC_ID,
|
|
194
|
+
readonly ['equality', 'order', 'textual'],
|
|
195
|
+
string,
|
|
196
|
+
string
|
|
197
|
+
> {
|
|
198
|
+
async encode(value: string, _ctx: CodecCallContext): Promise<string> {
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
async decode(wire: string, _ctx: CodecCallContext): Promise<string> {
|
|
202
|
+
return wire;
|
|
203
|
+
}
|
|
204
|
+
encodeJson(value: string): JsonValue {
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
decodeJson(json: JsonValue): string {
|
|
208
|
+
return blindCast<
|
|
209
|
+
string,
|
|
210
|
+
'text codec: a native-enum member value is stored as its wire string form'
|
|
211
|
+
>(json);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
type PgEnumParams = { readonly typeName: string };
|
|
216
|
+
|
|
217
|
+
const pgEnumParamsSchema = arktype({
|
|
218
|
+
typeName: 'string',
|
|
219
|
+
}) satisfies StandardSchemaV1<PgEnumParams>;
|
|
220
|
+
|
|
221
|
+
function isJsonObject(
|
|
222
|
+
value: JsonValue | undefined,
|
|
223
|
+
): value is { readonly [key: string]: JsonValue } {
|
|
224
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export class PgEnumDescriptor extends CodecDescriptorImpl<PgEnumParams> {
|
|
228
|
+
override readonly codecId = PG_ENUM_CODEC_ID;
|
|
229
|
+
override readonly traits = ['equality', 'order', 'textual'] as const;
|
|
230
|
+
override readonly targetTypes = ['text'] as const;
|
|
231
|
+
override readonly meta = PG_TEXT_META;
|
|
232
|
+
override readonly paramsSchema = pgEnumParamsSchema satisfies StandardSchemaV1<PgEnumParams>;
|
|
233
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
234
|
+
return renderTsLiteral(value);
|
|
235
|
+
}
|
|
236
|
+
override metaFor(typeParams: JsonValue | undefined): CodecMeta | undefined {
|
|
237
|
+
if (!isJsonObject(typeParams)) return this.meta;
|
|
238
|
+
const typeName = typeParams['typeName'];
|
|
239
|
+
return typeof typeName === 'string'
|
|
240
|
+
? { db: { sql: { postgres: { nativeType: typeName } } } }
|
|
241
|
+
: this.meta;
|
|
242
|
+
}
|
|
243
|
+
override factory(_params: PgEnumParams): (ctx: CodecInstanceContext) => PgEnumCodec {
|
|
244
|
+
return () => new PgEnumCodec(this);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Authoring-time hook a `pg.enum(<ref>)` type constructor calls once it has
|
|
249
|
+
* resolved its ref argument to the referenced `native_enum` entity:
|
|
250
|
+
* produces this codec's per-column `typeParams` and native type from the
|
|
251
|
+
* entity's bare type name. Schema-qualification (`auth.aal_level` for a
|
|
252
|
+
* named non-default schema) is not this hook's concern — the field's
|
|
253
|
+
* namespace isn't known at this call site for every authoring path (the TS
|
|
254
|
+
* builder resolves a column before it knows its model's namespace), so it is
|
|
255
|
+
* applied later, at contract construction, by {@link qualifyNativeType} via
|
|
256
|
+
* the target's `authoring.qualifyColumnType` hook. `nativeType` mirrors
|
|
257
|
+
* `typeParams.typeName` — the same value {@link metaFor} derives at render
|
|
258
|
+
* time — so the column's declared native type and the render-time cast
|
|
259
|
+
* agree. Returns `undefined` if `entity` is not a `PostgresNativeEnum` (a
|
|
260
|
+
* contributor bug, not a user-schema error — the caller decides how to
|
|
261
|
+
* report it).
|
|
262
|
+
*/
|
|
263
|
+
columnFromEntity(
|
|
264
|
+
entity: object,
|
|
265
|
+
): { readonly typeParams: PgEnumParams; readonly nativeType: string } | undefined {
|
|
266
|
+
if (!PostgresNativeEnum.is(entity)) return undefined;
|
|
267
|
+
return { typeParams: { typeName: entity.typeName }, nativeType: entity.typeName };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Schema-qualifies this native enum type's name for the namespace the
|
|
272
|
+
* consuming column lives in: `${namespaceId}.${typeName}` for a named
|
|
273
|
+
* non-default schema, bare for the target's default schema (`public`) or
|
|
274
|
+
* the late-bound unbound sentinel (whose schema `search_path` resolves at
|
|
275
|
+
* runtime). Postgres's `format_type()` reports the bare name for a
|
|
276
|
+
* public-schema type, so a public column's declared native type must stay
|
|
277
|
+
* bare to match. Owned here because the codec owns its native type.
|
|
278
|
+
*/
|
|
279
|
+
qualifyNativeType(typeName: string, namespaceId: string): string {
|
|
280
|
+
return namespaceId === DEFAULT_NAMESPACE_ID || namespaceId === UNBOUND_NAMESPACE_ID
|
|
281
|
+
? typeName
|
|
282
|
+
: `${namespaceId}.${typeName}`;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export const pgEnumDescriptor = new PgEnumDescriptor();
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Contract-construction-time column-type qualifier the Postgres target
|
|
290
|
+
* contributes through `authoring.qualifyColumnType`.
|
|
291
|
+
* `buildSqlContractFromDefinition` calls this for every column as it is
|
|
292
|
+
* constructed, passing the column's bare type info and its owning
|
|
293
|
+
* `namespaceId`; a native-enum column (`pg/enum@1`) gets its type name
|
|
294
|
+
* schema-qualified for that namespace (via
|
|
295
|
+
* {@link PgEnumDescriptor.qualifyNativeType}), keeping `nativeType` and
|
|
296
|
+
* `typeParams.typeName` in sync. Every other codec passes through unchanged.
|
|
297
|
+
* Both the PSL `pg.enum(Ref)` path and the TS `pg.enum(handle)` path route
|
|
298
|
+
* through here — the dispatch keys off the codec id, not authoring surface.
|
|
299
|
+
*/
|
|
300
|
+
export function postgresQualifyColumnType(
|
|
301
|
+
input: {
|
|
302
|
+
readonly codecId: string;
|
|
303
|
+
readonly nativeType: string;
|
|
304
|
+
readonly typeParams?: Record<string, unknown>;
|
|
305
|
+
},
|
|
306
|
+
namespaceId: string,
|
|
307
|
+
): { readonly nativeType: string; readonly typeParams?: Record<string, unknown> } {
|
|
308
|
+
if (input.codecId !== PG_ENUM_CODEC_ID) return input;
|
|
309
|
+
const bareTypeName = input.typeParams?.['typeName'];
|
|
310
|
+
if (typeof bareTypeName !== 'string') return input;
|
|
311
|
+
const qualified = pgEnumDescriptor.qualifyNativeType(bareTypeName, namespaceId);
|
|
312
|
+
return { nativeType: qualified, typeParams: { ...input.typeParams, typeName: qualified } };
|
|
313
|
+
}
|
|
314
|
+
|
|
164
315
|
/**
|
|
165
316
|
* Postgres `text[]` codec. Encode is an identity pass-through: the pg wire
|
|
166
317
|
* driver serialises a JS `string[]` to a Postgres array literal under the
|
|
@@ -228,6 +379,9 @@ export class PgInt4Descriptor extends CodecDescriptorImpl<void> {
|
|
|
228
379
|
override readonly targetTypes = ['int4'] as const;
|
|
229
380
|
override readonly meta = PG_INT4_META;
|
|
230
381
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
382
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
383
|
+
return renderTsLiteral(value);
|
|
384
|
+
}
|
|
231
385
|
override factory(): (ctx: CodecInstanceContext) => PgInt4Codec {
|
|
232
386
|
return () => new PgInt4Codec(this);
|
|
233
387
|
}
|
|
@@ -267,6 +421,9 @@ export class PgInt2Descriptor extends CodecDescriptorImpl<void> {
|
|
|
267
421
|
override readonly targetTypes = ['int2'] as const;
|
|
268
422
|
override readonly meta = PG_INT2_META;
|
|
269
423
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
424
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
425
|
+
return renderTsLiteral(value);
|
|
426
|
+
}
|
|
270
427
|
override factory(): (ctx: CodecInstanceContext) => PgInt2Codec {
|
|
271
428
|
return () => new PgInt2Codec(this);
|
|
272
429
|
}
|
|
@@ -306,6 +463,9 @@ export class PgInt8Descriptor extends CodecDescriptorImpl<void> {
|
|
|
306
463
|
override readonly targetTypes = ['int8'] as const;
|
|
307
464
|
override readonly meta = PG_INT8_META;
|
|
308
465
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
466
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
467
|
+
return renderTsLiteral(value);
|
|
468
|
+
}
|
|
309
469
|
override factory(): (ctx: CodecInstanceContext) => PgInt8Codec {
|
|
310
470
|
return () => new PgInt8Codec(this);
|
|
311
471
|
}
|
|
@@ -345,6 +505,9 @@ export class PgFloat4Descriptor extends CodecDescriptorImpl<void> {
|
|
|
345
505
|
override readonly targetTypes = ['float4'] as const;
|
|
346
506
|
override readonly meta = PG_FLOAT4_META;
|
|
347
507
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
508
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
509
|
+
return renderTsLiteral(value);
|
|
510
|
+
}
|
|
348
511
|
override factory(): (ctx: CodecInstanceContext) => PgFloat4Codec {
|
|
349
512
|
return () => new PgFloat4Codec(this);
|
|
350
513
|
}
|
|
@@ -384,6 +547,9 @@ export class PgFloat8Descriptor extends CodecDescriptorImpl<void> {
|
|
|
384
547
|
override readonly targetTypes = ['float8'] as const;
|
|
385
548
|
override readonly meta = PG_FLOAT8_META;
|
|
386
549
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
550
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
551
|
+
return renderTsLiteral(value);
|
|
552
|
+
}
|
|
387
553
|
override factory(): (ctx: CodecInstanceContext) => PgFloat8Codec {
|
|
388
554
|
return () => new PgFloat8Codec(this);
|
|
389
555
|
}
|
|
@@ -423,6 +589,9 @@ export class PgBoolDescriptor extends CodecDescriptorImpl<void> {
|
|
|
423
589
|
override readonly targetTypes = ['bool'] as const;
|
|
424
590
|
override readonly meta = PG_BOOL_META;
|
|
425
591
|
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
592
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
593
|
+
return renderTsLiteral(value);
|
|
594
|
+
}
|
|
426
595
|
override factory(): (ctx: CodecInstanceContext) => PgBoolCodec {
|
|
427
596
|
return () => new PgBoolCodec(this);
|
|
428
597
|
}
|
|
@@ -449,10 +618,17 @@ export class PgNumericCodec extends CodecImpl<
|
|
|
449
618
|
return pgNumericDecode(wire);
|
|
450
619
|
}
|
|
451
620
|
encodeJson(value: string): JsonValue {
|
|
452
|
-
|
|
621
|
+
const number = Number(value);
|
|
622
|
+
if (!Number.isFinite(number)) {
|
|
623
|
+
throw new TypeError('pg/numeric@1 database JSON value must be a finite number');
|
|
624
|
+
}
|
|
625
|
+
return number;
|
|
453
626
|
}
|
|
454
627
|
decodeJson(json: JsonValue): string {
|
|
455
|
-
|
|
628
|
+
if (typeof json !== 'number') {
|
|
629
|
+
throw new TypeError('pg/numeric@1 database JSON value must be a number');
|
|
630
|
+
}
|
|
631
|
+
return pgNumericDecode(json);
|
|
456
632
|
}
|
|
457
633
|
}
|
|
458
634
|
|
|
@@ -755,17 +931,10 @@ export class PgByteaCodec extends CodecImpl<
|
|
|
755
931
|
: new Uint8Array(wire.buffer, wire.byteOffset, wire.byteLength);
|
|
756
932
|
}
|
|
757
933
|
encodeJson(value: Uint8Array): JsonValue {
|
|
758
|
-
return
|
|
934
|
+
return pgByteaEncodeJson(value);
|
|
759
935
|
}
|
|
760
936
|
decodeJson(json: JsonValue): Uint8Array {
|
|
761
|
-
|
|
762
|
-
throw new Error(`Expected base64 string for pg/bytea@1, got ${typeof json}`);
|
|
763
|
-
}
|
|
764
|
-
const decoded = Buffer.from(json, 'base64');
|
|
765
|
-
if (decoded.toString('base64') !== json) {
|
|
766
|
-
throw new Error(`Invalid base64 string for pg/bytea@1 (length: ${json.length})`);
|
|
767
|
-
}
|
|
768
|
-
return new Uint8Array(decoded);
|
|
937
|
+
return pgByteaDecodeJson(json);
|
|
769
938
|
}
|
|
770
939
|
}
|
|
771
940
|
|
|
@@ -829,6 +998,47 @@ export const pgUuidColumn = () =>
|
|
|
829
998
|
pgUuidColumn satisfies ColumnHelperFor<PgUuidDescriptor>;
|
|
830
999
|
pgUuidColumn satisfies ColumnHelperForStrict<PgUuidDescriptor>;
|
|
831
1000
|
|
|
1001
|
+
const PG_INET_META = { db: { sql: { postgres: { nativeType: 'inet' } } } } as const;
|
|
1002
|
+
|
|
1003
|
+
export class PgInetCodec extends CodecImpl<
|
|
1004
|
+
typeof PG_INET_CODEC_ID,
|
|
1005
|
+
readonly ['equality', 'order'],
|
|
1006
|
+
string,
|
|
1007
|
+
string
|
|
1008
|
+
> {
|
|
1009
|
+
async encode(value: string, _ctx: CodecCallContext): Promise<string> {
|
|
1010
|
+
return value;
|
|
1011
|
+
}
|
|
1012
|
+
async decode(wire: string, _ctx: CodecCallContext): Promise<string> {
|
|
1013
|
+
return wire;
|
|
1014
|
+
}
|
|
1015
|
+
encodeJson(value: string): JsonValue {
|
|
1016
|
+
return value;
|
|
1017
|
+
}
|
|
1018
|
+
decodeJson(json: JsonValue): string {
|
|
1019
|
+
return blindCast<string, 'inet columns serialize to JSON as their wire string form'>(json);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
export class PgInetDescriptor extends CodecDescriptorImpl<void> {
|
|
1024
|
+
override readonly codecId = PG_INET_CODEC_ID;
|
|
1025
|
+
override readonly traits = ['equality', 'order'] as const;
|
|
1026
|
+
override readonly targetTypes = ['inet'] as const;
|
|
1027
|
+
override readonly meta = PG_INET_META;
|
|
1028
|
+
override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
|
|
1029
|
+
override factory(): (ctx: CodecInstanceContext) => PgInetCodec {
|
|
1030
|
+
return () => new PgInetCodec(this);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
export const pgInetDescriptor = new PgInetDescriptor();
|
|
1035
|
+
|
|
1036
|
+
export const pgInetColumn = () =>
|
|
1037
|
+
column(pgInetDescriptor.factory(), pgInetDescriptor.codecId, undefined, 'inet');
|
|
1038
|
+
|
|
1039
|
+
pgInetColumn satisfies ColumnHelperFor<PgInetDescriptor>;
|
|
1040
|
+
pgInetColumn satisfies ColumnHelperForStrict<PgInetDescriptor>;
|
|
1041
|
+
|
|
832
1042
|
export class PgIntervalCodec extends CodecImpl<
|
|
833
1043
|
typeof PG_INTERVAL_CODEC_ID,
|
|
834
1044
|
readonly ['equality', 'order'],
|
|
@@ -968,6 +1178,9 @@ export class PgCharDescriptor extends CodecDescriptorImpl<LengthParams> {
|
|
|
968
1178
|
override renderOutputType(params: LengthParams): string | undefined {
|
|
969
1179
|
return sqlCharDescriptor.renderOutputType(params);
|
|
970
1180
|
}
|
|
1181
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
1182
|
+
return renderTsLiteral(value);
|
|
1183
|
+
}
|
|
971
1184
|
override factory(_params: LengthParams): (ctx: CodecInstanceContext) => SqlCharCodec {
|
|
972
1185
|
return () => new SqlCharCodec(this);
|
|
973
1186
|
}
|
|
@@ -989,6 +1202,9 @@ export class PgVarcharDescriptor extends CodecDescriptorImpl<LengthParams> {
|
|
|
989
1202
|
override renderOutputType(params: LengthParams): string | undefined {
|
|
990
1203
|
return sqlVarcharDescriptor.renderOutputType(params);
|
|
991
1204
|
}
|
|
1205
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
1206
|
+
return renderTsLiteral(value);
|
|
1207
|
+
}
|
|
992
1208
|
override factory(_params: LengthParams): (ctx: CodecInstanceContext) => SqlVarcharCodec {
|
|
993
1209
|
return () => new SqlVarcharCodec(this);
|
|
994
1210
|
}
|
|
@@ -1012,6 +1228,9 @@ export class PgIntDescriptor extends CodecDescriptorImpl<void> {
|
|
|
1012
1228
|
override readonly meta = PG_INT_META;
|
|
1013
1229
|
override readonly traits = sqlIntDescriptor.traits;
|
|
1014
1230
|
override readonly paramsSchema = sqlIntDescriptor.paramsSchema;
|
|
1231
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
1232
|
+
return renderTsLiteral(value);
|
|
1233
|
+
}
|
|
1015
1234
|
override factory(): (ctx: CodecInstanceContext) => SqlIntCodec {
|
|
1016
1235
|
return () => new SqlIntCodec(this);
|
|
1017
1236
|
}
|
|
@@ -1030,6 +1249,9 @@ export class PgFloatDescriptor extends CodecDescriptorImpl<void> {
|
|
|
1030
1249
|
override readonly meta = PG_FLOAT_META;
|
|
1031
1250
|
override readonly traits = sqlFloatDescriptor.traits;
|
|
1032
1251
|
override readonly paramsSchema = sqlFloatDescriptor.paramsSchema;
|
|
1252
|
+
override renderValueLiteral(value: JsonValue): string | undefined {
|
|
1253
|
+
return renderTsLiteral(value);
|
|
1254
|
+
}
|
|
1033
1255
|
override factory(): (ctx: CodecInstanceContext) => SqlFloatCodec {
|
|
1034
1256
|
return () => new SqlFloatCodec(this);
|
|
1035
1257
|
}
|
|
@@ -1052,6 +1274,7 @@ export const codecDescriptors: readonly AnyCodecDescriptor[] = [
|
|
|
1052
1274
|
sqlTextDescriptor,
|
|
1053
1275
|
sqlTimestampDescriptor,
|
|
1054
1276
|
pgTextDescriptor,
|
|
1277
|
+
pgEnumDescriptor,
|
|
1055
1278
|
pgCharDescriptor,
|
|
1056
1279
|
pgVarcharDescriptor,
|
|
1057
1280
|
pgIntDescriptor,
|
|
@@ -1071,6 +1294,7 @@ export const codecDescriptors: readonly AnyCodecDescriptor[] = [
|
|
|
1071
1294
|
pgVarbitDescriptor,
|
|
1072
1295
|
pgByteaDescriptor,
|
|
1073
1296
|
pgUuidDescriptor,
|
|
1297
|
+
pgInetDescriptor,
|
|
1074
1298
|
pgIntervalDescriptor,
|
|
1075
1299
|
pgJsonDescriptor,
|
|
1076
1300
|
pgJsonbDescriptor,
|