/** * AgentFS - FileSystem implementation using Cloudflare Durable Objects SQLite * * This implementation uses Cloudflare's Durable Objects SQLite storage API, * allowing AgentFS to run on Cloudflare's edge platform. * * @see https://developers.cloudflare.com/durable-objects/api/sqlite-storage-api/ */ import { type Stats, type DirEntry, type FilesystemStats, type FileHandle, type FileSystem } from '../../filesystem/interface.js'; /** * Cloudflare Durable Objects SqlStorage cursor interface */ interface SqlStorageCursor> { toArray(): T[]; one(): T; raw(): IterableIterator; readonly columnNames: string[]; readonly rowsRead: number; readonly rowsWritten: number; next(): { done: boolean; value?: T; }; [Symbol.iterator](): IterableIterator; } /** * Cloudflare Durable Objects SqlStorage interface */ interface SqlStorage { exec>(query: string, ...bindings: unknown[]): SqlStorageCursor; readonly databaseSize: number; } /** * Cloudflare Durable Objects Storage interface (subset we need) */ export interface CloudflareStorage { readonly sql: SqlStorage; transactionSync(callback: () => T): T; } /** * A filesystem backed by Cloudflare Durable Objects SQLite storage. * * AgentFS implements the FileSystem interface using Cloudflare's * Durable Objects SQLite storage as the backing store. * * @example * ```typescript * // In a Durable Object class * export class MyDurableObject extends DurableObject { * private fs: AgentFS; * * constructor(ctx: DurableObjectState, env: Env) { * super(ctx, env); * this.fs = AgentFS.create(ctx.storage); * } * * async fetch(request: Request) { * await this.fs.writeFile('/hello.txt', 'Hello, World!'); * const content = await this.fs.readFile('/hello.txt', 'utf8'); * return new Response(content); * } * } * ``` */ export declare class AgentFS implements FileSystem { private storage; private rootIno; private chunkSize; private constructor(); /** * Create a AgentFS from a Durable Object storage context. * * @param storage - The ctx.storage from a Durable Object */ static create(storage: CloudflareStorage): AgentFS; getChunkSize(): number; private initialize; private ensureRoot; private normalizePath; private splitPath; private resolvePath; private resolvePathOrThrow; private resolveParent; private createInode; private createDentry; private ensureParentDirs; private getLinkCount; private getInodeMode; writeFile(path: string, content: string | Buffer, options?: BufferEncoding | { encoding?: BufferEncoding; }): Promise; private updateFileContent; readFile(path: string): Promise; readFile(path: string, encoding: BufferEncoding): Promise; readFile(path: string, options: { encoding: BufferEncoding; }): Promise; readdir(path: string): Promise; readdirPlus(path: string): Promise; stat(path: string): Promise; lstat(path: string): Promise; mkdir(path: string): Promise; rmdir(path: string): Promise; unlink(path: string): Promise; rm(path: string, options?: { force?: boolean; recursive?: boolean; }): Promise; private rmDirContentsRecursive; private removeDentryAndMaybeInode; rename(oldPath: string, newPath: string): Promise; copyFile(src: string, dest: string): Promise; symlink(target: string, linkpath: string): Promise; readlink(path: string): Promise; access(path: string): Promise; statfs(): Promise; open(path: string): Promise; deleteFile(path: string): Promise; } export {};