@prisma/orm-framework 8.0.0-rc.12-dev.5 → 8.0.0-rc.12-dev.7

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 (43) hide show
  1. package/dist/components.d.mts +1 -1
  2. package/dist/components__control.d.mts +1 -1
  3. package/dist/{config-types-DFbRLLoj.d.mts → config-types-DuuEJ0He.d.mts} +3 -3
  4. package/dist/{config-types-DFbRLLoj.d.mts.map → config-types-DuuEJ0He.d.mts.map} +1 -1
  5. package/dist/config.d.mts +1 -1
  6. package/dist/config__config-types.d.mts +1 -1
  7. package/dist/{control-daWTOzIt.d.mts → control-BANcoCty.d.mts} +2 -2
  8. package/dist/{control-daWTOzIt.d.mts.map → control-BANcoCty.d.mts.map} +1 -1
  9. package/dist/{declarations-SwNXosDu-D2vp62Qo.mjs → declarations-D79GooqC-BhBEz1Kc.mjs} +47 -29
  10. package/dist/declarations-D79GooqC-BhBEz1Kc.mjs.map +1 -0
  11. package/dist/errors.d.mts +1 -1
  12. package/dist/errors__execution.d.mts +1 -1
  13. package/dist/{execution-shS9XY88.d.mts → execution-Chfc3cj8.d.mts} +2 -2
  14. package/dist/{execution-shS9XY88.d.mts.map → execution-Chfc3cj8.d.mts.map} +1 -1
  15. package/dist/{parse-DT0CXbYQ-BsAldB1g.mjs → parse-DN-F4ASD-CdISnhAA.mjs} +3 -3
  16. package/dist/{parse-DT0CXbYQ-BsAldB1g.mjs.map → parse-DN-F4ASD-CdISnhAA.mjs.map} +1 -1
  17. package/dist/{parse-Cc94-3I4-CNqJmnMR.d.mts → parse-SHpUIBnv-DTmN_vgC.d.mts} +6 -4
  18. package/dist/parse-SHpUIBnv-DTmN_vgC.d.mts.map +1 -0
  19. package/dist/psl-parser.d.mts +104 -8
  20. package/dist/psl-parser.d.mts.map +1 -1
  21. package/dist/psl-parser.mjs +505 -79
  22. package/dist/psl-parser.mjs.map +1 -1
  23. package/dist/psl-parser__format.mjs +2 -2
  24. package/dist/psl-parser__format.mjs.map +1 -1
  25. package/dist/psl-parser__interpret.d.mts +4 -4
  26. package/dist/psl-parser__interpret.mjs +1 -1
  27. package/dist/psl-parser__syntax.d.mts +1 -1
  28. package/dist/psl-parser__syntax.mjs +2 -2
  29. package/dist/psl-parser__syntax.mjs.map +1 -1
  30. package/dist/{result-C0NUq1Ok.mjs → result-8OXF26MN.mjs} +13 -2
  31. package/dist/{result-C0NUq1Ok.mjs.map → result-8OXF26MN.mjs.map} +1 -1
  32. package/dist/{result-Bpupv5vO.d.mts → result-BYCOANWy.d.mts} +4 -2
  33. package/dist/result-BYCOANWy.d.mts.map +1 -0
  34. package/dist/{symbol-table-BKzfcqoT-6qb_OZnS.d.mts → symbol-table-DVPEY1fq-Ch1nLrFN.d.mts} +3 -3
  35. package/dist/{symbol-table-BKzfcqoT-6qb_OZnS.d.mts.map → symbol-table-DVPEY1fq-Ch1nLrFN.d.mts.map} +1 -1
  36. package/dist/utils.d.mts +2 -2
  37. package/dist/utils.mjs +2 -2
  38. package/dist/utils__result.d.mts +2 -2
  39. package/dist/utils__result.mjs +2 -2
  40. package/package.json +15 -15
  41. package/dist/declarations-SwNXosDu-D2vp62Qo.mjs.map +0 -1
  42. package/dist/parse-Cc94-3I4-CNqJmnMR.d.mts.map +0 -1
  43. package/dist/result-Bpupv5vO.d.mts.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { t as blindCast } from "./casts-DpaahrlC-Bd5n2coI.mjs";
2
2
  import { t as InternalError } from "./internal-error-ChGYPVpq-DhUD05u0.mjs";
3
- import { n as ok, t as notOk } from "./result-C0NUq1Ok.mjs";
4
- import { h as isAuthoringPslBlockDescriptor, m as isAuthoringModelAttributeDescriptor } from "./framework-authoring-bUu_R58O-Cr-Mz1dC.mjs";
3
+ import { a as or, i as okVoid, n as notOk, r as ok, t as and } from "./result-8OXF26MN.mjs";
4
+ import { g as isAuthoringTypeConstructorDescriptor, h as isAuthoringPslBlockDescriptor, m as isAuthoringModelAttributeDescriptor } from "./framework-authoring-bUu_R58O-Cr-Mz1dC.mjs";
5
5
  import { a as makePslNamespace, c as validateExtensionBlock, i as flatPslModels, n as UNSPECIFIED_PSL_NAMESPACE_ID, o as makePslNamespaceEntries, s as namespacePslExtensionBlocks } from "./psl-ast-DUCvVXbB.mjs";
6
- import { D as TypesBlockAst, P as printSyntax, _ 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, w as TaggedLiteralExprAst, x as StringLiteralExprAst, y as ObjectLiteralExprAst } from "./declarations-SwNXosDu-D2vp62Qo.mjs";
6
+ import { D as TypesBlockAst, P as printSyntax, _ 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, w as TaggedLiteralExprAst, x as StringLiteralExprAst, y as ObjectLiteralExprAst } from "./declarations-D79GooqC-BhBEz1Kc.mjs";
7
7
  import { i as mapPslDiagnostics, n as diagnosticFromSpan, r as diagnosticSource, t as createPslDiagnosticCollector } from "./diagnostic-Esyl8Qw1-Cd6SnWPN.mjs";
8
8
  //#region ../../../1-framework/2-authoring/psl-parser/dist/index.mjs
9
9
  function getPositionalArgument(attribute, index = 0) {
@@ -130,37 +130,41 @@ function bool() {
130
130
  };
131
131
  }
132
132
  const references = /* @__PURE__ */ new WeakMap();
133
- function resolveEntityReference(expression, name, symbols) {
134
- const namespaceName = expression.syntax.findAncestor(NamespaceDeclarationAst.cast)?.name()?.name();
135
- const namespace = namespaceName === void 0 ? void 0 : ownValue(symbols.topLevel.namespaces, namespaceName);
136
- if (namespace !== void 0) {
137
- const declaration = declarationIn(namespace, name);
138
- if (declaration !== void 0) return referenceFor(namespace, declaration, namespace);
133
+ function entityReference(resolution) {
134
+ switch (resolution.kind) {
135
+ case "model":
136
+ case "compositeType":
137
+ case "namedType":
138
+ case "block": return interned(resolution.symbol, resolution.namespace);
139
+ default: return;
139
140
  }
140
- const declaration = declarationIn(symbols.topLevel, name);
141
- return declaration === void 0 ? void 0 : referenceFor(symbols.topLevel, declaration, void 0);
142
141
  }
143
- function ownValue(values, name) {
144
- return Object.hasOwn(values, name) ? values[name] : void 0;
145
- }
146
- function declarationIn(scope, name) {
147
- return ownValue(scope.models, name) ?? ownValue(scope.compositeTypes, name) ?? ownValue(scope.blocks, name) ?? ("namedTypes" in scope ? ownValue(scope.namedTypes, name) : void 0);
142
+ function interned(declaration, namespace) {
143
+ const existing = references.get(declaration);
144
+ if (existing !== void 0) return existing;
145
+ const reference = {
146
+ declaration,
147
+ namespace
148
+ };
149
+ references.set(declaration, reference);
150
+ return reference;
148
151
  }
149
- function referenceFor(scope, declaration, namespace) {
150
- let byDeclaration = references.get(scope);
151
- if (byDeclaration === void 0) {
152
- byDeclaration = /* @__PURE__ */ new WeakMap();
153
- references.set(scope, byDeclaration);
154
- }
155
- let reference = byDeclaration.get(declaration);
156
- if (reference === void 0) {
157
- reference = {
158
- declaration,
159
- namespace
160
- };
161
- byDeclaration.set(declaration, reference);
152
+ function matchesSelector(reference, expected) {
153
+ const declaration = reference.declaration;
154
+ if (declaration.kind !== expected.kind) return false;
155
+ return expected.kind !== "block" || declaration.kind === "block" && declaration.keyword === expected.keyword;
156
+ }
157
+ function describeResolution(resolution) {
158
+ switch (resolution.kind) {
159
+ case "block": return resolution.symbol.keyword;
160
+ case "contributedType": return "scalar type";
161
+ case "crossSpace": return "cross-space reference";
162
+ case "unresolved": return "unresolved name";
163
+ default: return resolution.kind;
162
164
  }
163
- return reference;
165
+ }
166
+ function unbound(name) {
167
+ throw new InternalError(`The binder on this attribute context bound nothing for "${name}". A reference argument is always examined, so the binder must be built over the same snapshot - the same symbol table and sources - as the interpretation consuming it.`);
164
168
  }
165
169
  function entityRef(expected) {
166
170
  const label = `${expected.kind === "block" ? expected.keyword : expected.kind} reference`;
@@ -171,45 +175,41 @@ function entityRef(expected) {
171
175
  parse: (arg, ctx) => {
172
176
  const name = IdentifierAst.cast(arg.syntax)?.name();
173
177
  if (name === void 0) return notOk([leafDiagnostic(ctx, arg, `Expected ${label}`)]);
174
- const reference = resolveEntityReference(arg, name, ctx.symbols);
175
- if (reference === void 0) return notOk([leafDiagnostic(ctx, arg, `Unknown ${label} "${name}"`)]);
176
- if (!matchesSelector(reference, expected)) {
177
- const actual = reference.declaration;
178
- const kind = actual.kind === "block" ? actual.keyword : actual.kind;
179
- return notOk([leafDiagnostic(ctx, arg, `Expected ${label} "${name}", found ${kind}`)]);
180
- }
178
+ const resolution = ctx.binder.symbolForNode(arg.syntax) ?? unbound(name);
179
+ if (resolution.kind === "unresolved") return notOk([]);
180
+ const reference = entityReference(resolution);
181
+ if (reference === void 0 || !matchesSelector(reference, expected)) return notOk([leafDiagnostic(ctx, arg, `Expected ${label} "${name}", found ${describeResolution(resolution)}`)]);
181
182
  return ok(reference);
182
183
  }
183
184
  };
184
185
  }
185
- function matchesSelector(reference, expected) {
186
- const declaration = reference.declaration;
187
- return declaration.kind === expected.kind && (expected.kind !== "block" || declaration.kind === "block" && declaration.keyword === expected.keyword);
188
- }
189
- function parseFieldName(arg, ctx, model) {
186
+ function parseFieldName(arg, ctx) {
190
187
  const identifier = IdentifierAst.cast(arg.syntax);
191
188
  if (identifier === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
192
189
  const name = identifier.name();
193
190
  if (name === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected a field name")]);
194
- if (model !== void 0 && !Object.hasOwn(model.fields, name)) return notOk([leafDiagnostic(ctx, arg, `Field "${name}" does not exist on model "${model.name}"`)]);
195
- return ok(name);
191
+ const resolution = ctx.binder.symbolForNode(arg.syntax);
192
+ if (resolution === void 0) throw new InternalError(`The binder on this attribute context bound nothing for "${name}". A reference argument is always examined, so the binder must be built over the same snapshot - the same symbol table and sources - as the interpretation consuming it.`);
193
+ if (resolution.kind === "field") return ok(resolution.symbol.name);
194
+ if (resolution.kind === "crossSpace") return ok(name);
195
+ return notOk([]);
196
196
  }
197
197
  function fieldRef() {
198
198
  return {
199
199
  kind: "fieldRef",
200
200
  label: "field name",
201
- parse: (arg, ctx) => parseFieldName(arg, ctx, ctx.selfModel)
201
+ parse: (arg, ctx) => parseFieldName(arg, ctx)
202
202
  };
203
203
  }
204
204
  function referencedFieldRef() {
205
205
  return {
206
206
  kind: "referencedFieldRef",
207
207
  label: "field name",
208
- parse: (arg, ctx) => parseFieldName(arg, ctx, ctx.resolveReferencedModel())
208
+ parse: (arg, ctx) => parseFieldName(arg, ctx)
209
209
  };
210
210
  }
211
211
  function interpretArgs(args, spec, ctx, span, sourceNode) {
212
- const diagnostics = [];
212
+ let outcome = okVoid();
213
213
  const output = {};
214
214
  const seen = /* @__PURE__ */ new Set();
215
215
  let positionalSlot = 0;
@@ -222,7 +222,7 @@ function interpretArgs(args, spec, ctx, span, sourceNode) {
222
222
  const posParam = spec.positional[positionalSlot];
223
223
  if (posParam === void 0) {
224
224
  if (!reportedExcess) {
225
- diagnostics.push(diagnostic(`Attribute "${spec.name}" received too many positional arguments`, ctx, span, sourceNode));
225
+ outcome = and(outcome, notOk([diagnostic(`Attribute "${spec.name}" received too many positional arguments`, ctx, span, sourceNode)]));
226
226
  reportedExcess = true;
227
227
  }
228
228
  continue;
@@ -233,19 +233,20 @@ function interpretArgs(args, spec, ctx, span, sourceNode) {
233
233
  } else {
234
234
  const namedParam = Object.hasOwn(spec.named, name) ? spec.named[name] : void 0;
235
235
  if (namedParam === void 0) {
236
- diagnostics.push(diagnostic(`Attribute "${spec.name}" received unknown argument "${name}"`, ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax));
236
+ outcome = and(outcome, notOk([diagnostic(`Attribute "${spec.name}" received unknown argument "${name}"`, ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax)]));
237
237
  continue;
238
238
  }
239
239
  key = name;
240
240
  param = namedParam.type;
241
241
  }
242
242
  if (seen.has(key)) {
243
- diagnostics.push(diagnostic(`Attribute "${spec.name}" received duplicate argument "${key}"`, ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax));
243
+ outcome = and(outcome, notOk([diagnostic(`Attribute "${spec.name}" received duplicate argument "${key}"`, ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax)]));
244
244
  continue;
245
245
  }
246
246
  seen.add(key);
247
- const result = parseArgValue(arg, param, ctx, diagnostics);
247
+ const result = parseArgValue(arg, param, ctx);
248
248
  if (result.ok) output[key] = result.value;
249
+ outcome = and(outcome, result);
249
250
  }
250
251
  const finalized = /* @__PURE__ */ new Set();
251
252
  const finalizeAbsentKey = (key, positionalParam, namedParam) => {
@@ -257,14 +258,14 @@ function interpretArgs(args, spec, ctx, span, sourceNode) {
257
258
  if (effective.hasDefault) output[key] = effective.defaultValue;
258
259
  return;
259
260
  }
260
- diagnostics.push(diagnostic(`Attribute "${spec.name}" is missing required argument "${key}"`, ctx, span, sourceNode));
261
+ outcome = and(outcome, notOk([diagnostic(`Attribute "${spec.name}" is missing required argument "${key}"`, ctx, span, sourceNode)]));
261
262
  };
262
263
  for (const param of spec.positional) {
263
264
  const namedParam = Object.hasOwn(spec.named, param.key) ? spec.named[param.key] : void 0;
264
265
  finalizeAbsentKey(param.key, param.type, namedParam?.type);
265
266
  }
266
267
  for (const key of Object.keys(spec.named)) finalizeAbsentKey(key, void 0, spec.named[key]?.type);
267
- if (diagnostics.length > 0) return notOk(diagnostics);
268
+ if (!outcome.ok) return notOk(outcome.failure);
268
269
  return ok(output);
269
270
  }
270
271
  function interpretAttribute(attrNode, spec, ctx) {
@@ -278,16 +279,10 @@ function interpretAttribute(attrNode, spec, ctx) {
278
279
  }
279
280
  return ok(value);
280
281
  }
281
- function parseArgValue(arg, argType, ctx, diagnostics) {
282
+ function parseArgValue(arg, argType, ctx) {
282
283
  const value = arg.value();
283
- if (value === void 0) {
284
- const missing = diagnostic("Attribute argument is missing a value", ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax);
285
- diagnostics.push(missing);
286
- return notOk([missing]);
287
- }
288
- const result = argType.parse(value, ctx);
289
- if (!result.ok) for (const failure of result.failure) diagnostics.push(failure);
290
- return result;
284
+ if (value === void 0) return notOk([diagnostic("Attribute argument is missing a value", ctx, nodePslSpan(arg.syntax, ctx.sources), arg.syntax)]);
285
+ return argType.parse(value, ctx);
291
286
  }
292
287
  function isOptionalArgType(param) {
293
288
  return "optional" in param && param.optional === true;
@@ -406,8 +401,8 @@ function list(of, opts) {
406
401
  parse: (arg, ctx) => {
407
402
  const literal = ArrayLiteralAst.cast(arg.syntax);
408
403
  if (literal === void 0) return notOk([leafDiagnostic(ctx, arg, `Expected a list of ${of.label}`)]);
409
- const diagnostics = [];
410
404
  const parsed = [];
405
+ let outcome = okVoid();
411
406
  let count = 0;
412
407
  for (const element of literal.elements()) {
413
408
  count += 1;
@@ -416,15 +411,15 @@ function list(of, opts) {
416
411
  node: element,
417
412
  value: result.value
418
413
  });
419
- else diagnostics.push(...result.failure);
414
+ outcome = and(outcome, result);
420
415
  }
421
- if (!allowEmpty && count === 0) diagnostics.push(leafDiagnostic(ctx, arg, "Expected a non-empty list"));
416
+ if (!allowEmpty && count === 0) outcome = and(outcome, notOk([leafDiagnostic(ctx, arg, "Expected a non-empty list")]));
422
417
  if (unique) {
423
418
  const seen = /* @__PURE__ */ new Set();
424
- for (const { node, value } of parsed) if (seen.has(value)) diagnostics.push(leafDiagnostic(ctx, node, "Duplicate list entry"));
419
+ for (const { node, value } of parsed) if (seen.has(value)) outcome = and(outcome, notOk([leafDiagnostic(ctx, node, "Duplicate list entry")]));
425
420
  else seen.add(value);
426
421
  }
427
- if (diagnostics.length > 0) return notOk(diagnostics);
422
+ if (!outcome.ok) return notOk(outcome.failure);
428
423
  return ok(parsed.map((entry) => entry.value));
429
424
  }
430
425
  };
@@ -476,10 +471,15 @@ function oneOf(...alts) {
476
471
  label,
477
472
  alternatives: alts,
478
473
  parse: (arg, ctx) => {
479
- for (const alt of alts) {
480
- const result = blindCast(alt.parse)(arg, ctx);
481
- if (result.ok) return ok(blindCast(result.value));
474
+ const [head, ...tail] = blindCast(alts);
475
+ let rejection = head.parse(arg, ctx);
476
+ if (rejection.ok) return rejection;
477
+ for (const alt of tail) {
478
+ const result = alt.parse(arg, ctx);
479
+ if (result.ok) return result;
480
+ rejection = or(rejection, result);
482
481
  }
482
+ if (!rejection.ok && rejection.failure.length === 0) return notOk([]);
483
483
  return notOk([leafDiagnostic(ctx, arg, `Expected one of: ${label}`)]);
484
484
  }
485
485
  };
@@ -492,33 +492,33 @@ function record(of) {
492
492
  parse: (arg, ctx) => {
493
493
  const literal = ObjectLiteralExprAst.cast(arg.syntax);
494
494
  if (literal === void 0) return notOk([leafDiagnostic(ctx, arg, "Expected an object literal")]);
495
- const diagnostics = [];
496
495
  const entries = [];
497
496
  const keys = /* @__PURE__ */ new Set();
497
+ let outcome = okVoid();
498
498
  for (const field of Array.from(literal.fields())) {
499
499
  const key = field.keyName();
500
500
  if (key === void 0) {
501
- diagnostics.push(leafDiagnostic(ctx, field, "Expected a key"));
501
+ outcome = and(outcome, notOk([leafDiagnostic(ctx, field, "Expected a key")]));
502
502
  continue;
503
503
  }
504
504
  const value = field.value();
505
505
  if (value === void 0) {
506
- diagnostics.push(leafDiagnostic(ctx, field, `Expected a value for key "${key}"`));
506
+ outcome = and(outcome, notOk([leafDiagnostic(ctx, field, `Expected a value for key "${key}"`)]));
507
507
  continue;
508
508
  }
509
509
  const parsed = of.parse(value, ctx);
510
510
  if (!parsed.ok) {
511
- diagnostics.push(...parsed.failure);
511
+ outcome = and(outcome, parsed);
512
512
  continue;
513
513
  }
514
514
  if (keys.has(key)) {
515
- diagnostics.push(leafDiagnostic(ctx, field, `Duplicate key "${key}"`));
515
+ outcome = and(outcome, notOk([leafDiagnostic(ctx, field, `Duplicate key "${key}"`)]));
516
516
  continue;
517
517
  }
518
518
  keys.add(key);
519
519
  entries.push([key, parsed.value]);
520
520
  }
521
- if (diagnostics.length > 0) return notOk(diagnostics);
521
+ if (!outcome.ok) return notOk(outcome.failure);
522
522
  return ok(Object.fromEntries(entries));
523
523
  }
524
524
  };
@@ -577,7 +577,7 @@ function fieldAttribute(name, config) {
577
577
  name,
578
578
  documentation: config.documentation,
579
579
  positional: config.positional ?? [],
580
- named: config.named ?? {},
580
+ named: Object.assign(Object.create(null), config.named),
581
581
  ...config.refine !== void 0 ? { refine: config.refine } : {}
582
582
  };
583
583
  }
@@ -587,7 +587,7 @@ function modelAttribute(name, config) {
587
587
  name,
588
588
  documentation: config.documentation,
589
589
  positional: config.positional ?? [],
590
- named: config.named ?? {},
590
+ named: Object.assign(Object.create(null), config.named),
591
591
  ...config.refine !== void 0 ? { refine: config.refine } : {}
592
592
  };
593
593
  }
@@ -604,6 +604,432 @@ function optional(type, ...rest) {
604
604
  defaultValue: rest[0]
605
605
  };
606
606
  }
607
+ const scopes = /* @__PURE__ */ new WeakMap();
608
+ function contributedTypeScope(typeConstructors) {
609
+ const existing = scopes.get(typeConstructors);
610
+ if (existing !== void 0) return existing;
611
+ const members = collect(typeConstructors, []);
612
+ const created = { lookup(name) {
613
+ return members.get(name);
614
+ } };
615
+ scopes.set(typeConstructors, created);
616
+ return created;
617
+ }
618
+ function collect(namespace, prefix) {
619
+ const members = /* @__PURE__ */ new Map();
620
+ for (const [name, value] of Object.entries(namespace)) {
621
+ const path = [...prefix, name];
622
+ members.set(name, isAuthoringTypeConstructorDescriptor(value) ? {
623
+ kind: "contributedType",
624
+ name,
625
+ path,
626
+ descriptor: value
627
+ } : {
628
+ kind: "contributedNamespace",
629
+ name,
630
+ path,
631
+ members: collect(value, path)
632
+ });
633
+ }
634
+ return members;
635
+ }
636
+ function contributedResolution(member) {
637
+ return member.kind === "contributedType" ? {
638
+ kind: "contributedType",
639
+ symbol: member
640
+ } : {
641
+ kind: "contributedNamespace",
642
+ symbol: member
643
+ };
644
+ }
645
+ function namespaceMember(namespace, name) {
646
+ const model = namespace.models[name];
647
+ if (model !== void 0) return {
648
+ kind: "model",
649
+ symbol: model,
650
+ namespace
651
+ };
652
+ const compositeType = namespace.compositeTypes[name];
653
+ if (compositeType !== void 0) return {
654
+ kind: "compositeType",
655
+ symbol: compositeType,
656
+ namespace
657
+ };
658
+ const block = namespace.blocks[name];
659
+ if (block !== void 0) return {
660
+ kind: "block",
661
+ symbol: block,
662
+ namespace
663
+ };
664
+ }
665
+ var ContributedScope = class {
666
+ #registry;
667
+ constructor(registry) {
668
+ this.#registry = registry;
669
+ }
670
+ lookup(name) {
671
+ const member = this.#registry.lookup(name);
672
+ return member === void 0 ? void 0 : contributedResolution(member);
673
+ }
674
+ };
675
+ var DocumentScope = class {
676
+ #records;
677
+ #parent;
678
+ constructor(records, parent) {
679
+ this.#records = records;
680
+ this.#parent = parent;
681
+ }
682
+ lookup(name) {
683
+ const records = this.#records;
684
+ const model = records.models[name];
685
+ if (model !== void 0) return {
686
+ kind: "model",
687
+ symbol: model
688
+ };
689
+ const compositeType = records.compositeTypes[name];
690
+ if (compositeType !== void 0) return {
691
+ kind: "compositeType",
692
+ symbol: compositeType
693
+ };
694
+ const namedType = records.namedTypes[name];
695
+ if (namedType !== void 0) return {
696
+ kind: "namedType",
697
+ symbol: namedType
698
+ };
699
+ const block = records.blocks[name];
700
+ if (block !== void 0) return {
701
+ kind: "block",
702
+ symbol: block
703
+ };
704
+ const namespace = records.namespaces[name];
705
+ if (namespace !== void 0) return {
706
+ kind: "namespace",
707
+ symbol: namespace
708
+ };
709
+ return this.#parent?.lookup(name);
710
+ }
711
+ };
712
+ var NamespaceScope = class {
713
+ #namespace;
714
+ #parent;
715
+ constructor(namespace, parent) {
716
+ this.#namespace = namespace;
717
+ this.#parent = parent;
718
+ }
719
+ lookup(name) {
720
+ return namespaceMember(this.#namespace, name) ?? this.#parent.lookup(name);
721
+ }
722
+ };
723
+ function contributedScope(registry) {
724
+ return new ContributedScope(registry);
725
+ }
726
+ function documentScope(records, parent) {
727
+ return new DocumentScope(records, parent);
728
+ }
729
+ function namespaceScope(namespace, parent) {
730
+ return new NamespaceScope(namespace, parent);
731
+ }
732
+ function isNamespaceLike(resolution) {
733
+ return resolution.kind === "namespace" || resolution.kind === "contributedNamespace";
734
+ }
735
+ function lookupMember(qualifier, name) {
736
+ if (qualifier.kind === "contributedNamespace") {
737
+ const member = qualifier.symbol.members.get(name);
738
+ return member === void 0 ? void 0 : contributedResolution(member);
739
+ }
740
+ return namespaceMember(qualifier.symbol, name);
741
+ }
742
+ const PSL_UNRESOLVED_REFERENCE = "PSL_UNRESOLVED_REFERENCE";
743
+ function typeReferenceNode(field) {
744
+ return field.node.typeAnnotation()?.name()?.syntax;
745
+ }
746
+ var PslBinder = class {
747
+ #declarations;
748
+ #references;
749
+ constructor(declarations, references) {
750
+ this.#declarations = declarations;
751
+ this.#references = references;
752
+ }
753
+ declaredSymbol(node) {
754
+ return this.#declarations.get(node);
755
+ }
756
+ symbolForNode(node) {
757
+ return this.#references.get(node);
758
+ }
759
+ };
760
+ var ScopeStack = class {
761
+ #base;
762
+ #scopes;
763
+ constructor(base) {
764
+ this.#base = base;
765
+ this.#scopes = [base];
766
+ }
767
+ current() {
768
+ return this.#scopes[this.#scopes.length - 1] ?? this.#base;
769
+ }
770
+ push(scope) {
771
+ this.#scopes.push(scope);
772
+ }
773
+ pop() {
774
+ this.#scopes.pop();
775
+ }
776
+ };
777
+ function walkEntities(symbolTable, stack, visit) {
778
+ const { topLevel } = symbolTable;
779
+ for (const entity of Object.values(topLevel.models)) visit(entity);
780
+ for (const entity of Object.values(topLevel.compositeTypes)) visit(entity);
781
+ for (const namespace of Object.values(topLevel.namespaces)) {
782
+ stack.push(namespaceScope(namespace, stack.current()));
783
+ for (const entity of Object.values(namespace.models)) visit(entity);
784
+ for (const entity of Object.values(namespace.compositeTypes)) visit(entity);
785
+ stack.pop();
786
+ }
787
+ }
788
+ function createBinder(options) {
789
+ const { sources, symbolTable, typeConstructors, attributeSpecs, controlMutationDefaults, describeUnsupportedAttribute } = options;
790
+ const stack = new ScopeStack(documentScope(symbolTable.topLevel, contributedScope(contributedTypeScope(typeConstructors))));
791
+ const declarations = /* @__PURE__ */ new WeakMap();
792
+ const references = /* @__PURE__ */ new WeakMap();
793
+ const diagnostics = [];
794
+ for (const symbol of Object.values(symbolTable.topLevel.namedTypes)) declarations.set(symbol.node.syntax, symbol);
795
+ for (const symbol of Object.values(symbolTable.topLevel.blocks)) declarations.set(symbol.node.syntax, symbol);
796
+ for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
797
+ for (const declaration of namespace.declarations) declarations.set(declaration.node.syntax, namespace);
798
+ for (const symbol of Object.values(namespace.blocks)) declarations.set(symbol.node.syntax, symbol);
799
+ }
800
+ walkEntities(symbolTable, stack, (entity) => {
801
+ declarations.set(entity.node.syntax, entity);
802
+ for (const field of Object.values(entity.fields)) {
803
+ declarations.set(field.node.syntax, field);
804
+ const node = typeReferenceNode(field);
805
+ if (node === void 0) continue;
806
+ const outcome = resolveTypeReference(field, stack.current());
807
+ if (outcome === void 0) continue;
808
+ references.set(node, outcome.resolution);
809
+ if (outcome.message !== void 0) diagnostics.push({
810
+ code: PSL_UNRESOLVED_REFERENCE,
811
+ message: outcome.message,
812
+ data: {
813
+ reference: "type",
814
+ name: outcome.name
815
+ },
816
+ ...diagnosticSource(sources, node).at()
817
+ });
818
+ }
819
+ });
820
+ walkEntities(symbolTable, stack, (entity) => {
821
+ const context = {
822
+ owner: entity,
823
+ scope: stack.current(),
824
+ references,
825
+ diagnostics,
826
+ symbolTable,
827
+ sources,
828
+ describeUnsupportedAttribute
829
+ };
830
+ const specContext = entity.kind === "model" ? {
831
+ symbols: symbolTable,
832
+ model: entity,
833
+ controlMutationDefaults
834
+ } : void 0;
835
+ bindAttributes(entity, entity.attributes, attributeSpecs.model, (factory) => specContext === void 0 ? void 0 : factory(specContext), {
836
+ ...context,
837
+ field: void 0
838
+ });
839
+ for (const field of Object.values(entity.fields)) bindAttributes(field, field.attributes, attributeSpecs.field, (factory) => specContext === void 0 ? void 0 : factory({
840
+ ...specContext,
841
+ field
842
+ }), {
843
+ ...context,
844
+ field
845
+ });
846
+ });
847
+ return {
848
+ binder: new PslBinder(declarations, references),
849
+ diagnostics
850
+ };
851
+ }
852
+ function bindAttributes(holder, attributes, specs, instantiate, ctx) {
853
+ const declared = holder.node.attributes();
854
+ const nodes = Array.from(declared);
855
+ const level = holder.kind === "field" ? "field" : "model";
856
+ attributes.forEach((attribute, index) => {
857
+ const factory = own(specs, attribute.name);
858
+ if (factory === void 0) {
859
+ const diagnostic = ctx.describeUnsupportedAttribute?.({
860
+ attribute,
861
+ level,
862
+ owner: ctx.owner,
863
+ field: level === "field" ? ctx.field : void 0
864
+ });
865
+ if (diagnostic !== void 0) ctx.diagnostics.push(diagnostic);
866
+ return;
867
+ }
868
+ const spec = instantiate(factory);
869
+ if (spec === void 0) return;
870
+ const nameNode = nodes[index]?.name()?.syntax;
871
+ if (nameNode !== void 0) ctx.references.set(nameNode, {
872
+ kind: "attribute",
873
+ symbol: {
874
+ kind: "attribute",
875
+ name: attribute.name,
876
+ level,
877
+ spec
878
+ }
879
+ });
880
+ bindArguments(attribute, spec, ctx);
881
+ });
882
+ }
883
+ function bindArguments(attribute, spec, ctx) {
884
+ let positional = 0;
885
+ for (const arg of attribute.args) {
886
+ const param = arg.name === void 0 ? spec.positional[positional++] : spec.named[arg.name];
887
+ if (param === void 0 || arg.expression === void 0) continue;
888
+ const kind = referenceKind(param.type);
889
+ if (kind === void 0) continue;
890
+ for (const node of referenceNodes(arg.expression)) {
891
+ const resolution = resolveArgument(kind, node, ctx);
892
+ if (resolution !== void 0) ctx.references.set(node, resolution);
893
+ }
894
+ }
895
+ }
896
+ function resolveArgument(kind, node, ctx) {
897
+ const name = IdentifierAst.cast(node)?.name();
898
+ if (name === void 0) return void 0;
899
+ switch (kind) {
900
+ case "fieldRef": return resolveOwnerField(name, node, ctx);
901
+ case "referencedFieldRef": return resolveReferencedField(name, node, ctx);
902
+ case "entityRef": return resolveEntity(name, node, ctx);
903
+ }
904
+ }
905
+ function resolveOwnerField(name, node, ctx) {
906
+ const field = ctx.owner.fields[name];
907
+ if (field !== void 0) return {
908
+ kind: "field",
909
+ symbol: field
910
+ };
911
+ report(`Cannot find field "${name}" on "${ctx.owner.name}"`, node, ctx, "field");
912
+ return {
913
+ kind: "unresolved",
914
+ name
915
+ };
916
+ }
917
+ function resolveReferencedField(name, node, ctx) {
918
+ const declaring = ctx.field;
919
+ if (declaring === void 0) return {
920
+ kind: "unresolved",
921
+ name
922
+ };
923
+ if (declaring.typeContractSpaceId !== void 0) return { kind: "crossSpace" };
924
+ const typeNode = typeReferenceNode(declaring);
925
+ const field = targetFields(typeNode === void 0 ? void 0 : ctx.references.get(typeNode))?.[name];
926
+ if (field !== void 0) return {
927
+ kind: "field",
928
+ symbol: field
929
+ };
930
+ report(`Cannot find field "${name}" on the type of "${ctx.owner.name}.${declaring.name}"`, node, ctx, "field");
931
+ return {
932
+ kind: "unresolved",
933
+ name
934
+ };
935
+ }
936
+ function targetFields(target) {
937
+ if (target === void 0) return void 0;
938
+ if (target.kind === "model" || target.kind === "compositeType") return target.symbol.fields;
939
+ }
940
+ function resolveEntity(name, node, ctx) {
941
+ const found = ctx.scope.lookup(name);
942
+ if (found === void 0) {
943
+ report(`Cannot find entity "${name}"`, node, ctx, "entity");
944
+ return {
945
+ kind: "unresolved",
946
+ name
947
+ };
948
+ }
949
+ return found;
950
+ }
951
+ function report(message, node, ctx, reference) {
952
+ ctx.diagnostics.push({
953
+ code: PSL_UNRESOLVED_REFERENCE,
954
+ message,
955
+ data: { reference },
956
+ ...diagnosticSource(ctx.sources, node).at()
957
+ });
958
+ }
959
+ function referenceKind(type) {
960
+ if (typeof type !== "object" || type === null) return void 0;
961
+ if ("kind" in type) {
962
+ const kind = type.kind;
963
+ if (kind === "fieldRef" || kind === "referencedFieldRef" || kind === "entityRef") return kind;
964
+ }
965
+ if ("of" in type) return referenceKind(type.of);
966
+ if ("alternatives" in type && Array.isArray(type.alternatives)) for (const alternative of type.alternatives) {
967
+ const kind = referenceKind(alternative);
968
+ if (kind !== void 0) return kind;
969
+ }
970
+ }
971
+ function referenceNodes(expression) {
972
+ const array = ArrayLiteralAst.cast(expression.syntax);
973
+ if (array === void 0) return [expression.syntax];
974
+ return Array.from(array.elements(), (element) => element.syntax);
975
+ }
976
+ function resolveTypeReference(field, scope) {
977
+ if (field.malformedType === true) return void 0;
978
+ if (field.typeContractSpaceId !== void 0) return { resolution: { kind: "crossSpace" } };
979
+ const name = field.typeName;
980
+ if (name === "") return void 0;
981
+ const namespaceId = field.typeNamespaceId;
982
+ const found = namespaceId === void 0 ? scope.lookup(name) : qualifiedMember(namespaceId, name, scope);
983
+ if (found === void 0) {
984
+ const written = namespaceId === void 0 ? name : `${namespaceId}.${name}`;
985
+ return {
986
+ resolution: {
987
+ kind: "unresolved",
988
+ name: written
989
+ },
990
+ message: `Cannot find type "${written}"`,
991
+ name: written
992
+ };
993
+ }
994
+ if ("badQualifier" in found) return {
995
+ resolution: {
996
+ kind: "unresolved",
997
+ name: found.qualifier
998
+ },
999
+ message: found.badQualifier,
1000
+ name: found.qualifier
1001
+ };
1002
+ if (found.kind === "namespace" || found.kind === "contributedNamespace") {
1003
+ const written = namespaceId === void 0 ? name : `${namespaceId}.${name}`;
1004
+ return {
1005
+ resolution: found,
1006
+ message: `"${written}" is a namespace; a type reference must name a model, composite type, enum, or named type`,
1007
+ name: written
1008
+ };
1009
+ }
1010
+ return { resolution: found };
1011
+ }
1012
+ function qualifiedMember(namespaceId, name, scope) {
1013
+ const qualifier = scope.lookup(namespaceId);
1014
+ if (qualifier === void 0) return void 0;
1015
+ if (!isNamespaceLike(qualifier)) return {
1016
+ badQualifier: `"${namespaceId}" is ${describeQualifier(qualifier)}, not a namespace`,
1017
+ qualifier: namespaceId
1018
+ };
1019
+ return lookupMember(qualifier, name);
1020
+ }
1021
+ function describeQualifier(resolution) {
1022
+ switch (resolution.kind) {
1023
+ case "model": return "a model";
1024
+ case "compositeType": return "a composite type";
1025
+ case "namedType": return "a named type";
1026
+ case "block": return `${resolution.symbol.keyword === "enum" ? "an" : "a"} ${resolution.symbol.keyword}`;
1027
+ default: return "a scalar type";
1028
+ }
1029
+ }
1030
+ function own(record, name) {
1031
+ return Object.hasOwn(record, name) ? record[name] : void 0;
1032
+ }
607
1033
  function findBlockDescriptor(descriptors, keyword) {
608
1034
  if (descriptors === void 0) return void 0;
609
1035
  for (const value of Object.values(descriptors)) {
@@ -1064,6 +1490,6 @@ function nodeRange(node, sources) {
1064
1490
  };
1065
1491
  }
1066
1492
  //#endregion
1067
- export { assembleAttributeSpecs, blockAttribute, bool, buildSymbolTable, createPslDiagnosticCollector, diagnosticFromSpan, diagnosticSource, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, isPrismaNextSchema, json, keywordPslSpan, leafDiagnostic, list, mapPslDiagnostics, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, referencedFieldRef, renameLegacyDirective, str, taggedLiteral, validateExtensionBlockFromSymbol };
1493
+ export { PSL_UNRESOLVED_REFERENCE, assembleAttributeSpecs, blockAttribute, bool, buildSymbolTable, createBinder, createPslDiagnosticCollector, diagnosticFromSpan, diagnosticSource, entityRef, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, isPrismaNextSchema, json, keywordPslSpan, leafDiagnostic, list, mapPslDiagnostics, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, record, referencedFieldRef, renameLegacyDirective, str, taggedLiteral, validateExtensionBlockFromSymbol };
1068
1494
 
1069
1495
  //# sourceMappingURL=psl-parser.mjs.map