UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

59 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrSearchElements = void 0; const search_enrichers_1 = require("./search-executor/search-enrichers"); /** Intentionally, we abstract away from an array to avoid the use of conventional typescript operations */ class FlowrSearchElements { elements = []; enrichments = {}; constructor(elements) { if (elements) { this.elements = elements; } } add(element) { this.elements.push(element); return this; } addAll(elements) { this.elements.push(...elements); return this; } getElements() { return this.elements; } mutate(mutator) { const result = mutator(this.elements); if (result instanceof Promise) { return result.then(resolvedElements => { this.elements = resolvedElements; return this; }); } else { this.elements = result; return this; } } /** * Enriches this flowr search element collection with the given enrichment. * To retrieve enrichment content for a given enrichment type, use {@link enrichmentContent}. * * Please note that this function does not also enrich individual elements, which is done through {@link enrichElement}. Both functions are called in a concise manner in {@link FlowrSearchBuilder.with}, which is the preferred way to add enrichments to a search. */ async enrich(data, enrichment, args) { const enrichmentData = search_enrichers_1.Enrichments[enrichment]; if (enrichmentData.enrichSearch !== undefined) { this.enrichments = { ...this.enrichments ?? {}, [enrichment]: await enrichmentData.enrichSearch(this, data, args, this.enrichments?.[enrichment]) }; } return this; } enrichmentContent(enrichment) { return this.enrichments?.[enrichment]; } } exports.FlowrSearchElements = FlowrSearchElements; //# sourceMappingURL=flowr-search.js.map