@prisma-next/sql-contract-psl 0.11.0 → 0.12.0
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 +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{interpreter-fVwMptxi.mjs → interpreter-QE6eZZof.mjs} +22 -9
- package/dist/interpreter-QE6eZZof.mjs.map +1 -0
- package/dist/provider.d.mts.map +1 -1
- package/dist/provider.mjs +1 -1
- package/dist/provider.mjs.map +1 -1
- package/package.json +24 -13
- package/src/interpreter.ts +52 -9
- package/dist/interpreter-fVwMptxi.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
1
2
|
import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
|
|
3
|
+
import { Namespace } from "@prisma-next/framework-components/ir";
|
|
2
4
|
import { SqlNamespaceTablesInput } from "@prisma-next/sql-contract/types";
|
|
3
5
|
import { Result } from "@prisma-next/utils/result";
|
|
4
6
|
import { ParsePslDocumentResult } from "@prisma-next/psl-parser";
|
|
5
7
|
import { ControlMutationDefaults, ControlMutationDefaults as ControlMutationDefaults$1, DefaultFunctionLoweringContext, DefaultFunctionLoweringHandler, DefaultFunctionRegistry, DefaultFunctionRegistryEntry, MutationDefaultGeneratorDescriptor } from "@prisma-next/framework-components/control";
|
|
6
8
|
import { ContractSourceDiagnostics } from "@prisma-next/config/config-types";
|
|
7
|
-
import { Contract } from "@prisma-next/contract/types";
|
|
8
9
|
import { ExtensionPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
|
|
9
|
-
import { Namespace } from "@prisma-next/framework-components/ir";
|
|
10
10
|
|
|
11
11
|
//#region src/psl-column-resolution.d.ts
|
|
12
12
|
type ColumnDescriptor = {
|
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":";;;;;;;;;;;KAyCY,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/psl-column-resolution.ts","../src/interpreter.ts"],"mappings":";;;;;;;;;;;KAyCY,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;UC8Cb,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;EDrDzB;;;AAAmB;;;;AC8C9B;;ED9CW,SC+DA,eAAA,IAAmB,KAAA,EAAO,uBAAA,KAA4B,SAAA;AAAA;AAAA,iBAwyCjD,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-QE6eZZof.mjs";
|
|
2
2
|
export { interpretPslDocumentToSqlContract };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { crossRef } from "@prisma-next/contract/types";
|
|
1
2
|
import { hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringTypeConstructorDescriptor, validateAuthoringHelperArguments } from "@prisma-next/framework-components/authoring";
|
|
3
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
2
4
|
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
3
5
|
import { buildSqlContractFromDefinition } from "@prisma-next/sql-contract-ts/contract-builder";
|
|
4
6
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -1850,9 +1852,12 @@ const UNSPECIFIED_PSL_NAMESPACE_NAME = "__unspecified__";
|
|
|
1850
1852
|
* slot empty (which means the late-bound default at the `StorageTable`
|
|
1851
1853
|
* layer; emitted JSON omits the field).
|
|
1852
1854
|
*/
|
|
1855
|
+
function defaultSqlNamespaceIdForTarget(targetId) {
|
|
1856
|
+
return targetId === "postgres" ? "public" : UNBOUND_NAMESPACE_ID;
|
|
1857
|
+
}
|
|
1853
1858
|
function resolveNamespaceIdForSqlTarget(input) {
|
|
1854
1859
|
if (input.targetId !== "postgres") return;
|
|
1855
|
-
if (input.bucketName === UNSPECIFIED_PSL_NAMESPACE_NAME) return;
|
|
1860
|
+
if (input.bucketName === UNSPECIFIED_PSL_NAMESPACE_NAME) return "public";
|
|
1856
1861
|
if (input.bucketName === "unbound") return "__unbound__";
|
|
1857
1862
|
return input.bucketName;
|
|
1858
1863
|
}
|
|
@@ -2683,7 +2688,7 @@ function collectPolymorphismDeclarations(models, sourceId, diagnostics) {
|
|
|
2683
2688
|
baseDeclarations
|
|
2684
2689
|
};
|
|
2685
2690
|
}
|
|
2686
|
-
function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, sourceId, diagnostics) {
|
|
2691
|
+
function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, targetId, sourceId, diagnostics) {
|
|
2687
2692
|
let patched = models;
|
|
2688
2693
|
for (const [modelName, decl] of discriminatorDeclarations) {
|
|
2689
2694
|
if (baseDeclarations.has(modelName)) {
|
|
@@ -2770,7 +2775,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
|
|
|
2770
2775
|
...patched,
|
|
2771
2776
|
[variantName]: {
|
|
2772
2777
|
...variantModel,
|
|
2773
|
-
base: baseDecl.baseName,
|
|
2778
|
+
base: crossRef(baseDecl.baseName, modelNamespaceIds.get(baseDecl.baseName) ?? defaultSqlNamespaceIdForTarget(targetId)),
|
|
2774
2779
|
...resolvedTable ? { storage: {
|
|
2775
2780
|
...variantModel.storage,
|
|
2776
2781
|
table: resolvedTable
|
|
@@ -2951,23 +2956,31 @@ function interpretPslDocumentToSqlContract(input) {
|
|
|
2951
2956
|
...modelRelations.has(model.modelName) ? { relations: [...modelRelations.get(model.modelName) ?? []].sort((left, right) => compareStrings(left.fieldName, right.fieldName)) } : {}
|
|
2952
2957
|
}))
|
|
2953
2958
|
});
|
|
2954
|
-
|
|
2959
|
+
const modelsForPatch = {};
|
|
2960
|
+
for (const namespaceSlice of Object.values(contract.domain.namespaces)) for (const [modelName, model] of Object.entries(namespaceSlice.models)) {
|
|
2961
|
+
if (Object.hasOwn(modelsForPatch, modelName)) throw new Error(`duplicate model name "${modelName}" across domain namespaces during PSL interpretation`);
|
|
2962
|
+
modelsForPatch[modelName] = model;
|
|
2963
|
+
}
|
|
2964
|
+
let patchedModels = patchModelDomainFields(modelsForPatch, modelResolvedFields);
|
|
2955
2965
|
const polyDiagnostics = [];
|
|
2956
|
-
patchedModels = resolvePolymorphism(patchedModels, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, sourceId, polyDiagnostics);
|
|
2966
|
+
patchedModels = resolvePolymorphism(patchedModels, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, input.target.targetId, sourceId, polyDiagnostics);
|
|
2957
2967
|
if (polyDiagnostics.length > 0) return notOk({
|
|
2958
2968
|
summary: "PSL to SQL contract interpretation failed",
|
|
2959
2969
|
diagnostics: polyDiagnostics
|
|
2960
2970
|
});
|
|
2961
2971
|
const variantModelNames = new Set(baseDeclarations.keys());
|
|
2962
|
-
const filteredRoots = Object.fromEntries(Object.entries(contract.roots).filter(([,
|
|
2972
|
+
const filteredRoots = Object.fromEntries(Object.entries(contract.roots).filter(([, crossReference]) => !variantModelNames.has(crossReference.model)));
|
|
2963
2973
|
return ok({
|
|
2964
2974
|
...contract,
|
|
2965
2975
|
roots: filteredRoots,
|
|
2966
|
-
|
|
2967
|
-
|
|
2976
|
+
domain: { namespaces: Object.fromEntries(Object.entries(contract.domain.namespaces).map(([namespaceId, namespaceSlice]) => [namespaceId, {
|
|
2977
|
+
models: Object.fromEntries(Object.entries(namespaceSlice.models).map(([modelName, model]) => [modelName, patchedModels[modelName] ?? model])),
|
|
2978
|
+
...namespaceSlice.valueObjects !== void 0 ? { valueObjects: namespaceSlice.valueObjects } : {},
|
|
2979
|
+
...namespaceId === defaultSqlNamespaceIdForTarget(input.target.targetId) && Object.keys(valueObjects).length > 0 ? { valueObjects } : {}
|
|
2980
|
+
}])) }
|
|
2968
2981
|
});
|
|
2969
2982
|
}
|
|
2970
2983
|
//#endregion
|
|
2971
2984
|
export { interpretPslDocumentToSqlContract as t };
|
|
2972
2985
|
|
|
2973
|
-
//# sourceMappingURL=interpreter-
|
|
2986
|
+
//# sourceMappingURL=interpreter-QE6eZZof.mjs.map
|