@prisma-next/sql-contract-psl 0.13.0-dev.16 → 0.13.0-dev.17

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 CHANGED
@@ -5,6 +5,7 @@ import { Result } from "@prisma-next/utils/result";
5
5
  import { ParsePslDocumentResult } from "@prisma-next/psl-parser";
6
6
  import { ControlMutationDefaults, ControlMutationDefaults as ControlMutationDefaults$1, DefaultFunctionLoweringContext, DefaultFunctionLoweringHandler, DefaultFunctionRegistry, DefaultFunctionRegistryEntry, MutationDefaultGeneratorDescriptor } from "@prisma-next/framework-components/control";
7
7
  import { ContractSourceDiagnostics } from "@prisma-next/config/config-types";
8
+ import { CodecLookup } from "@prisma-next/framework-components/codec";
8
9
  import { ExtensionPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
9
10
  import { Namespace } from "@prisma-next/framework-components/ir";
10
11
 
@@ -45,6 +46,7 @@ interface InterpretPslDocumentToSqlContractInput {
45
46
  * `SqlUnboundNamespace` singleton.
46
47
  */
47
48
  readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
49
+ readonly codecLookup?: CodecLookup;
48
50
  }
49
51
  declare function interpretPslDocumentToSqlContract(input: InterpretPslDocumentToSqlContractInput): Result<Contract, ContractSourceDiagnostics>;
50
52
  //#endregion
@@ -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;;;UCoDb,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;ED3DzB;;;AAAmB;;;;ACoD9B;;EDpDW,SCqEA,0BAAA,EAA4B,WAAA,SAAoB,QAAA;EAhBtC;;;;;;;;;EAAA,SA0BV,eAAA,IAAmB,KAAA,EAAO,uBAAA,KAA4B,SAAA;AAAA;AAAA,iBA8sDjD,iCAAA,CACd,KAAA,EAAO,sCAAA,GACN,MAAA,CAAO,QAAA,EAAU,yBAAA"}
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;;;UCwDb,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;ED/DzB;;;AAAmB;;;;ACwD9B;;EDxDW,SCyEA,0BAAA,EAA4B,WAAA,SAAoB,QAAA;EAhBtC;;;;;;;;;EAAA,SA0BV,eAAA,IAAmB,KAAA,EAAO,uBAAA,KAA4B,SAAA;EAAA,SACtD,WAAA,GAAc,WAAA;AAAA;AAAA,iBAwwDT,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-B_KtZusL.mjs";
1
+ import { t as interpretPslDocumentToSqlContract } from "./interpreter-He_PL0li.mjs";
2
2
  export { interpretPslDocumentToSqlContract };
@@ -1,5 +1,6 @@
1
1
  import { crossRef } from "@prisma-next/contract/types";
2
2
  import { hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringTypeConstructorDescriptor, validateAuthoringHelperArguments } from "@prisma-next/framework-components/authoring";
3
+ import { namespacePslExtensionBlocks } from "@prisma-next/framework-components/psl-ast";
3
4
  import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
4
5
  import { buildSqlContractFromDefinition } from "@prisma-next/sql-contract-ts/contract-builder";
5
6
  import { blindCast } from "@prisma-next/utils/casts";
@@ -1998,6 +1999,41 @@ function processEnumDeclarations(input) {
1998
1999
  enumTypeDescriptors
1999
2000
  };
2000
2001
  }
2002
+ function processEnum2Declarations(input) {
2003
+ const enumHandles = {};
2004
+ const enumTypeDescriptors = /* @__PURE__ */ new Map();
2005
+ if (input.enum2Blocks.length === 0) return {
2006
+ enumHandles,
2007
+ enumTypeDescriptors
2008
+ };
2009
+ const enum2EntityDescriptor = getAuthoringEntity(input.authoringContributions, ["enum2"]);
2010
+ if (!enum2EntityDescriptor) {
2011
+ for (const decl of input.enum2Blocks) input.diagnostics.push({
2012
+ code: "PSL_ENUM2_MISSING_FACTORY",
2013
+ message: `enum2 "${decl.name}" requires an "enum2" entityType factory in the active authoring contributions`,
2014
+ sourceId: input.sourceId,
2015
+ span: decl.span
2016
+ });
2017
+ return {
2018
+ enumHandles,
2019
+ enumTypeDescriptors
2020
+ };
2021
+ }
2022
+ for (const decl of input.enum2Blocks) {
2023
+ const handle = instantiateAuthoringEntityType("enum2", enum2EntityDescriptor, [decl], input.entityContext);
2024
+ if (handle === void 0 || handle === null) continue;
2025
+ const enumHandle = blindCast(handle);
2026
+ enumHandles[decl.name] = enumHandle;
2027
+ enumTypeDescriptors.set(decl.name, {
2028
+ codecId: enumHandle.codecId,
2029
+ nativeType: enumHandle.nativeType
2030
+ });
2031
+ }
2032
+ return {
2033
+ enumHandles,
2034
+ enumTypeDescriptors
2035
+ };
2036
+ }
2001
2037
  function validateNamedTypeAttributes(input) {
2002
2038
  const [dbNativeTypeAttribute, ...extraDbNativeTypeAttributes] = input.allowDbNativeType ? input.declaration.attributes.filter((attribute) => attribute.name.startsWith("db.")) : [];
2003
2039
  let hasUnsupportedNamedTypeAttribute = false;
@@ -2710,14 +2746,18 @@ function buildModelNodeFromPsl(input) {
2710
2746
  modelNode: {
2711
2747
  modelName: model.name,
2712
2748
  tableName,
2713
- fields: resolvedFields.map((resolvedField) => ({
2714
- fieldName: resolvedField.field.name,
2715
- columnName: resolvedField.columnName,
2716
- descriptor: resolvedField.descriptor,
2717
- nullable: resolvedField.field.optional,
2718
- ...ifDefined("default", resolvedField.defaultValue),
2719
- ...ifDefined("executionDefaults", resolvedField.executionDefaults)
2720
- })),
2749
+ fields: resolvedFields.map((resolvedField) => {
2750
+ const enumHandle = input.enum2Handles?.get(resolvedField.field.typeName);
2751
+ return {
2752
+ fieldName: resolvedField.field.name,
2753
+ columnName: resolvedField.columnName,
2754
+ descriptor: resolvedField.descriptor,
2755
+ nullable: resolvedField.field.optional,
2756
+ ...ifDefined("default", resolvedField.defaultValue),
2757
+ ...ifDefined("executionDefaults", resolvedField.executionDefaults),
2758
+ ...ifDefined("enumTypeHandle", enumHandle)
2759
+ };
2760
+ }),
2721
2761
  ...ifDefined("id", primaryKey),
2722
2762
  ...uniqueConstraints.length > 0 ? { uniques: uniqueConstraints } : {},
2723
2763
  ...indexNodes.length > 0 ? { indexes: indexNodes } : {},
@@ -3237,6 +3277,47 @@ function interpretPslDocumentToSqlContract(input) {
3237
3277
  for (const [name, entry] of Object.entries(nsEnumResult.storageTypes)) if (isPostgresEnumStorageEntry(entry)) nsEntries[name] = entry;
3238
3278
  if (Object.keys(nsEntries).length > 0) namespaceEnumStorageTypes[nsId] = nsEntries;
3239
3279
  }
3280
+ const topLevelEnum2s = input.document.ast.namespaces.filter((ns) => ns.name === UNSPECIFIED_PSL_NAMESPACE_NAME).flatMap((ns) => namespacePslExtensionBlocks(ns).filter((b) => b.kind === "enum2"));
3281
+ for (const ns of input.document.ast.namespaces) {
3282
+ if (ns.name === UNSPECIFIED_PSL_NAMESPACE_NAME) continue;
3283
+ const nsEnum2s = namespacePslExtensionBlocks(ns).filter((b) => b.kind === "enum2");
3284
+ if (nsEnum2s.length === 0) continue;
3285
+ for (const decl of nsEnum2s) diagnostics.push({
3286
+ code: "PSL_ENUM2_NAMESPACE_NOT_SUPPORTED",
3287
+ message: `enum2 "${decl.name}" inside namespace "${ns.name}" is not supported; declare enum2 at the top level`,
3288
+ sourceId,
3289
+ span: decl.span
3290
+ });
3291
+ }
3292
+ const enum2Result = processEnum2Declarations({
3293
+ enum2Blocks: topLevelEnum2s,
3294
+ sourceId,
3295
+ authoringContributions: input.authoringContributions,
3296
+ entityContext: {
3297
+ family: input.target.familyId,
3298
+ target: input.target.targetId,
3299
+ ...ifDefined("codecLookup", input.codecLookup),
3300
+ sourceId,
3301
+ diagnostics: { push: (d) => {
3302
+ diagnostics.push(blindCast(d));
3303
+ } }
3304
+ },
3305
+ diagnostics
3306
+ });
3307
+ const collidingEnum2Names = /* @__PURE__ */ new Set();
3308
+ for (const [name, descriptor] of enum2Result.enumTypeDescriptors) if (allEnumTypeDescriptors.has(name)) {
3309
+ collidingEnum2Names.add(name);
3310
+ const collision = topLevelEnum2s.find((e) => e.name === name);
3311
+ diagnostics.push({
3312
+ code: "PSL_ENUM2_DUPLICATE_TYPE_NAME",
3313
+ message: `enum2 "${name}" collides with an existing type name; each type name must be unique`,
3314
+ sourceId,
3315
+ ...ifDefined("span", collision?.span)
3316
+ });
3317
+ } else allEnumTypeDescriptors.set(name, descriptor);
3318
+ const validEnum2Handles = {};
3319
+ for (const [name, handle] of Object.entries(enum2Result.enumHandles)) if (!collidingEnum2Names.has(name)) validEnum2Handles[name] = handle;
3320
+ const enum2HandlesByName = new Map(Object.entries(validEnum2Handles));
3240
3321
  const namedTypeResult = resolveNamedTypeDeclarations({
3241
3322
  declarations: input.document.ast.types?.declarations ?? [],
3242
3323
  sourceId,
@@ -3283,7 +3364,8 @@ function interpretPslDocumentToSqlContract(input) {
3283
3364
  scalarTypeDescriptors: input.scalarTypeDescriptors,
3284
3365
  sourceId,
3285
3366
  diagnostics,
3286
- modelNamespaceIds
3367
+ modelNamespaceIds,
3368
+ ...enum2HandlesByName.size > 0 ? { enum2Handles: enum2HandlesByName } : {}
3287
3369
  });
3288
3370
  modelNodes.push(namespaceId !== void 0 ? {
3289
3371
  ...result.modelNode,
@@ -3336,6 +3418,7 @@ function interpretPslDocumentToSqlContract(input) {
3336
3418
  ...ifDefined("extensionPacks", buildComposedExtensionPackRefs(input.target, [...composedExtensions].sort(compareStrings), input.composedExtensionPackRefs)),
3337
3419
  ...Object.keys(storageTypes).length > 0 ? { storageTypes } : {},
3338
3420
  ...Object.keys(namespaceEnumStorageTypes).length > 0 ? { namespaceTypes: namespaceEnumStorageTypes } : {},
3421
+ ...Object.keys(validEnum2Handles).length > 0 ? { enums: validEnum2Handles } : {},
3339
3422
  ...ifDefined("createNamespace", input.createNamespace),
3340
3423
  models: stiColumnModelNodes.map((model) => ({
3341
3424
  ...model,
@@ -3362,6 +3445,7 @@ function interpretPslDocumentToSqlContract(input) {
3362
3445
  roots: filteredRoots,
3363
3446
  domain: { namespaces: Object.fromEntries(Object.entries(contract.domain.namespaces).map(([namespaceId, namespaceSlice]) => [namespaceId, {
3364
3447
  models: Object.fromEntries(Object.entries(namespaceSlice.models).map(([modelName, model]) => [modelName, patchedModels[modelCoordinateKey(namespaceId, modelName)] ?? model])),
3448
+ ...namespaceSlice.enum !== void 0 ? { enum: namespaceSlice.enum } : {},
3365
3449
  ...namespaceSlice.valueObjects !== void 0 ? { valueObjects: namespaceSlice.valueObjects } : {},
3366
3450
  ...namespaceId === input.target.defaultNamespaceId && Object.keys(valueObjects).length > 0 ? { valueObjects } : {}
3367
3451
  }])) }
@@ -3370,4 +3454,4 @@ function interpretPslDocumentToSqlContract(input) {
3370
3454
  //#endregion
3371
3455
  export { interpretPslDocumentToSqlContract as t };
3372
3456
 
3373
- //# sourceMappingURL=interpreter-B_KtZusL.mjs.map
3457
+ //# sourceMappingURL=interpreter-He_PL0li.mjs.map