@aventara/core 0.1.0-pilot.4 → 1.0.0-rc.1

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 (255) hide show
  1. package/CHANGELOG.md +1478 -0
  2. package/README.md +275 -11
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +17 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -25
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/avz/avz.js +354 -0
  19. package/dist/avz/index.d.ts +7 -0
  20. package/dist/avz/index.js +1 -0
  21. package/dist/avz/json-shape.registry.d.ts +22 -0
  22. package/dist/avz/json-shape.registry.js +16 -0
  23. package/dist/avz/zod-issue.translator.d.ts +57 -0
  24. package/dist/avz/zod-issue.translator.js +149 -0
  25. package/dist/compiler/contract-compiler-diagnostic.d.ts +37 -5
  26. package/dist/compiler/contract.compiler.d.ts +18 -18
  27. package/dist/compiler/contract.compiler.js +595 -421
  28. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  29. package/dist/compiler/create-requirements.projector.js +423 -0
  30. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  31. package/dist/compiler/field-validator.compiler.js +238 -0
  32. package/dist/config/any-framework-config.d.ts +19 -12
  33. package/dist/config/config-diagnostic.d.ts +11 -4
  34. package/dist/config/config-layer.d.ts +15 -6
  35. package/dist/config/config.resolver.d.ts +75 -29
  36. package/dist/config/config.resolver.js +109 -44
  37. package/dist/config/config.validator.d.ts +7 -7
  38. package/dist/config/config.validator.js +586 -71
  39. package/dist/config/define-resource.d.ts +57 -0
  40. package/dist/config/define-resource.js +14 -0
  41. package/dist/config/effective-fields.d.ts +19 -23
  42. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  43. package/dist/config/exact-framework-config.d.ts +280 -0
  44. package/dist/config/field-compute.resolver.d.ts +19 -0
  45. package/dist/config/field-compute.resolver.js +115 -0
  46. package/dist/config/field-pipeline-config.d.ts +47 -0
  47. package/dist/config/forced-operation.validator.d.ts +10 -0
  48. package/dist/config/forced-operation.validator.js +66 -0
  49. package/dist/config/framework-config.d.ts +111 -37
  50. package/dist/config/framework-exemptions-config.d.ts +91 -0
  51. package/dist/config/framework-exemptions-config.js +1 -0
  52. package/dist/config/framework-field-definition.d.ts +78 -0
  53. package/dist/config/framework-field-definition.js +28 -0
  54. package/dist/config/framework-resources-config.d.ts +116 -0
  55. package/dist/config/framework-resources-config.js +1 -0
  56. package/dist/config/pipeline-config.d.ts +56 -20
  57. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  58. package/dist/config/pipeline-tree.resolver.js +220 -0
  59. package/dist/config/stage-type.eraser.d.ts +65 -0
  60. package/dist/config/stage-type.eraser.js +1 -0
  61. package/dist/contracts/capability.d.ts +11 -11
  62. package/dist/contracts/client-contract-structure.validator.d.ts +344 -29
  63. package/dist/contracts/client-contract-structure.validator.js +248 -7
  64. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  65. package/dist/contracts/contract-canonicalizer.js +172 -27
  66. package/dist/contracts/contract-hash.d.ts +12 -7
  67. package/dist/contracts/contract-hash.js +3 -2
  68. package/dist/contracts/contract-limits.d.ts +4 -1
  69. package/dist/contracts/contract-limits.js +1 -0
  70. package/dist/contracts/contract-lookup.d.ts +5 -5
  71. package/dist/contracts/contract-protocol.d.ts +4 -4
  72. package/dist/contracts/contract.d.ts +31 -16
  73. package/dist/contracts/create-requirements.d.ts +35 -0
  74. package/dist/contracts/create-requirements.js +1 -0
  75. package/dist/contracts/enum-definition.d.ts +1 -1
  76. package/dist/contracts/field-check.d.ts +101 -0
  77. package/dist/contracts/field-check.js +1 -0
  78. package/dist/contracts/field.d.ts +61 -41
  79. package/dist/contracts/identifier.d.ts +4 -4
  80. package/dist/contracts/json-shape.d.ts +76 -0
  81. package/dist/contracts/json-shape.js +1 -0
  82. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  83. package/dist/contracts/reference-write-limit.d.ts +7 -0
  84. package/dist/contracts/reference-write-limit.js +1 -0
  85. package/dist/contracts/resource-operations.d.ts +28 -28
  86. package/dist/contracts/resource.d.ts +15 -9
  87. package/dist/contracts/scalar-value-type.d.ts +25 -14
  88. package/dist/contracts/scalar.d.ts +3 -3
  89. package/dist/contracts/transaction-capability.d.ts +1 -1
  90. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  91. package/dist/framework/contract-view.d.ts +234 -63
  92. package/dist/framework/framework-construction.error.d.ts +10 -10
  93. package/dist/framework/framework-construction.error.js +2 -2
  94. package/dist/framework/framework.d.ts +50 -24
  95. package/dist/framework/framework.factory.d.ts +8 -6
  96. package/dist/framework/framework.factory.js +95 -32
  97. package/dist/framework/operation-facade.d.ts +123 -52
  98. package/dist/framework/operation-facade.js +9 -1
  99. package/dist/index.d.ts +55 -82
  100. package/dist/index.js +6 -26
  101. package/dist/internal.d.ts +40 -0
  102. package/dist/internal.js +18 -0
  103. package/dist/operations/operation-arguments.d.ts +316 -201
  104. package/dist/operations/operation-call.d.ts +27 -28
  105. package/dist/operations/operation-identity.d.ts +12 -10
  106. package/dist/operations/operation-identity.js +3 -0
  107. package/dist/operations/operation-result.d.ts +21 -21
  108. package/dist/operations/operation-validator-core.d.ts +6 -6
  109. package/dist/operations/operation-validator-core.js +41 -12
  110. package/dist/operations/operation-validator.d.ts +24 -9
  111. package/dist/operations/operation-validator.js +26 -10
  112. package/dist/operations/projection-scope.resolver.d.ts +7 -7
  113. package/dist/operations/structural-limits.walker.d.ts +19 -0
  114. package/dist/operations/structural-limits.walker.js +489 -0
  115. package/dist/operations/validation-code.d.ts +11 -6
  116. package/dist/operations/validation-code.js +4 -0
  117. package/dist/operations/write-scope.resolver.d.ts +6 -6
  118. package/dist/protocol/absent-route.responder.d.ts +13 -11
  119. package/dist/protocol/absent-route.responder.js +42 -16
  120. package/dist/protocol/contract-document.responder.d.ts +3 -3
  121. package/dist/protocol/contract-document.responder.js +2 -2
  122. package/dist/protocol/http-request.decoder.d.ts +23 -13
  123. package/dist/protocol/http-request.decoder.js +19 -11
  124. package/dist/protocol/http-request.reader.d.ts +3 -3
  125. package/dist/protocol/http-response.encoder.d.ts +4 -4
  126. package/dist/protocol/http-response.encoder.js +94 -55
  127. package/dist/protocol/http-status.table.d.ts +2 -2
  128. package/dist/protocol/operation-response.guard.d.ts +2 -2
  129. package/dist/protocol/protocol-surface.d.ts +4 -4
  130. package/dist/protocol/protocol.binder.d.ts +52 -27
  131. package/dist/protocol/protocol.binder.js +14 -9
  132. package/dist/protocol/protocol.handler.d.ts +28 -15
  133. package/dist/protocol/protocol.handler.js +55 -10
  134. package/dist/protocol/unmounted-route.error.d.ts +19 -0
  135. package/dist/protocol/unmounted-route.error.js +10 -0
  136. package/dist/runtime/caller-data.copier.d.ts +59 -0
  137. package/dist/runtime/caller-data.copier.js +470 -0
  138. package/dist/runtime/caller-data.door.d.ts +56 -0
  139. package/dist/runtime/caller-data.door.js +67 -0
  140. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  141. package/dist/runtime/computed-read-runtime.js +61 -55
  142. package/dist/runtime/computed-value.error.d.ts +13 -0
  143. package/dist/runtime/computed-value.error.js +9 -0
  144. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  145. package/dist/runtime/context-executor.runtime.js +275 -0
  146. package/dist/runtime/create-requirement.d.ts +22 -57
  147. package/dist/runtime/create-requirement.js +140 -37
  148. package/dist/runtime/decimal.d.ts +2 -2
  149. package/dist/runtime/decimal.js +1 -1
  150. package/dist/runtime/diagnostics-reporter.d.ts +64 -22
  151. package/dist/runtime/diagnostics-reporter.js +35 -4
  152. package/dist/runtime/error-boundary.d.ts +73 -8
  153. package/dist/runtime/error-boundary.js +104 -48
  154. package/dist/runtime/execution-options.d.ts +10 -2
  155. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  156. package/dist/runtime/field-check.evaluator.js +521 -0
  157. package/dist/runtime/field-compute.d.ts +64 -0
  158. package/dist/runtime/field-compute.js +1 -0
  159. package/dist/runtime/field-stage.plan.d.ts +15 -0
  160. package/dist/runtime/field-stage.plan.js +27 -0
  161. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  162. package/dist/runtime/field-stage.runtime.js +143 -0
  163. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  164. package/dist/runtime/field-validator.runtime.js +87 -0
  165. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  166. package/dist/runtime/framework-error-class.table.js +25 -0
  167. package/dist/runtime/framework-error.d.ts +79 -7
  168. package/dist/runtime/framework-error.factory.d.ts +4 -0
  169. package/dist/runtime/framework-error.factory.js +15 -0
  170. package/dist/runtime/framework-error.js +23 -2
  171. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  172. package/dist/runtime/interceptor-next.error.js +6 -0
  173. package/dist/runtime/json-value.d.ts +3 -3
  174. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  175. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  176. package/dist/runtime/misuse-reporter.d.ts +32 -0
  177. package/dist/runtime/misuse-reporter.js +19 -0
  178. package/dist/runtime/mutation-planner.d.ts +19 -10
  179. package/dist/runtime/mutation-planner.js +62 -36
  180. package/dist/runtime/nested-write.walker.d.ts +32 -0
  181. package/dist/runtime/nested-write.walker.js +73 -0
  182. package/dist/runtime/operation-request.d.ts +35 -15
  183. package/dist/runtime/operation-response.d.ts +17 -17
  184. package/dist/runtime/operation-runtime.d.ts +125 -30
  185. package/dist/runtime/operation-runtime.js +423 -83
  186. package/dist/runtime/outcome-mapper.d.ts +16 -5
  187. package/dist/runtime/outcome-mapper.js +35 -8
  188. package/dist/runtime/output-validator.d.ts +16 -6
  189. package/dist/runtime/output-validator.js +12 -1
  190. package/dist/runtime/owned-execution.registry.d.ts +13 -0
  191. package/dist/runtime/owned-execution.registry.js +7 -0
  192. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  193. package/dist/runtime/pipe-output.validator.js +12 -12
  194. package/dist/runtime/pipeline.d.ts +202 -28
  195. package/dist/runtime/readonly-value.d.ts +32 -0
  196. package/dist/runtime/readonly-value.js +141 -0
  197. package/dist/runtime/referential-action.d.ts +7 -0
  198. package/dist/runtime/request-envelope.validator.d.ts +5 -0
  199. package/dist/runtime/request-envelope.validator.js +123 -0
  200. package/dist/runtime/request-id.d.ts +1 -1
  201. package/dist/runtime/request-state.d.ts +14 -0
  202. package/dist/runtime/request-state.js +1 -0
  203. package/dist/runtime/request-state.resolver.d.ts +12 -0
  204. package/dist/runtime/request-state.resolver.js +20 -0
  205. package/dist/runtime/scalar-runtime.d.ts +56 -13
  206. package/dist/runtime/scalar-runtime.js +167 -86
  207. package/dist/transactions/deferred-operation.d.ts +35 -20
  208. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  209. package/dist/transactions/operation-arguments-encoder.js +2 -2
  210. package/dist/transactions/sql-statement.d.ts +77 -0
  211. package/dist/transactions/sql-statement.js +47 -0
  212. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  213. package/dist/transactions/sql-statement.validator.js +134 -0
  214. package/dist/transactions/transaction-envelope.d.ts +4 -4
  215. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  216. package/dist/transactions/transaction-integrity-error.js +5 -2
  217. package/dist/transactions/transaction-plan-assembler.d.ts +23 -9
  218. package/dist/transactions/transaction-plan-assembler.js +195 -82
  219. package/dist/transactions/transaction-plan-validator.d.ts +53 -21
  220. package/dist/transactions/transaction-plan-validator.js +246 -163
  221. package/dist/transactions/transaction-reference-collector.d.ts +30 -0
  222. package/dist/transactions/transaction-reference-collector.js +204 -0
  223. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  224. package/dist/transactions/transaction-reference-resolver.js +27 -10
  225. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  226. package/dist/transactions/transaction-reference-validator.js +82 -43
  227. package/dist/transactions/transaction-reference.d.ts +30 -58
  228. package/dist/transactions/transaction-request.d.ts +20 -7
  229. package/dist/transactions/transaction-response.d.ts +12 -7
  230. package/dist/transactions/transaction-response.js +24 -1
  231. package/dist/transactions/transaction-runtime.d.ts +11 -8
  232. package/dist/transactions/transaction-runtime.js +167 -50
  233. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  234. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  235. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  236. package/dist/transactions/transaction-slot-path-error.js +2 -2
  237. package/dist/transactions/transaction-slot-writer.js +2 -2
  238. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  239. package/dist/transactions/transaction-stage.runtime.js +123 -0
  240. package/package.json +18 -3
  241. package/src/runtime/field-check.evaluator.ts +720 -0
  242. package/dist/config/define-fields.d.ts +0 -35
  243. package/dist/config/define-fields.js +0 -3
  244. package/dist/config/framework-behaviors-config.d.ts +0 -30
  245. package/dist/config/framework-fields-config.d.ts +0 -36
  246. package/dist/config/framework-restrictions-config.d.ts +0 -142
  247. package/dist/operations/operation-boolean-nodes.d.ts +0 -11
  248. package/dist/operations/operation-boolean-nodes.js +0 -283
  249. package/dist/operations/operation-nesting.d.ts +0 -8
  250. package/dist/operations/operation-nesting.js +0 -307
  251. package/dist/runtime/field-behavior.d.ts +0 -48
  252. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  253. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  254. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  255. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,307 +0,0 @@
1
- import { lookupField, lookupResource } from "../contracts/contract-lookup.js";
2
- function isRecord(value) {
3
- return typeof value === "object" && value !== null && !Array.isArray(value);
4
- }
5
- function nestingIssue(context) {
6
- return {
7
- path: context.rootPath,
8
- code: "V1013",
9
- message: `Request nesting exceeds maxNestingDepth (${context.limit}).`,
10
- };
11
- }
12
- function checkDepth(context, depth) {
13
- return depth > context.limit ? nestingIssue(context) : undefined;
14
- }
15
- function createContext(contract, rootPath) {
16
- return {
17
- contract,
18
- limit: contract.limits.maxNestingDepth,
19
- rootPath,
20
- };
21
- }
22
- function relationEntries(value) {
23
- return Array.isArray(value) ? value : [value];
24
- }
25
- function walkWhere(context, resourceName, value, depth, path) {
26
- const exceeded = checkDepth(context, depth);
27
- if (exceeded !== undefined || !isRecord(value)) {
28
- return exceeded;
29
- }
30
- const resource = lookupResource(context.contract, resourceName);
31
- if (resource === undefined) {
32
- return undefined;
33
- }
34
- for (const [key, child] of Object.entries(value)) {
35
- if (key === "AND" || key === "OR") {
36
- if (!Array.isArray(child)) {
37
- continue;
38
- }
39
- for (let index = 0; index < child.length; index += 1) {
40
- const issue = walkWhere(context, resourceName, child[index], depth + 1, [...path, key, index]);
41
- if (issue !== undefined) {
42
- return issue;
43
- }
44
- }
45
- continue;
46
- }
47
- if (key === "NOT") {
48
- const issue = walkWhere(context, resourceName, child, depth + 1, [
49
- ...path,
50
- key,
51
- ]);
52
- if (issue !== undefined) {
53
- return issue;
54
- }
55
- continue;
56
- }
57
- const field = lookupField(resource, key);
58
- if (field?.kind !== "relation") {
59
- continue;
60
- }
61
- if (field.cardinality === "one") {
62
- const issue = walkWhere(context, field.target, child, depth + 1, [
63
- ...path,
64
- key,
65
- ]);
66
- if (issue !== undefined) {
67
- return issue;
68
- }
69
- continue;
70
- }
71
- if (!isRecord(child)) {
72
- continue;
73
- }
74
- for (const relationOperator of ["some", "every", "none"]) {
75
- if (!(relationOperator in child)) {
76
- continue;
77
- }
78
- const issue = walkWhere(context, field.target, child[relationOperator], depth + 1, [...path, key, relationOperator]);
79
- if (issue !== undefined) {
80
- return issue;
81
- }
82
- }
83
- }
84
- return undefined;
85
- }
86
- function walkOrderBy(context, resourceName, value, depth, path) {
87
- const entries = Array.isArray(value) ? value : [value];
88
- const resource = lookupResource(context.contract, resourceName);
89
- if (resource === undefined) {
90
- return undefined;
91
- }
92
- for (let index = 0; index < entries.length; index += 1) {
93
- const entry = entries[index];
94
- if (!isRecord(entry)) {
95
- continue;
96
- }
97
- const entryPath = Array.isArray(value) ? [...path, index] : path;
98
- for (const [fieldName, child] of Object.entries(entry)) {
99
- const field = lookupField(resource, fieldName);
100
- if (field?.kind !== "relation" || field.cardinality === "many") {
101
- continue;
102
- }
103
- const relationDepth = depth + 1;
104
- const exceeded = checkDepth(context, relationDepth);
105
- if (exceeded !== undefined) {
106
- return exceeded;
107
- }
108
- const issue = walkOrderBy(context, field.target, child, relationDepth, [
109
- ...entryPath,
110
- fieldName,
111
- ]);
112
- if (issue !== undefined) {
113
- return issue;
114
- }
115
- }
116
- }
117
- return undefined;
118
- }
119
- function walkProjection(context, resourceName, value, depth, path) {
120
- if (!Array.isArray(value)) {
121
- return undefined;
122
- }
123
- const resource = lookupResource(context.contract, resourceName);
124
- if (resource === undefined) {
125
- return undefined;
126
- }
127
- for (let index = 0; index < value.length; index += 1) {
128
- const entry = value[index];
129
- if (!isRecord(entry) || Object.keys(entry).length !== 1) {
130
- continue;
131
- }
132
- const relationName = Object.keys(entry)[0];
133
- const edge = lookupField(resource, relationName);
134
- if (edge?.kind !== "relation") {
135
- continue;
136
- }
137
- const relationPath = [...path, index, relationName];
138
- const relationDepth = depth + 1;
139
- const exceeded = checkDepth(context, relationDepth);
140
- if (exceeded !== undefined) {
141
- return exceeded;
142
- }
143
- const projection = entry[relationName];
144
- if (!isRecord(projection)) {
145
- continue;
146
- }
147
- if ("where" in projection) {
148
- const issue = walkWhere(context, edge.target, projection.where, relationDepth, [...relationPath, "where"]);
149
- if (issue !== undefined) {
150
- return issue;
151
- }
152
- }
153
- if ("orderBy" in projection) {
154
- const issue = walkOrderBy(context, edge.target, projection.orderBy, relationDepth, [...relationPath, "orderBy"]);
155
- if (issue !== undefined) {
156
- return issue;
157
- }
158
- }
159
- for (const mode of ["select", "include"]) {
160
- if (!(mode in projection)) {
161
- continue;
162
- }
163
- const issue = walkProjection(context, edge.target, projection[mode], relationDepth, [...relationPath, mode]);
164
- if (issue !== undefined) {
165
- return issue;
166
- }
167
- }
168
- }
169
- return undefined;
170
- }
171
- function nestedMutationPayloads(directive, value) {
172
- const values = relationEntries(value);
173
- const payloads = [];
174
- for (let index = 0; index < values.length; index += 1) {
175
- const entry = values[index];
176
- const indexPath = Array.isArray(value) ? [index] : [];
177
- if (directive === "$create") {
178
- payloads.push({ data: entry, suffix: indexPath });
179
- continue;
180
- }
181
- if (!isRecord(entry)) {
182
- continue;
183
- }
184
- if (directive === "$connectOrCreate" && "create" in entry) {
185
- payloads.push({ data: entry.create, suffix: [...indexPath, "create"] });
186
- continue;
187
- }
188
- if (directive === "$update" && "data" in entry) {
189
- payloads.push({ data: entry.data, suffix: [...indexPath, "data"] });
190
- continue;
191
- }
192
- if (directive === "$upsert") {
193
- if ("create" in entry) {
194
- payloads.push({ data: entry.create, suffix: [...indexPath, "create"] });
195
- }
196
- if ("update" in entry) {
197
- payloads.push({ data: entry.update, suffix: [...indexPath, "update"] });
198
- }
199
- }
200
- }
201
- return payloads;
202
- }
203
- function walkMutationDirectiveWheres(context, resourceName, directive, value, depth, path) {
204
- if (directive !== "$update" && directive !== "$delete") {
205
- return undefined;
206
- }
207
- const entries = relationEntries(value);
208
- for (let index = 0; index < entries.length; index += 1) {
209
- const entry = entries[index];
210
- if (!isRecord(entry) || !("where" in entry)) {
211
- continue;
212
- }
213
- const indexPath = Array.isArray(value) ? [index] : [];
214
- const issue = walkWhere(context, resourceName, entry.where, depth, [
215
- ...path,
216
- ...indexPath,
217
- "where",
218
- ]);
219
- if (issue !== undefined) {
220
- return issue;
221
- }
222
- }
223
- return undefined;
224
- }
225
- function walkMutationData(context, resourceName, value, depth, path) {
226
- const exceeded = checkDepth(context, depth);
227
- if (exceeded !== undefined || !isRecord(value)) {
228
- return exceeded;
229
- }
230
- const resource = lookupResource(context.contract, resourceName);
231
- if (resource === undefined) {
232
- return undefined;
233
- }
234
- for (const [fieldName, fieldValue] of Object.entries(value)) {
235
- const edge = lookupField(resource, fieldName);
236
- if (edge?.kind !== "relation" || !isRecord(fieldValue)) {
237
- continue;
238
- }
239
- for (const [directive, directiveValue] of Object.entries(fieldValue)) {
240
- const relationDepth = depth + 1;
241
- const relationPath = [...path, fieldName, directive];
242
- const relationExceeded = checkDepth(context, relationDepth);
243
- if (relationExceeded !== undefined) {
244
- return relationExceeded;
245
- }
246
- const whereIssue = walkMutationDirectiveWheres(context, edge.target, directive, directiveValue, relationDepth, relationPath);
247
- if (whereIssue !== undefined) {
248
- return whereIssue;
249
- }
250
- for (const payload of nestedMutationPayloads(directive, directiveValue)) {
251
- const issue = walkMutationData(context, edge.target, payload.data, relationDepth, [...relationPath, ...payload.suffix]);
252
- if (issue !== undefined) {
253
- return issue;
254
- }
255
- }
256
- }
257
- }
258
- return undefined;
259
- }
260
- export function findOperationNestingIssue(contract, resourceName, args) {
261
- if ("where" in args) {
262
- const rootPath = ["arguments", "where"];
263
- const issue = walkWhere(createContext(contract, rootPath), resourceName, args.where, 1, rootPath);
264
- if (issue !== undefined) {
265
- return issue;
266
- }
267
- }
268
- if ("orderBy" in args) {
269
- const rootPath = ["arguments", "orderBy"];
270
- const issue = walkOrderBy(createContext(contract, rootPath), resourceName, args.orderBy, 0, rootPath);
271
- if (issue !== undefined) {
272
- return issue;
273
- }
274
- }
275
- for (const mode of ["select", "include"]) {
276
- if (!(mode in args)) {
277
- continue;
278
- }
279
- const rootPath = ["arguments", mode];
280
- const issue = walkProjection(createContext(contract, rootPath), resourceName, args[mode], 0, rootPath);
281
- if (issue !== undefined) {
282
- return issue;
283
- }
284
- }
285
- if ("data" in args) {
286
- const rootPath = ["arguments", "data"];
287
- const context = createContext(contract, rootPath);
288
- const dataEntries = Array.isArray(args.data) ? args.data : [args.data];
289
- for (let index = 0; index < dataEntries.length; index += 1) {
290
- const issue = walkMutationData(context, resourceName, dataEntries[index], 0, Array.isArray(args.data) ? [...rootPath, index] : rootPath);
291
- if (issue !== undefined) {
292
- return issue;
293
- }
294
- }
295
- }
296
- for (const branch of ["create", "update"]) {
297
- if (!(branch in args)) {
298
- continue;
299
- }
300
- const rootPath = ["arguments", branch];
301
- const issue = walkMutationData(createContext(contract, rootPath), resourceName, args[branch], 0, rootPath);
302
- if (issue !== undefined) {
303
- return issue;
304
- }
305
- }
306
- return undefined;
307
- }
@@ -1,48 +0,0 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
3
- import type { RequestOrigin } from "../config/config-layer.js";
4
- import type { EffectiveFieldKey } from "../config/effective-fields.js";
5
- import type { FrameworkResourceKey } from "../config/framework-fields-config.js";
6
- import type { PipelineContext } from "./pipeline.js";
7
- /**
8
- * What a write-stage compute callback is told about the field it is computing.
9
- */
10
- type ComputedWriteContext<M extends AdapterModel, Cfg, R extends FrameworkResourceKey<M>> = {
11
- readonly scope: RequestOrigin;
12
- readonly resource: R;
13
- readonly field: EffectiveFieldKey<M, Cfg, R>;
14
- readonly value: unknown;
15
- readonly data: Readonly<Record<EffectiveFieldKey<M, Cfg, R>, unknown>>;
16
- readonly operation: PipelineContext;
17
- };
18
- /**
19
- * Computes a field's value when a row is created. It receives the incoming
20
- * `data` and returns the value to store.
21
- */
22
- export type ComputeOnCreate<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = (context: ComputedWriteContext<M, Cfg, R>) => unknown | Promise<unknown>;
23
- /**
24
- * Computes a field's value when a row is updated. It receives the incoming
25
- * `data` and returns the value to store.
26
- */
27
- export type ComputeOnUpdate<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = (context: ComputedWriteContext<M, Cfg, R>) => unknown | Promise<unknown>;
28
- /**
29
- * Computes a field's value when a row is read. It receives the stored `record`
30
- * and returns the value to return.
31
- */
32
- export type ComputeOnRead<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = (context: {
33
- readonly scope: RequestOrigin;
34
- readonly resource: R;
35
- readonly field: EffectiveFieldKey<M, Cfg, R>;
36
- readonly value: unknown;
37
- readonly record: Readonly<Record<EffectiveFieldKey<M, Cfg, R>, unknown>>;
38
- readonly operation: PipelineContext;
39
- }) => unknown | Promise<unknown>;
40
- /**
41
- * A computed read: a compute function, or `{ compute, dependsOn }` naming the
42
- * fields it reads.
43
- */
44
- export type ComputedReadBehavior<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = ComputeOnRead<M, Cfg, R> | {
45
- readonly dependsOn?: readonly EffectiveFieldKey<M, Cfg, R>[];
46
- readonly compute: ComputeOnRead<M, Cfg, R>;
47
- };
48
- export {};