refactor: use resource identifiers
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -72,9 +72,16 @@ export const collectionService = {
|
||||
*
|
||||
* @returns Promise with collection object
|
||||
*/
|
||||
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
|
||||
async fetch(request: CollectionFetchRequest): Promise<Record<string, CollectionObject>> {
|
||||
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
|
||||
return createCollectionObject(response);
|
||||
|
||||
// Convert response to CollectionObject instances
|
||||
const list: Record<string, CollectionObject> = {};
|
||||
Object.entries(response).forEach(([identifier, entity]) => {
|
||||
list[entity.identifier] = createCollectionObject(entity);
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -128,8 +135,8 @@ export const collectionService = {
|
||||
async delete(request: CollectionDeleteRequest): Promise<boolean | CollectionObject> {
|
||||
const response = await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
||||
|
||||
if (response.outcome === 'moved' && response.data) {
|
||||
return createCollectionObject(response.data);
|
||||
if (response.disposition === 'moved' && response.mutation) {
|
||||
return createCollectionObject(response.mutation);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -87,8 +87,8 @@ export const entityService = {
|
||||
|
||||
// Convert response to EntityObject instances
|
||||
const list: Record<string, EntityObject> = {};
|
||||
Object.entries(response).forEach(([identifier, entityData]) => {
|
||||
list[identifier] = createEntityObject(entityData);
|
||||
Object.entries(response).forEach(([identifier, entity]) => {
|
||||
list[entity.identifier] = createEntityObject(entity);
|
||||
});
|
||||
|
||||
return list;
|
||||
@@ -184,10 +184,7 @@ export const entityService = {
|
||||
*
|
||||
* @returns Promise resolving to { total } when the stream completes
|
||||
*/
|
||||
async stream(
|
||||
request: EntityStreamRequest,
|
||||
onEntity: (entity: EntityObject) => void
|
||||
): Promise<{ total: number }> {
|
||||
async stream(request: EntityStreamRequest, onEntity: (entity: EntityObject) => void): Promise<{ total: number }> {
|
||||
return await transceiveStream<EntityStreamRequest, EntityStreamResponse>(
|
||||
'entity.stream',
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user