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

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 (53) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +6 -1
  3. package/dist/arazzo-runner.browser.js +2212 -1116
  4. package/dist/arazzo-runner.browser.min.js +1 -1
  5. package/package.json +78 -25
  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/vendor/swagger-client.cjs +1 -1
  37. package/src/vendor/swagger-client.mjs +1 -1
  38. package/src/version.cjs +9 -0
  39. package/src/version.mjs +3 -0
  40. package/types/observability/logging/LoggingObserver.d.cts +82 -0
  41. package/types/observability/logging/LoggingObserver.d.ts +82 -0
  42. package/types/observability/logging/index.d.cts +2 -0
  43. package/types/observability/logging/index.d.ts +2 -0
  44. package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.cts +84 -0
  45. package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.ts +84 -0
  46. package/types/observability/opentelemetry/index.d.cts +2 -0
  47. package/types/observability/opentelemetry/index.d.ts +2 -0
  48. package/types/observability/stream/EventStream.d.cts +68 -0
  49. package/types/observability/stream/EventStream.d.ts +68 -0
  50. package/types/observability/stream/index.d.cts +2 -0
  51. package/types/observability/stream/index.d.ts +2 -0
  52. package/types/runner.d.cts +3891 -0
  53. package/types/runner.d.ts +137 -40
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // generated by scripts/version-update.mjs from package.json; do not edit
8
+ const version = '1.0.1-alpha.35';
9
+ var _default = exports.default = version;
@@ -0,0 +1,3 @@
1
+ // generated by scripts/version-update.mjs from package.json; do not edit
2
+ const version = '1.0.1-alpha.35';
3
+ export default version;
@@ -0,0 +1,82 @@
1
+ import { Redactor, type ArazzoRunnerEvent, type ArazzoRunnerObserver } from '@usearazzo/runner';
2
+ /**
3
+ * The level a log record is written at. Every common logger has these four.
4
+ * @public
5
+ */
6
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
7
+ /**
8
+ * One log record, made from one event.
9
+ * @public
10
+ */
11
+ export interface LogRecord {
12
+ readonly level: LogLevel;
13
+ /**
14
+ * A one-line, human-readable summary of the event, e.g.
15
+ * `step placeOrder failed after 2 attempts`.
16
+ */
17
+ readonly message: string;
18
+ /**
19
+ * The event, masked, as structured fields: its `type`, `runId`, `stepId`,
20
+ * `location` and the rest. The selected action of `action:selected` is
21
+ * given by its `name` and `type`, not as the document's element. The
22
+ * `error` of a settled event that threw is the native `Error`, for the
23
+ * logger to serialize as it is configured to: loggers serialize errors only
24
+ * under their own keys (pino's `err`, winston's top level), so give yours
25
+ * one for `error`, e.g. pino's `serializers: { error: pino.stdSerializers.err }`.
26
+ */
27
+ readonly fields: Readonly<Record<string, unknown>>;
28
+ }
29
+ /**
30
+ * Writes one log record to the logger of your choice. Loggers disagree on
31
+ * argument order, so this is where a record is handed over the way yours
32
+ * expects: `logger[level](fields, message)` for pino or bunyan,
33
+ * `logger.log(level, message, fields)` for winston,
34
+ * `console[level](message, fields)` for the console.
35
+ * @public
36
+ */
37
+ export type LogFunction = (record: LogRecord) => void;
38
+ /**
39
+ * Options for {@link loggingObserver}.
40
+ * @public
41
+ */
42
+ export interface LoggingObserverOptions {
43
+ /**
44
+ * Masks each event before it is logged. A `new Redactor()` with the default
45
+ * field patterns when omitted; there is no way to log unmasked events
46
+ * through this adapter. A settled event's `error` is the exception: it is
47
+ * logged as `execute` rejects with it.
48
+ */
49
+ readonly redactor?: Redactor;
50
+ /**
51
+ * The level for an event type, replacing the default for every event of
52
+ * that type: `{ 'criterion:evaluated': 'info' }`.
53
+ */
54
+ readonly levels?: Readonly<Partial<Record<ArazzoRunnerEvent['type'], LogLevel>>>;
55
+ }
56
+ /**
57
+ * An observer that writes every event as a log record through `log`, masked
58
+ * by a `Redactor` first.
59
+ *
60
+ * Events carry no level, so this adapter gives them one: `info` for workflows
61
+ * and steps starting and settling, `warn` for a failed step, `error` for a
62
+ * failed workflow or a step or workflow that threw, and `debug` for
63
+ * attempts, criteria, actions, retries,
64
+ * dependencies, document loads, normalization and requests. A workflow that
65
+ * transferred to another is `info`: the workflow it transferred to reports its
66
+ * own outcome. `levels` overrides it per event type.
67
+ *
68
+ * ```js
69
+ * import pino from 'pino';
70
+ * import { ArazzoRunner } from '@usearazzo/runner';
71
+ * import { loggingObserver } from '@usearazzo/runner/observability/logging';
72
+ *
73
+ * // the error of a step or workflow that threw, serialized as pino does `err`
74
+ * const logger = pino({ serializers: { error: pino.stdSerializers.err } });
75
+ * const runner = await ArazzoRunner.load(uri, {
76
+ * observer: loggingObserver(({ level, message, fields }) => logger[level](fields, message)),
77
+ * });
78
+ * ```
79
+ * @public
80
+ */
81
+ declare const loggingObserver: (log: LogFunction, options?: LoggingObserverOptions) => ArazzoRunnerObserver;
82
+ export default loggingObserver;
@@ -0,0 +1,82 @@
1
+ import { Redactor, type ArazzoRunnerEvent, type ArazzoRunnerObserver } from '@usearazzo/runner';
2
+ /**
3
+ * The level a log record is written at. Every common logger has these four.
4
+ * @public
5
+ */
6
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
7
+ /**
8
+ * One log record, made from one event.
9
+ * @public
10
+ */
11
+ export interface LogRecord {
12
+ readonly level: LogLevel;
13
+ /**
14
+ * A one-line, human-readable summary of the event, e.g.
15
+ * `step placeOrder failed after 2 attempts`.
16
+ */
17
+ readonly message: string;
18
+ /**
19
+ * The event, masked, as structured fields: its `type`, `runId`, `stepId`,
20
+ * `location` and the rest. The selected action of `action:selected` is
21
+ * given by its `name` and `type`, not as the document's element. The
22
+ * `error` of a settled event that threw is the native `Error`, for the
23
+ * logger to serialize as it is configured to: loggers serialize errors only
24
+ * under their own keys (pino's `err`, winston's top level), so give yours
25
+ * one for `error`, e.g. pino's `serializers: { error: pino.stdSerializers.err }`.
26
+ */
27
+ readonly fields: Readonly<Record<string, unknown>>;
28
+ }
29
+ /**
30
+ * Writes one log record to the logger of your choice. Loggers disagree on
31
+ * argument order, so this is where a record is handed over the way yours
32
+ * expects: `logger[level](fields, message)` for pino or bunyan,
33
+ * `logger.log(level, message, fields)` for winston,
34
+ * `console[level](message, fields)` for the console.
35
+ * @public
36
+ */
37
+ export type LogFunction = (record: LogRecord) => void;
38
+ /**
39
+ * Options for {@link loggingObserver}.
40
+ * @public
41
+ */
42
+ export interface LoggingObserverOptions {
43
+ /**
44
+ * Masks each event before it is logged. A `new Redactor()` with the default
45
+ * field patterns when omitted; there is no way to log unmasked events
46
+ * through this adapter. A settled event's `error` is the exception: it is
47
+ * logged as `execute` rejects with it.
48
+ */
49
+ readonly redactor?: Redactor;
50
+ /**
51
+ * The level for an event type, replacing the default for every event of
52
+ * that type: `{ 'criterion:evaluated': 'info' }`.
53
+ */
54
+ readonly levels?: Readonly<Partial<Record<ArazzoRunnerEvent['type'], LogLevel>>>;
55
+ }
56
+ /**
57
+ * An observer that writes every event as a log record through `log`, masked
58
+ * by a `Redactor` first.
59
+ *
60
+ * Events carry no level, so this adapter gives them one: `info` for workflows
61
+ * and steps starting and settling, `warn` for a failed step, `error` for a
62
+ * failed workflow or a step or workflow that threw, and `debug` for
63
+ * attempts, criteria, actions, retries,
64
+ * dependencies, document loads, normalization and requests. A workflow that
65
+ * transferred to another is `info`: the workflow it transferred to reports its
66
+ * own outcome. `levels` overrides it per event type.
67
+ *
68
+ * ```js
69
+ * import pino from 'pino';
70
+ * import { ArazzoRunner } from '@usearazzo/runner';
71
+ * import { loggingObserver } from '@usearazzo/runner/observability/logging';
72
+ *
73
+ * // the error of a step or workflow that threw, serialized as pino does `err`
74
+ * const logger = pino({ serializers: { error: pino.stdSerializers.err } });
75
+ * const runner = await ArazzoRunner.load(uri, {
76
+ * observer: loggingObserver(({ level, message, fields }) => logger[level](fields, message)),
77
+ * });
78
+ * ```
79
+ * @public
80
+ */
81
+ declare const loggingObserver: (log: LogFunction, options?: LoggingObserverOptions) => ArazzoRunnerObserver;
82
+ export default loggingObserver;
@@ -0,0 +1,2 @@
1
+ export { default as loggingObserver } from './LoggingObserver.cts';
2
+ export type { LogFunction, LogLevel, LogRecord, LoggingObserverOptions, } from './LoggingObserver.cts';
@@ -0,0 +1,2 @@
1
+ export { default as loggingObserver } from './LoggingObserver.ts';
2
+ export type { LogFunction, LogLevel, LogRecord, LoggingObserverOptions, } from './LoggingObserver.ts';
@@ -0,0 +1,84 @@
1
+ import { type TracerProvider } from '@opentelemetry/api';
2
+ /**
3
+ * Configuration of {@link ArazzoRunnerInstrumentation}, OpenTelemetry's
4
+ * `InstrumentationConfig`.
5
+ * @public
6
+ */
7
+ export interface ArazzoRunnerInstrumentationConfig {
8
+ /** Whether it is enabled once constructed. `true` when omitted. */
9
+ readonly enabled?: boolean;
10
+ }
11
+ /**
12
+ * Traces every runner in the process with OpenTelemetry, as an OpenTelemetry
13
+ * instrumentation: list it with the others, and no runner needs wiring.
14
+ *
15
+ * ```js
16
+ * import { NodeSDK } from '@opentelemetry/sdk-node';
17
+ * import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
18
+ * import { ArazzoRunnerInstrumentation } from '@usearazzo/runner/observability/opentelemetry';
19
+ *
20
+ * new NodeSDK({
21
+ * instrumentations: [getNodeAutoInstrumentations(), new ArazzoRunnerInstrumentation()],
22
+ * }).start();
23
+ * ```
24
+ *
25
+ * In the browser, with the fetch instrumentation for the request spans:
26
+ *
27
+ * ```js
28
+ * import { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';
29
+ * import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
30
+ * import { ZoneContextManager } from '@opentelemetry/context-zone';
31
+ * import { registerInstrumentations } from '@opentelemetry/instrumentation';
32
+ * import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
33
+ * import { ArazzoRunnerInstrumentation } from '@usearazzo/runner/observability/opentelemetry';
34
+ *
35
+ * const provider = new WebTracerProvider({
36
+ * spanProcessors: [new BatchSpanProcessor(new OTLPTraceExporter())],
37
+ * });
38
+ * provider.register({ contextManager: new ZoneContextManager() });
39
+ * registerInstrumentations({
40
+ * // propagateTraceHeaderCorsUrls: the cross-origin APIs that get a traceparent
41
+ * instrumentations: [
42
+ * new FetchInstrumentation({ propagateTraceHeaderCorsUrls: [/api\.example\.com/] }),
43
+ * new ArazzoRunnerInstrumentation(),
44
+ * ],
45
+ * });
46
+ * ```
47
+ *
48
+ * Each workflow invocation and each step is an `INTERNAL` span, the step's
49
+ * under its workflow's, a sub-workflow's and a retry reference's under the
50
+ * step that calls them, and a `dependsOn` workflow's or a transfer target's
51
+ * under the workflow that runs them. Attempts, criteria,
52
+ * selected actions, retry waits, retry references and the operations a step
53
+ * calls are events of the step's span, each named by the runner event it
54
+ * comes from (`step:attempt`, `criterion:evaluated`, `action:selected`, …). A step runs in its span's context, so
55
+ * the HTTP instrumentation of the client it sends with (undici for Node's
56
+ * `fetch`, `@opentelemetry/instrumentation-fetch` in the browser) nests its
57
+ * request spans under the step and propagates the trace into the API.
58
+ *
59
+ * In the browser, the workflow and step spans keep their tree with any
60
+ * context manager, but request spans nest under the step only where the
61
+ * context survives an `await`: zone.js loses it across a native one, so
62
+ * transpile `async`/`await` as OpenTelemetry's web instrumentation asks.
63
+ *
64
+ * Spans carry the identifiers and outcomes of the run, not its data: no
65
+ * inputs, outputs, criterion values or requests. A step or workflow that
66
+ * throws records the error, whose message can quote what the run saw.
67
+ * @public
68
+ */
69
+ declare class ArazzoRunnerInstrumentation {
70
+ #private;
71
+ readonly instrumentationName = "@usearazzo/runner";
72
+ readonly instrumentationVersion: string;
73
+ constructor(config?: ArazzoRunnerInstrumentationConfig);
74
+ /** Starts tracing every runner in the process. */
75
+ enable(): void;
76
+ /** Stops tracing; runs in progress stop at their next workflow or step. */
77
+ disable(): void;
78
+ setTracerProvider(tracerProvider: TracerProvider): void;
79
+ /** Records no metrics. */
80
+ setMeterProvider(): void;
81
+ setConfig(config: ArazzoRunnerInstrumentationConfig): void;
82
+ getConfig(): ArazzoRunnerInstrumentationConfig;
83
+ }
84
+ export default ArazzoRunnerInstrumentation;
@@ -0,0 +1,84 @@
1
+ import { type TracerProvider } from '@opentelemetry/api';
2
+ /**
3
+ * Configuration of {@link ArazzoRunnerInstrumentation}, OpenTelemetry's
4
+ * `InstrumentationConfig`.
5
+ * @public
6
+ */
7
+ export interface ArazzoRunnerInstrumentationConfig {
8
+ /** Whether it is enabled once constructed. `true` when omitted. */
9
+ readonly enabled?: boolean;
10
+ }
11
+ /**
12
+ * Traces every runner in the process with OpenTelemetry, as an OpenTelemetry
13
+ * instrumentation: list it with the others, and no runner needs wiring.
14
+ *
15
+ * ```js
16
+ * import { NodeSDK } from '@opentelemetry/sdk-node';
17
+ * import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
18
+ * import { ArazzoRunnerInstrumentation } from '@usearazzo/runner/observability/opentelemetry';
19
+ *
20
+ * new NodeSDK({
21
+ * instrumentations: [getNodeAutoInstrumentations(), new ArazzoRunnerInstrumentation()],
22
+ * }).start();
23
+ * ```
24
+ *
25
+ * In the browser, with the fetch instrumentation for the request spans:
26
+ *
27
+ * ```js
28
+ * import { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';
29
+ * import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
30
+ * import { ZoneContextManager } from '@opentelemetry/context-zone';
31
+ * import { registerInstrumentations } from '@opentelemetry/instrumentation';
32
+ * import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
33
+ * import { ArazzoRunnerInstrumentation } from '@usearazzo/runner/observability/opentelemetry';
34
+ *
35
+ * const provider = new WebTracerProvider({
36
+ * spanProcessors: [new BatchSpanProcessor(new OTLPTraceExporter())],
37
+ * });
38
+ * provider.register({ contextManager: new ZoneContextManager() });
39
+ * registerInstrumentations({
40
+ * // propagateTraceHeaderCorsUrls: the cross-origin APIs that get a traceparent
41
+ * instrumentations: [
42
+ * new FetchInstrumentation({ propagateTraceHeaderCorsUrls: [/api\.example\.com/] }),
43
+ * new ArazzoRunnerInstrumentation(),
44
+ * ],
45
+ * });
46
+ * ```
47
+ *
48
+ * Each workflow invocation and each step is an `INTERNAL` span, the step's
49
+ * under its workflow's, a sub-workflow's and a retry reference's under the
50
+ * step that calls them, and a `dependsOn` workflow's or a transfer target's
51
+ * under the workflow that runs them. Attempts, criteria,
52
+ * selected actions, retry waits, retry references and the operations a step
53
+ * calls are events of the step's span, each named by the runner event it
54
+ * comes from (`step:attempt`, `criterion:evaluated`, `action:selected`, …). A step runs in its span's context, so
55
+ * the HTTP instrumentation of the client it sends with (undici for Node's
56
+ * `fetch`, `@opentelemetry/instrumentation-fetch` in the browser) nests its
57
+ * request spans under the step and propagates the trace into the API.
58
+ *
59
+ * In the browser, the workflow and step spans keep their tree with any
60
+ * context manager, but request spans nest under the step only where the
61
+ * context survives an `await`: zone.js loses it across a native one, so
62
+ * transpile `async`/`await` as OpenTelemetry's web instrumentation asks.
63
+ *
64
+ * Spans carry the identifiers and outcomes of the run, not its data: no
65
+ * inputs, outputs, criterion values or requests. A step or workflow that
66
+ * throws records the error, whose message can quote what the run saw.
67
+ * @public
68
+ */
69
+ declare class ArazzoRunnerInstrumentation {
70
+ #private;
71
+ readonly instrumentationName = "@usearazzo/runner";
72
+ readonly instrumentationVersion: string;
73
+ constructor(config?: ArazzoRunnerInstrumentationConfig);
74
+ /** Starts tracing every runner in the process. */
75
+ enable(): void;
76
+ /** Stops tracing; runs in progress stop at their next workflow or step. */
77
+ disable(): void;
78
+ setTracerProvider(tracerProvider: TracerProvider): void;
79
+ /** Records no metrics. */
80
+ setMeterProvider(): void;
81
+ setConfig(config: ArazzoRunnerInstrumentationConfig): void;
82
+ getConfig(): ArazzoRunnerInstrumentationConfig;
83
+ }
84
+ export default ArazzoRunnerInstrumentation;
@@ -0,0 +1,2 @@
1
+ export { default as ArazzoRunnerInstrumentation } from './ArazzoRunnerInstrumentation.cts';
2
+ export type { ArazzoRunnerInstrumentationConfig } from './ArazzoRunnerInstrumentation.cts';
@@ -0,0 +1,2 @@
1
+ export { default as ArazzoRunnerInstrumentation } from './ArazzoRunnerInstrumentation.ts';
2
+ export type { ArazzoRunnerInstrumentationConfig } from './ArazzoRunnerInstrumentation.ts';
@@ -0,0 +1,68 @@
1
+ import { Redactor, type ArazzoRunnerEvent, type ArazzoRunnerObserver } from '@usearazzo/runner';
2
+ /**
3
+ * Options for {@link eventStream}.
4
+ * @public
5
+ */
6
+ export interface EventStreamOptions {
7
+ /**
8
+ * Masks each event before it is queued. A `new Redactor()` with the default
9
+ * field patterns when omitted; there is no way to stream unmasked events
10
+ * through this adapter. A settled event's `error` is the exception: it is
11
+ * queued as `execute` rejects with it.
12
+ */
13
+ readonly redactor?: Redactor;
14
+ }
15
+ /**
16
+ * A run's events as a stream: wire `observer` into the runner, read the
17
+ * events with `for await`, or pipe `stream`, and end it with `close` or
18
+ * `error` once the run settles.
19
+ * @public
20
+ */
21
+ export interface EventStream extends AsyncIterable<ArazzoRunnerEvent> {
22
+ /**
23
+ * Queues each event, masked. It never waits for the consumer, so a slow
24
+ * consumer cannot hold the run back: events wait in an unbounded queue.
25
+ */
26
+ readonly observer: ArazzoRunnerObserver;
27
+ /**
28
+ * The events as a WHATWG `ReadableStream`, for piping. It has one consumer:
29
+ * read it or iterate this object, not both. For two consumers, give each
30
+ * an `eventStream()` of its own behind `combineObservers`: a `tee()`d
31
+ * branch loses its unread events when the stream fails.
32
+ */
33
+ readonly stream: ReadableStream<ArazzoRunnerEvent>;
34
+ /**
35
+ * Ends the stream once the queued events are read. Call it when `execute`
36
+ * resolves; events after it are dropped.
37
+ */
38
+ close(): void;
39
+ /**
40
+ * Fails the stream once the queued events are read: reading it then rejects
41
+ * with `reason`. Call it when `execute` rejects; events after it are
42
+ * dropped.
43
+ */
44
+ error(reason: unknown): void;
45
+ }
46
+ /**
47
+ * Turns a run's events into a stream. The caller ends it: a runner can run
48
+ * many times into one stream, and an `execute` that fails before its
49
+ * workflow starts (an unknown workflow, a document that does not load)
50
+ * emits no workflow event to end it on:
51
+ *
52
+ * ```js
53
+ * import { ArazzoRunner } from '@usearazzo/runner';
54
+ * import { eventStream } from '@usearazzo/runner/observability/stream';
55
+ *
56
+ * const events = eventStream();
57
+ * const runner = await ArazzoRunner.load(uri, { observer: events.observer });
58
+ * runner.execute('authenticateAndOrderPet', options).then(events.close, events.error);
59
+ *
60
+ * for await (const event of events) render(event);
61
+ * ```
62
+ *
63
+ * A consumer that stops reading early (a `break` out of `for await`, or a
64
+ * cancelled stream) stops the queuing: the run goes on unobserved.
65
+ * @public
66
+ */
67
+ declare const eventStream: (options?: EventStreamOptions) => EventStream;
68
+ export default eventStream;
@@ -0,0 +1,68 @@
1
+ import { Redactor, type ArazzoRunnerEvent, type ArazzoRunnerObserver } from '@usearazzo/runner';
2
+ /**
3
+ * Options for {@link eventStream}.
4
+ * @public
5
+ */
6
+ export interface EventStreamOptions {
7
+ /**
8
+ * Masks each event before it is queued. A `new Redactor()` with the default
9
+ * field patterns when omitted; there is no way to stream unmasked events
10
+ * through this adapter. A settled event's `error` is the exception: it is
11
+ * queued as `execute` rejects with it.
12
+ */
13
+ readonly redactor?: Redactor;
14
+ }
15
+ /**
16
+ * A run's events as a stream: wire `observer` into the runner, read the
17
+ * events with `for await`, or pipe `stream`, and end it with `close` or
18
+ * `error` once the run settles.
19
+ * @public
20
+ */
21
+ export interface EventStream extends AsyncIterable<ArazzoRunnerEvent> {
22
+ /**
23
+ * Queues each event, masked. It never waits for the consumer, so a slow
24
+ * consumer cannot hold the run back: events wait in an unbounded queue.
25
+ */
26
+ readonly observer: ArazzoRunnerObserver;
27
+ /**
28
+ * The events as a WHATWG `ReadableStream`, for piping. It has one consumer:
29
+ * read it or iterate this object, not both. For two consumers, give each
30
+ * an `eventStream()` of its own behind `combineObservers`: a `tee()`d
31
+ * branch loses its unread events when the stream fails.
32
+ */
33
+ readonly stream: ReadableStream<ArazzoRunnerEvent>;
34
+ /**
35
+ * Ends the stream once the queued events are read. Call it when `execute`
36
+ * resolves; events after it are dropped.
37
+ */
38
+ close(): void;
39
+ /**
40
+ * Fails the stream once the queued events are read: reading it then rejects
41
+ * with `reason`. Call it when `execute` rejects; events after it are
42
+ * dropped.
43
+ */
44
+ error(reason: unknown): void;
45
+ }
46
+ /**
47
+ * Turns a run's events into a stream. The caller ends it: a runner can run
48
+ * many times into one stream, and an `execute` that fails before its
49
+ * workflow starts (an unknown workflow, a document that does not load)
50
+ * emits no workflow event to end it on:
51
+ *
52
+ * ```js
53
+ * import { ArazzoRunner } from '@usearazzo/runner';
54
+ * import { eventStream } from '@usearazzo/runner/observability/stream';
55
+ *
56
+ * const events = eventStream();
57
+ * const runner = await ArazzoRunner.load(uri, { observer: events.observer });
58
+ * runner.execute('authenticateAndOrderPet', options).then(events.close, events.error);
59
+ *
60
+ * for await (const event of events) render(event);
61
+ * ```
62
+ *
63
+ * A consumer that stops reading early (a `break` out of `for await`, or a
64
+ * cancelled stream) stops the queuing: the run goes on unobserved.
65
+ * @public
66
+ */
67
+ declare const eventStream: (options?: EventStreamOptions) => EventStream;
68
+ export default eventStream;
@@ -0,0 +1,2 @@
1
+ export { default as eventStream } from './EventStream.cts';
2
+ export type { EventStream, EventStreamOptions } from './EventStream.cts';
@@ -0,0 +1,2 @@
1
+ export { default as eventStream } from './EventStream.ts';
2
+ export type { EventStream, EventStreamOptions } from './EventStream.ts';