/** * @module minions-sdk/storage/json-file * Disk-based JSON storage adapter with sharded directory layout and * in-memory index for fast queries / full-text search. * * Directory layout (flat mode — default) * ────────────────────────────────────── * ///.json * * Directory layout (directory mode — opt-in) * ────────────────────────────────────────── * //// * ├── minion.json ← the Minion object * └── ... ← attachment files * * The two-level shard prefix keeps individual directories small even when * millions of minions are stored, while still being human-readable and * git-friendly. * * Index * ───── * An in-memory `Map` is populated at construction time by * scanning the root directory. All subsequent reads hit the index first * (O(1)), falling back to disk only when the entry is missing (which should * not happen in normal usage). Writes update both disk and the index * atomically (from the caller's perspective). * * Writes use a write-to-tmp-then-rename pattern to avoid partial writes * corrupting data if the process crashes mid-write. * * The adapter can **read both flat and directory layouts** regardless of * its configured mode, so migration is seamless. * * This adapter uses Node.js `node:fs/promises`, so it is only suitable for * server-side / CLI usage. */ import type { Minion } from '../types/index.js'; import type { StorageAdapter, StorageFilter, FileStorageOptions } from './StorageAdapter.js'; /** * Disk-backed JSON storage adapter. * * @example * ```typescript * import { Minions } from 'minions-sdk'; * import { JsonFileStorageAdapter } from 'minions-sdk/storage'; * * // Flat mode (default) * const storage = await JsonFileStorageAdapter.create('./data/minions'); * * // Directory mode (enables attachments) * const storage = await JsonFileStorageAdapter.create('./data/minions', { directoryMode: true }); * * const minions = new Minions({ storage }); * const wrapper = minions.create('note', { title: 'Hello', fields: { content: 'World' } }); * await minions.save(wrapper.data); * * // Attach a file (directory mode only) * await storage.putFile(wrapper.data.id, 'readme.md', Buffer.from('# Hello')); * ``` */ export declare class JsonFileStorageAdapter implements StorageAdapter { private readonly rootDir; private index; private readonly directoryMode; private constructor(); /** * Create (or open) a `JsonFileStorageAdapter` rooted at `rootDir`. * * The directory is created if it does not yet exist. All existing JSON * files underneath it are loaded into the in-memory index. * * @param options - Optional. Set `directoryMode: true` to enable * directory-per-minion layout with attachment file support. */ static create(rootDir: string, options?: FileStorageOptions): Promise; private init; /** * Walk the sharded directory tree and populate the in-memory index. * Missing or malformed files are silently skipped. * * Detects both flat files (`.json`) and directory entries * (`/minion.json`) so the adapter can read data written in either * mode. */ private buildIndex; get(id: string): Promise; set(minion: Minion): Promise; delete(id: string): Promise; list(filter?: StorageFilter): Promise; search(query: string): Promise; putFile(id: string, filename: string, data: Uint8Array): Promise; getFile(id: string, filename: string): Promise; deleteFile(id: string, filename: string): Promise; listFiles(id: string): Promise; } //# sourceMappingURL=JsonFileStorageAdapter.d.ts.map