@usearazzo/runner 1.0.1-alpha.34 → 1.0.1-alpha.35

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 (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +6 -1
  3. package/dist/arazzo-runner.browser.js +687 -317
  4. package/dist/arazzo-runner.browser.min.js +1 -1
  5. package/package.json +52 -7
  6. package/src/errors/ExecutionError.cjs +2 -0
  7. package/src/errors/ExecutionError.mjs +2 -0
  8. package/src/executor/OpenAPIOperationExecutor.cjs +58 -47
  9. package/src/executor/OpenAPIOperationExecutor.mjs +58 -47
  10. package/src/executor/WorkflowExecutor.cjs +302 -160
  11. package/src/executor/WorkflowExecutor.mjs +302 -160
  12. package/src/index.cjs +14 -0
  13. package/src/index.mjs +2 -0
  14. package/src/observability/EventChannel.cjs +30 -20
  15. package/src/observability/EventChannel.mjs +30 -23
  16. package/src/observability/Redactor.cjs +7 -5
  17. package/src/observability/Redactor.mjs +7 -5
  18. package/src/observability/combineObservers.cjs +18 -0
  19. package/src/observability/combineObservers.mjs +12 -0
  20. package/src/observability/instrument.cjs +159 -0
  21. package/src/observability/instrument.mjs +144 -0
  22. package/src/observability/logging/LoggingObserver.cjs +177 -0
  23. package/src/observability/logging/LoggingObserver.mjs +172 -0
  24. package/src/observability/logging/index.cjs +13 -0
  25. package/src/observability/logging/index.mjs +1 -0
  26. package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.cjs +321 -0
  27. package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.mjs +313 -0
  28. package/src/observability/opentelemetry/index.cjs +13 -0
  29. package/src/observability/opentelemetry/index.mjs +1 -0
  30. package/src/observability/stream/EventStream.cjs +112 -0
  31. package/src/observability/stream/EventStream.mjs +107 -0
  32. package/src/observability/stream/index.cjs +13 -0
  33. package/src/observability/stream/index.mjs +1 -0
  34. package/src/registry/DocumentRegistry.cjs +14 -9
  35. package/src/registry/DocumentRegistry.mjs +14 -9
  36. package/src/version.cjs +9 -0
  37. package/src/version.mjs +3 -0
  38. package/types/observability/logging/LoggingObserver.d.ts +82 -0
  39. package/types/observability/logging/index.d.ts +2 -0
  40. package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.ts +84 -0
  41. package/types/observability/opentelemetry/index.d.ts +2 -0
  42. package/types/observability/stream/EventStream.d.ts +68 -0
  43. package/types/observability/stream/index.d.ts +2 -0
  44. package/types/runner.d.ts +131 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearazzo/runner",
3
- "version": "1.0.1-alpha.34",
3
+ "version": "1.0.1-alpha.35",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -28,11 +28,41 @@
28
28
  "unpkg": "./dist/arazzo-runner.browser.min.js",
29
29
  "main": "./src/index.cjs",
30
30
  "exports": {
31
- "types": "./types/runner.d.ts",
32
- "import": "./src/index.mjs",
33
- "require": "./src/index.cjs"
31
+ ".": {
32
+ "types": "./types/runner.d.ts",
33
+ "import": "./src/index.mjs",
34
+ "require": "./src/index.cjs"
35
+ },
36
+ "./observability/logging": {
37
+ "types": "./types/observability/logging/index.d.ts",
38
+ "import": "./src/observability/logging/index.mjs",
39
+ "require": "./src/observability/logging/index.cjs"
40
+ },
41
+ "./observability/stream": {
42
+ "types": "./types/observability/stream/index.d.ts",
43
+ "import": "./src/observability/stream/index.mjs",
44
+ "require": "./src/observability/stream/index.cjs"
45
+ },
46
+ "./observability/opentelemetry": {
47
+ "types": "./types/observability/opentelemetry/index.d.ts",
48
+ "import": "./src/observability/opentelemetry/index.mjs",
49
+ "require": "./src/observability/opentelemetry/index.cjs"
50
+ }
34
51
  },
35
52
  "types": "./types/runner.d.ts",
53
+ "typesVersions": {
54
+ "*": {
55
+ "observability/logging": [
56
+ "./types/observability/logging/index.d.ts"
57
+ ],
58
+ "observability/stream": [
59
+ "./types/observability/stream/index.d.ts"
60
+ ],
61
+ "observability/opentelemetry": [
62
+ "./types/observability/opentelemetry/index.d.ts"
63
+ ]
64
+ }
65
+ },
36
66
  "scripts": {
37
67
  "build": "npm run clean && npm run build:es && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:cjs build:umd:browser",
38
68
  "build:es": "npm run build:swagger-client && cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
@@ -43,6 +73,7 @@
43
73
  "lint:fix": "eslint ./ --fix",
44
74
  "clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types",
45
75
  "typescript:check-types": "tsc --noEmit",
76
+ "version": "node ../../scripts/version-update.mjs",
46
77
  "typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
47
78
  "test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
48
79
  "test:e2e": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha --config .mocharc.e2e.json",
@@ -73,8 +104,8 @@
73
104
  "@swaggerexpert/json-pointer": "^3.0.2",
74
105
  "@swaggerexpert/jsonpath": "^4.0.5",
75
106
  "@swaggerexpert/media-types": "^1.0.2",
76
- "@usearazzo/parser": "1.0.1-alpha.34",
77
- "@usearazzo/resolver": "1.0.1-alpha.34",
107
+ "@usearazzo/parser": "1.0.1-alpha.35",
108
+ "@usearazzo/resolver": "1.0.1-alpha.35",
78
109
  "@xmldom/xmldom": "^0.9.12",
79
110
  "fontoxpath": "^3.34.0",
80
111
  "ramda": "^0.32.0",
@@ -87,13 +118,27 @@
87
118
  "src/**/*.cjs",
88
119
  "dist/",
89
120
  "types/runner.d.ts",
121
+ "types/observability/logging/",
122
+ "types/observability/stream/",
123
+ "types/observability/opentelemetry/",
90
124
  "LICENSE",
91
125
  "NOTICE",
92
126
  "README.md",
93
127
  "CHANGELOG.md"
94
128
  ],
129
+ "peerDependencies": {
130
+ "@opentelemetry/api": "^1.9.0"
131
+ },
132
+ "peerDependenciesMeta": {
133
+ "@opentelemetry/api": {
134
+ "optional": true
135
+ }
136
+ },
95
137
  "devDependencies": {
138
+ "@opentelemetry/api": "~1.9.0",
139
+ "@opentelemetry/context-async-hooks": "^2.12.1",
140
+ "@opentelemetry/sdk-trace-base": "^2.12.0",
96
141
  "swagger-client": "^3.39.0"
97
142
  },
98
- "gitHead": "38ba1b2907b4af68cf4cf615ea8031b93fed60e6"
143
+ "gitHead": "8a1fa9ce51886f2788d381483d4aa0763dfd5d4c"
99
144
  }
@@ -27,6 +27,8 @@ class ExecutionError extends _ArazzoRunnerError.default {
27
27
  static GotoTargetMissing = 'goto-target-missing';
28
28
  /** A `goto` action's `stepId` names no step in the workflow. */
29
29
  static GotoTargetNotFound = 'goto-target-not-found';
30
+ /** A process-wide instrumentation wrap (see `instrument`) settled without running its workflow or step. */
31
+ static InstrumentationWrap = 'instrumentation-wrap';
30
32
  /** An `operationId` or `operationPath` is not a valid operation reference. */
31
33
  static InvalidOperationReference = 'invalid-operation-reference';
32
34
  /** A `workflowId` is not a valid `$sourceDescriptions.{name}.{workflowId}` expression. */
@@ -20,6 +20,8 @@ class ExecutionError extends ArazzoRunnerError {
20
20
  static GotoTargetMissing = 'goto-target-missing';
21
21
  /** A `goto` action's `stepId` names no step in the workflow. */
22
22
  static GotoTargetNotFound = 'goto-target-not-found';
23
+ /** A process-wide instrumentation wrap (see `instrument`) settled without running its workflow or step. */
24
+ static InstrumentationWrap = 'instrumentation-wrap';
23
25
  /** An `operationId` or `operationPath` is not a valid operation reference. */
24
26
  static InvalidOperationReference = 'invalid-operation-reference';
25
27
  /** A `workflowId` is not a valid `$sourceDescriptions.{name}.{workflowId}` expression. */
@@ -171,6 +171,7 @@ class OpenAPIOperationExecutor {
171
171
  #operationNormalizer;
172
172
  #documentAssembler;
173
173
  #captureBodies;
174
+ // emits only while `hasObservers`, so an unobserved block builds no events
174
175
  #events;
175
176
  constructor(options = {}) {
176
177
  this.#httpClient = options.httpClient ?? _HTTPClientFetch.default;
@@ -179,7 +180,7 @@ class OpenAPIOperationExecutor {
179
180
  this.#operationExtractor = options.operationExtractor ?? new _OpenAPIOperationExtractor.default();
180
181
  this.#operationNormalizer = options.operationNormalizer ?? new _OpenAPIOperationNormalizer.default();
181
182
  this.#documentAssembler = options.documentAssembler ?? new _OpenAPIDocumentAssembler.default();
182
- this.#events = _EventChannel.default.open({
183
+ this.#events = new _EventChannel.default({
183
184
  observer: options.observer,
184
185
  now: options.now
185
186
  });
@@ -239,26 +240,32 @@ class OpenAPIOperationExecutor {
239
240
  }
240
241
  })
241
242
  };
242
- this.#events?.emit({
243
- type: 'openapi-operation-normalize-start',
244
- ...context,
245
- runId,
246
- location: location()
247
- });
243
+ if (this.#events.hasObservers) {
244
+ this.#events.emit({
245
+ type: 'openapi:operation:normalize:start',
246
+ ...context,
247
+ runId,
248
+ location: location()
249
+ });
250
+ }
248
251
  const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
249
- this.#events?.emit({
250
- type: 'openapi-operation-normalize-settled',
251
- ...context,
252
- runId,
253
- location: location()
254
- });
252
+ if (this.#events.hasObservers) {
253
+ this.#events.emit({
254
+ type: 'openapi:operation:normalize:settled',
255
+ ...context,
256
+ runId,
257
+ location: location()
258
+ });
259
+ }
255
260
  const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
256
- this.#events?.emit({
257
- type: 'openapi-operation-assembled',
258
- ...context,
259
- runId,
260
- location: location()
261
- });
261
+ if (this.#events.hasObservers) {
262
+ this.#events.emit({
263
+ type: 'openapi:operation:assembled',
264
+ ...context,
265
+ runId,
266
+ location: location()
267
+ });
268
+ }
262
269
  const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'runId', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
263
270
 
264
271
  // each step derives the next options rather than editing in place
@@ -303,20 +310,22 @@ class OpenAPIOperationExecutor {
303
310
  },
304
311
  body: request.body
305
312
  };
306
- this.#events?.emit({
307
- type: 'openapi-operation-request-start',
308
- ...context,
309
- runId,
310
- location: location(),
311
- request: {
312
- method: request.method,
313
- url: request.url,
314
- headers: request.headers,
315
- ...(this.#captureBodies ? {
316
- body: request.body
317
- } : {})
318
- }
319
- });
313
+ if (this.#events.hasObservers) {
314
+ this.#events.emit({
315
+ type: 'openapi:operation:request:start',
316
+ ...context,
317
+ runId,
318
+ location: location(),
319
+ request: {
320
+ method: request.method,
321
+ url: request.url,
322
+ headers: request.headers,
323
+ ...(this.#captureBodies ? {
324
+ body: request.body
325
+ } : {})
326
+ }
327
+ });
328
+ }
320
329
  let rawResponse;
321
330
  try {
322
331
  rawResponse = await this.#httpClient(request);
@@ -327,20 +336,22 @@ class OpenAPIOperationExecutor {
327
336
  });
328
337
  }
329
338
  const response = await this.#responseNormalizer.normalize(rawResponse, requestInfo);
330
- this.#events?.emit({
331
- type: 'openapi-operation-request-settled',
332
- ...context,
333
- runId,
334
- location: location(),
335
- response: {
336
- status: response.status,
337
- headers: response.headers,
338
- size: response.size,
339
- ...(this.#captureBodies ? {
340
- body: response.body
341
- } : {})
342
- }
343
- });
339
+ if (this.#events.hasObservers) {
340
+ this.#events.emit({
341
+ type: 'openapi:operation:request:settled',
342
+ ...context,
343
+ runId,
344
+ location: location(),
345
+ response: {
346
+ status: response.status,
347
+ headers: response.headers,
348
+ size: response.size,
349
+ ...(this.#captureBodies ? {
350
+ body: response.body
351
+ } : {})
352
+ }
353
+ });
354
+ }
344
355
  return response;
345
356
  }
346
357
 
@@ -159,6 +159,7 @@ class OpenAPIOperationExecutor {
159
159
  #operationNormalizer;
160
160
  #documentAssembler;
161
161
  #captureBodies;
162
+ // emits only while `hasObservers`, so an unobserved block builds no events
162
163
  #events;
163
164
  constructor(options = {}) {
164
165
  this.#httpClient = options.httpClient ?? httpClientFetch;
@@ -167,7 +168,7 @@ class OpenAPIOperationExecutor {
167
168
  this.#operationExtractor = options.operationExtractor ?? new OpenAPIOperationExtractor();
168
169
  this.#operationNormalizer = options.operationNormalizer ?? new OpenAPIOperationNormalizer();
169
170
  this.#documentAssembler = options.documentAssembler ?? new OpenAPIDocumentAssembler();
170
- this.#events = EventChannel.open({
171
+ this.#events = new EventChannel({
171
172
  observer: options.observer,
172
173
  now: options.now
173
174
  });
@@ -227,26 +228,32 @@ class OpenAPIOperationExecutor {
227
228
  }
228
229
  })
229
230
  };
230
- this.#events?.emit({
231
- type: 'openapi-operation-normalize-start',
232
- ...context,
233
- runId,
234
- location: location()
235
- });
231
+ if (this.#events.hasObservers) {
232
+ this.#events.emit({
233
+ type: 'openapi:operation:normalize:start',
234
+ ...context,
235
+ runId,
236
+ location: location()
237
+ });
238
+ }
236
239
  const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
237
- this.#events?.emit({
238
- type: 'openapi-operation-normalize-settled',
239
- ...context,
240
- runId,
241
- location: location()
242
- });
240
+ if (this.#events.hasObservers) {
241
+ this.#events.emit({
242
+ type: 'openapi:operation:normalize:settled',
243
+ ...context,
244
+ runId,
245
+ location: location()
246
+ });
247
+ }
243
248
  const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
244
- this.#events?.emit({
245
- type: 'openapi-operation-assembled',
246
- ...context,
247
- runId,
248
- location: location()
249
- });
249
+ if (this.#events.hasObservers) {
250
+ this.#events.emit({
251
+ type: 'openapi:operation:assembled',
252
+ ...context,
253
+ runId,
254
+ location: location()
255
+ });
256
+ }
250
257
  const rest = omit(['requestInterceptor', 'step', 'runId', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
251
258
 
252
259
  // each step derives the next options rather than editing in place
@@ -291,20 +298,22 @@ class OpenAPIOperationExecutor {
291
298
  },
292
299
  body: request.body
293
300
  };
294
- this.#events?.emit({
295
- type: 'openapi-operation-request-start',
296
- ...context,
297
- runId,
298
- location: location(),
299
- request: {
300
- method: request.method,
301
- url: request.url,
302
- headers: request.headers,
303
- ...(this.#captureBodies ? {
304
- body: request.body
305
- } : {})
306
- }
307
- });
301
+ if (this.#events.hasObservers) {
302
+ this.#events.emit({
303
+ type: 'openapi:operation:request:start',
304
+ ...context,
305
+ runId,
306
+ location: location(),
307
+ request: {
308
+ method: request.method,
309
+ url: request.url,
310
+ headers: request.headers,
311
+ ...(this.#captureBodies ? {
312
+ body: request.body
313
+ } : {})
314
+ }
315
+ });
316
+ }
308
317
  let rawResponse;
309
318
  try {
310
319
  rawResponse = await this.#httpClient(request);
@@ -315,20 +324,22 @@ class OpenAPIOperationExecutor {
315
324
  });
316
325
  }
317
326
  const response = await this.#responseNormalizer.normalize(rawResponse, requestInfo);
318
- this.#events?.emit({
319
- type: 'openapi-operation-request-settled',
320
- ...context,
321
- runId,
322
- location: location(),
323
- response: {
324
- status: response.status,
325
- headers: response.headers,
326
- size: response.size,
327
- ...(this.#captureBodies ? {
328
- body: response.body
329
- } : {})
330
- }
331
- });
327
+ if (this.#events.hasObservers) {
328
+ this.#events.emit({
329
+ type: 'openapi:operation:request:settled',
330
+ ...context,
331
+ runId,
332
+ location: location(),
333
+ response: {
334
+ status: response.status,
335
+ headers: response.headers,
336
+ size: response.size,
337
+ ...(this.#captureBodies ? {
338
+ body: response.body
339
+ } : {})
340
+ }
341
+ });
342
+ }
332
343
  return response;
333
344
  }
334
345