{"version":3,"file":"flows.cjs","names":[],"sources":["../../../../src/rest/commands/update/flows.ts"],"sourcesContent":["import type { DirectusFlow } from '../../../schema/flow.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 UpdateFlowOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusFlow<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\n/**\n * Update multiple existing flows.\n * @param keys\n * @param item\n * @param query\n * @returns Returns the flow objects for the updated flows.\n * @throws Will throw if keys is empty\n */\nexport const updateFlows =\n\t<Schema, const TQuery extends Query<Schema, DirectusFlow<Schema>>>(\n\t\tkeys: DirectusFlow<Schema>['id'][],\n\t\titem: NestedPartial<DirectusFlow<Schema>>,\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateFlowOutput<Schema, TQuery>[], Schema> =>\n\t() => {\n\t\tthrowIfEmpty(keys, 'Keys cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/flows`,\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 flows as batch.\n * @param items\n * @param query\n * @returns Returns the flow objects for the updated flows.\n */\nexport const updateFlowsBatch =\n\t<Schema, const TQuery extends Query<Schema, DirectusFlow<Schema>>>(\n\t\titems: NestedPartial<DirectusFlow<Schema>>[],\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateFlowOutput<Schema, TQuery>[], Schema> =>\n\t() => ({\n\t\tpath: `/flows`,\n\t\tparams: query ?? {},\n\t\tbody: JSON.stringify(items),\n\t\tmethod: 'PATCH',\n\t});\n\n/**\n * Update an existing flow.\n * @param key\n * @param item\n * @param query\n * @returns Returns the flow object for the updated flow.\n * @throws Will throw if key is empty\n */\nexport const updateFlow =\n\t<Schema, const TQuery extends Query<Schema, DirectusFlow<Schema>>>(\n\t\tkey: DirectusFlow<Schema>['id'],\n\t\titem: NestedPartial<DirectusFlow<Schema>>,\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateFlowOutput<Schema, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(key, 'Key cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/flows/${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":"kDAmBa,GAEX,EACA,EACA,SAGA,EAAA,aAAa,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,aAAa,EAAK,sBAAsB,CAEjC,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR"}