xaa 1.7.3 → 2.0.0

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.
@@ -7,11 +7,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.wrap = exports.try = exports.tryCatch = exports.filter = exports.each = exports.map = exports.runTimeout = exports.timeout = exports.TimeoutRunner = exports.delay = exports.TimeoutError = exports.defer = exports.makeDefer = exports.Defer = void 0;
11
- /* eslint-disable max-statements, @typescript-eslint/ban-types */
10
+ exports.TimeoutRunner = exports.TimeoutError = exports.Defer = void 0;
11
+ exports.isPromise = isPromise;
12
+ exports.makeDefer = makeDefer;
13
+ exports.defer = makeDefer;
14
+ exports.delay = delay;
15
+ exports.timeout = timeout;
16
+ exports.runTimeout = runTimeout;
17
+ exports.mapSeries = mapSeries;
18
+ exports.map = map;
19
+ exports.each = each;
20
+ exports.filter = filter;
21
+ exports.tryCatch = tryCatch;
22
+ exports.try = tryCatch;
23
+ exports.wrap = wrap;
24
+ /* eslint-disable max-statements, @typescript-eslint/ban-types, max-params, complexity */
12
25
  const assert_1 = __importDefault(require("assert"));
13
- const util_1 = require("util");
14
- const setTimeoutPromise = (0, util_1.promisify)(setTimeout);
15
26
  /**
16
27
  * check if something is a promise
17
28
  *
@@ -19,7 +30,7 @@ const setTimeoutPromise = (0, util_1.promisify)(setTimeout);
19
30
  * @returns true or false
20
31
  */
21
32
  function isPromise(p) {
22
- return p && p.then && p.catch;
33
+ return p && p.then && p.catch && typeof p.then === "function" && typeof p.catch === "function";
23
34
  }
24
35
  /**
25
36
  * Defer object for fulfilling a promise later in other events
@@ -63,14 +74,12 @@ exports.Defer = Defer;
63
74
  * }
64
75
  * ```
65
76
  *
66
- * @param Promise - optional Promise constructor.
77
+ * @param ThePromise - optional Promise constructor.
67
78
  * @returns Defer instance
68
79
  */
69
- function makeDefer(Promise = global.Promise) {
70
- return new Defer(Promise);
80
+ function makeDefer(ThePromise = global.Promise) {
81
+ return new Defer(ThePromise);
71
82
  }
72
- exports.makeDefer = makeDefer;
73
- exports.defer = makeDefer;
74
83
  /**
75
84
  * The error xaa.timeout will throw if operation timed out
76
85
  */
@@ -83,21 +92,28 @@ class TimeoutError extends Error {
83
92
  }
84
93
  exports.TimeoutError = TimeoutError;
85
94
  async function delay(delayMs, valOrFunc) {
86
- await setTimeoutPromise(delayMs);
95
+ await new Promise(resolve => setTimeout(resolve, delayMs));
87
96
  return typeof valOrFunc === "function" ? /* lazily */ valOrFunc() : valOrFunc;
88
97
  }
89
- exports.delay = delay;
90
98
  /**
91
99
  * TimeoutRunner for running tasks (promises) with a timeout
92
100
  *
93
101
  * Please use `xaa.timeout` or `xaa.runTimeout` APIs instead.
94
102
  */
95
103
  class TimeoutRunner {
96
- constructor(maxMs, rejectMsg) {
104
+ /**
105
+ * constructor
106
+ * @param maxMs - number of milliseconds to allow tasks to run
107
+ * @param rejectMsg - message to reject with when timeout triggers
108
+ * @param options - TimeoutRunnerOptions
109
+ */
110
+ constructor(maxMs, rejectMsg, options) {
97
111
  this.maxMs = maxMs;
98
112
  this.rejectMsg = rejectMsg;
99
- this.defer = makeDefer();
100
- this.timeout = setTimeout(() => this.defer.reject(new TimeoutError(rejectMsg)), maxMs);
113
+ this.defer = makeDefer(options.Promise);
114
+ this.ThePromise = options.Promise;
115
+ this.TimeoutError = options.TimeoutError;
116
+ this.timeout = setTimeout(() => this.defer.reject(new this.TimeoutError(rejectMsg)), maxMs);
101
117
  }
102
118
  /**
103
119
  * check if runner has failed with error
@@ -126,9 +142,9 @@ class TimeoutRunner {
126
142
  // Cast below is due in part to https://github.com/microsoft/TypeScript/issues/17002
127
143
  const arrTasks = !Array.isArray(tasks)
128
144
  ? process(tasks)
129
- : Promise.all(tasks.map(process));
145
+ : this.ThePromise.all(tasks.map(process));
130
146
  try {
131
- const r = await Promise.race([arrTasks, this.defer.promise]);
147
+ const r = await this.ThePromise.race([arrTasks, this.defer.promise]);
132
148
  this.clear();
133
149
  this.result = r;
134
150
  return r;
@@ -146,7 +162,7 @@ class TimeoutRunner {
146
162
  */
147
163
  cancel(msg = "xaa TimeoutRunner operation cancelled") {
148
164
  this.clear();
149
- this.defer.reject(new TimeoutError(msg));
165
+ this.defer.reject(new this.TimeoutError(msg));
150
166
  }
151
167
  /** Explicitly clear the setTimeout handle */
152
168
  clear() {
@@ -184,14 +200,12 @@ exports.TimeoutRunner = TimeoutRunner;
184
200
  * @param rejectMsg - message to reject with when timeout triggers
185
201
  * @returns TimeoutRunner object
186
202
  */
187
- function timeout(maxMs, rejectMsg = "xaa TimeoutRunner operation timed out") {
188
- return new TimeoutRunner(maxMs, rejectMsg);
203
+ function timeout(maxMs, rejectMsg = "xaa TimeoutRunner operation timed out", options = { TimeoutError: TimeoutError, Promise: global.Promise }) {
204
+ return new TimeoutRunner(maxMs, rejectMsg, options);
189
205
  }
190
- exports.timeout = timeout;
191
- async function runTimeout(tasks, maxMs, rejectMsg) {
192
- return await timeout(maxMs, rejectMsg).run(tasks);
206
+ async function runTimeout(tasks, maxMs, rejectMsg, options) {
207
+ return await timeout(maxMs, rejectMsg, options).run(tasks);
193
208
  }
194
- exports.runTimeout = runTimeout;
195
209
  /**
196
210
  * create map context
197
211
  *
@@ -225,6 +239,10 @@ function multiMap(array, func, options) {
225
239
  let completedCount = 0;
226
240
  let freeSlots = options.concurrency;
227
241
  let index = 0;
242
+ const iterator = Symbol.iterator in array && typeof array[Symbol.iterator] === "function"
243
+ ? array[Symbol.iterator]()
244
+ : null;
245
+ let totalCount = iterator ? Infinity : array.length;
228
246
  const context = createMapContext(array);
229
247
  const defer = makeDefer();
230
248
  const fail = (err) => {
@@ -238,10 +256,19 @@ function multiMap(array, func, options) {
238
256
  const mapNext = () => {
239
257
  // important to check this here, so an empty input array immediately
240
258
  // gets resolved with an empty result.
241
- if (!error && completedCount === array.length) {
259
+ if (!error && completedCount === totalCount) {
242
260
  return defer.resolve(awaited);
243
261
  }
244
- if (error || freeSlots <= 0 || index >= array.length) {
262
+ if (error || freeSlots <= 0 || index >= totalCount) {
263
+ return null;
264
+ }
265
+ const ir = iterator && iterator.next();
266
+ /* c8 ignore next 7 */
267
+ if (ir && ir.done) {
268
+ if (totalCount !== index) {
269
+ totalCount = index;
270
+ return mapNext();
271
+ }
245
272
  return null;
246
273
  }
247
274
  freeSlots--;
@@ -261,7 +288,7 @@ function multiMap(array, func, options) {
261
288
  return save(res);
262
289
  }
263
290
  };
264
- const item = array[pendingIx];
291
+ const item = ir ? ir.value : array[pendingIx];
265
292
  if (isPromise(item)) {
266
293
  return item.then(val => {
267
294
  return handleRet(func.call(options.thisArg, val, pendingIx, context));
@@ -287,6 +314,24 @@ function multiMap(array, func, options) {
287
314
  mapNext();
288
315
  return defer.promise;
289
316
  }
317
+ async function mapSeries(array, func, options) {
318
+ const awaited = new Array();
319
+ const context = createMapContext(array);
320
+ let i = 0;
321
+ try {
322
+ for (const element of array) {
323
+ const item = isPromise(element) ? await element : element;
324
+ awaited[i] = await func.call(options && options.thisArg, item, i, context);
325
+ i++;
326
+ }
327
+ }
328
+ catch (err) {
329
+ context.failed = true;
330
+ err.partial = awaited;
331
+ throw err;
332
+ }
333
+ return awaited;
334
+ }
290
335
  /**
291
336
  * async map array with concurrency
292
337
  *
@@ -297,35 +342,15 @@ function multiMap(array, func, options) {
297
342
  * @param options - MapOptions
298
343
  * @returns promise with mapped result
299
344
  */
300
- async function map(array, func, options = { concurrency: 1 }) {
345
+ async function map(array, func, options = { concurrency: 50 }) {
301
346
  (0, assert_1.default)(Array.isArray(array), `xaa.map expecting an array but got ${typeof array}`);
302
- if (array.length < 1) {
303
- return [];
304
- }
305
347
  if (options.concurrency > 1) {
306
348
  return multiMap(array, func, options);
307
349
  }
308
350
  else {
309
- const awaited = new Array(array.length);
310
- const context = createMapContext(array);
311
- for (let i = 0; i < array.length; i++) {
312
- try {
313
- let item = array[i];
314
- if (isPromise(item)) {
315
- item = await item;
316
- }
317
- awaited[i] = await func.call(options.thisArg, item, i, context);
318
- }
319
- catch (err) {
320
- context.failed = true;
321
- err.partial = awaited;
322
- throw err;
323
- }
324
- }
325
- return awaited;
351
+ return mapSeries(array, func, options);
326
352
  }
327
353
  }
328
- exports.map = map;
329
354
  /**
330
355
  * async version of array.forEach
331
356
  * - iterate through array and await call func with each element and index
@@ -340,11 +365,16 @@ exports.map = map;
340
365
  * @param func callback for each
341
366
  */
342
367
  async function each(array, func) {
343
- for (let i = 0; i < array.length; i++) {
344
- await func(array[i], i);
368
+ let i = 0;
369
+ const items = [];
370
+ for (const element of array) {
371
+ const item = isPromise(element) ? await element : element;
372
+ items.push(item);
373
+ await func(item, i);
374
+ i++;
345
375
  }
376
+ return items;
346
377
  }
347
- exports.each = each;
348
378
  /**
349
379
  * async filter array
350
380
  *
@@ -369,7 +399,6 @@ async function filter(array, func) {
369
399
  }
370
400
  return filtered;
371
401
  }
372
- exports.filter = filter;
373
402
  /**
374
403
  * try to:
375
404
  * - await a promise
@@ -394,8 +423,6 @@ async function tryCatch(funcOrPromise, valOrFunc) {
394
423
  return typeof valOrFunc === "function" ? valOrFunc(err) : valOrFunc;
395
424
  }
396
425
  }
397
- exports.tryCatch = tryCatch;
398
- exports.try = tryCatch;
399
426
  /**
400
427
  * Wrap the calling of a function into async/await (promise) context
401
428
  * - intended to be similar to `bluebird.try`
@@ -407,5 +434,4 @@ exports.try = tryCatch;
407
434
  async function wrap(func, ...args2) {
408
435
  return func(...args2);
409
436
  }
410
- exports.wrap = wrap;
411
- //# sourceMappingURL=index.js.map
437
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -2,10 +2,17 @@
2
2
  * @packageDocumentation
3
3
  * @module index
4
4
  */
5
- declare type Consumer<T> = (item: T, index?: number) => unknown;
6
- declare type FuncProducer<T> = () => T | Promise<T>;
7
- declare type Producer<T> = Promise<T> | FuncProducer<T>;
8
- declare type Predicate<T> = (item: T, index?: number) => boolean | Promise<boolean>;
5
+ type Consumer<T> = (item: T, index?: number) => unknown;
6
+ type FuncProducer<T> = () => T | Promise<T>;
7
+ type Producer<T> = Promise<T> | FuncProducer<T>;
8
+ type Predicate<T> = (item: T, index?: number) => boolean | Promise<boolean>;
9
+ /**
10
+ * check if something is a promise
11
+ *
12
+ * @param p
13
+ * @returns true or false
14
+ */
15
+ export declare function isPromise<T>(p: any): p is Promise<T>;
9
16
  /**
10
17
  * Defer object for fulfilling a promise later in other events
11
18
  *
@@ -47,10 +54,10 @@ export declare class Defer<T> {
47
54
  * }
48
55
  * ```
49
56
  *
50
- * @param Promise - optional Promise constructor.
57
+ * @param ThePromise - optional Promise constructor.
51
58
  * @returns Defer instance
52
59
  */
53
- export declare function makeDefer<T>(Promise?: PromiseConstructor): Defer<T>;
60
+ export declare function makeDefer<T>(ThePromise?: PromiseConstructor): Defer<T>;
54
61
  export { makeDefer as defer };
55
62
  /**
56
63
  * The error xaa.timeout will throw if operation timed out
@@ -76,18 +83,31 @@ export declare class TimeoutError extends Error {
76
83
  */
77
84
  export declare function delay(delayMs: number): Promise<void>;
78
85
  export declare function delay<T = void>(delayMs: number, valOrFunc: T): Promise<T>;
79
- declare type Task<T> = Promise<T> | (() => Promise<T>);
80
- declare type Tasks<T extends readonly any[]> = {
86
+ type Task<T> = Promise<T> | (() => Promise<T>);
87
+ type Tasks<T extends readonly any[]> = {
81
88
  readonly [P in keyof T]: Task<T[P]>;
82
89
  };
83
- declare type Runnable<T> = T extends readonly any[] ? Tasks<T> : Task<T>;
90
+ type Runnable<T> = T extends readonly any[] ? Tasks<T> : Task<T>;
91
+ type TimeoutRunnerOptions = {
92
+ TimeoutError: typeof TimeoutError;
93
+ Promise: PromiseConstructor;
94
+ };
84
95
  /**
85
96
  * TimeoutRunner for running tasks (promises) with a timeout
86
97
  *
87
98
  * Please use `xaa.timeout` or `xaa.runTimeout` APIs instead.
88
99
  */
89
100
  export declare class TimeoutRunner<T> {
90
- constructor(maxMs: number, rejectMsg: string);
101
+ /**
102
+ * constructor
103
+ * @param maxMs - number of milliseconds to allow tasks to run
104
+ * @param rejectMsg - message to reject with when timeout triggers
105
+ * @param options - TimeoutRunnerOptions
106
+ */
107
+ constructor(maxMs: number, rejectMsg: string, options: TimeoutRunnerOptions);
108
+ /**
109
+ * message to reject with when timeout triggers
110
+ */
91
111
  private defer;
92
112
  /** setTimeout handle */
93
113
  private timeout;
@@ -132,6 +152,10 @@ export declare class TimeoutRunner<T> {
132
152
  error?: Error;
133
153
  /** the result from running tasks */
134
154
  result?: T | T[];
155
+ /** Promise constructor */
156
+ ThePromise: PromiseConstructor;
157
+ /** TimeoutError constructor */
158
+ TimeoutError: typeof TimeoutError;
135
159
  }
136
160
  /**
137
161
  * Create a TimeoutRunner to run tasks (promises) with timeout
@@ -152,7 +176,7 @@ export declare class TimeoutRunner<T> {
152
176
  * @param rejectMsg - message to reject with when timeout triggers
153
177
  * @returns TimeoutRunner object
154
178
  */
155
- export declare function timeout<T>(maxMs: number, rejectMsg?: string): TimeoutRunner<T>;
179
+ export declare function timeout<T>(maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): TimeoutRunner<T>;
156
180
  /**
157
181
  * Calls `timeout(maxMs, rejectMsg).run(tasks)`
158
182
  *
@@ -161,8 +185,8 @@ export declare function timeout<T>(maxMs: number, rejectMsg?: string): TimeoutRu
161
185
  * @param rejectMsg - message to reject with if operation timed out
162
186
  * @returns promise results from all tasks
163
187
  */
164
- export declare function runTimeout<T>(tasks: Task<T>, maxMs: number, rejectMsg?: string): Promise<T>;
165
- export declare function runTimeout<T extends readonly any[]>(tasks: Tasks<T>, maxMs: number, rejectMsg?: string): Promise<T[]>;
188
+ export declare function runTimeout<T>(tasks: Task<T>, maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): Promise<T>;
189
+ export declare function runTimeout<T extends readonly any[]>(tasks: Tasks<T>, maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): Promise<T[]>;
166
190
  /**
167
191
  * The error xaa.map will throw if something went wrong.
168
192
  *
@@ -173,14 +197,14 @@ export interface MapError<T> extends Error {
173
197
  partial: T[];
174
198
  }
175
199
  /** options for xaa.map */
176
- export declare type MapOptions = {
200
+ export type MapOptions = {
177
201
  /** number of items to map concurrently */
178
202
  concurrency: number;
179
203
  /** the this passed to the map callback */
180
204
  thisArg?: any;
181
205
  };
182
206
  /** context from xaa.map to the mapper callback */
183
- export declare type MapContext<T> = {
207
+ export type MapContext<T> = {
184
208
  /**
185
209
  * indicate if another map operation during concurrent map has failed
186
210
  * Mapping should observe this flag whenever possible and avoid continuing
@@ -197,7 +221,7 @@ export declare type MapContext<T> = {
197
221
  */
198
222
  assertNoFailure: () => void;
199
223
  };
200
- declare type Awaited<T> = T extends PromiseLike<infer T2> ? {
224
+ type Awaited<T> = T extends PromiseLike<infer T2> ? {
201
225
  0: Awaited<T2>;
202
226
  1: T2;
203
227
  }[T2 extends PromiseLike<any> ? 0 : 1] : T;
@@ -209,7 +233,8 @@ declare type Awaited<T> = T extends PromiseLike<infer T2> ? {
209
233
  * @param context MapContext
210
234
  * @returns any or a promise
211
235
  */
212
- export declare type MapFunction<T, O> = (value: Awaited<T>, index: number, context: MapContext<T>) => O | Promise<O>;
236
+ export type MapFunction<T, O> = (value: Awaited<T>, index: number, context: MapContext<T>) => O | Promise<O>;
237
+ export declare function mapSeries<T, O>(array: readonly T[], func?: MapFunction<T, O>, options?: MapOptions): Promise<O[]>;
213
238
  /**
214
239
  * async map array with concurrency
215
240
  *
@@ -234,7 +259,7 @@ export declare function map<T, O>(array: readonly T[], func?: MapFunction<T, O>,
234
259
  * @param array array to each
235
260
  * @param func callback for each
236
261
  */
237
- export declare function each<T>(array: readonly T[], func: Consumer<T>): Promise<void>;
262
+ export declare function each<T>(array: readonly T[], func: Consumer<T>): Promise<T[]>;
238
263
  /**
239
264
  * async filter array
240
265
  *
@@ -251,7 +276,7 @@ export declare function each<T>(array: readonly T[], func: Consumer<T>): Promise
251
276
  * @returns filtered result
252
277
  */
253
278
  export declare function filter<T>(array: readonly T[], func: Predicate<T>): Promise<any[]>;
254
- declare type ValueOrErrorHandler<T> = T extends Function ? never : T | Promise<T> | ((err?: Error) => T | Promise<T>);
279
+ type ValueOrErrorHandler<T> = T extends Function ? never : T | Promise<T> | ((err?: Error) => T | Promise<T>);
255
280
  /**
256
281
  * try to:
257
282
  * - await a promise
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","s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C,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,SAAiB,CAAC;IAC/E,CAAC;AACH,CAAC;AAID;;;;;;;GAOG;AACI,KAAK,UAAU,IAAI,CACxB,IAAO,EACP,GAAG,KAAoB;IAEvB,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts"],"version":"5.9.3"}
@@ -0,0 +1,303 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module index
4
+ */
5
+ type Consumer<T> = (item: T, index?: number) => unknown;
6
+ type FuncProducer<T> = () => T | Promise<T>;
7
+ type Producer<T> = Promise<T> | FuncProducer<T>;
8
+ type Predicate<T> = (item: T, index?: number) => boolean | Promise<boolean>;
9
+ /**
10
+ * check if something is a promise
11
+ *
12
+ * @param p
13
+ * @returns true or false
14
+ */
15
+ export declare function isPromise<T>(p: any): p is Promise<T>;
16
+ /**
17
+ * Defer object for fulfilling a promise later in other events
18
+ *
19
+ * To use, use `xaa.makeDefer` or its alias `xaa.defeer`.
20
+ *
21
+ */
22
+ export declare class Defer<T> {
23
+ /**
24
+ * construct Defer
25
+ *
26
+ * @param ThePromise optional promise constructor
27
+ */
28
+ constructor(ThePromise?: PromiseConstructor);
29
+ /** The promise object for the defer */
30
+ promise: Promise<T>;
31
+ /** resolve the defered promise */
32
+ resolve: (result?: T) => void;
33
+ /** reject the deferred promise */
34
+ reject: (reason?: any) => void;
35
+ /**
36
+ * node.js callback for the deferred promise
37
+ *
38
+ * @param err - error
39
+ * @param args - result
40
+ * @returns nothing
41
+ */
42
+ done: (err: Error, ...args: any[]) => void;
43
+ }
44
+ /**
45
+ * Create a promise Defer object
46
+ *
47
+ * Sample:
48
+ *
49
+ * ```js
50
+ * async function waitEvent() {
51
+ * const defer = xaa.makeDefer();
52
+ * someThing.on("event", (data) => defer.resolve(data))
53
+ * return defer.promise;
54
+ * }
55
+ * ```
56
+ *
57
+ * @param ThePromise - optional Promise constructor.
58
+ * @returns Defer instance
59
+ */
60
+ export declare function makeDefer<T>(ThePromise?: PromiseConstructor): Defer<T>;
61
+ export { makeDefer as defer };
62
+ /**
63
+ * The error xaa.timeout will throw if operation timed out
64
+ */
65
+ export declare class TimeoutError extends Error {
66
+ constructor(msg: string);
67
+ }
68
+ /**
69
+ * delay some milliseconds and then return `valOrFunc`
70
+ *
71
+ * Sample:
72
+ *
73
+ * ```js
74
+ * await xaa.delay(500);
75
+ * await xaa.delay(500, "Result");
76
+ * await xaa.delay(500, () => "Result");
77
+ * ```
78
+ *
79
+ * @param delayMs - number milliseconds to delay
80
+ * @param valOrFunc - the value to return. If it's a function, call it to get the value.
81
+ * It can be an async function.
82
+ * @returns `valOrFunc` or its returned value if it's a function.
83
+ */
84
+ export declare function delay(delayMs: number): Promise<void>;
85
+ export declare function delay<T = void>(delayMs: number, valOrFunc: T): Promise<T>;
86
+ type Task<T> = Promise<T> | (() => Promise<T>);
87
+ type Tasks<T extends readonly any[]> = {
88
+ readonly [P in keyof T]: Task<T[P]>;
89
+ };
90
+ type Runnable<T> = T extends readonly any[] ? Tasks<T> : Task<T>;
91
+ type TimeoutRunnerOptions = {
92
+ TimeoutError: typeof TimeoutError;
93
+ Promise: PromiseConstructor;
94
+ };
95
+ /**
96
+ * TimeoutRunner for running tasks (promises) with a timeout
97
+ *
98
+ * Please use `xaa.timeout` or `xaa.runTimeout` APIs instead.
99
+ */
100
+ export declare class TimeoutRunner<T> {
101
+ /**
102
+ * constructor
103
+ * @param maxMs - number of milliseconds to allow tasks to run
104
+ * @param rejectMsg - message to reject with when timeout triggers
105
+ * @param options - TimeoutRunnerOptions
106
+ */
107
+ constructor(maxMs: number, rejectMsg: string, options: TimeoutRunnerOptions);
108
+ /**
109
+ * message to reject with when timeout triggers
110
+ */
111
+ private defer;
112
+ /** setTimeout handle */
113
+ private timeout;
114
+ /**
115
+ * check if runner has failed with error
116
+ *
117
+ * @returns has error flag
118
+ */
119
+ hasError(): boolean;
120
+ /**
121
+ * check if runner has finished with result
122
+ *
123
+ * @returns has result flag
124
+ */
125
+ hasResult(): boolean;
126
+ /**
127
+ * Run tasks
128
+ *
129
+ * @param tasks - Promise or function that returns Promise, or array of them.
130
+ * @returns Promise to wait for tasks to complete, or timeout error.
131
+ */
132
+ run<U extends Runnable<T>>(tasks: U): Promise<T | T[]>;
133
+ /**
134
+ * Cancel the operation and reject with msg
135
+ *
136
+ * @param msg - cancel message
137
+ */
138
+ cancel(msg?: string): void;
139
+ /** Explicitly clear the setTimeout handle */
140
+ clear(): void;
141
+ /**
142
+ * Check if runner is done
143
+ *
144
+ * @returns is done flag
145
+ */
146
+ isDone(): boolean;
147
+ /** number of milliseconds to allow tasks to run */
148
+ maxMs: number;
149
+ /** message to reject with if operation timed out */
150
+ rejectMsg: string;
151
+ /** the error if running failed */
152
+ error?: Error;
153
+ /** the result from running tasks */
154
+ result?: T | T[];
155
+ /** Promise constructor */
156
+ ThePromise: PromiseConstructor;
157
+ /** TimeoutError constructor */
158
+ TimeoutError: typeof TimeoutError;
159
+ }
160
+ /**
161
+ * Create a TimeoutRunner to run tasks (promises) with timeout
162
+ *
163
+ * Sample:
164
+ *
165
+ * ```js
166
+ * await xaa.timeout(1000, "timeout fetching data").run(() => fetch(url))
167
+ * ```
168
+ *
169
+ * with promises:
170
+ *
171
+ * ```js
172
+ * await xaa.timout(1000).run([promise1, promise2])
173
+ * ```
174
+ *
175
+ * @param maxMs - number of milliseconds to allow tasks to run
176
+ * @param rejectMsg - message to reject with when timeout triggers
177
+ * @returns TimeoutRunner object
178
+ */
179
+ export declare function timeout<T>(maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): TimeoutRunner<T>;
180
+ /**
181
+ * Calls `timeout(maxMs, rejectMsg).run(tasks)`
182
+ *
183
+ * @param tasks - Promise or function or array of them
184
+ * @param maxMs - milliseconds to wait for the tasks to fulfill
185
+ * @param rejectMsg - message to reject with if operation timed out
186
+ * @returns promise results from all tasks
187
+ */
188
+ export declare function runTimeout<T>(tasks: Task<T>, maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): Promise<T>;
189
+ export declare function runTimeout<T extends readonly any[]>(tasks: Tasks<T>, maxMs: number, rejectMsg?: string, options?: TimeoutRunnerOptions): Promise<T[]>;
190
+ /**
191
+ * The error xaa.map will throw if something went wrong.
192
+ *
193
+ * Contains a partial field for result mapped before error was encountered.
194
+ */
195
+ export interface MapError<T> extends Error {
196
+ /** the result that has been mapped before error was encountered */
197
+ partial: T[];
198
+ }
199
+ /** options for xaa.map */
200
+ export type MapOptions = {
201
+ /** number of items to map concurrently */
202
+ concurrency: number;
203
+ /** the this passed to the map callback */
204
+ thisArg?: any;
205
+ };
206
+ /** context from xaa.map to the mapper callback */
207
+ export type MapContext<T> = {
208
+ /**
209
+ * indicate if another map operation during concurrent map has failed
210
+ * Mapping should observe this flag whenever possible and avoid continuing
211
+ * if it makes sense.
212
+ */
213
+ failed?: boolean;
214
+ /**
215
+ * the original array that's passed to xaa.map
216
+ */
217
+ array: readonly T[];
218
+ /**
219
+ * During concurrent map, if any mapper failed, this allow other inflight
220
+ * map functions to assert that no failure has occurred, else stop.
221
+ */
222
+ assertNoFailure: () => void;
223
+ };
224
+ type Awaited<T> = T extends PromiseLike<infer T2> ? {
225
+ 0: Awaited<T2>;
226
+ 1: T2;
227
+ }[T2 extends PromiseLike<any> ? 0 : 1] : T;
228
+ /**
229
+ * callback function for xaa.map to map the value.
230
+ *
231
+ * @param value value to map
232
+ * @param index index of the value in the array
233
+ * @param context MapContext
234
+ * @returns any or a promise
235
+ */
236
+ export type MapFunction<T, O> = (value: Awaited<T>, index: number, context: MapContext<T>) => O | Promise<O>;
237
+ export declare function mapSeries<T, O>(array: readonly T[], func?: MapFunction<T, O>, options?: MapOptions): Promise<O[]>;
238
+ /**
239
+ * async map array with concurrency
240
+ *
241
+ * - intended to be similar to `bluebird.map`
242
+ *
243
+ * @param array array to map, if any item is promise-like, it will be resolved first.
244
+ * @param func - callback to map values from the array
245
+ * @param options - MapOptions
246
+ * @returns promise with mapped result
247
+ */
248
+ export declare function map<T, O>(array: readonly T[], func?: MapFunction<T, O>, options?: MapOptions): Promise<O[]>;
249
+ /**
250
+ * async version of array.forEach
251
+ * - iterate through array and await call func with each element and index
252
+ *
253
+ * Sample:
254
+ *
255
+ * ```js
256
+ * await xaa.each([1, 2, 3], async val => await xaa.delay(val))
257
+ * ```
258
+ *
259
+ * @param array array to each
260
+ * @param func callback for each
261
+ */
262
+ export declare function each<T>(array: readonly T[], func: Consumer<T>): Promise<T[]>;
263
+ /**
264
+ * async filter array
265
+ *
266
+ * Sample:
267
+ *
268
+ * ```js
269
+ * await xaa.filter([1, 2, 3], async val => await validateResult(val))
270
+ * ```
271
+ *
272
+ * Beware: concurrency is fixed to 1.
273
+ *
274
+ * @param array array to filter
275
+ * @param func callback for filter
276
+ * @returns filtered result
277
+ */
278
+ export declare function filter<T>(array: readonly T[], func: Predicate<T>): Promise<any[]>;
279
+ type ValueOrErrorHandler<T> = T extends Function ? never : T | Promise<T> | ((err?: Error) => T | Promise<T>);
280
+ /**
281
+ * try to:
282
+ * - await a promise
283
+ * - call and await function that returns a promise
284
+ *
285
+ * If exception occur, then return `valOrFunc`
286
+ *
287
+ * - if `valOrFunc` is a function, then return `valOrFunc(err)`
288
+ *
289
+ * @param funcOrPromise function or promise to try
290
+ * @param valOrFunc value, or callback to get value, to return if `func` throws
291
+ * @returns result, `valOrFunc`, or `valOrFunc(err)`.
292
+ */
293
+ export declare function tryCatch<T, TAlt>(funcOrPromise: Producer<T>, valOrFunc?: ValueOrErrorHandler<TAlt>): Promise<T | TAlt>;
294
+ export { tryCatch as try };
295
+ /**
296
+ * Wrap the calling of a function into async/await (promise) context
297
+ * - intended to be similar to `bluebird.try`
298
+ *
299
+ * @param func function to wrap in async context
300
+ * @param args arguments to pass to `func`
301
+ * @returns result from `func`
302
+ */
303
+ export declare function wrap<T, F extends (...args: any[]) => T>(func: F, ...args2: Parameters<F>): Promise<T>;
@@ -0,0 +1,417 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module index
4
+ */
5
+ /* eslint-disable max-statements, @typescript-eslint/ban-types, max-params, complexity */
6
+ import assert from "assert";
7
+ /**
8
+ * check if something is a promise
9
+ *
10
+ * @param p
11
+ * @returns true or false
12
+ */
13
+ export function isPromise(p) {
14
+ return p && p.then && p.catch && typeof p.then === "function" && typeof p.catch === "function";
15
+ }
16
+ /**
17
+ * Defer object for fulfilling a promise later in other events
18
+ *
19
+ * To use, use `xaa.makeDefer` or its alias `xaa.defeer`.
20
+ *
21
+ */
22
+ export class Defer {
23
+ /**
24
+ * construct Defer
25
+ *
26
+ * @param ThePromise optional promise constructor
27
+ */
28
+ constructor(ThePromise = global.Promise) {
29
+ this.promise = new ThePromise((resolve, reject) => {
30
+ this.resolve = resolve;
31
+ this.reject = reject;
32
+ });
33
+ // Not declaring (err, result) explicitly for standard node.js callback.
34
+ // we can't be sure if user's API expects callback that
35
+ // should have a second arg for result.
36
+ this.done = (err, ...args) => {
37
+ if (err)
38
+ this.reject(err);
39
+ else
40
+ this.resolve(args[0]);
41
+ };
42
+ }
43
+ }
44
+ /**
45
+ * Create a promise Defer object
46
+ *
47
+ * Sample:
48
+ *
49
+ * ```js
50
+ * async function waitEvent() {
51
+ * const defer = xaa.makeDefer();
52
+ * someThing.on("event", (data) => defer.resolve(data))
53
+ * return defer.promise;
54
+ * }
55
+ * ```
56
+ *
57
+ * @param ThePromise - optional Promise constructor.
58
+ * @returns Defer instance
59
+ */
60
+ export function makeDefer(ThePromise = global.Promise) {
61
+ return new Defer(ThePromise);
62
+ }
63
+ export { makeDefer as defer };
64
+ /**
65
+ * The error xaa.timeout will throw if operation timed out
66
+ */
67
+ export class TimeoutError extends Error {
68
+ constructor(msg) {
69
+ super(msg);
70
+ this.name = "TimeoutError";
71
+ assert(msg);
72
+ }
73
+ }
74
+ export async function delay(delayMs, valOrFunc) {
75
+ await new Promise(resolve => setTimeout(resolve, delayMs));
76
+ return typeof valOrFunc === "function" ? /* lazily */ valOrFunc() : valOrFunc;
77
+ }
78
+ /**
79
+ * TimeoutRunner for running tasks (promises) with a timeout
80
+ *
81
+ * Please use `xaa.timeout` or `xaa.runTimeout` APIs instead.
82
+ */
83
+ export class TimeoutRunner {
84
+ /**
85
+ * constructor
86
+ * @param maxMs - number of milliseconds to allow tasks to run
87
+ * @param rejectMsg - message to reject with when timeout triggers
88
+ * @param options - TimeoutRunnerOptions
89
+ */
90
+ constructor(maxMs, rejectMsg, options) {
91
+ this.maxMs = maxMs;
92
+ this.rejectMsg = rejectMsg;
93
+ this.defer = makeDefer(options.Promise);
94
+ this.ThePromise = options.Promise;
95
+ this.TimeoutError = options.TimeoutError;
96
+ this.timeout = setTimeout(() => this.defer.reject(new this.TimeoutError(rejectMsg)), maxMs);
97
+ }
98
+ /**
99
+ * check if runner has failed with error
100
+ *
101
+ * @returns has error flag
102
+ */
103
+ hasError() {
104
+ return this.hasOwnProperty("error");
105
+ }
106
+ /**
107
+ * check if runner has finished with result
108
+ *
109
+ * @returns has result flag
110
+ */
111
+ hasResult() {
112
+ return this.hasOwnProperty("result");
113
+ }
114
+ /**
115
+ * Run tasks
116
+ *
117
+ * @param tasks - Promise or function that returns Promise, or array of them.
118
+ * @returns Promise to wait for tasks to complete, or timeout error.
119
+ */
120
+ async run(tasks) {
121
+ const process = async (x) => (typeof x === "function" ? x() : x);
122
+ // Cast below is due in part to https://github.com/microsoft/TypeScript/issues/17002
123
+ const arrTasks = !Array.isArray(tasks)
124
+ ? process(tasks)
125
+ : this.ThePromise.all(tasks.map(process));
126
+ try {
127
+ const r = await this.ThePromise.race([arrTasks, this.defer.promise]);
128
+ this.clear();
129
+ this.result = r;
130
+ return r;
131
+ }
132
+ catch (err) {
133
+ this.clear();
134
+ this.error = err;
135
+ throw err;
136
+ }
137
+ }
138
+ /**
139
+ * Cancel the operation and reject with msg
140
+ *
141
+ * @param msg - cancel message
142
+ */
143
+ cancel(msg = "xaa TimeoutRunner operation cancelled") {
144
+ this.clear();
145
+ this.defer.reject(new this.TimeoutError(msg));
146
+ }
147
+ /** Explicitly clear the setTimeout handle */
148
+ clear() {
149
+ if (this.timeout) {
150
+ clearTimeout(this.timeout);
151
+ this.timeout = null;
152
+ }
153
+ }
154
+ /**
155
+ * Check if runner is done
156
+ *
157
+ * @returns is done flag
158
+ */
159
+ isDone() {
160
+ return this.hasResult() || this.hasError();
161
+ }
162
+ }
163
+ /**
164
+ * Create a TimeoutRunner to run tasks (promises) with timeout
165
+ *
166
+ * Sample:
167
+ *
168
+ * ```js
169
+ * await xaa.timeout(1000, "timeout fetching data").run(() => fetch(url))
170
+ * ```
171
+ *
172
+ * with promises:
173
+ *
174
+ * ```js
175
+ * await xaa.timout(1000).run([promise1, promise2])
176
+ * ```
177
+ *
178
+ * @param maxMs - number of milliseconds to allow tasks to run
179
+ * @param rejectMsg - message to reject with when timeout triggers
180
+ * @returns TimeoutRunner object
181
+ */
182
+ export function timeout(maxMs, rejectMsg = "xaa TimeoutRunner operation timed out", options = { TimeoutError: TimeoutError, Promise: global.Promise }) {
183
+ return new TimeoutRunner(maxMs, rejectMsg, options);
184
+ }
185
+ export async function runTimeout(tasks, maxMs, rejectMsg, options) {
186
+ return await timeout(maxMs, rejectMsg, options).run(tasks);
187
+ }
188
+ /**
189
+ * create map context
190
+ *
191
+ * @param array - array to map
192
+ * @returns map context
193
+ */
194
+ function createMapContext(array) {
195
+ return {
196
+ array,
197
+ failed: false,
198
+ assertNoFailure() {
199
+ if (this.failed) {
200
+ throw new Error("assertNoFailure");
201
+ }
202
+ }
203
+ };
204
+ }
205
+ /**
206
+ * async map for array that supports concurrency
207
+ *
208
+ * Use by xaa.map internally.
209
+ *
210
+ * @param array array to map, if any item is promise-like, it will be resolved first.
211
+ * @param func mapper callback
212
+ * @param options MapOptions
213
+ * @returns promise with mapped result
214
+ */
215
+ function multiMap(array, func, options) {
216
+ const awaited = new Array(array.length);
217
+ let error;
218
+ let completedCount = 0;
219
+ let freeSlots = options.concurrency;
220
+ let index = 0;
221
+ const iterator = Symbol.iterator in array && typeof array[Symbol.iterator] === "function"
222
+ ? array[Symbol.iterator]()
223
+ : null;
224
+ let totalCount = iterator ? Infinity : array.length;
225
+ const context = createMapContext(array);
226
+ const defer = makeDefer();
227
+ const fail = (err) => {
228
+ context.failed = true;
229
+ if (!error) {
230
+ error = err; // Safe because of the following line:
231
+ error.partial = awaited;
232
+ defer.reject(error);
233
+ }
234
+ };
235
+ const mapNext = () => {
236
+ // important to check this here, so an empty input array immediately
237
+ // gets resolved with an empty result.
238
+ if (!error && completedCount === totalCount) {
239
+ return defer.resolve(awaited);
240
+ }
241
+ if (error || freeSlots <= 0 || index >= totalCount) {
242
+ return null;
243
+ }
244
+ const ir = iterator && iterator.next();
245
+ /* c8 ignore next 7 */
246
+ if (ir && ir.done) {
247
+ if (totalCount !== index) {
248
+ totalCount = index;
249
+ return mapNext();
250
+ }
251
+ return null;
252
+ }
253
+ freeSlots--;
254
+ const pendingIx = index++;
255
+ const save = (x) => {
256
+ completedCount++;
257
+ freeSlots++;
258
+ awaited[pendingIx] = x;
259
+ mapNext();
260
+ };
261
+ const handleRet = res => {
262
+ if (isPromise(res)) {
263
+ res.then(save, fail);
264
+ return mapNext();
265
+ }
266
+ else {
267
+ return save(res);
268
+ }
269
+ };
270
+ const item = ir ? ir.value : array[pendingIx];
271
+ if (isPromise(item)) {
272
+ return item.then(val => {
273
+ return handleRet(func.call(options.thisArg, val, pendingIx, context));
274
+ }, fail);
275
+ }
276
+ else {
277
+ try {
278
+ return handleRet(func.call(options.thisArg, item, pendingIx, context));
279
+ }
280
+ catch (err) {
281
+ return fail(err);
282
+ }
283
+ }
284
+ };
285
+ //
286
+ // Should not use setTimeout for next:
287
+ //
288
+ // Top level code in async functions before any await statements, execute synchronously.
289
+ //
290
+ // Similar to that setting up promises is sync, and then the
291
+ // fulfilment of them is async, meaning their .then are called.
292
+ //
293
+ mapNext();
294
+ return defer.promise;
295
+ }
296
+ export async function mapSeries(array, func, options) {
297
+ const awaited = new Array();
298
+ const context = createMapContext(array);
299
+ let i = 0;
300
+ try {
301
+ for (const element of array) {
302
+ const item = isPromise(element) ? await element : element;
303
+ awaited[i] = await func.call(options && options.thisArg, item, i, context);
304
+ i++;
305
+ }
306
+ }
307
+ catch (err) {
308
+ context.failed = true;
309
+ err.partial = awaited;
310
+ throw err;
311
+ }
312
+ return awaited;
313
+ }
314
+ /**
315
+ * async map array with concurrency
316
+ *
317
+ * - intended to be similar to `bluebird.map`
318
+ *
319
+ * @param array array to map, if any item is promise-like, it will be resolved first.
320
+ * @param func - callback to map values from the array
321
+ * @param options - MapOptions
322
+ * @returns promise with mapped result
323
+ */
324
+ export async function map(array, func, options = { concurrency: 50 }) {
325
+ assert(Array.isArray(array), `xaa.map expecting an array but got ${typeof array}`);
326
+ if (options.concurrency > 1) {
327
+ return multiMap(array, func, options);
328
+ }
329
+ else {
330
+ return mapSeries(array, func, options);
331
+ }
332
+ }
333
+ /**
334
+ * async version of array.forEach
335
+ * - iterate through array and await call func with each element and index
336
+ *
337
+ * Sample:
338
+ *
339
+ * ```js
340
+ * await xaa.each([1, 2, 3], async val => await xaa.delay(val))
341
+ * ```
342
+ *
343
+ * @param array array to each
344
+ * @param func callback for each
345
+ */
346
+ export async function each(array, func) {
347
+ let i = 0;
348
+ const items = [];
349
+ for (const element of array) {
350
+ const item = isPromise(element) ? await element : element;
351
+ items.push(item);
352
+ await func(item, i);
353
+ i++;
354
+ }
355
+ return items;
356
+ }
357
+ /**
358
+ * async filter array
359
+ *
360
+ * Sample:
361
+ *
362
+ * ```js
363
+ * await xaa.filter([1, 2, 3], async val => await validateResult(val))
364
+ * ```
365
+ *
366
+ * Beware: concurrency is fixed to 1.
367
+ *
368
+ * @param array array to filter
369
+ * @param func callback for filter
370
+ * @returns filtered result
371
+ */
372
+ export async function filter(array, func) {
373
+ const filtered = [];
374
+ for (let i = 0; i < array.length; i++) {
375
+ const x = await func(array[i], i);
376
+ if (x)
377
+ filtered.push(array[i]);
378
+ }
379
+ return filtered;
380
+ }
381
+ /**
382
+ * try to:
383
+ * - await a promise
384
+ * - call and await function that returns a promise
385
+ *
386
+ * If exception occur, then return `valOrFunc`
387
+ *
388
+ * - if `valOrFunc` is a function, then return `valOrFunc(err)`
389
+ *
390
+ * @param funcOrPromise function or promise to try
391
+ * @param valOrFunc value, or callback to get value, to return if `func` throws
392
+ * @returns result, `valOrFunc`, or `valOrFunc(err)`.
393
+ */
394
+ export async function tryCatch(funcOrPromise, valOrFunc) {
395
+ try {
396
+ if (isPromise(funcOrPromise)) {
397
+ return await funcOrPromise;
398
+ }
399
+ return await funcOrPromise();
400
+ }
401
+ catch (err) {
402
+ return typeof valOrFunc === "function" ? valOrFunc(err) : valOrFunc;
403
+ }
404
+ }
405
+ export { tryCatch as try };
406
+ /**
407
+ * Wrap the calling of a function into async/await (promise) context
408
+ * - intended to be similar to `bluebird.try`
409
+ *
410
+ * @param func function to wrap in async context
411
+ * @param args arguments to pass to `func`
412
+ * @returns result from `func`
413
+ */
414
+ export async function wrap(func, ...args2) {
415
+ return func(...args2);
416
+ }
417
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yFAAyF;AAEzF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAI,CAAM;IACjC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,UAAU,CAAC;AACjG,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,KAAK;IAChB;;;;OAIG;IACH,YAAY,aAAiC,MAAM,CAAC,OAAO;QACzD,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,CAAC,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AmB,EAAE,IAAkB;IACrE,MAAM,QAAQ,GAAG,EAAE,CAAC;IAEpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAElC,IAAI,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAMD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,aAA0B,EAC1B,SAAqC;IAErC,IAAI,CAAC;QACH,IAAI,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;YAC7B,OAAO,MAAM,aAAa,CAAC;QAC7B,CAAC;QAED,OAAO,MAAM,aAAa,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,SAAiB,CAAC;IAC/E,CAAC;AACH,CAAC;AAED,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,CAAC;AAE3B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,IAAO,EACP,GAAG,KAAoB;IAEvB,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,15 +1,36 @@
1
1
  {
2
2
  "name": "xaa",
3
- "version": "1.7.3",
3
+ "version": "2.0.0",
4
+ "engines": {
5
+ "node": ">=18"
6
+ },
4
7
  "description": "async/await/Promise helpers - delay, defer, timeout, each, map, filter",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "types": "dist-cjs/index.d.ts",
10
+ "main": "dist-cjs/index.cjs",
11
+ "module": "dist-esm/index.js",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist-esm/index.js",
15
+ "require": "./dist-cjs/index.cjs"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
7
19
  "scripts": {
8
- "build": "rm -rf dist && tsc",
9
- "test": "xrun -s build xarc/test-only",
10
- "coverage": "xrun -s build xarc/test-cov",
11
- "prepublishOnly": "xrun [[build, docs] xarc/check]",
12
- "docs": "clap xarc/docs && touch docs/.nojekyll"
20
+ "build": "xrun [-s, build:clean, [build:esm, build:cjs], build:2cjs]",
21
+ "build:clean": "rm -rf dist-*",
22
+ "build:esm": "tsc --build tsconfig.esm.json",
23
+ "build:cjs": "tsc --build tsconfig.cjs.json",
24
+ "build:2cjs": "ts2mjs --cjs --skip-ts --remove-source dist-cjs",
25
+ "test": "xrun [vitest, demo:cjs, demo:esm]",
26
+ "vitest": "vitest run",
27
+ "coverage": "vitest run --coverage",
28
+ "format": "prettier --write src test demo vitest.config.ts",
29
+ "demo:cjs": "cd demo/sample-1-cjs && fyn install && node demo.cjs",
30
+ "demo:esm": "cd demo/sample-1-esm && fyn install && node demo.js",
31
+ "prepublishOnly": "xrun -s '[coverage, [build, docs]]'",
32
+ "docs": "typedoc --gitRevision $(git rev-list -1 HEAD src) --out docs src",
33
+ "postpack": "publish-util-postpack"
13
34
  },
14
35
  "homepage": "https://jchip.github.io/xaa/",
15
36
  "repository": {
@@ -30,89 +51,12 @@
30
51
  "filter"
31
52
  ],
32
53
  "files": [
33
- "dist"
54
+ "dist-cjs",
55
+ "dist-esm"
34
56
  ],
35
57
  "author": "Joel Chen",
36
58
  "license": "Apache-2.0",
37
- "devDependencies": {
38
- "@istanbuljs/nyc-config-typescript": "^1.0.1",
39
- "@types/chai": "^4.2.14",
40
- "@types/mocha": "^8.2.0",
41
- "@types/node": "^14.14.16",
42
- "@types/sinon": "^9.0.10",
43
- "@types/sinon-chai": "^3.2.5",
44
- "@typescript-eslint/eslint-plugin": "^4.11.0",
45
- "@typescript-eslint/parser": "^4.11.0",
46
- "@xarc/module-dev": "^4.0.0",
47
- "babel-eslint": "^10.1.0",
48
- "chai": "^4.2.0",
49
- "eslint": "^7.16.0",
50
- "eslint-config-walmart": "^2.2.1",
51
- "eslint-plugin-filenames": "^1.1.0",
52
- "eslint-plugin-jsdoc": "^30.7.9",
53
- "eslint-plugin-tsdoc": "^0.2.11",
54
- "mocha": "^8.2.1",
55
- "nyc": "^15.1.0",
56
- "prettier": "^2.2.1",
57
- "run-verify": "^1.2.1",
58
- "sinon": "^9.2.2",
59
- "sinon-chai": "^3.5.0",
60
- "source-map-support": "^0.5.19",
61
- "ts-node": "^9.1.1",
62
- "typedoc": "^0.22.12",
63
- "typescript": "^4.1.3"
64
- },
65
- "nyc": {
66
- "extends": [
67
- "@istanbuljs/nyc-config-typescript"
68
- ],
69
- "all": true,
70
- "reporter": [
71
- "lcov",
72
- "text",
73
- "text-summary"
74
- ],
75
- "exclude": [
76
- "*clap.js",
77
- "*clap.ts",
78
- "coverage",
79
- "dist",
80
- "docs",
81
- "gulpfile.js",
82
- "test",
83
- "xrun*.js",
84
- "xrun*.ts",
85
- ".eslintrc.js"
86
- ],
87
- "check-coverage": true,
88
- "statements": 100,
89
- "branches": 100,
90
- "functions": 100,
91
- "lines": 100,
92
- "cache": false
93
- },
94
- "prettier": {
95
- "printWidth": 100,
96
- "trailingComma": "none",
97
- "arrowParens": "avoid"
98
- },
99
- "@xarc/module-dev": {
100
- "features": [
101
- "eslint",
102
- "eslintTS",
103
- "mocha",
104
- "prettier",
105
- "typedoc",
106
- "typescript"
107
- ]
108
- },
109
- "mocha": {
110
- "require": [
111
- "ts-node/register",
112
- "source-map-support/register",
113
- "@xarc/module-dev/config/test/setup.js"
114
- ],
115
- "recursive": true
116
- },
117
- "dependencies": {}
59
+ "dependencies": {
60
+ "tslib": "^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