@fluidframework/core-utils 2.0.0-internal.7.0.0 → 2.0.0-internal.7.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/core-utils
2
2
 
3
+ ## 2.0.0-internal.7.1.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.0.0-internal.7.0.0
4
8
 
5
9
  ### Major Changes
@@ -1,4 +1,13 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-common-report.json"
3
+ "extends": "@fluidframework/build-common/api-extractor-base.json",
4
+
5
+ // TODO: Fix violations and remove these rule overrides
6
+ "messages": {
7
+ "extractorMessageReporting": {
8
+ "ae-missing-release-tag": {
9
+ "logLevel": "none"
10
+ }
11
+ }
12
+ }
4
13
  }
@@ -0,0 +1,147 @@
1
+ ## API Report File for "@fluidframework/core-utils"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ // @public
8
+ export function assert(condition: boolean, message: string | number): asserts condition;
9
+
10
+ // @internal
11
+ export const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
12
+
13
+ // @public
14
+ export class Deferred<T> {
15
+ constructor();
16
+ get isCompleted(): boolean;
17
+ get promise(): Promise<T>;
18
+ reject(error: any): void;
19
+ resolve(value: T | PromiseLike<T>): void;
20
+ }
21
+
22
+ // @public
23
+ export const delay: (timeMs: number) => Promise<void>;
24
+
25
+ // @public
26
+ export class Heap<T> {
27
+ constructor(comp: IComparer<T>);
28
+ add(x: T): IHeapNode<T>;
29
+ // (undocumented)
30
+ comp: IComparer<T>;
31
+ count(): number;
32
+ get(): T;
33
+ peek(): IHeapNode<T>;
34
+ remove(node: IHeapNode<T>): void;
35
+ update(node: IHeapNode<T>): void;
36
+ }
37
+
38
+ // @public
39
+ export interface IComparer<T> {
40
+ compare(a: T, b: T): number;
41
+ min: T;
42
+ }
43
+
44
+ // @public
45
+ export interface IHeapNode<T> {
46
+ // (undocumented)
47
+ position: number;
48
+ // (undocumented)
49
+ value: T;
50
+ }
51
+
52
+ // @public
53
+ export interface IPromiseTimer extends ITimer {
54
+ start(): Promise<IPromiseTimerResult>;
55
+ }
56
+
57
+ // @public (undocumented)
58
+ export interface IPromiseTimerResult {
59
+ // (undocumented)
60
+ timerResult: "timeout" | "cancel";
61
+ }
62
+
63
+ // @public (undocumented)
64
+ export interface ITimer {
65
+ clear(): void;
66
+ readonly hasTimer: boolean;
67
+ start(): void;
68
+ }
69
+
70
+ // @public
71
+ export class Lazy<T> {
72
+ constructor(valueGenerator: () => T);
73
+ get evaluated(): boolean;
74
+ get value(): T;
75
+ }
76
+
77
+ // @public
78
+ export class LazyPromise<T> implements Promise<T> {
79
+ // (undocumented)
80
+ get [Symbol.toStringTag](): string;
81
+ constructor(execute: () => Promise<T>);
82
+ // (undocumented)
83
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
84
+ // (undocumented)
85
+ finally(onfinally?: (() => void) | null | undefined): Promise<T>;
86
+ // (undocumented)
87
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
88
+ }
89
+
90
+ // @public
91
+ export const NumberComparer: IComparer<number>;
92
+
93
+ // @public
94
+ export class PromiseCache<TKey, TResult> {
95
+ constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
96
+ add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
97
+ addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult>;
98
+ addValue(key: TKey, value: TResult): boolean;
99
+ addValueOrGet(key: TKey, value: TResult): Promise<TResult>;
100
+ get(key: TKey): Promise<TResult> | undefined;
101
+ has(key: TKey): boolean;
102
+ remove(key: TKey): boolean;
103
+ }
104
+
105
+ // @public
106
+ export type PromiseCacheExpiry = {
107
+ policy: "indefinite";
108
+ } | {
109
+ policy: "absolute" | "sliding";
110
+ durationMs: number;
111
+ };
112
+
113
+ // @public
114
+ export interface PromiseCacheOptions {
115
+ expiry?: PromiseCacheExpiry;
116
+ removeOnError?: (error: any) => boolean;
117
+ }
118
+
119
+ // @public
120
+ export class PromiseTimer implements IPromiseTimer {
121
+ constructor(defaultTimeout: number, defaultHandler: () => void);
122
+ // (undocumented)
123
+ clear(): void;
124
+ get hasTimer(): boolean;
125
+ start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult>;
126
+ // (undocumented)
127
+ protected wrapHandler(handler: () => void): void;
128
+ }
129
+
130
+ // @public
131
+ export function setLongTimeout(timeoutFn: () => void, timeoutMs: number, setTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void): ReturnType<typeof setTimeout>;
132
+
133
+ // @public
134
+ export class Timer implements ITimer {
135
+ constructor(defaultTimeout: number, defaultHandler: () => void, getCurrentTick?: () => number);
136
+ clear(): void;
137
+ get hasTimer(): boolean;
138
+ restart(ms?: number, handler?: () => void): void;
139
+ start(ms?: number, handler?: () => void): void;
140
+ }
141
+
142
+ // @public
143
+ export function unreachableCase(_: never, message?: string): never;
144
+
145
+ // (No @packageDocumentation comment for this package)
146
+
147
+ ```
@@ -0,0 +1,381 @@
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
+ */
11
+ export declare function assert(condition: boolean, message: string | number): asserts condition;
12
+
13
+ /* Excluded from this release type: compareArrays */
14
+
15
+ /**
16
+ * A deferred creates a promise and the ability to resolve or reject it
17
+ */
18
+ export declare class Deferred<T> {
19
+ private readonly p;
20
+ private res;
21
+ private rej;
22
+ private completed;
23
+ constructor();
24
+ /**
25
+ * Returns whether the underlying promise has been completed
26
+ */
27
+ get isCompleted(): boolean;
28
+ /**
29
+ * Retrieves the underlying promise for the deferred
30
+ *
31
+ * @returns the underlying promise
32
+ */
33
+ get promise(): Promise<T>;
34
+ /**
35
+ * Resolves the promise
36
+ *
37
+ * @param value - the value to resolve the promise with
38
+ */
39
+ resolve(value: T | PromiseLike<T>): void;
40
+ /**
41
+ * Rejects the promise
42
+ *
43
+ * @param value - the value to reject the promise with
44
+ */
45
+ reject(error: any): void;
46
+ }
47
+
48
+ /**
49
+ * Returns a promise that resolves after `timeMs`.
50
+ * @param timeMs - Time in milliseconds to wait.
51
+ */
52
+ export declare const delay: (timeMs: number) => Promise<void>;
53
+
54
+ /**
55
+ * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
56
+ */
57
+ export declare class Heap<T> {
58
+ comp: IComparer<T>;
59
+ private L;
60
+ /**
61
+ * Creates an instance of `Heap` with comparer.
62
+ * @param comp - A comparer that specify how elements are ordered.
63
+ */
64
+ constructor(comp: IComparer<T>);
65
+ /**
66
+ * Return the smallest element in the heap as determined by the order of the comparer
67
+ *
68
+ * @returns Heap node containing the smallest element
69
+ */
70
+ peek(): IHeapNode<T>;
71
+ /**
72
+ * Get and remove the smallest element in the heap as determined by the order of the comparer
73
+ *
74
+ * @returns The smallest value in the heap
75
+ */
76
+ get(): T;
77
+ /**
78
+ * Add a value to the heap
79
+ *
80
+ * @param x - value to add
81
+ * @returns The heap node that contains the value
82
+ */
83
+ add(x: T): IHeapNode<T>;
84
+ /**
85
+ * Allows for the Heap to be updated after a node's value changes.
86
+ */
87
+ update(node: IHeapNode<T>): void;
88
+ /**
89
+ * Removes the given node from the heap.
90
+ *
91
+ * @param node - The node to remove from the heap.
92
+ */
93
+ remove(node: IHeapNode<T>): void;
94
+ /**
95
+ * Get the number of elements in the Heap.
96
+ *
97
+ * @returns The number of elements in the Heap.
98
+ */
99
+ count(): number;
100
+ private fixup;
101
+ private isGreaterThanParent;
102
+ private fixdown;
103
+ private swap;
104
+ }
105
+
106
+ /**
107
+ * Interface for a comparer.
108
+ */
109
+ export declare interface IComparer<T> {
110
+ /**
111
+ * The minimum value of type T.
112
+ */
113
+ min: T;
114
+ /**
115
+ * Compare the two value
116
+ *
117
+ * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise
118
+ */
119
+ compare(a: T, b: T): number;
120
+ }
121
+
122
+ /**
123
+ * Interface to a node in {@link Heap}.
124
+ */
125
+ export declare interface IHeapNode<T> {
126
+ value: T;
127
+ position: number;
128
+ }
129
+
130
+ /**
131
+ * Timer which offers a promise that fulfills when the timer
132
+ * completes.
133
+ */
134
+ export declare interface IPromiseTimer extends ITimer {
135
+ /**
136
+ * Starts the timer and returns a promise that
137
+ * resolves when the timer times out or is canceled.
138
+ */
139
+ start(): Promise<IPromiseTimerResult>;
140
+ }
141
+
142
+ export declare interface IPromiseTimerResult {
143
+ timerResult: "timeout" | "cancel";
144
+ }
145
+
146
+ export declare interface ITimer {
147
+ /**
148
+ * True if timer is currently running
149
+ */
150
+ readonly hasTimer: boolean;
151
+ /**
152
+ * Starts the timer
153
+ */
154
+ start(): void;
155
+ /**
156
+ * Cancels the timer if already running
157
+ */
158
+ clear(): void;
159
+ }
160
+
161
+ /**
162
+ * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.
163
+ */
164
+ export declare class Lazy<T> {
165
+ private readonly valueGenerator;
166
+ private _value;
167
+ private _evaluated;
168
+ /**
169
+ * Instantiates an instance of Lazy<T>.
170
+ * @param valueGenerator - The function that will generate the value when value is accessed the first time.
171
+ */
172
+ constructor(valueGenerator: () => T);
173
+ /**
174
+ * Return true if the value as been generated, otherwise false.
175
+ */
176
+ get evaluated(): boolean;
177
+ /**
178
+ * Get the value. If this is the first call the value will be generated.
179
+ */
180
+ get value(): T;
181
+ }
182
+
183
+ /**
184
+ * A lazy evaluated promise. The execute function is delayed until
185
+ * the promise is used, e.g. await, then, catch ...
186
+ * The execute function is only called once.
187
+ * All calls are then proxied to the promise returned by the execute method.
188
+ */
189
+ export declare class LazyPromise<T> implements Promise<T> {
190
+ private readonly execute;
191
+ get [Symbol.toStringTag](): string;
192
+ private result;
193
+ constructor(execute: () => Promise<T>);
194
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
195
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
196
+ finally(onfinally?: (() => void) | null | undefined): Promise<T>;
197
+ private getPromise;
198
+ }
199
+
200
+ /**
201
+ * A comparer for numbers.
202
+ */
203
+ export declare const NumberComparer: IComparer<number>;
204
+
205
+ /**
206
+ * A specialized cache for async work, allowing you to safely cache the promised result of some async work
207
+ * without fear of running it multiple times or losing track of errors.
208
+ */
209
+ export declare class PromiseCache<TKey, TResult> {
210
+ private readonly cache;
211
+ private readonly gc;
212
+ private readonly removeOnError;
213
+ /**
214
+ * Create the PromiseCache with the given options, with the following defaults:
215
+ *
216
+ * expiry: indefinite, removeOnError: true for all errors
217
+ */
218
+ constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
219
+ /**
220
+ * Check if there's anything cached at the given key
221
+ */
222
+ has(key: TKey): boolean;
223
+ /**
224
+ * Get the Promise for the given key, or undefined if it's not found.
225
+ * Extend expiry if applicable.
226
+ */
227
+ get(key: TKey): Promise<TResult> | undefined;
228
+ /**
229
+ * Remove the Promise for the given key, returning true if it was found and removed
230
+ */
231
+ remove(key: TKey): boolean;
232
+ /**
233
+ * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
234
+ * Returns a Promise for the added or existing async work being done at that key.
235
+ * @param key - key name where to store the async work
236
+ * @param asyncFn - the async work to do and store, if not already in progress under the given key
237
+ */
238
+ addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult>;
239
+ /**
240
+ * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
241
+ * Returns false if the cache already contained an entry at that key, and true otherwise.
242
+ * @param key - key name where to store the async work
243
+ * @param asyncFn - the async work to do and store, if not already in progress under the given key
244
+ */
245
+ add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
246
+ /**
247
+ * Try to add the given value, without overwriting an existing cache entry at that key.
248
+ * Returns a Promise for the added or existing async work being done at that key.
249
+ * @param key - key name where to store the async work
250
+ * @param value - value to store
251
+ */
252
+ addValueOrGet(key: TKey, value: TResult): Promise<TResult>;
253
+ /**
254
+ * Try to add the given value, without overwriting an existing cache entry at that key.
255
+ * Returns false if the cache already contained an entry at that key, and true otherwise.
256
+ * @param key - key name where to store the value
257
+ * @param value - value to store
258
+ */
259
+ addValue(key: TKey, value: TResult): boolean;
260
+ }
261
+
262
+ /**
263
+ * Three supported expiry policies:
264
+ * - indefinite: entries don't expire and must be explicitly removed
265
+ * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
266
+ * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
267
+ */
268
+ export declare type PromiseCacheExpiry = {
269
+ policy: "indefinite";
270
+ } | {
271
+ policy: "absolute" | "sliding";
272
+ durationMs: number;
273
+ };
274
+
275
+ /**
276
+ * Options for configuring the {@link PromiseCache}
277
+ */
278
+ export declare interface PromiseCacheOptions {
279
+ /**
280
+ * Common expiration policy for all items added to this cache
281
+ */
282
+ expiry?: PromiseCacheExpiry;
283
+ /**
284
+ * If the stored Promise is rejected with a particular error, should the given key be removed?
285
+ */
286
+ removeOnError?: (error: any) => boolean;
287
+ }
288
+
289
+ /**
290
+ * This class is a wrapper over setTimeout and clearTimeout which
291
+ * makes it simpler to keep track of recurring timeouts with the
292
+ * same handlers and timeouts, while also providing a promise that
293
+ * resolves when it times out.
294
+ */
295
+ export declare class PromiseTimer implements IPromiseTimer {
296
+ private deferred?;
297
+ private readonly timer;
298
+ /**
299
+ * {@inheritDoc Timer.hasTimer}
300
+ */
301
+ get hasTimer(): boolean;
302
+ constructor(defaultTimeout: number, defaultHandler: () => void);
303
+ /**
304
+ * {@inheritDoc IPromiseTimer.start}
305
+ */
306
+ start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult>;
307
+ clear(): void;
308
+ protected wrapHandler(handler: () => void): void;
309
+ }
310
+
311
+ /**
312
+ * Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.
313
+ * Timeouts may not be exactly accurate due to browser implementations and the OS.
314
+ * https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate
315
+ * @param timeoutFn - Executed when the timeout expires
316
+ * @param timeoutMs - Duration of the timeout in milliseconds
317
+ * @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when
318
+ * timeoutMs greater than maxTimeout
319
+ * @returns The initial timeout
320
+ */
321
+ export declare function setLongTimeout(timeoutFn: () => void, timeoutMs: number, setTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void): ReturnType<typeof setTimeout>;
322
+
323
+ /**
324
+ * This class is a thin wrapper over setTimeout and clearTimeout which
325
+ * makes it simpler to keep track of recurring timeouts with the same
326
+ * or similar handlers and timeouts. This class supports long timeouts
327
+ * or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.
328
+ */
329
+ export declare class Timer implements ITimer {
330
+ private readonly defaultTimeout;
331
+ private readonly defaultHandler;
332
+ private readonly getCurrentTick;
333
+ /**
334
+ * Returns true if the timer is running.
335
+ */
336
+ get hasTimer(): boolean;
337
+ private runningState;
338
+ constructor(defaultTimeout: number, defaultHandler: () => void, getCurrentTick?: () => number);
339
+ /**
340
+ * Calls setTimeout and tracks the resulting timeout.
341
+ * @param ms - overrides default timeout in ms
342
+ * @param handler - overrides default handler
343
+ */
344
+ start(ms?: number, handler?: () => void): void;
345
+ /**
346
+ * Calls clearTimeout on the underlying timeout if running.
347
+ */
348
+ clear(): void;
349
+ /**
350
+ * Restarts the timer with the new handler and duration.
351
+ * If a new handler is passed, the original handler may
352
+ * never execute.
353
+ * This is a potentially more efficient way to clear and start
354
+ * a new timer.
355
+ * @param ms - overrides previous or default timeout in ms
356
+ * @param handler - overrides previous or default handler
357
+ */
358
+ restart(ms?: number, handler?: () => void): void;
359
+ private startCore;
360
+ private handler;
361
+ private calculateRemainingTime;
362
+ }
363
+
364
+ /**
365
+ * This function can be used to assert at compile time that a given value has type never.
366
+ * One common usage is in the default case of a switch block,
367
+ * to ensure that all cases are explicitly handled.
368
+ *
369
+ * Example:
370
+ * ```typescript
371
+ * const bool: true | false = ...;
372
+ * switch(bool) {
373
+ * case true: {...}
374
+ * case false: {...}
375
+ * default: unreachableCase(bool);
376
+ * }
377
+ * ```
378
+ */
379
+ export declare function unreachableCase(_: never, message?: string): never;
380
+
381
+ export { }