{"version":3,"file":"aggregate.cjs","names":["isSystemCollection"],"sources":["../../../../src/rest/commands/read/aggregate.ts"],"sourcesContent":["import { type AllCollections } from '../../../index.js';\nimport type { AggregationOptions, AggregationOutput } from '../../../types/aggregate.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\nimport { isSystemCollection } from '../../utils/is-system-collection.js';\n\n/**\n * Aggregate allow you to perform calculations on a set of values, returning a single result.\n * @param collection The collection to aggregate\n * @param options The aggregation options\n * @returns Aggregated data\n * @throws Will throw if collection is empty\n */\nexport const aggregate =\n\t<Schema, Collection extends AllCollections<Schema>, Options extends AggregationOptions<Schema, Collection>>(\n\t\tcollection: Collection,\n\t\toptions: Options,\n\t): RestCommand<AggregationOutput<Schema, Collection, Options>, Schema> =>\n\t() => {\n\t\tconst collectionName = String(collection);\n\t\tthrowIfEmpty(collectionName, 'Collection cannot be empty');\n\n\t\tconst path = isSystemCollection(collectionName) ? `/${collectionName.substring(9)}` : `/items/${collectionName}`;\n\n\t\treturn {\n\t\t\tpath,\n\t\t\tmethod: 'GET',\n\t\t\tparams: {\n\t\t\t\t...(options.query ?? {}),\n\t\t\t\t...(options.groupBy ? { groupBy: options.groupBy } : {}),\n\t\t\t\taggregate: options.aggregate,\n\t\t\t},\n\t\t};\n\t};\n"],"mappings":"kIAaA,MAAa,GAEX,EACA,QAEK,CACL,IAAM,EAAiB,OAAO,EAAW,CAKzC,OAJA,EAAA,aAAa,EAAgB,6BAA6B,CAInD,CACN,KAHYA,EAAAA,mBAAmB,EAAe,CAAG,IAAI,EAAe,UAAU,EAAE,GAAK,UAAU,IAI/F,OAAQ,MACR,OAAQ,CACP,GAAI,EAAQ,OAAS,EAAE,CACvB,GAAI,EAAQ,QAAU,CAAE,QAAS,EAAQ,QAAS,CAAG,EAAE,CACvD,UAAW,EAAQ,UACnB,CACD"}