@eagleoutice/flowr 2.17.0 → 2.17.2
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 +8 -8
- package/config.d.ts +32 -0
- package/config.js +22 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/dataflow/environments/ambient-state-name.d.ts +4 -0
- package/dataflow/environments/ambient-state-name.js +4 -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-props.d.ts +18 -2
- package/dataflow/environments/built-in-props.js +26 -4
- package/dataflow/environments/built-in.d.ts +16 -6
- package/dataflow/environments/built-in.js +58 -7
- package/dataflow/environments/default-builtin-config.d.ts +1245 -159
- package/dataflow/environments/default-builtin-config.js +191 -38
- package/dataflow/environments/environment.d.ts +19 -2
- package/dataflow/environments/environment.js +90 -19
- package/dataflow/environments/identifier.d.ts +25 -1
- package/dataflow/environments/query-fn-props.js +4 -3
- package/dataflow/environments/resolve-by-name.js +5 -3
- package/dataflow/eval/resolve/node-value.d.ts +1 -1
- package/dataflow/eval/resolve/node-value.js +2 -2
- package/dataflow/eval/resolve/resolve-argument.js +1 -1
- package/dataflow/extractor.js +68 -17
- package/dataflow/fn/function-semantics.d.ts +1 -0
- package/dataflow/graph/df-helper.d.ts +34 -1
- package/dataflow/graph/df-helper.js +60 -0
- package/dataflow/info.d.ts +2 -0
- package/dataflow/info.js +4 -0
- package/dataflow/internal/linker.js +21 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +4 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +3 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +18 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +144 -30
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +10 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +8 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +43 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +67 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +27 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +2 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +1 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +28 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +134 -88
- package/dataflow/internal/process/functions/call/built-in/built-in-load.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +87 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +8 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +23 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +28 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +18 -15
- package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +8 -7
- package/documentation/wiki-dataflow-graph.js +20 -1
- package/linter/rules/network-functions.js +10 -2
- package/linter/rules/undefined-symbol.js +2 -2
- package/linter/rules/unused-import.js +11 -1
- package/package.json +1 -1
- package/project/attached-packages.d.ts +11 -6
- package/project/attached-packages.js +37 -9
- package/project/cache/flowr-analyzer-cache.d.ts +4 -0
- package/project/cache/flowr-analyzer-cache.js +11 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +3 -0
- package/project/context/flowr-analyzer-dependencies-context.js +6 -0
- package/project/context/flowr-file.d.ts +2 -2
- package/project/context/flowr-file.js +2 -2
- package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +39 -4
- package/project/plugins/file-plugins/files/flowr-manifest-files.js +134 -30
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +7 -0
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +14 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +18 -5
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +43 -15
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +12 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +58 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +237 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +8 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +8 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +7 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +24 -18
- package/project/plugins/plugin-registry.d.ts +5 -4
- package/project/plugins/plugin-registry.js +6 -0
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
- package/project/sigdb/decode.js +13 -3
- package/project/sigdb/memory-source.d.ts +6 -4
- package/project/sigdb/memory-source.js +6 -5
- package/project/sigdb/on-demand/fetch.d.ts +18 -0
- package/project/sigdb/on-demand/fetch.js +127 -0
- package/project/sigdb/on-demand/package-sources.d.ts +40 -0
- package/project/sigdb/on-demand/package-sources.js +263 -0
- package/project/sigdb/on-demand/recoverer.d.ts +40 -0
- package/project/sigdb/on-demand/recoverer.js +169 -0
- package/project/sigdb/on-demand/remote-sources.d.ts +72 -0
- package/project/sigdb/on-demand/remote-sources.js +132 -0
- package/project/sigdb/on-demand/tar.d.ts +19 -0
- package/project/sigdb/on-demand/tar.js +119 -0
- package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +5 -0
- package/queries/catalog/dependencies-query/function-info/derived-functions.js +17 -1
- package/queries/catalog/dependencies-query/function-info/read-functions.js +3 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +11 -1
- package/queries/catalog/signature-query/signature-query-executor.js +15 -1
- package/queries/catalog/signature-query/signature-query-format.d.ts +3 -2
- package/r-bridge/data/data.d.ts +31 -2
- package/r-bridge/data/data.js +25 -2
- package/r-bridge/lang-4.x/ast/model/model.d.ts +2 -0
- package/r-bridge/lang-4.x/ast/model/model.js +6 -1
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -1
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +12 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +4 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +8 -0
- package/reconstruct/reconstruct.js +2 -5
- package/search/search-executor/search-enrichers.js +17 -2
- package/search/search-executor/search-generators.js +6 -2
- package/slicing/static/slice-call.d.ts +16 -0
- package/slicing/static/slice-call.js +42 -0
- package/slicing/static/static-slicer.js +6 -0
- package/taint-analysis/predefined/secret-analysis.js +7 -2
- package/taint-analysis/taint-mapping.d.ts +5 -2
- package/taint-analysis/taint-mapping.js +17 -6
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/r-version.js +4 -2
package/project/sigdb/decode.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.deriveLibraryExports = deriveLibraryExports;
|
|
|
12
12
|
const schema_1 = require("./schema");
|
|
13
13
|
const sigdb_version_1 = require("./sigdb-version");
|
|
14
14
|
const objects_1 = require("../../util/objects");
|
|
15
|
+
const r_primitives_generated_1 = require("../../data/r-primitives.generated");
|
|
15
16
|
/**
|
|
16
17
|
* Reconstruct the CRAN source blob link which is the newest non-archived version lives under `src/contrib`,
|
|
17
18
|
* every other under `Archive`.
|
|
@@ -75,6 +76,7 @@ function transitiveCallees(functions, name) {
|
|
|
75
76
|
/** decode one of a blob's function records against the global string dictionary */
|
|
76
77
|
function decodeFunction(strings, blob, fnIdx) {
|
|
77
78
|
const [nameIdx, sigIdx, cgIdx, bits, fileIdx, line, topicIdx] = blob.fns[fnIdx];
|
|
79
|
+
const name = strings.at(nameIdx);
|
|
78
80
|
const signature = (sigIdx >= 0 ? blob.sigs[sigIdx] : []).map(p => {
|
|
79
81
|
const [n, props, def] = Array.isArray(p) ? [p[0], p[1], p.length === 3 ? p[2] : -1] : [p, 0, -1];
|
|
80
82
|
return (0, objects_1.compactRecord)({ name: strings.at(n), props, default: def >= 0 ? strings.at(def) : undefined });
|
|
@@ -85,11 +87,11 @@ function decodeFunction(strings, blob, fnIdx) {
|
|
|
85
87
|
callees = blob.cgs[cgIdx].map(d => strings.at(prev += d));
|
|
86
88
|
}
|
|
87
89
|
return (0, objects_1.compactRecord)({
|
|
88
|
-
name
|
|
90
|
+
name,
|
|
89
91
|
topic: topicIdx !== undefined && topicIdx >= 0 ? strings.at(topicIdx) : undefined,
|
|
90
92
|
file: fileIdx >= 0 ? strings.at(fileIdx) : undefined,
|
|
91
93
|
line,
|
|
92
|
-
exported:
|
|
94
|
+
exported: isExportedEntry(bits, name),
|
|
93
95
|
props: Object.entries(schema_1.FnPropNames).filter(([m]) => bits & Number(m)).map(([, n]) => n),
|
|
94
96
|
signature,
|
|
95
97
|
callees
|
|
@@ -145,6 +147,14 @@ function versionFnIndices(blob, ver) {
|
|
|
145
147
|
}
|
|
146
148
|
return out;
|
|
147
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Whether a stored entry is an export. A method on a primitive generic (`setMethod("+", ...)`) binds nothing in the
|
|
152
|
+
* namespace, so R exports it under no directive, and `pkg::"+"` does not exist; a database built before that was
|
|
153
|
+
* known may still flag it exported, and attaching it would shadow the base primitive for every call.
|
|
154
|
+
*/
|
|
155
|
+
function isExportedEntry(bits, name) {
|
|
156
|
+
return (bits & 1 /* FnProp.Exported */) !== 0 && !((bits & 4096 /* FnProp.S4Method */) !== 0 && r_primitives_generated_1.RPrimitives.has(name));
|
|
157
|
+
}
|
|
148
158
|
/** derive the {@link LibraryExports} export view of one package version from its blob + metadata */
|
|
149
159
|
function deriveLibraryExports(strings, blob, meta, pkg, version, cranBase = schema_1.DefaultCranBase) {
|
|
150
160
|
const [latest, archived] = meta;
|
|
@@ -162,7 +172,7 @@ function deriveLibraryExports(strings, blob, meta, pkg, version, cranBase = sche
|
|
|
162
172
|
for (const i of idxs) {
|
|
163
173
|
const [nameIdx, , , bits, fileIdx, line] = blob.fns[i];
|
|
164
174
|
const name = strings.at(nameIdx);
|
|
165
|
-
(bits
|
|
175
|
+
(isExportedEntry(bits, name) ? exported : internal).push(name);
|
|
166
176
|
if (bits & 32 /* FnProp.Deprecated */) {
|
|
167
177
|
deprecated.push(name);
|
|
168
178
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PackageSignatureSource } from './reader';
|
|
2
2
|
import type { VersionRelease } from './sigdb-version';
|
|
3
3
|
import type { LibraryExports } from './schema';
|
|
4
|
-
import type { ResolvedDependency } from './decode';
|
|
4
|
+
import type { DecodedFunction, ResolvedDependency } from './decode';
|
|
5
5
|
import { RVersion } from '../../util/r-version';
|
|
6
6
|
/**
|
|
7
7
|
* One package as {@link MemorySignatureSource} carries it: the exports are what attaching it brings, the rest
|
|
@@ -18,6 +18,8 @@ export interface MemoryPackage {
|
|
|
18
18
|
readonly deps?: readonly ResolvedDependency[];
|
|
19
19
|
/** when that version was released, which is what makes it a release rather than a label */
|
|
20
20
|
readonly released?: Date;
|
|
21
|
+
/** the functions the package defines, exported or not, for the per-function view, absent if unknown */
|
|
22
|
+
readonly functions?: readonly DecodedFunction[];
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* A signature source held entirely in memory, for the places that cannot open a database file: a browser
|
|
@@ -39,9 +41,9 @@ export declare class MemorySignatureSource implements PackageSignatureSource {
|
|
|
39
41
|
lookup(pkg: string, version?: string): LibraryExports | undefined;
|
|
40
42
|
packagesExporting(name: string): readonly string[];
|
|
41
43
|
classOwner(className: string, version?: string): string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
functions(): undefined;
|
|
44
|
-
functionByName(): undefined;
|
|
44
|
+
/** the functions a package was given with, the per-function view stays empty for the others */
|
|
45
|
+
functions(pkg: string, version?: string): DecodedFunction[] | undefined;
|
|
46
|
+
functionByName(pkg: string, name: string, version?: string): DecodedFunction | undefined;
|
|
45
47
|
transitiveCallees(): undefined;
|
|
46
48
|
dependencies(pkg: string, version?: string): ResolvedDependency[] | undefined;
|
|
47
49
|
/** an in-memory package states its exports, never its class relations */
|
|
@@ -68,12 +68,13 @@ class MemorySignatureSource {
|
|
|
68
68
|
this.classIndex ??= (0, reader_1.classOwnerIndexFor)(this, this.packageNames());
|
|
69
69
|
return this.classIndex.get(className);
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
72
|
-
functions() {
|
|
73
|
-
|
|
71
|
+
/** the functions a package was given with, the per-function view stays empty for the others */
|
|
72
|
+
functions(pkg, version) {
|
|
73
|
+
const found = this.packages.get(pkg);
|
|
74
|
+
return found?.functions === undefined || !this.answersFor(pkg, version) ? undefined : [...found.functions];
|
|
74
75
|
}
|
|
75
|
-
functionByName() {
|
|
76
|
-
return
|
|
76
|
+
functionByName(pkg, name, version) {
|
|
77
|
+
return this.functions(pkg, version)?.find(f => f.name === name);
|
|
77
78
|
}
|
|
78
79
|
transitiveCallees() {
|
|
79
80
|
return undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FetchBytes } from './remote-sources';
|
|
2
|
+
/** an archive bigger than its source was allowed to be */
|
|
3
|
+
export declare class TooLargeError extends Error {
|
|
4
|
+
constructor(url: string, max: number);
|
|
5
|
+
}
|
|
6
|
+
/** a URL the on-demand fetch refuses: anything but `https`, or a host on the local machine or network */
|
|
7
|
+
export declare class RefusedUrlError extends Error {
|
|
8
|
+
constructor(url: string, why: string);
|
|
9
|
+
}
|
|
10
|
+
/** whether `host` is this machine or an address of a private network, which a redirect must never lead to */
|
|
11
|
+
export declare function isLocalHost(host: string): boolean;
|
|
12
|
+
/** the URL, if the fetch may go there. `trusted` hosts (the mirrors a trusted configuration names) may be local */
|
|
13
|
+
export declare function checkedUrl(url: string, trusted?: ReadonlySet<string>): URL;
|
|
14
|
+
/**
|
|
15
|
+
* {@link FetchBytes} over HTTPS, see {@link checkedUrl}. A 404 (or 410) means the server does not have it.
|
|
16
|
+
* @param trusted - the hosts (with port) that may be local, as a company mirror is
|
|
17
|
+
*/
|
|
18
|
+
export declare function httpsFetcher(trusted?: ReadonlySet<string>): FetchBytes;
|
|
@@ -0,0 +1,127 @@
|
|
|
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.RefusedUrlError = exports.TooLargeError = void 0;
|
|
7
|
+
exports.isLocalHost = isLocalHost;
|
|
8
|
+
exports.checkedUrl = checkedUrl;
|
|
9
|
+
exports.httpsFetcher = httpsFetcher;
|
|
10
|
+
const https_1 = __importDefault(require("https"));
|
|
11
|
+
const net_1 = __importDefault(require("net"));
|
|
12
|
+
const secure_mode_1 = require("../../../util/secure-mode");
|
|
13
|
+
/** an archive bigger than its source was allowed to be */
|
|
14
|
+
class TooLargeError extends Error {
|
|
15
|
+
constructor(url, max) {
|
|
16
|
+
super(`${url} is larger than ${Math.round(max / 1024 / 1024)} MiB`);
|
|
17
|
+
this.name = 'TooLargeError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.TooLargeError = TooLargeError;
|
|
21
|
+
/** a URL the on-demand fetch refuses: anything but `https`, or a host on the local machine or network */
|
|
22
|
+
class RefusedUrlError extends Error {
|
|
23
|
+
constructor(url, why) {
|
|
24
|
+
super(`refusing ${url}: ${why}`);
|
|
25
|
+
this.name = 'RefusedUrlError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.RefusedUrlError = RefusedUrlError;
|
|
29
|
+
/** whether `host` is this machine or an address of a private network, which a redirect must never lead to */
|
|
30
|
+
function isLocalHost(host) {
|
|
31
|
+
const bare = host.replace(/^\[|\]$/g, '').toLowerCase();
|
|
32
|
+
if (bare === 'localhost' || bare.endsWith('.localhost') || bare.endsWith('.local') || bare.endsWith('.internal')) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (net_1.default.isIPv4(bare)) {
|
|
36
|
+
const [a, b] = bare.split('.').map(Number);
|
|
37
|
+
return a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127) || a >= 224;
|
|
38
|
+
}
|
|
39
|
+
if (net_1.default.isIPv6(bare)) {
|
|
40
|
+
return bare === '::' || bare === '::1' || /^(fc|fd|fe8|fe9|fea|feb)/.test(bare) || bare.startsWith('::ffff:');
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
/** the URL, if the fetch may go there. `trusted` hosts (the mirrors a trusted configuration names) may be local */
|
|
45
|
+
function checkedUrl(url, trusted = new Set()) {
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = new URL(url);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new RefusedUrlError(url, 'no URL');
|
|
52
|
+
}
|
|
53
|
+
if (parsed.protocol !== 'https:') {
|
|
54
|
+
throw new RefusedUrlError(url, 'only https is allowed');
|
|
55
|
+
}
|
|
56
|
+
if (parsed.username || parsed.password) {
|
|
57
|
+
throw new RefusedUrlError(url, 'no credentials in URLs');
|
|
58
|
+
}
|
|
59
|
+
if (isLocalHost(parsed.hostname) && !trusted.has(parsed.host)) {
|
|
60
|
+
throw new RefusedUrlError(url, 'a local or private host');
|
|
61
|
+
}
|
|
62
|
+
return parsed;
|
|
63
|
+
}
|
|
64
|
+
const IdleTimeoutMs = 30_000;
|
|
65
|
+
const MaxRedirects = 5;
|
|
66
|
+
function get(url, redirects, trusted) {
|
|
67
|
+
secure_mode_1.SecureMode.guard('network access', url);
|
|
68
|
+
const target = checkedUrl(url, trusted);
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
/* no token or cookie ever goes out: these are public sources */
|
|
71
|
+
const req = https_1.default.get(target, { headers: { 'User-Agent': 'flowr', Accept: '*/*' } }, res => {
|
|
72
|
+
const status = res.statusCode ?? 0;
|
|
73
|
+
if (status >= 300 && status < 400 && res.headers.location) {
|
|
74
|
+
res.resume();
|
|
75
|
+
if (redirects <= 0) {
|
|
76
|
+
reject(new Error(`GET ${url}: too many redirects`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
/* every hop is checked again, so a redirect cannot lead to plain http or into the local network */
|
|
80
|
+
get(new URL(res.headers.location, target).toString(), redirects - 1, trusted).then(resolve, reject);
|
|
81
|
+
}
|
|
82
|
+
else if (status >= 200 && status < 300) {
|
|
83
|
+
resolve(res);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
res.resume();
|
|
87
|
+
if (status === 404 || status === 410) {
|
|
88
|
+
resolve(undefined);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
reject(new Error(`GET ${url} -> HTTP ${status}`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
req.setTimeout(IdleTimeoutMs, () => req.destroy(new Error(`GET ${url} -> no data for ${IdleTimeoutMs / 1000}s`)));
|
|
96
|
+
req.on('error', reject);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* {@link FetchBytes} over HTTPS, see {@link checkedUrl}. A 404 (or 410) means the server does not have it.
|
|
101
|
+
* @param trusted - the hosts (with port) that may be local, as a company mirror is
|
|
102
|
+
*/
|
|
103
|
+
function httpsFetcher(trusted = new Set()) {
|
|
104
|
+
return async (url, maxBytes) => {
|
|
105
|
+
const res = await get(url, MaxRedirects, trusted);
|
|
106
|
+
if (res === undefined) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const announced = Number(res.headers['content-length'] ?? NaN);
|
|
110
|
+
if (announced > maxBytes) {
|
|
111
|
+
res.destroy();
|
|
112
|
+
throw new TooLargeError(url, maxBytes);
|
|
113
|
+
}
|
|
114
|
+
const chunks = [];
|
|
115
|
+
let total = 0;
|
|
116
|
+
for await (const chunk of res) {
|
|
117
|
+
total += chunk.length;
|
|
118
|
+
if (total > maxBytes) {
|
|
119
|
+
res.destroy();
|
|
120
|
+
throw new TooLargeError(url, maxBytes);
|
|
121
|
+
}
|
|
122
|
+
chunks.push(chunk);
|
|
123
|
+
}
|
|
124
|
+
return Buffer.concat(chunks);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type Parser from 'web-tree-sitter';
|
|
2
|
+
import type { DecodedFunction } from '../decode';
|
|
3
|
+
/**
|
|
4
|
+
* What flowR recovers of a package from its sources: the exports its `NAMESPACE` states (an `exportPattern`
|
|
5
|
+
* matched against the names the code defines) and the formals of every function its `R/` files define at the
|
|
6
|
+
* top level. This is what an on-demand signature source serves for a package no database knows.
|
|
7
|
+
*/
|
|
8
|
+
export interface RecoveredPackage {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly version?: string;
|
|
11
|
+
/** where the sources came from, like `github:masurp/ggmirt` */
|
|
12
|
+
readonly origin: string;
|
|
13
|
+
readonly exported: readonly string[];
|
|
14
|
+
readonly s4Classes: readonly string[];
|
|
15
|
+
readonly functions: readonly DecodedFunction[];
|
|
16
|
+
}
|
|
17
|
+
/** The R files of a package source, the way `R CMD build` picks them: `R/*.R` (and `.r`, `.S`, `.s`, `.q`), not the platform subdirectories. */
|
|
18
|
+
export declare function isPackageCodeFile(path: string): boolean;
|
|
19
|
+
/** the files of a package source the recovery reads */
|
|
20
|
+
export declare function isRecoveredFile(path: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Recovers a package from the files of its source (`DESCRIPTION`, `NAMESPACE`, `R/*.R`, paths relative to its
|
|
23
|
+
* root), parsing the code with `parse`. `undefined` if the files are no R package (no `DESCRIPTION` naming one).
|
|
24
|
+
* Without a `NAMESPACE`, as old packages have, every name not starting with a dot is exported, as R does.
|
|
25
|
+
*/
|
|
26
|
+
export declare function recoverPackage(files: ReadonlyMap<string, string>, parse: (code: string) => Parser.Tree, origin: string): RecoveredPackage | undefined;
|
|
27
|
+
/** the most names, functions, and parameters a recovered package may state, so a crafted one cannot bloat the analysis */
|
|
28
|
+
export declare const RecoveredLimits: {
|
|
29
|
+
readonly names: 20000;
|
|
30
|
+
readonly parameters: 256;
|
|
31
|
+
readonly nameLength: 256;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* What of a recovered package (fresh from its sources, or read back from the cache, both of which an attacker
|
|
35
|
+
* may have shaped) flowR is willing to use: package and bindable names only, a version that is one, bounded
|
|
36
|
+
* sizes, and no properties beyond the ones the recovery itself states. Names in `shielded` are dropped from the
|
|
37
|
+
* exports: a package nobody vetted must not take over a call flowR knows to be security relevant, like `system`,
|
|
38
|
+
* which would hide that call from every analysis looking for it. `undefined` for something that is no package.
|
|
39
|
+
*/
|
|
40
|
+
export declare function sanitizeRecovered(value: unknown, shielded?: ReadonlySet<string>): RecoveredPackage | undefined;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecoveredLimits = void 0;
|
|
4
|
+
exports.isPackageCodeFile = isPackageCodeFile;
|
|
5
|
+
exports.isRecoveredFile = isRecoveredFile;
|
|
6
|
+
exports.recoverPackage = recoverPackage;
|
|
7
|
+
exports.sanitizeRecovered = sanitizeRecovered;
|
|
8
|
+
const flowr_file_1 = require("../../context/flowr-file");
|
|
9
|
+
const flowr_description_file_1 = require("../../plugins/file-plugins/files/flowr-description-file");
|
|
10
|
+
const schema_1 = require("../schema");
|
|
11
|
+
const built_in_props_1 = require("../../../dataflow/environments/built-in-props");
|
|
12
|
+
const r_regex_1 = require("../../../util/r-regex");
|
|
13
|
+
const arrays_1 = require("../../../util/collections/arrays");
|
|
14
|
+
const tree_sitter_types_1 = require("../../../r-bridge/lang-4.x/tree-sitter/tree-sitter-types");
|
|
15
|
+
/** The R files of a package source, the way `R CMD build` picks them: `R/*.R` (and `.r`, `.S`, `.s`, `.q`), not the platform subdirectories. */
|
|
16
|
+
function isPackageCodeFile(path) {
|
|
17
|
+
return /^R\/[^/]+\.[RrSsq]$/.test(path);
|
|
18
|
+
}
|
|
19
|
+
/** the files of a package source the recovery reads */
|
|
20
|
+
function isRecoveredFile(path) {
|
|
21
|
+
return path === 'DESCRIPTION' || path === 'NAMESPACE' || isPackageCodeFile(path);
|
|
22
|
+
}
|
|
23
|
+
const AssignLeft = new Set(['<-', '=', '<<-', ':=']);
|
|
24
|
+
const AssignRight = new Set(['->', '->>']);
|
|
25
|
+
/** the name a definition binds, without the quotes or backticks it may be written with */
|
|
26
|
+
function boundName(node) {
|
|
27
|
+
if (node.type === tree_sitter_types_1.TreeSitterType.Identifier) {
|
|
28
|
+
return node.text.startsWith('`') && node.text.endsWith('`') && node.text.length > 1 ? node.text.slice(1, -1) : node.text;
|
|
29
|
+
}
|
|
30
|
+
else if (node.type === tree_sitter_types_1.TreeSitterType.String) {
|
|
31
|
+
return node.childForFieldName('content')?.text ?? '';
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function shortened(text) {
|
|
36
|
+
return text.length > schema_1.MaxDefaultLength ? `${text.slice(0, schema_1.MaxDefaultLength)}…` : text;
|
|
37
|
+
}
|
|
38
|
+
function signatureOf(definition) {
|
|
39
|
+
const parameters = definition.childForFieldName('parameters')?.namedChildren.filter(p => p.type === tree_sitter_types_1.TreeSitterType.Parameter) ?? [];
|
|
40
|
+
return parameters.flatMap(p => {
|
|
41
|
+
const name = p.childForFieldName('name');
|
|
42
|
+
if (name === null) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const value = p.childForFieldName('default');
|
|
46
|
+
const param = name.type === tree_sitter_types_1.TreeSitterType.Dots ? '...' : boundName(name) ?? name.text;
|
|
47
|
+
return [value === null
|
|
48
|
+
? { name: param, props: param === '...' ? 0 : built_in_props_1.ArgProp.NoDefault }
|
|
49
|
+
: { name: param, props: 0, default: shortened(value.text) }];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** the expression within parentheses, `(function(x) x)` is a function as well */
|
|
53
|
+
function unwrapped(node) {
|
|
54
|
+
while (node.type === tree_sitter_types_1.TreeSitterType.ParenthesizedExpression && node.namedChildren.length === 1) {
|
|
55
|
+
node = node.namedChildren[0];
|
|
56
|
+
}
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
/** the name an assignment binds and the value it binds it to, `undefined` for another operator or a target that is no name (`x$a <- 1`) */
|
|
60
|
+
function assignment(node) {
|
|
61
|
+
if (node.type !== tree_sitter_types_1.TreeSitterType.BinaryOperator) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const operator = node.childForFieldName('operator')?.type ?? '';
|
|
65
|
+
const [target, value] = AssignLeft.has(operator) ? [node.childForFieldName('lhs'), node.childForFieldName('rhs')]
|
|
66
|
+
: AssignRight.has(operator) ? [node.childForFieldName('rhs'), node.childForFieldName('lhs')] : [null, null];
|
|
67
|
+
const name = target === null ? undefined : boundName(target);
|
|
68
|
+
return name === undefined || value === null ? undefined : { name, value };
|
|
69
|
+
}
|
|
70
|
+
/** the string a call's first argument is, like the `"show"` of `setGeneric("show", ...)` */
|
|
71
|
+
function firstStringArgument(call) {
|
|
72
|
+
const first = call.childForFieldName('arguments')?.namedChildren.find(a => a.type === tree_sitter_types_1.TreeSitterType.Argument);
|
|
73
|
+
const value = first?.childForFieldName('value');
|
|
74
|
+
return value?.type === tree_sitter_types_1.TreeSitterType.String ? boundName(value) : undefined;
|
|
75
|
+
}
|
|
76
|
+
/** the definitions a top-level expression makes, looking into blocks and branches (`if(getRversion() >= "4.0") f <- ...`) but not into functions */
|
|
77
|
+
function collect(node, file, into, exportedFrom) {
|
|
78
|
+
switch (node.type) {
|
|
79
|
+
case tree_sitter_types_1.TreeSitterType.BinaryOperator: {
|
|
80
|
+
const assigned = assignment(node);
|
|
81
|
+
if (assigned === undefined) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
into.names.push(assigned.name);
|
|
85
|
+
/* `f <- g <- function(x) x` defines both */
|
|
86
|
+
collect(assigned.value, file, into, exportedFrom);
|
|
87
|
+
let value = unwrapped(assigned.value);
|
|
88
|
+
for (let inner = assignment(value); inner !== undefined; inner = assignment(value)) {
|
|
89
|
+
value = unwrapped(inner.value);
|
|
90
|
+
}
|
|
91
|
+
if (value.type === tree_sitter_types_1.TreeSitterType.FunctionDefinition) {
|
|
92
|
+
into.functions.push({ name: assigned.name, file, line: node.startPosition.row + 1, exported: exportedFrom(assigned.name), props: [], signature: signatureOf(value), callees: [] });
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
case tree_sitter_types_1.TreeSitterType.Call: {
|
|
97
|
+
const callee = node.childForFieldName('function')?.text;
|
|
98
|
+
if (callee === 'setGeneric' || callee === 'methods::setGeneric') {
|
|
99
|
+
const name = firstStringArgument(node);
|
|
100
|
+
const definition = node.childForFieldName('arguments')?.namedChildren
|
|
101
|
+
.map(a => a.childForFieldName('value')).find(v => v?.type === tree_sitter_types_1.TreeSitterType.FunctionDefinition);
|
|
102
|
+
if (name !== undefined) {
|
|
103
|
+
into.names.push(name);
|
|
104
|
+
if (definition) {
|
|
105
|
+
into.functions.push({ name, file, line: node.startPosition.row + 1, exported: exportedFrom(name), props: ['generic'], signature: signatureOf(definition), callees: [] });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
case tree_sitter_types_1.TreeSitterType.BracedExpression:
|
|
112
|
+
case tree_sitter_types_1.TreeSitterType.Program:
|
|
113
|
+
for (const child of node.namedChildren) {
|
|
114
|
+
collect(child, file, into, exportedFrom);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
case tree_sitter_types_1.TreeSitterType.IfStatement:
|
|
118
|
+
for (const field of ['consequence', 'alternative']) {
|
|
119
|
+
const branch = node.childForFieldName(field);
|
|
120
|
+
if (branch) {
|
|
121
|
+
collect(branch, file, into, exportedFrom);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
default:
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** the directives of a `NAMESPACE`, read as the R code it is, so a directive spanning lines or a conditional one counts as well */
|
|
130
|
+
function namespaceDirectives(root) {
|
|
131
|
+
const found = { exports: [], patterns: [], classes: [] };
|
|
132
|
+
const visit = (node) => {
|
|
133
|
+
if (node.type === tree_sitter_types_1.TreeSitterType.Call) {
|
|
134
|
+
const args = node.childForFieldName('arguments')?.namedChildren.filter(a => a.type === tree_sitter_types_1.TreeSitterType.Argument && a.childForFieldName('name') === null)
|
|
135
|
+
.flatMap(a => {
|
|
136
|
+
const value = a.childForFieldName('value');
|
|
137
|
+
return value === null ? [] : [boundName(value)].filter(v => v !== undefined);
|
|
138
|
+
}) ?? [];
|
|
139
|
+
const directive = node.childForFieldName('function')?.text;
|
|
140
|
+
const into = directive === 'export' ? found.exports : directive === 'exportPattern' ? found.patterns
|
|
141
|
+
: directive === 'exportClasses' || directive === 'exportClass' ? found.classes : undefined;
|
|
142
|
+
into?.push(...args);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
node.namedChildren.forEach(visit);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
visit(root);
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Recovers a package from the files of its source (`DESCRIPTION`, `NAMESPACE`, `R/*.R`, paths relative to its
|
|
153
|
+
* root), parsing the code with `parse`. `undefined` if the files are no R package (no `DESCRIPTION` naming one).
|
|
154
|
+
* Without a `NAMESPACE`, as old packages have, every name not starting with a dot is exported, as R does.
|
|
155
|
+
*/
|
|
156
|
+
function recoverPackage(files, parse, origin) {
|
|
157
|
+
const descriptionText = files.get('DESCRIPTION');
|
|
158
|
+
if (descriptionText === undefined) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
const description = new flowr_description_file_1.FlowrDescriptionFile(new flowr_file_1.FlowrInlineTextFile('DESCRIPTION', descriptionText));
|
|
162
|
+
const name = description.packageName();
|
|
163
|
+
if (name === undefined || !/^[A-Za-z][A-Za-z0-9.]*$/.test(name)) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
const namespaceText = files.get('NAMESPACE');
|
|
167
|
+
const namespace = namespaceText === undefined ? undefined : namespaceDirectives(parse(namespaceText).rootNode);
|
|
168
|
+
const stated = new Set(namespace?.exports ?? []);
|
|
169
|
+
const patterns = namespace?.patterns.map(r_regex_1.parseRRegexPattern) ?? [];
|
|
170
|
+
const exportedFrom = namespace === undefined ? (n) => !n.startsWith('.') : (n) => stated.has(n) || patterns.some(p => p.test(n));
|
|
171
|
+
const definitions = { names: [], functions: [] };
|
|
172
|
+
/* the collation order decides which of two definitions of one name wins, alphabetical by default */
|
|
173
|
+
const collate = description.collate()?.map(f => `R/${f}`);
|
|
174
|
+
const code = [...files.keys()].filter(isPackageCodeFile).sort();
|
|
175
|
+
const ordered = collate === undefined ? code : (0, arrays_1.uniqueArray)([...collate.filter(f => files.has(f)), ...code]);
|
|
176
|
+
for (const file of ordered) {
|
|
177
|
+
collect(parse(files.get(file) ?? '').rootNode, file, definitions, exportedFrom);
|
|
178
|
+
}
|
|
179
|
+
const latest = new Map(definitions.functions.map(f => [f.name, f]));
|
|
180
|
+
const exported = (0, arrays_1.uniqueArray)([...stated, ...definitions.names.filter(exportedFrom)]);
|
|
181
|
+
return {
|
|
182
|
+
name,
|
|
183
|
+
version: versionField(descriptionText) ?? description.version()?.str,
|
|
184
|
+
origin,
|
|
185
|
+
exported,
|
|
186
|
+
s4Classes: namespace?.classes ?? [],
|
|
187
|
+
functions: [...latest.values()]
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** the `Version` field as written, for one semver cannot read (`1.2-3`) */
|
|
191
|
+
function versionField(description) {
|
|
192
|
+
return /^Version:\s*(\S+)/m.exec(description)?.[1];
|
|
193
|
+
}
|
|
194
|
+
/** the most names, functions, and parameters a recovered package may state, so a crafted one cannot bloat the analysis */
|
|
195
|
+
exports.RecoveredLimits = { names: 20_000, parameters: 256, nameLength: 256 };
|
|
196
|
+
/** whether the code unit is a control character (below space, or DEL) */
|
|
197
|
+
const isControl = (code) => code < 0x20 || code === 0x7f;
|
|
198
|
+
function hasControlChar(text) {
|
|
199
|
+
for (let i = 0; i < text.length; i++) {
|
|
200
|
+
if (isControl(text.charCodeAt(i))) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
function withoutControlChars(text) {
|
|
207
|
+
return Array.from(text, c => isControl(c.charCodeAt(0)) ? ' ' : c).join('');
|
|
208
|
+
}
|
|
209
|
+
/** a name R may bind: not empty, not too long, no control characters, and nothing that names an object prototype */
|
|
210
|
+
function isBindableName(name) {
|
|
211
|
+
return typeof name === 'string' && name.length > 0 && name.length <= exports.RecoveredLimits.nameLength && !hasControlChar(name) && name !== '__proto__';
|
|
212
|
+
}
|
|
213
|
+
function sanitizedParameter(p) {
|
|
214
|
+
const param = p;
|
|
215
|
+
if (typeof param !== 'object' || param === null || !isBindableName(param.name)) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
/* whether a parameter has a default is all the sources say, every other bit is flowR's to state, never a package's */
|
|
219
|
+
const props = typeof param.props === 'number' ? param.props & built_in_props_1.ArgProp.NoDefault : 0;
|
|
220
|
+
const value = typeof param.default === 'string' ? shortened(withoutControlChars(param.default)) : undefined;
|
|
221
|
+
return value === undefined ? { name: param.name, props } : { name: param.name, props, default: value };
|
|
222
|
+
}
|
|
223
|
+
function sanitizedFunction(f) {
|
|
224
|
+
const fn = f;
|
|
225
|
+
if (typeof fn !== 'object' || fn === null || !isBindableName(fn.name) || !Array.isArray(fn.signature)) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
name: fn.name,
|
|
230
|
+
file: typeof fn.file === 'string' && isPackageCodeFile(fn.file) ? fn.file : undefined,
|
|
231
|
+
line: Number.isInteger(fn.line) && fn.line > 0 ? fn.line : 0,
|
|
232
|
+
exported: fn.exported === true,
|
|
233
|
+
props: Array.isArray(fn.props) && fn.props.includes('generic') ? ['generic'] : [],
|
|
234
|
+
signature: fn.signature.slice(0, exports.RecoveredLimits.parameters).map(sanitizedParameter).filter(p => p !== undefined),
|
|
235
|
+
callees: []
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* What of a recovered package (fresh from its sources, or read back from the cache, both of which an attacker
|
|
240
|
+
* may have shaped) flowR is willing to use: package and bindable names only, a version that is one, bounded
|
|
241
|
+
* sizes, and no properties beyond the ones the recovery itself states. Names in `shielded` are dropped from the
|
|
242
|
+
* exports: a package nobody vetted must not take over a call flowR knows to be security relevant, like `system`,
|
|
243
|
+
* which would hide that call from every analysis looking for it. `undefined` for something that is no package.
|
|
244
|
+
*/
|
|
245
|
+
function sanitizeRecovered(value, shielded = new Set()) {
|
|
246
|
+
const pkg = value;
|
|
247
|
+
if (typeof pkg !== 'object' || pkg === null || typeof pkg.name !== 'string' || !/^[A-Za-z][A-Za-z0-9.]*$/.test(pkg.name)
|
|
248
|
+
|| !Array.isArray(pkg.exported) || !Array.isArray(pkg.functions) || !Array.isArray(pkg.s4Classes)) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
const exported = (0, arrays_1.uniqueArray)(pkg.exported.filter(isBindableName).filter(n => !shielded.has(n))).slice(0, exports.RecoveredLimits.names);
|
|
252
|
+
const isExported = new Set(exported);
|
|
253
|
+
return {
|
|
254
|
+
name: pkg.name,
|
|
255
|
+
version: typeof pkg.version === 'string' && /^[0-9][0-9.-]{0,40}$/.test(pkg.version) ? pkg.version : undefined,
|
|
256
|
+
origin: typeof pkg.origin === 'string' && !hasControlChar(pkg.origin) ? pkg.origin.slice(0, 200) : 'unknown',
|
|
257
|
+
exported,
|
|
258
|
+
s4Classes: (0, arrays_1.uniqueArray)(pkg.s4Classes.filter(isBindableName)).slice(0, exports.RecoveredLimits.names),
|
|
259
|
+
functions: pkg.functions.slice(0, exports.RecoveredLimits.names).map(sanitizedFunction).filter(f => f !== undefined)
|
|
260
|
+
.map(f => ({ ...f, exported: f.exported && isExported.has(f.name) }))
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=package-sources.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type Parser from 'web-tree-sitter';
|
|
2
|
+
import type { FlowrConfig } from '../../../config';
|
|
3
|
+
import type { FetchBytes, OnDemandSource, PackageRequest } from './remote-sources';
|
|
4
|
+
import { type RecoveredPackage } from './package-sources';
|
|
5
|
+
export declare const onDemandLog: import("tslog").Logger<import("tslog").ILogObj>;
|
|
6
|
+
/** what `solver.sigdb.onDemand` configures */
|
|
7
|
+
export type OnDemandOptions = NonNullable<FlowrConfig['solver']['sigdb']['onDemand']>;
|
|
8
|
+
/** what a {@link OnDemandRecoverer} works with, injectable so a test needs no network */
|
|
9
|
+
export interface OnDemandRecovererArgs {
|
|
10
|
+
readonly sources: readonly OnDemandSource[];
|
|
11
|
+
readonly fetch: FetchBytes;
|
|
12
|
+
readonly parse: (code: string) => Parser.Tree;
|
|
13
|
+
readonly cacheDir: string;
|
|
14
|
+
readonly now?: () => number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Recovers packages no signature database knows from their sources: asks each {@link OnDemandSource} in turn for
|
|
18
|
+
* archives, reads `DESCRIPTION`, `NAMESPACE`, and `R/` from the first one that holds the package, and caches the
|
|
19
|
+
* result (or that no source had it) as one JSON file per package, so later analyses need no network.
|
|
20
|
+
*/
|
|
21
|
+
export declare class OnDemandRecoverer {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private readonly args;
|
|
24
|
+
private readonly now;
|
|
25
|
+
constructor(options: OnDemandOptions, args: OnDemandRecovererArgs);
|
|
26
|
+
private cacheFile;
|
|
27
|
+
private readEntry;
|
|
28
|
+
private writeEntry;
|
|
29
|
+
/** The package as fetched before, `undefined` if it never was or no source had it. */
|
|
30
|
+
cached(name: string): RecoveredPackage | undefined;
|
|
31
|
+
/** whether the cache answers `request`, with the package or with a recent miss */
|
|
32
|
+
private settled;
|
|
33
|
+
/**
|
|
34
|
+
* Fetches the packages of `requests` the cache does not answer yet, at most `maxPackages` of them, and returns
|
|
35
|
+
* those it recovered. A failing source is logged and the next one tried, so this never throws.
|
|
36
|
+
*/
|
|
37
|
+
recover(requests: readonly PackageRequest[]): Promise<RecoveredPackage[]>;
|
|
38
|
+
private recoverOne;
|
|
39
|
+
private fromArchive;
|
|
40
|
+
}
|