refactor: front end code to unified manager api
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
* Entity management service
|
||||
*/
|
||||
|
||||
import { transceivePost } from './transceive';
|
||||
import { transceivePost, transceiveStream } from './transceive';
|
||||
import type {
|
||||
EntityListRequest,
|
||||
EntityListResponse,
|
||||
EntityListBulkRequest,
|
||||
EntityListBulkResponse,
|
||||
EntityListStreamRequest,
|
||||
EntityListStreamResponse,
|
||||
EntityFetchRequest,
|
||||
EntityFetchResponse,
|
||||
EntityExtantRequest,
|
||||
@@ -18,6 +20,10 @@ import type {
|
||||
EntityDeleteResponse,
|
||||
EntityDeltaRequest,
|
||||
EntityDeltaResponse,
|
||||
EntityMoveRequest,
|
||||
EntityMoveResponse,
|
||||
EntityCopyRequest,
|
||||
EntityCopyResponse,
|
||||
EntityInterface,
|
||||
} from '../types/entity';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
@@ -31,7 +37,7 @@ function createEntityObject(data: EntityInterface): EntityObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('people_entity_factory', data.provider) as any;
|
||||
const factory = factoryItem?.factory;
|
||||
|
||||
|
||||
// Use provider factory if available, otherwise base class
|
||||
return factory ? factory(data) : new EntityObject().fromJson(data);
|
||||
}
|
||||
@@ -39,15 +45,15 @@ 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 collection 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: EntityListBulkRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||
const response = await transceivePost<EntityListBulkRequest, EntityListBulkResponse>('entity.listBulk', request);
|
||||
|
||||
// Convert nested response to EntityObject instances
|
||||
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
@@ -65,34 +71,55 @@ export const entityService = {
|
||||
});
|
||||
providerList[providerId] = serviceList;
|
||||
});
|
||||
|
||||
|
||||
return providerList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Stream entities as NDJSON, invoking onEntity for each entity as it arrives.
|
||||
*
|
||||
* The server emits one entity per line so the caller receives entities
|
||||
* progressively rather than waiting for the full collection to load.
|
||||
*
|
||||
* @param request - stream request parameters (same shape as list)
|
||||
* @param onEntity - called synchronously for each entity as it is received
|
||||
*
|
||||
* @returns Promise resolving to { total } when the stream completes
|
||||
*/
|
||||
async listStream(request: EntityListStreamRequest, onEntity: (entity: EntityObject) => void): Promise<{ total: number }> {
|
||||
return await transceiveStream<EntityListStreamRequest, EntityListStreamResponse>(
|
||||
'entity.listStream',
|
||||
request,
|
||||
(entity) => {
|
||||
onEntity(createEntityObject(entity));
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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>> {
|
||||
const response = await transceivePost<EntityFetchRequest, EntityFetchResponse>('entity.fetch', request);
|
||||
|
||||
|
||||
// Convert response to EntityObject instances
|
||||
const list: Record<string, EntityObject> = {};
|
||||
Object.entries(response).forEach(([identifier, entityData]) => {
|
||||
list[identifier] = createEntityObject(entityData);
|
||||
Object.entries(response).forEach(([, entity]) => {
|
||||
list[entity.identifier] = createEntityObject(entity);
|
||||
});
|
||||
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve entity availability status for a given source selector
|
||||
*
|
||||
* Retrieve entity availability status for a given set of entity identifiers
|
||||
*
|
||||
* @param request - extant request parameters
|
||||
*
|
||||
*
|
||||
* @returns Promise with entity availability status
|
||||
*/
|
||||
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
|
||||
@@ -101,9 +128,9 @@ export const entityService = {
|
||||
|
||||
/**
|
||||
* Create a new entity
|
||||
*
|
||||
*
|
||||
* @param request - create request parameters
|
||||
*
|
||||
*
|
||||
* @returns Promise with created entity object
|
||||
*/
|
||||
async create(request: EntityCreateRequest): Promise<EntityObject> {
|
||||
@@ -113,9 +140,9 @@ export const entityService = {
|
||||
|
||||
/**
|
||||
* Update an existing entity
|
||||
*
|
||||
*
|
||||
* @param request - update request parameters
|
||||
*
|
||||
*
|
||||
* @returns Promise with updated entity object
|
||||
*/
|
||||
async update(request: EntityUpdateRequest): Promise<EntityObject> {
|
||||
@@ -124,11 +151,11 @@ export const entityService = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete an entity
|
||||
*
|
||||
* Delete entities by their identifiers
|
||||
*
|
||||
* @param request - delete request parameters
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*
|
||||
* @returns Promise with deletion results keyed by source entity identifier
|
||||
*/
|
||||
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
|
||||
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
|
||||
@@ -136,15 +163,37 @@ export const entityService = {
|
||||
|
||||
/**
|
||||
* Retrieve delta changes for entities
|
||||
*
|
||||
*
|
||||
* @param request - delta request parameters
|
||||
*
|
||||
* @returns Promise with delta changes (created, modified, deleted)
|
||||
*
|
||||
* @returns Promise with delta changes (additions, modifications, deletions)
|
||||
*/
|
||||
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
||||
return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Move entities to a target collection
|
||||
*
|
||||
* @param request - move request parameters
|
||||
*
|
||||
* @returns Promise with move results keyed by source entity identifier
|
||||
*/
|
||||
async move(request: EntityMoveRequest): Promise<EntityMoveResponse> {
|
||||
return await transceivePost<EntityMoveRequest, EntityMoveResponse>('entity.move', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy entities to a target collection
|
||||
*
|
||||
* @param request - copy request parameters
|
||||
*
|
||||
* @returns Promise with copy results keyed by source entity identifier
|
||||
*/
|
||||
async copy(request: EntityCopyRequest): Promise<EntityCopyResponse> {
|
||||
return await transceivePost<EntityCopyRequest, EntityCopyResponse>('entity.copy', request);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
export default entityService;
|
||||
|
||||
Reference in New Issue
Block a user