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