@everyonesoftware/common 1.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.
Files changed (60) hide show
  1. package/.github/workflows/publish.yml +54 -38
  2. package/package.json +9 -2
  3. package/sources/asyncIterator.ts +436 -436
  4. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
  5. package/sources/asyncResult.ts +95 -95
  6. package/sources/byteList.ts +201 -201
  7. package/sources/byteListStream.ts +120 -120
  8. package/sources/byteReadStream.ts +23 -23
  9. package/sources/byteWriteStream.ts +15 -15
  10. package/sources/characterList.ts +194 -194
  11. package/sources/characterListStream.ts +150 -150
  12. package/sources/characterReadStream.ts +80 -80
  13. package/sources/characterReadStreamIterator.ts +127 -127
  14. package/sources/concatenateIterable.ts +118 -118
  15. package/sources/concatenateIterator.ts +164 -164
  16. package/sources/currentProcess.ts +157 -157
  17. package/sources/dateTime.ts +129 -129
  18. package/sources/depthFirstSearch.ts +229 -229
  19. package/sources/flatMapIterable.ts +103 -103
  20. package/sources/flatMapIterator.ts +151 -151
  21. package/sources/generator.ts +250 -250
  22. package/sources/index.ts +1 -1
  23. package/sources/iterator.ts +480 -480
  24. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
  25. package/sources/javascriptSetSet.ts +133 -133
  26. package/sources/listQueue.ts +61 -61
  27. package/sources/listStack.ts +61 -61
  28. package/sources/luxonDateTime.ts +108 -108
  29. package/sources/mapAsyncIterator.ts +140 -140
  30. package/sources/mutableMap.ts +291 -291
  31. package/sources/node.ts +36 -36
  32. package/sources/promiseAsyncResult.ts +173 -173
  33. package/sources/queue.ts +48 -48
  34. package/sources/recreationDotGovClient.ts +258 -258
  35. package/sources/searchControl.ts +41 -41
  36. package/sources/set.ts +243 -243
  37. package/sources/skipAsyncIterator.ts +144 -144
  38. package/sources/stack.ts +47 -47
  39. package/sources/syncResult.ts +299 -299
  40. package/sources/takeAsyncIterator.ts +140 -140
  41. package/sources/whereAsyncIterator.ts +142 -142
  42. package/sources/wonderlandTrailClient.ts +1502 -1502
  43. package/tests/assertTestTests.ts +74 -74
  44. package/tests/byteListStreamTests.ts +389 -389
  45. package/tests/byteListTests.ts +26 -26
  46. package/tests/characterListStreamTests.ts +390 -390
  47. package/tests/characterListTests.ts +249 -249
  48. package/tests/dateTimeTests.ts +29 -29
  49. package/tests/depthFirstSearchTests.ts +105 -105
  50. package/tests/generatorTests.ts +85 -85
  51. package/tests/mutableMapTests.ts +153 -153
  52. package/tests/promiseAsyncResultTests.ts +687 -687
  53. package/tests/queueTests.ts +28 -28
  54. package/tests/recreationDotGovClientTests.ts +190 -190
  55. package/tests/setTests.ts +139 -139
  56. package/tests/stackTests.ts +65 -65
  57. package/tests/syncResultTests.ts +1250 -1250
  58. package/tests/wonderlandTrailClientTests.ts +451 -451
  59. package/tsconfig.json +3 -0
  60. package/tsup.config.ts +12 -12
@@ -1,174 +1,174 @@
1
- import { PreCondition } from "./preCondition";
2
- import { AsyncResult } from "./asyncResult";
3
- import { instanceOfType, isPromise, isUndefinedOrNull, Type } from "./types";
4
-
5
- export class PromiseAsyncResult<T> implements AsyncResult<T>
6
- {
7
- private readonly promise: Promise<T>;
8
-
9
- private constructor(promise: Promise<T>)
10
- {
11
- PreCondition.assertNotUndefinedAndNotNull(promise, "promise");
12
-
13
- this.promise = promise;
14
- }
15
-
16
- public static create<T>(action: () => (T | Promise<T>)): PromiseAsyncResult<T>;
17
- public static create<T>(promise: Promise<T>): PromiseAsyncResult<T>;
18
- static create<T>(actionOrPromise: (() => (T | Promise<T>)) | Promise<T>): PromiseAsyncResult<T>
19
- {
20
- PreCondition.assertNotUndefinedAndNotNull(actionOrPromise, "action or promise");
21
-
22
- return new PromiseAsyncResult(Promise.resolve(isPromise<T>(actionOrPromise) ? actionOrPromise : actionOrPromise()));
23
- }
24
-
25
- public static value<T>(value: T): PromiseAsyncResult<T>
26
- {
27
- return PromiseAsyncResult.create(Promise.resolve(value));
28
- }
29
-
30
- public static error<T>(error: unknown): PromiseAsyncResult<T>
31
- {
32
- return PromiseAsyncResult.create(Promise.reject(error));
33
- }
34
-
35
- public static yield(): PromiseAsyncResult<void>
36
- {
37
- return PromiseAsyncResult.create(Promise.resolve());
38
- }
39
-
40
- public then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseAsyncResult<TResult1 | TResult2>
41
- {
42
- return PromiseAsyncResult.create(this.promise.then(onfulfilled, onrejected));
43
- }
44
-
45
- public onValue(onValueFunction: (value: T) => (void | Promise<void>)): PromiseAsyncResult<T>
46
- {
47
- return this.then<T>(async (value: T) =>
48
- {
49
- let result: PromiseAsyncResult<T>;
50
- try
51
- {
52
- await onValueFunction(value);
53
- result = this;
54
- }
55
- catch (error)
56
- {
57
- result = PromiseAsyncResult.error(error);
58
- }
59
- return result;
60
- })
61
- }
62
-
63
- public catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): PromiseAsyncResult<T | TResult>
64
- public catch<TError,TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => (TResult | PromiseLike<TResult>)): PromiseAsyncResult<T | TResult>
65
- catch<TResult = never>(errorTypeOrOnRejected?: Type<Error> | ((reason: unknown) => TResult | PromiseLike<TResult>) | null, onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): PromiseAsyncResult<T | TResult>
66
- {
67
- let errorType: Type<Error> | undefined;
68
- if (!isUndefinedOrNull(onrejected))
69
- {
70
- errorType = errorTypeOrOnRejected as Type<unknown>;
71
-
72
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
73
- }
74
- else
75
- {
76
- onrejected = errorTypeOrOnRejected as ((reason: any) => TResult | PromiseLike<TResult>) | null;
77
- }
78
-
79
- return PromiseAsyncResult.create<T | TResult>(this.promise.catch((reason: unknown) =>
80
- {
81
- let value: TResult | PromiseLike<TResult> | undefined;
82
- if (errorType && !instanceOfType(reason, errorType))
83
- {
84
- throw reason;
85
- }
86
- else if (!isUndefinedOrNull(onrejected))
87
- {
88
- value = onrejected(reason);
89
- }
90
- return value!;
91
- }));
92
- }
93
-
94
- public onError(onErrorFunction: (reason: unknown) => (void | PromiseLike<void>)): PromiseAsyncResult<T>;
95
- public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => (void | PromiseLike<void>)): PromiseAsyncResult<T>;
96
- onError(errorTypeOrOnErrorFunction: Type<unknown> | ((reason: unknown) => (void | PromiseLike<void>)), onErrorFunction?: (reason: unknown) => (void | PromiseLike<void>)): PromiseAsyncResult<T>
97
- {
98
- let errorType: Type<unknown> | undefined;
99
- if (!isUndefinedOrNull(onErrorFunction))
100
- {
101
- errorType = errorTypeOrOnErrorFunction as Type<unknown>;
102
-
103
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
104
- }
105
- else
106
- {
107
- onErrorFunction = errorTypeOrOnErrorFunction as ((reason: unknown) => void | PromiseLike<void>);
108
- }
109
- PreCondition.assertNotUndefinedAndNotNull(onErrorFunction, "onErrorFunction");
110
-
111
- let result: PromiseAsyncResult<T>;
112
- if (errorType)
113
- {
114
- result = this.catch(errorType, async (reason: unknown) =>
115
- {
116
- await onErrorFunction(reason);
117
- throw reason;
118
- });
119
- }
120
- else
121
- {
122
- result = this.catch(async (reason: unknown) =>
123
- {
124
- await onErrorFunction(reason);
125
- throw reason;
126
- });
127
- }
128
-
129
- return result;
130
- }
131
-
132
- public convertError(convertErrorFunction: (reason: unknown) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>;
133
- public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>;
134
- convertError(errorTypeOrConvertErrorFunction: Type<unknown> | ((reason: unknown) => (unknown | PromiseLike<unknown>)), convertErrorFunction?: (reason: unknown) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>
135
- {
136
- let errorType: Type<unknown> | undefined;
137
- if (!isUndefinedOrNull(convertErrorFunction))
138
- {
139
- errorType = errorTypeOrConvertErrorFunction as Type<unknown>;
140
-
141
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
142
- }
143
- else
144
- {
145
- convertErrorFunction = errorTypeOrConvertErrorFunction as ((reason: unknown) => void | PromiseLike<void>);
146
- }
147
- PreCondition.assertNotUndefinedAndNotNull(convertErrorFunction, "convertErrorFunction");
148
-
149
- let result: PromiseAsyncResult<T>;
150
- if (errorType)
151
- {
152
- result = this.catch(errorType, async (reason: unknown) =>
153
- {
154
- throw await convertErrorFunction(reason);
155
- });
156
- }
157
- else
158
- {
159
- result = this.catch(async (reason: unknown) =>
160
- {
161
- throw await convertErrorFunction(reason);
162
- });
163
- }
164
-
165
- return result;
166
- }
167
-
168
- public finally(onfinally?: (() => (void | Promise<void>)) | null): PromiseAsyncResult<T>
169
- {
170
- return PromiseAsyncResult.create(this.promise.finally(onfinally));
171
- }
172
-
173
- readonly [Symbol.toStringTag]: string = "AsyncResult";
1
+ import { PreCondition } from "./preCondition";
2
+ import { AsyncResult } from "./asyncResult";
3
+ import { instanceOfType, isPromise, isUndefinedOrNull, Type } from "./types";
4
+
5
+ export class PromiseAsyncResult<T> implements AsyncResult<T>
6
+ {
7
+ private readonly promise: Promise<T>;
8
+
9
+ private constructor(promise: Promise<T>)
10
+ {
11
+ PreCondition.assertNotUndefinedAndNotNull(promise, "promise");
12
+
13
+ this.promise = promise;
14
+ }
15
+
16
+ public static create<T>(action: () => (T | Promise<T>)): PromiseAsyncResult<T>;
17
+ public static create<T>(promise: Promise<T>): PromiseAsyncResult<T>;
18
+ static create<T>(actionOrPromise: (() => (T | Promise<T>)) | Promise<T>): PromiseAsyncResult<T>
19
+ {
20
+ PreCondition.assertNotUndefinedAndNotNull(actionOrPromise, "action or promise");
21
+
22
+ return new PromiseAsyncResult(Promise.resolve(isPromise<T>(actionOrPromise) ? actionOrPromise : actionOrPromise()));
23
+ }
24
+
25
+ public static value<T>(value: T): PromiseAsyncResult<T>
26
+ {
27
+ return PromiseAsyncResult.create(Promise.resolve(value));
28
+ }
29
+
30
+ public static error<T>(error: unknown): PromiseAsyncResult<T>
31
+ {
32
+ return PromiseAsyncResult.create(Promise.reject(error));
33
+ }
34
+
35
+ public static yield(): PromiseAsyncResult<void>
36
+ {
37
+ return PromiseAsyncResult.create(Promise.resolve());
38
+ }
39
+
40
+ public then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseAsyncResult<TResult1 | TResult2>
41
+ {
42
+ return PromiseAsyncResult.create(this.promise.then(onfulfilled, onrejected));
43
+ }
44
+
45
+ public onValue(onValueFunction: (value: T) => (void | Promise<void>)): PromiseAsyncResult<T>
46
+ {
47
+ return this.then<T>(async (value: T) =>
48
+ {
49
+ let result: PromiseAsyncResult<T>;
50
+ try
51
+ {
52
+ await onValueFunction(value);
53
+ result = this;
54
+ }
55
+ catch (error)
56
+ {
57
+ result = PromiseAsyncResult.error(error);
58
+ }
59
+ return result;
60
+ })
61
+ }
62
+
63
+ public catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): PromiseAsyncResult<T | TResult>
64
+ public catch<TError,TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => (TResult | PromiseLike<TResult>)): PromiseAsyncResult<T | TResult>
65
+ catch<TResult = never>(errorTypeOrOnRejected?: Type<Error> | ((reason: unknown) => TResult | PromiseLike<TResult>) | null, onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): PromiseAsyncResult<T | TResult>
66
+ {
67
+ let errorType: Type<Error> | undefined;
68
+ if (!isUndefinedOrNull(onrejected))
69
+ {
70
+ errorType = errorTypeOrOnRejected as Type<unknown>;
71
+
72
+ PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
73
+ }
74
+ else
75
+ {
76
+ onrejected = errorTypeOrOnRejected as ((reason: any) => TResult | PromiseLike<TResult>) | null;
77
+ }
78
+
79
+ return PromiseAsyncResult.create<T | TResult>(this.promise.catch((reason: unknown) =>
80
+ {
81
+ let value: TResult | PromiseLike<TResult> | undefined;
82
+ if (errorType && !instanceOfType(reason, errorType))
83
+ {
84
+ throw reason;
85
+ }
86
+ else if (!isUndefinedOrNull(onrejected))
87
+ {
88
+ value = onrejected(reason);
89
+ }
90
+ return value!;
91
+ }));
92
+ }
93
+
94
+ public onError(onErrorFunction: (reason: unknown) => (void | PromiseLike<void>)): PromiseAsyncResult<T>;
95
+ public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => (void | PromiseLike<void>)): PromiseAsyncResult<T>;
96
+ onError(errorTypeOrOnErrorFunction: Type<unknown> | ((reason: unknown) => (void | PromiseLike<void>)), onErrorFunction?: (reason: unknown) => (void | PromiseLike<void>)): PromiseAsyncResult<T>
97
+ {
98
+ let errorType: Type<unknown> | undefined;
99
+ if (!isUndefinedOrNull(onErrorFunction))
100
+ {
101
+ errorType = errorTypeOrOnErrorFunction as Type<unknown>;
102
+
103
+ PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
104
+ }
105
+ else
106
+ {
107
+ onErrorFunction = errorTypeOrOnErrorFunction as ((reason: unknown) => void | PromiseLike<void>);
108
+ }
109
+ PreCondition.assertNotUndefinedAndNotNull(onErrorFunction, "onErrorFunction");
110
+
111
+ let result: PromiseAsyncResult<T>;
112
+ if (errorType)
113
+ {
114
+ result = this.catch(errorType, async (reason: unknown) =>
115
+ {
116
+ await onErrorFunction(reason);
117
+ throw reason;
118
+ });
119
+ }
120
+ else
121
+ {
122
+ result = this.catch(async (reason: unknown) =>
123
+ {
124
+ await onErrorFunction(reason);
125
+ throw reason;
126
+ });
127
+ }
128
+
129
+ return result;
130
+ }
131
+
132
+ public convertError(convertErrorFunction: (reason: unknown) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>;
133
+ public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>;
134
+ convertError(errorTypeOrConvertErrorFunction: Type<unknown> | ((reason: unknown) => (unknown | PromiseLike<unknown>)), convertErrorFunction?: (reason: unknown) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>
135
+ {
136
+ let errorType: Type<unknown> | undefined;
137
+ if (!isUndefinedOrNull(convertErrorFunction))
138
+ {
139
+ errorType = errorTypeOrConvertErrorFunction as Type<unknown>;
140
+
141
+ PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
142
+ }
143
+ else
144
+ {
145
+ convertErrorFunction = errorTypeOrConvertErrorFunction as ((reason: unknown) => void | PromiseLike<void>);
146
+ }
147
+ PreCondition.assertNotUndefinedAndNotNull(convertErrorFunction, "convertErrorFunction");
148
+
149
+ let result: PromiseAsyncResult<T>;
150
+ if (errorType)
151
+ {
152
+ result = this.catch(errorType, async (reason: unknown) =>
153
+ {
154
+ throw await convertErrorFunction(reason);
155
+ });
156
+ }
157
+ else
158
+ {
159
+ result = this.catch(async (reason: unknown) =>
160
+ {
161
+ throw await convertErrorFunction(reason);
162
+ });
163
+ }
164
+
165
+ return result;
166
+ }
167
+
168
+ public finally(onfinally?: (() => (void | Promise<void>)) | null): PromiseAsyncResult<T>
169
+ {
170
+ return PromiseAsyncResult.create(this.promise.finally(onfinally));
171
+ }
172
+
173
+ readonly [Symbol.toStringTag]: string = "AsyncResult";
174
174
  }
package/sources/queue.ts CHANGED
@@ -1,49 +1,49 @@
1
- import { EqualFunctions } from "./equalFunctions";
2
- import { JavascriptIterable } from "./javascript";
3
- import { ListQueue } from "./listQueue";
4
- import { ListStack } from "./listStack";
5
- import { AsyncResult } from "./asyncResult";
6
-
7
- /**
8
- * A data structure that stores values in a first-in-first-out order.
9
- */
10
- export abstract class Queue<T>
11
- {
12
- /**
13
- * Create an instance of the default {@link Queue} implementation.
14
- * @returns A new {@link Queue} object.
15
- */
16
- public static create<T>(): ListQueue<T>
17
- {
18
- return ListQueue.create();
19
- }
20
-
21
- /**
22
- * Get whether there are any values in this {@link Stack}.
23
- */
24
- public abstract any(): AsyncResult<boolean>;
25
-
26
- /**
27
- * Add the provided value onto the end of this {@link Queue}.
28
- * @param value The value to add to the end of this {@link Queue}.
29
- */
30
- public abstract add(value: T): AsyncResult<void>;
31
-
32
- /**
33
- * Add the provided values to the end of this {@link Queue}.
34
- * @param values The values to add to the end of this {@link Queue}.
35
- */
36
- public abstract addAll(values: JavascriptIterable<T>): AsyncResult<void>;
37
-
38
- /**
39
- * Remove the next value off of this {@link Queue}.
40
- */
41
- public abstract remove(): AsyncResult<T>;
42
-
43
- /**
44
- * Get whether this {@link Stack} contains the provided value.
45
- * @param value The value to look for.
46
- * @param equalFunctions The functions to use to compare values.
47
- */
48
- public abstract contains(value: T, equalFunctions?: EqualFunctions): AsyncResult<boolean>;
1
+ import { EqualFunctions } from "./equalFunctions";
2
+ import { JavascriptIterable } from "./javascript";
3
+ import { ListQueue } from "./listQueue";
4
+ import { ListStack } from "./listStack";
5
+ import { AsyncResult } from "./asyncResult";
6
+
7
+ /**
8
+ * A data structure that stores values in a first-in-first-out order.
9
+ */
10
+ export abstract class Queue<T>
11
+ {
12
+ /**
13
+ * Create an instance of the default {@link Queue} implementation.
14
+ * @returns A new {@link Queue} object.
15
+ */
16
+ public static create<T>(): ListQueue<T>
17
+ {
18
+ return ListQueue.create();
19
+ }
20
+
21
+ /**
22
+ * Get whether there are any values in this {@link Stack}.
23
+ */
24
+ public abstract any(): AsyncResult<boolean>;
25
+
26
+ /**
27
+ * Add the provided value onto the end of this {@link Queue}.
28
+ * @param value The value to add to the end of this {@link Queue}.
29
+ */
30
+ public abstract add(value: T): AsyncResult<void>;
31
+
32
+ /**
33
+ * Add the provided values to the end of this {@link Queue}.
34
+ * @param values The values to add to the end of this {@link Queue}.
35
+ */
36
+ public abstract addAll(values: JavascriptIterable<T>): AsyncResult<void>;
37
+
38
+ /**
39
+ * Remove the next value off of this {@link Queue}.
40
+ */
41
+ public abstract remove(): AsyncResult<T>;
42
+
43
+ /**
44
+ * Get whether this {@link Stack} contains the provided value.
45
+ * @param value The value to look for.
46
+ * @param equalFunctions The functions to use to compare values.
47
+ */
48
+ public abstract contains(value: T, equalFunctions?: EqualFunctions): AsyncResult<boolean>;
49
49
  }