typedrest 0.4.1 → 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 +42 -4
- package/endpoints/{CachingEndpoint.ts → CachingEndpoint.d.ts} +0 -1
- package/endpoints/Endpoint.d.ts +121 -0
- package/endpoints/Endpoint.js +9 -22
- package/endpoints/{EntryEndpoint.ts → EntryEndpoint.d.ts} +7 -27
- package/endpoints/EntryEndpoint.js +3 -14
- package/endpoints/generic/{CollectionEndpoint.ts → CollectionEndpoint.d.ts} +2 -5
- package/endpoints/generic/{ETagEndpointBase.ts → ETagEndpointBase.d.ts} +7 -38
- package/endpoints/generic/ETagEndpointBase.js +27 -42
- package/endpoints/generic/{ElementEndpoint.ts → ElementEndpoint.d.ts} +12 -70
- package/endpoints/generic/ElementEndpoint.js +39 -60
- package/endpoints/generic/{GenericCollectionEndpoint.ts → GenericCollectionEndpoint.d.ts} +43 -75
- package/endpoints/generic/GenericCollectionEndpoint.js +70 -44
- package/endpoints/generic/{IndexerEndpoint.ts → IndexerEndpoint.d.ts} +4 -11
- package/endpoints/generic/PartialResponse.d.ts +19 -0
- package/endpoints/generic/PartialResponse.js +33 -0
- package/endpoints/generic/{index.ts → index.d.ts} +1 -0
- package/endpoints/generic/index.js +2 -1
- package/endpoints/{index.ts → index.d.ts} +2 -2
- package/endpoints/index.js +3 -2
- package/endpoints/raw/{BlobEndpoint.ts → BlobEndpoint.d.ts} +9 -29
- package/endpoints/raw/BlobEndpoint.js +10 -27
- package/endpoints/raw/{UploadEndpoint.ts → UploadEndpoint.d.ts} +4 -18
- package/endpoints/raw/UploadEndpoint.js +11 -22
- package/endpoints/reactive/Delay.d.ts +7 -0
- package/endpoints/reactive/Delay.js +27 -0
- package/endpoints/reactive/GenericStreamingCollectionEndpoint.d.ts +32 -0
- package/endpoints/reactive/GenericStreamingCollectionEndpoint.js +79 -0
- package/endpoints/reactive/PollingEndpoint.d.ts +39 -0
- package/endpoints/reactive/PollingEndpoint.js +67 -0
- package/endpoints/reactive/SseStreamingEndpoint.d.ts +50 -0
- package/endpoints/reactive/SseStreamingEndpoint.js +120 -0
- package/endpoints/reactive/StreamingCollectionEndpoint.d.ts +17 -0
- package/endpoints/reactive/StreamingCollectionEndpoint.js +23 -0
- package/endpoints/reactive/StreamingEndpoint.d.ts +28 -0
- package/endpoints/reactive/StreamingEndpoint.js +56 -0
- package/endpoints/reactive/index.d.ts +5 -0
- package/endpoints/reactive/index.js +22 -0
- package/endpoints/rpc/{ActionEndpoint.ts → ActionEndpoint.d.ts} +3 -10
- package/endpoints/rpc/ActionEndpoint.js +3 -14
- package/endpoints/rpc/{ConsumerEndpoint.ts → ConsumerEndpoint.d.ts} +3 -12
- package/endpoints/rpc/ConsumerEndpoint.js +5 -16
- package/endpoints/rpc/{FunctionEndpoint.ts → FunctionEndpoint.d.ts} +3 -14
- package/endpoints/rpc/FunctionEndpoint.js +6 -17
- package/endpoints/rpc/{ProducerEndpoint.ts → ProducerEndpoint.d.ts} +3 -11
- package/endpoints/rpc/ProducerEndpoint.js +4 -15
- package/endpoints/rpc/{RpcEndpointBase.ts → RpcEndpointBase.d.ts} +4 -12
- package/endpoints/rpc/RpcEndpointBase.js +3 -14
- package/errors/DefaultErrorHandler.d.ts +21 -0
- package/errors/DefaultErrorHandler.js +19 -27
- package/errors/{Errors.ts → Errors.d.ts} +23 -19
- package/errors/Errors.js +8 -2
- package/http/EntityStream.d.ts +10 -0
- package/http/EntityStream.js +42 -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/HttpContentRange.js +39 -0
- package/http/HttpHeader.d.ts +16 -0
- package/http/HttpHeader.js +6 -1
- package/http/{HttpMethod.ts → HttpMethod.d.ts} +1 -1
- package/http/{HttpStatusCode.ts → HttpStatusCode.d.ts} +5 -2
- package/http/HttpStatusCode.js +4 -1
- package/http/ResponseCache.d.ts +19 -0
- package/http/ResponseCache.js +4 -15
- package/http/RetryAfter.d.ts +6 -0
- package/http/RetryAfter.js +24 -0
- package/http/ServerSentEvents.d.ts +50 -0
- package/http/ServerSentEvents.js +140 -0
- package/http/{index.ts → index.d.ts} +4 -0
- package/http/index.js +5 -1
- package/links/AggregateLinkExtractor.d.ts +17 -0
- package/links/AggregateLinkExtractor.js +7 -18
- package/links/HalLinkExtractor.d.ts +13 -0
- package/links/HalLinkExtractor.js +9 -20
- package/links/HeaderLinkExtractor.d.ts +13 -0
- package/links/HeaderLinkExtractor.js +4 -15
- package/links/{Link.ts → Link.d.ts} +6 -2
- package/links/{LinkExtractor.ts → LinkExtractor.d.ts} +0 -1
- package/package.json +66 -16
- 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/IndexerEndpoint.test.ts +0 -12
- package/endpoints/raw/BlobEndpoint.test.ts +0 -52
- package/endpoints/raw/UploadEndpoint.test.ts +0 -47
- 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 -62
- package/http/FetchHttpClient.ts +0 -26
- package/http/HttpHeader.ts +0 -11
- package/http/ResponseCache.ts +0 -25
- 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/raw/{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/{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,31 +1,20 @@
|
|
|
1
1
|
import { ETagEndpointBase } from "./ETagEndpointBase";
|
|
2
2
|
import { Endpoint } from "../Endpoint";
|
|
3
|
-
import { HttpMethod, HttpHeader, HttpStatusCode } from "../../http";
|
|
4
|
-
import { ConcurrencyError } from "../../errors";
|
|
5
|
-
|
|
6
3
|
/**
|
|
7
4
|
* Endpoint for an individual resource.
|
|
8
5
|
* @typeParam TEntity The type of entity the endpoint represents.
|
|
9
6
|
*/
|
|
10
|
-
export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
7
|
+
export declare class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
11
8
|
/**
|
|
12
9
|
* Creates a new element endpoint.
|
|
13
10
|
* @param referrer The endpoint used to navigate to this one.
|
|
14
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.
|
|
15
12
|
*/
|
|
16
|
-
constructor(referrer: Endpoint, relativeUri: URL | string)
|
|
17
|
-
super(referrer, relativeUri);
|
|
18
|
-
}
|
|
19
|
-
|
|
13
|
+
constructor(referrer: Endpoint, relativeUri: URL | string);
|
|
20
14
|
/**
|
|
21
15
|
* A cached copy of the entity as received from the server.
|
|
22
16
|
*/
|
|
23
|
-
|
|
24
|
-
return this.responseCache
|
|
25
|
-
? this.serializer.deserialize<TEntity>(this.responseCache.content)
|
|
26
|
-
: undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
17
|
+
get response(): TEntity | undefined;
|
|
29
18
|
/**
|
|
30
19
|
* Returns the `TEntity`.
|
|
31
20
|
* @param signal Used to cancel the request.
|
|
@@ -34,10 +23,7 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
|
34
23
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
35
24
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
36
25
|
*/
|
|
37
|
-
|
|
38
|
-
return this.serializer.deserialize<TEntity>(await this.getContent(signal));
|
|
39
|
-
}
|
|
40
|
-
|
|
26
|
+
read(signal?: AbortSignal): Promise<TEntity>;
|
|
41
27
|
/**
|
|
42
28
|
* Determines whether the element currently exists.
|
|
43
29
|
* @param signal Used to cancel the request.
|
|
@@ -45,22 +31,13 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
|
45
31
|
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
46
32
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
47
33
|
*/
|
|
48
|
-
|
|
49
|
-
const response = await this.httpClient.send(this.uri, HttpMethod.Head, signal);
|
|
50
|
-
if (response.ok) return true;
|
|
51
|
-
if (response.status === HttpStatusCode.NotFound || response.status === HttpStatusCode.Gone) return false;
|
|
52
|
-
|
|
53
|
-
await this.errorHandler.handle(response);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
34
|
+
exists(signal?: AbortSignal): Promise<boolean>;
|
|
57
35
|
/**
|
|
58
36
|
* Shows whether the server has indicated that {@link set} is currently allowed.
|
|
59
37
|
* Uses cached data from last response.
|
|
60
38
|
* @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.
|
|
61
39
|
*/
|
|
62
|
-
get setAllowed()
|
|
63
|
-
|
|
40
|
+
get setAllowed(): boolean | undefined;
|
|
64
41
|
/**
|
|
65
42
|
* Sets/replaces the `TEntity`.
|
|
66
43
|
* @param entity The new `TEntity`.
|
|
@@ -73,21 +50,13 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
|
73
50
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
74
51
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
75
52
|
*/
|
|
76
|
-
|
|
77
|
-
const response = await this.putContent(entity, signal);
|
|
78
|
-
const text = await response.text();
|
|
79
|
-
if (text) {
|
|
80
|
-
return this.serializer.deserialize<TEntity>(text);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
53
|
+
set(entity: TEntity, signal?: AbortSignal): Promise<(TEntity | undefined)>;
|
|
84
54
|
/**
|
|
85
55
|
* Shows whether the server has indicated that {@link merge} is currently allowed.
|
|
86
56
|
* Uses cached data from last response.
|
|
87
57
|
* @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.
|
|
88
58
|
*/
|
|
89
|
-
get mergeAllowed()
|
|
90
|
-
|
|
59
|
+
get mergeAllowed(): boolean | undefined;
|
|
91
60
|
/**
|
|
92
61
|
* Modifies an existing `TEntity` by merging changes on the server-side.
|
|
93
62
|
* @param entity The `TEntity` data to merge with the existing element.
|
|
@@ -100,18 +69,7 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
|
100
69
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
101
70
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
102
71
|
*/
|
|
103
|
-
|
|
104
|
-
this.responseCache = undefined;
|
|
105
|
-
const response = await this.send(HttpMethod.Patch, signal, {
|
|
106
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
107
|
-
}, this.serializer.serialize(entity));
|
|
108
|
-
|
|
109
|
-
const text = await response.text();
|
|
110
|
-
if (text) {
|
|
111
|
-
return this.serializer.deserialize<TEntity>(text);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
72
|
+
merge(entity: TEntity, signal?: AbortSignal): Promise<(TEntity | undefined)>;
|
|
115
73
|
/**
|
|
116
74
|
* Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.
|
|
117
75
|
* @param updateAction A callback that takes the current state of the entity and applies the desired modifications.
|
|
@@ -125,27 +83,13 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
|
125
83
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
126
84
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
127
85
|
*/
|
|
128
|
-
|
|
129
|
-
let retryCounter = 0;
|
|
130
|
-
while (true) {
|
|
131
|
-
const entity = await this.read(signal);
|
|
132
|
-
updateAction(entity);
|
|
133
|
-
try {
|
|
134
|
-
return await this.set(entity, signal);
|
|
135
|
-
} catch (err) {
|
|
136
|
-
if (retryCounter++ >= maxRetries || !(err instanceof ConcurrencyError))
|
|
137
|
-
throw err;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
86
|
+
update(updateAction: (entity: TEntity) => void, maxRetries?: number, signal?: AbortSignal): Promise<(TEntity | undefined)>;
|
|
142
87
|
/**
|
|
143
88
|
* Shows whether the server has indicated that {@link delete} is currently allowed.
|
|
144
89
|
* Uses cached data from last response.
|
|
145
90
|
* @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.
|
|
146
91
|
*/
|
|
147
|
-
get deleteAllowed()
|
|
148
|
-
|
|
92
|
+
get deleteAllowed(): boolean | undefined;
|
|
149
93
|
/**
|
|
150
94
|
* Deletes the element.
|
|
151
95
|
* @param signal Used to cancel the request.
|
|
@@ -155,7 +99,5 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
|
|
|
155
99
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
156
100
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
157
101
|
*/
|
|
158
|
-
|
|
159
|
-
await this.deleteContent(signal);
|
|
160
|
-
}
|
|
102
|
+
delete(signal?: AbortSignal): Promise<void>;
|
|
161
103
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ElementEndpoint = void 0;
|
|
13
4
|
const ETagEndpointBase_1 = require("./ETagEndpointBase");
|
|
@@ -42,10 +33,8 @@ class ElementEndpoint extends ETagEndpointBase_1.ETagEndpointBase {
|
|
|
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
|
-
read(signal) {
|
|
46
|
-
return
|
|
47
|
-
return this.serializer.deserialize(yield this.getContent(signal));
|
|
48
|
-
});
|
|
36
|
+
async read(signal) {
|
|
37
|
+
return this.serializer.deserialize(await this.getContent(signal));
|
|
49
38
|
}
|
|
50
39
|
/**
|
|
51
40
|
* Determines whether the element currently exists.
|
|
@@ -54,16 +43,14 @@ class ElementEndpoint extends ETagEndpointBase_1.ETagEndpointBase {
|
|
|
54
43
|
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
55
44
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
56
45
|
*/
|
|
57
|
-
exists(signal) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (response.status === http_1.HttpStatusCode.NotFound || response.status === http_1.HttpStatusCode.Gone)
|
|
63
|
-
return false;
|
|
64
|
-
yield this.errorHandler.handle(response);
|
|
46
|
+
async exists(signal) {
|
|
47
|
+
const response = await this.httpClient.send(this.uri, http_1.HttpMethod.Head, signal);
|
|
48
|
+
if (response.ok)
|
|
49
|
+
return true;
|
|
50
|
+
if (response.status === http_1.HttpStatusCode.NotFound || response.status === http_1.HttpStatusCode.Gone)
|
|
65
51
|
return false;
|
|
66
|
-
|
|
52
|
+
await this.errorHandler.handle(response);
|
|
53
|
+
return false;
|
|
67
54
|
}
|
|
68
55
|
/**
|
|
69
56
|
* Shows whether the server has indicated that {@link set} is currently allowed.
|
|
@@ -83,14 +70,12 @@ class ElementEndpoint extends ETagEndpointBase_1.ETagEndpointBase {
|
|
|
83
70
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
84
71
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
85
72
|
*/
|
|
86
|
-
set(entity, signal) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
});
|
|
73
|
+
async set(entity, signal) {
|
|
74
|
+
const response = await this.putContent(entity, signal);
|
|
75
|
+
const text = await response.text();
|
|
76
|
+
if (text) {
|
|
77
|
+
return this.serializer.deserialize(text);
|
|
78
|
+
}
|
|
94
79
|
}
|
|
95
80
|
/**
|
|
96
81
|
* Shows whether the server has indicated that {@link merge} is currently allowed.
|
|
@@ -110,17 +95,15 @@ class ElementEndpoint extends ETagEndpointBase_1.ETagEndpointBase {
|
|
|
110
95
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
111
96
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
112
97
|
*/
|
|
113
|
-
merge(entity, signal) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
});
|
|
98
|
+
async merge(entity, signal) {
|
|
99
|
+
this.responseCache = undefined;
|
|
100
|
+
const response = await this.send(http_1.HttpMethod.Patch, signal, {
|
|
101
|
+
[http_1.HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
102
|
+
}, this.serializer.serialize(entity));
|
|
103
|
+
const text = await response.text();
|
|
104
|
+
if (text) {
|
|
105
|
+
return this.serializer.deserialize(text);
|
|
106
|
+
}
|
|
124
107
|
}
|
|
125
108
|
/**
|
|
126
109
|
* Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.
|
|
@@ -135,21 +118,19 @@ class ElementEndpoint extends ETagEndpointBase_1.ETagEndpointBase {
|
|
|
135
118
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
136
119
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
137
120
|
*/
|
|
138
|
-
update(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
throw err;
|
|
150
|
-
}
|
|
121
|
+
async update(updateAction, maxRetries = 3, signal) {
|
|
122
|
+
let retryCounter = 0;
|
|
123
|
+
while (true) {
|
|
124
|
+
const entity = await this.read(signal);
|
|
125
|
+
updateAction(entity);
|
|
126
|
+
try {
|
|
127
|
+
return await this.set(entity, signal);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
if (retryCounter++ >= maxRetries || !(err instanceof errors_1.ConcurrencyError))
|
|
131
|
+
throw err;
|
|
151
132
|
}
|
|
152
|
-
}
|
|
133
|
+
}
|
|
153
134
|
}
|
|
154
135
|
/**
|
|
155
136
|
* Shows whether the server has indicated that {@link delete} is currently allowed.
|
|
@@ -166,11 +147,9 @@ class ElementEndpoint extends ETagEndpointBase_1.ETagEndpointBase {
|
|
|
166
147
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
167
148
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
168
149
|
*/
|
|
169
|
-
delete(signal) {
|
|
170
|
-
|
|
171
|
-
yield this.deleteContent(signal);
|
|
172
|
-
});
|
|
150
|
+
async delete(signal) {
|
|
151
|
+
await this.deleteContent(signal);
|
|
173
152
|
}
|
|
174
153
|
}
|
|
175
154
|
exports.ElementEndpoint = ElementEndpoint;
|
|
176
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
155
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRWxlbWVudEVuZHBvaW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiRWxlbWVudEVuZHBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlEQUFzRDtBQUV0RCxxQ0FBb0U7QUFDcEUseUNBQWdEO0FBRWhEOzs7R0FHRztBQUNILE1BQWEsZUFBeUIsU0FBUSxtQ0FBZ0I7SUFDMUQ7Ozs7T0FJRztJQUNILFlBQVksUUFBa0IsRUFBRSxXQUF5QjtRQUNyRCxLQUFLLENBQUMsUUFBUSxFQUFFLFdBQVcsQ0FBQyxDQUFDO0lBQ2pDLENBQUM7SUFFRDs7T0FFRztJQUNILElBQVcsUUFBUTtRQUNmLE9BQU8sSUFBSSxDQUFDLGFBQWE7WUFDckIsQ0FBQyxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsV0FBVyxDQUFVLElBQUksQ0FBQyxhQUFhLENBQUMsT0F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LENBQUMsTUFBTSxDQUFDLFlBQXVDLEVBQUUsYUFBcUIsQ0FBQyxFQUFFLE1BQW9CO1FBQzlGLElBQUksWUFBWSxHQUFHLENBQUMsQ0FBQztRQUNyQixPQUFPLElBQUksRUFBRSxDQUFDO1lBQ1YsTUFBTSxNQUFNLEdBQUcsTUFBTSxJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxDQUFDO1lBQ3ZDLFlBQVksQ0FBQyxNQUFNLENBQUMsQ0FBQztZQUNyQixJQUFJLENBQUM7Z0JBQ0QsT0FBTyxNQUFNLElBQUksQ0FBQyxHQUFHLENBQUMsTUFBTSxFQUFFLE1BQU0sQ0FBQyxDQUFDO1lBQzFDLENBQUM7WUFBQyxPQUFPLEdBQUcsRUFBRSxDQUFDO2dCQUNYLElBQUksWUFBWSxFQUFFLElBQUksVUFBVSxJQUFJLENBQUMsQ0FBQyxHQUFHLFlBQVkseUJBQWdCLENBQUM7b0JBQ2xFLE1BQU0sR0FBRyxDQUFDO1lBQ2xCLENBQUM7UUFDTCxDQUFDO0lBQ0wsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxJQUFJLGFBQWEsS0FBSyxPQUFPLElBQUksQ0FBQyxlQUFlLENBQUMsaUJBQVUsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFFdkU7Ozs7Ozs7O09BUUc7SUFDSCxLQUFLLENBQUMsTUFBTSxDQUFDLE1BQW9CO1FBQzdCLE1BQU0sSUFBSSxDQUFDLGFBQWEsQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNyQyxDQUFDO0NBQ0o7QUF2SkQsMENBdUpDIn0=
|
|
@@ -1,53 +1,33 @@
|
|
|
1
1
|
import { ETagEndpointBase } from "./ETagEndpointBase";
|
|
2
2
|
import { ElementEndpoint } from "./ElementEndpoint";
|
|
3
|
+
import { PartialResponse } from "./PartialResponse";
|
|
3
4
|
import { Endpoint } from "../Endpoint";
|
|
4
|
-
import { CachingEndpoint } from "../CachingEndpoint";
|
|
5
|
-
import { HttpMethod, HttpHeader, ResponseCache } from "../../http";
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* Endpoint for a collection of `TEntity`s addressable as `TElementEndpoint`s.<br>
|
|
9
7
|
* Use {@link CollectionEndpoint} instead if you wish to use the default {@link ElementEndpoint} type.
|
|
10
8
|
* @typeParam TEntity The type of individual elements in the collection.
|
|
11
9
|
* @typeParam TElementEndpoint The type of {@link ElementEndpoint} to provide for individual `TEntity`s.
|
|
12
10
|
*/
|
|
13
|
-
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;
|
|
14
13
|
/**
|
|
15
14
|
* Creates a new collection endpoint.
|
|
16
15
|
* @param referrer The endpoint used to navigate to this one.
|
|
17
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.
|
|
18
17
|
* @param elementEndpoint A factory method for creating instances of `TElementEndpoint`.
|
|
19
18
|
*/
|
|
20
|
-
constructor(referrer: Endpoint, relativeUri: URL | string,
|
|
21
|
-
super(referrer, relativeUri);
|
|
22
|
-
this.setDefaultLinkTemplate("child", "./{id}");
|
|
23
|
-
}
|
|
24
|
-
|
|
19
|
+
constructor(referrer: Endpoint, relativeUri: URL | string, elementEndpoint: new (referrer: Endpoint, uri: URL) => TElementEndpoint);
|
|
25
20
|
/**
|
|
26
21
|
* Returns an `TElementEndpoint` for a specific child element.
|
|
27
22
|
* @param element The ID identifying the entity or an entity to extract the ID from.
|
|
28
23
|
*/
|
|
29
|
-
get(element: (TEntity | string)): TElementEndpoint
|
|
30
|
-
if (element == null) throw new Error("element must not be null or unspecified.");
|
|
31
|
-
|
|
32
|
-
let id: string;
|
|
33
|
-
if (typeof element === "string") {
|
|
34
|
-
id = element;
|
|
35
|
-
} else {
|
|
36
|
-
id = (element as any).id;
|
|
37
|
-
if (id === undefined) throw new Error(`Element ${element} does not have an id property.`);
|
|
38
|
-
}
|
|
39
|
-
if (id == null || id === "") throw new Error("id must not be null or empty.");
|
|
40
|
-
|
|
41
|
-
return new this.elementEndpoint(this, this.linkTemplate("child", { id }));
|
|
42
|
-
}
|
|
43
|
-
|
|
24
|
+
get(element: (TEntity | string)): TElementEndpoint;
|
|
44
25
|
/**
|
|
45
26
|
* Shows whether the server has indicated that {@link readAll} is currently allowed.
|
|
46
27
|
* Uses cached data from last response.
|
|
47
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.
|
|
48
29
|
*/
|
|
49
|
-
get readAllAllowed()
|
|
50
|
-
|
|
30
|
+
get readAllAllowed(): boolean | undefined;
|
|
51
31
|
/**
|
|
52
32
|
* Returns all `TEntity`s in the collection.
|
|
53
33
|
* @param signal Used to cancel the request.
|
|
@@ -56,17 +36,39 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
56
36
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
57
37
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
58
38
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
39
|
+
readAll(signal?: AbortSignal): Promise<TEntity[]>;
|
|
40
|
+
/**
|
|
41
|
+
* The unit used when requesting ranges of elements. Sent in the {@link http!HttpHeader.Range} header.
|
|
42
|
+
*/
|
|
43
|
+
rangeUnit: string;
|
|
44
|
+
private acceptedRangeUnits;
|
|
45
|
+
/**
|
|
46
|
+
* @inheritDoc
|
|
47
|
+
*/
|
|
48
|
+
protected handleCapabilities(response: Response): void;
|
|
49
|
+
/**
|
|
50
|
+
* Shows whether the server has indicated that {@link readRange} is currently allowed.
|
|
51
|
+
* Uses cached data from last response.
|
|
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.
|
|
53
|
+
*/
|
|
54
|
+
get readRangeAllowed(): boolean | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Returns a subset of the `TEntity`s in the collection.
|
|
57
|
+
* @param from The index of the first element to return. Leave unspecified to return the last `to` elements ("tail").
|
|
58
|
+
* @param to The index of the last element to return. Leave unspecified to return all elements starting at `from`.
|
|
59
|
+
* @param signal Used to cancel the request.
|
|
60
|
+
* @throws {@link errors!AuthenticationError}: {@link http!HttpStatusCode.Unauthorized}
|
|
61
|
+
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
62
|
+
* @throws {@link errors!RangeNotSatisfiableError}: {@link http!HttpStatusCode.RangeNotSatisfiable}, i.e. the requested range lies outside of the elements currently available
|
|
63
|
+
* @throws {@link errors!HttpError}: Other non-success status code
|
|
64
|
+
*/
|
|
65
|
+
readRange(from?: number, to?: number, signal?: AbortSignal): Promise<PartialResponse<TEntity>>;
|
|
63
66
|
/**
|
|
64
67
|
* Shows whether the server has indicated that {@link create} is currently allowed.
|
|
65
68
|
* Uses cached data from last response.
|
|
66
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.
|
|
67
70
|
*/
|
|
68
|
-
get createAllowed()
|
|
69
|
-
|
|
71
|
+
get createAllowed(): boolean | undefined;
|
|
70
72
|
/**
|
|
71
73
|
* Adds a `TEntity` as a new element to the collection.
|
|
72
74
|
* @param entity The new `TEntity`.
|
|
@@ -78,37 +80,13 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
78
80
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
79
81
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
80
82
|
*/
|
|
81
|
-
|
|
82
|
-
const response = await this.send(HttpMethod.Post, signal, {
|
|
83
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
84
|
-
}, this.serializer.serialize(entity));
|
|
85
|
-
const location = response.headers.get(HttpHeader.Location);
|
|
86
|
-
|
|
87
|
-
let elementEndpoint: TElementEndpoint;
|
|
88
|
-
if (location) {
|
|
89
|
-
// Explicit element endpoint URL from "Location" header
|
|
90
|
-
elementEndpoint = new this.elementEndpoint(this, this.join(location));
|
|
91
|
-
} else {
|
|
92
|
-
try {
|
|
93
|
-
// Infer URL from entity ID in response body
|
|
94
|
-
elementEndpoint = this.get(this.serializer.deserialize(await response.clone().text()));
|
|
95
|
-
} catch {
|
|
96
|
-
// No element endpoint
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
(elementEndpoint as CachingEndpoint).responseCache = await ResponseCache.from(response);
|
|
102
|
-
return elementEndpoint;
|
|
103
|
-
}
|
|
104
|
-
|
|
83
|
+
create(entity: TEntity, signal?: AbortSignal): Promise<TElementEndpoint | undefined>;
|
|
105
84
|
/**
|
|
106
85
|
* Shows whether the server has indicated that {@link createAll} is currently allowed.
|
|
107
86
|
* Uses cached data from last response.
|
|
108
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.
|
|
109
88
|
*/
|
|
110
|
-
get createAllAllowed()
|
|
111
|
-
|
|
89
|
+
get createAllAllowed(): boolean | undefined;
|
|
112
90
|
/**
|
|
113
91
|
* Adds (or updates) multiple `TEntity`s as elements in the collection.
|
|
114
92
|
* @param entities The `TEntity`s to create or modify.
|
|
@@ -119,19 +97,13 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
119
97
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
120
98
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
121
99
|
*/
|
|
122
|
-
|
|
123
|
-
await this.send(HttpMethod.Patch, signal, {
|
|
124
|
-
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
|
|
125
|
-
}, this.serializer.serialize(entities));
|
|
126
|
-
}
|
|
127
|
-
|
|
100
|
+
createAll(entities: TEntity[], signal?: AbortSignal): Promise<void>;
|
|
128
101
|
/**
|
|
129
102
|
* Shows whether the server has indicated that {@link setAll} is currently allowed.
|
|
130
103
|
* Uses cached data from last response.
|
|
131
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.
|
|
132
105
|
*/
|
|
133
|
-
get setAllAllowed()
|
|
134
|
-
|
|
106
|
+
get setAllAllowed(): boolean | undefined;
|
|
135
107
|
/**
|
|
136
108
|
* Replaces the entire content of the collection with new `TEntity`s.
|
|
137
109
|
* @param entities The `TEntity`s to create or modify.
|
|
@@ -141,8 +113,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
141
113
|
* @throws {@link errors!ConflictError}: {@link http!HttpStatusCode.Conflict}
|
|
142
114
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
143
115
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
116
|
+
setAll(entities: TEntity[]): Promise<void>;
|
|
146
117
|
/**
|
|
147
118
|
* Determines whether the collection contains a specific element.
|
|
148
119
|
* @param element The ID identifying the entity or an entity to extract the ID from.
|
|
@@ -150,8 +121,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
150
121
|
* @throws {@link errors!AuthorizationError}: {@link http!HttpStatusCode.Forbidden}
|
|
151
122
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
152
123
|
*/
|
|
153
|
-
contains(element: (TEntity | string))
|
|
154
|
-
|
|
124
|
+
contains(element: (TEntity | string)): Promise<boolean>;
|
|
155
125
|
/**
|
|
156
126
|
* Sets/replaces an existing element in the collection.
|
|
157
127
|
* @param element The new state of the element.
|
|
@@ -162,8 +132,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
162
132
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
163
133
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
164
134
|
*/
|
|
165
|
-
set(element: TEntity)
|
|
166
|
-
|
|
135
|
+
set(element: TEntity): Promise<TEntity | undefined>;
|
|
167
136
|
/**
|
|
168
137
|
* Modifies an existing element in the collection by merging changes on the server-side.
|
|
169
138
|
* @param element The `TEntity` data to merge with the existing element.
|
|
@@ -174,8 +143,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
174
143
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
175
144
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
176
145
|
*/
|
|
177
|
-
merge(element: TEntity)
|
|
178
|
-
|
|
146
|
+
merge(element: TEntity): Promise<TEntity | undefined>;
|
|
179
147
|
/**
|
|
180
148
|
* Deletes an existing element from the collection.
|
|
181
149
|
* @param element The ID identifying the entity or an entity to extract the ID from.
|
|
@@ -184,5 +152,5 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
|
|
|
184
152
|
* @throws {@link errors!NotFoundError}: {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}
|
|
185
153
|
* @throws {@link errors!HttpError}: Other non-success status code
|
|
186
154
|
*/
|
|
187
|
-
delete(element: (TEntity | string))
|
|
155
|
+
delete(element: (TEntity | string)): Promise<void>;
|
|
188
156
|
}
|