@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.
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 +11 -2
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -36
  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,216 +0,0 @@
1
- import { EqualFunctions } from "./equalFunctions";
2
- import { HttpHeader } from "./httpHeader";
3
- import { Iterable } from "./iterable";
4
- import { Iterator } from "./iterator";
5
- import { JavascriptIterable, JavascriptIterator } from "./javascript";
6
- import { MutableHttpHeaders } from "./mutableHttpHeaders";
7
- import { NotFoundError } from "./notFoundError";
8
- import { AsyncResult } from "./asyncResult";
9
- import { SyncResult } from "./syncResult";
10
- import { ToStringFunctions } from "./toStringFunctions";
11
- import { Type } from "./types";
12
-
13
- /**
14
- * A collection of {@link HttpHeader}s.
15
- */
16
- export abstract class HttpHeaders implements Iterable<HttpHeader>
17
- {
18
- public static readonly contentTypeHeaderName: string = "Content-Type";
19
-
20
- public static create(headers?: JavascriptIterable<HttpHeader>): MutableHttpHeaders
21
- {
22
- return MutableHttpHeaders.create(headers);
23
- }
24
-
25
- /**
26
- * Get the header with the provided name.
27
- * @param headerName The name of the header.
28
- */
29
- public abstract get(headerName: string): SyncResult<HttpHeader>;
30
-
31
- /**
32
- * Get the value of the header with the provided name.
33
- * @param headerName The name of the header.
34
- */
35
- public abstract getValue(headerName: string): SyncResult<string>;
36
-
37
- public getContentType(): AsyncResult<HttpHeader>
38
- {
39
- return HttpHeaders.getContentType(this);
40
- }
41
-
42
- public static getContentType(headers: HttpHeaders): AsyncResult<HttpHeader>
43
- {
44
- return headers.get(HttpHeaders.contentTypeHeaderName);
45
- }
46
-
47
- public getContentTypeValue(): AsyncResult<string>
48
- {
49
- return HttpHeaders.getContentTypeValue(this);
50
- }
51
-
52
- public static getContentTypeValue(headers: HttpHeaders): AsyncResult<string>
53
- {
54
- return headers.getValue(HttpHeaders.contentTypeHeaderName);
55
- }
56
-
57
- /**
58
- * Get an {@link Iterator} that can be used to iterate through the {@link HttpHeader}s in this
59
- * collection.
60
- */
61
- public abstract iterate(): Iterator<HttpHeader>;
62
-
63
- /**
64
- * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
65
- */
66
- public toArray(): SyncResult<HttpHeader[]>
67
- {
68
- return HttpHeaders.toArray(this);
69
- }
70
-
71
- public static toArray(headers: HttpHeaders): SyncResult<HttpHeader[]>
72
- {
73
- return Iterable.toArray(headers);
74
- }
75
-
76
- public any(): SyncResult<boolean>
77
- {
78
- return HttpHeaders.any(this);
79
- }
80
-
81
- public static any(headers: HttpHeaders): SyncResult<boolean>
82
- {
83
- return Iterable.any(headers);
84
- }
85
-
86
- public getCount(): SyncResult<number>
87
- {
88
- return HttpHeaders.getCount(this);
89
- }
90
-
91
- public static getCount(headers: HttpHeaders): SyncResult<number>
92
- {
93
- return Iterable.getCount(headers);
94
- }
95
-
96
- public equals(right: JavascriptIterable<HttpHeader>, equalFunctions?: EqualFunctions): SyncResult<boolean>
97
- {
98
- return HttpHeaders.equals(this, right, equalFunctions);
99
- }
100
-
101
- public static equals(headers: HttpHeaders, right: JavascriptIterable<HttpHeader>, equalFunctions?: EqualFunctions): SyncResult<boolean>
102
- {
103
- return Iterable.equals(headers, right, equalFunctions);
104
- }
105
-
106
- public toString(toStringFunctions?: ToStringFunctions): string
107
- {
108
- return HttpHeaders.toString(this, toStringFunctions);
109
- }
110
-
111
- public static toString(headers: HttpHeaders, toStringFunctions?: ToStringFunctions): string
112
- {
113
- return Iterable.toString(headers, toStringFunctions);
114
- }
115
-
116
- public concatenate(...toConcatenate: JavascriptIterable<HttpHeader>[]): Iterable<HttpHeader>
117
- {
118
- return HttpHeaders.concatenate(this, ...toConcatenate);
119
- }
120
-
121
- public static concatenate(headers: HttpHeaders, ...toConcatenate: JavascriptIterable<HttpHeader>[]): Iterable<HttpHeader>
122
- {
123
- return Iterable.concatenate(headers, ...toConcatenate);
124
- }
125
-
126
- public map<TOutput>(mapping: (value: HttpHeader) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
127
- {
128
- return HttpHeaders.map(this, mapping);
129
- }
130
-
131
- public static map<TOutput>(headers: HttpHeaders, mapping: (value: HttpHeader) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
132
- {
133
- return Iterable.map(headers, mapping);
134
- }
135
-
136
- public flatMap<TOutput>(mapping: (value: HttpHeader) => JavascriptIterable<TOutput>): Iterable<TOutput>
137
- {
138
- return HttpHeaders.flatMap(this, mapping);
139
- }
140
-
141
- public static flatMap<TOutput>(headers: HttpHeaders, mapping: (value: HttpHeader) => JavascriptIterable<TOutput>): Iterable<TOutput>
142
- {
143
- return Iterable.flatMap(headers, mapping);
144
- }
145
-
146
- public where(condition: (value: HttpHeader) => boolean): Iterable<HttpHeader>
147
- {
148
- return HttpHeaders.where(this, condition);
149
- }
150
-
151
- public static where(headers: HttpHeaders, condition: (value: HttpHeader) => (boolean | SyncResult<boolean>)): Iterable<HttpHeader>
152
- {
153
- return Iterable.where(headers, condition);
154
- }
155
-
156
- public instanceOf<TOutput extends HttpHeader>(typeOrTypeCheck: Type<TOutput> | ((value: HttpHeader) => value is TOutput)): Iterable<TOutput>
157
- {
158
- return HttpHeaders.instanceOf(this, typeOrTypeCheck);
159
- }
160
-
161
- public static instanceOf<TOutput extends HttpHeader>(headers: HttpHeaders, typeOrTypeCheck: Type<TOutput> | ((value: HttpHeader) => value is TOutput)): Iterable<TOutput>
162
- {
163
- return Iterable.instanceOf(headers, typeOrTypeCheck);
164
- }
165
-
166
- public first(condition?: (value: HttpHeader) => (boolean | SyncResult<boolean>)): SyncResult<HttpHeader>
167
- {
168
- return HttpHeaders.first(this, condition);
169
- }
170
-
171
- public static first(headers: HttpHeaders, condition?: (value: HttpHeader) => (boolean | SyncResult<boolean>)): SyncResult<HttpHeader>
172
- {
173
- return Iterable.first(headers, condition);
174
- }
175
-
176
- public last(condition?: (value: HttpHeader) => (boolean | SyncResult<boolean>)): SyncResult<HttpHeader>
177
- {
178
- return HttpHeaders.last(this, condition);
179
- }
180
-
181
- public static last(headers: HttpHeaders, condition?: (value: HttpHeader) => (boolean | SyncResult<boolean>)): SyncResult<HttpHeader>
182
- {
183
- return Iterable.last(headers, condition);
184
- }
185
-
186
- public [Symbol.iterator](): JavascriptIterator<HttpHeader>
187
- {
188
- return HttpHeaders[Symbol.iterator](this);
189
- }
190
-
191
- public static [Symbol.iterator](headers: HttpHeaders): JavascriptIterator<HttpHeader>
192
- {
193
- return Iterable[Symbol.iterator](headers);
194
- }
195
-
196
- public contains(value: HttpHeader, equalFunctions?: EqualFunctions): SyncResult<boolean>
197
- {
198
- return HttpHeaders.contains(this, value, equalFunctions);
199
- }
200
-
201
- public static contains(headers: HttpHeaders, value: HttpHeader, equalFunctions?: EqualFunctions): SyncResult<boolean>
202
- {
203
- return SyncResult.create(() =>
204
- {
205
- if (!equalFunctions)
206
- {
207
- equalFunctions = EqualFunctions.create();
208
- }
209
-
210
- return headers.getValue(value.getName())
211
- .then((headerValue: string) => equalFunctions!.areEqual(headerValue, value.getValue()).await())
212
- .catch(NotFoundError, () => false)
213
- .await();
214
- });
215
- }
216
- }
@@ -1,30 +0,0 @@
1
- import { HttpHeader } from "./httpHeader";
2
- import { HttpHeaders } from "./httpHeaders";
3
- import { HttpMethod } from "./httpMethod";
4
- import { AsyncResult } from "./asyncResult";
5
-
6
- /**
7
- * A HTTP request that is received by a {@link HttpServer}.
8
- */
9
- export abstract class HttpIncomingRequest
10
- {
11
- /**
12
- * Get the {@link HttpMethod} of the request.
13
- */
14
- public abstract getMethod(): HttpMethod;
15
-
16
- public abstract getHost(): AsyncResult<string>;
17
-
18
- /**
19
- * Get the path component of the requested URL.
20
- */
21
- public abstract getURLPath(): string;
22
-
23
- public abstract getHeaders(): AsyncResult<HttpHeaders>;
24
-
25
- public abstract getHeader(headerName: string): AsyncResult<HttpHeader>;
26
-
27
- public abstract getHeaderValue(headerName: string): AsyncResult<string>;
28
-
29
- public abstract getBody(): AsyncResult<string>;
30
- }
@@ -1,19 +0,0 @@
1
- import { HttpHeader } from "./httpHeader";
2
- import { HttpHeaders } from "./httpHeaders";
3
- import { AsyncResult } from "./asyncResult";
4
-
5
- /**
6
- * The response from a {@link HttpClient}'s sendRequest() method.
7
- */
8
- export abstract class HttpIncomingResponse
9
- {
10
- public abstract getStatusCode(): number;
11
-
12
- public abstract getHeaders(): AsyncResult<HttpHeaders>;
13
-
14
- public abstract getHeader(headerName: string): AsyncResult<HttpHeader>;
15
-
16
- public abstract getHeaderValue(headerName: string): AsyncResult<string>;
17
-
18
- public abstract getBody(): AsyncResult<string>;
19
- }
@@ -1,164 +0,0 @@
1
- import { NotFoundError } from "./notFoundError";
2
- import { PreCondition } from "./preCondition";
3
- import { SyncResult } from "./syncResult";
4
-
5
- export enum HttpMethod
6
- {
7
- /**
8
- * The GET method requests a representation of the specified resource. Requests using GET should
9
- * only retrieve data and should not contain a request content.
10
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/GET
11
- */
12
- GET,
13
- /**
14
- * The HEAD method asks for a response identical to a GET request, but without a response body.
15
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/HEAD
16
- */
17
- HEAD,
18
- /**
19
- * The POST method submits an entity to the specified resource, often causing a change in state
20
- * or side effects on the server.
21
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST
22
- */
23
- POST,
24
- /**
25
- * The PUT method replaces all current representations of the target resource with the request
26
- * content.
27
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/PUT
28
- */
29
- PUT,
30
- /**
31
- * The DELETE method deletes the specified resource.
32
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/DELETE
33
- */
34
- DELETE,
35
- /**
36
- * The CONNECT method establishes a tunnel to the server identified by the target resource.
37
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/CONNECT
38
- */
39
- CONNECT,
40
- /**
41
- * The OPTIONS method describes the communication options for the target resource.
42
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/OPTIONS
43
- */
44
- OPTIONS,
45
- /**
46
- * The TRACE method performs a message loop-back test along the path to the target resource.
47
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/TRACE
48
- */
49
- TRACE,
50
- /**
51
- * The PATCH method applies partial modifications to a resource.
52
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/PATCH
53
- */
54
- PATCH,
55
- }
56
-
57
- /**
58
- * Parse a {@link HttpMethod} from the provided text.
59
- * @param text The text to parse.
60
- */
61
- export function parseHttpMethod(text: string): SyncResult<HttpMethod>
62
- {
63
- return SyncResult.create(() =>
64
- {
65
- let result: HttpMethod;
66
-
67
- switch (text.toUpperCase())
68
- {
69
- case "GET":
70
- result = HttpMethod.GET;
71
- break;
72
-
73
- case "HEAD":
74
- result = HttpMethod.HEAD;
75
- break;
76
-
77
- case "POST":
78
- result = HttpMethod.POST;
79
- break;
80
-
81
- case "PUT":
82
- result = HttpMethod.PUT;
83
- break;
84
-
85
- case "DELETE":
86
- result = HttpMethod.DELETE;
87
- break;
88
-
89
- case "CONNECT":
90
- result = HttpMethod.CONNECT;
91
- break;
92
-
93
- case "OPTIONS":
94
- result = HttpMethod.OPTIONS;
95
- break;
96
-
97
- case "TRACE":
98
- result = HttpMethod.TRACE;
99
- break;
100
-
101
- case "PATCH":
102
- result = HttpMethod.PATCH;
103
- break;
104
-
105
- default:
106
- throw new NotFoundError(`No HttpMethod exists for the text "${text}".`);
107
- }
108
-
109
- return result;
110
- });
111
- }
112
-
113
- /**
114
- * Get the string representation of the provided {@link HttpMethod}.
115
- * @param httpMethod The {@link HttpMethod} to get the string representation of.
116
- */
117
- export function httpMethodToString(httpMethod: HttpMethod): string
118
- {
119
- PreCondition.assertNotUndefinedAndNotNull(httpMethod, "httpMethod");
120
-
121
- let result: string;
122
- switch (httpMethod)
123
- {
124
- case HttpMethod.GET:
125
- result = "GET";
126
- break;
127
-
128
- case HttpMethod.HEAD:
129
- result = "HEAD";
130
- break;
131
-
132
- case HttpMethod.POST:
133
- result = "POST";
134
- break;
135
-
136
- case HttpMethod.PUT:
137
- result = "PUT";
138
- break;
139
-
140
- case HttpMethod.DELETE:
141
- result = "DELETE";
142
- break;
143
-
144
- case HttpMethod.CONNECT:
145
- result = "CONNECT";
146
- break;
147
-
148
- case HttpMethod.OPTIONS:
149
- result = "OPTIONS";
150
- break;
151
-
152
- case HttpMethod.TRACE:
153
- result = "TRACE";
154
- break;
155
-
156
- case HttpMethod.PATCH:
157
- result = "PATCH";
158
- break;
159
-
160
- default:
161
- throw new NotFoundError(`Unrecognized HttpMethod: ${httpMethod}`);
162
- }
163
- return result;
164
- }
@@ -1,119 +0,0 @@
1
- import { HttpHeader } from "./httpHeader";
2
- import { HttpHeaders } from "./httpHeaders";
3
- import { HttpMethod } from "./httpMethod";
4
- import { MutableHttpHeaders } from "./mutableHttpHeaders";
5
- import { PreCondition } from "./preCondition";
6
- import { SyncResult } from "./syncResult";
7
-
8
- /**
9
- * A HTTP request that is sent out by a {@link HttpClient}.
10
- */
11
- export class HttpOutgoingRequest
12
- {
13
- private method: HttpMethod;
14
- private url: string;
15
- private readonly headers: MutableHttpHeaders;
16
- private body: string;
17
-
18
- private constructor(method: HttpMethod, url: string)
19
- {
20
- PreCondition.assertNotUndefinedAndNotNull(method, "method");
21
- PreCondition.assertNotEmpty(url, "url");
22
-
23
- this.method = method;
24
- this.url = url;
25
- this.headers = HttpHeaders.create();
26
- this.body = "";
27
- }
28
-
29
- public static create(method: HttpMethod, url: string): HttpOutgoingRequest
30
- {
31
- return new HttpOutgoingRequest(method, url);
32
- }
33
-
34
- /**
35
- * Create a new {@link HttpOutgoingRequest} with a GET {@link HttpMethod}.
36
- * @param url The target URL for the {@link HttpOutgoingRequest}.
37
- */
38
- public static get(url: string): HttpOutgoingRequest
39
- {
40
- return HttpOutgoingRequest.create(HttpMethod.GET, url);
41
- }
42
-
43
- /**
44
- * Get the {@link HttpMethod} for this {@link HttpOutgoingRequest}.
45
- */
46
- public getMethod(): HttpMethod
47
- {
48
- return this.method;
49
- }
50
-
51
- /**
52
- * Set the {@link HttpMethod} for this {@link HttpOutgoingRequest}.
53
- * @param method The {@link HttpMethod} for this {@link HttpOutgoingRequest}.
54
- */
55
- public setMethod(method: HttpMethod): this
56
- {
57
- PreCondition.assertNotUndefinedAndNotNull(method, "method");
58
-
59
- this.method = method;
60
-
61
- return this;
62
- }
63
-
64
- /**
65
- * Get this {@link HttpOutgoingRequest}'s target URL.
66
- */
67
- public getURL(): string
68
- {
69
- return this.url;
70
- }
71
-
72
- /**
73
- * Set the URL that this request will be sent to.
74
- * @param url The URL to send this request to.
75
- */
76
- public setURL(url: string): this
77
- {
78
- PreCondition.assertNotEmpty(url, "url");
79
-
80
- this.url = url;
81
-
82
- return this;
83
- }
84
-
85
- /**
86
- * Get the {@link HttpHeaders} that will be sent.
87
- */
88
- public getHeaders(): HttpHeaders
89
- {
90
- return this.headers;
91
- }
92
-
93
- public getHeader(headerName: string): SyncResult<HttpHeader>
94
- {
95
- return this.headers.get(headerName);
96
- }
97
-
98
- public getHeaderValue(headerName: string): SyncResult<string>
99
- {
100
- return this.headers.getValue(headerName);
101
- }
102
-
103
- /**
104
- * Get the body that will be sent.
105
- */
106
- public getBody(): string
107
- {
108
- return this.body;
109
- }
110
-
111
- public setBody(body: string): this
112
- {
113
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
114
-
115
- this.body = body;
116
-
117
- return this;
118
- }
119
- }
@@ -1,113 +0,0 @@
1
- import { HttpHeader } from "./httpHeader";
2
- import { HttpHeaders } from "./httpHeaders";
3
- import { MutableHttpHeaders } from "./mutableHttpHeaders";
4
- import { PreCondition } from "./preCondition";
5
- import { SyncResult } from "./syncResult";
6
-
7
- /**
8
- * A HTTP response that is sent out by an {@link HttpServer}.
9
- */
10
- export class HttpOutgoingResponse
11
- {
12
- private statusCode: number;
13
- private readonly headers: MutableHttpHeaders;
14
- private body: string;
15
-
16
- private constructor()
17
- {
18
- this.statusCode = 200;
19
- this.headers = MutableHttpHeaders.create();
20
- this.body = "";
21
- }
22
-
23
- public static create(): HttpOutgoingResponse
24
- {
25
- return new HttpOutgoingResponse();
26
- }
27
-
28
- /**
29
- * Get the status code of this {@link HttpOutgoingResponse}.
30
- */
31
- public getStatusCode(): number
32
- {
33
- return this.statusCode;
34
- }
35
-
36
- /**
37
- * Set the status code of this {@link HttpOutgoingResponse}.
38
- * @param statusCode The status code of this {@link HttpOutgoingResponse}.
39
- */
40
- public setStatusCode(statusCode: number): this
41
- {
42
- PreCondition.assertBetween(100, statusCode, 599, "statusCode");
43
-
44
- this.statusCode = statusCode;
45
-
46
- return this;
47
- }
48
-
49
- public getHeaders(): HttpHeaders
50
- {
51
- return this.headers;
52
- }
53
-
54
- /**
55
- * Get the HTTP header with the provided name or return a {@link NotFoundError} if the header
56
- * doesn't exist.
57
- * @param headerName The name of the header to get.
58
- */
59
- public getHeader(headerName: string): SyncResult<HttpHeader>
60
- {
61
- return this.headers.get(headerName);
62
- }
63
-
64
- /**
65
- * Get the value of the header with the provided name or return a {@link NotFoundError} if the
66
- * header doesn't exist.
67
- * @param headerName The name of the header value to get.
68
- */
69
- public getHeaderValue(headerName: string): SyncResult<string>
70
- {
71
- return this.headers.getValue(headerName);
72
- }
73
-
74
- /**
75
- * Set the HTTP header in this {@link HttpOutgoingResponse}.
76
- * @param headerName The name of the HTTP header.
77
- * @param headerValue The value of the HTTP header.
78
- */
79
- public setHeader(headerName: string, headerValue: string): this
80
- {
81
- this.headers.set(headerName, headerValue);
82
-
83
- return this;
84
- }
85
-
86
- public setContentTypeHeader(contentType: string): this
87
- {
88
- this.headers.setContentType(contentType);
89
-
90
- return this;
91
- }
92
-
93
- /**
94
- * Get the body of this {@link HttpOutgoingResponse}.
95
- */
96
- public getBody(): string
97
- {
98
- return this.body;
99
- }
100
-
101
- /**
102
- * Set the body of this {@link HttpOutgoingResponse}.
103
- * @param body The body for this {@link HttpOutgoingResponse}.
104
- */
105
- public setBody(body: string): this
106
- {
107
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
108
-
109
- this.body = body;
110
-
111
- return this;
112
- }
113
- }
@@ -1,34 +0,0 @@
1
- import { Disposable } from "./disposable";
2
- import { HttpIncomingRequest } from "./httpIncomingRequest";
3
- import { HttpOutgoingResponse } from "./httpOutgoingResponse";
4
- import { AsyncResult } from "./asyncResult";
5
-
6
- export abstract class HttpServer implements Disposable
7
- {
8
- public abstract dispose(): AsyncResult<boolean>;
9
-
10
- public abstract isDisposed(): boolean;
11
-
12
- /**
13
- * Add the provided request handler so it will be invoked when a request is received for the
14
- * provided path.
15
- * @param requestPath The path that will cause the provided handler to be invoked.
16
- * @param handler The function that will be invoked when the
17
- */
18
- public abstract addRequestHandler(requestPath: string, handler: (request: HttpIncomingRequest, response: HttpOutgoingResponse) => AsyncResult<void>): void;
19
-
20
- /**
21
- * Set the default request handler that will be invoked when no other request handlers match an
22
- * {@link HttpIncomingRequest}.
23
- * @param handler The handler that will be invoked when no other request handlers match an
24
- * {@link HttpIncomingRequest}.
25
- */
26
- public abstract setDefaultRequestHandler(handler: (request: HttpIncomingRequest, response: HttpOutgoingResponse) => AsyncResult<void>): void;
27
-
28
- /**
29
- * Start listening for incoming connections on the provided port number. The returned
30
- * {@link AsyncResult} will complete when the server is disposed.
31
- * @param portNumber The port number to start listening on.
32
- */
33
- public abstract start(portNumber: number): AsyncResult<void>;
34
- }