{"version":3,"file":"collections.cjs","names":[],"sources":["../../../../src/rest/commands/read/collections.ts"],"sourcesContent":["import type { DirectusCollection } from '../../../schema/collection.js';\nimport type { ApplyQueryFields } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadCollectionOutput<Schema, Item extends object = DirectusCollection<Schema>> = ApplyQueryFields<\n\tSchema,\n\tItem,\n\t'*'\n>;\n\n/**\n * List the available collections.\n * @returns An array of collection objects.\n */\nexport const readCollections =\n\t<Schema>(): RestCommand<ReadCollectionOutput<Schema>[], Schema> =>\n\t() => ({\n\t\tpath: `/collections`,\n\t\tmethod: 'GET',\n\t});\n\n/**\n * Retrieve a single collection by table name.\n * @param collection The collection name\n * @returns A collection object.\n * @throws Will throw if collection is empty\n */\nexport const readCollection =\n\t<Schema>(collection: DirectusCollection<Schema>['collection']): RestCommand<ReadCollectionOutput<Schema>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Collection cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/collections/${collection}`,\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n"],"mappings":"kDAea,WAEL,CACN,KAAM,eACN,OAAQ,MACR,EAQW,EACH,QAER,EAAA,aAAa,EAAY,6BAA6B,CAE/C,CACN,KAAM,gBAAgB,IACtB,OAAQ,MACR"}