/** * @module minions-sdk/storage/yaml-file * Disk-based YAML storage adapter with sharded directory layout and * in-memory index for fast queries / full-text search. * * Identical architecture to {@link JsonFileStorageAdapter} but persists * minions as human-readable YAML files instead of JSON. * * Directory layout (flat mode — default) * ────────────────────────────────────── * ///.yaml * * Directory layout (directory mode — opt-in) * ────────────────────────────────────────── * //// * ├── minion.yaml ← 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. * * The adapter can **read both flat and directory layouts** regardless of * its configured mode, so migration is seamless. * * Writes use a write-to-tmp-then-rename pattern to avoid partial writes * corrupting data if the process crashes mid-write. * * YAML Serializer * ─────────────── * Uses a built-in minimal YAML serializer (no external dependencies) that * supports all Minion field types: strings, numbers, booleans, dates, * arrays, nested objects, and null values. * * 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'; /** * Serialize a value to YAML string. Handles all types that a Minion can * contain: primitives, arrays, nested objects, null, and Date strings. */ declare function toYaml(obj: Record, indent?: number): string; /** * Parse a YAML string into a JavaScript object. * Handles the subset of YAML that {@link toYaml} produces. */ declare function parseYaml(content: string): Record; /** * Disk-backed YAML storage adapter. * * @example * ```typescript * import { Minions } from 'minions-sdk'; * import { YamlFileStorageAdapter } from 'minions-sdk/node'; * * // Flat mode (default) * const storage = await YamlFileStorageAdapter.create('./data/minions'); * * // Directory mode (enables attachments) * const storage = await YamlFileStorageAdapter.create('./data/minions', { directoryMode: true }); * * const minions = new Minions({ storage }); * const wrapper = await 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 YamlFileStorageAdapter implements StorageAdapter { private readonly rootDir; private index; private readonly directoryMode; private constructor(); /** * Create (or open) a `YamlFileStorageAdapter` rooted at `rootDir`. * * The directory is created if it does not yet exist. All existing YAML * 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 (`.yaml`) and directory entries * (`/minion.yaml`) 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; } /** Convert a plain object to YAML string. */ export { toYaml }; /** Parse a YAML string to a plain object. */ export { parseYaml }; //# sourceMappingURL=YamlFileStorageAdapter.d.ts.map