Skip to content

Commit

Permalink
fix unload logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 26, 2023
1 parent a489311 commit 31445d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/kbn-test/src/kbn_client/import_export/parse_archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ export interface SavedObject {
[key: string]: unknown;
}

export async function parseArchive(path: string): Promise<SavedObject[]> {
export async function parseArchive(
path: string,
{ stripSummary = false }: { stripSummary?: boolean } = {}
): Promise<SavedObject[]> {
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
);
}
3 changes: 2 additions & 1 deletion packages/kbn-test/src/kbn_client/kbn_client_import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ImportApiResponse {
success: boolean;
[key: string]: unknown;
}

export class KbnClientImportExport {
constructor(
public readonly log: ToolingLog,
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 31445d8

Please sign in to comment.