@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.
- package/dist/_virtual/index.js +7 -3
- package/dist/_virtual/index.mjs +5 -3
- package/dist/_virtual/index2.js +2 -6
- package/dist/_virtual/index2.mjs +2 -6
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.mjs +1 -1
- package/dist/lib/upstash/qstash.d.ts.map +1 -1
- package/dist/lib/upstash/qstash.js +66 -62
- package/dist/lib/upstash/qstash.mjs +67 -63
- package/dist/lib/upstash/redis-counter.d.ts.map +1 -1
- package/dist/lib/upstash/redis-counter.js +9 -24
- package/dist/lib/upstash/redis-counter.mjs +10 -25
- package/dist/lib/upstash/redis-favorite.d.ts.map +1 -1
- package/dist/lib/upstash/redis-favorite.js +22 -36
- package/dist/lib/upstash/redis-favorite.mjs +23 -37
- package/dist/lib/upstash/redis-like.d.ts.map +1 -1
- package/dist/lib/upstash/redis-like.js +22 -36
- package/dist/lib/upstash/redis-like.mjs +23 -37
- package/dist/lib/upstash/redis-lock.d.ts.map +1 -1
- package/dist/lib/upstash/redis-lock.js +22 -38
- package/dist/lib/upstash/redis-lock.mjs +23 -39
- package/dist/lib/upstash/redis-structures.d.ts.map +1 -1
- package/dist/lib/upstash/redis-structures.js +77 -113
- package/dist/lib/upstash/redis-structures.mjs +78 -114
- package/dist/lib/upstash-config.d.ts +9 -1
- package/dist/lib/upstash-config.d.ts.map +1 -1
- package/dist/lib/upstash-config.js +221 -27
- package/dist/lib/upstash-config.mjs +220 -28
- 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
- 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
- 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
- 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
- package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1 → @upstash_redis@1.37.0}/node_modules/@upstash/redis/nodejs.js +6 -5
- package/dist/node_modules/.pnpm/{@upstash_redis@1.36.1 → @upstash_redis@1.37.0}/node_modules/@upstash/redis/nodejs.mjs +2 -2
- package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +1 -1
- package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.mjs +1 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js +6 -6
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js +1 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js +2 -2
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js +1 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js +7 -5
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js +4 -2
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js +1 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js +3 -1
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js +6 -4
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js +6 -4
- package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js +7 -5
- package/dist/prisma/prisma.d.ts +1 -1
- package/dist/prisma/prisma.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/lib/upstash/qstash.ts +64 -62
- package/src/lib/upstash/redis-counter.ts +10 -26
- package/src/lib/upstash/redis-favorite.ts +23 -42
- package/src/lib/upstash/redis-like.ts +23 -42
- package/src/lib/upstash/redis-lock.ts +23 -49
- package/src/lib/upstash/redis-structures.ts +82 -131
- package/src/lib/upstash-config.ts +231 -24
- package/dist/_virtual/index3.js +0 -5
- package/dist/_virtual/index3.mjs +0 -3
- package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.js +0 -191
- package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.mjs +0 -189
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +0 -54
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +0 -51
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +0 -44
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +0 -35
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +0 -31
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +0 -18
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +0 -587
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +0 -527
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +0 -447
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +0 -399
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +0 -245
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +0 -232
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +0 -68
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +0 -62
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +0 -39
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +0 -37
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +0 -80
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +0 -75
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +0 -101
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +0 -86
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +0 -102
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +0 -76
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +0 -56
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +0 -52
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +0 -1205
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +0 -1157
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +0 -407
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +0 -374
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +0 -9
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +0 -7
|
@@ -9,62 +9,48 @@ const favoriteUserKey = (userId) => `favorite:user:${userId}`;
|
|
|
9
9
|
* Favorite a target. Returns true if added, false if already favorited, null if Redis is unavailable.
|
|
10
10
|
*/
|
|
11
11
|
const addFavorite = (targetId, userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
12
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const added = yield redis.sadd(favoriteTargetKey(targetId), userId);
|
|
14
|
+
if (added === 1) {
|
|
15
|
+
yield redis.sadd(favoriteUserKey(userId), targetId);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}));
|
|
22
20
|
});
|
|
23
21
|
/**
|
|
24
22
|
* Remove a favorite. Returns true if removed, false if not found, null if Redis is unavailable.
|
|
25
23
|
*/
|
|
26
24
|
const removeFavorite = (targetId, userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
25
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const removed = yield redis.srem(favoriteTargetKey(targetId), userId);
|
|
27
|
+
if (removed === 1) {
|
|
28
|
+
yield redis.srem(favoriteUserKey(userId), targetId);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}));
|
|
37
33
|
});
|
|
38
34
|
/**
|
|
39
35
|
* Check whether a user has favorited a target. Returns null if Redis is unavailable.
|
|
40
36
|
*/
|
|
41
37
|
const isFavorited = (targetId, userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
const result = yield redis.sismember(favoriteTargetKey(targetId), userId);
|
|
47
|
-
return result === 1;
|
|
38
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const result = yield redis.sismember(favoriteTargetKey(targetId), userId);
|
|
40
|
+
return result === 1;
|
|
41
|
+
}));
|
|
48
42
|
});
|
|
49
43
|
/**
|
|
50
44
|
* Get favorite count for a target. Returns null if Redis is unavailable.
|
|
51
45
|
*/
|
|
52
46
|
const getFavoriteCount = (targetId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
|
|
54
|
-
if (!redis) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return redis.scard(favoriteTargetKey(targetId));
|
|
47
|
+
return upstashConfig.withRedis((redis) => redis.scard(favoriteTargetKey(targetId)));
|
|
58
48
|
});
|
|
59
49
|
/**
|
|
60
50
|
* Get target ids favorited by a user. Returns null if Redis is unavailable.
|
|
61
51
|
*/
|
|
62
52
|
const getUserFavorites = (userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
if (!redis) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return redis.smembers(favoriteUserKey(userId));
|
|
53
|
+
return upstashConfig.withRedis((redis) => redis.smembers(favoriteUserKey(userId)));
|
|
68
54
|
});
|
|
69
55
|
|
|
70
56
|
exports.addFavorite = addFavorite;
|
|
@@ -1,5 +1,5 @@
|
|
|
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 {
|
|
2
|
+
import { withRedis } from '../upstash-config.mjs';
|
|
3
3
|
|
|
4
4
|
const favoriteTargetKey = (targetId) => `favorite:target:${targetId}`;
|
|
5
5
|
const favoriteUserKey = (userId) => `favorite:user:${userId}`;
|
|
@@ -7,62 +7,48 @@ const favoriteUserKey = (userId) => `favorite:user:${userId}`;
|
|
|
7
7
|
* Favorite a target. Returns true if added, false if already favorited, null if Redis is unavailable.
|
|
8
8
|
*/
|
|
9
9
|
const addFavorite = (targetId, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
10
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const added = yield redis.sadd(favoriteTargetKey(targetId), userId);
|
|
12
|
+
if (added === 1) {
|
|
13
|
+
yield redis.sadd(favoriteUserKey(userId), targetId);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}));
|
|
20
18
|
});
|
|
21
19
|
/**
|
|
22
20
|
* Remove a favorite. Returns true if removed, false if not found, null if Redis is unavailable.
|
|
23
21
|
*/
|
|
24
22
|
const removeFavorite = (targetId, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
23
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const removed = yield redis.srem(favoriteTargetKey(targetId), userId);
|
|
25
|
+
if (removed === 1) {
|
|
26
|
+
yield redis.srem(favoriteUserKey(userId), targetId);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}));
|
|
35
31
|
});
|
|
36
32
|
/**
|
|
37
33
|
* Check whether a user has favorited a target. Returns null if Redis is unavailable.
|
|
38
34
|
*/
|
|
39
35
|
const isFavorited = (targetId, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
const result = yield redis.sismember(favoriteTargetKey(targetId), userId);
|
|
45
|
-
return result === 1;
|
|
36
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const result = yield redis.sismember(favoriteTargetKey(targetId), userId);
|
|
38
|
+
return result === 1;
|
|
39
|
+
}));
|
|
46
40
|
});
|
|
47
41
|
/**
|
|
48
42
|
* Get favorite count for a target. Returns null if Redis is unavailable.
|
|
49
43
|
*/
|
|
50
44
|
const getFavoriteCount = (targetId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
|
|
52
|
-
if (!redis) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return redis.scard(favoriteTargetKey(targetId));
|
|
45
|
+
return withRedis((redis) => redis.scard(favoriteTargetKey(targetId)));
|
|
56
46
|
});
|
|
57
47
|
/**
|
|
58
48
|
* Get target ids favorited by a user. Returns null if Redis is unavailable.
|
|
59
49
|
*/
|
|
60
50
|
const getUserFavorites = (userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
-
|
|
62
|
-
if (!redis) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return redis.smembers(favoriteUserKey(userId));
|
|
51
|
+
return withRedis((redis) => redis.smembers(favoriteUserKey(userId)));
|
|
66
52
|
});
|
|
67
53
|
|
|
68
54
|
export { addFavorite, getFavoriteCount, getUserFavorites, isFavorited, removeFavorite };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-like.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-like.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"redis-like.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-like.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CASzF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAS3F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAK5F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAEhF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAEjF,CAAC"}
|
|
@@ -9,62 +9,48 @@ const likeUserKey = (userId) => `like:user:${userId}`;
|
|
|
9
9
|
* Like a target. Returns true if the like was added, false if it already existed, null if Redis is unavailable.
|
|
10
10
|
*/
|
|
11
11
|
const likeTarget = (targetId, userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
12
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const added = yield redis.sadd(likeTargetKey(targetId), userId);
|
|
14
|
+
if (added === 1) {
|
|
15
|
+
yield redis.sadd(likeUserKey(userId), targetId);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}));
|
|
22
20
|
});
|
|
23
21
|
/**
|
|
24
22
|
* Unlike a target. Returns true if removed, false if it didn't exist, null if Redis is unavailable.
|
|
25
23
|
*/
|
|
26
24
|
const unlikeTarget = (targetId, userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
25
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const removed = yield redis.srem(likeTargetKey(targetId), userId);
|
|
27
|
+
if (removed === 1) {
|
|
28
|
+
yield redis.srem(likeUserKey(userId), targetId);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}));
|
|
37
33
|
});
|
|
38
34
|
/**
|
|
39
35
|
* Check whether a user liked a target. Returns null if Redis is unavailable.
|
|
40
36
|
*/
|
|
41
37
|
const isTargetLiked = (targetId, userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
const result = yield redis.sismember(likeTargetKey(targetId), userId);
|
|
47
|
-
return result === 1;
|
|
38
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const result = yield redis.sismember(likeTargetKey(targetId), userId);
|
|
40
|
+
return result === 1;
|
|
41
|
+
}));
|
|
48
42
|
});
|
|
49
43
|
/**
|
|
50
44
|
* Get like count for a target (unique by user). Returns null if Redis is unavailable.
|
|
51
45
|
*/
|
|
52
46
|
const getTargetLikeCount = (targetId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
|
|
54
|
-
if (!redis) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return redis.scard(likeTargetKey(targetId));
|
|
47
|
+
return upstashConfig.withRedis((redis) => redis.scard(likeTargetKey(targetId)));
|
|
58
48
|
});
|
|
59
49
|
/**
|
|
60
50
|
* Get target ids liked by a user. Returns null if Redis is unavailable.
|
|
61
51
|
*/
|
|
62
52
|
const getUserLikedTargets = (userId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
if (!redis) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return redis.smembers(likeUserKey(userId));
|
|
53
|
+
return upstashConfig.withRedis((redis) => redis.smembers(likeUserKey(userId)));
|
|
68
54
|
});
|
|
69
55
|
|
|
70
56
|
exports.getTargetLikeCount = getTargetLikeCount;
|
|
@@ -1,5 +1,5 @@
|
|
|
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 {
|
|
2
|
+
import { withRedis } from '../upstash-config.mjs';
|
|
3
3
|
|
|
4
4
|
const likeTargetKey = (targetId) => `like:target:${targetId}`;
|
|
5
5
|
const likeUserKey = (userId) => `like:user:${userId}`;
|
|
@@ -7,62 +7,48 @@ const likeUserKey = (userId) => `like:user:${userId}`;
|
|
|
7
7
|
* Like a target. Returns true if the like was added, false if it already existed, null if Redis is unavailable.
|
|
8
8
|
*/
|
|
9
9
|
const likeTarget = (targetId, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
10
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const added = yield redis.sadd(likeTargetKey(targetId), userId);
|
|
12
|
+
if (added === 1) {
|
|
13
|
+
yield redis.sadd(likeUserKey(userId), targetId);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}));
|
|
20
18
|
});
|
|
21
19
|
/**
|
|
22
20
|
* Unlike a target. Returns true if removed, false if it didn't exist, null if Redis is unavailable.
|
|
23
21
|
*/
|
|
24
22
|
const unlikeTarget = (targetId, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
23
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const removed = yield redis.srem(likeTargetKey(targetId), userId);
|
|
25
|
+
if (removed === 1) {
|
|
26
|
+
yield redis.srem(likeUserKey(userId), targetId);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}));
|
|
35
31
|
});
|
|
36
32
|
/**
|
|
37
33
|
* Check whether a user liked a target. Returns null if Redis is unavailable.
|
|
38
34
|
*/
|
|
39
35
|
const isTargetLiked = (targetId, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
const result = yield redis.sismember(likeTargetKey(targetId), userId);
|
|
45
|
-
return result === 1;
|
|
36
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const result = yield redis.sismember(likeTargetKey(targetId), userId);
|
|
38
|
+
return result === 1;
|
|
39
|
+
}));
|
|
46
40
|
});
|
|
47
41
|
/**
|
|
48
42
|
* Get like count for a target (unique by user). Returns null if Redis is unavailable.
|
|
49
43
|
*/
|
|
50
44
|
const getTargetLikeCount = (targetId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
|
|
52
|
-
if (!redis) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return redis.scard(likeTargetKey(targetId));
|
|
45
|
+
return withRedis((redis) => redis.scard(likeTargetKey(targetId)));
|
|
56
46
|
});
|
|
57
47
|
/**
|
|
58
48
|
* Get target ids liked by a user. Returns null if Redis is unavailable.
|
|
59
49
|
*/
|
|
60
50
|
const getUserLikedTargets = (userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
-
|
|
62
|
-
if (!redis) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return redis.smembers(likeUserKey(userId));
|
|
51
|
+
return withRedis((redis) => redis.smembers(likeUserKey(userId)));
|
|
66
52
|
});
|
|
67
53
|
|
|
68
54
|
export { getTargetLikeCount, getUserLikedTargets, isTargetLiked, likeTarget, unlikeTarget };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-lock.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-lock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redis-lock.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-lock.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAMnF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,OAAO,CAM7E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAU,CAAC,EAC9B,KAAK,MAAM,EACX,OAAO,MAAM,EACb,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KACvB,OAAO,CAAC,CAAC,GAAG,IAAI,CAWlB,CAAC"}
|
|
@@ -1,64 +1,48 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tslib_es6 = require('../../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.js');
|
|
4
|
-
var index = require('../../_virtual/index.js');
|
|
5
4
|
var upstashConfig = require('../upstash-config.js');
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const unlockScript = `
|
|
7
|
+
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
8
|
+
return redis.call("del", KEYS[1])
|
|
9
|
+
else
|
|
10
|
+
return 0
|
|
11
|
+
end
|
|
12
|
+
`;
|
|
13
|
+
const generateToken = () => {
|
|
11
14
|
try {
|
|
12
|
-
return
|
|
15
|
+
return crypto.randomUUID();
|
|
13
16
|
}
|
|
14
17
|
catch (_a) {
|
|
15
|
-
return
|
|
18
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
16
19
|
}
|
|
17
20
|
};
|
|
18
|
-
const getLock = () => {
|
|
19
|
-
if (cachedLock) {
|
|
20
|
-
return cachedLock;
|
|
21
|
-
}
|
|
22
|
-
if (lockInitAttempted) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
lockInitAttempted = true;
|
|
26
|
-
const redis = upstashConfig.getRedis();
|
|
27
|
-
if (!redis) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
cachedLock = createLock(redis);
|
|
31
|
-
return cachedLock;
|
|
32
|
-
};
|
|
33
21
|
/**
|
|
34
22
|
* Acquire a distributed lock. Returns the lock token or null when unavailable.
|
|
35
23
|
*/
|
|
36
24
|
const acquireLock = (key, ttlMs) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const token = generateToken();
|
|
27
|
+
const result = yield redis.set(key, token, { nx: true, px: ttlMs });
|
|
28
|
+
return result === 'OK' ? token : null;
|
|
29
|
+
}));
|
|
42
30
|
});
|
|
43
31
|
/**
|
|
44
32
|
* Release a distributed lock. Returns false when the lock client is unavailable.
|
|
45
33
|
*/
|
|
46
34
|
const releaseLock = (key, token) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
return
|
|
35
|
+
const result = yield upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const released = yield redis.eval(unlockScript, [key], [token]);
|
|
37
|
+
return Number(released) === 1;
|
|
38
|
+
}));
|
|
39
|
+
return result !== null && result !== void 0 ? result : false;
|
|
52
40
|
});
|
|
53
41
|
/**
|
|
54
42
|
* Run a function under a distributed lock. Returns null when the lock is unavailable.
|
|
55
43
|
*/
|
|
56
44
|
const withLock = (key, ttlMs, fn) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
const
|
|
58
|
-
if (!lock) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
const token = yield lock.acquire(key, ttlMs);
|
|
45
|
+
const token = yield acquireLock(key, ttlMs);
|
|
62
46
|
if (!token) {
|
|
63
47
|
return null;
|
|
64
48
|
}
|
|
@@ -66,7 +50,7 @@ const withLock = (key, ttlMs, fn) => tslib_es6.__awaiter(void 0, void 0, void 0,
|
|
|
66
50
|
return yield fn();
|
|
67
51
|
}
|
|
68
52
|
finally {
|
|
69
|
-
yield
|
|
53
|
+
yield releaseLock(key, token);
|
|
70
54
|
}
|
|
71
55
|
});
|
|
72
56
|
|
|
@@ -1,62 +1,46 @@
|
|
|
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 {
|
|
3
|
-
import { getRedis } from '../upstash-config.mjs';
|
|
2
|
+
import { withRedis } from '../upstash-config.mjs';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const unlockScript = `
|
|
5
|
+
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
6
|
+
return redis.call("del", KEYS[1])
|
|
7
|
+
else
|
|
8
|
+
return 0
|
|
9
|
+
end
|
|
10
|
+
`;
|
|
11
|
+
const generateToken = () => {
|
|
9
12
|
try {
|
|
10
|
-
return
|
|
13
|
+
return crypto.randomUUID();
|
|
11
14
|
}
|
|
12
15
|
catch (_a) {
|
|
13
|
-
return
|
|
16
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
14
17
|
}
|
|
15
18
|
};
|
|
16
|
-
const getLock = () => {
|
|
17
|
-
if (cachedLock) {
|
|
18
|
-
return cachedLock;
|
|
19
|
-
}
|
|
20
|
-
if (lockInitAttempted) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
lockInitAttempted = true;
|
|
24
|
-
const redis = getRedis();
|
|
25
|
-
if (!redis) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
cachedLock = createLock(redis);
|
|
29
|
-
return cachedLock;
|
|
30
|
-
};
|
|
31
19
|
/**
|
|
32
20
|
* Acquire a distributed lock. Returns the lock token or null when unavailable.
|
|
33
21
|
*/
|
|
34
22
|
const acquireLock = (key, ttlMs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const token = generateToken();
|
|
25
|
+
const result = yield redis.set(key, token, { nx: true, px: ttlMs });
|
|
26
|
+
return result === 'OK' ? token : null;
|
|
27
|
+
}));
|
|
40
28
|
});
|
|
41
29
|
/**
|
|
42
30
|
* Release a distributed lock. Returns false when the lock client is unavailable.
|
|
43
31
|
*/
|
|
44
32
|
const releaseLock = (key, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
return
|
|
33
|
+
const result = yield withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const released = yield redis.eval(unlockScript, [key], [token]);
|
|
35
|
+
return Number(released) === 1;
|
|
36
|
+
}));
|
|
37
|
+
return result !== null && result !== void 0 ? result : false;
|
|
50
38
|
});
|
|
51
39
|
/**
|
|
52
40
|
* Run a function under a distributed lock. Returns null when the lock is unavailable.
|
|
53
41
|
*/
|
|
54
42
|
const withLock = (key, ttlMs, fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const
|
|
56
|
-
if (!lock) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const token = yield lock.acquire(key, ttlMs);
|
|
43
|
+
const token = yield acquireLock(key, ttlMs);
|
|
60
44
|
if (!token) {
|
|
61
45
|
return null;
|
|
62
46
|
}
|
|
@@ -64,7 +48,7 @@ const withLock = (key, ttlMs, fn) => __awaiter(void 0, void 0, void 0, function*
|
|
|
64
48
|
return yield fn();
|
|
65
49
|
}
|
|
66
50
|
finally {
|
|
67
|
-
yield
|
|
51
|
+
yield releaseLock(key, token);
|
|
68
52
|
}
|
|
69
53
|
});
|
|
70
54
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-structures.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-structures.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,KAAK,MAAM,EACX,OAAO,MAAM,EACb,SAAS,MAAM,KACd,OAAO,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"redis-structures.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-structures.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,KAAK,MAAM,EACX,OAAO,MAAM,EACb,SAAS,MAAM,KACd,OAAO,CAAC,OAAO,CAUjB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAElE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAAU,CAAC,EAC7B,KAAK,MAAM,EACX,OAAO,CAAC,EACR,SAAS,MAAM,KACd,OAAO,CAAC,OAAO,CAWjB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAAU,CAAC,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAa9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,OAAO,CAM5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAU,KAAK,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,OAAO,CAM7F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAU,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAEpF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,EACjC,KAAK,MAAM,EACX,OAAO,MAAM,EACb,OAAO,CAAC,KACP,OAAO,CAAC,OAAO,CAOjB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,EAAE,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAajF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAKnF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAU,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,OAAO,CAMjF,CAAC;AAEF,KAAK,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAEtC;;GAEG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,MAAM,EACX,QAAQ,MAAM,EAAE,EAChB,YAAW,aAAuB,KACjC,OAAO,CAAC,MAAM,GAAG,IAAI,CAUvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAClB,KAAK,MAAM,EACX,YAAW,aAAuB,KACjC,OAAO,CAAC,MAAM,GAAG,IAAI,CAIvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,KAAK,MAAM,EACX,cAAS,EACT,aAAS,KACR,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAEzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAEnE,CAAC"}
|