@prisma-next/sql-contract-psl 0.3.0-dev.147 → 0.3.0-dev.162
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 +5 -5
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{interpreter-qjtea3zY.mjs → interpreter-iFCRN9nb.mjs} +712 -195
- package/dist/interpreter-iFCRN9nb.mjs.map +1 -0
- package/dist/provider.mjs +1 -1
- package/package.json +9 -9
- package/src/interpreter.ts +259 -149
- package/src/psl-authoring-arguments.ts +454 -0
- package/src/psl-column-resolution.ts +233 -37
- package/src/psl-field-resolution.ts +162 -139
- package/src/psl-relation-resolution.ts +13 -4
- package/dist/interpreter-qjtea3zY.mjs.map +0 -1
package/src/interpreter.ts
CHANGED
|
@@ -23,7 +23,6 @@ import type {
|
|
|
23
23
|
PslField,
|
|
24
24
|
PslModel,
|
|
25
25
|
PslNamedTypeDeclaration,
|
|
26
|
-
PslSpan,
|
|
27
26
|
} from '@prisma-next/psl-parser';
|
|
28
27
|
import type { StorageTypeInstance } from '@prisma-next/sql-contract/types';
|
|
29
28
|
import {
|
|
@@ -51,10 +50,13 @@ import {
|
|
|
51
50
|
} from './psl-attribute-parsing';
|
|
52
51
|
import type { ColumnDescriptor } from './psl-column-resolution';
|
|
53
52
|
import {
|
|
53
|
+
checkUncomposedNamespace,
|
|
54
54
|
getAuthoringTypeConstructor,
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
instantiatePslTypeConstructor,
|
|
56
|
+
reportUncomposedNamespace,
|
|
57
57
|
resolveDbNativeTypeAttribute,
|
|
58
|
+
resolveFieldTypeDescriptor,
|
|
59
|
+
resolvePslTypeConstructorDescriptor,
|
|
58
60
|
toNamedTypeFieldDescriptor,
|
|
59
61
|
} from './psl-column-resolution';
|
|
60
62
|
import {
|
|
@@ -109,13 +111,25 @@ function buildComposedExtensionPackRefs(
|
|
|
109
111
|
);
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
function diagnosticDedupKey(diagnostic: ContractSourceDiagnostic): string {
|
|
115
|
+
const span = diagnostic.span;
|
|
116
|
+
const spanKey = span
|
|
117
|
+
? `${span.start.offset}:${span.end.offset}:${span.start.line}:${span.end.line}`
|
|
118
|
+
: '';
|
|
119
|
+
return `${diagnostic.code}\u0000${diagnostic.sourceId}\u0000${spanKey}\u0000${diagnostic.message}`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function dedupeDiagnostics(
|
|
123
|
+
diagnostics: readonly ContractSourceDiagnostic[],
|
|
124
|
+
): ContractSourceDiagnostic[] {
|
|
125
|
+
const seen = new Map<string, ContractSourceDiagnostic>();
|
|
126
|
+
for (const diagnostic of diagnostics) {
|
|
127
|
+
const key = diagnosticDedupKey(diagnostic);
|
|
128
|
+
if (!seen.has(key)) {
|
|
129
|
+
seen.set(key, diagnostic);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return [...seen.values()];
|
|
119
133
|
}
|
|
120
134
|
|
|
121
135
|
function compareStrings(left: string, right: string): -1 | 0 | 1 {
|
|
@@ -194,112 +208,178 @@ interface ResolveNamedTypeDeclarationsInput {
|
|
|
194
208
|
readonly enumTypeDescriptors: ReadonlyMap<string, ColumnDescriptor>;
|
|
195
209
|
readonly scalarTypeDescriptors: ReadonlyMap<string, ColumnDescriptor>;
|
|
196
210
|
readonly composedExtensions: ReadonlySet<string>;
|
|
197
|
-
readonly
|
|
211
|
+
readonly familyId: string;
|
|
212
|
+
readonly targetId: string;
|
|
213
|
+
readonly authoringContributions: AuthoringContributions | undefined;
|
|
198
214
|
readonly diagnostics: ContractSourceDiagnostic[];
|
|
199
215
|
}
|
|
200
216
|
|
|
201
|
-
function
|
|
202
|
-
readonly
|
|
203
|
-
readonly
|
|
204
|
-
readonly
|
|
217
|
+
function validateNamedTypeAttributes(input: {
|
|
218
|
+
readonly declaration: PslNamedTypeDeclaration;
|
|
219
|
+
readonly sourceId: string;
|
|
220
|
+
readonly diagnostics: ContractSourceDiagnostic[];
|
|
221
|
+
readonly composedExtensions: ReadonlySet<string>;
|
|
222
|
+
readonly allowDbNativeType: boolean;
|
|
223
|
+
readonly familyId: string;
|
|
224
|
+
readonly targetId: string;
|
|
225
|
+
}): {
|
|
226
|
+
readonly dbNativeTypeAttribute: PslAttribute | undefined;
|
|
227
|
+
readonly hasUnsupportedNamedTypeAttribute: boolean;
|
|
205
228
|
} {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
229
|
+
const dbNativeTypeAttributes = input.allowDbNativeType
|
|
230
|
+
? input.declaration.attributes.filter((attribute) => attribute.name.startsWith('db.'))
|
|
231
|
+
: [];
|
|
232
|
+
const [dbNativeTypeAttribute, ...extraDbNativeTypeAttributes] = dbNativeTypeAttributes;
|
|
233
|
+
let hasUnsupportedNamedTypeAttribute = false;
|
|
234
|
+
|
|
235
|
+
for (const extra of extraDbNativeTypeAttributes) {
|
|
236
|
+
input.diagnostics.push({
|
|
237
|
+
code: 'PSL_INVALID_ATTRIBUTE_ARGUMENT',
|
|
238
|
+
message: `Named type "${input.declaration.name}" can declare at most one @db.* attribute`,
|
|
239
|
+
sourceId: input.sourceId,
|
|
240
|
+
span: extra.span,
|
|
241
|
+
});
|
|
242
|
+
hasUnsupportedNamedTypeAttribute = true;
|
|
243
|
+
}
|
|
209
244
|
|
|
210
|
-
for (const
|
|
211
|
-
|
|
212
|
-
input.enumTypeDescriptors.get(declaration.baseType) ??
|
|
213
|
-
input.scalarTypeDescriptors.get(declaration.baseType);
|
|
214
|
-
if (!baseDescriptor) {
|
|
215
|
-
input.diagnostics.push({
|
|
216
|
-
code: 'PSL_UNSUPPORTED_NAMED_TYPE_BASE',
|
|
217
|
-
message: `Named type "${declaration.name}" references unsupported base type "${declaration.baseType}"`,
|
|
218
|
-
sourceId: input.sourceId,
|
|
219
|
-
span: declaration.span,
|
|
220
|
-
});
|
|
245
|
+
for (const attribute of input.declaration.attributes) {
|
|
246
|
+
if (input.allowDbNativeType && attribute.name.startsWith('db.')) {
|
|
221
247
|
continue;
|
|
222
248
|
}
|
|
223
|
-
namedTypeBaseTypes.set(declaration.name, declaration.baseType);
|
|
224
249
|
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
input.diagnostics.push({
|
|
234
|
-
code: 'PSL_UNSUPPORTED_NAMED_TYPE_ATTRIBUTE',
|
|
235
|
-
message: `Named type "${declaration.name}" uses unsupported attribute "${unsupportedNamedTypeAttribute.name}"`,
|
|
250
|
+
const uncomposedNamespace = checkUncomposedNamespace(attribute.name, input.composedExtensions, {
|
|
251
|
+
familyId: input.familyId,
|
|
252
|
+
targetId: input.targetId,
|
|
253
|
+
});
|
|
254
|
+
if (uncomposedNamespace) {
|
|
255
|
+
reportUncomposedNamespace({
|
|
256
|
+
subjectLabel: `Attribute "@${attribute.name}"`,
|
|
257
|
+
namespace: uncomposedNamespace,
|
|
236
258
|
sourceId: input.sourceId,
|
|
237
|
-
span:
|
|
259
|
+
span: attribute.span,
|
|
260
|
+
diagnostics: input.diagnostics,
|
|
238
261
|
});
|
|
262
|
+
hasUnsupportedNamedTypeAttribute = true;
|
|
239
263
|
continue;
|
|
240
264
|
}
|
|
241
265
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
266
|
+
input.diagnostics.push({
|
|
267
|
+
code: 'PSL_UNSUPPORTED_NAMED_TYPE_ATTRIBUTE',
|
|
268
|
+
message: `Named type "${input.declaration.name}" uses unsupported attribute "${attribute.name}"`,
|
|
269
|
+
sourceId: input.sourceId,
|
|
270
|
+
span: attribute.span,
|
|
271
|
+
});
|
|
272
|
+
hasUnsupportedNamedTypeAttribute = true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return { dbNativeTypeAttribute, hasUnsupportedNamedTypeAttribute };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function resolveNamedTypeDeclarations(input: ResolveNamedTypeDeclarationsInput): {
|
|
279
|
+
readonly storageTypes: Record<string, StorageTypeInstance>;
|
|
280
|
+
readonly namedTypeDescriptors: Map<string, ColumnDescriptor>;
|
|
281
|
+
} {
|
|
282
|
+
const storageTypes: Record<string, StorageTypeInstance> = {};
|
|
283
|
+
const namedTypeDescriptors = new Map<string, ColumnDescriptor>();
|
|
284
|
+
|
|
285
|
+
for (const declaration of input.declarations) {
|
|
286
|
+
if (declaration.typeConstructor) {
|
|
287
|
+
const { hasUnsupportedNamedTypeAttribute } = validateNamedTypeAttributes({
|
|
288
|
+
declaration,
|
|
246
289
|
sourceId: input.sourceId,
|
|
247
|
-
|
|
290
|
+
diagnostics: input.diagnostics,
|
|
291
|
+
composedExtensions: input.composedExtensions,
|
|
292
|
+
allowDbNativeType: false,
|
|
293
|
+
familyId: input.familyId,
|
|
294
|
+
targetId: input.targetId,
|
|
248
295
|
});
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (pgvectorAttribute) {
|
|
253
|
-
if (!input.composedExtensions.has('pgvector')) {
|
|
254
|
-
input.diagnostics.push({
|
|
255
|
-
code: 'PSL_EXTENSION_NAMESPACE_NOT_COMPOSED',
|
|
256
|
-
message:
|
|
257
|
-
'Attribute "@pgvector.column" uses unrecognized namespace "pgvector". Add extension pack "pgvector" to extensionPacks in prisma-next.config.ts.',
|
|
258
|
-
sourceId: input.sourceId,
|
|
259
|
-
span: pgvectorAttribute.span,
|
|
260
|
-
});
|
|
296
|
+
if (hasUnsupportedNamedTypeAttribute) {
|
|
261
297
|
continue;
|
|
262
298
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
299
|
+
|
|
300
|
+
const helperPath = declaration.typeConstructor.path.join('.');
|
|
301
|
+
const typeConstructor = resolvePslTypeConstructorDescriptor({
|
|
302
|
+
call: declaration.typeConstructor,
|
|
303
|
+
authoringContributions: input.authoringContributions,
|
|
304
|
+
composedExtensions: input.composedExtensions,
|
|
305
|
+
familyId: input.familyId,
|
|
306
|
+
targetId: input.targetId,
|
|
307
|
+
diagnostics: input.diagnostics,
|
|
308
|
+
sourceId: input.sourceId,
|
|
309
|
+
unsupportedCode: 'PSL_UNSUPPORTED_NAMED_TYPE_CONSTRUCTOR',
|
|
310
|
+
unsupportedMessage: `Named type "${declaration.name}" references unsupported constructor "${helperPath}"`,
|
|
311
|
+
});
|
|
312
|
+
if (!typeConstructor) {
|
|
270
313
|
continue;
|
|
271
314
|
}
|
|
272
|
-
|
|
273
|
-
|
|
315
|
+
|
|
316
|
+
const storageType = instantiatePslTypeConstructor({
|
|
317
|
+
call: declaration.typeConstructor,
|
|
318
|
+
descriptor: typeConstructor,
|
|
274
319
|
diagnostics: input.diagnostics,
|
|
275
320
|
sourceId: input.sourceId,
|
|
321
|
+
entityLabel: `Named type "${declaration.name}"`,
|
|
276
322
|
});
|
|
277
|
-
if (
|
|
323
|
+
if (!storageType) {
|
|
278
324
|
continue;
|
|
279
325
|
}
|
|
280
|
-
|
|
281
|
-
? instantiateAuthoringTypeConstructor(input.pgvectorVectorConstructor, [length])
|
|
282
|
-
: {
|
|
283
|
-
codecId: 'pg/vector@1',
|
|
284
|
-
nativeType: 'vector',
|
|
285
|
-
typeParams: { length },
|
|
286
|
-
};
|
|
326
|
+
|
|
287
327
|
namedTypeDescriptors.set(
|
|
288
328
|
declaration.name,
|
|
289
|
-
toNamedTypeFieldDescriptor(declaration.name,
|
|
329
|
+
toNamedTypeFieldDescriptor(declaration.name, storageType),
|
|
290
330
|
);
|
|
291
331
|
storageTypes[declaration.name] = {
|
|
292
|
-
codecId:
|
|
293
|
-
nativeType:
|
|
294
|
-
typeParams:
|
|
332
|
+
codecId: storageType.codecId,
|
|
333
|
+
nativeType: storageType.nativeType,
|
|
334
|
+
typeParams: storageType.typeParams ?? {},
|
|
295
335
|
};
|
|
296
336
|
continue;
|
|
297
337
|
}
|
|
298
338
|
|
|
339
|
+
// Parser invariant: when typeConstructor is absent, baseType is defined.
|
|
340
|
+
// The check below narrows `baseType` for TypeScript and guards against a
|
|
341
|
+
// parser regression; it is unreachable under a correct parser.
|
|
342
|
+
if (declaration.baseType === undefined) {
|
|
343
|
+
input.diagnostics.push({
|
|
344
|
+
code: 'PSL_UNSUPPORTED_NAMED_TYPE_BASE',
|
|
345
|
+
message: `Named type "${declaration.name}" must declare a base type or constructor`,
|
|
346
|
+
sourceId: input.sourceId,
|
|
347
|
+
span: declaration.span,
|
|
348
|
+
});
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const { baseType } = declaration;
|
|
352
|
+
const baseDescriptor =
|
|
353
|
+
input.enumTypeDescriptors.get(baseType) ?? input.scalarTypeDescriptors.get(baseType);
|
|
354
|
+
if (!baseDescriptor) {
|
|
355
|
+
input.diagnostics.push({
|
|
356
|
+
code: 'PSL_UNSUPPORTED_NAMED_TYPE_BASE',
|
|
357
|
+
message: `Named type "${declaration.name}" references unsupported base type "${baseType}"`,
|
|
358
|
+
sourceId: input.sourceId,
|
|
359
|
+
span: declaration.span,
|
|
360
|
+
});
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const { dbNativeTypeAttribute, hasUnsupportedNamedTypeAttribute } = validateNamedTypeAttributes(
|
|
365
|
+
{
|
|
366
|
+
declaration,
|
|
367
|
+
sourceId: input.sourceId,
|
|
368
|
+
diagnostics: input.diagnostics,
|
|
369
|
+
composedExtensions: input.composedExtensions,
|
|
370
|
+
allowDbNativeType: true,
|
|
371
|
+
familyId: input.familyId,
|
|
372
|
+
targetId: input.targetId,
|
|
373
|
+
},
|
|
374
|
+
);
|
|
375
|
+
if (hasUnsupportedNamedTypeAttribute) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
|
|
299
379
|
if (dbNativeTypeAttribute) {
|
|
300
380
|
const descriptor = resolveDbNativeTypeAttribute({
|
|
301
381
|
attribute: dbNativeTypeAttribute,
|
|
302
|
-
baseType
|
|
382
|
+
baseType,
|
|
303
383
|
baseDescriptor,
|
|
304
384
|
diagnostics: input.diagnostics,
|
|
305
385
|
sourceId: input.sourceId,
|
|
@@ -329,7 +409,7 @@ function resolveNamedTypeDeclarations(input: ResolveNamedTypeDeclarationsInput):
|
|
|
329
409
|
};
|
|
330
410
|
}
|
|
331
411
|
|
|
332
|
-
return { storageTypes, namedTypeDescriptors
|
|
412
|
+
return { storageTypes, namedTypeDescriptors };
|
|
333
413
|
}
|
|
334
414
|
|
|
335
415
|
interface BuildModelNodeInput {
|
|
@@ -340,8 +420,9 @@ interface BuildModelNodeInput {
|
|
|
340
420
|
readonly compositeTypeNames: ReadonlySet<string>;
|
|
341
421
|
readonly enumTypeDescriptors: Map<string, ColumnDescriptor>;
|
|
342
422
|
readonly namedTypeDescriptors: Map<string, ColumnDescriptor>;
|
|
343
|
-
readonly namedTypeBaseTypes: Map<string, string>;
|
|
344
423
|
readonly composedExtensions: Set<string>;
|
|
424
|
+
readonly familyId: string;
|
|
425
|
+
readonly targetId: string;
|
|
345
426
|
readonly authoringContributions: AuthoringContributions | undefined;
|
|
346
427
|
readonly defaultFunctionRegistry: ControlMutationDefaultRegistry;
|
|
347
428
|
readonly generatorDescriptorById: ReadonlyMap<string, MutationDefaultGeneratorDescriptor>;
|
|
@@ -361,22 +442,23 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
|
|
|
361
442
|
const { model, mapping, sourceId, diagnostics } = input;
|
|
362
443
|
const tableName = mapping.tableName;
|
|
363
444
|
|
|
364
|
-
const resolvedFields = collectResolvedFields(
|
|
445
|
+
const resolvedFields = collectResolvedFields({
|
|
365
446
|
model,
|
|
366
447
|
mapping,
|
|
367
|
-
input.enumTypeDescriptors,
|
|
368
|
-
input.namedTypeDescriptors,
|
|
369
|
-
input.
|
|
370
|
-
input.
|
|
371
|
-
input.
|
|
372
|
-
input.
|
|
373
|
-
input.
|
|
374
|
-
input.
|
|
375
|
-
input.
|
|
448
|
+
enumTypeDescriptors: input.enumTypeDescriptors,
|
|
449
|
+
namedTypeDescriptors: input.namedTypeDescriptors,
|
|
450
|
+
modelNames: input.modelNames,
|
|
451
|
+
compositeTypeNames: input.compositeTypeNames,
|
|
452
|
+
composedExtensions: input.composedExtensions,
|
|
453
|
+
authoringContributions: input.authoringContributions,
|
|
454
|
+
familyId: input.familyId,
|
|
455
|
+
targetId: input.targetId,
|
|
456
|
+
defaultFunctionRegistry: input.defaultFunctionRegistry,
|
|
457
|
+
generatorDescriptorById: input.generatorDescriptorById,
|
|
376
458
|
diagnostics,
|
|
377
459
|
sourceId,
|
|
378
|
-
input.scalarTypeDescriptors,
|
|
379
|
-
);
|
|
460
|
+
scalarTypeDescriptors: input.scalarTypeDescriptors,
|
|
461
|
+
});
|
|
380
462
|
|
|
381
463
|
const primaryKeyFields = resolvedFields.filter((field) => field.isId);
|
|
382
464
|
const primaryKeyColumns = primaryKeyFields.map((field) => field.columnName);
|
|
@@ -402,6 +484,8 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
|
|
|
402
484
|
sourceId,
|
|
403
485
|
composedExtensions: input.composedExtensions,
|
|
404
486
|
diagnostics,
|
|
487
|
+
familyId: input.familyId,
|
|
488
|
+
targetId: input.targetId,
|
|
405
489
|
});
|
|
406
490
|
const relationAttribute = getAttribute(field.attributes, 'relation');
|
|
407
491
|
let relationName: string | undefined;
|
|
@@ -517,12 +601,18 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
|
|
|
517
601
|
}
|
|
518
602
|
continue;
|
|
519
603
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
604
|
+
const uncomposedNamespace = checkUncomposedNamespace(
|
|
605
|
+
modelAttribute.name,
|
|
606
|
+
input.composedExtensions,
|
|
607
|
+
{ familyId: input.familyId, targetId: input.targetId },
|
|
608
|
+
);
|
|
609
|
+
if (uncomposedNamespace) {
|
|
610
|
+
reportUncomposedNamespace({
|
|
611
|
+
subjectLabel: `Attribute "@@${modelAttribute.name}"`,
|
|
612
|
+
namespace: uncomposedNamespace,
|
|
524
613
|
sourceId,
|
|
525
614
|
span: modelAttribute.span,
|
|
615
|
+
diagnostics,
|
|
526
616
|
});
|
|
527
617
|
continue;
|
|
528
618
|
}
|
|
@@ -692,14 +782,32 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
|
|
|
692
782
|
};
|
|
693
783
|
}
|
|
694
784
|
|
|
695
|
-
|
|
696
|
-
compositeTypes: readonly PslCompositeType[]
|
|
697
|
-
enumTypeDescriptors: ReadonlyMap<string, ColumnDescriptor
|
|
698
|
-
namedTypeDescriptors: ReadonlyMap<string, ColumnDescriptor
|
|
699
|
-
scalarTypeDescriptors: ReadonlyMap<string, ColumnDescriptor
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
785
|
+
interface BuildValueObjectsInput {
|
|
786
|
+
readonly compositeTypes: readonly PslCompositeType[];
|
|
787
|
+
readonly enumTypeDescriptors: ReadonlyMap<string, ColumnDescriptor>;
|
|
788
|
+
readonly namedTypeDescriptors: ReadonlyMap<string, ColumnDescriptor>;
|
|
789
|
+
readonly scalarTypeDescriptors: ReadonlyMap<string, ColumnDescriptor>;
|
|
790
|
+
readonly composedExtensions: ReadonlySet<string>;
|
|
791
|
+
readonly familyId: string;
|
|
792
|
+
readonly targetId: string;
|
|
793
|
+
readonly authoringContributions: AuthoringContributions | undefined;
|
|
794
|
+
readonly diagnostics: ContractSourceDiagnostic[];
|
|
795
|
+
readonly sourceId: string;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function buildValueObjects(input: BuildValueObjectsInput): Record<string, ContractValueObject> {
|
|
799
|
+
const {
|
|
800
|
+
compositeTypes,
|
|
801
|
+
enumTypeDescriptors,
|
|
802
|
+
namedTypeDescriptors,
|
|
803
|
+
scalarTypeDescriptors,
|
|
804
|
+
composedExtensions,
|
|
805
|
+
familyId,
|
|
806
|
+
targetId,
|
|
807
|
+
authoringContributions,
|
|
808
|
+
diagnostics,
|
|
809
|
+
sourceId,
|
|
810
|
+
} = input;
|
|
703
811
|
const valueObjects: Record<string, ContractValueObject> = {};
|
|
704
812
|
const compositeTypeNames = new Set(compositeTypes.map((ct) => ct.name));
|
|
705
813
|
|
|
@@ -714,25 +822,35 @@ function buildValueObjects(
|
|
|
714
822
|
fields[field.name] = field.list ? { ...result, many: true } : result;
|
|
715
823
|
continue;
|
|
716
824
|
}
|
|
717
|
-
const
|
|
825
|
+
const resolved = resolveFieldTypeDescriptor({
|
|
718
826
|
field,
|
|
719
|
-
enumTypeDescriptors
|
|
720
|
-
namedTypeDescriptors
|
|
827
|
+
enumTypeDescriptors,
|
|
828
|
+
namedTypeDescriptors,
|
|
721
829
|
scalarTypeDescriptors,
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
830
|
+
authoringContributions,
|
|
831
|
+
composedExtensions,
|
|
832
|
+
familyId,
|
|
833
|
+
targetId,
|
|
834
|
+
diagnostics,
|
|
835
|
+
sourceId,
|
|
836
|
+
entityLabel: `Field "${compositeType.name}.${field.name}"`,
|
|
837
|
+
});
|
|
838
|
+
if (!resolved.ok) {
|
|
839
|
+
if (!resolved.alreadyReported) {
|
|
840
|
+
diagnostics.push({
|
|
841
|
+
code: 'PSL_UNSUPPORTED_FIELD_TYPE',
|
|
842
|
+
message: `Field "${compositeType.name}.${field.name}" type "${field.typeName}" is not supported`,
|
|
843
|
+
sourceId,
|
|
844
|
+
span: field.span,
|
|
845
|
+
});
|
|
846
|
+
}
|
|
730
847
|
continue;
|
|
731
848
|
}
|
|
732
|
-
|
|
849
|
+
const scalarField: ContractField = {
|
|
733
850
|
nullable: field.optional,
|
|
734
|
-
type: { kind: 'scalar', codecId: descriptor.codecId },
|
|
851
|
+
type: { kind: 'scalar', codecId: resolved.descriptor.codecId },
|
|
735
852
|
};
|
|
853
|
+
fields[field.name] = field.list ? { ...scalarField, many: true } : scalarField;
|
|
736
854
|
}
|
|
737
855
|
valueObjects[compositeType.name] = { fields };
|
|
738
856
|
}
|
|
@@ -1011,8 +1129,8 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1011
1129
|
const modelNames = new Set(models.map((model) => model.name));
|
|
1012
1130
|
const compositeTypeNames = new Set(compositeTypes.map((ct) => ct.name));
|
|
1013
1131
|
const composedExtensions = new Set(input.composedExtensionPacks ?? []);
|
|
1014
|
-
const defaultFunctionRegistry =
|
|
1015
|
-
input.controlMutationDefaults?.defaultFunctionRegistry ?? new Map
|
|
1132
|
+
const defaultFunctionRegistry: ControlMutationDefaultRegistry =
|
|
1133
|
+
input.controlMutationDefaults?.defaultFunctionRegistry ?? new Map();
|
|
1016
1134
|
const generatorDescriptors = input.controlMutationDefaults?.generatorDescriptors ?? [];
|
|
1017
1135
|
const generatorDescriptorById = new Map<string, MutationDefaultGeneratorDescriptor>();
|
|
1018
1136
|
for (const descriptor of generatorDescriptors) {
|
|
@@ -1032,10 +1150,9 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1032
1150
|
enumTypeDescriptors: enumResult.enumTypeDescriptors,
|
|
1033
1151
|
scalarTypeDescriptors: input.scalarTypeDescriptors,
|
|
1034
1152
|
composedExtensions,
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
]),
|
|
1153
|
+
familyId: input.target.familyId,
|
|
1154
|
+
targetId: input.target.targetId,
|
|
1155
|
+
authoringContributions: input.authoringContributions,
|
|
1039
1156
|
diagnostics,
|
|
1040
1157
|
});
|
|
1041
1158
|
|
|
@@ -1060,8 +1177,9 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1060
1177
|
compositeTypeNames,
|
|
1061
1178
|
enumTypeDescriptors: enumResult.enumTypeDescriptors,
|
|
1062
1179
|
namedTypeDescriptors: namedTypeResult.namedTypeDescriptors,
|
|
1063
|
-
namedTypeBaseTypes: namedTypeResult.namedTypeBaseTypes,
|
|
1064
1180
|
composedExtensions,
|
|
1181
|
+
familyId: input.target.familyId,
|
|
1182
|
+
targetId: input.target.targetId,
|
|
1065
1183
|
authoringContributions: input.authoringContributions,
|
|
1066
1184
|
defaultFunctionRegistry,
|
|
1067
1185
|
generatorDescriptorById,
|
|
@@ -1090,22 +1208,23 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1090
1208
|
diagnostics,
|
|
1091
1209
|
);
|
|
1092
1210
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1211
|
+
const valueObjects = buildValueObjects({
|
|
1212
|
+
compositeTypes,
|
|
1213
|
+
enumTypeDescriptors: enumResult.enumTypeDescriptors,
|
|
1214
|
+
namedTypeDescriptors: namedTypeResult.namedTypeDescriptors,
|
|
1215
|
+
scalarTypeDescriptors: input.scalarTypeDescriptors,
|
|
1216
|
+
composedExtensions,
|
|
1217
|
+
familyId: input.target.familyId,
|
|
1218
|
+
targetId: input.target.targetId,
|
|
1219
|
+
authoringContributions: input.authoringContributions,
|
|
1220
|
+
diagnostics,
|
|
1221
|
+
sourceId,
|
|
1222
|
+
});
|
|
1105
1223
|
|
|
1224
|
+
if (diagnostics.length > 0) {
|
|
1106
1225
|
return notOk({
|
|
1107
1226
|
summary: 'PSL to SQL contract interpretation failed',
|
|
1108
|
-
diagnostics:
|
|
1227
|
+
diagnostics: dedupeDiagnostics(diagnostics),
|
|
1109
1228
|
});
|
|
1110
1229
|
}
|
|
1111
1230
|
|
|
@@ -1132,15 +1251,6 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1132
1251
|
})),
|
|
1133
1252
|
});
|
|
1134
1253
|
|
|
1135
|
-
const valueObjects = buildValueObjects(
|
|
1136
|
-
compositeTypes,
|
|
1137
|
-
enumResult.enumTypeDescriptors,
|
|
1138
|
-
namedTypeResult.namedTypeDescriptors,
|
|
1139
|
-
input.scalarTypeDescriptors,
|
|
1140
|
-
diagnostics,
|
|
1141
|
-
sourceId,
|
|
1142
|
-
);
|
|
1143
|
-
|
|
1144
1254
|
let patchedModels = patchModelDomainFields(
|
|
1145
1255
|
contract.models as Record<string, ContractModel>,
|
|
1146
1256
|
modelResolvedFields,
|