import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, UpdateBatchResult, UpdateResult } from './collection.mjs'; import type { LoggerLike, ExpressionFunction, ExpressionObject } from './base.mjs'; import type { ModelDefinition, ModelEnsureIndexesOptions, ModelIndexEnsureResult, ModelInstance as ModelInstanceContract, RegisteredModel, RelationConfig } from './model.mjs'; import type { LockOptions, LockStats } from './lock.mjs'; import type { ConnectionPoolManagerOptions, FallbackStrategy, PoolConfig, PoolHealthStatus, PoolRole, PoolStats, PoolStrategy } from './pool.mjs'; import type { SagaDefinition, SagaOrchestratorOptions, SagaResult, SagaStats, SagaStep } from './saga.mjs'; import type { SlowQueryLogConfig, SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, SlowQueryLogQueryOptions, SlowQueryLogRecord, SlowQueryLogStorageConfig } from './slow-query-log.mjs'; import type { ResumeTokenConfig, SyncChangeEvent, SyncConfig, SyncStats, SyncTargetConfig, SyncTargetHealthCheckConfig } from './sync.mjs'; import type { MongoSession, TransactionOptions, TransactionStats } from './transaction.mjs'; import type { CacheLike as HubCacheLike, CacheRemainingTtl as HubCacheRemainingTtl, CacheSetOptions as HubCacheSetOptions, CacheStats as HubCacheStats, LockManager as HubCacheLockLike, MemoryCacheOptions as HubMemoryCacheOptions, } from 'cache-hub' with { "resolution-mode": "import" }; import type { RedisCacheAdapter as HubRedisCacheAdapter, RedisCacheAdapterOptions as HubRedisCacheAdapterOptions, } from 'cache-hub/redis' with { "resolution-mode": "import" }; import type { DistributedInvalidatorOptions as HubDistributedInvalidatorOptions, InvalidatorStats as HubInvalidatorStats, } from 'cache-hub/distributed' with { "resolution-mode": "import" }; import type { FunctionCacheOptions as HubFunctionCacheOptions, FunctionCacheStats as HubFunctionCacheStats, WithCacheOptions as HubWithCacheOptions, WithCacheStats as HubWithCacheStats, WrappedFunction as HubWrappedFunction, } from 'cache-hub/function-cache' with { "resolution-mode": "import" }; export { Lock, LockAcquireError, LockTimeoutError, LockManager } from './lock.mjs'; export { ConnectionPoolManager } from './pool.mjs'; export { SagaOrchestrator } from './saga.mjs'; export { BatchQueue, SlowQueryLogConfigManager, SlowQueryLogManager, SlowQueryLogMemoryStorage, MongoDBSlowQueryLogStorage } from './slow-query-log.mjs'; export { ChangeStreamSyncManager, ResumeTokenStore } from './sync.mjs'; export { CacheLockManager, Transaction, TransactionManager } from './transaction.mjs'; export declare class Logger { constructor(logger?: LoggerLike | null); debug(...args: unknown[]): void; info(...args: unknown[]): void; warn(...args: unknown[]): void; error(...args: unknown[]): void; static create(logger?: LoggerLike | null): Logger; } export type CacheLockLike = HubCacheLockLike; export type CacheLike = HubCacheLike; export type CacheRemainingTtl = HubCacheRemainingTtl; export type CacheSetOptions = HubCacheSetOptions; export type MemoryCacheOptions = HubMemoryCacheOptions; /** * Multi-level cache write policy. * - `both`: write to both local and remote simultaneously (waits for remote to complete) * - `local-first-async-remote`: return after local write; remote write is asynchronous (reduces tail latency) * @since v1.1.0 */ export type WritePolicy = 'both' | 'local-first-async-remote'; /** * Multi-level cache policy configuration. * @since v1.1.0 */ export interface MultiLevelCachePolicy { /** Write policy; defaults to `both`. */ writePolicy?: WritePolicy; /** Whether to backfill the local cache on a remote hit; defaults to true. */ backfillLocalOnRemoteHit?: boolean; } /** * Multi-level cache configuration object (declarative two-tier cache setup). * * When passed to `MonSQLizeOptions.cache`, the framework automatically creates a MultiLevelCache: * - `local`: always uses the built-in memory cache (accepts MemoryCacheOptions only) * - `remote`: accepts a CacheLike instance (recommended for production) or a config object * that degrades to an in-memory placeholder * - `policy`: write policy and backfill policy configuration * @since v1.1.0 */ export interface MultiLevelCacheOptions { multiLevel: true; local?: MemoryCacheOptions; remote?: CacheLike | (MemoryCacheOptions & { timeoutMs?: number }); policy?: MultiLevelCachePolicy; publish?: MultiLevelPublish; } export type MultiLevelInvalidationMessage = { type: 'del' | 'delete' | 'invalidateKey'; key: string; ts: number; } | { type: 'delPattern'; pattern: string; ts: number; } | { type: 'invalidateTag'; tag: string; ts: number; }; export type MultiLevelPublish = (msg: MultiLevelInvalidationMessage) => void; export declare class MemoryCache { constructor(options?: MemoryCacheOptions); setLockManager(lockManager: CacheLockLike): void; getLockManager(): CacheLockLike | null; get(key: string): T | undefined; set(key: string, value: unknown, ttl?: number, options?: CacheSetOptions): void; del(key: string): boolean; exists(key: string): boolean; has(key: string): boolean; getMany(keys: string[]): Record; setMany(values: Record, ttl?: number): boolean; delMany(keys: string[]): number; clear(): void; keys(pattern?: string): string[]; delPattern(pattern: string): number; getRemainingTtl(key: string): CacheRemainingTtl | undefined; getRemainingTtlMany(keys: string[]): Record; getStats(): CacheStats; resetStats(): void; invalidateByTag(tag: string): void; destroy(): void; } export declare class MultiLevelCache { constructor(options: { local: CacheLike; remote?: CacheLike; writePolicy?: 'both' | 'local-first-async-remote'; backfillOnRemoteHit?: boolean; remoteTimeoutMs?: number; publish?: MultiLevelPublish; remoteInvalidationErrors?: 'ignore' | 'throw'; }); get(key: string): Promise; set(key: string, value: unknown, ttl?: number, options?: CacheSetOptions): Promise; del(key: string): Promise; exists(key: string): Promise; has(key: string): Promise; clear(): Promise; getMany(keys: string[]): Promise>; setMany(values: Record, ttl?: number): Promise; delMany(keys: string[]): Promise; delPattern(pattern: string): Promise; keys(pattern?: string): Promise; invalidateByTag(tag: string): void | Promise; setPublish(publish: MultiLevelPublish): void; setLockManager(lockManager: CacheLockLike): void; getStats(): CacheStats; resetStats(): void; destroy(): void; } export type RedisCacheAdapterOptions = HubRedisCacheAdapterOptions; export type RedisLike = object; /** * Adapts a v1-style CacheLike object to the v2 CacheLike interface. * * v2 requires a `has()` method that was absent in v1. This helper adds it * by delegating to the existing `exists()`. All other methods are forwarded as-is. * * @param v1Cache - A v1 custom cache implementation missing `has()`. * @returns A fully v2-compatible `CacheLike` instance. * @example * ```ts * const v2Cache = adaptLegacyCacheLike(myV1Cache); * const msq = new MonSQLize({ cache: v2Cache }); * ``` */ export declare function adaptLegacyCacheLike(v1Cache: Omit): CacheLike; /** Re-exported alias so consumers can type the return value of `createRedisCacheAdapter`. */ export type RedisCacheAdapter = HubRedisCacheAdapter; export declare function createRedisCacheAdapter( redisUrlOrInstance: string | object | undefined, options?: RedisCacheAdapterOptions, ): HubRedisCacheAdapter; export type { LockOptions, LockStats, MongoSession, TransactionOptions, TransactionStats }; export type DistributedCacheInvalidatorOptions = HubDistributedInvalidatorOptions; export type DistributedCacheInvalidatorStats = HubInvalidatorStats; export declare class DistributedCacheInvalidator { constructor(options: DistributedCacheInvalidatorOptions); invalidate(pattern: string): Promise; invalidateKey(key: string): Promise; getStats(): HubInvalidatorStats; close(): Promise; } export type { ConnectionPoolManagerOptions, FallbackStrategy, PoolConfig, PoolHealthStatus, PoolRole, PoolStats, PoolStrategy, ResumeTokenConfig, SagaDefinition, SagaOrchestratorOptions, SagaResult, SagaStats, SagaStep, SlowQueryLogConfig, SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, SlowQueryLogQueryOptions, SlowQueryLogRecord, SlowQueryLogStorageConfig, SyncChangeEvent, SyncConfig, SyncStats, SyncTargetConfig, SyncTargetHealthCheckConfig, }; export declare function validateSyncConfig(config: SyncConfig): void; export declare function generateQueryHash(input: unknown): string; export type WithCacheOptions< T extends (...args: any[]) => Promise = (...args: unknown[]) => Promise, > = HubWithCacheOptions; export type CacheStats = HubCacheStats; export interface WithCacheStats extends HubWithCacheStats { calls: number; totalTime: number; avgTime: number; } export interface FunctionCacheStats extends HubFunctionCacheStats { calls: number; totalTime: number; avgTime: number; } export type CachedFunction = HubWrappedFunction<(...args: TArgs) => Promise> & { /** @deprecated Use `stats()`. v1 backward-compat alias. */ getCacheStats(): WithCacheStats; stats(): WithCacheStats; }; export interface FunctionCacheOptions extends HubFunctionCacheOptions { /** @deprecated v1 alias for `ttl`. Use `ttl` instead. */ defaultTTL?: number; } /** * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path; * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage. */ export declare function withCache( fn: (...args: TArgs) => Promise, options?: WithCacheOptions<(...args: TArgs) => Promise>, ): CachedFunction; /** * @deprecated Retained for v1 compatibility. Non-database function caching is no longer a recommended monSQLize feature path; * use `cache-hub` directly or an application-owned cache layer for new generic function-cache usage. */ export declare class FunctionCache { constructor(cacheOrDb?: CacheLike | { getCache(): CacheLike; }, options?: FunctionCacheOptions); register(name: string, fn: (...args: unknown[]) => Promise, options?: { ttl?: number; keyBuilder?: (...args: unknown[]) => string; namespace?: string; condition?: (result: unknown) => boolean; }): Promise; execute(name: string, ...args: unknown[]): Promise; invalidate(name: string, ...args: unknown[]): Promise; invalidatePattern(pattern: string): Promise; getStats(name?: string): FunctionCacheStats | Record | null; list(): string[]; resetStats(name?: string): void; clear(): void; } export declare class Model { static define(name: string, definition: ModelDefinition): void; static get(name: string): RegisteredModel | undefined; static has(name: string): boolean; static list(): string[]; static undefine(name: string): boolean; static redefine(name: string, definition: ModelDefinition): void; static _clear(): void; } export declare class ModelInstance implements ModelInstanceContract { private constructor(...args: unknown[]); readonly collectionName: string; readonly dbName: string; readonly poolName?: string; readonly definition: ModelDefinition; getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; pool?: string; }; getRelations(): Record; getEnums(): Record; raw(): unknown; find(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy>>; findOne(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy | null>; findOneById(id: unknown, options?: unknown): import('./model.mjs').PopulateProxy | null>; findById(id: unknown, options?: unknown): import('./model.mjs').PopulateProxy | null>; findByIds(ids: unknown[], options?: unknown): import('./model.mjs').PopulateProxy>>; findPage(options: { totals: { mode: 'sync'; } & Record; } & Record): import('./model.mjs').PopulateProxy<{ items: Array>; pageInfo: import('./model.mjs').ModelInstance extends { findPage(options?: unknown): import('./model.mjs').PopulateProxy; } ? TResult extends { pageInfo: infer TPageInfo } ? TPageInfo : never : never; totals: import('./model.mjs').ModelInstance extends { findPage(options: { totals: { mode: 'sync'; } & Record; } & Record): import('./model.mjs').PopulateProxy; } ? TResult extends { totals: infer TTotals } ? TTotals : never : never; meta?: import('./collection.mjs').MetaInfo; }>; findPage(options?: unknown): import('./model.mjs').PopulateProxy<{ items: Array>; pageInfo: import('./model.mjs').ModelInstance extends { findPage(options?: unknown): import('./model.mjs').PopulateProxy; } ? TResult extends { pageInfo: infer TPageInfo } ? TPageInfo : never : never; totals?: import('./model.mjs').ModelInstance extends { findPage(options?: unknown): import('./model.mjs').PopulateProxy; } ? TResult extends { totals?: infer TTotals } ? TTotals : never : never; meta?: import('./collection.mjs').MetaInfo; }>; findAndCount(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy<{ data: Array>; total: number; }>; count(query?: unknown, options?: unknown): Promise; insertOne(document?: unknown, options?: unknown): Promise<{ acknowledged: boolean; insertedId: any; }>; insertMany(documents?: unknown[], options?: unknown): Promise; updateOne(filter?: unknown, update?: unknown, options?: unknown): Promise; updateMany(filter?: unknown, update?: unknown, options?: unknown): Promise; replaceOne(filter?: unknown, replacement?: unknown, options?: unknown): Promise; findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise; findOneAndDelete(filter?: unknown, options?: unknown): Promise; upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise; deleteOne(filter?: unknown, options?: unknown): Promise; deleteMany(filter?: unknown, options?: unknown): Promise; createIndex(keys: unknown, options?: unknown): Promise; createIndexes(specs: Array<{ key: unknown; } & Record>): Promise; listIndexes(): Promise[]>; ensureIndexes(options?: ModelEnsureIndexesOptions): Promise; dropIndex(name: string): Promise; dropIndexes(): Promise; prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise; listBookmarks(keyDims?: unknown): Promise; clearBookmarks(keyDims?: unknown): Promise; distinct(key: string, query?: unknown, options?: unknown): Promise; aggregate(pipeline?: unknown[], options?: unknown): Promise; stream(query?: unknown, options?: unknown): NodeJS.ReadableStream; explain(query?: unknown, options?: unknown): Promise; invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise; dropCollection(): Promise; createCollection(name?: string, options?: Record): Promise; createView(name: string, source: string, pipeline?: unknown[]): Promise; indexStats(): Promise; setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>; setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>; setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>; getValidator(): Promise<{ validator: Record | null; validationLevel: string; validationAction: string }>; stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>; renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>; collMod(modifications: Record): Promise>; convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>; watch(pipeline?: unknown[], options?: unknown): import('mongodb').ChangeStream; validate(document?: unknown): import('./model.mjs').ValidationResult; findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise; incrementOne(filter?: unknown, field?: string | Record, increment?: number, options?: unknown): Promise>; findWithDeleted(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy>>; findOnlyDeleted(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy>>; findOneWithDeleted(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy | null>; restore(filter?: unknown, options?: unknown): Promise; restoreMany(filter?: unknown, options?: unknown): Promise; forceDelete(filter?: unknown, options?: unknown): Promise; forceDeleteMany(filter?: unknown, options?: unknown): Promise; findOneOnlyDeleted(query?: unknown, options?: unknown): import('./model.mjs').PopulateProxy | null>; countWithDeleted(query?: unknown, options?: unknown): Promise; countOnlyDeleted(query?: unknown, options?: unknown): Promise; insertBatch(docs: unknown[], options?: unknown): Promise; updateBatch(filter?: unknown, update?: unknown, options?: unknown): Promise; deleteBatch(filter?: unknown, options?: unknown): Promise; } export declare const expr: ExpressionFunction; export declare const createExpression: ExpressionFunction; export declare function isExpressionObject(value: unknown): value is ExpressionObject; export declare function hasExpressionInObject(value: unknown): boolean; export declare function hasExpressionInPipeline(pipeline: unknown): boolean; /** Compile expression objects in a MongoDB pipeline into real operators. */ export declare function compilePipelineExpressions(pipeline: TPipeline): TPipeline;