@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,191 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var dist;
|
|
4
|
-
var hasRequiredDist;
|
|
5
|
-
|
|
6
|
-
function requireDist () {
|
|
7
|
-
if (hasRequiredDist) return dist;
|
|
8
|
-
hasRequiredDist = 1;
|
|
9
|
-
var __defProp = Object.defineProperty;
|
|
10
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
-
var __export = (target, all) => {
|
|
14
|
-
for (var name in all)
|
|
15
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
-
};
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
-
for (let key of __getOwnPropNames(from))
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
-
var __async = (__this, __arguments, generator) => {
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
var fulfilled = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.next(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var rejected = (value) => {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.throw(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
43
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// src/index.ts
|
|
48
|
-
var src_exports = {};
|
|
49
|
-
__export(src_exports, {
|
|
50
|
-
Lock: () => Lock
|
|
51
|
-
});
|
|
52
|
-
dist = __toCommonJS(src_exports);
|
|
53
|
-
|
|
54
|
-
// src/lock.ts
|
|
55
|
-
var Lock = class {
|
|
56
|
-
constructor(config) {
|
|
57
|
-
this.DEFAULT_LEASE_MS = 1e4;
|
|
58
|
-
this.DEFAULT_RETRY_ATTEMPTS = 3;
|
|
59
|
-
this.DEFAULT_RETRY_DELAY_MS = 100;
|
|
60
|
-
var _a, _b, _c, _d, _e;
|
|
61
|
-
this.config = {
|
|
62
|
-
redis: config.redis,
|
|
63
|
-
id: config.id,
|
|
64
|
-
lease: (_a = config.lease) != null ? _a : this.DEFAULT_LEASE_MS,
|
|
65
|
-
UUID: null,
|
|
66
|
-
// set when lock is acquired
|
|
67
|
-
retry: {
|
|
68
|
-
attempts: (_c = (_b = config.retry) == null ? void 0 : _b.attempts) != null ? _c : this.DEFAULT_RETRY_ATTEMPTS,
|
|
69
|
-
delay: (_e = (_d = config.retry) == null ? void 0 : _d.delay) != null ? _e : this.DEFAULT_RETRY_DELAY_MS
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Tries to acquire a lock with the given configuration.
|
|
75
|
-
* If initially unsuccessful, the method will retry based on the provided retry configuration.
|
|
76
|
-
*
|
|
77
|
-
* @param config - Optional configuration for the lock acquisition to override the constructor config.
|
|
78
|
-
* @returns {Promise<boolean>} True if the lock was acquired, otherwise false.
|
|
79
|
-
*/
|
|
80
|
-
acquire(acquireConfig) {
|
|
81
|
-
return __async(this, null, function* () {
|
|
82
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
83
|
-
const lease = (_a = acquireConfig == null ? void 0 : acquireConfig.lease) != null ? _a : this.config.lease;
|
|
84
|
-
this.config.lease = lease;
|
|
85
|
-
const retryAttempts = (_d = (_b = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _b.attempts) != null ? _d : (_c = this.config.retry) == null ? void 0 : _c.attempts;
|
|
86
|
-
const retryDelay = (_g = (_e = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _e.delay) != null ? _g : (_f = this.config.retry) == null ? void 0 : _f.delay;
|
|
87
|
-
let attempts = 0;
|
|
88
|
-
let UUID;
|
|
89
|
-
if (acquireConfig == null ? void 0 : acquireConfig.uuid) {
|
|
90
|
-
UUID = acquireConfig.uuid;
|
|
91
|
-
} else {
|
|
92
|
-
try {
|
|
93
|
-
UUID = crypto.randomUUID();
|
|
94
|
-
} catch (error) {
|
|
95
|
-
throw new Error("No UUID provided and crypto module is not available in this environment.");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
while (attempts < retryAttempts) {
|
|
99
|
-
const upstashResult = yield this.config.redis.set(this.config.id, UUID, {
|
|
100
|
-
nx: true,
|
|
101
|
-
px: lease
|
|
102
|
-
});
|
|
103
|
-
if (upstashResult === "OK") {
|
|
104
|
-
this.config.UUID = UUID;
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
attempts += 1;
|
|
108
|
-
yield new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
109
|
-
}
|
|
110
|
-
this.config.UUID = null;
|
|
111
|
-
return false;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Safely releases the lock ensuring the UUID matches.
|
|
116
|
-
* This operation utilizes a Lua script to interact with Redis and
|
|
117
|
-
* guarantees atomicity of the unlock operation.
|
|
118
|
-
* @returns {Promise<boolean>} True if the lock was released, otherwise false.
|
|
119
|
-
*/
|
|
120
|
-
release() {
|
|
121
|
-
return __async(this, null, function* () {
|
|
122
|
-
const script = `
|
|
123
|
-
-- Check if the current UUID still holds the lock
|
|
124
|
-
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
125
|
-
return redis.call("del", KEYS[1])
|
|
126
|
-
else
|
|
127
|
-
return 0
|
|
128
|
-
end
|
|
129
|
-
`;
|
|
130
|
-
const numReleased = yield this.config.redis.eval(script, [this.config.id], [this.config.UUID]);
|
|
131
|
-
return numReleased === 1;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Extends the duration for which the lock is held by a given amount of milliseconds.
|
|
136
|
-
* @param amt - The number of milliseconds by which the lock duration should be extended.
|
|
137
|
-
* @returns {Promise<boolean>} True if the lock duration was extended, otherwise false.
|
|
138
|
-
*/
|
|
139
|
-
extend(amt) {
|
|
140
|
-
return __async(this, null, function* () {
|
|
141
|
-
const script = `
|
|
142
|
-
-- Check if the current UUID still holds the lock
|
|
143
|
-
if redis.call("get", KEYS[1]) ~= ARGV[1] then
|
|
144
|
-
return 0
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
-- Get the current TTL and extend it by the specified amount
|
|
148
|
-
local ttl = redis.call("ttl", KEYS[1])
|
|
149
|
-
if ttl > 0 then
|
|
150
|
-
return redis.call("expire", KEYS[1], ttl + ARGV[2])
|
|
151
|
-
else
|
|
152
|
-
return 0
|
|
153
|
-
end
|
|
154
|
-
`;
|
|
155
|
-
const extendBy = amt / 1e3;
|
|
156
|
-
const extended = yield this.config.redis.eval(
|
|
157
|
-
script,
|
|
158
|
-
[this.config.id],
|
|
159
|
-
[this.config.UUID, extendBy]
|
|
160
|
-
);
|
|
161
|
-
if (extended === 1) {
|
|
162
|
-
this.config.lease += amt;
|
|
163
|
-
}
|
|
164
|
-
return extended === 1;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
get id() {
|
|
168
|
-
return this.config.id;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Gets the status of the lock, ie: ACQUIRED or FREE.
|
|
172
|
-
* @returns {Promise<LockStatus>} The status of the lock.
|
|
173
|
-
*/
|
|
174
|
-
getStatus() {
|
|
175
|
-
return __async(this, null, function* () {
|
|
176
|
-
if (this.config.UUID === null) {
|
|
177
|
-
return "FREE";
|
|
178
|
-
}
|
|
179
|
-
const UUID = yield this.config.redis.get(this.config.id);
|
|
180
|
-
if (UUID === this.config.UUID) {
|
|
181
|
-
return "ACQUIRED";
|
|
182
|
-
}
|
|
183
|
-
return "FREE";
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
return dist;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
exports.__require = requireDist;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
var dist;
|
|
2
|
-
var hasRequiredDist;
|
|
3
|
-
|
|
4
|
-
function requireDist () {
|
|
5
|
-
if (hasRequiredDist) return dist;
|
|
6
|
-
hasRequiredDist = 1;
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var __async = (__this, __arguments, generator) => {
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
var fulfilled = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.next(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var rejected = (value) => {
|
|
34
|
-
try {
|
|
35
|
-
step(generator.throw(value));
|
|
36
|
-
} catch (e) {
|
|
37
|
-
reject(e);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/index.ts
|
|
46
|
-
var src_exports = {};
|
|
47
|
-
__export(src_exports, {
|
|
48
|
-
Lock: () => Lock
|
|
49
|
-
});
|
|
50
|
-
dist = __toCommonJS(src_exports);
|
|
51
|
-
|
|
52
|
-
// src/lock.ts
|
|
53
|
-
var Lock = class {
|
|
54
|
-
constructor(config) {
|
|
55
|
-
this.DEFAULT_LEASE_MS = 1e4;
|
|
56
|
-
this.DEFAULT_RETRY_ATTEMPTS = 3;
|
|
57
|
-
this.DEFAULT_RETRY_DELAY_MS = 100;
|
|
58
|
-
var _a, _b, _c, _d, _e;
|
|
59
|
-
this.config = {
|
|
60
|
-
redis: config.redis,
|
|
61
|
-
id: config.id,
|
|
62
|
-
lease: (_a = config.lease) != null ? _a : this.DEFAULT_LEASE_MS,
|
|
63
|
-
UUID: null,
|
|
64
|
-
// set when lock is acquired
|
|
65
|
-
retry: {
|
|
66
|
-
attempts: (_c = (_b = config.retry) == null ? void 0 : _b.attempts) != null ? _c : this.DEFAULT_RETRY_ATTEMPTS,
|
|
67
|
-
delay: (_e = (_d = config.retry) == null ? void 0 : _d.delay) != null ? _e : this.DEFAULT_RETRY_DELAY_MS
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Tries to acquire a lock with the given configuration.
|
|
73
|
-
* If initially unsuccessful, the method will retry based on the provided retry configuration.
|
|
74
|
-
*
|
|
75
|
-
* @param config - Optional configuration for the lock acquisition to override the constructor config.
|
|
76
|
-
* @returns {Promise<boolean>} True if the lock was acquired, otherwise false.
|
|
77
|
-
*/
|
|
78
|
-
acquire(acquireConfig) {
|
|
79
|
-
return __async(this, null, function* () {
|
|
80
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
81
|
-
const lease = (_a = acquireConfig == null ? void 0 : acquireConfig.lease) != null ? _a : this.config.lease;
|
|
82
|
-
this.config.lease = lease;
|
|
83
|
-
const retryAttempts = (_d = (_b = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _b.attempts) != null ? _d : (_c = this.config.retry) == null ? void 0 : _c.attempts;
|
|
84
|
-
const retryDelay = (_g = (_e = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _e.delay) != null ? _g : (_f = this.config.retry) == null ? void 0 : _f.delay;
|
|
85
|
-
let attempts = 0;
|
|
86
|
-
let UUID;
|
|
87
|
-
if (acquireConfig == null ? void 0 : acquireConfig.uuid) {
|
|
88
|
-
UUID = acquireConfig.uuid;
|
|
89
|
-
} else {
|
|
90
|
-
try {
|
|
91
|
-
UUID = crypto.randomUUID();
|
|
92
|
-
} catch (error) {
|
|
93
|
-
throw new Error("No UUID provided and crypto module is not available in this environment.");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
while (attempts < retryAttempts) {
|
|
97
|
-
const upstashResult = yield this.config.redis.set(this.config.id, UUID, {
|
|
98
|
-
nx: true,
|
|
99
|
-
px: lease
|
|
100
|
-
});
|
|
101
|
-
if (upstashResult === "OK") {
|
|
102
|
-
this.config.UUID = UUID;
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
attempts += 1;
|
|
106
|
-
yield new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
107
|
-
}
|
|
108
|
-
this.config.UUID = null;
|
|
109
|
-
return false;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Safely releases the lock ensuring the UUID matches.
|
|
114
|
-
* This operation utilizes a Lua script to interact with Redis and
|
|
115
|
-
* guarantees atomicity of the unlock operation.
|
|
116
|
-
* @returns {Promise<boolean>} True if the lock was released, otherwise false.
|
|
117
|
-
*/
|
|
118
|
-
release() {
|
|
119
|
-
return __async(this, null, function* () {
|
|
120
|
-
const script = `
|
|
121
|
-
-- Check if the current UUID still holds the lock
|
|
122
|
-
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
123
|
-
return redis.call("del", KEYS[1])
|
|
124
|
-
else
|
|
125
|
-
return 0
|
|
126
|
-
end
|
|
127
|
-
`;
|
|
128
|
-
const numReleased = yield this.config.redis.eval(script, [this.config.id], [this.config.UUID]);
|
|
129
|
-
return numReleased === 1;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Extends the duration for which the lock is held by a given amount of milliseconds.
|
|
134
|
-
* @param amt - The number of milliseconds by which the lock duration should be extended.
|
|
135
|
-
* @returns {Promise<boolean>} True if the lock duration was extended, otherwise false.
|
|
136
|
-
*/
|
|
137
|
-
extend(amt) {
|
|
138
|
-
return __async(this, null, function* () {
|
|
139
|
-
const script = `
|
|
140
|
-
-- Check if the current UUID still holds the lock
|
|
141
|
-
if redis.call("get", KEYS[1]) ~= ARGV[1] then
|
|
142
|
-
return 0
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
-- Get the current TTL and extend it by the specified amount
|
|
146
|
-
local ttl = redis.call("ttl", KEYS[1])
|
|
147
|
-
if ttl > 0 then
|
|
148
|
-
return redis.call("expire", KEYS[1], ttl + ARGV[2])
|
|
149
|
-
else
|
|
150
|
-
return 0
|
|
151
|
-
end
|
|
152
|
-
`;
|
|
153
|
-
const extendBy = amt / 1e3;
|
|
154
|
-
const extended = yield this.config.redis.eval(
|
|
155
|
-
script,
|
|
156
|
-
[this.config.id],
|
|
157
|
-
[this.config.UUID, extendBy]
|
|
158
|
-
);
|
|
159
|
-
if (extended === 1) {
|
|
160
|
-
this.config.lease += amt;
|
|
161
|
-
}
|
|
162
|
-
return extended === 1;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
get id() {
|
|
166
|
-
return this.config.id;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Gets the status of the lock, ie: ACQUIRED or FREE.
|
|
170
|
-
* @returns {Promise<LockStatus>} The status of the lock.
|
|
171
|
-
*/
|
|
172
|
-
getStatus() {
|
|
173
|
-
return __async(this, null, function* () {
|
|
174
|
-
if (this.config.UUID === null) {
|
|
175
|
-
return "FREE";
|
|
176
|
-
}
|
|
177
|
-
const UUID = yield this.config.redis.get(this.config.id);
|
|
178
|
-
if (UUID === this.config.UUID) {
|
|
179
|
-
return "ACQUIRED";
|
|
180
|
-
}
|
|
181
|
-
return "FREE";
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
return dist;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export { requireDist as __require };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('../core/core.js');
|
|
4
|
-
var errors = require('../core/errors.js');
|
|
5
|
-
var util = require('../core/util.js');
|
|
6
|
-
|
|
7
|
-
const initializer = (inst, issues) => {
|
|
8
|
-
errors.$ZodError.init(inst, issues);
|
|
9
|
-
inst.name = "ZodError";
|
|
10
|
-
Object.defineProperties(inst, {
|
|
11
|
-
format: {
|
|
12
|
-
value: (mapper) => errors.formatError(inst, mapper),
|
|
13
|
-
// enumerable: false,
|
|
14
|
-
},
|
|
15
|
-
flatten: {
|
|
16
|
-
value: (mapper) => errors.flattenError(inst, mapper),
|
|
17
|
-
// enumerable: false,
|
|
18
|
-
},
|
|
19
|
-
addIssue: {
|
|
20
|
-
value: (issue) => {
|
|
21
|
-
inst.issues.push(issue);
|
|
22
|
-
inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
|
|
23
|
-
},
|
|
24
|
-
// enumerable: false,
|
|
25
|
-
},
|
|
26
|
-
addIssues: {
|
|
27
|
-
value: (issues) => {
|
|
28
|
-
inst.issues.push(...issues);
|
|
29
|
-
inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
|
|
30
|
-
},
|
|
31
|
-
// enumerable: false,
|
|
32
|
-
},
|
|
33
|
-
isEmpty: {
|
|
34
|
-
get() {
|
|
35
|
-
return inst.issues.length === 0;
|
|
36
|
-
},
|
|
37
|
-
// enumerable: false,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
// Object.defineProperty(inst, "isEmpty", {
|
|
41
|
-
// get() {
|
|
42
|
-
// return inst.issues.length === 0;
|
|
43
|
-
// },
|
|
44
|
-
// });
|
|
45
|
-
};
|
|
46
|
-
const ZodError = core.$constructor("ZodError", initializer);
|
|
47
|
-
const ZodRealError = core.$constructor("ZodError", initializer, {
|
|
48
|
-
Parent: Error,
|
|
49
|
-
});
|
|
50
|
-
// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
|
|
51
|
-
// export type ErrorMapCtx = core.$ZodErrorMapCtx;
|
|
52
|
-
|
|
53
|
-
exports.ZodError = ZodError;
|
|
54
|
-
exports.ZodRealError = ZodRealError;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { $constructor } from '../core/core.mjs';
|
|
2
|
-
import { $ZodError, flattenError, formatError } from '../core/errors.mjs';
|
|
3
|
-
import { jsonStringifyReplacer } from '../core/util.mjs';
|
|
4
|
-
|
|
5
|
-
const initializer = (inst, issues) => {
|
|
6
|
-
$ZodError.init(inst, issues);
|
|
7
|
-
inst.name = "ZodError";
|
|
8
|
-
Object.defineProperties(inst, {
|
|
9
|
-
format: {
|
|
10
|
-
value: (mapper) => formatError(inst, mapper),
|
|
11
|
-
// enumerable: false,
|
|
12
|
-
},
|
|
13
|
-
flatten: {
|
|
14
|
-
value: (mapper) => flattenError(inst, mapper),
|
|
15
|
-
// enumerable: false,
|
|
16
|
-
},
|
|
17
|
-
addIssue: {
|
|
18
|
-
value: (issue) => {
|
|
19
|
-
inst.issues.push(issue);
|
|
20
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
21
|
-
},
|
|
22
|
-
// enumerable: false,
|
|
23
|
-
},
|
|
24
|
-
addIssues: {
|
|
25
|
-
value: (issues) => {
|
|
26
|
-
inst.issues.push(...issues);
|
|
27
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
28
|
-
},
|
|
29
|
-
// enumerable: false,
|
|
30
|
-
},
|
|
31
|
-
isEmpty: {
|
|
32
|
-
get() {
|
|
33
|
-
return inst.issues.length === 0;
|
|
34
|
-
},
|
|
35
|
-
// enumerable: false,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
// Object.defineProperty(inst, "isEmpty", {
|
|
39
|
-
// get() {
|
|
40
|
-
// return inst.issues.length === 0;
|
|
41
|
-
// },
|
|
42
|
-
// });
|
|
43
|
-
};
|
|
44
|
-
const ZodError = $constructor("ZodError", initializer);
|
|
45
|
-
const ZodRealError = $constructor("ZodError", initializer, {
|
|
46
|
-
Parent: Error,
|
|
47
|
-
});
|
|
48
|
-
// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
|
|
49
|
-
// export type ErrorMapCtx = core.$ZodErrorMapCtx;
|
|
50
|
-
|
|
51
|
-
export { ZodError, ZodRealError };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('../core/core.js');
|
|
4
|
-
var schemas = require('../core/schemas.js');
|
|
5
|
-
var api = require('../core/api.js');
|
|
6
|
-
var schemas$1 = require('./schemas.js');
|
|
7
|
-
|
|
8
|
-
const ZodISODateTime = /*@__PURE__*/ core.$constructor("ZodISODateTime", (inst, def) => {
|
|
9
|
-
schemas.$ZodISODateTime.init(inst, def);
|
|
10
|
-
schemas$1.ZodStringFormat.init(inst, def);
|
|
11
|
-
});
|
|
12
|
-
function datetime(params) {
|
|
13
|
-
return api._isoDateTime(ZodISODateTime, params);
|
|
14
|
-
}
|
|
15
|
-
const ZodISODate = /*@__PURE__*/ core.$constructor("ZodISODate", (inst, def) => {
|
|
16
|
-
schemas.$ZodISODate.init(inst, def);
|
|
17
|
-
schemas$1.ZodStringFormat.init(inst, def);
|
|
18
|
-
});
|
|
19
|
-
function date(params) {
|
|
20
|
-
return api._isoDate(ZodISODate, params);
|
|
21
|
-
}
|
|
22
|
-
const ZodISOTime = /*@__PURE__*/ core.$constructor("ZodISOTime", (inst, def) => {
|
|
23
|
-
schemas.$ZodISOTime.init(inst, def);
|
|
24
|
-
schemas$1.ZodStringFormat.init(inst, def);
|
|
25
|
-
});
|
|
26
|
-
function time(params) {
|
|
27
|
-
return api._isoTime(ZodISOTime, params);
|
|
28
|
-
}
|
|
29
|
-
const ZodISODuration = /*@__PURE__*/ core.$constructor("ZodISODuration", (inst, def) => {
|
|
30
|
-
schemas.$ZodISODuration.init(inst, def);
|
|
31
|
-
schemas$1.ZodStringFormat.init(inst, def);
|
|
32
|
-
});
|
|
33
|
-
function duration(params) {
|
|
34
|
-
return api._isoDuration(ZodISODuration, params);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
exports.ZodISODate = ZodISODate;
|
|
38
|
-
exports.ZodISODateTime = ZodISODateTime;
|
|
39
|
-
exports.ZodISODuration = ZodISODuration;
|
|
40
|
-
exports.ZodISOTime = ZodISOTime;
|
|
41
|
-
exports.date = date;
|
|
42
|
-
exports.datetime = datetime;
|
|
43
|
-
exports.duration = duration;
|
|
44
|
-
exports.time = time;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { $constructor } from '../core/core.mjs';
|
|
2
|
-
import { $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration } from '../core/schemas.mjs';
|
|
3
|
-
import { _isoDateTime, _isoDate, _isoTime, _isoDuration } from '../core/api.mjs';
|
|
4
|
-
import { ZodStringFormat } from './schemas.mjs';
|
|
5
|
-
|
|
6
|
-
const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
7
|
-
$ZodISODateTime.init(inst, def);
|
|
8
|
-
ZodStringFormat.init(inst, def);
|
|
9
|
-
});
|
|
10
|
-
function datetime(params) {
|
|
11
|
-
return _isoDateTime(ZodISODateTime, params);
|
|
12
|
-
}
|
|
13
|
-
const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
|
|
14
|
-
$ZodISODate.init(inst, def);
|
|
15
|
-
ZodStringFormat.init(inst, def);
|
|
16
|
-
});
|
|
17
|
-
function date(params) {
|
|
18
|
-
return _isoDate(ZodISODate, params);
|
|
19
|
-
}
|
|
20
|
-
const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
|
|
21
|
-
$ZodISOTime.init(inst, def);
|
|
22
|
-
ZodStringFormat.init(inst, def);
|
|
23
|
-
});
|
|
24
|
-
function time(params) {
|
|
25
|
-
return _isoTime(ZodISOTime, params);
|
|
26
|
-
}
|
|
27
|
-
const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
|
|
28
|
-
$ZodISODuration.init(inst, def);
|
|
29
|
-
ZodStringFormat.init(inst, def);
|
|
30
|
-
});
|
|
31
|
-
function duration(params) {
|
|
32
|
-
return _isoDuration(ZodISODuration, params);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { ZodISODate, ZodISODateTime, ZodISODuration, ZodISOTime, date, datetime, duration, time };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var parse$1 = require('../core/parse.js');
|
|
4
|
-
var errors = require('./errors.js');
|
|
5
|
-
|
|
6
|
-
const parse = /* @__PURE__ */ parse$1._parse(errors.ZodRealError);
|
|
7
|
-
const parseAsync = /* @__PURE__ */ parse$1._parseAsync(errors.ZodRealError);
|
|
8
|
-
const safeParse = /* @__PURE__ */ parse$1._safeParse(errors.ZodRealError);
|
|
9
|
-
const safeParseAsync = /* @__PURE__ */ parse$1._safeParseAsync(errors.ZodRealError);
|
|
10
|
-
// Codec functions
|
|
11
|
-
const encode = /* @__PURE__ */ parse$1._encode(errors.ZodRealError);
|
|
12
|
-
const decode = /* @__PURE__ */ parse$1._decode(errors.ZodRealError);
|
|
13
|
-
const encodeAsync = /* @__PURE__ */ parse$1._encodeAsync(errors.ZodRealError);
|
|
14
|
-
const decodeAsync = /* @__PURE__ */ parse$1._decodeAsync(errors.ZodRealError);
|
|
15
|
-
const safeEncode = /* @__PURE__ */ parse$1._safeEncode(errors.ZodRealError);
|
|
16
|
-
const safeDecode = /* @__PURE__ */ parse$1._safeDecode(errors.ZodRealError);
|
|
17
|
-
const safeEncodeAsync = /* @__PURE__ */ parse$1._safeEncodeAsync(errors.ZodRealError);
|
|
18
|
-
const safeDecodeAsync = /* @__PURE__ */ parse$1._safeDecodeAsync(errors.ZodRealError);
|
|
19
|
-
|
|
20
|
-
exports.decode = decode;
|
|
21
|
-
exports.decodeAsync = decodeAsync;
|
|
22
|
-
exports.encode = encode;
|
|
23
|
-
exports.encodeAsync = encodeAsync;
|
|
24
|
-
exports.parse = parse;
|
|
25
|
-
exports.parseAsync = parseAsync;
|
|
26
|
-
exports.safeDecode = safeDecode;
|
|
27
|
-
exports.safeDecodeAsync = safeDecodeAsync;
|
|
28
|
-
exports.safeEncode = safeEncode;
|
|
29
|
-
exports.safeEncodeAsync = safeEncodeAsync;
|
|
30
|
-
exports.safeParse = safeParse;
|
|
31
|
-
exports.safeParseAsync = safeParseAsync;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { _parse, _safeParse, _parseAsync, _safeParseAsync, _encode, _decode, _encodeAsync, _decodeAsync, _safeEncode, _safeDecode, _safeEncodeAsync, _safeDecodeAsync } from '../core/parse.mjs';
|
|
2
|
-
import { ZodRealError } from './errors.mjs';
|
|
3
|
-
|
|
4
|
-
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
5
|
-
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
6
|
-
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
7
|
-
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
8
|
-
// Codec functions
|
|
9
|
-
const encode = /* @__PURE__ */ _encode(ZodRealError);
|
|
10
|
-
const decode = /* @__PURE__ */ _decode(ZodRealError);
|
|
11
|
-
const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
12
|
-
const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
13
|
-
const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
14
|
-
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
15
|
-
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
16
|
-
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
17
|
-
|
|
18
|
-
export { decode, decodeAsync, encode, encodeAsync, parse, parseAsync, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync };
|