@everyonesoftware/common 3.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.
Files changed (176) hide show
  1. package/outputs/chunk-AY3YWKOM.js +7741 -0
  2. package/outputs/chunk-AY3YWKOM.js.map +1 -0
  3. package/outputs/sources.cjs +9007 -0
  4. package/outputs/sources.cjs.map +1 -0
  5. package/outputs/sources.d.cts +4082 -0
  6. package/outputs/sources.d.ts +4082 -0
  7. package/outputs/sources.js +1370 -0
  8. package/outputs/sources.js.map +1 -0
  9. package/outputs/tests.cjs +17208 -0
  10. package/outputs/tests.cjs.map +1 -0
  11. package/outputs/tests.d.cts +3 -0
  12. package/outputs/tests.d.ts +3 -0
  13. package/outputs/tests.js +9798 -0
  14. package/outputs/tests.js.map +1 -0
  15. package/package.json +6 -1
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -54
  18. package/.mocharc.json +0 -9
  19. package/sources/assertMessageParameters.ts +0 -22
  20. package/sources/asyncIterator.ts +0 -437
  21. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
  22. package/sources/asyncResult.ts +0 -95
  23. package/sources/basicDisposable.ts +0 -57
  24. package/sources/byteList.ts +0 -202
  25. package/sources/byteListStream.ts +0 -121
  26. package/sources/byteReadStream.ts +0 -24
  27. package/sources/byteWriteStream.ts +0 -16
  28. package/sources/bytes.ts +0 -25
  29. package/sources/characterList.ts +0 -195
  30. package/sources/characterListStream.ts +0 -151
  31. package/sources/characterReadStream.ts +0 -81
  32. package/sources/characterReadStreamIterator.ts +0 -128
  33. package/sources/characterWriteStream.ts +0 -45
  34. package/sources/commandLineParameter.ts +0 -45
  35. package/sources/commandLineParameters.ts +0 -21
  36. package/sources/comparable.ts +0 -144
  37. package/sources/comparer.ts +0 -133
  38. package/sources/comparison.ts +0 -20
  39. package/sources/concatenateIterable.ts +0 -119
  40. package/sources/concatenateIterator.ts +0 -165
  41. package/sources/condition.ts +0 -329
  42. package/sources/currentProcess.ts +0 -158
  43. package/sources/dateTime.ts +0 -130
  44. package/sources/depthFirstSearch.ts +0 -230
  45. package/sources/disposable.ts +0 -31
  46. package/sources/emptyError.ts +0 -10
  47. package/sources/english.ts +0 -45
  48. package/sources/equalFunctions.ts +0 -123
  49. package/sources/fetchHttpClient.ts +0 -89
  50. package/sources/fetchHttpResponse.ts +0 -106
  51. package/sources/flatMapIterable.ts +0 -104
  52. package/sources/flatMapIterator.ts +0 -152
  53. package/sources/generator.ts +0 -251
  54. package/sources/httpClient.ts +0 -36
  55. package/sources/httpHeader.ts +0 -37
  56. package/sources/httpHeaders.ts +0 -216
  57. package/sources/httpIncomingRequest.ts +0 -30
  58. package/sources/httpIncomingResponse.ts +0 -19
  59. package/sources/httpMethod.ts +0 -164
  60. package/sources/httpOutgoingRequest.ts +0 -119
  61. package/sources/httpOutgoingResponse.ts +0 -113
  62. package/sources/httpServer.ts +0 -34
  63. package/sources/inMemoryCharacterWriteStream.ts +0 -78
  64. package/sources/index.ts +0 -101
  65. package/sources/iterable.ts +0 -345
  66. package/sources/iterator.ts +0 -481
  67. package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
  68. package/sources/javascript.ts +0 -59
  69. package/sources/javascriptArrayList.ts +0 -175
  70. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
  71. package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
  72. package/sources/javascriptMapMap.ts +0 -143
  73. package/sources/javascriptSetSet.ts +0 -134
  74. package/sources/list.ts +0 -330
  75. package/sources/listQueue.ts +0 -62
  76. package/sources/listStack.ts +0 -62
  77. package/sources/luxonDateTime.ts +0 -109
  78. package/sources/map.ts +0 -302
  79. package/sources/mapAsyncIterator.ts +0 -141
  80. package/sources/mapIterable.ts +0 -105
  81. package/sources/mapIterator.ts +0 -145
  82. package/sources/mutableCondition.ts +0 -451
  83. package/sources/mutableHttpHeaders.ts +0 -204
  84. package/sources/mutableMap.ts +0 -292
  85. package/sources/network.ts +0 -18
  86. package/sources/node.ts +0 -37
  87. package/sources/nodeJSCharacterWriteStream.ts +0 -42
  88. package/sources/nodeJSHttpIncomingRequest.ts +0 -132
  89. package/sources/nodeJSHttpServer.ts +0 -134
  90. package/sources/notFoundError.ts +0 -12
  91. package/sources/postCondition.ts +0 -284
  92. package/sources/postConditionError.ts +0 -12
  93. package/sources/preCondition.ts +0 -284
  94. package/sources/preConditionError.ts +0 -12
  95. package/sources/promiseAsyncResult.ts +0 -174
  96. package/sources/property.ts +0 -63
  97. package/sources/queue.ts +0 -49
  98. package/sources/realNetwork.ts +0 -28
  99. package/sources/recreationDotGovClient.ts +0 -259
  100. package/sources/searchControl.ts +0 -42
  101. package/sources/set.ts +0 -244
  102. package/sources/skipAsyncIterator.ts +0 -145
  103. package/sources/skipIterator.ts +0 -155
  104. package/sources/stack.ts +0 -48
  105. package/sources/stringComparer.ts +0 -33
  106. package/sources/stringIterator.ts +0 -149
  107. package/sources/strings.ts +0 -322
  108. package/sources/syncResult.ts +0 -300
  109. package/sources/takeAsyncIterator.ts +0 -141
  110. package/sources/takeIterator.ts +0 -151
  111. package/sources/toStringFunctions.ts +0 -185
  112. package/sources/types.ts +0 -371
  113. package/sources/whereAsyncIterator.ts +0 -143
  114. package/sources/whereIterable.ts +0 -108
  115. package/sources/whereIterator.ts +0 -157
  116. package/sources/wonderlandTrailClient.ts +0 -1503
  117. package/tests/assertTest.ts +0 -113
  118. package/tests/assertTestTests.ts +0 -75
  119. package/tests/basicTestSkip.ts +0 -51
  120. package/tests/byteListStreamTests.ts +0 -390
  121. package/tests/byteListTests.ts +0 -27
  122. package/tests/bytesTests.ts +0 -43
  123. package/tests/characterListStreamTests.ts +0 -391
  124. package/tests/characterListTests.ts +0 -250
  125. package/tests/characterWriteStreamTests.ts +0 -12
  126. package/tests/comparerTests.ts +0 -92
  127. package/tests/conditionTests.ts +0 -877
  128. package/tests/consoleTestRunner.ts +0 -404
  129. package/tests/consoleTestRunnerTests.ts +0 -651
  130. package/tests/dateTimeTests.ts +0 -30
  131. package/tests/depthFirstSearchTests.ts +0 -106
  132. package/tests/disposableTests.ts +0 -121
  133. package/tests/englishTests.ts +0 -103
  134. package/tests/equalFunctionsTests.ts +0 -223
  135. package/tests/failedTest.ts +0 -43
  136. package/tests/fetchHttpClientTests.ts +0 -33
  137. package/tests/generatorTests.ts +0 -86
  138. package/tests/httpClientTests.ts +0 -18
  139. package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
  140. package/tests/iterableTests.ts +0 -141
  141. package/tests/iteratorTests.ts +0 -1086
  142. package/tests/javascriptMapMapTests.ts +0 -21
  143. package/tests/listTests.ts +0 -338
  144. package/tests/mapIteratorTests.ts +0 -55
  145. package/tests/mapTests.ts +0 -104
  146. package/tests/mutableConditionTests.ts +0 -273
  147. package/tests/mutableMapTests.ts +0 -154
  148. package/tests/nodeJSHttpServerTests.ts +0 -75
  149. package/tests/notFoundErrorTests.ts +0 -24
  150. package/tests/postConditionErrorTests.ts +0 -24
  151. package/tests/preConditionErrorTests.ts +0 -24
  152. package/tests/promiseAsyncResultTests.ts +0 -688
  153. package/tests/propertyTests.ts +0 -63
  154. package/tests/queueTests.ts +0 -29
  155. package/tests/recreationDotGovClientTests.ts +0 -191
  156. package/tests/setTests.ts +0 -140
  157. package/tests/skippedTest.ts +0 -39
  158. package/tests/stackTests.ts +0 -66
  159. package/tests/stringComparerTests.ts +0 -60
  160. package/tests/stringIteratorTests.ts +0 -156
  161. package/tests/stringsTests.ts +0 -516
  162. package/tests/syncResultTests.ts +0 -1251
  163. package/tests/test.ts +0 -228
  164. package/tests/testAction.ts +0 -75
  165. package/tests/testActionTests.ts +0 -93
  166. package/tests/testFailureTests.ts +0 -12
  167. package/tests/testRunner.ts +0 -267
  168. package/tests/testRunnerTests.ts +0 -895
  169. package/tests/testSkip.ts +0 -34
  170. package/tests/tests.ts +0 -103
  171. package/tests/toStringFunctionsTests.ts +0 -55
  172. package/tests/typesTests.ts +0 -257
  173. package/tests/whereIteratorTests.ts +0 -77
  174. package/tests/wonderlandTrailClientTests.ts +0 -452
  175. package/tsconfig.json +0 -20
  176. package/tsup.config.ts +0 -13
@@ -1,292 +0,0 @@
1
- import { EqualFunctions } from "./equalFunctions";
2
- import { Iterable } from "./iterable";
3
- import { Iterator } from "./iterator";
4
- import { JavascriptIterable, JavascriptIterator } from "./javascript";
5
- import { JavascriptMapMap } from "./javascriptMapMap";
6
- import { NotFoundError } from "./notFoundError";
7
- import { PreCondition } from "./preCondition";
8
- import { SyncResult } from "./syncResult";
9
- import { ToStringFunctions } from "./toStringFunctions";
10
- import { hasFunction, Type } from "./types";
11
- import { isMap, Map, MapEntry } from "./map";
12
-
13
- /**
14
- * Get whether the provided value is {@link Map}.
15
- * @param value The value to check.
16
- */
17
- export function isMutableMap(value: unknown): value is MutableMap<unknown, unknown>
18
- {
19
- return value instanceof MutableMap ||
20
- (
21
- isMap(value) &&
22
- hasFunction(value, "set", 2) &&
23
- hasFunction(value, "getOrSet", 2)
24
- );
25
- }
26
-
27
- /**
28
- * A type that maps {@link TKey} values to {@link TValue} values.
29
- */
30
- export abstract class MutableMap<TKey, TValue> implements Map<TKey, TValue>
31
- {
32
- /**
33
- * Create a new instance of the default {@link Map} implementation.
34
- */
35
- public static create<TKey, TValue>(): MutableMap<TKey, TValue>
36
- {
37
- return JavascriptMapMap.create();
38
- }
39
-
40
- /**
41
- * Iterate over the entries in this {@link MutableMap}.
42
- */
43
- public abstract iterate(): Iterator<MapEntry<TKey, TValue>>;
44
-
45
- public any(): SyncResult<boolean>
46
- {
47
- return MutableMap.any(this);
48
- }
49
-
50
- public static any<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<boolean>
51
- {
52
- return Map.any(map);
53
- }
54
-
55
- public toArray(): SyncResult<MapEntry<TKey, TValue>[]>
56
- {
57
- return MutableMap.toArray(this);
58
- }
59
-
60
- public static toArray<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<MapEntry<TKey,TValue>[]>
61
- {
62
- return Map.toArray(map);
63
- }
64
-
65
- public equals(right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
66
- {
67
- return MutableMap.equals(this, right, equalFunctions);
68
- }
69
-
70
- public static equals<TKey, TValue>(left: MutableMap<TKey, TValue>, right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
71
- {
72
- return Map.equals(left, right, equalFunctions);
73
- }
74
-
75
- /**
76
- * Get the {@link String} representation of this {@link MutableMap}.
77
- */
78
- public toString(toStringFunctions?: ToStringFunctions): string
79
- {
80
- return MutableMap.toString(this, toStringFunctions);
81
- }
82
-
83
- /**
84
- * Get the {@link String} representation of the provided {@link MutableMap}.
85
- */
86
- public static toString<TKey, TValue>(map: MutableMap<TKey, TValue>, toStringFunctions?: ToStringFunctions): string
87
- {
88
- return Map.toString(map, toStringFunctions);
89
- }
90
-
91
- public concatenate(...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
92
- {
93
- return MutableMap.concatenate(this, ...toConcatenate);
94
- }
95
-
96
- public static concatenate<TKey,TValue>(map: MutableMap<TKey,TValue>, ...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
97
- {
98
- return Map.concatenate(map, ...toConcatenate);
99
- }
100
-
101
- public map<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
102
- {
103
- return MutableMap.map(this, mapping);
104
- }
105
-
106
- public static map<TKey,TValue,TOutput>(map: MutableMap<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
107
- {
108
- return Map.map(map, mapping);
109
- }
110
-
111
- public flatMap<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
112
- {
113
- return MutableMap.flatMap(this, mapping);
114
- }
115
-
116
- public static flatMap<TKey,TValue,TOutput>(map: MutableMap<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
117
- {
118
- return Map.flatMap(map, mapping);
119
- }
120
-
121
- public where(condition: (value: MapEntry<TKey, TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey, TValue>>
122
- {
123
- return MutableMap.where(this, condition);
124
- }
125
-
126
- public static where<TKey,TValue>(map: MutableMap<TKey,TValue>, condition: (value: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey,TValue>>
127
- {
128
- return Map.where(map, condition);
129
- }
130
-
131
- public instanceOf<T extends MapEntry<TKey, TValue>>(typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
132
- {
133
- return MutableMap.instanceOf(this, typeOrTypeCheck);
134
- }
135
-
136
- public static instanceOf<TKey,TValue,T extends MapEntry<TKey, TValue>>(map: MutableMap<TKey,TValue>, typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
137
- {
138
- return Map.instanceOf(map, typeOrTypeCheck);
139
- }
140
-
141
- public [Symbol.iterator](): JavascriptIterator<MapEntry<TKey, TValue>>
142
- {
143
- return MutableMap[Symbol.iterator](this);
144
- }
145
-
146
- public static [Symbol.iterator]<TKey,TValue>(map: MutableMap<TKey,TValue>): JavascriptIterator<MapEntry<TKey,TValue>>
147
- {
148
- return Map[Symbol.iterator](map);
149
- }
150
-
151
- /**
152
- * Get the number of entries in this {@link MutableMap}.
153
- */
154
- public getCount(): SyncResult<number>
155
- {
156
- return MutableMap.getCount(this);
157
- }
158
-
159
- public static getCount<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<number>
160
- {
161
- return Map.getCount(map);
162
- }
163
-
164
- public first(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
165
- {
166
- return MutableMap.first(this, condition);
167
- }
168
-
169
- public static first<TKey,TValue>(map: MutableMap<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
170
- {
171
- return Map.first(map, condition);
172
- }
173
-
174
- public last(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
175
- {
176
- return MutableMap.last(this, condition);
177
- }
178
-
179
- public static last<TKey,TValue>(map: MutableMap<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
180
- {
181
- return Map.last(map, condition);
182
- }
183
-
184
- /**
185
- * Get whether this {@link MutableMap} contains the provided key.
186
- * @param key The key to look for.
187
- */
188
- public abstract containsKey(key: TKey): SyncResult<boolean>;
189
-
190
- /**
191
- * Get the value associated with the provided key.
192
- * @param key The key of the value to get.
193
- */
194
- public abstract get(key: TKey): SyncResult<TValue>;
195
-
196
- /**
197
- * Set the key/value association in this {@link MutableMap}.
198
- * @param key The key associated with the value.
199
- * @param value The value associated with the key.
200
- */
201
- public abstract set(key: TKey, value: TValue): this;
202
-
203
- /**
204
- * Get the {@link TValue} associated with the provided {@link TKey}. If the provided
205
- * {@link TKey} doesn't exist in this {@link MutableMap}, then invoke the provided {@link valueCreator}
206
- * and associate the returned {@link TValue} with the provided {@link TKey}. Then return the new
207
- * {@link TValue}.
208
- * @param key The {@link TKey} of the {@link TValue} to get.
209
- * @param valueCreator The {@link Function} that will be invoked if the {@link TKey} doesn't
210
- * exist in this {@link MutableMap}.
211
- */
212
- public getOrSet(key: TKey, valueCreator: () => (TValue | SyncResult<TValue>)): SyncResult<TValue>
213
- {
214
- return MutableMap.getOrSet(this, key, valueCreator);
215
- }
216
-
217
- /**
218
- * Get the {@link TValue} associated with the provided {@link TKey}. If the provided
219
- * {@link TKey} doesn't exist in the {@link MutableMap}, then invoke the provided {@link valueCreator}
220
- * and associate the returned {@link TValue} with the provided {@link TKey}. Then return the new
221
- * {@link TValue}.
222
- * @param key The {@link TKey} of the {@link TValue} to get.
223
- * @param valueCreator The {@link Function} that will be invoked if the {@link TKey} doesn't
224
- * exist in this {@link MutableMap}.
225
- */
226
- public static getOrSet<TKey, TValue>(map: MutableMap<TKey, TValue>, key: TKey, valueCreator: () => (TValue | SyncResult<TValue>)): SyncResult<TValue>
227
- {
228
- PreCondition.assertNotUndefinedAndNotNull(map, "map");
229
- PreCondition.assertNotUndefinedAndNotNull(valueCreator, "valueCreator");
230
-
231
- return map.get(key)
232
- .catch(NotFoundError, () =>
233
- {
234
- const creatorResult: TValue | SyncResult<TValue> = valueCreator();
235
- const value: TValue = creatorResult instanceof SyncResult ? creatorResult.await() : creatorResult;
236
- map.set(key, value);
237
- return value;
238
- });
239
- }
240
-
241
- /**
242
- * Remove the provided {@link TKey} from this {@link MutableMap}. If the {@link TKey} doesn't exist in
243
- * this {@link MutableMap}, then return a {@link NotFoundError}. If the {@link TKey} does exist, then
244
- * return the {@link TValue} that was associated with it.
245
- * @param key The {@link TKey} to remove from this {@link MutableMap}.
246
- */
247
- public abstract remove(key: TKey): SyncResult<TValue>;
248
-
249
- /**
250
- * Iterate over the keys in this {@link MutableMap}.
251
- */
252
- public iterateKeys(): Iterator<TKey>
253
- {
254
- return MutableMap.iterateKeys(this);
255
- }
256
-
257
- /**
258
- * Iterate over the keys in the {@link MutableMap}.
259
- * @param map The map to iterate over.
260
- */
261
- public static iterateKeys<TKey, TValue>(map: MutableMap<TKey, TValue>): Iterator<TKey>
262
- {
263
- return Map.iterateKeys(map);
264
- }
265
-
266
- /**
267
- * Iterate over the values in this {@link MutableMap}.
268
- */
269
- public iterateValues(): Iterator<TValue>
270
- {
271
- return MutableMap.iterateValues(this);
272
- }
273
-
274
- /**
275
- * Iterate over the keys in the {@link MutableMap}.
276
- * @param map The map to iterate over.
277
- */
278
- public static iterateValues<TKey, TValue>(map: MutableMap<TKey, TValue>): Iterator<TValue>
279
- {
280
- return Map.iterateValues(map);
281
- }
282
-
283
- public contains(value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
284
- {
285
- return MutableMap.contains(this, value, equalFunctions);
286
- }
287
-
288
- public static contains<TKey,TValue>(map: MutableMap<TKey,TValue>, value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
289
- {
290
- return Map.contains(map, value, equalFunctions);
291
- }
292
- }
@@ -1,18 +0,0 @@
1
- import { HttpClient } from "./httpClient";
2
- import { HttpServer } from "./httpServer";
3
-
4
- /**
5
- * An object that provides access to the network.
6
- */
7
- export abstract class Network
8
- {
9
- /**
10
- * Create a new {@link HttpServer} that is connected to this {@link Network}.
11
- */
12
- public abstract createHttpServer(): HttpServer;
13
-
14
- /**
15
- * Create a new {@link HttpClient} that is connected to this {@link Network}.
16
- */
17
- public abstract createHttpClient(): HttpClient;
18
- }
package/sources/node.ts DELETED
@@ -1,37 +0,0 @@
1
- import { Iterator } from "./iterator";
2
- import { PreCondition } from "./preCondition";
3
- import { Set } from "./set";
4
-
5
- export class Node<T>
6
- {
7
- private readonly value: T;
8
- private connectedNodes: Set<Node<T>>;
9
-
10
- private constructor(value: T)
11
- {
12
- this.value = value;
13
- this.connectedNodes = Set.create();
14
- }
15
-
16
- public static create<T>(value: T): Node<T>
17
- {
18
- return new Node<T>(value);
19
- }
20
-
21
- public getValue(): T
22
- {
23
- return this.value;
24
- }
25
-
26
- public iterateConnectedNodes(): Iterator<Node<T>>
27
- {
28
- return this.connectedNodes.iterate();
29
- }
30
-
31
- public addConnectedNode(node: Node<T>): void
32
- {
33
- PreCondition.assertNotUndefinedAndNotNull(node, "node");
34
-
35
- this.connectedNodes.add(node);
36
- }
37
- }
@@ -1,42 +0,0 @@
1
- import { PromiseAsyncResult } from "./promiseAsyncResult";
2
- import { CharacterWriteStream } from "./characterWriteStream";
3
- import { PreCondition } from "./preCondition";
4
-
5
- export class NodeJSCharacterWriteStream extends CharacterWriteStream
6
- {
7
- private readonly nodeJSWriteStream: NodeJS.WriteStream;
8
-
9
- private constructor(nodeJSWriteStream: NodeJS.WriteStream)
10
- {
11
- PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
12
-
13
- super();
14
-
15
- this.nodeJSWriteStream = nodeJSWriteStream;
16
- }
17
-
18
- public static create(nodeJSWriteStream: NodeJS.WriteStream): NodeJSCharacterWriteStream
19
- {
20
- return new NodeJSCharacterWriteStream(nodeJSWriteStream);
21
- }
22
-
23
- public writeString(text: string): PromiseAsyncResult<number>
24
- {
25
- PreCondition.assertNotUndefinedAndNotNull(text, "text");
26
-
27
- return PromiseAsyncResult.create(new Promise<number>((resolve, reject) =>
28
- {
29
- this.nodeJSWriteStream.write(text, (error?: Error | null) =>
30
- {
31
- if (error)
32
- {
33
- reject(error);
34
- }
35
- else
36
- {
37
- resolve(text.length);
38
- }
39
- });
40
- }));
41
- }
42
- }
@@ -1,132 +0,0 @@
1
- import { HttpIncomingRequest } from "./httpIncomingRequest";
2
- import * as http from "http";
3
- import { PreCondition } from "./preCondition";
4
- import { HttpHeader } from "./httpHeader";
5
- import { HttpHeaders } from "./httpHeaders";
6
- import { HttpMethod, parseHttpMethod } from "./httpMethod";
7
- import { NotFoundError } from "./notFoundError";
8
- import { isArray } from "./types";
9
- import { escapeAndQuote } from "./strings";
10
- import { SyncResult } from "./syncResult";
11
- import { AsyncResult } from "./asyncResult";
12
-
13
- export class NodeJSHttpIncomingRequest extends HttpIncomingRequest
14
- {
15
- private readonly request: http.IncomingMessage;
16
-
17
- private constructor(request: http.IncomingMessage)
18
- {
19
- PreCondition.assertNotUndefinedAndNotNull(request, "request");
20
-
21
- super();
22
-
23
- this.request = request;
24
- }
25
-
26
- public static create(request: http.IncomingMessage): NodeJSHttpIncomingRequest
27
- {
28
- return new NodeJSHttpIncomingRequest(request);
29
- }
30
-
31
- public getMethod(): HttpMethod
32
- {
33
- return parseHttpMethod(this.request.method!).await();
34
- }
35
-
36
- public getHost(): SyncResult<string>
37
- {
38
- return SyncResult.value(process.env.HOST ?? "localhost");
39
- }
40
-
41
- public getURLPath(): string
42
- {
43
- const url: URL = new URL(this.request.url!);
44
- return url.pathname;
45
- }
46
-
47
- private static toHttpHeader(header: [string, string | string[] | undefined]): HttpHeader
48
- {
49
- const headerName: string = header[0];
50
- const headerValue: string = this.toHttpHeaderValue(header[1]);
51
- return HttpHeader.create(headerName, headerValue);
52
- }
53
-
54
- private static toHttpHeaderValue(headerValue: string | string[] | undefined): string
55
- {
56
- let result: string | string[] | undefined = headerValue;
57
- if (result === undefined)
58
- {
59
- result = "";
60
- }
61
- else if (isArray(result))
62
- {
63
- result = result.join(",");
64
- }
65
- return result;
66
- }
67
-
68
- public getHeaders(): SyncResult<HttpHeaders>
69
- {
70
- return SyncResult.value(HttpHeaders.create(Object.entries(this.request.headers).map(NodeJSHttpIncomingRequest.toHttpHeader)));
71
- }
72
-
73
- public getHeader(headerName: string): SyncResult<HttpHeader>
74
- {
75
- PreCondition.assertNotEmpty(headerName, "headerName");
76
-
77
- return SyncResult.create(() =>
78
- {
79
- let result: HttpHeader | undefined;
80
-
81
- const lowerHeaderName: string = headerName.toLowerCase();
82
- for (const header of Object.entries(this.request.headers))
83
- {
84
- if (header[0].toLowerCase() === lowerHeaderName)
85
- {
86
- result = HttpHeader.create(header[0], NodeJSHttpIncomingRequest.toHttpHeaderValue(header[1]));
87
- break;
88
- }
89
- }
90
- if (result === undefined)
91
- {
92
- throw new NotFoundError(`No header with the name ${escapeAndQuote(headerName)} found.`);
93
- }
94
-
95
- return result;
96
- });
97
- }
98
-
99
- public getHeaderValue(headerName: string): SyncResult<string>
100
- {
101
- PreCondition.assertNotEmpty(headerName, "headerName");
102
-
103
- return SyncResult.create(() =>
104
- {
105
- let result: string | undefined;
106
-
107
- const lowerHeaderName: string = headerName.toLowerCase();
108
- for (const header of Object.entries(this.request.headers))
109
- {
110
- if (header[0].toLowerCase() === lowerHeaderName)
111
- {
112
- result = NodeJSHttpIncomingRequest.toHttpHeaderValue(header[1]);
113
- break;
114
- }
115
- }
116
- if (result === undefined)
117
- {
118
- throw new NotFoundError(`No header with the name ${escapeAndQuote(headerName)} found.`);
119
- }
120
-
121
- return result;
122
- });
123
- }
124
-
125
- public getBody(): SyncResult<string>
126
- {
127
- return SyncResult.create(() =>
128
- {
129
- throw new NotFoundError("Could not read the body from the incoming HTTP request.");
130
- });
131
- }
132
- }
@@ -1,134 +0,0 @@
1
- import * as http from "http";
2
-
3
- import { HttpServer } from "./httpServer";
4
- import { HttpIncomingRequest } from "./httpIncomingRequest";
5
- import { HttpOutgoingResponse } from "./httpOutgoingResponse";
6
- import { PreCondition } from "./preCondition";
7
- import { HttpHeaders } from "./httpHeaders";
8
- import { PromiseAsyncResult } from "./promiseAsyncResult";
9
- import { AsyncResult } from "./asyncResult";
10
-
11
- /**
12
- * A {@link HttpServer} implementation that uses the Node.js HTTP module.
13
- */
14
- export class NodeJSHttpServer extends HttpServer
15
- {
16
- private httpServer: http.Server | undefined;
17
- private disposed: boolean;
18
-
19
- private constructor()
20
- {
21
- super();
22
-
23
- this.disposed = false;
24
- }
25
-
26
- public static create(): NodeJSHttpServer
27
- {
28
- return new NodeJSHttpServer();
29
- }
30
-
31
- public dispose(): PromiseAsyncResult<boolean>
32
- {
33
- return PromiseAsyncResult.create(new Promise<boolean>((resolve, reject) =>
34
- {
35
- if (this.disposed)
36
- {
37
- resolve(false);
38
- }
39
- else if (!this.httpServer)
40
- {
41
- this.disposed = true;
42
- resolve(true);
43
- }
44
- else
45
- {
46
- this.httpServer.close((error?: Error) =>
47
- {
48
- if (error)
49
- {
50
- reject(error);
51
- }
52
- else
53
- {
54
- this.disposed = true;
55
- this.httpServer = undefined;
56
- resolve(true);
57
- }
58
- });
59
- }
60
- }));
61
- }
62
-
63
- public isDisposed(): boolean
64
- {
65
- return this.disposed;
66
- }
67
-
68
- public isStarted(): boolean
69
- {
70
- return !!this.httpServer;
71
- }
72
-
73
- public addRequestHandler(requestPath: string, handler: (request: HttpIncomingRequest, response: HttpOutgoingResponse) => AsyncResult<void>): void
74
- {
75
- throw new Error("Method not implemented.");
76
- }
77
-
78
- public setDefaultRequestHandler(handler: (request: HttpIncomingRequest, response: HttpOutgoingResponse) => AsyncResult<void>): void
79
- {
80
- throw new Error("Method not implemented.");
81
- }
82
-
83
- public start(portNumber: number): PromiseAsyncResult<void>
84
- {
85
- PreCondition.assertGreaterThanOrEqualTo(portNumber, 1, "portNumber");
86
- PreCondition.assertFalse(this.isDisposed(), "this.isDisposed()");
87
- PreCondition.assertUndefined(this.httpServer, "this.httpServer");
88
-
89
- return PromiseAsyncResult.create(new Promise<void>((resolve, reject) =>
90
- {
91
- if (this.httpServer)
92
- {
93
- reject(new Error("Can't run a HttpServer multiple times."));
94
- }
95
- else
96
- {
97
- this.httpServer = http.createServer();
98
-
99
- this.httpServer.on("request", (request: http.IncomingMessage, response: http.ServerResponse<http.IncomingMessage> & { req: http.IncomingMessage }) =>
100
- {
101
- // const httpRequest: HttpIncomingRequest = NodeJSHttpIncomingRequest.create(request);
102
- const httpResponse: HttpOutgoingResponse = HttpOutgoingResponse.create()
103
- .setStatusCode(200)
104
- .setHeader("Content-Type", "text/plain")
105
- .setBody("Hello world!");
106
-
107
- const statusCode: number = httpResponse.getStatusCode();
108
- const headers: HttpHeaders = httpResponse.getHeaders();
109
-
110
- const responseHeaders: http.OutgoingHttpHeaders = {};
111
- for (const header of headers)
112
- {
113
- responseHeaders[header.getName()] = header.getValue();
114
- }
115
-
116
- response.writeHead(statusCode, responseHeaders);
117
- response.end(httpResponse.getBody());
118
- });
119
-
120
- this.httpServer.on("close", () =>
121
- {
122
- resolve();
123
- });
124
-
125
- this.httpServer.on("error", (error: Error) =>
126
- {
127
- reject(error);
128
- });
129
-
130
- this.httpServer.listen(portNumber);
131
- }
132
- }));
133
- }
134
- }
@@ -1,12 +0,0 @@
1
- import { join } from "./strings";
2
-
3
- /**
4
- * An {@link Error} that is thrown when a value is not found.
5
- */
6
- export class NotFoundError extends Error
7
- {
8
- public constructor(...message: string[])
9
- {
10
- super(join("\n", message));
11
- }
12
- }