@usearazzo/runner 1.0.1-alpha.29 → 1.0.1-alpha.30
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 +7 -0
- package/README.md +27 -73
- package/dist/arazzo-runner.browser.js +161 -78
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +4 -4
- 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 +6 -4
- package/src/executor/StepExecutor.mjs +6 -4
- package/types/runner.d.ts +73 -4
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.30",
|
|
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.30",
|
|
77
|
+
"@usearazzo/resolver": "1.0.1-alpha.30",
|
|
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": "7b79e517626548f30ae1ae3fa6c689b59ccc26fa"
|
|
98
98
|
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _ramda = require("ramda");
|
|
8
9
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
10
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
10
11
|
var _empty = require("@speclynx/apidom-reference/configuration/empty");
|
|
@@ -22,12 +23,42 @@ var _OpenAPIDocumentAssembler = _interopRequireDefault(require("../assembler/Ope
|
|
|
22
23
|
var _ClientError = _interopRequireDefault(require("../errors/ClientError.cjs"));
|
|
23
24
|
// @ts-expect-error vendored swagger-client bundle has no type declarations
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
28
|
+
* of the workflow it belongs to when the caller names one (step ids are only
|
|
29
|
+
* unique within a workflow).
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Identifies the request a {@link RequestInterceptor} receives, so an
|
|
35
|
+
* interceptor can target one operation or one step without matching on the
|
|
36
|
+
* expanded URL.
|
|
37
|
+
*
|
|
38
|
+
* `operation` is always present: it is the operation's locator — its canonical
|
|
39
|
+
* OpenAPI document URI, the JSON Pointer to it and, when the locator carries
|
|
40
|
+
* one, the source description it was located through — plus the `operationId`
|
|
41
|
+
* the document declares, if any. `step` is present only when the request is
|
|
42
|
+
* issued for an Arazzo step, i.e. through the step executor (and so the runner); an
|
|
43
|
+
* {@link OpenAPIOperationExecutor} used on its own receives it only when its
|
|
44
|
+
* caller passes `step` in the execute options. Absent fields are omitted, never
|
|
45
|
+
* `undefined`.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
|
|
25
49
|
/**
|
|
26
50
|
* Decorates the built request before it is handed to the {@link HTTPClient}.
|
|
27
51
|
*
|
|
28
52
|
* Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
|
|
29
53
|
* place or return a replacement; returning nothing keeps the received request.
|
|
30
|
-
* May be synchronous or asynchronous.
|
|
54
|
+
* May be synchronous or asynchronous. The second argument identifies what the
|
|
55
|
+
* request is for (see {@link RequestContext}); an interceptor that has no use
|
|
56
|
+
* for it may declare only the first.
|
|
57
|
+
*
|
|
58
|
+
* Interceptors run after the body is serialized (a plain-object or array body
|
|
59
|
+
* is already a JSON string, so a signature covers the exact bytes sent) and
|
|
60
|
+
* after newlines in header values are squashed, and before the request is
|
|
61
|
+
* captured for `$request.*` and handed to the transport.
|
|
31
62
|
* @public
|
|
32
63
|
*/
|
|
33
64
|
|
|
@@ -95,12 +126,12 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
|
95
126
|
* needed a `contextUrl`, so reaching for that here means an edge case: tests
|
|
96
127
|
* standing in for a document fetched over HTTP.
|
|
97
128
|
*
|
|
98
|
-
* Two kinds of entry are
|
|
129
|
+
* Two kinds of entry are dropped rather than honored, since the executor owns
|
|
99
130
|
* what they used to control. The operation target always comes from the
|
|
100
131
|
* locator, so `operationId`/`operationPath` have no effect; and the options
|
|
101
132
|
* only swagger-client's `execute()` ever read — `userFetch` and
|
|
102
133
|
* `responseInterceptor`, which the runner replaces with `httpClient` and
|
|
103
|
-
* `responseNormalizer` — reach `buildRequest
|
|
134
|
+
* `responseNormalizer` — never reach `buildRequest`.
|
|
104
135
|
* @public
|
|
105
136
|
*/
|
|
106
137
|
|
|
@@ -168,14 +199,36 @@ class OpenAPIOperationExecutor {
|
|
|
168
199
|
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
169
200
|
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
170
201
|
|
|
171
|
-
// the interceptor
|
|
172
|
-
// locator,
|
|
202
|
+
// the interceptor and step are consumed here, the target always comes from
|
|
203
|
+
// the locator, and the transport is the httpClient, so none of these
|
|
204
|
+
// reach buildRequest
|
|
173
205
|
const {
|
|
174
206
|
requestInterceptor,
|
|
175
|
-
|
|
176
|
-
operationPath: __,
|
|
177
|
-
...rest
|
|
207
|
+
step
|
|
178
208
|
} = executeOptions;
|
|
209
|
+
const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
210
|
+
const declaredOperationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
211
|
+
const context = {
|
|
212
|
+
operation: {
|
|
213
|
+
documentURI: locator.document.uri,
|
|
214
|
+
jsonPointer: locator.jsonPointer,
|
|
215
|
+
...(typeof declaredOperationId === 'string' ? {
|
|
216
|
+
operationId: declaredOperationId
|
|
217
|
+
} : {}),
|
|
218
|
+
...(locator.sourceDescription === undefined ? {} : {
|
|
219
|
+
sourceDescription: {
|
|
220
|
+
...locator.sourceDescription
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
},
|
|
224
|
+
// a copy, so an interceptor editing it cannot rewrite the caller's object
|
|
225
|
+
// (the step executor reuses it to attribute errors)
|
|
226
|
+
...(step === undefined ? {} : {
|
|
227
|
+
step: {
|
|
228
|
+
...step
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
};
|
|
179
232
|
|
|
180
233
|
// each step derives the next options rather than editing in place
|
|
181
234
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -206,7 +259,7 @@ class OpenAPIOperationExecutor {
|
|
|
206
259
|
request.headers['Content-Type'] = authoredContentType;
|
|
207
260
|
}
|
|
208
261
|
this.#deliverHeadersAndCookies(request, undeclared);
|
|
209
|
-
request = await this.#finalizeRequest(request, requestInterceptor);
|
|
262
|
+
request = await this.#finalizeRequest(request, requestInterceptor, context);
|
|
210
263
|
|
|
211
264
|
// capture the request as sent, so `$url` / `$method` / `$request.*` can be
|
|
212
265
|
// evaluated after execution; headers are copied so a transport-side
|
|
@@ -583,7 +636,7 @@ class OpenAPIOperationExecutor {
|
|
|
583
636
|
* `http()`, which also fetch and throw on a non-2xx. Diff against those two
|
|
584
637
|
* when bumping swagger-client.
|
|
585
638
|
*/
|
|
586
|
-
async #finalizeRequest(request, perCallInterceptor) {
|
|
639
|
+
async #finalizeRequest(request, perCallInterceptor, context) {
|
|
587
640
|
let finalized = request;
|
|
588
641
|
|
|
589
642
|
// JSON-encode plain-object and array bodies, exactly as swagger-client's
|
|
@@ -602,8 +655,8 @@ class OpenAPIOperationExecutor {
|
|
|
602
655
|
finalized.headers[headerName] = value.replace(/\n+/g, ' ');
|
|
603
656
|
}
|
|
604
657
|
});
|
|
605
|
-
finalized = (await this.#requestInterceptor?.(finalized)) ?? finalized;
|
|
606
|
-
finalized = (await perCallInterceptor?.(finalized)) ?? finalized;
|
|
658
|
+
finalized = (await this.#requestInterceptor?.(finalized, context)) ?? finalized;
|
|
659
|
+
finalized = (await perCallInterceptor?.(finalized, context)) ?? finalized;
|
|
607
660
|
|
|
608
661
|
// for multipart/form-data, remove the built content-type so the transport
|
|
609
662
|
// sets one carrying the correct boundary
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { omit } from 'ramda';
|
|
1
2
|
import { toValue } from '@speclynx/apidom-core';
|
|
2
3
|
import { isArrayElement, isObjectElement } from '@speclynx/apidom-datamodel';
|
|
3
4
|
import { url as urlUtils } from '@speclynx/apidom-reference/configuration/empty';
|
|
@@ -15,12 +16,40 @@ import OpenAPIOperationExtractor from "../extractor/OpenAPIOperationExtractor.mj
|
|
|
15
16
|
import OpenAPIOperationNormalizer from "../normalizer/OpenAPIOperationNormalizer.mjs";
|
|
16
17
|
import OpenAPIDocumentAssembler from "../assembler/OpenAPIDocumentAssembler.mjs";
|
|
17
18
|
import ClientError from "../errors/ClientError.mjs";
|
|
19
|
+
/**
|
|
20
|
+
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
21
|
+
* of the workflow it belongs to when the caller names one (step ids are only
|
|
22
|
+
* unique within a workflow).
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Identifies the request a {@link RequestInterceptor} receives, so an
|
|
27
|
+
* interceptor can target one operation or one step without matching on the
|
|
28
|
+
* expanded URL.
|
|
29
|
+
*
|
|
30
|
+
* `operation` is always present: it is the operation's locator — its canonical
|
|
31
|
+
* OpenAPI document URI, the JSON Pointer to it and, when the locator carries
|
|
32
|
+
* one, the source description it was located through — plus the `operationId`
|
|
33
|
+
* the document declares, if any. `step` is present only when the request is
|
|
34
|
+
* issued for an Arazzo step, i.e. through the step executor (and so the runner); an
|
|
35
|
+
* {@link OpenAPIOperationExecutor} used on its own receives it only when its
|
|
36
|
+
* caller passes `step` in the execute options. Absent fields are omitted, never
|
|
37
|
+
* `undefined`.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
18
40
|
/**
|
|
19
41
|
* Decorates the built request before it is handed to the {@link HTTPClient}.
|
|
20
42
|
*
|
|
21
43
|
* Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
|
|
22
44
|
* place or return a replacement; returning nothing keeps the received request.
|
|
23
|
-
* May be synchronous or asynchronous.
|
|
45
|
+
* May be synchronous or asynchronous. The second argument identifies what the
|
|
46
|
+
* request is for (see {@link RequestContext}); an interceptor that has no use
|
|
47
|
+
* for it may declare only the first.
|
|
48
|
+
*
|
|
49
|
+
* Interceptors run after the body is serialized (a plain-object or array body
|
|
50
|
+
* is already a JSON string, so a signature covers the exact bytes sent) and
|
|
51
|
+
* after newlines in header values are squashed, and before the request is
|
|
52
|
+
* captured for `$request.*` and handed to the transport.
|
|
24
53
|
* @public
|
|
25
54
|
*/
|
|
26
55
|
/**
|
|
@@ -85,12 +114,12 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
|
85
114
|
* needed a `contextUrl`, so reaching for that here means an edge case: tests
|
|
86
115
|
* standing in for a document fetched over HTTP.
|
|
87
116
|
*
|
|
88
|
-
* Two kinds of entry are
|
|
117
|
+
* Two kinds of entry are dropped rather than honored, since the executor owns
|
|
89
118
|
* what they used to control. The operation target always comes from the
|
|
90
119
|
* locator, so `operationId`/`operationPath` have no effect; and the options
|
|
91
120
|
* only swagger-client's `execute()` ever read — `userFetch` and
|
|
92
121
|
* `responseInterceptor`, which the runner replaces with `httpClient` and
|
|
93
|
-
* `responseNormalizer` — reach `buildRequest
|
|
122
|
+
* `responseNormalizer` — never reach `buildRequest`.
|
|
94
123
|
* @public
|
|
95
124
|
*/
|
|
96
125
|
|
|
@@ -158,14 +187,36 @@ class OpenAPIOperationExecutor {
|
|
|
158
187
|
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
159
188
|
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
160
189
|
|
|
161
|
-
// the interceptor
|
|
162
|
-
// locator,
|
|
190
|
+
// the interceptor and step are consumed here, the target always comes from
|
|
191
|
+
// the locator, and the transport is the httpClient, so none of these
|
|
192
|
+
// reach buildRequest
|
|
163
193
|
const {
|
|
164
194
|
requestInterceptor,
|
|
165
|
-
|
|
166
|
-
operationPath: __,
|
|
167
|
-
...rest
|
|
195
|
+
step
|
|
168
196
|
} = executeOptions;
|
|
197
|
+
const rest = omit(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
198
|
+
const declaredOperationId = toValue(operation.operationId);
|
|
199
|
+
const context = {
|
|
200
|
+
operation: {
|
|
201
|
+
documentURI: locator.document.uri,
|
|
202
|
+
jsonPointer: locator.jsonPointer,
|
|
203
|
+
...(typeof declaredOperationId === 'string' ? {
|
|
204
|
+
operationId: declaredOperationId
|
|
205
|
+
} : {}),
|
|
206
|
+
...(locator.sourceDescription === undefined ? {} : {
|
|
207
|
+
sourceDescription: {
|
|
208
|
+
...locator.sourceDescription
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
},
|
|
212
|
+
// a copy, so an interceptor editing it cannot rewrite the caller's object
|
|
213
|
+
// (the step executor reuses it to attribute errors)
|
|
214
|
+
...(step === undefined ? {} : {
|
|
215
|
+
step: {
|
|
216
|
+
...step
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
};
|
|
169
220
|
|
|
170
221
|
// each step derives the next options rather than editing in place
|
|
171
222
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -196,7 +247,7 @@ class OpenAPIOperationExecutor {
|
|
|
196
247
|
request.headers['Content-Type'] = authoredContentType;
|
|
197
248
|
}
|
|
198
249
|
this.#deliverHeadersAndCookies(request, undeclared);
|
|
199
|
-
request = await this.#finalizeRequest(request, requestInterceptor);
|
|
250
|
+
request = await this.#finalizeRequest(request, requestInterceptor, context);
|
|
200
251
|
|
|
201
252
|
// capture the request as sent, so `$url` / `$method` / `$request.*` can be
|
|
202
253
|
// evaluated after execution; headers are copied so a transport-side
|
|
@@ -573,7 +624,7 @@ class OpenAPIOperationExecutor {
|
|
|
573
624
|
* `http()`, which also fetch and throw on a non-2xx. Diff against those two
|
|
574
625
|
* when bumping swagger-client.
|
|
575
626
|
*/
|
|
576
|
-
async #finalizeRequest(request, perCallInterceptor) {
|
|
627
|
+
async #finalizeRequest(request, perCallInterceptor, context) {
|
|
577
628
|
let finalized = request;
|
|
578
629
|
|
|
579
630
|
// JSON-encode plain-object and array bodies, exactly as swagger-client's
|
|
@@ -592,8 +643,8 @@ class OpenAPIOperationExecutor {
|
|
|
592
643
|
finalized.headers[headerName] = value.replace(/\n+/g, ' ');
|
|
593
644
|
}
|
|
594
645
|
});
|
|
595
|
-
finalized = (await this.#requestInterceptor?.(finalized)) ?? finalized;
|
|
596
|
-
finalized = (await perCallInterceptor?.(finalized)) ?? finalized;
|
|
646
|
+
finalized = (await this.#requestInterceptor?.(finalized, context)) ?? finalized;
|
|
647
|
+
finalized = (await perCallInterceptor?.(finalized, context)) ?? finalized;
|
|
597
648
|
|
|
598
649
|
// for multipart/form-data, remove the built content-type so the transport
|
|
599
650
|
// sets one carrying the correct boundary
|
|
@@ -25,6 +25,13 @@ var _SourceDescriptionsLocatorNormalizer = _interopRequireDefault(require("./Sou
|
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A source description as an Arazzo document declares it: its `name`, and the
|
|
30
|
+
* URI of the Arazzo document that declares it. Names are local to their
|
|
31
|
+
* document, so the pair identifies one source description across a run.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
|
|
28
35
|
/**
|
|
29
36
|
* Normalizes a step's OpenAPI operation locator to a canonical
|
|
30
37
|
* {@link OpenAPIOperationLocator} — the OpenAPI document and a JSON Pointer to
|
|
@@ -89,8 +96,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
89
96
|
* locate an operation in the acquired OpenAPI document.
|
|
90
97
|
*/
|
|
91
98
|
async normalizeOperationPath(operationPath, document, scope) {
|
|
99
|
+
let sourceName;
|
|
92
100
|
for (const expression of (0, _arazzoRuntimeExpression.extract)(operationPath) ?? []) {
|
|
93
101
|
const parsed = this.parseSourceDescriptionsExpression(expression);
|
|
102
|
+
// only the source whose url the path is built from names its document
|
|
103
|
+
if (parsed?.reference === 'url') sourceName ??= parsed.sourceName;
|
|
94
104
|
if (parsed !== undefined && document.resolveSourceDescriptionURI(parsed.sourceName) === undefined) {
|
|
95
105
|
throw new _ExecutionError.default(`operationPath "${operationPath}" names source description "${parsed.sourceName}", which the Arazzo document at "${document.uri}" does not define`, {
|
|
96
106
|
...scope,
|
|
@@ -139,7 +149,13 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
139
149
|
}
|
|
140
150
|
return {
|
|
141
151
|
document: source,
|
|
142
|
-
jsonPointer
|
|
152
|
+
jsonPointer,
|
|
153
|
+
...(sourceName === undefined ? {} : {
|
|
154
|
+
sourceDescription: {
|
|
155
|
+
name: sourceName,
|
|
156
|
+
documentURI: document.uri
|
|
157
|
+
}
|
|
158
|
+
})
|
|
143
159
|
};
|
|
144
160
|
}
|
|
145
161
|
async #resolveSourced(expression, document, scope) {
|
|
@@ -164,7 +180,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
164
180
|
}
|
|
165
181
|
return {
|
|
166
182
|
document: openapiDocument,
|
|
167
|
-
jsonPointer
|
|
183
|
+
jsonPointer,
|
|
184
|
+
sourceDescription: {
|
|
185
|
+
name: sourceName,
|
|
186
|
+
documentURI: document.uri
|
|
187
|
+
}
|
|
168
188
|
};
|
|
169
189
|
}
|
|
170
190
|
|
|
@@ -181,7 +201,10 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
181
201
|
* until the first OpenAPI source is reached.
|
|
182
202
|
*/
|
|
183
203
|
async #resolvePlainOperationId(operationId, document, scope) {
|
|
184
|
-
for (const
|
|
204
|
+
for (const [name, {
|
|
205
|
+
uri
|
|
206
|
+
}] of document.sourceDescriptionIndex) {
|
|
207
|
+
if (uri === undefined) continue;
|
|
185
208
|
const source = await this.registry.acquire(uri);
|
|
186
209
|
if (!_OpenAPIDocument.default.is(source)) continue;
|
|
187
210
|
const jsonPointer = source.operationIndex.get(operationId);
|
|
@@ -193,7 +216,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
193
216
|
}
|
|
194
217
|
return {
|
|
195
218
|
document: source,
|
|
196
|
-
jsonPointer
|
|
219
|
+
jsonPointer,
|
|
220
|
+
sourceDescription: {
|
|
221
|
+
name,
|
|
222
|
+
documentURI: document.uri
|
|
223
|
+
}
|
|
197
224
|
};
|
|
198
225
|
}
|
|
199
226
|
|
|
@@ -17,6 +17,12 @@ import SourceDescriptionsLocatorNormalizer from "./SourceDescriptionsLocatorNorm
|
|
|
17
17
|
* single canonical form.
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* A source description as an Arazzo document declares it: its `name`, and the
|
|
22
|
+
* URI of the Arazzo document that declares it. Names are local to their
|
|
23
|
+
* document, so the pair identifies one source description across a run.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
20
26
|
/**
|
|
21
27
|
* Normalizes a step's OpenAPI operation locator to a canonical
|
|
22
28
|
* {@link OpenAPIOperationLocator} — the OpenAPI document and a JSON Pointer to
|
|
@@ -81,8 +87,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
81
87
|
* locate an operation in the acquired OpenAPI document.
|
|
82
88
|
*/
|
|
83
89
|
async normalizeOperationPath(operationPath, document, scope) {
|
|
90
|
+
let sourceName;
|
|
84
91
|
for (const expression of extract(operationPath) ?? []) {
|
|
85
92
|
const parsed = this.parseSourceDescriptionsExpression(expression);
|
|
93
|
+
// only the source whose url the path is built from names its document
|
|
94
|
+
if (parsed?.reference === 'url') sourceName ??= parsed.sourceName;
|
|
86
95
|
if (parsed !== undefined && document.resolveSourceDescriptionURI(parsed.sourceName) === undefined) {
|
|
87
96
|
throw new ExecutionError(`operationPath "${operationPath}" names source description "${parsed.sourceName}", which the Arazzo document at "${document.uri}" does not define`, {
|
|
88
97
|
...scope,
|
|
@@ -131,7 +140,13 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
131
140
|
}
|
|
132
141
|
return {
|
|
133
142
|
document: source,
|
|
134
|
-
jsonPointer
|
|
143
|
+
jsonPointer,
|
|
144
|
+
...(sourceName === undefined ? {} : {
|
|
145
|
+
sourceDescription: {
|
|
146
|
+
name: sourceName,
|
|
147
|
+
documentURI: document.uri
|
|
148
|
+
}
|
|
149
|
+
})
|
|
135
150
|
};
|
|
136
151
|
}
|
|
137
152
|
async #resolveSourced(expression, document, scope) {
|
|
@@ -156,7 +171,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
156
171
|
}
|
|
157
172
|
return {
|
|
158
173
|
document: openapiDocument,
|
|
159
|
-
jsonPointer
|
|
174
|
+
jsonPointer,
|
|
175
|
+
sourceDescription: {
|
|
176
|
+
name: sourceName,
|
|
177
|
+
documentURI: document.uri
|
|
178
|
+
}
|
|
160
179
|
};
|
|
161
180
|
}
|
|
162
181
|
|
|
@@ -173,7 +192,10 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
173
192
|
* until the first OpenAPI source is reached.
|
|
174
193
|
*/
|
|
175
194
|
async #resolvePlainOperationId(operationId, document, scope) {
|
|
176
|
-
for (const
|
|
195
|
+
for (const [name, {
|
|
196
|
+
uri
|
|
197
|
+
}] of document.sourceDescriptionIndex) {
|
|
198
|
+
if (uri === undefined) continue;
|
|
177
199
|
const source = await this.registry.acquire(uri);
|
|
178
200
|
if (!OpenAPIDocument.is(source)) continue;
|
|
179
201
|
const jsonPointer = source.operationIndex.get(operationId);
|
|
@@ -185,7 +207,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
185
207
|
}
|
|
186
208
|
return {
|
|
187
209
|
document: source,
|
|
188
|
-
jsonPointer
|
|
210
|
+
jsonPointer,
|
|
211
|
+
sourceDescription: {
|
|
212
|
+
name,
|
|
213
|
+
documentURI: document.uri
|
|
214
|
+
}
|
|
189
215
|
};
|
|
190
216
|
}
|
|
191
217
|
|
|
@@ -195,15 +195,17 @@ class StepExecutor {
|
|
|
195
195
|
const signal = (0, _abort.readAbortSignal)(operationOptions);
|
|
196
196
|
(0, _abort.throwIfAborted)(signal, scope);
|
|
197
197
|
|
|
198
|
-
// the Arazzo-derived parameters
|
|
199
|
-
// executeOptions bag so they take precedence over it. the
|
|
200
|
-
// then forces the operation target on top of this
|
|
198
|
+
// the Arazzo-derived parameters, request body and step identity are spread
|
|
199
|
+
// after the opaque executeOptions bag so they take precedence over it. the
|
|
200
|
+
// operation executor then forces the operation target on top of this
|
|
201
|
+
// before executing.
|
|
201
202
|
let response;
|
|
202
203
|
try {
|
|
203
204
|
response = await this.#operationExecutor.execute(locator, {
|
|
204
205
|
...operationOptions,
|
|
205
206
|
parameters,
|
|
206
|
-
...this.#requestBodyOptions(requestBody)
|
|
207
|
+
...this.#requestBodyOptions(requestBody),
|
|
208
|
+
step: scope
|
|
207
209
|
});
|
|
208
210
|
} catch (error) {
|
|
209
211
|
// a transport that honors the signal rejects the request it was told to
|
|
@@ -188,15 +188,17 @@ class StepExecutor {
|
|
|
188
188
|
const signal = readAbortSignal(operationOptions);
|
|
189
189
|
throwIfAborted(signal, scope);
|
|
190
190
|
|
|
191
|
-
// the Arazzo-derived parameters
|
|
192
|
-
// executeOptions bag so they take precedence over it. the
|
|
193
|
-
// then forces the operation target on top of this
|
|
191
|
+
// the Arazzo-derived parameters, request body and step identity are spread
|
|
192
|
+
// after the opaque executeOptions bag so they take precedence over it. the
|
|
193
|
+
// operation executor then forces the operation target on top of this
|
|
194
|
+
// before executing.
|
|
194
195
|
let response;
|
|
195
196
|
try {
|
|
196
197
|
response = await this.#operationExecutor.execute(locator, {
|
|
197
198
|
...operationOptions,
|
|
198
199
|
parameters,
|
|
199
|
-
...this.#requestBodyOptions(requestBody)
|
|
200
|
+
...this.#requestBodyOptions(requestBody),
|
|
201
|
+
step: scope
|
|
200
202
|
});
|
|
201
203
|
} catch (error) {
|
|
202
204
|
// a transport that honors the signal rejects the request it was told to
|
package/types/runner.d.ts
CHANGED
|
@@ -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
|