@prisma/orm-family-sql 8.0.0-rc.20-dev.13 → 8.0.0-rc.20-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/{attribute-specs-DA_RwQFB.d.mts → attribute-specs-Dcd2ZUrY.d.mts} +4 -3
- package/dist/attribute-specs-Dcd2ZUrY.d.mts.map +1 -0
- package/dist/{authoring-entity-types-CgKIgWq5-pEdfjam5.d.mts → authoring-entity-types-CgKIgWq5-CZK1F9a_.d.mts} +2 -2
- package/dist/{authoring-entity-types-CgKIgWq5-pEdfjam5.d.mts.map → authoring-entity-types-CgKIgWq5-CZK1F9a_.d.mts.map} +1 -1
- package/dist/compare-strings-BVf3BgCV-CefXnrMB.mjs +10 -0
- package/dist/compare-strings-BVf3BgCV-CefXnrMB.mjs.map +1 -0
- package/dist/{contract-builder-C_Zi57iD.d.mts → contract-builder-B-Q9T1CO.d.mts} +10 -79
- package/dist/contract-builder-B-Q9T1CO.d.mts.map +1 -0
- package/dist/{contract-builder-50lF0kz1.mjs → contract-builder-DMNe_jX9.mjs} +109 -96
- package/dist/contract-builder-DMNe_jX9.mjs.map +1 -0
- package/dist/contract-prisma7__provider.mjs +2 -2
- 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.mjs +1 -1
- package/dist/contract-psl__diagnostics.d.mts +3 -4
- package/dist/contract-psl__diagnostics.d.mts.map +1 -1
- package/dist/contract-psl__diagnostics.mjs +1 -1
- package/dist/contract-psl__provider.mjs +1 -1
- package/dist/contract-psl__provider.mjs.map +1 -1
- package/dist/contract-ts.d.mts +1 -1
- package/dist/contract-ts.mjs +1 -1
- package/dist/contract-ts__contract-builder.d.mts +1 -1
- package/dist/contract-ts__contract-builder.mjs +1 -1
- package/dist/contract.d.mts +2 -1
- package/dist/contract.mjs +2 -1
- package/dist/contract__generated-id-column-aliases.d.mts +2 -0
- package/dist/contract__generated-id-column-aliases.mjs +2 -0
- package/dist/{control-CffuMKgt.d.mts → control-B6W_VEZ9.d.mts} +50 -176
- package/dist/control-B6W_VEZ9.d.mts.map +1 -0
- package/dist/{control-D7N_L18S.mjs → control-D6wIw5Fi.mjs} +4 -5
- package/dist/control-D6wIw5Fi.mjs.map +1 -0
- package/dist/diagnostics-C7jR1Jyf.mjs +109 -0
- package/dist/diagnostics-C7jR1Jyf.mjs.map +1 -0
- package/dist/family.d.mts +4 -4
- package/dist/family.mjs +5 -6
- package/dist/family__control.d.mts +1 -1
- package/dist/family__control.mjs +1 -1
- package/dist/family__pack.d.mts +2 -2
- package/dist/family__pack.mjs +27 -3
- package/dist/family__pack.mjs.map +1 -0
- package/dist/family__psl-build.mjs +1 -1
- package/dist/family__runtime.d.mts +1 -1
- package/dist/family__runtime.mjs +1 -1
- package/dist/generated-id-column-aliases-DCuTuZrU.d.mts +71 -0
- package/dist/generated-id-column-aliases-DCuTuZrU.d.mts.map +1 -0
- package/dist/generated-id-column-aliases-DPUii1fN.mjs +51 -0
- package/dist/generated-id-column-aliases-DPUii1fN.mjs.map +1 -0
- package/dist/{generator-functions-Cg5QkM46-C1ByFzyT.mjs → generator-functions-Hy4pDDr9-AUCNpeg5.mjs} +49 -187
- package/dist/generator-functions-Hy4pDDr9-AUCNpeg5.mjs.map +1 -0
- package/dist/{interpreter-D5qk4B---CG0C7kdx.mjs → interpreter-CS21wD1i-G0u1x8t_.mjs} +13 -10
- package/dist/interpreter-CS21wD1i-G0u1x8t_.mjs.map +1 -0
- package/dist/orm-client.d.mts +2 -2
- package/dist/orm-client.mjs +2 -2
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{pack-DA8HZ2mo.d.mts → pack-Cap3oVPy.d.mts} +69 -280
- package/dist/pack-Cap3oVPy.d.mts.map +1 -0
- package/dist/{psl-build-DFBG6vhz.mjs → psl-build-DqqYhOsa.mjs} +2 -2
- package/dist/psl-build-DqqYhOsa.mjs.map +1 -0
- package/dist/{psl-column-resolution-ChZqioOc-BREg4J7d.d.mts → psl-column-resolution-djGEITmJ-B5iMpe8H.d.mts} +4 -4
- package/dist/psl-column-resolution-djGEITmJ-B5iMpe8H.d.mts.map +1 -0
- package/dist/{psl-field-resolution-C5KQ7kzP-B0NwuRWV.mjs → psl-field-resolution-Bvhx79fP-CQqHf_L4.mjs} +20 -107
- package/dist/psl-field-resolution-Bvhx79fP-CQqHf_L4.mjs.map +1 -0
- package/dist/{runtime-6tH1yOxK.mjs → runtime-CCzfa1mY.mjs} +2 -3
- package/dist/{runtime-6tH1yOxK.mjs.map → runtime-CCzfa1mY.mjs.map} +1 -1
- package/dist/{runtime-CF6rAlE5.d.mts → runtime-JKWb27L5.d.mts} +2 -3
- package/dist/{runtime-CF6rAlE5.d.mts.map → runtime-JKWb27L5.d.mts.map} +1 -1
- package/package.json +19 -18
- package/dist/attribute-specs-DA_RwQFB.d.mts.map +0 -1
- package/dist/contract-builder-50lF0kz1.mjs.map +0 -1
- package/dist/contract-builder-C_Zi57iD.d.mts.map +0 -1
- package/dist/control-CffuMKgt.d.mts.map +0 -1
- package/dist/control-D7N_L18S.mjs.map +0 -1
- package/dist/diagnostics-RHJxoiIk.mjs +0 -23
- package/dist/diagnostics-RHJxoiIk.mjs.map +0 -1
- package/dist/generator-functions-Cg5QkM46-C1ByFzyT.mjs.map +0 -1
- package/dist/interpreter-D5qk4B---CG0C7kdx.mjs.map +0 -1
- package/dist/pack-DA8HZ2mo.d.mts.map +0 -1
- package/dist/pack-DOTaBfUC.mjs +0 -80
- package/dist/pack-DOTaBfUC.mjs.map +0 -1
- package/dist/psl-build-DFBG6vhz.mjs.map +0 -1
- package/dist/psl-column-resolution-ChZqioOc-BREg4J7d.d.mts.map +0 -1
- package/dist/psl-field-resolution-C5KQ7kzP-B0NwuRWV.mjs.map +0 -1
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { d as sqlColumnLength } from "./sql-data-type-D7M-YTTY-D2vRqDxn.mjs";
|
|
2
2
|
import { t as providesEntityHandleLowering } from "./entity-handle-lowering-hook-BJZSlVVF.mjs";
|
|
3
|
+
import { n as generatedIdColumnAliases, t as GENERATED_ID_COLUMN_ALIAS_NAMESPACES } from "./generated-id-column-aliases-DPUii1fN.mjs";
|
|
3
4
|
import { a as isSqlExpression, c as requireSqlExpression, r as SqlExpression, s as readSqlExpression } from "./sql-expression-CKgKznXS.mjs";
|
|
4
5
|
import { t as CODEC_INSTANCE_KIND } from "./types-CTdSkl0s.mjs";
|
|
5
6
|
import { n as checkSqlDefaultText, o as reservedSqlDefaultText } from "./validators-BwA7ttZM.mjs";
|
|
6
7
|
import { a as refuseTypesKey, n as buildSqlContractFromDefinition, r as contractError, s as toOneNullabilityContradictionMessage } from "./derived-checks-D5HVRvqN-BJx1gwPA.mjs";
|
|
7
8
|
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
8
9
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
9
|
-
import { assembleDataTypeSupport, assertNoCrossRegistryCollisions, assertTypeAliasesValid, describeAdmittedForms,
|
|
10
|
+
import { assembleDataTypeSupport, assertNoCrossRegistryCollisions, assertTypeAliasesValid, describeAdmittedForms, instantiateAuthoringTypeAlias, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringTypeAliasDescriptor, isAuthoringTypeConstructorDescriptor, isAuthoringTypeDescriptor, readWrittenValueAs, validateAuthoringHelperArguments, validateAuthoringTypeParams } from "@prisma/orm-framework/components/authoring";
|
|
10
11
|
import { dataTypeId, numeralText } from "@prisma/orm-framework/components/codec";
|
|
11
12
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
12
13
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
13
14
|
import { isColumnDefault } from "@prisma/orm-framework/contract/types";
|
|
14
15
|
import { assembleGeneratorFunctions, createGeneratorHelpers } from "@prisma/orm-framework/components/components";
|
|
15
|
-
import { assertSafeAuthoringHelperKey, bindEnumType, composePackAuthoringNamespace, createEntityHelpersFromNamespace,
|
|
16
|
+
import { answerMissingPropertyReads, assertSafeAuthoringHelperKey, bindEnumType, composePackAuthoringNamespace, createEntityHelpersFromNamespace, enumType, isEnumTypeHandle, member, resolveToOneRelationNullable } from "@prisma/orm-framework/contract-authoring";
|
|
16
17
|
import { UNBOUND_PSL_NAMESPACE_NAME } from "@prisma/orm-framework/components/psl-ast";
|
|
17
18
|
//#region ../../../2-sql-family/2-authoring/contract-ts/dist/contract-builder.mjs
|
|
18
19
|
/** The written value a TypeScript argument stands for: a number, string or boolean as written in PSL, and a `sql` value as a `sql` literal of its text. */
|
|
@@ -46,21 +47,15 @@ function readValueArgument(label, value, dataType, dataTypes) {
|
|
|
46
47
|
return read.ok ? read.value.value : refuse(read.failure.message);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
|
-
* The arguments of a type constructor
|
|
50
|
+
* The arguments of a type constructor call as the constructor receives them: each `value` argument read as a value of its data type, through the same read and cast as a PSL argument, so both give the same parameters. ADR 129, ADR 254.
|
|
50
51
|
*/
|
|
51
52
|
function readValueArguments(helperPath, descriptors, args, dataTypes) {
|
|
52
53
|
return args.map((value, index) => {
|
|
53
54
|
const descriptor = descriptors?.[index];
|
|
54
|
-
if (descriptor
|
|
55
|
+
if (descriptor === void 0 || value === void 0) return value;
|
|
55
56
|
return readValueArgument(descriptor.name === void 0 ? `Argument #${index + 1} of ${helperPath}` : `Argument "${descriptor.name}" of ${helperPath}`, value, dataTypeId(descriptor.dataType), dataTypes);
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
|
-
function isNamedConstraintOptionsLike(value) {
|
|
59
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
60
|
-
if (Object.keys(value).some((key) => key !== "name")) return false;
|
|
61
|
-
const name = value.name;
|
|
62
|
-
return name === void 0 || typeof name === "string";
|
|
63
|
-
}
|
|
64
59
|
function createTypeHelpersFromNamespace(namespace, lookups, path = []) {
|
|
65
60
|
const helpers = {};
|
|
66
61
|
for (const [key, value] of Object.entries(namespace)) {
|
|
@@ -103,35 +98,8 @@ function createTypeHelpersFromNamespace(namespace, lookups, path = []) {
|
|
|
103
98
|
}
|
|
104
99
|
return helpers;
|
|
105
100
|
}
|
|
106
|
-
function createFieldPresetHelper(options) {
|
|
107
|
-
return (...rawArgs) => {
|
|
108
|
-
const acceptsNamedConstraintOptions = options.descriptor.output.id === true || options.descriptor.output.unique === true;
|
|
109
|
-
const declaredArguments = options.descriptor.args ?? [];
|
|
110
|
-
if (acceptsNamedConstraintOptions && rawArgs.length > declaredArguments.length + 1) throw contractError("CONTRACT.ARGUMENT_INVALID", `${options.helperPath} expects at most ${declaredArguments.length + 1} argument(s), received ${rawArgs.length}`, { meta: {
|
|
111
|
-
helperPath: options.helperPath,
|
|
112
|
-
expected: declaredArguments.length + 1,
|
|
113
|
-
received: rawArgs.length
|
|
114
|
-
} });
|
|
115
|
-
let args = rawArgs;
|
|
116
|
-
let namedConstraintOptions;
|
|
117
|
-
if (acceptsNamedConstraintOptions && rawArgs.length === declaredArguments.length + 1) {
|
|
118
|
-
const maybeNamedConstraintOptions = rawArgs.at(-1);
|
|
119
|
-
if (!isNamedConstraintOptionsLike(maybeNamedConstraintOptions)) throw contractError("CONTRACT.ARGUMENT_INVALID", `${options.helperPath} accepts an optional trailing { name?: string } constraint options object`, { meta: { helperPath: options.helperPath } });
|
|
120
|
-
namedConstraintOptions = maybeNamedConstraintOptions;
|
|
121
|
-
args = rawArgs.slice(0, -1);
|
|
122
|
-
}
|
|
123
|
-
validateAuthoringHelperArguments(options.helperPath, options.descriptor.args, args);
|
|
124
|
-
const values = readValueArguments(options.helperPath, options.descriptor.args, args, options.dataTypes);
|
|
125
|
-
const output = options.descriptor.output;
|
|
126
|
-
validateAuthoringTypeParams(options.helperPath, output, instantiateAuthoringFieldPreset(options.descriptor, values).descriptor.typeParams, options.codecLookup.descriptorFor(output.codecId)?.paramsSchema);
|
|
127
|
-
return options.build({
|
|
128
|
-
args: values,
|
|
129
|
-
...namedConstraintOptions ? { namedConstraintOptions } : {}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
101
|
function withGeneratorCall(state, phase, call) {
|
|
134
|
-
if (state.generatorCalls?.[phase] !== void 0
|
|
102
|
+
if (state.generatorCalls?.[phase] !== void 0) throw contractError("CONTRACT.DEFAULT_INVALID", `.${phase}() is called on a field that already generates a value ${phase === "onCreate" ? "on create" : "on update"}. Set each phase once, and do not combine .${phase}() with a type alias or alias constant that sets it.`, { meta: {
|
|
135
103
|
reason: "generator-phase-set-twice",
|
|
136
104
|
phase
|
|
137
105
|
} });
|
|
@@ -144,7 +112,7 @@ function withGeneratorCall(state, phase, call) {
|
|
|
144
112
|
};
|
|
145
113
|
}
|
|
146
114
|
function withColumnDefault(state, columnDefault) {
|
|
147
|
-
if (state.default !== void 0) throw contractError("CONTRACT.DEFAULT_INVALID", ".default() is called on a field that already has a default. Set the default once, and do not combine .default() with
|
|
115
|
+
if (state.default !== void 0) throw contractError("CONTRACT.DEFAULT_INVALID", ".default() is called on a field that already has a default. Set the default once, and do not combine .default() with an alias constant that sets one.", { meta: { reason: "default-set-twice" } });
|
|
148
116
|
return {
|
|
149
117
|
...state,
|
|
150
118
|
default: columnDefault
|
|
@@ -290,37 +258,12 @@ const columnField = (descriptor) => {
|
|
|
290
258
|
...ifDefined("generatorCalls", generatorCalls)
|
|
291
259
|
});
|
|
292
260
|
};
|
|
293
|
-
function generatedField(spec) {
|
|
294
|
-
return new ScalarFieldBuilder({
|
|
295
|
-
kind: "scalar",
|
|
296
|
-
descriptor: blindCast({
|
|
297
|
-
...spec.type,
|
|
298
|
-
...spec.typeParams ? { typeParams: spec.typeParams } : {}
|
|
299
|
-
}),
|
|
300
|
-
nullable: false,
|
|
301
|
-
many: false,
|
|
302
|
-
executionDefaults: { onCreate: spec.generated }
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
261
|
const namedTypeField = (handle) => new EnumScalarFieldBuilder(blindCast({
|
|
306
262
|
kind: "scalar",
|
|
307
263
|
enumHandle: handle,
|
|
308
264
|
nullable: false,
|
|
309
265
|
many: false
|
|
310
266
|
}), handle);
|
|
311
|
-
function buildFieldPreset(descriptor, args, namedConstraintOptions) {
|
|
312
|
-
const preset = instantiateAuthoringFieldPreset(descriptor, args);
|
|
313
|
-
return new ScalarFieldBuilder({
|
|
314
|
-
kind: "scalar",
|
|
315
|
-
descriptor: preset.descriptor,
|
|
316
|
-
nullable: preset.nullable,
|
|
317
|
-
many: false,
|
|
318
|
-
...ifDefined("default", preset.default),
|
|
319
|
-
...ifDefined("executionDefaults", preset.executionDefaults),
|
|
320
|
-
...preset.id ? { id: namedConstraintOptions?.name ? { name: namedConstraintOptions.name } : {} } : {},
|
|
321
|
-
...preset.unique ? { unique: namedConstraintOptions?.name ? { name: namedConstraintOptions.name } : {} } : {}
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
267
|
var RelationBuilder = class RelationBuilder {
|
|
325
268
|
state;
|
|
326
269
|
constructor(state) {
|
|
@@ -676,7 +619,6 @@ const rel = {
|
|
|
676
619
|
};
|
|
677
620
|
const field = {
|
|
678
621
|
column: columnField,
|
|
679
|
-
generated: generatedField,
|
|
680
622
|
namedType: namedTypeField
|
|
681
623
|
};
|
|
682
624
|
function isContractInput(value) {
|
|
@@ -714,12 +656,104 @@ function applyNaming(name, strategy) {
|
|
|
714
656
|
}
|
|
715
657
|
return result;
|
|
716
658
|
}
|
|
659
|
+
const GUIDE = "The upgrade guide \"Field presets are removed\" lists every rewrite.";
|
|
660
|
+
/** The row of a preset whose rewrite is `rewrite`; its type is the first `type.X(` that `rewrite` writes. */
|
|
661
|
+
function writtenAs(rewrite, codecId) {
|
|
662
|
+
return [{
|
|
663
|
+
type: (/type\.([\w.]+)\(/.exec(rewrite)?.[1] ?? "").split("."),
|
|
664
|
+
codecId,
|
|
665
|
+
rewrite
|
|
666
|
+
}];
|
|
667
|
+
}
|
|
668
|
+
/** The `type.` prefix of a namespace, such as `sql.` for `['sql']`. */
|
|
669
|
+
const prefixOf = (namespace) => namespace.map((name) => `${name}.`).join("");
|
|
670
|
+
/** The rows of a preset whose rewrite `write` makes from each namespace's `type.` prefix, each named where that namespace has the generated id column alias `alias`. */
|
|
671
|
+
function idAlias(alias, write) {
|
|
672
|
+
return GENERATED_ID_COLUMN_ALIAS_NAMESPACES.map((namespace) => ({
|
|
673
|
+
type: [...namespace, alias],
|
|
674
|
+
codecId: generatedIdColumnAliases[alias].output.type.codecId,
|
|
675
|
+
rewrite: write(prefixOf(namespace))
|
|
676
|
+
}));
|
|
677
|
+
}
|
|
678
|
+
const column$1 = (prefix, type) => `field.column(type.${prefix}${type})`;
|
|
679
|
+
const id = (columnText, generator) => `${columnText}.id().onCreate(gen.${generator})`;
|
|
680
|
+
const aliasColumn = (alias) => idAlias(alias, (prefix) => column$1(prefix, `${alias}()`));
|
|
681
|
+
const aliasId = (alias, generator) => idAlias(alias, (prefix) => id(column$1(prefix, `${alias}()`), generator));
|
|
682
|
+
const withPhases = (type, codecId, precision) => writtenAs(`field.column(type.${type}(${precision ? "p" : ""})), with .onCreate(gen.now()) and .onUpdate(gen.now()) for the phases the preset set${precision ? ", and without p when it set no precision" : ""}`, codecId);
|
|
683
|
+
const PRESETS = {
|
|
684
|
+
uuidString: aliasColumn("UuidString"),
|
|
685
|
+
ulid: aliasColumn("Ulid"),
|
|
686
|
+
nanoid: idAlias("Nanoid", (prefix) => `${column$1(prefix, "Nanoid()")}, or ${column$1(prefix, "Char(n)")} for nanoid({ size: n })`),
|
|
687
|
+
cuid2: aliasColumn("Cuid2"),
|
|
688
|
+
ksuid: aliasColumn("Ksuid"),
|
|
689
|
+
text: writtenAs("field.column(type.String())", "pg/text@1"),
|
|
690
|
+
int: writtenAs("field.column(type.Int())", "pg/int4@1"),
|
|
691
|
+
bigint: writtenAs("field.column(type.BigInt())", "pg/int8@1"),
|
|
692
|
+
float: writtenAs("field.column(type.Float())", "pg/float8@1"),
|
|
693
|
+
decimal: writtenAs("field.column(type.Decimal())", "pg/numeric@1"),
|
|
694
|
+
boolean: writtenAs("field.column(type.Boolean())", "pg/bool@1"),
|
|
695
|
+
json: writtenAs("field.column(type.Jsonb())", "pg/jsonb@1"),
|
|
696
|
+
bytes: writtenAs("field.column(type.Bytes())", "pg/bytea@1"),
|
|
697
|
+
dateTime: writtenAs("field.column(type.DateTime())", "pg/timestamptz-temporal@1"),
|
|
698
|
+
uuidNative: writtenAs("field.column(type.Uuid())", "pg/uuid@1"),
|
|
699
|
+
generated: idAlias("UuidString", (prefix) => `${column$1(prefix, "Char(n)")}.onCreate(gen.fn()), such as ${column$1(prefix, "UuidString()")}.onCreate(gen.uuid()) for field.generated(uuidv4())`),
|
|
700
|
+
"id.uuidv4String": aliasId("UuidString", "uuid()"),
|
|
701
|
+
"id.uuidv7String": aliasId("UuidString", "uuid(7)"),
|
|
702
|
+
"id.ulid": aliasId("Ulid", "ulid()"),
|
|
703
|
+
"id.nanoid": idAlias("Nanoid", (prefix) => `${id(column$1(prefix, "Nanoid()"), "nanoid()")}, or ${id(column$1(prefix, "Char(n)"), "nanoid(n)")} for id.nanoid({ size: n })`),
|
|
704
|
+
"id.cuid2": aliasId("Cuid2", "cuid(2)"),
|
|
705
|
+
"id.ksuid": aliasId("Ksuid", "ksuid()"),
|
|
706
|
+
"id.uuidv4Native": writtenAs(id("field.column(type.Uuid())", "uuid()"), "pg/uuid@1"),
|
|
707
|
+
"id.uuidv7Native": writtenAs(id("field.column(type.Uuid())", "uuid(7)"), "pg/uuid@1"),
|
|
708
|
+
"temporal.createdAt": writtenAs("field.column(type.temporal.CreatedAt())"),
|
|
709
|
+
"temporal.updatedAt": writtenAs("field.column(type.temporal.UpdatedAt())"),
|
|
710
|
+
"temporal.createdAtString": writtenAs("field.column(type.temporal.CreatedAtString())"),
|
|
711
|
+
"temporal.updatedAtString": writtenAs("field.column(type.temporal.UpdatedAtString())"),
|
|
712
|
+
"temporal.createdAtJsDate": writtenAs("field.column(type.temporal.CreatedAtJsDate())"),
|
|
713
|
+
"temporal.updatedAtJsDate": writtenAs("field.column(type.temporal.UpdatedAtJsDate())"),
|
|
714
|
+
"temporal.timestamp": withPhases("TimestampTemporal", "pg/timestamp-temporal@1", true),
|
|
715
|
+
"temporal.timestamptz": withPhases("TimestamptzTemporal", "pg/timestamptz-temporal@1", true),
|
|
716
|
+
"temporal.timestampString": withPhases("TimestampString", "pg/timestamp-string@1", true),
|
|
717
|
+
"temporal.timestamptzString": withPhases("TimestamptzString", "pg/timestamptz-string@1", true),
|
|
718
|
+
"temporal.timestamptzJsDate": withPhases("TimestamptzJsDate", "pg/timestamptz-date@1", true),
|
|
719
|
+
"temporal.date": withPhases("Date", "pg/date-temporal@1", false),
|
|
720
|
+
"temporal.dateString": withPhases("DateString", "pg/date-string@1", false),
|
|
721
|
+
"temporal.time": withPhases("Time", "pg/time-temporal@1", true),
|
|
722
|
+
"temporal.timeString": withPhases("TimeString", "pg/time-string@1", true),
|
|
723
|
+
"temporal.timetz": withPhases("Timetz", "pg/timetz@1", true),
|
|
724
|
+
"temporal.datetime": withPhases("DateTime", "sqlite/datetime@1", false)
|
|
725
|
+
};
|
|
726
|
+
function codecIdAt(types, path) {
|
|
727
|
+
const [name, ...rest] = path;
|
|
728
|
+
if (name === void 0 || !Object.hasOwn(types, name)) return void 0;
|
|
729
|
+
const value = types[name];
|
|
730
|
+
if (value === void 0) return void 0;
|
|
731
|
+
if (!isAuthoringTypeDescriptor(value)) return codecIdAt(value, rest);
|
|
732
|
+
if (rest.length > 0) return void 0;
|
|
733
|
+
return isAuthoringTypeAliasDescriptor(value) ? value.output.type.codecId : value.output.codecId;
|
|
734
|
+
}
|
|
735
|
+
function appliesTo(preset, types) {
|
|
736
|
+
const codecId = codecIdAt(types, preset.type);
|
|
737
|
+
return codecId !== void 0 && (preset.codecId === void 0 || codecId === preset.codecId);
|
|
738
|
+
}
|
|
739
|
+
function refuse(path, types) {
|
|
740
|
+
const helper = `field.${path}`;
|
|
741
|
+
const preset = (Object.hasOwn(PRESETS, path) ? PRESETS[path] : void 0)?.find((row) => appliesTo(row, types));
|
|
742
|
+
throw contractError("CONTRACT.FIELD_HELPER_UNKNOWN", preset !== void 0 ? `${helper} was a field preset, and Prisma 8 removed field presets. Write ${preset.rewrite}. ${GUIDE}` : `${helper} does not exist. Prisma 8 removed field presets: declare a column as field.column(type.X(...)), add .id(), .onCreate(gen.fn()) and .onUpdate(gen.fn()) for what a preset set, or use a type alias such as field.column(type.temporal.CreatedAt()). ${GUIDE}`, { meta: { helper } });
|
|
743
|
+
}
|
|
744
|
+
function membersOf(namespace) {
|
|
745
|
+
return new Set(Object.keys(PRESETS).filter((path) => path.startsWith(`${namespace}.`)).map((path) => path.slice(namespace.length + 1)));
|
|
746
|
+
}
|
|
747
|
+
const NAMES = new Set(Object.keys(PRESETS).map((path) => path.split(".")[0] ?? path));
|
|
748
|
+
/**
|
|
749
|
+
* The SQL `field` helpers, where a read of a removed field preset throws `CONTRACT.FIELD_HELPER_UNKNOWN`, so a JavaScript caller, or a contract emitted before it is type-checked, learns what to write instead. The rewrite is named where `types`, the stack's `type` namespace, has the type it writes and that type stores the preset's codec; elsewhere the message names the forms that replace presets. `field.id` and `field.temporal`, which held presets, answer the same way for the presets read from them. Every other read behaves as on `helpers`.
|
|
750
|
+
*/
|
|
751
|
+
function refusingRemovedFieldPresets(helpers, types) {
|
|
752
|
+
return answerMissingPropertyReads(helpers, NAMES, (name) => Object.hasOwn(PRESETS, name) ? refuse(name, types) : answerMissingPropertyReads({}, membersOf(name), (member) => refuse(`${name}.${member}`, types)));
|
|
753
|
+
}
|
|
717
754
|
function composeTypeNamespace(components) {
|
|
718
755
|
return composePackAuthoringNamespace(components, "type");
|
|
719
756
|
}
|
|
720
|
-
function composeFieldNamespace(components) {
|
|
721
|
-
return composePackAuthoringNamespace(components, "field");
|
|
722
|
-
}
|
|
723
757
|
function composeEntityNamespace(components) {
|
|
724
758
|
return composePackAuthoringNamespace(components, "entityTypes");
|
|
725
759
|
}
|
|
@@ -746,26 +780,6 @@ function assertNoBuiltInEntityCollisions(namespace) {
|
|
|
746
780
|
reservedKeys: RESERVED_HELPER_KEYS
|
|
747
781
|
} });
|
|
748
782
|
}
|
|
749
|
-
function createComposedFieldHelpers(fieldNamespace, lookups) {
|
|
750
|
-
const helperNamespace = createFieldHelpersFromNamespace(fieldNamespace, ({ helperPath, descriptor }) => createFieldPresetHelper({
|
|
751
|
-
helperPath,
|
|
752
|
-
descriptor,
|
|
753
|
-
codecLookup: lookups.codecLookup,
|
|
754
|
-
dataTypes: lookups.dataTypes,
|
|
755
|
-
build: ({ args, namedConstraintOptions }) => buildFieldPreset(descriptor, args, namedConstraintOptions)
|
|
756
|
-
}));
|
|
757
|
-
const coreFieldHelpers = {
|
|
758
|
-
column: field.column,
|
|
759
|
-
generated: field.generated,
|
|
760
|
-
namedType: field.namedType
|
|
761
|
-
};
|
|
762
|
-
const coreHelperNames = new Set(Object.keys(coreFieldHelpers));
|
|
763
|
-
for (const helperName of Object.keys(helperNamespace)) if (coreHelperNames.has(helperName)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Duplicate authoring field helper "${helperName}". Core field helpers reserve that name.`, { meta: { helperName } });
|
|
764
|
-
return {
|
|
765
|
-
...coreFieldHelpers,
|
|
766
|
-
...helperNamespace
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
783
|
function createComposedAuthoringHelpers(options) {
|
|
770
784
|
const extensionValues = Object.values(options.extensions ?? {});
|
|
771
785
|
const components = [
|
|
@@ -774,9 +788,8 @@ function createComposedAuthoringHelpers(options) {
|
|
|
774
788
|
...extensionValues
|
|
775
789
|
];
|
|
776
790
|
const typeNamespace = composeTypeNamespace(components);
|
|
777
|
-
const fieldNamespace = composeFieldNamespace(components);
|
|
778
791
|
const entityNamespace = composeEntityNamespace(components);
|
|
779
|
-
assertNoCrossRegistryCollisions(typeNamespace,
|
|
792
|
+
assertNoCrossRegistryCollisions(typeNamespace, entityNamespace);
|
|
780
793
|
assertNoBuiltInEntityCollisions(entityNamespace);
|
|
781
794
|
const { support } = assembleDataTypeSupport(components, (codecId) => options.codecLookup.descriptorFor(codecId)?.dataType);
|
|
782
795
|
const helperLookups = {
|
|
@@ -790,7 +803,7 @@ function createComposedAuthoringHelpers(options) {
|
|
|
790
803
|
codecLookup: options.codecLookup,
|
|
791
804
|
dataTypes: support
|
|
792
805
|
} }),
|
|
793
|
-
field:
|
|
806
|
+
field: refusingRemovedFieldPresets(field, typeNamespace),
|
|
794
807
|
model,
|
|
795
808
|
rel,
|
|
796
809
|
type: createTypeHelpersFromNamespace(typeNamespace, helperLookups),
|
|
@@ -881,7 +894,7 @@ function emitTypedCrossModelFallbackWarnings(collection) {
|
|
|
881
894
|
}
|
|
882
895
|
flushWarnings(warnings);
|
|
883
896
|
}
|
|
884
|
-
/** A column stores no `typeParams` when it has none, as PSL writes it (
|
|
897
|
+
/** A column stores no `typeParams` when it has none, as PSL writes it (see "Deterministic emission" in `docs/architecture docs/subsystems/1. Data Contract.md`). */
|
|
885
898
|
function withoutEmptyTypeParams(descriptor) {
|
|
886
899
|
const { typeParams, ...rest } = descriptor;
|
|
887
900
|
return typeParams === void 0 || Object.keys(typeParams).length > 0 ? descriptor : rest;
|
|
@@ -1315,19 +1328,19 @@ function coveredFieldNames(index) {
|
|
|
1315
1328
|
return expression.fields.map((ref) => ref.fieldName);
|
|
1316
1329
|
}
|
|
1317
1330
|
/**
|
|
1318
|
-
* The generators a field's `.onCreate(...)` and `.onUpdate(...)` calls resolve to for its column
|
|
1331
|
+
* The generators a field's `.onCreate(...)` and `.onUpdate(...)` calls resolve to for its column.
|
|
1319
1332
|
*/
|
|
1320
1333
|
function resolveGeneratorCalls(input) {
|
|
1321
1334
|
const { modelName, fieldName, fieldState, descriptor, generatorFunctions } = input;
|
|
1322
1335
|
const calls = fieldState.generatorCalls;
|
|
1323
|
-
if (calls === void 0) return
|
|
1336
|
+
if (calls === void 0) return void 0;
|
|
1324
1337
|
const typeParams = descriptor.typeParams;
|
|
1325
1338
|
const column = {
|
|
1326
1339
|
codecId: descriptor.codecId,
|
|
1327
1340
|
typeParams,
|
|
1328
1341
|
length: input.columnLength(descriptor.codecId, typeParams)
|
|
1329
1342
|
};
|
|
1330
|
-
const phases = {
|
|
1343
|
+
const phases = {};
|
|
1331
1344
|
for (const phase of ["onCreate", "onUpdate"]) {
|
|
1332
1345
|
const call = calls[phase];
|
|
1333
1346
|
if (call === void 0) continue;
|
|
@@ -1852,4 +1865,4 @@ function autoincrement() {
|
|
|
1852
1865
|
//#endregion
|
|
1853
1866
|
export { check as a, enumType as c, member as d, model as f, buildContractDefinition as i, extensionModel as l, rel as m, bindEnumType as n, createComposedAuthoringHelpers as o, now as p, buildBoundContract as r, defineContract as s, autoincrement as t, field as u };
|
|
1854
1867
|
|
|
1855
|
-
//# sourceMappingURL=contract-builder-
|
|
1868
|
+
//# sourceMappingURL=contract-builder-DMNe_jX9.mjs.map
|