{"version":3,"file":"singleton.cjs","names":[],"sources":["../../../../src/rest/commands/read/singleton.ts"],"sourcesContent":["import type { ApplyQueryFields, CollectionType, Query, QueryItem, SingletonCollections } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfCoreCollection, throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadSingletonOutput<\n\tSchema,\n\tCollection extends SingletonCollections<Schema>,\n\tTQuery extends Query<Schema, Schema[Collection]>,\n> = ApplyQueryFields<Schema, CollectionType<Schema, Collection>, TQuery['fields']>;\n\n/**\n * List the singleton item in Directus.\n *\n * @param collection The collection of the items\n * @param query The query parameters\n *\n * @returns An array of up to limit item objects. If no items are available, data will be an empty array.\n * @throws Will throw if collection is a core collection\n * @throws Will throw if collection is empty\n */\nexport const readSingleton =\n\t<Schema, Collection extends SingletonCollections<Schema>, const TQuery extends QueryItem<Schema, Schema[Collection]>>(\n\t\tcollection: Collection,\n\t\tquery?: TQuery,\n\t): RestCommand<ReadSingletonOutput<Schema, Collection, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(collection), 'Collection cannot be empty');\n\t\tthrowIfCoreCollection(collection, 'Cannot use readSingleton for core collections');\n\n\t\treturn {\n\t\t\tpath: `/items/${collection as string}`,\n\t\t\tparams: query ?? {},\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n"],"mappings":"qGAoBa,GAEX,EACA,SAGA,EAAA,aAAa,OAAO,EAAW,CAAE,6BAA6B,CAC9D,EAAA,sBAAsB,EAAY,gDAAgD,CAE3E,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR"}