Skip to content

Commit

Permalink
Merge branch 'master' into snyk-upgrade-0d5b4c37019094233a211b7b9ae260a7
Browse files Browse the repository at this point in the history
  • Loading branch information
con-cis authored Dec 27, 2024
2 parents b152b42 + a6cd127 commit f52a5f9
Show file tree
Hide file tree
Showing 28 changed files with 1,503 additions and 1,154 deletions.
2,044 changes: 1,063 additions & 981 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@electron-toolkit/preload": "^3.0.1",
"@electron-toolkit/utils": "^3.0.0",
"electron-updater": "^6.3.9",
"vuetify": "^3.7.5",
"vuetify": "^3.7.6",
"xml2js": "^0.6.2"
},
"devDependencies": {
Expand All @@ -41,26 +41,26 @@
"@electron-toolkit/tsconfig": "^1.0.1",
"@mdi/font": "^7.4.47",
"@rushstack/eslint-patch": "^1.10.4",
"@types/node": "^22.7.5",
"@types/node": "^22.10.2",
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@vitejs/plugin-vue": "^5.1.4",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@vitejs/plugin-vue": "^5.2.1",
"@vue/eslint-config-prettier": "^10.1.0",
"@vue/eslint-config-typescript": "^14.1.3",
"@vue/eslint-config-typescript": "^14.2.0",
"cross-env": "^7.0.3",
"electron": "^33.0.2",
"electron": "^33.2.1",
"electron-builder": "^25.1.8",
"electron-vite": "^2.3.0",
"eslint": "^9.13.0",
"eslint-plugin-vue": "^9.29.0",
"eslint": "^9.17.0",
"eslint-plugin-vue": "^9.32.0",
"less": "^4.2.1",
"prettier": "^3.3.3",
"typescript": "^5.6.3",
"vite": "^5.4.8",
"vite-tsconfig-paths": "^5.1.3",
"vitest": "^2.1.6",
"vue": "^3.5.12",
"vue-tsc": "^2.1.6"
"prettier": "^3.4.2",
"typescript": "^5.7.2",
"vite": "^5.4.11",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^2.1.8",
"vue": "^3.5.13",
"vue-tsc": "^2.2.0"
},
"license": "GPLv3",
"keywords": [
Expand Down
76 changes: 41 additions & 35 deletions src/classes/DataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ import { ConfigData } from '../types/ConfigData'
*/
export class DataHandler {
private static instance: DataHandler
public dataObject: ConfigData

/**
* Private constructor to prevent direct instantiation.
* Initializes the data object with an initial value.
*/
private constructor() {
this.dataObject = { status: undefined }
}

/**
* Retrieves the singleton instance of the DataObjectSingleton class.
Expand All @@ -31,38 +22,20 @@ export class DataHandler {
return DataHandler.instance
}

public dataObject: ConfigData

/**
* Converts the data object to its JSON representation.
* @returns A JSON string representing the data object.
* Private constructor to prevent direct instantiation.
* Initializes the data object with an initial value.
*/
public toJSON(): string {
return JSON.stringify({
extractedData: this.dataObject.extractedData,
metadata: this.dataObject?.metadata
})
private constructor() {
this.dataObject = { status: undefined }
}

/**
* Creates a data object based on processed results.
* If processedResult is an error, returns an error status data object.
* Otherwise, returns a success status data object with extractedData and metadata.
* @param processedResult - The processed result to create the data object from.
* @returns void.
* Adds Annotations to a Channel
* @returns API Response of operation.
*/
public setDataObject(
processedResult: Error | { extractedData: ExtractedData; metadata: MetaData }
): void {
if (processedResult instanceof Error) {
this.dataObject = { status: ApiResponses.ERROR_RESOLVING_CONFIG }
} else {
this.dataObject = {
extractedData: processedResult.extractedData,
metadata: processedResult.metadata,
status: ApiResponses.RESOLVED_SUCCESSFULLY
}
}
}

public addAnnotation(data: { channelId: string; annotation: string }): ApiResponses {
const escapedAnnotation = escapeString(data.annotation)
let channelFound = false
Expand All @@ -83,6 +56,7 @@ export class DataHandler {
return ApiResponses.ERROR_RESOLVING_ANNOTATION
}
}

/**
* Sets data to an empty array
* @returns The singleton instance of DataObjectSingleton.
Expand All @@ -98,4 +72,36 @@ export class DataHandler {
return ApiResponses.ERROR_RESOLVING_ANNOTATION
}
}

/**
* Creates a data object based on processed results.
* If processedResult is an error, returns an error status data object.
* Otherwise, returns a success status data object with extractedData and metadata.
* @param processedResult - The processed result to create the data object from.
* @returns void.
*/
public setDataObject(
processedResult: Error | { extractedData: ExtractedData; metadata: MetaData }
): void {
if (processedResult instanceof Error) {
this.dataObject = { status: ApiResponses.ERROR_RESOLVING_CONFIG }
} else {
this.dataObject = {
extractedData: processedResult.extractedData,
metadata: processedResult.metadata,
status: ApiResponses.RESOLVED_SUCCESSFULLY
}
}
}

/**
* Converts the data object to its JSON representation.
* @returns A JSON string representing the data object.
*/
public toJSON(): string {
return JSON.stringify({
extractedData: this.dataObject.extractedData,
metadata: this.dataObject?.metadata
})
}
}
29 changes: 29 additions & 0 deletions src/classes/IpcHandler.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,60 @@
/**
* IpcHandler class manages IPC (Inter-Process Communication) between the main and renderer processes.
* It handles file operations and data management through registered event handlers.
*/
import { ipcMain } from 'electron'
import { openFile, saveFile } from '../main/modules/fileHandling/FileService'
import { DataHandler } from './DataHandler'

export class IpcHandler {
/** Instance of DataHandler for managing application data */
private dataHandler: DataHandler

/**
* Initializes the IpcHandler by getting DataHandler instance and registering IPC handlers
*/
constructor() {
this.dataHandler = DataHandler.getInstance()
this.registerHandlers()
}

/**
* Registers all IPC event handlers for the application
* @private
*/
private registerHandlers(): void {
/**
* Handles opening file dialog and loading file
*/
ipcMain.handle('open-file-dialog', async () => {
await openFile()
})

/**
* Handles saving file dialog and saving file
* @returns Promise with save operation result
*/
ipcMain.handle('save-file-dialog', async () => {
return await saveFile()
})

/**
* Handles setting annotations for channels
* @param _event - IPC event object
* @param data - Object containing channelId and annotation string
* @returns Promise with annotation operation result
*/
ipcMain.handle(
'set-annotation',
async (_event, data: { channelId: string; annotation: string }) => {
return this.dataHandler.addAnnotation(data)
}
)

/**
* Handles resetting all application data
* @returns Promise with reset operation result
*/
ipcMain.handle('reset-data', async () => {
return this.dataHandler.resetData()
})
Expand Down
15 changes: 13 additions & 2 deletions src/enums/ApiResponses.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/**
* Enum containing standard API response messages
* @enum {string}
*
* @property {string} OPERATION_CANCELLED - Response when operation is cancelled
* @property {string} RESOLVED_SUCCESSFULLY - Response for successful resolution
* @property {string} ERROR_RESOLVING_CONFIG - Response when config file resolution fails
* @property {string} NO_DATA_RESOLVING_DATA - Response when no data is available to resolve
* @property {string} ERROR_RESOLVING_ANNOTATION - Response when annotation resolution fails
* @property {string} ERROR_RESETTING_DATA - Response when data reset operation fails
*/
enum ApiResponses {
OPERATION_CANCELLED = 'Operation cancelled',
RESOLVED_SUCCESSFULLY = 'Resolved successfully',
RESOLVED_SUCCESSFULLY = 'Resolved successfully',
ERROR_RESOLVING_CONFIG = 'Error while resolving config file',
NO_DATA_RESOLVING_DATA = 'No data to resolve',
ERROR_RESOLVING_ANNOTATION = 'Error while resolving annotation',
ERROR_RESETTING_DATA = 'Error while resetting data'
}

export default ApiResponses
export default ApiResponses
8 changes: 7 additions & 1 deletion src/enums/ConnectorType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* Enum representing the types of connectors in the system
* @enum {string}
* @property {string} Source - Represents a source connector that data flows from
* @property {string} Destination - Represents a destination connector that data flows to
*/
enum ConnectorType {
Source = 'source',
Destination = 'destination'
}

export default ConnectorType
export default ConnectorType
15 changes: 14 additions & 1 deletion src/enums/FilteredProperties.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* Enum containing properties that should be filtered/masked in logs and outputs
* @enum {string}
* @property {string} Password - Password field
* @property {string} Username - Username field
* @property {string} PreprocessingScript - Script run before processing
* @property {string} PostprocessingScript - Script run after processing
* @property {string} DeployScript - Script used for deployment
* @property {string} UndeployScript - Script used for undeployment
* @property {string} GlobalScripts - Global scripts
* @property {string} KeyPW - Key password
* @property {string} KeyStorePW - Keystore password
*/
enum FilteredProperties {
Password = 'password',
Username = 'username',
Expand All @@ -11,4 +24,4 @@ enum FilteredProperties {
KeyStorePW = 'keyStorePW'
}

export default FilteredProperties
export default FilteredProperties
16 changes: 14 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/**
* @fileoverview Main electron application file that handles window creation, app lifecycle, and security settings
* @module main
* @requires electron
* @requires path
* @requires @electron-toolkit/utils
* @requires ./utils/Common
* @requires ./modules/fileHandling/FileService
*/
import { app, shell, BrowserWindow, Menu, session } from 'electron'
import { resolve, join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { configureMenu } from './utils/Common'
import { openFile, saveFile } from './modules/fileHandling/FileService'

/**
* Creates and configures the main application window
* @function createWindow
* @returns {void}
*/
function createWindow(): void {
// Create the browser window.
const mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -42,8 +56,6 @@ function createWindow(): void {
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron')
Expand Down
16 changes: 16 additions & 0 deletions src/main/modules/fileHandling/FileDialogService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
/**
* File dialog utility functions for Electron application
*/

import { BrowserWindow, dialog } from 'electron'

/**
* Opens a file selection dialog that allows choosing XML or JSON files
* @returns Promise that resolves to dialog result containing:
* - canceled: boolean indicating if dialog was canceled
* - filePaths: array of selected file paths, empty if canceled
*/
export function openFileDialog(): Promise<
Electron.OpenDialogReturnValue | { canceled: boolean; filePaths: [] }
> {
Expand All @@ -15,6 +25,12 @@ export function openFileDialog(): Promise<
}
}

/**
* Opens a file save dialog that allows saving JSON files
* @returns Promise that resolves to dialog result containing:
* - canceled: boolean indicating if dialog was canceled
* - filePath: selected save path, empty if canceled
*/
export function saveFileDialog(): Promise<
Electron.SaveDialogReturnValue | { canceled: boolean; filePath: [] }
> {
Expand Down
22 changes: 22 additions & 0 deletions src/main/modules/fileHandling/FileService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @fileoverview Handles file operations including reading, processing and saving JSON/XML files
*/

import fs from 'fs/promises'
import { processJsonFile } from '../jsonProcessing/JsonProcessingService'
import { processXmlFile } from '../xmlProcessing/XmlProcessingService'
Expand All @@ -14,6 +18,11 @@ new IpcHandler()

const dataHandler = DataHandler.getInstance()

/**
* Reads and processes a file from the given file path
* @param filePath - Path to the file to be processed
* @returns Object containing extracted data and metadata, or Error if processing fails
*/
async function readFileAndProcess(filePath: string): Promise<
| {
extractedData: ExtractedData
Expand All @@ -38,6 +47,11 @@ async function readFileAndProcess(filePath: string): Promise<
}
}

/**
* Determines the type of file based on content
* @param content - String content of the file
* @returns 'JSON', 'XML' or 'unknown format'
*/
function getFileType(content: string): string {
let format: string
if (isJSON(content)) {
Expand All @@ -50,6 +64,10 @@ function getFileType(content: string): string {
return format
}

/**
* Opens a file dialog and processes the selected file
* @returns ApiResponse indicating the operation result
*/
export async function openFile(): Promise<ApiResponses> {
const mainWindow = BrowserWindow.getFocusedWindow()

Expand All @@ -75,6 +93,10 @@ export async function openFile(): Promise<ApiResponses> {
}
}

/**
* Opens a save file dialog and saves the current data
* @returns ApiResponse indicating the operation result
*/
export async function saveFile(): Promise<ApiResponses> {
try {
const result = await saveFileDialog()
Expand Down
Loading

0 comments on commit f52a5f9

Please sign in to comment.