@usearazzo/runner 1.0.1-alpha.33 → 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 +8 -0
- package/README.md +10 -1
- package/dist/arazzo-runner.browser.js +1112 -231
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +16 -15
- package/src/ArazzoRunner.cjs +26 -3
- package/src/ArazzoRunner.mjs +26 -3
- package/src/client/OpenAPIOperationResponse.cjs +9 -0
- package/src/client/OpenAPIOperationResponse.mjs +9 -0
- 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/StepExecutor.cjs +16 -2
- package/src/executor/StepExecutor.mjs +16 -2
- 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 +269 -53
- package/src/executor/WorkflowExecutor.mjs +269 -53
- 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 +22 -3
- package/src/registry/DocumentRegistry.mjs +22 -3
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
- package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
- package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
- package/types/runner.d.ts +705 -5
|
@@ -7,6 +7,7 @@ import DocumentLoadError from "../errors/DocumentLoadError.mjs";
|
|
|
7
7
|
import InvalidEntryDocumentError from "../errors/InvalidEntryDocumentError.mjs";
|
|
8
8
|
import UnmatchedProviderError from "../errors/UnmatchedProviderError.mjs";
|
|
9
9
|
import * as constants from "../constants.mjs";
|
|
10
|
+
import EventChannel from "../observability/EventChannel.mjs";
|
|
10
11
|
/**
|
|
11
12
|
* Options for the DocumentRegistry.
|
|
12
13
|
* @public
|
|
@@ -23,8 +24,13 @@ class DocumentRegistry {
|
|
|
23
24
|
#documents = new Map();
|
|
24
25
|
#loading = new Map();
|
|
25
26
|
#providers;
|
|
27
|
+
#events;
|
|
26
28
|
constructor(options = {}) {
|
|
27
29
|
this.#providers = options.providers ?? [new ArazzoDocumentRegistryProvider(), new OpenAPIDocumentRegistryProvider()];
|
|
30
|
+
this.#events = EventChannel.open({
|
|
31
|
+
observer: options.observer,
|
|
32
|
+
now: options.now
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
/**
|
|
@@ -70,12 +76,15 @@ class DocumentRegistry {
|
|
|
70
76
|
* caches it.
|
|
71
77
|
*/
|
|
72
78
|
async #load(canonicalURI) {
|
|
79
|
+
this.#events?.emit({
|
|
80
|
+
type: 'document-load-start',
|
|
81
|
+
uri: canonicalURI
|
|
82
|
+
});
|
|
73
83
|
for (const provider of this.#providers) {
|
|
84
|
+
let document;
|
|
74
85
|
try {
|
|
75
86
|
if (await provider.canProvide(canonicalURI)) {
|
|
76
|
-
|
|
77
|
-
this.#set(canonicalURI, document);
|
|
78
|
-
return document;
|
|
87
|
+
document = await provider.provide(canonicalURI);
|
|
79
88
|
}
|
|
80
89
|
} catch (error) {
|
|
81
90
|
// a document that cannot be read or loaded fails in ApiDOM or the parser;
|
|
@@ -86,6 +95,16 @@ class DocumentRegistry {
|
|
|
86
95
|
cause: error
|
|
87
96
|
});
|
|
88
97
|
}
|
|
98
|
+
if (document !== undefined) {
|
|
99
|
+
// outside the try, so an observer's own error is not a failed load, and
|
|
100
|
+
// before caching, so a run it aborts leaves no half-registered document.
|
|
101
|
+
this.#events?.emit({
|
|
102
|
+
type: 'document-load-settled',
|
|
103
|
+
uri: canonicalURI
|
|
104
|
+
});
|
|
105
|
+
this.#set(canonicalURI, document);
|
|
106
|
+
return document;
|
|
107
|
+
}
|
|
89
108
|
}
|
|
90
109
|
throw new UnmatchedProviderError(`No provider can handle the document at "${canonicalURI}"`, {
|
|
91
110
|
uri: canonicalURI
|
|
@@ -86,11 +86,13 @@ class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
|
|
|
86
86
|
*/
|
|
87
87
|
async provide(uri) {
|
|
88
88
|
const parseResult = await (0, _parser.parseArazzo)(uri, this.#buildParseOptions());
|
|
89
|
+
this.assertParsed(uri, parseResult);
|
|
89
90
|
const {
|
|
90
91
|
workflowIndex,
|
|
91
92
|
stepIndex,
|
|
92
93
|
sourceDescriptionIndex
|
|
93
94
|
} = this.#buildIndexes(uri, parseResult);
|
|
95
|
+
ArazzoDocumentRegistryProvider.#recordPointers(parseResult);
|
|
94
96
|
return new _ArazzoDocument.default(uri, parseResult, workflowIndex, stepIndex, sourceDescriptionIndex);
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -150,6 +152,24 @@ class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
|
|
|
150
152
|
sourceDescriptionIndex
|
|
151
153
|
};
|
|
152
154
|
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Records, in each element's `json-pointer` meta, where it is written: every
|
|
158
|
+
* workflow, step, criterion and action, its `components` included, and
|
|
159
|
+
* every `dependsOn` entry. The record travels with the element through
|
|
160
|
+
* normalization, so an inherited or referenced element keeps the pointer of
|
|
161
|
+
* where it is defined, for the events to locate it by.
|
|
162
|
+
*/
|
|
163
|
+
static #recordPointers(parseResult) {
|
|
164
|
+
(0, _apidomTraverse.traverse)(parseResult.api, {
|
|
165
|
+
enter(path) {
|
|
166
|
+
const element = path.node;
|
|
167
|
+
const located = (0, _apidomNsArazzo.isWorkflowElement)(element) || (0, _apidomNsArazzo.isStepElement)(element) || (0, _apidomNsArazzo.isCriterionElement)(element) || (0, _apidomNsArazzo.isSuccessActionElement)(element) || (0, _apidomNsArazzo.isFailureActionElement)(element) || (0, _apidomNsArazzo.isWorkflowDependsOnElement)(path.parentPath?.node);
|
|
168
|
+
if (!located) return;
|
|
169
|
+
element.meta.set('json-pointer', path.formatPath('jsonpointer'));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
153
173
|
#buildParseOptions() {
|
|
154
174
|
return (0, _empty.mergeOptions)(_parser.defaultParseArazzoOptions, this.#options);
|
|
155
175
|
}
|
|
@@ -4,7 +4,7 @@ import { UnmatchedResolverError } from '@speclynx/apidom-reference/configuration
|
|
|
4
4
|
import { toValue } from '@speclynx/apidom-core';
|
|
5
5
|
import { isArrayElement, isStringElement } from '@speclynx/apidom-datamodel';
|
|
6
6
|
import { traverse } from '@speclynx/apidom-traverse';
|
|
7
|
-
import { isStepElement } from '@speclynx/apidom-ns-arazzo-1';
|
|
7
|
+
import { isCriterionElement, isFailureActionElement, isStepElement, isSuccessActionElement, isWorkflowDependsOnElement, isWorkflowElement } from '@speclynx/apidom-ns-arazzo-1';
|
|
8
8
|
import * as constants from "../../constants.mjs";
|
|
9
9
|
import ArazzoDocument from "../../document/ArazzoDocument.mjs";
|
|
10
10
|
import DocumentRegistryProvider, { circularReplacer } from "./DocumentRegistryProvider.mjs";
|
|
@@ -78,11 +78,13 @@ class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
78
78
|
*/
|
|
79
79
|
async provide(uri) {
|
|
80
80
|
const parseResult = await parseArazzo(uri, this.#buildParseOptions());
|
|
81
|
+
this.assertParsed(uri, parseResult);
|
|
81
82
|
const {
|
|
82
83
|
workflowIndex,
|
|
83
84
|
stepIndex,
|
|
84
85
|
sourceDescriptionIndex
|
|
85
86
|
} = this.#buildIndexes(uri, parseResult);
|
|
87
|
+
ArazzoDocumentRegistryProvider.#recordPointers(parseResult);
|
|
86
88
|
return new ArazzoDocument(uri, parseResult, workflowIndex, stepIndex, sourceDescriptionIndex);
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -142,6 +144,24 @@ class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
142
144
|
sourceDescriptionIndex
|
|
143
145
|
};
|
|
144
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Records, in each element's `json-pointer` meta, where it is written: every
|
|
150
|
+
* workflow, step, criterion and action, its `components` included, and
|
|
151
|
+
* every `dependsOn` entry. The record travels with the element through
|
|
152
|
+
* normalization, so an inherited or referenced element keeps the pointer of
|
|
153
|
+
* where it is defined, for the events to locate it by.
|
|
154
|
+
*/
|
|
155
|
+
static #recordPointers(parseResult) {
|
|
156
|
+
traverse(parseResult.api, {
|
|
157
|
+
enter(path) {
|
|
158
|
+
const element = path.node;
|
|
159
|
+
const located = isWorkflowElement(element) || isStepElement(element) || isCriterionElement(element) || isSuccessActionElement(element) || isFailureActionElement(element) || isWorkflowDependsOnElement(path.parentPath?.node);
|
|
160
|
+
if (!located) return;
|
|
161
|
+
element.meta.set('json-pointer', path.formatPath('jsonpointer'));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
145
165
|
#buildParseOptions() {
|
|
146
166
|
return mergeOptions(defaultParseArazzoOptions, this.#options);
|
|
147
167
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.circularReplacer = void 0;
|
|
7
7
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
8
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
|
+
var _parser = require("@usearazzo/parser");
|
|
8
10
|
/**
|
|
9
11
|
* Replaces circular $ref references with an empty ObjectElement
|
|
10
12
|
* annotated with the original $ref value. This ensures the dereferenced
|
|
@@ -45,5 +47,17 @@ class DocumentRegistryProvider {
|
|
|
45
47
|
/**
|
|
46
48
|
* Loads and produces a document from a URI.
|
|
47
49
|
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Rejects a document the parser could only partly read. The strict parsers
|
|
53
|
+
* throw on a syntax error; the lenient ones that source maps need record it
|
|
54
|
+
* and parse what they can instead, so a document must load with source maps
|
|
55
|
+
* exactly when it loads without.
|
|
56
|
+
*/
|
|
57
|
+
assertParsed(uri, parseResult) {
|
|
58
|
+
const [error] = parseResult.errors;
|
|
59
|
+
if (error === undefined) return;
|
|
60
|
+
throw new _parser.ParseError(`Failed to parse the document at "${uri}": ${(0, _apidomCore.toValue)(error)}`);
|
|
61
|
+
}
|
|
48
62
|
}
|
|
49
63
|
var _default = exports.default = DocumentRegistryProvider;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ObjectElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { ParseError } from '@usearazzo/parser';
|
|
2
4
|
/**
|
|
3
5
|
* Replaces circular $ref references with an empty ObjectElement
|
|
4
6
|
* annotated with the original $ref value. This ensures the dereferenced
|
|
@@ -39,5 +41,17 @@ class DocumentRegistryProvider {
|
|
|
39
41
|
/**
|
|
40
42
|
* Loads and produces a document from a URI.
|
|
41
43
|
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Rejects a document the parser could only partly read. The strict parsers
|
|
47
|
+
* throw on a syntax error; the lenient ones that source maps need record it
|
|
48
|
+
* and parse what they can instead, so a document must load with source maps
|
|
49
|
+
* exactly when it loads without.
|
|
50
|
+
*/
|
|
51
|
+
assertParsed(uri, parseResult) {
|
|
52
|
+
const [error] = parseResult.errors;
|
|
53
|
+
if (error === undefined) return;
|
|
54
|
+
throw new ParseError(`Failed to parse the document at "${uri}": ${toValue(error)}`);
|
|
55
|
+
}
|
|
42
56
|
}
|
|
43
57
|
export default DocumentRegistryProvider;
|
|
@@ -78,10 +78,11 @@ class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default
|
|
|
78
78
|
*/
|
|
79
79
|
async provide(uri) {
|
|
80
80
|
const parseResult = await (0, _parser.parseOpenAPI)(uri, this.#buildParseOptions());
|
|
81
|
-
|
|
81
|
+
this.assertParsed(uri, parseResult);
|
|
82
|
+
const operationIndex = await this.#buildOperationIndex(uri, parseResult);
|
|
82
83
|
return new _OpenAPIDocument.default(uri, parseResult, operationIndex);
|
|
83
84
|
}
|
|
84
|
-
async #buildOperationIndex(parseResult) {
|
|
85
|
+
async #buildOperationIndex(uri, parseResult) {
|
|
85
86
|
const index = new _OpenAPIOperationIndex.default();
|
|
86
87
|
const dereferenceOptions = this.#buildDereferenceOptions(parseResult);
|
|
87
88
|
const apiDereferenced = await (0, _apidomTraverse.traverseAsync)(parseResult.api, {
|
|
@@ -89,16 +90,37 @@ class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default
|
|
|
89
90
|
const pathItem = path.node;
|
|
90
91
|
if (!pathItem.hasMetaProperty('path')) return path.skip();
|
|
91
92
|
if (!(0, _apidomDatamodel.isStringElement)(pathItem.$ref)) return;
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
// an operation written next to the `$ref` stays where it is written
|
|
95
|
+
const pointer = path.formatPath('jsonpointer');
|
|
96
|
+
pathItem.forEach((value, key) => {
|
|
97
|
+
if (value.element !== 'operation') return;
|
|
98
|
+
value.meta.set('json-pointer', `${pointer}/${(0, _apidomCore.toValue)(key)}`);
|
|
99
|
+
});
|
|
100
|
+
path.replaceWith(await (0, _resolver.dereferenceOpenAPIElement)(pathItem, dereferenceOptions));
|
|
94
101
|
},
|
|
95
102
|
OperationElement(path) {
|
|
96
103
|
const operation = path.node;
|
|
97
104
|
const operationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
105
|
+
const pointer = path.formatPath('jsonpointer');
|
|
106
|
+
// where the operation is written, for the events to locate it by: an
|
|
107
|
+
// operation of a `$ref` path item is written where that path item is,
|
|
108
|
+
// unless it was written next to the `$ref` and so already located
|
|
109
|
+
if (!operation.hasMetaProperty('json-pointer')) {
|
|
110
|
+
const member = path.parentPath?.node;
|
|
111
|
+
const pathItem = path.parentPath?.parentPath?.node;
|
|
112
|
+
const definition = (0, _apidomCore.toValue)(pathItem.meta.get('ref-origin-pointer'));
|
|
113
|
+
if (typeof definition === 'string') {
|
|
114
|
+
operation.meta.set('ref-origin', (0, _apidomCore.toValue)(pathItem.meta.get('ref-origin')));
|
|
115
|
+
operation.meta.set('json-pointer', `${definition}/${(0, _apidomCore.toValue)(member.key)}`);
|
|
116
|
+
} else {
|
|
117
|
+
operation.meta.set('json-pointer', pointer);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
98
120
|
if (typeof operationId !== 'string') return path.skip();
|
|
99
121
|
if (operationId === '') return path.skip();
|
|
100
122
|
if (index.has(operationId)) return path.skip();
|
|
101
|
-
index.set(operationId,
|
|
123
|
+
index.set(operationId, pointer);
|
|
102
124
|
path.skip();
|
|
103
125
|
}
|
|
104
126
|
});
|
|
@@ -70,10 +70,11 @@ class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
70
70
|
*/
|
|
71
71
|
async provide(uri) {
|
|
72
72
|
const parseResult = await parseOpenAPI(uri, this.#buildParseOptions());
|
|
73
|
-
|
|
73
|
+
this.assertParsed(uri, parseResult);
|
|
74
|
+
const operationIndex = await this.#buildOperationIndex(uri, parseResult);
|
|
74
75
|
return new OpenAPIDocument(uri, parseResult, operationIndex);
|
|
75
76
|
}
|
|
76
|
-
async #buildOperationIndex(parseResult) {
|
|
77
|
+
async #buildOperationIndex(uri, parseResult) {
|
|
77
78
|
const index = new OpenAPIOperationIndex();
|
|
78
79
|
const dereferenceOptions = this.#buildDereferenceOptions(parseResult);
|
|
79
80
|
const apiDereferenced = await traverseAsync(parseResult.api, {
|
|
@@ -81,16 +82,37 @@ class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
81
82
|
const pathItem = path.node;
|
|
82
83
|
if (!pathItem.hasMetaProperty('path')) return path.skip();
|
|
83
84
|
if (!isStringElement(pathItem.$ref)) return;
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
|
|
86
|
+
// an operation written next to the `$ref` stays where it is written
|
|
87
|
+
const pointer = path.formatPath('jsonpointer');
|
|
88
|
+
pathItem.forEach((value, key) => {
|
|
89
|
+
if (value.element !== 'operation') return;
|
|
90
|
+
value.meta.set('json-pointer', `${pointer}/${toValue(key)}`);
|
|
91
|
+
});
|
|
92
|
+
path.replaceWith(await dereferenceOpenAPIElement(pathItem, dereferenceOptions));
|
|
86
93
|
},
|
|
87
94
|
OperationElement(path) {
|
|
88
95
|
const operation = path.node;
|
|
89
96
|
const operationId = toValue(operation.operationId);
|
|
97
|
+
const pointer = path.formatPath('jsonpointer');
|
|
98
|
+
// where the operation is written, for the events to locate it by: an
|
|
99
|
+
// operation of a `$ref` path item is written where that path item is,
|
|
100
|
+
// unless it was written next to the `$ref` and so already located
|
|
101
|
+
if (!operation.hasMetaProperty('json-pointer')) {
|
|
102
|
+
const member = path.parentPath?.node;
|
|
103
|
+
const pathItem = path.parentPath?.parentPath?.node;
|
|
104
|
+
const definition = toValue(pathItem.meta.get('ref-origin-pointer'));
|
|
105
|
+
if (typeof definition === 'string') {
|
|
106
|
+
operation.meta.set('ref-origin', toValue(pathItem.meta.get('ref-origin')));
|
|
107
|
+
operation.meta.set('json-pointer', `${definition}/${toValue(member.key)}`);
|
|
108
|
+
} else {
|
|
109
|
+
operation.meta.set('json-pointer', pointer);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
90
112
|
if (typeof operationId !== 'string') return path.skip();
|
|
91
113
|
if (operationId === '') return path.skip();
|
|
92
114
|
if (index.has(operationId)) return path.skip();
|
|
93
|
-
index.set(operationId,
|
|
115
|
+
index.set(operationId, pointer);
|
|
94
116
|
path.skip();
|
|
95
117
|
}
|
|
96
118
|
});
|