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