{"version":3,"file":"collections.cjs","names":[],"sources":["../../../../src/rest/commands/update/collections.ts"],"sourcesContent":["import type { DirectusCollection } from '../../../schema/collection.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 UpdateCollectionOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusCollection<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\n/**\n * Update the metadata for an existing collection.\n * @param collection\n * @param item\n * @param query\n * @returns The collection object for the updated collection in this request.\n * @throws Will throw if collection is empty\n */\nexport const updateCollection =\n\t<Schema, const TQuery extends Query<Schema, DirectusCollection<Schema>>>(\n\t\tcollection: DirectusCollection<Schema>['collection'],\n\t\titem: NestedPartial<DirectusCollection<Schema>>,\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateCollectionOutput<Schema, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Collection cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/collections/${collection}`,\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 * Update multiple collections as batch.\n * @param items\n * @param query\n * @returns Returns the collection objects for the updated collections.\n */\nexport const updateCollectionsBatch =\n\t<Schema, const TQuery extends Query<Schema, DirectusCollection<Schema>>>(\n\t\titems: NestedPartial<DirectusCollection<Schema>>[],\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateCollectionOutput<Schema, TQuery>, Schema> =>\n\t() => ({\n\t\tpath: `/collections`,\n\t\tparams: query ?? {},\n\t\tbody: JSON.stringify(items),\n\t\tmethod: 'PATCH',\n\t});\n"],"mappings":"kDAmBa,GAEX,EACA,EACA,SAGA,EAAA,aAAa,EAAY,6BAA6B,CAE/C,CACN,KAAM,gBAAgB,IACtB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR,EASU,GAEX,EACA,SAEM,CACN,KAAM,eACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,QACR"}