Skip to content

Commit 5be7636

Browse files
committed
Clarify type for the customCache
1 parent c93419f commit 5be7636

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/qrgenerator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createHmac } from "node:crypto";
22
import type { AuthResponse } from "./bankid";
33

4-
type QrCache = {
4+
interface QrCache {
55
startTime: number;
66
qrStartToken: string;
77
qrStartSecret: string;
8-
};
8+
}
99

1010
interface QRGenerateOptions {
1111
/** max cycles */
@@ -14,10 +14,14 @@ interface QRGenerateOptions {
1414
timeout?: number;
1515
}
1616

17+
export type MapCompatibleCache = Pick<typeof defaultCache, "get" | "delete"> & {
18+
set: (key: string, value: QrCache) => void;
19+
};
20+
1721
export type QrGeneratorOptions =
1822
| {
1923
/** Provide your own `Map`-compatible caching layer */
20-
customCache: typeof defaultCache;
24+
customCache: MapCompatibleCache;
2125
}
2226
| {
2327
orderTTL: number;
@@ -33,7 +37,7 @@ const defaultCache = new Map<string, QrCache>();
3337
const TIMEOUT = 60 as const;
3438

3539
export class QrGenerator {
36-
cache = defaultCache;
40+
cache: MapCompatibleCache = defaultCache;
3741

3842
static defaultOptions = { orderTTL: TIMEOUT } as const;
3943

0 commit comments

Comments
 (0)