@vertexvis/utils 0.24.6-canary.0 → 1.0.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/async.d.ts CHANGED
@@ -1,79 +1,79 @@
1
- /**
2
- * Converts an async generator to an array of results.
3
- *
4
- * @param generator The generator to convert.
5
- * @returns A promise that resolves with an array of results yielded by the
6
- * generator.
7
- */
8
- export declare function asArray<T>(generator: AsyncGenerator<T>): Promise<T[]>;
9
- /**
10
- * Returns a promise that resolves successfully after the given delay.
11
- *
12
- * @param ms The delay in milliseconds.
13
- */
14
- export declare function delay(ms: number): Promise<void>;
15
- /**
16
- * Delays the resolution of `promise` by the given delay.
17
- *
18
- * @param ms The delay in milliseconds.
19
- * @param promise The promise to delay.
20
- */
21
- export declare function delay<T>(ms: number, promise: Promise<T>): Promise<T>;
22
- /**
23
- * Returns a promise that will reject after the given duration.
24
- *
25
- * @param ms A duration in milliseconds.
26
- */
27
- export declare function timeout(ms: number): Promise<void>;
28
- /**
29
- * Assigns a timeout to the given promise, where if the promise doesn't complete
30
- * within the given duration an exception will be thrown.
31
- *
32
- * @param ms The timeout, in milliseconds.
33
- * @param promise The promise to assign a timeout to.
34
- */
35
- export declare function timeout<T>(ms: number, promise: Promise<T>): Promise<T>;
36
- export interface RetryOptions {
37
- /**
38
- * An array of delays that are used between each retry attempt.
39
- */
40
- delaysInMs?: number[];
41
- /**
42
- * The maximum number of retries that will be attempted.
43
- */
44
- maxRetries?: number;
45
- }
46
- /**
47
- * Executes and reattempts execution of an asynchronous function if it throws an
48
- * error. By default, this function will only retry once and reexecute
49
- * immediately after the previous execution throws. You can configure the number
50
- * of retry attempts and delays with the `maxRetries` and `delaysInMs` options.
51
- *
52
- * The `delaysInMs` is an array of delays in milliseconds for each retry
53
- * attempt. If there are more retry attempts than delays, the last delay will be
54
- * used.
55
- *
56
- * @param process The process to execute.
57
- * @param opts Options to configure retry behavior.
58
- * @returns A promise that resolves with a successful value, or the original
59
- * rejected value if the process fails.
60
- */
61
- export declare function retry<T>(process: () => Promise<T>, opts?: RetryOptions): Promise<T>;
62
- /**
63
- * Returns a promise that either resolves with the result of `promise`, or a
64
- * value that indicates the execution was aborted.
65
- *
66
- * **Note:** Because Promises in JS cannot be canceled, an abort signal will not
67
- * cancel the execution of the promise.
68
- *
69
- * @param signal A signal that communicates the process should be aborted.
70
- * @param promise A promise who's value will be returned if not aborted.
71
- * @returns A value indicating if the process was aborted, or the value of
72
- * `promise`.
73
- */
74
- export declare function abort<T>(signal: AbortSignal, promise: Promise<T>): Promise<{
75
- aborted: true;
76
- } | {
77
- aborted: false;
78
- result: T;
79
- }>;
1
+ /**
2
+ * Converts an async generator to an array of results.
3
+ *
4
+ * @param generator The generator to convert.
5
+ * @returns A promise that resolves with an array of results yielded by the
6
+ * generator.
7
+ */
8
+ export declare function asArray<T>(generator: AsyncGenerator<T>): Promise<T[]>;
9
+ /**
10
+ * Returns a promise that resolves successfully after the given delay.
11
+ *
12
+ * @param ms The delay in milliseconds.
13
+ */
14
+ export declare function delay(ms: number): Promise<void>;
15
+ /**
16
+ * Delays the resolution of `promise` by the given delay.
17
+ *
18
+ * @param ms The delay in milliseconds.
19
+ * @param promise The promise to delay.
20
+ */
21
+ export declare function delay<T>(ms: number, promise: Promise<T>): Promise<T>;
22
+ /**
23
+ * Returns a promise that will reject after the given duration.
24
+ *
25
+ * @param ms A duration in milliseconds.
26
+ */
27
+ export declare function timeout(ms: number): Promise<void>;
28
+ /**
29
+ * Assigns a timeout to the given promise, where if the promise doesn't complete
30
+ * within the given duration an exception will be thrown.
31
+ *
32
+ * @param ms The timeout, in milliseconds.
33
+ * @param promise The promise to assign a timeout to.
34
+ */
35
+ export declare function timeout<T>(ms: number, promise: Promise<T>): Promise<T>;
36
+ export interface RetryOptions {
37
+ /**
38
+ * An array of delays that are used between each retry attempt.
39
+ */
40
+ delaysInMs?: number[];
41
+ /**
42
+ * The maximum number of retries that will be attempted.
43
+ */
44
+ maxRetries?: number;
45
+ }
46
+ /**
47
+ * Executes and reattempts execution of an asynchronous function if it throws an
48
+ * error. By default, this function will only retry once and reexecute
49
+ * immediately after the previous execution throws. You can configure the number
50
+ * of retry attempts and delays with the `maxRetries` and `delaysInMs` options.
51
+ *
52
+ * The `delaysInMs` is an array of delays in milliseconds for each retry
53
+ * attempt. If there are more retry attempts than delays, the last delay will be
54
+ * used.
55
+ *
56
+ * @param process The process to execute.
57
+ * @param opts Options to configure retry behavior.
58
+ * @returns A promise that resolves with a successful value, or the original
59
+ * rejected value if the process fails.
60
+ */
61
+ export declare function retry<T>(process: () => Promise<T>, opts?: RetryOptions): Promise<T>;
62
+ /**
63
+ * Returns a promise that either resolves with the result of `promise`, or a
64
+ * value that indicates the execution was aborted.
65
+ *
66
+ * **Note:** Because Promises in JS cannot be canceled, an abort signal will not
67
+ * cancel the execution of the promise.
68
+ *
69
+ * @param signal A signal that communicates the process should be aborted.
70
+ * @param promise A promise who's value will be returned if not aborted.
71
+ * @returns A value indicating if the process was aborted, or the value of
72
+ * `promise`.
73
+ */
74
+ export declare function abort<T>(signal: AbortSignal, promise: Promise<T>): Promise<{
75
+ aborted: true;
76
+ } | {
77
+ aborted: false;
78
+ result: T;
79
+ }>;
@@ -1,58 +1,58 @@
1
- /**
2
- * A `BinaryReader` represents a view and offset for iteratively reading data
3
- * from an `ArrayBuffer`.
4
- *
5
- * Readers are created by calling the `BinaryReader.fromArrayBuffer()` method,
6
- * and passed to helper methods such as `BinaryReader.readInt32()` to read data
7
- * from the buffer. These helpers return a new `BinaryReader` that contains an
8
- * adjusted offset and the read value, and can further be passed to additional
9
- * helpers.
10
- *
11
- * @example
12
- * ```
13
- * // Reading from an `ArrayBuffer`
14
- * const reader = BinaryReader.fromArrayBuffer(buffer);
15
- * const messageLength = BinaryReader.readInt32(reader);
16
- * console.log(messageLength.value); // 11
17
- *
18
- * const message = BinaryReader.readUtf8String(messageLength.value, messageLength);
19
- * console.log(message.value); // Hello world
20
- * ```
21
- */
22
- export interface BinaryReader {
23
- offset: number;
24
- data: DataView;
25
- }
26
- interface BinaryReaderValue<T> extends BinaryReader {
27
- value: T;
28
- }
29
- /**
30
- * Returns a new `BinaryReader` for an `ArrayBuffer`.
31
- */
32
- export declare const fromArrayBuffer: (buffer: ArrayBuffer) => BinaryReader;
33
- /**
34
- * Returns a `BinaryReader` that contains the read Int32 value at the given
35
- * reader's offset. The returned reader will have its offset adjusted so it can
36
- * be passed to the next helper.
37
- */
38
- export declare const readInt32: (reader: BinaryReader) => BinaryReaderValue<number>;
39
- /**
40
- * Returns a `BinaryReader` that contains the read UTF-8 string at the given
41
- * reader's offset. The returned reader will have its offset adjusted so it can
42
- * be passed to the next helper.
43
- */
44
- export declare const readUtf8String: (length: number, reader: BinaryReader) => BinaryReaderValue<string>;
45
- /**
46
- * Returns a `BinaryReader` that contains the a signed `Int8Array` start from
47
- * the given reader's offset to the given length. The returned reader will have
48
- * its offset adjusted so it can be passed to the next helper.
49
- */
50
- export declare const readInt8Array: (length: number, reader: BinaryReader) => BinaryReaderValue<Int8Array>;
51
- /**
52
- * Returns a `BinaryReader` that contains the a signed `Int8Array` sliced from
53
- * the start of the reader's offset to offset + length. The new reader value has
54
- * an offset of zero, so downstream operations will not bee effected by the
55
- * previous offset
56
- */
57
- export declare const sliceInt8Array: (length: number, reader: BinaryReader) => BinaryReaderValue<Int8Array>;
58
- export {};
1
+ /**
2
+ * A `BinaryReader` represents a view and offset for iteratively reading data
3
+ * from an `ArrayBuffer`.
4
+ *
5
+ * Readers are created by calling the `BinaryReader.fromArrayBuffer()` method,
6
+ * and passed to helper methods such as `BinaryReader.readInt32()` to read data
7
+ * from the buffer. These helpers return a new `BinaryReader` that contains an
8
+ * adjusted offset and the read value, and can further be passed to additional
9
+ * helpers.
10
+ *
11
+ * @example
12
+ * ```
13
+ * // Reading from an `ArrayBuffer`
14
+ * const reader = BinaryReader.fromArrayBuffer(buffer);
15
+ * const messageLength = BinaryReader.readInt32(reader);
16
+ * console.log(messageLength.value); // 11
17
+ *
18
+ * const message = BinaryReader.readUtf8String(messageLength.value, messageLength);
19
+ * console.log(message.value); // Hello world
20
+ * ```
21
+ */
22
+ export interface BinaryReader {
23
+ offset: number;
24
+ data: DataView;
25
+ }
26
+ interface BinaryReaderValue<T> extends BinaryReader {
27
+ value: T;
28
+ }
29
+ /**
30
+ * Returns a new `BinaryReader` for an `ArrayBuffer`.
31
+ */
32
+ export declare const fromArrayBuffer: (buffer: ArrayBuffer) => BinaryReader;
33
+ /**
34
+ * Returns a `BinaryReader` that contains the read Int32 value at the given
35
+ * reader's offset. The returned reader will have its offset adjusted so it can
36
+ * be passed to the next helper.
37
+ */
38
+ export declare const readInt32: (reader: BinaryReader) => BinaryReaderValue<number>;
39
+ /**
40
+ * Returns a `BinaryReader` that contains the read UTF-8 string at the given
41
+ * reader's offset. The returned reader will have its offset adjusted so it can
42
+ * be passed to the next helper.
43
+ */
44
+ export declare const readUtf8String: (length: number, reader: BinaryReader) => BinaryReaderValue<string>;
45
+ /**
46
+ * Returns a `BinaryReader` that contains the a signed `Int8Array` start from
47
+ * the given reader's offset to the given length. The returned reader will have
48
+ * its offset adjusted so it can be passed to the next helper.
49
+ */
50
+ export declare const readInt8Array: (length: number, reader: BinaryReader) => BinaryReaderValue<Int8Array>;
51
+ /**
52
+ * Returns a `BinaryReader` that contains the a signed `Int8Array` sliced from
53
+ * the start of the reader's offset to offset + length. The new reader value has
54
+ * an offset of zero, so downstream operations will not bee effected by the
55
+ * previous offset
56
+ */
57
+ export declare const sliceInt8Array: (length: number, reader: BinaryReader) => BinaryReaderValue<Int8Array>;
58
+ export {};