@prisma-next/adapter-postgres 0.4.1 → 0.5.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-hNElNHo4.mjs +60 -0
- package/dist/adapter-hNElNHo4.mjs.map +1 -0
- package/dist/adapter.d.mts +2 -8
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/column-types.mjs +1 -1
- package/dist/column-types.mjs.map +1 -1
- package/dist/control.d.mts +3 -70
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +19 -160
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-BB9XPAFi.mjs → descriptor-meta-RTDzyrae.mjs} +7 -7
- package/dist/descriptor-meta-RTDzyrae.mjs.map +1 -0
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +7 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/{adapter-Du9Hr9Rl.mjs → sql-renderer-pEaSP82_.mjs} +102 -100
- package/dist/sql-renderer-pEaSP82_.mjs.map +1 -0
- package/dist/{types-TyL62f9Y.d.mts → types-CfRPdAk8.d.mts} +1 -1
- package/dist/{types-TyL62f9Y.d.mts.map → types-CfRPdAk8.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +21 -16
- package/src/core/adapter.ts +4 -625
- package/src/core/control-adapter.ts +21 -47
- package/src/core/descriptor-meta.ts +5 -5
- package/src/core/enum-control-hooks.ts +7 -2
- package/src/core/json-schema-validator.ts +2 -1
- package/src/core/sql-renderer.ts +710 -0
- package/src/exports/column-types.ts +1 -1
- package/src/exports/control.ts +9 -4
- package/src/exports/runtime.ts +3 -3
- package/dist/adapter-Du9Hr9Rl.mjs.map +0 -1
- package/dist/codec-ids-5g4Gwrgm.mjs +0 -29
- package/dist/codec-ids-5g4Gwrgm.mjs.map +0 -1
- package/dist/codec-types.d.mts +0 -107
- package/dist/codec-types.d.mts.map +0 -1
- package/dist/codec-types.mjs +0 -3
- package/dist/codecs-DiPlMi3-.mjs +0 -385
- package/dist/codecs-DiPlMi3-.mjs.map +0 -1
- package/dist/descriptor-meta-BB9XPAFi.mjs.map +0 -1
- package/dist/sql-utils-DkUJyZmA.mjs +0 -78
- package/dist/sql-utils-DkUJyZmA.mjs.map +0 -1
- package/src/core/codec-ids.ts +0 -30
- package/src/core/codecs.ts +0 -645
- package/src/core/default-normalizer.ts +0 -145
- package/src/core/json-schema-type-expression.ts +0 -131
- package/src/core/sql-utils.ts +0 -111
- package/src/exports/codec-types.ts +0 -44
package/dist/codecs-DiPlMi3-.mjs
DELETED
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
import { S as PG_VARCHAR_CODEC_ID, _ as PG_TIMESTAMPTZ_CODEC_ID, a as PG_FLOAT4_CODEC_ID, b as PG_TIME_CODEC_ID, c as PG_INT2_CODEC_ID, d as PG_INTERVAL_CODEC_ID, f as PG_INT_CODEC_ID, g as PG_TEXT_CODEC_ID, h as PG_NUMERIC_CODEC_ID, i as PG_ENUM_CODEC_ID, l as PG_INT4_CODEC_ID, m as PG_JSON_CODEC_ID, n as PG_BOOL_CODEC_ID, o as PG_FLOAT8_CODEC_ID, p as PG_JSONB_CODEC_ID, r as PG_CHAR_CODEC_ID, s as PG_FLOAT_CODEC_ID, t as PG_BIT_CODEC_ID, u as PG_INT8_CODEC_ID, v as PG_TIMESTAMP_CODEC_ID, x as PG_VARBIT_CODEC_ID, y as PG_TIMETZ_CODEC_ID } from "./codec-ids-5g4Gwrgm.mjs";
|
|
2
|
-
import { codec, defineCodecs, sqlCodecDefinitions } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
-
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
|
-
import { type } from "arktype";
|
|
5
|
-
|
|
6
|
-
//#region src/core/json-schema-type-expression.ts
|
|
7
|
-
const MAX_DEPTH = 32;
|
|
8
|
-
function isRecord(value) {
|
|
9
|
-
return typeof value === "object" && value !== null;
|
|
10
|
-
}
|
|
11
|
-
function escapeStringLiteral(str) {
|
|
12
|
-
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
13
|
-
}
|
|
14
|
-
function quotePropertyKey(key) {
|
|
15
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : `'${escapeStringLiteral(key)}'`;
|
|
16
|
-
}
|
|
17
|
-
function renderLiteral(value) {
|
|
18
|
-
if (typeof value === "string") return `'${escapeStringLiteral(value)}'`;
|
|
19
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
20
|
-
if (value === null) return "null";
|
|
21
|
-
return "unknown";
|
|
22
|
-
}
|
|
23
|
-
function renderUnion(items, depth) {
|
|
24
|
-
return items.map((item) => render(item, depth)).join(" | ");
|
|
25
|
-
}
|
|
26
|
-
function renderObjectType(schema, depth) {
|
|
27
|
-
const properties = isRecord(schema["properties"]) ? schema["properties"] : {};
|
|
28
|
-
const required = Array.isArray(schema["required"]) ? new Set(schema["required"].filter((key) => typeof key === "string")) : /* @__PURE__ */ new Set();
|
|
29
|
-
const keys = Object.keys(properties).sort((left, right) => left.localeCompare(right));
|
|
30
|
-
if (keys.length === 0) {
|
|
31
|
-
const additionalProperties = schema["additionalProperties"];
|
|
32
|
-
if (additionalProperties === true || additionalProperties === void 0) return "Record<string, unknown>";
|
|
33
|
-
return `Record<string, ${render(additionalProperties, depth)}>`;
|
|
34
|
-
}
|
|
35
|
-
return `{ ${keys.map((key) => {
|
|
36
|
-
const valueSchema = properties[key];
|
|
37
|
-
const optionalMarker = required.has(key) ? "" : "?";
|
|
38
|
-
return `${quotePropertyKey(key)}${optionalMarker}: ${render(valueSchema, depth)}`;
|
|
39
|
-
}).join("; ")} }`;
|
|
40
|
-
}
|
|
41
|
-
function renderArrayType(schema, depth) {
|
|
42
|
-
if (Array.isArray(schema["items"])) return `readonly [${schema["items"].map((item) => render(item, depth)).join(", ")}]`;
|
|
43
|
-
if (schema["items"] !== void 0) {
|
|
44
|
-
const itemType = render(schema["items"], depth);
|
|
45
|
-
return itemType.includes(" | ") || itemType.includes(" & ") ? `(${itemType})[]` : `${itemType}[]`;
|
|
46
|
-
}
|
|
47
|
-
return "unknown[]";
|
|
48
|
-
}
|
|
49
|
-
function render(schema, depth) {
|
|
50
|
-
if (depth > MAX_DEPTH || !isRecord(schema)) return "JsonValue";
|
|
51
|
-
const nextDepth = depth + 1;
|
|
52
|
-
if ("const" in schema) return renderLiteral(schema["const"]);
|
|
53
|
-
if (Array.isArray(schema["enum"])) return schema["enum"].map((value) => renderLiteral(value)).join(" | ");
|
|
54
|
-
if (Array.isArray(schema["oneOf"])) return renderUnion(schema["oneOf"], nextDepth);
|
|
55
|
-
if (Array.isArray(schema["anyOf"])) return renderUnion(schema["anyOf"], nextDepth);
|
|
56
|
-
if (Array.isArray(schema["allOf"])) return schema["allOf"].map((item) => render(item, nextDepth)).join(" & ");
|
|
57
|
-
if (Array.isArray(schema["type"])) return schema["type"].map((item) => render({
|
|
58
|
-
...schema,
|
|
59
|
-
type: item
|
|
60
|
-
}, nextDepth)).join(" | ");
|
|
61
|
-
switch (schema["type"]) {
|
|
62
|
-
case "string": return "string";
|
|
63
|
-
case "number":
|
|
64
|
-
case "integer": return "number";
|
|
65
|
-
case "boolean": return "boolean";
|
|
66
|
-
case "null": return "null";
|
|
67
|
-
case "array": return renderArrayType(schema, nextDepth);
|
|
68
|
-
case "object": return renderObjectType(schema, nextDepth);
|
|
69
|
-
default: break;
|
|
70
|
-
}
|
|
71
|
-
return "JsonValue";
|
|
72
|
-
}
|
|
73
|
-
function renderTypeScriptTypeFromJsonSchema(schema) {
|
|
74
|
-
return render(schema, 0);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/core/codecs.ts
|
|
79
|
-
const lengthParamsSchema = type({ length: "number.integer > 0" });
|
|
80
|
-
const numericParamsSchema = type({
|
|
81
|
-
precision: "number.integer > 0 & number.integer <= 1000",
|
|
82
|
-
"scale?": "number.integer >= 0"
|
|
83
|
-
});
|
|
84
|
-
const precisionParamsSchema = type({ "precision?": "number.integer >= 0 & number.integer <= 6" });
|
|
85
|
-
function renderLength(typeName, typeParams) {
|
|
86
|
-
const length = typeParams["length"];
|
|
87
|
-
if (length === void 0) return;
|
|
88
|
-
if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected integer "length" in typeParams for ${typeName}, got ${String(length)}`);
|
|
89
|
-
return `${typeName}<${length}>`;
|
|
90
|
-
}
|
|
91
|
-
function renderPrecision(typeName, typeParams) {
|
|
92
|
-
const precision = typeParams["precision"];
|
|
93
|
-
if (precision === void 0) return typeName;
|
|
94
|
-
if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw new Error(`renderOutputType: expected integer "precision" in typeParams for ${typeName}, got ${String(precision)}`);
|
|
95
|
-
return `${typeName}<${precision}>`;
|
|
96
|
-
}
|
|
97
|
-
function renderJsonOutputType(typeParams) {
|
|
98
|
-
const typeName = typeParams["type"];
|
|
99
|
-
if (typeof typeName === "string" && typeName.trim().length > 0) return typeName.trim();
|
|
100
|
-
const schema = typeParams["schemaJson"];
|
|
101
|
-
if (schema && typeof schema === "object") return renderTypeScriptTypeFromJsonSchema(schema);
|
|
102
|
-
throw new Error(`renderOutputType: JSON codec typeParams must contain "type" (string) or "schemaJson" (object), got keys: ${Object.keys(typeParams).join(", ")}`);
|
|
103
|
-
}
|
|
104
|
-
function aliasCodec(base, options) {
|
|
105
|
-
return {
|
|
106
|
-
id: options.typeId,
|
|
107
|
-
targetTypes: options.targetTypes,
|
|
108
|
-
...ifDefined("meta", options.meta),
|
|
109
|
-
...ifDefined("paramsSchema", base.paramsSchema),
|
|
110
|
-
...ifDefined("init", base.init),
|
|
111
|
-
...ifDefined("encode", base.encode),
|
|
112
|
-
...ifDefined("traits", base.traits),
|
|
113
|
-
...ifDefined("renderOutputType", base.renderOutputType),
|
|
114
|
-
decode: base.decode,
|
|
115
|
-
encodeJson: base.encodeJson,
|
|
116
|
-
decodeJson: base.decodeJson
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
const sqlCharCodec = sqlCodecDefinitions.char.codec;
|
|
120
|
-
const sqlVarcharCodec = sqlCodecDefinitions.varchar.codec;
|
|
121
|
-
const sqlIntCodec = sqlCodecDefinitions.int.codec;
|
|
122
|
-
const sqlFloatCodec = sqlCodecDefinitions.float.codec;
|
|
123
|
-
const sqlTextCodec = sqlCodecDefinitions.text.codec;
|
|
124
|
-
const sqlTimestampCodec = sqlCodecDefinitions.timestamp.codec;
|
|
125
|
-
const pgTextCodec = codec({
|
|
126
|
-
typeId: PG_TEXT_CODEC_ID,
|
|
127
|
-
targetTypes: ["text"],
|
|
128
|
-
traits: [
|
|
129
|
-
"equality",
|
|
130
|
-
"order",
|
|
131
|
-
"textual"
|
|
132
|
-
],
|
|
133
|
-
encode: (value) => value,
|
|
134
|
-
decode: (wire) => wire,
|
|
135
|
-
meta: { db: { sql: { postgres: { nativeType: "text" } } } }
|
|
136
|
-
});
|
|
137
|
-
const pgCharCodec = aliasCodec(sqlCharCodec, {
|
|
138
|
-
typeId: PG_CHAR_CODEC_ID,
|
|
139
|
-
targetTypes: ["character"],
|
|
140
|
-
meta: { db: { sql: { postgres: { nativeType: "character" } } } }
|
|
141
|
-
});
|
|
142
|
-
const pgVarcharCodec = aliasCodec(sqlVarcharCodec, {
|
|
143
|
-
typeId: PG_VARCHAR_CODEC_ID,
|
|
144
|
-
targetTypes: ["character varying"],
|
|
145
|
-
meta: { db: { sql: { postgres: { nativeType: "character varying" } } } }
|
|
146
|
-
});
|
|
147
|
-
const pgIntCodec = aliasCodec(sqlIntCodec, {
|
|
148
|
-
typeId: PG_INT_CODEC_ID,
|
|
149
|
-
targetTypes: ["int4"],
|
|
150
|
-
meta: { db: { sql: { postgres: { nativeType: "integer" } } } }
|
|
151
|
-
});
|
|
152
|
-
const pgFloatCodec = aliasCodec(sqlFloatCodec, {
|
|
153
|
-
typeId: PG_FLOAT_CODEC_ID,
|
|
154
|
-
targetTypes: ["float8"],
|
|
155
|
-
meta: { db: { sql: { postgres: { nativeType: "double precision" } } } }
|
|
156
|
-
});
|
|
157
|
-
const pgInt4Codec = codec({
|
|
158
|
-
typeId: PG_INT4_CODEC_ID,
|
|
159
|
-
targetTypes: ["int4"],
|
|
160
|
-
traits: [
|
|
161
|
-
"equality",
|
|
162
|
-
"order",
|
|
163
|
-
"numeric"
|
|
164
|
-
],
|
|
165
|
-
encode: (value) => value,
|
|
166
|
-
decode: (wire) => wire,
|
|
167
|
-
meta: { db: { sql: { postgres: { nativeType: "integer" } } } }
|
|
168
|
-
});
|
|
169
|
-
const pgNumericCodec = codec({
|
|
170
|
-
typeId: PG_NUMERIC_CODEC_ID,
|
|
171
|
-
targetTypes: ["numeric", "decimal"],
|
|
172
|
-
traits: [
|
|
173
|
-
"equality",
|
|
174
|
-
"order",
|
|
175
|
-
"numeric"
|
|
176
|
-
],
|
|
177
|
-
encode: (value) => value,
|
|
178
|
-
decode: (wire) => {
|
|
179
|
-
if (typeof wire === "number") return String(wire);
|
|
180
|
-
return wire;
|
|
181
|
-
},
|
|
182
|
-
paramsSchema: numericParamsSchema,
|
|
183
|
-
renderOutputType: (typeParams) => {
|
|
184
|
-
const precision = typeParams["precision"];
|
|
185
|
-
if (precision === void 0) return void 0;
|
|
186
|
-
if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw new Error(`renderOutputType: expected integer "precision" in typeParams for Numeric, got ${String(precision)}`);
|
|
187
|
-
const scale = typeParams["scale"];
|
|
188
|
-
return typeof scale === "number" ? `Numeric<${precision}, ${scale}>` : `Numeric<${precision}>`;
|
|
189
|
-
},
|
|
190
|
-
meta: { db: { sql: { postgres: { nativeType: "numeric" } } } }
|
|
191
|
-
});
|
|
192
|
-
const pgInt2Codec = codec({
|
|
193
|
-
typeId: PG_INT2_CODEC_ID,
|
|
194
|
-
targetTypes: ["int2"],
|
|
195
|
-
traits: [
|
|
196
|
-
"equality",
|
|
197
|
-
"order",
|
|
198
|
-
"numeric"
|
|
199
|
-
],
|
|
200
|
-
encode: (value) => value,
|
|
201
|
-
decode: (wire) => wire,
|
|
202
|
-
meta: { db: { sql: { postgres: { nativeType: "smallint" } } } }
|
|
203
|
-
});
|
|
204
|
-
const pgInt8Codec = codec({
|
|
205
|
-
typeId: PG_INT8_CODEC_ID,
|
|
206
|
-
targetTypes: ["int8"],
|
|
207
|
-
traits: [
|
|
208
|
-
"equality",
|
|
209
|
-
"order",
|
|
210
|
-
"numeric"
|
|
211
|
-
],
|
|
212
|
-
encode: (value) => value,
|
|
213
|
-
decode: (wire) => wire,
|
|
214
|
-
meta: { db: { sql: { postgres: { nativeType: "bigint" } } } }
|
|
215
|
-
});
|
|
216
|
-
const pgFloat4Codec = codec({
|
|
217
|
-
typeId: PG_FLOAT4_CODEC_ID,
|
|
218
|
-
targetTypes: ["float4"],
|
|
219
|
-
traits: [
|
|
220
|
-
"equality",
|
|
221
|
-
"order",
|
|
222
|
-
"numeric"
|
|
223
|
-
],
|
|
224
|
-
encode: (value) => value,
|
|
225
|
-
decode: (wire) => wire,
|
|
226
|
-
meta: { db: { sql: { postgres: { nativeType: "real" } } } }
|
|
227
|
-
});
|
|
228
|
-
const pgFloat8Codec = codec({
|
|
229
|
-
typeId: PG_FLOAT8_CODEC_ID,
|
|
230
|
-
targetTypes: ["float8"],
|
|
231
|
-
traits: [
|
|
232
|
-
"equality",
|
|
233
|
-
"order",
|
|
234
|
-
"numeric"
|
|
235
|
-
],
|
|
236
|
-
encode: (value) => value,
|
|
237
|
-
decode: (wire) => wire,
|
|
238
|
-
meta: { db: { sql: { postgres: { nativeType: "double precision" } } } }
|
|
239
|
-
});
|
|
240
|
-
const pgTimestampCodec = codec({
|
|
241
|
-
typeId: PG_TIMESTAMP_CODEC_ID,
|
|
242
|
-
targetTypes: ["timestamp"],
|
|
243
|
-
traits: ["equality", "order"],
|
|
244
|
-
encode: (value) => {
|
|
245
|
-
if (value instanceof Date) return value.toISOString();
|
|
246
|
-
if (typeof value === "string") return value;
|
|
247
|
-
return String(value);
|
|
248
|
-
},
|
|
249
|
-
decode: (wire) => {
|
|
250
|
-
if (wire instanceof Date) return wire.toISOString();
|
|
251
|
-
return wire;
|
|
252
|
-
},
|
|
253
|
-
encodeJson: (value) => value instanceof Date ? value.toISOString() : value,
|
|
254
|
-
decodeJson: (json) => {
|
|
255
|
-
if (typeof json !== "string") throw new Error(`Expected ISO date string for pg/timestamp@1, got ${typeof json}`);
|
|
256
|
-
const date = new Date(json);
|
|
257
|
-
if (Number.isNaN(date.getTime())) throw new Error(`Invalid ISO date string for pg/timestamp@1: ${json}`);
|
|
258
|
-
return date;
|
|
259
|
-
},
|
|
260
|
-
paramsSchema: precisionParamsSchema,
|
|
261
|
-
renderOutputType: (typeParams) => renderPrecision("Timestamp", typeParams),
|
|
262
|
-
meta: { db: { sql: { postgres: { nativeType: "timestamp without time zone" } } } }
|
|
263
|
-
});
|
|
264
|
-
const pgTimestamptzCodec = codec({
|
|
265
|
-
typeId: PG_TIMESTAMPTZ_CODEC_ID,
|
|
266
|
-
targetTypes: ["timestamptz"],
|
|
267
|
-
traits: ["equality", "order"],
|
|
268
|
-
encode: (value) => {
|
|
269
|
-
if (value instanceof Date) return value.toISOString();
|
|
270
|
-
if (typeof value === "string") return value;
|
|
271
|
-
return String(value);
|
|
272
|
-
},
|
|
273
|
-
decode: (wire) => {
|
|
274
|
-
if (wire instanceof Date) return wire.toISOString();
|
|
275
|
-
return wire;
|
|
276
|
-
},
|
|
277
|
-
encodeJson: (value) => value instanceof Date ? value.toISOString() : value,
|
|
278
|
-
decodeJson: (json) => {
|
|
279
|
-
if (typeof json !== "string") throw new Error(`Expected ISO date string for pg/timestamptz@1, got ${typeof json}`);
|
|
280
|
-
const date = new Date(json);
|
|
281
|
-
if (Number.isNaN(date.getTime())) throw new Error(`Invalid ISO date string for pg/timestamptz@1: ${json}`);
|
|
282
|
-
return date;
|
|
283
|
-
},
|
|
284
|
-
paramsSchema: precisionParamsSchema,
|
|
285
|
-
renderOutputType: (typeParams) => renderPrecision("Timestamptz", typeParams),
|
|
286
|
-
meta: { db: { sql: { postgres: { nativeType: "timestamp with time zone" } } } }
|
|
287
|
-
});
|
|
288
|
-
const pgTimeCodec = codec({
|
|
289
|
-
typeId: PG_TIME_CODEC_ID,
|
|
290
|
-
targetTypes: ["time"],
|
|
291
|
-
traits: ["equality", "order"],
|
|
292
|
-
encode: (value) => value,
|
|
293
|
-
decode: (wire) => wire,
|
|
294
|
-
paramsSchema: precisionParamsSchema,
|
|
295
|
-
renderOutputType: (typeParams) => renderPrecision("Time", typeParams),
|
|
296
|
-
meta: { db: { sql: { postgres: { nativeType: "time" } } } }
|
|
297
|
-
});
|
|
298
|
-
const pgTimetzCodec = codec({
|
|
299
|
-
typeId: PG_TIMETZ_CODEC_ID,
|
|
300
|
-
targetTypes: ["timetz"],
|
|
301
|
-
traits: ["equality", "order"],
|
|
302
|
-
encode: (value) => value,
|
|
303
|
-
decode: (wire) => wire,
|
|
304
|
-
paramsSchema: precisionParamsSchema,
|
|
305
|
-
renderOutputType: (typeParams) => renderPrecision("Timetz", typeParams),
|
|
306
|
-
meta: { db: { sql: { postgres: { nativeType: "timetz" } } } }
|
|
307
|
-
});
|
|
308
|
-
const pgBoolCodec = codec({
|
|
309
|
-
typeId: PG_BOOL_CODEC_ID,
|
|
310
|
-
targetTypes: ["bool"],
|
|
311
|
-
traits: ["equality", "boolean"],
|
|
312
|
-
encode: (value) => value,
|
|
313
|
-
decode: (wire) => wire,
|
|
314
|
-
meta: { db: { sql: { postgres: { nativeType: "boolean" } } } }
|
|
315
|
-
});
|
|
316
|
-
const pgBitCodec = codec({
|
|
317
|
-
typeId: PG_BIT_CODEC_ID,
|
|
318
|
-
targetTypes: ["bit"],
|
|
319
|
-
traits: ["equality", "order"],
|
|
320
|
-
encode: (value) => value,
|
|
321
|
-
decode: (wire) => wire,
|
|
322
|
-
paramsSchema: lengthParamsSchema,
|
|
323
|
-
renderOutputType: (typeParams) => renderLength("Bit", typeParams),
|
|
324
|
-
meta: { db: { sql: { postgres: { nativeType: "bit" } } } }
|
|
325
|
-
});
|
|
326
|
-
const pgVarbitCodec = codec({
|
|
327
|
-
typeId: PG_VARBIT_CODEC_ID,
|
|
328
|
-
targetTypes: ["bit varying"],
|
|
329
|
-
traits: ["equality", "order"],
|
|
330
|
-
encode: (value) => value,
|
|
331
|
-
decode: (wire) => wire,
|
|
332
|
-
paramsSchema: lengthParamsSchema,
|
|
333
|
-
renderOutputType: (typeParams) => renderLength("VarBit", typeParams),
|
|
334
|
-
meta: { db: { sql: { postgres: { nativeType: "bit varying" } } } }
|
|
335
|
-
});
|
|
336
|
-
const pgEnumCodec = codec({
|
|
337
|
-
typeId: PG_ENUM_CODEC_ID,
|
|
338
|
-
targetTypes: ["enum"],
|
|
339
|
-
traits: ["equality", "order"],
|
|
340
|
-
encode: (value) => value,
|
|
341
|
-
decode: (wire) => wire,
|
|
342
|
-
renderOutputType: (typeParams) => {
|
|
343
|
-
const values = typeParams["values"];
|
|
344
|
-
if (!Array.isArray(values)) throw new Error(`renderOutputType: expected array "values" in typeParams for enum, got ${typeof values}`);
|
|
345
|
-
return values.map((value) => `'${String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`).join(" | ");
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
const pgIntervalCodec = codec({
|
|
349
|
-
typeId: PG_INTERVAL_CODEC_ID,
|
|
350
|
-
targetTypes: ["interval"],
|
|
351
|
-
traits: ["equality", "order"],
|
|
352
|
-
encode: (value) => value,
|
|
353
|
-
decode: (wire) => {
|
|
354
|
-
if (typeof wire === "string") return wire;
|
|
355
|
-
return JSON.stringify(wire);
|
|
356
|
-
},
|
|
357
|
-
paramsSchema: precisionParamsSchema,
|
|
358
|
-
renderOutputType: (typeParams) => renderPrecision("Interval", typeParams),
|
|
359
|
-
meta: { db: { sql: { postgres: { nativeType: "interval" } } } }
|
|
360
|
-
});
|
|
361
|
-
const pgJsonCodec = codec({
|
|
362
|
-
typeId: PG_JSON_CODEC_ID,
|
|
363
|
-
targetTypes: ["json"],
|
|
364
|
-
traits: [],
|
|
365
|
-
encode: (value) => JSON.stringify(value),
|
|
366
|
-
decode: (wire) => typeof wire === "string" ? JSON.parse(wire) : wire,
|
|
367
|
-
renderOutputType: renderJsonOutputType,
|
|
368
|
-
meta: { db: { sql: { postgres: { nativeType: "json" } } } }
|
|
369
|
-
});
|
|
370
|
-
const pgJsonbCodec = codec({
|
|
371
|
-
typeId: PG_JSONB_CODEC_ID,
|
|
372
|
-
targetTypes: ["jsonb"],
|
|
373
|
-
traits: ["equality"],
|
|
374
|
-
encode: (value) => JSON.stringify(value),
|
|
375
|
-
decode: (wire) => typeof wire === "string" ? JSON.parse(wire) : wire,
|
|
376
|
-
renderOutputType: renderJsonOutputType,
|
|
377
|
-
meta: { db: { sql: { postgres: { nativeType: "jsonb" } } } }
|
|
378
|
-
});
|
|
379
|
-
const codecs = defineCodecs().add("char", sqlCharCodec).add("varchar", sqlVarcharCodec).add("int", sqlIntCodec).add("float", sqlFloatCodec).add("sql-text", sqlTextCodec).add("sql-timestamp", sqlTimestampCodec).add("text", pgTextCodec).add("character", pgCharCodec).add("character varying", pgVarcharCodec).add("integer", pgIntCodec).add("double precision", pgFloatCodec).add("int4", pgInt4Codec).add("int2", pgInt2Codec).add("int8", pgInt8Codec).add("float4", pgFloat4Codec).add("float8", pgFloat8Codec).add("numeric", pgNumericCodec).add("timestamp", pgTimestampCodec).add("timestamptz", pgTimestamptzCodec).add("time", pgTimeCodec).add("timetz", pgTimetzCodec).add("bool", pgBoolCodec).add("bit", pgBitCodec).add("bit varying", pgVarbitCodec).add("interval", pgIntervalCodec).add("enum", pgEnumCodec).add("json", pgJsonCodec).add("jsonb", pgJsonbCodec);
|
|
380
|
-
const codecDefinitions = codecs.codecDefinitions;
|
|
381
|
-
const dataTypes = codecs.dataTypes;
|
|
382
|
-
|
|
383
|
-
//#endregion
|
|
384
|
-
export { dataTypes as n, codecDefinitions as t };
|
|
385
|
-
//# sourceMappingURL=codecs-DiPlMi3-.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codecs-DiPlMi3-.mjs","names":["arktype"],"sources":["../src/core/json-schema-type-expression.ts","../src/core/codecs.ts"],"sourcesContent":["type JsonSchemaRecord = Record<string, unknown>;\n\nconst MAX_DEPTH = 32;\n\nfunction isRecord(value: unknown): value is JsonSchemaRecord {\n return typeof value === 'object' && value !== null;\n}\n\nfunction escapeStringLiteral(str: string): string {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/'/g, \"\\\\'\")\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r');\n}\n\nfunction quotePropertyKey(key: string): string {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : `'${escapeStringLiteral(key)}'`;\n}\n\nfunction renderLiteral(value: unknown): string {\n if (typeof value === 'string') {\n return `'${escapeStringLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (value === null) {\n return 'null';\n }\n return 'unknown';\n}\n\nfunction renderUnion(items: readonly unknown[], depth: number): string {\n const rendered = items.map((item) => render(item, depth));\n return rendered.join(' | ');\n}\n\nfunction renderObjectType(schema: JsonSchemaRecord, depth: number): string {\n const properties = isRecord(schema['properties']) ? schema['properties'] : {};\n const required = Array.isArray(schema['required'])\n ? new Set(schema['required'].filter((key): key is string => typeof key === 'string'))\n : new Set<string>();\n const keys = Object.keys(properties).sort((left, right) => left.localeCompare(right));\n\n if (keys.length === 0) {\n const additionalProperties = schema['additionalProperties'];\n if (additionalProperties === true || additionalProperties === undefined) {\n return 'Record<string, unknown>';\n }\n return `Record<string, ${render(additionalProperties, depth)}>`;\n }\n\n const renderedProperties = keys.map((key) => {\n const valueSchema = (properties as JsonSchemaRecord)[key];\n const optionalMarker = required.has(key) ? '' : '?';\n return `${quotePropertyKey(key)}${optionalMarker}: ${render(valueSchema, depth)}`;\n });\n\n return `{ ${renderedProperties.join('; ')} }`;\n}\n\nfunction renderArrayType(schema: JsonSchemaRecord, depth: number): string {\n if (Array.isArray(schema['items'])) {\n return `readonly [${schema['items'].map((item) => render(item, depth)).join(', ')}]`;\n }\n\n if (schema['items'] !== undefined) {\n const itemType = render(schema['items'], depth);\n const needsParens = itemType.includes(' | ') || itemType.includes(' & ');\n return needsParens ? `(${itemType})[]` : `${itemType}[]`;\n }\n\n return 'unknown[]';\n}\n\nfunction render(schema: unknown, depth: number): string {\n if (depth > MAX_DEPTH || !isRecord(schema)) {\n return 'JsonValue';\n }\n\n const nextDepth = depth + 1;\n\n if ('const' in schema) {\n return renderLiteral(schema['const']);\n }\n\n if (Array.isArray(schema['enum'])) {\n return schema['enum'].map((value) => renderLiteral(value)).join(' | ');\n }\n\n if (Array.isArray(schema['oneOf'])) {\n return renderUnion(schema['oneOf'], nextDepth);\n }\n\n if (Array.isArray(schema['anyOf'])) {\n return renderUnion(schema['anyOf'], nextDepth);\n }\n\n if (Array.isArray(schema['allOf'])) {\n return schema['allOf'].map((item) => render(item, nextDepth)).join(' & ');\n }\n\n if (Array.isArray(schema['type'])) {\n return schema['type'].map((item) => render({ ...schema, type: item }, nextDepth)).join(' | ');\n }\n\n switch (schema['type']) {\n case 'string':\n return 'string';\n case 'number':\n case 'integer':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'null':\n return 'null';\n case 'array':\n return renderArrayType(schema, nextDepth);\n case 'object':\n return renderObjectType(schema, nextDepth);\n default:\n break;\n }\n\n return 'JsonValue';\n}\n\nexport function renderTypeScriptTypeFromJsonSchema(schema: unknown): string {\n return render(schema, 0);\n}\n","/**\n * Unified codec definitions for Postgres adapter.\n *\n * This file contains a single source of truth for all codec information:\n * - Scalar names\n * - Type IDs\n * - Codec implementations (runtime)\n * - Type information (compile-time)\n *\n * This structure is used both at runtime (to populate the registry) and\n * at compile time (to derive CodecTypes).\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport type { Codec, CodecMeta, CodecTrait } from '@prisma-next/sql-relational-core/ast';\nimport { codec, defineCodecs, sqlCodecDefinitions } from '@prisma-next/sql-relational-core/ast';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { type as arktype } from 'arktype';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_CHAR_CODEC_ID,\n PG_ENUM_CODEC_ID,\n PG_FLOAT_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n PG_VARCHAR_CODEC_ID,\n} from './codec-ids';\nimport { renderTypeScriptTypeFromJsonSchema } from './json-schema-type-expression';\n\nconst lengthParamsSchema = arktype({\n length: 'number.integer > 0',\n});\n\nconst numericParamsSchema = arktype({\n precision: 'number.integer > 0 & number.integer <= 1000',\n 'scale?': 'number.integer >= 0',\n});\n\nconst precisionParamsSchema = arktype({\n 'precision?': 'number.integer >= 0 & number.integer <= 6',\n});\n\nfunction renderLength(typeName: string, typeParams: Record<string, unknown>): string | undefined {\n const length = typeParams['length'];\n if (length === undefined) {\n return undefined;\n }\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error(\n `renderOutputType: expected integer \"length\" in typeParams for ${typeName}, got ${String(length)}`,\n );\n }\n return `${typeName}<${length}>`;\n}\n\nfunction renderPrecision(typeName: string, typeParams: Record<string, unknown>): string {\n const precision = typeParams['precision'];\n if (precision === undefined) {\n return typeName;\n }\n if (\n typeof precision !== 'number' ||\n !Number.isFinite(precision) ||\n !Number.isInteger(precision)\n ) {\n throw new Error(\n `renderOutputType: expected integer \"precision\" in typeParams for ${typeName}, got ${String(precision)}`,\n );\n }\n return `${typeName}<${precision}>`;\n}\n\nfunction renderJsonOutputType(typeParams: Record<string, unknown>): string {\n const typeName = typeParams['type'];\n if (typeof typeName === 'string' && typeName.trim().length > 0) {\n return typeName.trim();\n }\n const schema = typeParams['schemaJson'];\n if (schema && typeof schema === 'object') {\n return renderTypeScriptTypeFromJsonSchema(schema);\n }\n throw new Error(\n `renderOutputType: JSON codec typeParams must contain \"type\" (string) or \"schemaJson\" (object), got keys: ${Object.keys(typeParams).join(', ')}`,\n );\n}\n\nfunction aliasCodec<\n Id extends string,\n TTraits extends readonly CodecTrait[],\n TWire,\n TJs,\n TParams,\n THelper,\n>(\n base: Codec<string, TTraits, TWire, TJs, TParams, THelper>,\n options: {\n readonly typeId: Id;\n readonly targetTypes: readonly string[];\n readonly meta?: CodecMeta;\n },\n): Codec<Id, TTraits, TWire, TJs, TParams, THelper> {\n return {\n id: options.typeId,\n targetTypes: options.targetTypes,\n ...ifDefined('meta', options.meta),\n ...ifDefined('paramsSchema', base.paramsSchema),\n ...ifDefined('init', base.init),\n ...ifDefined('encode', base.encode),\n ...ifDefined('traits', base.traits),\n ...ifDefined('renderOutputType', base.renderOutputType),\n decode: base.decode,\n encodeJson: base.encodeJson,\n decodeJson: base.decodeJson,\n } as Codec<Id, TTraits, TWire, TJs, TParams, THelper>;\n}\n\nconst sqlCharCodec = sqlCodecDefinitions.char.codec;\nconst sqlVarcharCodec = sqlCodecDefinitions.varchar.codec;\nconst sqlIntCodec = sqlCodecDefinitions.int.codec;\nconst sqlFloatCodec = sqlCodecDefinitions.float.codec;\nconst sqlTextCodec = sqlCodecDefinitions.text.codec;\nconst sqlTimestampCodec = sqlCodecDefinitions.timestamp.codec;\n\n// Create individual codec instances\nconst pgTextCodec = codec({\n typeId: PG_TEXT_CODEC_ID,\n targetTypes: ['text'],\n traits: ['equality', 'order', 'textual'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'text',\n },\n },\n },\n },\n});\n\nconst pgCharCodec = aliasCodec(sqlCharCodec, {\n typeId: PG_CHAR_CODEC_ID,\n targetTypes: ['character'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'character',\n },\n },\n },\n },\n});\n\nconst pgVarcharCodec = aliasCodec(sqlVarcharCodec, {\n typeId: PG_VARCHAR_CODEC_ID,\n targetTypes: ['character varying'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'character varying',\n },\n },\n },\n },\n});\n\nconst pgIntCodec = aliasCodec(sqlIntCodec, {\n typeId: PG_INT_CODEC_ID,\n targetTypes: ['int4'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'integer',\n },\n },\n },\n },\n});\n\nconst pgFloatCodec = aliasCodec(sqlFloatCodec, {\n typeId: PG_FLOAT_CODEC_ID,\n targetTypes: ['float8'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'double precision',\n },\n },\n },\n },\n});\n\nconst pgInt4Codec = codec({\n typeId: PG_INT4_CODEC_ID,\n targetTypes: ['int4'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'integer',\n },\n },\n },\n },\n});\n\nconst pgNumericCodec = codec<\n typeof PG_NUMERIC_CODEC_ID,\n readonly ['equality', 'order', 'numeric'],\n string,\n string\n>({\n typeId: PG_NUMERIC_CODEC_ID,\n targetTypes: ['numeric', 'decimal'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: string): string => value,\n decode: (wire: string | number): string => {\n if (typeof wire === 'number') return String(wire);\n return wire;\n },\n paramsSchema: numericParamsSchema,\n renderOutputType: (typeParams) => {\n const precision = typeParams['precision'];\n if (precision === undefined) return undefined;\n if (\n typeof precision !== 'number' ||\n !Number.isFinite(precision) ||\n !Number.isInteger(precision)\n ) {\n throw new Error(\n `renderOutputType: expected integer \"precision\" in typeParams for Numeric, got ${String(precision)}`,\n );\n }\n const scale = typeParams['scale'];\n return typeof scale === 'number' ? `Numeric<${precision}, ${scale}>` : `Numeric<${precision}>`;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'numeric',\n },\n },\n },\n },\n});\n\nconst pgInt2Codec = codec({\n typeId: PG_INT2_CODEC_ID,\n targetTypes: ['int2'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'smallint',\n },\n },\n },\n },\n});\n\nconst pgInt8Codec = codec({\n typeId: PG_INT8_CODEC_ID,\n targetTypes: ['int8'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'bigint',\n },\n },\n },\n },\n});\n\nconst pgFloat4Codec = codec({\n typeId: PG_FLOAT4_CODEC_ID,\n targetTypes: ['float4'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'real',\n },\n },\n },\n },\n});\n\nconst pgFloat8Codec = codec({\n typeId: PG_FLOAT8_CODEC_ID,\n targetTypes: ['float8'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'double precision',\n },\n },\n },\n },\n});\n\nconst pgTimestampCodec = codec<\n typeof PG_TIMESTAMP_CODEC_ID,\n readonly ['equality', 'order'],\n string | Date,\n string | Date\n>({\n typeId: PG_TIMESTAMP_CODEC_ID,\n targetTypes: ['timestamp'],\n traits: ['equality', 'order'],\n encode: (value: string | Date): string => {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string') return value;\n return String(value);\n },\n decode: (wire: string | Date): string => {\n if (wire instanceof Date) return wire.toISOString();\n return wire;\n },\n encodeJson: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),\n decodeJson: (json) => {\n if (typeof json !== 'string') {\n throw new Error(`Expected ISO date string for pg/timestamp@1, got ${typeof json}`);\n }\n const date = new Date(json);\n if (Number.isNaN(date.getTime())) {\n throw new Error(`Invalid ISO date string for pg/timestamp@1: ${json}`);\n }\n return date;\n },\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Timestamp', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'timestamp without time zone',\n },\n },\n },\n },\n});\n\nconst pgTimestamptzCodec = codec<\n typeof PG_TIMESTAMPTZ_CODEC_ID,\n readonly ['equality', 'order'],\n string | Date,\n string | Date\n>({\n typeId: PG_TIMESTAMPTZ_CODEC_ID,\n targetTypes: ['timestamptz'],\n traits: ['equality', 'order'],\n encode: (value: string | Date): string => {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string') return value;\n return String(value);\n },\n decode: (wire: string | Date): string => {\n if (wire instanceof Date) return wire.toISOString();\n return wire;\n },\n encodeJson: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),\n decodeJson: (json) => {\n if (typeof json !== 'string') {\n throw new Error(`Expected ISO date string for pg/timestamptz@1, got ${typeof json}`);\n }\n const date = new Date(json);\n if (Number.isNaN(date.getTime())) {\n throw new Error(`Invalid ISO date string for pg/timestamptz@1: ${json}`);\n }\n return date;\n },\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Timestamptz', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'timestamp with time zone',\n },\n },\n },\n },\n});\n\nconst pgTimeCodec = codec<typeof PG_TIME_CODEC_ID, readonly ['equality', 'order'], string, string>({\n typeId: PG_TIME_CODEC_ID,\n targetTypes: ['time'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Time', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'time',\n },\n },\n },\n },\n});\n\nconst pgTimetzCodec = codec<\n typeof PG_TIMETZ_CODEC_ID,\n readonly ['equality', 'order'],\n string,\n string\n>({\n typeId: PG_TIMETZ_CODEC_ID,\n targetTypes: ['timetz'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Timetz', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'timetz',\n },\n },\n },\n },\n});\n\nconst pgBoolCodec = codec({\n typeId: PG_BOOL_CODEC_ID,\n targetTypes: ['bool'],\n traits: ['equality', 'boolean'],\n encode: (value: boolean): boolean => value,\n decode: (wire: boolean): boolean => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'boolean',\n },\n },\n },\n },\n});\n\nconst pgBitCodec = codec<typeof PG_BIT_CODEC_ID, readonly ['equality', 'order'], string, string>({\n typeId: PG_BIT_CODEC_ID,\n targetTypes: ['bit'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: lengthParamsSchema,\n renderOutputType: (typeParams) => renderLength('Bit', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'bit',\n },\n },\n },\n },\n});\n\nconst pgVarbitCodec = codec<\n typeof PG_VARBIT_CODEC_ID,\n readonly ['equality', 'order'],\n string,\n string\n>({\n typeId: PG_VARBIT_CODEC_ID,\n targetTypes: ['bit varying'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: lengthParamsSchema,\n renderOutputType: (typeParams) => renderLength('VarBit', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'bit varying',\n },\n },\n },\n },\n});\n\nconst pgEnumCodec = codec({\n typeId: PG_ENUM_CODEC_ID,\n targetTypes: ['enum'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n renderOutputType: (typeParams) => {\n const values = typeParams['values'];\n if (!Array.isArray(values)) {\n throw new Error(\n `renderOutputType: expected array \"values\" in typeParams for enum, got ${typeof values}`,\n );\n }\n return values\n .map((value) => `'${String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`)\n .join(' | ');\n },\n});\n\nconst pgIntervalCodec = codec<\n typeof PG_INTERVAL_CODEC_ID,\n readonly ['equality', 'order'],\n string | Record<string, unknown>,\n string\n>({\n typeId: PG_INTERVAL_CODEC_ID,\n targetTypes: ['interval'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string | Record<string, unknown>): string => {\n if (typeof wire === 'string') return wire;\n return JSON.stringify(wire);\n },\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Interval', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'interval',\n },\n },\n },\n },\n});\n\nconst pgJsonCodec = codec({\n typeId: PG_JSON_CODEC_ID,\n targetTypes: ['json'],\n traits: [],\n encode: (value: string | JsonValue): string => JSON.stringify(value),\n decode: (wire: string | JsonValue): JsonValue =>\n typeof wire === 'string' ? JSON.parse(wire) : wire,\n renderOutputType: renderJsonOutputType,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'json',\n },\n },\n },\n },\n});\n\nconst pgJsonbCodec = codec({\n typeId: PG_JSONB_CODEC_ID,\n targetTypes: ['jsonb'],\n traits: ['equality'],\n encode: (value: string | JsonValue): string => JSON.stringify(value),\n decode: (wire: string | JsonValue): JsonValue =>\n typeof wire === 'string' ? JSON.parse(wire) : wire,\n renderOutputType: renderJsonOutputType,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'jsonb',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs()\n .add('char', sqlCharCodec)\n .add('varchar', sqlVarcharCodec)\n .add('int', sqlIntCodec)\n .add('float', sqlFloatCodec)\n .add('sql-text', sqlTextCodec)\n .add('sql-timestamp', sqlTimestampCodec)\n .add('text', pgTextCodec)\n .add('character', pgCharCodec)\n .add('character varying', pgVarcharCodec)\n .add('integer', pgIntCodec)\n .add('double precision', pgFloatCodec)\n .add('int4', pgInt4Codec)\n .add('int2', pgInt2Codec)\n .add('int8', pgInt8Codec)\n .add('float4', pgFloat4Codec)\n .add('float8', pgFloat8Codec)\n .add('numeric', pgNumericCodec)\n .add('timestamp', pgTimestampCodec)\n .add('timestamptz', pgTimestamptzCodec)\n .add('time', pgTimeCodec)\n .add('timetz', pgTimetzCodec)\n .add('bool', pgBoolCodec)\n .add('bit', pgBitCodec)\n .add('bit varying', pgVarbitCodec)\n .add('interval', pgIntervalCodec)\n .add('enum', pgEnumCodec)\n .add('json', pgJsonCodec)\n .add('jsonb', pgJsonbCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\nexport type CodecTypes = typeof codecs.CodecTypes;\n"],"mappings":";;;;;;AAEA,MAAM,YAAY;AAElB,SAAS,SAAS,OAA2C;AAC3D,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,oBAAoB,KAAqB;AAChD,QAAO,IACJ,QAAQ,OAAO,OAAO,CACtB,QAAQ,MAAM,MAAM,CACpB,QAAQ,OAAO,MAAM,CACrB,QAAQ,OAAO,MAAM;;AAG1B,SAAS,iBAAiB,KAAqB;AAC7C,QAAO,6BAA6B,KAAK,IAAI,GAAG,MAAM,IAAI,oBAAoB,IAAI,CAAC;;AAGrF,SAAS,cAAc,OAAwB;AAC7C,KAAI,OAAO,UAAU,SACnB,QAAO,IAAI,oBAAoB,MAAM,CAAC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CACjC,IAAI,YAAY,gBAAgB,CAChC,IAAI,QAAQ,YAAY,CACxB,IAAI,QAAQ,YAAY,CACxB,IAAI,SAAS,aAAa;AAG7B,MAAa,mBAAmB,OAAO;AACvC,MAAa,YAAY,OAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-BB9XPAFi.mjs","names":["result: string[]","operations: SqlMigrationPlanOperation<unknown>[]","columns: Array<{ table: string; column: string }>","result: Array<{ table: string; column: string }>","pgEnumControlHooks: CodecControlHooks","types: Record<string, StorageTypeInstance>","lengthHooks: CodecControlHooks","precisionHooks: CodecControlHooks","numericHooks: CodecControlHooks","identityHooks: CodecControlHooks","postgresQueryOperations: readonly SqlOperationDescriptor[]"],"sources":["../src/core/enum-control-hooks.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { CodecControlHooks, SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport type { SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from './codec-ids';\nimport { escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength } from './sql-utils';\n\n/**\n * Postgres enum control hooks.\n *\n * - Plans enum type operations for migrations\n * - Verifies enum types in schema IR\n * - Introspects enum types from the database\n */\ntype EnumRow = {\n schema_name: string;\n type_name: string;\n values: string[];\n};\n\ntype EnumDiff =\n | { kind: 'unchanged' }\n | { kind: 'add_values'; values: readonly string[] }\n | { kind: 'rebuild'; removedValues: readonly string[] };\n\n// ============================================================================\n// Introspection SQL\n// ============================================================================\n\nconst ENUM_INTROSPECT_QUERY = `\n SELECT\n n.nspname AS schema_name,\n t.typname AS type_name,\n array_agg(e.enumlabel ORDER BY e.enumsortorder) AS values\n FROM pg_type t\n JOIN pg_namespace n ON t.typnamespace = n.oid\n JOIN pg_enum e ON t.oid = e.enumtypid\n WHERE n.nspname = $1\n GROUP BY n.nspname, t.typname\n ORDER BY n.nspname, t.typname\n`;\n\n// ============================================================================\n// Schema Helpers (Simplified)\n// ============================================================================\n\n/**\n * Type guard for string arrays. Used for runtime validation of introspected data.\n */\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((entry) => typeof entry === 'string');\n}\n\n/**\n * Parses a PostgreSQL array value into a JavaScript string array.\n *\n * PostgreSQL's `pg` library may return `array_agg` results either as:\n * - A JavaScript array (when type parsers are configured)\n * - A string in PostgreSQL array literal format: `{value1,value2,...}`\n *\n * Handles PostgreSQL's quoting rules for array elements:\n * - Elements containing commas, double quotes, backslashes, or whitespace are double-quoted\n * - Inside quoted elements, `\\\"` represents `\"` and `\\\\` represents `\\`\n *\n * @param value - The value to parse (array or PostgreSQL array string)\n * @returns A string array, or null if the value cannot be parsed\n */\nexport function parsePostgresArray(value: unknown): string[] | null {\n if (isStringArray(value)) {\n return value;\n }\n if (typeof value === 'string' && value.startsWith('{') && value.endsWith('}')) {\n const inner = value.slice(1, -1);\n if (inner === '') {\n return [];\n }\n return parseArrayElements(inner);\n }\n return null;\n}\n\nfunction parseArrayElements(input: string): string[] {\n const result: string[] = [];\n let i = 0;\n while (i < input.length) {\n if (input[i] === ',') {\n i++;\n continue;\n }\n if (input[i] === '\"') {\n i++;\n let element = '';\n while (i < input.length && input[i] !== '\"') {\n if (input[i] === '\\\\' && i + 1 < input.length) {\n i++;\n element += input[i];\n } else {\n element += input[i];\n }\n i++;\n }\n i++;\n result.push(element);\n } else {\n const nextComma = input.indexOf(',', i);\n if (nextComma === -1) {\n result.push(input.slice(i).trim());\n i = input.length;\n } else {\n result.push(input.slice(i, nextComma).trim());\n i = nextComma;\n }\n }\n }\n return result;\n}\n\n/**\n * Extracts enum values from a StorageTypeInstance.\n * Returns null if values are missing or invalid.\n */\nfunction getEnumValues(typeInstance: StorageTypeInstance): readonly string[] | null {\n const values = typeInstance.typeParams?.['values'];\n return isStringArray(values) ? values : null;\n}\n\n/**\n * Reads existing enum values from the schema IR for a given native type.\n * Uses optional chaining to simplify navigation through the annotations structure.\n */\nfunction readExistingEnumValues(schema: SqlSchemaIR, nativeType: string): readonly string[] | null {\n const storageTypes = (schema.annotations?.['pg'] as Record<string, unknown> | undefined)?.[\n 'storageTypes'\n ] as Record<string, StorageTypeInstance> | undefined;\n\n const existing = storageTypes?.[nativeType];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n return getEnumValues(existing);\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to desired values.\n *\n * Returns one of:\n * - `unchanged`: No changes needed, values match exactly\n * - `add_values`: New values can be safely appended (PostgreSQL supports this)\n * - `rebuild`: Full enum rebuild required (value removal, reordering, or both)\n *\n * Note: PostgreSQL enums can only have values added (not removed or reordered) without\n * a full type rebuild involving temp type creation and column migration.\n *\n * @param existing - Current enum values in the database\n * @param desired - Target enum values from the contract\n * @returns The type of change required\n */\nfunction determineEnumDiff(existing: readonly string[], desired: readonly string[]): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n\n // Use Sets for O(1) lookups instead of O(n) array.includes()\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n\n return { kind: 'add_values', values: missingValues };\n}\n\n// ============================================================================\n// SQL Helpers\n// ============================================================================\n\nfunction enumTypeExistsCheck(schemaName: string, typeName: string, exists = true): string {\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n return `SELECT ${existsClause} (\n SELECT 1\n FROM pg_type t\n JOIN pg_namespace n ON t.typnamespace = n.oid\n WHERE n.nspname = '${escapeLiteral(schemaName)}'\n AND t.typname = '${escapeLiteral(typeName)}'\n)`;\n}\n\n// ============================================================================\n// Operation Builders\n// ============================================================================\n\nfunction buildCreateEnumOperation(\n typeName: string,\n nativeType: string,\n schemaName: string,\n values: readonly string[],\n): SqlMigrationPlanOperation<unknown> {\n // Validate all enum values don't exceed PostgreSQL's label length limit\n for (const value of values) {\n validateEnumValueLength(value, typeName);\n }\n const literalValues = values.map((value) => `'${escapeLiteral(value)}'`).join(', ');\n const qualifiedType = qualifyName(schemaName, nativeType);\n return {\n id: `type.${typeName}`,\n label: `Create type ${typeName}`,\n summary: `Creates enum type ${typeName}`,\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: `ensure type \"${nativeType}\" does not exist`,\n sql: enumTypeExistsCheck(schemaName, nativeType, false),\n },\n ],\n execute: [\n {\n description: `create type \"${nativeType}\"`,\n sql: `CREATE TYPE ${qualifiedType} AS ENUM (${literalValues})`,\n },\n ],\n postcheck: [\n {\n description: `verify type \"${nativeType}\" exists`,\n sql: enumTypeExistsCheck(schemaName, nativeType),\n },\n ],\n };\n}\n\n/**\n * Computes the optimal position for inserting a new enum value to maintain\n * the desired order relative to existing values.\n *\n * PostgreSQL's `ALTER TYPE ADD VALUE` supports BEFORE/AFTER positioning.\n * This function finds the best reference value by:\n * 1. Looking for the nearest preceding value that already exists\n * 2. Falling back to the nearest following value if no preceding exists\n * 3. Defaulting to end-of-list if no reference is found\n *\n * @param options.desired - The target ordered list of all enum values\n * @param options.desiredIndex - Index of the value being inserted in the desired list\n * @param options.current - Current list of enum values (being built up incrementally)\n * @returns SQL clause (e.g., \" AFTER 'x'\") and insert position for tracking\n */\nfunction computeInsertPosition(options: {\n desired: readonly string[];\n desiredIndex: number;\n current: readonly string[];\n}): { clause: string; insertAt: number } {\n const { desired, desiredIndex, current } = options;\n const currentSet = new Set(current);\n const previous = desired\n .slice(0, desiredIndex)\n .reverse()\n .find((candidate) => currentSet.has(candidate));\n const next = desired.slice(desiredIndex + 1).find((candidate) => currentSet.has(candidate));\n const clause = previous\n ? ` AFTER '${escapeLiteral(previous)}'`\n : next\n ? ` BEFORE '${escapeLiteral(next)}'`\n : '';\n const insertAt = previous\n ? current.indexOf(previous) + 1\n : next\n ? current.indexOf(next)\n : current.length;\n\n return { clause, insertAt };\n}\n\n/**\n * Builds operations to add new enum values to an existing PostgreSQL enum type.\n *\n * Each new value is added with `ALTER TYPE ... ADD VALUE IF NOT EXISTS` for idempotency.\n * Values are inserted in the correct order using BEFORE/AFTER positioning to match\n * the desired final order.\n *\n * This is a safe, non-destructive operation - existing data is not affected.\n *\n * @param options.typeName - Contract-level type name (e.g., 'Role')\n * @param options.nativeType - PostgreSQL type name (e.g., 'role')\n * @param options.schemaName - PostgreSQL schema (e.g., 'public')\n * @param options.desired - Target ordered list of all enum values\n * @param options.existing - Current enum values in the database\n * @returns Array of migration operations to add each missing value\n */\nfunction buildAddValueOperations(options: {\n typeName: string;\n nativeType: string;\n schemaName: string;\n desired: readonly string[];\n existing: readonly string[];\n}): SqlMigrationPlanOperation<unknown>[] {\n const { typeName, nativeType, schemaName } = options;\n const current = [...options.existing];\n const currentSet = new Set(current);\n const operations: SqlMigrationPlanOperation<unknown>[] = [];\n for (let index = 0; index < options.desired.length; index += 1) {\n const value = options.desired[index];\n if (value === undefined) {\n continue;\n }\n if (currentSet.has(value)) {\n continue;\n }\n // Validate the new value doesn't exceed PostgreSQL's label length limit\n validateEnumValueLength(value, typeName);\n const { clause, insertAt } = computeInsertPosition({\n desired: options.desired,\n desiredIndex: index,\n current,\n });\n // Use IF NOT EXISTS for idempotency - safe to re-run after partial failures.\n // Supported in PostgreSQL 9.3+, and we require PostgreSQL 12+.\n operations.push({\n id: `type.${typeName}.value.${value}`,\n label: `Add value ${value} to ${typeName}`,\n summary: `Adds enum value ${value} to ${typeName}`,\n operationClass: 'widening',\n target: { id: 'postgres' },\n precheck: [],\n execute: [\n {\n description: `add value \"${value}\" if not exists`,\n sql: `ALTER TYPE ${qualifyName(schemaName, nativeType)} ADD VALUE IF NOT EXISTS '${escapeLiteral(\n value,\n )}'${clause}`,\n },\n ],\n postcheck: [],\n });\n current.splice(insertAt, 0, value);\n currentSet.add(value);\n }\n return operations;\n}\n\n/**\n * Collects columns using the enum type from the contract (desired state).\n * Used for type-safe reference tracking.\n */\nfunction collectEnumColumnsFromContract(\n contract: Contract<SqlStorage>,\n typeName: string,\n nativeType: string,\n): ReadonlyArray<{ table: string; column: string }> {\n const columns: Array<{ table: string; column: string }> = [];\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (\n column.typeRef === typeName ||\n (column.nativeType === nativeType && column.codecId === PG_ENUM_CODEC_ID)\n ) {\n columns.push({ table: tableName, column: columnName });\n }\n }\n }\n return columns;\n}\n\n/**\n * Collects columns using the enum type from the schema IR (live database state).\n * This ensures we find ALL dependent columns, including those added outside the contract\n * (e.g., manual DDL), which is critical for safe enum rebuild operations.\n */\nfunction collectEnumColumnsFromSchema(\n schema: SqlSchemaIR,\n nativeType: string,\n): ReadonlyArray<{ table: string; column: string }> {\n const columns: Array<{ table: string; column: string }> = [];\n for (const [tableName, table] of Object.entries(schema.tables)) {\n for (const [columnName, column] of Object.entries(table.columns)) {\n // Match by nativeType since schema IR doesn't have codecId/typeRef\n if (column.nativeType === nativeType) {\n columns.push({ table: tableName, column: columnName });\n }\n }\n }\n return columns;\n}\n\n/**\n * Collects all columns using the enum type from both contract AND live database.\n * Merges and deduplicates to ensure we migrate ALL dependent columns during rebuild.\n *\n * This is critical for data integrity: if a column exists in the database using\n * this enum but is not in the contract (e.g., added via manual DDL), we must\n * still migrate it to avoid DROP TYPE failures.\n */\nfunction collectAllEnumColumns(\n contract: Contract<SqlStorage>,\n schema: SqlSchemaIR,\n typeName: string,\n nativeType: string,\n): ReadonlyArray<{ table: string; column: string }> {\n const contractColumns = collectEnumColumnsFromContract(contract, typeName, nativeType);\n const schemaColumns = collectEnumColumnsFromSchema(schema, nativeType);\n\n // Merge and deduplicate using a Set of \"table.column\" keys\n const seen = new Set<string>();\n const result: Array<{ table: string; column: string }> = [];\n\n for (const col of [...contractColumns, ...schemaColumns]) {\n const key = `${col.table}.${col.column}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(col);\n }\n }\n\n // Sort for deterministic operation order\n return result.sort((a, b) => {\n const tableCompare = a.table.localeCompare(b.table);\n return tableCompare !== 0 ? tableCompare : a.column.localeCompare(b.column);\n });\n}\n\n/**\n * Builds a SQL check to verify a column's type matches an expected type.\n */\nfunction columnTypeCheck(options: {\n schemaName: string;\n tableName: string;\n columnName: string;\n expectedType: string;\n}): string {\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = '${escapeLiteral(options.schemaName)}'\n AND table_name = '${escapeLiteral(options.tableName)}'\n AND column_name = '${escapeLiteral(options.columnName)}'\n AND udt_name = '${escapeLiteral(options.expectedType)}'\n)`;\n}\n\n/** PostgreSQL maximum identifier length (NAMEDATALEN - 1) */\nconst MAX_IDENTIFIER_LENGTH = 63;\n\n/** Suffix added to enum type names during rebuild operations */\nconst REBUILD_SUFFIX = '__pn_rebuild';\n\n/**\n * Builds an SQL check to verify no rows contain any of the removed enum values.\n * This prevents data loss during enum rebuild operations.\n *\n * @param schemaName - PostgreSQL schema name\n * @param tableName - Table containing the enum column\n * @param columnName - Column using the enum type\n * @param removedValues - Array of enum values being removed\n * @returns SQL query that returns true if no rows contain removed values\n */\nfunction noRemovedValuesExistCheck(\n schemaName: string,\n tableName: string,\n columnName: string,\n removedValues: readonly string[],\n): string {\n if (removedValues.length === 0) {\n // No values being removed, always passes\n return 'SELECT true';\n }\n const valuesList = removedValues.map((v) => `'${escapeLiteral(v)}'`).join(', ');\n return `SELECT NOT EXISTS (\n SELECT 1 FROM ${qualifyName(schemaName, tableName)}\n WHERE ${quoteIdentifier(columnName)}::text IN (${valuesList})\n LIMIT 1\n)`;\n}\n\n/**\n * Builds a migration operation to recreate a PostgreSQL enum type with updated values.\n *\n * This is required when:\n * - Enum values are removed (PostgreSQL doesn't support direct removal)\n * - Enum values are reordered (PostgreSQL doesn't support reordering)\n *\n * The operation:\n * 1. Creates a new enum type with the desired values (temp name)\n * 2. Migrates all columns to use the new type via text cast\n * 3. Drops the original type\n * 4. Renames the temp type to the original name\n *\n * IMPORTANT: If values are being removed and data exists using those values,\n * the operation will fail at the precheck stage with a clear error message.\n * This prevents silent data loss.\n *\n * @param options.typeName - Contract-level type name\n * @param options.nativeType - PostgreSQL type name\n * @param options.schemaName - PostgreSQL schema\n * @param options.values - Desired final enum values\n * @param options.removedValues - Values being removed (for data loss checks)\n * @param options.contract - Full contract for column discovery\n * @param options.schema - Current schema IR for column discovery\n * @returns Migration operation for full enum rebuild\n */\nfunction buildRecreateEnumOperation(options: {\n typeName: string;\n nativeType: string;\n schemaName: string;\n values: readonly string[];\n removedValues: readonly string[];\n contract: Contract<SqlStorage>;\n schema: SqlSchemaIR;\n}): SqlMigrationPlanOperation<unknown> {\n const tempTypeName = `${options.nativeType}${REBUILD_SUFFIX}`;\n\n // Validate temp type name length won't exceed PostgreSQL's 63-character limit.\n // If it would, PostgreSQL silently truncates which could cause conflicts.\n if (tempTypeName.length > MAX_IDENTIFIER_LENGTH) {\n const maxBaseLength = MAX_IDENTIFIER_LENGTH - REBUILD_SUFFIX.length;\n throw new Error(\n `Enum type name \"${options.nativeType}\" is too long for rebuild operation. ` +\n `Maximum length is ${maxBaseLength} characters (type name + \"${REBUILD_SUFFIX}\" suffix ` +\n `must fit within PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character identifier limit).`,\n );\n }\n\n const qualifiedOriginal = qualifyName(options.schemaName, options.nativeType);\n const qualifiedTemp = qualifyName(options.schemaName, tempTypeName);\n const literalValues = options.values.map((value) => `'${escapeLiteral(value)}'`).join(', ');\n\n // CRITICAL: Collect columns from BOTH contract AND live database.\n // This ensures we migrate ALL dependent columns, including those added\n // outside of Prisma Next (e.g., manual DDL). Without this, DROP TYPE\n // would fail if the database has columns not tracked in the contract.\n const columnRefs = collectAllEnumColumns(\n options.contract,\n options.schema,\n options.typeName,\n options.nativeType,\n );\n\n const alterColumns = columnRefs.map((ref) => ({\n description: `alter ${ref.table}.${ref.column} to ${tempTypeName}`,\n sql: `ALTER TABLE ${qualifyName(options.schemaName, ref.table)}\nALTER COLUMN ${quoteIdentifier(ref.column)}\nTYPE ${qualifiedTemp}\nUSING ${quoteIdentifier(ref.column)}::text::${qualifiedTemp}`,\n }));\n\n // Build postchecks to verify:\n // 1. The final type exists with the correct name\n // 2. The temp type was cleaned up (renamed away)\n // 3. All migrated columns now reference the final type\n const postchecks = [\n {\n description: `verify type \"${options.nativeType}\" exists`,\n sql: enumTypeExistsCheck(options.schemaName, options.nativeType),\n },\n {\n description: `verify temp type \"${tempTypeName}\" was removed`,\n sql: enumTypeExistsCheck(options.schemaName, tempTypeName, false),\n },\n // Verify each column was successfully migrated to the final type\n ...columnRefs.map((ref) => ({\n description: `verify ${ref.table}.${ref.column} uses type \"${options.nativeType}\"`,\n sql: columnTypeCheck({\n schemaName: options.schemaName,\n tableName: ref.table,\n columnName: ref.column,\n expectedType: options.nativeType,\n }),\n })),\n ];\n\n return {\n id: `type.${options.typeName}.rebuild`,\n label: `Rebuild type ${options.typeName}`,\n summary: `Recreates enum type ${options.typeName} with updated values`,\n operationClass: 'destructive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: `ensure type \"${options.nativeType}\" exists`,\n sql: enumTypeExistsCheck(options.schemaName, options.nativeType),\n },\n // Note: We don't precheck that temp type doesn't exist because we handle\n // orphaned temp types in the execute step below.\n\n // CRITICAL: If values are being removed, verify no data exists using those values.\n // This prevents silent data loss during the rebuild - the USING cast would fail\n // at runtime if rows contain values that don't exist in the new enum.\n ...(options.removedValues.length > 0\n ? columnRefs.map((ref) => ({\n description: `ensure no rows in ${ref.table}.${ref.column} contain removed values (${options.removedValues.join(', ')})`,\n sql: noRemovedValuesExistCheck(\n options.schemaName,\n ref.table,\n ref.column,\n options.removedValues,\n ),\n }))\n : []),\n ],\n execute: [\n // Clean up any orphaned temp type from a previous failed migration.\n // This makes the operation recoverable without manual intervention.\n // DROP TYPE IF EXISTS is safe - it's a no-op if the type doesn't exist.\n {\n description: `drop orphaned temp type \"${tempTypeName}\" if exists`,\n sql: `DROP TYPE IF EXISTS ${qualifiedTemp}`,\n },\n {\n description: `create temp type \"${tempTypeName}\"`,\n sql: `CREATE TYPE ${qualifiedTemp} AS ENUM (${literalValues})`,\n },\n ...alterColumns,\n {\n description: `drop type \"${options.nativeType}\"`,\n sql: `DROP TYPE ${qualifiedOriginal}`,\n },\n {\n description: `rename type \"${tempTypeName}\" to \"${options.nativeType}\"`,\n sql: `ALTER TYPE ${qualifiedTemp} RENAME TO ${quoteIdentifier(options.nativeType)}`,\n },\n ],\n postcheck: postchecks,\n };\n}\n\n// ============================================================================\n// Codec Control Hooks\n// ============================================================================\n\n/**\n * Postgres enum hooks for planning, verifying, and introspecting `storage.types`.\n */\nexport const pgEnumControlHooks: CodecControlHooks = {\n planTypeOperations: ({ typeName, typeInstance, contract, schema, schemaName }) => {\n const desired = getEnumValues(typeInstance);\n if (!desired || desired.length === 0) {\n return { operations: [] };\n }\n\n const schemaNamespace = schemaName ?? 'public';\n const existing = readExistingEnumValues(schema, typeInstance.nativeType);\n if (!existing) {\n return {\n operations: [\n buildCreateEnumOperation(typeName, typeInstance.nativeType, schemaNamespace, desired),\n ],\n };\n }\n\n const diff = determineEnumDiff(existing, desired);\n if (diff.kind === 'unchanged') {\n return { operations: [] };\n }\n\n if (diff.kind === 'rebuild') {\n return {\n operations: [\n buildRecreateEnumOperation({\n typeName,\n nativeType: typeInstance.nativeType,\n schemaName: schemaNamespace,\n values: desired,\n removedValues: diff.removedValues,\n contract,\n schema,\n }),\n ],\n };\n }\n\n return {\n operations: buildAddValueOperations({\n typeName,\n nativeType: typeInstance.nativeType,\n schemaName: schemaNamespace,\n desired,\n existing,\n }),\n };\n },\n verifyType: ({ typeName, typeInstance, schema }) => {\n const desired = getEnumValues(typeInstance);\n if (!desired) {\n return [];\n }\n const existing = readExistingEnumValues(schema, typeInstance.nativeType);\n if (!existing) {\n return [\n {\n kind: 'type_missing',\n typeName,\n message: `Type \"${typeName}\" is missing from database`,\n },\n ];\n }\n const diff = determineEnumDiff(existing, desired);\n if (diff.kind === 'unchanged') return [];\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const addedValues = desired.filter((v) => !existingSet.has(v));\n const removedValues = existing.filter((v) => !desiredSet.has(v));\n return [\n {\n kind: 'enum_values_changed' as const,\n typeName,\n addedValues,\n removedValues,\n message:\n diff.kind === 'add_values'\n ? `Enum type \"${typeName}\" needs new values: ${addedValues.join(', ')}`\n : `Enum type \"${typeName}\" values changed (requires rebuild): +[${addedValues.join(', ')}] -[${removedValues.join(', ')}]`,\n },\n ];\n },\n introspectTypes: async ({ driver, schemaName }) => {\n const namespace = schemaName ?? 'public';\n const result = await driver.query<EnumRow>(ENUM_INTROSPECT_QUERY, [namespace]);\n const types: Record<string, StorageTypeInstance> = {};\n for (const row of result.rows) {\n const values = parsePostgresArray(row.values);\n if (!values) {\n throw new Error(\n `Failed to parse enum values for type \"${row.type_name}\": ` +\n `unexpected format: ${JSON.stringify(row.values)}`,\n );\n }\n types[row.type_name] = {\n codecId: PG_ENUM_CODEC_ID,\n nativeType: row.type_name,\n typeParams: { values },\n };\n }\n return types;\n },\n};\n","import type { CodecControlHooks, ExpandNativeTypeInput } from '@prisma-next/family-sql/control';\nimport type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_CHAR_CODEC_ID,\n PG_ENUM_CODEC_ID,\n PG_FLOAT_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n PG_VARCHAR_CODEC_ID,\n SQL_CHAR_CODEC_ID,\n SQL_FLOAT_CODEC_ID,\n SQL_INT_CODEC_ID,\n SQL_TEXT_CODEC_ID,\n SQL_TIMESTAMP_CODEC_ID,\n SQL_VARCHAR_CODEC_ID,\n} from './codec-ids';\nimport { codecDefinitions } from './codecs';\nimport { pgEnumControlHooks } from './enum-control-hooks';\n\n// ============================================================================\n// Helper functions for reducing boilerplate\n// ============================================================================\n\n/** Creates a type import spec for codec types */\nconst codecTypeImport = (named: string) =>\n ({\n package: '@prisma-next/adapter-postgres/codec-types',\n named,\n alias: named,\n }) as const;\n\nfunction isPositiveInteger(value: unknown): value is number {\n return (\n typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value > 0\n );\n}\n\nfunction isNonNegativeInteger(value: unknown): value is number {\n return (\n typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value >= 0\n );\n}\n\nfunction expandLength({ nativeType, typeParams }: ExpandNativeTypeInput): string {\n if (!typeParams || !('length' in typeParams)) {\n return nativeType;\n }\n const length = typeParams['length'];\n if (!isPositiveInteger(length)) {\n throw new Error(\n `Invalid \"length\" type parameter for \"${nativeType}\": expected a positive integer, got ${JSON.stringify(length)}`,\n );\n }\n return `${nativeType}(${length})`;\n}\n\nfunction expandPrecision({ nativeType, typeParams }: ExpandNativeTypeInput): string {\n if (!typeParams || !('precision' in typeParams)) {\n return nativeType;\n }\n const precision = typeParams['precision'];\n if (!isPositiveInteger(precision)) {\n throw new Error(\n `Invalid \"precision\" type parameter for \"${nativeType}\": expected a positive integer, got ${JSON.stringify(precision)}`,\n );\n }\n return `${nativeType}(${precision})`;\n}\n\nfunction expandNumeric({ nativeType, typeParams }: ExpandNativeTypeInput): string {\n const hasPrecision = typeParams && 'precision' in typeParams;\n const hasScale = typeParams && 'scale' in typeParams;\n\n if (!hasPrecision && !hasScale) {\n return nativeType;\n }\n\n if (!hasPrecision && hasScale) {\n throw new Error(\n `Invalid type parameters for \"${nativeType}\": \"scale\" requires \"precision\" to be specified`,\n );\n }\n\n if (hasPrecision) {\n const precision = typeParams['precision'];\n if (!isPositiveInteger(precision)) {\n throw new Error(\n `Invalid \"precision\" type parameter for \"${nativeType}\": expected a positive integer, got ${JSON.stringify(precision)}`,\n );\n }\n if (hasScale) {\n const scale = typeParams['scale'];\n if (!isNonNegativeInteger(scale)) {\n throw new Error(\n `Invalid \"scale\" type parameter for \"${nativeType}\": expected a non-negative integer, got ${JSON.stringify(scale)}`,\n );\n }\n return `${nativeType}(${precision},${scale})`;\n }\n return `${nativeType}(${precision})`;\n }\n\n return nativeType;\n}\n\nconst lengthHooks: CodecControlHooks = { expandNativeType: expandLength };\nconst precisionHooks: CodecControlHooks = { expandNativeType: expandPrecision };\nconst numericHooks: CodecControlHooks = { expandNativeType: expandNumeric };\nconst identityHooks: CodecControlHooks = { expandNativeType: ({ nativeType }) => nativeType };\n\n// ============================================================================\n// Descriptor metadata\n// ============================================================================\n\nexport const postgresQueryOperations: readonly SqlOperationDescriptor[] = [\n {\n method: 'ilike',\n args: [\n { traits: ['textual'], nullable: false },\n { codecId: PG_TEXT_CODEC_ID, nullable: false },\n ],\n returns: { codecId: PG_BOOL_CODEC_ID, nullable: false },\n lowering: { targetFamily: 'sql', strategy: 'infix', template: '{{self}} ILIKE {{arg0}}' },\n },\n];\n\nexport const postgresAdapterDescriptorMeta = {\n kind: 'adapter',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n orderBy: true,\n limit: true,\n lateral: true,\n jsonAgg: true,\n returning: true,\n },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n },\n },\n types: {\n codecTypes: {\n codecInstances: Object.values(codecDefinitions).map((def) => def.codec),\n import: {\n package: '@prisma-next/adapter-postgres/codec-types',\n named: 'CodecTypes',\n alias: 'PgTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/adapter-postgres/codec-types',\n named: 'JsonValue',\n alias: 'JsonValue',\n },\n codecTypeImport('Char'),\n codecTypeImport('Varchar'),\n codecTypeImport('Numeric'),\n codecTypeImport('Bit'),\n codecTypeImport('VarBit'),\n codecTypeImport('Timestamp'),\n codecTypeImport('Timestamptz'),\n codecTypeImport('Time'),\n codecTypeImport('Timetz'),\n codecTypeImport('Interval'),\n ],\n controlPlaneHooks: {\n [SQL_CHAR_CODEC_ID]: lengthHooks,\n [SQL_VARCHAR_CODEC_ID]: lengthHooks,\n [SQL_TIMESTAMP_CODEC_ID]: precisionHooks,\n [PG_CHAR_CODEC_ID]: lengthHooks,\n [PG_VARCHAR_CODEC_ID]: lengthHooks,\n [PG_NUMERIC_CODEC_ID]: numericHooks,\n [PG_BIT_CODEC_ID]: lengthHooks,\n [PG_VARBIT_CODEC_ID]: lengthHooks,\n [PG_TIMESTAMP_CODEC_ID]: precisionHooks,\n [PG_TIMESTAMPTZ_CODEC_ID]: precisionHooks,\n [PG_TIME_CODEC_ID]: precisionHooks,\n [PG_TIMETZ_CODEC_ID]: precisionHooks,\n [PG_INTERVAL_CODEC_ID]: precisionHooks,\n [PG_ENUM_CODEC_ID]: pgEnumControlHooks,\n [PG_JSON_CODEC_ID]: identityHooks,\n [PG_JSONB_CODEC_ID]: identityHooks,\n },\n },\n storage: [\n { typeId: PG_TEXT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'text' },\n { typeId: SQL_TEXT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'text' },\n { typeId: SQL_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },\n {\n typeId: SQL_VARCHAR_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'character varying',\n },\n { typeId: SQL_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },\n { typeId: SQL_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },\n {\n typeId: SQL_TIMESTAMP_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'timestamp',\n },\n { typeId: PG_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },\n {\n typeId: PG_VARCHAR_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'character varying',\n },\n { typeId: PG_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },\n { typeId: PG_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },\n { typeId: PG_INT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },\n { typeId: PG_INT2_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int2' },\n { typeId: PG_INT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int8' },\n { typeId: PG_FLOAT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float4' },\n { typeId: PG_FLOAT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },\n { typeId: PG_NUMERIC_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'numeric' },\n {\n typeId: PG_TIMESTAMP_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'timestamp',\n },\n {\n typeId: PG_TIMESTAMPTZ_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'timestamptz',\n },\n { typeId: PG_TIME_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'time' },\n { typeId: PG_TIMETZ_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'timetz' },\n { typeId: PG_BOOL_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bool' },\n { typeId: PG_BIT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bit' },\n {\n typeId: PG_VARBIT_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'bit varying',\n },\n {\n typeId: PG_INTERVAL_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'interval',\n },\n { typeId: PG_JSON_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'json' },\n { typeId: PG_JSONB_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'jsonb' },\n ],\n queryOperationTypes: {\n import: {\n package: '@prisma-next/adapter-postgres/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PgAdapterQueryOps',\n },\n },\n },\n} as const;\n"],"mappings":";;;;;;AA8BA,MAAM,wBAAwB;;;;;;;;;;;;;;;AAoB9B,SAAS,cAAc,OAAmC;AACxD,QAAO,MAAM,QAAQ,MAAM,IAAI,MAAM,OAAO,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;AAiBlF,SAAgB,mBAAmB,OAAiC;AAClE,KAAI,cAAc,MAAM,CACtB,QAAO;AAET,KAAI,OAAO,UAAU,YAAY,MAAM,WAAW,IAAI,IAAI,MAAM,SAAS,IAAI,EAAE;EAC7E,MAAM,QAAQ,MAAM,MAAM,GAAG,GAAG;AAChC,MAAI,UAAU,GACZ,QAAO,EAAE;AAEX,SAAO,mBAAmB,MAAM;;AAElC,QAAO;;AAGT,SAAS,mBAAmB,OAAyB;CACnD,MAAMA,SAAmB,EAAE;CAC3B,IAAI,IAAI;AACR,QAAO,IAAI,MAAM,QAAQ;AACvB,MAAI,MAAM,OAAO,KAAK;AACpB;AACA;;AAEF,MAAI,MAAM,OAAO,MAAK;AACpB;GACA,IAAI,UAAU;AACd,UAAO,IAAI,MAAM,UAAU,MAAM,OAAO,MAAK;AAC3C,QAAI,MAAM,OAAO,QAAQ,IAAI,IAAI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