@usearazzo/runner 1.0.1-alpha.13 → 1.0.1-alpha.15

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.13",
3
+ "version": "1.0.1-alpha.15",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -73,8 +73,8 @@
73
73
  "@swaggerexpert/json-pointer": "^3.0.2",
74
74
  "@swaggerexpert/jsonpath": "^4.0.5",
75
75
  "@swaggerexpert/media-types": "^1.0.1",
76
- "@usearazzo/parser": "1.0.1-alpha.13",
77
- "@usearazzo/resolver": "1.0.1-alpha.13",
76
+ "@usearazzo/parser": "1.0.1-alpha.15",
77
+ "@usearazzo/resolver": "1.0.1-alpha.15",
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": "41c018418a867e1469de0b2393929f7ec129c447"
97
+ "gitHead": "0afacecfa7179fd95b07a8e4a5194a2d7d1c0687"
98
98
  }
@@ -75,6 +75,14 @@ class ParameterIdentity {
75
75
  if (location === undefined || (0, _apidomDatamodel.isNullElement)(location)) return undefined;
76
76
  return (0, _apidomDatamodel.isStringElement)(location) ? (0, _apidomCore.toValue)(location) : null;
77
77
  }
78
+
79
+ /**
80
+ * The locations the Parameter Object defines: Arazzo 1.0.1's closed set plus
81
+ * 1.1.0's `querystring`. 1.0.0's field description also listed `body`, which
82
+ * its own summary of locations did not; 1.0.1 removed it as an erratum, so it
83
+ * is not a location in any version (a payload is the step's `requestBody`).
84
+ */
85
+ static LOCATIONS = ['path', 'query', 'header', 'cookie', 'querystring'];
78
86
  name;
79
87
  location;
80
88
  constructor(name, location) {
@@ -82,6 +90,14 @@ class ParameterIdentity {
82
90
  this.location = location;
83
91
  }
84
92
 
93
+ /**
94
+ * Whether the location is one the Parameter Object defines. An absent or
95
+ * malformed location is not.
96
+ */
97
+ get hasDefinedLocation() {
98
+ return ParameterIdentity.LOCATIONS.includes(this.location);
99
+ }
100
+
85
101
  /**
86
102
  * Whether this and the other identity name the same parameter. A malformed
87
103
  * location equals nothing, its own duplicate included.
@@ -70,6 +70,14 @@ class ParameterIdentity {
70
70
  if (location === undefined || isNullElement(location)) return undefined;
71
71
  return isStringElement(location) ? toValue(location) : null;
72
72
  }
73
+
74
+ /**
75
+ * The locations the Parameter Object defines: Arazzo 1.0.1's closed set plus
76
+ * 1.1.0's `querystring`. 1.0.0's field description also listed `body`, which
77
+ * its own summary of locations did not; 1.0.1 removed it as an erratum, so it
78
+ * is not a location in any version (a payload is the step's `requestBody`).
79
+ */
80
+ static LOCATIONS = ['path', 'query', 'header', 'cookie', 'querystring'];
73
81
  name;
74
82
  location;
75
83
  constructor(name, location) {
@@ -77,6 +85,14 @@ class ParameterIdentity {
77
85
  this.location = location;
78
86
  }
79
87
 
88
+ /**
89
+ * Whether the location is one the Parameter Object defines. An absent or
90
+ * malformed location is not.
91
+ */
92
+ get hasDefinedLocation() {
93
+ return ParameterIdentity.LOCATIONS.includes(this.location);
94
+ }
95
+
80
96
  /**
81
97
  * Whether this and the other identity name the same parameter. A malformed
82
98
  * location equals nothing, its own duplicate included.
@@ -16,6 +16,7 @@ var _OutputResolver = _interopRequireDefault(require("../resolver/OutputResolver
16
16
  var _ActionResolver = _interopRequireDefault(require("../action/ActionResolver.cjs"));
17
17
  var _OpenAPIOperationLocatorNormalizer = _interopRequireDefault(require("./OpenAPIOperationLocatorNormalizer.cjs"));
18
18
  var _ExecutionError = _interopRequireDefault(require("../errors/ExecutionError.cjs"));
19
+ var _ResolverError = _interopRequireDefault(require("../errors/ResolverError.cjs"));
19
20
  var _RuntimeExpressionError = _interopRequireDefault(require("../errors/RuntimeExpressionError.cjs"));
20
21
  var _abort = require("./abort.cjs");
21
22
  /**
@@ -136,6 +137,7 @@ class StepExecutor {
136
137
  reason: 'workflow-step'
137
138
  });
138
139
  }
140
+ this.assertSuccessCriteria(step);
139
141
 
140
142
  // locate which operation the step invokes — reduced to a (document, JSON
141
143
  // Pointer) locator that the operation executor extracts, normalizes,
@@ -231,9 +233,48 @@ class StepExecutor {
231
233
  });
232
234
  }
233
235
 
236
+ /**
237
+ * Throws {@link ResolverError} unless the step's `successCriteria` is absent
238
+ * or a list of Criterion Objects: `malformed-criteria` for one that is
239
+ * present but not a list, `malformed-criterion` for an entry that is not a
240
+ * Criterion Object. Skipping an unreadable entry would turn the author's
241
+ * assertion into a vacuous pass, so it is an authoring error, as an action's
242
+ * unreadable `criteria` is in {@link ActionResolver}.
243
+ *
244
+ * Called before the step's request is sent, so no live side effect precedes
245
+ * the error. Public because the workflow executor checks every step of a
246
+ * workflow with it before any of them runs, a step targeting a `workflowId`
247
+ * included. It passes `workflowId`, which the error then carries: step ids
248
+ * are only unique within a workflow.
249
+ */
250
+ assertSuccessCriteria(step, workflowId) {
251
+ const criteria = step.successCriteria;
252
+ if (criteria === undefined) return;
253
+ const scope = {
254
+ ...(workflowId === undefined ? {} : {
255
+ workflowId
256
+ }),
257
+ stepId: (0, _apidomCore.toValue)(step.stepId),
258
+ target: 'successCriteria'
259
+ };
260
+ if (!(0, _apidomDatamodel.isArrayElement)(criteria)) {
261
+ throw new _ResolverError.default("A step's `successCriteria` is present but is not a list", {
262
+ ...scope,
263
+ reason: 'malformed-criteria'
264
+ });
265
+ }
266
+ if (![...criteria].every(_apidomNsArazzo.isCriterionElement)) {
267
+ throw new _ResolverError.default("A step's `successCriteria` contains an entry that is not a Criterion Object", {
268
+ ...scope,
269
+ reason: 'malformed-criterion'
270
+ });
271
+ }
272
+ }
273
+
234
274
  /**
235
275
  * Evaluates the step's `successCriteria`; all criteria must pass. A step with
236
- * no criteria succeeds on a received response.
276
+ * no criteria succeeds on a received response. An unreadable
277
+ * `successCriteria` throws, see {@link StepExecutor.assertSuccessCriteria}.
237
278
  *
238
279
  * Public for the same reason as {@link StepExecutor.selectActions}: a step
239
280
  * targeting a `workflowId` is run by the workflow executor and never reaches
@@ -241,15 +282,12 @@ class StepExecutor {
241
282
  * assertion about the step and must be evaluated somewhere.
242
283
  */
243
284
  evaluateCriteria(step, context) {
285
+ this.assertSuccessCriteria(step);
244
286
  const criteria = step.successCriteria;
245
- // no (or non-array) successCriteria: the step succeeds on a received response.
246
- if (!(0, _apidomDatamodel.isArrayElement)(criteria)) return true;
247
- for (const criterion of criteria) {
248
- if (!(0, _apidomNsArazzo.isCriterionElement)(criterion)) continue;
249
- const met = this.#criterionEvaluator.evaluate(criterion, expression => this.#evaluate(context, expression));
250
- if (!met) return false;
251
- }
252
- return true;
287
+ if (criteria === undefined) return true;
288
+
289
+ // assertSuccessCriteria above guarantees every entry is a Criterion Object
290
+ return [...criteria].every(criterion => this.#criterionEvaluator.evaluate(criterion, expression => this.#evaluate(context, expression)));
253
291
  }
254
292
 
255
293
  /**
@@ -9,6 +9,7 @@ import OutputResolver from "../resolver/OutputResolver.mjs";
9
9
  import ActionResolver from "../action/ActionResolver.mjs";
10
10
  import OpenAPIOperationLocatorNormalizer from "./OpenAPIOperationLocatorNormalizer.mjs";
11
11
  import ExecutionError from "../errors/ExecutionError.mjs";
12
+ import ResolverError from "../errors/ResolverError.mjs";
12
13
  import RuntimeExpressionError from "../errors/RuntimeExpressionError.mjs";
13
14
  import { readAbortSignal, throwIfAborted } from "./abort.mjs";
14
15
  /**
@@ -129,6 +130,7 @@ class StepExecutor {
129
130
  reason: 'workflow-step'
130
131
  });
131
132
  }
133
+ this.assertSuccessCriteria(step);
132
134
 
133
135
  // locate which operation the step invokes — reduced to a (document, JSON
134
136
  // Pointer) locator that the operation executor extracts, normalizes,
@@ -224,9 +226,48 @@ class StepExecutor {
224
226
  });
225
227
  }
226
228
 
229
+ /**
230
+ * Throws {@link ResolverError} unless the step's `successCriteria` is absent
231
+ * or a list of Criterion Objects: `malformed-criteria` for one that is
232
+ * present but not a list, `malformed-criterion` for an entry that is not a
233
+ * Criterion Object. Skipping an unreadable entry would turn the author's
234
+ * assertion into a vacuous pass, so it is an authoring error, as an action's
235
+ * unreadable `criteria` is in {@link ActionResolver}.
236
+ *
237
+ * Called before the step's request is sent, so no live side effect precedes
238
+ * the error. Public because the workflow executor checks every step of a
239
+ * workflow with it before any of them runs, a step targeting a `workflowId`
240
+ * included. It passes `workflowId`, which the error then carries: step ids
241
+ * are only unique within a workflow.
242
+ */
243
+ assertSuccessCriteria(step, workflowId) {
244
+ const criteria = step.successCriteria;
245
+ if (criteria === undefined) return;
246
+ const scope = {
247
+ ...(workflowId === undefined ? {} : {
248
+ workflowId
249
+ }),
250
+ stepId: toValue(step.stepId),
251
+ target: 'successCriteria'
252
+ };
253
+ if (!isArrayElement(criteria)) {
254
+ throw new ResolverError("A step's `successCriteria` is present but is not a list", {
255
+ ...scope,
256
+ reason: 'malformed-criteria'
257
+ });
258
+ }
259
+ if (![...criteria].every(isCriterionElement)) {
260
+ throw new ResolverError("A step's `successCriteria` contains an entry that is not a Criterion Object", {
261
+ ...scope,
262
+ reason: 'malformed-criterion'
263
+ });
264
+ }
265
+ }
266
+
227
267
  /**
228
268
  * Evaluates the step's `successCriteria`; all criteria must pass. A step with
229
- * no criteria succeeds on a received response.
269
+ * no criteria succeeds on a received response. An unreadable
270
+ * `successCriteria` throws, see {@link StepExecutor.assertSuccessCriteria}.
230
271
  *
231
272
  * Public for the same reason as {@link StepExecutor.selectActions}: a step
232
273
  * targeting a `workflowId` is run by the workflow executor and never reaches
@@ -234,15 +275,12 @@ class StepExecutor {
234
275
  * assertion about the step and must be evaluated somewhere.
235
276
  */
236
277
  evaluateCriteria(step, context) {
278
+ this.assertSuccessCriteria(step);
237
279
  const criteria = step.successCriteria;
238
- // no (or non-array) successCriteria: the step succeeds on a received response.
239
- if (!isArrayElement(criteria)) return true;
240
- for (const criterion of criteria) {
241
- if (!isCriterionElement(criterion)) continue;
242
- const met = this.#criterionEvaluator.evaluate(criterion, expression => this.#evaluate(context, expression));
243
- if (!met) return false;
244
- }
245
- return true;
280
+ if (criteria === undefined) return true;
281
+
282
+ // assertSuccessCriteria above guarantees every entry is a Criterion Object
283
+ return [...criteria].every(criterion => this.#criterionEvaluator.evaluate(criterion, expression => this.#evaluate(context, expression)));
246
284
  }
247
285
 
248
286
  /**
@@ -297,6 +297,10 @@ class WorkflowExecutor {
297
297
  // at `#result` where it used to be resolved, means the throw lands before
298
298
  // the first request rather than after the last.
299
299
  this.#validateWorkflowOutputsShape(workflow, workflowId);
300
+ // and to every step's `successCriteria`, a step calling a workflow
301
+ // included: an unreadable assertion found at step three must not cost the
302
+ // run the requests of steps one and two.
303
+ for (const step of steps) this.#stepExecutor.assertSuccessCriteria(step, workflowId);
300
304
  const dependencies = await this.#runDependencies(workflow, invocation, scope);
301
305
  if (dependencies.some(dependency => this.#settledFailed(dependency))) {
302
306
  // a declared prerequisite did not complete, so this workflow cannot be
@@ -283,6 +283,10 @@ class WorkflowExecutor {
283
283
  // at `#result` where it used to be resolved, means the throw lands before
284
284
  // the first request rather than after the last.
285
285
  this.#validateWorkflowOutputsShape(workflow, workflowId);
286
+ // and to every step's `successCriteria`, a step calling a workflow
287
+ // included: an unreadable assertion found at step three must not cost the
288
+ // run the requests of steps one and two.
289
+ for (const step of steps) this.#stepExecutor.assertSuccessCriteria(step, workflowId);
286
290
  const dependencies = await this.#runDependencies(workflow, invocation, scope);
287
291
  if (dependencies.some(dependency => this.#settledFailed(dependency))) {
288
292
  // a declared prerequisite did not complete, so this workflow cannot be
@@ -35,7 +35,11 @@ var _StepParameterResolver = _interopRequireDefault(require("./StepParameterReso
35
35
  * instead would let it capture *every* declared location of that name — see
36
36
  * `ParameterDelivery` for the lookup order that makes it so. A
37
37
  * non-string location throws for the same reason it deduplicates with nothing
38
- * in the normalizer: it names no location. And two *different* parameters the
38
+ * in the normalizer: it names no location. So does a location outside
39
+ * `path`, `query`, `header`, `cookie` and `querystring`: Arazzo 1.0.1 removed
40
+ * `in: body`, and forwarding one would let it still deliver a request body
41
+ * against an OpenAPI 2.0 operation, bypassing the step's `requestBody`, while
42
+ * an unknown location reaches nothing at all. And two *different* parameters the
39
43
  * map reports as colliding cannot both be delivered, so a collision throws
40
44
  * rather than silently dropping one — whether they collide on one key (the
41
45
  * scheme is not injective: a `querystring` parameter named `header.token` and
@@ -96,6 +100,13 @@ class OpenAPIOperationParameterResolver extends _StepParameterResolver.default {
96
100
  reason: 'malformed-location'
97
101
  });
98
102
  }
103
+ if (!identity.hasDefinedLocation) {
104
+ throw new _ResolverError.default(`Parameter "${name}" has location "${location}", which is not one of ` + `${_ParameterIdentity.default.LOCATIONS.join(', ')}`, {
105
+ ...scope,
106
+ target: name,
107
+ reason: 'invalid-location'
108
+ });
109
+ }
99
110
  const {
100
111
  key,
101
112
  outcome
@@ -28,7 +28,11 @@ import StepParameterResolver from "./StepParameterResolver.mjs";
28
28
  * instead would let it capture *every* declared location of that name — see
29
29
  * `ParameterDelivery` for the lookup order that makes it so. A
30
30
  * non-string location throws for the same reason it deduplicates with nothing
31
- * in the normalizer: it names no location. And two *different* parameters the
31
+ * in the normalizer: it names no location. So does a location outside
32
+ * `path`, `query`, `header`, `cookie` and `querystring`: Arazzo 1.0.1 removed
33
+ * `in: body`, and forwarding one would let it still deliver a request body
34
+ * against an OpenAPI 2.0 operation, bypassing the step's `requestBody`, while
35
+ * an unknown location reaches nothing at all. And two *different* parameters the
32
36
  * map reports as colliding cannot both be delivered, so a collision throws
33
37
  * rather than silently dropping one — whether they collide on one key (the
34
38
  * scheme is not injective: a `querystring` parameter named `header.token` and
@@ -89,6 +93,13 @@ class OpenAPIOperationParameterResolver extends StepParameterResolver {
89
93
  reason: 'malformed-location'
90
94
  });
91
95
  }
96
+ if (!identity.hasDefinedLocation) {
97
+ throw new ResolverError(`Parameter "${name}" has location "${location}", which is not one of ` + `${ParameterIdentity.LOCATIONS.join(', ')}`, {
98
+ ...scope,
99
+ target: name,
100
+ reason: 'invalid-location'
101
+ });
102
+ }
92
103
  const {
93
104
  key,
94
105
  outcome
package/types/runner.d.ts CHANGED
@@ -1196,7 +1196,11 @@ export declare interface OpenAPIOperationNormalizerOptions {
1196
1196
  * instead would let it capture *every* declared location of that name — see
1197
1197
  * `ParameterDelivery` for the lookup order that makes it so. A
1198
1198
  * non-string location throws for the same reason it deduplicates with nothing
1199
- * in the normalizer: it names no location. And two *different* parameters the
1199
+ * in the normalizer: it names no location. So does a location outside
1200
+ * `path`, `query`, `header`, `cookie` and `querystring`: Arazzo 1.0.1 removed
1201
+ * `in: body`, and forwarding one would let it still deliver a request body
1202
+ * against an OpenAPI 2.0 operation, bypassing the step's `requestBody`, while
1203
+ * an unknown location reaches nothing at all. And two *different* parameters the
1200
1204
  * map reports as colliding cannot both be delivered, so a collision throws
1201
1205
  * rather than silently dropping one — whether they collide on one key (the
1202
1206
  * scheme is not injective: a `querystring` parameter named `header.token` and
@@ -1885,9 +1889,25 @@ export declare class StepExecutor {
1885
1889
  * — rather than as the withdrawal it is.
1886
1890
  */
1887
1891
  execute(step: StepElement, state: ContextSource, executeOptions?: Record<string, unknown>): Promise<StepExecutionResult>;
1892
+ /**
1893
+ * Throws {@link ResolverError} unless the step's `successCriteria` is absent
1894
+ * or a list of Criterion Objects: `malformed-criteria` for one that is
1895
+ * present but not a list, `malformed-criterion` for an entry that is not a
1896
+ * Criterion Object. Skipping an unreadable entry would turn the author's
1897
+ * assertion into a vacuous pass, so it is an authoring error, as an action's
1898
+ * unreadable `criteria` is in {@link ActionResolver}.
1899
+ *
1900
+ * Called before the step's request is sent, so no live side effect precedes
1901
+ * the error. Public because the workflow executor checks every step of a
1902
+ * workflow with it before any of them runs, a step targeting a `workflowId`
1903
+ * included. It passes `workflowId`, which the error then carries: step ids
1904
+ * are only unique within a workflow.
1905
+ */
1906
+ assertSuccessCriteria(step: StepElement, workflowId?: string): void;
1888
1907
  /**
1889
1908
  * Evaluates the step's `successCriteria`; all criteria must pass. A step with
1890
- * no criteria succeeds on a received response.
1909
+ * no criteria succeeds on a received response. An unreadable
1910
+ * `successCriteria` throws, see {@link StepExecutor.assertSuccessCriteria}.
1891
1911
  *
1892
1912
  * Public for the same reason as {@link StepExecutor.selectActions}: a step
1893
1913
  * targeting a `workflowId` is run by the workflow executor and never reaches