From 1d2f527ce0ed556b516697f27eaf0689afcd1693 Mon Sep 17 00:00:00 2001 From: DmitryAstafyev Date: Mon, 4 Sep 2023 14:50:21 +0200 Subject: [PATCH 1/3] Remove dead-code and unused interfaces --- .../session.stream.extract.executor.ts | 2 +- .../session.stream.get_values.executor.ts | 2 +- .../executors/session.stream.map.executor.ts | 2 +- .../session.stream.nearest.executor.ts | 2 +- .../session.stream.search.executor.ts | 2 +- .../src/api/executors/single.task.extract.ts | 2 +- .../src/api/executors/single.task.search.ts | 2 +- .../apps/rustcore/ts-bindings/src/api/jobs.ts | 2 +- .../ts-bindings/src/api/session.provider.ts | 2 +- .../ts-bindings/src/api/session.search.ts | 10 +- .../ts-bindings/src/api/session.stream.ts | 43 +---- .../apps/rustcore/ts-bindings/src/index.ts | 12 -- .../ts-bindings/src/interfaces/index.ts | 21 --- .../ts-bindings/src/native/native.session.ts | 17 +- .../session/dependencies/charts/index.ts | 6 +- .../service/session/dependencies/search.ts | 2 +- .../search/providers/definitions/events.ts | 1 - .../search/providers/definitions/provider.ts | 1 - .../sidebar/search/providers/providers.ts | 165 ++++++------------ .../ui/views/toolbar/chart/render/chart.ts | 2 +- .../ui/views/toolbar/chart/render/filters.ts | 2 +- .../src/app/ui/views/workspace/map/state.ts | 2 +- application/platform/interfaces/index.ts | 16 -- .../platform/interfaces/interface.adb.ts | 25 --- .../platform/interfaces/interface.detect.ts | 20 --- .../platform/interfaces/interface.electron.ts | 56 ------ .../interfaces/interface.node.global.ts | 28 --- .../interfaces/interface.rust.api.general.ts | 98 ----------- .../interfaces/interface.timerange.ts | 9 - .../platform/ipc/event/values/updated.ts | 2 +- .../platform/ipc/request/search/map.ts | 4 +- .../platform/ipc/request/search/nearest.ts | 2 +- .../platform/ipc/request/values/frame.ts | 2 +- application/platform/lib.ts | 1 - application/platform/types/filter.ts | 41 +++++ 35 files changed, 118 insertions(+), 488 deletions(-) delete mode 100644 application/platform/interfaces/index.ts delete mode 100644 application/platform/interfaces/interface.adb.ts delete mode 100644 application/platform/interfaces/interface.detect.ts delete mode 100644 application/platform/interfaces/interface.electron.ts delete mode 100644 application/platform/interfaces/interface.node.global.ts delete mode 100644 application/platform/interfaces/interface.rust.api.general.ts delete mode 100644 application/platform/interfaces/interface.timerange.ts diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.extract.executor.ts b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.extract.executor.ts index b778ff6b01..6d933034b0 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.extract.executor.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.extract.executor.ts @@ -8,7 +8,7 @@ import { TExtractedValues, IExtractedMatch, IExtractedValue, -} from '../../interfaces/index'; +} from 'platform/types/filter'; export const executor: TExecutor = ( session: RustSession, diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.get_values.executor.ts b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.get_values.executor.ts index 03f49118ed..198b9ff473 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.get_values.executor.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.get_values.executor.ts @@ -1,7 +1,7 @@ import { TExecutor, Logger, CancelablePromise, AsyncResultsExecutor } from './executor'; import { RustSession } from '../../native/native.session'; import { EventProvider } from '../session.provider'; -import { IValuesMap } from '../../interfaces/index'; +import { IValuesMap } from 'platform/types/filter'; import { error } from 'platform/log/utils'; export interface IOptions { diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.map.executor.ts b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.map.executor.ts index f01e698387..bfd2623c4a 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.map.executor.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.map.executor.ts @@ -1,7 +1,7 @@ import { TExecutor, Logger, CancelablePromise, AsyncResultsExecutor } from './executor'; import { RustSession } from '../../native/native.session'; import { EventProvider } from '../../api/session.provider'; -import { ISearchMap } from '../../interfaces/index'; +import { ISearchMap } from 'platform/types/filter'; export interface IOptions { datasetLength: number; diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.nearest.executor.ts b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.nearest.executor.ts index 69f9e3711c..edfe6900eb 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.nearest.executor.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.nearest.executor.ts @@ -1,7 +1,7 @@ import { TExecutor, Logger, CancelablePromise, AsyncResultsExecutor } from './executor'; import { RustSession } from '../../native/native.session'; import { EventProvider } from '../../api/session.provider'; -import { INearest } from '../../interfaces/index'; +import { INearest } from 'platform/types/filter'; export interface IExecuteNearestOptions { positionInStream: number; diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.search.executor.ts b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.search.executor.ts index d2480dc02c..878af841fb 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.search.executor.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/session.stream.search.executor.ts @@ -1,7 +1,7 @@ import { TExecutor, Logger, CancelablePromise, AsyncResultsExecutor } from './executor'; import { RustSession } from '../../native/native.session'; import { EventProvider } from '../../api/session.provider'; -import { IFilter } from '../../interfaces/index'; +import { IFilter } from 'platform/types/filter'; export const executor: TExecutor = ( session: RustSession, diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/single.task.extract.ts b/application/apps/rustcore/ts-bindings/src/api/executors/single.task.extract.ts index 98dae7c14e..b6cdbac534 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/single.task.extract.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/single.task.extract.ts @@ -1,7 +1,7 @@ import { RustSession } from '../../native/native.session'; import { ICancelablePromise } from 'platform/env/promise'; import { EventProvider } from '../../api/session.provider'; -import { IFilter, TExtractedValues } from '../../interfaces/index'; +import { IFilter, TExtractedValues } from 'platform/types/filter'; import { Executors } from './session.stream.executors'; import { TaskManager } from './single.task'; import { scope } from 'platform/env/scope'; diff --git a/application/apps/rustcore/ts-bindings/src/api/executors/single.task.search.ts b/application/apps/rustcore/ts-bindings/src/api/executors/single.task.search.ts index 049150ceba..0324ff4c59 100644 --- a/application/apps/rustcore/ts-bindings/src/api/executors/single.task.search.ts +++ b/application/apps/rustcore/ts-bindings/src/api/executors/single.task.search.ts @@ -2,7 +2,7 @@ import { scope } from 'platform/env/scope'; import { RustSession } from '../../native/native.session'; import { ICancelablePromise } from 'platform/env/promise'; import { EventProvider } from '../../api/session.provider'; -import { IFilter } from '../../interfaces/index'; +import { IFilter } from 'platform/types/filter'; import { Executors } from './session.stream.executors'; import { TaskManager } from './single.task'; diff --git a/application/apps/rustcore/ts-bindings/src/api/jobs.ts b/application/apps/rustcore/ts-bindings/src/api/jobs.ts index c59b2fa03e..63926270e9 100644 --- a/application/apps/rustcore/ts-bindings/src/api/jobs.ts +++ b/application/apps/rustcore/ts-bindings/src/api/jobs.ts @@ -1,7 +1,7 @@ import { CancelablePromise } from 'platform/env/promise'; import { Base } from '../native/native.jobs'; import { error } from 'platform/log/utils'; -import { IFilter } from '../interfaces/index'; +import { IFilter } from 'platform/types/filter'; import { ShellProfile } from 'platform/types/shells'; import { SomeipStatistic } from 'platform/types/observe/parser/someip'; import { StatisticInfo } from 'platform/types/observe/parser/dlt'; diff --git a/application/apps/rustcore/ts-bindings/src/api/session.provider.ts b/application/apps/rustcore/ts-bindings/src/api/session.provider.ts index 37a3820769..9a0938e240 100644 --- a/application/apps/rustcore/ts-bindings/src/api/session.provider.ts +++ b/application/apps/rustcore/ts-bindings/src/api/session.provider.ts @@ -2,7 +2,7 @@ import { Subject } from 'platform/env/subscription'; import { ISearchUpdated } from 'platform/types/filter'; import { Computation } from '../provider/provider'; import { EErrorKind, EErrorSeverity } from '../provider/provider.errors'; -import { IMapEntity, IMatchEntity, IValuesMinMaxMap } from '../interfaces/index'; +import { IMapEntity, IMatchEntity, IValuesMinMaxMap } from 'platform/types/filter'; import { IAttachment } from 'platform/types/content'; export interface IProgressState { diff --git a/application/apps/rustcore/ts-bindings/src/api/session.search.ts b/application/apps/rustcore/ts-bindings/src/api/session.search.ts index 0fc0ff0d2f..7d900a7d51 100644 --- a/application/apps/rustcore/ts-bindings/src/api/session.search.ts +++ b/application/apps/rustcore/ts-bindings/src/api/session.search.ts @@ -3,14 +3,8 @@ import { scope } from 'platform/env/scope'; import { RustSession } from '../native/native.session'; import { ICancelablePromise } from 'platform/env/promise'; import { EventProvider } from '../api/session.provider'; -import { - IFilter, - IGrabbedElement, - ISearchMap, - TExtractedValues, - INearest, - IValuesMap, -} from '../interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; +import { IFilter, ISearchMap, TExtractedValues, INearest, IValuesMap } from 'platform/types/filter'; import { Executors } from './executors/session.stream.executors'; import { SearchTaskManager } from './executors/single.task.search'; import { ValuesTaskManager } from './executors/single.task.values'; diff --git a/application/apps/rustcore/ts-bindings/src/api/session.stream.ts b/application/apps/rustcore/ts-bindings/src/api/session.stream.ts index 668eae393f..44b73d876d 100644 --- a/application/apps/rustcore/ts-bindings/src/api/session.stream.ts +++ b/application/apps/rustcore/ts-bindings/src/api/session.stream.ts @@ -6,18 +6,12 @@ import { SdeRequest, SdeResponse } from 'platform/types/sde'; import { EventProvider } from '../api/session.provider'; import { Executors } from './executors/session.stream.executors'; import { EFileOptionsRequirements } from './executors/session.stream.observe.executor'; -import { - IGrabbedElement, - IExtractDTFormatOptions, - IExtractDTFormatResult, -} from '../interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { IRange } from 'platform/types/range'; import { ISourceLink } from 'platform/types/observe/types'; import { Attachment, IndexingMode } from 'platform/types/content'; import { IObserve } from 'platform/types/observe'; -export { IExtractDTFormatOptions, IExtractDTFormatResult }; - export class SessionStream { private readonly _provider: EventProvider; private readonly _session: RustSession; @@ -116,41 +110,6 @@ export class SessionStream { return Executors.exportRaw(this._session, this._provider, this._logger, { dest, ranges }); } - public extractTimeformat(options: IExtractDTFormatOptions): IExtractDTFormatResult | Error { - let results: IExtractDTFormatResult | Error = this._session.extract(options); - if (typeof results !== 'object' || results === null) { - results = new Error( - `Expecting {IExtractDTFormatOptions} as result of "extractTimeformat", but has been gotten: ${typeof results}`, - ); - } else if ( - typeof results === 'object' && - (typeof (results as IExtractDTFormatResult).format !== 'string' || - typeof (results as IExtractDTFormatResult).reg !== 'string' || - typeof (results as IExtractDTFormatResult).timestamp !== 'number') - ) { - results = new Error( - `Expecting {IExtractDTFormatOptions} as result of "extractTimeformat", but has been gotten: ${JSON.stringify( - results, - )}`, - ); - } - if (results instanceof Error) { - this._logger.warn( - `Fail to apply "extractTimeformat", options: ${JSON.stringify( - options, - )} due error: ${results.message}`, - ); - } - return results; - } - - public connect(): { - //dlt: (options: IDLTOptions) => Connector, - //adb: (options: IADBOptions) => Connector, - } { - return {}; - } - public len(): Promise { return this._session.getStreamLen(); } diff --git a/application/apps/rustcore/ts-bindings/src/index.ts b/application/apps/rustcore/ts-bindings/src/index.ts index 272fb68ed0..da344f180b 100644 --- a/application/apps/rustcore/ts-bindings/src/index.ts +++ b/application/apps/rustcore/ts-bindings/src/index.ts @@ -24,18 +24,6 @@ export { } from './api/session'; export { Jobs } from './api/jobs'; export { Tracker } from './api/tracker'; -export { - IGrabbedElement, - IExtractDTFormatOptions, - IExtractDTFormatResult, - IResultSearchElement, - IMapEntity, - IMatchEntity, - IFilter, - IFilterFlags, - IGrabbedContent, - IValuesMap, -} from './interfaces/index'; export { Units, Events, Interfaces }; export * as $ from 'platform/types/observe'; diff --git a/application/apps/rustcore/ts-bindings/src/interfaces/index.ts b/application/apps/rustcore/ts-bindings/src/interfaces/index.ts index 7c5ed0ba17..213f83454d 100644 --- a/application/apps/rustcore/ts-bindings/src/interfaces/index.ts +++ b/application/apps/rustcore/ts-bindings/src/interfaces/index.ts @@ -1,22 +1 @@ -export { - IFilter, - IFilterFlags, - IGrabbedContent, - IGrabbedElement, - IResultSearchElement, - ISearchMap, - TExtractedValuesSrc, - IExtractedValueSrc, - TExtractedValues, - IExtractedMatch, - IExtractedValue, - IExtractDTFormatOptions, - IExtractDTFormatResult, - IMatchEntity, - IMapEntity, - INearest, - IValuesMap, - IValuesMinMaxMap, -} from 'platform/interfaces/interface.rust.api.general'; -export { Logger, TLogFunc, IChipmunkNodeGlobal } from 'platform/interfaces/interface.node.global'; export { OperationStat } from '../interfaces/debug'; diff --git a/application/apps/rustcore/ts-bindings/src/native/native.session.ts b/application/apps/rustcore/ts-bindings/src/native/native.session.ts index f63118265c..7f6a3ab107 100644 --- a/application/apps/rustcore/ts-bindings/src/native/native.session.ts +++ b/application/apps/rustcore/ts-bindings/src/native/native.session.ts @@ -2,12 +2,8 @@ import { RustSessionRequiered } from '../native/native.session.required'; import { TEventEmitter } from '../provider/provider.general'; import { Computation } from '../provider/provider'; -import { - IFilter, - IGrabbedElement, - IExtractDTFormatResult, - IExtractDTFormatOptions, -} from '../interfaces/index'; +import { IFilter } from 'platform/types/filter'; +import { IGrabbedElement } from 'platform/types/content'; import { getNativeModule } from '../native/native'; import { EFileOptionsRequirements } from '../api/executors/session.stream.observe.executor'; import { Type, Source, NativeError } from '../interfaces/errors'; @@ -141,11 +137,6 @@ export abstract class RustSession extends RustSessionRequiered { public abstract isRawExportAvailable(): Promise; - /** - * This operation is sync. - */ - public abstract extract(options: IExtractDTFormatOptions): IExtractDTFormatResult | NativeError; - public abstract search(filters: IFilter[], operationUuid: string): Promise; public abstract searchValues(filters: string[], operationUuid: string): Promise; @@ -908,10 +899,6 @@ export class RustSessionWrapper extends RustSession { }); } - public extract(options: IExtractDTFormatOptions): IExtractDTFormatResult | NativeError { - return new NativeError(new Error('Not implemented yet'), Type.Other, Source.Extract); - } - public search(filters: IFilter[], operationUuid: string): Promise { return new Promise((resolve, reject) => { try { diff --git a/application/client/src/app/service/session/dependencies/charts/index.ts b/application/client/src/app/service/session/dependencies/charts/index.ts index 0436600558..06a57dea9c 100644 --- a/application/client/src/app/service/session/dependencies/charts/index.ts +++ b/application/client/src/app/service/session/dependencies/charts/index.ts @@ -1,11 +1,7 @@ import { SetupLogger, LoggerInterface } from '@platform/entity/logger'; import { Subject, Subjects, Subscriber } from '@platform/env/subscription'; import { isDevMode } from '@angular/core'; -import { - IValuesMap, - IValuesMinMaxMap, - ISearchMap, -} from '@platform/interfaces/interface.rust.api.general'; +import { IValuesMap, IValuesMinMaxMap, ISearchMap } from '@platform/types/filter'; import { cutUuid } from '@log/index'; import { IRange } from '@platform/types/range'; import { Cursor } from './cursor'; diff --git a/application/client/src/app/service/session/dependencies/search.ts b/application/client/src/app/service/session/dependencies/search.ts index 22fdfd26c8..e732704698 100644 --- a/application/client/src/app/service/session/dependencies/search.ts +++ b/application/client/src/app/service/session/dependencies/search.ts @@ -1,6 +1,6 @@ import { SetupLogger, LoggerInterface } from '@platform/entity/logger'; import { Subscriber, Subjects, Subject } from '@platform/env/subscription'; -import { ISearchMap, INearest } from '@platform/interfaces/interface.rust.api.general'; +import { ISearchMap, INearest } from '@platform/types/filter'; import { cutUuid } from '@log/index'; import { IFilter, ISearchUpdated } from '@platform/types/filter'; import { IRange } from '@platform/types/range'; diff --git a/application/client/src/app/ui/views/sidebar/search/providers/definitions/events.ts b/application/client/src/app/ui/views/sidebar/search/providers/definitions/events.ts index 1d8de21b96..6386816c1b 100644 --- a/application/client/src/app/ui/views/sidebar/search/providers/definitions/events.ts +++ b/application/client/src/app/ui/views/sidebar/search/providers/definitions/events.ts @@ -16,5 +16,4 @@ export interface ProviderEvents { edit: Subject; context: Subject; doubleclick: Subject; - reload: Subject; } diff --git a/application/client/src/app/ui/views/sidebar/search/providers/definitions/provider.ts b/application/client/src/app/ui/views/sidebar/search/providers/definitions/provider.ts index 78f01d0df5..54ab9aa9f0 100644 --- a/application/client/src/app/ui/views/sidebar/search/providers/definitions/provider.ts +++ b/application/client/src/app/ui/views/sidebar/search/providers/definitions/provider.ts @@ -72,7 +72,6 @@ export abstract class Provider extends Subscriber { edit: new Subject(), context: new Subject(), doubleclick: new Subject(), - reload: new Subject(), }); public readonly session: Session; public readonly logger: Logger; diff --git a/application/client/src/app/ui/views/sidebar/search/providers/providers.ts b/application/client/src/app/ui/views/sidebar/search/providers/providers.ts index ef61c62e4e..b3fb255a40 100644 --- a/application/client/src/app/ui/views/sidebar/search/providers/providers.ts +++ b/application/client/src/app/ui/views/sidebar/search/providers/providers.ts @@ -20,8 +20,6 @@ import { bridge } from '@service/bridge'; import { HistorySession } from '@service/history/session'; import { Notification, notifications } from '@ui/service/notifications'; -type TSelectedEntities = string[]; - export class Providers { public readonly subjects: Subjects = new Subjects({ select: new Subject(), @@ -56,7 +54,6 @@ export class Providers { provider.destroy(); }); this._keyboard.destroy(); - this._store().drop(); } public add(name: ProviderData, providerConstructor: ProviderConstructor): boolean { @@ -71,7 +68,6 @@ export class Providers { provider.subjects.get().context.subscribe(this._onContextMenuEvent.bind(this)); provider.subjects.get().doubleclick.subscribe(this._onDoubleclickEvent.bind(this)); provider.subjects.get().change.subscribe(this._onChange.bind(this)); - provider.subjects.get().reload.subscribe(this._onReload.bind(this)); provider.subjects.get().edit.subscribe(this._onEdit.bind(this)); provider.init(); this._providers.set(name, provider); @@ -260,64 +256,6 @@ export class Providers { }; } - private _store(): { - load(): TSelectedEntities; - save(entities: TSelectedEntities): void; - restore(provider: string): void; - drop(): void; - } { - const self = this; - return { - load: () => { - return []; - // if (self._session === undefined) { - // return []; - // } - // const stored: TSelectedEntities | undefined = self._session - // .getScope() - // .get(PROVIDERS_SCOPE_KEY); - // return stored === undefined ? [] : stored.slice(); - }, - save: (entities: TSelectedEntities) => { - console.log(`Not implemented: ${entities}`); - // if (self._session === undefined) { - // return; - // } - // self._session - // .getScope() - // .set(PROVIDERS_SCOPE_KEY, entities.slice()); - }, - restore: (provider: string) => { - const stored = self._store().load(); - this._providers.forEach((target: Provider) => { - if (provider !== target.uuid) { - return; - } - target.select().drop(self.SENDER); - target.select().apply(self.SENDER, stored); - if (stored.length === 1) { - const entity = target.entities().find((e) => e.uuid() === stored[0]); - entity !== undefined && - this.subjects.get().select.emit({ - entity: entity, - provider: target, - guids: stored, - }); - } - }); - if (stored.length === 0) { - this.subjects.get().select.emit(undefined); - } - }, - drop: () => { - // if (self._session === undefined) { - // return; - // } - // self._session.getScope().delete(PROVIDERS_SCOPE_KEY); - }, - }; - } - private _onSelectionEntity(event: ISelectEvent) { if (event.sender === this.SENDER) { // Ignore events triggered by holder @@ -358,7 +296,6 @@ export class Providers { this._providers.forEach((provider: Provider) => { provider.setLastSelection(guids.length > 0 ? event.entity : undefined); }); - this._store().save(guids); } private _onContextMenuEvent(event: IContextMenuEvent) { @@ -506,13 +443,11 @@ export class Providers { this.injectGeneralMenuItems(event.items); this.subjects.get().context.emit(event); - } - public injectGeneralMenuItems(items: IMenuItem[]): void { const historySession = history.get(this.session); - if(historySession === undefined) { + if (historySession === undefined) { this.logger.error('History session is not defined'); return; } @@ -520,14 +455,17 @@ export class Providers { /* Delimiter */ }); const store = this.session.search.store(); - const showExport: boolean = (store.filters().get().length + store.charts().get().length + store.disabled().get().length) !== 0; - showExport && items.push( - { - caption: 'Export All to File', - handler: () => this.filters(historySession).export(), - }); - items.push( - { + const showExport: boolean = + store.filters().get().length + + store.charts().get().length + + store.disabled().get().length !== + 0; + showExport && + items.push({ + caption: 'Export All to File', + handler: () => this.filters(historySession).export(), + }); + items.push({ caption: 'Import from File', handler: () => this.filters(historySession).import(), }); @@ -540,50 +478,57 @@ export class Providers { new Notification({ message: error.message, session: this.session.uuid(), - actions: [] - }) + actions: [], + }), ); }; return { import: (): void => { - bridge.files().select.text() - .then(file => { - if (file.length !== 1) { - this.logger.error('No file selected'); - return; - } - history.import(file[0].filename) - .then((uuids: string[]) => { - if (uuids.length === 0) { - this.logger.warn('File does not have a collection'); + bridge + .files() + .select.text() + .then((file) => { + if (file.length !== 1) { + this.logger.error('No file selected'); return; } - if (uuids.length > 1) { - this.session.switch().toolbar.presets(); - return; - } else { - const collection = history.collections.get(uuids[0]); - if (collection === undefined) { - this.logger.error(`Cannot find imported collection with UUID: ${uuids[0]}`); - return; - } - historySession.apply(collection); - } + history + .import(file[0].filename) + .then((uuids: string[]) => { + if (uuids.length === 0) { + this.logger.warn('File does not have a collection'); + return; + } + if (uuids.length > 1) { + this.session.switch().toolbar.presets(); + return; + } else { + const collection = history.collections.get(uuids[0]); + if (collection === undefined) { + this.logger.error( + `Cannot find imported collection with UUID: ${uuids[0]}`, + ); + return; + } + historySession.apply(collection); + } + }) + .catch((error) => logAndNotifyError(error)); }) - .catch(error => logAndNotifyError(error)); - }) - .catch(error => logAndNotifyError(error)) + .catch((error) => logAndNotifyError(error)); }, export: (): void => { - bridge.files().select.save() - .then((filename: string | undefined) => { - if (filename === undefined) - return; - history.export([historySession.collections.uuid], filename) - .catch(error => logAndNotifyError(error)) - }) - .catch(error => logAndNotifyError(error)) + bridge + .files() + .select.save() + .then((filename: string | undefined) => { + if (filename === undefined) return; + history + .export([historySession.collections.uuid], filename) + .catch((error) => logAndNotifyError(error)); + }) + .catch((error) => logAndNotifyError(error)); }, }; } @@ -597,10 +542,6 @@ export class Providers { this.subjects.get().change.emit(); } - private _onReload(provider: string) { - this._store().restore(provider); - } - private _onEdit(guid: string | undefined) { this.subjects.get().edit.emit(guid); } diff --git a/application/client/src/app/ui/views/toolbar/chart/render/chart.ts b/application/client/src/app/ui/views/toolbar/chart/render/chart.ts index 2533a0202c..8df9f2f942 100644 --- a/application/client/src/app/ui/views/toolbar/chart/render/chart.ts +++ b/application/client/src/app/ui/views/toolbar/chart/render/chart.ts @@ -1,4 +1,4 @@ -import { IValuesMap, IValuesMinMaxMap } from '@platform/interfaces/interface.rust.api.general'; +import { IValuesMap, IValuesMinMaxMap } from '@platform/types/filter'; import { scheme_color_0, scheme_color_5_75, shadeColor } from '@styles/colors'; import { Base } from './render'; import { ChartRequest, ChartType } from '@service/session/dependencies/search/charts/request'; diff --git a/application/client/src/app/ui/views/toolbar/chart/render/filters.ts b/application/client/src/app/ui/views/toolbar/chart/render/filters.ts index 37f5d7b337..456a686bb6 100644 --- a/application/client/src/app/ui/views/toolbar/chart/render/filters.ts +++ b/application/client/src/app/ui/views/toolbar/chart/render/filters.ts @@ -1,4 +1,4 @@ -import { ISearchMap } from '@platform/interfaces/interface.rust.api.general'; +import { ISearchMap } from '@platform/types/filter'; import { scheme_color_2, scheme_color_match } from '@styles/colors'; import { Base } from './render'; import { FilterRequest } from '@service/session/dependencies/search/filters/request'; diff --git a/application/client/src/app/ui/views/workspace/map/state.ts b/application/client/src/app/ui/views/workspace/map/state.ts index 54d3a4567b..e0326d4f5f 100644 --- a/application/client/src/app/ui/views/workspace/map/state.ts +++ b/application/client/src/app/ui/views/workspace/map/state.ts @@ -1,4 +1,4 @@ -import { ISearchMap } from '@platform/interfaces/interface.rust.api.general'; +import { ISearchMap } from '@platform/types/filter'; import { Session } from '@service/session'; import { scheme_color_5, scheme_color_match, scheme_color_2 } from '@styles/colors'; diff --git a/application/platform/interfaces/index.ts b/application/platform/interfaces/index.ts deleted file mode 100644 index 422bf8e1f1..0000000000 --- a/application/platform/interfaces/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -export * as global from './interface.node.global'; -export * as detect from './interface.detect'; -export * as timeranges from './interface.timerange'; -export * as electron from './interface.electron'; -export * as api from './interface.rust.api.general'; - -// describes a section of a file by indicies -// to identify lines 10-12 (inclusively) => first_line = 10, last_line = 12 -// to identify only line 13: first_line = 13, last_line = 13 -export interface IIndexSection { - first_line: number; - last_line: number; -} -export interface IFileSaveParams { - sections: Array; -} diff --git a/application/platform/interfaces/interface.adb.ts b/application/platform/interfaces/interface.adb.ts deleted file mode 100644 index 819f203d89..0000000000 --- a/application/platform/interfaces/interface.adb.ts +++ /dev/null @@ -1,25 +0,0 @@ -export interface IAdbDevice { - name: string; - type: string; -} - -export interface IAdbProcess { - user: string; - pid: number | undefined; - ppid: number | undefined; - vsz: number | undefined; - rss: number | undefined; - wchan: number | undefined; - addr: number | undefined; - s: string; - name: string; -} - -export interface IAdbSession { - devices: IAdbDevice[]; - processes: IAdbProcess[]; - device: string | undefined; - pid: number | undefined; - logLevel: string; - recieved: number; -} \ No newline at end of file diff --git a/application/platform/interfaces/interface.detect.ts b/application/platform/interfaces/interface.detect.ts deleted file mode 100644 index f5ae3253d8..0000000000 --- a/application/platform/interfaces/interface.detect.ts +++ /dev/null @@ -1,20 +0,0 @@ -export interface ITimestampFormat { - Ok?: ITimestampFormatOk, - Err?: string, -} -export interface ITimestampFormatOk { - format: string; - regex: string; - flags: string[]; -} -export interface ICheckFormatFlags { - miss_day: boolean, - miss_month: boolean, - miss_year: boolean, -} -export interface DateTimeReplacements { - day?: number; - month?: number; - year?: number; - offset?: number; -} diff --git a/application/platform/interfaces/interface.electron.ts b/application/platform/interfaces/interface.electron.ts deleted file mode 100644 index 20e03c2db7..0000000000 --- a/application/platform/interfaces/interface.electron.ts +++ /dev/null @@ -1,56 +0,0 @@ -declare interface MessagePort { - dummy: string; -} -declare interface Event { - dummy: string; -} - -export interface IpcRenderer { - invoke(channel: string, ...args: any[]): Promise; - on(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void): this; - once(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void): this; - postMessage(channel: string, message: any, transfer?: MessagePort[]): void; - removeAllListeners(channel: string): this; - removeListener(channel: string, listener: (...args: any[]) => void): this; - send(channel: string, ...args: any[]): void; - sendSync(channel: string, ...args: any[]): any; - sendTo(webContentsId: number, channel: string, ...args: any[]): void; - sendToHost(channel: string, ...args: any[]): void; -} - -export interface IpcRendererEvent extends Event { - ports: MessagePort[]; - sender: IpcRenderer; - senderId: number; -} - -export interface FileFilter { - extensions: string[]; - name: string; -} - -export interface OpenDialogOptions { - title?: string; - defaultPath?: string; - buttonLabel?: string; - filters?: FileFilter[]; - properties?: Array< - | 'openFile' - | 'openDirectory' - | 'multiSelections' - | 'showHiddenFiles' - | 'createDirectory' - | 'promptToCreate' - | 'noResolveAliases' - | 'treatPackageAsDirectory' - | 'dontAddToRecent' - >; - message?: string; - securityScopedBookmarks?: boolean; -} - -export interface OpenDialogReturnValue { - canceled: boolean; - filePaths: string[]; - bookmarks?: string[]; -} diff --git a/application/platform/interfaces/interface.node.global.ts b/application/platform/interfaces/interface.node.global.ts deleted file mode 100644 index a20f0cca16..0000000000 --- a/application/platform/interfaces/interface.node.global.ts +++ /dev/null @@ -1,28 +0,0 @@ -export type TLogFunc = (...args: any[]) => string; - -export interface ILogger { - verbose: TLogFunc; - info: TLogFunc; - env: TLogFunc; - debug: TLogFunc; - warn: TLogFunc; - error: TLogFunc; - wtf: TLogFunc; -} - -export abstract class Logger { - public abstract verbose(...args: any[]): string; - public abstract info(...args: any[]): string; - public abstract env(...args: any[]): string; - public abstract debug(...args: any[]): string; - public abstract warn(...args: any[]): string; - public abstract error(...args: any[]): string; - public abstract wtf(...args: any[]): string; -} - -export type LoggerConstructor = new (alias: string) => Required; - -export interface IChipmunkNodeGlobal { - logger: ILogger; - Logger: LoggerConstructor; -} diff --git a/application/platform/interfaces/interface.rust.api.general.ts b/application/platform/interfaces/interface.rust.api.general.ts deleted file mode 100644 index 201a7bcee8..0000000000 --- a/application/platform/interfaces/interface.rust.api.general.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { IFilter } from '../types/filter'; - -export { IFilter, IFilterFlags } from '../types/filter'; -export { IGrabbedContent, IGrabbedElement } from '../types/content'; - -export interface IMatchEntity { - filter: string; - match: string; - row: number; -} - -export interface IMapEntity { - filter: string; - rows: number[]; -} - -export interface IExtractedValueSrc { - index: number; // row position in the stream - // [filter_index, [values]] - values: Array>; -} -export type TExtractedValuesSrc = IExtractedValueSrc[]; - -export interface IExtractedMatch { - filter: IFilter; - values: string[]; -} - -export interface IExtractedValue { - position: number; // row position in the stream - values: IExtractedMatch[]; -} - -export type TExtractedValues = IExtractedValue[]; - -/** - * TODO: it should be removed! - * Output for @search method of session - * (application/apps/rustcore/ts/src/native/native.session.ts) - */ -export interface IResultSearchElement { - position: number; // Original position in stream - filters: number[]; // Indexes of matched filters, fit to indexes, which was - // provided with search(filters: IFilter[]) - // (application/apps/rustcore/ts/src/native/native.session.ts) - content: string; // Row value -} - -export type ISearchMap = Array<[number, number][]>; - -export type IValuesMap = { [key: number]: [number, number, number, number][] }; -export type IValuesMinMaxMap = { [key: number]: [number, number] }; - -/** - * Output for @extract method of session - * (application/apps/rustcore/ts/src/native/native.session.ts) - */ -export interface IExtractDTFormatResult { - format: string; - reg: string; - timestamp: string; -} - -/** - * Input for @extract method of session - * (application/apps/rustcore/ts/src/native/native.session.ts) - */ -export interface IExtractDTFormatOptions { - input: string; - format?: string; -} - -/** - * Input for @concat method of session - * (application/apps/rustcore/ts-bindings/src/api/session.stream.concat.executor.ts) - */ -export interface IConcatFile { - path: string; - tag: string; -} - -export interface IFileMergeOptions { - /// Path to the file to merge - path: string; - /// Offset in ms, this will be added to each posix timestamp - offset?: number; - /// If a year is provided and if no year was detected, this is what we use - year?: number; - /// An identifier string for the file - tag: string; - /// how we interpret the date string in each line - format: string; -} - -export interface INearest { - index: number; - position: number; -} diff --git a/application/platform/interfaces/interface.timerange.ts b/application/platform/interfaces/interface.timerange.ts deleted file mode 100644 index 8676821dfe..0000000000 --- a/application/platform/interfaces/interface.timerange.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface IRow { - position: number; - timestamp: number; - str: string; -} - -export interface IRange { - points: IRow[]; -} diff --git a/application/platform/ipc/event/values/updated.ts b/application/platform/ipc/event/values/updated.ts index d1c101cd73..b16c1f171c 100644 --- a/application/platform/ipc/event/values/updated.ts +++ b/application/platform/ipc/event/values/updated.ts @@ -1,5 +1,5 @@ import { Define, Interface, SignatureRequirement } from '../declarations'; -import { IValuesMinMaxMap } from '../../../interfaces/interface.rust.api.general'; +import { IValuesMinMaxMap } from '../../../types/filter'; import * as validator from '../../../env/obj'; diff --git a/application/platform/ipc/request/search/map.ts b/application/platform/ipc/request/search/map.ts index 4d32c8bcab..fbc921fa7a 100644 --- a/application/platform/ipc/request/search/map.ts +++ b/application/platform/ipc/request/search/map.ts @@ -1,5 +1,5 @@ import { Define, Interface, SignatureRequirement } from '../declarations'; -import { ISearchMap } from '../../../interfaces/interface.rust.api.general'; +import { ISearchMap } from '../../../types/filter'; import * as validator from '../../../env/obj'; @@ -33,7 +33,7 @@ export class Response extends SignatureRequirement { public map: ISearchMap; public from: number; public to: number; - + constructor(input: { session: string; map: ISearchMap; from: number; to: number }) { super(); validator.isObject(input); diff --git a/application/platform/ipc/request/search/nearest.ts b/application/platform/ipc/request/search/nearest.ts index 4a7daf0eea..8a91cabbc0 100644 --- a/application/platform/ipc/request/search/nearest.ts +++ b/application/platform/ipc/request/search/nearest.ts @@ -1,5 +1,5 @@ import { Define, Interface, SignatureRequirement } from '../declarations'; -import { INearest } from '../../../interfaces/interface.rust.api.general'; +import { INearest } from '../../../types/filter'; import * as validator from '../../../env/obj'; diff --git a/application/platform/ipc/request/values/frame.ts b/application/platform/ipc/request/values/frame.ts index 471a5b2bbc..18b0c34a12 100644 --- a/application/platform/ipc/request/values/frame.ts +++ b/application/platform/ipc/request/values/frame.ts @@ -1,5 +1,5 @@ import { Define, Interface, SignatureRequirement } from '../declarations'; -import { IValuesMap } from '../../../interfaces/interface.rust.api.general'; +import { IValuesMap } from '../../../types/filter'; import * as validator from '../../../env/obj'; diff --git a/application/platform/lib.ts b/application/platform/lib.ts index 430cc5fbf9..696b1ae60e 100644 --- a/application/platform/lib.ts +++ b/application/platform/lib.ts @@ -1,6 +1,5 @@ export * as entity from './entity'; export * as env from './env'; -export * as interfaces from './interfaces'; export * as ipc from './ipc'; export * as modules from './modules'; export * as types from './types'; diff --git a/application/platform/types/filter.ts b/application/platform/types/filter.ts index 6e3175b0ee..52fedaf38d 100644 --- a/application/platform/types/filter.ts +++ b/application/platform/types/filter.ts @@ -23,3 +23,44 @@ export enum EFlag { word = 'word', reg = 'reg', } + +export type ISearchMap = Array<[number, number][]>; + +export type IValuesMap = { [key: number]: [number, number, number, number][] }; + +export type IValuesMinMaxMap = { [key: number]: [number, number] }; + +export interface INearest { + index: number; + position: number; +} + +export interface IExtractedMatch { + filter: IFilter; + values: string[]; +} + +export interface IExtractedValueSrc { + index: number; // row position in the stream + // [filter_index, [values]] + values: Array>; +} +export type TExtractedValuesSrc = IExtractedValueSrc[]; + +export interface IExtractedValue { + position: number; // row position in the stream + values: IExtractedMatch[]; +} + +export type TExtractedValues = IExtractedValue[]; + +export interface IMatchEntity { + filter: string; + match: string; + row: number; +} + +export interface IMapEntity { + filter: string; + rows: number[]; +} From 0667ff63515de3175342a4f309022f37d588a97b Mon Sep 17 00:00:00 2001 From: DmitryAstafyev Date: Tue, 5 Sep 2023 09:39:46 +0200 Subject: [PATCH 2/3] Fix references in jasmine tests --- .../ts-bindings/spec/session.concat.spec.ts | 2 +- .../ts-bindings/spec/session.errors.spec.ts | 2 +- .../spec/session.exporting.spec.ts | 2 +- .../ts-bindings/spec/session.map.spec.ts | 30 ++++++++++++++----- .../ts-bindings/spec/session.observe.spec.ts | 2 +- .../ts-bindings/spec/session.ranges.spec.ts | 5 ++-- .../ts-bindings/spec/session.search.spec.ts | 2 +- .../ts-bindings/spec/session.stream.spec.ts | 26 ++++++++++------ 8 files changed, 47 insertions(+), 24 deletions(-) diff --git a/application/apps/rustcore/ts-bindings/spec/session.concat.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.concat.spec.ts index 1ff2dcfae6..0825a83244 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.concat.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.concat.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { createSampleFile, finish, runner } from './common'; import { readConfigurationFile } from './config'; diff --git a/application/apps/rustcore/ts-bindings/spec/session.errors.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.errors.spec.ts index 8470a8d37b..11b9a5ed80 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.errors.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.errors.spec.ts @@ -2,7 +2,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, SessionStream, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { finish, createSampleFile, runner } from './common'; import { readConfigurationFile } from './config'; import { error } from 'platform/log/utils'; diff --git a/application/apps/rustcore/ts-bindings/spec/session.exporting.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.exporting.spec.ts index 60f94e203d..1dbd6e9c96 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.exporting.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.exporting.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { createSampleFile, finish, runner } from './common'; import { readConfigurationFile } from './config'; import { fromIndexes } from 'platform/types/range'; diff --git a/application/apps/rustcore/ts-bindings/spec/session.map.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.map.spec.ts index e60f760787..29e953e904 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.map.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.map.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { ISearchMap } from '../src/interfaces/index'; +import { ISearchMap } from 'platform/types/filter'; import { finish, createSampleFile, runner } from './common'; import { readConfigurationFile } from './config'; @@ -51,7 +51,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search @@ -137,7 +139,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search @@ -227,7 +231,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search @@ -367,7 +373,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search @@ -457,7 +465,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search @@ -547,7 +557,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search @@ -637,7 +649,9 @@ describe('Map', function () { new Factory.File() .asText() .type(Factory.FileType.Text) - .file(tmpobj.name).get().sterilized(), + .file(tmpobj.name) + .get() + .sterilized(), ) .on('confirmed', () => { search diff --git a/application/apps/rustcore/ts-bindings/spec/session.observe.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.observe.spec.ts index 2a4312e929..8f52bc1445 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.observe.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.observe.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { IAttachmentsUpdatedUpdated } from '../src/api/session.provider'; import { IAttachment } from 'platform/types/content'; import { createSampleFile, finish, performanceReport, setMeasurement, runner } from './common'; diff --git a/application/apps/rustcore/ts-bindings/spec/session.ranges.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.ranges.spec.ts index 33912e52ff..96ffee9a99 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.ranges.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.ranges.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { createSampleFile, finish, runner } from './common'; import { readConfigurationFile } from './config'; @@ -44,7 +44,8 @@ describe('Grab ranges', function () { .asText() .type(Factory.FileType.Text) .file(tmpobj.name) - .get().sterilized(), + .get() + .sterilized(), ) .catch(finish.bind(null, session, done)); let grabbing: boolean = false; diff --git a/application/apps/rustcore/ts-bindings/spec/session.search.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.search.spec.ts index 2f31567e3f..0161b6109b 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.search.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.search.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { finish, createSampleFile, runner } from './common'; import { readConfigurationFile } from './config'; diff --git a/application/apps/rustcore/ts-bindings/spec/session.stream.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.stream.spec.ts index 38bd598740..c588fa4619 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.stream.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.stream.spec.ts @@ -6,7 +6,7 @@ import { initLogger } from './logger'; initLogger(); import { Session, Factory } from '../src/api/session'; -import { IGrabbedElement } from '../src/interfaces/index'; +import { IGrabbedElement } from 'platform/types/content'; import { createSampleFile, finish, runner } from './common'; import { readConfigurationFile } from './config'; import { utils } from 'platform/log'; @@ -60,7 +60,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .catch(finish.bind(null, session, done)); events.StreamUpdated.subscribe((rows: number) => { @@ -127,7 +128,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .on('confirmed', () => { lifeCycleEvents.push('confirmed'); @@ -171,7 +173,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .on('confirmed', () => { lifeCycleEvents.push('confirmed'); @@ -220,7 +223,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .catch(finish.bind(null, session, done)); const append = () => { @@ -333,7 +337,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .catch(finish.bind(null, session, done)); const filter = 'match A'; @@ -451,7 +456,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .catch(finish.bind(null, session, done)); events.StreamUpdated.subscribe((rows: number) => { @@ -510,7 +516,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .on('processing', (e) => { procceed(); @@ -526,7 +533,8 @@ if (process.platform === 'win32') { cwd: process.cwd(), envs: process.env as { [key: string]: string }, }) - .get().sterilized(), + .get() + .sterilized(), ) .on('processing', () => { procceed(); From 6b29bf78ed1810a944b2544352164ab677a08be0 Mon Sep 17 00:00:00 2001 From: DmitryAstafyev Date: Wed, 6 Sep 2023 20:31:06 +0200 Subject: [PATCH 3/3] Support importing filters/charts from v2 --- application/client/src/app/service/bridge.ts | 15 +++ .../src/app/service/history/collections.ts | 45 ++++++++ .../src/app/service/history/provider.ts | 104 ++++++++++++++---- .../dependencies/search/charts/request.ts | 13 +++ .../dependencies/search/filters/request.ts | 24 ++++ .../app/ui/views/dialogs/locker/styles.less | 1 + .../sidebar/search/providers/providers.ts | 1 - application/holder/src/service/bridge.ts | 9 ++ .../holder/src/service/bridge/file/index.ts | 1 + .../holder/src/service/bridge/file/read.ts | 44 ++++++++ .../holder/src/service/storage/entries.ts | 8 +- .../platform/ipc/request/file/index.ts | 1 + application/platform/ipc/request/file/read.ts | 30 +++++ 13 files changed, 275 insertions(+), 21 deletions(-) create mode 100644 application/holder/src/service/bridge/file/read.ts create mode 100644 application/platform/ipc/request/file/read.ts diff --git a/application/client/src/app/service/bridge.ts b/application/client/src/app/service/bridge.ts index 376c4f9be6..d575beb97e 100644 --- a/application/client/src/app/service/bridge.ts +++ b/application/client/src/app/service/bridge.ts @@ -39,6 +39,7 @@ export class Service extends Implementation { }); return Promise.resolve(); } + public files(): { getByPath(filenames: string[]): Promise; getByPathWithCache(filenames: string[]): Promise; @@ -57,6 +58,7 @@ export class Service extends Implementation { ): Promise<{ name: string; filename: string; parent: string; ext: string }>; cp(src: string, dest: string): Promise; copy(files: string[], dest: string): Promise; + read(filename: string): Promise; select: { any(): Promise; dlt(): Promise; @@ -249,6 +251,19 @@ export class Service extends Implementation { return Promise.resolve(); }); }, + read: (filename: string): Promise => { + return Requests.IpcRequest.send( + Requests.File.Read.Response, + new Requests.File.Read.Request({ + file: filename, + }), + ).then((response) => { + if (response.error !== undefined) { + return Promise.reject(new Error(response.error)); + } + return Promise.resolve(response.text as string); + }); + }, select: { any: (): Promise => { return request(undefined, `dlt,pcapng,txt,log,logs`); diff --git a/application/client/src/app/service/history/collections.ts b/application/client/src/app/service/history/collections.ts index 6c2c9053df..e33360e35a 100644 --- a/application/client/src/app/service/history/collections.ts +++ b/application/client/src/app/service/history/collections.ts @@ -12,6 +12,9 @@ import { SetupLogger, LoggerInterface } from '@platform/entity/logger'; import { Equal, Empty } from '@platform/types/env/types'; import { Subject, Subscriber } from '@platform/env/subscription'; import { StorageCollections } from './storage.collections'; +import { unique } from '@platform/env/sequence'; +import { FilterRequest } from '@service/session/dependencies/search/filters/request'; +import { ChartRequest } from '@service/session/dependencies/search/charts/request'; import * as obj from '@platform/env/obj'; @@ -62,6 +65,48 @@ export class Collections implements EntryConvertable, Equal, Empty } } + static fromV2(smth: { [key: string]: any }, storage: StorageCollections): Collections { + const uuid = unique(); + obj.isObject(smth); + const filters: FilterRequest[] = []; + if (smth['filters'] instanceof Array) { + smth['filters'].forEach((smth) => { + const validFilter = FilterRequest.fromV2(smth); + if (validFilter instanceof Error) { + return; + } + filters.push(validFilter); + }); + } + const charts: ChartRequest[] = []; + if (smth['charts'] instanceof Array) { + smth['charts'].forEach((smth) => { + const validChart = ChartRequest.fromV2(smth); + if (validChart instanceof Error) { + return; + } + charts.push(validChart); + }); + } + return new Collections( + `Collections:${uuid}`, + { + name: '-', + last: Date.now(), + created: Date.now(), + used: 1, + uuid: uuid, + preset: false, + relations: [], + origin: undefined, + entries: filters + .map((f) => f.asJsonField()) + .concat(charts.map((d) => d.asJsonField())), + }, + storage, + ); + } + static fromMinifiedStr(src: { [key: string]: number | string }): ICollection { return { name: obj.getAsNotEmptyString(src, 'n'), diff --git a/application/client/src/app/service/history/provider.ts b/application/client/src/app/service/history/provider.ts index 36767fc4e4..62c00ec134 100644 --- a/application/client/src/app/service/history/provider.ts +++ b/application/client/src/app/service/history/provider.ts @@ -7,6 +7,10 @@ import { Subject } from '@platform/env/subscription'; import { unique } from '@platform/env/sequence'; import { error } from '@platform/log/utils'; import { bridge } from '@service/bridge'; +import { lockers, Locker } from '@ui/service/lockers'; +import { scope } from '@platform/env/scope'; + +import * as obj from '@platform/env/obj'; export class Provider implements EntryConvertable { protected collections: Collections[] = []; @@ -16,6 +20,83 @@ export class Provider implements EntryConvertable { collections: StorageCollections; definitions: StorageDefinitions; }; + protected importFromC2Version(filename: string, err: Error): Promise { + const logger = scope.getLogger('ImporterFiltersFromV2'); + return new Promise((resolve, reject) => { + const message = lockers.lock( + new Locker( + false, + `Fail to read from file due error: ${err.message.split(/[\n\r]/gi)[0]}`, + ) + .set() + .buttons([ + { + caption: `Try read as Chipmunk v2 filters`, + handler: () => { + message.popup.close(); + bridge + .files() + .read(filename) + .then((text: string) => { + try { + const parsed = JSON.parse(text); + obj.isObject(parsed); + this.collections = [ + Collections.fromV2( + parsed, + this.storage.collections, + ), + ]; + this.definitions = []; + resolve(this.orderAfterImport()); + } catch (e) { + logger.error(error(e)); + reject(new Error(error(e))); + } + }) + .catch((err: Error) => { + logger.error(err.message); + reject(err); + }); + }, + }, + { + caption: `Cancel`, + handler: () => { + message.popup.close(); + resolve([]); + }, + }, + ]) + .end(), + { + closable: false, + }, + ); + }); + } + + protected orderAfterImport(): string[] { + this.collections = this.collections.map((col) => { + // Reassign uuids of definitions as soon as it will be diffrent in case + // if both users have same source + col.relations = col.relations.map((uuid) => { + let target = this.definitions.find((d) => d.uuid === uuid); + if (target === undefined) { + return uuid; + } + target = this.storage.definitions.update(target); + return target.uuid; + }); + return col; + }); + const uuids: string[] = this.collections.map((collection) => collection.uuid); + this.storage.definitions.add(this.definitions); + this.storage.collections.add(this.collections); + this.collections = []; + this.definitions = []; + return uuids; + } constructor(collections: StorageCollections, definitions: StorageDefinitions) { this.storage = { @@ -70,25 +151,10 @@ export class Provider implements EntryConvertable { if (error instanceof Error) { return Promise.reject(error); } - this.collections = this.collections.map((col) => { - // Reassign uuids of definitions as soon as it will be diffrent in case - // if both users have same source - col.relations = col.relations.map((uuid) => { - let target = this.definitions.find((d) => d.uuid === uuid); - if (target === undefined) { - return uuid; - } - target = this.storage.definitions.update(target); - return target.uuid; - }); - return col; - }); - const uuid: string[] = this.collections.map(collection => collection.uuid); - this.storage.definitions.add(this.definitions); - this.storage.collections.add(this.collections); - this.collections = []; - this.definitions = []; - return uuid; + return this.orderAfterImport(); + }) + .catch((err: Error) => { + return this.importFromC2Version(filename, err); }); } diff --git a/application/client/src/app/service/session/dependencies/search/charts/request.ts b/application/client/src/app/service/session/dependencies/search/charts/request.ts index f3a1264692..4f8f3337ab 100644 --- a/application/client/src/app/service/session/dependencies/search/charts/request.ts +++ b/application/client/src/app/service/session/dependencies/search/charts/request.ts @@ -85,6 +85,19 @@ export class ChartRequest } } + public static fromV2(smth: { [key: string]: unknown }): ChartRequest | Error { + try { + return new ChartRequest({ + uuid: obj.getAsString(smth, 'guid'), + filter: obj.getAsNotEmptyString(smth, 'request'), + color: obj.getAsNotEmptyString(smth, 'color'), + active: obj.getAsBool(smth, 'active'), + }); + } catch (e) { + return new Error(error(e)); + } + } + public readonly definition: Definition; public readonly updated: Subject = new Subject(); diff --git a/application/client/src/app/service/session/dependencies/search/filters/request.ts b/application/client/src/app/service/session/dependencies/search/filters/request.ts index cd84af5e1b..d19b39b62b 100644 --- a/application/client/src/app/service/session/dependencies/search/filters/request.ts +++ b/application/client/src/app/service/session/dependencies/search/filters/request.ts @@ -77,6 +77,30 @@ export class FilterRequest } } + public static fromV2(smth: { [key: string]: unknown }): FilterRequest | Error { + try { + const flags = obj.getAsObj(smth, 'flags'); + return new FilterRequest({ + uuid: obj.getAsString(smth, 'guid'), + filter: { + filter: obj.getAsNotEmptyString(smth, 'request'), + flags: { + cases: obj.getAsBool(flags, 'casesensitive'), + word: obj.getAsBool(flags, 'wholeword'), + reg: obj.getAsBool(flags, 'regexp'), + }, + }, + colors: { + color: obj.getAsNotEmptyString(smth, 'color'), + background: obj.getAsNotEmptyString(smth, 'background'), + }, + active: obj.getAsBool(smth, 'active'), + }); + } catch (e) { + return new Error(error(e)); + } + } + static isValid(filter: IFilter): boolean { return ( getFilterError( diff --git a/application/client/src/app/ui/views/dialogs/locker/styles.less b/application/client/src/app/ui/views/dialogs/locker/styles.less index 314333302c..b24170b48f 100644 --- a/application/client/src/app/ui/views/dialogs/locker/styles.less +++ b/application/client/src/app/ui/views/dialogs/locker/styles.less @@ -66,6 +66,7 @@ text-align: right; padding: 12px 0 6px 0; width: 100%; + white-space: nowrap; & button { display: inline-block; margin-left: 12px; diff --git a/application/client/src/app/ui/views/sidebar/search/providers/providers.ts b/application/client/src/app/ui/views/sidebar/search/providers/providers.ts index b3fb255a40..b66ede6559 100644 --- a/application/client/src/app/ui/views/sidebar/search/providers/providers.ts +++ b/application/client/src/app/ui/views/sidebar/search/providers/providers.ts @@ -482,7 +482,6 @@ export class Providers { }), ); }; - return { import: (): void => { bridge diff --git a/application/holder/src/service/bridge.ts b/application/holder/src/service/bridge.ts index aa33ac31fb..582053b043 100644 --- a/application/holder/src/service/bridge.ts +++ b/application/holder/src/service/bridge.ts @@ -118,6 +118,15 @@ export class Service extends Implementation { RequestHandlers.File.Copy.handler, ), ); + this.register( + electron + .ipc() + .respondent( + this.getName(), + Requests.File.Read.Request, + RequestHandlers.File.Read.handler, + ), + ); this.register( electron .ipc() diff --git a/application/holder/src/service/bridge/file/index.ts b/application/holder/src/service/bridge/file/index.ts index 14ac19b25e..4a9dc620ef 100644 --- a/application/holder/src/service/bridge/file/index.ts +++ b/application/holder/src/service/bridge/file/index.ts @@ -5,3 +5,4 @@ export * as Exists from './exists'; export * as Name from './name'; export * as Copy from './copy'; export * as CopyFile from './copyfile'; +export * as Read from './read'; diff --git a/application/holder/src/service/bridge/file/read.ts b/application/holder/src/service/bridge/file/read.ts new file mode 100644 index 0000000000..e3a89194c3 --- /dev/null +++ b/application/holder/src/service/bridge/file/read.ts @@ -0,0 +1,44 @@ +import { CancelablePromise } from 'platform/env/promise'; +import { Logger } from 'platform/log'; + +import * as fs from 'fs'; +import * as Requests from 'platform/ipc/request'; + +export const handler = Requests.InjectLogger< + Requests.File.Read.Request, + CancelablePromise +>( + ( + _log: Logger, + request: Requests.File.Read.Request, + ): CancelablePromise => { + return new CancelablePromise((resolve, _reject) => { + if (!fs.existsSync(request.file)) { + return resolve( + new Requests.File.Read.Response({ + text: undefined, + error: `File ${request.file} doesn't exist`, + }), + ); + } + fs.promises + .readFile(request.file, { encoding: 'utf-8' }) + .then((text: string) => { + return resolve( + new Requests.File.Read.Response({ + text, + error: undefined, + }), + ); + }) + .catch((err: Error) => { + return resolve( + new Requests.File.Read.Response({ + text: undefined, + error: `Fail to read file ${request.file}: ${err.message}`, + }), + ); + }); + }); + }, +); diff --git a/application/holder/src/service/storage/entries.ts b/application/holder/src/service/storage/entries.ts index fa6245c411..ed714adf68 100644 --- a/application/holder/src/service/storage/entries.ts +++ b/application/holder/src/service/storage/entries.ts @@ -10,7 +10,13 @@ export type Reader = (key: string) => Promise; export class Entries { static from(str: string, storageKey: string, logger: Logger): Map { const entries = new Map(); - (JSON.parse(str) as Entry[]).forEach((entry) => { + const parsed = JSON.parse(str) as Entry[]; + if (!(parsed instanceof Array)) { + throw new Error( + `Invalid format: expecting an Entry[], but has been gotten: ${typeof parsed}`, + ); + } + parsed.forEach((entry) => { if (typeof entry['uuid'] !== 'string' || entry['uuid'].trim() === '') { logger.warn(`Storage "${storageKey}" includes entries without valid "uuid"`); return; diff --git a/application/platform/ipc/request/file/index.ts b/application/platform/ipc/request/file/index.ts index 260522d692..c9c0228fbb 100644 --- a/application/platform/ipc/request/file/index.ts +++ b/application/platform/ipc/request/file/index.ts @@ -6,3 +6,4 @@ export * as Exists from './exists'; export * as Name from './name'; export * as Copy from './copy'; export * as CopyFile from './copyfile'; +export * as Read from './read'; diff --git a/application/platform/ipc/request/file/read.ts b/application/platform/ipc/request/file/read.ts new file mode 100644 index 0000000000..cfa72e4935 --- /dev/null +++ b/application/platform/ipc/request/file/read.ts @@ -0,0 +1,30 @@ +import { Define, Interface, SignatureRequirement } from '../declarations'; + +import * as validator from '../../../env/obj'; + +@Define({ name: 'ReadFileRequest' }) +export class Request extends SignatureRequirement { + public file: string; + + constructor(input: { file: string }) { + super(); + validator.isObject(input); + this.file = validator.getAsNotEmptyString(input, 'file'); + } +} +export interface Request extends Interface {} + +@Define({ name: 'ReadFilesResponse' }) +export class Response extends SignatureRequirement { + public error?: string; + public text?: string; + + constructor(input: { text?: string; error?: string }) { + super(); + validator.isObject(input); + this.text = validator.getAsNotEmptyStringOrAsUndefined(input, 'text'); + this.error = validator.getAsNotEmptyStringOrAsUndefined(input, 'error'); + } +} + +export interface Response extends Interface {}