@prisma/orm-family-sql 8.0.0-rc.12-dev.13 → 8.0.0-rc.12-dev.15
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/contract-prisma7__provider.mjs +3 -3
- package/dist/contract-prisma7__provider.mjs.map +1 -1
- package/dist/contract-psl.d.mts +2 -2
- package/dist/contract-psl.d.mts.map +1 -1
- package/dist/contract-psl.mjs +1 -1
- package/dist/contract-psl__attribute-specs.d.mts +1 -1
- package/dist/contract-psl__attribute-specs.d.mts.map +1 -1
- package/dist/contract-psl__map-names.d.mts +16 -0
- package/dist/contract-psl__map-names.d.mts.map +1 -0
- package/dist/contract-psl__map-names.mjs +21 -0
- package/dist/contract-psl__map-names.mjs.map +1 -0
- package/dist/contract-psl__provider.mjs +1 -1
- package/dist/contract-psl__provider.mjs.map +1 -1
- package/dist/{control-BynSKZfp.mjs → control-BoloIwBt.mjs} +17 -1
- package/dist/control-BoloIwBt.mjs.map +1 -0
- package/dist/{control-BLOiyNq-.d.mts → control-DftpYMXw.d.mts} +18 -5
- package/dist/control-DftpYMXw.d.mts.map +1 -0
- package/dist/family.d.mts +5 -3
- package/dist/family.mjs +4 -2
- package/dist/family__control.d.mts +2 -2
- package/dist/family__control.mjs +1 -1
- package/dist/family__psl-build.d.mts +3 -0
- package/dist/family__psl-build.mjs +3 -0
- package/dist/family__psl-infer.d.mts +2 -2
- package/dist/family__psl-infer.mjs +2 -2
- package/dist/{interpreter-Cy7S6Jh9-BIa0lyc-.mjs → interpreter-BrW0_y8Q-Dl5e-p7f.mjs} +26 -40
- package/dist/interpreter-BrW0_y8Q-Dl5e-p7f.mjs.map +1 -0
- package/dist/psl-build-Cp32ahjI.mjs +224 -0
- package/dist/psl-build-Cp32ahjI.mjs.map +1 -0
- package/dist/psl-build-yBrQQN3r.d.mts +13 -0
- package/dist/psl-build-yBrQQN3r.d.mts.map +1 -0
- package/dist/{psl-infer-CuTqC9UV.d.mts → psl-infer-BzjA7U3b.d.mts} +3 -50
- package/dist/psl-infer-BzjA7U3b.d.mts.map +1 -0
- package/dist/psl-infer-DwMyO-IV.mjs +195 -0
- package/dist/psl-infer-DwMyO-IV.mjs.map +1 -0
- package/dist/psl-names-C3cwe0rg-CsuHOV7E.mjs +66 -0
- package/dist/psl-names-C3cwe0rg-CsuHOV7E.mjs.map +1 -0
- package/dist/type-map-BwBI56i3-DDERtzxf.d.mts +49 -0
- package/dist/type-map-BwBI56i3-DDERtzxf.d.mts.map +1 -0
- package/package.json +20 -18
- package/dist/control-BLOiyNq-.d.mts.map +0 -1
- package/dist/control-BynSKZfp.mjs.map +0 -1
- package/dist/interpreter-Cy7S6Jh9-BIa0lyc-.mjs.map +0 -1
- package/dist/psl-infer-CuTqC9UV.d.mts.map +0 -1
- package/dist/psl-infer-Df2DrvP-.mjs +0 -474
- package/dist/psl-infer-Df2DrvP-.mjs.map +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { w as numeralText, x as escapePslString } from "./ast-Bhj549wG.mjs";
|
|
2
|
+
import { isDataTypeLoweringEntry } from "@prisma/orm-framework/components/authoring";
|
|
3
|
+
import { dataTypeId } from "@prisma/orm-framework/components/codec";
|
|
4
|
+
//#region ../../../2-sql/9-family/dist/psl-build.mjs
|
|
5
|
+
const DEFAULT_FUNCTION_ATTRIBUTES = {
|
|
6
|
+
"autoincrement()": "@default(autoincrement())",
|
|
7
|
+
"now()": "@default(now())"
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The attribute a stored default prints as: a named function, a literal the column takes, or any
|
|
11
|
+
* other expression as a raw SQL tagged literal. `undefined` when a literal has no written form.
|
|
12
|
+
*/
|
|
13
|
+
function mapDefault(columnDefault, options) {
|
|
14
|
+
switch (columnDefault.kind) {
|
|
15
|
+
case "literal": {
|
|
16
|
+
const text = writeDefaultLiteral(columnDefault.value, options);
|
|
17
|
+
return text === void 0 ? void 0 : { attribute: `@default(${text})` };
|
|
18
|
+
}
|
|
19
|
+
case "function": return { attribute: options?.functionAttributes?.[columnDefault.expression] ?? DEFAULT_FUNCTION_ATTRIBUTES[columnDefault.expression] ?? `@default(${sqlLiteralText(columnDefault.expression)})` };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A raw SQL default as a `sql` tagged literal. The backtick fence resolves only `` \` `` and `\\`,
|
|
24
|
+
* so a body holding a backtick is written inside the double-quote fence with PSL string escaping.
|
|
25
|
+
*/
|
|
26
|
+
function sqlLiteralText(expression) {
|
|
27
|
+
if (expression.includes("`")) return `sql"${escapePslString(expression)}"`;
|
|
28
|
+
return `sql\`${expression.replace(/\\/g, "\\\\")}\``;
|
|
29
|
+
}
|
|
30
|
+
function writingSurface(entries) {
|
|
31
|
+
const entryOf = /* @__PURE__ */ new Map();
|
|
32
|
+
let classify;
|
|
33
|
+
let plainStringType;
|
|
34
|
+
let plainBooleanType;
|
|
35
|
+
const tagTypes = [];
|
|
36
|
+
for (const [key, entry] of Object.entries(entries)) {
|
|
37
|
+
if (isDataTypeLoweringEntry(entry)) continue;
|
|
38
|
+
const written = entry.written;
|
|
39
|
+
if (written.kind === "tag") {
|
|
40
|
+
entryOf.set(key, entry);
|
|
41
|
+
tagTypes.push(dataTypeId(key));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (written.syntax === "number") {
|
|
45
|
+
classify = written.classify;
|
|
46
|
+
for (const type of written.types) entryOf.set(type, entry);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
entryOf.set(key, entry);
|
|
50
|
+
if (written.syntax === "string") plainStringType = dataTypeId(key);
|
|
51
|
+
else plainBooleanType = dataTypeId(key);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
entryOf,
|
|
55
|
+
classify,
|
|
56
|
+
plainStringType,
|
|
57
|
+
plainBooleanType,
|
|
58
|
+
tagTypes
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Every type the stored form could be a value of, in the order a written value would be read: a
|
|
63
|
+
* number or numeral text through the classifier first, then the plain syntax that matches the
|
|
64
|
+
* shape, then each tag, whose canonical form is a whole document.
|
|
65
|
+
*/
|
|
66
|
+
function classifications(value, surface) {
|
|
67
|
+
const found = [];
|
|
68
|
+
if (typeof value === "number") {
|
|
69
|
+
const classified = surface.classify?.(numeralText(value));
|
|
70
|
+
return classified === void 0 ? [] : [classified];
|
|
71
|
+
}
|
|
72
|
+
if (typeof value === "boolean") return surface.plainBooleanType === void 0 ? [] : [{
|
|
73
|
+
type: surface.plainBooleanType,
|
|
74
|
+
value
|
|
75
|
+
}];
|
|
76
|
+
if (typeof value === "string") {
|
|
77
|
+
const classified = surface.classify?.(value);
|
|
78
|
+
if (classified !== void 0) found.push(classified);
|
|
79
|
+
if (surface.plainStringType !== void 0) found.push({
|
|
80
|
+
type: surface.plainStringType,
|
|
81
|
+
value
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
for (const type of surface.tagTypes) found.push({
|
|
85
|
+
type,
|
|
86
|
+
value
|
|
87
|
+
});
|
|
88
|
+
return found;
|
|
89
|
+
}
|
|
90
|
+
/** The stored form the column takes this value as, or `undefined` when its type takes no such value. */
|
|
91
|
+
function admitted(candidate, columnDataType, dataTypes) {
|
|
92
|
+
if (candidate.type === columnDataType) return candidate.value;
|
|
93
|
+
const cast = dataTypes.get(columnDataType)?.casts[candidate.type];
|
|
94
|
+
if (cast === void 0) return void 0;
|
|
95
|
+
try {
|
|
96
|
+
return cast(candidate.value);
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** The body of the literal: what the entry prints, before the syntax that fences it. */
|
|
102
|
+
function printedBody(entry, value) {
|
|
103
|
+
try {
|
|
104
|
+
return entry.print(value);
|
|
105
|
+
} catch {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** What the entry reads the printed body back as, which for a number is the classifier's answer. */
|
|
110
|
+
function readBack(entry, type, body) {
|
|
111
|
+
const written = entry.written;
|
|
112
|
+
try {
|
|
113
|
+
return written.kind === "plain" && written.syntax === "number" ? written.classify(body) : {
|
|
114
|
+
type,
|
|
115
|
+
value: written.parse(body)
|
|
116
|
+
};
|
|
117
|
+
} catch {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The literal as PSL source. A tag body sits inside a backtick fence, which resolves `` \` `` and
|
|
123
|
+
* `\\` and nothing else, so a `\n` in the body survives as the two characters the entry wrote.
|
|
124
|
+
*/
|
|
125
|
+
function literalText(entry, body) {
|
|
126
|
+
const written = entry.written;
|
|
127
|
+
if (written.kind === "tag") {
|
|
128
|
+
const fenced = body.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
129
|
+
return `${written.tag}\`${fenced}\``;
|
|
130
|
+
}
|
|
131
|
+
return written.syntax === "string" ? `"${escapePslString(body)}"` : body;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The value written as the literal of one of its types, proven by reading the text straight back:
|
|
135
|
+
* the same entry, the same cast, and the stored form again.
|
|
136
|
+
*/
|
|
137
|
+
function writeScalar(value, columnDataType, dataTypes, surface) {
|
|
138
|
+
for (const candidate of classifications(value, surface)) {
|
|
139
|
+
const entry = surface.entryOf.get(candidate.type);
|
|
140
|
+
if (entry === void 0) continue;
|
|
141
|
+
const stored = admitted(candidate, columnDataType, dataTypes);
|
|
142
|
+
if (stored === void 0 || !sameForm(stored, value)) continue;
|
|
143
|
+
const body = printedBody(entry, candidate.value);
|
|
144
|
+
if (body === void 0) continue;
|
|
145
|
+
const reread = readBack(entry, candidate.type, body);
|
|
146
|
+
if (reread === void 0) continue;
|
|
147
|
+
const restored = admitted(reread, columnDataType, dataTypes);
|
|
148
|
+
if (restored === void 0 || !sameForm(restored, value)) continue;
|
|
149
|
+
return literalText(entry, body);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** One written element of a list, printed as a value of any type, with no column type to admit it. */
|
|
153
|
+
function writeElement(value, of, surface) {
|
|
154
|
+
for (const candidate of classifications(value, surface)) {
|
|
155
|
+
if (!of.includes(candidate.type)) continue;
|
|
156
|
+
const entry = surface.entryOf.get(candidate.type);
|
|
157
|
+
if (entry === void 0) continue;
|
|
158
|
+
const body = printedBody(entry, candidate.value);
|
|
159
|
+
if (body === void 0) continue;
|
|
160
|
+
const reread = readBack(entry, candidate.type, body);
|
|
161
|
+
if (reread === void 0 || !of.includes(reread.type)) continue;
|
|
162
|
+
return {
|
|
163
|
+
text: literalText(entry, body),
|
|
164
|
+
value: reread.value
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A written list on a scalar column, which the column type's list cast turns into its one value.
|
|
170
|
+
* Each element is classified on its own and must be of a type the cast takes.
|
|
171
|
+
*/
|
|
172
|
+
function writeListCast(value, columnDataType, dataTypes, surface) {
|
|
173
|
+
const listCast = dataTypes.get(columnDataType)?.listCast;
|
|
174
|
+
if (listCast === void 0) return void 0;
|
|
175
|
+
const parts = [];
|
|
176
|
+
const elements = [];
|
|
177
|
+
for (const element of value) {
|
|
178
|
+
const written = writeElement(element, listCast.of, surface);
|
|
179
|
+
if (written === void 0) return void 0;
|
|
180
|
+
parts.push(written.text);
|
|
181
|
+
elements.push(written.value);
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
if (!sameForm(listCast.cast(elements), value)) return void 0;
|
|
185
|
+
} catch {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
return `[${parts.join(", ")}]`;
|
|
189
|
+
}
|
|
190
|
+
function writeDefaultLiteral(value, options) {
|
|
191
|
+
if (value instanceof Date) return void 0;
|
|
192
|
+
const { dataTypeEntries, dataTypes, columnDataType } = options ?? {};
|
|
193
|
+
if (dataTypeEntries === void 0 || dataTypes === void 0 || columnDataType === void 0) return;
|
|
194
|
+
const surface = writingSurface(dataTypeEntries);
|
|
195
|
+
if (options?.list === true) {
|
|
196
|
+
if (!Array.isArray(value)) return void 0;
|
|
197
|
+
const parts = [];
|
|
198
|
+
for (const element of value) {
|
|
199
|
+
const written = writeScalar(element, columnDataType, dataTypes, surface);
|
|
200
|
+
if (written === void 0) return void 0;
|
|
201
|
+
parts.push(written);
|
|
202
|
+
}
|
|
203
|
+
return `[${parts.join(", ")}]`;
|
|
204
|
+
}
|
|
205
|
+
const written = writeScalar(value, columnDataType, dataTypes, surface);
|
|
206
|
+
if (written !== void 0) return written;
|
|
207
|
+
return Array.isArray(value) ? writeListCast(value, columnDataType, dataTypes, surface) : void 0;
|
|
208
|
+
}
|
|
209
|
+
/** Whether two canonical forms are the same JSON value, member by member and element by element. */
|
|
210
|
+
function sameForm(left, right) {
|
|
211
|
+
if (left === right) return true;
|
|
212
|
+
if (Array.isArray(left) !== Array.isArray(right)) return false;
|
|
213
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
|
|
214
|
+
const members = Object.entries(left);
|
|
215
|
+
const others = new Map(Object.entries(right));
|
|
216
|
+
return members.length === others.size && members.every(([key, member]) => {
|
|
217
|
+
const other = others.get(key);
|
|
218
|
+
return other !== void 0 && sameForm(member, other);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
export { mapDefault as t };
|
|
223
|
+
|
|
224
|
+
//# sourceMappingURL=psl-build-Cp32ahjI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psl-build-Cp32ahjI.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/psl-build.mjs"],"sourcesContent":["import { s as toEnumMemberName } from \"./psl-names-C3cwe0rg.mjs\";\nimport { isDataTypeLoweringEntry } from \"@internal/framework-components/authoring\";\nimport { dataTypeId } from \"@internal/framework-components/codec\";\nimport { escapePslString, numeralText } from \"@internal/sql-relational-core/ast\";\n//#region src/core/psl-build/default-mapping.ts\nconst DEFAULT_FUNCTION_ATTRIBUTES = {\n\t\"autoincrement()\": \"@default(autoincrement())\",\n\t\"now()\": \"@default(now())\"\n};\n/**\n* The attribute a stored default prints as: a named function, a literal the column takes, or any\n* other expression as a raw SQL tagged literal. `undefined` when a literal has no written form.\n*/\nfunction mapDefault(columnDefault, options) {\n\tswitch (columnDefault.kind) {\n\t\tcase \"literal\": {\n\t\t\tconst text = writeDefaultLiteral(columnDefault.value, options);\n\t\t\treturn text === void 0 ? void 0 : { attribute: `@default(${text})` };\n\t\t}\n\t\tcase \"function\": return { attribute: options?.functionAttributes?.[columnDefault.expression] ?? DEFAULT_FUNCTION_ATTRIBUTES[columnDefault.expression] ?? `@default(${sqlLiteralText(columnDefault.expression)})` };\n\t}\n}\n/**\n* A raw SQL default as a `sql` tagged literal. The backtick fence resolves only `` \\` `` and `\\\\`,\n* so a body holding a backtick is written inside the double-quote fence with PSL string escaping.\n*/\nfunction sqlLiteralText(expression) {\n\tif (expression.includes(\"`\")) return `sql\"${escapePslString(expression)}\"`;\n\treturn `sql\\`${expression.replace(/\\\\/g, \"\\\\\\\\\")}\\``;\n}\nfunction writingSurface(entries) {\n\tconst entryOf = /* @__PURE__ */ new Map();\n\tlet classify;\n\tlet plainStringType;\n\tlet plainBooleanType;\n\tconst tagTypes = [];\n\tfor (const [key, entry] of Object.entries(entries)) {\n\t\tif (isDataTypeLoweringEntry(entry)) continue;\n\t\tconst written = entry.written;\n\t\tif (written.kind === \"tag\") {\n\t\t\tentryOf.set(key, entry);\n\t\t\ttagTypes.push(dataTypeId(key));\n\t\t\tcontinue;\n\t\t}\n\t\tif (written.syntax === \"number\") {\n\t\t\tclassify = written.classify;\n\t\t\tfor (const type of written.types) entryOf.set(type, entry);\n\t\t\tcontinue;\n\t\t}\n\t\tentryOf.set(key, entry);\n\t\tif (written.syntax === \"string\") plainStringType = dataTypeId(key);\n\t\telse plainBooleanType = dataTypeId(key);\n\t}\n\treturn {\n\t\tentryOf,\n\t\tclassify,\n\t\tplainStringType,\n\t\tplainBooleanType,\n\t\ttagTypes\n\t};\n}\n/**\n* Every type the stored form could be a value of, in the order a written value would be read: a\n* number or numeral text through the classifier first, then the plain syntax that matches the\n* shape, then each tag, whose canonical form is a whole document.\n*/\nfunction classifications(value, surface) {\n\tconst found = [];\n\tif (typeof value === \"number\") {\n\t\tconst classified = surface.classify?.(numeralText(value));\n\t\treturn classified === void 0 ? [] : [classified];\n\t}\n\tif (typeof value === \"boolean\") return surface.plainBooleanType === void 0 ? [] : [{\n\t\ttype: surface.plainBooleanType,\n\t\tvalue\n\t}];\n\tif (typeof value === \"string\") {\n\t\tconst classified = surface.classify?.(value);\n\t\tif (classified !== void 0) found.push(classified);\n\t\tif (surface.plainStringType !== void 0) found.push({\n\t\t\ttype: surface.plainStringType,\n\t\t\tvalue\n\t\t});\n\t}\n\tfor (const type of surface.tagTypes) found.push({\n\t\ttype,\n\t\tvalue\n\t});\n\treturn found;\n}\n/** The stored form the column takes this value as, or `undefined` when its type takes no such value. */\nfunction admitted(candidate, columnDataType, dataTypes) {\n\tif (candidate.type === columnDataType) return candidate.value;\n\tconst cast = dataTypes.get(columnDataType)?.casts[candidate.type];\n\tif (cast === void 0) return void 0;\n\ttry {\n\t\treturn cast(candidate.value);\n\t} catch {\n\t\treturn;\n\t}\n}\n/** The body of the literal: what the entry prints, before the syntax that fences it. */\nfunction printedBody(entry, value) {\n\ttry {\n\t\treturn entry.print(value);\n\t} catch {\n\t\treturn;\n\t}\n}\n/** What the entry reads the printed body back as, which for a number is the classifier's answer. */\nfunction readBack(entry, type, body) {\n\tconst written = entry.written;\n\ttry {\n\t\treturn written.kind === \"plain\" && written.syntax === \"number\" ? written.classify(body) : {\n\t\t\ttype,\n\t\t\tvalue: written.parse(body)\n\t\t};\n\t} catch {\n\t\treturn;\n\t}\n}\n/**\n* The literal as PSL source. A tag body sits inside a backtick fence, which resolves `` \\` `` and\n* `\\\\` and nothing else, so a `\\n` in the body survives as the two characters the entry wrote.\n*/\nfunction literalText(entry, body) {\n\tconst written = entry.written;\n\tif (written.kind === \"tag\") {\n\t\tconst fenced = body.replace(/\\\\/g, \"\\\\\\\\\").replace(/`/g, \"\\\\`\");\n\t\treturn `${written.tag}\\`${fenced}\\``;\n\t}\n\treturn written.syntax === \"string\" ? `\"${escapePslString(body)}\"` : body;\n}\n/**\n* The value written as the literal of one of its types, proven by reading the text straight back:\n* the same entry, the same cast, and the stored form again.\n*/\nfunction writeScalar(value, columnDataType, dataTypes, surface) {\n\tfor (const candidate of classifications(value, surface)) {\n\t\tconst entry = surface.entryOf.get(candidate.type);\n\t\tif (entry === void 0) continue;\n\t\tconst stored = admitted(candidate, columnDataType, dataTypes);\n\t\tif (stored === void 0 || !sameForm(stored, value)) continue;\n\t\tconst body = printedBody(entry, candidate.value);\n\t\tif (body === void 0) continue;\n\t\tconst reread = readBack(entry, candidate.type, body);\n\t\tif (reread === void 0) continue;\n\t\tconst restored = admitted(reread, columnDataType, dataTypes);\n\t\tif (restored === void 0 || !sameForm(restored, value)) continue;\n\t\treturn literalText(entry, body);\n\t}\n}\n/** One written element of a list, printed as a value of any type, with no column type to admit it. */\nfunction writeElement(value, of, surface) {\n\tfor (const candidate of classifications(value, surface)) {\n\t\tif (!of.includes(candidate.type)) continue;\n\t\tconst entry = surface.entryOf.get(candidate.type);\n\t\tif (entry === void 0) continue;\n\t\tconst body = printedBody(entry, candidate.value);\n\t\tif (body === void 0) continue;\n\t\tconst reread = readBack(entry, candidate.type, body);\n\t\tif (reread === void 0 || !of.includes(reread.type)) continue;\n\t\treturn {\n\t\t\ttext: literalText(entry, body),\n\t\t\tvalue: reread.value\n\t\t};\n\t}\n}\n/**\n* A written list on a scalar column, which the column type's list cast turns into its one value.\n* Each element is classified on its own and must be of a type the cast takes.\n*/\nfunction writeListCast(value, columnDataType, dataTypes, surface) {\n\tconst listCast = dataTypes.get(columnDataType)?.listCast;\n\tif (listCast === void 0) return void 0;\n\tconst parts = [];\n\tconst elements = [];\n\tfor (const element of value) {\n\t\tconst written = writeElement(element, listCast.of, surface);\n\t\tif (written === void 0) return void 0;\n\t\tparts.push(written.text);\n\t\telements.push(written.value);\n\t}\n\ttry {\n\t\tif (!sameForm(listCast.cast(elements), value)) return void 0;\n\t} catch {\n\t\treturn;\n\t}\n\treturn `[${parts.join(\", \")}]`;\n}\nfunction writeDefaultLiteral(value, options) {\n\tif (value instanceof Date) return void 0;\n\tconst { dataTypeEntries, dataTypes, columnDataType } = options ?? {};\n\tif (dataTypeEntries === void 0 || dataTypes === void 0 || columnDataType === void 0) return;\n\tconst surface = writingSurface(dataTypeEntries);\n\tif (options?.list === true) {\n\t\tif (!Array.isArray(value)) return void 0;\n\t\tconst parts = [];\n\t\tfor (const element of value) {\n\t\t\tconst written = writeScalar(element, columnDataType, dataTypes, surface);\n\t\t\tif (written === void 0) return void 0;\n\t\t\tparts.push(written);\n\t\t}\n\t\treturn `[${parts.join(\", \")}]`;\n\t}\n\tconst written = writeScalar(value, columnDataType, dataTypes, surface);\n\tif (written !== void 0) return written;\n\treturn Array.isArray(value) ? writeListCast(value, columnDataType, dataTypes, surface) : void 0;\n}\n/** Whether two canonical forms are the same JSON value, member by member and element by element. */\nfunction sameForm(left, right) {\n\tif (left === right) return true;\n\tif (Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (typeof left !== \"object\" || typeof right !== \"object\" || left === null || right === null) return false;\n\tconst members = Object.entries(left);\n\tconst others = new Map(Object.entries(right));\n\treturn members.length === others.size && members.every(([key, member]) => {\n\t\tconst other = others.get(key);\n\t\treturn other !== void 0 && sameForm(member, other);\n\t});\n}\n//#endregion\nexport { mapDefault, toEnumMemberName };\n\n//# sourceMappingURL=psl-build.mjs.map"],"mappings":";;;;AAKA,MAAM,8BAA8B;CACnC,mBAAmB;CACnB,SAAS;AACV;;;;;AAKA,SAAS,WAAW,eAAe,SAAS;CAC3C,QAAQ,cAAc,MAAtB;EACC,KAAK,WAAW;GACf,MAAM,OAAO,oBAAoB,cAAc,OAAO,OAAO;GAC7D,OAAO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AS,YAAY,OAAO,UAAU,YAAY,SAAS,QAAQ,UAAU,MAAM,OAAO;CACrG,MAAM,UAAU,OAAO,QAAQ,IAAI;CACnC,MAAM,SAAS,IAAI,IAAI,OAAO,QAAQ,KAAK,CAAC;CAC5C,OAAO,QAAQ,WAAW,OAAO,QAAQ,QAAQ,OAAO,CAAC,KAAK,YAAY;EACzE,MAAM,QAAQ,OAAO,IAAI,GAAG;EAC5B,OAAO,UAAU,KAAK,KAAK,SAAS,QAAQ,KAAK;CAClD,CAAC;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./type-map-BwBI56i3-DDERtzxf.mjs";
|
|
2
|
+
//#region ../../../2-sql/9-family/dist/psl-build.d.mts
|
|
3
|
+
//#region src/core/psl-build/psl-names.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* PSL member name for a native-enum value. The value itself always prints
|
|
6
|
+
* explicitly (`member = "value"`), so the returned name never needs a map:
|
|
7
|
+
* a value that already is a valid, non-reserved identifier is kept verbatim
|
|
8
|
+
* (case included); anything else is camelCased/escaped like a field name.
|
|
9
|
+
*/
|
|
10
|
+
declare function toEnumMemberName(value: string): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { toEnumMemberName as t };
|
|
13
|
+
//# sourceMappingURL=psl-build-yBrQQN3r.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psl-build-yBrQQN3r.d.mts","names":[],"sources":["../../../../2-sql/9-family/dist/psl-build.d.mts"],"mappings":";;;;;;;;;iBAQiB,iBAAiB"}
|
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import { d as SqlForeignKeyIR, y as SqlTableIR } from "./types-CHOgKgHg-BxgkL3GS.mjs";
|
|
2
2
|
import "./types-BijNazlM.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { r as PslTypeMap, t as DefaultMappingOptions } from "./type-map-BwBI56i3-DDERtzxf.mjs";
|
|
4
4
|
import { ColumnDefault } from "@prisma/orm-framework/contract/types";
|
|
5
|
-
import { DataTypeId, DataTypeLookup } from "@prisma/orm-framework/components/codec";
|
|
6
5
|
//#region ../../../2-sql/9-family/dist/psl-infer.d.mts
|
|
7
|
-
//#region src/core/psl-contract-infer/default-mapping.d.ts
|
|
8
|
-
interface DefaultMappingOptions {
|
|
9
|
-
readonly functionAttributes?: Readonly<Record<string, string>>;
|
|
10
|
-
/** PSL support for the stack's data types, keyed by data type id. */
|
|
11
|
-
readonly dataTypeEntries?: Readonly<Record<string, AuthoringDataTypeEntry>> | undefined;
|
|
12
|
-
/** The stack's data types, whose casts say which other types' values each one takes. */
|
|
13
|
-
readonly dataTypes?: DataTypeLookup | undefined;
|
|
14
|
-
/** The data type of the column's codec. */
|
|
15
|
-
readonly columnDataType?: DataTypeId | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Whether the column is a list, whose elements each carry the column's own data type. A written
|
|
18
|
-
* list on a scalar column goes through that type's list cast instead.
|
|
19
|
-
*/
|
|
20
|
-
readonly list?: boolean;
|
|
21
|
-
}
|
|
22
|
-
type DefaultMappingResult = {
|
|
23
|
-
readonly attribute: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The attribute a stored default prints as: a named function, a literal the column takes, or any
|
|
27
|
-
* other expression as a raw SQL tagged literal. `undefined` when a literal has no written form.
|
|
28
|
-
*/
|
|
29
|
-
declare function mapDefault(columnDefault: ColumnDefault, options?: DefaultMappingOptions): DefaultMappingResult | undefined;
|
|
30
|
-
//#endregion
|
|
31
6
|
//#region src/core/psl-contract-infer/name-transforms.d.ts
|
|
32
7
|
type NameResult = {
|
|
33
8
|
readonly name: string;
|
|
@@ -36,33 +11,11 @@ type NameResult = {
|
|
|
36
11
|
declare function toModelName(tableName: string): NameResult;
|
|
37
12
|
declare function toFieldName(columnName: string): NameResult;
|
|
38
13
|
declare function toEnumName(pgTypeName: string): NameResult;
|
|
39
|
-
/**
|
|
40
|
-
* PSL member name for a native-enum value. The value itself always prints
|
|
41
|
-
* explicitly (`member = "value"`), so the returned name never needs a map:
|
|
42
|
-
* a value that already is a valid, non-reserved identifier is kept verbatim
|
|
43
|
-
* (case included); anything else is camelCased/escaped like a field name.
|
|
44
|
-
*/
|
|
45
|
-
declare function toEnumMemberName(value: string): string;
|
|
46
14
|
declare function pluralize(word: string): string;
|
|
47
15
|
declare function deriveRelationFieldName(fkColumns: readonly string[], referencedTableName: string): string;
|
|
48
16
|
declare function deriveBackRelationFieldName(childModelName: string, isOneToOne: boolean): string;
|
|
49
17
|
//#endregion
|
|
50
18
|
//#region src/core/psl-contract-infer/printer-config.d.ts
|
|
51
|
-
type PslTypeReference = {
|
|
52
|
-
readonly name: string;
|
|
53
|
-
readonly args?: readonly string[];
|
|
54
|
-
};
|
|
55
|
-
type PslTypeResolution = {
|
|
56
|
-
readonly pslType: PslTypeReference;
|
|
57
|
-
readonly nativeType: string;
|
|
58
|
-
readonly typeParams?: Record<string, unknown>;
|
|
59
|
-
} | {
|
|
60
|
-
readonly unsupported: true;
|
|
61
|
-
readonly nativeType: string;
|
|
62
|
-
};
|
|
63
|
-
interface PslTypeMap {
|
|
64
|
-
resolve(nativeType: string, annotations?: Record<string, unknown>): PslTypeResolution;
|
|
65
|
-
}
|
|
66
19
|
interface EnumInfo {
|
|
67
20
|
readonly typeNames: ReadonlySet<string>;
|
|
68
21
|
readonly definitions: ReadonlyMap<string, readonly string[]>;
|
|
@@ -126,5 +79,5 @@ declare function inferRelations(tables: Record<string, SqlTableIR>, modelNameMap
|
|
|
126
79
|
*/
|
|
127
80
|
declare function buildChildRelationField(fieldName: string, parentModelName: string, fk: SqlForeignKeyIR, optional: boolean, relationName?: string, hostTable?: SqlTableIR): RelationField;
|
|
128
81
|
//#endregion
|
|
129
|
-
export {
|
|
130
|
-
//# sourceMappingURL=psl-infer-
|
|
82
|
+
export { buildChildRelationField as a, inferRelations as c, toFieldName as d, toModelName as f, RelationField as i, pluralize as l, InferredRelations as n, deriveBackRelationFieldName as o, PslPrinterOptions as r, deriveRelationFieldName as s, EnumInfo as t, toEnumName as u };
|
|
83
|
+
//# sourceMappingURL=psl-infer-BzjA7U3b.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psl-infer-BzjA7U3b.d.mts","names":[],"sources":["../../../../2-sql/9-family/dist/psl-infer.d.mts"],"mappings":";;;;;;KAIK;WACM;WACA;;iBAEM,YAAY,oBAAoB;iBAChC,YAAY,qBAAqB;iBACjC,WAAW,qBAAqB;iBAChC,UAAU;iBACV,wBAAwB,8BAA8B;iBACtD,4BAA4B,wBAAwB;;;UAG3D;WACC,WAAW;WACX,aAAa;;UAEd;WACC,SAAS;WACT,iBAAiB;WACjB,WAAW;WACX,mBAAmB,oBAAoB,wBAAwB;;KAErE;WACM;WACA;;;;;;WAMA;;;;;;WAMA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;;;;KAIN;WACM,kBAAkB,6BAA6B;;iBAEzC,eAAe,QAAQ,eAAe,aAAa,cAAc,8BAA8B;;;;;;;;;;;;;;;;;;;iBAmB/F,wBAAwB,mBAAmB,yBAAyB,IAAI,iBAAiB,mBAAmB,uBAAuB,YAAY,aAAa"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { n as isBackedByColumnKeys, t as backingIndexColumnKeys } from "./foreign-key-materialization-B3HQzQIA.mjs";
|
|
2
|
+
import { t as defaultTableName } from "./default-table-name-BfFY8qYR-lHNcVmY5.mjs";
|
|
3
|
+
import { a as snakeToCamelCase, i as needsEscaping, n as escapeName, o as snakeToPascalCase, r as hasSeparators, t as escapeIfNeeded } from "./psl-names-C3cwe0rg-CsuHOV7E.mjs";
|
|
4
|
+
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
5
|
+
import pluralizeLib from "pluralize";
|
|
6
|
+
//#region ../../../2-sql/9-family/dist/psl-infer.mjs
|
|
7
|
+
function toModelName(tableName) {
|
|
8
|
+
let name;
|
|
9
|
+
if (hasSeparators(tableName)) name = snakeToPascalCase(tableName);
|
|
10
|
+
else name = tableName.charAt(0).toUpperCase() + tableName.slice(1);
|
|
11
|
+
if (needsEscaping(name)) return {
|
|
12
|
+
name: escapeName(name),
|
|
13
|
+
map: tableName
|
|
14
|
+
};
|
|
15
|
+
if (defaultTableName(name) !== tableName) return {
|
|
16
|
+
name,
|
|
17
|
+
map: tableName
|
|
18
|
+
};
|
|
19
|
+
return { name };
|
|
20
|
+
}
|
|
21
|
+
function toFieldName(columnName) {
|
|
22
|
+
let name;
|
|
23
|
+
if (hasSeparators(columnName)) name = snakeToCamelCase(columnName);
|
|
24
|
+
else name = columnName.charAt(0).toLowerCase() + columnName.slice(1);
|
|
25
|
+
if (needsEscaping(name)) return {
|
|
26
|
+
name: escapeName(name),
|
|
27
|
+
map: columnName
|
|
28
|
+
};
|
|
29
|
+
if (name !== columnName) return {
|
|
30
|
+
name,
|
|
31
|
+
map: columnName
|
|
32
|
+
};
|
|
33
|
+
return { name };
|
|
34
|
+
}
|
|
35
|
+
function toEnumName(pgTypeName) {
|
|
36
|
+
let name;
|
|
37
|
+
if (hasSeparators(pgTypeName)) name = snakeToPascalCase(pgTypeName);
|
|
38
|
+
else name = pgTypeName.charAt(0).toUpperCase() + pgTypeName.slice(1);
|
|
39
|
+
if (needsEscaping(name)) return {
|
|
40
|
+
name: escapeName(name),
|
|
41
|
+
map: pgTypeName
|
|
42
|
+
};
|
|
43
|
+
if (name !== pgTypeName) return {
|
|
44
|
+
name,
|
|
45
|
+
map: pgTypeName
|
|
46
|
+
};
|
|
47
|
+
return { name };
|
|
48
|
+
}
|
|
49
|
+
function pluralize(word) {
|
|
50
|
+
return pluralizeLib.plural(word);
|
|
51
|
+
}
|
|
52
|
+
function deriveRelationFieldName(fkColumns, referencedTableName) {
|
|
53
|
+
if (fkColumns.length === 1) {
|
|
54
|
+
const [col = referencedTableName] = fkColumns;
|
|
55
|
+
const stripped = col.replace(/_id$/i, "").replace(/Id$/, "");
|
|
56
|
+
if (stripped.length > 0 && stripped !== col) return escapeIfNeeded(snakeToCamelCase(stripped));
|
|
57
|
+
return escapeIfNeeded(snakeToCamelCase(referencedTableName));
|
|
58
|
+
}
|
|
59
|
+
return escapeIfNeeded(snakeToCamelCase(referencedTableName));
|
|
60
|
+
}
|
|
61
|
+
function deriveBackRelationFieldName(childModelName, isOneToOne) {
|
|
62
|
+
const base = childModelName.charAt(0).toLowerCase() + childModelName.slice(1);
|
|
63
|
+
return isOneToOne ? base : pluralize(base);
|
|
64
|
+
}
|
|
65
|
+
const DEFAULT_ON_DELETE = "noAction";
|
|
66
|
+
const DEFAULT_ON_UPDATE = "noAction";
|
|
67
|
+
const REFERENTIAL_ACTION_PSL = {
|
|
68
|
+
noAction: "NoAction",
|
|
69
|
+
restrict: "Restrict",
|
|
70
|
+
cascade: "Cascade",
|
|
71
|
+
setNull: "SetNull",
|
|
72
|
+
setDefault: "SetDefault"
|
|
73
|
+
};
|
|
74
|
+
function inferRelations(tables, modelNameMap) {
|
|
75
|
+
const relationsByTable = /* @__PURE__ */ new Map();
|
|
76
|
+
const fkCountByPair = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const table of Object.values(tables)) for (const fk of table.foreignKeys) {
|
|
78
|
+
const pairKey = `${table.name}→${fk.referencedTable}`;
|
|
79
|
+
fkCountByPair.set(pairKey, (fkCountByPair.get(pairKey) ?? 0) + 1);
|
|
80
|
+
}
|
|
81
|
+
const usedFieldNames = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const table of Object.values(tables)) {
|
|
83
|
+
const names = /* @__PURE__ */ new Set();
|
|
84
|
+
for (const col of Object.values(table.columns)) names.add(col.name);
|
|
85
|
+
usedFieldNames.set(table.name, names);
|
|
86
|
+
}
|
|
87
|
+
for (const table of Object.values(tables)) for (const fk of table.foreignKeys) {
|
|
88
|
+
const childTableName = table.name;
|
|
89
|
+
const parentTableName = fk.referencedTable;
|
|
90
|
+
const childUsed = usedFieldNames.get(childTableName);
|
|
91
|
+
if (childUsed === void 0) throw new InternalError(`Missing inferred field-name set for table "${childTableName}"`);
|
|
92
|
+
const childModelName = modelNameMap.get(childTableName) ?? childTableName;
|
|
93
|
+
const parentModelName = modelNameMap.get(parentTableName) ?? parentTableName;
|
|
94
|
+
const pairKey = `${childTableName}→${parentTableName}`;
|
|
95
|
+
const isSelfRelation = childTableName === parentTableName;
|
|
96
|
+
const needsRelationName = (fkCountByPair.get(pairKey) ?? 0) > 1 || isSelfRelation;
|
|
97
|
+
const isOneToOne = detectOneToOne(fk, table);
|
|
98
|
+
const childRelFieldName = resolveUniqueFieldName(deriveRelationFieldName(fk.columns, parentTableName), childUsed, parentModelName);
|
|
99
|
+
const relationName = needsRelationName ? deriveRelationName(fk, childRelFieldName, parentModelName, isSelfRelation) : void 0;
|
|
100
|
+
addRelationField(relationsByTable, childTableName, buildChildRelationField(childRelFieldName, parentModelName, fk, fk.columns.some((columnName) => table.columns[columnName]?.nullable ?? false), relationName, table));
|
|
101
|
+
childUsed.add(childRelFieldName);
|
|
102
|
+
const parentUsed = usedFieldNames.get(parentTableName) ?? /* @__PURE__ */ new Set();
|
|
103
|
+
usedFieldNames.set(parentTableName, parentUsed);
|
|
104
|
+
const backRelFieldName = resolveUniqueFieldName(deriveBackRelationFieldName(childModelName, isOneToOne), parentUsed, childModelName);
|
|
105
|
+
addRelationField(relationsByTable, parentTableName, {
|
|
106
|
+
fieldName: backRelFieldName,
|
|
107
|
+
typeName: childModelName,
|
|
108
|
+
optional: isOneToOne,
|
|
109
|
+
list: !isOneToOne,
|
|
110
|
+
relationName
|
|
111
|
+
});
|
|
112
|
+
parentUsed.add(backRelFieldName);
|
|
113
|
+
}
|
|
114
|
+
return { relationsByTable };
|
|
115
|
+
}
|
|
116
|
+
function detectOneToOne(fk, table) {
|
|
117
|
+
const fkCols = [...fk.columns].sort();
|
|
118
|
+
if (table.primaryKey) {
|
|
119
|
+
const pkCols = [...table.primaryKey.columns].sort();
|
|
120
|
+
if (pkCols.length === fkCols.length && pkCols.every((c, i) => c === fkCols[i])) return true;
|
|
121
|
+
}
|
|
122
|
+
for (const unique of table.uniques) {
|
|
123
|
+
const uniqueCols = [...unique.columns].sort();
|
|
124
|
+
if (uniqueCols.length === fkCols.length && uniqueCols.every((c, i) => c === fkCols[i])) return true;
|
|
125
|
+
}
|
|
126
|
+
for (const index of table.indexes) {
|
|
127
|
+
if (!index.unique || index.partial || index.columns === void 0) continue;
|
|
128
|
+
const indexCols = [...index.columns].sort();
|
|
129
|
+
if (indexCols.length === fkCols.length && indexCols.every((c, i) => c === fkCols[i])) return true;
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
function deriveRelationName(fk, childRelationFieldName, parentModelName, isSelfRelation) {
|
|
134
|
+
if (fk.name) return fk.name;
|
|
135
|
+
if (isSelfRelation) return `${childRelationFieldName.charAt(0).toUpperCase() + childRelationFieldName.slice(1)}${pluralize(parentModelName)}`;
|
|
136
|
+
return fk.columns.join("_");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Builds the child-side {@link RelationField} for a single foreign key:
|
|
140
|
+
* `typeName` is the parent model name, `fields`/`references` are the FK's raw
|
|
141
|
+
* columns, and `onDelete`/`onUpdate` are normalized to their PSL spelling.
|
|
142
|
+
* Exported so a caller resolving a foreign key against a model outside
|
|
143
|
+
* `tables` (e.g. a cross-space reference into another contract) can reuse the
|
|
144
|
+
* same normalization instead of duplicating it.
|
|
145
|
+
*
|
|
146
|
+
* `hostTable` is the table the FK is declared on (i.e. `table`, not the
|
|
147
|
+
* referenced parent) — its own indexes/uniques/primary key are what a
|
|
148
|
+
* backing index for this FK would be. When none of them exactly match the
|
|
149
|
+
* FK's source columns (in order), `index: false` is stamped so the emitted
|
|
150
|
+
* `@relation` opts out of the framework's default derived backing-index
|
|
151
|
+
* expectation, matching what `db verify` will find live. Passing the table
|
|
152
|
+
* is optional so existing single-FK callers (e.g. cross-space resolution
|
|
153
|
+
* before a host table reference is threaded through) can omit it and keep
|
|
154
|
+
* the framework default.
|
|
155
|
+
*/
|
|
156
|
+
function buildChildRelationField(fieldName, parentModelName, fk, optional, relationName, hostTable) {
|
|
157
|
+
const onDelete = fk.onDelete && fk.onDelete !== DEFAULT_ON_DELETE ? fk.onDelete : void 0;
|
|
158
|
+
const onUpdate = fk.onUpdate && fk.onUpdate !== DEFAULT_ON_UPDATE ? fk.onUpdate : void 0;
|
|
159
|
+
const index = hostTable && !isBackedByColumnKeys(fk.columns, backingIndexColumnKeys({
|
|
160
|
+
indexes: hostTable.indexes.filter((i) => i.where === void 0),
|
|
161
|
+
uniques: hostTable.uniques,
|
|
162
|
+
primaryKey: hostTable.primaryKey
|
|
163
|
+
})) ? false : void 0;
|
|
164
|
+
return {
|
|
165
|
+
fieldName,
|
|
166
|
+
typeName: parentModelName,
|
|
167
|
+
referencedTableName: fk.referencedTable,
|
|
168
|
+
optional,
|
|
169
|
+
list: false,
|
|
170
|
+
relationName,
|
|
171
|
+
fkName: fk.name,
|
|
172
|
+
fields: fk.columns,
|
|
173
|
+
references: fk.referencedColumns,
|
|
174
|
+
onDelete: onDelete ? REFERENTIAL_ACTION_PSL[onDelete] : void 0,
|
|
175
|
+
onUpdate: onUpdate ? REFERENTIAL_ACTION_PSL[onUpdate] : void 0,
|
|
176
|
+
index
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function resolveUniqueFieldName(desired, usedNames, fallbackSuffix) {
|
|
180
|
+
if (!usedNames.has(desired)) return desired;
|
|
181
|
+
const withSuffix = `${desired}${fallbackSuffix}`;
|
|
182
|
+
if (!usedNames.has(withSuffix)) return withSuffix;
|
|
183
|
+
let counter = 2;
|
|
184
|
+
while (usedNames.has(`${desired}${counter}`)) counter++;
|
|
185
|
+
return `${desired}${counter}`;
|
|
186
|
+
}
|
|
187
|
+
function addRelationField(map, tableName, field) {
|
|
188
|
+
const existing = map.get(tableName);
|
|
189
|
+
if (existing) existing.push(field);
|
|
190
|
+
else map.set(tableName, [field]);
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
export { pluralize as a, toModelName as c, inferRelations as i, deriveBackRelationFieldName as n, toEnumName as o, deriveRelationFieldName as r, toFieldName as s, buildChildRelationField as t };
|
|
194
|
+
|
|
195
|
+
//# sourceMappingURL=psl-infer-DwMyO-IV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psl-infer-DwMyO-IV.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/psl-infer.mjs"],"sourcesContent":["import { a as snakeToCamelCase, i as needsEscaping, n as escapeName, o as snakeToPascalCase, r as hasSeparators, t as escapeIfNeeded } from \"./psl-names-C3cwe0rg.mjs\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { defaultTableName } from \"@internal/sql-contract-psl/default-table-name\";\nimport pluralizeLib from \"pluralize\";\nimport { backingIndexColumnKeys, isBackedByColumnKeys } from \"@internal/sql-contract/foreign-key-materialization\";\n//#region src/core/psl-contract-infer/name-transforms.ts\nfunction toModelName(tableName) {\n\tlet name;\n\tif (hasSeparators(tableName)) name = snakeToPascalCase(tableName);\n\telse name = tableName.charAt(0).toUpperCase() + tableName.slice(1);\n\tif (needsEscaping(name)) return {\n\t\tname: escapeName(name),\n\t\tmap: tableName\n\t};\n\tif (defaultTableName(name) !== tableName) return {\n\t\tname,\n\t\tmap: tableName\n\t};\n\treturn { name };\n}\nfunction toFieldName(columnName) {\n\tlet name;\n\tif (hasSeparators(columnName)) name = snakeToCamelCase(columnName);\n\telse name = columnName.charAt(0).toLowerCase() + columnName.slice(1);\n\tif (needsEscaping(name)) return {\n\t\tname: escapeName(name),\n\t\tmap: columnName\n\t};\n\tif (name !== columnName) return {\n\t\tname,\n\t\tmap: columnName\n\t};\n\treturn { name };\n}\nfunction toEnumName(pgTypeName) {\n\tlet name;\n\tif (hasSeparators(pgTypeName)) name = snakeToPascalCase(pgTypeName);\n\telse name = pgTypeName.charAt(0).toUpperCase() + pgTypeName.slice(1);\n\tif (needsEscaping(name)) return {\n\t\tname: escapeName(name),\n\t\tmap: pgTypeName\n\t};\n\tif (name !== pgTypeName) return {\n\t\tname,\n\t\tmap: pgTypeName\n\t};\n\treturn { name };\n}\nfunction pluralize(word) {\n\treturn pluralizeLib.plural(word);\n}\nfunction deriveRelationFieldName(fkColumns, referencedTableName) {\n\tif (fkColumns.length === 1) {\n\t\tconst [col = referencedTableName] = fkColumns;\n\t\tconst stripped = col.replace(/_id$/i, \"\").replace(/Id$/, \"\");\n\t\tif (stripped.length > 0 && stripped !== col) return escapeIfNeeded(snakeToCamelCase(stripped));\n\t\treturn escapeIfNeeded(snakeToCamelCase(referencedTableName));\n\t}\n\treturn escapeIfNeeded(snakeToCamelCase(referencedTableName));\n}\nfunction deriveBackRelationFieldName(childModelName, isOneToOne) {\n\tconst base = childModelName.charAt(0).toLowerCase() + childModelName.slice(1);\n\treturn isOneToOne ? base : pluralize(base);\n}\n//#endregion\n//#region src/core/psl-contract-infer/relation-inference.ts\nconst DEFAULT_ON_DELETE = \"noAction\";\nconst DEFAULT_ON_UPDATE = \"noAction\";\nconst REFERENTIAL_ACTION_PSL = {\n\tnoAction: \"NoAction\",\n\trestrict: \"Restrict\",\n\tcascade: \"Cascade\",\n\tsetNull: \"SetNull\",\n\tsetDefault: \"SetDefault\"\n};\nfunction inferRelations(tables, modelNameMap) {\n\tconst relationsByTable = /* @__PURE__ */ new Map();\n\tconst fkCountByPair = /* @__PURE__ */ new Map();\n\tfor (const table of Object.values(tables)) for (const fk of table.foreignKeys) {\n\t\tconst pairKey = `${table.name}→${fk.referencedTable}`;\n\t\tfkCountByPair.set(pairKey, (fkCountByPair.get(pairKey) ?? 0) + 1);\n\t}\n\tconst usedFieldNames = /* @__PURE__ */ new Map();\n\tfor (const table of Object.values(tables)) {\n\t\tconst names = /* @__PURE__ */ new Set();\n\t\tfor (const col of Object.values(table.columns)) names.add(col.name);\n\t\tusedFieldNames.set(table.name, names);\n\t}\n\tfor (const table of Object.values(tables)) for (const fk of table.foreignKeys) {\n\t\tconst childTableName = table.name;\n\t\tconst parentTableName = fk.referencedTable;\n\t\tconst childUsed = usedFieldNames.get(childTableName);\n\t\tif (childUsed === void 0) throw new InternalError(`Missing inferred field-name set for table \"${childTableName}\"`);\n\t\tconst childModelName = modelNameMap.get(childTableName) ?? childTableName;\n\t\tconst parentModelName = modelNameMap.get(parentTableName) ?? parentTableName;\n\t\tconst pairKey = `${childTableName}→${parentTableName}`;\n\t\tconst isSelfRelation = childTableName === parentTableName;\n\t\tconst needsRelationName = (fkCountByPair.get(pairKey) ?? 0) > 1 || isSelfRelation;\n\t\tconst isOneToOne = detectOneToOne(fk, table);\n\t\tconst childRelFieldName = resolveUniqueFieldName(deriveRelationFieldName(fk.columns, parentTableName), childUsed, parentModelName);\n\t\tconst relationName = needsRelationName ? deriveRelationName(fk, childRelFieldName, parentModelName, isSelfRelation) : void 0;\n\t\taddRelationField(relationsByTable, childTableName, buildChildRelationField(childRelFieldName, parentModelName, fk, fk.columns.some((columnName) => table.columns[columnName]?.nullable ?? false), relationName, table));\n\t\tchildUsed.add(childRelFieldName);\n\t\tconst parentUsed = usedFieldNames.get(parentTableName) ?? /* @__PURE__ */ new Set();\n\t\tusedFieldNames.set(parentTableName, parentUsed);\n\t\tconst backRelFieldName = resolveUniqueFieldName(deriveBackRelationFieldName(childModelName, isOneToOne), parentUsed, childModelName);\n\t\taddRelationField(relationsByTable, parentTableName, {\n\t\t\tfieldName: backRelFieldName,\n\t\t\ttypeName: childModelName,\n\t\t\toptional: isOneToOne,\n\t\t\tlist: !isOneToOne,\n\t\t\trelationName\n\t\t});\n\t\tparentUsed.add(backRelFieldName);\n\t}\n\treturn { relationsByTable };\n}\nfunction detectOneToOne(fk, table) {\n\tconst fkCols = [...fk.columns].sort();\n\tif (table.primaryKey) {\n\t\tconst pkCols = [...table.primaryKey.columns].sort();\n\t\tif (pkCols.length === fkCols.length && pkCols.every((c, i) => c === fkCols[i])) return true;\n\t}\n\tfor (const unique of table.uniques) {\n\t\tconst uniqueCols = [...unique.columns].sort();\n\t\tif (uniqueCols.length === fkCols.length && uniqueCols.every((c, i) => c === fkCols[i])) return true;\n\t}\n\tfor (const index of table.indexes) {\n\t\tif (!index.unique || index.partial || index.columns === void 0) continue;\n\t\tconst indexCols = [...index.columns].sort();\n\t\tif (indexCols.length === fkCols.length && indexCols.every((c, i) => c === fkCols[i])) return true;\n\t}\n\treturn false;\n}\nfunction deriveRelationName(fk, childRelationFieldName, parentModelName, isSelfRelation) {\n\tif (fk.name) return fk.name;\n\tif (isSelfRelation) return `${childRelationFieldName.charAt(0).toUpperCase() + childRelationFieldName.slice(1)}${pluralize(parentModelName)}`;\n\treturn fk.columns.join(\"_\");\n}\n/**\n* Builds the child-side {@link RelationField} for a single foreign key:\n* `typeName` is the parent model name, `fields`/`references` are the FK's raw\n* columns, and `onDelete`/`onUpdate` are normalized to their PSL spelling.\n* Exported so a caller resolving a foreign key against a model outside\n* `tables` (e.g. a cross-space reference into another contract) can reuse the\n* same normalization instead of duplicating it.\n*\n* `hostTable` is the table the FK is declared on (i.e. `table`, not the\n* referenced parent) — its own indexes/uniques/primary key are what a\n* backing index for this FK would be. When none of them exactly match the\n* FK's source columns (in order), `index: false` is stamped so the emitted\n* `@relation` opts out of the framework's default derived backing-index\n* expectation, matching what `db verify` will find live. Passing the table\n* is optional so existing single-FK callers (e.g. cross-space resolution\n* before a host table reference is threaded through) can omit it and keep\n* the framework default.\n*/\nfunction buildChildRelationField(fieldName, parentModelName, fk, optional, relationName, hostTable) {\n\tconst onDelete = fk.onDelete && fk.onDelete !== DEFAULT_ON_DELETE ? fk.onDelete : void 0;\n\tconst onUpdate = fk.onUpdate && fk.onUpdate !== DEFAULT_ON_UPDATE ? fk.onUpdate : void 0;\n\tconst index = hostTable && !isBackedByColumnKeys(fk.columns, backingIndexColumnKeys({\n\t\tindexes: hostTable.indexes.filter((i) => i.where === void 0),\n\t\tuniques: hostTable.uniques,\n\t\tprimaryKey: hostTable.primaryKey\n\t})) ? false : void 0;\n\treturn {\n\t\tfieldName,\n\t\ttypeName: parentModelName,\n\t\treferencedTableName: fk.referencedTable,\n\t\toptional,\n\t\tlist: false,\n\t\trelationName,\n\t\tfkName: fk.name,\n\t\tfields: fk.columns,\n\t\treferences: fk.referencedColumns,\n\t\tonDelete: onDelete ? REFERENTIAL_ACTION_PSL[onDelete] : void 0,\n\t\tonUpdate: onUpdate ? REFERENTIAL_ACTION_PSL[onUpdate] : void 0,\n\t\tindex\n\t};\n}\nfunction resolveUniqueFieldName(desired, usedNames, fallbackSuffix) {\n\tif (!usedNames.has(desired)) return desired;\n\tconst withSuffix = `${desired}${fallbackSuffix}`;\n\tif (!usedNames.has(withSuffix)) return withSuffix;\n\tlet counter = 2;\n\twhile (usedNames.has(`${desired}${counter}`)) counter++;\n\treturn `${desired}${counter}`;\n}\nfunction addRelationField(map, tableName, field) {\n\tconst existing = map.get(tableName);\n\tif (existing) existing.push(field);\n\telse map.set(tableName, [field]);\n}\n//#endregion\nexport { buildChildRelationField, deriveBackRelationFieldName, deriveRelationFieldName, inferRelations, pluralize, toEnumName, toFieldName, toModelName };\n\n//# sourceMappingURL=psl-infer.mjs.map"],"mappings":";;;;;;AAMA,SAAS,YAAY,WAAW;CAC/B,IAAI;CACJ,IAAI,cAAc,SAAS,GAAG,OAAO,kBAAkB,SAAS;MAC3D,OAAO,UAAU,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,UAAU,MAAM,CAAC;CACjE,IAAI,cAAc,IAAI,GAAG,OAAO;EAC/B,MAAM,WAAW,IAAI;EACrB,KAAK;CACN;CACA,IAAI,iBAAiB,IAAI,MAAM,WAAW,OAAO;EAChD;EACA,KAAK;CACN;CACA,OAAO,EAAE,KAAK;AACf;AACA,SAAS,YAAY,YAAY;CAChC,IAAI;CACJ,IAAI,cAAc,UAAU,GAAG,OAAO,iBAAiB,UAAU;MAC5D,OAAO,WAAW,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,WAAW,MAAM,CAAC;CACnE,IAAI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C3cwe0rg.mjs
|
|
2
|
+
const PSL_RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
3
|
+
"model",
|
|
4
|
+
"enum",
|
|
5
|
+
"types",
|
|
6
|
+
"type",
|
|
7
|
+
"generator",
|
|
8
|
+
"datasource"
|
|
9
|
+
]);
|
|
10
|
+
const IDENTIFIER_PART_PATTERN = /[A-Za-z0-9]+/g;
|
|
11
|
+
function hasSeparators(input) {
|
|
12
|
+
return /[^A-Za-z0-9]/.test(input);
|
|
13
|
+
}
|
|
14
|
+
function extractIdentifierParts(input) {
|
|
15
|
+
return input.match(IDENTIFIER_PART_PATTERN) ?? [];
|
|
16
|
+
}
|
|
17
|
+
function createSyntheticIdentifier(input) {
|
|
18
|
+
let hash = 2166136261;
|
|
19
|
+
for (const char of input) {
|
|
20
|
+
hash ^= char.codePointAt(0) ?? 0;
|
|
21
|
+
hash = Math.imul(hash, 16777619);
|
|
22
|
+
}
|
|
23
|
+
return `x${(hash >>> 0).toString(16)}`;
|
|
24
|
+
}
|
|
25
|
+
function sanitizeIdentifierCharacters(input) {
|
|
26
|
+
const sanitized = input.replace(/[^\w]/g, "");
|
|
27
|
+
return sanitized.length > 0 ? sanitized : createSyntheticIdentifier(input);
|
|
28
|
+
}
|
|
29
|
+
function capitalize(word) {
|
|
30
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
31
|
+
}
|
|
32
|
+
function snakeToPascalCase(input) {
|
|
33
|
+
const parts = extractIdentifierParts(input);
|
|
34
|
+
if (parts.length === 0) return capitalize(sanitizeIdentifierCharacters(input));
|
|
35
|
+
return parts.map(capitalize).join("");
|
|
36
|
+
}
|
|
37
|
+
function snakeToCamelCase(input) {
|
|
38
|
+
const parts = extractIdentifierParts(input);
|
|
39
|
+
if (parts.length === 0) return sanitizeIdentifierCharacters(input);
|
|
40
|
+
const [firstPart = input, ...rest] = parts;
|
|
41
|
+
return firstPart.charAt(0).toLowerCase() + firstPart.slice(1) + rest.map(capitalize).join("");
|
|
42
|
+
}
|
|
43
|
+
function needsEscaping(name) {
|
|
44
|
+
return PSL_RESERVED_WORDS.has(name.toLowerCase()) || /^\d/.test(name);
|
|
45
|
+
}
|
|
46
|
+
function escapeName(name) {
|
|
47
|
+
return `_${name}`;
|
|
48
|
+
}
|
|
49
|
+
function escapeIfNeeded(name) {
|
|
50
|
+
return needsEscaping(name) ? escapeName(name) : name;
|
|
51
|
+
}
|
|
52
|
+
const VALID_IDENTIFIER_PATTERN = /^[A-Za-z_]\w*$/;
|
|
53
|
+
/**
|
|
54
|
+
* PSL member name for a native-enum value. The value itself always prints
|
|
55
|
+
* explicitly (`member = "value"`), so the returned name never needs a map:
|
|
56
|
+
* a value that already is a valid, non-reserved identifier is kept verbatim
|
|
57
|
+
* (case included); anything else is camelCased/escaped like a field name.
|
|
58
|
+
*/
|
|
59
|
+
function toEnumMemberName(value) {
|
|
60
|
+
if (VALID_IDENTIFIER_PATTERN.test(value) && !needsEscaping(value)) return value;
|
|
61
|
+
return escapeIfNeeded(snakeToCamelCase(value));
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { snakeToCamelCase as a, needsEscaping as i, escapeName as n, snakeToPascalCase as o, hasSeparators as r, toEnumMemberName as s, escapeIfNeeded as t };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=psl-names-C3cwe0rg-CsuHOV7E.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psl-names-C3cwe0rg-CsuHOV7E.mjs","names":[],"sources":["../../../../2-sql/9-family/dist/psl-names-C3cwe0rg.mjs"],"sourcesContent":["//#region src/core/psl-build/psl-names.ts\nconst PSL_RESERVED_WORDS = /* @__PURE__ */ new Set([\n\t\"model\",\n\t\"enum\",\n\t\"types\",\n\t\"type\",\n\t\"generator\",\n\t\"datasource\"\n]);\nconst IDENTIFIER_PART_PATTERN = /[A-Za-z0-9]+/g;\nfunction hasSeparators(input) {\n\treturn /[^A-Za-z0-9]/.test(input);\n}\nfunction extractIdentifierParts(input) {\n\treturn input.match(IDENTIFIER_PART_PATTERN) ?? [];\n}\nfunction createSyntheticIdentifier(input) {\n\tlet hash = 2166136261;\n\tfor (const char of input) {\n\t\thash ^= char.codePointAt(0) ?? 0;\n\t\thash = Math.imul(hash, 16777619);\n\t}\n\treturn `x${(hash >>> 0).toString(16)}`;\n}\nfunction sanitizeIdentifierCharacters(input) {\n\tconst sanitized = input.replace(/[^\\w]/g, \"\");\n\treturn sanitized.length > 0 ? sanitized : createSyntheticIdentifier(input);\n}\nfunction capitalize(word) {\n\treturn word.charAt(0).toUpperCase() + word.slice(1);\n}\nfunction snakeToPascalCase(input) {\n\tconst parts = extractIdentifierParts(input);\n\tif (parts.length === 0) return capitalize(sanitizeIdentifierCharacters(input));\n\treturn parts.map(capitalize).join(\"\");\n}\nfunction snakeToCamelCase(input) {\n\tconst parts = extractIdentifierParts(input);\n\tif (parts.length === 0) return sanitizeIdentifierCharacters(input);\n\tconst [firstPart = input, ...rest] = parts;\n\treturn firstPart.charAt(0).toLowerCase() + firstPart.slice(1) + rest.map(capitalize).join(\"\");\n}\nfunction needsEscaping(name) {\n\treturn PSL_RESERVED_WORDS.has(name.toLowerCase()) || /^\\d/.test(name);\n}\nfunction escapeName(name) {\n\treturn `_${name}`;\n}\nfunction escapeIfNeeded(name) {\n\treturn needsEscaping(name) ? escapeName(name) : name;\n}\nconst VALID_IDENTIFIER_PATTERN = /^[A-Za-z_]\\w*$/;\n/**\n* PSL member name for a native-enum value. The value itself always prints\n* explicitly (`member = \"value\"`), so the returned name never needs a map:\n* a value that already is a valid, non-reserved identifier is kept verbatim\n* (case included); anything else is camelCased/escaped like a field name.\n*/\nfunction toEnumMemberName(value) {\n\tif (VALID_IDENTIFIER_PATTERN.test(value) && !needsEscaping(value)) return value;\n\treturn escapeIfNeeded(snakeToCamelCase(value));\n}\n//#endregion\nexport { snakeToCamelCase as a, needsEscaping as i, escapeName as n, snakeToPascalCase as o, hasSeparators as r, toEnumMemberName as s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