/** * StrictDB — All shared types and interfaces * * This is the ONLY file every other file imports. * No circular dependencies. No file imports from an adapter. */ import type { z } from 'zod'; export type Backend = 'mongo' | 'sql' | 'elastic'; export type Driver = 'mongodb' | 'pg' | 'mysql2' | 'mssql' | 'sqlite' | 'elasticsearch'; export type SqlDialect = 'pg' | 'mysql2' | 'mssql' | 'sqlite'; export type FilterValue = T | FilterOperators; export interface FilterOperators { $eq?: T; $ne?: T; $gt?: T; $gte?: T; $lt?: T; $lte?: T; $in?: T[]; $nin?: T[]; $exists?: boolean; $regex?: string | RegExp; $options?: string; $not?: FilterOperators; $size?: number; } export interface LogicalFilter { $and?: StrictFilter[]; $or?: StrictFilter[]; $nor?: StrictFilter[]; } export type StrictFilter = { [K in keyof T]?: FilterValue; } & LogicalFilter; export interface UpdateOperators { $set?: Partial; $setOnInsert?: Record; $inc?: { [K in keyof T]?: number; }; $unset?: { [K in keyof T]?: true; }; $push?: { [K in keyof T]?: T[K] extends Array ? U : never; }; $pull?: { [K in keyof T]?: T[K] extends Array ? U | StrictFilter : never; }; } export type SortDirection = 1 | -1 | 'asc' | 'desc'; export type SortSpec = { [K in keyof T]?: SortDirection; }; export type Projection = { [K in keyof T]?: 1 | 0; }; export interface QueryOptions> { sort?: SortSpec | Record; limit?: number; skip?: number; projection?: Projection | Record; } export interface LookupOptions { match: StrictFilter; lookup: { from: string; localField: string; foreignField: string; as: string; type?: 'left' | 'inner'; }; unwind?: string; sort?: SortSpec; limit?: number; } export interface IndexDefinition { collection: string; fields: Record; unique?: boolean; sparse?: boolean; expireAfterSeconds?: number; } export interface OperationReceipt { operation: 'insertOne' | 'insertMany' | 'updateOne' | 'updateMany' | 'deleteOne' | 'deleteMany' | 'batch'; collection: string; success: boolean; matchedCount: number; modifiedCount: number; insertedCount: number; deletedCount: number; duration: number; backend: Backend; /** The _id of the inserted document (insertOne only) */ insertedId?: string; /** Array of _ids for inserted documents (insertMany only), preserves insertion order */ insertedIds?: string[]; /** The _id of the upserted document (updateOne with upsert:true, only when a new doc was created) */ upsertedId?: string; } export interface ValidationResult { valid: boolean; errors: Array<{ field: string; message: string; expected: string; received: string; }>; } export interface CollectionDescription { name: string; backend: Backend; fields: Array<{ name: string; type: string; required: boolean; enum?: string[]; }>; indexes: IndexDefinition[]; documentCount: number; exampleFilter: Record; } export type PoolPreset = 'high' | 'standard' | 'low'; export interface ReconnectConfig { enabled?: boolean; maxAttempts?: number; initialDelayMs?: number; maxDelayMs?: number; backoffMultiplier?: number; } export interface TimestampFieldNames { createdAt?: string; updatedAt?: string; } export interface SanitizeRule { /** Field(s) to target. Omit or '*' for all string fields. */ field?: string | string[]; /** Transform the value. Return the new value. */ transform: (value: unknown, field: string, collection: string) => unknown; } export interface GuardrailConfig { /** Block unbounded queries without LIMIT (default: true) */ limitRequired?: boolean; /** Block empty-filter deletes/updates (default: true) */ emptyFilter?: boolean; /** Block = NULL comparisons in SQL mode (default: true) */ nullComparison?: boolean; } export interface StrictDBConfig { uri: string; pool?: PoolPreset; dbName?: string; label?: string; schema?: boolean; sanitize?: boolean; sanitizeRules?: SanitizeRule[]; reconnect?: ReconnectConfig | boolean; slowQueryMs?: number; guardrails?: boolean | GuardrailConfig; logging?: boolean | 'verbose'; timestamps?: boolean | TimestampFieldNames; elastic?: { apiKey?: string; caFingerprint?: string; sniffOnStart?: boolean; }; } export interface CollectionSchema { name: string; schema: z.ZodType; indexes?: IndexDefinition[]; } export interface AggregateOptions { /** Return execution plan alongside results */ explain?: boolean; /** MongoDB: allow spilling to disk for large sorts */ allowDiskUse?: boolean; } export type NativeBulkWriteOp = { insertOne: { document: Record; }; } | { updateOne: { filter: Record; update: Record; upsert?: boolean; }; } | { updateMany: { filter: Record; update: Record; }; } | { deleteOne: { filter: Record; }; } | { deleteMany: { filter: Record; }; } | { replaceOne: { filter: Record; replacement: Record; upsert?: boolean; }; }; export type BatchOperation = { operation: 'insertOne'; collection: string; doc: Record; } | { operation: 'insertMany'; collection: string; docs: Record[]; } | { operation: 'updateOne'; collection: string; filter: StrictFilter>; update: UpdateOperators>; upsert?: boolean; } | { operation: 'updateMany'; collection: string; filter: StrictFilter>; update: UpdateOperators>; } | { operation: 'deleteOne'; collection: string; filter: StrictFilter>; } | { operation: 'deleteMany'; collection: string; filter: StrictFilter>; }; export type StrictErrorCode = 'CONNECTION_FAILED' | 'CONNECTION_LOST' | 'AUTHENTICATION_FAILED' | 'TIMEOUT' | 'POOL_EXHAUSTED' | 'DUPLICATE_KEY' | 'VALIDATION_ERROR' | 'COLLECTION_NOT_FOUND' | 'QUERY_ERROR' | 'GUARDRAIL_BLOCKED' | 'UNKNOWN_OPERATOR' | 'SCHEMA_MISMATCH' | 'UNSUPPORTED_OPERATION' | 'PIPELINE_STAGE_UNSUPPORTED' | 'INTERNAL_ERROR' | 'SQL_PARSE_ERROR' | 'SQL_UNSUPPORTED' | 'SQL_MODE_UNAVAILABLE' | 'SQL_RAW_UNAVAILABLE' | 'SQL_SUGGEST_RAW' | 'SQL_NULL_COMPARISON' | 'SQL_PARAM_MISMATCH' | 'SQL_TRANSACTION_FAILED' | 'SQL_INVALID_OBJECTID'; export interface StrictDBEvents { connected: { backend: string; dbName: string; label: string; }; disconnected: { backend: string; reason: string; timestamp: Date; }; reconnecting: { backend: string; attempt: number; maxAttempts: number; delayMs: number; }; reconnected: { backend: string; attempt: number; downtimeMs: number; }; error: { code: StrictErrorCode; message: string; fix: string; backend: Backend; }; operation: { collection: string; operation: string; durationMs: number; receipt: OperationReceipt; }; 'slow-query': { collection: string; operation: string; durationMs: number; threshold: number; }; 'pool-status': { active: number; idle: number; waiting: number; max: number; }; 'guardrail-blocked': { collection: string; operation: string; reason: string; }; shutdown: { exitCode: number; }; } export interface ConnectionStatus { state: 'connected' | 'disconnected' | 'reconnecting' | 'closed'; backend: Backend; driver: Driver; uri: string; dbName: string; uptimeMs: number; pool: { active: number; idle: number; waiting: number; max: number; }; reconnect: { enabled: boolean; attempts: number; lastDisconnect?: Date; }; } export interface SqlTranslation { clause: string; values: unknown[]; } export interface ExplainResult { backend: Backend; native: string | object; } export interface ConfirmOptions { confirm?: 'DELETE_ALL' | 'UPDATE_ALL'; } //# sourceMappingURL=types.d.ts.map