/** * MongoDB-compatible Document Storage Types * * Comprehensive TypeScript types for NoSQL's schema-free document storage * Compatible with MongoDB query patterns and operators */ export type ObjectId = string; export interface BaseDocument { _id?: ObjectId; _version?: number; _createdAt?: Date; _updatedAt?: Date; [key: string]: any; } export type DocumentValue = string | number | boolean | Date | null | undefined | DocumentValue[] | { [key: string]: DocumentValue; }; export interface Document extends Record { _id?: ObjectId; } export interface QueryFilter { [key: string]: any; } export interface QueryOptions { limit?: number; skip?: number; sort?: Record; projection?: Record; } export interface FindOptions extends QueryOptions { hint?: string | Record; explain?: boolean; } export interface ComparisonOperators { $eq?: T; $ne?: T; $gt?: T; $gte?: T; $lt?: T; $lte?: T; $in?: T[]; $nin?: T[]; } export interface LogicalOperators { $and?: QueryFilter[]; $or?: QueryFilter[]; $not?: QueryFilter; $nor?: QueryFilter[]; } export interface ElementOperators { $exists?: boolean; $type?: string | number; } export interface EvaluationOperators { $regex?: string | RegExp; $options?: string; $text?: { $search: string; $language?: string; $caseSensitive?: boolean; $diacriticSensitive?: boolean; }; $where?: string | Function; $expr?: any; $jsonSchema?: any; $mod?: [number, number]; } export interface ArrayOperators { $all?: T[]; $elemMatch?: QueryFilter; $size?: number; } export interface GeospatialOperators { $geoWithin?: any; $geoIntersects?: any; $near?: any; $nearSphere?: any; } export type QueryOperators = ComparisonOperators | LogicalOperators | ElementOperators | EvaluationOperators | ArrayOperators | GeospatialOperators; export interface UpdateOperators { $set?: Record; $unset?: Record; $inc?: Record; $mul?: Record; $rename?: Record; $min?: Record; $max?: Record; $currentDate?: Record; $addToSet?: Record; $pop?: Record; $pull?: Record; $push?: Record; $pullAll?: Record; } export interface ReplaceOptions { upsert?: boolean; } export interface UpdateOptions extends ReplaceOptions { multi?: boolean; arrayFilters?: any[]; } export interface AggregationStage { $match?: QueryFilter; $project?: Record; $group?: Record; $sort?: Record; $limit?: number; $skip?: number; $unwind?: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean; }; $lookup?: { from: string; localField: string; foreignField: string; as: string; }; $addFields?: Record; $replaceRoot?: { newRoot: any; }; $facet?: Record; $bucket?: { groupBy: any; boundaries: any[]; default?: any; output?: Record; }; $bucketAuto?: { groupBy: any; buckets: number; output?: Record; granularity?: string; }; $count?: string; $sample?: { size: number; }; $geoNear?: any; $graphLookup?: any; [key: string]: any; } export type AggregationPipeline = AggregationStage[]; export interface AggregationOptions { allowDiskUse?: boolean; cursor?: { batchSize?: number; }; maxTimeMS?: number; bypassDocumentValidation?: boolean; readConcern?: any; collation?: any; hint?: string | Record; comment?: string; } export interface IndexKey { [key: string]: 1 | -1 | 'text' | '2d' | '2dsphere' | 'hashed'; } export interface IndexOptions { unique?: boolean; sparse?: boolean; background?: boolean; name?: string; partialFilterExpression?: QueryFilter; expireAfterSeconds?: number; textIndexVersion?: number; weights?: Record; default_language?: string; language_override?: string; '2dsphereIndexVersion'?: number; bits?: number; min?: number; max?: number; bucketSize?: number; collation?: any; wildcardProjection?: Record; } export interface IndexSpec { key: IndexKey; options?: IndexOptions; } export interface IndexInfo { name: string; key: IndexKey; options: IndexOptions; size: number; stats?: { accesses: number; lastAccessed: Date; usage: number; }; } export interface CollectionOptions { capped?: boolean; size?: number; max?: number; validator?: { $jsonSchema?: any; $or?: any[]; }; validationLevel?: 'off' | 'strict' | 'moderate'; validationAction?: 'error' | 'warn'; indexOptionDefaults?: IndexOptions; viewOn?: string; pipeline?: AggregationPipeline; collation?: any; writeConcern?: any; readConcern?: any; comment?: string; } export interface CollectionInfo { name: string; type: 'collection' | 'view'; options: CollectionOptions; info: { readOnly: boolean; uuid?: string; }; idIndex?: IndexInfo; } export interface BulkWriteOperation { insertOne?: { document: Document; }; updateOne?: { filter: QueryFilter; update: UpdateOperators | Document; upsert?: boolean; arrayFilters?: any[]; }; updateMany?: { filter: QueryFilter; update: UpdateOperators | Document; upsert?: boolean; arrayFilters?: any[]; }; replaceOne?: { filter: QueryFilter; replacement: Document; upsert?: boolean; }; deleteOne?: { filter: QueryFilter; }; deleteMany?: { filter: QueryFilter; }; } export interface BulkWriteOptions { ordered?: boolean; bypassDocumentValidation?: boolean; } export interface BulkWriteResult { acknowledged: boolean; insertedCount: number; insertedIds: Record; matchedCount: number; modifiedCount: number; deletedCount: number; upsertedCount: number; upsertedIds: Record; } export interface ChangeStreamOptions { fullDocument?: 'default' | 'updateLookup'; resumeAfter?: any; startAfter?: any; startAtOperationTime?: Date; maxAwaitTimeMS?: number; batchSize?: number; collation?: any; } export interface ChangeEvent { _id: any; operationType: 'insert' | 'update' | 'replace' | 'delete' | 'invalidate' | 'drop' | 'rename' | 'dropDatabase'; fullDocument?: T; fullDocumentBeforeChange?: T; ns: { db: string; coll: string; }; to?: { db: string; coll: string; }; documentKey?: { _id: ObjectId; }; updateDescription?: { updatedFields: Record; removedFields: string[]; }; clusterTime?: Date; txnNumber?: number; lsid?: any; } export interface TransactionOptions { readConcern?: any; writeConcern?: any; readPreference?: any; maxCommitTimeMS?: number; } export interface ClientSession { id: string; inTransaction: boolean; transactionOptions?: TransactionOptions; } export interface SchemaEvolutionEvent { collection: string; field: string; oldType?: string; newType: string; operation: 'add' | 'modify' | 'remove' | 'rename'; timestamp: Date; auto: boolean; } export interface FieldAnalysis { fieldPath: string; dataType: string; frequency: number; lastUsed: Date; queryPatterns: string[]; indexRecommendation?: { recommended: boolean; reason: string; priority: 'high' | 'medium' | 'low'; }; } export interface CollectionAnalytics { collection: string; documentCount: number; averageDocumentSize: number; indexUsage: Record; queryPatterns: Record; fieldAnalysis: FieldAnalysis[]; recommendations: { newIndexes: IndexSpec[]; dropIndexes: string[]; schemaOptimizations: string[]; }; } export interface StorageEngine { name: 'd1' | 'kv' | 'r2'; config: Record; } export interface StorageLocation { engine: StorageEngine; key: string; metadata?: Record; } export interface DocumentStorage { _id: ObjectId; _collection: string; _data: any; _searchText?: string; _vector?: ArrayBuffer; _vectorDims?: number; _locations?: StorageLocation[]; _idx_field_1?: any; _idx_field_2?: any; _idx_field_3?: any; _idx_field_4?: any; _idx_field_5?: any; _idx_field_6?: any; _idx_field_7?: any; _idx_field_8?: any; _idx_field_9?: any; _idx_field_10?: any; } export interface IndexMapping { collection: string; fieldPath: string; indexColumn: string; dataType: string; createdAt: Date; } export interface QueryPlan { stage: string; executionStats: { totalExamined: number; totalDocsReturned: number; executionTimeMillis: number; indexesUsed: string[]; }; children?: QueryPlan[]; } export interface QueryExplain { queryPlanner: { plannerVersion: number; namespace: string; indexFilterSet: boolean; parsedQuery: any; winningPlan: QueryPlan; rejectedPlans: QueryPlan[]; }; executionStats: QueryPlan; } export interface PerformanceMetrics { operationType: string; collection: string; duration: number; documentsExamined: number; documentsReturned: number; indexHits: number; indexMisses: number; timestamp: Date; } export declare class DocumentError extends Error { code: number; collection?: string; operation?: string; constructor(message: string, code?: number, collection?: string, operation?: string); } export declare class ValidationError extends DocumentError { constructor(message: string, collection?: string); } export declare class DuplicateKeyError extends DocumentError { constructor(message: string, collection?: string); } export declare class IndexError extends DocumentError { constructor(message: string, collection?: string); } export interface InsertOneResult { acknowledged: boolean; insertedId: ObjectId; } export interface InsertManyResult { acknowledged: boolean; insertedCount: number; insertedIds: ObjectId[]; } export interface UpdateResult { acknowledged: boolean; matchedCount: number; modifiedCount: number; upsertedId?: ObjectId; upsertedCount: number; } export interface DeleteResult { acknowledged: boolean; deletedCount: number; } export interface ReplaceOneResult { acknowledged: boolean; matchedCount: number; modifiedCount: number; upsertedId?: ObjectId; upsertedCount: number; } export type Flatten = T extends (infer U)[] ? U : T; export type DeepPartial = T extends object ? { [P in keyof T]?: DeepPartial; } : T; export interface PaginationResult { documents: T[]; totalCount: number; hasMore: boolean; nextCursor?: string; } export interface AggregationCursor { hasNext(): Promise; next(): Promise; toArray(): Promise; close(): Promise; } export interface ChangeStream { on(event: 'change', listener: (change: ChangeEvent) => void): this; on(event: 'error', listener: (error: Error) => void): this; on(event: 'close', listener: () => void): this; close(): Promise; isClosed(): boolean; } //# sourceMappingURL=types.d.ts.map