{"version":3,"file":"singleton.cjs","names":[],"sources":["../../../../src/rest/commands/update/singleton.ts"],"sourcesContent":["import type {\n\tApplyQueryFields,\n\tCollectionType,\n\tNestedPartial,\n\tQuery,\n\tSingletonCollections,\n} from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfCoreCollection, throwIfEmpty } from '../../utils/index.js';\n\nexport type UpdateSingletonOutput<\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 * Update a singleton item\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 updateSingleton =\n\t<\n\t\tSchema,\n\t\tCollection extends SingletonCollections<Schema>,\n\t\tconst TQuery extends Query<Schema, Schema[Collection]>,\n\t\tItem = Schema[Collection],\n\t>(\n\t\tcollection: Collection,\n\t\titem: NestedPartial<Item>,\n\t\tquery?: TQuery,\n\t): RestCommand<UpdateSingletonOutput<Schema, Collection, TQuery>, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(String(collection), 'Collection cannot be empty');\n\t\tthrowIfCoreCollection(collection, 'Cannot use updateSingleton for core collections');\n\n\t\treturn {\n\t\t\tpath: `/items/${collection as string}`,\n\t\t\tparams: query ?? {},\n\t\t\tbody: JSON.stringify(item),\n\t\t\tmethod: 'PATCH',\n\t\t};\n\t};\n"],"mappings":"qGA0Ba,GAOX,EACA,EACA,SAGA,EAAA,aAAa,OAAO,EAAW,CAAE,6BAA6B,CAC9D,EAAA,sBAAsB,EAAY,kDAAkD,CAE7E,CACN,KAAM,UAAU,IAChB,OAAQ,GAAS,EAAE,CACnB,KAAM,KAAK,UAAU,EAAK,CAC1B,OAAQ,QACR"}