diff --git a/app/lib/database/services/Message.js b/app/lib/database/services/Message.ts similarity index 61% rename from app/lib/database/services/Message.js rename to app/lib/database/services/Message.ts index 562bf589d9..60295b3711 100644 --- a/app/lib/database/services/Message.js +++ b/app/lib/database/services/Message.ts @@ -1,9 +1,10 @@ import database from '..'; +import { TAppDatabase } from '../interfaces'; import { MESSAGES_TABLE } from '../model/Message'; -const getCollection = db => db.get(MESSAGES_TABLE); +const getCollection = (db: TAppDatabase) => db.get(MESSAGES_TABLE); -export const getMessageById = async messageId => { +export const getMessageById = async (messageId: string) => { const db = database.active; const messageCollection = getCollection(db); try { diff --git a/app/lib/database/services/Thread.js b/app/lib/database/services/Thread.ts similarity index 61% rename from app/lib/database/services/Thread.js rename to app/lib/database/services/Thread.ts index 9d90dc00d8..8dc61b8a4d 100644 --- a/app/lib/database/services/Thread.js +++ b/app/lib/database/services/Thread.ts @@ -1,9 +1,10 @@ import database from '..'; +import { TAppDatabase } from '../interfaces'; import { THREADS_TABLE } from '../model/Thread'; -const getCollection = db => db.get(THREADS_TABLE); +const getCollection = (db: TAppDatabase) => db.get(THREADS_TABLE); -export const getThreadById = async tmid => { +export const getThreadById = async (tmid: string) => { const db = database.active; const threadCollection = getCollection(db); try { diff --git a/app/lib/database/services/ThreadMessage.js b/app/lib/database/services/ThreadMessage.ts similarity index 61% rename from app/lib/database/services/ThreadMessage.js rename to app/lib/database/services/ThreadMessage.ts index 7ac937b2a0..899693f841 100644 --- a/app/lib/database/services/ThreadMessage.js +++ b/app/lib/database/services/ThreadMessage.ts @@ -1,9 +1,10 @@ import database from '..'; +import { TAppDatabase } from '../interfaces'; import { THREAD_MESSAGES_TABLE } from '../model/ThreadMessage'; -const getCollection = db => db.get(THREAD_MESSAGES_TABLE); +const getCollection = (db: TAppDatabase) => db.get(THREAD_MESSAGES_TABLE); -export const getThreadMessageById = async messageId => { +export const getThreadMessageById = async (messageId: string) => { const db = database.active; const threadMessageCollection = getCollection(db); try { diff --git a/app/lib/database/utils.js b/app/lib/database/utils.js deleted file mode 100644 index 472af733b6..0000000000 --- a/app/lib/database/utils.js +++ /dev/null @@ -1,7 +0,0 @@ -import XRegExp from 'xregexp'; - -// Matches letters from any alphabet and numbers -const likeStringRegex = new XRegExp('[^\\p{L}\\p{Nd}]', 'g'); -export const sanitizeLikeString = str => str?.replace(likeStringRegex, '_'); - -export const sanitizer = r => r; diff --git a/app/lib/database/utils.test.js b/app/lib/database/utils.test.ts similarity index 89% rename from app/lib/database/utils.test.js rename to app/lib/database/utils.test.ts index 8c1d054e17..54ecbab6a8 100644 --- a/app/lib/database/utils.test.js +++ b/app/lib/database/utils.test.ts @@ -1,14 +1,12 @@ -/* eslint-disable no-undef */ import * as utils from './utils'; describe('sanitizeLikeStringTester', () => { // example chars that shouldn't return const disallowedChars = ',./;[]!@#$%^&*()_-=+~'; - const sanitizeLikeStringTester = str => + const sanitizeLikeStringTester = (str: string) => expect(utils.sanitizeLikeString(`${str}${disallowedChars}`)).toBe(`${str}${'_'.repeat(disallowedChars.length)}`); test('render empty', () => { - expect(utils.sanitizeLikeString(null)).toBe(undefined); expect(utils.sanitizeLikeString('')).toBe(''); expect(utils.sanitizeLikeString(undefined)).toBe(undefined); }); diff --git a/app/lib/database/utils.ts b/app/lib/database/utils.ts new file mode 100644 index 0000000000..a5b9d8e8d7 --- /dev/null +++ b/app/lib/database/utils.ts @@ -0,0 +1,7 @@ +import XRegExp from 'xregexp'; + +// Matches letters from any alphabet and numbers +const likeStringRegex = XRegExp('[^\\p{L}\\p{Nd}]', 'g'); +export const sanitizeLikeString = (str?: string): string | undefined => str?.replace(likeStringRegex, '_'); + +export const sanitizer = (r: object): object => r;