@windrun-huaiin/backend-core 13.0.0 → 14.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.
Files changed (104) hide show
  1. package/dist/_virtual/index.js +7 -3
  2. package/dist/_virtual/index.mjs +5 -3
  3. package/dist/_virtual/index2.js +2 -6
  4. package/dist/_virtual/index2.mjs +2 -6
  5. package/dist/index.js +2 -0
  6. package/dist/index.mjs +1 -1
  7. package/dist/lib/index.js +2 -0
  8. package/dist/lib/index.mjs +1 -1
  9. package/dist/lib/upstash/qstash.d.ts.map +1 -1
  10. package/dist/lib/upstash/qstash.js +66 -62
  11. package/dist/lib/upstash/qstash.mjs +67 -63
  12. package/dist/lib/upstash/redis-counter.d.ts.map +1 -1
  13. package/dist/lib/upstash/redis-counter.js +9 -24
  14. package/dist/lib/upstash/redis-counter.mjs +10 -25
  15. package/dist/lib/upstash/redis-favorite.d.ts.map +1 -1
  16. package/dist/lib/upstash/redis-favorite.js +22 -36
  17. package/dist/lib/upstash/redis-favorite.mjs +23 -37
  18. package/dist/lib/upstash/redis-like.d.ts.map +1 -1
  19. package/dist/lib/upstash/redis-like.js +22 -36
  20. package/dist/lib/upstash/redis-like.mjs +23 -37
  21. package/dist/lib/upstash/redis-lock.d.ts.map +1 -1
  22. package/dist/lib/upstash/redis-lock.js +22 -38
  23. package/dist/lib/upstash/redis-lock.mjs +23 -39
  24. package/dist/lib/upstash/redis-structures.d.ts.map +1 -1
  25. package/dist/lib/upstash/redis-structures.js +77 -113
  26. package/dist/lib/upstash/redis-structures.mjs +78 -114
  27. package/dist/lib/upstash-config.d.ts +9 -1
  28. package/dist/lib/upstash-config.d.ts.map +1 -1
  29. package/dist/lib/upstash-config.js +221 -27
  30. package/dist/lib/upstash-config.mjs +220 -28
  31. package/dist/node_modules/.pnpm/{@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.js → @upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.js} +897 -468
  32. package/dist/node_modules/.pnpm/{@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.mjs → @upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.mjs} +895 -468
  33. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.js → @upstash_redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.js} +657 -40
  34. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.mjs → @upstash_redis@1.37.0/node_modules/@upstash/redis/chunk-IH7W44G6.mjs} +657 -41
  35. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1 → @upstash_redis@1.37.0}/node_modules/@upstash/redis/nodejs.js +6 -5
  36. package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1 → @upstash_redis@1.37.0}/node_modules/@upstash/redis/nodejs.mjs +2 -2
  37. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +1 -1
  38. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.mjs +1 -1
  39. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js +6 -6
  40. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js +1 -1
  41. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js +2 -2
  42. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js +3 -1
  43. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js +3 -1
  44. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js +1 -1
  45. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js +3 -1
  46. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js +7 -5
  47. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js +3 -1
  48. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js +3 -1
  49. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js +3 -1
  50. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js +3 -1
  51. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js +3 -1
  52. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js +4 -2
  53. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js +3 -1
  54. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js +3 -1
  55. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js +1 -1
  56. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js +3 -1
  57. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js +3 -1
  58. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js +6 -4
  59. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js +6 -4
  60. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js +7 -5
  61. package/dist/prisma/prisma.d.ts +1 -1
  62. package/dist/prisma/prisma.d.ts.map +1 -1
  63. package/package.json +5 -5
  64. package/src/lib/upstash/qstash.ts +64 -62
  65. package/src/lib/upstash/redis-counter.ts +10 -26
  66. package/src/lib/upstash/redis-favorite.ts +23 -42
  67. package/src/lib/upstash/redis-like.ts +23 -42
  68. package/src/lib/upstash/redis-lock.ts +23 -49
  69. package/src/lib/upstash/redis-structures.ts +82 -131
  70. package/src/lib/upstash-config.ts +231 -24
  71. package/dist/_virtual/index3.js +0 -5
  72. package/dist/_virtual/index3.mjs +0 -3
  73. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.js +0 -191
  74. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.mjs +0 -189
  75. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +0 -54
  76. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +0 -51
  77. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +0 -44
  78. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +0 -35
  79. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +0 -31
  80. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +0 -18
  81. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +0 -587
  82. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +0 -527
  83. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +0 -447
  84. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +0 -399
  85. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +0 -245
  86. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +0 -232
  87. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +0 -68
  88. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +0 -62
  89. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +0 -39
  90. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +0 -37
  91. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +0 -80
  92. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +0 -75
  93. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +0 -101
  94. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +0 -86
  95. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +0 -102
  96. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +0 -76
  97. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +0 -56
  98. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +0 -52
  99. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +0 -1205
  100. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +0 -1157
  101. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +0 -407
  102. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +0 -374
  103. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +0 -9
  104. package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +0 -7
@@ -7,191 +7,155 @@ var upstashConfig = require('../upstash-config.js');
7
7
  * Set a plain string value with optional TTL (seconds).
8
8
  */
9
9
  const setString = (key, value, ttlSec) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
10
- const redis = upstashConfig.getRedis();
11
- if (!redis) {
12
- return false;
13
- }
14
- if (ttlSec && ttlSec > 0) {
15
- yield redis.set(key, value, { ex: ttlSec });
10
+ return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
11
+ if (ttlSec && ttlSec > 0) {
12
+ yield redis.set(key, value, { ex: ttlSec });
13
+ return true;
14
+ }
15
+ yield redis.set(key, value);
16
16
  return true;
17
- }
18
- yield redis.set(key, value);
19
- return true;
17
+ })).then((result) => result !== null && result !== void 0 ? result : false);
20
18
  });
21
19
  /**
22
20
  * Get a plain string value. Returns null if Redis is unavailable or key missing.
23
21
  */
24
22
  const getString = (key) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
25
- const redis = upstashConfig.getRedis();
26
- if (!redis) {
27
- return null;
28
- }
29
- return redis.get(key);
23
+ return upstashConfig.withRedis((redis) => redis.get(key));
30
24
  });
31
25
  /**
32
26
  * Store an object as JSON string with optional TTL (seconds).
33
27
  */
34
28
  const setJson = (key, value, ttlSec) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
35
- const redis = upstashConfig.getRedis();
36
- if (!redis) {
37
- return false;
38
- }
39
- const payload = JSON.stringify(value);
40
- if (ttlSec && ttlSec > 0) {
41
- yield redis.set(key, payload, { ex: ttlSec });
29
+ return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
30
+ const payload = JSON.stringify(value);
31
+ if (ttlSec && ttlSec > 0) {
32
+ yield redis.set(key, payload, { ex: ttlSec });
33
+ return true;
34
+ }
35
+ yield redis.set(key, payload);
42
36
  return true;
43
- }
44
- yield redis.set(key, payload);
45
- return true;
37
+ })).then((result) => result !== null && result !== void 0 ? result : false);
46
38
  });
47
39
  /**
48
40
  * Get an object stored as JSON string. Returns null if missing or invalid JSON.
49
41
  */
50
42
  const getJson = (key) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
51
- const redis = upstashConfig.getRedis();
52
- if (!redis) {
53
- return null;
54
- }
55
- const payload = yield redis.get(key);
56
- if (!payload) {
57
- return null;
58
- }
59
- try {
60
- return JSON.parse(payload);
61
- }
62
- catch (_a) {
63
- return null;
64
- }
43
+ return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
44
+ const payload = yield redis.get(key);
45
+ if (!payload) {
46
+ return null;
47
+ }
48
+ try {
49
+ return JSON.parse(payload);
50
+ }
51
+ catch (_a) {
52
+ return null;
53
+ }
54
+ }));
65
55
  });
66
56
  /**
67
57
  * Delete a key. Returns false if Redis is unavailable.
68
58
  */
69
59
  const deleteKey = (key) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
70
- const redis = upstashConfig.getRedis();
71
- if (!redis) {
72
- return false;
73
- }
74
- const deleted = yield redis.del(key);
75
- return deleted > 0;
60
+ const result = yield upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
61
+ const deleted = yield redis.del(key);
62
+ return deleted > 0;
63
+ }));
64
+ return result !== null && result !== void 0 ? result : false;
76
65
  });
77
66
  /**
78
67
  * Set a hash field value.
79
68
  */
80
69
  const setHashField = (key, field, value) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
81
- const redis = upstashConfig.getRedis();
82
- if (!redis) {
83
- return false;
84
- }
85
- const result = yield redis.hset(key, { [field]: value });
86
- return result > 0;
70
+ const result = yield upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
71
+ const changed = yield redis.hset(key, { [field]: value });
72
+ return changed > 0;
73
+ }));
74
+ return result !== null && result !== void 0 ? result : false;
87
75
  });
88
76
  /**
89
77
  * Get a hash field value.
90
78
  */
91
79
  const getHashField = (key, field) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
92
- const redis = upstashConfig.getRedis();
93
- if (!redis) {
94
- return null;
95
- }
96
- return redis.hget(key, field);
80
+ return upstashConfig.withRedis((redis) => redis.hget(key, field));
97
81
  });
98
82
  /**
99
83
  * Store a hash field as JSON string.
100
84
  */
101
85
  const setHashJson = (key, field, value) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
102
- const redis = upstashConfig.getRedis();
103
- if (!redis) {
104
- return false;
105
- }
106
- const payload = JSON.stringify(value);
107
- const result = yield redis.hset(key, { [field]: payload });
108
- return result > 0;
86
+ const result = yield upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
87
+ const payload = JSON.stringify(value);
88
+ const changed = yield redis.hset(key, { [field]: payload });
89
+ return changed > 0;
90
+ }));
91
+ return result !== null && result !== void 0 ? result : false;
109
92
  });
110
93
  /**
111
94
  * Get a hash field stored as JSON string.
112
95
  */
113
96
  const getHashJson = (key, field) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
114
- const redis = upstashConfig.getRedis();
115
- if (!redis) {
116
- return null;
117
- }
118
- const payload = yield redis.hget(key, field);
119
- if (!payload) {
120
- return null;
121
- }
122
- try {
123
- return JSON.parse(payload);
124
- }
125
- catch (_a) {
126
- return null;
127
- }
97
+ return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
98
+ const payload = yield redis.hget(key, field);
99
+ if (!payload) {
100
+ return null;
101
+ }
102
+ try {
103
+ return JSON.parse(payload);
104
+ }
105
+ catch (_a) {
106
+ return null;
107
+ }
108
+ }));
128
109
  });
129
110
  /**
130
111
  * Get all hash fields.
131
112
  */
132
113
  const getHashAll = (key) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
133
- const redis = upstashConfig.getRedis();
134
- if (!redis) {
135
- return null;
136
- }
137
- const result = yield redis.hgetall(key);
138
- return result !== null && result !== void 0 ? result : {};
114
+ return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
115
+ const result = yield redis.hgetall(key);
116
+ return result !== null && result !== void 0 ? result : {};
117
+ }));
139
118
  });
140
119
  /**
141
120
  * Remove a hash field.
142
121
  */
143
122
  const deleteHashField = (key, field) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
144
- const redis = upstashConfig.getRedis();
145
- if (!redis) {
146
- return false;
147
- }
148
- const removed = yield redis.hdel(key, field);
149
- return removed > 0;
123
+ const result = yield upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
124
+ const removed = yield redis.hdel(key, field);
125
+ return removed > 0;
126
+ }));
127
+ return result !== null && result !== void 0 ? result : false;
150
128
  });
151
129
  /**
152
130
  * Push values to a list. Returns list length or null if Redis is unavailable.
153
131
  */
154
132
  const pushList = (key_1, values_1, ...args_1) => tslib_es6.__awaiter(void 0, [key_1, values_1, ...args_1], void 0, function* (key, values, direction = 'right') {
155
- const redis = upstashConfig.getRedis();
156
- if (!redis) {
157
- return null;
158
- }
159
- if (values.length === 0) {
160
- return redis.llen(key);
161
- }
162
- return direction === 'left'
163
- ? redis.lpush(key, ...values)
164
- : redis.rpush(key, ...values);
133
+ return upstashConfig.withRedis((redis) => {
134
+ if (values.length === 0) {
135
+ return redis.llen(key);
136
+ }
137
+ return direction === 'left'
138
+ ? redis.lpush(key, ...values)
139
+ : redis.rpush(key, ...values);
140
+ });
165
141
  });
166
142
  /**
167
143
  * Pop a value from a list.
168
144
  */
169
145
  const popList = (key_1, ...args_1) => tslib_es6.__awaiter(void 0, [key_1, ...args_1], void 0, function* (key, direction = 'right') {
170
- const redis = upstashConfig.getRedis();
171
- if (!redis) {
172
- return null;
173
- }
174
- return direction === 'left' ? redis.lpop(key) : redis.rpop(key);
146
+ return upstashConfig.withRedis((redis) => direction === 'left' ? redis.lpop(key) : redis.rpop(key));
175
147
  });
176
148
  /**
177
149
  * Get a range from a list.
178
150
  */
179
151
  const rangeList = (key_1, ...args_1) => tslib_es6.__awaiter(void 0, [key_1, ...args_1], void 0, function* (key, start = 0, stop = -1) {
180
- const redis = upstashConfig.getRedis();
181
- if (!redis) {
182
- return null;
183
- }
184
- return redis.lrange(key, start, stop);
152
+ return upstashConfig.withRedis((redis) => redis.lrange(key, start, stop));
185
153
  });
186
154
  /**
187
155
  * Get list length.
188
156
  */
189
157
  const listLength = (key) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
190
- const redis = upstashConfig.getRedis();
191
- if (!redis) {
192
- return null;
193
- }
194
- return redis.llen(key);
158
+ return upstashConfig.withRedis((redis) => redis.llen(key));
195
159
  });
196
160
 
197
161
  exports.deleteHashField = deleteHashField;
@@ -1,195 +1,159 @@
1
1
  import { __awaiter } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
2
- import { getRedis } from '../upstash-config.mjs';
2
+ import { withRedis } from '../upstash-config.mjs';
3
3
 
4
4
  /**
5
5
  * Set a plain string value with optional TTL (seconds).
6
6
  */
7
7
  const setString = (key, value, ttlSec) => __awaiter(void 0, void 0, void 0, function* () {
8
- const redis = getRedis();
9
- if (!redis) {
10
- return false;
11
- }
12
- if (ttlSec && ttlSec > 0) {
13
- yield redis.set(key, value, { ex: ttlSec });
8
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
9
+ if (ttlSec && ttlSec > 0) {
10
+ yield redis.set(key, value, { ex: ttlSec });
11
+ return true;
12
+ }
13
+ yield redis.set(key, value);
14
14
  return true;
15
- }
16
- yield redis.set(key, value);
17
- return true;
15
+ })).then((result) => result !== null && result !== void 0 ? result : false);
18
16
  });
19
17
  /**
20
18
  * Get a plain string value. Returns null if Redis is unavailable or key missing.
21
19
  */
22
20
  const getString = (key) => __awaiter(void 0, void 0, void 0, function* () {
23
- const redis = getRedis();
24
- if (!redis) {
25
- return null;
26
- }
27
- return redis.get(key);
21
+ return withRedis((redis) => redis.get(key));
28
22
  });
29
23
  /**
30
24
  * Store an object as JSON string with optional TTL (seconds).
31
25
  */
32
26
  const setJson = (key, value, ttlSec) => __awaiter(void 0, void 0, void 0, function* () {
33
- const redis = getRedis();
34
- if (!redis) {
35
- return false;
36
- }
37
- const payload = JSON.stringify(value);
38
- if (ttlSec && ttlSec > 0) {
39
- yield redis.set(key, payload, { ex: ttlSec });
27
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const payload = JSON.stringify(value);
29
+ if (ttlSec && ttlSec > 0) {
30
+ yield redis.set(key, payload, { ex: ttlSec });
31
+ return true;
32
+ }
33
+ yield redis.set(key, payload);
40
34
  return true;
41
- }
42
- yield redis.set(key, payload);
43
- return true;
35
+ })).then((result) => result !== null && result !== void 0 ? result : false);
44
36
  });
45
37
  /**
46
38
  * Get an object stored as JSON string. Returns null if missing or invalid JSON.
47
39
  */
48
40
  const getJson = (key) => __awaiter(void 0, void 0, void 0, function* () {
49
- const redis = getRedis();
50
- if (!redis) {
51
- return null;
52
- }
53
- const payload = yield redis.get(key);
54
- if (!payload) {
55
- return null;
56
- }
57
- try {
58
- return JSON.parse(payload);
59
- }
60
- catch (_a) {
61
- return null;
62
- }
41
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
42
+ const payload = yield redis.get(key);
43
+ if (!payload) {
44
+ return null;
45
+ }
46
+ try {
47
+ return JSON.parse(payload);
48
+ }
49
+ catch (_a) {
50
+ return null;
51
+ }
52
+ }));
63
53
  });
64
54
  /**
65
55
  * Delete a key. Returns false if Redis is unavailable.
66
56
  */
67
57
  const deleteKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
68
- const redis = getRedis();
69
- if (!redis) {
70
- return false;
71
- }
72
- const deleted = yield redis.del(key);
73
- return deleted > 0;
58
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
59
+ const deleted = yield redis.del(key);
60
+ return deleted > 0;
61
+ }));
62
+ return result !== null && result !== void 0 ? result : false;
74
63
  });
75
64
  /**
76
65
  * Set a hash field value.
77
66
  */
78
67
  const setHashField = (key, field, value) => __awaiter(void 0, void 0, void 0, function* () {
79
- const redis = getRedis();
80
- if (!redis) {
81
- return false;
82
- }
83
- const result = yield redis.hset(key, { [field]: value });
84
- return result > 0;
68
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
69
+ const changed = yield redis.hset(key, { [field]: value });
70
+ return changed > 0;
71
+ }));
72
+ return result !== null && result !== void 0 ? result : false;
85
73
  });
86
74
  /**
87
75
  * Get a hash field value.
88
76
  */
89
77
  const getHashField = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
90
- const redis = getRedis();
91
- if (!redis) {
92
- return null;
93
- }
94
- return redis.hget(key, field);
78
+ return withRedis((redis) => redis.hget(key, field));
95
79
  });
96
80
  /**
97
81
  * Store a hash field as JSON string.
98
82
  */
99
83
  const setHashJson = (key, field, value) => __awaiter(void 0, void 0, void 0, function* () {
100
- const redis = getRedis();
101
- if (!redis) {
102
- return false;
103
- }
104
- const payload = JSON.stringify(value);
105
- const result = yield redis.hset(key, { [field]: payload });
106
- return result > 0;
84
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
85
+ const payload = JSON.stringify(value);
86
+ const changed = yield redis.hset(key, { [field]: payload });
87
+ return changed > 0;
88
+ }));
89
+ return result !== null && result !== void 0 ? result : false;
107
90
  });
108
91
  /**
109
92
  * Get a hash field stored as JSON string.
110
93
  */
111
94
  const getHashJson = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
112
- const redis = getRedis();
113
- if (!redis) {
114
- return null;
115
- }
116
- const payload = yield redis.hget(key, field);
117
- if (!payload) {
118
- return null;
119
- }
120
- try {
121
- return JSON.parse(payload);
122
- }
123
- catch (_a) {
124
- return null;
125
- }
95
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
96
+ const payload = yield redis.hget(key, field);
97
+ if (!payload) {
98
+ return null;
99
+ }
100
+ try {
101
+ return JSON.parse(payload);
102
+ }
103
+ catch (_a) {
104
+ return null;
105
+ }
106
+ }));
126
107
  });
127
108
  /**
128
109
  * Get all hash fields.
129
110
  */
130
111
  const getHashAll = (key) => __awaiter(void 0, void 0, void 0, function* () {
131
- const redis = getRedis();
132
- if (!redis) {
133
- return null;
134
- }
135
- const result = yield redis.hgetall(key);
136
- return result !== null && result !== void 0 ? result : {};
112
+ return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
113
+ const result = yield redis.hgetall(key);
114
+ return result !== null && result !== void 0 ? result : {};
115
+ }));
137
116
  });
138
117
  /**
139
118
  * Remove a hash field.
140
119
  */
141
120
  const deleteHashField = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
142
- const redis = getRedis();
143
- if (!redis) {
144
- return false;
145
- }
146
- const removed = yield redis.hdel(key, field);
147
- return removed > 0;
121
+ const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
122
+ const removed = yield redis.hdel(key, field);
123
+ return removed > 0;
124
+ }));
125
+ return result !== null && result !== void 0 ? result : false;
148
126
  });
149
127
  /**
150
128
  * Push values to a list. Returns list length or null if Redis is unavailable.
151
129
  */
152
130
  const pushList = (key_1, values_1, ...args_1) => __awaiter(void 0, [key_1, values_1, ...args_1], void 0, function* (key, values, direction = 'right') {
153
- const redis = getRedis();
154
- if (!redis) {
155
- return null;
156
- }
157
- if (values.length === 0) {
158
- return redis.llen(key);
159
- }
160
- return direction === 'left'
161
- ? redis.lpush(key, ...values)
162
- : redis.rpush(key, ...values);
131
+ return withRedis((redis) => {
132
+ if (values.length === 0) {
133
+ return redis.llen(key);
134
+ }
135
+ return direction === 'left'
136
+ ? redis.lpush(key, ...values)
137
+ : redis.rpush(key, ...values);
138
+ });
163
139
  });
164
140
  /**
165
141
  * Pop a value from a list.
166
142
  */
167
143
  const popList = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, direction = 'right') {
168
- const redis = getRedis();
169
- if (!redis) {
170
- return null;
171
- }
172
- return direction === 'left' ? redis.lpop(key) : redis.rpop(key);
144
+ return withRedis((redis) => direction === 'left' ? redis.lpop(key) : redis.rpop(key));
173
145
  });
174
146
  /**
175
147
  * Get a range from a list.
176
148
  */
177
149
  const rangeList = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, start = 0, stop = -1) {
178
- const redis = getRedis();
179
- if (!redis) {
180
- return null;
181
- }
182
- return redis.lrange(key, start, stop);
150
+ return withRedis((redis) => redis.lrange(key, start, stop));
183
151
  });
184
152
  /**
185
153
  * Get list length.
186
154
  */
187
155
  const listLength = (key) => __awaiter(void 0, void 0, void 0, function* () {
188
- const redis = getRedis();
189
- if (!redis) {
190
- return null;
191
- }
192
- return redis.llen(key);
156
+ return withRedis((redis) => redis.llen(key));
193
157
  });
194
158
 
195
159
  export { deleteHashField, deleteKey, getHashAll, getHashField, getHashJson, getJson, getString, listLength, popList, pushList, rangeList, setHashField, setHashJson, setJson, setString };
@@ -1,11 +1,19 @@
1
1
  import { Redis } from '@upstash/redis';
2
2
  import { Client as QstashClient } from '@upstash/qstash';
3
3
  /**
4
- * Get the Upstash Redis client. Returns null when required env vars are missing.
4
+ * Get the Upstash Redis client. Returns null when required env vars are missing/invalid.
5
+ *
6
+ * Singleton semantics:
7
+ * - read-through cached instance only
5
8
  */
6
9
  export declare const getRedis: () => Redis | null;
7
10
  /**
8
11
  * Get the Upstash QStash client. Returns null when required env vars are missing.
12
+ *
13
+ * Singleton semantics:
14
+ * - read-through cached instance only
9
15
  */
10
16
  export declare const getQstash: () => QstashClient | null;
17
+ export declare const withRedis: <T>(fn: (redis: Redis) => Promise<T> | T) => Promise<T | null>;
18
+ export declare const withQstash: <T>(fn: (qstash: QstashClient) => Promise<T> | T) => Promise<T | null>;
11
19
  //# sourceMappingURL=upstash-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upstash-config.d.ts","sourceRoot":"","sources":["../../src/lib/upstash-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOzD;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAO,KAAK,GAAG,IAoBnC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,QAAO,YAAY,GAAG,IAiB3C,CAAC"}
1
+ {"version":3,"file":"upstash-config.d.ts","sourceRoot":"","sources":["../../src/lib/upstash-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAoIzD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,QAAO,KAAK,GAAG,IAEnC,CAAC;AAsDF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,QAAO,YAAY,GAAG,IAE3C,CAAC;AAyCF,eAAO,MAAM,SAAS,GAAU,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAMzF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,CAAC,EAChC,IAAI,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAC3C,OAAO,CAAC,CAAC,GAAG,IAAI,CAMlB,CAAC"}