@sebspark/promise-cache 3.10.1 → 4.0.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.
package/dist/index.d.mts CHANGED
@@ -105,9 +105,7 @@ declare class PromiseCache<U> {
105
105
  wrap(key: string, delegate: () => Promise<U>, ttlInSeconds?: number, ttlKeyInSeconds?: string): Promise<U>;
106
106
  }
107
107
 
108
- type Client = ReturnType<typeof createClient>;
109
- type Multi = ReturnType<Client['multi']>;
110
- type MultiExecReturnTypes = Awaited<ReturnType<Multi['exec']>>[number] | boolean;
108
+ type MultiExecReturnTypes = string[] | string | number | boolean | null | undefined;
111
109
  /**
112
110
  * Defines the expiration strategy for cached values.
113
111
  *
@@ -186,7 +184,7 @@ interface IPersistor {
186
184
  * @param seconds - TTL in seconds.
187
185
  * @returns Resolves to `true` if the expiration was successfully set, `false` if the key does not exist.
188
186
  */
189
- expire: (key: string, seconds: number) => Promise<boolean>;
187
+ expire: (key: string, seconds: number) => Promise<number>;
190
188
  /**
191
189
  * Gets the remaining TTL (time-to-live) of a key.
192
190
  * @param key - The storage key.
@@ -223,7 +221,7 @@ interface IPersistor {
223
221
  * @param value - The string value to store.
224
222
  * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
225
223
  */
226
- setNX: (key: string, value: string) => Promise<boolean>;
224
+ setNX: (key: string, value: string) => Promise<number>;
227
225
  /**
228
226
  * Creates a multi-command batch operation.
229
227
  * This allows multiple commands to be executed in a batch, improving performance.
@@ -276,7 +274,7 @@ interface IPersistor {
276
274
  * @param field - The field name.
277
275
  * @returns Resolves to the value, or `undefined` if the field does not exist.
278
276
  */
279
- hGet: (key: string, field: string) => Promise<string | undefined>;
277
+ hGet: (key: string, field: string) => Promise<string | null>;
280
278
  /**
281
279
  * Pushes values to the left (head) of a list.
282
280
  * @param key - The list key.
@@ -560,7 +558,7 @@ interface IPersistorMulti {
560
558
  * @returns A promise resolving to an array of results for each command.
561
559
  * The result type can be `string | number | boolean | null`, depending on the command.
562
560
  */
563
- exec: () => Promise<MultiExecReturnTypes[]>;
561
+ exec: () => Promise<MultiExecReturnTypes[] | unknown>;
564
562
  }
565
563
 
566
564
  /**
@@ -641,7 +639,7 @@ declare class InMemoryPersistor implements IPersistor {
641
639
  * @param value - The string value to store.
642
640
  * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
643
641
  */
644
- setNX(key: string, value: string): Promise<boolean>;
642
+ setNX(key: string, value: string): Promise<number>;
645
643
  /**
646
644
  * Retrieves the value associated with a key.
647
645
  *
@@ -665,7 +663,7 @@ declare class InMemoryPersistor implements IPersistor {
665
663
  * @param {number} seconds - The TTL in seconds.
666
664
  * @returns {Promise<number>} Resolves to `1` if the TTL was set, or `0` if the key does not exist.
667
665
  */
668
- expire(key: string, seconds: number): Promise<boolean>;
666
+ expire(key: string, seconds: number): Promise<number>;
669
667
  /**
670
668
  * Retrieves the remaining time-to-live (TTL) of a key in seconds.
671
669
  *
@@ -732,9 +730,9 @@ declare class InMemoryPersistor implements IPersistor {
732
730
  *
733
731
  * @param key - The hash key.
734
732
  * @param field - The field name to retrieve.
735
- * @returns Resolves to the field value, or `undefined` if the field does not exist.
733
+ * @returns Resolves to the field value, or `null` if the field does not exist.
736
734
  */
737
- hGet(key: string, field: string): Promise<string | undefined>;
735
+ hGet(key: string, field: string): Promise<string | null>;
738
736
  /**
739
737
  * Pushes elements to the left (head) of a list.
740
738
  *
package/dist/index.d.ts CHANGED
@@ -105,9 +105,7 @@ declare class PromiseCache<U> {
105
105
  wrap(key: string, delegate: () => Promise<U>, ttlInSeconds?: number, ttlKeyInSeconds?: string): Promise<U>;
106
106
  }
107
107
 
108
- type Client = ReturnType<typeof createClient>;
109
- type Multi = ReturnType<Client['multi']>;
110
- type MultiExecReturnTypes = Awaited<ReturnType<Multi['exec']>>[number] | boolean;
108
+ type MultiExecReturnTypes = string[] | string | number | boolean | null | undefined;
111
109
  /**
112
110
  * Defines the expiration strategy for cached values.
113
111
  *
@@ -186,7 +184,7 @@ interface IPersistor {
186
184
  * @param seconds - TTL in seconds.
187
185
  * @returns Resolves to `true` if the expiration was successfully set, `false` if the key does not exist.
188
186
  */
189
- expire: (key: string, seconds: number) => Promise<boolean>;
187
+ expire: (key: string, seconds: number) => Promise<number>;
190
188
  /**
191
189
  * Gets the remaining TTL (time-to-live) of a key.
192
190
  * @param key - The storage key.
@@ -223,7 +221,7 @@ interface IPersistor {
223
221
  * @param value - The string value to store.
224
222
  * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
225
223
  */
226
- setNX: (key: string, value: string) => Promise<boolean>;
224
+ setNX: (key: string, value: string) => Promise<number>;
227
225
  /**
228
226
  * Creates a multi-command batch operation.
229
227
  * This allows multiple commands to be executed in a batch, improving performance.
@@ -276,7 +274,7 @@ interface IPersistor {
276
274
  * @param field - The field name.
277
275
  * @returns Resolves to the value, or `undefined` if the field does not exist.
278
276
  */
279
- hGet: (key: string, field: string) => Promise<string | undefined>;
277
+ hGet: (key: string, field: string) => Promise<string | null>;
280
278
  /**
281
279
  * Pushes values to the left (head) of a list.
282
280
  * @param key - The list key.
@@ -560,7 +558,7 @@ interface IPersistorMulti {
560
558
  * @returns A promise resolving to an array of results for each command.
561
559
  * The result type can be `string | number | boolean | null`, depending on the command.
562
560
  */
563
- exec: () => Promise<MultiExecReturnTypes[]>;
561
+ exec: () => Promise<MultiExecReturnTypes[] | unknown>;
564
562
  }
565
563
 
566
564
  /**
@@ -641,7 +639,7 @@ declare class InMemoryPersistor implements IPersistor {
641
639
  * @param value - The string value to store.
642
640
  * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
643
641
  */
644
- setNX(key: string, value: string): Promise<boolean>;
642
+ setNX(key: string, value: string): Promise<number>;
645
643
  /**
646
644
  * Retrieves the value associated with a key.
647
645
  *
@@ -665,7 +663,7 @@ declare class InMemoryPersistor implements IPersistor {
665
663
  * @param {number} seconds - The TTL in seconds.
666
664
  * @returns {Promise<number>} Resolves to `1` if the TTL was set, or `0` if the key does not exist.
667
665
  */
668
- expire(key: string, seconds: number): Promise<boolean>;
666
+ expire(key: string, seconds: number): Promise<number>;
669
667
  /**
670
668
  * Retrieves the remaining time-to-live (TTL) of a key in seconds.
671
669
  *
@@ -732,9 +730,9 @@ declare class InMemoryPersistor implements IPersistor {
732
730
  *
733
731
  * @param key - The hash key.
734
732
  * @param field - The field name to retrieve.
735
- * @returns Resolves to the field value, or `undefined` if the field does not exist.
733
+ * @returns Resolves to the field value, or `null` if the field does not exist.
736
734
  */
737
- hGet(key: string, field: string): Promise<string | undefined>;
735
+ hGet(key: string, field: string): Promise<string | null>;
738
736
  /**
739
737
  * Pushes elements to the left (head) of a list.
740
738
  *
package/dist/index.js CHANGED
@@ -582,9 +582,9 @@ var InMemoryPersistor = class {
582
582
  * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
583
583
  */
584
584
  async setNX(key, value) {
585
- if (this.store.has(key)) return false;
585
+ if (this.store.has(key)) return 0;
586
586
  this.store.set(key, value);
587
- return true;
587
+ return 1;
588
588
  }
589
589
  /**
590
590
  * Retrieves the value associated with a key.
@@ -619,9 +619,9 @@ var InMemoryPersistor = class {
619
619
  * @returns {Promise<number>} Resolves to `1` if the TTL was set, or `0` if the key does not exist.
620
620
  */
621
621
  async expire(key, seconds2) {
622
- if (!this.store.has(key)) return false;
622
+ if (!this.store.has(key)) return 0;
623
623
  this.setExpiration(key, seconds2 * 1e3);
624
- return true;
624
+ return 1;
625
625
  }
626
626
  /**
627
627
  * Retrieves the remaining time-to-live (TTL) of a key in seconds.
@@ -729,11 +729,11 @@ var InMemoryPersistor = class {
729
729
  *
730
730
  * @param key - The hash key.
731
731
  * @param field - The field name to retrieve.
732
- * @returns Resolves to the field value, or `undefined` if the field does not exist.
732
+ * @returns Resolves to the field value, or `null` if the field does not exist.
733
733
  */
734
734
  async hGet(key, field) {
735
735
  const hash = JSON.parse(this.store.get(key) ?? "{}");
736
- return hash[field] ?? void 0;
736
+ return hash[field] ?? null;
737
737
  }
738
738
  /**
739
739
  * Pushes elements to the left (head) of a list.
package/dist/index.mjs CHANGED
@@ -563,9 +563,9 @@ var InMemoryPersistor = class {
563
563
  * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
564
564
  */
565
565
  async setNX(key, value) {
566
- if (this.store.has(key)) return false;
566
+ if (this.store.has(key)) return 0;
567
567
  this.store.set(key, value);
568
- return true;
568
+ return 1;
569
569
  }
570
570
  /**
571
571
  * Retrieves the value associated with a key.
@@ -600,9 +600,9 @@ var InMemoryPersistor = class {
600
600
  * @returns {Promise<number>} Resolves to `1` if the TTL was set, or `0` if the key does not exist.
601
601
  */
602
602
  async expire(key, seconds2) {
603
- if (!this.store.has(key)) return false;
603
+ if (!this.store.has(key)) return 0;
604
604
  this.setExpiration(key, seconds2 * 1e3);
605
- return true;
605
+ return 1;
606
606
  }
607
607
  /**
608
608
  * Retrieves the remaining time-to-live (TTL) of a key in seconds.
@@ -710,11 +710,11 @@ var InMemoryPersistor = class {
710
710
  *
711
711
  * @param key - The hash key.
712
712
  * @param field - The field name to retrieve.
713
- * @returns Resolves to the field value, or `undefined` if the field does not exist.
713
+ * @returns Resolves to the field value, or `null` if the field does not exist.
714
714
  */
715
715
  async hGet(key, field) {
716
716
  const hash = JSON.parse(this.store.get(key) ?? "{}");
717
- return hash[field] ?? void 0;
717
+ return hash[field] ?? null;
718
718
  }
719
719
  /**
720
720
  * Pushes elements to the left (head) of a list.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/promise-cache",
3
- "version": "3.10.1",
3
+ "version": "4.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "date-fn": "^0.0.2",
26
26
  "fix-esm": "1.0.1",
27
- "redis": "4.7.1",
27
+ "redis": "5.5.6",
28
28
  "superjson": "2.2.2"
29
29
  }
30
30
  }