-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistributedLockFactory.mts
26 lines (23 loc) · 1.14 KB
/
DistributedLockFactory.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { DistributedLock } from "./DistributedLock.mjs";
import { DistributedLockDb } from "./DistributedLockDb.mjs";
import { logger, TMMLogger } from "@tmm/tools/logger";
import type { Metrics } from "@aws-lambda-powertools/metrics";
import type { DistributedLockDependencies, DistributedLockParams } from "./DistributedLock.mjs";
export class DistributedLockFactory {
readonly #lockDb: DistributedLockDb;
readonly #logger: TMMLogger;
readonly #metrics?: Metrics;
constructor({ lockDb = new DistributedLockDb(), loggerInstance = logger, metricsInstance }: DistributedLockDependencies = {}) {
this.#lockDb = lockDb;
this.#logger = loggerInstance;
this.#metrics = metricsInstance;
//mocks may not have setlogger method
if (typeof this.#lockDb.setlogger === "function") {
this.#lockDb.setlogger(this.#logger);
}
}
createLock(params: DistributedLockParams): DistributedLock {
return new DistributedLock(params, { lockDb: this.#lockDb, loggerInstance: this.#logger, metricsInstance: this.#metrics });
}
}
export type { DistributedLockDependencies, DistributedLockParams };