arvo-core
Version:
The core Arvo package which provides application tier core primitives and contract system for building production-grade event-driven application. Provides ArvoEvent (CloudEvents-compliant), ArvoContract for type-safe service interfaces, event factories, O
78 lines (77 loc) • 3.38 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isViolationError = exports.ViolationError = void 0;
var zod_1 = __importDefault(require("zod"));
/**
* ViolationError represents errors that require explicit handling in the system.
* These are distinct from recoverable errors that can be automatically handled
* by workflow logic. The explicit handling may be required for severe
* violation of service contracts or explict retry handling
*
* Common violation scenarios include:
* - Execution error like rate limit exceeded on external API calls
* - Contract violations (invalid input/output)
* - Configuration errors
* - Permission/authorization failures
*/
var ViolationError = /** @class */ (function (_super) {
__extends(ViolationError, _super);
function ViolationError(_a) {
var type = _a.type, message = _a.message, metadata = _a.metadata;
var _this = _super.call(this, "ViolationError<".concat(type, "> ").concat(message)) || this;
/** An additional flag to determine if it is an Arvo specific violation error */
_this.isArvoViolationError = true;
_this.type = type;
_this.name = "ViolationError<".concat(_this.type, ">");
_this.metadata = metadata !== null && metadata !== void 0 ? metadata : null;
return _this;
}
return ViolationError;
}(Error));
exports.ViolationError = ViolationError;
/**
* Type guard to determine if an unknown value is a ViolationError, an instance
* of a class that inherits from ViolationError.
*
* @param e - The value to check, typically an unknown error or exception
* @returns `true` if the value is a ViolationError, inherits from it, or has the isArvoViolationError flag, `false` otherwise
*
* ```typescript
* const error = new ViolationError({
* type: 'RATE_LIMIT',
* message: 'API rate limit exceeded'
* });
*
* console.log(isViolationError(error)); // true
* console.log(isViolationError(new Error())); // false
* console.log(isViolationError(null)); // false
* ```
*/
var isViolationError = function (e) {
var ViolationErrorSchema = zod_1.default.object({
isArvoViolationError: zod_1.default.literal(true),
type: zod_1.default.string().min(1),
name: zod_1.default.string().min(1),
message: zod_1.default.string().min(1),
});
return e instanceof Error && ViolationErrorSchema.safeParse(e).success;
};
exports.isViolationError = isViolationError;