UNPKG

@altostra/core

Version:

Core library for shared types and logic

1 lines 1.45 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.assertConnectionType=exports.ofConnectionType=exports.ConnectionCollectionBase=void 0;const AltoError_1=require("../../../common/Errors/AltoError"),from_1=require("@reactivex/ix-es2015-cjs/iterable/from"),Collection_1=require("../Collection"),ConnectionHelper_1=require("../ConnectionHelper");class ConnectionCollectionBase extends Collection_1.Collection{constructor(e,o,n){super(e,n=>new ConnectionHelper_1.ConnectionHelper(o,e,n)),this._blueprint=o,this._connections=n}*[Symbol.iterator](){for(const e of this._connections())yield this._getWrapper(e)}get({from:e,to:o}){var n;const t=null===(n=this._blueprint.blueprint.connections[e])||void 0===n?void 0:n[o];return t&&this._getWrapper(t)}ofType(...e){return this.pipe(ofConnectionType(...e))}assertType(...e){return this.pipe(assertConnectionType(...e))}}function ofConnectionType(...e){return function(o){return(0,from_1.from)({*[Symbol.iterator](){for(const n of o)n.is(...e)&&(yield n)}})}}function assertConnectionType(...e){const o=new Set(e);return function(n){return(0,from_1.from)({*[Symbol.iterator](){for(const t of n){if(!o.has(t.type))throw AltoError_1.AltoError.create({message:"Connection is of invalid type",data:{connection:t,validTypes:e}});yield t}}})}}exports.ConnectionCollectionBase=ConnectionCollectionBase,exports.ofConnectionType=ofConnectionType,exports.assertConnectionType=assertConnectionType;