/// /// import type { ObjectIdLike } from 'bson'; import { EventEmitter } from 'events'; import type { Binary, BSONRegExp, Decimal128, Document, Double, Int32, Long, ObjectId, Timestamp } from './bson'; import type { Sort } from './sort'; /** @internal */ export declare type TODO_NODE_3286 = any; /** Given an object shaped type, return the type of the _id field or default to ObjectId @public */ export declare type InferIdType = TSchema extends { _id: infer IdType; } ? Record extends IdType ? never : IdType : TSchema extends { _id?: infer IdType; } ? unknown extends IdType ? ObjectId : IdType : ObjectId; /** Add an _id field to an object shaped type @public */ export declare type WithId = EnhancedOmit & { _id: InferIdType; }; /** * Add an optional _id field to an object shaped type * @public */ export declare type OptionalId = EnhancedOmit & { _id?: InferIdType; }; /** * Adds an optional _id field to an object shaped type, unless the _id field is requried on that type. * In the case _id is required, this method continues to require_id. * * @public * * @privateRemarks * `ObjectId extends TSchema['_id']` is a confusing ordering at first glance. Rather than ask * `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?" * we instead ask "Does ObjectId look like (have the same shape) as the _id?" */ export declare type OptionalUnlessRequiredId = TSchema extends { _id: any; } ? TSchema : OptionalId; /** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */ export declare type EnhancedOmit = string extends keyof TRecordOrUnion ? TRecordOrUnion : TRecordOrUnion extends any ? Pick> : never; /** Remove the _id field from an object shaped type @public */ export declare type WithoutId = Omit; /** A MongoDB filter can be some portion of the schema or a set of operators @public */ export declare type Filter = Partial | ({ [Property in Join>, '.'>]?: Condition, Property>>; } & RootFilterOperators>); /** @public */ export declare type Condition = AlternativeType | FilterOperators>; /** * It is possible to search using alternative types in mongodb e.g. * string types can be searched using a regex in mongo * array types can be searched using their element type * @public */ export declare type AlternativeType = T extends ReadonlyArray ? T | RegExpOrString : RegExpOrString; /** @public */ export declare type RegExpOrString = T extends string ? BSONRegExp | RegExp | T : T; /** @public */ export interface RootFilterOperators extends Document { $and?: Filter[]; $nor?: Filter[]; $or?: Filter[]; $text?: { $search: string; $language?: string; $caseSensitive?: boolean; $diacriticSensitive?: boolean; }; $where?: string | ((this: TSchema) => boolean); $comment?: string | Document; } /** * @public * A type that extends Document but forbids anything that "looks like" an object id. */ export declare type NonObjectIdLikeDocument = { [key in keyof ObjectIdLike]?: never; } & Document; /** @public */ export interface FilterOperators extends NonObjectIdLikeDocument { $eq?: TValue; $gt?: TValue; $gte?: TValue; $in?: ReadonlyArray; $lt?: TValue; $lte?: TValue; $ne?: TValue; $nin?: ReadonlyArray; $not?: TValue extends string ? FilterOperators | RegExp : FilterOperators; /** * When `true`, `$exists` matches the documents that contain the field, * including documents where the field value is null. */ $exists?: boolean; $type?: BSONType | BSONTypeAlias; $expr?: Record; $jsonSchema?: Record; $mod?: TValue extends number ? [number, number] : never; $regex?: TValue extends string ? RegExp | BSONRegExp | string : never; $options?: TValue extends string ? string : never; $geoIntersects?: { $geometry: Document; }; $geoWithin?: Document; $near?: Document; $nearSphere?: Document; $maxDistance?: number; $all?: ReadonlyArray; $elemMatch?: Document; $size?: TValue extends ReadonlyArray ? number : never; $bitsAllClear?: BitwiseFilter; $bitsAllSet?: BitwiseFilter; $bitsAnyClear?: BitwiseFilter; $bitsAnySet?: BitwiseFilter; $rand?: Record; } /** @public */ export declare type BitwiseFilter = number /** numeric bit mask */ | Binary /** BinData bit mask */ | ReadonlyArray; /** `[ , , ... ]` */ /** @public */ export declare const BSONType: Readonly<{ readonly double: 1; readonly string: 2; readonly object: 3; readonly array: 4; readonly binData: 5; readonly undefined: 6; readonly objectId: 7; readonly bool: 8; readonly date: 9; readonly null: 10; readonly regex: 11; readonly dbPointer: 12; readonly javascript: 13; readonly symbol: 14; readonly javascriptWithScope: 15; readonly int: 16; readonly timestamp: 17; readonly long: 18; readonly decimal: 19; readonly minKey: -1; readonly maxKey: 127; }>; /** @public */ export declare type BSONType = typeof BSONType[keyof typeof BSONType]; /** @public */ export declare type BSONTypeAlias = keyof typeof BSONType; /** * @public * Projection is flexible to permit the wide array of aggregation operators * @deprecated since v4.1.0: Since projections support all aggregation operations we have no plans to narrow this type further */ export declare type Projection = Document; /** * @public * @deprecated since v4.1.0: Since projections support all aggregation operations we have no plans to narrow this type further */ export declare type ProjectionOperators = Document; /** @public */ export declare type IsAny = true extends false & Type ? ResultIfAny : ResultIfNotAny; /** @public */ export declare type Flatten = Type extends ReadonlyArray ? Item : Type; /** @public */ export declare type ArrayElement = Type extends ReadonlyArray ? Item : never; /** @public */ export declare type SchemaMember = { [P in keyof T]?: V; } | { [key: string]: V; }; /** @public */ export declare type IntegerType = number | Int32 | Long; /** @public */ export declare type NumericType = IntegerType | Decimal128 | Double; /** @public */ export declare type FilterOperations = T extends Record ? { [key in keyof T]?: FilterOperators; } : FilterOperators; /** @public */ export declare type KeysOfAType = { [key in keyof TSchema]: NonNullable extends Type ? key : never; }[keyof TSchema]; /** @public */ export declare type KeysOfOtherType = { [key in keyof TSchema]: NonNullable extends Type ? never : key; }[keyof TSchema]; /** @public */ export declare type AcceptedFields = { readonly [key in KeysOfAType]?: AssignableType; }; /** It avoids using fields with not acceptable types @public */ export declare type NotAcceptedFields = { readonly [key in KeysOfOtherType]?: never; }; /** @public */ export declare type OnlyFieldsOfType = IsAny, AcceptedFields & NotAcceptedFields & Record>; /** @public */ export declare type MatchKeysAndValues = Readonly<{ [Property in Join, '.'>]?: PropertyType; } & { [Property in `${NestedPathsOfType}.$${`[${string}]` | ''}`]?: ArrayElement>; } & { [Property in `${NestedPathsOfType[]>}.$${`[${string}]` | ''}.${string}`]?: any; }>; /** @public */ export declare type AddToSetOperators = { $each?: Array>; }; /** @public */ export declare type ArrayOperator = { $each?: Array>; $slice?: number; $position?: number; $sort?: Sort; }; /** @public */ export declare type SetFields = ({ readonly [key in KeysOfAType | undefined>]?: OptionalId> | AddToSetOperators>>>; } & NotAcceptedFields | undefined>) & { readonly [key: string]: AddToSetOperators | any; }; /** @public */ export declare type PushOperator = ({ readonly [key in KeysOfAType>]?: Flatten | ArrayOperator>>; } & NotAcceptedFields>) & { readonly [key: string]: ArrayOperator | any; }; /** @public */ export declare type PullOperator = ({ readonly [key in KeysOfAType>]?: Partial> | FilterOperations>; } & NotAcceptedFields>) & { readonly [key: string]: FilterOperators | any; }; /** @public */ export declare type PullAllOperator = ({ readonly [key in KeysOfAType>]?: TSchema[key]; } & NotAcceptedFields>) & { readonly [key: string]: ReadonlyArray; }; /** @public */ export declare type UpdateFilter = { $currentDate?: OnlyFieldsOfType; $inc?: OnlyFieldsOfType; $min?: MatchKeysAndValues; $max?: MatchKeysAndValues; $mul?: OnlyFieldsOfType; $rename?: Record; $set?: MatchKeysAndValues; $setOnInsert?: MatchKeysAndValues; $unset?: OnlyFieldsOfType; $addToSet?: SetFields; $pop?: OnlyFieldsOfType, 1 | -1>; $pull?: PullOperator; $push?: PushOperator; $pullAll?: PullAllOperator; $bit?: OnlyFieldsOfType; } & Document; /** @public */ export declare type Nullable = AnyType | null | undefined; /** @public */ export declare type OneOrMore = T | ReadonlyArray; /** @public */ export declare type GenericListener = (...args: any[]) => void; /** * Event description type * @public */ export declare type EventsDescription = Record; /** @public */ export declare type CommonEvents = 'newListener' | 'removeListener'; /** * Typescript type safe event emitter * @public */ export declare interface TypedEventEmitter extends EventEmitter { addListener(event: EventKey, listener: Events[EventKey]): this; addListener(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; addListener(event: string | symbol, listener: GenericListener): this; on(event: EventKey, listener: Events[EventKey]): this; on(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; on(event: string | symbol, listener: GenericListener): this; once(event: EventKey, listener: Events[EventKey]): this; once(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; once(event: string | symbol, listener: GenericListener): this; removeListener(event: EventKey, listener: Events[EventKey]): this; removeListener(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; removeListener(event: string | symbol, listener: GenericListener): this; off(event: EventKey, listener: Events[EventKey]): this; off(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; off(event: string | symbol, listener: GenericListener): this; removeAllListeners(event?: EventKey | CommonEvents | symbol | string): this; listeners(event: EventKey | CommonEvents | symbol | string): Events[EventKey][]; rawListeners(event: EventKey | CommonEvents | symbol | string): Events[EventKey][]; emit(event: EventKey | symbol, ...args: Parameters): boolean; listenerCount(type: EventKey | CommonEvents | symbol | string): number; prependListener(event: EventKey, listener: Events[EventKey]): this; prependListener(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; prependListener(event: string | symbol, listener: GenericListener): this; prependOnceListener(event: EventKey, listener: Events[EventKey]): this; prependOnceListener(event: CommonEvents, listener: (eventName: string | symbol, listener: GenericListener) => void): this; prependOnceListener(event: string | symbol, listener: GenericListener): this; eventNames(): string[]; getMaxListeners(): number; setMaxListeners(n: number): this; } /** * Typescript type safe event emitter * @public */ export declare class TypedEventEmitter extends EventEmitter { } /** @public */ export declare class CancellationToken extends TypedEventEmitter<{ cancel(): void; }> { } /** * Helper types for dot-notation filter attributes */ /** @public */ export declare type Join = T extends [] ? '' : T extends [string | number] ? `${T[0]}` : T extends [string | number, ...infer R] ? `${T[0]}${D}${Join}` : string; /** @public */ export declare type PropertyType = string extends Property ? unknown : Property extends keyof Type ? Type[Property] : Property extends `${number}` ? Type extends ReadonlyArray ? ArrayType : unknown : Property extends `${infer Key}.${infer Rest}` ? Key extends `${number}` ? Type extends ReadonlyArray ? PropertyType : unknown : Key extends keyof Type ? Type[Key] extends Map ? MapType : PropertyType : unknown : unknown; /** * @public * returns tuple of strings (keys to be joined on '.') that represent every path into a schema * https://docs.mongodb.com/manual/tutorial/query-embedded-documents/ */ export declare type NestedPaths = Type extends string | number | boolean | Date | RegExp | Buffer | Uint8Array | ((...args: any[]) => any) | { _bsontype: string; } ? [] : Type extends ReadonlyArray ? [] | [number, ...NestedPaths] : Type extends Map ? [string] : Type extends object ? { [Key in Extract]: Type[Key] extends Type ? [Key] : Type extends Type[Key] ? [Key] : Type[Key] extends ReadonlyArray ? Type extends ArrayType ? [Key] : ArrayType extends Type ? [Key] : [ Key, ...NestedPaths ] : [ Key, ...NestedPaths ]; }[Extract] : []; /** * @public * returns keys (strings) for every path into a schema with a value of type * https://docs.mongodb.com/manual/tutorial/query-embedded-documents/ */ export declare type NestedPathsOfType = KeysOfAType<{ [Property in Join, '.'>]: PropertyType; }, Type>; //# sourceMappingURL=mongo_types.d.ts.map