@usearazzo/runner 1.0.1-alpha.33 → 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 (72) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +15 -1
  3. package/dist/arazzo-runner.browser.js +1516 -265
  4. package/dist/arazzo-runner.browser.min.js +1 -1
  5. package/package.json +64 -18
  6. package/src/ArazzoRunner.cjs +26 -3
  7. package/src/ArazzoRunner.mjs +26 -3
  8. package/src/client/OpenAPIOperationResponse.cjs +9 -0
  9. package/src/client/OpenAPIOperationResponse.mjs +9 -0
  10. package/src/document/APIDocument.cjs +53 -0
  11. package/src/document/APIDocument.mjs +53 -0
  12. package/src/errors/ExecutionError.cjs +2 -0
  13. package/src/errors/ExecutionError.mjs +2 -0
  14. package/src/executor/OpenAPIOperationExecutor.cjs +77 -6
  15. package/src/executor/OpenAPIOperationExecutor.mjs +77 -6
  16. package/src/executor/StepExecutor.cjs +16 -2
  17. package/src/executor/StepExecutor.mjs +16 -2
  18. package/src/executor/StepRetryRunner.cjs +5 -3
  19. package/src/executor/StepRetryRunner.mjs +5 -3
  20. package/src/executor/StepTransitionInterpreter.cjs +1 -1
  21. package/src/executor/StepTransitionInterpreter.mjs +1 -1
  22. package/src/executor/WorkflowCallStack.cjs +1 -1
  23. package/src/executor/WorkflowCallStack.mjs +1 -1
  24. package/src/executor/WorkflowExecutor.cjs +447 -89
  25. package/src/executor/WorkflowExecutor.mjs +447 -89
  26. package/src/index.cjs +21 -0
  27. package/src/index.mjs +4 -0
  28. package/src/observability/ArazzoRunnerEvent.cjs +5 -0
  29. package/src/observability/ArazzoRunnerEvent.mjs +1 -0
  30. package/src/observability/DocumentRegistryEvent.cjs +5 -0
  31. package/src/observability/DocumentRegistryEvent.mjs +1 -0
  32. package/src/observability/EventChannel.cjs +106 -0
  33. package/src/observability/EventChannel.mjs +98 -0
  34. package/src/observability/OpenAPIOperationEvent.cjs +5 -0
  35. package/src/observability/OpenAPIOperationEvent.mjs +1 -0
  36. package/src/observability/Redactor.cjs +215 -0
  37. package/src/observability/Redactor.mjs +210 -0
  38. package/src/observability/WorkflowExecutionEvent.cjs +5 -0
  39. package/src/observability/WorkflowExecutionEvent.mjs +1 -0
  40. package/src/observability/combineObservers.cjs +18 -0
  41. package/src/observability/combineObservers.mjs +12 -0
  42. package/src/observability/instrument.cjs +159 -0
  43. package/src/observability/instrument.mjs +144 -0
  44. package/src/observability/logging/LoggingObserver.cjs +177 -0
  45. package/src/observability/logging/LoggingObserver.mjs +172 -0
  46. package/src/observability/logging/index.cjs +13 -0
  47. package/src/observability/logging/index.mjs +1 -0
  48. package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.cjs +321 -0
  49. package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.mjs +313 -0
  50. package/src/observability/opentelemetry/index.cjs +13 -0
  51. package/src/observability/opentelemetry/index.mjs +1 -0
  52. package/src/observability/stream/EventStream.cjs +112 -0
  53. package/src/observability/stream/EventStream.mjs +107 -0
  54. package/src/observability/stream/index.cjs +13 -0
  55. package/src/observability/stream/index.mjs +1 -0
  56. package/src/registry/DocumentRegistry.cjs +27 -3
  57. package/src/registry/DocumentRegistry.mjs +27 -3
  58. package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
  59. package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
  60. package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
  61. package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
  62. package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
  63. package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
  64. package/src/version.cjs +9 -0
  65. package/src/version.mjs +3 -0
  66. package/types/observability/logging/LoggingObserver.d.ts +82 -0
  67. package/types/observability/logging/index.d.ts +2 -0
  68. package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.ts +84 -0
  69. package/types/observability/opentelemetry/index.d.ts +2 -0
  70. package/types/observability/stream/EventStream.d.ts +68 -0
  71. package/types/observability/stream/index.d.ts +2 -0
  72. package/types/runner.d.ts +802 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearazzo/runner",
3
- "version": "1.0.1-alpha.33",
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",
@@ -56,29 +87,30 @@
56
87
  "author": "Vladimir Gorej <vladimir.gorej@gmail.com>",
57
88
  "license": "Apache-2.0",
58
89
  "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",
90
+ "@babel/runtime-corejs3": "^8.1.2",
91
+ "@speclynx/apidom-core": "^7.1.0",
92
+ "@speclynx/apidom-datamodel": "^7.1.0",
93
+ "@speclynx/apidom-error": "^7.1.0",
94
+ "@speclynx/apidom-json-pointer": "^7.1.0",
95
+ "@speclynx/apidom-ns-arazzo-1": "^7.1.0",
96
+ "@speclynx/apidom-ns-openapi-2": "^7.1.0",
97
+ "@speclynx/apidom-ns-openapi-3-0": "^7.1.0",
98
+ "@speclynx/apidom-ns-openapi-3-1": "^7.1.0",
99
+ "@speclynx/apidom-reference": "^7.1.0",
100
+ "@speclynx/apidom-traverse": "^7.1.0",
70
101
  "@swaggerexpert/arazzo-criterion": "^1.2.0",
71
102
  "@swaggerexpert/arazzo-runtime-expression": "^3.4.0",
72
103
  "@swaggerexpert/cookie": "^2.1.1",
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.33",
77
- "@usearazzo/resolver": "1.0.1-alpha.33",
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",
81
112
  "ramda-adjunct": "^6.1.0",
113
+ "short-unique-id": "^5.3.2",
82
114
  "type-fest": "^5.10.0"
83
115
  },
84
116
  "files": [
@@ -86,13 +118,27 @@
86
118
  "src/**/*.cjs",
87
119
  "dist/",
88
120
  "types/runner.d.ts",
121
+ "types/observability/logging/",
122
+ "types/observability/stream/",
123
+ "types/observability/opentelemetry/",
89
124
  "LICENSE",
90
125
  "NOTICE",
91
126
  "README.md",
92
127
  "CHANGELOG.md"
93
128
  ],
129
+ "peerDependencies": {
130
+ "@opentelemetry/api": "^1.9.0"
131
+ },
132
+ "peerDependenciesMeta": {
133
+ "@opentelemetry/api": {
134
+ "optional": true
135
+ }
136
+ },
94
137
  "devDependencies": {
138
+ "@opentelemetry/api": "~1.9.0",
139
+ "@opentelemetry/context-async-hooks": "^2.12.1",
140
+ "@opentelemetry/sdk-trace-base": "^2.12.0",
95
141
  "swagger-client": "^3.39.0"
96
142
  },
97
- "gitHead": "a41d6c5821d21691caa11160e125f89f860f5511"
143
+ "gitHead": "8a1fa9ce51886f2788d381483d4aa0763dfd5d4c"
98
144
  }
@@ -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),
@@ -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
  */
@@ -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.
@@ -1,5 +1,22 @@
1
1
  import { toValue, toYAML } from '@speclynx/apidom-core';
2
2
 
3
+ /**
4
+ * A position in a document, as in the Language Server Protocol: a 0-based
5
+ * line, and a 0-based character offset within it in UTF-16 code units.
6
+ * @public
7
+ */
8
+
9
+ /**
10
+ * A range in a document, as in the Language Server Protocol: from `start` to
11
+ * `end`, the shape the validator's diagnostics use.
12
+ * @public
13
+ */
14
+
15
+ /**
16
+ * Where an element is written.
17
+ * @public
18
+ */
19
+
3
20
  /**
4
21
  * Base document held by the document registry.
5
22
  * @public
@@ -12,6 +29,42 @@ class APIDocument {
12
29
  this.parseResult = parseResult;
13
30
  }
14
31
 
32
+ /**
33
+ * Where an element of this document, or one it references, is written, as
34
+ * the registry provider recorded it when it loaded the document: the
35
+ * document it came from (its `ref-origin`) when it came through a
36
+ * reference, and its JSON Pointer there.
37
+ */
38
+ locationOf(element) {
39
+ const origin = toValue(element.meta.get('ref-origin'));
40
+ const jsonPointer = toValue(element.meta.get('json-pointer'));
41
+ const {
42
+ startLine,
43
+ startCharacter,
44
+ endLine,
45
+ endCharacter
46
+ } = element;
47
+ return {
48
+ uri: typeof origin === 'string' ? origin : this.uri,
49
+ ...(typeof jsonPointer === 'string' && {
50
+ jsonPointer
51
+ }),
52
+ // a source-mapped parse positions every element fully, any other none
53
+ ...(startLine !== undefined && {
54
+ range: {
55
+ start: {
56
+ line: startLine,
57
+ character: startCharacter
58
+ },
59
+ end: {
60
+ line: endLine,
61
+ character: endCharacter
62
+ }
63
+ }
64
+ })
65
+ };
66
+ }
67
+
15
68
  /**
16
69
  * Returns a JSON-serializable representation of the document's API element.
17
70
  * Compatible with JSON.stringify() — JSON.stringify(doc) produces correct output.
@@ -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. */
@@ -21,6 +21,7 @@ var _OpenAPIOperationExtractor = _interopRequireDefault(require("../extractor/Op
21
21
  var _OpenAPIOperationNormalizer = _interopRequireDefault(require("../normalizer/OpenAPIOperationNormalizer.cjs"));
22
22
  var _OpenAPIDocumentAssembler = _interopRequireDefault(require("../assembler/OpenAPIDocumentAssembler.cjs"));
23
23
  var _ClientError = _interopRequireDefault(require("../errors/ClientError.cjs"));
24
+ var _EventChannel = _interopRequireDefault(require("../observability/EventChannel.cjs"));
24
25
  // @ts-expect-error vendored swagger-client bundle has no type declarations
25
26
 
26
27
  /**
@@ -169,6 +170,9 @@ class OpenAPIOperationExecutor {
169
170
  #operationExtractor;
170
171
  #operationNormalizer;
171
172
  #documentAssembler;
173
+ #captureBodies;
174
+ // emits only while `hasObservers`, so an unobserved block builds no events
175
+ #events;
172
176
  constructor(options = {}) {
173
177
  this.#httpClient = options.httpClient ?? _HTTPClientFetch.default;
174
178
  this.#requestInterceptor = options.requestInterceptor;
@@ -176,6 +180,11 @@ class OpenAPIOperationExecutor {
176
180
  this.#operationExtractor = options.operationExtractor ?? new _OpenAPIOperationExtractor.default();
177
181
  this.#operationNormalizer = options.operationNormalizer ?? new _OpenAPIOperationNormalizer.default();
178
182
  this.#documentAssembler = options.documentAssembler ?? new _OpenAPIDocumentAssembler.default();
183
+ this.#events = new _EventChannel.default({
184
+ observer: options.observer,
185
+ now: options.now
186
+ });
187
+ this.#captureBodies = options.captureBodies ?? false;
179
188
  }
180
189
 
181
190
  /**
@@ -196,17 +205,19 @@ class OpenAPIOperationExecutor {
196
205
  // the legacy id (`{method}-{path}`) matches regardless of an explicit
197
206
  // `operationId` in the assembled document
198
207
  const operationId = (0, _swaggerClient.idFromPathMethodLegacy)((0, _apidomCore.toValue)(operation.meta.get('path')), (0, _apidomCore.toValue)(operation.meta.get('http-method')));
199
- const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
200
- const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
201
-
202
208
  // the interceptor and step are consumed here, the target always comes from
203
209
  // the locator, and the transport is the httpClient, so none of these
204
210
  // reach buildRequest
205
211
  const {
206
212
  requestInterceptor,
207
- step
213
+ step,
214
+ runId
208
215
  } = executeOptions;
209
- const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
216
+ // the operation as extracted from its own document, before normalizing
217
+ // copies it, carries where it is written; located once, and only for an
218
+ // observer.
219
+ let located;
220
+ const location = () => located ??= locator.document.locationOf(operation);
210
221
  const declaredOperationId = (0, _apidomCore.toValue)(operation.operationId);
211
222
  const context = {
212
223
  operation: {
@@ -229,6 +240,33 @@ class OpenAPIOperationExecutor {
229
240
  }
230
241
  })
231
242
  };
243
+ if (this.#events.hasObservers) {
244
+ this.#events.emit({
245
+ type: 'openapi:operation:normalize:start',
246
+ ...context,
247
+ runId,
248
+ location: location()
249
+ });
250
+ }
251
+ const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
252
+ if (this.#events.hasObservers) {
253
+ this.#events.emit({
254
+ type: 'openapi:operation:normalize:settled',
255
+ ...context,
256
+ runId,
257
+ location: location()
258
+ });
259
+ }
260
+ const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
261
+ if (this.#events.hasObservers) {
262
+ this.#events.emit({
263
+ type: 'openapi:operation:assembled',
264
+ ...context,
265
+ runId,
266
+ location: location()
267
+ });
268
+ }
269
+ const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'runId', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
232
270
 
233
271
  // each step derives the next options rather than editing in place
234
272
  const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
@@ -272,6 +310,22 @@ class OpenAPIOperationExecutor {
272
310
  },
273
311
  body: request.body
274
312
  };
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
+ }
275
329
  let rawResponse;
276
330
  try {
277
331
  rawResponse = await this.#httpClient(request);
@@ -281,7 +335,24 @@ class OpenAPIOperationExecutor {
281
335
  cause: error
282
336
  });
283
337
  }
284
- return this.#responseNormalizer.normalize(rawResponse, requestInfo);
338
+ const response = await this.#responseNormalizer.normalize(rawResponse, requestInfo);
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
+ }
355
+ return response;
285
356
  }
286
357
 
287
358
  /**