Skip to content

Commit

Permalink
take server code out of public imports, and public code out of server…
Browse files Browse the repository at this point in the history
… imports, and public and server code out of common imports
  • Loading branch information
tsullivan committed Nov 9, 2023
1 parent c9dcbe3 commit 2f29780
Show file tree
Hide file tree
Showing 40 changed files with 232 additions and 252 deletions.
34 changes: 34 additions & 0 deletions packages/kbn-generate-csv-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
import { ByteSizeValue } from '@kbn/config-schema';
import type { SerializedSearchSourceFields } from '@kbn/data-plugin/public';

/**
* @internal
* Needed to separate dependencies from reporting
*/
export interface JobParams {
searchSource: SerializedSearchSourceFields;
columns?: string[];
browserTimezone?: string;
}

/**
* @internal
* Needed to separate dependencies from reporting
*/
export interface CsvConfig {
checkForFormulas: boolean;
escapeFormulaValues: boolean;
Expand All @@ -25,3 +33,29 @@ export interface CsvConfig {
size: number;
};
}

/**
* @internal
* Needed to separate dependencies from reporting
*/
export interface CancellationToken {
isCancelled: () => boolean;
cancel: () => void;
}

/**
* @internal
* Needed to separate dependencies from reporting
*/
export interface TaskRunResult {
content_type: string;
csv_contains_formulas: boolean;
max_size_reached: boolean;
metrics: {
csv: {
rows: number;
};
};
warnings: unknown;
error_code: unknown;
}
5 changes: 5 additions & 0 deletions packages/kbn-generate-csv/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
* Side Public License, v 1.
*/

/**
* These can not be imported from reporting-common due to potential for circular dependency
*/
export const CSV_BOM_CHARS = '\ufeff';
export const CONTENT_TYPE_CSV = 'text/csv';
export const UI_SETTINGS_CSV_SEPARATOR = 'csv:separator';
export const UI_SETTINGS_CSV_QUOTE_VALUES = 'csv:quoteValues';
export const UI_SETTINGS_SEARCH_INCLUDE_FROZEN = 'search:includeFrozen';
export const UI_SETTINGS_DATEFORMAT_TZ = 'dateFormat:tz';
54 changes: 31 additions & 23 deletions packages/kbn-generate-csv/src/generate_csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ import { identity, range } from 'lodash';
import * as Rx from 'rxjs';
import type { Writable } from 'stream';
import { CsvGenerator } from './generate_csv';
import { CancellationToken, UI_SETTINGS_DATEFORMAT_TZ } from '@kbn/reporting-common';
import { CsvConfig, JobParams } from '@kbn/generate-csv-types';
import { UI_SETTINGS_CSV_QUOTE_VALUES, UI_SETTINGS_CSV_SEPARATOR } from './constants';
import { CancellationToken, CsvConfig, JobParams } from '@kbn/generate-csv-types';
import {
UI_SETTINGS_CSV_QUOTE_VALUES,
UI_SETTINGS_CSV_SEPARATOR,
UI_SETTINGS_DATEFORMAT_TZ,
} from './constants';

const createMockJob = (baseObj: any = {}): JobParams => ({
...baseObj,
});

const createMockCancellationToken = (): CancellationToken => ({
isCancelled: () => false,
cancel: jest.fn(),
});

describe('CsvGenerator', () => {
let mockEsClient: IScopedClusterClient;
let mockDataClient: IScopedSearchClient;
Expand Down Expand Up @@ -146,7 +154,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -181,7 +189,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -220,7 +228,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -268,7 +276,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -327,7 +335,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -397,7 +405,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -435,7 +443,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -482,7 +490,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -536,7 +544,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -578,7 +586,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -616,7 +624,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -654,7 +662,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -694,7 +702,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -732,7 +740,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -777,7 +785,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -806,7 +814,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -864,7 +872,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -908,7 +916,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -957,7 +965,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down Expand Up @@ -1016,7 +1024,7 @@ describe('CsvGenerator', () => {
searchSourceStart: mockSearchSourceService,
fieldFormatsRegistry: mockFieldFormatsRegistry,
},
new CancellationToken(),
createMockCancellationToken(),
mockLogger,
stream
);
Expand Down
23 changes: 9 additions & 14 deletions packages/kbn-generate-csv/src/generate_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,26 @@
* Side Public License, v 1.
*/

import { lastValueFrom } from 'rxjs';
import type { Writable } from 'stream';

import { errors as esErrors, estypes } from '@elastic/elasticsearch';
import type { IScopedClusterClient, IUiSettingsClient, Logger } from '@kbn/core/server';
import type { ISearchSource, ISearchStartSearchSource } from '@kbn/data-plugin/common';
import { cellHasFormulas, ES_SEARCH_STRATEGY, tabifyDocs } from '@kbn/data-plugin/common';
import { ES_SEARCH_STRATEGY, cellHasFormulas, tabifyDocs } from '@kbn/data-plugin/common';
import type { IScopedSearchClient } from '@kbn/data-plugin/server';
import type { Datatable } from '@kbn/expressions-plugin/server';
import type {
FieldFormat,
FieldFormatConfig,
IFieldFormatsRegistry,
} from '@kbn/field-formats-plugin/common';
import { lastValueFrom } from 'rxjs';
import type { Writable } from 'stream';
import {
CancellationToken,
byteSizeValueToNumber,
ReportingError,
AuthenticationExpiredError,
} from '@kbn/reporting-common';
import { CsvConfig, JobParams } from '@kbn/generate-csv-types';
import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public';
import { MaxSizeStringBuilder } from './max_size_string_builder';
import { i18nTexts } from './i18n_texts';
import { CsvExportSettings, getExportSettings } from './get_export_settings';

import { CancellationToken, CsvConfig, JobParams, TaskRunResult } from '@kbn/generate-csv-types';
import { CONTENT_TYPE_CSV } from './constants';
import { CsvExportSettings, getExportSettings } from './get_export_settings';
import { i18nTexts } from './i18n_texts';
import { MaxSizeStringBuilder } from './max_size_string_builder';

interface Clients {
es: IScopedClusterClient;
Expand Down
11 changes: 6 additions & 5 deletions packages/kbn-generate-csv/src/get_export_settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
* Side Public License, v 1.
*/

import {
UI_SETTINGS_SEARCH_INCLUDE_FROZEN,
UI_SETTINGS_DATEFORMAT_TZ,
} from '@kbn/reporting-common';
import { IUiSettingsClient } from '@kbn/core/server';
import {
loggingSystemMock,
Expand All @@ -18,7 +14,12 @@ import {
} from '@kbn/core/server/mocks';
import { getExportSettings } from './get_export_settings';
import { CsvConfig } from '@kbn/generate-csv-types';
import { UI_SETTINGS_CSV_QUOTE_VALUES, UI_SETTINGS_CSV_SEPARATOR } from './constants';
import {
UI_SETTINGS_CSV_QUOTE_VALUES,
UI_SETTINGS_CSV_SEPARATOR,
UI_SETTINGS_DATEFORMAT_TZ,
UI_SETTINGS_SEARCH_INCLUDE_FROZEN,
} from './constants';

describe('getExportSettings', () => {
let uiSettingsClient: IUiSettingsClient;
Expand Down
6 changes: 2 additions & 4 deletions packages/kbn-generate-csv/src/get_export_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import { ByteSizeValue } from '@kbn/config-schema';
import type { IUiSettingsClient, Logger } from '@kbn/core/server';
import { createEscapeValue } from '@kbn/data-plugin/common';
import { CsvConfig } from '@kbn/generate-csv-types';
import {
UI_SETTINGS_DATEFORMAT_TZ,
UI_SETTINGS_SEARCH_INCLUDE_FROZEN,
} from '@kbn/reporting-common';
import {
CSV_BOM_CHARS,
UI_SETTINGS_CSV_QUOTE_VALUES,
UI_SETTINGS_CSV_SEPARATOR,
UI_SETTINGS_DATEFORMAT_TZ,
UI_SETTINGS_SEARCH_INCLUDE_FROZEN,
} from './constants';

export interface CsvExportSettings {
Expand Down
2 changes: 0 additions & 2 deletions packages/kbn-generate-csv/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
"@kbn/data-plugin",
"@kbn/expressions-plugin",
"@kbn/field-formats-plugin",
"@kbn/reporting-common",
"@kbn/config-schema",
"@kbn/i18n",
"@kbn/generate-csv-types",
"@kbn/reporting-export-types-helpers-public",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import { ReportingConfigType } from '@kbn/reporting-common';
import { getFullRedirectAppUrl } from './get_full_redirect_app_url';

describe('getFullRedirectAppUrl', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*/

import { format } from 'url';
import { getRedirectAppPath } from '@kbn/reporting-common/constants';
import { ReportingConfigType } from '@kbn/reporting-common/schema';
import { buildKibanaPath } from '@kbn/reporting-common/build_kibana_path';
import { ReportingServerInfo } from './types';
import { buildKibanaPath } from './build_kibana_path';
import { getRedirectAppPath } from './constants';

export function getFullRedirectAppUrl(
config: ReportingConfigType,
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-reporting/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export { buildKibanaPath } from './build_kibana_path';
export * from './constants';
export * from './errors';
export * from './schema_utils';
export * from './schema';
export * as jobTypes from './job_types';
export * from './report_types';
export type {
Expand Down
Loading

0 comments on commit 2f29780

Please sign in to comment.