UNPKG

@altostra/core

Version:

Core library for shared types and logic

1 lines 1.47 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConnectionsFactory=exports.mkCompositeKey=void 0;const Object_1=require("../../../common/Utils/Object"),from_1=require("@reactivex/ix-es2015-cjs/iterable/from"),groupby_1=require("@reactivex/ix-es2015-cjs/iterable/operators/groupby"),map_1=require("@reactivex/ix-es2015-cjs/iterable/operators/map"),COMPOSITE_KEY_SEPARATOR=":";function mkCompositeKey(e,o,t){return[e,o,t].join(":")}exports.mkCompositeKey=mkCompositeKey;class ConnectionsFactory{constructor(e){this.registry={},e&&e(this)}buildConnection(e,o,t){const r=this.registry[mkCompositeKey(e.type,o.type,t.type)];if(r)return r(e.id,o.id,t)}isConnectionValid(e,o,t){return!!this.registry[mkCompositeKey(e,o,t)]}registerConnectionProducer(e,o,t,r){const s=mkCompositeKey(e,o,t);this.registry[s]=r}registerConnection(e,o){o=Array.isArray(o)?o:[o];for(const{sources:t,targets:r}of o)for(const o of t)for(const t of r)this.registerConnectionProducer(o,t,e,(e,o,t)=>Object.assign(Object.assign({},t),{from:e,to:o}))}allowedConnectionsMapping(e){const o="source"===e?"target":"source",t=(0,from_1.from)(Object.keys(this.registry)).pipe((0,map_1.map)(e=>e.split(":")),(0,map_1.map)(([e,o,t])=>({source:e,target:o,connection:t})),(0,groupby_1.groupBy)(o=>o[e]));return(0,Object_1.fromEntries)(t.pipe((0,map_1.map)(e=>[e.key,(0,Object_1.fromEntries)(e.pipe((0,map_1.map)(e=>[e[o],e.connection])))])))}}exports.ConnectionsFactory=ConnectionsFactory;