UNPKG

@tonk/keepsync

Version:

A reactive sync engine framework for use with Tonk apps

72 lines (70 loc) 2.39 kB
import { DocumentId, Repo, DocHandle } from '@automerge/automerge-repo/slim'; export type RefNode = { pointer: DocumentId; type: 'doc' | 'dir'; timestamps: { create: number; modified: number; }; name: string; }; export type DirNode = { type: 'dir'; name: string; timestamps: { create: number; modified: number; }; children?: RefNode[]; }; export type DocNode = { type: 'doc' | 'dir'; pointer?: DocumentId; name: string; timestamps: { create: number; modified: number; }; children?: RefNode[]; }; type TraverseResult = { nodeHandle: DocHandle<DirNode>; node: DirNode; targetRef?: RefNode; parentPath: string; }; /** * Traverses the document tree to find or create nodes along a path * @param repo The Automerge repository * @param rootId The ID of the root document * @param path The path to traverse * @param createMissing Whether to create missing directories along the way * @returns Information about the target node and its parent */ export declare function traverseDocTree(repo: Repo, rootId: DocumentId, path: string, createMissing?: boolean): Promise<TraverseResult | undefined>; /** * Finds a document at the specified path * @param repo The Automerge repository * @param rootId The ID of the root document * @param path The path to the document * @returns The RefNode if found at the leaf, or the FullNode for the root */ export declare function findDocument<T>(repo: Repo, rootId: DocumentId, path: string): Promise<DocHandle<T> | undefined>; /** * Creates a document at the specified path * @param repo The Automerge repository * @param rootId The ID of the root document * @param path The path where the document should be created * @param document The document to create * @returns The document handle for the newly created document */ export declare function createDocument<T>(repo: Repo, rootId: DocumentId, path: string, docHandle: DocHandle<T>): Promise<void>; /** * Removes a document at the specified path * @param repo The Automerge repository * @param rootId The ID of the root document * @param path The path to the document to remove * @returns Whether the document was successfully removed */ export declare function removeDocument(repo: Repo, rootId: DocumentId, path: string): Promise<boolean>; export {};