@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
70 lines • 3.66 kB
TypeScript
/** Quote a literal for a redis MATCH pattern, so a prefix holding `*?[]\` matches itself. */
export declare function escapeGlob(literal: string): string;
/**
* The keyspace a redis mount is built on, as the ops see it.
*
* Every op under `core/redis/` reaches redis through this surface and
* nothing else, so the transport is the store's business: node speaks RESP
* over a socket, the browser speaks the Upstash REST shape over fetch, and
* the ops cannot tell which. Paths are mount-relative and values are bytes.
*
* The key layout is shared by every implementation and by python, so two
* runtimes pointed at one server serve one filesystem: `<prefix>file:<path>`
* holds the bytes, `<prefix>dir` is the set of every directory,
* `<prefix>modified:<path>` the ISO mtime and `<prefix>attrs:<path>` a hash
* carrying the stat overlay.
*/
export interface RedisRestore {
files: Record<string, Uint8Array>;
dirs: readonly string[];
attrs: Record<string, Record<string, string>>;
modified: Record<string, string>;
}
export interface RedisStoreLike {
readonly url: string;
readonly keyPrefix: string;
getFile(path: string): Promise<Uint8Array | null>;
/** A byte window, or null when the file is absent; a null `size` reads to the end. */
getFileRange(path: string, offset: number, size: number | null): Promise<Uint8Array | null>;
setFile(path: string, data: Uint8Array): Promise<void>;
/** Add bytes to the end of a file, creating it when missing (`APPEND`). */
appendFile(path: string, data: Uint8Array): Promise<void>;
/** Write bytes at an offset, zero-filling a shorter file up to it (`SETRANGE`). */
setFileRange(path: string, offset: number, data: Uint8Array): Promise<void>;
truncateFile(path: string, length: number, modified: string, noCreate?: boolean): Promise<boolean>;
delFile(path: string): Promise<void>;
hasFile(path: string): Promise<boolean>;
/** Every file path on the mount sorted by code point, narrowed by `prefix` when given. */
listFiles(prefix?: string): Promise<string[]>;
fileLen(path: string): Promise<number>;
hasDir(path: string): Promise<boolean>;
addDir(path: string): Promise<void>;
removeDir(path: string): Promise<void>;
listDirs(): Promise<Set<string>>;
getModified(path: string): Promise<string | null>;
setModified(path: string, ts: string): Promise<void>;
delModified(path: string): Promise<void>;
getAttrs(path: string): Promise<Record<string, string>>;
/**
* The attributes, length and modified time of many paths, what `getAttrs`,
* `fileLen` and `getModified` answer for each, in one round trip where the
* transport allows. A directory (`true`) has no length.
*/
statMany(paths: readonly (readonly [string, boolean])[]): Promise<[Record<string, string>, number | null, string | null][]>;
/** The server's `INFO memory` section, as the server prints it. */
infoMemory(): Promise<string>;
setAttrs(path: string, fields: Record<string, string>): Promise<void>;
delAttrs(path: string): Promise<void>;
listAttrs(): Promise<Record<string, Record<string, string>>>;
listModified(): Promise<Record<string, string>>;
/** Drop every key of this mount. */
/**
* Write a whole snapshot in as few round trips as the transport allows:
* node queues everything into one MULTI, the browser pipelines the side
* keys under the REST request cap and sends each file's bytes on its own.
*/
restore(state: RedisRestore): Promise<void>;
clear(): Promise<void>;
close(): Promise<void>;
}
//# sourceMappingURL=store.d.ts.map