@prisma-next/sql-contract-psl 0.8.0 → 0.9.0-dev.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/psl-column-resolution.ts","../src/interpreter.ts"],"mappings":";;;;;;;;;KAuCY,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAA;AAAA;;;UCsCP,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;AAAA;AAAA,iBA+nCpB,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":";;;;;;;;;KAyCY,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAA;AAAA;;;UCyCP,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;AAAA;AAAA,iBAypCpB,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-ijCjxhaU.mjs";
1
+ import { t as interpretPslDocumentToSqlContract } from "./interpreter-D_zkd14G.mjs";
2
2
  export { interpretPslDocumentToSqlContract };
@@ -1,4 +1,5 @@
1
- import { hasRegisteredFieldNamespace, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringFieldPresetDescriptor, isAuthoringTypeConstructorDescriptor, validateAuthoringHelperArguments } from "@prisma-next/framework-components/authoring";
1
+ import { hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringTypeConstructorDescriptor, validateAuthoringHelperArguments } from "@prisma-next/framework-components/authoring";
2
+ import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
2
3
  import { buildSqlContractFromDefinition } from "@prisma-next/sql-contract-ts/contract-builder";
3
4
  import { ifDefined } from "@prisma-next/utils/defined";
4
5
  import { notOk, ok } from "@prisma-next/utils/result";
@@ -732,6 +733,25 @@ function getAuthoringTypeConstructor(contributions, path) {
732
733
  return isAuthoringTypeConstructorDescriptor(current) ? current : void 0;
733
734
  }
734
735
  /**
736
+ * Walks `authoringContributions.entityTypes` segment-by-segment and returns
737
+ * the entity type descriptor at the resolved path, or `undefined` if no
738
+ * descriptor is registered.
739
+ *
740
+ * Used by the PSL interpreter to dispatch declarative entity-shaped
741
+ * declarations (`enum`, future `namespace { … }`, …) through the
742
+ * pack entity-type mechanism — the descriptor's `factory` (or
743
+ * `template`) materialises the IR-class instance without the
744
+ * interpreter knowing target-specific construction.
745
+ */
746
+ function getAuthoringEntity(contributions, path) {
747
+ let current = contributions?.entityTypes;
748
+ for (const segment of path) {
749
+ if (typeof current !== "object" || current === null || Array.isArray(current)) return;
750
+ current = current[segment];
751
+ }
752
+ return isAuthoringEntityTypeDescriptor(current) ? current : void 0;
753
+ }
754
+ /**
735
755
  * Walks `authoringContributions.field` segment-by-segment and returns the field-preset descriptor at the resolved path, or `undefined` if no descriptor is registered.
736
756
  *
737
757
  * Symmetric with `getAuthoringTypeConstructor`. Field presets are strictly richer than type constructors — they can contribute `default` / `executionDefaults` / `id` / `unique` / `nullable` in addition to the `codecId` / `nativeType` / `typeParams` triple. PSL resolution tries field presets first, then falls back to type constructors on miss (see `resolveFieldTypeDescriptor`).
@@ -1780,6 +1800,22 @@ function mapParserDiagnostics(document) {
1780
1800
  function processEnumDeclarations(input) {
1781
1801
  const storageTypes = {};
1782
1802
  const enumTypeDescriptors = /* @__PURE__ */ new Map();
1803
+ if (input.enums.length === 0) return {
1804
+ storageTypes,
1805
+ enumTypeDescriptors
1806
+ };
1807
+ if (!input.enumEntityDescriptor) {
1808
+ for (const enumDeclaration of input.enums) input.diagnostics.push({
1809
+ code: "PSL_UNSUPPORTED_NAMED_TYPE_BASE",
1810
+ message: `Enum "${enumDeclaration.name}" requires the active target pack to contribute an enum entity-type helper`,
1811
+ sourceId: input.sourceId,
1812
+ span: enumDeclaration.span
1813
+ });
1814
+ return {
1815
+ storageTypes,
1816
+ enumTypeDescriptors
1817
+ };
1818
+ }
1783
1819
  for (const enumDeclaration of input.enums) {
1784
1820
  const nativeType = parseMapName({
1785
1821
  attribute: getAttribute(enumDeclaration.attributes, "map"),
@@ -1789,22 +1825,28 @@ function processEnumDeclarations(input) {
1789
1825
  entityLabel: `Enum "${enumDeclaration.name}"`,
1790
1826
  span: enumDeclaration.span
1791
1827
  });
1792
- const enumStorageType = input.enumTypeConstructor ? instantiateAuthoringTypeConstructor(input.enumTypeConstructor, [nativeType, enumDeclaration.values.map((value) => value.name)]) : {
1793
- codecId: "pg/enum@1",
1828
+ const values = enumDeclaration.values.map((value) => value.name);
1829
+ const constructed = instantiateAuthoringEntityType("enum", input.enumEntityDescriptor, [{
1830
+ name: enumDeclaration.name,
1794
1831
  nativeType,
1795
- typeParams: { values: enumDeclaration.values.map((value) => value.name) }
1796
- };
1832
+ values
1833
+ }], input.entityContext);
1834
+ if (!isPostgresEnumStorageEntry(constructed)) {
1835
+ input.diagnostics.push({
1836
+ code: "PSL_UNSUPPORTED_NAMED_TYPE_BASE",
1837
+ message: `Enum "${enumDeclaration.name}": enum entity-type factory must return a PostgresEnumStorageEntry-shaped value (kind: 'postgres-enum')`,
1838
+ sourceId: input.sourceId,
1839
+ span: enumDeclaration.span
1840
+ });
1841
+ continue;
1842
+ }
1797
1843
  const descriptor = {
1798
- codecId: enumStorageType.codecId,
1799
- nativeType: enumStorageType.nativeType,
1844
+ codecId: constructed.codecId,
1845
+ nativeType: constructed.nativeType,
1800
1846
  typeRef: enumDeclaration.name
1801
1847
  };
1802
1848
  enumTypeDescriptors.set(enumDeclaration.name, descriptor);
1803
- storageTypes[enumDeclaration.name] = {
1804
- codecId: enumStorageType.codecId,
1805
- nativeType: enumStorageType.nativeType,
1806
- typeParams: enumStorageType.typeParams ?? { values: enumDeclaration.values.map((value) => value.name) }
1807
- };
1849
+ storageTypes[enumDeclaration.name] = constructed;
1808
1850
  }
1809
1851
  return {
1810
1852
  storageTypes,
@@ -1893,6 +1935,7 @@ function resolveNamedTypeDeclarations(input) {
1893
1935
  if (!storageType) continue;
1894
1936
  namedTypeDescriptors.set(declaration.name, toNamedTypeFieldDescriptor(declaration.name, storageType));
1895
1937
  storageTypes[declaration.name] = {
1938
+ kind: "codec-instance",
1896
1939
  codecId: storageType.codecId,
1897
1940
  nativeType: storageType.nativeType,
1898
1941
  typeParams: storageType.typeParams ?? {}
@@ -1942,6 +1985,7 @@ function resolveNamedTypeDeclarations(input) {
1942
1985
  if (!descriptor) continue;
1943
1986
  namedTypeDescriptors.set(declaration.name, toNamedTypeFieldDescriptor(declaration.name, descriptor));
1944
1987
  storageTypes[declaration.name] = {
1988
+ kind: "codec-instance",
1945
1989
  codecId: descriptor.codecId,
1946
1990
  nativeType: descriptor.nativeType,
1947
1991
  typeParams: descriptor.typeParams ?? {}
@@ -1951,6 +1995,7 @@ function resolveNamedTypeDeclarations(input) {
1951
1995
  const descriptor = toNamedTypeFieldDescriptor(declaration.name, baseDescriptor);
1952
1996
  namedTypeDescriptors.set(declaration.name, descriptor);
1953
1997
  storageTypes[declaration.name] = {
1998
+ kind: "codec-instance",
1954
1999
  codecId: baseDescriptor.codecId,
1955
2000
  nativeType: baseDescriptor.nativeType,
1956
2001
  typeParams: {}
@@ -2665,7 +2710,11 @@ function interpretPslDocumentToSqlContract(input) {
2665
2710
  const enumResult = processEnumDeclarations({
2666
2711
  enums,
2667
2712
  sourceId,
2668
- enumTypeConstructor: getAuthoringTypeConstructor(input.authoringContributions, ["enum"]),
2713
+ enumEntityDescriptor: getAuthoringEntity(input.authoringContributions, ["enum"]),
2714
+ entityContext: {
2715
+ family: input.target.familyId,
2716
+ target: input.target.targetId
2717
+ },
2669
2718
  diagnostics
2670
2719
  });
2671
2720
  const namedTypeResult = resolveNamedTypeDeclarations({
@@ -2767,4 +2816,4 @@ function interpretPslDocumentToSqlContract(input) {
2767
2816
  //#endregion
2768
2817
  export { interpretPslDocumentToSqlContract as t };
2769
2818
 
2770
- //# sourceMappingURL=interpreter-ijCjxhaU.mjs.map
2819
+ //# sourceMappingURL=interpreter-D_zkd14G.mjs.map