chore:little fixes and formating and linting and patches

This commit is contained in:
2026-03-31 15:50:54 +02:00
parent a1ce71ffb6
commit 9b197abcfa
815 changed files with 22960 additions and 8982 deletions

View File

@@ -9,8 +9,8 @@ describe('cachable', () => {
redis = getRedisCache();
// Clear any existing cache data for clean tests
const keys = [
...await redis.keys('cachable:*'),
...await redis.keys('test-key*'),
...(await redis.keys('cachable:*')),
...(await redis.keys('test-key*')),
];
if (keys.length > 0) {
await redis.del(...keys);
@@ -20,8 +20,8 @@ describe('cachable', () => {
afterEach(async () => {
// Clean up after each test
const keys = [
...await redis.keys('cachable:*'),
...await redis.keys('test-key*'),
...(await redis.keys('cachable:*')),
...(await redis.keys('test-key*')),
];
if (keys.length > 0) {
await redis.del(...keys);
@@ -139,7 +139,7 @@ describe('cachable', () => {
const cachedFn = cacheable(
'testFunction',
async (arg1: string, arg2: string) => mockData,
3600,
3600
);
await cachedFn('arg1', 'arg2');
@@ -354,7 +354,7 @@ describe('cachable', () => {
const cachedFn = cacheable(
'testFunction',
async (arg1: string) => mockData,
3600,
3600
);
const key = cachedFn.getKey('arg1');
await redis.set(key, 'invalid json');
@@ -376,7 +376,7 @@ describe('cachable', () => {
expect(fnCalled).toBe(true);
expect(consoleSpy).toHaveBeenCalledWith(
'Failed to parse cache',
expect.any(Error),
expect.any(Error)
);
consoleSpy.mockRestore();
@@ -390,7 +390,7 @@ describe('cachable', () => {
const cachedFn = cacheable(
'testFunction',
async (arg1: string) => cachedData,
3600,
3600
);
await cachedFn('arg1');
@@ -478,7 +478,7 @@ describe('cachable', () => {
arg5: undefined,
arg6: number[],
arg7: { a: number; b: number },
arg8: Date,
arg8: Date
) => ({});
const cachedFn = cacheable(fn, 3600);
@@ -490,7 +490,7 @@ describe('cachable', () => {
undefined,
[1, 2, 3],
{ a: 1, b: 2 },
new Date('2023-01-01T00:00:00Z'),
new Date('2023-01-01T00:00:00Z')
);
expect(key).toMatch(/^cachable:.*:/);

View File

@@ -1,4 +1,4 @@
export * from './redis';
export * from './cachable';
export * from './run-every';
export * from './publisher';
export * from './redis';
export * from './run-every';

View File

@@ -1,7 +1,6 @@
import { type Redis, getRedisPub, getRedisSub } from './redis';
import type { IServiceEvent, Notification, Prisma } from '@openpanel/db';
import type { Prisma } from '@openpanel/db';
import { getSuperJson, setSuperJson } from '@openpanel/json';
import { getRedisPub, getRedisSub, type Redis } from './redis';
export type IPublishChannels = {
organization: {
@@ -19,7 +18,7 @@ export type IPublishChannels = {
export function getSubscribeChannel<Channel extends keyof IPublishChannels>(
channel: Channel,
type: keyof IPublishChannels[Channel],
type: keyof IPublishChannels[Channel]
) {
return `${channel}:${String(type)}`;
}
@@ -28,7 +27,7 @@ export function publishEvent<Channel extends keyof IPublishChannels>(
channel: Channel,
type: keyof IPublishChannels[Channel],
event: IPublishChannels[Channel][typeof type],
multi?: ReturnType<Redis['multi']>,
multi?: ReturnType<Redis['multi']>
) {
const redis = multi ?? getRedisPub();
return redis.publish(getSubscribeChannel(channel, type), setSuperJson(event));
@@ -37,7 +36,7 @@ export function publishEvent<Channel extends keyof IPublishChannels>(
export function parsePublishedEvent<Channel extends keyof IPublishChannels>(
_channel: Channel,
_type: keyof IPublishChannels[Channel],
message: string,
message: string
): IPublishChannels[Channel][typeof _type] {
return getSuperJson<IPublishChannels[Channel][typeof _type]>(message)!;
}
@@ -47,7 +46,7 @@ export function subscribeToPublishedEvent<
>(
channel: Channel,
type: keyof IPublishChannels[Channel],
callback: (event: IPublishChannels[Channel][typeof type]) => void,
callback: (event: IPublishChannels[Channel][typeof type]) => void
) {
const subscribeChannel = getSubscribeChannel(channel, type);
getRedisSub().subscribe(subscribeChannel);
@@ -71,7 +70,7 @@ export function subscribeToPublishedEvent<
export function psubscribeToPublishedEvent(
pattern: string,
callback: (key: string) => void,
callback: (key: string) => void
) {
getRedisSub().psubscribe(pattern);
const pmessage = (_: unknown, pattern: string, key: string) => callback(key);

View File

@@ -3,7 +3,7 @@ import type { RedisOptions } from 'ioredis';
import { Redis } from 'ioredis';
const options: RedisOptions = {
connectTimeout: 10000,
connectTimeout: 10_000,
};
export { Redis };
@@ -15,14 +15,14 @@ export interface ExtendedRedis extends Redis {
setJson: <T = any>(
key: string,
expireInSec: number,
value: T,
value: T
) => Promise<void>;
}
const createRedisClient = (
name: string,
url: string,
overrides: RedisOptions = {},
overrides: RedisOptions = {}
): ExtendedRedis => {
const client = new Redis(url, {
...options,
@@ -55,7 +55,7 @@ const createRedisClient = (
client.setJson = async <T = any>(
key: string,
expireInSec: number,
value: T,
value: T
): Promise<void> => {
await client.setex(key, expireInSec, setSuperJson(value));
};