@daiso-tech/core 0.17.4 → 0.19.0

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 (82) hide show
  1. package/dist/cjs/cache/contracts/cache.errors.js +19 -0
  2. package/dist/cjs/cache/contracts/cache.errors.js.map +1 -1
  3. package/dist/cjs/cache/contracts/cache.events.js +0 -12
  4. package/dist/cjs/cache/contracts/cache.events.js.map +1 -1
  5. package/dist/cjs/cache/implementations/derivables/cache-factory-settings.js +18 -0
  6. package/dist/cjs/cache/implementations/derivables/cache-factory-settings.js.map +1 -1
  7. package/dist/cjs/cache/implementations/derivables/cache-factory.js +32 -12
  8. package/dist/cjs/cache/implementations/derivables/cache-factory.js.map +1 -1
  9. package/dist/cjs/cache/implementations/derivables/cache-settings.js +18 -0
  10. package/dist/cjs/cache/implementations/derivables/cache-settings.js.map +1 -1
  11. package/dist/cjs/cache/implementations/derivables/cache.js +64 -1
  12. package/dist/cjs/cache/implementations/derivables/cache.js.map +1 -1
  13. package/dist/cjs/event-bus/contracts/event-bus.errors.js +19 -0
  14. package/dist/cjs/event-bus/contracts/event-bus.errors.js.map +1 -1
  15. package/dist/cjs/event-bus/implementations/derivables/event-bus-factory-settings.js +12 -0
  16. package/dist/cjs/event-bus/implementations/derivables/event-bus-factory-settings.js.map +1 -1
  17. package/dist/cjs/event-bus/implementations/derivables/event-bus-factory.js +27 -10
  18. package/dist/cjs/event-bus/implementations/derivables/event-bus-factory.js.map +1 -1
  19. package/dist/cjs/event-bus/implementations/derivables/event-bus-settings.js +12 -0
  20. package/dist/cjs/event-bus/implementations/derivables/event-bus-settings.js.map +1 -1
  21. package/dist/cjs/event-bus/implementations/derivables/event-bus.js +29 -1
  22. package/dist/cjs/event-bus/implementations/derivables/event-bus.js.map +1 -1
  23. package/dist/cjs/serde/implementations/_shared/test-utilities/flexible-serde.test-suite.js +16 -0
  24. package/dist/cjs/serde/implementations/_shared/test-utilities/flexible-serde.test-suite.js.map +1 -1
  25. package/dist/cjs/serde/implementations/no-op-serde/no-op-serde.js +3 -0
  26. package/dist/cjs/serde/implementations/no-op-serde/no-op-serde.js.map +1 -1
  27. package/dist/cjs/serde/implementations/super-json-serde/super-json-serde.js +54 -111
  28. package/dist/cjs/serde/implementations/super-json-serde/super-json-serde.js.map +1 -1
  29. package/dist/cjs/utilities/contracts/_module.js +1 -0
  30. package/dist/cjs/utilities/contracts/_module.js.map +1 -1
  31. package/dist/cjs/utilities/contracts/serialized-error.contract.js +3 -0
  32. package/dist/cjs/utilities/contracts/serialized-error.contract.js.map +1 -0
  33. package/dist/esm/cache/contracts/cache.errors.js +19 -0
  34. package/dist/esm/cache/contracts/cache.errors.js.map +1 -1
  35. package/dist/esm/cache/contracts/cache.events.js +0 -11
  36. package/dist/esm/cache/contracts/cache.events.js.map +1 -1
  37. package/dist/esm/cache/implementations/derivables/cache-factory-settings.js +18 -0
  38. package/dist/esm/cache/implementations/derivables/cache-factory-settings.js.map +1 -1
  39. package/dist/esm/cache/implementations/derivables/cache-factory.js +32 -12
  40. package/dist/esm/cache/implementations/derivables/cache-factory.js.map +1 -1
  41. package/dist/esm/cache/implementations/derivables/cache-settings.js +18 -0
  42. package/dist/esm/cache/implementations/derivables/cache-settings.js.map +1 -1
  43. package/dist/esm/cache/implementations/derivables/cache.js +65 -2
  44. package/dist/esm/cache/implementations/derivables/cache.js.map +1 -1
  45. package/dist/esm/event-bus/contracts/event-bus.errors.js +19 -0
  46. package/dist/esm/event-bus/contracts/event-bus.errors.js.map +1 -1
  47. package/dist/esm/event-bus/implementations/derivables/event-bus-factory-settings.js +12 -0
  48. package/dist/esm/event-bus/implementations/derivables/event-bus-factory-settings.js.map +1 -1
  49. package/dist/esm/event-bus/implementations/derivables/event-bus-factory.js +27 -10
  50. package/dist/esm/event-bus/implementations/derivables/event-bus-factory.js.map +1 -1
  51. package/dist/esm/event-bus/implementations/derivables/event-bus-settings.js +12 -0
  52. package/dist/esm/event-bus/implementations/derivables/event-bus-settings.js.map +1 -1
  53. package/dist/esm/event-bus/implementations/derivables/event-bus.js +30 -2
  54. package/dist/esm/event-bus/implementations/derivables/event-bus.js.map +1 -1
  55. package/dist/esm/serde/implementations/_shared/test-utilities/flexible-serde.test-suite.js +16 -0
  56. package/dist/esm/serde/implementations/_shared/test-utilities/flexible-serde.test-suite.js.map +1 -1
  57. package/dist/esm/serde/implementations/no-op-serde/no-op-serde.js +3 -0
  58. package/dist/esm/serde/implementations/no-op-serde/no-op-serde.js.map +1 -1
  59. package/dist/esm/serde/implementations/super-json-serde/super-json-serde.js +54 -111
  60. package/dist/esm/serde/implementations/super-json-serde/super-json-serde.js.map +1 -1
  61. package/dist/esm/utilities/contracts/_module.js +1 -0
  62. package/dist/esm/utilities/contracts/_module.js.map +1 -1
  63. package/dist/esm/utilities/contracts/serialized-error.contract.js +1 -0
  64. package/dist/esm/utilities/contracts/serialized-error.contract.js.map +1 -0
  65. package/dist/types/cache/contracts/cache.errors.d.ts +11 -4
  66. package/dist/types/cache/contracts/cache.events.d.ts +0 -6
  67. package/dist/types/cache/implementations/derivables/cache-factory-settings.d.ts +32 -1
  68. package/dist/types/cache/implementations/derivables/cache-factory.d.ts +10 -2
  69. package/dist/types/cache/implementations/derivables/cache-settings.d.ts +33 -1
  70. package/dist/types/cache/implementations/derivables/cache.d.ts +32 -2
  71. package/dist/types/event-bus/contracts/event-bus.errors.d.ts +8 -1
  72. package/dist/types/event-bus/implementations/derivables/event-bus-factory-settings.d.ts +23 -1
  73. package/dist/types/event-bus/implementations/derivables/event-bus-factory.d.ts +4 -0
  74. package/dist/types/event-bus/implementations/derivables/event-bus-settings.d.ts +23 -1
  75. package/dist/types/event-bus/implementations/derivables/event-bus.d.ts +13 -1
  76. package/dist/types/serde/contracts/flexible-serde.contract.d.ts +65 -1
  77. package/dist/types/serde/implementations/no-op-serde/no-op-serde.d.ts +2 -1
  78. package/dist/types/serde/implementations/super-json-serde/super-json-serde.d.ts +22 -1
  79. package/dist/types/utilities/contracts/_module.d.ts +1 -0
  80. package/dist/types/utilities/contracts/serialized-error.contract.d.ts +11 -0
  81. package/dist/types/utilities/types.d.ts +1 -1
  82. package/package.json +1 -1
@@ -2,7 +2,8 @@
2
2
  * @module Cache
3
3
  */
4
4
  import type { CacheEvents, WithTtlValue } from "../../../cache/contracts/_module";
5
- import { type ICache } from "../../../cache/contracts/_module";
5
+ import { KeyFoundCacheEvent, KeyNotFoundCacheEvent, KeyAddedCacheEvent, KeyUpdatedCacheEvent, KeyRemovedCacheEvent, KeyIncrementedCacheEvent, KeyDecrementedCacheEvent, KeysClearedCacheEvent, type ICache } from "../../../cache/contracts/_module";
6
+ import { CacheError, KeyNotFoundCacheError, TypeCacheError, UnexpectedCacheError } from "../../../cache/contracts/_module";
6
7
  import { type IGroupableCache } from "../../../cache/contracts/_module";
7
8
  import type { AsyncLazyable, GetOrAddValue, OneOrMore } from "../../../utilities/_module";
8
9
  import type { TimeSpan } from "../../../utilities/_module";
@@ -15,14 +16,31 @@ import { CacheSettingsBuilder } from "../../../cache/implementations/derivables/
15
16
  * @group Derivables
16
17
  */
17
18
  export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
19
+ static readonly errors: {
20
+ readonly Error: typeof CacheError;
21
+ readonly Unexpected: typeof UnexpectedCacheError;
22
+ readonly Type: typeof TypeCacheError;
23
+ readonly KeyNotFound: typeof KeyNotFoundCacheError;
24
+ };
25
+ static readonly events: {
26
+ readonly KeyFound: typeof KeyFoundCacheEvent;
27
+ readonly KeyNotFound: typeof KeyNotFoundCacheEvent;
28
+ readonly KeyAdded: typeof KeyAddedCacheEvent;
29
+ readonly KeyUpdated: typeof KeyUpdatedCacheEvent;
30
+ readonly KeyRemoved: typeof KeyRemovedCacheEvent;
31
+ readonly KeyIncremented: typeof KeyIncrementedCacheEvent;
32
+ readonly KeyDecremented: typeof KeyDecrementedCacheEvent;
33
+ readonly KeysCleared: typeof KeysClearedCacheEvent;
34
+ };
18
35
  /**
19
36
  * @example
20
37
  * ```ts
21
- * import { Cache, MemoryCacheAdapter, TimeSpan } from "@daiso-tech/core";
38
+ * import { Cache, MemoryCacheAdapter, TimeSpan, SuperJsonSerde } from "@daiso-tech/core";
22
39
  *
23
40
  * const cache = new Cache(
24
41
  * Cache
25
42
  * .settings()
43
+ * .setSerde(new SuperJsonSerde())
26
44
  * .setAdapter(new MemoryCacheAdapter({ rootGroup: "@global" }))
27
45
  * .setEventBus(new EventBus(new MemoryEventBusAdapter({ rootGroup: "@global" })))
28
46
  * .setDefaultTtl(TimeSpan.fromMinutes(2))
@@ -40,6 +58,9 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
40
58
  private readonly backoffPolicy;
41
59
  private readonly retryPolicy;
42
60
  private readonly timeout;
61
+ private readonly serde;
62
+ private readonly shouldRegisterErrors;
63
+ private readonly shouldRegisterEvents;
43
64
  /**
44
65
  *@example
45
66
  * ```ts
@@ -49,6 +70,7 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
49
70
  * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
50
71
  * });
51
72
  * const cache = new Cache({
73
+ * serde: new SuperJsonSerde();
52
74
  * adapter: new MemoryCacheAdapter({
53
75
  * rootGroup: "@global"
54
76
  * }),
@@ -57,6 +79,14 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
57
79
  * ```
58
80
  */
59
81
  constructor(settings: CacheSettings);
82
+ /**
83
+ * Registers all cache-related events within the given <i>IFlexibleSerde</i> contract.
84
+ */
85
+ private registerEvents;
86
+ /**
87
+ * Registers all cache-related error within the given <i>IFlexibleSerde</i> contract.
88
+ */
89
+ private registerErrors;
60
90
  private createLayPromise;
61
91
  private createKeyFoundEvent;
62
92
  private createKeyNotFoundEvent;
@@ -1,28 +1,35 @@
1
1
  /**
2
2
  * @module EventBus
3
3
  */
4
+ import type { ISerializable } from "../../serde/contracts/_module";
5
+ import type { ISerializedError } from "../../utilities/_module";
4
6
  /**
5
7
  * @group Errors
6
8
  */
7
- export declare class EventBusError extends Error {
9
+ export declare class EventBusError extends Error implements ISerializable<ISerializedError> {
10
+ static deserialize(deserializedValue: ISerializedError): EventBusError;
8
11
  constructor(message: string, cause?: unknown);
12
+ serialize(): ISerializedError;
9
13
  }
10
14
  /**
11
15
  * @group Errors
12
16
  */
13
17
  export declare class UnexpectedEventBusError extends EventBusError {
18
+ static deserialize(deserializedValue: ISerializedError): EventBusError;
14
19
  constructor(message: string, cause?: unknown);
15
20
  }
16
21
  /**
17
22
  * @group Errors
18
23
  */
19
24
  export declare class RemoveListenerEventBusError extends UnexpectedEventBusError {
25
+ static deserialize(deserializedValue: ISerializedError): EventBusError;
20
26
  constructor(message: string, cause?: unknown);
21
27
  }
22
28
  /**
23
29
  * @group Errors
24
30
  */
25
31
  export declare class AddListenerEventBusError extends UnexpectedEventBusError {
32
+ static deserialize(deserializedValue: ISerializedError): EventBusError;
26
33
  constructor(message: string, cause?: unknown);
27
34
  }
28
35
  /**
@@ -3,7 +3,8 @@
3
3
  */
4
4
  import type { BackoffPolicy, RetryPolicy } from "../../../async/_module";
5
5
  import type { IGroupableEventBus, IEventBusAdapter } from "../../../event-bus/contracts/_module";
6
- import type { TimeSpan } from "../../../utilities/_module";
6
+ import type { IFlexibleSerde } from "../../../serde/contracts/_module";
7
+ import type { OneOrMore, TimeSpan } from "../../../utilities/_module";
7
8
  /**
8
9
  * @group Derivables
9
10
  */
@@ -13,6 +14,17 @@ export type EventBusAdapters<TAdapters extends string = string> = Partial<Record
13
14
  * @group Derivables
14
15
  */
15
16
  export type EventBusFactorySettings<TAdapters extends string = string> = {
17
+ /**
18
+ * You can pass one or more <i>{@link IFlexibleSerde}</i> that will be used to register all <i>{@link IGroupableEventBus}</i> related errors.
19
+ * @default {true}
20
+ */
21
+ serde: OneOrMore<IFlexibleSerde>;
22
+ /**
23
+ * If set to true, all <i>{@link IGroupableEventBus}</i> related errors will be registered with the specified <i>IFlexibleSerde</i> during constructor initialization.
24
+ * This ensures that all <i>{@link IGroupableEventBus}</i> related errors will be serialized correctly.
25
+ * @default {true}
26
+ */
27
+ shouldRegisterErrors?: boolean;
16
28
  adapters: EventBusAdapters<TAdapters>;
17
29
  defaultAdapter?: NoInfer<TAdapters>;
18
30
  /**
@@ -21,18 +33,22 @@ export type EventBusFactorySettings<TAdapters extends string = string> = {
21
33
  eventBus?: IGroupableEventBus<any>;
22
34
  /**
23
35
  * The default retry attempt to use in the returned <i>LazyPromise</i>.
36
+ * @default {null}
24
37
  */
25
38
  retryAttempts?: number | null;
26
39
  /**
27
40
  * The default backof policy to use in the returned <i>LazyPromise</i>.
41
+ * @default {null}
28
42
  */
29
43
  backoffPolicy?: BackoffPolicy | null;
30
44
  /**
31
45
  * The default retry policy to use in the returned <i>LazyPromise</i>.
46
+ * @default {null}
32
47
  */
33
48
  retryPolicy?: RetryPolicy | null;
34
49
  /**
35
50
  * The default timeout to use in the returned <i>LazyPromise</i>.
51
+ * @default {null}
36
52
  */
37
53
  timeout?: TimeSpan | null;
38
54
  };
@@ -43,6 +59,12 @@ export type EventBusFactorySettings<TAdapters extends string = string> = {
43
59
  export declare class EventBusFactorySettingsBuilder<TSettings extends EventBusFactorySettings> {
44
60
  private readonly settings;
45
61
  constructor(settings?: TSettings);
62
+ setShouldRegisterErrors(shouldRegisterErrors: boolean): EventBusFactorySettingsBuilder<TSettings & {
63
+ shouldRegisterErrors: boolean;
64
+ }>;
65
+ setSerde(serde: OneOrMore<IFlexibleSerde>): EventBusFactorySettingsBuilder<TSettings & {
66
+ serde: OneOrMore<IFlexibleSerde>;
67
+ }>;
46
68
  setEventBus(eventBus: IGroupableEventBus<any>): EventBusFactorySettingsBuilder<TSettings & {
47
69
  eventBus: IGroupableEventBus<any>;
48
70
  }>;
@@ -49,12 +49,16 @@ export declare class EventBusFactory<TAdapters extends string = string> implemen
49
49
  * ```
50
50
  */
51
51
  static settings<TAdapters extends string, TSettings extends EventBusFactorySettings<TAdapters>>(): EventBusFactorySettingsBuilder<TSettings>;
52
+ private readonly eventBuses;
53
+ private readonly serde;
52
54
  private readonly adapters;
53
55
  private readonly defaultAdapter?;
54
56
  private readonly retryAttempts?;
55
57
  private readonly backoffPolicy?;
56
58
  private readonly retryPolicy?;
57
59
  private readonly timeout?;
60
+ private readonly shouldRegisterErrors?;
58
61
  constructor(settings: EventBusFactorySettings<TAdapters>);
62
+ private initCaches;
59
63
  use<TEvents extends BaseEvent = BaseEvent>(adapterName?: TAdapters | undefined): IGroupableEventBus<TEvents>;
60
64
  }
@@ -3,26 +3,42 @@
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 { IBuildable, TimeSpan } from "../../../utilities/_module";
6
+ import type { IFlexibleSerde } from "../../../serde/contracts/_module";
7
+ import type { IBuildable, OneOrMore, TimeSpan } from "../../../utilities/_module";
7
8
  /**
8
9
  * @group Derivables
9
10
  */
10
11
  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;
11
23
  adapter: IEventBusAdapter;
12
24
  /**
13
25
  * The default retry attempt to use in the returned <i>LazyPromise</i>.
26
+ * @default {null}
14
27
  */
15
28
  retryAttempts?: number | null;
16
29
  /**
17
30
  * The default backof policy to use in the returned <i>LazyPromise</i>.
31
+ * @default {null}
18
32
  */
19
33
  backoffPolicy?: BackoffPolicy | null;
20
34
  /**
21
35
  * The default retry policy to use in the returned <i>LazyPromise</i>.
36
+ * @default {null}
22
37
  */
23
38
  retryPolicy?: RetryPolicy | null;
24
39
  /**
25
40
  * The default timeout to use in the returned <i>LazyPromise</i>.
41
+ * @default {null}
26
42
  */
27
43
  timeout?: TimeSpan | null;
28
44
  };
@@ -33,6 +49,12 @@ export type EventBusSettings = {
33
49
  export declare class EventBusSettingsBuilder<TSettings extends Partial<EventBusSettings>> implements IBuildable<EventBusSettings> {
34
50
  private readonly settings;
35
51
  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
+ }>;
36
58
  setAdapter(adapter: IEventBusAdapter): EventBusSettingsBuilder<TSettings & {
37
59
  adapter: IEventBusAdapter;
38
60
  }>;
@@ -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 } from "../../../event-bus/contracts/_module";
6
+ import { type IEventBus, type IGroupableEventBus, type Listener, type BaseEvent, RemoveListenerEventBusError, AddListenerEventBusError, UnexpectedEventBusError, EventBusError } 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-settings";
9
9
  import { EventBusSettingsBuilder } from "../../../event-bus/implementations/derivables/event-bus-settings";
@@ -12,6 +12,12 @@ import { EventBusSettingsBuilder } from "../../../event-bus/implementations/deri
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 RemoveListenerEventBusError;
19
+ readonly AddListener: typeof AddListenerEventBusError;
20
+ };
15
21
  /**
16
22
  * @example
17
23
  * ```ts
@@ -26,12 +32,18 @@ export declare class EventBus<TEvents extends BaseEvent = BaseEvent> implements
26
32
  * ```
27
33
  */
28
34
  static settings<TSettings extends Partial<EventBusSettings>>(): EventBusSettingsBuilder<TSettings>;
35
+ private readonly serde;
29
36
  private readonly adapter;
30
37
  private readonly retryAttempts;
31
38
  private readonly backoffPolicy;
32
39
  private readonly retryPolicy;
33
40
  private readonly timeout;
41
+ private readonly shouldRegisterErrors;
34
42
  constructor(settings: EventBusSettings);
43
+ /**
44
+ * Registers all event bus related error within the given <i>IFlexibleSerde</i> contract.
45
+ */
46
+ private registerErrors;
35
47
  private createLayPromise;
36
48
  withGroup(group: OneOrMore<string>): IEventBus<TEvents>;
37
49
  getGroup(): string;
@@ -11,6 +11,20 @@ export type SerializableClass<TSerializedValue> = {
11
11
  new (...arguments_: any[]): ISerializable<TSerializedValue>;
12
12
  deserialize(serializedValue: TSerializedValue): ISerializable<TSerializedValue>;
13
13
  };
14
+ /**
15
+ * The <i>SerializableClass</i> contract defines standard way to make a error class instance serializable and deserializable.
16
+ * @group Contracts
17
+ */
18
+ export type ErrorClass = new (...args: any[]) => Error;
19
+ /**
20
+ * @group Contracts
21
+ */
22
+ export type ISerdeTransformer<TDeserializedValue, TSerializedValue> = {
23
+ name: string;
24
+ isApplicable(value: unknown): value is TDeserializedValue;
25
+ deserialize(serializedValue: TSerializedValue): TDeserializedValue;
26
+ serialize(deserializedValue: TDeserializedValue): TSerializedValue;
27
+ };
14
28
  /**
15
29
  * The <i>IFlexibleSerde</i> contract defines a standard way to serialize and deserialize both plain data and custom classes.
16
30
  * @group Contracts
@@ -49,8 +63,58 @@ export type IFlexibleSerde<TSerializedValue = unknown> = ISerde<TSerializedValue
49
63
  * console.log(user.getInfo());
50
64
  * // "name: Jacob, age: 50"
51
65
  * }
52
- *
53
66
  * ```
54
67
  */
55
68
  registerClass<TSerializedClassInstance>(class_: SerializableClass<TSerializedClassInstance>): IFlexibleSerde<TSerializedValue>;
69
+ /**
70
+ * The <i>registerCustom</i> method is used for registering custom values for serialization and deserialization.
71
+ * @example
72
+ * ```ts
73
+ * import type { IFlexibleSerde, ISerdeTransformer } from "@daiso-tech/core";
74
+ *
75
+ * type SerializedUser = {
76
+ * name: string;
77
+ * age: number;
78
+ * };
79
+ *
80
+ * class User implements ISerializable<SerializedUser> {
81
+ * static deserialize(serializedUser: SerializedUser): User {
82
+ * return new User(serializedUser.name, serializedUser.age);
83
+ * }
84
+ *
85
+ * constructor(public readonly name: string, public readonly age: number) {}
86
+ *
87
+ * getInfo(): string {
88
+ * return `name: ${this.name}, age: ${this.age}`;
89
+ * }
90
+ * }
91
+ *
92
+ * const transformer: ISerdeTransformer<User, SerializedUser> = {
93
+ * name: User.name,
94
+ * isApplicable(value): value is User {
95
+ * return (
96
+ * value instanceof User &&
97
+ * value.constructor.name === User.name
98
+ * );
99
+ * },
100
+ * deserialize(serializedValue) {
101
+ * return User.deserialize(serializedValue);
102
+ * },
103
+ * serialize(deserializedValue) {
104
+ * return deserializedValue.serialize();
105
+ * }
106
+ * }
107
+ *
108
+ * function main(serde: IFlexibleSerde) {
109
+ * // You must register the transformer is it will get applied.
110
+ * serde.registerCustom(transformer);
111
+ *
112
+ * const user = serde.deserialize(serde.serialize(new User("Jacob", 50)));
113
+ *
114
+ * console.log(user.getInfo());
115
+ * // "name: Jacob, age: 50"
116
+ * }
117
+ * ```
118
+ */
119
+ registerCustom<TCustomSerialized, TCustomDeserialized>(transformer: ISerdeTransformer<TCustomSerialized, TCustomDeserialized>): IFlexibleSerde<TSerializedValue>;
56
120
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module EventBus
3
3
  */
4
- import type { IFlexibleSerde, SerializableClass } from "../../../serde/contracts/_module";
4
+ import type { 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
@@ -10,4 +10,5 @@ export declare class NoOpSerde<TSerializedValue> implements IFlexibleSerde<TSeri
10
10
  serialize<TValue>(value: TValue): TSerializedValue;
11
11
  deserialize<TValue>(serializedValue: TSerializedValue): TValue;
12
12
  registerClass<TSerializedClassInstance>(_class: SerializableClass<TSerializedClassInstance>): IFlexibleSerde<TSerializedValue>;
13
+ registerCustom<TCustomSerialized, TCustomDeserialized>(_transformer: ISerdeTransformer<TCustomSerialized, TCustomDeserialized>): IFlexibleSerde<TSerializedValue>;
13
14
  }
@@ -1,14 +1,35 @@
1
1
  /**
2
2
  * @module Serde
3
3
  */
4
- import type { SerializableClass } from "../../../serde/contracts/_module";
4
+ import type { ISerdeTransformer, SerializableClass } from "../../../serde/contracts/_module";
5
5
  import { type IFlexibleSerde } from "../../../serde/contracts/_module";
6
6
  /**
7
+ * The <i>SuperJsonSerde</i> class has direct support for the following values
8
+ * - String
9
+ * - Number
10
+ * - Boolean
11
+ * - Null,
12
+ * - Arrays
13
+ * - Object literals
14
+ * - Date
15
+ * - Map
16
+ * - Set
17
+ * - BigInt
18
+ * - Buffer
19
+ * - Uint8Array
20
+ * - Int8Array
21
+ * - Uint16Array
22
+ * - Int16Array
23
+ * - Uint32Array
24
+ * - Int32Array
25
+ * - Float32Array
26
+ * - Float64Array
7
27
  * @group Adapters
8
28
  */
9
29
  export declare class SuperJsonSerde implements IFlexibleSerde<string> {
10
30
  private readonly superJson;
11
31
  constructor();
32
+ registerCustom<TCustomSerialized, TCustomDeserialized>(transformer: ISerdeTransformer<TCustomSerialized, TCustomDeserialized>): IFlexibleSerde<string>;
12
33
  private registerBuffer;
13
34
  private registerUint8Array;
14
35
  private registerInt8Array;
@@ -1,3 +1,4 @@
1
+ export * from "../../utilities/contracts/serialized-error.contract";
1
2
  export * from "../../utilities/contracts/buildable.contract";
2
3
  export * from "../../utilities/contracts/deinitizable.contract";
3
4
  export * from "../../utilities/contracts/initizable.contract";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module Utilities
3
+ */
4
+ /**
5
+ * @group Contracts
6
+ */
7
+ export type ISerializedError = {
8
+ name: string;
9
+ message: string;
10
+ cause?: unknown;
11
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Utilities
3
3
  */
4
- export type OneOrMore<TItem> = TItem | TItem[];
4
+ export type OneOrMore<TItem> = TItem | [TItem, ...TItem[]];
5
5
  export type Lazyable<TValue> = TValue | (() => TValue);
6
6
  export type Promisable<TValue> = TValue | PromiseLike<TValue>;
7
7
  export type AsyncLazyable<TValue> = TValue | (() => Promisable<TValue>);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@daiso-tech/core",
3
3
  "private": false,
4
- "version": "0.17.4",
4
+ "version": "0.19.0",
5
5
  "author": "Yousif Abdulkarim",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./dist/cjs/_module.js",