@mcp-s/skills 1.0.2 → 1.3.1

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.
@@ -0,0 +1,4141 @@
1
+ import { n as __require, t as __commonJSMin } from "../rolldown-runtime.mjs";
2
+ var require_es5 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3
+ var isES5 = (function() {
4
+ "use strict";
5
+ return this === void 0;
6
+ })();
7
+ if (isES5) module.exports = {
8
+ freeze: Object.freeze,
9
+ defineProperty: Object.defineProperty,
10
+ getDescriptor: Object.getOwnPropertyDescriptor,
11
+ keys: Object.keys,
12
+ names: Object.getOwnPropertyNames,
13
+ getPrototypeOf: Object.getPrototypeOf,
14
+ isArray: Array.isArray,
15
+ isES5,
16
+ propertyIsWritable: function(obj, prop) {
17
+ var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
18
+ return !!(!descriptor || descriptor.writable || descriptor.set);
19
+ }
20
+ };
21
+ else {
22
+ var has = {}.hasOwnProperty;
23
+ var str = {}.toString;
24
+ var proto = {}.constructor.prototype;
25
+ var ObjectKeys = function(o) {
26
+ var ret = [];
27
+ for (var key in o) if (has.call(o, key)) ret.push(key);
28
+ return ret;
29
+ };
30
+ var ObjectGetDescriptor = function(o, key) {
31
+ return { value: o[key] };
32
+ };
33
+ var ObjectDefineProperty = function(o, key, desc) {
34
+ o[key] = desc.value;
35
+ return o;
36
+ };
37
+ var ObjectFreeze = function(obj) {
38
+ return obj;
39
+ };
40
+ var ObjectGetPrototypeOf = function(obj) {
41
+ try {
42
+ return Object(obj).constructor.prototype;
43
+ } catch (e) {
44
+ return proto;
45
+ }
46
+ };
47
+ var ArrayIsArray = function(obj) {
48
+ try {
49
+ return str.call(obj) === "[object Array]";
50
+ } catch (e) {
51
+ return false;
52
+ }
53
+ };
54
+ module.exports = {
55
+ isArray: ArrayIsArray,
56
+ keys: ObjectKeys,
57
+ names: ObjectKeys,
58
+ defineProperty: ObjectDefineProperty,
59
+ getDescriptor: ObjectGetDescriptor,
60
+ freeze: ObjectFreeze,
61
+ getPrototypeOf: ObjectGetPrototypeOf,
62
+ isES5,
63
+ propertyIsWritable: function() {
64
+ return true;
65
+ }
66
+ };
67
+ }
68
+ }));
69
+ var require_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
70
+ var es5 = require_es5();
71
+ var canEvaluate = typeof navigator == "undefined";
72
+ var errorObj = { e: {} };
73
+ var tryCatchTarget;
74
+ var globalObject = typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : exports !== void 0 ? exports : null;
75
+ function tryCatcher() {
76
+ try {
77
+ var target = tryCatchTarget;
78
+ tryCatchTarget = null;
79
+ return target.apply(this, arguments);
80
+ } catch (e) {
81
+ errorObj.e = e;
82
+ return errorObj;
83
+ }
84
+ }
85
+ function tryCatch(fn) {
86
+ tryCatchTarget = fn;
87
+ return tryCatcher;
88
+ }
89
+ var inherits = function(Child, Parent) {
90
+ var hasProp = {}.hasOwnProperty;
91
+ function T() {
92
+ this.constructor = Child;
93
+ this.constructor$ = Parent;
94
+ for (var propertyName in Parent.prototype) if (hasProp.call(Parent.prototype, propertyName) && propertyName.charAt(propertyName.length - 1) !== "$") this[propertyName + "$"] = Parent.prototype[propertyName];
95
+ }
96
+ T.prototype = Parent.prototype;
97
+ Child.prototype = new T();
98
+ return Child.prototype;
99
+ };
100
+ function isPrimitive(val) {
101
+ return val == null || val === true || val === false || typeof val === "string" || typeof val === "number";
102
+ }
103
+ function isObject(value) {
104
+ return typeof value === "function" || typeof value === "object" && value !== null;
105
+ }
106
+ function maybeWrapAsError(maybeError) {
107
+ if (!isPrimitive(maybeError)) return maybeError;
108
+ return new Error(safeToString(maybeError));
109
+ }
110
+ function withAppended(target, appendee) {
111
+ var len = target.length;
112
+ var ret = new Array(len + 1);
113
+ var i;
114
+ for (i = 0; i < len; ++i) ret[i] = target[i];
115
+ ret[i] = appendee;
116
+ return ret;
117
+ }
118
+ function getDataPropertyOrDefault(obj, key, defaultValue) {
119
+ if (es5.isES5) {
120
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
121
+ if (desc != null) return desc.get == null && desc.set == null ? desc.value : defaultValue;
122
+ } else return {}.hasOwnProperty.call(obj, key) ? obj[key] : void 0;
123
+ }
124
+ function notEnumerableProp(obj, name, value) {
125
+ if (isPrimitive(obj)) return obj;
126
+ var descriptor = {
127
+ value,
128
+ configurable: true,
129
+ enumerable: false,
130
+ writable: true
131
+ };
132
+ es5.defineProperty(obj, name, descriptor);
133
+ return obj;
134
+ }
135
+ function thrower(r) {
136
+ throw r;
137
+ }
138
+ var inheritedDataKeys = (function() {
139
+ var excludedPrototypes = [
140
+ Array.prototype,
141
+ Object.prototype,
142
+ Function.prototype
143
+ ];
144
+ var isExcludedProto = function(val) {
145
+ for (var i = 0; i < excludedPrototypes.length; ++i) if (excludedPrototypes[i] === val) return true;
146
+ return false;
147
+ };
148
+ if (es5.isES5) {
149
+ var getKeys = Object.getOwnPropertyNames;
150
+ return function(obj) {
151
+ var ret = [];
152
+ var visitedKeys = Object.create(null);
153
+ while (obj != null && !isExcludedProto(obj)) {
154
+ var keys;
155
+ try {
156
+ keys = getKeys(obj);
157
+ } catch (e) {
158
+ return ret;
159
+ }
160
+ for (var i = 0; i < keys.length; ++i) {
161
+ var key = keys[i];
162
+ if (visitedKeys[key]) continue;
163
+ visitedKeys[key] = true;
164
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
165
+ if (desc != null && desc.get == null && desc.set == null) ret.push(key);
166
+ }
167
+ obj = es5.getPrototypeOf(obj);
168
+ }
169
+ return ret;
170
+ };
171
+ } else {
172
+ var hasProp = {}.hasOwnProperty;
173
+ return function(obj) {
174
+ if (isExcludedProto(obj)) return [];
175
+ var ret = [];
176
+ enumeration: for (var key in obj) if (hasProp.call(obj, key)) ret.push(key);
177
+ else {
178
+ for (var i = 0; i < excludedPrototypes.length; ++i) if (hasProp.call(excludedPrototypes[i], key)) continue enumeration;
179
+ ret.push(key);
180
+ }
181
+ return ret;
182
+ };
183
+ }
184
+ })();
185
+ var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
186
+ function isClass(fn) {
187
+ try {
188
+ if (typeof fn === "function") {
189
+ var keys = es5.names(fn.prototype);
190
+ var hasMethods = es5.isES5 && keys.length > 1;
191
+ var hasMethodsOtherThanConstructor = keys.length > 0 && !(keys.length === 1 && keys[0] === "constructor");
192
+ var hasThisAssignmentAndStaticMethods = thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
193
+ if (hasMethods || hasMethodsOtherThanConstructor || hasThisAssignmentAndStaticMethods) return true;
194
+ }
195
+ return false;
196
+ } catch (e) {
197
+ return false;
198
+ }
199
+ }
200
+ function toFastProperties(obj) {
201
+ function FakeConstructor() {}
202
+ FakeConstructor.prototype = obj;
203
+ var receiver = new FakeConstructor();
204
+ function ic() {
205
+ return typeof receiver.foo;
206
+ }
207
+ ic();
208
+ ic();
209
+ return obj;
210
+ }
211
+ var rident = /^[a-z$_][a-z$_0-9]*$/i;
212
+ function isIdentifier(str) {
213
+ return rident.test(str);
214
+ }
215
+ function filledRange(count, prefix, suffix) {
216
+ var ret = new Array(count);
217
+ for (var i = 0; i < count; ++i) ret[i] = prefix + i + suffix;
218
+ return ret;
219
+ }
220
+ function safeToString(obj) {
221
+ try {
222
+ return obj + "";
223
+ } catch (e) {
224
+ return "[no string representation]";
225
+ }
226
+ }
227
+ function isError(obj) {
228
+ return obj instanceof Error || obj !== null && typeof obj === "object" && typeof obj.message === "string" && typeof obj.name === "string";
229
+ }
230
+ function markAsOriginatingFromRejection(e) {
231
+ try {
232
+ notEnumerableProp(e, "isOperational", true);
233
+ } catch (ignore) {}
234
+ }
235
+ function originatesFromRejection(e) {
236
+ if (e == null) return false;
237
+ return e instanceof Error["__BluebirdErrorTypes__"].OperationalError || e["isOperational"] === true;
238
+ }
239
+ function canAttachTrace(obj) {
240
+ return isError(obj) && es5.propertyIsWritable(obj, "stack");
241
+ }
242
+ var ensureErrorObject = (function() {
243
+ if (!("stack" in /* @__PURE__ */ new Error())) return function(value) {
244
+ if (canAttachTrace(value)) return value;
245
+ try {
246
+ throw new Error(safeToString(value));
247
+ } catch (err) {
248
+ return err;
249
+ }
250
+ };
251
+ else return function(value) {
252
+ if (canAttachTrace(value)) return value;
253
+ return new Error(safeToString(value));
254
+ };
255
+ })();
256
+ function classString(obj) {
257
+ return {}.toString.call(obj);
258
+ }
259
+ function copyDescriptors(from, to, filter) {
260
+ var keys = es5.names(from);
261
+ for (var i = 0; i < keys.length; ++i) {
262
+ var key = keys[i];
263
+ if (filter(key)) try {
264
+ es5.defineProperty(to, key, es5.getDescriptor(from, key));
265
+ } catch (ignore) {}
266
+ }
267
+ }
268
+ var asArray = function(v) {
269
+ if (es5.isArray(v)) return v;
270
+ return null;
271
+ };
272
+ if (typeof Symbol !== "undefined" && Symbol.iterator) {
273
+ var ArrayFrom = typeof Array.from === "function" ? function(v) {
274
+ return Array.from(v);
275
+ } : function(v) {
276
+ var ret = [];
277
+ var it = v[Symbol.iterator]();
278
+ var itResult;
279
+ while (!(itResult = it.next()).done) ret.push(itResult.value);
280
+ return ret;
281
+ };
282
+ asArray = function(v) {
283
+ if (es5.isArray(v)) return v;
284
+ else if (v != null && typeof v[Symbol.iterator] === "function") return ArrayFrom(v);
285
+ return null;
286
+ };
287
+ }
288
+ var isNode = typeof process !== "undefined" && classString(process).toLowerCase() === "[object process]";
289
+ var hasEnvVariables = typeof process !== "undefined" && typeof process.env !== "undefined";
290
+ function env(key) {
291
+ return hasEnvVariables ? process.env[key] : void 0;
292
+ }
293
+ function getNativePromise() {
294
+ if (typeof Promise === "function") try {
295
+ if (classString(new Promise(function() {})) === "[object Promise]") return Promise;
296
+ } catch (e) {}
297
+ }
298
+ var reflectHandler;
299
+ function contextBind(ctx, cb) {
300
+ if (ctx === null || typeof cb !== "function" || cb === reflectHandler) return cb;
301
+ if (ctx.domain !== null) cb = ctx.domain.bind(cb);
302
+ var async = ctx.async;
303
+ if (async !== null) {
304
+ var old = cb;
305
+ cb = function() {
306
+ var $_len = arguments.length + 2;
307
+ var args = new Array($_len);
308
+ for (var $_i = 2; $_i < $_len; ++$_i) args[$_i] = arguments[$_i - 2];
309
+ args[0] = old;
310
+ args[1] = this;
311
+ return async.runInAsyncScope.apply(async, args);
312
+ };
313
+ }
314
+ return cb;
315
+ }
316
+ var ret = {
317
+ setReflectHandler: function(fn) {
318
+ reflectHandler = fn;
319
+ },
320
+ isClass,
321
+ isIdentifier,
322
+ inheritedDataKeys,
323
+ getDataPropertyOrDefault,
324
+ thrower,
325
+ isArray: es5.isArray,
326
+ asArray,
327
+ notEnumerableProp,
328
+ isPrimitive,
329
+ isObject,
330
+ isError,
331
+ canEvaluate,
332
+ errorObj,
333
+ tryCatch,
334
+ inherits,
335
+ withAppended,
336
+ maybeWrapAsError,
337
+ toFastProperties,
338
+ filledRange,
339
+ toString: safeToString,
340
+ canAttachTrace,
341
+ ensureErrorObject,
342
+ originatesFromRejection,
343
+ markAsOriginatingFromRejection,
344
+ classString,
345
+ copyDescriptors,
346
+ isNode,
347
+ hasEnvVariables,
348
+ env,
349
+ global: globalObject,
350
+ getNativePromise,
351
+ contextBind
352
+ };
353
+ ret.isRecentNode = ret.isNode && (function() {
354
+ var version;
355
+ if (process.versions && process.versions.node) version = process.versions.node.split(".").map(Number);
356
+ else if (process.version) version = process.version.split(".").map(Number);
357
+ return version[0] === 0 && version[1] > 10 || version[0] > 0;
358
+ })();
359
+ ret.nodeSupportsAsyncResource = ret.isNode && (function() {
360
+ var supportsAsync = false;
361
+ try {
362
+ supportsAsync = typeof __require("async_hooks").AsyncResource.prototype.runInAsyncScope === "function";
363
+ } catch (e) {
364
+ supportsAsync = false;
365
+ }
366
+ return supportsAsync;
367
+ })();
368
+ if (ret.isNode) ret.toFastProperties(process);
369
+ try {
370
+ throw new Error();
371
+ } catch (e) {
372
+ ret.lastLineError = e;
373
+ }
374
+ module.exports = ret;
375
+ }));
376
+ var require_schedule = /* @__PURE__ */ __commonJSMin(((exports, module) => {
377
+ var util = require_util();
378
+ var schedule;
379
+ var noAsyncScheduler = function() {
380
+ throw new Error("No async scheduler available\n\n See http://goo.gl/MqrFmX\n");
381
+ };
382
+ var NativePromise = util.getNativePromise();
383
+ if (util.isNode && typeof MutationObserver === "undefined") {
384
+ var GlobalSetImmediate = global.setImmediate;
385
+ var ProcessNextTick = process.nextTick;
386
+ schedule = util.isRecentNode ? function(fn) {
387
+ GlobalSetImmediate.call(global, fn);
388
+ } : function(fn) {
389
+ ProcessNextTick.call(process, fn);
390
+ };
391
+ } else if (typeof NativePromise === "function" && typeof NativePromise.resolve === "function") {
392
+ var nativePromise = NativePromise.resolve();
393
+ schedule = function(fn) {
394
+ nativePromise.then(fn);
395
+ };
396
+ } else if (typeof MutationObserver !== "undefined" && !(typeof window !== "undefined" && window.navigator && (window.navigator.standalone || window.cordova)) && "classList" in document.documentElement) schedule = (function() {
397
+ var div = document.createElement("div");
398
+ var opts = { attributes: true };
399
+ var toggleScheduled = false;
400
+ var div2 = document.createElement("div");
401
+ new MutationObserver(function() {
402
+ div.classList.toggle("foo");
403
+ toggleScheduled = false;
404
+ }).observe(div2, opts);
405
+ var scheduleToggle = function() {
406
+ if (toggleScheduled) return;
407
+ toggleScheduled = true;
408
+ div2.classList.toggle("foo");
409
+ };
410
+ return function schedule(fn) {
411
+ var o = new MutationObserver(function() {
412
+ o.disconnect();
413
+ fn();
414
+ });
415
+ o.observe(div, opts);
416
+ scheduleToggle();
417
+ };
418
+ })();
419
+ else if (typeof setImmediate !== "undefined") schedule = function(fn) {
420
+ setImmediate(fn);
421
+ };
422
+ else if (typeof setTimeout !== "undefined") schedule = function(fn) {
423
+ setTimeout(fn, 0);
424
+ };
425
+ else schedule = noAsyncScheduler;
426
+ module.exports = schedule;
427
+ }));
428
+ var require_queue = /* @__PURE__ */ __commonJSMin(((exports, module) => {
429
+ function arrayMove(src, srcIndex, dst, dstIndex, len) {
430
+ for (var j = 0; j < len; ++j) {
431
+ dst[j + dstIndex] = src[j + srcIndex];
432
+ src[j + srcIndex] = void 0;
433
+ }
434
+ }
435
+ function Queue(capacity) {
436
+ this._capacity = capacity;
437
+ this._length = 0;
438
+ this._front = 0;
439
+ }
440
+ Queue.prototype._willBeOverCapacity = function(size) {
441
+ return this._capacity < size;
442
+ };
443
+ Queue.prototype._pushOne = function(arg) {
444
+ var length = this.length();
445
+ this._checkCapacity(length + 1);
446
+ var i = this._front + length & this._capacity - 1;
447
+ this[i] = arg;
448
+ this._length = length + 1;
449
+ };
450
+ Queue.prototype.push = function(fn, receiver, arg) {
451
+ var length = this.length() + 3;
452
+ if (this._willBeOverCapacity(length)) {
453
+ this._pushOne(fn);
454
+ this._pushOne(receiver);
455
+ this._pushOne(arg);
456
+ return;
457
+ }
458
+ var j = this._front + length - 3;
459
+ this._checkCapacity(length);
460
+ var wrapMask = this._capacity - 1;
461
+ this[j + 0 & wrapMask] = fn;
462
+ this[j + 1 & wrapMask] = receiver;
463
+ this[j + 2 & wrapMask] = arg;
464
+ this._length = length;
465
+ };
466
+ Queue.prototype.shift = function() {
467
+ var front = this._front, ret = this[front];
468
+ this[front] = void 0;
469
+ this._front = front + 1 & this._capacity - 1;
470
+ this._length--;
471
+ return ret;
472
+ };
473
+ Queue.prototype.length = function() {
474
+ return this._length;
475
+ };
476
+ Queue.prototype._checkCapacity = function(size) {
477
+ if (this._capacity < size) this._resizeTo(this._capacity << 1);
478
+ };
479
+ Queue.prototype._resizeTo = function(capacity) {
480
+ var oldCapacity = this._capacity;
481
+ this._capacity = capacity;
482
+ var moveItemsCount = this._front + this._length & oldCapacity - 1;
483
+ arrayMove(this, 0, this, oldCapacity, moveItemsCount);
484
+ };
485
+ module.exports = Queue;
486
+ }));
487
+ var require_async = /* @__PURE__ */ __commonJSMin(((exports, module) => {
488
+ var firstLineError;
489
+ try {
490
+ throw new Error();
491
+ } catch (e) {
492
+ firstLineError = e;
493
+ }
494
+ var schedule = require_schedule();
495
+ var Queue = require_queue();
496
+ function Async() {
497
+ this._customScheduler = false;
498
+ this._isTickUsed = false;
499
+ this._lateQueue = new Queue(16);
500
+ this._normalQueue = new Queue(16);
501
+ this._haveDrainedQueues = false;
502
+ var self = this;
503
+ this.drainQueues = function() {
504
+ self._drainQueues();
505
+ };
506
+ this._schedule = schedule;
507
+ }
508
+ Async.prototype.setScheduler = function(fn) {
509
+ var prev = this._schedule;
510
+ this._schedule = fn;
511
+ this._customScheduler = true;
512
+ return prev;
513
+ };
514
+ Async.prototype.hasCustomScheduler = function() {
515
+ return this._customScheduler;
516
+ };
517
+ Async.prototype.haveItemsQueued = function() {
518
+ return this._isTickUsed || this._haveDrainedQueues;
519
+ };
520
+ Async.prototype.fatalError = function(e, isNode) {
521
+ if (isNode) {
522
+ process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) + "\n");
523
+ process.exit(2);
524
+ } else this.throwLater(e);
525
+ };
526
+ Async.prototype.throwLater = function(fn, arg) {
527
+ if (arguments.length === 1) {
528
+ arg = fn;
529
+ fn = function() {
530
+ throw arg;
531
+ };
532
+ }
533
+ if (typeof setTimeout !== "undefined") setTimeout(function() {
534
+ fn(arg);
535
+ }, 0);
536
+ else try {
537
+ this._schedule(function() {
538
+ fn(arg);
539
+ });
540
+ } catch (e) {
541
+ throw new Error("No async scheduler available\n\n See http://goo.gl/MqrFmX\n");
542
+ }
543
+ };
544
+ function AsyncInvokeLater(fn, receiver, arg) {
545
+ this._lateQueue.push(fn, receiver, arg);
546
+ this._queueTick();
547
+ }
548
+ function AsyncInvoke(fn, receiver, arg) {
549
+ this._normalQueue.push(fn, receiver, arg);
550
+ this._queueTick();
551
+ }
552
+ function AsyncSettlePromises(promise) {
553
+ this._normalQueue._pushOne(promise);
554
+ this._queueTick();
555
+ }
556
+ Async.prototype.invokeLater = AsyncInvokeLater;
557
+ Async.prototype.invoke = AsyncInvoke;
558
+ Async.prototype.settlePromises = AsyncSettlePromises;
559
+ function _drainQueue(queue) {
560
+ while (queue.length() > 0) _drainQueueStep(queue);
561
+ }
562
+ function _drainQueueStep(queue) {
563
+ var fn = queue.shift();
564
+ if (typeof fn !== "function") fn._settlePromises();
565
+ else {
566
+ var receiver = queue.shift();
567
+ var arg = queue.shift();
568
+ fn.call(receiver, arg);
569
+ }
570
+ }
571
+ Async.prototype._drainQueues = function() {
572
+ _drainQueue(this._normalQueue);
573
+ this._reset();
574
+ this._haveDrainedQueues = true;
575
+ _drainQueue(this._lateQueue);
576
+ };
577
+ Async.prototype._queueTick = function() {
578
+ if (!this._isTickUsed) {
579
+ this._isTickUsed = true;
580
+ this._schedule(this.drainQueues);
581
+ }
582
+ };
583
+ Async.prototype._reset = function() {
584
+ this._isTickUsed = false;
585
+ };
586
+ module.exports = Async;
587
+ module.exports.firstLineError = firstLineError;
588
+ }));
589
+ var require_errors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
590
+ var es5 = require_es5();
591
+ var Objectfreeze = es5.freeze;
592
+ var util = require_util();
593
+ var inherits = util.inherits;
594
+ var notEnumerableProp = util.notEnumerableProp;
595
+ function subError(nameProperty, defaultMessage) {
596
+ function SubError(message) {
597
+ if (!(this instanceof SubError)) return new SubError(message);
598
+ notEnumerableProp(this, "message", typeof message === "string" ? message : defaultMessage);
599
+ notEnumerableProp(this, "name", nameProperty);
600
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
601
+ else Error.call(this);
602
+ }
603
+ inherits(SubError, Error);
604
+ return SubError;
605
+ }
606
+ var _TypeError, _RangeError;
607
+ var Warning = subError("Warning", "warning");
608
+ var CancellationError = subError("CancellationError", "cancellation error");
609
+ var TimeoutError = subError("TimeoutError", "timeout error");
610
+ var AggregateError = subError("AggregateError", "aggregate error");
611
+ try {
612
+ _TypeError = TypeError;
613
+ _RangeError = RangeError;
614
+ } catch (e) {
615
+ _TypeError = subError("TypeError", "type error");
616
+ _RangeError = subError("RangeError", "range error");
617
+ }
618
+ var methods = "join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" ");
619
+ for (var i = 0; i < methods.length; ++i) if (typeof Array.prototype[methods[i]] === "function") AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
620
+ es5.defineProperty(AggregateError.prototype, "length", {
621
+ value: 0,
622
+ configurable: false,
623
+ writable: true,
624
+ enumerable: true
625
+ });
626
+ AggregateError.prototype["isOperational"] = true;
627
+ var level = 0;
628
+ AggregateError.prototype.toString = function() {
629
+ var indent = Array(level * 4 + 1).join(" ");
630
+ var ret = "\n" + indent + "AggregateError of:\n";
631
+ level++;
632
+ indent = Array(level * 4 + 1).join(" ");
633
+ for (var i = 0; i < this.length; ++i) {
634
+ var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
635
+ var lines = str.split("\n");
636
+ for (var j = 0; j < lines.length; ++j) lines[j] = indent + lines[j];
637
+ str = lines.join("\n");
638
+ ret += str + "\n";
639
+ }
640
+ level--;
641
+ return ret;
642
+ };
643
+ function OperationalError(message) {
644
+ if (!(this instanceof OperationalError)) return new OperationalError(message);
645
+ notEnumerableProp(this, "name", "OperationalError");
646
+ notEnumerableProp(this, "message", message);
647
+ this.cause = message;
648
+ this["isOperational"] = true;
649
+ if (message instanceof Error) {
650
+ notEnumerableProp(this, "message", message.message);
651
+ notEnumerableProp(this, "stack", message.stack);
652
+ } else if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
653
+ }
654
+ inherits(OperationalError, Error);
655
+ var errorTypes = Error["__BluebirdErrorTypes__"];
656
+ if (!errorTypes) {
657
+ errorTypes = Objectfreeze({
658
+ CancellationError,
659
+ TimeoutError,
660
+ OperationalError,
661
+ RejectionError: OperationalError,
662
+ AggregateError
663
+ });
664
+ es5.defineProperty(Error, "__BluebirdErrorTypes__", {
665
+ value: errorTypes,
666
+ writable: false,
667
+ enumerable: false,
668
+ configurable: false
669
+ });
670
+ }
671
+ module.exports = {
672
+ Error,
673
+ TypeError: _TypeError,
674
+ RangeError: _RangeError,
675
+ CancellationError: errorTypes.CancellationError,
676
+ OperationalError: errorTypes.OperationalError,
677
+ TimeoutError: errorTypes.TimeoutError,
678
+ AggregateError: errorTypes.AggregateError,
679
+ Warning
680
+ };
681
+ }));
682
+ var require_thenables = /* @__PURE__ */ __commonJSMin(((exports, module) => {
683
+ module.exports = function(Promise, INTERNAL) {
684
+ var util = require_util();
685
+ var errorObj = util.errorObj;
686
+ var isObject = util.isObject;
687
+ function tryConvertToPromise(obj, context) {
688
+ if (isObject(obj)) {
689
+ if (obj instanceof Promise) return obj;
690
+ var then = getThen(obj);
691
+ if (then === errorObj) {
692
+ if (context) context._pushContext();
693
+ var ret = Promise.reject(then.e);
694
+ if (context) context._popContext();
695
+ return ret;
696
+ } else if (typeof then === "function") {
697
+ if (isAnyBluebirdPromise(obj)) {
698
+ var ret = new Promise(INTERNAL);
699
+ obj._then(ret._fulfill, ret._reject, void 0, ret, null);
700
+ return ret;
701
+ }
702
+ return doThenable(obj, then, context);
703
+ }
704
+ }
705
+ return obj;
706
+ }
707
+ function doGetThen(obj) {
708
+ return obj.then;
709
+ }
710
+ function getThen(obj) {
711
+ try {
712
+ return doGetThen(obj);
713
+ } catch (e) {
714
+ errorObj.e = e;
715
+ return errorObj;
716
+ }
717
+ }
718
+ var hasProp = {}.hasOwnProperty;
719
+ function isAnyBluebirdPromise(obj) {
720
+ try {
721
+ return hasProp.call(obj, "_promise0");
722
+ } catch (e) {
723
+ return false;
724
+ }
725
+ }
726
+ function doThenable(x, then, context) {
727
+ var promise = new Promise(INTERNAL);
728
+ var ret = promise;
729
+ if (context) context._pushContext();
730
+ promise._captureStackTrace();
731
+ if (context) context._popContext();
732
+ var synchronous = true;
733
+ var result = util.tryCatch(then).call(x, resolve, reject);
734
+ synchronous = false;
735
+ if (promise && result === errorObj) {
736
+ promise._rejectCallback(result.e, true, true);
737
+ promise = null;
738
+ }
739
+ function resolve(value) {
740
+ if (!promise) return;
741
+ promise._resolveCallback(value);
742
+ promise = null;
743
+ }
744
+ function reject(reason) {
745
+ if (!promise) return;
746
+ promise._rejectCallback(reason, synchronous, true);
747
+ promise = null;
748
+ }
749
+ return ret;
750
+ }
751
+ return tryConvertToPromise;
752
+ };
753
+ }));
754
+ var require_promise_array = /* @__PURE__ */ __commonJSMin(((exports, module) => {
755
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise, apiRejection, Proxyable) {
756
+ var util = require_util();
757
+ util.isArray;
758
+ function toResolutionValue(val) {
759
+ switch (val) {
760
+ case -2: return [];
761
+ case -3: return {};
762
+ case -6: return /* @__PURE__ */ new Map();
763
+ }
764
+ }
765
+ function PromiseArray(values) {
766
+ var promise = this._promise = new Promise(INTERNAL);
767
+ if (values instanceof Promise) {
768
+ promise._propagateFrom(values, 3);
769
+ values.suppressUnhandledRejections();
770
+ }
771
+ promise._setOnCancel(this);
772
+ this._values = values;
773
+ this._length = 0;
774
+ this._totalResolved = 0;
775
+ this._init(void 0, -2);
776
+ }
777
+ util.inherits(PromiseArray, Proxyable);
778
+ PromiseArray.prototype.length = function() {
779
+ return this._length;
780
+ };
781
+ PromiseArray.prototype.promise = function() {
782
+ return this._promise;
783
+ };
784
+ PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
785
+ var values = tryConvertToPromise(this._values, this._promise);
786
+ if (values instanceof Promise) {
787
+ values = values._target();
788
+ var bitField = values._bitField;
789
+ this._values = values;
790
+ if ((bitField & 50397184) === 0) {
791
+ this._promise._setAsyncGuaranteed();
792
+ return values._then(init, this._reject, void 0, this, resolveValueIfEmpty);
793
+ } else if ((bitField & 33554432) !== 0) values = values._value();
794
+ else if ((bitField & 16777216) !== 0) return this._reject(values._reason());
795
+ else return this._cancel();
796
+ }
797
+ values = util.asArray(values);
798
+ if (values === null) {
799
+ var err = apiRejection("expecting an array or an iterable object but got " + util.classString(values)).reason();
800
+ this._promise._rejectCallback(err, false);
801
+ return;
802
+ }
803
+ if (values.length === 0) {
804
+ if (resolveValueIfEmpty === -5) this._resolveEmptyArray();
805
+ else this._resolve(toResolutionValue(resolveValueIfEmpty));
806
+ return;
807
+ }
808
+ this._iterate(values);
809
+ };
810
+ PromiseArray.prototype._iterate = function(values) {
811
+ var len = this.getActualLength(values.length);
812
+ this._length = len;
813
+ this._values = this.shouldCopyValues() ? new Array(len) : this._values;
814
+ var result = this._promise;
815
+ var isResolved = false;
816
+ var bitField = null;
817
+ for (var i = 0; i < len; ++i) {
818
+ var maybePromise = tryConvertToPromise(values[i], result);
819
+ if (maybePromise instanceof Promise) {
820
+ maybePromise = maybePromise._target();
821
+ bitField = maybePromise._bitField;
822
+ } else bitField = null;
823
+ if (isResolved) {
824
+ if (bitField !== null) maybePromise.suppressUnhandledRejections();
825
+ } else if (bitField !== null) if ((bitField & 50397184) === 0) {
826
+ maybePromise._proxy(this, i);
827
+ this._values[i] = maybePromise;
828
+ } else if ((bitField & 33554432) !== 0) isResolved = this._promiseFulfilled(maybePromise._value(), i);
829
+ else if ((bitField & 16777216) !== 0) isResolved = this._promiseRejected(maybePromise._reason(), i);
830
+ else isResolved = this._promiseCancelled(i);
831
+ else isResolved = this._promiseFulfilled(maybePromise, i);
832
+ }
833
+ if (!isResolved) result._setAsyncGuaranteed();
834
+ };
835
+ PromiseArray.prototype._isResolved = function() {
836
+ return this._values === null;
837
+ };
838
+ PromiseArray.prototype._resolve = function(value) {
839
+ this._values = null;
840
+ this._promise._fulfill(value);
841
+ };
842
+ PromiseArray.prototype._cancel = function() {
843
+ if (this._isResolved() || !this._promise._isCancellable()) return;
844
+ this._values = null;
845
+ this._promise._cancel();
846
+ };
847
+ PromiseArray.prototype._reject = function(reason) {
848
+ this._values = null;
849
+ this._promise._rejectCallback(reason, false);
850
+ };
851
+ PromiseArray.prototype._promiseFulfilled = function(value, index) {
852
+ this._values[index] = value;
853
+ if (++this._totalResolved >= this._length) {
854
+ this._resolve(this._values);
855
+ return true;
856
+ }
857
+ return false;
858
+ };
859
+ PromiseArray.prototype._promiseCancelled = function() {
860
+ this._cancel();
861
+ return true;
862
+ };
863
+ PromiseArray.prototype._promiseRejected = function(reason) {
864
+ this._totalResolved++;
865
+ this._reject(reason);
866
+ return true;
867
+ };
868
+ PromiseArray.prototype._resultCancelled = function() {
869
+ if (this._isResolved()) return;
870
+ var values = this._values;
871
+ this._cancel();
872
+ if (values instanceof Promise) values.cancel();
873
+ else for (var i = 0; i < values.length; ++i) if (values[i] instanceof Promise) values[i].cancel();
874
+ };
875
+ PromiseArray.prototype.shouldCopyValues = function() {
876
+ return true;
877
+ };
878
+ PromiseArray.prototype.getActualLength = function(len) {
879
+ return len;
880
+ };
881
+ return PromiseArray;
882
+ };
883
+ }));
884
+ var require_context = /* @__PURE__ */ __commonJSMin(((exports, module) => {
885
+ module.exports = function(Promise) {
886
+ var longStackTraces = false;
887
+ var contextStack = [];
888
+ Promise.prototype._promiseCreated = function() {};
889
+ Promise.prototype._pushContext = function() {};
890
+ Promise.prototype._popContext = function() {
891
+ return null;
892
+ };
893
+ Promise._peekContext = Promise.prototype._peekContext = function() {};
894
+ function Context() {
895
+ this._trace = new Context.CapturedTrace(peekContext());
896
+ }
897
+ Context.prototype._pushContext = function() {
898
+ if (this._trace !== void 0) {
899
+ this._trace._promiseCreated = null;
900
+ contextStack.push(this._trace);
901
+ }
902
+ };
903
+ Context.prototype._popContext = function() {
904
+ if (this._trace !== void 0) {
905
+ var trace = contextStack.pop();
906
+ var ret = trace._promiseCreated;
907
+ trace._promiseCreated = null;
908
+ return ret;
909
+ }
910
+ return null;
911
+ };
912
+ function createContext() {
913
+ if (longStackTraces) return new Context();
914
+ }
915
+ function peekContext() {
916
+ var lastIndex = contextStack.length - 1;
917
+ if (lastIndex >= 0) return contextStack[lastIndex];
918
+ }
919
+ Context.CapturedTrace = null;
920
+ Context.create = createContext;
921
+ Context.deactivateLongStackTraces = function() {};
922
+ Context.activateLongStackTraces = function() {
923
+ var Promise_pushContext = Promise.prototype._pushContext;
924
+ var Promise_popContext = Promise.prototype._popContext;
925
+ var Promise_PeekContext = Promise._peekContext;
926
+ var Promise_peekContext = Promise.prototype._peekContext;
927
+ var Promise_promiseCreated = Promise.prototype._promiseCreated;
928
+ Context.deactivateLongStackTraces = function() {
929
+ Promise.prototype._pushContext = Promise_pushContext;
930
+ Promise.prototype._popContext = Promise_popContext;
931
+ Promise._peekContext = Promise_PeekContext;
932
+ Promise.prototype._peekContext = Promise_peekContext;
933
+ Promise.prototype._promiseCreated = Promise_promiseCreated;
934
+ longStackTraces = false;
935
+ };
936
+ longStackTraces = true;
937
+ Promise.prototype._pushContext = Context.prototype._pushContext;
938
+ Promise.prototype._popContext = Context.prototype._popContext;
939
+ Promise._peekContext = Promise.prototype._peekContext = peekContext;
940
+ Promise.prototype._promiseCreated = function() {
941
+ var ctx = this._peekContext();
942
+ if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
943
+ };
944
+ };
945
+ return Context;
946
+ };
947
+ }));
948
+ var require_debuggability = /* @__PURE__ */ __commonJSMin(((exports, module) => {
949
+ module.exports = function(Promise, Context, enableAsyncHooks, disableAsyncHooks) {
950
+ var async = Promise._async;
951
+ var Warning = require_errors().Warning;
952
+ var util = require_util();
953
+ var es5 = require_es5();
954
+ var canAttachTrace = util.canAttachTrace;
955
+ var unhandledRejectionHandled;
956
+ var possiblyUnhandledRejection;
957
+ var bluebirdFramePattern = /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
958
+ var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/;
959
+ var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/;
960
+ var stackFramePattern = null;
961
+ var formatStack = null;
962
+ var indentStackFrames = false;
963
+ var printWarning;
964
+ var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 && (util.env("BLUEBIRD_DEBUG") || util.env("NODE_ENV") === "development"));
965
+ var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 && (debugging || util.env("BLUEBIRD_WARNINGS")));
966
+ var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 && (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
967
+ var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 && (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
968
+ var deferUnhandledRejectionCheck;
969
+ (function() {
970
+ var promises = [];
971
+ function unhandledRejectionCheck() {
972
+ for (var i = 0; i < promises.length; ++i) promises[i]._notifyUnhandledRejection();
973
+ unhandledRejectionClear();
974
+ }
975
+ function unhandledRejectionClear() {
976
+ promises.length = 0;
977
+ }
978
+ deferUnhandledRejectionCheck = function(promise) {
979
+ promises.push(promise);
980
+ setTimeout(unhandledRejectionCheck, 1);
981
+ };
982
+ es5.defineProperty(Promise, "_unhandledRejectionCheck", { value: unhandledRejectionCheck });
983
+ es5.defineProperty(Promise, "_unhandledRejectionClear", { value: unhandledRejectionClear });
984
+ })();
985
+ Promise.prototype.suppressUnhandledRejections = function() {
986
+ var target = this._target();
987
+ target._bitField = target._bitField & -1048577 | 524288;
988
+ };
989
+ Promise.prototype._ensurePossibleRejectionHandled = function() {
990
+ if ((this._bitField & 524288) !== 0) return;
991
+ this._setRejectionIsUnhandled();
992
+ deferUnhandledRejectionCheck(this);
993
+ };
994
+ Promise.prototype._notifyUnhandledRejectionIsHandled = function() {
995
+ fireRejectionEvent("rejectionHandled", unhandledRejectionHandled, void 0, this);
996
+ };
997
+ Promise.prototype._setReturnedNonUndefined = function() {
998
+ this._bitField = this._bitField | 268435456;
999
+ };
1000
+ Promise.prototype._returnedNonUndefined = function() {
1001
+ return (this._bitField & 268435456) !== 0;
1002
+ };
1003
+ Promise.prototype._notifyUnhandledRejection = function() {
1004
+ if (this._isRejectionUnhandled()) {
1005
+ var reason = this._settledValue();
1006
+ this._setUnhandledRejectionIsNotified();
1007
+ fireRejectionEvent("unhandledRejection", possiblyUnhandledRejection, reason, this);
1008
+ }
1009
+ };
1010
+ Promise.prototype._setUnhandledRejectionIsNotified = function() {
1011
+ this._bitField = this._bitField | 262144;
1012
+ };
1013
+ Promise.prototype._unsetUnhandledRejectionIsNotified = function() {
1014
+ this._bitField = this._bitField & -262145;
1015
+ };
1016
+ Promise.prototype._isUnhandledRejectionNotified = function() {
1017
+ return (this._bitField & 262144) > 0;
1018
+ };
1019
+ Promise.prototype._setRejectionIsUnhandled = function() {
1020
+ this._bitField = this._bitField | 1048576;
1021
+ };
1022
+ Promise.prototype._unsetRejectionIsUnhandled = function() {
1023
+ this._bitField = this._bitField & -1048577;
1024
+ if (this._isUnhandledRejectionNotified()) {
1025
+ this._unsetUnhandledRejectionIsNotified();
1026
+ this._notifyUnhandledRejectionIsHandled();
1027
+ }
1028
+ };
1029
+ Promise.prototype._isRejectionUnhandled = function() {
1030
+ return (this._bitField & 1048576) > 0;
1031
+ };
1032
+ Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
1033
+ return warn(message, shouldUseOwnTrace, promise || this);
1034
+ };
1035
+ Promise.onPossiblyUnhandledRejection = function(fn) {
1036
+ var context = Promise._getContext();
1037
+ possiblyUnhandledRejection = util.contextBind(context, fn);
1038
+ };
1039
+ Promise.onUnhandledRejectionHandled = function(fn) {
1040
+ var context = Promise._getContext();
1041
+ unhandledRejectionHandled = util.contextBind(context, fn);
1042
+ };
1043
+ var disableLongStackTraces = function() {};
1044
+ Promise.longStackTraces = function() {
1045
+ if (async.haveItemsQueued() && !config.longStackTraces) throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");
1046
+ if (!config.longStackTraces && longStackTracesIsSupported()) {
1047
+ var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
1048
+ var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
1049
+ var Promise_dereferenceTrace = Promise.prototype._dereferenceTrace;
1050
+ config.longStackTraces = true;
1051
+ disableLongStackTraces = function() {
1052
+ if (async.haveItemsQueued() && !config.longStackTraces) throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");
1053
+ Promise.prototype._captureStackTrace = Promise_captureStackTrace;
1054
+ Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
1055
+ Promise.prototype._dereferenceTrace = Promise_dereferenceTrace;
1056
+ Context.deactivateLongStackTraces();
1057
+ config.longStackTraces = false;
1058
+ };
1059
+ Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
1060
+ Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
1061
+ Promise.prototype._dereferenceTrace = longStackTracesDereferenceTrace;
1062
+ Context.activateLongStackTraces();
1063
+ }
1064
+ };
1065
+ Promise.hasLongStackTraces = function() {
1066
+ return config.longStackTraces && longStackTracesIsSupported();
1067
+ };
1068
+ var legacyHandlers = {
1069
+ unhandledrejection: {
1070
+ before: function() {
1071
+ var ret = util.global.onunhandledrejection;
1072
+ util.global.onunhandledrejection = null;
1073
+ return ret;
1074
+ },
1075
+ after: function(fn) {
1076
+ util.global.onunhandledrejection = fn;
1077
+ }
1078
+ },
1079
+ rejectionhandled: {
1080
+ before: function() {
1081
+ var ret = util.global.onrejectionhandled;
1082
+ util.global.onrejectionhandled = null;
1083
+ return ret;
1084
+ },
1085
+ after: function(fn) {
1086
+ util.global.onrejectionhandled = fn;
1087
+ }
1088
+ }
1089
+ };
1090
+ var fireDomEvent = (function() {
1091
+ var dispatch = function(legacy, e) {
1092
+ if (legacy) {
1093
+ var fn;
1094
+ try {
1095
+ fn = legacy.before();
1096
+ return !util.global.dispatchEvent(e);
1097
+ } finally {
1098
+ legacy.after(fn);
1099
+ }
1100
+ } else return !util.global.dispatchEvent(e);
1101
+ };
1102
+ try {
1103
+ if (typeof CustomEvent === "function") {
1104
+ var event = new CustomEvent("CustomEvent");
1105
+ util.global.dispatchEvent(event);
1106
+ return function(name, event) {
1107
+ name = name.toLowerCase();
1108
+ var eventData = {
1109
+ detail: event,
1110
+ cancelable: true
1111
+ };
1112
+ var domEvent = new CustomEvent(name, eventData);
1113
+ es5.defineProperty(domEvent, "promise", { value: event.promise });
1114
+ es5.defineProperty(domEvent, "reason", { value: event.reason });
1115
+ return dispatch(legacyHandlers[name], domEvent);
1116
+ };
1117
+ } else if (typeof Event === "function") {
1118
+ var event = new Event("CustomEvent");
1119
+ util.global.dispatchEvent(event);
1120
+ return function(name, event) {
1121
+ name = name.toLowerCase();
1122
+ var domEvent = new Event(name, { cancelable: true });
1123
+ domEvent.detail = event;
1124
+ es5.defineProperty(domEvent, "promise", { value: event.promise });
1125
+ es5.defineProperty(domEvent, "reason", { value: event.reason });
1126
+ return dispatch(legacyHandlers[name], domEvent);
1127
+ };
1128
+ } else {
1129
+ var event = document.createEvent("CustomEvent");
1130
+ event.initCustomEvent("testingtheevent", false, true, {});
1131
+ util.global.dispatchEvent(event);
1132
+ return function(name, event) {
1133
+ name = name.toLowerCase();
1134
+ var domEvent = document.createEvent("CustomEvent");
1135
+ domEvent.initCustomEvent(name, false, true, event);
1136
+ return dispatch(legacyHandlers[name], domEvent);
1137
+ };
1138
+ }
1139
+ } catch (e) {}
1140
+ return function() {
1141
+ return false;
1142
+ };
1143
+ })();
1144
+ var fireGlobalEvent = (function() {
1145
+ if (util.isNode) return function() {
1146
+ return process.emit.apply(process, arguments);
1147
+ };
1148
+ else {
1149
+ if (!util.global) return function() {
1150
+ return false;
1151
+ };
1152
+ return function(name) {
1153
+ var methodName = "on" + name.toLowerCase();
1154
+ var method = util.global[methodName];
1155
+ if (!method) return false;
1156
+ method.apply(util.global, [].slice.call(arguments, 1));
1157
+ return true;
1158
+ };
1159
+ }
1160
+ })();
1161
+ function generatePromiseLifecycleEventObject(name, promise) {
1162
+ return { promise };
1163
+ }
1164
+ var eventToObjectGenerator = {
1165
+ promiseCreated: generatePromiseLifecycleEventObject,
1166
+ promiseFulfilled: generatePromiseLifecycleEventObject,
1167
+ promiseRejected: generatePromiseLifecycleEventObject,
1168
+ promiseResolved: generatePromiseLifecycleEventObject,
1169
+ promiseCancelled: generatePromiseLifecycleEventObject,
1170
+ promiseChained: function(name, promise, child) {
1171
+ return {
1172
+ promise,
1173
+ child
1174
+ };
1175
+ },
1176
+ warning: function(name, warning) {
1177
+ return { warning };
1178
+ },
1179
+ unhandledRejection: function(name, reason, promise) {
1180
+ return {
1181
+ reason,
1182
+ promise
1183
+ };
1184
+ },
1185
+ rejectionHandled: generatePromiseLifecycleEventObject
1186
+ };
1187
+ var activeFireEvent = function(name) {
1188
+ var globalEventFired = false;
1189
+ try {
1190
+ globalEventFired = fireGlobalEvent.apply(null, arguments);
1191
+ } catch (e) {
1192
+ async.throwLater(e);
1193
+ globalEventFired = true;
1194
+ }
1195
+ var domEventFired = false;
1196
+ try {
1197
+ domEventFired = fireDomEvent(name, eventToObjectGenerator[name].apply(null, arguments));
1198
+ } catch (e) {
1199
+ async.throwLater(e);
1200
+ domEventFired = true;
1201
+ }
1202
+ return domEventFired || globalEventFired;
1203
+ };
1204
+ Promise.config = function(opts) {
1205
+ opts = Object(opts);
1206
+ if ("longStackTraces" in opts) {
1207
+ if (opts.longStackTraces) Promise.longStackTraces();
1208
+ else if (!opts.longStackTraces && Promise.hasLongStackTraces()) disableLongStackTraces();
1209
+ }
1210
+ if ("warnings" in opts) {
1211
+ var warningsOption = opts.warnings;
1212
+ config.warnings = !!warningsOption;
1213
+ wForgottenReturn = config.warnings;
1214
+ if (util.isObject(warningsOption)) {
1215
+ if ("wForgottenReturn" in warningsOption) wForgottenReturn = !!warningsOption.wForgottenReturn;
1216
+ }
1217
+ }
1218
+ if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
1219
+ if (async.haveItemsQueued()) throw new Error("cannot enable cancellation after promises are in use");
1220
+ Promise.prototype._clearCancellationData = cancellationClearCancellationData;
1221
+ Promise.prototype._propagateFrom = cancellationPropagateFrom;
1222
+ Promise.prototype._onCancel = cancellationOnCancel;
1223
+ Promise.prototype._setOnCancel = cancellationSetOnCancel;
1224
+ Promise.prototype._attachCancellationCallback = cancellationAttachCancellationCallback;
1225
+ Promise.prototype._execute = cancellationExecute;
1226
+ propagateFromFunction = cancellationPropagateFrom;
1227
+ config.cancellation = true;
1228
+ }
1229
+ if ("monitoring" in opts) {
1230
+ if (opts.monitoring && !config.monitoring) {
1231
+ config.monitoring = true;
1232
+ Promise.prototype._fireEvent = activeFireEvent;
1233
+ } else if (!opts.monitoring && config.monitoring) {
1234
+ config.monitoring = false;
1235
+ Promise.prototype._fireEvent = defaultFireEvent;
1236
+ }
1237
+ }
1238
+ if ("asyncHooks" in opts && util.nodeSupportsAsyncResource) {
1239
+ var prev = config.asyncHooks;
1240
+ var cur = !!opts.asyncHooks;
1241
+ if (prev !== cur) {
1242
+ config.asyncHooks = cur;
1243
+ if (cur) enableAsyncHooks();
1244
+ else disableAsyncHooks();
1245
+ }
1246
+ }
1247
+ return Promise;
1248
+ };
1249
+ function defaultFireEvent() {
1250
+ return false;
1251
+ }
1252
+ Promise.prototype._fireEvent = defaultFireEvent;
1253
+ Promise.prototype._execute = function(executor, resolve, reject) {
1254
+ try {
1255
+ executor(resolve, reject);
1256
+ } catch (e) {
1257
+ return e;
1258
+ }
1259
+ };
1260
+ Promise.prototype._onCancel = function() {};
1261
+ Promise.prototype._setOnCancel = function(handler) {};
1262
+ Promise.prototype._attachCancellationCallback = function(onCancel) {};
1263
+ Promise.prototype._captureStackTrace = function() {};
1264
+ Promise.prototype._attachExtraTrace = function() {};
1265
+ Promise.prototype._dereferenceTrace = function() {};
1266
+ Promise.prototype._clearCancellationData = function() {};
1267
+ Promise.prototype._propagateFrom = function(parent, flags) {};
1268
+ function cancellationExecute(executor, resolve, reject) {
1269
+ var promise = this;
1270
+ try {
1271
+ executor(resolve, reject, function(onCancel) {
1272
+ if (typeof onCancel !== "function") throw new TypeError("onCancel must be a function, got: " + util.toString(onCancel));
1273
+ promise._attachCancellationCallback(onCancel);
1274
+ });
1275
+ } catch (e) {
1276
+ return e;
1277
+ }
1278
+ }
1279
+ function cancellationAttachCancellationCallback(onCancel) {
1280
+ if (!this._isCancellable()) return this;
1281
+ var previousOnCancel = this._onCancel();
1282
+ if (previousOnCancel !== void 0) if (util.isArray(previousOnCancel)) previousOnCancel.push(onCancel);
1283
+ else this._setOnCancel([previousOnCancel, onCancel]);
1284
+ else this._setOnCancel(onCancel);
1285
+ }
1286
+ function cancellationOnCancel() {
1287
+ return this._onCancelField;
1288
+ }
1289
+ function cancellationSetOnCancel(onCancel) {
1290
+ this._onCancelField = onCancel;
1291
+ }
1292
+ function cancellationClearCancellationData() {
1293
+ this._cancellationParent = void 0;
1294
+ this._onCancelField = void 0;
1295
+ }
1296
+ function cancellationPropagateFrom(parent, flags) {
1297
+ if ((flags & 1) !== 0) {
1298
+ this._cancellationParent = parent;
1299
+ var branchesRemainingToCancel = parent._branchesRemainingToCancel;
1300
+ if (branchesRemainingToCancel === void 0) branchesRemainingToCancel = 0;
1301
+ parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
1302
+ }
1303
+ if ((flags & 2) !== 0 && parent._isBound()) this._setBoundTo(parent._boundTo);
1304
+ }
1305
+ function bindingPropagateFrom(parent, flags) {
1306
+ if ((flags & 2) !== 0 && parent._isBound()) this._setBoundTo(parent._boundTo);
1307
+ }
1308
+ var propagateFromFunction = bindingPropagateFrom;
1309
+ function boundValueFunction() {
1310
+ var ret = this._boundTo;
1311
+ if (ret !== void 0) {
1312
+ if (ret instanceof Promise) if (ret.isFulfilled()) return ret.value();
1313
+ else return;
1314
+ }
1315
+ return ret;
1316
+ }
1317
+ function longStackTracesCaptureStackTrace() {
1318
+ this._trace = new CapturedTrace(this._peekContext());
1319
+ }
1320
+ function longStackTracesAttachExtraTrace(error, ignoreSelf) {
1321
+ if (canAttachTrace(error)) {
1322
+ var trace = this._trace;
1323
+ if (trace !== void 0) {
1324
+ if (ignoreSelf) trace = trace._parent;
1325
+ }
1326
+ if (trace !== void 0) trace.attachExtraTrace(error);
1327
+ else if (!error.__stackCleaned__) {
1328
+ var parsed = parseStackAndMessage(error);
1329
+ util.notEnumerableProp(error, "stack", parsed.message + "\n" + parsed.stack.join("\n"));
1330
+ util.notEnumerableProp(error, "__stackCleaned__", true);
1331
+ }
1332
+ }
1333
+ }
1334
+ function longStackTracesDereferenceTrace() {
1335
+ this._trace = void 0;
1336
+ }
1337
+ function checkForgottenReturns(returnValue, promiseCreated, name, promise, parent) {
1338
+ if (returnValue === void 0 && promiseCreated !== null && wForgottenReturn) {
1339
+ if (parent !== void 0 && parent._returnedNonUndefined()) return;
1340
+ if ((promise._bitField & 65535) === 0) return;
1341
+ if (name) name = name + " ";
1342
+ var handlerLine = "";
1343
+ var creatorLine = "";
1344
+ if (promiseCreated._trace) {
1345
+ var traceLines = promiseCreated._trace.stack.split("\n");
1346
+ var stack = cleanStack(traceLines);
1347
+ for (var i = stack.length - 1; i >= 0; --i) {
1348
+ var line = stack[i];
1349
+ if (!nodeFramePattern.test(line)) {
1350
+ var lineMatches = line.match(parseLinePattern);
1351
+ if (lineMatches) handlerLine = "at " + lineMatches[1] + ":" + lineMatches[2] + ":" + lineMatches[3] + " ";
1352
+ break;
1353
+ }
1354
+ }
1355
+ if (stack.length > 0) {
1356
+ var firstUserLine = stack[0];
1357
+ for (var i = 0; i < traceLines.length; ++i) if (traceLines[i] === firstUserLine) {
1358
+ if (i > 0) creatorLine = "\n" + traceLines[i - 1];
1359
+ break;
1360
+ }
1361
+ }
1362
+ }
1363
+ var msg = "a promise was created in a " + name + "handler " + handlerLine + "but was not returned from it, see http://goo.gl/rRqMUw" + creatorLine;
1364
+ promise._warn(msg, true, promiseCreated);
1365
+ }
1366
+ }
1367
+ function deprecated(name, replacement) {
1368
+ var message = name + " is deprecated and will be removed in a future version.";
1369
+ if (replacement) message += " Use " + replacement + " instead.";
1370
+ return warn(message);
1371
+ }
1372
+ function warn(message, shouldUseOwnTrace, promise) {
1373
+ if (!config.warnings) return;
1374
+ var warning = new Warning(message);
1375
+ var ctx;
1376
+ if (shouldUseOwnTrace) promise._attachExtraTrace(warning);
1377
+ else if (config.longStackTraces && (ctx = Promise._peekContext())) ctx.attachExtraTrace(warning);
1378
+ else {
1379
+ var parsed = parseStackAndMessage(warning);
1380
+ warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
1381
+ }
1382
+ if (!activeFireEvent("warning", warning)) formatAndLogError(warning, "", true);
1383
+ }
1384
+ function reconstructStack(message, stacks) {
1385
+ for (var i = 0; i < stacks.length - 1; ++i) {
1386
+ stacks[i].push("From previous event:");
1387
+ stacks[i] = stacks[i].join("\n");
1388
+ }
1389
+ if (i < stacks.length) stacks[i] = stacks[i].join("\n");
1390
+ return message + "\n" + stacks.join("\n");
1391
+ }
1392
+ function removeDuplicateOrEmptyJumps(stacks) {
1393
+ for (var i = 0; i < stacks.length; ++i) if (stacks[i].length === 0 || i + 1 < stacks.length && stacks[i][0] === stacks[i + 1][0]) {
1394
+ stacks.splice(i, 1);
1395
+ i--;
1396
+ }
1397
+ }
1398
+ function removeCommonRoots(stacks) {
1399
+ var current = stacks[0];
1400
+ for (var i = 1; i < stacks.length; ++i) {
1401
+ var prev = stacks[i];
1402
+ var currentLastIndex = current.length - 1;
1403
+ var currentLastLine = current[currentLastIndex];
1404
+ var commonRootMeetPoint = -1;
1405
+ for (var j = prev.length - 1; j >= 0; --j) if (prev[j] === currentLastLine) {
1406
+ commonRootMeetPoint = j;
1407
+ break;
1408
+ }
1409
+ for (var j = commonRootMeetPoint; j >= 0; --j) {
1410
+ var line = prev[j];
1411
+ if (current[currentLastIndex] === line) {
1412
+ current.pop();
1413
+ currentLastIndex--;
1414
+ } else break;
1415
+ }
1416
+ current = prev;
1417
+ }
1418
+ }
1419
+ function cleanStack(stack) {
1420
+ var ret = [];
1421
+ for (var i = 0; i < stack.length; ++i) {
1422
+ var line = stack[i];
1423
+ var isTraceLine = " (No stack trace)" === line || stackFramePattern.test(line);
1424
+ var isInternalFrame = isTraceLine && shouldIgnore(line);
1425
+ if (isTraceLine && !isInternalFrame) {
1426
+ if (indentStackFrames && line.charAt(0) !== " ") line = " " + line;
1427
+ ret.push(line);
1428
+ }
1429
+ }
1430
+ return ret;
1431
+ }
1432
+ function stackFramesAsArray(error) {
1433
+ var stack = error.stack.replace(/\s+$/g, "").split("\n");
1434
+ for (var i = 0; i < stack.length; ++i) {
1435
+ var line = stack[i];
1436
+ if (" (No stack trace)" === line || stackFramePattern.test(line)) break;
1437
+ }
1438
+ if (i > 0 && error.name != "SyntaxError") stack = stack.slice(i);
1439
+ return stack;
1440
+ }
1441
+ function parseStackAndMessage(error) {
1442
+ var stack = error.stack;
1443
+ var message = error.toString();
1444
+ stack = typeof stack === "string" && stack.length > 0 ? stackFramesAsArray(error) : [" (No stack trace)"];
1445
+ return {
1446
+ message,
1447
+ stack: error.name == "SyntaxError" ? stack : cleanStack(stack)
1448
+ };
1449
+ }
1450
+ function formatAndLogError(error, title, isSoft) {
1451
+ if (typeof console !== "undefined") {
1452
+ var message;
1453
+ if (util.isObject(error)) {
1454
+ var stack = error.stack;
1455
+ message = title + formatStack(stack, error);
1456
+ } else message = title + String(error);
1457
+ if (typeof printWarning === "function") printWarning(message, isSoft);
1458
+ else if (typeof console.log === "function" || typeof console.log === "object") console.log(message);
1459
+ }
1460
+ }
1461
+ function fireRejectionEvent(name, localHandler, reason, promise) {
1462
+ var localEventFired = false;
1463
+ try {
1464
+ if (typeof localHandler === "function") {
1465
+ localEventFired = true;
1466
+ if (name === "rejectionHandled") localHandler(promise);
1467
+ else localHandler(reason, promise);
1468
+ }
1469
+ } catch (e) {
1470
+ async.throwLater(e);
1471
+ }
1472
+ if (name === "unhandledRejection") {
1473
+ if (!activeFireEvent(name, reason, promise) && !localEventFired) formatAndLogError(reason, "Unhandled rejection ");
1474
+ } else activeFireEvent(name, promise);
1475
+ }
1476
+ function formatNonError(obj) {
1477
+ var str;
1478
+ if (typeof obj === "function") str = "[function " + (obj.name || "anonymous") + "]";
1479
+ else {
1480
+ str = obj && typeof obj.toString === "function" ? obj.toString() : util.toString(obj);
1481
+ if (/\[object [a-zA-Z0-9$_]+\]/.test(str)) try {
1482
+ str = JSON.stringify(obj);
1483
+ } catch (e) {}
1484
+ if (str.length === 0) str = "(empty array)";
1485
+ }
1486
+ return "(<" + snip(str) + ">, no stack trace)";
1487
+ }
1488
+ function snip(str) {
1489
+ var maxChars = 41;
1490
+ if (str.length < maxChars) return str;
1491
+ return str.substr(0, maxChars - 3) + "...";
1492
+ }
1493
+ function longStackTracesIsSupported() {
1494
+ return typeof captureStackTrace === "function";
1495
+ }
1496
+ var shouldIgnore = function() {
1497
+ return false;
1498
+ };
1499
+ var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
1500
+ function parseLineInfo(line) {
1501
+ var matches = line.match(parseLineInfoRegex);
1502
+ if (matches) return {
1503
+ fileName: matches[1],
1504
+ line: parseInt(matches[2], 10)
1505
+ };
1506
+ }
1507
+ function setBounds(firstLineError, lastLineError) {
1508
+ if (!longStackTracesIsSupported()) return;
1509
+ var firstStackLines = (firstLineError.stack || "").split("\n");
1510
+ var lastStackLines = (lastLineError.stack || "").split("\n");
1511
+ var firstIndex = -1;
1512
+ var lastIndex = -1;
1513
+ var firstFileName;
1514
+ var lastFileName;
1515
+ for (var i = 0; i < firstStackLines.length; ++i) {
1516
+ var result = parseLineInfo(firstStackLines[i]);
1517
+ if (result) {
1518
+ firstFileName = result.fileName;
1519
+ firstIndex = result.line;
1520
+ break;
1521
+ }
1522
+ }
1523
+ for (var i = 0; i < lastStackLines.length; ++i) {
1524
+ var result = parseLineInfo(lastStackLines[i]);
1525
+ if (result) {
1526
+ lastFileName = result.fileName;
1527
+ lastIndex = result.line;
1528
+ break;
1529
+ }
1530
+ }
1531
+ if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName || firstFileName !== lastFileName || firstIndex >= lastIndex) return;
1532
+ shouldIgnore = function(line) {
1533
+ if (bluebirdFramePattern.test(line)) return true;
1534
+ var info = parseLineInfo(line);
1535
+ if (info) {
1536
+ if (info.fileName === firstFileName && firstIndex <= info.line && info.line <= lastIndex) return true;
1537
+ }
1538
+ return false;
1539
+ };
1540
+ }
1541
+ function CapturedTrace(parent) {
1542
+ this._parent = parent;
1543
+ this._promisesCreated = 0;
1544
+ var length = this._length = 1 + (parent === void 0 ? 0 : parent._length);
1545
+ captureStackTrace(this, CapturedTrace);
1546
+ if (length > 32) this.uncycle();
1547
+ }
1548
+ util.inherits(CapturedTrace, Error);
1549
+ Context.CapturedTrace = CapturedTrace;
1550
+ CapturedTrace.prototype.uncycle = function() {
1551
+ var length = this._length;
1552
+ if (length < 2) return;
1553
+ var nodes = [];
1554
+ var stackToIndex = {};
1555
+ for (var i = 0, node = this; node !== void 0; ++i) {
1556
+ nodes.push(node);
1557
+ node = node._parent;
1558
+ }
1559
+ length = this._length = i;
1560
+ for (var i = length - 1; i >= 0; --i) {
1561
+ var stack = nodes[i].stack;
1562
+ if (stackToIndex[stack] === void 0) stackToIndex[stack] = i;
1563
+ }
1564
+ for (var i = 0; i < length; ++i) {
1565
+ var index = stackToIndex[nodes[i].stack];
1566
+ if (index !== void 0 && index !== i) {
1567
+ if (index > 0) {
1568
+ nodes[index - 1]._parent = void 0;
1569
+ nodes[index - 1]._length = 1;
1570
+ }
1571
+ nodes[i]._parent = void 0;
1572
+ nodes[i]._length = 1;
1573
+ var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
1574
+ if (index < length - 1) {
1575
+ cycleEdgeNode._parent = nodes[index + 1];
1576
+ cycleEdgeNode._parent.uncycle();
1577
+ cycleEdgeNode._length = cycleEdgeNode._parent._length + 1;
1578
+ } else {
1579
+ cycleEdgeNode._parent = void 0;
1580
+ cycleEdgeNode._length = 1;
1581
+ }
1582
+ var currentChildLength = cycleEdgeNode._length + 1;
1583
+ for (var j = i - 2; j >= 0; --j) {
1584
+ nodes[j]._length = currentChildLength;
1585
+ currentChildLength++;
1586
+ }
1587
+ return;
1588
+ }
1589
+ }
1590
+ };
1591
+ CapturedTrace.prototype.attachExtraTrace = function(error) {
1592
+ if (error.__stackCleaned__) return;
1593
+ this.uncycle();
1594
+ var parsed = parseStackAndMessage(error);
1595
+ var message = parsed.message;
1596
+ var stacks = [parsed.stack];
1597
+ var trace = this;
1598
+ while (trace !== void 0) {
1599
+ stacks.push(cleanStack(trace.stack.split("\n")));
1600
+ trace = trace._parent;
1601
+ }
1602
+ removeCommonRoots(stacks);
1603
+ removeDuplicateOrEmptyJumps(stacks);
1604
+ util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
1605
+ util.notEnumerableProp(error, "__stackCleaned__", true);
1606
+ };
1607
+ var captureStackTrace = (function stackDetection() {
1608
+ var v8stackFramePattern = /^\s*at\s*/;
1609
+ var v8stackFormatter = function(stack, error) {
1610
+ if (typeof stack === "string") return stack;
1611
+ if (error.name !== void 0 && error.message !== void 0) return error.toString();
1612
+ return formatNonError(error);
1613
+ };
1614
+ if (typeof Error.stackTraceLimit === "number" && typeof Error.captureStackTrace === "function") {
1615
+ Error.stackTraceLimit += 6;
1616
+ stackFramePattern = v8stackFramePattern;
1617
+ formatStack = v8stackFormatter;
1618
+ var captureStackTrace = Error.captureStackTrace;
1619
+ shouldIgnore = function(line) {
1620
+ return bluebirdFramePattern.test(line);
1621
+ };
1622
+ return function(receiver, ignoreUntil) {
1623
+ Error.stackTraceLimit += 6;
1624
+ captureStackTrace(receiver, ignoreUntil);
1625
+ Error.stackTraceLimit -= 6;
1626
+ };
1627
+ }
1628
+ var err = /* @__PURE__ */ new Error();
1629
+ if (typeof err.stack === "string" && err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
1630
+ stackFramePattern = /@/;
1631
+ formatStack = v8stackFormatter;
1632
+ indentStackFrames = true;
1633
+ return function captureStackTrace(o) {
1634
+ o.stack = (/* @__PURE__ */ new Error()).stack;
1635
+ };
1636
+ }
1637
+ var hasStackAfterThrow;
1638
+ try {
1639
+ throw new Error();
1640
+ } catch (e) {
1641
+ hasStackAfterThrow = "stack" in e;
1642
+ }
1643
+ if (!("stack" in err) && hasStackAfterThrow && typeof Error.stackTraceLimit === "number") {
1644
+ stackFramePattern = v8stackFramePattern;
1645
+ formatStack = v8stackFormatter;
1646
+ return function captureStackTrace(o) {
1647
+ Error.stackTraceLimit += 6;
1648
+ try {
1649
+ throw new Error();
1650
+ } catch (e) {
1651
+ o.stack = e.stack;
1652
+ }
1653
+ Error.stackTraceLimit -= 6;
1654
+ };
1655
+ }
1656
+ formatStack = function(stack, error) {
1657
+ if (typeof stack === "string") return stack;
1658
+ if ((typeof error === "object" || typeof error === "function") && error.name !== void 0 && error.message !== void 0) return error.toString();
1659
+ return formatNonError(error);
1660
+ };
1661
+ return null;
1662
+ })([]);
1663
+ if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
1664
+ printWarning = function(message) {
1665
+ console.warn(message);
1666
+ };
1667
+ if (util.isNode && process.stderr.isTTY) printWarning = function(message, isSoft) {
1668
+ var color = isSoft ? "\x1B[33m" : "\x1B[31m";
1669
+ console.warn(color + message + "\x1B[0m\n");
1670
+ };
1671
+ else if (!util.isNode && typeof (/* @__PURE__ */ new Error()).stack === "string") printWarning = function(message, isSoft) {
1672
+ console.warn("%c" + message, isSoft ? "color: darkorange" : "color: red");
1673
+ };
1674
+ }
1675
+ var config = {
1676
+ warnings,
1677
+ longStackTraces: false,
1678
+ cancellation: false,
1679
+ monitoring: false,
1680
+ asyncHooks: false
1681
+ };
1682
+ if (longStackTraces) Promise.longStackTraces();
1683
+ return {
1684
+ asyncHooks: function() {
1685
+ return config.asyncHooks;
1686
+ },
1687
+ longStackTraces: function() {
1688
+ return config.longStackTraces;
1689
+ },
1690
+ warnings: function() {
1691
+ return config.warnings;
1692
+ },
1693
+ cancellation: function() {
1694
+ return config.cancellation;
1695
+ },
1696
+ monitoring: function() {
1697
+ return config.monitoring;
1698
+ },
1699
+ propagateFromFunction: function() {
1700
+ return propagateFromFunction;
1701
+ },
1702
+ boundValueFunction: function() {
1703
+ return boundValueFunction;
1704
+ },
1705
+ checkForgottenReturns,
1706
+ setBounds,
1707
+ warn,
1708
+ deprecated,
1709
+ CapturedTrace,
1710
+ fireDomEvent,
1711
+ fireGlobalEvent
1712
+ };
1713
+ };
1714
+ }));
1715
+ var require_catch_filter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1716
+ module.exports = function(NEXT_FILTER) {
1717
+ var util = require_util();
1718
+ var getKeys = require_es5().keys;
1719
+ var tryCatch = util.tryCatch;
1720
+ var errorObj = util.errorObj;
1721
+ function catchFilter(instances, cb, promise) {
1722
+ return function(e) {
1723
+ var boundTo = promise._boundValue();
1724
+ predicateLoop: for (var i = 0; i < instances.length; ++i) {
1725
+ var item = instances[i];
1726
+ if (item === Error || item != null && item.prototype instanceof Error) {
1727
+ if (e instanceof item) return tryCatch(cb).call(boundTo, e);
1728
+ } else if (typeof item === "function") {
1729
+ var matchesPredicate = tryCatch(item).call(boundTo, e);
1730
+ if (matchesPredicate === errorObj) return matchesPredicate;
1731
+ else if (matchesPredicate) return tryCatch(cb).call(boundTo, e);
1732
+ } else if (util.isObject(e)) {
1733
+ var keys = getKeys(item);
1734
+ for (var j = 0; j < keys.length; ++j) {
1735
+ var key = keys[j];
1736
+ if (item[key] != e[key]) continue predicateLoop;
1737
+ }
1738
+ return tryCatch(cb).call(boundTo, e);
1739
+ }
1740
+ }
1741
+ return NEXT_FILTER;
1742
+ };
1743
+ }
1744
+ return catchFilter;
1745
+ };
1746
+ }));
1747
+ var require_finally = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1748
+ module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) {
1749
+ var util = require_util();
1750
+ var CancellationError = Promise.CancellationError;
1751
+ var errorObj = util.errorObj;
1752
+ var catchFilter = require_catch_filter()(NEXT_FILTER);
1753
+ function PassThroughHandlerContext(promise, type, handler) {
1754
+ this.promise = promise;
1755
+ this.type = type;
1756
+ this.handler = handler;
1757
+ this.called = false;
1758
+ this.cancelPromise = null;
1759
+ }
1760
+ PassThroughHandlerContext.prototype.isFinallyHandler = function() {
1761
+ return this.type === 0;
1762
+ };
1763
+ function FinallyHandlerCancelReaction(finallyHandler) {
1764
+ this.finallyHandler = finallyHandler;
1765
+ }
1766
+ FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
1767
+ checkCancel(this.finallyHandler);
1768
+ };
1769
+ function checkCancel(ctx, reason) {
1770
+ if (ctx.cancelPromise != null) {
1771
+ if (arguments.length > 1) ctx.cancelPromise._reject(reason);
1772
+ else ctx.cancelPromise._cancel();
1773
+ ctx.cancelPromise = null;
1774
+ return true;
1775
+ }
1776
+ return false;
1777
+ }
1778
+ function succeed() {
1779
+ return finallyHandler.call(this, this.promise._target()._settledValue());
1780
+ }
1781
+ function fail(reason) {
1782
+ if (checkCancel(this, reason)) return;
1783
+ errorObj.e = reason;
1784
+ return errorObj;
1785
+ }
1786
+ function finallyHandler(reasonOrValue) {
1787
+ var promise = this.promise;
1788
+ var handler = this.handler;
1789
+ if (!this.called) {
1790
+ this.called = true;
1791
+ var ret = this.isFinallyHandler() ? handler.call(promise._boundValue()) : handler.call(promise._boundValue(), reasonOrValue);
1792
+ if (ret === NEXT_FILTER) return ret;
1793
+ else if (ret !== void 0) {
1794
+ promise._setReturnedNonUndefined();
1795
+ var maybePromise = tryConvertToPromise(ret, promise);
1796
+ if (maybePromise instanceof Promise) {
1797
+ if (this.cancelPromise != null) {
1798
+ if (maybePromise._isCancelled()) {
1799
+ var reason = new CancellationError("late cancellation observer");
1800
+ promise._attachExtraTrace(reason);
1801
+ errorObj.e = reason;
1802
+ return errorObj;
1803
+ } else if (maybePromise.isPending()) maybePromise._attachCancellationCallback(new FinallyHandlerCancelReaction(this));
1804
+ }
1805
+ return maybePromise._then(succeed, fail, void 0, this, void 0);
1806
+ }
1807
+ }
1808
+ }
1809
+ if (promise.isRejected()) {
1810
+ checkCancel(this);
1811
+ errorObj.e = reasonOrValue;
1812
+ return errorObj;
1813
+ } else {
1814
+ checkCancel(this);
1815
+ return reasonOrValue;
1816
+ }
1817
+ }
1818
+ Promise.prototype._passThrough = function(handler, type, success, fail) {
1819
+ if (typeof handler !== "function") return this.then();
1820
+ return this._then(success, fail, void 0, new PassThroughHandlerContext(this, type, handler), void 0);
1821
+ };
1822
+ Promise.prototype.lastly = Promise.prototype["finally"] = function(handler) {
1823
+ return this._passThrough(handler, 0, finallyHandler, finallyHandler);
1824
+ };
1825
+ Promise.prototype.tap = function(handler) {
1826
+ return this._passThrough(handler, 1, finallyHandler);
1827
+ };
1828
+ Promise.prototype.tapCatch = function(handlerOrPredicate) {
1829
+ var len = arguments.length;
1830
+ if (len === 1) return this._passThrough(handlerOrPredicate, 1, void 0, finallyHandler);
1831
+ else {
1832
+ var catchInstances = new Array(len - 1), j = 0, i;
1833
+ for (i = 0; i < len - 1; ++i) {
1834
+ var item = arguments[i];
1835
+ if (util.isObject(item)) catchInstances[j++] = item;
1836
+ else return Promise.reject(/* @__PURE__ */ new TypeError("tapCatch statement predicate: expecting an object but got " + util.classString(item)));
1837
+ }
1838
+ catchInstances.length = j;
1839
+ var handler = arguments[i];
1840
+ return this._passThrough(catchFilter(catchInstances, handler, this), 1, void 0, finallyHandler);
1841
+ }
1842
+ };
1843
+ return PassThroughHandlerContext;
1844
+ };
1845
+ }));
1846
+ var require_nodeback = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1847
+ var util = require_util();
1848
+ var maybeWrapAsError = util.maybeWrapAsError;
1849
+ var OperationalError = require_errors().OperationalError;
1850
+ var es5 = require_es5();
1851
+ function isUntypedError(obj) {
1852
+ return obj instanceof Error && es5.getPrototypeOf(obj) === Error.prototype;
1853
+ }
1854
+ var rErrorKey = /^(?:name|message|stack|cause)$/;
1855
+ function wrapAsOperationalError(obj) {
1856
+ var ret;
1857
+ if (isUntypedError(obj)) {
1858
+ ret = new OperationalError(obj);
1859
+ ret.name = obj.name;
1860
+ ret.message = obj.message;
1861
+ ret.stack = obj.stack;
1862
+ var keys = es5.keys(obj);
1863
+ for (var i = 0; i < keys.length; ++i) {
1864
+ var key = keys[i];
1865
+ if (!rErrorKey.test(key)) ret[key] = obj[key];
1866
+ }
1867
+ return ret;
1868
+ }
1869
+ util.markAsOriginatingFromRejection(obj);
1870
+ return obj;
1871
+ }
1872
+ function nodebackForPromise(promise, multiArgs) {
1873
+ return function(err, value) {
1874
+ if (promise === null) return;
1875
+ if (err) {
1876
+ var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
1877
+ promise._attachExtraTrace(wrapped);
1878
+ promise._reject(wrapped);
1879
+ } else if (!multiArgs) promise._fulfill(value);
1880
+ else {
1881
+ var $_len = arguments.length;
1882
+ var args = new Array(Math.max($_len - 1, 0));
1883
+ for (var $_i = 1; $_i < $_len; ++$_i) args[$_i - 1] = arguments[$_i];
1884
+ promise._fulfill(args);
1885
+ }
1886
+ promise = null;
1887
+ };
1888
+ }
1889
+ module.exports = nodebackForPromise;
1890
+ }));
1891
+ var require_method = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1892
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
1893
+ var util = require_util();
1894
+ var tryCatch = util.tryCatch;
1895
+ Promise.method = function(fn) {
1896
+ if (typeof fn !== "function") throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
1897
+ return function() {
1898
+ var ret = new Promise(INTERNAL);
1899
+ ret._captureStackTrace();
1900
+ ret._pushContext();
1901
+ var value = tryCatch(fn).apply(this, arguments);
1902
+ var promiseCreated = ret._popContext();
1903
+ debug.checkForgottenReturns(value, promiseCreated, "Promise.method", ret);
1904
+ ret._resolveFromSyncValue(value);
1905
+ return ret;
1906
+ };
1907
+ };
1908
+ Promise.attempt = Promise["try"] = function(fn) {
1909
+ if (typeof fn !== "function") return apiRejection("expecting a function but got " + util.classString(fn));
1910
+ var ret = new Promise(INTERNAL);
1911
+ ret._captureStackTrace();
1912
+ ret._pushContext();
1913
+ var value;
1914
+ if (arguments.length > 1) {
1915
+ debug.deprecated("calling Promise.try with more than 1 argument");
1916
+ var arg = arguments[1];
1917
+ var ctx = arguments[2];
1918
+ value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg) : tryCatch(fn).call(ctx, arg);
1919
+ } else value = tryCatch(fn)();
1920
+ var promiseCreated = ret._popContext();
1921
+ debug.checkForgottenReturns(value, promiseCreated, "Promise.try", ret);
1922
+ ret._resolveFromSyncValue(value);
1923
+ return ret;
1924
+ };
1925
+ Promise.prototype._resolveFromSyncValue = function(value) {
1926
+ if (value === util.errorObj) this._rejectCallback(value.e, false);
1927
+ else this._resolveCallback(value, true);
1928
+ };
1929
+ };
1930
+ }));
1931
+ var require_bind = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1932
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
1933
+ var calledBind = false;
1934
+ var rejectThis = function(_, e) {
1935
+ this._reject(e);
1936
+ };
1937
+ var targetRejected = function(e, context) {
1938
+ context.promiseRejectionQueued = true;
1939
+ context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
1940
+ };
1941
+ var bindingResolved = function(thisArg, context) {
1942
+ if ((this._bitField & 50397184) === 0) this._resolveCallback(context.target);
1943
+ };
1944
+ var bindingRejected = function(e, context) {
1945
+ if (!context.promiseRejectionQueued) this._reject(e);
1946
+ };
1947
+ Promise.prototype.bind = function(thisArg) {
1948
+ if (!calledBind) {
1949
+ calledBind = true;
1950
+ Promise.prototype._propagateFrom = debug.propagateFromFunction();
1951
+ Promise.prototype._boundValue = debug.boundValueFunction();
1952
+ }
1953
+ var maybePromise = tryConvertToPromise(thisArg);
1954
+ var ret = new Promise(INTERNAL);
1955
+ ret._propagateFrom(this, 1);
1956
+ var target = this._target();
1957
+ ret._setBoundTo(maybePromise);
1958
+ if (maybePromise instanceof Promise) {
1959
+ var context = {
1960
+ promiseRejectionQueued: false,
1961
+ promise: ret,
1962
+ target,
1963
+ bindingPromise: maybePromise
1964
+ };
1965
+ target._then(INTERNAL, targetRejected, void 0, ret, context);
1966
+ maybePromise._then(bindingResolved, bindingRejected, void 0, ret, context);
1967
+ ret._setOnCancel(maybePromise);
1968
+ } else ret._resolveCallback(target);
1969
+ return ret;
1970
+ };
1971
+ Promise.prototype._setBoundTo = function(obj) {
1972
+ if (obj !== void 0) {
1973
+ this._bitField = this._bitField | 2097152;
1974
+ this._boundTo = obj;
1975
+ } else this._bitField = this._bitField & -2097153;
1976
+ };
1977
+ Promise.prototype._isBound = function() {
1978
+ return (this._bitField & 2097152) === 2097152;
1979
+ };
1980
+ Promise.bind = function(thisArg, value) {
1981
+ return Promise.resolve(value).bind(thisArg);
1982
+ };
1983
+ };
1984
+ }));
1985
+ var require_cancel = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1986
+ module.exports = function(Promise, PromiseArray, apiRejection, debug) {
1987
+ var util = require_util();
1988
+ var tryCatch = util.tryCatch;
1989
+ var errorObj = util.errorObj;
1990
+ var async = Promise._async;
1991
+ Promise.prototype["break"] = Promise.prototype.cancel = function() {
1992
+ if (!debug.cancellation()) return this._warn("cancellation is disabled");
1993
+ var promise = this;
1994
+ var child = promise;
1995
+ while (promise._isCancellable()) {
1996
+ if (!promise._cancelBy(child)) {
1997
+ if (child._isFollowing()) child._followee().cancel();
1998
+ else child._cancelBranched();
1999
+ break;
2000
+ }
2001
+ var parent = promise._cancellationParent;
2002
+ if (parent == null || !parent._isCancellable()) {
2003
+ if (promise._isFollowing()) promise._followee().cancel();
2004
+ else promise._cancelBranched();
2005
+ break;
2006
+ } else {
2007
+ if (promise._isFollowing()) promise._followee().cancel();
2008
+ promise._setWillBeCancelled();
2009
+ child = promise;
2010
+ promise = parent;
2011
+ }
2012
+ }
2013
+ };
2014
+ Promise.prototype._branchHasCancelled = function() {
2015
+ this._branchesRemainingToCancel--;
2016
+ };
2017
+ Promise.prototype._enoughBranchesHaveCancelled = function() {
2018
+ return this._branchesRemainingToCancel === void 0 || this._branchesRemainingToCancel <= 0;
2019
+ };
2020
+ Promise.prototype._cancelBy = function(canceller) {
2021
+ if (canceller === this) {
2022
+ this._branchesRemainingToCancel = 0;
2023
+ this._invokeOnCancel();
2024
+ return true;
2025
+ } else {
2026
+ this._branchHasCancelled();
2027
+ if (this._enoughBranchesHaveCancelled()) {
2028
+ this._invokeOnCancel();
2029
+ return true;
2030
+ }
2031
+ }
2032
+ return false;
2033
+ };
2034
+ Promise.prototype._cancelBranched = function() {
2035
+ if (this._enoughBranchesHaveCancelled()) this._cancel();
2036
+ };
2037
+ Promise.prototype._cancel = function() {
2038
+ if (!this._isCancellable()) return;
2039
+ this._setCancelled();
2040
+ async.invoke(this._cancelPromises, this, void 0);
2041
+ };
2042
+ Promise.prototype._cancelPromises = function() {
2043
+ if (this._length() > 0) this._settlePromises();
2044
+ };
2045
+ Promise.prototype._unsetOnCancel = function() {
2046
+ this._onCancelField = void 0;
2047
+ };
2048
+ Promise.prototype._isCancellable = function() {
2049
+ return this.isPending() && !this._isCancelled();
2050
+ };
2051
+ Promise.prototype.isCancellable = function() {
2052
+ return this.isPending() && !this.isCancelled();
2053
+ };
2054
+ Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
2055
+ if (util.isArray(onCancelCallback)) for (var i = 0; i < onCancelCallback.length; ++i) this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
2056
+ else if (onCancelCallback !== void 0) if (typeof onCancelCallback === "function") {
2057
+ if (!internalOnly) {
2058
+ var e = tryCatch(onCancelCallback).call(this._boundValue());
2059
+ if (e === errorObj) {
2060
+ this._attachExtraTrace(e.e);
2061
+ async.throwLater(e.e);
2062
+ }
2063
+ }
2064
+ } else onCancelCallback._resultCancelled(this);
2065
+ };
2066
+ Promise.prototype._invokeOnCancel = function() {
2067
+ var onCancelCallback = this._onCancel();
2068
+ this._unsetOnCancel();
2069
+ async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
2070
+ };
2071
+ Promise.prototype._invokeInternalOnCancel = function() {
2072
+ if (this._isCancellable()) {
2073
+ this._doInvokeOnCancel(this._onCancel(), true);
2074
+ this._unsetOnCancel();
2075
+ }
2076
+ };
2077
+ Promise.prototype._resultCancelled = function() {
2078
+ this.cancel();
2079
+ };
2080
+ };
2081
+ }));
2082
+ var require_direct_resolve = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2083
+ module.exports = function(Promise) {
2084
+ function returner() {
2085
+ return this.value;
2086
+ }
2087
+ function thrower() {
2088
+ throw this.reason;
2089
+ }
2090
+ Promise.prototype["return"] = Promise.prototype.thenReturn = function(value) {
2091
+ if (value instanceof Promise) value.suppressUnhandledRejections();
2092
+ return this._then(returner, void 0, void 0, { value }, void 0);
2093
+ };
2094
+ Promise.prototype["throw"] = Promise.prototype.thenThrow = function(reason) {
2095
+ return this._then(thrower, void 0, void 0, { reason }, void 0);
2096
+ };
2097
+ Promise.prototype.catchThrow = function(reason) {
2098
+ if (arguments.length <= 1) return this._then(void 0, thrower, void 0, { reason }, void 0);
2099
+ else {
2100
+ var _reason = arguments[1];
2101
+ var handler = function() {
2102
+ throw _reason;
2103
+ };
2104
+ return this.caught(reason, handler);
2105
+ }
2106
+ };
2107
+ Promise.prototype.catchReturn = function(value) {
2108
+ if (arguments.length <= 1) {
2109
+ if (value instanceof Promise) value.suppressUnhandledRejections();
2110
+ return this._then(void 0, returner, void 0, { value }, void 0);
2111
+ } else {
2112
+ var _value = arguments[1];
2113
+ if (_value instanceof Promise) _value.suppressUnhandledRejections();
2114
+ var handler = function() {
2115
+ return _value;
2116
+ };
2117
+ return this.caught(value, handler);
2118
+ }
2119
+ };
2120
+ };
2121
+ }));
2122
+ var require_synchronous_inspection = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2123
+ module.exports = function(Promise) {
2124
+ function PromiseInspection(promise) {
2125
+ if (promise !== void 0) {
2126
+ promise = promise._target();
2127
+ this._bitField = promise._bitField;
2128
+ this._settledValueField = promise._isFateSealed() ? promise._settledValue() : void 0;
2129
+ } else {
2130
+ this._bitField = 0;
2131
+ this._settledValueField = void 0;
2132
+ }
2133
+ }
2134
+ PromiseInspection.prototype._settledValue = function() {
2135
+ return this._settledValueField;
2136
+ };
2137
+ var value = PromiseInspection.prototype.value = function() {
2138
+ if (!this.isFulfilled()) throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/MqrFmX\n");
2139
+ return this._settledValue();
2140
+ };
2141
+ var reason = PromiseInspection.prototype.error = PromiseInspection.prototype.reason = function() {
2142
+ if (!this.isRejected()) throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/MqrFmX\n");
2143
+ return this._settledValue();
2144
+ };
2145
+ var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
2146
+ return (this._bitField & 33554432) !== 0;
2147
+ };
2148
+ var isRejected = PromiseInspection.prototype.isRejected = function() {
2149
+ return (this._bitField & 16777216) !== 0;
2150
+ };
2151
+ var isPending = PromiseInspection.prototype.isPending = function() {
2152
+ return (this._bitField & 50397184) === 0;
2153
+ };
2154
+ var isResolved = PromiseInspection.prototype.isResolved = function() {
2155
+ return (this._bitField & 50331648) !== 0;
2156
+ };
2157
+ PromiseInspection.prototype.isCancelled = function() {
2158
+ return (this._bitField & 8454144) !== 0;
2159
+ };
2160
+ Promise.prototype.__isCancelled = function() {
2161
+ return (this._bitField & 65536) === 65536;
2162
+ };
2163
+ Promise.prototype._isCancelled = function() {
2164
+ return this._target().__isCancelled();
2165
+ };
2166
+ Promise.prototype.isCancelled = function() {
2167
+ return (this._target()._bitField & 8454144) !== 0;
2168
+ };
2169
+ Promise.prototype.isPending = function() {
2170
+ return isPending.call(this._target());
2171
+ };
2172
+ Promise.prototype.isRejected = function() {
2173
+ return isRejected.call(this._target());
2174
+ };
2175
+ Promise.prototype.isFulfilled = function() {
2176
+ return isFulfilled.call(this._target());
2177
+ };
2178
+ Promise.prototype.isResolved = function() {
2179
+ return isResolved.call(this._target());
2180
+ };
2181
+ Promise.prototype.value = function() {
2182
+ return value.call(this._target());
2183
+ };
2184
+ Promise.prototype.reason = function() {
2185
+ var target = this._target();
2186
+ target._unsetRejectionIsUnhandled();
2187
+ return reason.call(target);
2188
+ };
2189
+ Promise.prototype._value = function() {
2190
+ return this._settledValue();
2191
+ };
2192
+ Promise.prototype._reason = function() {
2193
+ this._unsetRejectionIsUnhandled();
2194
+ return this._settledValue();
2195
+ };
2196
+ Promise.PromiseInspection = PromiseInspection;
2197
+ };
2198
+ }));
2199
+ var require_join = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2200
+ module.exports = function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async) {
2201
+ var util = require_util();
2202
+ var canEvaluate = util.canEvaluate;
2203
+ var tryCatch = util.tryCatch;
2204
+ var errorObj = util.errorObj;
2205
+ var reject;
2206
+ if (canEvaluate) {
2207
+ var thenCallback = function(i) {
2208
+ return new Function("value", "holder", " \n 'use strict'; \n holder.pIndex = value; \n holder.checkFulfillment(this); \n ".replace(/Index/g, i));
2209
+ };
2210
+ var promiseSetter = function(i) {
2211
+ return new Function("promise", "holder", " \n 'use strict'; \n holder.pIndex = promise; \n ".replace(/Index/g, i));
2212
+ };
2213
+ var generateHolderClass = function(total) {
2214
+ var props = new Array(total);
2215
+ for (var i = 0; i < props.length; ++i) props[i] = "this.p" + (i + 1);
2216
+ var assignment = props.join(" = ") + " = null;";
2217
+ var cancellationCode = "var promise;\n" + props.map(function(prop) {
2218
+ return " \n promise = " + prop + "; \n if (promise instanceof Promise) { \n promise.cancel(); \n } \n ";
2219
+ }).join("\n");
2220
+ var passedArguments = props.join(", ");
2221
+ var name = "Holder$" + total;
2222
+ var code = "return function(tryCatch, errorObj, Promise, async) { \n 'use strict'; \n function [TheName](fn) { \n [TheProperties] \n this.fn = fn; \n this.asyncNeeded = true; \n this.now = 0; \n } \n \n [TheName].prototype._callFunction = function(promise) { \n promise._pushContext(); \n var ret = tryCatch(this.fn)([ThePassedArguments]); \n promise._popContext(); \n if (ret === errorObj) { \n promise._rejectCallback(ret.e, false); \n } else { \n promise._resolveCallback(ret); \n } \n }; \n \n [TheName].prototype.checkFulfillment = function(promise) { \n var now = ++this.now; \n if (now === [TheTotal]) { \n if (this.asyncNeeded) { \n async.invoke(this._callFunction, this, promise); \n } else { \n this._callFunction(promise); \n } \n \n } \n }; \n \n [TheName].prototype._resultCancelled = function() { \n [CancellationCode] \n }; \n \n return [TheName]; \n }(tryCatch, errorObj, Promise, async); \n ";
2223
+ code = code.replace(/\[TheName\]/g, name).replace(/\[TheTotal\]/g, total).replace(/\[ThePassedArguments\]/g, passedArguments).replace(/\[TheProperties\]/g, assignment).replace(/\[CancellationCode\]/g, cancellationCode);
2224
+ return new Function("tryCatch", "errorObj", "Promise", "async", code)(tryCatch, errorObj, Promise, async);
2225
+ };
2226
+ var holderClasses = [];
2227
+ var thenCallbacks = [];
2228
+ var promiseSetters = [];
2229
+ for (var i = 0; i < 8; ++i) {
2230
+ holderClasses.push(generateHolderClass(i + 1));
2231
+ thenCallbacks.push(thenCallback(i + 1));
2232
+ promiseSetters.push(promiseSetter(i + 1));
2233
+ }
2234
+ reject = function(reason) {
2235
+ this._reject(reason);
2236
+ };
2237
+ }
2238
+ Promise.join = function() {
2239
+ var last = arguments.length - 1;
2240
+ var fn;
2241
+ if (last > 0 && typeof arguments[last] === "function") {
2242
+ fn = arguments[last];
2243
+ if (last <= 8 && canEvaluate) {
2244
+ var ret = new Promise(INTERNAL);
2245
+ ret._captureStackTrace();
2246
+ var HolderClass = holderClasses[last - 1];
2247
+ var holder = new HolderClass(fn);
2248
+ var callbacks = thenCallbacks;
2249
+ for (var i = 0; i < last; ++i) {
2250
+ var maybePromise = tryConvertToPromise(arguments[i], ret);
2251
+ if (maybePromise instanceof Promise) {
2252
+ maybePromise = maybePromise._target();
2253
+ var bitField = maybePromise._bitField;
2254
+ if ((bitField & 50397184) === 0) {
2255
+ maybePromise._then(callbacks[i], reject, void 0, ret, holder);
2256
+ promiseSetters[i](maybePromise, holder);
2257
+ holder.asyncNeeded = false;
2258
+ } else if ((bitField & 33554432) !== 0) callbacks[i].call(ret, maybePromise._value(), holder);
2259
+ else if ((bitField & 16777216) !== 0) ret._reject(maybePromise._reason());
2260
+ else ret._cancel();
2261
+ } else callbacks[i].call(ret, maybePromise, holder);
2262
+ }
2263
+ if (!ret._isFateSealed()) {
2264
+ if (holder.asyncNeeded) {
2265
+ var context = Promise._getContext();
2266
+ holder.fn = util.contextBind(context, holder.fn);
2267
+ }
2268
+ ret._setAsyncGuaranteed();
2269
+ ret._setOnCancel(holder);
2270
+ }
2271
+ return ret;
2272
+ }
2273
+ }
2274
+ var $_len = arguments.length;
2275
+ var args = new Array($_len);
2276
+ for (var $_i = 0; $_i < $_len; ++$_i) args[$_i] = arguments[$_i];
2277
+ if (fn) args.pop();
2278
+ var ret = new PromiseArray(args).promise();
2279
+ return fn !== void 0 ? ret.spread(fn) : ret;
2280
+ };
2281
+ };
2282
+ }));
2283
+ var require_call_get = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2284
+ var cr = Object.create;
2285
+ if (cr) {
2286
+ var callerCache = cr(null);
2287
+ var getterCache = cr(null);
2288
+ callerCache[" size"] = getterCache[" size"] = 0;
2289
+ }
2290
+ module.exports = function(Promise) {
2291
+ var util = require_util();
2292
+ var canEvaluate = util.canEvaluate;
2293
+ var isIdentifier = util.isIdentifier;
2294
+ var getMethodCaller;
2295
+ var getGetter;
2296
+ var makeMethodCaller = function(methodName) {
2297
+ return new Function("ensureMethod", " \n return function(obj) { \n 'use strict' \n var len = this.length; \n ensureMethod(obj, 'methodName'); \n switch(len) { \n case 1: return obj.methodName(this[0]); \n case 2: return obj.methodName(this[0], this[1]); \n case 3: return obj.methodName(this[0], this[1], this[2]); \n case 0: return obj.methodName(); \n default: \n return obj.methodName.apply(obj, this); \n } \n }; \n ".replace(/methodName/g, methodName))(ensureMethod);
2298
+ };
2299
+ var makeGetter = function(propertyName) {
2300
+ return new Function("obj", " \n 'use strict'; \n return obj.propertyName; \n ".replace("propertyName", propertyName));
2301
+ };
2302
+ var getCompiled = function(name, compiler, cache) {
2303
+ var ret = cache[name];
2304
+ if (typeof ret !== "function") {
2305
+ if (!isIdentifier(name)) return null;
2306
+ ret = compiler(name);
2307
+ cache[name] = ret;
2308
+ cache[" size"]++;
2309
+ if (cache[" size"] > 512) {
2310
+ var keys = Object.keys(cache);
2311
+ for (var i = 0; i < 256; ++i) delete cache[keys[i]];
2312
+ cache[" size"] = keys.length - 256;
2313
+ }
2314
+ }
2315
+ return ret;
2316
+ };
2317
+ getMethodCaller = function(name) {
2318
+ return getCompiled(name, makeMethodCaller, callerCache);
2319
+ };
2320
+ getGetter = function(name) {
2321
+ return getCompiled(name, makeGetter, getterCache);
2322
+ };
2323
+ function ensureMethod(obj, methodName) {
2324
+ var fn;
2325
+ if (obj != null) fn = obj[methodName];
2326
+ if (typeof fn !== "function") {
2327
+ var message = "Object " + util.classString(obj) + " has no method '" + util.toString(methodName) + "'";
2328
+ throw new Promise.TypeError(message);
2329
+ }
2330
+ return fn;
2331
+ }
2332
+ function caller(obj) {
2333
+ return ensureMethod(obj, this.pop()).apply(obj, this);
2334
+ }
2335
+ Promise.prototype.call = function(methodName) {
2336
+ var $_len = arguments.length;
2337
+ var args = new Array(Math.max($_len - 1, 0));
2338
+ for (var $_i = 1; $_i < $_len; ++$_i) args[$_i - 1] = arguments[$_i];
2339
+ if (canEvaluate) {
2340
+ var maybeCaller = getMethodCaller(methodName);
2341
+ if (maybeCaller !== null) return this._then(maybeCaller, void 0, void 0, args, void 0);
2342
+ }
2343
+ args.push(methodName);
2344
+ return this._then(caller, void 0, void 0, args, void 0);
2345
+ };
2346
+ function namedGetter(obj) {
2347
+ return obj[this];
2348
+ }
2349
+ function indexedGetter(obj) {
2350
+ var index = +this;
2351
+ if (index < 0) index = Math.max(0, index + obj.length);
2352
+ return obj[index];
2353
+ }
2354
+ Promise.prototype.get = function(propertyName) {
2355
+ var isIndex = typeof propertyName === "number";
2356
+ var getter;
2357
+ if (!isIndex) if (canEvaluate) {
2358
+ var maybeGetter = getGetter(propertyName);
2359
+ getter = maybeGetter !== null ? maybeGetter : namedGetter;
2360
+ } else getter = namedGetter;
2361
+ else getter = indexedGetter;
2362
+ return this._then(getter, void 0, void 0, propertyName, void 0);
2363
+ };
2364
+ };
2365
+ }));
2366
+ var require_generators = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2367
+ module.exports = function(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug) {
2368
+ var TypeError = require_errors().TypeError;
2369
+ var util = require_util();
2370
+ var errorObj = util.errorObj;
2371
+ var tryCatch = util.tryCatch;
2372
+ var yieldHandlers = [];
2373
+ function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
2374
+ for (var i = 0; i < yieldHandlers.length; ++i) {
2375
+ traceParent._pushContext();
2376
+ var result = tryCatch(yieldHandlers[i])(value);
2377
+ traceParent._popContext();
2378
+ if (result === errorObj) {
2379
+ traceParent._pushContext();
2380
+ var ret = Promise.reject(errorObj.e);
2381
+ traceParent._popContext();
2382
+ return ret;
2383
+ }
2384
+ var maybePromise = tryConvertToPromise(result, traceParent);
2385
+ if (maybePromise instanceof Promise) return maybePromise;
2386
+ }
2387
+ return null;
2388
+ }
2389
+ function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
2390
+ if (debug.cancellation()) {
2391
+ var internal = new Promise(INTERNAL);
2392
+ var _finallyPromise = this._finallyPromise = new Promise(INTERNAL);
2393
+ this._promise = internal.lastly(function() {
2394
+ return _finallyPromise;
2395
+ });
2396
+ internal._captureStackTrace();
2397
+ internal._setOnCancel(this);
2398
+ } else (this._promise = new Promise(INTERNAL))._captureStackTrace();
2399
+ this._stack = stack;
2400
+ this._generatorFunction = generatorFunction;
2401
+ this._receiver = receiver;
2402
+ this._generator = void 0;
2403
+ this._yieldHandlers = typeof yieldHandler === "function" ? [yieldHandler].concat(yieldHandlers) : yieldHandlers;
2404
+ this._yieldedPromise = null;
2405
+ this._cancellationPhase = false;
2406
+ }
2407
+ util.inherits(PromiseSpawn, Proxyable);
2408
+ PromiseSpawn.prototype._isResolved = function() {
2409
+ return this._promise === null;
2410
+ };
2411
+ PromiseSpawn.prototype._cleanup = function() {
2412
+ this._promise = this._generator = null;
2413
+ if (debug.cancellation() && this._finallyPromise !== null) {
2414
+ this._finallyPromise._fulfill();
2415
+ this._finallyPromise = null;
2416
+ }
2417
+ };
2418
+ PromiseSpawn.prototype._promiseCancelled = function() {
2419
+ if (this._isResolved()) return;
2420
+ var implementsReturn = typeof this._generator["return"] !== "undefined";
2421
+ var result;
2422
+ if (!implementsReturn) {
2423
+ var reason = new Promise.CancellationError("generator .return() sentinel");
2424
+ Promise.coroutine.returnSentinel = reason;
2425
+ this._promise._attachExtraTrace(reason);
2426
+ this._promise._pushContext();
2427
+ result = tryCatch(this._generator["throw"]).call(this._generator, reason);
2428
+ this._promise._popContext();
2429
+ } else {
2430
+ this._promise._pushContext();
2431
+ result = tryCatch(this._generator["return"]).call(this._generator, void 0);
2432
+ this._promise._popContext();
2433
+ }
2434
+ this._cancellationPhase = true;
2435
+ this._yieldedPromise = null;
2436
+ this._continue(result);
2437
+ };
2438
+ PromiseSpawn.prototype._promiseFulfilled = function(value) {
2439
+ this._yieldedPromise = null;
2440
+ this._promise._pushContext();
2441
+ var result = tryCatch(this._generator.next).call(this._generator, value);
2442
+ this._promise._popContext();
2443
+ this._continue(result);
2444
+ };
2445
+ PromiseSpawn.prototype._promiseRejected = function(reason) {
2446
+ this._yieldedPromise = null;
2447
+ this._promise._attachExtraTrace(reason);
2448
+ this._promise._pushContext();
2449
+ var result = tryCatch(this._generator["throw"]).call(this._generator, reason);
2450
+ this._promise._popContext();
2451
+ this._continue(result);
2452
+ };
2453
+ PromiseSpawn.prototype._resultCancelled = function() {
2454
+ if (this._yieldedPromise instanceof Promise) {
2455
+ var promise = this._yieldedPromise;
2456
+ this._yieldedPromise = null;
2457
+ promise.cancel();
2458
+ }
2459
+ };
2460
+ PromiseSpawn.prototype.promise = function() {
2461
+ return this._promise;
2462
+ };
2463
+ PromiseSpawn.prototype._run = function() {
2464
+ this._generator = this._generatorFunction.call(this._receiver);
2465
+ this._receiver = this._generatorFunction = void 0;
2466
+ this._promiseFulfilled(void 0);
2467
+ };
2468
+ PromiseSpawn.prototype._continue = function(result) {
2469
+ var promise = this._promise;
2470
+ if (result === errorObj) {
2471
+ this._cleanup();
2472
+ if (this._cancellationPhase) return promise.cancel();
2473
+ else return promise._rejectCallback(result.e, false);
2474
+ }
2475
+ var value = result.value;
2476
+ if (result.done === true) {
2477
+ this._cleanup();
2478
+ if (this._cancellationPhase) return promise.cancel();
2479
+ else return promise._resolveCallback(value);
2480
+ } else {
2481
+ var maybePromise = tryConvertToPromise(value, this._promise);
2482
+ if (!(maybePromise instanceof Promise)) {
2483
+ maybePromise = promiseFromYieldHandler(maybePromise, this._yieldHandlers, this._promise);
2484
+ if (maybePromise === null) {
2485
+ this._promiseRejected(new TypeError("A value %s was yielded that could not be treated as a promise\n\n See http://goo.gl/MqrFmX\n\n".replace("%s", String(value)) + "From coroutine:\n" + this._stack.split("\n").slice(1, -7).join("\n")));
2486
+ return;
2487
+ }
2488
+ }
2489
+ maybePromise = maybePromise._target();
2490
+ var bitField = maybePromise._bitField;
2491
+ if ((bitField & 50397184) === 0) {
2492
+ this._yieldedPromise = maybePromise;
2493
+ maybePromise._proxy(this, null);
2494
+ } else if ((bitField & 33554432) !== 0) Promise._async.invoke(this._promiseFulfilled, this, maybePromise._value());
2495
+ else if ((bitField & 16777216) !== 0) Promise._async.invoke(this._promiseRejected, this, maybePromise._reason());
2496
+ else this._promiseCancelled();
2497
+ }
2498
+ };
2499
+ Promise.coroutine = function(generatorFunction, options) {
2500
+ if (typeof generatorFunction !== "function") throw new TypeError("generatorFunction must be a function\n\n See http://goo.gl/MqrFmX\n");
2501
+ var yieldHandler = Object(options).yieldHandler;
2502
+ var PromiseSpawn$ = PromiseSpawn;
2503
+ var stack = (/* @__PURE__ */ new Error()).stack;
2504
+ return function() {
2505
+ var generator = generatorFunction.apply(this, arguments);
2506
+ var spawn = new PromiseSpawn$(void 0, void 0, yieldHandler, stack);
2507
+ var ret = spawn.promise();
2508
+ spawn._generator = generator;
2509
+ spawn._promiseFulfilled(void 0);
2510
+ return ret;
2511
+ };
2512
+ };
2513
+ Promise.coroutine.addYieldHandler = function(fn) {
2514
+ if (typeof fn !== "function") throw new TypeError("expecting a function but got " + util.classString(fn));
2515
+ yieldHandlers.push(fn);
2516
+ };
2517
+ Promise.spawn = function(generatorFunction) {
2518
+ debug.deprecated("Promise.spawn()", "Promise.coroutine()");
2519
+ if (typeof generatorFunction !== "function") return apiRejection("generatorFunction must be a function\n\n See http://goo.gl/MqrFmX\n");
2520
+ var spawn = new PromiseSpawn(generatorFunction, this);
2521
+ var ret = spawn.promise();
2522
+ spawn._run(Promise.spawn);
2523
+ return ret;
2524
+ };
2525
+ };
2526
+ }));
2527
+ var require_map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2528
+ module.exports = function(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug) {
2529
+ var util = require_util();
2530
+ var tryCatch = util.tryCatch;
2531
+ var errorObj = util.errorObj;
2532
+ var async = Promise._async;
2533
+ function MappingPromiseArray(promises, fn, limit, _filter) {
2534
+ this.constructor$(promises);
2535
+ this._promise._captureStackTrace();
2536
+ var context = Promise._getContext();
2537
+ this._callback = util.contextBind(context, fn);
2538
+ this._preservedValues = _filter === INTERNAL ? new Array(this.length()) : null;
2539
+ this._limit = limit;
2540
+ this._inFlight = 0;
2541
+ this._queue = [];
2542
+ async.invoke(this._asyncInit, this, void 0);
2543
+ if (util.isArray(promises)) for (var i = 0; i < promises.length; ++i) {
2544
+ var maybePromise = promises[i];
2545
+ if (maybePromise instanceof Promise) maybePromise.suppressUnhandledRejections();
2546
+ }
2547
+ }
2548
+ util.inherits(MappingPromiseArray, PromiseArray);
2549
+ MappingPromiseArray.prototype._asyncInit = function() {
2550
+ this._init$(void 0, -2);
2551
+ };
2552
+ MappingPromiseArray.prototype._init = function() {};
2553
+ MappingPromiseArray.prototype._promiseFulfilled = function(value, index) {
2554
+ var values = this._values;
2555
+ var length = this.length();
2556
+ var preservedValues = this._preservedValues;
2557
+ var limit = this._limit;
2558
+ if (index < 0) {
2559
+ index = index * -1 - 1;
2560
+ values[index] = value;
2561
+ if (limit >= 1) {
2562
+ this._inFlight--;
2563
+ this._drainQueue();
2564
+ if (this._isResolved()) return true;
2565
+ }
2566
+ } else {
2567
+ if (limit >= 1 && this._inFlight >= limit) {
2568
+ values[index] = value;
2569
+ this._queue.push(index);
2570
+ return false;
2571
+ }
2572
+ if (preservedValues !== null) preservedValues[index] = value;
2573
+ var promise = this._promise;
2574
+ var callback = this._callback;
2575
+ var receiver = promise._boundValue();
2576
+ promise._pushContext();
2577
+ var ret = tryCatch(callback).call(receiver, value, index, length);
2578
+ var promiseCreated = promise._popContext();
2579
+ debug.checkForgottenReturns(ret, promiseCreated, preservedValues !== null ? "Promise.filter" : "Promise.map", promise);
2580
+ if (ret === errorObj) {
2581
+ this._reject(ret.e);
2582
+ return true;
2583
+ }
2584
+ var maybePromise = tryConvertToPromise(ret, this._promise);
2585
+ if (maybePromise instanceof Promise) {
2586
+ maybePromise = maybePromise._target();
2587
+ var bitField = maybePromise._bitField;
2588
+ if ((bitField & 50397184) === 0) {
2589
+ if (limit >= 1) this._inFlight++;
2590
+ values[index] = maybePromise;
2591
+ maybePromise._proxy(this, (index + 1) * -1);
2592
+ return false;
2593
+ } else if ((bitField & 33554432) !== 0) ret = maybePromise._value();
2594
+ else if ((bitField & 16777216) !== 0) {
2595
+ this._reject(maybePromise._reason());
2596
+ return true;
2597
+ } else {
2598
+ this._cancel();
2599
+ return true;
2600
+ }
2601
+ }
2602
+ values[index] = ret;
2603
+ }
2604
+ if (++this._totalResolved >= length) {
2605
+ if (preservedValues !== null) this._filter(values, preservedValues);
2606
+ else this._resolve(values);
2607
+ return true;
2608
+ }
2609
+ return false;
2610
+ };
2611
+ MappingPromiseArray.prototype._drainQueue = function() {
2612
+ var queue = this._queue;
2613
+ var limit = this._limit;
2614
+ var values = this._values;
2615
+ while (queue.length > 0 && this._inFlight < limit) {
2616
+ if (this._isResolved()) return;
2617
+ var index = queue.pop();
2618
+ this._promiseFulfilled(values[index], index);
2619
+ }
2620
+ };
2621
+ MappingPromiseArray.prototype._filter = function(booleans, values) {
2622
+ var len = values.length;
2623
+ var ret = new Array(len);
2624
+ var j = 0;
2625
+ for (var i = 0; i < len; ++i) if (booleans[i]) ret[j++] = values[i];
2626
+ ret.length = j;
2627
+ this._resolve(ret);
2628
+ };
2629
+ MappingPromiseArray.prototype.preservedValues = function() {
2630
+ return this._preservedValues;
2631
+ };
2632
+ function map(promises, fn, options, _filter) {
2633
+ if (typeof fn !== "function") return apiRejection("expecting a function but got " + util.classString(fn));
2634
+ var limit = 0;
2635
+ if (options !== void 0) if (typeof options === "object" && options !== null) {
2636
+ if (typeof options.concurrency !== "number") return Promise.reject(/* @__PURE__ */ new TypeError("'concurrency' must be a number but it is " + util.classString(options.concurrency)));
2637
+ limit = options.concurrency;
2638
+ } else return Promise.reject(/* @__PURE__ */ new TypeError("options argument must be an object but it is " + util.classString(options)));
2639
+ limit = typeof limit === "number" && isFinite(limit) && limit >= 1 ? limit : 0;
2640
+ return new MappingPromiseArray(promises, fn, limit, _filter).promise();
2641
+ }
2642
+ Promise.prototype.map = function(fn, options) {
2643
+ return map(this, fn, options, null);
2644
+ };
2645
+ Promise.map = function(promises, fn, options, _filter) {
2646
+ return map(promises, fn, options, _filter);
2647
+ };
2648
+ };
2649
+ }));
2650
+ var require_nodeify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2651
+ module.exports = function(Promise) {
2652
+ var util = require_util();
2653
+ var async = Promise._async;
2654
+ var tryCatch = util.tryCatch;
2655
+ var errorObj = util.errorObj;
2656
+ function spreadAdapter(val, nodeback) {
2657
+ var promise = this;
2658
+ if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
2659
+ var ret = tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
2660
+ if (ret === errorObj) async.throwLater(ret.e);
2661
+ }
2662
+ function successAdapter(val, nodeback) {
2663
+ var receiver = this._boundValue();
2664
+ var ret = val === void 0 ? tryCatch(nodeback).call(receiver, null) : tryCatch(nodeback).call(receiver, null, val);
2665
+ if (ret === errorObj) async.throwLater(ret.e);
2666
+ }
2667
+ function errorAdapter(reason, nodeback) {
2668
+ var promise = this;
2669
+ if (!reason) {
2670
+ var newReason = /* @__PURE__ */ new Error(reason + "");
2671
+ newReason.cause = reason;
2672
+ reason = newReason;
2673
+ }
2674
+ var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
2675
+ if (ret === errorObj) async.throwLater(ret.e);
2676
+ }
2677
+ Promise.prototype.asCallback = Promise.prototype.nodeify = function(nodeback, options) {
2678
+ if (typeof nodeback == "function") {
2679
+ var adapter = successAdapter;
2680
+ if (options !== void 0 && Object(options).spread) adapter = spreadAdapter;
2681
+ this._then(adapter, errorAdapter, void 0, this, nodeback);
2682
+ }
2683
+ return this;
2684
+ };
2685
+ };
2686
+ }));
2687
+ var require_promisify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2688
+ module.exports = function(Promise, INTERNAL) {
2689
+ var THIS = {};
2690
+ var util = require_util();
2691
+ var nodebackForPromise = require_nodeback();
2692
+ var withAppended = util.withAppended;
2693
+ var maybeWrapAsError = util.maybeWrapAsError;
2694
+ var canEvaluate = util.canEvaluate;
2695
+ var TypeError = require_errors().TypeError;
2696
+ var defaultSuffix = "Async";
2697
+ var defaultPromisified = { __isPromisified__: true };
2698
+ var noCopyPropsPattern = new RegExp("^(?:" + [
2699
+ "arity",
2700
+ "length",
2701
+ "name",
2702
+ "arguments",
2703
+ "caller",
2704
+ "callee",
2705
+ "prototype",
2706
+ "__isPromisified__"
2707
+ ].join("|") + ")$");
2708
+ var defaultFilter = function(name) {
2709
+ return util.isIdentifier(name) && name.charAt(0) !== "_" && name !== "constructor";
2710
+ };
2711
+ function propsFilter(key) {
2712
+ return !noCopyPropsPattern.test(key);
2713
+ }
2714
+ function isPromisified(fn) {
2715
+ try {
2716
+ return fn.__isPromisified__ === true;
2717
+ } catch (e) {
2718
+ return false;
2719
+ }
2720
+ }
2721
+ function hasPromisified(obj, key, suffix) {
2722
+ var val = util.getDataPropertyOrDefault(obj, key + suffix, defaultPromisified);
2723
+ return val ? isPromisified(val) : false;
2724
+ }
2725
+ function checkValid(ret, suffix, suffixRegexp) {
2726
+ for (var i = 0; i < ret.length; i += 2) {
2727
+ var key = ret[i];
2728
+ if (suffixRegexp.test(key)) {
2729
+ var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
2730
+ for (var j = 0; j < ret.length; j += 2) if (ret[j] === keyWithoutAsyncSuffix) throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\n\n See http://goo.gl/MqrFmX\n".replace("%s", suffix));
2731
+ }
2732
+ }
2733
+ }
2734
+ function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
2735
+ var keys = util.inheritedDataKeys(obj);
2736
+ var ret = [];
2737
+ for (var i = 0; i < keys.length; ++i) {
2738
+ var key = keys[i];
2739
+ var value = obj[key];
2740
+ var passesDefaultFilter = filter === defaultFilter ? true : defaultFilter(key, value, obj);
2741
+ if (typeof value === "function" && !isPromisified(value) && !hasPromisified(obj, key, suffix) && filter(key, value, obj, passesDefaultFilter)) ret.push(key, value);
2742
+ }
2743
+ checkValid(ret, suffix, suffixRegexp);
2744
+ return ret;
2745
+ }
2746
+ var escapeIdentRegex = function(str) {
2747
+ return str.replace(/([$])/, "\\$");
2748
+ };
2749
+ var makeNodePromisifiedEval;
2750
+ var switchCaseArgumentOrder = function(likelyArgumentCount) {
2751
+ var ret = [likelyArgumentCount];
2752
+ var min = Math.max(0, likelyArgumentCount - 1 - 3);
2753
+ for (var i = likelyArgumentCount - 1; i >= min; --i) ret.push(i);
2754
+ for (var i = likelyArgumentCount + 1; i <= 3; ++i) ret.push(i);
2755
+ return ret;
2756
+ };
2757
+ var argumentSequence = function(argumentCount) {
2758
+ return util.filledRange(argumentCount, "_arg", "");
2759
+ };
2760
+ var parameterDeclaration = function(parameterCount) {
2761
+ return util.filledRange(Math.max(parameterCount, 3), "_arg", "");
2762
+ };
2763
+ var parameterCount = function(fn) {
2764
+ if (typeof fn.length === "number") return Math.max(Math.min(fn.length, 1024), 0);
2765
+ return 0;
2766
+ };
2767
+ makeNodePromisifiedEval = function(callback, receiver, originalName, fn, _, multiArgs) {
2768
+ var newParameterCount = Math.max(0, parameterCount(fn) - 1);
2769
+ var argumentOrder = switchCaseArgumentOrder(newParameterCount);
2770
+ var shouldProxyThis = typeof callback === "string" || receiver === THIS;
2771
+ function generateCallForArgumentCount(count) {
2772
+ var args = argumentSequence(count).join(", ");
2773
+ var comma = count > 0 ? ", " : "";
2774
+ var ret;
2775
+ if (shouldProxyThis) ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
2776
+ else ret = receiver === void 0 ? "ret = callback({{args}}, nodeback); break;\n" : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
2777
+ return ret.replace("{{args}}", args).replace(", ", comma);
2778
+ }
2779
+ function generateArgumentSwitchCase() {
2780
+ var ret = "";
2781
+ for (var i = 0; i < argumentOrder.length; ++i) ret += "case " + argumentOrder[i] + ":" + generateCallForArgumentCount(argumentOrder[i]);
2782
+ ret += " \n default: \n var args = new Array(len + 1); \n var i = 0; \n for (var i = 0; i < len; ++i) { \n args[i] = arguments[i]; \n } \n args[i] = nodeback; \n [CodeForCall] \n break; \n ".replace("[CodeForCall]", shouldProxyThis ? "ret = callback.apply(this, args);\n" : "ret = callback.apply(receiver, args);\n");
2783
+ return ret;
2784
+ }
2785
+ var getFunctionCode = typeof callback === "string" ? "this != null ? this['" + callback + "'] : fn" : "fn";
2786
+ var body = "'use strict'; \n var ret = function (Parameters) { \n 'use strict'; \n var len = arguments.length; \n var promise = new Promise(INTERNAL); \n promise._captureStackTrace(); \n var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n var ret; \n var callback = tryCatch([GetFunctionCode]); \n switch(len) { \n [CodeForSwitchCase] \n } \n if (ret === errorObj) { \n promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n } \n if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n return promise; \n }; \n notEnumerableProp(ret, '__isPromisified__', true); \n return ret; \n ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase()).replace("[GetFunctionCode]", getFunctionCode);
2787
+ body = body.replace("Parameters", parameterDeclaration(newParameterCount));
2788
+ return new Function("Promise", "fn", "receiver", "withAppended", "maybeWrapAsError", "nodebackForPromise", "tryCatch", "errorObj", "notEnumerableProp", "INTERNAL", body)(Promise, fn, receiver, withAppended, maybeWrapAsError, nodebackForPromise, util.tryCatch, util.errorObj, util.notEnumerableProp, INTERNAL);
2789
+ };
2790
+ function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
2791
+ var defaultThis = (function() {
2792
+ return this;
2793
+ })();
2794
+ var method = callback;
2795
+ if (typeof method === "string") callback = fn;
2796
+ function promisified() {
2797
+ var _receiver = receiver;
2798
+ if (receiver === THIS) _receiver = this;
2799
+ var promise = new Promise(INTERNAL);
2800
+ promise._captureStackTrace();
2801
+ var cb = typeof method === "string" && this !== defaultThis ? this[method] : callback;
2802
+ var fn = nodebackForPromise(promise, multiArgs);
2803
+ try {
2804
+ cb.apply(_receiver, withAppended(arguments, fn));
2805
+ } catch (e) {
2806
+ promise._rejectCallback(maybeWrapAsError(e), true, true);
2807
+ }
2808
+ if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
2809
+ return promise;
2810
+ }
2811
+ util.notEnumerableProp(promisified, "__isPromisified__", true);
2812
+ return promisified;
2813
+ }
2814
+ var makeNodePromisified = canEvaluate ? makeNodePromisifiedEval : makeNodePromisifiedClosure;
2815
+ function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
2816
+ var methods = promisifiableMethods(obj, suffix, new RegExp(escapeIdentRegex(suffix) + "$"), filter);
2817
+ for (var i = 0, len = methods.length; i < len; i += 2) {
2818
+ var key = methods[i];
2819
+ var fn = methods[i + 1];
2820
+ var promisifiedKey = key + suffix;
2821
+ if (promisifier === makeNodePromisified) obj[promisifiedKey] = makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
2822
+ else {
2823
+ var promisified = promisifier(fn, function() {
2824
+ return makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
2825
+ });
2826
+ util.notEnumerableProp(promisified, "__isPromisified__", true);
2827
+ obj[promisifiedKey] = promisified;
2828
+ }
2829
+ }
2830
+ util.toFastProperties(obj);
2831
+ return obj;
2832
+ }
2833
+ function promisify(callback, receiver, multiArgs) {
2834
+ return makeNodePromisified(callback, receiver, void 0, callback, null, multiArgs);
2835
+ }
2836
+ Promise.promisify = function(fn, options) {
2837
+ if (typeof fn !== "function") throw new TypeError("expecting a function but got " + util.classString(fn));
2838
+ if (isPromisified(fn)) return fn;
2839
+ options = Object(options);
2840
+ var ret = promisify(fn, options.context === void 0 ? THIS : options.context, !!options.multiArgs);
2841
+ util.copyDescriptors(fn, ret, propsFilter);
2842
+ return ret;
2843
+ };
2844
+ Promise.promisifyAll = function(target, options) {
2845
+ if (typeof target !== "function" && typeof target !== "object") throw new TypeError("the target of promisifyAll must be an object or a function\n\n See http://goo.gl/MqrFmX\n");
2846
+ options = Object(options);
2847
+ var multiArgs = !!options.multiArgs;
2848
+ var suffix = options.suffix;
2849
+ if (typeof suffix !== "string") suffix = defaultSuffix;
2850
+ var filter = options.filter;
2851
+ if (typeof filter !== "function") filter = defaultFilter;
2852
+ var promisifier = options.promisifier;
2853
+ if (typeof promisifier !== "function") promisifier = makeNodePromisified;
2854
+ if (!util.isIdentifier(suffix)) throw new RangeError("suffix must be a valid identifier\n\n See http://goo.gl/MqrFmX\n");
2855
+ var keys = util.inheritedDataKeys(target);
2856
+ for (var i = 0; i < keys.length; ++i) {
2857
+ var value = target[keys[i]];
2858
+ if (keys[i] !== "constructor" && util.isClass(value)) {
2859
+ promisifyAll(value.prototype, suffix, filter, promisifier, multiArgs);
2860
+ promisifyAll(value, suffix, filter, promisifier, multiArgs);
2861
+ }
2862
+ }
2863
+ return promisifyAll(target, suffix, filter, promisifier, multiArgs);
2864
+ };
2865
+ };
2866
+ }));
2867
+ var require_props = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2868
+ module.exports = function(Promise, PromiseArray, tryConvertToPromise, apiRejection) {
2869
+ var util = require_util();
2870
+ var isObject = util.isObject;
2871
+ var es5 = require_es5();
2872
+ var Es6Map;
2873
+ if (typeof Map === "function") Es6Map = Map;
2874
+ var mapToEntries = (function() {
2875
+ var index = 0;
2876
+ var size = 0;
2877
+ function extractEntry(value, key) {
2878
+ this[index] = value;
2879
+ this[index + size] = key;
2880
+ index++;
2881
+ }
2882
+ return function mapToEntries(map) {
2883
+ size = map.size;
2884
+ index = 0;
2885
+ var ret = new Array(map.size * 2);
2886
+ map.forEach(extractEntry, ret);
2887
+ return ret;
2888
+ };
2889
+ })();
2890
+ var entriesToMap = function(entries) {
2891
+ var ret = new Es6Map();
2892
+ var length = entries.length / 2 | 0;
2893
+ for (var i = 0; i < length; ++i) {
2894
+ var key = entries[length + i];
2895
+ var value = entries[i];
2896
+ ret.set(key, value);
2897
+ }
2898
+ return ret;
2899
+ };
2900
+ function PropertiesPromiseArray(obj) {
2901
+ var isMap = false;
2902
+ var entries;
2903
+ if (Es6Map !== void 0 && obj instanceof Es6Map) {
2904
+ entries = mapToEntries(obj);
2905
+ isMap = true;
2906
+ } else {
2907
+ var keys = es5.keys(obj);
2908
+ var len = keys.length;
2909
+ entries = new Array(len * 2);
2910
+ for (var i = 0; i < len; ++i) {
2911
+ var key = keys[i];
2912
+ entries[i] = obj[key];
2913
+ entries[i + len] = key;
2914
+ }
2915
+ }
2916
+ this.constructor$(entries);
2917
+ this._isMap = isMap;
2918
+ this._init$(void 0, isMap ? -6 : -3);
2919
+ }
2920
+ util.inherits(PropertiesPromiseArray, PromiseArray);
2921
+ PropertiesPromiseArray.prototype._init = function() {};
2922
+ PropertiesPromiseArray.prototype._promiseFulfilled = function(value, index) {
2923
+ this._values[index] = value;
2924
+ if (++this._totalResolved >= this._length) {
2925
+ var val;
2926
+ if (this._isMap) val = entriesToMap(this._values);
2927
+ else {
2928
+ val = {};
2929
+ var keyOffset = this.length();
2930
+ for (var i = 0, len = this.length(); i < len; ++i) val[this._values[i + keyOffset]] = this._values[i];
2931
+ }
2932
+ this._resolve(val);
2933
+ return true;
2934
+ }
2935
+ return false;
2936
+ };
2937
+ PropertiesPromiseArray.prototype.shouldCopyValues = function() {
2938
+ return false;
2939
+ };
2940
+ PropertiesPromiseArray.prototype.getActualLength = function(len) {
2941
+ return len >> 1;
2942
+ };
2943
+ function props(promises) {
2944
+ var ret;
2945
+ var castValue = tryConvertToPromise(promises);
2946
+ if (!isObject(castValue)) return apiRejection("cannot await properties of a non-object\n\n See http://goo.gl/MqrFmX\n");
2947
+ else if (castValue instanceof Promise) ret = castValue._then(Promise.props, void 0, void 0, void 0, void 0);
2948
+ else ret = new PropertiesPromiseArray(castValue).promise();
2949
+ if (castValue instanceof Promise) ret._propagateFrom(castValue, 2);
2950
+ return ret;
2951
+ }
2952
+ Promise.prototype.props = function() {
2953
+ return props(this);
2954
+ };
2955
+ Promise.props = function(promises) {
2956
+ return props(promises);
2957
+ };
2958
+ };
2959
+ }));
2960
+ var require_race = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2961
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise, apiRejection) {
2962
+ var util = require_util();
2963
+ var raceLater = function(promise) {
2964
+ return promise.then(function(array) {
2965
+ return race(array, promise);
2966
+ });
2967
+ };
2968
+ function race(promises, parent) {
2969
+ var maybePromise = tryConvertToPromise(promises);
2970
+ if (maybePromise instanceof Promise) return raceLater(maybePromise);
2971
+ else {
2972
+ promises = util.asArray(promises);
2973
+ if (promises === null) return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
2974
+ }
2975
+ var ret = new Promise(INTERNAL);
2976
+ if (parent !== void 0) ret._propagateFrom(parent, 3);
2977
+ var fulfill = ret._fulfill;
2978
+ var reject = ret._reject;
2979
+ for (var i = 0, len = promises.length; i < len; ++i) {
2980
+ var val = promises[i];
2981
+ if (val === void 0 && !(i in promises)) continue;
2982
+ Promise.cast(val)._then(fulfill, reject, void 0, ret, null);
2983
+ }
2984
+ return ret;
2985
+ }
2986
+ Promise.race = function(promises) {
2987
+ return race(promises, void 0);
2988
+ };
2989
+ Promise.prototype.race = function() {
2990
+ return race(this, void 0);
2991
+ };
2992
+ };
2993
+ }));
2994
+ var require_reduce = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2995
+ module.exports = function(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug) {
2996
+ var util = require_util();
2997
+ var tryCatch = util.tryCatch;
2998
+ function ReductionPromiseArray(promises, fn, initialValue, _each) {
2999
+ this.constructor$(promises);
3000
+ var context = Promise._getContext();
3001
+ this._fn = util.contextBind(context, fn);
3002
+ if (initialValue !== void 0) {
3003
+ initialValue = Promise.resolve(initialValue);
3004
+ initialValue._attachCancellationCallback(this);
3005
+ }
3006
+ this._initialValue = initialValue;
3007
+ this._currentCancellable = null;
3008
+ if (_each === INTERNAL) this._eachValues = Array(this._length);
3009
+ else if (_each === 0) this._eachValues = null;
3010
+ else this._eachValues = void 0;
3011
+ this._promise._captureStackTrace();
3012
+ this._init$(void 0, -5);
3013
+ }
3014
+ util.inherits(ReductionPromiseArray, PromiseArray);
3015
+ ReductionPromiseArray.prototype._gotAccum = function(accum) {
3016
+ if (this._eachValues !== void 0 && this._eachValues !== null && accum !== INTERNAL) this._eachValues.push(accum);
3017
+ };
3018
+ ReductionPromiseArray.prototype._eachComplete = function(value) {
3019
+ if (this._eachValues !== null) this._eachValues.push(value);
3020
+ return this._eachValues;
3021
+ };
3022
+ ReductionPromiseArray.prototype._init = function() {};
3023
+ ReductionPromiseArray.prototype._resolveEmptyArray = function() {
3024
+ this._resolve(this._eachValues !== void 0 ? this._eachValues : this._initialValue);
3025
+ };
3026
+ ReductionPromiseArray.prototype.shouldCopyValues = function() {
3027
+ return false;
3028
+ };
3029
+ ReductionPromiseArray.prototype._resolve = function(value) {
3030
+ this._promise._resolveCallback(value);
3031
+ this._values = null;
3032
+ };
3033
+ ReductionPromiseArray.prototype._resultCancelled = function(sender) {
3034
+ if (sender === this._initialValue) return this._cancel();
3035
+ if (this._isResolved()) return;
3036
+ this._resultCancelled$();
3037
+ if (this._currentCancellable instanceof Promise) this._currentCancellable.cancel();
3038
+ if (this._initialValue instanceof Promise) this._initialValue.cancel();
3039
+ };
3040
+ ReductionPromiseArray.prototype._iterate = function(values) {
3041
+ this._values = values;
3042
+ var value;
3043
+ var i;
3044
+ var length = values.length;
3045
+ if (this._initialValue !== void 0) {
3046
+ value = this._initialValue;
3047
+ i = 0;
3048
+ } else {
3049
+ value = Promise.resolve(values[0]);
3050
+ i = 1;
3051
+ }
3052
+ this._currentCancellable = value;
3053
+ for (var j = i; j < length; ++j) {
3054
+ var maybePromise = values[j];
3055
+ if (maybePromise instanceof Promise) maybePromise.suppressUnhandledRejections();
3056
+ }
3057
+ if (!value.isRejected()) for (; i < length; ++i) {
3058
+ var ctx = {
3059
+ accum: null,
3060
+ value: values[i],
3061
+ index: i,
3062
+ length,
3063
+ array: this
3064
+ };
3065
+ value = value._then(gotAccum, void 0, void 0, ctx, void 0);
3066
+ if ((i & 127) === 0) value._setNoAsyncGuarantee();
3067
+ }
3068
+ if (this._eachValues !== void 0) value = value._then(this._eachComplete, void 0, void 0, this, void 0);
3069
+ value._then(completed, completed, void 0, value, this);
3070
+ };
3071
+ Promise.prototype.reduce = function(fn, initialValue) {
3072
+ return reduce(this, fn, initialValue, null);
3073
+ };
3074
+ Promise.reduce = function(promises, fn, initialValue, _each) {
3075
+ return reduce(promises, fn, initialValue, _each);
3076
+ };
3077
+ function completed(valueOrReason, array) {
3078
+ if (this.isFulfilled()) array._resolve(valueOrReason);
3079
+ else array._reject(valueOrReason);
3080
+ }
3081
+ function reduce(promises, fn, initialValue, _each) {
3082
+ if (typeof fn !== "function") return apiRejection("expecting a function but got " + util.classString(fn));
3083
+ return new ReductionPromiseArray(promises, fn, initialValue, _each).promise();
3084
+ }
3085
+ function gotAccum(accum) {
3086
+ this.accum = accum;
3087
+ this.array._gotAccum(accum);
3088
+ var value = tryConvertToPromise(this.value, this.array._promise);
3089
+ if (value instanceof Promise) {
3090
+ this.array._currentCancellable = value;
3091
+ return value._then(gotValue, void 0, void 0, this, void 0);
3092
+ } else return gotValue.call(this, value);
3093
+ }
3094
+ function gotValue(value) {
3095
+ var array = this.array;
3096
+ var promise = array._promise;
3097
+ var fn = tryCatch(array._fn);
3098
+ promise._pushContext();
3099
+ var ret;
3100
+ if (array._eachValues !== void 0) ret = fn.call(promise._boundValue(), value, this.index, this.length);
3101
+ else ret = fn.call(promise._boundValue(), this.accum, value, this.index, this.length);
3102
+ if (ret instanceof Promise) array._currentCancellable = ret;
3103
+ var promiseCreated = promise._popContext();
3104
+ debug.checkForgottenReturns(ret, promiseCreated, array._eachValues !== void 0 ? "Promise.each" : "Promise.reduce", promise);
3105
+ return ret;
3106
+ }
3107
+ };
3108
+ }));
3109
+ var require_settle = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3110
+ module.exports = function(Promise, PromiseArray, debug) {
3111
+ var PromiseInspection = Promise.PromiseInspection;
3112
+ var util = require_util();
3113
+ function SettledPromiseArray(values) {
3114
+ this.constructor$(values);
3115
+ }
3116
+ util.inherits(SettledPromiseArray, PromiseArray);
3117
+ SettledPromiseArray.prototype._promiseResolved = function(index, inspection) {
3118
+ this._values[index] = inspection;
3119
+ if (++this._totalResolved >= this._length) {
3120
+ this._resolve(this._values);
3121
+ return true;
3122
+ }
3123
+ return false;
3124
+ };
3125
+ SettledPromiseArray.prototype._promiseFulfilled = function(value, index) {
3126
+ var ret = new PromiseInspection();
3127
+ ret._bitField = 33554432;
3128
+ ret._settledValueField = value;
3129
+ return this._promiseResolved(index, ret);
3130
+ };
3131
+ SettledPromiseArray.prototype._promiseRejected = function(reason, index) {
3132
+ var ret = new PromiseInspection();
3133
+ ret._bitField = 16777216;
3134
+ ret._settledValueField = reason;
3135
+ return this._promiseResolved(index, ret);
3136
+ };
3137
+ Promise.settle = function(promises) {
3138
+ debug.deprecated(".settle()", ".reflect()");
3139
+ return new SettledPromiseArray(promises).promise();
3140
+ };
3141
+ Promise.allSettled = function(promises) {
3142
+ return new SettledPromiseArray(promises).promise();
3143
+ };
3144
+ Promise.prototype.settle = function() {
3145
+ return Promise.settle(this);
3146
+ };
3147
+ };
3148
+ }));
3149
+ var require_some = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3150
+ module.exports = function(Promise, PromiseArray, apiRejection) {
3151
+ var util = require_util();
3152
+ var RangeError = require_errors().RangeError;
3153
+ var AggregateError = require_errors().AggregateError;
3154
+ var isArray = util.isArray;
3155
+ var CANCELLATION = {};
3156
+ function SomePromiseArray(values) {
3157
+ this.constructor$(values);
3158
+ this._howMany = 0;
3159
+ this._unwrap = false;
3160
+ this._initialized = false;
3161
+ }
3162
+ util.inherits(SomePromiseArray, PromiseArray);
3163
+ SomePromiseArray.prototype._init = function() {
3164
+ if (!this._initialized) return;
3165
+ if (this._howMany === 0) {
3166
+ this._resolve([]);
3167
+ return;
3168
+ }
3169
+ this._init$(void 0, -5);
3170
+ var isArrayResolved = isArray(this._values);
3171
+ if (!this._isResolved() && isArrayResolved && this._howMany > this._canPossiblyFulfill()) this._reject(this._getRangeError(this.length()));
3172
+ };
3173
+ SomePromiseArray.prototype.init = function() {
3174
+ this._initialized = true;
3175
+ this._init();
3176
+ };
3177
+ SomePromiseArray.prototype.setUnwrap = function() {
3178
+ this._unwrap = true;
3179
+ };
3180
+ SomePromiseArray.prototype.howMany = function() {
3181
+ return this._howMany;
3182
+ };
3183
+ SomePromiseArray.prototype.setHowMany = function(count) {
3184
+ this._howMany = count;
3185
+ };
3186
+ SomePromiseArray.prototype._promiseFulfilled = function(value) {
3187
+ this._addFulfilled(value);
3188
+ if (this._fulfilled() === this.howMany()) {
3189
+ this._values.length = this.howMany();
3190
+ if (this.howMany() === 1 && this._unwrap) this._resolve(this._values[0]);
3191
+ else this._resolve(this._values);
3192
+ return true;
3193
+ }
3194
+ return false;
3195
+ };
3196
+ SomePromiseArray.prototype._promiseRejected = function(reason) {
3197
+ this._addRejected(reason);
3198
+ return this._checkOutcome();
3199
+ };
3200
+ SomePromiseArray.prototype._promiseCancelled = function() {
3201
+ if (this._values instanceof Promise || this._values == null) return this._cancel();
3202
+ this._addRejected(CANCELLATION);
3203
+ return this._checkOutcome();
3204
+ };
3205
+ SomePromiseArray.prototype._checkOutcome = function() {
3206
+ if (this.howMany() > this._canPossiblyFulfill()) {
3207
+ var e = new AggregateError();
3208
+ for (var i = this.length(); i < this._values.length; ++i) if (this._values[i] !== CANCELLATION) e.push(this._values[i]);
3209
+ if (e.length > 0) this._reject(e);
3210
+ else this._cancel();
3211
+ return true;
3212
+ }
3213
+ return false;
3214
+ };
3215
+ SomePromiseArray.prototype._fulfilled = function() {
3216
+ return this._totalResolved;
3217
+ };
3218
+ SomePromiseArray.prototype._rejected = function() {
3219
+ return this._values.length - this.length();
3220
+ };
3221
+ SomePromiseArray.prototype._addRejected = function(reason) {
3222
+ this._values.push(reason);
3223
+ };
3224
+ SomePromiseArray.prototype._addFulfilled = function(value) {
3225
+ this._values[this._totalResolved++] = value;
3226
+ };
3227
+ SomePromiseArray.prototype._canPossiblyFulfill = function() {
3228
+ return this.length() - this._rejected();
3229
+ };
3230
+ SomePromiseArray.prototype._getRangeError = function(count) {
3231
+ return new RangeError("Input array must contain at least " + this._howMany + " items but contains only " + count + " items");
3232
+ };
3233
+ SomePromiseArray.prototype._resolveEmptyArray = function() {
3234
+ this._reject(this._getRangeError(0));
3235
+ };
3236
+ function some(promises, howMany) {
3237
+ if ((howMany | 0) !== howMany || howMany < 0) return apiRejection("expecting a positive integer\n\n See http://goo.gl/MqrFmX\n");
3238
+ var ret = new SomePromiseArray(promises);
3239
+ var promise = ret.promise();
3240
+ ret.setHowMany(howMany);
3241
+ ret.init();
3242
+ return promise;
3243
+ }
3244
+ Promise.some = function(promises, howMany) {
3245
+ return some(promises, howMany);
3246
+ };
3247
+ Promise.prototype.some = function(howMany) {
3248
+ return some(this, howMany);
3249
+ };
3250
+ Promise._SomePromiseArray = SomePromiseArray;
3251
+ };
3252
+ }));
3253
+ var require_timers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3254
+ module.exports = function(Promise, INTERNAL, debug) {
3255
+ var util = require_util();
3256
+ var TimeoutError = Promise.TimeoutError;
3257
+ function HandleWrapper(handle) {
3258
+ this.handle = handle;
3259
+ }
3260
+ HandleWrapper.prototype._resultCancelled = function() {
3261
+ clearTimeout(this.handle);
3262
+ };
3263
+ var afterValue = function(value) {
3264
+ return delay(+this).thenReturn(value);
3265
+ };
3266
+ var delay = Promise.delay = function(ms, value) {
3267
+ var ret;
3268
+ var handle;
3269
+ if (value !== void 0) {
3270
+ ret = Promise.resolve(value)._then(afterValue, null, null, ms, void 0);
3271
+ if (debug.cancellation() && value instanceof Promise) ret._setOnCancel(value);
3272
+ } else {
3273
+ ret = new Promise(INTERNAL);
3274
+ handle = setTimeout(function() {
3275
+ ret._fulfill();
3276
+ }, +ms);
3277
+ if (debug.cancellation()) ret._setOnCancel(new HandleWrapper(handle));
3278
+ ret._captureStackTrace();
3279
+ }
3280
+ ret._setAsyncGuaranteed();
3281
+ return ret;
3282
+ };
3283
+ Promise.prototype.delay = function(ms) {
3284
+ return delay(ms, this);
3285
+ };
3286
+ var afterTimeout = function(promise, message, parent) {
3287
+ var err;
3288
+ if (typeof message !== "string") if (message instanceof Error) err = message;
3289
+ else err = new TimeoutError("operation timed out");
3290
+ else err = new TimeoutError(message);
3291
+ util.markAsOriginatingFromRejection(err);
3292
+ promise._attachExtraTrace(err);
3293
+ promise._reject(err);
3294
+ if (parent != null) parent.cancel();
3295
+ };
3296
+ function successClear(value) {
3297
+ clearTimeout(this.handle);
3298
+ return value;
3299
+ }
3300
+ function failureClear(reason) {
3301
+ clearTimeout(this.handle);
3302
+ throw reason;
3303
+ }
3304
+ Promise.prototype.timeout = function(ms, message) {
3305
+ ms = +ms;
3306
+ var ret, parent;
3307
+ var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() {
3308
+ if (ret.isPending()) afterTimeout(ret, message, parent);
3309
+ }, ms));
3310
+ if (debug.cancellation()) {
3311
+ parent = this.then();
3312
+ ret = parent._then(successClear, failureClear, void 0, handleWrapper, void 0);
3313
+ ret._setOnCancel(handleWrapper);
3314
+ } else ret = this._then(successClear, failureClear, void 0, handleWrapper, void 0);
3315
+ return ret;
3316
+ };
3317
+ };
3318
+ }));
3319
+ var require_using = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3320
+ module.exports = function(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug) {
3321
+ var util = require_util();
3322
+ var TypeError = require_errors().TypeError;
3323
+ var inherits = require_util().inherits;
3324
+ var errorObj = util.errorObj;
3325
+ var tryCatch = util.tryCatch;
3326
+ var NULL = {};
3327
+ function thrower(e) {
3328
+ setTimeout(function() {
3329
+ throw e;
3330
+ }, 0);
3331
+ }
3332
+ function castPreservingDisposable(thenable) {
3333
+ var maybePromise = tryConvertToPromise(thenable);
3334
+ if (maybePromise !== thenable && typeof thenable._isDisposable === "function" && typeof thenable._getDisposer === "function" && thenable._isDisposable()) maybePromise._setDisposable(thenable._getDisposer());
3335
+ return maybePromise;
3336
+ }
3337
+ function dispose(resources, inspection) {
3338
+ var i = 0;
3339
+ var len = resources.length;
3340
+ var ret = new Promise(INTERNAL);
3341
+ function iterator() {
3342
+ if (i >= len) return ret._fulfill();
3343
+ var maybePromise = castPreservingDisposable(resources[i++]);
3344
+ if (maybePromise instanceof Promise && maybePromise._isDisposable()) {
3345
+ try {
3346
+ maybePromise = tryConvertToPromise(maybePromise._getDisposer().tryDispose(inspection), resources.promise);
3347
+ } catch (e) {
3348
+ return thrower(e);
3349
+ }
3350
+ if (maybePromise instanceof Promise) return maybePromise._then(iterator, thrower, null, null, null);
3351
+ }
3352
+ iterator();
3353
+ }
3354
+ iterator();
3355
+ return ret;
3356
+ }
3357
+ function Disposer(data, promise, context) {
3358
+ this._data = data;
3359
+ this._promise = promise;
3360
+ this._context = context;
3361
+ }
3362
+ Disposer.prototype.data = function() {
3363
+ return this._data;
3364
+ };
3365
+ Disposer.prototype.promise = function() {
3366
+ return this._promise;
3367
+ };
3368
+ Disposer.prototype.resource = function() {
3369
+ if (this.promise().isFulfilled()) return this.promise().value();
3370
+ return NULL;
3371
+ };
3372
+ Disposer.prototype.tryDispose = function(inspection) {
3373
+ var resource = this.resource();
3374
+ var context = this._context;
3375
+ if (context !== void 0) context._pushContext();
3376
+ var ret = resource !== NULL ? this.doDispose(resource, inspection) : null;
3377
+ if (context !== void 0) context._popContext();
3378
+ this._promise._unsetDisposable();
3379
+ this._data = null;
3380
+ return ret;
3381
+ };
3382
+ Disposer.isDisposer = function(d) {
3383
+ return d != null && typeof d.resource === "function" && typeof d.tryDispose === "function";
3384
+ };
3385
+ function FunctionDisposer(fn, promise, context) {
3386
+ this.constructor$(fn, promise, context);
3387
+ }
3388
+ inherits(FunctionDisposer, Disposer);
3389
+ FunctionDisposer.prototype.doDispose = function(resource, inspection) {
3390
+ return this.data().call(resource, resource, inspection);
3391
+ };
3392
+ function maybeUnwrapDisposer(value) {
3393
+ if (Disposer.isDisposer(value)) {
3394
+ this.resources[this.index]._setDisposable(value);
3395
+ return value.promise();
3396
+ }
3397
+ return value;
3398
+ }
3399
+ function ResourceList(length) {
3400
+ this.length = length;
3401
+ this.promise = null;
3402
+ this[length - 1] = null;
3403
+ }
3404
+ ResourceList.prototype._resultCancelled = function() {
3405
+ var len = this.length;
3406
+ for (var i = 0; i < len; ++i) {
3407
+ var item = this[i];
3408
+ if (item instanceof Promise) item.cancel();
3409
+ }
3410
+ };
3411
+ Promise.using = function() {
3412
+ var len = arguments.length;
3413
+ if (len < 2) return apiRejection("you must pass at least 2 arguments to Promise.using");
3414
+ var fn = arguments[len - 1];
3415
+ if (typeof fn !== "function") return apiRejection("expecting a function but got " + util.classString(fn));
3416
+ var input;
3417
+ var spreadArgs = true;
3418
+ if (len === 2 && Array.isArray(arguments[0])) {
3419
+ input = arguments[0];
3420
+ len = input.length;
3421
+ spreadArgs = false;
3422
+ } else {
3423
+ input = arguments;
3424
+ len--;
3425
+ }
3426
+ var resources = new ResourceList(len);
3427
+ for (var i = 0; i < len; ++i) {
3428
+ var resource = input[i];
3429
+ if (Disposer.isDisposer(resource)) {
3430
+ var disposer = resource;
3431
+ resource = resource.promise();
3432
+ resource._setDisposable(disposer);
3433
+ } else {
3434
+ var maybePromise = tryConvertToPromise(resource);
3435
+ if (maybePromise instanceof Promise) resource = maybePromise._then(maybeUnwrapDisposer, null, null, {
3436
+ resources,
3437
+ index: i
3438
+ }, void 0);
3439
+ }
3440
+ resources[i] = resource;
3441
+ }
3442
+ var reflectedResources = new Array(resources.length);
3443
+ for (var i = 0; i < reflectedResources.length; ++i) reflectedResources[i] = Promise.resolve(resources[i]).reflect();
3444
+ var resultPromise = Promise.all(reflectedResources).then(function(inspections) {
3445
+ for (var i = 0; i < inspections.length; ++i) {
3446
+ var inspection = inspections[i];
3447
+ if (inspection.isRejected()) {
3448
+ errorObj.e = inspection.error();
3449
+ return errorObj;
3450
+ } else if (!inspection.isFulfilled()) {
3451
+ resultPromise.cancel();
3452
+ return;
3453
+ }
3454
+ inspections[i] = inspection.value();
3455
+ }
3456
+ promise._pushContext();
3457
+ fn = tryCatch(fn);
3458
+ var ret = spreadArgs ? fn.apply(void 0, inspections) : fn(inspections);
3459
+ var promiseCreated = promise._popContext();
3460
+ debug.checkForgottenReturns(ret, promiseCreated, "Promise.using", promise);
3461
+ return ret;
3462
+ });
3463
+ var promise = resultPromise.lastly(function() {
3464
+ return dispose(resources, new Promise.PromiseInspection(resultPromise));
3465
+ });
3466
+ resources.promise = promise;
3467
+ promise._setOnCancel(resources);
3468
+ return promise;
3469
+ };
3470
+ Promise.prototype._setDisposable = function(disposer) {
3471
+ this._bitField = this._bitField | 131072;
3472
+ this._disposer = disposer;
3473
+ };
3474
+ Promise.prototype._isDisposable = function() {
3475
+ return (this._bitField & 131072) > 0;
3476
+ };
3477
+ Promise.prototype._getDisposer = function() {
3478
+ return this._disposer;
3479
+ };
3480
+ Promise.prototype._unsetDisposable = function() {
3481
+ this._bitField = this._bitField & -131073;
3482
+ this._disposer = void 0;
3483
+ };
3484
+ Promise.prototype.disposer = function(fn) {
3485
+ if (typeof fn === "function") return new FunctionDisposer(fn, this, createContext());
3486
+ throw new TypeError();
3487
+ };
3488
+ };
3489
+ }));
3490
+ var require_any = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3491
+ module.exports = function(Promise) {
3492
+ var SomePromiseArray = Promise._SomePromiseArray;
3493
+ function any(promises) {
3494
+ var ret = new SomePromiseArray(promises);
3495
+ var promise = ret.promise();
3496
+ ret.setHowMany(1);
3497
+ ret.setUnwrap();
3498
+ ret.init();
3499
+ return promise;
3500
+ }
3501
+ Promise.any = function(promises) {
3502
+ return any(promises);
3503
+ };
3504
+ Promise.prototype.any = function() {
3505
+ return any(this);
3506
+ };
3507
+ };
3508
+ }));
3509
+ var require_each = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3510
+ module.exports = function(Promise, INTERNAL) {
3511
+ var PromiseReduce = Promise.reduce;
3512
+ var PromiseAll = Promise.all;
3513
+ function promiseAllThis() {
3514
+ return PromiseAll(this);
3515
+ }
3516
+ function PromiseMapSeries(promises, fn) {
3517
+ return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
3518
+ }
3519
+ Promise.prototype.each = function(fn) {
3520
+ return PromiseReduce(this, fn, INTERNAL, 0)._then(promiseAllThis, void 0, void 0, this, void 0);
3521
+ };
3522
+ Promise.prototype.mapSeries = function(fn) {
3523
+ return PromiseReduce(this, fn, INTERNAL, INTERNAL);
3524
+ };
3525
+ Promise.each = function(promises, fn) {
3526
+ return PromiseReduce(promises, fn, INTERNAL, 0)._then(promiseAllThis, void 0, void 0, promises, void 0);
3527
+ };
3528
+ Promise.mapSeries = PromiseMapSeries;
3529
+ };
3530
+ }));
3531
+ var require_filter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3532
+ module.exports = function(Promise, INTERNAL) {
3533
+ var PromiseMap = Promise.map;
3534
+ Promise.prototype.filter = function(fn, options) {
3535
+ return PromiseMap(this, fn, options, INTERNAL);
3536
+ };
3537
+ Promise.filter = function(promises, fn, options) {
3538
+ return PromiseMap(promises, fn, options, INTERNAL);
3539
+ };
3540
+ };
3541
+ }));
3542
+ var require_promise = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3543
+ module.exports = function() {
3544
+ var makeSelfResolutionError = function() {
3545
+ return new TypeError("circular promise resolution chain\n\n See http://goo.gl/MqrFmX\n");
3546
+ };
3547
+ var reflectHandler = function() {
3548
+ return new Promise.PromiseInspection(this._target());
3549
+ };
3550
+ var apiRejection = function(msg) {
3551
+ return Promise.reject(new TypeError(msg));
3552
+ };
3553
+ function Proxyable() {}
3554
+ var UNDEFINED_BINDING = {};
3555
+ var util = require_util();
3556
+ util.setReflectHandler(reflectHandler);
3557
+ var getDomain = function() {
3558
+ var domain = process.domain;
3559
+ if (domain === void 0) return null;
3560
+ return domain;
3561
+ };
3562
+ var getContextDefault = function() {
3563
+ return null;
3564
+ };
3565
+ var getContextDomain = function() {
3566
+ return {
3567
+ domain: getDomain(),
3568
+ async: null
3569
+ };
3570
+ };
3571
+ var AsyncResource = util.isNode && util.nodeSupportsAsyncResource ? __require("async_hooks").AsyncResource : null;
3572
+ var getContextAsyncHooks = function() {
3573
+ return {
3574
+ domain: getDomain(),
3575
+ async: new AsyncResource("Bluebird::Promise")
3576
+ };
3577
+ };
3578
+ var getContext = util.isNode ? getContextDomain : getContextDefault;
3579
+ util.notEnumerableProp(Promise, "_getContext", getContext);
3580
+ var enableAsyncHooks = function() {
3581
+ getContext = getContextAsyncHooks;
3582
+ util.notEnumerableProp(Promise, "_getContext", getContextAsyncHooks);
3583
+ };
3584
+ var disableAsyncHooks = function() {
3585
+ getContext = getContextDomain;
3586
+ util.notEnumerableProp(Promise, "_getContext", getContextDomain);
3587
+ };
3588
+ var es5 = require_es5();
3589
+ var Async = require_async();
3590
+ var async = new Async();
3591
+ es5.defineProperty(Promise, "_async", { value: async });
3592
+ var errors = require_errors();
3593
+ var TypeError = Promise.TypeError = errors.TypeError;
3594
+ Promise.RangeError = errors.RangeError;
3595
+ var CancellationError = Promise.CancellationError = errors.CancellationError;
3596
+ Promise.TimeoutError = errors.TimeoutError;
3597
+ Promise.OperationalError = errors.OperationalError;
3598
+ Promise.RejectionError = errors.OperationalError;
3599
+ Promise.AggregateError = errors.AggregateError;
3600
+ var INTERNAL = function() {};
3601
+ var APPLY = {};
3602
+ var NEXT_FILTER = {};
3603
+ var tryConvertToPromise = require_thenables()(Promise, INTERNAL);
3604
+ var PromiseArray = require_promise_array()(Promise, INTERNAL, tryConvertToPromise, apiRejection, Proxyable);
3605
+ var Context = require_context()(Promise);
3606
+ var createContext = Context.create;
3607
+ var debug = require_debuggability()(Promise, Context, enableAsyncHooks, disableAsyncHooks);
3608
+ debug.CapturedTrace;
3609
+ var PassThroughHandlerContext = require_finally()(Promise, tryConvertToPromise, NEXT_FILTER);
3610
+ var catchFilter = require_catch_filter()(NEXT_FILTER);
3611
+ var nodebackForPromise = require_nodeback();
3612
+ var errorObj = util.errorObj;
3613
+ var tryCatch = util.tryCatch;
3614
+ function check(self, executor) {
3615
+ if (self == null || self.constructor !== Promise) throw new TypeError("the promise constructor cannot be invoked directly\n\n See http://goo.gl/MqrFmX\n");
3616
+ if (typeof executor !== "function") throw new TypeError("expecting a function but got " + util.classString(executor));
3617
+ }
3618
+ function Promise(executor) {
3619
+ if (executor !== INTERNAL) check(this, executor);
3620
+ this._bitField = 0;
3621
+ this._fulfillmentHandler0 = void 0;
3622
+ this._rejectionHandler0 = void 0;
3623
+ this._promise0 = void 0;
3624
+ this._receiver0 = void 0;
3625
+ this._resolveFromExecutor(executor);
3626
+ this._promiseCreated();
3627
+ this._fireEvent("promiseCreated", this);
3628
+ }
3629
+ Promise.prototype.toString = function() {
3630
+ return "[object Promise]";
3631
+ };
3632
+ Promise.prototype.caught = Promise.prototype["catch"] = function(fn) {
3633
+ var len = arguments.length;
3634
+ if (len > 1) {
3635
+ var catchInstances = new Array(len - 1), j = 0, i;
3636
+ for (i = 0; i < len - 1; ++i) {
3637
+ var item = arguments[i];
3638
+ if (util.isObject(item)) catchInstances[j++] = item;
3639
+ else return apiRejection("Catch statement predicate: expecting an object but got " + util.classString(item));
3640
+ }
3641
+ catchInstances.length = j;
3642
+ fn = arguments[i];
3643
+ if (typeof fn !== "function") throw new TypeError("The last argument to .catch() must be a function, got " + util.toString(fn));
3644
+ return this.then(void 0, catchFilter(catchInstances, fn, this));
3645
+ }
3646
+ return this.then(void 0, fn);
3647
+ };
3648
+ Promise.prototype.reflect = function() {
3649
+ return this._then(reflectHandler, reflectHandler, void 0, this, void 0);
3650
+ };
3651
+ Promise.prototype.then = function(didFulfill, didReject) {
3652
+ if (debug.warnings() && arguments.length > 0 && typeof didFulfill !== "function" && typeof didReject !== "function") {
3653
+ var msg = ".then() only accepts functions but was passed: " + util.classString(didFulfill);
3654
+ if (arguments.length > 1) msg += ", " + util.classString(didReject);
3655
+ this._warn(msg);
3656
+ }
3657
+ return this._then(didFulfill, didReject, void 0, void 0, void 0);
3658
+ };
3659
+ Promise.prototype.done = function(didFulfill, didReject) {
3660
+ this._then(didFulfill, didReject, void 0, void 0, void 0)._setIsFinal();
3661
+ };
3662
+ Promise.prototype.spread = function(fn) {
3663
+ if (typeof fn !== "function") return apiRejection("expecting a function but got " + util.classString(fn));
3664
+ return this.all()._then(fn, void 0, void 0, APPLY, void 0);
3665
+ };
3666
+ Promise.prototype.toJSON = function() {
3667
+ var ret = {
3668
+ isFulfilled: false,
3669
+ isRejected: false,
3670
+ fulfillmentValue: void 0,
3671
+ rejectionReason: void 0
3672
+ };
3673
+ if (this.isFulfilled()) {
3674
+ ret.fulfillmentValue = this.value();
3675
+ ret.isFulfilled = true;
3676
+ } else if (this.isRejected()) {
3677
+ ret.rejectionReason = this.reason();
3678
+ ret.isRejected = true;
3679
+ }
3680
+ return ret;
3681
+ };
3682
+ Promise.prototype.all = function() {
3683
+ if (arguments.length > 0) this._warn(".all() was passed arguments but it does not take any");
3684
+ return new PromiseArray(this).promise();
3685
+ };
3686
+ Promise.prototype.error = function(fn) {
3687
+ return this.caught(util.originatesFromRejection, fn);
3688
+ };
3689
+ Promise.getNewLibraryCopy = module.exports;
3690
+ Promise.is = function(val) {
3691
+ return val instanceof Promise;
3692
+ };
3693
+ Promise.fromNode = Promise.fromCallback = function(fn) {
3694
+ var ret = new Promise(INTERNAL);
3695
+ ret._captureStackTrace();
3696
+ var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs : false;
3697
+ var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
3698
+ if (result === errorObj) ret._rejectCallback(result.e, true);
3699
+ if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
3700
+ return ret;
3701
+ };
3702
+ Promise.all = function(promises) {
3703
+ return new PromiseArray(promises).promise();
3704
+ };
3705
+ Promise.cast = function(obj) {
3706
+ var ret = tryConvertToPromise(obj);
3707
+ if (!(ret instanceof Promise)) {
3708
+ ret = new Promise(INTERNAL);
3709
+ ret._captureStackTrace();
3710
+ ret._setFulfilled();
3711
+ ret._rejectionHandler0 = obj;
3712
+ }
3713
+ return ret;
3714
+ };
3715
+ Promise.resolve = Promise.fulfilled = Promise.cast;
3716
+ Promise.reject = Promise.rejected = function(reason) {
3717
+ var ret = new Promise(INTERNAL);
3718
+ ret._captureStackTrace();
3719
+ ret._rejectCallback(reason, true);
3720
+ return ret;
3721
+ };
3722
+ Promise.setScheduler = function(fn) {
3723
+ if (typeof fn !== "function") throw new TypeError("expecting a function but got " + util.classString(fn));
3724
+ return async.setScheduler(fn);
3725
+ };
3726
+ Promise.prototype._then = function(didFulfill, didReject, _, receiver, internalData) {
3727
+ var haveInternalData = internalData !== void 0;
3728
+ var promise = haveInternalData ? internalData : new Promise(INTERNAL);
3729
+ var target = this._target();
3730
+ var bitField = target._bitField;
3731
+ if (!haveInternalData) {
3732
+ promise._propagateFrom(this, 3);
3733
+ promise._captureStackTrace();
3734
+ if (receiver === void 0 && (this._bitField & 2097152) !== 0) if (!((bitField & 50397184) === 0)) receiver = this._boundValue();
3735
+ else receiver = target === this ? void 0 : this._boundTo;
3736
+ this._fireEvent("promiseChained", this, promise);
3737
+ }
3738
+ var context = getContext();
3739
+ if (!((bitField & 50397184) === 0)) {
3740
+ var handler, value, settler = target._settlePromiseCtx;
3741
+ if ((bitField & 33554432) !== 0) {
3742
+ value = target._rejectionHandler0;
3743
+ handler = didFulfill;
3744
+ } else if ((bitField & 16777216) !== 0) {
3745
+ value = target._fulfillmentHandler0;
3746
+ handler = didReject;
3747
+ target._unsetRejectionIsUnhandled();
3748
+ } else {
3749
+ settler = target._settlePromiseLateCancellationObserver;
3750
+ value = new CancellationError("late cancellation observer");
3751
+ target._attachExtraTrace(value);
3752
+ handler = didReject;
3753
+ }
3754
+ async.invoke(settler, target, {
3755
+ handler: util.contextBind(context, handler),
3756
+ promise,
3757
+ receiver,
3758
+ value
3759
+ });
3760
+ } else target._addCallbacks(didFulfill, didReject, promise, receiver, context);
3761
+ return promise;
3762
+ };
3763
+ Promise.prototype._length = function() {
3764
+ return this._bitField & 65535;
3765
+ };
3766
+ Promise.prototype._isFateSealed = function() {
3767
+ return (this._bitField & 117506048) !== 0;
3768
+ };
3769
+ Promise.prototype._isFollowing = function() {
3770
+ return (this._bitField & 67108864) === 67108864;
3771
+ };
3772
+ Promise.prototype._setLength = function(len) {
3773
+ this._bitField = this._bitField & -65536 | len & 65535;
3774
+ };
3775
+ Promise.prototype._setFulfilled = function() {
3776
+ this._bitField = this._bitField | 33554432;
3777
+ this._fireEvent("promiseFulfilled", this);
3778
+ };
3779
+ Promise.prototype._setRejected = function() {
3780
+ this._bitField = this._bitField | 16777216;
3781
+ this._fireEvent("promiseRejected", this);
3782
+ };
3783
+ Promise.prototype._setFollowing = function() {
3784
+ this._bitField = this._bitField | 67108864;
3785
+ this._fireEvent("promiseResolved", this);
3786
+ };
3787
+ Promise.prototype._setIsFinal = function() {
3788
+ this._bitField = this._bitField | 4194304;
3789
+ };
3790
+ Promise.prototype._isFinal = function() {
3791
+ return (this._bitField & 4194304) > 0;
3792
+ };
3793
+ Promise.prototype._unsetCancelled = function() {
3794
+ this._bitField = this._bitField & -65537;
3795
+ };
3796
+ Promise.prototype._setCancelled = function() {
3797
+ this._bitField = this._bitField | 65536;
3798
+ this._fireEvent("promiseCancelled", this);
3799
+ };
3800
+ Promise.prototype._setWillBeCancelled = function() {
3801
+ this._bitField = this._bitField | 8388608;
3802
+ };
3803
+ Promise.prototype._setAsyncGuaranteed = function() {
3804
+ if (async.hasCustomScheduler()) return;
3805
+ var bitField = this._bitField;
3806
+ this._bitField = bitField | (bitField & 536870912) >> 2 ^ 134217728;
3807
+ };
3808
+ Promise.prototype._setNoAsyncGuarantee = function() {
3809
+ this._bitField = (this._bitField | 536870912) & -134217729;
3810
+ };
3811
+ Promise.prototype._receiverAt = function(index) {
3812
+ var ret = index === 0 ? this._receiver0 : this[index * 4 - 4 + 3];
3813
+ if (ret === UNDEFINED_BINDING) return;
3814
+ else if (ret === void 0 && this._isBound()) return this._boundValue();
3815
+ return ret;
3816
+ };
3817
+ Promise.prototype._promiseAt = function(index) {
3818
+ return this[index * 4 - 4 + 2];
3819
+ };
3820
+ Promise.prototype._fulfillmentHandlerAt = function(index) {
3821
+ return this[index * 4 - 4 + 0];
3822
+ };
3823
+ Promise.prototype._rejectionHandlerAt = function(index) {
3824
+ return this[index * 4 - 4 + 1];
3825
+ };
3826
+ Promise.prototype._boundValue = function() {};
3827
+ Promise.prototype._migrateCallback0 = function(follower) {
3828
+ follower._bitField;
3829
+ var fulfill = follower._fulfillmentHandler0;
3830
+ var reject = follower._rejectionHandler0;
3831
+ var promise = follower._promise0;
3832
+ var receiver = follower._receiverAt(0);
3833
+ if (receiver === void 0) receiver = UNDEFINED_BINDING;
3834
+ this._addCallbacks(fulfill, reject, promise, receiver, null);
3835
+ };
3836
+ Promise.prototype._migrateCallbackAt = function(follower, index) {
3837
+ var fulfill = follower._fulfillmentHandlerAt(index);
3838
+ var reject = follower._rejectionHandlerAt(index);
3839
+ var promise = follower._promiseAt(index);
3840
+ var receiver = follower._receiverAt(index);
3841
+ if (receiver === void 0) receiver = UNDEFINED_BINDING;
3842
+ this._addCallbacks(fulfill, reject, promise, receiver, null);
3843
+ };
3844
+ Promise.prototype._addCallbacks = function(fulfill, reject, promise, receiver, context) {
3845
+ var index = this._length();
3846
+ if (index >= 65531) {
3847
+ index = 0;
3848
+ this._setLength(0);
3849
+ }
3850
+ if (index === 0) {
3851
+ this._promise0 = promise;
3852
+ this._receiver0 = receiver;
3853
+ if (typeof fulfill === "function") this._fulfillmentHandler0 = util.contextBind(context, fulfill);
3854
+ if (typeof reject === "function") this._rejectionHandler0 = util.contextBind(context, reject);
3855
+ } else {
3856
+ var base = index * 4 - 4;
3857
+ this[base + 2] = promise;
3858
+ this[base + 3] = receiver;
3859
+ if (typeof fulfill === "function") this[base + 0] = util.contextBind(context, fulfill);
3860
+ if (typeof reject === "function") this[base + 1] = util.contextBind(context, reject);
3861
+ }
3862
+ this._setLength(index + 1);
3863
+ return index;
3864
+ };
3865
+ Promise.prototype._proxy = function(proxyable, arg) {
3866
+ this._addCallbacks(void 0, void 0, arg, proxyable, null);
3867
+ };
3868
+ Promise.prototype._resolveCallback = function(value, shouldBind) {
3869
+ if ((this._bitField & 117506048) !== 0) return;
3870
+ if (value === this) return this._rejectCallback(makeSelfResolutionError(), false);
3871
+ var maybePromise = tryConvertToPromise(value, this);
3872
+ if (!(maybePromise instanceof Promise)) return this._fulfill(value);
3873
+ if (shouldBind) this._propagateFrom(maybePromise, 2);
3874
+ var promise = maybePromise._target();
3875
+ if (promise === this) {
3876
+ this._reject(makeSelfResolutionError());
3877
+ return;
3878
+ }
3879
+ var bitField = promise._bitField;
3880
+ if ((bitField & 50397184) === 0) {
3881
+ var len = this._length();
3882
+ if (len > 0) promise._migrateCallback0(this);
3883
+ for (var i = 1; i < len; ++i) promise._migrateCallbackAt(this, i);
3884
+ this._setFollowing();
3885
+ this._setLength(0);
3886
+ this._setFollowee(maybePromise);
3887
+ } else if ((bitField & 33554432) !== 0) this._fulfill(promise._value());
3888
+ else if ((bitField & 16777216) !== 0) this._reject(promise._reason());
3889
+ else {
3890
+ var reason = new CancellationError("late cancellation observer");
3891
+ promise._attachExtraTrace(reason);
3892
+ this._reject(reason);
3893
+ }
3894
+ };
3895
+ Promise.prototype._rejectCallback = function(reason, synchronous, ignoreNonErrorWarnings) {
3896
+ var trace = util.ensureErrorObject(reason);
3897
+ var hasStack = trace === reason;
3898
+ if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
3899
+ var message = "a promise was rejected with a non-error: " + util.classString(reason);
3900
+ this._warn(message, true);
3901
+ }
3902
+ this._attachExtraTrace(trace, synchronous ? hasStack : false);
3903
+ this._reject(reason);
3904
+ };
3905
+ Promise.prototype._resolveFromExecutor = function(executor) {
3906
+ if (executor === INTERNAL) return;
3907
+ var promise = this;
3908
+ this._captureStackTrace();
3909
+ this._pushContext();
3910
+ var synchronous = true;
3911
+ var r = this._execute(executor, function(value) {
3912
+ promise._resolveCallback(value);
3913
+ }, function(reason) {
3914
+ promise._rejectCallback(reason, synchronous);
3915
+ });
3916
+ synchronous = false;
3917
+ this._popContext();
3918
+ if (r !== void 0) promise._rejectCallback(r, true);
3919
+ };
3920
+ Promise.prototype._settlePromiseFromHandler = function(handler, receiver, value, promise) {
3921
+ var bitField = promise._bitField;
3922
+ if ((bitField & 65536) !== 0) return;
3923
+ promise._pushContext();
3924
+ var x;
3925
+ if (receiver === APPLY) if (!value || typeof value.length !== "number") {
3926
+ x = errorObj;
3927
+ x.e = new TypeError("cannot .spread() a non-array: " + util.classString(value));
3928
+ } else x = tryCatch(handler).apply(this._boundValue(), value);
3929
+ else x = tryCatch(handler).call(receiver, value);
3930
+ var promiseCreated = promise._popContext();
3931
+ bitField = promise._bitField;
3932
+ if ((bitField & 65536) !== 0) return;
3933
+ if (x === NEXT_FILTER) promise._reject(value);
3934
+ else if (x === errorObj) promise._rejectCallback(x.e, false);
3935
+ else {
3936
+ debug.checkForgottenReturns(x, promiseCreated, "", promise, this);
3937
+ promise._resolveCallback(x);
3938
+ }
3939
+ };
3940
+ Promise.prototype._target = function() {
3941
+ var ret = this;
3942
+ while (ret._isFollowing()) ret = ret._followee();
3943
+ return ret;
3944
+ };
3945
+ Promise.prototype._followee = function() {
3946
+ return this._rejectionHandler0;
3947
+ };
3948
+ Promise.prototype._setFollowee = function(promise) {
3949
+ this._rejectionHandler0 = promise;
3950
+ };
3951
+ Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
3952
+ var isPromise = promise instanceof Promise;
3953
+ var bitField = this._bitField;
3954
+ var asyncGuaranteed = (bitField & 134217728) !== 0;
3955
+ if ((bitField & 65536) !== 0) {
3956
+ if (isPromise) promise._invokeInternalOnCancel();
3957
+ if (receiver instanceof PassThroughHandlerContext && receiver.isFinallyHandler()) {
3958
+ receiver.cancelPromise = promise;
3959
+ if (tryCatch(handler).call(receiver, value) === errorObj) promise._reject(errorObj.e);
3960
+ } else if (handler === reflectHandler) promise._fulfill(reflectHandler.call(receiver));
3961
+ else if (receiver instanceof Proxyable) receiver._promiseCancelled(promise);
3962
+ else if (isPromise || promise instanceof PromiseArray) promise._cancel();
3963
+ else receiver.cancel();
3964
+ } else if (typeof handler === "function") if (!isPromise) handler.call(receiver, value, promise);
3965
+ else {
3966
+ if (asyncGuaranteed) promise._setAsyncGuaranteed();
3967
+ this._settlePromiseFromHandler(handler, receiver, value, promise);
3968
+ }
3969
+ else if (receiver instanceof Proxyable) {
3970
+ if (!receiver._isResolved()) if ((bitField & 33554432) !== 0) receiver._promiseFulfilled(value, promise);
3971
+ else receiver._promiseRejected(value, promise);
3972
+ } else if (isPromise) {
3973
+ if (asyncGuaranteed) promise._setAsyncGuaranteed();
3974
+ if ((bitField & 33554432) !== 0) promise._fulfill(value);
3975
+ else promise._reject(value);
3976
+ }
3977
+ };
3978
+ Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
3979
+ var handler = ctx.handler;
3980
+ var promise = ctx.promise;
3981
+ var receiver = ctx.receiver;
3982
+ var value = ctx.value;
3983
+ if (typeof handler === "function") if (!(promise instanceof Promise)) handler.call(receiver, value, promise);
3984
+ else this._settlePromiseFromHandler(handler, receiver, value, promise);
3985
+ else if (promise instanceof Promise) promise._reject(value);
3986
+ };
3987
+ Promise.prototype._settlePromiseCtx = function(ctx) {
3988
+ this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
3989
+ };
3990
+ Promise.prototype._settlePromise0 = function(handler, value, bitField) {
3991
+ var promise = this._promise0;
3992
+ var receiver = this._receiverAt(0);
3993
+ this._promise0 = void 0;
3994
+ this._receiver0 = void 0;
3995
+ this._settlePromise(promise, handler, receiver, value);
3996
+ };
3997
+ Promise.prototype._clearCallbackDataAtIndex = function(index) {
3998
+ var base = index * 4 - 4;
3999
+ this[base + 2] = this[base + 3] = this[base + 0] = this[base + 1] = void 0;
4000
+ };
4001
+ Promise.prototype._fulfill = function(value) {
4002
+ var bitField = this._bitField;
4003
+ if ((bitField & 117506048) >>> 16) return;
4004
+ if (value === this) {
4005
+ var err = makeSelfResolutionError();
4006
+ this._attachExtraTrace(err);
4007
+ return this._reject(err);
4008
+ }
4009
+ this._setFulfilled();
4010
+ this._rejectionHandler0 = value;
4011
+ if ((bitField & 65535) > 0) {
4012
+ if ((bitField & 134217728) !== 0) this._settlePromises();
4013
+ else async.settlePromises(this);
4014
+ this._dereferenceTrace();
4015
+ }
4016
+ };
4017
+ Promise.prototype._reject = function(reason) {
4018
+ var bitField = this._bitField;
4019
+ if ((bitField & 117506048) >>> 16) return;
4020
+ this._setRejected();
4021
+ this._fulfillmentHandler0 = reason;
4022
+ if (this._isFinal()) return async.fatalError(reason, util.isNode);
4023
+ if ((bitField & 65535) > 0) async.settlePromises(this);
4024
+ else this._ensurePossibleRejectionHandled();
4025
+ };
4026
+ Promise.prototype._fulfillPromises = function(len, value) {
4027
+ for (var i = 1; i < len; i++) {
4028
+ var handler = this._fulfillmentHandlerAt(i);
4029
+ var promise = this._promiseAt(i);
4030
+ var receiver = this._receiverAt(i);
4031
+ this._clearCallbackDataAtIndex(i);
4032
+ this._settlePromise(promise, handler, receiver, value);
4033
+ }
4034
+ };
4035
+ Promise.prototype._rejectPromises = function(len, reason) {
4036
+ for (var i = 1; i < len; i++) {
4037
+ var handler = this._rejectionHandlerAt(i);
4038
+ var promise = this._promiseAt(i);
4039
+ var receiver = this._receiverAt(i);
4040
+ this._clearCallbackDataAtIndex(i);
4041
+ this._settlePromise(promise, handler, receiver, reason);
4042
+ }
4043
+ };
4044
+ Promise.prototype._settlePromises = function() {
4045
+ var bitField = this._bitField;
4046
+ var len = bitField & 65535;
4047
+ if (len > 0) {
4048
+ if ((bitField & 16842752) !== 0) {
4049
+ var reason = this._fulfillmentHandler0;
4050
+ this._settlePromise0(this._rejectionHandler0, reason, bitField);
4051
+ this._rejectPromises(len, reason);
4052
+ } else {
4053
+ var value = this._rejectionHandler0;
4054
+ this._settlePromise0(this._fulfillmentHandler0, value, bitField);
4055
+ this._fulfillPromises(len, value);
4056
+ }
4057
+ this._setLength(0);
4058
+ }
4059
+ this._clearCancellationData();
4060
+ };
4061
+ Promise.prototype._settledValue = function() {
4062
+ var bitField = this._bitField;
4063
+ if ((bitField & 33554432) !== 0) return this._rejectionHandler0;
4064
+ else if ((bitField & 16777216) !== 0) return this._fulfillmentHandler0;
4065
+ };
4066
+ if (typeof Symbol !== "undefined" && Symbol.toStringTag) es5.defineProperty(Promise.prototype, Symbol.toStringTag, { get: function() {
4067
+ return "Object";
4068
+ } });
4069
+ function deferResolve(v) {
4070
+ this.promise._resolveCallback(v);
4071
+ }
4072
+ function deferReject(v) {
4073
+ this.promise._rejectCallback(v, false);
4074
+ }
4075
+ Promise.defer = Promise.pending = function() {
4076
+ debug.deprecated("Promise.defer", "new Promise");
4077
+ return {
4078
+ promise: new Promise(INTERNAL),
4079
+ resolve: deferResolve,
4080
+ reject: deferReject
4081
+ };
4082
+ };
4083
+ util.notEnumerableProp(Promise, "_makeSelfResolutionError", makeSelfResolutionError);
4084
+ require_method()(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug);
4085
+ require_bind()(Promise, INTERNAL, tryConvertToPromise, debug);
4086
+ require_cancel()(Promise, PromiseArray, apiRejection, debug);
4087
+ require_direct_resolve()(Promise);
4088
+ require_synchronous_inspection()(Promise);
4089
+ require_join()(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async);
4090
+ Promise.Promise = Promise;
4091
+ Promise.version = "3.7.2";
4092
+ require_call_get()(Promise);
4093
+ require_generators()(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
4094
+ require_map()(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
4095
+ require_nodeify()(Promise);
4096
+ require_promisify()(Promise, INTERNAL);
4097
+ require_props()(Promise, PromiseArray, tryConvertToPromise, apiRejection);
4098
+ require_race()(Promise, INTERNAL, tryConvertToPromise, apiRejection);
4099
+ require_reduce()(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
4100
+ require_settle()(Promise, PromiseArray, debug);
4101
+ require_some()(Promise, PromiseArray, apiRejection);
4102
+ require_timers()(Promise, INTERNAL, debug);
4103
+ require_using()(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
4104
+ require_any()(Promise);
4105
+ require_each()(Promise, INTERNAL);
4106
+ require_filter()(Promise, INTERNAL);
4107
+ util.toFastProperties(Promise);
4108
+ util.toFastProperties(Promise.prototype);
4109
+ function fillTypes(value) {
4110
+ var p = new Promise(INTERNAL);
4111
+ p._fulfillmentHandler0 = value;
4112
+ p._rejectionHandler0 = value;
4113
+ p._promise0 = value;
4114
+ p._receiver0 = value;
4115
+ }
4116
+ fillTypes({ a: 1 });
4117
+ fillTypes({ b: 2 });
4118
+ fillTypes({ c: 3 });
4119
+ fillTypes(1);
4120
+ fillTypes(function() {});
4121
+ fillTypes(void 0);
4122
+ fillTypes(false);
4123
+ fillTypes(new Promise(INTERNAL));
4124
+ debug.setBounds(Async.firstLineError, util.lastLineError);
4125
+ return Promise;
4126
+ };
4127
+ }));
4128
+ var require_bluebird = /* @__PURE__ */ __commonJSMin(((exports, module) => {
4129
+ var old;
4130
+ if (typeof Promise !== "undefined") old = Promise;
4131
+ function noConflict() {
4132
+ try {
4133
+ if (Promise === bluebird) Promise = old;
4134
+ } catch (e) {}
4135
+ return bluebird;
4136
+ }
4137
+ var bluebird = require_promise()();
4138
+ bluebird.noConflict = noConflict;
4139
+ module.exports = bluebird;
4140
+ }));
4141
+ export { require_bluebird as t };