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

Chore: Migrate database/services and database/utils to TS #3708

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import database from '..';
import { TAppDatabase } from '../interfaces';
import { SUBSCRIPTIONS_TABLE } from '../model/Subscription';

const getCollection = db => db.get(SUBSCRIPTIONS_TABLE);
const getCollection = (db: TAppDatabase) => db.get(SUBSCRIPTIONS_TABLE);

export const getSubscriptionByRoomId = async rid => {
export const getSubscriptionByRoomId = async (rid: string) => {
const db = database.active;
const subCollection = getCollection(db);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions app/lib/database/utils.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
});
Expand Down
7 changes: 7 additions & 0 deletions app/lib/database/utils.ts
Original file line number Diff line number Diff line change
@@ -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;