refactor: documents interfaces

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-09 19:32:27 -04:00
parent ac393843f1
commit 050467919b
23 changed files with 1731 additions and 1581 deletions
+14 -22
View File
@@ -1,7 +1,7 @@
/**
* Collection type definitions
*/
import type { ListFilter, ListSort, SourceSelector } from './common';
import type { CollectionIdentifier, ListFilter, ListSort, ServiceIdentifier } from './common';
export interface CollectionModelInterface extends Omit<CollectionInterface, '@type' | 'created' | 'modified'> {
@@ -46,7 +46,7 @@ export interface CollectionPropertiesInterface extends CollectionMutableProperti
* Collection list
*/
export interface CollectionListRequest {
sources?: SourceSelector;
sources?: (ServiceIdentifier | CollectionIdentifier)[];
filter?: ListFilter;
sort?: ListSort;
}
@@ -63,9 +63,7 @@ export interface CollectionListResponse {
* Collection fetch
*/
export interface CollectionFetchRequest {
provider: string;
service: string | number;
collection: string | number;
targets: CollectionIdentifier[];
}
export interface CollectionFetchResponse extends CollectionInterface {}
@@ -74,7 +72,7 @@ export interface CollectionFetchResponse extends CollectionInterface {}
* Collection extant
*/
export interface CollectionExtantRequest {
sources: SourceSelector;
targets: CollectionIdentifier[];
}
export interface CollectionExtantResponse {
@@ -91,8 +89,9 @@ export interface CollectionExtantResponse {
export interface CollectionCreateRequest {
provider: string;
service: string | number;
collection?: string | number | null; // Parent Collection Identifier
target?: CollectionIdentifier | null; // Parent collection identifier (absent for root)
properties: CollectionMutableProperties;
options?: Record<string, unknown>;
}
export interface CollectionCreateResponse extends CollectionInterface {}
@@ -101,9 +100,7 @@ export interface CollectionCreateResponse extends CollectionInterface {}
* Collection modify
*/
export interface CollectionUpdateRequest {
provider: string;
service: string | number;
identifier: string | number;
target: CollectionIdentifier;
properties: CollectionMutableProperties;
}
@@ -113,26 +110,23 @@ export interface CollectionUpdateResponse extends CollectionInterface {}
* Collection delete
*/
export interface CollectionDeleteRequest {
provider: string;
service: string | number;
identifier: string | number;
target: CollectionIdentifier;
options?: {
force?: boolean; // Whether to force delete even if collection is not empty
};
}
export interface CollectionDeleteResponse {
success: boolean;
disposition: 'deleted' | 'moved';
mutation?: CollectionInterface;
}
/**
* Collection copy
*/
export interface CollectionCopyRequest {
provider: string;
service: string;
identifier: string;
location?: string | null;
source: CollectionIdentifier;
target?: CollectionIdentifier | null; // Destination parent (absent for root)
}
export interface CollectionCopyResponse extends CollectionInterface {}
@@ -141,10 +135,8 @@ export interface CollectionCopyResponse extends CollectionInterface {}
* Collection move
*/
export interface CollectionMoveRequest {
provider: string;
service: string;
identifier: string;
location?: string | null;
source: CollectionIdentifier;
target?: CollectionIdentifier | null; // Destination parent (absent for root)
}
export interface CollectionMoveResponse extends CollectionInterface {}
+47 -23
View File
@@ -44,33 +44,57 @@ export interface ApiErrorResponse {
export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
/**
* Selector for targeting specific providers, services, collections, or entities in list or extant operations.
*
* Example usage:
* {
* "provider1": true, // Select all services/collections/entities under provider1
* "provider2": {
* "serviceA": true, // Select all collections/entities under serviceA of provider2
* "serviceB": {
* "collectionX": true, // Select all entities under collectionX of serviceB of provider2
* "collectionY": [1, 2, 3] // Select entities with identifiers 1, 2, and 3 under collectionY of serviceB of provider2
* }
* }
* }
* Stream control start line.
*/
export type SourceSelector = {
[provider: string]: boolean | ServiceSelector;
};
export interface ApiStreamStartResponse {
type: 'control';
status: 'start';
version: number;
transaction: string;
total?: number;
}
export type ServiceSelector = {
[service: string]: boolean | CollectionSelector;
};
/**
* Stream control end line
*/
export interface ApiStreamEndResponse {
type: 'control';
status: 'end';
total: number;
}
export type CollectionSelector = {
[collection: string | number]: boolean | EntitySelector;
};
/**
* Stream error line
*/
export interface ApiStreamErrorResponse {
type: 'error';
message: string;
}
export type EntitySelector = (string | number)[];
export interface ApiStreamDataResponse<T = any> {
type: 'data';
data: T;
}
/**
* Shared stream control lines
*/
export type ApiStreamResponse<T = any> =
| ApiStreamStartResponse
| ApiStreamEndResponse
| ApiStreamErrorResponse
| ApiStreamDataResponse<T>;
/**
* Identifiers for targeting specific providers, services, collections, or entities in list or extant operations.
*
* Operations accept flat arrays of colon-separated identifier strings, e.g.
* ["default:personal:00000000-0000-0000-0000-000000000000", "default:personal:folder1:file1"].
*/
export type ProviderIdentifier = `${string}`;
export type ServiceIdentifier = `${string}:${string}`;
export type CollectionIdentifier = `${string}:${string}:${string | number}`;
export type EntityIdentifier = `${string}:${string}:${string}:${string | number}`;
/**
+31 -40
View File
@@ -1,7 +1,7 @@
/**
* Entity type definitions
*/
import type { ListFilter, ListRange, ListSort, SourceSelector } from './common';
import type { CollectionIdentifier, EntityIdentifier, ListFilter, ListRange, ListSort, ServiceIdentifier } from './common';
import type { DocumentInterface, DocumentModelInterface } from './document';
/**
@@ -25,11 +25,21 @@ export interface EntityInterface<T = DocumentInterface> {
properties: T;
}
/**
* Entity mutation result (delete/move/copy operations)
*/
export interface EntityMutationResult {
disposition: 'deleted' | 'moved' | 'copied' | 'error';
destination?: CollectionIdentifier | null;
mutation?: EntityIdentifier;
error?: string;
}
/**
* Entity list
*/
export interface EntityListRequest {
sources?: SourceSelector;
sources?: (ServiceIdentifier | CollectionIdentifier)[];
filter?: ListFilter;
sort?: ListSort;
range?: ListRange;
@@ -49,10 +59,7 @@ export interface EntityListResponse {
* Entity fetch
*/
export interface EntityFetchRequest {
provider: string;
service: string | number;
collection: string | number;
identifiers: (string | number)[];
targets: EntityIdentifier[];
}
export interface EntityFetchResponse {
@@ -63,7 +70,7 @@ export interface EntityFetchResponse {
* Entity extant
*/
export interface EntityExtantRequest {
sources: SourceSelector;
targets: (CollectionIdentifier | EntityIdentifier)[];
}
export interface EntityExtantResponse {
@@ -80,9 +87,7 @@ export interface EntityExtantResponse {
* Entity create
*/
export interface EntityCreateRequest<T = DocumentInterface> {
provider: string;
service: string | number;
collection: string | number;
target: CollectionIdentifier;
properties: T;
options?: Record<string, unknown>;
}
@@ -93,10 +98,7 @@ export interface EntityCreateResponse<T = DocumentInterface> extends EntityInter
* Entity update
*/
export interface EntityUpdateRequest<T = DocumentInterface> {
provider: string;
service: string | number;
collection: string | number;
identifier: string | number;
target: EntityIdentifier;
properties: T;
}
@@ -106,21 +108,18 @@ export interface EntityUpdateResponse<T = DocumentInterface> extends EntityInter
* Entity delete
*/
export interface EntityDeleteRequest {
provider: string;
service: string | number;
collection: string | number;
identifier: string | number;
targets: EntityIdentifier[];
}
export interface EntityDeleteResponse {
success: boolean;
[identifier: string]: EntityMutationResult;
}
/**
* Entity delta
*/
export interface EntityDeltaRequest {
sources: SourceSelector;
targets: (CollectionIdentifier | EntityIdentifier)[];
}
export interface EntityDeltaResponse {
@@ -140,36 +139,31 @@ export interface EntityDeltaResponse {
* Entity copy
*/
export interface EntityCopyRequest {
provider: string;
service: string | number;
collection: string | number;
identifier: string | number;
destination?: string | null;
target: CollectionIdentifier;
sources: EntityIdentifier[];
}
export interface EntityCopyResponse<T = DocumentInterface> extends EntityInterface<T> {}
export interface EntityCopyResponse {
[identifier: string]: EntityMutationResult;
}
/**
* Entity move
*/
export interface EntityMoveRequest {
provider: string;
service: string | number;
collection: string | number;
identifier: string | number;
destination?: string | null;
target: CollectionIdentifier;
sources: EntityIdentifier[];
}
export interface EntityMoveResponse<T = DocumentInterface> extends EntityInterface<T> {}
export interface EntityMoveResponse {
[identifier: string]: EntityMutationResult;
}
/**
* Entity read content
*/
export interface EntityReadRequest {
provider: string;
service: string | number;
collection: string | number;
identifier: string | number;
target: EntityIdentifier;
}
export interface EntityReadResult {
@@ -183,10 +177,7 @@ export type EntityReadResponse = EntityReadResult;
* Entity write content
*/
export interface EntityWriteRequest {
provider: string;
service: string | number;
collection: string | number;
identifier: string | number;
target: EntityIdentifier;
content: string;
encoding?: 'base64';
}
-1
View File
@@ -4,4 +4,3 @@ export type * from './service';
export type * from './collection';
export type * from './entity';
export type * from './document';
export type * from './node';
-37
View File
@@ -1,37 +0,0 @@
/**
* Node types for combined operations
*/
import type { CollectionInterface } from "./collection";
import type { ApiResponse, ListFilterCondition, ListRange, ListSort } from "./common";
import type { EntityInterface } from "./entity";
export interface NodeListRequest {
provider: string;
service: string;
location?: string | null;
recursive?: boolean;
filter?: ListFilterCondition | null;
sort?: ListSort | null;
range?: ListRange | null;
}
export type NodeListResponse = ApiResponse<CollectionInterface | EntityInterface>;
export interface NodeDeltaRequest {
provider: string;
service: string;
location?: string | null;
signature: string;
recursive?: boolean;
detail?: 'ids' | 'full';
}
export interface NodeDeltaResult {
added: string[];
modified: string[];
removed: string[];
signature: string;
}
export type NodeDeltaResponse = ApiResponse<NodeDeltaResult>;
+6 -6
View File
@@ -1,7 +1,7 @@
/**
* Provider type definitions
*/
import type { SourceSelector } from "./common";
import type { ProviderIdentifier } from "./common";
/**
* Provider capabilities
@@ -32,7 +32,7 @@ export interface ProviderInterface {
* Provider list
*/
export interface ProviderListRequest {
sources?: SourceSelector;
targets?: ProviderIdentifier[];
}
export interface ProviderListResponse {
@@ -40,19 +40,19 @@ export interface ProviderListResponse {
}
/**
* Provider fetch
* Provider fetch
*/
export interface ProviderFetchRequest {
identifier: string;
target: ProviderIdentifier;
}
export interface ProviderFetchResponse extends ProviderInterface {}
/**
* Provider extant
* Provider extant
*/
export interface ProviderExtantRequest {
sources: SourceSelector;
targets: ProviderIdentifier[];
}
export interface ProviderExtantResponse {
+3 -3
View File
@@ -1,7 +1,7 @@
/**
* Service type definitions
*/
import type { SourceSelector, ListFilterComparisonOperator } from './common';
import type { ServiceIdentifier as ServiceIdentifierString, ListFilterComparisonOperator } from './common';
/**
* Service capabilities
@@ -66,7 +66,7 @@ export interface ServiceInterface {
* Service list
*/
export interface ServiceListRequest {
sources?: SourceSelector;
targets?: ServiceIdentifierString[];
}
export interface ServiceListResponse {
@@ -89,7 +89,7 @@ export interface ServiceFetchResponse extends ServiceInterface {}
* Service extant
*/
export interface ServiceExtantRequest {
sources: SourceSelector;
targets: ServiceIdentifierString[];
}
export interface ServiceExtantResponse {