Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iobroker/db-base

Package Overview
Dependencies
Maintainers
6
Versions
424
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iobroker/db-base - npm Package Compare versions

Comparing version 5.0.20-alpha.0-20240409-d68ed299 to 5.0.20-alpha.0-20240418-165fc4c8

4

build/cjs/index.d.ts

@@ -1,4 +0,4 @@

export { InMemoryFileDB } from './lib/inMemFileDB';
export { RedisHandler } from './lib/redisHandler';
export { InMemoryFileDB } from './lib/inMemFileDB.js';
export { RedisHandler } from './lib/redisHandler.js';
export { tools } from '@iobroker/js-controller-common';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tools = exports.RedisHandler = exports.InMemoryFileDB = void 0;
var inMemFileDB_1 = require("./lib/inMemFileDB");
Object.defineProperty(exports, "InMemoryFileDB", { enumerable: true, get: function() {
return inMemFileDB_1.InMemoryFileDB;
} });
var redisHandler_1 = require("./lib/redisHandler");
Object.defineProperty(exports, "RedisHandler", { enumerable: true, get: function() {
return redisHandler_1.RedisHandler;
} });
var js_controller_common_1 = require("@iobroker/js-controller-common");
Object.defineProperty(exports, "tools", { enumerable: true, get: function() {
return js_controller_common_1.tools;
} });
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var esm_exports = {};
__export(esm_exports, {
InMemoryFileDB: () => import_inMemFileDB.InMemoryFileDB,
RedisHandler: () => import_redisHandler.RedisHandler,
tools: () => import_js_controller_common.tools
});
module.exports = __toCommonJS(esm_exports);
var import_inMemFileDB = require("./lib/inMemFileDB.js");
var import_redisHandler = require("./lib/redisHandler.js");
var import_js_controller_common = require("@iobroker/js-controller-common");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InMemoryFileDB,
RedisHandler,
tools
});
//# sourceMappingURL=index.js.map

@@ -1,4 +0,4 @@

/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
export declare const QUEUED_STR_BUF: Buffer;
export declare const OK_STR_BUF: Buffer;
//# sourceMappingURL=constants.d.ts.map
"use strict";
var __importDefault = exports && exports.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OK_STR_BUF = exports.QUEUED_STR_BUF = void 0;
const respjs_1 = __importDefault(require("respjs"));
exports.QUEUED_STR_BUF = respjs_1.default.encodeString("QUEUED");
exports.OK_STR_BUF = respjs_1.default.encodeString("OK");
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var constants_exports = {};
__export(constants_exports, {
OK_STR_BUF: () => OK_STR_BUF,
QUEUED_STR_BUF: () => QUEUED_STR_BUF
});
module.exports = __toCommonJS(constants_exports);
var import_respjs = __toESM(require("respjs"), 1);
const QUEUED_STR_BUF = import_respjs.default.encodeString("QUEUED");
const OK_STR_BUF = import_respjs.default.encodeString("OK");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
OK_STR_BUF,
QUEUED_STR_BUF
});
//# sourceMappingURL=constants.js.map
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __importDefault = exports && exports.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryFileDB = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const js_controller_common_1 = require("@iobroker/js-controller-common");
const zlib_1 = require("zlib");
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var inMemFileDB_exports = {};
__export(inMemFileDB_exports, {
InMemoryFileDB: () => InMemoryFileDB
});
module.exports = __toCommonJS(inMemFileDB_exports);
var import_fs_extra = __toESM(require("fs-extra"), 1);
var import_node_path = __toESM(require("node:path"), 1);
var import_js_controller_common = require("@iobroker/js-controller-common");
var import_node_zlib = require("node:zlib");
class InMemoryFileDB {
settings;
change;
dataset;
namespace;
lastSave;
stateTimer;
callbackSubscriptionClient;
dataDir;
datasetName;
log;
backupDir;
constructor(settings) {
__publicField(this, "settings");
__publicField(this, "change");
__publicField(this, "dataset");
__publicField(this, "namespace");
__publicField(this, "lastSave");
__publicField(this, "stateTimer");
__publicField(this, "callbackSubscriptionClient");
__publicField(this, "dataDir");
__publicField(this, "datasetName");
__publicField(this, "log");
__publicField(this, "backupDir");
this.settings = settings || {};

@@ -43,14 +60,14 @@ this.change = this.settings.change;

};
this.dataDir = this.settings.connection.dataDir || js_controller_common_1.tools.getDefaultDataDir();
if (!path_1.default.isAbsolute(this.dataDir)) {
this.dataDir = path_1.default.normalize(path_1.default.join(js_controller_common_1.tools.getControllerDir(), this.dataDir));
this.dataDir = this.settings.connection.dataDir || import_js_controller_common.tools.getDefaultDataDir();
if (!import_node_path.default.isAbsolute(this.dataDir)) {
this.dataDir = import_node_path.default.normalize(import_node_path.default.join(import_js_controller_common.tools.getControllerDir(), this.dataDir));
}
this.dataDir = this.dataDir.replace(/\\/g, "/");
const fileName = this.settings.jsonlDB ? this.settings.jsonlDB.fileName : this.settings.fileDB.fileName;
this.datasetName = path_1.default.join(this.dataDir, fileName);
const parts = path_1.default.dirname(this.datasetName);
fs_extra_1.default.ensureDirSync(parts);
this.datasetName = import_node_path.default.join(this.dataDir, fileName);
const parts = import_node_path.default.dirname(this.datasetName);
import_fs_extra.default.ensureDirSync(parts);
this.stateTimer = null;
this.backupDir = this.settings.backup.path || path_1.default.join(this.dataDir, this.settings.fileDB.backupDirName);
this.log = js_controller_common_1.tools.getLogger(this.settings.logger);
this.backupDir = this.settings.backup.path || import_node_path.default.join(this.dataDir, this.settings.fileDB.backupDirName);
this.log = import_js_controller_common.tools.getLogger(this.settings.logger);
if (!this.settings.backup.disabled) {

@@ -71,6 +88,6 @@ try {

async loadDatasetFile(datasetName) {
if (!await fs_extra_1.default.pathExists(datasetName)) {
if (!await import_fs_extra.default.pathExists(datasetName)) {
throw new Error(`Database file ${datasetName} does not exists.`);
}
return fs_extra_1.default.readJSON(datasetName);
return import_fs_extra.default.readJSON(datasetName);
}

@@ -82,3 +99,3 @@ async loadDataset(datasetName) {

try {
await fs_extra_1.default.readJSON(`${datasetName}.bak`);
await import_fs_extra.default.readJSON(`${datasetName}.bak`);
} catch (e) {

@@ -88,3 +105,3 @@ this.log.info(`${this.namespace} Rewrite bak file, because error on verify ${datasetName}.bak: ${e.message}`);

const jsonString = JSON.stringify(ret);
await fs_extra_1.default.writeFile(`${datasetName}.bak`, jsonString);
await import_fs_extra.default.writeFile(`${datasetName}.bak`, jsonString);
} catch (e2) {

@@ -99,5 +116,5 @@ this.log.error(`${this.namespace} Cannot save ${datasetName}.bak: ${e2.message}`);

try {
if (await fs_extra_1.default.pathExists(datasetName)) {
if (await import_fs_extra.default.pathExists(datasetName)) {
try {
await fs_extra_1.default.move(datasetName, `${datasetName}.broken`, { overwrite: true });
await import_fs_extra.default.move(datasetName, `${datasetName}.broken`, { overwrite: true });
} catch (e) {

@@ -107,3 +124,3 @@ this.log.error(`${this.namespace} Cannot copy the broken file ${datasetName} to ${datasetName}.broken ${e.message}`);

try {
await fs_extra_1.default.writeFile(datasetName, JSON.stringify(ret));
await import_fs_extra.default.writeFile(datasetName, JSON.stringify(ret));
} catch (e) {

@@ -141,3 +158,3 @@ this.log.error(`${this.namespace} Cannot restore backup file as new main ${datasetName}: ${e.message}`);

}
fs_extra_1.default.ensureDirSync(this.backupDir);
import_fs_extra.default.ensureDirSync(this.backupDir);
}

@@ -157,7 +174,7 @@ handleSubscribe(client, type, pattern, options, cb) {

}
s.push({ pattern: pattern2, regex: new RegExp(js_controller_common_1.tools.pattern2RegEx(pattern2)), options });
s.push({ pattern: pattern2, regex: new RegExp(import_js_controller_common.tools.pattern2RegEx(pattern2)), options });
});
} else {
if (!s.find((sub) => sub.pattern === pattern)) {
s.push({ pattern, regex: new RegExp(js_controller_common_1.tools.pattern2RegEx(pattern)), options });
s.push({ pattern, regex: new RegExp(import_js_controller_common.tools.pattern2RegEx(pattern)), options });
}

@@ -168,4 +185,3 @@ }

handleUnsubscribe(client, type, pattern, cb) {
var _a;
const s = (_a = client == null ? void 0 : client._subscribe) == null ? void 0 : _a[type];
const s = client?._subscribe?.[type];
if (s) {

@@ -186,3 +202,3 @@ const removeEntry = (p) => {

}
return js_controller_common_1.tools.maybeCallback(cb);
return import_js_controller_common.tools.maybeCallback(cb);
}

@@ -193,3 +209,3 @@ publishToClients(_client, _type, _id, _obj) {

deleteOldBackupFiles(baseFilename) {
let files = fs_extra_1.default.readdirSync(this.backupDir);
let files = import_fs_extra.default.readdirSync(this.backupDir);
files.sort();

@@ -206,5 +222,5 @@ const limit = Date.now() - this.settings.backup.hours * 36e5;

try {
fs_extra_1.default.unlinkSync(path_1.default.join(this.backupDir, file));
import_fs_extra.default.unlinkSync(import_node_path.default.join(this.backupDir, file));
} catch (e) {
this.log.error(`${this.namespace} Cannot delete file "${path_1.default.join(this.backupDir, file)}: ${e.message}`);
this.log.error(`${this.namespace} Cannot delete file "${import_node_path.default.join(this.backupDir, file)}: ${e.message}`);
}

@@ -255,3 +271,3 @@ }

try {
await fs_extra_1.default.writeFile(`${this.datasetName}.new`, jsonString);
await import_fs_extra.default.writeFile(`${this.datasetName}.new`, jsonString);
} catch (e) {

@@ -263,5 +279,5 @@ this.log.error(`${this.namespace} Cannot save Dataset to ${this.datasetName}.new: ${e.message}`);

try {
if (await fs_extra_1.default.pathExists(this.datasetName)) {
if (await import_fs_extra.default.pathExists(this.datasetName)) {
try {
await fs_extra_1.default.move(this.datasetName, `${this.datasetName}.bak`, { overwrite: true });
await import_fs_extra.default.move(this.datasetName, `${this.datasetName}.bak`, { overwrite: true });
} catch (e) {

@@ -278,7 +294,7 @@ bakOk = false;

try {
await fs_extra_1.default.move(`${this.datasetName}.new`, this.datasetName, { overwrite: true });
await import_fs_extra.default.move(`${this.datasetName}.new`, this.datasetName, { overwrite: true });
} catch (e) {
this.log.error(`${this.namespace} Cannot move ${this.datasetName}.new to ${this.datasetName}: ${e.message}. Try direct write as fallback`);
try {
await fs_extra_1.default.writeFile(this.datasetName, jsonString);
await import_fs_extra.default.writeFile(this.datasetName, jsonString);
} catch (e2) {

@@ -291,3 +307,3 @@ this.log.error(`${this.namespace} Cannot directly write Dataset to ${this.datasetName}: ${e2.message}`);

try {
await fs_extra_1.default.writeFile(`${this.datasetName}.bak`, jsonString);
await import_fs_extra.default.writeFile(`${this.datasetName}.bak`, jsonString);
} catch (e) {

@@ -303,10 +319,10 @@ this.log.error(`${this.namespace} Cannot save ${this.datasetName}.bak: ${e.message}`);

this.lastSave = now;
const backFileName = path_1.default.join(this.backupDir, this.getTimeStr(now) + "_" + this.settings.fileDB.fileName + ".gz");
const backFileName = import_node_path.default.join(this.backupDir, this.getTimeStr(now) + "_" + this.settings.fileDB.fileName + ".gz");
try {
if (!fs_extra_1.default.existsSync(backFileName)) {
const output = fs_extra_1.default.createWriteStream(backFileName);
if (!import_fs_extra.default.existsSync(backFileName)) {
const output = import_fs_extra.default.createWriteStream(backFileName);
output.on("error", (err) => {
this.log.error(`${this.namespace} Cannot save ${this.datasetName}: ${err.stack}`);
});
const compress = (0, zlib_1.createGzip)();
const compress = (0, import_node_zlib.createGzip)();
compress.pipe(output);

@@ -357,3 +373,6 @@ compress.write(jsonString);

}
exports.InMemoryFileDB = InMemoryFileDB;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InMemoryFileDB
});
//# sourceMappingURL=inMemFileDB.js.map

@@ -1,6 +0,6 @@

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import type { Socket } from 'net';
import { EventEmitter } from 'events';
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import type { Socket } from 'node:net';
import { EventEmitter } from 'node:events';
import type { InternalLogger } from '@iobroker/js-controller-common/tools';

@@ -7,0 +7,0 @@ type NestedArray<T> = T[] | NestedArray<T>[];

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __importDefault = exports && exports.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisHandler = void 0;
const respjs_1 = __importDefault(require("respjs"));
const events_1 = require("events");
const constants_1 = require("./constants");
class RedisHandler extends events_1.EventEmitter {
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var redisHandler_exports = {};
__export(redisHandler_exports, {
RedisHandler: () => RedisHandler
});
module.exports = __toCommonJS(redisHandler_exports);
var import_respjs = __toESM(require("respjs"), 1);
var import_node_events = require("node:events");
var import_constants = require("./constants.js");
class RedisHandler extends import_node_events.EventEmitter {
socket;
logScope;
handleBuffers;
options;
log;
socketId;
initialized;
stop;
activeMultiCalls;
writeQueue;
responseId = 0;
resp;
constructor(socket, options) {
super();
__publicField(this, "socket");
__publicField(this, "logScope");
__publicField(this, "handleBuffers");
__publicField(this, "options");
__publicField(this, "log");
__publicField(this, "socketId");
__publicField(this, "initialized");
__publicField(this, "stop");
__publicField(this, "activeMultiCalls");
__publicField(this, "writeQueue");
__publicField(this, "responseId", 0);
__publicField(this, "resp");
options = options || {};

@@ -50,3 +67,3 @@ this.options = options;

}
this.resp = new respjs_1.default(respOptions);
this.resp = new import_respjs.default(respOptions);
this.resp.on("error", (err) => {

@@ -167,3 +184,3 @@ this.log.error(`${this.socketId} (Init=${this.initialized}) Redis error:${err}`);

this.log.warn(`${this.socketId} Not able to write ${JSON.stringify(data)}`);
data = respjs_1.default.encodeError(new Error(`INVALID RESPONSE: ${JSON.stringify(data)}`));
data = import_respjs.default.encodeError(new Error(`INVALID RESPONSE: ${JSON.stringify(data)}`));
}

@@ -183,7 +200,7 @@ setImmediate(() => this._sendQueued(responseId, data));

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeNull());
this._handleMultiResponse(responseId, i, import_respjs.default.encodeNull());
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeNull());
this.sendResponse(responseId, import_respjs.default.encodeNull());
}

@@ -193,7 +210,7 @@ sendNullArray(responseId) {

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeNullArray());
this._handleMultiResponse(responseId, i, import_respjs.default.encodeNullArray());
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeNullArray());
this.sendResponse(responseId, import_respjs.default.encodeNullArray());
}

@@ -203,7 +220,7 @@ sendString(responseId, str) {

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeString(str));
this._handleMultiResponse(responseId, i, import_respjs.default.encodeString(str));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeString(str));
this.sendResponse(responseId, import_respjs.default.encodeString(str));
}

@@ -214,7 +231,7 @@ sendError(responseId, error) {

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeError(error));
this._handleMultiResponse(responseId, i, import_respjs.default.encodeError(error));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeError(error));
this.sendResponse(responseId, import_respjs.default.encodeError(error));
}

@@ -224,7 +241,7 @@ sendInteger(responseId, num) {

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeInteger(num));
this._handleMultiResponse(responseId, i, import_respjs.default.encodeInteger(num));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeInteger(num));
this.sendResponse(responseId, import_respjs.default.encodeInteger(num));
}

@@ -234,7 +251,7 @@ sendBulk(responseId, str) {

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeBulk(str));
this._handleMultiResponse(responseId, i, import_respjs.default.encodeBulk(str));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeBulk(str));
this.sendResponse(responseId, import_respjs.default.encodeBulk(str));
}

@@ -244,7 +261,7 @@ sendBufBulk(responseId, buf) {

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeBufBulk(buf));
this._handleMultiResponse(responseId, i, import_respjs.default.encodeBufBulk(buf));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeBufBulk(buf));
this.sendResponse(responseId, import_respjs.default.encodeBufBulk(buf));
}

@@ -257,9 +274,9 @@ encodeRespArray(arr) {

} else if (Buffer.isBuffer(value)) {
returnArr[i] = respjs_1.default.encodeBufBulk(value);
returnArr[i] = import_respjs.default.encodeBufBulk(value);
} else if (value === null) {
returnArr[i] = respjs_1.default.encodeNull();
returnArr[i] = import_respjs.default.encodeNull();
} else if (typeof value === "number") {
returnArr[i] = respjs_1.default.encodeInteger(value);
returnArr[i] = import_respjs.default.encodeInteger(value);
} else {
returnArr[i] = respjs_1.default.encodeBulk(value);
returnArr[i] = import_respjs.default.encodeBulk(value);
}

@@ -272,7 +289,7 @@ });

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeArray(this.encodeRespArray(arr)));
this._handleMultiResponse(responseId, i, import_respjs.default.encodeArray(this.encodeRespArray(arr)));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeArray(this.encodeRespArray(arr)));
this.sendResponse(responseId, import_respjs.default.encodeArray(this.encodeRespArray(arr)));
}

@@ -300,4 +317,4 @@ _handleMulti() {

_sendExecResponse(multiObj) {
const queuedStrArr = new Array(multiObj.responseCount).fill(constants_1.QUEUED_STR_BUF);
this._sendQueued(multiObj.execId, Buffer.concat([constants_1.OK_STR_BUF, ...queuedStrArr, respjs_1.default.encodeArray(Array.from(multiObj.responseMap.values()))]));
const queuedStrArr = new Array(multiObj.responseCount).fill(import_constants.QUEUED_STR_BUF);
this._sendQueued(multiObj.execId, Buffer.concat([import_constants.OK_STR_BUF, ...queuedStrArr, import_respjs.default.encodeArray(Array.from(multiObj.responseMap.values()))]));
}

@@ -313,3 +330,6 @@ _handleMultiResponse(responseId, index, buf) {

}
exports.RedisHandler = RedisHandler;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
RedisHandler
});
//# sourceMappingURL=redisHandler.js.map

@@ -1,4 +0,4 @@

export { InMemoryFileDB } from './lib/inMemFileDB';
export { RedisHandler } from './lib/redisHandler';
export { InMemoryFileDB } from './lib/inMemFileDB.js';
export { RedisHandler } from './lib/redisHandler.js';
export { tools } from '@iobroker/js-controller-common';
//# sourceMappingURL=index.d.ts.map

@@ -1,10 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tools = exports.RedisHandler = exports.InMemoryFileDB = void 0;
var inMemFileDB_1 = require("./lib/inMemFileDB");
Object.defineProperty(exports, "InMemoryFileDB", { enumerable: true, get: function () { return inMemFileDB_1.InMemoryFileDB; } });
var redisHandler_1 = require("./lib/redisHandler");
Object.defineProperty(exports, "RedisHandler", { enumerable: true, get: function () { return redisHandler_1.RedisHandler; } });
var js_controller_common_1 = require("@iobroker/js-controller-common");
Object.defineProperty(exports, "tools", { enumerable: true, get: function () { return js_controller_common_1.tools; } });
export { InMemoryFileDB } from './lib/inMemFileDB.js';
export { RedisHandler } from './lib/redisHandler.js';
export { tools } from '@iobroker/js-controller-common';
//# sourceMappingURL=index.js.map

@@ -1,4 +0,4 @@

/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
export declare const QUEUED_STR_BUF: Buffer;
export declare const OK_STR_BUF: Buffer;
//# sourceMappingURL=constants.d.ts.map

@@ -1,11 +0,5 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OK_STR_BUF = exports.QUEUED_STR_BUF = void 0;
// @ts-expect-error types missing
const respjs_1 = __importDefault(require("respjs"));
exports.QUEUED_STR_BUF = respjs_1.default.encodeString('QUEUED');
exports.OK_STR_BUF = respjs_1.default.encodeString('OK');
import Resp from 'respjs';
export const QUEUED_STR_BUF = Resp.encodeString('QUEUED');
export const OK_STR_BUF = Resp.encodeString('OK');
//# sourceMappingURL=constants.js.map

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -10,11 +9,6 @@ * States DB in memory - Server

*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryFileDB = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const js_controller_common_1 = require("@iobroker/js-controller-common");
const zlib_1 = require("zlib");
import fs from 'fs-extra';
import path from 'node:path';
import { tools } from '@iobroker/js-controller-common';
import { createGzip } from 'node:zlib';
/**

@@ -24,3 +18,3 @@ * The parent of the class structure, which provides basic JSON storage

*/
class InMemoryFileDB {
export class InMemoryFileDB {
settings;

@@ -51,14 +45,14 @@ change;

};
this.dataDir = this.settings.connection.dataDir || js_controller_common_1.tools.getDefaultDataDir();
if (!path_1.default.isAbsolute(this.dataDir)) {
this.dataDir = path_1.default.normalize(path_1.default.join(js_controller_common_1.tools.getControllerDir(), this.dataDir));
this.dataDir = this.settings.connection.dataDir || tools.getDefaultDataDir();
if (!path.isAbsolute(this.dataDir)) {
this.dataDir = path.normalize(path.join(tools.getControllerDir(), this.dataDir));
}
this.dataDir = this.dataDir.replace(/\\/g, '/');
const fileName = this.settings.jsonlDB ? this.settings.jsonlDB.fileName : this.settings.fileDB.fileName;
this.datasetName = path_1.default.join(this.dataDir, fileName);
const parts = path_1.default.dirname(this.datasetName);
fs_extra_1.default.ensureDirSync(parts);
this.datasetName = path.join(this.dataDir, fileName);
const parts = path.dirname(this.datasetName);
fs.ensureDirSync(parts);
this.stateTimer = null;
this.backupDir = this.settings.backup.path || path_1.default.join(this.dataDir, this.settings.fileDB.backupDirName);
this.log = js_controller_common_1.tools.getLogger(this.settings.logger);
this.backupDir = this.settings.backup.path || path.join(this.dataDir, this.settings.fileDB.backupDirName);
this.log = tools.getLogger(this.settings.logger);
if (!this.settings.backup.disabled) {

@@ -87,6 +81,6 @@ try {

async loadDatasetFile(datasetName) {
if (!(await fs_extra_1.default.pathExists(datasetName))) {
if (!(await fs.pathExists(datasetName))) {
throw new Error(`Database file ${datasetName} does not exists.`);
}
return fs_extra_1.default.readJSON(datasetName);
return fs.readJSON(datasetName);
}

@@ -105,3 +99,3 @@ /**

try {
await fs_extra_1.default.readJSON(`${datasetName}.bak`);
await fs.readJSON(`${datasetName}.bak`);
}

@@ -112,3 +106,3 @@ catch (e) {

const jsonString = JSON.stringify(ret);
await fs_extra_1.default.writeFile(`${datasetName}.bak`, jsonString);
await fs.writeFile(`${datasetName}.bak`, jsonString);
}

@@ -126,5 +120,5 @@ catch (e) {

try {
if (await fs_extra_1.default.pathExists(datasetName)) {
if (await fs.pathExists(datasetName)) {
try {
await fs_extra_1.default.move(datasetName, `${datasetName}.broken`, { overwrite: true });
await fs.move(datasetName, `${datasetName}.broken`, { overwrite: true });
}

@@ -135,3 +129,3 @@ catch (e) {

try {
await fs_extra_1.default.writeFile(datasetName, JSON.stringify(ret));
await fs.writeFile(datasetName, JSON.stringify(ret));
}

@@ -180,3 +174,3 @@ catch (e) {

// Create backup directory
fs_extra_1.default.ensureDirSync(this.backupDir);
fs.ensureDirSync(this.backupDir);
}

@@ -196,3 +190,3 @@ handleSubscribe(client, type, pattern, options, cb) {

}
s.push({ pattern, regex: new RegExp(js_controller_common_1.tools.pattern2RegEx(pattern)), options });
s.push({ pattern, regex: new RegExp(tools.pattern2RegEx(pattern)), options });
});

@@ -202,3 +196,3 @@ }

if (!s.find(sub => sub.pattern === pattern)) {
s.push({ pattern, regex: new RegExp(js_controller_common_1.tools.pattern2RegEx(pattern)), options });
s.push({ pattern, regex: new RegExp(tools.pattern2RegEx(pattern)), options });
}

@@ -226,3 +220,3 @@ }

}
return js_controller_common_1.tools.maybeCallback(cb);
return tools.maybeCallback(cb);
}

@@ -234,3 +228,3 @@ publishToClients(_client, _type, _id, _obj) {

// delete files only if settings.backupNumber is not 0
let files = fs_extra_1.default.readdirSync(this.backupDir);
let files = fs.readdirSync(this.backupDir);
files.sort();

@@ -248,6 +242,6 @@ const limit = Date.now() - this.settings.backup.hours * 3600000;

try {
fs_extra_1.default.unlinkSync(path_1.default.join(this.backupDir, file));
fs.unlinkSync(path.join(this.backupDir, file));
}
catch (e) {
this.log.error(`${this.namespace} Cannot delete file "${path_1.default.join(this.backupDir, file)}: ${e.message}`);
this.log.error(`${this.namespace} Cannot delete file "${path.join(this.backupDir, file)}: ${e.message}`);
}

@@ -307,3 +301,3 @@ }

try {
await fs_extra_1.default.writeFile(`${this.datasetName}.new`, jsonString);
await fs.writeFile(`${this.datasetName}.new`, jsonString);
}

@@ -316,5 +310,5 @@ catch (e) {

try {
if (await fs_extra_1.default.pathExists(this.datasetName)) {
if (await fs.pathExists(this.datasetName)) {
try {
await fs_extra_1.default.move(this.datasetName, `${this.datasetName}.bak`, { overwrite: true });
await fs.move(this.datasetName, `${this.datasetName}.bak`, { overwrite: true });
}

@@ -335,3 +329,3 @@ catch (e) {

try {
await fs_extra_1.default.move(`${this.datasetName}.new`, this.datasetName, { overwrite: true });
await fs.move(`${this.datasetName}.new`, this.datasetName, { overwrite: true });
}

@@ -341,3 +335,3 @@ catch (e) {

try {
await fs_extra_1.default.writeFile(this.datasetName, jsonString);
await fs.writeFile(this.datasetName, jsonString);
}

@@ -352,3 +346,3 @@ catch (e) {

try {
await fs_extra_1.default.writeFile(`${this.datasetName}.bak`, jsonString);
await fs.writeFile(`${this.datasetName}.bak`, jsonString);
}

@@ -372,10 +366,10 @@ catch (e) {

this.lastSave = now;
const backFileName = path_1.default.join(this.backupDir, this.getTimeStr(now) + '_' + this.settings.fileDB.fileName + '.gz');
const backFileName = path.join(this.backupDir, this.getTimeStr(now) + '_' + this.settings.fileDB.fileName + '.gz');
try {
if (!fs_extra_1.default.existsSync(backFileName)) {
const output = fs_extra_1.default.createWriteStream(backFileName);
if (!fs.existsSync(backFileName)) {
const output = fs.createWriteStream(backFileName);
output.on('error', err => {
this.log.error(`${this.namespace} Cannot save ${this.datasetName}: ${err.stack}`);
});
const compress = (0, zlib_1.createGzip)();
const compress = createGzip();
/* The following line will pipe everything written into compress to the file stream */

@@ -436,3 +430,2 @@ compress.pipe(output);

}
exports.InMemoryFileDB = InMemoryFileDB;
//# sourceMappingURL=inMemFileDB.js.map

@@ -1,6 +0,6 @@

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import type { Socket } from 'net';
import { EventEmitter } from 'events';
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import type { Socket } from 'node:net';
import { EventEmitter } from 'node:events';
import type { InternalLogger } from '@iobroker/js-controller-common/tools';

@@ -7,0 +7,0 @@ type NestedArray<T> = T[] | NestedArray<T>[];

@@ -1,11 +0,5 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisHandler = void 0;
// @ts-expect-error no types
const respjs_1 = __importDefault(require("respjs"));
const events_1 = require("events");
const constants_1 = require("./constants");
import Resp from 'respjs';
import { EventEmitter } from 'node:events';
import { QUEUED_STR_BUF, OK_STR_BUF } from './constants.js';
/**

@@ -15,3 +9,3 @@ * Class to handle a redis connection and provide events to react on for

*/
class RedisHandler extends events_1.EventEmitter {
export class RedisHandler extends EventEmitter {
socket;

@@ -56,3 +50,3 @@ logScope;

}
this.resp = new respjs_1.default(respOptions);
this.resp = new Resp(respOptions);
this.resp.on('error', (err) => {

@@ -225,3 +219,3 @@ this.log.error(`${this.socketId} (Init=${this.initialized}) Redis error:${err}`);

this.log.warn(`${this.socketId} Not able to write ${JSON.stringify(data)}`);
data = respjs_1.default.encodeError(new Error(`INVALID RESPONSE: ${JSON.stringify(data)}`));
data = Resp.encodeError(new Error(`INVALID RESPONSE: ${JSON.stringify(data)}`));
}

@@ -254,7 +248,7 @@ setImmediate(() => this._sendQueued(responseId, data));

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeNull());
this._handleMultiResponse(responseId, i, Resp.encodeNull());
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeNull());
this.sendResponse(responseId, Resp.encodeNull());
}

@@ -269,7 +263,7 @@ /**

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeNullArray());
this._handleMultiResponse(responseId, i, Resp.encodeNullArray());
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeNullArray());
this.sendResponse(responseId, Resp.encodeNullArray());
}

@@ -285,7 +279,7 @@ /**

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeString(str));
this._handleMultiResponse(responseId, i, Resp.encodeString(str));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeString(str));
this.sendResponse(responseId, Resp.encodeString(str));
}

@@ -302,7 +296,7 @@ /**

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeError(error));
this._handleMultiResponse(responseId, i, Resp.encodeError(error));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeError(error));
this.sendResponse(responseId, Resp.encodeError(error));
}

@@ -318,7 +312,7 @@ /**

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeInteger(num));
this._handleMultiResponse(responseId, i, Resp.encodeInteger(num));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeInteger(num));
this.sendResponse(responseId, Resp.encodeInteger(num));
}

@@ -334,7 +328,7 @@ /**

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeBulk(str));
this._handleMultiResponse(responseId, i, Resp.encodeBulk(str));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeBulk(str));
this.sendResponse(responseId, Resp.encodeBulk(str));
}

@@ -350,7 +344,7 @@ /**

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeBufBulk(buf));
this._handleMultiResponse(responseId, i, Resp.encodeBufBulk(buf));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeBufBulk(buf));
this.sendResponse(responseId, Resp.encodeBufBulk(buf));
}

@@ -370,12 +364,12 @@ /**

else if (Buffer.isBuffer(value)) {
returnArr[i] = respjs_1.default.encodeBufBulk(value);
returnArr[i] = Resp.encodeBufBulk(value);
}
else if (value === null) {
returnArr[i] = respjs_1.default.encodeNull();
returnArr[i] = Resp.encodeNull();
}
else if (typeof value === 'number') {
returnArr[i] = respjs_1.default.encodeInteger(value);
returnArr[i] = Resp.encodeInteger(value);
}
else {
returnArr[i] = respjs_1.default.encodeBulk(value);
returnArr[i] = Resp.encodeBulk(value);
}

@@ -394,7 +388,7 @@ });

if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, respjs_1.default.encodeArray(this.encodeRespArray(arr)));
this._handleMultiResponse(responseId, i, Resp.encodeArray(this.encodeRespArray(arr)));
return;
}
}
this.sendResponse(responseId, respjs_1.default.encodeArray(this.encodeRespArray(arr)));
this.sendResponse(responseId, Resp.encodeArray(this.encodeRespArray(arr)));
}

@@ -438,4 +432,4 @@ /**

// collect all 'QUEUED' answers
const queuedStrArr = new Array(multiObj.responseCount).fill(constants_1.QUEUED_STR_BUF);
this._sendQueued(multiObj.execId, Buffer.concat([constants_1.OK_STR_BUF, ...queuedStrArr, respjs_1.default.encodeArray(Array.from(multiObj.responseMap.values()))]));
const queuedStrArr = new Array(multiObj.responseCount).fill(QUEUED_STR_BUF);
this._sendQueued(multiObj.execId, Buffer.concat([OK_STR_BUF, ...queuedStrArr, Resp.encodeArray(Array.from(multiObj.responseMap.values()))]));
}

@@ -459,3 +453,2 @@ /**

}
exports.RedisHandler = RedisHandler;
//# sourceMappingURL=redisHandler.js.map
{
"name": "@iobroker/db-base",
"version": "5.0.20-alpha.0-20240409-d68ed299",
"type": "module",
"version": "5.0.20-alpha.0-20240418-165fc4c8",
"engines": {

@@ -8,3 +9,3 @@ "node": ">=18.0.0"

"dependencies": {
"@iobroker/js-controller-common": "5.0.20-alpha.0-20240409-d68ed299",
"@iobroker/js-controller-common": "5.0.20-alpha.0-20240418-165fc4c8",
"deep-clone": "^3.0.3",

@@ -31,3 +32,3 @@ "fs-extra": "^11.1.0",

"build": "tsc -b tsconfig.build.json",
"postbuild": "esm2cjs --in build/esm --out build/cjs -l error && cpy ./**/*.d.ts ./build/cjs/ --cwd=build/esm/"
"postbuild": "esm2cjs --in build/esm --out build/cjs -l error -t node18 && cpy ./**/*.d.ts ./build/cjs/ --cwd=build/esm/"
},

@@ -57,3 +58,3 @@ "main": "build/cjs/index.js",

],
"gitHead": "177223a8779da419012abbbff883d3cc649045d0"
"gitHead": "ba7b732f23ddf0da772e23ed6175185ec204ee6b"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc