hap-nodejs
Version:
HAP-NodeJS is a Node.js implementation of HomeKit Accessory Server.
43 lines • 1.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.HAPStorage = void 0;
const tslib_1 = require("tslib");
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const node_persist_1 = tslib_1.__importDefault(require("node-persist"));
/**
* @group Model
*/
class HAPStorage {
static INSTANCE = new HAPStorage();
localStore;
customStoragePath;
static storage() {
return this.INSTANCE.storage();
}
static setCustomStoragePath(path) {
this.INSTANCE.setCustomStoragePath(path);
}
storage() {
if (!this.localStore) {
this.localStore = node_persist_1.default.create();
if (this.customStoragePath) {
this.localStore.initSync({
dir: this.customStoragePath,
});
}
else {
this.localStore.initSync();
}
}
return this.localStore;
}
setCustomStoragePath(path) {
if (this.localStore) {
throw new Error("Cannot change storage path after it has already been initialized!");
}
this.customStoragePath = path;
}
}
exports.HAPStorage = HAPStorage;
//# sourceMappingURL=HAPStorage.js.map
;