UNPKG

@dataql/mongodb-adapter

Version:

MongoDB adapter for DataQL with zero API changes

274 lines 7.88 kB
import { Data } from "@dataql/core"; type DataOptions = { dbName?: string; env?: "dev" | "prod"; devPrefix?: string; appToken?: string; customConnection?: any; }; export interface MongoClientOptions { useNewUrlParser?: boolean; useUnifiedTopology?: boolean; maxPoolSize?: number; serverSelectionTimeoutMS?: number; socketTimeoutMS?: number; family?: number; bufferMaxEntries?: number; readPreference?: string; ssl?: boolean; sslValidate?: boolean; sslCA?: string; sslCert?: string; sslKey?: string; sslPass?: string; sslCRL?: string; authSource?: string; authMechanism?: string; dataql?: DataOptions; } export interface InsertOneOptions { bypassDocumentValidation?: boolean; forceServerObjectId?: boolean; writeConcern?: WriteConcern; comment?: any; } export interface InsertManyOptions { bypassDocumentValidation?: boolean; forceServerObjectId?: boolean; ordered?: boolean; writeConcern?: WriteConcern; comment?: any; } export interface UpdateOptions { arrayFilters?: any[]; bypassDocumentValidation?: boolean; collation?: any; hint?: any; upsert?: boolean; writeConcern?: WriteConcern; comment?: any; } export interface ReplaceOptions { bypassDocumentValidation?: boolean; collation?: any; hint?: any; upsert?: boolean; writeConcern?: WriteConcern; comment?: any; } export interface DeleteOptions { collation?: any; hint?: any; writeConcern?: WriteConcern; comment?: any; } export interface FindOptions { allowDiskUse?: boolean; allowPartialResults?: boolean; batchSize?: number; collation?: any; comment?: any; cursorType?: string; hint?: any; limit?: number; max?: any; maxAwaitTimeMS?: number; maxTimeMS?: number; min?: any; noCursorTimeout?: boolean; oplogReplay?: boolean; projection?: any; readConcern?: any; readPreference?: any; returnKey?: boolean; showRecordId?: boolean; skip?: number; sort?: any; tailable?: boolean; awaitData?: boolean; } export interface WriteConcern { w?: number | string; j?: boolean; wtimeout?: number; } export interface InsertOneResult { acknowledged: boolean; insertedId: any; } export interface InsertManyResult { acknowledged: boolean; insertedCount: number; insertedIds: { [key: number]: any; }; } export interface UpdateResult { acknowledged: boolean; matchedCount: number; modifiedCount: number; upsertedId?: any; upsertedCount: number; } export interface DeleteResult { acknowledged: boolean; deletedCount: number; } export interface BulkWriteOptions { ordered?: boolean; bypassDocumentValidation?: boolean; writeConcern?: WriteConcern; comment?: any; } export interface BulkWriteResult { acknowledged: boolean; insertedCount: number; matchedCount: number; modifiedCount: number; deletedCount: number; upsertedCount: number; insertedIds: { [key: number]: any; }; upsertedIds: { [key: number]: any; }; } export type BulkWriteOperation = { insertOne: { document: any; }; } | { updateOne: { filter: any; update: any; upsert?: boolean; }; } | { updateMany: { filter: any; update: any; upsert?: boolean; }; } | { deleteOne: { filter: any; }; } | { deleteMany: { filter: any; }; } | { replaceOne: { filter: any; replacement: any; upsert?: boolean; }; }; export declare class ObjectId { private _id; constructor(id?: string | ObjectId); private _generateObjectId; toString(): string; toHexString(): string; equals(other: ObjectId | string): boolean; getTimestamp(): Date; static isValid(id: any): boolean; static createFromHexString(hexString: string): ObjectId; } export declare class FindCursor<T = any> implements AsyncIterable<T> { private _data; private _collectionName; private _filter; private _options; private _results?; constructor(data: Data, collectionName: string, filter?: any, options?: FindOptions); private get _collection(); private _getDefaultSchema; toArray(): Promise<T[]>; private _applySorting; private _applyProjection; next(): Promise<T | null>; hasNext(): Promise<boolean>; forEach(fn: (doc: T) => void): Promise<void>; map<U>(fn: (doc: T) => U): FindCursor<U>; filter(fn: (doc: T) => boolean): FindCursor<T>; limit(count: number): FindCursor<T>; skip(count: number): FindCursor<T>; sort(sort: any): FindCursor<T>; project(projection: any): FindCursor<T>; count(): Promise<number>; [Symbol.asyncIterator](): AsyncIterator<T>; } export declare class Collection<T = any> { private _data; private _db; collectionName: string; constructor(_data: Data, _db: Db, collectionName: string); private get _collection(); private _getDefaultSchema; insertOne(doc: T, options?: InsertOneOptions): Promise<InsertOneResult>; insertMany(docs: T[], options?: InsertManyOptions): Promise<InsertManyResult>; find(filter?: any, options?: FindOptions): FindCursor<T>; findOne(filter?: any, options?: FindOptions): Promise<T | null>; findOneAndUpdate(filter: any, update: any, options?: UpdateOptions & { returnDocument?: "before" | "after"; }): Promise<{ value: T | null; }>; findOneAndDelete(filter: any): Promise<{ value: T | null; }>; findOneAndReplace(filter: any, replacement: any, options?: ReplaceOptions & { returnDocument?: "before" | "after"; }): Promise<{ value: T | null; }>; updateOne(filter: any, update: any, options?: UpdateOptions): Promise<UpdateResult>; updateMany(filter: any, update: any, options?: UpdateOptions): Promise<UpdateResult>; replaceOne(filter: any, replacement: any, options?: ReplaceOptions): Promise<UpdateResult>; deleteOne(filter: any, options?: DeleteOptions): Promise<DeleteResult>; deleteMany(filter: any, options?: DeleteOptions): Promise<DeleteResult>; bulkWrite(operations: BulkWriteOperation[], options?: BulkWriteOptions): Promise<BulkWriteResult>; countDocuments(filter?: any): Promise<number>; estimatedDocumentCount(): Promise<number>; aggregate(pipeline: any[]): any; createIndex(fieldOrSpec: any, options?: any): Promise<string>; createIndexes(indexSpecs: any[]): Promise<string[]>; dropIndex(indexName: string): Promise<any>; dropIndexes(): Promise<any>; listIndexes(): Promise<any[]>; distinct(field: string, filter?: any): Promise<any[]>; drop(): Promise<boolean>; } export declare class Db { private _data; databaseName: string; constructor(_data: Data, databaseName: string); collection<T = any>(name: string): Collection<T>; listCollections(): Promise<any[]>; dropCollection(name: string): Promise<boolean>; dropDatabase(): Promise<any>; stats(): Promise<any>; } export declare class MongoClient { private _url; private _options?; private _data; private _connected; private _databaseName?; constructor(_url: string, _options?: MongoClientOptions | undefined); private _extractDatabaseName; connect(): Promise<this>; close(): Promise<void>; db(name?: string): Db; isConnected(): boolean; static connect(url: string, options?: MongoClientOptions): Promise<MongoClient>; } export default MongoClient; export declare const BSON: { ObjectId: typeof ObjectId; ObjectID: typeof ObjectId; }; export declare function connect(url: string, options?: MongoClientOptions): Promise<MongoClient>; //# sourceMappingURL=index.d.ts.map