@prisma/orm-framework 8.0.0-rc.19 → 8.0.0-rc.19-dev.4

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 (120) hide show
  1. package/dist/{authoring-BxyfEUyh.mjs → authoring-BMkyimEq.mjs} +3 -3
  2. package/dist/authoring-BMkyimEq.mjs.map +1 -0
  3. package/dist/{authoring-DWhPMprN.d.mts → authoring-CUZxY2RV.d.mts} +4 -4
  4. package/dist/{authoring-DWhPMprN.d.mts.map → authoring-CUZxY2RV.d.mts.map} +1 -1
  5. package/dist/{binder-63ozT0D8-D7n-9Uv4.d.mts → binder-D_4RBHbt-HJoM87MJ.d.mts} +16 -15
  6. package/dist/binder-D_4RBHbt-HJoM87MJ.d.mts.map +1 -0
  7. package/dist/{codec-DkiEF2cQ.d.mts → codec-B_KV-HpC.d.mts} +2 -3
  8. package/dist/codec-B_KV-HpC.d.mts.map +1 -0
  9. package/dist/{codec-types-DjozIOvT-BIcpyFea.d.mts → codec-types-CPgEZoIq-BL9hisr8.d.mts} +3 -3
  10. package/dist/{codec-types-DjozIOvT-BIcpyFea.d.mts.map → codec-types-CPgEZoIq-BL9hisr8.d.mts.map} +1 -1
  11. package/dist/{components-B3SnaxMU.d.mts → components-CJ5VhJT8.d.mts} +5 -4
  12. package/dist/components-CJ5VhJT8.d.mts.map +1 -0
  13. package/dist/components.d.mts +16 -17
  14. package/dist/components.mjs +4 -4
  15. package/dist/components__authoring.d.mts +4 -4
  16. package/dist/components__authoring.mjs +3 -3
  17. package/dist/components__codec.d.mts +2 -2
  18. package/dist/components__components.d.mts +4 -4
  19. package/dist/components__control.d.mts +4 -4
  20. package/dist/components__control.mjs +3 -3
  21. package/dist/components__emission.d.mts +3 -3
  22. package/dist/components__execution.d.mts +1 -1
  23. package/dist/components__psl-ast.d.mts +3 -3
  24. package/dist/components__runtime.d.mts +1 -1
  25. package/dist/{config-types-Bs7GpaPJ.d.mts → config-types-B7pDUyu2.d.mts} +7 -9
  26. package/dist/config-types-B7pDUyu2.d.mts.map +1 -0
  27. package/dist/config.d.mts +1 -1
  28. package/dist/config__config-types.d.mts +1 -1
  29. package/dist/contract-authoring.d.mts +4 -4
  30. package/dist/contract-authoring.mjs +4 -4
  31. package/dist/contract-authoring.mjs.map +1 -1
  32. package/dist/{control-B5ezUWD2-DTWXJUHt.d.mts → control-B5ezUWD2-CWp9npSb.d.mts} +2 -2
  33. package/dist/{control-B5ezUWD2-DTWXJUHt.d.mts.map → control-B5ezUWD2-CWp9npSb.d.mts.map} +1 -1
  34. package/dist/{control-DnNh47Wd.d.mts → control-BC7a9D7N.d.mts} +219 -186
  35. package/dist/control-BC7a9D7N.d.mts.map +1 -0
  36. package/dist/control-BLmwnbM0.d.mts +1 -0
  37. package/dist/{control-xg2R0dXx.mjs → control-Bq9kKKJS.mjs} +57 -8
  38. package/dist/control-Bq9kKKJS.mjs.map +1 -0
  39. package/dist/{control-KsXr4fYD-DLPY47Il.mjs → control-KsXr4fYD-O9tIteNn.mjs} +2 -2
  40. package/dist/{control-KsXr4fYD-DLPY47Il.mjs.map → control-KsXr4fYD-O9tIteNn.mjs.map} +1 -1
  41. package/dist/{declarations-BgUAq1RG-CEN8W7dJ.mjs → declarations-BgUAq1RG-BOxzxoTR.mjs} +2 -2
  42. package/dist/{declarations-BgUAq1RG-CEN8W7dJ.mjs.map → declarations-BgUAq1RG-BOxzxoTR.mjs.map} +1 -1
  43. package/dist/emission-BtJvV97M.d.mts +2 -0
  44. package/dist/{emission-types-sz0-pyyS-D3-ssRUu.d.mts → emission-types-B-jKEbjI-D7BW8Gk1.d.mts} +4 -4
  45. package/dist/{emission-types-sz0-pyyS-D3-ssRUu.d.mts.map → emission-types-B-jKEbjI-D7BW8Gk1.d.mts.map} +1 -1
  46. package/dist/errors.d.mts +5 -5
  47. package/dist/errors.mjs +4 -4
  48. package/dist/errors__control.d.mts +2 -2
  49. package/dist/errors__control.mjs +1 -1
  50. package/dist/errors__execution.d.mts +2 -2
  51. package/dist/errors__execution.mjs +2 -2
  52. package/dist/errors__migration.d.mts +1 -1
  53. package/dist/errors__migration.mjs +1 -1
  54. package/dist/{execution-CktUHYP0.d.mts → execution-0Irooze3.d.mts} +2 -2
  55. package/dist/{execution-CktUHYP0.d.mts.map → execution-0Irooze3.d.mts.map} +1 -1
  56. package/dist/{execution-yrBEIzBV.d.mts → execution-CL5odLfv.d.mts} +3 -13
  57. package/dist/execution-CL5odLfv.d.mts.map +1 -0
  58. package/dist/{execution-BbpdDFYd.mjs → execution-D5ISN2Rt.mjs} +3 -25
  59. package/dist/{execution-BbpdDFYd.mjs.map → execution-D5ISN2Rt.mjs.map} +1 -1
  60. package/dist/{expressions-CMQzbnHk-D2oE4DzM.mjs → expressions-CMQzbnHk-CrNw_vqf.mjs} +2 -2
  61. package/dist/{expressions-CMQzbnHk-D2oE4DzM.mjs.map → expressions-CMQzbnHk-CrNw_vqf.mjs.map} +1 -1
  62. package/dist/{framework-authoring-Du7xSUmg-D85Toszi.d.mts → framework-authoring-C78etPdT-CeiBIBJ-.d.mts} +227 -10
  63. package/dist/framework-authoring-C78etPdT-CeiBIBJ-.d.mts.map +1 -0
  64. package/dist/{framework-components-DQFte83L-CIIcH8Bj.d.mts → framework-components-BmRQfvNS-KSEiBXXc.d.mts} +6 -103
  65. package/dist/framework-components-BmRQfvNS-KSEiBXXc.d.mts.map +1 -0
  66. package/dist/ids.d.mts +1 -1
  67. package/dist/{migration-DH3rxAoO.d.mts → migration-Db3N-7JB.d.mts} +2 -2
  68. package/dist/{migration-DH3rxAoO.d.mts.map → migration-Db3N-7JB.d.mts.map} +1 -1
  69. package/dist/{migration-BHhDtq__.mjs → migration-DkzPlgX1.mjs} +2 -2
  70. package/dist/{migration-BHhDtq__.mjs.map → migration-DkzPlgX1.mjs.map} +1 -1
  71. package/dist/{parse-bZgfjovA-D0MdY-kP.mjs → parse-bZgfjovA-sINnImkq.mjs} +3 -3
  72. package/dist/{parse-bZgfjovA-D0MdY-kP.mjs.map → parse-bZgfjovA-sINnImkq.mjs.map} +1 -1
  73. package/dist/{parse-djL5wker-BQzi1u4O.d.mts → parse-djL5wker-D6uXzzA7.d.mts} +6 -6
  74. package/dist/{parse-djL5wker-BQzi1u4O.d.mts.map → parse-djL5wker-D6uXzzA7.d.mts.map} +1 -1
  75. package/dist/{psl-ast-B6X_rlhZ-DCrq7Zie.d.mts → psl-ast-54cA0pl_-DrzGrcMF.d.mts} +3 -4
  76. package/dist/psl-ast-54cA0pl_-DrzGrcMF.d.mts.map +1 -0
  77. package/dist/psl-ast-BubQebay.d.mts +2 -0
  78. package/dist/psl-parser.d.mts +111 -16
  79. package/dist/psl-parser.d.mts.map +1 -1
  80. package/dist/psl-parser.mjs +278 -32
  81. package/dist/psl-parser.mjs.map +1 -1
  82. package/dist/psl-parser__format.d.mts +1 -1
  83. package/dist/psl-parser__format.mjs +3 -3
  84. package/dist/psl-parser__interpret.d.mts +6 -6
  85. package/dist/psl-parser__interpret.mjs +2 -24
  86. package/dist/psl-parser__interpret.mjs.map +1 -1
  87. package/dist/psl-parser__syntax.d.mts +1 -1
  88. package/dist/psl-parser__syntax.mjs +3 -3
  89. package/dist/psl-printer.d.mts +4 -4
  90. package/dist/psl-printer.mjs +1 -1
  91. package/dist/{runtime-BXPhK_oW.d.mts → runtime-8WddX9H_.d.mts} +2 -2
  92. package/dist/{runtime-BXPhK_oW.d.mts.map → runtime-8WddX9H_.d.mts.map} +1 -1
  93. package/dist/{temporal-presets-DF8wiIwk-CZI3cLQZ.mjs → temporal-presets-CIFczljn-BrjropV6.mjs} +123 -27
  94. package/dist/temporal-presets-CIFczljn-BrjropV6.mjs.map +1 -0
  95. package/dist/{temporal-presets-9VgC1-FN-MoyINRBU.d.mts → temporal-presets-suGfXweJ-Cv2uijGj.d.mts} +36 -6
  96. package/dist/temporal-presets-suGfXweJ-Cv2uijGj.d.mts.map +1 -0
  97. package/dist/{read-expression-as-Dhyvx51C-BbNqJHAR.mjs → type-constructor-calls-BLf-HsFy-Z9ApP-kL.mjs} +28 -6
  98. package/dist/type-constructor-calls-BLf-HsFy-Z9ApP-kL.mjs.map +1 -0
  99. package/dist/{types-import-spec-hkPsnreE-C-fa8812.d.mts → types-import-spec-DQjfX-gM-zVncuzs0.d.mts} +3 -3
  100. package/dist/{types-import-spec-hkPsnreE-C-fa8812.d.mts.map → types-import-spec-DQjfX-gM-zVncuzs0.d.mts.map} +1 -1
  101. package/package.json +15 -15
  102. package/dist/authoring-BxyfEUyh.mjs.map +0 -1
  103. package/dist/binder-63ozT0D8-D7n-9Uv4.d.mts.map +0 -1
  104. package/dist/codec-DkiEF2cQ.d.mts.map +0 -1
  105. package/dist/components-B3SnaxMU.d.mts.map +0 -1
  106. package/dist/config-types-Bs7GpaPJ.d.mts.map +0 -1
  107. package/dist/control-Dhq4un61.d.mts +0 -1
  108. package/dist/control-DnNh47Wd.d.mts.map +0 -1
  109. package/dist/control-xg2R0dXx.mjs.map +0 -1
  110. package/dist/emission-XBYOUuHN.d.mts +0 -2
  111. package/dist/execution-yrBEIzBV.d.mts.map +0 -1
  112. package/dist/framework-authoring-Du7xSUmg-D85Toszi.d.mts.map +0 -1
  113. package/dist/framework-components-DQFte83L-CIIcH8Bj.d.mts.map +0 -1
  114. package/dist/mutation-default-types-js6llINX-WGmpaAAL.d.mts +0 -66
  115. package/dist/mutation-default-types-js6llINX-WGmpaAAL.d.mts.map +0 -1
  116. package/dist/psl-ast-B6X_rlhZ-DCrq7Zie.d.mts.map +0 -1
  117. package/dist/psl-ast-DlmFfwfZ.d.mts +0 -2
  118. package/dist/read-expression-as-Dhyvx51C-BbNqJHAR.mjs.map +0 -1
  119. package/dist/temporal-presets-9VgC1-FN-MoyINRBU.d.mts.map +0 -1
  120. package/dist/temporal-presets-DF8wiIwk-CZI3cLQZ.mjs.map +0 -1
@@ -2,15 +2,15 @@ import { t as blindCast } from "./casts-DpaahrlC-Bd5n2coI.mjs";
2
2
  import { t as InternalError } from "./internal-error-ChGYPVpq-DhUD05u0.mjs";
3
3
  import { a as or, i as okVoid, n as notOk, r as ok, t as and } from "./result-8OXF26MN.mjs";
4
4
  import { c as createDataTypeLookup } from "./data-type-CVNHtd6y-BFa_VnCb.mjs";
5
- import { T as isAuthoringPslBlockDescriptor, m as describeTaggedLiteralFailure, w as isAuthoringModelAttributeDescriptor } from "./temporal-presets-DF8wiIwk-CZI3cLQZ.mjs";
5
+ import { D as isAuthoringModelAttributeDescriptor, O as isAuthoringPslBlockDescriptor, g as describeTaggedLiteralFailure, x as instantiateAuthoringTypeAlias } from "./temporal-presets-CIFczljn-BrjropV6.mjs";
6
6
  import { r as UNBOUND_NAMESPACE_ID } from "./namespace-VUH2dgnS-By5y75h9.mjs";
7
- import { C as tagForm, n as admittedTags, o as describeAdmittedForms } from "./authoring-BxyfEUyh.mjs";
7
+ import { C as tagForm, _ as findAuthoringTypeConstructorCall, n as admittedTags, o as describeAdmittedForms } from "./authoring-BMkyimEq.mjs";
8
8
  import { a as flatPslModels, c as namespacePslExtensionBlocks, n as UNBOUND_PSL_NAMESPACE_NAME } from "./psl-ast-CyvE6CR-.mjs";
9
9
  import { n as isPslIdentifier } from "./tokenizer-C-GTKKjR-B1vOzJy0.mjs";
10
- import { C as printSyntax, a as IdentifierAst, c as ObjectLiteralExprAst, d as StringLiteralExprAst, i as FunctionCallAst, l as PathExprAst, m as TaggedLiteralExprAst, o as NumberLiteralExprAst, r as BooleanLiteralExprAst, t as ArrayLiteralAst } from "./expressions-CMQzbnHk-D2oE4DzM.mjs";
11
- import { a as keywordPslSpan, c as readResolvedAttribute, d as readWrittenScalar, i as diagnosticSource, l as readResolvedAttributes, n as createPslDiagnosticCollector, o as mapPslDiagnostics, r as diagnosticFromSpan, s as nodePslSpan, t as readExpressionAs, u as readResolvedConstructorCall } from "./read-expression-as-Dhyvx51C-BbNqJHAR.mjs";
12
- import { a as FieldDeclarationAst, c as MixinDeclarationAst, d as ModelDeclarationAst, h as TypesBlockAst, n as CompositeTypeDeclarationAst, o as GenericBlockDeclarationAst, p as NamespaceDeclarationAst, s as KeyValuePairAst, u as ModelAttributeAst } from "./declarations-BgUAq1RG-CEN8W7dJ.mjs";
13
- //#region ../../../1-framework/2-authoring/psl-parser/dist/binder-Cl92Fnz3.mjs
10
+ import { C as printSyntax, a as IdentifierAst, c as ObjectLiteralExprAst, d as StringLiteralExprAst, i as FunctionCallAst, l as PathExprAst, m as TaggedLiteralExprAst, o as NumberLiteralExprAst, r as BooleanLiteralExprAst, t as ArrayLiteralAst } from "./expressions-CMQzbnHk-CrNw_vqf.mjs";
11
+ import { a as diagnosticFromSpan, c as mapPslDiagnostics, d as readResolvedAttributes, f as readResolvedConstructorCall, i as createPslDiagnosticCollector, l as nodePslSpan, n as readExpressionAs, o as diagnosticSource, p as readWrittenScalar, s as keywordPslSpan, t as isBareTypeConstructor, u as readResolvedAttribute } from "./type-constructor-calls-BLf-HsFy-Z9ApP-kL.mjs";
12
+ import { a as FieldDeclarationAst, c as MixinDeclarationAst, d as ModelDeclarationAst, g as isTrivia, h as TypesBlockAst, n as CompositeTypeDeclarationAst, o as GenericBlockDeclarationAst, p as NamespaceDeclarationAst, s as KeyValuePairAst, u as ModelAttributeAst } from "./declarations-BgUAq1RG-BOxzxoTR.mjs";
13
+ //#region ../../../1-framework/2-authoring/psl-parser/dist/binder-MH8x-Dk-.mjs
14
14
  function* modelAttributeDescriptors(namespace) {
15
15
  for (const value of Object.values(namespace)) {
16
16
  if (isAuthoringModelAttributeDescriptor(value)) {
@@ -92,18 +92,12 @@ function describeResolution(resolution) {
92
92
  default: return resolution.kind;
93
93
  }
94
94
  }
95
- function blockSpecFactoryOf(descriptor) {
96
- return blindCast(descriptor.spec);
97
- }
98
- /** The context a block spec factory and a block-attribute spec factory are built from. ADR 262. */
99
- function blockSpecContext(input) {
100
- return {
101
- symbols: input.symbols,
102
- dataTypes: input.dataTypes
103
- };
104
- }
105
95
  function isContributedTypeDescriptor(value) {
106
- return "kind" in value && (value.kind === "typeConstructor" || value.kind === "fieldPreset");
96
+ return "kind" in value && (value.kind === "typeConstructor" || value.kind === "typeAlias" || value.kind === "fieldPreset");
97
+ }
98
+ /** The codec a column typed by `descriptor` is stored with. */
99
+ function contributedTypeCodecId(descriptor) {
100
+ return descriptor.kind === "typeAlias" ? descriptor.output.type.codecId : descriptor.output.codecId;
107
101
  }
108
102
  function mergeContributedTypes(...namespaces) {
109
103
  const merged = {};
@@ -142,6 +136,16 @@ function collect(namespace, prefix) {
142
136
  }
143
137
  return members;
144
138
  }
139
+ function blockSpecFactoryOf(descriptor) {
140
+ return blindCast(descriptor.spec);
141
+ }
142
+ /** The context a block spec factory and a block-attribute spec factory are built from. ADR 262. */
143
+ function blockSpecContext(input) {
144
+ return {
145
+ symbols: input.symbols,
146
+ dataTypes: input.dataTypes
147
+ };
148
+ }
145
149
  function findBlockDescriptor(descriptors, keyword) {
146
150
  if (descriptors === void 0) return void 0;
147
151
  for (const value of Object.values(descriptors)) {
@@ -1454,7 +1458,7 @@ function resolveTypeReference(reference, scope, references, describeUnresolved)
1454
1458
  const written = namespaceId === void 0 ? name : `${namespaceId}.${name}`;
1455
1459
  return {
1456
1460
  resolution: found,
1457
- message: `"${written}" is a ${found.kind === "mixin" ? "mixin" : "namespace"}; a type reference must name a model, composite type, enum, or named type`,
1461
+ message: `"${written}" is a ${found.kind === "mixin" ? "mixin" : "namespace"}; a type reference must name a model, composite type, enum, or type alias`,
1458
1462
  name: written
1459
1463
  };
1460
1464
  }
@@ -1472,7 +1476,7 @@ function describeQualifier(resolution) {
1472
1476
  switch (resolution.kind) {
1473
1477
  case "model": return "a model";
1474
1478
  case "compositeType": return "a composite type";
1475
- case "namedType": return "a named type";
1479
+ case "namedType": return "a type alias";
1476
1480
  case "block": return `${resolution.symbol.keyword === "enum" ? "an" : "a"} ${resolution.symbol.keyword}`;
1477
1481
  default: return "a scalar type";
1478
1482
  }
@@ -2092,6 +2096,15 @@ function writtenList(of) {
2092
2096
  }));
2093
2097
  }
2094
2098
  function fieldAttribute(name, config) {
2099
+ return fieldLevelAttribute(name, config);
2100
+ }
2101
+ /**
2102
+ * A field attribute that reads only its type, never the field it is written on, so a type alias can carry it too.
2103
+ */
2104
+ function typeAttribute(name, config) {
2105
+ return fieldLevelAttribute(name, config);
2106
+ }
2107
+ function fieldLevelAttribute(name, config) {
2095
2108
  return {
2096
2109
  level: "field",
2097
2110
  name,
@@ -2101,6 +2114,32 @@ function fieldAttribute(name, config) {
2101
2114
  ...config.refine !== void 0 ? { refine: config.refine } : {}
2102
2115
  };
2103
2116
  }
2117
+ /** The data types of a stack that registers none. */
2118
+ const EMPTY_DATA_TYPES = {
2119
+ entries: {},
2120
+ lookup: createDataTypeLookup([]),
2121
+ dataTypeOfCodec: () => void 0
2122
+ };
2123
+ /** How a diagnostic names a subject, as in `Field "Post.slug"` or `Type alias "Slug"`. */
2124
+ function typeAttributeSubjectLabel(subject) {
2125
+ return `${subject.kind === "field" ? "Field" : "Type alias"} "${subject.name}"`;
2126
+ }
2127
+ function typeAttributeSpecContextOfField(ctx) {
2128
+ return {
2129
+ symbols: ctx.symbols,
2130
+ defaultFunctionRegistry: ctx.defaultFunctionRegistry,
2131
+ generatorFunctions: ctx.generatorFunctions,
2132
+ dataTypes: ctx.dataTypes,
2133
+ subject: {
2134
+ kind: "field",
2135
+ name: `${ctx.model.name}.${ctx.field.name}`
2136
+ },
2137
+ list: ctx.field.list,
2138
+ typeName: ctx.field.typeName,
2139
+ typeResolution: ctx.typeResolution,
2140
+ typeConstructor: ctx.typeConstructor
2141
+ };
2142
+ }
2104
2143
  const GENERATOR_PHASE_DOCUMENTATION = {
2105
2144
  onCreate: "Generates a value in the client when a row is created without one.",
2106
2145
  onUpdate: "Generates a value in the client every time a row is updated."
@@ -2127,13 +2166,13 @@ function generatorFunctionCall(name, signature, dataTypes) {
2127
2166
  * The generator function arms for a field's codec. A call to a function that does not apply to the codec, or that no component declares, is refused before the arms are tried, so the author is told which functions do apply.
2128
2167
  */
2129
2168
  function generatorCallArm(ctx) {
2130
- const codecId = ctx.typeConstructor?.descriptor.output.codecId;
2169
+ const codecId = ctx.typeConstructor === void 0 ? void 0 : contributedTypeCodecId(ctx.typeConstructor.descriptor);
2131
2170
  const functions = codecId === void 0 ? [] : ctx.generatorFunctions.functionsFor(codecId);
2132
- const fieldPath = `${ctx.model.name}.${ctx.field.name}`;
2171
+ const subject = typeAttributeSubjectLabel(ctx.subject);
2133
2172
  const target = codecId === void 0 ? "the field's type" : `codec "${codecId}"`;
2134
2173
  const refuse = (arg, attributeCtx) => {
2135
2174
  const name = calleeName(arg);
2136
- return notOk([name !== void 0 && !ctx.generatorFunctions.has(name) ? leafDiagnostic(attributeCtx, arg, `Field "${fieldPath}": unknown generator function "${name}". ${functionListText(functions, codecId !== void 0)}`, "PSL_UNKNOWN_GENERATOR_FUNCTION") : leafDiagnostic(attributeCtx, arg, `Field "${fieldPath}": ${nodeSourceText(arg, attributeCtx)} does not apply to ${target}. ${functionListText(functions, codecId !== void 0)}`, "PSL_GENERATOR_NOT_APPLICABLE")]);
2175
+ return notOk([name !== void 0 && !ctx.generatorFunctions.has(name) ? leafDiagnostic(attributeCtx, arg, `${subject}: unknown generator function "${name}". ${functionListText(functions, codecId !== void 0)}`, "PSL_UNKNOWN_GENERATOR_FUNCTION") : leafDiagnostic(attributeCtx, arg, `${subject}: ${nodeSourceText(arg, attributeCtx)} does not apply to ${target}. ${functionListText(functions, codecId !== void 0)}`, "PSL_GENERATOR_NOT_APPLICABLE")]);
2137
2176
  };
2138
2177
  const [first, ...rest] = functions.map(({ name, signature }) => generatorFunctionCall(name, signature, ctx.dataTypes));
2139
2178
  if (first === void 0) return {
@@ -2152,9 +2191,9 @@ function generatorCallArm(ctx) {
2152
2191
  }
2153
2192
  };
2154
2193
  }
2155
- /** The spec of `@onCreate(fn())` or `@onUpdate(fn())`, offering the generator functions bound to the field's codec. */
2156
- function generatorAttributeSpec(phase) {
2157
- return (ctx) => fieldAttribute(phase, {
2194
+ /** The spec of `@onCreate(fn())` or `@onUpdate(fn())` on a field or type alias, offering the generator functions bound to its codec. */
2195
+ function typeGeneratorAttributeSpec(phase, ctx) {
2196
+ return typeAttribute(phase, {
2158
2197
  documentation: GENERATOR_PHASE_DOCUMENTATION[phase],
2159
2198
  positional: [{
2160
2199
  key: "value",
@@ -2163,6 +2202,10 @@ function generatorAttributeSpec(phase) {
2163
2202
  }]
2164
2203
  });
2165
2204
  }
2205
+ /** The spec of `@onCreate(fn())` or `@onUpdate(fn())`, offering the generator functions bound to the field's codec. */
2206
+ function generatorAttributeSpec(phase) {
2207
+ return (ctx) => typeGeneratorAttributeSpec(phase, typeAttributeSpecContextOfField(ctx));
2208
+ }
2166
2209
  function modelAttribute(name, config) {
2167
2210
  return {
2168
2211
  level: "model",
@@ -2186,12 +2229,6 @@ function optional(type, ...rest) {
2186
2229
  defaultValue: rest[0]
2187
2230
  };
2188
2231
  }
2189
- /** The data types of a stack that registers none. */
2190
- const EMPTY_DATA_TYPES = {
2191
- entries: {},
2192
- lookup: createDataTypeLookup([]),
2193
- dataTypeOfCodec: () => void 0
2194
- };
2195
2232
  function structBlock(config) {
2196
2233
  return {
2197
2234
  mode: "struct",
@@ -2442,7 +2479,216 @@ function isPrismaNextSchema(text) {
2442
2479
  function renameLegacyDirective(text) {
2443
2480
  return text.replace(DIRECTIVE, (whole, lead, name, trail) => name === LEGACY_NAME ? `${lead}prisma-8${trail}` : whole);
2444
2481
  }
2482
+ /** The attributes a type alias may carry. Every field typed by the alias takes them. */
2483
+ const TYPE_ALIAS_ATTRIBUTE_NAMES = /* @__PURE__ */ new Set([
2484
+ "default",
2485
+ "onCreate",
2486
+ "onUpdate"
2487
+ ]);
2488
+ function writtenBase(declaration, sources) {
2489
+ const node = typeReferenceNode(declaration);
2490
+ if (node === void 0) return declaration.baseType ?? "";
2491
+ return sources.sourceFileFor(node).text.slice(node.offset, node.endOffset).trim();
2492
+ }
2493
+ /** A node's text without its comments, each run of whitespace and comments written as one space. */
2494
+ function writtenText(node) {
2495
+ let text = "";
2496
+ let pendingSpace = false;
2497
+ for (const token of node.tokens()) {
2498
+ if (isTrivia(token)) {
2499
+ pendingSpace = text.length > 0;
2500
+ continue;
2501
+ }
2502
+ text += `${pendingSpace ? " " : ""}${token.text}`;
2503
+ pendingSpace = false;
2504
+ }
2505
+ return text;
2506
+ }
2507
+ /** The alias `declaration` is written as, if it is written as another `types {}` declaration. */
2508
+ function declaredBaseOf(declaration, declarations, sources) {
2509
+ const base = writtenBase(declaration, sources);
2510
+ return declarations.find((other) => other !== declaration && other.name === base);
2511
+ }
2512
+ /**
2513
+ * What `declaration` stands for, written as one alias with a base that is not an alias: the type of the last alias of the chain, and the attributes of every alias in it, a nearer alias's attribute replacing a farther one's. `undefined` when the chain loops or ends at a contributed alias.
2514
+ */
2515
+ function expandedDefinition(declaration, declarations, sources, binder) {
2516
+ const chain = [declaration];
2517
+ let next = declaredBaseOf(declaration, declarations, sources);
2518
+ while (next !== void 0) {
2519
+ if (chain.includes(next)) return void 0;
2520
+ chain.push(next);
2521
+ next = declaredBaseOf(next, declarations, sources);
2522
+ }
2523
+ const last = chain.at(-1) ?? declaration;
2524
+ const reference = typeReferenceNode(last);
2525
+ const annotation = last.node.typeAnnotation()?.syntax;
2526
+ if (annotation === void 0 || reference === void 0) return void 0;
2527
+ if (contributedTypeAliasOf(binder.symbolForNode(reference)) !== void 0) return void 0;
2528
+ const attributes = /* @__PURE__ */ new Map();
2529
+ for (const alias of [...chain].reverse()) for (const attribute of alias.attributes) attributes.set(attribute.name, writtenText(attribute.node.syntax));
2530
+ return [writtenText(annotation), ...attributes.values()].join(" ");
2531
+ }
2532
+ /** `path`, called with `args` when it takes any; `undefined` when an argument is not a number, string or boolean. */
2533
+ function writtenCall(path, args) {
2534
+ const written = [];
2535
+ for (const arg of args) if (typeof arg === "string") written.push(JSON.stringify(arg));
2536
+ else if (typeof arg === "number" || typeof arg === "boolean") written.push(String(arg));
2537
+ else return void 0;
2538
+ const name = path.join(".");
2539
+ return written.length === 0 ? name : `${name}(${written.join(", ")})`;
2540
+ }
2541
+ /** The refusal of an alias written as another alias, saying what to write instead; `undefined` when its base is not an alias. */
2542
+ function aliasBaseMessage(declaration, resolution, input) {
2543
+ const refusal = (base) => `Type alias "${declaration.name}" is written as the type alias "${base}", and a type alias cannot be written as another one.`;
2544
+ const declared = declaredBaseOf(declaration, input.declarations, input.sources);
2545
+ if (declared !== void 0) {
2546
+ const expanded = expandedDefinition(declaration, input.declarations, input.sources, input.binder);
2547
+ if (expanded === void 0) return refusal(declared.name);
2548
+ const meaning = declaredBaseOf(declared, input.declarations, input.sources) === void 0 ? "is written as" : "stands for";
2549
+ return `${refusal(declared.name)} Write what "${declared.name}" ${meaning} instead: ${declaration.name} = ${expanded}`;
2550
+ }
2551
+ const contributed = contributedTypeAliasOf(resolution);
2552
+ if (contributed === void 0) return void 0;
2553
+ const { onCreate, onUpdate } = contributed.descriptor.output;
2554
+ const attributes = Object.entries({
2555
+ onCreate,
2556
+ onUpdate
2557
+ }).flatMap(([phase, call]) => call === void 0 ? [] : [`@${phase}(${call.name}())`]);
2558
+ const insteadOfAlias = `${refusal(contributed.name)} Type the fields ${contributed.name} instead`;
2559
+ const call = input.authoringTypes === void 0 ? void 0 : findAuthoringTypeConstructorCall(input.authoringTypes, instantiateAuthoringTypeAlias(contributed.descriptor).type);
2560
+ const type = call === void 0 ? void 0 : writtenCall(call.path, call.args);
2561
+ if (type !== void 0) return `${insteadOfAlias}, or write: ${[`${declaration.name} = ${type}`, ...attributes].join(" ")}`;
2562
+ const written = attributes.length === 0 ? "" : ` with ${attributes.join(" ")}`;
2563
+ return `${insteadOfAlias}, or write ${declaration.name} as a type constructor${written}.`;
2564
+ }
2565
+ function baseOf(declaration, resolution) {
2566
+ if (resolution?.kind === "block" && !declaration.isConstructor) return {
2567
+ kind: "block",
2568
+ symbol: resolution.symbol
2569
+ };
2570
+ if (resolution?.kind !== "contributedType") return void 0;
2571
+ const { descriptor } = resolution.symbol;
2572
+ if (descriptor.kind !== "typeConstructor") return void 0;
2573
+ if (declaration.isConstructor) return {
2574
+ kind: "typeConstructor",
2575
+ descriptor,
2576
+ call: declaration.typeConstructor
2577
+ };
2578
+ return isBareTypeConstructor(descriptor) ? {
2579
+ kind: "typeConstructor",
2580
+ descriptor,
2581
+ call: void 0
2582
+ } : void 0;
2583
+ }
2584
+ function fieldOnlyAttributeMessage(attribute, declaration) {
2585
+ return attribute.name === "id" || attribute.name === "unique" ? `Type alias "${declaration.name}" cannot carry @${attribute.name}. @id and @unique belong to a model's field, not to its type; write them on the field.` : void 0;
2586
+ }
2587
+ /**
2588
+ * Reads each `types {}` declaration as a type alias. A base must be a type constructor or a block; another alias, a field preset or anything else is refused, as is an alias with no base. Of the attributes, those the family accepts are kept and every other one is refused and dropped, keeping the alias, so its fields are not refused for it too.
2589
+ */
2590
+ function resolveTypeAliases(input) {
2591
+ const aliases = /* @__PURE__ */ new Map();
2592
+ const accepted = input.acceptedAttributes ?? TYPE_ALIAS_ATTRIBUTE_NAMES;
2593
+ for (const declaration of input.declarations) {
2594
+ const source = diagnosticSource(input.sources, declaration.node.syntax);
2595
+ const refuseBase = (code, message, span = declaration.span) => input.diagnostics.push({
2596
+ code,
2597
+ message,
2598
+ ...source.at(span)
2599
+ });
2600
+ const reference = typeReferenceNode(declaration);
2601
+ const resolution = reference === void 0 ? void 0 : input.binder.symbolForNode(reference);
2602
+ if ((declaration.isConstructor ? declaration.typeConstructor : declaration.baseType) === void 0) {
2603
+ refuseBase("PSL_UNSUPPORTED_NAMED_TYPE_BASE", `Type alias "${declaration.name}" must declare a base type or constructor`);
2604
+ continue;
2605
+ }
2606
+ const base = baseOf(declaration, resolution);
2607
+ if (base === void 0 || resolution === void 0) {
2608
+ if (declaration.typeConstructor !== void 0) refuseBase("PSL_UNSUPPORTED_NAMED_TYPE_CONSTRUCTOR", `Type alias "${declaration.name}" references unsupported constructor "${declaration.typeConstructor.path.join(".")}"`, declaration.typeConstructor.span);
2609
+ else refuseBase("PSL_UNSUPPORTED_NAMED_TYPE_BASE", aliasBaseMessage(declaration, resolution, input) ?? `Type alias "${declaration.name}" references unsupported base type "${writtenBase(declaration, input.sources)}"`);
2610
+ continue;
2611
+ }
2612
+ const attributes = [];
2613
+ for (const attribute of declaration.attributes) {
2614
+ if (accepted.has(attribute.name)) {
2615
+ attributes.push(attribute);
2616
+ continue;
2617
+ }
2618
+ const message = fieldOnlyAttributeMessage(attribute, declaration) ?? input.describeUnsupportedAttribute?.(attribute, declaration) ?? `Type alias "${declaration.name}" uses unsupported attribute "${attribute.name}"`;
2619
+ input.diagnostics.push({
2620
+ code: "PSL_UNSUPPORTED_NAMED_TYPE_ATTRIBUTE",
2621
+ message,
2622
+ ...source.at(attribute.span)
2623
+ });
2624
+ }
2625
+ aliases.set(declaration, {
2626
+ symbol: declaration,
2627
+ base,
2628
+ baseName: declaration.baseType ?? writtenBase(declaration, input.sources),
2629
+ baseResolution: resolution,
2630
+ attributes
2631
+ });
2632
+ }
2633
+ return aliases;
2634
+ }
2635
+ /** The contributed type alias a type reference resolves to, if it resolves to one. */
2636
+ function contributedTypeAliasOf(resolution) {
2637
+ if (resolution?.kind !== "contributedType") return void 0;
2638
+ const { descriptor, path } = resolution.symbol;
2639
+ return descriptor.kind === "typeAlias" ? {
2640
+ name: path.join("."),
2641
+ descriptor
2642
+ } : void 0;
2643
+ }
2644
+ /** The names of the attributes a type alias sets for every field typed by it. */
2645
+ function typeAliasAttributeNames(alias) {
2646
+ if ("symbol" in alias) return new Set(alias.attributes.map(({ name }) => name));
2647
+ const { onCreate, onUpdate } = alias.descriptor.output;
2648
+ return new Set(Object.entries({
2649
+ onCreate,
2650
+ onUpdate
2651
+ }).flatMap(([name, value]) => value === void 0 ? [] : [name]));
2652
+ }
2653
+ /** The type alias a field is typed by, if it is typed by one. */
2654
+ function typeAliasOfField(field, binder, aliases) {
2655
+ const node = typeReferenceNode(field);
2656
+ const resolution = node === void 0 ? void 0 : binder.symbolForNode(node);
2657
+ return resolution?.kind === "namedType" ? aliases.get(resolution.symbol) : void 0;
2658
+ }
2659
+ /** The spec context the attributes a type alias carries are read in, as a field's are read in its own. */
2660
+ function typeAliasSpecContext(alias, input) {
2661
+ return {
2662
+ symbols: input.symbols,
2663
+ defaultFunctionRegistry: input.defaultFunctionRegistry,
2664
+ generatorFunctions: input.generatorFunctions,
2665
+ dataTypes: input.dataTypes,
2666
+ subject: {
2667
+ kind: "type alias",
2668
+ name: alias.symbol.name
2669
+ },
2670
+ list: false,
2671
+ typeName: alias.baseName,
2672
+ typeResolution: alias.baseResolution,
2673
+ typeConstructor: contributedTypeOf(alias.baseResolution, input.binder)
2674
+ };
2675
+ }
2676
+ /**
2677
+ * Refuses each attribute a field writes that its type alias already carries, at the field's attribute. Returns whether it refused any.
2678
+ */
2679
+ function refuseRepeatedTypeAliasAttributes(input) {
2680
+ const carried = typeAliasAttributeNames(input.alias);
2681
+ const aliasName = "symbol" in input.alias ? input.alias.symbol.name : input.alias.name;
2682
+ const repeated = input.field.attributes.filter(({ name }) => carried.has(name));
2683
+ const source = diagnosticSource(input.sources, input.field.node.syntax);
2684
+ for (const attribute of repeated) input.diagnostics.push({
2685
+ code: "PSL_DUPLICATE_ATTRIBUTE",
2686
+ message: `Field "${input.fieldPath}" writes @${attribute.name}, which its type alias "${aliasName}" already sets. Remove one of them.`,
2687
+ ...source.at(attribute.span)
2688
+ });
2689
+ return repeated.length > 0;
2690
+ }
2445
2691
  //#endregion
2446
- export { EMPTY_DATA_TYPES, NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, assembleAttributeSpecs, blockAttribute, blockSpecContext, blockSpecFactoryOf, bool, buildSymbolTable, contributedTypeOf, createBinder, createPslDiagnosticCollector, dataTypeValue, diagnosticFromSpan, diagnosticSource, entityRef, entityReference, enumMemberValue, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, generatorAttributeSpec, generatorFunctionCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, interpretExtensionBlock, interpretExtensionBlockAttributes, interpretExtensionBlocks, isNamespaceLike, isPrismaNextSchema, isPslIdentifier, json, jsonValue, keywordPslSpan, leafDiagnostic, list, mapArg, mapBlock, mapPslDiagnostics, matchesSelector, memberEntries, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, nodeSourceText, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readExpressionAs, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, readWrittenScalar, record, referencedFieldRef, refineArg, renameLegacyDirective, str, structBlock, taggedLiteral, typeReferenceNode, writtenList, writtenScalar };
2692
+ export { EMPTY_DATA_TYPES, NAME_THE_PSL_SOURCE_LOSES, PSL_UNRESOLVED_REFERENCE, TYPE_ALIAS_ATTRIBUTE_NAMES, assembleAttributeSpecs, blockAttribute, blockSpecContext, blockSpecFactoryOf, bool, buildSymbolTable, contributedTypeAliasOf, contributedTypeCodecId, contributedTypeOf, createBinder, createPslDiagnosticCollector, dataTypeValue, diagnosticFromSpan, diagnosticSource, entityRef, entityReference, enumMemberValue, fieldAttribute, fieldRef, findBlockDescriptor, flatPslModels, funcCall, generatorAttributeSpec, generatorFunctionCall, getPositionalArgument, identifier, int, interpretArgs, interpretAttribute, interpretExtensionBlock, interpretExtensionBlockAttributes, interpretExtensionBlocks, isNamespaceLike, isPrismaNextSchema, isPslIdentifier, json, jsonValue, keywordPslSpan, leafDiagnostic, list, mapArg, mapBlock, mapPslDiagnostics, matchesSelector, memberEntries, modelAttribute, namespacePslExtensionBlocks, nodePslSpan, nodeSourceText, num, numLiteral, oneOf, optional, parseQuotedStringLiteral, readExpressionAs, readResolvedAttribute, readResolvedAttributes, readResolvedConstructorCall, readWrittenScalar, record, referencedFieldRef, refineArg, refuseRepeatedTypeAliasAttributes, renameLegacyDirective, resolveTypeAliases, str, structBlock, taggedLiteral, typeAliasAttributeNames, typeAliasOfField, typeAliasSpecContext, typeAttribute, typeAttributeSpecContextOfField, typeAttributeSubjectLabel, typeGeneratorAttributeSpec, typeReferenceNode, writtenList, writtenScalar };
2447
2693
 
2448
2694
  //# sourceMappingURL=psl-parser.mjs.map