@prisma/orm-family-sql 8.0.0-rc.17-dev.36 → 8.0.0-rc.17-dev.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{authoring-type-constructors-0Iv2zdwS-DjC0oxBn.mjs → authoring-type-constructors-0Iv2zdwS-ZTBL7w8X.mjs} +2 -2
- package/dist/{authoring-type-constructors-0Iv2zdwS-DjC0oxBn.mjs.map → authoring-type-constructors-0Iv2zdwS-ZTBL7w8X.mjs.map} +1 -1
- package/dist/{config-types-GKGrPAno.mjs → config-types-DiCetrJe.mjs} +2 -2
- package/dist/{config-types-GKGrPAno.mjs.map → config-types-DiCetrJe.mjs.map} +1 -1
- package/dist/{contract-builder-uPgNqtxM.mjs → contract-builder-D84f__Oc.mjs} +2 -2
- package/dist/{contract-builder-uPgNqtxM.mjs.map → contract-builder-D84f__Oc.mjs.map} +1 -1
- package/dist/contract-prisma7__provider.mjs +4 -4
- package/dist/contract-psl.mjs +1 -1
- package/dist/contract-psl__attribute-specs.mjs +1 -1
- package/dist/contract-psl__provider.mjs +2 -2
- package/dist/contract-ts.mjs +3 -3
- package/dist/contract-ts__config-types.mjs +1 -1
- package/dist/contract-ts__contract-builder.mjs +2 -2
- package/dist/contract.d.mts +2 -2
- package/dist/contract.mjs +2 -2
- package/dist/contract__data-type.d.mts +2 -2
- package/dist/contract__data-type.mjs +2 -2
- package/dist/{control-D4PHWMpB.d.mts → control-Bs-0JljW.d.mts} +199 -10
- package/dist/{control-D4PHWMpB.d.mts.map → control-Bs-0JljW.d.mts.map} +1 -1
- package/dist/{control-DoMJbS3w.mjs → control-Bvnz4Uk4.mjs} +337 -17
- package/dist/control-Bvnz4Uk4.mjs.map +1 -0
- package/dist/{data-type-C_PI_Jsa.mjs → data-type-BgP6Wv48.mjs} +27 -5
- package/dist/{data-type-C_PI_Jsa.mjs.map → data-type-BgP6Wv48.mjs.map} +1 -1
- package/dist/{data-type-CpqSDmR_.d.mts → data-type-gKl5DBHw.d.mts} +9 -2
- package/dist/{data-type-CpqSDmR_.d.mts.map → data-type-gKl5DBHw.d.mts.map} +1 -1
- package/dist/{derived-checks-DSMOrZN--D4sGB1Rt.mjs → derived-checks-CYz041Ol-TjL7rPxe.mjs} +126 -207
- package/dist/derived-checks-CYz041Ol-TjL7rPxe.mjs.map +1 -0
- package/dist/family.d.mts +2 -2
- package/dist/family.mjs +3 -3
- package/dist/family__control.d.mts +2 -2
- package/dist/family__control.mjs +3 -3
- package/dist/family__diff.mjs +1 -1
- package/dist/family__pack.mjs +2 -2
- package/dist/{interpreter-0z4AxG0I-DO_n08hz.mjs → interpreter-0z4AxG0I-CM9DULu1.mjs} +3 -3
- package/dist/{interpreter-0z4AxG0I-DO_n08hz.mjs.map → interpreter-0z4AxG0I-CM9DULu1.mjs.map} +1 -1
- package/dist/{psl-field-resolution-D4jnVVTd-Drt-tbfu.mjs → psl-field-resolution-D4jnVVTd-B396sZmO.mjs} +2 -2
- package/dist/{psl-field-resolution-D4jnVVTd-Drt-tbfu.mjs.map → psl-field-resolution-D4jnVVTd-B396sZmO.mjs.map} +1 -1
- package/dist/{schema-verify-DIfHSB4I-Bbek1093.mjs → schema-verify-DIfHSB4I-Du0-5I8k.mjs} +2 -2
- package/dist/{schema-verify-DIfHSB4I-Bbek1093.mjs.map → schema-verify-DIfHSB4I-Du0-5I8k.mjs.map} +1 -1
- package/package.json +18 -18
- package/dist/control-DoMJbS3w.mjs.map +0 -1
- package/dist/derived-checks-DSMOrZN--D4sGB1Rt.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-type-
|
|
1
|
+
{"version":3,"file":"data-type-gKl5DBHw.d.mts","names":[],"sources":["../../../../2-sql/1-core/contract/dist/data-type.d.mts"],"mappings":";;;;;;;;iBAOiB,YAAY;;;;UAInB;;WAEC;;WAEA;;WAEA;;WAEA;;KAEN,gBAAgB,SAAS;;UAEpB;;WAEC;;WAEA;WACA;;WAEA;;UAED,gBAAgB,eAAe,gBAAgB,uBAAuB;WACrE,SAAS,KAAK;WACd,iBAAiB;;WAEjB;WACA,aAAa,QAAQ,WAAW;WAChC,UAAU,QAAQ;WAClB,gBAAgB,UAAU,oBAAoB;;UAE/C,iBAAiB,eAAe,gBAAgB;WAC/C,gBAAgB;WAChB;WACA,YAAY,QAAQ,WAAW;WAC/B,UAAU,QAAQ;WAClB,gBAAgB,UAAU,oBAAoB;;UAE/C,YAAY,eAAe,gBAAgB,uBAAuB;WACjE,SAAS,KAAK;WACd,KAAK,iBAAiB;;UAEvB;WACC,UAAU;WACV,YAAY;;;iBAGN,YAAY,eAAe,gBAAgB,eAAe,YAAY,MAAM,gBAAgB,UAAU,YAAY;;iBAElH,cAAc,MAAM,WAAW,QAAQ;;iBAEvC,eAAe,MAAM,UAAU,YAAY,4BAA4B;;iBAEvE,sBAAsB,eAAe,eAAe,MAAM,YAAY,SAAS,QAAQ,gBAAgB;;iBAEvG,YAAY,eAAe,eAAe,MAAM,YAAY,SAAS,QAAQ;;;;;;iBAM7E,oBAAoB,eAAe,eAAe,MAAM,YAAY,SAAS,QAAQ;;UAE5F;WACC,aAAa,KAAK;WAClB,gBAAgB,KAAK;;;iBAGf,mBAAmB,iBAAiB,SAAS,iBAAiB;;iBAE9D,2BAA2B,iBAAiB,YAAY,2BAA2B,SAAS;;iBAE5F,kBAAkB,eAAe,eAAe,MAAM,YAAY,SAAS,QAAQ;;iBAEnF,qBAAqB,eAAe,eAAe,MAAM,YAAY,SAAS,QAAQ;;UAE7F;WACC,OAAO;WACP,QAAQ;WACR;aACE;aACA;aACA;;aAEA;aACA;;;;;;;;iBAQI,yBAAyB,gBAAgB,aAAa;;;;;iBAKtD,uBAAuB,UAAU,iBAAiB,oBAAoB,aAAa;;;;;;;iBAOnF,uBAAuB,cAAc,oBAAoB,sBAAsB"}
|
|
@@ -3,7 +3,7 @@ import { i as computeCheckContentHash, r as composeCheckWirePrefix, s as derived
|
|
|
3
3
|
import { r as lowerAuthoredIndex } from "./index-naming-BOcJT1B3-CeEoP8t3.mjs";
|
|
4
4
|
import { t as lowerAuthoredCheck } from "./authored-check-naming-CO3GA46Y.mjs";
|
|
5
5
|
import { t as sqlContractCanonicalizationHooks } from "./canonicalization-hooks-dmXkOR4a.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { p as validateSqlTypeParams, t as dataTypeParams, u as sqlDataTypeOfCodec } from "./data-type-BgP6Wv48.mjs";
|
|
7
7
|
import { c as StorageTable, i as Index, t as CheckConstraint } from "./storage-table-B7OSPl3G-p1j6AjMS.mjs";
|
|
8
8
|
import { n as checkConstraintInputFromSerialized } from "./serialized-index-C26m_DWu-BjU519sW.mjs";
|
|
9
9
|
import { m as valueSetEntityKind, p as tableEntityKind } from "./entity-kinds-DDTkNIr9-DJ2EIO94.mjs";
|
|
@@ -17,17 +17,16 @@ import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
|
17
17
|
import { flushAuthoringWarnings, isAuthoringEntityTypeDescriptor } from "@prisma/orm-framework/components/authoring";
|
|
18
18
|
import { compareCodeUnits } from "@prisma/orm-framework/contract/hashing-utils";
|
|
19
19
|
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
20
|
-
import { codecForRef
|
|
20
|
+
import { codecForRef } from "@prisma/orm-framework/components/codec";
|
|
21
21
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
22
22
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
23
23
|
import { asNamespaceId, coreHash, crossRef, effectiveControlPolicy } from "@prisma/orm-framework/contract/types";
|
|
24
|
-
import { canonicalStringify } from "@prisma/orm-framework/utils/canonical-stringify";
|
|
25
24
|
import { mergeCapabilityMatrices } from "@prisma/orm-framework/components/components";
|
|
26
|
-
import {
|
|
25
|
+
import { encodeEnumTypeMembers, resolveToOneRelationNullable } from "@prisma/orm-framework/contract-authoring";
|
|
27
26
|
import { buildExecutionSection, computeProfileHash, computeStorageHash } from "@prisma/orm-framework/contract/hashing";
|
|
28
27
|
import { invariant } from "@prisma/orm-framework/utils/assertions";
|
|
29
28
|
import { applySpecifierDefaultControlPolicy } from "@prisma/orm-framework/contract/apply-specifier-default-control-policy";
|
|
30
|
-
//#region ../../../2-sql/2-authoring/contract-ts/dist/derived-checks-
|
|
29
|
+
//#region ../../../2-sql/2-authoring/contract-ts/dist/derived-checks-CYz041Ol.mjs
|
|
31
30
|
function contractError(code, message, options) {
|
|
32
31
|
return structuredError(code, message, options);
|
|
33
32
|
}
|
|
@@ -54,211 +53,12 @@ function describeColumn(column, site) {
|
|
|
54
53
|
site
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
|
-
/** How an error message names the column: `Field "Model.field"` or `Column "table.column"`. */
|
|
58
|
-
function columnSiteSubject(site) {
|
|
59
|
-
return site.kind === "field" ? `Field "${site.modelName}.${site.fieldName}"` : `Column "${site.tableName}.${site.columnName}"`;
|
|
60
|
-
}
|
|
61
|
-
/** The error metadata that locates the column. */
|
|
62
|
-
function columnSiteMeta(site) {
|
|
63
|
-
return site.kind === "field" ? {
|
|
64
|
-
modelName: site.modelName,
|
|
65
|
-
fieldName: site.fieldName
|
|
66
|
-
} : {
|
|
67
|
-
namespaceId: site.namespaceId,
|
|
68
|
-
tableName: site.tableName,
|
|
69
|
-
columnName: site.columnName
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/** How an error message names the owner: `model "User"` or `table "audit_rows" in namespace "public"`. */
|
|
73
|
-
function referenceOwnerSubject(owner) {
|
|
74
|
-
return owner.kind === "model" ? `model "${owner.modelName}"` : `table "${owner.tableName}" in namespace "${owner.namespaceId}"`;
|
|
75
|
-
}
|
|
76
|
-
/** The error metadata that locates the owner. */
|
|
77
|
-
function referenceOwnerMeta(owner) {
|
|
78
|
-
return owner.kind === "model" ? { sourceModel: owner.modelName } : {
|
|
79
|
-
sourceTable: owner.tableName,
|
|
80
|
-
sourceNamespaceId: owner.namespaceId
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The codec that encodes one column's default, built with the column's own `typeParams`, because a parameterized codec checks its params when it encodes and reads a default. Only a column has params; every other encode site takes the representative instance.
|
|
85
|
-
*/
|
|
86
|
-
function columnCodec(codecId, typeParams, codecLookup) {
|
|
87
|
-
return codecForRef(codecLookup, {
|
|
88
|
-
codecId,
|
|
89
|
-
...ifDefined("typeParams", typeParams === void 0 ? void 0 : blindCast(typeParams))
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/** Encodes a value the contract stores, and reads it back with the codec, which refuses a value its column would not hold. */
|
|
93
|
-
function encodeViaCodec(value, codec) {
|
|
94
|
-
if (codec) {
|
|
95
|
-
const json = codec.encodeJson(value);
|
|
96
|
-
codec.decodeJson(json);
|
|
97
|
-
return json;
|
|
98
|
-
}
|
|
99
|
-
return blindCast(value);
|
|
100
|
-
}
|
|
101
|
-
function defaultRefusal(site, cause, elementPosition) {
|
|
102
|
-
const subject = elementPosition === void 0 ? "default" : `default (element ${elementPosition})`;
|
|
103
|
-
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
104
|
-
return contractError("CONTRACT.DEFAULT_INVALID", `${columnSiteSubject(site)} has a ${subject} that its codec refuses: ${reason}`, {
|
|
105
|
-
cause,
|
|
106
|
-
meta: {
|
|
107
|
-
...columnSiteMeta(site),
|
|
108
|
-
codecId: site.codecId,
|
|
109
|
-
reason: "codec-refused-default",
|
|
110
|
-
...ifDefined("elementPosition", elementPosition)
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
function encodeDefaultValue(value, codec, site, elementPosition) {
|
|
115
|
-
try {
|
|
116
|
-
return encodeViaCodec(value, codec);
|
|
117
|
-
} catch (cause) {
|
|
118
|
-
if (cause instanceof InternalError) throw cause;
|
|
119
|
-
throw defaultRefusal(site, cause, elementPosition);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function codecForDefault(codecLookup, resolveCodec, site) {
|
|
123
|
-
const codec = buildCodecForDefault(codecLookup, resolveCodec, site);
|
|
124
|
-
if (codec === void 0) throw contractError("CONTRACT.DEFAULT_INVALID", `${columnSiteSubject(site)} has a default, but no pack in the contract declares its codec "${site.codecId}", so the default cannot be checked. List the pack that owns the codec in \`extensions\`.`, { meta: {
|
|
125
|
-
...columnSiteMeta(site),
|
|
126
|
-
codecId: site.codecId,
|
|
127
|
-
reason: "codec-not-found"
|
|
128
|
-
} });
|
|
129
|
-
return codec;
|
|
130
|
-
}
|
|
131
|
-
function buildCodecForDefault(codecLookup, resolveCodec, site) {
|
|
132
|
-
try {
|
|
133
|
-
return resolveCodec(codecLookup);
|
|
134
|
-
} catch (cause) {
|
|
135
|
-
if (!isStructuredError(cause) || cause.code !== "RUNTIME.TYPE_PARAMS_INVALID") throw cause;
|
|
136
|
-
throw contractError("CONTRACT.ARGUMENT_INVALID", `${columnSiteSubject(site)} has type parameters that its codec does not accept: ${cause.message}`, {
|
|
137
|
-
cause,
|
|
138
|
-
meta: {
|
|
139
|
-
...columnSiteMeta(site),
|
|
140
|
-
codecId: site.codecId,
|
|
141
|
-
reason: "type-params-invalid"
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function encodeColumnDefault(defaultInput, codecLookup, resolveCodec, site, many = false, elementNullable = false) {
|
|
147
|
-
if (defaultInput.kind === "function") return {
|
|
148
|
-
kind: "function",
|
|
149
|
-
expression: defaultInput.expression
|
|
150
|
-
};
|
|
151
|
-
if ("canonical" in defaultInput && defaultInput.canonical === true) return {
|
|
152
|
-
kind: "literal",
|
|
153
|
-
value: blindCast(defaultInput.value)
|
|
154
|
-
};
|
|
155
|
-
if (many) {
|
|
156
|
-
if (!Array.isArray(defaultInput.value)) throw contractError("CONTRACT.DEFAULT_INVALID", `${columnSiteSubject(site)} is a list field, so its default is an array; received ${typeof defaultInput.value}. Call .many() before .default().`, { meta: {
|
|
157
|
-
...columnSiteMeta(site),
|
|
158
|
-
codecId: site.codecId,
|
|
159
|
-
reason: "list-default-not-array"
|
|
160
|
-
} });
|
|
161
|
-
const codec = codecForDefault(codecLookup, resolveCodec, site);
|
|
162
|
-
return {
|
|
163
|
-
kind: "literal",
|
|
164
|
-
value: defaultInput.value.map((element, index) => {
|
|
165
|
-
if (element !== null) return encodeDefaultValue(element, codec, site, index + 1);
|
|
166
|
-
if (elementNullable) return null;
|
|
167
|
-
throw new InternalError("Literal default on a strict list column cannot contain null elements.");
|
|
168
|
-
})
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
kind: "literal",
|
|
173
|
-
value: encodeDefaultValue(defaultInput.value, codecForDefault(codecLookup, resolveCodec, site), site)
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
/** Whether TypeScript gives the value a literal type: a primitive, or an array or plain object of them. */
|
|
177
|
-
function hasLiteralType(value) {
|
|
178
|
-
if ([
|
|
179
|
-
"string",
|
|
180
|
-
"number",
|
|
181
|
-
"boolean",
|
|
182
|
-
"bigint"
|
|
183
|
-
].includes(typeof value)) return true;
|
|
184
|
-
if (Array.isArray(value)) return value.every(hasLiteralType);
|
|
185
|
-
if (typeof value !== "object" || value === null) return false;
|
|
186
|
-
const prototype = Object.getPrototypeOf(value);
|
|
187
|
-
return (prototype === Object.prototype || prototype === null) && Object.values(value).every(hasLiteralType);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Refuses a member whose codec reads its stored value back as a different value from the one written.
|
|
191
|
-
* The contract's types name the member as written, while the runtime reads the stored value, so the
|
|
192
|
-
* two must be the same value. A member with no literal type has nothing to contradict. The caller
|
|
193
|
-
* has already read the stored value back once, so the codec takes it.
|
|
194
|
-
*/
|
|
195
|
-
function assertStoredAsWritten(enumName, member, stored, codec) {
|
|
196
|
-
if (!hasLiteralType(member.value)) return;
|
|
197
|
-
const readBack = codec.decodeJson(stored);
|
|
198
|
-
if (hasLiteralType(readBack) && canonicalStringify(readBack) === canonicalStringify(member.value)) return;
|
|
199
|
-
const writeAs = hasLiteralType(readBack) ? canonicalStringify(readBack) : JSON.stringify(stored);
|
|
200
|
-
throw contractError("CONTRACT.ENUM_INVALID", `enumType("${enumName}"): member "${member.name}" is written ${canonicalStringify(member.value)}, but the column stores ${JSON.stringify(stored)}. Write the member as ${writeAs}.`, { meta: {
|
|
201
|
-
enumName,
|
|
202
|
-
member: member.name,
|
|
203
|
-
reason: "member-not-stored-as-written"
|
|
204
|
-
} });
|
|
205
|
-
}
|
|
206
|
-
/** A member's value in the form the enum's codec stores it. A member the codec refuses is a `CONTRACT.ENUM_INVALID` naming the enum and the member. */
|
|
207
|
-
function encodeEnumMember(handle, member, codec) {
|
|
208
|
-
try {
|
|
209
|
-
return encodeViaCodec(member.value, codec);
|
|
210
|
-
} catch (cause) {
|
|
211
|
-
if (cause instanceof InternalError) throw cause;
|
|
212
|
-
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
213
|
-
throw contractError("CONTRACT.ENUM_INVALID", `enumType("${handle.enumName}") member "${member.name}" has a value its codec ${handle.codecId} refuses: ${reason}`, {
|
|
214
|
-
fix: "Give the member a value the codec takes, or type the enum with a codec that takes it.",
|
|
215
|
-
cause,
|
|
216
|
-
meta: {
|
|
217
|
-
enumName: handle.enumName,
|
|
218
|
-
member: member.name,
|
|
219
|
-
codecId: handle.codecId,
|
|
220
|
-
reason: "codec-refused-member"
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Each member's value in the form the enum's codec stores it, read back by the codec. A codec an
|
|
227
|
-
* enum cannot use, a member the codec refuses, a member written differently from how it is stored,
|
|
228
|
-
* and two members that store the same value are each a `CONTRACT.ENUM_INVALID`.
|
|
229
|
-
*/
|
|
230
|
-
function encodeEnumMembers(handle, codecLookup) {
|
|
231
|
-
const descriptor = codecLookup.descriptorFor(handle.codecId);
|
|
232
|
-
const enumRefusal = descriptor === void 0 ? void 0 : enumRefusalOf(descriptor);
|
|
233
|
-
if (enumRefusal !== void 0) throw contractError("CONTRACT.ENUM_INVALID", `enumType("${handle.enumName}"): an enum cannot use the codec ${handle.codecId}. ${enumRefusal}`, {
|
|
234
|
-
fix: "Type the enum with another codec.",
|
|
235
|
-
meta: {
|
|
236
|
-
enumName: handle.enumName,
|
|
237
|
-
codecId: handle.codecId,
|
|
238
|
-
reason: "codec-not-for-enums"
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
const codec = codecLookup.get(handle.codecId);
|
|
242
|
-
const members = handle.enumMembers.map((member) => {
|
|
243
|
-
const value = encodeEnumMember(handle, member, codec);
|
|
244
|
-
if (codec !== void 0) assertStoredAsWritten(handle.enumName, member, value, codec);
|
|
245
|
-
return {
|
|
246
|
-
name: member.name,
|
|
247
|
-
value
|
|
248
|
-
};
|
|
249
|
-
});
|
|
250
|
-
assertEnumMembersStoredUniquely(handle.enumName, members.map(({ name, value }) => ({
|
|
251
|
-
name,
|
|
252
|
-
stored: value
|
|
253
|
-
})));
|
|
254
|
-
return members;
|
|
255
|
-
}
|
|
256
56
|
/**
|
|
257
57
|
* The member values a membership check must enforce, encoded exactly as the
|
|
258
58
|
* column stores them. Membership predicates support strings and finite numbers.
|
|
259
59
|
*/
|
|
260
60
|
function checkMemberValues(handle, codecLookup) {
|
|
261
|
-
const encoded =
|
|
61
|
+
const encoded = encodeEnumTypeMembers(handle, codecLookup, "the column").map((member) => member.value);
|
|
262
62
|
const values = [];
|
|
263
63
|
for (const value of encoded) {
|
|
264
64
|
if (typeof value !== "string" && !(typeof value === "number" && Number.isFinite(value))) throw contractError("CONTRACT.ENUM_INVALID", `enumType("${handle.enumName}"): CHECK constraint members must encode to strings or finite numbers.`, { meta: {
|
|
@@ -311,6 +111,32 @@ function buildDomainField(field, defaultNamespaceId, storageTypes) {
|
|
|
311
111
|
...ifDefined("valueSet", enumValueSetRefs(field.enumTypeHandle, defaultNamespaceId)?.domain)
|
|
312
112
|
};
|
|
313
113
|
}
|
|
114
|
+
/** How an error message names the column: `Field "Model.field"` or `Column "table.column"`. */
|
|
115
|
+
function columnSiteSubject(site) {
|
|
116
|
+
return site.kind === "field" ? `Field "${site.modelName}.${site.fieldName}"` : `Column "${site.tableName}.${site.columnName}"`;
|
|
117
|
+
}
|
|
118
|
+
/** The error metadata that locates the column. */
|
|
119
|
+
function columnSiteMeta(site) {
|
|
120
|
+
return site.kind === "field" ? {
|
|
121
|
+
modelName: site.modelName,
|
|
122
|
+
fieldName: site.fieldName
|
|
123
|
+
} : {
|
|
124
|
+
namespaceId: site.namespaceId,
|
|
125
|
+
tableName: site.tableName,
|
|
126
|
+
columnName: site.columnName
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** How an error message names the owner: `model "User"` or `table "audit_rows" in namespace "public"`. */
|
|
130
|
+
function referenceOwnerSubject(owner) {
|
|
131
|
+
return owner.kind === "model" ? `model "${owner.modelName}"` : `table "${owner.tableName}" in namespace "${owner.namespaceId}"`;
|
|
132
|
+
}
|
|
133
|
+
/** The error metadata that locates the owner. */
|
|
134
|
+
function referenceOwnerMeta(owner) {
|
|
135
|
+
return owner.kind === "model" ? { sourceModel: owner.modelName } : {
|
|
136
|
+
sourceTable: owner.tableName,
|
|
137
|
+
sourceNamespaceId: owner.namespaceId
|
|
138
|
+
};
|
|
139
|
+
}
|
|
314
140
|
/** A declared namespace coordinate, where an omitted or empty one means the target's default namespace. */
|
|
315
141
|
function namespaceIdOrDefault(namespaceId, defaultNamespaceId) {
|
|
316
142
|
return namespaceId !== void 0 && namespaceId.length > 0 ? namespaceId : defaultNamespaceId;
|
|
@@ -749,6 +575,99 @@ function describeTableNode(table, context) {
|
|
|
749
575
|
};
|
|
750
576
|
}
|
|
751
577
|
/**
|
|
578
|
+
* The codec that encodes one column's default, built with the column's own `typeParams`, because a parameterized codec checks its params when it encodes and reads a default. Only a column has params; every other encode site takes the representative instance.
|
|
579
|
+
*/
|
|
580
|
+
function columnCodec(codecId, typeParams, codecLookup) {
|
|
581
|
+
return codecForRef(codecLookup, {
|
|
582
|
+
codecId,
|
|
583
|
+
...ifDefined("typeParams", typeParams === void 0 ? void 0 : blindCast(typeParams))
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
/** Encodes a value the contract stores, and reads it back with the codec, which refuses a value its column would not hold. */
|
|
587
|
+
function encodeViaCodec(value, codec) {
|
|
588
|
+
if (codec) {
|
|
589
|
+
const json = codec.encodeJson(value);
|
|
590
|
+
codec.decodeJson(json);
|
|
591
|
+
return json;
|
|
592
|
+
}
|
|
593
|
+
return blindCast(value);
|
|
594
|
+
}
|
|
595
|
+
function defaultRefusal(site, cause, elementPosition) {
|
|
596
|
+
const subject = elementPosition === void 0 ? "default" : `default (element ${elementPosition})`;
|
|
597
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
598
|
+
return contractError("CONTRACT.DEFAULT_INVALID", `${columnSiteSubject(site)} has a ${subject} that its codec refuses: ${reason}`, {
|
|
599
|
+
cause,
|
|
600
|
+
meta: {
|
|
601
|
+
...columnSiteMeta(site),
|
|
602
|
+
codecId: site.codecId,
|
|
603
|
+
reason: "codec-refused-default",
|
|
604
|
+
...ifDefined("elementPosition", elementPosition)
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
function encodeDefaultValue(value, codec, site, elementPosition) {
|
|
609
|
+
try {
|
|
610
|
+
return encodeViaCodec(value, codec);
|
|
611
|
+
} catch (cause) {
|
|
612
|
+
if (cause instanceof InternalError) throw cause;
|
|
613
|
+
throw defaultRefusal(site, cause, elementPosition);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function codecForDefault(codecLookup, resolveCodec, site) {
|
|
617
|
+
const codec = buildCodecForDefault(codecLookup, resolveCodec, site);
|
|
618
|
+
if (codec === void 0) throw contractError("CONTRACT.DEFAULT_INVALID", `${columnSiteSubject(site)} has a default, but no pack in the contract declares its codec "${site.codecId}", so the default cannot be checked. List the pack that owns the codec in \`extensions\`.`, { meta: {
|
|
619
|
+
...columnSiteMeta(site),
|
|
620
|
+
codecId: site.codecId,
|
|
621
|
+
reason: "codec-not-found"
|
|
622
|
+
} });
|
|
623
|
+
return codec;
|
|
624
|
+
}
|
|
625
|
+
function buildCodecForDefault(codecLookup, resolveCodec, site) {
|
|
626
|
+
try {
|
|
627
|
+
return resolveCodec(codecLookup);
|
|
628
|
+
} catch (cause) {
|
|
629
|
+
if (!isStructuredError(cause) || cause.code !== "RUNTIME.TYPE_PARAMS_INVALID") throw cause;
|
|
630
|
+
throw contractError("CONTRACT.ARGUMENT_INVALID", `${columnSiteSubject(site)} has type parameters that its codec does not accept: ${cause.message}`, {
|
|
631
|
+
cause,
|
|
632
|
+
meta: {
|
|
633
|
+
...columnSiteMeta(site),
|
|
634
|
+
codecId: site.codecId,
|
|
635
|
+
reason: "type-params-invalid"
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function encodeColumnDefault(defaultInput, codecLookup, resolveCodec, site, many = false, elementNullable = false) {
|
|
641
|
+
if (defaultInput.kind === "function") return {
|
|
642
|
+
kind: "function",
|
|
643
|
+
expression: defaultInput.expression
|
|
644
|
+
};
|
|
645
|
+
if ("canonical" in defaultInput && defaultInput.canonical === true) return {
|
|
646
|
+
kind: "literal",
|
|
647
|
+
value: blindCast(defaultInput.value)
|
|
648
|
+
};
|
|
649
|
+
if (many) {
|
|
650
|
+
if (!Array.isArray(defaultInput.value)) throw contractError("CONTRACT.DEFAULT_INVALID", `${columnSiteSubject(site)} is a list field, so its default is an array; received ${typeof defaultInput.value}. Call .many() before .default().`, { meta: {
|
|
651
|
+
...columnSiteMeta(site),
|
|
652
|
+
codecId: site.codecId,
|
|
653
|
+
reason: "list-default-not-array"
|
|
654
|
+
} });
|
|
655
|
+
const codec = codecForDefault(codecLookup, resolveCodec, site);
|
|
656
|
+
return {
|
|
657
|
+
kind: "literal",
|
|
658
|
+
value: defaultInput.value.map((element, index) => {
|
|
659
|
+
if (element !== null) return encodeDefaultValue(element, codec, site, index + 1);
|
|
660
|
+
if (elementNullable) return null;
|
|
661
|
+
throw new InternalError("Literal default on a strict list column cannot contain null elements.");
|
|
662
|
+
})
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
kind: "literal",
|
|
667
|
+
value: encodeDefaultValue(defaultInput.value, codecForDefault(codecLookup, resolveCodec, site), site)
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
752
671
|
* Records a deferred column's entity-ref into the namespace-scoped collection
|
|
753
672
|
* accumulator (`namespaceId → entityKind → entityName`) — folded into the same
|
|
754
673
|
* namespace assembly `deriveEntityValueSets`/`entries.<kind>` step as the
|
|
@@ -1368,7 +1287,7 @@ function buildSqlContractFromDefinition(definition, codecLookup, dataTypeLookup)
|
|
|
1368
1287
|
domainSlot = {};
|
|
1369
1288
|
domainEnumsByNs[nsId] = domainSlot;
|
|
1370
1289
|
}
|
|
1371
|
-
const storedMembers =
|
|
1290
|
+
const storedMembers = encodeEnumTypeMembers(handle, codecLookup, "the column");
|
|
1372
1291
|
domainSlot[enumName] = {
|
|
1373
1292
|
codecId: handle.codecId,
|
|
1374
1293
|
members: storedMembers
|
|
@@ -1615,4 +1534,4 @@ function withoutDerivedChecks(tableName, table, contractDefault) {
|
|
|
1615
1534
|
//#endregion
|
|
1616
1535
|
export { storedAsListColumn as a, isValueObjectMember as i, buildSqlContractFromDefinition as n, toOneNullabilityContradictionMessage as o, contractError as r, applySqlSpecifierControlPolicy as t };
|
|
1617
1536
|
|
|
1618
|
-
//# sourceMappingURL=derived-checks-
|
|
1537
|
+
//# sourceMappingURL=derived-checks-CYz041Ol-TjL7rPxe.mjs.map
|