{"version":3,"file":"relations.cjs","names":[],"sources":["../../../../src/rest/commands/read/relations.ts"],"sourcesContent":["import type { DirectusRelation } from '../../../schema/relation.js';\nimport type { ApplyQueryFields } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadRelationOutput<Schema> = ApplyQueryFields<Schema, DirectusRelation<Schema>, '*'>;\n\n/**\n * List all Relations that exist in Directus.\n * @returns An array of Relation objects. If no items are available, data will be an empty array.\n */\nexport const readRelations =\n\t<Schema>(): RestCommand<ReadRelationOutput<Schema>[], Schema> =>\n\t() => ({\n\t\tpath: `/relations`,\n\t\tmethod: 'GET',\n\t});\n\n/**\n * List all Relations of a collection.\n * @param collection The collection\n * @returns Returns an array of Relation objects if a valid collection name was provided.\n */\nexport const readRelationByCollection =\n\t<Schema>(collection: DirectusRelation<Schema>['collection']): RestCommand<ReadRelationOutput<Schema>[], Schema> =>\n\t() => ({\n\t\tpath: `/relations/${collection}`,\n\t\tmethod: 'GET',\n\t});\n\n/**\n * List an existing Relation by collection and field name.\n * @param collection The collection\n * @param field The field\n * @returns Returns a Relation object if a valid collection and field name was provided.\n * @throws Will throw if collection is empty\n * @throws Will throw if field is empty\n */\nexport const readRelation =\n\t<Schema>(\n\t\tcollection: DirectusRelation<Schema>['collection'],\n\t\tfield: DirectusRelation<Schema>['field'],\n\t): RestCommand<ReadRelationOutput<Schema>, 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\tmethod: 'GET',\n\t\t};\n\t};\n"],"mappings":"kDAWa,WAEL,CACN,KAAM,aACN,OAAQ,MACR,EAOW,EACH,QACF,CACN,KAAM,cAAc,IACpB,OAAQ,MACR,EAUW,GAEX,EACA,SAGA,EAAA,aAAa,EAAY,6BAA6B,CACtD,EAAA,aAAa,EAAO,wBAAwB,CAErC,CACN,KAAM,cAAc,EAAW,GAAG,IAClC,OAAQ,MACR"}