import { S as SchemaDefinition } from '../defineSchema-N1qnU3Md.mjs'; import { MonkoClient } from '../connections/index.mjs'; import { Filter, WithId, ObjectId, InsertOneResult, UpdateFilter, UpdateResult, DeleteResult, Document, Collection } from 'mongodb'; /** * Flattens a complex type into a simpler object type for better readability in tooltips. */ type Prettify = { [K in keyof T]: T[K]; } & {}; /** * Type for document creation - excludes _id which is auto-generated by MongoDB */ type CreateDocument = Omit; /** * Represents the options that can be passed to the populate method. */ interface PopulateOptions { strategy?: "multiple" | "aggregation"; } /** * Utility type to replace a field's type in a document. * It correctly handles optional properties. * * @template Doc The base document type. * @template K The key of the field to replace. * @template T The new type for the field. */ type Populate = Omit & { [P in K]: Doc[P] extends readonly unknown[] ? T[] | Extract : T | Extract; }; interface QueryBuilder extends PromiseLike[]> { populate(field: K, options?: PopulateOptions): QueryBuilder>>; then[], TResult2 = never>(onfulfilled?: ((value: WithId[]) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike) | undefined | null): PromiseLike; toJSON(): Promise>>[]>; } interface SingleQueryBuilder extends PromiseLike | null> { populate(field: K, options?: PopulateOptions): SingleQueryBuilder>>; then | null, TResult2 = never>(onfulfilled?: ((value: WithId | null) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike) | undefined | null): PromiseLike; toJSON(): Promise>> | null>; } /** * Serializes a document type for JSON transport. * It converts types like ObjectId and Date to strings. */ type Primitives = string | number | boolean | null | undefined; type JSONSerialized = T extends Primitives ? T : T extends ObjectId ? string : T extends Date ? string : T extends (infer U)[] ? JSONSerialized[] : T extends ReadonlyArray ? ReadonlyArray> : T extends object ? { [K in keyof T]: JSONSerialized; } : T; interface Model { find(filter?: Filter): QueryBuilder; findOne(filter: Filter): SingleQueryBuilder; create(doc: CreateDocument): Promise>; update(filter: Filter, update: UpdateFilter): Promise; delete(filter: Filter): Promise; toJSON(doc: WithId): Prettify>>; } declare function createModel(schema: S, monkoClient: MonkoClient): Model; interface PopulateInfo { fields: string[]; options: PopulateOptions; } declare function registerSchema(schema: SchemaDefinition): void; declare abstract class QueryBuilderBase implements PromiseLike { protected collection: Collection; protected schema: SchemaDefinition; protected monkoClient: MonkoClient; protected filter: Filter; protected toJSONFunc: (doc: WithId) => Prettify>>; protected populates: PopulateInfo[]; constructor(collection: Collection, schema: SchemaDefinition, monkoClient: MonkoClient, filter: Filter, toJSONFunc: (doc: WithId) => Prettify>>); protected _populate(field: string, options?: PopulateOptions): this; protected abstract executeQuery(): Promise; then(onfulfilled?: ((value: TReturn) => TResult1 | PromiseLike) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): Promise; } declare class QueryBuilderImpl extends QueryBuilderBase[]> implements QueryBuilder { populate(field: K, options?: PopulateOptions): QueryBuilder>>; toJSON(): Promise<(JSONSerialized> extends infer T ? { [K in keyof T]: JSONSerialized>[K]; } : never)[]>; protected executeQuery(): Promise[]>; } declare class SingleQueryBuilderImpl extends QueryBuilderBase | null> implements SingleQueryBuilder { populate(field: K, options?: PopulateOptions): SingleQueryBuilder>>; toJSON(): Promise<(JSONSerialized> extends infer T ? { [K in keyof T]: JSONSerialized>[K]; } : never) | null>; protected executeQuery(): Promise | null>; } export { type JSONSerialized, type Model, type Populate, type PopulateOptions, type Prettify, type QueryBuilder, QueryBuilderImpl, type SingleQueryBuilder, SingleQueryBuilderImpl, createModel, registerSchema };