UNPKG

@tvkitchen/countertop

Version:

The entry point for developers who want to set up a TV Kitchen.

95 lines (76 loc) 4.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _CountertopStream = _interopRequireDefault(require("./CountertopStream")); var _countertop = require("../tools/utils/countertop"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /** * CountertopToplogies are a complete set of valid *paths* that data might take across a given * array of CountertopStations. * * The distinction of paths (as opposed to edges / direct steps) is important, as a given payload * will have a source, and only payloads with a common source should be considered together in * the case of dual-input appliances. * * In many data processing pipelines, topologies need to be manually specified by the developer * configuring the system. In this case, the topologies are automatically generated based on which * appliances produce outputs that are valid inputs to others. * * The logic for generating a CountertopTopology starts in the static `generateStreams` method. */ class CountertopTopology { /** * Create a CountertopTopology. * * @param {CountertopStation[]} stations The stations used to define the topology. */ constructor(stations = []) { _defineProperty(this, "stations", []); _defineProperty(this, "streams", []); this.stations = stations; this.streams = CountertopTopology.generateStreams(this.stations); } /** * Extend a set of streams by a single station. * * This will only create streams that pull from the same source. * This will generate and return any valid streams that extend a given stream set. * This will ONLY return new streams, which means if no valid streams extensions exist, it will * return an empty array. * This will not create streams that re-visit a given station (no loops). * * @param {CountertopStream[]} streams The set of streams to be extended. * @param {CountertopStation[]} station The station being used to extend. * @return {CountertopStream[]} The extended streams. */ } _defineProperty(CountertopTopology, "extendStreamsByStation", (streams, station) => { const streamOutputMap = (0, _countertop.getStreamOutputMap)((0, _countertop.filterStreamsContainingStation)(streams)); const tributaryMaps = (0, _countertop.generateTributaryMaps)(station, streamOutputMap); return tributaryMaps.map(tributaryMap => new _CountertopStream.default(station, tributaryMap)); }); _defineProperty(CountertopTopology, "generateStreams", (stations, streams = []) => { let nextStreams = []; if (streams.length === 0) { nextStreams = CountertopTopology.generateSourceStreams(stations); } else { const extentionLength = 1 + (0, _countertop.getLongestStreamLength)(streams); const outputTypes = (0, _countertop.getCollectiveOutputTypes)(streams); const nextStations = (0, _countertop.getStationsThatConsumeTypes)(stations, outputTypes); nextStreams = nextStations.flatMap(station => CountertopTopology.extendStreamsByStation(streams, station)) // Remove any new streams that aren't long enough .filter(stream => stream.getLength() === extentionLength); } // Prune any past streams whose tributaries are explicit subsets of new streams const obsoleteStreams = (0, _countertop.identifyObsoleteStreams)(streams, nextStreams); const prunedStreams = (0, _countertop.pruneStreams)(streams, obsoleteStreams); const prunedNextStreams = (0, _countertop.pruneStreams)(nextStreams, obsoleteStreams); // If there were any new streams, iterate again if (prunedNextStreams.length !== 0) { return CountertopTopology.generateStreams(stations, prunedStreams.concat(prunedNextStreams)); } return prunedStreams; }); _defineProperty(CountertopTopology, "generateSourceStreams", stations => (0, _countertop.getSourceStations)(stations).map(station => new _CountertopStream.default(station))); var _default = CountertopTopology; exports.default = _default;