@prisma-next/sql-contract-psl 0.12.0-dev.59 → 0.12.0-dev.60
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/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{interpreter-VW03aPWq.mjs → interpreter-1VmrYYbi.mjs} +124 -3
- package/dist/interpreter-1VmrYYbi.mjs.map +1 -0
- package/dist/provider.mjs +1 -1
- package/package.json +12 -12
- package/src/interpreter.ts +173 -2
- package/src/psl-field-resolution.ts +6 -0
- package/dist/interpreter-VW03aPWq.mjs.map +0 -1
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/psl-column-resolution.ts","../src/interpreter.ts"],"mappings":";;;;;;;;;;;KA0CY,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/psl-column-resolution.ts","../src/interpreter.ts"],"mappings":";;;;;;;;;;;KA0CY,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;UCkDb,sCAAA;EAAA,SACN,QAAA,EAAU,sBAAA;EAAA,SACV,MAAA,EAAQ,aAAA;EAAA,SACR,qBAAA,EAAuB,WAAA,SAAoB,gBAAA;EAAA,SAC3C,sBAAA;EAAA,SACA,yBAAA,YAAqC,gBAAA;EAAA,SACrC,uBAAA,GAA0B,yBAAA;EAAA,SAC1B,sBAAA,GAAyB,sBAAA;EDzDzB;;;AAAmB;;;;ACkD9B;;EDlDW,SCmEA,eAAA,IAAmB,KAAA,EAAO,uBAAA,KAA4B,SAAA;AAAA;AAAA,iBAgqDjD,iCAAA,CACd,KAAA,EAAO,sCAAA,GACN,MAAA,CAAO,QAAA,EAAU,yBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as interpretPslDocumentToSqlContract } from "./interpreter-
|
|
1
|
+
import { t as interpretPslDocumentToSqlContract } from "./interpreter-1VmrYYbi.mjs";
|
|
2
2
|
export { interpretPslDocumentToSqlContract };
|
|
@@ -1394,6 +1394,7 @@ function collectResolvedFields(input) {
|
|
|
1394
1394
|
});
|
|
1395
1395
|
const relationAttribute = getAttribute(field.attributes, "relation");
|
|
1396
1396
|
if (isModelField && relationAttribute) continue;
|
|
1397
|
+
if (field.typeContractSpaceId !== void 0 && relationAttribute) continue;
|
|
1397
1398
|
const isValueObjectField = compositeTypeNames.has(field.typeName);
|
|
1398
1399
|
const isListField = field.list;
|
|
1399
1400
|
let descriptor;
|
|
@@ -2451,9 +2452,118 @@ function buildModelNodeFromPsl(input) {
|
|
|
2451
2452
|
});
|
|
2452
2453
|
}
|
|
2453
2454
|
const resultFkRelationMetadata = [];
|
|
2455
|
+
const resultCrossSpaceRelations = [];
|
|
2454
2456
|
for (const relationAttribute of relationAttributes) {
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
+
const { typeName: fieldTypeName, typeNamespaceId: fieldTypeNamespaceId, typeContractSpaceId: fieldTypeContractSpaceId } = relationAttribute.field;
|
|
2458
|
+
if (relationAttribute.field.list) {
|
|
2459
|
+
if (fieldTypeContractSpaceId !== void 0) diagnostics.push({
|
|
2460
|
+
code: "PSL_UNSUPPORTED_CROSS_SPACE_LIST",
|
|
2461
|
+
message: `Relation field "${model.name}.${relationAttribute.field.name}" is a cross-space list relation (type "${fieldTypeContractSpaceId}:${fieldTypeNamespaceId !== void 0 ? `${fieldTypeNamespaceId}.` : ""}${fieldTypeName}[]"). Cross-space relations must be singular in v0.1 — list cross-space relations are not supported.`,
|
|
2462
|
+
sourceId,
|
|
2463
|
+
span: relationAttribute.field.span
|
|
2464
|
+
});
|
|
2465
|
+
continue;
|
|
2466
|
+
}
|
|
2467
|
+
if (fieldTypeContractSpaceId !== void 0) {
|
|
2468
|
+
if (!input.composedExtensions.has(fieldTypeContractSpaceId)) {
|
|
2469
|
+
diagnostics.push({
|
|
2470
|
+
code: "PSL_UNKNOWN_CONTRACT_SPACE",
|
|
2471
|
+
message: `Relation field "${model.name}.${relationAttribute.field.name}" references contract space "${fieldTypeContractSpaceId}" which is not declared in extensionPacks. Add "${fieldTypeContractSpaceId}" to extensionPacks in prisma-next.config.ts.`,
|
|
2472
|
+
sourceId,
|
|
2473
|
+
span: relationAttribute.field.span,
|
|
2474
|
+
data: {
|
|
2475
|
+
space: fieldTypeContractSpaceId,
|
|
2476
|
+
suggestedPack: fieldTypeContractSpaceId
|
|
2477
|
+
}
|
|
2478
|
+
});
|
|
2479
|
+
continue;
|
|
2480
|
+
}
|
|
2481
|
+
const parsedRelation = parseRelationAttribute({
|
|
2482
|
+
attribute: relationAttribute.relation,
|
|
2483
|
+
modelName: model.name,
|
|
2484
|
+
fieldName: relationAttribute.field.name,
|
|
2485
|
+
sourceId,
|
|
2486
|
+
diagnostics
|
|
2487
|
+
});
|
|
2488
|
+
if (!parsedRelation) continue;
|
|
2489
|
+
if (!parsedRelation.fields || !parsedRelation.references) {
|
|
2490
|
+
diagnostics.push({
|
|
2491
|
+
code: "PSL_INVALID_RELATION_ATTRIBUTE",
|
|
2492
|
+
message: `Relation field "${model.name}.${relationAttribute.field.name}" requires fields and references arguments`,
|
|
2493
|
+
sourceId,
|
|
2494
|
+
span: relationAttribute.relation.span
|
|
2495
|
+
});
|
|
2496
|
+
continue;
|
|
2497
|
+
}
|
|
2498
|
+
const localColumns = mapFieldNamesToColumns({
|
|
2499
|
+
modelName: model.name,
|
|
2500
|
+
fieldNames: parsedRelation.fields,
|
|
2501
|
+
mapping,
|
|
2502
|
+
sourceId,
|
|
2503
|
+
diagnostics,
|
|
2504
|
+
span: relationAttribute.relation.span,
|
|
2505
|
+
entityLabel: `Relation field "${model.name}.${relationAttribute.field.name}"`
|
|
2506
|
+
});
|
|
2507
|
+
if (!localColumns) continue;
|
|
2508
|
+
const referencedColumns = parsedRelation.references;
|
|
2509
|
+
if (localColumns.length !== referencedColumns.length) {
|
|
2510
|
+
diagnostics.push({
|
|
2511
|
+
code: "PSL_INVALID_RELATION_ATTRIBUTE",
|
|
2512
|
+
message: `Relation field "${model.name}.${relationAttribute.field.name}" must provide the same number of fields and references`,
|
|
2513
|
+
sourceId,
|
|
2514
|
+
span: relationAttribute.relation.span
|
|
2515
|
+
});
|
|
2516
|
+
continue;
|
|
2517
|
+
}
|
|
2518
|
+
const onDelete = parsedRelation.onDelete ? normalizeReferentialAction({
|
|
2519
|
+
modelName: model.name,
|
|
2520
|
+
fieldName: relationAttribute.field.name,
|
|
2521
|
+
actionName: "onDelete",
|
|
2522
|
+
actionToken: parsedRelation.onDelete,
|
|
2523
|
+
sourceId,
|
|
2524
|
+
span: relationAttribute.field.span,
|
|
2525
|
+
diagnostics
|
|
2526
|
+
}) : void 0;
|
|
2527
|
+
const onUpdate = parsedRelation.onUpdate ? normalizeReferentialAction({
|
|
2528
|
+
modelName: model.name,
|
|
2529
|
+
fieldName: relationAttribute.field.name,
|
|
2530
|
+
actionName: "onUpdate",
|
|
2531
|
+
actionToken: parsedRelation.onUpdate,
|
|
2532
|
+
sourceId,
|
|
2533
|
+
span: relationAttribute.field.span,
|
|
2534
|
+
diagnostics
|
|
2535
|
+
}) : void 0;
|
|
2536
|
+
const crossTargetNamespaceId = fieldTypeNamespaceId ?? "__unbound__";
|
|
2537
|
+
const crossTargetTableName = fieldTypeName.toLowerCase();
|
|
2538
|
+
foreignKeyNodes.push({
|
|
2539
|
+
columns: localColumns,
|
|
2540
|
+
references: {
|
|
2541
|
+
model: fieldTypeName,
|
|
2542
|
+
table: crossTargetTableName,
|
|
2543
|
+
columns: referencedColumns,
|
|
2544
|
+
namespaceId: crossTargetNamespaceId,
|
|
2545
|
+
spaceId: fieldTypeContractSpaceId
|
|
2546
|
+
},
|
|
2547
|
+
...ifDefined("name", parsedRelation.constraintName),
|
|
2548
|
+
...ifDefined("onDelete", onDelete),
|
|
2549
|
+
...ifDefined("onUpdate", onUpdate)
|
|
2550
|
+
});
|
|
2551
|
+
resultCrossSpaceRelations.push({
|
|
2552
|
+
fieldName: relationAttribute.field.name,
|
|
2553
|
+
toModel: fieldTypeName,
|
|
2554
|
+
toTable: crossTargetTableName,
|
|
2555
|
+
cardinality: "N:1",
|
|
2556
|
+
spaceId: fieldTypeContractSpaceId,
|
|
2557
|
+
namespaceId: crossTargetNamespaceId,
|
|
2558
|
+
on: {
|
|
2559
|
+
parentTable: tableName,
|
|
2560
|
+
parentColumns: localColumns,
|
|
2561
|
+
childTable: crossTargetTableName,
|
|
2562
|
+
childColumns: referencedColumns
|
|
2563
|
+
}
|
|
2564
|
+
});
|
|
2565
|
+
continue;
|
|
2566
|
+
}
|
|
2457
2567
|
const qualifiedTypeName = fieldTypeNamespaceId ? `${fieldTypeNamespaceId}.${fieldTypeName}` : fieldTypeName;
|
|
2458
2568
|
if (!input.modelNames.has(fieldTypeName)) {
|
|
2459
2569
|
diagnostics.push({
|
|
@@ -2592,6 +2702,7 @@ function buildModelNodeFromPsl(input) {
|
|
|
2592
2702
|
...ifDefined("control", controlPolicy)
|
|
2593
2703
|
},
|
|
2594
2704
|
fkRelationMetadata: resultFkRelationMetadata,
|
|
2705
|
+
crossSpaceRelations: resultCrossSpaceRelations,
|
|
2595
2706
|
backrelationCandidates: resultBackrelationCandidates,
|
|
2596
2707
|
resolvedFields
|
|
2597
2708
|
};
|
|
@@ -3114,6 +3225,7 @@ function interpretPslDocumentToSqlContract(input) {
|
|
|
3114
3225
|
const fkRelationMetadata = [];
|
|
3115
3226
|
const backrelationCandidates = [];
|
|
3116
3227
|
const modelResolvedFields = /* @__PURE__ */ new Map();
|
|
3228
|
+
const crossSpaceRelationsByModel = /* @__PURE__ */ new Map();
|
|
3117
3229
|
for (const model of models) {
|
|
3118
3230
|
const mapping = modelMappings.get(model.name);
|
|
3119
3231
|
if (!mapping) continue;
|
|
@@ -3144,6 +3256,10 @@ function interpretPslDocumentToSqlContract(input) {
|
|
|
3144
3256
|
fkRelationMetadata.push(...result.fkRelationMetadata);
|
|
3145
3257
|
backrelationCandidates.push(...result.backrelationCandidates);
|
|
3146
3258
|
modelResolvedFields.set(model.name, result.resolvedFields);
|
|
3259
|
+
if (result.crossSpaceRelations.length > 0) {
|
|
3260
|
+
const existing = crossSpaceRelationsByModel.get(model.name) ?? [];
|
|
3261
|
+
crossSpaceRelationsByModel.set(model.name, [...existing, ...result.crossSpaceRelations]);
|
|
3262
|
+
}
|
|
3147
3263
|
}
|
|
3148
3264
|
const { modelRelations, fkRelationsByPair } = indexFkRelations({ fkRelationMetadata });
|
|
3149
3265
|
applyBackrelationCandidates({
|
|
@@ -3153,6 +3269,11 @@ function interpretPslDocumentToSqlContract(input) {
|
|
|
3153
3269
|
diagnostics,
|
|
3154
3270
|
sourceId
|
|
3155
3271
|
});
|
|
3272
|
+
for (const [modelName, relations] of crossSpaceRelationsByModel) {
|
|
3273
|
+
const existing = modelRelations.get(modelName);
|
|
3274
|
+
if (existing) existing.push(...relations);
|
|
3275
|
+
else modelRelations.set(modelName, [...relations]);
|
|
3276
|
+
}
|
|
3156
3277
|
const { discriminatorDeclarations, baseDeclarations } = collectPolymorphismDeclarations(models, sourceId, diagnostics);
|
|
3157
3278
|
const stiVariantNames = /* @__PURE__ */ new Set();
|
|
3158
3279
|
for (const variantName of baseDeclarations.keys()) if (!(modelMappings.get(variantName)?.model.attributes.some((attr) => attr.name === "map") ?? false)) stiVariantNames.add(variantName);
|
|
@@ -3212,4 +3333,4 @@ function interpretPslDocumentToSqlContract(input) {
|
|
|
3212
3333
|
//#endregion
|
|
3213
3334
|
export { interpretPslDocumentToSqlContract as t };
|
|
3214
3335
|
|
|
3215
|
-
//# sourceMappingURL=interpreter-
|
|
3336
|
+
//# sourceMappingURL=interpreter-1VmrYYbi.mjs.map
|