@fluidframework/core-utils 2.0.0-dev.6.4.0.192049 → 2.0.0-dev.7.2.0.204906

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.eslintrc.js +13 -3
  2. package/CHANGELOG.md +16 -0
  3. package/api-extractor.json +1 -1
  4. package/api-report/core-utils.api.md +147 -0
  5. package/dist/assert.d.ts +1 -0
  6. package/dist/assert.d.ts.map +1 -1
  7. package/dist/assert.js +1 -0
  8. package/dist/assert.js.map +1 -1
  9. package/dist/compare.js.map +1 -1
  10. package/dist/core-utils-alpha.d.ts +404 -0
  11. package/dist/core-utils-beta.d.ts +404 -0
  12. package/dist/core-utils-public.d.ts +404 -0
  13. package/dist/core-utils-untrimmed.d.ts +414 -0
  14. package/dist/delay.d.ts +1 -0
  15. package/dist/delay.d.ts.map +1 -1
  16. package/dist/delay.js +1 -0
  17. package/dist/delay.js.map +1 -1
  18. package/dist/heap.d.ts +4 -0
  19. package/dist/heap.d.ts.map +1 -1
  20. package/dist/heap.js +3 -1
  21. package/dist/heap.js.map +1 -1
  22. package/dist/lazy.d.ts +2 -0
  23. package/dist/lazy.d.ts.map +1 -1
  24. package/dist/lazy.js +10 -5
  25. package/dist/lazy.js.map +1 -1
  26. package/dist/promiseCache.d.ts +11 -4
  27. package/dist/promiseCache.d.ts.map +1 -1
  28. package/dist/promiseCache.js +1 -0
  29. package/dist/promiseCache.js.map +1 -1
  30. package/dist/promises.d.ts +1 -0
  31. package/dist/promises.d.ts.map +1 -1
  32. package/dist/promises.js +3 -0
  33. package/dist/promises.js.map +1 -1
  34. package/dist/timer.d.ts +10 -0
  35. package/dist/timer.d.ts.map +1 -1
  36. package/dist/timer.js +22 -19
  37. package/dist/timer.js.map +1 -1
  38. package/dist/tsdoc-metadata.json +1 -1
  39. package/dist/unreachable.d.ts +1 -0
  40. package/dist/unreachable.d.ts.map +1 -1
  41. package/dist/unreachable.js +1 -0
  42. package/dist/unreachable.js.map +1 -1
  43. package/lib/assert.d.ts +1 -0
  44. package/lib/assert.d.ts.map +1 -1
  45. package/lib/assert.js +1 -0
  46. package/lib/assert.js.map +1 -1
  47. package/lib/compare.js.map +1 -1
  48. package/lib/delay.d.ts +1 -0
  49. package/lib/delay.d.ts.map +1 -1
  50. package/lib/delay.js +1 -0
  51. package/lib/delay.js.map +1 -1
  52. package/lib/heap.d.ts +4 -0
  53. package/lib/heap.d.ts.map +1 -1
  54. package/lib/heap.js +3 -1
  55. package/lib/heap.js.map +1 -1
  56. package/lib/lazy.d.ts +2 -0
  57. package/lib/lazy.d.ts.map +1 -1
  58. package/lib/lazy.js +10 -5
  59. package/lib/lazy.js.map +1 -1
  60. package/lib/promiseCache.d.ts +11 -4
  61. package/lib/promiseCache.d.ts.map +1 -1
  62. package/lib/promiseCache.js +1 -0
  63. package/lib/promiseCache.js.map +1 -1
  64. package/lib/promises.d.ts +1 -0
  65. package/lib/promises.d.ts.map +1 -1
  66. package/lib/promises.js +3 -0
  67. package/lib/promises.js.map +1 -1
  68. package/lib/timer.d.ts +10 -0
  69. package/lib/timer.d.ts.map +1 -1
  70. package/lib/timer.js +22 -19
  71. package/lib/timer.js.map +1 -1
  72. package/lib/unreachable.d.ts +1 -0
  73. package/lib/unreachable.d.ts.map +1 -1
  74. package/lib/unreachable.js +1 -0
  75. package/lib/unreachable.js.map +1 -1
  76. package/package.json +13 -14
  77. package/src/assert.ts +1 -0
  78. package/src/compare.ts +1 -1
  79. package/src/delay.ts +1 -0
  80. package/src/heap.ts +5 -1
  81. package/src/lazy.ts +9 -4
  82. package/src/promiseCache.ts +15 -6
  83. package/src/promises.ts +5 -2
  84. package/src/timer.ts +21 -11
  85. package/src/unreachable.ts +1 -0
@@ -0,0 +1,414 @@
1
+ /**
2
+ * A browser friendly assert library.
3
+ * Use this instead of the 'assert' package, which has a big impact on bundle sizes.
4
+ * @param condition - The condition that should be true, if the condition is false an error will be thrown.
5
+ * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
6
+ * @param message - The message to include in the error when the condition does not hold.
7
+ * A number should not be specified manually: use a string.
8
+ * Before a release, policy-check should be run, which will convert any asserts still using strings to
9
+ * use numbered error codes instead.
10
+ * @public
11
+ */
12
+ export declare function assert(condition: boolean, message: string | number): asserts condition;
13
+
14
+ /**
15
+ * Compare two arrays. Returns true if their elements are equivalent and in the same order.
16
+ *
17
+ * @internal
18
+ *
19
+ * @param left - The first array to compare
20
+ * @param right - The second array to compare
21
+ * @param comparator - The function used to check if two `T`s are equivalent.
22
+ * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
23
+ */
24
+ export declare const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
25
+
26
+ /**
27
+ * A deferred creates a promise and the ability to resolve or reject it
28
+ * @public
29
+ */
30
+ export declare class Deferred<T> {
31
+ private readonly p;
32
+ private res;
33
+ private rej;
34
+ private completed;
35
+ constructor();
36
+ /**
37
+ * Returns whether the underlying promise has been completed
38
+ */
39
+ get isCompleted(): boolean;
40
+ /**
41
+ * Retrieves the underlying promise for the deferred
42
+ *
43
+ * @returns the underlying promise
44
+ */
45
+ get promise(): Promise<T>;
46
+ /**
47
+ * Resolves the promise
48
+ *
49
+ * @param value - the value to resolve the promise with
50
+ */
51
+ resolve(value: T | PromiseLike<T>): void;
52
+ /**
53
+ * Rejects the promise
54
+ *
55
+ * @param value - the value to reject the promise with
56
+ */
57
+ reject(error: any): void;
58
+ }
59
+
60
+ /**
61
+ * Returns a promise that resolves after `timeMs`.
62
+ * @param timeMs - Time in milliseconds to wait.
63
+ * @public
64
+ */
65
+ export declare const delay: (timeMs: number) => Promise<void>;
66
+
67
+ /**
68
+ * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
69
+ * @public
70
+ */
71
+ export declare class Heap<T> {
72
+ comp: IComparer<T>;
73
+ private L;
74
+ /**
75
+ * Creates an instance of `Heap` with comparer.
76
+ * @param comp - A comparer that specify how elements are ordered.
77
+ */
78
+ constructor(comp: IComparer<T>);
79
+ /**
80
+ * Return the smallest element in the heap as determined by the order of the comparer
81
+ *
82
+ * @returns Heap node containing the smallest element
83
+ */
84
+ peek(): IHeapNode<T>;
85
+ /**
86
+ * Get and remove the smallest element in the heap as determined by the order of the comparer
87
+ *
88
+ * @returns The smallest value in the heap
89
+ */
90
+ get(): T;
91
+ /**
92
+ * Add a value to the heap
93
+ *
94
+ * @param x - value to add
95
+ * @returns The heap node that contains the value
96
+ */
97
+ add(x: T): IHeapNode<T>;
98
+ /**
99
+ * Allows for the Heap to be updated after a node's value changes.
100
+ */
101
+ update(node: IHeapNode<T>): void;
102
+ /**
103
+ * Removes the given node from the heap.
104
+ *
105
+ * @param node - The node to remove from the heap.
106
+ */
107
+ remove(node: IHeapNode<T>): void;
108
+ /**
109
+ * Get the number of elements in the Heap.
110
+ *
111
+ * @returns The number of elements in the Heap.
112
+ */
113
+ count(): number;
114
+ private fixup;
115
+ private isGreaterThanParent;
116
+ private fixdown;
117
+ private swap;
118
+ }
119
+
120
+ /**
121
+ * Interface for a comparer.
122
+ * @public
123
+ */
124
+ export declare interface IComparer<T> {
125
+ /**
126
+ * The minimum value of type T.
127
+ */
128
+ min: T;
129
+ /**
130
+ * Compare the two value
131
+ *
132
+ * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise
133
+ */
134
+ compare(a: T, b: T): number;
135
+ }
136
+
137
+ /**
138
+ * Interface to a node in {@link Heap}.
139
+ * @public
140
+ */
141
+ export declare interface IHeapNode<T> {
142
+ value: T;
143
+ position: number;
144
+ }
145
+
146
+ /**
147
+ * Timer which offers a promise that fulfills when the timer
148
+ * completes.
149
+ * @public
150
+ */
151
+ export declare interface IPromiseTimer extends ITimer {
152
+ /**
153
+ * Starts the timer and returns a promise that
154
+ * resolves when the timer times out or is canceled.
155
+ */
156
+ start(): Promise<IPromiseTimerResult>;
157
+ }
158
+
159
+ /**
160
+ * @public
161
+ */
162
+ export declare interface IPromiseTimerResult {
163
+ timerResult: "timeout" | "cancel";
164
+ }
165
+
166
+ /**
167
+ * @public
168
+ */
169
+ export declare interface ITimer {
170
+ /**
171
+ * True if timer is currently running
172
+ */
173
+ readonly hasTimer: boolean;
174
+ /**
175
+ * Starts the timer
176
+ */
177
+ start(): void;
178
+ /**
179
+ * Cancels the timer if already running
180
+ */
181
+ clear(): void;
182
+ }
183
+
184
+ /**
185
+ * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.
186
+ * @public
187
+ */
188
+ export declare class Lazy<T> {
189
+ private readonly valueGenerator;
190
+ private _value;
191
+ private _evaluated;
192
+ /**
193
+ * Instantiates an instance of Lazy<T>.
194
+ * @param valueGenerator - The function that will generate the value when value is accessed the first time.
195
+ */
196
+ constructor(valueGenerator: () => T);
197
+ /**
198
+ * Return true if the value as been generated, otherwise false.
199
+ */
200
+ get evaluated(): boolean;
201
+ /**
202
+ * Get the value. If this is the first call the value will be generated.
203
+ */
204
+ get value(): T;
205
+ }
206
+
207
+ /**
208
+ * A lazy evaluated promise. The execute function is delayed until
209
+ * the promise is used, e.g. await, then, catch ...
210
+ * The execute function is only called once.
211
+ * All calls are then proxied to the promise returned by the execute method.
212
+ * @public
213
+ */
214
+ export declare class LazyPromise<T> implements Promise<T> {
215
+ private readonly execute;
216
+ get [Symbol.toStringTag](): string;
217
+ private result;
218
+ constructor(execute: () => Promise<T>);
219
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
220
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
221
+ finally(onfinally?: (() => void) | null | undefined): Promise<T>;
222
+ private getPromise;
223
+ }
224
+
225
+ /**
226
+ * A comparer for numbers.
227
+ * @public
228
+ */
229
+ export declare const NumberComparer: IComparer<number>;
230
+
231
+ /**
232
+ * A specialized cache for async work, allowing you to safely cache the promised result of some async work
233
+ * without fear of running it multiple times or losing track of errors.
234
+ * @public
235
+ */
236
+ export declare class PromiseCache<TKey, TResult> {
237
+ private readonly cache;
238
+ private readonly gc;
239
+ private readonly removeOnError;
240
+ /**
241
+ * Create the PromiseCache with the given options, with the following defaults:
242
+ *
243
+ * expiry: indefinite, removeOnError: true for all errors
244
+ */
245
+ constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
246
+ /**
247
+ * Check if there's anything cached at the given key
248
+ */
249
+ has(key: TKey): boolean;
250
+ /**
251
+ * Get the Promise for the given key, or undefined if it's not found.
252
+ * Extend expiry if applicable.
253
+ */
254
+ get(key: TKey): Promise<TResult> | undefined;
255
+ /**
256
+ * Remove the Promise for the given key, returning true if it was found and removed
257
+ */
258
+ remove(key: TKey): boolean;
259
+ /**
260
+ * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
261
+ * Returns a Promise for the added or existing async work being done at that key.
262
+ * @param key - key name where to store the async work
263
+ * @param asyncFn - the async work to do and store, if not already in progress under the given key
264
+ */
265
+ addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult>;
266
+ /**
267
+ * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
268
+ * Returns false if the cache already contained an entry at that key, and true otherwise.
269
+ * @param key - key name where to store the async work
270
+ * @param asyncFn - the async work to do and store, if not already in progress under the given key
271
+ */
272
+ add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
273
+ /**
274
+ * Try to add the given value, without overwriting an existing cache entry at that key.
275
+ * Returns a Promise for the added or existing async work being done at that key.
276
+ * @param key - key name where to store the async work
277
+ * @param value - value to store
278
+ */
279
+ addValueOrGet(key: TKey, value: TResult): Promise<TResult>;
280
+ /**
281
+ * Try to add the given value, without overwriting an existing cache entry at that key.
282
+ * Returns false if the cache already contained an entry at that key, and true otherwise.
283
+ * @param key - key name where to store the value
284
+ * @param value - value to store
285
+ */
286
+ addValue(key: TKey, value: TResult): boolean;
287
+ }
288
+
289
+ /**
290
+ * Three supported expiry policies:
291
+ * - indefinite: entries don't expire and must be explicitly removed
292
+ * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
293
+ * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
294
+ * @public
295
+ */
296
+ export declare type PromiseCacheExpiry = {
297
+ policy: "indefinite";
298
+ } | {
299
+ policy: "absolute" | "sliding";
300
+ durationMs: number;
301
+ };
302
+
303
+ /**
304
+ * Options for configuring the {@link PromiseCache}
305
+ * @public
306
+ */
307
+ export declare interface PromiseCacheOptions {
308
+ /**
309
+ * Common expiration policy for all items added to this cache
310
+ */
311
+ expiry?: PromiseCacheExpiry;
312
+ /**
313
+ * If the stored Promise is rejected with a particular error, should the given key be removed?
314
+ */
315
+ removeOnError?: (error: any) => boolean;
316
+ }
317
+
318
+ /**
319
+ * This class is a wrapper over setTimeout and clearTimeout which
320
+ * makes it simpler to keep track of recurring timeouts with the
321
+ * same handlers and timeouts, while also providing a promise that
322
+ * resolves when it times out.
323
+ * @public
324
+ */
325
+ export declare class PromiseTimer implements IPromiseTimer {
326
+ private deferred?;
327
+ private readonly timer;
328
+ /**
329
+ * {@inheritDoc Timer.hasTimer}
330
+ */
331
+ get hasTimer(): boolean;
332
+ constructor(defaultTimeout: number, defaultHandler: () => void);
333
+ /**
334
+ * {@inheritDoc IPromiseTimer.start}
335
+ */
336
+ start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult>;
337
+ clear(): void;
338
+ protected wrapHandler(handler: () => void): void;
339
+ }
340
+
341
+ /**
342
+ * Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.
343
+ * Timeouts may not be exactly accurate due to browser implementations and the OS.
344
+ * https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate
345
+ * @param timeoutFn - Executed when the timeout expires
346
+ * @param timeoutMs - Duration of the timeout in milliseconds
347
+ * @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when
348
+ * timeoutMs greater than maxTimeout
349
+ * @returns The initial timeout
350
+ * @public
351
+ */
352
+ export declare function setLongTimeout(timeoutFn: () => void, timeoutMs: number, setTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void): ReturnType<typeof setTimeout>;
353
+
354
+ /**
355
+ * This class is a thin wrapper over setTimeout and clearTimeout which
356
+ * makes it simpler to keep track of recurring timeouts with the same
357
+ * or similar handlers and timeouts. This class supports long timeouts
358
+ * or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.
359
+ * @public
360
+ */
361
+ export declare class Timer implements ITimer {
362
+ private readonly defaultTimeout;
363
+ private readonly defaultHandler;
364
+ private readonly getCurrentTick;
365
+ /**
366
+ * Returns true if the timer is running.
367
+ */
368
+ get hasTimer(): boolean;
369
+ private runningState;
370
+ constructor(defaultTimeout: number, defaultHandler: () => void, getCurrentTick?: () => number);
371
+ /**
372
+ * Calls setTimeout and tracks the resulting timeout.
373
+ * @param ms - overrides default timeout in ms
374
+ * @param handler - overrides default handler
375
+ */
376
+ start(ms?: number, handler?: () => void): void;
377
+ /**
378
+ * Calls clearTimeout on the underlying timeout if running.
379
+ */
380
+ clear(): void;
381
+ /**
382
+ * Restarts the timer with the new handler and duration.
383
+ * If a new handler is passed, the original handler may
384
+ * never execute.
385
+ * This is a potentially more efficient way to clear and start
386
+ * a new timer.
387
+ * @param ms - overrides previous or default timeout in ms
388
+ * @param handler - overrides previous or default handler
389
+ */
390
+ restart(ms?: number, handler?: () => void): void;
391
+ private startCore;
392
+ private handler;
393
+ private calculateRemainingTime;
394
+ }
395
+
396
+ /**
397
+ * This function can be used to assert at compile time that a given value has type never.
398
+ * One common usage is in the default case of a switch block,
399
+ * to ensure that all cases are explicitly handled.
400
+ *
401
+ * Example:
402
+ * ```typescript
403
+ * const bool: true | false = ...;
404
+ * switch(bool) {
405
+ * case true: {...}
406
+ * case false: {...}
407
+ * default: unreachableCase(bool);
408
+ * }
409
+ * ```
410
+ * @public
411
+ */
412
+ export declare function unreachableCase(_: never, message?: string): never;
413
+
414
+ export { }
package/dist/delay.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  /**
6
6
  * Returns a promise that resolves after `timeMs`.
7
7
  * @param timeMs - Time in milliseconds to wait.
8
+ * @public
8
9
  */
9
10
  export declare const delay: (timeMs: number) => Promise<void>;
10
11
  //# sourceMappingURL=delay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,KAAK,WAAkB,MAAM,KAAG,QAAQ,IAAI,CACK,CAAC"}
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,KAAK,WAAkB,MAAM,KAAG,QAAQ,IAAI,CACK,CAAC"}
package/dist/delay.js CHANGED
@@ -8,6 +8,7 @@ exports.delay = void 0;
8
8
  /**
9
9
  * Returns a promise that resolves after `timeMs`.
10
10
  * @param timeMs - Time in milliseconds to wait.
11
+ * @public
11
12
  */
12
13
  const delay = async (timeMs) => new Promise((resolve) => setTimeout(() => resolve(), timeMs));
13
14
  exports.delay = delay;
package/dist/delay.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACI,MAAM,KAAK,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE,CAC5D,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;AADlD,QAAA,KAAK,SAC6C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Returns a promise that resolves after `timeMs`.\n * @param timeMs - Time in milliseconds to wait.\n */\nexport const delay = async (timeMs: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(() => resolve(), timeMs));\n"]}
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AACI,MAAM,KAAK,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE,CAC5D,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;AADlD,QAAA,KAAK,SAC6C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Returns a promise that resolves after `timeMs`.\n * @param timeMs - Time in milliseconds to wait.\n * @public\n */\nexport const delay = async (timeMs: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(() => resolve(), timeMs));\n"]}
package/dist/heap.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  /**
6
6
  * Interface for a comparer.
7
+ * @public
7
8
  */
8
9
  export interface IComparer<T> {
9
10
  /**
@@ -19,10 +20,12 @@ export interface IComparer<T> {
19
20
  }
20
21
  /**
21
22
  * A comparer for numbers.
23
+ * @public
22
24
  */
23
25
  export declare const NumberComparer: IComparer<number>;
24
26
  /**
25
27
  * Interface to a node in {@link Heap}.
28
+ * @public
26
29
  */
27
30
  export interface IHeapNode<T> {
28
31
  value: T;
@@ -30,6 +33,7 @@ export interface IHeapNode<T> {
30
33
  }
31
34
  /**
32
35
  * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
36
+ * @public
33
37
  */
34
38
  export declare class Heap<T> {
35
39
  comp: IComparer<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"heap.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AAC;IAC3B;;OAEG;IACH,GAAG,EAAE,CAAC,CAAC;IAEP;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,MAAM,CAW5C,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,IAAI,CAAC,CAAC;IAOC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IANrC,OAAO,CAAC,CAAC,CAAiB;IAE1B;;;OAGG;gBACgB,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAIrC;;;;OAIG;IACI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC;IAI3B;;;;OAIG;IACI,GAAG,IAAI,CAAC;IAQf;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAQ9B;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IASvC;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAYvC;;;;OAIG;IACI,KAAK,IAAI,MAAM;IAItB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,OAAO;IAiBf,OAAO,CAAC,IAAI;CAOZ"}
package/dist/heap.js CHANGED
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.Heap = exports.NumberComparer = void 0;
8
8
  /**
9
9
  * A comparer for numbers.
10
+ * @public
10
11
  */
11
12
  exports.NumberComparer = {
12
13
  /**
@@ -21,6 +22,7 @@ exports.NumberComparer = {
21
22
  };
22
23
  /**
23
24
  * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
25
+ * @public
24
26
  */
25
27
  class Heap {
26
28
  /**
@@ -84,7 +86,7 @@ class Heap {
84
86
  // Move the node we want to remove to the end of the array
85
87
  const position = node.position;
86
88
  this.swap(node.position, this.L.length - 1);
87
- this.L.splice(this.L.length - 1);
89
+ this.L.splice(-1);
88
90
  // Update the swapped node assuming we didn't remove the end of the list
89
91
  if (position !== this.L.length) {
90
92
  this.update(this.L[position]);
package/dist/heap.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmBH;;GAEG;AACU,QAAA,cAAc,GAAsB;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC;IAEhC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,SAAS;CACrB,CAAC;AAUF;;GAEG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAAmB,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;QACpC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,IAAI;QACV,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACI,GAAG;QACT,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAChB,oEAAoE;QACpE,OAAO,CAAE,CAAC,KAAK,CAAC;IACjB,CAAC;IAED;;;;;O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AEO,IAAI,CAAC,CAAS,EAAE,CAAS;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;IACxB,CAAC;CACD;AA5HD,oBA4HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tconstructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T {\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(this.L.length - 1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\tthis.update(this.L[position]);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\tconst tmp = this.L[k];\n\t\tthis.L[k] = this.L[j];\n\t\tthis.L[k].position = k;\n\t\tthis.L[j] = tmp;\n\t\tthis.L[j].position = j;\n\t}\n}\n"]}
1
+ {"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBH;;;GAGG;AACU,QAAA,cAAc,GAAsB;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC;IAEhC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,SAAS;CACrB,CAAC;AAWF;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAAmB,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;QACpC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,IAAI;QACV,OAAO,IAAI,CAAC,CAAC,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D,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBAC7D,MAAM;aACN;YACD,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAChB,CAAC,GAAG,CAAC,CAAC;SACN;IACF,CAAC;IAEO,IAAI,CAAC,CAAS,EAAE,CAAS;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;IACxB,CAAC;CACD;AA5HD,oBA4HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n * @public\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n * @public\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n * @public\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n * @public\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tconstructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T {\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(-1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\tthis.update(this.L[position]);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\tconst tmp = this.L[k];\n\t\tthis.L[k] = this.L[j];\n\t\tthis.L[k].position = k;\n\t\tthis.L[j] = tmp;\n\t\tthis.L[j].position = j;\n\t}\n}\n"]}
package/dist/lazy.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  /**
6
6
  * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.
7
+ * @public
7
8
  */
8
9
  export declare class Lazy<T> {
9
10
  private readonly valueGenerator;
@@ -28,6 +29,7 @@ export declare class Lazy<T> {
28
29
  * the promise is used, e.g. await, then, catch ...
29
30
  * The execute function is only called once.
30
31
  * All calls are then proxied to the promise returned by the execute method.
32
+ * @public
31
33
  */
32
34
  export declare class LazyPromise<T> implements Promise<T> {
33
35
  private readonly execute;
@@ -1 +1 @@
1
- {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,IAAI,CAAC,CAAC;IAON,OAAO,CAAC,QAAQ,CAAC,cAAc;IAN3C,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,UAAU,CAAkB;IACpC;;;OAGG;gBAC0B,cAAc,EAAE,MAAM,CAAC;IAEpD;;OAEG;IACH,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,CAAC,CAOpB;CACD;AAED;;;;;GAKG;AACH,qBAAa,WAAW,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IAOpC,OAAO,CAAC,QAAQ,CAAC,OAAO;IANpC,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAExC;IAED,OAAO,CAAC,MAAM,CAAyB;gBAEV,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAEzC,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,EAE/C,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAEjF,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GACjF,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAKlB,KAAK,CAAC,OAAO,GAAG,KAAK,EAEjC,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,OAA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,GAAG,QAAQ,CAAC;IAKlB,KAAK,CAAC,OAAO,GAAG,KAAK,EAGjC,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAC/E,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC;IAMV,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;YAK/D,UAAU;CAMxB"}
package/dist/lazy.js CHANGED
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.LazyPromise = exports.Lazy = void 0;
8
8
  /**
9
9
  * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.
10
+ * @public
10
11
  */
11
12
  class Lazy {
12
13
  /**
@@ -41,24 +42,28 @@ exports.Lazy = Lazy;
41
42
  * the promise is used, e.g. await, then, catch ...
42
43
  * The execute function is only called once.
43
44
  * All calls are then proxied to the promise returned by the execute method.
45
+ * @public
44
46
  */
45
47
  class LazyPromise {
46
- constructor(execute) {
47
- this.execute = execute;
48
- }
49
48
  get [Symbol.toStringTag]() {
50
49
  return this.getPromise()[Symbol.toStringTag];
51
50
  }
51
+ constructor(execute) {
52
+ this.execute = execute;
53
+ }
54
+ // eslint-disable-next-line unicorn/no-thenable
52
55
  async then(
53
56
  // eslint-disable-next-line @rushstack/no-new-null
54
57
  onfulfilled,
55
- // eslint-disable-next-line @rushstack/no-new-null
58
+ // TODO: Use `unknown` instead (API breaking)
59
+ // eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any
56
60
  onrejected) {
57
61
  // eslint-disable-next-line prefer-rest-params
58
62
  return this.getPromise().then(...arguments);
59
63
  }
60
64
  async catch(
61
- // eslint-disable-next-line @rushstack/no-new-null
65
+ // TODO: Use `unknown` instead (API breaking)
66
+ // eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any
62
67
  onrejected) {
63
68
  // eslint-disable-next-line prefer-rest-params
64
69
  return this.getPromise().catch(...arguments);
package/dist/lazy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAA6B,cAAuB;QAAvB,mBAAc,GAAd,cAAc,CAAS;QAL5C,eAAU,GAAY,KAAK,CAAC;IAKmB,CAAC;IAExD;;OAEG;IACH,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;SACpC;QACD,oEAAoE;QACpE,OAAO,IAAI,CAAC,MAAO,CAAC;IACrB,CAAC;CACD;AA3BD,oBA2BC;AAED;;;;;GAKG;AACH,MAAa,WAAW;IAOvB,YAA6B,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAN1D,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9B,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAMM,KAAK,CAAC,IAAI;IAChB,kDAAkD;IAClD,WAAiF;IACjF,kDAAkD;IAClD,UAAmF;QAEnF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAqB,GAAG,SAAS,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,KAAK;IACjB,kDAAkD;IAClD,UAAiF;QAEjF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAU,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,kDAAkD;IAC3C,KAAK,CAAC,OAAO,CAAC,SAA2C;QAC/D,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,UAAU;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;SAC7B;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AAvCD,kCAuCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.\n */\nexport class Lazy<T> {\n\tprivate _value: T | undefined;\n\tprivate _evaluated: boolean = false;\n\t/**\n\t * Instantiates an instance of Lazy<T>.\n\t * @param valueGenerator - The function that will generate the value when value is accessed the first time.\n\t */\n\tconstructor(private readonly valueGenerator: () => T) {}\n\n\t/**\n\t * Return true if the value as been generated, otherwise false.\n\t */\n\tpublic get evaluated(): boolean {\n\t\treturn this._evaluated;\n\t}\n\n\t/**\n\t * Get the value. If this is the first call the value will be generated.\n\t */\n\tpublic get value(): T {\n\t\tif (!this._evaluated) {\n\t\t\tthis._evaluated = true;\n\t\t\tthis._value = this.valueGenerator();\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this._value!;\n\t}\n}\n\n/**\n * A lazy evaluated promise. The execute function is delayed until\n * the promise is used, e.g. await, then, catch ...\n * The execute function is only called once.\n * All calls are then proxied to the promise returned by the execute method.\n */\nexport class LazyPromise<T> implements Promise<T> {\n\tpublic get [Symbol.toStringTag](): string {\n\t\treturn this.getPromise()[Symbol.toStringTag];\n\t}\n\n\tprivate result: Promise<T> | undefined;\n\n\tconstructor(private readonly execute: () => Promise<T>) {}\n\n\tpublic async then<TResult1 = T, TResult2 = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().then<TResult1, TResult2>(...arguments);\n\t}\n\n\tpublic async catch<TResult = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined,\n\t): Promise<T | TResult> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().catch<TResult>(...arguments);\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async finally(onfinally?: (() => void) | null | undefined): Promise<T> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().finally(...arguments);\n\t}\n\n\tprivate async getPromise(): Promise<T> {\n\t\tif (this.result === undefined) {\n\t\t\tthis.result = this.execute();\n\t\t}\n\t\treturn this.result;\n\t}\n}\n"]}
1
+ {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAAoC,cAAuB;QAAvB,mBAAc,GAAd,cAAc,CAAS;QALnD,eAAU,GAAY,KAAK,CAAC;IAK0B,CAAC;IAE/D;;OAEG;IACH,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;SACpC;QACD,oEAAoE;QACpE,OAAO,IAAI,CAAC,MAAO,CAAC;IACrB,CAAC;CACD;AA3BD,oBA2BC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IACvB,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9B,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAID,YAAoC,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAEjE,+CAA+C;IACxC,KAAK,CAAC,IAAI;IAChB,kDAAkD;IAClD,WAAiF;IACjF,6CAA6C;IAC7C,sFAAsF;IACtF,UAAmF;QAEnF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAqB,GAAG,SAAS,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,KAAK;IACjB,6CAA6C;IAC7C,sFAAsF;IACtF,UAAiF;QAEjF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAU,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,kDAAkD;IAC3C,KAAK,CAAC,OAAO,CAAC,SAA2C;QAC/D,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,UAAU;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;SAC7B;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AA1CD,kCA0CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.\n * @public\n */\nexport class Lazy<T> {\n\tprivate _value: T | undefined;\n\tprivate _evaluated: boolean = false;\n\t/**\n\t * Instantiates an instance of Lazy<T>.\n\t * @param valueGenerator - The function that will generate the value when value is accessed the first time.\n\t */\n\tpublic constructor(private readonly valueGenerator: () => T) {}\n\n\t/**\n\t * Return true if the value as been generated, otherwise false.\n\t */\n\tpublic get evaluated(): boolean {\n\t\treturn this._evaluated;\n\t}\n\n\t/**\n\t * Get the value. If this is the first call the value will be generated.\n\t */\n\tpublic get value(): T {\n\t\tif (!this._evaluated) {\n\t\t\tthis._evaluated = true;\n\t\t\tthis._value = this.valueGenerator();\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this._value!;\n\t}\n}\n\n/**\n * A lazy evaluated promise. The execute function is delayed until\n * the promise is used, e.g. await, then, catch ...\n * The execute function is only called once.\n * All calls are then proxied to the promise returned by the execute method.\n * @public\n */\nexport class LazyPromise<T> implements Promise<T> {\n\tpublic get [Symbol.toStringTag](): string {\n\t\treturn this.getPromise()[Symbol.toStringTag];\n\t}\n\n\tprivate result: Promise<T> | undefined;\n\n\tpublic constructor(private readonly execute: () => Promise<T>) {}\n\n\t// eslint-disable-next-line unicorn/no-thenable\n\tpublic async then<TResult1 = T, TResult2 = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().then<TResult1, TResult2>(...arguments);\n\t}\n\n\tpublic async catch<TResult = never>(\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined,\n\t): Promise<T | TResult> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().catch<TResult>(...arguments);\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async finally(onfinally?: (() => void) | null | undefined): Promise<T> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().finally(...arguments);\n\t}\n\n\tprivate async getPromise(): Promise<T> {\n\t\tif (this.result === undefined) {\n\t\t\tthis.result = this.execute();\n\t\t}\n\t\treturn this.result;\n\t}\n}\n"]}
@@ -7,8 +7,9 @@
7
7
  * - indefinite: entries don't expire and must be explicitly removed
8
8
  * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
9
9
  * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
10
+ * @public
10
11
  */
11
- export declare type PromiseCacheExpiry = {
12
+ export type PromiseCacheExpiry = {
12
13
  policy: "indefinite";
13
14
  } | {
14
15
  policy: "absolute" | "sliding";
@@ -16,16 +17,22 @@ export declare type PromiseCacheExpiry = {
16
17
  };
17
18
  /**
18
19
  * Options for configuring the {@link PromiseCache}
20
+ * @public
19
21
  */
20
22
  export interface PromiseCacheOptions {
21
- /** Common expiration policy for all items added to this cache */
23
+ /**
24
+ * Common expiration policy for all items added to this cache
25
+ */
22
26
  expiry?: PromiseCacheExpiry;
23
- /** If the stored Promise is rejected with a particular error, should the given key be removed? */
24
- removeOnError?: (e: any) => boolean;
27
+ /**
28
+ * If the stored Promise is rejected with a particular error, should the given key be removed?
29
+ */
30
+ removeOnError?: (error: any) => boolean;
25
31
  }
26
32
  /**
27
33
  * A specialized cache for async work, allowing you to safely cache the promised result of some async work
28
34
  * without fear of running it multiple times or losing track of errors.
35
+ * @public
29
36
  */
30
37
  export declare class PromiseCache<TKey, TResult> {
31
38
  private readonly cache;