@aventara/core 1.0.0-rc.0 → 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 (242) hide show
  1. package/CHANGELOG.md +1140 -0
  2. package/README.md +224 -57
  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 +9 -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 -29
  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/{json → avz}/avz.js +150 -8
  19. package/dist/{json → avz}/index.d.ts +2 -1
  20. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  21. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  22. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  23. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  24. package/dist/compiler/contract.compiler.d.ts +18 -18
  25. package/dist/compiler/contract.compiler.js +548 -441
  26. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  27. package/dist/compiler/create-requirements.projector.js +423 -0
  28. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  29. package/dist/compiler/field-validator.compiler.js +238 -0
  30. package/dist/config/any-framework-config.d.ts +19 -12
  31. package/dist/config/config-diagnostic.d.ts +11 -4
  32. package/dist/config/config-layer.d.ts +15 -6
  33. package/dist/config/config.resolver.d.ts +74 -31
  34. package/dist/config/config.resolver.js +108 -44
  35. package/dist/config/config.validator.d.ts +7 -7
  36. package/dist/config/config.validator.js +581 -72
  37. package/dist/config/define-resource.d.ts +57 -0
  38. package/dist/config/define-resource.js +14 -0
  39. package/dist/config/effective-fields.d.ts +19 -23
  40. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  41. package/dist/config/exact-framework-config.d.ts +280 -0
  42. package/dist/config/field-compute.resolver.d.ts +19 -0
  43. package/dist/config/field-compute.resolver.js +115 -0
  44. package/dist/config/field-pipeline-config.d.ts +47 -0
  45. package/dist/config/forced-operation.validator.d.ts +10 -0
  46. package/dist/config/forced-operation.validator.js +66 -0
  47. package/dist/config/framework-config.d.ts +110 -39
  48. package/dist/config/framework-exemptions-config.d.ts +91 -0
  49. package/dist/config/framework-exemptions-config.js +1 -0
  50. package/dist/config/framework-field-definition.d.ts +78 -0
  51. package/dist/config/framework-field-definition.js +28 -0
  52. package/dist/config/framework-resources-config.d.ts +116 -0
  53. package/dist/config/framework-resources-config.js +1 -0
  54. package/dist/config/pipeline-config.d.ts +56 -20
  55. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  56. package/dist/config/pipeline-tree.resolver.js +220 -0
  57. package/dist/config/stage-type.eraser.d.ts +65 -0
  58. package/dist/config/stage-type.eraser.js +1 -0
  59. package/dist/contracts/capability.d.ts +11 -11
  60. package/dist/contracts/client-contract-structure.validator.d.ts +323 -28
  61. package/dist/contracts/client-contract-structure.validator.js +152 -8
  62. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  63. package/dist/contracts/contract-canonicalizer.js +141 -28
  64. package/dist/contracts/contract-hash.d.ts +12 -7
  65. package/dist/contracts/contract-hash.js +3 -2
  66. package/dist/contracts/contract-limits.d.ts +4 -1
  67. package/dist/contracts/contract-limits.js +1 -0
  68. package/dist/contracts/contract-lookup.d.ts +5 -5
  69. package/dist/contracts/contract-protocol.d.ts +4 -4
  70. package/dist/contracts/contract.d.ts +24 -16
  71. package/dist/contracts/create-requirements.d.ts +35 -0
  72. package/dist/contracts/create-requirements.js +1 -0
  73. package/dist/contracts/enum-definition.d.ts +1 -1
  74. package/dist/contracts/field-check.d.ts +101 -0
  75. package/dist/contracts/field-check.js +1 -0
  76. package/dist/contracts/field.d.ts +52 -42
  77. package/dist/contracts/identifier.d.ts +4 -4
  78. package/dist/contracts/json-shape.d.ts +12 -1
  79. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  80. package/dist/contracts/resource-operations.d.ts +28 -28
  81. package/dist/contracts/resource.d.ts +15 -9
  82. package/dist/contracts/scalar-value-type.d.ts +15 -15
  83. package/dist/contracts/scalar.d.ts +3 -3
  84. package/dist/contracts/transaction-capability.d.ts +1 -1
  85. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  86. package/dist/framework/contract-view.d.ts +213 -147
  87. package/dist/framework/framework-construction.error.d.ts +10 -10
  88. package/dist/framework/framework-construction.error.js +2 -2
  89. package/dist/framework/framework.d.ts +47 -23
  90. package/dist/framework/framework.factory.d.ts +8 -6
  91. package/dist/framework/framework.factory.js +40 -20
  92. package/dist/framework/operation-facade.d.ts +123 -52
  93. package/dist/framework/operation-facade.js +9 -1
  94. package/dist/index.d.ts +55 -50
  95. package/dist/index.js +6 -6
  96. package/dist/internal.d.ts +15 -10
  97. package/dist/internal.js +3 -1
  98. package/dist/operations/operation-arguments.d.ts +267 -202
  99. package/dist/operations/operation-call.d.ts +27 -28
  100. package/dist/operations/operation-identity.d.ts +10 -10
  101. package/dist/operations/operation-result.d.ts +21 -21
  102. package/dist/operations/operation-validator-core.d.ts +6 -6
  103. package/dist/operations/operation-validator-core.js +13 -2
  104. package/dist/operations/operation-validator.d.ts +9 -9
  105. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  106. package/dist/operations/structural-limits.walker.d.ts +6 -6
  107. package/dist/operations/structural-limits.walker.js +145 -0
  108. package/dist/operations/validation-code.d.ts +11 -6
  109. package/dist/operations/validation-code.js +4 -0
  110. package/dist/operations/write-scope.resolver.d.ts +6 -6
  111. package/dist/protocol/absent-route.responder.d.ts +13 -12
  112. package/dist/protocol/absent-route.responder.js +19 -19
  113. package/dist/protocol/contract-document.responder.d.ts +3 -3
  114. package/dist/protocol/contract-document.responder.js +2 -2
  115. package/dist/protocol/http-request.decoder.d.ts +17 -13
  116. package/dist/protocol/http-request.decoder.js +10 -10
  117. package/dist/protocol/http-request.reader.d.ts +3 -3
  118. package/dist/protocol/http-response.encoder.d.ts +4 -4
  119. package/dist/protocol/http-response.encoder.js +94 -55
  120. package/dist/protocol/http-status.table.d.ts +2 -2
  121. package/dist/protocol/operation-response.guard.d.ts +2 -2
  122. package/dist/protocol/protocol-surface.d.ts +4 -4
  123. package/dist/protocol/protocol.binder.d.ts +50 -27
  124. package/dist/protocol/protocol.binder.js +12 -9
  125. package/dist/protocol/protocol.handler.d.ts +22 -13
  126. package/dist/protocol/protocol.handler.js +44 -9
  127. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  128. package/dist/protocol/unmounted-route.error.js +2 -2
  129. package/dist/runtime/caller-data.copier.d.ts +5 -5
  130. package/dist/runtime/caller-data.copier.js +13 -13
  131. package/dist/runtime/caller-data.door.d.ts +6 -6
  132. package/dist/runtime/caller-data.door.js +6 -4
  133. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  134. package/dist/runtime/computed-read-runtime.js +61 -48
  135. package/dist/runtime/computed-value.error.d.ts +6 -6
  136. package/dist/runtime/computed-value.error.js +3 -3
  137. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  138. package/dist/runtime/context-executor.runtime.js +275 -0
  139. package/dist/runtime/create-requirement.d.ts +10 -81
  140. package/dist/runtime/create-requirement.js +80 -57
  141. package/dist/runtime/decimal.d.ts +2 -2
  142. package/dist/runtime/decimal.js +1 -1
  143. package/dist/runtime/diagnostics-reporter.d.ts +53 -27
  144. package/dist/runtime/diagnostics-reporter.js +24 -0
  145. package/dist/runtime/error-boundary.d.ts +65 -8
  146. package/dist/runtime/error-boundary.js +45 -19
  147. package/dist/runtime/execution-options.d.ts +10 -2
  148. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  149. package/dist/runtime/field-check.evaluator.js +521 -0
  150. package/dist/runtime/field-compute.d.ts +64 -0
  151. package/dist/runtime/field-compute.js +1 -0
  152. package/dist/runtime/field-stage.plan.d.ts +15 -0
  153. package/dist/runtime/field-stage.plan.js +27 -0
  154. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  155. package/dist/runtime/field-stage.runtime.js +143 -0
  156. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  157. package/dist/runtime/field-validator.runtime.js +87 -0
  158. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  159. package/dist/runtime/framework-error-class.table.js +25 -0
  160. package/dist/runtime/framework-error.d.ts +68 -8
  161. package/dist/runtime/framework-error.factory.d.ts +4 -0
  162. package/dist/runtime/framework-error.factory.js +15 -0
  163. package/dist/runtime/framework-error.js +23 -2
  164. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  165. package/dist/runtime/interceptor-next.error.js +6 -0
  166. package/dist/runtime/json-value.d.ts +3 -3
  167. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  168. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  169. package/dist/runtime/misuse-reporter.d.ts +12 -12
  170. package/dist/runtime/mutation-planner.d.ts +19 -10
  171. package/dist/runtime/mutation-planner.js +54 -30
  172. package/dist/runtime/nested-write.walker.d.ts +32 -0
  173. package/dist/runtime/nested-write.walker.js +73 -0
  174. package/dist/runtime/operation-request.d.ts +33 -6
  175. package/dist/runtime/operation-response.d.ts +17 -17
  176. package/dist/runtime/operation-runtime.d.ts +113 -25
  177. package/dist/runtime/operation-runtime.js +395 -74
  178. package/dist/runtime/outcome-mapper.d.ts +16 -5
  179. package/dist/runtime/outcome-mapper.js +23 -6
  180. package/dist/runtime/output-validator.d.ts +10 -10
  181. package/dist/runtime/output-validator.js +3 -3
  182. package/dist/runtime/owned-execution.registry.d.ts +6 -6
  183. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  184. package/dist/runtime/pipe-output.validator.js +12 -12
  185. package/dist/runtime/pipeline.d.ts +196 -34
  186. package/dist/runtime/readonly-value.d.ts +32 -0
  187. package/dist/runtime/readonly-value.js +141 -0
  188. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  189. package/dist/runtime/request-envelope.validator.js +12 -7
  190. package/dist/runtime/request-id.d.ts +1 -1
  191. package/dist/runtime/request-state.d.ts +14 -0
  192. package/dist/runtime/request-state.js +1 -0
  193. package/dist/runtime/request-state.resolver.d.ts +12 -0
  194. package/dist/runtime/request-state.resolver.js +20 -0
  195. package/dist/runtime/scalar-runtime.d.ts +31 -16
  196. package/dist/runtime/scalar-runtime.js +16 -18
  197. package/dist/transactions/deferred-operation.d.ts +35 -20
  198. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  199. package/dist/transactions/operation-arguments-encoder.js +2 -2
  200. package/dist/transactions/sql-statement.d.ts +77 -0
  201. package/dist/transactions/sql-statement.js +47 -0
  202. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  203. package/dist/transactions/sql-statement.validator.js +134 -0
  204. package/dist/transactions/transaction-envelope.d.ts +4 -4
  205. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  206. package/dist/transactions/transaction-integrity-error.js +5 -2
  207. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  208. package/dist/transactions/transaction-plan-assembler.js +148 -34
  209. package/dist/transactions/transaction-plan-validator.d.ts +29 -20
  210. package/dist/transactions/transaction-plan-validator.js +70 -38
  211. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  212. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  213. package/dist/transactions/transaction-reference-resolver.js +26 -14
  214. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  215. package/dist/transactions/transaction-reference-validator.js +58 -26
  216. package/dist/transactions/transaction-reference.d.ts +13 -13
  217. package/dist/transactions/transaction-request.d.ts +18 -5
  218. package/dist/transactions/transaction-response.d.ts +6 -6
  219. package/dist/transactions/transaction-runtime.d.ts +8 -7
  220. package/dist/transactions/transaction-runtime.js +166 -50
  221. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  222. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  223. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  224. package/dist/transactions/transaction-slot-path-error.js +2 -2
  225. package/dist/transactions/transaction-slot-writer.js +2 -2
  226. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  227. package/dist/transactions/transaction-stage.runtime.js +123 -0
  228. package/package.json +6 -5
  229. package/src/runtime/field-check.evaluator.ts +720 -0
  230. package/dist/config/define-fields.d.ts +0 -42
  231. package/dist/config/define-fields.js +0 -3
  232. package/dist/config/framework-behaviors-config.d.ts +0 -30
  233. package/dist/config/framework-fields-config.d.ts +0 -42
  234. package/dist/config/framework-restrictions-config.d.ts +0 -142
  235. package/dist/json/avz.d.ts +0 -96
  236. package/dist/runtime/field-behavior.d.ts +0 -48
  237. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  238. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  239. /package/dist/{json → avz}/index.js +0 -0
  240. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  241. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  242. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -0,0 +1,79 @@
1
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
2
+ import type { AvFieldGuard, AvFieldPipe } from "../runtime/pipeline.js";
3
+ import type { ResolvedPipelineConfig, ResolvedTransactionPipelineConfig } from "./pipeline-config.js";
4
+ /** One variant's levels and whether a layer forces it. */
5
+ export type ResolvedVariantPipelines = {
6
+ readonly pipelines: readonly ResolvedPipelineConfig[];
7
+ readonly forceTransaction: boolean;
8
+ };
9
+ /** One family's levels, its variants' and whether a layer forces the family. */
10
+ export type ResolvedFamilyPipelines = ResolvedVariantPipelines & {
11
+ readonly variants: Readonly<Record<string, ResolvedVariantPipelines>>;
12
+ };
13
+ /** One field's stages for one origin: the root's, then the overlay's. */
14
+ export type ResolvedFieldStages = {
15
+ readonly pipes: readonly AvFieldPipe[];
16
+ readonly guards: readonly AvFieldGuard[];
17
+ /**
18
+ * The field's validators as authored, root's then overlay's: the Contract compiler
19
+ * checks and compiles them; the runtime reads the compiled form
20
+ * (`field-validator.registry.ts`).
21
+ */
22
+ readonly validators: readonly unknown[];
23
+ };
24
+ /** One Resource's levels for one origin. */
25
+ export type ResolvedResourcePipelines = {
26
+ readonly pipelines: readonly ResolvedPipelineConfig[];
27
+ readonly families: Readonly<Record<string, ResolvedFamilyPipelines>>;
28
+ readonly transactions: readonly ResolvedTransactionPipelineConfig[];
29
+ readonly fields: Readonly<Record<string, ResolvedFieldStages>>;
30
+ };
31
+ /** Every stage that runs for one origin, by level. */
32
+ export type ResolvedPipelineTree = {
33
+ readonly layer: readonly ResolvedPipelineConfig[];
34
+ readonly resources: Readonly<Record<string, ResolvedResourcePipelines>>;
35
+ };
36
+ type UnknownRecord = Readonly<Record<string, unknown>>;
37
+ /**
38
+ * The pipeline tree of one origin: each layer's registrations in turn, at every
39
+ * level — the root's, then the overlay's; for the agent, the root's, then the
40
+ * overlay it extends, then its own. The root layer alone (the Core Contract's)
41
+ * is one layer.
42
+ */
43
+ export declare function resolvePipelineTree(layers: readonly UnknownRecord[]): ResolvedPipelineTree;
44
+ /** The tree a raw ctx call runs over: `tree`'s field pipes, and nothing else. */
45
+ export declare function rawPipelineTree(tree: ResolvedPipelineTree): ResolvedPipelineTree;
46
+ /**
47
+ * The levels of one operation, outer to inner: root layer, overlay layer, root
48
+ * Resource, overlay Resource, root family, overlay family, root variant, overlay
49
+ * variant. A level no layer states is left out.
50
+ */
51
+ export declare function operationLevels(tree: ResolvedPipelineTree, operation: AvOperationIdentity & {
52
+ readonly resource: string;
53
+ }): readonly ResolvedPipelineConfig[];
54
+ /**
55
+ * The levels a nested write's target runs, outer to inner: root Resource,
56
+ * overlay Resource, root family, overlay family. A level no layer states is
57
+ * left out.
58
+ */
59
+ export declare function nestedTargetLevels(tree: ResolvedPipelineTree, resource: string, family: string): readonly ResolvedPipelineConfig[];
60
+ /** Whether a layer sets `forceTransaction` on the operation's family or variant. */
61
+ export declare function isForcedOperation(tree: ResolvedPipelineTree, operation: AvOperationIdentity & {
62
+ readonly resource: string;
63
+ }): boolean;
64
+ /** The field stages registered on one Resource's fields, by field name. */
65
+ export declare function fieldStagesOf(tree: ResolvedPipelineTree, resource: string): Readonly<Record<string, ResolvedFieldStages>>;
66
+ /** One Resource's transaction levels: the root's, then the overlay's. */
67
+ export declare function transactionLevelsOf(tree: ResolvedPipelineTree, resource: string): readonly ResolvedTransactionPipelineConfig[];
68
+ /**
69
+ * Every `forceTransaction` the tree states, as the configuration paths that set
70
+ * it (`resources.R.operations.F[.V]`), with the operation each one forces. Read
71
+ * once at construction, for the startup check against `transactionsStyle`.
72
+ */
73
+ export declare function forcedOperationsOf(layer: UnknownRecord, prefix: string): readonly {
74
+ readonly path: string;
75
+ readonly resource: string;
76
+ readonly family: string;
77
+ readonly variant: string | undefined;
78
+ }[];
79
+ export {};
@@ -0,0 +1,220 @@
1
+ function isRecord(value) {
2
+ return value !== null && typeof value === "object" && !Array.isArray(value);
3
+ }
4
+ function own(record, key) {
5
+ return record !== undefined && Object.hasOwn(record, key)
6
+ ? record[key]
7
+ : undefined;
8
+ }
9
+ function list(value) {
10
+ return Array.isArray(value) ? [...value] : [];
11
+ }
12
+ function levelOf(value) {
13
+ if (!isRecord(value)) {
14
+ return undefined;
15
+ }
16
+ const pipeline = value;
17
+ return {
18
+ guards: list(pipeline.guards),
19
+ pipes: list(pipeline.pipes),
20
+ hooks: {
21
+ before: list(pipeline.hooks?.before),
22
+ after: list(pipeline.hooks?.after),
23
+ },
24
+ interceptors: list(pipeline.interceptors),
25
+ filters: list(pipeline.filters),
26
+ };
27
+ }
28
+ function transactionLevelOf(value) {
29
+ if (!isRecord(value)) {
30
+ return undefined;
31
+ }
32
+ const pipeline = value;
33
+ return {
34
+ guards: list(pipeline.guards),
35
+ pipes: list(pipeline.pipes),
36
+ hooks: {
37
+ before: list(pipeline.hooks?.before),
38
+ after: list(pipeline.hooks?.after),
39
+ },
40
+ interceptors: list(pipeline.interceptors),
41
+ filters: list(pipeline.filters),
42
+ };
43
+ }
44
+ function levels(layers, read) {
45
+ return layers.flatMap((layer) => {
46
+ const level = read(layer);
47
+ return level === undefined ? [] : [level];
48
+ });
49
+ }
50
+ function child(value, key) {
51
+ return isRecord(value) && Object.hasOwn(value, key) ? value[key] : undefined;
52
+ }
53
+ function forced(layers) {
54
+ return layers.some((layer) => child(layer, "forceTransaction") === true);
55
+ }
56
+ function keysOf(layers, skip) {
57
+ const keys = new Set();
58
+ for (const layer of layers) {
59
+ if (!isRecord(layer)) {
60
+ continue;
61
+ }
62
+ for (const key of Object.keys(layer)) {
63
+ if (skip?.has(key) !== true) {
64
+ keys.add(key);
65
+ }
66
+ }
67
+ }
68
+ return keys;
69
+ }
70
+ const FAMILY_LEVEL_KEYS = new Set(["pipelines", "forceTransaction"]);
71
+ function resolveVariant(layers) {
72
+ return {
73
+ pipelines: levels(layers, (layer) => levelOf(child(layer, "pipelines"))),
74
+ forceTransaction: forced(layers),
75
+ };
76
+ }
77
+ function resolveFamily(layers) {
78
+ const variants = {};
79
+ for (const variant of keysOf(layers, FAMILY_LEVEL_KEYS)) {
80
+ variants[variant] = resolveVariant(layers.map((layer) => child(layer, variant)));
81
+ }
82
+ return { ...resolveVariant(layers), variants };
83
+ }
84
+ function resolveFields(layers) {
85
+ const fields = {};
86
+ for (const field of keysOf(layers)) {
87
+ const pipelines = layers.map((layer) => child(child(layer, field), "pipelines"));
88
+ const pipes = pipelines.flatMap((stage) => list(child(stage, "pipes")));
89
+ const guards = pipelines.flatMap((stage) => list(child(stage, "guards")));
90
+ const validators = pipelines.flatMap((stage) => list(child(stage, "validators")));
91
+ if (pipes.length > 0 || guards.length > 0 || validators.length > 0) {
92
+ fields[field] = { pipes, guards, validators };
93
+ }
94
+ }
95
+ return fields;
96
+ }
97
+ function resolveResource(layers) {
98
+ const operations = layers.map((layer) => child(layer, "operations"));
99
+ const families = {};
100
+ for (const family of keysOf(operations)) {
101
+ families[family] = resolveFamily(operations.map((layer) => child(layer, family)));
102
+ }
103
+ return {
104
+ pipelines: levels(layers, (layer) => levelOf(child(layer, "pipelines"))),
105
+ families,
106
+ transactions: levels(layers, (layer) => transactionLevelOf(child(child(layer, "transactions"), "pipelines"))),
107
+ fields: resolveFields(layers.map((layer) => child(layer, "fields"))),
108
+ };
109
+ }
110
+ export function resolvePipelineTree(layers) {
111
+ const trees = layers.map((layer) => child(layer, "resources"));
112
+ const resources = {};
113
+ for (const resource of keysOf(trees)) {
114
+ resources[resource] = resolveResource(trees.map((tree) => child(tree, resource)));
115
+ }
116
+ return {
117
+ layer: levels(layers, (layer) => levelOf(child(layer, "pipelines"))),
118
+ resources,
119
+ };
120
+ }
121
+ const NO_LEVELS = Object.freeze([]);
122
+ export function rawPipelineTree(tree) {
123
+ const resources = {};
124
+ for (const [name, resource] of Object.entries(tree.resources)) {
125
+ const fields = {};
126
+ for (const [field, stages] of Object.entries(resource.fields)) {
127
+ if (stages.pipes.length > 0) {
128
+ fields[field] = {
129
+ pipes: stages.pipes,
130
+ guards: [],
131
+ validators: stages.validators,
132
+ };
133
+ }
134
+ }
135
+ resources[name] = {
136
+ pipelines: NO_LEVELS,
137
+ families: {},
138
+ transactions: [],
139
+ fields,
140
+ };
141
+ }
142
+ return { layer: NO_LEVELS, resources };
143
+ }
144
+ export function operationLevels(tree, operation) {
145
+ const resource = own(tree.resources, operation.resource);
146
+ if (resource === undefined) {
147
+ return tree.layer;
148
+ }
149
+ const family = own(resource.families, operation.family);
150
+ const variant = own(family?.variants, operation.variant);
151
+ return [
152
+ ...tree.layer,
153
+ ...resource.pipelines,
154
+ ...(family?.pipelines ?? NO_LEVELS),
155
+ ...(variant?.pipelines ?? NO_LEVELS),
156
+ ];
157
+ }
158
+ export function nestedTargetLevels(tree, resource, family) {
159
+ const found = own(tree.resources, resource);
160
+ if (found === undefined) {
161
+ return NO_LEVELS;
162
+ }
163
+ return [
164
+ ...found.pipelines,
165
+ ...(own(found.families, family)?.pipelines ?? NO_LEVELS),
166
+ ];
167
+ }
168
+ export function isForcedOperation(tree, operation) {
169
+ const family = own(own(tree.resources, operation.resource)?.families, operation.family);
170
+ return (family?.forceTransaction === true ||
171
+ own(family?.variants, operation.variant)?.forceTransaction === true);
172
+ }
173
+ const NO_FIELDS = Object.freeze({});
174
+ export function fieldStagesOf(tree, resource) {
175
+ return own(tree.resources, resource)?.fields ?? NO_FIELDS;
176
+ }
177
+ export function transactionLevelsOf(tree, resource) {
178
+ return own(tree.resources, resource)?.transactions ?? [];
179
+ }
180
+ export function forcedOperationsOf(layer, prefix) {
181
+ const found = [];
182
+ const resources = child(layer, "resources");
183
+ if (!isRecord(resources)) {
184
+ return found;
185
+ }
186
+ for (const [resource, entry] of Object.entries(resources)) {
187
+ const operations = child(entry, "operations");
188
+ if (!isRecord(operations)) {
189
+ continue;
190
+ }
191
+ for (const [family, level] of Object.entries(operations)) {
192
+ const familyPath = `${prefix}resources.${resource}.operations.${family}`;
193
+ if (child(level, "forceTransaction") === true) {
194
+ found.push({
195
+ path: `${familyPath}.forceTransaction`,
196
+ resource,
197
+ family,
198
+ variant: undefined,
199
+ });
200
+ }
201
+ if (!isRecord(level)) {
202
+ continue;
203
+ }
204
+ for (const [variant, variantLevel] of Object.entries(level)) {
205
+ if (FAMILY_LEVEL_KEYS.has(variant)) {
206
+ continue;
207
+ }
208
+ if (child(variantLevel, "forceTransaction") === true) {
209
+ found.push({
210
+ path: `${familyPath}.${variant}.forceTransaction`,
211
+ resource,
212
+ family,
213
+ variant,
214
+ });
215
+ }
216
+ }
217
+ }
218
+ }
219
+ return found;
220
+ }
@@ -0,0 +1,65 @@
1
+ import type { AvComputeCreate, AvComputeRead, AvComputeUpdate } from "../runtime/field-compute.js";
2
+ import type { AvScalarFieldPipeline } from "./field-pipeline-config.js";
3
+ import type { AvPipeline, AvTransactionPipeline } from "./pipeline-config.js";
4
+ /** Stage lists of one `pipelines` value as `Wide` states them; `validators` kept. */
5
+ type ErasedPipelines<P, Wide> = P extends object ? {
6
+ [K in keyof P]: K extends "validators" ? P[K] : K extends "compute" ? ErasedCompute<P[K]> : K extends "hooks" ? ErasedStageGroup<P[K], NonNullable<Wide[K & keyof Wide]>> : K extends keyof Wide ? NonNullable<Wide[K]> : P[K];
7
+ } : P;
8
+ /** `hooks`, by phase (`before`, `after`). */
9
+ type ErasedStageGroup<G, Wide> = G extends object ? {
10
+ [K in keyof G]: K extends keyof Wide ? NonNullable<Wide[K]> : G[K];
11
+ } : G;
12
+ /** A field's `compute`, by phase; a read stage's `dependsOn` kept. */
13
+ type ErasedCompute<C> = C extends object ? {
14
+ [K in keyof C]: K extends "create" ? AvComputeCreate : K extends "update" ? AvComputeUpdate : K extends "read" ? C[K] extends {
15
+ readonly compute: unknown;
16
+ } ? {
17
+ [D in keyof C[K]]: D extends "compute" ? ComputeReadStage : C[K][D];
18
+ } : ComputeReadStage : C[K];
19
+ } : C;
20
+ /** A read compute stage's function form, for any model. */
21
+ type ComputeReadStage = Parameters<Extract<AvComputeRead, (context: never) => unknown>>[0] extends infer Context ? (context: Context) => unknown : never;
22
+ /** A variant's level: its `pipelines` erased, `forceTransaction` kept. */
23
+ type ErasedVariant<V> = V extends object ? {
24
+ [K in keyof V]: K extends "pipelines" ? ErasedPipelines<V[K], AvPipeline> : V[K];
25
+ } : V;
26
+ /** A family's level: its own `pipelines` and each variant's. */
27
+ type ErasedFamily<F> = F extends object ? {
28
+ [K in keyof F]: K extends "pipelines" ? ErasedPipelines<F[K], AvPipeline> : K extends "forceTransaction" ? F[K] : ErasedVariant<F[K]>;
29
+ } : F;
30
+ /** A field's entry: its `definition` kept, its `pipelines` erased. */
31
+ type ErasedField<Field> = Field extends object ? {
32
+ [K in keyof Field]: K extends "pipelines" ? ErasedPipelines<Field[K], AvScalarFieldPipeline> : Field[K];
33
+ } : Field;
34
+ /**
35
+ * One Resource's block with every stage stated by its public type for any model.
36
+ */
37
+ export type ErasedResourceBlock<B> = B extends object ? {
38
+ [K in keyof B]: K extends "pipelines" ? ErasedPipelines<B[K], AvPipeline> : K extends "operations" ? {
39
+ [F in keyof B[K]]: ErasedFamily<B[K][F]>;
40
+ } : K extends "transactions" ? {
41
+ [T in keyof B[K]]: T extends "pipelines" ? ErasedPipelines<B[K][T], AvTransactionPipeline> : B[K][T];
42
+ } : K extends "fields" ? {
43
+ [Name in keyof B[K]]: ErasedField<B[K][Name]>;
44
+ } : B[K];
45
+ } : B;
46
+ /** A Resource's overlay blocks (`application`, `client`, `agent`), each erased. */
47
+ export type ErasedOverlayBlocks<Overlays> = Overlays extends object ? {
48
+ [L in keyof Overlays]: ErasedResourceBlock<Overlays[L]>;
49
+ } : Overlays;
50
+ /** A `resources` tree: each Resource's block erased. */
51
+ export type ErasedResources<Resources> = Resources extends object ? {
52
+ [R in keyof Resources]: ErasedResourceBlock<Resources[R]>;
53
+ } : Resources;
54
+ /** One layer (the root's keys, `application`, `client`, `agent`): its stages erased. */
55
+ type ErasedLayer<Layer> = Layer extends object ? {
56
+ [K in keyof Layer]: K extends "pipelines" ? ErasedPipelines<Layer[K], AvPipeline> : K extends "resources" ? ErasedResources<Layer[K]> : Layer[K];
57
+ } : Layer;
58
+ /**
59
+ * An authored configuration with every stage stated by its public type for any
60
+ * model: the `Cfg` a Framework carries (see the note above).
61
+ */
62
+ export type ErasedConfig<Cfg> = Cfg extends object ? {
63
+ [K in keyof Cfg]: K extends "pipelines" ? ErasedPipelines<Cfg[K], AvPipeline> : K extends "resources" ? ErasedResources<Cfg[K]> : K extends "application" | "client" | "agent" ? ErasedLayer<Cfg[K]> : Cfg[K];
64
+ } : Cfg;
65
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,15 @@
1
1
  /** The operators a scalar field can be filtered with. */
2
- export type ScalarFilterOperator = "equals" | "not" | "in" | "notIn" | "lt" | "lte" | "gt" | "gte" | "contains" | "startsWith" | "endsWith" | "mode" | "has" | "hasEvery" | "hasSome" | "isEmpty" | "path" | "stringContains" | "stringStartsWith" | "stringEndsWith" | "arrayContains" | "arrayStartsWith" | "arrayEndsWith";
2
+ export type AvScalarFilterOperator = "equals" | "not" | "in" | "notIn" | "lt" | "lte" | "gt" | "gte" | "contains" | "startsWith" | "endsWith" | "mode" | "has" | "hasEvery" | "hasSome" | "isEmpty" | "path" | "stringContains" | "stringStartsWith" | "stringEndsWith" | "arrayContains" | "arrayStartsWith" | "arrayEndsWith";
3
3
  /** What an update can do to a scalar value besides setting it. */
4
- export type ScalarMutationDirective = "$increment" | "$decrement" | "$multiply" | "$divide" | "$push" | "$unset";
4
+ export type AvScalarMutationDirective = "$increment" | "$decrement" | "$multiply" | "$divide" | "$push" | "$unset";
5
5
  /** How a relation can be filtered on. */
6
- export type RelationFilterCapability = "nested" | "match" | "null" | "some" | "every" | "none";
6
+ export type AvRelationFilterCapability = "nested" | "match" | "null" | "some" | "every" | "none";
7
7
  /** What a write can do to a relation: `$create`, `$connect` and the rest. */
8
- export type RelationMutationDirective = "$create" | "$connect" | "$connectOrCreate" | "$disconnect" | "$set" | "$update" | "$delete" | "$upsert";
8
+ export type AvRelationMutationDirective = "$create" | "$connect" | "$connectOrCreate" | "$disconnect" | "$set" | "$update" | "$delete" | "$upsert";
9
9
  /** How a list of related rows can be paginated. */
10
- export type PaginationCapability = "limit" | "offset" | "cursor";
10
+ export type AvPaginationCapability = "limit" | "offset" | "cursor";
11
11
  /** What a projection can compute over a to-many relation. */
12
- export type RelationReducer = "$count";
12
+ export type AvRelationReducer = "$count";
13
13
  /**
14
14
  * Where a projected field may be asked for: the kind of argument POSITION a projection
15
15
  * sits in, not the operation that carries it. A variant states the position its
@@ -17,13 +17,13 @@ export type RelationReducer = "$count";
17
17
  * projectable in.
18
18
  */
19
19
  export declare const PROJECTION_SCOPES: readonly ["record", "bulkWrite"];
20
- /** @see PROJECTION_SCOPES — the axis this union is derived from. */
21
- export type ProjectionScope = (typeof PROJECTION_SCOPES)[number];
20
+ /** @see PROJECTION_SCOPES, the axis this union is derived from. */
21
+ export type AvProjectionScope = (typeof PROJECTION_SCOPES)[number];
22
22
  /**
23
23
  * Where a field may be written: the kind of argument POSITION a write sits in,
24
24
  * not the operation that carries it. The write counterpart of
25
- * {@link ProjectionScope}.
25
+ * {@link AvProjectionScope}.
26
26
  */
27
27
  export declare const WRITE_SCOPES: readonly ["nested", "bulkWrite"];
28
- /** @see WRITE_SCOPES — the axis this union is derived from. */
29
- export type WriteScope = (typeof WRITE_SCOPES)[number];
28
+ /** @see WRITE_SCOPES, the axis this union is derived from. */
29
+ export type AvWriteScope = (typeof WRITE_SCOPES)[number];