abxbus 2.5.6 → 2.5.9

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 (46) hide show
  1. package/dist/cjs/BaseEvent.d.ts +12 -32
  2. package/dist/cjs/BaseEvent.js +20 -17
  3. package/dist/cjs/BaseEvent.js.map +2 -2
  4. package/dist/cjs/CoreClient.d.ts +167 -0
  5. package/dist/cjs/CoreEventBus.d.ts +334 -0
  6. package/dist/cjs/LockManager.js +1 -1
  7. package/dist/cjs/LockManager.js.map +2 -2
  8. package/dist/cjs/base_event.d.ts +2 -2
  9. package/dist/cjs/event_handler.d.ts +0 -1
  10. package/dist/cjs/events_suck.d.ts +7 -14
  11. package/dist/cjs/events_suck.js +1 -1
  12. package/dist/cjs/events_suck.js.map +2 -2
  13. package/dist/cjs/retry.d.ts +2 -0
  14. package/dist/cjs/retry.js +110 -35
  15. package/dist/cjs/retry.js.map +3 -3
  16. package/dist/cjs/types.d.ts +3 -6
  17. package/dist/cjs/types.js +1 -1
  18. package/dist/cjs/types.js.map +2 -2
  19. package/dist/esm/BaseEvent.js +20 -17
  20. package/dist/esm/BaseEvent.js.map +2 -2
  21. package/dist/esm/LockManager.js +1 -1
  22. package/dist/esm/LockManager.js.map +2 -2
  23. package/dist/esm/events_suck.js +1 -1
  24. package/dist/esm/events_suck.js.map +2 -2
  25. package/dist/esm/retry.js +110 -35
  26. package/dist/esm/retry.js.map +3 -3
  27. package/dist/esm/types.js +1 -1
  28. package/dist/esm/types.js.map +2 -2
  29. package/dist/types/BaseEvent.d.ts +12 -32
  30. package/dist/types/CoreClient.d.ts +167 -0
  31. package/dist/types/CoreEventBus.d.ts +334 -0
  32. package/dist/types/base_event.d.ts +2 -2
  33. package/dist/types/event_handler.d.ts +0 -1
  34. package/dist/types/events_suck.d.ts +7 -14
  35. package/dist/types/retry.d.ts +2 -0
  36. package/dist/types/types.d.ts +3 -6
  37. package/package.json +1 -1
  38. package/src/BaseEvent.ts +93 -75
  39. package/src/LockManager.ts +1 -1
  40. package/src/events_suck.ts +17 -20
  41. package/src/retry.ts +132 -38
  42. package/src/types.ts +4 -5
  43. package/dist/cjs/bridge_ipc.d.ts +0 -45
  44. package/dist/cjs/middleware_otel_tracing.d.ts +0 -49
  45. package/dist/types/bridge_ipc.d.ts +0 -45
  46. package/dist/types/middleware_otel_tracing.d.ts +0 -49
@@ -57,13 +57,13 @@ type EventPayloadShape<TShape extends z.ZodRawShape> = {
57
57
  [K in keyof TShape as K extends BaseEventFieldName ? never : K]: TShape[K];
58
58
  };
59
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';
60
+ type EventClassMetadataFieldName = 'fromJSON' | 'prototype' | 'event_schema' | 'model_fields' | 'event_type' | 'event_version' | 'event_result_type';
61
61
  type StaticDefaultSchema = z.ZodDefault<z.ZodTypeAny> | z.ZodPrefault<z.ZodTypeAny> | z.ZodCatch<z.ZodTypeAny>;
62
62
  type EventModelFields<TShape extends z.ZodRawShape> = {
63
63
  readonly [K in keyof TShape]: TShape[K];
64
64
  };
65
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]>;
66
+ readonly [K in keyof TShape as K extends EventClassMetadataFieldName ? never : TShape[K] extends StaticDefaultSchema ? K : never]: z.output<TShape[K]>;
67
67
  };
68
68
  type StaticEventDefaultValuesFromSchema<TSchema extends AnyEventSchema> = TSchema extends z.ZodObject<infer TShape> ? StaticEventDefaultValues<TShape> : {};
69
69
  type EventModelFieldsFromSchema<TSchema extends AnyEventSchema> = TSchema extends z.ZodObject<infer TShape> ? TSchema['shape'] & EventModelFields<TShape> : {};
@@ -99,7 +99,7 @@ type ShortcutZodModelFields<TShape> = {
99
99
  [K in keyof ShortcutModelFields<TShape>]: ShortcutModelFields<TShape>[K] extends z.ZodTypeAny ? ShortcutModelFields<TShape>[K] : never;
100
100
  };
101
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];
102
+ readonly [K in keyof TShape as K extends EventClassMetadataFieldName ? never : TShape[K] extends z.ZodTypeAny ? never : K]: TShape[K];
103
103
  };
104
104
  export type EventResultInclude<TEvent extends BaseEvent> = (result: EventResult<TEvent>['result'], event_result: EventResult<TEvent>) => boolean;
105
105
  export type EventResultOptions<TEvent extends BaseEvent> = {
@@ -121,35 +121,15 @@ type EventResultUpdateOptions<TEvent extends BaseEvent> = {
121
121
  result?: EventResultType<TEvent> | BaseEvent | undefined;
122
122
  error?: unknown;
123
123
  };
124
- export type EventFactoryClass<TShape extends z.ZodRawShape, TResult = unknown> = (new (...args: OptionalFactoryArgs<EventInit<TShape>>) => EventWithResultSchema<TResult> & EventPayload<TShape>) & StaticEventDefaultValues<TShape> & {
125
- event_schema: EventSchema<TShape>;
126
- model_fields: EventModelFields<TShape>;
127
- };
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> & {
140
- event_schema: TSchema;
141
- model_fields: EventModelFieldsFromSchema<TSchema>;
142
- };
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>;
124
+ export type EventClass<TEvent extends BaseEvent = BaseEvent, TInit = never, TSchema extends z.ZodTypeAny = AnyEventSchema, TModelFields extends z.ZodRawShape = z.ZodRawShape, TResultSchema extends z.ZodTypeAny | undefined = z.ZodTypeAny | undefined, TStaticFields = {}> = TStaticFields & {
125
+ (...args: OptionalFactoryArgs<TInit>): TEvent;
126
+ new (...args: OptionalFactoryArgs<TInit>): TEvent;
146
127
  event_schema: TSchema;
147
- model_fields: EventModelFieldsFromSchema<TSchema>;
148
- class: SchemaEventFactoryClass<TSchema, TResult>;
128
+ model_fields: TModelFields;
149
129
  event_type: string;
150
130
  event_version: string;
151
- event_result_type: ResultTypeSchemaFromEventSchema<TSchema>;
152
- fromJSON: (data: unknown) => EventWithResultSchema<TResult> & EventPayloadFromSchema<TSchema>;
131
+ event_result_type: TResultSchema;
132
+ fromJSON: (data: unknown) => TEvent;
153
133
  };
154
134
  export declare class BaseEvent {
155
135
  event_id: string;
@@ -189,9 +169,9 @@ export declare class BaseEvent {
189
169
  _lock_for_event_handler: AsyncLock | null;
190
170
  constructor(data?: BaseEventInit<Record<string, unknown>>);
191
171
  toString(): string;
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>>>;
194
- static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventFactory<TShape, ResultSchemaFromShape<TShape>>;
172
+ static extend<TSchema extends z.ZodObject<z.ZodRawShape>>(event_type: string, event_schema: TSchema): EventClass<EventWithResultSchema<ResultSchemaFromEventSchema<TSchema>> & EventPayloadFromSchema<TSchema>, EventInitFromSchema<TSchema>, TSchema, EventModelFieldsFromSchema<TSchema>, ResultTypeSchemaFromEventSchema<TSchema>, StaticEventDefaultValuesFromSchema<TSchema>>;
173
+ static extend<const TShape extends Record<string, unknown>>(event_type: string, shape?: TShape): EventClass<EventWithResultSchema<ResultSchemaFromShape<ShortcutZodModelFields<TShape>>> & EventPayload<ShortcutZodModelFields<TShape>>, EventInit<ShortcutZodModelFields<TShape>>, EventSchema<ShortcutZodModelFields<TShape>>, EventModelFields<ShortcutZodModelFields<TShape>>, ResultTypeSchemaFromShape<ShortcutZodModelFields<TShape>>, ShortcutStaticDefaultValues<TShape, ShortcutZodModelFields<TShape>>>;
174
+ static extend<TShape extends z.ZodRawShape>(event_type: string, shape?: TShape): EventClass<EventWithResultSchema<ResultSchemaFromShape<TShape>> & EventPayload<TShape>, EventInit<TShape>, EventSchema<TShape>, EventModelFields<TShape>, ResultTypeSchemaFromShape<TShape>, StaticEventDefaultValues<TShape>>;
195
175
  static fromJSON<T extends typeof BaseEvent>(this: T, data: unknown): InstanceType<T>;
196
176
  static toJSONArray(events: Iterable<BaseEvent>): BaseEventJSON[];
197
177
  static fromJSONArray(data: unknown): BaseEvent[];
@@ -441,7 +441,7 @@ class BaseEvent {
441
441
  const static_field_defaults = built.static_field_defaults;
442
442
  const event_result_type = built.event_result_type;
443
443
  const event_version = built.event_version;
444
- class ExtendedEvent extends BaseEvent {
444
+ const EventClass = class extends BaseEvent {
445
445
  static event_schema = full_schema;
446
446
  static model_fields = full_schema.shape;
447
447
  static _event_parse_schema = event_parse_schema;
@@ -451,22 +451,25 @@ class BaseEvent {
451
451
  constructor(data) {
452
452
  super(data);
453
453
  }
454
- }
455
- function EventFactory(data) {
456
- return new ExtendedEvent(data);
457
- }
458
- EventFactory.event_schema = full_schema;
459
- EventFactory.model_fields = EventFactory.event_schema.shape;
460
- EventFactory.event_type = event_type;
461
- EventFactory.event_version = event_version ?? BaseEvent.event_version;
462
- EventFactory.event_result_type = event_result_type;
463
- EventFactory.class = ExtendedEvent;
464
- EventFactory.fromJSON = (data) => ExtendedEvent.fromJSON(data);
465
- EventFactory.prototype = ExtendedEvent.prototype;
466
- defineStaticEventFields(ExtendedEvent, static_field_defaults);
467
- defineStaticEventFields(EventFactory, static_field_defaults);
468
- EVENT_TYPE_REGISTRY.set(event_type, ExtendedEvent);
469
- return EventFactory;
454
+ };
455
+ Object.defineProperty(EventClass, "name", { value: event_type, configurable: true });
456
+ defineStaticEventFields(EventClass, static_field_defaults);
457
+ let CallableEventClass;
458
+ CallableEventClass = new Proxy(EventClass, {
459
+ apply(target, _this_arg, args) {
460
+ return Reflect.construct(target, args, target);
461
+ },
462
+ construct(target, args, new_target) {
463
+ return Reflect.construct(target, args, new_target === CallableEventClass ? target : new_target);
464
+ }
465
+ });
466
+ Object.defineProperty(EventClass.prototype, "constructor", {
467
+ value: CallableEventClass,
468
+ writable: true,
469
+ configurable: true
470
+ });
471
+ EVENT_TYPE_REGISTRY.set(event_type, CallableEventClass);
472
+ return CallableEventClass;
470
473
  }
471
474
  static fromJSON(data) {
472
475
  if (!data || typeof data !== "object") {