ioredis-om 5.10.2

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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1571 -0
  3. package/built/Command.d.ts +166 -0
  4. package/built/Command.js +450 -0
  5. package/built/DataHandler.d.ts +37 -0
  6. package/built/DataHandler.js +224 -0
  7. package/built/Pipeline.d.ts +31 -0
  8. package/built/Pipeline.js +342 -0
  9. package/built/Redis.d.ts +243 -0
  10. package/built/Redis.js +800 -0
  11. package/built/ScanStream.d.ts +23 -0
  12. package/built/ScanStream.js +51 -0
  13. package/built/Script.d.ts +11 -0
  14. package/built/Script.js +62 -0
  15. package/built/SubscriptionSet.d.ts +14 -0
  16. package/built/SubscriptionSet.js +41 -0
  17. package/built/autoPipelining.d.ts +8 -0
  18. package/built/autoPipelining.js +167 -0
  19. package/built/cluster/ClusterOptions.d.ts +172 -0
  20. package/built/cluster/ClusterOptions.js +22 -0
  21. package/built/cluster/ClusterSubscriber.d.ts +29 -0
  22. package/built/cluster/ClusterSubscriber.js +223 -0
  23. package/built/cluster/ClusterSubscriberGroup.d.ts +108 -0
  24. package/built/cluster/ClusterSubscriberGroup.js +373 -0
  25. package/built/cluster/ConnectionPool.d.ts +37 -0
  26. package/built/cluster/ConnectionPool.js +154 -0
  27. package/built/cluster/DelayQueue.d.ts +20 -0
  28. package/built/cluster/DelayQueue.js +53 -0
  29. package/built/cluster/ShardedSubscriber.d.ts +36 -0
  30. package/built/cluster/ShardedSubscriber.js +147 -0
  31. package/built/cluster/index.d.ts +163 -0
  32. package/built/cluster/index.js +937 -0
  33. package/built/cluster/util.d.ts +25 -0
  34. package/built/cluster/util.js +100 -0
  35. package/built/connectors/AbstractConnector.d.ts +12 -0
  36. package/built/connectors/AbstractConnector.js +26 -0
  37. package/built/connectors/ConnectorConstructor.d.ts +5 -0
  38. package/built/connectors/ConnectorConstructor.js +2 -0
  39. package/built/connectors/SentinelConnector/FailoverDetector.d.ts +11 -0
  40. package/built/connectors/SentinelConnector/FailoverDetector.js +45 -0
  41. package/built/connectors/SentinelConnector/SentinelIterator.d.ts +13 -0
  42. package/built/connectors/SentinelConnector/SentinelIterator.js +37 -0
  43. package/built/connectors/SentinelConnector/index.d.ts +72 -0
  44. package/built/connectors/SentinelConnector/index.js +305 -0
  45. package/built/connectors/SentinelConnector/types.d.ts +21 -0
  46. package/built/connectors/SentinelConnector/types.js +2 -0
  47. package/built/connectors/StandaloneConnector.d.ts +17 -0
  48. package/built/connectors/StandaloneConnector.js +69 -0
  49. package/built/connectors/index.d.ts +3 -0
  50. package/built/connectors/index.js +7 -0
  51. package/built/constants/TLSProfiles.d.ts +9 -0
  52. package/built/constants/TLSProfiles.js +149 -0
  53. package/built/errors/ClusterAllFailedError.d.ts +7 -0
  54. package/built/errors/ClusterAllFailedError.js +15 -0
  55. package/built/errors/MaxRetriesPerRequestError.d.ts +5 -0
  56. package/built/errors/MaxRetriesPerRequestError.js +14 -0
  57. package/built/errors/index.d.ts +2 -0
  58. package/built/errors/index.js +5 -0
  59. package/built/index.d.ts +44 -0
  60. package/built/index.js +62 -0
  61. package/built/redis/RedisOptions.d.ts +197 -0
  62. package/built/redis/RedisOptions.js +58 -0
  63. package/built/redis/event_handler.d.ts +4 -0
  64. package/built/redis/event_handler.js +315 -0
  65. package/built/tracing.d.ts +26 -0
  66. package/built/tracing.js +96 -0
  67. package/built/transaction.d.ts +13 -0
  68. package/built/transaction.js +100 -0
  69. package/built/types.d.ts +33 -0
  70. package/built/types.js +2 -0
  71. package/built/utils/Commander.d.ts +50 -0
  72. package/built/utils/Commander.js +117 -0
  73. package/built/utils/RedisCommander.d.ts +8950 -0
  74. package/built/utils/RedisCommander.js +7 -0
  75. package/built/utils/applyMixin.d.ts +3 -0
  76. package/built/utils/applyMixin.js +8 -0
  77. package/built/utils/argumentParsers.d.ts +14 -0
  78. package/built/utils/argumentParsers.js +74 -0
  79. package/built/utils/debug.d.ts +16 -0
  80. package/built/utils/debug.js +95 -0
  81. package/built/utils/index.d.ts +124 -0
  82. package/built/utils/index.js +332 -0
  83. package/built/utils/lodash.d.ts +4 -0
  84. package/built/utils/lodash.js +9 -0
  85. package/package.json +103 -0
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is generated by @ioredis/interface-generator.
4
+ * Don't edit it manually. Instead, run `npm run generate` to update
5
+ * this file.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ declare type Constructor = new (...args: any[]) => void;
2
+ declare function applyMixin(derivedConstructor: Constructor, mixinConstructor: Constructor): void;
3
+ export default applyMixin;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function applyMixin(derivedConstructor, mixinConstructor) {
4
+ Object.getOwnPropertyNames(mixinConstructor.prototype).forEach((name) => {
5
+ Object.defineProperty(derivedConstructor.prototype, name, Object.getOwnPropertyDescriptor(mixinConstructor.prototype, name));
6
+ });
7
+ }
8
+ exports.default = applyMixin;
@@ -0,0 +1,14 @@
1
+ import { CommandParameter } from "../types";
2
+ /**
3
+ * Parses a command parameter as seconds and converts to milliseconds.
4
+ * @param arg - The command parameter representing seconds
5
+ * @returns The value in milliseconds, 0 if value is <= 0, or undefined if parsing fails
6
+ */
7
+ export declare const parseSecondsArgument: (arg: CommandParameter | undefined) => number | undefined;
8
+ /**
9
+ * Parses the BLOCK option from Redis command arguments (e.g., XREAD, XREADGROUP).
10
+ * @param args - Array of command parameters to search for the BLOCK option
11
+ * @returns The block duration in milliseconds, 0 if duration is <= 0,
12
+ * null if BLOCK option is not found, or undefined if BLOCK is found but duration is invalid
13
+ */
14
+ export declare const parseBlockOption: (args: CommandParameter[]) => number | null | undefined;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBlockOption = exports.parseSecondsArgument = void 0;
4
+ /**
5
+ * Parses a command parameter to a number.
6
+ * @param arg - The command parameter to parse (number, string, or Buffer)
7
+ * @returns The parsed number, or undefined if parsing fails or arg is undefined
8
+ */
9
+ const parseNumberArgument = (arg) => {
10
+ if (typeof arg === "number") {
11
+ return arg;
12
+ }
13
+ if (Buffer.isBuffer(arg)) {
14
+ return parseNumberArgument(arg.toString());
15
+ }
16
+ if (typeof arg === "string") {
17
+ const value = Number(arg);
18
+ return Number.isFinite(value) ? value : undefined;
19
+ }
20
+ return undefined;
21
+ };
22
+ /**
23
+ * Parses a command parameter to a string.
24
+ * @param arg - The command parameter to parse (string or Buffer)
25
+ * @returns The parsed string, or undefined if arg is not a string/Buffer or is undefined
26
+ */
27
+ const parseStringArgument = (arg) => {
28
+ if (typeof arg === "string") {
29
+ return arg;
30
+ }
31
+ if (Buffer.isBuffer(arg)) {
32
+ return arg.toString();
33
+ }
34
+ return undefined;
35
+ };
36
+ /**
37
+ * Parses a command parameter as seconds and converts to milliseconds.
38
+ * @param arg - The command parameter representing seconds
39
+ * @returns The value in milliseconds, 0 if value is <= 0, or undefined if parsing fails
40
+ */
41
+ const parseSecondsArgument = (arg) => {
42
+ const value = parseNumberArgument(arg);
43
+ if (value === undefined) {
44
+ return undefined;
45
+ }
46
+ if (value <= 0) {
47
+ return 0;
48
+ }
49
+ return value * 1000;
50
+ };
51
+ exports.parseSecondsArgument = parseSecondsArgument;
52
+ /**
53
+ * Parses the BLOCK option from Redis command arguments (e.g., XREAD, XREADGROUP).
54
+ * @param args - Array of command parameters to search for the BLOCK option
55
+ * @returns The block duration in milliseconds, 0 if duration is <= 0,
56
+ * null if BLOCK option is not found, or undefined if BLOCK is found but duration is invalid
57
+ */
58
+ const parseBlockOption = (args) => {
59
+ for (let i = 0; i < args.length; i++) {
60
+ const token = parseStringArgument(args[i]);
61
+ if (token && token.toLowerCase() === "block") {
62
+ const duration = parseNumberArgument(args[i + 1]);
63
+ if (duration === undefined) {
64
+ return undefined;
65
+ }
66
+ if (duration <= 0) {
67
+ return 0;
68
+ }
69
+ return duration;
70
+ }
71
+ }
72
+ return null;
73
+ };
74
+ exports.parseBlockOption = parseBlockOption;
@@ -0,0 +1,16 @@
1
+ declare const MAX_ARGUMENT_LENGTH = 200;
2
+ /**
3
+ * helper function that tried to get a string value for
4
+ * arbitrary "debug" arg
5
+ */
6
+ declare function getStringValue(v: any): string | void;
7
+ /**
8
+ * helper function that redacts a string representation of a "debug" arg
9
+ */
10
+ declare function genRedactedString(str: string, maxLen: number): string;
11
+ /**
12
+ * a wrapper for the `debug` module, used to generate
13
+ * "debug functions" that trim the values in their output
14
+ */
15
+ export default function genDebugFunction(namespace: string): (...args: any[]) => void;
16
+ export { MAX_ARGUMENT_LENGTH, getStringValue, genRedactedString };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genRedactedString = exports.getStringValue = exports.MAX_ARGUMENT_LENGTH = void 0;
4
+ const debug_1 = require("debug");
5
+ const MAX_ARGUMENT_LENGTH = 200;
6
+ exports.MAX_ARGUMENT_LENGTH = MAX_ARGUMENT_LENGTH;
7
+ const NAMESPACE_PREFIX = "ioredis-om";
8
+ /**
9
+ * helper function that tried to get a string value for
10
+ * arbitrary "debug" arg
11
+ */
12
+ function getStringValue(v) {
13
+ if (v === null) {
14
+ return;
15
+ }
16
+ switch (typeof v) {
17
+ case "boolean":
18
+ return;
19
+ case "number":
20
+ return;
21
+ case "object":
22
+ if (Buffer.isBuffer(v)) {
23
+ return v.toString("hex");
24
+ }
25
+ if (Array.isArray(v)) {
26
+ return v.join(",");
27
+ }
28
+ try {
29
+ return JSON.stringify(v);
30
+ }
31
+ catch (e) {
32
+ return;
33
+ }
34
+ case "string":
35
+ return v;
36
+ }
37
+ }
38
+ exports.getStringValue = getStringValue;
39
+ /**
40
+ * helper function that redacts a string representation of a "debug" arg
41
+ */
42
+ function genRedactedString(str, maxLen) {
43
+ const { length } = str;
44
+ return length <= maxLen
45
+ ? str
46
+ : str.slice(0, maxLen) + ' ... <REDACTED full-length="' + length + '">';
47
+ }
48
+ exports.genRedactedString = genRedactedString;
49
+ /**
50
+ * a wrapper for the `debug` module, used to generate
51
+ * "debug functions" that trim the values in their output
52
+ */
53
+ function genDebugFunction(namespace) {
54
+ const fn = (0, debug_1.default)(`${NAMESPACE_PREFIX}:${namespace}`);
55
+ function wrappedDebug(...args) {
56
+ if (!fn.enabled) {
57
+ return; // no-op
58
+ }
59
+ // we skip the first arg because that is the message
60
+ for (let i = 1; i < args.length; i++) {
61
+ const str = getStringValue(args[i]);
62
+ if (typeof str === "string" && str.length > MAX_ARGUMENT_LENGTH) {
63
+ args[i] = genRedactedString(str, MAX_ARGUMENT_LENGTH);
64
+ }
65
+ }
66
+ return fn.apply(null, args);
67
+ }
68
+ Object.defineProperties(wrappedDebug, {
69
+ namespace: {
70
+ get() {
71
+ return fn.namespace;
72
+ },
73
+ },
74
+ enabled: {
75
+ get() {
76
+ return fn.enabled;
77
+ },
78
+ },
79
+ destroy: {
80
+ get() {
81
+ return fn.destroy;
82
+ },
83
+ },
84
+ log: {
85
+ get() {
86
+ return fn.log;
87
+ },
88
+ set(l) {
89
+ fn.log = l;
90
+ },
91
+ },
92
+ });
93
+ return wrappedDebug;
94
+ }
95
+ exports.default = genDebugFunction;
@@ -0,0 +1,124 @@
1
+ /// <reference types="node" />
2
+ import { defaults, noop } from "./lodash";
3
+ import { Callback } from "../types";
4
+ import Debug from "./debug";
5
+ /**
6
+ * Convert a buffer to string, supports buffer array
7
+ *
8
+ * @example
9
+ * ```js
10
+ * const input = [Buffer.from('foo'), [Buffer.from('bar')]]
11
+ * const res = convertBufferToString(input, 'utf8')
12
+ * expect(res).to.eql(['foo', ['bar']])
13
+ * ```
14
+ */
15
+ export declare function convertBufferToString(value: any, encoding?: BufferEncoding): any;
16
+ /**
17
+ * Convert a list of results to node-style
18
+ *
19
+ * @example
20
+ * ```js
21
+ * const input = ['a', 'b', new Error('c'), 'd']
22
+ * const output = exports.wrapMultiResult(input)
23
+ * expect(output).to.eql([[null, 'a'], [null, 'b'], [new Error('c')], [null, 'd'])
24
+ * ```
25
+ */
26
+ export declare function wrapMultiResult(arr: unknown[] | null): unknown[][] | null;
27
+ /**
28
+ * Detect if the argument is a int
29
+ * @example
30
+ * ```js
31
+ * > isInt('123')
32
+ * true
33
+ * > isInt('123.3')
34
+ * false
35
+ * > isInt('1x')
36
+ * false
37
+ * > isInt(123)
38
+ * true
39
+ * > isInt(true)
40
+ * false
41
+ * ```
42
+ */
43
+ export declare function isInt(value: any): value is string;
44
+ /**
45
+ * Pack an array to an Object
46
+ *
47
+ * @example
48
+ * ```js
49
+ * > packObject(['a', 'b', 'c', 'd'])
50
+ * { a: 'b', c: 'd' }
51
+ * ```
52
+ */
53
+ export declare function packObject(array: any[]): Record<string, any>;
54
+ /**
55
+ * Return a callback with timeout
56
+ */
57
+ export declare function timeout<T>(callback: Callback<T>, timeout: number): Callback<T>;
58
+ /**
59
+ * Convert an object to an array
60
+ * @example
61
+ * ```js
62
+ * > convertObjectToArray({ a: '1' })
63
+ * ['a', '1']
64
+ * ```
65
+ */
66
+ export declare function convertObjectToArray<T>(obj: Record<string, T>): (string | T)[];
67
+ /**
68
+ * Convert a map to an array
69
+ * @example
70
+ * ```js
71
+ * > convertMapToArray(new Map([[1, '2']]))
72
+ * [1, '2']
73
+ * ```
74
+ */
75
+ export declare function convertMapToArray<K, V>(map: Map<K, V>): (K | V)[];
76
+ /**
77
+ * Convert a non-string arg to a string
78
+ */
79
+ export declare function toArg(arg: any): string;
80
+ /**
81
+ * Optimize error stack
82
+ *
83
+ * @param error actually error
84
+ * @param friendlyStack the stack that more meaningful
85
+ * @param filterPath only show stacks with the specified path
86
+ */
87
+ export declare function optimizeErrorStack(error: Error, friendlyStack: string, filterPath: string): Error;
88
+ /**
89
+ * Parse the redis protocol url
90
+ */
91
+ export declare function parseURL(url: string): Record<string, unknown>;
92
+ interface TLSOptions {
93
+ port: number;
94
+ host: string;
95
+ [key: string]: any;
96
+ }
97
+ /**
98
+ * Resolve TLS profile shortcut in connection options
99
+ */
100
+ export declare function resolveTLSProfile(options: TLSOptions): TLSOptions;
101
+ /**
102
+ * Get a random element from `array`
103
+ */
104
+ export declare function sample<T>(array: T[], from?: number): T;
105
+ /**
106
+ * Shuffle the array using the Fisher-Yates Shuffle.
107
+ * This method will mutate the original array.
108
+ */
109
+ export declare function shuffle<T>(array: T[]): T[];
110
+ /**
111
+ * Error message for connection being disconnected
112
+ */
113
+ export declare const CONNECTION_CLOSED_ERROR_MSG = "Connection is closed.";
114
+ export declare function zipMap<K, V>(keys: K[], values: V[]): Map<K, V>;
115
+ /**
116
+ * Retrieves cached package metadata from package.json.
117
+ *
118
+ * @internal
119
+ * @returns {Promise<{version: string} | null>} Package metadata or null if unavailable
120
+ */
121
+ export declare function getPackageMeta(): Promise<{
122
+ version: string;
123
+ }>;
124
+ export { Debug, defaults, noop };
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noop = exports.defaults = exports.Debug = exports.getPackageMeta = exports.zipMap = exports.CONNECTION_CLOSED_ERROR_MSG = exports.shuffle = exports.sample = exports.resolveTLSProfile = exports.parseURL = exports.optimizeErrorStack = exports.toArg = exports.convertMapToArray = exports.convertObjectToArray = exports.timeout = exports.packObject = exports.isInt = exports.wrapMultiResult = exports.convertBufferToString = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const url_1 = require("url");
7
+ const lodash_1 = require("./lodash");
8
+ Object.defineProperty(exports, "defaults", { enumerable: true, get: function () { return lodash_1.defaults; } });
9
+ Object.defineProperty(exports, "noop", { enumerable: true, get: function () { return lodash_1.noop; } });
10
+ const debug_1 = require("./debug");
11
+ exports.Debug = debug_1.default;
12
+ const TLSProfiles_1 = require("../constants/TLSProfiles");
13
+ /**
14
+ * Convert a buffer to string, supports buffer array
15
+ *
16
+ * @example
17
+ * ```js
18
+ * const input = [Buffer.from('foo'), [Buffer.from('bar')]]
19
+ * const res = convertBufferToString(input, 'utf8')
20
+ * expect(res).to.eql(['foo', ['bar']])
21
+ * ```
22
+ */
23
+ function convertBufferToString(value, encoding) {
24
+ if (value instanceof Buffer) {
25
+ return value.toString(encoding);
26
+ }
27
+ if (Array.isArray(value)) {
28
+ const length = value.length;
29
+ const res = Array(length);
30
+ for (let i = 0; i < length; ++i) {
31
+ res[i] =
32
+ value[i] instanceof Buffer && encoding === "utf8"
33
+ ? value[i].toString()
34
+ : convertBufferToString(value[i], encoding);
35
+ }
36
+ return res;
37
+ }
38
+ return value;
39
+ }
40
+ exports.convertBufferToString = convertBufferToString;
41
+ /**
42
+ * Convert a list of results to node-style
43
+ *
44
+ * @example
45
+ * ```js
46
+ * const input = ['a', 'b', new Error('c'), 'd']
47
+ * const output = exports.wrapMultiResult(input)
48
+ * expect(output).to.eql([[null, 'a'], [null, 'b'], [new Error('c')], [null, 'd'])
49
+ * ```
50
+ */
51
+ function wrapMultiResult(arr) {
52
+ // When using WATCH/EXEC transactions, the EXEC will return
53
+ // a null instead of an array
54
+ if (!arr) {
55
+ return null;
56
+ }
57
+ const result = [];
58
+ const length = arr.length;
59
+ for (let i = 0; i < length; ++i) {
60
+ const item = arr[i];
61
+ if (item instanceof Error) {
62
+ result.push([item]);
63
+ }
64
+ else {
65
+ result.push([null, item]);
66
+ }
67
+ }
68
+ return result;
69
+ }
70
+ exports.wrapMultiResult = wrapMultiResult;
71
+ /**
72
+ * Detect if the argument is a int
73
+ * @example
74
+ * ```js
75
+ * > isInt('123')
76
+ * true
77
+ * > isInt('123.3')
78
+ * false
79
+ * > isInt('1x')
80
+ * false
81
+ * > isInt(123)
82
+ * true
83
+ * > isInt(true)
84
+ * false
85
+ * ```
86
+ */
87
+ function isInt(value) {
88
+ const x = parseFloat(value);
89
+ return !isNaN(value) && (x | 0) === x;
90
+ }
91
+ exports.isInt = isInt;
92
+ /**
93
+ * Pack an array to an Object
94
+ *
95
+ * @example
96
+ * ```js
97
+ * > packObject(['a', 'b', 'c', 'd'])
98
+ * { a: 'b', c: 'd' }
99
+ * ```
100
+ */
101
+ function packObject(array) {
102
+ const result = {};
103
+ const length = array.length;
104
+ for (let i = 1; i < length; i += 2) {
105
+ result[array[i - 1]] = array[i];
106
+ }
107
+ return result;
108
+ }
109
+ exports.packObject = packObject;
110
+ /**
111
+ * Return a callback with timeout
112
+ */
113
+ function timeout(callback, timeout) {
114
+ let timer = null;
115
+ const run = function () {
116
+ if (timer) {
117
+ clearTimeout(timer);
118
+ timer = null;
119
+ callback.apply(this, arguments);
120
+ }
121
+ };
122
+ timer = setTimeout(run, timeout, new Error("timeout"));
123
+ return run;
124
+ }
125
+ exports.timeout = timeout;
126
+ /**
127
+ * Convert an object to an array
128
+ * @example
129
+ * ```js
130
+ * > convertObjectToArray({ a: '1' })
131
+ * ['a', '1']
132
+ * ```
133
+ */
134
+ function convertObjectToArray(obj) {
135
+ const result = [];
136
+ const keys = Object.keys(obj); // Object.entries requires node 7+
137
+ for (let i = 0, l = keys.length; i < l; i++) {
138
+ result.push(keys[i], obj[keys[i]]);
139
+ }
140
+ return result;
141
+ }
142
+ exports.convertObjectToArray = convertObjectToArray;
143
+ /**
144
+ * Convert a map to an array
145
+ * @example
146
+ * ```js
147
+ * > convertMapToArray(new Map([[1, '2']]))
148
+ * [1, '2']
149
+ * ```
150
+ */
151
+ function convertMapToArray(map) {
152
+ const result = [];
153
+ let pos = 0;
154
+ map.forEach(function (value, key) {
155
+ result[pos] = key;
156
+ result[pos + 1] = value;
157
+ pos += 2;
158
+ });
159
+ return result;
160
+ }
161
+ exports.convertMapToArray = convertMapToArray;
162
+ /**
163
+ * Convert a non-string arg to a string
164
+ */
165
+ function toArg(arg) {
166
+ if (arg === null || typeof arg === "undefined") {
167
+ return "";
168
+ }
169
+ return String(arg);
170
+ }
171
+ exports.toArg = toArg;
172
+ /**
173
+ * Optimize error stack
174
+ *
175
+ * @param error actually error
176
+ * @param friendlyStack the stack that more meaningful
177
+ * @param filterPath only show stacks with the specified path
178
+ */
179
+ function optimizeErrorStack(error, friendlyStack, filterPath) {
180
+ const stacks = friendlyStack.split("\n");
181
+ let lines = "";
182
+ let i;
183
+ for (i = 1; i < stacks.length; ++i) {
184
+ if (stacks[i].indexOf(filterPath) === -1) {
185
+ break;
186
+ }
187
+ }
188
+ for (let j = i; j < stacks.length; ++j) {
189
+ lines += "\n" + stacks[j];
190
+ }
191
+ if (error.stack) {
192
+ const pos = error.stack.indexOf("\n");
193
+ error.stack = error.stack.slice(0, pos) + lines;
194
+ }
195
+ return error;
196
+ }
197
+ exports.optimizeErrorStack = optimizeErrorStack;
198
+ /**
199
+ * Parse the redis protocol url
200
+ */
201
+ function parseURL(url) {
202
+ if (isInt(url)) {
203
+ return { port: url };
204
+ }
205
+ let parsed = (0, url_1.parse)(url, true, true);
206
+ if (!parsed.slashes && url[0] !== "/") {
207
+ url = "//" + url;
208
+ parsed = (0, url_1.parse)(url, true, true);
209
+ }
210
+ const options = parsed.query || {};
211
+ const result = {};
212
+ if (parsed.auth) {
213
+ const index = parsed.auth.indexOf(":");
214
+ result.username = index === -1 ? parsed.auth : parsed.auth.slice(0, index);
215
+ result.password = index === -1 ? "" : parsed.auth.slice(index + 1);
216
+ }
217
+ if (parsed.pathname) {
218
+ if (parsed.protocol === "redis:" || parsed.protocol === "rediss:") {
219
+ if (parsed.pathname.length > 1) {
220
+ result.db = parsed.pathname.slice(1);
221
+ }
222
+ }
223
+ else {
224
+ result.path = parsed.pathname;
225
+ }
226
+ }
227
+ if (parsed.host) {
228
+ result.host = parsed.hostname;
229
+ }
230
+ if (parsed.port) {
231
+ result.port = parsed.port;
232
+ }
233
+ if (typeof options.family === "string") {
234
+ const intFamily = Number.parseInt(options.family, 10);
235
+ if (!Number.isNaN(intFamily)) {
236
+ result.family = intFamily;
237
+ }
238
+ }
239
+ (0, lodash_1.defaults)(result, options);
240
+ return result;
241
+ }
242
+ exports.parseURL = parseURL;
243
+ /**
244
+ * Resolve TLS profile shortcut in connection options
245
+ */
246
+ function resolveTLSProfile(options) {
247
+ let tls = options === null || options === void 0 ? void 0 : options.tls;
248
+ if (typeof tls === "string")
249
+ tls = { profile: tls };
250
+ const profile = TLSProfiles_1.default[tls === null || tls === void 0 ? void 0 : tls.profile];
251
+ if (profile) {
252
+ tls = Object.assign({}, profile, tls);
253
+ delete tls.profile;
254
+ options = Object.assign({}, options, { tls });
255
+ }
256
+ return options;
257
+ }
258
+ exports.resolveTLSProfile = resolveTLSProfile;
259
+ /**
260
+ * Get a random element from `array`
261
+ */
262
+ function sample(array, from = 0) {
263
+ const length = array.length;
264
+ if (from >= length) {
265
+ return null;
266
+ }
267
+ return array[from + Math.floor(Math.random() * (length - from))];
268
+ }
269
+ exports.sample = sample;
270
+ /**
271
+ * Shuffle the array using the Fisher-Yates Shuffle.
272
+ * This method will mutate the original array.
273
+ */
274
+ function shuffle(array) {
275
+ let counter = array.length;
276
+ // While there are elements in the array
277
+ while (counter > 0) {
278
+ // Pick a random index
279
+ const index = Math.floor(Math.random() * counter);
280
+ // Decrease counter by 1
281
+ counter--;
282
+ // And swap the last element with it
283
+ [array[counter], array[index]] = [array[index], array[counter]];
284
+ }
285
+ return array;
286
+ }
287
+ exports.shuffle = shuffle;
288
+ /**
289
+ * Error message for connection being disconnected
290
+ */
291
+ exports.CONNECTION_CLOSED_ERROR_MSG = "Connection is closed.";
292
+ function zipMap(keys, values) {
293
+ const map = new Map();
294
+ keys.forEach((key, index) => {
295
+ map.set(key, values[index]);
296
+ });
297
+ return map;
298
+ }
299
+ exports.zipMap = zipMap;
300
+ /**
301
+ * Memoized package metadata to avoid repeated file system reads.
302
+ *
303
+ * @internal
304
+ */
305
+ let cachedPackageMeta = null;
306
+ /**
307
+ * Retrieves cached package metadata from package.json.
308
+ *
309
+ * @internal
310
+ * @returns {Promise<{version: string} | null>} Package metadata or null if unavailable
311
+ */
312
+ async function getPackageMeta() {
313
+ if (cachedPackageMeta) {
314
+ return cachedPackageMeta;
315
+ }
316
+ try {
317
+ const filePath = (0, path_1.resolve)(__dirname, "..", "..", "package.json");
318
+ const data = await fs_1.promises.readFile(filePath, "utf8");
319
+ const parsed = JSON.parse(data);
320
+ cachedPackageMeta = {
321
+ version: parsed.version,
322
+ };
323
+ return cachedPackageMeta;
324
+ }
325
+ catch (err) {
326
+ cachedPackageMeta = {
327
+ version: "error-fetching-version",
328
+ };
329
+ return cachedPackageMeta;
330
+ }
331
+ }
332
+ exports.getPackageMeta = getPackageMeta;
@@ -0,0 +1,4 @@
1
+ import defaults = require("lodash.defaults");
2
+ import isArguments = require("lodash.isarguments");
3
+ export declare function noop(): void;
4
+ export { defaults, isArguments };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isArguments = exports.defaults = exports.noop = void 0;
4
+ const defaults = require("lodash.defaults");
5
+ exports.defaults = defaults;
6
+ const isArguments = require("lodash.isarguments");
7
+ exports.isArguments = isArguments;
8
+ function noop() { }
9
+ exports.noop = noop;