{"version":3,"file":"fields.cjs","names":[],"sources":["../../../../src/rest/commands/read/fields.ts"],"sourcesContent":["import type { DirectusField } from '../../../schema/field.js';\nimport type { ApplyQueryFields } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadFieldOutput<Schema, Item extends object = DirectusField<Schema>> = ApplyQueryFields<Schema, Item, '*'>;\n\n/**\n * List the available fields.\n * @param query The query parameters\n * @returns An array of field objects.\n */\nexport const readFields =\n\t<Schema>(): RestCommand<ReadFieldOutput<Schema>[], Schema> =>\n\t() => ({\n\t\tpath: `/fields`,\n\t\tmethod: 'GET',\n\t});\n\n/**\n * List the available fields in a given collection.\n * @param collection The primary key of the field\n * @returns\n * @throws Will throw if collection is empty\n */\nexport const readFieldsByCollection =\n\t<Schema>(collection: DirectusField<Schema>['collection']): RestCommand<ReadFieldOutput<Schema>[], Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Collection cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/fields/${collection}`,\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n\n/**\n *\n * @param key The primary key of the dashboard\n * @param query The query parameters\n * @returns\n * @throws Will throw if collection is empty\n * @throws Will throw if field is empty\n */\nexport const readField =\n\t<Schema>(\n\t\tcollection: DirectusField<Schema>['collection'],\n\t\tfield: DirectusField<Schema>['field'],\n\t): RestCommand<ReadFieldOutput<Schema>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Collection cannot be empty');\n\t\tthrowIfEmpty(field, 'Field cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/fields/${collection}/${field}`,\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n"],"mappings":"kDAYa,WAEL,CACN,KAAM,UACN,OAAQ,MACR,EAQW,EACH,QAER,EAAA,aAAa,EAAY,6BAA6B,CAE/C,CACN,KAAM,WAAW,IACjB,OAAQ,MACR,EAWU,GAEX,EACA,SAGA,EAAA,aAAa,EAAY,6BAA6B,CACtD,EAAA,aAAa,EAAO,wBAAwB,CAErC,CACN,KAAM,WAAW,EAAW,GAAG,IAC/B,OAAQ,MACR"}