@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
|
@@ -0,0 +1,122 @@
|
|
|
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.ZstdCodec = exports.BrotliCodec = exports.CompressedExtPattern = exports.CompressedExts = exports.DefaultSigDbCodec = void 0;
|
|
7
|
+
exports.zstdSupported = zstdSupported;
|
|
8
|
+
exports.isCompressedExt = isCompressedExt;
|
|
9
|
+
exports.compressedExtOf = compressedExtOf;
|
|
10
|
+
exports.stripCompressedExt = stripCompressedExt;
|
|
11
|
+
exports.codecFor = codecFor;
|
|
12
|
+
exports.writeCodecs = writeCodecs;
|
|
13
|
+
exports.readableExtsPreferred = readableExtsPreferred;
|
|
14
|
+
exports.createDecompressFor = createDecompressFor;
|
|
15
|
+
exports.decompressSyncFor = decompressSyncFor;
|
|
16
|
+
/**
|
|
17
|
+
* The on-disk compression codec for sigdb bundles. Brotli (`.br`) is always written as a universal fallback
|
|
18
|
+
* (every Node ships it), and zstd (`.zst`, smaller + faster to decompress) is written additionally whenever the
|
|
19
|
+
* running Node exposes it (`node:zlib` zstd, Node 22.15+ / 23.8+). Readers pick the better available variant at
|
|
20
|
+
* runtime -- `.zst` when this Node can decompress it, else the `.br` fallback -- so bundles read on any Node,
|
|
21
|
+
* including the older Node bundled in the VS Code extension host. Only the outer compression changes -- the
|
|
22
|
+
* ranged reads and `.idx` seek logic operate on the decompressed plain NDJSON and are codec-agnostic.
|
|
23
|
+
*/
|
|
24
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
25
|
+
const zstd = node_zlib_1.default;
|
|
26
|
+
/** whether the running Node exposes the `node:zlib` zstd API (Node 22.15+ / 23.8+) */
|
|
27
|
+
function zstdSupported() {
|
|
28
|
+
return typeof zstd.zstdCompressSync === 'function' && typeof zstd.createZstdDecompress === 'function';
|
|
29
|
+
}
|
|
30
|
+
function requireZstd() {
|
|
31
|
+
if (!zstdSupported()) {
|
|
32
|
+
throw new Error('zstd sigdb bundles need Node >= 22.15 (node:zlib zstd support); upgrade Node or use the brotli codec');
|
|
33
|
+
}
|
|
34
|
+
return zstd;
|
|
35
|
+
}
|
|
36
|
+
/** the richer codec, preferred by readers when this Node supports it (writers always additionally emit `.br`) */
|
|
37
|
+
exports.DefaultSigDbCodec = 'zstd';
|
|
38
|
+
/** compressed extensions a reader understands (outer compression only); `.gz` is read-only legacy */
|
|
39
|
+
exports.CompressedExts = ['.br', '.zst', '.gz'];
|
|
40
|
+
/** whether a bundle path is a compressed source that must be decompressed to be seekable */
|
|
41
|
+
function isCompressedExt(file) {
|
|
42
|
+
return exports.CompressedExts.some(e => file.endsWith(e));
|
|
43
|
+
}
|
|
44
|
+
/** the compressed extension of a path, or `undefined` if it is a plain (uncompressed) source */
|
|
45
|
+
function compressedExtOf(file) {
|
|
46
|
+
return exports.CompressedExts.find(e => file.endsWith(e));
|
|
47
|
+
}
|
|
48
|
+
/** strip a trailing compressed extension (`.br`/`.zst`/`.gz`) from a filename, if present */
|
|
49
|
+
function stripCompressedExt(name) {
|
|
50
|
+
const ext = compressedExtOf(name);
|
|
51
|
+
return ext ? name.slice(0, -ext.length) : name;
|
|
52
|
+
}
|
|
53
|
+
/** regex alternation matching an optional trailing compressed extension, e.g. `(?:\.br|\.zst|\.gz)?` */
|
|
54
|
+
exports.CompressedExtPattern = `(?:${exports.CompressedExts.map(e => e.replace(/\./g, '\\.')).join('|')})?`;
|
|
55
|
+
// reading large-window brotli requires opting in; every `.br` flowR writes uses large windows, so this is always safe
|
|
56
|
+
const BrotliDecodeParams = { params: { [node_zlib_1.default.constants.BROTLI_DECODER_PARAM_LARGE_WINDOW]: 1 } };
|
|
57
|
+
function brotliParams(opts) {
|
|
58
|
+
const lgwin = opts.lgwin ?? 30;
|
|
59
|
+
const params = {
|
|
60
|
+
[node_zlib_1.default.constants.BROTLI_PARAM_QUALITY]: opts.level ?? 11,
|
|
61
|
+
[node_zlib_1.default.constants.BROTLI_PARAM_LGWIN]: lgwin,
|
|
62
|
+
[node_zlib_1.default.constants.BROTLI_PARAM_LARGE_WINDOW]: lgwin > 24 ? 1 : 0
|
|
63
|
+
};
|
|
64
|
+
if (opts.sizeHint !== undefined) {
|
|
65
|
+
params[node_zlib_1.default.constants.BROTLI_PARAM_SIZE_HINT] = opts.sizeHint;
|
|
66
|
+
}
|
|
67
|
+
return params;
|
|
68
|
+
}
|
|
69
|
+
function zstdParams(opts) {
|
|
70
|
+
return { [zstd.constants.ZSTD_c_compressionLevel]: opts.level ?? 19 };
|
|
71
|
+
}
|
|
72
|
+
exports.BrotliCodec = {
|
|
73
|
+
codec: 'brotli',
|
|
74
|
+
ext: '.br',
|
|
75
|
+
compressSync: (buf, opts = {}) => node_zlib_1.default.brotliCompressSync(buf, { params: brotliParams(opts) }),
|
|
76
|
+
createCompress: (opts = {}) => node_zlib_1.default.createBrotliCompress({ params: brotliParams(opts) })
|
|
77
|
+
};
|
|
78
|
+
exports.ZstdCodec = {
|
|
79
|
+
codec: 'zstd',
|
|
80
|
+
ext: '.zst',
|
|
81
|
+
compressSync: (buf, opts = {}) => requireZstd().zstdCompressSync(buf, { params: zstdParams(opts) }),
|
|
82
|
+
createCompress: (opts = {}) => requireZstd().createZstdCompress({ params: zstdParams(opts) })
|
|
83
|
+
};
|
|
84
|
+
/** the codec spec for a codec name (used when writing) */
|
|
85
|
+
function codecFor(codec) {
|
|
86
|
+
return codec === 'zstd' ? exports.ZstdCodec : exports.BrotliCodec;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The codec specs a writer emits: brotli `.br` always (the universal fallback -- every Node ships it), plus
|
|
90
|
+
* zstd `.zst` when this Node can produce/read it. So a `.br` fallback is guaranteed next to every `.zst`.
|
|
91
|
+
*/
|
|
92
|
+
function writeCodecs() {
|
|
93
|
+
return zstdSupported() ? [exports.BrotliCodec, exports.ZstdCodec] : [exports.BrotliCodec];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Compressed extensions this runtime can actually decompress, most-preferred first (zstd before brotli when
|
|
97
|
+
* supported). `.zst` is omitted entirely when this Node lacks zstd, so a reader never picks a variant it cannot read.
|
|
98
|
+
*/
|
|
99
|
+
function readableExtsPreferred() {
|
|
100
|
+
return zstdSupported() ? ['.zst', '.br', '.gz'] : ['.br', '.gz'];
|
|
101
|
+
}
|
|
102
|
+
/** a streaming decompressor for a compressed source, chosen by its extension (`.zst`/`.gz`/`.br`) */
|
|
103
|
+
function createDecompressFor(file) {
|
|
104
|
+
if (file.endsWith('.zst')) {
|
|
105
|
+
return requireZstd().createZstdDecompress();
|
|
106
|
+
}
|
|
107
|
+
if (file.endsWith('.gz')) {
|
|
108
|
+
return node_zlib_1.default.createGunzip();
|
|
109
|
+
}
|
|
110
|
+
return node_zlib_1.default.createBrotliDecompress(BrotliDecodeParams);
|
|
111
|
+
}
|
|
112
|
+
/** synchronously decompress a compressed buffer, choosing the codec by the source's extension */
|
|
113
|
+
function decompressSyncFor(file, raw) {
|
|
114
|
+
if (file.endsWith('.zst')) {
|
|
115
|
+
return requireZstd().zstdDecompressSync(raw);
|
|
116
|
+
}
|
|
117
|
+
if (file.endsWith('.gz')) {
|
|
118
|
+
return node_zlib_1.default.gunzipSync(raw);
|
|
119
|
+
}
|
|
120
|
+
return node_zlib_1.default.brotliDecompressSync(raw, BrotliDecodeParams);
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decoding a {@link PkgBlob} into the reader-facing views: the on-disk tuple form, the decoded function/
|
|
3
|
+
* dependency records, and the {@link LibraryExports} export view. Pure -- no I/O, no mutation of inputs.
|
|
4
|
+
* Split out of `../sigdb` so the reader/writer there does not carry the per-record decoding.
|
|
5
|
+
*/
|
|
6
|
+
import { type DepType, type LibraryExports, type PkgBlob, type PkgBlobTuple, type SigDbPkgMeta } from './schema';
|
|
7
|
+
/** the CRAN status of a version, used to build (or skip) its source-tarball link */
|
|
8
|
+
export interface CranBlobInfo {
|
|
9
|
+
readonly latest: string;
|
|
10
|
+
readonly archived: boolean;
|
|
11
|
+
readonly cran: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reconstruct the CRAN source blob link which is the newest non-archived version lives under `src/contrib`,
|
|
15
|
+
* every other under `Archive`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function cranBlobUrl(cranBase: string, pkg: string, version: string, opts: CranBlobInfo): string | undefined;
|
|
18
|
+
/** a {@link PkgBlob} in its compact on-disk tuple form (drops the trailing `dates` when empty) */
|
|
19
|
+
export declare const blobTuple: (b: Readonly<PkgBlob>) => PkgBlobTuple;
|
|
20
|
+
/** the inverse of {@link blobTuple}: rebuild a {@link PkgBlob} from its on-disk tuple */
|
|
21
|
+
export declare function tupleToBlob(t: PkgBlobTuple): PkgBlob;
|
|
22
|
+
/** one decoded parameter of a function signature */
|
|
23
|
+
export interface SigParameter {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly forced: boolean;
|
|
26
|
+
readonly optional: boolean;
|
|
27
|
+
readonly default?: string;
|
|
28
|
+
}
|
|
29
|
+
/** the decoded view of one function at one package version */
|
|
30
|
+
export interface DecodedFunction {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly file?: string;
|
|
33
|
+
readonly line: number;
|
|
34
|
+
readonly exported: boolean;
|
|
35
|
+
readonly props: readonly string[];
|
|
36
|
+
readonly signature: readonly SigParameter[];
|
|
37
|
+
readonly callees: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The formal parameter names of a known signature, ready for `RFunctionCall.matchArgumentsToParameters`: the
|
|
41
|
+
* `...` parameter is excluded so partial (`pmatch`) matches against the remaining names stay unambiguous.
|
|
42
|
+
*/
|
|
43
|
+
export declare function signatureParameterNames(signature: readonly SigParameter[]): string[];
|
|
44
|
+
/** decode one of a blob's function records against the global string dictionary */
|
|
45
|
+
export declare function decodeFunction(strings: readonly string[], blob: Readonly<PkgBlob>, fnIdx: number): DecodedFunction;
|
|
46
|
+
/** a decoded package dependency of one version (`type` is the compact {@link DepType} enum; map to a label via {@link DepTypeNames}) */
|
|
47
|
+
export interface ResolvedDependency {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly type: DepType;
|
|
50
|
+
/** version qualifier as declared in DESCRIPTION, e.g. `>= 3.0.0` (absent = any version) */
|
|
51
|
+
readonly constraint?: string;
|
|
52
|
+
}
|
|
53
|
+
/** decode the declared dependencies of one blob version (empty when it declares none / the bundle omits them) */
|
|
54
|
+
export declare function decodeDependencies(strings: readonly string[], blob: Readonly<PkgBlob>, ver: string): ResolvedDependency[];
|
|
55
|
+
/** the function indices of a blob version (undoing the delta encoding) */
|
|
56
|
+
export declare function versionFnIndices(blob: Readonly<PkgBlob>, ver: string): number[] | undefined;
|
|
57
|
+
/** derive the {@link LibraryExports} export view of one package version from its blob + metadata */
|
|
58
|
+
export declare function deriveLibraryExports(strings: readonly string[], blob: Readonly<PkgBlob>, meta: SigDbPkgMeta, pkg: string, version?: string, cranBase?: string): LibraryExports | undefined;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blobTuple = void 0;
|
|
4
|
+
exports.cranBlobUrl = cranBlobUrl;
|
|
5
|
+
exports.tupleToBlob = tupleToBlob;
|
|
6
|
+
exports.signatureParameterNames = signatureParameterNames;
|
|
7
|
+
exports.decodeFunction = decodeFunction;
|
|
8
|
+
exports.decodeDependencies = decodeDependencies;
|
|
9
|
+
exports.versionFnIndices = versionFnIndices;
|
|
10
|
+
exports.deriveLibraryExports = deriveLibraryExports;
|
|
11
|
+
/**
|
|
12
|
+
* Decoding a {@link PkgBlob} into the reader-facing views: the on-disk tuple form, the decoded function/
|
|
13
|
+
* dependency records, and the {@link LibraryExports} export view. Pure -- no I/O, no mutation of inputs.
|
|
14
|
+
* Split out of `../sigdb` so the reader/writer there does not carry the per-record decoding.
|
|
15
|
+
*/
|
|
16
|
+
const schema_1 = require("./schema");
|
|
17
|
+
const version_1 = require("./version");
|
|
18
|
+
/**
|
|
19
|
+
* Reconstruct the CRAN source blob link which is the newest non-archived version lives under `src/contrib`,
|
|
20
|
+
* every other under `Archive`.
|
|
21
|
+
*/
|
|
22
|
+
function cranBlobUrl(cranBase, pkg, version, opts) {
|
|
23
|
+
if (!opts.cran) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const base = cranBase.endsWith('/') ? cranBase : cranBase + '/';
|
|
27
|
+
return version === opts.latest && !opts.archived
|
|
28
|
+
? `${base}${pkg}_${version}.tar.gz`
|
|
29
|
+
: `${base}Archive/${pkg}/${pkg}_${version}.tar.gz`;
|
|
30
|
+
}
|
|
31
|
+
/** a {@link PkgBlob} in its compact on-disk tuple form (drops the trailing `dates` when empty) */
|
|
32
|
+
const blobTuple = (b) => Object.keys(b.dates).length > 0
|
|
33
|
+
? [b.sigs, b.cgs, b.fns, b.versions, b.noncran ?? [], b.deps, b.depsByVersion, b.dates]
|
|
34
|
+
: [b.sigs, b.cgs, b.fns, b.versions, b.noncran ?? [], b.deps, b.depsByVersion];
|
|
35
|
+
exports.blobTuple = blobTuple;
|
|
36
|
+
/** the inverse of {@link blobTuple}: rebuild a {@link PkgBlob} from its on-disk tuple */
|
|
37
|
+
function tupleToBlob(t) {
|
|
38
|
+
return { sigs: t[0], cgs: t[1], fns: t[2], versions: t[3], noncran: t[4]?.length ? t[4] : undefined, deps: t[5] ?? [], depsByVersion: t[6] ?? {}, dates: t[7] ?? {} };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The formal parameter names of a known signature, ready for `RFunctionCall.matchArgumentsToParameters`: the
|
|
42
|
+
* `...` parameter is excluded so partial (`pmatch`) matches against the remaining names stay unambiguous.
|
|
43
|
+
*/
|
|
44
|
+
function signatureParameterNames(signature) {
|
|
45
|
+
return signature.map(p => p.name).filter(n => n !== '...');
|
|
46
|
+
}
|
|
47
|
+
/** decode one of a blob's function records against the global string dictionary */
|
|
48
|
+
function decodeFunction(strings, blob, fnIdx) {
|
|
49
|
+
const [nameIdx, sigIdx, cgIdx, bits, fileIdx, line] = blob.fns[fnIdx];
|
|
50
|
+
const signature = (sigIdx >= 0 ? blob.sigs[sigIdx] : []).map(p => {
|
|
51
|
+
const [n, flags, def] = Array.isArray(p) ? [p[0], p[1], p.length === 3 ? p[2] : -1] : [p, 0, -1];
|
|
52
|
+
return {
|
|
53
|
+
name: strings[n],
|
|
54
|
+
forced: Boolean(flags & 1 /* ParamFlag.Forced */),
|
|
55
|
+
optional: !(flags & 2 /* ParamFlag.Missing */),
|
|
56
|
+
...(def >= 0 ? { default: strings[def] } : {})
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
let callees = [];
|
|
60
|
+
if (cgIdx >= 0) {
|
|
61
|
+
let prev = 0;
|
|
62
|
+
callees = blob.cgs[cgIdx].map(d => strings[prev += d]);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
name: strings[nameIdx],
|
|
66
|
+
...(fileIdx >= 0 ? { file: strings[fileIdx] } : {}),
|
|
67
|
+
line,
|
|
68
|
+
exported: Boolean(bits & 1 /* FnProp.Exported */),
|
|
69
|
+
props: Object.entries(schema_1.FnPropNames).filter(([m]) => bits & Number(m)).map(([, n]) => n),
|
|
70
|
+
signature,
|
|
71
|
+
callees
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** decode the declared dependencies of one blob version (empty when it declares none / the bundle omits them) */
|
|
75
|
+
function decodeDependencies(strings, blob, ver) {
|
|
76
|
+
const idx = blob.depsByVersion[ver];
|
|
77
|
+
if (idx === undefined) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return blob.deps[idx].map(d => ({
|
|
81
|
+
name: strings[d[0]],
|
|
82
|
+
type: d[1],
|
|
83
|
+
...(d.length === 3 ? { constraint: strings[d[2]] } : {})
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
/** the function indices of a blob version (undoing the delta encoding) */
|
|
87
|
+
function versionFnIndices(blob, ver) {
|
|
88
|
+
const list = blob.versions[ver];
|
|
89
|
+
if (list === undefined) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const out = [];
|
|
93
|
+
let prev = 0;
|
|
94
|
+
for (const d of list) {
|
|
95
|
+
out.push(prev += d);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/** derive the {@link LibraryExports} export view of one package version from its blob + metadata */
|
|
100
|
+
function deriveLibraryExports(strings, blob, meta, pkg, version, cranBase = schema_1.DefaultCranBase) {
|
|
101
|
+
const [latest, archived] = meta;
|
|
102
|
+
const ver = (0, version_1.resolveVersion)(blob, latest, version);
|
|
103
|
+
if (ver === undefined) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const idxs = versionFnIndices(blob, ver) ?? [];
|
|
107
|
+
const exported = [];
|
|
108
|
+
const internal = [];
|
|
109
|
+
const deprecated = [];
|
|
110
|
+
const locations = new Map();
|
|
111
|
+
for (const i of idxs) {
|
|
112
|
+
const [nameIdx, , , bits, fileIdx, line] = blob.fns[i];
|
|
113
|
+
const name = strings[nameIdx];
|
|
114
|
+
(bits & 1 /* FnProp.Exported */ ? exported : internal).push(name);
|
|
115
|
+
if (bits & 32 /* FnProp.Deprecated */) {
|
|
116
|
+
deprecated.push(name);
|
|
117
|
+
}
|
|
118
|
+
if (fileIdx >= 0) {
|
|
119
|
+
locations.set(name, { file: strings[fileIdx], line });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const cran = !blob.noncran?.includes(ver);
|
|
123
|
+
return {
|
|
124
|
+
version: ver, exported, internal, deprecated, cran,
|
|
125
|
+
cranUrl: cranBlobUrl(cranBase, pkg, ver, { latest, archived: archived === 1, cran }),
|
|
126
|
+
...(locations.size > 0 ? { locations } : {})
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import { type SigDbIndex } from './index-format';
|
|
3
|
+
/** whether a bundle path is a compressed (`.br`/`.zst`/`.gz`) source that must be decompressed to be seekable */
|
|
4
|
+
export declare const isCompressed: (f: string) => boolean;
|
|
5
|
+
/** read and parse the header (line 1) from a buffer/string of NDJSON */
|
|
6
|
+
export declare function parseHeader(text: string): Record<string, unknown> | undefined;
|
|
7
|
+
/** a readable stream of the bundle's plain NDJSON, transparently decompressing `.gz`/`.br`/`.zst` inputs */
|
|
8
|
+
export declare function sigDbStream(file: string): Readable;
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a manifest-relative file to the best source this runtime can read: a plain (already seekable) file
|
|
11
|
+
* if present, else the most-preferred compressed variant that exists AND is decompressible here -- `.zst` first
|
|
12
|
+
* when this Node supports zstd, otherwise `.br` (then `.gz`). A `.zst` is never returned on a Node without zstd
|
|
13
|
+
* (it could not be decompressed), so `.br`-only bundles read on any Node. Falls back to the plain path.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveSource(baseDir: string, relPath: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Directory for decompressed, hash-keyed caches. Honours `$FLOWR_SIGDB_CACHE` / `$FLOWR_CACHE_DIR`, then the
|
|
18
|
+
* platform cache home (`$XDG_CACHE_HOME` on Linux, `%LOCALAPPDATA%` on Windows), then `~/.cache/flowr`, falling
|
|
19
|
+
* back to the OS temp dir (so it works in a read-only Docker image where only `/tmp` is writable -- mount a
|
|
20
|
+
* volume at the cache dir to persist it).
|
|
21
|
+
*/
|
|
22
|
+
export declare function sigDbCacheDir(override?: string): string;
|
|
23
|
+
/** read the (small) header line of a possibly-compressed bundle without decompressing the whole thing */
|
|
24
|
+
export declare function readHeaderOf(source: string): Promise<Record<string, unknown> | undefined>;
|
|
25
|
+
/** where an index for a decompressed source comes from -- a caller-supplied one (e.g. a manifest) or the sibling `.idx` */
|
|
26
|
+
export interface EnsureOptions {
|
|
27
|
+
cacheDir?: string;
|
|
28
|
+
hash?: string;
|
|
29
|
+
index?: SigDbIndex;
|
|
30
|
+
/** the source is not a seekable bundle (e.g. a shared dictionary file) -- decompress only, write no `.idx` */
|
|
31
|
+
indexless?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Ensure a seekable plain `.sigs.ndjson` (+ its `.idx`) exists for `source`, decompressing a `.br`/`.zst`/`.gz`
|
|
35
|
+
* once into a hash-keyed cache the first time and reusing it on every later startup. The index may be
|
|
36
|
+
* supplied by the caller (e.g. embedded in a manifest) so no separate `.idx` file needs to ship.
|
|
37
|
+
*/
|
|
38
|
+
export declare function ensurePlain(source: string, opts?: EnsureOptions): Promise<string>;
|
|
39
|
+
/** synchronous {@link ensurePlain} (blocking decompression) -- a `hash` must be supplied to key the cache */
|
|
40
|
+
export interface EnsurePlainSyncOptions extends EnsureOptions {
|
|
41
|
+
hash: string;
|
|
42
|
+
}
|
|
43
|
+
/** synchronous {@link ensurePlain} (blocking decompression); the supplied `hash` keys the decompress cache */
|
|
44
|
+
export declare function ensurePlainSync(source: string, opts: EnsurePlainSyncOptions): string;
|
|
@@ -0,0 +1,176 @@
|
|
|
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.isCompressed = void 0;
|
|
7
|
+
exports.parseHeader = parseHeader;
|
|
8
|
+
exports.sigDbStream = sigDbStream;
|
|
9
|
+
exports.resolveSource = resolveSource;
|
|
10
|
+
exports.sigDbCacheDir = sigDbCacheDir;
|
|
11
|
+
exports.readHeaderOf = readHeaderOf;
|
|
12
|
+
exports.ensurePlain = ensurePlain;
|
|
13
|
+
exports.ensurePlainSync = ensurePlainSync;
|
|
14
|
+
/**
|
|
15
|
+
* On-disk (de)compression + the hash-keyed decompress cache: turn a `.br`/`.zst`/`.gz` bundle into a seekable
|
|
16
|
+
* plain `.sigs.ndjson` (materialized once, reused on later startups), read a bundle's header cheaply, and resolve
|
|
17
|
+
* the cache directory. Split out of `../sigdb` so the reader there only consumes plain, seekable files. The codec
|
|
18
|
+
* is detected by extension (see `./codec`), so existing `.br` and new `.zst` bundles read transparently.
|
|
19
|
+
*/
|
|
20
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
21
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
22
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
23
|
+
const node_readline_1 = __importDefault(require("node:readline"));
|
|
24
|
+
const promises_1 = require("node:stream/promises");
|
|
25
|
+
const schema_1 = require("./schema");
|
|
26
|
+
const index_format_1 = require("./index-format");
|
|
27
|
+
const hash_1 = require("../../util/hash");
|
|
28
|
+
const codec_1 = require("./codec");
|
|
29
|
+
/** whether a bundle path is a compressed (`.br`/`.zst`/`.gz`) source that must be decompressed to be seekable */
|
|
30
|
+
const isCompressed = (f) => (0, codec_1.isCompressedExt)(f);
|
|
31
|
+
exports.isCompressed = isCompressed;
|
|
32
|
+
/** read and parse the header (line 1) from a buffer/string of NDJSON */
|
|
33
|
+
function parseHeader(text) {
|
|
34
|
+
const nl = text.indexOf('\n');
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(nl >= 0 ? text.slice(0, nl) : text);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function decompressStream(file) {
|
|
43
|
+
return node_fs_1.default.createReadStream(file).pipe((0, codec_1.createDecompressFor)(file));
|
|
44
|
+
}
|
|
45
|
+
/** a readable stream of the bundle's plain NDJSON, transparently decompressing `.gz`/`.br`/`.zst` inputs */
|
|
46
|
+
function sigDbStream(file) {
|
|
47
|
+
return (0, exports.isCompressed)(file) ? decompressStream(file) : node_fs_1.default.createReadStream(file);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a manifest-relative file to the best source this runtime can read: a plain (already seekable) file
|
|
51
|
+
* if present, else the most-preferred compressed variant that exists AND is decompressible here -- `.zst` first
|
|
52
|
+
* when this Node supports zstd, otherwise `.br` (then `.gz`). A `.zst` is never returned on a Node without zstd
|
|
53
|
+
* (it could not be decompressed), so `.br`-only bundles read on any Node. Falls back to the plain path.
|
|
54
|
+
*/
|
|
55
|
+
function resolveSource(baseDir, relPath) {
|
|
56
|
+
const plain = node_path_1.default.resolve(baseDir, relPath);
|
|
57
|
+
if (node_fs_1.default.existsSync(plain)) {
|
|
58
|
+
return plain;
|
|
59
|
+
}
|
|
60
|
+
for (const ext of (0, codec_1.readableExtsPreferred)()) {
|
|
61
|
+
const compressed = `${plain}${ext}`;
|
|
62
|
+
if (node_fs_1.default.existsSync(compressed)) {
|
|
63
|
+
return compressed;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return plain;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Directory for decompressed, hash-keyed caches. Honours `$FLOWR_SIGDB_CACHE` / `$FLOWR_CACHE_DIR`, then the
|
|
70
|
+
* platform cache home (`$XDG_CACHE_HOME` on Linux, `%LOCALAPPDATA%` on Windows), then `~/.cache/flowr`, falling
|
|
71
|
+
* back to the OS temp dir (so it works in a read-only Docker image where only `/tmp` is writable -- mount a
|
|
72
|
+
* volume at the cache dir to persist it).
|
|
73
|
+
*/
|
|
74
|
+
function sigDbCacheDir(override) {
|
|
75
|
+
const base = override
|
|
76
|
+
?? process.env.FLOWR_SIGDB_CACHE ?? process.env.FLOWR_CACHE_DIR
|
|
77
|
+
?? (process.env.XDG_CACHE_HOME ? node_path_1.default.join(process.env.XDG_CACHE_HOME, 'flowr') : undefined)
|
|
78
|
+
?? (process.env.LOCALAPPDATA ? node_path_1.default.join(process.env.LOCALAPPDATA, 'flowr', 'cache') : undefined)
|
|
79
|
+
?? node_path_1.default.join(node_os_1.default.homedir?.() || node_os_1.default.tmpdir(), '.cache', 'flowr');
|
|
80
|
+
const dir = node_path_1.default.join(base, 'sigdb');
|
|
81
|
+
try {
|
|
82
|
+
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
83
|
+
return dir;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
const tmp = node_path_1.default.join(node_os_1.default.tmpdir(), 'flowr-sigdb-cache');
|
|
87
|
+
node_fs_1.default.mkdirSync(tmp, { recursive: true });
|
|
88
|
+
return tmp;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** read the (small) header line of a possibly-compressed bundle without decompressing the whole thing */
|
|
92
|
+
async function readHeaderOf(source) {
|
|
93
|
+
if (!(0, exports.isCompressed)(source)) {
|
|
94
|
+
const fd = node_fs_1.default.openSync(source, 'r');
|
|
95
|
+
try {
|
|
96
|
+
const buf = Buffer.allocUnsafe(65536);
|
|
97
|
+
const n = node_fs_1.default.readSync(fd, buf, 0, buf.length, 0);
|
|
98
|
+
return parseHeader(buf.toString('utf8', 0, n));
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
node_fs_1.default.closeSync(fd);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const input = decompressStream(source);
|
|
105
|
+
const rl = node_readline_1.default.createInterface({ input, crlfDelay: Infinity });
|
|
106
|
+
try {
|
|
107
|
+
const line = (await rl[Symbol.asyncIterator]().next()).value; // just the first line (the header)
|
|
108
|
+
return line !== undefined ? JSON.parse(line) : undefined;
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
rl.close();
|
|
112
|
+
input.destroy();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function cachePaths(hash, cacheDir) {
|
|
116
|
+
const plain = node_path_1.default.join(sigDbCacheDir(cacheDir), `sigdb-${hash}${schema_1.SigDbExt}`);
|
|
117
|
+
return { plain, idx: `${plain}.idx` };
|
|
118
|
+
}
|
|
119
|
+
/** materialize the `.idx` for a freshly decompressed cache file -- from the supplied index or the source's sibling */
|
|
120
|
+
function writeCacheIndex(source, idx, index) {
|
|
121
|
+
if (index) {
|
|
122
|
+
node_fs_1.default.writeFileSync(idx, JSON.stringify((0, index_format_1.encodeIndex)(index)));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const srcIdx = source.replace(/\.(br|zst|gz)$/, '') + '.idx';
|
|
126
|
+
if (!node_fs_1.default.existsSync(srcIdx)) {
|
|
127
|
+
throw new Error(`missing sidecar index next to ${source} (expected ${srcIdx}), and none was supplied`);
|
|
128
|
+
}
|
|
129
|
+
node_fs_1.default.copyFileSync(srcIdx, idx);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Ensure a seekable plain `.sigs.ndjson` (+ its `.idx`) exists for `source`, decompressing a `.br`/`.zst`/`.gz`
|
|
133
|
+
* once into a hash-keyed cache the first time and reusing it on every later startup. The index may be
|
|
134
|
+
* supplied by the caller (e.g. embedded in a manifest) so no separate `.idx` file needs to ship.
|
|
135
|
+
*/
|
|
136
|
+
async function ensurePlain(source, opts = {}) {
|
|
137
|
+
if (!(0, exports.isCompressed)(source)) {
|
|
138
|
+
return source;
|
|
139
|
+
}
|
|
140
|
+
let hash = opts.hash;
|
|
141
|
+
if (hash === undefined) {
|
|
142
|
+
const content = (await readHeaderOf(source))?.content;
|
|
143
|
+
hash = content?.hash ?? new hash_1.Hash53().update(source).digest();
|
|
144
|
+
}
|
|
145
|
+
const { plain, idx } = cachePaths(hash, opts.cacheDir);
|
|
146
|
+
if (node_fs_1.default.existsSync(plain) && (opts.indexless || node_fs_1.default.existsSync(idx))) {
|
|
147
|
+
return plain;
|
|
148
|
+
}
|
|
149
|
+
const tmp = `${plain}.${process.pid}.tmp`;
|
|
150
|
+
await (0, promises_1.pipeline)(decompressStream(source), node_fs_1.default.createWriteStream(tmp));
|
|
151
|
+
node_fs_1.default.renameSync(tmp, plain);
|
|
152
|
+
if (!opts.indexless) {
|
|
153
|
+
writeCacheIndex(source, idx, opts.index);
|
|
154
|
+
}
|
|
155
|
+
return plain;
|
|
156
|
+
}
|
|
157
|
+
/** synchronous {@link ensurePlain} (blocking decompression); the supplied `hash` keys the decompress cache */
|
|
158
|
+
function ensurePlainSync(source, opts) {
|
|
159
|
+
if (!(0, exports.isCompressed)(source)) {
|
|
160
|
+
return source;
|
|
161
|
+
}
|
|
162
|
+
const { plain, idx } = cachePaths(opts.hash, opts.cacheDir);
|
|
163
|
+
if (node_fs_1.default.existsSync(plain) && (opts.indexless || node_fs_1.default.existsSync(idx))) {
|
|
164
|
+
return plain;
|
|
165
|
+
}
|
|
166
|
+
const raw = node_fs_1.default.readFileSync(source);
|
|
167
|
+
const out = (0, codec_1.decompressSyncFor)(source, raw);
|
|
168
|
+
const tmp = `${plain}.${process.pid}.tmp`;
|
|
169
|
+
node_fs_1.default.writeFileSync(tmp, out);
|
|
170
|
+
node_fs_1.default.renameSync(tmp, plain);
|
|
171
|
+
if (!opts.indexless) {
|
|
172
|
+
writeCacheIndex(source, idx, opts.index);
|
|
173
|
+
}
|
|
174
|
+
return plain;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=decompress.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PkgBlob, SigDb } from './schema';
|
|
2
|
+
/** run a Hash53 over a stream of chunks (each null-terminated so boundaries can't collide) */
|
|
3
|
+
export declare function hashOf(chunks: Iterable<string>): string;
|
|
4
|
+
/** the self-contained content hash of a whole bundle (dictionary + blobs + routing/metadata) */
|
|
5
|
+
export declare function contentHash(db: Pick<SigDb, 'strings' | 'blobs' | 'pkgs' | 'meta'>): string;
|
|
6
|
+
/** stable hash of a shared dictionary */
|
|
7
|
+
export declare function dictionaryHash(strings: readonly string[]): string;
|
|
8
|
+
/** stable hash of one shard's data (its blobs + pkgs map; the dictionary is hashed separately) */
|
|
9
|
+
export declare function shardHash(blobs: readonly PkgBlob[], pkgs: Record<string, number>): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashOf = hashOf;
|
|
4
|
+
exports.contentHash = contentHash;
|
|
5
|
+
exports.dictionaryHash = dictionaryHash;
|
|
6
|
+
exports.shardHash = shardHash;
|
|
7
|
+
/**
|
|
8
|
+
* Stable content hashes over a bundle's data, used both when writing a bundle (to stamp its header/manifest)
|
|
9
|
+
* and when reading one back (to verify it). A portable {@link Hash53} runs over newline-terminated JSON chunks
|
|
10
|
+
* so chunk boundaries can never collide. Split out of `../sigdb` as it is shared by the writer and the reader.
|
|
11
|
+
*/
|
|
12
|
+
const hash_1 = require("../../util/hash");
|
|
13
|
+
const decode_1 = require("./decode");
|
|
14
|
+
/** the JSON chunks a bundle is hashed over: every dictionary string, every blob tuple, then the pkgs + meta maps */
|
|
15
|
+
function* hashChunks(db) {
|
|
16
|
+
for (const s of db.strings) {
|
|
17
|
+
yield JSON.stringify(s);
|
|
18
|
+
}
|
|
19
|
+
for (const b of db.blobs) {
|
|
20
|
+
yield JSON.stringify((0, decode_1.blobTuple)(b));
|
|
21
|
+
}
|
|
22
|
+
yield JSON.stringify(db.pkgs);
|
|
23
|
+
yield JSON.stringify(db.meta);
|
|
24
|
+
}
|
|
25
|
+
/** run a Hash53 over a stream of chunks (each null-terminated so boundaries can't collide) */
|
|
26
|
+
function hashOf(chunks) {
|
|
27
|
+
const h = new hash_1.Hash53();
|
|
28
|
+
for (const chunk of chunks) {
|
|
29
|
+
h.update(chunk).update('\x00');
|
|
30
|
+
}
|
|
31
|
+
return h.digest();
|
|
32
|
+
}
|
|
33
|
+
/** the self-contained content hash of a whole bundle (dictionary + blobs + routing/metadata) */
|
|
34
|
+
function contentHash(db) {
|
|
35
|
+
return hashOf(hashChunks(db));
|
|
36
|
+
}
|
|
37
|
+
/** stable hash of a shared dictionary */
|
|
38
|
+
function dictionaryHash(strings) {
|
|
39
|
+
return hashOf((function* () {
|
|
40
|
+
for (const s of strings) {
|
|
41
|
+
yield JSON.stringify(s);
|
|
42
|
+
}
|
|
43
|
+
})());
|
|
44
|
+
}
|
|
45
|
+
/** stable hash of one shard's data (its blobs + pkgs map; the dictionary is hashed separately) */
|
|
46
|
+
function shardHash(blobs, pkgs) {
|
|
47
|
+
return hashOf((function* () {
|
|
48
|
+
for (const b of blobs) {
|
|
49
|
+
yield JSON.stringify((0, decode_1.blobTuple)(b));
|
|
50
|
+
}
|
|
51
|
+
yield JSON.stringify(pkgs);
|
|
52
|
+
})());
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SigDbPkgMeta } from './schema';
|
|
2
|
+
/** a byte range `[startByte, bytes]` in the plain `.ndjson` */
|
|
3
|
+
export type ByteRange = [startByte: number, bytes: number];
|
|
4
|
+
/**
|
|
5
|
+
* Everything a reader needs to seek into a plain `.ndjson`: the dictionary's byte range, each package
|
|
6
|
+
* blob's byte range, the package to blob-index map, and per-package metadata. (Line numbers and section
|
|
7
|
+
* bookkeeping the writer used are intentionally not kept -- they bloat the index and are never read.)
|
|
8
|
+
*/
|
|
9
|
+
export interface SigDbIndex {
|
|
10
|
+
/** total byte size of the plain `.ndjson` */
|
|
11
|
+
byteCount: number;
|
|
12
|
+
/** byte range of the string dictionary section */
|
|
13
|
+
dict: ByteRange;
|
|
14
|
+
/** per package-blob byte range (indexed by blob index) */
|
|
15
|
+
blobs: ByteRange[];
|
|
16
|
+
/** package name to blob index */
|
|
17
|
+
pkgs: Record<string, number>;
|
|
18
|
+
/** package name to metadata */
|
|
19
|
+
meta: Record<string, SigDbPkgMeta>;
|
|
20
|
+
}
|
|
21
|
+
/** the on-disk (compact) form of a {@link SigDbIndex}: short keys, `meta` optional (hoisted into a manifest) */
|
|
22
|
+
export interface SigDbIndexWire {
|
|
23
|
+
n: number;
|
|
24
|
+
d: ByteRange;
|
|
25
|
+
b: ByteRange[];
|
|
26
|
+
p: Record<string, number>;
|
|
27
|
+
m?: Record<string, SigDbPkgMeta>;
|
|
28
|
+
}
|
|
29
|
+
/** the on-disk (compact) index of a blob-only shard (no dictionary of its own; it shares a dictionary file) */
|
|
30
|
+
export interface SigShardIndexWire {
|
|
31
|
+
n: number;
|
|
32
|
+
b: ByteRange[];
|
|
33
|
+
p: Record<string, number>;
|
|
34
|
+
}
|
|
35
|
+
/** encode an index to its compact on-disk form; omit `meta` when it is hoisted elsewhere (a manifest) */
|
|
36
|
+
export declare function encodeIndex(i: SigDbIndex, withMeta?: boolean): SigDbIndexWire;
|
|
37
|
+
/** decode a compact index; `meta` falls back to a hoisted map, and `dict` to empty (a blob-only shard) */
|
|
38
|
+
export declare function decodeIndex(w: SigDbIndexWire | SigShardIndexWire, meta?: Record<string, SigDbPkgMeta>): SigDbIndex;
|
|
39
|
+
/** read a plain bundle's sidecar `.idx` file and decode it */
|
|
40
|
+
export declare function readSigDbIndex(plainFile: string): SigDbIndex;
|
|
@@ -0,0 +1,28 @@
|
|
|
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.encodeIndex = encodeIndex;
|
|
7
|
+
exports.decodeIndex = decodeIndex;
|
|
8
|
+
exports.readSigDbIndex = readSigDbIndex;
|
|
9
|
+
/**
|
|
10
|
+
* The sidecar `.idx` index format: the byte ranges a reader seeks to (dictionary + per-package blob) plus the
|
|
11
|
+
* package routing/metadata, and its compact on-disk (wire) form. Split out of `../sigdb` so the reader/writer
|
|
12
|
+
* there does not carry the index encoding.
|
|
13
|
+
*/
|
|
14
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
15
|
+
/** encode an index to its compact on-disk form; omit `meta` when it is hoisted elsewhere (a manifest) */
|
|
16
|
+
function encodeIndex(i, withMeta = true) {
|
|
17
|
+
return { n: i.byteCount, d: i.dict, b: i.blobs, p: i.pkgs, ...(withMeta ? { m: i.meta } : {}) };
|
|
18
|
+
}
|
|
19
|
+
/** decode a compact index; `meta` falls back to a hoisted map, and `dict` to empty (a blob-only shard) */
|
|
20
|
+
function decodeIndex(w, meta) {
|
|
21
|
+
const full = w;
|
|
22
|
+
return { byteCount: w.n, dict: full.d ?? [0, 0], blobs: w.b, pkgs: w.p, meta: full.m ?? meta ?? {} };
|
|
23
|
+
}
|
|
24
|
+
/** read a plain bundle's sidecar `.idx` file and decode it */
|
|
25
|
+
function readSigDbIndex(plainFile) {
|
|
26
|
+
return decodeIndex(JSON.parse(node_fs_1.default.readFileSync(`${plainFile}.idx`, 'utf8')));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index-format.js.map
|