Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(services): add some ts ignores #1641

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,7 @@ export class Commander {
'--config [PATH]',
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
)
.option(
'--file-read <PATH>',
'read the message body from the file',
parseFileRead
)
.option('--file-read <PATH>', 'read the message body from the file', parseFileRead)
.option(
'-Pp, --protobuf-path <PATH>',
'the path to the .proto file that defines the message format for Protocol Buffers (protobuf)',
Expand Down Expand Up @@ -311,8 +307,16 @@ export class Commander {
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
)
// https://github.com/tj/commander.js/blob/master/examples/options-conflicts.js
.addOption(new Option('--file-write <PATH>', 'append received messages to a specified file').argParser(parseFileWrite).conflicts('fileSave'))
.addOption(new Option('--file-save <PATH>', 'save each received message to a new file').argParser(parseFileSave).conflicts('fileWrite'))
.addOption(
new Option('--file-write <PATH>', 'append received messages to a specified file')
.argParser(parseFileWrite)
.conflicts('fileSave'),
)
.addOption(
new Option('--file-save <PATH>', 'save each received message to a new file')
.argParser(parseFileSave)
.conflicts('fileWrite'),
)
.option(
'-Pp, --protobuf-path <PATH>',
'the path to the .proto file that defines the message format for Protocol Buffers (protobuf)',
Expand Down Expand Up @@ -496,11 +500,7 @@ export class Commander {
'--config [PATH]',
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
)
.option(
'--file-read <PATH>',
'read the message body from the file',
parseFileRead
)
.option('--file-read <PATH>', 'read the message body from the file', parseFileRead)
.allowUnknownOption(false)
.action(benchPub)

Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const benchConn = async (options: BenchConnectOptions) => {
const start = Date.now()

for (let i = 1; i <= count; i++) {
; ((i: number, connOpts: mqtt.IClientOptions) => {
;((i: number, connOpts: mqtt.IClientOptions) => {
const opts = { ...connOpts }

opts.clientId = clientId.includes('%i') ? clientId.replaceAll('%i', i.toString()) : `${clientId}_${i}`
Expand Down
6 changes: 3 additions & 3 deletions cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const pub = (options: PublishOptions) => {
concat((data) => {
pubOpts.message = data
send(config, connOpts, pubOpts)
})
}),
)
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions |
} = options

let fileData: Buffer | string
if(fileRead) {
if (fileRead) {
fileData = handleFileRead(processPath(fileRead))
}

Expand Down Expand Up @@ -321,7 +321,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions |
}
publishMessage = simulationResult.message
}
if(fileRead) {
if (fileRead) {
publishMessage = fileData
}
client.publish(publishTopic, publishMessage, pubOpts.opts, (err) => {
Expand Down
8 changes: 4 additions & 4 deletions cli/src/lib/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const processReceivedMessage = (
}

const handleDefaultBinaryFile = (format: FormatType | undefined, filePath?: string) => {
if(filePath) {
if (filePath) {
if ((!format || format !== 'binary') && isSupportedBinaryFormatForMQTT(getPathExtname(filePath))) {
signale.warn('Please use the --format binary option for handling binary files')
if(!format) {
if (!format) {
return 'binary'
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ const sub = (options: SubscribeOptions) => {
const receivedMessage = processReceivedMessage(payload, protobufPath, protobufMessageName, format)

const savePath = fileSave ? createNextNumberedFileName(fileSave) : fileWrite
if(savePath) {
if (savePath) {
fileSave && writeFile(savePath, receivedMessage)
fileWrite && appendFile(savePath, receivedMessage)
}
Expand All @@ -127,7 +127,7 @@ const sub = (options: SubscribeOptions) => {

packet.retain && msgData.push({ label: 'retain', value: packet.retain })

if(savePath) {
if (savePath) {
const successMessage = fileSave ? 'Saved to file' : 'Appended to file'
msgData.push({ label: 'payload', value: `${successMessage}: ${savePath}` })
} else {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ declare global {
}

interface IDisconnectPacket {
cmd: 'disconnect',
cmd: 'disconnect'
qos: QoS
dup: boolean
retain: boolean
reasonCode: number,
reasonCode: number
length: number
}
}
Expand Down
47 changes: 41 additions & 6 deletions cli/src/utils/binaryFormats.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
const supportedBinaryFormatsForMQTT = [
'.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.tif', '.tiff', // Image file formats
'.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.mpeg', '.3gp', // Video file formats
'.mp3', '.wav', '.flac', '.aac', '.ogg', '.wma', '.m4a', '.m4p', // Audio file formats
'.zip', '.gz', '.rar', '.tar', '.7z', '.bz2', '.xz', '.jar', // Compressed file formats
'.bin', '.exe', '.dll', '.so', '.dmg', '.iso', '.img', // Binary file formats
'.pdf', '.epub', // Binary document file formats
'.png',
'.jpg',
'.jpeg',
'.gif',
'.bmp',
'.ico',
'.tif',
'.tiff', // Image file formats
'.mp4',
'.avi',
'.mov',
'.mkv',
'.flv',
'.wmv',
'.mpeg',
'.3gp', // Video file formats
'.mp3',
'.wav',
'.flac',
'.aac',
'.ogg',
'.wma',
'.m4a',
'.m4p', // Audio file formats
'.zip',
'.gz',
'.rar',
'.tar',
'.7z',
'.bz2',
'.xz',
'.jar', // Compressed file formats
'.bin',
'.exe',
'.dll',
'.so',
'.dmg',
'.iso',
'.img', // Binary file formats
'.pdf',
'.epub', // Binary document file formats
]

const isSupportedBinaryFormatForMQTT = (fileExtname: string) => {
Expand Down
11 changes: 9 additions & 2 deletions cli/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import signale from 'signale'
import { fileExists, writeFile, readFile, processPath, stringifyToYamlOrJson, parseYamlOrJson, isYaml } from '../utils/fileUtils'
import {
fileExists,
writeFile,
readFile,
processPath,
stringifyToYamlOrJson,
parseYamlOrJson,
isYaml,
} from '../utils/fileUtils'

const defaultPath = `${process.cwd()}/mqttx-cli-config.json`

const mergeConfig = (oldConfig: Config, newConfig: Config) => Object.assign({}, oldConfig, newConfig)


const removeUselessOptions = (
opts:
| ConnectOptions
Expand Down
11 changes: 5 additions & 6 deletions cli/src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ const appendFile = (filePath: string, data: string | Buffer): void => {

const createNextNumberedFileName = (filePath: string): string => {
const escapeRegExp = (string: string) => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
try {
if(!fileExists(filePath))
return filePath
if (!fileExists(filePath)) return filePath

const dir = path.dirname(filePath)
const baseNameWithoutExt = path.basename(filePath, path.extname(filePath))
Expand All @@ -86,7 +85,7 @@ const createNextNumberedFileName = (filePath: string): string => {
const newNumber = maxNumber + 1
const newFileName = `${baseNameWithoutExt}(${newNumber})${ext}`
return path.join(dir, newFileName)
} catch(err) {
} catch (err) {
signale.error(`Error: Unable to create a new numbered file name for path '${filePath}'.`)
process.exit(1)
}
Expand All @@ -102,5 +101,5 @@ export {
readFile,
writeFile,
appendFile,
createNextNumberedFileName
}
createNextNumberedFileName,
}
8 changes: 4 additions & 4 deletions cli/src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ const parsePubTopic = (value: string) => {

const parseFileRead = (value: string) => {
const filePath = processPath(value)
if(!filePath) {
if (!filePath) {
signale.error('A valid file path is required when reading from file.')
process.exit(1)
}

const fileContent = readFile(filePath)
if(fileContent.length >= MQTT_SINGLE_MESSAGE_BYTE_LIMIT) {
if (fileContent.length >= MQTT_SINGLE_MESSAGE_BYTE_LIMIT) {
signale.error('File size over 256MB not supported by MQTT.')
process.exit(1)
}
Expand All @@ -117,7 +117,7 @@ const parseFileRead = (value: string) => {

const parseFileSave = (value: string) => {
const filePath = processPath(value)
if(!filePath) {
if (!filePath) {
signale.error('A valid file path is required when saving to file.')
process.exit(1)
}
Expand All @@ -126,7 +126,7 @@ const parseFileSave = (value: string) => {

const parseFileWrite = (value: string) => {
const filePath = processPath(value)
if(!filePath) {
if (!filePath) {
signale.error('A valid file path is required when writing to file.')
process.exit(1)
}
Expand Down
9 changes: 7 additions & 2 deletions cli/src/utils/signale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const basicLog = {
signale.await('Connecting...')
} else {
signale.await(
`Connecting using configuration file, host: ${host}, port: ${port}${topic ? `, topic: ${topic}` : ''}${message ? `, message: ${message}` : ''
`Connecting using configuration file, host: ${host}, port: ${port}${topic ? `, topic: ${topic}` : ''}${
message ? `, message: ${message}` : ''
}`,
)
}
Expand All @@ -51,7 +52,11 @@ const basicLog = {
disconnect: (packet: IDisconnectPacket, clientId?: string) => {
const { reasonCode } = packet
const reason = reasonCode === 0 ? 'Normal disconnection' : getErrorReason(reasonCode)
signale.warn(`${clientId ? `Client ID: ${clientId}, ` : ''}The Broker has actively disconnected, Reason: ${reason} (Code: ${reasonCode})`)
signale.warn(
`${
clientId ? `Client ID: ${clientId}, ` : ''
}The Broker has actively disconnected, Reason: ${reason} (Code: ${reasonCode})`,
)
},
fileReading: () => signale.await('Reading file...'),
fileReadSuccess: () => signale.success('Read file successfully'),
Expand Down
2 changes: 1 addition & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function handleIpcMessages() {
type: 'error',
title: 'Rebuild Database Error',
message: 'An error occurred while rebuilding the database.',
detail: error.message
detail: error.message,
})
}
})
Expand Down
42 changes: 19 additions & 23 deletions src/components/DatabaseError.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<template>
<div class="connect-database-error-page">
<div class="page-content">
<p class="info">A corruption has been detected in the database file, preventing the software from launching properly. To fix this, please click 'Rebuild Database'.</p>
<p class="info">
A corruption has been detected in the database file, preventing the software from launching properly. To fix
this, please click 'Rebuild Database'.
</p>
<p class="error">Error - {{ connectDatabaseFailMessage }}</p>
</div>
<el-button class="rebuild-database-btn" type="primary" @click="confirmRebuild">
Rebuild Database
</el-button>
<el-button class="rebuild-database-btn" type="primary" @click="confirmRebuild"> Rebuild Database </el-button>
</div>
</template>


<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { Getter } from 'vuex-class'
Expand All @@ -25,25 +25,21 @@ export default class DatabaseError extends Vue {
}

private confirmRebuild() {
this.$confirm(
'Proceed with database rebuild now? All data will be lost and cannot be undone',
{
title:'Database Rebuild Confirmation',
showClose: false,
closeOnClickModal:false,
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning',
beforeClose: (action, instance, done) => {
if (action === 'confirm') {
instance.confirmButtonLoading = true
instance.confirmButtonText = 'Loading...'
}
done()
this.$confirm('Proceed with database rebuild now? All data will be lost and cannot be undone', {
title: 'Database Rebuild Confirmation',
showClose: false,
closeOnClickModal: false,
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning',
beforeClose: (action, instance, done) => {
if (action === 'confirm') {
instance.confirmButtonLoading = true
instance.confirmButtonText = 'Loading...'
}
}
)
.then(() => {
done()
},
}).then(() => {
try {
this.rebuildDatabase()
this.$log.info('Database rebuild completed. The application will restart')
Expand Down
3 changes: 3 additions & 0 deletions src/database/services/CollectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import time from '@/utils/time'
@Service()
export default class CollectionService {
constructor(
// @ts-ignore
@InjectRepository(CollectionEntity)
private collectionRepository: Repository<CollectionEntity>,
// @ts-ignore
@InjectRepository(ConnectionEntity)
private connectionRepository: Repository<ConnectionEntity>,
// @ts-ignore
@InjectRepository(WillEntity)
private willRepository: Repository<WillEntity>,
) {}
Expand Down
3 changes: 3 additions & 0 deletions src/database/services/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export const LessThanDate = (date: string | Date) => LessThan(DateUtils.mixedDat
@Service()
export default class ConnectionService {
constructor(
// @ts-ignore
@InjectRepository(ConnectionEntity)
private connectionRepository: Repository<ConnectionEntity>,
// @ts-ignore
@InjectRepository(HistoryConnectionEntity)
private historyConnectionRepository: Repository<HistoryConnectionEntity>,
// @ts-ignore
@InjectRepository(WillEntity)
private willRepository: Repository<WillEntity>,
) {}
Expand Down
1 change: 1 addition & 0 deletions src/database/services/HistoryMessageHeaderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HistoryMessageHeaderEntity from '../models/HistoryMessageHeaderEntity'
@Service()
export default class HistoryMessageHeaderService {
constructor(
// @ts-ignore
@InjectRepository(HistoryMessageHeaderEntity)
private messageRepository: Repository<HistoryMessageHeaderEntity>,
) {}
Expand Down
Loading
Loading