/** * Node.js-only storage adapters for PostgreSQL and Supabase. * * DO NOT import this file in browser code. It requires Node.js modules (pg). * For browser environments, use MemoryStore or LocalStorageStore from runtime-engine.ts. * * Supabase adapter is optional. '@supabase/supabase-js' is a peer dependency. * It is loaded via dynamic import only when SupabaseStore is instantiated. * If the package is not installed, a clear error is thrown at construction time. */ import { Pool } from 'pg'; export interface EntityInstance { id: string; [key: string]: unknown; } export interface Store { getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; } export interface PostgresConfig { host?: string; port?: number; database?: string; user?: string; password?: string; connectionString?: string; tableName?: string; /** * Optional pre-built `pg` Pool. When set, host/port/database/user/password/ * connectionString are ignored. Used by unit tests and advanced host wiring. */ pool?: Pool; } export declare class PostgresStore implements Store { private pool; private tableName; private generateId; private initialized; /** * Quotes a PostgreSQL identifier to prevent SQL injection. * Wraps the identifier in double quotes and escapes any existing quotes. */ private quoteIdentifier; constructor(config: PostgresConfig, generateId?: () => string); private ensureInitialized; private withConnection; /** * Run `callback` against a query runner. When `tx` is a PoolClient bound to * an open transaction, the queries participate in that transaction so the * write commits atomically with the caller's other work; otherwise a * dedicated pooled connection is acquired and released (matching * withConnection). Table DDL is ensured on a separate connection either way * — schema creation is intentionally not part of the caller's transaction. */ private withRunner; getAll(): Promise; getById(id: string, tx?: unknown): Promise; create(data: Partial, tx?: unknown): Promise; update(id: string, data: Partial, tx?: unknown): Promise; delete(id: string, tx?: unknown): Promise; clear(): Promise; close(): Promise; } export interface SupabaseConfig { url: string; key: string; tableName?: string; /** * Optional pre-built Supabase client. When set, url/key and the dynamic * `@supabase/supabase-js` import are skipped. Used by unit tests and * advanced host wiring. */ client?: any; } /** * Supabase-backed store adapter. * * '@supabase/supabase-js' is an optional peer dependency. It is loaded via * dynamic import at construction time. If the package is not installed, a * clear error is thrown instructing the user to install it. */ export declare class SupabaseStore implements Store { private client; private tableName; private generateId; private ready; private readonly initConfig; constructor(config: SupabaseConfig, generateId?: () => string); private init; private ensureReady; getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; } export interface MongoDBConfig { connectionString: string; databaseName?: string; collectionName?: string; } /** * MongoDB-backed store adapter. * * 'mongodb' is an optional peer dependency. It is loaded via dynamic import * at construction time. If the package is not installed, a clear error is * thrown instructing the user to install it. * * Entities are stored as native BSON documents with `_id` mapped from the * entity's `id` field. Properties map directly to document fields (not * wrapped in a JSONB `data` column like the PostgreSQL adapter). * * Optimistic locking: when a document has a `version` field, update * operations use it as a filter condition. If the stored version doesn't * match, the update returns null and the method returns `undefined`, * consistent with the runtime engine's concurrency control. */ export declare class MongoDBStore implements Store { private client; private collection; private collectionName; private databaseName; private generateId; private ready; private readonly initConfig; constructor(config: MongoDBConfig, generateId?: () => string); private init; private ensureReady; getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; close(): Promise; /** * Convert a MongoDB document to an entity instance. * Strips the MongoDB `_id` field and preserves the entity `id`. */ private docToEntity; } /** * Configuration for DynamoDBStore. */ export interface DynamoDBConfig { /** DynamoDB table name. Default: 'entities' */ tableName?: string; /** Partition key attribute name. Default: 'pk' */ partitionKey?: string; /** Sort key attribute name. Default: 'sk' */ sortKey?: string; /** Entity prefix for partition key. Default: entity name uppercased */ entityPrefix?: string; /** AWS region */ region?: string; /** Pre-initialized DynamoDB DocumentClient */ client?: any; } /** * Build a DynamoDB key from an entity ID and configuration. */ export declare function buildDynamoDBKey(id: string, config: Partial, entityName: string): Record; /** * DynamoDB-backed store adapter using single-table design pattern. * * Requires `@aws-sdk/lib-dynamodb` at runtime. Items are stored with * composite keys (pk/sk) for single-table design. The client is injected * via config so tests can use mocks. */ export declare class DynamoDBStore implements Store { private entityName; private client; private tableName; private partitionKey; private sortKey; private entityPrefix; private generateId; constructor(entityName: string, config: DynamoDBConfig, generateId?: () => string); private buildKey; private entityToItem; private itemToEntity; getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; close(): Promise; } /** * Configuration for RedisStore. */ export interface RedisConfig { /** Redis connection URL */ url?: string; /** Key prefix for all stored entities */ keyPrefix?: string; /** Default TTL in seconds (optional) */ defaultTTL?: number; } /** * Redis-backed store adapter. * * Requires `ioredis` at runtime. Entities are stored as JSON strings * under keys like `{keyPrefix}{entityName}:{id}`. */ export declare class RedisStore implements Store { private client; private keyPrefix; private defaultTTL; private generateId; constructor(entityName: string, config?: RedisConfig, generateId?: () => string); private entityKey; getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; close(): Promise; getTTL(): Promise; setTTL(ttl: number | undefined): Promise; /** * @deprecated Removed no-op. Use `RedisEventBus` from * `@angriff36/manifest/events/redis` for realtime event fan-out. */ publishEvent(_channel: string, _event: unknown): Promise; /** * @deprecated Removed no-op — the old implementation silently dropped * callbacks (they were never invoked). Use `RedisEventBus` from * `@angriff36/manifest/events/redis` for realtime event fan-out. */ subscribe(_channel: string, _callback: (event: unknown) => void): Promise; } /** * Configuration for TursoStore. */ export interface TursoConfig { /** Turso/LibSQL connection URL */ url: string; /** Auth token (optional for local SQLite) */ authToken?: string; /** Table name. Default: 'entities' */ tableName?: string; /** Pre-initialized LibSQL client (for testing or custom setups) */ client?: any; } /** * Generate SQL DDL for the Turso/LibSQL entity table. */ export declare function generateTursoSchema(tableName?: string): string; /** * Turso/LibSQL-backed store adapter. * * Requires `@libsql/client` at runtime. Entities are stored as JSON in a * `data` column, similar to the PostgreSQL adapter. */ export declare class TursoStore implements Store { private client; private tableName; private generateId; private initialized; constructor(config: TursoConfig, generateId?: () => string); private ensureInitialized; getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; transaction(callback: (tx: unknown) => Promise): Promise; close(): Promise; } //# sourceMappingURL=stores.node.d.ts.map