@windrun-huaiin/backend-core 13.0.0 → 14.1.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 +3 -1
- package/dist/index.mjs +2 -2
- package/dist/lib/index.js +3 -1
- package/dist/lib/index.mjs +2 -2
- package/dist/lib/stripe-config.d.ts +1 -1
- package/dist/lib/stripe-config.d.ts.map +1 -1
- package/dist/lib/stripe-config.js +25 -16
- package/dist/lib/stripe-config.mjs +25 -16
- 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/services/stripe/webhook-handler.js +4 -2
- package/dist/services/stripe/webhook-handler.mjs +3 -1
- package/package.json +5 -5
- package/src/lib/stripe-config.ts +27 -15
- 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/src/services/stripe/webhook-handler.ts +3 -1
- 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
|
@@ -1,101 +1,105 @@
|
|
|
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 { Receiver } from '../../node_modules/.pnpm/@upstash_qstash@2.
|
|
3
|
-
import {
|
|
2
|
+
import { Receiver } from '../../node_modules/.pnpm/@upstash_qstash@2.10.1/node_modules/@upstash/qstash/chunk-35B33QW3.mjs';
|
|
3
|
+
import { withQstash } from '../upstash-config.mjs';
|
|
4
4
|
|
|
5
5
|
let cachedReceiver = null;
|
|
6
|
-
let
|
|
6
|
+
let receiverWarnedMissingEnv = false;
|
|
7
|
+
let receiverWarnedInitError = false;
|
|
7
8
|
const isTruthy = (value) => value === '1' || value === 'true' || value === 'TRUE';
|
|
8
9
|
const shouldSkipVerify = () => process.env.NODE_ENV === 'development' && isTruthy(process.env.SKIP_UPSTASH_QSTASH_VERIFY);
|
|
9
10
|
const getReceiver = () => {
|
|
10
11
|
if (cachedReceiver) {
|
|
11
12
|
return cachedReceiver;
|
|
12
13
|
}
|
|
13
|
-
if (receiverInitAttempted) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
receiverInitAttempted = true;
|
|
17
14
|
const currentSigningKey = process.env.QSTASH_CURRENT_SIGNING_KEY;
|
|
18
15
|
const nextSigningKey = process.env.QSTASH_NEXT_SIGNING_KEY;
|
|
19
16
|
if (!currentSigningKey || !nextSigningKey) {
|
|
17
|
+
if (!receiverWarnedMissingEnv) {
|
|
18
|
+
receiverWarnedMissingEnv = true;
|
|
19
|
+
console.warn('[Upstash Config] QStash Receiver disabled: missing QSTASH_CURRENT_SIGNING_KEY or QSTASH_NEXT_SIGNING_KEY');
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
cachedReceiver = new Receiver({
|
|
25
|
+
currentSigningKey,
|
|
26
|
+
nextSigningKey,
|
|
27
|
+
});
|
|
28
|
+
return cachedReceiver;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (!receiverWarnedInitError) {
|
|
32
|
+
receiverWarnedInitError = true;
|
|
33
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
34
|
+
console.warn(`[Upstash Config] QStash Receiver init failed: ${message}`);
|
|
35
|
+
}
|
|
20
36
|
return null;
|
|
21
37
|
}
|
|
22
|
-
cachedReceiver = new Receiver({
|
|
23
|
-
currentSigningKey,
|
|
24
|
-
nextSigningKey,
|
|
25
|
-
});
|
|
26
|
-
return cachedReceiver;
|
|
27
38
|
};
|
|
28
39
|
/**
|
|
29
40
|
* Publish a message. Returns message id or null if QStash is unavailable.
|
|
30
41
|
*/
|
|
31
42
|
const publishMessage = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
return typeof result === 'string' ? result : (_a = result === null || result === void 0 ? void 0 : result.messageId) !== null && _a !== void 0 ? _a : null;
|
|
43
|
+
return withQstash((client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
var _a;
|
|
45
|
+
const result = yield client.publishJSON({
|
|
46
|
+
url: options.url,
|
|
47
|
+
body: options.body,
|
|
48
|
+
});
|
|
49
|
+
return typeof result === 'string' ? result : (_a = result === null || result === void 0 ? void 0 : result.messageId) !== null && _a !== void 0 ? _a : null;
|
|
50
|
+
}));
|
|
42
51
|
});
|
|
43
52
|
/**
|
|
44
53
|
* Publish a delayed message. Returns message id or null if QStash is unavailable.
|
|
45
54
|
*/
|
|
46
55
|
const publishDelayedMessage = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
return typeof result === 'string' ? result : (_a = result === null || result === void 0 ? void 0 : result.messageId) !== null && _a !== void 0 ? _a : null;
|
|
56
|
+
return withQstash((client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
const result = yield client.publishJSON({
|
|
59
|
+
url: options.url,
|
|
60
|
+
body: options.body,
|
|
61
|
+
delay: options.delaySec,
|
|
62
|
+
});
|
|
63
|
+
return typeof result === 'string' ? result : (_a = result === null || result === void 0 ? void 0 : result.messageId) !== null && _a !== void 0 ? _a : null;
|
|
64
|
+
}));
|
|
58
65
|
});
|
|
59
66
|
/**
|
|
60
67
|
* Schedule a recurring message. Returns schedule id or null if QStash is unavailable.
|
|
61
68
|
*/
|
|
62
69
|
const scheduleMessage = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})));
|
|
78
|
-
return typeof result === 'string' ? result : (_f = (_e = result === null || result === void 0 ? void 0 : result.scheduleId) !== null && _e !== void 0 ? _e : result === null || result === void 0 ? void 0 : result.id) !== null && _f !== void 0 ? _f : null;
|
|
70
|
+
return withQstash((client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
var _a, _b, _c, _d, _e, _f;
|
|
72
|
+
const anyClient = client;
|
|
73
|
+
const result = (_c = (yield ((_b = (_a = anyClient.schedules) === null || _a === void 0 ? void 0 : _a.create) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
74
|
+
url: options.url,
|
|
75
|
+
body: options.body,
|
|
76
|
+
cron: options.cron,
|
|
77
|
+
})))) !== null && _c !== void 0 ? _c : (yield ((_d = anyClient.publishJSON) === null || _d === void 0 ? void 0 : _d.call(anyClient, {
|
|
78
|
+
url: options.url,
|
|
79
|
+
body: options.body,
|
|
80
|
+
cron: options.cron,
|
|
81
|
+
})));
|
|
82
|
+
return typeof result === 'string' ? result : (_f = (_e = result === null || result === void 0 ? void 0 : result.scheduleId) !== null && _e !== void 0 ? _e : result === null || result === void 0 ? void 0 : result.id) !== null && _f !== void 0 ? _f : null;
|
|
83
|
+
}));
|
|
79
84
|
});
|
|
80
85
|
/**
|
|
81
86
|
* Cancel a scheduled message. Returns false if QStash is unavailable.
|
|
82
87
|
*/
|
|
83
88
|
const cancelSchedule = (scheduleId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
const result = yield withQstash((client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const anyClient = client;
|
|
92
|
+
if ((_a = anyClient.schedules) === null || _a === void 0 ? void 0 : _a.delete) {
|
|
93
|
+
yield anyClient.schedules.delete(scheduleId);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if ((_b = anyClient.schedules) === null || _b === void 0 ? void 0 : _b.remove) {
|
|
97
|
+
yield anyClient.schedules.remove(scheduleId);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
87
100
|
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if ((_a = anyClient.schedules) === null || _a === void 0 ? void 0 : _a.delete) {
|
|
91
|
-
yield anyClient.schedules.delete(scheduleId);
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
if ((_b = anyClient.schedules) === null || _b === void 0 ? void 0 : _b.remove) {
|
|
95
|
-
yield anyClient.schedules.remove(scheduleId);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
101
|
+
}));
|
|
102
|
+
return result !== null && result !== void 0 ? result : false;
|
|
99
103
|
});
|
|
100
104
|
/**
|
|
101
105
|
* Verify QStash signature. Throws on failure in non-dev environments.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-counter.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-counter.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,EAAE,cAAS,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"redis-counter.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-counter.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,EAAE,cAAS,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAE/E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAKnE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAU,QAAQ,MAAM,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAK/F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAE5E,CAAC"}
|
|
@@ -7,46 +7,31 @@ var upstashConfig = require('../upstash-config.js');
|
|
|
7
7
|
* Increment a counter (e.g. views, forwards). Returns null if Redis is unavailable.
|
|
8
8
|
*/
|
|
9
9
|
const incrCounter = (key_1, ...args_1) => tslib_es6.__awaiter(void 0, [key_1, ...args_1], void 0, function* (key, delta = 1) {
|
|
10
|
-
|
|
11
|
-
if (!redis) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
return redis.incrby(key, delta);
|
|
10
|
+
return upstashConfig.withRedis((redis) => redis.incrby(key, delta));
|
|
15
11
|
});
|
|
16
12
|
/**
|
|
17
13
|
* Get a counter value. Returns null if Redis is unavailable.
|
|
18
14
|
*/
|
|
19
15
|
const getCounter = (key) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const value = yield redis.get(key);
|
|
25
|
-
return value !== null && value !== void 0 ? value : 0;
|
|
16
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const value = yield redis.get(key);
|
|
18
|
+
return value !== null && value !== void 0 ? value : 0;
|
|
19
|
+
}));
|
|
26
20
|
});
|
|
27
21
|
/**
|
|
28
22
|
* Increment a unique counter via SET (e.g. unique views). Returns null if Redis is unavailable.
|
|
29
23
|
*/
|
|
30
24
|
const incrUniqueCounter = (setKey, memberId) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
const added = yield redis.sadd(setKey, memberId);
|
|
36
|
-
if (added === 1) {
|
|
25
|
+
return upstashConfig.withRedis((redis) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
yield redis.sadd(setKey, memberId);
|
|
37
27
|
return redis.scard(setKey);
|
|
38
|
-
}
|
|
39
|
-
return redis.scard(setKey);
|
|
28
|
+
}));
|
|
40
29
|
});
|
|
41
30
|
/**
|
|
42
31
|
* Get unique counter value (SET cardinality). Returns null if Redis is unavailable.
|
|
43
32
|
*/
|
|
44
33
|
const getUniqueCounter = (setKey) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
|
|
46
|
-
if (!redis) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return redis.scard(setKey);
|
|
34
|
+
return upstashConfig.withRedis((redis) => redis.scard(setKey));
|
|
50
35
|
});
|
|
51
36
|
|
|
52
37
|
exports.getCounter = getCounter;
|
|
@@ -1,50 +1,35 @@
|
|
|
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
|
/**
|
|
5
5
|
* Increment a counter (e.g. views, forwards). Returns null if Redis is unavailable.
|
|
6
6
|
*/
|
|
7
7
|
const incrCounter = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, delta = 1) {
|
|
8
|
-
|
|
9
|
-
if (!redis) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return redis.incrby(key, delta);
|
|
8
|
+
return withRedis((redis) => redis.incrby(key, delta));
|
|
13
9
|
});
|
|
14
10
|
/**
|
|
15
11
|
* Get a counter value. Returns null if Redis is unavailable.
|
|
16
12
|
*/
|
|
17
13
|
const getCounter = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
const value = yield redis.get(key);
|
|
23
|
-
return value !== null && value !== void 0 ? value : 0;
|
|
14
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const value = yield redis.get(key);
|
|
16
|
+
return value !== null && value !== void 0 ? value : 0;
|
|
17
|
+
}));
|
|
24
18
|
});
|
|
25
19
|
/**
|
|
26
20
|
* Increment a unique counter via SET (e.g. unique views). Returns null if Redis is unavailable.
|
|
27
21
|
*/
|
|
28
22
|
const incrUniqueCounter = (setKey, memberId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
const added = yield redis.sadd(setKey, memberId);
|
|
34
|
-
if (added === 1) {
|
|
23
|
+
return withRedis((redis) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
yield redis.sadd(setKey, memberId);
|
|
35
25
|
return redis.scard(setKey);
|
|
36
|
-
}
|
|
37
|
-
return redis.scard(setKey);
|
|
26
|
+
}));
|
|
38
27
|
});
|
|
39
28
|
/**
|
|
40
29
|
* Get unique counter value (SET cardinality). Returns null if Redis is unavailable.
|
|
41
30
|
*/
|
|
42
31
|
const getUniqueCounter = (setKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
|
|
44
|
-
if (!redis) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return redis.scard(setKey);
|
|
32
|
+
return withRedis((redis) => redis.scard(setKey));
|
|
48
33
|
});
|
|
49
34
|
|
|
50
35
|
export { getCounter, getUniqueCounter, incrCounter, incrUniqueCounter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-favorite.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-favorite.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"redis-favorite.d.ts","sourceRoot":"","sources":["../../../src/lib/upstash/redis-favorite.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAS1F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAS7F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAK1F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAE9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAE9E,CAAC"}
|
|
@@ -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;
|