@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +10 -1
  3. package/dist/arazzo-runner.browser.js +1789 -403
  4. package/dist/arazzo-runner.browser.min.js +1 -1
  5. package/package.json +18 -17
  6. package/src/ArazzoRunner.cjs +26 -3
  7. package/src/ArazzoRunner.mjs +26 -3
  8. package/src/action/ActionResolver.cjs +13 -12
  9. package/src/action/ActionResolver.mjs +13 -12
  10. package/src/client/OpenAPIOperationResponse.cjs +9 -0
  11. package/src/client/OpenAPIOperationResponse.mjs +9 -0
  12. package/src/criterion/CriterionEvaluator.cjs +13 -8
  13. package/src/criterion/CriterionEvaluator.mjs +13 -8
  14. package/src/criterion/SimpleCriterionEvaluator.cjs +5 -3
  15. package/src/criterion/SimpleCriterionEvaluator.mjs +6 -4
  16. package/src/document/APIDocument.cjs +53 -0
  17. package/src/document/APIDocument.mjs +53 -0
  18. package/src/executor/OpenAPIOperationExecutor.cjs +66 -6
  19. package/src/executor/OpenAPIOperationExecutor.mjs +66 -6
  20. package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +1 -1
  21. package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +1 -1
  22. package/src/executor/StepExecutor.cjs +34 -15
  23. package/src/executor/StepExecutor.mjs +34 -15
  24. package/src/executor/StepRetryRunner.cjs +5 -3
  25. package/src/executor/StepRetryRunner.mjs +5 -3
  26. package/src/executor/StepTransitionInterpreter.cjs +1 -1
  27. package/src/executor/StepTransitionInterpreter.mjs +1 -1
  28. package/src/executor/WorkflowCallStack.cjs +1 -1
  29. package/src/executor/WorkflowCallStack.mjs +1 -1
  30. package/src/executor/WorkflowExecutor.cjs +277 -61
  31. package/src/executor/WorkflowExecutor.mjs +277 -61
  32. package/src/expression/RuntimeExpressionEvaluator.cjs +52 -9
  33. package/src/expression/RuntimeExpressionEvaluator.mjs +52 -9
  34. package/src/index.cjs +7 -0
  35. package/src/index.mjs +2 -0
  36. package/src/observability/ArazzoRunnerEvent.cjs +5 -0
  37. package/src/observability/ArazzoRunnerEvent.mjs +1 -0
  38. package/src/observability/DocumentRegistryEvent.cjs +5 -0
  39. package/src/observability/DocumentRegistryEvent.mjs +1 -0
  40. package/src/observability/EventChannel.cjs +96 -0
  41. package/src/observability/EventChannel.mjs +91 -0
  42. package/src/observability/OpenAPIOperationEvent.cjs +5 -0
  43. package/src/observability/OpenAPIOperationEvent.mjs +1 -0
  44. package/src/observability/Redactor.cjs +213 -0
  45. package/src/observability/Redactor.mjs +208 -0
  46. package/src/observability/WorkflowExecutionEvent.cjs +5 -0
  47. package/src/observability/WorkflowExecutionEvent.mjs +1 -0
  48. package/src/registry/DocumentRegistry.cjs +57 -11
  49. package/src/registry/DocumentRegistry.mjs +57 -11
  50. package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +21 -0
  51. package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +22 -1
  52. package/src/registry/providers/DocumentRegistryProvider.cjs +33 -1
  53. package/src/registry/providers/DocumentRegistryProvider.mjs +33 -1
  54. package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +28 -5
  55. package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +28 -5
  56. package/src/resolver/ArazzoValueResolver.cjs +6 -3
  57. package/src/resolver/ArazzoValueResolver.mjs +6 -3
  58. package/src/resolver/OpenAPIOperationParameterResolver.cjs +2 -2
  59. package/src/resolver/OpenAPIOperationParameterResolver.mjs +2 -2
  60. package/src/resolver/OutputResolver.cjs +10 -3
  61. package/src/resolver/OutputResolver.mjs +10 -3
  62. package/src/resolver/RequestBodyResolver.cjs +37 -17
  63. package/src/resolver/RequestBodyResolver.mjs +37 -17
  64. package/src/resolver/WorkflowParameterResolver.cjs +2 -2
  65. package/src/resolver/WorkflowParameterResolver.mjs +2 -2
  66. package/types/runner.d.ts +788 -41
@@ -56,6 +56,7 @@ const providerOptionsOverride = exports.providerOptionsOverride = {
56
56
  * @public
57
57
  */
58
58
  class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
59
+ sourceDescriptionType = 'arazzo';
59
60
  #options;
60
61
  constructor(options = {}) {
61
62
  super();
@@ -85,11 +86,13 @@ class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
85
86
  */
86
87
  async provide(uri) {
87
88
  const parseResult = await (0, _parser.parseArazzo)(uri, this.#buildParseOptions());
89
+ this.assertParsed(uri, parseResult);
88
90
  const {
89
91
  workflowIndex,
90
92
  stepIndex,
91
93
  sourceDescriptionIndex
92
94
  } = this.#buildIndexes(uri, parseResult);
95
+ ArazzoDocumentRegistryProvider.#recordPointers(parseResult);
93
96
  return new _ArazzoDocument.default(uri, parseResult, workflowIndex, stepIndex, sourceDescriptionIndex);
94
97
  }
95
98
 
@@ -149,6 +152,24 @@ class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
149
152
  sourceDescriptionIndex
150
153
  };
151
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
+ }
152
173
  #buildParseOptions() {
153
174
  return (0, _empty.mergeOptions)(_parser.defaultParseArazzoOptions, this.#options);
154
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";
@@ -48,6 +48,7 @@ export const providerOptionsOverride = {
48
48
  * @public
49
49
  */
50
50
  class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
51
+ sourceDescriptionType = 'arazzo';
51
52
  #options;
52
53
  constructor(options = {}) {
53
54
  super();
@@ -77,11 +78,13 @@ class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
77
78
  */
78
79
  async provide(uri) {
79
80
  const parseResult = await parseArazzo(uri, this.#buildParseOptions());
81
+ this.assertParsed(uri, parseResult);
80
82
  const {
81
83
  workflowIndex,
82
84
  stepIndex,
83
85
  sourceDescriptionIndex
84
86
  } = this.#buildIndexes(uri, parseResult);
87
+ ArazzoDocumentRegistryProvider.#recordPointers(parseResult);
85
88
  return new ArazzoDocument(uri, parseResult, workflowIndex, stepIndex, sourceDescriptionIndex);
86
89
  }
87
90
 
@@ -141,6 +144,24 @@ class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
141
144
  sourceDescriptionIndex
142
145
  };
143
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
+ }
144
165
  #buildParseOptions() {
145
166
  return mergeOptions(defaultParseArazzoOptions, this.#options);
146
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
@@ -27,5 +29,35 @@ exports.circularReplacer = circularReplacer;
27
29
  * Subclasses implement `canProvide()` for format detection and `provide()` for loading.
28
30
  * @public
29
31
  */
30
- class DocumentRegistryProvider {}
32
+ class DocumentRegistryProvider {
33
+ /**
34
+ * The Source Description Object `type` this provider loads (`openapi`,
35
+ * `arazzo`, …), or `undefined` when it does not say — then it may load a
36
+ * source of any type.
37
+ *
38
+ * Lets the registry tell, without fetching anything, whether a source of a
39
+ * given type can be loaded at all (`DocumentRegistry.canLoad`).
40
+ */
41
+ sourceDescriptionType;
42
+
43
+ /**
44
+ * Checks if the content at the URI can be handled by this provider.
45
+ */
46
+
47
+ /**
48
+ * Loads and produces a document from a URI.
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
+ }
62
+ }
31
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
@@ -21,5 +23,35 @@ export const circularReplacer = ref => new ObjectElement({
21
23
  * Subclasses implement `canProvide()` for format detection and `provide()` for loading.
22
24
  * @public
23
25
  */
24
- class DocumentRegistryProvider {}
26
+ class DocumentRegistryProvider {
27
+ /**
28
+ * The Source Description Object `type` this provider loads (`openapi`,
29
+ * `arazzo`, …), or `undefined` when it does not say — then it may load a
30
+ * source of any type.
31
+ *
32
+ * Lets the registry tell, without fetching anything, whether a source of a
33
+ * given type can be loaded at all (`DocumentRegistry.canLoad`).
34
+ */
35
+ sourceDescriptionType;
36
+
37
+ /**
38
+ * Checks if the content at the URI can be handled by this provider.
39
+ */
40
+
41
+ /**
42
+ * Loads and produces a document from a URI.
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
+ }
56
+ }
25
57
  export default DocumentRegistryProvider;
@@ -48,6 +48,7 @@ const providerOptionsOverride = exports.providerOptionsOverride = {
48
48
  * @public
49
49
  */
50
50
  class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default {
51
+ sourceDescriptionType = 'openapi';
51
52
  #options;
52
53
  constructor(options = {}) {
53
54
  super();
@@ -77,10 +78,11 @@ class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default
77
78
  */
78
79
  async provide(uri) {
79
80
  const parseResult = await (0, _parser.parseOpenAPI)(uri, this.#buildParseOptions());
80
- const operationIndex = await this.#buildOperationIndex(parseResult);
81
+ this.assertParsed(uri, parseResult);
82
+ const operationIndex = await this.#buildOperationIndex(uri, parseResult);
81
83
  return new _OpenAPIDocument.default(uri, parseResult, operationIndex);
82
84
  }
83
- async #buildOperationIndex(parseResult) {
85
+ async #buildOperationIndex(uri, parseResult) {
84
86
  const index = new _OpenAPIOperationIndex.default();
85
87
  const dereferenceOptions = this.#buildDereferenceOptions(parseResult);
86
88
  const apiDereferenced = await (0, _apidomTraverse.traverseAsync)(parseResult.api, {
@@ -88,16 +90,37 @@ class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default
88
90
  const pathItem = path.node;
89
91
  if (!pathItem.hasMetaProperty('path')) return path.skip();
90
92
  if (!(0, _apidomDatamodel.isStringElement)(pathItem.$ref)) return;
91
- const pathItemDereferenced = await (0, _resolver.dereferenceOpenAPIElement)(pathItem, dereferenceOptions);
92
- path.replaceWith(pathItemDereferenced);
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));
93
101
  },
94
102
  OperationElement(path) {
95
103
  const operation = path.node;
96
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
+ }
97
120
  if (typeof operationId !== 'string') return path.skip();
98
121
  if (operationId === '') return path.skip();
99
122
  if (index.has(operationId)) return path.skip();
100
- index.set(operationId, path.formatPath('jsonpointer'));
123
+ index.set(operationId, pointer);
101
124
  path.skip();
102
125
  }
103
126
  });
@@ -40,6 +40,7 @@ export const providerOptionsOverride = {
40
40
  * @public
41
41
  */
42
42
  class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
43
+ sourceDescriptionType = 'openapi';
43
44
  #options;
44
45
  constructor(options = {}) {
45
46
  super();
@@ -69,10 +70,11 @@ class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
69
70
  */
70
71
  async provide(uri) {
71
72
  const parseResult = await parseOpenAPI(uri, this.#buildParseOptions());
72
- const operationIndex = await this.#buildOperationIndex(parseResult);
73
+ this.assertParsed(uri, parseResult);
74
+ const operationIndex = await this.#buildOperationIndex(uri, parseResult);
73
75
  return new OpenAPIDocument(uri, parseResult, operationIndex);
74
76
  }
75
- async #buildOperationIndex(parseResult) {
77
+ async #buildOperationIndex(uri, parseResult) {
76
78
  const index = new OpenAPIOperationIndex();
77
79
  const dereferenceOptions = this.#buildDereferenceOptions(parseResult);
78
80
  const apiDereferenced = await traverseAsync(parseResult.api, {
@@ -80,16 +82,37 @@ class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
80
82
  const pathItem = path.node;
81
83
  if (!pathItem.hasMetaProperty('path')) return path.skip();
82
84
  if (!isStringElement(pathItem.$ref)) return;
83
- const pathItemDereferenced = await dereferenceOpenAPIElement(pathItem, dereferenceOptions);
84
- path.replaceWith(pathItemDereferenced);
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));
85
93
  },
86
94
  OperationElement(path) {
87
95
  const operation = path.node;
88
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
+ }
89
112
  if (typeof operationId !== 'string') return path.skip();
90
113
  if (operationId === '') return path.skip();
91
114
  if (index.has(operationId)) return path.skip();
92
- index.set(operationId, path.formatPath('jsonpointer'));
115
+ index.set(operationId, pointer);
93
116
  path.skip();
94
117
  }
95
118
  });
@@ -7,11 +7,14 @@ exports.default = void 0;
7
7
  var _apidomCore = require("@speclynx/apidom-core");
8
8
  var _arazzoRuntimeExpression = require("@swaggerexpert/arazzo-runtime-expression");
9
9
  /**
10
- * Resolves a runtime expression to its value.
10
+ * Resolves a runtime expression to its value, or to a Promise of it.
11
11
  *
12
12
  * Bridged to a lenient runtime expression evaluator
13
13
  * (`(expression) => runtimeExpressionEvaluator.evaluate(expression)`), so an
14
- * unresolvable reference yields `undefined` rather than throwing.
14
+ * unresolvable reference yields `undefined` rather than throwing; a
15
+ * `$sourceDescriptions` document that cannot be loaded still rejects with the
16
+ * load error (see `RuntimeExpressionEvaluator.evaluate`). The result
17
+ * is awaited, so a synchronous resolver works too.
15
18
  * @public
16
19
  */
17
20
 
@@ -34,7 +37,7 @@ class ArazzoValueResolver {
34
37
  /**
35
38
  * Resolves one authored value element by the rule above.
36
39
  */
37
- resolveValue(element, resolve) {
40
+ async resolveValue(element, resolve) {
38
41
  const value = (0, _apidomCore.toValue)(element);
39
42
  return typeof value === 'string' && (0, _arazzoRuntimeExpression.test)(value) ? resolve(value) : value;
40
43
  }
@@ -2,11 +2,14 @@ import { toValue } from '@speclynx/apidom-core';
2
2
  import { test as isRuntimeExpression } from '@swaggerexpert/arazzo-runtime-expression';
3
3
 
4
4
  /**
5
- * Resolves a runtime expression to its value.
5
+ * Resolves a runtime expression to its value, or to a Promise of it.
6
6
  *
7
7
  * Bridged to a lenient runtime expression evaluator
8
8
  * (`(expression) => runtimeExpressionEvaluator.evaluate(expression)`), so an
9
- * unresolvable reference yields `undefined` rather than throwing.
9
+ * unresolvable reference yields `undefined` rather than throwing; a
10
+ * `$sourceDescriptions` document that cannot be loaded still rejects with the
11
+ * load error (see `RuntimeExpressionEvaluator.evaluate`). The result
12
+ * is awaited, so a synchronous resolver works too.
10
13
  * @public
11
14
  */
12
15
 
@@ -29,7 +32,7 @@ class ArazzoValueResolver {
29
32
  /**
30
33
  * Resolves one authored value element by the rule above.
31
34
  */
32
- resolveValue(element, resolve) {
35
+ async resolveValue(element, resolve) {
33
36
  const value = toValue(element);
34
37
  return typeof value === 'string' && isRuntimeExpression(value) ? resolve(value) : value;
35
38
  }
@@ -60,7 +60,7 @@ class OpenAPIOperationParameterResolver extends _StepParameterResolver.default {
60
60
  *
61
61
  * `scope` names the step in a thrown {@link ResolverError}.
62
62
  */
63
- resolve(parameters, resolve, scope) {
63
+ async resolve(parameters, resolve, scope) {
64
64
  const delivery = new _ParameterDelivery.default();
65
65
  if (parameters === undefined) return delivery.toRecord();
66
66
  // present but scalar: walking it would fail as a bare
@@ -124,7 +124,7 @@ class OpenAPIOperationParameterResolver extends _StepParameterResolver.default {
124
124
  reason: _ResolverError.default.AmbiguousDelivery
125
125
  });
126
126
  }
127
- delivery.set(key, this.resolveValue(parameter.value, resolve));
127
+ delivery.set(key, await this.resolveValue(parameter.value, resolve));
128
128
  }
129
129
  return delivery.toRecord();
130
130
  }
@@ -53,7 +53,7 @@ class OpenAPIOperationParameterResolver extends StepParameterResolver {
53
53
  *
54
54
  * `scope` names the step in a thrown {@link ResolverError}.
55
55
  */
56
- resolve(parameters, resolve, scope) {
56
+ async resolve(parameters, resolve, scope) {
57
57
  const delivery = new ParameterDelivery();
58
58
  if (parameters === undefined) return delivery.toRecord();
59
59
  // present but scalar: walking it would fail as a bare
@@ -117,7 +117,7 @@ class OpenAPIOperationParameterResolver extends StepParameterResolver {
117
117
  reason: ResolverError.AmbiguousDelivery
118
118
  });
119
119
  }
120
- delivery.set(key, this.resolveValue(parameter.value, resolve));
120
+ delivery.set(key, await this.resolveValue(parameter.value, resolve));
121
121
  }
122
122
  return delivery.toRecord();
123
123
  }
@@ -32,7 +32,7 @@ class OutputResolver extends _ArazzoValueResolver.default {
32
32
  * {@link ResolverError}. An output value that is not a valid runtime
33
33
  * expression throws with reason `ResolverError.InvalidExpression`.
34
34
  */
35
- resolve(outputs, resolve, scope) {
35
+ async resolve(outputs, resolve, scope) {
36
36
  const result = {};
37
37
  if (outputs === undefined) return result;
38
38
  // present but not a map: the walk below would fail as a bare
@@ -44,7 +44,14 @@ class OutputResolver extends _ArazzoValueResolver.default {
44
44
  reason: _ResolverError.default.MalformedOutputs
45
45
  });
46
46
  }
47
+
48
+ // collected first: `forEach` takes a synchronous callback, and each output
49
+ // is awaited in turn below.
50
+ const entries = [];
47
51
  outputs.forEach((value, key) => {
52
+ entries.push([key, value]);
53
+ });
54
+ for (const [key, value] of entries) {
48
55
  const name = (0, _apidomCore.toValue)(key);
49
56
  const expression = (0, _apidomCore.toValue)(value);
50
57
  if (typeof expression !== 'string' || !(0, _arazzoRuntimeExpression.test)(expression)) {
@@ -59,12 +66,12 @@ class OutputResolver extends _ArazzoValueResolver.default {
59
66
  // ever created and the output is silently lost — and an object value
60
67
  // additionally rewrites the record's prototype
61
68
  Object.defineProperty(result, name, {
62
- value: resolve(expression),
69
+ value: await resolve(expression),
63
70
  enumerable: true,
64
71
  writable: true,
65
72
  configurable: true
66
73
  });
67
- });
74
+ }
68
75
  return result;
69
76
  }
70
77
  }
@@ -25,7 +25,7 @@ class OutputResolver extends ArazzoValueResolver {
25
25
  * {@link ResolverError}. An output value that is not a valid runtime
26
26
  * expression throws with reason `ResolverError.InvalidExpression`.
27
27
  */
28
- resolve(outputs, resolve, scope) {
28
+ async resolve(outputs, resolve, scope) {
29
29
  const result = {};
30
30
  if (outputs === undefined) return result;
31
31
  // present but not a map: the walk below would fail as a bare
@@ -37,7 +37,14 @@ class OutputResolver extends ArazzoValueResolver {
37
37
  reason: ResolverError.MalformedOutputs
38
38
  });
39
39
  }
40
+
41
+ // collected first: `forEach` takes a synchronous callback, and each output
42
+ // is awaited in turn below.
43
+ const entries = [];
40
44
  outputs.forEach((value, key) => {
45
+ entries.push([key, value]);
46
+ });
47
+ for (const [key, value] of entries) {
41
48
  const name = toValue(key);
42
49
  const expression = toValue(value);
43
50
  if (typeof expression !== 'string' || !isRuntimeExpression(expression)) {
@@ -52,12 +59,12 @@ class OutputResolver extends ArazzoValueResolver {
52
59
  // ever created and the output is silently lost — and an object value
53
60
  // additionally rewrites the record's prototype
54
61
  Object.defineProperty(result, name, {
55
- value: resolve(expression),
62
+ value: await resolve(expression),
56
63
  enumerable: true,
57
64
  writable: true,
58
65
  configurable: true
59
66
  });
60
- });
67
+ }
61
68
  return result;
62
69
  }
63
70
  }
@@ -65,7 +65,7 @@ class RequestBodyResolver extends _ArazzoValueResolver.default {
65
65
  *
66
66
  * `scope` names the step in a thrown {@link ResolverError}.
67
67
  */
68
- resolve(requestBody, resolve, scope) {
68
+ async resolve(requestBody, resolve, scope) {
69
69
  if (requestBody === undefined) return undefined;
70
70
 
71
71
  // present but scalar: `.payload`, `.replacements` and `.contentType` are
@@ -79,7 +79,7 @@ class RequestBodyResolver extends _ArazzoValueResolver.default {
79
79
  });
80
80
  }
81
81
  const authoredPayload = (0, _apidomCore.toValue)(requestBody.payload);
82
- let payload = this.#requireResolved(authoredPayload, this.#resolvePayloadValue(authoredPayload, [], resolve, scope), [], scope);
82
+ let payload = this.#requireResolved(authoredPayload, await this.#resolvePayloadValue(authoredPayload, [], resolve, scope), [], scope);
83
83
  if (requestBody.replacements !== undefined) {
84
84
  // present but scalar: walking it would fail as a bare
85
85
  // `TypeError: requestBody.replacements is not iterable`.
@@ -94,7 +94,7 @@ class RequestBodyResolver extends _ArazzoValueResolver.default {
94
94
  if (!(0, _apidomNsArazzo.isPayloadReplacementElement)(replacement)) continue;
95
95
  const target = (0, _apidomCore.toValue)(replacement.target);
96
96
  if (typeof target !== 'string') continue;
97
- const value = this.resolveValue(replacement.value, resolve);
97
+ const value = await this.resolveValue(replacement.value, resolve);
98
98
  if (value === undefined) continue;
99
99
  payload = this.#applyReplacement(payload, target, value, scope);
100
100
  }
@@ -113,19 +113,26 @@ class RequestBodyResolver extends _ArazzoValueResolver.default {
113
113
  * objects and arrays. Returns {@link UNRESOLVED} for a bare expression that
114
114
  * did not resolve, for its container to handle.
115
115
  */
116
- #resolvePayloadValue(value, tokens, resolve, scope) {
116
+ async #resolvePayloadValue(value, tokens, resolve, scope) {
117
117
  if (typeof value === 'string') return this.#resolvePayloadString(value, tokens, resolve, scope);
118
118
  if (Array.isArray(value)) {
119
- return value.map((item, index) => {
119
+ const items = [];
120
+ for (const [index, item] of value.entries()) {
120
121
  const itemTokens = [...tokens, String(index)];
121
- const resolved = this.#resolvePayloadValue(item, itemTokens, resolve, scope);
122
- return this.#requireResolved(item, resolved, itemTokens, scope);
123
- });
122
+ const resolved = await this.#resolvePayloadValue(item, itemTokens, resolve, scope);
123
+ items.push(this.#requireResolved(item, resolved, itemTokens, scope));
124
+ }
125
+ return items;
124
126
  }
125
127
  if (value !== null && typeof value === 'object') {
128
+ const members = [];
129
+ for (const [key, member] of Object.entries(value)) {
130
+ const resolved = await this.#resolvePayloadValue(member, [...tokens, key], resolve, scope);
131
+ if (resolved !== UNRESOLVED) members.push([key, resolved]);
132
+ }
126
133
  // `fromEntries` defines own properties, so an authored `__proto__` key
127
134
  // stays a plain member instead of replacing the prototype.
128
- return Object.fromEntries(Object.entries(value).map(([key, member]) => [key, this.#resolvePayloadValue(member, [...tokens, key], resolve, scope)]).filter(([, resolved]) => resolved !== UNRESOLVED));
135
+ return Object.fromEntries(members);
129
136
  }
130
137
  return value;
131
138
  }
@@ -135,16 +142,12 @@ class RequestBodyResolver extends _ArazzoValueResolver.default {
135
142
  * typed value (or {@link UNRESOLVED}), anything else by tolerant
136
143
  * interpolation of its embedded `{expression}` occurrences.
137
144
  */
138
- #resolvePayloadString(value, tokens, resolve, scope) {
145
+ async #resolvePayloadString(value, tokens, resolve, scope) {
139
146
  if ((0, _arazzoRuntimeExpression.test)(value)) {
140
- const resolved = resolve(value);
147
+ const resolved = await resolve(value);
141
148
  return resolved === undefined ? UNRESOLVED : resolved;
142
149
  }
143
- return (0, _arazzoRuntimeExpression.interpolate)(value, expression => {
144
- const resolved = resolve(expression);
145
- if (resolved === undefined) throw this.#unresolvedError(expression, tokens, scope);
146
- return resolved;
147
- }, {
150
+ const options = {
148
151
  strict: false,
149
152
  onError: ({
150
153
  text
@@ -155,7 +158,24 @@ class RequestBodyResolver extends _ArazzoValueResolver.default {
155
158
  reason: _ResolverError.default.InvalidExpression
156
159
  });
157
160
  }
158
- });
161
+ };
162
+
163
+ // `interpolate` takes a synchronous resolver, so the embedded expressions
164
+ // are collected by a first pass, resolved in order, and substituted by a
165
+ // second. Interpolation never skips an expression, so the result is the same.
166
+ const expressions = [];
167
+ (0, _arazzoRuntimeExpression.interpolate)(value, expression => {
168
+ expressions.push(expression);
169
+ return '';
170
+ }, options);
171
+ const values = new Map();
172
+ for (const expression of expressions) {
173
+ if (values.has(expression)) continue;
174
+ const resolved = await resolve(expression);
175
+ if (resolved === undefined) throw this.#unresolvedError(expression, tokens, scope);
176
+ values.set(expression, resolved);
177
+ }
178
+ return (0, _arazzoRuntimeExpression.interpolate)(value, expression => values.get(expression), options);
159
179
  }
160
180
 
161
181
  /**