@eagleoutice/flowr 2.11.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -260
- package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
- package/abstract-interpretation/domains/set-range-domain.js +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
- package/benchmark/slicer.d.ts +1 -1
- package/benchmark/slicer.js +3 -1
- package/benchmark/summarizer/second-phase/graph.js +5 -0
- package/cli/common/options.d.ts +8 -0
- package/cli/common/options.js +2 -0
- package/cli/common/scripts-info.d.ts +8 -0
- package/cli/flowr.js +1 -1
- package/cli/repl/commands/repl-commands.d.ts +1 -0
- package/cli/repl/commands/repl-commands.js +69 -17
- package/cli/repl/commands/repl-dataflow.js +48 -4
- package/cli/repl/commands/repl-main.d.ts +2 -0
- package/cli/repl/commands/repl-main.js +5 -0
- package/cli/repl/commands/repl-query.d.ts +4 -1
- package/cli/repl/commands/repl-query.js +72 -22
- package/cli/repl/commands/repl-signature.d.ts +7 -0
- package/cli/repl/commands/repl-signature.js +119 -0
- package/cli/repl/core.d.ts +8 -1
- package/cli/repl/core.js +46 -6
- package/cli/repl/ghost-hint.d.ts +37 -0
- package/cli/repl/ghost-hint.js +72 -0
- package/cli/repl/parser/slice-query-parser.d.ts +11 -1
- package/cli/repl/parser/slice-query-parser.js +45 -16
- package/cli/repl/print-version.d.ts +2 -4
- package/cli/repl/print-version.js +41 -23
- package/cli/repl/server/connection.js +19 -17
- package/cli/slicer-app.d.ts +2 -0
- package/cli/slicer-app.js +3 -3
- package/cli/wiki.d.ts +2 -2
- package/cli/wiki.js +2 -2
- package/config.d.ts +70 -13
- package/config.js +65 -7
- package/control-flow/cfg-dead-code.js +0 -1
- package/control-flow/control-flow-graph.js +6 -6
- package/control-flow/diff-cfg.js +2 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/core/print/slice-diff-ansi.js +8 -8
- package/core/steps/all/core/20-dataflow.d.ts +2 -2
- package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
- package/core/steps/all/static-slicing/00-slice.js +1 -1
- package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
- package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
- package/core/steps/pipeline/default-pipelines.d.ts +20 -16
- package/data/r-base-packages.generated.d.ts +44 -0
- package/data/r-base-packages.generated.js +32 -0
- package/data/r-base-primitives.generated.d.ts +1 -0
- package/data/r-base-primitives.generated.js +15 -0
- package/data/sigdb/sigdb.remote.json +112 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in.d.ts +14 -4
- package/dataflow/environments/built-in.js +13 -2
- package/dataflow/environments/data-masking-functions.d.ts +12 -0
- package/dataflow/environments/data-masking-functions.js +46 -0
- package/dataflow/environments/default-builtin-config.d.ts +72 -19
- package/dataflow/environments/default-builtin-config.js +48 -14
- package/dataflow/environments/diff.js +1 -1
- package/dataflow/environments/environment.js +1 -2
- package/dataflow/environments/identifier.d.ts +11 -4
- package/dataflow/environments/identifier.js +28 -10
- package/dataflow/environments/resolve-by-name.js +16 -2
- package/dataflow/extractor.js +6 -3
- package/dataflow/graph/call-graph.d.ts +2 -2
- package/dataflow/graph/df-helper.d.ts +4 -4
- package/dataflow/graph/diff-dataflow-graph.js +2 -2
- package/dataflow/graph/edge.d.ts +3 -3
- package/dataflow/graph/edge.js +3 -3
- package/dataflow/graph/graph-helper.d.ts +2 -2
- package/dataflow/internal/linker.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
- package/dataflow/internal/process/functions/call/common.js +8 -1
- package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
- package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
- package/dataflow/internal/process/functions/process-argument.js +12 -1
- package/dataflow/internal/process/process-named-call.d.ts +18 -1
- package/dataflow/internal/process/process-named-call.js +94 -0
- package/dataflow/processor.d.ts +18 -0
- package/documentation/data/faq/faqs.js +5 -1
- package/documentation/doc-capabilities.js +1 -1
- package/documentation/doc-util/doc-cli-option.d.ts +10 -0
- package/documentation/doc-util/doc-cli-option.js +23 -0
- package/documentation/doc-util/doc-dfg.js +2 -1
- package/documentation/doc-util/doc-query.d.ts +9 -3
- package/documentation/doc-util/doc-query.js +9 -4
- package/documentation/wiki-dataflow-graph.js +8 -5
- package/documentation/wiki-interface.js +3 -2
- package/documentation/wiki-linter.js +1 -1
- package/documentation/wiki-linting-and-testing.js +4 -1
- package/documentation/wiki-mk/doc-context.d.ts +14 -0
- package/documentation/wiki-mk/doc-context.js +3 -0
- package/documentation/wiki-mk/doc-maker.js +3 -1
- package/documentation/wiki-query.js +19 -1
- package/documentation/wiki-setup.js +10 -7
- package/documentation/wiki-signature-database.d.ts +16 -0
- package/documentation/wiki-signature-database.js +293 -0
- package/linter/linter-format.d.ts +7 -0
- package/linter/linter-rules.d.ts +10 -9
- package/linter/rules/naming-convention.d.ts +1 -0
- package/linter/rules/naming-convention.js +2 -0
- package/linter/rules/no-leaked-credentials.js +1 -2
- package/linter/rules/roxygen-arguments.js +18 -5
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/undefined-symbol-util.d.ts +36 -0
- package/linter/rules/undefined-symbol-util.js +149 -0
- package/linter/rules/undefined-symbol.d.ts +58 -17
- package/linter/rules/undefined-symbol.js +143 -33
- package/linter/rules/unused-definition.d.ts +8 -1
- package/linter/rules/unused-definition.js +126 -1
- package/package.json +23 -10
- package/project/context/abstract-flowr-analyzer-context.js +7 -1
- package/project/context/flowr-analyzer-context.d.ts +8 -0
- package/project/context/flowr-analyzer-context.js +10 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
- package/project/context/flowr-analyzer-dependencies-context.js +53 -1
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-analyzer-files-context.js +2 -1
- package/project/context/flowr-analyzer-functions-context.js +1 -1
- package/project/context/flowr-file.d.ts +5 -0
- package/project/context/flowr-file.js +5 -0
- package/project/flowr-analyzer-builder.js +12 -2
- package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
- package/project/plugins/package-version-plugins/package.d.ts +5 -3
- package/project/plugins/package-version-plugins/package.js +27 -25
- package/project/plugins/plugin-registry.d.ts +3 -2
- package/project/plugins/plugin-registry.js +4 -2
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
- package/project/sigdb/build.d.ts +131 -0
- package/project/sigdb/build.js +628 -0
- package/project/sigdb/codec.d.ts +51 -0
- package/project/sigdb/codec.js +122 -0
- package/project/sigdb/decode.d.ts +58 -0
- package/project/sigdb/decode.js +129 -0
- package/project/sigdb/decompress.d.ts +44 -0
- package/project/sigdb/decompress.js +176 -0
- package/project/sigdb/hash.d.ts +9 -0
- package/project/sigdb/hash.js +54 -0
- package/project/sigdb/index-format.d.ts +40 -0
- package/project/sigdb/index-format.js +28 -0
- package/project/sigdb/manifest.d.ts +68 -0
- package/project/sigdb/manifest.js +146 -0
- package/project/sigdb/reader.d.ts +250 -0
- package/project/sigdb/reader.js +692 -0
- package/project/sigdb/schema.d.ts +196 -0
- package/project/sigdb/schema.js +33 -0
- package/project/sigdb/sigdb-download.d.ts +65 -0
- package/project/sigdb/sigdb-download.js +237 -0
- package/project/sigdb/signature-match.d.ts +26 -0
- package/project/sigdb/signature-match.js +40 -0
- package/project/sigdb/version.d.ts +20 -0
- package/project/sigdb/version.js +55 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
- package/queries/catalog/config-query/config-query-format.d.ts +3 -1
- package/queries/catalog/config-query/config-query-format.js +68 -9
- package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
- package/queries/catalog/linter-query/linter-query-executor.js +6 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
- package/queries/catalog/linter-query/linter-query-format.js +40 -8
- package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
- package/queries/catalog/project-query/project-query-executor.js +96 -4
- package/queries/catalog/project-query/project-query-format.d.ts +44 -0
- package/queries/catalog/project-query/project-query-format.js +33 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
- package/queries/catalog/signature-query/signature-query-executor.js +461 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
- package/queries/catalog/signature-query/signature-query-format.js +76 -0
- package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
- package/queries/catalog/signature-query/signature-query-render.js +155 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
- package/queries/query-print.js +5 -0
- package/queries/query.d.ts +10 -1
- package/queries/query.js +5 -2
- package/r-bridge/init.js +5 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
- package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
- package/r-bridge/parser.d.ts +2 -0
- package/r-bridge/retriever.js +4 -1
- package/r-bridge/roxygen2/documentation-provider.js +2 -1
- package/r-bridge/shell.d.ts +5 -0
- package/r-bridge/shell.js +17 -1
- package/reconstruct/inline/source-inline-map.d.ts +48 -0
- package/reconstruct/inline/source-inline-map.js +94 -0
- package/reconstruct/reconstruct.d.ts +19 -2
- package/reconstruct/reconstruct.js +79 -16
- package/search/search-executor/search-generators.js +5 -22
- package/search/search-executor/search-transformer.js +10 -6
- package/slicing/criterion/parse.d.ts +22 -4
- package/slicing/criterion/parse.js +125 -18
- package/slicing/static/slice-call.d.ts +24 -1
- package/slicing/static/slice-call.js +90 -0
- package/slicing/static/static-slicer.d.ts +7 -0
- package/slicing/static/static-slicer.js +38 -3
- package/util/collections/arrays.d.ts +4 -5
- package/util/collections/arrays.js +7 -18
- package/util/hash.d.ts +14 -0
- package/util/hash.js +31 -0
- package/util/mermaid/dfg.d.ts +7 -2
- package/util/mermaid/dfg.js +53 -13
- package/util/r-base-packages.d.ts +19 -0
- package/util/r-base-packages.js +72 -0
- package/util/r-license.js +2 -10
- package/util/r-version.d.ts +45 -15
- package/util/r-version.js +97 -36
- package/util/range.d.ts +15 -0
- package/util/range.js +39 -0
- package/util/schema.d.ts +10 -0
- package/util/schema.js +22 -0
- package/util/text/ansi.d.ts +13 -1
- package/util/text/ansi.js +27 -4
- package/util/text/args.js +1 -2
- package/util/version.js +28 -8
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/documentation/wiki-package-database.d.ts +0 -9
- package/documentation/wiki-package-database.js +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -174
- package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
- package/project/plugins/package-version-plugins/pkgdb.js +0 -370
package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FlowrAnalyzerPackageVersionsPkgDbPlugin = exports.pkgDbLog = exports.PkgDbPluginName = void 0;
|
|
7
|
-
exports.reconstructS3Generics = reconstructS3Generics;
|
|
8
|
-
const flowr_analyzer_package_versions_plugin_1 = require("./flowr-analyzer-package-versions-plugin");
|
|
9
|
-
const semver_1 = require("semver");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const package_1 = require("./package");
|
|
12
|
-
const pkgdb_1 = require("./pkgdb");
|
|
13
|
-
const log_1 = require("../../../util/log");
|
|
14
|
-
/** the plugin's instance name (pass to `unregisterPlugins` to disable the default pkgdb resolver) */
|
|
15
|
-
exports.PkgDbPluginName = 'flowr-analyzer-package-versions-pkgdb-plugin';
|
|
16
|
-
exports.pkgDbLog = log_1.log.getSubLogger({ name: exports.PkgDbPluginName });
|
|
17
|
-
/** additional sources from `$FLOWR_PKGDB` (path-delimiter separated), highest priority after explicit ones */
|
|
18
|
-
function envSources() {
|
|
19
|
-
const env = typeof process !== 'undefined' ? process.env?.FLOWR_PKGDB : undefined;
|
|
20
|
-
return env ? env.split(path_1.default.delimiter).filter(s => s.length > 0) : [];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The database flattens S3 methods into the export list, so we recover the `generic -> classes` map for
|
|
24
|
-
* dispatch: an export `generic.class` is a method when the `generic` is itself exported (e.g. `print.foo`).
|
|
25
|
-
*/
|
|
26
|
-
function reconstructS3Generics(exported) {
|
|
27
|
-
const names = new Set(exported);
|
|
28
|
-
const generics = new Map();
|
|
29
|
-
for (const name of exported) {
|
|
30
|
-
const dot = name.indexOf('.');
|
|
31
|
-
const generic = dot > 0 ? name.slice(0, dot) : undefined;
|
|
32
|
-
if (generic !== undefined && names.has(generic)) {
|
|
33
|
-
const classes = generics.get(generic) ?? [];
|
|
34
|
-
classes.push(name.slice(dot + 1));
|
|
35
|
-
generics.set(generic, classes);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return generics;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Resolves `library(pkg)` / `use(pkg, fn)` from precomputed `flowr-pkgdb` databases: the one bundled
|
|
42
|
-
* with flowR plus any extra sources (constructor args or `$FLOWR_PKGDB`). Extra sources are consulted
|
|
43
|
-
* first, so they override the bundle; packages only in the bundle still resolve. Everything is loaded
|
|
44
|
-
* lazily on the first miss (never touched if a project uses no external packages). On by default; opt
|
|
45
|
-
* out via `unregisterPlugins(PkgDbPluginName)` or `$FLOWR_DISABLE_DEFAULT_PKGDB`.
|
|
46
|
-
*
|
|
47
|
-
* A source may be an `http(s)` URL to a downloadable summary; call {@link preload} once at the
|
|
48
|
-
* analyzer boundary to fetch it, so resolution falls through to it for packages not in the bundle.
|
|
49
|
-
*/
|
|
50
|
-
class FlowrAnalyzerPackageVersionsPkgDbPlugin extends flowr_analyzer_package_versions_plugin_1.FlowrAnalyzerPackageVersionsPlugin {
|
|
51
|
-
name = exports.PkgDbPluginName;
|
|
52
|
-
description = 'Resolves library exports from precomputed flowr-pkgdb databases.';
|
|
53
|
-
version = new semver_1.SemVer('0.1.0');
|
|
54
|
-
/**
|
|
55
|
-
* Process-wide cache of parsed file databases, keyed by their source path, so a flowR session parses
|
|
56
|
-
* each file once. Parsing the bundled database is ~25ms and a fresh plugin instance is created per
|
|
57
|
-
* analyzer, so without this every analysis touching a `library()` call would re-parse the multi-MB file.
|
|
58
|
-
*/
|
|
59
|
-
static fileCache = new Map();
|
|
60
|
-
extraSources;
|
|
61
|
-
databases;
|
|
62
|
-
constructor(...sources) {
|
|
63
|
-
super();
|
|
64
|
-
this.extraSources = sources;
|
|
65
|
-
}
|
|
66
|
-
process(ctx) {
|
|
67
|
-
this.databases = undefined; // reload on (re)registration so config/source changes take effect
|
|
68
|
-
ctx.deps.addLazyResolver((name, existing) => this.resolve(name, existing));
|
|
69
|
-
}
|
|
70
|
-
/** Mount the databases up front (see `solver.eagerlyLoadPackageDatabase`) instead of on the first library load. */
|
|
71
|
-
preloadDatabasesSync() {
|
|
72
|
-
this.loadDatabases();
|
|
73
|
-
}
|
|
74
|
-
/** metadata of the databases currently loaded (the synchronously available, non-URL sources) */
|
|
75
|
-
loadedDatabases() {
|
|
76
|
-
return this.loadDatabases().map(db => ({ scope: db.scope, version: db.content.version, date: db.content.date }));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Sources in priority order: explicit constructor sources, then `$FLOWR_PKGDB`, then the bundled
|
|
80
|
-
* default. The bundled default is skipped when `$FLOWR_DISABLE_DEFAULT_PKGDB` is set (explicit
|
|
81
|
-
* sources are always honored) - the env opt-out for the shipped database.
|
|
82
|
-
*/
|
|
83
|
-
sources() {
|
|
84
|
-
const disableBundled = typeof process !== 'undefined' && process.env?.FLOWR_DISABLE_DEFAULT_PKGDB;
|
|
85
|
-
const bundled = disableBundled ? undefined : (0, pkgdb_1.defaultPkgDbPath)(); // richest bundled tier (all > latest > tiny)
|
|
86
|
-
return [...this.extraSources, ...envSources(), ...(bundled ? [bundled] : [])];
|
|
87
|
-
}
|
|
88
|
-
static isUrl(s) {
|
|
89
|
-
return typeof s === 'string' && /^https?:\/\//.test(s);
|
|
90
|
-
}
|
|
91
|
-
/** synchronously loaded databases; remote (URL) summaries are only added by {@link preload}. */
|
|
92
|
-
loadDatabases() {
|
|
93
|
-
if (this.databases === undefined) {
|
|
94
|
-
this.databases = this.sources()
|
|
95
|
-
.filter(s => !FlowrAnalyzerPackageVersionsPkgDbPlugin.isUrl(s))
|
|
96
|
-
.map(s => this.load(s))
|
|
97
|
-
.filter((d) => d !== undefined);
|
|
98
|
-
}
|
|
99
|
-
return this.databases;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Download and load every source, including remote (URL) summaries. Call this once at the
|
|
103
|
-
* analyzer boundary to let `library()` resolution fall through to additional downloaded databases
|
|
104
|
-
* (e.g. the full `all` summary or a richer `latest`). Without it, only local sources are used.
|
|
105
|
-
*/
|
|
106
|
-
async preload() {
|
|
107
|
-
const dbs = [];
|
|
108
|
-
for (const source of this.sources()) {
|
|
109
|
-
try {
|
|
110
|
-
dbs.push(FlowrAnalyzerPackageVersionsPkgDbPlugin.isUrl(source) ? await pkgdb_1.PkgDatabase.fromUrl(source) : this.mustLoad(source));
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
exports.pkgDbLog.warn(`Could not load pkgdb source: ${e.message}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
this.databases = dbs;
|
|
117
|
-
}
|
|
118
|
-
load(source) {
|
|
119
|
-
try {
|
|
120
|
-
return this.mustLoad(source);
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
exports.pkgDbLog.warn(`Could not load pkgdb source: ${e.message}`);
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
mustLoad(source) {
|
|
128
|
-
if (source instanceof pkgdb_1.PkgDatabase) {
|
|
129
|
-
return source;
|
|
130
|
-
}
|
|
131
|
-
if (typeof source !== 'string') {
|
|
132
|
-
return pkgdb_1.PkgDatabase.fromObject(source);
|
|
133
|
-
}
|
|
134
|
-
return FlowrAnalyzerPackageVersionsPkgDbPlugin.loadFileCached(source);
|
|
135
|
-
}
|
|
136
|
-
/** Load a file source once per session, reusing the parsed database across analyzer instances. */
|
|
137
|
-
static loadFileCached(file) {
|
|
138
|
-
const cache = FlowrAnalyzerPackageVersionsPkgDbPlugin.fileCache;
|
|
139
|
-
let db = cache.get(file);
|
|
140
|
-
if (db === undefined) {
|
|
141
|
-
db = pkgdb_1.PkgDatabase.fromFileSync(file);
|
|
142
|
-
cache.set(file, db);
|
|
143
|
-
}
|
|
144
|
-
return db;
|
|
145
|
-
}
|
|
146
|
-
resolve(name, existing) {
|
|
147
|
-
const pinned = existing?.derivedVersion ? (0, semver_1.minVersion)(existing.derivedVersion)?.version : undefined;
|
|
148
|
-
for (const db of this.loadDatabases()) {
|
|
149
|
-
const info = db.lookup(name, pinned);
|
|
150
|
-
if (!info) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
if (pinned && info.version !== pinned) {
|
|
154
|
-
exports.pkgDbLog.warn(`project pins ${name}@${pinned} but the export database only has ${info.version}; analyzing with ${info.version}`);
|
|
155
|
-
}
|
|
156
|
-
else if (!pinned) {
|
|
157
|
-
exports.pkgDbLog.debug(`no pinned version for ${name}; using ${info.version}`);
|
|
158
|
-
}
|
|
159
|
-
const namespaceInfo = {
|
|
160
|
-
exportedSymbols: info.exported,
|
|
161
|
-
exportedFunctions: [],
|
|
162
|
-
exportS3Generics: reconstructS3Generics(info.exported),
|
|
163
|
-
exportedPatterns: [],
|
|
164
|
-
importedPackages: new Map(),
|
|
165
|
-
loadsWithSideEffects: false,
|
|
166
|
-
callable: info.exported
|
|
167
|
-
};
|
|
168
|
-
return new package_1.Package({ name, namespaceInfo });
|
|
169
|
-
}
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.FlowrAnalyzerPackageVersionsPkgDbPlugin = FlowrAnalyzerPackageVersionsPkgDbPlugin;
|
|
174
|
-
//# sourceMappingURL=flowr-analyzer-package-versions-pkgdb-plugin.js.map
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
export declare const PkgDbMagic = "flowr-pkgdb";
|
|
2
|
-
export declare const PkgDbSchema = 4;
|
|
3
|
-
export declare const DefaultCranBase = "https://cran.r-project.org/src/contrib/";
|
|
4
|
-
export type PkgDbItem = number | string;
|
|
5
|
-
export type PkgDbLatestEntry = [version: string, exported: PkgDbItem[]];
|
|
6
|
-
/** one version in the `all` scope: `[version, exported, internal?, deprecated?]` of `lists` indices */
|
|
7
|
-
export type PkgDbAllVersion = [string, number] | [string, number, number] | [string, number, number, number];
|
|
8
|
-
/** `all`-scope package: `[latest, versions, nonCranVersions?]` (all arrays, no keys) */
|
|
9
|
-
export type PkgDbAllEntry = [string, PkgDbAllVersion[]] | [string, PkgDbAllVersion[], string[]];
|
|
10
|
-
/** optional definition location `[fileIndex, line]` indexing the `files` pool */
|
|
11
|
-
export type PkgDbLoc = readonly [fileIndex: number, line: number];
|
|
12
|
-
export interface PkgDbContent {
|
|
13
|
-
version: number;
|
|
14
|
-
date: string;
|
|
15
|
-
hash: string;
|
|
16
|
-
generated: number;
|
|
17
|
-
packages: number;
|
|
18
|
-
versions: number;
|
|
19
|
-
}
|
|
20
|
-
interface PkgDbCommon {
|
|
21
|
-
format: string;
|
|
22
|
-
schema: number;
|
|
23
|
-
content: PkgDbContent;
|
|
24
|
-
cranBase?: string;
|
|
25
|
-
strings: string[];
|
|
26
|
-
archived?: string[];
|
|
27
|
-
noncran?: string[];
|
|
28
|
-
}
|
|
29
|
-
export interface PkgDbLatest extends PkgDbCommon {
|
|
30
|
-
scope: 'latest';
|
|
31
|
-
pkgs: Record<string, PkgDbLatestEntry>;
|
|
32
|
-
}
|
|
33
|
-
export interface PkgDbAll extends PkgDbCommon {
|
|
34
|
-
scope: 'all';
|
|
35
|
-
lists: PkgDbItem[][];
|
|
36
|
-
pkgs: Record<string, PkgDbAllEntry>;
|
|
37
|
-
/** optional file-path pool for {@link locs} */
|
|
38
|
-
files?: string[];
|
|
39
|
-
/** optional definition locations of the latest version: `pkg -> identifier -> [fileIndex, line]` */
|
|
40
|
-
locs?: Record<string, Record<string, PkgDbLoc>>;
|
|
41
|
-
}
|
|
42
|
-
export type PkgDb = PkgDbLatest | PkgDbAll;
|
|
43
|
-
/** a definition location surfaced from the `all` scope when the database carries them */
|
|
44
|
-
export interface PkgDbDefinitionLocation {
|
|
45
|
-
file: string;
|
|
46
|
-
line: number;
|
|
47
|
-
}
|
|
48
|
-
/** the resolved identifiers of one package version */
|
|
49
|
-
export interface LibraryExports {
|
|
50
|
-
version: string;
|
|
51
|
-
exported: string[];
|
|
52
|
-
/** defined-but-not-exported identifiers (only available in the `all` scope) */
|
|
53
|
-
internal: string[];
|
|
54
|
-
deprecated: string[];
|
|
55
|
-
cran: boolean;
|
|
56
|
-
cranUrl?: string;
|
|
57
|
-
/** definition location per identifier, if the database carries them (`all` scope, latest version) */
|
|
58
|
-
locations?: ReadonlyMap<string, PkgDbDefinitionLocation>;
|
|
59
|
-
}
|
|
60
|
-
/** Reconstruct the CRAN source blob link; the newest non-archived version lives under `src/contrib`, every other under `Archive`. */
|
|
61
|
-
export declare function cranBlobUrl(cranBase: string, pkg: string, version: string, opts: {
|
|
62
|
-
latest: string;
|
|
63
|
-
archived: boolean;
|
|
64
|
-
cran: boolean;
|
|
65
|
-
}): string | undefined;
|
|
66
|
-
/** Validate the structural invariants of a decoded database, throwing a descriptive error on failure. */
|
|
67
|
-
export declare function validatePkgDb(o: unknown): asserts o is PkgDb;
|
|
68
|
-
export type PkgDbScope = 'all' | 'latest' | 'tiny';
|
|
69
|
-
/**
|
|
70
|
-
* Location of a bundled database, found by walking up from several roots (this module,
|
|
71
|
-
* `$FLOWR_PKGDB_DIR`, the working directory) across the dev (`src`) and build (`dist`) layouts. With
|
|
72
|
-
* no `scope` it returns the richest available tier (brotli, then gzip, then plain json). Node only
|
|
73
|
-
* (needs `fs`); pass `searchRoots` to override where it looks.
|
|
74
|
-
*/
|
|
75
|
-
export declare function defaultPkgDbPath(scope?: PkgDbScope, searchRoots?: readonly string[]): string | undefined;
|
|
76
|
-
/** classified identifiers of one package version, fed to {@link PkgDbBuilder} */
|
|
77
|
-
export interface VersionExports {
|
|
78
|
-
exported: readonly string[];
|
|
79
|
-
internal: readonly string[];
|
|
80
|
-
deprecated: readonly string[];
|
|
81
|
-
cran: boolean;
|
|
82
|
-
/** optional definition location per identifier: `name -> [file, line]` (emitted only in the `all` scope) */
|
|
83
|
-
locations?: ReadonlyMap<string, readonly [file: string, line: number]>;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Serializes a {@link PkgDb}. Accumulate per-version exports with {@link addPackage}/{@link addVersion},
|
|
87
|
-
* then {@link build} a scope. The multi-use string pool is computed per scope; the `latest` scope may
|
|
88
|
-
* be pruned to the most-downloaded packages. This is the counterpart of {@link PkgDatabase} (the reader).
|
|
89
|
-
*/
|
|
90
|
-
export declare class PkgDbBuilder {
|
|
91
|
-
private readonly raw;
|
|
92
|
-
private versionCount;
|
|
93
|
-
addPackage(name: string, opts: {
|
|
94
|
-
latest: string;
|
|
95
|
-
archived?: boolean;
|
|
96
|
-
downloads?: number;
|
|
97
|
-
}): void;
|
|
98
|
-
addVersion(name: string, version: string, exports: VersionExports): void;
|
|
99
|
-
private relevant;
|
|
100
|
-
private buildPool;
|
|
101
|
-
build(scope: 'latest' | 'all', meta: {
|
|
102
|
-
version: number;
|
|
103
|
-
date: string;
|
|
104
|
-
generated: number;
|
|
105
|
-
cranBase?: string;
|
|
106
|
-
minDownloads?: number;
|
|
107
|
-
topN?: number;
|
|
108
|
-
}): PkgDb;
|
|
109
|
-
}
|
|
110
|
-
export declare class PkgDatabase {
|
|
111
|
-
private readonly db;
|
|
112
|
-
private readonly archived;
|
|
113
|
-
private readonly noncran;
|
|
114
|
-
constructor(db: PkgDb);
|
|
115
|
-
get content(): PkgDbContent;
|
|
116
|
-
get scope(): 'latest' | 'all';
|
|
117
|
-
/** parse an already-loaded object (validates the schema, throwing a descriptive error on failure) */
|
|
118
|
-
static fromObject(obj: unknown): PkgDatabase;
|
|
119
|
-
/** portable async load from raw bytes (gzip auto-detected) */
|
|
120
|
-
static fromBytes(bytes: Uint8Array): Promise<PkgDatabase>;
|
|
121
|
-
/** portable async load from a URL (works in Node 18+, browser and VS Code) */
|
|
122
|
-
static fromUrl(url: string): Promise<PkgDatabase>;
|
|
123
|
-
/** synchronous load from a local file (Node only; brotli by `.br`, else gzip auto-detected, else plain) */
|
|
124
|
-
static fromFileSync(file: string): PkgDatabase;
|
|
125
|
-
has(pkg: string): boolean;
|
|
126
|
-
private decode;
|
|
127
|
-
private result;
|
|
128
|
-
/** definition locations of the latest version, if the (`all`-scope) database carries them */
|
|
129
|
-
private locations;
|
|
130
|
-
/** look up the identifiers of a package (defaulting to its latest version) */
|
|
131
|
-
lookup(pkg: string, version?: string): LibraryExports | undefined;
|
|
132
|
-
}
|
|
133
|
-
export {};
|
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PkgDatabase = exports.PkgDbBuilder = exports.DefaultCranBase = exports.PkgDbSchema = exports.PkgDbMagic = void 0;
|
|
7
|
-
exports.cranBlobUrl = cranBlobUrl;
|
|
8
|
-
exports.validatePkgDb = validatePkgDb;
|
|
9
|
-
exports.defaultPkgDbPath = defaultPkgDbPath;
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
/*
|
|
14
|
-
* Reader/writer for the `flowr-pkgdb` database (schema 4) produced by crawlr's `dump`.
|
|
15
|
-
* An export list mixes `strings`-pool indices (number) and inline single-use names.
|
|
16
|
-
* latest: pkgs[name] = [version, exported]. all: shares a `lists` pool and stores
|
|
17
|
-
* pkgs[name] = [latest, versions, nonCran?] with each version [ver, exported, internal?, deprecated?].
|
|
18
|
-
* Optional `all` definition locations: a `files` pool + locs[pkg][id] = [fileIndex, line] (latest only).
|
|
19
|
-
* CRAN urls are reconstructed on load. {@link PkgDbBuilder} writes, {@link PkgDatabase} reads - both in flowR.
|
|
20
|
-
*/
|
|
21
|
-
exports.PkgDbMagic = 'flowr-pkgdb';
|
|
22
|
-
exports.PkgDbSchema = 4;
|
|
23
|
-
exports.DefaultCranBase = 'https://cran.r-project.org/src/contrib/';
|
|
24
|
-
/** Reconstruct the CRAN source blob link; the newest non-archived version lives under `src/contrib`, every other under `Archive`. */
|
|
25
|
-
function cranBlobUrl(cranBase, pkg, version, opts) {
|
|
26
|
-
if (!opts.cran) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const base = cranBase.endsWith('/') ? cranBase : cranBase + '/';
|
|
30
|
-
return version === opts.latest && !opts.archived
|
|
31
|
-
? `${base}${pkg}_${version}.tar.gz`
|
|
32
|
-
: `${base}Archive/${pkg}/${pkg}_${version}.tar.gz`;
|
|
33
|
-
}
|
|
34
|
-
/** Validate the structural invariants of a decoded database, throwing a descriptive error on failure. */
|
|
35
|
-
function validatePkgDb(o) {
|
|
36
|
-
const fail = (msg) => {
|
|
37
|
-
throw new Error(`invalid flowr-pkgdb database: ${msg}`);
|
|
38
|
-
};
|
|
39
|
-
if (typeof o !== 'object' || o === null) {
|
|
40
|
-
fail('not an object');
|
|
41
|
-
}
|
|
42
|
-
const db = o;
|
|
43
|
-
if (db.format !== exports.PkgDbMagic) {
|
|
44
|
-
fail(`missing/invalid format (expected "${exports.PkgDbMagic}")`);
|
|
45
|
-
}
|
|
46
|
-
if (db.schema !== exports.PkgDbSchema) {
|
|
47
|
-
fail(`unsupported schema version ${String(db.schema)} (expected ${exports.PkgDbSchema})`);
|
|
48
|
-
}
|
|
49
|
-
if (db.scope !== 'latest' && db.scope !== 'all') {
|
|
50
|
-
fail(`invalid scope ${String(db.scope)}`);
|
|
51
|
-
}
|
|
52
|
-
if (!Array.isArray(db.strings)) {
|
|
53
|
-
fail('missing strings pool');
|
|
54
|
-
}
|
|
55
|
-
if (typeof db.pkgs !== 'object' || db.pkgs === null) {
|
|
56
|
-
fail('missing pkgs');
|
|
57
|
-
}
|
|
58
|
-
if (db.scope === 'all' && !Array.isArray(db.lists)) {
|
|
59
|
-
fail('all-scope database is missing the lists pool');
|
|
60
|
-
}
|
|
61
|
-
if (typeof db.content !== 'object' || db.content === null || typeof db.content.version !== 'number') {
|
|
62
|
-
fail('missing/invalid content header');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/** portable gunzip (Node + browser + VS Code) via the Web Streams API */
|
|
66
|
-
async function gunzip(bytes) {
|
|
67
|
-
return new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'))).text();
|
|
68
|
-
}
|
|
69
|
-
function isGzip(bytes) {
|
|
70
|
-
return bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
71
|
-
}
|
|
72
|
-
/** richest first: `all` carries every version, `latest`/`tiny` only the current one */
|
|
73
|
-
const PkgDbScopeOrder = ['all', 'latest', 'tiny'];
|
|
74
|
-
/** layouts a bundled database may sit in, relative to a search root */
|
|
75
|
-
const PkgDbSubDirs = ['data/pkgdb', 'src/data/pkgdb', 'dist/src/data/pkgdb'];
|
|
76
|
-
/** roots to search for a bundled database; extendable via `$FLOWR_PKGDB_DIR` (path-delimiter separated) */
|
|
77
|
-
function pkgDbSearchRoots(extra) {
|
|
78
|
-
const roots = [...(extra ?? [])];
|
|
79
|
-
const env = typeof process !== 'undefined' ? process.env?.FLOWR_PKGDB_DIR : undefined;
|
|
80
|
-
if (env) {
|
|
81
|
-
roots.push(...env.split(path_1.default.delimiter).filter(Boolean));
|
|
82
|
-
}
|
|
83
|
-
if (typeof __dirname !== 'undefined') {
|
|
84
|
-
roots.push(__dirname);
|
|
85
|
-
}
|
|
86
|
-
if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
|
|
87
|
-
roots.push(process.cwd());
|
|
88
|
-
}
|
|
89
|
-
return roots;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Location of a bundled database, found by walking up from several roots (this module,
|
|
93
|
-
* `$FLOWR_PKGDB_DIR`, the working directory) across the dev (`src`) and build (`dist`) layouts. With
|
|
94
|
-
* no `scope` it returns the richest available tier (brotli, then gzip, then plain json). Node only
|
|
95
|
-
* (needs `fs`); pass `searchRoots` to override where it looks.
|
|
96
|
-
*/
|
|
97
|
-
function defaultPkgDbPath(scope, searchRoots) {
|
|
98
|
-
if (typeof fs_1.default?.existsSync !== 'function') {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
const scopes = scope ? [scope] : PkgDbScopeOrder;
|
|
102
|
-
for (const root of pkgDbSearchRoots(searchRoots)) {
|
|
103
|
-
for (let dir = root, i = 0; i < 10; i++) {
|
|
104
|
-
for (const sub of PkgDbSubDirs) {
|
|
105
|
-
for (const s of scopes) {
|
|
106
|
-
for (const suffix of ['.br', '.gz', '']) {
|
|
107
|
-
const candidate = path_1.default.join(dir, sub, `pkgdb-${s}.json${suffix}`);
|
|
108
|
-
if (fs_1.default.existsSync(candidate)) {
|
|
109
|
-
return candidate;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const parent = path_1.default.dirname(dir);
|
|
115
|
-
if (parent === dir) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
dir = parent;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
/** portable non-cryptographic 64-bit hash (cyrb53), hex, for update detection */
|
|
124
|
-
function hash53(str) {
|
|
125
|
-
let h1 = 0xdeadbeef, h2 = 0x41c6ce57;
|
|
126
|
-
for (let i = 0; i < str.length; i++) {
|
|
127
|
-
const ch = str.charCodeAt(i);
|
|
128
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
129
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
130
|
-
}
|
|
131
|
-
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
132
|
-
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
133
|
-
return (h2 >>> 0).toString(16).padStart(8, '0') + (h1 >>> 0).toString(16).padStart(8, '0');
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Serializes a {@link PkgDb}. Accumulate per-version exports with {@link addPackage}/{@link addVersion},
|
|
137
|
-
* then {@link build} a scope. The multi-use string pool is computed per scope; the `latest` scope may
|
|
138
|
-
* be pruned to the most-downloaded packages. This is the counterpart of {@link PkgDatabase} (the reader).
|
|
139
|
-
*/
|
|
140
|
-
class PkgDbBuilder {
|
|
141
|
-
raw = new Map();
|
|
142
|
-
versionCount = 0;
|
|
143
|
-
addPackage(name, opts) {
|
|
144
|
-
const p = this.raw.get(name);
|
|
145
|
-
if (p) {
|
|
146
|
-
p.latest = opts.latest;
|
|
147
|
-
p.archived = opts.archived ?? p.archived;
|
|
148
|
-
p.downloads = opts.downloads ?? p.downloads;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
this.raw.set(name, { latest: opts.latest, archived: opts.archived ?? false, downloads: opts.downloads ?? 0, versions: new Map() });
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
addVersion(name, version, exports) {
|
|
155
|
-
const p = this.raw.get(name) ?? { latest: version, archived: false, downloads: 0, versions: new Map() };
|
|
156
|
-
if (!this.raw.has(name)) {
|
|
157
|
-
this.raw.set(name, p);
|
|
158
|
-
}
|
|
159
|
-
p.versions.set(version, exports);
|
|
160
|
-
this.versionCount++;
|
|
161
|
-
}
|
|
162
|
-
relevant(scope, prune) {
|
|
163
|
-
if (scope === 'all') {
|
|
164
|
-
const out = [];
|
|
165
|
-
for (const [name, p] of this.raw) {
|
|
166
|
-
for (const [version, ex] of p.versions) {
|
|
167
|
-
out.push({ name, version, ex });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return out;
|
|
171
|
-
}
|
|
172
|
-
let pkgs = [...this.raw].filter(([, p]) => p.downloads >= prune.minDownloads && p.versions.has(p.latest));
|
|
173
|
-
if (prune.topN !== undefined && pkgs.length > prune.topN) {
|
|
174
|
-
pkgs = pkgs.sort((a, b) => b[1].downloads - a[1].downloads).slice(0, prune.topN);
|
|
175
|
-
}
|
|
176
|
-
return pkgs.map(([name, p]) => ({ name, version: p.latest, ex: p.versions.get(p.latest) }));
|
|
177
|
-
}
|
|
178
|
-
buildPool(relevant, scope) {
|
|
179
|
-
const freq = new Map();
|
|
180
|
-
for (const { ex } of relevant) {
|
|
181
|
-
const names = scope === 'all' ? [...ex.exported, ...ex.internal, ...ex.deprecated] : ex.exported;
|
|
182
|
-
for (const name of names) {
|
|
183
|
-
freq.set(name, (freq.get(name) ?? 0) + 1);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const strings = [...freq.entries()].filter(([, c]) => c >= 2).sort((a, b) => b[1] - a[1]).map(([n]) => n);
|
|
187
|
-
return { strings, index: new Map(strings.map((n, i) => [n, i])) };
|
|
188
|
-
}
|
|
189
|
-
build(scope, meta) {
|
|
190
|
-
const relevant = this.relevant(scope, { minDownloads: meta.minDownloads ?? 0, topN: meta.topN });
|
|
191
|
-
const { strings, index } = this.buildPool(relevant, scope);
|
|
192
|
-
const encode = (names) => [...new Set(names)].sort().map(n => index.get(n) ?? n);
|
|
193
|
-
const content = {
|
|
194
|
-
version: meta.version, date: meta.date, hash: '', generated: meta.generated,
|
|
195
|
-
packages: scope === 'latest' ? relevant.length : this.raw.size, versions: this.versionCount
|
|
196
|
-
};
|
|
197
|
-
const cranBase = meta.cranBase && meta.cranBase !== exports.DefaultCranBase ? meta.cranBase : undefined;
|
|
198
|
-
const archived = [];
|
|
199
|
-
let db;
|
|
200
|
-
if (scope === 'latest') {
|
|
201
|
-
const noncran = [];
|
|
202
|
-
const pkgs = {};
|
|
203
|
-
for (const { name, version, ex } of relevant) {
|
|
204
|
-
pkgs[name] = [version, encode(ex.exported)];
|
|
205
|
-
if (this.raw.get(name)?.archived) {
|
|
206
|
-
archived.push(name);
|
|
207
|
-
}
|
|
208
|
-
if (!ex.cran) {
|
|
209
|
-
noncran.push(name);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
db = { format: exports.PkgDbMagic, schema: exports.PkgDbSchema, scope, content, cranBase, strings, pkgs,
|
|
213
|
-
...(archived.length ? { archived } : {}), ...(noncran.length ? { noncran } : {}) };
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
const lists = [];
|
|
217
|
-
const listIndex = new Map();
|
|
218
|
-
const internList = (names) => {
|
|
219
|
-
const enc = encode(names);
|
|
220
|
-
const key = JSON.stringify(enc);
|
|
221
|
-
let idx = listIndex.get(key);
|
|
222
|
-
if (idx === undefined) {
|
|
223
|
-
idx = lists.length;
|
|
224
|
-
lists.push(enc);
|
|
225
|
-
listIndex.set(key, idx);
|
|
226
|
-
}
|
|
227
|
-
return idx;
|
|
228
|
-
};
|
|
229
|
-
internList([]);
|
|
230
|
-
const files = [];
|
|
231
|
-
const fileIndex = new Map();
|
|
232
|
-
const internFile = (f) => {
|
|
233
|
-
let idx = fileIndex.get(f);
|
|
234
|
-
if (idx === undefined) {
|
|
235
|
-
idx = files.length;
|
|
236
|
-
files.push(f);
|
|
237
|
-
fileIndex.set(f, idx);
|
|
238
|
-
}
|
|
239
|
-
return idx;
|
|
240
|
-
};
|
|
241
|
-
const locs = {};
|
|
242
|
-
const pkgs = {};
|
|
243
|
-
for (const [name, p] of this.raw) {
|
|
244
|
-
const versions = [];
|
|
245
|
-
const nc = [];
|
|
246
|
-
for (const [version, ex] of p.versions) {
|
|
247
|
-
const e = internList(ex.exported), i = internList(ex.internal), d = internList(ex.deprecated);
|
|
248
|
-
versions.push(d !== 0 ? [version, e, i, d] : i !== 0 ? [version, e, i] : [version, e]);
|
|
249
|
-
if (!ex.cran) {
|
|
250
|
-
nc.push(version);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
pkgs[name] = nc.length ? [p.latest, versions, nc] : [p.latest, versions];
|
|
254
|
-
if (p.archived) {
|
|
255
|
-
archived.push(name);
|
|
256
|
-
}
|
|
257
|
-
// optional: record the latest version's definition locations, if the source carried them
|
|
258
|
-
const latestLoc = p.versions.get(p.latest)?.locations;
|
|
259
|
-
if (latestLoc && latestLoc.size > 0) {
|
|
260
|
-
const entry = {};
|
|
261
|
-
for (const [id, [file, line]] of latestLoc) {
|
|
262
|
-
entry[id] = [internFile(file), line];
|
|
263
|
-
}
|
|
264
|
-
locs[name] = entry;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
db = { format: exports.PkgDbMagic, schema: exports.PkgDbSchema, scope, content, cranBase, strings, lists, pkgs,
|
|
268
|
-
...(archived.length ? { archived } : {}),
|
|
269
|
-
...(files.length ? { files, locs } : {}) };
|
|
270
|
-
}
|
|
271
|
-
return { ...db, content: { ...content, hash: hash53(JSON.stringify(db)) } };
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
exports.PkgDbBuilder = PkgDbBuilder;
|
|
275
|
-
class PkgDatabase {
|
|
276
|
-
db;
|
|
277
|
-
archived;
|
|
278
|
-
noncran;
|
|
279
|
-
constructor(db) {
|
|
280
|
-
this.db = db;
|
|
281
|
-
this.archived = new Set(db.archived ?? []);
|
|
282
|
-
this.noncran = new Set(db.noncran ?? []);
|
|
283
|
-
}
|
|
284
|
-
get content() {
|
|
285
|
-
return this.db.content;
|
|
286
|
-
}
|
|
287
|
-
get scope() {
|
|
288
|
-
return this.db.scope;
|
|
289
|
-
}
|
|
290
|
-
/** parse an already-loaded object (validates the schema, throwing a descriptive error on failure) */
|
|
291
|
-
static fromObject(obj) {
|
|
292
|
-
validatePkgDb(obj);
|
|
293
|
-
return new PkgDatabase(obj);
|
|
294
|
-
}
|
|
295
|
-
/** portable async load from raw bytes (gzip auto-detected) */
|
|
296
|
-
static async fromBytes(bytes) {
|
|
297
|
-
const text = isGzip(bytes) ? await gunzip(bytes) : new TextDecoder().decode(bytes);
|
|
298
|
-
return PkgDatabase.fromObject(JSON.parse(text));
|
|
299
|
-
}
|
|
300
|
-
/** portable async load from a URL (works in Node 18+, browser and VS Code) */
|
|
301
|
-
static async fromUrl(url) {
|
|
302
|
-
return PkgDatabase.fromBytes(new Uint8Array(await (await fetch(url)).arrayBuffer()));
|
|
303
|
-
}
|
|
304
|
-
/** synchronous load from a local file (Node only; brotli by `.br`, else gzip auto-detected, else plain) */
|
|
305
|
-
static fromFileSync(file) {
|
|
306
|
-
const raw = fs_1.default.readFileSync(file);
|
|
307
|
-
const bytes = new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
308
|
-
const text = file.endsWith('.br') ? zlib_1.default.brotliDecompressSync(raw).toString('utf8')
|
|
309
|
-
: isGzip(bytes) ? zlib_1.default.gunzipSync(raw).toString('utf8')
|
|
310
|
-
: raw.toString('utf8');
|
|
311
|
-
return PkgDatabase.fromObject(JSON.parse(text));
|
|
312
|
-
}
|
|
313
|
-
has(pkg) {
|
|
314
|
-
return this.db.pkgs[pkg] !== undefined;
|
|
315
|
-
}
|
|
316
|
-
decode(list) {
|
|
317
|
-
return (list ?? []).map(x => typeof x === 'number' ? this.db.strings[x] : x);
|
|
318
|
-
}
|
|
319
|
-
result(pkg, version, latest, cran, exported, internal, deprecated, locations) {
|
|
320
|
-
const cranBase = this.db.cranBase ?? exports.DefaultCranBase;
|
|
321
|
-
return {
|
|
322
|
-
version, exported, internal, deprecated, cran,
|
|
323
|
-
cranUrl: cranBlobUrl(cranBase, pkg, version, { latest, archived: this.archived.has(pkg), cran }),
|
|
324
|
-
...(locations ? { locations } : {})
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
/** definition locations of the latest version, if the (`all`-scope) database carries them */
|
|
328
|
-
locations(pkg) {
|
|
329
|
-
if (this.db.scope !== 'all' || !this.db.locs || !this.db.files) {
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
const entry = this.db.locs[pkg];
|
|
333
|
-
if (!entry) {
|
|
334
|
-
return undefined;
|
|
335
|
-
}
|
|
336
|
-
const files = this.db.files;
|
|
337
|
-
const map = new Map();
|
|
338
|
-
for (const id in entry) {
|
|
339
|
-
const [fileIdx, line] = entry[id];
|
|
340
|
-
map.set(id, { file: files[fileIdx], line });
|
|
341
|
-
}
|
|
342
|
-
return map;
|
|
343
|
-
}
|
|
344
|
-
/** look up the identifiers of a package (defaulting to its latest version) */
|
|
345
|
-
lookup(pkg, version) {
|
|
346
|
-
if (this.db.scope === 'latest') {
|
|
347
|
-
const entry = this.db.pkgs[pkg];
|
|
348
|
-
if (!entry) {
|
|
349
|
-
return undefined;
|
|
350
|
-
}
|
|
351
|
-
return this.result(pkg, entry[0], entry[0], !this.noncran.has(pkg), this.decode(entry[1]), [], []);
|
|
352
|
-
}
|
|
353
|
-
const entry = this.db.pkgs[pkg];
|
|
354
|
-
if (!entry) {
|
|
355
|
-
return undefined;
|
|
356
|
-
}
|
|
357
|
-
const [latest, versions, nc] = entry;
|
|
358
|
-
const vt = (version ? versions.find(v => v[0] === version) : undefined)
|
|
359
|
-
?? versions.find(v => v[0] === latest) ?? versions[versions.length - 1];
|
|
360
|
-
if (!vt) {
|
|
361
|
-
return undefined;
|
|
362
|
-
}
|
|
363
|
-
const lists = this.db.lists;
|
|
364
|
-
// locations are only stored for the latest version
|
|
365
|
-
const locations = vt[0] === latest ? this.locations(pkg) : undefined;
|
|
366
|
-
return this.result(pkg, vt[0], latest, !nc?.includes(vt[0]), this.decode(lists[vt[1]]), this.decode(lists[vt[2] ?? 0]), this.decode(lists[vt[3] ?? 0]), locations);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
exports.PkgDatabase = PkgDatabase;
|
|
370
|
-
//# sourceMappingURL=pkgdb.js.map
|