@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
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
import { AssertMessageParameters } from "./assertMessageParameters";
|
|
2
|
-
import { Bytes } from "./bytes";
|
|
3
|
-
import { Comparer } from "./comparer";
|
|
4
|
-
import { Comparison } from "./comparison";
|
|
5
|
-
import { Condition } from "./condition";
|
|
6
|
-
import { EqualFunctions } from "./equalFunctions";
|
|
7
|
-
import { Iterable } from "./iterable";
|
|
8
|
-
import { JavascriptIterable } from "./javascript";
|
|
9
|
-
import { ToStringFunctions } from "./toStringFunctions";
|
|
10
|
-
import {
|
|
11
|
-
hasFunction, hasProperty, instanceOf, isJavascriptIterable, isString, isUndefinedOrNull, Type
|
|
12
|
-
} from "./types";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A collection of condition methods that can be used to assert the state of an application.
|
|
16
|
-
*/
|
|
17
|
-
export class MutableCondition implements Condition
|
|
18
|
-
{
|
|
19
|
-
private toStringFunctions: ToStringFunctions;
|
|
20
|
-
private equalFunctions: EqualFunctions;
|
|
21
|
-
private createErrorFunction: (message: string) => Error;
|
|
22
|
-
|
|
23
|
-
protected constructor()
|
|
24
|
-
{
|
|
25
|
-
this.toStringFunctions = ToStringFunctions.create();
|
|
26
|
-
this.equalFunctions = EqualFunctions.create();
|
|
27
|
-
this.createErrorFunction = MutableCondition.defaultCreateErrorFunction;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private static defaultCreateErrorFunction(message: string): Error
|
|
31
|
-
{
|
|
32
|
-
return new Error(message);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a new {@link MutableCondition} object.
|
|
37
|
-
*/
|
|
38
|
-
public static create(): MutableCondition
|
|
39
|
-
{
|
|
40
|
-
return new MutableCondition();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Set the {@link ToStringFunctions} that will be used to convert values to their {@link String}
|
|
45
|
-
* representations.
|
|
46
|
-
* @param toStringFunctions The {@link ToStringFunctions} that will be used to convert values to
|
|
47
|
-
* their {@link String} representations.
|
|
48
|
-
* @returns This object for method chaining.
|
|
49
|
-
*/
|
|
50
|
-
public setToStringFunctions(toStringFunctions: ToStringFunctions): this
|
|
51
|
-
{
|
|
52
|
-
this.assertNotUndefinedAndNotNull(toStringFunctions, "toStringFunctions");
|
|
53
|
-
|
|
54
|
-
this.toStringFunctions = toStringFunctions;
|
|
55
|
-
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Set the {@link EqualFunctions} that will be used to determine if values are equal.
|
|
61
|
-
* @param equalFunctions The {@link EqualFunctions} that will be used to determine if values are
|
|
62
|
-
* equal.
|
|
63
|
-
* @returns This object for method chaining.
|
|
64
|
-
*/
|
|
65
|
-
public setEqualFunctions(equalFunctions: EqualFunctions): this
|
|
66
|
-
{
|
|
67
|
-
this.assertNotUndefinedAndNotNull(equalFunctions, "equalFunctions");
|
|
68
|
-
|
|
69
|
-
this.equalFunctions = equalFunctions;
|
|
70
|
-
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Set the {@link Function} that will be used to create {@link Error}s.
|
|
76
|
-
* @param createErrorFunction The {@link Function} to use to create {@link Error}.
|
|
77
|
-
* @returns This object for method chaining.
|
|
78
|
-
*/
|
|
79
|
-
public setCreateErrorFunction(createErrorFunction: (message: string) => Error): this
|
|
80
|
-
{
|
|
81
|
-
this.assertNotUndefinedAndNotNull(createErrorFunction, "createErrorFunction");
|
|
82
|
-
|
|
83
|
-
this.createErrorFunction = createErrorFunction;
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public assertUndefined(value: unknown, expression?: string, message?: string): asserts value is undefined
|
|
88
|
-
{
|
|
89
|
-
Condition.assertUndefined(this, value, expression, message);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public assertNotUndefined<T>(value: T, expression?: string, message?: string): asserts value is NonNullable<T>
|
|
93
|
-
{
|
|
94
|
-
Condition.assertNotUndefined(this, value, expression, message);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Get whether the provided values are equal.
|
|
99
|
-
* @param left The left part of the comparison.
|
|
100
|
-
* @param right The right part of the comparison.
|
|
101
|
-
*/
|
|
102
|
-
public areEqual(left: unknown, right: unknown): boolean
|
|
103
|
-
{
|
|
104
|
-
return this.equalFunctions.areEqual(left, right).await();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get the {@link String} representation of the provided value.
|
|
109
|
-
* @param value The value to get the {@link String} representation of.
|
|
110
|
-
*/
|
|
111
|
-
public toValueString(value: unknown): string
|
|
112
|
-
{
|
|
113
|
-
return this.toStringFunctions.toString(value);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Create an {@link Error} based on the provided {@link AssertMessageParameters}.
|
|
118
|
-
* @param parameters The {@link AssertMessageParameters} that define how the should be made.
|
|
119
|
-
*/
|
|
120
|
-
public createError(parameters: AssertMessageParameters): Error
|
|
121
|
-
{
|
|
122
|
-
const message: string = MutableCondition.createErrorMessage(parameters);
|
|
123
|
-
return this.createErrorFunction(message);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Create an error message based on the provided parameters.
|
|
128
|
-
* @param parameters The parameters to use to create the error message.
|
|
129
|
-
*/
|
|
130
|
-
public static createErrorMessage(parameters: AssertMessageParameters): string
|
|
131
|
-
{
|
|
132
|
-
let result: string = "";
|
|
133
|
-
|
|
134
|
-
if (parameters.message)
|
|
135
|
-
{
|
|
136
|
-
result += `Message: ${parameters.message}`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (parameters.expression)
|
|
140
|
-
{
|
|
141
|
-
if (result)
|
|
142
|
-
{
|
|
143
|
-
result += "\n";
|
|
144
|
-
}
|
|
145
|
-
result += `Expression: ${parameters.expression}`;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (result)
|
|
149
|
-
{
|
|
150
|
-
result += "\n";
|
|
151
|
-
}
|
|
152
|
-
result += `Expected: ${parameters.expected}`;
|
|
153
|
-
|
|
154
|
-
if (result)
|
|
155
|
-
{
|
|
156
|
-
result += "\n";
|
|
157
|
-
}
|
|
158
|
-
result += `Actual: ${parameters.actual}`;
|
|
159
|
-
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
public assertNotUndefinedAndNotNull<T>(value: T, expression?: string, message?: string): asserts value is NonNullable<T>
|
|
164
|
-
{
|
|
165
|
-
if (value === undefined || value === null)
|
|
166
|
-
{
|
|
167
|
-
throw this.createError({
|
|
168
|
-
expected: `not ${this.toValueString(undefined)} and not ${this.toValueString(null)}`,
|
|
169
|
-
actual: this.toValueString(value),
|
|
170
|
-
expression: expression,
|
|
171
|
-
message: message,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public assertTrue(value: boolean, expression?: string, message?: string): asserts value is true
|
|
177
|
-
{
|
|
178
|
-
Condition.assertTrue(this, value, expression, message);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
public assertFalse(value: boolean, expression?: string, message?: string): asserts value is false
|
|
182
|
-
{
|
|
183
|
-
if (value !== false)
|
|
184
|
-
{
|
|
185
|
-
throw this.createError({
|
|
186
|
-
expected: this.toValueString(false),
|
|
187
|
-
actual: this.toValueString(value),
|
|
188
|
-
expression: expression,
|
|
189
|
-
message: message,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
public assertSame<T>(expected: T, actual: T, expression?: string, message?: string): void
|
|
195
|
-
{
|
|
196
|
-
if (expected !== actual)
|
|
197
|
-
{
|
|
198
|
-
throw this.createError({
|
|
199
|
-
expected: this.toValueString(expected),
|
|
200
|
-
actual: this.toValueString(actual),
|
|
201
|
-
expression: expression,
|
|
202
|
-
message: message,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
public assertNotSame<T>(expected: T, actual: T, expression?: string, message?: string): void
|
|
208
|
-
{
|
|
209
|
-
if (expected === actual)
|
|
210
|
-
{
|
|
211
|
-
throw this.createError({
|
|
212
|
-
expected: `not ${this.toValueString(expected)}`,
|
|
213
|
-
actual: this.toValueString(actual),
|
|
214
|
-
expression: expression,
|
|
215
|
-
message: message,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public assertEqual<T>(expected: T, actual: T, expression?: string, message?: string): void
|
|
221
|
-
{
|
|
222
|
-
let comparison: Comparison | undefined = Comparer.compareSameUndefinedNull(expected, actual);
|
|
223
|
-
if (comparison === undefined && this.areEqual(expected, actual))
|
|
224
|
-
{
|
|
225
|
-
comparison = Comparison.Equal;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (comparison !== Comparison.Equal)
|
|
229
|
-
{
|
|
230
|
-
throw this.createError({
|
|
231
|
-
expected: this.toValueString(expected),
|
|
232
|
-
actual: this.toValueString(actual),
|
|
233
|
-
expression: expression,
|
|
234
|
-
message: message,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
public assertNotEqual<T>(notExpected: T, actual: T, expression?: string, message?: string): void
|
|
240
|
-
{
|
|
241
|
-
let comparison: Comparison | undefined = Comparer.compareSameUndefinedNull(notExpected, actual);
|
|
242
|
-
if (comparison === undefined && this.areEqual(notExpected, actual))
|
|
243
|
-
{
|
|
244
|
-
comparison = Comparison.Equal;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (comparison === Comparison.Equal)
|
|
248
|
-
{
|
|
249
|
-
throw this.createError({
|
|
250
|
-
expected: `not ${this.toValueString(notExpected)}`,
|
|
251
|
-
actual: this.toValueString(actual),
|
|
252
|
-
expression: expression,
|
|
253
|
-
message: message,
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
public assertNotEmpty<T extends JavascriptIterable<unknown> | string | null | undefined>(value: T, expression?: string, message?: string): asserts value is NonNullable<T>
|
|
259
|
-
{
|
|
260
|
-
this.assertNotUndefinedAndNotNull(value, expression, message);
|
|
261
|
-
if ((isString(value) && value.length === 0) ||
|
|
262
|
-
(isJavascriptIterable(value) && !Iterable.create(value).any()))
|
|
263
|
-
{
|
|
264
|
-
throw this.createError({
|
|
265
|
-
expected: "not empty",
|
|
266
|
-
actual: this.toValueString(value),
|
|
267
|
-
expression: expression,
|
|
268
|
-
message: message,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
public assertLessThan(value: number, upperBound: number, expression?: string, message?: string): void
|
|
274
|
-
{
|
|
275
|
-
if (!(value < upperBound))
|
|
276
|
-
{
|
|
277
|
-
throw this.createError({
|
|
278
|
-
expected: `less than ${this.toValueString(upperBound)}`,
|
|
279
|
-
actual: this.toValueString(value),
|
|
280
|
-
expression: expression,
|
|
281
|
-
message: message,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
public assertLessThanOrEqualTo(value: number, upperBound: number, expression?: string, message?: string): void
|
|
287
|
-
{
|
|
288
|
-
if (!(value <= upperBound))
|
|
289
|
-
{
|
|
290
|
-
throw this.createError({
|
|
291
|
-
expected: `less than or equal to ${this.toValueString(upperBound)}`,
|
|
292
|
-
actual: this.toValueString(value),
|
|
293
|
-
expression: expression,
|
|
294
|
-
message: message,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
public assertGreaterThanOrEqualTo(value: number, lowerBound: number, expression?: string, message?: string): void
|
|
300
|
-
{
|
|
301
|
-
if (!(lowerBound <= value))
|
|
302
|
-
{
|
|
303
|
-
throw this.createError({
|
|
304
|
-
expected: `greater than or equal to ${this.toValueString(lowerBound)}`,
|
|
305
|
-
actual: this.toValueString(value),
|
|
306
|
-
expression: expression,
|
|
307
|
-
message: message,
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
public assertGreaterThan(value: number, lowerBound: number, expression?: string, message?: string): void
|
|
313
|
-
{
|
|
314
|
-
if (!(lowerBound < value))
|
|
315
|
-
{
|
|
316
|
-
throw this.createError({
|
|
317
|
-
expected: `greater than ${this.toValueString(lowerBound)}`,
|
|
318
|
-
actual: this.toValueString(value),
|
|
319
|
-
expression: expression,
|
|
320
|
-
message: message,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
public assertBetween(lowerBound: number, value: number, upperBound: number, expression?: string, message?: string): void
|
|
326
|
-
{
|
|
327
|
-
this.assertLessThanOrEqualTo(lowerBound, upperBound, "lowerBound");
|
|
328
|
-
if (isUndefinedOrNull(value) || !(lowerBound <= value && value <= upperBound))
|
|
329
|
-
{
|
|
330
|
-
throw this.createError({
|
|
331
|
-
expected: (lowerBound === upperBound
|
|
332
|
-
? this.toValueString(lowerBound)
|
|
333
|
-
: `between ${this.toValueString(lowerBound)} and ${this.toValueString(upperBound)}`),
|
|
334
|
-
actual: this.toValueString(value),
|
|
335
|
-
expression: expression,
|
|
336
|
-
message: message,
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
public assertAccessIndex(index: number, count: number, expression?: string, message?: string): void
|
|
342
|
-
{
|
|
343
|
-
this.assertGreaterThanOrEqualTo(count, 1, "count");
|
|
344
|
-
this.assertInteger(index, expression);
|
|
345
|
-
this.assertBetween(0, index, count - 1, expression, message);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
public assertInsertIndex(index: number, count: number, expression?: string, message?: string): void
|
|
349
|
-
{
|
|
350
|
-
this.assertGreaterThanOrEqualTo(count, 0, "count");
|
|
351
|
-
this.assertInteger(index, expression);
|
|
352
|
-
this.assertBetween(0, index, count, expression, message);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
public assertOneOf<T>(possibilities: JavascriptIterable<T>, value: T, expression?: string, message?: string): void
|
|
356
|
-
{
|
|
357
|
-
this.assertNotUndefinedAndNotNull(possibilities, "possibilities");
|
|
358
|
-
|
|
359
|
-
let found: boolean = false;
|
|
360
|
-
for (const possibility of possibilities)
|
|
361
|
-
{
|
|
362
|
-
if (this.areEqual(possibility, value))
|
|
363
|
-
{
|
|
364
|
-
found = true;
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (!found)
|
|
370
|
-
{
|
|
371
|
-
throw this.createError({
|
|
372
|
-
expected: `one of ${this.toValueString(possibilities)}`,
|
|
373
|
-
actual: this.toValueString(value),
|
|
374
|
-
expression: expression,
|
|
375
|
-
message: message,
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
public assertByte(value: number, expression?: string, message?: string): void
|
|
381
|
-
{
|
|
382
|
-
this.assertBetween(Bytes.minimumValue, value, Bytes.maximumValue, expression, message);
|
|
383
|
-
this.assertInteger(value, "value");
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
public assertInteger(value: number, expression?: string, message?: string): void
|
|
387
|
-
{
|
|
388
|
-
if (value % 1 !== 0)
|
|
389
|
-
{
|
|
390
|
-
throw this.createError({
|
|
391
|
-
expected: `integer`,
|
|
392
|
-
actual: this.toValueString(value),
|
|
393
|
-
expression: expression,
|
|
394
|
-
message: message,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
public assertCharacter(value: string, expression?: string, message?: string): void
|
|
400
|
-
{
|
|
401
|
-
if (!value || value.length !== 1)
|
|
402
|
-
{
|
|
403
|
-
throw this.createError({
|
|
404
|
-
expected: `character`,
|
|
405
|
-
actual: this.toValueString(value),
|
|
406
|
-
expression: expression,
|
|
407
|
-
message: message,
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
public assertInstanceOf<T>(value: unknown, type: Type<T>, typeCheck?: (value: unknown) => value is T, expression?: string, message?: string): asserts value is T;
|
|
413
|
-
public assertInstanceOf<T>(parameters: { value: unknown, type: Type<T>, typeCheck?: (value: unknown) => value is T, expression?: string, message?: string }): void;
|
|
414
|
-
public assertInstanceOf<T>(parametersOrValue: unknown | { value: unknown, type: Type<T>, typeCheck?: (value: unknown) => value is T, expression?: string, message?: string }, type?: Type<T>, typeCheck?: (value: unknown) => value is T, expression?: string, message?: string): void;
|
|
415
|
-
public assertInstanceOf<T>(parametersOrValue: unknown | { value: unknown, type: Type<T>, typeCheck?: (value: unknown) => value is T, expression?: string, message?: string }, type?: Type<T>, typeCheck?: (value: unknown) => value is T, expression?: string, message?: string): void
|
|
416
|
-
{
|
|
417
|
-
let value: unknown;
|
|
418
|
-
if (hasProperty(parametersOrValue, "value") &&
|
|
419
|
-
hasProperty(parametersOrValue, "type"))
|
|
420
|
-
{
|
|
421
|
-
value = parametersOrValue.value;
|
|
422
|
-
type = parametersOrValue.type as Type<T>;
|
|
423
|
-
if (hasFunction(parametersOrValue, "typeCheck"))
|
|
424
|
-
{
|
|
425
|
-
typeCheck = parametersOrValue.typeCheck as (value: unknown) => value is T;
|
|
426
|
-
}
|
|
427
|
-
if (hasProperty(parametersOrValue, "expression"))
|
|
428
|
-
{
|
|
429
|
-
expression = parametersOrValue.expression as string;
|
|
430
|
-
}
|
|
431
|
-
if (hasProperty(parametersOrValue, "message"))
|
|
432
|
-
{
|
|
433
|
-
message = parametersOrValue.message as string;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
else
|
|
437
|
-
{
|
|
438
|
-
value = parametersOrValue;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (!instanceOf(value, type!, typeCheck))
|
|
442
|
-
{
|
|
443
|
-
throw this.createError({
|
|
444
|
-
expected: `instance of ${type!.name}`,
|
|
445
|
-
actual: this.toValueString(value),
|
|
446
|
-
expression: expression,
|
|
447
|
-
message: message,
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { EqualFunctions } from "./equalFunctions";
|
|
2
|
-
import { HttpHeader } from "./httpHeader";
|
|
3
|
-
import { HttpHeaders } from "./httpHeaders";
|
|
4
|
-
import { Iterable } from "./iterable";
|
|
5
|
-
import { Iterator } from "./iterator";
|
|
6
|
-
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
7
|
-
import { List } from "./list";
|
|
8
|
-
import { NotFoundError } from "./notFoundError";
|
|
9
|
-
import { PreCondition } from "./preCondition";
|
|
10
|
-
import { escapeAndQuote } from "./strings";
|
|
11
|
-
import { SyncResult } from "./syncResult";
|
|
12
|
-
import { ToStringFunctions } from "./toStringFunctions";
|
|
13
|
-
import { isString, Type } from "./types";
|
|
14
|
-
|
|
15
|
-
export class MutableHttpHeaders implements HttpHeaders
|
|
16
|
-
{
|
|
17
|
-
private readonly headers: List<HttpHeader>;
|
|
18
|
-
|
|
19
|
-
private constructor(headers?: JavascriptIterable<HttpHeader>)
|
|
20
|
-
{
|
|
21
|
-
this.headers = List.create();
|
|
22
|
-
if (headers)
|
|
23
|
-
{
|
|
24
|
-
this.setAll(headers);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public static create(headers?: JavascriptIterable<HttpHeader>): MutableHttpHeaders
|
|
29
|
-
{
|
|
30
|
-
return new MutableHttpHeaders(headers);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public iterate(): Iterator<HttpHeader>
|
|
34
|
-
{
|
|
35
|
-
return this.headers.iterate();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public get(headerName: string): SyncResult<HttpHeader>
|
|
39
|
-
{
|
|
40
|
-
PreCondition.assertNotEmpty(headerName, "headerName");
|
|
41
|
-
|
|
42
|
-
return SyncResult.create(() =>
|
|
43
|
-
{
|
|
44
|
-
let result: HttpHeader | undefined;
|
|
45
|
-
|
|
46
|
-
const lowerHeaderName: string = headerName.toLowerCase();
|
|
47
|
-
for (const header of this.headers)
|
|
48
|
-
{
|
|
49
|
-
if (header.getName().toLowerCase() === lowerHeaderName)
|
|
50
|
-
{
|
|
51
|
-
result = header
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (result === undefined)
|
|
56
|
-
{
|
|
57
|
-
throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return result;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public getValue(headerName: string): SyncResult<string>
|
|
65
|
-
{
|
|
66
|
-
return this.get(headerName)
|
|
67
|
-
.then((header: HttpHeader) => header.getValue());
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Set a {@link HttpHeader} value in this collection. This will overwrite any existing
|
|
72
|
-
* {@link HttpHeader} with the same name.
|
|
73
|
-
* @param headerName The name of the header to set.
|
|
74
|
-
* @param headerValue The value of the header to set.
|
|
75
|
-
*/
|
|
76
|
-
public set(headerName: string, headerValue: string): this;
|
|
77
|
-
public set(header: HttpHeader): this;
|
|
78
|
-
set(headerOrHeaderName: HttpHeader | string, headerValue?: string): this
|
|
79
|
-
{
|
|
80
|
-
let headerName: string;
|
|
81
|
-
if (isString(headerOrHeaderName))
|
|
82
|
-
{
|
|
83
|
-
headerName = headerOrHeaderName;
|
|
84
|
-
}
|
|
85
|
-
else
|
|
86
|
-
{
|
|
87
|
-
headerName = headerOrHeaderName.getName();
|
|
88
|
-
headerValue = headerOrHeaderName.getValue();
|
|
89
|
-
}
|
|
90
|
-
PreCondition.assertNotEmpty(headerName, "headerName");
|
|
91
|
-
PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
|
|
92
|
-
|
|
93
|
-
let insertIndex: number = 0;
|
|
94
|
-
for (let insertIndex = 0; insertIndex < this.headers.getCount().await(); insertIndex++)
|
|
95
|
-
{
|
|
96
|
-
const header: HttpHeader = this.headers.get(insertIndex).await();
|
|
97
|
-
if (header.getName() === headerName)
|
|
98
|
-
{
|
|
99
|
-
this.headers.removeAt(insertIndex);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
|
|
104
|
-
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public setAll(headers: JavascriptIterable<HttpHeader>): this
|
|
109
|
-
{
|
|
110
|
-
PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
|
|
111
|
-
|
|
112
|
-
for (const header of headers)
|
|
113
|
-
{
|
|
114
|
-
this.set(header);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public setContentType(contentType: string): this
|
|
121
|
-
{
|
|
122
|
-
return this.set(HttpHeaders.contentTypeHeaderName, contentType);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public getContentType(): SyncResult<HttpHeader>
|
|
126
|
-
{
|
|
127
|
-
return this.get(HttpHeaders.contentTypeHeaderName);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public getContentTypeValue(): SyncResult<string>
|
|
131
|
-
{
|
|
132
|
-
return this.getValue(HttpHeaders.contentTypeHeaderName);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public getCount(): SyncResult<number>
|
|
136
|
-
{
|
|
137
|
-
return this.headers.getCount();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public toArray(): SyncResult<HttpHeader[]>
|
|
141
|
-
{
|
|
142
|
-
return HttpHeaders.toArray(this);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public any(): SyncResult<boolean>
|
|
146
|
-
{
|
|
147
|
-
return HttpHeaders.any(this);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public equals(right: JavascriptIterable<HttpHeader>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
151
|
-
{
|
|
152
|
-
return HttpHeaders.equals(this, right, equalFunctions);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public toString(toStringFunctions?: ToStringFunctions): string
|
|
156
|
-
{
|
|
157
|
-
return HttpHeaders.toString(this, toStringFunctions);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
public concatenate(...toConcatenate: JavascriptIterable<HttpHeader>[]): Iterable<HttpHeader>
|
|
161
|
-
{
|
|
162
|
-
return HttpHeaders.concatenate(this, ...toConcatenate);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public map<TOutput>(mapping: (value: HttpHeader) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
|
|
166
|
-
{
|
|
167
|
-
return HttpHeaders.map(this, mapping);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public flatMap<TOutput>(mapping: (value: HttpHeader) => JavascriptIterable<TOutput>): Iterable<TOutput>
|
|
171
|
-
{
|
|
172
|
-
return HttpHeaders.flatMap(this, mapping);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
public where(condition: (value: HttpHeader) => (boolean | SyncResult<boolean>)): Iterable<HttpHeader>
|
|
176
|
-
{
|
|
177
|
-
return HttpHeaders.where(this, condition);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public instanceOf<TOutput extends HttpHeader>(typeOrTypeCheck: Type<TOutput> | ((value: HttpHeader) => value is TOutput)): Iterable<TOutput>
|
|
181
|
-
{
|
|
182
|
-
return HttpHeaders.instanceOf(this, typeOrTypeCheck);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
public first(condition?: (value: HttpHeader) => (boolean | SyncResult<boolean>)): SyncResult<HttpHeader>
|
|
186
|
-
{
|
|
187
|
-
return HttpHeaders.first(this, condition);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
public last(condition?: (value: HttpHeader) => (boolean | SyncResult<boolean>)): SyncResult<HttpHeader>
|
|
191
|
-
{
|
|
192
|
-
return HttpHeaders.last(this, condition);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
public [Symbol.iterator](): JavascriptIterator<HttpHeader>
|
|
196
|
-
{
|
|
197
|
-
return HttpHeaders[Symbol.iterator](this);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
public contains(value: HttpHeader, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
201
|
-
{
|
|
202
|
-
return HttpHeaders.contains(this, value, equalFunctions);
|
|
203
|
-
}
|
|
204
|
-
}
|