@prisma/orm-framework 8.0.0-rc.14-dev.13 → 8.0.0-rc.14-dev.14

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.
@@ -4,7 +4,7 @@ import { a as or, i as okVoid, n as notOk, r as ok, t as and } from "./result-8O
4
4
  import { C as isAuthoringTypeConstructorDescriptor, S as isAuthoringPslBlockDescriptor, x as isAuthoringModelAttributeDescriptor } from "./temporal-presets-DsGuaFyT-DWzKyja_.mjs";
5
5
  import { a as flatPslModels, c as namespacePslExtensionBlocks } from "./psl-ast-CyvE6CR-.mjs";
6
6
  import { n as isPslIdentifier } from "./tokenizer-BMz7z2KR-J0yZ4im3.mjs";
7
- import { C as TaggedLiteralExprAst, S as StringLiteralExprAst, T as TypesBlockAst, _ as NumberLiteralExprAst, a as CompositeTypeDeclarationAst, d as IdentifierAst, g as NamespaceDeclarationAst, i as BooleanLiteralExprAst, l as FunctionCallAst, m as ModelDeclarationAst, t as ArrayLiteralAst, u as GenericBlockDeclarationAst, y as ObjectLiteralExprAst } from "./declarations-CgS5vnfJ-Dhi3X7oU.mjs";
7
+ import { C as TaggedLiteralExprAst, S as StringLiteralExprAst, T as TypesBlockAst, _ as NumberLiteralExprAst, a as CompositeTypeDeclarationAst, d as IdentifierAst, g as NamespaceDeclarationAst, i as BooleanLiteralExprAst, l as FunctionCallAst, m as ModelDeclarationAst, t as ArrayLiteralAst, u as GenericBlockDeclarationAst, y as ObjectLiteralExprAst } from "./declarations-DqOfcPNK-CxtZmhmW.mjs";
8
8
  import { a as mapPslDiagnostics, c as readResolvedAttributes, i as keywordPslSpan, l as readResolvedConstructorCall, n as diagnosticFromSpan, o as nodePslSpan, r as diagnosticSource, s as readResolvedAttribute, t as createPslDiagnosticCollector } from "./resolve-GE34dgM6-D33m6YEw.mjs";
9
9
  //#region ../../../1-framework/2-authoring/psl-parser/dist/index.mjs
10
10
  function getPositionalArgument(attribute, index = 0) {
@@ -583,9 +583,14 @@ function contributedTypeScope(typeConstructors) {
583
583
  const existing = scopes.get(typeConstructors);
584
584
  if (existing !== void 0) return existing;
585
585
  const members = collect(typeConstructors, []);
586
- const created = { lookup(name) {
587
- return members.get(name);
588
- } };
586
+ const created = {
587
+ lookup(name) {
588
+ return members.get(name);
589
+ },
590
+ entries() {
591
+ return members.entries();
592
+ }
593
+ };
589
594
  scopes.set(typeConstructors, created);
590
595
  return created;
591
596
  }
@@ -619,6 +624,25 @@ function findBlockDescriptor(descriptors, keyword) {
619
624
  if (nested !== void 0) return nested;
620
625
  }
621
626
  }
627
+ function* recordNames(...records) {
628
+ for (const record of records) yield* Object.keys(record);
629
+ }
630
+ var Scope = class {
631
+ parent;
632
+ constructor(parent) {
633
+ this.parent = parent;
634
+ }
635
+ *entries() {
636
+ const seen = /* @__PURE__ */ new Set();
637
+ for (const name of this.ownNames()) {
638
+ if (seen.has(name)) continue;
639
+ seen.add(name);
640
+ const resolution = this.lookup(name);
641
+ if (resolution !== void 0) yield [name, resolution];
642
+ }
643
+ for (const entry of this.parent?.entries() ?? []) if (!seen.has(entry[0])) yield entry;
644
+ }
645
+ };
622
646
  function contributedResolution(member) {
623
647
  return member.kind === "contributedType" ? {
624
648
  kind: "contributedType",
@@ -648,22 +672,25 @@ function namespaceMember(namespace, name) {
648
672
  namespace
649
673
  };
650
674
  }
651
- var ContributedScope = class {
675
+ var ContributedScope = class extends Scope {
652
676
  #registry;
653
677
  constructor(registry) {
678
+ super(void 0);
654
679
  this.#registry = registry;
655
680
  }
656
681
  lookup(name) {
657
682
  const member = this.#registry.lookup(name);
658
683
  return member === void 0 ? void 0 : contributedResolution(member);
659
684
  }
685
+ *ownNames() {
686
+ for (const [name] of this.#registry.entries()) yield name;
687
+ }
660
688
  };
661
- var DocumentScope = class {
689
+ var DocumentScope = class extends Scope {
662
690
  #records;
663
- #parent;
664
691
  constructor(records, parent) {
692
+ super(parent);
665
693
  this.#records = records;
666
- this.#parent = parent;
667
694
  }
668
695
  lookup(name) {
669
696
  const records = this.#records;
@@ -692,18 +719,25 @@ var DocumentScope = class {
692
719
  kind: "namespace",
693
720
  symbol: namespace
694
721
  };
695
- return this.#parent?.lookup(name);
722
+ return this.parent?.lookup(name);
723
+ }
724
+ ownNames() {
725
+ const records = this.#records;
726
+ return recordNames(records.models, records.compositeTypes, records.namedTypes, records.blocks, records.namespaces);
696
727
  }
697
728
  };
698
- var NamespaceScope = class {
729
+ var NamespaceScope = class extends Scope {
699
730
  #namespace;
700
- #parent;
701
731
  constructor(namespace, parent) {
732
+ super(parent);
702
733
  this.#namespace = namespace;
703
- this.#parent = parent;
704
734
  }
705
735
  lookup(name) {
706
- return namespaceMember(this.#namespace, name) ?? this.#parent.lookup(name);
736
+ return namespaceMember(this.#namespace, name) ?? this.parent?.lookup(name);
737
+ }
738
+ ownNames() {
739
+ const namespace = this.#namespace;
740
+ return recordNames(namespace.models, namespace.compositeTypes, namespace.blocks);
707
741
  }
708
742
  };
709
743
  function contributedScope(registry) {
@@ -718,6 +752,13 @@ function namespaceScope(namespace, parent) {
718
752
  function isNamespaceLike(resolution) {
719
753
  return resolution.kind === "namespace" || resolution.kind === "contributedNamespace";
720
754
  }
755
+ function* memberEntries(qualifier) {
756
+ if (qualifier.kind === "contributedNamespace") {
757
+ for (const [name, member] of qualifier.symbol.members) yield [name, contributedResolution(member)];
758
+ return;
759
+ }
760
+ yield* new NamespaceScope(qualifier.symbol, void 0).entries();
761
+ }
721
762
  function lookupMember(qualifier, name) {
722
763
  if (qualifier.kind === "contributedNamespace") {
723
764
  const member = qualifier.symbol.members.get(name);
@@ -726,15 +767,19 @@ function lookupMember(qualifier, name) {
726
767
  return namespaceMember(qualifier.symbol, name);
727
768
  }
728
769
  const PSL_UNRESOLVED_REFERENCE = "PSL_UNRESOLVED_REFERENCE";
729
- function typeReferenceNode(field) {
730
- return field.node.typeAnnotation()?.name()?.syntax;
770
+ function typeReferenceNode(symbol) {
771
+ return symbol.node.typeAnnotation()?.name()?.syntax;
731
772
  }
732
773
  var PslBinder = class {
733
774
  #declarations;
734
775
  #references;
735
- constructor(declarations, references) {
776
+ #documentScope;
777
+ #scopes;
778
+ constructor(declarations, references, documentScope, scopes) {
736
779
  this.#declarations = declarations;
737
780
  this.#references = references;
781
+ this.#documentScope = documentScope;
782
+ this.#scopes = scopes;
738
783
  }
739
784
  declaredSymbol(node) {
740
785
  return this.#declarations.get(node);
@@ -742,6 +787,9 @@ var PslBinder = class {
742
787
  symbolForNode(node) {
743
788
  return this.#references.get(node);
744
789
  }
790
+ scopeAt(node) {
791
+ return node.findAncestor((ancestor) => this.#scopes.get(ancestor)) ?? this.#documentScope;
792
+ }
745
793
  };
746
794
  var ScopeStack = class {
747
795
  #base;
@@ -760,12 +808,12 @@ var ScopeStack = class {
760
808
  this.#scopes.pop();
761
809
  }
762
810
  };
763
- function walkEntities(symbolTable, stack, visit) {
811
+ function walkEntities(symbolTable, stack, binder, visit) {
764
812
  const { topLevel } = symbolTable;
765
813
  for (const entity of Object.values(topLevel.models)) visit(entity);
766
814
  for (const entity of Object.values(topLevel.compositeTypes)) visit(entity);
767
815
  for (const namespace of Object.values(topLevel.namespaces)) {
768
- stack.push(namespaceScope(namespace, stack.current()));
816
+ stack.push(binder.scopeAt(namespace.declarations[0].node.syntax));
769
817
  for (const entity of Object.values(namespace.models)) visit(entity);
770
818
  for (const entity of Object.values(namespace.compositeTypes)) visit(entity);
771
819
  stack.pop();
@@ -774,24 +822,35 @@ function walkEntities(symbolTable, stack, visit) {
774
822
  function createBinder(options) {
775
823
  const { sources, symbolTable, typeConstructors, attributeSpecs, controlMutationDefaults, describeUnsupportedAttribute } = options;
776
824
  const pslBlockDescriptors = options.pslBlockDescriptors ?? {};
777
- const stack = new ScopeStack(documentScope(symbolTable.topLevel, contributedScope(contributedTypeScope(typeConstructors))));
825
+ const document = documentScope(symbolTable.topLevel, contributedScope(contributedTypeScope(typeConstructors)));
826
+ const stack = new ScopeStack(document);
827
+ const scopes = /* @__PURE__ */ new WeakMap();
778
828
  const declarations = /* @__PURE__ */ new WeakMap();
779
829
  const references = /* @__PURE__ */ new WeakMap();
780
830
  const diagnostics = [];
781
- const binder = new PslBinder(declarations, references);
782
- for (const symbol of Object.values(symbolTable.topLevel.namedTypes)) declarations.set(symbol.node.syntax, symbol);
831
+ const binder = new PslBinder(declarations, references, document, scopes);
832
+ for (const symbol of Object.values(symbolTable.topLevel.namedTypes)) {
833
+ declarations.set(symbol.node.syntax, symbol);
834
+ const name = symbol.node.typeAnnotation()?.name();
835
+ const outcome = resolveTypeReference(name, document);
836
+ if (name !== void 0 && outcome !== void 0) references.set(name.syntax, outcome.resolution);
837
+ }
783
838
  for (const symbol of Object.values(symbolTable.topLevel.blocks)) declarations.set(symbol.node.syntax, symbol);
784
839
  for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
785
- for (const declaration of namespace.declarations) declarations.set(declaration.node.syntax, namespace);
840
+ const scope = namespaceScope(namespace, document);
841
+ for (const declaration of namespace.declarations) {
842
+ declarations.set(declaration.node.syntax, namespace);
843
+ scopes.set(declaration.node.syntax, scope);
844
+ }
786
845
  for (const symbol of Object.values(namespace.blocks)) declarations.set(symbol.node.syntax, symbol);
787
846
  }
788
- walkEntities(symbolTable, stack, (entity) => {
847
+ walkEntities(symbolTable, stack, binder, (entity) => {
789
848
  declarations.set(entity.node.syntax, entity);
790
849
  for (const field of Object.values(entity.fields)) {
791
850
  declarations.set(field.node.syntax, field);
792
851
  const node = typeReferenceNode(field);
793
852
  if (node === void 0) continue;
794
- const outcome = resolveTypeReference(field, stack.current());
853
+ const outcome = resolveTypeReference(field.node.typeAnnotation()?.name(), stack.current());
795
854
  if (outcome === void 0) continue;
796
855
  references.set(node, outcome.resolution);
797
856
  if (outcome.message !== void 0) diagnostics.push({
@@ -806,7 +865,7 @@ function createBinder(options) {
806
865
  });
807
866
  }
808
867
  });
809
- walkEntities(symbolTable, stack, (entity) => {
868
+ walkEntities(symbolTable, stack, binder, (entity) => {
810
869
  const context = {
811
870
  owner: entity,
812
871
  scope: stack.current(),
@@ -849,7 +908,7 @@ function createBinder(options) {
849
908
  };
850
909
  bindBlocks(symbolTable.topLevel.blocks);
851
910
  for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
852
- stack.push(namespaceScope(namespace, stack.current()));
911
+ stack.push(binder.scopeAt(namespace.declarations[0].node.syntax));
853
912
  bindBlocks(namespace.blocks);
854
913
  stack.pop();
855
914
  }
@@ -1132,12 +1191,12 @@ function report(message, node, ctx, reference) {
1132
1191
  ...diagnosticSource(ctx.sources, node).at()
1133
1192
  });
1134
1193
  }
1135
- function resolveTypeReference(field, scope) {
1136
- if (field.malformedType === true) return void 0;
1137
- if (field.typeContractSpaceId !== void 0) return { resolution: { kind: "crossSpace" } };
1138
- const name = field.typeName;
1139
- if (name === "") return void 0;
1140
- const namespaceId = field.typeNamespaceId;
1194
+ function resolveTypeReference(reference, scope) {
1195
+ if (reference === void 0 || reference.isOverQualified()) return void 0;
1196
+ if (reference.space() !== void 0) return { resolution: { kind: "crossSpace" } };
1197
+ const name = reference.identifier()?.name();
1198
+ if (name === void 0 || name === "") return void 0;
1199
+ const namespaceId = reference.namespace()?.name();
1141
1200
  const found = namespaceId === void 0 ? scope.lookup(name) : qualifiedMember(namespaceId, name, scope);
1142
1201
  if (found === void 0) {
1143
1202
  const written = namespaceId === void 0 ? name : `${namespaceId}.${name}`;
@@ -1474,13 +1533,19 @@ function buildSymbolTable(options) {
1474
1533
  namespace = {
1475
1534
  kind: "namespace",
1476
1535
  name,
1477
- declarations: [],
1536
+ declarations: [{
1537
+ node: declaration,
1538
+ span: nodePslSpan(declaration.syntax, sources)
1539
+ }],
1478
1540
  models: Object.create(null),
1479
1541
  compositeTypes: Object.create(null),
1480
1542
  blocks: Object.create(null)
1481
1543
  };
1482
1544
  namespaces[name] = namespace;
1483
- }
1545
+ } else namespace.declarations.push({
1546
+ node: declaration,
1547
+ span: nodePslSpan(declaration.syntax, sources)
1548
+ });
1484
1549
  extendNamespace(namespace, declaration, diagnostics, sources);
1485
1550
  } else if (declaration instanceof TypesBlockAst) for (const binding of declaration.declarations()) {
1486
1551
  const name = claim(topLevelNames, binding.name());
@@ -1537,10 +1602,6 @@ function buildBlock(name, node, sources) {
1537
1602
  }
1538
1603
  function extendNamespace(namespace, node, diagnostics, sources) {
1539
1604
  const { models, compositeTypes, blocks } = namespace;
1540
- namespace.declarations.push({
1541
- node,
1542
- span: nodePslSpan(node.syntax, sources)
1543
- });
1544
1605
  for (const member of node.declarations()) {
1545
1606
  const memberName = member.name()?.name();
1546
1607
  if (memberName === void 0) continue;
@@ -1651,6 +1712,6 @@ function nodeRange(node, sources) {
1651
1712
  };
1652
1713
  }
1653
1714
  //#endregion
1654
- export { NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, assembleAttributeSpecs, blockAttribute, blockSpecFactoryOf, bool, buildSymbolTable, createBinder, createPslDiagnosticCollector, diagnosticFromSpan, diagnosticSource, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, interpretExtensionBlock, interpretExtensionBlockAttributes, interpretExtensionBlocks, isPrismaNextSchema, isPslIdentifier, json, jsonValue, keywordPslSpan, leafDiagnostic, list, mapBlock, mapPslDiagnostics, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, referencedFieldRef, renameLegacyDirective, str, structBlock, taggedLiteral, typeReferenceNode };
1715
+ export { NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, assembleAttributeSpecs, blockAttribute, blockSpecFactoryOf, bool, buildSymbolTable, createBinder, createPslDiagnosticCollector, diagnosticFromSpan, diagnosticSource, entityRef, entityReference, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, interpretExtensionBlock, interpretExtensionBlockAttributes, interpretExtensionBlocks, isNamespaceLike, isPrismaNextSchema, isPslIdentifier, json, jsonValue, keywordPslSpan, leafDiagnostic, list, mapBlock, mapPslDiagnostics, matchesSelector, memberEntries, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, referencedFieldRef, renameLegacyDirective, str, structBlock, taggedLiteral, typeReferenceNode };
1655
1716
 
1656
1717
  //# sourceMappingURL=psl-parser.mjs.map