UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

102 lines 3.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerMetaContext = exports.MetaPriority = void 0; const assert_1 = require("../../util/assert"); /** * How much a {@link ProjectMetaFields | contribution} is trusted, in case several sources disagree. * A higher value wins; among equal values the first contribution stays. */ var MetaPriority; (function (MetaPriority) { /** derived from a lockfile, e.g. the `r_version` of an `rv.lock` */ MetaPriority[MetaPriority["Lockfile"] = 0] = "Lockfile"; /** declared in a project manifest, e.g. an `rproject.toml` */ MetaPriority[MetaPriority["Manifest"] = 1] = "Manifest"; /** declared in a `DESCRIPTION` file, which identifies an actual R package */ MetaPriority[MetaPriority["Description"] = 2] = "Description"; })(MetaPriority || (exports.MetaPriority = MetaPriority = {})); /** * This is the context responsible for managing the project metadata such as name, version, title, and namespace. * * The metadata is source-agnostic: plugins {@link FlowrAnalyzerMetaContext#contribute | contribute} whatever their * file declares (`DESCRIPTION`, `rproject.toml`, a lockfile, ...) and consumers read it from here rather than from * any particular file. Conflicts are settled by {@link MetaPriority}, so contributions are order-independent. * * If you are interested in inspecting this metadata, refer to {@link ReadOnlyFlowrAnalyzerMetaContext}. */ class FlowrAnalyzerMetaContext { name = 'flowr-analyzer-meta-context'; fields = new Map(); /** runs the plugins that contribute the metadata, as they only do so on demand */ ensureContributed; constructor(ensureContributed = () => { }) { this.ensureContributed = ensureContributed; } reset() { this.fields.clear(); } receive(event) { const type = event.type; switch (type) { case "full" /* InvalidationEventType.Full */: this.reset(); break; case "single-file-invalidate" /* InvalidationEventType.SingleFileInvalidate */: // nothing to do break; default: (0, assert_1.assertUnreachable)(type); } } /** * Contribute what a source declares about the project; `undefined` fields are ignored, so a plugin can pass * whatever it happens to know. * @param fields - the metadata to contribute * @param priority - how much to trust these fields against other sources */ contribute(fields, priority) { for (const [key, value] of Object.entries(fields)) { if (value === undefined) { continue; } const have = this.fields.get(key); if (have === undefined || priority > have.priority) { this.fields.set(key, { value, priority }); } } return this; } get(key) { this.ensureContributed(); return this.fields.get(key)?.value; } getProjectName() { return this.get('name'); } getProjectTitle() { return this.get('title'); } getProjectVersion() { return this.get('version'); } getRVersion() { return this.get('rVersion'); } getNamespace() { return this.get('namespace'); } getAuthors() { return this.get('authors'); } getEncoding() { return this.get('encoding'); } getLicenses() { return this.get('licenses'); } getDeclaredPackages() { return this.get('declares') ?? {}; } } exports.FlowrAnalyzerMetaContext = FlowrAnalyzerMetaContext; //# sourceMappingURL=flowr-analyzer-meta-context.js.map