@everyonesoftware/common 2.0.0 → 4.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/outputs/chunk-AY3YWKOM.js +7741 -0
- package/outputs/chunk-AY3YWKOM.js.map +1 -0
- package/outputs/sources.cjs +9007 -0
- package/outputs/sources.cjs.map +1 -0
- package/outputs/sources.d.cts +4082 -0
- package/outputs/sources.d.ts +4082 -0
- package/outputs/sources.js +1370 -0
- package/outputs/sources.js.map +1 -0
- package/outputs/tests.cjs +17208 -0
- package/outputs/tests.cjs.map +1 -0
- package/outputs/tests.d.cts +3 -0
- package/outputs/tests.d.ts +3 -0
- package/outputs/tests.js +9798 -0
- package/outputs/tests.js.map +1 -0
- package/package.json +11 -2
- package/.c8rc.json +0 -12
- package/.github/workflows/publish.yml +0 -36
- package/.mocharc.json +0 -9
- package/sources/assertMessageParameters.ts +0 -22
- package/sources/asyncIterator.ts +0 -437
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
- package/sources/asyncResult.ts +0 -95
- package/sources/basicDisposable.ts +0 -57
- package/sources/byteList.ts +0 -202
- package/sources/byteListStream.ts +0 -121
- package/sources/byteReadStream.ts +0 -24
- package/sources/byteWriteStream.ts +0 -16
- package/sources/bytes.ts +0 -25
- package/sources/characterList.ts +0 -195
- package/sources/characterListStream.ts +0 -151
- package/sources/characterReadStream.ts +0 -81
- package/sources/characterReadStreamIterator.ts +0 -128
- package/sources/characterWriteStream.ts +0 -45
- package/sources/commandLineParameter.ts +0 -45
- package/sources/commandLineParameters.ts +0 -21
- package/sources/comparable.ts +0 -144
- package/sources/comparer.ts +0 -133
- package/sources/comparison.ts +0 -20
- package/sources/concatenateIterable.ts +0 -119
- package/sources/concatenateIterator.ts +0 -165
- package/sources/condition.ts +0 -329
- package/sources/currentProcess.ts +0 -158
- package/sources/dateTime.ts +0 -130
- package/sources/depthFirstSearch.ts +0 -230
- package/sources/disposable.ts +0 -31
- package/sources/emptyError.ts +0 -10
- package/sources/english.ts +0 -45
- package/sources/equalFunctions.ts +0 -123
- package/sources/fetchHttpClient.ts +0 -89
- package/sources/fetchHttpResponse.ts +0 -106
- package/sources/flatMapIterable.ts +0 -104
- package/sources/flatMapIterator.ts +0 -152
- package/sources/generator.ts +0 -251
- package/sources/httpClient.ts +0 -36
- package/sources/httpHeader.ts +0 -37
- package/sources/httpHeaders.ts +0 -216
- package/sources/httpIncomingRequest.ts +0 -30
- package/sources/httpIncomingResponse.ts +0 -19
- package/sources/httpMethod.ts +0 -164
- package/sources/httpOutgoingRequest.ts +0 -119
- package/sources/httpOutgoingResponse.ts +0 -113
- package/sources/httpServer.ts +0 -34
- package/sources/inMemoryCharacterWriteStream.ts +0 -78
- package/sources/index.ts +0 -101
- package/sources/iterable.ts +0 -345
- package/sources/iterator.ts +0 -481
- package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
- package/sources/javascript.ts +0 -59
- package/sources/javascriptArrayList.ts +0 -175
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
- package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
- package/sources/javascriptMapMap.ts +0 -143
- package/sources/javascriptSetSet.ts +0 -134
- package/sources/list.ts +0 -330
- package/sources/listQueue.ts +0 -62
- package/sources/listStack.ts +0 -62
- package/sources/luxonDateTime.ts +0 -109
- package/sources/map.ts +0 -302
- package/sources/mapAsyncIterator.ts +0 -141
- package/sources/mapIterable.ts +0 -105
- package/sources/mapIterator.ts +0 -145
- package/sources/mutableCondition.ts +0 -451
- package/sources/mutableHttpHeaders.ts +0 -204
- package/sources/mutableMap.ts +0 -292
- package/sources/network.ts +0 -18
- package/sources/node.ts +0 -37
- package/sources/nodeJSCharacterWriteStream.ts +0 -42
- package/sources/nodeJSHttpIncomingRequest.ts +0 -132
- package/sources/nodeJSHttpServer.ts +0 -134
- package/sources/notFoundError.ts +0 -12
- package/sources/postCondition.ts +0 -284
- package/sources/postConditionError.ts +0 -12
- package/sources/preCondition.ts +0 -284
- package/sources/preConditionError.ts +0 -12
- package/sources/promiseAsyncResult.ts +0 -174
- package/sources/property.ts +0 -63
- package/sources/queue.ts +0 -49
- package/sources/realNetwork.ts +0 -28
- package/sources/recreationDotGovClient.ts +0 -259
- package/sources/searchControl.ts +0 -42
- package/sources/set.ts +0 -244
- package/sources/skipAsyncIterator.ts +0 -145
- package/sources/skipIterator.ts +0 -155
- package/sources/stack.ts +0 -48
- package/sources/stringComparer.ts +0 -33
- package/sources/stringIterator.ts +0 -149
- package/sources/strings.ts +0 -322
- package/sources/syncResult.ts +0 -300
- package/sources/takeAsyncIterator.ts +0 -141
- package/sources/takeIterator.ts +0 -151
- package/sources/toStringFunctions.ts +0 -185
- package/sources/types.ts +0 -371
- package/sources/whereAsyncIterator.ts +0 -143
- package/sources/whereIterable.ts +0 -108
- package/sources/whereIterator.ts +0 -157
- package/sources/wonderlandTrailClient.ts +0 -1503
- package/tests/assertTest.ts +0 -113
- package/tests/assertTestTests.ts +0 -75
- package/tests/basicTestSkip.ts +0 -51
- package/tests/byteListStreamTests.ts +0 -390
- package/tests/byteListTests.ts +0 -27
- package/tests/bytesTests.ts +0 -43
- package/tests/characterListStreamTests.ts +0 -391
- package/tests/characterListTests.ts +0 -250
- package/tests/characterWriteStreamTests.ts +0 -12
- package/tests/comparerTests.ts +0 -92
- package/tests/conditionTests.ts +0 -877
- package/tests/consoleTestRunner.ts +0 -404
- package/tests/consoleTestRunnerTests.ts +0 -651
- package/tests/dateTimeTests.ts +0 -30
- package/tests/depthFirstSearchTests.ts +0 -106
- package/tests/disposableTests.ts +0 -121
- package/tests/englishTests.ts +0 -103
- package/tests/equalFunctionsTests.ts +0 -223
- package/tests/failedTest.ts +0 -43
- package/tests/fetchHttpClientTests.ts +0 -33
- package/tests/generatorTests.ts +0 -86
- package/tests/httpClientTests.ts +0 -18
- package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
- package/tests/iterableTests.ts +0 -141
- package/tests/iteratorTests.ts +0 -1086
- package/tests/javascriptMapMapTests.ts +0 -21
- package/tests/listTests.ts +0 -338
- package/tests/mapIteratorTests.ts +0 -55
- package/tests/mapTests.ts +0 -104
- package/tests/mutableConditionTests.ts +0 -273
- package/tests/mutableMapTests.ts +0 -154
- package/tests/nodeJSHttpServerTests.ts +0 -75
- package/tests/notFoundErrorTests.ts +0 -24
- package/tests/postConditionErrorTests.ts +0 -24
- package/tests/preConditionErrorTests.ts +0 -24
- package/tests/promiseAsyncResultTests.ts +0 -688
- package/tests/propertyTests.ts +0 -63
- package/tests/queueTests.ts +0 -29
- package/tests/recreationDotGovClientTests.ts +0 -191
- package/tests/setTests.ts +0 -140
- package/tests/skippedTest.ts +0 -39
- package/tests/stackTests.ts +0 -66
- package/tests/stringComparerTests.ts +0 -60
- package/tests/stringIteratorTests.ts +0 -156
- package/tests/stringsTests.ts +0 -516
- package/tests/syncResultTests.ts +0 -1251
- package/tests/test.ts +0 -228
- package/tests/testAction.ts +0 -75
- package/tests/testActionTests.ts +0 -93
- package/tests/testFailureTests.ts +0 -12
- package/tests/testRunner.ts +0 -267
- package/tests/testRunnerTests.ts +0 -895
- package/tests/testSkip.ts +0 -34
- package/tests/tests.ts +0 -103
- package/tests/toStringFunctionsTests.ts +0 -55
- package/tests/typesTests.ts +0 -257
- package/tests/whereIteratorTests.ts +0 -77
- package/tests/wonderlandTrailClientTests.ts +0 -452
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -13
package/sources/syncResult.ts
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { PreCondition } from "./preCondition";
|
|
2
|
-
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
3
|
-
import { instanceOfType, isPromise, isPromiseLike, isUndefinedOrNull, Type } from "./types";
|
|
4
|
-
import { AsyncResult } from "./asyncResult";
|
|
5
|
-
|
|
6
|
-
export class SyncResult<T> implements AsyncResult<T>
|
|
7
|
-
{
|
|
8
|
-
private value: T | undefined;
|
|
9
|
-
private error: unknown | undefined;
|
|
10
|
-
|
|
11
|
-
private constructor(value: T | undefined, error: unknown | undefined)
|
|
12
|
-
{
|
|
13
|
-
PreCondition.assertTrue(value === undefined || error === undefined, "value === undefined || error === undefined", "Either value or error must be undefined.");
|
|
14
|
-
|
|
15
|
-
this.value = value;
|
|
16
|
-
this.error = error;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public static create<T>(action: () => T): SyncResult<T>
|
|
20
|
-
{
|
|
21
|
-
PreCondition.assertNotUndefinedAndNotNull(action, "action");
|
|
22
|
-
|
|
23
|
-
let value: T | undefined;
|
|
24
|
-
let error: unknown | undefined;
|
|
25
|
-
try
|
|
26
|
-
{
|
|
27
|
-
value = action();
|
|
28
|
-
}
|
|
29
|
-
catch (e)
|
|
30
|
-
{
|
|
31
|
-
error = e;
|
|
32
|
-
}
|
|
33
|
-
return new SyncResult(value, error);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public static value<T>(value: T): SyncResult<T>
|
|
37
|
-
{
|
|
38
|
-
return new SyncResult(value, undefined);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public static error<T>(error: unknown): SyncResult<T>
|
|
42
|
-
{
|
|
43
|
-
return new SyncResult<T>(undefined, error);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public await(): T
|
|
47
|
-
{
|
|
48
|
-
if (this.error)
|
|
49
|
-
{
|
|
50
|
-
throw this.error;
|
|
51
|
-
}
|
|
52
|
-
return this.value!;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public then<TResult1 = T, TResult2 = never>(onfullfilled?: ((value: T) => TResult1) | null, onrejected?: ((reason: unknown) => TResult2) | null): SyncResult<TResult1 | TResult2>;
|
|
56
|
-
public then<TResult1 = T, TResult2 = never>(onfullfilled?: ((value: T) => (TResult1 | PromiseLike<TResult1>)) | null, onrejected?: ((reason: unknown) => (TResult2 | PromiseLike<TResult2>)) | null): SyncResult<TResult1 | TResult2>;
|
|
57
|
-
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => (TResult1 | PromiseLike<TResult1>)) | null, onrejected?: ((reason: unknown) => (TResult2 | PromiseLike<TResult2>)) | null): SyncResult<TResult1 | TResult2> | PromiseAsyncResult<TResult1 | TResult2>
|
|
58
|
-
{
|
|
59
|
-
let result: SyncResult<TResult1 | TResult2> | PromiseAsyncResult<TResult1 | TResult2>;
|
|
60
|
-
if (this.error)
|
|
61
|
-
{
|
|
62
|
-
if (onrejected)
|
|
63
|
-
{
|
|
64
|
-
try
|
|
65
|
-
{
|
|
66
|
-
const onRejectedResult: TResult2 | PromiseLike<TResult2> = onrejected(this.error);
|
|
67
|
-
if (onRejectedResult instanceof SyncResult || onRejectedResult instanceof PromiseAsyncResult)
|
|
68
|
-
{
|
|
69
|
-
result = onRejectedResult;
|
|
70
|
-
}
|
|
71
|
-
else if (isPromise<TResult2>(onRejectedResult))
|
|
72
|
-
{
|
|
73
|
-
result = PromiseAsyncResult.create(onRejectedResult);
|
|
74
|
-
}
|
|
75
|
-
else
|
|
76
|
-
{
|
|
77
|
-
result = SyncResult.value(onRejectedResult as TResult2);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error)
|
|
81
|
-
{
|
|
82
|
-
result = SyncResult.error(error);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else
|
|
86
|
-
{
|
|
87
|
-
result = SyncResult.error<TResult2>(this.error);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else
|
|
91
|
-
{
|
|
92
|
-
if (onfulfilled)
|
|
93
|
-
{
|
|
94
|
-
try
|
|
95
|
-
{
|
|
96
|
-
const onFullfilledResult: TResult1 | PromiseLike<TResult1> = onfulfilled(this.value!);
|
|
97
|
-
if (onFullfilledResult instanceof SyncResult || onFullfilledResult instanceof PromiseAsyncResult)
|
|
98
|
-
{
|
|
99
|
-
result = onFullfilledResult;
|
|
100
|
-
}
|
|
101
|
-
else if (isPromise<TResult1>(onFullfilledResult))
|
|
102
|
-
{
|
|
103
|
-
result = PromiseAsyncResult.create(onFullfilledResult);
|
|
104
|
-
}
|
|
105
|
-
else
|
|
106
|
-
{
|
|
107
|
-
result = SyncResult.value(onFullfilledResult as TResult1);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (error)
|
|
111
|
-
{
|
|
112
|
-
result = SyncResult.error(error);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else
|
|
116
|
-
{
|
|
117
|
-
result = SyncResult.value<TResult1>(this.value as TResult1);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public onValue(onValueFunction: (value: T) => void): SyncResult<T>;
|
|
124
|
-
public onValue(onValueFunction: (value: T) => Promise<void>): PromiseAsyncResult<T>;
|
|
125
|
-
onValue(onValueFunction: (value: T) => (void | Promise<void>)): SyncResult<T> | PromiseAsyncResult<T>
|
|
126
|
-
{
|
|
127
|
-
return this.then<T>((value: T) =>
|
|
128
|
-
{
|
|
129
|
-
let result: SyncResult<T> | PromiseAsyncResult<T>;
|
|
130
|
-
try
|
|
131
|
-
{
|
|
132
|
-
const onValueFunctionResult: (void | Promise<void>) = onValueFunction(value);
|
|
133
|
-
if (isPromise(onValueFunctionResult))
|
|
134
|
-
{
|
|
135
|
-
result = PromiseAsyncResult.create(onValueFunctionResult.then(() => value));
|
|
136
|
-
}
|
|
137
|
-
else
|
|
138
|
-
{
|
|
139
|
-
result = this;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (error)
|
|
143
|
-
{
|
|
144
|
-
result = SyncResult.error(error);
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public catch<TResult = never>(onrejected: (reason: unknown) => TResult): SyncResult<T | TResult>;
|
|
151
|
-
public catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): SyncResult<T | TResult> | PromiseAsyncResult<T | TResult>
|
|
152
|
-
public catch<TError, TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => TResult): SyncResult<T | TResult>;
|
|
153
|
-
public catch<TError, TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => PromiseLike<TResult>): PromiseAsyncResult<T | TResult>;
|
|
154
|
-
catch<TResult = never>(errorTypeOrOnRejected?: Type<unknown> | ((reason: unknown) => TResult | PromiseLike<TResult>) | null, onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): SyncResult<T | TResult> | PromiseAsyncResult<T | TResult>
|
|
155
|
-
{
|
|
156
|
-
let errorType: Type<TypeError> | undefined;
|
|
157
|
-
if (!isUndefinedOrNull(onrejected))
|
|
158
|
-
{
|
|
159
|
-
errorType = errorTypeOrOnRejected as Type<unknown>;
|
|
160
|
-
|
|
161
|
-
PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
|
|
162
|
-
}
|
|
163
|
-
else
|
|
164
|
-
{
|
|
165
|
-
onrejected = errorTypeOrOnRejected as ((reason: any) => TResult | PromiseLike<TResult>) | null;
|
|
166
|
-
}
|
|
167
|
-
PreCondition.assertNotUndefinedAndNotNull(onrejected, "onrejected");
|
|
168
|
-
|
|
169
|
-
let result: SyncResult<T | TResult> | PromiseAsyncResult<T | TResult> = this;
|
|
170
|
-
if (this.error && (!errorType || instanceOfType(this.error, errorType)))
|
|
171
|
-
{
|
|
172
|
-
try
|
|
173
|
-
{
|
|
174
|
-
const onRejectedResult: TResult | PromiseLike<TResult> = onrejected(this.error);
|
|
175
|
-
if (onRejectedResult instanceof SyncResult || onRejectedResult instanceof PromiseAsyncResult)
|
|
176
|
-
{
|
|
177
|
-
result = onRejectedResult;
|
|
178
|
-
}
|
|
179
|
-
else if (isPromise<TResult>(onRejectedResult))
|
|
180
|
-
{
|
|
181
|
-
result = PromiseAsyncResult.create(onRejectedResult);
|
|
182
|
-
}
|
|
183
|
-
else
|
|
184
|
-
{
|
|
185
|
-
result = SyncResult.value(onRejectedResult as TResult);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (error)
|
|
189
|
-
{
|
|
190
|
-
result = SyncResult.error(error);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return result;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
public onError(onErrorFunction: (reason: unknown) => void): SyncResult<T>;
|
|
197
|
-
public onError(onErrorFunction: (reason: unknown) => PromiseLike<void>): PromiseAsyncResult<T>;
|
|
198
|
-
public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => void): SyncResult<T>;
|
|
199
|
-
public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => PromiseLike<void>): PromiseAsyncResult<T>;
|
|
200
|
-
onError(errorTypeOrOnErrorFunction: Type<unknown> | ((reason: unknown) => (void | PromiseLike<void>)), onErrorFunction?: (reason: unknown) => (void | PromiseLike<void>)): SyncResult<T> | PromiseAsyncResult<T>
|
|
201
|
-
{
|
|
202
|
-
let errorType: Type<TypeError> | undefined;
|
|
203
|
-
if (!isUndefinedOrNull(onErrorFunction))
|
|
204
|
-
{
|
|
205
|
-
errorType = errorTypeOrOnErrorFunction as Type<unknown>;
|
|
206
|
-
|
|
207
|
-
PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
|
|
208
|
-
}
|
|
209
|
-
else
|
|
210
|
-
{
|
|
211
|
-
onErrorFunction = errorTypeOrOnErrorFunction as ((reason: any) => void | PromiseLike<void>);
|
|
212
|
-
}
|
|
213
|
-
PreCondition.assertNotUndefinedAndNotNull(onErrorFunction, "onErrorFunction");
|
|
214
|
-
|
|
215
|
-
let result: SyncResult<T> | PromiseAsyncResult<T> = this;
|
|
216
|
-
if (this.error && (!errorType || instanceOfType(this.error, errorType)))
|
|
217
|
-
{
|
|
218
|
-
try
|
|
219
|
-
{
|
|
220
|
-
const onErrorResult: void | PromiseLike<void> = onErrorFunction(this.error);
|
|
221
|
-
if (isPromise(onErrorResult))
|
|
222
|
-
{
|
|
223
|
-
result = PromiseAsyncResult.create(onErrorResult).then(() => this);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
catch (error)
|
|
227
|
-
{
|
|
228
|
-
result = SyncResult.error(error);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return result;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public convertError(convertErrorFunction: (reason: unknown) => unknown): SyncResult<T>;
|
|
235
|
-
public convertError(onErrorFunction: (reason: unknown) => PromiseLike<unknown>): PromiseAsyncResult<T>;
|
|
236
|
-
public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => unknown): SyncResult<T>;
|
|
237
|
-
public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => PromiseLike<unknown>): PromiseAsyncResult<T>;
|
|
238
|
-
convertError(errorTypeOrConvertErrorFunction: Type<unknown> | ((reason: unknown) => (unknown | PromiseLike<unknown>)), convertErrorFunction?: (reason: unknown) => (unknown | PromiseLike<unknown>)): SyncResult<T> | PromiseAsyncResult<T>
|
|
239
|
-
{
|
|
240
|
-
let errorType: Type<TypeError> | undefined;
|
|
241
|
-
if (!isUndefinedOrNull(convertErrorFunction))
|
|
242
|
-
{
|
|
243
|
-
errorType = errorTypeOrConvertErrorFunction as Type<unknown>;
|
|
244
|
-
|
|
245
|
-
PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
|
|
246
|
-
}
|
|
247
|
-
else
|
|
248
|
-
{
|
|
249
|
-
convertErrorFunction = errorTypeOrConvertErrorFunction as ((reason: any) => void | PromiseLike<void>);
|
|
250
|
-
}
|
|
251
|
-
PreCondition.assertNotUndefinedAndNotNull(convertErrorFunction, "convertErrorFunction");
|
|
252
|
-
|
|
253
|
-
let result: SyncResult<T> | PromiseAsyncResult<T> = this;
|
|
254
|
-
if (this.error && (!errorType || instanceOfType(this.error, errorType)))
|
|
255
|
-
{
|
|
256
|
-
try
|
|
257
|
-
{
|
|
258
|
-
const convertErrorResult: unknown | PromiseLike<unknown> = convertErrorFunction(this.error);
|
|
259
|
-
if (isPromise(convertErrorResult))
|
|
260
|
-
{
|
|
261
|
-
result = PromiseAsyncResult.error(convertErrorResult);
|
|
262
|
-
}
|
|
263
|
-
else
|
|
264
|
-
{
|
|
265
|
-
result = SyncResult.error(convertErrorResult);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
catch (error)
|
|
269
|
-
{
|
|
270
|
-
result = SyncResult.error(error);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return result;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public finally(onfinally?: (() => void) | null): SyncResult<T>
|
|
277
|
-
public finally(onfinally?: (() => Promise<void>) | null): PromiseAsyncResult<T>
|
|
278
|
-
finally(onfinally?: (() => (void | Promise<void>)) | null | undefined): PromiseAsyncResult<T> | SyncResult<T>
|
|
279
|
-
{
|
|
280
|
-
let result: PromiseAsyncResult<T> | SyncResult<T> = this;
|
|
281
|
-
if (onfinally)
|
|
282
|
-
{
|
|
283
|
-
try
|
|
284
|
-
{
|
|
285
|
-
const onfinallyResult: void | Promise<void> = onfinally();
|
|
286
|
-
if (isPromiseLike(onfinallyResult))
|
|
287
|
-
{
|
|
288
|
-
result = PromiseAsyncResult.create(onfinallyResult).then(() => this);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
catch (error)
|
|
292
|
-
{
|
|
293
|
-
result = SyncResult.error(error);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return result;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
readonly [Symbol.toStringTag]: string = "SyncResult2";
|
|
300
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { AsyncIterator } from "./asyncIterator";
|
|
2
|
-
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
3
|
-
import { JavascriptAsyncIterator } from "./javascript";
|
|
4
|
-
import { PreCondition } from "./preCondition";
|
|
5
|
-
import { Type } from "./types";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* An {@link AsyncIterator} that iterates over a maximum number of values.
|
|
9
|
-
*/
|
|
10
|
-
export class TakeAsyncIterator<T> implements AsyncIterator<T>
|
|
11
|
-
{
|
|
12
|
-
private readonly innerIterator: AsyncIterator<T>;
|
|
13
|
-
private started: boolean;
|
|
14
|
-
private readonly maximumToTake: number;
|
|
15
|
-
private taken: number;
|
|
16
|
-
|
|
17
|
-
private constructor(innerIterator: AsyncIterator<T>, maximumToTake: number)
|
|
18
|
-
{
|
|
19
|
-
PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
|
|
20
|
-
|
|
21
|
-
this.innerIterator = innerIterator;
|
|
22
|
-
this.started = false;
|
|
23
|
-
this.maximumToTake = maximumToTake;
|
|
24
|
-
this.taken = 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public static create<T>(innerIterator: AsyncIterator<T>, maximumToTake: number)
|
|
28
|
-
{
|
|
29
|
-
return new TakeAsyncIterator(innerIterator, maximumToTake);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public hasCurrent(): boolean
|
|
33
|
-
{
|
|
34
|
-
return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public next(): PromiseAsyncResult<boolean>
|
|
38
|
-
{
|
|
39
|
-
return PromiseAsyncResult.create(async () =>
|
|
40
|
-
{
|
|
41
|
-
if (this.maximumToTake <= 0)
|
|
42
|
-
{
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
else if (!this.hasStarted())
|
|
46
|
-
{
|
|
47
|
-
this.started = true;
|
|
48
|
-
await this.innerIterator.start();
|
|
49
|
-
this.taken++;
|
|
50
|
-
}
|
|
51
|
-
else if (this.taken <= this.maximumToTake)
|
|
52
|
-
{
|
|
53
|
-
await this.innerIterator.next();
|
|
54
|
-
this.taken++;
|
|
55
|
-
}
|
|
56
|
-
return this.hasCurrent();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public hasStarted(): boolean
|
|
61
|
-
{
|
|
62
|
-
return this.started;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public getCurrent(): T
|
|
66
|
-
{
|
|
67
|
-
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
68
|
-
|
|
69
|
-
return this.innerIterator.getCurrent();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public start(): PromiseAsyncResult<this>
|
|
73
|
-
{
|
|
74
|
-
return AsyncIterator.start<T, this>(this);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public takeCurrent(): PromiseAsyncResult<T>
|
|
78
|
-
{
|
|
79
|
-
return AsyncIterator.takeCurrent(this);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public any(): PromiseAsyncResult<boolean>
|
|
83
|
-
{
|
|
84
|
-
return AsyncIterator.any(this);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public getCount(): PromiseAsyncResult<number>
|
|
88
|
-
{
|
|
89
|
-
return AsyncIterator.getCount(this);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public toArray(): PromiseAsyncResult<T[]>
|
|
93
|
-
{
|
|
94
|
-
return AsyncIterator.toArray(this);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public where(condition: (value: T) => boolean): AsyncIterator<T>
|
|
98
|
-
{
|
|
99
|
-
return AsyncIterator.where(this, condition);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): AsyncIterator<U>
|
|
103
|
-
{
|
|
104
|
-
return AsyncIterator.whereInstanceOf(this, typeCheck);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public whereInstanceOfType<U extends T>(type: Type<U>): AsyncIterator<U>
|
|
108
|
-
{
|
|
109
|
-
return AsyncIterator.whereInstanceOfType(this, type);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public map<TOutput>(mapping: (value: T) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
|
|
113
|
-
{
|
|
114
|
-
return AsyncIterator.map(this, mapping);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public first(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
|
|
118
|
-
{
|
|
119
|
-
return AsyncIterator.first(this, condition);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public last(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
|
|
123
|
-
{
|
|
124
|
-
return AsyncIterator.last(this, condition);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public [Symbol.asyncIterator](): JavascriptAsyncIterator<T>
|
|
128
|
-
{
|
|
129
|
-
return AsyncIterator[Symbol.asyncIterator](this);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public take(maximumToTake: number): AsyncIterator<T>
|
|
133
|
-
{
|
|
134
|
-
return AsyncIterator.take(this, maximumToTake);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public skip(maximumToSkip: number): AsyncIterator<T>
|
|
138
|
-
{
|
|
139
|
-
return AsyncIterator.skip(this, maximumToSkip);
|
|
140
|
-
}
|
|
141
|
-
}
|
package/sources/takeIterator.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Iterator } from "./iterator";
|
|
2
|
-
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
3
|
-
import { PreCondition } from "./preCondition";
|
|
4
|
-
import { SyncResult } from "./syncResult";
|
|
5
|
-
import { Type } from "./types";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* An {@link Iterator} that iterates over a maximum number of values.
|
|
9
|
-
*/
|
|
10
|
-
export class TakeIterator<T> implements Iterator<T>
|
|
11
|
-
{
|
|
12
|
-
private readonly innerIterator: Iterator<T>;
|
|
13
|
-
private started: boolean;
|
|
14
|
-
private readonly maximumToTake: number;
|
|
15
|
-
private taken: number;
|
|
16
|
-
|
|
17
|
-
private constructor(innerIterator: Iterator<T>, maximumToTake: number)
|
|
18
|
-
{
|
|
19
|
-
PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
|
|
20
|
-
|
|
21
|
-
this.innerIterator = innerIterator;
|
|
22
|
-
this.started = false;
|
|
23
|
-
this.maximumToTake = maximumToTake;
|
|
24
|
-
this.taken = 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public static create<T>(innerIterator: Iterator<T>, maximumToTake: number)
|
|
28
|
-
{
|
|
29
|
-
return new TakeIterator(innerIterator, maximumToTake);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public hasCurrent(): boolean
|
|
33
|
-
{
|
|
34
|
-
return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public next(): SyncResult<boolean>
|
|
38
|
-
{
|
|
39
|
-
return SyncResult.create(() =>
|
|
40
|
-
{
|
|
41
|
-
if (this.maximumToTake <= 0)
|
|
42
|
-
{
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
else if (!this.hasStarted())
|
|
46
|
-
{
|
|
47
|
-
this.started = true;
|
|
48
|
-
this.innerIterator.start().await();
|
|
49
|
-
this.taken++;
|
|
50
|
-
}
|
|
51
|
-
else if (this.taken <= this.maximumToTake)
|
|
52
|
-
{
|
|
53
|
-
this.innerIterator.next().await();
|
|
54
|
-
this.taken++;
|
|
55
|
-
}
|
|
56
|
-
return this.hasCurrent();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public hasStarted(): boolean
|
|
61
|
-
{
|
|
62
|
-
return this.started;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public getCurrent(): T
|
|
66
|
-
{
|
|
67
|
-
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
68
|
-
|
|
69
|
-
return this.innerIterator.getCurrent();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public start(): SyncResult<this>
|
|
73
|
-
{
|
|
74
|
-
return Iterator.start<T, this>(this);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public takeCurrent(): SyncResult<T>
|
|
78
|
-
{
|
|
79
|
-
return Iterator.takeCurrent(this);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public any(): SyncResult<boolean>
|
|
83
|
-
{
|
|
84
|
-
return Iterator.any(this);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public getCount(): SyncResult<number>
|
|
88
|
-
{
|
|
89
|
-
return Iterator.getCount(this);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public toArray(): SyncResult<T[]>
|
|
93
|
-
{
|
|
94
|
-
return Iterator.toArray(this);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public concatenate(...toConcatenate: JavascriptIterable<T>[]): Iterator<T>
|
|
98
|
-
{
|
|
99
|
-
return Iterator.concatenate(this, ...toConcatenate);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public where(condition: (value: T) => boolean): Iterator<T>
|
|
103
|
-
{
|
|
104
|
-
return Iterator.where(this, condition);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): Iterator<U>
|
|
108
|
-
{
|
|
109
|
-
return Iterator.whereInstanceOf(this, typeCheck);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public whereInstanceOfType<U extends T>(type: Type<U>): Iterator<U>
|
|
113
|
-
{
|
|
114
|
-
return Iterator.whereInstanceOfType(this, type);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public map<TOutput>(mapping: (value: T) => (TOutput | SyncResult<TOutput>)): Iterator<TOutput>
|
|
118
|
-
{
|
|
119
|
-
return Iterator.map(this, mapping);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public flatMap<TOutput>(mapping: (value: T) => JavascriptIterable<TOutput>): Iterator<TOutput>
|
|
123
|
-
{
|
|
124
|
-
return Iterator.flatMap(this, mapping);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public first(condition?: (value: T) => boolean): SyncResult<T>
|
|
128
|
-
{
|
|
129
|
-
return Iterator.first(this, condition);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public last(condition?: (value: T) => boolean): SyncResult<T>
|
|
133
|
-
{
|
|
134
|
-
return Iterator.last(this, condition);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public [Symbol.iterator](): JavascriptIterator<T>
|
|
138
|
-
{
|
|
139
|
-
return Iterator[Symbol.iterator](this);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public take(maximumToTake: number): Iterator<T>
|
|
143
|
-
{
|
|
144
|
-
return Iterator.take(this, maximumToTake);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
public skip(maximumToSkip: number): Iterator<T>
|
|
148
|
-
{
|
|
149
|
-
return Iterator.skip(this, maximumToSkip);
|
|
150
|
-
}
|
|
151
|
-
}
|