{"version":3,"file":"import.cjs","names":[],"sources":["../../../../src/rest/commands/utils/import.ts"],"sourcesContent":["import type { RestCommand } from '../../types.js';\nimport { throwIfEmpty } from '../../utils/index.js';\n\n/**\n * Import multiple records from a JSON or CSV file into a collection.\n * @returns Nothing\n * @throws Will throw if collection is empty\n */\nexport const utilsImport =\n\t<Schema>(collection: keyof Schema, data: FormData): RestCommand<void, Schema> =>\n\t() => {\n\t\tthrowIfEmpty(collection as string, 'Collection cannot be empty');\n\n\t\treturn {\n\t\t\tpath: `/utils/import/${collection as string}`,\n\t\t\tmethod: 'POST',\n\t\t\tbody: data,\n\t\t\theaders: { 'Content-Type': 'multipart/form-data' },\n\t\t};\n\t};\n\nexport interface ImportBatchOptions {\n\tmode?: 'add' | 'merge';\n\tdryRun?: boolean;\n\tdangerouslyAllowDelete?: boolean;\n}\n\nexport interface ImportBatchCollectionResult {\n\texisting: (string | number)[];\n\tnew: (string | number)[];\n\tdeleted: (string | number)[];\n\tmapped: Record<string, string | number>;\n}\n\nexport interface ImportBatchResult {\n\tapplied: boolean; // `false` for a dry run.\n\tmode: 'add' | 'merge';\n\tcollections: Record<string, ImportBatchCollectionResult>;\n}\n\n/**\n * Import flat data for multiple related collections in a single request. The payload is uploaded as a\n * JSON file (`multipart/form-data`); build the `FormData` with a single file field containing an array\n * of `{ collection, items }` objects.\n *\n * @param data A FormData object holding the JSON file to import.\n * @param options Import mode, dry-run, and destructive-delete flags.\n * @returns Per-collection summary of the changes: existing, new, deleted, and remapped primary keys.\n */\nexport const utilsImportBatch =\n\t<Schema>(data: FormData, options: ImportBatchOptions = {}): RestCommand<ImportBatchResult, Schema> =>\n\t() => ({\n\t\tpath: '/utils/import',\n\t\tmethod: 'POST',\n\t\tparams: options,\n\t\tbody: data,\n\t\theaders: { 'Content-Type': 'multipart/form-data' },\n\t});\n"],"mappings":"kDAQa,GACH,EAA0B,SAElC,EAAA,aAAa,EAAsB,6BAA6B,CAEzD,CACN,KAAM,iBAAiB,IACvB,OAAQ,OACR,KAAM,EACN,QAAS,CAAE,eAAgB,sBAAuB,CAClD,EA+BU,GACH,EAAgB,EAA8B,EAAE,QAClD,CACN,KAAM,gBACN,OAAQ,OACR,OAAQ,EACR,KAAM,EACN,QAAS,CAAE,eAAgB,sBAAuB,CAClD"}