refactor: front end
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
+57
-63
@@ -2,73 +2,67 @@
|
||||
* Node (unified collection/entity) management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { FilterCondition, SortCondition, RangeCondition } from '@/types/common';
|
||||
import type { FileNode } from '@/types/node';
|
||||
import type { NodeDeltaResult } from '@/types/api';
|
||||
import { transceivePost } from './transceive'
|
||||
import type { ListFilter, ListSort, ListRange } from '../types/common'
|
||||
import type { CollectionInterface } from '../types/collection'
|
||||
import type { EntityInterface } from '../types/entity'
|
||||
|
||||
export type NodeItem = CollectionInterface | EntityInterface
|
||||
|
||||
export interface NodeListRequest {
|
||||
provider: string
|
||||
service: string | number
|
||||
location?: string | number | null
|
||||
recursive?: boolean
|
||||
filter?: ListFilter | null
|
||||
sort?: ListSort | null
|
||||
range?: ListRange | null
|
||||
}
|
||||
|
||||
export type NodeListResponse = Record<string, NodeItem>
|
||||
|
||||
export interface NodeDeltaRequest {
|
||||
provider: string
|
||||
service: string | number
|
||||
location?: string | number | null
|
||||
signature: string
|
||||
recursive?: boolean
|
||||
detail?: 'ids' | 'full'
|
||||
}
|
||||
|
||||
export interface NodeDeltaResult {
|
||||
added: Array<string | number | NodeItem>
|
||||
modified: Array<string | number | NodeItem>
|
||||
removed: Array<string | number>
|
||||
signature: string
|
||||
}
|
||||
|
||||
export const nodeService = {
|
||||
|
||||
/**
|
||||
* List all nodes (collections and entities) within a location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param recursive - Whether to list recursively
|
||||
* @param filter - Optional filter conditions
|
||||
* @param sort - Optional sort conditions
|
||||
* @param range - Optional range/pagination conditions
|
||||
* @returns Promise with node list
|
||||
*/
|
||||
async list(
|
||||
provider: string,
|
||||
service: string,
|
||||
location?: string | null,
|
||||
recursive: boolean = false,
|
||||
filter?: FilterCondition[] | null,
|
||||
sort?: SortCondition[] | null,
|
||||
range?: RangeCondition | null
|
||||
): Promise<FileNode[]> {
|
||||
return await fileManagerApi.execute<FileNode[]>('node.list', {
|
||||
provider,
|
||||
service,
|
||||
location: location ?? null,
|
||||
recursive,
|
||||
filter: filter ?? null,
|
||||
sort: sort ?? null,
|
||||
range: range ?? null,
|
||||
});
|
||||
async list(request: NodeListRequest): Promise<NodeItem[]> {
|
||||
const response = await transceivePost<NodeListRequest, NodeListResponse>('node.list', {
|
||||
provider: request.provider,
|
||||
service: request.service,
|
||||
location: request.location ?? null,
|
||||
recursive: request.recursive ?? false,
|
||||
filter: request.filter ?? null,
|
||||
sort: request.sort ?? null,
|
||||
range: request.range ?? null,
|
||||
})
|
||||
|
||||
return Object.values(response)
|
||||
},
|
||||
|
||||
/**
|
||||
* Get delta changes for nodes since a signature
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param signature - Previous sync signature
|
||||
* @param recursive - Whether to get delta recursively
|
||||
* @param detail - Detail level ('ids' or 'full')
|
||||
* @returns Promise with delta changes
|
||||
*/
|
||||
async delta(
|
||||
provider: string,
|
||||
service: string,
|
||||
location: string | null,
|
||||
signature: string,
|
||||
recursive: boolean = false,
|
||||
detail: 'ids' | 'full' = 'ids'
|
||||
): Promise<NodeDeltaResult> {
|
||||
return await fileManagerApi.execute<NodeDeltaResult>('node.delta', {
|
||||
provider,
|
||||
service,
|
||||
location,
|
||||
signature,
|
||||
recursive,
|
||||
detail,
|
||||
});
|
||||
async delta(request: NodeDeltaRequest): Promise<NodeDeltaResult> {
|
||||
return await transceivePost<NodeDeltaRequest, NodeDeltaResult>('node.delta', {
|
||||
provider: request.provider,
|
||||
service: request.service,
|
||||
location: request.location ?? null,
|
||||
signature: request.signature,
|
||||
recursive: request.recursive ?? false,
|
||||
detail: request.detail ?? 'ids',
|
||||
})
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default nodeService;
|
||||
export default nodeService
|
||||
|
||||
Reference in New Issue
Block a user