@prisma/orm-family-sql 8.0.0-rc.13 → 8.0.0-rc.13-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.
Files changed (59) hide show
  1. package/dist/authoring-entity-types-CZ-vdwYS-GsYvzoFF.d.mts +9 -0
  2. package/dist/authoring-entity-types-CZ-vdwYS-GsYvzoFF.d.mts.map +1 -0
  3. package/dist/{authoring-type-constructors-C1ogrr_x-BZQc95SF.mjs → authoring-type-constructors-DQZEX4Sb-DORF5BnN.mjs} +32 -39
  4. package/dist/authoring-type-constructors-DQZEX4Sb-DORF5BnN.mjs.map +1 -0
  5. package/dist/{contract-builder-3vURlaBN.mjs → contract-builder-BKfGg37_.mjs} +2 -2
  6. package/dist/{contract-builder-3vURlaBN.mjs.map → contract-builder-BKfGg37_.mjs.map} +1 -1
  7. package/dist/{contract-builder-Ct1IMc8_.d.mts → contract-builder-j05FWfIe.d.mts} +2 -2
  8. package/dist/{contract-builder-Ct1IMc8_.d.mts.map → contract-builder-j05FWfIe.d.mts.map} +1 -1
  9. package/dist/contract-prisma7__provider.mjs +53 -26
  10. package/dist/contract-prisma7__provider.mjs.map +1 -1
  11. package/dist/contract-psl.d.mts +1 -1
  12. package/dist/contract-psl.mjs +1 -1
  13. package/dist/contract-psl__attribute-specs.mjs +1 -1
  14. package/dist/contract-psl__provider.mjs +2 -3
  15. package/dist/contract-psl__provider.mjs.map +1 -1
  16. package/dist/contract-ts.d.mts +1 -1
  17. package/dist/contract-ts.mjs +1 -1
  18. package/dist/contract-ts__contract-builder.d.mts +1 -1
  19. package/dist/contract-ts__contract-builder.mjs +1 -1
  20. package/dist/contract.d.mts +2 -2
  21. package/dist/contract.mjs +2 -2
  22. package/dist/contract__entity-handle-lowering-hook.d.mts +2 -2
  23. package/dist/contract__entity-handle-lowering-hook.mjs +2 -2
  24. package/dist/{control-BcWypsQy.mjs → control-DUrW46cS.mjs} +5 -5
  25. package/dist/{control-BcWypsQy.mjs.map → control-DUrW46cS.mjs.map} +1 -1
  26. package/dist/{control-BKwzdenn.d.mts → control-VctoviCf.d.mts} +12 -12
  27. package/dist/control-VctoviCf.d.mts.map +1 -0
  28. package/dist/diff-B16bL_IR.mjs.map +1 -1
  29. package/dist/{entity-handle-lowering-hook-CIvRKBfa.d.mts → entity-handle-lowering-hook-93syhZ0p.d.mts} +7 -10
  30. package/dist/{entity-handle-lowering-hook-CIvRKBfa.d.mts.map → entity-handle-lowering-hook-93syhZ0p.d.mts.map} +1 -1
  31. package/dist/{entity-handle-lowering-hook-DwLIKNiS.mjs → entity-handle-lowering-hook-B3atrRKX.mjs} +7 -2
  32. package/dist/entity-handle-lowering-hook-B3atrRKX.mjs.map +1 -0
  33. package/dist/family.d.mts +2 -1
  34. package/dist/family.mjs +3 -3
  35. package/dist/family__control.d.mts +1 -1
  36. package/dist/family__control.mjs +2 -2
  37. package/dist/family__diff.mjs +1 -1
  38. package/dist/family__ir.mjs +1 -1
  39. package/dist/family__pack.d.mts +2 -323
  40. package/dist/family__pack.mjs +2 -2
  41. package/dist/family__pack.mjs.map +1 -1
  42. package/dist/{interpreter-BrW0_y8Q-ChkFlzaN.mjs → interpreter-BMMGMTBa-CT5iKl13.mjs} +102 -142
  43. package/dist/interpreter-BMMGMTBa-CT5iKl13.mjs.map +1 -0
  44. package/dist/ir-I-xciGUH.mjs.map +1 -1
  45. package/dist/pack-CUGnCaEh.d.mts +323 -0
  46. package/dist/pack-CUGnCaEh.d.mts.map +1 -0
  47. package/dist/{schema-verify-CrvQZ5V8-BfrNHJbX.mjs → schema-verify-DI0aJQ9d-D5SmSZg3.mjs} +2 -2
  48. package/dist/{schema-verify-CrvQZ5V8-BfrNHJbX.mjs.map → schema-verify-DI0aJQ9d-D5SmSZg3.mjs.map} +1 -1
  49. package/dist/{sql-attribute-specs-DH3Yxb21-CZV-L28L.mjs → sql-attribute-specs-4YqT9Gt_-DkPyYEaE.mjs} +12 -3
  50. package/dist/sql-attribute-specs-4YqT9Gt_-DkPyYEaE.mjs.map +1 -0
  51. package/dist/{sql-contract-serializer-0a4k494z-tI6ajwvm.mjs → sql-contract-serializer-C90xg7_q-A3_F0w7f.mjs} +2 -2
  52. package/dist/{sql-contract-serializer-0a4k494z-tI6ajwvm.mjs.map → sql-contract-serializer-C90xg7_q-A3_F0w7f.mjs.map} +1 -1
  53. package/package.json +18 -18
  54. package/dist/authoring-type-constructors-C1ogrr_x-BZQc95SF.mjs.map +0 -1
  55. package/dist/control-BKwzdenn.d.mts.map +0 -1
  56. package/dist/entity-handle-lowering-hook-DwLIKNiS.mjs.map +0 -1
  57. package/dist/family__pack.d.mts.map +0 -1
  58. package/dist/interpreter-BrW0_y8Q-ChkFlzaN.mjs.map +0 -1
  59. package/dist/sql-attribute-specs-DH3Yxb21-CZV-L28L.mjs.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import { n as isAuthoredIndexInput } from "./index-naming-Cj1Anq-T-w1JL7-EM.mjs";
2
+ import { n as providesPslEntityPlacement } from "./entity-handle-lowering-hook-B3atrRKX.mjs";
2
3
  import { t as deriveValueSetFromEntity } from "./value-set-derivation-hook-Di9JZ0X7.mjs";
3
4
  import { n as buildSqlContractFromDefinition } from "./derived-checks-Bsrdb2Wk-D4UfM06W.mjs";
4
- import { a as findModelAttributeNode, c as lowerDefaultFunctionWithRegistry, i as findFieldAttributeNode, l as modelAttributeSpecsFrom, n as createSqlBinder, o as interpretFieldAttribute, r as fieldSpecContext, s as interpretModelAttribute, t as PSL_CHECK_ON_STI_VARIANT, u as sqlAttributeSpecs } from "./sql-attribute-specs-DH3Yxb21-CZV-L28L.mjs";
5
+ import { a as findModelAttributeNode, c as lowerDefaultFunctionWithRegistry, i as findFieldAttributeNode, l as modelAttributeSpecsFrom, n as createSqlBinder, o as interpretFieldAttribute, r as fieldSpecContext, s as interpretModelAttribute, t as PSL_CHECK_ON_STI_VARIANT, u as sqlAttributeSpecs } from "./sql-attribute-specs-4YqT9Gt_-DkPyYEaE.mjs";
5
6
  import { t as defaultTableName } from "./default-table-name-BfFY8qYR-lHNcVmY5.mjs";
6
7
  import { isStructuredError, structuredError } from "@prisma/orm-framework/utils/structured-error";
7
8
  import { checkUncomposedNamespace, getAuthoringFieldPreset, hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringModelAttributeDescriptor, isAuthoringTypeConstructorDescriptor, isDataTypeLoweringEntry, loweringEntryKey, validateAuthoringHelperArguments } from "@prisma/orm-framework/components/authoring";
@@ -15,10 +16,10 @@ import { materializeCodec } from "@prisma/orm-framework/components/codec";
15
16
  import { assertDefined, invariant } from "@prisma/orm-framework/utils/assertions";
16
17
  import { describeTaggedLiteralFailure } from "@prisma/orm-framework/components/control";
17
18
  import { notOk, ok } from "@prisma/orm-framework/utils/result";
18
- import { createPslDiagnosticCollector, diagnosticSource, findBlockDescriptor, nodePslSpan } from "@prisma/orm-framework/psl-parser";
19
+ import { createPslDiagnosticCollector, diagnosticSource, findBlockDescriptor, interpretExtensionBlocks, nodePslSpan } from "@prisma/orm-framework/psl-parser";
19
20
  import { UNBOUND_PSL_NAMESPACE_NAME, UNSPECIFIED_PSL_NAMESPACE_ID } from "@prisma/orm-framework/components/psl-ast";
20
21
  import { claimedBlockKeywords, consumeInvalidFkPairing, enumMemberAttributeDiagnostics, fkRelationPairKey, instantiatePslFieldPreset, mapPslHelperArgs, reportUncomposedNamespace, reportUnknownFieldPreset, requiredOneToOneBackrelationDiagnostic, uncomposedNamespaceDiagnostic, unsupportedBlockDiagnostic } from "@prisma/orm-framework/psl-parser/interpret";
21
- //#region ../../../2-sql/2-authoring/contract-psl/dist/interpreter-BrW0_y8Q.mjs
22
+ //#region ../../../2-sql/2-authoring/contract-psl/dist/interpreter-BMMGMTBa.mjs
22
23
  function contractError(code, message, options) {
23
24
  return structuredError(code, message, options);
24
25
  }
@@ -1871,29 +1872,23 @@ function duplicateModelAttributeDiagnostic(input) {
1871
1872
  ...input.source.at(input.span)
1872
1873
  };
1873
1874
  }
1874
- /**
1875
- * Enforces `AuthoringPslBlockDescriptor.requiresModelAttribute` over one
1876
- * scope (the top level or one namespace): every block whose descriptor
1877
- * declares the requirement must name a model that carries the required
1878
- * bare `@@` attribute. Runs on the parsed symbol table, so it is
1879
- * independent of block/model declaration order and of lowering order. A
1880
- * missing parameter or an unresolvable model is skipped — the
1881
- * missing-required-parameter and unresolved-ref diagnostics own those
1882
- * failure modes.
1883
- */
1875
+ function isResolvedModelReference(value) {
1876
+ if (typeof value !== "object" || value === null || !("declaration" in value)) return false;
1877
+ const declaration = value.declaration;
1878
+ return typeof declaration === "object" && declaration !== null && "kind" in declaration && declaration.kind === "model";
1879
+ }
1884
1880
  function validateBlockModelAttributeRequirements(input) {
1885
- for (const scope of input.scopes) for (const blockSymbol of Object.values(scope.blocks)) {
1881
+ for (const [blockSymbol, envelope] of input.parsedBlocks) {
1886
1882
  const requirement = findBlockDescriptor(input.pslBlockDescriptors, blockSymbol.keyword)?.requiresModelAttribute;
1887
1883
  if (requirement === void 0) continue;
1888
- const captured = blockSymbol.block.parameters[requirement.parameter];
1889
- if (captured?.kind !== "ref") continue;
1890
- const model = scope.models[captured.identifier];
1891
- if (model === void 0) continue;
1884
+ const target = envelope.values[requirement.parameter];
1885
+ if (!isResolvedModelReference(target)) continue;
1886
+ const model = target.declaration;
1892
1887
  if (model.attributes.some((attribute) => attribute.name === requirement.attribute)) continue;
1893
1888
  input.diagnostics.push({
1894
1889
  code: "PSL_EXTENSION_TARGET_MODEL_MISSING_ATTRIBUTE",
1895
- message: `\`${blockSymbol.keyword}\` block "${blockSymbol.block.name}" targets model "${captured.identifier}", which does not declare \`@@${requirement.attribute}\`. Add \`@@${requirement.attribute}\` to model "${captured.identifier}".`,
1896
- ...diagnosticSource(input.source.sources, blockSymbol.node.syntax).at(captured.span)
1890
+ message: `\`${blockSymbol.keyword}\` block "${envelope.name}" targets model "${model.name}", which does not declare \`@@${requirement.attribute}\`. Add \`@@${requirement.attribute}\` to model "${model.name}".`,
1891
+ ...diagnosticSource(input.sources, blockSymbol.node.syntax).at(envelope.parameterSpans[requirement.parameter] ?? envelope.span)
1897
1892
  });
1898
1893
  }
1899
1894
  }
@@ -1915,77 +1910,29 @@ function buildModelAttributesByName(contributions) {
1915
1910
  return result;
1916
1911
  }
1917
1912
  /**
1918
- * For a single lexical scope (a named PSL namespace, or the document top
1919
- * level), lowers all extension blocks into IR entities via the registered
1920
- * factory for each block's discriminator. Groups results by discriminator
1921
- * (the entries key — one-string rule: discriminator === entries key).
1922
- *
1923
1913
  * This pass is intentionally generic: no discriminator value is named here.
1924
1914
  * The factory (registered by the target pack) owns all block-specific logic.
1925
- * A descriptor's factory output may also opt into value-set derivation via
1926
- * the SQL family's `SqlValueSetDerivingEntityTypeOutput.deriveValueSet` hook
1927
- * (probed by {@link deriveValueSetFromEntity}) — when present, the derived
1928
- * value-set is folded into the namespace's `valueSet` slot (keyed by block
1929
- * name), so a value-set-carrying pack entity (e.g. Postgres `native_enum`)
1930
- * contributes the value-set that drives value-set → codec typing without
1931
- * this pass inspecting a target-specific shape.
1932
- *
1933
- * The `namespaceId` is attached to the block before the factory call so the
1934
- * factory can record the namespace coordinate without the interpreter
1935
- * containing any target-specific knowledge about how namespace ids are used.
1936
- *
1937
- * Ref conversion is this pass's job, over typed data: each block-descriptor
1938
- * parameter declared `{ kind: 'ref', refKind: 'model' }` (same-namespace
1939
- * scope) is resolved to the referenced model's storage table name and
1940
- * attached to the block as `resolvedModelRefs` ({@link ResolvedPslModelRefs})
1941
- * before the factory runs — the factory consumes a resolved coordinate and
1942
- * never looks a model up itself. A required model ref that is missing or
1943
- * does not resolve is this pass's diagnostic; the factory is skipped.
1944
1915
  */
1945
- function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminator, entityContext, pslBlockDescriptors, resolveModelTable, sources, diagnostics) {
1946
- const blockSymbols = Object.values(blocks);
1947
- if (blockSymbols.length === 0) return {};
1948
- const result = {};
1949
- for (const blockSymbol of blockSymbols) {
1950
- const block = blockSymbol.block;
1951
- const descriptor = entityTypesByDiscriminator.get(block.kind);
1916
+ function lowerExtensionBlocksForNamespace(blocks, ownerNamespaceId, entityTypesByDiscriminator, entityContext, parsedBlocks, modelCoordinateOf, sources) {
1917
+ const rows = [];
1918
+ for (const blockSymbol of Object.values(blocks)) {
1919
+ const envelope = parsedBlocks.get(blockSymbol);
1920
+ if (envelope === void 0) continue;
1921
+ const descriptor = entityTypesByDiscriminator.get(envelope.kind);
1952
1922
  if (descriptor === void 0) continue;
1953
- const blockDescriptor = findBlockDescriptor(pslBlockDescriptors, block.keyword);
1954
- let unresolvedRef = false;
1955
1923
  let resolvedModelRefs;
1956
- for (const [paramName, paramDecl] of Object.entries(blockDescriptor?.parameters ?? {})) {
1957
- if (paramDecl.kind !== "ref" || paramDecl.refKind !== "model" || paramDecl.scope !== "same-namespace") continue;
1958
- const captured = block.parameters[paramName];
1959
- if (captured?.kind !== "ref") {
1960
- if (paramDecl.required === true) {
1961
- diagnostics.push({
1962
- code: "PSL_EXTENSION_MODEL_REF_UNRESOLVED",
1963
- message: `\`${block.keyword}\` block "${block.name}" is missing the required \`${paramName}\` model reference.`,
1964
- ...diagnosticSource(sources, blockSymbol.node.syntax).at(block.span)
1965
- });
1966
- unresolvedRef = true;
1967
- }
1968
- continue;
1969
- }
1970
- const tableName = resolveModelTable(captured.identifier);
1971
- if (tableName === void 0) {
1972
- diagnostics.push({
1973
- code: "PSL_EXTENSION_MODEL_REF_UNRESOLVED",
1974
- message: `\`${block.keyword}\` block "${block.name}" references model "${captured.identifier}" in \`${paramName}\`, which is not declared in the same namespace. Declare the model or fix the reference.`,
1975
- ...diagnosticSource(sources, blockSymbol.node.syntax).at(captured.span)
1976
- });
1977
- unresolvedRef = true;
1978
- continue;
1979
- }
1924
+ for (const [paramName, value] of Object.entries(envelope.values)) {
1925
+ if (!isResolvedModelReference(value)) continue;
1926
+ const coordinate = modelCoordinateOf(value.declaration);
1927
+ invariant(coordinate !== void 0, `model mappings cover every collected model; \`${envelope.keyword}\` block "${envelope.name}" selected model "${value.declaration.name}" in \`${paramName}\` without a storage coordinate`);
1980
1928
  resolvedModelRefs = {
1981
1929
  ...resolvedModelRefs ?? {},
1982
- [paramName]: { tableName }
1930
+ [paramName]: coordinate
1983
1931
  };
1984
1932
  }
1985
- if (unresolvedRef) continue;
1986
1933
  const annotatedBlock = {
1987
- ...block,
1988
- namespaceId: nsId,
1934
+ ...envelope,
1935
+ namespaceId: ownerNamespaceId,
1989
1936
  ...resolvedModelRefs !== void 0 ? { resolvedModelRefs } : {}
1990
1937
  };
1991
1938
  const entity = instantiateAuthoringEntityType(descriptor.discriminator, descriptor, [annotatedBlock], {
@@ -1993,18 +1940,22 @@ function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminat
1993
1940
  sourceId: sources.sourceFileFor(blockSymbol.node.syntax).filename
1994
1941
  });
1995
1942
  if (entity === void 0) continue;
1996
- const entriesKey = descriptor.discriminator;
1997
- const slot = result[entriesKey] ?? {};
1998
- result[entriesKey] = slot;
1999
- slot[block.name] = entity;
1943
+ const namespaceId = providesPslEntityPlacement(descriptor.output) ? descriptor.output.pslPlacement(entity).namespaceId : ownerNamespaceId;
1944
+ rows.push({
1945
+ namespaceId,
1946
+ entityKind: descriptor.discriminator,
1947
+ key: envelope.name,
1948
+ entity
1949
+ });
2000
1950
  const derivedValueSet = deriveValueSetFromEntity(descriptor.output, entity);
2001
- if (derivedValueSet !== void 0) {
2002
- const valueSetSlot = result["valueSet"] ?? {};
2003
- result["valueSet"] = valueSetSlot;
2004
- valueSetSlot[block.name] = derivedValueSet;
2005
- }
1951
+ if (derivedValueSet !== void 0) rows.push({
1952
+ namespaceId,
1953
+ entityKind: "valueSet",
1954
+ key: envelope.name,
1955
+ entity: derivedValueSet
1956
+ });
2006
1957
  }
2007
- return result;
1958
+ return rows;
2008
1959
  }
2009
1960
  function processEnumDeclarations(input) {
2010
1961
  const enumHandles = {};
@@ -2015,29 +1966,27 @@ function processEnumDeclarations(input) {
2015
1966
  };
2016
1967
  const enumDescriptor = getAuthoringEntity(input.authoringContributions, ["enum"]);
2017
1968
  if (!enumDescriptor) {
2018
- for (const symbol of input.enumBlocks) {
2019
- const decl = symbol.block;
2020
- input.diagnostics.push({
2021
- code: "PSL_ENUM_MISSING_FACTORY",
2022
- message: `enum "${decl.name}" requires an "enum" entityType factory in the active authoring contributions`,
2023
- ...diagnosticSource(input.source.sources, symbol.node.syntax).at(decl.span)
2024
- });
2025
- }
1969
+ for (const symbol of input.enumBlocks) input.diagnostics.push({
1970
+ code: "PSL_ENUM_MISSING_FACTORY",
1971
+ message: `enum "${symbol.name}" requires an "enum" entityType factory in the active authoring contributions`,
1972
+ ...diagnosticSource(input.source.sources, symbol.node.syntax).at(symbol.span)
1973
+ });
2026
1974
  return {
2027
1975
  enumHandles,
2028
1976
  enumTypeDescriptors
2029
1977
  };
2030
1978
  }
2031
1979
  for (const symbol of input.enumBlocks) {
2032
- const decl = symbol.block;
1980
+ const envelope = input.parsedBlocks.get(symbol);
2033
1981
  input.diagnostics.push(...enumMemberAttributeDiagnostics(symbol, input.source.sources));
2034
- const handle = instantiateAuthoringEntityType("enum", enumDescriptor, [decl], {
1982
+ if (envelope === void 0) continue;
1983
+ const handle = instantiateAuthoringEntityType("enum", enumDescriptor, [envelope], {
2035
1984
  ...input.entityContext,
2036
1985
  sourceId: input.source.sources.sourceFileFor(symbol.node.syntax).filename
2037
1986
  });
2038
1987
  if (handle === void 0 || handle === null) continue;
2039
- enumHandles[decl.name] = handle;
2040
- enumTypeDescriptors.set(decl.name, {
1988
+ enumHandles[envelope.name] = handle;
1989
+ enumTypeDescriptors.set(envelope.name, {
2041
1990
  codecId: handle.codecId,
2042
1991
  nativeType: handle.nativeType
2043
1992
  });
@@ -3109,9 +3058,11 @@ function interpretPslDocumentToSqlContract(input) {
3109
3058
  const composedExtensionNames = new Set(input.composedExtensions ?? []);
3110
3059
  const modelAttributesByName = buildModelAttributesByName(input.authoringContributions);
3111
3060
  const contributedModelSpecs = modelAttributeSpecsFrom(modelAttributesByName);
3061
+ const composedPslBlockDescriptors = input.authoringContributions?.pslBlockDescriptors ?? {};
3112
3062
  const { binder, diagnostics: binderDiagnostics } = createSqlBinder({
3113
3063
  symbolTable: input.symbolTable,
3114
3064
  sources: input.sources,
3065
+ pslBlockDescriptors: composedPslBlockDescriptors,
3115
3066
  authoringContributions: input.authoringContributions,
3116
3067
  controlMutationDefaults: {
3117
3068
  defaultFunctionRegistry: input.controlMutationDefaults?.defaultFunctionRegistry ?? /* @__PURE__ */ new Map(),
@@ -3142,10 +3093,17 @@ function interpretPslDocumentToSqlContract(input) {
3142
3093
  binder,
3143
3094
  diagnostics
3144
3095
  });
3096
+ const { parsedBlocks, diagnostics: blockDiagnostics } = interpretExtensionBlocks({
3097
+ symbolTable: input.symbolTable,
3098
+ sources: input.sources,
3099
+ pslBlockDescriptors: composedPslBlockDescriptors,
3100
+ binder
3101
+ });
3102
+ diagnostics.push(...blockDiagnostics);
3145
3103
  validateBlockModelAttributeRequirements({
3146
- scopes: [topLevel, ...namespaceSymbols],
3147
- pslBlockDescriptors: input.authoringContributions?.pslBlockDescriptors ?? {},
3148
- source,
3104
+ parsedBlocks,
3105
+ pslBlockDescriptors: composedPslBlockDescriptors,
3106
+ sources: input.sources,
3149
3107
  diagnostics
3150
3108
  });
3151
3109
  const models = [];
@@ -3210,6 +3168,7 @@ function interpretPslDocumentToSqlContract(input) {
3210
3168
  }
3211
3169
  const enumResult = processEnumDeclarations({
3212
3170
  enumBlocks: topLevelEnums,
3171
+ parsedBlocks,
3213
3172
  source,
3214
3173
  authoringContributions: input.authoringContributions,
3215
3174
  entityContext: {
@@ -3241,35 +3200,38 @@ function interpretPslDocumentToSqlContract(input) {
3241
3200
  warnings: authoringWarnings
3242
3201
  };
3243
3202
  const earlyModelMappingsByCoordinate = buildModelMappings(input.symbolTable, modelEntries, defaultNamespaceId, createPslDiagnosticCollector(input.sources), input.sources, binder);
3244
- const composedPslBlockDescriptors = input.authoringContributions?.pslBlockDescriptors ?? {};
3203
+ const modelCoordinates = /* @__PURE__ */ new Map();
3204
+ for (const entry of modelEntries) {
3205
+ const nsId = entry.namespaceId ?? defaultNamespaceId;
3206
+ const mapping = earlyModelMappingsByCoordinate.get(modelCoordinateKey(nsId, entry.model.name));
3207
+ if (mapping !== void 0) modelCoordinates.set(entry.model, {
3208
+ namespaceId: nsId,
3209
+ tableName: mapping.tableName
3210
+ });
3211
+ }
3212
+ const modelCoordinateOf = (model) => modelCoordinates.get(model);
3245
3213
  const namespaceExtensionEntities = /* @__PURE__ */ new Map();
3246
- const mergeNamespaceExtensionEntities = (nsId, entities, blocks) => {
3247
- if (Object.keys(entities).length === 0) return;
3248
- const existing = namespaceExtensionEntities.get(nsId);
3249
- if (existing === void 0) {
3250
- namespaceExtensionEntities.set(nsId, entities);
3251
- return;
3252
- }
3253
- const merged = { ...existing };
3254
- for (const [entriesKey, slot] of Object.entries(entities)) {
3255
- const existingSlot = existing[entriesKey];
3256
- if (existingSlot !== void 0) {
3257
- for (const name of Object.keys(slot)) if (Object.hasOwn(existingSlot, name)) {
3258
- const block = Object.values(blocks).find((block) => block.name === name);
3259
- invariant(block !== void 0, "Lowered entity has an owning block");
3260
- diagnostics.pushUnlocated({
3261
- code: "PSL_DUPLICATE_EXTENSION_ENTITY",
3262
- message: `entries slot "${entriesKey}" in namespace "${nsId}": entity "${name}" is declared more than once in the same namespace.`,
3263
- ...diagnosticSource(input.sources, block.node.syntax).at()
3264
- });
3265
- }
3214
+ const fileExtensionEntityRows = (rows, blocks) => {
3215
+ for (const row of rows) {
3216
+ let entities = namespaceExtensionEntities.get(row.namespaceId);
3217
+ if (entities === void 0) {
3218
+ entities = {};
3219
+ namespaceExtensionEntities.set(row.namespaceId, entities);
3266
3220
  }
3267
- merged[entriesKey] = {
3268
- ...existingSlot,
3269
- ...slot
3270
- };
3221
+ const slot = entities[row.entityKind] ?? {};
3222
+ entities[row.entityKind] = slot;
3223
+ if (Object.hasOwn(slot, row.key)) {
3224
+ const block = Object.values(blocks).find((candidate) => candidate.name === row.key);
3225
+ invariant(block !== void 0, "Lowered entity has an owning block");
3226
+ diagnostics.pushUnlocated({
3227
+ code: "PSL_DUPLICATE_EXTENSION_ENTITY",
3228
+ message: `entries slot "${row.entityKind}" in namespace "${row.namespaceId}": entity "${row.key}" is declared more than once in the same namespace.`,
3229
+ ...diagnosticSource(input.sources, block.node.syntax).at()
3230
+ });
3231
+ continue;
3232
+ }
3233
+ slot[row.key] = row.entity;
3271
3234
  }
3272
- namespaceExtensionEntities.set(nsId, merged);
3273
3235
  };
3274
3236
  for (const ns of namespaceSymbols) {
3275
3237
  if (ns.name === UNSPECIFIED_PSL_NAMESPACE_ID) continue;
@@ -3278,15 +3240,12 @@ function interpretPslDocumentToSqlContract(input) {
3278
3240
  targetId: input.target.targetId
3279
3241
  });
3280
3242
  if (nsId === void 0) continue;
3281
- mergeNamespaceExtensionEntities(nsId, lowerExtensionBlocksForNamespace(ns.blocks, nsId, entityTypesByDiscriminator, extensionEntityContext, composedPslBlockDescriptors, (modelName) => earlyModelMappingsByCoordinate.get(modelCoordinateKey(nsId, modelName))?.tableName, input.sources, diagnostics), ns.blocks);
3282
- }
3283
- if (Object.keys(topLevelExtensionBlocks).length > 0) {
3284
- const topLevelNsId = resolveNamespaceIdForSqlTarget({
3285
- bucketName: UNSPECIFIED_PSL_NAMESPACE_ID,
3286
- targetId: input.target.targetId
3287
- }) ?? defaultNamespaceId;
3288
- mergeNamespaceExtensionEntities(topLevelNsId, lowerExtensionBlocksForNamespace(topLevelExtensionBlocks, topLevelNsId, entityTypesByDiscriminator, extensionEntityContext, composedPslBlockDescriptors, (modelName) => earlyModelMappingsByCoordinate.get(modelCoordinateKey(topLevelNsId, modelName))?.tableName, input.sources, diagnostics), topLevelExtensionBlocks);
3243
+ fileExtensionEntityRows(lowerExtensionBlocksForNamespace(ns.blocks, nsId, entityTypesByDiscriminator, extensionEntityContext, parsedBlocks, modelCoordinateOf, input.sources), ns.blocks);
3289
3244
  }
3245
+ if (Object.keys(topLevelExtensionBlocks).length > 0) fileExtensionEntityRows(lowerExtensionBlocksForNamespace(topLevelExtensionBlocks, resolveNamespaceIdForSqlTarget({
3246
+ bucketName: UNSPECIFIED_PSL_NAMESPACE_ID,
3247
+ targetId: input.target.targetId
3248
+ }) ?? defaultNamespaceId, entityTypesByDiscriminator, extensionEntityContext, parsedBlocks, modelCoordinateOf, input.sources), topLevelExtensionBlocks);
3290
3249
  const defaultNsExtensionValueSets = namespaceExtensionEntities.get(defaultNamespaceId)?.["valueSet"];
3291
3250
  if (defaultNsExtensionValueSets !== void 0) {
3292
3251
  for (const name of Object.keys(defaultNsExtensionValueSets)) if (Object.hasOwn(validEnumHandles, name)) {
@@ -3356,7 +3315,8 @@ function interpretPslDocumentToSqlContract(input) {
3356
3315
  ...ifDefined("codecLookup", input.codecLookup),
3357
3316
  modelAttributesByName,
3358
3317
  contributedModelAttributeSpecs: contributedModelSpecs,
3359
- defaultNamespaceId
3318
+ defaultNamespaceId,
3319
+ parsedBlocks
3360
3320
  });
3361
3321
  modelNodes.push(namespaceId !== void 0 ? {
3362
3322
  ...result.modelNode,
@@ -3518,4 +3478,4 @@ function interpretPslDocumentToSqlContract(input) {
3518
3478
  //#endregion
3519
3479
  export { interpretPslDocumentToSqlContract as a, resolveFieldTypeDescriptor as c, indexFkRelations as i, buildEntityTypesByDiscriminator as n, normalizeReferentialAction as o, entryForTag as r, readDataTypeDefault as s, applyBackrelationCandidates as t };
3520
3480
 
3521
- //# sourceMappingURL=interpreter-BrW0_y8Q-ChkFlzaN.mjs.map
3481
+ //# sourceMappingURL=interpreter-BMMGMTBa-CT5iKl13.mjs.map