|
1 | | -import { ETagEndpointBase } from "."; |
| 1 | +import { ETagEndpointBase, ElementEndpoint } from "."; |
2 | 2 | import { Endpoint } from "../Endpoint"; |
3 | 3 | import { CachingEndpoint } from "../CachingEndpoint"; |
4 | 4 | import { HttpMethod, HttpHeader, ResponseCache } from "../../http"; |
5 | 5 |
|
6 | 6 | /** |
7 | | - * Endpoint for a collection of `TEntity`s addressable as `TElementEndpoint`s. |
| 7 | + * Endpoint for a collection of `TEntity`s addressable as `TElementEndpoint`s.<br> |
| 8 | + * Use {@link CollectionEndpoint} instead if you wish to use the default {@link ElementEndpoint} type. |
8 | 9 | * @typeParam TEntity The type of individual elements in the collection. |
9 | | - * @typeParam TElementEndpoint The type of {@link Endpoint}s to provide for individual `TEntity`s. |
| 10 | + * @typeParam TElementEndpoint The type of {@link ElementEndpoint} to provide for individual `TEntity`s. |
10 | 11 | */ |
11 | | -export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoint> extends ETagEndpointBase { |
| 12 | +export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends ElementEndpoint<TEntity>> extends ETagEndpointBase { |
12 | 13 | /** |
13 | 14 | * Creates a new collection endpoint. |
14 | 15 | * @param referrer The endpoint used to navigate to this one. |
@@ -114,4 +115,47 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Endpoin |
114 | 115 | * @throws {@link HttpError}: Other non-success status code |
115 | 116 | */ |
116 | 117 | async setAll(entities: TEntity[]) { await this.putContent(entities); } |
| 118 | + |
| 119 | + /** |
| 120 | + * Determines whether the collection contains a specific element. |
| 121 | + * @param element The ID identifying the entity or an entity to extract the ID from. |
| 122 | + * @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized} |
| 123 | + * @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden} |
| 124 | + * @throws {@link HttpError}: Other non-success status code |
| 125 | + */ |
| 126 | + contains(element: (TEntity | string)) { return this.get(element).exists(); } |
| 127 | + |
| 128 | + /** |
| 129 | + * Sets/replaces an existing element in the collection. |
| 130 | + * @param element The new state of the element. |
| 131 | + * @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity. |
| 132 | + * @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest} |
| 133 | + * @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized} |
| 134 | + * @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden} |
| 135 | + * @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone} |
| 136 | + * @throws {@link HttpError}: Other non-success status code |
| 137 | + */ |
| 138 | + set(element: TEntity) { return this.get(element).set(element); } |
| 139 | + |
| 140 | + /** |
| 141 | + * Modifies an existing element in the collection by merging changes on the server-side. |
| 142 | + * @param element The `TEntity` data to merge with the existing element. |
| 143 | + * @returns The `TEntity` as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity. |
| 144 | + * @throws {@link BadRequestError}: {@link HttpStatusCode.BadRequest} |
| 145 | + * @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized} |
| 146 | + * @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden} |
| 147 | + * @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone} |
| 148 | + * @throws {@link HttpError}: Other non-success status code |
| 149 | + */ |
| 150 | + merge(element: TEntity) { return this.get(element).merge(element); } |
| 151 | + |
| 152 | + /** |
| 153 | + * Deletes an existing element from the collection. |
| 154 | + * @param element The ID identifying the entity or an entity to extract the ID from. |
| 155 | + * @throws {@link AuthenticationError}: {@link HttpStatusCode.Unauthorized} |
| 156 | + * @throws {@link AuthorizationError}: {@link HttpStatusCode.Forbidden} |
| 157 | + * @throws {@link NotFoundError}: {@link HttpStatusCode.NotFound} or {@link HttpStatusCode.Gone} |
| 158 | + * @throws {@link HttpError}: Other non-success status code |
| 159 | + */ |
| 160 | + delete(element: (TEntity | string)) { return this.get(element).delete(); } |
117 | 161 | } |
0 commit comments