mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-16 13:38:41 +00:00
* merge develop * Add eslint dependencies, configs and scripts to plugins project * run lint with Github action * ignore tests and dist folders * fun eslint with --fix and manual fixes, renamed __tests_ to __tests__ * add plugins packages folder to lint-staged config * fix lint issue
33 lines
942 B
TypeScript
33 lines
942 B
TypeScript
import { QueryError } from './query.error';
|
|
|
|
const CACHED_CONNECTIONS: any = {};
|
|
|
|
export function parseJson(jsonString: string, errorMessage?: string): object {
|
|
try {
|
|
return JSON.parse(jsonString);
|
|
} catch (err) {
|
|
throw new QueryError(errorMessage, err.message, {});
|
|
}
|
|
}
|
|
|
|
export function cacheConnection(dataSourceId: string, connection: any): any {
|
|
const updatedAt = new Date();
|
|
CACHED_CONNECTIONS[dataSourceId] = { connection, updatedAt };
|
|
}
|
|
|
|
export function getCachedConnection(dataSourceId: string | number, dataSourceUpdatedAt: any): any {
|
|
const cachedData = CACHED_CONNECTIONS[dataSourceId];
|
|
|
|
if (cachedData) {
|
|
const updatedAt = new Date(dataSourceUpdatedAt || null);
|
|
const cachedAt = new Date(cachedData.updatedAt || null);
|
|
|
|
const diffTime = (cachedAt.getTime() - updatedAt.getTime()) / 1000;
|
|
|
|
if (diffTime < 0) {
|
|
return null;
|
|
} else {
|
|
return cachedData['connection'];
|
|
}
|
|
}
|
|
}
|