bullmq 5.5.1 → 5.5.3

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.
@@ -1,428 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ScriptLoader = exports.ScriptLoaderError = void 0;
4
- const crypto_1 = require("crypto");
5
- const path = require("path");
6
- const fs = require("fs");
7
- const util_1 = require("util");
8
- const readFile = (0, util_1.promisify)(fs.readFile);
9
- const readdir = (0, util_1.promisify)(fs.readdir);
10
- const GlobOptions = { dot: true, silent: false };
11
- const IncludeRegex = /^[-]{2,3}[ \t]*@include[ \t]+(["'])(.+?)\1[; \t\n]*$/m;
12
- const EmptyLineRegex = /^\s*[\r\n]/gm;
13
- class ScriptLoaderError extends Error {
14
- constructor(message, path, stack = [], line, position = 0) {
15
- super(message);
16
- // Ensure the name of this error is the same as the class name
17
- this.name = this.constructor.name;
18
- Error.captureStackTrace(this, this.constructor);
19
- this.includes = stack;
20
- this.line = line !== null && line !== void 0 ? line : 0;
21
- this.position = position;
22
- }
23
- }
24
- exports.ScriptLoaderError = ScriptLoaderError;
25
- const isPossiblyMappedPath = (path) => path && ['~', '<'].includes(path[0]);
26
- /**
27
- * Lua script loader with include support
28
- */
29
- class ScriptLoader {
30
- constructor() {
31
- /**
32
- * Map an alias to a path
33
- */
34
- this.pathMapper = new Map();
35
- this.clientScripts = new WeakMap();
36
- /**
37
- * Cache commands by dir
38
- */
39
- this.commandCache = new Map();
40
- this.rootPath = getPkgJsonDir();
41
- this.pathMapper.set('~', this.rootPath);
42
- this.pathMapper.set('rootDir', this.rootPath);
43
- this.pathMapper.set('base', __dirname);
44
- }
45
- /**
46
- * Add a script path mapping. Allows includes of the form "<includes>/utils.lua" where `includes` is a user
47
- * defined path
48
- * @param name - the name of the mapping. Note: do not include angle brackets
49
- * @param mappedPath - if a relative path is passed, it's relative to the *caller* of this function.
50
- * Mapped paths are also accepted, e.g. "~/server/scripts/lua" or "<base>/includes"
51
- */
52
- addPathMapping(name, mappedPath) {
53
- let resolved;
54
- if (isPossiblyMappedPath(mappedPath)) {
55
- resolved = this.resolvePath(mappedPath);
56
- }
57
- else {
58
- const caller = getCallerFile();
59
- const callerPath = path.dirname(caller);
60
- resolved = path.normalize(path.resolve(callerPath, mappedPath));
61
- }
62
- const last = resolved.length - 1;
63
- if (resolved[last] === path.sep) {
64
- resolved = resolved.substr(0, last);
65
- }
66
- this.pathMapper.set(name, resolved);
67
- }
68
- /**
69
- * Resolve the script path considering path mappings
70
- * @param scriptName - the name of the script
71
- * @param stack - the include stack, for nicer errors
72
- */
73
- resolvePath(scriptName, stack = []) {
74
- const first = scriptName[0];
75
- if (first === '~') {
76
- scriptName = path.join(this.rootPath, scriptName.substr(2));
77
- }
78
- else if (first === '<') {
79
- const p = scriptName.indexOf('>');
80
- if (p > 0) {
81
- const name = scriptName.substring(1, p);
82
- const mappedPath = this.pathMapper.get(name);
83
- if (!mappedPath) {
84
- throw new ScriptLoaderError(`No path mapping found for "${name}"`, scriptName, stack);
85
- }
86
- scriptName = path.join(mappedPath, scriptName.substring(p + 1));
87
- }
88
- }
89
- return path.normalize(scriptName);
90
- }
91
- /**
92
- * Recursively collect all scripts included in a file
93
- * @param file - the parent file
94
- * @param cache - a cache for file metadata to increase efficiency. Since a file can be included
95
- * multiple times, we make sure to load it only once.
96
- * @param stack - internal stack to prevent circular references
97
- */
98
- async resolveDependencies(file, cache, isInclude = false, stack = []) {
99
- cache = cache !== null && cache !== void 0 ? cache : new Map();
100
- if (stack.includes(file.path)) {
101
- throw new ScriptLoaderError(`circular reference: "${file.path}"`, file.path, stack);
102
- }
103
- stack.push(file.path);
104
- function findPos(content, match) {
105
- const pos = content.indexOf(match);
106
- const arr = content.slice(0, pos).split('\n');
107
- return {
108
- line: arr.length,
109
- column: arr[arr.length - 1].length + match.indexOf('@include') + 1,
110
- };
111
- }
112
- function raiseError(msg, match) {
113
- const pos = findPos(file.content, match);
114
- throw new ScriptLoaderError(msg, file.path, stack, pos.line, pos.column);
115
- }
116
- const minimatch = await import('minimatch');
117
- if (!minimatch) {
118
- console.warn('Install minimatch as dev-dependency');
119
- }
120
- const Minimatch = minimatch.Minimatch || class Empty {
121
- };
122
- const fg = await import('fast-glob');
123
- if (!fg) {
124
- console.warn('Install fast-glob as dev-dependency');
125
- }
126
- const nonOp = () => {
127
- return [''];
128
- };
129
- const glob = (fg === null || fg === void 0 ? void 0 : fg.default.glob) || nonOp;
130
- const hasMagic = (pattern) => {
131
- if (!Array.isArray(pattern)) {
132
- pattern = [pattern];
133
- }
134
- for (const p of pattern) {
135
- if (new Minimatch(p, GlobOptions).hasMagic()) {
136
- return true;
137
- }
138
- }
139
- return false;
140
- };
141
- const hasFilenamePattern = (path) => hasMagic(path);
142
- async function getFilenamesByPattern(pattern) {
143
- return glob(pattern, { dot: true });
144
- }
145
- let res;
146
- let content = file.content;
147
- while ((res = IncludeRegex.exec(content)) !== null) {
148
- const [match, , reference] = res;
149
- const includeFilename = isPossiblyMappedPath(reference)
150
- ? // mapped paths imply absolute reference
151
- this.resolvePath(ensureExt(reference), stack)
152
- : // include path is relative to the file being processed
153
- path.resolve(path.dirname(file.path), ensureExt(reference));
154
- let includePaths;
155
- if (hasFilenamePattern(includeFilename)) {
156
- const filesMatched = await getFilenamesByPattern(includeFilename);
157
- includePaths = filesMatched.map((x) => path.resolve(x));
158
- }
159
- else {
160
- includePaths = [includeFilename];
161
- }
162
- includePaths = includePaths.filter((file) => path.extname(file) === '.lua');
163
- if (includePaths.length === 0) {
164
- raiseError(`include not found: "${reference}"`, match);
165
- }
166
- const tokens = [];
167
- for (let i = 0; i < includePaths.length; i++) {
168
- const includePath = includePaths[i];
169
- const hasInclude = file.includes.find((x) => x.path === includePath);
170
- if (hasInclude) {
171
- /**
172
- * We have something like
173
- * --- \@include "a"
174
- * ...
175
- * --- \@include "a"
176
- */
177
- raiseError(`file "${reference}" already included in "${file.path}"`, match);
178
- }
179
- let includeMetadata = cache.get(includePath);
180
- let token;
181
- if (!includeMetadata) {
182
- const { name, numberOfKeys } = splitFilename(includePath);
183
- let childContent = '';
184
- try {
185
- const buf = await readFile(includePath, { flag: 'r' });
186
- childContent = buf.toString();
187
- }
188
- catch (err) {
189
- if (err.code === 'ENOENT') {
190
- raiseError(`include not found: "${reference}"`, match);
191
- }
192
- else {
193
- throw err;
194
- }
195
- }
196
- // this represents a normalized version of the path to make replacement easy
197
- token = getPathHash(includePath);
198
- includeMetadata = {
199
- name,
200
- numberOfKeys,
201
- path: includePath,
202
- content: childContent,
203
- token,
204
- includes: [],
205
- };
206
- cache.set(includePath, includeMetadata);
207
- }
208
- else {
209
- token = includeMetadata.token;
210
- }
211
- tokens.push(token);
212
- file.includes.push(includeMetadata);
213
- await this.resolveDependencies(includeMetadata, cache, true, stack);
214
- }
215
- // Replace @includes with normalized path hashes
216
- const substitution = tokens.join('\n');
217
- content = content.replace(match, substitution);
218
- }
219
- file.content = content;
220
- if (isInclude) {
221
- cache.set(file.path, file);
222
- }
223
- else {
224
- cache.set(file.name, file);
225
- }
226
- stack.pop();
227
- }
228
- /**
229
- * Parse a (top-level) lua script
230
- * @param filename - the full path to the script
231
- * @param content - the content of the script
232
- * @param cache - cache
233
- */
234
- async parseScript(filename, content, cache) {
235
- const { name, numberOfKeys } = splitFilename(filename);
236
- const meta = cache === null || cache === void 0 ? void 0 : cache.get(name);
237
- if ((meta === null || meta === void 0 ? void 0 : meta.content) === content) {
238
- return meta;
239
- }
240
- const fileInfo = {
241
- path: filename,
242
- token: getPathHash(filename),
243
- content,
244
- name,
245
- numberOfKeys,
246
- includes: [],
247
- };
248
- await this.resolveDependencies(fileInfo, cache);
249
- return fileInfo;
250
- }
251
- /**
252
- * Construct the final version of a file by interpolating its includes in dependency order.
253
- * @param file - the file whose content we want to construct
254
- * @param processed - a cache to keep track of which includes have already been processed
255
- */
256
- interpolate(file, processed) {
257
- processed = processed || new Set();
258
- let content = file.content;
259
- file.includes.forEach((child) => {
260
- const emitted = processed.has(child.path);
261
- const fragment = this.interpolate(child, processed);
262
- const replacement = emitted ? '' : fragment;
263
- if (!replacement) {
264
- content = replaceAll(content, child.token, '');
265
- }
266
- else {
267
- // replace the first instance with the dependency
268
- content = content.replace(child.token, replacement);
269
- // remove the rest
270
- content = replaceAll(content, child.token, '');
271
- }
272
- processed.add(child.path);
273
- });
274
- return content;
275
- }
276
- async loadCommand(filename, cache) {
277
- filename = path.resolve(filename);
278
- const { name: scriptName } = splitFilename(filename);
279
- let script = cache === null || cache === void 0 ? void 0 : cache.get(scriptName);
280
- if (!script) {
281
- const content = (await readFile(filename)).toString();
282
- script = await this.parseScript(filename, content, cache);
283
- }
284
- const lua = removeEmptyLines(this.interpolate(script));
285
- const { name, numberOfKeys } = script;
286
- return {
287
- name,
288
- options: { numberOfKeys: numberOfKeys, lua },
289
- };
290
- }
291
- /**
292
- * Load redis lua scripts.
293
- * The name of the script must have the following format:
294
- *
295
- * cmdName-numKeys.lua
296
- *
297
- * cmdName must be in camel case format.
298
- *
299
- * For example:
300
- * moveToFinish-3.lua
301
- *
302
- */
303
- async loadScripts(dir, cache) {
304
- dir = path.normalize(dir || __dirname);
305
- let commands = this.commandCache.get(dir);
306
- if (commands) {
307
- return commands;
308
- }
309
- const files = await readdir(dir);
310
- const luaFiles = files.filter((file) => path.extname(file) === '.lua');
311
- if (luaFiles.length === 0) {
312
- /**
313
- * To prevent unclarified runtime error "updateDelayset is not a function
314
- * @see https://github.com/OptimalBits/bull/issues/920
315
- */
316
- throw new ScriptLoaderError('No .lua files found!', dir, []);
317
- }
318
- commands = [];
319
- cache = cache !== null && cache !== void 0 ? cache : new Map();
320
- for (let i = 0; i < luaFiles.length; i++) {
321
- const file = path.join(dir, luaFiles[i]);
322
- const command = await this.loadCommand(file, cache);
323
- commands.push(command);
324
- }
325
- this.commandCache.set(dir, commands);
326
- return commands;
327
- }
328
- /**
329
- * Attach all lua scripts in a given directory to a client instance
330
- * @param client - redis client to attach script to
331
- * @param pathname - the path to the directory containing the scripts
332
- */
333
- async load(client, pathname, cache) {
334
- let paths = this.clientScripts.get(client);
335
- if (!paths) {
336
- paths = new Set();
337
- this.clientScripts.set(client, paths);
338
- }
339
- if (!paths.has(pathname)) {
340
- paths.add(pathname);
341
- const scripts = await this.loadScripts(pathname, cache !== null && cache !== void 0 ? cache : new Map());
342
- scripts.forEach((command) => {
343
- // Only define the command if not already defined
344
- if (!client[command.name]) {
345
- client.defineCommand(command.name, command.options);
346
- }
347
- });
348
- }
349
- }
350
- /**
351
- * Clears the command cache
352
- */
353
- clearCache() {
354
- this.commandCache.clear();
355
- }
356
- }
357
- exports.ScriptLoader = ScriptLoader;
358
- function ensureExt(filename, ext = 'lua') {
359
- const foundExt = path.extname(filename);
360
- if (foundExt && foundExt !== '.') {
361
- return filename;
362
- }
363
- if (ext && ext[0] !== '.') {
364
- ext = `.${ext}`;
365
- }
366
- return `${filename}${ext}`;
367
- }
368
- function splitFilename(filePath) {
369
- const longName = path.basename(filePath, '.lua');
370
- const [name, num] = longName.split('-');
371
- const numberOfKeys = num ? parseInt(num, 10) : undefined;
372
- return { name, numberOfKeys };
373
- }
374
- // Determine the project root
375
- // https://stackoverflow.com/a/18721515
376
- function getPkgJsonDir() {
377
- for (const modPath of module.paths || []) {
378
- try {
379
- const prospectivePkgJsonDir = path.dirname(modPath);
380
- fs.accessSync(modPath, fs.constants.F_OK);
381
- return prospectivePkgJsonDir;
382
- // eslint-disable-next-line no-empty
383
- }
384
- catch (e) { }
385
- }
386
- return '';
387
- }
388
- // https://stackoverflow.com/a/66842927
389
- // some dark magic here :-)
390
- // this version is preferred to the simpler version because of
391
- // https://github.com/facebook/jest/issues/5303 -
392
- // tldr: dont assume you're the only one with the doing something like this
393
- function getCallerFile() {
394
- var _a, _b, _c;
395
- const originalFunc = Error.prepareStackTrace;
396
- let callerFile = '';
397
- try {
398
- Error.prepareStackTrace = (_, stack) => stack;
399
- const sites = new Error().stack;
400
- const currentFile = (_a = sites.shift()) === null || _a === void 0 ? void 0 : _a.getFileName();
401
- while (sites.length) {
402
- callerFile = (_c = (_b = sites.shift()) === null || _b === void 0 ? void 0 : _b.getFileName()) !== null && _c !== void 0 ? _c : '';
403
- if (currentFile !== callerFile) {
404
- break;
405
- }
406
- }
407
- // eslint-disable-next-line no-empty
408
- }
409
- catch (e) {
410
- }
411
- finally {
412
- Error.prepareStackTrace = originalFunc;
413
- }
414
- return callerFile;
415
- }
416
- function sha1(data) {
417
- return (0, crypto_1.createHash)('sha1').update(data).digest('hex');
418
- }
419
- function getPathHash(normalizedPath) {
420
- return `@@${sha1(normalizedPath)}`;
421
- }
422
- function replaceAll(str, find, replace) {
423
- return str.replace(new RegExp(find, 'g'), replace);
424
- }
425
- function removeEmptyLines(str) {
426
- return str.replace(EmptyLineRegex, '');
427
- }
428
- //# sourceMappingURL=script-loader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"script-loader.js","sourceRoot":"","sources":["../../../src/commands/script-loader.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AACpC,6BAA6B;AAC7B,yBAAyB;AAEzB,+BAAiC;AAEjC,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AACxC,MAAM,OAAO,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AAEtC,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACjD,MAAM,YAAY,GAAG,uDAAuD,CAAC;AAC7E,MAAM,cAAc,GAAG,cAAc,CAAC;AAuCtC,MAAa,iBAAkB,SAAQ,KAAK;IAQ1C,YACE,OAAe,EACf,IAAY,EACZ,QAAkB,EAAE,EACpB,IAAa,EACb,QAAQ,GAAG,CAAC;QAEZ,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,8DAA8D;QAC9D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC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CAAC"}
@@ -1,4 +0,0 @@
1
- import { ScriptLoader } from './script-loader';
2
- export { ScriptMetadata, Command, ScriptLoaderError } from './script-loader';
3
- declare const scriptLoader: ScriptLoader;
4
- export { ScriptLoader, scriptLoader };
@@ -1,5 +0,0 @@
1
- import { ScriptLoader } from './script-loader';
2
- export { ScriptLoaderError } from './script-loader';
3
- const scriptLoader = new ScriptLoader();
4
- export { ScriptLoader, scriptLoader };
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAA2B,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
@@ -1,119 +0,0 @@
1
- import { RedisClient } from '../interfaces';
2
- export interface Command {
3
- name: string;
4
- options: {
5
- numberOfKeys: number;
6
- lua: string;
7
- };
8
- }
9
- /**
10
- * Script metadata
11
- */
12
- export interface ScriptMetadata {
13
- /**
14
- * Name of the script
15
- */
16
- name: string;
17
- numberOfKeys?: number;
18
- /**
19
- * The path to the script. For includes, this is the normalized path,
20
- * whereas it may not be normalized for the top-level parent
21
- */
22
- path: string;
23
- /**
24
- * The raw script content
25
- */
26
- content: string;
27
- /**
28
- * A hash of the normalized path for easy replacement in the parent
29
- */
30
- token: string;
31
- /**
32
- * Metadata on the scripts that this script includes
33
- */
34
- includes: ScriptMetadata[];
35
- }
36
- export declare class ScriptLoaderError extends Error {
37
- /**
38
- * The include stack
39
- */
40
- readonly includes: string[];
41
- readonly line: number;
42
- readonly position: number;
43
- constructor(message: string, path: string, stack?: string[], line?: number, position?: number);
44
- }
45
- /**
46
- * Lua script loader with include support
47
- */
48
- export declare class ScriptLoader {
49
- /**
50
- * Map an alias to a path
51
- */
52
- private pathMapper;
53
- private clientScripts;
54
- /**
55
- * Cache commands by dir
56
- */
57
- private commandCache;
58
- private rootPath;
59
- constructor();
60
- /**
61
- * Add a script path mapping. Allows includes of the form "<includes>/utils.lua" where `includes` is a user
62
- * defined path
63
- * @param name - the name of the mapping. Note: do not include angle brackets
64
- * @param mappedPath - if a relative path is passed, it's relative to the *caller* of this function.
65
- * Mapped paths are also accepted, e.g. "~/server/scripts/lua" or "<base>/includes"
66
- */
67
- addPathMapping(name: string, mappedPath: string): void;
68
- /**
69
- * Resolve the script path considering path mappings
70
- * @param scriptName - the name of the script
71
- * @param stack - the include stack, for nicer errors
72
- */
73
- resolvePath(scriptName: string, stack?: string[]): string;
74
- /**
75
- * Recursively collect all scripts included in a file
76
- * @param file - the parent file
77
- * @param cache - a cache for file metadata to increase efficiency. Since a file can be included
78
- * multiple times, we make sure to load it only once.
79
- * @param stack - internal stack to prevent circular references
80
- */
81
- private resolveDependencies;
82
- /**
83
- * Parse a (top-level) lua script
84
- * @param filename - the full path to the script
85
- * @param content - the content of the script
86
- * @param cache - cache
87
- */
88
- parseScript(filename: string, content: string, cache?: Map<string, ScriptMetadata>): Promise<ScriptMetadata>;
89
- /**
90
- * Construct the final version of a file by interpolating its includes in dependency order.
91
- * @param file - the file whose content we want to construct
92
- * @param processed - a cache to keep track of which includes have already been processed
93
- */
94
- interpolate(file: ScriptMetadata, processed?: Set<string>): string;
95
- loadCommand(filename: string, cache?: Map<string, ScriptMetadata>): Promise<Command>;
96
- /**
97
- * Load redis lua scripts.
98
- * The name of the script must have the following format:
99
- *
100
- * cmdName-numKeys.lua
101
- *
102
- * cmdName must be in camel case format.
103
- *
104
- * For example:
105
- * moveToFinish-3.lua
106
- *
107
- */
108
- loadScripts(dir?: string, cache?: Map<string, ScriptMetadata>): Promise<Command[]>;
109
- /**
110
- * Attach all lua scripts in a given directory to a client instance
111
- * @param client - redis client to attach script to
112
- * @param pathname - the path to the directory containing the scripts
113
- */
114
- load(client: RedisClient, pathname: string, cache?: Map<string, ScriptMetadata>): Promise<void>;
115
- /**
116
- * Clears the command cache
117
- */
118
- clearCache(): void;
119
- }