@usearazzo/runner 1.0.1-alpha.27 → 1.0.1-alpha.29

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.27",
3
+ "version": "1.0.1-alpha.29",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -57,24 +57,24 @@
57
57
  "license": "Apache-2.0",
58
58
  "dependencies": {
59
59
  "@babel/runtime-corejs3": "^8.1.0",
60
- "@speclynx/apidom-core": "^7.0.1",
61
- "@speclynx/apidom-datamodel": "^7.0.1",
62
- "@speclynx/apidom-error": "^7.0.1",
63
- "@speclynx/apidom-json-pointer": "^7.0.1",
64
- "@speclynx/apidom-ns-arazzo-1": "^7.0.1",
65
- "@speclynx/apidom-ns-openapi-2": "^7.0.1",
66
- "@speclynx/apidom-ns-openapi-3-0": "^7.0.1",
67
- "@speclynx/apidom-ns-openapi-3-1": "^7.0.1",
68
- "@speclynx/apidom-reference": "^7.0.1",
69
- "@speclynx/apidom-traverse": "^7.0.1",
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.27",
77
- "@usearazzo/resolver": "1.0.1-alpha.27",
76
+ "@usearazzo/parser": "1.0.1-alpha.29",
77
+ "@usearazzo/resolver": "1.0.1-alpha.29",
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": "c2017ebba31c3a95f6f6dd0ba75058f0a19a8d0d"
97
+ "gitHead": "113b0d571325f56bb364e7fc9a492e7e6d08dfee"
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
 
@@ -17,6 +17,8 @@ var _ArazzoRunnerError = _interopRequireDefault(require("./ArazzoRunnerError.cjs
17
17
  class ExecutionError extends _ArazzoRunnerError.default {
18
18
  /** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
19
19
  static Aborted = 'aborted';
20
+ /** Two `executeOptions` entries name source descriptions that point at the same document. */
21
+ static AmbiguousExecuteOptions = 'ambiguous-execute-options';
20
22
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
21
23
  static AmbiguousTarget = 'ambiguous-target';
22
24
  /** The `dependsOn` edges alone form a cycle between workflows. */
@@ -51,7 +53,7 @@ class ExecutionError extends _ArazzoRunnerError.default {
51
53
  static StepBudget = 'step-budget';
52
54
  /** An action declares a `type` other than `end`, `goto` or `retry`. */
53
55
  static UnknownActionType = 'unknown-action-type';
54
- /** `execute` received an option it does not know. */
56
+ /** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
55
57
  static UnknownExecuteOption = 'unknown-execute-option';
56
58
  /** A step produced a transition the workflow executor does not recognize. */
57
59
  static UnknownTransitionKind = 'unknown-transition-kind';
@@ -10,6 +10,8 @@ import ArazzoRunnerError from "./ArazzoRunnerError.mjs";
10
10
  class ExecutionError extends ArazzoRunnerError {
11
11
  /** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
12
12
  static Aborted = 'aborted';
13
+ /** Two `executeOptions` entries name source descriptions that point at the same document. */
14
+ static AmbiguousExecuteOptions = 'ambiguous-execute-options';
13
15
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
14
16
  static AmbiguousTarget = 'ambiguous-target';
15
17
  /** The `dependsOn` edges alone form a cycle between workflows. */
@@ -44,7 +46,7 @@ class ExecutionError extends ArazzoRunnerError {
44
46
  static StepBudget = 'step-budget';
45
47
  /** An action declares a `type` other than `end`, `goto` or `retry`. */
46
48
  static UnknownActionType = 'unknown-action-type';
47
- /** `execute` received an option it does not know. */
49
+ /** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
48
50
  static UnknownExecuteOption = 'unknown-execute-option';
49
51
  /** A step produced a transition the workflow executor does not recognize. */
50
52
  static UnknownTransitionKind = 'unknown-transition-kind';
@@ -46,6 +46,22 @@ const UNDECLARED_LOCATIONS = new Set(['header', 'query', 'cookie', 'path']);
46
46
  // the header parameters OpenAPI 3 says SHALL be ignored, which buildRequest drops
47
47
  const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
48
48
 
49
+ /**
50
+ * The credential for one security scheme, in the form the vendored
51
+ * swagger-client applies it: the key or token itself (or `{ value }`) for an
52
+ * `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
53
+ * basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
54
+ * or `openIdConnect` scheme.
55
+ * @public
56
+ */
57
+
58
+ /**
59
+ * Credentials for the security schemes of an OpenAPI document, keyed by the
60
+ * scheme name under `components.securitySchemes` (`securityDefinitions` in
61
+ * OpenAPI 2.0).
62
+ * @public
63
+ */
64
+
49
65
  /**
50
66
  * Options for executing an OpenAPI operation.
51
67
  *
@@ -55,11 +71,14 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
55
71
  * building the request and sending it.
56
72
  *
57
73
  * Typed here are the options the runner itself drives and the ones callers
58
- * routinely reach for. The rest of `buildRequest`'s surface (`securities`,
59
- * `scheme`, `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is
60
- * deliberately left untyped and passes through the bag's open tail unchanged —
61
- * see {@link OpenAPIOperationExecuteOptionsBag}. Authentication in particular
62
- * is not modeled: Arazzo is auth-agnostic, so credentials are applied with a
74
+ * routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
75
+ * `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
76
+ * left untyped and passes through the bag's open tail unchanged — see
77
+ * {@link OpenAPIOperationExecuteOptionsBag}.
78
+ *
79
+ * Arazzo is auth-agnostic, so credentials come from outside the workflow:
80
+ * static ones for the security schemes the OpenAPI document declares go in
81
+ * `securities`, and anything computed per request is applied with a
63
82
  * {@link RequestInterceptor}.
64
83
  * @public
65
84
  */
@@ -72,11 +91,9 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
72
91
  * the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
73
92
  * `attachContentTypeForEmptyPayload`, …) passes through untouched.
74
93
  *
75
- * Nothing routine belongs in the tail. Credentials go through a
76
- * {@link RequestInterceptor} and `server` covers every case that once needed a
77
- * `contextUrl`, so reaching for either of those here means an edge case: tests
78
- * standing in for a document fetched over HTTP, or credentials applied from the
79
- * document's own security schemes.
94
+ * Nothing routine belongs in the tail. `server` covers every case that once
95
+ * needed a `contextUrl`, so reaching for that here means an edge case: tests
96
+ * standing in for a document fetched over HTTP.
80
97
  *
81
98
  * Two kinds of entry are inert rather than honored, since the executor owns
82
99
  * what they used to control. The operation target always comes from the
@@ -36,6 +36,22 @@ const UNDECLARED_LOCATIONS = new Set(['header', 'query', 'cookie', 'path']);
36
36
  // the header parameters OpenAPI 3 says SHALL be ignored, which buildRequest drops
37
37
  const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
38
38
 
39
+ /**
40
+ * The credential for one security scheme, in the form the vendored
41
+ * swagger-client applies it: the key or token itself (or `{ value }`) for an
42
+ * `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
43
+ * basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
44
+ * or `openIdConnect` scheme.
45
+ * @public
46
+ */
47
+
48
+ /**
49
+ * Credentials for the security schemes of an OpenAPI document, keyed by the
50
+ * scheme name under `components.securitySchemes` (`securityDefinitions` in
51
+ * OpenAPI 2.0).
52
+ * @public
53
+ */
54
+
39
55
  /**
40
56
  * Options for executing an OpenAPI operation.
41
57
  *
@@ -45,11 +61,14 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
45
61
  * building the request and sending it.
46
62
  *
47
63
  * Typed here are the options the runner itself drives and the ones callers
48
- * routinely reach for. The rest of `buildRequest`'s surface (`securities`,
49
- * `scheme`, `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is
50
- * deliberately left untyped and passes through the bag's open tail unchanged —
51
- * see {@link OpenAPIOperationExecuteOptionsBag}. Authentication in particular
52
- * is not modeled: Arazzo is auth-agnostic, so credentials are applied with a
64
+ * routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
65
+ * `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
66
+ * left untyped and passes through the bag's open tail unchanged — see
67
+ * {@link OpenAPIOperationExecuteOptionsBag}.
68
+ *
69
+ * Arazzo is auth-agnostic, so credentials come from outside the workflow:
70
+ * static ones for the security schemes the OpenAPI document declares go in
71
+ * `securities`, and anything computed per request is applied with a
53
72
  * {@link RequestInterceptor}.
54
73
  * @public
55
74
  */
@@ -62,11 +81,9 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
62
81
  * the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
63
82
  * `attachContentTypeForEmptyPayload`, …) passes through untouched.
64
83
  *
65
- * Nothing routine belongs in the tail. Credentials go through a
66
- * {@link RequestInterceptor} and `server` covers every case that once needed a
67
- * `contextUrl`, so reaching for either of those here means an edge case: tests
68
- * standing in for a document fetched over HTTP, or credentials applied from the
69
- * document's own security schemes.
84
+ * Nothing routine belongs in the tail. `server` covers every case that once
85
+ * needed a `contextUrl`, so reaching for that here means an edge case: tests
86
+ * standing in for a document fetched over HTTP.
70
87
  *
71
88
  * Two kinds of entry are inert rather than honored, since the executor owns
72
89
  * what they used to control. The operation target always comes from the
@@ -65,6 +65,13 @@ const STEP_TARGET_FIELDS = exports.STEP_TARGET_FIELDS = ['operationId', 'operati
65
65
  * @internal
66
66
  */
67
67
 
68
+ /**
69
+ * The execute options of a step: the opaque bag forwarded to the operation
70
+ * executor, or a function returning it for the operation the step was located
71
+ * to.
72
+ * @public
73
+ */
74
+
68
75
  /**
69
76
  * Executes a single Arazzo step that invokes an OpenAPI operation.
70
77
  *
@@ -127,7 +134,9 @@ class StepExecutor {
127
134
  * `executeOptions` is an opaque bag passed through to the operation executor
128
135
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
129
136
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
130
- * take precedence over it.
137
+ * take precedence over it. A function is called with the operation the step
138
+ * was located to and returns the bag, for options that depend on which API
139
+ * the step calls.
131
140
  *
132
141
  * A `signal` in that bag is honored here and not only at the transport: an
133
142
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -169,6 +178,7 @@ class StepExecutor {
169
178
  // Pointer) locator that the operation executor extracts, normalizes,
170
179
  // assembles into a standalone doc, and runs.
171
180
  const locator = await this.#locateOperation(step, scope);
181
+ const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
172
182
 
173
183
  // resolve parameters and request body against the pre-request context.
174
184
  // keyed by '{in}.{name}' rather than bare name, so two parameters that
@@ -182,7 +192,7 @@ class StepExecutor {
182
192
  // still reach this line — and this is the last moment before the step has a
183
193
  // live side effect. The signal stays in the bag, so a request already in
184
194
  // flight is aborted by the transport as before.
185
- const signal = (0, _abort.readAbortSignal)(executeOptions);
195
+ const signal = (0, _abort.readAbortSignal)(operationOptions);
186
196
  (0, _abort.throwIfAborted)(signal, scope);
187
197
 
188
198
  // the Arazzo-derived parameters and request body are spread after the opaque
@@ -191,7 +201,7 @@ class StepExecutor {
191
201
  let response;
192
202
  try {
193
203
  response = await this.#operationExecutor.execute(locator, {
194
- ...executeOptions,
204
+ ...operationOptions,
195
205
  parameters,
196
206
  ...this.#requestBodyOptions(requestBody)
197
207
  });
@@ -58,6 +58,13 @@ export const STEP_TARGET_FIELDS = ['operationId', 'operationPath', 'workflowId']
58
58
  * @internal
59
59
  */
60
60
 
61
+ /**
62
+ * The execute options of a step: the opaque bag forwarded to the operation
63
+ * executor, or a function returning it for the operation the step was located
64
+ * to.
65
+ * @public
66
+ */
67
+
61
68
  /**
62
69
  * Executes a single Arazzo step that invokes an OpenAPI operation.
63
70
  *
@@ -120,7 +127,9 @@ class StepExecutor {
120
127
  * `executeOptions` is an opaque bag passed through to the operation executor
121
128
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
122
129
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
123
- * take precedence over it.
130
+ * take precedence over it. A function is called with the operation the step
131
+ * was located to and returns the bag, for options that depend on which API
132
+ * the step calls.
124
133
  *
125
134
  * A `signal` in that bag is honored here and not only at the transport: an
126
135
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -162,6 +171,7 @@ class StepExecutor {
162
171
  // Pointer) locator that the operation executor extracts, normalizes,
163
172
  // assembles into a standalone doc, and runs.
164
173
  const locator = await this.#locateOperation(step, scope);
174
+ const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
165
175
 
166
176
  // resolve parameters and request body against the pre-request context.
167
177
  // keyed by '{in}.{name}' rather than bare name, so two parameters that
@@ -175,7 +185,7 @@ class StepExecutor {
175
185
  // still reach this line — and this is the last moment before the step has a
176
186
  // live side effect. The signal stays in the bag, so a request already in
177
187
  // flight is aborted by the transport as before.
178
- const signal = readAbortSignal(executeOptions);
188
+ const signal = readAbortSignal(operationOptions);
179
189
  throwIfAborted(signal, scope);
180
190
 
181
191
  // the Arazzo-derived parameters and request body are spread after the opaque
@@ -184,7 +194,7 @@ class StepExecutor {
184
194
  let response;
185
195
  try {
186
196
  response = await this.#operationExecutor.execute(locator, {
187
- ...executeOptions,
197
+ ...operationOptions,
188
198
  parameters,
189
199
  ...this.#requestBodyOptions(requestBody)
190
200
  });
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  exports.settledResult = settledResult;
10
10
  var _apidomCore = require("@speclynx/apidom-core");
11
+ var _ramdaAdjunct = require("ramda-adjunct");
11
12
  var _apidomDatamodel = require("@speclynx/apidom-datamodel");
12
13
  var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
13
14
  var _RuntimeExpressionEvaluator = _interopRequireDefault(require("../expression/RuntimeExpressionEvaluator.cjs"));
@@ -163,7 +164,7 @@ class WorkflowExecutor {
163
164
  #maxWorkflowDepth;
164
165
  #now;
165
166
  #extractor = new _ArazzoWorkflowExtractor.default();
166
- #normalizer = new _ArazzoWorkflowNormalizer.default();
167
+ #normalizer;
167
168
  #outputResolver = new _OutputResolver.default();
168
169
  #parameterResolver = new _WorkflowParameterResolver.default();
169
170
  #stepExecutor;
@@ -174,6 +175,7 @@ class WorkflowExecutor {
174
175
  this.#document = options.document;
175
176
  this.#registry = options.registry;
176
177
  this.#workflowLocatorNormalizer = new _ArazzoWorkflowLocatorNormalizer.default(options.registry);
178
+ this.#normalizer = options.workflowNormalizer ?? new _ArazzoWorkflowNormalizer.default();
177
179
  this.#maxSteps = options.maxSteps ?? WorkflowExecutor.#DEFAULT_MAX_STEPS;
178
180
  this.#maxWorkflowDepth = options.maxWorkflowDepth ?? WorkflowExecutor.#DEFAULT_MAX_WORKFLOW_DEPTH;
179
181
  this.#now = options.now ?? WorkflowExecutor.#DEFAULT_NOW;
@@ -196,23 +198,21 @@ class WorkflowExecutor {
196
198
  */
197
199
  async execute(workflowId, options = {}) {
198
200
  this.#rejectUnknownOptions(options);
199
-
200
- // a signal in the opaque bag was the only channel before this option existed,
201
- // and it still reaches the transport. Absorbing it here is what makes it a
202
- // whole cancellation rather than half of one: read only at dispatch, it would
203
- // abort requests while the loop walked on through the remaining steps.
204
- const signal = options.signal ?? (0, _abort.readAbortSignal)(options.executeOptions ?? {});
201
+ const {
202
+ signal
203
+ } = options;
204
+ const executeOptions = this.#executeOptionsByDocument(options.executeOptions ?? {});
205
205
  const scope = {
206
- // the first-class signal is also spread into the opaque bag, because that
207
- // bag is how anything reaches the transport: the executor's own checks
208
- // stop the run at the next boundary, and this is what cancels the request
209
- // already in flight. Spread last, so it wins over one passed in the bag.
210
- executeOptions: {
211
- ...options.executeOptions,
212
- ...(signal === undefined ? {} : {
213
- signal
214
- })
215
- },
206
+ // the signal is put into every step's opaque bag, because that bag is
207
+ // how anything reaches the transport: the executor's own checks stop the
208
+ // run at the next boundary, and this is what cancels the request already
209
+ // in flight. Set even when absent, so a `signal` in an entry never
210
+ // stands in for it: that one would cancel the steps of a single API and
211
+ // leave the run walking on.
212
+ executeOptions: locator => ({
213
+ ...executeOptions.get(locator.document.uri),
214
+ signal
215
+ }),
216
216
  dependencyInputs: options.dependencyInputs ?? {},
217
217
  runDependencies: options.runDependencies ?? true,
218
218
  signal,
@@ -231,6 +231,41 @@ class WorkflowExecutor {
231
231
  }), 'root');
232
232
  }
233
233
 
234
+ /**
235
+ * Resolves the `executeOptions` entries to the documents they configure,
236
+ * keyed by canonical document URI.
237
+ *
238
+ * Every way an entry can fail to name exactly one OpenAPI document throws
239
+ * here, before the run starts: sent to no API or to two, its options would
240
+ * be missing or misdirected with nothing to show for it until a request
241
+ * failed.
242
+ */
243
+ #executeOptionsByDocument(executeOptions) {
244
+ const byDocument = new Map();
245
+ const fail = (name, problem, reason) => {
246
+ throw new _ExecutionError.default(`executeOptions is keyed by source description name, and "${name}" ${problem}`, {
247
+ reason
248
+ });
249
+ };
250
+ for (const [name, options] of Object.entries(executeOptions)) {
251
+ const uri = this.#document.resolveSourceDescriptionURI(name);
252
+ if (uri === undefined) {
253
+ return fail(name, `names no source description with a url in the Arazzo document at "${this.#document.uri}"`, _ExecutionError.default.SourceDescriptionNotFound);
254
+ }
255
+ if (this.#document.resolveSourceDescriptionField(name, 'type') === 'arazzo') {
256
+ fail(name, 'names an Arazzo document', _ExecutionError.default.SourceDescriptionNotOpenAPI);
257
+ }
258
+ if (!(0, _ramdaAdjunct.isPlainObject)(options)) {
259
+ fail(name, 'is not given an object of options', _ExecutionError.default.UnknownExecuteOption);
260
+ }
261
+ if (byDocument.has(uri)) {
262
+ fail(name, `points at "${uri}", which another entry already configures`, _ExecutionError.default.AmbiguousExecuteOptions);
263
+ }
264
+ byDocument.set(uri, options);
265
+ }
266
+ return byDocument;
267
+ }
268
+
234
269
  /**
235
270
  * Rejects an options bag carrying keys this method does not recognize.
236
271
  *