{"version":3,"file":"items.cjs","names":[],"sources":["../../../../src/rest/commands/read/items.ts"],"sourcesContent":["import type { ApplyQueryFields, CollectionType, Query, QueryItem, RegularCollections } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfCoreCollection, throwIfEmpty } from '../../utils/index.js';\n\nexport type ReadItemOutput<\n\tSchema,\n\tCollection extends RegularCollections<Schema>,\n\tTQuery extends Query<Schema, CollectionType<Schema, Collection>>,\n> = ApplyQueryFields<Schema, CollectionType<Schema, Collection>, TQuery['fields']>;\n\n/**\n * List all items that exist 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 readItems =\n\t<\n\t\tSchema,\n\t\tCollection extends RegularCollections<Schema>,\n\t\tconst TQuery extends Query<Schema, CollectionType<Schema, Collection>>,\n\t>(\n\t\tcollection: Collection,\n\t\tquery?: TQuery,\n\t): RestCommand<ReadItemOutput<Schema, Collection, TQuery>[], Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(collection), 'Collection cannot be empty');\n\t\tthrowIfCoreCollection(collection, 'Cannot use readItems 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\n/**\n * Get an item that exists in Directus.\n *\n * @param collection The collection of the item\n * @param key The primary key of the item\n * @param query The query parameters\n *\n * @returns Returns an item object if a valid primary key was provided.\n * @throws Will throw if collection is a core collection\n * @throws Will throw if collection is empty\n * @throws Will throw if key is empty\n */\nexport const readItem =\n\t<\n\t\tSchema,\n\t\tCollection extends RegularCollections<Schema>,\n\t\tconst TQuery extends QueryItem<Schema, CollectionType<Schema, Collection>>,\n\t>(\n\t\tcollection: Collection,\n\t\tkey: string | number,\n\t\tquery?: TQuery,\n\t): RestCommand<ReadItemOutput<Schema, Collection, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(collection), 'Collection cannot be empty');\n\t\tthrowIfCoreCollection(collection, 'Cannot use readItem for core collections');\n\t\tthrowIfEmpty(String(key), 'Key cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/items/${collection as string}/${key}`,\n\t\t\tparams: query ?? {},\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n"],"mappings":"qGAoBa,GAMX,EACA,SAGA,EAAA,aAAa,OAAO,EAAW,CAAE,6BAA6B,CAC9D,EAAA,sBAAsB,EAAY,4CAA4C,CAEvE,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR,EAeU,GAMX,EACA,EACA,SAGA,EAAA,aAAa,OAAO,EAAW,CAAE,6BAA6B,CAC9D,EAAA,sBAAsB,EAAY,2CAA2C,CAC7E,EAAA,aAAa,OAAO,EAAI,CAAE,sBAAsB,CAEzC,CACN,KAAM,UAAU,EAAqB,GAAG,IACxC,OAAQ,GAAS,EAAE,CACnB,OAAQ,MACR"}