@duongtrungnguyen/nestro
Version:
Service registry for Nest JS
116 lines • 3.87 kB
JavaScript
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 utils_exports = {};
__export(utils_exports, {
buildHttpUrl: () => buildHttpUrl,
buildInstanceHttpUrl: () => buildInstanceHttpUrl,
buildInstanceWsUrl: () => buildInstanceWsUrl,
buildWsUrl: () => buildWsUrl,
debugError: () => debugError,
debugLog: () => debugLog,
debugWarn: () => debugWarn,
getHttpSecureProtocol: () => getHttpSecureProtocol,
getServerURL: () => getServerURL,
isClass: () => isClass,
normalizeJson: () => normalizeJson
});
module.exports = __toCommonJS(utils_exports);
var import_common = require("@nestjs/common");
var import_constants = require("./constants");
function canLog() {
const isDevelopment = process.env.NODE_ENV != "production";
const disableLog = process.env.NESTRO_LOG == "off";
return isDevelopment && !disableLog;
}
function debugLog(context, message, data) {
if (canLog()) {
if (data) {
import_common.Logger.debug(`${message} - ${JSON.stringify(data)}`, context);
} else {
import_common.Logger.debug(message, context);
}
}
}
function debugWarn(context, message, data) {
if (canLog()) {
if (data) {
import_common.Logger.warn(`${message} - ${JSON.stringify(data)}`, context);
} else {
import_common.Logger.warn(message, context);
}
}
}
function debugError(context, message, data) {
if (canLog()) {
if (data) {
import_common.Logger.error(`${message} - ${JSON.stringify(data)}`, context);
} else {
import_common.Logger.error(message, context);
}
}
}
function normalizeJson(data) {
function sortKeys(obj) {
if (Array.isArray(obj)) {
return obj.map(sortKeys);
} else if (obj !== null && typeof obj === "object") {
return Object.keys(obj).sort().reduce((acc, key) => {
acc[key] = sortKeys(obj[key]);
return acc;
}, {});
}
return obj;
}
return JSON.stringify(sortKeys(data));
}
function buildInstanceHttpUrl(instance) {
return `${instance.protocol}://${instance.host}${instance.port ? `:${instance.port}` : ""}`;
}
function buildInstanceWsUrl(instance) {
return `${instance.protocol === "https" ? "wss" : "ws"}://${instance.host}${instance.port ? `:${instance.port}` : ""}`;
}
function buildHttpUrl(host, protocol = "http", port) {
return `${protocol}://${host}${port ? `:${port}` : ""}`;
}
function buildWsUrl(host, protocol = "ws", port) {
return `${protocol}://${host}${port ? `:${port}` : ""}`;
}
function getHttpSecureProtocol(secure) {
return secure ? "https" : "http";
}
function isClass(target) {
return typeof target === "function" && import_constants.CLASS_REGEX.test(Function.prototype.toString.call(target));
}
function getServerURL(server) {
return server instanceof URL ? server.toString() : buildHttpUrl(server.host, server.protocol, server.port);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
buildHttpUrl,
buildInstanceHttpUrl,
buildInstanceWsUrl,
buildWsUrl,
debugError,
debugLog,
debugWarn,
getHttpSecureProtocol,
getServerURL,
isClass,
normalizeJson
});
//# sourceMappingURL=utils.js.map