From 31445d839bae4f48d9c52f4c564ae234e0c71483 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Thu, 26 Jan 2023 17:39:13 +0100 Subject: [PATCH] fix unload logic --- .../src/kbn_client/import_export/parse_archive.ts | 14 ++++++++++++-- .../src/kbn_client/kbn_client_import_export.ts | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/kbn-test/src/kbn_client/import_export/parse_archive.ts b/packages/kbn-test/src/kbn_client/import_export/parse_archive.ts index b6b85ba521525..eda37b62cf0d6 100644 --- a/packages/kbn-test/src/kbn_client/import_export/parse_archive.ts +++ b/packages/kbn-test/src/kbn_client/import_export/parse_archive.ts @@ -14,9 +14,19 @@ export interface SavedObject { [key: string]: unknown; } -export async function parseArchive(path: string): Promise { +export async function parseArchive( + path: string, + { stripSummary = false }: { stripSummary?: boolean } = {} +): Promise { return (await Fs.readFile(path, 'utf-8')) .split(/\r?\n\r?\n/) .filter((line) => !!line) - .map((line) => JSON.parse(line)); + .map((line) => JSON.parse(line)) + .filter( + stripSummary + ? (object) => { + return object.type && object.id; + } + : () => true + ); } diff --git a/packages/kbn-test/src/kbn_client/kbn_client_import_export.ts b/packages/kbn-test/src/kbn_client/kbn_client_import_export.ts index 5259b50cfce85..f9646410f64b5 100644 --- a/packages/kbn-test/src/kbn_client/kbn_client_import_export.ts +++ b/packages/kbn-test/src/kbn_client/kbn_client_import_export.ts @@ -25,6 +25,7 @@ interface ImportApiResponse { success: boolean; [key: string]: unknown; } + export class KbnClientImportExport { constructor( public readonly log: ToolingLog, @@ -92,7 +93,7 @@ export class KbnClientImportExport { const src = this.resolveAndValidatePath(path); this.log.debug('unloading docs from archive at', src); - const objects = await parseArchive(src); + const objects = await parseArchive(src, { stripSummary: true }); this.log.info('deleting', objects.length, 'objects', { space: options?.space }); const { deleted, missing } = await this.savedObjects.bulkDelete({