@envelop/response-cache-redis 4.2.1 → 4.2.2-alpha-20250305181327-16712a1a224ce96ab5b61590493f0e4354bf7019

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultBuildRedisOperationResultCacheKey = exports.defaultBuildRedisEntityId = exports.createRedisCache = void 0;
4
+ const promise_helpers_1 = require("@whatwg-node/promise-helpers");
4
5
  const createRedisCache = (params) => {
5
6
  const store = params.redis;
6
7
  const buildRedisEntityId = params?.buildRedisEntityId ?? exports.defaultBuildRedisEntityId;
@@ -33,7 +34,7 @@ const createRedisCache = (params) => {
33
34
  return keysToInvalidate;
34
35
  }
35
36
  return {
36
- async set(responseId, result, collectedEntities, ttl) {
37
+ set(responseId, result, collectedEntities, ttl) {
37
38
  const pipeline = store.pipeline();
38
39
  if (ttl === Infinity) {
39
40
  pipeline.set(responseId, JSON.stringify(result));
@@ -56,11 +57,10 @@ const createRedisCache = (params) => {
56
57
  pipeline.sadd(responseKey, entityId);
57
58
  }
58
59
  }
59
- await pipeline.exec();
60
+ return pipeline.exec().then(() => undefined);
60
61
  },
61
- async get(responseId) {
62
- const result = await store.get(responseId);
63
- return result && JSON.parse(result);
62
+ get(responseId) {
63
+ return (0, promise_helpers_1.handleMaybePromise)(() => store.get(responseId), (result) => (result ? JSON.parse(result) : undefined));
64
64
  },
65
65
  async invalidate(entitiesToRemove) {
66
66
  const invalidationKeys = [];
@@ -1,3 +1,4 @@
1
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
1
2
  export const createRedisCache = (params) => {
2
3
  const store = params.redis;
3
4
  const buildRedisEntityId = params?.buildRedisEntityId ?? defaultBuildRedisEntityId;
@@ -30,7 +31,7 @@ export const createRedisCache = (params) => {
30
31
  return keysToInvalidate;
31
32
  }
32
33
  return {
33
- async set(responseId, result, collectedEntities, ttl) {
34
+ set(responseId, result, collectedEntities, ttl) {
34
35
  const pipeline = store.pipeline();
35
36
  if (ttl === Infinity) {
36
37
  pipeline.set(responseId, JSON.stringify(result));
@@ -53,11 +54,10 @@ export const createRedisCache = (params) => {
53
54
  pipeline.sadd(responseKey, entityId);
54
55
  }
55
56
  }
56
- await pipeline.exec();
57
+ return pipeline.exec().then(() => undefined);
57
58
  },
58
- async get(responseId) {
59
- const result = await store.get(responseId);
60
- return result && JSON.parse(result);
59
+ get(responseId) {
60
+ return handleMaybePromise(() => store.get(responseId), (result) => (result ? JSON.parse(result) : undefined));
61
61
  },
62
62
  async invalidate(entitiesToRemove) {
63
63
  const invalidationKeys = [];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@envelop/response-cache-redis",
3
- "version": "4.2.1",
3
+ "version": "4.2.2-alpha-20250305181327-16712a1a224ce96ab5b61590493f0e4354bf7019",
4
4
  "sideEffects": false,
5
- "peerDependencies": {},
6
5
  "dependencies": {
6
+ "@whatwg-node/promise-helpers": "^1.2.4",
7
7
  "ioredis": "^5.4.2",
8
8
  "tslib": "^2.5.0",
9
- "@envelop/response-cache": "^7.1.1"
9
+ "@envelop/response-cache": "^7.1.2-alpha-20250305181327-16712a1a224ce96ab5b61590493f0e4354bf7019"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",