{"version":3,"file":"files.js","names":[],"sources":["../../../../src/rest/commands/update/files.ts"],"sourcesContent":["import type { DirectusFile } from '../../../schema/file.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 UpdateFileOutput<\n\tSchema,\n\tTQuery extends Query,\n\tItem extends object = DirectusFile,\n> = ApplyQueryFields;\n\n/**\n * Update multiple files at the same time.\n * @param keys\n * @param item\n * @param query\n * @returns Returns the file objects for the updated files.\n * @throws Will throw if keys is empty\n */\nexport const updateFiles =\n\t>>(\n\t\tkeys: DirectusFile['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: `/files`,\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 files as batch.\n * @param items\n * @param query\n * @returns Returns the file objects for the updated files.\n */\nexport const updateFilesBatch =\n\t>>(\n\t\titems: NestedPartial>[],\n\t\tquery?: TQuery,\n\t): RestCommand[], Schema> =>\n\t() => ({\n\t\tpath: `/files`,\n\t\tparams: query ?? {},\n\t\tbody: JSON.stringify(items),\n\t\tmethod: 'PATCH',\n\t});\n\n/**\n * Update an existing file, and/or replace it's file contents.\n * @param key\n * @param item\n * @param query\n * @returns Returns the file object for the updated file.\n * @throws Will throw if key is empty\n */\nexport const updateFile =\n\t>>(\n\t\tkey: DirectusFile['id'],\n\t\titem: NestedPartial> | FormData,\n\t\tquery?: TQuery,\n\t): RestCommand, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(key, 'Key cannot be empty');\n\n\t\tif (item instanceof FormData) {\n\t\t\treturn {\n\t\t\t\tpath: `/files/${key}`,\n\t\t\t\tparams: query ?? {},\n\t\t\t\tbody: item,\n\t\t\t\tmethod: 'PATCH',\n\t\t\t\theaders: { 'Content-Type': 'multipart/form-data' },\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tpath: `/files/${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,SACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,CAAE,OAAM,KAAM,EAAM,CAAC,CAC1C,OAAQ,QACR,EASU,GAEX,EACA,SAEM,CACN,KAAM,SACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,QACR,EAUW,GAEX,EACA,EACA,SAGA,EAAa,EAAK,sBAAsB,CAEpC,aAAgB,SACZ,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,EACN,OAAQ,QACR,QAAS,CAAE,eAAgB,sBAAuB,CAClD,CAGK,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR"}