UNPKG

@clickup/ent-framework

Version:

A PostgreSQL graph-database-alike library with microsharding and row-level security

53 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntAccessError = void 0; const misc_1 = require("../../internal/misc"); /** * A base class for errors that trigger the validation framework to process them * as a DENY/SKIP. Invariants in derived classes: the error message should be * safe to pass to the client (it must not have any private information; a good * example is EntValidationError), plus the message alone should be descriptive * enough to extract information from it. If `cause` is passed, it becomes a * part of the message, with the above assumptions. */ class EntAccessError extends Error { constructor(entName, message, cause = null) { super(cause ? message.replace(/[,.?!:;]+$/s, "") + ", because:\n" + (0, misc_1.indent)(causeToString(cause)) : message); this.entName = entName; Object.defineProperty(this, "name", { value: this.constructor.name, writable: true, enumerable: false, }); if (cause instanceof Error) { this.cause = cause; (0, misc_1.copyStack)(this, cause); } else { this.cause = cause ? causeToString(cause) : null; } } toStandardSchemaV1() { return { issues: [ this.entName ? { message: this.message, path: [this.entName] } : { message: this.message }, ], }; } } exports.EntAccessError = EntAccessError; function causeToString(cause) { // - Error is turned into its class name and the message (no stacktrace). // - String is left as it is. // - Any other object will be inspected in compact mode. return cause instanceof Error || typeof cause === "string" ? String(cause).trimEnd() : (0, misc_1.inspectCompact)(cause); } //# sourceMappingURL=EntAccessError.js.map