koishi-plugin-warframe 1.7.9 → 1.7.11

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/lib/index.js CHANGED
@@ -34,2975 +34,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
34
  ));
35
35
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
36
 
37
- // node_modules/bottleneck/lib/parser.js
38
- var require_parser = __commonJS({
39
- "node_modules/bottleneck/lib/parser.js"(exports2) {
40
- "use strict";
41
- exports2.load = function(received, defaults, onto = {}) {
42
- var k, ref, v;
43
- for (k in defaults) {
44
- v = defaults[k];
45
- onto[k] = (ref = received[k]) != null ? ref : v;
46
- }
47
- return onto;
48
- };
49
- exports2.overwrite = function(received, defaults, onto = {}) {
50
- var k, v;
51
- for (k in received) {
52
- v = received[k];
53
- if (defaults[k] !== void 0) {
54
- onto[k] = v;
55
- }
56
- }
57
- return onto;
58
- };
59
- }
60
- });
61
-
62
- // node_modules/bottleneck/lib/DLList.js
63
- var require_DLList = __commonJS({
64
- "node_modules/bottleneck/lib/DLList.js"(exports2, module2) {
65
- "use strict";
66
- var DLList;
67
- DLList = class DLList {
68
- static {
69
- __name(this, "DLList");
70
- }
71
- constructor(incr, decr) {
72
- this.incr = incr;
73
- this.decr = decr;
74
- this._first = null;
75
- this._last = null;
76
- this.length = 0;
77
- }
78
- push(value) {
79
- var node;
80
- this.length++;
81
- if (typeof this.incr === "function") {
82
- this.incr();
83
- }
84
- node = {
85
- value,
86
- prev: this._last,
87
- next: null
88
- };
89
- if (this._last != null) {
90
- this._last.next = node;
91
- this._last = node;
92
- } else {
93
- this._first = this._last = node;
94
- }
95
- return void 0;
96
- }
97
- shift() {
98
- var value;
99
- if (this._first == null) {
100
- return;
101
- } else {
102
- this.length--;
103
- if (typeof this.decr === "function") {
104
- this.decr();
105
- }
106
- }
107
- value = this._first.value;
108
- if ((this._first = this._first.next) != null) {
109
- this._first.prev = null;
110
- } else {
111
- this._last = null;
112
- }
113
- return value;
114
- }
115
- first() {
116
- if (this._first != null) {
117
- return this._first.value;
118
- }
119
- }
120
- getArray() {
121
- var node, ref, results;
122
- node = this._first;
123
- results = [];
124
- while (node != null) {
125
- results.push((ref = node, node = node.next, ref.value));
126
- }
127
- return results;
128
- }
129
- forEachShift(cb) {
130
- var node;
131
- node = this.shift();
132
- while (node != null) {
133
- cb(node), node = this.shift();
134
- }
135
- return void 0;
136
- }
137
- debug() {
138
- var node, ref, ref1, ref2, results;
139
- node = this._first;
140
- results = [];
141
- while (node != null) {
142
- results.push((ref = node, node = node.next, {
143
- value: ref.value,
144
- prev: (ref1 = ref.prev) != null ? ref1.value : void 0,
145
- next: (ref2 = ref.next) != null ? ref2.value : void 0
146
- }));
147
- }
148
- return results;
149
- }
150
- };
151
- module2.exports = DLList;
152
- }
153
- });
154
-
155
- // node_modules/bottleneck/lib/Events.js
156
- var require_Events = __commonJS({
157
- "node_modules/bottleneck/lib/Events.js"(exports2, module2) {
158
- "use strict";
159
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
160
- try {
161
- var info = gen[key](arg);
162
- var value = info.value;
163
- } catch (error) {
164
- reject(error);
165
- return;
166
- }
167
- if (info.done) {
168
- resolve3(value);
169
- } else {
170
- Promise.resolve(value).then(_next, _throw);
171
- }
172
- }
173
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
174
- function _asyncToGenerator2(fn) {
175
- return function() {
176
- var self2 = this, args = arguments;
177
- return new Promise(function(resolve3, reject) {
178
- var gen = fn.apply(self2, args);
179
- function _next(value) {
180
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
181
- }
182
- __name(_next, "_next");
183
- function _throw(err) {
184
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
185
- }
186
- __name(_throw, "_throw");
187
- _next(void 0);
188
- });
189
- };
190
- }
191
- __name(_asyncToGenerator2, "_asyncToGenerator");
192
- var Events2;
193
- Events2 = class Events {
194
- static {
195
- __name(this, "Events");
196
- }
197
- constructor(instance) {
198
- this.instance = instance;
199
- this._events = {};
200
- if (this.instance.on != null || this.instance.once != null || this.instance.removeAllListeners != null) {
201
- throw new Error("An Emitter already exists for this object");
202
- }
203
- this.instance.on = (name2, cb) => {
204
- return this._addListener(name2, "many", cb);
205
- };
206
- this.instance.once = (name2, cb) => {
207
- return this._addListener(name2, "once", cb);
208
- };
209
- this.instance.removeAllListeners = (name2 = null) => {
210
- if (name2 != null) {
211
- return delete this._events[name2];
212
- } else {
213
- return this._events = {};
214
- }
215
- };
216
- }
217
- _addListener(name2, status, cb) {
218
- var base;
219
- if ((base = this._events)[name2] == null) {
220
- base[name2] = [];
221
- }
222
- this._events[name2].push({
223
- cb,
224
- status
225
- });
226
- return this.instance;
227
- }
228
- listenerCount(name2) {
229
- if (this._events[name2] != null) {
230
- return this._events[name2].length;
231
- } else {
232
- return 0;
233
- }
234
- }
235
- trigger(name2, ...args) {
236
- var _this = this;
237
- return _asyncToGenerator2(function* () {
238
- var e, promises;
239
- try {
240
- if (name2 !== "debug") {
241
- _this.trigger("debug", `Event triggered: ${name2}`, args);
242
- }
243
- if (_this._events[name2] == null) {
244
- return;
245
- }
246
- _this._events[name2] = _this._events[name2].filter(function(listener) {
247
- return listener.status !== "none";
248
- });
249
- promises = _this._events[name2].map(
250
- /* @__PURE__ */ (function() {
251
- var _ref = _asyncToGenerator2(function* (listener) {
252
- var e2, returned;
253
- if (listener.status === "none") {
254
- return;
255
- }
256
- if (listener.status === "once") {
257
- listener.status = "none";
258
- }
259
- try {
260
- returned = typeof listener.cb === "function" ? listener.cb(...args) : void 0;
261
- if (typeof (returned != null ? returned.then : void 0) === "function") {
262
- return yield returned;
263
- } else {
264
- return returned;
265
- }
266
- } catch (error) {
267
- e2 = error;
268
- if (true) {
269
- _this.trigger("error", e2);
270
- }
271
- return null;
272
- }
273
- });
274
- return function(_x) {
275
- return _ref.apply(this, arguments);
276
- };
277
- })()
278
- );
279
- return (yield Promise.all(promises)).find(function(x) {
280
- return x != null;
281
- });
282
- } catch (error) {
283
- e = error;
284
- if (true) {
285
- _this.trigger("error", e);
286
- }
287
- return null;
288
- }
289
- })();
290
- }
291
- };
292
- module2.exports = Events2;
293
- }
294
- });
295
-
296
- // node_modules/bottleneck/lib/Queues.js
297
- var require_Queues = __commonJS({
298
- "node_modules/bottleneck/lib/Queues.js"(exports2, module2) {
299
- "use strict";
300
- var DLList;
301
- var Events2;
302
- var Queues;
303
- DLList = require_DLList();
304
- Events2 = require_Events();
305
- Queues = class Queues {
306
- static {
307
- __name(this, "Queues");
308
- }
309
- constructor(num_priorities) {
310
- var i;
311
- this.Events = new Events2(this);
312
- this._length = 0;
313
- this._lists = function() {
314
- var j, ref, results;
315
- results = [];
316
- for (i = j = 1, ref = num_priorities; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) {
317
- results.push(new DLList(() => {
318
- return this.incr();
319
- }, () => {
320
- return this.decr();
321
- }));
322
- }
323
- return results;
324
- }.call(this);
325
- }
326
- incr() {
327
- if (this._length++ === 0) {
328
- return this.Events.trigger("leftzero");
329
- }
330
- }
331
- decr() {
332
- if (--this._length === 0) {
333
- return this.Events.trigger("zero");
334
- }
335
- }
336
- push(job) {
337
- return this._lists[job.options.priority].push(job);
338
- }
339
- queued(priority) {
340
- if (priority != null) {
341
- return this._lists[priority].length;
342
- } else {
343
- return this._length;
344
- }
345
- }
346
- shiftAll(fn) {
347
- return this._lists.forEach(function(list) {
348
- return list.forEachShift(fn);
349
- });
350
- }
351
- getFirst(arr = this._lists) {
352
- var j, len, list;
353
- for (j = 0, len = arr.length; j < len; j++) {
354
- list = arr[j];
355
- if (list.length > 0) {
356
- return list;
357
- }
358
- }
359
- return [];
360
- }
361
- shiftLastFrom(priority) {
362
- return this.getFirst(this._lists.slice(priority).reverse()).shift();
363
- }
364
- };
365
- module2.exports = Queues;
366
- }
367
- });
368
-
369
- // node_modules/bottleneck/lib/BottleneckError.js
370
- var require_BottleneckError = __commonJS({
371
- "node_modules/bottleneck/lib/BottleneckError.js"(exports2, module2) {
372
- "use strict";
373
- var BottleneckError;
374
- BottleneckError = class BottleneckError extends Error {
375
- static {
376
- __name(this, "BottleneckError");
377
- }
378
- };
379
- module2.exports = BottleneckError;
380
- }
381
- });
382
-
383
- // node_modules/bottleneck/lib/Job.js
384
- var require_Job = __commonJS({
385
- "node_modules/bottleneck/lib/Job.js"(exports2, module2) {
386
- "use strict";
387
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
388
- try {
389
- var info = gen[key](arg);
390
- var value = info.value;
391
- } catch (error) {
392
- reject(error);
393
- return;
394
- }
395
- if (info.done) {
396
- resolve3(value);
397
- } else {
398
- Promise.resolve(value).then(_next, _throw);
399
- }
400
- }
401
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
402
- function _asyncToGenerator2(fn) {
403
- return function() {
404
- var self2 = this, args = arguments;
405
- return new Promise(function(resolve3, reject) {
406
- var gen = fn.apply(self2, args);
407
- function _next(value) {
408
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
409
- }
410
- __name(_next, "_next");
411
- function _throw(err) {
412
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
413
- }
414
- __name(_throw, "_throw");
415
- _next(void 0);
416
- });
417
- };
418
- }
419
- __name(_asyncToGenerator2, "_asyncToGenerator");
420
- var BottleneckError;
421
- var DEFAULT_PRIORITY;
422
- var Job;
423
- var NUM_PRIORITIES;
424
- var parser2;
425
- NUM_PRIORITIES = 10;
426
- DEFAULT_PRIORITY = 5;
427
- parser2 = require_parser();
428
- BottleneckError = require_BottleneckError();
429
- Job = class Job {
430
- static {
431
- __name(this, "Job");
432
- }
433
- constructor(task, args, options2, jobDefaults, rejectOnDrop, Events2, _states, Promise2) {
434
- this.task = task;
435
- this.args = args;
436
- this.rejectOnDrop = rejectOnDrop;
437
- this.Events = Events2;
438
- this._states = _states;
439
- this.Promise = Promise2;
440
- this.options = parser2.load(options2, jobDefaults);
441
- this.options.priority = this._sanitizePriority(this.options.priority);
442
- if (this.options.id === jobDefaults.id) {
443
- this.options.id = `${this.options.id}-${this._randomIndex()}`;
444
- }
445
- this.promise = new this.Promise((_resolve, _reject) => {
446
- this._resolve = _resolve;
447
- this._reject = _reject;
448
- });
449
- this.retryCount = 0;
450
- }
451
- _sanitizePriority(priority) {
452
- var sProperty;
453
- sProperty = ~~priority !== priority ? DEFAULT_PRIORITY : priority;
454
- if (sProperty < 0) {
455
- return 0;
456
- } else if (sProperty > NUM_PRIORITIES - 1) {
457
- return NUM_PRIORITIES - 1;
458
- } else {
459
- return sProperty;
460
- }
461
- }
462
- _randomIndex() {
463
- return Math.random().toString(36).slice(2);
464
- }
465
- doDrop({
466
- error,
467
- message = "This job has been dropped by Bottleneck"
468
- } = {}) {
469
- if (this._states.remove(this.options.id)) {
470
- if (this.rejectOnDrop) {
471
- this._reject(error != null ? error : new BottleneckError(message));
472
- }
473
- this.Events.trigger("dropped", {
474
- args: this.args,
475
- options: this.options,
476
- task: this.task,
477
- promise: this.promise
478
- });
479
- return true;
480
- } else {
481
- return false;
482
- }
483
- }
484
- _assertStatus(expected) {
485
- var status;
486
- status = this._states.jobStatus(this.options.id);
487
- if (!(status === expected || expected === "DONE" && status === null)) {
488
- throw new BottleneckError(`Invalid job status ${status}, expected ${expected}. Please open an issue at https://github.com/SGrondin/bottleneck/issues`);
489
- }
490
- }
491
- doReceive() {
492
- this._states.start(this.options.id);
493
- return this.Events.trigger("received", {
494
- args: this.args,
495
- options: this.options
496
- });
497
- }
498
- doQueue(reachedHWM, blocked) {
499
- this._assertStatus("RECEIVED");
500
- this._states.next(this.options.id);
501
- return this.Events.trigger("queued", {
502
- args: this.args,
503
- options: this.options,
504
- reachedHWM,
505
- blocked
506
- });
507
- }
508
- doRun() {
509
- if (this.retryCount === 0) {
510
- this._assertStatus("QUEUED");
511
- this._states.next(this.options.id);
512
- } else {
513
- this._assertStatus("EXECUTING");
514
- }
515
- return this.Events.trigger("scheduled", {
516
- args: this.args,
517
- options: this.options
518
- });
519
- }
520
- doExecute(chained, clearGlobalState, run, free) {
521
- var _this = this;
522
- return _asyncToGenerator2(function* () {
523
- var error, eventInfo, passed;
524
- if (_this.retryCount === 0) {
525
- _this._assertStatus("RUNNING");
526
- _this._states.next(_this.options.id);
527
- } else {
528
- _this._assertStatus("EXECUTING");
529
- }
530
- eventInfo = {
531
- args: _this.args,
532
- options: _this.options,
533
- retryCount: _this.retryCount
534
- };
535
- _this.Events.trigger("executing", eventInfo);
536
- try {
537
- passed = yield chained != null ? chained.schedule(_this.options, _this.task, ..._this.args) : _this.task(..._this.args);
538
- if (clearGlobalState()) {
539
- _this.doDone(eventInfo);
540
- yield free(_this.options, eventInfo);
541
- _this._assertStatus("DONE");
542
- return _this._resolve(passed);
543
- }
544
- } catch (error1) {
545
- error = error1;
546
- return _this._onFailure(error, eventInfo, clearGlobalState, run, free);
547
- }
548
- })();
549
- }
550
- doExpire(clearGlobalState, run, free) {
551
- var error, eventInfo;
552
- if (this._states.jobStatus(this.options.id === "RUNNING")) {
553
- this._states.next(this.options.id);
554
- }
555
- this._assertStatus("EXECUTING");
556
- eventInfo = {
557
- args: this.args,
558
- options: this.options,
559
- retryCount: this.retryCount
560
- };
561
- error = new BottleneckError(`This job timed out after ${this.options.expiration} ms.`);
562
- return this._onFailure(error, eventInfo, clearGlobalState, run, free);
563
- }
564
- _onFailure(error, eventInfo, clearGlobalState, run, free) {
565
- var _this2 = this;
566
- return _asyncToGenerator2(function* () {
567
- var retry, retryAfter;
568
- if (clearGlobalState()) {
569
- retry = yield _this2.Events.trigger("failed", error, eventInfo);
570
- if (retry != null) {
571
- retryAfter = ~~retry;
572
- _this2.Events.trigger("retry", `Retrying ${_this2.options.id} after ${retryAfter} ms`, eventInfo);
573
- _this2.retryCount++;
574
- return run(retryAfter);
575
- } else {
576
- _this2.doDone(eventInfo);
577
- yield free(_this2.options, eventInfo);
578
- _this2._assertStatus("DONE");
579
- return _this2._reject(error);
580
- }
581
- }
582
- })();
583
- }
584
- doDone(eventInfo) {
585
- this._assertStatus("EXECUTING");
586
- this._states.next(this.options.id);
587
- return this.Events.trigger("done", eventInfo);
588
- }
589
- };
590
- module2.exports = Job;
591
- }
592
- });
593
-
594
- // node_modules/bottleneck/lib/LocalDatastore.js
595
- var require_LocalDatastore = __commonJS({
596
- "node_modules/bottleneck/lib/LocalDatastore.js"(exports2, module2) {
597
- "use strict";
598
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
599
- try {
600
- var info = gen[key](arg);
601
- var value = info.value;
602
- } catch (error) {
603
- reject(error);
604
- return;
605
- }
606
- if (info.done) {
607
- resolve3(value);
608
- } else {
609
- Promise.resolve(value).then(_next, _throw);
610
- }
611
- }
612
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
613
- function _asyncToGenerator2(fn) {
614
- return function() {
615
- var self2 = this, args = arguments;
616
- return new Promise(function(resolve3, reject) {
617
- var gen = fn.apply(self2, args);
618
- function _next(value) {
619
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
620
- }
621
- __name(_next, "_next");
622
- function _throw(err) {
623
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
624
- }
625
- __name(_throw, "_throw");
626
- _next(void 0);
627
- });
628
- };
629
- }
630
- __name(_asyncToGenerator2, "_asyncToGenerator");
631
- var BottleneckError;
632
- var LocalDatastore;
633
- var parser2;
634
- parser2 = require_parser();
635
- BottleneckError = require_BottleneckError();
636
- LocalDatastore = class LocalDatastore {
637
- static {
638
- __name(this, "LocalDatastore");
639
- }
640
- constructor(instance, storeOptions, storeInstanceOptions) {
641
- this.instance = instance;
642
- this.storeOptions = storeOptions;
643
- this.clientId = this.instance._randomIndex();
644
- parser2.load(storeInstanceOptions, storeInstanceOptions, this);
645
- this._nextRequest = this._lastReservoirRefresh = this._lastReservoirIncrease = Date.now();
646
- this._running = 0;
647
- this._done = 0;
648
- this._unblockTime = 0;
649
- this.ready = this.Promise.resolve();
650
- this.clients = {};
651
- this._startHeartbeat();
652
- }
653
- _startHeartbeat() {
654
- var base;
655
- if (this.heartbeat == null && (this.storeOptions.reservoirRefreshInterval != null && this.storeOptions.reservoirRefreshAmount != null || this.storeOptions.reservoirIncreaseInterval != null && this.storeOptions.reservoirIncreaseAmount != null)) {
656
- return typeof (base = this.heartbeat = setInterval(() => {
657
- var amount, incr, maximum, now, reservoir;
658
- now = Date.now();
659
- if (this.storeOptions.reservoirRefreshInterval != null && now >= this._lastReservoirRefresh + this.storeOptions.reservoirRefreshInterval) {
660
- this._lastReservoirRefresh = now;
661
- this.storeOptions.reservoir = this.storeOptions.reservoirRefreshAmount;
662
- this.instance._drainAll(this.computeCapacity());
663
- }
664
- if (this.storeOptions.reservoirIncreaseInterval != null && now >= this._lastReservoirIncrease + this.storeOptions.reservoirIncreaseInterval) {
665
- var _this$storeOptions = this.storeOptions;
666
- amount = _this$storeOptions.reservoirIncreaseAmount;
667
- maximum = _this$storeOptions.reservoirIncreaseMaximum;
668
- reservoir = _this$storeOptions.reservoir;
669
- this._lastReservoirIncrease = now;
670
- incr = maximum != null ? Math.min(amount, maximum - reservoir) : amount;
671
- if (incr > 0) {
672
- this.storeOptions.reservoir += incr;
673
- return this.instance._drainAll(this.computeCapacity());
674
- }
675
- }
676
- }, this.heartbeatInterval)).unref === "function" ? base.unref() : void 0;
677
- } else {
678
- return clearInterval(this.heartbeat);
679
- }
680
- }
681
- __publish__(message) {
682
- var _this = this;
683
- return _asyncToGenerator2(function* () {
684
- yield _this.yieldLoop();
685
- return _this.instance.Events.trigger("message", message.toString());
686
- })();
687
- }
688
- __disconnect__(flush) {
689
- var _this2 = this;
690
- return _asyncToGenerator2(function* () {
691
- yield _this2.yieldLoop();
692
- clearInterval(_this2.heartbeat);
693
- return _this2.Promise.resolve();
694
- })();
695
- }
696
- yieldLoop(t2 = 0) {
697
- return new this.Promise(function(resolve3, reject) {
698
- return setTimeout(resolve3, t2);
699
- });
700
- }
701
- computePenalty() {
702
- var ref;
703
- return (ref = this.storeOptions.penalty) != null ? ref : 15 * this.storeOptions.minTime || 5e3;
704
- }
705
- __updateSettings__(options2) {
706
- var _this3 = this;
707
- return _asyncToGenerator2(function* () {
708
- yield _this3.yieldLoop();
709
- parser2.overwrite(options2, options2, _this3.storeOptions);
710
- _this3._startHeartbeat();
711
- _this3.instance._drainAll(_this3.computeCapacity());
712
- return true;
713
- })();
714
- }
715
- __running__() {
716
- var _this4 = this;
717
- return _asyncToGenerator2(function* () {
718
- yield _this4.yieldLoop();
719
- return _this4._running;
720
- })();
721
- }
722
- __queued__() {
723
- var _this5 = this;
724
- return _asyncToGenerator2(function* () {
725
- yield _this5.yieldLoop();
726
- return _this5.instance.queued();
727
- })();
728
- }
729
- __done__() {
730
- var _this6 = this;
731
- return _asyncToGenerator2(function* () {
732
- yield _this6.yieldLoop();
733
- return _this6._done;
734
- })();
735
- }
736
- __groupCheck__(time2) {
737
- var _this7 = this;
738
- return _asyncToGenerator2(function* () {
739
- yield _this7.yieldLoop();
740
- return _this7._nextRequest + _this7.timeout < time2;
741
- })();
742
- }
743
- computeCapacity() {
744
- var maxConcurrent, reservoir;
745
- var _this$storeOptions2 = this.storeOptions;
746
- maxConcurrent = _this$storeOptions2.maxConcurrent;
747
- reservoir = _this$storeOptions2.reservoir;
748
- if (maxConcurrent != null && reservoir != null) {
749
- return Math.min(maxConcurrent - this._running, reservoir);
750
- } else if (maxConcurrent != null) {
751
- return maxConcurrent - this._running;
752
- } else if (reservoir != null) {
753
- return reservoir;
754
- } else {
755
- return null;
756
- }
757
- }
758
- conditionsCheck(weight) {
759
- var capacity;
760
- capacity = this.computeCapacity();
761
- return capacity == null || weight <= capacity;
762
- }
763
- __incrementReservoir__(incr) {
764
- var _this8 = this;
765
- return _asyncToGenerator2(function* () {
766
- var reservoir;
767
- yield _this8.yieldLoop();
768
- reservoir = _this8.storeOptions.reservoir += incr;
769
- _this8.instance._drainAll(_this8.computeCapacity());
770
- return reservoir;
771
- })();
772
- }
773
- __currentReservoir__() {
774
- var _this9 = this;
775
- return _asyncToGenerator2(function* () {
776
- yield _this9.yieldLoop();
777
- return _this9.storeOptions.reservoir;
778
- })();
779
- }
780
- isBlocked(now) {
781
- return this._unblockTime >= now;
782
- }
783
- check(weight, now) {
784
- return this.conditionsCheck(weight) && this._nextRequest - now <= 0;
785
- }
786
- __check__(weight) {
787
- var _this10 = this;
788
- return _asyncToGenerator2(function* () {
789
- var now;
790
- yield _this10.yieldLoop();
791
- now = Date.now();
792
- return _this10.check(weight, now);
793
- })();
794
- }
795
- __register__(index, weight, expiration) {
796
- var _this11 = this;
797
- return _asyncToGenerator2(function* () {
798
- var now, wait;
799
- yield _this11.yieldLoop();
800
- now = Date.now();
801
- if (_this11.conditionsCheck(weight)) {
802
- _this11._running += weight;
803
- if (_this11.storeOptions.reservoir != null) {
804
- _this11.storeOptions.reservoir -= weight;
805
- }
806
- wait = Math.max(_this11._nextRequest - now, 0);
807
- _this11._nextRequest = now + wait + _this11.storeOptions.minTime;
808
- return {
809
- success: true,
810
- wait,
811
- reservoir: _this11.storeOptions.reservoir
812
- };
813
- } else {
814
- return {
815
- success: false
816
- };
817
- }
818
- })();
819
- }
820
- strategyIsBlock() {
821
- return this.storeOptions.strategy === 3;
822
- }
823
- __submit__(queueLength, weight) {
824
- var _this12 = this;
825
- return _asyncToGenerator2(function* () {
826
- var blocked, now, reachedHWM;
827
- yield _this12.yieldLoop();
828
- if (_this12.storeOptions.maxConcurrent != null && weight > _this12.storeOptions.maxConcurrent) {
829
- throw new BottleneckError(`Impossible to add a job having a weight of ${weight} to a limiter having a maxConcurrent setting of ${_this12.storeOptions.maxConcurrent}`);
830
- }
831
- now = Date.now();
832
- reachedHWM = _this12.storeOptions.highWater != null && queueLength === _this12.storeOptions.highWater && !_this12.check(weight, now);
833
- blocked = _this12.strategyIsBlock() && (reachedHWM || _this12.isBlocked(now));
834
- if (blocked) {
835
- _this12._unblockTime = now + _this12.computePenalty();
836
- _this12._nextRequest = _this12._unblockTime + _this12.storeOptions.minTime;
837
- _this12.instance._dropAllQueued();
838
- }
839
- return {
840
- reachedHWM,
841
- blocked,
842
- strategy: _this12.storeOptions.strategy
843
- };
844
- })();
845
- }
846
- __free__(index, weight) {
847
- var _this13 = this;
848
- return _asyncToGenerator2(function* () {
849
- yield _this13.yieldLoop();
850
- _this13._running -= weight;
851
- _this13._done += weight;
852
- _this13.instance._drainAll(_this13.computeCapacity());
853
- return {
854
- running: _this13._running
855
- };
856
- })();
857
- }
858
- };
859
- module2.exports = LocalDatastore;
860
- }
861
- });
862
-
863
- // node_modules/bottleneck/lib/lua.json
864
- var require_lua = __commonJS({
865
- "node_modules/bottleneck/lib/lua.json"(exports2, module2) {
866
- module2.exports = {
867
- "blacklist_client.lua": "local blacklist = ARGV[num_static_argv + 1]\n\nif redis.call('zscore', client_last_seen_key, blacklist) then\n redis.call('zadd', client_last_seen_key, 0, blacklist)\nend\n\n\nreturn {}\n",
868
- "check.lua": "local weight = tonumber(ARGV[num_static_argv + 1])\n\nlocal capacity = process_tick(now, false)['capacity']\nlocal nextRequest = tonumber(redis.call('hget', settings_key, 'nextRequest'))\n\nreturn conditions_check(capacity, weight) and nextRequest - now <= 0\n",
869
- "conditions_check.lua": "local conditions_check = function (capacity, weight)\n return capacity == nil or weight <= capacity\nend\n",
870
- "current_reservoir.lua": "return process_tick(now, false)['reservoir']\n",
871
- "done.lua": "process_tick(now, false)\n\nreturn tonumber(redis.call('hget', settings_key, 'done'))\n",
872
- "free.lua": "local index = ARGV[num_static_argv + 1]\n\nredis.call('zadd', job_expirations_key, 0, index)\n\nreturn process_tick(now, false)['running']\n",
873
- "get_time.lua": "redis.replicate_commands()\n\nlocal get_time = function ()\n local time = redis.call('time')\n\n return tonumber(time[1]..string.sub(time[2], 1, 3))\nend\n",
874
- "group_check.lua": "return not (redis.call('exists', settings_key) == 1)\n",
875
- "heartbeat.lua": "process_tick(now, true)\n",
876
- "increment_reservoir.lua": "local incr = tonumber(ARGV[num_static_argv + 1])\n\nredis.call('hincrby', settings_key, 'reservoir', incr)\n\nlocal reservoir = process_tick(now, true)['reservoir']\n\nlocal groupTimeout = tonumber(redis.call('hget', settings_key, 'groupTimeout'))\nrefresh_expiration(0, 0, groupTimeout)\n\nreturn reservoir\n",
877
- "init.lua": `local clear = tonumber(ARGV[num_static_argv + 1])
878
- local limiter_version = ARGV[num_static_argv + 2]
879
- local num_local_argv = num_static_argv + 2
880
-
881
- if clear == 1 then
882
- redis.call('del', unpack(KEYS))
883
- end
884
-
885
- if redis.call('exists', settings_key) == 0 then
886
- -- Create
887
- local args = {'hmset', settings_key}
888
-
889
- for i = num_local_argv + 1, #ARGV do
890
- table.insert(args, ARGV[i])
891
- end
892
-
893
- redis.call(unpack(args))
894
- redis.call('hmset', settings_key,
895
- 'nextRequest', now,
896
- 'lastReservoirRefresh', now,
897
- 'lastReservoirIncrease', now,
898
- 'running', 0,
899
- 'done', 0,
900
- 'unblockTime', 0,
901
- 'capacityPriorityCounter', 0
902
- )
903
-
904
- else
905
- -- Apply migrations
906
- local settings = redis.call('hmget', settings_key,
907
- 'id',
908
- 'version'
909
- )
910
- local id = settings[1]
911
- local current_version = settings[2]
912
-
913
- if current_version ~= limiter_version then
914
- local version_digits = {}
915
- for k, v in string.gmatch(current_version, "([^.]+)") do
916
- table.insert(version_digits, tonumber(k))
917
- end
918
-
919
- -- 2.10.0
920
- if version_digits[2] < 10 then
921
- redis.call('hsetnx', settings_key, 'reservoirRefreshInterval', '')
922
- redis.call('hsetnx', settings_key, 'reservoirRefreshAmount', '')
923
- redis.call('hsetnx', settings_key, 'lastReservoirRefresh', '')
924
- redis.call('hsetnx', settings_key, 'done', 0)
925
- redis.call('hset', settings_key, 'version', '2.10.0')
926
- end
927
-
928
- -- 2.11.1
929
- if version_digits[2] < 11 or (version_digits[2] == 11 and version_digits[3] < 1) then
930
- if redis.call('hstrlen', settings_key, 'lastReservoirRefresh') == 0 then
931
- redis.call('hmset', settings_key,
932
- 'lastReservoirRefresh', now,
933
- 'version', '2.11.1'
934
- )
935
- end
936
- end
937
-
938
- -- 2.14.0
939
- if version_digits[2] < 14 then
940
- local old_running_key = 'b_'..id..'_running'
941
- local old_executing_key = 'b_'..id..'_executing'
942
-
943
- if redis.call('exists', old_running_key) == 1 then
944
- redis.call('rename', old_running_key, job_weights_key)
945
- end
946
- if redis.call('exists', old_executing_key) == 1 then
947
- redis.call('rename', old_executing_key, job_expirations_key)
948
- end
949
- redis.call('hset', settings_key, 'version', '2.14.0')
950
- end
951
-
952
- -- 2.15.2
953
- if version_digits[2] < 15 or (version_digits[2] == 15 and version_digits[3] < 2) then
954
- redis.call('hsetnx', settings_key, 'capacityPriorityCounter', 0)
955
- redis.call('hset', settings_key, 'version', '2.15.2')
956
- end
957
-
958
- -- 2.17.0
959
- if version_digits[2] < 17 then
960
- redis.call('hsetnx', settings_key, 'clientTimeout', 10000)
961
- redis.call('hset', settings_key, 'version', '2.17.0')
962
- end
963
-
964
- -- 2.18.0
965
- if version_digits[2] < 18 then
966
- redis.call('hsetnx', settings_key, 'reservoirIncreaseInterval', '')
967
- redis.call('hsetnx', settings_key, 'reservoirIncreaseAmount', '')
968
- redis.call('hsetnx', settings_key, 'reservoirIncreaseMaximum', '')
969
- redis.call('hsetnx', settings_key, 'lastReservoirIncrease', now)
970
- redis.call('hset', settings_key, 'version', '2.18.0')
971
- end
972
-
973
- end
974
-
975
- process_tick(now, false)
976
- end
977
-
978
- local groupTimeout = tonumber(redis.call('hget', settings_key, 'groupTimeout'))
979
- refresh_expiration(0, 0, groupTimeout)
980
-
981
- return {}
982
- `,
983
- "process_tick.lua": "local process_tick = function (now, always_publish)\n\n local compute_capacity = function (maxConcurrent, running, reservoir)\n if maxConcurrent ~= nil and reservoir ~= nil then\n return math.min((maxConcurrent - running), reservoir)\n elseif maxConcurrent ~= nil then\n return maxConcurrent - running\n elseif reservoir ~= nil then\n return reservoir\n else\n return nil\n end\n end\n\n local settings = redis.call('hmget', settings_key,\n 'id',\n 'maxConcurrent',\n 'running',\n 'reservoir',\n 'reservoirRefreshInterval',\n 'reservoirRefreshAmount',\n 'lastReservoirRefresh',\n 'reservoirIncreaseInterval',\n 'reservoirIncreaseAmount',\n 'reservoirIncreaseMaximum',\n 'lastReservoirIncrease',\n 'capacityPriorityCounter',\n 'clientTimeout'\n )\n local id = settings[1]\n local maxConcurrent = tonumber(settings[2])\n local running = tonumber(settings[3])\n local reservoir = tonumber(settings[4])\n local reservoirRefreshInterval = tonumber(settings[5])\n local reservoirRefreshAmount = tonumber(settings[6])\n local lastReservoirRefresh = tonumber(settings[7])\n local reservoirIncreaseInterval = tonumber(settings[8])\n local reservoirIncreaseAmount = tonumber(settings[9])\n local reservoirIncreaseMaximum = tonumber(settings[10])\n local lastReservoirIncrease = tonumber(settings[11])\n local capacityPriorityCounter = tonumber(settings[12])\n local clientTimeout = tonumber(settings[13])\n\n local initial_capacity = compute_capacity(maxConcurrent, running, reservoir)\n\n --\n -- Process 'running' changes\n --\n local expired = redis.call('zrangebyscore', job_expirations_key, '-inf', '('..now)\n\n if #expired > 0 then\n redis.call('zremrangebyscore', job_expirations_key, '-inf', '('..now)\n\n local flush_batch = function (batch, acc)\n local weights = redis.call('hmget', job_weights_key, unpack(batch))\n redis.call('hdel', job_weights_key, unpack(batch))\n local clients = redis.call('hmget', job_clients_key, unpack(batch))\n redis.call('hdel', job_clients_key, unpack(batch))\n\n -- Calculate sum of removed weights\n for i = 1, #weights do\n acc['total'] = acc['total'] + (tonumber(weights[i]) or 0)\n end\n\n -- Calculate sum of removed weights by client\n local client_weights = {}\n for i = 1, #clients do\n local removed = tonumber(weights[i]) or 0\n if removed > 0 then\n acc['client_weights'][clients[i]] = (acc['client_weights'][clients[i]] or 0) + removed\n end\n end\n end\n\n local acc = {\n ['total'] = 0,\n ['client_weights'] = {}\n }\n local batch_size = 1000\n\n -- Compute changes to Zsets and apply changes to Hashes\n for i = 1, #expired, batch_size do\n local batch = {}\n for j = i, math.min(i + batch_size - 1, #expired) do\n table.insert(batch, expired[j])\n end\n\n flush_batch(batch, acc)\n end\n\n -- Apply changes to Zsets\n if acc['total'] > 0 then\n redis.call('hincrby', settings_key, 'done', acc['total'])\n running = tonumber(redis.call('hincrby', settings_key, 'running', -acc['total']))\n end\n\n for client, weight in pairs(acc['client_weights']) do\n redis.call('zincrby', client_running_key, -weight, client)\n end\n end\n\n --\n -- Process 'reservoir' changes\n --\n local reservoirRefreshActive = reservoirRefreshInterval ~= nil and reservoirRefreshAmount ~= nil\n if reservoirRefreshActive and now >= lastReservoirRefresh + reservoirRefreshInterval then\n reservoir = reservoirRefreshAmount\n redis.call('hmset', settings_key,\n 'reservoir', reservoir,\n 'lastReservoirRefresh', now\n )\n end\n\n local reservoirIncreaseActive = reservoirIncreaseInterval ~= nil and reservoirIncreaseAmount ~= nil\n if reservoirIncreaseActive and now >= lastReservoirIncrease + reservoirIncreaseInterval then\n local num_intervals = math.floor((now - lastReservoirIncrease) / reservoirIncreaseInterval)\n local incr = reservoirIncreaseAmount * num_intervals\n if reservoirIncreaseMaximum ~= nil then\n incr = math.min(incr, reservoirIncreaseMaximum - (reservoir or 0))\n end\n if incr > 0 then\n reservoir = (reservoir or 0) + incr\n end\n redis.call('hmset', settings_key,\n 'reservoir', reservoir,\n 'lastReservoirIncrease', lastReservoirIncrease + (num_intervals * reservoirIncreaseInterval)\n )\n end\n\n --\n -- Clear unresponsive clients\n --\n local unresponsive = redis.call('zrangebyscore', client_last_seen_key, '-inf', (now - clientTimeout))\n local unresponsive_lookup = {}\n local terminated_clients = {}\n for i = 1, #unresponsive do\n unresponsive_lookup[unresponsive[i]] = true\n if tonumber(redis.call('zscore', client_running_key, unresponsive[i])) == 0 then\n table.insert(terminated_clients, unresponsive[i])\n end\n end\n if #terminated_clients > 0 then\n redis.call('zrem', client_running_key, unpack(terminated_clients))\n redis.call('hdel', client_num_queued_key, unpack(terminated_clients))\n redis.call('zrem', client_last_registered_key, unpack(terminated_clients))\n redis.call('zrem', client_last_seen_key, unpack(terminated_clients))\n end\n\n --\n -- Broadcast capacity changes\n --\n local final_capacity = compute_capacity(maxConcurrent, running, reservoir)\n\n if always_publish or (initial_capacity ~= nil and final_capacity == nil) then\n -- always_publish or was not unlimited, now unlimited\n redis.call('publish', 'b_'..id, 'capacity:'..(final_capacity or ''))\n\n elseif initial_capacity ~= nil and final_capacity ~= nil and final_capacity > initial_capacity then\n -- capacity was increased\n -- send the capacity message to the limiter having the lowest number of running jobs\n -- the tiebreaker is the limiter having not registered a job in the longest time\n\n local lowest_concurrency_value = nil\n local lowest_concurrency_clients = {}\n local lowest_concurrency_last_registered = {}\n local client_concurrencies = redis.call('zrange', client_running_key, 0, -1, 'withscores')\n\n for i = 1, #client_concurrencies, 2 do\n local client = client_concurrencies[i]\n local concurrency = tonumber(client_concurrencies[i+1])\n\n if (\n lowest_concurrency_value == nil or lowest_concurrency_value == concurrency\n ) and (\n not unresponsive_lookup[client]\n ) and (\n tonumber(redis.call('hget', client_num_queued_key, client)) > 0\n ) then\n lowest_concurrency_value = concurrency\n table.insert(lowest_concurrency_clients, client)\n local last_registered = tonumber(redis.call('zscore', client_last_registered_key, client))\n table.insert(lowest_concurrency_last_registered, last_registered)\n end\n end\n\n if #lowest_concurrency_clients > 0 then\n local position = 1\n local earliest = lowest_concurrency_last_registered[1]\n\n for i,v in ipairs(lowest_concurrency_last_registered) do\n if v < earliest then\n position = i\n earliest = v\n end\n end\n\n local next_client = lowest_concurrency_clients[position]\n redis.call('publish', 'b_'..id,\n 'capacity-priority:'..(final_capacity or '')..\n ':'..next_client..\n ':'..capacityPriorityCounter\n )\n redis.call('hincrby', settings_key, 'capacityPriorityCounter', '1')\n else\n redis.call('publish', 'b_'..id, 'capacity:'..(final_capacity or ''))\n end\n end\n\n return {\n ['capacity'] = final_capacity,\n ['running'] = running,\n ['reservoir'] = reservoir\n }\nend\n",
984
- "queued.lua": "local clientTimeout = tonumber(redis.call('hget', settings_key, 'clientTimeout'))\nlocal valid_clients = redis.call('zrangebyscore', client_last_seen_key, (now - clientTimeout), 'inf')\nlocal client_queued = redis.call('hmget', client_num_queued_key, unpack(valid_clients))\n\nlocal sum = 0\nfor i = 1, #client_queued do\n sum = sum + tonumber(client_queued[i])\nend\n\nreturn sum\n",
985
- "refresh_expiration.lua": "local refresh_expiration = function (now, nextRequest, groupTimeout)\n\n if groupTimeout ~= nil then\n local ttl = (nextRequest + groupTimeout) - now\n\n for i = 1, #KEYS do\n redis.call('pexpire', KEYS[i], ttl)\n end\n end\n\nend\n",
986
- "refs.lua": "local settings_key = KEYS[1]\nlocal job_weights_key = KEYS[2]\nlocal job_expirations_key = KEYS[3]\nlocal job_clients_key = KEYS[4]\nlocal client_running_key = KEYS[5]\nlocal client_num_queued_key = KEYS[6]\nlocal client_last_registered_key = KEYS[7]\nlocal client_last_seen_key = KEYS[8]\n\nlocal now = tonumber(ARGV[1])\nlocal client = ARGV[2]\n\nlocal num_static_argv = 2\n",
987
- "register.lua": "local index = ARGV[num_static_argv + 1]\nlocal weight = tonumber(ARGV[num_static_argv + 2])\nlocal expiration = tonumber(ARGV[num_static_argv + 3])\n\nlocal state = process_tick(now, false)\nlocal capacity = state['capacity']\nlocal reservoir = state['reservoir']\n\nlocal settings = redis.call('hmget', settings_key,\n 'nextRequest',\n 'minTime',\n 'groupTimeout'\n)\nlocal nextRequest = tonumber(settings[1])\nlocal minTime = tonumber(settings[2])\nlocal groupTimeout = tonumber(settings[3])\n\nif conditions_check(capacity, weight) then\n\n redis.call('hincrby', settings_key, 'running', weight)\n redis.call('hset', job_weights_key, index, weight)\n if expiration ~= nil then\n redis.call('zadd', job_expirations_key, now + expiration, index)\n end\n redis.call('hset', job_clients_key, index, client)\n redis.call('zincrby', client_running_key, weight, client)\n redis.call('hincrby', client_num_queued_key, client, -1)\n redis.call('zadd', client_last_registered_key, now, client)\n\n local wait = math.max(nextRequest - now, 0)\n local newNextRequest = now + wait + minTime\n\n if reservoir == nil then\n redis.call('hset', settings_key,\n 'nextRequest', newNextRequest\n )\n else\n reservoir = reservoir - weight\n redis.call('hmset', settings_key,\n 'reservoir', reservoir,\n 'nextRequest', newNextRequest\n )\n end\n\n refresh_expiration(now, newNextRequest, groupTimeout)\n\n return {true, wait, reservoir}\n\nelse\n return {false}\nend\n",
988
- "register_client.lua": "local queued = tonumber(ARGV[num_static_argv + 1])\n\n-- Could have been re-registered concurrently\nif not redis.call('zscore', client_last_seen_key, client) then\n redis.call('zadd', client_running_key, 0, client)\n redis.call('hset', client_num_queued_key, client, queued)\n redis.call('zadd', client_last_registered_key, 0, client)\nend\n\nredis.call('zadd', client_last_seen_key, now, client)\n\nreturn {}\n",
989
- "running.lua": "return process_tick(now, false)['running']\n",
990
- "submit.lua": "local queueLength = tonumber(ARGV[num_static_argv + 1])\nlocal weight = tonumber(ARGV[num_static_argv + 2])\n\nlocal capacity = process_tick(now, false)['capacity']\n\nlocal settings = redis.call('hmget', settings_key,\n 'id',\n 'maxConcurrent',\n 'highWater',\n 'nextRequest',\n 'strategy',\n 'unblockTime',\n 'penalty',\n 'minTime',\n 'groupTimeout'\n)\nlocal id = settings[1]\nlocal maxConcurrent = tonumber(settings[2])\nlocal highWater = tonumber(settings[3])\nlocal nextRequest = tonumber(settings[4])\nlocal strategy = tonumber(settings[5])\nlocal unblockTime = tonumber(settings[6])\nlocal penalty = tonumber(settings[7])\nlocal minTime = tonumber(settings[8])\nlocal groupTimeout = tonumber(settings[9])\n\nif maxConcurrent ~= nil and weight > maxConcurrent then\n return redis.error_reply('OVERWEIGHT:'..weight..':'..maxConcurrent)\nend\n\nlocal reachedHWM = (highWater ~= nil and queueLength == highWater\n and not (\n conditions_check(capacity, weight)\n and nextRequest - now <= 0\n )\n)\n\nlocal blocked = strategy == 3 and (reachedHWM or unblockTime >= now)\n\nif blocked then\n local computedPenalty = penalty\n if computedPenalty == nil then\n if minTime == 0 then\n computedPenalty = 5000\n else\n computedPenalty = 15 * minTime\n end\n end\n\n local newNextRequest = now + computedPenalty + minTime\n\n redis.call('hmset', settings_key,\n 'unblockTime', now + computedPenalty,\n 'nextRequest', newNextRequest\n )\n\n local clients_queued_reset = redis.call('hkeys', client_num_queued_key)\n local queued_reset = {}\n for i = 1, #clients_queued_reset do\n table.insert(queued_reset, clients_queued_reset[i])\n table.insert(queued_reset, 0)\n end\n redis.call('hmset', client_num_queued_key, unpack(queued_reset))\n\n redis.call('publish', 'b_'..id, 'blocked:')\n\n refresh_expiration(now, newNextRequest, groupTimeout)\nend\n\nif not blocked and not reachedHWM then\n redis.call('hincrby', client_num_queued_key, client, 1)\nend\n\nreturn {reachedHWM, blocked, strategy}\n",
991
- "update_settings.lua": "local args = {'hmset', settings_key}\n\nfor i = num_static_argv + 1, #ARGV do\n table.insert(args, ARGV[i])\nend\n\nredis.call(unpack(args))\n\nprocess_tick(now, true)\n\nlocal groupTimeout = tonumber(redis.call('hget', settings_key, 'groupTimeout'))\nrefresh_expiration(0, 0, groupTimeout)\n\nreturn {}\n",
992
- "validate_client.lua": "if not redis.call('zscore', client_last_seen_key, client) then\n return redis.error_reply('UNKNOWN_CLIENT')\nend\n\nredis.call('zadd', client_last_seen_key, now, client)\n",
993
- "validate_keys.lua": "if not (redis.call('exists', settings_key) == 1) then\n return redis.error_reply('SETTINGS_KEY_NOT_FOUND')\nend\n"
994
- };
995
- }
996
- });
997
-
998
- // node_modules/bottleneck/lib/Scripts.js
999
- var require_Scripts = __commonJS({
1000
- "node_modules/bottleneck/lib/Scripts.js"(exports2) {
1001
- "use strict";
1002
- var headers;
1003
- var lua;
1004
- var templates;
1005
- lua = require_lua();
1006
- headers = {
1007
- refs: lua["refs.lua"],
1008
- validate_keys: lua["validate_keys.lua"],
1009
- validate_client: lua["validate_client.lua"],
1010
- refresh_expiration: lua["refresh_expiration.lua"],
1011
- process_tick: lua["process_tick.lua"],
1012
- conditions_check: lua["conditions_check.lua"],
1013
- get_time: lua["get_time.lua"]
1014
- };
1015
- exports2.allKeys = function(id) {
1016
- return [
1017
- /*
1018
- HASH
1019
- */
1020
- `b_${id}_settings`,
1021
- /*
1022
- HASH
1023
- job index -> weight
1024
- */
1025
- `b_${id}_job_weights`,
1026
- /*
1027
- ZSET
1028
- job index -> expiration
1029
- */
1030
- `b_${id}_job_expirations`,
1031
- /*
1032
- HASH
1033
- job index -> client
1034
- */
1035
- `b_${id}_job_clients`,
1036
- /*
1037
- ZSET
1038
- client -> sum running
1039
- */
1040
- `b_${id}_client_running`,
1041
- /*
1042
- HASH
1043
- client -> num queued
1044
- */
1045
- `b_${id}_client_num_queued`,
1046
- /*
1047
- ZSET
1048
- client -> last job registered
1049
- */
1050
- `b_${id}_client_last_registered`,
1051
- /*
1052
- ZSET
1053
- client -> last seen
1054
- */
1055
- `b_${id}_client_last_seen`
1056
- ];
1057
- };
1058
- templates = {
1059
- init: {
1060
- keys: exports2.allKeys,
1061
- headers: ["process_tick"],
1062
- refresh_expiration: true,
1063
- code: lua["init.lua"]
1064
- },
1065
- group_check: {
1066
- keys: exports2.allKeys,
1067
- headers: [],
1068
- refresh_expiration: false,
1069
- code: lua["group_check.lua"]
1070
- },
1071
- register_client: {
1072
- keys: exports2.allKeys,
1073
- headers: ["validate_keys"],
1074
- refresh_expiration: false,
1075
- code: lua["register_client.lua"]
1076
- },
1077
- blacklist_client: {
1078
- keys: exports2.allKeys,
1079
- headers: ["validate_keys", "validate_client"],
1080
- refresh_expiration: false,
1081
- code: lua["blacklist_client.lua"]
1082
- },
1083
- heartbeat: {
1084
- keys: exports2.allKeys,
1085
- headers: ["validate_keys", "validate_client", "process_tick"],
1086
- refresh_expiration: false,
1087
- code: lua["heartbeat.lua"]
1088
- },
1089
- update_settings: {
1090
- keys: exports2.allKeys,
1091
- headers: ["validate_keys", "validate_client", "process_tick"],
1092
- refresh_expiration: true,
1093
- code: lua["update_settings.lua"]
1094
- },
1095
- running: {
1096
- keys: exports2.allKeys,
1097
- headers: ["validate_keys", "validate_client", "process_tick"],
1098
- refresh_expiration: false,
1099
- code: lua["running.lua"]
1100
- },
1101
- queued: {
1102
- keys: exports2.allKeys,
1103
- headers: ["validate_keys", "validate_client"],
1104
- refresh_expiration: false,
1105
- code: lua["queued.lua"]
1106
- },
1107
- done: {
1108
- keys: exports2.allKeys,
1109
- headers: ["validate_keys", "validate_client", "process_tick"],
1110
- refresh_expiration: false,
1111
- code: lua["done.lua"]
1112
- },
1113
- check: {
1114
- keys: exports2.allKeys,
1115
- headers: ["validate_keys", "validate_client", "process_tick", "conditions_check"],
1116
- refresh_expiration: false,
1117
- code: lua["check.lua"]
1118
- },
1119
- submit: {
1120
- keys: exports2.allKeys,
1121
- headers: ["validate_keys", "validate_client", "process_tick", "conditions_check"],
1122
- refresh_expiration: true,
1123
- code: lua["submit.lua"]
1124
- },
1125
- register: {
1126
- keys: exports2.allKeys,
1127
- headers: ["validate_keys", "validate_client", "process_tick", "conditions_check"],
1128
- refresh_expiration: true,
1129
- code: lua["register.lua"]
1130
- },
1131
- free: {
1132
- keys: exports2.allKeys,
1133
- headers: ["validate_keys", "validate_client", "process_tick"],
1134
- refresh_expiration: true,
1135
- code: lua["free.lua"]
1136
- },
1137
- current_reservoir: {
1138
- keys: exports2.allKeys,
1139
- headers: ["validate_keys", "validate_client", "process_tick"],
1140
- refresh_expiration: false,
1141
- code: lua["current_reservoir.lua"]
1142
- },
1143
- increment_reservoir: {
1144
- keys: exports2.allKeys,
1145
- headers: ["validate_keys", "validate_client", "process_tick"],
1146
- refresh_expiration: true,
1147
- code: lua["increment_reservoir.lua"]
1148
- }
1149
- };
1150
- exports2.names = Object.keys(templates);
1151
- exports2.keys = function(name2, id) {
1152
- return templates[name2].keys(id);
1153
- };
1154
- exports2.payload = function(name2) {
1155
- var template2;
1156
- template2 = templates[name2];
1157
- return Array.prototype.concat(headers.refs, template2.headers.map(function(h2) {
1158
- return headers[h2];
1159
- }), template2.refresh_expiration ? headers.refresh_expiration : "", template2.code).join("\n");
1160
- };
1161
- }
1162
- });
1163
-
1164
- // node_modules/bottleneck/lib/RedisConnection.js
1165
- var require_RedisConnection = __commonJS({
1166
- "node_modules/bottleneck/lib/RedisConnection.js"(exports, module) {
1167
- "use strict";
1168
- function asyncGeneratorStep(gen, resolve3, reject, _next, _throw, key, arg) {
1169
- try {
1170
- var info = gen[key](arg);
1171
- var value = info.value;
1172
- } catch (error) {
1173
- reject(error);
1174
- return;
1175
- }
1176
- if (info.done) {
1177
- resolve3(value);
1178
- } else {
1179
- Promise.resolve(value).then(_next, _throw);
1180
- }
1181
- }
1182
- __name(asyncGeneratorStep, "asyncGeneratorStep");
1183
- function _asyncToGenerator(fn) {
1184
- return function() {
1185
- var self2 = this, args = arguments;
1186
- return new Promise(function(resolve3, reject) {
1187
- var gen = fn.apply(self2, args);
1188
- function _next(value) {
1189
- asyncGeneratorStep(gen, resolve3, reject, _next, _throw, "next", value);
1190
- }
1191
- __name(_next, "_next");
1192
- function _throw(err) {
1193
- asyncGeneratorStep(gen, resolve3, reject, _next, _throw, "throw", err);
1194
- }
1195
- __name(_throw, "_throw");
1196
- _next(void 0);
1197
- });
1198
- };
1199
- }
1200
- __name(_asyncToGenerator, "_asyncToGenerator");
1201
- var Events;
1202
- var RedisConnection;
1203
- var Scripts;
1204
- var parser;
1205
- parser = require_parser();
1206
- Events = require_Events();
1207
- Scripts = require_Scripts();
1208
- RedisConnection = function() {
1209
- class RedisConnection {
1210
- static {
1211
- __name(this, "RedisConnection");
1212
- }
1213
- constructor(options = {}) {
1214
- parser.load(options, this.defaults, this);
1215
- if (this.Redis == null) {
1216
- this.Redis = eval("require")("redis");
1217
- }
1218
- if (this.Events == null) {
1219
- this.Events = new Events(this);
1220
- }
1221
- this.terminated = false;
1222
- if (this.client == null) {
1223
- this.client = this.Redis.createClient(this.clientOptions);
1224
- }
1225
- this.subscriber = this.client.duplicate();
1226
- this.limiters = {};
1227
- this.shas = {};
1228
- this.ready = this.Promise.all([this._setup(this.client, false), this._setup(this.subscriber, true)]).then(() => {
1229
- return this._loadScripts();
1230
- }).then(() => {
1231
- return {
1232
- client: this.client,
1233
- subscriber: this.subscriber
1234
- };
1235
- });
1236
- }
1237
- _setup(client, sub) {
1238
- client.setMaxListeners(0);
1239
- return new this.Promise((resolve3, reject) => {
1240
- client.on("error", (e) => {
1241
- return this.Events.trigger("error", e);
1242
- });
1243
- if (sub) {
1244
- client.on("message", (channel, message) => {
1245
- var ref;
1246
- return (ref = this.limiters[channel]) != null ? ref._store.onMessage(channel, message) : void 0;
1247
- });
1248
- }
1249
- if (client.ready) {
1250
- return resolve3();
1251
- } else {
1252
- return client.once("ready", resolve3);
1253
- }
1254
- });
1255
- }
1256
- _loadScript(name2) {
1257
- return new this.Promise((resolve3, reject) => {
1258
- var payload;
1259
- payload = Scripts.payload(name2);
1260
- return this.client.multi([["script", "load", payload]]).exec((err, replies) => {
1261
- if (err != null) {
1262
- return reject(err);
1263
- }
1264
- this.shas[name2] = replies[0];
1265
- return resolve3(replies[0]);
1266
- });
1267
- });
1268
- }
1269
- _loadScripts() {
1270
- return this.Promise.all(Scripts.names.map((k) => {
1271
- return this._loadScript(k);
1272
- }));
1273
- }
1274
- __runCommand__(cmd) {
1275
- var _this = this;
1276
- return _asyncToGenerator(function* () {
1277
- yield _this.ready;
1278
- return new _this.Promise((resolve3, reject) => {
1279
- return _this.client.multi([cmd]).exec_atomic(function(err, replies) {
1280
- if (err != null) {
1281
- return reject(err);
1282
- } else {
1283
- return resolve3(replies[0]);
1284
- }
1285
- });
1286
- });
1287
- })();
1288
- }
1289
- __addLimiter__(instance) {
1290
- return this.Promise.all([instance.channel(), instance.channel_client()].map((channel) => {
1291
- return new this.Promise((resolve3, reject) => {
1292
- var handler;
1293
- handler = /* @__PURE__ */ __name((chan) => {
1294
- if (chan === channel) {
1295
- this.subscriber.removeListener("subscribe", handler);
1296
- this.limiters[channel] = instance;
1297
- return resolve3();
1298
- }
1299
- }, "handler");
1300
- this.subscriber.on("subscribe", handler);
1301
- return this.subscriber.subscribe(channel);
1302
- });
1303
- }));
1304
- }
1305
- __removeLimiter__(instance) {
1306
- var _this2 = this;
1307
- return this.Promise.all([instance.channel(), instance.channel_client()].map(
1308
- /* @__PURE__ */ (function() {
1309
- var _ref = _asyncToGenerator(function* (channel) {
1310
- if (!_this2.terminated) {
1311
- yield new _this2.Promise((resolve3, reject) => {
1312
- return _this2.subscriber.unsubscribe(channel, function(err, chan) {
1313
- if (err != null) {
1314
- return reject(err);
1315
- }
1316
- if (chan === channel) {
1317
- return resolve3();
1318
- }
1319
- });
1320
- });
1321
- }
1322
- return delete _this2.limiters[channel];
1323
- });
1324
- return function(_x) {
1325
- return _ref.apply(this, arguments);
1326
- };
1327
- })()
1328
- ));
1329
- }
1330
- __scriptArgs__(name2, id, args, cb) {
1331
- var keys;
1332
- keys = Scripts.keys(name2, id);
1333
- return [this.shas[name2], keys.length].concat(keys, args, cb);
1334
- }
1335
- __scriptFn__(name2) {
1336
- return this.client.evalsha.bind(this.client);
1337
- }
1338
- disconnect(flush = true) {
1339
- var i, k, len, ref;
1340
- ref = Object.keys(this.limiters);
1341
- for (i = 0, len = ref.length; i < len; i++) {
1342
- k = ref[i];
1343
- clearInterval(this.limiters[k]._store.heartbeat);
1344
- }
1345
- this.limiters = {};
1346
- this.terminated = true;
1347
- this.client.end(flush);
1348
- this.subscriber.end(flush);
1349
- return this.Promise.resolve();
1350
- }
1351
- }
1352
- ;
1353
- RedisConnection.prototype.datastore = "redis";
1354
- RedisConnection.prototype.defaults = {
1355
- Redis: null,
1356
- clientOptions: {},
1357
- client: null,
1358
- Promise,
1359
- Events: null
1360
- };
1361
- return RedisConnection;
1362
- }.call(void 0);
1363
- module.exports = RedisConnection;
1364
- }
1365
- });
1366
-
1367
- // node_modules/bottleneck/lib/IORedisConnection.js
1368
- var require_IORedisConnection = __commonJS({
1369
- "node_modules/bottleneck/lib/IORedisConnection.js"(exports, module) {
1370
- "use strict";
1371
- function _slicedToArray(arr, i) {
1372
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
1373
- }
1374
- __name(_slicedToArray, "_slicedToArray");
1375
- function _nonIterableRest() {
1376
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
1377
- }
1378
- __name(_nonIterableRest, "_nonIterableRest");
1379
- function _iterableToArrayLimit(arr, i) {
1380
- var _arr = [];
1381
- var _n = true;
1382
- var _d = false;
1383
- var _e = void 0;
1384
- try {
1385
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
1386
- _arr.push(_s.value);
1387
- if (i && _arr.length === i) break;
1388
- }
1389
- } catch (err) {
1390
- _d = true;
1391
- _e = err;
1392
- } finally {
1393
- try {
1394
- if (!_n && _i["return"] != null) _i["return"]();
1395
- } finally {
1396
- if (_d) throw _e;
1397
- }
1398
- }
1399
- return _arr;
1400
- }
1401
- __name(_iterableToArrayLimit, "_iterableToArrayLimit");
1402
- function _arrayWithHoles(arr) {
1403
- if (Array.isArray(arr)) return arr;
1404
- }
1405
- __name(_arrayWithHoles, "_arrayWithHoles");
1406
- function asyncGeneratorStep(gen, resolve3, reject, _next, _throw, key, arg) {
1407
- try {
1408
- var info = gen[key](arg);
1409
- var value = info.value;
1410
- } catch (error) {
1411
- reject(error);
1412
- return;
1413
- }
1414
- if (info.done) {
1415
- resolve3(value);
1416
- } else {
1417
- Promise.resolve(value).then(_next, _throw);
1418
- }
1419
- }
1420
- __name(asyncGeneratorStep, "asyncGeneratorStep");
1421
- function _asyncToGenerator(fn) {
1422
- return function() {
1423
- var self2 = this, args = arguments;
1424
- return new Promise(function(resolve3, reject) {
1425
- var gen = fn.apply(self2, args);
1426
- function _next(value) {
1427
- asyncGeneratorStep(gen, resolve3, reject, _next, _throw, "next", value);
1428
- }
1429
- __name(_next, "_next");
1430
- function _throw(err) {
1431
- asyncGeneratorStep(gen, resolve3, reject, _next, _throw, "throw", err);
1432
- }
1433
- __name(_throw, "_throw");
1434
- _next(void 0);
1435
- });
1436
- };
1437
- }
1438
- __name(_asyncToGenerator, "_asyncToGenerator");
1439
- var Events;
1440
- var IORedisConnection;
1441
- var Scripts;
1442
- var parser;
1443
- parser = require_parser();
1444
- Events = require_Events();
1445
- Scripts = require_Scripts();
1446
- IORedisConnection = function() {
1447
- class IORedisConnection {
1448
- static {
1449
- __name(this, "IORedisConnection");
1450
- }
1451
- constructor(options = {}) {
1452
- parser.load(options, this.defaults, this);
1453
- if (this.Redis == null) {
1454
- this.Redis = eval("require")("ioredis");
1455
- }
1456
- if (this.Events == null) {
1457
- this.Events = new Events(this);
1458
- }
1459
- this.terminated = false;
1460
- if (this.clusterNodes != null) {
1461
- this.client = new this.Redis.Cluster(this.clusterNodes, this.clientOptions);
1462
- this.subscriber = new this.Redis.Cluster(this.clusterNodes, this.clientOptions);
1463
- } else if (this.client != null && this.client.duplicate == null) {
1464
- this.subscriber = new this.Redis.Cluster(this.client.startupNodes, this.client.options);
1465
- } else {
1466
- if (this.client == null) {
1467
- this.client = new this.Redis(this.clientOptions);
1468
- }
1469
- this.subscriber = this.client.duplicate();
1470
- }
1471
- this.limiters = {};
1472
- this.ready = this.Promise.all([this._setup(this.client, false), this._setup(this.subscriber, true)]).then(() => {
1473
- this._loadScripts();
1474
- return {
1475
- client: this.client,
1476
- subscriber: this.subscriber
1477
- };
1478
- });
1479
- }
1480
- _setup(client, sub) {
1481
- client.setMaxListeners(0);
1482
- return new this.Promise((resolve3, reject) => {
1483
- client.on("error", (e) => {
1484
- return this.Events.trigger("error", e);
1485
- });
1486
- if (sub) {
1487
- client.on("message", (channel, message) => {
1488
- var ref;
1489
- return (ref = this.limiters[channel]) != null ? ref._store.onMessage(channel, message) : void 0;
1490
- });
1491
- }
1492
- if (client.status === "ready") {
1493
- return resolve3();
1494
- } else {
1495
- return client.once("ready", resolve3);
1496
- }
1497
- });
1498
- }
1499
- _loadScripts() {
1500
- return Scripts.names.forEach((name2) => {
1501
- return this.client.defineCommand(name2, {
1502
- lua: Scripts.payload(name2)
1503
- });
1504
- });
1505
- }
1506
- __runCommand__(cmd) {
1507
- var _this = this;
1508
- return _asyncToGenerator(function* () {
1509
- var _, deleted;
1510
- yield _this.ready;
1511
- var _ref = yield _this.client.pipeline([cmd]).exec();
1512
- var _ref2 = _slicedToArray(_ref, 1);
1513
- var _ref2$ = _slicedToArray(_ref2[0], 2);
1514
- _ = _ref2$[0];
1515
- deleted = _ref2$[1];
1516
- return deleted;
1517
- })();
1518
- }
1519
- __addLimiter__(instance) {
1520
- return this.Promise.all([instance.channel(), instance.channel_client()].map((channel) => {
1521
- return new this.Promise((resolve3, reject) => {
1522
- return this.subscriber.subscribe(channel, () => {
1523
- this.limiters[channel] = instance;
1524
- return resolve3();
1525
- });
1526
- });
1527
- }));
1528
- }
1529
- __removeLimiter__(instance) {
1530
- var _this2 = this;
1531
- return [instance.channel(), instance.channel_client()].forEach(
1532
- /* @__PURE__ */ (function() {
1533
- var _ref3 = _asyncToGenerator(function* (channel) {
1534
- if (!_this2.terminated) {
1535
- yield _this2.subscriber.unsubscribe(channel);
1536
- }
1537
- return delete _this2.limiters[channel];
1538
- });
1539
- return function(_x) {
1540
- return _ref3.apply(this, arguments);
1541
- };
1542
- })()
1543
- );
1544
- }
1545
- __scriptArgs__(name2, id, args, cb) {
1546
- var keys;
1547
- keys = Scripts.keys(name2, id);
1548
- return [keys.length].concat(keys, args, cb);
1549
- }
1550
- __scriptFn__(name2) {
1551
- return this.client[name2].bind(this.client);
1552
- }
1553
- disconnect(flush = true) {
1554
- var i, k, len, ref;
1555
- ref = Object.keys(this.limiters);
1556
- for (i = 0, len = ref.length; i < len; i++) {
1557
- k = ref[i];
1558
- clearInterval(this.limiters[k]._store.heartbeat);
1559
- }
1560
- this.limiters = {};
1561
- this.terminated = true;
1562
- if (flush) {
1563
- return this.Promise.all([this.client.quit(), this.subscriber.quit()]);
1564
- } else {
1565
- this.client.disconnect();
1566
- this.subscriber.disconnect();
1567
- return this.Promise.resolve();
1568
- }
1569
- }
1570
- }
1571
- ;
1572
- IORedisConnection.prototype.datastore = "ioredis";
1573
- IORedisConnection.prototype.defaults = {
1574
- Redis: null,
1575
- clientOptions: {},
1576
- clusterNodes: null,
1577
- client: null,
1578
- Promise,
1579
- Events: null
1580
- };
1581
- return IORedisConnection;
1582
- }.call(void 0);
1583
- module.exports = IORedisConnection;
1584
- }
1585
- });
1586
-
1587
- // node_modules/bottleneck/lib/RedisDatastore.js
1588
- var require_RedisDatastore = __commonJS({
1589
- "node_modules/bottleneck/lib/RedisDatastore.js"(exports2, module2) {
1590
- "use strict";
1591
- function _slicedToArray2(arr, i) {
1592
- return _arrayWithHoles2(arr) || _iterableToArrayLimit2(arr, i) || _nonIterableRest2();
1593
- }
1594
- __name(_slicedToArray2, "_slicedToArray");
1595
- function _nonIterableRest2() {
1596
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
1597
- }
1598
- __name(_nonIterableRest2, "_nonIterableRest");
1599
- function _iterableToArrayLimit2(arr, i) {
1600
- var _arr = [];
1601
- var _n = true;
1602
- var _d = false;
1603
- var _e = void 0;
1604
- try {
1605
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
1606
- _arr.push(_s.value);
1607
- if (i && _arr.length === i) break;
1608
- }
1609
- } catch (err) {
1610
- _d = true;
1611
- _e = err;
1612
- } finally {
1613
- try {
1614
- if (!_n && _i["return"] != null) _i["return"]();
1615
- } finally {
1616
- if (_d) throw _e;
1617
- }
1618
- }
1619
- return _arr;
1620
- }
1621
- __name(_iterableToArrayLimit2, "_iterableToArrayLimit");
1622
- function _arrayWithHoles2(arr) {
1623
- if (Array.isArray(arr)) return arr;
1624
- }
1625
- __name(_arrayWithHoles2, "_arrayWithHoles");
1626
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
1627
- try {
1628
- var info = gen[key](arg);
1629
- var value = info.value;
1630
- } catch (error) {
1631
- reject(error);
1632
- return;
1633
- }
1634
- if (info.done) {
1635
- resolve3(value);
1636
- } else {
1637
- Promise.resolve(value).then(_next, _throw);
1638
- }
1639
- }
1640
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
1641
- function _asyncToGenerator2(fn) {
1642
- return function() {
1643
- var self2 = this, args = arguments;
1644
- return new Promise(function(resolve3, reject) {
1645
- var gen = fn.apply(self2, args);
1646
- function _next(value) {
1647
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
1648
- }
1649
- __name(_next, "_next");
1650
- function _throw(err) {
1651
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
1652
- }
1653
- __name(_throw, "_throw");
1654
- _next(void 0);
1655
- });
1656
- };
1657
- }
1658
- __name(_asyncToGenerator2, "_asyncToGenerator");
1659
- var BottleneckError;
1660
- var IORedisConnection2;
1661
- var RedisConnection2;
1662
- var RedisDatastore;
1663
- var parser2;
1664
- parser2 = require_parser();
1665
- BottleneckError = require_BottleneckError();
1666
- RedisConnection2 = require_RedisConnection();
1667
- IORedisConnection2 = require_IORedisConnection();
1668
- RedisDatastore = class RedisDatastore {
1669
- static {
1670
- __name(this, "RedisDatastore");
1671
- }
1672
- constructor(instance, storeOptions, storeInstanceOptions) {
1673
- this.instance = instance;
1674
- this.storeOptions = storeOptions;
1675
- this.originalId = this.instance.id;
1676
- this.clientId = this.instance._randomIndex();
1677
- parser2.load(storeInstanceOptions, storeInstanceOptions, this);
1678
- this.clients = {};
1679
- this.capacityPriorityCounters = {};
1680
- this.sharedConnection = this.connection != null;
1681
- if (this.connection == null) {
1682
- this.connection = this.instance.datastore === "redis" ? new RedisConnection2({
1683
- Redis: this.Redis,
1684
- clientOptions: this.clientOptions,
1685
- Promise: this.Promise,
1686
- Events: this.instance.Events
1687
- }) : this.instance.datastore === "ioredis" ? new IORedisConnection2({
1688
- Redis: this.Redis,
1689
- clientOptions: this.clientOptions,
1690
- clusterNodes: this.clusterNodes,
1691
- Promise: this.Promise,
1692
- Events: this.instance.Events
1693
- }) : void 0;
1694
- }
1695
- this.instance.connection = this.connection;
1696
- this.instance.datastore = this.connection.datastore;
1697
- this.ready = this.connection.ready.then((clients) => {
1698
- this.clients = clients;
1699
- return this.runScript("init", this.prepareInitSettings(this.clearDatastore));
1700
- }).then(() => {
1701
- return this.connection.__addLimiter__(this.instance);
1702
- }).then(() => {
1703
- return this.runScript("register_client", [this.instance.queued()]);
1704
- }).then(() => {
1705
- var base;
1706
- if (typeof (base = this.heartbeat = setInterval(() => {
1707
- return this.runScript("heartbeat", []).catch((e) => {
1708
- return this.instance.Events.trigger("error", e);
1709
- });
1710
- }, this.heartbeatInterval)).unref === "function") {
1711
- base.unref();
1712
- }
1713
- return this.clients;
1714
- });
1715
- }
1716
- __publish__(message) {
1717
- var _this = this;
1718
- return _asyncToGenerator2(function* () {
1719
- var client;
1720
- var _ref = yield _this.ready;
1721
- client = _ref.client;
1722
- return client.publish(_this.instance.channel(), `message:${message.toString()}`);
1723
- })();
1724
- }
1725
- onMessage(channel, message) {
1726
- var _this2 = this;
1727
- return _asyncToGenerator2(function* () {
1728
- var capacity, counter, data, drained, e, newCapacity, pos, priorityClient, rawCapacity, type;
1729
- try {
1730
- pos = message.indexOf(":");
1731
- var _ref2 = [message.slice(0, pos), message.slice(pos + 1)];
1732
- type = _ref2[0];
1733
- data = _ref2[1];
1734
- if (type === "capacity") {
1735
- return yield _this2.instance._drainAll(data.length > 0 ? ~~data : void 0);
1736
- } else if (type === "capacity-priority") {
1737
- var _data$split = data.split(":");
1738
- var _data$split2 = _slicedToArray2(_data$split, 3);
1739
- rawCapacity = _data$split2[0];
1740
- priorityClient = _data$split2[1];
1741
- counter = _data$split2[2];
1742
- capacity = rawCapacity.length > 0 ? ~~rawCapacity : void 0;
1743
- if (priorityClient === _this2.clientId) {
1744
- drained = yield _this2.instance._drainAll(capacity);
1745
- newCapacity = capacity != null ? capacity - (drained || 0) : "";
1746
- return yield _this2.clients.client.publish(_this2.instance.channel(), `capacity-priority:${newCapacity}::${counter}`);
1747
- } else if (priorityClient === "") {
1748
- clearTimeout(_this2.capacityPriorityCounters[counter]);
1749
- delete _this2.capacityPriorityCounters[counter];
1750
- return _this2.instance._drainAll(capacity);
1751
- } else {
1752
- return _this2.capacityPriorityCounters[counter] = setTimeout(
1753
- /* @__PURE__ */ _asyncToGenerator2(function* () {
1754
- var e2;
1755
- try {
1756
- delete _this2.capacityPriorityCounters[counter];
1757
- yield _this2.runScript("blacklist_client", [priorityClient]);
1758
- return yield _this2.instance._drainAll(capacity);
1759
- } catch (error) {
1760
- e2 = error;
1761
- return _this2.instance.Events.trigger("error", e2);
1762
- }
1763
- }),
1764
- 1e3
1765
- );
1766
- }
1767
- } else if (type === "message") {
1768
- return _this2.instance.Events.trigger("message", data);
1769
- } else if (type === "blocked") {
1770
- return yield _this2.instance._dropAllQueued();
1771
- }
1772
- } catch (error) {
1773
- e = error;
1774
- return _this2.instance.Events.trigger("error", e);
1775
- }
1776
- })();
1777
- }
1778
- __disconnect__(flush) {
1779
- clearInterval(this.heartbeat);
1780
- if (this.sharedConnection) {
1781
- return this.connection.__removeLimiter__(this.instance);
1782
- } else {
1783
- return this.connection.disconnect(flush);
1784
- }
1785
- }
1786
- runScript(name2, args) {
1787
- var _this3 = this;
1788
- return _asyncToGenerator2(function* () {
1789
- if (!(name2 === "init" || name2 === "register_client")) {
1790
- yield _this3.ready;
1791
- }
1792
- return new _this3.Promise((resolve3, reject) => {
1793
- var all_args, arr;
1794
- all_args = [Date.now(), _this3.clientId].concat(args);
1795
- _this3.instance.Events.trigger("debug", `Calling Redis script: ${name2}.lua`, all_args);
1796
- arr = _this3.connection.__scriptArgs__(name2, _this3.originalId, all_args, function(err, replies) {
1797
- if (err != null) {
1798
- return reject(err);
1799
- }
1800
- return resolve3(replies);
1801
- });
1802
- return _this3.connection.__scriptFn__(name2)(...arr);
1803
- }).catch((e) => {
1804
- if (e.message === "SETTINGS_KEY_NOT_FOUND") {
1805
- if (name2 === "heartbeat") {
1806
- return _this3.Promise.resolve();
1807
- } else {
1808
- return _this3.runScript("init", _this3.prepareInitSettings(false)).then(() => {
1809
- return _this3.runScript(name2, args);
1810
- });
1811
- }
1812
- } else if (e.message === "UNKNOWN_CLIENT") {
1813
- return _this3.runScript("register_client", [_this3.instance.queued()]).then(() => {
1814
- return _this3.runScript(name2, args);
1815
- });
1816
- } else {
1817
- return _this3.Promise.reject(e);
1818
- }
1819
- });
1820
- })();
1821
- }
1822
- prepareArray(arr) {
1823
- var i, len, results, x;
1824
- results = [];
1825
- for (i = 0, len = arr.length; i < len; i++) {
1826
- x = arr[i];
1827
- results.push(x != null ? x.toString() : "");
1828
- }
1829
- return results;
1830
- }
1831
- prepareObject(obj) {
1832
- var arr, k, v;
1833
- arr = [];
1834
- for (k in obj) {
1835
- v = obj[k];
1836
- arr.push(k, v != null ? v.toString() : "");
1837
- }
1838
- return arr;
1839
- }
1840
- prepareInitSettings(clear) {
1841
- var args;
1842
- args = this.prepareObject(Object.assign({}, this.storeOptions, {
1843
- id: this.originalId,
1844
- version: this.instance.version,
1845
- groupTimeout: this.timeout,
1846
- clientTimeout: this.clientTimeout
1847
- }));
1848
- args.unshift(clear ? 1 : 0, this.instance.version);
1849
- return args;
1850
- }
1851
- convertBool(b) {
1852
- return !!b;
1853
- }
1854
- __updateSettings__(options2) {
1855
- var _this4 = this;
1856
- return _asyncToGenerator2(function* () {
1857
- yield _this4.runScript("update_settings", _this4.prepareObject(options2));
1858
- return parser2.overwrite(options2, options2, _this4.storeOptions);
1859
- })();
1860
- }
1861
- __running__() {
1862
- return this.runScript("running", []);
1863
- }
1864
- __queued__() {
1865
- return this.runScript("queued", []);
1866
- }
1867
- __done__() {
1868
- return this.runScript("done", []);
1869
- }
1870
- __groupCheck__() {
1871
- var _this5 = this;
1872
- return _asyncToGenerator2(function* () {
1873
- return _this5.convertBool(yield _this5.runScript("group_check", []));
1874
- })();
1875
- }
1876
- __incrementReservoir__(incr) {
1877
- return this.runScript("increment_reservoir", [incr]);
1878
- }
1879
- __currentReservoir__() {
1880
- return this.runScript("current_reservoir", []);
1881
- }
1882
- __check__(weight) {
1883
- var _this6 = this;
1884
- return _asyncToGenerator2(function* () {
1885
- return _this6.convertBool(yield _this6.runScript("check", _this6.prepareArray([weight])));
1886
- })();
1887
- }
1888
- __register__(index, weight, expiration) {
1889
- var _this7 = this;
1890
- return _asyncToGenerator2(function* () {
1891
- var reservoir, success, wait;
1892
- var _ref4 = yield _this7.runScript("register", _this7.prepareArray([index, weight, expiration]));
1893
- var _ref5 = _slicedToArray2(_ref4, 3);
1894
- success = _ref5[0];
1895
- wait = _ref5[1];
1896
- reservoir = _ref5[2];
1897
- return {
1898
- success: _this7.convertBool(success),
1899
- wait,
1900
- reservoir
1901
- };
1902
- })();
1903
- }
1904
- __submit__(queueLength, weight) {
1905
- var _this8 = this;
1906
- return _asyncToGenerator2(function* () {
1907
- var blocked, e, maxConcurrent, overweight, reachedHWM, strategy;
1908
- try {
1909
- var _ref6 = yield _this8.runScript("submit", _this8.prepareArray([queueLength, weight]));
1910
- var _ref7 = _slicedToArray2(_ref6, 3);
1911
- reachedHWM = _ref7[0];
1912
- blocked = _ref7[1];
1913
- strategy = _ref7[2];
1914
- return {
1915
- reachedHWM: _this8.convertBool(reachedHWM),
1916
- blocked: _this8.convertBool(blocked),
1917
- strategy
1918
- };
1919
- } catch (error) {
1920
- e = error;
1921
- if (e.message.indexOf("OVERWEIGHT") === 0) {
1922
- var _e$message$split = e.message.split(":");
1923
- var _e$message$split2 = _slicedToArray2(_e$message$split, 3);
1924
- overweight = _e$message$split2[0];
1925
- weight = _e$message$split2[1];
1926
- maxConcurrent = _e$message$split2[2];
1927
- throw new BottleneckError(`Impossible to add a job having a weight of ${weight} to a limiter having a maxConcurrent setting of ${maxConcurrent}`);
1928
- } else {
1929
- throw e;
1930
- }
1931
- }
1932
- })();
1933
- }
1934
- __free__(index, weight) {
1935
- var _this9 = this;
1936
- return _asyncToGenerator2(function* () {
1937
- var running;
1938
- running = yield _this9.runScript("free", _this9.prepareArray([index]));
1939
- return {
1940
- running
1941
- };
1942
- })();
1943
- }
1944
- };
1945
- module2.exports = RedisDatastore;
1946
- }
1947
- });
1948
-
1949
- // node_modules/bottleneck/lib/States.js
1950
- var require_States = __commonJS({
1951
- "node_modules/bottleneck/lib/States.js"(exports2, module2) {
1952
- "use strict";
1953
- var BottleneckError;
1954
- var States;
1955
- BottleneckError = require_BottleneckError();
1956
- States = class States {
1957
- static {
1958
- __name(this, "States");
1959
- }
1960
- constructor(status1) {
1961
- this.status = status1;
1962
- this._jobs = {};
1963
- this.counts = this.status.map(function() {
1964
- return 0;
1965
- });
1966
- }
1967
- next(id) {
1968
- var current, next;
1969
- current = this._jobs[id];
1970
- next = current + 1;
1971
- if (current != null && next < this.status.length) {
1972
- this.counts[current]--;
1973
- this.counts[next]++;
1974
- return this._jobs[id]++;
1975
- } else if (current != null) {
1976
- this.counts[current]--;
1977
- return delete this._jobs[id];
1978
- }
1979
- }
1980
- start(id) {
1981
- var initial;
1982
- initial = 0;
1983
- this._jobs[id] = initial;
1984
- return this.counts[initial]++;
1985
- }
1986
- remove(id) {
1987
- var current;
1988
- current = this._jobs[id];
1989
- if (current != null) {
1990
- this.counts[current]--;
1991
- delete this._jobs[id];
1992
- }
1993
- return current != null;
1994
- }
1995
- jobStatus(id) {
1996
- var ref;
1997
- return (ref = this.status[this._jobs[id]]) != null ? ref : null;
1998
- }
1999
- statusJobs(status) {
2000
- var k, pos, ref, results, v;
2001
- if (status != null) {
2002
- pos = this.status.indexOf(status);
2003
- if (pos < 0) {
2004
- throw new BottleneckError(`status must be one of ${this.status.join(", ")}`);
2005
- }
2006
- ref = this._jobs;
2007
- results = [];
2008
- for (k in ref) {
2009
- v = ref[k];
2010
- if (v === pos) {
2011
- results.push(k);
2012
- }
2013
- }
2014
- return results;
2015
- } else {
2016
- return Object.keys(this._jobs);
2017
- }
2018
- }
2019
- statusCounts() {
2020
- return this.counts.reduce((acc, v, i) => {
2021
- acc[this.status[i]] = v;
2022
- return acc;
2023
- }, {});
2024
- }
2025
- };
2026
- module2.exports = States;
2027
- }
2028
- });
2029
-
2030
- // node_modules/bottleneck/lib/Sync.js
2031
- var require_Sync = __commonJS({
2032
- "node_modules/bottleneck/lib/Sync.js"(exports2, module2) {
2033
- "use strict";
2034
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
2035
- try {
2036
- var info = gen[key](arg);
2037
- var value = info.value;
2038
- } catch (error) {
2039
- reject(error);
2040
- return;
2041
- }
2042
- if (info.done) {
2043
- resolve3(value);
2044
- } else {
2045
- Promise.resolve(value).then(_next, _throw);
2046
- }
2047
- }
2048
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
2049
- function _asyncToGenerator2(fn) {
2050
- return function() {
2051
- var self2 = this, args = arguments;
2052
- return new Promise(function(resolve3, reject) {
2053
- var gen = fn.apply(self2, args);
2054
- function _next(value) {
2055
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
2056
- }
2057
- __name(_next, "_next");
2058
- function _throw(err) {
2059
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
2060
- }
2061
- __name(_throw, "_throw");
2062
- _next(void 0);
2063
- });
2064
- };
2065
- }
2066
- __name(_asyncToGenerator2, "_asyncToGenerator");
2067
- var DLList;
2068
- var Sync;
2069
- DLList = require_DLList();
2070
- Sync = class Sync {
2071
- static {
2072
- __name(this, "Sync");
2073
- }
2074
- constructor(name2, Promise2) {
2075
- this.schedule = this.schedule.bind(this);
2076
- this.name = name2;
2077
- this.Promise = Promise2;
2078
- this._running = 0;
2079
- this._queue = new DLList();
2080
- }
2081
- isEmpty() {
2082
- return this._queue.length === 0;
2083
- }
2084
- _tryToRun() {
2085
- var _this = this;
2086
- return _asyncToGenerator2(function* () {
2087
- var args, cb, error, reject, resolve3, returned, task;
2088
- if (_this._running < 1 && _this._queue.length > 0) {
2089
- _this._running++;
2090
- var _this$_queue$shift = _this._queue.shift();
2091
- task = _this$_queue$shift.task;
2092
- args = _this$_queue$shift.args;
2093
- resolve3 = _this$_queue$shift.resolve;
2094
- reject = _this$_queue$shift.reject;
2095
- cb = yield _asyncToGenerator2(function* () {
2096
- try {
2097
- returned = yield task(...args);
2098
- return function() {
2099
- return resolve3(returned);
2100
- };
2101
- } catch (error1) {
2102
- error = error1;
2103
- return function() {
2104
- return reject(error);
2105
- };
2106
- }
2107
- })();
2108
- _this._running--;
2109
- _this._tryToRun();
2110
- return cb();
2111
- }
2112
- })();
2113
- }
2114
- schedule(task, ...args) {
2115
- var promise, reject, resolve3;
2116
- resolve3 = reject = null;
2117
- promise = new this.Promise(function(_resolve, _reject) {
2118
- resolve3 = _resolve;
2119
- return reject = _reject;
2120
- });
2121
- this._queue.push({
2122
- task,
2123
- args,
2124
- resolve: resolve3,
2125
- reject
2126
- });
2127
- this._tryToRun();
2128
- return promise;
2129
- }
2130
- };
2131
- module2.exports = Sync;
2132
- }
2133
- });
2134
-
2135
- // node_modules/bottleneck/lib/version.json
2136
- var require_version = __commonJS({
2137
- "node_modules/bottleneck/lib/version.json"(exports2, module2) {
2138
- module2.exports = { version: "2.19.5" };
2139
- }
2140
- });
2141
-
2142
- // node_modules/bottleneck/lib/Group.js
2143
- var require_Group = __commonJS({
2144
- "node_modules/bottleneck/lib/Group.js"(exports2, module2) {
2145
- "use strict";
2146
- function _slicedToArray2(arr, i) {
2147
- return _arrayWithHoles2(arr) || _iterableToArrayLimit2(arr, i) || _nonIterableRest2();
2148
- }
2149
- __name(_slicedToArray2, "_slicedToArray");
2150
- function _nonIterableRest2() {
2151
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
2152
- }
2153
- __name(_nonIterableRest2, "_nonIterableRest");
2154
- function _iterableToArrayLimit2(arr, i) {
2155
- var _arr = [];
2156
- var _n = true;
2157
- var _d = false;
2158
- var _e = void 0;
2159
- try {
2160
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
2161
- _arr.push(_s.value);
2162
- if (i && _arr.length === i) break;
2163
- }
2164
- } catch (err) {
2165
- _d = true;
2166
- _e = err;
2167
- } finally {
2168
- try {
2169
- if (!_n && _i["return"] != null) _i["return"]();
2170
- } finally {
2171
- if (_d) throw _e;
2172
- }
2173
- }
2174
- return _arr;
2175
- }
2176
- __name(_iterableToArrayLimit2, "_iterableToArrayLimit");
2177
- function _arrayWithHoles2(arr) {
2178
- if (Array.isArray(arr)) return arr;
2179
- }
2180
- __name(_arrayWithHoles2, "_arrayWithHoles");
2181
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
2182
- try {
2183
- var info = gen[key](arg);
2184
- var value = info.value;
2185
- } catch (error) {
2186
- reject(error);
2187
- return;
2188
- }
2189
- if (info.done) {
2190
- resolve3(value);
2191
- } else {
2192
- Promise.resolve(value).then(_next, _throw);
2193
- }
2194
- }
2195
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
2196
- function _asyncToGenerator2(fn) {
2197
- return function() {
2198
- var self2 = this, args = arguments;
2199
- return new Promise(function(resolve3, reject) {
2200
- var gen = fn.apply(self2, args);
2201
- function _next(value) {
2202
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
2203
- }
2204
- __name(_next, "_next");
2205
- function _throw(err) {
2206
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
2207
- }
2208
- __name(_throw, "_throw");
2209
- _next(void 0);
2210
- });
2211
- };
2212
- }
2213
- __name(_asyncToGenerator2, "_asyncToGenerator");
2214
- var Events2;
2215
- var Group;
2216
- var IORedisConnection2;
2217
- var RedisConnection2;
2218
- var Scripts2;
2219
- var parser2;
2220
- parser2 = require_parser();
2221
- Events2 = require_Events();
2222
- RedisConnection2 = require_RedisConnection();
2223
- IORedisConnection2 = require_IORedisConnection();
2224
- Scripts2 = require_Scripts();
2225
- Group = function() {
2226
- class Group2 {
2227
- static {
2228
- __name(this, "Group");
2229
- }
2230
- constructor(limiterOptions = {}) {
2231
- this.deleteKey = this.deleteKey.bind(this);
2232
- this.limiterOptions = limiterOptions;
2233
- parser2.load(this.limiterOptions, this.defaults, this);
2234
- this.Events = new Events2(this);
2235
- this.instances = {};
2236
- this.Bottleneck = require_Bottleneck();
2237
- this._startAutoCleanup();
2238
- this.sharedConnection = this.connection != null;
2239
- if (this.connection == null) {
2240
- if (this.limiterOptions.datastore === "redis") {
2241
- this.connection = new RedisConnection2(Object.assign({}, this.limiterOptions, {
2242
- Events: this.Events
2243
- }));
2244
- } else if (this.limiterOptions.datastore === "ioredis") {
2245
- this.connection = new IORedisConnection2(Object.assign({}, this.limiterOptions, {
2246
- Events: this.Events
2247
- }));
2248
- }
2249
- }
2250
- }
2251
- key(key = "") {
2252
- var ref;
2253
- return (ref = this.instances[key]) != null ? ref : (() => {
2254
- var limiter;
2255
- limiter = this.instances[key] = new this.Bottleneck(Object.assign(this.limiterOptions, {
2256
- id: `${this.id}-${key}`,
2257
- timeout: this.timeout,
2258
- connection: this.connection
2259
- }));
2260
- this.Events.trigger("created", limiter, key);
2261
- return limiter;
2262
- })();
2263
- }
2264
- deleteKey(key = "") {
2265
- var _this = this;
2266
- return _asyncToGenerator2(function* () {
2267
- var deleted, instance;
2268
- instance = _this.instances[key];
2269
- if (_this.connection) {
2270
- deleted = yield _this.connection.__runCommand__(["del", ...Scripts2.allKeys(`${_this.id}-${key}`)]);
2271
- }
2272
- if (instance != null) {
2273
- delete _this.instances[key];
2274
- yield instance.disconnect();
2275
- }
2276
- return instance != null || deleted > 0;
2277
- })();
2278
- }
2279
- limiters() {
2280
- var k, ref, results, v;
2281
- ref = this.instances;
2282
- results = [];
2283
- for (k in ref) {
2284
- v = ref[k];
2285
- results.push({
2286
- key: k,
2287
- limiter: v
2288
- });
2289
- }
2290
- return results;
2291
- }
2292
- keys() {
2293
- return Object.keys(this.instances);
2294
- }
2295
- clusterKeys() {
2296
- var _this2 = this;
2297
- return _asyncToGenerator2(function* () {
2298
- var cursor, end, found, i, k, keys, len, next, start;
2299
- if (_this2.connection == null) {
2300
- return _this2.Promise.resolve(_this2.keys());
2301
- }
2302
- keys = [];
2303
- cursor = null;
2304
- start = `b_${_this2.id}-`.length;
2305
- end = "_settings".length;
2306
- while (cursor !== 0) {
2307
- var _ref = yield _this2.connection.__runCommand__(["scan", cursor != null ? cursor : 0, "match", `b_${_this2.id}-*_settings`, "count", 1e4]);
2308
- var _ref2 = _slicedToArray2(_ref, 2);
2309
- next = _ref2[0];
2310
- found = _ref2[1];
2311
- cursor = ~~next;
2312
- for (i = 0, len = found.length; i < len; i++) {
2313
- k = found[i];
2314
- keys.push(k.slice(start, -end));
2315
- }
2316
- }
2317
- return keys;
2318
- })();
2319
- }
2320
- _startAutoCleanup() {
2321
- var _this3 = this;
2322
- var base;
2323
- clearInterval(this.interval);
2324
- return typeof (base = this.interval = setInterval(
2325
- /* @__PURE__ */ _asyncToGenerator2(function* () {
2326
- var e, k, ref, results, time2, v;
2327
- time2 = Date.now();
2328
- ref = _this3.instances;
2329
- results = [];
2330
- for (k in ref) {
2331
- v = ref[k];
2332
- try {
2333
- if (yield v._store.__groupCheck__(time2)) {
2334
- results.push(_this3.deleteKey(k));
2335
- } else {
2336
- results.push(void 0);
2337
- }
2338
- } catch (error) {
2339
- e = error;
2340
- results.push(v.Events.trigger("error", e));
2341
- }
2342
- }
2343
- return results;
2344
- }),
2345
- this.timeout / 2
2346
- )).unref === "function" ? base.unref() : void 0;
2347
- }
2348
- updateSettings(options2 = {}) {
2349
- parser2.overwrite(options2, this.defaults, this);
2350
- parser2.overwrite(options2, options2, this.limiterOptions);
2351
- if (options2.timeout != null) {
2352
- return this._startAutoCleanup();
2353
- }
2354
- }
2355
- disconnect(flush = true) {
2356
- var ref;
2357
- if (!this.sharedConnection) {
2358
- return (ref = this.connection) != null ? ref.disconnect(flush) : void 0;
2359
- }
2360
- }
2361
- }
2362
- ;
2363
- Group2.prototype.defaults = {
2364
- timeout: 1e3 * 60 * 5,
2365
- connection: null,
2366
- Promise,
2367
- id: "group-key"
2368
- };
2369
- return Group2;
2370
- }.call(void 0);
2371
- module2.exports = Group;
2372
- }
2373
- });
2374
-
2375
- // node_modules/bottleneck/lib/Batcher.js
2376
- var require_Batcher = __commonJS({
2377
- "node_modules/bottleneck/lib/Batcher.js"(exports2, module2) {
2378
- "use strict";
2379
- var Batcher;
2380
- var Events2;
2381
- var parser2;
2382
- parser2 = require_parser();
2383
- Events2 = require_Events();
2384
- Batcher = function() {
2385
- class Batcher2 {
2386
- static {
2387
- __name(this, "Batcher");
2388
- }
2389
- constructor(options2 = {}) {
2390
- this.options = options2;
2391
- parser2.load(this.options, this.defaults, this);
2392
- this.Events = new Events2(this);
2393
- this._arr = [];
2394
- this._resetPromise();
2395
- this._lastFlush = Date.now();
2396
- }
2397
- _resetPromise() {
2398
- return this._promise = new this.Promise((res, rej) => {
2399
- return this._resolve = res;
2400
- });
2401
- }
2402
- _flush() {
2403
- clearTimeout(this._timeout);
2404
- this._lastFlush = Date.now();
2405
- this._resolve();
2406
- this.Events.trigger("batch", this._arr);
2407
- this._arr = [];
2408
- return this._resetPromise();
2409
- }
2410
- add(data) {
2411
- var ret;
2412
- this._arr.push(data);
2413
- ret = this._promise;
2414
- if (this._arr.length === this.maxSize) {
2415
- this._flush();
2416
- } else if (this.maxTime != null && this._arr.length === 1) {
2417
- this._timeout = setTimeout(() => {
2418
- return this._flush();
2419
- }, this.maxTime);
2420
- }
2421
- return ret;
2422
- }
2423
- }
2424
- ;
2425
- Batcher2.prototype.defaults = {
2426
- maxTime: null,
2427
- maxSize: null,
2428
- Promise
2429
- };
2430
- return Batcher2;
2431
- }.call(void 0);
2432
- module2.exports = Batcher;
2433
- }
2434
- });
2435
-
2436
- // node_modules/bottleneck/lib/Bottleneck.js
2437
- var require_Bottleneck = __commonJS({
2438
- "node_modules/bottleneck/lib/Bottleneck.js"(exports2, module2) {
2439
- "use strict";
2440
- function _slicedToArray2(arr, i) {
2441
- return _arrayWithHoles2(arr) || _iterableToArrayLimit2(arr, i) || _nonIterableRest2();
2442
- }
2443
- __name(_slicedToArray2, "_slicedToArray");
2444
- function _iterableToArrayLimit2(arr, i) {
2445
- var _arr = [];
2446
- var _n = true;
2447
- var _d = false;
2448
- var _e = void 0;
2449
- try {
2450
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
2451
- _arr.push(_s.value);
2452
- if (i && _arr.length === i) break;
2453
- }
2454
- } catch (err) {
2455
- _d = true;
2456
- _e = err;
2457
- } finally {
2458
- try {
2459
- if (!_n && _i["return"] != null) _i["return"]();
2460
- } finally {
2461
- if (_d) throw _e;
2462
- }
2463
- }
2464
- return _arr;
2465
- }
2466
- __name(_iterableToArrayLimit2, "_iterableToArrayLimit");
2467
- function _toArray(arr) {
2468
- return _arrayWithHoles2(arr) || _iterableToArray(arr) || _nonIterableRest2();
2469
- }
2470
- __name(_toArray, "_toArray");
2471
- function _nonIterableRest2() {
2472
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
2473
- }
2474
- __name(_nonIterableRest2, "_nonIterableRest");
2475
- function _iterableToArray(iter) {
2476
- if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
2477
- }
2478
- __name(_iterableToArray, "_iterableToArray");
2479
- function _arrayWithHoles2(arr) {
2480
- if (Array.isArray(arr)) return arr;
2481
- }
2482
- __name(_arrayWithHoles2, "_arrayWithHoles");
2483
- function asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, key, arg) {
2484
- try {
2485
- var info = gen[key](arg);
2486
- var value = info.value;
2487
- } catch (error) {
2488
- reject(error);
2489
- return;
2490
- }
2491
- if (info.done) {
2492
- resolve3(value);
2493
- } else {
2494
- Promise.resolve(value).then(_next, _throw);
2495
- }
2496
- }
2497
- __name(asyncGeneratorStep2, "asyncGeneratorStep");
2498
- function _asyncToGenerator2(fn) {
2499
- return function() {
2500
- var self2 = this, args = arguments;
2501
- return new Promise(function(resolve3, reject) {
2502
- var gen = fn.apply(self2, args);
2503
- function _next(value) {
2504
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "next", value);
2505
- }
2506
- __name(_next, "_next");
2507
- function _throw(err) {
2508
- asyncGeneratorStep2(gen, resolve3, reject, _next, _throw, "throw", err);
2509
- }
2510
- __name(_throw, "_throw");
2511
- _next(void 0);
2512
- });
2513
- };
2514
- }
2515
- __name(_asyncToGenerator2, "_asyncToGenerator");
2516
- var Bottleneck2;
2517
- var DEFAULT_PRIORITY;
2518
- var Events2;
2519
- var Job;
2520
- var LocalDatastore;
2521
- var NUM_PRIORITIES;
2522
- var Queues;
2523
- var RedisDatastore;
2524
- var States;
2525
- var Sync;
2526
- var parser2;
2527
- var splice = [].splice;
2528
- NUM_PRIORITIES = 10;
2529
- DEFAULT_PRIORITY = 5;
2530
- parser2 = require_parser();
2531
- Queues = require_Queues();
2532
- Job = require_Job();
2533
- LocalDatastore = require_LocalDatastore();
2534
- RedisDatastore = require_RedisDatastore();
2535
- Events2 = require_Events();
2536
- States = require_States();
2537
- Sync = require_Sync();
2538
- Bottleneck2 = function() {
2539
- class Bottleneck3 {
2540
- static {
2541
- __name(this, "Bottleneck");
2542
- }
2543
- constructor(options2 = {}, ...invalid) {
2544
- var storeInstanceOptions, storeOptions;
2545
- this._addToQueue = this._addToQueue.bind(this);
2546
- this._validateOptions(options2, invalid);
2547
- parser2.load(options2, this.instanceDefaults, this);
2548
- this._queues = new Queues(NUM_PRIORITIES);
2549
- this._scheduled = {};
2550
- this._states = new States(["RECEIVED", "QUEUED", "RUNNING", "EXECUTING"].concat(this.trackDoneStatus ? ["DONE"] : []));
2551
- this._limiter = null;
2552
- this.Events = new Events2(this);
2553
- this._submitLock = new Sync("submit", this.Promise);
2554
- this._registerLock = new Sync("register", this.Promise);
2555
- storeOptions = parser2.load(options2, this.storeDefaults, {});
2556
- this._store = function() {
2557
- if (this.datastore === "redis" || this.datastore === "ioredis" || this.connection != null) {
2558
- storeInstanceOptions = parser2.load(options2, this.redisStoreDefaults, {});
2559
- return new RedisDatastore(this, storeOptions, storeInstanceOptions);
2560
- } else if (this.datastore === "local") {
2561
- storeInstanceOptions = parser2.load(options2, this.localStoreDefaults, {});
2562
- return new LocalDatastore(this, storeOptions, storeInstanceOptions);
2563
- } else {
2564
- throw new Bottleneck3.prototype.BottleneckError(`Invalid datastore type: ${this.datastore}`);
2565
- }
2566
- }.call(this);
2567
- this._queues.on("leftzero", () => {
2568
- var ref;
2569
- return (ref = this._store.heartbeat) != null ? typeof ref.ref === "function" ? ref.ref() : void 0 : void 0;
2570
- });
2571
- this._queues.on("zero", () => {
2572
- var ref;
2573
- return (ref = this._store.heartbeat) != null ? typeof ref.unref === "function" ? ref.unref() : void 0 : void 0;
2574
- });
2575
- }
2576
- _validateOptions(options2, invalid) {
2577
- if (!(options2 != null && typeof options2 === "object" && invalid.length === 0)) {
2578
- throw new Bottleneck3.prototype.BottleneckError("Bottleneck v2 takes a single object argument. Refer to https://github.com/SGrondin/bottleneck#upgrading-to-v2 if you're upgrading from Bottleneck v1.");
2579
- }
2580
- }
2581
- ready() {
2582
- return this._store.ready;
2583
- }
2584
- clients() {
2585
- return this._store.clients;
2586
- }
2587
- channel() {
2588
- return `b_${this.id}`;
2589
- }
2590
- channel_client() {
2591
- return `b_${this.id}_${this._store.clientId}`;
2592
- }
2593
- publish(message) {
2594
- return this._store.__publish__(message);
2595
- }
2596
- disconnect(flush = true) {
2597
- return this._store.__disconnect__(flush);
2598
- }
2599
- chain(_limiter) {
2600
- this._limiter = _limiter;
2601
- return this;
2602
- }
2603
- queued(priority) {
2604
- return this._queues.queued(priority);
2605
- }
2606
- clusterQueued() {
2607
- return this._store.__queued__();
2608
- }
2609
- empty() {
2610
- return this.queued() === 0 && this._submitLock.isEmpty();
2611
- }
2612
- running() {
2613
- return this._store.__running__();
2614
- }
2615
- done() {
2616
- return this._store.__done__();
2617
- }
2618
- jobStatus(id) {
2619
- return this._states.jobStatus(id);
2620
- }
2621
- jobs(status) {
2622
- return this._states.statusJobs(status);
2623
- }
2624
- counts() {
2625
- return this._states.statusCounts();
2626
- }
2627
- _randomIndex() {
2628
- return Math.random().toString(36).slice(2);
2629
- }
2630
- check(weight = 1) {
2631
- return this._store.__check__(weight);
2632
- }
2633
- _clearGlobalState(index) {
2634
- if (this._scheduled[index] != null) {
2635
- clearTimeout(this._scheduled[index].expiration);
2636
- delete this._scheduled[index];
2637
- return true;
2638
- } else {
2639
- return false;
2640
- }
2641
- }
2642
- _free(index, job, options2, eventInfo) {
2643
- var _this = this;
2644
- return _asyncToGenerator2(function* () {
2645
- var e, running;
2646
- try {
2647
- var _ref = yield _this._store.__free__(index, options2.weight);
2648
- running = _ref.running;
2649
- _this.Events.trigger("debug", `Freed ${options2.id}`, eventInfo);
2650
- if (running === 0 && _this.empty()) {
2651
- return _this.Events.trigger("idle");
2652
- }
2653
- } catch (error1) {
2654
- e = error1;
2655
- return _this.Events.trigger("error", e);
2656
- }
2657
- })();
2658
- }
2659
- _run(index, job, wait) {
2660
- var clearGlobalState, free, run;
2661
- job.doRun();
2662
- clearGlobalState = this._clearGlobalState.bind(this, index);
2663
- run = this._run.bind(this, index, job);
2664
- free = this._free.bind(this, index, job);
2665
- return this._scheduled[index] = {
2666
- timeout: setTimeout(() => {
2667
- return job.doExecute(this._limiter, clearGlobalState, run, free);
2668
- }, wait),
2669
- expiration: job.options.expiration != null ? setTimeout(function() {
2670
- return job.doExpire(clearGlobalState, run, free);
2671
- }, wait + job.options.expiration) : void 0,
2672
- job
2673
- };
2674
- }
2675
- _drainOne(capacity) {
2676
- return this._registerLock.schedule(() => {
2677
- var args, index, next, options2, queue;
2678
- if (this.queued() === 0) {
2679
- return this.Promise.resolve(null);
2680
- }
2681
- queue = this._queues.getFirst();
2682
- var _next2 = next = queue.first();
2683
- options2 = _next2.options;
2684
- args = _next2.args;
2685
- if (capacity != null && options2.weight > capacity) {
2686
- return this.Promise.resolve(null);
2687
- }
2688
- this.Events.trigger("debug", `Draining ${options2.id}`, {
2689
- args,
2690
- options: options2
2691
- });
2692
- index = this._randomIndex();
2693
- return this._store.__register__(index, options2.weight, options2.expiration).then(({
2694
- success,
2695
- wait,
2696
- reservoir
2697
- }) => {
2698
- var empty;
2699
- this.Events.trigger("debug", `Drained ${options2.id}`, {
2700
- success,
2701
- args,
2702
- options: options2
2703
- });
2704
- if (success) {
2705
- queue.shift();
2706
- empty = this.empty();
2707
- if (empty) {
2708
- this.Events.trigger("empty");
2709
- }
2710
- if (reservoir === 0) {
2711
- this.Events.trigger("depleted", empty);
2712
- }
2713
- this._run(index, next, wait);
2714
- return this.Promise.resolve(options2.weight);
2715
- } else {
2716
- return this.Promise.resolve(null);
2717
- }
2718
- });
2719
- });
2720
- }
2721
- _drainAll(capacity, total = 0) {
2722
- return this._drainOne(capacity).then((drained) => {
2723
- var newCapacity;
2724
- if (drained != null) {
2725
- newCapacity = capacity != null ? capacity - drained : capacity;
2726
- return this._drainAll(newCapacity, total + drained);
2727
- } else {
2728
- return this.Promise.resolve(total);
2729
- }
2730
- }).catch((e) => {
2731
- return this.Events.trigger("error", e);
2732
- });
2733
- }
2734
- _dropAllQueued(message) {
2735
- return this._queues.shiftAll(function(job) {
2736
- return job.doDrop({
2737
- message
2738
- });
2739
- });
2740
- }
2741
- stop(options2 = {}) {
2742
- var done, waitForExecuting;
2743
- options2 = parser2.load(options2, this.stopDefaults);
2744
- waitForExecuting = /* @__PURE__ */ __name((at) => {
2745
- var finished;
2746
- finished = /* @__PURE__ */ __name(() => {
2747
- var counts;
2748
- counts = this._states.counts;
2749
- return counts[0] + counts[1] + counts[2] + counts[3] === at;
2750
- }, "finished");
2751
- return new this.Promise((resolve3, reject) => {
2752
- if (finished()) {
2753
- return resolve3();
2754
- } else {
2755
- return this.on("done", () => {
2756
- if (finished()) {
2757
- this.removeAllListeners("done");
2758
- return resolve3();
2759
- }
2760
- });
2761
- }
2762
- });
2763
- }, "waitForExecuting");
2764
- done = options2.dropWaitingJobs ? (this._run = function(index, next) {
2765
- return next.doDrop({
2766
- message: options2.dropErrorMessage
2767
- });
2768
- }, this._drainOne = () => {
2769
- return this.Promise.resolve(null);
2770
- }, this._registerLock.schedule(() => {
2771
- return this._submitLock.schedule(() => {
2772
- var k, ref, v;
2773
- ref = this._scheduled;
2774
- for (k in ref) {
2775
- v = ref[k];
2776
- if (this.jobStatus(v.job.options.id) === "RUNNING") {
2777
- clearTimeout(v.timeout);
2778
- clearTimeout(v.expiration);
2779
- v.job.doDrop({
2780
- message: options2.dropErrorMessage
2781
- });
2782
- }
2783
- }
2784
- this._dropAllQueued(options2.dropErrorMessage);
2785
- return waitForExecuting(0);
2786
- });
2787
- })) : this.schedule({
2788
- priority: NUM_PRIORITIES - 1,
2789
- weight: 0
2790
- }, () => {
2791
- return waitForExecuting(1);
2792
- });
2793
- this._receive = function(job) {
2794
- return job._reject(new Bottleneck3.prototype.BottleneckError(options2.enqueueErrorMessage));
2795
- };
2796
- this.stop = () => {
2797
- return this.Promise.reject(new Bottleneck3.prototype.BottleneckError("stop() has already been called"));
2798
- };
2799
- return done;
2800
- }
2801
- _addToQueue(job) {
2802
- var _this2 = this;
2803
- return _asyncToGenerator2(function* () {
2804
- var args, blocked, error, options2, reachedHWM, shifted, strategy;
2805
- args = job.args;
2806
- options2 = job.options;
2807
- try {
2808
- var _ref2 = yield _this2._store.__submit__(_this2.queued(), options2.weight);
2809
- reachedHWM = _ref2.reachedHWM;
2810
- blocked = _ref2.blocked;
2811
- strategy = _ref2.strategy;
2812
- } catch (error1) {
2813
- error = error1;
2814
- _this2.Events.trigger("debug", `Could not queue ${options2.id}`, {
2815
- args,
2816
- options: options2,
2817
- error
2818
- });
2819
- job.doDrop({
2820
- error
2821
- });
2822
- return false;
2823
- }
2824
- if (blocked) {
2825
- job.doDrop();
2826
- return true;
2827
- } else if (reachedHWM) {
2828
- shifted = strategy === Bottleneck3.prototype.strategy.LEAK ? _this2._queues.shiftLastFrom(options2.priority) : strategy === Bottleneck3.prototype.strategy.OVERFLOW_PRIORITY ? _this2._queues.shiftLastFrom(options2.priority + 1) : strategy === Bottleneck3.prototype.strategy.OVERFLOW ? job : void 0;
2829
- if (shifted != null) {
2830
- shifted.doDrop();
2831
- }
2832
- if (shifted == null || strategy === Bottleneck3.prototype.strategy.OVERFLOW) {
2833
- if (shifted == null) {
2834
- job.doDrop();
2835
- }
2836
- return reachedHWM;
2837
- }
2838
- }
2839
- job.doQueue(reachedHWM, blocked);
2840
- _this2._queues.push(job);
2841
- yield _this2._drainAll();
2842
- return reachedHWM;
2843
- })();
2844
- }
2845
- _receive(job) {
2846
- if (this._states.jobStatus(job.options.id) != null) {
2847
- job._reject(new Bottleneck3.prototype.BottleneckError(`A job with the same id already exists (id=${job.options.id})`));
2848
- return false;
2849
- } else {
2850
- job.doReceive();
2851
- return this._submitLock.schedule(this._addToQueue, job);
2852
- }
2853
- }
2854
- submit(...args) {
2855
- var cb, fn, job, options2, ref, ref1, task;
2856
- if (typeof args[0] === "function") {
2857
- var _ref3, _ref4, _splice$call, _splice$call2;
2858
- ref = args, _ref3 = ref, _ref4 = _toArray(_ref3), fn = _ref4[0], args = _ref4.slice(1), _ref3, _splice$call = splice.call(args, -1), _splice$call2 = _slicedToArray2(_splice$call, 1), cb = _splice$call2[0], _splice$call;
2859
- options2 = parser2.load({}, this.jobDefaults);
2860
- } else {
2861
- var _ref5, _ref6, _splice$call3, _splice$call4;
2862
- ref1 = args, _ref5 = ref1, _ref6 = _toArray(_ref5), options2 = _ref6[0], fn = _ref6[1], args = _ref6.slice(2), _ref5, _splice$call3 = splice.call(args, -1), _splice$call4 = _slicedToArray2(_splice$call3, 1), cb = _splice$call4[0], _splice$call3;
2863
- options2 = parser2.load(options2, this.jobDefaults);
2864
- }
2865
- task = /* @__PURE__ */ __name((...args2) => {
2866
- return new this.Promise(function(resolve3, reject) {
2867
- return fn(...args2, function(...args3) {
2868
- return (args3[0] != null ? reject : resolve3)(args3);
2869
- });
2870
- });
2871
- }, "task");
2872
- job = new Job(task, args, options2, this.jobDefaults, this.rejectOnDrop, this.Events, this._states, this.Promise);
2873
- job.promise.then(function(args2) {
2874
- return typeof cb === "function" ? cb(...args2) : void 0;
2875
- }).catch(function(args2) {
2876
- if (Array.isArray(args2)) {
2877
- return typeof cb === "function" ? cb(...args2) : void 0;
2878
- } else {
2879
- return typeof cb === "function" ? cb(args2) : void 0;
2880
- }
2881
- });
2882
- return this._receive(job);
2883
- }
2884
- schedule(...args) {
2885
- var job, options2, task;
2886
- if (typeof args[0] === "function") {
2887
- var _args = args;
2888
- var _args2 = _toArray(_args);
2889
- task = _args2[0];
2890
- args = _args2.slice(1);
2891
- options2 = {};
2892
- } else {
2893
- var _args3 = args;
2894
- var _args4 = _toArray(_args3);
2895
- options2 = _args4[0];
2896
- task = _args4[1];
2897
- args = _args4.slice(2);
2898
- }
2899
- job = new Job(task, args, options2, this.jobDefaults, this.rejectOnDrop, this.Events, this._states, this.Promise);
2900
- this._receive(job);
2901
- return job.promise;
2902
- }
2903
- wrap(fn) {
2904
- var schedule, wrapped;
2905
- schedule = this.schedule.bind(this);
2906
- wrapped = /* @__PURE__ */ __name(function wrapped2(...args) {
2907
- return schedule(fn.bind(this), ...args);
2908
- }, "wrapped");
2909
- wrapped.withOptions = function(options2, ...args) {
2910
- return schedule(options2, fn, ...args);
2911
- };
2912
- return wrapped;
2913
- }
2914
- updateSettings(options2 = {}) {
2915
- var _this3 = this;
2916
- return _asyncToGenerator2(function* () {
2917
- yield _this3._store.__updateSettings__(parser2.overwrite(options2, _this3.storeDefaults));
2918
- parser2.overwrite(options2, _this3.instanceDefaults, _this3);
2919
- return _this3;
2920
- })();
2921
- }
2922
- currentReservoir() {
2923
- return this._store.__currentReservoir__();
2924
- }
2925
- incrementReservoir(incr = 0) {
2926
- return this._store.__incrementReservoir__(incr);
2927
- }
2928
- }
2929
- ;
2930
- Bottleneck3.default = Bottleneck3;
2931
- Bottleneck3.Events = Events2;
2932
- Bottleneck3.version = Bottleneck3.prototype.version = require_version().version;
2933
- Bottleneck3.strategy = Bottleneck3.prototype.strategy = {
2934
- LEAK: 1,
2935
- OVERFLOW: 2,
2936
- OVERFLOW_PRIORITY: 4,
2937
- BLOCK: 3
2938
- };
2939
- Bottleneck3.BottleneckError = Bottleneck3.prototype.BottleneckError = require_BottleneckError();
2940
- Bottleneck3.Group = Bottleneck3.prototype.Group = require_Group();
2941
- Bottleneck3.RedisConnection = Bottleneck3.prototype.RedisConnection = require_RedisConnection();
2942
- Bottleneck3.IORedisConnection = Bottleneck3.prototype.IORedisConnection = require_IORedisConnection();
2943
- Bottleneck3.Batcher = Bottleneck3.prototype.Batcher = require_Batcher();
2944
- Bottleneck3.prototype.jobDefaults = {
2945
- priority: DEFAULT_PRIORITY,
2946
- weight: 1,
2947
- expiration: null,
2948
- id: "<no-id>"
2949
- };
2950
- Bottleneck3.prototype.storeDefaults = {
2951
- maxConcurrent: null,
2952
- minTime: 0,
2953
- highWater: null,
2954
- strategy: Bottleneck3.prototype.strategy.LEAK,
2955
- penalty: null,
2956
- reservoir: null,
2957
- reservoirRefreshInterval: null,
2958
- reservoirRefreshAmount: null,
2959
- reservoirIncreaseInterval: null,
2960
- reservoirIncreaseAmount: null,
2961
- reservoirIncreaseMaximum: null
2962
- };
2963
- Bottleneck3.prototype.localStoreDefaults = {
2964
- Promise,
2965
- timeout: null,
2966
- heartbeatInterval: 250
2967
- };
2968
- Bottleneck3.prototype.redisStoreDefaults = {
2969
- Promise,
2970
- timeout: null,
2971
- heartbeatInterval: 5e3,
2972
- clientTimeout: 1e4,
2973
- Redis: null,
2974
- clientOptions: {},
2975
- clusterNodes: null,
2976
- clearDatastore: false,
2977
- connection: null
2978
- };
2979
- Bottleneck3.prototype.instanceDefaults = {
2980
- datastore: "local",
2981
- connection: null,
2982
- id: "<no-id>",
2983
- rejectOnDrop: true,
2984
- trackDoneStatus: false,
2985
- Promise
2986
- };
2987
- Bottleneck3.prototype.stopDefaults = {
2988
- enqueueErrorMessage: "This limiter has been stopped and cannot accept new jobs.",
2989
- dropWaitingJobs: true,
2990
- dropErrorMessage: "This limiter has been stopped."
2991
- };
2992
- return Bottleneck3;
2993
- }.call(void 0);
2994
- module2.exports = Bottleneck2;
2995
- }
2996
- });
2997
-
2998
- // node_modules/bottleneck/lib/index.js
2999
- var require_lib = __commonJS({
3000
- "node_modules/bottleneck/lib/index.js"(exports2, module2) {
3001
- "use strict";
3002
- module2.exports = require_Bottleneck();
3003
- }
3004
- });
3005
-
3006
37
  // node_modules/reflect-metadata/Reflect.js
3007
38
  var require_Reflect = __commonJS({
3008
39
  "node_modules/reflect-metadata/Reflect.js"() {
@@ -5057,191 +2088,42 @@ var rivenStatFixFactor = {
5057
2088
  }
5058
2089
  };
5059
2090
 
5060
- // packages/wfm-api-client/lib/client.js
5061
- var import_bottleneck = __toESM(require_lib());
5062
-
5063
- // packages/wfm-api-client/lib/cache.js
5064
- var WfmMemoryCache = class {
5065
- static {
5066
- __name(this, "WfmMemoryCache");
5067
- }
5068
- maxSize;
5069
- storage = /* @__PURE__ */ new Map();
5070
- constructor(maxSize) {
5071
- this.maxSize = maxSize;
5072
- }
5073
- get(key, ttlSeconds, factory) {
5074
- const now = Date.now();
5075
- const existing = this.storage.get(key);
5076
- if (existing && existing.expiresAt > now) {
5077
- this.storage.delete(key);
5078
- this.storage.set(key, existing);
5079
- return existing.promise;
5080
- }
5081
- if (existing) {
5082
- this.storage.delete(key);
5083
- }
5084
- const promise = factory().catch((err) => {
5085
- const existing2 = this.storage.get(key);
5086
- if (existing2 && existing2.promise === promise) {
5087
- this.storage.delete(key);
5088
- }
5089
- throw err;
5090
- });
5091
- this.storage.set(key, {
5092
- expiresAt: now + ttlSeconds * 1e3,
5093
- promise
5094
- });
5095
- while (this.storage.size > this.maxSize) {
5096
- const oldest = this.storage.keys().next().value;
5097
- if (!oldest)
5098
- break;
5099
- this.storage.delete(oldest);
5100
- }
5101
- return promise;
5102
- }
5103
- };
5104
-
5105
- // packages/wfm-api-client/lib/endpoints/items.js
5106
- var wfmApiV1Base = "https://api.warframe.market/v1/";
5107
- var wfmApiV2Base = "https://api.warframe.market/v2/";
5108
- function createItemEndpoints(get, cacheOptions) {
5109
- return {
5110
- getList: /* @__PURE__ */ __name(async () => {
5111
- const response = await get(`${wfmApiV2Base}items`, cacheOptions?.itemListTtl ?? 0);
5112
- return response?.data;
5113
- }, "getList"),
5114
- getStatistics: /* @__PURE__ */ __name(async (itemId) => {
5115
- const response = await get(`${wfmApiV1Base}items/${itemId}/statistics`, cacheOptions?.statisticsTtl ?? 0);
5116
- return response?.payload;
5117
- }, "getStatistics"),
5118
- getOrders: /* @__PURE__ */ __name(async (itemId) => {
5119
- const response = await get(`${wfmApiV2Base}orders/item/${itemId}`, cacheOptions?.orderListTtl ?? 0);
5120
- return response?.data;
5121
- }, "getOrders")
5122
- };
5123
- }
5124
- __name(createItemEndpoints, "createItemEndpoints");
5125
-
5126
- // packages/wfm-api-client/lib/endpoints/rivens.js
5127
- var wfmApiV1Base2 = "https://api.warframe.market/v1/";
5128
- var wfmApiV2Base2 = "https://api.warframe.market/v2/";
5129
- function createRivenEndpoints(get, cacheOptions) {
5130
- return {
5131
- getItems: /* @__PURE__ */ __name(async () => {
5132
- const response = await get(`${wfmApiV2Base2}riven/weapons`, cacheOptions?.rivenItemListTtl ?? 0);
5133
- return response?.data;
5134
- }, "getItems"),
5135
- getOrders: /* @__PURE__ */ __name(async (itemId) => {
5136
- const response = await get(`${wfmApiV1Base2}auctions/search?type=riven&sort_by=price_asc&weapon_url_name=${itemId}`, cacheOptions?.rivenOrderListTtl ?? 0);
5137
- return response?.payload?.auctions;
5138
- }, "getOrders"),
5139
- getAttributes: /* @__PURE__ */ __name(async () => {
5140
- const response = await get(`${wfmApiV2Base2}riven/attributes`, cacheOptions?.rivenAttributeListTtl ?? 0);
5141
- return response?.data;
5142
- }, "getAttributes")
5143
- };
5144
- }
5145
- __name(createRivenEndpoints, "createRivenEndpoints");
5146
-
5147
- // packages/wfm-api-client/lib/endpoints/tools.js
5148
- var wfmApiV1Base3 = "https://api.warframe.market/v1/";
5149
- function createToolEndpoints(get, cacheOptions) {
2091
+ // src/warframe/infrastructure/wfm-client.ts
2092
+ var import_wfm_api_client = require("wfm-api-client");
2093
+ function softFailPlugin() {
5150
2094
  return {
5151
- getDucatnator: /* @__PURE__ */ __name(async () => {
5152
- const response = await get(`${wfmApiV1Base3}tools/ducats`, cacheOptions?.ducatnatorTtl ?? 0);
5153
- if (!response?.payload)
5154
- return void 0;
5155
- return {
5156
- day: response.payload.previous_day,
5157
- hour: response.payload.previous_hour
2095
+ wrap: /* @__PURE__ */ __name((next) => {
2096
+ return async (ctx) => {
2097
+ try {
2098
+ return await next(ctx);
2099
+ } catch {
2100
+ return void 0;
2101
+ }
5158
2102
  };
5159
- }, "getDucatnator")
2103
+ }, "wrap")
5160
2104
  };
5161
2105
  }
5162
- __name(createToolEndpoints, "createToolEndpoints");
5163
-
5164
- // packages/wfm-api-client/lib/transport.js
5165
- var import_ofetch2 = require("ofetch");
5166
- var defaultFetcher = /* @__PURE__ */ __name(async (url) => {
5167
- return (0, import_ofetch2.ofetch)(url, {
5168
- headers: {
5169
- "Accept": "application/json,text/plain;q=0.9,*/*;q=0.8",
5170
- "Accept-Language": "zh-CN,zh-Hans;q=0.9",
5171
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
5172
- "Language": "zh-hans"
5173
- },
5174
- retry: 3,
5175
- retryDelay: 500,
5176
- retryStatusCodes: [408, 429, 500, 502, 503, 504],
5177
- timeout: 1e4
2106
+ __name(softFailPlugin, "softFailPlugin");
2107
+ function createPluginWfmClient(fetcher) {
2108
+ const plugins = [
2109
+ softFailPlugin(),
2110
+ (0, import_wfm_api_client.memoryCachePlugin)({ maxSize: 1024, ttl: 60 })
2111
+ ];
2112
+ if (!fetcher)
2113
+ plugins.push((0, import_wfm_api_client.rateLimitPlugin)({ minTime: 400 }));
2114
+ return (0, import_wfm_api_client.createWfmApiClient)({
2115
+ fetcher,
2116
+ language: "zh-hans",
2117
+ timeoutMs: 1e4,
2118
+ plugins
5178
2119
  });
5179
- }, "defaultFetcher");
5180
- function fetchWithLimiter(fetcher, url, limiter) {
5181
- const run = /* @__PURE__ */ __name(() => fetcher(url), "run");
5182
- return limiter ? limiter.schedule(run) : run();
5183
- }
5184
- __name(fetchWithLimiter, "fetchWithLimiter");
5185
-
5186
- // packages/wfm-api-client/lib/client.js
5187
- var defaultCacheOptions = {
5188
- maxSize: 1024,
5189
- itemListTtl: 3600,
5190
- orderListTtl: 30,
5191
- statisticsTtl: 60,
5192
- rivenItemListTtl: 3600,
5193
- rivenOrderListTtl: 30,
5194
- rivenAttributeListTtl: 3600,
5195
- ducatnatorTtl: 60
5196
- };
5197
- var defaultRateLimitOptions = {
5198
- minTime: 500
5199
- };
5200
- function createWfmApiClient(options2 = {}) {
5201
- const fetcher = options2.fetcher ?? defaultFetcher;
5202
- const cacheOptions = resolveCacheOptions(options2.cache);
5203
- const limiter = resolveLimiter(options2.rateLimit);
5204
- const cache = cacheOptions ? new WfmMemoryCache(cacheOptions.maxSize) : void 0;
5205
- async function get(url, ttl) {
5206
- try {
5207
- if (!cache || ttl <= 0) {
5208
- return await fetchWithLimiter(fetcher, url, limiter);
5209
- }
5210
- return await cache.get(url, ttl, () => fetchWithLimiter(fetcher, url, limiter));
5211
- } catch {
5212
- return void 0;
5213
- }
5214
- }
5215
- __name(get, "get");
5216
- return {
5217
- items: createItemEndpoints(get, cacheOptions),
5218
- rivens: createRivenEndpoints(get, cacheOptions),
5219
- tools: createToolEndpoints(get, cacheOptions)
5220
- };
5221
- }
5222
- __name(createWfmApiClient, "createWfmApiClient");
5223
- function resolveCacheOptions(cache) {
5224
- if (cache === false)
5225
- return void 0;
5226
- if (cache === true || cache === void 0)
5227
- return defaultCacheOptions;
5228
- return { ...defaultCacheOptions, ...cache };
5229
- }
5230
- __name(resolveCacheOptions, "resolveCacheOptions");
5231
- function resolveLimiter(rateLimit) {
5232
- if (rateLimit === false)
5233
- return void 0;
5234
- const options2 = rateLimit === true || rateLimit === void 0 ? defaultRateLimitOptions : { ...defaultRateLimitOptions, ...rateLimit };
5235
- return new import_bottleneck.default({ minTime: options2.minTime });
5236
2120
  }
5237
- __name(resolveLimiter, "resolveLimiter");
5238
-
5239
- // src/warframe/infrastructure/wfm-client.ts
5240
- var wfmClient = createWfmApiClient();
2121
+ __name(createPluginWfmClient, "createPluginWfmClient");
2122
+ var wfmClient = createPluginWfmClient();
5241
2123
 
5242
2124
  // src/warframe/data/wfm/globalRivenAttribute.ts
5243
2125
  async function globalRivenAttributeFactory(rivenAttributeData) {
5244
- rivenAttributeData ??= await wfmClient.rivens.getAttributes();
2126
+ rivenAttributeData ??= await wfmClient.rivens.listAttributes();
5245
2127
  if (!rivenAttributeData) {
5246
2128
  throw new Error(
5247
2129
  "Failed to fetch riven attributes from Warframe Market API."
@@ -5305,7 +2187,7 @@ function buildGlobalRivenItemWordPrefixCandidates(globalRivenItemList) {
5305
2187
  }
5306
2188
  __name(buildGlobalRivenItemWordPrefixCandidates, "buildGlobalRivenItemWordPrefixCandidates");
5307
2189
  async function globalRivenItemFactory(rivenData) {
5308
- rivenData ??= await wfmClient.rivens.getItems();
2190
+ rivenData ??= await wfmClient.rivens.listWeapons();
5309
2191
  if (!rivenData) {
5310
2192
  throw new Error("Failed to fetch riven items from Warframe Market API.");
5311
2193
  }
@@ -5739,12 +2621,12 @@ async function getStaticRivenStats(weaponType, statType, disposition) {
5739
2621
  const { globalRivenAttributeList } = await globalRivenAttribute.get();
5740
2622
  for (const key in rivenAttrValues2) {
5741
2623
  const data = globalRivenAttributeList.find(
5742
- (v) => normalizeName(v.i18n.en.name) === key
2624
+ (v) => v.i18n?.en?.name !== void 0 && normalizeName(v.i18n.en.name) === key
5743
2625
  );
5744
2626
  const baseValue = rivenAttrValues2[key];
5745
2627
  const buffValue = baseValue * disposition * factor.buffFactor;
5746
2628
  result.positive[key] = {
5747
- name: data?.i18n["zh-hans"].name ?? key,
2629
+ name: data?.i18n?.["zh-hans"]?.name ?? data?.i18n?.en?.name ?? key,
5748
2630
  max: buffValue * 1.1,
5749
2631
  min: buffValue * 0.9,
5750
2632
  unit: data?.unit ?? ""
@@ -5752,7 +2634,7 @@ async function getStaticRivenStats(weaponType, statType, disposition) {
5752
2634
  if (result.negative) {
5753
2635
  const curseValue = baseValue * disposition * factor.curseFactor;
5754
2636
  result.negative[key] = {
5755
- name: data?.i18n["zh-hans"].name ?? key,
2637
+ name: data?.i18n?.["zh-hans"]?.name ?? data?.i18n?.en?.name ?? key,
5756
2638
  max: curseValue * 0.9,
5757
2639
  min: curseValue * 1.1,
5758
2640
  unit: data?.unit ?? ""
@@ -5820,7 +2702,7 @@ async function parseOCRResult(ocrResult) {
5820
2702
  const attr = globalRivenAttributeList.find((a) => {
5821
2703
  if (!a)
5822
2704
  return false;
5823
- const zhName = a.i18n["zh-hans"]?.name;
2705
+ const zhName = a.i18n?.["zh-hans"]?.name;
5824
2706
  if (!zhName)
5825
2707
  return false;
5826
2708
  const sim = similarity(zhName, attrNamePart);
@@ -5921,54 +2803,65 @@ function analyzeRivenStat(parseResult) {
5921
2803
  }
5922
2804
  const disposition = weaponRiven.calc.disposition;
5923
2805
  const weaponType = weaponRiven.calc.riventype;
5924
- const rivenStatCountType = (function() {
5925
- if (parseResult.attributes.length === 4) {
5926
- return "31";
5927
- } else if (parseResult.attributes.length === 2) {
5928
- return "2";
5929
- }
2806
+ const lookupBaseValue = /* @__PURE__ */ __name((enName) => rivenAttrValueDict[weaponType]?.[normalizeName(enName)], "lookupBaseValue");
2807
+ const buildStat = /* @__PURE__ */ __name((entry, factor, invertPercent) => {
2808
+ const enName = entry.attr.i18n?.en?.name;
2809
+ if (!enName) {
2810
+ return failure("riven.statTypeError");
2811
+ }
2812
+ const baseValue = lookupBaseValue(enName);
2813
+ if (baseValue === void 0) {
2814
+ return failure("riven.statTypeError");
2815
+ }
2816
+ const unit = entry.attr.unit ?? "";
2817
+ const value = unit === "multiply" ? entry.value - 1 : entry.value;
2818
+ const standardValue = baseValue * factor * disposition;
2819
+ const percent = invertPercent ? (value - standardValue) / standardValue * -1 : (value - standardValue) / standardValue;
2820
+ return {
2821
+ ok: true,
2822
+ data: {
2823
+ name: entry.attr.i18n?.["zh-hans"]?.name ?? enName,
2824
+ unit,
2825
+ value: entry.value,
2826
+ percent,
2827
+ max: invertPercent ? standardValue * 0.9 : standardValue * 1.1,
2828
+ min: invertPercent ? standardValue * 1.1 : standardValue * 0.9
2829
+ }
2830
+ };
2831
+ }, "buildStat");
2832
+ const firstStatName = parseResult.attributes[0]?.attr.i18n?.en?.name;
2833
+ if (!firstStatName) {
2834
+ return failure("riven.statTypeError");
2835
+ }
2836
+ let rivenStatCountType;
2837
+ if (parseResult.attributes.length === 4) {
2838
+ rivenStatCountType = "31";
2839
+ } else if (parseResult.attributes.length === 2) {
2840
+ rivenStatCountType = "2";
2841
+ } else {
5930
2842
  const firstStat = parseResult.attributes[0];
5931
- const firstStatBaseValue = rivenAttrValueDict[weaponType][normalizeName(firstStat.attr.i18n.en.name)];
5932
- if (firstStat.value >= firstStatBaseValue * 1.2375 * 0.9 * disposition) {
5933
- return "21";
5934
- } else {
5935
- return "3";
2843
+ const firstStatBaseValue = lookupBaseValue(firstStatName);
2844
+ if (firstStatBaseValue === void 0) {
2845
+ return failure("riven.statTypeError");
5936
2846
  }
5937
- })();
2847
+ rivenStatCountType = firstStat.value >= firstStatBaseValue * 1.2375 * 0.9 * disposition ? "21" : "3";
2848
+ }
5938
2849
  const { buffFactor, buffCount, curseFactor, curseCount } = rivenStatFixFactor[rivenStatCountType];
5939
2850
  const buffs = [];
5940
2851
  for (let i = 0; i < buffCount; i++) {
5941
- const attr = parseResult.attributes[i];
5942
- const baseValue = rivenAttrValueDict[weaponType][normalizeName(attr.attr.i18n.en.name)];
5943
- const value = attr.attr.unit === "multiply" ? attr.value - 1 : attr.value;
5944
- const standardValue = baseValue * buffFactor * disposition;
5945
- const percent = (value - standardValue) / standardValue;
5946
- buffs.push({
5947
- name: attr.attr.i18n["zh-hans"].name,
5948
- unit: attr.attr.unit,
5949
- value: attr.value,
5950
- percent,
5951
- max: standardValue * 1.1,
5952
- min: standardValue * 0.9
5953
- });
2852
+ const result = buildStat(parseResult.attributes[i], buffFactor, false);
2853
+ if (!result.ok) {
2854
+ return result;
2855
+ }
2856
+ buffs.push(result.data);
5954
2857
  }
5955
2858
  const curses = [];
5956
- if (curseCount > 0) {
5957
- for (let i = buffCount; i < buffCount + curseCount; i++) {
5958
- const attr = parseResult.attributes[i];
5959
- const baseValue = rivenAttrValueDict[weaponType][normalizeName(attr.attr.i18n.en.name)];
5960
- const value = attr.attr.unit === "multiply" ? attr.value - 1 : attr.value;
5961
- const standardValue = baseValue * curseFactor * disposition;
5962
- const percent = (value - standardValue) / standardValue * -1;
5963
- curses.push({
5964
- name: attr.attr.i18n["zh-hans"].name,
5965
- unit: attr.attr.unit,
5966
- value: attr.value,
5967
- percent,
5968
- max: standardValue * 0.9,
5969
- min: standardValue * 1.1
5970
- });
2859
+ for (let i = buffCount; i < buffCount + curseCount; i++) {
2860
+ const result = buildStat(parseResult.attributes[i], curseFactor, true);
2861
+ if (!result.ok) {
2862
+ return result;
5971
2863
  }
2864
+ curses.push(result.data);
5972
2865
  }
5973
2866
  return {
5974
2867
  ok: true,
@@ -6036,7 +2929,7 @@ function buildGlobalItemWordPrefixCandidates(globalItemList) {
6036
2929
  }
6037
2930
  __name(buildGlobalItemWordPrefixCandidates, "buildGlobalItemWordPrefixCandidates");
6038
2931
  async function globalItemDataFactory(response) {
6039
- response ??= await wfmClient.items.getList();
2932
+ response ??= await wfmClient.items.list();
6040
2933
  if (!response) {
6041
2934
  return {
6042
2935
  globalItemList: [],
@@ -6055,11 +2948,13 @@ async function globalItemDataFactory(response) {
6055
2948
  const globalItemNameToSlugDict = ((list) => {
6056
2949
  const result = {};
6057
2950
  for (const item of list) {
6058
- if (item.i18n["zh-hans"]?.name) {
6059
- result[normalizeName(item.i18n["zh-hans"].name)] = item.slug;
2951
+ const zhName = item.i18n?.["zh-hans"]?.name;
2952
+ if (zhName) {
2953
+ result[normalizeName(zhName)] = item.slug;
6060
2954
  }
6061
- if (item.i18n.en?.name) {
6062
- result[normalizeName(item.i18n.en.name)] = item.slug;
2955
+ const enName = item.i18n?.en?.name;
2956
+ if (enName) {
2957
+ result[normalizeName(enName)] = item.slug;
6063
2958
  }
6064
2959
  }
6065
2960
  return result;
@@ -6652,14 +3547,14 @@ async function getItemOrders(input) {
6652
3547
  const itemId = targetItem.slug;
6653
3548
  const targetRank = isFullLevel ? targetItem.maxRank : targetItem.maxRank === void 0 ? void 0 : 0;
6654
3549
  const [data, statsData] = await Promise.all([
6655
- wfmClient.items.getOrders(itemId),
3550
+ wfmClient.orders.listByItem({ slug: itemId }),
6656
3551
  wfmClient.items.getStatistics(itemId)
6657
3552
  ]);
6658
3553
  if (!data) {
6659
3554
  return failure("wfm.orderFetchFailed", true);
6660
3555
  }
6661
3556
  const result = data.filter(
6662
- (order) => order.user.status === "ingame" && order.visible && order.type === "sell" && (!isFullLevel || order.rank === targetItem.maxRank)
3557
+ (order) => order.user?.status === "ingame" && order.visible && order.type === "sell" && (!isFullLevel || order.rank === targetItem.maxRank)
6663
3558
  ).sort((a, b) => toTimeStamp(b.updatedAt) - toTimeStamp(a.updatedAt)).sort((a, b) => a.platinum - b.platinum).slice(0, 8);
6664
3559
  if (result.length === 0) {
6665
3560
  return failure("wfm.noOnlineSeller");
@@ -6694,7 +3589,7 @@ async function getRivenOrders(input) {
6694
3589
  return failure("wfm.rivenOrderFetchFailed", true);
6695
3590
  }
6696
3591
  const top5 = data.filter(
6697
- (order) => order.owner.status === "ingame" && order.visible && !order.private && !order.closed && order.is_direct_sell
3592
+ (order) => order.owner?.status === "ingame" && order.visible && !order.private && !order.closed && order.is_direct_sell
6698
3593
  ).sort((a, b) => toTimeStamp(b.updated) - toTimeStamp(a.updated)).sort((a, b) => a.starting_price - b.starting_price).slice(0, 5);
6699
3594
  if (top5.length === 0) {
6700
3595
  return failure("wfm.noOnlineRivenSeller");
@@ -6788,13 +3683,13 @@ var primedModHistory = createAsyncCache(async () => {
6788
3683
  const lastThree = zeroRankList.slice(-3);
6789
3684
  const avg = lastThree.length > 0 ? Math.round(lastThree.reduce((acc, e) => acc + e.median, 0) / lastThree.length * 10) / 10 : void 0;
6790
3685
  result.push({
6791
- name: item.i18n["zh-hans"]?.name,
3686
+ name: item.i18n?.["zh-hans"]?.name ?? item.i18n?.en?.name,
6792
3687
  last: mod.Last,
6793
3688
  plats: avg
6794
3689
  });
6795
3690
  } else {
6796
3691
  result.push({
6797
- name: item.i18n["zh-hans"]?.name,
3692
+ name: item.i18n?.["zh-hans"]?.name ?? item.i18n?.en?.name,
6798
3693
  last: mod.Last
6799
3694
  });
6800
3695
  }
@@ -6803,6 +3698,8 @@ var primedModHistory = createAsyncCache(async () => {
6803
3698
  }, 432e5);
6804
3699
 
6805
3700
  // src/warframe/services/world-state-refresh.ts
3701
+ var import_warframe_public_export_plus8 = require("warframe-public-export-plus");
3702
+ var ALLOWED_FISSURE_MISSION_TYPES = /* @__PURE__ */ new Set(["MT_EXTERMINATION", "MT_DEFENSE", "MT_ARTIFACT"]);
6806
3703
  function time(value) {
6807
3704
  return value?.getTime() ?? 0;
6808
3705
  }
@@ -6818,6 +3715,11 @@ function fissureId(value) {
6818
3715
  ].join(":");
6819
3716
  }
6820
3717
  __name(fissureId, "fissureId");
3718
+ async function fissureMissionType(fissure) {
3719
+ const nodeKey = await getSolNodeKey(fissure.nodeKey);
3720
+ return import_warframe_public_export_plus8.ExportRegions[nodeKey]?.missionType;
3721
+ }
3722
+ __name(fissureMissionType, "fissureMissionType");
6821
3723
  function dailyDealId(value) {
6822
3724
  return value.id ?? [
6823
3725
  time(value.activation),
@@ -6863,19 +3765,24 @@ async function diffWorldStates(previous, current) {
6863
3765
  const previousFissures = new Set(previous.raw.fissures.map(fissureId));
6864
3766
  for (const fissure of current.raw.fissures) {
6865
3767
  const id = fissureId(fissure);
6866
- if (!previousFissures.has(id)) {
6867
- const mapped = await adaptFissure(fissure);
6868
- notifications.push({
6869
- type: "fissure",
6870
- id,
6871
- tier: mapped.tier,
6872
- tierNum: mapped.tierNum,
6873
- node: mapped.node,
6874
- hard: mapped.hard,
6875
- category: fissure.isStorm ? "railjack" : fissure.isHard ? "steel-path" : "normal",
6876
- expiry: time(fissure.expiry)
6877
- });
3768
+ if (previousFissures.has(id)) {
3769
+ continue;
6878
3770
  }
3771
+ const missionType = await fissureMissionType(fissure);
3772
+ if (!missionType || !ALLOWED_FISSURE_MISSION_TYPES.has(missionType)) {
3773
+ continue;
3774
+ }
3775
+ const mapped = await adaptFissure(fissure);
3776
+ notifications.push({
3777
+ type: "fissure",
3778
+ id,
3779
+ tier: mapped.tier,
3780
+ tierNum: mapped.tierNum,
3781
+ node: mapped.node,
3782
+ hard: mapped.hard,
3783
+ category: fissure.isStorm ? "railjack" : fissure.isHard ? "steel-path" : "normal",
3784
+ expiry: time(fissure.expiry)
3785
+ });
6879
3786
  }
6880
3787
  const previousTimestamp = previous.raw.timestamp.getTime();
6881
3788
  const currentTimestamp = current.raw.timestamp.getTime();
@@ -8809,8 +5716,8 @@ function ItemStatisticsComponent(stats) {
8809
5716
  }
8810
5717
  __name(ItemStatisticsComponent, "ItemStatisticsComponent");
8811
5718
  function ItemOrderComponent(item, orders, statistics) {
8812
- const itemNameCN = item.i18n["zh-hans"]?.name;
8813
- const itemNameEN = item.i18n.en?.name;
5719
+ const itemNameCN = item.i18n?.["zh-hans"]?.name;
5720
+ const itemNameEN = item.i18n?.en?.name;
8814
5721
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: "display:flex;flex-direction:column;width:1600px;background-color:var(--wf-bg-card);border-radius:var(--wf-radius);padding:16px;border:1px solid var(--wf-border);box-shadow:var(--wf-shadow-card);color:var(--wf-text-body);", children: [
8815
5722
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
8816
5723
  th {
@@ -8850,12 +5757,12 @@ function ItemOrderComponent(item, orders, statistics) {
8850
5757
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { style: "width:10%;", children: "好评" })
8851
5758
  ] }),
8852
5759
  orders.map((order) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
8853
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.user.ingameName }),
8854
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.user.status }),
5760
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.user?.ingameName ?? "未知" }),
5761
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.user?.status ?? "未知" }),
8855
5762
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { style: "color:var(--wf-platinum);font-weight:600;", children: order.platinum }),
8856
5763
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.quantity }),
8857
5764
  item.maxRank && item.maxRank > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.rank }) : null,
8858
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.user.reputation })
5765
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: order.user?.reputation ?? "未知" })
8859
5766
  ] }))
8860
5767
  ] }),
8861
5768
  statistics ? ItemStatisticsComponent(statistics) : null
@@ -9026,14 +5933,10 @@ function RivenOrderItemComponent(order, cnName, enName, thumb) {
9026
5933
  __name(RivenOrderItemComponent, "RivenOrderItemComponent");
9027
5934
  function RivenAttributeComponent(attr, index) {
9028
5935
  const attrInfo = attr.attribute;
9029
- const attrName = attrInfo.i18n["zh-hans"].name;
9030
- const attrValuePrefix = attrInfo.unit === "multiply" ? "x" : "";
9031
- const unitSuffixMap = {
9032
- percent: "%",
9033
- second: "s",
9034
- multiply: ""
9035
- };
9036
- const attrValueSuffix = unitSuffixMap[attrInfo.unit] || "";
5936
+ const attrName = attrInfo?.i18n?.["zh-hans"]?.name ?? attrInfo?.i18n?.en?.name ?? attr.url_name;
5937
+ const unit = attrInfo?.unit ?? "";
5938
+ const attrValuePrefix = unit === "multiply" ? "x" : "";
5939
+ const attrValueSuffix = unit === "percent" ? "%" : unit === "second" ? "s" : "";
9037
5940
  const attrValue = attrValuePrefix + attr.value + attrValueSuffix;
9038
5941
  const positiveColors = ["#2e7d32", "#4a8c5a", "#6b9b78"];
9039
5942
  const negativeColor = "#e05050";
@@ -9324,7 +6227,7 @@ function buildStatisticsTextLine(stats) {
9324
6227
  __name(buildStatisticsTextLine, "buildStatisticsTextLine");
9325
6228
  function wmMessage(img, item, orders, statistics) {
9326
6229
  const lines = orders.slice(0, 3).map((order) => `
9327
- /w ${order.user.ingameName} Hi! I want to buy: "${item.i18n.en?.name}${!item.maxRank || item.maxRank === 0 ? "" : ` (rank ${order.rank})`}" for ${order.platinum} platinum. (warframe.market)`);
6230
+ /w ${order.user?.ingameName ?? "Unknown"} Hi! I want to buy: "${item.i18n?.en?.name ?? item.i18n?.["zh-hans"]?.name ?? item.slug}${!item.maxRank || item.maxRank === 0 ? "" : ` (rank ${order.rank})`}" for ${order.platinum} platinum. (warframe.market)`);
9328
6231
  const statLine = statistics ? buildStatisticsTextLine(statistics) : "";
9329
6232
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("message", { children: [
9330
6233
  img,