@usearazzo/runner 1.0.1-alpha.18 → 1.0.1-alpha.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearazzo/runner",
3
- "version": "1.0.1-alpha.18",
3
+ "version": "1.0.1-alpha.20",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -57,24 +57,24 @@
57
57
  "license": "Apache-2.0",
58
58
  "dependencies": {
59
59
  "@babel/runtime-corejs3": "^8.0.8",
60
- "@speclynx/apidom-core": "^6.1.0",
61
- "@speclynx/apidom-datamodel": "^6.1.0",
62
- "@speclynx/apidom-error": "^6.1.0",
63
- "@speclynx/apidom-json-pointer": "^6.1.0",
64
- "@speclynx/apidom-ns-arazzo-1": "^6.1.0",
65
- "@speclynx/apidom-ns-openapi-2": "^6.1.0",
66
- "@speclynx/apidom-ns-openapi-3-0": "^6.1.0",
67
- "@speclynx/apidom-ns-openapi-3-1": "^6.1.0",
68
- "@speclynx/apidom-reference": "^6.1.0",
69
- "@speclynx/apidom-traverse": "^6.1.0",
60
+ "@speclynx/apidom-core": "^6.1.2",
61
+ "@speclynx/apidom-datamodel": "^6.1.2",
62
+ "@speclynx/apidom-error": "^6.1.2",
63
+ "@speclynx/apidom-json-pointer": "^6.1.2",
64
+ "@speclynx/apidom-ns-arazzo-1": "^6.1.2",
65
+ "@speclynx/apidom-ns-openapi-2": "^6.1.2",
66
+ "@speclynx/apidom-ns-openapi-3-0": "^6.1.2",
67
+ "@speclynx/apidom-ns-openapi-3-1": "^6.1.2",
68
+ "@speclynx/apidom-reference": "^6.1.2",
69
+ "@speclynx/apidom-traverse": "^6.1.2",
70
70
  "@swaggerexpert/arazzo-criterion": "^1.0.1",
71
71
  "@swaggerexpert/arazzo-runtime-expression": "^3.3.0",
72
72
  "@swaggerexpert/cookie": "^2.0.2",
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.18",
77
- "@usearazzo/resolver": "1.0.1-alpha.18",
76
+ "@usearazzo/parser": "1.0.1-alpha.20",
77
+ "@usearazzo/resolver": "1.0.1-alpha.20",
78
78
  "@xmldom/xmldom": "^0.9.12",
79
79
  "fontoxpath": "^3.34.0",
80
80
  "ramda": "^0.32.0",
@@ -94,5 +94,5 @@
94
94
  "devDependencies": {
95
95
  "swagger-client": "^3.38.4"
96
96
  },
97
- "gitHead": "29cba37b82d02fa4b11e7d8acf3ba9f96dc44e10"
97
+ "gitHead": "5af237fe28ae20de4d56e5c0ba6d2e17fcf90f73"
98
98
  }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * The `reason` a {@link CriterionError} carries.
9
+ *
10
+ * Structural reasons mark a criterion that is malformed as written; they are
11
+ * thrown as a plain `CriterionError`. Evaluation reasons (`InvalidSimple`,
12
+ * `InvalidRegex`, `InvalidJSONPath`, `InvalidXPath`, `InvalidXPathContext`) mark
13
+ * a condition that cannot be evaluated; they are thrown as a
14
+ * {@link CriterionEvaluationError}, which `CriterionEvaluator` turns into an
15
+ * unmet criterion.
16
+ * @public
17
+ */
18
+ const CriterionErrorReason = {
19
+ /** The element is not a Criterion Object. */
20
+ InvalidCriterion: 'invalid-criterion',
21
+ /** The `condition` is missing or empty. */
22
+ MissingCondition: 'missing-condition',
23
+ /** The `type` is present but unreadable. */
24
+ InvalidType: 'invalid-type',
25
+ /** The `type` names no known criterion type. */
26
+ UnknownType: 'unknown-type',
27
+ /** The expression type `version` is present but not a string. */
28
+ InvalidVersion: 'invalid-version',
29
+ /** The expression type `version` is not the one this runner supports. */
30
+ UnsupportedVersion: 'unsupported-version',
31
+ /** The `context` is not a runtime expression. */
32
+ InvalidContext: 'invalid-context',
33
+ /** A `regex`, `jsonpath` or `xpath` criterion has no `context`. */
34
+ MissingContext: 'missing-context',
35
+ /** The `simple` condition cannot be parsed. */
36
+ InvalidSimple: 'invalid-simple',
37
+ /** The `regex` condition is not a valid regular expression. */
38
+ InvalidRegex: 'invalid-regex',
39
+ /** The `jsonpath` condition is not a valid JSONPath query. */
40
+ InvalidJSONPath: 'invalid-jsonpath',
41
+ /** The `xpath` condition is invalid or fails to evaluate. */
42
+ InvalidXPath: 'invalid-xpath',
43
+ /** The resolved `xpath` context is not XML. */
44
+ InvalidXPathContext: 'invalid-xpath-context'
45
+ };
46
+
47
+ /**
48
+ * One of the `CriterionErrorReason` values.
49
+ * @public
50
+ */
51
+ var _default = exports.default = CriterionErrorReason;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The `reason` a {@link CriterionError} carries.
3
+ *
4
+ * Structural reasons mark a criterion that is malformed as written; they are
5
+ * thrown as a plain `CriterionError`. Evaluation reasons (`InvalidSimple`,
6
+ * `InvalidRegex`, `InvalidJSONPath`, `InvalidXPath`, `InvalidXPathContext`) mark
7
+ * a condition that cannot be evaluated; they are thrown as a
8
+ * {@link CriterionEvaluationError}, which `CriterionEvaluator` turns into an
9
+ * unmet criterion.
10
+ * @public
11
+ */
12
+ const CriterionErrorReason = {
13
+ /** The element is not a Criterion Object. */
14
+ InvalidCriterion: 'invalid-criterion',
15
+ /** The `condition` is missing or empty. */
16
+ MissingCondition: 'missing-condition',
17
+ /** The `type` is present but unreadable. */
18
+ InvalidType: 'invalid-type',
19
+ /** The `type` names no known criterion type. */
20
+ UnknownType: 'unknown-type',
21
+ /** The expression type `version` is present but not a string. */
22
+ InvalidVersion: 'invalid-version',
23
+ /** The expression type `version` is not the one this runner supports. */
24
+ UnsupportedVersion: 'unsupported-version',
25
+ /** The `context` is not a runtime expression. */
26
+ InvalidContext: 'invalid-context',
27
+ /** A `regex`, `jsonpath` or `xpath` criterion has no `context`. */
28
+ MissingContext: 'missing-context',
29
+ /** The `simple` condition cannot be parsed. */
30
+ InvalidSimple: 'invalid-simple',
31
+ /** The `regex` condition is not a valid regular expression. */
32
+ InvalidRegex: 'invalid-regex',
33
+ /** The `jsonpath` condition is not a valid JSONPath query. */
34
+ InvalidJSONPath: 'invalid-jsonpath',
35
+ /** The `xpath` condition is invalid or fails to evaluate. */
36
+ InvalidXPath: 'invalid-xpath',
37
+ /** The resolved `xpath` context is not XML. */
38
+ InvalidXPathContext: 'invalid-xpath-context'
39
+ };
40
+
41
+ /**
42
+ * One of the `CriterionErrorReason` values.
43
+ * @public
44
+ */
45
+
46
+ export default CriterionErrorReason;
@@ -10,6 +10,8 @@ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
10
10
  var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
11
11
  var _arazzoRuntimeExpression = require("@swaggerexpert/arazzo-runtime-expression");
12
12
  var _CriterionError = _interopRequireDefault(require("../errors/CriterionError.cjs"));
13
+ var _CriterionEvaluationError = _interopRequireDefault(require("../errors/CriterionEvaluationError.cjs"));
14
+ var _CriterionErrorReason = _interopRequireDefault(require("./CriterionErrorReason.cjs"));
13
15
  var _RegexCriterionEvaluator = _interopRequireDefault(require("./RegexCriterionEvaluator.cjs"));
14
16
  var _SimpleCriterionEvaluator = _interopRequireDefault(require("./SimpleCriterionEvaluator.cjs"));
15
17
  var _JSONPathCriterionEvaluator = _interopRequireDefault(require("./JSONPathCriterionEvaluator.cjs"));
@@ -28,6 +30,10 @@ var _XPathCriterionEvaluator = _interopRequireDefault(require("./XPathCriterionE
28
30
 
29
31
  /**
30
32
  * Options for the CriterionEvaluator.
33
+ *
34
+ * An injected evaluator signals a condition it cannot evaluate by throwing a
35
+ * {@link CriterionEvaluationError}, which fails the criterion; any other error
36
+ * it throws, a plain {@link CriterionError} included, propagates.
31
37
  * @public
32
38
  */
33
39
 
@@ -41,12 +47,26 @@ var _XPathCriterionEvaluator = _interopRequireDefault(require("./XPathCriterionE
41
47
  * pattern to the resolved value.
42
48
  * - `jsonpath` — resolves the `context` runtime expression, then applies the
43
49
  * JSONPath query to the resolved value (met when the query matches). Only the
44
- * `rfc9535` version is supported (the spec default); an explicit other version
45
- * throws.
50
+ * `rfc9535` version is supported; an explicit other version throws.
46
51
  * - `xpath` — resolves the `context` runtime expression, then applies the XPath
47
52
  * 3.1 query to the resolved XML value (met by the Effective Boolean Value).
48
- * Only the `xpath-31` version is supported (the spec default); an explicit
49
- * other version throws.
53
+ * Only the `xpath-31` version is supported; an explicit other version throws.
54
+ *
55
+ * Versions follow Arazzo 1.1.0's Expression Type Object: `rfc9535` and
56
+ * `xpath-31` are allowed values, and an omitted `version` defaults to them.
57
+ * Arazzo 1.0.x lists neither and requires `version`; this evaluator applies
58
+ * the 1.1.0 rule to every document, which accepts more but never evaluates a
59
+ * query under the wrong dialect.
60
+ *
61
+ * A condition that cannot be evaluated fails the criterion (`false`), as
62
+ * Arazzo 1.1.0 requires: a syntax error in the condition, a context the
63
+ * condition cannot apply to (non-XML data for `xpath`), or an XPath evaluation
64
+ * error. The type-specific evaluators report these as a
65
+ * {@link CriterionEvaluationError}, which this facade absorbs; any other error
66
+ * they raise propagates. A criterion that is malformed as written still throws: a
67
+ * missing `condition`, an unknown or unreadable `type`, an unsupported
68
+ * expression `version`, or a `context` that is missing or not a runtime
69
+ * expression.
50
70
  *
51
71
  * The evaluator is agnostic about how runtime expressions are resolved: the
52
72
  * caller supplies a {@link CriterionContextResolver} per evaluation, keeping
@@ -76,7 +96,7 @@ class CriterionEvaluator {
76
96
  evaluate(criterion, resolve) {
77
97
  if (!(0, _apidomNsArazzo.isCriterionElement)(criterion)) {
78
98
  throw new _CriterionError.default('Element is not a Criterion Object', {
79
- reason: 'invalid-criterion'
99
+ reason: _CriterionErrorReason.default.InvalidCriterion
80
100
  });
81
101
  }
82
102
  const condition = (0, _apidomDatamodel.isStringElement)(criterion.condition) ? (0, _apidomCore.toValue)(criterion.condition) : undefined;
@@ -84,33 +104,40 @@ class CriterionEvaluator {
84
104
  // (e.g. an empty regex would match unconditionally), so reject it too.
85
105
  if (condition === undefined || condition === '') {
86
106
  throw new _CriterionError.default('Criterion is missing a "condition"', {
87
- reason: 'missing-condition'
107
+ reason: _CriterionErrorReason.default.MissingCondition
88
108
  });
89
109
  }
90
110
  const type = this.#resolveType(criterion);
91
111
  this.#requireValidContext(criterion, type);
92
- switch (type) {
93
- case 'simple':
94
- return this.#simple.evaluate(condition, resolve);
95
- case 'regex':
96
- return this.#regex.evaluate(condition, this.#resolveContext(criterion, type, resolve));
97
- case 'jsonpath':
98
- // only rfc9535 is supported; it is the spec default, so an omitted
99
- // version is accepted. draft-goessner has different semantics and is
100
- // rejected rather than mis-evaluated.
101
- this.#requireVersion(criterion, type, condition, 'rfc9535');
102
- return this.#jsonpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
103
- case 'xpath':
104
- // only XPath 3.1 is supported; xpath-31 is the spec default, so an
105
- // omitted version is accepted. Older versions are rejected.
106
- this.#requireVersion(criterion, type, condition, 'xpath-31');
107
- return this.#xpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
108
- default:
109
- throw new _CriterionError.default(`Unknown criterion type "${type}"`, {
110
- condition,
111
- type,
112
- reason: 'unknown-type'
113
- });
112
+ try {
113
+ switch (type) {
114
+ case 'simple':
115
+ return this.#simple.evaluate(condition, resolve);
116
+ case 'regex':
117
+ return this.#regex.evaluate(condition, this.#resolveContext(criterion, type, resolve));
118
+ case 'jsonpath':
119
+ // only rfc9535 is supported, Arazzo 1.1.0's default, so an omitted
120
+ // version is accepted. draft-goessner has different semantics and is
121
+ // rejected rather than mis-evaluated.
122
+ this.#requireVersion(criterion, type, condition, 'rfc9535');
123
+ return this.#jsonpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
124
+ case 'xpath':
125
+ // only XPath 3.1 is supported; xpath-31 is Arazzo 1.1.0's default, so
126
+ // an omitted version is accepted. Older versions are rejected.
127
+ this.#requireVersion(criterion, type, condition, 'xpath-31');
128
+ return this.#xpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
129
+ default:
130
+ throw new _CriterionError.default(`Unknown criterion type "${type}"`, {
131
+ condition,
132
+ type,
133
+ reason: _CriterionErrorReason.default.UnknownType
134
+ });
135
+ }
136
+ } catch (error) {
137
+ // Arazzo 1.1.0: a condition that cannot be evaluated MUST evaluate to fail.
138
+ // The structural checks throw a plain CriterionError and still propagate.
139
+ if (error instanceof _CriterionEvaluationError.default) return false;
140
+ throw error;
114
141
  }
115
142
  }
116
143
 
@@ -128,15 +155,15 @@ class CriterionEvaluator {
128
155
  }
129
156
  if ((0, _apidomDatamodel.isStringElement)(type)) return (0, _apidomCore.toValue)(type);
130
157
  throw new _CriterionError.default('Criterion has an invalid "type"', {
131
- reason: 'invalid-type'
158
+ reason: _CriterionErrorReason.default.InvalidType
132
159
  });
133
160
  }
134
161
 
135
162
  /**
136
163
  * Extracts the expression `version` from a Criterion Expression Type Object,
137
164
  * or `undefined` when no version is declared (a bare-string `type`, or a type
138
- * object without a `version`) — in which case the spec default for the type
139
- * applies. A `version` that is present but not a string is malformed and
165
+ * object without a `version`) — in which case Arazzo 1.1.0's default for the
166
+ * type applies. A `version` that is present but not a string is malformed and
140
167
  * throws a {@link CriterionError} rather than silently defaulting.
141
168
  */
142
169
  #resolveVersion(criterion) {
@@ -148,13 +175,13 @@ class CriterionEvaluator {
148
175
  return (0, _apidomCore.toValue)(type.version);
149
176
  }
150
177
  throw new _CriterionError.default('Criterion has an invalid expression type "version"', {
151
- reason: 'invalid-version'
178
+ reason: _CriterionErrorReason.default.InvalidVersion
152
179
  });
153
180
  }
154
181
 
155
182
  /**
156
183
  * Enforces that a versioned condition type declares only the one version this
157
- * runner supports. An omitted version is accepted (it is the spec default);
184
+ * runner supports. An omitted version is accepted (Arazzo 1.1.0's default);
158
185
  * any other declared version throws a {@link CriterionError}.
159
186
  */
160
187
  #requireVersion(criterion, type, condition, supported) {
@@ -163,7 +190,7 @@ class CriterionEvaluator {
163
190
  throw new _CriterionError.default(`Unsupported ${type} version "${version}" (only ${supported})`, {
164
191
  condition,
165
192
  type,
166
- reason: 'unsupported-version'
193
+ reason: _CriterionErrorReason.default.UnsupportedVersion
167
194
  });
168
195
  }
169
196
  }
@@ -181,7 +208,7 @@ class CriterionEvaluator {
181
208
  if (!(0, _apidomDatamodel.isStringElement)(context) || !(0, _arazzoRuntimeExpression.test)((0, _apidomCore.toValue)(context))) {
182
209
  throw new _CriterionError.default('Criterion has a "context" that is not a valid runtime expression', {
183
210
  type,
184
- reason: 'invalid-context'
211
+ reason: _CriterionErrorReason.default.InvalidContext
185
212
  });
186
213
  }
187
214
  }
@@ -196,7 +223,7 @@ class CriterionEvaluator {
196
223
  if (!(0, _apidomDatamodel.isStringElement)(criterion.context)) {
197
224
  throw new _CriterionError.default(`Criterion type "${type}" requires a "context"`, {
198
225
  type,
199
- reason: 'missing-context'
226
+ reason: _CriterionErrorReason.default.MissingContext
200
227
  });
201
228
  }
202
229
  return resolve((0, _apidomCore.toValue)(criterion.context));
@@ -3,6 +3,8 @@ import { isStringElement } from '@speclynx/apidom-datamodel';
3
3
  import { isCriterionElement, isCriterionExpressionTypeElement } from '@speclynx/apidom-ns-arazzo-1';
4
4
  import { test as isRuntimeExpression } from '@swaggerexpert/arazzo-runtime-expression';
5
5
  import CriterionError from "../errors/CriterionError.mjs";
6
+ import CriterionEvaluationError from "../errors/CriterionEvaluationError.mjs";
7
+ import CriterionErrorReason from "./CriterionErrorReason.mjs";
6
8
  import RegexCriterionEvaluator from "./RegexCriterionEvaluator.mjs";
7
9
  import SimpleCriterionEvaluator from "./SimpleCriterionEvaluator.mjs";
8
10
  import JSONPathCriterionEvaluator from "./JSONPathCriterionEvaluator.mjs";
@@ -20,6 +22,10 @@ import XPathCriterionEvaluator from "./XPathCriterionEvaluator.mjs";
20
22
  */
21
23
  /**
22
24
  * Options for the CriterionEvaluator.
25
+ *
26
+ * An injected evaluator signals a condition it cannot evaluate by throwing a
27
+ * {@link CriterionEvaluationError}, which fails the criterion; any other error
28
+ * it throws, a plain {@link CriterionError} included, propagates.
23
29
  * @public
24
30
  */
25
31
  /**
@@ -32,12 +38,26 @@ import XPathCriterionEvaluator from "./XPathCriterionEvaluator.mjs";
32
38
  * pattern to the resolved value.
33
39
  * - `jsonpath` — resolves the `context` runtime expression, then applies the
34
40
  * JSONPath query to the resolved value (met when the query matches). Only the
35
- * `rfc9535` version is supported (the spec default); an explicit other version
36
- * throws.
41
+ * `rfc9535` version is supported; an explicit other version throws.
37
42
  * - `xpath` — resolves the `context` runtime expression, then applies the XPath
38
43
  * 3.1 query to the resolved XML value (met by the Effective Boolean Value).
39
- * Only the `xpath-31` version is supported (the spec default); an explicit
40
- * other version throws.
44
+ * Only the `xpath-31` version is supported; an explicit other version throws.
45
+ *
46
+ * Versions follow Arazzo 1.1.0's Expression Type Object: `rfc9535` and
47
+ * `xpath-31` are allowed values, and an omitted `version` defaults to them.
48
+ * Arazzo 1.0.x lists neither and requires `version`; this evaluator applies
49
+ * the 1.1.0 rule to every document, which accepts more but never evaluates a
50
+ * query under the wrong dialect.
51
+ *
52
+ * A condition that cannot be evaluated fails the criterion (`false`), as
53
+ * Arazzo 1.1.0 requires: a syntax error in the condition, a context the
54
+ * condition cannot apply to (non-XML data for `xpath`), or an XPath evaluation
55
+ * error. The type-specific evaluators report these as a
56
+ * {@link CriterionEvaluationError}, which this facade absorbs; any other error
57
+ * they raise propagates. A criterion that is malformed as written still throws: a
58
+ * missing `condition`, an unknown or unreadable `type`, an unsupported
59
+ * expression `version`, or a `context` that is missing or not a runtime
60
+ * expression.
41
61
  *
42
62
  * The evaluator is agnostic about how runtime expressions are resolved: the
43
63
  * caller supplies a {@link CriterionContextResolver} per evaluation, keeping
@@ -67,7 +87,7 @@ class CriterionEvaluator {
67
87
  evaluate(criterion, resolve) {
68
88
  if (!isCriterionElement(criterion)) {
69
89
  throw new CriterionError('Element is not a Criterion Object', {
70
- reason: 'invalid-criterion'
90
+ reason: CriterionErrorReason.InvalidCriterion
71
91
  });
72
92
  }
73
93
  const condition = isStringElement(criterion.condition) ? toValue(criterion.condition) : undefined;
@@ -75,33 +95,40 @@ class CriterionEvaluator {
75
95
  // (e.g. an empty regex would match unconditionally), so reject it too.
76
96
  if (condition === undefined || condition === '') {
77
97
  throw new CriterionError('Criterion is missing a "condition"', {
78
- reason: 'missing-condition'
98
+ reason: CriterionErrorReason.MissingCondition
79
99
  });
80
100
  }
81
101
  const type = this.#resolveType(criterion);
82
102
  this.#requireValidContext(criterion, type);
83
- switch (type) {
84
- case 'simple':
85
- return this.#simple.evaluate(condition, resolve);
86
- case 'regex':
87
- return this.#regex.evaluate(condition, this.#resolveContext(criterion, type, resolve));
88
- case 'jsonpath':
89
- // only rfc9535 is supported; it is the spec default, so an omitted
90
- // version is accepted. draft-goessner has different semantics and is
91
- // rejected rather than mis-evaluated.
92
- this.#requireVersion(criterion, type, condition, 'rfc9535');
93
- return this.#jsonpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
94
- case 'xpath':
95
- // only XPath 3.1 is supported; xpath-31 is the spec default, so an
96
- // omitted version is accepted. Older versions are rejected.
97
- this.#requireVersion(criterion, type, condition, 'xpath-31');
98
- return this.#xpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
99
- default:
100
- throw new CriterionError(`Unknown criterion type "${type}"`, {
101
- condition,
102
- type,
103
- reason: 'unknown-type'
104
- });
103
+ try {
104
+ switch (type) {
105
+ case 'simple':
106
+ return this.#simple.evaluate(condition, resolve);
107
+ case 'regex':
108
+ return this.#regex.evaluate(condition, this.#resolveContext(criterion, type, resolve));
109
+ case 'jsonpath':
110
+ // only rfc9535 is supported, Arazzo 1.1.0's default, so an omitted
111
+ // version is accepted. draft-goessner has different semantics and is
112
+ // rejected rather than mis-evaluated.
113
+ this.#requireVersion(criterion, type, condition, 'rfc9535');
114
+ return this.#jsonpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
115
+ case 'xpath':
116
+ // only XPath 3.1 is supported; xpath-31 is Arazzo 1.1.0's default, so
117
+ // an omitted version is accepted. Older versions are rejected.
118
+ this.#requireVersion(criterion, type, condition, 'xpath-31');
119
+ return this.#xpath.evaluate(condition, this.#resolveContext(criterion, type, resolve));
120
+ default:
121
+ throw new CriterionError(`Unknown criterion type "${type}"`, {
122
+ condition,
123
+ type,
124
+ reason: CriterionErrorReason.UnknownType
125
+ });
126
+ }
127
+ } catch (error) {
128
+ // Arazzo 1.1.0: a condition that cannot be evaluated MUST evaluate to fail.
129
+ // The structural checks throw a plain CriterionError and still propagate.
130
+ if (error instanceof CriterionEvaluationError) return false;
131
+ throw error;
105
132
  }
106
133
  }
107
134
 
@@ -119,15 +146,15 @@ class CriterionEvaluator {
119
146
  }
120
147
  if (isStringElement(type)) return toValue(type);
121
148
  throw new CriterionError('Criterion has an invalid "type"', {
122
- reason: 'invalid-type'
149
+ reason: CriterionErrorReason.InvalidType
123
150
  });
124
151
  }
125
152
 
126
153
  /**
127
154
  * Extracts the expression `version` from a Criterion Expression Type Object,
128
155
  * or `undefined` when no version is declared (a bare-string `type`, or a type
129
- * object without a `version`) — in which case the spec default for the type
130
- * applies. A `version` that is present but not a string is malformed and
156
+ * object without a `version`) — in which case Arazzo 1.1.0's default for the
157
+ * type applies. A `version` that is present but not a string is malformed and
131
158
  * throws a {@link CriterionError} rather than silently defaulting.
132
159
  */
133
160
  #resolveVersion(criterion) {
@@ -139,13 +166,13 @@ class CriterionEvaluator {
139
166
  return toValue(type.version);
140
167
  }
141
168
  throw new CriterionError('Criterion has an invalid expression type "version"', {
142
- reason: 'invalid-version'
169
+ reason: CriterionErrorReason.InvalidVersion
143
170
  });
144
171
  }
145
172
 
146
173
  /**
147
174
  * Enforces that a versioned condition type declares only the one version this
148
- * runner supports. An omitted version is accepted (it is the spec default);
175
+ * runner supports. An omitted version is accepted (Arazzo 1.1.0's default);
149
176
  * any other declared version throws a {@link CriterionError}.
150
177
  */
151
178
  #requireVersion(criterion, type, condition, supported) {
@@ -154,7 +181,7 @@ class CriterionEvaluator {
154
181
  throw new CriterionError(`Unsupported ${type} version "${version}" (only ${supported})`, {
155
182
  condition,
156
183
  type,
157
- reason: 'unsupported-version'
184
+ reason: CriterionErrorReason.UnsupportedVersion
158
185
  });
159
186
  }
160
187
  }
@@ -172,7 +199,7 @@ class CriterionEvaluator {
172
199
  if (!isStringElement(context) || !isRuntimeExpression(toValue(context))) {
173
200
  throw new CriterionError('Criterion has a "context" that is not a valid runtime expression', {
174
201
  type,
175
- reason: 'invalid-context'
202
+ reason: CriterionErrorReason.InvalidContext
176
203
  });
177
204
  }
178
205
  }
@@ -187,7 +214,7 @@ class CriterionEvaluator {
187
214
  if (!isStringElement(criterion.context)) {
188
215
  throw new CriterionError(`Criterion type "${type}" requires a "context"`, {
189
216
  type,
190
- reason: 'missing-context'
217
+ reason: CriterionErrorReason.MissingContext
191
218
  });
192
219
  }
193
220
  return resolve(toValue(criterion.context));
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _jsonpath = require("@swaggerexpert/jsonpath");
9
- var _CriterionError = _interopRequireDefault(require("../errors/CriterionError.cjs"));
9
+ var _CriterionEvaluationError = _interopRequireDefault(require("../errors/CriterionEvaluationError.cjs"));
10
+ var _CriterionErrorReason = _interopRequireDefault(require("./CriterionErrorReason.cjs"));
10
11
  /**
11
12
  * Evaluates a `jsonpath` Arazzo criterion condition against a resolved context value.
12
13
  *
@@ -25,7 +26,7 @@ class JSONPathCriterionEvaluator {
25
26
  * whether it matched anything.
26
27
  *
27
28
  * Returns `false` when the context is `null` or `undefined`. Throws
28
- * {@link CriterionError} when the condition is not a valid JSONPath query.
29
+ * {@link CriterionEvaluationError} when the condition is not a valid JSONPath query.
29
30
  */
30
31
  evaluate(condition, context) {
31
32
  if (context === null || context === undefined) return false;
@@ -33,11 +34,11 @@ class JSONPathCriterionEvaluator {
33
34
  return (0, _jsonpath.evaluate)(context, condition).length > 0;
34
35
  } catch (error) {
35
36
  if (error instanceof _jsonpath.JSONPathError) {
36
- throw new _CriterionError.default(`Invalid jsonpath criterion condition "${condition}"`, {
37
+ throw new _CriterionEvaluationError.default(`Invalid jsonpath criterion condition "${condition}"`, {
37
38
  cause: error,
38
39
  condition,
39
40
  type: 'jsonpath',
40
- reason: 'invalid-jsonpath'
41
+ reason: _CriterionErrorReason.default.InvalidJSONPath
41
42
  });
42
43
  }
43
44
  throw error;
@@ -1,5 +1,6 @@
1
1
  import { evaluate as evaluateJSONPath, JSONPathError } from '@swaggerexpert/jsonpath';
2
- import CriterionError from "../errors/CriterionError.mjs";
2
+ import CriterionEvaluationError from "../errors/CriterionEvaluationError.mjs";
3
+ import CriterionErrorReason from "./CriterionErrorReason.mjs";
3
4
  /**
4
5
  * Evaluates a `jsonpath` Arazzo criterion condition against a resolved context value.
5
6
  *
@@ -18,7 +19,7 @@ class JSONPathCriterionEvaluator {
18
19
  * whether it matched anything.
19
20
  *
20
21
  * Returns `false` when the context is `null` or `undefined`. Throws
21
- * {@link CriterionError} when the condition is not a valid JSONPath query.
22
+ * {@link CriterionEvaluationError} when the condition is not a valid JSONPath query.
22
23
  */
23
24
  evaluate(condition, context) {
24
25
  if (context === null || context === undefined) return false;
@@ -26,11 +27,11 @@ class JSONPathCriterionEvaluator {
26
27
  return evaluateJSONPath(context, condition).length > 0;
27
28
  } catch (error) {
28
29
  if (error instanceof JSONPathError) {
29
- throw new CriterionError(`Invalid jsonpath criterion condition "${condition}"`, {
30
+ throw new CriterionEvaluationError(`Invalid jsonpath criterion condition "${condition}"`, {
30
31
  cause: error,
31
32
  condition,
32
33
  type: 'jsonpath',
33
- reason: 'invalid-jsonpath'
34
+ reason: CriterionErrorReason.InvalidJSONPath
34
35
  });
35
36
  }
36
37
  throw error;
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _CriterionError = _interopRequireDefault(require("../errors/CriterionError.cjs"));
8
+ var _CriterionEvaluationError = _interopRequireDefault(require("../errors/CriterionEvaluationError.cjs"));
9
+ var _CriterionErrorReason = _interopRequireDefault(require("./CriterionErrorReason.cjs"));
9
10
  /**
10
11
  * Evaluates a `regex` Arazzo criterion condition against a resolved context value.
11
12
  *
@@ -33,7 +34,7 @@ class RegexCriterionEvaluator {
33
34
  * Tests the resolved context value against the regular expression `condition`.
34
35
  *
35
36
  * The context is coerced to a string before matching. Returns `false` when the
36
- * context is `null` or `undefined`. Throws {@link CriterionError} when the
37
+ * context is `null` or `undefined`. Throws {@link CriterionEvaluationError} when the
37
38
  * condition is not a valid regular expression.
38
39
  */
39
40
  evaluate(condition, context) {
@@ -42,11 +43,11 @@ class RegexCriterionEvaluator {
42
43
  try {
43
44
  regExp = new RegExp(condition);
44
45
  } catch (error) {
45
- throw new _CriterionError.default(`Invalid regex criterion condition "${condition}"`, {
46
+ throw new _CriterionEvaluationError.default(`Invalid regex criterion condition "${condition}"`, {
46
47
  cause: error,
47
48
  condition,
48
49
  type: 'regex',
49
- reason: 'invalid-regex'
50
+ reason: _CriterionErrorReason.default.InvalidRegex
50
51
  });
51
52
  }
52
53
  return regExp.test(this.#stringify(context));
@@ -1,4 +1,5 @@
1
- import CriterionError from "../errors/CriterionError.mjs";
1
+ import CriterionEvaluationError from "../errors/CriterionEvaluationError.mjs";
2
+ import CriterionErrorReason from "./CriterionErrorReason.mjs";
2
3
  /**
3
4
  * Evaluates a `regex` Arazzo criterion condition against a resolved context value.
4
5
  *
@@ -26,7 +27,7 @@ class RegexCriterionEvaluator {
26
27
  * Tests the resolved context value against the regular expression `condition`.
27
28
  *
28
29
  * The context is coerced to a string before matching. Returns `false` when the
29
- * context is `null` or `undefined`. Throws {@link CriterionError} when the
30
+ * context is `null` or `undefined`. Throws {@link CriterionEvaluationError} when the
30
31
  * condition is not a valid regular expression.
31
32
  */
32
33
  evaluate(condition, context) {
@@ -35,11 +36,11 @@ class RegexCriterionEvaluator {
35
36
  try {
36
37
  regExp = new RegExp(condition);
37
38
  } catch (error) {
38
- throw new CriterionError(`Invalid regex criterion condition "${condition}"`, {
39
+ throw new CriterionEvaluationError(`Invalid regex criterion condition "${condition}"`, {
39
40
  cause: error,
40
41
  condition,
41
42
  type: 'regex',
42
- reason: 'invalid-regex'
43
+ reason: CriterionErrorReason.InvalidRegex
43
44
  });
44
45
  }
45
46
  return regExp.test(this.#stringify(context));