/** * MongoDB-compatible Document Storage Interface * * Core interface defining the API for document storage operations * Provides full MongoDB compatibility with NoSQL optimizations */ export { Document, ObjectId, QueryFilter, FindOptions, UpdateOperators, UpdateOptions, ReplaceOptions, InsertOneResult, InsertManyResult, UpdateResult, DeleteResult, ReplaceOneResult, BulkWriteOperation, BulkWriteOptions, BulkWriteResult, AggregationPipeline, AggregationOptions, AggregationCursor, IndexSpec, IndexInfo, ChangeStream, ChangeStreamOptions, QueryExplain, CollectionOptions, CollectionInfo, ClientSession, TransactionOptions, PaginationResult, ChangeEvent, DocumentError, IndexMapping, FieldAnalysis, SchemaEvolutionEvent, CollectionAnalytics } from './types.js'; export interface IDocumentCollection { readonly name: string; readonly database: string; /** * Find documents matching the filter */ find(filter?: QueryFilter, options?: FindOptions): Promise; /** * Find a single document matching the filter */ findOne(filter?: QueryFilter, options?: FindOptions): Promise; /** * Find documents with cursor-based pagination */ findWithPagination(filter?: QueryFilter, options?: FindOptions & { pageSize?: number; cursor?: string; }): Promise>; /** * Count documents matching the filter */ countDocuments(filter?: QueryFilter): Promise; /** * Get estimated document count (faster but less accurate) */ estimatedDocumentCount(): Promise; /** * Check if any documents match the filter */ exists(filter: QueryFilter): Promise; /** * Get distinct values for a field */ distinct(field: K, filter?: QueryFilter): Promise; /** * Insert a single document */ insertOne(document: Omit & { _id?: ObjectId; }): Promise; /** * Insert multiple documents */ insertMany(documents: (Omit & { _id?: ObjectId; })[], options?: { ordered?: boolean; }): Promise; /** * Update a single document */ updateOne(filter: QueryFilter, update: UpdateOperators | Partial, options?: UpdateOptions): Promise; /** * Update multiple documents */ updateMany(filter: QueryFilter, update: UpdateOperators | Partial, options?: UpdateOptions): Promise; /** * Replace a single document */ replaceOne(filter: QueryFilter, replacement: Omit, options?: ReplaceOptions): Promise; /** * Find and update a document atomically */ findOneAndUpdate(filter: QueryFilter, update: UpdateOperators | Partial, options?: UpdateOptions & { returnDocument?: 'before' | 'after'; includeResultMetadata?: boolean; }): Promise; /** * Find and replace a document atomically */ findOneAndReplace(filter: QueryFilter, replacement: Omit, options?: ReplaceOptions & { returnDocument?: 'before' | 'after'; includeResultMetadata?: boolean; }): Promise; /** * Find and delete a document atomically */ findOneAndDelete(filter: QueryFilter, options?: { includeResultMetadata?: boolean; }): Promise; /** * Delete a single document */ deleteOne(filter: QueryFilter): Promise; /** * Delete multiple documents */ deleteMany(filter: QueryFilter): Promise; /** * Execute multiple operations in a single batch */ bulkWrite(operations: BulkWriteOperation[], options?: BulkWriteOptions): Promise; /** * Initialize an ordered bulk operation builder */ initializeOrderedBulkOp(): IBulkOperationBuilder; /** * Initialize an unordered bulk operation builder */ initializeUnorderedBulkOp(): IBulkOperationBuilder; /** * Execute an aggregation pipeline */ aggregate(pipeline: AggregationPipeline, options?: AggregationOptions): Promise>; /** * Execute aggregation and return all results */ aggregateToArray(pipeline: AggregationPipeline, options?: AggregationOptions): Promise; /** * Create a single index */ createIndex(keyPattern: IndexSpec['key'], options?: IndexSpec['options']): Promise; /** * Create multiple indexes */ createIndexes(indexSpecs: IndexSpec[]): Promise; /** * Drop an index */ dropIndex(indexName: string): Promise; /** * Drop all indexes except _id */ dropIndexes(): Promise; /** * List all indexes */ listIndexes(): Promise; /** * Check if an index exists */ indexExists(indexName: string): Promise; /** * Get index statistics */ indexStats(): Promise>; /** * Reindex the collection */ reIndex(): Promise; /** * Watch for changes in the collection */ watch(pipeline?: AggregationPipeline, options?: ChangeStreamOptions): Promise>; /** * Drop the collection */ drop(): Promise; /** * Rename the collection */ rename(newName: string, options?: { dropTarget?: boolean; }): Promise; /** * Get collection statistics */ stats(): Promise; /** * Validate collection data and indexes */ validate(options?: { full?: boolean; }): Promise; /** * Explain query execution plan */ explain(operation: 'find' | 'aggregate' | 'update' | 'delete', query: any, options?: any): Promise; /** * Get query hints for optimization */ hint(query: QueryFilter): Promise; /** * Get field usage analytics */ analyzeFields(): Promise; /** * Get index recommendations */ getIndexRecommendations(): Promise; /** * Migrate field types */ migrateField(fieldPath: string, transform: (value: any) => any, options?: { dryRun?: boolean; }): Promise; } export interface IBulkOperationBuilder { /** * Add an insert operation */ insert(document: Document): this; /** * Find documents for bulk operations */ find(filter: QueryFilter): IBulkFindOperations; /** * Execute the bulk operation */ execute(): Promise; /** * Get the current batch size */ length: number; } export interface IBulkFindOperations { /** * Update one document */ updateOne(update: UpdateOperators): this; /** * Update multiple documents */ update(update: UpdateOperators): this; /** * Replace one document */ replaceOne(replacement: Document): this; /** * Upsert one document */ upsert(): IBulkUpsertOperations; /** * Delete one document */ deleteOne(): this; /** * Delete multiple documents */ delete(): this; } export interface IBulkUpsertOperations { /** * Update one document with upsert */ updateOne(update: UpdateOperators): this; /** * Replace one document with upsert */ replaceOne(replacement: Document): this; } export interface IDocumentDatabase { readonly name: string; /** * Get a collection */ collection(name: string): IDocumentCollection; /** * Create a collection with options */ createCollection(name: string, options?: CollectionOptions): Promise; /** * Drop a collection */ dropCollection(name: string): Promise; /** * List all collections */ listCollections(): Promise; /** * Rename a collection */ renameCollection(fromName: string, toName: string, options?: { dropTarget?: boolean; }): Promise; /** * Get database statistics */ stats(): Promise; /** * Drop the database */ drop(): Promise; /** * Start a new session */ startSession(options?: any): Promise; /** * Execute operations in a transaction */ withTransaction(session: ClientSession, fn: () => Promise, options?: TransactionOptions): Promise; } export interface IDocumentStorageEngine { /** * Initialize the storage engine */ initialize(): Promise; /** * Create database connection */ createDatabase(name: string): Promise; /** * Get existing database */ getDatabase(name: string): Promise; /** * Drop database */ dropDatabase(name: string): Promise; /** * List all databases */ listDatabases(): Promise; /** * Close all connections */ close(): Promise; /** * Health check */ ping(): Promise; /** * Get storage metrics */ getMetrics(): Promise; } export interface IQueryEngine { /** * Parse MongoDB query to SQL */ translateQuery(collection: string, filter: QueryFilter, options?: FindOptions): Promise<{ sql: string; params: any[]; }>; /** * Parse MongoDB update to SQL */ translateUpdate(collection: string, filter: QueryFilter, update: UpdateOperators, options?: UpdateOptions): Promise<{ sql: string; params: any[]; }>; /** * Parse aggregation pipeline */ translateAggregation(collection: string, pipeline: AggregationPipeline, options?: AggregationOptions): Promise<{ sql: string; params: any[]; stages: string[]; }>; /** * Optimize query execution plan */ optimizeQuery(query: any): Promise; /** * Analyze query performance */ analyzeQuery(query: any): Promise; } export interface IIndexManager { /** * Ensure field is indexed if needed */ ensureFieldIndex(collection: string, fieldPath: string, value: any): Promise; /** * Get available index column */ getAvailableIndexColumn(collection: string): Promise; /** * Register field mapping */ registerFieldMapping(collection: string, fieldPath: string, indexColumn: string, dataType: string): Promise; /** * Get field mapping */ getFieldMapping(collection: string, fieldPath: string): Promise<{ indexColumn: string; dataType: string; } | null>; /** * Analyze query patterns for indexing */ analyzeQueryPatterns(collection: string): Promise; /** * Backfill index for existing documents */ backfillIndex(collection: string, fieldPath: string, indexColumn: string): Promise; } export interface IChangeStreamManager { /** * Create a change stream */ createStream(collection: string, pipeline?: AggregationPipeline, options?: ChangeStreamOptions): Promise>; /** * Close a change stream */ closeStream(streamId: string): Promise; /** * Emit change events */ emitChange(collection: string, change: any): Promise; /** * List active streams */ listActiveStreams(): Promise; } export interface DocumentStorageConfig { d1Database: any; kvStore?: any; r2Bucket?: any; maxIndexedFields?: number; autoIndexThreshold?: number; queryTimeout?: number; maxDocumentSize?: number; enableQueryCache?: boolean; queryCacheTTL?: number; enableAutoIndexing?: boolean; enableSchemaEvolution?: boolean; enableChangeStreams?: boolean; maxChangeStreamConnections?: number; enableQueryLogging?: boolean; enablePerformanceMetrics?: boolean; } //# sourceMappingURL=interface.d.ts.map