{"version":3,"file":"relations.cjs","names":[],"sources":["../../../../src/rest/commands/update/relations.ts"],"sourcesContent":["import type { DirectusRelation } from '../../../schema/relation.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 UpdateRelationOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusRelation<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\n/**\n * Update an existing relation.\n * @param collection\n * @param field\n * @param item\n * @param query\n * @returns Returns the relation object for the created relation.\n */\nexport const updateRelation =\n\t<Schema, const TQuery extends Query<Schema, DirectusRelation<Schema>>>(\n\t\tcollection: DirectusRelation<Schema>['collection'],\n\t\tfield: DirectusRelation<Schema>['field'],\n\t\titem: NestedPartial<DirectusRelation<Schema>>,\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateRelationOutput<Schema, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection, 'Collection cannot be empty');\n\t\tthrowIfEmpty(field, 'Field cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/relations/${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"],"mappings":"kDAmBa,GAEX,EACA,EACA,EACA,SAGA,EAAA,aAAa,EAAY,6BAA6B,CACtD,EAAA,aAAa,EAAO,wBAAwB,CAErC,CACN,KAAM,cAAc,EAAW,GAAG,IAClC,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR"}