import { UnpackList } from "./utils.js"; import { AllCollections, GetCollection, RelationalFields } from "./schema.js"; import { LiteralFields } from "./fields.js"; import { ArrayFunctions, DateFunctions, DateTimeFunctions, MappedFieldNames, MappedFunctionFields, TimeFunctions } from "./functions.js"; import { Query } from "./query.js"; //#region src/types/aggregate.d.ts type GroupingFunctions = { date: "year" | "month" | "week" | "day" | "weekday" | "hour" | "minute" | "second"; array: "count"; }; type AggregationTypes = { count: { output: string | null; wildcard: true; }; countDistinct: { output: string | null; wildcard: true; }; sum: { output: string | null; wildcard: never; }; sumDistinct: { output: string | null; wildcard: never; }; avg: { output: string | null; wildcard: never; }; avgDistinct: { output: string | null; wildcard: never; }; min: { output: number | null; wildcard: never; }; max: { output: number | null; wildcard: never; }; }; /** * Aggregation parameters */ type AggregateRecord = { [Func in keyof AggregationTypes]?: Fields | Fields[] | (AggregationTypes[Func]["wildcard"] extends never ? never : "*") }; /** * GroupBy parameters */ type GroupByFields = WrappedFields, DateTimeFunctions> | WrappedFields, DateFunctions> | WrappedFields, TimeFunctions> | WrappedFields, ArrayFunctions>; /** * Aggregation input options */ type AggregationOptions, Fields = (Collection extends keyof Schema ? keyof UnpackList> : string), Item$1 = (Collection extends keyof Schema ? UnpackList> : object)> = { aggregate: AggregateRecord; groupBy?: (Fields | GroupByFields)[]; query?: Omit, "fields" | "deep" | "alias">; }; /** * Output typing for aggregation */ type AggregationOutput, Options extends AggregationOptions> = ((Options["groupBy"] extends string[] ? UnpackList> extends infer Item ? Item extends object ? MappedFunctionFields extends infer FieldMap ? MappedFieldNames extends infer NamesMap ? { [Field in UnpackList as TranslateFunctionField]: TranslateFunctionField extends keyof Item ? Item[TranslateFunctionField] : never } : never : never : never : never : object) & { [Func in keyof Options["aggregate"]]: Func extends keyof AggregationTypes ? Options["aggregate"][Func] extends string[] ? { [Field in UnpackList]: Field extends "*" ? AggregationTypes[Func]["output"] : { [SubField in Field]: AggregationTypes[Func]["output"] }[Field] } : Options["aggregate"][Func] extends string ? Options["aggregate"][Func] extends "*" ? AggregationTypes[Func]["output"] : { [SubField in Options["aggregate"][Func]]: AggregationTypes[Func]["output"] }[Options["aggregate"][Func]] : never : never })[]; /** * Wrap fields in functions */ type WrappedFields = Fields extends string ? Funcs extends string ? `${Funcs}(${Fields})` : never : never; /** * Translate function names based on provided map */ type TranslateFunctionField = Field$1 extends keyof FieldMap$1 ? FieldMap$1[Field$1] extends string ? FieldMap$1[Field$1] : never : Field$1 extends string ? Field$1 : never; //#endregion export { AggregateRecord, AggregationOptions, AggregationOutput, AggregationTypes, GroupByFields, GroupingFunctions }; //# sourceMappingURL=aggregate.d.ts.map