@everyonesoftware/common 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +54 -36
- package/package.json +6 -2
- package/sources/asyncIterator.ts +436 -436
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
- package/sources/asyncResult.ts +95 -95
- package/sources/byteList.ts +201 -201
- package/sources/byteListStream.ts +120 -120
- package/sources/byteReadStream.ts +23 -23
- package/sources/byteWriteStream.ts +15 -15
- package/sources/characterList.ts +194 -194
- package/sources/characterListStream.ts +150 -150
- package/sources/characterReadStream.ts +80 -80
- package/sources/characterReadStreamIterator.ts +127 -127
- package/sources/concatenateIterable.ts +118 -118
- package/sources/concatenateIterator.ts +164 -164
- package/sources/currentProcess.ts +157 -157
- package/sources/dateTime.ts +129 -129
- package/sources/depthFirstSearch.ts +229 -229
- package/sources/flatMapIterable.ts +103 -103
- package/sources/flatMapIterator.ts +151 -151
- package/sources/generator.ts +250 -250
- package/sources/index.ts +1 -1
- package/sources/iterator.ts +480 -480
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
- package/sources/javascriptSetSet.ts +133 -133
- package/sources/listQueue.ts +61 -61
- package/sources/listStack.ts +61 -61
- package/sources/luxonDateTime.ts +108 -108
- package/sources/mapAsyncIterator.ts +140 -140
- package/sources/mutableMap.ts +291 -291
- package/sources/node.ts +36 -36
- package/sources/promiseAsyncResult.ts +173 -173
- package/sources/queue.ts +48 -48
- package/sources/recreationDotGovClient.ts +258 -258
- package/sources/searchControl.ts +41 -41
- package/sources/set.ts +243 -243
- package/sources/skipAsyncIterator.ts +144 -144
- package/sources/stack.ts +47 -47
- package/sources/syncResult.ts +299 -299
- package/sources/takeAsyncIterator.ts +140 -140
- package/sources/whereAsyncIterator.ts +142 -142
- package/sources/wonderlandTrailClient.ts +1502 -1502
- package/tests/assertTestTests.ts +74 -74
- package/tests/byteListStreamTests.ts +389 -389
- package/tests/byteListTests.ts +26 -26
- package/tests/characterListStreamTests.ts +390 -390
- package/tests/characterListTests.ts +249 -249
- package/tests/dateTimeTests.ts +29 -29
- package/tests/depthFirstSearchTests.ts +105 -105
- package/tests/generatorTests.ts +85 -85
- package/tests/mutableMapTests.ts +153 -153
- package/tests/promiseAsyncResultTests.ts +687 -687
- package/tests/queueTests.ts +28 -28
- package/tests/recreationDotGovClientTests.ts +190 -190
- package/tests/setTests.ts +139 -139
- package/tests/stackTests.ts +65 -65
- package/tests/syncResultTests.ts +1250 -1250
- package/tests/wonderlandTrailClientTests.ts +451 -451
- package/tsup.config.ts +12 -12
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { AsyncIterator } from "./asyncIterator";
|
|
2
|
-
import { JavascriptAsyncIterator, JavascriptIteratorResult } from "./javascript";
|
|
3
|
-
import { PreCondition } from "./preCondition";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A type that adapts an {@link AsyncIterator} to match a {@link JavascriptAsyncIterator}.
|
|
7
|
-
*/
|
|
8
|
-
export class AsyncIteratorToJavascriptAsyncIteratorAdapter<T> implements JavascriptAsyncIterator<T>
|
|
9
|
-
{
|
|
10
|
-
private readonly iterator: AsyncIterator<T>;
|
|
11
|
-
private hasStarted: boolean;
|
|
12
|
-
|
|
13
|
-
private constructor(iterator: AsyncIterator<T>)
|
|
14
|
-
{
|
|
15
|
-
PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
|
|
16
|
-
|
|
17
|
-
this.iterator = iterator;
|
|
18
|
-
this.hasStarted = false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public static create<T>(iterator: AsyncIterator<T>): AsyncIteratorToJavascriptAsyncIteratorAdapter<T>
|
|
22
|
-
{
|
|
23
|
-
return new AsyncIteratorToJavascriptAsyncIteratorAdapter<T>(iterator);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async next(): Promise<JavascriptIteratorResult<T>>
|
|
27
|
-
{
|
|
28
|
-
if (!this.hasStarted)
|
|
29
|
-
{
|
|
30
|
-
this.hasStarted = true;
|
|
31
|
-
await this.iterator.start();
|
|
32
|
-
}
|
|
33
|
-
else
|
|
34
|
-
{
|
|
35
|
-
await this.iterator.next();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const result: JavascriptIteratorResult<T> = {
|
|
39
|
-
done: !this.iterator.hasCurrent(),
|
|
40
|
-
value: undefined!,
|
|
41
|
-
};
|
|
42
|
-
if (!result.done)
|
|
43
|
-
{
|
|
44
|
-
result.value = this.iterator.getCurrent();
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
1
|
+
import { AsyncIterator } from "./asyncIterator";
|
|
2
|
+
import { JavascriptAsyncIterator, JavascriptIteratorResult } from "./javascript";
|
|
3
|
+
import { PreCondition } from "./preCondition";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A type that adapts an {@link AsyncIterator} to match a {@link JavascriptAsyncIterator}.
|
|
7
|
+
*/
|
|
8
|
+
export class AsyncIteratorToJavascriptAsyncIteratorAdapter<T> implements JavascriptAsyncIterator<T>
|
|
9
|
+
{
|
|
10
|
+
private readonly iterator: AsyncIterator<T>;
|
|
11
|
+
private hasStarted: boolean;
|
|
12
|
+
|
|
13
|
+
private constructor(iterator: AsyncIterator<T>)
|
|
14
|
+
{
|
|
15
|
+
PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
|
|
16
|
+
|
|
17
|
+
this.iterator = iterator;
|
|
18
|
+
this.hasStarted = false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static create<T>(iterator: AsyncIterator<T>): AsyncIteratorToJavascriptAsyncIteratorAdapter<T>
|
|
22
|
+
{
|
|
23
|
+
return new AsyncIteratorToJavascriptAsyncIteratorAdapter<T>(iterator);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async next(): Promise<JavascriptIteratorResult<T>>
|
|
27
|
+
{
|
|
28
|
+
if (!this.hasStarted)
|
|
29
|
+
{
|
|
30
|
+
this.hasStarted = true;
|
|
31
|
+
await this.iterator.start();
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
{
|
|
35
|
+
await this.iterator.next();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result: JavascriptIteratorResult<T> = {
|
|
39
|
+
done: !this.iterator.hasCurrent(),
|
|
40
|
+
value: undefined!,
|
|
41
|
+
};
|
|
42
|
+
if (!result.done)
|
|
43
|
+
{
|
|
44
|
+
result.value = this.iterator.getCurrent();
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
48
|
}
|
package/sources/asyncResult.ts
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
2
|
-
import { isPromise, Type } from "./types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A result object that adds extra behavior beyond the standard {@link Promise}.
|
|
6
|
-
*/
|
|
7
|
-
export abstract class AsyncResult<T> implements Promise<T>
|
|
8
|
-
{
|
|
9
|
-
public static create<T>(action: () => (T | Promise<T>)): AsyncResult<T>;
|
|
10
|
-
public static create<T>(promise: Promise<T>): AsyncResult<T>;
|
|
11
|
-
static create<T>(actionOrPromise: (() => (T | Promise<T>)) | Promise<T>): AsyncResult<T>
|
|
12
|
-
{
|
|
13
|
-
return PromiseAsyncResult.create<T>(isPromise<T>(actionOrPromise) ? actionOrPromise : new Promise<T>(actionOrPromise));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Create a new {@link AsyncResult} that contains the provided value.
|
|
18
|
-
* @param value The value to wrap in a {@link AsyncResult}.
|
|
19
|
-
*/
|
|
20
|
-
public static value<T>(value: T): AsyncResult<T>
|
|
21
|
-
{
|
|
22
|
-
return PromiseAsyncResult.value(value);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Create a new {@link AsyncResult} that contains the provided error.
|
|
27
|
-
* @param error The error to wrap in a {@link AsyncResult}.
|
|
28
|
-
*/
|
|
29
|
-
public static error<T>(error: Error): AsyncResult<T>
|
|
30
|
-
{
|
|
31
|
-
return PromiseAsyncResult.error<T>(error);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public static yield(): AsyncResult<void>
|
|
35
|
-
{
|
|
36
|
-
return PromiseAsyncResult.yield();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get a {@link AsyncResult} that runs the provided function if this {@link AsyncResult} is successful.
|
|
41
|
-
* @param thenFunction The function to run if this {@link AsyncResult} is successful.
|
|
42
|
-
*/
|
|
43
|
-
public abstract then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): AsyncResult<TResult1 | TResult2>
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Run the provided onValueFunction if this {@link AsyncResult} is successful. The value or error
|
|
47
|
-
* contained by this {@link AsyncResult} will be contained by the returned {@link AsyncResult}.
|
|
48
|
-
* @param onValueFunction The function to run if this {@link AsyncResult} is successful.
|
|
49
|
-
*/
|
|
50
|
-
public abstract onValue(onValueFunction: (value: T) => (void | Promise<void>)): AsyncResult<T>
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Run the provided catchFunction if this {@link AsyncResult} contains an error.
|
|
54
|
-
* @param catchFunction The function to run if an error is caught.
|
|
55
|
-
*/
|
|
56
|
-
public abstract catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): AsyncResult<T | TResult>
|
|
57
|
-
/**
|
|
58
|
-
* Run the provided catchFunction if this {@link AsyncResult} contains an error of the provided type.
|
|
59
|
-
* @param errorType The type of error to catch.
|
|
60
|
-
* @param catchFunction The function to run if the error is caught.
|
|
61
|
-
*/
|
|
62
|
-
public abstract catch<TError,TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => (TResult | PromiseLike<TResult>)): AsyncResult<T | TResult>
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Run the provided onErrorFunction if this {@link AsyncResult} contains an error.
|
|
66
|
-
* @param onErrorFunction The function to run if an error is found.
|
|
67
|
-
*/
|
|
68
|
-
public abstract onError(onErrorFunction: (reason: unknown) => (void | PromiseLike<void>)): AsyncResult<T>;
|
|
69
|
-
/**
|
|
70
|
-
* Run the provided onErrorFunction if this {@link AsyncResult} contains an error of the provided
|
|
71
|
-
* type.
|
|
72
|
-
* @param errorType The type of error to respond to.
|
|
73
|
-
* @param onErrorFunction The function to run if the error is found.
|
|
74
|
-
*/
|
|
75
|
-
public abstract onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => (void | PromiseLike<void>)): AsyncResult<T>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Run the provided convertErrorFunction if this {@link AsyncResult} contains an error. The value
|
|
79
|
-
* returned from the convertErrorFunction will be the error for the returned {@link AsyncResult}.
|
|
80
|
-
* @param convertErrorFunction The function that will return the new error.
|
|
81
|
-
*/
|
|
82
|
-
public abstract convertError(convertErrorFunction: (reason: unknown) => (unknown | PromiseLike<unknown>)): AsyncResult<T>;
|
|
83
|
-
/**
|
|
84
|
-
* Run the provided convertErrorFunction if this {@link AsyncResult} contains an error of the
|
|
85
|
-
* provided type. The value returned from the convertErrorFunction will be the error for the
|
|
86
|
-
* returned {@link AsyncResult}.
|
|
87
|
-
* @param errorType The type of error to respond to.
|
|
88
|
-
* @param convertErrorFunction The function that will return the new error.
|
|
89
|
-
*/
|
|
90
|
-
public abstract convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => (unknown | PromiseLike<unknown>)): AsyncResult<T>;
|
|
91
|
-
|
|
92
|
-
public abstract finally(onfinally?: (() => (void | Promise<void>)) | null): AsyncResult<T>;
|
|
93
|
-
|
|
94
|
-
readonly abstract [Symbol.toStringTag]: string;
|
|
95
|
-
}
|
|
1
|
+
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
2
|
+
import { isPromise, Type } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A result object that adds extra behavior beyond the standard {@link Promise}.
|
|
6
|
+
*/
|
|
7
|
+
export abstract class AsyncResult<T> implements Promise<T>
|
|
8
|
+
{
|
|
9
|
+
public static create<T>(action: () => (T | Promise<T>)): AsyncResult<T>;
|
|
10
|
+
public static create<T>(promise: Promise<T>): AsyncResult<T>;
|
|
11
|
+
static create<T>(actionOrPromise: (() => (T | Promise<T>)) | Promise<T>): AsyncResult<T>
|
|
12
|
+
{
|
|
13
|
+
return PromiseAsyncResult.create<T>(isPromise<T>(actionOrPromise) ? actionOrPromise : new Promise<T>(actionOrPromise));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a new {@link AsyncResult} that contains the provided value.
|
|
18
|
+
* @param value The value to wrap in a {@link AsyncResult}.
|
|
19
|
+
*/
|
|
20
|
+
public static value<T>(value: T): AsyncResult<T>
|
|
21
|
+
{
|
|
22
|
+
return PromiseAsyncResult.value(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a new {@link AsyncResult} that contains the provided error.
|
|
27
|
+
* @param error The error to wrap in a {@link AsyncResult}.
|
|
28
|
+
*/
|
|
29
|
+
public static error<T>(error: Error): AsyncResult<T>
|
|
30
|
+
{
|
|
31
|
+
return PromiseAsyncResult.error<T>(error);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static yield(): AsyncResult<void>
|
|
35
|
+
{
|
|
36
|
+
return PromiseAsyncResult.yield();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get a {@link AsyncResult} that runs the provided function if this {@link AsyncResult} is successful.
|
|
41
|
+
* @param thenFunction The function to run if this {@link AsyncResult} is successful.
|
|
42
|
+
*/
|
|
43
|
+
public abstract then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): AsyncResult<TResult1 | TResult2>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Run the provided onValueFunction if this {@link AsyncResult} is successful. The value or error
|
|
47
|
+
* contained by this {@link AsyncResult} will be contained by the returned {@link AsyncResult}.
|
|
48
|
+
* @param onValueFunction The function to run if this {@link AsyncResult} is successful.
|
|
49
|
+
*/
|
|
50
|
+
public abstract onValue(onValueFunction: (value: T) => (void | Promise<void>)): AsyncResult<T>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Run the provided catchFunction if this {@link AsyncResult} contains an error.
|
|
54
|
+
* @param catchFunction The function to run if an error is caught.
|
|
55
|
+
*/
|
|
56
|
+
public abstract catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): AsyncResult<T | TResult>
|
|
57
|
+
/**
|
|
58
|
+
* Run the provided catchFunction if this {@link AsyncResult} contains an error of the provided type.
|
|
59
|
+
* @param errorType The type of error to catch.
|
|
60
|
+
* @param catchFunction The function to run if the error is caught.
|
|
61
|
+
*/
|
|
62
|
+
public abstract catch<TError,TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => (TResult | PromiseLike<TResult>)): AsyncResult<T | TResult>
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Run the provided onErrorFunction if this {@link AsyncResult} contains an error.
|
|
66
|
+
* @param onErrorFunction The function to run if an error is found.
|
|
67
|
+
*/
|
|
68
|
+
public abstract onError(onErrorFunction: (reason: unknown) => (void | PromiseLike<void>)): AsyncResult<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Run the provided onErrorFunction if this {@link AsyncResult} contains an error of the provided
|
|
71
|
+
* type.
|
|
72
|
+
* @param errorType The type of error to respond to.
|
|
73
|
+
* @param onErrorFunction The function to run if the error is found.
|
|
74
|
+
*/
|
|
75
|
+
public abstract onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => (void | PromiseLike<void>)): AsyncResult<T>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Run the provided convertErrorFunction if this {@link AsyncResult} contains an error. The value
|
|
79
|
+
* returned from the convertErrorFunction will be the error for the returned {@link AsyncResult}.
|
|
80
|
+
* @param convertErrorFunction The function that will return the new error.
|
|
81
|
+
*/
|
|
82
|
+
public abstract convertError(convertErrorFunction: (reason: unknown) => (unknown | PromiseLike<unknown>)): AsyncResult<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Run the provided convertErrorFunction if this {@link AsyncResult} contains an error of the
|
|
85
|
+
* provided type. The value returned from the convertErrorFunction will be the error for the
|
|
86
|
+
* returned {@link AsyncResult}.
|
|
87
|
+
* @param errorType The type of error to respond to.
|
|
88
|
+
* @param convertErrorFunction The function that will return the new error.
|
|
89
|
+
*/
|
|
90
|
+
public abstract convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => (unknown | PromiseLike<unknown>)): AsyncResult<T>;
|
|
91
|
+
|
|
92
|
+
public abstract finally(onfinally?: (() => (void | Promise<void>)) | null): AsyncResult<T>;
|
|
93
|
+
|
|
94
|
+
readonly abstract [Symbol.toStringTag]: string;
|
|
95
|
+
}
|