@everyonesoftware/common 2.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/outputs/chunk-AY3YWKOM.js +7741 -0
- package/outputs/chunk-AY3YWKOM.js.map +1 -0
- package/outputs/sources.cjs +9007 -0
- package/outputs/sources.cjs.map +1 -0
- package/outputs/sources.d.cts +4082 -0
- package/outputs/sources.d.ts +4082 -0
- package/outputs/sources.js +1370 -0
- package/outputs/sources.js.map +1 -0
- package/outputs/tests.cjs +17208 -0
- package/outputs/tests.cjs.map +1 -0
- package/outputs/tests.d.cts +3 -0
- package/outputs/tests.d.ts +3 -0
- package/outputs/tests.js +9798 -0
- package/outputs/tests.js.map +1 -0
- package/package.json +11 -2
- package/.c8rc.json +0 -12
- package/.github/workflows/publish.yml +0 -36
- package/.mocharc.json +0 -9
- package/sources/assertMessageParameters.ts +0 -22
- package/sources/asyncIterator.ts +0 -437
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
- package/sources/asyncResult.ts +0 -95
- package/sources/basicDisposable.ts +0 -57
- package/sources/byteList.ts +0 -202
- package/sources/byteListStream.ts +0 -121
- package/sources/byteReadStream.ts +0 -24
- package/sources/byteWriteStream.ts +0 -16
- package/sources/bytes.ts +0 -25
- package/sources/characterList.ts +0 -195
- package/sources/characterListStream.ts +0 -151
- package/sources/characterReadStream.ts +0 -81
- package/sources/characterReadStreamIterator.ts +0 -128
- package/sources/characterWriteStream.ts +0 -45
- package/sources/commandLineParameter.ts +0 -45
- package/sources/commandLineParameters.ts +0 -21
- package/sources/comparable.ts +0 -144
- package/sources/comparer.ts +0 -133
- package/sources/comparison.ts +0 -20
- package/sources/concatenateIterable.ts +0 -119
- package/sources/concatenateIterator.ts +0 -165
- package/sources/condition.ts +0 -329
- package/sources/currentProcess.ts +0 -158
- package/sources/dateTime.ts +0 -130
- package/sources/depthFirstSearch.ts +0 -230
- package/sources/disposable.ts +0 -31
- package/sources/emptyError.ts +0 -10
- package/sources/english.ts +0 -45
- package/sources/equalFunctions.ts +0 -123
- package/sources/fetchHttpClient.ts +0 -89
- package/sources/fetchHttpResponse.ts +0 -106
- package/sources/flatMapIterable.ts +0 -104
- package/sources/flatMapIterator.ts +0 -152
- package/sources/generator.ts +0 -251
- package/sources/httpClient.ts +0 -36
- package/sources/httpHeader.ts +0 -37
- package/sources/httpHeaders.ts +0 -216
- package/sources/httpIncomingRequest.ts +0 -30
- package/sources/httpIncomingResponse.ts +0 -19
- package/sources/httpMethod.ts +0 -164
- package/sources/httpOutgoingRequest.ts +0 -119
- package/sources/httpOutgoingResponse.ts +0 -113
- package/sources/httpServer.ts +0 -34
- package/sources/inMemoryCharacterWriteStream.ts +0 -78
- package/sources/index.ts +0 -101
- package/sources/iterable.ts +0 -345
- package/sources/iterator.ts +0 -481
- package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
- package/sources/javascript.ts +0 -59
- package/sources/javascriptArrayList.ts +0 -175
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
- package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
- package/sources/javascriptMapMap.ts +0 -143
- package/sources/javascriptSetSet.ts +0 -134
- package/sources/list.ts +0 -330
- package/sources/listQueue.ts +0 -62
- package/sources/listStack.ts +0 -62
- package/sources/luxonDateTime.ts +0 -109
- package/sources/map.ts +0 -302
- package/sources/mapAsyncIterator.ts +0 -141
- package/sources/mapIterable.ts +0 -105
- package/sources/mapIterator.ts +0 -145
- package/sources/mutableCondition.ts +0 -451
- package/sources/mutableHttpHeaders.ts +0 -204
- package/sources/mutableMap.ts +0 -292
- package/sources/network.ts +0 -18
- package/sources/node.ts +0 -37
- package/sources/nodeJSCharacterWriteStream.ts +0 -42
- package/sources/nodeJSHttpIncomingRequest.ts +0 -132
- package/sources/nodeJSHttpServer.ts +0 -134
- package/sources/notFoundError.ts +0 -12
- package/sources/postCondition.ts +0 -284
- package/sources/postConditionError.ts +0 -12
- package/sources/preCondition.ts +0 -284
- package/sources/preConditionError.ts +0 -12
- package/sources/promiseAsyncResult.ts +0 -174
- package/sources/property.ts +0 -63
- package/sources/queue.ts +0 -49
- package/sources/realNetwork.ts +0 -28
- package/sources/recreationDotGovClient.ts +0 -259
- package/sources/searchControl.ts +0 -42
- package/sources/set.ts +0 -244
- package/sources/skipAsyncIterator.ts +0 -145
- package/sources/skipIterator.ts +0 -155
- package/sources/stack.ts +0 -48
- package/sources/stringComparer.ts +0 -33
- package/sources/stringIterator.ts +0 -149
- package/sources/strings.ts +0 -322
- package/sources/syncResult.ts +0 -300
- package/sources/takeAsyncIterator.ts +0 -141
- package/sources/takeIterator.ts +0 -151
- package/sources/toStringFunctions.ts +0 -185
- package/sources/types.ts +0 -371
- package/sources/whereAsyncIterator.ts +0 -143
- package/sources/whereIterable.ts +0 -108
- package/sources/whereIterator.ts +0 -157
- package/sources/wonderlandTrailClient.ts +0 -1503
- package/tests/assertTest.ts +0 -113
- package/tests/assertTestTests.ts +0 -75
- package/tests/basicTestSkip.ts +0 -51
- package/tests/byteListStreamTests.ts +0 -390
- package/tests/byteListTests.ts +0 -27
- package/tests/bytesTests.ts +0 -43
- package/tests/characterListStreamTests.ts +0 -391
- package/tests/characterListTests.ts +0 -250
- package/tests/characterWriteStreamTests.ts +0 -12
- package/tests/comparerTests.ts +0 -92
- package/tests/conditionTests.ts +0 -877
- package/tests/consoleTestRunner.ts +0 -404
- package/tests/consoleTestRunnerTests.ts +0 -651
- package/tests/dateTimeTests.ts +0 -30
- package/tests/depthFirstSearchTests.ts +0 -106
- package/tests/disposableTests.ts +0 -121
- package/tests/englishTests.ts +0 -103
- package/tests/equalFunctionsTests.ts +0 -223
- package/tests/failedTest.ts +0 -43
- package/tests/fetchHttpClientTests.ts +0 -33
- package/tests/generatorTests.ts +0 -86
- package/tests/httpClientTests.ts +0 -18
- package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
- package/tests/iterableTests.ts +0 -141
- package/tests/iteratorTests.ts +0 -1086
- package/tests/javascriptMapMapTests.ts +0 -21
- package/tests/listTests.ts +0 -338
- package/tests/mapIteratorTests.ts +0 -55
- package/tests/mapTests.ts +0 -104
- package/tests/mutableConditionTests.ts +0 -273
- package/tests/mutableMapTests.ts +0 -154
- package/tests/nodeJSHttpServerTests.ts +0 -75
- package/tests/notFoundErrorTests.ts +0 -24
- package/tests/postConditionErrorTests.ts +0 -24
- package/tests/preConditionErrorTests.ts +0 -24
- package/tests/promiseAsyncResultTests.ts +0 -688
- package/tests/propertyTests.ts +0 -63
- package/tests/queueTests.ts +0 -29
- package/tests/recreationDotGovClientTests.ts +0 -191
- package/tests/setTests.ts +0 -140
- package/tests/skippedTest.ts +0 -39
- package/tests/stackTests.ts +0 -66
- package/tests/stringComparerTests.ts +0 -60
- package/tests/stringIteratorTests.ts +0 -156
- package/tests/stringsTests.ts +0 -516
- package/tests/syncResultTests.ts +0 -1251
- package/tests/test.ts +0 -228
- package/tests/testAction.ts +0 -75
- package/tests/testActionTests.ts +0 -93
- package/tests/testFailureTests.ts +0 -12
- package/tests/testRunner.ts +0 -267
- package/tests/testRunnerTests.ts +0 -895
- package/tests/testSkip.ts +0 -34
- package/tests/tests.ts +0 -103
- package/tests/toStringFunctionsTests.ts +0 -55
- package/tests/typesTests.ts +0 -257
- package/tests/whereIteratorTests.ts +0 -77
- package/tests/wonderlandTrailClientTests.ts +0 -452
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -13
package/sources/httpHeaders.ts
DELETED
|
@@ -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
|
-
}
|
package/sources/httpMethod.ts
DELETED
|
@@ -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
|
-
}
|
package/sources/httpServer.ts
DELETED
|
@@ -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
|
-
}
|