{"version":3,"file":"fields.js","names":[],"sources":["../../../../src/rest/commands/update/fields.ts"],"sourcesContent":["import type { DirectusField } from '../../../schema/field.js';\nimport type { ApplyQueryFields, FieldQuery, NestedPartial, Query } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type UpdateFieldOutput<\n\tSchema,\n\tTQuery extends Query,\n\tItem extends object = DirectusField,\n> = ApplyQueryFields;\n\n/**\n * Updates the given field in the given collection.\n * @param collection\n * @param field\n * @param item\n * @param query\n * @returns\n * @throws Will throw if collection is empty\n * @throws Will throw if field is empty\n */\nexport const updateField =\n\t>>(\n\t\tcollection: DirectusField['collection'],\n\t\tfield: DirectusField['field'],\n\t\titem: NestedPartial>,\n\t\tquery?: TQuery,\n\t): RestCommand, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Keys 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\tparams: query ?? {},\n\t\t\tbody: JSON.stringify(item),\n\t\t\tmethod: 'PATCH',\n\t\t};\n\t};\n\n/**\n * Updates the multiple field in the given collection.\n * Update multiple existing fields.\n * @param collection\n * @param items\n * @param query\n * @returns\n * @throws Will throw if collection is empty\n */\nexport const updateFields =\n\t>>(\n\t\tcollection: DirectusField['collection'],\n\t\titems: NestedPartial>[],\n\t\tquery?: TQuery,\n\t): RestCommand[], Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Collection cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/fields/${collection}`,\n\t\t\tparams: query ?? {},\n\t\t\tbody: JSON.stringify(items),\n\t\t\tmethod: 'PATCH',\n\t\t};\n\t};\n"],"mappings":"6DAqBA,MAAa,GAEX,EACA,EACA,EACA,SAGA,EAAa,EAAY,uBAAuB,CAChD,EAAa,EAAO,wBAAwB,CAErC,CACN,KAAM,WAAW,EAAW,GAAG,IAC/B,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR,EAYU,GAEX,EACA,EACA,SAGA,EAAa,EAAY,6BAA6B,CAE/C,CACN,KAAM,WAAW,IACjB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,QACR"}