@eagleoutice/flowr 2.11.1 → 2.12.1

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.
Files changed (264) hide show
  1. package/README.md +187 -257
  2. package/abstract-interpretation/absint-visitor.d.ts +1 -0
  3. package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
  4. package/abstract-interpretation/domains/set-range-domain.js +1 -1
  5. package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
  6. package/benchmark/slicer.d.ts +1 -1
  7. package/benchmark/slicer.js +3 -1
  8. package/benchmark/summarizer/second-phase/graph.js +5 -0
  9. package/cli/common/options.d.ts +8 -0
  10. package/cli/common/options.js +2 -0
  11. package/cli/common/scripts-info.d.ts +8 -0
  12. package/cli/repl/commands/repl-commands.d.ts +1 -0
  13. package/cli/repl/commands/repl-commands.js +66 -15
  14. package/cli/repl/commands/repl-dataflow.js +48 -4
  15. package/cli/repl/commands/repl-main.d.ts +2 -0
  16. package/cli/repl/commands/repl-main.js +5 -0
  17. package/cli/repl/commands/repl-query.d.ts +4 -1
  18. package/cli/repl/commands/repl-query.js +72 -22
  19. package/cli/repl/commands/repl-signature.d.ts +7 -0
  20. package/cli/repl/commands/repl-signature.js +119 -0
  21. package/cli/repl/core.d.ts +8 -1
  22. package/cli/repl/core.js +46 -6
  23. package/cli/repl/ghost-hint.d.ts +37 -0
  24. package/cli/repl/ghost-hint.js +72 -0
  25. package/cli/repl/parser/slice-query-parser.d.ts +11 -1
  26. package/cli/repl/parser/slice-query-parser.js +45 -16
  27. package/cli/repl/print-version.d.ts +2 -4
  28. package/cli/repl/print-version.js +41 -23
  29. package/cli/repl/server/connection.js +19 -17
  30. package/cli/slicer-app.d.ts +2 -0
  31. package/cli/slicer-app.js +3 -3
  32. package/cli/wiki.d.ts +2 -2
  33. package/cli/wiki.js +2 -2
  34. package/config.d.ts +63 -2
  35. package/config.js +64 -8
  36. package/control-flow/cfg-dead-code.js +0 -1
  37. package/control-flow/control-flow-graph.js +6 -6
  38. package/control-flow/diff-cfg.js +2 -2
  39. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  40. package/core/print/slice-diff-ansi.js +8 -8
  41. package/core/steps/all/core/20-dataflow.d.ts +2 -2
  42. package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
  43. package/core/steps/all/static-slicing/00-slice.js +1 -1
  44. package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
  45. package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
  46. package/core/steps/pipeline/default-pipelines.d.ts +20 -16
  47. package/data/r-base-packages.generated.d.ts +44 -0
  48. package/data/r-base-packages.generated.js +32 -0
  49. package/data/r-base-primitives.generated.d.ts +1 -0
  50. package/data/r-base-primitives.generated.js +15 -0
  51. package/data/sigdb/sigdb.remote.json +112 -0
  52. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  53. package/dataflow/environments/built-in-proc-name.js +4 -0
  54. package/dataflow/environments/built-in.d.ts +14 -4
  55. package/dataflow/environments/built-in.js +13 -2
  56. package/dataflow/environments/data-masking-functions.d.ts +12 -0
  57. package/dataflow/environments/data-masking-functions.js +46 -0
  58. package/dataflow/environments/default-builtin-config.d.ts +72 -19
  59. package/dataflow/environments/default-builtin-config.js +48 -14
  60. package/dataflow/environments/diff.js +1 -1
  61. package/dataflow/environments/environment.js +1 -2
  62. package/dataflow/environments/identifier.d.ts +11 -4
  63. package/dataflow/environments/identifier.js +28 -10
  64. package/dataflow/environments/resolve-by-name.js +16 -2
  65. package/dataflow/extractor.js +6 -3
  66. package/dataflow/graph/call-graph.d.ts +2 -2
  67. package/dataflow/graph/df-helper.d.ts +4 -4
  68. package/dataflow/graph/diff-dataflow-graph.js +2 -2
  69. package/dataflow/graph/edge.d.ts +3 -3
  70. package/dataflow/graph/edge.js +3 -3
  71. package/dataflow/graph/graph-helper.d.ts +2 -2
  72. package/dataflow/internal/linker.js +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
  74. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
  75. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
  76. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
  77. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
  81. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
  82. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
  83. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
  84. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
  85. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
  86. package/dataflow/internal/process/functions/call/common.js +8 -1
  87. package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
  88. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
  89. package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
  90. package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
  91. package/dataflow/internal/process/functions/process-argument.js +12 -1
  92. package/dataflow/internal/process/process-named-call.d.ts +18 -1
  93. package/dataflow/internal/process/process-named-call.js +94 -0
  94. package/dataflow/processor.d.ts +18 -0
  95. package/documentation/data/faq/faqs.js +5 -1
  96. package/documentation/doc-capabilities.js +1 -1
  97. package/documentation/doc-util/doc-cli-option.d.ts +10 -0
  98. package/documentation/doc-util/doc-cli-option.js +23 -0
  99. package/documentation/doc-util/doc-dfg.js +2 -1
  100. package/documentation/doc-util/doc-query.d.ts +9 -3
  101. package/documentation/doc-util/doc-query.js +9 -4
  102. package/documentation/wiki-dataflow-graph.js +8 -5
  103. package/documentation/wiki-interface.js +4 -2
  104. package/documentation/wiki-linter.js +1 -1
  105. package/documentation/wiki-linting-and-testing.js +4 -1
  106. package/documentation/wiki-mk/doc-context.d.ts +14 -0
  107. package/documentation/wiki-mk/doc-context.js +3 -0
  108. package/documentation/wiki-mk/doc-maker.js +3 -1
  109. package/documentation/wiki-query.js +36 -15
  110. package/documentation/wiki-setup.js +10 -7
  111. package/documentation/wiki-signature-database.d.ts +16 -0
  112. package/documentation/wiki-signature-database.js +293 -0
  113. package/linter/linter-format.d.ts +7 -0
  114. package/linter/linter-rules.d.ts +10 -9
  115. package/linter/rules/naming-convention.d.ts +1 -0
  116. package/linter/rules/naming-convention.js +2 -0
  117. package/linter/rules/no-leaked-credentials.js +1 -2
  118. package/linter/rules/roxygen-arguments.js +18 -5
  119. package/linter/rules/stop-with-call-arg.js +2 -2
  120. package/linter/rules/undefined-symbol-util.d.ts +36 -0
  121. package/linter/rules/undefined-symbol-util.js +149 -0
  122. package/linter/rules/undefined-symbol.d.ts +58 -17
  123. package/linter/rules/undefined-symbol.js +143 -33
  124. package/linter/rules/unused-definition.d.ts +8 -1
  125. package/linter/rules/unused-definition.js +126 -1
  126. package/package.json +22 -10
  127. package/project/context/abstract-flowr-analyzer-context.js +7 -1
  128. package/project/context/flowr-analyzer-context.d.ts +8 -0
  129. package/project/context/flowr-analyzer-context.js +10 -0
  130. package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
  131. package/project/context/flowr-analyzer-dependencies-context.js +51 -2
  132. package/project/context/flowr-analyzer-files-context.d.ts +1 -0
  133. package/project/context/flowr-analyzer-files-context.js +2 -1
  134. package/project/context/flowr-analyzer-functions-context.js +1 -1
  135. package/project/context/flowr-file.d.ts +5 -0
  136. package/project/context/flowr-file.js +5 -0
  137. package/project/flowr-analyzer-builder.js +12 -2
  138. package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
  139. package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
  140. package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
  141. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
  142. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
  143. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
  144. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
  145. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
  146. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
  147. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
  148. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
  149. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
  150. package/project/plugins/package-version-plugins/package.d.ts +5 -3
  151. package/project/plugins/package-version-plugins/package.js +27 -25
  152. package/project/plugins/plugin-registry.d.ts +3 -2
  153. package/project/plugins/plugin-registry.js +4 -2
  154. package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
  155. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
  156. package/project/sigdb/build.d.ts +131 -0
  157. package/project/sigdb/build.js +628 -0
  158. package/project/sigdb/codec.d.ts +51 -0
  159. package/project/sigdb/codec.js +122 -0
  160. package/project/sigdb/decode.d.ts +58 -0
  161. package/project/sigdb/decode.js +129 -0
  162. package/project/sigdb/decompress.d.ts +44 -0
  163. package/project/sigdb/decompress.js +176 -0
  164. package/project/sigdb/hash.d.ts +9 -0
  165. package/project/sigdb/hash.js +54 -0
  166. package/project/sigdb/index-format.d.ts +40 -0
  167. package/project/sigdb/index-format.js +28 -0
  168. package/project/sigdb/manifest.d.ts +68 -0
  169. package/project/sigdb/manifest.js +146 -0
  170. package/project/sigdb/reader.d.ts +250 -0
  171. package/project/sigdb/reader.js +692 -0
  172. package/project/sigdb/schema.d.ts +196 -0
  173. package/project/sigdb/schema.js +33 -0
  174. package/project/sigdb/sigdb-download.d.ts +65 -0
  175. package/project/sigdb/sigdb-download.js +237 -0
  176. package/project/sigdb/signature-match.d.ts +26 -0
  177. package/project/sigdb/signature-match.js +40 -0
  178. package/project/sigdb/version.d.ts +20 -0
  179. package/project/sigdb/version.js +55 -0
  180. package/queries/catalog/absint-query/absint-query-executor.d.ts +6 -0
  181. package/queries/catalog/absint-query/absint-query-executor.js +63 -0
  182. package/queries/catalog/absint-query/absint-query-format.d.ts +37 -0
  183. package/queries/catalog/absint-query/absint-query-format.js +102 -0
  184. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
  185. package/queries/catalog/config-query/config-query-format.d.ts +3 -1
  186. package/queries/catalog/config-query/config-query-format.js +68 -9
  187. package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
  188. package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
  189. package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
  190. package/queries/catalog/linter-query/linter-query-executor.js +6 -1
  191. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
  192. package/queries/catalog/linter-query/linter-query-format.js +40 -8
  193. package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
  194. package/queries/catalog/project-query/project-query-executor.js +96 -4
  195. package/queries/catalog/project-query/project-query-format.d.ts +44 -0
  196. package/queries/catalog/project-query/project-query-format.js +33 -2
  197. package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
  198. package/queries/catalog/signature-query/signature-query-executor.js +461 -0
  199. package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
  200. package/queries/catalog/signature-query/signature-query-format.js +76 -0
  201. package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
  202. package/queries/catalog/signature-query/signature-query-render.js +155 -0
  203. package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
  204. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
  205. package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
  206. package/queries/query-print.js +5 -0
  207. package/queries/query.d.ts +15 -5
  208. package/queries/query.js +7 -4
  209. package/r-bridge/init.js +5 -1
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
  212. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
  213. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
  214. package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
  215. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
  216. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
  217. package/r-bridge/parser.d.ts +2 -0
  218. package/r-bridge/retriever.js +4 -1
  219. package/r-bridge/roxygen2/documentation-provider.js +2 -1
  220. package/r-bridge/shell.d.ts +5 -0
  221. package/r-bridge/shell.js +17 -1
  222. package/reconstruct/inline/source-inline-map.d.ts +48 -0
  223. package/reconstruct/inline/source-inline-map.js +94 -0
  224. package/reconstruct/reconstruct.d.ts +19 -2
  225. package/reconstruct/reconstruct.js +79 -16
  226. package/search/search-executor/search-generators.js +5 -22
  227. package/search/search-executor/search-transformer.js +10 -6
  228. package/slicing/criterion/parse.d.ts +28 -4
  229. package/slicing/criterion/parse.js +133 -18
  230. package/slicing/static/slice-call.d.ts +24 -1
  231. package/slicing/static/slice-call.js +90 -0
  232. package/slicing/static/static-slicer.d.ts +7 -0
  233. package/slicing/static/static-slicer.js +38 -3
  234. package/util/collections/arrays.d.ts +4 -5
  235. package/util/collections/arrays.js +7 -18
  236. package/util/hash.d.ts +14 -0
  237. package/util/hash.js +31 -0
  238. package/util/mermaid/dfg.d.ts +7 -2
  239. package/util/mermaid/dfg.js +53 -13
  240. package/util/r-base-packages.d.ts +19 -0
  241. package/util/r-base-packages.js +72 -0
  242. package/util/r-license.js +2 -10
  243. package/util/r-version.d.ts +45 -15
  244. package/util/r-version.js +97 -36
  245. package/util/range.d.ts +15 -0
  246. package/util/range.js +39 -0
  247. package/util/schema.d.ts +10 -0
  248. package/util/schema.js +22 -0
  249. package/util/text/ansi.d.ts +3 -0
  250. package/util/text/ansi.js +10 -0
  251. package/util/text/args.js +1 -2
  252. package/util/version.js +28 -8
  253. package/data/pkgdb/pkgdb-latest.json.br +0 -0
  254. package/data/pkgdb/pkgdb-tiny.json.br +0 -0
  255. package/documentation/wiki-package-database.d.ts +0 -9
  256. package/documentation/wiki-package-database.js +0 -63
  257. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
  258. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -176
  259. package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
  260. package/project/plugins/package-version-plugins/pkgdb.js +0 -370
  261. package/queries/catalog/df-shape-query/df-shape-query-executor.d.ts +0 -6
  262. package/queries/catalog/df-shape-query/df-shape-query-executor.js +0 -58
  263. package/queries/catalog/df-shape-query/df-shape-query-format.d.ts +0 -27
  264. package/queries/catalog/df-shape-query/df-shape-query-format.js +0 -56
@@ -0,0 +1,628 @@
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.SigDbDictExt = exports.SigDbBuilder = void 0;
7
+ exports.shardId = shardId;
8
+ exports.writeSignatureDb = writeSignatureDb;
9
+ exports.writeDictionary = writeDictionary;
10
+ exports.writeShardBundle = writeShardBundle;
11
+ exports.writeShardedDatabase = writeShardedDatabase;
12
+ /**
13
+ * The build/write half of the sigdb format: the {@link SigDbBuilder} (accumulate analyzed packages, pool +
14
+ * frequency-reorder the dictionary, emit a {@link SigDb}) and the NDJSON writers (single bundle, shared
15
+ * dictionary, blob-only shards, and the sharded {@link SigDbManifest}). Split out of `../sigdb` so the reader
16
+ * there is not weighed down by the (build-time only) encoder; imports only sibling format/codec modules.
17
+ */
18
+ const node_fs_1 = __importDefault(require("node:fs"));
19
+ const node_path_1 = __importDefault(require("node:path"));
20
+ const node_events_1 = require("node:events");
21
+ const schema_1 = require("./schema");
22
+ const r_version_1 = require("../../util/r-version");
23
+ const decode_1 = require("./decode");
24
+ const hash_1 = require("./hash");
25
+ const index_format_1 = require("./index-format");
26
+ const manifest_1 = require("./manifest");
27
+ const codec_1 = require("./codec");
28
+ const log_1 = require("../../util/log");
29
+ // warn once (build-time) when this Node cannot produce `.zst`, so only the brotli `.br` fallback is written
30
+ let zstdSkipLogged = false;
31
+ function noteZstdSupport() {
32
+ if (!(0, codec_1.zstdSupported)() && !zstdSkipLogged) {
33
+ zstdSkipLogged = true;
34
+ log_1.log.warn('sigdb: this Node lacks zstd (node:zlib); writing only the brotli .br fallback (upgrade to Node >= 22.15 for smaller .zst bundles)');
35
+ }
36
+ }
37
+ /** resolve the effective features (everything defaults to on) */
38
+ function resolveFeatures(f) {
39
+ if (f === undefined) {
40
+ return { signatures: true, callGraphs: true, locations: true, dependencies: true };
41
+ }
42
+ return {
43
+ signatures: f.signatures ?? true,
44
+ callGraphs: f.callGraphs ?? true,
45
+ locations: f.locations ?? true,
46
+ dependencies: f.dependencies ?? true
47
+ };
48
+ }
49
+ /** first-order delta encoding of an ascending integer list (smaller, more repetitive, compresses better) */
50
+ function deltaEncode(sorted) {
51
+ const out = new Array(sorted.length);
52
+ let prev = 0;
53
+ for (let i = 0; i < sorted.length; i++) {
54
+ out[i] = sorted[i] - prev;
55
+ prev = sorted[i];
56
+ }
57
+ return out;
58
+ }
59
+ /**
60
+ * Index based string internalization
61
+ */
62
+ function internalize(arr, map, key, value) {
63
+ let i = map.get(key);
64
+ if (i === undefined) {
65
+ i = arr.length;
66
+ arr.push(value);
67
+ map.set(key, i);
68
+ }
69
+ return i;
70
+ }
71
+ /** pack a raw package's metadata, appending the R-core marker only for base packages */
72
+ function packMeta(p) {
73
+ return p.core ? [p.latest, p.archived ? 1 : 0, p.downloads, 1] : [p.latest, p.archived ? 1 : 0, p.downloads];
74
+ }
75
+ /** an append-once dedup pool: {@link internalize}s a value under a string key, returning its stable index */
76
+ class Pool {
77
+ items = [];
78
+ index = new Map();
79
+ intern(key, value) {
80
+ return internalize(this.items, this.index, key, value);
81
+ }
82
+ }
83
+ /** the versions of `p` to keep for `tier`: `current` only the latest, `history` all but it, `full` all (see {@link SigDbTier}) */
84
+ function keptVersions(p, tier) {
85
+ const all = [...p.versions.keys()].sort();
86
+ if (tier === 'full') {
87
+ return all;
88
+ }
89
+ // fall back to the highest by R-version order (not lexical) when the recorded latest is absent
90
+ const latest = p.versions.has(p.latest) ? p.latest : r_version_1.RVersion.highest(all);
91
+ return tier === 'current'
92
+ ? (latest !== undefined ? [latest] : [])
93
+ : all.filter(v => v !== latest);
94
+ }
95
+ /** build one self-contained blob for the given tier + features (functions sorted for determinism) */
96
+ function buildBlob(p, strings, tier, feats) {
97
+ const sigs = new Pool();
98
+ const cgs = new Pool();
99
+ const fns = new Pool();
100
+ const deps = new Pool();
101
+ const sig = (params) => {
102
+ if (!feats.signatures || params.length === 0) {
103
+ return -1;
104
+ }
105
+ const value = params.map(par => {
106
+ const nameI = strings.str(par.name);
107
+ const flags = (par.forced ? 1 /* ParamFlag.Forced */ : 0) | (par.missing ? 2 /* ParamFlag.Missing */ : 0);
108
+ if (par.default !== undefined) {
109
+ // cap very long default expressions (e.g. a 7 KB `c(...)` column list): they are unique, so they never
110
+ // dedupe and bloat the dictionary. A truncation marker keeps "has a default" plus a preview. Newlines
111
+ // are flattened so the string is safe as a delimiter in the newline-blob dictionary.
112
+ const d0 = par.default.replace(/[\r\n]+/g, ' ');
113
+ const def = d0.length > schema_1.MaxDefaultLength ? d0.slice(0, schema_1.MaxDefaultLength) + '…' : d0;
114
+ return [nameI, flags, strings.str(def)];
115
+ }
116
+ return flags === 0 ? nameI : [nameI, flags];
117
+ });
118
+ return sigs.intern(JSON.stringify(value), value);
119
+ };
120
+ const cg = (callees) => {
121
+ if (!feats.callGraphs || callees.length === 0) {
122
+ return -1;
123
+ }
124
+ const idxs = Array.from(new Set(callees), c => strings.str(c)).sort((a, b) => a - b);
125
+ return cgs.intern(idxs.join(','), deltaEncode(idxs));
126
+ };
127
+ const fn = (f) => {
128
+ const rec = [strings.str(f.name), sig(f.params), cg(f.callees), f.props,
129
+ feats.locations && f.file ? strings.str(f.file) : -1, feats.locations ? f.line ?? -1 : -1];
130
+ return fns.intern(rec.join(','), rec);
131
+ };
132
+ const depList = (list) => {
133
+ // sorted by (type, name) for a canonical, poolable form
134
+ const value = list
135
+ .toSorted((a, b) => a.type - b.type || a.name.localeCompare(b.name))
136
+ .map(d => d.constraint !== undefined
137
+ ? [strings.str(d.name), d.type, strings.str(d.constraint)]
138
+ : [strings.str(d.name), d.type]);
139
+ return deps.intern(JSON.stringify(value), value);
140
+ };
141
+ const versions = {};
142
+ const depsByVersion = {};
143
+ const dates = {};
144
+ const noncran = [];
145
+ let versionCount = 0;
146
+ let functionCount = 0;
147
+ for (const version of keptVersions(p, tier)) {
148
+ const info = p.versions.get(version);
149
+ const idxs = info.functions
150
+ .toSorted((a, b) => a.name.localeCompare(b.name) || (a.file ?? '').localeCompare(b.file ?? '') || (a.line ?? -1) - (b.line ?? -1))
151
+ .map(fn).sort((a, b) => a - b);
152
+ versions[version] = deltaEncode(idxs);
153
+ if (feats.dependencies && info.dependencies && info.dependencies.length > 0) {
154
+ depsByVersion[version] = depList(info.dependencies);
155
+ }
156
+ if (info.date !== undefined && Number.isFinite(info.date)) {
157
+ dates[version] = Math.round(info.date / 86_400_000); // days since the Unix epoch (compact; day precision)
158
+ }
159
+ versionCount++;
160
+ functionCount += info.functions.length;
161
+ if (!info.cran) {
162
+ noncran.push(version);
163
+ }
164
+ }
165
+ const blob = { sigs: sigs.items, cgs: cgs.items, fns: fns.items, versions, noncran: noncran.length ? noncran : undefined, deps: deps.items, depsByVersion, dates };
166
+ return { blob, versionCount, functionCount };
167
+ }
168
+ /**
169
+ * Accumulates analyzed functions and serializes a {@link SigDb}. Feed it with {@link addPackage} and
170
+ * {@link addVersion}, then {@link build}. Pooling (dictionary, per-package blobs, whole-package dedup,
171
+ * frequency reordering) happens in {@link build} so the result is deterministic for identical inputs.
172
+ */
173
+ class SigDbBuilder {
174
+ raw = new Map();
175
+ addPackage(name, opts) {
176
+ const p = this.raw.get(name);
177
+ if (p) {
178
+ p.latest = opts.latest;
179
+ p.archived = opts.archived ?? p.archived;
180
+ p.downloads = opts.downloads ?? p.downloads;
181
+ p.core = opts.core ?? p.core;
182
+ }
183
+ else {
184
+ this.raw.set(name, { latest: opts.latest, archived: opts.archived ?? false, downloads: opts.downloads ?? 0, core: opts.core ?? false, versions: new Map() });
185
+ this.namesCache = undefined; // a new package name invalidates the memoized sorted order
186
+ }
187
+ }
188
+ addVersion(name, version, info) {
189
+ let p = this.raw.get(name);
190
+ if (!p) {
191
+ p = { latest: version, archived: false, downloads: 0, core: false, versions: new Map() };
192
+ this.raw.set(name, p);
193
+ this.namesCache = undefined; // a new package name invalidates the memoized sorted order
194
+ }
195
+ p.versions.set(version, info);
196
+ }
197
+ /** the package names once, alphabetically -- the stable build order, computed a single time (see {@link selectPackages}) */
198
+ sortedNames() {
199
+ return (this.namesCache ??= [...this.raw.keys()].sort());
200
+ }
201
+ namesCache;
202
+ /** the package names to include, in build (sorted) order, honoring the R-core policy and popularity shard */
203
+ selectPackages(opts) {
204
+ let names = this.sortedNames(); // filters below reassign to fresh arrays, so no copy needed
205
+ if (opts.core === 'only') {
206
+ names = names.filter(n => this.raw.get(n).core);
207
+ }
208
+ else if (opts.core === 'exclude') {
209
+ names = names.filter(n => !this.raw.get(n).core);
210
+ }
211
+ if (opts.topN === undefined || opts.shard === undefined) {
212
+ return names;
213
+ }
214
+ // rank by downloads within the (already core-filtered) selection, then split into top-N / rest
215
+ const ranked = names
216
+ .map(n => [n, this.raw.get(n).downloads])
217
+ .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
218
+ .map(([n]) => n);
219
+ const top = new Set(ranked.slice(0, opts.topN));
220
+ return names.filter(n => opts.shard === 'top' ? top.has(n) : !top.has(n));
221
+ }
222
+ /**
223
+ * Build one {@link SigDb} bundle. `tier: 'current'` keeps only each package's latest version (small,
224
+ * fast to load); `tier: 'full'` keeps every version. `topN` + `shard` further restrict to the most-
225
+ * downloaded packages (`'top'`) or the remainder (`'rest'`), so a database can be split into several
226
+ * small shards routed by a {@link SigDbManifest}.
227
+ */
228
+ build(opts) {
229
+ const tier = opts.tier ?? 'full';
230
+ const feats = resolveFeatures(opts.features);
231
+ const strings = new StringPool();
232
+ const blobs = [];
233
+ const blobIdx = new Map();
234
+ const pkgs = {};
235
+ const pkgMeta = {};
236
+ let versionCount = 0;
237
+ let functionCount = 0;
238
+ for (const name of this.selectPackages(opts)) {
239
+ const p = this.raw.get(name);
240
+ const built = buildBlob(p, strings, tier, feats);
241
+ if (built.versionCount === 0) {
242
+ continue; // a package with no versions in this tier (e.g. a single-version package under `history`) is not routed
243
+ }
244
+ versionCount += built.versionCount;
245
+ functionCount += built.functionCount;
246
+ const key = JSON.stringify((0, decode_1.blobTuple)(built.blob));
247
+ pkgs[name] = internalize(blobs, blobIdx, key, built.blob);
248
+ pkgMeta[name] = packMeta(p);
249
+ }
250
+ const dict = (opts.optimizeStrings ?? true) ? optimizeStringOrder(strings.strings, blobs) : strings.strings;
251
+ const cranBase = opts.cranBase && opts.cranBase !== schema_1.DefaultCranBase ? opts.cranBase : undefined;
252
+ const partial = {
253
+ format: schema_1.SigDbMagic, schema: schema_1.SigDbSchema, scope: 'signatures',
254
+ ...(cranBase ? { cranBase } : {}), strings: dict, blobs, pkgs, meta: pkgMeta
255
+ };
256
+ return {
257
+ ...partial,
258
+ content: {
259
+ version: Number(opts.date.replace(/-/g, '')),
260
+ date: opts.date,
261
+ generated: opts.generated,
262
+ tier,
263
+ ...(opts.shard ? { shard: opts.shard, topN: opts.topN } : {}),
264
+ features: feats,
265
+ packages: Object.keys(pkgs).length,
266
+ versions: versionCount,
267
+ functions: functionCount,
268
+ uniquePackages: blobs.length,
269
+ strings: dict.length,
270
+ hash: (0, hash_1.contentHash)(partial)
271
+ }
272
+ };
273
+ }
274
+ /**
275
+ * Build several shards that all reindex into a **single shared string dictionary** (stored once, not
276
+ * per shard). All shards' blobs are pooled into one dictionary and frequency-sorted together, so the
277
+ * dictionary loads once and no strings are duplicated across shards. Package metadata is likewise
278
+ * collected once. This is the compact, fast-loading counterpart of calling {@link build} per shard.
279
+ */
280
+ buildSharded(opts, specs) {
281
+ const feats = resolveFeatures(opts.features);
282
+ const strings = new StringPool(); // SHARED across every shard
283
+ const meta = {};
284
+ const shards = specs.map(spec => {
285
+ const tier = spec.tier ?? 'full';
286
+ const blobs = [];
287
+ const blobIdx = new Map();
288
+ const pkgs = {};
289
+ let versions = 0;
290
+ let functions = 0;
291
+ for (const name of this.selectPackages(spec)) {
292
+ const p = this.raw.get(name);
293
+ const built = buildBlob(p, strings, tier, feats); // interns into the SHARED dictionary
294
+ if (built.versionCount === 0) {
295
+ continue; // no versions in this tier (e.g. a single-version package under `history`) -> not routed
296
+ }
297
+ versions += built.versionCount;
298
+ functions += built.functionCount;
299
+ pkgs[name] = internalize(blobs, blobIdx, JSON.stringify((0, decode_1.blobTuple)(built.blob)), built.blob);
300
+ meta[name] = packMeta(p);
301
+ }
302
+ return { id: shardId(spec), tier, shard: spec.shard, topN: spec.topN, core: spec.core, blobs, pkgs, versions, functions, hash: '' };
303
+ });
304
+ // ONE frequency reorder over every shard's blobs, remapping the shared dictionary in place
305
+ const dict = (opts.optimizeStrings ?? true) ? optimizeStringOrder(strings.strings, shards.flatMap(s => s.blobs)) : strings.strings;
306
+ for (const s of shards) {
307
+ s.hash = (0, hash_1.shardHash)(s.blobs, s.pkgs);
308
+ }
309
+ const cranBase = opts.cranBase && opts.cranBase !== schema_1.DefaultCranBase ? opts.cranBase : undefined;
310
+ return {
311
+ format: schema_1.SigDbMagic, schema: schema_1.SigDbSchema, scope: 'signatures',
312
+ date: opts.date, generated: opts.generated, ...(cranBase ? { cranBase } : {}),
313
+ features: feats, strings: dict, dictHash: (0, hash_1.dictionaryHash)(dict), meta, shards
314
+ };
315
+ }
316
+ }
317
+ exports.SigDbBuilder = SigDbBuilder;
318
+ /** the id of a shard, e.g. `base-current`, `current-top` or `full` */
319
+ function shardId(spec) {
320
+ const tier = spec.tier ?? 'full';
321
+ if (spec.core === 'only') {
322
+ return `base-${tier}`;
323
+ }
324
+ return spec.shard ? `${tier}-${spec.shard}` : tier;
325
+ }
326
+ /** the global, frequency-orderable string dictionary shared by every package blob */
327
+ class StringPool {
328
+ strings = [];
329
+ idx = new Map();
330
+ str(s) {
331
+ return internalize(this.strings, this.idx, s, s);
332
+ }
333
+ }
334
+ /** renumber the dictionary so the most-referenced strings get the smallest indices (a pure bijection) */
335
+ function optimizeStringOrder(strings, blobs) {
336
+ const n = strings.length;
337
+ const counts = new Float64Array(n);
338
+ const bump = (i) => {
339
+ if (i >= 0) {
340
+ counts[i]++;
341
+ }
342
+ };
343
+ for (const blob of blobs) {
344
+ for (const s of blob.sigs) {
345
+ for (const p of s) {
346
+ if (typeof p === 'number') {
347
+ bump(p);
348
+ }
349
+ else {
350
+ bump(p[0]);
351
+ if (p.length === 3) {
352
+ bump(p[2]);
353
+ }
354
+ }
355
+ }
356
+ }
357
+ for (const c of blob.cgs) {
358
+ let prev = 0;
359
+ for (const d of c) {
360
+ prev += d;
361
+ bump(prev);
362
+ }
363
+ }
364
+ for (const f of blob.fns) {
365
+ bump(f[0]);
366
+ bump(f[4]);
367
+ }
368
+ for (const list of blob.deps) {
369
+ for (const d of list) {
370
+ bump(d[0]);
371
+ if (d.length === 3) {
372
+ bump(d[2]);
373
+ }
374
+ }
375
+ }
376
+ }
377
+ const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => counts[b] - counts[a] || a - b);
378
+ const remap = new Int32Array(n);
379
+ for (let newI = 0; newI < n; newI++) {
380
+ remap[order[newI]] = newI;
381
+ }
382
+ for (const blob of blobs) {
383
+ for (const s of blob.sigs) {
384
+ for (let k = 0; k < s.length; k++) {
385
+ const p = s[k];
386
+ if (typeof p === 'number') {
387
+ s[k] = remap[p];
388
+ }
389
+ else {
390
+ p[0] = remap[p[0]];
391
+ if (p.length === 3) {
392
+ p[2] = remap[p[2]];
393
+ }
394
+ }
395
+ }
396
+ }
397
+ for (let c = 0; c < blob.cgs.length; c++) {
398
+ const idxs = [];
399
+ let prev = 0;
400
+ for (const d of blob.cgs[c]) {
401
+ prev += d;
402
+ idxs.push(remap[prev]);
403
+ }
404
+ idxs.sort((a, b) => a - b);
405
+ blob.cgs[c] = deltaEncode(idxs);
406
+ }
407
+ for (const f of blob.fns) {
408
+ f[0] = remap[f[0]];
409
+ if (f[4] >= 0) {
410
+ f[4] = remap[f[4]];
411
+ }
412
+ }
413
+ for (const list of blob.deps) {
414
+ for (const d of list) {
415
+ d[0] = remap[d[0]];
416
+ if (d.length === 3) {
417
+ d[2] = remap[d[2]];
418
+ }
419
+ }
420
+ }
421
+ }
422
+ return order.map(oldI => strings[oldI]);
423
+ }
424
+ /** flush a batch line once its serialized size reaches roughly this many bytes (keeps lines under the string cap) */
425
+ const NdjsonBatchBytes = 8_000_000;
426
+ /**
427
+ * Batch the string dictionary into `["d", startIdx, "s1\ns2\n…"]` lines: the strings are joined into ONE
428
+ * newline-delimited blob per line rather than a JSON array of quoted strings. On load this parses as a single
429
+ * string and `split('\n')` -- far faster than `JSON.parse`-ing an array of ~1.4M elements, and a touch smaller
430
+ * Safe because no dictionary string contains a newline (defaults are normalized).
431
+ */
432
+ function* dictLines(strings) {
433
+ let start = 0;
434
+ let parts = [];
435
+ let bytes = 0;
436
+ const line = (from) => `["d",${from},${JSON.stringify(parts.join('\n'))}]`;
437
+ for (let i = 0; i < strings.length; i++) {
438
+ const s = strings[i];
439
+ if (parts.length > 0 && bytes + s.length + 1 > NdjsonBatchBytes) {
440
+ yield line(start);
441
+ start = i;
442
+ parts = [];
443
+ bytes = 0;
444
+ }
445
+ parts.push(s);
446
+ bytes += s.length + 1;
447
+ }
448
+ yield line(start);
449
+ }
450
+ /** batch an array into `[tag, startIdx, [...]]` lines that never approach V8's string cap */
451
+ function* batchLines(tag, arr) {
452
+ let start = 0;
453
+ let parts = [];
454
+ let bytes = 0;
455
+ const line = (from) => `["${tag}",${from},[${parts.join(',')}]]`;
456
+ for (let i = 0; i < arr.length; i++) {
457
+ const s = JSON.stringify(arr[i]);
458
+ if (parts.length > 0 && bytes + s.length + 1 > NdjsonBatchBytes) {
459
+ yield line(start);
460
+ start = i;
461
+ parts = [];
462
+ bytes = 0;
463
+ }
464
+ parts.push(s);
465
+ bytes += s.length + 1;
466
+ }
467
+ yield line(start);
468
+ }
469
+ // large window (30) shaves ~15% off the `.br`; every {@link SigDatabase} read path decodes with
470
+ // `BROTLI_DECODER_PARAM_LARGE_WINDOW` enabled, so this is always safe for bundles flowR reads back.
471
+ const DefaultBrotliLgwin = 30;
472
+ /** codec-appropriate compression options: brotli takes the quality/window, zstd its own level */
473
+ function codecOptions(spec, compress) {
474
+ return spec.codec === 'zstd'
475
+ ? { level: compress.level }
476
+ : { level: compress.brotliQuality, lgwin: compress.brotliLgwin ?? DefaultBrotliLgwin };
477
+ }
478
+ /**
479
+ * Streams NDJSON lines to `<plain>` plus every codec {@link writeCodecs} yields (`.br` always, `.zst` when this
480
+ * Node supports it) at once, tracking the plain byte offset for seek indexes. A `.br` fallback is thus always
481
+ * produced beside any `.zst`.
482
+ */
483
+ class LineWriter {
484
+ plainOut;
485
+ sinks = [];
486
+ byteOff = 0;
487
+ constructor(plain, compress) {
488
+ noteZstdSupport();
489
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(node_path_1.default.resolve(plain)), { recursive: true });
490
+ this.plainOut = node_fs_1.default.createWriteStream(plain);
491
+ for (const spec of (0, codec_1.writeCodecs)()) {
492
+ const file = node_fs_1.default.createWriteStream(`${plain}${spec.ext}`);
493
+ const stream = spec.createCompress(codecOptions(spec, compress));
494
+ stream.pipe(file);
495
+ this.sinks.push({ stream, file });
496
+ }
497
+ }
498
+ async write(text) {
499
+ const chunk = text + '\n';
500
+ const back = [];
501
+ if (!this.plainOut.write(chunk)) {
502
+ back.push((0, node_events_1.once)(this.plainOut, 'drain'));
503
+ }
504
+ for (const { stream } of this.sinks) {
505
+ if (!stream.write(chunk)) {
506
+ back.push((0, node_events_1.once)(stream, 'drain'));
507
+ }
508
+ }
509
+ if (back.length > 0) {
510
+ await Promise.all(back);
511
+ }
512
+ this.byteOff += Buffer.byteLength(chunk);
513
+ }
514
+ async close() {
515
+ this.plainOut.end();
516
+ for (const { stream } of this.sinks) {
517
+ stream.end();
518
+ }
519
+ await Promise.all([(0, node_events_1.once)(this.plainOut, 'close'), ...this.sinks.map(s => (0, node_events_1.once)(s.file, 'close'))]);
520
+ }
521
+ }
522
+ /** Write `<outBase>.sigs.ndjson` (+ `.br`, `.zst` when supported, `.idx`) -- a single self-contained bundle (its own dictionary). */
523
+ async function writeSignatureDb(outBase, db, compress = {}) {
524
+ const plain = `${outBase}${schema_1.SigDbExt}`;
525
+ const w = new LineWriter(plain, compress);
526
+ await w.write(JSON.stringify({
527
+ format: db.format, schema: db.schema, scope: db.scope,
528
+ ...(db.cranBase ? { cranBase: db.cranBase } : {}), content: db.content
529
+ }));
530
+ const dictStartByte = w.byteOff;
531
+ for (const line of dictLines(db.strings)) {
532
+ await w.write(line);
533
+ }
534
+ const dict = [dictStartByte, w.byteOff - dictStartByte];
535
+ const blobs = [];
536
+ for (let i = 0; i < db.blobs.length; i++) {
537
+ const startByte = w.byteOff;
538
+ await w.write(`["b",${i},${JSON.stringify((0, decode_1.blobTuple)(db.blobs[i]))}]`);
539
+ blobs.push([startByte, w.byteOff - startByte]);
540
+ }
541
+ for (const line of batchLines('m', Object.entries(db.meta))) {
542
+ await w.write(line);
543
+ }
544
+ for (const line of batchLines('p', Object.entries(db.pkgs))) {
545
+ await w.write(line);
546
+ }
547
+ await w.close();
548
+ const index = { byteCount: w.byteOff, dict, blobs, pkgs: db.pkgs, meta: db.meta };
549
+ node_fs_1.default.writeFileSync(`${plain}.idx`, JSON.stringify((0, index_format_1.encodeIndex)(index)));
550
+ return index;
551
+ }
552
+ /** the extension of a standalone shared-dictionary file */
553
+ exports.SigDbDictExt = '.dict.sigs.ndjson';
554
+ /** Write a shared string dictionary to `<outBase>.dict.sigs.ndjson` (+ `.br`/`.zst`). Returns where its lines sit. */
555
+ async function writeDictionary(outBase, id, strings, compress = {}) {
556
+ const plain = `${outBase}${exports.SigDbDictExt}`;
557
+ const w = new LineWriter(plain, compress);
558
+ await w.write(JSON.stringify({ format: 'flowr-sigdb-dict', schema: schema_1.SigDbSchema, strings: strings.length }));
559
+ const start = w.byteOff;
560
+ for (const line of dictLines(strings)) {
561
+ await w.write(line);
562
+ }
563
+ const range = [start, w.byteOff - start];
564
+ await w.close();
565
+ return { id, path: `${node_path_1.default.basename(outBase)}${exports.SigDbDictExt}`, hash: (0, hash_1.dictionaryHash)(strings), range, byteCount: w.byteOff, strings: strings.length };
566
+ }
567
+ /** Write one blob-only shard (references a shared dictionary) to `<outBase>.<id>.sigs.ndjson` (+ `.br`/`.zst`). */
568
+ async function writeShardBundle(outBase, shard, cranBase, compress = {}) {
569
+ const plain = `${outBase}.${shard.id}${schema_1.SigDbExt}`;
570
+ const w = new LineWriter(plain, compress);
571
+ await w.write(JSON.stringify({
572
+ format: schema_1.SigDbMagic, schema: schema_1.SigDbSchema, scope: 'signatures', shared: true,
573
+ ...(cranBase ? { cranBase } : {}),
574
+ content: { tier: shard.tier, ...(shard.shard ? { shard: shard.shard, topN: shard.topN } : {}), packages: Object.keys(shard.pkgs).length, versions: shard.versions, functions: shard.functions, hash: shard.hash }
575
+ }));
576
+ const blobs = [];
577
+ for (let i = 0; i < shard.blobs.length; i++) {
578
+ const startByte = w.byteOff;
579
+ await w.write(`["b",${i},${JSON.stringify((0, decode_1.blobTuple)(shard.blobs[i]))}]`);
580
+ blobs.push([startByte, w.byteOff - startByte]);
581
+ }
582
+ for (const line of batchLines('p', Object.entries(shard.pkgs))) {
583
+ await w.write(line);
584
+ }
585
+ await w.close();
586
+ return { n: w.byteOff, b: blobs, p: shard.pkgs };
587
+ }
588
+ /**
589
+ * Write a {@link ShardedSigDb}: one shared dictionary file, one blob-only file per shard, and a
590
+ * {@link SigDbManifest} that embeds each shard's index and references the shared dictionary by id. Every
591
+ * shard reindexes into that single dictionary (stored once, not per shard). A reader needs only the compressed
592
+ * files plus the manifest -- no `.idx` sidecars. With `pack`, also assembles a clean copy-into-flowR folder.
593
+ */
594
+ async function writeShardedDatabase(outBase, db, manifestFile, opts = {}) {
595
+ const compress = { level: opts.level, brotliQuality: opts.brotliQuality, brotliLgwin: opts.brotliLgwin };
596
+ const exts = (0, codec_1.writeCodecs)().map(c => c.ext); // every compressed variant produced (`.br` always, `.zst` when supported)
597
+ const base = node_path_1.default.basename(outBase);
598
+ const dictRef = await writeDictionary(outBase, 'shared', db.strings, compress);
599
+ const shardRefs = [];
600
+ for (const s of db.shards) {
601
+ const idx = await writeShardBundle(outBase, s, db.cranBase, compress);
602
+ const ref = {
603
+ id: s.id, tier: s.tier, ...(s.shard ? { shard: s.shard, topN: s.topN } : {}),
604
+ path: `${base}.${s.id}${schema_1.SigDbExt}`, hash: s.hash,
605
+ packages: Object.keys(s.pkgs).length, versions: s.versions, dict: dictRef.id, idx
606
+ };
607
+ shardRefs.push(ref);
608
+ opts.onShard?.(s, ref);
609
+ }
610
+ const manifest = {
611
+ format: manifest_1.SigDbManifestMagic, schema: manifest_1.SigDbManifestSchema, date: db.date, generated: db.generated,
612
+ ...(db.cranBase ? { cranBase: db.cranBase } : {}), meta: db.meta, dicts: [dictRef], shards: shardRefs
613
+ };
614
+ (0, manifest_1.writeManifest)(manifestFile, manifest);
615
+ if (opts.pack) {
616
+ // a self-contained folder to copy into flowR: every compressed variant of the dictionary + shards + the (index-embedding) manifest
617
+ node_fs_1.default.mkdirSync(opts.pack, { recursive: true });
618
+ for (const ext of exts) {
619
+ node_fs_1.default.copyFileSync(`${outBase}${exports.SigDbDictExt}${ext}`, node_path_1.default.join(opts.pack, `${dictRef.path}${ext}`));
620
+ for (const ref of shardRefs) {
621
+ node_fs_1.default.copyFileSync(`${outBase}.${ref.id}${schema_1.SigDbExt}${ext}`, node_path_1.default.join(opts.pack, `${ref.path}${ext}`));
622
+ }
623
+ }
624
+ (0, manifest_1.writeManifest)(node_path_1.default.join(opts.pack, `${base}.manifest.json`), manifest);
625
+ }
626
+ return manifest;
627
+ }
628
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1,51 @@
1
+ import type { Transform } from 'node:stream';
2
+ /** whether the running Node exposes the `node:zlib` zstd API (Node 22.15+ / 23.8+) */
3
+ export declare function zstdSupported(): boolean;
4
+ /** on-disk compression codec for a sigdb bundle */
5
+ export type SigDbCodec = 'brotli' | 'zstd';
6
+ /** the richer codec, preferred by readers when this Node supports it (writers always additionally emit `.br`) */
7
+ export declare const DefaultSigDbCodec: SigDbCodec;
8
+ /** compressed extensions a reader understands (outer compression only); `.gz` is read-only legacy */
9
+ export declare const CompressedExts: readonly [".br", ".zst", ".gz"];
10
+ /** whether a bundle path is a compressed source that must be decompressed to be seekable */
11
+ export declare function isCompressedExt(file: string): boolean;
12
+ /** the compressed extension of a path, or `undefined` if it is a plain (uncompressed) source */
13
+ export declare function compressedExtOf(file: string): string | undefined;
14
+ /** strip a trailing compressed extension (`.br`/`.zst`/`.gz`) from a filename, if present */
15
+ export declare function stripCompressedExt(name: string): string;
16
+ /** regex alternation matching an optional trailing compressed extension, e.g. `(?:\.br|\.zst|\.gz)?` */
17
+ export declare const CompressedExtPattern: string;
18
+ /** options shared by the (de)compression codecs; unused knobs are ignored by a codec that lacks them */
19
+ export interface CodecCompressOptions {
20
+ /** compression level -- brotli quality (0..11), zstd level (1..22) */
21
+ level?: number;
22
+ /** brotli window bits (10..30); above 24 enables large-window mode. Ignored by zstd */
23
+ lgwin?: number;
24
+ /** uncompressed size hint for the compressor */
25
+ sizeHint?: number;
26
+ }
27
+ /** a compression codec: its file extension plus sync + streaming (de)compression */
28
+ export interface SigDbCodecSpec {
29
+ readonly codec: SigDbCodec;
30
+ readonly ext: string;
31
+ compressSync(buf: Buffer | string, opts?: CodecCompressOptions): Buffer;
32
+ createCompress(opts?: CodecCompressOptions): Transform;
33
+ }
34
+ export declare const BrotliCodec: SigDbCodecSpec;
35
+ export declare const ZstdCodec: SigDbCodecSpec;
36
+ /** the codec spec for a codec name (used when writing) */
37
+ export declare function codecFor(codec: SigDbCodec): SigDbCodecSpec;
38
+ /**
39
+ * The codec specs a writer emits: brotli `.br` always (the universal fallback -- every Node ships it), plus
40
+ * zstd `.zst` when this Node can produce/read it. So a `.br` fallback is guaranteed next to every `.zst`.
41
+ */
42
+ export declare function writeCodecs(): readonly SigDbCodecSpec[];
43
+ /**
44
+ * Compressed extensions this runtime can actually decompress, most-preferred first (zstd before brotli when
45
+ * supported). `.zst` is omitted entirely when this Node lacks zstd, so a reader never picks a variant it cannot read.
46
+ */
47
+ export declare function readableExtsPreferred(): readonly string[];
48
+ /** a streaming decompressor for a compressed source, chosen by its extension (`.zst`/`.gz`/`.br`) */
49
+ export declare function createDecompressFor(file: string): Transform;
50
+ /** synchronously decompress a compressed buffer, choosing the codec by the source's extension */
51
+ export declare function decompressSyncFor(file: string, raw: Buffer): Buffer;