@daiso-tech/core 0.24.0 → 0.26.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 (96) hide show
  1. package/README.md +3 -2
  2. package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +12 -3
  3. package/dist/async/utilities/lazy-promise/lazy-promise.js +37 -4
  4. package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
  5. package/dist/cache/contracts/cache.contract.d.ts +4 -4
  6. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +2 -2
  7. package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +1 -1
  8. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +4 -4
  9. package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
  10. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +2 -2
  11. package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
  12. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +5 -5
  13. package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
  14. package/dist/cache/implementations/derivables/cache/cache.d.ts +70 -184
  15. package/dist/cache/implementations/derivables/cache/cache.js +68 -185
  16. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  17. package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +11 -15
  18. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +0 -11
  19. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
  20. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +5 -5
  21. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
  22. package/dist/collection/implementations/iterable-collection/iterable-collection.js +5 -5
  23. package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
  24. package/dist/collection/implementations/list-collection/list-collection.js +5 -5
  25. package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
  26. package/dist/event-bus/contracts/_shared.d.ts +0 -7
  27. package/dist/event-bus/contracts/_shared.js.map +1 -1
  28. package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +6 -5
  29. package/dist/event-bus/contracts/event-bus.contract.d.ts +21 -16
  30. package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +4 -3
  31. package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +3 -3
  32. package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
  33. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +4 -3
  34. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js.map +1 -1
  35. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +4 -3
  36. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +3 -3
  37. package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
  38. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +64 -33
  39. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +92 -33
  40. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  41. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +957 -201
  42. package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
  43. package/dist/lock/contracts/lock-provider.contract.d.ts +2 -2
  44. package/dist/lock/contracts/lock.contract.d.ts +24 -6
  45. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +2 -2
  46. package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
  47. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +4 -4
  48. package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
  49. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +2 -2
  50. package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
  51. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +4 -4
  52. package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
  53. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +90 -48
  54. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +67 -43
  55. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  56. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +4 -23
  57. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +8 -2
  58. package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
  59. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +744 -11
  60. package/dist/lock/implementations/derivables/lock-provider/lock.js +770 -3
  61. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  62. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +36 -5
  63. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +10 -4
  64. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  65. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +1 -0
  66. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +417 -0
  67. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
  68. package/dist/serde/implementations/derivables/serde.js +4 -4
  69. package/dist/serde/implementations/derivables/serde.js.map +1 -1
  70. package/dist/utilities/{constants.js → _constants.js} +1 -1
  71. package/dist/utilities/_constants.js.map +1 -0
  72. package/dist/utilities/_module-exports.d.ts +1 -1
  73. package/dist/utilities/_module-exports.js +1 -1
  74. package/dist/utilities/_module-exports.js.map +1 -1
  75. package/dist/utilities/contracts/_module.d.ts +0 -1
  76. package/dist/utilities/contracts/_module.js +0 -1
  77. package/dist/utilities/contracts/_module.js.map +1 -1
  78. package/dist/utilities/functions.d.ts +3 -7
  79. package/dist/utilities/functions.js +3 -10
  80. package/dist/utilities/functions.js.map +1 -1
  81. package/dist/utilities/pipeline/_module.d.ts +1 -0
  82. package/dist/utilities/pipeline/_module.js +2 -0
  83. package/dist/utilities/pipeline/_module.js.map +1 -0
  84. package/dist/utilities/pipeline/pipeline.d.ts +45 -0
  85. package/dist/utilities/pipeline/pipeline.js +75 -0
  86. package/dist/utilities/pipeline/pipeline.js.map +1 -0
  87. package/dist/utilities/time-span/time-span.d.ts +3 -12
  88. package/dist/utilities/time-span/time-span.js +3 -6
  89. package/dist/utilities/time-span/time-span.js.map +1 -1
  90. package/dist/utilities/types.d.ts +19 -2
  91. package/package.json +1 -1
  92. package/dist/utilities/constants.js.map +0 -1
  93. package/dist/utilities/contracts/buildable.contract.d.ts +0 -11
  94. package/dist/utilities/contracts/buildable.contract.js +0 -5
  95. package/dist/utilities/contracts/buildable.contract.js.map +0 -1
  96. /package/dist/utilities/{constants.d.ts → _constants.d.ts} +0 -0
@@ -4,11 +4,11 @@
4
4
  import type { CacheEvents, WithTtlValue } from "../../../../cache/contracts/_module-exports.js";
5
5
  import { type ICache, type ICacheAdapter } from "../../../../cache/contracts/_module-exports.js";
6
6
  import { type IGroupableCache } from "../../../../cache/contracts/_module-exports.js";
7
- import type { AsyncLazyable, GetOrAddValue, OneOrMore } from "../../../../utilities/_module-exports.js";
7
+ import type { AsyncLazyable, GetOrAddValue, Invokable, OneOrMore } from "../../../../utilities/_module-exports.js";
8
8
  import type { TimeSpan } from "../../../../utilities/_module-exports.js";
9
9
  import type { BackoffPolicy, RetryPolicy } from "../../../../async/_module-exports.js";
10
10
  import { LazyPromise } from "../../../../async/_module-exports.js";
11
- import type { IGroupableEventBus, Listener, Unsubscribe, EventClass, EventInstance } from "../../../../event-bus/contracts/_module-exports.js";
11
+ import type { IGroupableEventBus, Unsubscribe, EventClass, EventInstance } from "../../../../event-bus/contracts/_module-exports.js";
12
12
  /**
13
13
  *
14
14
  * IMPORT_PATH: ```"@daiso-tech/core/cache/implementations/derivables"```
@@ -17,7 +17,14 @@ import type { IGroupableEventBus, Listener, Unsubscribe, EventClass, EventInstan
17
17
  export type CacheSettings = {
18
18
  adapter: ICacheAdapter<any>;
19
19
  /**
20
- * In order to listen to events of <i>{@link Cache}</i> class you must pass in <i>{@link IGroupableEventBus}</i>.
20
+ * @default
21
+ * ```ts
22
+ * new EventBus({
23
+ * adapter: new MemoryEventBusAdapter({
24
+ * rootGroup: "@global"
25
+ * })
26
+ * })
27
+ * ```
21
28
  */
22
29
  eventBus?: IGroupableEventBus<any>;
23
30
  /**
@@ -66,245 +73,220 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
66
73
  * @example
67
74
  * ```ts
68
75
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
69
- * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
70
76
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
71
77
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
72
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
73
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
74
78
  *
75
- * const eventBus: IGroupableEventBus = new EventBus({
76
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
77
- * });
78
79
  * const cache: IGroupableCache = new Cache({
79
80
  * adapter: new MemoryCacheAdapter({
80
81
  * rootGroup: "@global"
81
82
  * }),
82
- * eventBus,
83
83
  * });
84
84
  * ```
85
85
  */
86
86
  constructor(settings: CacheSettings);
87
87
  private createLayPromise;
88
88
  /**
89
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
90
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
89
+ * You can listen to different events of <i>Cache</i> class instance.
90
+ *
91
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
92
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
91
93
  * @example
92
94
  * ```ts
93
95
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
94
96
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
95
97
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
96
98
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
97
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
98
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
99
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
99
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
100
100
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
101
101
  *
102
- * const eventBus: IGroupableEventBus = new EventBus({
103
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
104
- * });
105
102
  * const cache: IGroupableCache = new Cache({
106
103
  * adapter: new MemoryCacheAdapter({
107
104
  * rootGroup: "@global"
108
105
  * }),
109
- * eventBus,
110
106
  * });
111
107
  *
112
- * const listener: Listener<CacheEvents> = event => {
108
+ * const listener: Invokable<CacheEvents> = event => {
113
109
  * console.log(event);
114
110
  * };
115
111
  * await cache.addListener(KeyAddedCacheEvent, listener);
112
+ * await cache.add("a", 1);
116
113
  * ```
117
114
  */
118
- addListener<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
115
+ addListener<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
119
116
  /**
120
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
121
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
117
+ * You can listen to different events of <i>Cache</i> class instance.
118
+ *
119
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
120
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
122
121
  * @example
123
122
  * ```ts
124
123
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
125
124
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
126
125
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
127
126
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
128
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
129
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
130
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
131
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
127
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
128
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
132
129
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
133
130
  *
134
- * const eventBus: IGroupableEventBus = new EventBus({
135
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
136
- * });
137
131
  * const cache: IGroupableCache = new Cache({
138
132
  * adapter: new MemoryCacheAdapter({
139
133
  * rootGroup: "@global"
140
134
  * }),
141
- * eventBus,
142
135
  * });
143
136
  *
144
- * const listener: Listener<CacheEvents> = event => {
137
+ * const listener: Invokable<CacheEvents> = event => {
145
138
  * console.log(event);
146
139
  * };
147
140
  * await cache.addListenerMany([KeyAddedCacheEvent], listener);
141
+ * await cache.add("a", 1);
148
142
  * ```
149
143
  */
150
- addListenerMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
144
+ addListenerMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
151
145
  /**
152
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
153
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
146
+ * You can listen to different events of <i>Cache</i> class instance.
147
+ *
148
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
149
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
154
150
  * @example
155
151
  * ```ts
156
152
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
157
153
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
158
154
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
159
155
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
160
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
161
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
162
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
156
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
163
157
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
164
158
  *
165
- * const eventBus: IGroupableEventBus = new EventBus({
166
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
167
- * });
168
159
  * const cache: IGroupableCache = new Cache({
169
160
  * adapter: new MemoryCacheAdapter({
170
161
  * rootGroup: "@global"
171
162
  * }),
172
- * eventBus,
173
163
  * });
174
164
  *
175
- * const listener: Listener<CacheEvents> = event => {
165
+ * const listener: Invokable<CacheEvents> = event => {
176
166
  * console.log(event);
177
167
  * };
168
+ * await cache.addListener(KeyAddedCacheEvent, listener);
178
169
  * await cache.removeListener(KeyAddedCacheEvent, listener);
170
+ * await cache.add("a", 1);
179
171
  * ```
180
172
  */
181
- removeListener<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
173
+ removeListener<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
182
174
  /**
183
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
184
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
175
+ * You can listen to different events of <i>Cache</i> class instance.
176
+ *
177
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
178
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
185
179
  * @example
186
180
  * ```ts
187
181
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
188
182
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
189
183
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
190
184
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
191
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
192
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
193
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
185
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
194
186
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
195
187
  *
196
- * const eventBus: IGroupableEventBus = new EventBus({
197
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
198
- * });
199
188
  * const cache: IGroupableCache = new Cache({
200
189
  * adapter: new MemoryCacheAdapter({
201
190
  * rootGroup: "@global"
202
191
  * }),
203
- * eventBus,
204
192
  * });
205
193
  *
206
- * const listener: Listener<CacheEvents> = event => {
194
+ * const listener: Invokable<CacheEvents> = event => {
207
195
  * console.log(event);
208
196
  * };
197
+ * await cache.addListenerMany([KeyAddedCacheEvent], listener);
209
198
  * await cache.removeListenerMany(KeyAddedCacheEvent, listener);
199
+ * await cache.add("a", 1);
210
200
  * ```
211
201
  */
212
- removeListenerMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
202
+ removeListenerMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
213
203
  /**
214
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
215
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
204
+ * You can listen to different events of <i>Cache</i> class instance.
205
+ *
206
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
207
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
216
208
  * @example
217
209
  * ```ts
218
210
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
219
211
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
220
212
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
221
213
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
222
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
223
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
224
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
214
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
225
215
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
226
216
  *
227
- * const eventBus: IGroupableEventBus = new EventBus({
228
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
229
- * });
230
217
  * const cache: IGroupableCache = new Cache({
231
218
  * adapter: new MemoryCacheAdapter({
232
219
  * rootGroup: "@global"
233
220
  * }),
234
- * eventBus,
235
221
  * });
236
222
  *
237
- * const listener: Listener<CacheEvents> = event => {
223
+ * const listener: Invokable<CacheEvents> = event => {
238
224
  * console.log(event);
239
225
  * };
240
226
  * await cache.listenOnce(KeyAddedCacheEvent, listener);
227
+ * await cache.add("a", 1);
241
228
  * ```
242
229
  */
243
- listenOnce<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
230
+ listenOnce<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
231
+ asPromise<TEventClass extends EventClass<CacheEvents>>(event: TEventClass): LazyPromise<EventInstance<TEventClass>>;
244
232
  /**
245
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
246
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
233
+ * You can listen to different events of <i>Cache</i> class instance.
234
+ *
235
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
236
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
247
237
  * @example
248
238
  * ```ts
249
239
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
250
240
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
251
241
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
252
242
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
253
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
254
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
255
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
243
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
256
244
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
257
245
  *
258
- * const eventBus: IGroupableEventBus = new EventBus({
259
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
260
- * });
261
246
  * const cache: IGroupableCache = new Cache({
262
247
  * adapter: new MemoryCacheAdapter({
263
248
  * rootGroup: "@global"
264
249
  * }),
265
- * eventBus,
266
250
  * });
267
251
  *
268
- * const listener: Listener<CacheEvents> = event => {
252
+ * const listener: Invokable<CacheEvents> = event => {
269
253
  * console.log(event);
270
254
  * };
271
255
  * const unsubscribe = await cache.subscribe(KeyAddedCacheEvent, listener);
256
+ * await cache.add("a", 1);
272
257
  * await unsubscribe();
273
258
  * ```
274
259
  */
275
- subscribe<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
260
+ subscribe<TEventClass extends EventClass<CacheEvents>>(eventName: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
276
261
  /**
277
- * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class.
278
- * Refer to <i>{@link IEventListener}</i> ford details on how the method works.
262
+ * You can listen to different events of <i>Cache</i> class instance.
263
+ *
264
+ * Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
265
+ * Refer to <i>{@link IEventListenable}</i> for details on how the method works.
279
266
  * @example
280
267
  * ```ts
281
268
  * import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
282
269
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
283
270
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
284
271
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
285
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
286
- * import type { Listener } from "@daiso-tech/core/event-bus/contracts";
287
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
272
+ * import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
288
273
  * import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
289
274
  *
290
- * const eventBus: IGroupableEventBus = new EventBus({
291
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
292
- * });
293
275
  * const cache: IGroupableCache = new Cache({
294
276
  * adapter: new MemoryCacheAdapter({
295
277
  * rootGroup: "@global"
296
278
  * }),
297
- * eventBus,
298
279
  * });
299
280
  *
300
- * const listener: Listener<CacheEvents> = event => {
281
+ * const listener: Invokable<CacheEvents> = event => {
301
282
  * console.log(event);
302
283
  * };
303
284
  * const unsubscribe = await cache.subscribeMany([KeyAddedCacheEvent], listener);
285
+ * await cache.add("a", 1);
304
286
  * await unsubscribe();
305
287
  * ```
306
288
  */
307
- subscribeMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Listener<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
289
+ subscribeMany<TEventClass extends EventClass<CacheEvents>>(eventNames: TEventClass[], listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
308
290
  /**
309
291
  * @example
310
292
  * ```ts
@@ -312,17 +294,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
312
294
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
313
295
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
314
296
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
315
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
316
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
317
297
  *
318
- * const eventBus: IGroupableEventBus = new EventBus({
319
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
320
- * });
321
298
  * const cache: IGroupableCache = new Cache({
322
299
  * adapter: new MemoryCacheAdapter({
323
300
  * rootGroup: "@global"
324
301
  * }),
325
- * eventBus,
326
302
  * });
327
303
  *
328
304
  * // Will print "@global"
@@ -342,17 +318,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
342
318
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
343
319
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
344
320
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
345
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
346
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
347
321
  *
348
- * const eventBus: IGroupableEventBus = new EventBus({
349
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
350
- * });
351
322
  * const cache: IGroupableCache = new Cache({
352
323
  * adapter: new MemoryCacheAdapter({
353
324
  * rootGroup: "@global"
354
325
  * }),
355
- * eventBus,
356
326
  * });
357
327
  *
358
328
  * // Will print "@global"
@@ -387,17 +357,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
387
357
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
388
358
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
389
359
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
390
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
391
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
392
360
  *
393
- * const eventBus: IGroupableEventBus = new EventBus({
394
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
395
- * });
396
361
  * const cache: IGroupableCache = new Cache({
397
362
  * adapter: new MemoryCacheAdapter({
398
363
  * rootGroup: "@global"
399
364
  * }),
400
- * eventBus,
401
365
  * });
402
366
  *
403
367
  * const result = await cache.getOr("a", -1);
@@ -412,17 +376,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
412
376
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
413
377
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
414
378
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
415
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
416
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
417
379
  *
418
- * const eventBus: IGroupableEventBus = new EventBus({
419
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
420
- * });
421
380
  * const cache: IGroupableCache = new Cache({
422
381
  * adapter: new MemoryCacheAdapter({
423
382
  * rootGroup: "@global"
424
383
  * }),
425
- * eventBus,
426
384
  * });
427
385
  *
428
386
  * const result = await cache.getOr("a", () => -1);
@@ -437,17 +395,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
437
395
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
438
396
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
439
397
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
440
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
441
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
442
398
  *
443
- * const eventBus: IGroupableEventBus = new EventBus({
444
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
445
- * });
446
399
  * const cache: IGroupableCache = new Cache({
447
400
  * adapter: new MemoryCacheAdapter({
448
401
  * rootGroup: "@global"
449
402
  * }),
450
- * eventBus,
451
403
  * });
452
404
  *
453
405
  * const result = await cache.getOr("a", async () => -1);
@@ -462,17 +414,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
462
414
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
463
415
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
464
416
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
465
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
466
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
467
417
  *
468
- * const eventBus: IGroupableEventBus = new EventBus({
469
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
470
- * });
471
418
  * const cache: IGroupableCache = new Cache({
472
419
  * adapter: new MemoryCacheAdapter({
473
420
  * rootGroup: "@global"
474
421
  * }),
475
- * eventBus,
476
422
  * });
477
423
  *
478
424
  * const result = await cache.getOr("a", new LazyPromise(async () => -1));
@@ -488,17 +434,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
488
434
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
489
435
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
490
436
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
491
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
492
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
493
437
  *
494
- * const eventBus: IGroupableEventBus = new EventBus({
495
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
496
- * });
497
438
  * const cache: IGroupableCache = new Cache({
498
439
  * adapter: new MemoryCacheAdapter({
499
440
  * rootGroup: "@global"
500
441
  * }),
501
- * eventBus,
502
442
  * });
503
443
  *
504
444
  * const result = await cache.getOrMany({ a: -1 });
@@ -513,17 +453,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
513
453
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
514
454
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
515
455
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
516
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
517
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
518
456
  *
519
- * const eventBus: IGroupableEventBus = new EventBus({
520
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
521
- * });
522
457
  * const cache: IGroupableCache = new Cache({
523
458
  * adapter: new MemoryCacheAdapter({
524
459
  * rootGroup: "@global"
525
460
  * }),
526
- * eventBus,
527
461
  * });
528
462
  *
529
463
  * const result = await cache.getOrMany({ a: () => -1 });
@@ -538,17 +472,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
538
472
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
539
473
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
540
474
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
541
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
542
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
543
475
  *
544
- * const eventBus: IGroupableEventBus = new EventBus({
545
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
546
- * });
547
476
  * const cache: IGroupableCache = new Cache({
548
477
  * adapter: new MemoryCacheAdapter({
549
478
  * rootGroup: "@global"
550
479
  * }),
551
- * eventBus,
552
480
  * });
553
481
  *
554
482
  * const result = await cache.getOrMany({ a: async () => -1 });
@@ -563,17 +491,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
563
491
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
564
492
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
565
493
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
566
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
567
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
568
494
  *
569
- * const eventBus: IGroupableEventBus = new EventBus({
570
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
571
- * });
572
495
  * const cache: IGroupableCache = new Cache({
573
496
  * adapter: new MemoryCacheAdapter({
574
497
  * rootGroup: "@global"
575
498
  * }),
576
- * eventBus,
577
499
  * });
578
500
  *
579
501
  * const result = await cache.getOrMany({ a: new LazyPromise(async () => - 1) });
@@ -589,17 +511,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
589
511
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
590
512
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
591
513
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
592
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
593
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
594
514
  *
595
- * const eventBus: IGroupableEventBus = new EventBus({
596
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
597
- * });
598
515
  * const cache: IGroupableCache = new Cache({
599
516
  * adapter: new MemoryCacheAdapter({
600
517
  * rootGroup: "@global"
601
518
  * }),
602
- * eventBus,
603
519
  * });
604
520
  *
605
521
  * await cache.add("a", 1);
@@ -626,17 +542,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
626
542
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
627
543
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
628
544
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
629
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
630
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
631
545
  *
632
- * const eventBus: IGroupableEventBus = new EventBus({
633
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
634
- * });
635
546
  * const cache: IGroupableCache = new Cache({
636
547
  * adapter: new MemoryCacheAdapter({
637
548
  * rootGroup: "@global"
638
549
  * }),
639
- * eventBus,
640
550
  * });
641
551
  *
642
552
  * const result1 = await cache.getAndRemove("a");
@@ -662,17 +572,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
662
572
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
663
573
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
664
574
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
665
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
666
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
667
575
  *
668
- * const eventBus: IGroupableEventBus = new EventBus({
669
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
670
- * });
671
576
  * const cache: IGroupableCache = new Cache({
672
577
  * adapter: new MemoryCacheAdapter({
673
578
  * rootGroup: "@global"
674
579
  * }),
675
- * eventBus,
676
580
  * });
677
581
  *
678
582
  * const result = await cache.getOrAdd("a", -1);
@@ -687,17 +591,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
687
591
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
688
592
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
689
593
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
690
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
691
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
692
594
  *
693
- * const eventBus: IGroupableEventBus = new EventBus({
694
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
695
- * });
696
595
  * const cache: IGroupableCache = new Cache({
697
596
  * adapter: new MemoryCacheAdapter({
698
597
  * rootGroup: "@global"
699
598
  * }),
700
- * eventBus,
701
599
  * });
702
600
  *
703
601
  * const result = await cache.getOrAdd("a", () => -1);
@@ -712,17 +610,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
712
610
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
713
611
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
714
612
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
715
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
716
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
717
613
  *
718
- * const eventBus: IGroupableEventBus = new EventBus({
719
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
720
- * });
721
614
  * const cache: IGroupableCache = new Cache({
722
615
  * adapter: new MemoryCacheAdapter({
723
616
  * rootGroup: "@global"
724
617
  * }),
725
- * eventBus,
726
618
  * });
727
619
  *
728
620
  * const result = await cache.getOrAdd("a", async () => -1);
@@ -737,17 +629,11 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
737
629
  * import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
738
630
  * import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
739
631
  * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
740
- * import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
741
- * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
742
632
  *
743
- * const eventBus: IGroupableEventBus = new EventBus({
744
- * adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
745
- * });
746
633
  * const cache: IGroupableCache = new Cache({
747
634
  * adapter: new MemoryCacheAdapter({
748
635
  * rootGroup: "@global"
749
636
  * }),
750
- * eventBus,
751
637
  * });
752
638
  *
753
639
  * const result = await cache.getOrAdd("a", new LazyPromise(async () => -1));