import { ObjectId } from 'mongodb'; import type { Collection, Document, WithId } from 'mongodb'; import type { Arrayable } from 'type-fest'; /** * Represents the value of the `_id` property of a MongoDB collection entry. * Optionally, a key other than `_id` can be specified using the `{ key: ..., * id: ... }` syntax. */ export type ItemExistsIdParam = string | ObjectId | { key: string; id: string | ObjectId; }; /** * Available options for the `itemExists` function. */ export type ItemExistsOptions = { /** * Items matching excludeId will be completely ignored by this function. * * @default undefined */ excludeId?: ItemExistsIdParam; /** * If `true`, ids will be matched in a case-insensitive manner (via locale). * * @default false */ caseInsensitive?: boolean; /** * When looking for an item matching `{ _id: id }`, where the descriptor key * is the string `"_id"`, `id` will be optimistically wrapped in a `new * ObjectId(id)` call. Set this to `false` to prevent this. * * @default true */ optimisticCoercion?: boolean; }; /** * Checks if an item matching `{ _id: id }` exists within `collection`, * returning the result (`boolean`). * * This function **does not throw** if the item is not found. */ export declare function itemExists(collection: Collection, id: string | ObjectId, options?: ItemExistsOptions): Promise; /** * Checks if an item matching `{ [descriptor.key]: descriptor.id }` exists * within `collection`, * returning the result (`boolean`). * * This function **does not throw** if the item is not found. */ export declare function itemExists(collection: Collection, descriptor: { key: string; id: string | ObjectId; }, options?: ItemExistsOptions): Promise; /** * Checks if an item matching `id` exists within `collection`, returning the * result (`boolean`). * * This function **does not throw** if the item is not found. */ export declare function itemExists(collection: Collection, id: ItemExistsIdParam, options?: ItemExistsOptions): Promise; /** * The shape of an object that can be translated into an {@link ObjectId} (or * `T`) instance, or is `null`/`undefined`. */ export type IdItem = WithId | string | T | null | undefined; /** * The shape of an array of objects that can be translated into an array of * {@link ObjectId} (or `T`) instances, or are `null`/`undefined`. */ export type IdItemArray = IdItem[]; export type ItemToObjectIdOptions = { /** * If `true`, inputs that cannot be coerced into an {@link ObjectId} will be * replaced with `null` instead of throwing a {@link ValidationError}. * * @default false */ ignoreInvalidId?: boolean; }; /** * Reduces an `item` down to its {@link ObjectId} instance. * * When `options.ignoreInvalidId` is `true`, result may be `null`. */ export declare function itemToObjectId(item: IdItem, options: Exclude & { ignoreInvalidId: true; }): T | null; /** * Reduces an array of `items` down to their respective {@link ObjectId} * instances. * * An attempt is made to eliminate duplicates via `new Set(...)`, but the * absence of duplicates is not guaranteed when `items` contains {@link WithId} * objects. * * When `options.ignoreInvalidId` is `true`, result may contain `null`s. */ export declare function itemToObjectId(items: IdItemArray, options: Exclude & { ignoreInvalidId: true; }): (T | null)[]; /** * Reduces an `item` down to its {@link ObjectId} instance. */ export declare function itemToObjectId(item: IdItem, options?: ItemToObjectIdOptions): T; /** * Reduces an array of `items` down to their respective {@link ObjectId} * instances. * * An attempt is made to eliminate duplicates via `new Set(...)`, but the * absence of duplicates is not guaranteed when `items` contains {@link WithId} * objects. */ export declare function itemToObjectId(items: IdItemArray, options?: ItemToObjectIdOptions): T[]; /** * Reduces `itemOrItems` down to its {@link ObjectId} instance(s). * * When `options.ignoreInvalidId` is `true`, result may be or contain * `null`s. */ export declare function itemToObjectId(itemOrItems: IdItem | IdItemArray, options?: ItemToObjectIdOptions): Arrayable; /** * Reduces an `item` down to the string representation of its {@link ObjectId} * instance. */ export declare function itemToStringId(item: IdItem): string; /** * Reduces an array of `items` down to the string representations of their * respective {@link ObjectId} instances. */ export declare function itemToStringId(items: IdItemArray): string[]; /** * Reduces `itemOrItems` down to the string representation(s) of its * {@link ObjectId} instance(s). */ export declare function itemToStringId(itemOrItems: IdItem | IdItemArray): Arrayable;