refactor: front end

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-28 12:47:21 -04:00
parent 28e5cce23a
commit ccb781f933
38 changed files with 4909 additions and 2897 deletions
+113 -153
View File
@@ -2,194 +2,154 @@
* Collection management service
*/
import { fileManagerApi } from './api';
import type { FilterCondition, SortCondition } from '@/types/common';
import type { FileCollection } from '@/types/node';
import { transceivePost } from './transceive';
import type {
CollectionListRequest,
CollectionListResponse,
CollectionExtantRequest,
CollectionExtantResponse,
CollectionFetchRequest,
CollectionFetchResponse,
CollectionCreateRequest,
CollectionCreateResponse,
CollectionUpdateResponse,
CollectionUpdateRequest,
CollectionDeleteResponse,
CollectionDeleteRequest,
CollectionInterface,
} from '../types/collection';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { CollectionObject, CollectionPropertiesObject } from '../models/collection';
function isCollectionPayload(value: unknown): value is CollectionInterface {
if (!value || typeof value !== 'object') {
return false;
}
const candidate = value as Record<string, unknown>;
return (
('identifier' in candidate || 'provider' in candidate || 'service' in candidate)
&& 'properties' in candidate
);
}
/**
* Helper to create the right collection model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base CollectionObject
*/
function createCollectionObject(data: CollectionInterface): CollectionObject {
const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('documents_collection_factory', data.provider) as any;
const factory = factoryItem?.factory;
// Use provider factory if available, otherwise base class
return factory ? factory(data) : new CollectionObject().fromJson(data);
}
export const collectionService = {
/**
* List collections within a location
* Retrieve list of collections, optionally filtered by source selector
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param location - Parent collection ID (null for root)
* @param filter - Optional filter conditions
* @param sort - Optional sort conditions
* @returns Promise with collection list
* @param request - list request parameters
*
* @returns Promise with collection object list grouped by provider, service, and collection identifier
*/
async list(
provider: string,
service: string,
location?: string | null,
filter?: FilterCondition[] | null,
sort?: SortCondition[] | null
): Promise<FileCollection[]> {
return await fileManagerApi.execute<FileCollection[]>('collection.list', {
provider,
service,
location: location ?? null,
filter: filter ?? null,
sort: sort ?? null,
async list(request: CollectionListRequest = {}): Promise<Record<string, Record<string, Record<string, CollectionObject>>>> {
const response = await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request);
// Convert nested response to CollectionObject instances
const providerList: Record<string, Record<string, Record<string, CollectionObject>>> = {};
Object.entries(response).forEach(([providerId, providerServices]) => {
const serviceList: Record<string, Record<string, CollectionObject>> = {};
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
const collectionList: Record<string, CollectionObject> = {};
Object.entries(serviceCollections as Record<string, unknown>).forEach(([collectionId, collectionData]) => {
if (isCollectionPayload(collectionData)) {
collectionList[collectionId] = createCollectionObject(collectionData);
return;
}
if (collectionData && typeof collectionData === 'object') {
Object.entries(collectionData as Record<string, unknown>).forEach(([nestedCollectionId, nestedCollectionData]) => {
if (isCollectionPayload(nestedCollectionData)) {
collectionList[nestedCollectionId] = createCollectionObject(nestedCollectionData);
}
});
}
});
serviceList[serviceId] = collectionList;
});
providerList[providerId] = serviceList;
});
return providerList;
},
/**
* Check if a collection exists
* Retrieve a specific collection by provider and identifier
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @returns Promise with extant status
* @param request - fetch request parameters
*
* @returns Promise with collection object
*/
async extant(
provider: string,
service: string,
identifier: string
): Promise<boolean> {
const result = await fileManagerApi.execute<{ extant: boolean }>('collection.extant', {
provider,
service,
identifier,
});
return result.extant;
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
return createCollectionObject(response);
},
/**
* Fetch a specific collection
* Retrieve collection availability status for a given source selector
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @returns Promise with collection details
* @param request - extant request parameters
*
* @returns Promise with collection availability status
*/
async fetch(
provider: string,
service: string,
identifier: string
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.fetch', {
provider,
service,
identifier,
});
async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> {
return await transceivePost<CollectionExtantRequest, CollectionExtantResponse>('collection.extant', request);
},
/**
* Create a new collection (folder)
* Create a new collection
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param location - Parent collection ID (null for root)
* @param data - Collection data (label, etc.)
* @param options - Additional options
* @returns Promise with created collection
* @param request - create request parameters
*
* @returns Promise with created collection object
*/
async create(
provider: string,
service: string,
location: string | null,
data: Partial<FileCollection>,
options?: Record<string, unknown>
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.create', {
provider,
service,
location,
data,
options: options ?? {},
});
async create(request: CollectionCreateRequest): Promise<CollectionObject> {
if (request.properties instanceof CollectionPropertiesObject) {
request.properties = request.properties.toJson();
}
const response = await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request);
return createCollectionObject(response);
},
/**
* Modify an existing collection
* Update an existing collection
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @param data - Data to modify
* @returns Promise with modified collection
* @param request - update request parameters
*
* @returns Promise with updated collection object
*/
async modify(
provider: string,
service: string,
identifier: string,
data: Partial<FileCollection>
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.modify', {
provider,
service,
identifier,
data,
});
async update(request: CollectionUpdateRequest): Promise<CollectionObject> {
if (request.properties instanceof CollectionPropertiesObject) {
request.properties = request.properties.toJson();
}
const response = await transceivePost<CollectionUpdateRequest, CollectionUpdateResponse>('collection.update', request);
return createCollectionObject(response);
},
/**
* Delete a collection
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @returns Promise with success status
* @param request - delete request parameters
*
* @returns Promise with deletion result
*/
async destroy(
provider: string,
service: string,
identifier: string
): Promise<boolean> {
const result = await fileManagerApi.execute<{ success: boolean }>('collection.destroy', {
provider,
service,
identifier,
});
return result.success;
async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
},
/**
* Copy a collection to a new location
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier to copy
* @param location - Destination parent collection ID (null for root)
* @returns Promise with copied collection
*/
async copy(
provider: string,
service: string,
identifier: string,
location?: string | null
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.copy', {
provider,
service,
identifier,
location: location ?? null,
});
},
/**
* Move a collection to a new location
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier to move
* @param location - Destination parent collection ID (null for root)
* @returns Promise with moved collection
*/
async move(
provider: string,
service: string,
identifier: string,
location?: string | null
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.move', {
provider,
service,
identifier,
location: location ?? null,
});
},
};
export default collectionService;