Initial commit

This commit is contained in:
root
2025-12-21 09:57:43 -05:00
committed by Sebastian Krupinski
commit db42b6699c
35 changed files with 6458 additions and 0 deletions

View File

@@ -0,0 +1,293 @@
/**
* Entity (file) management service
*/
import { fileManagerApi } from './api';
import type { FilterCondition, SortCondition, RangeCondition } from '@/types/common';
import type { FileEntity } from '@/types/node';
import type { EntityDeltaResult } from '@/types/api';
export const entityService = {
/**
* List entities within a collection
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param filter - Optional filter conditions
* @param sort - Optional sort conditions
* @param range - Optional range/pagination conditions
* @returns Promise with entity list
*/
async list(
provider: string,
service: string,
collection: string,
filter?: FilterCondition[] | null,
sort?: SortCondition[] | null,
range?: RangeCondition | null
): Promise<FileEntity[]> {
return await fileManagerApi.execute<FileEntity[]>('entity.list', {
provider,
service,
collection,
filter: filter ?? null,
sort: sort ?? null,
range: range ?? null,
});
},
/**
* Get delta changes for entities since a signature
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param signature - Previous sync signature
* @param detail - Detail level ('ids' or 'full')
* @returns Promise with delta changes
*/
async delta(
provider: string,
service: string,
collection: string,
signature: string,
detail: 'ids' | 'full' = 'ids'
): Promise<EntityDeltaResult> {
return await fileManagerApi.execute<EntityDeltaResult>('entity.delta', {
provider,
service,
collection,
signature,
detail,
});
},
/**
* Check which entities exist
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param identifiers - Entity identifiers to check
* @returns Promise with existence map
*/
async extant(
provider: string,
service: string,
collection: string,
identifiers: string[]
): Promise<Record<string, boolean>> {
return await fileManagerApi.execute<Record<string, boolean>>('entity.extant', {
provider,
service,
collection,
identifiers,
});
},
/**
* Fetch specific entities
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param identifiers - Entity identifiers to fetch
* @returns Promise with entity list
*/
async fetch(
provider: string,
service: string,
collection: string,
identifiers: string[]
): Promise<FileEntity[]> {
return await fileManagerApi.execute<FileEntity[]>('entity.fetch', {
provider,
service,
collection,
identifiers,
});
},
/**
* Read entity content
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param identifier - Entity identifier
* @returns Promise with base64 encoded content
*/
async read(
provider: string,
service: string,
collection: string,
identifier: string
): Promise<{ content: string | null; encoding: 'base64' }> {
return await fileManagerApi.execute<{ content: string | null; encoding: 'base64' }>('entity.read', {
provider,
service,
collection,
identifier,
});
},
/**
* Create a new entity (file)
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier (null for root)
* @param data - Entity data (label, mime, etc.)
* @param options - Additional options
* @returns Promise with created entity
*/
async create(
provider: string,
service: string,
collection: string | null,
data: Partial<FileEntity>,
options?: Record<string, unknown>
): Promise<FileEntity> {
return await fileManagerApi.execute<FileEntity>('entity.create', {
provider,
service,
collection,
data,
options: options ?? {},
});
},
/**
* Modify an existing entity
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier (can be null)
* @param identifier - Entity identifier
* @param data - Data to modify
* @returns Promise with modified entity
*/
async modify(
provider: string,
service: string,
collection: string | null,
identifier: string,
data: Partial<FileEntity>
): Promise<FileEntity> {
return await fileManagerApi.execute<FileEntity>('entity.modify', {
provider,
service,
collection,
identifier,
data,
});
},
/**
* Delete an entity
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier (can be null)
* @param identifier - Entity identifier
* @returns Promise with success status
*/
async destroy(
provider: string,
service: string,
collection: string | null,
identifier: string
): Promise<boolean> {
const result = await fileManagerApi.execute<{ success: boolean }>('entity.destroy', {
provider,
service,
collection,
identifier,
});
return result.success;
},
/**
* Copy an entity to a new location
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Source collection identifier (can be null)
* @param identifier - Entity identifier to copy
* @param destination - Destination collection ID (null for root)
* @returns Promise with copied entity
*/
async copy(
provider: string,
service: string,
collection: string | null,
identifier: string,
destination?: string | null
): Promise<FileEntity> {
return await fileManagerApi.execute<FileEntity>('entity.copy', {
provider,
service,
collection,
identifier,
destination: destination ?? null,
});
},
/**
* Move an entity to a new location
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Source collection identifier (can be null)
* @param identifier - Entity identifier to move
* @param destination - Destination collection ID (null for root)
* @returns Promise with moved entity
*/
async move(
provider: string,
service: string,
collection: string | null,
identifier: string,
destination?: string | null
): Promise<FileEntity> {
return await fileManagerApi.execute<FileEntity>('entity.move', {
provider,
service,
collection,
identifier,
destination: destination ?? null,
});
},
/**
* Write content to an entity
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier (can be null)
* @param identifier - Entity identifier
* @param content - Content to write (base64 encoded)
* @returns Promise with bytes written
*/
async write(
provider: string,
service: string,
collection: string | null,
identifier: string,
content: string
): Promise<number> {
const result = await fileManagerApi.execute<{ bytesWritten: number }>('entity.write', {
provider,
service,
collection,
identifier,
content,
encoding: 'base64',
});
return result.bytesWritten;
},
};
export default entityService;