import { Filter, UpdateFilter } from 'mongodb'; import * as valleyed from 'valleyed'; import { PipeOutput, Pipe, PipeInput, ConditionalObjectKeys, DistributiveOmit, DeepPartial } from 'valleyed'; import { KafkaEventBus } from './events/adapters/kafka/index.js'; declare const dbChangeConfigPipe: () => valleyed.Pipe<{ debeziumUrl: string; eventBus: KafkaEventBus; }, { debeziumUrl: string; eventBus: KafkaEventBus; }>; type DbChangeConfig = PipeOutput>; type DbConfig = { changes?: DbChangeConfig; }; declare abstract class DbChange, Entity extends Entity> { protected config: DbChangeConfig; protected callbacks: DbChangeCallbacks; protected mapper: (model: Model) => Entity; constructor(config: DbChangeConfig, callbacks: DbChangeCallbacks, mapper: (model: Model) => Entity); protected configureConnector(key: string, data: Record): Promise; } declare enum QueryKeys { and = "and", or = "or" } declare enum Conditions { lt = "lt", lte = "lte", gt = "gt", gte = "gte", eq = "eq", ne = "ne", in = "in", nin = "nin" } declare const queryKeys: Pipe; declare const queryWhere: Pipe<{ field: string; value: any; condition: Conditions | undefined; }, { field: string; value: any; condition: Conditions; }>; declare function queryParamsPipe(): Pipe<{ all: boolean | undefined; limit: number | undefined; page: number | undefined; search: { value: string; fields: string[]; } | null | undefined; sort: { field: string; desc: boolean | undefined; }[] | undefined; whereType: QueryKeys | undefined; where: ({ field: string; value: any; condition: Conditions | undefined; } | { condition: PipeInput; value: PipeInput[]; })[] | undefined; select: string[] | undefined; }, { auth: ({ field: string; value: any; condition: Conditions; } | { condition: PipeOutput; value: PipeOutput[]; })[]; authType: QueryKeys; all: boolean; limit: number; page: number; search: { value: string; fields: string[]; } | null; sort: { field: string; desc: boolean; }[]; whereType: QueryKeys; where: ({ field: string; value: any; condition: Conditions; } | { condition: PipeOutput; value: PipeOutput[]; })[]; select: string[] | undefined; }>; declare function queryResultsPipe(model: Pipe): Pipe<{ pages: { current: number; start: number; last: number; previous: number | null; next: number | null; }; docs: { limit: number; total: number; count: number; }; results: any[]; }, { pages: { current: number; start: number; last: number; previous: number | null; next: number | null; }; docs: { limit: number; total: number; count: number; }; results: T[]; }>; declare function wrapQueryParams(params: QueryParamsInput): QueryParamsBase; type QueryParamsBase = PipeOutput>; type QueryParams | undefined = undefined> = Omit & { select?: S extends undefined ? QueryParamsBase['select'] : S; }; type QueryParamsInput = ConditionalObjectKeys>>; type QueryWhereClause = QueryParamsBase['where'][number]; type QueryWhere = Extract; type QueryWhereBlock = Exclude; type QueryResults = PipeOutput>>; type IdType = { _id: string; } | { id: string; }; type Entity = { toJSON: () => Record; }; type ModelId = T extends Model ? Id[keyof Id] : never; type Model = IdKey & { createdAt?: number; updatedAt?: number; }; type Select = (keyof T)[]; type SelectEntity = S extends readonly (keyof E)[] ? (S[number] extends never ? E : Pick) : E; type Sort = NonNullable[number]; type FindManyOptions | undefined = undefined> = { limit?: number; sort?: Sort | Sort[]; select?: S; }; type FindOneOptions | undefined = undefined> = { select?: S; }; type Table, E extends Entity, Extras extends Record = {}> = { query: | undefined = undefined>(query: QueryParams) => Promise>>; findMany: | undefined = undefined>(filter: Filter, options?: FindManyOptions) => Promise[]>; findOne: | undefined = undefined>(filter: Filter, options?: FindOneOptions) => Promise | null>; findById: | undefined = undefined>(id: ModelId, options?: FindOneOptions) => Promise | null>; insertOne: (values: CreateInput, options?: { makeId?: () => string; getTime?: () => Date; }) => Promise; insertMany: (values: CreateInput[], options?: { makeId?: (i: number) => string; getTime?: () => Date; }) => Promise; updateMany: (filter: Filter, values: UpdateInput, options?: { getTime?: () => Date; }) => Promise; updateOne: (filter: Filter, values: UpdateInput, options?: { getTime?: () => Date; }) => Promise; updateById: (id: ModelId, values: UpdateInput, options?: { getTime?: () => Date; }) => Promise; upsertOne: (filter: Filter, values: { insert: CreateInput; } | { insert: Partial>; update: UpdateInput; }, options?: { makeId?: () => string; getTime?: () => Date; }) => Promise; deleteOne: (filter: Filter) => Promise; deleteById: (id: ModelId) => Promise; deleteMany: (filter: Filter) => Promise; bulkWrite: (operations: BulkWriteOperation[], options?: { getTime?: () => Date; }) => Promise; readonly config: Config; readonly extras: Extras; watch: (callbacks: DbChangeCallbacks) => DbChange; }; type AllKeys = T extends any ? keyof T : never; type EntityInput> = ConditionalObjectKeys | keyof Model>>; type CreateInput> = EntityInput; type UpdateInput> = DistributiveOmit>, '$setOnInsert'>; type BulkWriteOperation> = { op: 'insert'; value: CreateInput; makeId?: (i: number) => string; } | { op: 'update'; filter: Filter; value: UpdateInput; } | ({ op: 'upsert'; filter: Filter; makeId?: (i: number) => string; } & ({ insert: CreateInput; } | { insert: Partial>; update: UpdateInput; })) | { op: 'delete'; filter: Filter; }; type DbChangeCallbacks, E extends Entity> = { created?: (data: { before: null; after: E; }) => Promise; updated?: (data: { before: E; after: E; changes: DeepPartial; }) => Promise; deleted?: (data: { before: E; after: null; }) => Promise; }; type Config, E extends Entity> = { db: string; col: string; mapper: (model: M, select?: Select) => E; options?: { skipAudit?: boolean; }; }; export { type BulkWriteOperation as B, type Config as C, DbChange as D, type Entity as E, type IdType as I, type Model as M, QueryKeys as Q, type Select as S, type Table as T, type UpdateInput as U, type DbChangeConfig as a, type DbChangeCallbacks as b, type DbConfig as c, type EntityInput as d, type CreateInput as e, dbChangeConfigPipe as f, Conditions as g, queryResultsPipe as h, type QueryParamsBase as i, type QueryParams as j, type QueryParamsInput as k, type QueryWhereClause as l, type QueryWhere as m, type QueryWhereBlock as n, type QueryResults as o, queryParamsPipe as q, wrapQueryParams as w };