typedrest 0.5.0 → 0.6.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/README.md +41 -5
- package/endpoints/{CachingEndpoint.ts → CachingEndpoint.d.ts} +0 -1
- package/endpoints/Endpoint.d.ts +121 -0
- package/endpoints/Endpoint.js +1 -1
- package/endpoints/{EntryEndpoint.ts → EntryEndpoint.d.ts} +7 -27
- package/endpoints/generic/{CollectionEndpoint.ts → CollectionEndpoint.d.ts} +2 -5
- package/endpoints/generic/{ETagEndpointBase.ts → ETagEndpointBase.d.ts} +7 -38
- package/endpoints/generic/{ElementEndpoint.ts → ElementEndpoint.d.ts} +12 -70
- package/endpoints/generic/{GenericCollectionEndpoint.ts → GenericCollectionEndpoint.d.ts} +21 -106
- package/endpoints/generic/{IndexerEndpoint.ts → IndexerEndpoint.d.ts} +4 -11
- package/endpoints/generic/PartialResponse.d.ts +19 -0
- package/endpoints/{index.ts → index.d.ts} +1 -2
- package/endpoints/raw/{BlobEndpoint.ts → BlobEndpoint.d.ts} +9 -29
- package/endpoints/raw/{UploadEndpoint.ts → UploadEndpoint.d.ts} +4 -18
- package/endpoints/reactive/Delay.d.ts +7 -0
- package/endpoints/reactive/GenericStreamingCollectionEndpoint.d.ts +32 -0
- package/endpoints/reactive/{PollingEndpoint.ts → PollingEndpoint.d.ts} +7 -34
- package/endpoints/reactive/SseStreamingEndpoint.d.ts +50 -0
- package/endpoints/reactive/{StreamingCollectionEndpoint.ts → StreamingCollectionEndpoint.d.ts} +2 -5
- package/endpoints/reactive/{StreamingEndpoint.ts → StreamingEndpoint.d.ts} +5 -27
- package/endpoints/rpc/{ActionEndpoint.ts → ActionEndpoint.d.ts} +3 -10
- package/endpoints/rpc/{ConsumerEndpoint.ts → ConsumerEndpoint.d.ts} +3 -12
- package/endpoints/rpc/{FunctionEndpoint.ts → FunctionEndpoint.d.ts} +3 -14
- package/endpoints/rpc/{ProducerEndpoint.ts → ProducerEndpoint.d.ts} +3 -11
- package/endpoints/rpc/{RpcEndpointBase.ts → RpcEndpointBase.d.ts} +4 -12
- package/errors/DefaultErrorHandler.d.ts +21 -0
- package/errors/{Errors.ts → Errors.d.ts} +20 -21
- package/http/EntityStream.d.ts +10 -0
- package/http/FetchHttpClient.d.ts +15 -0
- package/http/FetchHttpClient.js +1 -1
- package/http/{HttpClient.ts → HttpClient.d.ts} +1 -3
- package/http/HttpContentRange.d.ts +23 -0
- package/http/{HttpHeader.ts → HttpHeader.d.ts} +1 -1
- package/http/{HttpMethod.ts → HttpMethod.d.ts} +1 -1
- package/http/{HttpStatusCode.ts → HttpStatusCode.d.ts} +1 -1
- package/http/ResponseCache.d.ts +19 -0
- package/http/RetryAfter.d.ts +6 -0
- package/http/ServerSentEvents.d.ts +50 -0
- package/links/AggregateLinkExtractor.d.ts +17 -0
- package/links/HalLinkExtractor.d.ts +13 -0
- package/links/HeaderLinkExtractor.d.ts +13 -0
- package/links/{Link.ts → Link.d.ts} +6 -2
- package/links/{LinkExtractor.ts → LinkExtractor.d.ts} +0 -1
- package/package.json +64 -14
- package/serializers/JsonSerializer.d.ts +18 -0
- package/serializers/{Serializer.ts → Serializer.d.ts} +0 -2
- package/endpoints/Endpoint.test.ts +0 -300
- package/endpoints/Endpoint.ts +0 -247
- package/endpoints/generic/CollectionEndpoint.test.ts +0 -215
- package/endpoints/generic/ElementEndpoint.test.ts +0 -262
- package/endpoints/generic/GenericCollectionEndpoint.test.ts +0 -123
- package/endpoints/generic/IndexerEndpoint.test.ts +0 -12
- package/endpoints/generic/PartialResponse.ts +0 -28
- package/endpoints/raw/BlobEndpoint.test.ts +0 -52
- package/endpoints/raw/UploadEndpoint.test.ts +0 -47
- package/endpoints/reactive/Delay.ts +0 -26
- package/endpoints/reactive/GenericStreamingCollectionEndpoint.ts +0 -73
- package/endpoints/reactive/PollingEndpoint.test.ts +0 -84
- package/endpoints/reactive/SseStreamingEndpoint.test.ts +0 -169
- package/endpoints/reactive/SseStreamingEndpoint.ts +0 -115
- package/endpoints/reactive/StreamingCollectionEndpoint.test.ts +0 -110
- package/endpoints/reactive/StreamingEndpoint.test.ts +0 -130
- package/endpoints/rpc/ActionEndpoint.test.ts +0 -36
- package/endpoints/rpc/ConsumerEndpoint.test.ts +0 -29
- package/endpoints/rpc/FunctionEndpoint.test.ts +0 -29
- package/endpoints/rpc/ProducerEndpoint.test.ts +0 -32
- package/errors/DefaultErrorHandler.ts +0 -65
- package/http/EntityStream.ts +0 -40
- package/http/FetchHttpClient.ts +0 -26
- package/http/HttpContentRange.ts +0 -41
- package/http/ResponseCache.ts +0 -25
- package/http/RetryAfter.ts +0 -19
- package/http/ServerSentEvents.ts +0 -145
- package/jest.config.js +0 -12
- package/links/AggregateLinkExtractor.ts +0 -28
- package/links/HalLinkExtractor.ts +0 -45
- package/links/HeaderLinkExtractor.ts +0 -56
- package/serializers/JsonSerializer.ts +0 -25
- /package/endpoints/generic/{index.ts → index.d.ts} +0 -0
- /package/endpoints/raw/{index.ts → index.d.ts} +0 -0
- /package/endpoints/reactive/{index.ts → index.d.ts} +0 -0
- /package/endpoints/rpc/{index.ts → index.d.ts} +0 -0
- /package/errors/{ErrorHandler.ts → ErrorHandler.d.ts} +0 -0
- /package/errors/{index.ts → index.d.ts} +0 -0
- /package/http/{index.ts → index.d.ts} +0 -0
- /package/{index.ts → index.d.ts} +0 -0
- /package/links/{index.ts → index.d.ts} +0 -0
- /package/serializers/{index.ts → index.d.ts} +0 -0
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { Endpoint } from "../Endpoint";
|
|
2
|
-
import { HttpMethod, entityStream } from "../../http";
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Endpoint for a stream of `TEntity`s using a persistent HTTP connection.
|
|
6
4
|
* @typeParam TEntity The type of individual elements in the stream.
|
|
7
5
|
*/
|
|
8
|
-
export class StreamingEndpoint<TEntity> extends Endpoint {
|
|
6
|
+
export declare class StreamingEndpoint<TEntity> extends Endpoint {
|
|
7
|
+
private readonly separator;
|
|
9
8
|
/**
|
|
10
9
|
* Creates a new streaming endpoint.
|
|
11
10
|
* @param referrer The endpoint used to navigate to this one.
|
|
12
11
|
* @param relativeUri The URI of this endpoint relative to the `referrer`'s. Add a `./` prefix here to imply a trailing slash in the `referrer`'s URI.
|
|
13
12
|
* @param separator The character sequence used to detect that a new element starts in the HTTP stream.
|
|
14
13
|
*/
|
|
15
|
-
constructor(referrer: Endpoint, relativeUri: URL | string,
|
|
16
|
-
super(referrer, relativeUri);
|
|
17
|
-
}
|
|
18
|
-
|
|
14
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, separator?: string);
|
|
19
15
|
/**
|
|
20
16
|
* Provides a stream of `TEntity`s, keeping the HTTP connection open until the server closes it.
|
|
21
17
|
* @param signal Used to close the connection.
|
|
@@ -24,27 +20,9 @@ export class StreamingEndpoint<TEntity> extends Endpoint {
|
|
|
24
20
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
25
21
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
26
22
|
*/
|
|
27
|
-
|
|
28
|
-
// NOTE: Abort the request when the consumer stops iterating, not just when the caller's signal fires.
|
|
29
|
-
const controller = new AbortController();
|
|
30
|
-
const onAbort = () => controller.abort();
|
|
31
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
32
|
-
if (signal?.aborted) controller.abort();
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const response = await this.send(HttpMethod.Get, controller.signal);
|
|
36
|
-
yield* entityStream<TEntity>(response, this.serializer, this.separator);
|
|
37
|
-
} catch (err) {
|
|
38
|
-
// Aborting is a regular way of ending the stream, not an error
|
|
39
|
-
if (!signal?.aborted) throw err;
|
|
40
|
-
} finally {
|
|
41
|
-
signal?.removeEventListener("abort", onAbort);
|
|
42
|
-
controller.abort();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
23
|
+
stream(signal?: AbortSignal): AsyncIterableIterator<TEntity>;
|
|
46
24
|
/**
|
|
47
25
|
* Provides a stream of `TEntity`s using {@link stream}.
|
|
48
26
|
*/
|
|
49
|
-
[Symbol.asyncIterator]()
|
|
27
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TEntity>;
|
|
50
28
|
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { RpcEndpointBase } from "./RpcEndpointBase";
|
|
2
2
|
import { Endpoint } from "../Endpoint";
|
|
3
|
-
import { HttpMethod } from "../../http";
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* RPC endpoint that is invoked with no input or output.
|
|
7
5
|
*/
|
|
8
|
-
export class ActionEndpoint extends RpcEndpointBase {
|
|
6
|
+
export declare class ActionEndpoint extends RpcEndpointBase {
|
|
9
7
|
/**
|
|
10
8
|
* Creates a new action endpoint.
|
|
11
9
|
* @param referrer The endpoint used to navigate to this one.
|
|
12
10
|
* @param relativeUri The URI of this endpoint relative to the `referrer`'s. Add a `./` prefix here to imply a trailing slash in the `referrer`'s URI.
|
|
13
11
|
*/
|
|
14
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
15
|
-
super(referrer, relativeUri);
|
|
16
|
-
}
|
|
17
|
-
|
|
12
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
18
13
|
/**
|
|
19
14
|
* Invokes the action.
|
|
20
15
|
* @param signal Used to cancel the request.
|
|
@@ -23,7 +18,5 @@ export class ActionEndpoint extends RpcEndpointBase {
|
|
|
23
18
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
24
19
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
25
20
|
*/
|
|
26
|
-
|
|
27
|
-
await this.send(HttpMethod.Post, signal);
|
|
28
|
-
}
|
|
21
|
+
invoke(signal?: AbortSignal): Promise<void>;
|
|
29
22
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { RpcEndpointBase } from "./RpcEndpointBase";
|
|
2
2
|
import { Endpoint } from "../Endpoint";
|
|
3
|
-
import { HttpMethod, HttpHeader } from "../../http";
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* RPC endpoint that takes `TEntity` as input when invoked.
|
|
7
5
|
* @typeParam TEntity The type of entity the endpoint takes as input.
|
|
8
6
|
*/
|
|
9
|
-
export class ConsumerEndpoint<TEntity> extends RpcEndpointBase {
|
|
7
|
+
export declare class ConsumerEndpoint<TEntity> extends RpcEndpointBase {
|
|
10
8
|
/**
|
|
11
9
|
* Creates a new consumer endpoint.
|
|
12
10
|
* @param referrer The endpoint used to navigate to this one.
|
|
13
11
|
* @param relativeUri The URI of this endpoint relative to the `referrer`'s. Add a `./` prefix here to imply a trailing slash in the `referrer`'s URI.
|
|
14
12
|
*/
|
|
15
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
16
|
-
super(referrer, relativeUri);
|
|
17
|
-
}
|
|
18
|
-
|
|
13
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
19
14
|
/**
|
|
20
15
|
* Sends the entity to the consumer.
|
|
21
16
|
* @param entity The `TEntity` to post as input.
|
|
@@ -25,9 +20,5 @@ export class ConsumerEndpoint<TEntity> extends RpcEndpointBase {
|
|
|
25
20
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
26
21
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
27
22
|
*/
|
|
28
|
-
|
|
29
|
-
await this.send(HttpMethod.Post, signal, {
|
|
30
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
31
|
-
}, this.serializer.serialize(entity));
|
|
32
|
-
}
|
|
23
|
+
invoke(entity: TEntity, signal?: AbortSignal): Promise<void>;
|
|
33
24
|
}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { RpcEndpointBase } from "./RpcEndpointBase";
|
|
2
2
|
import { Endpoint } from "../Endpoint";
|
|
3
|
-
import { HttpMethod, HttpHeader } from "../../http";
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* RPC endpoint that takes `TEntity` as input and returns `TResult` as output when invoked.
|
|
7
5
|
* @typeParam TEntity The type of entity the endpoint takes as input.
|
|
8
6
|
* @typeParam TResult The type of entity the endpoint returns as output.
|
|
9
7
|
*/
|
|
10
|
-
export class FunctionEndpoint<TEntity, TResult> extends RpcEndpointBase {
|
|
8
|
+
export declare class FunctionEndpoint<TEntity, TResult> extends RpcEndpointBase {
|
|
11
9
|
/**
|
|
12
10
|
* Creates a new function endpoint.
|
|
13
11
|
* @param referrer The endpoint used to navigate to this one.
|
|
14
12
|
* @param relativeUri The URI of this endpoint relative to the `referrer`'s. Add a `./` prefix here to imply a trailing slash in the `referrer`'s URI.
|
|
15
13
|
*/
|
|
16
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
17
|
-
super(referrer, relativeUri);
|
|
18
|
-
}
|
|
19
|
-
|
|
14
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
20
15
|
/**
|
|
21
16
|
* Invokes the function.
|
|
22
17
|
* @param entity The `TEntity` to post as input.
|
|
@@ -27,11 +22,5 @@ export class FunctionEndpoint<TEntity, TResult> extends RpcEndpointBase {
|
|
|
27
22
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
28
23
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
29
24
|
*/
|
|
30
|
-
|
|
31
|
-
const response = await this.send(HttpMethod.Post, signal, {
|
|
32
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
33
|
-
}, this.serializer.serialize(entity));
|
|
34
|
-
|
|
35
|
-
return this.serializer.deserialize<TResult>(await response.text());
|
|
36
|
-
}
|
|
25
|
+
invoke(entity: TEntity, signal?: AbortSignal): Promise<TResult>;
|
|
37
26
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { RpcEndpointBase } from "./RpcEndpointBase";
|
|
2
2
|
import { Endpoint } from "../Endpoint";
|
|
3
|
-
import { HttpMethod } from "../../http";
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* RPC endpoint that returns `TResult` as output when invoked.
|
|
7
5
|
* @typeParam TResult The type of entity the endpoint returns as output.
|
|
8
6
|
*/
|
|
9
|
-
export class ProducerEndpoint<TResult> extends RpcEndpointBase {
|
|
7
|
+
export declare class ProducerEndpoint<TResult> extends RpcEndpointBase {
|
|
10
8
|
/**
|
|
11
9
|
* Creates a new producer endpoint.
|
|
12
10
|
* @param referrer The endpoint used to navigate to this one.
|
|
13
11
|
* @param relativeUri The URI of this endpoint relative to the `referrer`'s. Add a `./` prefix here to imply a trailing slash in the `referrer`'s URI.
|
|
14
12
|
*/
|
|
15
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
16
|
-
super(referrer, relativeUri);
|
|
17
|
-
}
|
|
18
|
-
|
|
13
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
19
14
|
/**
|
|
20
15
|
* Gets a result from the producer.
|
|
21
16
|
* @param signal Used to cancel the request.
|
|
@@ -25,8 +20,5 @@ export class ProducerEndpoint<TResult> extends RpcEndpointBase {
|
|
|
25
20
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
26
21
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
27
22
|
*/
|
|
28
|
-
|
|
29
|
-
const response = await this.send(HttpMethod.Post, signal);
|
|
30
|
-
return this.serializer.deserialize<TResult>(await response.text());
|
|
31
|
-
}
|
|
23
|
+
invoke(signal?: AbortSignal): Promise<TResult>;
|
|
32
24
|
}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { Endpoint } from "../Endpoint";
|
|
2
|
-
import { HttpMethod } from "../../http";
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Base class for building RPC endpoints.
|
|
6
4
|
*/
|
|
7
|
-
export class RpcEndpointBase extends Endpoint {
|
|
5
|
+
export declare class RpcEndpointBase extends Endpoint {
|
|
8
6
|
/**
|
|
9
7
|
* Creates a new RPC endpoint.
|
|
10
8
|
* @param referrer The endpoint used to navigate to this one.
|
|
11
9
|
* @param relativeUri The URI of this endpoint relative to the `referrer`'s. Add a `./` prefix here to imply a trailing slash in the `referrer`'s URI.
|
|
12
10
|
*/
|
|
13
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
14
|
-
super(referrer, relativeUri);
|
|
15
|
-
}
|
|
16
|
-
|
|
11
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
17
12
|
/**
|
|
18
13
|
* Queries the server about capabilities of the endpoint without performing any action.
|
|
19
14
|
* @param signal Used to cancel the request.
|
|
@@ -22,14 +17,11 @@ export class RpcEndpointBase extends Endpoint {
|
|
|
22
17
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
23
18
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
24
19
|
*/
|
|
25
|
-
|
|
26
|
-
await this.send(HttpMethod.Options, signal);
|
|
27
|
-
}
|
|
28
|
-
|
|
20
|
+
probe(signal?: AbortSignal): Promise<void>;
|
|
29
21
|
/**
|
|
30
22
|
* Shows whether the server has indicated that the invoke method is currently allowed.
|
|
31
23
|
* Uses cached data from last response.
|
|
32
24
|
* @returns `true` if the method is allowed, `false` if the method is not allowed, `undefined` if no request has been sent yet or the server did not specify allowed methods.
|
|
33
25
|
*/
|
|
34
|
-
get invokeAllowed()
|
|
26
|
+
get invokeAllowed(): boolean | undefined;
|
|
35
27
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ErrorHandler } from "./ErrorHandler";
|
|
2
|
+
/**
|
|
3
|
+
* Handles errors in HTTP responses by mapping status codes to common error types.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DefaultErrorHandler implements ErrorHandler {
|
|
6
|
+
/**
|
|
7
|
+
* Throws appropriate `Error`s based on HTTP status codes and response bodies.
|
|
8
|
+
*
|
|
9
|
+
* @throws {@link errors!BadRequestError}: {@link http!HttpStatusCode.BadRequest}
|
|
10
|
+
* @throws {@link errors!AuthenticationError}: {@link http!HttpStatusCode.Unauthorized}
|
|
11
|
+
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
12
|
+
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
13
|
+
* @throws {@link errors!TimeoutError}: {@link http!HttpStatusCode.RequestTimeout}
|
|
14
|
+
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
15
|
+
* @throws {@link errors!ConcurrencyError}: {@link http!HttpStatusCode.PreconditionFailed}
|
|
16
|
+
* @throws {@link errors!RangeNotSatisfiableError}: {@link http!HttpStatusCode.RangeNotSatisfiable}
|
|
17
|
+
* @throws {@link errors!HttpError}: Other non-success status code
|
|
18
|
+
*/
|
|
19
|
+
handle(response: Response): Promise<void>;
|
|
20
|
+
private static errorType;
|
|
21
|
+
}
|
|
@@ -1,56 +1,55 @@
|
|
|
1
1
|
import { HttpStatusCode } from "../http";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Thrown on HTTP response with a non-successful status code (4xx or 5xx).
|
|
5
4
|
*/
|
|
6
|
-
export class HttpError extends Error {
|
|
5
|
+
export declare class HttpError extends Error {
|
|
6
|
+
status: HttpStatusCode;
|
|
7
|
+
data?: any | undefined;
|
|
7
8
|
/**
|
|
8
9
|
* Creates a new HTTP error.
|
|
9
10
|
* @param message The error message.
|
|
10
11
|
* @param status The HTTP status code.
|
|
11
12
|
* @param data Additional error data.
|
|
12
13
|
*/
|
|
13
|
-
constructor(message: string,
|
|
14
|
-
super(message);
|
|
15
|
-
}
|
|
14
|
+
constructor(message: string, status: HttpStatusCode, data?: any | undefined);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
/**
|
|
19
17
|
* Thrown on HTTP response for a bad request (usually {@link http!HttpStatusCode.BadRequest}).
|
|
20
18
|
*/
|
|
21
|
-
export class BadRequestError extends HttpError {
|
|
22
|
-
|
|
19
|
+
export declare class BadRequestError extends HttpError {
|
|
20
|
+
}
|
|
23
21
|
/**
|
|
24
22
|
* Thrown on HTTP response for an unauthenticated request, i.e. missing credentials (usually {@link http!HttpStatusCode.Unauthorized}).
|
|
25
23
|
*/
|
|
26
|
-
export class AuthenticationError extends HttpError {
|
|
27
|
-
|
|
24
|
+
export declare class AuthenticationError extends HttpError {
|
|
25
|
+
}
|
|
28
26
|
/**
|
|
29
27
|
* Thrown on HTTP response for an unauthorized request, i.e. missing permissions (usually {@link http!HttpStatusCode.Forbidden}).
|
|
30
28
|
*/
|
|
31
|
-
export class AuthorizationError extends HttpError {
|
|
32
|
-
|
|
29
|
+
export declare class AuthorizationError extends HttpError {
|
|
30
|
+
}
|
|
33
31
|
/**
|
|
34
32
|
* Thrown on HTTP response for a missing resource (usually {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}).
|
|
35
33
|
*/
|
|
36
|
-
export class NotFoundError extends HttpError {
|
|
37
|
-
|
|
34
|
+
export declare class NotFoundError extends HttpError {
|
|
35
|
+
}
|
|
38
36
|
/**
|
|
39
37
|
* Thrown on HTTP response for a timed-out operation (usually {@link http!HttpStatusCode.RequestTimeout}).
|
|
40
38
|
*/
|
|
41
|
-
export class TimeoutError extends HttpError {
|
|
42
|
-
|
|
39
|
+
export declare class TimeoutError extends HttpError {
|
|
40
|
+
}
|
|
43
41
|
/**
|
|
44
42
|
* Thrown on HTTP response for a resource conflict (usually {@link http!HttpStatusCode.Conflict}).
|
|
45
43
|
*/
|
|
46
|
-
export class ConflictError extends HttpError {
|
|
47
|
-
|
|
44
|
+
export declare class ConflictError extends HttpError {
|
|
45
|
+
}
|
|
48
46
|
/**
|
|
49
47
|
* Thrown on HTTP response for a failed precondition or mid-air collision (usually {@link http!HttpStatusCode.PreconditionFailed}).
|
|
50
48
|
*/
|
|
51
|
-
export class ConcurrencyError extends HttpError {
|
|
52
|
-
|
|
49
|
+
export declare class ConcurrencyError extends HttpError {
|
|
50
|
+
}
|
|
53
51
|
/**
|
|
54
52
|
* Thrown on HTTP response for a requested range that the server can not provide (usually {@link http!HttpStatusCode.RangeNotSatisfiable}).
|
|
55
53
|
*/
|
|
56
|
-
export class RangeNotSatisfiableError extends HttpError {
|
|
54
|
+
export declare class RangeNotSatisfiableError extends HttpError {
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Serializer } from "../serializers";
|
|
2
|
+
/**
|
|
3
|
+
* Exposes the body of a `Response` as a stream of deserialized entities.
|
|
4
|
+
* @typeParam TEntity The type of entity the stream provides.
|
|
5
|
+
* @param response The response to read the body from.
|
|
6
|
+
* @param serializer Controls the deserialization of the entities in the body.
|
|
7
|
+
* @param separator The character sequence used to detect that a new entity starts in the stream.
|
|
8
|
+
* @returns A stream that ends when the server closes the connection.
|
|
9
|
+
*/
|
|
10
|
+
export declare function entityStream<TEntity>(response: Response, serializer: Serializer, separator?: string): AsyncIterableIterator<TEntity>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpMethod } from "./HttpMethod";
|
|
2
|
+
import { HttpClient } from "./HttpClient";
|
|
3
|
+
/**
|
|
4
|
+
* Communicates with remote resources using JavaScript's standard Fetch API.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FetchHttpClient implements HttpClient {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritDoc
|
|
9
|
+
*/
|
|
10
|
+
defaultHeaders: Headers;
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
send(uri: URL, method: HttpMethod, signal?: AbortSignal, headers?: RequestInit["headers"], body?: RequestInit["body"]): Promise<Response>;
|
|
15
|
+
}
|
package/http/FetchHttpClient.js
CHANGED
|
@@ -25,4 +25,4 @@ class FetchHttpClient {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.FetchHttpClient = FetchHttpClient;
|
|
28
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRmV0Y2hIdHRwQ2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiRmV0Y2hIdHRwQ2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUdBOztHQUVHO0FBQ0gsTUFBYSxlQUFlO0lBQTVCO1FBQ0k7O1dBRUc7UUFDSCxtQkFBYyxHQUFHLElBQUksT0FBTyxFQUFFLENBQUM7SUFlbkMsQ0FBQztJQWJHOztPQUVHO0lBQ0gsSUFBSSxDQUFDLEdBQVEsRUFBRSxNQUFrQixFQUFFLE1BQW9CLEVBQUUsT0FBZ0MsRUFBRSxJQUEwQjtRQUNqSCxNQUFNLGFBQWEsR0FBRyxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUMzQyxJQUFJLENBQUMsY0FBYyxDQUFDLE9BQU8sQ0FBQyxDQUFDLEtBQUssRUFBRSxHQUFHLEVBQUUsRUFBRTtZQUN2QyxJQUFJLENBQUMsYUFBYSxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDO2dCQUMxQixhQUFhLENBQUMsR0FBRyxDQUFDLEdBQUcsRUFBRSxLQUFLLENBQUMsQ0FBQztZQUNsQyxDQUFDO1FBQ0wsQ0FBQyxDQUFDLENBQUM7UUFFSCxPQUFPLEtBQUssQ0FBQyxHQUFHLENBQUMsSUFBSSxFQUFFLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxPQUFPLEVBQUUsYUFBYSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUM7SUFDN0UsQ0FBQztDQUNKO0FBbkJELDBDQW1CQyJ9
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HttpMethod } from "./HttpMethod";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* HTTP client used to communicate with remote resources.
|
|
5
4
|
*/
|
|
@@ -8,7 +7,6 @@ export interface HttpClient {
|
|
|
8
7
|
* Default HTTP headers to set for requests when not explicitly overridden.
|
|
9
8
|
*/
|
|
10
9
|
defaultHeaders: Headers;
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* Sends an HTTP request.
|
|
14
12
|
* @param uri The URI to send the message to.
|
|
@@ -17,5 +15,5 @@ export interface HttpClient {
|
|
|
17
15
|
* @param headers The HTTP headers to set.
|
|
18
16
|
* @param body The body to send.
|
|
19
17
|
*/
|
|
20
|
-
send(uri: URL, method: HttpMethod, signal?: AbortSignal, headers?:
|
|
18
|
+
send(uri: URL, method: HttpMethod, signal?: AbortSignal, headers?: RequestInit["headers"], body?: RequestInit["body"]): Promise<Response>;
|
|
21
19
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes which subset of a set of elements a response contains.
|
|
3
|
+
*/
|
|
4
|
+
export declare class HttpContentRange {
|
|
5
|
+
readonly unit: string;
|
|
6
|
+
readonly from?: number | undefined;
|
|
7
|
+
readonly to?: number | undefined;
|
|
8
|
+
readonly length?: number | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new content range.
|
|
11
|
+
* @param unit The unit the range is expressed in, e.g. `elements`.
|
|
12
|
+
* @param from The index at which the data starts.
|
|
13
|
+
* @param to The index at which the data stops.
|
|
14
|
+
* @param length The total number of elements available on the server; `undefined` if unknown.
|
|
15
|
+
*/
|
|
16
|
+
constructor(unit: string, from?: number | undefined, to?: number | undefined, length?: number | undefined);
|
|
17
|
+
private static readonly pattern;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the content range from a `Response`.
|
|
20
|
+
* @returns The content range; `undefined` if the response has no (valid) {@link HttpHeader.ContentRange} header.
|
|
21
|
+
*/
|
|
22
|
+
static from(response: Response): HttpContentRange | undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caches the contents of a `Response`.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ResponseCache {
|
|
5
|
+
readonly content: string;
|
|
6
|
+
readonly contentType?: string | undefined;
|
|
7
|
+
readonly eTag?: string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new cache.
|
|
10
|
+
* @param content The content of the `Response`.
|
|
11
|
+
* @param contentType The MIME type of the `content`.
|
|
12
|
+
* @param eTag The E-Tag associated with the `content`.
|
|
13
|
+
*/
|
|
14
|
+
constructor(content: string, contentType?: string | undefined, eTag?: string | undefined);
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new cache from a `Response`.
|
|
17
|
+
*/
|
|
18
|
+
static from(response: Response): Promise<ResponseCache>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the delay a server has asked clients to wait for before retrying a request.
|
|
3
|
+
* @param response The response to read the {@link HttpHeader.RetryAfter} header from.
|
|
4
|
+
* @returns The delay in milliseconds; `undefined` if the response has no (valid) header.
|
|
5
|
+
*/
|
|
6
|
+
export declare function retryAfter(response: Response): number | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single event read from a Server-Sent Events (SSE) stream.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ServerSentEvent {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly data: string;
|
|
7
|
+
readonly id?: string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new event.
|
|
10
|
+
* @param type The event type from the `event:` field. {@link defaultEventType} if the server did not specify one.
|
|
11
|
+
* @param data The concatenated content of the event's `data:` fields.
|
|
12
|
+
* @param id The id of the most recent `id:` field if any.
|
|
13
|
+
*/
|
|
14
|
+
constructor(type: string, data: string, id?: string | undefined);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The event type used for events without an explicit `event:` field.
|
|
18
|
+
*/
|
|
19
|
+
export declare const defaultEventType = "message";
|
|
20
|
+
/**
|
|
21
|
+
* Reads {@link ServerSentEvent}s from the body of a `Response` in the `text/event-stream` format.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SseReader {
|
|
24
|
+
private readonly response;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new reader.
|
|
27
|
+
* @param response The response to read the body from.
|
|
28
|
+
*/
|
|
29
|
+
constructor(response: Response);
|
|
30
|
+
private _lastEventId?;
|
|
31
|
+
/**
|
|
32
|
+
* The id of the most recent event that carried an `id:` field.<br>
|
|
33
|
+
* Send this back as a {@link HttpHeader.LastEventId} header when reconnecting to let the server resume where it left off.
|
|
34
|
+
*/
|
|
35
|
+
get lastEventId(): string | undefined;
|
|
36
|
+
private _reconnectionInterval?;
|
|
37
|
+
/**
|
|
38
|
+
* The reconnection interval in milliseconds most recently requested by the server via a `retry:` field if any.
|
|
39
|
+
*/
|
|
40
|
+
get reconnectionInterval(): number | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Reads events until the stream ends.<br>
|
|
43
|
+
* Any event that is still incomplete when the stream ends is discarded.
|
|
44
|
+
*/
|
|
45
|
+
events(): AsyncIterableIterator<ServerSentEvent>;
|
|
46
|
+
/**
|
|
47
|
+
* Splits the response body into lines, accepting `\n`, `\r\n` and `\r` as terminators.
|
|
48
|
+
*/
|
|
49
|
+
private lines;
|
|
50
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Link } from "./Link";
|
|
2
|
+
import { LinkExtractor } from "./LinkExtractor";
|
|
3
|
+
/**
|
|
4
|
+
* Combines the results of multiple {@link LinkExtractor}s.
|
|
5
|
+
*/
|
|
6
|
+
export declare class AggregateLinkExtractor implements LinkExtractor {
|
|
7
|
+
private extractors;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new aggregate link extractor.
|
|
10
|
+
* @param extractors The link extractors to aggregate.
|
|
11
|
+
*/
|
|
12
|
+
constructor(...extractors: LinkExtractor[]);
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
getLinks(response: Response): Promise<Link[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Link } from "./Link";
|
|
2
|
+
import { LinkExtractor } from "./LinkExtractor";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts links from JSON bodies according to the Hypertext Application Language (HAL) specification.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HalLinkExtractor implements LinkExtractor {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritDoc
|
|
9
|
+
*/
|
|
10
|
+
getLinks(response: Response): Promise<Link[]>;
|
|
11
|
+
private parseJsonBody;
|
|
12
|
+
private parseLink;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Link } from "./Link";
|
|
2
|
+
import { LinkExtractor } from "./LinkExtractor";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts links from HTTP headers.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HeaderLinkExtractor implements LinkExtractor {
|
|
7
|
+
/**
|
|
8
|
+
* @inheritDoc
|
|
9
|
+
*/
|
|
10
|
+
getLinks(response: Response): Promise<Link[]>;
|
|
11
|
+
private parseLink;
|
|
12
|
+
private split;
|
|
13
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a link to another resource.
|
|
3
3
|
*/
|
|
4
|
-
export class Link {
|
|
4
|
+
export declare class Link {
|
|
5
|
+
rel: string;
|
|
6
|
+
href: string;
|
|
7
|
+
title?: string | undefined;
|
|
8
|
+
templated: boolean;
|
|
5
9
|
/**
|
|
6
10
|
* Creates a new link.
|
|
7
11
|
* @param rel The relation type of the link.
|
|
@@ -9,5 +13,5 @@ export class Link {
|
|
|
9
13
|
* @param title The title of the link.
|
|
10
14
|
* @param templated Indicates whether the link is an URI Template (RFC 6570).
|
|
11
15
|
*/
|
|
12
|
-
constructor(
|
|
16
|
+
constructor(rel: string, href: string, title?: string | undefined, templated?: boolean);
|
|
13
17
|
}
|