convex
Version:
Client for the Convex Cloud
79 lines (78 loc) • 2.54 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 logging_exports = {};
__export(logging_exports, {
createHybridErrorStacktrace: () => createHybridErrorStacktrace,
forwardData: () => forwardData,
logFatalError: () => logFatalError,
logToConsole: () => logToConsole
});
module.exports = __toCommonJS(logging_exports);
const INFO_COLOR = "color:rgb(0, 145, 255)";
function prefix_for_source(source) {
switch (source) {
case "query":
return "Q";
case "mutation":
return "M";
case "action":
return "A";
case "any":
return "?";
}
}
function logToConsole(type, source, udfPath, message) {
const prefix = prefix_for_source(source);
if (typeof message === "object") {
message = `ConvexError ${JSON.stringify(message.errorData, null, 2)}`;
}
if (type === "info") {
const match = message.match(/^\[.*?\] /);
if (match === null) {
console.error(
`[CONVEX ${prefix}(${udfPath})] Could not parse console.log`
);
return;
}
const level = message.slice(1, match[0].length - 2);
const args = message.slice(match[0].length);
console.log(
`%c[CONVEX ${prefix}(${udfPath})] [${level}]`,
INFO_COLOR,
args
);
} else {
console.error(`[CONVEX ${prefix}(${udfPath})] ${message}`);
}
}
function logFatalError(message) {
const errorMessage = `[CONVEX FATAL ERROR] ${message}`;
console.error(errorMessage);
return new Error(errorMessage);
}
function createHybridErrorStacktrace(source, udfPath, result) {
const prefix = prefix_for_source(source);
return `[CONVEX ${prefix}(${udfPath})] ${result.errorMessage}
Called by client`;
}
function forwardData(result, error) {
error.data = result.errorData;
return error;
}
//# sourceMappingURL=logging.js.map