{"version":3,"file":"operations.js","names":[],"sources":["../../../../src/rest/commands/update/operations.ts"],"sourcesContent":["import type { DirectusOperation } from '../../../schema/operation.js';\nimport type { ApplyQueryFields, NestedPartial, Query } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type UpdateOperationOutput<\n\tSchema,\n\tTQuery extends Query,\n\tItem extends object = DirectusOperation,\n> = ApplyQueryFields;\n\n/**\n * Update multiple existing operations.\n * @param keys\n * @param item\n * @param query\n * @returns Returns the operation objects for the updated operations.\n * @throws Will throw if keys is empty\n */\nexport const updateOperations =\n\t>>(\n\t\tkeys: DirectusOperation['id'][],\n\t\titem: NestedPartial>,\n\t\tquery?: TQuery,\n\t): RestCommand[], Schema> =>\n\t() => {\n\t\tthrowIfEmpty(keys, 'Keys cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/operations`,\n\t\t\tparams: query ?? {},\n\t\t\tbody: JSON.stringify({ keys, data: item }),\n\t\t\tmethod: 'PATCH',\n\t\t};\n\t};\n\n/**\n * Update multiple operations as batch.\n * @param items\n * @param query\n * @returns Returns the operation objects for the updated operations.\n */\nexport const updateOperationsBatch =\n\t>>(\n\t\titems: NestedPartial>[],\n\t\tquery?: TQuery,\n\t): RestCommand[], Schema> =>\n\t() => ({\n\t\tpath: `/operations`,\n\t\tparams: query ?? {},\n\t\tbody: JSON.stringify(items),\n\t\tmethod: 'PATCH',\n\t});\n\n/**\n * Update an existing operation.\n * @param key\n * @param item\n * @param query\n * @returns Returns the operation object for the updated operation.\n * @throws Will throw if key is empty\n */\nexport const updateOperation =\n\t>>(\n\t\tkey: DirectusOperation['id'],\n\t\titem: NestedPartial>,\n\t\tquery?: TQuery,\n\t): RestCommand, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(key, 'Key cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/operations/${key}`,\n\t\t\tparams: query ?? {},\n\t\t\tbody: JSON.stringify(item),\n\t\t\tmethod: 'PATCH',\n\t\t};\n\t};\n"],"mappings":"6DAmBA,MAAa,GAEX,EACA,EACA,SAGA,EAAa,EAAM,uBAAuB,CAEnC,CACN,KAAM,cACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,CAAE,OAAM,KAAM,EAAM,CAAC,CAC1C,OAAQ,QACR,EASU,GAEX,EACA,SAEM,CACN,KAAM,cACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,QACR,EAUW,GAEX,EACA,EACA,SAGA,EAAa,EAAK,sBAAsB,CAEjC,CACN,KAAM,eAAe,IACrB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR"}