UNPKG

@iobroker/js-controller-common-db

Version:

The Library contains the common utils for the ioBroker controller which can be used by db classes too, as they do not rely on the db (circular dependencies).

60 lines (59 loc) 2.31 kB
"use strict"; 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 maybeCallback_exports = {}; __export(maybeCallback_exports, { maybeCallback: () => maybeCallback, maybeCallbackWithError: () => maybeCallbackWithError, maybeCallbackWithRedisError: () => maybeCallbackWithRedisError }); module.exports = __toCommonJS(maybeCallback_exports); var import_tools = require("../../lib/common/tools.js"); function maybeCallback(callback, ...args) { if (typeof callback === "function") { setImmediate(callback, ...args); } else { return Promise.resolve(args.length > 1 ? args : args[0]); } } function maybeCallbackWithError(callback, error, ...args) { if (error !== void 0 && error !== null && !(error instanceof Error)) { error = new Error(error); } const isDbError = error ? error.message === import_tools.ERRORS.ERROR_DB_CLOSED : false; if (typeof callback === "function") { setImmediate(callback, error, ...args); } else if (error && !isDbError) { return Promise.reject(error); } else { return Promise.resolve(args.length > 1 ? args : args[0]); } } function maybeCallbackWithRedisError(callback, error, ...args) { if (error instanceof Error && error.message.includes("Connection is closed")) { error.message = import_tools.ERRORS.ERROR_DB_CLOSED; } return maybeCallbackWithError(callback, error, ...args); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { maybeCallback, maybeCallbackWithError, maybeCallbackWithRedisError }); //# sourceMappingURL=maybeCallback.js.map