{"version":3,"file":"items.cjs","names":["isSystemCollection"],"sources":["../../../../src/rest/commands/create/items.ts"],"sourcesContent":["import type { ApplyQueryFields, CollectionType, NestedPartial, Query, UnpackList } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { isSystemCollection } from '../../utils/is-system-collection.js';\n\nexport type CreateItemOutput<\n\tSchema,\n\tCollection extends keyof Schema,\n\tTQuery extends Query<Schema, Schema[Collection]>,\n> = ApplyQueryFields<Schema, CollectionType<Schema, Collection>, TQuery['fields']>;\n\n/**\n * Create new items in the given collection.\n *\n * @param collection The collection of the item\n * @param items The items to create\n * @param query Optional return data query\n *\n * @returns Returns the item objects of the item that were created.\n */\nexport const createItems =\n\t<Schema, Collection extends keyof Schema, const TQuery extends Query<Schema, Schema[Collection]>>(\n\t\tcollection: Collection,\n\t\titems: NestedPartial<UnpackList<Schema[Collection]>>[],\n\t\tquery?: TQuery,\n\t): RestCommand<CreateItemOutput<Schema, Collection, TQuery>[], Schema> =>\n\t() => {\n\t\tconst _collection = String(collection);\n\n\t\tif (isSystemCollection(_collection)) {\n\t\t\tthrow new Error('Cannot use createItems for core collections');\n\t\t}\n\n\t\treturn {\n\t\t\tpath: `/items/${_collection}`,\n\t\t\tparams: query ?? {},\n\t\t\tbody: JSON.stringify(items),\n\t\t\tmethod: 'POST',\n\t\t};\n\t};\n\n/**\n * Create a new item in the given collection.\n *\n * @param collection The collection of the item\n * @param item The item to create\n * @param query Optional return data query\n *\n * @returns Returns the item objects of the item that were created.\n */\nexport const createItem =\n\t<Schema, Collection extends keyof Schema, const TQuery extends Query<Schema, Schema[Collection]>>(\n\t\tcollection: Collection,\n\t\titem: NestedPartial<UnpackList<Schema[Collection]>>,\n\t\tquery?: TQuery,\n\t): RestCommand<CreateItemOutput<Schema, Collection, TQuery>, Schema> =>\n\t() => {\n\t\tconst _collection = String(collection);\n\n\t\tif (isSystemCollection(_collection)) {\n\t\t\tthrow new Error('Cannot use createItem for core collections');\n\t\t}\n\n\t\treturn {\n\t\t\tpath: `/items/${_collection}`,\n\t\t\tparams: query ?? {},\n\t\t\tbody: JSON.stringify(item),\n\t\t\tmethod: 'POST',\n\t\t};\n\t};\n"],"mappings":"wDAmBa,GAEX,EACA,EACA,QAEK,CACL,IAAM,EAAc,OAAO,EAAW,CAEtC,GAAIA,EAAAA,mBAAmB,EAAY,CAClC,MAAU,MAAM,8CAA8C,CAG/D,MAAO,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAM,CAC3B,OAAQ,OACR,EAYU,GAEX,EACA,EACA,QAEK,CACL,IAAM,EAAc,OAAO,EAAW,CAEtC,GAAIA,EAAAA,mBAAmB,EAAY,CAClC,MAAU,MAAM,6CAA6C,CAG9D,MAAO,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,OACR"}