@prisma/orm-family-sql 8.0.0-rc.11-dev.33 → 8.0.0-rc.11-dev.34

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 (41) hide show
  1. package/dist/contract-prisma7__provider.mjs +58 -44
  2. package/dist/contract-prisma7__provider.mjs.map +1 -1
  3. package/dist/contract-psl.d.mts +5 -5
  4. package/dist/contract-psl.d.mts.map +1 -1
  5. package/dist/contract-psl.mjs +1 -1
  6. package/dist/contract-psl__attribute-specs.d.mts +2 -2
  7. package/dist/contract-psl__attribute-specs.d.mts.map +1 -1
  8. package/dist/contract-psl__attribute-specs.mjs +1 -1
  9. package/dist/contract-psl__provider.mjs +11 -20
  10. package/dist/contract-psl__provider.mjs.map +1 -1
  11. package/dist/{control-BICEwXxs.mjs → control-liGaqQ0q.mjs} +26 -27
  12. package/dist/control-liGaqQ0q.mjs.map +1 -0
  13. package/dist/diff-B16bL_IR.mjs.map +1 -1
  14. package/dist/family.mjs +5 -5
  15. package/dist/family__control.mjs +2 -2
  16. package/dist/family__diff.mjs +1 -1
  17. package/dist/family__ir.mjs +1 -1
  18. package/dist/family__pack.mjs +1 -1
  19. package/dist/family__psl-infer.mjs +1 -1
  20. package/dist/family__verify.mjs +1 -1
  21. package/dist/{interpreter-9Ru2E-MH-CQdWmnh8.mjs → interpreter-C8N5eRW1-LGv-WI9y.mjs} +280 -336
  22. package/dist/interpreter-C8N5eRW1-LGv-WI9y.mjs.map +1 -0
  23. package/dist/ir-I-xciGUH.mjs.map +1 -1
  24. package/dist/{psl-infer-DyRJ8dw6.mjs → psl-infer-CsCbcmXS.mjs} +4 -2
  25. package/dist/psl-infer-CsCbcmXS.mjs.map +1 -0
  26. package/dist/{schema-verify-C_PEdlAr-CmXrFuW1.mjs → schema-verify-CrvQZ5V8-BfrNHJbX.mjs} +3 -3
  27. package/dist/schema-verify-CrvQZ5V8-BfrNHJbX.mjs.map +1 -0
  28. package/dist/{sql-attribute-specs-CHSP1wKs-D5T2TZQ8.mjs → sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs} +11 -16
  29. package/dist/sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs.map +1 -0
  30. package/dist/{sql-contract-serializer-Bxu4a5oQ-CNy5ONMn.mjs → sql-contract-serializer-C4HbCKFe-BD1Fx4JX.mjs} +6 -6
  31. package/dist/sql-contract-serializer-C4HbCKFe-BD1Fx4JX.mjs.map +1 -0
  32. package/dist/{verify-ChiDeTk8-HEewdjrM.mjs → verify-BVk5bjdH-BXgGLM2U.mjs} +6 -5
  33. package/dist/verify-BVk5bjdH-BXgGLM2U.mjs.map +1 -0
  34. package/package.json +18 -18
  35. package/dist/control-BICEwXxs.mjs.map +0 -1
  36. package/dist/interpreter-9Ru2E-MH-CQdWmnh8.mjs.map +0 -1
  37. package/dist/psl-infer-DyRJ8dw6.mjs.map +0 -1
  38. package/dist/schema-verify-C_PEdlAr-CmXrFuW1.mjs.map +0 -1
  39. package/dist/sql-attribute-specs-CHSP1wKs-D5T2TZQ8.mjs.map +0 -1
  40. package/dist/sql-contract-serializer-Bxu4a5oQ-CNy5ONMn.mjs.map +0 -1
  41. package/dist/verify-ChiDeTk8-HEewdjrM.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { t as deriveValueSetFromEntity } from "./value-set-derivation-hook-Di9JZ0X7.mjs";
2
2
  import { n as buildSqlContractFromDefinition } from "./derived-checks-DGjY5t7S-DofD5V_2.mjs";
3
- import { a as interpretFieldAttribute, i as findModelAttributeNode, n as fieldSpecContext, o as interpretModelAttribute, r as findFieldAttributeNode, s as sqlAttributeSpecs, t as PSL_CHECK_ON_STI_VARIANT } from "./sql-attribute-specs-CHSP1wKs-D5T2TZQ8.mjs";
3
+ import { a as interpretFieldAttribute, i as findModelAttributeNode, n as fieldSpecContext, o as interpretModelAttribute, r as findFieldAttributeNode, s as sqlAttributeSpecs, t as PSL_CHECK_ON_STI_VARIANT } from "./sql-attribute-specs-DAEpjrWl-C0kmaUJt.mjs";
4
4
  import { t as defaultTableName } from "./default-table-name-BfFY8qYR-lHNcVmY5.mjs";
5
5
  import { structuredError } from "@prisma/orm-framework/utils/structured-error";
6
6
  import { hasRegisteredFieldNamespace, instantiateAuthoringEntityType, instantiateAuthoringFieldPreset, instantiateAuthoringTypeConstructor, isAuthoringEntityTypeDescriptor, isAuthoringFieldPresetDescriptor, isAuthoringModelAttributeDescriptor, isAuthoringPslBlockDescriptor, isAuthoringTypeConstructorDescriptor, validateAuthoringHelperArguments } from "@prisma/orm-framework/components/authoring";
@@ -9,13 +9,13 @@ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
9
9
  import { crossRef } from "@prisma/orm-framework/contract/types";
10
10
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
11
11
  import { blindCast } from "@prisma/orm-framework/utils/casts";
12
- import { findBlockDescriptor, keywordPslSpan, nodePslSpan } from "@prisma/orm-framework/psl-parser";
13
12
  import { resolveToOneRelationNullable } from "@prisma/orm-framework/contract-authoring";
14
13
  import { assertDefined, invariant } from "@prisma/orm-framework/utils/assertions";
15
14
  import { describeTaggedLiteralFailure } from "@prisma/orm-framework/components/control";
16
15
  import { notOk, ok } from "@prisma/orm-framework/utils/result";
16
+ import { createPslDiagnosticCollector, diagnosticSource, findBlockDescriptor, keywordPslSpan, nodePslSpan } from "@prisma/orm-framework/psl-parser";
17
17
  import { consumeInvalidFkPairing, fkRelationPairKey, requiredOneToOneBackrelationDiagnostic } from "@prisma/orm-framework/psl-parser/interpret";
18
- //#region ../../../2-sql/2-authoring/contract-psl/dist/interpreter-9Ru2E-MH.mjs
18
+ //#region ../../../2-sql/2-authoring/contract-psl/dist/interpreter-C8N5eRW1.mjs
19
19
  function contractError(code, message, options) {
20
20
  return structuredError(code, message, options);
21
21
  }
@@ -47,8 +47,7 @@ function mapFieldNamesToColumns(input) {
47
47
  input.diagnostics.push({
48
48
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
49
49
  message: `${input.entityLabel} references unknown field "${input.modelName}.${fieldName}"`,
50
- sourceId: input.sourceId,
51
- span: input.span
50
+ ...input.source.at(input.span)
52
51
  });
53
52
  return;
54
53
  }
@@ -65,18 +64,24 @@ function formatSupportedFunctionList(registry) {
65
64
  }
66
65
  function lowerDefaultFunctionWithRegistry(input) {
67
66
  const entry = input.registry.get(input.call.fn);
68
- if (entry) return entry.lower({
69
- call: input.call,
70
- context: input.context
71
- });
67
+ if (entry) {
68
+ const result = entry.lower({
69
+ call: input.call,
70
+ context: input.context
71
+ });
72
+ return result.ok ? result : {
73
+ ...result,
74
+ kind: "external"
75
+ };
76
+ }
72
77
  const supportedFunctionList = formatSupportedFunctionList(input.registry);
73
78
  return {
74
79
  ok: false,
80
+ kind: "owned",
75
81
  diagnostic: {
76
82
  code: "PSL_UNKNOWN_DEFAULT_FUNCTION",
77
83
  message: `Default function "${input.call.fn}" is not supported in SQL PSL provider v1. Supported functions: ${supportedFunctionList}.`,
78
- sourceId: input.context.sourceId,
79
- span: input.call.span
84
+ ...input.source.at(input.call.span)
80
85
  }
81
86
  };
82
87
  }
@@ -326,8 +331,7 @@ function pushInvalidPslHelperArgument(input) {
326
331
  input.diagnostics.push({
327
332
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
328
333
  message: `${input.entityLabel} ${input.helperLabel} ${input.message}`,
329
- sourceId: input.sourceId,
330
- span: input.span
334
+ ...input.source.at(input.span)
331
335
  });
332
336
  }
333
337
  function mapPslHelperArgs(input) {
@@ -336,7 +340,7 @@ function mapPslHelperArgs(input) {
336
340
  const namedArgs = input.args.filter((arg) => arg.kind === "named");
337
341
  if (positionalArgs.length > input.descriptors.length) return pushInvalidPslHelperArgument({
338
342
  diagnostics: input.diagnostics,
339
- sourceId: input.sourceId,
343
+ source: input.source,
340
344
  span: input.span,
341
345
  entityLabel: input.entityLabel,
342
346
  helperLabel: input.helperLabel,
@@ -346,7 +350,7 @@ function mapPslHelperArgs(input) {
346
350
  const descriptor = input.descriptors[index];
347
351
  if (!descriptor) return pushInvalidPslHelperArgument({
348
352
  diagnostics: input.diagnostics,
349
- sourceId: input.sourceId,
353
+ source: input.source,
350
354
  span: argument.span,
351
355
  entityLabel: input.entityLabel,
352
356
  helperLabel: input.helperLabel,
@@ -355,7 +359,7 @@ function mapPslHelperArgs(input) {
355
359
  const value = parsePslAuthoringArgumentValue(descriptor, argument.value);
356
360
  if (value === INVALID_AUTHORING_ARGUMENT) return pushInvalidPslHelperArgument({
357
361
  diagnostics: input.diagnostics,
358
- sourceId: input.sourceId,
362
+ source: input.source,
359
363
  span: argument.span,
360
364
  entityLabel: input.entityLabel,
361
365
  helperLabel: input.helperLabel,
@@ -367,7 +371,7 @@ function mapPslHelperArgs(input) {
367
371
  const descriptorIndex = input.descriptors.findIndex((descriptor) => descriptor.name === argument.name);
368
372
  if (descriptorIndex < 0) return pushInvalidPslHelperArgument({
369
373
  diagnostics: input.diagnostics,
370
- sourceId: input.sourceId,
374
+ source: input.source,
371
375
  span: argument.span,
372
376
  entityLabel: input.entityLabel,
373
377
  helperLabel: input.helperLabel,
@@ -375,7 +379,7 @@ function mapPslHelperArgs(input) {
375
379
  });
376
380
  if (mappedArgs[descriptorIndex] !== void 0) return pushInvalidPslHelperArgument({
377
381
  diagnostics: input.diagnostics,
378
- sourceId: input.sourceId,
382
+ source: input.source,
379
383
  span: argument.span,
380
384
  entityLabel: input.entityLabel,
381
385
  helperLabel: input.helperLabel,
@@ -384,7 +388,7 @@ function mapPslHelperArgs(input) {
384
388
  const descriptor = input.descriptors[descriptorIndex];
385
389
  if (!descriptor) return pushInvalidPslHelperArgument({
386
390
  diagnostics: input.diagnostics,
387
- sourceId: input.sourceId,
391
+ source: input.source,
388
392
  span: argument.span,
389
393
  entityLabel: input.entityLabel,
390
394
  helperLabel: input.helperLabel,
@@ -393,7 +397,7 @@ function mapPslHelperArgs(input) {
393
397
  const value = parsePslAuthoringArgumentValue(descriptor, argument.value);
394
398
  if (value === INVALID_AUTHORING_ARGUMENT) return pushInvalidPslHelperArgument({
395
399
  diagnostics: input.diagnostics,
396
- sourceId: input.sourceId,
400
+ source: input.source,
397
401
  span: argument.span,
398
402
  entityLabel: input.entityLabel,
399
403
  helperLabel: input.helperLabel,
@@ -477,8 +481,7 @@ function reportUncomposedNamespace(input) {
477
481
  input.diagnostics.push({
478
482
  code: "PSL_EXTENSION_NAMESPACE_NOT_COMPOSED",
479
483
  message: `${input.subjectLabel} uses unrecognized namespace "${input.namespace}". Add extension pack "${input.namespace}" to extensions in prisma.config.ts.`,
480
- sourceId: input.sourceId,
481
- span: input.span,
484
+ ...input.source.at(input.span),
482
485
  data: {
483
486
  namespace: input.namespace,
484
487
  suggestedPack: input.namespace
@@ -492,8 +495,7 @@ function reportUnknownFieldPreset(input) {
492
495
  input.diagnostics.push({
493
496
  code: "PSL_UNKNOWN_FIELD_PRESET",
494
497
  message: `${input.entityLabel} references unknown field preset "${input.helperPath}". Check the spelling against the available presets in the "${input.namespace}" namespace.`,
495
- sourceId: input.sourceId,
496
- span: input.span,
498
+ ...input.source.at(input.span),
497
499
  data: {
498
500
  namespace: input.namespace,
499
501
  helperPath: input.helperPath
@@ -508,7 +510,7 @@ function instantiatePslTypeConstructor(input) {
508
510
  helperLabel: `constructor "${helperPath}"`,
509
511
  span: input.call.span,
510
512
  diagnostics: input.diagnostics,
511
- sourceId: input.sourceId,
513
+ source: input.source,
512
514
  entityLabel: input.entityLabel
513
515
  });
514
516
  if (!args) return;
@@ -520,8 +522,7 @@ function instantiatePslTypeConstructor(input) {
520
522
  input.diagnostics.push({
521
523
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
522
524
  message: `${input.entityLabel} constructor "${helperPath}" ${message}`,
523
- sourceId: input.sourceId,
524
- span: input.call.span
525
+ ...input.source.at(input.call.span)
525
526
  });
526
527
  return;
527
528
  }
@@ -530,8 +531,7 @@ function pushUnsupportedTypeConstructorDiagnostic(input) {
530
531
  input.diagnostics.push({
531
532
  code: input.code,
532
533
  message: input.message,
533
- sourceId: input.sourceId,
534
- span: input.span
534
+ ...input.source.at(input.span)
535
535
  });
536
536
  }
537
537
  function resolvePslTypeConstructorDescriptor(input) {
@@ -546,7 +546,7 @@ function resolvePslTypeConstructorDescriptor(input) {
546
546
  reportUncomposedNamespace({
547
547
  subjectLabel: `Type constructor "${input.call.path.join(".")}"`,
548
548
  namespace: uncomposedNamespace,
549
- sourceId: input.sourceId,
549
+ source: input.source,
550
550
  span: input.call.span,
551
551
  diagnostics: input.diagnostics
552
552
  });
@@ -554,7 +554,7 @@ function resolvePslTypeConstructorDescriptor(input) {
554
554
  }
555
555
  return pushUnsupportedTypeConstructorDiagnostic({
556
556
  diagnostics: input.diagnostics,
557
- sourceId: input.sourceId,
557
+ source: input.source,
558
558
  span: input.call.span,
559
559
  code: input.unsupportedCode,
560
560
  message: input.unsupportedMessage
@@ -573,7 +573,7 @@ function instantiateFieldPreset(input) {
573
573
  helperLabel: `preset "${helperPath}"`,
574
574
  span: input.call.span,
575
575
  diagnostics: input.diagnostics,
576
- sourceId: input.sourceId,
576
+ source: input.source,
577
577
  entityLabel: input.entityLabel
578
578
  });
579
579
  if (!args) return;
@@ -597,8 +597,7 @@ function instantiateFieldPreset(input) {
597
597
  input.diagnostics.push({
598
598
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
599
599
  message: `${input.entityLabel} preset "${helperPath}" ${message}`,
600
- sourceId: input.sourceId,
601
- span: input.call.span
600
+ ...input.source.at(input.call.span)
602
601
  });
603
602
  return;
604
603
  }
@@ -636,8 +635,7 @@ function resolveEntityRefTypeConstructorCall(input) {
636
635
  input.diagnostics.push({
637
636
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
638
637
  message: `${input.entityLabel} type constructor "${helperPath}" expects exactly one positional argument naming the referenced entity`,
639
- sourceId: input.sourceId,
640
- span: input.call.span
638
+ ...input.source.at(input.call.span)
641
639
  });
642
640
  return {
643
641
  ok: false,
@@ -648,8 +646,7 @@ function resolveEntityRefTypeConstructorCall(input) {
648
646
  input.diagnostics.push({
649
647
  code: "PSL_UNKNOWN_ENTITY_REF",
650
648
  message: `${input.entityLabel} type constructor "${helperPath}(${ref})" does not resolve — no entity named "${ref}" was found in namespace "${input.namespaceId ?? "(unspecified)"}"`,
651
- sourceId: input.sourceId,
652
- span: input.call.span
649
+ ...input.source.at(input.call.span)
653
650
  });
654
651
  return {
655
652
  ok: false,
@@ -671,8 +668,7 @@ function resolveEntityRefTypeConstructorCall(input) {
671
668
  input.diagnostics.push({
672
669
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
673
670
  message: `${input.entityLabel} type constructor "${helperPath}(${ref})" resolves to a value-set-typed entity, but the field has no resolvable namespace to scope the value-set ref to`,
674
- sourceId: input.sourceId,
675
- span: input.call.span
671
+ ...input.source.at(input.call.span)
676
672
  });
677
673
  return {
678
674
  ok: false,
@@ -696,6 +692,7 @@ function resolveEntityRefTypeConstructorCall(input) {
696
692
  };
697
693
  }
698
694
  function resolveFieldTypeDescriptor(input) {
695
+ const source = diagnosticSource(input.sources, input.field.node.syntax);
699
696
  if (input.field.malformedType) return {
700
697
  ok: false,
701
698
  alreadyReported: true
@@ -707,7 +704,7 @@ function resolveFieldTypeDescriptor(input) {
707
704
  call: input.field.typeConstructor,
708
705
  descriptor: presetDescriptor,
709
706
  diagnostics: input.diagnostics,
710
- sourceId: input.sourceId,
707
+ source,
711
708
  entityLabel: input.entityLabel
712
709
  });
713
710
  if (!instantiated) return {
@@ -737,7 +734,7 @@ function resolveFieldTypeDescriptor(input) {
737
734
  namespaceExtensionEntities: input.namespaceExtensionEntities,
738
735
  codecLookup: input.codecLookup,
739
736
  diagnostics: input.diagnostics,
740
- sourceId: input.sourceId,
737
+ source,
741
738
  entityLabel: input.entityLabel
742
739
  });
743
740
  if (!typeDescriptor && namespacePrefix && hasRegisteredFieldNamespace(input.authoringContributions, namespacePrefix)) {
@@ -745,7 +742,7 @@ function resolveFieldTypeDescriptor(input) {
745
742
  entityLabel: input.entityLabel,
746
743
  namespace: namespacePrefix,
747
744
  helperPath,
748
- sourceId: input.sourceId,
745
+ source,
749
746
  span: input.field.typeConstructor.span,
750
747
  diagnostics: input.diagnostics
751
748
  });
@@ -761,7 +758,7 @@ function resolveFieldTypeDescriptor(input) {
761
758
  familyId: input.familyId,
762
759
  targetId: input.targetId,
763
760
  diagnostics: input.diagnostics,
764
- sourceId: input.sourceId,
761
+ source,
765
762
  unsupportedCode: "PSL_UNSUPPORTED_FIELD_TYPE",
766
763
  unsupportedMessage: `${input.entityLabel} type constructor "${helperPath}" is not supported in SQL PSL provider v1`
767
764
  });
@@ -773,7 +770,7 @@ function resolveFieldTypeDescriptor(input) {
773
770
  call: input.field.typeConstructor,
774
771
  descriptor,
775
772
  diagnostics: input.diagnostics,
776
- sourceId: input.sourceId,
773
+ source,
777
774
  entityLabel: input.entityLabel
778
775
  });
779
776
  if (!instantiated) return {
@@ -799,21 +796,21 @@ const TAGGED_LITERAL_CANONICALIZATION_CODES = {
799
796
  nul: "PSL_TAGGED_LITERAL_NUL",
800
797
  "too-large": "PSL_TAGGED_LITERAL_TOO_LARGE"
801
798
  };
802
- function lowerTaggedLiteral(literal, registry, context) {
799
+ function lowerTaggedLiteral(literal, registry, context, source) {
803
800
  const reject = (code, message) => ({
804
801
  ok: false,
802
+ kind: "owned",
805
803
  diagnostic: {
806
804
  code,
807
805
  message,
808
- sourceId: context.sourceId,
809
- span: literal.span
806
+ ...source.at(literal.span)
810
807
  }
811
808
  });
812
809
  const entry = registry.get(literal.tag);
813
810
  if (entry === void 0) return reject("PSL_UNKNOWN_DEFAULT_LITERAL_TAG", `Unknown literal tag "${literal.tag}". Known tags: ${[...registry.keys()].join(", ")}.`);
814
811
  const { canonicalization } = literal;
815
812
  if (!canonicalization.ok) return reject(TAGGED_LITERAL_CANONICALIZATION_CODES[canonicalization.reason], describeTaggedLiteralFailure(canonicalization.reason));
816
- return entry.lower({
813
+ const result = entry.lower({
817
814
  literal: {
818
815
  tag: literal.tag,
819
816
  body: canonicalization.body,
@@ -821,10 +818,15 @@ function lowerTaggedLiteral(literal, registry, context) {
821
818
  },
822
819
  context
823
820
  });
821
+ return result.ok ? result : {
822
+ ...result,
823
+ kind: "external"
824
+ };
824
825
  }
825
826
  function lowerDefaultForField(input) {
826
827
  const node = findFieldAttributeNode(input.field, "default");
827
828
  if (node === void 0) return {};
829
+ const source = diagnosticSource(input.sources, node.syntax);
828
830
  const interpreted = interpretFieldAttribute({
829
831
  node,
830
832
  spec: sqlAttributeSpecs.field.default(fieldSpecContext({
@@ -838,8 +840,7 @@ function lowerDefaultForField(input) {
838
840
  })),
839
841
  model: input.model,
840
842
  field: input.field,
841
- sourceFile: input.sourceFile,
842
- sourceId: input.sourceId,
843
+ sources: input.sources,
843
844
  diagnostics: input.diagnostics
844
845
  });
845
846
  if (interpreted === void 0) return {};
@@ -855,18 +856,20 @@ function lowerDefaultForField(input) {
855
856
  } };
856
857
  if (typeof value === "object") {
857
858
  const context = {
858
- sourceId: input.sourceId,
859
+ sourceId: input.sources.sourceFileFor(node.syntax).filename,
859
860
  modelName: input.modelName,
860
861
  fieldName: input.fieldName,
861
862
  columnCodecId: input.columnDescriptor.codecId
862
863
  };
863
- const lowered = "tag" in value ? lowerTaggedLiteral(value, input.defaultLiteralTagRegistry, context) : lowerDefaultFunctionWithRegistry({
864
+ const lowered = "tag" in value ? lowerTaggedLiteral(value, input.defaultLiteralTagRegistry, context, source) : lowerDefaultFunctionWithRegistry({
864
865
  call: value,
865
866
  registry: input.defaultFunctionRegistry,
866
- context
867
+ context,
868
+ source
867
869
  });
868
870
  if (!lowered.ok) {
869
- input.diagnostics.push(lowered.diagnostic);
871
+ if (lowered.kind === "owned") input.diagnostics.push(lowered.diagnostic);
872
+ else input.diagnostics.pushExternal(lowered.diagnostic);
870
873
  return {};
871
874
  }
872
875
  if (lowered.value.kind === "storage") return { defaultValue: lowered.value.defaultValue };
@@ -875,8 +878,7 @@ function lowerDefaultForField(input) {
875
878
  input.diagnostics.push({
876
879
  code: "PSL_INVALID_DEFAULT_APPLICABILITY",
877
880
  message: `Default generator "${lowered.value.generated.id}" is not available in the composed mutation default registry.`,
878
- sourceId: input.sourceId,
879
- span: value.span
881
+ ...source.at(value.span)
880
882
  });
881
883
  return {};
882
884
  }
@@ -884,8 +886,7 @@ function lowerDefaultForField(input) {
884
886
  input.diagnostics.push({
885
887
  code: "PSL_INVALID_DEFAULT_APPLICABILITY",
886
888
  message: `Default generator "${generatorDescriptor.id}" is not applicable to "@default(...)" lowering. Use the corresponding field preset (e.g. \`temporal.${generatorDescriptor.id === "timestampNow" ? "updatedAt" : generatorDescriptor.id}()\`) instead.`,
887
- sourceId: input.sourceId,
888
- span: value.span
889
+ ...source.at(value.span)
889
890
  });
890
891
  return {};
891
892
  }
@@ -893,8 +894,7 @@ function lowerDefaultForField(input) {
893
894
  input.diagnostics.push({
894
895
  code: "PSL_INVALID_DEFAULT_APPLICABILITY",
895
896
  message: `Default generator "${generatorDescriptor.id}" is not applicable to "${input.modelName}.${input.fieldName}" with codecId "${input.columnDescriptor.codecId}".`,
896
- sourceId: input.sourceId,
897
- span: value.span
897
+ ...source.at(value.span)
898
898
  });
899
899
  return {};
900
900
  }
@@ -911,7 +911,7 @@ function resolveColumnDescriptor(field, enumTypeDescriptors, namedTypeDescriptor
911
911
  return scalarColumnDescriptors.get(field.typeName);
912
912
  }
913
913
  function lowerEnumDefaultForField(input) {
914
- const { field, model, sourceFile, enumHandle, sourceId, diagnostics } = input;
914
+ const { field, model, enumHandle, diagnostics } = input;
915
915
  const node = findFieldAttributeNode(field, "default");
916
916
  if (node === void 0) return {};
917
917
  if (enumHandle.enumMembers.length === 0) return {};
@@ -928,8 +928,7 @@ function lowerEnumDefaultForField(input) {
928
928
  })),
929
929
  model,
930
930
  field,
931
- sourceFile,
932
- sourceId,
931
+ sources: input.sources,
933
932
  diagnostics
934
933
  });
935
934
  if (interpreted === void 0) return {};
@@ -961,8 +960,7 @@ function validateFieldAttributes(input) {
961
960
  input.diagnostics.push({
962
961
  code: "PSL_UNSUPPORTED_FIELD_ATTRIBUTE",
963
962
  message: formatDbAttributeMigrationMessage(attribute),
964
- sourceId: input.sourceId,
965
- span: attribute.span
963
+ ...diagnosticSource(input.sources, input.field.node.syntax).at(attribute.span)
966
964
  });
967
965
  continue;
968
966
  }
@@ -975,7 +973,7 @@ function validateFieldAttributes(input) {
975
973
  reportUncomposedNamespace({
976
974
  subjectLabel: `Attribute "@${attribute.name}"`,
977
975
  namespace: uncomposedNamespace,
978
- sourceId: input.sourceId,
976
+ source: diagnosticSource(input.sources, input.field.node.syntax),
979
977
  span: attribute.span,
980
978
  diagnostics: input.diagnostics
981
979
  });
@@ -987,8 +985,7 @@ function validateFieldAttributes(input) {
987
985
  input.diagnostics.push({
988
986
  code: "PSL_UNSUPPORTED_FIELD_ATTRIBUTE",
989
987
  message,
990
- sourceId: input.sourceId,
991
- span: attribute.span
988
+ ...diagnosticSource(input.sources, input.field.node.syntax).at(attribute.span)
992
989
  });
993
990
  }
994
991
  }
@@ -1001,8 +998,7 @@ function extractFieldConstraintNames(input) {
1001
998
  spec: sqlAttributeSpecs.field.id(),
1002
999
  model: input.model,
1003
1000
  field: input.field,
1004
- sourceFile: input.sourceFile,
1005
- sourceId: input.sourceId,
1001
+ sources: input.sources,
1006
1002
  diagnostics: input.diagnostics
1007
1003
  })?.map;
1008
1004
  const uniqueNode = findFieldAttributeNode(input.field, "unique");
@@ -1015,8 +1011,7 @@ function extractFieldConstraintNames(input) {
1015
1011
  spec: sqlAttributeSpecs.field.unique(),
1016
1012
  model: input.model,
1017
1013
  field: input.field,
1018
- sourceFile: input.sourceFile,
1019
- sourceId: input.sourceId,
1014
+ sources: input.sources,
1020
1015
  diagnostics: input.diagnostics
1021
1016
  })?.map
1022
1017
  };
@@ -1036,8 +1031,7 @@ function lowerNoCheckForField(input) {
1036
1031
  spec: sqlAttributeSpecs.field.noCheck(),
1037
1032
  model: input.model,
1038
1033
  field: input.field,
1039
- sourceFile: input.sourceFile,
1040
- sourceId: input.sourceId,
1034
+ sources: input.sources,
1041
1035
  diagnostics: input.diagnostics
1042
1036
  });
1043
1037
  if (interpreted === void 0) return void 0;
@@ -1052,8 +1046,7 @@ function lowerNoCheckForField(input) {
1052
1046
  input.diagnostics.push({
1053
1047
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
1054
1048
  message: `${subject} @noCheck waives nothing — this column's shape derives no generated checks`,
1055
- sourceId: input.sourceId,
1056
- span
1049
+ ...diagnosticSource(input.sources, input.field.node.syntax).at(span)
1057
1050
  });
1058
1051
  return;
1059
1052
  }
@@ -1064,20 +1057,20 @@ function lowerNoCheckForField(input) {
1064
1057
  input.diagnostics.push({
1065
1058
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
1066
1059
  message: `${subject} @noCheck(${kind}) does not apply — ${explanation}`,
1067
- sourceId: input.sourceId,
1068
- span
1060
+ ...diagnosticSource(input.sources, input.field.node.syntax).at(span)
1069
1061
  });
1070
1062
  return;
1071
1063
  }
1072
1064
  return [...authored].sort();
1073
1065
  }
1074
1066
  function collectResolvedFields(input) {
1075
- const { model, symbolTable, mapping, enumTypeDescriptors, namedTypeDescriptors, modelNames, compositeTypeNames, composedExtensions, authoringContributions, familyId, targetId, defaultFunctionRegistry, defaultLiteralTagRegistry, generatorDescriptorById, diagnostics, sourceId, scalarColumnDescriptors, enumHandles, capabilities, namespaceId, namespaceExtensionEntities, codecLookup } = input;
1067
+ const { model, symbolTable, mapping, enumTypeDescriptors, namedTypeDescriptors, modelNames, compositeTypeNames, composedExtensions, authoringContributions, familyId, targetId, defaultFunctionRegistry, defaultLiteralTagRegistry, generatorDescriptorById, diagnostics, sources, scalarColumnDescriptors, enumHandles, capabilities, namespaceId, namespaceExtensionEntities, codecLookup } = input;
1076
1068
  const resolvedFields = [];
1077
1069
  const valueObjectStorageTypeName = authoringContributions?.valueObjectStorageType;
1078
1070
  const declaredControlPolicy = getAttribute(model.attributes, "control")?.args.find((arg) => arg.kind === "positional")?.value.trim();
1079
1071
  const modelDerivesChecks = declaredControlPolicy === void 0 || declaredControlPolicy === "managed";
1080
1072
  for (const field of Object.values(model.fields)) {
1073
+ const source = diagnosticSource(sources, field.node.syntax);
1081
1074
  const isModelField = modelNames.has(field.typeName);
1082
1075
  if (field.list && isModelField) continue;
1083
1076
  validateFieldAttributes({
@@ -1086,7 +1079,7 @@ function collectResolvedFields(input) {
1086
1079
  composedExtensions,
1087
1080
  authoringContributions,
1088
1081
  diagnostics,
1089
- sourceId,
1082
+ sources,
1090
1083
  familyId,
1091
1084
  targetId
1092
1085
  });
@@ -1109,7 +1102,7 @@ function collectResolvedFields(input) {
1109
1102
  familyId,
1110
1103
  targetId,
1111
1104
  diagnostics,
1112
- sourceId,
1105
+ sources,
1113
1106
  entityLabel: `Field "${model.name}.${field.name}"`,
1114
1107
  ...ifDefined("namespaceId", namespaceId),
1115
1108
  ...ifDefined("namespaceExtensionEntities", namespaceExtensionEntities),
@@ -1121,8 +1114,7 @@ function collectResolvedFields(input) {
1121
1114
  diagnostics.push({
1122
1115
  code: "PSL_SCALAR_LIST_UNSUPPORTED_TARGET",
1123
1116
  message: `Field "${model.name}.${field.name}" is a scalar list, but target "${targetId}" does not support scalar lists (the adapter does not report the "scalarList" capability). Remove the list or author it against a target that supports scalar lists.`,
1124
- sourceId,
1125
- span: field.span
1117
+ ...source.at(field.span)
1126
1118
  });
1127
1119
  continue;
1128
1120
  }
@@ -1131,8 +1123,7 @@ function collectResolvedFields(input) {
1131
1123
  if (!resolved.alreadyReported) diagnostics.push({
1132
1124
  code: "PSL_UNSUPPORTED_FIELD_TYPE",
1133
1125
  message: `Field "${model.name}.${field.name}" type "${field.typeName}" is not supported in SQL PSL provider v1`,
1134
- sourceId,
1135
- span: field.span
1126
+ ...source.at(field.span)
1136
1127
  });
1137
1128
  continue;
1138
1129
  }
@@ -1140,8 +1131,7 @@ function collectResolvedFields(input) {
1140
1131
  diagnostics.push({
1141
1132
  code: "PSL_PRESET_NOT_LIST",
1142
1133
  message: `Field "${model.name}.${field.name}" uses a field-preset call as a list element type. Presets cannot be list elements; remove "[]" or use a scalar type.`,
1143
- sourceId,
1144
- span: field.span
1134
+ ...source.at(field.span)
1145
1135
  });
1146
1136
  continue;
1147
1137
  }
@@ -1153,8 +1143,7 @@ function collectResolvedFields(input) {
1153
1143
  if (!resolved.alreadyReported) diagnostics.push({
1154
1144
  code: "PSL_UNSUPPORTED_FIELD_TYPE",
1155
1145
  message: `Field "${model.name}.${field.name}" type "${field.typeName}" is not supported in SQL PSL provider v1`,
1156
- sourceId,
1157
- span: field.span
1146
+ ...source.at(field.span)
1158
1147
  });
1159
1148
  continue;
1160
1149
  }
@@ -1166,8 +1155,7 @@ function collectResolvedFields(input) {
1166
1155
  diagnostics.push({
1167
1156
  code: "PSL_PRESET_NOT_OPTIONAL",
1168
1157
  message: `Field "${model.name}.${field.name}" uses a field-preset call and cannot be optional. Remove "?" or use a different field type.`,
1169
- sourceId,
1170
- span: field.span
1158
+ ...source.at(field.span)
1171
1159
  });
1172
1160
  continue;
1173
1161
  }
@@ -1176,8 +1164,7 @@ function collectResolvedFields(input) {
1176
1164
  diagnostics.push({
1177
1165
  code: "PSL_PRESET_AND_DEFAULT_CONFLICT",
1178
1166
  message: `Field "${model.name}.${field.name}" uses a field-preset call and cannot also declare @default(...). The preset already specifies the default value.`,
1179
- sourceId,
1180
- span: defaultAttribute.span
1167
+ ...source.at(defaultAttribute.span)
1181
1168
  });
1182
1169
  continue;
1183
1170
  }
@@ -1188,9 +1175,8 @@ function collectResolvedFields(input) {
1188
1175
  field,
1189
1176
  model,
1190
1177
  symbolTable,
1191
- sourceFile: input.sourceFile,
1178
+ sources: input.sources,
1192
1179
  enumHandle,
1193
- sourceId,
1194
1180
  defaultFunctionRegistry,
1195
1181
  defaultLiteralTagRegistry,
1196
1182
  diagnostics
@@ -1200,10 +1186,9 @@ function collectResolvedFields(input) {
1200
1186
  field,
1201
1187
  model,
1202
1188
  symbolTable,
1203
- sourceFile: input.sourceFile,
1189
+ sources: input.sources,
1204
1190
  columnDescriptor: descriptor,
1205
1191
  generatorDescriptorById,
1206
- sourceId,
1207
1192
  defaultFunctionRegistry,
1208
1193
  defaultLiteralTagRegistry,
1209
1194
  codecLookup,
@@ -1214,8 +1199,7 @@ function collectResolvedFields(input) {
1214
1199
  diagnostics.push({
1215
1200
  code: "PSL_LIST_AUTOINCREMENT_UNSUPPORTED",
1216
1201
  message: `Field "${model.name}.${field.name}" is a list and cannot use autoincrement(); it is a Prisma marker for a sequence-backed scalar column, not SQL.`,
1217
- sourceId,
1218
- span: defaultAttribute?.span ?? field.span
1202
+ ...source.at(defaultAttribute?.span ?? field.span)
1219
1203
  });
1220
1204
  continue;
1221
1205
  }
@@ -1224,8 +1208,7 @@ function collectResolvedFields(input) {
1224
1208
  diagnostics.push({
1225
1209
  code: "PSL_LIST_EXECUTION_DEFAULT_UNSUPPORTED",
1226
1210
  message: `Field "${model.name}.${field.name}" is a list and cannot use an execution default ("${defaultExpression}"). Lists have no per-element execution-default semantics; use a literal list @default or remove the default.`,
1227
- sourceId,
1228
- span: defaultAttribute?.span ?? field.span
1211
+ ...source.at(defaultAttribute?.span ?? field.span)
1229
1212
  });
1230
1213
  continue;
1231
1214
  }
@@ -1234,8 +1217,7 @@ function collectResolvedFields(input) {
1234
1217
  diagnostics.push({
1235
1218
  code: "PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT",
1236
1219
  message: `Field "${model.name}.${field.name}" cannot be optional when using execution default ${generatorDescription}. Remove "?" or use a storage default.`,
1237
- sourceId,
1238
- span: defaultAttribute?.span ?? field.span
1220
+ ...source.at(defaultAttribute?.span ?? field.span)
1239
1221
  });
1240
1222
  continue;
1241
1223
  }
@@ -1243,8 +1225,7 @@ function collectResolvedFields(input) {
1243
1225
  const { idAttribute, uniqueAttribute, idName, uniqueName } = extractFieldConstraintNames({
1244
1226
  model,
1245
1227
  field,
1246
- sourceFile: input.sourceFile,
1247
- sourceId,
1228
+ sources: input.sources,
1248
1229
  diagnostics
1249
1230
  });
1250
1231
  let isIdField = Boolean(idAttribute);
@@ -1252,8 +1233,7 @@ function collectResolvedFields(input) {
1252
1233
  diagnostics.push({
1253
1234
  code: "PSL_LIST_ID_UNSUPPORTED",
1254
1235
  message: `Field "${model.name}.${field.name}" is a list and cannot be a primary key. Remove @id; a list cannot be an identity column.`,
1255
- sourceId,
1256
- span: idAttribute.span
1236
+ ...source.at(idAttribute.span)
1257
1237
  });
1258
1238
  continue;
1259
1239
  }
@@ -1261,8 +1241,7 @@ function collectResolvedFields(input) {
1261
1241
  diagnostics.push({
1262
1242
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
1263
1243
  message: `Field "${model.name}.${field.name}" @id cannot be optional; primary key columns must be NOT NULL`,
1264
- sourceId,
1265
- span: idAttribute.span
1244
+ ...source.at(idAttribute.span)
1266
1245
  });
1267
1246
  isIdField = false;
1268
1247
  }
@@ -1270,8 +1249,7 @@ function collectResolvedFields(input) {
1270
1249
  diagnostics.push({
1271
1250
  code: "PSL_PRESET_AND_ID_CONFLICT",
1272
1251
  message: `Field "${model.name}.${field.name}" uses a field-preset call and cannot also declare @id. Use a preset that contributes id semantics, or drop @id.`,
1273
- sourceId,
1274
- span: idAttribute.span
1252
+ ...source.at(idAttribute.span)
1275
1253
  });
1276
1254
  continue;
1277
1255
  }
@@ -1280,8 +1258,7 @@ function collectResolvedFields(input) {
1280
1258
  const noCheckKinds = modelDerivesChecks ? lowerNoCheckForField({
1281
1259
  model,
1282
1260
  field,
1283
- sourceFile: input.sourceFile,
1284
- sourceId,
1261
+ sources: input.sources,
1285
1262
  isListField: isListField && !isValueObjectField,
1286
1263
  isDomainEnum: enumHandle !== void 0,
1287
1264
  diagnostics
@@ -1305,7 +1282,7 @@ function collectResolvedFields(input) {
1305
1282
  }
1306
1283
  return resolvedFields;
1307
1284
  }
1308
- function buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sourceId, sourceFile) {
1285
+ function buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sources) {
1309
1286
  const result = /* @__PURE__ */ new Map();
1310
1287
  for (const { model, namespaceId } of modelEntries) {
1311
1288
  const mapNode = findModelAttributeNode(model, "map");
@@ -1313,8 +1290,7 @@ function buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sourc
1313
1290
  node: mapNode,
1314
1291
  spec: sqlAttributeSpecs.model.map(),
1315
1292
  model,
1316
- sourceFile,
1317
- sourceId,
1293
+ sources,
1318
1294
  diagnostics
1319
1295
  })?.name ?? defaultTableName(model.name);
1320
1296
  const fieldColumns = /* @__PURE__ */ new Map();
@@ -1325,8 +1301,7 @@ function buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sourc
1325
1301
  spec: sqlAttributeSpecs.field.map(),
1326
1302
  model,
1327
1303
  field,
1328
- sourceFile,
1329
- sourceId,
1304
+ sources,
1330
1305
  diagnostics
1331
1306
  })?.name ?? field.name;
1332
1307
  fieldColumns.set(field.name, columnName);
@@ -1346,8 +1321,7 @@ function validateNamedTypeAttributes(input) {
1346
1321
  input.diagnostics.push({
1347
1322
  code: "PSL_UNSUPPORTED_NAMED_TYPE_ATTRIBUTE",
1348
1323
  message: formatDbAttributeMigrationMessage(attribute),
1349
- sourceId: input.sourceId,
1350
- span: attribute.span
1324
+ ...input.source.at(attribute.span)
1351
1325
  });
1352
1326
  hasUnsupportedNamedTypeAttribute = true;
1353
1327
  continue;
@@ -1361,7 +1335,7 @@ function validateNamedTypeAttributes(input) {
1361
1335
  reportUncomposedNamespace({
1362
1336
  subjectLabel: `Attribute "@${attribute.name}"`,
1363
1337
  namespace: uncomposedNamespace,
1364
- sourceId: input.sourceId,
1338
+ source: input.source,
1365
1339
  span: attribute.span,
1366
1340
  diagnostics: input.diagnostics
1367
1341
  });
@@ -1371,8 +1345,7 @@ function validateNamedTypeAttributes(input) {
1371
1345
  input.diagnostics.push({
1372
1346
  code: "PSL_UNSUPPORTED_NAMED_TYPE_ATTRIBUTE",
1373
1347
  message: `Named type "${input.declaration.name}" uses unsupported attribute "${attribute.name}"`,
1374
- sourceId: input.sourceId,
1375
- span: attribute.span
1348
+ ...input.source.at(attribute.span)
1376
1349
  });
1377
1350
  hasUnsupportedNamedTypeAttribute = true;
1378
1351
  }
@@ -1382,20 +1355,20 @@ function resolveNamedTypeDeclarations(input) {
1382
1355
  const storageTypeEntries = [];
1383
1356
  const namedTypeDescriptors = /* @__PURE__ */ new Map();
1384
1357
  for (const declaration of input.declarations) {
1358
+ const source = diagnosticSource(input.source.sources, declaration.node.syntax);
1385
1359
  if (declaration.isConstructor) {
1386
1360
  const typeConstructor = declaration.typeConstructor;
1387
1361
  if (typeConstructor === void 0) {
1388
1362
  input.diagnostics.push({
1389
1363
  code: "PSL_UNSUPPORTED_NAMED_TYPE_BASE",
1390
1364
  message: `Named type "${declaration.name}" must declare a base type or constructor`,
1391
- sourceId: input.sourceId,
1392
- span: declaration.span
1365
+ ...source.at(declaration.span)
1393
1366
  });
1394
1367
  continue;
1395
1368
  }
1396
1369
  if (validateNamedTypeAttributes({
1397
1370
  declaration,
1398
- sourceId: input.sourceId,
1371
+ source,
1399
1372
  diagnostics: input.diagnostics,
1400
1373
  composedExtensions: input.composedExtensions,
1401
1374
  authoringContributions: input.authoringContributions,
@@ -1410,7 +1383,7 @@ function resolveNamedTypeDeclarations(input) {
1410
1383
  familyId: input.familyId,
1411
1384
  targetId: input.targetId,
1412
1385
  diagnostics: input.diagnostics,
1413
- sourceId: input.sourceId,
1386
+ source,
1414
1387
  unsupportedCode: "PSL_UNSUPPORTED_NAMED_TYPE_CONSTRUCTOR",
1415
1388
  unsupportedMessage: `Named type "${declaration.name}" references unsupported constructor "${helperPath}"`
1416
1389
  });
@@ -1419,7 +1392,7 @@ function resolveNamedTypeDeclarations(input) {
1419
1392
  call: typeConstructor,
1420
1393
  descriptor,
1421
1394
  diagnostics: input.diagnostics,
1422
- sourceId: input.sourceId,
1395
+ source,
1423
1396
  entityLabel: `Named type "${declaration.name}"`
1424
1397
  });
1425
1398
  if (!storageType) continue;
@@ -1437,8 +1410,7 @@ function resolveNamedTypeDeclarations(input) {
1437
1410
  input.diagnostics.push({
1438
1411
  code: "PSL_UNSUPPORTED_NAMED_TYPE_BASE",
1439
1412
  message: `Named type "${declaration.name}" must declare a base type or constructor`,
1440
- sourceId: input.sourceId,
1441
- span: declaration.span
1413
+ ...source.at(declaration.span)
1442
1414
  });
1443
1415
  continue;
1444
1416
  }
@@ -1447,14 +1419,13 @@ function resolveNamedTypeDeclarations(input) {
1447
1419
  input.diagnostics.push({
1448
1420
  code: "PSL_UNSUPPORTED_NAMED_TYPE_BASE",
1449
1421
  message: `Named type "${declaration.name}" references unsupported base type "${baseType}"`,
1450
- sourceId: input.sourceId,
1451
- span: declaration.span
1422
+ ...source.at(declaration.span)
1452
1423
  });
1453
1424
  continue;
1454
1425
  }
1455
1426
  if (validateNamedTypeAttributes({
1456
1427
  declaration,
1457
- sourceId: input.sourceId,
1428
+ source,
1458
1429
  diagnostics: input.diagnostics,
1459
1430
  composedExtensions: input.composedExtensions,
1460
1431
  authoringContributions: input.authoringContributions,
@@ -1506,8 +1477,7 @@ function interpretRelationAttribute(input) {
1506
1477
  spec: sqlAttributeSpecs.field.relation(),
1507
1478
  model: input.selfModel,
1508
1479
  field: input.field,
1509
- sourceFile: input.sourceFile,
1510
- sourceId: input.sourceId,
1480
+ sources: input.sources,
1511
1481
  diagnostics: input.diagnostics,
1512
1482
  resolveReferencedModel: () => resolveReferencedModel(input.symbols, input.field)
1513
1483
  });
@@ -1638,7 +1608,8 @@ function findJunctionFkPairs(input) {
1638
1608
  nearMisses
1639
1609
  };
1640
1610
  }
1641
- function junctionNearMissDiagnostic(candidate, nearMiss, sourceId) {
1611
+ function junctionNearMissDiagnostic(candidate, nearMiss, sources) {
1612
+ const source = diagnosticSource(sources, candidate.field.node.syntax);
1642
1613
  const listField = `${candidate.modelName}.${candidate.field.name}`;
1643
1614
  const data = {
1644
1615
  listField,
@@ -1648,15 +1619,13 @@ function junctionNearMissDiagnostic(candidate, nearMiss, sourceId) {
1648
1619
  if (nearMiss.reason === "target-fk-not-id") return {
1649
1620
  code: "PSL_JUNCTION_TARGET_FK_NOT_ID",
1650
1621
  message: `Backrelation list field "${listField}" found junction model "${nearMiss.junctionModelName}", but its foreign key to "${candidate.targetModelName}" does not reference "${candidate.targetModelName}"'s @id. The junction's target-side foreign key must reference "${candidate.targetModelName}"'s full @id columns for many-to-many recognition.`,
1651
- sourceId,
1652
- span: candidate.field.span,
1622
+ ...source.at(candidate.field.span),
1653
1623
  data
1654
1624
  };
1655
1625
  return {
1656
1626
  code: "PSL_JUNCTION_ID_NOT_FK_COVERING",
1657
1627
  message: `Backrelation list field "${listField}" found junction-shaped model "${nearMiss.junctionModelName}" linking "${candidate.modelName}" and "${candidate.targetModelName}", but its id does not cover exactly its foreign-key columns. Declare @@id([...]) on "${nearMiss.junctionModelName}" listing exactly the two foreign-key columns for many-to-many recognition.`,
1658
- sourceId,
1659
- span: candidate.field.span,
1628
+ ...source.at(candidate.field.span),
1660
1629
  data
1661
1630
  };
1662
1631
  }
@@ -1701,6 +1670,7 @@ function fkColumnsAreUnique(localColumns, uniqueColumnSets) {
1701
1670
  }
1702
1671
  function applyBackrelationCandidates(input) {
1703
1672
  for (const candidate of input.backrelationCandidates) {
1673
+ const source = diagnosticSource(input.sources, candidate.field.node.syntax);
1704
1674
  const pairKey = fkRelationPairKey(candidate.targetModelName, candidate.modelName);
1705
1675
  const pairMatches = input.fkRelationsByPair.get(pairKey) ?? [];
1706
1676
  const matches = candidate.relationName ? pairMatches.filter((relation) => relation.relationName === candidate.relationName) : [...pairMatches];
@@ -1721,22 +1691,20 @@ function applyBackrelationCandidates(input) {
1721
1691
  input.diagnostics.push({
1722
1692
  code: "PSL_AMBIGUOUS_BACKRELATION",
1723
1693
  message: `Backrelation list field "${candidate.modelName}.${candidate.field.name}" matches multiple junction FK pairs for a many-to-many relation. Add @relation(name: "...") (or @relation("...")) to the list field and the junction FK-side relation pointing back at "${candidate.modelName}" to disambiguate.`,
1724
- sourceId: input.sourceId,
1725
- span: candidate.field.span
1694
+ ...source.at(candidate.field.span)
1726
1695
  });
1727
1696
  continue;
1728
1697
  }
1729
1698
  const nearMiss = nearMisses[0];
1730
1699
  if (nearMiss) {
1731
- input.diagnostics.push(junctionNearMissDiagnostic(candidate, nearMiss, input.sourceId));
1700
+ input.diagnostics.push(junctionNearMissDiagnostic(candidate, nearMiss, input.sources));
1732
1701
  continue;
1733
1702
  }
1734
1703
  }
1735
1704
  input.diagnostics.push({
1736
1705
  code: "PSL_ORPHANED_BACKRELATION",
1737
1706
  message: `Backrelation field "${candidate.modelName}.${candidate.field.name}" has no matching FK-side relation on model "${candidate.targetModelName}". Add @relation(fields: [...], references: [...]) on the FK-side relation${candidate.isList ? " or use an explicit join model for many-to-many" : ""}.`,
1738
- sourceId: input.sourceId,
1739
- span: candidate.field.span
1707
+ ...source.at(candidate.field.span)
1740
1708
  });
1741
1709
  continue;
1742
1710
  }
@@ -1744,8 +1712,7 @@ function applyBackrelationCandidates(input) {
1744
1712
  input.diagnostics.push({
1745
1713
  code: "PSL_AMBIGUOUS_BACKRELATION",
1746
1714
  message: `Backrelation field "${candidate.modelName}.${candidate.field.name}" matches multiple FK-side relations on model "${candidate.targetModelName}". Add @relation(name: "...") (or @relation("...")) to both sides to disambiguate.`,
1747
- sourceId: input.sourceId,
1748
- span: candidate.field.span
1715
+ ...source.at(candidate.field.span)
1749
1716
  });
1750
1717
  continue;
1751
1718
  }
@@ -1758,8 +1725,7 @@ function applyBackrelationCandidates(input) {
1758
1725
  input.diagnostics.push({
1759
1726
  code: "PSL_NON_UNIQUE_BACKRELATION",
1760
1727
  message: `Backrelation field "${candidate.modelName}.${candidate.field.name}" is singular, but the matching FK on "${matched.declaringModelName}" (fields ${matched.localColumns.map((column) => `"${column}"`).join(", ")}) is not unique. A singular back-relation implies at most one related row; add @unique (or @@unique([...])) to the FK fields, or make "${candidate.field.name}" a list.`,
1761
- sourceId: input.sourceId,
1762
- span: candidate.field.span
1728
+ ...source.at(candidate.field.span)
1763
1729
  });
1764
1730
  continue;
1765
1731
  }
@@ -1768,7 +1734,7 @@ function applyBackrelationCandidates(input) {
1768
1734
  modelName: candidate.modelName,
1769
1735
  field: candidate.field,
1770
1736
  targetModelName: candidate.targetModelName,
1771
- sourceId: input.sourceId,
1737
+ sources: input.sources,
1772
1738
  recordNoun: "row"
1773
1739
  }));
1774
1740
  relationsForModel(input.modelRelations, candidate.modelName).push({
@@ -1790,6 +1756,7 @@ function applyBackrelationCandidates(input) {
1790
1756
  }
1791
1757
  }
1792
1758
  function validateBackrelationFieldAttributes(input) {
1759
+ const source = diagnosticSource(input.sources, input.field.node.syntax);
1793
1760
  let valid = true;
1794
1761
  for (const attribute of input.field.attributes) {
1795
1762
  if (attribute.name === "relation") continue;
@@ -1802,7 +1769,7 @@ function validateBackrelationFieldAttributes(input) {
1802
1769
  reportUncomposedNamespace({
1803
1770
  subjectLabel: `Attribute "@${attribute.name}"`,
1804
1771
  namespace: uncomposedNamespace,
1805
- sourceId: input.sourceId,
1772
+ source,
1806
1773
  span: attribute.span,
1807
1774
  diagnostics: input.diagnostics
1808
1775
  });
@@ -1812,8 +1779,7 @@ function validateBackrelationFieldAttributes(input) {
1812
1779
  input.diagnostics.push({
1813
1780
  code: "PSL_UNSUPPORTED_FIELD_ATTRIBUTE",
1814
1781
  message: `Field "${input.modelName}.${input.field.name}" uses unsupported attribute "@${attribute.name}"`,
1815
- sourceId: input.sourceId,
1816
- span: attribute.span
1782
+ ...source.at(attribute.span)
1817
1783
  });
1818
1784
  valid = false;
1819
1785
  }
@@ -1909,22 +1875,20 @@ function isUnboundNamespaceBlock(ns, targetId) {
1909
1875
  }
1910
1876
  function validateNamespaceBlocksForSqlTarget(input) {
1911
1877
  if (input.targetId === "sqlite") {
1912
- for (const namespace of input.namespaces) for (const { span } of namespace.declarations) input.diagnostics.push({
1878
+ for (const namespace of input.namespaces) for (const { node, span } of namespace.declarations) input.diagnostics.push({
1913
1879
  code: "PSL_UNSUPPORTED_NAMESPACE_BLOCK",
1914
1880
  message: `SQLite does not support \`namespace ${namespace.name} { … }\` blocks (SQLite has no schema concept; declare models at the document top level instead).`,
1915
- sourceId: input.sourceId,
1916
- span
1881
+ ...diagnosticSource(input.sources, node.syntax).at(span)
1917
1882
  });
1918
1883
  return;
1919
1884
  }
1920
1885
  if (input.targetId === "postgres") {
1921
1886
  const unboundBlock = input.namespaces.find((ns) => isUnboundNamespaceBlock(ns, input.targetId) && Object.keys(ns.models).length > 0);
1922
1887
  const hasSibling = input.namespaces.some((ns) => !isUnboundNamespaceBlock(ns, input.targetId));
1923
- if (unboundBlock !== void 0 && hasSibling) for (const { span } of unboundBlock.declarations) input.diagnostics.push({
1888
+ if (unboundBlock !== void 0 && hasSibling) for (const { node, span } of unboundBlock.declarations) input.diagnostics.push({
1924
1889
  code: "PSL_RESERVED_NAMESPACE_NAME",
1925
1890
  message: "Namespace \"unbound\" is reserved for the late-binding sentinel mapping; a `namespace unbound { … }` containing models cannot appear alongside other named namespace blocks. Use `namespace unbound { … }` alone (no sibling named namespaces) for late-binding multi-tenant contracts.",
1926
- sourceId: input.sourceId,
1927
- span
1891
+ ...diagnosticSource(input.sources, node.syntax).at(span)
1928
1892
  });
1929
1893
  }
1930
1894
  }
@@ -1955,8 +1919,7 @@ function duplicateModelAttributeDiagnostic(input) {
1955
1919
  return {
1956
1920
  code: "PSL_DUPLICATE_ATTRIBUTE",
1957
1921
  message: `\`@@${input.name}\` declared more than once on model "${input.modelName}".`,
1958
- sourceId: input.sourceId,
1959
- ...ifDefined("span", input.span)
1922
+ ...input.source.at(input.span)
1960
1923
  };
1961
1924
  }
1962
1925
  /**
@@ -1981,8 +1944,7 @@ function validateBlockModelAttributeRequirements(input) {
1981
1944
  input.diagnostics.push({
1982
1945
  code: "PSL_EXTENSION_TARGET_MODEL_MISSING_ATTRIBUTE",
1983
1946
  message: `\`${blockSymbol.keyword}\` block "${blockSymbol.block.name}" targets model "${captured.identifier}", which does not declare \`@@${requirement.attribute}\`. Add \`@@${requirement.attribute}\` to model "${captured.identifier}".`,
1984
- sourceId: input.sourceId,
1985
- span: captured.span
1947
+ ...diagnosticSource(input.source.sources, blockSymbol.node.syntax).at(captured.span)
1986
1948
  });
1987
1949
  }
1988
1950
  }
@@ -2031,7 +1993,7 @@ function buildModelAttributesByName(contributions) {
2031
1993
  * never looks a model up itself. A required model ref that is missing or
2032
1994
  * does not resolve is this pass's diagnostic; the factory is skipped.
2033
1995
  */
2034
- function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminator, entityContext, pslBlockDescriptors, resolveModelTable) {
1996
+ function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminator, entityContext, pslBlockDescriptors, resolveModelTable, sources, diagnostics) {
2035
1997
  const blockSymbols = Object.values(blocks);
2036
1998
  if (blockSymbols.length === 0) return {};
2037
1999
  const result = {};
@@ -2047,11 +2009,10 @@ function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminat
2047
2009
  const captured = block.parameters[paramName];
2048
2010
  if (captured?.kind !== "ref") {
2049
2011
  if (paramDecl.required === true) {
2050
- entityContext.diagnostics?.push({
2012
+ diagnostics.push({
2051
2013
  code: "PSL_EXTENSION_MODEL_REF_UNRESOLVED",
2052
2014
  message: `\`${block.keyword}\` block "${block.name}" is missing the required \`${paramName}\` model reference.`,
2053
- sourceId: entityContext.sourceId ?? "unknown",
2054
- span: block.span
2015
+ ...diagnosticSource(sources, blockSymbol.node.syntax).at(block.span)
2055
2016
  });
2056
2017
  unresolvedRef = true;
2057
2018
  }
@@ -2059,11 +2020,10 @@ function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminat
2059
2020
  }
2060
2021
  const tableName = resolveModelTable(captured.identifier);
2061
2022
  if (tableName === void 0) {
2062
- entityContext.diagnostics?.push({
2023
+ diagnostics.push({
2063
2024
  code: "PSL_EXTENSION_MODEL_REF_UNRESOLVED",
2064
2025
  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.`,
2065
- sourceId: entityContext.sourceId ?? "unknown",
2066
- span: captured.span
2026
+ ...diagnosticSource(sources, blockSymbol.node.syntax).at(captured.span)
2067
2027
  });
2068
2028
  unresolvedRef = true;
2069
2029
  continue;
@@ -2079,7 +2039,10 @@ function lowerExtensionBlocksForNamespace(blocks, nsId, entityTypesByDiscriminat
2079
2039
  namespaceId: nsId,
2080
2040
  ...resolvedModelRefs !== void 0 ? { resolvedModelRefs } : {}
2081
2041
  };
2082
- const entity = instantiateAuthoringEntityType(descriptor.discriminator, descriptor, [annotatedBlock], entityContext);
2042
+ const entity = instantiateAuthoringEntityType(descriptor.discriminator, descriptor, [annotatedBlock], {
2043
+ ...entityContext,
2044
+ sourceId: sources.sourceFileFor(blockSymbol.node.syntax).filename
2045
+ });
2083
2046
  if (entity === void 0) continue;
2084
2047
  const entriesKey = descriptor.discriminator;
2085
2048
  const slot = result[entriesKey] ?? {};
@@ -2103,19 +2066,25 @@ function processEnumDeclarations(input) {
2103
2066
  };
2104
2067
  const enumDescriptor = getAuthoringEntity(input.authoringContributions, ["enum"]);
2105
2068
  if (!enumDescriptor) {
2106
- for (const decl of input.enumBlocks) input.diagnostics.push({
2107
- code: "PSL_ENUM_MISSING_FACTORY",
2108
- message: `enum "${decl.name}" requires an "enum" entityType factory in the active authoring contributions`,
2109
- sourceId: input.sourceId,
2110
- span: decl.span
2111
- });
2069
+ for (const symbol of input.enumBlocks) {
2070
+ const decl = symbol.block;
2071
+ input.diagnostics.push({
2072
+ code: "PSL_ENUM_MISSING_FACTORY",
2073
+ message: `enum "${decl.name}" requires an "enum" entityType factory in the active authoring contributions`,
2074
+ ...diagnosticSource(input.source.sources, symbol.node.syntax).at(decl.span)
2075
+ });
2076
+ }
2112
2077
  return {
2113
2078
  enumHandles,
2114
2079
  enumTypeDescriptors
2115
2080
  };
2116
2081
  }
2117
- for (const decl of input.enumBlocks) {
2118
- const handle = instantiateAuthoringEntityType("enum", enumDescriptor, [decl], input.entityContext);
2082
+ for (const symbol of input.enumBlocks) {
2083
+ const decl = symbol.block;
2084
+ const handle = instantiateAuthoringEntityType("enum", enumDescriptor, [decl], {
2085
+ ...input.entityContext,
2086
+ sourceId: input.source.sources.sourceFileFor(symbol.node.syntax).filename
2087
+ });
2119
2088
  if (handle === void 0 || handle === null) continue;
2120
2089
  enumHandles[decl.name] = handle;
2121
2090
  enumTypeDescriptors.set(decl.name, {
@@ -2153,17 +2122,17 @@ function relationNullabilityMismatch(relationField, localColumns, resolvedFields
2153
2122
  ownsReference: true
2154
2123
  }).contradiction !== void 0;
2155
2124
  }
2156
- function relationNullabilityMismatchDiagnostic(modelName, relationAttribute, sourceId) {
2125
+ function relationNullabilityMismatchDiagnostic(modelName, relationAttribute, source) {
2157
2126
  const fieldLabel = `Relation field "${modelName}.${relationAttribute.field.name}"`;
2158
2127
  return {
2159
2128
  code: "PSL_RELATION_NULLABILITY_MISMATCH",
2160
2129
  message: relationAttribute.field.optional ? `${fieldLabel} is optional but every field in @relation(fields: [...]) is required. Make one of those fields optional with "?" or remove "?" from "${relationAttribute.field.name}".` : `${fieldLabel} is required but a field in @relation(fields: [...]) is optional. Add "?" to "${relationAttribute.field.name}" or make those fields required.`,
2161
- sourceId,
2162
- span: relationAttribute.field.span
2130
+ ...source.at(relationAttribute.field.span)
2163
2131
  };
2164
2132
  }
2165
2133
  function buildModelNodeFromPsl(input) {
2166
- const { model, mapping, sourceId, diagnostics } = input;
2134
+ const { model, mapping, diagnostics } = input;
2135
+ const source = diagnosticSource(input.sources, model.node.syntax);
2167
2136
  const tableName = mapping.tableName;
2168
2137
  const modelNamespaceId = input.modelNamespaceIds.get(model.name);
2169
2138
  const namespaceExtensionEntitiesForModel = modelNamespaceId !== void 0 ? input.namespaceExtensionEntities?.get(modelNamespaceId) : void 0;
@@ -2183,8 +2152,7 @@ function buildModelNodeFromPsl(input) {
2183
2152
  defaultLiteralTagRegistry: input.defaultLiteralTagRegistry,
2184
2153
  generatorDescriptorById: input.generatorDescriptorById,
2185
2154
  diagnostics,
2186
- sourceId,
2187
- sourceFile: input.sourceFile,
2155
+ sources: input.sources,
2188
2156
  scalarColumnDescriptors: input.scalarColumnDescriptors,
2189
2157
  ...ifDefined("enumHandles", input.enumHandles),
2190
2158
  capabilities: input.capabilities,
@@ -2196,8 +2164,7 @@ function buildModelNodeFromPsl(input) {
2196
2164
  if (inlineIdFields.length > 1) diagnostics.push({
2197
2165
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
2198
2166
  message: `Model "${model.name}" cannot declare inline @id on multiple fields; use model-level @@id([...]) for composite identity`,
2199
- sourceId,
2200
- span: model.span
2167
+ ...source.at(model.span)
2201
2168
  });
2202
2169
  const singleInlineIdField = inlineIdFields.length === 1 ? inlineIdFields[0] : void 0;
2203
2170
  let primaryKey = singleInlineIdField ? {
@@ -2218,7 +2185,7 @@ function buildModelNodeFromPsl(input) {
2218
2185
  const attributesValid = validateBackrelationFieldAttributes({
2219
2186
  modelName: model.name,
2220
2187
  field,
2221
- sourceId,
2188
+ sources: input.sources,
2222
2189
  composedExtensions: input.composedExtensions,
2223
2190
  authoringContributions: input.authoringContributions,
2224
2191
  diagnostics,
@@ -2231,8 +2198,7 @@ function buildModelNodeFromPsl(input) {
2231
2198
  selfModel: model,
2232
2199
  field,
2233
2200
  symbols: input.symbolTable,
2234
- sourceFile: input.sourceFile,
2235
- sourceId,
2201
+ sources: input.sources,
2236
2202
  diagnostics
2237
2203
  });
2238
2204
  if (!parsedRelation) continue;
@@ -2240,8 +2206,7 @@ function buildModelNodeFromPsl(input) {
2240
2206
  diagnostics.push({
2241
2207
  code: "PSL_INVALID_RELATION_ATTRIBUTE",
2242
2208
  message: `Backrelation list field "${model.name}.${field.name}" cannot declare fields/references; define them on the FK-side relation field`,
2243
- sourceId,
2244
- span: relationAttribute.span
2209
+ ...source.at(relationAttribute.span)
2245
2210
  });
2246
2211
  continue;
2247
2212
  }
@@ -2249,8 +2214,7 @@ function buildModelNodeFromPsl(input) {
2249
2214
  diagnostics.push({
2250
2215
  code: "PSL_INVALID_RELATION_ATTRIBUTE",
2251
2216
  message: `Backrelation list field "${model.name}.${field.name}" cannot declare onDelete/onUpdate/index; define them on the FK-side relation field`,
2252
- sourceId,
2253
- span: relationAttribute.span
2217
+ ...source.at(relationAttribute.span)
2254
2218
  });
2255
2219
  continue;
2256
2220
  }
@@ -2289,7 +2253,7 @@ function buildModelNodeFromPsl(input) {
2289
2253
  reportUncomposedNamespace({
2290
2254
  subjectLabel: `Attribute "@@${modelAttribute.name}"`,
2291
2255
  namespace: uncomposedNamespace,
2292
- sourceId,
2256
+ source,
2293
2257
  span: modelAttribute.span,
2294
2258
  diagnostics
2295
2259
  });
@@ -2298,8 +2262,7 @@ function buildModelNodeFromPsl(input) {
2298
2262
  diagnostics.push({
2299
2263
  code: "PSL_UNSUPPORTED_MODEL_ATTRIBUTE",
2300
2264
  message: `Model "${model.name}" uses unsupported attribute "@@${modelAttribute.name}"`,
2301
- sourceId,
2302
- span: modelAttribute.span
2265
+ ...source.at(modelAttribute.span)
2303
2266
  });
2304
2267
  continue;
2305
2268
  }
@@ -2310,7 +2273,7 @@ function buildModelNodeFromPsl(input) {
2310
2273
  diagnostics.push(duplicateModelAttributeDiagnostic({
2311
2274
  name: "control",
2312
2275
  modelName: model.name,
2313
- sourceId,
2276
+ source,
2314
2277
  span: modelAttribute.span
2315
2278
  }));
2316
2279
  continue;
@@ -2322,8 +2285,7 @@ function buildModelNodeFromPsl(input) {
2322
2285
  node,
2323
2286
  spec: sqlAttributeSpecs.model.control(),
2324
2287
  model,
2325
- sourceFile: input.sourceFile,
2326
- sourceId,
2288
+ sources: input.sources,
2327
2289
  diagnostics
2328
2290
  });
2329
2291
  if (parsed !== void 0) controlPolicy = parsed.policy;
@@ -2335,8 +2297,7 @@ function buildModelNodeFromPsl(input) {
2335
2297
  diagnostics.push({
2336
2298
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
2337
2299
  message: `Model "${model.name}" declares @@id more than once`,
2338
- sourceId,
2339
- span: modelAttribute.span
2300
+ ...source.at(modelAttribute.span)
2340
2301
  });
2341
2302
  continue;
2342
2303
  }
@@ -2344,8 +2305,7 @@ function buildModelNodeFromPsl(input) {
2344
2305
  diagnostics.push({
2345
2306
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
2346
2307
  message: `Model "${model.name}" cannot declare both field-level @id and model-level @@id`,
2347
- sourceId,
2348
- span: modelAttribute.span
2308
+ ...source.at(modelAttribute.span)
2349
2309
  });
2350
2310
  blockPrimaryKeyDeclared = true;
2351
2311
  continue;
@@ -2356,8 +2316,7 @@ function buildModelNodeFromPsl(input) {
2356
2316
  node,
2357
2317
  spec: sqlAttributeSpecs.model.id(),
2358
2318
  model,
2359
- sourceFile: input.sourceFile,
2360
- sourceId,
2319
+ sources: input.sources,
2361
2320
  diagnostics
2362
2321
  });
2363
2322
  if (parsed === void 0) continue;
@@ -2367,8 +2326,7 @@ function buildModelNodeFromPsl(input) {
2367
2326
  diagnostics.push({
2368
2327
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
2369
2328
  message: `${attributeLabel} cannot include optional field "${nullableFieldName}"; primary key columns must be NOT NULL`,
2370
- sourceId,
2371
- span: modelAttribute.span
2329
+ ...source.at(modelAttribute.span)
2372
2330
  });
2373
2331
  continue;
2374
2332
  }
@@ -2376,7 +2334,7 @@ function buildModelNodeFromPsl(input) {
2376
2334
  modelName: model.name,
2377
2335
  fieldNames,
2378
2336
  mapping,
2379
- sourceId,
2337
+ source,
2380
2338
  diagnostics,
2381
2339
  span: modelAttribute.span,
2382
2340
  entityLabel: attributeLabel
@@ -2396,8 +2354,7 @@ function buildModelNodeFromPsl(input) {
2396
2354
  node,
2397
2355
  spec: sqlAttributeSpecs.model.unique(),
2398
2356
  model,
2399
- sourceFile: input.sourceFile,
2400
- sourceId,
2357
+ sources: input.sources,
2401
2358
  diagnostics
2402
2359
  });
2403
2360
  if (parsed === void 0) continue;
@@ -2405,7 +2362,7 @@ function buildModelNodeFromPsl(input) {
2405
2362
  modelName: model.name,
2406
2363
  fieldNames: parsed.fields,
2407
2364
  mapping,
2408
- sourceId,
2365
+ source,
2409
2366
  diagnostics,
2410
2367
  span: modelAttribute.span,
2411
2368
  entityLabel: attributeLabel
@@ -2424,8 +2381,7 @@ function buildModelNodeFromPsl(input) {
2424
2381
  node,
2425
2382
  spec: sqlAttributeSpecs.model.index(),
2426
2383
  model,
2427
- sourceFile: input.sourceFile,
2428
- sourceId,
2384
+ sources: input.sources,
2429
2385
  diagnostics
2430
2386
  });
2431
2387
  if (parsed === void 0) continue;
@@ -2435,7 +2391,7 @@ function buildModelNodeFromPsl(input) {
2435
2391
  modelName: model.name,
2436
2392
  fieldNames: parsed.fields,
2437
2393
  mapping,
2438
- sourceId,
2394
+ source,
2439
2395
  diagnostics,
2440
2396
  span: modelAttribute.span,
2441
2397
  entityLabel: attributeLabel
@@ -2462,8 +2418,7 @@ function buildModelNodeFromPsl(input) {
2462
2418
  diagnostics.push({
2463
2419
  code: "PSL_CHECK_UNSUPPORTED_TARGET",
2464
2420
  message: `Model "${model.name}" declares "@@check", but target "${input.targetId}" does not support check constraints (the adapter does not report the "checkConstraint" capability). Remove the check or author it against a target that supports check constraints.`,
2465
- sourceId,
2466
- span: modelAttribute.span
2421
+ ...source.at(modelAttribute.span)
2467
2422
  });
2468
2423
  continue;
2469
2424
  }
@@ -2471,8 +2426,7 @@ function buildModelNodeFromPsl(input) {
2471
2426
  node,
2472
2427
  spec: sqlAttributeSpecs.model.check(),
2473
2428
  model,
2474
- sourceFile: input.sourceFile,
2475
- sourceId,
2429
+ sources: input.sources,
2476
2430
  diagnostics
2477
2431
  });
2478
2432
  if (parsed === void 0) continue;
@@ -2489,7 +2443,7 @@ function buildModelNodeFromPsl(input) {
2489
2443
  diagnostics.push(duplicateModelAttributeDiagnostic({
2490
2444
  name: modelAttribute.name,
2491
2445
  modelName: model.name,
2492
- sourceId,
2446
+ source,
2493
2447
  span: modelAttribute.span
2494
2448
  }));
2495
2449
  continue;
@@ -2508,8 +2462,7 @@ function buildModelNodeFromPsl(input) {
2508
2462
  }
2509
2463
  }),
2510
2464
  model,
2511
- sourceFile: input.sourceFile,
2512
- sourceId,
2465
+ sources: input.sources,
2513
2466
  diagnostics
2514
2467
  });
2515
2468
  if (parsed === void 0) continue;
@@ -2519,9 +2472,9 @@ function buildModelNodeFromPsl(input) {
2519
2472
  modelName: model.name,
2520
2473
  storageName: tableName,
2521
2474
  namespaceId: modelNamespaceId ?? input.defaultNamespaceId,
2522
- sourceId,
2475
+ sourceId: source.sources.sourceFileFor(source.node).filename,
2523
2476
  diagnostics: { push: (d) => {
2524
- diagnostics.push(blindCast(d));
2477
+ diagnostics.pushExternal(blindCast(d));
2525
2478
  } }
2526
2479
  });
2527
2480
  if (lowered === void 0) continue;
@@ -2541,8 +2494,7 @@ function buildModelNodeFromPsl(input) {
2541
2494
  if (fieldTypeContractSpaceId !== void 0) diagnostics.push({
2542
2495
  code: "PSL_UNSUPPORTED_CROSS_SPACE_LIST",
2543
2496
  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.`,
2544
- sourceId,
2545
- span: relationAttribute.field.span
2497
+ ...source.at(relationAttribute.field.span)
2546
2498
  });
2547
2499
  continue;
2548
2500
  }
@@ -2553,8 +2505,7 @@ function buildModelNodeFromPsl(input) {
2553
2505
  diagnostics.push({
2554
2506
  code: "PSL_UNKNOWN_CONTRACT_SPACE",
2555
2507
  message: `Relation field "${model.name}.${relationAttribute.field.name}" references contract space "${fieldTypeContractSpaceId}" which is not declared in extensions. Add "${fieldTypeContractSpaceId}" to extensions in prisma.config.ts.`,
2556
- sourceId,
2557
- span: relationAttribute.field.span,
2508
+ ...source.at(relationAttribute.field.span),
2558
2509
  data: {
2559
2510
  space: fieldTypeContractSpaceId,
2560
2511
  suggestedPack: fieldTypeContractSpaceId
@@ -2566,8 +2517,7 @@ function buildModelNodeFromPsl(input) {
2566
2517
  selfModel: model,
2567
2518
  field: relationAttribute.field,
2568
2519
  symbols: input.symbolTable,
2569
- sourceFile: input.sourceFile,
2570
- sourceId,
2520
+ sources: input.sources,
2571
2521
  diagnostics
2572
2522
  });
2573
2523
  if (!parsedRelation) continue;
@@ -2575,8 +2525,7 @@ function buildModelNodeFromPsl(input) {
2575
2525
  diagnostics.push({
2576
2526
  code: "PSL_INVALID_RELATION_ATTRIBUTE",
2577
2527
  message: `Relation field "${model.name}.${relationAttribute.field.name}" requires fields and references arguments`,
2578
- sourceId,
2579
- span: relationAttribute.relation.span
2528
+ ...source.at(relationAttribute.relation.span)
2580
2529
  });
2581
2530
  continue;
2582
2531
  }
@@ -2584,14 +2533,14 @@ function buildModelNodeFromPsl(input) {
2584
2533
  modelName: model.name,
2585
2534
  fieldNames: parsedRelation.fields,
2586
2535
  mapping,
2587
- sourceId,
2536
+ source,
2588
2537
  diagnostics,
2589
2538
  span: relationAttribute.relation.span,
2590
2539
  entityLabel: `Relation field "${model.name}.${relationAttribute.field.name}"`
2591
2540
  });
2592
2541
  if (!localColumns) continue;
2593
2542
  if (relationNullabilityMismatch(relationAttribute.field, localColumns, resolvedFields)) {
2594
- diagnostics.push(relationNullabilityMismatchDiagnostic(model.name, relationAttribute, sourceId));
2543
+ diagnostics.push(relationNullabilityMismatchDiagnostic(model.name, relationAttribute, source));
2595
2544
  continue;
2596
2545
  }
2597
2546
  const referencedColumns = parsedRelation.references;
@@ -2599,8 +2548,7 @@ function buildModelNodeFromPsl(input) {
2599
2548
  diagnostics.push({
2600
2549
  code: "PSL_INVALID_RELATION_ATTRIBUTE",
2601
2550
  message: `Relation field "${model.name}.${relationAttribute.field.name}" must provide the same number of fields and references`,
2602
- sourceId,
2603
- span: relationAttribute.relation.span
2551
+ ...source.at(relationAttribute.relation.span)
2604
2552
  });
2605
2553
  continue;
2606
2554
  }
@@ -2614,8 +2562,7 @@ function buildModelNodeFromPsl(input) {
2614
2562
  diagnostics.push({
2615
2563
  code: "PSL_UNKNOWN_CROSS_SPACE_TARGET",
2616
2564
  message: `Relation field "${model.name}.${relationAttribute.field.name}" references model "${fieldTypeName}" in namespace "${crossTargetNamespaceId}" of space "${fieldTypeContractSpaceId}", but that model was not found in the extension contract. Available models: ${availableModels}`,
2617
- sourceId,
2618
- span: relationAttribute.field.span,
2565
+ ...source.at(relationAttribute.field.span),
2619
2566
  data: {
2620
2567
  space: fieldTypeContractSpaceId,
2621
2568
  namespace: crossTargetNamespaceId,
@@ -2661,8 +2608,7 @@ function buildModelNodeFromPsl(input) {
2661
2608
  diagnostics.push({
2662
2609
  code: "PSL_INVALID_RELATION_TARGET",
2663
2610
  message: `Relation field "${model.name}.${relationAttribute.field.name}" references unknown model "${qualifiedTypeName}"`,
2664
- sourceId,
2665
- span: relationAttribute.field.span
2611
+ ...source.at(relationAttribute.field.span)
2666
2612
  });
2667
2613
  continue;
2668
2614
  }
@@ -2671,8 +2617,7 @@ function buildModelNodeFromPsl(input) {
2671
2617
  diagnostics.push({
2672
2618
  code: "PSL_INVALID_RELATION_TARGET",
2673
2619
  message: `Relation field "${model.name}.${relationAttribute.field.name}" references unknown model "${qualifiedTypeName}"`,
2674
- sourceId,
2675
- span: relationAttribute.field.span
2620
+ ...source.at(relationAttribute.field.span)
2676
2621
  });
2677
2622
  continue;
2678
2623
  }
@@ -2680,8 +2625,7 @@ function buildModelNodeFromPsl(input) {
2680
2625
  selfModel: model,
2681
2626
  field: relationAttribute.field,
2682
2627
  symbols: input.symbolTable,
2683
- sourceFile: input.sourceFile,
2684
- sourceId,
2628
+ sources: input.sources,
2685
2629
  diagnostics
2686
2630
  });
2687
2631
  if (!parsedRelation) continue;
@@ -2689,8 +2633,7 @@ function buildModelNodeFromPsl(input) {
2689
2633
  diagnostics.push({
2690
2634
  code: "PSL_INVALID_RELATION_ATTRIBUTE",
2691
2635
  message: `Relation field "${model.name}.${relationAttribute.field.name}" requires fields and references arguments`,
2692
- sourceId,
2693
- span: relationAttribute.relation.span
2636
+ ...source.at(relationAttribute.relation.span)
2694
2637
  });
2695
2638
  continue;
2696
2639
  }
@@ -2699,8 +2642,7 @@ function buildModelNodeFromPsl(input) {
2699
2642
  diagnostics.push({
2700
2643
  code: "PSL_INVALID_RELATION_TARGET",
2701
2644
  message: `Relation field "${model.name}.${relationAttribute.field.name}" references unknown model "${qualifiedTypeName}"`,
2702
- sourceId,
2703
- span: relationAttribute.field.span
2645
+ ...source.at(relationAttribute.field.span)
2704
2646
  });
2705
2647
  continue;
2706
2648
  }
@@ -2708,14 +2650,14 @@ function buildModelNodeFromPsl(input) {
2708
2650
  modelName: model.name,
2709
2651
  fieldNames: parsedRelation.fields,
2710
2652
  mapping,
2711
- sourceId,
2653
+ source,
2712
2654
  diagnostics,
2713
2655
  span: relationAttribute.relation.span,
2714
2656
  entityLabel: `Relation field "${model.name}.${relationAttribute.field.name}"`
2715
2657
  });
2716
2658
  if (!localColumns) continue;
2717
2659
  if (relationNullabilityMismatch(relationAttribute.field, localColumns, resolvedFields)) {
2718
- diagnostics.push(relationNullabilityMismatchDiagnostic(model.name, relationAttribute, sourceId));
2660
+ diagnostics.push(relationNullabilityMismatchDiagnostic(model.name, relationAttribute, source));
2719
2661
  resultInvalidFkPairings.push({
2720
2662
  pairKey: fkRelationPairKey(model.name, targetMapping.model.name),
2721
2663
  ...ifDefined("relationName", parsedRelation.name)
@@ -2726,7 +2668,7 @@ function buildModelNodeFromPsl(input) {
2726
2668
  modelName: targetMapping.model.name,
2727
2669
  fieldNames: parsedRelation.references,
2728
2670
  mapping: targetMapping,
2729
- sourceId,
2671
+ source,
2730
2672
  diagnostics,
2731
2673
  span: relationAttribute.relation.span,
2732
2674
  entityLabel: `Relation field "${model.name}.${relationAttribute.field.name}"`
@@ -2736,8 +2678,7 @@ function buildModelNodeFromPsl(input) {
2736
2678
  diagnostics.push({
2737
2679
  code: "PSL_INVALID_RELATION_ATTRIBUTE",
2738
2680
  message: `Relation field "${model.name}.${relationAttribute.field.name}" must provide the same number of fields and references`,
2739
- sourceId,
2740
- span: relationAttribute.relation.span
2681
+ ...source.at(relationAttribute.relation.span)
2741
2682
  });
2742
2683
  continue;
2743
2684
  }
@@ -2805,7 +2746,7 @@ function buildModelNodeFromPsl(input) {
2805
2746
  };
2806
2747
  }
2807
2748
  function buildValueObjects(input) {
2808
- const { compositeTypes, enumTypeDescriptors, namedTypeDescriptors, scalarColumnDescriptors, composedExtensions, familyId, targetId, authoringContributions, diagnostics, sourceId } = input;
2749
+ const { compositeTypes, enumTypeDescriptors, namedTypeDescriptors, scalarColumnDescriptors, composedExtensions, familyId, targetId, authoringContributions, diagnostics, sources } = input;
2809
2750
  const valueObjects = {};
2810
2751
  const compositeTypeNames = new Set(compositeTypes.map((ct) => ct.name));
2811
2752
  for (const compositeType of compositeTypes) {
@@ -2835,15 +2776,14 @@ function buildValueObjects(input) {
2835
2776
  familyId,
2836
2777
  targetId,
2837
2778
  diagnostics,
2838
- sourceId,
2779
+ sources,
2839
2780
  entityLabel: `Field "${compositeType.name}.${field.name}"`
2840
2781
  });
2841
2782
  if (!resolved.ok) {
2842
2783
  if (!resolved.alreadyReported) diagnostics.push({
2843
2784
  code: "PSL_UNSUPPORTED_FIELD_TYPE",
2844
2785
  message: `Field "${compositeType.name}.${field.name}" type "${field.typeName}" is not supported`,
2845
- sourceId,
2846
- span: field.span
2786
+ ...diagnosticSource(sources, field.node.syntax).at(field.span)
2847
2787
  });
2848
2788
  continue;
2849
2789
  }
@@ -2901,32 +2841,32 @@ function patchModelDomainFields(models, modelResolvedFields) {
2901
2841
  }
2902
2842
  return patched;
2903
2843
  }
2904
- function collectPolymorphismDeclarations(models, sourceFile, sourceId, diagnostics) {
2844
+ function collectPolymorphismDeclarations(models, sources, diagnostics) {
2905
2845
  const discriminatorDeclarations = /* @__PURE__ */ new Map();
2906
2846
  const baseDeclarations = /* @__PURE__ */ new Map();
2907
2847
  for (const model of models) {
2848
+ const source = diagnosticSource(sources, model.node.syntax);
2908
2849
  const discriminatorNode = findModelAttributeNode(model, "discriminator");
2909
2850
  if (discriminatorNode !== void 0) {
2910
2851
  const parsed = interpretModelAttribute({
2911
2852
  node: discriminatorNode,
2912
2853
  spec: sqlAttributeSpecs.model.discriminator(),
2913
2854
  model,
2914
- sourceFile,
2915
- sourceId,
2855
+ sources,
2916
2856
  diagnostics
2917
2857
  });
2918
2858
  if (parsed !== void 0) {
2919
- const span = nodePslSpan(discriminatorNode.syntax, sourceFile);
2859
+ const span = nodePslSpan(discriminatorNode.syntax, sources);
2920
2860
  const discField = model.fields[parsed.field];
2921
2861
  if (discField && discField.typeName !== "String") diagnostics.push({
2922
2862
  code: "PSL_INVALID_ATTRIBUTE_ARGUMENT",
2923
2863
  message: `Discriminator field "${parsed.field}" on model "${model.name}" must be of type String, but is "${discField.typeName}"`,
2924
- sourceId,
2925
- span
2864
+ ...source.at(span)
2926
2865
  });
2927
2866
  else discriminatorDeclarations.set(model.name, {
2928
2867
  fieldName: parsed.field,
2929
- span
2868
+ span,
2869
+ source
2930
2870
  });
2931
2871
  }
2932
2872
  }
@@ -2936,14 +2876,14 @@ function collectPolymorphismDeclarations(models, sourceFile, sourceId, diagnosti
2936
2876
  node: baseNode,
2937
2877
  spec: sqlAttributeSpecs.model.base(),
2938
2878
  model,
2939
- sourceFile,
2940
- sourceId,
2879
+ sources,
2941
2880
  diagnostics
2942
2881
  });
2943
2882
  if (parsed !== void 0) baseDeclarations.set(model.name, {
2883
+ source,
2944
2884
  baseName: parsed.base,
2945
2885
  value: parsed.value,
2946
- span: nodePslSpan(baseNode.syntax, sourceFile)
2886
+ span: nodePslSpan(baseNode.syntax, sources)
2947
2887
  });
2948
2888
  }
2949
2889
  }
@@ -2952,7 +2892,7 @@ function collectPolymorphismDeclarations(models, sourceFile, sourceId, diagnosti
2952
2892
  baseDeclarations
2953
2893
  };
2954
2894
  }
2955
- function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, defaultNamespaceId, syntheticPkFieldsByVariant, stiBaseFieldsByBase, sourceId, diagnostics) {
2895
+ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, defaultNamespaceId, syntheticPkFieldsByVariant, stiBaseFieldsByBase, diagnostics) {
2956
2896
  let patched = models;
2957
2897
  const coordinateFor = (modelName) => modelCoordinateKey(modelNamespaceIds.get(modelName) ?? defaultNamespaceId, modelName);
2958
2898
  for (const [baseName, fieldNames] of stiBaseFieldsByBase) {
@@ -2969,8 +2909,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2969
2909
  diagnostics.push({
2970
2910
  code: "PSL_DISCRIMINATOR_AND_BASE",
2971
2911
  message: `Model "${modelName}" cannot have both @@discriminator and @@base`,
2972
- sourceId,
2973
- span: decl.span
2912
+ ...decl.source.at(decl.span)
2974
2913
  });
2975
2914
  continue;
2976
2915
  }
@@ -2985,8 +2924,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2985
2924
  diagnostics.push({
2986
2925
  code: "PSL_DUPLICATE_DISCRIMINATOR_VALUE",
2987
2926
  message: `Discriminator value "${baseDecl.value}" is used by both "${existingVariant}" and "${variantName}" on base model "${modelName}"`,
2988
- sourceId,
2989
- span: baseDecl.span
2927
+ ...baseDecl.source.at(baseDecl.span)
2990
2928
  });
2991
2929
  continue;
2992
2930
  }
@@ -2997,8 +2935,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
2997
2935
  diagnostics.push({
2998
2936
  code: "PSL_ORPHANED_DISCRIMINATOR",
2999
2937
  message: `Model "${modelName}" has @@discriminator but no variant models declare @@base(${modelName}, ...)`,
3000
- sourceId,
3001
- span: decl.span
2938
+ ...decl.source.at(decl.span)
3002
2939
  });
3003
2940
  continue;
3004
2941
  }
@@ -3016,8 +2953,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
3016
2953
  diagnostics.push({
3017
2954
  code: "PSL_BASE_TARGET_NOT_FOUND",
3018
2955
  message: `Model "${variantName}" @@base references non-existent model "${baseDecl.baseName}"`,
3019
- sourceId,
3020
- span: baseDecl.span
2956
+ ...baseDecl.source.at(baseDecl.span)
3021
2957
  });
3022
2958
  continue;
3023
2959
  }
@@ -3025,8 +2961,7 @@ function resolvePolymorphism(models, discriminatorDeclarations, baseDeclarations
3025
2961
  diagnostics.push({
3026
2962
  code: "PSL_ORPHANED_BASE",
3027
2963
  message: `Model "${variantName}" declares @@base(${baseDecl.baseName}, ...) but "${baseDecl.baseName}" has no @@discriminator`,
3028
- sourceId,
3029
- span: baseDecl.span
2964
+ ...baseDecl.source.at(baseDecl.span)
3030
2965
  });
3031
2966
  continue;
3032
2967
  }
@@ -3199,38 +3134,43 @@ function stripStorageOnlyDomainFields(model, fieldNames) {
3199
3134
  };
3200
3135
  }
3201
3136
  function interpretPslDocumentToSqlContract(input) {
3202
- const sourceId = input.sourceId;
3203
- if (!input.target) return notOk({
3204
- summary: "PSL to SQL contract interpretation failed",
3205
- diagnostics: [{
3137
+ const source = diagnosticSource(input.sources, input.document.syntax);
3138
+ const diagnostics = createPslDiagnosticCollector(input.sources);
3139
+ if (!input.target) {
3140
+ diagnostics.pushUnlocated({
3206
3141
  code: "PSL_TARGET_CONTEXT_REQUIRED",
3207
3142
  message: "PSL interpretation requires an explicit target context from composition.",
3208
- sourceId
3209
- }]
3210
- });
3211
- if (!input.scalarColumnDescriptors) return notOk({
3212
- summary: "PSL to SQL contract interpretation failed",
3213
- diagnostics: [{
3143
+ ...source.at()
3144
+ });
3145
+ return notOk({
3146
+ summary: "PSL to SQL contract interpretation failed",
3147
+ diagnostics: diagnostics.toExternal()
3148
+ });
3149
+ }
3150
+ if (!input.scalarColumnDescriptors) {
3151
+ diagnostics.pushUnlocated({
3214
3152
  code: "PSL_SCALAR_TYPE_CONTEXT_REQUIRED",
3215
3153
  message: "PSL interpretation requires composed scalar type descriptors.",
3216
- sourceId
3217
- }]
3218
- });
3154
+ ...source.at()
3155
+ });
3156
+ return notOk({
3157
+ summary: "PSL to SQL contract interpretation failed",
3158
+ diagnostics: diagnostics.toExternal()
3159
+ });
3160
+ }
3219
3161
  const { topLevel } = input.symbolTable;
3220
- const sourceFile = input.sourceFile;
3221
3162
  const namespaceSymbols = Object.values(topLevel.namespaces);
3222
- const diagnostics = [...input.seedDiagnostics ?? []];
3223
3163
  validateNamespaceBlocksForSqlTarget({
3224
3164
  namespaces: namespaceSymbols,
3225
3165
  targetId: input.target.targetId,
3226
- sourceId,
3227
- sourceFile,
3166
+ source,
3167
+ sources: input.sources,
3228
3168
  diagnostics
3229
3169
  });
3230
3170
  validateBlockModelAttributeRequirements({
3231
3171
  scopes: [topLevel, ...namespaceSymbols],
3232
3172
  pslBlockDescriptors: input.authoringContributions?.pslBlockDescriptors ?? {},
3233
- sourceId,
3173
+ source,
3234
3174
  diagnostics
3235
3175
  });
3236
3176
  const models = [];
@@ -3270,8 +3210,7 @@ function interpretPslDocumentToSqlContract(input) {
3270
3210
  diagnostics.push({
3271
3211
  code: "PSL_UNSUPPORTED_TOP_LEVEL_BLOCK",
3272
3212
  message: `Unsupported top-level block "${block.keyword}"`,
3273
- sourceId,
3274
- span: keywordPslSpan(block.node.syntax, block.keyword, sourceFile)
3213
+ ...diagnosticSource(input.sources, block.node.syntax).at(keywordPslSpan(block.node.syntax, block.keyword, input.sources))
3275
3214
  });
3276
3215
  };
3277
3216
  const topLevelEnums = [];
@@ -3281,7 +3220,7 @@ function interpretPslDocumentToSqlContract(input) {
3281
3220
  reportUnsupportedTopLevelBlock(block);
3282
3221
  continue;
3283
3222
  }
3284
- if (isEnumBlock(block)) topLevelEnums.push(block.block);
3223
+ if (isEnumBlock(block)) topLevelEnums.push(block);
3285
3224
  else topLevelExtensionBlocks[blockName] = block;
3286
3225
  }
3287
3226
  for (const namespace of namespaceSymbols) for (const block of Object.values(namespace.blocks)) {
@@ -3289,8 +3228,7 @@ function interpretPslDocumentToSqlContract(input) {
3289
3228
  diagnostics.push({
3290
3229
  code: "PSL_ENUM_NAMESPACE_NOT_SUPPORTED",
3291
3230
  message: `enum "${block.name}" inside namespace "${namespace.name}" is not supported; declare enum at the top level`,
3292
- sourceId,
3293
- span: nodePslSpan(block.node.syntax, sourceFile)
3231
+ ...diagnosticSource(input.sources, block.node.syntax).at(nodePslSpan(block.node.syntax, input.sources))
3294
3232
  });
3295
3233
  continue;
3296
3234
  }
@@ -3298,15 +3236,15 @@ function interpretPslDocumentToSqlContract(input) {
3298
3236
  }
3299
3237
  const enumResult = processEnumDeclarations({
3300
3238
  enumBlocks: topLevelEnums,
3301
- sourceId,
3239
+ source,
3302
3240
  authoringContributions: input.authoringContributions,
3303
3241
  entityContext: {
3304
3242
  family: input.target.familyId,
3305
3243
  target: input.target.targetId,
3306
3244
  ...ifDefined("codecLookup", input.codecLookup),
3307
- sourceId,
3245
+ sourceId: source.sources.sourceFileFor(source.node).filename,
3308
3246
  diagnostics: { push: (d) => {
3309
- diagnostics.push(blindCast(d));
3247
+ diagnostics.pushExternal(blindCast(d));
3310
3248
  } },
3311
3249
  ...ifDefined("enumInferenceCodecs", input.enumInferenceCodecs)
3312
3250
  },
@@ -3323,16 +3261,16 @@ function interpretPslDocumentToSqlContract(input) {
3323
3261
  target: input.target.targetId,
3324
3262
  ...ifDefined("enumInferenceCodecs", input.enumInferenceCodecs),
3325
3263
  ...ifDefined("codecLookup", input.codecLookup),
3326
- sourceId,
3264
+ sourceId: source.sources.sourceFileFor(source.node).filename,
3327
3265
  diagnostics: { push: (d) => {
3328
- diagnostics.push(blindCast(d));
3266
+ diagnostics.pushExternal(blindCast(d));
3329
3267
  } },
3330
3268
  warnings: authoringWarnings
3331
3269
  };
3332
- const earlyModelMappingsByCoordinate = buildModelMappings(modelEntries, defaultNamespaceId, [], sourceId, sourceFile);
3270
+ const earlyModelMappingsByCoordinate = buildModelMappings(modelEntries, defaultNamespaceId, createPslDiagnosticCollector(input.sources), input.sources);
3333
3271
  const composedPslBlockDescriptors = input.authoringContributions?.pslBlockDescriptors ?? {};
3334
3272
  const namespaceExtensionEntities = /* @__PURE__ */ new Map();
3335
- const mergeNamespaceExtensionEntities = (nsId, entities) => {
3273
+ const mergeNamespaceExtensionEntities = (nsId, entities, blocks) => {
3336
3274
  if (Object.keys(entities).length === 0) return;
3337
3275
  const existing = namespaceExtensionEntities.get(nsId);
3338
3276
  if (existing === void 0) {
@@ -3343,11 +3281,15 @@ function interpretPslDocumentToSqlContract(input) {
3343
3281
  for (const [entriesKey, slot] of Object.entries(entities)) {
3344
3282
  const existingSlot = existing[entriesKey];
3345
3283
  if (existingSlot !== void 0) {
3346
- for (const name of Object.keys(slot)) if (Object.hasOwn(existingSlot, name)) diagnostics.push({
3347
- code: "PSL_DUPLICATE_EXTENSION_ENTITY",
3348
- message: `entries slot "${entriesKey}" in namespace "${nsId}": entity "${name}" is declared more than once in the same namespace.`,
3349
- sourceId
3350
- });
3284
+ for (const name of Object.keys(slot)) if (Object.hasOwn(existingSlot, name)) {
3285
+ const block = Object.values(blocks).find((block) => block.name === name);
3286
+ invariant(block !== void 0, "Lowered entity has an owning block");
3287
+ diagnostics.pushUnlocated({
3288
+ code: "PSL_DUPLICATE_EXTENSION_ENTITY",
3289
+ message: `entries slot "${entriesKey}" in namespace "${nsId}": entity "${name}" is declared more than once in the same namespace.`,
3290
+ ...diagnosticSource(input.sources, block.node.syntax).at()
3291
+ });
3292
+ }
3351
3293
  }
3352
3294
  merged[entriesKey] = {
3353
3295
  ...existingSlot,
@@ -3363,28 +3305,32 @@ function interpretPslDocumentToSqlContract(input) {
3363
3305
  targetId: input.target.targetId
3364
3306
  });
3365
3307
  if (nsId === void 0) continue;
3366
- mergeNamespaceExtensionEntities(nsId, lowerExtensionBlocksForNamespace(ns.blocks, nsId, entityTypesByDiscriminator, extensionEntityContext, composedPslBlockDescriptors, (modelName) => earlyModelMappingsByCoordinate.get(modelCoordinateKey(nsId, modelName))?.tableName));
3308
+ mergeNamespaceExtensionEntities(nsId, lowerExtensionBlocksForNamespace(ns.blocks, nsId, entityTypesByDiscriminator, extensionEntityContext, composedPslBlockDescriptors, (modelName) => earlyModelMappingsByCoordinate.get(modelCoordinateKey(nsId, modelName))?.tableName, input.sources, diagnostics), ns.blocks);
3367
3309
  }
3368
3310
  if (Object.keys(topLevelExtensionBlocks).length > 0) {
3369
3311
  const topLevelNsId = resolveNamespaceIdForSqlTarget({
3370
3312
  bucketName: UNSPECIFIED_PSL_NAMESPACE_NAME,
3371
3313
  targetId: input.target.targetId
3372
3314
  }) ?? defaultNamespaceId;
3373
- mergeNamespaceExtensionEntities(topLevelNsId, lowerExtensionBlocksForNamespace(topLevelExtensionBlocks, topLevelNsId, entityTypesByDiscriminator, extensionEntityContext, composedPslBlockDescriptors, (modelName) => earlyModelMappingsByCoordinate.get(modelCoordinateKey(topLevelNsId, modelName))?.tableName));
3315
+ mergeNamespaceExtensionEntities(topLevelNsId, lowerExtensionBlocksForNamespace(topLevelExtensionBlocks, topLevelNsId, entityTypesByDiscriminator, extensionEntityContext, composedPslBlockDescriptors, (modelName) => earlyModelMappingsByCoordinate.get(modelCoordinateKey(topLevelNsId, modelName))?.tableName, input.sources, diagnostics), topLevelExtensionBlocks);
3374
3316
  }
3375
3317
  const defaultNsExtensionValueSets = namespaceExtensionEntities.get(defaultNamespaceId)?.["valueSet"];
3376
3318
  if (defaultNsExtensionValueSets !== void 0) {
3377
- for (const name of Object.keys(defaultNsExtensionValueSets)) if (Object.hasOwn(validEnumHandles, name)) diagnostics.push({
3378
- code: "PSL_VALUE_SET_NAME_COLLISION",
3379
- message: `namespace "${defaultNamespaceId}": name "${name}" is declared both as a domain enum and as an extension entity that derives a value-set; rename one`,
3380
- sourceId
3381
- });
3319
+ for (const name of Object.keys(defaultNsExtensionValueSets)) if (Object.hasOwn(validEnumHandles, name)) {
3320
+ const enumSymbol = topLevel.blocks[name];
3321
+ invariant(enumSymbol !== void 0, "Domain enum has an owning block");
3322
+ diagnostics.pushUnlocated({
3323
+ code: "PSL_VALUE_SET_NAME_COLLISION",
3324
+ message: `namespace "${defaultNamespaceId}": name "${name}" is declared both as a domain enum and as an extension entity that derives a value-set; rename one`,
3325
+ ...diagnosticSource(input.sources, enumSymbol.node.syntax).at()
3326
+ });
3327
+ }
3382
3328
  }
3383
3329
  const isScalarRefinement = (symbol) => !symbol.isConstructor && symbol.baseType !== void 0 && input.scalarColumnDescriptors.has(symbol.baseType);
3384
3330
  const allNamedTypes = Object.values(topLevel.namedTypes);
3385
3331
  const namedTypeResult = resolveNamedTypeDeclarations({
3386
3332
  declarations: [...allNamedTypes.filter(isScalarRefinement), ...allNamedTypes.filter((symbol) => !isScalarRefinement(symbol))],
3387
- sourceId,
3333
+ source,
3388
3334
  enumTypeDescriptors: allEnumTypeDescriptors,
3389
3335
  scalarColumnDescriptors: input.scalarColumnDescriptors,
3390
3336
  composedExtensions,
@@ -3394,7 +3340,7 @@ function interpretPslDocumentToSqlContract(input) {
3394
3340
  diagnostics
3395
3341
  });
3396
3342
  const storageTypes = { ...namedTypeResult.storageTypes };
3397
- const modelMappingsByCoordinate = buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, sourceId, sourceFile);
3343
+ const modelMappingsByCoordinate = buildModelMappings(modelEntries, defaultNamespaceId, diagnostics, input.sources);
3398
3344
  const modelMappings = /* @__PURE__ */ new Map();
3399
3345
  for (const mapping of modelMappingsByCoordinate.values()) modelMappings.set(mapping.model.name, mapping);
3400
3346
  const modelNodes = [];
@@ -3426,8 +3372,7 @@ function interpretPslDocumentToSqlContract(input) {
3426
3372
  defaultLiteralTagRegistry,
3427
3373
  generatorDescriptorById,
3428
3374
  scalarColumnDescriptors: input.scalarColumnDescriptors,
3429
- sourceId,
3430
- sourceFile,
3375
+ sources: input.sources,
3431
3376
  symbolTable: input.symbolTable,
3432
3377
  diagnostics,
3433
3378
  modelNamespaceIds,
@@ -3479,14 +3424,14 @@ function interpretPslDocumentToSqlContract(input) {
3479
3424
  modelUniqueColumnSets,
3480
3425
  modelRelations,
3481
3426
  diagnostics,
3482
- sourceId
3427
+ sources: input.sources
3483
3428
  });
3484
3429
  for (const [modelName, relations] of crossSpaceRelationsByModel) {
3485
3430
  const existing = modelRelations.get(modelName);
3486
3431
  if (existing) existing.push(...relations);
3487
3432
  else modelRelations.set(modelName, [...relations]);
3488
3433
  }
3489
- const { discriminatorDeclarations, baseDeclarations } = collectPolymorphismDeclarations(models, sourceFile, sourceId, diagnostics);
3434
+ const { discriminatorDeclarations, baseDeclarations } = collectPolymorphismDeclarations(models, input.sources, diagnostics);
3490
3435
  const stiVariantNames = /* @__PURE__ */ new Set();
3491
3436
  for (const variantName of baseDeclarations.keys()) if (!(modelMappings.get(variantName)?.model.attributes.some((attr) => attr.name === "map") ?? false)) stiVariantNames.add(variantName);
3492
3437
  for (const variantName of stiVariantNames) {
@@ -3499,8 +3444,7 @@ function interpretPslDocumentToSqlContract(input) {
3499
3444
  diagnostics.push({
3500
3445
  code: PSL_CHECK_ON_STI_VARIANT,
3501
3446
  message: `Model "${variantName}" declares "@@check", but it shares its base model "${baseDecl.baseName}"'s storage table (single-table inheritance via @@base) and has no table of its own to declare a check constraint on. Declare the check on "${baseDecl.baseName}" instead.`,
3502
- sourceId,
3503
- span: nodePslSpan(attribute.syntax, sourceFile)
3447
+ ...diagnosticSource(input.sources, attribute.syntax).at(nodePslSpan(attribute.syntax, input.sources))
3504
3448
  });
3505
3449
  }
3506
3450
  }
@@ -3516,11 +3460,11 @@ function interpretPslDocumentToSqlContract(input) {
3516
3460
  targetId: input.target.targetId,
3517
3461
  authoringContributions: input.authoringContributions,
3518
3462
  diagnostics,
3519
- sourceId
3463
+ sources: input.sources
3520
3464
  });
3521
- if (diagnostics.length > 0) return notOk({
3465
+ if (diagnostics.length > 0 || (input.seedDiagnostics?.length ?? 0) > 0) return notOk({
3522
3466
  summary: "PSL to SQL contract interpretation failed",
3523
- diagnostics
3467
+ diagnostics: [...input.seedDiagnostics ?? [], ...diagnostics.toExternal()]
3524
3468
  });
3525
3469
  const { createNamespace } = input;
3526
3470
  const createNamespaceWithExtensions = (nsInput) => {
@@ -3568,11 +3512,11 @@ function interpretPslDocumentToSqlContract(input) {
3568
3512
  modelsForPatch[coordinate] = model;
3569
3513
  }
3570
3514
  let patchedModels = patchModelDomainFields(modelsForPatch, modelResolvedFields);
3571
- const polyDiagnostics = [];
3572
- patchedModels = resolvePolymorphism(patchedModels, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, input.target.defaultNamespaceId, syntheticPkFieldsByVariant, stiBaseFieldsByBase, sourceId, polyDiagnostics);
3515
+ const polyDiagnostics = createPslDiagnosticCollector(input.sources);
3516
+ patchedModels = resolvePolymorphism(patchedModels, discriminatorDeclarations, baseDeclarations, modelNames, modelMappings, modelNamespaceIds, input.target.defaultNamespaceId, syntheticPkFieldsByVariant, stiBaseFieldsByBase, polyDiagnostics);
3573
3517
  if (polyDiagnostics.length > 0) return notOk({
3574
3518
  summary: "PSL to SQL contract interpretation failed",
3575
- diagnostics: polyDiagnostics
3519
+ diagnostics: polyDiagnostics.toExternal()
3576
3520
  });
3577
3521
  const variantModelNames = new Set(baseDeclarations.keys());
3578
3522
  const filteredRoots = Object.fromEntries(Object.entries(contract.roots).filter(([, crossReference]) => !variantModelNames.has(crossReference.model)));
@@ -3590,4 +3534,4 @@ function interpretPslDocumentToSqlContract(input) {
3590
3534
  //#endregion
3591
3535
  export { normalizeReferentialAction as a, interpretPslDocumentToSqlContract as i, buildEntityTypesByDiscriminator as n, numberLiteralDefault as o, indexFkRelations as r, resolveFieldTypeDescriptor as s, applyBackrelationCandidates as t };
3592
3536
 
3593
- //# sourceMappingURL=interpreter-9Ru2E-MH-CQdWmnh8.mjs.map
3537
+ //# sourceMappingURL=interpreter-C8N5eRW1-LGv-WI9y.mjs.map