{"version":3,"file":"users.cjs","names":[],"sources":["../../../../src/rest/commands/update/users.ts"],"sourcesContent":["import type { DirectusUser } from '../../../schema/user.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 UpdateUserOutput<\n\tSchema,\n\tTQuery extends Query,\n\tItem extends object = DirectusUser,\n> = ApplyQueryFields;\n\n/**\n * Update multiple existing users.\n *\n * @param keys The primary key of the users\n * @param item The user data to update\n * @param query Optional return data query\n *\n * @returns Returns the user objects for the updated users.\n * @throws Will throw if keys is empty\n */\nexport const updateUsers =\n\t>>(\n\t\tkeys: DirectusUser['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: `/users`,\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 users as batch.\n *\n * @param items The user data to update\n * @param query Optional return data query\n *\n * @returns Returns the user objects for the updated users.\n */\nexport const updateUsersBatch =\n\t>>(\n\t\titems: NestedPartial>[],\n\t\tquery?: TQuery,\n\t): RestCommand[], Schema> =>\n\t() => ({\n\t\tpath: `/users`,\n\t\tparams: query ?? {},\n\t\tbody: JSON.stringify(items),\n\t\tmethod: 'PATCH',\n\t});\n\n/**\n * Update an existing user.\n *\n * @param key The primary key of the user\n * @param item The user data to update\n * @param query Optional return data query\n *\n * @returns Returns the user object for the updated user.\n * @throws Will throw if key is empty\n */\nexport const updateUser =\n\t>>(\n\t\tkey: DirectusUser['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: `/users/${key}`,\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 the authenticated user.\n *\n * @param item The user data to update\n * @param query Optional return data query\n *\n * @returns Returns the updated user object for the authenticated user.\n */\nexport const updateMe =\n\t>>(\n\t\titem: NestedPartial>,\n\t\tquery?: TQuery,\n\t): RestCommand, Schema> =>\n\t() => ({\n\t\tpath: `/users/me`,\n\t\tparams: query ?? {},\n\t\tbody: JSON.stringify(item),\n\t\tmethod: 'PATCH',\n\t});\n"],"mappings":"kDAqBa,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,EAWU,GAEX,EACA,SAEM,CACN,KAAM,SACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,QACR,EAYW,GAEX,EACA,EACA,SAGA,EAAA,aAAa,EAAK,sBAAsB,CAEjC,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR,EAWU,GAEX,EACA,SAEM,CACN,KAAM,YACN,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR"}