@usearazzo/runner 1.0.1-alpha.29 → 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 +13 -0
- package/README.md +27 -73
- package/dist/arazzo-runner.browser.js +210 -99
- 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/OpenAPIOperationExecutor.cjs +65 -12
- package/src/executor/OpenAPIOperationExecutor.mjs +63 -12
- package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +31 -4
- package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +30 -4
- package/src/executor/StepExecutor.cjs +14 -8
- package/src/executor/StepExecutor.mjs +14 -8
- package/src/executor/WorkflowExecutor.cjs +40 -16
- package/src/executor/WorkflowExecutor.mjs +40 -16
- package/types/runner.d.ts +90 -18
|
@@ -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";
|
|
@@ -1212,7 +1212,16 @@ export declare interface OpenAPIOperationExecuteOptions {
|
|
|
1212
1212
|
*/
|
|
1213
1213
|
readonly securities?: OpenAPIOperationSecurities;
|
|
1214
1214
|
readonly signal?: AbortSignal;
|
|
1215
|
+
/**
|
|
1216
|
+
* Runs after the executor-level interceptor, for this call only.
|
|
1217
|
+
*/
|
|
1215
1218
|
readonly requestInterceptor?: RequestInterceptor;
|
|
1219
|
+
/**
|
|
1220
|
+
* The Arazzo step this call is issued for, handed to both interceptors as
|
|
1221
|
+
* {@link RequestContext.step}. The step executor sets it; it is not
|
|
1222
|
+
* forwarded to `buildRequest`.
|
|
1223
|
+
*/
|
|
1224
|
+
readonly step?: RequestContextStep;
|
|
1216
1225
|
}
|
|
1217
1226
|
|
|
1218
1227
|
/**
|
|
@@ -1227,12 +1236,12 @@ export declare interface OpenAPIOperationExecuteOptions {
|
|
|
1227
1236
|
* needed a `contextUrl`, so reaching for that here means an edge case: tests
|
|
1228
1237
|
* standing in for a document fetched over HTTP.
|
|
1229
1238
|
*
|
|
1230
|
-
* Two kinds of entry are
|
|
1239
|
+
* Two kinds of entry are dropped rather than honored, since the executor owns
|
|
1231
1240
|
* what they used to control. The operation target always comes from the
|
|
1232
1241
|
* locator, so `operationId`/`operationPath` have no effect; and the options
|
|
1233
1242
|
* only swagger-client's `execute()` ever read — `userFetch` and
|
|
1234
1243
|
* `responseInterceptor`, which the runner replaces with `httpClient` and
|
|
1235
|
-
* `responseNormalizer` — reach `buildRequest
|
|
1244
|
+
* `responseNormalizer` — never reach `buildRequest`.
|
|
1236
1245
|
* @public
|
|
1237
1246
|
*/
|
|
1238
1247
|
export declare type OpenAPIOperationExecuteOptionsBag = OpenAPIOperationExecuteOptions & Record<string, unknown>;
|
|
@@ -1360,6 +1369,12 @@ export declare class OpenAPIOperationIndex extends Map<OperationId, JSONPointer>
|
|
|
1360
1369
|
export declare interface OpenAPIOperationLocator {
|
|
1361
1370
|
readonly document: OpenAPIDocument;
|
|
1362
1371
|
readonly jsonPointer: string;
|
|
1372
|
+
/**
|
|
1373
|
+
* The source description the step reached the operation through. Absent when
|
|
1374
|
+
* the reference names none (an `operationPath` with a literal URL) and on a
|
|
1375
|
+
* locator built by hand.
|
|
1376
|
+
*/
|
|
1377
|
+
readonly sourceDescription?: OpenAPIOperationSourceDescription;
|
|
1363
1378
|
}
|
|
1364
1379
|
|
|
1365
1380
|
/**
|
|
@@ -1646,6 +1661,17 @@ export declare type OpenAPIOperationSecurityCredential = string | {
|
|
|
1646
1661
|
readonly token: Readonly<Record<string, string>>;
|
|
1647
1662
|
};
|
|
1648
1663
|
|
|
1664
|
+
/**
|
|
1665
|
+
* A source description as an Arazzo document declares it: its `name`, and the
|
|
1666
|
+
* URI of the Arazzo document that declares it. Names are local to their
|
|
1667
|
+
* document, so the pair identifies one source description across a run.
|
|
1668
|
+
* @public
|
|
1669
|
+
*/
|
|
1670
|
+
export declare interface OpenAPIOperationSourceDescription {
|
|
1671
|
+
readonly name: string;
|
|
1672
|
+
readonly documentURI: string;
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1649
1675
|
/**
|
|
1650
1676
|
* Union of PathItemElement across all supported OpenAPI versions.
|
|
1651
1677
|
* @public
|
|
@@ -1754,15 +1780,58 @@ export declare class RequestBodyResolver extends ArazzoValueResolver {
|
|
|
1754
1780
|
resolve(requestBody: RequestBodyElement | undefined, resolve: RuntimeExpressionResolver, scope: StepScope): ResolvedRequestBody | undefined;
|
|
1755
1781
|
}
|
|
1756
1782
|
|
|
1783
|
+
/**
|
|
1784
|
+
* Identifies the request a {@link RequestInterceptor} receives, so an
|
|
1785
|
+
* interceptor can target one operation or one step without matching on the
|
|
1786
|
+
* expanded URL.
|
|
1787
|
+
*
|
|
1788
|
+
* `operation` is always present: it is the operation's locator — its canonical
|
|
1789
|
+
* OpenAPI document URI, the JSON Pointer to it and, when the locator carries
|
|
1790
|
+
* one, the source description it was located through — plus the `operationId`
|
|
1791
|
+
* the document declares, if any. `step` is present only when the request is
|
|
1792
|
+
* issued for an Arazzo step, i.e. through the step executor (and so the runner); an
|
|
1793
|
+
* {@link OpenAPIOperationExecutor} used on its own receives it only when its
|
|
1794
|
+
* caller passes `step` in the execute options. Absent fields are omitted, never
|
|
1795
|
+
* `undefined`.
|
|
1796
|
+
* @public
|
|
1797
|
+
*/
|
|
1798
|
+
export declare interface RequestContext {
|
|
1799
|
+
readonly operation: {
|
|
1800
|
+
readonly documentURI: string;
|
|
1801
|
+
readonly jsonPointer: string;
|
|
1802
|
+
readonly operationId?: string;
|
|
1803
|
+
readonly sourceDescription?: OpenAPIOperationSourceDescription;
|
|
1804
|
+
};
|
|
1805
|
+
readonly step?: RequestContextStep;
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
1810
|
+
* of the workflow it belongs to when the caller names one (step ids are only
|
|
1811
|
+
* unique within a workflow).
|
|
1812
|
+
* @public
|
|
1813
|
+
*/
|
|
1814
|
+
export declare interface RequestContextStep {
|
|
1815
|
+
readonly stepId: string;
|
|
1816
|
+
readonly workflowId?: string;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1757
1819
|
/**
|
|
1758
1820
|
* Decorates the built request before it is handed to the {@link HTTPClient}.
|
|
1759
1821
|
*
|
|
1760
1822
|
* Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
|
|
1761
1823
|
* place or return a replacement; returning nothing keeps the received request.
|
|
1762
|
-
* May be synchronous or asynchronous.
|
|
1824
|
+
* May be synchronous or asynchronous. The second argument identifies what the
|
|
1825
|
+
* request is for (see {@link RequestContext}); an interceptor that has no use
|
|
1826
|
+
* for it may declare only the first.
|
|
1827
|
+
*
|
|
1828
|
+
* Interceptors run after the body is serialized (a plain-object or array body
|
|
1829
|
+
* is already a JSON string, so a signature covers the exact bytes sent) and
|
|
1830
|
+
* after newlines in header values are squashed, and before the request is
|
|
1831
|
+
* captured for `$request.*` and handed to the transport.
|
|
1763
1832
|
* @public
|
|
1764
1833
|
*/
|
|
1765
|
-
export declare type RequestInterceptor = (request: OpenAPIOperationRequest) => OpenAPIOperationRequest | void | Promise<OpenAPIOperationRequest | void>;
|
|
1834
|
+
export declare type RequestInterceptor = (request: OpenAPIOperationRequest, context: RequestContext) => OpenAPIOperationRequest | void | Promise<OpenAPIOperationRequest | void>;
|
|
1766
1835
|
|
|
1767
1836
|
/**
|
|
1768
1837
|
* A resolved request body: the payload with all replacements applied, plus the
|
|
@@ -2214,10 +2283,10 @@ export declare abstract class SourceDescriptionsLocatorNormalizer {
|
|
|
2214
2283
|
/**
|
|
2215
2284
|
* The execute options of a step: the opaque bag forwarded to the operation
|
|
2216
2285
|
* executor, or a function returning it for the operation the step was located
|
|
2217
|
-
* to.
|
|
2286
|
+
* to, called with the step it is located for.
|
|
2218
2287
|
* @public
|
|
2219
2288
|
*/
|
|
2220
|
-
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>);
|
|
2221
2290
|
|
|
2222
2291
|
/**
|
|
2223
2292
|
* The outcome of executing a single step.
|
|
@@ -2306,8 +2375,8 @@ export declare class StepExecutor {
|
|
|
2306
2375
|
* (e.g. a `server` to run the step against, or an `AbortSignal`). The
|
|
2307
2376
|
* Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
|
|
2308
2377
|
* take precedence over it. A function is called with the operation the step
|
|
2309
|
-
* was located to and
|
|
2310
|
-
* 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.
|
|
2311
2380
|
*
|
|
2312
2381
|
* A `signal` in that bag is honored here and not only at the transport: an
|
|
2313
2382
|
* already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
|
|
@@ -2555,18 +2624,21 @@ export declare interface WorkflowExecuteOptions {
|
|
|
2555
2624
|
* Execute options addressed to an API: keyed by the `name` of a source
|
|
2556
2625
|
* description of the entry document, each entry the opaque client-specific
|
|
2557
2626
|
* bag forwarded verbatim to {@link StepExecutor.execute} for the steps that
|
|
2558
|
-
* call an operation
|
|
2559
|
-
*
|
|
2627
|
+
* call an operation through that source description (e.g. a `server` to run
|
|
2628
|
+
* against, or the credentials of its security schemes).
|
|
2560
2629
|
*
|
|
2561
|
-
* An entry configures a
|
|
2562
|
-
*
|
|
2563
|
-
*
|
|
2564
|
-
*
|
|
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.
|
|
2565
2638
|
*
|
|
2566
2639
|
* A key naming no source description, one naming a source description that
|
|
2567
|
-
* has no `url` or is not an OpenAPI document,
|
|
2568
|
-
*
|
|
2569
|
-
* 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.
|
|
2570
2642
|
*/
|
|
2571
2643
|
readonly executeOptions?: Record<string, Record<string, unknown>>;
|
|
2572
2644
|
/**
|