{"version":3,"file":"versions.cjs","names":[],"sources":["../../../../src/rest/commands/utils/versions.ts"],"sourcesContent":["import type { DirectusVersion } from '../../../schema/version.js';\nimport type { NestedPartial, UnpackList } from '../../../types/index.js';\nimport type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\n/**\n * Save item changes to an existing Content Version.\n *\n * @param id Primary key of the Content Version.\n * @param item The item changes to save to the specified Content Version.\n *\n * @returns State of the item after save.\n */\nexport const saveToContentVersion =\n\t<Schema, Collection extends keyof Schema, Item = UnpackList<Schema[Collection]>>(\n\t\tid: DirectusVersion<Schema>['id'],\n\t\titem: NestedPartial<Item>,\n\t): RestCommand<Item, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(id, 'ID cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/versions/${id}/save`,\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify(item),\n\t\t};\n\t};\n\n/**\n * Compare an existing Content Version with the main version of the item.\n *\n * @param id Primary key of the Content Version.\n *\n * @returns All fields with different values, along with the hash of the main version of the item and the information\nwhether the Content Version is outdated (i.e. main version of the item has been updated since the creation of the\nContent Version)\n */\nexport const compareContentVersion =\n\t<Schema, Collection extends keyof Schema, Item = UnpackList<Schema[Collection]>>(\n\t\tid: DirectusVersion<Schema>['id'],\n\t): RestCommand<\n\t\t{\n\t\t\toutdated: boolean;\n\t\t\tmainHash: string;\n\t\t\tcurrent: Partial<Item>;\n\t\t\tmain: Item;\n\t\t},\n\t\tSchema\n\t> =>\n\t() => {\n\t\tthrowIfEmpty(id, 'ID cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/versions/${id}/compare`,\n\t\t\tmethod: 'GET',\n\t\t};\n\t};\n\n/**\n * Promote an existing Content Version to become the new main version of the item.\n *\n * @param id Primary key of the version.\n * @param mainHash The current hash of the main version of the item (obtained from the `compare` endpoint).\n * @param fields Optional array of field names of which the values are to be promoted. By default, all fields are selected.\n *\n * @returns The primary key of the promoted item.\n */\nexport const promoteContentVersion =\n\t<Schema, Collection extends keyof Schema, Item = UnpackList<Schema[Collection]>>(\n\t\tid: DirectusVersion<Schema>['id'],\n\t\tmainHash: string,\n\t\tfields?: (keyof UnpackList<Item>)[],\n\t): RestCommand<string | number, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(id, 'ID cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/versions/${id}/promote`,\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify(fields ? { mainHash, fields } : { mainHash }),\n\t\t};\n\t};\n"],"mappings":"kDAaa,GAEX,EACA,SAGA,EAAA,aAAa,EAAI,qBAAqB,CAE/B,CACN,KAAM,aAAa,EAAG,OACtB,OAAQ,OACR,KAAM,KAAK,UAAU,EAAK,CAC1B,EAYU,EAEX,QAWA,EAAA,aAAa,EAAI,qBAAqB,CAE/B,CACN,KAAM,aAAa,EAAG,UACtB,OAAQ,MACR,EAYU,GAEX,EACA,EACA,SAGA,EAAA,aAAa,EAAI,qBAAqB,CAE/B,CACN,KAAM,aAAa,EAAG,UACtB,OAAQ,OACR,KAAM,KAAK,UAAU,EAAS,CAAE,WAAU,SAAQ,CAAG,CAAE,WAAU,CAAC,CAClE"}