Skip to content

Commit 01e69f2

Browse files
committed
Improved return type definitions
1 parent efa6627 commit 01e69f2

17 files changed

Lines changed: 60 additions & 104 deletions

endpoints/Endpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class Endpoint {
226226
* Shows whether the server has indicated that a specific HTTP method is currently allowed.
227227
* Uses cached data from last response.
228228
* @param method The HTTP methods (e.g. GET, POST, ...) to check.
229-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
229+
* @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.
230230
*/
231231
protected isMethodAllowed(method: HttpMethod): boolean | undefined {
232232
if (this.allowedMethods.length === 0)

endpoints/EntryEndpoint.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,5 @@ export class EntryEndpoint extends Endpoint {
4141
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
4242
* @throws {@link HttpError}: Other non-success status code
4343
*/
44-
async readMeta(): Promise<void> {
45-
await this.send(HttpMethod.Get);
46-
}
44+
async readMeta() { await this.send(HttpMethod.Get); }
4745
}

endpoints/generic/CollectionEndpoint.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,31 @@ export class CollectionEndpoint<TEntity> extends GenericCollectionEndpoint<TEnti
2222
* @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden}
2323
* @throws {@link HttpError}: Other non-success status code
2424
*/
25-
contains(element: (TEntity | string)): Promise<boolean> {
26-
return this.get(element).exists();
27-
}
25+
contains(element: (TEntity | string)) { return this.get(element).exists(); }
2826

2927
/**
3028
* Sets/replaces an existing element in the collection.
3129
* @param element The new state of the element.
30+
* @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.
3231
* @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest}
3332
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
3433
* @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden}
3534
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
3635
* @throws {@link HttpError}: Other non-success status code
3736
*/
38-
set(element: TEntity): Promise<void | TEntity> {
39-
return this.get(element).set(element);
40-
}
37+
set(element: TEntity) { return this.get(element).set(element); }
4138

4239
/**
4340
* Modifies an existing element in the collection by merging changes on the server-side.
4441
* @param element The `TEntity` data to merge with the existing element.
42+
* @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.
4543
* @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest}
4644
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
4745
* @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden}
4846
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
4947
* @throws {@link HttpError}: Other non-success status code
5048
*/
51-
merge(element: TEntity): Promise<void | TEntity> {
52-
return this.get(element).merge(element);
53-
}
49+
merge(element: TEntity) { return this.get(element).merge(element); }
5450

5551
/**
5652
* Deletes an existing element from the collection.
@@ -60,7 +56,5 @@ export class CollectionEndpoint<TEntity> extends GenericCollectionEndpoint<TEnti
6056
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
6157
* @throws {@link HttpError}: Other non-success status code
6258
*/
63-
delete(element: (TEntity | string)): Promise<void> {
64-
return this.get(element).delete();
65-
}
59+
delete(element: (TEntity | string)) { return this.get(element).delete(); }
6660
}

endpoints/generic/ElementEndpoint.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
3333
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
3434
* @throws {@link HttpError}: Other non-success status code
3535
*/
36-
async read(): Promise<TEntity> {
37-
return this.serializer.deserialize<TEntity>(await this.getContent());
38-
}
36+
async read() { return this.serializer.deserialize<TEntity>(await this.getContent()); }
3937

4038
/**
4139
* Determines whether the element currently exists.
4240
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
4341
* @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden}
4442
* @throws {@link HttpError}: Other non-success status code
4543
*/
46-
async exists(): Promise<boolean> {
44+
async exists() {
4745
const response = await this.httpClient.send(this.uri, HttpMethod.Head);
4846
if (response.ok) return true;
4947
if (response.status === HttpStatusCode.NotFound || response.status === HttpStatusCode.Gone) return false;
@@ -55,15 +53,14 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
5553
/**
5654
* Shows whether the server has indicated that {@link set} is currently allowed.
5755
* Uses cached data from last response.
58-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
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.
5957
*/
60-
get setAllowed(): boolean | undefined {
61-
return this.isMethodAllowed(HttpMethod.Put);
62-
}
58+
get setAllowed() { return this.isMethodAllowed(HttpMethod.Put); }
6359

6460
/**
6561
* Sets/replaces the `TEntity`.
6662
* @param entity The new `TEntity`.
63+
* @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.
6764
* @throws {@link ConcurrencyError}: The entity has changed since it was last retrieved with {@link read}. Your changes were rejected to prevent a lost update.
6865
* @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest}
6966
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
@@ -82,15 +79,14 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
8279
/**
8380
* Shows whether the server has indicated that {@link merge} is currently allowed.
8481
* Uses cached data from last response.
85-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
82+
* @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.
8683
*/
87-
get mergeAllowed(): boolean | undefined {
88-
return this.isMethodAllowed(HttpMethod.Patch);
89-
}
84+
get mergeAllowed() { return this.isMethodAllowed(HttpMethod.Patch); }
9085

9186
/**
9287
* Modifies an existing `TEntity` by merging changes on the server-side.
9388
* @param entity The `TEntity` data to merge with the existing element.
89+
* @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.
9490
* @throws {@link ConcurrencyError}: The entity has changed since it was last retrieved with {@link read}. Your changes were rejected to prevent a lost update.
9591
* @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest}
9692
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
@@ -114,6 +110,7 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
114110
* Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.
115111
* @param updateAction A callback that takes the current state of the entity and applies the desired modifications.
116112
* @param maxRetries The maximum number of retries to perform for optimistic concurrency before giving up.
113+
* @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.
117114
* @throws {@link ConcurrencyError}: The maximum number of retries to perform for optimistic concurrency before giving up.
118115
* @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest}
119116
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
@@ -138,11 +135,9 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
138135
/**
139136
* Shows whether the server has indicated that {@link delete} is currently allowed.
140137
* Uses cached data from last response.
141-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
138+
* @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.
142139
*/
143-
get deleteAllowed(): boolean | undefined {
144-
return this.isMethodAllowed(HttpMethod.Delete);
145-
}
140+
get deleteAllowed() { return this.isMethodAllowed(HttpMethod.Delete); }
146141

147142
/**
148143
* Deletes the element.
@@ -152,7 +147,5 @@ export class ElementEndpoint<TEntity> extends ETagEndpointBase {
152147
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
153148
* @throws {@link HttpError}: Other non-success status code
154149
*/
155-
async delete(): Promise<void> {
156-
await this.deleteContent();
157-
}
150+
async delete() { await this.deleteContent(); }
158151
}

endpoints/generic/GenericCollectionEndpoint.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,23 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoin
3939
/**
4040
* Shows whether the server has indicated that {@link readAll} is currently allowed.
4141
* Uses cached data from last response.
42-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
42+
* @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.
4343
*/
44-
get readAllAllowed(): boolean | undefined {
45-
return this.isMethodAllowed(HttpMethod.Get);
46-
}
44+
get readAllAllowed() { return this.isMethodAllowed(HttpMethod.Get); }
4745

48-
async readAll(): Promise<TEntity[]> {
49-
return this.serializer.deserialize<TEntity[]>(await this.getContent());
50-
}
46+
async readAll() { return this.serializer.deserialize<TEntity[]>(await this.getContent()); }
5147

5248
/**
5349
* Shows whether the server has indicated that {@link create} is currently allowed.
5450
* Uses cached data from last response.
55-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
51+
* @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.
5652
*/
57-
get createAllowed(): boolean | undefined {
58-
return this.isMethodAllowed(HttpMethod.Post);
59-
}
53+
get createAllowed() { return this.isMethodAllowed(HttpMethod.Post); }
6054

6155
/**
6256
* Adds a `TEntity` as a new element to the collection.
6357
* @param entity The new `TEntity`.
58+
* @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.
6459
* @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest}
6560
* @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized}
6661
* @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden}
@@ -83,11 +78,9 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoin
8378
/**
8479
* Shows whether the server has indicated that {@link createAll} is currently allowed.
8580
* Uses cached data from last response.
86-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
81+
* @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.
8782
*/
88-
get createAllAllowed(): boolean | undefined {
89-
return this.isMethodAllowed(HttpMethod.Patch);
90-
}
83+
get createAllAllowed() { return this.isMethodAllowed(HttpMethod.Patch); }
9184

9285
/**
9386
* Adds (or updates) multiple `TEntity`s as elements in the collection.
@@ -98,7 +91,7 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoin
9891
* @throws {@link ConflictError}: {@link HttpStatusCode.Conflict}
9992
* @throws {@link HttpError}: Other non-success status code
10093
*/
101-
async createAll(entities: TEntity[]): Promise<void> {
94+
async createAll(entities: TEntity[]) {
10295
await this.send(HttpMethod.Patch, {
10396
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
10497
}, this.serializer.serialize(entities));
@@ -107,11 +100,9 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoin
107100
/**
108101
* Shows whether the server has indicated that {@link setAll} is currently allowed.
109102
* Uses cached data from last response.
110-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
103+
* @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.
111104
*/
112-
get setAllAllowed(): boolean | undefined {
113-
return this.isMethodAllowed(HttpMethod.Put);
114-
}
105+
get setAllAllowed() { return this.isMethodAllowed(HttpMethod.Put); }
115106

116107
/**
117108
* Replaces the entire content of the collection with new `TEntity`s.
@@ -122,7 +113,5 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoin
122113
* @throws {@link ConflictError}: {@link HttpStatusCode.Conflict}
123114
* @throws {@link HttpError}: Other non-success status code
124115
*/
125-
async setAll(entities: TEntity[]): Promise<void> {
126-
await this.putContent(entities);
127-
}
116+
async setAll(entities: TEntity[]) { await this.putContent(entities); }
128117
}

endpoints/raw/BlobEndpoint.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@ export class BlobEndpoint extends Endpoint {
1818
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
1919
* @throws {@link HttpError}: Other non-success status code
2020
*/
21-
async probe(): Promise<void> {
22-
await this.send(HttpMethod.Options);
23-
}
21+
async probe() { await this.send(HttpMethod.Options); }
2422

2523
/**
2624
* Shows whether the server has indicated that {@link download} is currently allowed.
2725
* Uses cached data from last response.
28-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
26+
* @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.
2927
*/
30-
get downloadAllowed(): boolean | undefined {
31-
return this.isMethodAllowed(HttpMethod.Get);
32-
}
28+
get downloadAllowed() { return this.isMethodAllowed(HttpMethod.Get); }
3329

3430
/**
3531
* Downloads the blob's content.
@@ -47,11 +43,9 @@ export class BlobEndpoint extends Endpoint {
4743
/**
4844
* Shows whether the server has indicated that {@link upload} is currently allowed.
4945
* Uses cached data from last response.
50-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
46+
* @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.
5147
*/
52-
get uploadAllowed(): boolean | undefined {
53-
return this.isMethodAllowed(HttpMethod.Put);
54-
}
48+
get uploadAllowed() { return this.isMethodAllowed(HttpMethod.Put); }
5549

5650
/**
5751
* Uploads data as the blob's content.
@@ -61,18 +55,14 @@ export class BlobEndpoint extends Endpoint {
6155
* @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden}
6256
* @throws {@link HttpError}: Other non-success status code
6357
*/
64-
async upload(blob: Blob): Promise<void> {
65-
await this.send(HttpMethod.Put, { [HttpHeader.ContentType]: blob.type }, blob);
66-
}
58+
async upload(blob: Blob) { await this.send(HttpMethod.Put, { [HttpHeader.ContentType]: blob.type }, blob); }
6759

6860
/**
6961
* Shows whether the server has indicated that {@link delete} is currently allowed.
7062
* Uses cached data from last response.
71-
* @returns An indicator whether the method is allowed. If no request has been sent yet or the server did not specify allowed methods `undefined` is returned.
63+
* @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.
7264
*/
73-
get deleteAllowed(): boolean | undefined {
74-
return this.isMethodAllowed(HttpMethod.Delete);
75-
}
65+
get deleteAllowed() { return this.isMethodAllowed(HttpMethod.Delete); }
7666

7767
/**
7868
* Deletes the blob from the server.
@@ -82,7 +72,5 @@ export class BlobEndpoint extends Endpoint {
8272
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
8373
* @throws {@link HttpError}: Other non-success status code
8474
*/
85-
async delete(): Promise<void> {
86-
await this.send(HttpMethod.Delete);
87-
}
75+
async delete() { await this.send(HttpMethod.Delete); }
8876
}

endpoints/raw/UploadEndpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class UploadEndpoint extends Endpoint {
2323
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
2424
* @throws {@link HttpError}: Other non-success status code
2525
*/
26-
async upload(blob: Blob, fileName?: string): Promise<void> {
26+
async upload(blob: Blob, fileName?: string) {
2727
if (this.formField) {
2828
const formData = new FormData();
2929
formData.set(this.formField, blob, fileName);

endpoints/rpc/ActionEndpoint.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ export class ActionEndpoint extends RpcEndpointBase {
2222
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
2323
* @throws {@link HttpError}: Other non-success status code
2424
*/
25-
async invoke(): Promise<void> {
26-
await this.send(HttpMethod.Post);
27-
}
25+
async invoke() { await this.send(HttpMethod.Post); }
2826
}

endpoints/rpc/ConsumerEndpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ConsumerEndpoint<TEntity> extends RpcEndpointBase {
2424
* @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone}
2525
* @throws {@link HttpError}: Other non-success status code
2626
*/
27-
async invoke(entity: TEntity): Promise<void> {
27+
async invoke(entity: TEntity) {
2828
await this.send(HttpMethod.Post, {
2929
[HttpHeader.ContentType]: this.serializer.supportedMediaTypes[0]
3030
}, this.serializer.serialize(entity));

0 commit comments

Comments
 (0)