@prisma/param-graph-builder 7.3.0-integration-parameterization.7 → 7.3.0-integration-parameterization.9
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/build-param-graph.js +76 -137
- package/dist/build-param-graph.mjs +76 -138
- package/package.json +3 -3
|
@@ -31,11 +31,8 @@ class ParamGraphBuilder {
|
|
|
31
31
|
inputNodes = [];
|
|
32
32
|
outputNodes = [];
|
|
33
33
|
roots = {};
|
|
34
|
-
// Cache for input type nodes to avoid rebuilding
|
|
35
34
|
inputTypeNodeCache = /* @__PURE__ */ new Map();
|
|
36
|
-
// Cache for union nodes keyed by sorted type names
|
|
37
35
|
unionNodeCache = /* @__PURE__ */ new Map();
|
|
38
|
-
// Cache for output type nodes
|
|
39
36
|
outputTypeNodeCache = /* @__PURE__ */ new Map();
|
|
40
37
|
/**
|
|
41
38
|
* Interns a string into the string table, returning its index.
|
|
@@ -143,7 +140,7 @@ class ParamGraphBuilder {
|
|
|
143
140
|
build() {
|
|
144
141
|
return {
|
|
145
142
|
s: this.stringTable,
|
|
146
|
-
|
|
143
|
+
e: this.enumNames,
|
|
147
144
|
i: this.inputNodes,
|
|
148
145
|
o: this.outputNodes,
|
|
149
146
|
r: this.roots
|
|
@@ -159,16 +156,16 @@ function buildParamGraph(dmmf) {
|
|
|
159
156
|
userEnumNames.add(e.name);
|
|
160
157
|
}
|
|
161
158
|
for (const inputType of dmmf.schema.inputObjectTypes.prisma ?? []) {
|
|
162
|
-
inputTypeMap.set(inputType.name, inputType);
|
|
159
|
+
inputTypeMap.set(getTypeName(inputType.name, "prisma"), inputType);
|
|
163
160
|
}
|
|
164
161
|
for (const inputType of dmmf.schema.inputObjectTypes.model ?? []) {
|
|
165
|
-
inputTypeMap.set(inputType.name, inputType);
|
|
162
|
+
inputTypeMap.set(getTypeName(inputType.name, "model"), inputType);
|
|
166
163
|
}
|
|
167
164
|
for (const outputType of dmmf.schema.outputObjectTypes.prisma) {
|
|
168
|
-
outputTypeMap.set(outputType.name, outputType);
|
|
165
|
+
outputTypeMap.set(getTypeName(outputType.name, "prisma"), outputType);
|
|
169
166
|
}
|
|
170
167
|
for (const outputType of dmmf.schema.outputObjectTypes.model) {
|
|
171
|
-
outputTypeMap.set(outputType.name, outputType);
|
|
168
|
+
outputTypeMap.set(getTypeName(outputType.name, "model"), outputType);
|
|
172
169
|
}
|
|
173
170
|
function buildInputNodeFromArgs(args) {
|
|
174
171
|
const fields = {};
|
|
@@ -189,83 +186,7 @@ function buildParamGraph(dmmf) {
|
|
|
189
186
|
return nodeId;
|
|
190
187
|
}
|
|
191
188
|
function buildInputEdge(arg) {
|
|
192
|
-
|
|
193
|
-
let scalarMask = 0;
|
|
194
|
-
let childNodeId;
|
|
195
|
-
let enumNameId;
|
|
196
|
-
const scalarTypes = [];
|
|
197
|
-
const enumTypes = [];
|
|
198
|
-
const inputObjectTypes = [];
|
|
199
|
-
for (const inputType of arg.inputTypes) {
|
|
200
|
-
switch (inputType.location) {
|
|
201
|
-
case "scalar":
|
|
202
|
-
scalarTypes.push(inputType);
|
|
203
|
-
break;
|
|
204
|
-
case "enumTypes":
|
|
205
|
-
enumTypes.push(inputType);
|
|
206
|
-
break;
|
|
207
|
-
case "inputObjectTypes":
|
|
208
|
-
inputObjectTypes.push(inputType);
|
|
209
|
-
break;
|
|
210
|
-
case "fieldRefTypes":
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
for (const st of scalarTypes) {
|
|
215
|
-
scalarMask |= (0, import_param_graph.scalarTypeToMask)(st.type);
|
|
216
|
-
}
|
|
217
|
-
const hasStringScalar = (scalarMask & import_param_graph.ScalarMask.String) !== 0;
|
|
218
|
-
for (const et of enumTypes) {
|
|
219
|
-
const isUserEnum = userEnumNames.has(et.type);
|
|
220
|
-
const isPrismaEnum = et.namespace === "prisma";
|
|
221
|
-
if (isUserEnum) {
|
|
222
|
-
if (!hasStringScalar) {
|
|
223
|
-
enumNameId = builder.registerEnum(et.type);
|
|
224
|
-
}
|
|
225
|
-
scalarMask |= import_param_graph.ScalarMask.String;
|
|
226
|
-
} else if (!isPrismaEnum) {
|
|
227
|
-
scalarMask |= import_param_graph.ScalarMask.String;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const canParamScalar = arg.isParameterizable && scalarMask !== 0;
|
|
231
|
-
if (canParamScalar) {
|
|
232
|
-
const hasScalarList = scalarTypes.some((st) => st.isList) || enumTypes.some((et) => et.isList && (userEnumNames.has(et.type) || et.namespace !== "prisma"));
|
|
233
|
-
if (hasScalarList) {
|
|
234
|
-
flags |= import_param_graph.EdgeFlag.ListScalar;
|
|
235
|
-
} else {
|
|
236
|
-
flags |= import_param_graph.EdgeFlag.ParamScalar;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (inputObjectTypes.length > 0) {
|
|
240
|
-
const hasObjectList = inputObjectTypes.some((iot) => iot.isList);
|
|
241
|
-
if (hasObjectList) {
|
|
242
|
-
flags |= import_param_graph.EdgeFlag.ListObject;
|
|
243
|
-
} else {
|
|
244
|
-
flags |= import_param_graph.EdgeFlag.Object;
|
|
245
|
-
}
|
|
246
|
-
if (inputObjectTypes.length === 1) {
|
|
247
|
-
childNodeId = buildInputTypeNode(inputObjectTypes[0].type);
|
|
248
|
-
} else {
|
|
249
|
-
childNodeId = buildUnionNode(inputObjectTypes.map((iot) => iot.type));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (arg.isNullable) {
|
|
253
|
-
flags |= import_param_graph.EdgeFlag.Nullable;
|
|
254
|
-
}
|
|
255
|
-
if (flags === 0 && childNodeId === void 0) {
|
|
256
|
-
return void 0;
|
|
257
|
-
}
|
|
258
|
-
const edge = { k: flags };
|
|
259
|
-
if (childNodeId !== void 0) {
|
|
260
|
-
edge.c = childNodeId;
|
|
261
|
-
}
|
|
262
|
-
if (scalarMask !== 0 && canParamScalar) {
|
|
263
|
-
edge.m = scalarMask;
|
|
264
|
-
}
|
|
265
|
-
if (enumNameId !== void 0) {
|
|
266
|
-
edge.e = enumNameId;
|
|
267
|
-
}
|
|
268
|
-
return edge;
|
|
189
|
+
return mergeFieldVariants([arg]);
|
|
269
190
|
}
|
|
270
191
|
function buildInputTypeNode(typeName) {
|
|
271
192
|
if (builder.hasInputTypeNode(typeName)) {
|
|
@@ -318,7 +239,7 @@ function buildParamGraph(dmmf) {
|
|
|
318
239
|
const mergedFields = {};
|
|
319
240
|
let hasAnyField = false;
|
|
320
241
|
for (const [fieldName, variantFields] of fieldsByName) {
|
|
321
|
-
const mergedEdge = mergeFieldVariants(variantFields
|
|
242
|
+
const mergedEdge = mergeFieldVariants(variantFields);
|
|
322
243
|
if (mergedEdge) {
|
|
323
244
|
const stringIndex = builder.internString(fieldName);
|
|
324
245
|
mergedFields[stringIndex] = mergedEdge;
|
|
@@ -330,75 +251,87 @@ function buildParamGraph(dmmf) {
|
|
|
330
251
|
}
|
|
331
252
|
return nodeId;
|
|
332
253
|
}
|
|
333
|
-
function mergeFieldVariants(variants
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
let variantMask = 0;
|
|
342
|
-
for (const inputType of variant.inputTypes) {
|
|
343
|
-
if (inputType.location === "scalar") {
|
|
344
|
-
variantMask |= (0, import_param_graph.scalarTypeToMask)(inputType.type);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
masks.push(variantMask);
|
|
348
|
-
combinedMask |= variantMask;
|
|
349
|
-
}
|
|
350
|
-
const allAgreeOnScalars = masks.every((m) => m === masks[0]);
|
|
351
|
-
const allObjectTypes = /* @__PURE__ */ new Set();
|
|
352
|
-
let hasObjectList = false;
|
|
353
|
-
let hasObject = false;
|
|
254
|
+
function mergeFieldVariants(variants) {
|
|
255
|
+
let flags = 0;
|
|
256
|
+
let scalarMask = 0;
|
|
257
|
+
let childNodeId;
|
|
258
|
+
let enumNameId;
|
|
259
|
+
const scalarTypes = [];
|
|
260
|
+
const enumTypes = [];
|
|
261
|
+
const inputObjectTypes = [];
|
|
354
262
|
for (const variant of variants) {
|
|
355
263
|
for (const inputType of variant.inputTypes) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
264
|
+
switch (inputType.location) {
|
|
265
|
+
case "scalar":
|
|
266
|
+
if (variant.isParameterizable) {
|
|
267
|
+
scalarTypes.push(inputType);
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
case "enumTypes":
|
|
271
|
+
if (variant.isParameterizable) {
|
|
272
|
+
enumTypes.push(inputType);
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
275
|
+
case "inputObjectTypes":
|
|
276
|
+
if (!inputObjectTypes.some(
|
|
277
|
+
(ot) => ot.type === inputType.type && ot.namespace === inputType.namespace && ot.isList === inputType.isList
|
|
278
|
+
)) {
|
|
279
|
+
inputObjectTypes.push(inputType);
|
|
280
|
+
}
|
|
281
|
+
break;
|
|
282
|
+
case "fieldRefTypes":
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
inputType.location;
|
|
363
286
|
}
|
|
364
287
|
}
|
|
365
288
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const hasScalarList = variants.some((v) => v.inputTypes.some((it) => it.location === "scalar" && it.isList));
|
|
371
|
-
if (hasScalarList) {
|
|
372
|
-
flags |= import_param_graph.EdgeFlag.ListScalar;
|
|
289
|
+
for (const st of scalarTypes) {
|
|
290
|
+
scalarMask |= (0, import_param_graph.scalarTypeToMask)(st.type);
|
|
291
|
+
if (st.isList) {
|
|
292
|
+
flags |= import_param_graph.EdgeFlag.ParamListScalar;
|
|
373
293
|
} else {
|
|
374
294
|
flags |= import_param_graph.EdgeFlag.ParamScalar;
|
|
375
295
|
}
|
|
376
296
|
}
|
|
377
|
-
|
|
297
|
+
for (const et of enumTypes) {
|
|
298
|
+
if (et.namespace === "model") {
|
|
299
|
+
enumNameId = builder.registerEnum(et.type);
|
|
300
|
+
if (et.isList) {
|
|
301
|
+
flags |= import_param_graph.EdgeFlag.ParamListEnum;
|
|
302
|
+
} else {
|
|
303
|
+
flags |= import_param_graph.EdgeFlag.ParamEnum;
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (inputObjectTypes.length > 0) {
|
|
309
|
+
const hasObjectList = inputObjectTypes.some((iot) => iot.isList);
|
|
310
|
+
const hasSingleObject = inputObjectTypes.some((iot) => !iot.isList);
|
|
378
311
|
if (hasObjectList) {
|
|
379
312
|
flags |= import_param_graph.EdgeFlag.ListObject;
|
|
380
|
-
}
|
|
313
|
+
}
|
|
314
|
+
if (hasSingleObject) {
|
|
381
315
|
flags |= import_param_graph.EdgeFlag.Object;
|
|
382
316
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
childNodeId = buildInputTypeNode(objectTypeArray[0]);
|
|
317
|
+
if (inputObjectTypes.length === 1) {
|
|
318
|
+
childNodeId = buildInputTypeNode(getTypeName(inputObjectTypes[0].type, inputObjectTypes[0].namespace));
|
|
386
319
|
} else {
|
|
387
|
-
childNodeId = buildUnionNode(
|
|
320
|
+
childNodeId = buildUnionNode(inputObjectTypes.map((iot) => getTypeName(iot.type, iot.namespace)));
|
|
388
321
|
}
|
|
389
322
|
}
|
|
390
|
-
if (
|
|
391
|
-
flags |= import_param_graph.EdgeFlag.Nullable;
|
|
392
|
-
}
|
|
393
|
-
if (flags === 0 && childNodeId === void 0) {
|
|
323
|
+
if (flags === 0) {
|
|
394
324
|
return void 0;
|
|
395
325
|
}
|
|
396
326
|
const edge = { k: flags };
|
|
397
327
|
if (childNodeId !== void 0) {
|
|
398
328
|
edge.c = childNodeId;
|
|
399
329
|
}
|
|
400
|
-
if (
|
|
401
|
-
edge.m =
|
|
330
|
+
if (scalarMask !== 0) {
|
|
331
|
+
edge.m = scalarMask;
|
|
332
|
+
}
|
|
333
|
+
if (enumNameId !== void 0) {
|
|
334
|
+
edge.e = enumNameId;
|
|
402
335
|
}
|
|
403
336
|
return edge;
|
|
404
337
|
}
|
|
@@ -436,7 +369,7 @@ function buildParamGraph(dmmf) {
|
|
|
436
369
|
argsNodeId = buildInputNodeFromArgs(field.args);
|
|
437
370
|
}
|
|
438
371
|
if (field.outputType.location === "outputObjectTypes") {
|
|
439
|
-
childOutputNodeId = buildOutputTypeNode(field.outputType.type);
|
|
372
|
+
childOutputNodeId = buildOutputTypeNode(getTypeName(field.outputType.type, field.outputType.namespace));
|
|
440
373
|
}
|
|
441
374
|
if (argsNodeId === void 0 && childOutputNodeId === void 0) {
|
|
442
375
|
return void 0;
|
|
@@ -457,12 +390,12 @@ function buildParamGraph(dmmf) {
|
|
|
457
390
|
const fieldName = mapping[action];
|
|
458
391
|
if (!fieldName) continue;
|
|
459
392
|
let rootField;
|
|
460
|
-
const queryType = outputTypeMap.get("Query");
|
|
393
|
+
const queryType = outputTypeMap.get("prisma.Query");
|
|
461
394
|
if (queryType) {
|
|
462
395
|
rootField = queryType.fields.find((f) => f.name === fieldName);
|
|
463
396
|
}
|
|
464
397
|
if (!rootField) {
|
|
465
|
-
const mutationType = outputTypeMap.get("Mutation");
|
|
398
|
+
const mutationType = outputTypeMap.get("prisma.Mutation");
|
|
466
399
|
if (mutationType) {
|
|
467
400
|
rootField = mutationType.fields.find((f) => f.name === fieldName);
|
|
468
401
|
}
|
|
@@ -471,7 +404,7 @@ function buildParamGraph(dmmf) {
|
|
|
471
404
|
const argsNodeId = buildInputNodeFromArgs(rootField.args);
|
|
472
405
|
let outputNodeId;
|
|
473
406
|
if (rootField.outputType.location === "outputObjectTypes") {
|
|
474
|
-
outputNodeId = buildOutputTypeNode(rootField.outputType.type);
|
|
407
|
+
outputNodeId = buildOutputTypeNode(getTypeName(rootField.outputType.type, rootField.outputType.namespace));
|
|
475
408
|
}
|
|
476
409
|
const dmmfActionToJsonAction = {
|
|
477
410
|
create: "createOne",
|
|
@@ -486,6 +419,12 @@ function buildParamGraph(dmmf) {
|
|
|
486
419
|
}
|
|
487
420
|
return builder.build();
|
|
488
421
|
}
|
|
422
|
+
function getTypeName(name, namespace) {
|
|
423
|
+
if (namespace === void 0) {
|
|
424
|
+
return name;
|
|
425
|
+
}
|
|
426
|
+
return `${namespace}.${name}`;
|
|
427
|
+
}
|
|
489
428
|
// Annotate the CommonJS export names for ESM import in node:
|
|
490
429
|
0 && (module.exports = {
|
|
491
430
|
buildParamGraph
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ModelAction } from "@prisma/dmmf";
|
|
2
2
|
import {
|
|
3
3
|
EdgeFlag,
|
|
4
|
-
ScalarMask,
|
|
5
4
|
scalarTypeToMask
|
|
6
5
|
} from "@prisma/param-graph";
|
|
7
6
|
class ParamGraphBuilder {
|
|
@@ -12,11 +11,8 @@ class ParamGraphBuilder {
|
|
|
12
11
|
inputNodes = [];
|
|
13
12
|
outputNodes = [];
|
|
14
13
|
roots = {};
|
|
15
|
-
// Cache for input type nodes to avoid rebuilding
|
|
16
14
|
inputTypeNodeCache = /* @__PURE__ */ new Map();
|
|
17
|
-
// Cache for union nodes keyed by sorted type names
|
|
18
15
|
unionNodeCache = /* @__PURE__ */ new Map();
|
|
19
|
-
// Cache for output type nodes
|
|
20
16
|
outputTypeNodeCache = /* @__PURE__ */ new Map();
|
|
21
17
|
/**
|
|
22
18
|
* Interns a string into the string table, returning its index.
|
|
@@ -124,7 +120,7 @@ class ParamGraphBuilder {
|
|
|
124
120
|
build() {
|
|
125
121
|
return {
|
|
126
122
|
s: this.stringTable,
|
|
127
|
-
|
|
123
|
+
e: this.enumNames,
|
|
128
124
|
i: this.inputNodes,
|
|
129
125
|
o: this.outputNodes,
|
|
130
126
|
r: this.roots
|
|
@@ -140,16 +136,16 @@ function buildParamGraph(dmmf) {
|
|
|
140
136
|
userEnumNames.add(e.name);
|
|
141
137
|
}
|
|
142
138
|
for (const inputType of dmmf.schema.inputObjectTypes.prisma ?? []) {
|
|
143
|
-
inputTypeMap.set(inputType.name, inputType);
|
|
139
|
+
inputTypeMap.set(getTypeName(inputType.name, "prisma"), inputType);
|
|
144
140
|
}
|
|
145
141
|
for (const inputType of dmmf.schema.inputObjectTypes.model ?? []) {
|
|
146
|
-
inputTypeMap.set(inputType.name, inputType);
|
|
142
|
+
inputTypeMap.set(getTypeName(inputType.name, "model"), inputType);
|
|
147
143
|
}
|
|
148
144
|
for (const outputType of dmmf.schema.outputObjectTypes.prisma) {
|
|
149
|
-
outputTypeMap.set(outputType.name, outputType);
|
|
145
|
+
outputTypeMap.set(getTypeName(outputType.name, "prisma"), outputType);
|
|
150
146
|
}
|
|
151
147
|
for (const outputType of dmmf.schema.outputObjectTypes.model) {
|
|
152
|
-
outputTypeMap.set(outputType.name, outputType);
|
|
148
|
+
outputTypeMap.set(getTypeName(outputType.name, "model"), outputType);
|
|
153
149
|
}
|
|
154
150
|
function buildInputNodeFromArgs(args) {
|
|
155
151
|
const fields = {};
|
|
@@ -170,83 +166,7 @@ function buildParamGraph(dmmf) {
|
|
|
170
166
|
return nodeId;
|
|
171
167
|
}
|
|
172
168
|
function buildInputEdge(arg) {
|
|
173
|
-
|
|
174
|
-
let scalarMask = 0;
|
|
175
|
-
let childNodeId;
|
|
176
|
-
let enumNameId;
|
|
177
|
-
const scalarTypes = [];
|
|
178
|
-
const enumTypes = [];
|
|
179
|
-
const inputObjectTypes = [];
|
|
180
|
-
for (const inputType of arg.inputTypes) {
|
|
181
|
-
switch (inputType.location) {
|
|
182
|
-
case "scalar":
|
|
183
|
-
scalarTypes.push(inputType);
|
|
184
|
-
break;
|
|
185
|
-
case "enumTypes":
|
|
186
|
-
enumTypes.push(inputType);
|
|
187
|
-
break;
|
|
188
|
-
case "inputObjectTypes":
|
|
189
|
-
inputObjectTypes.push(inputType);
|
|
190
|
-
break;
|
|
191
|
-
case "fieldRefTypes":
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
for (const st of scalarTypes) {
|
|
196
|
-
scalarMask |= scalarTypeToMask(st.type);
|
|
197
|
-
}
|
|
198
|
-
const hasStringScalar = (scalarMask & ScalarMask.String) !== 0;
|
|
199
|
-
for (const et of enumTypes) {
|
|
200
|
-
const isUserEnum = userEnumNames.has(et.type);
|
|
201
|
-
const isPrismaEnum = et.namespace === "prisma";
|
|
202
|
-
if (isUserEnum) {
|
|
203
|
-
if (!hasStringScalar) {
|
|
204
|
-
enumNameId = builder.registerEnum(et.type);
|
|
205
|
-
}
|
|
206
|
-
scalarMask |= ScalarMask.String;
|
|
207
|
-
} else if (!isPrismaEnum) {
|
|
208
|
-
scalarMask |= ScalarMask.String;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const canParamScalar = arg.isParameterizable && scalarMask !== 0;
|
|
212
|
-
if (canParamScalar) {
|
|
213
|
-
const hasScalarList = scalarTypes.some((st) => st.isList) || enumTypes.some((et) => et.isList && (userEnumNames.has(et.type) || et.namespace !== "prisma"));
|
|
214
|
-
if (hasScalarList) {
|
|
215
|
-
flags |= EdgeFlag.ListScalar;
|
|
216
|
-
} else {
|
|
217
|
-
flags |= EdgeFlag.ParamScalar;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (inputObjectTypes.length > 0) {
|
|
221
|
-
const hasObjectList = inputObjectTypes.some((iot) => iot.isList);
|
|
222
|
-
if (hasObjectList) {
|
|
223
|
-
flags |= EdgeFlag.ListObject;
|
|
224
|
-
} else {
|
|
225
|
-
flags |= EdgeFlag.Object;
|
|
226
|
-
}
|
|
227
|
-
if (inputObjectTypes.length === 1) {
|
|
228
|
-
childNodeId = buildInputTypeNode(inputObjectTypes[0].type);
|
|
229
|
-
} else {
|
|
230
|
-
childNodeId = buildUnionNode(inputObjectTypes.map((iot) => iot.type));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (arg.isNullable) {
|
|
234
|
-
flags |= EdgeFlag.Nullable;
|
|
235
|
-
}
|
|
236
|
-
if (flags === 0 && childNodeId === void 0) {
|
|
237
|
-
return void 0;
|
|
238
|
-
}
|
|
239
|
-
const edge = { k: flags };
|
|
240
|
-
if (childNodeId !== void 0) {
|
|
241
|
-
edge.c = childNodeId;
|
|
242
|
-
}
|
|
243
|
-
if (scalarMask !== 0 && canParamScalar) {
|
|
244
|
-
edge.m = scalarMask;
|
|
245
|
-
}
|
|
246
|
-
if (enumNameId !== void 0) {
|
|
247
|
-
edge.e = enumNameId;
|
|
248
|
-
}
|
|
249
|
-
return edge;
|
|
169
|
+
return mergeFieldVariants([arg]);
|
|
250
170
|
}
|
|
251
171
|
function buildInputTypeNode(typeName) {
|
|
252
172
|
if (builder.hasInputTypeNode(typeName)) {
|
|
@@ -299,7 +219,7 @@ function buildParamGraph(dmmf) {
|
|
|
299
219
|
const mergedFields = {};
|
|
300
220
|
let hasAnyField = false;
|
|
301
221
|
for (const [fieldName, variantFields] of fieldsByName) {
|
|
302
|
-
const mergedEdge = mergeFieldVariants(variantFields
|
|
222
|
+
const mergedEdge = mergeFieldVariants(variantFields);
|
|
303
223
|
if (mergedEdge) {
|
|
304
224
|
const stringIndex = builder.internString(fieldName);
|
|
305
225
|
mergedFields[stringIndex] = mergedEdge;
|
|
@@ -311,75 +231,87 @@ function buildParamGraph(dmmf) {
|
|
|
311
231
|
}
|
|
312
232
|
return nodeId;
|
|
313
233
|
}
|
|
314
|
-
function mergeFieldVariants(variants
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
let variantMask = 0;
|
|
323
|
-
for (const inputType of variant.inputTypes) {
|
|
324
|
-
if (inputType.location === "scalar") {
|
|
325
|
-
variantMask |= scalarTypeToMask(inputType.type);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
masks.push(variantMask);
|
|
329
|
-
combinedMask |= variantMask;
|
|
330
|
-
}
|
|
331
|
-
const allAgreeOnScalars = masks.every((m) => m === masks[0]);
|
|
332
|
-
const allObjectTypes = /* @__PURE__ */ new Set();
|
|
333
|
-
let hasObjectList = false;
|
|
334
|
-
let hasObject = false;
|
|
234
|
+
function mergeFieldVariants(variants) {
|
|
235
|
+
let flags = 0;
|
|
236
|
+
let scalarMask = 0;
|
|
237
|
+
let childNodeId;
|
|
238
|
+
let enumNameId;
|
|
239
|
+
const scalarTypes = [];
|
|
240
|
+
const enumTypes = [];
|
|
241
|
+
const inputObjectTypes = [];
|
|
335
242
|
for (const variant of variants) {
|
|
336
243
|
for (const inputType of variant.inputTypes) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
244
|
+
switch (inputType.location) {
|
|
245
|
+
case "scalar":
|
|
246
|
+
if (variant.isParameterizable) {
|
|
247
|
+
scalarTypes.push(inputType);
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
case "enumTypes":
|
|
251
|
+
if (variant.isParameterizable) {
|
|
252
|
+
enumTypes.push(inputType);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case "inputObjectTypes":
|
|
256
|
+
if (!inputObjectTypes.some(
|
|
257
|
+
(ot) => ot.type === inputType.type && ot.namespace === inputType.namespace && ot.isList === inputType.isList
|
|
258
|
+
)) {
|
|
259
|
+
inputObjectTypes.push(inputType);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
case "fieldRefTypes":
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
inputType.location;
|
|
344
266
|
}
|
|
345
267
|
}
|
|
346
268
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const hasScalarList = variants.some((v) => v.inputTypes.some((it) => it.location === "scalar" && it.isList));
|
|
352
|
-
if (hasScalarList) {
|
|
353
|
-
flags |= EdgeFlag.ListScalar;
|
|
269
|
+
for (const st of scalarTypes) {
|
|
270
|
+
scalarMask |= scalarTypeToMask(st.type);
|
|
271
|
+
if (st.isList) {
|
|
272
|
+
flags |= EdgeFlag.ParamListScalar;
|
|
354
273
|
} else {
|
|
355
274
|
flags |= EdgeFlag.ParamScalar;
|
|
356
275
|
}
|
|
357
276
|
}
|
|
358
|
-
|
|
277
|
+
for (const et of enumTypes) {
|
|
278
|
+
if (et.namespace === "model") {
|
|
279
|
+
enumNameId = builder.registerEnum(et.type);
|
|
280
|
+
if (et.isList) {
|
|
281
|
+
flags |= EdgeFlag.ParamListEnum;
|
|
282
|
+
} else {
|
|
283
|
+
flags |= EdgeFlag.ParamEnum;
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (inputObjectTypes.length > 0) {
|
|
289
|
+
const hasObjectList = inputObjectTypes.some((iot) => iot.isList);
|
|
290
|
+
const hasSingleObject = inputObjectTypes.some((iot) => !iot.isList);
|
|
359
291
|
if (hasObjectList) {
|
|
360
292
|
flags |= EdgeFlag.ListObject;
|
|
361
|
-
}
|
|
293
|
+
}
|
|
294
|
+
if (hasSingleObject) {
|
|
362
295
|
flags |= EdgeFlag.Object;
|
|
363
296
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
childNodeId = buildInputTypeNode(objectTypeArray[0]);
|
|
297
|
+
if (inputObjectTypes.length === 1) {
|
|
298
|
+
childNodeId = buildInputTypeNode(getTypeName(inputObjectTypes[0].type, inputObjectTypes[0].namespace));
|
|
367
299
|
} else {
|
|
368
|
-
childNodeId = buildUnionNode(
|
|
300
|
+
childNodeId = buildUnionNode(inputObjectTypes.map((iot) => getTypeName(iot.type, iot.namespace)));
|
|
369
301
|
}
|
|
370
302
|
}
|
|
371
|
-
if (
|
|
372
|
-
flags |= EdgeFlag.Nullable;
|
|
373
|
-
}
|
|
374
|
-
if (flags === 0 && childNodeId === void 0) {
|
|
303
|
+
if (flags === 0) {
|
|
375
304
|
return void 0;
|
|
376
305
|
}
|
|
377
306
|
const edge = { k: flags };
|
|
378
307
|
if (childNodeId !== void 0) {
|
|
379
308
|
edge.c = childNodeId;
|
|
380
309
|
}
|
|
381
|
-
if (
|
|
382
|
-
edge.m =
|
|
310
|
+
if (scalarMask !== 0) {
|
|
311
|
+
edge.m = scalarMask;
|
|
312
|
+
}
|
|
313
|
+
if (enumNameId !== void 0) {
|
|
314
|
+
edge.e = enumNameId;
|
|
383
315
|
}
|
|
384
316
|
return edge;
|
|
385
317
|
}
|
|
@@ -417,7 +349,7 @@ function buildParamGraph(dmmf) {
|
|
|
417
349
|
argsNodeId = buildInputNodeFromArgs(field.args);
|
|
418
350
|
}
|
|
419
351
|
if (field.outputType.location === "outputObjectTypes") {
|
|
420
|
-
childOutputNodeId = buildOutputTypeNode(field.outputType.type);
|
|
352
|
+
childOutputNodeId = buildOutputTypeNode(getTypeName(field.outputType.type, field.outputType.namespace));
|
|
421
353
|
}
|
|
422
354
|
if (argsNodeId === void 0 && childOutputNodeId === void 0) {
|
|
423
355
|
return void 0;
|
|
@@ -438,12 +370,12 @@ function buildParamGraph(dmmf) {
|
|
|
438
370
|
const fieldName = mapping[action];
|
|
439
371
|
if (!fieldName) continue;
|
|
440
372
|
let rootField;
|
|
441
|
-
const queryType = outputTypeMap.get("Query");
|
|
373
|
+
const queryType = outputTypeMap.get("prisma.Query");
|
|
442
374
|
if (queryType) {
|
|
443
375
|
rootField = queryType.fields.find((f) => f.name === fieldName);
|
|
444
376
|
}
|
|
445
377
|
if (!rootField) {
|
|
446
|
-
const mutationType = outputTypeMap.get("Mutation");
|
|
378
|
+
const mutationType = outputTypeMap.get("prisma.Mutation");
|
|
447
379
|
if (mutationType) {
|
|
448
380
|
rootField = mutationType.fields.find((f) => f.name === fieldName);
|
|
449
381
|
}
|
|
@@ -452,7 +384,7 @@ function buildParamGraph(dmmf) {
|
|
|
452
384
|
const argsNodeId = buildInputNodeFromArgs(rootField.args);
|
|
453
385
|
let outputNodeId;
|
|
454
386
|
if (rootField.outputType.location === "outputObjectTypes") {
|
|
455
|
-
outputNodeId = buildOutputTypeNode(rootField.outputType.type);
|
|
387
|
+
outputNodeId = buildOutputTypeNode(getTypeName(rootField.outputType.type, rootField.outputType.namespace));
|
|
456
388
|
}
|
|
457
389
|
const dmmfActionToJsonAction = {
|
|
458
390
|
create: "createOne",
|
|
@@ -467,6 +399,12 @@ function buildParamGraph(dmmf) {
|
|
|
467
399
|
}
|
|
468
400
|
return builder.build();
|
|
469
401
|
}
|
|
402
|
+
function getTypeName(name, namespace) {
|
|
403
|
+
if (namespace === void 0) {
|
|
404
|
+
return name;
|
|
405
|
+
}
|
|
406
|
+
return `${namespace}.${name}`;
|
|
407
|
+
}
|
|
470
408
|
export {
|
|
471
409
|
buildParamGraph
|
|
472
410
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/param-graph-builder",
|
|
3
|
-
"version": "7.3.0-integration-parameterization.
|
|
3
|
+
"version": "7.3.0-integration-parameterization.9",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@prisma/
|
|
28
|
-
"@prisma/
|
|
27
|
+
"@prisma/param-graph": "7.3.0-integration-parameterization.9",
|
|
28
|
+
"@prisma/dmmf": "7.3.0-integration-parameterization.9"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist"
|