@daiso-tech/core 0.27.0 → 0.28.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 (83) hide show
  1. package/README.md +10 -10
  2. package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +57 -19
  3. package/dist/async/utilities/lazy-promise/lazy-promise.js +93 -52
  4. package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
  5. package/dist/async/utilities/retry/retry-or-fail.d.ts +2 -0
  6. package/dist/async/utilities/retry/retry-or-fail.js.map +1 -1
  7. package/dist/cache/contracts/cache.contract.d.ts +98 -14
  8. package/dist/cache/implementations/adapters/_module-exports.d.ts +1 -0
  9. package/dist/cache/implementations/adapters/_module-exports.js +1 -0
  10. package/dist/cache/implementations/adapters/_module-exports.js.map +1 -1
  11. package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.d.ts +1 -0
  12. package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js +2 -0
  13. package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js.map +1 -0
  14. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +23 -0
  15. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +41 -0
  16. package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -0
  17. package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +2 -3
  18. package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +1 -1
  19. package/dist/cache/implementations/derivables/cache/cache.d.ts +250 -45
  20. package/dist/cache/implementations/derivables/cache/cache.js +256 -28
  21. package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
  22. package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +20 -17
  23. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +33 -19
  24. package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
  25. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +4 -20
  26. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +7 -4
  27. package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
  28. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +1 -1
  29. package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +1 -1
  30. package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +21 -36
  31. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +24 -17
  32. package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
  33. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +57 -14
  34. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +61 -13
  35. package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
  36. package/dist/lock/contracts/lock-provider.contract.d.ts +19 -5
  37. package/dist/lock/contracts/lock.contract.d.ts +37 -8
  38. package/dist/lock/implementations/adapters/_module-exports.d.ts +1 -0
  39. package/dist/lock/implementations/adapters/_module-exports.js +1 -0
  40. package/dist/lock/implementations/adapters/_module-exports.js.map +1 -1
  41. package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.d.ts +1 -0
  42. package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js +2 -0
  43. package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js.map +1 -0
  44. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +17 -0
  45. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +24 -0
  46. package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -0
  47. package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +2 -3
  48. package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
  49. package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +130 -62
  50. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +134 -44
  51. package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
  52. package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +238 -0
  53. package/dist/lock/implementations/derivables/lock-provider/lock.js +258 -0
  54. package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
  55. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +75 -9
  56. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +85 -7
  57. package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
  58. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +162 -8
  59. package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
  60. package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +1 -0
  61. package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +1 -0
  62. package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js.map +1 -1
  63. package/dist/utilities/_module-exports.d.ts +1 -1
  64. package/dist/utilities/_module-exports.js +1 -1
  65. package/dist/utilities/_module-exports.js.map +1 -1
  66. package/dist/utilities/classes/key-prefixer/key-prefixer.js +1 -1
  67. package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
  68. package/dist/utilities/{_constants.d.ts → constants.d.ts} +0 -3
  69. package/dist/utilities/constants.js +5 -0
  70. package/dist/utilities/constants.js.map +1 -0
  71. package/dist/utilities/contracts/_module.d.ts +2 -1
  72. package/dist/utilities/contracts/_module.js +2 -1
  73. package/dist/utilities/contracts/_module.js.map +1 -1
  74. package/dist/utilities/contracts/sqlite-database.contract.d.ts +26 -0
  75. package/dist/utilities/contracts/sqlite-database.contract.js +5 -0
  76. package/dist/utilities/contracts/sqlite-database.contract.js.map +1 -0
  77. package/dist/utilities/functions.d.ts +4 -0
  78. package/dist/utilities/functions.js +10 -4
  79. package/dist/utilities/functions.js.map +1 -1
  80. package/dist/utilities/types.d.ts +4 -4
  81. package/package.json +1 -1
  82. package/dist/utilities/_constants.js +0 -8
  83. package/dist/utilities/_constants.js.map +0 -1
@@ -6,7 +6,7 @@ import { type ICache, type ICacheAdapter } from "../../../../cache/contracts/_mo
6
6
  import { type IGroupableCache } from "../../../../cache/contracts/_module-exports.js";
7
7
  import { type AsyncLazyable, type Invokable, type OneOrMore } from "../../../../utilities/_module-exports.js";
8
8
  import { type NoneFunction, type TimeSpan, type Factoryable } from "../../../../utilities/_module-exports.js";
9
- import type { BackoffPolicy, RetryPolicy } from "../../../../async/_module-exports.js";
9
+ import type { LazyPromiseSettingsBase } from "../../../../async/_module-exports.js";
10
10
  import { LazyPromise } from "../../../../async/_module-exports.js";
11
11
  import type { IGroupableEventBus, Unsubscribe, EventClass, EventInstance } from "../../../../event-bus/contracts/_module-exports.js";
12
12
  import type { IKeyPrefixer, Items } from "../../../../utilities/_module-exports.js";
@@ -15,7 +15,7 @@ import type { IKeyPrefixer, Items } from "../../../../utilities/_module-exports.
15
15
  * IMPORT_PATH: ```"@daiso-tech/core/cache"```
16
16
  * @group Derivables
17
17
  */
18
- export type CacheSettingsBase = {
18
+ export type CacheSettingsBase = LazyPromiseSettingsBase & {
19
19
  keyPrefixer: IKeyPrefixer;
20
20
  /**
21
21
  * @default
@@ -36,26 +36,6 @@ export type CacheSettingsBase = {
36
36
  * @default {null}
37
37
  */
38
38
  defaultTtl?: TimeSpan | null;
39
- /**
40
- * The default retry attempt to use in the returned <i>LazyPromise</i>.
41
- * @default {null}
42
- */
43
- retryAttempts?: number | null;
44
- /**
45
- * The default backof policy to use in the returned <i>LazyPromise</i>.
46
- * @default {null}
47
- */
48
- backoffPolicy?: BackoffPolicy | null;
49
- /**
50
- * The default retry policy to use in the returned <i>LazyPromise</i>.
51
- * @default {null}
52
- */
53
- retryPolicy?: RetryPolicy | null;
54
- /**
55
- * The default timeout to use in the returned <i>LazyPromise</i>.
56
- * @default {null}
57
- */
58
- timeout?: TimeSpan | null;
59
39
  };
60
40
  /**
61
41
  *
@@ -88,7 +68,8 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
88
68
  private readonly retryAttempts;
89
69
  private readonly backoffPolicy;
90
70
  private readonly retryPolicy;
91
- private readonly timeout;
71
+ private readonly retryTimeout;
72
+ private readonly totalTimeout;
92
73
  private readonly keyPrefixer;
93
74
  /**
94
75
  *
@@ -122,27 +103,29 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
122
103
  * import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
123
104
  * import type { ICacheAdapter } from "@daiso-tech/core/cache/contracts";
124
105
  * import { Serde } from "@daiso-tech/core/serde";
106
+ * import type { ISerde } from "@daiso-tech/core/serde/contracts";
125
107
  * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
126
108
  * import Sqlite from "better-sqlite3";
127
109
  * import { Cache } from "@daiso-tech/core/cache";
128
- * import { KeyPrefixer, type Promiseable } from "@daiso-tech/core/utilities";
129
- *
130
- *
131
- * async function cahceAdapterFactory(prefix: string): Promiseable<ICacheAdapter> {
132
- * const database = new Sqlite("local.db");
133
- * const serde = new Serde(new SuperJsonSerdeAdapter());
134
- * const cacheAdapter = new SqliteCacheAdapter({
135
- * database,
136
- * serde,
137
- * tableName: `cache_${prefix}`
138
- * });
139
- * await cacheAdapter.init();
140
- * return cacheAdapter;
110
+ * import { KeyPrefixer, type ISqliteDatabase, type FactoryFn } from "@daiso-tech/core/utilities";
111
+ *
112
+ * function cahceAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): FactoryFn<string, ICacheAdapter> {
113
+ * return async (prefix) => {
114
+ * const cacheAdapter = new SqliteCacheAdapter({
115
+ * database,
116
+ * serde,
117
+ * tableName: `cache_${prefix}`
118
+ * });
119
+ * await cacheAdapter.init();
120
+ * return cacheAdapter;
121
+ * }
141
122
  * }
142
123
  *
124
+ * const database = new Sqlite("local.db");
125
+ * const serde = new Serde(new SuperJsonSerdeAdapter());
143
126
  * const cache = new Cache({
144
127
  * keyPrefixer: new KeyPrefixer("cache"),
145
- * adapter: cahceAdapterFactory,
128
+ * adapter: cahceAdapterFactory(database, serde),
146
129
  * });
147
130
  * ```
148
131
  *
@@ -152,39 +135,74 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
152
135
  * import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters";
153
136
  * import type { ICacheAdapter } from "@daiso-tech/core/cache/contracts";
154
137
  * import { Serde } from "@daiso-tech/core/serde";
138
+ * import type { ISerde } from "@daiso-tech/core/serde/contracts";
155
139
  * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
156
140
  * import Sqlite from "better-sqlite3";
157
141
  * import { Cache } from "@daiso-tech/core/cache";
158
- * import { KeyPrefixer, type IFactoryObject, type Promiseable } from "@daiso-tech/core/utilities";
142
+ * import { KeyPrefixer, type ISqliteDatabase, type IFactoryObject, type Promiseable } from "@daiso-tech/core/utilities";
159
143
  *
160
144
  * class CahceAdapterFactory implements IFactoryObject<string, ICacheAdapter> {
145
+ * constructor(private readonly database: ISqliteDatabase, private readonly serde: ISerde<string>) {}
146
+ *
161
147
  * async use(prefix: string): Promiseable<ICacheAdapter> {
162
- * const database = new Sqlite("local.db");
163
- * const serde = new Serde(new SuperJsonSerdeAdapter());
164
148
  * const cacheAdapter = new SqliteCacheAdapter({
165
- * database,
166
- * serde,
149
+ * database: this.database,
150
+ * serde: this.serde,
167
151
  * tableName: `cache_${prefix}`
168
152
  * });
169
153
  * await cacheAdapter.init();
170
154
  * return cacheAdapter;
171
155
  * }
172
156
  * }
173
- * const cahceAdapterFactory = new CahceAdapterFactory();
157
+ *
158
+ * const database = new Sqlite("local.db");
159
+ * const serde = new Serde(new SuperJsonSerdeAdapter());
174
160
  * const cache = new Cache({
175
161
  * keyPrefixer: new KeyPrefixer("cache"),
176
- * adapter: cahceAdapterFactory,
162
+ * adapter: new CahceAdapterFactory(database, serde),
177
163
  * });
178
164
  * ```
179
165
  */
180
166
  constructor(settings: CacheSettings);
167
+ /**
168
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
169
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
170
+ */
181
171
  addListener<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
172
+ /**
173
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
174
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
175
+ */
182
176
  addListenerMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<void>;
177
+ /**
178
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
179
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
180
+ */
183
181
  removeListener<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
182
+ /**
183
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
184
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
185
+ */
184
186
  removeListenerMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<void>;
187
+ /**
188
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
189
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
190
+ */
185
191
  listenOnce<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<void>;
192
+ /**
193
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
194
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
195
+ */
186
196
  asPromise<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass): LazyPromise<EventInstance<TEventClass>>;
197
+ /**
198
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
199
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
200
+ */
187
201
  subscribe<TEventClass extends EventClass<CacheEvents<TType>>>(event: TEventClass, listener: Invokable<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
202
+ /**
203
+ * You can listen to the following <i>{@link CacheEvents}</i> of the <i>{@link ICache}</i> instance.
204
+ * To understand how this method works, refer to <i>{@link IEventListenable}</i>.
205
+ */
188
206
  subscribeMany<TEventClassArr extends EventClass<CacheEvents<TType>>[]>(events: [...TEventClassArr], listener: Invokable<EventInstance<Items<TEventClassArr>>>): LazyPromise<Unsubscribe>;
189
207
  private createLazyPromise;
190
208
  exists(key: OneOrMore<string>): LazyPromise<boolean>;
@@ -192,7 +210,151 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
192
210
  get(key: OneOrMore<string>): LazyPromise<TType | null>;
193
211
  getOrFail(key: OneOrMore<string>): LazyPromise<TType>;
194
212
  getAndRemove(key: OneOrMore<string>): LazyPromise<TType | null>;
213
+ /**
214
+ * @example
215
+ * ```ts
216
+ * import { Cache } from "@daiso-tech/core/cache";
217
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
218
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
219
+ *
220
+ * const cache = new Cache({
221
+ * adapter: new MemoryCacheAdapter(),
222
+ * keyPrefixer: new KeyPrefixer("cache")
223
+ * });
224
+ *
225
+ * const value = await cache.getOr("a", 1);
226
+ *
227
+ * // Will be 1
228
+ * console.log(value);
229
+ * ```
230
+ *
231
+ * You can also pass in a function
232
+ * @example
233
+ * ```ts
234
+ * import { Cache } from "@daiso-tech/core/cache";
235
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
236
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
237
+ *
238
+ * const cache = new Cache({
239
+ * adapter: new MemoryCacheAdapter(),
240
+ * keyPrefixer: new KeyPrefixer("cache")
241
+ * });
242
+ *
243
+ * const value = await cache.getOr("a", () => 1);
244
+ *
245
+ * // Will be 1
246
+ * console.log(value);
247
+ * ```
248
+ *
249
+ * You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
250
+ * @example
251
+ * ```ts
252
+ * import { Cache } from "@daiso-tech/core/cache";
253
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
254
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
255
+ *
256
+ * const cache = new Cache({
257
+ * adapter: new MemoryCacheAdapter(),
258
+ * keyPrefixer: new KeyPrefixer("cache")
259
+ * });
260
+ *
261
+ * const value = await cache.getOr("a", async () => 1);
262
+ *
263
+ * // Will be 1
264
+ * console.log(value);
265
+ * ```
266
+ *
267
+ * You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
268
+ * @example
269
+ * ```ts
270
+ * import { Cache } from "@daiso-tech/core/cache";
271
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
272
+ * import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
273
+ *
274
+ * const cache = new Cache({
275
+ * adapter: new MemoryCacheAdapter(),
276
+ * keyPrefixer: new KeyPrefixer("cache")
277
+ * });
278
+ *
279
+ * const value = await cache.getOr("a", new LazyPromise(async () => 1));
280
+ *
281
+ * // Will be 1
282
+ * console.log(value);
283
+ * ```
284
+ */
195
285
  getOr(key: OneOrMore<string>, defaultValue: AsyncLazyable<NoneFunction<TType>>): LazyPromise<TType>;
286
+ /**
287
+ * @example
288
+ * ```ts
289
+ * import { Cache } from "@daiso-tech/core/cache";
290
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
291
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
292
+ *
293
+ * const cache = new Cache({
294
+ * adapter: new MemoryCacheAdapter(),
295
+ * keyPrefixer: new KeyPrefixer("cache")
296
+ * });
297
+ *
298
+ * const value = await cache.getOrAdd("a", 1);
299
+ *
300
+ * // Will be 1
301
+ * console.log(value);
302
+ * ```
303
+ *
304
+ * You can also pass in a function
305
+ * @example
306
+ * ```ts
307
+ * import { Cache } from "@daiso-tech/core/cache";
308
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
309
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
310
+ *
311
+ * const cache = new Cache({
312
+ * adapter: new MemoryCacheAdapter(),
313
+ * keyPrefixer: new KeyPrefixer("cache")
314
+ * });
315
+ *
316
+ * const value = await cache.getOrAdd("a", () => 1);
317
+ *
318
+ * // Will be 1
319
+ * console.log(value);
320
+ * ```
321
+ *
322
+ * You can also pass in a async function. This is useful because it allows for retrieval of external data if the key doesnt't.
323
+ * @example
324
+ * ```ts
325
+ * import { Cache } from "@daiso-tech/core/cache";
326
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
327
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
328
+ *
329
+ * const cache = new Cache({
330
+ * adapter: new MemoryCacheAdapter(),
331
+ * keyPrefixer: new KeyPrefixer("cache")
332
+ * });
333
+ *
334
+ * const value = await cache.getOrAdd("a", async () => 1);
335
+ *
336
+ * // Will be 1
337
+ * console.log(value);
338
+ * ```
339
+ *
340
+ * You can also pass in a <i>{@link LazyPromise}</i>. This is useful because all other components in this library returns <i>{@link LazyPromise}</i>.
341
+ * @example
342
+ * ```ts
343
+ * import { Cache } from "@daiso-tech/core/cache";
344
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
345
+ * import { KeyPrefixer, LazyPromise } from "@daiso-tech/core/utilities";
346
+ *
347
+ * const cache = new Cache({
348
+ * adapter: new MemoryCacheAdapter(),
349
+ * keyPrefixer: new KeyPrefixer("cache")
350
+ * });
351
+ *
352
+ * const value = await cache.getOrAdd("a", new LazyPromise(async () => 1));
353
+ *
354
+ * // Will be 1
355
+ * console.log(value);
356
+ * ```
357
+ */
196
358
  getOrAdd(key: OneOrMore<string>, valueToAdd: AsyncLazyable<NoneFunction<TType>>, ttl?: TimeSpan | null): LazyPromise<TType>;
197
359
  add(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
198
360
  put(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
@@ -200,8 +362,51 @@ export declare class Cache<TType = unknown> implements IGroupableCache<TType> {
200
362
  increment(key: OneOrMore<string>, value?: Extract<TType, number>): LazyPromise<boolean>;
201
363
  decrement(key: OneOrMore<string>, value?: Extract<TType, number>): LazyPromise<boolean>;
202
364
  remove(key: OneOrMore<string>): LazyPromise<boolean>;
203
- removeMany(keys: OneOrMore<string>[]): LazyPromise<boolean>;
365
+ removeMany(keys: Iterable<OneOrMore<string>>): LazyPromise<boolean>;
204
366
  clear(): LazyPromise<void>;
367
+ /**
368
+ * @example
369
+ * ```ts
370
+ * import { Cache } from "@daiso-tech/core/cache";
371
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
372
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
373
+ *
374
+ * const cache = new Cache({
375
+ * adapter: new MemoryCacheAdapter(),
376
+ * keyPrefixer: new KeyPrefixer("cache")
377
+ * });
378
+ *
379
+ * // Will log null because the cache is not in a group
380
+ * console.log(cache.getGroup());
381
+ *
382
+ * const groupedCache = cache.withGroup("group-a");
383
+ *
384
+ * // Will log "group-a" because the groupedCache is in a group
385
+ * console.log(groupedCache.getGroup());
386
+ * ```
387
+ */
205
388
  getGroup(): string | null;
389
+ /**
390
+ * @example
391
+ * ```ts
392
+ * import { Cache } from "@daiso-tech/core/cache";
393
+ * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/adapters";
394
+ * import { KeyPrefixer } from "@daiso-tech/core/utilities";
395
+ *
396
+ * const cache = new Cache({
397
+ * adapter: new MemoryCacheAdapter(),
398
+ * keyPrefixer: new KeyPrefixer("cache")
399
+ * });
400
+ *
401
+ * const groupedCache = cache.withGroup("group-a");
402
+ * await groupedCache.add("a", 1);
403
+ *
404
+ * // Will log "a".
405
+ * console.log(await groupedCache.get("a"));
406
+ *
407
+ * // Will log null because the caches are in different groups.
408
+ * console.log(await cache.get("a"));
409
+ * ```
410
+ */
206
411
  withGroup(group: OneOrMore<string>): ICache<TType>;
207
412
  }