lakutata 2.0.66 → 2.0.68

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 (91) hide show
  1. package/com/cacher.cjs +1 -1
  2. package/com/cacher.mjs +1 -1
  3. package/com/entrypoint.cjs +3 -1
  4. package/com/entrypoint.mjs +3 -1
  5. package/decorator/ctrl.cjs +3 -1
  6. package/decorator/ctrl.mjs +3 -1
  7. package/helper.cjs +24 -18
  8. package/helper.d.ts +128 -2
  9. package/helper.mjs +6 -2
  10. package/lakutata.cjs +3 -1
  11. package/lakutata.d.ts +1 -1
  12. package/lakutata.mjs +3 -1
  13. package/package.json +1 -1
  14. package/src/components/cacher/Cacher.cjs +1 -1
  15. package/src/components/cacher/Cacher.mjs +1 -1
  16. package/src/components/cacher/adapters/CreateFileCacheAdapter.cjs +1 -1
  17. package/src/components/cacher/adapters/CreateFileCacheAdapter.mjs +1 -1
  18. package/src/components/cacher/adapters/CreateMemcacheCacheAdapter.cjs +2 -2
  19. package/src/components/cacher/adapters/CreateMemcacheCacheAdapter.mjs +2 -2
  20. package/src/components/cacher/adapters/CreateMongoCacheAdapter.cjs +2 -2
  21. package/src/components/cacher/adapters/CreateMongoCacheAdapter.mjs +2 -2
  22. package/src/components/cacher/adapters/CreateMysqlCacheAdapter.cjs +2 -2
  23. package/src/components/cacher/adapters/CreateMysqlCacheAdapter.mjs +2 -2
  24. package/src/components/cacher/adapters/CreatePostgresCacheAdapter.cjs +2 -2
  25. package/src/components/cacher/adapters/CreatePostgresCacheAdapter.mjs +2 -2
  26. package/src/components/cacher/adapters/CreateRedisCacheAdapter.cjs +2 -2
  27. package/src/components/cacher/adapters/CreateRedisCacheAdapter.mjs +2 -2
  28. package/src/components/cacher/adapters/CreateSqliteCacheAdapter.cjs +2 -2
  29. package/src/components/cacher/adapters/CreateSqliteCacheAdapter.mjs +2 -2
  30. package/src/components/entrypoint/Entrypoint.cjs +6 -1
  31. package/src/components/entrypoint/Entrypoint.mjs +6 -1
  32. package/src/decorators/ctrl/CLIAction.cjs +7 -5
  33. package/src/decorators/ctrl/CLIAction.mjs +3 -1
  34. package/src/decorators/ctrl/HTTPAction.cjs +8 -6
  35. package/src/decorators/ctrl/HTTPAction.mjs +3 -1
  36. package/src/decorators/ctrl/ServiceAction.cjs +3 -1
  37. package/src/decorators/ctrl/ServiceAction.mjs +7 -5
  38. package/src/decorators/ctrl/http/DELETE.cjs +3 -1
  39. package/src/decorators/ctrl/http/DELETE.mjs +3 -1
  40. package/src/decorators/ctrl/http/GET.cjs +3 -1
  41. package/src/decorators/ctrl/http/GET.mjs +3 -1
  42. package/src/decorators/ctrl/http/HEAD.cjs +3 -1
  43. package/src/decorators/ctrl/http/HEAD.mjs +3 -1
  44. package/src/decorators/ctrl/http/OPTIONS.cjs +3 -1
  45. package/src/decorators/ctrl/http/OPTIONS.mjs +3 -1
  46. package/src/decorators/ctrl/http/PATCH.cjs +3 -1
  47. package/src/decorators/ctrl/http/PATCH.mjs +3 -1
  48. package/src/decorators/ctrl/http/POST.cjs +3 -1
  49. package/src/decorators/ctrl/http/POST.mjs +3 -1
  50. package/src/decorators/ctrl/http/PUT.cjs +3 -1
  51. package/src/decorators/ctrl/http/PUT.mjs +3 -1
  52. package/src/lib/base/internal/ControllerEntrypoint.cjs +70 -610
  53. package/src/lib/base/internal/ControllerEntrypoint.mjs +87 -627
  54. package/src/lib/base/internal/StringifyPattern.cjs +1 -1
  55. package/src/lib/base/internal/StringifyPattern.mjs +1 -1
  56. package/src/lib/core/Application.cjs +3 -1
  57. package/src/lib/core/Application.mjs +3 -1
  58. package/src/lib/helpers/MD5.cjs +1 -1
  59. package/src/lib/helpers/MD5.mjs +1 -1
  60. package/src/lib/helpers/SHA1.cjs +1 -1
  61. package/src/lib/helpers/SHA1.mjs +1 -1
  62. package/src/lib/helpers/SHA256.cjs +1 -1
  63. package/src/lib/helpers/SHA256.mjs +1 -1
  64. package/src/lib/helpers/SortArray.cjs +1 -1
  65. package/src/lib/helpers/SortArray.mjs +1 -1
  66. package/src/lib/helpers/UUID.cjs +45 -0
  67. package/src/lib/helpers/UUID.mjs +39 -0
  68. package/vendor/Package.19.cjs +1 -1
  69. package/vendor/Package.19.mjs +176 -187
  70. package/vendor/Package.610.cjs +297 -113
  71. package/vendor/Package.610.mjs +285 -97
  72. package/vendor/Package.611.cjs +85 -103
  73. package/vendor/Package.611.mjs +80 -98
  74. package/vendor/Package.612.cjs +100 -121
  75. package/vendor/Package.612.mjs +97 -120
  76. package/vendor/Package.613.cjs +196 -0
  77. package/vendor/Package.613.mjs +180 -0
  78. package/vendor/Package.64.cjs +511 -134
  79. package/vendor/Package.64.mjs +491 -134
  80. package/vendor/Package.65.cjs +140 -4118
  81. package/vendor/Package.65.mjs +140 -4126
  82. package/vendor/Package.66.cjs +4142 -692
  83. package/vendor/Package.66.mjs +4151 -689
  84. package/vendor/Package.67.cjs +571 -535
  85. package/vendor/Package.67.mjs +586 -528
  86. package/vendor/Package.68.cjs +633 -96
  87. package/vendor/Package.68.mjs +619 -94
  88. package/vendor/Package.69.cjs +96 -294
  89. package/vendor/Package.69.mjs +95 -295
  90. package/vendor/TypeDef.internal.13.d.ts +1 -0
  91. package/vendor/TypeDef.internal.5.d.ts +1 -1
@@ -1,127 +1,652 @@
1
- import e from "events";
1
+ import { createClient as t, createCluster as e } from "@redis/client";
2
2
 
3
- import t from "memjs";
3
+ export { createClient, createCluster } from "@redis/client";
4
4
 
5
- import { d as s } from "./Package.66.mjs";
5
+ import { K as s } from "./Package.67.mjs";
6
+
7
+ import r from "cluster-key-slot";
6
8
 
7
9
  import "buffer";
8
10
 
9
- var r = class extends e {
10
- ttlSupport=true;
11
- namespace;
12
- client;
13
- opts;
14
- constructor(e, s) {
11
+ var i = class {
12
+ _eventListeners;
13
+ _maxListeners;
14
+ _logger;
15
+ constructor(t) {
16
+ this._eventListeners = new Map, this._maxListeners = 100, this._logger = t?.logger;
17
+ }
18
+ once(t, e) {
19
+ let s = (...r) => {
20
+ this.off(t, s), e(...r);
21
+ };
22
+ return this.on(t, s), this;
23
+ }
24
+ listenerCount(t) {
25
+ if (!t) return this.getAllListeners().length;
26
+ let e = this._eventListeners.get(t);
27
+ return e ? e.length : 0;
28
+ }
29
+ eventNames() {
30
+ return [ ...this._eventListeners.keys() ];
31
+ }
32
+ rawListeners(t) {
33
+ return t ? this._eventListeners.get(t) ?? [] : this.getAllListeners();
34
+ }
35
+ prependListener(t, e) {
36
+ let s = this._eventListeners.get(t) ?? [];
37
+ return s.unshift(e), this._eventListeners.set(t, s), this;
38
+ }
39
+ prependOnceListener(t, e) {
40
+ let s = (...r) => {
41
+ this.off(t, s), e(...r);
42
+ };
43
+ return this.prependListener(t, s), this;
44
+ }
45
+ maxListeners() {
46
+ return this._maxListeners;
47
+ }
48
+ addListener(t, e) {
49
+ return this.on(t, e), this;
50
+ }
51
+ on(t, e) {
52
+ this._eventListeners.has(t) || this._eventListeners.set(t, []);
53
+ let s = this._eventListeners.get(t);
54
+ return s && (s.length >= this._maxListeners && console.warn(`MaxListenersExceededWarning: Possible event memory leak detected. ${s.length + 1} ${t} listeners added. Use setMaxListeners() to increase limit.`),
55
+ s.push(e)), this;
56
+ }
57
+ removeListener(t, e) {
58
+ return this.off(t, e), this;
59
+ }
60
+ off(t, e) {
61
+ let s = this._eventListeners.get(t) ?? [], r = s.indexOf(e);
62
+ return r !== -1 && s.splice(r, 1), s.length === 0 && this._eventListeners.delete(t),
63
+ this;
64
+ }
65
+ emit(t, ...e) {
66
+ let s = !1, r = this._eventListeners.get(t);
67
+ if (r && r.length > 0) for (let t of r) t(...e), s = !0;
68
+ return s;
69
+ }
70
+ listeners(t) {
71
+ return this._eventListeners.get(t) ?? [];
72
+ }
73
+ removeAllListeners(t) {
74
+ return t ? this._eventListeners.delete(t) : this._eventListeners.clear(), this;
75
+ }
76
+ setMaxListeners(t) {
77
+ this._maxListeners = t;
78
+ for (let e of this._eventListeners.values()) e.length > t && e.splice(t);
79
+ }
80
+ getAllListeners() {
81
+ let t = new Array;
82
+ for (let e of this._eventListeners.values()) t = [ ...t, ...e ];
83
+ return t;
84
+ }
85
+ };
86
+
87
+ var n = class extends i {
88
+ _hooks;
89
+ _throwHookErrors=!1;
90
+ constructor(t) {
91
+ super({
92
+ logger: t?.logger
93
+ }), this._hooks = new Map, t?.throwHookErrors !== void 0 && (this._throwHookErrors = t.throwHookErrors);
94
+ }
95
+ get hooks() {
96
+ return this._hooks;
97
+ }
98
+ get throwHookErrors() {
99
+ return this._throwHookErrors;
100
+ }
101
+ set throwHookErrors(t) {
102
+ this._throwHookErrors = t;
103
+ }
104
+ get logger() {
105
+ return this._logger;
106
+ }
107
+ set logger(t) {
108
+ this._logger = t;
109
+ }
110
+ onHook(t, e) {
111
+ let s = this._hooks.get(t);
112
+ s ? s.push(e) : this._hooks.set(t, [ e ]);
113
+ }
114
+ addHook(t, e) {
115
+ this.onHook(t, e);
116
+ }
117
+ onHooks(t) {
118
+ for (let e of t) this.onHook(e.event, e.handler);
119
+ }
120
+ prependHook(t, e) {
121
+ let s = this._hooks.get(t);
122
+ s ? s.unshift(e) : this._hooks.set(t, [ e ]);
123
+ }
124
+ prependOnceHook(t, e) {
125
+ let s = async (...r) => (this.removeHook(t, s), e(...r));
126
+ this.prependHook(t, s);
127
+ }
128
+ onceHook(t, e) {
129
+ let s = async (...r) => (this.removeHook(t, s), e(...r));
130
+ this.onHook(t, s);
131
+ }
132
+ removeHook(t, e) {
133
+ let s = this._hooks.get(t);
134
+ if (s) {
135
+ let t = s.indexOf(e);
136
+ t !== -1 && s.splice(t, 1);
137
+ }
138
+ }
139
+ removeHooks(t) {
140
+ for (let e of t) this.removeHook(e.event, e.handler);
141
+ }
142
+ async hook(t, ...e) {
143
+ let s = this._hooks.get(t);
144
+ if (s) for (let r of s) try {
145
+ await r(...e);
146
+ } catch (e) {
147
+ let s = `${t}: ${e.message}`;
148
+ if (this.emit("error", new Error(s)), this._logger && this._logger.error(s), this._throwHookErrors) throw new Error(s);
149
+ }
150
+ }
151
+ async callHook(t, ...e) {
152
+ await this.hook(t, ...e);
153
+ }
154
+ getHooks(t) {
155
+ return this._hooks.get(t);
156
+ }
157
+ clearHooks() {
158
+ this._hooks.clear();
159
+ }
160
+ };
161
+
162
+ var o = (t => {
163
+ t["RedisClientNotConnectedThrown"] = "Redis client is not connected or has failed to connect. This is thrown because throwOnConnectError is set to true.";
164
+ return t;
165
+ })(o || {});
166
+
167
+ var a = t => {
168
+ const e = Math.min(2 ** t * 100, 2e3);
169
+ const s = (Math.random() - .5) * 100;
170
+ return e + s;
171
+ };
172
+
173
+ var c = class extends n {
174
+ _client=t();
175
+ _namespace;
176
+ _keyPrefixSeparator="::";
177
+ _clearBatchSize=1e3;
178
+ _useUnlink=true;
179
+ _noNamespaceAffectsAll=false;
180
+ _throwOnConnectError=true;
181
+ _throwErrors=false;
182
+ _connectionTimeout;
183
+ constructor(s, r) {
15
184
  super();
16
- s = {
17
- ...typeof e === "string" ? {
18
- uri: e
19
- } : e,
20
- ...s
185
+ const i = {
186
+ reconnectStrategy: a
21
187
  };
22
- if (s.uri && s.url === void 0) {
23
- s.url = s.uri;
188
+ if (s) {
189
+ if (typeof s === "string") {
190
+ this._client = t({
191
+ url: s,
192
+ socket: i
193
+ });
194
+ } else if (s.connect !== void 0) {
195
+ this._client = this.isClientCluster(s) ? s : s;
196
+ } else if (s instanceof Object) {
197
+ this._client = s.rootNodes === void 0 ? t(s) : e(s);
198
+ }
24
199
  }
25
- if (e === void 0) {
26
- e = "localhost:11211";
27
- s.url = s.uri = e;
200
+ this.setOptions(r);
201
+ this.initClient();
202
+ }
203
+ get client() {
204
+ return this._client;
205
+ }
206
+ set client(t) {
207
+ this._client = t;
208
+ this.initClient();
209
+ }
210
+ get opts() {
211
+ let t = "redis://localhost:6379";
212
+ if (this._client.options) {
213
+ const e = this._client.options?.url;
214
+ if (e) {
215
+ t = e;
216
+ }
28
217
  }
29
- this.opts = s;
30
- this.client = t.Client.create(e, s);
218
+ const e = {
219
+ namespace: this._namespace,
220
+ keyPrefixSeparator: this._keyPrefixSeparator,
221
+ clearBatchSize: this._clearBatchSize,
222
+ noNamespaceAffectsAll: this._noNamespaceAffectsAll,
223
+ useUnlink: this._useUnlink,
224
+ throwOnConnectError: this._throwOnConnectError,
225
+ throwErrors: this._throwErrors,
226
+ connectionTimeout: this._connectionTimeout,
227
+ dialect: "redis",
228
+ url: t
229
+ };
230
+ return e;
31
231
  }
32
- _getNamespace() {
33
- return `namespace:${this.namespace}`;
232
+ set opts(t) {
233
+ this.setOptions(t);
34
234
  }
35
- async get(e) {
36
- return new Promise(((t, r) => {
37
- this.client.get(this.formatKey(e), ((e, i) => {
38
- if (e) {
39
- this.emit("error", e);
40
- r(e);
41
- } else {
42
- let e;
43
- if (i === null) {
44
- e = {
45
- value: void 0,
46
- expires: 0
47
- };
48
- } else {
49
- e = this.opts.deserialize ? this.opts.deserialize(i) : s(i);
50
- }
51
- t(e);
52
- }
53
- }));
54
- }));
235
+ get namespace() {
236
+ return this._namespace;
55
237
  }
56
- async getMany(e) {
57
- const t = [];
58
- for (const s of e) {
59
- t.push(this.get(s));
238
+ set namespace(t) {
239
+ this._namespace = t;
240
+ }
241
+ get keyPrefixSeparator() {
242
+ return this._keyPrefixSeparator;
243
+ }
244
+ set keyPrefixSeparator(t) {
245
+ this._keyPrefixSeparator = t;
246
+ }
247
+ get clearBatchSize() {
248
+ return this._clearBatchSize;
249
+ }
250
+ set clearBatchSize(t) {
251
+ if (t > 0) {
252
+ this._clearBatchSize = t;
253
+ } else {
254
+ this.emit("error", "clearBatchSize must be greater than 0");
60
255
  }
61
- return Promise.allSettled(t).then((e => {
62
- const t = [];
63
- for (const s of e) {
64
- t.push(s.value);
256
+ }
257
+ get useUnlink() {
258
+ return this._useUnlink;
259
+ }
260
+ set useUnlink(t) {
261
+ this._useUnlink = t;
262
+ }
263
+ get noNamespaceAffectsAll() {
264
+ return this._noNamespaceAffectsAll;
265
+ }
266
+ set noNamespaceAffectsAll(t) {
267
+ this._noNamespaceAffectsAll = t;
268
+ }
269
+ get throwOnConnectError() {
270
+ return this._throwOnConnectError;
271
+ }
272
+ set throwOnConnectError(t) {
273
+ this._throwOnConnectError = t;
274
+ }
275
+ get throwErrors() {
276
+ return this._throwErrors;
277
+ }
278
+ set throwErrors(t) {
279
+ this._throwErrors = t;
280
+ }
281
+ get connectionTimeout() {
282
+ return this._connectionTimeout;
283
+ }
284
+ set connectionTimeout(t) {
285
+ this._connectionTimeout = t;
286
+ }
287
+ async getClient() {
288
+ if (this._client.isOpen) {
289
+ return this._client;
290
+ }
291
+ try {
292
+ if (this._connectionTimeout === void 0) {
293
+ await this._client.connect();
294
+ } else {
295
+ await Promise.race([ this._client.connect(), this.createTimeoutPromise(this._connectionTimeout) ]);
65
296
  }
66
- return t;
67
- }));
297
+ } catch (t) {
298
+ this.emit("error", t);
299
+ if (this._throwOnConnectError) {
300
+ throw new Error("Redis client is not connected or has failed to connect. This is thrown because throwOnConnectError is set to true.");
301
+ }
302
+ await this.disconnect(true);
303
+ }
304
+ this.initClient();
305
+ return this._client;
68
306
  }
69
- async set(e, t, s) {
70
- const r = {};
71
- if (s !== void 0) {
72
- r.expires = r.ttl = Math.floor(s / 1e3);
307
+ async set(t, e, s) {
308
+ const r = await this.getClient();
309
+ try {
310
+ t = this.createKeyPrefix(t, this._namespace);
311
+ if (s) {
312
+ await r.set(t, e, {
313
+ PX: s
314
+ });
315
+ } else {
316
+ await r.set(t, e);
317
+ }
318
+ } catch (t) {
319
+ this.emit("error", t);
320
+ if (this._throwErrors) {
321
+ throw t;
322
+ }
73
323
  }
74
- await this.client.set(this.formatKey(e), t, r);
75
324
  }
76
- async delete(e) {
77
- return new Promise(((t, s) => {
78
- this.client.delete(this.formatKey(e), ((e, r) => {
79
- if (e) {
80
- this.emit("error", e);
81
- s(e);
325
+ async setMany(t) {
326
+ const e = await this.getClient();
327
+ try {
328
+ const s = e.multi();
329
+ for (const {key: e, value: r, ttl: i} of t) {
330
+ const t = this.createKeyPrefix(e, this._namespace);
331
+ if (i) {
332
+ s.set(t, r, {
333
+ PX: i
334
+ });
82
335
  } else {
83
- t(Boolean(r));
336
+ s.set(t, r);
84
337
  }
85
- }));
86
- }));
338
+ }
339
+ await s.exec();
340
+ } catch (t) {
341
+ this.emit("error", t);
342
+ if (this._throwErrors) {
343
+ throw t;
344
+ }
345
+ }
87
346
  }
88
- async deleteMany(e) {
89
- const t = e.map((async e => this.delete(e)));
90
- const s = await Promise.allSettled(t);
91
- return s.every((e => e.value === true));
347
+ async has(t) {
348
+ const e = await this.getClient();
349
+ try {
350
+ t = this.createKeyPrefix(t, this._namespace);
351
+ const s = await e.exists(t);
352
+ return s === 1;
353
+ } catch (t) {
354
+ this.emit("error", t);
355
+ if (this._throwErrors) {
356
+ throw t;
357
+ }
358
+ return false;
359
+ }
92
360
  }
93
- async clear() {
94
- return new Promise(((e, t) => {
95
- this.client.flush((s => {
96
- if (s) {
97
- this.emit("error", s);
98
- t(s);
361
+ async hasMany(t) {
362
+ const e = await this.getClient();
363
+ try {
364
+ const s = e.multi();
365
+ for (const e of t) {
366
+ const t = this.createKeyPrefix(e, this._namespace);
367
+ s.exists(t);
368
+ }
369
+ const r = await s.exec();
370
+ return r.map((t => t === 1));
371
+ } catch (e) {
372
+ this.emit("error", e);
373
+ if (this._throwErrors) {
374
+ throw e;
375
+ }
376
+ return Array.from({
377
+ length: t.length
378
+ }).fill(false);
379
+ }
380
+ }
381
+ async get(t) {
382
+ const e = await this.getClient();
383
+ try {
384
+ t = this.createKeyPrefix(t, this._namespace);
385
+ const s = await e.get(t);
386
+ if (s === null) {
387
+ return void 0;
388
+ }
389
+ return s;
390
+ } catch (t) {
391
+ this.emit("error", t);
392
+ if (this._throwErrors) {
393
+ throw t;
394
+ }
395
+ return void 0;
396
+ }
397
+ }
398
+ async getMany(t) {
399
+ if (t.length === 0) {
400
+ return [];
401
+ }
402
+ t = t.map((t => this.createKeyPrefix(t, this._namespace)));
403
+ try {
404
+ const e = await this.mget(t);
405
+ return e;
406
+ } catch (e) {
407
+ this.emit("error", e);
408
+ if (this._throwErrors) {
409
+ throw e;
410
+ }
411
+ return Array.from({
412
+ length: t.length
413
+ }).fill(void 0);
414
+ }
415
+ }
416
+ async delete(t) {
417
+ const e = await this.getClient();
418
+ try {
419
+ t = this.createKeyPrefix(t, this._namespace);
420
+ let s = 0;
421
+ s = await (this._useUnlink ? e.unlink(t) : e.del(t));
422
+ return s > 0;
423
+ } catch (t) {
424
+ this.emit("error", t);
425
+ if (this._throwErrors) {
426
+ throw t;
427
+ }
428
+ return false;
429
+ }
430
+ }
431
+ async deleteMany(t) {
432
+ let e = false;
433
+ const s = await this.getClient();
434
+ try {
435
+ const r = s.multi();
436
+ for (const e of t) {
437
+ const t = this.createKeyPrefix(e, this._namespace);
438
+ if (this._useUnlink) {
439
+ r.unlink(t);
99
440
  } else {
100
- e(void 0);
441
+ r.del(t);
101
442
  }
102
- }));
103
- }));
443
+ }
444
+ const i = await r.exec();
445
+ for (const t of i) {
446
+ if (typeof t === "number" && t > 0) {
447
+ e = true;
448
+ }
449
+ }
450
+ } catch (t) {
451
+ this.emit("error", t);
452
+ if (this._throwErrors) {
453
+ throw t;
454
+ }
455
+ }
456
+ return e;
457
+ }
458
+ async disconnect(t) {
459
+ if (this._client.isOpen) {
460
+ await (t ? this._client.disconnect() : this._client.quit());
461
+ }
104
462
  }
105
- formatKey(e) {
106
- let t = e;
107
- if (this.namespace) {
108
- t = this.namespace.trim() + ":" + e.trim();
463
+ createKeyPrefix(t, e) {
464
+ if (e) {
465
+ return `${e}${this._keyPrefixSeparator}${t}`;
109
466
  }
110
467
  return t;
111
468
  }
112
- async has(e) {
113
- return new Promise((t => {
114
- this.client.get(this.formatKey(e), ((e, s) => {
115
- if (e) {
116
- t(false);
117
- } else {
118
- t(s !== null);
469
+ getKeyWithoutPrefix(t, e) {
470
+ if (e) {
471
+ return t.replace(`${e}${this._keyPrefixSeparator}`, "");
472
+ }
473
+ return t;
474
+ }
475
+ isCluster() {
476
+ return this.isClientCluster(this._client);
477
+ }
478
+ async getMasterNodes() {
479
+ if (this.isCluster()) {
480
+ const t = await this.getClient();
481
+ return Promise.all(t.masters.map((async e => t.nodeClient(e))));
482
+ }
483
+ return [ await this.getClient() ];
484
+ }
485
+ async* iterator(t) {
486
+ const e = await this.getMasterNodes();
487
+ for (const s of e) {
488
+ const e = t ? `${t}${this._keyPrefixSeparator}*` : "*";
489
+ let r = "0";
490
+ do {
491
+ const i = await s.scan(Number.parseInt(r, 10), {
492
+ MATCH: e,
493
+ TYPE: "string"
494
+ });
495
+ r = i.cursor.toString();
496
+ let {keys: n} = i;
497
+ if (!t && !this._noNamespaceAffectsAll) {
498
+ n = n.filter((t => !t.includes(this._keyPrefixSeparator)));
499
+ }
500
+ if (n.length > 0) {
501
+ const e = await this.mget(n);
502
+ for (const s of n.keys()) {
503
+ const r = this.getKeyWithoutPrefix(n[s], t);
504
+ const i = e[s];
505
+ yield [ r, i ];
506
+ }
507
+ }
508
+ } while (r !== "0");
509
+ }
510
+ }
511
+ async clear() {
512
+ try {
513
+ const t = await this.getMasterNodes();
514
+ await Promise.all(t.map((async t => {
515
+ if (!this._namespace && this._noNamespaceAffectsAll) {
516
+ await t.flushDb();
517
+ return;
119
518
  }
120
- }));
519
+ let e = "0";
520
+ const s = this._clearBatchSize;
521
+ const r = this._namespace ? `${this._namespace}${this._keyPrefixSeparator}*` : "*";
522
+ const i = [];
523
+ do {
524
+ const n = await t.scan(Number.parseInt(e, 10), {
525
+ MATCH: r,
526
+ COUNT: s,
527
+ TYPE: "string"
528
+ });
529
+ e = n.cursor.toString();
530
+ let {keys: o} = n;
531
+ if (o.length === 0) {
532
+ continue;
533
+ }
534
+ if (!this._namespace) {
535
+ o = o.filter((t => !t.includes(this._keyPrefixSeparator)));
536
+ }
537
+ i.push(this.clearWithClusterSupport(o));
538
+ } while (e !== "0");
539
+ await Promise.all(i);
540
+ })));
541
+ } catch (t) {
542
+ this.emit("error", t);
543
+ }
544
+ }
545
+ async mget(t) {
546
+ const e = this.getSlotMap(t);
547
+ const s = new Map;
548
+ await Promise.all(Array.from(e.entries(), (async ([t, e]) => {
549
+ const r = await this.getSlotMaster(t);
550
+ const i = await r.mGet(e);
551
+ for (const [t, r] of i.entries()) {
552
+ s.set(e[t], r ?? void 0);
553
+ }
554
+ })));
555
+ return t.map((t => s.get(t)));
556
+ }
557
+ async clearWithClusterSupport(t) {
558
+ if (t.length > 0) {
559
+ const e = this.getSlotMap(t);
560
+ await Promise.all(Array.from(e.entries(), (async ([t, e]) => {
561
+ const s = await this.getSlotMaster(t);
562
+ return this._useUnlink ? s.unlink(e) : s.del(e);
563
+ })));
564
+ }
565
+ }
566
+ async getSlotMaster(t) {
567
+ const e = await this.getClient();
568
+ if (this.isCluster()) {
569
+ const s = e;
570
+ const r = s.slots[t].master;
571
+ return s.nodeClient(r);
572
+ }
573
+ return e;
574
+ }
575
+ getSlotMap(t) {
576
+ const e = new Map;
577
+ if (this.isCluster()) {
578
+ for (const s of t) {
579
+ const t = r(s);
580
+ const i = e.get(t) ?? [];
581
+ i.push(s);
582
+ e.set(t, i);
583
+ }
584
+ } else {
585
+ e.set(0, t);
586
+ }
587
+ return e;
588
+ }
589
+ isClientCluster(t) {
590
+ if (t.options === void 0 && t.scan === void 0) {
591
+ return true;
592
+ }
593
+ return false;
594
+ }
595
+ setOptions(t) {
596
+ if (!t) {
597
+ return;
598
+ }
599
+ if (t.namespace) {
600
+ this._namespace = t.namespace;
601
+ }
602
+ if (t.keyPrefixSeparator !== void 0) {
603
+ this._keyPrefixSeparator = t.keyPrefixSeparator;
604
+ }
605
+ if (t.clearBatchSize !== void 0 && t.clearBatchSize > 0) {
606
+ this._clearBatchSize = t.clearBatchSize;
607
+ }
608
+ if (t.useUnlink !== void 0) {
609
+ this._useUnlink = t.useUnlink;
610
+ }
611
+ if (t.noNamespaceAffectsAll !== void 0) {
612
+ this._noNamespaceAffectsAll = t.noNamespaceAffectsAll;
613
+ }
614
+ if (t.throwOnConnectError !== void 0) {
615
+ this._throwOnConnectError = t.throwOnConnectError;
616
+ }
617
+ if (t.throwErrors !== void 0) {
618
+ this._throwErrors = t.throwErrors;
619
+ }
620
+ if (t.connectionTimeout !== void 0) {
621
+ this._connectionTimeout = t.connectionTimeout;
622
+ }
623
+ }
624
+ initClient() {
625
+ this._client.on("connect", (() => {
626
+ this.emit("connect", this._client);
627
+ }));
628
+ this._client.on("disconnect", (() => {
629
+ this.emit("disconnect", this._client);
121
630
  }));
631
+ this._client.on("reconnecting", (t => {
632
+ this.emit("reconnecting", t);
633
+ }));
634
+ }
635
+ async createTimeoutPromise(t) {
636
+ return new Promise(((e, s) => setTimeout((() => {
637
+ s(new Error(`Redis timed out after ${t}ms`));
638
+ }), t)));
122
639
  }
123
640
  };
124
641
 
125
- var i = r;
642
+ function h(t, e) {
643
+ t ??= "redis://localhost:6379";
644
+ const r = new c(t, e);
645
+ const i = new s(r, {
646
+ namespace: e?.namespace,
647
+ useKeyPrefix: false
648
+ });
649
+ return i;
650
+ }
126
651
 
127
- export { r as KeyvMemcache, i as default };
652
+ export { s as Keyv, o as RedisErrorMessages, h as createKeyv, c as default, a as defaultReconnectStrategy };