@daiso-tech/core 0.20.0 → 0.21.1
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.
- package/dist/cjs/async/utilities/lazy-promise/lazy-promise.js +13 -7
- package/dist/cjs/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/cjs/cache/contracts/cache.errors.js +13 -0
- package/dist/cjs/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cjs/cache/contracts/cache.events.js +17 -130
- package/dist/cjs/cache/contracts/cache.events.js.map +1 -1
- package/dist/cjs/cache/implementations/_shared/cache-adapter.test-suite.js +0 -19
- package/dist/cjs/cache/implementations/_shared/cache-adapter.test-suite.js.map +1 -1
- package/dist/cjs/cache/implementations/_shared/cache.test-suite.js +671 -0
- package/dist/cjs/cache/implementations/_shared/cache.test-suite.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +0 -20
- package/dist/cjs/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +0 -3
- package/dist/cjs/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +0 -4
- package/dist/cjs/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +0 -23
- package/dist/cjs/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +0 -3
- package/dist/cjs/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +0 -5
- package/dist/cjs/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +0 -3
- package/dist/cjs/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +1 -1
- package/dist/cjs/cache/implementations/derivables/cache/cache-settings.js +0 -18
- package/dist/cjs/cache/implementations/derivables/cache/cache-settings.js.map +1 -1
- package/dist/cjs/cache/implementations/derivables/cache/cache.js +4 -69
- package/dist/cjs/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cjs/cache/implementations/derivables/cache-factory/cache-factory.js +17 -13
- package/dist/cjs/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cjs/event-bus/contracts/_shared.js +3 -2
- package/dist/cjs/event-bus/contracts/_shared.js.map +1 -1
- package/dist/cjs/event-bus/contracts/event-bus.errors.js +14 -0
- package/dist/cjs/event-bus/contracts/event-bus.errors.js.map +1 -1
- package/dist/cjs/event-bus/implementations/_shared/event-bus-adapter.test-suite.js +1 -12
- package/dist/cjs/event-bus/implementations/_shared/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/cjs/event-bus/implementations/_shared/event-bus.test-suite.js +2 -24
- package/dist/cjs/event-bus/implementations/_shared/event-bus.test-suite.js.map +1 -1
- package/dist/cjs/event-bus/implementations/derivables/event-bus/event-bus-settings.js +0 -12
- package/dist/cjs/event-bus/implementations/derivables/event-bus/event-bus-settings.js.map +1 -1
- package/dist/cjs/event-bus/implementations/derivables/event-bus/event-bus.js +1 -29
- package/dist/cjs/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/cjs/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +17 -15
- package/dist/cjs/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/cjs/serde/implementations/no-op-serde/no-op-serde.js +3 -0
- package/dist/cjs/serde/implementations/no-op-serde/no-op-serde.js.map +1 -1
- package/dist/cjs/serde/implementations/super-json-serde/super-json-serde.js +15 -0
- package/dist/cjs/serde/implementations/super-json-serde/super-json-serde.js.map +1 -1
- package/dist/esm/async/utilities/lazy-promise/lazy-promise.js +13 -7
- package/dist/esm/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/esm/cache/contracts/cache.errors.js +12 -0
- package/dist/esm/cache/contracts/cache.errors.js.map +1 -1
- package/dist/esm/cache/contracts/cache.events.js +15 -129
- package/dist/esm/cache/contracts/cache.events.js.map +1 -1
- package/dist/esm/cache/implementations/_shared/cache-adapter.test-suite.js +0 -19
- package/dist/esm/cache/implementations/_shared/cache-adapter.test-suite.js.map +1 -1
- package/dist/esm/cache/implementations/_shared/cache.test-suite.js +672 -1
- package/dist/esm/cache/implementations/_shared/cache.test-suite.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +0 -20
- package/dist/esm/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +0 -3
- package/dist/esm/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +0 -4
- package/dist/esm/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +0 -23
- package/dist/esm/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +0 -3
- package/dist/esm/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +0 -5
- package/dist/esm/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +0 -3
- package/dist/esm/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +1 -1
- package/dist/esm/cache/implementations/derivables/cache/cache-settings.js +0 -18
- package/dist/esm/cache/implementations/derivables/cache/cache-settings.js.map +1 -1
- package/dist/esm/cache/implementations/derivables/cache/cache.js +5 -70
- package/dist/esm/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/esm/cache/implementations/derivables/cache-factory/cache-factory.js +17 -13
- package/dist/esm/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/esm/event-bus/contracts/_shared.js +3 -2
- package/dist/esm/event-bus/contracts/_shared.js.map +1 -1
- package/dist/esm/event-bus/contracts/event-bus.errors.js +13 -0
- package/dist/esm/event-bus/contracts/event-bus.errors.js.map +1 -1
- package/dist/esm/event-bus/implementations/_shared/event-bus-adapter.test-suite.js +1 -12
- package/dist/esm/event-bus/implementations/_shared/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/esm/event-bus/implementations/_shared/event-bus.test-suite.js +2 -24
- package/dist/esm/event-bus/implementations/_shared/event-bus.test-suite.js.map +1 -1
- package/dist/esm/event-bus/implementations/derivables/event-bus/event-bus-settings.js +0 -12
- package/dist/esm/event-bus/implementations/derivables/event-bus/event-bus-settings.js.map +1 -1
- package/dist/esm/event-bus/implementations/derivables/event-bus/event-bus.js +2 -30
- package/dist/esm/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/esm/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +14 -12
- package/dist/esm/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/esm/serde/implementations/no-op-serde/no-op-serde.js +3 -0
- package/dist/esm/serde/implementations/no-op-serde/no-op-serde.js.map +1 -1
- package/dist/esm/serde/implementations/super-json-serde/super-json-serde.js +15 -0
- package/dist/esm/serde/implementations/super-json-serde/super-json-serde.js.map +1 -1
- package/dist/types/cache/contracts/cache-adapter.contract.d.ts +0 -4
- package/dist/types/cache/contracts/cache.errors.d.ts +7 -2
- package/dist/types/cache/contracts/cache.events.d.ts +22 -93
- package/dist/types/cache/implementations/_shared/cache.test-suite.d.ts +6 -10
- package/dist/types/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +0 -1
- package/dist/types/cache/implementations/derivables/cache/cache-settings.d.ts +2 -29
- package/dist/types/cache/implementations/derivables/cache/cache.d.ts +5 -33
- package/dist/types/cache/implementations/derivables/cache-factory/cache-factory-settings.d.ts +1 -1
- package/dist/types/cache/implementations/derivables/cache-factory/cache-factory.d.ts +4 -5
- package/dist/types/event-bus/contracts/_shared.d.ts +3 -4
- package/dist/types/event-bus/contracts/event-bus-factory.contract.d.ts +4 -23
- package/dist/types/event-bus/contracts/event-bus.errors.d.ts +7 -2
- package/dist/types/event-bus/implementations/derivables/event-bus/event-bus-settings.d.ts +1 -19
- package/dist/types/event-bus/implementations/derivables/event-bus/event-bus.d.ts +16 -14
- package/dist/types/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +30 -5
- package/dist/types/serde/contracts/flexible-serde.contract.d.ts +3 -2
- package/dist/types/serde/implementations/no-op-serde/no-op-serde.d.ts +2 -1
- package/dist/types/serde/implementations/super-json-serde/super-json-serde.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Cache
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
4
|
+
import { type ICacheFactory, type IGroupableCache } from "../../../../cache/contracts/_module";
|
|
5
5
|
import type { CacheFactorySettings } from "../../../../cache/implementations/derivables/cache-factory/cache-factory-settings";
|
|
6
6
|
import { CacheFactorySettingsBuilder } from "../../../../cache/implementations/derivables/cache-factory/cache-factory-settings";
|
|
7
7
|
/**
|
|
@@ -33,10 +33,9 @@ export declare class CacheFactory<TAdapters extends string = string> implements
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
static settings<TAdapters extends string, TSettings extends CacheFactorySettings<TAdapters>>(): CacheFactorySettingsBuilder<TSettings>;
|
|
36
|
-
private readonly
|
|
37
|
-
private readonly adapters;
|
|
36
|
+
private readonly cacheRecord;
|
|
38
37
|
private readonly defaultAdapter?;
|
|
39
|
-
private readonly eventBus
|
|
38
|
+
private readonly eventBus;
|
|
40
39
|
private readonly defaultTtl;
|
|
41
40
|
private readonly retryAttempts?;
|
|
42
41
|
private readonly backoffPolicy?;
|
|
@@ -73,6 +72,6 @@ export declare class CacheFactory<TAdapters extends string = string> implements
|
|
|
73
72
|
* ```
|
|
74
73
|
*/
|
|
75
74
|
constructor(settings: CacheFactorySettings<TAdapters>);
|
|
76
|
-
private
|
|
75
|
+
private init;
|
|
77
76
|
use<TType = unknown>(adapterName?: TAdapters | undefined): IGroupableCache<TType>;
|
|
78
77
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module EventBus
|
|
3
3
|
*/
|
|
4
|
-
import type { ISerializable } from "../../serde/contracts/_module";
|
|
5
4
|
import type { Promisable } from "../../utilities/_module";
|
|
6
5
|
/**
|
|
7
6
|
* @group Contracts
|
|
@@ -10,7 +9,7 @@ export type Listener<TEvent> = (event: TEvent) => Promisable<void>;
|
|
|
10
9
|
/**
|
|
11
10
|
* @group Contracts
|
|
12
11
|
*/
|
|
13
|
-
export declare abstract class BaseEvent<
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export declare abstract class BaseEvent<TFields extends Record<string, unknown> = Record<string, unknown>> {
|
|
13
|
+
readonly fields: TFields;
|
|
14
|
+
constructor(fields: TFields);
|
|
16
15
|
}
|
|
@@ -17,29 +17,10 @@ export type IEventBusFactory<TAdapters extends string = string> = {
|
|
|
17
17
|
* ```ts
|
|
18
18
|
* import { type IEventBusFactory } from "@daiso-tech/core";
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* class AddEvent extends BaseEvent<{
|
|
21
21
|
* a: number;
|
|
22
22
|
* b: number;
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* class AddEvent extends BaseEvent<SerializedAddEvent> {
|
|
26
|
-
* // This needed for adapters that need to deserialize like the redis dapter.
|
|
27
|
-
* static override deserialize({ a, b }: SerializedAddEvent): AddEvent {
|
|
28
|
-
* return new AddEvent(a, b);
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* constructor(public readonly a: number, public readonly b: number) {
|
|
32
|
-
* super();
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* // This needed for adapters that need to serialize like the redis adapter.
|
|
36
|
-
* override serialize(): SerializedAddEvent {
|
|
37
|
-
* return {
|
|
38
|
-
* a: this.a,
|
|
39
|
-
* b: this.b
|
|
40
|
-
* };
|
|
41
|
-
* }
|
|
42
|
-
* }
|
|
23
|
+
* }> {}
|
|
43
24
|
*
|
|
44
25
|
* // Asume the inputed eventFactory has registered both a memory and Redis IEventBusAdapter.
|
|
45
26
|
* // The memory IEventBusAdapter adapter is the default.
|
|
@@ -47,11 +28,11 @@ export type IEventBusFactory<TAdapters extends string = string> = {
|
|
|
47
28
|
* // Will dispatch envent using the default adapter
|
|
48
29
|
* await eventBusFactory
|
|
49
30
|
* .use()
|
|
50
|
-
* .dispatch(new AddEvent(1, 2));
|
|
31
|
+
* .dispatch(new AddEvent({ a: 1, b: 2 }));
|
|
51
32
|
* // Will dispatch envent using the redis addapter
|
|
52
33
|
* await eventBusFactory
|
|
53
34
|
* .use("redis")
|
|
54
|
-
* .dispatch(new AddEvent(1, 2));
|
|
35
|
+
* .dispatch(new AddEvent({ a: 1, b: 2 }));
|
|
55
36
|
* }
|
|
56
37
|
* ```
|
|
57
38
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module EventBus
|
|
3
3
|
*/
|
|
4
|
-
import type { ISerializable } from "../../serde/contracts/_module";
|
|
5
|
-
import type { ISerializedError } from "../../utilities/_module";
|
|
4
|
+
import type { IFlexibleSerde, ISerializable } from "../../serde/contracts/_module";
|
|
5
|
+
import type { ISerializedError, OneOrMore } from "../../utilities/_module";
|
|
6
6
|
/**
|
|
7
7
|
* @group Errors
|
|
8
8
|
*/
|
|
@@ -38,3 +38,8 @@ export declare class UnableToAddListenerEventBusError extends UnexpectedEventBus
|
|
|
38
38
|
export declare class UnableToDispatchEventBusError extends UnexpectedEventBusError {
|
|
39
39
|
constructor(message: string, cause?: unknown);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The <i>registerEventBusErrors</i> function registers all <i>{@link IGroupableEventBus}</i> related errors with <i>IFlexibleSerde</i>, ensuring they will properly be serialized and deserialized.
|
|
43
|
+
* @group Errors
|
|
44
|
+
*/
|
|
45
|
+
export declare function registerEventBusErrors(serde: OneOrMore<IFlexibleSerde>): void;
|
|
@@ -3,23 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { BackoffPolicy, RetryPolicy } from "../../../../async/_module";
|
|
5
5
|
import { type IGroupableEventBus, type IEventBusAdapter } from "../../../../event-bus/contracts/_module";
|
|
6
|
-
import type {
|
|
7
|
-
import type { IBuildable, OneOrMore, TimeSpan } from "../../../../utilities/_module";
|
|
6
|
+
import type { IBuildable, TimeSpan } from "../../../../utilities/_module";
|
|
8
7
|
/**
|
|
9
8
|
* @group Derivables
|
|
10
9
|
*/
|
|
11
10
|
export type EventBusSettings = {
|
|
12
|
-
/**
|
|
13
|
-
* You can pass one or more <i>{@link IFlexibleSerde}</i> that will be used to register all <i>{@link IGroupableEventBus}</i> related errors.
|
|
14
|
-
* @default {true}
|
|
15
|
-
*/
|
|
16
|
-
serde: OneOrMore<IFlexibleSerde>;
|
|
17
|
-
/**
|
|
18
|
-
* If set to true, all <i>{@link IGroupableEventBus}</i> related errors will be registered with the specified <i>IFlexibleSerde</i> during constructor initialization.
|
|
19
|
-
* This ensures that all <i>{@link IGroupableEventBus}</i> related errors will be serialized correctly.
|
|
20
|
-
* @default {true}
|
|
21
|
-
*/
|
|
22
|
-
shouldRegisterErrors?: boolean;
|
|
23
11
|
adapter: IEventBusAdapter;
|
|
24
12
|
/**
|
|
25
13
|
* The default retry attempt to use in the returned <i>LazyPromise</i>.
|
|
@@ -49,12 +37,6 @@ export type EventBusSettings = {
|
|
|
49
37
|
export declare class EventBusSettingsBuilder<TSettings extends Partial<EventBusSettings>> implements IBuildable<EventBusSettings> {
|
|
50
38
|
private readonly settings;
|
|
51
39
|
constructor(settings?: TSettings);
|
|
52
|
-
setShouldRegisterErrors(shouldRegisterErrors: boolean): EventBusSettingsBuilder<TSettings & {
|
|
53
|
-
shouldRegisterErrors: boolean;
|
|
54
|
-
}>;
|
|
55
|
-
setSerde(serde: OneOrMore<IFlexibleSerde>): EventBusSettingsBuilder<TSettings & {
|
|
56
|
-
serde: OneOrMore<IFlexibleSerde>;
|
|
57
|
-
}>;
|
|
58
40
|
setAdapter(adapter: IEventBusAdapter): EventBusSettingsBuilder<TSettings & {
|
|
59
41
|
adapter: IEventBusAdapter;
|
|
60
42
|
}>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { LazyPromise } from "../../../../async/_module";
|
|
5
5
|
import type { EventClass, EventInstance, Unsubscribe } from "../../../../event-bus/contracts/_module";
|
|
6
|
-
import { type IEventBus, type IGroupableEventBus, type Listener, type BaseEvent
|
|
6
|
+
import { type IEventBus, type IGroupableEventBus, type Listener, type BaseEvent } from "../../../../event-bus/contracts/_module";
|
|
7
7
|
import type { OneOrMore } from "../../../../utilities/_module";
|
|
8
8
|
import type { EventBusSettings } from "../../../../event-bus/implementations/derivables/event-bus/event-bus-settings";
|
|
9
9
|
import { EventBusSettingsBuilder } from "../../../../event-bus/implementations/derivables/event-bus/event-bus-settings";
|
|
@@ -12,38 +12,40 @@ import { EventBusSettingsBuilder } from "../../../../event-bus/implementations/d
|
|
|
12
12
|
* @group Derivables
|
|
13
13
|
*/
|
|
14
14
|
export declare class EventBus<TEvents extends BaseEvent = BaseEvent> implements IGroupableEventBus<TEvents> {
|
|
15
|
-
static readonly errors: {
|
|
16
|
-
readonly Error: typeof EventBusError;
|
|
17
|
-
readonly Unexpected: typeof UnexpectedEventBusError;
|
|
18
|
-
readonly RemoveListener: typeof UnableToRemoveListenerEventBusError;
|
|
19
|
-
readonly AddListener: typeof UnableToAddListenerEventBusError;
|
|
20
|
-
};
|
|
21
15
|
/**
|
|
22
16
|
* @example
|
|
23
17
|
* ```ts
|
|
24
|
-
* import { EventBus, MemoryEventBusAdapter } from "@daiso-tech/core";
|
|
18
|
+
* import { EventBus, MemoryEventBusAdapter, registerEventErrors, SuperJsonSerde } from "@daiso-tech/core";
|
|
25
19
|
*
|
|
26
|
-
* const
|
|
20
|
+
* const eventBus = new EventBus(
|
|
27
21
|
* EventBus
|
|
28
22
|
* .settings()
|
|
29
23
|
* .setAdapter(new MemoryEventBusAdapter({ rootGroup: "@global" }))
|
|
30
24
|
* .build()
|
|
31
25
|
* );
|
|
26
|
+
* const serde = new SuperJsonSerde();
|
|
27
|
+
* registerEventErrors(serde)
|
|
32
28
|
* ```
|
|
33
29
|
*/
|
|
34
30
|
static settings<TSettings extends Partial<EventBusSettings>>(): EventBusSettingsBuilder<TSettings>;
|
|
35
|
-
private readonly serde;
|
|
36
31
|
private readonly adapter;
|
|
37
32
|
private readonly retryAttempts;
|
|
38
33
|
private readonly backoffPolicy;
|
|
39
34
|
private readonly retryPolicy;
|
|
40
35
|
private readonly timeout;
|
|
41
|
-
private readonly shouldRegisterErrors;
|
|
42
|
-
constructor(settings: EventBusSettings);
|
|
43
36
|
/**
|
|
44
|
-
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { EventBus, MemoryEventBusAdapter, registerEventErrors, SuperJsonSerde } from "@daiso-tech/core";
|
|
40
|
+
*
|
|
41
|
+
* const eventBus = new EventBus({
|
|
42
|
+
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
43
|
+
* });
|
|
44
|
+
* const serde = new SuperJsonSerde();
|
|
45
|
+
* registerEventErrors(serde)
|
|
46
|
+
* ```
|
|
45
47
|
*/
|
|
46
|
-
|
|
48
|
+
constructor(settings: EventBusSettings);
|
|
47
49
|
private createLayPromise;
|
|
48
50
|
withGroup(group: OneOrMore<string>): IEventBus<TEvents>;
|
|
49
51
|
getGroup(): string;
|
package/dist/types/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module EventBus
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
4
|
+
import { type IGroupableEventBus, type IEventBusFactory, type BaseEvent } from "../../../../event-bus/contracts/_module";
|
|
5
5
|
import { type EventBusFactorySettings, EventBusFactorySettingsBuilder } from "../../../../event-bus/implementations/derivables/event-bus-factory/event-bus-factory-settings";
|
|
6
6
|
/**
|
|
7
7
|
* @group Derivables
|
|
@@ -21,6 +21,7 @@ import { type EventBusFactorySettings, EventBusFactorySettingsBuilder } from "..
|
|
|
21
21
|
* }),
|
|
22
22
|
* },
|
|
23
23
|
* defaultAdapter: "memory",
|
|
24
|
+
* serde: new SuperJsonSerde()
|
|
24
25
|
* });
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
@@ -31,16 +32,18 @@ export declare class EventBusFactory<TAdapters extends string = string> implemen
|
|
|
31
32
|
* import { EventBusFactory, SuperJsonSerde. MemoryEventBusAdapter, RedisPubSubEventBusAdapter, EventBus, MemoryEventBusAdapter } from "@daiso-tech/core";
|
|
32
33
|
* import Redis from "ioredis";
|
|
33
34
|
*
|
|
35
|
+
* const serde = new SuperJsonSerde();
|
|
34
36
|
* const cacheFactory = new EventBusFactory(
|
|
35
37
|
* EventBusFactory
|
|
36
38
|
* .settings()
|
|
39
|
+
* .setSerde(serde)
|
|
37
40
|
* .setAdapter("memory", new MemoryEventBusAdapter({
|
|
38
41
|
* rootGroup: "@global"
|
|
39
42
|
* }))
|
|
40
43
|
* .setAdapter("redis", new RedisPubSubEventBusAdapter({
|
|
41
44
|
* dispatcherClient: new Redis("YOUR_REDIS_CONNECTION"),
|
|
42
45
|
* listenerClient: new Redis("YOUR_REDIS_CONNECTION")
|
|
43
|
-
* serde
|
|
46
|
+
* serde,
|
|
44
47
|
* rootGroup: "@global"
|
|
45
48
|
* }))
|
|
46
49
|
* .setDefaultAdapter("memory")
|
|
@@ -49,16 +52,38 @@ export declare class EventBusFactory<TAdapters extends string = string> implemen
|
|
|
49
52
|
* ```
|
|
50
53
|
*/
|
|
51
54
|
static settings<TAdapters extends string, TSettings extends EventBusFactorySettings<TAdapters>>(): EventBusFactorySettingsBuilder<TSettings>;
|
|
52
|
-
private readonly
|
|
55
|
+
private readonly eventBusRecord;
|
|
53
56
|
private readonly serde;
|
|
54
|
-
private readonly adapters;
|
|
55
57
|
private readonly defaultAdapter?;
|
|
56
58
|
private readonly retryAttempts?;
|
|
57
59
|
private readonly backoffPolicy?;
|
|
58
60
|
private readonly retryPolicy?;
|
|
59
61
|
private readonly timeout?;
|
|
60
62
|
private readonly shouldRegisterErrors?;
|
|
63
|
+
/**
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { EventBusFactory, SuperJsonSerde. MemoryEventBusAdapter, RedisPubSubEventBusAdapter, EventBus, MemoryEventBusAdapter } from "@daiso-tech/core";
|
|
67
|
+
* import Redis from "ioredis";
|
|
68
|
+
* const serde = new SuperJsonSerde();
|
|
69
|
+
* const cacheFactory = new EventBusFactory({
|
|
70
|
+
* serde,
|
|
71
|
+
* adapters: {
|
|
72
|
+
* memory:new MemoryEventBusAdapter({
|
|
73
|
+
* rootGroup: "@global"
|
|
74
|
+
* }),
|
|
75
|
+
* redis: new RedisPubSubEventBusAdapter({
|
|
76
|
+
* dispatcherClient: new Redis("YOUR_REDIS_CONNECTION"),
|
|
77
|
+
* listenerClient: new Redis("YOUR_REDIS_CONNECTION")
|
|
78
|
+
* serde,
|
|
79
|
+
* rootGroup: "@global"
|
|
80
|
+
* }),
|
|
81
|
+
* defaultAdapter: "memory"
|
|
82
|
+
* }
|
|
83
|
+
* })
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
61
86
|
constructor(settings: EventBusFactorySettings<TAdapters>);
|
|
62
|
-
private
|
|
87
|
+
private init;
|
|
63
88
|
use<TEvents extends BaseEvent = BaseEvent>(adapterName?: TAdapters | undefined): IGroupableEventBus<TEvents>;
|
|
64
89
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { ISerializable } from "../../serde/contracts/serializable.contract";
|
|
5
5
|
import type { ISerde } from "../../serde/contracts/serde.contract";
|
|
6
|
+
import type { BaseEvent } from "../../_module";
|
|
6
7
|
/**
|
|
7
8
|
* The <i>SerializableClass</i> contract defines standard way to make a class instance serializable and deserializable.
|
|
8
9
|
* @group Contracts
|
|
@@ -12,10 +13,9 @@ export type SerializableClass<TSerializedValue> = {
|
|
|
12
13
|
deserialize(serializedValue: TSerializedValue): ISerializable<TSerializedValue>;
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
|
-
* The <i>SerializableClass</i> contract defines standard way to make a error class instance serializable and deserializable.
|
|
16
16
|
* @group Contracts
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type SerializableEventClass<TFields extends Record<string, unknown>> = new (fields: any) => BaseEvent<TFields>;
|
|
19
19
|
/**
|
|
20
20
|
* @group Contracts
|
|
21
21
|
*/
|
|
@@ -30,6 +30,7 @@ export type ISerdeTransformer<TDeserializedValue, TSerializedValue> = {
|
|
|
30
30
|
* @group Contracts
|
|
31
31
|
*/
|
|
32
32
|
export type IFlexibleSerde<TSerializedValue = unknown> = ISerde<TSerializedValue> & {
|
|
33
|
+
registerEvent<TFields extends Record<string, unknown>>(eventClass: SerializableEventClass<TFields>): IFlexibleSerde<TSerializedValue>;
|
|
33
34
|
/**
|
|
34
35
|
* The <i>registerClass</i> method is used for registering custom class for serialization and deserialization.
|
|
35
36
|
* The <i>class_</i> parameter must be of type <i>{@link SerializableClass}</i>.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module EventBus
|
|
3
3
|
*/
|
|
4
|
-
import type { IFlexibleSerde, ISerdeTransformer, SerializableClass } from "../../../serde/contracts/_module";
|
|
4
|
+
import type { SerializableEventClass, IFlexibleSerde, ISerdeTransformer, SerializableClass } from "../../../serde/contracts/_module";
|
|
5
5
|
/**
|
|
6
6
|
* This <i>NoOpSerde</i> will do nothing and is used for easily mocking {@link IFlexibleSerde} or {@link ISerde} for testing.
|
|
7
7
|
* @group Adapters
|
|
8
8
|
*/
|
|
9
9
|
export declare class NoOpSerde<TSerializedValue> implements IFlexibleSerde<TSerializedValue> {
|
|
10
|
+
registerEvent<TFields extends Record<string, unknown>>(_eventClass: SerializableEventClass<TFields>): IFlexibleSerde<TSerializedValue>;
|
|
10
11
|
serialize<TValue>(value: TValue): TSerializedValue;
|
|
11
12
|
deserialize<TValue>(serializedValue: TSerializedValue): TValue;
|
|
12
13
|
registerClass<TSerializedClassInstance>(_class: SerializableClass<TSerializedClassInstance>): IFlexibleSerde<TSerializedValue>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Serde
|
|
3
3
|
*/
|
|
4
|
-
import type { ISerdeTransformer, SerializableClass } from "../../../serde/contracts/_module";
|
|
4
|
+
import type { SerializableEventClass, ISerdeTransformer, SerializableClass } from "../../../serde/contracts/_module";
|
|
5
5
|
import { type IFlexibleSerde } from "../../../serde/contracts/_module";
|
|
6
6
|
/**
|
|
7
7
|
* The <i>SuperJsonSerde</i> class has direct support for the following values
|
|
@@ -41,6 +41,7 @@ export declare class SuperJsonSerde implements IFlexibleSerde<string> {
|
|
|
41
41
|
private registerFloat64Array;
|
|
42
42
|
private registerAll;
|
|
43
43
|
registerClass<TSerializedClassInstance>(class_: SerializableClass<TSerializedClassInstance>): IFlexibleSerde<string>;
|
|
44
|
+
registerEvent<TFields extends Record<string, unknown>>(eventClass: SerializableEventClass<TFields>): IFlexibleSerde<string>;
|
|
44
45
|
serialize<TValue>(value: TValue): string;
|
|
45
46
|
deserialize<TValue>(value: string): TValue;
|
|
46
47
|
}
|