{"version":3,"file":"fields.cjs","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<Schema, Item>,\n\tItem extends object = DirectusField<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\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<Schema, const TQuery extends FieldQuery<Schema, DirectusField<Schema>>>(\n\t\tcollection: DirectusField<Schema>['collection'],\n\t\tfield: DirectusField<Schema>['field'],\n\t\titem: NestedPartial<DirectusField<Schema>>,\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateFieldOutput<Schema, TQuery>, 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<Schema, const TQuery extends FieldQuery<Schema, DirectusField<Schema>>>(\n\t\tcollection: DirectusField<Schema>['collection'],\n\t\titems: NestedPartial<DirectusField<Schema>>[],\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateFieldOutput<Schema, TQuery>[], 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":"kDAqBa,GAEX,EACA,EACA,EACA,SAGA,EAAA,aAAa,EAAY,uBAAuB,CAChD,EAAA,aAAa,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,aAAa,EAAY,6BAA6B,CAE/C,CACN,KAAM,WAAW,IACjB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,QACR"}