@usearazzo/runner 1.0.1-alpha.32 → 1.0.1-alpha.34
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 +29 -0
- package/README.md +10 -1
- package/dist/arazzo-runner.browser.js +1789 -403
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +18 -17
- package/src/ArazzoRunner.cjs +26 -3
- package/src/ArazzoRunner.mjs +26 -3
- package/src/action/ActionResolver.cjs +13 -12
- package/src/action/ActionResolver.mjs +13 -12
- package/src/client/OpenAPIOperationResponse.cjs +9 -0
- package/src/client/OpenAPIOperationResponse.mjs +9 -0
- package/src/criterion/CriterionEvaluator.cjs +13 -8
- package/src/criterion/CriterionEvaluator.mjs +13 -8
- package/src/criterion/SimpleCriterionEvaluator.cjs +5 -3
- package/src/criterion/SimpleCriterionEvaluator.mjs +6 -4
- package/src/document/APIDocument.cjs +53 -0
- package/src/document/APIDocument.mjs +53 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +66 -6
- package/src/executor/OpenAPIOperationExecutor.mjs +66 -6
- package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +1 -1
- package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +1 -1
- package/src/executor/StepExecutor.cjs +34 -15
- package/src/executor/StepExecutor.mjs +34 -15
- package/src/executor/StepRetryRunner.cjs +5 -3
- package/src/executor/StepRetryRunner.mjs +5 -3
- package/src/executor/StepTransitionInterpreter.cjs +1 -1
- package/src/executor/StepTransitionInterpreter.mjs +1 -1
- package/src/executor/WorkflowCallStack.cjs +1 -1
- package/src/executor/WorkflowCallStack.mjs +1 -1
- package/src/executor/WorkflowExecutor.cjs +277 -61
- package/src/executor/WorkflowExecutor.mjs +277 -61
- package/src/expression/RuntimeExpressionEvaluator.cjs +52 -9
- package/src/expression/RuntimeExpressionEvaluator.mjs +52 -9
- package/src/index.cjs +7 -0
- package/src/index.mjs +2 -0
- package/src/observability/ArazzoRunnerEvent.cjs +5 -0
- package/src/observability/ArazzoRunnerEvent.mjs +1 -0
- package/src/observability/DocumentRegistryEvent.cjs +5 -0
- package/src/observability/DocumentRegistryEvent.mjs +1 -0
- package/src/observability/EventChannel.cjs +96 -0
- package/src/observability/EventChannel.mjs +91 -0
- package/src/observability/OpenAPIOperationEvent.cjs +5 -0
- package/src/observability/OpenAPIOperationEvent.mjs +1 -0
- package/src/observability/Redactor.cjs +213 -0
- package/src/observability/Redactor.mjs +208 -0
- package/src/observability/WorkflowExecutionEvent.cjs +5 -0
- package/src/observability/WorkflowExecutionEvent.mjs +1 -0
- package/src/registry/DocumentRegistry.cjs +57 -11
- package/src/registry/DocumentRegistry.mjs +57 -11
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +21 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +22 -1
- package/src/registry/providers/DocumentRegistryProvider.cjs +33 -1
- package/src/registry/providers/DocumentRegistryProvider.mjs +33 -1
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +28 -5
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +28 -5
- package/src/resolver/ArazzoValueResolver.cjs +6 -3
- package/src/resolver/ArazzoValueResolver.mjs +6 -3
- package/src/resolver/OpenAPIOperationParameterResolver.cjs +2 -2
- package/src/resolver/OpenAPIOperationParameterResolver.mjs +2 -2
- package/src/resolver/OutputResolver.cjs +10 -3
- package/src/resolver/OutputResolver.mjs +10 -3
- package/src/resolver/RequestBodyResolver.cjs +37 -17
- package/src/resolver/RequestBodyResolver.mjs +37 -17
- package/src/resolver/WorkflowParameterResolver.cjs +2 -2
- package/src/resolver/WorkflowParameterResolver.mjs +2 -2
- package/types/runner.d.ts +788 -41
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { toValue, toYAML } from '@speclynx/apidom-core';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A position in a document, as in the Language Server Protocol: a 0-based
|
|
5
|
+
* line, and a 0-based character offset within it in UTF-16 code units.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A range in a document, as in the Language Server Protocol: from `start` to
|
|
11
|
+
* `end`, the shape the validator's diagnostics use.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Where an element is written.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
3
20
|
/**
|
|
4
21
|
* Base document held by the document registry.
|
|
5
22
|
* @public
|
|
@@ -12,6 +29,42 @@ class APIDocument {
|
|
|
12
29
|
this.parseResult = parseResult;
|
|
13
30
|
}
|
|
14
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Where an element of this document, or one it references, is written, as
|
|
34
|
+
* the registry provider recorded it when it loaded the document: the
|
|
35
|
+
* document it came from (its `ref-origin`) when it came through a
|
|
36
|
+
* reference, and its JSON Pointer there.
|
|
37
|
+
*/
|
|
38
|
+
locationOf(element) {
|
|
39
|
+
const origin = toValue(element.meta.get('ref-origin'));
|
|
40
|
+
const jsonPointer = toValue(element.meta.get('json-pointer'));
|
|
41
|
+
const {
|
|
42
|
+
startLine,
|
|
43
|
+
startCharacter,
|
|
44
|
+
endLine,
|
|
45
|
+
endCharacter
|
|
46
|
+
} = element;
|
|
47
|
+
return {
|
|
48
|
+
uri: typeof origin === 'string' ? origin : this.uri,
|
|
49
|
+
...(typeof jsonPointer === 'string' && {
|
|
50
|
+
jsonPointer
|
|
51
|
+
}),
|
|
52
|
+
// a source-mapped parse positions every element fully, any other none
|
|
53
|
+
...(startLine !== undefined && {
|
|
54
|
+
range: {
|
|
55
|
+
start: {
|
|
56
|
+
line: startLine,
|
|
57
|
+
character: startCharacter
|
|
58
|
+
},
|
|
59
|
+
end: {
|
|
60
|
+
line: endLine,
|
|
61
|
+
character: endCharacter
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
15
68
|
/**
|
|
16
69
|
* Returns a JSON-serializable representation of the document's API element.
|
|
17
70
|
* Compatible with JSON.stringify() — JSON.stringify(doc) produces correct output.
|
|
@@ -21,6 +21,7 @@ var _OpenAPIOperationExtractor = _interopRequireDefault(require("../extractor/Op
|
|
|
21
21
|
var _OpenAPIOperationNormalizer = _interopRequireDefault(require("../normalizer/OpenAPIOperationNormalizer.cjs"));
|
|
22
22
|
var _OpenAPIDocumentAssembler = _interopRequireDefault(require("../assembler/OpenAPIDocumentAssembler.cjs"));
|
|
23
23
|
var _ClientError = _interopRequireDefault(require("../errors/ClientError.cjs"));
|
|
24
|
+
var _EventChannel = _interopRequireDefault(require("../observability/EventChannel.cjs"));
|
|
24
25
|
// @ts-expect-error vendored swagger-client bundle has no type declarations
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -169,6 +170,8 @@ class OpenAPIOperationExecutor {
|
|
|
169
170
|
#operationExtractor;
|
|
170
171
|
#operationNormalizer;
|
|
171
172
|
#documentAssembler;
|
|
173
|
+
#captureBodies;
|
|
174
|
+
#events;
|
|
172
175
|
constructor(options = {}) {
|
|
173
176
|
this.#httpClient = options.httpClient ?? _HTTPClientFetch.default;
|
|
174
177
|
this.#requestInterceptor = options.requestInterceptor;
|
|
@@ -176,6 +179,11 @@ class OpenAPIOperationExecutor {
|
|
|
176
179
|
this.#operationExtractor = options.operationExtractor ?? new _OpenAPIOperationExtractor.default();
|
|
177
180
|
this.#operationNormalizer = options.operationNormalizer ?? new _OpenAPIOperationNormalizer.default();
|
|
178
181
|
this.#documentAssembler = options.documentAssembler ?? new _OpenAPIDocumentAssembler.default();
|
|
182
|
+
this.#events = _EventChannel.default.open({
|
|
183
|
+
observer: options.observer,
|
|
184
|
+
now: options.now
|
|
185
|
+
});
|
|
186
|
+
this.#captureBodies = options.captureBodies ?? false;
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
/**
|
|
@@ -196,17 +204,19 @@ class OpenAPIOperationExecutor {
|
|
|
196
204
|
// the legacy id (`{method}-{path}`) matches regardless of an explicit
|
|
197
205
|
// `operationId` in the assembled document
|
|
198
206
|
const operationId = (0, _swaggerClient.idFromPathMethodLegacy)((0, _apidomCore.toValue)(operation.meta.get('path')), (0, _apidomCore.toValue)(operation.meta.get('http-method')));
|
|
199
|
-
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
200
|
-
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
201
|
-
|
|
202
207
|
// the interceptor and step are consumed here, the target always comes from
|
|
203
208
|
// the locator, and the transport is the httpClient, so none of these
|
|
204
209
|
// reach buildRequest
|
|
205
210
|
const {
|
|
206
211
|
requestInterceptor,
|
|
207
|
-
step
|
|
212
|
+
step,
|
|
213
|
+
runId
|
|
208
214
|
} = executeOptions;
|
|
209
|
-
|
|
215
|
+
// the operation as extracted from its own document, before normalizing
|
|
216
|
+
// copies it, carries where it is written; located once, and only for an
|
|
217
|
+
// observer.
|
|
218
|
+
let located;
|
|
219
|
+
const location = () => located ??= locator.document.locationOf(operation);
|
|
210
220
|
const declaredOperationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
211
221
|
const context = {
|
|
212
222
|
operation: {
|
|
@@ -229,6 +239,27 @@ class OpenAPIOperationExecutor {
|
|
|
229
239
|
}
|
|
230
240
|
})
|
|
231
241
|
};
|
|
242
|
+
this.#events?.emit({
|
|
243
|
+
type: 'openapi-operation-normalize-start',
|
|
244
|
+
...context,
|
|
245
|
+
runId,
|
|
246
|
+
location: location()
|
|
247
|
+
});
|
|
248
|
+
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
249
|
+
this.#events?.emit({
|
|
250
|
+
type: 'openapi-operation-normalize-settled',
|
|
251
|
+
...context,
|
|
252
|
+
runId,
|
|
253
|
+
location: location()
|
|
254
|
+
});
|
|
255
|
+
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
256
|
+
this.#events?.emit({
|
|
257
|
+
type: 'openapi-operation-assembled',
|
|
258
|
+
...context,
|
|
259
|
+
runId,
|
|
260
|
+
location: location()
|
|
261
|
+
});
|
|
262
|
+
const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'runId', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
232
263
|
|
|
233
264
|
// each step derives the next options rather than editing in place
|
|
234
265
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -272,6 +303,20 @@ class OpenAPIOperationExecutor {
|
|
|
272
303
|
},
|
|
273
304
|
body: request.body
|
|
274
305
|
};
|
|
306
|
+
this.#events?.emit({
|
|
307
|
+
type: 'openapi-operation-request-start',
|
|
308
|
+
...context,
|
|
309
|
+
runId,
|
|
310
|
+
location: location(),
|
|
311
|
+
request: {
|
|
312
|
+
method: request.method,
|
|
313
|
+
url: request.url,
|
|
314
|
+
headers: request.headers,
|
|
315
|
+
...(this.#captureBodies ? {
|
|
316
|
+
body: request.body
|
|
317
|
+
} : {})
|
|
318
|
+
}
|
|
319
|
+
});
|
|
275
320
|
let rawResponse;
|
|
276
321
|
try {
|
|
277
322
|
rawResponse = await this.#httpClient(request);
|
|
@@ -281,7 +326,22 @@ class OpenAPIOperationExecutor {
|
|
|
281
326
|
cause: error
|
|
282
327
|
});
|
|
283
328
|
}
|
|
284
|
-
|
|
329
|
+
const response = await this.#responseNormalizer.normalize(rawResponse, requestInfo);
|
|
330
|
+
this.#events?.emit({
|
|
331
|
+
type: 'openapi-operation-request-settled',
|
|
332
|
+
...context,
|
|
333
|
+
runId,
|
|
334
|
+
location: location(),
|
|
335
|
+
response: {
|
|
336
|
+
status: response.status,
|
|
337
|
+
headers: response.headers,
|
|
338
|
+
size: response.size,
|
|
339
|
+
...(this.#captureBodies ? {
|
|
340
|
+
body: response.body
|
|
341
|
+
} : {})
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
return response;
|
|
285
345
|
}
|
|
286
346
|
|
|
287
347
|
/**
|
|
@@ -16,6 +16,7 @@ import OpenAPIOperationExtractor from "../extractor/OpenAPIOperationExtractor.mj
|
|
|
16
16
|
import OpenAPIOperationNormalizer from "../normalizer/OpenAPIOperationNormalizer.mjs";
|
|
17
17
|
import OpenAPIDocumentAssembler from "../assembler/OpenAPIDocumentAssembler.mjs";
|
|
18
18
|
import ClientError from "../errors/ClientError.mjs";
|
|
19
|
+
import EventChannel from "../observability/EventChannel.mjs";
|
|
19
20
|
/**
|
|
20
21
|
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
21
22
|
* of the workflow it belongs to when the caller names one (step ids are only
|
|
@@ -157,6 +158,8 @@ class OpenAPIOperationExecutor {
|
|
|
157
158
|
#operationExtractor;
|
|
158
159
|
#operationNormalizer;
|
|
159
160
|
#documentAssembler;
|
|
161
|
+
#captureBodies;
|
|
162
|
+
#events;
|
|
160
163
|
constructor(options = {}) {
|
|
161
164
|
this.#httpClient = options.httpClient ?? httpClientFetch;
|
|
162
165
|
this.#requestInterceptor = options.requestInterceptor;
|
|
@@ -164,6 +167,11 @@ class OpenAPIOperationExecutor {
|
|
|
164
167
|
this.#operationExtractor = options.operationExtractor ?? new OpenAPIOperationExtractor();
|
|
165
168
|
this.#operationNormalizer = options.operationNormalizer ?? new OpenAPIOperationNormalizer();
|
|
166
169
|
this.#documentAssembler = options.documentAssembler ?? new OpenAPIDocumentAssembler();
|
|
170
|
+
this.#events = EventChannel.open({
|
|
171
|
+
observer: options.observer,
|
|
172
|
+
now: options.now
|
|
173
|
+
});
|
|
174
|
+
this.#captureBodies = options.captureBodies ?? false;
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
/**
|
|
@@ -184,17 +192,19 @@ class OpenAPIOperationExecutor {
|
|
|
184
192
|
// the legacy id (`{method}-{path}`) matches regardless of an explicit
|
|
185
193
|
// `operationId` in the assembled document
|
|
186
194
|
const operationId = idFromPathMethodLegacy(toValue(operation.meta.get('path')), toValue(operation.meta.get('http-method')));
|
|
187
|
-
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
188
|
-
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
189
|
-
|
|
190
195
|
// the interceptor and step are consumed here, the target always comes from
|
|
191
196
|
// the locator, and the transport is the httpClient, so none of these
|
|
192
197
|
// reach buildRequest
|
|
193
198
|
const {
|
|
194
199
|
requestInterceptor,
|
|
195
|
-
step
|
|
200
|
+
step,
|
|
201
|
+
runId
|
|
196
202
|
} = executeOptions;
|
|
197
|
-
|
|
203
|
+
// the operation as extracted from its own document, before normalizing
|
|
204
|
+
// copies it, carries where it is written; located once, and only for an
|
|
205
|
+
// observer.
|
|
206
|
+
let located;
|
|
207
|
+
const location = () => located ??= locator.document.locationOf(operation);
|
|
198
208
|
const declaredOperationId = toValue(operation.operationId);
|
|
199
209
|
const context = {
|
|
200
210
|
operation: {
|
|
@@ -217,6 +227,27 @@ class OpenAPIOperationExecutor {
|
|
|
217
227
|
}
|
|
218
228
|
})
|
|
219
229
|
};
|
|
230
|
+
this.#events?.emit({
|
|
231
|
+
type: 'openapi-operation-normalize-start',
|
|
232
|
+
...context,
|
|
233
|
+
runId,
|
|
234
|
+
location: location()
|
|
235
|
+
});
|
|
236
|
+
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
237
|
+
this.#events?.emit({
|
|
238
|
+
type: 'openapi-operation-normalize-settled',
|
|
239
|
+
...context,
|
|
240
|
+
runId,
|
|
241
|
+
location: location()
|
|
242
|
+
});
|
|
243
|
+
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
244
|
+
this.#events?.emit({
|
|
245
|
+
type: 'openapi-operation-assembled',
|
|
246
|
+
...context,
|
|
247
|
+
runId,
|
|
248
|
+
location: location()
|
|
249
|
+
});
|
|
250
|
+
const rest = omit(['requestInterceptor', 'step', 'runId', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
220
251
|
|
|
221
252
|
// each step derives the next options rather than editing in place
|
|
222
253
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -260,6 +291,20 @@ class OpenAPIOperationExecutor {
|
|
|
260
291
|
},
|
|
261
292
|
body: request.body
|
|
262
293
|
};
|
|
294
|
+
this.#events?.emit({
|
|
295
|
+
type: 'openapi-operation-request-start',
|
|
296
|
+
...context,
|
|
297
|
+
runId,
|
|
298
|
+
location: location(),
|
|
299
|
+
request: {
|
|
300
|
+
method: request.method,
|
|
301
|
+
url: request.url,
|
|
302
|
+
headers: request.headers,
|
|
303
|
+
...(this.#captureBodies ? {
|
|
304
|
+
body: request.body
|
|
305
|
+
} : {})
|
|
306
|
+
}
|
|
307
|
+
});
|
|
263
308
|
let rawResponse;
|
|
264
309
|
try {
|
|
265
310
|
rawResponse = await this.#httpClient(request);
|
|
@@ -269,7 +314,22 @@ class OpenAPIOperationExecutor {
|
|
|
269
314
|
cause: error
|
|
270
315
|
});
|
|
271
316
|
}
|
|
272
|
-
|
|
317
|
+
const response = await this.#responseNormalizer.normalize(rawResponse, requestInfo);
|
|
318
|
+
this.#events?.emit({
|
|
319
|
+
type: 'openapi-operation-request-settled',
|
|
320
|
+
...context,
|
|
321
|
+
runId,
|
|
322
|
+
location: location(),
|
|
323
|
+
response: {
|
|
324
|
+
status: response.status,
|
|
325
|
+
headers: response.headers,
|
|
326
|
+
size: response.size,
|
|
327
|
+
...(this.#captureBodies ? {
|
|
328
|
+
body: response.body
|
|
329
|
+
} : {})
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
return response;
|
|
273
333
|
}
|
|
274
334
|
|
|
275
335
|
/**
|
|
@@ -113,7 +113,7 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
113
113
|
document,
|
|
114
114
|
registry: this.registry
|
|
115
115
|
});
|
|
116
|
-
const uriReference = evaluator.interpolate(operationPath);
|
|
116
|
+
const uriReference = await evaluator.interpolate(operationPath);
|
|
117
117
|
const documentURI = _empty.url.sanitize(_empty.url.stripHash(uriReference));
|
|
118
118
|
if (documentURI === '') {
|
|
119
119
|
throw new _ExecutionError.default(`operationPath "${operationPath}" does not resolve to a source description URL`, {
|
|
@@ -104,7 +104,7 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
104
104
|
document,
|
|
105
105
|
registry: this.registry
|
|
106
106
|
});
|
|
107
|
-
const uriReference = evaluator.interpolate(operationPath);
|
|
107
|
+
const uriReference = await evaluator.interpolate(operationPath);
|
|
108
108
|
const documentURI = url.sanitize(url.stripHash(uriReference));
|
|
109
109
|
if (documentURI === '') {
|
|
110
110
|
throw new ExecutionError(`operationPath "${operationPath}" does not resolve to a source description URL`, {
|
|
@@ -188,8 +188,8 @@ class StepExecutor {
|
|
|
188
188
|
// keyed by '{in}.{name}' rather than bare name, so two parameters that
|
|
189
189
|
// legally differ only in their location each reach their own place.
|
|
190
190
|
const preContext = state.toContext();
|
|
191
|
-
const parameters = this.#parameterResolver.resolve(step.parameters, expression => this.#evaluate(preContext, expression), scope);
|
|
192
|
-
const requestBody = this.#requestBodyResolver.resolve(step.requestBody, expression => this.#evaluate(preContext, expression), scope);
|
|
191
|
+
const parameters = await this.#parameterResolver.resolve(step.parameters, expression => this.#evaluate(preContext, expression), scope);
|
|
192
|
+
const requestBody = await this.#requestBodyResolver.resolve(step.requestBody, expression => this.#evaluate(preContext, expression), scope);
|
|
193
193
|
|
|
194
194
|
// checked here rather than on entry: locating the operation and resolving
|
|
195
195
|
// the expressions above are awaited, so a run cancelled during them would
|
|
@@ -225,13 +225,13 @@ class StepExecutor {
|
|
|
225
225
|
// evaluate criteria, outputs, and the next action against the post-request
|
|
226
226
|
// context (with $request / $url / $method and $response / $statusCode).
|
|
227
227
|
const postContext = state.toContext(this.#requestContext(response), this.#responseContext(response));
|
|
228
|
-
const successCriteria = this.evaluateCriteria(step, postContext, workflowId);
|
|
228
|
+
const successCriteria = await this.evaluateCriteria(step, postContext, workflowId);
|
|
229
229
|
const successful = successCriteria.every(criterion => criterion.met);
|
|
230
|
-
const outputs = this.#outputResolver.resolve(step.outputs, expression => this.#evaluate(postContext, expression), scope);
|
|
230
|
+
const outputs = await this.#outputResolver.resolve(step.outputs, expression => this.#evaluate(postContext, expression), scope);
|
|
231
231
|
const {
|
|
232
232
|
matchedActions,
|
|
233
233
|
actionCriteria
|
|
234
|
-
} = this.selectActions(step, successful, postContext, workflowId);
|
|
234
|
+
} = await this.selectActions(step, successful, postContext, workflowId);
|
|
235
235
|
return {
|
|
236
236
|
stepId,
|
|
237
237
|
response,
|
|
@@ -328,13 +328,18 @@ class StepExecutor {
|
|
|
328
328
|
* names the step's workflow on a thrown error, as for
|
|
329
329
|
* {@link StepExecutor.execute}.
|
|
330
330
|
*/
|
|
331
|
-
evaluateCriteria(step, context, workflowId) {
|
|
331
|
+
async evaluateCriteria(step, context, workflowId) {
|
|
332
332
|
this.assertSuccessCriteria(step, workflowId);
|
|
333
333
|
const criteria = step.successCriteria;
|
|
334
334
|
if (criteria === undefined) return [];
|
|
335
335
|
|
|
336
|
-
// assertSuccessCriteria above guarantees every entry is a Criterion Object
|
|
337
|
-
|
|
336
|
+
// assertSuccessCriteria above guarantees every entry is a Criterion Object.
|
|
337
|
+
// evaluated one after another, in list order, like the actions' criteria.
|
|
338
|
+
const records = [];
|
|
339
|
+
for (const criterion of [...criteria]) {
|
|
340
|
+
records.push(await this.#evaluateCriterion(criterion, context));
|
|
341
|
+
}
|
|
342
|
+
return records;
|
|
338
343
|
}
|
|
339
344
|
|
|
340
345
|
/**
|
|
@@ -360,11 +365,11 @@ class StepExecutor {
|
|
|
360
365
|
* `workflowId` names the step's workflow on a thrown error, as for
|
|
361
366
|
* {@link StepExecutor.execute}.
|
|
362
367
|
*/
|
|
363
|
-
selectActions(step, successful, context, workflowId) {
|
|
368
|
+
async selectActions(step, successful, context, workflowId) {
|
|
364
369
|
const actionCriteria = [];
|
|
365
|
-
const isCriterionMet = (criterion, action) => {
|
|
370
|
+
const isCriterionMet = async (criterion, action) => {
|
|
366
371
|
const record = {
|
|
367
|
-
...this.#evaluateCriterion(criterion, context),
|
|
372
|
+
...(await this.#evaluateCriterion(criterion, context)),
|
|
368
373
|
actionName: (0, _apidomCore.toValue)(action.name)
|
|
369
374
|
};
|
|
370
375
|
actionCriteria.push(record);
|
|
@@ -376,7 +381,7 @@ class StepExecutor {
|
|
|
376
381
|
}),
|
|
377
382
|
stepId: (0, _apidomCore.toValue)(step.stepId)
|
|
378
383
|
};
|
|
379
|
-
const matchedActions = successful ? this.#actionResolver.resolveOnSuccess(step.onSuccess, isCriterionMet, scope) : this.#actionResolver.resolveOnFailure(step.onFailure, isCriterionMet, scope);
|
|
384
|
+
const matchedActions = successful ? await this.#actionResolver.resolveOnSuccess(step.onSuccess, isCriterionMet, scope) : await this.#actionResolver.resolveOnFailure(step.onFailure, isCriterionMet, scope);
|
|
380
385
|
return {
|
|
381
386
|
matchedActions,
|
|
382
387
|
actionCriteria
|
|
@@ -410,20 +415,32 @@ class StepExecutor {
|
|
|
410
415
|
* condition that cannot be evaluated is unmet and records why; any other
|
|
411
416
|
* error propagates.
|
|
412
417
|
*/
|
|
413
|
-
#evaluateCriterion(criterion, context) {
|
|
418
|
+
async #evaluateCriterion(criterion, context) {
|
|
414
419
|
const condition = (0, _apidomCore.toValue)(criterion.condition);
|
|
420
|
+
const location = this.#document.locationOf(criterion);
|
|
421
|
+
const values = {};
|
|
422
|
+
const resolve = async expression => {
|
|
423
|
+
const value = await this.#evaluate(context, expression);
|
|
424
|
+
const wholeBody = expression === '$response.body' || expression === '$request.body';
|
|
425
|
+
values[expression] = wholeBody ? '[body]' : value;
|
|
426
|
+
return value;
|
|
427
|
+
};
|
|
415
428
|
try {
|
|
416
429
|
const {
|
|
417
430
|
met,
|
|
418
431
|
error
|
|
419
|
-
} = this.#criterionEvaluator.evaluate(criterion,
|
|
432
|
+
} = await this.#criterionEvaluator.evaluate(criterion, resolve);
|
|
420
433
|
if (error === undefined) return {
|
|
421
434
|
condition,
|
|
422
|
-
met
|
|
435
|
+
met,
|
|
436
|
+
values,
|
|
437
|
+
location
|
|
423
438
|
};
|
|
424
439
|
return {
|
|
425
440
|
condition,
|
|
426
441
|
met,
|
|
442
|
+
values,
|
|
443
|
+
location,
|
|
427
444
|
diagnostic: {
|
|
428
445
|
code: error.reason,
|
|
429
446
|
message: error.message
|
|
@@ -437,6 +454,8 @@ class StepExecutor {
|
|
|
437
454
|
return {
|
|
438
455
|
condition,
|
|
439
456
|
met: false,
|
|
457
|
+
values,
|
|
458
|
+
location,
|
|
440
459
|
diagnostic: {
|
|
441
460
|
code: error.reason,
|
|
442
461
|
message: error.message
|
|
@@ -181,8 +181,8 @@ class StepExecutor {
|
|
|
181
181
|
// keyed by '{in}.{name}' rather than bare name, so two parameters that
|
|
182
182
|
// legally differ only in their location each reach their own place.
|
|
183
183
|
const preContext = state.toContext();
|
|
184
|
-
const parameters = this.#parameterResolver.resolve(step.parameters, expression => this.#evaluate(preContext, expression), scope);
|
|
185
|
-
const requestBody = this.#requestBodyResolver.resolve(step.requestBody, expression => this.#evaluate(preContext, expression), scope);
|
|
184
|
+
const parameters = await this.#parameterResolver.resolve(step.parameters, expression => this.#evaluate(preContext, expression), scope);
|
|
185
|
+
const requestBody = await this.#requestBodyResolver.resolve(step.requestBody, expression => this.#evaluate(preContext, expression), scope);
|
|
186
186
|
|
|
187
187
|
// checked here rather than on entry: locating the operation and resolving
|
|
188
188
|
// the expressions above are awaited, so a run cancelled during them would
|
|
@@ -218,13 +218,13 @@ class StepExecutor {
|
|
|
218
218
|
// evaluate criteria, outputs, and the next action against the post-request
|
|
219
219
|
// context (with $request / $url / $method and $response / $statusCode).
|
|
220
220
|
const postContext = state.toContext(this.#requestContext(response), this.#responseContext(response));
|
|
221
|
-
const successCriteria = this.evaluateCriteria(step, postContext, workflowId);
|
|
221
|
+
const successCriteria = await this.evaluateCriteria(step, postContext, workflowId);
|
|
222
222
|
const successful = successCriteria.every(criterion => criterion.met);
|
|
223
|
-
const outputs = this.#outputResolver.resolve(step.outputs, expression => this.#evaluate(postContext, expression), scope);
|
|
223
|
+
const outputs = await this.#outputResolver.resolve(step.outputs, expression => this.#evaluate(postContext, expression), scope);
|
|
224
224
|
const {
|
|
225
225
|
matchedActions,
|
|
226
226
|
actionCriteria
|
|
227
|
-
} = this.selectActions(step, successful, postContext, workflowId);
|
|
227
|
+
} = await this.selectActions(step, successful, postContext, workflowId);
|
|
228
228
|
return {
|
|
229
229
|
stepId,
|
|
230
230
|
response,
|
|
@@ -321,13 +321,18 @@ class StepExecutor {
|
|
|
321
321
|
* names the step's workflow on a thrown error, as for
|
|
322
322
|
* {@link StepExecutor.execute}.
|
|
323
323
|
*/
|
|
324
|
-
evaluateCriteria(step, context, workflowId) {
|
|
324
|
+
async evaluateCriteria(step, context, workflowId) {
|
|
325
325
|
this.assertSuccessCriteria(step, workflowId);
|
|
326
326
|
const criteria = step.successCriteria;
|
|
327
327
|
if (criteria === undefined) return [];
|
|
328
328
|
|
|
329
|
-
// assertSuccessCriteria above guarantees every entry is a Criterion Object
|
|
330
|
-
|
|
329
|
+
// assertSuccessCriteria above guarantees every entry is a Criterion Object.
|
|
330
|
+
// evaluated one after another, in list order, like the actions' criteria.
|
|
331
|
+
const records = [];
|
|
332
|
+
for (const criterion of [...criteria]) {
|
|
333
|
+
records.push(await this.#evaluateCriterion(criterion, context));
|
|
334
|
+
}
|
|
335
|
+
return records;
|
|
331
336
|
}
|
|
332
337
|
|
|
333
338
|
/**
|
|
@@ -353,11 +358,11 @@ class StepExecutor {
|
|
|
353
358
|
* `workflowId` names the step's workflow on a thrown error, as for
|
|
354
359
|
* {@link StepExecutor.execute}.
|
|
355
360
|
*/
|
|
356
|
-
selectActions(step, successful, context, workflowId) {
|
|
361
|
+
async selectActions(step, successful, context, workflowId) {
|
|
357
362
|
const actionCriteria = [];
|
|
358
|
-
const isCriterionMet = (criterion, action) => {
|
|
363
|
+
const isCriterionMet = async (criterion, action) => {
|
|
359
364
|
const record = {
|
|
360
|
-
...this.#evaluateCriterion(criterion, context),
|
|
365
|
+
...(await this.#evaluateCriterion(criterion, context)),
|
|
361
366
|
actionName: toValue(action.name)
|
|
362
367
|
};
|
|
363
368
|
actionCriteria.push(record);
|
|
@@ -369,7 +374,7 @@ class StepExecutor {
|
|
|
369
374
|
}),
|
|
370
375
|
stepId: toValue(step.stepId)
|
|
371
376
|
};
|
|
372
|
-
const matchedActions = successful ? this.#actionResolver.resolveOnSuccess(step.onSuccess, isCriterionMet, scope) : this.#actionResolver.resolveOnFailure(step.onFailure, isCriterionMet, scope);
|
|
377
|
+
const matchedActions = successful ? await this.#actionResolver.resolveOnSuccess(step.onSuccess, isCriterionMet, scope) : await this.#actionResolver.resolveOnFailure(step.onFailure, isCriterionMet, scope);
|
|
373
378
|
return {
|
|
374
379
|
matchedActions,
|
|
375
380
|
actionCriteria
|
|
@@ -403,20 +408,32 @@ class StepExecutor {
|
|
|
403
408
|
* condition that cannot be evaluated is unmet and records why; any other
|
|
404
409
|
* error propagates.
|
|
405
410
|
*/
|
|
406
|
-
#evaluateCriterion(criterion, context) {
|
|
411
|
+
async #evaluateCriterion(criterion, context) {
|
|
407
412
|
const condition = toValue(criterion.condition);
|
|
413
|
+
const location = this.#document.locationOf(criterion);
|
|
414
|
+
const values = {};
|
|
415
|
+
const resolve = async expression => {
|
|
416
|
+
const value = await this.#evaluate(context, expression);
|
|
417
|
+
const wholeBody = expression === '$response.body' || expression === '$request.body';
|
|
418
|
+
values[expression] = wholeBody ? '[body]' : value;
|
|
419
|
+
return value;
|
|
420
|
+
};
|
|
408
421
|
try {
|
|
409
422
|
const {
|
|
410
423
|
met,
|
|
411
424
|
error
|
|
412
|
-
} = this.#criterionEvaluator.evaluate(criterion,
|
|
425
|
+
} = await this.#criterionEvaluator.evaluate(criterion, resolve);
|
|
413
426
|
if (error === undefined) return {
|
|
414
427
|
condition,
|
|
415
|
-
met
|
|
428
|
+
met,
|
|
429
|
+
values,
|
|
430
|
+
location
|
|
416
431
|
};
|
|
417
432
|
return {
|
|
418
433
|
condition,
|
|
419
434
|
met,
|
|
435
|
+
values,
|
|
436
|
+
location,
|
|
420
437
|
diagnostic: {
|
|
421
438
|
code: error.reason,
|
|
422
439
|
message: error.message
|
|
@@ -430,6 +447,8 @@ class StepExecutor {
|
|
|
430
447
|
return {
|
|
431
448
|
condition,
|
|
432
449
|
met: false,
|
|
450
|
+
values,
|
|
451
|
+
location,
|
|
433
452
|
diagnostic: {
|
|
434
453
|
code: error.reason,
|
|
435
454
|
message: error.message
|
|
@@ -100,7 +100,8 @@ class StepRetryRunner {
|
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Runs `attempt` until the step succeeds, a terminal failure action is reached,
|
|
103
|
-
* or its retries are exhausted.
|
|
103
|
+
* or its retries are exhausted. Each call is given its attempt number,
|
|
104
|
+
* starting at 1.
|
|
104
105
|
*/
|
|
105
106
|
async run(attempt, context) {
|
|
106
107
|
// attempts already spent on each retry action, keyed by the action element.
|
|
@@ -114,7 +115,7 @@ class StepRetryRunner {
|
|
|
114
115
|
const retriesSpent = new Map();
|
|
115
116
|
let attempts = 0;
|
|
116
117
|
for (;;) {
|
|
117
|
-
const outcome = await attempt();
|
|
118
|
+
const outcome = await attempt(attempts + 1);
|
|
118
119
|
attempts += 1;
|
|
119
120
|
if (outcome.successful) {
|
|
120
121
|
return {
|
|
@@ -148,8 +149,9 @@ class StepRetryRunner {
|
|
|
148
149
|
// sleep(0) for immediate retries, and never hand a custom sleep a
|
|
149
150
|
// zero/negative/NaN value.
|
|
150
151
|
const delayMs = this.#retryAfterMs(action);
|
|
152
|
+
context.onRetry?.(action, delayMs, attempts);
|
|
151
153
|
if (delayMs > 0) await this.#sleep(delayMs, context.signal);
|
|
152
|
-
if (runReference !== undefined) await runReference(action, outcome);
|
|
154
|
+
if (runReference !== undefined) await runReference(action, outcome, attempts);
|
|
153
155
|
fired = true;
|
|
154
156
|
break;
|
|
155
157
|
}
|
|
@@ -90,7 +90,8 @@ class StepRetryRunner {
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Runs `attempt` until the step succeeds, a terminal failure action is reached,
|
|
93
|
-
* or its retries are exhausted.
|
|
93
|
+
* or its retries are exhausted. Each call is given its attempt number,
|
|
94
|
+
* starting at 1.
|
|
94
95
|
*/
|
|
95
96
|
async run(attempt, context) {
|
|
96
97
|
// attempts already spent on each retry action, keyed by the action element.
|
|
@@ -104,7 +105,7 @@ class StepRetryRunner {
|
|
|
104
105
|
const retriesSpent = new Map();
|
|
105
106
|
let attempts = 0;
|
|
106
107
|
for (;;) {
|
|
107
|
-
const outcome = await attempt();
|
|
108
|
+
const outcome = await attempt(attempts + 1);
|
|
108
109
|
attempts += 1;
|
|
109
110
|
if (outcome.successful) {
|
|
110
111
|
return {
|
|
@@ -138,8 +139,9 @@ class StepRetryRunner {
|
|
|
138
139
|
// sleep(0) for immediate retries, and never hand a custom sleep a
|
|
139
140
|
// zero/negative/NaN value.
|
|
140
141
|
const delayMs = this.#retryAfterMs(action);
|
|
142
|
+
context.onRetry?.(action, delayMs, attempts);
|
|
141
143
|
if (delayMs > 0) await this.#sleep(delayMs, context.signal);
|
|
142
|
-
if (runReference !== undefined) await runReference(action, outcome);
|
|
144
|
+
if (runReference !== undefined) await runReference(action, outcome, attempts);
|
|
143
145
|
fired = true;
|
|
144
146
|
break;
|
|
145
147
|
}
|
|
@@ -36,7 +36,7 @@ function actionTargets(action) {
|
|
|
36
36
|
* workflow; `transfer` hands control one-way to another workflow, which the
|
|
37
37
|
* caller's run then ends on; `end` stops the run with `status: ended`; `break`
|
|
38
38
|
* stops with `status: failed` (the failure default).
|
|
39
|
-
* @
|
|
39
|
+
* @public
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -28,7 +28,7 @@ export function actionTargets(action) {
|
|
|
28
28
|
* workflow; `transfer` hands control one-way to another workflow, which the
|
|
29
29
|
* caller's run then ends on; `end` stops the run with `status: ended`; `break`
|
|
30
30
|
* stops with `status: failed` (the failure default).
|
|
31
|
-
* @
|
|
31
|
+
* @public
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -15,7 +15,7 @@ var _ExecutionError = _interopRequireDefault(require("../errors/ExecutionError.c
|
|
|
15
15
|
* reference — or a `goto`'s one-way transfer to a `workflowId` — is a call
|
|
16
16
|
* cycle. `retry` and `goto` are grouped with `step` for that classification, not
|
|
17
17
|
* `dependsOn`: each is a call the current step makes, not a stated precondition.
|
|
18
|
-
* @
|
|
18
|
+
* @public
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -8,7 +8,7 @@ import ExecutionError from "../errors/ExecutionError.mjs";
|
|
|
8
8
|
* reference — or a `goto`'s one-way transfer to a `workflowId` — is a call
|
|
9
9
|
* cycle. `retry` and `goto` are grouped with `step` for that classification, not
|
|
10
10
|
* `dependsOn`: each is a call the current step makes, not a stated precondition.
|
|
11
|
-
* @
|
|
11
|
+
* @public
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* One workflow invocation in progress. Its identity is the (documentURI,
|