@aventara/core 1.0.0-rc.0 → 1.0.0-rc.2
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.
- package/CHANGELOG.md +1434 -0
- package/ERRORS.md +142 -0
- package/README.md +247 -57
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
- package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
- package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
- package/dist/adapters/adapter-field.d.ts +25 -11
- package/dist/adapters/adapter-identifier.d.ts +6 -6
- package/dist/adapters/adapter-model.d.ts +18 -9
- package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
- package/dist/adapters/adapter-operation.d.ts +3 -3
- package/dist/adapters/adapter-resource.d.ts +18 -9
- package/dist/adapters/adapter-sql-statement.d.ts +19 -0
- package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
- package/dist/adapters/adapter.interface.d.ts +59 -29
- package/dist/avz/avz-check.factory.d.ts +83 -0
- package/dist/avz/avz-check.factory.js +116 -0
- package/dist/avz/avz-check.registry.d.ts +35 -0
- package/dist/avz/avz-check.registry.js +9 -0
- package/dist/avz/avz.d.ts +203 -0
- package/dist/{json → avz}/avz.js +150 -8
- package/dist/{json → avz}/index.d.ts +2 -1
- package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
- package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
- package/dist/{json → avz}/zod-issue.translator.js +7 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
- package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
- package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
- package/dist/compiler/contract.compiler.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +637 -442
- package/dist/compiler/create-requirements.projector.d.ts +49 -0
- package/dist/compiler/create-requirements.projector.js +423 -0
- package/dist/compiler/field-validator.compiler.d.ts +47 -0
- package/dist/compiler/field-validator.compiler.js +238 -0
- package/dist/config/any-framework-config.d.ts +19 -12
- package/dist/config/computed-fields.d.ts +62 -0
- package/dist/config/computed-fields.js +80 -0
- package/dist/config/config-diagnostic.d.ts +11 -4
- package/dist/config/config-diagnostic.guidance.d.ts +6 -0
- package/dist/config/config-diagnostic.guidance.js +32 -0
- package/dist/config/config-layer.d.ts +15 -6
- package/dist/config/config.resolver.d.ts +74 -31
- package/dist/config/config.resolver.js +108 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +581 -72
- package/dist/config/define-resource.d.ts +57 -0
- package/dist/config/define-resource.js +14 -0
- package/dist/config/effective-fields.d.ts +19 -23
- package/dist/config/entrypoint.normalizer.d.ts +1 -1
- package/dist/config/exact-framework-config.d.ts +308 -0
- package/dist/config/field-compute.resolver.d.ts +21 -0
- package/dist/config/field-compute.resolver.js +123 -0
- package/dist/config/field-pipeline-config.d.ts +47 -0
- package/dist/config/forced-operation.validator.d.ts +10 -0
- package/dist/config/forced-operation.validator.js +66 -0
- package/dist/config/framework-config.d.ts +111 -39
- package/dist/config/framework-exemptions-config.d.ts +91 -0
- package/dist/config/framework-exemptions-config.js +1 -0
- package/dist/config/framework-field-definition.d.ts +78 -0
- package/dist/config/framework-field-definition.js +28 -0
- package/dist/config/framework-resources-config.d.ts +122 -0
- package/dist/config/framework-resources-config.js +1 -0
- package/dist/config/pipeline-config.d.ts +56 -20
- package/dist/config/pipeline-tree.resolver.d.ts +79 -0
- package/dist/config/pipeline-tree.resolver.js +220 -0
- package/dist/config/stage-type.eraser.d.ts +65 -0
- package/dist/config/stage-type.eraser.js +1 -0
- package/dist/contracts/capability.d.ts +21 -12
- package/dist/contracts/capability.js +2 -0
- package/dist/contracts/client-contract-structure.validator.d.ts +388 -63
- package/dist/contracts/client-contract-structure.validator.js +156 -10
- package/dist/contracts/contract-canonicalizer.d.ts +26 -3
- package/dist/contracts/contract-canonicalizer.js +156 -29
- package/dist/contracts/contract-hash.d.ts +12 -7
- package/dist/contracts/contract-hash.js +3 -2
- package/dist/contracts/contract-limits.d.ts +4 -1
- package/dist/contracts/contract-limits.js +1 -0
- package/dist/contracts/contract-lookup.d.ts +5 -5
- package/dist/contracts/contract-protocol.d.ts +4 -4
- package/dist/contracts/contract.d.ts +24 -16
- package/dist/contracts/create-requirements.d.ts +35 -0
- package/dist/contracts/create-requirements.js +1 -0
- package/dist/contracts/enum-definition.d.ts +1 -1
- package/dist/contracts/field-check.d.ts +101 -0
- package/dist/contracts/field-check.js +1 -0
- package/dist/contracts/field.d.ts +81 -42
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-shape.d.ts +12 -1
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- package/dist/contracts/resource-operations.d.ts +28 -28
- package/dist/contracts/resource.d.ts +15 -9
- package/dist/contracts/scalar-value-type.d.ts +15 -15
- package/dist/contracts/scalar.d.ts +3 -3
- package/dist/contracts/transaction-capability.d.ts +1 -1
- package/dist/contracts/wire-scalar-format.d.ts +4 -4
- package/dist/framework/contract-view.d.ts +213 -147
- package/dist/framework/framework-construction.error.d.ts +19 -10
- package/dist/framework/framework-construction.error.js +7 -3
- package/dist/framework/framework.d.ts +47 -23
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +49 -22
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +57 -50
- package/dist/index.js +7 -6
- package/dist/internal.d.ts +17 -10
- package/dist/internal.js +4 -1
- package/dist/operations/database-refusal.d.ts +51 -0
- package/dist/operations/database-refusal.js +45 -0
- package/dist/operations/operation-arguments.d.ts +343 -207
- package/dist/operations/operation-call.d.ts +27 -28
- package/dist/operations/operation-identity.d.ts +10 -10
- package/dist/operations/operation-result.d.ts +21 -21
- package/dist/operations/operation-validator-core.d.ts +6 -6
- package/dist/operations/operation-validator-core.js +99 -6
- package/dist/operations/operation-validator.d.ts +9 -9
- package/dist/operations/projection-scope.resolver.d.ts +6 -6
- package/dist/operations/structural-limits.walker.d.ts +6 -6
- package/dist/operations/structural-limits.walker.js +145 -0
- package/dist/operations/validation-code.d.ts +11 -6
- package/dist/operations/validation-code.guidance.d.ts +6 -0
- package/dist/operations/validation-code.guidance.js +90 -0
- package/dist/operations/validation-code.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +10 -6
- package/dist/operations/write-scope.resolver.js +2 -0
- package/dist/protocol/absent-route.responder.d.ts +13 -12
- package/dist/protocol/absent-route.responder.js +19 -19
- package/dist/protocol/contract-document.responder.d.ts +3 -3
- package/dist/protocol/contract-document.responder.js +2 -2
- package/dist/protocol/http-request.decoder.d.ts +17 -13
- package/dist/protocol/http-request.decoder.js +10 -10
- package/dist/protocol/http-request.reader.d.ts +3 -3
- package/dist/protocol/http-response.encoder.d.ts +4 -4
- package/dist/protocol/http-response.encoder.js +94 -55
- package/dist/protocol/http-status.table.d.ts +2 -2
- package/dist/protocol/operation-response.guard.d.ts +2 -2
- package/dist/protocol/protocol-surface.d.ts +4 -4
- package/dist/protocol/protocol.binder.d.ts +50 -27
- package/dist/protocol/protocol.binder.js +12 -9
- package/dist/protocol/protocol.handler.d.ts +22 -13
- package/dist/protocol/protocol.handler.js +91 -17
- package/dist/protocol/unmounted-route.error.d.ts +4 -4
- package/dist/protocol/unmounted-route.error.js +2 -2
- package/dist/runtime/caller-data.copier.d.ts +22 -5
- package/dist/runtime/caller-data.copier.js +31 -14
- package/dist/runtime/caller-data.door.d.ts +17 -11
- package/dist/runtime/caller-data.door.js +6 -4
- package/dist/runtime/computed-read-runtime.d.ts +7 -6
- package/dist/runtime/computed-read-runtime.js +76 -50
- package/dist/runtime/computed-value.error.d.ts +7 -6
- package/dist/runtime/computed-value.error.js +5 -4
- package/dist/runtime/context-executor.runtime.d.ts +59 -0
- package/dist/runtime/context-executor.runtime.js +275 -0
- package/dist/runtime/create-requirement.d.ts +44 -79
- package/dist/runtime/create-requirement.js +213 -73
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +54 -27
- package/dist/runtime/diagnostics-reporter.js +24 -0
- package/dist/runtime/error-boundary.d.ts +65 -8
- package/dist/runtime/error-boundary.js +49 -19
- package/dist/runtime/error-guidance.d.ts +12 -0
- package/dist/runtime/error-guidance.js +1 -0
- package/dist/runtime/error.catalog.d.ts +49 -0
- package/dist/runtime/error.catalog.js +49 -0
- package/dist/runtime/execution-options.d.ts +10 -2
- package/dist/runtime/field-check.evaluator.d.ts +29 -0
- package/dist/runtime/field-check.evaluator.js +521 -0
- package/dist/runtime/field-compute.d.ts +64 -0
- package/dist/runtime/field-compute.js +1 -0
- package/dist/runtime/field-stage.plan.d.ts +15 -0
- package/dist/runtime/field-stage.plan.js +27 -0
- package/dist/runtime/field-stage.runtime.d.ts +37 -0
- package/dist/runtime/field-stage.runtime.js +147 -0
- package/dist/runtime/field-validator.runtime.d.ts +19 -0
- package/dist/runtime/field-validator.runtime.js +92 -0
- package/dist/runtime/framework-error-class.table.d.ts +33 -0
- package/dist/runtime/framework-error-class.table.js +25 -0
- package/dist/runtime/framework-error.d.ts +68 -8
- package/dist/runtime/framework-error.factory.d.ts +4 -0
- package/dist/runtime/framework-error.factory.js +15 -0
- package/dist/runtime/framework-error.js +23 -2
- package/dist/runtime/interceptor-next.error.d.ts +5 -0
- package/dist/runtime/interceptor-next.error.js +6 -0
- package/dist/runtime/json-value.d.ts +11 -6
- package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
- package/dist/runtime/level-lifecycle.runtime.js +39 -0
- package/dist/runtime/misuse-reporter.d.ts +12 -12
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +48 -35
- package/dist/runtime/nested-write.walker.d.ts +32 -0
- package/dist/runtime/nested-write.walker.js +73 -0
- package/dist/runtime/operation-code.guidance.d.ts +6 -0
- package/dist/runtime/operation-code.guidance.js +167 -0
- package/dist/runtime/operation-request.d.ts +33 -6
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +127 -25
- package/dist/runtime/operation-runtime.js +441 -78
- package/dist/runtime/outcome-mapper.d.ts +16 -5
- package/dist/runtime/outcome-mapper.js +23 -6
- package/dist/runtime/output-validator.d.ts +10 -10
- package/dist/runtime/output-validator.js +3 -3
- package/dist/runtime/owned-execution.registry.d.ts +16 -6
- package/dist/runtime/pipe-output.validator.d.ts +43 -18
- package/dist/runtime/pipe-output.validator.js +15 -13
- package/dist/runtime/pipeline.d.ts +223 -34
- package/dist/runtime/readonly-value.d.ts +43 -0
- package/dist/runtime/readonly-value.js +150 -0
- package/dist/runtime/request-envelope.validator.d.ts +3 -3
- package/dist/runtime/request-envelope.validator.js +12 -7
- package/dist/runtime/request-id.d.ts +1 -1
- package/dist/runtime/request-state.d.ts +14 -0
- package/dist/runtime/request-state.js +1 -0
- package/dist/runtime/request-state.resolver.d.ts +12 -0
- package/dist/runtime/request-state.resolver.js +20 -0
- package/dist/runtime/scalar-runtime.d.ts +35 -16
- package/dist/runtime/scalar-runtime.js +102 -34
- package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
- package/dist/runtime/unsent-value.normalizer.js +128 -0
- package/dist/transactions/deferred-operation.d.ts +35 -20
- package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
- package/dist/transactions/operation-arguments-encoder.js +2 -2
- package/dist/transactions/operation-fingerprint.js +2 -2
- package/dist/transactions/sql-statement.d.ts +85 -0
- package/dist/transactions/sql-statement.js +47 -0
- package/dist/transactions/sql-statement.validator.d.ts +44 -0
- package/dist/transactions/sql-statement.validator.js +167 -0
- package/dist/transactions/transaction-envelope.d.ts +4 -4
- package/dist/transactions/transaction-integrity-error.d.ts +6 -6
- package/dist/transactions/transaction-integrity-error.js +5 -2
- package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
- package/dist/transactions/transaction-plan-assembler.js +169 -32
- package/dist/transactions/transaction-plan-validator.d.ts +45 -20
- package/dist/transactions/transaction-plan-validator.js +96 -38
- package/dist/transactions/transaction-reference-collector.d.ts +5 -5
- package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
- package/dist/transactions/transaction-reference-resolver.js +26 -14
- package/dist/transactions/transaction-reference-validator.d.ts +76 -4
- package/dist/transactions/transaction-reference-validator.js +129 -71
- package/dist/transactions/transaction-reference.d.ts +13 -13
- package/dist/transactions/transaction-reference.js +5 -0
- package/dist/transactions/transaction-request.d.ts +18 -5
- package/dist/transactions/transaction-response.d.ts +6 -6
- package/dist/transactions/transaction-runtime.d.ts +8 -7
- package/dist/transactions/transaction-runtime.js +191 -50
- package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
- package/dist/transactions/transaction-settlement.runtime.js +120 -0
- package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
- package/dist/transactions/transaction-slot-path-error.js +2 -2
- package/dist/transactions/transaction-slot-writer.js +2 -2
- package/dist/transactions/transaction-stage.runtime.d.ts +82 -0
- package/dist/transactions/transaction-stage.runtime.js +126 -0
- package/package.json +9 -7
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -42
- package/dist/config/define-fields.js +0 -3
- package/dist/config/framework-behaviors-config.d.ts +0 -30
- package/dist/config/framework-fields-config.d.ts +0 -42
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- package/dist/json/avz.d.ts +0 -96
- package/dist/runtime/field-behavior.d.ts +0 -48
- /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
- /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
- /package/dist/{json → avz}/index.js +0 -0
- /package/dist/{json → avz}/json-shape.registry.js +0 -0
- /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
- /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
|
@@ -164,86 +164,136 @@ function isAssignable(source, destination, shape) {
|
|
|
164
164
|
return source.list && !source.nullable;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
export function invalidSourceIndexIssue(operationPath) {
|
|
168
|
+
return validationIssue("V1016", operationPath, "Transaction reference operation index is invalid.");
|
|
169
|
+
}
|
|
170
|
+
export function referenceSourceAt(earlier, sourceIndex, referencingIndex) {
|
|
171
|
+
if (typeof sourceIndex !== "number" ||
|
|
172
|
+
!Number.isInteger(sourceIndex) ||
|
|
173
|
+
sourceIndex < 0 ||
|
|
174
|
+
sourceIndex >= referencingIndex) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const source = earlier[sourceIndex];
|
|
178
|
+
return source !== undefined && source.index === sourceIndex
|
|
179
|
+
? source
|
|
180
|
+
: undefined;
|
|
181
|
+
}
|
|
182
|
+
export function sqlSourceIssue(pathPath) {
|
|
183
|
+
return validationIssue("V1010", pathPath, "Transaction reference source is a SQL step, whose rows cannot be referenced.");
|
|
184
|
+
}
|
|
185
|
+
export function referenceSourceField(source, segment, pathPath) {
|
|
186
|
+
if (source.kind === "sql") {
|
|
187
|
+
return { ok: false, issue: sqlSourceIssue(pathPath) };
|
|
188
|
+
}
|
|
189
|
+
if (source.request.variant === "many" || source.request.variant === "count") {
|
|
190
|
+
return {
|
|
191
|
+
ok: false,
|
|
192
|
+
issue: validationIssue("V1010", pathPath, "Transaction reference source has no addressable single-row projection."),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const projection = source.projection;
|
|
196
|
+
if (projection?.reducers.some((reducer) => reducer === segment)) {
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
issue: validationIssue("V1011", pathPath, "Transaction reference source is not a scalar field."),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const field = projection === undefined || !projection.requested.includes(segment)
|
|
203
|
+
? undefined
|
|
204
|
+
: lookupField(lookupResource(source.contract, projection.resource), segment);
|
|
205
|
+
if (field === undefined) {
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
issue: validationIssue("V1010", pathPath, "Transaction reference path is not present in the source projection."),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return { ok: true, field };
|
|
212
|
+
}
|
|
167
213
|
const CANDIDATE_KEYS = new Set(["$ref"]);
|
|
168
214
|
const REFERENCE_KEYS = new Set(["operation", "fingerprint", "path"]);
|
|
169
|
-
export function
|
|
215
|
+
export function inspectReferenceCandidate(candidate, slotPath, earlier, referencingIndex) {
|
|
216
|
+
const refused = (issue) => ({ ok: false, issue });
|
|
217
|
+
const candidateInspection = inspectControlObject(candidate, CANDIDATE_KEYS, slotPath, validationIssue("V1001", slotPath, "Reference control value must be an object."));
|
|
218
|
+
if (!candidateInspection.ok) {
|
|
219
|
+
return refused(candidateInspection.issue);
|
|
220
|
+
}
|
|
221
|
+
const refPath = [...slotPath, "$ref"];
|
|
222
|
+
const refProperty = inspectOwnDataProperty(candidateInspection.value, "$ref", refPath, "V1001", slotPath);
|
|
223
|
+
if (!refProperty.ok) {
|
|
224
|
+
return refused(refProperty.issue);
|
|
225
|
+
}
|
|
226
|
+
const operationPath = [...refPath, "operation"];
|
|
227
|
+
const referenceInspection = inspectControlObject(refProperty.value, REFERENCE_KEYS, refPath, validationIssue("V1016", operationPath, "Transaction reference operation index is invalid."));
|
|
228
|
+
if (!referenceInspection.ok) {
|
|
229
|
+
return refused(referenceInspection.issue);
|
|
230
|
+
}
|
|
231
|
+
const sourceIndexProperty = inspectOwnDataProperty(referenceInspection.value, "operation", operationPath, "V1016", refPath);
|
|
232
|
+
if (!sourceIndexProperty.ok) {
|
|
233
|
+
return refused(sourceIndexProperty.issue);
|
|
234
|
+
}
|
|
235
|
+
const source = referenceSourceAt(earlier, sourceIndexProperty.value, referencingIndex);
|
|
236
|
+
if (source === undefined) {
|
|
237
|
+
return refused(invalidSourceIndexIssue(operationPath));
|
|
238
|
+
}
|
|
239
|
+
if (source.kind === "sql") {
|
|
240
|
+
return refused(sqlSourceIssue([...refPath, "path"]));
|
|
241
|
+
}
|
|
242
|
+
const fingerprintPath = [...refPath, "fingerprint"];
|
|
243
|
+
const fingerprintProperty = inspectOwnDataProperty(referenceInspection.value, "fingerprint", fingerprintPath, "V1000", refPath);
|
|
244
|
+
if (!fingerprintProperty.ok) {
|
|
245
|
+
return refused(fingerprintProperty.issue);
|
|
246
|
+
}
|
|
247
|
+
const fingerprint = fingerprintProperty.value;
|
|
248
|
+
if (!isOperationFingerprint(fingerprint) ||
|
|
249
|
+
fingerprint !== source.fingerprint) {
|
|
250
|
+
return refused(validationIssue("V1017", fingerprintPath, "Transaction reference fingerprint does not match its source operation."));
|
|
251
|
+
}
|
|
252
|
+
const pathPath = [...refPath, "path"];
|
|
253
|
+
const pathProperty = inspectOwnDataProperty(referenceInspection.value, "path", pathPath, "V1010", refPath);
|
|
254
|
+
if (!pathProperty.ok) {
|
|
255
|
+
return refused(pathProperty.issue);
|
|
256
|
+
}
|
|
257
|
+
const pathInspection = inspectPathTuple(pathProperty.value, pathPath);
|
|
258
|
+
if (!pathInspection.ok) {
|
|
259
|
+
return refused(pathInspection.issue);
|
|
260
|
+
}
|
|
261
|
+
const { segment } = pathInspection;
|
|
262
|
+
if (containsUnpairedSurrogate(segment)) {
|
|
263
|
+
return refused(validationIssue("V1010", pathPath, "Transaction reference path contains invalid Unicode."));
|
|
264
|
+
}
|
|
265
|
+
const sourceRead = referenceSourceField(source, segment, pathPath);
|
|
266
|
+
if (!sourceRead.ok) {
|
|
267
|
+
return refused(sourceRead.issue);
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
ok: true,
|
|
271
|
+
source,
|
|
272
|
+
segment,
|
|
273
|
+
fingerprint,
|
|
274
|
+
field: sourceRead.field,
|
|
275
|
+
pathPath,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
export function validateReferenceSlots(candidates, earlier, index) {
|
|
170
279
|
const references = [];
|
|
171
|
-
for (const slot of
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
const refPath = [...slot.path, "$ref"];
|
|
177
|
-
const refProperty = inspectOwnDataProperty(candidateInspection.value, "$ref", refPath, "V1001", slot.path);
|
|
178
|
-
if (!refProperty.ok) {
|
|
179
|
-
return failure(refProperty.issue, operation.index);
|
|
180
|
-
}
|
|
181
|
-
const operationPath = [...refPath, "operation"];
|
|
182
|
-
const referenceInspection = inspectControlObject(refProperty.value, REFERENCE_KEYS, refPath, validationIssue("V1016", operationPath, "Transaction reference operation index is invalid."));
|
|
183
|
-
if (!referenceInspection.ok) {
|
|
184
|
-
return failure(referenceInspection.issue, operation.index);
|
|
185
|
-
}
|
|
186
|
-
const sourceIndexProperty = inspectOwnDataProperty(referenceInspection.value, "operation", operationPath, "V1016", refPath);
|
|
187
|
-
if (!sourceIndexProperty.ok) {
|
|
188
|
-
return failure(sourceIndexProperty.issue, operation.index);
|
|
189
|
-
}
|
|
190
|
-
const sourceIndex = sourceIndexProperty.value;
|
|
191
|
-
const source = typeof sourceIndex === "number" && Number.isInteger(sourceIndex)
|
|
192
|
-
? earlier[sourceIndex]
|
|
193
|
-
: undefined;
|
|
194
|
-
if (typeof sourceIndex !== "number" ||
|
|
195
|
-
!Number.isInteger(sourceIndex) ||
|
|
196
|
-
sourceIndex < 0 ||
|
|
197
|
-
sourceIndex >= operation.index ||
|
|
198
|
-
source === undefined ||
|
|
199
|
-
source.index !== sourceIndex) {
|
|
200
|
-
return failure(validationIssue("V1016", operationPath, "Transaction reference operation index is invalid."), operation.index);
|
|
201
|
-
}
|
|
202
|
-
const fingerprintPath = [...refPath, "fingerprint"];
|
|
203
|
-
const fingerprintProperty = inspectOwnDataProperty(referenceInspection.value, "fingerprint", fingerprintPath, "V1017", refPath);
|
|
204
|
-
if (!fingerprintProperty.ok) {
|
|
205
|
-
return failure(fingerprintProperty.issue, operation.index);
|
|
206
|
-
}
|
|
207
|
-
const fingerprint = fingerprintProperty.value;
|
|
208
|
-
if (!isOperationFingerprint(fingerprint) ||
|
|
209
|
-
fingerprint !== source.fingerprint) {
|
|
210
|
-
return failure(validationIssue("V1017", fingerprintPath, "Transaction reference fingerprint does not match its source operation."), operation.index);
|
|
211
|
-
}
|
|
212
|
-
const pathPath = [...refPath, "path"];
|
|
213
|
-
const pathProperty = inspectOwnDataProperty(referenceInspection.value, "path", pathPath, "V1010", refPath);
|
|
214
|
-
if (!pathProperty.ok) {
|
|
215
|
-
return failure(pathProperty.issue, operation.index);
|
|
216
|
-
}
|
|
217
|
-
const pathInspection = inspectPathTuple(pathProperty.value, pathPath);
|
|
218
|
-
if (!pathInspection.ok) {
|
|
219
|
-
return failure(pathInspection.issue, operation.index);
|
|
220
|
-
}
|
|
221
|
-
const { segment } = pathInspection;
|
|
222
|
-
if (containsUnpairedSurrogate(segment)) {
|
|
223
|
-
return failure(validationIssue("V1010", pathPath, "Transaction reference path contains invalid Unicode."), operation.index);
|
|
224
|
-
}
|
|
225
|
-
if (source.request.variant === "many" ||
|
|
226
|
-
source.request.variant === "count") {
|
|
227
|
-
return failure(validationIssue("V1010", pathPath, "Transaction reference source has no addressable single-row projection."), operation.index);
|
|
228
|
-
}
|
|
229
|
-
const projection = source.projection;
|
|
230
|
-
if (projection?.reducers.some((reducer) => reducer === segment)) {
|
|
231
|
-
return failure(validationIssue("V1011", pathPath, "Transaction reference source is not a scalar field."), operation.index);
|
|
232
|
-
}
|
|
233
|
-
if (projection === undefined || !projection.requested.includes(segment)) {
|
|
234
|
-
return failure(validationIssue("V1010", pathPath, "Transaction reference path is not present in the source projection."), operation.index);
|
|
235
|
-
}
|
|
236
|
-
const sourceField = lookupField(lookupResource(source.contract, projection.resource), segment);
|
|
237
|
-
if (sourceField === undefined) {
|
|
238
|
-
return failure(validationIssue("V1010", pathPath, "Transaction reference path is not present in the source projection."), operation.index);
|
|
280
|
+
for (const slot of candidates) {
|
|
281
|
+
const inspection = inspectReferenceCandidate(slot.candidate, slot.path, earlier, index);
|
|
282
|
+
if (!inspection.ok) {
|
|
283
|
+
return inspection;
|
|
239
284
|
}
|
|
285
|
+
const { source, segment, fingerprint, pathPath } = inspection;
|
|
286
|
+
const sourceField = inspection.field;
|
|
240
287
|
if (sourceField.kind !== "scalar" ||
|
|
241
288
|
!isAssignable(sourceField, slot.field, slot.shape)) {
|
|
242
|
-
return
|
|
289
|
+
return {
|
|
290
|
+
ok: false,
|
|
291
|
+
issue: validationIssue("V1011", pathPath, "Transaction reference source type is not assignable to its destination."),
|
|
292
|
+
};
|
|
243
293
|
}
|
|
244
294
|
const reference = Object.freeze({
|
|
245
295
|
$ref: Object.freeze({
|
|
246
|
-
operation:
|
|
296
|
+
operation: source.index,
|
|
247
297
|
fingerprint,
|
|
248
298
|
path: Object.freeze([segment]),
|
|
249
299
|
}),
|
|
@@ -257,6 +307,14 @@ export function validateTransactionReferences(operation, earlier) {
|
|
|
257
307
|
reference,
|
|
258
308
|
});
|
|
259
309
|
}
|
|
310
|
+
return { ok: true, references };
|
|
311
|
+
}
|
|
312
|
+
export function validateTransactionReferences(operation, earlier) {
|
|
313
|
+
const validation = validateReferenceSlots(operation.candidates, earlier, operation.index);
|
|
314
|
+
if (!validation.ok) {
|
|
315
|
+
return failure(validation.issue, operation.index);
|
|
316
|
+
}
|
|
317
|
+
const { references } = validation;
|
|
260
318
|
const controls = references.map((slot) => ({
|
|
261
319
|
path: slot.path,
|
|
262
320
|
value: slot.reference,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvWriteScope } from "../contracts/capability.js";
|
|
2
|
+
import type { AvContract } from "../contracts/contract.js";
|
|
3
3
|
import type { ScalarForms } from "../contracts/scalar-value-type.js";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { AvCreateDataInput, AvOperationArgumentsFor, AvResourceKey, AvUpdateDataInput } from "../operations/operation-arguments.js";
|
|
5
|
+
import type { AvOperationIdentity } from "../operations/operation-identity.js";
|
|
6
6
|
import type { OperationFingerprint } from "./deferred-operation.js";
|
|
7
7
|
declare const REFERENCE_VALUE: unique symbol;
|
|
8
8
|
/** Any object with a `$ref` key, before it is validated as a reference. */
|
|
@@ -13,7 +13,7 @@ export type TransactionReferenceCandidate = {
|
|
|
13
13
|
* A reference to a field of an earlier operation's result in the same
|
|
14
14
|
* transaction plan: `{ $ref: { operation, fingerprint, path } }`.
|
|
15
15
|
*/
|
|
16
|
-
export type
|
|
16
|
+
export type AvTransactionReference<Value = unknown> = {
|
|
17
17
|
readonly $ref: {
|
|
18
18
|
readonly operation: number;
|
|
19
19
|
readonly fingerprint: OperationFingerprint;
|
|
@@ -38,12 +38,12 @@ export declare function routeTransactionReferenceCandidate(value: unknown): Tran
|
|
|
38
38
|
/** Whether `value` is an object with a `$ref` key; it is not validated here. */
|
|
39
39
|
export declare function isTransactionReferenceCandidate(value: unknown): value is TransactionReferenceCandidate;
|
|
40
40
|
/** Whether `value` is a complete `$ref` object. */
|
|
41
|
-
export declare function isTransactionReferenceObject(value: unknown): value is
|
|
41
|
+
export declare function isTransactionReferenceObject(value: unknown): value is AvTransactionReference;
|
|
42
42
|
/**
|
|
43
43
|
* A scalar mutation value inside a plan: the value itself, or a reference to an
|
|
44
44
|
* earlier operation's field of that same type.
|
|
45
45
|
*/
|
|
46
|
-
export type TransactionScalarValue<Value> = Value |
|
|
46
|
+
export type TransactionScalarValue<Value> = Value | AvTransactionReference<Value>;
|
|
47
47
|
/**
|
|
48
48
|
* What a Transaction Slot holds of its destination field, which decides the source
|
|
49
49
|
* fields a reference there accepts — always the same scalar or enum, no coercion:
|
|
@@ -62,16 +62,16 @@ export type TransactionSlotShape = "value" | "nonNullValue" | "entry" | "entries
|
|
|
62
62
|
/**
|
|
63
63
|
* Create data inside a transaction plan, at one write position: its scalar values
|
|
64
64
|
* and the unique keys its relation directives name may hold a `$ref`. The default
|
|
65
|
-
* is the unrestricted position, as on `
|
|
65
|
+
* is the unrestricted position, as on `AvCreateDataInput`.
|
|
66
66
|
*/
|
|
67
|
-
export type TransactionCreateDataInput<C extends
|
|
67
|
+
export type TransactionCreateDataInput<C extends AvContract, K extends AvResourceKey<C>, Scope extends AvWriteScope = "nested"> = AvCreateDataInput<C, K, Scope, ScalarForms, ScalarForms>;
|
|
68
68
|
/** Update data inside a transaction plan. See {@link TransactionCreateDataInput}. */
|
|
69
|
-
export type TransactionUpdateDataInput<C extends
|
|
69
|
+
export type TransactionUpdateDataInput<C extends AvContract, K extends AvResourceKey<C>, Scope extends AvWriteScope = "nested"> = AvUpdateDataInput<C, K, Scope, ScalarForms, ScalarForms>;
|
|
70
70
|
/**
|
|
71
71
|
* Operation arguments inside a transaction plan, under one value form and one
|
|
72
|
-
* reference form: `
|
|
72
|
+
* reference form: `AvOperationArgumentsFor` with its reference positions opened.
|
|
73
73
|
*/
|
|
74
|
-
export type ReferenceableArgumentsFor<C extends
|
|
74
|
+
export type ReferenceableArgumentsFor<C extends AvContract, K extends AvResourceKey<C>, I extends AvOperationIdentity, Forms extends ScalarForms, ReferenceForms extends ScalarForms> = AvOperationArgumentsFor<C, K, I, Forms, ReferenceForms>;
|
|
75
75
|
/** Operation arguments inside a transaction plan, no scalar form stated. */
|
|
76
|
-
export type TransactionOperationArgumentsFor<C extends
|
|
76
|
+
export type TransactionOperationArgumentsFor<C extends AvContract, K extends AvResourceKey<C>, I extends AvOperationIdentity> = ReferenceableArgumentsFor<C, K, I, ScalarForms, ScalarForms>;
|
|
77
77
|
export {};
|
|
@@ -14,6 +14,11 @@ export function routeTransactionReferenceCandidate(value) {
|
|
|
14
14
|
if (!ownKeys.includes("$ref") || referenceDescriptor === undefined) {
|
|
15
15
|
return ORDINARY_ROUTE;
|
|
16
16
|
}
|
|
17
|
+
if ("value" in referenceDescriptor &&
|
|
18
|
+
(referenceDescriptor.value === null ||
|
|
19
|
+
typeof referenceDescriptor.value !== "object")) {
|
|
20
|
+
return ORDINARY_ROUTE;
|
|
21
|
+
}
|
|
17
22
|
return {
|
|
18
23
|
kind: "candidate",
|
|
19
24
|
candidate: value,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { ClientProtocolIdentity } from "../runtime/operation-request.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AvTransportContext } from "../runtime/pipeline.js";
|
|
3
|
+
import type { AvState } from "../runtime/request-state.js";
|
|
3
4
|
type TransactionRequestBase = {
|
|
4
5
|
readonly requestId: string;
|
|
5
6
|
readonly plan: unknown;
|
|
7
|
+
/**
|
|
8
|
+
* The run's `ctx.$state`: every step's stages and the transaction stages share
|
|
9
|
+
* this one object. Omitted, it is a fresh `{}`.
|
|
10
|
+
*/
|
|
11
|
+
readonly state?: AvState;
|
|
6
12
|
};
|
|
7
13
|
/** An in-process transaction request, run under the Application Contract. */
|
|
8
14
|
export type ApplicationTransactionRequest = TransactionRequestBase & {
|
|
@@ -14,13 +20,20 @@ export type ApplicationTransactionRequest = TransactionRequestBase & {
|
|
|
14
20
|
export type ClientTransactionRequest = TransactionRequestBase & {
|
|
15
21
|
readonly origin: "client";
|
|
16
22
|
readonly protocol: ClientProtocolIdentity;
|
|
17
|
-
readonly transport?:
|
|
23
|
+
readonly transport?: AvTransportContext;
|
|
24
|
+
};
|
|
25
|
+
/** An AI agent's transaction request, run under the Agent Contract. */
|
|
26
|
+
export type AgentTransactionRequest = TransactionRequestBase & {
|
|
27
|
+
readonly origin: "agent";
|
|
28
|
+
readonly protocol: ClientProtocolIdentity;
|
|
29
|
+
readonly transport?: AvTransportContext;
|
|
18
30
|
};
|
|
19
31
|
/** One transaction request, as `framework.executeTransaction` takes it. */
|
|
20
|
-
export type FrameworkTransactionRequest = ApplicationTransactionRequest | ClientTransactionRequest;
|
|
32
|
+
export type FrameworkTransactionRequest = ApplicationTransactionRequest | ClientTransactionRequest | AgentTransactionRequest;
|
|
21
33
|
/**
|
|
22
34
|
* The origin one plan operation runs under: its own layer's Contract, its own
|
|
23
|
-
* pipelines, and — for a client step — the protocol identity it is
|
|
35
|
+
* pipelines, and — for a client or agent step — the protocol identity it is
|
|
36
|
+
* accepted with.
|
|
24
37
|
*/
|
|
25
|
-
export type TransactionOperationOrigin = Pick<ApplicationTransactionRequest, "origin"> | Pick<ClientTransactionRequest, "origin" | "protocol" | "transport">;
|
|
38
|
+
export type TransactionOperationOrigin = Pick<ApplicationTransactionRequest, "origin"> | Pick<ClientTransactionRequest, "origin" | "protocol" | "transport"> | Pick<AgentTransactionRequest, "origin" | "protocol" | "transport">;
|
|
26
39
|
export {};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
|
|
2
2
|
/** A committed plan: each operation's final `data`, in plan order. */
|
|
3
|
-
export type
|
|
3
|
+
export type AvTransactionCommittedResponse<T = readonly unknown[]> = {
|
|
4
4
|
readonly data: T;
|
|
5
5
|
readonly code: "A1009";
|
|
6
6
|
readonly cause: null;
|
|
7
7
|
};
|
|
8
8
|
/** What a transaction answers: committed (`A1009`) or a failure. */
|
|
9
|
-
export type
|
|
9
|
+
export type AvTransactionResponse = AvTransactionCommittedResponse | AvOperationFailureResponse;
|
|
10
10
|
/** Builds the committed response. */
|
|
11
|
-
export declare function transactionCommitted(results: readonly unknown[]):
|
|
11
|
+
export declare function transactionCommitted(results: readonly unknown[]): AvTransactionCommittedResponse;
|
|
12
12
|
/**
|
|
13
13
|
* Builds the failure response of a plan step: the step named in
|
|
14
14
|
* `cause.operation`, and each issue at its full plan location —
|
|
15
15
|
* `["operations", operation, "args", …]` for the step's arguments,
|
|
16
16
|
* `["operations", operation, …]` for the step itself.
|
|
17
17
|
*/
|
|
18
|
-
export declare function transactionOperationFailure(failure:
|
|
18
|
+
export declare function transactionOperationFailure(failure: AvOperationFailureResponse, operation: number): AvOperationFailureResponse;
|
|
19
19
|
/** Builds the `A3002` response for a transaction that itself failed. */
|
|
20
|
-
export declare function transactionInfrastructureFailure(operation?: number):
|
|
20
|
+
export declare function transactionInfrastructureFailure(operation?: number): AvOperationFailureResponse;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel } from "../adapters/adapter-model.js";
|
|
2
2
|
import type { TransactionDiagnosticsChannel } from "../runtime/diagnostics-reporter.js";
|
|
3
|
-
import type { OperationRuntimeDependencies } from "../runtime/operation-runtime.js";
|
|
3
|
+
import type { OperationPipelineDependencies, OperationRuntimeDependencies } from "../runtime/operation-runtime.js";
|
|
4
4
|
import type { PlanArguments } from "./transaction-plan-validator.js";
|
|
5
5
|
import type { FrameworkTransactionRequest, TransactionOperationOrigin } from "./transaction-request.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { AvTransactionResponse } from "./transaction-response.js";
|
|
7
7
|
/**
|
|
8
8
|
* The transaction executor core. Like the operation executor it owns no
|
|
9
9
|
* diagnostics channel: the framework factory binds one to the request and
|
|
@@ -13,10 +13,11 @@ import type { TransactionResponse } from "./transaction-response.js";
|
|
|
13
13
|
* runner's mixed plans), and `planArguments` whether the steps' arguments are
|
|
14
14
|
* copied at the door; see `validateTransactionPlan`.
|
|
15
15
|
*/
|
|
16
|
-
export type FrameworkTransactionExecutor = (request: FrameworkTransactionRequest, diagnostics: TransactionDiagnosticsChannel, origins: readonly TransactionOperationOrigin[] | undefined, planArguments: PlanArguments) => Promise<
|
|
16
|
+
export type FrameworkTransactionExecutor = (request: FrameworkTransactionRequest, diagnostics: TransactionDiagnosticsChannel, origins: readonly TransactionOperationOrigin[] | undefined, planArguments: PlanArguments) => Promise<AvTransactionResponse>;
|
|
17
17
|
/**
|
|
18
18
|
* Validates a whole plan through the Framework Validation Layer, then runs it inside
|
|
19
|
-
* exactly one Adapter transaction.
|
|
20
|
-
* operation
|
|
19
|
+
* exactly one Adapter transaction. The touched Resources' transaction stages and
|
|
20
|
+
* every plan operation's guards, pipes, hooks and interceptors run while the
|
|
21
|
+
* provider transaction is open.
|
|
21
22
|
*/
|
|
22
|
-
export declare function createTransactionRuntime<M extends
|
|
23
|
+
export declare function createTransactionRuntime<M extends AvAdapterModel>(dependencies: OperationRuntimeDependencies<M>, pipelineDependencies: OperationPipelineDependencies<M>): FrameworkTransactionExecutor;
|