@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearazzo/runner",
3
- "version": "1.0.1-alpha.32",
3
+ "version": "1.0.1-alpha.34",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -56,29 +56,30 @@
56
56
  "author": "Vladimir Gorej <vladimir.gorej@gmail.com>",
57
57
  "license": "Apache-2.0",
58
58
  "dependencies": {
59
- "@babel/runtime-corejs3": "^8.1.0",
60
- "@speclynx/apidom-core": "^7.0.2",
61
- "@speclynx/apidom-datamodel": "^7.0.2",
62
- "@speclynx/apidom-error": "^7.0.2",
63
- "@speclynx/apidom-json-pointer": "^7.0.2",
64
- "@speclynx/apidom-ns-arazzo-1": "^7.0.2",
65
- "@speclynx/apidom-ns-openapi-2": "^7.0.2",
66
- "@speclynx/apidom-ns-openapi-3-0": "^7.0.2",
67
- "@speclynx/apidom-ns-openapi-3-1": "^7.0.2",
68
- "@speclynx/apidom-reference": "^7.0.2",
69
- "@speclynx/apidom-traverse": "^7.0.2",
70
- "@swaggerexpert/arazzo-criterion": "^1.0.1",
71
- "@swaggerexpert/arazzo-runtime-expression": "^3.3.0",
59
+ "@babel/runtime-corejs3": "^8.1.2",
60
+ "@speclynx/apidom-core": "^7.1.0",
61
+ "@speclynx/apidom-datamodel": "^7.1.0",
62
+ "@speclynx/apidom-error": "^7.1.0",
63
+ "@speclynx/apidom-json-pointer": "^7.1.0",
64
+ "@speclynx/apidom-ns-arazzo-1": "^7.1.0",
65
+ "@speclynx/apidom-ns-openapi-2": "^7.1.0",
66
+ "@speclynx/apidom-ns-openapi-3-0": "^7.1.0",
67
+ "@speclynx/apidom-ns-openapi-3-1": "^7.1.0",
68
+ "@speclynx/apidom-reference": "^7.1.0",
69
+ "@speclynx/apidom-traverse": "^7.1.0",
70
+ "@swaggerexpert/arazzo-criterion": "^1.2.0",
71
+ "@swaggerexpert/arazzo-runtime-expression": "^3.4.0",
72
72
  "@swaggerexpert/cookie": "^2.1.1",
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.32",
77
- "@usearazzo/resolver": "1.0.1-alpha.32",
76
+ "@usearazzo/parser": "1.0.1-alpha.34",
77
+ "@usearazzo/resolver": "1.0.1-alpha.34",
78
78
  "@xmldom/xmldom": "^0.9.12",
79
79
  "fontoxpath": "^3.34.0",
80
80
  "ramda": "^0.32.0",
81
81
  "ramda-adjunct": "^6.1.0",
82
+ "short-unique-id": "^5.3.2",
82
83
  "type-fest": "^5.10.0"
83
84
  },
84
85
  "files": [
@@ -94,5 +95,5 @@
94
95
  "devDependencies": {
95
96
  "swagger-client": "^3.39.0"
96
97
  },
97
- "gitHead": "e19832b62ed4a938f9fdbd4c9072a94a247254d0"
98
+ "gitHead": "38ba1b2907b4af68cf4cf615ea8031b93fed60e6"
98
99
  }
@@ -32,8 +32,9 @@ var _InvalidEntryDocumentError = _interopRequireDefault(require("./errors/Invali
32
32
  * Every option is a seam of a building block the runner wires: `registry` is
33
33
  * the {@link DocumentRegistry} the documents load into (a fresh one with the
34
34
  * default providers when omitted), `reference` goes to everything the runner
35
- * builds that retrieves documents, `httpClient` and `requestInterceptor` go to
36
- * the {@link OpenAPIOperationExecutor}, and the rest go to the
35
+ * builds that retrieves documents, `httpClient`, `requestInterceptor` and
36
+ * `captureBodies` go to the {@link OpenAPIOperationExecutor}, and the rest go
37
+ * to the
37
38
  * {@link WorkflowExecutor}.
38
39
  *
39
40
  * Retrieving documents and calling APIs are separate on purpose: `reference`
@@ -74,10 +75,24 @@ class ArazzoRunner {
74
75
  static async load(uri, options = {}) {
75
76
  // `resolve` only, whatever else the given object carries
76
77
  const referenceOptions = (0, _ramda.pick)(['resolve'], options.reference ?? {});
78
+ // source maps need the non-strict parsers, which are the ones that keep
79
+ // positions
80
+ const providerOptions = options.sourceMap ? {
81
+ ...referenceOptions,
82
+ parse: {
83
+ parserOpts: {
84
+ sourceMap: true,
85
+ strict: false
86
+ }
87
+ }
88
+ } : referenceOptions;
77
89
  const {
78
90
  registry = new _DocumentRegistry.default({
79
- providers: [new _ArazzoDocumentRegistryProvider.default(referenceOptions), new _OpenAPIDocumentRegistryProvider.default(referenceOptions)]
91
+ providers: [new _ArazzoDocumentRegistryProvider.default(providerOptions), new _OpenAPIDocumentRegistryProvider.default(providerOptions)],
92
+ observer: options.observer,
93
+ now: options.now
80
94
  }),
95
+ sourceMap: _sourceMap,
81
96
  ...rest
82
97
  } = options;
83
98
  // acquiring a second entry would pin it for good and, through the LRU
@@ -109,6 +124,7 @@ class ArazzoRunner {
109
124
  reference,
110
125
  httpClient,
111
126
  requestInterceptor,
127
+ captureBodies,
112
128
  ...workflowExecutorOptions
113
129
  } = options;
114
130
 
@@ -122,9 +138,16 @@ class ArazzoRunner {
122
138
 
123
139
  // `resolve` only, whatever else the given object carries
124
140
  const referenceOptions = (0, _ramda.pick)(['resolve'], reference ?? {});
141
+ const {
142
+ observer,
143
+ now
144
+ } = workflowExecutorOptions;
125
145
  const operationExecutor = new _OpenAPIOperationExecutor.default({
126
146
  httpClient,
127
147
  requestInterceptor,
148
+ captureBodies,
149
+ observer,
150
+ now,
128
151
  operationNormalizer: new _OpenAPIOperationNormalizer.default({
129
152
  openapi2: new _OpenAPI2OperationNormalizer.default(referenceOptions),
130
153
  openapi30: new _OpenAPI30OperationNormalizer.default(referenceOptions),
@@ -24,8 +24,9 @@ import InvalidEntryDocumentError from "./errors/InvalidEntryDocumentError.mjs";
24
24
  * Every option is a seam of a building block the runner wires: `registry` is
25
25
  * the {@link DocumentRegistry} the documents load into (a fresh one with the
26
26
  * default providers when omitted), `reference` goes to everything the runner
27
- * builds that retrieves documents, `httpClient` and `requestInterceptor` go to
28
- * the {@link OpenAPIOperationExecutor}, and the rest go to the
27
+ * builds that retrieves documents, `httpClient`, `requestInterceptor` and
28
+ * `captureBodies` go to the {@link OpenAPIOperationExecutor}, and the rest go
29
+ * to the
29
30
  * {@link WorkflowExecutor}.
30
31
  *
31
32
  * Retrieving documents and calling APIs are separate on purpose: `reference`
@@ -64,10 +65,24 @@ class ArazzoRunner {
64
65
  static async load(uri, options = {}) {
65
66
  // `resolve` only, whatever else the given object carries
66
67
  const referenceOptions = pick(['resolve'], options.reference ?? {});
68
+ // source maps need the non-strict parsers, which are the ones that keep
69
+ // positions
70
+ const providerOptions = options.sourceMap ? {
71
+ ...referenceOptions,
72
+ parse: {
73
+ parserOpts: {
74
+ sourceMap: true,
75
+ strict: false
76
+ }
77
+ }
78
+ } : referenceOptions;
67
79
  const {
68
80
  registry = new DocumentRegistry({
69
- providers: [new ArazzoDocumentRegistryProvider(referenceOptions), new OpenAPIDocumentRegistryProvider(referenceOptions)]
81
+ providers: [new ArazzoDocumentRegistryProvider(providerOptions), new OpenAPIDocumentRegistryProvider(providerOptions)],
82
+ observer: options.observer,
83
+ now: options.now
70
84
  }),
85
+ sourceMap: _sourceMap,
71
86
  ...rest
72
87
  } = options;
73
88
  // acquiring a second entry would pin it for good and, through the LRU
@@ -99,6 +114,7 @@ class ArazzoRunner {
99
114
  reference,
100
115
  httpClient,
101
116
  requestInterceptor,
117
+ captureBodies,
102
118
  ...workflowExecutorOptions
103
119
  } = options;
104
120
 
@@ -112,9 +128,16 @@ class ArazzoRunner {
112
128
 
113
129
  // `resolve` only, whatever else the given object carries
114
130
  const referenceOptions = pick(['resolve'], reference ?? {});
131
+ const {
132
+ observer,
133
+ now
134
+ } = workflowExecutorOptions;
115
135
  const operationExecutor = new OpenAPIOperationExecutor({
116
136
  httpClient,
117
137
  requestInterceptor,
138
+ captureBodies,
139
+ observer,
140
+ now,
118
141
  operationNormalizer: new OpenAPIOperationNormalizer({
119
142
  openapi2: new OpenAPI2OperationNormalizer(referenceOptions),
120
143
  openapi30: new OpenAPI30OperationNormalizer(referenceOptions),
@@ -9,12 +9,13 @@ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
9
9
  var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
10
10
  var _ResolverError = _interopRequireDefault(require("../errors/ResolverError.cjs"));
11
11
  /**
12
- * Determines whether a single criterion of an action is met. Receives the
13
- * action declaring the criterion, so a caller can attribute the outcome to it.
12
+ * Determines whether a single criterion of an action is met, or resolves to
13
+ * whether it is. Receives the action declaring the criterion, so a caller can
14
+ * attribute the outcome to it.
14
15
  *
15
16
  * Bridged to a criterion evaluator
16
- * (`(criterion) => criterionEvaluator.evaluate(criterion, resolve).met`); an
17
- * unresolvable/failing criterion is `false`, not an error.
17
+ * (`async (criterion) => (await criterionEvaluator.evaluate(criterion, resolve)).met`);
18
+ * an unresolvable/failing criterion is `false`, not an error.
18
19
  * @public
19
20
  */
20
21
 
@@ -69,12 +70,12 @@ class ActionResolver {
69
70
  * `end` its author was reaching for would otherwise never happen without a
70
71
  * word said about why.
71
72
  */
72
- resolveOnSuccess(actions, isCriterionMet, scope) {
73
+ async resolveOnSuccess(actions, isCriterionMet, scope) {
73
74
  // safe: `#resolveAll` validates every entry as *a* Success/Failure Action
74
75
  // Object, not one matching this list's own field, but a well-formed
75
76
  // `StepOnSuccessElement` only ever refracts Success Action entries — the
76
77
  // apidom refractor types list entries positionally at parse time.
77
- return this.#resolveAll(actions, isCriterionMet, 'onSuccess', scope);
78
+ return await this.#resolveAll(actions, isCriterionMet, 'onSuccess', scope);
78
79
  }
79
80
 
80
81
  /**
@@ -83,9 +84,9 @@ class ActionResolver {
83
84
  * Same matching and error behavior as {@link ActionResolver.resolveOnSuccess} —
84
85
  * see there for the full rationale — mirrored for the step's other list.
85
86
  */
86
- resolveOnFailure(actions, isCriterionMet, scope) {
87
+ async resolveOnFailure(actions, isCriterionMet, scope) {
87
88
  // safe: see the same-named comment in `resolveOnSuccess` above.
88
- return this.#resolveAll(actions, isCriterionMet, 'onFailure', scope);
89
+ return await this.#resolveAll(actions, isCriterionMet, 'onFailure', scope);
89
90
  }
90
91
 
91
92
  /**
@@ -98,7 +99,7 @@ class ActionResolver {
98
99
  * element's own type no longer distinguishes them. Baked in by the public
99
100
  * method rather than taken from the caller.
100
101
  */
101
- #resolveAll(actions, isCriterionMet, field, scope) {
102
+ async #resolveAll(actions, isCriterionMet, field, scope) {
102
103
  if (actions === undefined) return [];
103
104
  // present but scalar: walking it would fail as a bare
104
105
  // `TypeError: actions is not iterable`.
@@ -118,7 +119,7 @@ class ActionResolver {
118
119
  reason: _ResolverError.default.MalformedActionEntry
119
120
  });
120
121
  }
121
- if (this.#criteriaMet(action, isCriterionMet, scope)) {
122
+ if (await this.#criteriaMet(action, isCriterionMet, scope)) {
122
123
  matched.push(action);
123
124
  }
124
125
  }
@@ -135,7 +136,7 @@ class ActionResolver {
135
136
  * not say what its author meant, the same as an unrecognized entry in the
136
137
  * action list itself.
137
138
  */
138
- #criteriaMet(action, isCriterionMet, scope) {
139
+ async #criteriaMet(action, isCriterionMet, scope) {
139
140
  const criteria = action.criteria;
140
141
  if (criteria === undefined) return true;
141
142
  if (!(0, _apidomDatamodel.isArrayElement)(criteria)) {
@@ -156,7 +157,7 @@ class ActionResolver {
156
157
  }
157
158
  // every criterion is evaluated, not only up to the first unmet one, so
158
159
  // a predicate that records outcomes sees the whole list.
159
- if (!isCriterionMet(criterion, action)) met = false;
160
+ if (!(await isCriterionMet(criterion, action))) met = false;
160
161
  }
161
162
  return met;
162
163
  }
@@ -2,12 +2,13 @@ import { isArrayElement } from '@speclynx/apidom-datamodel';
2
2
  import { isSuccessActionElement, isFailureActionElement, isCriterionElement } from '@speclynx/apidom-ns-arazzo-1';
3
3
  import ResolverError from "../errors/ResolverError.mjs";
4
4
  /**
5
- * Determines whether a single criterion of an action is met. Receives the
6
- * action declaring the criterion, so a caller can attribute the outcome to it.
5
+ * Determines whether a single criterion of an action is met, or resolves to
6
+ * whether it is. Receives the action declaring the criterion, so a caller can
7
+ * attribute the outcome to it.
7
8
  *
8
9
  * Bridged to a criterion evaluator
9
- * (`(criterion) => criterionEvaluator.evaluate(criterion, resolve).met`); an
10
- * unresolvable/failing criterion is `false`, not an error.
10
+ * (`async (criterion) => (await criterionEvaluator.evaluate(criterion, resolve)).met`);
11
+ * an unresolvable/failing criterion is `false`, not an error.
11
12
  * @public
12
13
  */
13
14
  /**
@@ -59,12 +60,12 @@ class ActionResolver {
59
60
  * `end` its author was reaching for would otherwise never happen without a
60
61
  * word said about why.
61
62
  */
62
- resolveOnSuccess(actions, isCriterionMet, scope) {
63
+ async resolveOnSuccess(actions, isCriterionMet, scope) {
63
64
  // safe: `#resolveAll` validates every entry as *a* Success/Failure Action
64
65
  // Object, not one matching this list's own field, but a well-formed
65
66
  // `StepOnSuccessElement` only ever refracts Success Action entries — the
66
67
  // apidom refractor types list entries positionally at parse time.
67
- return this.#resolveAll(actions, isCriterionMet, 'onSuccess', scope);
68
+ return await this.#resolveAll(actions, isCriterionMet, 'onSuccess', scope);
68
69
  }
69
70
 
70
71
  /**
@@ -73,9 +74,9 @@ class ActionResolver {
73
74
  * Same matching and error behavior as {@link ActionResolver.resolveOnSuccess} —
74
75
  * see there for the full rationale — mirrored for the step's other list.
75
76
  */
76
- resolveOnFailure(actions, isCriterionMet, scope) {
77
+ async resolveOnFailure(actions, isCriterionMet, scope) {
77
78
  // safe: see the same-named comment in `resolveOnSuccess` above.
78
- return this.#resolveAll(actions, isCriterionMet, 'onFailure', scope);
79
+ return await this.#resolveAll(actions, isCriterionMet, 'onFailure', scope);
79
80
  }
80
81
 
81
82
  /**
@@ -88,7 +89,7 @@ class ActionResolver {
88
89
  * element's own type no longer distinguishes them. Baked in by the public
89
90
  * method rather than taken from the caller.
90
91
  */
91
- #resolveAll(actions, isCriterionMet, field, scope) {
92
+ async #resolveAll(actions, isCriterionMet, field, scope) {
92
93
  if (actions === undefined) return [];
93
94
  // present but scalar: walking it would fail as a bare
94
95
  // `TypeError: actions is not iterable`.
@@ -108,7 +109,7 @@ class ActionResolver {
108
109
  reason: ResolverError.MalformedActionEntry
109
110
  });
110
111
  }
111
- if (this.#criteriaMet(action, isCriterionMet, scope)) {
112
+ if (await this.#criteriaMet(action, isCriterionMet, scope)) {
112
113
  matched.push(action);
113
114
  }
114
115
  }
@@ -125,7 +126,7 @@ class ActionResolver {
125
126
  * not say what its author meant, the same as an unrecognized entry in the
126
127
  * action list itself.
127
128
  */
128
- #criteriaMet(action, isCriterionMet, scope) {
129
+ async #criteriaMet(action, isCriterionMet, scope) {
129
130
  const criteria = action.criteria;
130
131
  if (criteria === undefined) return true;
131
132
  if (!isArrayElement(criteria)) {
@@ -146,7 +147,7 @@ class ActionResolver {
146
147
  }
147
148
  // every criterion is evaluated, not only up to the first unmet one, so
148
149
  // a predicate that records outcomes sees the whole list.
149
- if (!isCriterionMet(criterion, action)) met = false;
150
+ if (!(await isCriterionMet(criterion, action))) met = false;
150
151
  }
151
152
  return met;
152
153
  }
@@ -47,6 +47,15 @@ class OpenAPIOperationResponse {
47
47
  this.request = raw.request;
48
48
  }
49
49
 
50
+ /**
51
+ * The body's size in bytes, as read: after the transport decoded any
52
+ * `Content-Encoding`, so a compressed body counts at its decoded size.
53
+ */
54
+ get size() {
55
+ // a string content encodes back to exactly the bytes received
56
+ return typeof this.#content === 'string' ? new TextEncoder().encode(this.#content).length : this.#content.length;
57
+ }
58
+
50
59
  /**
51
60
  * The body as text, like `Response.text()`; `''` when there is none.
52
61
  */
@@ -41,6 +41,15 @@ class OpenAPIOperationResponse {
41
41
  this.request = raw.request;
42
42
  }
43
43
 
44
+ /**
45
+ * The body's size in bytes, as read: after the transport decoded any
46
+ * `Content-Encoding`, so a compressed body counts at its decoded size.
47
+ */
48
+ get size() {
49
+ // a string content encodes back to exactly the bytes received
50
+ return typeof this.#content === 'string' ? new TextEncoder().encode(this.#content).length : this.#content.length;
51
+ }
52
+
44
53
  /**
45
54
  * The body as text, like `Response.text()`; `''` when there is none.
46
55
  */
@@ -16,14 +16,19 @@ var _SimpleCriterionEvaluator = _interopRequireDefault(require("./SimpleCriterio
16
16
  var _JSONPathCriterionEvaluator = _interopRequireDefault(require("./JSONPathCriterionEvaluator.cjs"));
17
17
  var _XPathCriterionEvaluator = _interopRequireDefault(require("./XPathCriterionEvaluator.cjs"));
18
18
  /**
19
- * Resolves a runtime expression to a value during criterion evaluation.
19
+ * Resolves a runtime expression to a value, or to a Promise of it, during
20
+ * criterion evaluation. The result is awaited, so a synchronous resolver works
21
+ * too.
20
22
  *
21
23
  * Used both for a criterion's `context` (regex/jsonpath/xpath) and for the
22
24
  * expressions embedded in a `simple` condition. It should resolve leniently —
23
25
  * an unresolvable reference returning `undefined` fails the criterion rather
24
26
  * than throwing (a common way to drive it is
25
27
  * `(expression) => runtimeExpressionEvaluator.evaluate(expression)` with a
26
- * lenient evaluator).
28
+ * lenient evaluator). An error it throws or rejects with — such as the load
29
+ * error of a `$sourceDescriptions` document that cannot be loaded — is not a
30
+ * {@link CriterionEvaluationError}, so it propagates instead of failing the
31
+ * criterion.
27
32
  * @public
28
33
  */
29
34
 
@@ -99,7 +104,7 @@ class CriterionEvaluator {
99
104
  * the expressions embedded in the condition; for the other types it resolves
100
105
  * the criterion's `context` expression that the condition is applied to.
101
106
  */
102
- evaluate(criterion, resolve) {
107
+ async evaluate(criterion, resolve) {
103
108
  if (!(0, _apidomNsArazzo.isCriterionElement)(criterion)) {
104
109
  throw new _CriterionError.default('Element is not a Criterion Object', {
105
110
  reason: _CriterionError.default.InvalidCriterion
@@ -119,23 +124,23 @@ class CriterionEvaluator {
119
124
  try {
120
125
  switch (type) {
121
126
  case 'simple':
122
- met = this.#simple.evaluate(condition, resolve);
127
+ met = await this.#simple.evaluate(condition, resolve);
123
128
  break;
124
129
  case 'regex':
125
- met = this.#regex.evaluate(condition, this.#resolveContext(criterion, type, resolve));
130
+ met = this.#regex.evaluate(condition, await this.#resolveContext(criterion, type, resolve));
126
131
  break;
127
132
  case 'jsonpath':
128
133
  // only rfc9535 is supported, Arazzo 1.1.0's default, so an omitted
129
134
  // version is accepted. draft-goessner has different semantics and is
130
135
  // rejected rather than mis-evaluated.
131
136
  this.#requireVersion(criterion, type, condition, 'rfc9535');
132
- met = this.#jsonpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
137
+ met = this.#jsonpath.evaluate(condition, await this.#resolveContext(criterion, type, resolve));
133
138
  break;
134
139
  case 'xpath':
135
140
  // only XPath 3.1 is supported; xpath-31 is Arazzo 1.1.0's default, so
136
141
  // an omitted version is accepted. Older versions are rejected.
137
142
  this.#requireVersion(criterion, type, condition, 'xpath-31');
138
- met = this.#xpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
143
+ met = this.#xpath.evaluate(condition, await this.#resolveContext(criterion, type, resolve));
139
144
  break;
140
145
  default:
141
146
  throw new _CriterionError.default(`Unknown criterion type "${type}"`, {
@@ -236,7 +241,7 @@ class CriterionEvaluator {
236
241
  * `jsonpath`, `xpath`) must declare one; a criterion of such a type without a
237
242
  * `context` throws a {@link CriterionError}.
238
243
  */
239
- #resolveContext(criterion, type, resolve) {
244
+ async #resolveContext(criterion, type, resolve) {
240
245
  if (!(0, _apidomDatamodel.isStringElement)(criterion.context)) {
241
246
  throw new _CriterionError.default(`Criterion type "${type}" requires a "context"`, {
242
247
  type,
@@ -9,14 +9,19 @@ import SimpleCriterionEvaluator from "./SimpleCriterionEvaluator.mjs";
9
9
  import JSONPathCriterionEvaluator from "./JSONPathCriterionEvaluator.mjs";
10
10
  import XPathCriterionEvaluator from "./XPathCriterionEvaluator.mjs";
11
11
  /**
12
- * Resolves a runtime expression to a value during criterion evaluation.
12
+ * Resolves a runtime expression to a value, or to a Promise of it, during
13
+ * criterion evaluation. The result is awaited, so a synchronous resolver works
14
+ * too.
13
15
  *
14
16
  * Used both for a criterion's `context` (regex/jsonpath/xpath) and for the
15
17
  * expressions embedded in a `simple` condition. It should resolve leniently —
16
18
  * an unresolvable reference returning `undefined` fails the criterion rather
17
19
  * than throwing (a common way to drive it is
18
20
  * `(expression) => runtimeExpressionEvaluator.evaluate(expression)` with a
19
- * lenient evaluator).
21
+ * lenient evaluator). An error it throws or rejects with — such as the load
22
+ * error of a `$sourceDescriptions` document that cannot be loaded — is not a
23
+ * {@link CriterionEvaluationError}, so it propagates instead of failing the
24
+ * criterion.
20
25
  * @public
21
26
  */
22
27
  /**
@@ -89,7 +94,7 @@ class CriterionEvaluator {
89
94
  * the expressions embedded in the condition; for the other types it resolves
90
95
  * the criterion's `context` expression that the condition is applied to.
91
96
  */
92
- evaluate(criterion, resolve) {
97
+ async evaluate(criterion, resolve) {
93
98
  if (!isCriterionElement(criterion)) {
94
99
  throw new CriterionError('Element is not a Criterion Object', {
95
100
  reason: CriterionError.InvalidCriterion
@@ -109,23 +114,23 @@ class CriterionEvaluator {
109
114
  try {
110
115
  switch (type) {
111
116
  case 'simple':
112
- met = this.#simple.evaluate(condition, resolve);
117
+ met = await this.#simple.evaluate(condition, resolve);
113
118
  break;
114
119
  case 'regex':
115
- met = this.#regex.evaluate(condition, this.#resolveContext(criterion, type, resolve));
120
+ met = this.#regex.evaluate(condition, await this.#resolveContext(criterion, type, resolve));
116
121
  break;
117
122
  case 'jsonpath':
118
123
  // only rfc9535 is supported, Arazzo 1.1.0's default, so an omitted
119
124
  // version is accepted. draft-goessner has different semantics and is
120
125
  // rejected rather than mis-evaluated.
121
126
  this.#requireVersion(criterion, type, condition, 'rfc9535');
122
- met = this.#jsonpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
127
+ met = this.#jsonpath.evaluate(condition, await this.#resolveContext(criterion, type, resolve));
123
128
  break;
124
129
  case 'xpath':
125
130
  // only XPath 3.1 is supported; xpath-31 is Arazzo 1.1.0's default, so
126
131
  // an omitted version is accepted. Older versions are rejected.
127
132
  this.#requireVersion(criterion, type, condition, 'xpath-31');
128
- met = this.#xpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
133
+ met = this.#xpath.evaluate(condition, await this.#resolveContext(criterion, type, resolve));
129
134
  break;
130
135
  default:
131
136
  throw new CriterionError(`Unknown criterion type "${type}"`, {
@@ -226,7 +231,7 @@ class CriterionEvaluator {
226
231
  * `jsonpath`, `xpath`) must declare one; a criterion of such a type without a
227
232
  * `context` throws a {@link CriterionError}.
228
233
  */
229
- #resolveContext(criterion, type, resolve) {
234
+ async #resolveContext(criterion, type, resolve) {
230
235
  if (!isStringElement(criterion.context)) {
231
236
  throw new CriterionError(`Criterion type "${type}" requires a "context"`, {
232
237
  type,
@@ -15,7 +15,9 @@ var _CriterionEvaluationError = _interopRequireDefault(require("../errors/Criter
15
15
  * unlike `regex`/`jsonpath`/`xpath` — it has no separate `context`. Parsing,
16
16
  * loose/case-insensitive comparison, and member/index navigation are delegated
17
17
  * to `@swaggerexpert/arazzo-criterion`; each embedded runtime expression is
18
- * resolved through the supplied resolver.
18
+ * resolved through the supplied resolver and awaited in turn. `&&` and `||`
19
+ * short-circuit, so an operand that cannot change the outcome is never
20
+ * resolved.
19
21
  *
20
22
  * An operand that resolves to `undefined` (a lenient miss) does not throw; it is
21
23
  * compared per the library's rules (e.g. `undefined == x` and relational
@@ -29,9 +31,9 @@ class SimpleCriterionEvaluator {
29
31
  * Evaluates the simple `condition`, resolving each embedded runtime
30
32
  * expression via `resolve`.
31
33
  */
32
- evaluate(condition, resolve) {
34
+ async evaluate(condition, resolve) {
33
35
  try {
34
- return (0, _arazzoCriterion.evaluate)(condition, {
36
+ return await (0, _arazzoCriterion.evaluateAsync)(condition, {
35
37
  resolve
36
38
  });
37
39
  } catch (error) {
@@ -1,4 +1,4 @@
1
- import { evaluate as evaluateSimpleCriterion, ArazzoCriterionError } from '@swaggerexpert/arazzo-criterion';
1
+ import { evaluateAsync as evaluateSimpleCriterion, ArazzoCriterionError } from '@swaggerexpert/arazzo-criterion';
2
2
  import CriterionEvaluationError from "../errors/CriterionEvaluationError.mjs";
3
3
  /**
4
4
  * Evaluates a `simple` Arazzo criterion condition.
@@ -8,7 +8,9 @@ import CriterionEvaluationError from "../errors/CriterionEvaluationError.mjs";
8
8
  * unlike `regex`/`jsonpath`/`xpath` — it has no separate `context`. Parsing,
9
9
  * loose/case-insensitive comparison, and member/index navigation are delegated
10
10
  * to `@swaggerexpert/arazzo-criterion`; each embedded runtime expression is
11
- * resolved through the supplied resolver.
11
+ * resolved through the supplied resolver and awaited in turn. `&&` and `||`
12
+ * short-circuit, so an operand that cannot change the outcome is never
13
+ * resolved.
12
14
  *
13
15
  * An operand that resolves to `undefined` (a lenient miss) does not throw; it is
14
16
  * compared per the library's rules (e.g. `undefined == x` and relational
@@ -22,9 +24,9 @@ class SimpleCriterionEvaluator {
22
24
  * Evaluates the simple `condition`, resolving each embedded runtime
23
25
  * expression via `resolve`.
24
26
  */
25
- evaluate(condition, resolve) {
27
+ async evaluate(condition, resolve) {
26
28
  try {
27
- return evaluateSimpleCriterion(condition, {
29
+ return await evaluateSimpleCriterion(condition, {
28
30
  resolve
29
31
  });
30
32
  } catch (error) {
@@ -5,6 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _apidomCore = require("@speclynx/apidom-core");
8
+ /**
9
+ * A position in a document, as in the Language Server Protocol: a 0-based
10
+ * line, and a 0-based character offset within it in UTF-16 code units.
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * A range in a document, as in the Language Server Protocol: from `start` to
16
+ * `end`, the shape the validator's diagnostics use.
17
+ * @public
18
+ */
19
+
20
+ /**
21
+ * Where an element is written.
22
+ * @public
23
+ */
24
+
8
25
  /**
9
26
  * Base document held by the document registry.
10
27
  * @public
@@ -17,6 +34,42 @@ class APIDocument {
17
34
  this.parseResult = parseResult;
18
35
  }
19
36
 
37
+ /**
38
+ * Where an element of this document, or one it references, is written, as
39
+ * the registry provider recorded it when it loaded the document: the
40
+ * document it came from (its `ref-origin`) when it came through a
41
+ * reference, and its JSON Pointer there.
42
+ */
43
+ locationOf(element) {
44
+ const origin = (0, _apidomCore.toValue)(element.meta.get('ref-origin'));
45
+ const jsonPointer = (0, _apidomCore.toValue)(element.meta.get('json-pointer'));
46
+ const {
47
+ startLine,
48
+ startCharacter,
49
+ endLine,
50
+ endCharacter
51
+ } = element;
52
+ return {
53
+ uri: typeof origin === 'string' ? origin : this.uri,
54
+ ...(typeof jsonPointer === 'string' && {
55
+ jsonPointer
56
+ }),
57
+ // a source-mapped parse positions every element fully, any other none
58
+ ...(startLine !== undefined && {
59
+ range: {
60
+ start: {
61
+ line: startLine,
62
+ character: startCharacter
63
+ },
64
+ end: {
65
+ line: endLine,
66
+ character: endCharacter
67
+ }
68
+ }
69
+ })
70
+ };
71
+ }
72
+
20
73
  /**
21
74
  * Returns a JSON-serializable representation of the document's API element.
22
75
  * Compatible with JSON.stringify() — JSON.stringify(doc) produces correct output.