@usearazzo/runner 1.0.1-alpha.26 → 1.0.1-alpha.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearazzo/runner",
3
- "version": "1.0.1-alpha.26",
3
+ "version": "1.0.1-alpha.28",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -56,25 +56,25 @@
56
56
  "author": "Vladimir Gorej <vladimir.gorej@gmail.com>",
57
57
  "license": "Apache-2.0",
58
58
  "dependencies": {
59
- "@babel/runtime-corejs3": "^8.0.8",
60
- "@speclynx/apidom-core": "^6.1.2",
61
- "@speclynx/apidom-datamodel": "^6.1.2",
62
- "@speclynx/apidom-error": "^6.1.2",
63
- "@speclynx/apidom-json-pointer": "^6.1.2",
64
- "@speclynx/apidom-ns-arazzo-1": "^6.1.2",
65
- "@speclynx/apidom-ns-openapi-2": "^6.1.2",
66
- "@speclynx/apidom-ns-openapi-3-0": "^6.1.2",
67
- "@speclynx/apidom-ns-openapi-3-1": "^6.1.2",
68
- "@speclynx/apidom-reference": "^6.1.2",
69
- "@speclynx/apidom-traverse": "^6.1.2",
59
+ "@babel/runtime-corejs3": "^8.1.0",
60
+ "@speclynx/apidom-core": "^7.0.2",
61
+ "@speclynx/apidom-datamodel": "^7.0.2",
62
+ "@speclynx/apidom-error": "^7.0.2",
63
+ "@speclynx/apidom-json-pointer": "^7.0.2",
64
+ "@speclynx/apidom-ns-arazzo-1": "^7.0.2",
65
+ "@speclynx/apidom-ns-openapi-2": "^7.0.2",
66
+ "@speclynx/apidom-ns-openapi-3-0": "^7.0.2",
67
+ "@speclynx/apidom-ns-openapi-3-1": "^7.0.2",
68
+ "@speclynx/apidom-reference": "^7.0.2",
69
+ "@speclynx/apidom-traverse": "^7.0.2",
70
70
  "@swaggerexpert/arazzo-criterion": "^1.0.1",
71
71
  "@swaggerexpert/arazzo-runtime-expression": "^3.3.0",
72
72
  "@swaggerexpert/cookie": "^2.1.1",
73
73
  "@swaggerexpert/json-pointer": "^3.0.2",
74
74
  "@swaggerexpert/jsonpath": "^4.0.5",
75
75
  "@swaggerexpert/media-types": "^1.0.2",
76
- "@usearazzo/parser": "1.0.1-alpha.26",
77
- "@usearazzo/resolver": "1.0.1-alpha.26",
76
+ "@usearazzo/parser": "1.0.1-alpha.28",
77
+ "@usearazzo/resolver": "1.0.1-alpha.28",
78
78
  "@xmldom/xmldom": "^0.9.12",
79
79
  "fontoxpath": "^3.34.0",
80
80
  "ramda": "^0.32.0",
@@ -92,7 +92,7 @@
92
92
  "CHANGELOG.md"
93
93
  ],
94
94
  "devDependencies": {
95
- "swagger-client": "^3.38.4"
95
+ "swagger-client": "^3.39.0"
96
96
  },
97
- "gitHead": "8bacf6bf0e5d1e4c44a81583c5f1719bbbefaf97"
97
+ "gitHead": "a6908027adcc7a67f773a453431dae704eba60f7"
98
98
  }
@@ -5,19 +5,40 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _ramda = require("ramda");
8
9
  var _DocumentRegistry = _interopRequireDefault(require("./registry/DocumentRegistry.cjs"));
10
+ var _ArazzoDocumentRegistryProvider = _interopRequireDefault(require("./registry/providers/ArazzoDocumentRegistryProvider.cjs"));
11
+ var _OpenAPIDocumentRegistryProvider = _interopRequireDefault(require("./registry/providers/OpenAPIDocumentRegistryProvider.cjs"));
12
+ var _ArazzoWorkflowNormalizer = _interopRequireDefault(require("./normalizer/ArazzoWorkflowNormalizer.cjs"));
13
+ var _OpenAPIOperationNormalizer = _interopRequireDefault(require("./normalizer/OpenAPIOperationNormalizer.cjs"));
14
+ var _OpenAPI2OperationNormalizer = _interopRequireDefault(require("./normalizer/OpenAPI2OperationNormalizer.cjs"));
15
+ var _OpenAPI30OperationNormalizer = _interopRequireDefault(require("./normalizer/OpenAPI30OperationNormalizer.cjs"));
16
+ var _OpenAPI31OperationNormalizer = _interopRequireDefault(require("./normalizer/OpenAPI31OperationNormalizer.cjs"));
9
17
  var _OpenAPIOperationExecutor = _interopRequireDefault(require("./executor/OpenAPIOperationExecutor.cjs"));
10
18
  var _StepExecutor = _interopRequireDefault(require("./executor/StepExecutor.cjs"));
11
19
  var _WorkflowExecutor = _interopRequireDefault(require("./executor/WorkflowExecutor.cjs"));
12
20
  var _InvalidEntryDocumentError = _interopRequireDefault(require("./errors/InvalidEntryDocumentError.cjs"));
21
+ /**
22
+ * The options of ApiDOM reference the runner accepts: its `resolve` options,
23
+ * which mean the same for every building block that retrieves documents.
24
+ * `parse` and `dereference` options differ per building block, so the runner
25
+ * passes none of them on; set those on the building blocks themselves.
26
+ * @public
27
+ */
28
+
13
29
  /**
14
30
  * Options for {@link ArazzoRunner.load}.
15
31
  *
16
32
  * Every option is a seam of a building block the runner wires: `registry` is
17
33
  * the {@link DocumentRegistry} the documents load into (a fresh one with the
18
- * default providers when omitted), `httpClient` and `requestInterceptor` go to
34
+ * default providers when omitted), `reference` goes to everything the runner
35
+ * builds that retrieves documents, `httpClient` and `requestInterceptor` go to
19
36
  * the {@link OpenAPIOperationExecutor}, and the rest go to the
20
37
  * {@link WorkflowExecutor}.
38
+ *
39
+ * Retrieving documents and calling APIs are separate on purpose: `reference`
40
+ * never applies to API calls, and `httpClient` / `requestInterceptor` never
41
+ * apply to document retrieval, so credentials for one do not reach the other.
21
42
  * @public
22
43
  */
23
44
 
@@ -51,8 +72,12 @@ class ArazzoRunner {
51
72
  * document, or the given registry already backs another entry document
52
73
  */
53
74
  static async load(uri, options = {}) {
75
+ // `resolve` only, whatever else the given object carries
76
+ const referenceOptions = (0, _ramda.pick)(['resolve'], options.reference ?? {});
54
77
  const {
55
- registry = new _DocumentRegistry.default(),
78
+ registry = new _DocumentRegistry.default({
79
+ providers: [new _ArazzoDocumentRegistryProvider.default(referenceOptions), new _OpenAPIDocumentRegistryProvider.default(referenceOptions)]
80
+ }),
56
81
  ...rest
57
82
  } = options;
58
83
  // acquiring a second entry would pin it for good and, through the LRU
@@ -81,6 +106,7 @@ class ArazzoRunner {
81
106
  const {
82
107
  document,
83
108
  registry,
109
+ reference,
84
110
  httpClient,
85
111
  requestInterceptor,
86
112
  ...workflowExecutorOptions
@@ -93,9 +119,17 @@ class ArazzoRunner {
93
119
  uri: document.uri
94
120
  });
95
121
  }
122
+
123
+ // `resolve` only, whatever else the given object carries
124
+ const referenceOptions = (0, _ramda.pick)(['resolve'], reference ?? {});
96
125
  const operationExecutor = new _OpenAPIOperationExecutor.default({
97
126
  httpClient,
98
- requestInterceptor
127
+ requestInterceptor,
128
+ operationNormalizer: new _OpenAPIOperationNormalizer.default({
129
+ openapi2: new _OpenAPI2OperationNormalizer.default(referenceOptions),
130
+ openapi30: new _OpenAPI30OperationNormalizer.default(referenceOptions),
131
+ openapi31: new _OpenAPI31OperationNormalizer.default(referenceOptions)
132
+ })
99
133
  });
100
134
  const stepExecutor = new _StepExecutor.default({
101
135
  document,
@@ -108,7 +142,8 @@ class ArazzoRunner {
108
142
  ...workflowExecutorOptions,
109
143
  document,
110
144
  registry,
111
- stepExecutor
145
+ stepExecutor,
146
+ workflowNormalizer: new _ArazzoWorkflowNormalizer.default(referenceOptions)
112
147
  });
113
148
  }
114
149
 
@@ -1,16 +1,36 @@
1
+ import { pick } from 'ramda';
1
2
  import DocumentRegistry from "./registry/DocumentRegistry.mjs";
3
+ import ArazzoDocumentRegistryProvider from "./registry/providers/ArazzoDocumentRegistryProvider.mjs";
4
+ import OpenAPIDocumentRegistryProvider from "./registry/providers/OpenAPIDocumentRegistryProvider.mjs";
5
+ import ArazzoWorkflowNormalizer from "./normalizer/ArazzoWorkflowNormalizer.mjs";
6
+ import OpenAPIOperationNormalizer from "./normalizer/OpenAPIOperationNormalizer.mjs";
7
+ import OpenAPI2OperationNormalizer from "./normalizer/OpenAPI2OperationNormalizer.mjs";
8
+ import OpenAPI30OperationNormalizer from "./normalizer/OpenAPI30OperationNormalizer.mjs";
9
+ import OpenAPI31OperationNormalizer from "./normalizer/OpenAPI31OperationNormalizer.mjs";
2
10
  import OpenAPIOperationExecutor from "./executor/OpenAPIOperationExecutor.mjs";
3
11
  import StepExecutor from "./executor/StepExecutor.mjs";
4
12
  import WorkflowExecutor from "./executor/WorkflowExecutor.mjs";
5
13
  import InvalidEntryDocumentError from "./errors/InvalidEntryDocumentError.mjs";
14
+ /**
15
+ * The options of ApiDOM reference the runner accepts: its `resolve` options,
16
+ * which mean the same for every building block that retrieves documents.
17
+ * `parse` and `dereference` options differ per building block, so the runner
18
+ * passes none of them on; set those on the building blocks themselves.
19
+ * @public
20
+ */
6
21
  /**
7
22
  * Options for {@link ArazzoRunner.load}.
8
23
  *
9
24
  * Every option is a seam of a building block the runner wires: `registry` is
10
25
  * the {@link DocumentRegistry} the documents load into (a fresh one with the
11
- * default providers when omitted), `httpClient` and `requestInterceptor` go to
26
+ * default providers when omitted), `reference` goes to everything the runner
27
+ * builds that retrieves documents, `httpClient` and `requestInterceptor` go to
12
28
  * the {@link OpenAPIOperationExecutor}, and the rest go to the
13
29
  * {@link WorkflowExecutor}.
30
+ *
31
+ * Retrieving documents and calling APIs are separate on purpose: `reference`
32
+ * never applies to API calls, and `httpClient` / `requestInterceptor` never
33
+ * apply to document retrieval, so credentials for one do not reach the other.
14
34
  * @public
15
35
  */
16
36
  /**
@@ -42,8 +62,12 @@ class ArazzoRunner {
42
62
  * document, or the given registry already backs another entry document
43
63
  */
44
64
  static async load(uri, options = {}) {
65
+ // `resolve` only, whatever else the given object carries
66
+ const referenceOptions = pick(['resolve'], options.reference ?? {});
45
67
  const {
46
- registry = new DocumentRegistry(),
68
+ registry = new DocumentRegistry({
69
+ providers: [new ArazzoDocumentRegistryProvider(referenceOptions), new OpenAPIDocumentRegistryProvider(referenceOptions)]
70
+ }),
47
71
  ...rest
48
72
  } = options;
49
73
  // acquiring a second entry would pin it for good and, through the LRU
@@ -72,6 +96,7 @@ class ArazzoRunner {
72
96
  const {
73
97
  document,
74
98
  registry,
99
+ reference,
75
100
  httpClient,
76
101
  requestInterceptor,
77
102
  ...workflowExecutorOptions
@@ -84,9 +109,17 @@ class ArazzoRunner {
84
109
  uri: document.uri
85
110
  });
86
111
  }
112
+
113
+ // `resolve` only, whatever else the given object carries
114
+ const referenceOptions = pick(['resolve'], reference ?? {});
87
115
  const operationExecutor = new OpenAPIOperationExecutor({
88
116
  httpClient,
89
- requestInterceptor
117
+ requestInterceptor,
118
+ operationNormalizer: new OpenAPIOperationNormalizer({
119
+ openapi2: new OpenAPI2OperationNormalizer(referenceOptions),
120
+ openapi30: new OpenAPI30OperationNormalizer(referenceOptions),
121
+ openapi31: new OpenAPI31OperationNormalizer(referenceOptions)
122
+ })
90
123
  });
91
124
  const stepExecutor = new StepExecutor({
92
125
  document,
@@ -99,7 +132,8 @@ class ArazzoRunner {
99
132
  ...workflowExecutorOptions,
100
133
  document,
101
134
  registry,
102
- stepExecutor
135
+ stepExecutor,
136
+ workflowNormalizer: new ArazzoWorkflowNormalizer(referenceOptions)
103
137
  });
104
138
  }
105
139
 
@@ -167,7 +167,7 @@ class CriterionEvaluator {
167
167
  #resolveType(criterion) {
168
168
  const type = criterion.type;
169
169
  if (type === undefined) return 'simple';
170
- if ((0, _apidomNsArazzo.isCriterionExpressionTypeElement)(type) && (0, _apidomDatamodel.isStringElement)(type.type)) {
170
+ if ((0, _apidomNsArazzo.isExpressionTypeElement)(type) && (0, _apidomDatamodel.isStringElement)(type.type)) {
171
171
  return (0, _apidomCore.toValue)(type.type);
172
172
  }
173
173
  if ((0, _apidomDatamodel.isStringElement)(type)) return (0, _apidomCore.toValue)(type);
@@ -185,7 +185,7 @@ class CriterionEvaluator {
185
185
  */
186
186
  #resolveVersion(criterion) {
187
187
  const type = criterion.type;
188
- if (!(0, _apidomNsArazzo.isCriterionExpressionTypeElement)(type) || type.version === undefined) {
188
+ if (!(0, _apidomNsArazzo.isExpressionTypeElement)(type) || type.version === undefined) {
189
189
  return undefined;
190
190
  }
191
191
  if ((0, _apidomDatamodel.isStringElement)(type.version)) {
@@ -1,6 +1,6 @@
1
1
  import { toValue } from '@speclynx/apidom-core';
2
2
  import { isStringElement } from '@speclynx/apidom-datamodel';
3
- import { isCriterionElement, isCriterionExpressionTypeElement } from '@speclynx/apidom-ns-arazzo-1';
3
+ import { isCriterionElement, isExpressionTypeElement } from '@speclynx/apidom-ns-arazzo-1';
4
4
  import { test as isRuntimeExpression } from '@swaggerexpert/arazzo-runtime-expression';
5
5
  import CriterionError from "../errors/CriterionError.mjs";
6
6
  import CriterionEvaluationError from "../errors/CriterionEvaluationError.mjs";
@@ -157,7 +157,7 @@ class CriterionEvaluator {
157
157
  #resolveType(criterion) {
158
158
  const type = criterion.type;
159
159
  if (type === undefined) return 'simple';
160
- if (isCriterionExpressionTypeElement(type) && isStringElement(type.type)) {
160
+ if (isExpressionTypeElement(type) && isStringElement(type.type)) {
161
161
  return toValue(type.type);
162
162
  }
163
163
  if (isStringElement(type)) return toValue(type);
@@ -175,7 +175,7 @@ class CriterionEvaluator {
175
175
  */
176
176
  #resolveVersion(criterion) {
177
177
  const type = criterion.type;
178
- if (!isCriterionExpressionTypeElement(type) || type.version === undefined) {
178
+ if (!isExpressionTypeElement(type) || type.version === undefined) {
179
179
  return undefined;
180
180
  }
181
181
  if (isStringElement(type.version)) {
@@ -15,6 +15,13 @@ var _ArazzoRunnerError = _interopRequireDefault(require("./ArazzoRunnerError.cjs
15
15
  * @public
16
16
  */
17
17
  class ResolverError extends _ArazzoRunnerError.default {
18
+ /**
19
+ * A parameter of a Success / Failure Action declares an `in` inline, which
20
+ * the Arazzo Specification forbids; one inherited from a
21
+ * `$components.parameters` Reusable Object maps by name instead. Thrown
22
+ * before the workflow's first request.
23
+ */
24
+ static ActionParameterLocation = 'action-parameter-location';
18
25
  /** A parameter cannot be delivered unambiguously at its location. */
19
26
  static AmbiguousDelivery = 'ambiguous-delivery';
20
27
  /** An output or a request body payload holds a value that is not a valid runtime expression. */
@@ -8,6 +8,13 @@ import ArazzoRunnerError from "./ArazzoRunnerError.mjs";
8
8
  * @public
9
9
  */
10
10
  class ResolverError extends ArazzoRunnerError {
11
+ /**
12
+ * A parameter of a Success / Failure Action declares an `in` inline, which
13
+ * the Arazzo Specification forbids; one inherited from a
14
+ * `$components.parameters` Reusable Object maps by name instead. Thrown
15
+ * before the workflow's first request.
16
+ */
17
+ static ActionParameterLocation = 'action-parameter-location';
11
18
  /** A parameter cannot be delivered unambiguously at its location. */
12
19
  static AmbiguousDelivery = 'ambiguous-delivery';
13
20
  /** An output or a request body payload holds a value that is not a valid runtime expression. */
@@ -224,7 +224,8 @@ class StepExecutor {
224
224
  action: matchedActions[0],
225
225
  matchedActions,
226
226
  successCriteria,
227
- actionCriteria
227
+ actionCriteria,
228
+ actionContext: this.actionContext(postContext, stepId, outputs)
228
229
  };
229
230
  }
230
231
 
@@ -366,6 +367,28 @@ class StepExecutor {
366
367
  };
367
368
  }
368
369
 
370
+ /**
371
+ * The context a step's actions are taken in — see
372
+ * {@link StepExecutionResult.actionContext}: `context` with
373
+ * `$steps.{stepId}.outputs` replaced by the outputs the attempt just
374
+ * resolved, as a fresh object, so run state is never written.
375
+ *
376
+ * Public for the same reason as {@link StepExecutor.selectActions}: the
377
+ * workflow executor builds this context for a step targeting a
378
+ * `workflowId`, which never reaches {@link StepExecutor.execute}.
379
+ */
380
+ actionContext(context, stepId, outputs) {
381
+ return {
382
+ ...context,
383
+ steps: {
384
+ ...context.steps,
385
+ [stepId]: {
386
+ outputs
387
+ }
388
+ }
389
+ };
390
+ }
391
+
369
392
  /**
370
393
  * Evaluates one criterion into a {@link CriterionEvaluationRecord}. A
371
394
  * condition that cannot be evaluated is unmet and records why; any other
@@ -217,7 +217,8 @@ class StepExecutor {
217
217
  action: matchedActions[0],
218
218
  matchedActions,
219
219
  successCriteria,
220
- actionCriteria
220
+ actionCriteria,
221
+ actionContext: this.actionContext(postContext, stepId, outputs)
221
222
  };
222
223
  }
223
224
 
@@ -359,6 +360,28 @@ class StepExecutor {
359
360
  };
360
361
  }
361
362
 
363
+ /**
364
+ * The context a step's actions are taken in — see
365
+ * {@link StepExecutionResult.actionContext}: `context` with
366
+ * `$steps.{stepId}.outputs` replaced by the outputs the attempt just
367
+ * resolved, as a fresh object, so run state is never written.
368
+ *
369
+ * Public for the same reason as {@link StepExecutor.selectActions}: the
370
+ * workflow executor builds this context for a step targeting a
371
+ * `workflowId`, which never reaches {@link StepExecutor.execute}.
372
+ */
373
+ actionContext(context, stepId, outputs) {
374
+ return {
375
+ ...context,
376
+ steps: {
377
+ ...context.steps,
378
+ [stepId]: {
379
+ outputs
380
+ }
381
+ }
382
+ };
383
+ }
384
+
362
385
  /**
363
386
  * Evaluates one criterion into a {@link CriterionEvaluationRecord}. A
364
387
  * condition that cannot be evaluated is unmet and records why; any other
@@ -149,7 +149,7 @@ class StepRetryRunner {
149
149
  // zero/negative/NaN value.
150
150
  const delayMs = this.#retryAfterMs(action);
151
151
  if (delayMs > 0) await this.#sleep(delayMs, context.signal);
152
- if (runReference !== undefined) await runReference(action);
152
+ if (runReference !== undefined) await runReference(action, outcome);
153
153
  fired = true;
154
154
  break;
155
155
  }
@@ -139,7 +139,7 @@ class StepRetryRunner {
139
139
  // zero/negative/NaN value.
140
140
  const delayMs = this.#retryAfterMs(action);
141
141
  if (delayMs > 0) await this.#sleep(delayMs, context.signal);
142
- if (runReference !== undefined) await runReference(action);
142
+ if (runReference !== undefined) await runReference(action, outcome);
143
143
  fired = true;
144
144
  break;
145
145
  }
@@ -163,7 +163,7 @@ class WorkflowExecutor {
163
163
  #maxWorkflowDepth;
164
164
  #now;
165
165
  #extractor = new _ArazzoWorkflowExtractor.default();
166
- #normalizer = new _ArazzoWorkflowNormalizer.default();
166
+ #normalizer;
167
167
  #outputResolver = new _OutputResolver.default();
168
168
  #parameterResolver = new _WorkflowParameterResolver.default();
169
169
  #stepExecutor;
@@ -174,6 +174,7 @@ class WorkflowExecutor {
174
174
  this.#document = options.document;
175
175
  this.#registry = options.registry;
176
176
  this.#workflowLocatorNormalizer = new _ArazzoWorkflowLocatorNormalizer.default(options.registry);
177
+ this.#normalizer = options.workflowNormalizer ?? new _ArazzoWorkflowNormalizer.default();
177
178
  this.#maxSteps = options.maxSteps ?? WorkflowExecutor.#DEFAULT_MAX_STEPS;
178
179
  this.#maxWorkflowDepth = options.maxWorkflowDepth ?? WorkflowExecutor.#DEFAULT_MAX_WORKFLOW_DEPTH;
179
180
  this.#now = options.now ?? WorkflowExecutor.#DEFAULT_NOW;
@@ -301,6 +302,16 @@ class WorkflowExecutor {
301
302
  // included: an unreadable assertion found at step three must not cost the
302
303
  // run the requests of steps one and two.
303
304
  for (const step of steps) this.#stepExecutor.assertSuccessCriteria(step, workflowId);
305
+ // and to every action's `parameters`, for the same reason: an `in` the
306
+ // specification forbids must not cost the run the requests before the
307
+ // step whose action carries it.
308
+ // the workflow's own default actions too: one every step overrides by
309
+ // name never reaches a step's list, yet the validator still reports it.
310
+ this.#assertActionParameters([workflow.successActions, workflow.failureActions], workflowId);
311
+ for (const step of steps) {
312
+ const stepId = (0, _apidomCore.toValue)(step.stepId);
313
+ this.#assertActionParameters([step.onSuccess, step.onFailure], workflowId, stepId);
314
+ }
304
315
  const dependencies = await this.#runDependencies(workflow, invocation, scope);
305
316
  if (dependencies.some(dependency => this.#settledFailed(dependency))) {
306
317
  // a declared prerequisite did not complete, so this workflow cannot be
@@ -396,7 +407,7 @@ class WorkflowExecutor {
396
407
  stepId,
397
408
  callStack: nested
398
409
  });
399
- const transferredTo = await this.#runReferencedWorkflow(transition.workflowId, stepId, invocation, scope, 'goto');
410
+ const transferredTo = await this.#runReferencedWorkflow(transition.workflowId, stepId, invocation, scope, 'goto', this.#actionInputs(action?.parameters, outcome, invocation, stepId));
400
411
  runOutcome = {
401
412
  kind: 'transferred',
402
413
  transferredTo
@@ -572,16 +583,16 @@ class WorkflowExecutor {
572
583
  * for entering the reference itself, matching the "1 for the step itself
573
584
  * plus whatever its sub-run spends" convention a sub-workflow step
574
585
  * already follows (without it, a reference to a workflow with few or no
575
- * steps of its own would cost nothing to fire). It runs with no inputs:
576
- * the specification gives a retry reference no input-mapping mechanism
577
- * of its own (the same gap `dependsOn` has), and `{}` is the only
578
- * spec-honest fallback — see issue `#62`. Its outputs are recorded via
579
- * `state.setWorkflow`, which *is* "context transfers back" — but its
580
- * `inputs` are preserved rather than overwritten with `{}` when this
581
- * workflowId was already recorded (by an earlier `dependsOn` prerequisite
582
- * or sub-workflow step sharing the id): this call's own lack of a real
583
- * inputs value must not erase one a different, better-informed caller
584
- * already gave.
586
+ * steps of its own would cost nothing to fire). Its inputs are the
587
+ * action's `parameters` (`#115`), resolved again on every firing
588
+ * against the attempt that fired it — `{}` without them. Its outputs are
589
+ * recorded via `state.setWorkflow`, which *is* "context transfers back",
590
+ * together with the inputs it ran with when the action carries
591
+ * `parameters`. Without them, the recorded `inputs` are preserved rather
592
+ * than overwritten with `{}` when this workflowId was already recorded
593
+ * (by an earlier `dependsOn` prerequisite or sub-workflow step sharing
594
+ * the id): this call's own lack of a real inputs value must not erase one
595
+ * a different, better-informed caller already gave.
585
596
  * - a `stepId` reference must name a step of the current workflow (checked
586
597
  * lazily, at fire time, via the same lookup a `goto` target uses) and
587
598
  * runs as one more attempt at that step, through
@@ -604,7 +615,7 @@ class WorkflowExecutor {
604
615
  state,
605
616
  callStack
606
617
  } = invocation;
607
- return async action => {
618
+ return async (action, outcome) => {
608
619
  (0, _abort.throwIfAborted)(scope.signal, {
609
620
  workflowId,
610
621
  stepId,
@@ -623,13 +634,16 @@ class WorkflowExecutor {
623
634
  }
624
635
  if (hasWorkflowId) {
625
636
  const reference = (0, _apidomCore.toValue)(action.workflowId);
637
+ // resolved before the budget is charged, so an authoring error in them
638
+ // costs no budget unit.
639
+ const inputs = this.#actionInputs(action.parameters, outcome, invocation, stepId);
626
640
  this.#chargeBudget(scope, invocation, stepId);
627
- const result = await this.#runReferencedWorkflow(reference, stepId, invocation, scope, 'retry');
641
+ const result = await this.#runReferencedWorkflow(reference, stepId, invocation, scope, 'retry', inputs);
628
642
  // the result's workflowId is the bare id the reference resolved to —
629
643
  // the key run state is recorded under, whichever document owns it.
630
644
  const refId = result.workflowId;
631
645
  state.setWorkflow(refId, {
632
- inputs: state.getWorkflow(refId)?.inputs ?? {},
646
+ inputs: action.hasKey('parameters') ? inputs : state.getWorkflow(refId)?.inputs ?? {},
633
647
  outputs: result.outputs
634
648
  });
635
649
  retryReferences.push({
@@ -647,12 +661,12 @@ class WorkflowExecutor {
647
661
  });
648
662
  const refStep = steps[refIndex];
649
663
  const refSubWorkflows = [];
650
- const outcome = await this.#chargedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), invocation, scope, refStepId)();
651
- state.setStepOutputs(outcome.stepId, outcome.outputs);
664
+ const refOutcome = await this.#chargedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), invocation, scope, refStepId)();
665
+ state.setStepOutputs(refOutcome.stepId, refOutcome.outputs);
652
666
  retryReferences.push({
653
667
  kind: 'step',
654
668
  id: refStepId,
655
- successful: outcome.successful,
669
+ successful: refOutcome.successful,
656
670
  ...(refSubWorkflows.length > 0 ? {
657
671
  subWorkflow: refSubWorkflows[0]
658
672
  } : {})
@@ -905,7 +919,8 @@ class WorkflowExecutor {
905
919
  action: matchedActions[0],
906
920
  matchedActions,
907
921
  successCriteria,
908
- actionCriteria
922
+ actionCriteria,
923
+ actionContext: stepExecutor.actionContext(context, stepId, outputs)
909
924
  };
910
925
  };
911
926
  }
@@ -962,20 +977,95 @@ class WorkflowExecutor {
962
977
  /**
963
978
  * Runs a workflow an action references directly — a retry's `workflowId`
964
979
  * reference or a goto's transfer, plain id or cross-document expression —
965
- * with `{}` inputs, since neither has an input-mapping mechanism of its own
966
- * (issue `#62`).
980
+ * with the inputs its action's `parameters` resolved to (`#115`), `{}`
981
+ * without them.
967
982
  *
968
983
  * Shared rather than duplicated by its two callers, which otherwise repeat
969
- * the identical "resolve the reference, then run with no inputs" sequence.
984
+ * the identical "resolve the reference, then run it" sequence.
970
985
  * A target its document does not define is rejected by the normalizer,
971
986
  * attributed to the calling workflow and `stepId`.
972
987
  */
973
- async #runReferencedWorkflow(reference, stepId, invocation, scope, via) {
988
+ async #runReferencedWorkflow(reference, stepId, invocation, scope, via, inputs) {
974
989
  const locator = await this.#workflowLocatorNormalizer.normalize(reference, invocation.document, {
975
990
  workflowId: invocation.workflowId,
976
991
  stepId
977
992
  });
978
- return this.#run(locator, {}, scope, invocation.callStack, via);
993
+ return this.#run(locator, inputs, scope, invocation.callStack, via);
994
+ }
995
+
996
+ /**
997
+ * The inputs a `goto` / `retry` action naming a `workflowId` passes its
998
+ * target: the action's own `parameters`, mapped by name and resolved against
999
+ * the context of the attempt that fired it — `$statusCode`, `$response.*`
1000
+ * and the rest of that step outcome, plus the outputs it just produced.
1001
+ * Resolved against the calling invocation's document, so its `$components`
1002
+ * apply, never the target's. No `parameters` gives `{}`. Their shape was
1003
+ * checked before the workflow's first request, by
1004
+ * {@link WorkflowExecutor.#assertActionParameters}.
1005
+ */
1006
+ #actionInputs(parameters, outcome, invocation, stepId) {
1007
+ const {
1008
+ workflowId,
1009
+ document
1010
+ } = invocation;
1011
+ return this.#parameterResolver.resolve(parameters, expression => this.#evaluate(outcome.actionContext, expression, document), {
1012
+ workflowId,
1013
+ stepId
1014
+ });
1015
+ }
1016
+
1017
+ /**
1018
+ * Throws {@link ResolverError} unless every action in `lists` — a step's
1019
+ * `onSuccess` / `onFailure`, or the workflow's own `successActions` /
1020
+ * `failureActions` — has an absent `parameters` or a list free of inline `in`:
1021
+ * `malformed-parameters` for one that is present but not a list,
1022
+ * `action-parameter-location` for a Parameter Object that declares `in`. The
1023
+ * specification says outright that "The `in` field MUST NOT be used" on
1024
+ * them. An `in` arriving through a `$components.parameters` Reusable Object
1025
+ * is not inline — a shared component carries `in` for the operation steps
1026
+ * that use it — and the dereferencer marks the transcluded copy with
1027
+ * `ref-fields`.
1028
+ *
1029
+ * Checked for every action, `workflowId` or not, before any step of the
1030
+ * workflow runs: both are authoring errors the validator reports, so a run
1031
+ * must not make requests on the way to discovering them. Valid `parameters`
1032
+ * on an action naming no `workflowId` are still ignored, as the validator
1033
+ * only warns about them. A list that is not an array is skipped here and left
1034
+ * for the code that reads it to report. `stepId` is absent for the
1035
+ * workflow's own lists, and the error then names the workflow alone.
1036
+ */
1037
+ #assertActionParameters(lists, workflowId, stepId) {
1038
+ const owner = stepId === undefined ? `workflow "${workflowId}"` : `step "${stepId}" in workflow "${workflowId}"`;
1039
+ for (const actions of lists) {
1040
+ if (!(0, _apidomDatamodel.isArrayElement)(actions)) continue;
1041
+ for (const action of actions) {
1042
+ if (!(0, _apidomNsArazzo.isSuccessActionElement)(action) && !(0, _apidomNsArazzo.isFailureActionElement)(action)) continue;
1043
+ if (!action.hasKey('parameters')) continue;
1044
+ const scope = {
1045
+ workflowId,
1046
+ ...(stepId === undefined ? {} : {
1047
+ stepId
1048
+ }),
1049
+ target: 'parameters'
1050
+ };
1051
+ const {
1052
+ parameters
1053
+ } = action;
1054
+ if (!(0, _apidomDatamodel.isArrayElement)(parameters)) {
1055
+ throw new _ResolverError.default('`parameters` is present but is not a list', {
1056
+ ...scope,
1057
+ reason: _ResolverError.default.MalformedParameters
1058
+ });
1059
+ }
1060
+ const inline = [...parameters].some(parameter => (0, _apidomNsArazzo.isParameterElement)(parameter) && parameter.hasKey('in') && !parameter.meta.hasKey('ref-fields'));
1061
+ if (inline) {
1062
+ throw new _ResolverError.default(`An action parameter of ${owner} declares an \`in\`; action parameters map to the target workflow's inputs by name`, {
1063
+ ...scope,
1064
+ reason: _ResolverError.default.ActionParameterLocation
1065
+ });
1066
+ }
1067
+ }
1068
+ }
979
1069
  }
980
1070
 
981
1071
  /**