@usearazzo/runner 1.0.1-alpha.30 → 1.0.1-alpha.31
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 +6 -0
- package/dist/arazzo-runner.browser.js +49 -21
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +4 -4
- package/src/errors/ExecutionError.cjs +1 -1
- package/src/errors/ExecutionError.mjs +1 -1
- package/src/executor/StepExecutor.cjs +8 -4
- package/src/executor/StepExecutor.mjs +8 -4
- package/src/executor/WorkflowExecutor.cjs +40 -16
- package/src/executor/WorkflowExecutor.mjs +40 -16
- package/types/runner.d.ts +17 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usearazzo/runner",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.31",
|
|
4
4
|
"description": "Runner for Arazzo Workflows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arazzo",
|
|
@@ -73,8 +73,8 @@
|
|
|
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.
|
|
77
|
-
"@usearazzo/resolver": "1.0.1-alpha.
|
|
76
|
+
"@usearazzo/parser": "1.0.1-alpha.31",
|
|
77
|
+
"@usearazzo/resolver": "1.0.1-alpha.31",
|
|
78
78
|
"@xmldom/xmldom": "^0.9.12",
|
|
79
79
|
"fontoxpath": "^3.34.0",
|
|
80
80
|
"ramda": "^0.32.0",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"swagger-client": "^3.39.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "ff411e3bd2734c6f6c6d9b9cbe83e9b65dfe53f0"
|
|
98
98
|
}
|
|
@@ -17,7 +17,7 @@ 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
|
-
/**
|
|
20
|
+
/** A step without an `executeOptions` entry of its own reaches a document that several entries configure. */
|
|
21
21
|
static AmbiguousExecuteOptions = 'ambiguous-execute-options';
|
|
22
22
|
/** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
|
|
23
23
|
static AmbiguousTarget = 'ambiguous-target';
|
|
@@ -10,7 +10,7 @@ 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
|
-
/**
|
|
13
|
+
/** A step without an `executeOptions` entry of its own reaches a document that several entries configure. */
|
|
14
14
|
static AmbiguousExecuteOptions = 'ambiguous-execute-options';
|
|
15
15
|
/** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
|
|
16
16
|
static AmbiguousTarget = 'ambiguous-target';
|
|
@@ -68,7 +68,7 @@ const STEP_TARGET_FIELDS = exports.STEP_TARGET_FIELDS = ['operationId', 'operati
|
|
|
68
68
|
/**
|
|
69
69
|
* The execute options of a step: the opaque bag forwarded to the operation
|
|
70
70
|
* executor, or a function returning it for the operation the step was located
|
|
71
|
-
* to.
|
|
71
|
+
* to, called with the step it is located for.
|
|
72
72
|
* @public
|
|
73
73
|
*/
|
|
74
74
|
|
|
@@ -135,8 +135,8 @@ class StepExecutor {
|
|
|
135
135
|
* (e.g. a `server` to run the step against, or an `AbortSignal`). The
|
|
136
136
|
* Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
|
|
137
137
|
* take precedence over it. A function is called with the operation the step
|
|
138
|
-
* was located to and
|
|
139
|
-
* the step calls.
|
|
138
|
+
* was located to and the step's `stepId` / `workflowId`, and returns the bag,
|
|
139
|
+
* for options that depend on which API the step calls.
|
|
140
140
|
*
|
|
141
141
|
* A `signal` in that bag is honored here and not only at the transport: an
|
|
142
142
|
* already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
|
|
@@ -178,7 +178,11 @@ class StepExecutor {
|
|
|
178
178
|
// Pointer) locator that the operation executor extracts, normalizes,
|
|
179
179
|
// assembles into a standalone doc, and runs.
|
|
180
180
|
const locator = await this.#locateOperation(step, scope);
|
|
181
|
-
const operationOptions =
|
|
181
|
+
const operationOptions =
|
|
182
|
+
// a copy, so the function cannot rewrite the scope this step attributes its errors to
|
|
183
|
+
typeof executeOptions === 'function' ? executeOptions(locator, {
|
|
184
|
+
...scope
|
|
185
|
+
}) : executeOptions;
|
|
182
186
|
|
|
183
187
|
// resolve parameters and request body against the pre-request context.
|
|
184
188
|
// keyed by '{in}.{name}' rather than bare name, so two parameters that
|
|
@@ -61,7 +61,7 @@ export const STEP_TARGET_FIELDS = ['operationId', 'operationPath', 'workflowId']
|
|
|
61
61
|
/**
|
|
62
62
|
* The execute options of a step: the opaque bag forwarded to the operation
|
|
63
63
|
* executor, or a function returning it for the operation the step was located
|
|
64
|
-
* to.
|
|
64
|
+
* to, called with the step it is located for.
|
|
65
65
|
* @public
|
|
66
66
|
*/
|
|
67
67
|
|
|
@@ -128,8 +128,8 @@ class StepExecutor {
|
|
|
128
128
|
* (e.g. a `server` to run the step against, or an `AbortSignal`). The
|
|
129
129
|
* Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
|
|
130
130
|
* take precedence over it. A function is called with the operation the step
|
|
131
|
-
* was located to and
|
|
132
|
-
* the step calls.
|
|
131
|
+
* was located to and the step's `stepId` / `workflowId`, and returns the bag,
|
|
132
|
+
* for options that depend on which API the step calls.
|
|
133
133
|
*
|
|
134
134
|
* A `signal` in that bag is honored here and not only at the transport: an
|
|
135
135
|
* already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
|
|
@@ -171,7 +171,11 @@ class StepExecutor {
|
|
|
171
171
|
// Pointer) locator that the operation executor extracts, normalizes,
|
|
172
172
|
// assembles into a standalone doc, and runs.
|
|
173
173
|
const locator = await this.#locateOperation(step, scope);
|
|
174
|
-
const operationOptions =
|
|
174
|
+
const operationOptions =
|
|
175
|
+
// a copy, so the function cannot rewrite the scope this step attributes its errors to
|
|
176
|
+
typeof executeOptions === 'function' ? executeOptions(locator, {
|
|
177
|
+
...scope
|
|
178
|
+
}) : executeOptions;
|
|
175
179
|
|
|
176
180
|
// resolve parameters and request body against the pre-request context.
|
|
177
181
|
// keyed by '{in}.{name}' rather than bare name, so two parameters that
|
|
@@ -101,6 +101,11 @@ function settledResult(result) {
|
|
|
101
101
|
* given — see {@link RunScope.dependencyRuns}.
|
|
102
102
|
*/
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* One `executeOptions` entry and the canonical URI of the document its name
|
|
106
|
+
* points at.
|
|
107
|
+
*/
|
|
108
|
+
|
|
104
109
|
/**
|
|
105
110
|
* The state shared by every workflow invocation of a single
|
|
106
111
|
* {@link WorkflowExecutor.execute} call — the caller's per-run options plus the
|
|
@@ -201,7 +206,7 @@ class WorkflowExecutor {
|
|
|
201
206
|
const {
|
|
202
207
|
signal
|
|
203
208
|
} = options;
|
|
204
|
-
const executeOptions = this.#
|
|
209
|
+
const executeOptions = this.#executeOptionsByName(options.executeOptions ?? {});
|
|
205
210
|
const scope = {
|
|
206
211
|
// the signal is put into every step's opaque bag, because that bag is
|
|
207
212
|
// how anything reaches the transport: the executor's own checks stop the
|
|
@@ -209,8 +214,8 @@ class WorkflowExecutor {
|
|
|
209
214
|
// in flight. Set even when absent, so a `signal` in an entry never
|
|
210
215
|
// stands in for it: that one would cancel the steps of a single API and
|
|
211
216
|
// leave the run walking on.
|
|
212
|
-
executeOptions: locator => ({
|
|
213
|
-
...executeOptions
|
|
217
|
+
executeOptions: (locator, step) => ({
|
|
218
|
+
...this.#executeOptionsFor(executeOptions, locator, step),
|
|
214
219
|
signal
|
|
215
220
|
}),
|
|
216
221
|
dependencyInputs: options.dependencyInputs ?? {},
|
|
@@ -232,16 +237,15 @@ class WorkflowExecutor {
|
|
|
232
237
|
}
|
|
233
238
|
|
|
234
239
|
/**
|
|
235
|
-
* Resolves
|
|
236
|
-
* keyed by
|
|
240
|
+
* Resolves each `executeOptions` entry to the canonical URI of the document
|
|
241
|
+
* its name points at, keyed by name.
|
|
237
242
|
*
|
|
238
|
-
* Every way an entry can fail to name
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* failed.
|
|
243
|
+
* Every way an entry can fail to name an OpenAPI document throws here,
|
|
244
|
+
* before the run starts: sent to no API, its options would be missing with
|
|
245
|
+
* nothing to show for it until a request failed.
|
|
242
246
|
*/
|
|
243
|
-
#
|
|
244
|
-
const
|
|
247
|
+
#executeOptionsByName(executeOptions) {
|
|
248
|
+
const byName = new Map();
|
|
245
249
|
const fail = (name, problem, reason) => {
|
|
246
250
|
throw new _ExecutionError.default(`executeOptions is keyed by source description name, and "${name}" ${problem}`, {
|
|
247
251
|
reason
|
|
@@ -258,12 +262,32 @@ class WorkflowExecutor {
|
|
|
258
262
|
if (!(0, _ramdaAdjunct.isPlainObject)(options)) {
|
|
259
263
|
fail(name, 'is not given an object of options', _ExecutionError.default.UnknownExecuteOption);
|
|
260
264
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
+
byName.set(name, {
|
|
266
|
+
uri,
|
|
267
|
+
options
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return byName;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* The entry for the step's operation: the entry of the name the step reached
|
|
275
|
+
* it through, when that is a name of the entry document with an entry;
|
|
276
|
+
* otherwise the one entry configuring the operation's document, if any.
|
|
277
|
+
*/
|
|
278
|
+
#executeOptionsFor(entries, locator, step) {
|
|
279
|
+
const source = locator.sourceDescription;
|
|
280
|
+
const named = source?.documentURI === this.#document.uri ? entries.get(source.name) : undefined;
|
|
281
|
+
if (named !== undefined) return named.options;
|
|
282
|
+
const configuring = [...entries].filter(([, entry]) => entry.uri === locator.document.uri);
|
|
283
|
+
if (configuring.length > 1) {
|
|
284
|
+
const names = configuring.map(([name]) => `"${name}"`).join(', ');
|
|
285
|
+
throw new _ExecutionError.default(`Step "${step.stepId}" has no executeOptions entry of its own, and ${names} all configure "${locator.document.uri}", the document it calls`, {
|
|
286
|
+
...step,
|
|
287
|
+
reason: _ExecutionError.default.AmbiguousExecuteOptions
|
|
288
|
+
});
|
|
265
289
|
}
|
|
266
|
-
return
|
|
290
|
+
return configuring[0]?.[1].options;
|
|
267
291
|
}
|
|
268
292
|
|
|
269
293
|
/**
|
|
@@ -87,6 +87,11 @@ export function settledResult(result) {
|
|
|
87
87
|
* given — see {@link RunScope.dependencyRuns}.
|
|
88
88
|
*/
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* One `executeOptions` entry and the canonical URI of the document its name
|
|
92
|
+
* points at.
|
|
93
|
+
*/
|
|
94
|
+
|
|
90
95
|
/**
|
|
91
96
|
* The state shared by every workflow invocation of a single
|
|
92
97
|
* {@link WorkflowExecutor.execute} call — the caller's per-run options plus the
|
|
@@ -187,7 +192,7 @@ class WorkflowExecutor {
|
|
|
187
192
|
const {
|
|
188
193
|
signal
|
|
189
194
|
} = options;
|
|
190
|
-
const executeOptions = this.#
|
|
195
|
+
const executeOptions = this.#executeOptionsByName(options.executeOptions ?? {});
|
|
191
196
|
const scope = {
|
|
192
197
|
// the signal is put into every step's opaque bag, because that bag is
|
|
193
198
|
// how anything reaches the transport: the executor's own checks stop the
|
|
@@ -195,8 +200,8 @@ class WorkflowExecutor {
|
|
|
195
200
|
// in flight. Set even when absent, so a `signal` in an entry never
|
|
196
201
|
// stands in for it: that one would cancel the steps of a single API and
|
|
197
202
|
// leave the run walking on.
|
|
198
|
-
executeOptions: locator => ({
|
|
199
|
-
...executeOptions
|
|
203
|
+
executeOptions: (locator, step) => ({
|
|
204
|
+
...this.#executeOptionsFor(executeOptions, locator, step),
|
|
200
205
|
signal
|
|
201
206
|
}),
|
|
202
207
|
dependencyInputs: options.dependencyInputs ?? {},
|
|
@@ -218,16 +223,15 @@ class WorkflowExecutor {
|
|
|
218
223
|
}
|
|
219
224
|
|
|
220
225
|
/**
|
|
221
|
-
* Resolves
|
|
222
|
-
* keyed by
|
|
226
|
+
* Resolves each `executeOptions` entry to the canonical URI of the document
|
|
227
|
+
* its name points at, keyed by name.
|
|
223
228
|
*
|
|
224
|
-
* Every way an entry can fail to name
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* failed.
|
|
229
|
+
* Every way an entry can fail to name an OpenAPI document throws here,
|
|
230
|
+
* before the run starts: sent to no API, its options would be missing with
|
|
231
|
+
* nothing to show for it until a request failed.
|
|
228
232
|
*/
|
|
229
|
-
#
|
|
230
|
-
const
|
|
233
|
+
#executeOptionsByName(executeOptions) {
|
|
234
|
+
const byName = new Map();
|
|
231
235
|
const fail = (name, problem, reason) => {
|
|
232
236
|
throw new ExecutionError(`executeOptions is keyed by source description name, and "${name}" ${problem}`, {
|
|
233
237
|
reason
|
|
@@ -244,12 +248,32 @@ class WorkflowExecutor {
|
|
|
244
248
|
if (!isPlainObject(options)) {
|
|
245
249
|
fail(name, 'is not given an object of options', ExecutionError.UnknownExecuteOption);
|
|
246
250
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
+
byName.set(name, {
|
|
252
|
+
uri,
|
|
253
|
+
options
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return byName;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The entry for the step's operation: the entry of the name the step reached
|
|
261
|
+
* it through, when that is a name of the entry document with an entry;
|
|
262
|
+
* otherwise the one entry configuring the operation's document, if any.
|
|
263
|
+
*/
|
|
264
|
+
#executeOptionsFor(entries, locator, step) {
|
|
265
|
+
const source = locator.sourceDescription;
|
|
266
|
+
const named = source?.documentURI === this.#document.uri ? entries.get(source.name) : undefined;
|
|
267
|
+
if (named !== undefined) return named.options;
|
|
268
|
+
const configuring = [...entries].filter(([, entry]) => entry.uri === locator.document.uri);
|
|
269
|
+
if (configuring.length > 1) {
|
|
270
|
+
const names = configuring.map(([name]) => `"${name}"`).join(', ');
|
|
271
|
+
throw new ExecutionError(`Step "${step.stepId}" has no executeOptions entry of its own, and ${names} all configure "${locator.document.uri}", the document it calls`, {
|
|
272
|
+
...step,
|
|
273
|
+
reason: ExecutionError.AmbiguousExecuteOptions
|
|
274
|
+
});
|
|
251
275
|
}
|
|
252
|
-
return
|
|
276
|
+
return configuring[0]?.[1].options;
|
|
253
277
|
}
|
|
254
278
|
|
|
255
279
|
/**
|
package/types/runner.d.ts
CHANGED
|
@@ -816,7 +816,7 @@ export declare type DocumentRegistryProviderOptions = PartialDeep<ApiDOMReferenc
|
|
|
816
816
|
export declare class ExecutionError extends ArazzoRunnerError {
|
|
817
817
|
/** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
|
|
818
818
|
static readonly Aborted: "aborted";
|
|
819
|
-
/**
|
|
819
|
+
/** A step without an `executeOptions` entry of its own reaches a document that several entries configure. */
|
|
820
820
|
static readonly AmbiguousExecuteOptions: "ambiguous-execute-options";
|
|
821
821
|
/** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
|
|
822
822
|
static readonly AmbiguousTarget: "ambiguous-target";
|
|
@@ -2283,10 +2283,10 @@ export declare abstract class SourceDescriptionsLocatorNormalizer {
|
|
|
2283
2283
|
/**
|
|
2284
2284
|
* The execute options of a step: the opaque bag forwarded to the operation
|
|
2285
2285
|
* executor, or a function returning it for the operation the step was located
|
|
2286
|
-
* to.
|
|
2286
|
+
* to, called with the step it is located for.
|
|
2287
2287
|
* @public
|
|
2288
2288
|
*/
|
|
2289
|
-
export declare type StepExecuteOptions = Record<string, unknown> | ((locator: OpenAPIOperationLocator) => Record<string, unknown>);
|
|
2289
|
+
export declare type StepExecuteOptions = Record<string, unknown> | ((locator: OpenAPIOperationLocator, step: RequestContextStep) => Record<string, unknown>);
|
|
2290
2290
|
|
|
2291
2291
|
/**
|
|
2292
2292
|
* The outcome of executing a single step.
|
|
@@ -2375,8 +2375,8 @@ export declare class StepExecutor {
|
|
|
2375
2375
|
* (e.g. a `server` to run the step against, or an `AbortSignal`). The
|
|
2376
2376
|
* Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
|
|
2377
2377
|
* take precedence over it. A function is called with the operation the step
|
|
2378
|
-
* was located to and
|
|
2379
|
-
* the step calls.
|
|
2378
|
+
* was located to and the step's `stepId` / `workflowId`, and returns the bag,
|
|
2379
|
+
* for options that depend on which API the step calls.
|
|
2380
2380
|
*
|
|
2381
2381
|
* A `signal` in that bag is honored here and not only at the transport: an
|
|
2382
2382
|
* already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
|
|
@@ -2624,18 +2624,21 @@ export declare interface WorkflowExecuteOptions {
|
|
|
2624
2624
|
* Execute options addressed to an API: keyed by the `name` of a source
|
|
2625
2625
|
* description of the entry document, each entry the opaque client-specific
|
|
2626
2626
|
* bag forwarded verbatim to {@link StepExecutor.execute} for the steps that
|
|
2627
|
-
* call an operation
|
|
2628
|
-
*
|
|
2627
|
+
* call an operation through that source description (e.g. a `server` to run
|
|
2628
|
+
* against, or the credentials of its security schemes).
|
|
2629
2629
|
*
|
|
2630
|
-
* An entry configures a
|
|
2631
|
-
*
|
|
2632
|
-
*
|
|
2633
|
-
*
|
|
2630
|
+
* An entry configures a name, so two source descriptions pointing at the
|
|
2631
|
+
* same OpenAPI document can be configured apart. A step reaching its document
|
|
2632
|
+
* any other way — through a name without an entry, through a name of
|
|
2633
|
+
* another Arazzo document, or through a literal URL — gets the one entry
|
|
2634
|
+
* configuring that document; it gets nothing when no entry does, and throws
|
|
2635
|
+
* when several do, since nothing says which applies. That throw comes at the
|
|
2636
|
+
* step, so the steps before it have already run. Steps of an API without
|
|
2637
|
+
* an entry get no options.
|
|
2634
2638
|
*
|
|
2635
2639
|
* A key naming no source description, one naming a source description that
|
|
2636
|
-
* has no `url` or is not an OpenAPI document,
|
|
2637
|
-
*
|
|
2638
|
-
* request.
|
|
2640
|
+
* has no `url` or is not an OpenAPI document, and an entry that is not an
|
|
2641
|
+
* object all throw before the first request.
|
|
2639
2642
|
*/
|
|
2640
2643
|
readonly executeOptions?: Record<string, Record<string, unknown>>;
|
|
2641
2644
|
/**
|