{"version":3,"file":"users.cjs","names":[],"sources":["../../../../src/rest/commands/read/users.ts"],"sourcesContent":["import type { DirectusUser } from '../../../schema/user.js';\nimport type { ApplyQueryFields, Query } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadUserOutput<\n\tSchema,\n\tTQuery extends Query<Schema, Item>,\n\tItem extends object = DirectusUser<Schema>,\n> = ApplyQueryFields<Schema, Item, TQuery['fields']>;\n\n/**\n * List all users that exist in Directus.\n *\n * @param query The query parameters\n *\n * @returns An array of up to limit user objects. If no items are available, data will be an empty array.\n */\nexport const readUsers =\n\t<Schema, const TQuery extends Query<Schema, DirectusUser<Schema>>>(\n\t\tquery?: TQuery,\n\t): RestCommand<ReadUserOutput<Schema, TQuery>[], Schema> =>\n\t() => ({\n\t\tpath: `/users`,\n\t\tparams: query ?? {},\n\t\tmethod: 'GET',\n\t});\n\n/**\n * List an existing user by primary key.\n *\n * @param key The primary key of the user\n * @param query The query parameters\n *\n * @returns Returns the requested user object.\n * @throws Will throw if key is empty\n */\nexport const readUser =\n\t<Schema, const TQuery extends Query<Schema, DirectusUser<Schema>>>(\n\t\tkey: DirectusUser<Schema>['id'],\n\t\tquery?: TQuery,\n\t): RestCommand<ReadUserOutput<Schema, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(key), 'Key cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/users/${key}`,\n\t\t\tparams: query ?? {},\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n\n/**\n * Retrieve the currently authenticated user.\n *\n * @param query The query parameters\n *\n * @returns Returns the user object for the currently authenticated user.\n */\nexport const readMe =\n\t<Schema, const TQuery extends Query<Schema, DirectusUser<Schema>>>(\n\t\tquery?: TQuery,\n\t): RestCommand<ReadUserOutput<Schema, TQuery>, Schema> =>\n\t() => ({\n\t\tpath: `/users/me`,\n\t\tparams: query ?? {},\n\t\tmethod: 'GET',\n\t});\n"],"mappings":"kDAkBa,EAEX,QAEM,CACN,KAAM,SACN,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EAWW,GAEX,EACA,SAGA,EAAA,aAAa,OAAO,EAAI,CAAE,sBAAsB,CAEzC,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EAUU,EAEX,QAEM,CACN,KAAM,YACN,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR"}