UNPKG

arvo-core

Version:

This core package contains all the core classes and components of the Arvo Event Driven System

149 lines (148 loc) 5.39 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VersionedArvoContract = void 0; var zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema")); var OpenTelemetry_1 = require("../../OpenTelemetry"); var utils_1 = require("../../utils"); var WildCardArvoSemanticVersion_1 = require("../WildCardArvoSemanticVersion"); var utils_2 = require("./utils"); /** * Implements a version-specific view of an ArvoContract with type-safe schema validation * and JSON Schema generation capabilities. */ var VersionedArvoContract = /** @class */ (function () { function VersionedArvoContract(param) { this._version = param.version; this._contract = param.contract; this._accepts = { type: param.contract.type, schema: param.contract.versions[param.version].accepts, }; this._emits = param.contract.versions[param.version].emits; this._emitList = (0, utils_2.transformEmitsToArray)(this.emits); } Object.defineProperty(VersionedArvoContract.prototype, "uri", { get: function () { return this._contract.uri; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "version", { get: function () { return this._version; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "description", { get: function () { return this._contract.description; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "metadata", { get: function () { return this._contract.metadata; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "systemError", { get: function () { return __assign(__assign({}, this._contract.systemError), { dataschema: utils_1.EventDataschemaUtil.build(this.uri, WildCardArvoSemanticVersion_1.WildCardArvoSemanticVersion) }); }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "accepts", { get: function () { return this._accepts; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "emits", { get: function () { return this._emits; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "emitList", { get: function () { return this._emitList; }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "dataschema", { get: function () { return utils_1.EventDataschemaUtil.build(this.uri, this.version); }, enumerable: false, configurable: true }); Object.defineProperty(VersionedArvoContract.prototype, "domain", { get: function () { return this._contract.domain; }, enumerable: false, configurable: true }); /** * Converts the contract to JSON Schema format * @returns Contract specification in JSON Schema format for documentation/serialization */ VersionedArvoContract.prototype.toJsonSchema = function () { try { return { uri: this.uri, description: this.description, domain: this.domain, version: this.version, metadata: this.metadata, accepts: { type: this._accepts.type, schema: (0, zod_to_json_schema_1.default)(this._accepts.schema), }, systemError: { type: this.systemError.type, schema: (0, zod_to_json_schema_1.default)(this.systemError.schema), }, emits: Object.entries(this._emits).map(function (_a) { var key = _a[0], value = _a[1]; return ({ type: key, schema: (0, zod_to_json_schema_1.default)(value), }); }), }; } catch (e) { var errorMessage = "VersionedArvoContract.toJsonSchema failed: ".concat(e.message); (0, OpenTelemetry_1.logToSpan)({ level: 'ERROR', message: errorMessage, }); throw new Error(errorMessage); } }; return VersionedArvoContract; }()); exports.VersionedArvoContract = VersionedArvoContract;