Skip to content

Commit

Permalink
[Reporting/NPMigration] typescriptify ExportTypeRegistry, remove from…
Browse files Browse the repository at this point in the history
… server.expose
  • Loading branch information
tsullivan committed Dec 3, 2019
1 parent 45ef370 commit 723ab00
Show file tree
Hide file tree
Showing 30 changed files with 438 additions and 297 deletions.
64 changes: 0 additions & 64 deletions x-pack/legacy/plugins/reporting/common/export_types_registry.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import * as Rx from 'rxjs';
import { first, mergeMap } from 'rxjs/operators';
import { ServerFacade, CaptureConfig } from '../../../../types';
import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers/chromium/driver';
import {
ServerFacade,
CaptureConfig,
HeadlessChromiumDriverFactory,
HeadlessChromiumDriver as HeadlessBrowser,
} from '../../../../types';
import {
ElementsPositionAndAttribute,
ScreenshotResults,
Expand All @@ -26,10 +30,12 @@ import { getElementPositionAndAttributes } from './get_element_position_data';
import { getScreenshots } from './get_screenshots';
import { skipTelemetry } from './skip_telemetry';

export function screenshotsObservableFactory(server: ServerFacade) {
export function screenshotsObservableFactory(
server: ServerFacade,
browserDriverFactory: HeadlessChromiumDriverFactory
) {
const config = server.config();
const captureConfig: CaptureConfig = config.get('xpack.reporting.capture');
const { browserDriverFactory } = server.plugins.reporting!;

return function screenshotsObservable({
logger,
Expand Down
26 changes: 26 additions & 0 deletions x-pack/legacy/plugins/reporting/export_types/csv/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CSV_JOB_TYPE as jobType } from '../../common/constants';
import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types';
import { metadata } from './metadata';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { JobParamsDiscoverCsv, JobDocPayloadDiscoverCsv } from './types';

export const getExportType = (): ExportTypeDefinition<
JobParamsDiscoverCsv,
ESQueueCreateJobFn<JobParamsDiscoverCsv>,
JobDocPayloadDiscoverCsv,
ESQueueWorkerExecuteFn<JobDocPayloadDiscoverCsv>
> => ({
...metadata,
jobType,
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'basic', 'standard', 'gold', 'platinum'],
});
22 changes: 0 additions & 22 deletions x-pack/legacy/plugins/reporting/export_types/csv/server/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../common/constants';
import { ExportTypeDefinition, ImmediateCreateJobFn, ImmediateExecuteFn } from '../../types';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { metadata } from './metadata';
import { JobParamsPanelCsv } from './types';

/*
* These functions are exported to share with the API route handler that
* generates csv from saved object immediately on request.
*/
export { executeJobFactory } from './server/execute_job';
export { createJobFactory } from './server/create_job';

export const getExportType = (): ExportTypeDefinition<
JobParamsPanelCsv,
ImmediateCreateJobFn<JobParamsPanelCsv>,
JobParamsPanelCsv,
ImmediateExecuteFn<JobParamsPanelCsv>
> => ({
...metadata,
jobType: CSV_FROM_SAVEDOBJECT_JOB_TYPE,
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'basic', 'standard', 'gold', 'platinum'],
});

This file was deleted.

27 changes: 27 additions & 0 deletions x-pack/legacy/plugins/reporting/export_types/png/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { PNG_JOB_TYPE as jobType } from '../../common/constants';
import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { metadata } from './metadata';
import { JobParamsPNG, JobDocPayloadPNG } from './types';

export const getExportType = (): ExportTypeDefinition<
JobParamsPNG,
ESQueueCreateJobFn<JobParamsPNG>,
JobDocPayloadPNG,
ESQueueWorkerExecuteFn<JobDocPayloadPNG>
> => ({
...metadata,
jobType,
jobContentEncoding: 'base64',
jobContentExtension: 'PNG',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'standard', 'gold', 'platinum'],
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import * as Rx from 'rxjs';
import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators';
import { PLUGIN_ID, PNG_JOB_TYPE } from '../../../../common/constants';
import { ServerFacade, ExecuteJobFactory, ESQueueWorkerExecuteFn } from '../../../../types';
import {
ServerFacade,
ExecuteJobFactory,
ESQueueWorkerExecuteFn,
HeadlessChromiumDriverFactory,
} from '../../../../types';
import { LevelLogger } from '../../../../server/lib';
import {
decryptJobHeaders,
Expand All @@ -20,8 +25,15 @@ import { generatePngObservableFactory } from '../lib/generate_png';

export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<
JobDocPayloadPNG
>> = function executeJobFactoryFn(server: ServerFacade) {
const generatePngObservable = generatePngObservableFactory(server);
>> = function executeJobFactoryFn(
server: ServerFacade,
{ browserDriverFactory }: { browserDriverFactory?: HeadlessChromiumDriverFactory } = {}
) {
if (!browserDriverFactory) {
throw new Error('Reporting browser driver factory must be passed for PNG job execution');
}

const generatePngObservable = generatePngObservableFactory(server, browserDriverFactory);
const logger = LevelLogger.createForServer(server, [PLUGIN_ID, PNG_JOB_TYPE, 'execute']);

return function executeJob(
Expand Down
23 changes: 0 additions & 23 deletions x-pack/legacy/plugins/reporting/export_types/png/server/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import * as Rx from 'rxjs';
import { map } from 'rxjs/operators';
import { LevelLogger } from '../../../../server/lib';
import { ServerFacade, ConditionalHeaders } from '../../../../types';
import { ServerFacade, HeadlessChromiumDriverFactory, ConditionalHeaders } from '../../../../types';
import { screenshotsObservableFactory } from '../../../common/lib/screenshots';
import { PreserveLayout } from '../../../common/layouts/preserve_layout';
import { LayoutParams } from '../../../common/layouts/layout';

export function generatePngObservableFactory(server: ServerFacade) {
const screenshotsObservable = screenshotsObservableFactory(server);
export function generatePngObservableFactory(
server: ServerFacade,
browserDriverFactory: HeadlessChromiumDriverFactory
) {
const screenshotsObservable = screenshotsObservableFactory(server, browserDriverFactory);

return function generatePngObservable(
logger: LevelLogger,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { PDF_JOB_TYPE as jobType } from '../../common/constants';
import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { metadata } from './metadata';
import { JobParamsPDF, JobDocPayloadPDF } from './types';

export const getExportType = (): ExportTypeDefinition<
JobParamsPDF,
ESQueueCreateJobFn<JobParamsPDF>,
JobDocPayloadPDF,
ESQueueWorkerExecuteFn<JobDocPayloadPDF>
> => ({
...metadata,
jobType,
jobContentEncoding: 'base64',
jobContentExtension: 'pdf',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'standard', 'gold', 'platinum'],
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

import * as Rx from 'rxjs';
import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators';
import { ExecuteJobFactory, ESQueueWorkerExecuteFn, ServerFacade } from '../../../../types';
import {
ServerFacade,
ExecuteJobFactory,
ESQueueWorkerExecuteFn,
HeadlessChromiumDriverFactory,
} from '../../../../types';
import { JobDocPayloadPDF } from '../../types';
import { PLUGIN_ID, PDF_JOB_TYPE } from '../../../../common/constants';
import { LevelLogger } from '../../../../server/lib';
Expand All @@ -21,8 +26,15 @@ import {

export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<
JobDocPayloadPDF
>> = function executeJobFactoryFn(server: ServerFacade) {
const generatePdfObservable = generatePdfObservableFactory(server);
>> = function executeJobFactoryFn(
server: ServerFacade,
{ browserDriverFactory }: { browserDriverFactory?: HeadlessChromiumDriverFactory } = {}
) {
if (!browserDriverFactory) {
throw new Error('Reporting browser driver factory must be passed for PDF job execution');
}

const generatePdfObservable = generatePdfObservableFactory(server, browserDriverFactory);
const logger = LevelLogger.createForServer(server, [PLUGIN_ID, PDF_JOB_TYPE, 'execute']);

return function executeJob(
Expand Down

This file was deleted.

Loading

0 comments on commit 723ab00

Please sign in to comment.