Skip to content

Commit c9385ac

Browse files
fix type error
1 parent b1f012b commit c9385ac

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

packages/backend/src/repoIndexManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class RepoIndexManager {
253253
const lockKey = `${LOCK_PREFIX}${groupId}`;
254254

255255
try {
256-
return await this.redlock.using([lockKey], LOCK_TTL_MS, async (lockSignal) => {
256+
return await this.redlock.using([lockKey], LOCK_TTL_MS, async (lockSignal: AbortSignal) => {
257257
const signal = AbortSignal.any([
258258
this.abortController.signal,
259259
lockSignal,
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Type declarations for redlock
2+
// The redlock package's exports field doesn't include types, so TypeScript can't resolve them.
3+
// This file re-exports the types from the actual .d.ts file.
4+
5+
declare module 'redlock' {
6+
import { EventEmitter } from "events";
7+
import { Redis as IORedisClient, Cluster as IORedisCluster } from "ioredis";
8+
9+
type Client = IORedisClient | IORedisCluster;
10+
11+
export type ClientExecutionResult = {
12+
client: Client;
13+
vote: "for";
14+
value: number;
15+
} | {
16+
client: Client;
17+
vote: "against";
18+
error: Error;
19+
};
20+
21+
export type ExecutionStats = {
22+
readonly membershipSize: number;
23+
readonly quorumSize: number;
24+
readonly votesFor: Set<Client>;
25+
readonly votesAgainst: Map<Client, Error>;
26+
};
27+
28+
export type ExecutionResult = {
29+
attempts: ReadonlyArray<Promise<ExecutionStats>>;
30+
};
31+
32+
export interface Settings {
33+
readonly driftFactor: number;
34+
readonly retryCount: number;
35+
readonly retryDelay: number;
36+
readonly retryJitter: number;
37+
readonly automaticExtensionThreshold: number;
38+
}
39+
40+
export class ResourceLockedError extends Error {
41+
readonly message: string;
42+
constructor(message: string);
43+
}
44+
45+
export class ExecutionError extends Error {
46+
readonly message: string;
47+
readonly attempts: ReadonlyArray<Promise<ExecutionStats>>;
48+
constructor(message: string, attempts: ReadonlyArray<Promise<ExecutionStats>>);
49+
}
50+
51+
export class Lock {
52+
readonly redlock: Redlock;
53+
readonly resources: string[];
54+
readonly value: string;
55+
readonly attempts: ReadonlyArray<Promise<ExecutionStats>>;
56+
expiration: number;
57+
constructor(redlock: Redlock, resources: string[], value: string, attempts: ReadonlyArray<Promise<ExecutionStats>>, expiration: number);
58+
release(): Promise<ExecutionResult>;
59+
extend(duration: number): Promise<Lock>;
60+
}
61+
62+
export type RedlockAbortSignal = AbortSignal & {
63+
error?: Error;
64+
};
65+
66+
export default class Redlock extends EventEmitter {
67+
readonly clients: Set<Client>;
68+
readonly settings: Settings;
69+
readonly scripts: {
70+
readonly acquireScript: {
71+
value: string;
72+
hash: string;
73+
};
74+
readonly extendScript: {
75+
value: string;
76+
hash: string;
77+
};
78+
readonly releaseScript: {
79+
value: string;
80+
hash: string;
81+
};
82+
};
83+
constructor(clients: Iterable<Client>, settings?: Partial<Settings>, scripts?: {
84+
readonly acquireScript?: string | ((script: string) => string);
85+
readonly extendScript?: string | ((script: string) => string);
86+
readonly releaseScript?: string | ((script: string) => string);
87+
});
88+
quit(): Promise<void>;
89+
acquire(resources: string[], duration: number, settings?: Partial<Settings>): Promise<Lock>;
90+
release(lock: Lock, settings?: Partial<Settings>): Promise<ExecutionResult>;
91+
extend(existing: Lock, duration: number, settings?: Partial<Settings>): Promise<Lock>;
92+
using<T>(resources: string[], duration: number, settings: Partial<Settings>, routine?: (signal: RedlockAbortSignal) => Promise<T>): Promise<T>;
93+
using<T>(resources: string[], duration: number, routine: (signal: RedlockAbortSignal) => Promise<T>): Promise<T>;
94+
}
95+
}

packages/backend/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
// This improves issue grouping in Sentry.
2828
"sourceRoot": "/"
2929
},
30-
"include": ["src/index.ts"],
30+
"include": ["src/index.ts", "src/types/**/*.d.ts"],
3131
"exclude": ["node_modules"]
3232
}

0 commit comments

Comments
 (0)