@medusajs/locking-redis 0.0.2-preview-20241015160245
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/index.d.ts +4 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +31 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/services/redis-lock.d.ts +42 -0
- package/dist/services/redis-lock.d.ts.map +1 -0
- package/dist/services/redis-lock.js +186 -0
- package/dist/services/redis-lock.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAOA,wBAGE"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const utils_1 = require("@medusajs/framework/utils");
|
7
|
+
const loaders_1 = __importDefault(require("./loaders"));
|
8
|
+
const redis_lock_1 = require("./services/redis-lock");
|
9
|
+
const services = [redis_lock_1.RedisLockingProvider];
|
10
|
+
const loaders = [loaders_1.default];
|
11
|
+
exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.LOCKING, {
|
12
|
+
services,
|
13
|
+
loaders,
|
14
|
+
});
|
15
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmE;AACnE,wDAA8B;AAC9B,sDAA4D;AAE5D,MAAM,QAAQ,GAAG,CAAC,iCAAoB,CAAC,CAAA;AACvC,MAAM,OAAO,GAAG,CAAC,iBAAM,CAAC,CAAA;AAExB,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,OAAO,EAAE;IAC7C,QAAQ;IACR,OAAO;CACR,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;yEAUpD,qBAAqB,KAAG,OAAO,CAAC,IAAI,CAAC;AALxC,wBAkCC"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const utils_1 = require("@medusajs/framework/utils");
|
7
|
+
const awilix_1 = require("awilix");
|
8
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
9
|
+
exports.default = async ({ container, logger, options, moduleOptions, }) => {
|
10
|
+
const { redisUrl, redisOptions, namespace } = options;
|
11
|
+
if (!redisUrl) {
|
12
|
+
throw Error(`No "redisUrl" provided in "${utils_1.Modules.LOCKING}" module, "locking-redis" provider options. It is required for the "locking-redis" Module provider.`);
|
13
|
+
}
|
14
|
+
const connection = new ioredis_1.default(redisUrl, {
|
15
|
+
// Lazy connect to properly handle connection errors
|
16
|
+
lazyConnect: true,
|
17
|
+
...(redisOptions ?? {}),
|
18
|
+
});
|
19
|
+
try {
|
20
|
+
await connection.connect();
|
21
|
+
logger?.info(`Connection to Redis in "locking-redis" provider established`);
|
22
|
+
}
|
23
|
+
catch (err) {
|
24
|
+
logger?.error(`An error occurred while connecting to Redis in provider "locking-redis": ${err}`);
|
25
|
+
}
|
26
|
+
container.register({
|
27
|
+
redisClient: (0, awilix_1.asValue)(connection),
|
28
|
+
prefix: (0, awilix_1.asValue)(namespace ?? "medusa_lock:"),
|
29
|
+
});
|
30
|
+
};
|
31
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmD;AAGnD,mCAAgC;AAChC,sDAA2B;AAE3B,kBAAe,KAAK,EAAE,EACpB,SAAS,EACT,MAAM,EACN,OAAO,EACP,aAAa,GACS,EAAiB,EAAE;IACzC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,GACzC,OAAkC,CAAA;IAEpC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,KAAK,CACT,8BAA8B,eAAO,CAAC,OAAO,qGAAqG,CACnJ,CAAA;IACH,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;QACrC,oDAAoD;QACpD,WAAW,EAAE,IAAI;QACjB,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;KACxB,CAAC,CAAA;IAEF,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;QAC1B,MAAM,EAAE,IAAI,CAAC,6DAA6D,CAAC,CAAA;IAC7E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,EAAE,KAAK,CACX,4EAA4E,GAAG,EAAE,CAClF,CAAA;IACH,CAAC;IAED,SAAS,CAAC,QAAQ,CAAC;QACjB,WAAW,EAAE,IAAA,gBAAO,EAAC,UAAU,CAAC;QAChC,MAAM,EAAE,IAAA,gBAAO,EAAC,SAAS,IAAI,cAAc,CAAC;KAC7C,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { ILockingProvider } from "@medusajs/types";
|
2
|
+
import { RedisCacheModuleOptions } from "../types";
|
3
|
+
import { Redis } from "ioredis";
|
4
|
+
export declare class RedisLockingProvider implements ILockingProvider {
|
5
|
+
static identifier: string;
|
6
|
+
protected redisClient: Redis & {
|
7
|
+
acquireLock: (key: string, ownerId: string, ttl: number, awaitQueue?: boolean) => Promise<number>;
|
8
|
+
releaseLock: (key: string, ownerId: string) => Promise<number>;
|
9
|
+
};
|
10
|
+
protected keyNamePrefix: string;
|
11
|
+
protected waitLockingTimeout: number;
|
12
|
+
protected defaultRetryInterval: number;
|
13
|
+
protected maximumRetryInterval: number;
|
14
|
+
constructor({ redisClient, prefix }: {
|
15
|
+
redisClient: any;
|
16
|
+
prefix: any;
|
17
|
+
}, options: RedisCacheModuleOptions);
|
18
|
+
private getKeyName;
|
19
|
+
execute<T>(keys: string | string[], job: () => Promise<T>, args?: {
|
20
|
+
timeout?: number;
|
21
|
+
}): Promise<T>;
|
22
|
+
acquire(keys: string | string[], args?: {
|
23
|
+
ownerId?: string;
|
24
|
+
expire?: number;
|
25
|
+
awaitQueue?: boolean;
|
26
|
+
}): Promise<void>;
|
27
|
+
acquire_(keys: string | string[], args?: {
|
28
|
+
ownerId?: string;
|
29
|
+
expire?: number;
|
30
|
+
awaitQueue?: boolean;
|
31
|
+
}, cancellationToken?: {
|
32
|
+
cancelled: boolean;
|
33
|
+
}): Promise<void>;
|
34
|
+
release(keys: string | string[], args?: {
|
35
|
+
ownerId?: string | null;
|
36
|
+
}): Promise<boolean>;
|
37
|
+
releaseAll(args?: {
|
38
|
+
ownerId?: string | null;
|
39
|
+
}): Promise<void>;
|
40
|
+
private getTimeout;
|
41
|
+
}
|
42
|
+
//# sourceMappingURL=redis-lock.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redis-lock.d.ts","sourceRoot":"","sources":["../../src/services/redis-lock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAA;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AE,MAAM,CAAA;QAChB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,EACD,iBAAiB,CAAC,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GACzC,OAAO,CAAC,IAAI,CAAC;IAqDV,OAAO,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACxB,GACA,OAAO,CAAC,OAAO,CAAC;IAeb,UAAU,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAwCrD,UAAU;CAUzB"}
|
@@ -0,0 +1,186 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.RedisLockingProvider = void 0;
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
|
+
const promises_1 = require("node:timers/promises");
|
6
|
+
class RedisLockingProvider {
|
7
|
+
constructor({ redisClient, prefix }, options) {
|
8
|
+
this.waitLockingTimeout = 5;
|
9
|
+
this.defaultRetryInterval = 5;
|
10
|
+
this.maximumRetryInterval = 200;
|
11
|
+
this.redisClient = redisClient;
|
12
|
+
this.keyNamePrefix = prefix ?? "medusa_lock:";
|
13
|
+
if (!isNaN(+options?.waitLockingTimeout)) {
|
14
|
+
this.waitLockingTimeout = +options.waitLockingTimeout;
|
15
|
+
}
|
16
|
+
if (!isNaN(+options?.defaultRetryInterval)) {
|
17
|
+
this.defaultRetryInterval = +options.defaultRetryInterval;
|
18
|
+
}
|
19
|
+
if (!isNaN(+options?.maximumRetryInterval)) {
|
20
|
+
this.maximumRetryInterval = +options.maximumRetryInterval;
|
21
|
+
}
|
22
|
+
// Define the custom command for acquiring locks
|
23
|
+
this.redisClient.defineCommand("acquireLock", {
|
24
|
+
numberOfKeys: 1,
|
25
|
+
lua: `
|
26
|
+
local key = KEYS[1]
|
27
|
+
local ownerId = ARGV[1]
|
28
|
+
local ttl = tonumber(ARGV[2])
|
29
|
+
local awaitQueue = ARGV[3] == 'true'
|
30
|
+
|
31
|
+
local setArgs = {key, ownerId, 'NX'}
|
32
|
+
if ttl > 0 then
|
33
|
+
table.insert(setArgs, 'EX')
|
34
|
+
table.insert(setArgs, ttl)
|
35
|
+
end
|
36
|
+
|
37
|
+
local setResult = redis.call('SET', unpack(setArgs))
|
38
|
+
|
39
|
+
if setResult then
|
40
|
+
return 1
|
41
|
+
elseif not awaitQueue then
|
42
|
+
-- Key already exists; retrieve the current ownerId
|
43
|
+
local currentOwnerId = redis.call('GET', key)
|
44
|
+
if currentOwnerId == '*' then
|
45
|
+
return 0
|
46
|
+
elseif currentOwnerId == ownerId then
|
47
|
+
setArgs = {key, ownerId, 'XX'}
|
48
|
+
if ttl > 0 then
|
49
|
+
table.insert(setArgs, 'EX')
|
50
|
+
table.insert(setArgs, ttl)
|
51
|
+
end
|
52
|
+
redis.call('SET', unpack(setArgs))
|
53
|
+
return 1
|
54
|
+
else
|
55
|
+
return 0
|
56
|
+
end
|
57
|
+
else
|
58
|
+
return 0
|
59
|
+
end
|
60
|
+
|
61
|
+
`,
|
62
|
+
});
|
63
|
+
// Define the custom command for releasing locks
|
64
|
+
this.redisClient.defineCommand("releaseLock", {
|
65
|
+
numberOfKeys: 1,
|
66
|
+
lua: `
|
67
|
+
local key = KEYS[1]
|
68
|
+
local ownerId = ARGV[1]
|
69
|
+
|
70
|
+
if redis.call('GET', key) == ownerId then
|
71
|
+
return redis.call('DEL', key)
|
72
|
+
else
|
73
|
+
return 0
|
74
|
+
end
|
75
|
+
`,
|
76
|
+
});
|
77
|
+
}
|
78
|
+
getKeyName(key) {
|
79
|
+
return `${this.keyNamePrefix}${key}`;
|
80
|
+
}
|
81
|
+
async execute(keys, job, args) {
|
82
|
+
const timeout = Math.max(args?.timeout ?? this.waitLockingTimeout, 1);
|
83
|
+
const timeoutSeconds = Number.isNaN(timeout) ? 1 : timeout;
|
84
|
+
const cancellationToken = { cancelled: false };
|
85
|
+
const promises = [];
|
86
|
+
if (timeoutSeconds > 0) {
|
87
|
+
promises.push(this.getTimeout(timeoutSeconds, cancellationToken));
|
88
|
+
}
|
89
|
+
promises.push(this.acquire_(keys, {
|
90
|
+
awaitQueue: true,
|
91
|
+
expire: args?.timeout ? timeoutSeconds : 0,
|
92
|
+
}, cancellationToken));
|
93
|
+
await Promise.race(promises);
|
94
|
+
try {
|
95
|
+
return await job();
|
96
|
+
}
|
97
|
+
finally {
|
98
|
+
await this.release(keys);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
async acquire(keys, args) {
|
102
|
+
return this.acquire_(keys, args);
|
103
|
+
}
|
104
|
+
async acquire_(keys, args, cancellationToken) {
|
105
|
+
keys = Array.isArray(keys) ? keys : [keys];
|
106
|
+
const timeout = Math.max(args?.expire ?? this.waitLockingTimeout, 1);
|
107
|
+
const timeoutSeconds = Number.isNaN(timeout) ? 1 : timeout;
|
108
|
+
let retryTimes = 0;
|
109
|
+
const ownerId = args?.ownerId ?? "*";
|
110
|
+
const awaitQueue = args?.awaitQueue ?? false;
|
111
|
+
const acquirePromises = keys.map(async (key) => {
|
112
|
+
const errMessage = `Failed to acquire lock for key "${key}"`;
|
113
|
+
const keyName = this.getKeyName(key);
|
114
|
+
const acquireLock = async () => {
|
115
|
+
while (true) {
|
116
|
+
if (cancellationToken?.cancelled) {
|
117
|
+
throw new Error(errMessage);
|
118
|
+
}
|
119
|
+
const result = await this.redisClient.acquireLock(keyName, ownerId, args?.expire ? timeoutSeconds : 0, awaitQueue);
|
120
|
+
if (result === 1) {
|
121
|
+
break;
|
122
|
+
}
|
123
|
+
else {
|
124
|
+
if (awaitQueue) {
|
125
|
+
// Wait for a short period before retrying
|
126
|
+
await (0, promises_1.setTimeout)(Math.min(this.defaultRetryInterval +
|
127
|
+
(retryTimes / 10) * this.defaultRetryInterval, this.maximumRetryInterval));
|
128
|
+
retryTimes++;
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
throw new Error(errMessage);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
};
|
136
|
+
await acquireLock();
|
137
|
+
});
|
138
|
+
await (0, utils_1.promiseAll)(acquirePromises);
|
139
|
+
}
|
140
|
+
async release(keys, args) {
|
141
|
+
const ownerId = args?.ownerId ?? "*";
|
142
|
+
keys = Array.isArray(keys) ? keys : [keys];
|
143
|
+
const releasePromises = keys.map(async (key) => {
|
144
|
+
const keyName = this.getKeyName(key);
|
145
|
+
const result = await this.redisClient.releaseLock(keyName, ownerId);
|
146
|
+
return result === 1;
|
147
|
+
});
|
148
|
+
const results = await (0, utils_1.promiseAll)(releasePromises);
|
149
|
+
return results.every((released) => released);
|
150
|
+
}
|
151
|
+
async releaseAll(args) {
|
152
|
+
const ownerId = args?.ownerId ?? "*";
|
153
|
+
const pattern = `${this.keyNamePrefix}*`;
|
154
|
+
let cursor = "0";
|
155
|
+
do {
|
156
|
+
const result = await this.redisClient.scan(cursor, "MATCH", pattern, "COUNT", 100);
|
157
|
+
cursor = result[0];
|
158
|
+
const keys = result[1];
|
159
|
+
if (keys.length > 0) {
|
160
|
+
const pipeline = this.redisClient.pipeline();
|
161
|
+
keys.forEach((key) => {
|
162
|
+
pipeline.get(key);
|
163
|
+
});
|
164
|
+
const currentOwners = await pipeline.exec();
|
165
|
+
const deletePipeline = this.redisClient.pipeline();
|
166
|
+
keys.forEach((key, idx) => {
|
167
|
+
const currentOwner = currentOwners?.[idx]?.[1];
|
168
|
+
if (currentOwner === ownerId) {
|
169
|
+
deletePipeline.del(key);
|
170
|
+
}
|
171
|
+
});
|
172
|
+
await deletePipeline.exec();
|
173
|
+
}
|
174
|
+
} while (cursor !== "0");
|
175
|
+
}
|
176
|
+
async getTimeout(seconds, cancellationToken) {
|
177
|
+
return new Promise(async (_, reject) => {
|
178
|
+
await (0, promises_1.setTimeout)(seconds * 1000);
|
179
|
+
cancellationToken.cancelled = true;
|
180
|
+
reject(new Error("Timed-out acquiring lock."));
|
181
|
+
});
|
182
|
+
}
|
183
|
+
}
|
184
|
+
exports.RedisLockingProvider = RedisLockingProvider;
|
185
|
+
RedisLockingProvider.identifier = "locking-redis";
|
186
|
+
//# sourceMappingURL=redis-lock.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redis-lock.js","sourceRoot":"","sources":["../../src/services/redis-lock.ts"],"names":[],"mappings":";;;AAAA,qDAAsD;AAItD,mDAAiD;AAEjD,MAAa,oBAAoB;IAiB/B,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,OAAgC;QAJ3D,uBAAkB,GAAW,CAAC,CAAA;QAC9B,yBAAoB,GAAW,CAAC,CAAA;QAChC,yBAAoB,GAAW,GAAG,CAAA;QAG1C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,IAAI,cAAc,CAAA;QAE7C,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,kBAAmB,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,kBAAkB,GAAG,CAAC,OAAO,CAAC,kBAAmB,CAAA;QACxD,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,oBAAqB,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,oBAAoB,GAAG,CAAC,OAAO,CAAC,oBAAqB,CAAA;QAC5D,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,oBAAqB,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,oBAAoB,GAAG,CAAC,OAAO,CAAC,oBAAqB,CAAA;QAC5D,CAAC;QAED,gDAAgD;QAChD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,aAAa,EAAE;YAC5C,YAAY,EAAE,CAAC;YACf,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAE,CAAA;YAC7B,CAAC;QACH,CAAC,QAAQ,MAAM,KAAK,GAAG,EAAC;IAC1B,CAAC;IAEO,KAAK,CAAC,UAAU,CACtB,OAAe,EACf,iBAAyC;QAEzC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,IAAA,qBAAU,EAAC,OAAO,GAAG,IAAI,CAAC,CAAA;YAChC,iBAAiB,CAAC,SAAS,GAAG,IAAI,CAAA;YAClC,MAAM,CAAC,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACJ,CAAC;;AAhRH,oDAiRC;AAhRQ,+BAAU,GAAG,eAAe,AAAlB,CAAkB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"root":["../src/index.ts","../src/loaders/index.ts","../src/services/redis-lock.ts","../src/types/index.ts"],"version":"5.6.2"}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { RedisOptions } from "ioredis";
|
2
|
+
/**
|
3
|
+
* Module config type
|
4
|
+
*/
|
5
|
+
export type RedisCacheModuleOptions = {
|
6
|
+
/**
|
7
|
+
* Time to keep data in cache (in seconds)
|
8
|
+
*/
|
9
|
+
ttl?: number;
|
10
|
+
/**
|
11
|
+
* Redis connection string
|
12
|
+
*/
|
13
|
+
redisUrl?: string;
|
14
|
+
/**
|
15
|
+
* Redis client options
|
16
|
+
*/
|
17
|
+
redisOptions?: RedisOptions;
|
18
|
+
/**
|
19
|
+
* Prefix for event keys
|
20
|
+
* @default `medusa_lock:`
|
21
|
+
*/
|
22
|
+
namespace?: string;
|
23
|
+
/**
|
24
|
+
* Time to wait for lock (in seconds)
|
25
|
+
* @default 5
|
26
|
+
*/
|
27
|
+
waitLockingTimeout?: number;
|
28
|
+
/**
|
29
|
+
* Default retry interval (in milliseconds)
|
30
|
+
* @default 5
|
31
|
+
*/
|
32
|
+
defaultRetryInterval?: number;
|
33
|
+
/**
|
34
|
+
* Maximum retry interval (in milliseconds)
|
35
|
+
* @default 200
|
36
|
+
*/
|
37
|
+
maximumRetryInterval?: number;
|
38
|
+
};
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAA;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAE7B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
{
|
2
|
+
"name": "@medusajs/locking-redis",
|
3
|
+
"version": "0.0.2-preview-20241015160245",
|
4
|
+
"description": "Redis Lock for Medusa",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "https://github.com/medusajs/medusa",
|
9
|
+
"directory": "packages/locking-redis"
|
10
|
+
},
|
11
|
+
"files": [
|
12
|
+
"dist",
|
13
|
+
"!dist/**/__tests__",
|
14
|
+
"!dist/**/__mocks__",
|
15
|
+
"!dist/**/__fixtures__"
|
16
|
+
],
|
17
|
+
"engines": {
|
18
|
+
"node": ">=20"
|
19
|
+
},
|
20
|
+
"author": "Medusa",
|
21
|
+
"license": "MIT",
|
22
|
+
"devDependencies": {
|
23
|
+
"@medusajs/framework": "0.0.2-preview-20241015160245",
|
24
|
+
"@swc/core": "^1.7.28",
|
25
|
+
"@swc/jest": "^0.2.36",
|
26
|
+
"jest": "^29.7.0",
|
27
|
+
"rimraf": "^5.0.1",
|
28
|
+
"typescript": "^5.6.2"
|
29
|
+
},
|
30
|
+
"peerDependencies": {
|
31
|
+
"@medusajs/framework": "0.0.2-preview-20241015160245"
|
32
|
+
},
|
33
|
+
"dependencies": {
|
34
|
+
"ioredis": "^5.4.1"
|
35
|
+
},
|
36
|
+
"scripts": {
|
37
|
+
"watch": "tsc --build --watch",
|
38
|
+
"watch:test": "tsc --build tsconfig.spec.json --watch",
|
39
|
+
"resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json",
|
40
|
+
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
41
|
+
"test": "jest --passWithNoTests src",
|
42
|
+
"test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.spec.ts"
|
43
|
+
},
|
44
|
+
"keywords": [
|
45
|
+
"medusa-providers",
|
46
|
+
"medusa-providers-locking"
|
47
|
+
]
|
48
|
+
}
|