chore(root): migrate to biome

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-16 12:20:40 +02:00
parent 1f6e198336
commit 32e91959f6
383 changed files with 1943 additions and 3085 deletions

View File

@@ -2,7 +2,7 @@ import { getRedisCache } from './redis';
export function cacheable<T extends (...args: any) => any>(
fn: T,
expireInSec: number
expireInSec: number,
) {
const cachePrefix = `cachable:${fn.name}`;
function stringify(obj: unknown): string {
@@ -14,7 +14,7 @@ export function cacheable<T extends (...args: any) => any>(
if (typeof obj === 'function') return obj.toString();
if (Array.isArray(obj)) {
return '[' + obj.map(stringify).join(',') + ']';
return `[${obj.map(stringify).join(',')}]`;
}
if (typeof obj === 'object') {
@@ -29,9 +29,9 @@ export function cacheable<T extends (...args: any) => any>(
}
const getKey = (...args: Parameters<T>) =>
`${cachePrefix}:${stringify(args)}`;
const cachedFn = async function (
const cachedFn = async (
...args: Parameters<T>
): Promise<Awaited<ReturnType<T>>> {
): Promise<Awaited<ReturnType<T>>> => {
// JSON.stringify here is not bullet proof since ordering of object keys matters etc
const key = getKey(...args);
const cached = await getRedisCache().get(key);
@@ -52,7 +52,7 @@ export function cacheable<T extends (...args: any) => any>(
};
cachedFn.getKey = getKey;
cachedFn.clear = async function (...args: Parameters<T>) {
cachedFn.clear = async (...args: Parameters<T>) => {
const key = getKey(...args);
return getRedisCache().del(key);
};

View File

@@ -3,29 +3,15 @@
"version": "0.0.1",
"main": "index.ts",
"scripts": {
"lint": "eslint .",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"typecheck": "tsc --noEmit",
"with-env": "dotenv -e ../../.env -c --"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"ioredis": "^5.4.1"
},
"devDependencies": {
"@openpanel/eslint-config": "workspace:*",
"@openpanel/prettier-config": "workspace:*",
"@openpanel/tsconfig": "workspace:*",
"@types/node": "^18.16.0",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"prisma": "^5.1.1",
"typescript": "^5.2.2"
},
"eslintConfig": {
"root": true,
"extends": [
"@openpanel/eslint-config/base"
]
},
"prettier": "@openpanel/prettier-config"
}
}
}

View File

@@ -9,7 +9,7 @@ export { Redis };
const createRedisClient = (
url: string,
overrides: RedisOptions = {}
overrides: RedisOptions = {},
): Redis => {
const client = new Redis(url, { ...options, ...overrides });
@@ -58,7 +58,7 @@ export function getRedisQueue() {
enableReadyCheck: false,
maxRetriesPerRequest: null,
enableOfflineQueue: true,
}
},
);
}