UNPKG

api-core

Version:

Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels

60 lines 2.39 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiEdgeRelation = exports.ApiEdgeRelationTypes = void 0; exports.ApiEdgeRelationTypes = {}; class ApiEdgeRelation { constructor(from, to) { this.resolved = false; this.onResolve = () => { }; this.from = from; this.to = to; this.external = from.external || to.external; } toJSON() { return { type: this.getType(), name: this.name, relationId: this.relationId, relatedId: this.relatedId, from: this.from.name, to: this.to.name, hasPair: this.hasPair }; } static fromJSON(obj, api) { return __awaiter(this, void 0, void 0, function* () { const Relation = exports.ApiEdgeRelationTypes[obj.type]; const relation = new Relation(yield api.findEdge(obj.from, false), yield api.findEdge(obj.to, false)); relation.relationId = obj.relationId; relation.relatedId = obj.relatedId; relation.name = obj.name; relation.hasPair = obj.hasPair; return relation; }); } resolve() { return __awaiter(this, void 0, void 0, function* () { if (this.resolved) return true; if (yield this.from.resolve()) { if (yield this.to.resolve()) { this.onResolve(); this.resolved = true; return true; } } return false; }); } } exports.ApiEdgeRelation = ApiEdgeRelation; //# sourceMappingURL=ApiEdgeRelation.js.map