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
|
@@ -2,53 +2,32 @@ import { ETagEndpointBase } from "./ETagEndpointBase";
|
|
|
2
2
|
import { ElementEndpoint } from "./ElementEndpoint";
|
|
3
3
|
import { PartialResponse } from "./PartialResponse";
|
|
4
4
|
import { Endpoint } from "../Endpoint";
|
|
5
|
-
import { CachingEndpoint } from "../CachingEndpoint";
|
|
6
|
-
import { HttpMethod, HttpHeader, HttpContentRange, ResponseCache } from "../../http";
|
|
7
|
-
|
|
8
5
|
/**
|
|
9
6
|
* Endpoint for a collection of `TEntity`s addressable as `TElementEndpoint`s.<br>
|
|
10
7
|
* Use {@link CollectionEndpoint} instead if you wish to use the default {@link ElementEndpoint} type.
|
|
11
8
|
* @typeParam TEntity The type of individual elements in the collection.
|
|
12
9
|
* @typeParam TElementEndpoint The type of {@link ElementEndpoint} to provide for individual `TEntity`s.
|
|
13
10
|
*/
|
|
14
|
-
export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends ElementEndpoint<TEntity>> extends ETagEndpointBase {
|
|
11
|
+
export declare class GenericCollectionEndpoint<TEntity, TElementEndpoint extends ElementEndpoint<TEntity>> extends ETagEndpointBase {
|
|
12
|
+
private readonly elementEndpoint;
|
|
15
13
|
/**
|
|
16
14
|
* Creates a new collection endpoint.
|
|
17
15
|
* @param referrer The endpoint used to navigate to this one.
|
|
18
16
|
* @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.
|
|
19
17
|
* @param elementEndpoint A factory method for creating instances of `TElementEndpoint`.
|
|
20
18
|
*/
|
|
21
|
-
constructor(referrer: Endpoint, relativeUri: URL | string,
|
|
22
|
-
super(referrer, relativeUri);
|
|
23
|
-
this.setDefaultLinkTemplate("child", "./{id}");
|
|
24
|
-
}
|
|
25
|
-
|
|
19
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, elementEndpoint: new (referrer: Endpoint, uri: URL) => TElementEndpoint);
|
|
26
20
|
/**
|
|
27
21
|
* Returns an `TElementEndpoint` for a specific child element.
|
|
28
22
|
* @param element The ID identifying the entity or an entity to extract the ID from.
|
|
29
23
|
*/
|
|
30
|
-
get(element: (TEntity | string)): TElementEndpoint
|
|
31
|
-
if (element == null) throw new Error("element must not be null or unspecified.");
|
|
32
|
-
|
|
33
|
-
let id: string;
|
|
34
|
-
if (typeof element === "string") {
|
|
35
|
-
id = element;
|
|
36
|
-
} else {
|
|
37
|
-
id = (element as any).id;
|
|
38
|
-
if (id === undefined) throw new Error(`Element ${element} does not have an id property.`);
|
|
39
|
-
}
|
|
40
|
-
if (id == null || id === "") throw new Error("id must not be null or empty.");
|
|
41
|
-
|
|
42
|
-
return new this.elementEndpoint(this, this.linkTemplate("child", { id }));
|
|
43
|
-
}
|
|
44
|
-
|
|
24
|
+
get(element: (TEntity | string)): TElementEndpoint;
|
|
45
25
|
/**
|
|
46
26
|
* Shows whether the server has indicated that {@link readAll} is currently allowed.
|
|
47
27
|
* Uses cached data from last response.
|
|
48
28
|
* @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.
|
|
49
29
|
*/
|
|
50
|
-
get readAllAllowed()
|
|
51
|
-
|
|
30
|
+
get readAllAllowed(): boolean | undefined;
|
|
52
31
|
/**
|
|
53
32
|
* Returns all `TEntity`s in the collection.
|
|
54
33
|
* @param signal Used to cancel the request.
|
|
@@ -57,42 +36,22 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
57
36
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
58
37
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
59
38
|
*/
|
|
60
|
-
|
|
61
|
-
return this.serializer.deserialize<TEntity[]>(await this.getContent(signal));
|
|
62
|
-
}
|
|
63
|
-
|
|
39
|
+
readAll(signal?: AbortSignal): Promise<TEntity[]>;
|
|
64
40
|
/**
|
|
65
41
|
* The unit used when requesting ranges of elements. Sent in the {@link http!HttpHeader.Range} header.
|
|
66
42
|
*/
|
|
67
|
-
rangeUnit
|
|
68
|
-
|
|
69
|
-
// NOTE: Only modified when the server reports its capabilities.
|
|
70
|
-
private acceptedRangeUnits: string[] = [];
|
|
71
|
-
|
|
43
|
+
rangeUnit: string;
|
|
44
|
+
private acceptedRangeUnits;
|
|
72
45
|
/**
|
|
73
46
|
* @inheritDoc
|
|
74
47
|
*/
|
|
75
|
-
protected handleCapabilities(response: Response)
|
|
76
|
-
super.handleCapabilities(response);
|
|
77
|
-
|
|
78
|
-
const header = response.headers.get(HttpHeader.AcceptRanges);
|
|
79
|
-
if (header) {
|
|
80
|
-
this.acceptedRangeUnits = header.split(",").map(x => x.trim());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
48
|
+
protected handleCapabilities(response: Response): void;
|
|
84
49
|
/**
|
|
85
50
|
* Shows whether the server has indicated that {@link readRange} is currently allowed.
|
|
86
51
|
* Uses cached data from last response.
|
|
87
52
|
* @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 accepted range units.
|
|
88
53
|
*/
|
|
89
|
-
get readRangeAllowed(): boolean | undefined
|
|
90
|
-
if (this.acceptedRangeUnits.length === 0)
|
|
91
|
-
return undefined;
|
|
92
|
-
|
|
93
|
-
return this.acceptedRangeUnits.indexOf(this.rangeUnit) !== -1;
|
|
94
|
-
}
|
|
95
|
-
|
|
54
|
+
get readRangeAllowed(): boolean | undefined;
|
|
96
55
|
/**
|
|
97
56
|
* Returns a subset of the `TEntity`s in the collection.
|
|
98
57
|
* @param from The index of the first element to return. Leave unspecified to return the last `to` elements ("tail").
|
|
@@ -103,23 +62,13 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
103
62
|
* @throws {@link errors!RangeNotSatisfiableError}: {@link http!HttpStatusCode.RangeNotSatisfiable}, i.e. the requested range lies outside of the elements currently available
|
|
104
63
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
105
64
|
*/
|
|
106
|
-
|
|
107
|
-
const response = await this.send(HttpMethod.Get, signal, {
|
|
108
|
-
[HttpHeader.Range]: `${this.rangeUnit}=${from ?? ""}-${to ?? ""}`
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return new PartialResponse<TEntity>(
|
|
112
|
-
this.serializer.deserialize<TEntity[]>(await response.text()),
|
|
113
|
-
HttpContentRange.from(response));
|
|
114
|
-
}
|
|
115
|
-
|
|
65
|
+
readRange(from?: number, to?: number, signal?: AbortSignal): Promise<PartialResponse<TEntity>>;
|
|
116
66
|
/**
|
|
117
67
|
* Shows whether the server has indicated that {@link create} is currently allowed.
|
|
118
68
|
* Uses cached data from last response.
|
|
119
69
|
* @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.
|
|
120
70
|
*/
|
|
121
|
-
get createAllowed()
|
|
122
|
-
|
|
71
|
+
get createAllowed(): boolean | undefined;
|
|
123
72
|
/**
|
|
124
73
|
* Adds a `TEntity` as a new element to the collection.
|
|
125
74
|
* @param entity The new `TEntity`.
|
|
@@ -131,37 +80,13 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
131
80
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
132
81
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
133
82
|
*/
|
|
134
|
-
|
|
135
|
-
const response = await this.send(HttpMethod.Post, signal, {
|
|
136
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
137
|
-
}, this.serializer.serialize(entity));
|
|
138
|
-
const location = response.headers.get(HttpHeader.Location);
|
|
139
|
-
|
|
140
|
-
let elementEndpoint: TElementEndpoint;
|
|
141
|
-
if (location) {
|
|
142
|
-
// Explicit element endpoint URL from "Location" header
|
|
143
|
-
elementEndpoint = new this.elementEndpoint(this, this.join(location));
|
|
144
|
-
} else {
|
|
145
|
-
try {
|
|
146
|
-
// Infer URL from entity ID in response body
|
|
147
|
-
elementEndpoint = this.get(this.serializer.deserialize(await response.clone().text()));
|
|
148
|
-
} catch {
|
|
149
|
-
// No element endpoint
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
(elementEndpoint as CachingEndpoint).responseCache = await ResponseCache.from(response);
|
|
155
|
-
return elementEndpoint;
|
|
156
|
-
}
|
|
157
|
-
|
|
83
|
+
create(entity: TEntity, signal?: AbortSignal): Promise<TElementEndpoint | undefined>;
|
|
158
84
|
/**
|
|
159
85
|
* Shows whether the server has indicated that {@link createAll} is currently allowed.
|
|
160
86
|
* Uses cached data from last response.
|
|
161
87
|
* @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.
|
|
162
88
|
*/
|
|
163
|
-
get createAllAllowed()
|
|
164
|
-
|
|
89
|
+
get createAllAllowed(): boolean | undefined;
|
|
165
90
|
/**
|
|
166
91
|
* Adds (or updates) multiple `TEntity`s as elements in the collection.
|
|
167
92
|
* @param entities The `TEntity`s to create or modify.
|
|
@@ -172,19 +97,13 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
172
97
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
173
98
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
174
99
|
*/
|
|
175
|
-
|
|
176
|
-
await this.send(HttpMethod.Patch, signal, {
|
|
177
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
178
|
-
}, this.serializer.serialize(entities));
|
|
179
|
-
}
|
|
180
|
-
|
|
100
|
+
createAll(entities: TEntity[], signal?: AbortSignal): Promise<void>;
|
|
181
101
|
/**
|
|
182
102
|
* Shows whether the server has indicated that {@link setAll} is currently allowed.
|
|
183
103
|
* Uses cached data from last response.
|
|
184
104
|
* @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.
|
|
185
105
|
*/
|
|
186
|
-
get setAllAllowed()
|
|
187
|
-
|
|
106
|
+
get setAllAllowed(): boolean | undefined;
|
|
188
107
|
/**
|
|
189
108
|
* Replaces the entire content of the collection with new `TEntity`s.
|
|
190
109
|
* @param entities The `TEntity`s to create or modify.
|
|
@@ -194,8 +113,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
194
113
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
195
114
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
196
115
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
116
|
+
setAll(entities: TEntity[]): Promise<void>;
|
|
199
117
|
/**
|
|
200
118
|
* Determines whether the collection contains a specific element.
|
|
201
119
|
* @param element The ID identifying the entity or an entity to extract the ID from.
|
|
@@ -203,8 +121,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
203
121
|
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
204
122
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
205
123
|
*/
|
|
206
|
-
contains(element: (TEntity | string))
|
|
207
|
-
|
|
124
|
+
contains(element: (TEntity | string)): Promise<boolean>;
|
|
208
125
|
/**
|
|
209
126
|
* Sets/replaces an existing element in the collection.
|
|
210
127
|
* @param element The new state of the element.
|
|
@@ -215,8 +132,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
215
132
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
216
133
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
217
134
|
*/
|
|
218
|
-
set(element: TEntity)
|
|
219
|
-
|
|
135
|
+
set(element: TEntity): Promise<TEntity | undefined>;
|
|
220
136
|
/**
|
|
221
137
|
* Modifies an existing element in the collection by merging changes on the server-side.
|
|
222
138
|
* @param element The `TEntity` data to merge with the existing element.
|
|
@@ -227,8 +143,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
227
143
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
228
144
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
229
145
|
*/
|
|
230
|
-
merge(element: TEntity)
|
|
231
|
-
|
|
146
|
+
merge(element: TEntity): Promise<TEntity | undefined>;
|
|
232
147
|
/**
|
|
233
148
|
* Deletes an existing element from the collection.
|
|
234
149
|
* @param element The ID identifying the entity or an entity to extract the ID from.
|
|
@@ -237,5 +152,5 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
237
152
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
238
153
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
239
154
|
*/
|
|
240
|
-
delete(element: (TEntity | string))
|
|
155
|
+
delete(element: (TEntity | string)): Promise<void>;
|
|
241
156
|
}
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import { Endpoint } from "../Endpoint";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Endpoint that addresses child `TElementEndpoint`s by ID.
|
|
5
4
|
* @typeParam TElementEndpoint The type of {@link Endpoint} to provide for individual elements.
|
|
6
5
|
*/
|
|
7
|
-
export class IndexerEndpoint<TElementEndpoint extends Endpoint> extends Endpoint {
|
|
6
|
+
export declare class IndexerEndpoint<TElementEndpoint extends Endpoint> extends Endpoint {
|
|
7
|
+
private readonly elementEndpoint;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new indexer endpoint.
|
|
10
10
|
* @param referrer The endpoint used to navigate to this one.
|
|
11
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.
|
|
12
12
|
* @param elementEndpoint A factory method for creating instances of `TElementEndpoint`.
|
|
13
13
|
*/
|
|
14
|
-
constructor(referrer: Endpoint, relativeUri: URL | string,
|
|
15
|
-
super(referrer, relativeUri);
|
|
16
|
-
this.setDefaultLinkTemplate("child", "./{id}");
|
|
17
|
-
}
|
|
18
|
-
|
|
14
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, elementEndpoint: new (referrer: Endpoint, uri: URL) => TElementEndpoint);
|
|
19
15
|
/**
|
|
20
16
|
* Returns a `TElementEndpoint` for a specific child element.
|
|
21
17
|
* @param id The ID identifying the entity.
|
|
22
18
|
*/
|
|
23
|
-
get(id: string): TElementEndpoint
|
|
24
|
-
if (id == null || id === "") throw new Error("id must not be null, unspecified or empty.");
|
|
25
|
-
return new this.elementEndpoint(this, this.linkTemplate("child", { id }));
|
|
26
|
-
}
|
|
19
|
+
get(id: string): TElementEndpoint;
|
|
27
20
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HttpContentRange } from "../../http";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a subset of a set of elements.
|
|
4
|
+
* @typeParam TEntity The type of element the response contains.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PartialResponse<TEntity> {
|
|
7
|
+
readonly elements: TEntity[];
|
|
8
|
+
readonly range?: HttpContentRange | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new partial response.
|
|
11
|
+
* @param elements The returned elements.
|
|
12
|
+
* @param range The range the `elements` come from.
|
|
13
|
+
*/
|
|
14
|
+
constructor(elements: TEntity[], range?: HttpContentRange | undefined);
|
|
15
|
+
/**
|
|
16
|
+
* Indicates whether the response reaches the end of the elements available on the server.
|
|
17
|
+
*/
|
|
18
|
+
get endReached(): boolean;
|
|
19
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export * as generic from "./generic";
|
|
2
2
|
export * as rpc from "./rpc";
|
|
3
3
|
export * as raw from "./raw";
|
|
4
4
|
export * as reactive from "./reactive";
|
|
5
|
-
|
|
6
5
|
export * from "./Endpoint";
|
|
7
6
|
export * from "./EntryEndpoint";
|
|
8
7
|
export * from "./CachingEndpoint";
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { Endpoint } from "../Endpoint";
|
|
2
|
-
import { HttpMethod, HttpHeader } from "../../http";
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Endpoint for a binary blob that can be downloaded or uploaded.
|
|
6
4
|
*/
|
|
7
|
-
export class BlobEndpoint extends Endpoint {
|
|
5
|
+
export declare class BlobEndpoint extends Endpoint {
|
|
8
6
|
/**
|
|
9
7
|
* Creates a new blob 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,17 +17,13 @@ export class BlobEndpoint 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 {@link download} 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 downloadAllowed()
|
|
35
|
-
|
|
26
|
+
get downloadAllowed(): boolean | undefined;
|
|
36
27
|
/**
|
|
37
28
|
* Downloads the blob's content.
|
|
38
29
|
* @param signal Used to cancel the request.
|
|
@@ -42,18 +33,13 @@ export class BlobEndpoint extends Endpoint {
|
|
|
42
33
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
43
34
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
44
35
|
*/
|
|
45
|
-
|
|
46
|
-
const response = await this.send(HttpMethod.Get, signal);
|
|
47
|
-
return response.blob();
|
|
48
|
-
}
|
|
49
|
-
|
|
36
|
+
download(signal?: AbortSignal): Promise<Blob>;
|
|
50
37
|
/**
|
|
51
38
|
* Shows whether the server has indicated that {@link upload} is currently allowed.
|
|
52
39
|
* Uses cached data from last response.
|
|
53
40
|
* @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.
|
|
54
41
|
*/
|
|
55
|
-
get uploadAllowed()
|
|
56
|
-
|
|
42
|
+
get uploadAllowed(): boolean | undefined;
|
|
57
43
|
/**
|
|
58
44
|
* Uploads data as the blob's content.
|
|
59
45
|
* @param blob The blob to read the upload data from.
|
|
@@ -63,17 +49,13 @@ export class BlobEndpoint extends Endpoint {
|
|
|
63
49
|
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
64
50
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
65
51
|
*/
|
|
66
|
-
|
|
67
|
-
await this.send(HttpMethod.Put, signal, { [HttpHeader.ContentType]: blob.type }, blob);
|
|
68
|
-
}
|
|
69
|
-
|
|
52
|
+
uploadFrom(blob: Blob, signal?: AbortSignal): Promise<void>;
|
|
70
53
|
/**
|
|
71
54
|
* Shows whether the server has indicated that {@link delete} is currently allowed.
|
|
72
55
|
* Uses cached data from last response.
|
|
73
56
|
* @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.
|
|
74
57
|
*/
|
|
75
|
-
get deleteAllowed()
|
|
76
|
-
|
|
58
|
+
get deleteAllowed(): boolean | undefined;
|
|
77
59
|
/**
|
|
78
60
|
* Deletes the blob from the server.
|
|
79
61
|
* @param signal Used to cancel the request.
|
|
@@ -83,7 +65,5 @@ export class BlobEndpoint extends Endpoint {
|
|
|
83
65
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
84
66
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
85
67
|
*/
|
|
86
|
-
|
|
87
|
-
await this.send(HttpMethod.Delete, signal);
|
|
88
|
-
}
|
|
68
|
+
delete(signal?: AbortSignal): Promise<void>;
|
|
89
69
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { Endpoint } from "../Endpoint";
|
|
2
|
-
import { HttpMethod, HttpHeader } from "../../http";
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Endpoint that accepts binary uploads using multi-part form encoding or raw bodies.
|
|
6
4
|
*/
|
|
7
|
-
export class UploadEndpoint extends Endpoint {
|
|
5
|
+
export declare class UploadEndpoint extends Endpoint {
|
|
6
|
+
private readonly formField?;
|
|
8
7
|
/**
|
|
9
8
|
* Creates a new upload endpoint.
|
|
10
9
|
* @param referrer The endpoint used to navigate to this one.
|
|
11
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.
|
|
12
11
|
* @param formField The name of the form field to place the uploaded data into; leave unspecified to use raw bodies instead of a multi-part forms.
|
|
13
12
|
*/
|
|
14
|
-
constructor(referrer: Endpoint, relativeUri: URL | string,
|
|
15
|
-
super(referrer, relativeUri);
|
|
16
|
-
}
|
|
17
|
-
|
|
13
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, formField?: string | undefined);
|
|
18
14
|
/**
|
|
19
15
|
* Uploads data to the endpoint.
|
|
20
16
|
* @param blob The blob or file to read the upload data from.
|
|
@@ -25,15 +21,5 @@ export class UploadEndpoint extends Endpoint {
|
|
|
25
21
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
26
22
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
27
23
|
*/
|
|
28
|
-
|
|
29
|
-
const fileName = blob instanceof File ? blob.name : undefined;
|
|
30
|
-
|
|
31
|
-
if (this.formField) {
|
|
32
|
-
const formData = new FormData();
|
|
33
|
-
formData.set(this.formField, blob, fileName);
|
|
34
|
-
await this.send(HttpMethod.Post, signal, undefined, formData);
|
|
35
|
-
} else {
|
|
36
|
-
await this.send(HttpMethod.Post, signal, { [HttpHeader.ContentType]: blob.type }, blob);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
24
|
+
uploadFrom(blob: Blob | File, signal?: AbortSignal): Promise<void>;
|
|
39
25
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits for a specific amount of time.
|
|
3
|
+
* @param ms The time to wait in milliseconds.
|
|
4
|
+
* @param signal Used to cancel the wait.
|
|
5
|
+
* @returns `true` if the time has elapsed; `false` if the wait was cancelled via the `signal`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function delay(ms: number, signal?: AbortSignal): Promise<boolean>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ElementEndpoint } from "../generic/ElementEndpoint";
|
|
2
|
+
import { GenericCollectionEndpoint } from "../generic/GenericCollectionEndpoint";
|
|
3
|
+
/**
|
|
4
|
+
* Endpoint for a collection of `TEntity`s observable as an append-only stream using long-polling.<br>
|
|
5
|
+
* Use {@link StreamingCollectionEndpoint} instead if you wish to use the default {@link ElementEndpoint} type.
|
|
6
|
+
* @typeParam TEntity The type of individual elements in the collection.
|
|
7
|
+
* @typeParam TElementEndpoint The type of {@link ElementEndpoint} to provide for individual `TEntity`s.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GenericStreamingCollectionEndpoint<TEntity, TElementEndpoint extends ElementEndpoint<TEntity>> extends GenericCollectionEndpoint<TEntity, TElementEndpoint> {
|
|
10
|
+
/**
|
|
11
|
+
* The interval in milliseconds to wait between polling requests.
|
|
12
|
+
* Automatically updated whenever the server sends a {@link http!HttpHeader.RetryAfter} header.
|
|
13
|
+
*/
|
|
14
|
+
pollingInterval: number;
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
protected handle(response: Response): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Provides a stream of `TEntity`s, polling the server for elements appended to the collection.
|
|
21
|
+
* @param startIndex The index of the first element to return. Use a negative value to start with the last `-startIndex` elements ("tail").
|
|
22
|
+
* @param signal Used to stop polling.
|
|
23
|
+
* @throws {@link errors!AuthenticationError}: {@link http!HttpStatusCode.Unauthorized}
|
|
24
|
+
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
25
|
+
* @throws {@link errors!HttpError}: Other non-success status code
|
|
26
|
+
*/
|
|
27
|
+
stream(startIndex?: number, signal?: AbortSignal): AsyncIterableIterator<TEntity>;
|
|
28
|
+
/**
|
|
29
|
+
* Provides a stream of `TEntity`s using {@link stream}.
|
|
30
|
+
*/
|
|
31
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TEntity>;
|
|
32
|
+
}
|
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
import { ElementEndpoint } from "../generic/ElementEndpoint";
|
|
2
2
|
import { Endpoint } from "../Endpoint";
|
|
3
|
-
import { delay } from "./Delay";
|
|
4
|
-
import { retryAfter } from "../../http";
|
|
5
|
-
|
|
6
3
|
/**
|
|
7
4
|
* Endpoint for a resource that can be polled for state changes.
|
|
8
5
|
* @typeParam TEntity The type of entity the endpoint represents.
|
|
9
6
|
*/
|
|
10
|
-
export class PollingEndpoint<TEntity> extends ElementEndpoint<TEntity> {
|
|
7
|
+
export declare class PollingEndpoint<TEntity> extends ElementEndpoint<TEntity> {
|
|
8
|
+
private readonly endCondition?;
|
|
11
9
|
/**
|
|
12
10
|
* Creates a new polling 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
|
* @param endCondition A check to determine whether the entity has reached its final state and no further polling is required.
|
|
16
14
|
*/
|
|
17
|
-
constructor(referrer: Endpoint, relativeUri: URL | string,
|
|
18
|
-
super(referrer, relativeUri);
|
|
19
|
-
}
|
|
20
|
-
|
|
15
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, endCondition?: ((entity: TEntity) => boolean) | undefined);
|
|
21
16
|
/**
|
|
22
17
|
* The interval in milliseconds to wait between polling requests.
|
|
23
18
|
* Automatically updated whenever the server sends a {@link http!HttpHeader.RetryAfter} header.
|
|
24
19
|
*/
|
|
25
|
-
pollingInterval
|
|
26
|
-
|
|
20
|
+
pollingInterval: number;
|
|
27
21
|
/**
|
|
28
22
|
* @inheritDoc
|
|
29
23
|
*/
|
|
30
|
-
protected
|
|
31
|
-
await super.handle(response);
|
|
32
|
-
this.pollingInterval = retryAfter(response) ?? this.pollingInterval;
|
|
33
|
-
}
|
|
34
|
-
|
|
24
|
+
protected handle(response: Response): Promise<void>;
|
|
35
25
|
/**
|
|
36
26
|
* Provides a stream of the `TEntity`'s states, polling the server for changes.
|
|
37
27
|
* States that are identical to the previously provided one are skipped.
|
|
@@ -41,26 +31,9 @@ export class PollingEndpoint<TEntity> extends ElementEndpoint<TEntity> {
|
|
|
41
31
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
42
32
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
43
33
|
*/
|
|
44
|
-
|
|
45
|
-
// NOTE: Compare the serialized form because every poll deserializes a new object instance.
|
|
46
|
-
let previous: string | undefined;
|
|
47
|
-
|
|
48
|
-
while (!signal?.aborted) {
|
|
49
|
-
const entity = await this.read(signal);
|
|
50
|
-
|
|
51
|
-
const serialized = this.serializer.serialize(entity);
|
|
52
|
-
if (serialized !== previous) {
|
|
53
|
-
previous = serialized;
|
|
54
|
-
yield entity;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (this.endCondition?.(entity)) return;
|
|
58
|
-
if (!await delay(this.pollingInterval, signal)) return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
34
|
+
stream(signal?: AbortSignal): AsyncIterableIterator<TEntity>;
|
|
62
35
|
/**
|
|
63
36
|
* Provides a stream of the `TEntity`'s states using {@link stream}.
|
|
64
37
|
*/
|
|
65
|
-
[Symbol.asyncIterator]()
|
|
38
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TEntity>;
|
|
66
39
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Endpoint } from "../Endpoint";
|
|
2
|
+
/**
|
|
3
|
+
* Endpoint for a stream of `TEntity`s using Server-Sent Events (SSE).<br>
|
|
4
|
+
* Sends `Accept: text/event-stream`. By default, transparently reconnects on connection drops or transient errors,
|
|
5
|
+
* honoring the server-supplied `retry:` interval and resuming via the {@link http!HttpHeader.LastEventId} header.
|
|
6
|
+
* @typeParam TEntity The type of individual elements in the stream.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SseStreamingEndpoint<TEntity> extends Endpoint {
|
|
9
|
+
private readonly eventType?;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new SSE streaming endpoint.
|
|
12
|
+
* @param referrer The endpoint used to navigate to this one.
|
|
13
|
+
* @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
|
+
* @param eventType If set, only events with this `event:` type are provided; others are ignored. Leave unspecified to provide all events.
|
|
15
|
+
*/
|
|
16
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, eventType?: string | undefined);
|
|
17
|
+
/**
|
|
18
|
+
* Whether to transparently reconnect on connection drops, transient transport errors and 5xx responses.
|
|
19
|
+
*/
|
|
20
|
+
autoReconnect: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The reconnection interval in milliseconds used when the server has not (yet) supplied one via the SSE `retry:` field.
|
|
23
|
+
*/
|
|
24
|
+
defaultReconnectionInterval: number;
|
|
25
|
+
/**
|
|
26
|
+
* Provides a stream of `TEntity`s, reconnecting as needed unless {@link autoReconnect} is disabled.
|
|
27
|
+
* @param signal Used to close the connection.
|
|
28
|
+
* @throws {@link errors!AuthenticationError}: {@link http!HttpStatusCode.Unauthorized}
|
|
29
|
+
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
30
|
+
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
31
|
+
* @throws {@link errors!HttpError}: Other non-success status code
|
|
32
|
+
*/
|
|
33
|
+
stream(signal?: AbortSignal): AsyncIterableIterator<TEntity>;
|
|
34
|
+
/**
|
|
35
|
+
* Provides a stream of `TEntity`s using {@link stream}.
|
|
36
|
+
*/
|
|
37
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TEntity>;
|
|
38
|
+
/**
|
|
39
|
+
* Opens a connection and provides events until the stream ends.
|
|
40
|
+
* @param state Carries the last event id and the reconnection interval over to the next attempt.
|
|
41
|
+
* @param signal Used to close the connection.
|
|
42
|
+
* @returns `true` if another connection attempt should be made; `false` if the stream has ended for good.
|
|
43
|
+
*/
|
|
44
|
+
private consumeOnce;
|
|
45
|
+
/**
|
|
46
|
+
* Determines whether an error is a transport-level failure that may succeed on a retry.
|
|
47
|
+
* The Fetch API reports these as `TypeError`s, while responses the server actually sent become {@link errors!HttpError}s.
|
|
48
|
+
*/
|
|
49
|
+
private static isTransient;
|
|
50
|
+
}
|
package/endpoints/reactive/{StreamingCollectionEndpoint.ts → StreamingCollectionEndpoint.d.ts}
RENAMED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { GenericStreamingCollectionEndpoint } from "./GenericStreamingCollectionEndpoint";
|
|
2
2
|
import { ElementEndpoint } from "../generic/ElementEndpoint";
|
|
3
3
|
import { Endpoint } from "../Endpoint";
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Endpoint for a collection of `TEntity`s observable as an append-only stream using long-polling,
|
|
7
6
|
* addressable as {@link ElementEndpoint}s.<br>
|
|
8
7
|
* Use {@link GenericStreamingCollectionEndpoint} instead if you wish to customize the element endpoint type.
|
|
9
8
|
* @typeParam TEntity The type of individual elements in the collection.
|
|
10
9
|
*/
|
|
11
|
-
export class StreamingCollectionEndpoint<TEntity> extends GenericStreamingCollectionEndpoint<TEntity, ElementEndpoint<TEntity>> {
|
|
10
|
+
export declare class StreamingCollectionEndpoint<TEntity> extends GenericStreamingCollectionEndpoint<TEntity, ElementEndpoint<TEntity>> {
|
|
12
11
|
/**
|
|
13
12
|
* Creates a new streaming collection endpoint.
|
|
14
13
|
* @param referrer The endpoint used to navigate to this one.
|
|
15
14
|
* @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.
|
|
16
15
|
*/
|
|
17
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
18
|
-
super(referrer, relativeUri, ElementEndpoint);
|
|
19
|
-
}
|
|
16
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
20
17
|
}
|