refactor: documents interfaces
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Entity management service
|
||||
*/
|
||||
|
||||
import { transceivePost } from './transceive';
|
||||
import { transceivePost, transceiveStream } from './transceive';
|
||||
import type {
|
||||
EntityListRequest,
|
||||
EntityListResponse,
|
||||
@@ -18,6 +18,10 @@ import type {
|
||||
EntityDeleteResponse,
|
||||
EntityDeltaRequest,
|
||||
EntityDeltaResponse,
|
||||
EntityCopyRequest,
|
||||
EntityCopyResponse,
|
||||
EntityMoveRequest,
|
||||
EntityMoveResponse,
|
||||
EntityReadRequest,
|
||||
EntityReadResponse,
|
||||
EntityWriteRequest,
|
||||
@@ -43,14 +47,14 @@ function createEntityObject(data: EntityInterface): EntityObject {
|
||||
export const entityService = {
|
||||
|
||||
/**
|
||||
* Retrieve list of entities, optionally filtered by source selector
|
||||
*
|
||||
* Retrieve list of entities, optionally filtered by source identifiers
|
||||
*
|
||||
* @param request - list request parameters
|
||||
*
|
||||
*
|
||||
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
|
||||
*/
|
||||
async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||
const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request);
|
||||
async listBulk(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||
const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.listBulk', request);
|
||||
|
||||
// Convert nested response to EntityObject instances
|
||||
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
||||
@@ -73,11 +77,25 @@ export const entityService = {
|
||||
return providerList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Stream entities one by one, invoking the callback for each entity
|
||||
*
|
||||
* @param request - list request parameters
|
||||
* @param onEntity - callback invoked for each streamed entity
|
||||
*
|
||||
* @returns Promise with the total number of streamed entities
|
||||
*/
|
||||
async listStream(request: EntityListRequest, onEntity: (entity: EntityObject) => void): Promise<{ total: number }> {
|
||||
return await transceiveStream<EntityListRequest, EntityInterface>('entity.listStream', request, (entityData) => {
|
||||
onEntity(createEntityObject(entityData));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve a specific entity by provider and identifier
|
||||
*
|
||||
*
|
||||
* @param request - fetch request parameters
|
||||
*
|
||||
*
|
||||
* @returns Promise with entity objects keyed by identifier
|
||||
*/
|
||||
async fetch(request: EntityFetchRequest): Promise<Record<string, EntityObject>> {
|
||||
@@ -128,16 +146,38 @@ export const entityService = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete an entity
|
||||
*
|
||||
* Delete entities
|
||||
*
|
||||
* @param request - delete request parameters
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*
|
||||
* @returns Promise with per-entity disposition results
|
||||
*/
|
||||
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
|
||||
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy entities to another collection
|
||||
*
|
||||
* @param request - copy request parameters
|
||||
*
|
||||
* @returns Promise with per-entity disposition results
|
||||
*/
|
||||
async copy(request: EntityCopyRequest): Promise<EntityCopyResponse> {
|
||||
return await transceivePost<EntityCopyRequest, EntityCopyResponse>('entity.copy', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Move entities to another collection
|
||||
*
|
||||
* @param request - move request parameters
|
||||
*
|
||||
* @returns Promise with per-entity disposition results
|
||||
*/
|
||||
async move(request: EntityMoveRequest): Promise<EntityMoveResponse> {
|
||||
return await transceivePost<EntityMoveRequest, EntityMoveResponse>('entity.move', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve delta changes for entities
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user