@prisma-next/sql-contract-ts 0.13.0-dev.3 → 0.13.0-dev.31
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/README.md +12 -9
- package/dist/{build-contract-C-x2pfu4.mjs → build-contract-Bu6zubET.mjs} +18 -49
- package/dist/build-contract-Bu6zubET.mjs.map +1 -0
- package/dist/config-types.mjs +1 -1
- package/dist/contract-builder.d.mts +111 -60
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-builder.mjs +43 -9
- package/dist/contract-builder.mjs.map +1 -1
- package/package.json +10 -10
- package/src/build-contract.ts +20 -87
- package/src/contract-builder.ts +47 -31
- package/src/contract-definition.ts +3 -23
- package/src/contract-dsl.ts +41 -17
- package/src/contract-lowering.ts +12 -24
- package/src/contract-types.ts +105 -26
- package/src/contract-warnings.ts +3 -6
- package/src/enum-type.ts +98 -28
- package/src/exports/contract-builder.ts +10 -2
- package/dist/build-contract-C-x2pfu4.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as buildSqlContractFromDefinition } from "./build-contract-
|
|
1
|
+
import { t as buildSqlContractFromDefinition } from "./build-contract-Bu6zubET.mjs";
|
|
2
2
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
4
|
import { isColumnDefault } from "@prisma-next/contract/types";
|
|
5
5
|
import { createEntityHelpersFromNamespace } from "@prisma-next/contract-authoring";
|
|
6
|
-
import {
|
|
6
|
+
import { toStorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
7
7
|
import { assertNoCrossRegistryCollisions, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringTypeConstructorDescriptor, mergeAuthoringNamespaces, validateAuthoringHelperArguments } from "@prisma-next/framework-components/authoring";
|
|
8
8
|
//#region src/authoring-helper-runtime.ts
|
|
9
9
|
function isNamedConstraintOptionsLike(value) {
|
|
@@ -98,8 +98,9 @@ function enumType(name, codec, ...members) {
|
|
|
98
98
|
for (const m of members) {
|
|
99
99
|
if (seenNames.has(m.name)) throw new Error(`enumType("${name}"): duplicate member name "${m.name}". Member names must be unique.`);
|
|
100
100
|
seenNames.add(m.name);
|
|
101
|
-
|
|
102
|
-
seenValues.
|
|
101
|
+
const loweredValue = String(m.value);
|
|
102
|
+
if (seenValues.has(loweredValue)) throw new Error(`enumType("${name}"): duplicate member value "${loweredValue}". Member values must be unique.`);
|
|
103
|
+
seenValues.add(loweredValue);
|
|
103
104
|
}
|
|
104
105
|
const values = Object.freeze(members.map((m) => m.value));
|
|
105
106
|
const names = Object.freeze(members.map((m) => m.name));
|
|
@@ -126,6 +127,15 @@ function enumType(name, codec, ...members) {
|
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
129
|
/**
|
|
130
|
+
* Bind `enumType` to a target's codec typemap. The returned function is the
|
|
131
|
+
* same runtime `enumType`, retyped so member values are constrained to the
|
|
132
|
+
* codec's input type. Target packages call this with their pack's
|
|
133
|
+
* `ExtractCodecTypesFromPack<Pack>` to expose a codec-aware `enumType`.
|
|
134
|
+
*/
|
|
135
|
+
function bindEnumType() {
|
|
136
|
+
return enumType;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
129
139
|
* Returns true when the value is an `EnumTypeHandle` produced by
|
|
130
140
|
* `enumType()`. Used in the lowering pipeline to detect enum handles
|
|
131
141
|
* in field state without importing the BRAND symbol at every call site.
|
|
@@ -211,6 +221,25 @@ var ScalarFieldBuilder = class ScalarFieldBuilder {
|
|
|
211
221
|
return this.state;
|
|
212
222
|
}
|
|
213
223
|
};
|
|
224
|
+
var EnumScalarFieldBuilder = class EnumScalarFieldBuilder extends ScalarFieldBuilder {
|
|
225
|
+
#handle;
|
|
226
|
+
constructor(state, handle) {
|
|
227
|
+
super(state);
|
|
228
|
+
this.#handle = handle;
|
|
229
|
+
}
|
|
230
|
+
default(value) {
|
|
231
|
+
return blindCast(new EnumScalarFieldBuilder({
|
|
232
|
+
...this.build(),
|
|
233
|
+
default: {
|
|
234
|
+
kind: "literal",
|
|
235
|
+
value
|
|
236
|
+
}
|
|
237
|
+
}, this.#handle));
|
|
238
|
+
}
|
|
239
|
+
defaultSql(_expression) {
|
|
240
|
+
throw new Error("defaultSql is not available on an enum field; use .default(members.X) instead");
|
|
241
|
+
}
|
|
242
|
+
};
|
|
214
243
|
function columnField(descriptor) {
|
|
215
244
|
return new ScalarFieldBuilder({
|
|
216
245
|
kind: "scalar",
|
|
@@ -230,11 +259,11 @@ function generatedField(spec) {
|
|
|
230
259
|
});
|
|
231
260
|
}
|
|
232
261
|
function namedTypeField(typeRef) {
|
|
233
|
-
if (isEnumTypeHandle(typeRef)) return new
|
|
262
|
+
if (isEnumTypeHandle(typeRef)) return new EnumScalarFieldBuilder({
|
|
234
263
|
kind: "scalar",
|
|
235
264
|
typeRef,
|
|
236
265
|
nullable: false
|
|
237
|
-
});
|
|
266
|
+
}, typeRef);
|
|
238
267
|
return new ScalarFieldBuilder({
|
|
239
268
|
kind: "scalar",
|
|
240
269
|
typeRef,
|
|
@@ -818,7 +847,7 @@ function resolveFieldDescriptor(modelName, fieldName, fieldState, storageTypes,
|
|
|
818
847
|
const referencedType = storageTypes[typeRef];
|
|
819
848
|
if (!referencedType) throw new Error(`Field "${modelName}.${fieldName}" references unknown storage type "${typeRef}"`);
|
|
820
849
|
return {
|
|
821
|
-
codecId:
|
|
850
|
+
codecId: referencedType.codecId,
|
|
822
851
|
nativeType: referencedType.nativeType,
|
|
823
852
|
typeRef
|
|
824
853
|
};
|
|
@@ -1329,10 +1358,15 @@ function buildBoundContract(family, target, definition, factory) {
|
|
|
1329
1358
|
target,
|
|
1330
1359
|
extensionPacks: definition.extensionPacks
|
|
1331
1360
|
}));
|
|
1361
|
+
const mergedEnums = {
|
|
1362
|
+
...definition.enums ?? {},
|
|
1363
|
+
...built.enums
|
|
1364
|
+
};
|
|
1332
1365
|
return buildContractFromDsl({
|
|
1333
1366
|
...full,
|
|
1334
1367
|
...ifDefined("types", built.types),
|
|
1335
|
-
...ifDefined("models", built.models)
|
|
1368
|
+
...ifDefined("models", built.models),
|
|
1369
|
+
...ifDefined("enums", Object.keys(mergedEnums).length > 0 ? mergedEnums : void 0)
|
|
1336
1370
|
});
|
|
1337
1371
|
}
|
|
1338
1372
|
return buildContractFromDsl(full);
|
|
@@ -1343,6 +1377,6 @@ function defineContract(definition, factory) {
|
|
|
1343
1377
|
return buildBoundContract(definition.family, definition.target, definition);
|
|
1344
1378
|
}
|
|
1345
1379
|
//#endregion
|
|
1346
|
-
export { buildBoundContract, buildSqlContractFromDefinition, defineContract, enumType, extensionModel, field, member, model, rel };
|
|
1380
|
+
export { bindEnumType, buildBoundContract, buildSqlContractFromDefinition, defineContract, enumType, extensionModel, field, member, model, rel };
|
|
1347
1381
|
|
|
1348
1382
|
//# sourceMappingURL=contract-builder.mjs.map
|