UNPKG

1.27 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.HAPStorage = void 0;
4const tslib_1 = require("tslib");
5// eslint-disable-next-line @typescript-eslint/ban-ts-comment
6// @ts-ignore
7const node_persist_1 = tslib_1.__importDefault(require("node-persist"));
8/**
9 * @group Model
10 */
11class HAPStorage {
12 static INSTANCE = new HAPStorage();
13 localStore;
14 customStoragePath;
15 static storage() {
16 return this.INSTANCE.storage();
17 }
18 static setCustomStoragePath(path) {
19 this.INSTANCE.setCustomStoragePath(path);
20 }
21 storage() {
22 if (!this.localStore) {
23 this.localStore = node_persist_1.default.create();
24 if (this.customStoragePath) {
25 this.localStore.initSync({
26 dir: this.customStoragePath,
27 });
28 }
29 else {
30 this.localStore.initSync();
31 }
32 }
33 return this.localStore;
34 }
35 setCustomStoragePath(path) {
36 if (this.localStore) {
37 throw new Error("Cannot change storage path after it has already been initialized!");
38 }
39 this.customStoragePath = path;
40 }
41}
42exports.HAPStorage = HAPStorage;
43//# sourceMappingURL=HAPStorage.js.map
\No newline at end of file