@prisma-next/target-postgres 0.5.0-dev.4 → 0.5.0-dev.41
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/codec-types.d.mts +1 -1
- package/dist/codec-types.mjs +1 -1
- package/dist/{codecs-D-F2KJqt.d.mts → codecs-CE5EUsNM.d.mts} +54 -30
- package/dist/codecs-CE5EUsNM.d.mts.map +1 -0
- package/dist/{codecs-BoahtY_Q.mjs → codecs-dzZ_dMpK.mjs} +7 -102
- package/dist/codecs-dzZ_dMpK.mjs.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +1 -1
- package/dist/control.mjs +17 -9
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-VfEGzXWt.mjs → data-transform-C83dy0vk.mjs} +3 -1
- package/dist/data-transform-C83dy0vk.mjs.map +1 -0
- package/dist/{data-transform-CxFRBIUp.d.mts → data-transform-D8x5m1YV.d.mts} +7 -1
- package/dist/data-transform-D8x5m1YV.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/migration.d.mts +2 -2
- package/dist/migration.mjs +2 -2
- package/dist/op-factory-call-C3bWXKSP.d.mts.map +1 -1
- package/dist/pack.d.mts +1 -1
- package/dist/{planner-CLUvVhUN.mjs → planner-B4ZSLHRI.mjs} +6 -6
- package/dist/planner-B4ZSLHRI.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs → planner-produced-postgres-migration-C0GNhHGw.mjs} +3 -4
- package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs.map → planner-produced-postgres-migration-C0GNhHGw.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-CRRTno6Z.d.mts → planner-produced-postgres-migration-Dw_mPMKt.d.mts} +2 -2
- package/dist/planner-produced-postgres-migration-Dw_mPMKt.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +2 -2
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/planner.d.mts +15 -9
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-migration-BjA3Zmts.d.mts → postgres-migration-DcfWGqhe.d.mts} +2 -2
- package/dist/{postgres-migration-BjA3Zmts.d.mts.map → postgres-migration-DcfWGqhe.d.mts.map} +1 -1
- package/dist/{postgres-migration-qtmtbONe.mjs → postgres-migration-EGSlO4jO.mjs} +2 -2
- package/dist/{postgres-migration-qtmtbONe.mjs.map → postgres-migration-EGSlO4jO.mjs.map} +1 -1
- package/dist/{render-typescript-1rF_SB4g.mjs → render-typescript-Co3Emwgz.mjs} +1 -2
- package/dist/render-typescript-Co3Emwgz.mjs.map +1 -0
- package/dist/render-typescript.d.mts +1 -2
- package/dist/render-typescript.d.mts.map +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/dist/{statement-builders-BPnmt6wx.mjs → statement-builders-CHqCtSfe.mjs} +13 -8
- package/dist/statement-builders-CHqCtSfe.mjs.map +1 -0
- package/dist/statement-builders.d.mts +10 -3
- package/dist/statement-builders.d.mts.map +1 -1
- package/dist/statement-builders.mjs +2 -2
- package/package.json +18 -15
- package/src/core/codecs.ts +17 -40
- package/src/core/migrations/operations/data-transform.ts +8 -0
- package/src/core/migrations/planner-produced-postgres-migration.ts +0 -1
- package/src/core/migrations/planner.ts +17 -11
- package/src/core/migrations/render-typescript.ts +1 -5
- package/src/core/migrations/runner.ts +45 -9
- package/src/core/migrations/statement-builders.ts +22 -6
- package/src/exports/statement-builders.ts +1 -1
- package/dist/codecs-BoahtY_Q.mjs.map +0 -1
- package/dist/codecs-D-F2KJqt.d.mts.map +0 -1
- package/dist/data-transform-CxFRBIUp.d.mts.map +0 -1
- package/dist/data-transform-VfEGzXWt.mjs.map +0 -1
- package/dist/planner-CLUvVhUN.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-CRRTno6Z.d.mts.map +0 -1
- package/dist/render-typescript-1rF_SB4g.mjs.map +0 -1
- package/dist/statement-builders-BPnmt6wx.mjs.map +0 -1
- package/src/core/json-schema-type-expression.ts +0 -131
package/dist/codec-types.d.mts
CHANGED
package/dist/codec-types.mjs
CHANGED
|
@@ -10,9 +10,7 @@ declare const codecs: _prisma_next_sql_relational_core_ast0.CodecDefBuilder<{
|
|
|
10
10
|
int: Codec<"sql/int@1", readonly ["equality", "order", "numeric"], number, number, Record<string, unknown>, unknown>;
|
|
11
11
|
float: Codec<"sql/float@1", readonly ["equality", "order", "numeric"], number, number, Record<string, unknown>, unknown>;
|
|
12
12
|
"sql-text": Codec<"sql/text@1", readonly ["equality", "order", "textual"], string, string, Record<string, unknown>, unknown>;
|
|
13
|
-
"sql-timestamp": Codec<"sql/timestamp@1", readonly ["equality", "order"],
|
|
14
|
-
precision?: number;
|
|
15
|
-
}, unknown>;
|
|
13
|
+
"sql-timestamp": Codec<"sql/timestamp@1", readonly ["equality", "order"], Date, Date, Record<string, unknown>, unknown>;
|
|
16
14
|
text: Codec<"pg/text@1", readonly ["equality", "order", "textual"], string, string, Record<string, unknown>, unknown>;
|
|
17
15
|
character: Codec<"pg/char@1", readonly ["equality", "order", "textual"], string, string, Record<string, unknown>, unknown>;
|
|
18
16
|
"character varying": Codec<"pg/varchar@1", readonly ["equality", "order", "textual"], string, string, Record<string, unknown>, unknown>;
|
|
@@ -24,8 +22,8 @@ declare const codecs: _prisma_next_sql_relational_core_ast0.CodecDefBuilder<{
|
|
|
24
22
|
float4: Codec<"pg/float4@1", readonly ["equality", "order", "numeric"], number, number, Record<string, unknown>, unknown>;
|
|
25
23
|
float8: Codec<"pg/float8@1", readonly ["equality", "order", "numeric"], number, number, Record<string, unknown>, unknown>;
|
|
26
24
|
numeric: Codec<"pg/numeric@1", readonly ["equality", "order", "numeric"], string, string, Record<string, unknown>, unknown>;
|
|
27
|
-
timestamp: Codec<"pg/timestamp@1", readonly ["equality", "order"],
|
|
28
|
-
timestamptz: Codec<"pg/timestamptz@1", readonly ["equality", "order"],
|
|
25
|
+
timestamp: Codec<"pg/timestamp@1", readonly ["equality", "order"], Date, Date, Record<string, unknown>, unknown>;
|
|
26
|
+
timestamptz: Codec<"pg/timestamptz@1", readonly ["equality", "order"], Date, Date, Record<string, unknown>, unknown>;
|
|
29
27
|
time: Codec<"pg/time@1", readonly ["equality", "order"], string, string, Record<string, unknown>, unknown>;
|
|
30
28
|
timetz: Codec<"pg/timetz@1", readonly ["equality", "order"], string, string, Record<string, unknown>, unknown>;
|
|
31
29
|
bool: Codec<"pg/bool@1", readonly ["equality", "boolean"], boolean, boolean, Record<string, unknown>, unknown>;
|
|
@@ -33,8 +31,16 @@ declare const codecs: _prisma_next_sql_relational_core_ast0.CodecDefBuilder<{
|
|
|
33
31
|
"bit varying": Codec<"pg/varbit@1", readonly ["equality", "order"], string, string, Record<string, unknown>, unknown>;
|
|
34
32
|
interval: Codec<"pg/interval@1", readonly ["equality", "order"], string | Record<string, unknown>, string, Record<string, unknown>, unknown>;
|
|
35
33
|
enum: Codec<"pg/enum@1", readonly ["equality", "order"], string, string, Record<string, unknown>, unknown>;
|
|
36
|
-
json: Codec<"pg/json@1", readonly [], string
|
|
37
|
-
|
|
34
|
+
json: Codec<"pg/json@1", readonly [], string | number | boolean | {
|
|
35
|
+
readonly [key: string]: JsonValue;
|
|
36
|
+
} | readonly JsonValue[] | null, string | number | boolean | {
|
|
37
|
+
readonly [key: string]: JsonValue;
|
|
38
|
+
} | readonly JsonValue[] | null, Record<string, unknown>, unknown>;
|
|
39
|
+
} & Record<"jsonb", Codec<"pg/jsonb@1", readonly ["equality"], string | number | boolean | {
|
|
40
|
+
readonly [key: string]: JsonValue;
|
|
41
|
+
} | readonly JsonValue[] | null, string | number | boolean | {
|
|
42
|
+
readonly [key: string]: JsonValue;
|
|
43
|
+
} | readonly JsonValue[] | null, Record<string, unknown>, unknown>>>;
|
|
38
44
|
declare const codecDefinitions: {
|
|
39
45
|
readonly char: {
|
|
40
46
|
readonly typeId: "sql/char@1";
|
|
@@ -79,12 +85,10 @@ declare const codecDefinitions: {
|
|
|
79
85
|
readonly "sql-timestamp": {
|
|
80
86
|
readonly typeId: "sql/timestamp@1";
|
|
81
87
|
readonly scalar: "sql-timestamp";
|
|
82
|
-
readonly codec: Codec<"sql/timestamp@1", readonly ["equality", "order"],
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
readonly
|
|
86
|
-
readonly output: string;
|
|
87
|
-
readonly jsType: string;
|
|
88
|
+
readonly codec: Codec<"sql/timestamp@1", readonly ["equality", "order"], Date, Date, Record<string, unknown>, unknown>;
|
|
89
|
+
readonly input: Date;
|
|
90
|
+
readonly output: Date;
|
|
91
|
+
readonly jsType: Date;
|
|
88
92
|
};
|
|
89
93
|
readonly text: {
|
|
90
94
|
readonly typeId: "pg/text@1";
|
|
@@ -177,18 +181,18 @@ declare const codecDefinitions: {
|
|
|
177
181
|
readonly timestamp: {
|
|
178
182
|
readonly typeId: "pg/timestamp@1";
|
|
179
183
|
readonly scalar: "timestamp";
|
|
180
|
-
readonly codec: Codec<"pg/timestamp@1", readonly ["equality", "order"],
|
|
181
|
-
readonly input:
|
|
182
|
-
readonly output:
|
|
183
|
-
readonly jsType:
|
|
184
|
+
readonly codec: Codec<"pg/timestamp@1", readonly ["equality", "order"], Date, Date, Record<string, unknown>, unknown>;
|
|
185
|
+
readonly input: Date;
|
|
186
|
+
readonly output: Date;
|
|
187
|
+
readonly jsType: Date;
|
|
184
188
|
};
|
|
185
189
|
readonly timestamptz: {
|
|
186
190
|
readonly typeId: "pg/timestamptz@1";
|
|
187
191
|
readonly scalar: "timestamptz";
|
|
188
|
-
readonly codec: Codec<"pg/timestamptz@1", readonly ["equality", "order"],
|
|
189
|
-
readonly input:
|
|
190
|
-
readonly output:
|
|
191
|
-
readonly jsType:
|
|
192
|
+
readonly codec: Codec<"pg/timestamptz@1", readonly ["equality", "order"], Date, Date, Record<string, unknown>, unknown>;
|
|
193
|
+
readonly input: Date;
|
|
194
|
+
readonly output: Date;
|
|
195
|
+
readonly jsType: Date;
|
|
192
196
|
};
|
|
193
197
|
readonly time: {
|
|
194
198
|
readonly typeId: "pg/time@1";
|
|
@@ -249,18 +253,38 @@ declare const codecDefinitions: {
|
|
|
249
253
|
readonly json: {
|
|
250
254
|
readonly typeId: "pg/json@1";
|
|
251
255
|
readonly scalar: "json";
|
|
252
|
-
readonly codec: Codec<"pg/json@1", readonly [], string
|
|
253
|
-
|
|
254
|
-
readonly
|
|
255
|
-
|
|
256
|
+
readonly codec: Codec<"pg/json@1", readonly [], string | number | boolean | {
|
|
257
|
+
readonly [key: string]: JsonValue;
|
|
258
|
+
} | readonly JsonValue[] | null, string | number | boolean | {
|
|
259
|
+
readonly [key: string]: JsonValue;
|
|
260
|
+
} | readonly JsonValue[] | null, Record<string, unknown>, unknown>;
|
|
261
|
+
readonly input: string | number | boolean | {
|
|
262
|
+
readonly [key: string]: JsonValue;
|
|
263
|
+
} | readonly JsonValue[] | null;
|
|
264
|
+
readonly output: string | number | boolean | {
|
|
265
|
+
readonly [key: string]: JsonValue;
|
|
266
|
+
} | readonly JsonValue[] | null;
|
|
267
|
+
readonly jsType: string | number | boolean | {
|
|
268
|
+
readonly [key: string]: JsonValue;
|
|
269
|
+
} | readonly JsonValue[] | null;
|
|
256
270
|
};
|
|
257
271
|
readonly jsonb: {
|
|
258
272
|
readonly typeId: "pg/jsonb@1";
|
|
259
273
|
readonly scalar: "jsonb";
|
|
260
|
-
readonly codec: Codec<"pg/jsonb@1", readonly ["equality"], string
|
|
261
|
-
|
|
262
|
-
readonly
|
|
263
|
-
|
|
274
|
+
readonly codec: Codec<"pg/jsonb@1", readonly ["equality"], string | number | boolean | {
|
|
275
|
+
readonly [key: string]: JsonValue;
|
|
276
|
+
} | readonly JsonValue[] | null, string | number | boolean | {
|
|
277
|
+
readonly [key: string]: JsonValue;
|
|
278
|
+
} | readonly JsonValue[] | null, Record<string, unknown>, unknown>;
|
|
279
|
+
readonly input: string | number | boolean | {
|
|
280
|
+
readonly [key: string]: JsonValue;
|
|
281
|
+
} | readonly JsonValue[] | null;
|
|
282
|
+
readonly output: string | number | boolean | {
|
|
283
|
+
readonly [key: string]: JsonValue;
|
|
284
|
+
} | readonly JsonValue[] | null;
|
|
285
|
+
readonly jsType: string | number | boolean | {
|
|
286
|
+
readonly [key: string]: JsonValue;
|
|
287
|
+
} | readonly JsonValue[] | null;
|
|
264
288
|
};
|
|
265
289
|
};
|
|
266
290
|
declare const dataTypes: {
|
|
@@ -296,4 +320,4 @@ declare const dataTypes: {
|
|
|
296
320
|
type CodecTypes = typeof codecs.CodecTypes;
|
|
297
321
|
//#endregion
|
|
298
322
|
export { codecDefinitions as n, dataTypes as r, CodecTypes as t };
|
|
299
|
-
//# sourceMappingURL=codecs-
|
|
323
|
+
//# sourceMappingURL=codecs-CE5EUsNM.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs-CE5EUsNM.d.mts","names":[],"sources":["../src/core/codecs.ts"],"sourcesContent":[],"mappings":";;;;;;cA2kBM,8CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BC;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA/BD,SAAA,KAAA,OAAA,CAAA,aAAA,EAAA,SAAA,CAAA,UAAA,EAAA,OAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,MAAA,QAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,CAAA;IA+BC,SAAA,KAAA,EAA0C,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC1C,SAA4B,MAAA,EAAA,QAAA;IAE7B,SAAU,KAAA,OAAA,CAAU,aAAO,EAAA,SAAU,CAAA,UAAA,EAAA,OAAA,EAAA,SAAA,CAAA,EAAA,MAAA,EAAA,MAAA,QAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAFpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAED,UAAA,UAAoB,MAAA,CAAO"}
|
|
@@ -3,78 +3,6 @@ import { codec, defineCodecs, sqlCodecDefinitions } from "@prisma-next/sql-relat
|
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
4
|
import { type } from "arktype";
|
|
5
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
6
|
//#region src/core/codecs.ts
|
|
79
7
|
const lengthParamsSchema = type({ length: "number.integer > 0" });
|
|
80
8
|
const numericParamsSchema = type({
|
|
@@ -94,13 +22,6 @@ function renderPrecision(typeName, typeParams) {
|
|
|
94
22
|
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
23
|
return `${typeName}<${precision}>`;
|
|
96
24
|
}
|
|
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
25
|
function aliasCodec(base, options) {
|
|
105
26
|
return {
|
|
106
27
|
id: options.typeId,
|
|
@@ -241,16 +162,9 @@ const pgTimestampCodec = codec({
|
|
|
241
162
|
typeId: PG_TIMESTAMP_CODEC_ID,
|
|
242
163
|
targetTypes: ["timestamp"],
|
|
243
164
|
traits: ["equality", "order"],
|
|
244
|
-
encode: (value) =>
|
|
245
|
-
|
|
246
|
-
|
|
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,
|
|
165
|
+
encode: (value) => value,
|
|
166
|
+
decode: (wire) => wire,
|
|
167
|
+
encodeJson: (value) => value.toISOString(),
|
|
254
168
|
decodeJson: (json) => {
|
|
255
169
|
if (typeof json !== "string") throw new Error(`Expected ISO date string for pg/timestamp@1, got ${typeof json}`);
|
|
256
170
|
const date = new Date(json);
|
|
@@ -265,16 +179,9 @@ const pgTimestamptzCodec = codec({
|
|
|
265
179
|
typeId: PG_TIMESTAMPTZ_CODEC_ID,
|
|
266
180
|
targetTypes: ["timestamptz"],
|
|
267
181
|
traits: ["equality", "order"],
|
|
268
|
-
encode: (value) =>
|
|
269
|
-
|
|
270
|
-
|
|
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,
|
|
182
|
+
encode: (value) => value,
|
|
183
|
+
decode: (wire) => wire,
|
|
184
|
+
encodeJson: (value) => value.toISOString(),
|
|
278
185
|
decodeJson: (json) => {
|
|
279
186
|
if (typeof json !== "string") throw new Error(`Expected ISO date string for pg/timestamptz@1, got ${typeof json}`);
|
|
280
187
|
const date = new Date(json);
|
|
@@ -364,7 +271,6 @@ const pgJsonCodec = codec({
|
|
|
364
271
|
traits: [],
|
|
365
272
|
encode: (value) => JSON.stringify(value),
|
|
366
273
|
decode: (wire) => typeof wire === "string" ? JSON.parse(wire) : wire,
|
|
367
|
-
renderOutputType: renderJsonOutputType,
|
|
368
274
|
meta: { db: { sql: { postgres: { nativeType: "json" } } } }
|
|
369
275
|
});
|
|
370
276
|
const pgJsonbCodec = codec({
|
|
@@ -373,7 +279,6 @@ const pgJsonbCodec = codec({
|
|
|
373
279
|
traits: ["equality"],
|
|
374
280
|
encode: (value) => JSON.stringify(value),
|
|
375
281
|
decode: (wire) => typeof wire === "string" ? JSON.parse(wire) : wire,
|
|
376
|
-
renderOutputType: renderJsonOutputType,
|
|
377
282
|
meta: { db: { sql: { postgres: { nativeType: "jsonb" } } } }
|
|
378
283
|
});
|
|
379
284
|
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);
|
|
@@ -382,4 +287,4 @@ const dataTypes = codecs.dataTypes;
|
|
|
382
287
|
|
|
383
288
|
//#endregion
|
|
384
289
|
export { dataTypes as n, codecDefinitions as t };
|
|
385
|
-
//# sourceMappingURL=codecs-
|
|
290
|
+
//# sourceMappingURL=codecs-dzZ_dMpK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs-dzZ_dMpK.mjs","names":["arktype"],"sources":["../src/core/codecs.ts"],"sourcesContent":["/**\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';\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\n// Phase C: postgres' raw json/jsonb codecs no longer carry a\n// `renderOutputType` slot — the schema-typed JSON surface that drove\n// `typeParams: { schemaJson, type? }` retired in favor of the per-library\n// extension package (`@prisma-next/extension-arktype-json`). Untyped\n// json/jsonb columns have no typeParams; the framework emit path falls\n// through to the generic `CodecTypes['pg/jsonb@1']['output']` accessor\n// (which resolves to `JsonValue` via the codec-types map).\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 Date,\n Date\n>({\n typeId: PG_TIMESTAMP_CODEC_ID,\n targetTypes: ['timestamp'],\n traits: ['equality', 'order'],\n encode: (value: Date): Date => value,\n decode: (wire: Date): Date => wire,\n encodeJson: (value: Date) => value.toISOString(),\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 Date,\n Date\n>({\n typeId: PG_TIMESTAMPTZ_CODEC_ID,\n targetTypes: ['timestamptz'],\n traits: ['equality', 'order'],\n encode: (value: Date): Date => value,\n decode: (wire: Date): Date => wire,\n encodeJson: (value: Date) => value.toISOString(),\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 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 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":";;;;;;AA2CA,MAAM,qBAAqBA,KAAQ,EACjC,QAAQ,sBACT,CAAC;AAEF,MAAM,sBAAsBA,KAAQ;CAClC,WAAW;CACX,UAAU;CACX,CAAC;AAEF,MAAM,wBAAwBA,KAAQ,EACpC,cAAc,6CACf,CAAC;AAEF,SAAS,aAAa,UAAkB,YAAyD;CAC/F,MAAM,SAAS,WAAW;AAC1B,KAAI,WAAW,OACb;AAEF,KAAI,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,OAAO,IAAI,CAAC,OAAO,UAAU,OAAO,CACrF,OAAM,IAAI,MACR,iEAAiE,SAAS,QAAQ,OAAO,OAAO,GACjG;AAEH,QAAO,GAAG,SAAS,GAAG,OAAO;;AAG/B,SAAS,gBAAgB,UAAkB,YAA6C;CACtF,MAAM,YAAY,WAAW;AAC7B,KAAI,cAAc,OAChB,QAAO;AAET,KACE,OAAO,cAAc,YACrB,CAAC,OAAO,SAAS,UAAU,IAC3B,CAAC,OAAO,UAAU,UAAU,CAE5B,OAAM,IAAI,MACR,oEAAoE,SAAS,QAAQ,OAAO,UAAU,GACvG;AAEH,QAAO,GAAG,SAAS,GAAG,UAAU;;AAWlC,SAAS,WAQP,MACA,SA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ACtB,IAAI,eAAe,cAAc,CACjC,IAAI,YAAY,gBAAgB,CAChC,IAAI,QAAQ,YAAY,CACxB,IAAI,QAAQ,YAAY,CACxB,IAAI,SAAS,aAAa;AAG7B,MAAa,mBAAmB,OAAO;AACvC,MAAa,YAAY,OAAO"}
|
package/dist/codecs.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as codecDefinitions, r as dataTypes, t as CodecTypes } from "./codecs-
|
|
1
|
+
import { n as codecDefinitions, r as dataTypes, t as CodecTypes } from "./codecs-CE5EUsNM.mjs";
|
|
2
2
|
export { type CodecTypes, codecDefinitions, dataTypes };
|
package/dist/codecs.mjs
CHANGED
package/dist/control.mjs
CHANGED
|
@@ -3,13 +3,12 @@ import { t as parsePostgresDefault } from "./default-normalizer-DNOpRoOF.mjs";
|
|
|
3
3
|
import { t as normalizeSchemaNativeType } from "./native-type-normalizer-CInai_oY.mjs";
|
|
4
4
|
import { o as renderDefaultLiteral } from "./planner-ddl-builders-Dxvw1LHw.mjs";
|
|
5
5
|
import "./issue-planner-CFjB0_oO.mjs";
|
|
6
|
-
import { t as createPostgresMigrationPlanner } from "./planner-
|
|
7
|
-
import { a as ensurePrismaContractSchemaStatement, i as ensureMarkerTableStatement, n as
|
|
6
|
+
import { t as createPostgresMigrationPlanner } from "./planner-B4ZSLHRI.mjs";
|
|
7
|
+
import { a as ensurePrismaContractSchemaStatement, i as ensureMarkerTableStatement, n as buildMergeMarkerStatements, r as ensureLedgerTableStatement, t as buildLedgerInsertStatement } from "./statement-builders-CHqCtSfe.mjs";
|
|
8
8
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
9
9
|
import { contractToSchemaIR, extractCodecControlHooks, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
|
|
10
10
|
import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
|
|
11
11
|
import { ok, okVoid } from "@prisma-next/utils/result";
|
|
12
|
-
import { readMarker } from "@prisma-next/family-sql/verify";
|
|
13
12
|
import { SqlQueryError } from "@prisma-next/sql-errors";
|
|
14
13
|
|
|
15
14
|
//#region src/core/migrations/runner.ts
|
|
@@ -54,10 +53,12 @@ var PostgresMigrationRunner = class {
|
|
|
54
53
|
try {
|
|
55
54
|
await this.acquireLock(driver, lockKey);
|
|
56
55
|
await this.ensureControlTables(driver);
|
|
57
|
-
const existingMarker = await readMarker(driver);
|
|
56
|
+
const existingMarker = await this.family.readMarker({ driver });
|
|
58
57
|
const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);
|
|
59
58
|
if (!markerCheck.ok) return markerCheck;
|
|
60
|
-
const
|
|
59
|
+
const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);
|
|
60
|
+
const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;
|
|
61
|
+
const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;
|
|
61
62
|
let applyValue;
|
|
62
63
|
if (skipOperations) applyValue = {
|
|
63
64
|
operationsExecuted: 0,
|
|
@@ -86,8 +87,13 @@ var PostgresMigrationRunner = class {
|
|
|
86
87
|
why: "The resulting database schema does not satisfy the destination contract.",
|
|
87
88
|
meta: { issues: schemaVerifyResult.schema.issues }
|
|
88
89
|
});
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
const incomingInvariants = options.plan.providedInvariants;
|
|
91
|
+
const existingInvariants = new Set(existingMarker?.invariants ?? []);
|
|
92
|
+
const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));
|
|
93
|
+
if (!(isSelfEdge && applyValue.operationsExecuted === 0 && incomingIsSubsetOfExisting)) {
|
|
94
|
+
await this.upsertMarker(driver, options, existingMarker);
|
|
95
|
+
await this.recordLedgerEntry(driver, options, existingMarker, applyValue.executedOperations);
|
|
96
|
+
}
|
|
91
97
|
await this.commitTransaction(driver);
|
|
92
98
|
committed = true;
|
|
93
99
|
return runnerSuccess({
|
|
@@ -308,12 +314,14 @@ var PostgresMigrationRunner = class {
|
|
|
308
314
|
return okVoid();
|
|
309
315
|
}
|
|
310
316
|
async upsertMarker(driver, options, existingMarker) {
|
|
311
|
-
const
|
|
317
|
+
const incomingInvariants = options.plan.providedInvariants;
|
|
318
|
+
const writeStatements = buildMergeMarkerStatements({
|
|
312
319
|
storageHash: options.plan.destination.storageHash,
|
|
313
320
|
profileHash: options.plan.destination.profileHash ?? options.destinationContract.profileHash ?? options.plan.destination.storageHash,
|
|
314
321
|
contractJson: options.destinationContract,
|
|
315
322
|
canonicalVersion: null,
|
|
316
|
-
meta: {}
|
|
323
|
+
meta: {},
|
|
324
|
+
invariants: incomingInvariants
|
|
317
325
|
});
|
|
318
326
|
const statement = existingMarker ? writeStatements.update : writeStatements.insert;
|
|
319
327
|
await this.executeStatement(driver, statement);
|