@ima/plugin-rest-client
Version:
Generic REST API client plugin for the IMA application framework.
269 lines • 12.5 kB
TypeScript
/**
* The base class for creating REST API service classes, used to group REST API methods
* specified by the REST API client implementation on the given AbstractEntity Class.
*/
export default class AbstractResource {
/** @type {import('@ima/core').Dependencies} */
static get $dependencies(): import("@ima/core").Dependencies;
/**
* This setter is used for compatibility with the Public Class Fields ES
* proposal (at stage 2 at the moment of writing this).
*
* See the related getter for more details about this property.
*
* @param {?AbstractEntity} entityClass Entity class identifying the resource of this service.
*/
static set entityClass(entityClass: AbstractEntity | null);
/**
* Returns entity class identifying the resource of this service, it is also used
* to initialize all data fetched using the appropriate class methods.
*
* @returns {?AbstractEntity} Entity class identifying the resource of this service.
*/
static get entityClass(): AbstractEntity | null;
/**
* Initializes the service.
*
* @param {RestClient} restClient REST API client.
*/
constructor(restClient: RestClient);
/**
* Returns the REST API client instance that is used in this service class. The
* returned REST API client will also be used in all the dynamic methods of
* this service.
*
* @returns {RestClient} The REST API client.
*/
get $restClient(): RestClient;
/**
* Retrieves the specified entities from the REST API resource
* identified by the {@link AbstractResource.entityClass}.
*
* @param {Object<string, (number|string|(number|string)[])>=} parameters
* The additional parameters to send to the server with the request
* to configure the server's response.
* @param {{
* timeout: number=,
* ttl: number=,
* repeatRequest: number=,
* headers: Object<string, string>=,
* cache: boolean=,
* withCredentials: boolean=
* }=} options Request options. See the documentation of the HTTP
* agent for more details.
* @param {?AbstractEntity=} parentEntity The parent entity containing the
* resource from which the entities should be listed.
* @returns {Promise<?(Response|AbstractEntity|AbstractEntity[])>} A promise
* that will resolve to the server's response, or the entity,
* entities or {@code null} constructed from the response body if
* this entity class has the {@code inlineResponseBody} flag set.
*/
list(parameters?: {
[x: string]: (number | string | (number | string)[]);
} | undefined, options?: {
timeout: number;
ttl: number;
repeatRequest: number;
headers: {
[x: string]: string;
};
cache: boolean;
withCredentials: boolean;
} | undefined, parentEntity?: (AbstractEntity | null) | undefined): Promise<(Response | AbstractEntity | AbstractEntity[]) | null>;
/**
* Retrieves the specified entity or entities from the REST API resource
* identified by the {@link AbstractResource.entityClass}.
*
* @param {(number|string|(number|string)[])} id The ID(s) identifying the
* entity or group of entities to retrieve.
* @param {Object<string, (number|string|(number|string)[])>=} parameters
* The additional parameters to send to the server with the request
* to configure the server's response.
* @param {{
* timeout: number=,
* ttl: number=,
* repeatRequest: number=,
* headers: Object<string, string>=,
* cache: boolean=,
* withCredentials: boolean=
* }=} options Request options. See the documentation of the HTTP
* agent for more details.
* @param {?AbstractEntity=} parentEntity The parent entity containing the
* resource from which the entity should be retrieved.
* @returns {Promise<?(Response|AbstractEntity|AbstractEntity[])>} A promise
* that will resolve to the server's response, or the entity,
* entities or {@code null} constructed from the response body if
* this entity class has the {@code inlineResponseBody} flag set.
*/
get(id: (number | string | (number | string)[]), parameters?: {
[x: string]: (number | string | (number | string)[]);
} | undefined, options?: {
timeout: number;
ttl: number;
repeatRequest: number;
headers: {
[x: string]: string;
};
cache: boolean;
withCredentials: boolean;
} | undefined, parentEntity?: (AbstractEntity | null) | undefined): Promise<(Response | AbstractEntity | AbstractEntity[]) | null>;
/**
* Creates a new entity in the REST API resource identifying by this
* {@link AbstractResource.entityClass} class using the provided data.
*
* @param {Object<string, *>} data The entity data. The data should be
* compatible with this entity's structure so that they can be
* directly assigned to the entity, and will be automatically
* serialized before submitting to the server.
* @param {Object<string, (number|string|(number|string)[])>=} parameters
* The additional parameters to send to the server with the request
* to configure the server's response.
* @param {{
* timeout: number=,
* ttl: number=,
* repeatRequest: number=,
* headers: Object<string, string>=,
* cache: boolean=,
* withCredentials: boolean=
* }=} options Request options. See the documentation of the HTTP
* agent for more details.
* @param {?AbstractEntity=} parentEntity The parent entity containing the
* nested resource within which the new entity should be created.
* @returns {Promise<?(Response|AbstractEntity|AbstractEntity[])>} A promise
* that will resolve to the server's response, or the entity,
* entities or {@code null} constructed from the response body if
* this entity class has the {@code inlineResponseBody} flag set.
*/
create(data: {
[x: string]: any;
}, parameters?: {
[x: string]: (number | string | (number | string)[]);
} | undefined, options?: {
timeout: number;
ttl: number;
repeatRequest: number;
headers: {
[x: string]: string;
};
cache: boolean;
withCredentials: boolean;
} | undefined, parentEntity?: (AbstractEntity | null) | undefined): Promise<(Response | AbstractEntity | AbstractEntity[]) | null>;
/**
* Deletes the specified entity or entities from the REST API resource
* identified by this {@link AbstractResource.entityClass} class.
*
* @param {(number|string|(number|string)[])} id The ID(s) identifying the
* entity or group of entities to retrieve.
* @param {Object<string, (number|string|(number|string)[])>=} parameters
* The additional parameters to send to the server with the request
* to configure the server's response.
* @param {{
* timeout: number=,
* ttl: number=,
* repeatRequest: number=,
* headers: Object<string, string>=,
* cache: boolean=,
* withCredentials: boolean=
* }=} options Request options. See the documentation of the HTTP
* agent for more details.
* @param {?AbstractEntity=} parentEntity The parent entity containing the
* resource from which the entity should be deleted.
* @returns {Promise<?(Response|AbstractEntity|AbstractEntity[])>} A promise
* that will resolve to the server's response, or the entity,
* entities or {@code null} constructed from the response body if
* this entity class has the {@code inlineResponseBody} flag set.
*/
delete(id: (number | string | (number | string)[]), parameters?: {
[x: string]: (number | string | (number | string)[]);
} | undefined, options?: {
timeout: number;
ttl: number;
repeatRequest: number;
headers: {
[x: string]: string;
};
cache: boolean;
withCredentials: boolean;
} | undefined, parentEntity?: (AbstractEntity | null) | undefined): Promise<(Response | AbstractEntity | AbstractEntity[]) | null>;
/**
* Patches the state of an entity using the provided data. The method
* first patches the state of provided entity in the REST API resource,
* and, after a successful update, the method then patches the state of
* provided entity's instance.
*
* @param {AbstractEntity} entity Instance of the entity to be patched.
* @param {Object<string, *>} data The data with which provided entity
* should be patched. The data should be compatible with provided
* entity's structure so that they can be directly assigned to the
* entity, and will be automatically serialized before submitting
* to the server.
* @param {Object<string, (number|string|(number|string)[])>=} parameters
* The additional parameters to send to the server with the request
* to configure the server's response.
* @param {{
* timeout: number=,
* ttl: number=,
* repeatRequest: number=,
* headers: Object<string, string>=,
* cache: boolean=,
* withCredentials: boolean=
* }=} options Request options. See the documentation of the HTTP
* agent for more details.
* @returns {Promise<?(Response|AbstractEntity|AbstractEntity[])>} A promise
* that will resolve to the server's response, or the entity,
* entities or {@code null} constructed from the response body if
* the provided entity's class has the {@code inlineResponseBody}
* flag set.
*/
patch(entity: AbstractEntity, data: {
[x: string]: any;
}, parameters?: {
[x: string]: (number | string | (number | string)[]);
} | undefined, options?: {
timeout: number;
ttl: number;
repeatRequest: number;
headers: {
[x: string]: string;
};
cache: boolean;
withCredentials: boolean;
} | undefined): Promise<(Response | AbstractEntity | AbstractEntity[]) | null>;
/**
* Replaces entity in the REST API resource with the provided entity's current
* state.
*
* @param {AbstractEntity} entity Entity containing state to be replaced.
* @param {Object<string, (number|string|(number|string)[])>=} parameters
* The additional parameters to send to the server with the request
* to configure the server's response.
* @param {{
* timeout: number=,
* ttl: number=,
* repeatRequest: number=,
* headers: Object<string, string>=,
* cache: boolean=,
* withCredentials: boolean=
* }=} options Request options. See the documentation of the HTTP
* agent for more details.
* @returns {Promise<?(Response|AbstractEntity|AbstractEntity[])>} A promise
* that will resolve to the server's response, or the entity,
* entities or {@code null} constructed from the response body if
* the provided entity's class has the {@code inlineResponseBody}
* flag set.
*/
replace(entity: AbstractEntity, parameters?: {
[x: string]: (number | string | (number | string)[]);
} | undefined, options?: {
timeout: number;
ttl: number;
repeatRequest: number;
headers: {
[x: string]: string;
};
cache: boolean;
withCredentials: boolean;
} | undefined): Promise<(Response | AbstractEntity | AbstractEntity[]) | null>;
}
import RestClient from './RestClient';
//# sourceMappingURL=AbstractResource.d.ts.map