UNPKG

@chix/flow

Version:
113 lines 4.39 kB
"use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("../common"); var util_1 = require("../util"); var validate_1 = require("../validate"); var link_1 = require("./link"); var node_1 = require("./node"); var ports_1 = require("./ports"); var process_1 = require("./process"); var providers_1 = require("./providers"); function $ToJSON(Base) { return (function (_super) { __extends(ToJSON$, _super); function ToJSON$() { return _super !== null && _super.apply(this, arguments) || this; } ToJSON$.prototype.toJSON = function (asProcess) { var e_1, _a, e_2, _b; if (asProcess === void 0) { asProcess = false; } var nodeDefinition = { description: this.description, id: this.id, links: [], name: this.name, nodes: [], ns: this.ns, ports: this.ports, providers: this.providers, title: this.title, type: this.type, }; try { for (var _c = __values(this.nodes.values()), _d = _c.next(); !_d.done; _d = _c.next()) { var node = _d.value; var _node = { id: node.id, ns: node.ns, name: node.name, description: node.description, context: node.context, metadata: node.metadata, provider: node.provider, }; if (asProcess) { ; _node.pid = node.pid; } nodeDefinition.nodes.push(_node); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_d && !_d.done && (_a = _c.return)) _a.call(_c); } finally { if (e_1) throw e_1.error; } } try { for (var _e = __values(this.links.values()), _f = _e.next(); !_f.done; _f = _e.next()) { var link = _f.value; nodeDefinition.links.push(link); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_f && !_f.done && (_b = _e.return)) _b.call(_e); } finally { if (e_2) throw e_2.error; } } if (asProcess) { nodeDefinition.pid = this.pid; } else { validate_1.validate.flow(nodeDefinition); } return JSON.parse(JSON.stringify(nodeDefinition)); }; return ToJSON$; }(Base)); } exports.$ToJSON = $ToJSON; (function ($ToJSON) { function create(Base) { return util_1.mixin($ToJSON, common_1.$Identity.create, link_1.$Link.create, common_1.$Meta.create, node_1.$Node.create, ports_1.$Ports.create, process_1.$Process.create, providers_1.$Providers.create)(Base); } $ToJSON.create = create; })($ToJSON = exports.$ToJSON || (exports.$ToJSON = {})); //# sourceMappingURL=toJSON.js.map