abxbus 2.5.3 → 2.5.6

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 (42) hide show
  1. package/dist/cjs/BaseEvent.d.ts +68 -23
  2. package/dist/cjs/BaseEvent.js +131 -14
  3. package/dist/cjs/BaseEvent.js.map +2 -2
  4. package/dist/cjs/base_event.d.ts +2 -2
  5. package/dist/cjs/bridge_ipc.d.ts +45 -0
  6. package/dist/cjs/event_handler.d.ts +1 -0
  7. package/dist/cjs/events_suck.d.ts +1 -1
  8. package/dist/cjs/events_suck.js.map +2 -2
  9. package/dist/cjs/jsonschema.d.ts +6 -0
  10. package/dist/cjs/jsonschema.js +155 -0
  11. package/dist/cjs/jsonschema.js.map +7 -0
  12. package/dist/cjs/middleware_otel_tracing.d.ts +49 -0
  13. package/dist/cjs/retry.js.map +2 -2
  14. package/dist/cjs/types.d.ts +3 -4
  15. package/dist/cjs/types.js +8 -15
  16. package/dist/cjs/types.js.map +2 -2
  17. package/dist/esm/BaseEvent.js +131 -14
  18. package/dist/esm/BaseEvent.js.map +2 -2
  19. package/dist/esm/events_suck.js.map +2 -2
  20. package/dist/esm/jsonschema.js +135 -0
  21. package/dist/esm/jsonschema.js.map +7 -0
  22. package/dist/esm/retry.js.map +2 -2
  23. package/dist/esm/types.js +7 -14
  24. package/dist/esm/types.js.map +2 -2
  25. package/dist/types/BaseEvent.d.ts +68 -23
  26. package/dist/types/base_event.d.ts +2 -2
  27. package/dist/types/bridge_ipc.d.ts +45 -0
  28. package/dist/types/event_handler.d.ts +1 -0
  29. package/dist/types/events_suck.d.ts +1 -1
  30. package/dist/types/jsonschema.d.ts +6 -0
  31. package/dist/types/middleware_otel_tracing.d.ts +49 -0
  32. package/dist/types/types.d.ts +3 -4
  33. package/package.json +1 -1
  34. package/src/BaseEvent.ts +277 -54
  35. package/src/events_suck.ts +3 -2
  36. package/src/jsonschema.ts +146 -0
  37. package/src/retry.ts +7 -4
  38. package/src/types.ts +6 -14
  39. package/dist/cjs/CoreClient.d.ts +0 -167
  40. package/dist/cjs/CoreEventBus.d.ts +0 -334
  41. package/dist/types/CoreClient.d.ts +0 -167
  42. package/dist/types/CoreEventBus.d.ts +0 -334
@@ -4,6 +4,7 @@ import { EventResult } from './EventResult.js';
4
4
  import { EventHandler } from './EventHandler.js';
5
5
  import type { EventConcurrencyMode, EventHandlerConcurrencyMode, EventHandlerCompletionMode, Deferred } from './LockManager.js';
6
6
  import { AsyncLock } from './LockManager.js';
7
+ import { type JsonSchema } from './jsonschema.js';
7
8
  import type { EventHandlerCallable, EventResultType } from './types.js';
8
9
  export declare const BaseEventSchema: z.ZodObject<{
9
10
  event_id: z.ZodString;
@@ -42,7 +43,7 @@ export declare const BaseEventSchema: z.ZodObject<{
42
43
  first: "first";
43
44
  }>>>;
44
45
  }, z.core.$loose>;
45
- type AnyEventSchema = z.ZodTypeAny;
46
+ type AnyEventSchema = z.ZodObject<z.ZodRawShape>;
46
47
  export type BaseEventData = z.infer<typeof BaseEventSchema>;
47
48
  export type BaseEventJSON = BaseEventData & Record<string, unknown>;
48
49
  type BaseEventFieldName = 'event_id' | 'event_created_at' | 'event_type' | 'event_version' | 'event_timeout' | 'event_slow_timeout' | 'event_handler_timeout' | 'event_handler_slow_timeout' | 'event_blocks_parent_completion' | 'event_parent_id' | 'event_path' | 'event_result_type' | 'event_emitted_by_handler_id' | 'event_pending_bus_count' | 'event_status' | 'event_started_at' | 'event_completed_at' | 'event_results' | 'event_concurrency' | 'event_handler_concurrency' | 'event_handler_completion';
@@ -52,20 +53,54 @@ type BaseEventFields = {
52
53
  export type BaseEventInit<TFields extends Record<string, unknown>> = TFields & Partial<BaseEventFields>;
53
54
  type BaseEventSchemaShape = typeof BaseEventSchema.shape;
54
55
  export type EventSchema<TShape extends z.ZodRawShape> = z.ZodObject<BaseEventSchemaShape & TShape>;
55
- type EventPayload<TShape extends z.ZodRawShape> = TShape extends Record<string, never> ? {} : z.infer<z.ZodObject<TShape>>;
56
+ type EventPayloadShape<TShape extends z.ZodRawShape> = {
57
+ [K in keyof TShape as K extends BaseEventFieldName ? never : K]: TShape[K];
58
+ };
59
+ type EventPayload<TShape extends z.ZodRawShape> = EventPayloadShape<TShape> extends Record<string, never> ? {} : z.infer<z.ZodObject<EventPayloadShape<TShape>>>;
60
+ type EventFactoryMetadataFieldName = 'class' | 'fromJSON' | 'prototype' | 'event_schema' | 'model_fields' | 'event_type' | 'event_version' | 'event_result_type';
61
+ type StaticDefaultSchema = z.ZodDefault<z.ZodTypeAny> | z.ZodPrefault<z.ZodTypeAny> | z.ZodCatch<z.ZodTypeAny>;
62
+ type EventModelFields<TShape extends z.ZodRawShape> = {
63
+ readonly [K in keyof TShape]: TShape[K];
64
+ };
65
+ type StaticEventDefaultValues<TShape extends z.ZodRawShape> = {
66
+ readonly [K in keyof TShape as K extends EventFactoryMetadataFieldName ? never : TShape[K] extends StaticDefaultSchema ? K : never]: z.output<TShape[K]>;
67
+ };
68
+ type StaticEventDefaultValuesFromSchema<TSchema extends AnyEventSchema> = TSchema extends z.ZodObject<infer TShape> ? StaticEventDefaultValues<TShape> : {};
69
+ type EventModelFieldsFromSchema<TSchema extends AnyEventSchema> = TSchema extends z.ZodObject<infer TShape> ? TSchema['shape'] & EventModelFields<TShape> : {};
70
+ type OptionalFactoryArgs<TData> = {} extends TData ? [data?: TData] : [data: TData];
56
71
  type EventInput<TShape extends z.ZodRawShape> = z.input<EventSchema<TShape>>;
57
72
  export type EventInit<TShape extends z.ZodRawShape> = Omit<EventInput<TShape>, keyof BaseEventFields> & Partial<BaseEventFields>;
58
- type EventPayloadFromSchema<TSchema extends AnyEventSchema> = z.output<TSchema> extends Record<string, unknown> ? z.output<TSchema> : {};
73
+ type EventPayloadFromSchema<TSchema extends AnyEventSchema> = z.output<TSchema> extends Record<string, unknown> ? Omit<z.output<TSchema>, keyof BaseEventFields> : {};
59
74
  type EventInputFromSchema<TSchema extends AnyEventSchema> = z.input<TSchema> extends Record<string, unknown> ? z.input<TSchema> : never;
60
75
  export type EventInitFromSchema<TSchema extends AnyEventSchema> = Omit<EventInputFromSchema<TSchema>, keyof BaseEventFields> & Partial<BaseEventFields>;
61
76
  type EventWithResultSchema<TResult> = BaseEvent & {
62
77
  __event_result_type__?: TResult;
63
78
  };
64
- type ResultTypeFromEventResultTypeInput<TInput> = TInput extends z.ZodTypeAny ? z.infer<TInput> : TInput extends StringConstructor ? string : TInput extends NumberConstructor ? number : TInput extends BooleanConstructor ? boolean : TInput extends ArrayConstructor ? unknown[] : TInput extends ObjectConstructor ? Record<string, unknown> : unknown;
79
+ type NormalizedEventResultSchema<TInput> = TInput extends z.ZodTypeAny ? TInput : TInput extends z.core.$ZodType ? z.ZodType<z.output<TInput>> : TInput extends StringConstructor ? z.ZodString : TInput extends NumberConstructor ? z.ZodNumber : TInput extends BooleanConstructor ? z.ZodBoolean : TInput extends ArrayConstructor ? z.ZodArray<z.ZodUnknown> : TInput extends ObjectConstructor ? z.ZodRecord<z.ZodString, z.ZodUnknown> : TInput extends JsonSchema ? z.ZodTypeAny : z.ZodTypeAny;
80
+ type ResultTypeSchemaFromShape<TShape> = TShape extends {
81
+ event_result_type: infer S;
82
+ } ? NormalizedEventResultSchema<S> : z.ZodTypeAny | undefined;
83
+ type ResultTypeSchemaFromEventSchema<TSchema> = TSchema extends z.ZodObject<infer TShape> ? ResultTypeSchemaFromShape<TShape> : z.ZodTypeAny | undefined;
84
+ type ResultTypeFromEventResultTypeInput<TInput> = TInput extends z.ZodTypeAny ? z.infer<TInput> : TInput extends z.core.$ZodType ? z.output<TInput> : TInput extends StringConstructor ? string : TInput extends NumberConstructor ? number : TInput extends BooleanConstructor ? boolean : TInput extends ArrayConstructor ? unknown[] : TInput extends ObjectConstructor ? Record<string, unknown> : TInput extends JsonSchema ? unknown : unknown;
65
85
  type ResultSchemaFromShape<TShape> = TShape extends {
66
86
  event_result_type: infer S;
67
87
  } ? ResultTypeFromEventResultTypeInput<S> : unknown;
68
88
  type ResultSchemaFromEventSchema<TSchema> = TSchema extends z.ZodObject<infer TShape> ? ResultSchemaFromShape<TShape> : unknown;
89
+ type ZodLiteralValue = string | number | bigint | boolean | null | undefined;
90
+ type ShortcutDefaultModelField<K, TValue> = K extends keyof BaseEventSchemaShape ? z.ZodDefault<BaseEventSchemaShape[K]> : z.ZodDefault<TValue extends ZodLiteralValue ? z.ZodLiteral<TValue> : z.ZodType<TValue>>;
91
+ type ShortcutModelFields<TShape> = {
92
+ [K in keyof TShape as K extends 'event_result_type' ? never : K]: TShape[K] extends z.ZodTypeAny ? TShape[K] : ShortcutDefaultModelField<K, TShape[K]>;
93
+ } & (TShape extends {
94
+ event_result_type: infer TResultType;
95
+ } ? {
96
+ event_result_type: NormalizedEventResultSchema<TResultType>;
97
+ } : {});
98
+ type ShortcutZodModelFields<TShape> = {
99
+ [K in keyof ShortcutModelFields<TShape>]: ShortcutModelFields<TShape>[K] extends z.ZodTypeAny ? ShortcutModelFields<TShape>[K] : never;
100
+ };
101
+ type ShortcutStaticDefaultValues<TShape, TModelFields extends z.ZodRawShape> = StaticEventDefaultValues<TModelFields> & {
102
+ readonly [K in keyof TShape as K extends EventFactoryMetadataFieldName ? never : TShape[K] extends z.ZodTypeAny ? never : K]: TShape[K];
103
+ };
69
104
  export type EventResultInclude<TEvent extends BaseEvent> = (result: EventResult<TEvent>['result'], event_result: EventResult<TEvent>) => boolean;
70
105
  export type EventResultOptions<TEvent extends BaseEvent> = {
71
106
  include?: EventResultInclude<TEvent>;
@@ -86,28 +121,35 @@ type EventResultUpdateOptions<TEvent extends BaseEvent> = {
86
121
  result?: EventResultType<TEvent> | BaseEvent | undefined;
87
122
  error?: unknown;
88
123
  };
89
- export type EventFactory<TShape extends z.ZodRawShape, TResult = unknown> = {
90
- (data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
91
- new (data: EventInit<TShape>): EventWithResultSchema<TResult> & EventPayload<TShape>;
124
+ export type EventFactoryClass<TShape extends z.ZodRawShape, TResult = unknown> = (new (...args: OptionalFactoryArgs<EventInit<TShape>>) => EventWithResultSchema<TResult> & EventPayload<TShape>) & StaticEventDefaultValues<TShape> & {
92
125
  event_schema: EventSchema<TShape>;
93
- class?: new (data: EventInit<TShape>) => EventWithResultSchema<TResult> & EventPayload<TShape>;
94
- event_type?: string;
95
- event_version?: string;
96
- event_result_type?: z.ZodTypeAny;
97
- fromJSON?: (data: unknown) => EventWithResultSchema<TResult> & EventPayload<TShape>;
126
+ model_fields: EventModelFields<TShape>;
98
127
  };
99
- export type SchemaEventFactory<TSchema extends AnyEventSchema, TResult = unknown> = {
100
- (data: EventInitFromSchema<TSchema>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
101
- new (data: EventInitFromSchema<TSchema>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
128
+ export type EventFactory<TShape extends z.ZodRawShape, TResult = unknown, TStaticFields = StaticEventDefaultValues<TShape>> = TStaticFields & {
129
+ (...args: OptionalFactoryArgs<EventInit<TShape>>): EventWithResultSchema<TResult> & EventPayload<TShape>;
130
+ new (...args: OptionalFactoryArgs<EventInit<TShape>>): EventWithResultSchema<TResult> & EventPayload<TShape>;
131
+ event_schema: EventSchema<TShape>;
132
+ model_fields: EventModelFields<TShape>;
133
+ class: EventFactoryClass<TShape, TResult>;
134
+ event_type: string;
135
+ event_version: string;
136
+ event_result_type: ResultTypeSchemaFromShape<TShape>;
137
+ fromJSON: (data: unknown) => EventWithResultSchema<TResult> & EventPayload<TShape>;
138
+ };
139
+ export type SchemaEventFactoryClass<TSchema extends AnyEventSchema, TResult = unknown> = (new (...args: OptionalFactoryArgs<EventInitFromSchema<TSchema>>) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>) & StaticEventDefaultValuesFromSchema<TSchema> & {
102
140
  event_schema: TSchema;
103
- class?: new (data: EventInitFromSchema<TSchema>) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
104
- event_type?: string;
105
- event_version?: string;
106
- event_result_type?: z.ZodTypeAny;
107
- fromJSON?: (data: unknown) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
141
+ model_fields: EventModelFieldsFromSchema<TSchema>;
108
142
  };
109
- type ZodShapeFrom<TShape extends Record<string, unknown>> = {
110
- [K in keyof TShape as K extends 'event_result_type' ? never : TShape[K] extends z.ZodTypeAny ? K : never]: Extract<TShape[K], z.ZodTypeAny>;
143
+ export type SchemaEventFactory<TSchema extends AnyEventSchema, TResult = unknown> = StaticEventDefaultValuesFromSchema<TSchema> & {
144
+ (...args: OptionalFactoryArgs<EventInitFromSchema<TSchema>>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
145
+ new (...args: OptionalFactoryArgs<EventInitFromSchema<TSchema>>): EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
146
+ event_schema: TSchema;
147
+ model_fields: EventModelFieldsFromSchema<TSchema>;
148
+ class: SchemaEventFactoryClass<TSchema, TResult>;
149
+ event_type: string;
150
+ event_version: string;
151
+ event_result_type: ResultTypeSchemaFromEventSchema<TSchema>;
152
+ fromJSON: (data: unknown) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
111
153
  };
112
154
  export declare class BaseEvent {
113
155
  event_id: string;
@@ -132,10 +174,13 @@ export declare class BaseEvent {
132
174
  event_handler_concurrency?: EventHandlerConcurrencyMode | null;
133
175
  event_handler_completion?: EventHandlerCompletionMode | null;
134
176
  event_schema?: z.ZodTypeAny;
177
+ _event_parse_schema?: z.ZodTypeAny;
135
178
  static event_type?: string;
136
179
  static event_version: string;
137
180
  static event_result_type?: z.ZodTypeAny;
138
181
  static event_schema: AnyEventSchema;
182
+ static model_fields: z.ZodRawShape;
183
+ static _event_parse_schema: AnyEventSchema;
139
184
  event_bus?: EventBus;
140
185
  _event_original?: BaseEvent;
141
186
  _event_dispatch_context?: unknown | null;
@@ -145,8 +190,8 @@ export declare class BaseEvent {
145
190
  constructor(data?: BaseEventInit<Record<string, unknown>>);
146
191
  toString(): string;
147
192
  static extend<TSchema extends z.ZodObject<z.ZodRawShape>>(event_type: string, event_schema: TSchema): SchemaEventFactory<TSchema, ResultSchemaFromEventSchema<TSchema>>;
193
+ static extend<const TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventFactory<ShortcutZodModelFields<TShape>, ResultSchemaFromShape<ShortcutZodModelFields<TShape>>, ShortcutStaticDefaultValues<TShape, ShortcutZodModelFields<TShape>>>;
148
194
  static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultSchemaFromShape<TShape>>;
149
- static extend<TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventFactory<ZodShapeFrom<TShape>, ResultSchemaFromShape<TShape>>;
150
195
  static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
151
196
  static toJSONArray(events: Iterable<BaseEvent>): BaseEventJSON[];
152
197
  static fromJSONArray(data: unknown): BaseEvent[];
@@ -27,7 +27,7 @@ export declare const BaseEventSchema: z.ZodObject<{
27
27
  }>>;
28
28
  event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
29
  event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
- event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
30
+ event_results: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
31
31
  event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
32
32
  "global-serial": "global-serial";
33
33
  "bus-serial": "bus-serial";
@@ -133,7 +133,7 @@ export declare class BaseEvent {
133
133
  }>>;
134
134
  event_started_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
135
135
  event_completed_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
136
- event_results: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
136
+ event_results: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
137
137
  event_concurrency: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
138
138
  "global-serial": "global-serial";
139
139
  "bus-serial": "bus-serial";
@@ -0,0 +1,45 @@
1
+ import { BaseEvent } from './base_event.js';
2
+ import { EventBus } from './event_bus.js';
3
+ import type { EventClass, EventHandlerCallable, UntypedEventHandlerFunction } from './types.js';
4
+ type EndpointScheme = 'unix' | 'http' | 'https';
5
+ type ParsedEndpoint = {
6
+ raw: string;
7
+ scheme: EndpointScheme;
8
+ host?: string;
9
+ port?: number;
10
+ path?: string;
11
+ };
12
+ export type HTTPEventBridgeOptions = {
13
+ send_to?: string | null;
14
+ listen_on?: string | null;
15
+ name?: string;
16
+ };
17
+ export declare class EventBridge {
18
+ readonly send_to: ParsedEndpoint | null;
19
+ readonly listen_on: ParsedEndpoint | null;
20
+ readonly name: string;
21
+ protected readonly inbound_bus: EventBus;
22
+ private start_promise;
23
+ private node_server;
24
+ constructor(send_to?: string | null, listen_on?: string | null, name?: string);
25
+ on<T extends BaseEvent>(event_pattern: EventClass<T>, handler: EventHandlerCallable<T>): void;
26
+ on<T extends BaseEvent>(event_pattern: string | '*', handler: UntypedEventHandlerFunction<T>): void;
27
+ emit<T extends BaseEvent>(event: T): Promise<void>;
28
+ dispatch<T extends BaseEvent>(event: T): Promise<void>;
29
+ start(): Promise<void>;
30
+ close(): Promise<void>;
31
+ private ensureListenerStarted;
32
+ private handleIncomingPayload;
33
+ private sendHttp;
34
+ private sendUnix;
35
+ private startHttpListener;
36
+ private startUnixListener;
37
+ }
38
+ export declare class HTTPEventBridge extends EventBridge {
39
+ constructor(send_to?: string | null, listen_on?: string | null, name?: string);
40
+ constructor(options?: HTTPEventBridgeOptions);
41
+ }
42
+ export declare class SocketEventBridge extends EventBridge {
43
+ constructor(path?: string | null, name?: string);
44
+ }
45
+ export {};
@@ -61,6 +61,7 @@ export declare class EventHandler {
61
61
  eventbus_id: string;
62
62
  });
63
63
  get _handler_async(): EventHandlerCallable;
64
+ static handlerNameFromCallable(handler: EventHandlerCallable): string;
64
65
  static computeHandlerId(params: {
65
66
  eventbus_id: string;
66
67
  handler_name: string;
@@ -22,7 +22,7 @@ export type GeneratedEvents<TEvents extends FunctionMap> = {
22
22
  } & {
23
23
  [K in keyof TEvents]: GeneratedEvent<TEvents[K]>;
24
24
  };
25
- type EventInit<TEventClass extends EventClass<BaseEvent>> = ConstructorParameters<TEventClass> extends [infer TInit, ...unknown[]] ? TInit : never;
25
+ type EventInit<TEventClass extends EventClass<BaseEvent>> = [ConstructorParameters<TEventClass>[0]] extends [undefined] ? {} : NonNullable<ConstructorParameters<TEventClass>[0]>;
26
26
  type EventMethodArgs<TEventClass extends EventClass<BaseEvent>> = {} extends EventInit<TEventClass> ? [init?: EventInit<TEventClass>, extra?: Record<string, unknown>] : [init: EventInit<TEventClass>, extra?: Record<string, unknown>];
27
27
  type EventMethodResult<TEventClass extends EventClass<BaseEvent>> = EventResultType<InstanceType<TEventClass>> | undefined;
28
28
  export type EventsSuckClient<TEvents extends EventMap> = {
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ export type JsonSchema = boolean | z.core.JSONSchema.JSONSchema;
3
+ export declare const isJsonSchema: (value: unknown) => value is JsonSchema;
4
+ export declare const normalizeJsonSchema: (schema: JsonSchema) => JsonSchema;
5
+ export declare const toJsonSchema: (schema: z.core.$ZodType) => JsonSchema;
6
+ export declare const fromJsonSchema: (schema: JsonSchema) => z.ZodTypeAny;
@@ -0,0 +1,49 @@
1
+ import { trace, type Span, type SpanAttributes, type SpanContext, type TimeInput, type Tracer } from '@opentelemetry/api';
2
+ import type { BaseEvent } from './base_event.js';
3
+ import type { EventBus } from './event_bus.js';
4
+ import type { EventResult } from './event_result.js';
5
+ import type { EventBusMiddleware } from './middlewares.js';
6
+ import type { EventStatus } from './types.js';
7
+ type OpenTelemetryTraceApi = Pick<typeof trace, 'getTracer' | 'setSpan'> & Partial<Pick<typeof trace, 'setSpanContext'>>;
8
+ export type OtelTracingSpanFactoryInput = {
9
+ name: string;
10
+ span_context: SpanContext;
11
+ parent_span_context?: SpanContext;
12
+ attributes: SpanAttributes;
13
+ start_time?: TimeInput;
14
+ };
15
+ export type OtelTracingSpanFactory = (input: OtelTracingSpanFactoryInput) => Span;
16
+ export type OtelTracingSpanProvider = object;
17
+ export type OtelTracingMiddlewareOptions = {
18
+ tracer?: Tracer;
19
+ trace_api?: OpenTelemetryTraceApi;
20
+ span_provider?: OtelTracingSpanProvider;
21
+ span_factory?: OtelTracingSpanFactory;
22
+ otlp_endpoint?: string;
23
+ service_name?: string;
24
+ instrumentation_name?: string;
25
+ root_span_attributes?: SpanAttributes | ((eventbus: EventBus, event: BaseEvent) => SpanAttributes);
26
+ };
27
+ export declare class OtelTracingMiddleware implements EventBusMiddleware {
28
+ private readonly tracer;
29
+ private readonly trace_api;
30
+ private readonly span_factory?;
31
+ private readonly span_provider?;
32
+ private readonly root_span_attributes;
33
+ private readonly event_spans;
34
+ private readonly event_contexts;
35
+ private readonly handler_spans;
36
+ private readonly handler_contexts;
37
+ constructor(options?: OtelTracingMiddlewareOptions);
38
+ onEventChange(eventbus: EventBus, event: BaseEvent, status: EventStatus): void;
39
+ onEventResultChange(eventbus: EventBus, event: BaseEvent, event_result: EventResult, status: EventStatus): void;
40
+ private startEventSpan;
41
+ private completeEventSpan;
42
+ private startHandlerSpan;
43
+ private completeHandlerSpan;
44
+ private parentContextForEvent;
45
+ private completeEventSpanWithFactory;
46
+ private exportEventTreeWithFactory;
47
+ private exportHandlerSpanWithFactory;
48
+ }
49
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import type { BaseEvent } from './BaseEvent.js';
3
+ import { type JsonSchema } from './jsonschema.js';
3
4
  export type EventStatus = 'pending' | 'started' | 'completed';
4
5
  export type EventClass<T extends BaseEvent = BaseEvent> = {
5
6
  event_type?: string;
@@ -12,7 +13,7 @@ export type EventResultType<TEvent extends BaseEvent> = TEvent extends {
12
13
  __event_result_type__?: infer TResult;
13
14
  } ? TResult : unknown;
14
15
  export type EventResultTypeConstructor = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor;
15
- export type EventResultTypeInput = z.ZodTypeAny | EventResultTypeConstructor | unknown;
16
+ export type EventResultTypeInput = z.ZodTypeAny | EventResultTypeConstructor | JsonSchema;
16
17
  export type EventHandlerReturn<T extends BaseEvent = BaseEvent> = EventResultType<T> | BaseEvent | null | void;
17
18
  export type EventHandlerCallable<T extends BaseEvent = BaseEvent> = (event: T) => EventHandlerReturn<T> | Promise<EventHandlerReturn<T>>;
18
19
  export type UntypedEventHandlerFunction<T extends BaseEvent = BaseEvent> = (event: T) => EventHandlerReturn<T> | unknown | Promise<EventHandlerReturn<T> | unknown>;
@@ -33,7 +34,5 @@ export declare const normalizeEventPattern: (event_pattern: EventPattern | "*")
33
34
  export declare const isZodSchema: (value: unknown) => value is z.ZodTypeAny;
34
35
  export declare const eventResultTypeFromConstructor: (value: unknown) => z.ZodTypeAny | undefined;
35
36
  export declare const extractZodShape: (raw: Record<string, unknown>) => z.ZodRawShape;
36
- export declare const toJsonSchema: (schema: unknown) => unknown;
37
- export declare const fromJsonSchema: (schema: unknown) => z.ZodTypeAny;
38
- export declare const normalizeEventResultType: (value: EventResultTypeInput) => z.ZodTypeAny | undefined;
37
+ export declare function normalizeEventResultType(value: unknown): z.ZodTypeAny | undefined;
39
38
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abxbus",
3
- "version": "2.5.3",
3
+ "version": "2.5.6",
4
4
  "description": "Event bus library for browsers and ESM Node.js",
5
5
  "type": "module",
6
6
  "sideEffects": false,