@eagleoutice/flowr 2.15.4 → 2.15.8
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/config.d.ts +2 -0
- package/config.js +3 -1
- package/dataflow/environments/default-builtin-config.d.ts +57 -0
- package/dataflow/environments/default-builtin-config.js +6 -2
- package/dataflow/environments/environment.d.ts +11 -19
- package/dataflow/environments/environment.js +17 -39
- package/dataflow/environments/frame-memory.d.ts +33 -68
- package/dataflow/environments/frame-memory.js +77 -200
- package/dataflow/environments/identifier.d.ts +5 -0
- package/dataflow/environments/resolve-by-name.js +7 -1
- package/dataflow/internal/process/functions/call/argument/make-argument.d.ts +1 -1
- package/dataflow/internal/process/functions/call/argument/make-argument.js +17 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +16 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +12 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +5 -19
- package/dataflow/internal/process/process-named-call.d.ts +2 -2
- package/dataflow/internal/process/process-named-call.js +3 -3
- package/documentation/wiki-setup.js +28 -3
- package/linter/rules/unescaped-arguments.js +43 -3
- package/package.json +1 -1
- package/project/context/flowr-analyzer-files-context.d.ts +2 -2
- package/project/context/flowr-analyzer-files-context.js +3 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -0
- package/project/sigdb/decode.d.ts +5 -4
- package/project/sigdb/decode.js +13 -18
- package/project/sigdb/dict.d.ts +35 -0
- package/project/sigdb/dict.js +97 -0
- package/project/sigdb/hash.d.ts +7 -2
- package/project/sigdb/reader.d.ts +9 -6
- package/project/sigdb/reader.js +40 -28
- package/slicing/static/fingerprint.js +6 -12
- package/util/text/playground-link.d.ts +14 -5
- package/util/text/playground-link.js +32 -8
- package/util/version.js +2 -2
|
@@ -11,6 +11,7 @@ const vertex_1 = require("../../dataflow/graph/vertex");
|
|
|
11
11
|
const identify_link_to_last_call_relation_1 = require("../../queries/catalog/call-context-query/identify-link-to-last-call-relation");
|
|
12
12
|
const input_source_functions_1 = require("../../queries/catalog/input-sources-query/input-source-functions");
|
|
13
13
|
const simple_input_classifier_1 = require("../../queries/catalog/input-sources-query/simple-input-classifier");
|
|
14
|
+
const edge_1 = require("../../dataflow/graph/edge");
|
|
14
15
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
15
16
|
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
16
17
|
const parse_1 = require("../../slicing/criterion/parse");
|
|
@@ -35,6 +36,8 @@ var UnescapedArgumentCategory;
|
|
|
35
36
|
/** Functions generating/running JavaScript code, e.g. `shinyjs::runjs` */
|
|
36
37
|
UnescapedArgumentCategory["JavaScript"] = "javascript";
|
|
37
38
|
})(UnescapedArgumentCategory || (exports.UnescapedArgumentCategory = UnescapedArgumentCategory = {}));
|
|
39
|
+
/** how many vertices {@link readsParameter} may visit before it gives up on finding one */
|
|
40
|
+
const ParameterSearchLimit = 256;
|
|
38
41
|
/** Maximum depth to descent to find unescaped part of argument */
|
|
39
42
|
const MaxDescentDepth = 5;
|
|
40
43
|
/** Input types that are considered to be safe */
|
|
@@ -111,6 +114,36 @@ function mapInputSourceToArgs(call, sources) {
|
|
|
111
114
|
}
|
|
112
115
|
return result;
|
|
113
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether anything `start` reads is a parameter of an enclosing function. What the call sites happen to pass says
|
|
119
|
+
* nothing here: the function escapes its parameter, and it is one call away from being handed anything at all.
|
|
120
|
+
*/
|
|
121
|
+
function readsParameter(graph, start, sanitizers) {
|
|
122
|
+
const seen = new Set([start]);
|
|
123
|
+
const queue = [start];
|
|
124
|
+
while (queue.length > 0) {
|
|
125
|
+
const id = queue.pop();
|
|
126
|
+
if (graph.idMap?.get(id)?.info.role === "param-n" /* RoleInParent.ParameterName */) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
const vertex = graph.getVertex(id);
|
|
130
|
+
/* what a sanitizer hands back is escaped, whatever it read to get there */
|
|
131
|
+
if (vertex_1.FunctionCallVertex.is(vertex) && sanitizers.has(identifier_1.Identifier.getName(vertex.name))) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (seen.size > ParameterSearchLimit) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
for (const [to, edge] of graph.outgoingEdges(id) ?? graph_1.NoEdges) {
|
|
138
|
+
/* only what the value is built from, never the calls it is an argument of */
|
|
139
|
+
if (!seen.has(to) && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Returns)) {
|
|
140
|
+
seen.add(to);
|
|
141
|
+
queue.push(to);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
114
147
|
function isAcceptedInput(source, config) {
|
|
115
148
|
return source.types.every(type => config.acceptedInputs.includes(type));
|
|
116
149
|
}
|
|
@@ -121,6 +154,7 @@ function isCertainlyCritical(source, config) {
|
|
|
121
154
|
* Gets all unescaped sources for the critical target calls of the given category
|
|
122
155
|
*/
|
|
123
156
|
async function getUnescapedSources(category, targets, config, data, graph) {
|
|
157
|
+
const sanitizerNames = new Set((config.categories[category].sanitizers ?? []).map(call => identifier_1.Identifier.getName(call)));
|
|
124
158
|
const sanitizers = (config.categories[category].sanitizers ?? []).map(call => ({ call }));
|
|
125
159
|
const queryConfig = { narrowing: [...(0, input_source_functions_1.narrowingFunctions)(), ...sanitizers] };
|
|
126
160
|
const found = new Map();
|
|
@@ -137,14 +171,20 @@ async function getUnescapedSources(category, targets, config, data, graph) {
|
|
|
137
171
|
}
|
|
138
172
|
for (const [arg, source] of mapInputSourceToArgs(call, classified[parse_1.SlicingCriterion.fromId(entry.call)] ?? [])) {
|
|
139
173
|
const vertex = graph.getVertex(arg);
|
|
140
|
-
|
|
174
|
+
/* a call passing a constant today makes the argument constant, but the function still escapes its
|
|
175
|
+
parameter, and it is one call away from being handed anything */
|
|
176
|
+
const viaParameter = isAcceptedInput(source, config)
|
|
177
|
+
&& source.types.length > 0 && source.types.every(t => t === simple_input_classifier_1.InputType.Constant || t === simple_input_classifier_1.InputType.DerivedConstant)
|
|
178
|
+
&& readsParameter(graph, arg, sanitizerNames);
|
|
179
|
+
if ((entry.only !== undefined && !entry.only.has(arg)) || (isAcceptedInput(source, config) && !viaParameter)) {
|
|
141
180
|
continue;
|
|
142
181
|
}
|
|
143
|
-
else if (entry.depth < config.maxDecentDepth && source.trace === simple_input_classifier_1.InputTraceType.Known && vertex_1.FunctionCallVertex.is(vertex) && !vertex_1.FunctionCallVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access)) {
|
|
182
|
+
else if (entry.depth < config.maxDecentDepth && (source.trace === simple_input_classifier_1.InputTraceType.Known || viaParameter) && vertex_1.FunctionCallVertex.is(vertex) && !vertex_1.FunctionCallVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access)) {
|
|
144
183
|
next.push({ target: entry.target, call: arg, only: undefined, depth: entry.depth + 1 });
|
|
145
184
|
}
|
|
146
185
|
else {
|
|
147
|
-
|
|
186
|
+
const types = viaParameter ? [...source.types, simple_input_classifier_1.InputType.Parameter] : source.types;
|
|
187
|
+
found.set(entry.target, [...(found.get(entry.target) ?? []), { ...source, id: arg, types }]);
|
|
148
188
|
}
|
|
149
189
|
}
|
|
150
190
|
}
|
package/package.json
CHANGED
|
@@ -219,9 +219,9 @@ export declare class FlowrAnalyzerFilesContext extends AbstractFlowrAnalyzerCont
|
|
|
219
219
|
* Add a file to the context. If the file has a special role, it will be added to the corresponding list of special files.
|
|
220
220
|
* This method also applies any registered {@link FlowrAnalyzerFilePlugin}s to the file before adding it to the context.
|
|
221
221
|
*/
|
|
222
|
-
addFile(file: string | FlowrFileProvider | RParseRequestFromFile, roles?: readonly FileRole[]): FlowrFileProvider<{
|
|
222
|
+
addFile(file: string | FlowrFileProvider | RParseRequestFromFile | undefined, roles?: readonly FileRole[]): FlowrFileProvider<{
|
|
223
223
|
toString(): string;
|
|
224
|
-
}
|
|
224
|
+
}> | undefined;
|
|
225
225
|
hasCached(path: string): boolean;
|
|
226
226
|
hasFile(path: string): boolean;
|
|
227
227
|
exists(p: string, ignoreCase: boolean): string | undefined;
|
|
@@ -236,6 +236,9 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
236
236
|
* This method also applies any registered {@link FlowrAnalyzerFilePlugin}s to the file before adding it to the context.
|
|
237
237
|
*/
|
|
238
238
|
addFile(file, roles) {
|
|
239
|
+
if (file === undefined) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
239
242
|
const f = this.fileLoadPlugins(wrapFile(file, roles));
|
|
240
243
|
f.addOnInvalidate(c => {
|
|
241
244
|
this.context.analyzer?.receive(c);
|
package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js
CHANGED
|
@@ -217,6 +217,10 @@ class FlowrAnalyzerPackageVersionsSigDbPlugin extends flowr_analyzer_package_ver
|
|
|
217
217
|
this.resetAssembled(); // reload on (re)registration so config/source changes take effect (shared bundles are reused)
|
|
218
218
|
this.analyzerCtx = ctx;
|
|
219
219
|
if ((0, config_1.isSigDbEnabled)(ctx.config)) {
|
|
220
|
+
const budgetMb = ctx.config.solver.sigdb.blobCacheBudgetMb;
|
|
221
|
+
if (budgetMb !== undefined) {
|
|
222
|
+
(0, reader_1.setBlobCacheBudget)(budgetMb * 1024 * 1024);
|
|
223
|
+
}
|
|
220
224
|
ctx.deps.addLazyResolver((name, existing) => this.resolve(name, existing));
|
|
221
225
|
if (ctx.config.solver.sigdb.warmInBackground) {
|
|
222
226
|
this.startBackgroundWarm();
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* dependency records, and the {@link LibraryExports} export view. Pure -- no I/O, no mutation of inputs.
|
|
4
4
|
* Split out of `../sigdb` so the reader/writer there does not carry the per-record decoding.
|
|
5
5
|
*/
|
|
6
|
+
import type { SigDict } from './dict';
|
|
6
7
|
import { type DepType, type LibraryExports, type PkgBlob, type PkgBlobTuple, type SigClassInfo, type SigDbPkgMeta } from './schema';
|
|
7
8
|
import type { ArgProps } from '../../dataflow/environments/built-in-props';
|
|
8
9
|
/** the CRAN status of a version, used to build (or skip) its source-tarball link */
|
|
@@ -48,7 +49,7 @@ export interface DecodedFunction {
|
|
|
48
49
|
*/
|
|
49
50
|
export declare function transitiveCallees(functions: readonly DecodedFunction[], name: string): string[];
|
|
50
51
|
/** decode one of a blob's function records against the global string dictionary */
|
|
51
|
-
export declare function decodeFunction(strings:
|
|
52
|
+
export declare function decodeFunction(strings: SigDict, blob: Readonly<PkgBlob>, fnIdx: number): DecodedFunction;
|
|
52
53
|
/** a decoded package dependency of one version (`type` is the compact {@link DepType} enum; map to a label via {@link DepTypeNames}) */
|
|
53
54
|
export interface ResolvedDependency {
|
|
54
55
|
readonly name: string;
|
|
@@ -57,10 +58,10 @@ export interface ResolvedDependency {
|
|
|
57
58
|
readonly constraint?: string;
|
|
58
59
|
}
|
|
59
60
|
/** decode the declared dependencies of one blob version (empty when it declares none / the bundle omits them) */
|
|
60
|
-
export declare function decodeDependencies(strings:
|
|
61
|
+
export declare function decodeDependencies(strings: SigDict, blob: Readonly<PkgBlob>, ver: string): ResolvedDependency[];
|
|
61
62
|
/** the classes a package version declares, decoded from the blob's class pool */
|
|
62
|
-
export declare function decodeClasses(strings:
|
|
63
|
+
export declare function decodeClasses(strings: SigDict, blob: Readonly<PkgBlob>, ver: string): SigClassInfo[];
|
|
63
64
|
/** the function indices of a blob version (undoing the delta encoding) */
|
|
64
65
|
export declare function versionFnIndices(blob: Readonly<PkgBlob>, ver: string): number[] | undefined;
|
|
65
66
|
/** derive the {@link LibraryExports} export view of one package version from its blob + metadata */
|
|
66
|
-
export declare function deriveLibraryExports(strings:
|
|
67
|
+
export declare function deriveLibraryExports(strings: SigDict, blob: Readonly<PkgBlob>, meta: SigDbPkgMeta, pkg: string, version?: string, cranBase?: string): LibraryExports | undefined;
|
package/project/sigdb/decode.js
CHANGED
|
@@ -9,11 +9,6 @@ exports.decodeDependencies = decodeDependencies;
|
|
|
9
9
|
exports.decodeClasses = decodeClasses;
|
|
10
10
|
exports.versionFnIndices = versionFnIndices;
|
|
11
11
|
exports.deriveLibraryExports = deriveLibraryExports;
|
|
12
|
-
/**
|
|
13
|
-
* Decoding a {@link PkgBlob} into the reader-facing views: the on-disk tuple form, the decoded function/
|
|
14
|
-
* dependency records, and the {@link LibraryExports} export view. Pure -- no I/O, no mutation of inputs.
|
|
15
|
-
* Split out of `../sigdb` so the reader/writer there does not carry the per-record decoding.
|
|
16
|
-
*/
|
|
17
12
|
const schema_1 = require("./schema");
|
|
18
13
|
const sigdb_version_1 = require("./sigdb-version");
|
|
19
14
|
const objects_1 = require("../../util/objects");
|
|
@@ -82,17 +77,17 @@ function decodeFunction(strings, blob, fnIdx) {
|
|
|
82
77
|
const [nameIdx, sigIdx, cgIdx, bits, fileIdx, line, topicIdx] = blob.fns[fnIdx];
|
|
83
78
|
const signature = (sigIdx >= 0 ? blob.sigs[sigIdx] : []).map(p => {
|
|
84
79
|
const [n, props, def] = Array.isArray(p) ? [p[0], p[1], p.length === 3 ? p[2] : -1] : [p, 0, -1];
|
|
85
|
-
return (0, objects_1.compactRecord)({ name: strings
|
|
80
|
+
return (0, objects_1.compactRecord)({ name: strings.at(n), props, default: def >= 0 ? strings.at(def) : undefined });
|
|
86
81
|
});
|
|
87
82
|
let callees = [];
|
|
88
83
|
if (cgIdx >= 0) {
|
|
89
84
|
let prev = 0;
|
|
90
|
-
callees = blob.cgs[cgIdx].map(d => strings
|
|
85
|
+
callees = blob.cgs[cgIdx].map(d => strings.at(prev += d));
|
|
91
86
|
}
|
|
92
87
|
return (0, objects_1.compactRecord)({
|
|
93
|
-
name: strings
|
|
94
|
-
topic: topicIdx !== undefined && topicIdx >= 0 ? strings
|
|
95
|
-
file: fileIdx >= 0 ? strings
|
|
88
|
+
name: strings.at(nameIdx),
|
|
89
|
+
topic: topicIdx !== undefined && topicIdx >= 0 ? strings.at(topicIdx) : undefined,
|
|
90
|
+
file: fileIdx >= 0 ? strings.at(fileIdx) : undefined,
|
|
96
91
|
line,
|
|
97
92
|
exported: Boolean(bits & 1 /* FnProp.Exported */),
|
|
98
93
|
props: Object.entries(schema_1.FnPropNames).filter(([m]) => bits & Number(m)).map(([, n]) => n),
|
|
@@ -106,7 +101,7 @@ function decodeDependencies(strings, blob, ver) {
|
|
|
106
101
|
if (idx === undefined) {
|
|
107
102
|
return [];
|
|
108
103
|
}
|
|
109
|
-
return blob.deps[idx].map(d => (0, objects_1.compactRecord)({ name: strings
|
|
104
|
+
return blob.deps[idx].map(d => (0, objects_1.compactRecord)({ name: strings.at(d[0]), type: d[1], constraint: d.length === 3 ? strings.at(d[2]) : undefined }));
|
|
110
105
|
}
|
|
111
106
|
/** the classes a package version declares, decoded from the blob's class pool */
|
|
112
107
|
function decodeClasses(strings, blob, ver) {
|
|
@@ -124,15 +119,15 @@ function decodeClasses(strings, blob, ver) {
|
|
|
124
119
|
}
|
|
125
120
|
const [nameIdx, system, props, supers, slots, pkgIdx] = rec;
|
|
126
121
|
out.push((0, objects_1.compactRecord)({
|
|
127
|
-
name: strings
|
|
122
|
+
name: strings.at(nameIdx),
|
|
128
123
|
system: schema_1.SigClassSystemNames[system] ?? schema_1.SigClassSystemNames[0],
|
|
129
|
-
supers: supers.map(i => strings
|
|
124
|
+
supers: supers.map(i => strings.at(i)),
|
|
130
125
|
slots: slots.map((sl) => typeof sl === 'number'
|
|
131
|
-
? { name: strings
|
|
132
|
-
: { name: strings
|
|
126
|
+
? { name: strings.at(sl) }
|
|
127
|
+
: { name: strings.at(sl[0]), type: strings.at(sl[1]) }),
|
|
133
128
|
virtual: props & 1 /* ClassProp.Virtual */ ? true : undefined,
|
|
134
129
|
union: props & 2 /* ClassProp.Union */ ? true : undefined,
|
|
135
|
-
package: pkgIdx !== undefined ? strings
|
|
130
|
+
package: pkgIdx !== undefined ? strings.at(pkgIdx) : undefined
|
|
136
131
|
}));
|
|
137
132
|
}
|
|
138
133
|
return out;
|
|
@@ -166,7 +161,7 @@ function deriveLibraryExports(strings, blob, meta, pkg, version, cranBase = sche
|
|
|
166
161
|
const locations = new Map();
|
|
167
162
|
for (const i of idxs) {
|
|
168
163
|
const [nameIdx, , , bits, fileIdx, line] = blob.fns[i];
|
|
169
|
-
const name = strings
|
|
164
|
+
const name = strings.at(nameIdx);
|
|
170
165
|
(bits & 1 /* FnProp.Exported */ ? exported : internal).push(name);
|
|
171
166
|
if (bits & 32 /* FnProp.Deprecated */) {
|
|
172
167
|
deprecated.push(name);
|
|
@@ -178,7 +173,7 @@ function deriveLibraryExports(strings, blob, meta, pkg, version, cranBase = sche
|
|
|
178
173
|
s4Classes.push(name);
|
|
179
174
|
}
|
|
180
175
|
if (fileIdx >= 0) {
|
|
181
|
-
locations.set(name, { file: strings
|
|
176
|
+
locations.set(name, { file: strings.at(fileIdx), line });
|
|
182
177
|
}
|
|
183
178
|
}
|
|
184
179
|
const cran = !blob.noncran?.includes(ver);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A bundle's string dictionary, held as the bytes of its names rather than as an array of strings.
|
|
3
|
+
* Split apart, a dictionary of 1.4 million names cost a slice object per name and kept the text alive
|
|
4
|
+
* through them anyway; as one buffer it is off the JS heap entirely, which is what a worker's
|
|
5
|
+
* `--max-old-space-size` bounds, and a name is built only when something asks for it.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/** A dictionary's names by id. Ids are positions, so {@link SigDict.at} is what `strings[id]` used to be. */
|
|
9
|
+
export declare class SigDict implements Iterable<string> {
|
|
10
|
+
/** every name in utf8, separated by newlines, so a name never carries one */
|
|
11
|
+
private readonly bytes;
|
|
12
|
+
/** where each name ends in {@link bytes}; the next one starts one past that */
|
|
13
|
+
private readonly ends;
|
|
14
|
+
private constructor();
|
|
15
|
+
/** The dictionary `names` spells out. */
|
|
16
|
+
static of(names: readonly string[]): SigDict;
|
|
17
|
+
/**
|
|
18
|
+
* The dictionary the given runs spell out together, each a newline-joined batch of names starting at the id
|
|
19
|
+
* it names. The runs must cover the ids from `0` without a gap, which is how a bundle writes them.
|
|
20
|
+
*/
|
|
21
|
+
static ofRuns(runs: readonly {
|
|
22
|
+
start: number;
|
|
23
|
+
names: string;
|
|
24
|
+
}[]): SigDict;
|
|
25
|
+
/** how many names it holds */
|
|
26
|
+
get length(): number;
|
|
27
|
+
/** The name with the given id, `''` for an id the dictionary does not hold. */
|
|
28
|
+
at(id: number): string;
|
|
29
|
+
/** The group the name with the given id belongs to, as {@link SigDict.keyOf} groups one in hand. */
|
|
30
|
+
groupOf(id: number): number;
|
|
31
|
+
/** The group `name` would be in, so a lookup only compares the names that could match it. */
|
|
32
|
+
static keyOf(name: string): number;
|
|
33
|
+
private startOf;
|
|
34
|
+
[Symbol.iterator](): Iterator<string>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* A bundle's string dictionary, held as the bytes of its names rather than as an array of strings.
|
|
4
|
+
* Split apart, a dictionary of 1.4 million names cost a slice object per name and kept the text alive
|
|
5
|
+
* through them anyway; as one buffer it is off the JS heap entirely, which is what a worker's
|
|
6
|
+
* `--max-old-space-size` bounds, and a name is built only when something asks for it.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SigDict = void 0;
|
|
11
|
+
/** the number of newline-separated pieces in `text`; `''` is one empty piece */
|
|
12
|
+
function pieces(text) {
|
|
13
|
+
let count = 1;
|
|
14
|
+
for (let at = text.indexOf('\n'); at >= 0; at = text.indexOf('\n', at + 1)) {
|
|
15
|
+
count++;
|
|
16
|
+
}
|
|
17
|
+
return count;
|
|
18
|
+
}
|
|
19
|
+
/** A dictionary's names by id. Ids are positions, so {@link SigDict.at} is what `strings[id]` used to be. */
|
|
20
|
+
class SigDict {
|
|
21
|
+
/** every name in utf8, separated by newlines, so a name never carries one */
|
|
22
|
+
bytes;
|
|
23
|
+
/** where each name ends in {@link bytes}; the next one starts one past that */
|
|
24
|
+
ends;
|
|
25
|
+
constructor(bytes, ends) {
|
|
26
|
+
this.bytes = bytes;
|
|
27
|
+
this.ends = ends;
|
|
28
|
+
}
|
|
29
|
+
/** The dictionary `names` spells out. */
|
|
30
|
+
static of(names) {
|
|
31
|
+
return SigDict.ofRuns(names.length === 0 ? [] : [{ start: 0, names: names.join('\n') }]);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The dictionary the given runs spell out together, each a newline-joined batch of names starting at the id
|
|
35
|
+
* it names. The runs must cover the ids from `0` without a gap, which is how a bundle writes them.
|
|
36
|
+
*/
|
|
37
|
+
static ofRuns(runs) {
|
|
38
|
+
if (runs.length === 0) {
|
|
39
|
+
return new SigDict(Buffer.alloc(0), new Int32Array(0));
|
|
40
|
+
}
|
|
41
|
+
const ordered = [...runs].sort((a, b) => a.start - b.start);
|
|
42
|
+
/* sized in one pass and written in the next, so no run is ever copied twice */
|
|
43
|
+
let size = ordered.length - 1, count = 0;
|
|
44
|
+
for (const run of ordered) {
|
|
45
|
+
size += Buffer.byteLength(run.names, 'utf8');
|
|
46
|
+
count += pieces(run.names);
|
|
47
|
+
}
|
|
48
|
+
const bytes = Buffer.allocUnsafe(size);
|
|
49
|
+
let at = 0;
|
|
50
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
51
|
+
if (i > 0) {
|
|
52
|
+
bytes[at++] = Newline;
|
|
53
|
+
}
|
|
54
|
+
at += bytes.write(ordered[i].names, at, 'utf8');
|
|
55
|
+
}
|
|
56
|
+
const ends = new Int32Array(count);
|
|
57
|
+
for (let i = 0, from = 0; i < ends.length; i++) {
|
|
58
|
+
const newline = bytes.indexOf(Newline, from);
|
|
59
|
+
ends[i] = newline < 0 ? bytes.length : newline;
|
|
60
|
+
from = ends[i] + 1;
|
|
61
|
+
}
|
|
62
|
+
return new SigDict(bytes, ends);
|
|
63
|
+
}
|
|
64
|
+
/** how many names it holds */
|
|
65
|
+
get length() {
|
|
66
|
+
return this.ends.length;
|
|
67
|
+
}
|
|
68
|
+
/** The name with the given id, `''` for an id the dictionary does not hold. */
|
|
69
|
+
at(id) {
|
|
70
|
+
return id < 0 || id >= this.ends.length ? '' : this.bytes.toString('utf8', this.startOf(id), this.ends[id]);
|
|
71
|
+
}
|
|
72
|
+
/** The group the name with the given id belongs to, as {@link SigDict.keyOf} groups one in hand. */
|
|
73
|
+
groupOf(id) {
|
|
74
|
+
const start = this.startOf(id);
|
|
75
|
+
return group(this.ends[id] - start, this.bytes[start]);
|
|
76
|
+
}
|
|
77
|
+
/** The group `name` would be in, so a lookup only compares the names that could match it. */
|
|
78
|
+
static keyOf(name) {
|
|
79
|
+
const bytes = Buffer.from(name, 'utf8');
|
|
80
|
+
return group(bytes.length, bytes[0]);
|
|
81
|
+
}
|
|
82
|
+
startOf(id) {
|
|
83
|
+
return id === 0 ? 0 : this.ends[id - 1] + 1;
|
|
84
|
+
}
|
|
85
|
+
*[Symbol.iterator]() {
|
|
86
|
+
for (let i = 0; i < this.ends.length; i++) {
|
|
87
|
+
yield this.at(i);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.SigDict = SigDict;
|
|
92
|
+
const Newline = 0x0a;
|
|
93
|
+
/** the group a name of that byte length starting with that byte belongs to; the empty name has none of its own */
|
|
94
|
+
function group(size, first) {
|
|
95
|
+
return size === 0 ? 0 : (first << 8) | Math.min(size, 255);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=dict.js.map
|
package/project/sigdb/hash.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { PkgBlob, SigDb } from './schema';
|
|
2
|
+
/** a bundle as it is hashed: the dictionary in any form that names its strings in order */
|
|
3
|
+
type Hashable = Omit<Pick<SigDb, 'strings' | 'blobs' | 'pkgs' | 'meta'>, 'strings'> & {
|
|
4
|
+
strings: Iterable<string>;
|
|
5
|
+
};
|
|
2
6
|
/** run a Hash53 over a stream of chunks (each null-terminated so boundaries can't collide) */
|
|
3
7
|
export declare function hashOf(chunks: Iterable<string>): string;
|
|
4
8
|
/** the self-contained content hash of a whole bundle (dictionary + blobs + routing/metadata) */
|
|
5
|
-
export declare function contentHash(db:
|
|
9
|
+
export declare function contentHash(db: Hashable): string;
|
|
6
10
|
/** stable hash of a shared dictionary */
|
|
7
|
-
export declare function dictionaryHash(strings:
|
|
11
|
+
export declare function dictionaryHash(strings: Iterable<string>): string;
|
|
8
12
|
/** stable hash of one shard's data (its blobs + pkgs map; the dictionary is hashed separately) */
|
|
9
13
|
export declare function shardHash(blobs: readonly PkgBlob[], pkgs: Record<string, number>): string;
|
|
14
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import { type LibraryExports, type PkgBlob, type SigClassInfo, type SigDb, type
|
|
|
3
3
|
import { type VersionRelease } from './sigdb-version';
|
|
4
4
|
import { type SigDbIndex } from './index-format';
|
|
5
5
|
import { type DecodedFunction, type ResolvedDependency } from './decode';
|
|
6
|
+
import { SigDict } from './dict';
|
|
6
7
|
import { type SigDbManifest, type SigDbShardRef } from './manifest';
|
|
7
8
|
/** stream-read a whole bundle into a {@link SigDb} (any size; never one string). Prefer {@link SigDatabase} for partial access. */
|
|
8
9
|
export declare function readSignatureDb(file: string): Promise<SigDb>;
|
|
@@ -131,19 +132,21 @@ export interface SigDbOpenOptions {
|
|
|
131
132
|
/** a caller-supplied index/dictionary for {@link SigDatabase.openSync} (both derived from the source otherwise) */
|
|
132
133
|
export interface OpenSyncOptions {
|
|
133
134
|
index?: SigDbIndex;
|
|
134
|
-
strings?:
|
|
135
|
+
strings?: SigDict;
|
|
135
136
|
}
|
|
136
137
|
/** {@link SigDatabase.openSyncFrom} options: cache settings plus an optional precomputed hash/index/dictionary */
|
|
137
138
|
export interface OpenSyncFromOptions extends SigDbOpenOptions, OpenSyncOptions {
|
|
138
139
|
hash?: string;
|
|
139
140
|
}
|
|
141
|
+
/** Sets how many bytes of decoded blobs all open bundles may hold together (`solver.sigdb.blobCacheBudgetMb`). */
|
|
142
|
+
export declare function setBlobCacheBudget(bytes: number): void;
|
|
140
143
|
/**
|
|
141
144
|
* Fast, partial reader for a single bundle. `open()`/`openSync()` load the string dictionary + `.idx` once, then every
|
|
142
145
|
* query seeks straight to one package blob; `open()` additionally decompresses a `.br`/`.gz` source into a hash-keyed cache.
|
|
143
146
|
*/
|
|
144
147
|
export declare class SigDatabase implements PackageSignatureSource {
|
|
145
148
|
private closed;
|
|
146
|
-
/** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; bounded by {@link
|
|
149
|
+
/** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; bounded by {@link setBlobCacheBudget|the shared budget} */
|
|
147
150
|
private readonly blobCache;
|
|
148
151
|
/** a version's function indices plus its `name -> index` view, keyed by package and version; FIFO-bounded */
|
|
149
152
|
private readonly versionFnCache;
|
|
@@ -155,7 +158,7 @@ export declare class SigDatabase implements PackageSignatureSource {
|
|
|
155
158
|
/** reverse index `S3 class -> owning package`, over every package's latest version; built once (see {@link classOwner}) */
|
|
156
159
|
private classIndex;
|
|
157
160
|
private readonly fd;
|
|
158
|
-
readonly strings:
|
|
161
|
+
readonly strings: SigDict;
|
|
159
162
|
readonly index: SigDbIndex;
|
|
160
163
|
readonly content: SigDbContent | undefined;
|
|
161
164
|
private readonly cranBase;
|
|
@@ -214,7 +217,7 @@ export declare class SigDatabase implements PackageSignatureSource {
|
|
|
214
217
|
/**
|
|
215
218
|
* Resolve a package version to its blob and the function records of that version (the shared prologue of
|
|
216
219
|
* {@link functions}/{@link functionByName}). The blob comes from {@link blob} every time rather than out of
|
|
217
|
-
* {@link versionFnCache}: holding one here would keep it decoded past what {@link
|
|
220
|
+
* {@link versionFnCache}: holding one here would keep it decoded past what {@link setBlobCacheBudget|the shared budget} allows.
|
|
218
221
|
*/
|
|
219
222
|
private versionFns;
|
|
220
223
|
functions(pkg: string, version?: string): DecodedFunction[] | undefined;
|
|
@@ -309,8 +312,8 @@ export declare class SigDatabaseSet implements PackageSignatureSource {
|
|
|
309
312
|
shardStatus(): ShardStatus[];
|
|
310
313
|
/** open (blocking) and return every shard database with its manifest ref, for whole-set verification */
|
|
311
314
|
allShards(): MountedShard[];
|
|
312
|
-
/** load (and cache) a shared dictionary
|
|
313
|
-
sharedDictionary(id: string):
|
|
315
|
+
/** load (and cache) a shared dictionary by id, for verification/inspection */
|
|
316
|
+
sharedDictionary(id: string): SigDict;
|
|
314
317
|
/** the first non-empty result from the shards that can serve `pkg` (in preferred order: current before full) */
|
|
315
318
|
private firstOf;
|
|
316
319
|
lookup(pkg: string, version?: string): LibraryExports | undefined;
|