@eagleoutice/flowr 2.15.9 → 2.16.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.
Files changed (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -39,10 +39,7 @@ function dictLineRun(json) {
39
39
  /** apply one `d` line to a plain array, for the whole-file form {@link readSigDbFile} reads */
40
40
  function applyDictLine(json, strings) {
41
41
  const { start, names } = dictLineRun(json);
42
- const batch = names.split('\n');
43
- for (let k = 0; k < batch.length; k++) {
44
- strings[start + k] = batch[k];
45
- }
42
+ names.split('\n').forEach((name, k) => strings[start + k] = name);
46
43
  }
47
44
  /**
48
45
  * Dictionary ids grouped by first byte and byte length, kept per dictionary rather than per reader (the shards of one
@@ -353,10 +350,6 @@ function keepBlob(db, blobIdx, bytes) {
353
350
  cachedBlobBytes += bytes;
354
351
  return entry;
355
352
  }
356
- /** Mark `entry` read, so the hand passes over it once before dropping it. */
357
- function touchBlob(entry) {
358
- entry.used = true;
359
- }
360
353
  /** give back what `db` held, so a closed bundle stops spending the budget of the open ones */
361
354
  function releaseBlobs(db) {
362
355
  for (let i = cachedBlobs.length - 1; i >= 0; i--) {
@@ -440,12 +433,13 @@ class SigDatabase {
440
433
  * is compressed. Pass `strings` for a blob-only shard that shares an already-loaded dictionary.
441
434
  */
442
435
  static openSyncFrom(source, opts) {
443
- const plain = (0, decompress_1.isCompressed)(source)
444
- ? (opts.hash !== undefined ? (0, decompress_1.ensurePlainSync)(source, { cacheDir: opts.cacheDir, hash: opts.hash, index: opts.index })
445
- : (() => {
446
- throw new Error('openSyncFrom needs a hash to key the cache for a compressed source');
447
- })())
448
- : source;
436
+ let plain = source;
437
+ if ((0, decompress_1.isCompressed)(source)) {
438
+ if (opts.hash === undefined) {
439
+ throw new Error('openSyncFrom needs a hash to key the cache for a compressed source');
440
+ }
441
+ plain = (0, decompress_1.ensurePlainSync)(source, { cacheDir: opts.cacheDir, hash: opts.hash, index: opts.index });
442
+ }
449
443
  return SigDatabase.openSync(plain, { index: opts.index, strings: opts.strings });
450
444
  }
451
445
  has(pkg) {
@@ -463,12 +457,12 @@ class SigDatabase {
463
457
  const cached = this.blobCache.get(blobIdx);
464
458
  if (cached !== undefined) {
465
459
  if (cached.entry !== undefined) {
466
- touchBlob(cached.entry);
460
+ cached.entry.used = true;
467
461
  }
468
462
  return cached.blob;
469
463
  }
470
464
  if (this.fd === NoFile) {
471
- return undefined; // an in-memory database starts out with every blob cached
465
+ return undefined;
472
466
  }
473
467
  const range = this.index.blobs[blobIdx];
474
468
  const blob = this.readBlobAt(range);
@@ -595,16 +589,7 @@ class SigDatabase {
595
589
  */
596
590
  exportsNameId(pkg, id) {
597
591
  const r = this.versionFns(pkg);
598
- if (r === undefined) {
599
- return false;
600
- }
601
- for (const i of r.fns.idxs) {
602
- const fn = r.blob.fns[i];
603
- if (fn[0] === id && (fn[3] & 1 /* FnProp.Exported */) !== 0) {
604
- return true;
605
- }
606
- }
607
- return false;
592
+ return r?.fns.idxs.some(i => r.blob.fns[i][0] === id && (r.blob.fns[i][3] & 1 /* FnProp.Exported */) !== 0) ?? false;
608
593
  }
609
594
  classOwner(className, version) {
610
595
  if (version !== undefined) {
@@ -851,40 +836,22 @@ class SigDatabaseSet {
851
836
  }
852
837
  const ref = this.manifest.shards[i];
853
838
  const strings = ref.dict ? this.dictionaryStrings(ref.dict) : undefined;
854
- const db = SigDatabase.openSyncFrom((0, decompress_1.resolveSource)(this.baseDir, ref.path), { cacheDir: this.cacheDir, hash: ref.hash, index: this.indices[i], strings });
855
- this.opened[i] = db;
856
- return db;
839
+ return this.opened[i] = SigDatabase.openSyncFrom((0, decompress_1.resolveSource)(this.baseDir, ref.path), { cacheDir: this.cacheDir, hash: ref.hash, index: this.indices[i], strings });
857
840
  }
858
841
  /**
859
842
  * Warm the shards (and their shared dictionaries) needed for `pkgs`, or **everything** when omitted.
860
843
  * Afterward, the synchronous query methods, for the latest *and* historical versions, do no I/O or decompression.
861
844
  */
862
845
  async preload(pkgs) {
863
- const need = new Set();
864
- if (pkgs) {
865
- for (const p of pkgs) {
866
- for (const i of this.routes.get(p) ?? []) {
867
- need.add(i);
868
- }
869
- }
870
- }
871
- else {
872
- this.manifest.shards.forEach((_, i) => need.add(i));
873
- }
874
- await this.warmShards(need);
846
+ const need = pkgs ? pkgs.flatMap(p => this.routes.get(p) ?? []) : this.manifest.shards.map((_, i) => i);
847
+ await this.warmShards(new Set(need));
875
848
  }
876
849
  /**
877
850
  * Warm just the shards matching `include`, e.g., only the current-tier top shards (the base + most-downloaded
878
851
  * packages) to speed up common lookups without paying for the long tail or the history shards. See {@link preload}.
879
852
  */
880
853
  async preloadShards(include) {
881
- const need = new Set();
882
- this.manifest.shards.forEach((s, i) => {
883
- if (include(s)) {
884
- need.add(i);
885
- }
886
- });
887
- await this.warmShards(need);
854
+ await this.warmShards(new Set(this.manifest.shards.flatMap((s, i) => include(s) ? [i] : [])));
888
855
  }
889
856
  /** decompress the given shards + their shared dictionaries concurrently, then open them (see {@link preload}) */
890
857
  async warmShards(need) {
@@ -912,7 +879,7 @@ class SigDatabaseSet {
912
879
  /** read (once) the blob from the shard with the most complete history: a `full` or `history` tier if present */
913
880
  historyBlob(pkg) {
914
881
  const candidates = this.routes.get(pkg);
915
- if (!candidates || candidates.length === 0) {
882
+ if (!candidates?.length) {
916
883
  return undefined;
917
884
  }
918
885
  const full = candidates.find(i => this.manifest.shards[i].tier === 'full' || this.manifest.shards[i].tier === 'history');
@@ -997,10 +964,7 @@ class SigDatabaseSet {
997
964
  /** whether this is an R-core / base package (see {@link SigDatabase.isBaseR}); O(1) via the hoisted metadata */
998
965
  isBaseR(pkg) {
999
966
  const meta = this.manifest.meta?.[pkg];
1000
- if (meta) {
1001
- return meta[3] === 1;
1002
- }
1003
- return this.route(pkg).some(i => this.shard(i).isBaseR(pkg));
967
+ return meta ? meta[3] === 1 : this.route(pkg).some(i => this.shard(i).isBaseR(pkg));
1004
968
  }
1005
969
  /** the download count of the package; O(1) via the hoisted metadata, so no shard has to be unpacked for it */
1006
970
  downloads(pkg) {
@@ -1023,8 +987,8 @@ class SigDatabaseSet {
1023
987
  return undefined;
1024
988
  }
1025
989
  const ver = version ?? (0, sigdb_version_1.newestVersion)(blob, this.manifest.meta?.[pkg]?.[0] ?? '');
1026
- const day = ver !== undefined ? blob.dates[ver] : undefined;
1027
- return day !== undefined ? new Date((0, sigdb_version_1.dayToMillis)(day)) : undefined;
990
+ const day = ver === undefined ? undefined : blob.dates[ver];
991
+ return day === undefined ? undefined : new Date((0, sigdb_version_1.dayToMillis)(day));
1028
992
  }
1029
993
  latestVersion(pkg) {
1030
994
  const blob = this.historyBlob(pkg);
@@ -1056,12 +1020,9 @@ function isSyncOpenable(source) {
1056
1020
  */
1057
1021
  function getSharedSigSourceSync(source) {
1058
1022
  const cached = sharedSources.get(source);
1059
- if (cached) {
1023
+ if (cached || !isSyncOpenable(source)) {
1060
1024
  return cached;
1061
1025
  }
1062
- if (!isSyncOpenable(source)) {
1063
- return undefined;
1064
- }
1065
1026
  const opened = source.endsWith(schema_1.SigDbExt) ? SigDatabase.openSync(source) : SigDatabaseSet.openManifestSync(source);
1066
1027
  sharedSources.set(source, opened);
1067
1028
  return opened;
@@ -1107,7 +1068,8 @@ async function verifyShardedDatabase(manifestFile, opts = {}) {
1107
1068
  }
1108
1069
  // 2. every shard's content hash, recomputed from its re-read blobs, matches the manifest and the file header
1109
1070
  const shardResults = [];
1110
- for (const { ref, db } of set.allShards()) {
1071
+ const mounted = set.allShards();
1072
+ for (const { ref, db } of mounted) {
1111
1073
  const blobs = db.allBlobs();
1112
1074
  // shared-dictionary shards are hashed over blobs+pkgs only; self-contained shards over their whole content
1113
1075
  const actual = ref.dict ? (0, hash_1.shardHash)(blobs, db.index.pkgs) : db.contentHash(blobs);
@@ -1124,7 +1086,7 @@ async function verifyShardedDatabase(manifestFile, opts = {}) {
1124
1086
  }
1125
1087
  // 3. routing covers every package that any shard holds
1126
1088
  const routed = new Set(set.packageNames());
1127
- for (const { ref, db } of set.allShards()) {
1089
+ for (const { ref, db } of mounted) {
1128
1090
  for (const pkg of Object.keys(db.index.pkgs)) {
1129
1091
  if (!routed.has(pkg)) {
1130
1092
  errors.push(`package '${pkg}' in shard '${ref.id}' is not routed by the manifest`);
@@ -27,22 +27,45 @@ export interface SigDbDownloadOptions {
27
27
  readonly repo?: string;
28
28
  /** release version, i.e. tag `sigdb-v<version>` (default the running flowR version); ignored when the committed `sigdb.remote.json` is present, whose `tag` then drives the download */
29
29
  readonly version?: string;
30
- /** progress callback (one line per asset) */
30
+ /** progress callback (one line per step) */
31
31
  readonly onProgress?: (msg: string) => void;
32
32
  readonly force?: boolean;
33
33
  }
34
34
  export interface SigDbDownloadResult {
35
+ /** the release tag the files belong to */
36
+ readonly tag: string;
35
37
  /** the directory the bundle landed in (add it to `solver.sigdb.additionalPaths` to keep it mounted) */
36
38
  readonly dir: string;
37
39
  /** the manifest to mount (richest scope), or `undefined` if the release ships only standalone bundles */
38
40
  readonly manifest: string | undefined;
39
- /** every downloaded file */
41
+ /** every file of the bundle, downloaded now or already cached */
40
42
  readonly files: readonly string[];
43
+ /** the files fetched by this call */
44
+ readonly downloaded: readonly string[];
45
+ readonly bytes: number;
46
+ /** how long the sync took */
47
+ readonly ms: number;
48
+ /** bundle directories of other releases still in the cache (e.g., the one this sync replaces) */
49
+ readonly stale: readonly string[];
41
50
  }
51
+ /** Thrown when some files of a bundle could not be fetched; the others are cached, so a retry only fetches the rest. */
52
+ export declare class SigDbDownloadError extends Error {
53
+ readonly tag: string;
54
+ readonly failed: readonly {
55
+ readonly name: string;
56
+ readonly reason: string;
57
+ }[];
58
+ readonly completed: number;
59
+ constructor(tag: string, failed: readonly {
60
+ readonly name: string;
61
+ readonly reason: string;
62
+ }[], completed: number);
63
+ }
64
+ /** whether the file is a manifest (in any codec); these go last as they reference the shards */
65
+ export declare const isManifestFile: (name: string) => boolean;
42
66
  /**
43
- * Download the signature-database shards into the cache directory and return where they landed. Prefers the
44
- * committed `sigdb.remote.json`, we verify each download by content hash, and **skip shards already
45
- * present with the right hash**.
67
+ * Downloads the signature-database shards into the cache, verified by hash and skipping cached ones. A failing file
68
+ * does not stop the others; a {@link SigDbDownloadError} names what is missing at the end.
46
69
  * Use the returned {@link SigDbDownloadResult.manifest}, or point `solver.sigdb.additionalPaths` at the dir.
47
70
  */
48
71
  export declare function downloadFullSigDb(opts?: SigDbDownloadOptions): Promise<SigDbDownloadResult>;
@@ -60,5 +83,5 @@ export declare function sigDbRemoteRelease(): {
60
83
  } | undefined;
61
84
  /** Fast presence check (existence + byte size only, no hashing) for the shards the committed pointer selects for this runtime; `false` when no pointer is committed or any selected shard is missing/wrong-size. */
62
85
  export declare function sigDbCacheComplete(): boolean;
63
- /** Startup check: `true` when a committed link file lists shards whose cached copies are missing or hash-mismatched */
86
+ /** Startup check: `true` when a committed link file lists shards whose cached copies are missing or mismatched */
64
87
  export declare function sigDbNeedsSync(): boolean;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SigDbRemoteFileName = exports.sha256File = void 0;
6
+ exports.isManifestFile = exports.SigDbDownloadError = exports.SigDbRemoteFileName = exports.sha256File = void 0;
7
7
  exports.selectDownloadVariants = selectDownloadVariants;
8
8
  exports.downloadFullSigDb = downloadFullSigDb;
9
9
  exports.syncedSigDbDir = syncedSigDbDir;
@@ -12,6 +12,7 @@ exports.sigDbCacheComplete = sigDbCacheComplete;
12
12
  exports.sigDbNeedsSync = sigDbNeedsSync;
13
13
  const fs_1 = __importDefault(require("fs"));
14
14
  const path_1 = __importDefault(require("path"));
15
+ const http_1 = __importDefault(require("http"));
15
16
  const https_1 = __importDefault(require("https"));
16
17
  const crypto_1 = __importDefault(require("crypto"));
17
18
  const decompress_1 = require("./decompress");
@@ -24,10 +25,22 @@ function ghHeaders(accept, withAuth) {
24
25
  const token = withAuth ? (process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN) : undefined;
25
26
  return { 'User-Agent': 'flowr', Accept: accept, ...(token ? { Authorization: `Bearer ${token}` } : {}) };
26
27
  }
28
+ /** how long a connection may stay silent before we give up on it */
29
+ const IdleTimeoutMs = 30_000;
30
+ /** attempts per request, so a flaky connection does not fail a whole sync */
31
+ const MaxAttempts = 3;
32
+ /** an HTTP failure; `retryable` for server-side and rate-limit errors */
33
+ class HttpError extends Error {
34
+ retryable;
35
+ constructor(message, retryable) {
36
+ super(message);
37
+ this.retryable = retryable;
38
+ }
39
+ }
27
40
  /** GET following redirects (GitHub asset URLs redirect to a storage host); resolves the final response for streaming */
28
41
  function httpGet(url, accept, redirects = 5, withAuth = true) {
29
42
  return new Promise((resolve, reject) => {
30
- https_1.default.get(url, { headers: ghHeaders(accept, withAuth) }, res => {
43
+ const req = (url.startsWith('http:') ? http_1.default : https_1.default).get(url, { headers: ghHeaders(accept, withAuth) }, res => {
31
44
  const status = res.statusCode ?? 0;
32
45
  if (status >= 300 && status < 400 && res.headers.location && redirects > 0) {
33
46
  res.resume();
@@ -42,11 +55,29 @@ function httpGet(url, accept, redirects = 5, withAuth = true) {
42
55
  }
43
56
  else {
44
57
  res.resume();
45
- reject(new Error(`GET ${url} -> HTTP ${status}`));
58
+ reject(new HttpError(`GET ${url} -> HTTP ${status}`, status >= 500 || status === 429 || status === 408));
46
59
  }
47
- }).on('error', reject);
60
+ });
61
+ req.setTimeout(IdleTimeoutMs, () => req.destroy(new Error(`GET ${url} -> no data for ${IdleTimeoutMs / 1000}s`)));
62
+ req.on('error', reject);
48
63
  });
49
64
  }
65
+ /** runs `attempt` until it succeeds, retrying network and server errors with a growing pause */
66
+ async function withRetries(what, attempt, progress) {
67
+ for (let i = 1;; i++) {
68
+ try {
69
+ return await attempt();
70
+ }
71
+ catch (e) {
72
+ const retryable = !(e instanceof HttpError) || e.retryable;
73
+ if (!retryable || i >= MaxAttempts) {
74
+ throw e;
75
+ }
76
+ progress(`${what} failed (${e.message}), retry ${i}/${MaxAttempts - 1}`);
77
+ await new Promise(r => setTimeout(r, 1000 * i));
78
+ }
79
+ }
80
+ }
50
81
  async function readJson(url) {
51
82
  const res = await httpGet(url, 'application/vnd.github+json');
52
83
  const chunks = [];
@@ -55,22 +86,62 @@ async function readJson(url) {
55
86
  }
56
87
  return JSON.parse(Buffer.concat(chunks).toString('utf8'));
57
88
  }
58
- async function downloadTo(url, dest) {
59
- const res = await httpGet(url, 'application/octet-stream');
60
- await new Promise((resolve, reject) => {
61
- const out = fs_1.default.createWriteStream(dest);
62
- res.on('error', reject);
63
- out.on('error', reject).on('finish', () => out.close(err => err ? reject(err) : resolve()));
64
- res.pipe(out);
65
- });
89
+ const mb = (bytes) => `${(bytes / 1e6).toFixed(1)} MB`;
90
+ const rate = (bytes, ms) => `${(bytes / 1e6 / Math.max(ms / 1000, 0.001)).toFixed(1)} MB/s`;
91
+ /** Download `url` to `dest` via a temporary file, so a partial or corrupt file never lands there (checked against `sha256`, if given). */
92
+ async function downloadTo(url, dest, name, progress, expected) {
93
+ const part = `${dest}.${process.pid}.part`;
94
+ const start = Date.now();
95
+ try {
96
+ const res = await httpGet(url, 'application/octet-stream');
97
+ const total = expected?.bytes ?? Number(res.headers['content-length'] ?? 0);
98
+ let received = 0;
99
+ let nextReport = 0.25;
100
+ const hash = crypto_1.default.createHash('sha256');
101
+ res.on('data', (chunk) => {
102
+ received += chunk.length;
103
+ hash.update(chunk);
104
+ if (total > 5e6 && received / total >= nextReport && received < total) {
105
+ progress(` ${name}: ${Math.floor(received / total * 100)}% (${mb(received)} of ${mb(total)}, ${rate(received, Date.now() - start)})`);
106
+ nextReport += 0.25;
107
+ }
108
+ });
109
+ await new Promise((resolve, reject) => {
110
+ const out = fs_1.default.createWriteStream(part);
111
+ res.on('error', reject).on('aborted', () => reject(new Error(`connection closed after ${mb(received)}`)));
112
+ out.on('error', reject).on('finish', () => out.close(err => err ? reject(err) : resolve()));
113
+ res.pipe(out);
114
+ });
115
+ if (expected === undefined && total > 0 && received !== total) {
116
+ throw new Error(`expected ${total} bytes but got ${received}`);
117
+ }
118
+ if (expected !== undefined) {
119
+ if (received !== expected.bytes) {
120
+ throw new Error(`expected ${expected.bytes} bytes but got ${received}`);
121
+ }
122
+ const actual = hash.digest('hex');
123
+ if (actual !== expected.sha256) {
124
+ throw new Error(`sha256 mismatch (expected ${expected.sha256.slice(0, 12)}..., got ${actual.slice(0, 12)}...); the download is corrupt or sigdb.remote.json is outdated`);
125
+ }
126
+ }
127
+ fs_1.default.renameSync(part, dest);
128
+ return received;
129
+ }
130
+ finally {
131
+ fs_1.default.rmSync(part, { force: true });
132
+ }
66
133
  }
67
134
  /** hex sha256 of a file's contents (shared by the runtime verify and the `sigdb-remote` pointer generator) */
68
135
  const sha256File = (p) => crypto_1.default.createHash('sha256').update(fs_1.default.readFileSync(p)).digest('hex');
69
136
  exports.sha256File = sha256File;
70
137
  /** the committed link file naming every downloadable shard (base floor + CRAN sets); only this pointer is committed */
71
138
  exports.SigDbRemoteFileName = 'sigdb.remote.json';
72
- /** locate the committed `sigdb.remote.json` link file in the sigdb data dir (dev `src`, built `dist`) */
139
+ /** locate the committed `sigdb.remote.json` link file in the sigdb data dir (dev `src`, built `dist`), or the one `$FLOWR_SIGDB_REMOTE` names */
73
140
  function findRemotePointer() {
141
+ const override = process.env.FLOWR_SIGDB_REMOTE;
142
+ if (override) {
143
+ return fs_1.default.existsSync(override) ? override : undefined;
144
+ }
74
145
  const candidates = [
75
146
  path_1.default.join(__dirname, '../../data/sigdb', exports.SigDbRemoteFileName), // src/ and dist/src/ layouts (same depth)
76
147
  path_1.default.join(process.cwd(), 'src/data/sigdb', exports.SigDbRemoteFileName),
@@ -86,8 +157,8 @@ function findRemotePointer() {
86
157
  });
87
158
  }
88
159
  const readPointer = (p) => JSON.parse(fs_1.default.readFileSync(p, 'utf8'));
89
- /** the direct release-asset CDN URL -- bypasses the REST API (and its rate limit) entirely */
90
- const assetUrl = (repo, tag, name) => `https://github.com/${repo}/releases/download/${tag}/${encodeURIComponent(name)}`;
160
+ /** the direct release-asset URL, which avoids the REST API rate limit; `$FLOWR_SIGDB_MIRROR` replaces the host */
161
+ const assetUrl = (repo, tag, name) => `${process.env.FLOWR_SIGDB_MIRROR ?? 'https://github.com'}/${repo}/releases/download/${tag}/${encodeURIComponent(name)}`;
91
162
  /** runtime-decodable variant extensions, most-preferred first, ending in plain (`''`) as a last resort */
92
163
  function downloadVariantOrder() {
93
164
  return [...(0, codec_1.readableExtsPreferred)(), ''];
@@ -123,70 +194,150 @@ function selectDownloadVariants(names) {
123
194
  /** pick the richest manifest among downloaded files (a `full`/scope manifest first, else any) */
124
195
  const pickManifest = (files) => files.find(f => new RegExp(`full\\.manifest\\.json${codec_1.CompressedExtPattern}$`).test(f))
125
196
  ?? files.find(f => new RegExp(`\\.manifest\\.json${codec_1.CompressedExtPattern}$`).test(f));
197
+ /** Thrown when some files of a bundle could not be fetched; the others are cached, so a retry only fetches the rest. */
198
+ class SigDbDownloadError extends Error {
199
+ tag;
200
+ failed;
201
+ completed;
202
+ constructor(tag, failed, completed) {
203
+ super(`could not fetch ${failed.length} of ${failed.length + completed} file(s) of ${tag}: ${failed.map(f => `${f.name} (${f.reason})`).join('; ')}`);
204
+ this.tag = tag;
205
+ this.failed = failed;
206
+ this.completed = completed;
207
+ }
208
+ }
209
+ exports.SigDbDownloadError = SigDbDownloadError;
210
+ /** whether the file is a manifest (in any codec); these go last as they reference the shards */
211
+ const isManifestFile = (name) => new RegExp(`\\.manifest\\.json${codec_1.CompressedExtPattern}$`).test(name);
212
+ exports.isManifestFile = isManifestFile;
213
+ /** the bundle directories of other tags in the cache, so a sync can say what it leaves behind */
214
+ function staleBundleDirs(current) {
215
+ const bundles = path_1.default.dirname(current);
216
+ try {
217
+ return fs_1.default.readdirSync(bundles, { withFileTypes: true })
218
+ .filter(e => e.isDirectory() && path_1.default.join(bundles, e.name) !== current)
219
+ .map(e => path_1.default.join(bundles, e.name));
220
+ }
221
+ catch {
222
+ return [];
223
+ }
224
+ }
225
+ /** whether the cached copy at `dest` can be kept */
226
+ function isCached(dest, file) {
227
+ try {
228
+ const size = fs_1.default.statSync(dest).size;
229
+ if (file.expected !== undefined) {
230
+ return size === file.expected.bytes && (0, exports.sha256File)(dest) === file.expected.sha256;
231
+ }
232
+ return file.size === undefined || size === file.size;
233
+ }
234
+ catch {
235
+ return false;
236
+ }
237
+ }
238
+ async function syncFiles(tag, repo, planned, opts) {
239
+ const progress = opts.onProgress ?? (() => { });
240
+ const start = Date.now();
241
+ const dir = path_1.default.join((0, decompress_1.sigDbCacheDir)(), 'bundles', tag);
242
+ fs_1.default.mkdirSync(dir, { recursive: true });
243
+ const ordered = [...planned.filter(p => !(0, exports.isManifestFile)(p.name)), ...planned.filter(p => (0, exports.isManifestFile)(p.name))];
244
+ const missing = ordered.filter(p => opts.force || !isCached(path_1.default.join(dir, p.name), p));
245
+ const toFetch = missing.reduce((sum, p) => sum + (p.expected?.bytes ?? p.size ?? 0), 0);
246
+ progress(`signature database ${tag} from ${repo}: ${ordered.length} file(s), ${ordered.length - missing.length} up to date, ${missing.length} to fetch (${mb(toFetch)}) into ${dir}`);
247
+ const files = [];
248
+ const downloaded = [];
249
+ const failed = [];
250
+ let bytes = 0;
251
+ for (const file of ordered) {
252
+ const dest = path_1.default.join(dir, file.name);
253
+ if (!missing.includes(file)) {
254
+ files.push(dest);
255
+ continue;
256
+ }
257
+ if ((0, exports.isManifestFile)(file.name) && failed.length > 0) {
258
+ failed.push({ name: file.name, reason: 'skipped, as the shards it references are incomplete' });
259
+ continue;
260
+ }
261
+ const size = file.expected?.bytes ?? file.size;
262
+ progress(`downloading ${file.name}${size === undefined ? '' : ` (${mb(size)})`}`);
263
+ const fileStart = Date.now();
264
+ try {
265
+ const got = await withRetries(file.name, () => downloadTo(file.url, dest, file.name, progress, file.expected), progress);
266
+ bytes += got;
267
+ progress(` ${file.name}: done in ${((Date.now() - fileStart) / 1000).toFixed(1)}s (${rate(got, Date.now() - fileStart)})${file.expected ? ', checksum verified' : ''}`);
268
+ files.push(dest);
269
+ downloaded.push(dest);
270
+ }
271
+ catch (e) {
272
+ const reason = e.message;
273
+ progress(` ${file.name}: failed (${reason})`);
274
+ failed.push({ name: file.name, reason });
275
+ }
276
+ }
277
+ const ms = Date.now() - start;
278
+ if (failed.length > 0) {
279
+ throw new SigDbDownloadError(tag, failed, files.length);
280
+ }
281
+ /* the bundle synced last takes precedence over the others in the cache, even if nothing had to be fetched */
282
+ const now = new Date();
283
+ fs_1.default.utimesSync(dir, now, now);
284
+ const stale = staleBundleDirs(dir);
285
+ progress(downloaded.length === 0
286
+ ? `signature database ${tag} is up to date`
287
+ : `signature database ${tag}: fetched ${downloaded.length} file(s), ${mb(bytes)} in ${(ms / 1000).toFixed(1)}s`);
288
+ if (stale.length > 0) {
289
+ progress(`the cache still holds ${stale.length} bundle(s) of other releases: ${stale.map(d => path_1.default.basename(d)).join(', ')} (in ${path_1.default.dirname(dir)}); the most recently synced one takes precedence, delete the others to free the space`);
290
+ }
291
+ return { tag, dir, manifest: pickManifest(files), files, downloaded, bytes, ms, stale };
292
+ }
293
+ /** read the committed link file, naming it in the error when it is broken */
294
+ function readPointerChecked(p) {
295
+ let remote;
296
+ try {
297
+ remote = readPointer(p);
298
+ }
299
+ catch (e) {
300
+ throw new Error(`cannot read the signature database link file ${p}: ${e.message}`, { cause: e });
301
+ }
302
+ if (typeof remote.tag !== 'string' || typeof remote.shards !== 'object' || remote.shards === null) {
303
+ throw new Error(`the signature database link file ${p} names no tag or shards`);
304
+ }
305
+ return remote;
306
+ }
126
307
  /**
127
- * Download the signature-database shards into the cache directory and return where they landed. Prefers the
128
- * committed `sigdb.remote.json`, we verify each download by content hash, and **skip shards already
129
- * present with the right hash**.
308
+ * Downloads the signature-database shards into the cache, verified by hash and skipping cached ones. A failing file
309
+ * does not stop the others; a {@link SigDbDownloadError} names what is missing at the end.
130
310
  * Use the returned {@link SigDbDownloadResult.manifest}, or point `solver.sigdb.additionalPaths` at the dir.
131
311
  */
132
312
  async function downloadFullSigDb(opts = {}) {
133
313
  const progress = opts.onProgress ?? (() => { });
134
314
  const pointerPath = findRemotePointer();
135
315
  if (pointerPath) {
136
- const remote = readPointer(pointerPath);
316
+ const remote = readPointerChecked(pointerPath);
137
317
  const repo = opts.repo ?? remote.repo ?? DefaultRepo;
138
- const tag = remote.tag;
139
- const dir = path_1.default.join((0, decompress_1.sigDbCacheDir)(), 'bundles', tag);
140
- fs_1.default.mkdirSync(dir, { recursive: true });
141
318
  // one variant per logical shard/dictionary -- the best this runtime can decompress (never both codecs)
142
- const picked = selectDownloadVariants(Object.keys(remote.shards));
143
- progress(`syncing ${picked.length} shards for ${tag} from ${repo}`);
144
- const files = [];
145
- for (const name of picked) {
146
- const meta = remote.shards[name];
147
- const dest = path_1.default.join(dir, name);
148
- if (!opts.force && fs_1.default.existsSync(dest) && (0, exports.sha256File)(dest) === meta.sha256) {
149
- progress(`have ${name}`);
150
- }
151
- else {
152
- progress(`downloading ${name} (${(meta.bytes / 1e6).toFixed(1)} MB)`);
153
- await downloadTo(assetUrl(repo, tag, name), dest);
154
- if ((0, exports.sha256File)(dest) !== meta.sha256) {
155
- throw new Error(`sha256 mismatch for ${name} (${tag}); the download is corrupt -- retry, or regenerate sigdb.remote.json`);
156
- }
157
- }
158
- files.push(dest);
159
- }
160
- return { dir, manifest: pickManifest(files), files };
319
+ const planned = selectDownloadVariants(Object.keys(remote.shards)).map(name => ({
320
+ name, url: assetUrl(repo, remote.tag, name), expected: remote.shards[name]
321
+ }));
322
+ return syncFiles(remote.tag, repo, planned, opts);
161
323
  }
162
324
  // fallback: no committed link file -> list the release via the API and download by size
163
325
  const repo = opts.repo ?? DefaultRepo;
164
326
  const version = opts.version ?? (0, version_1.flowrVersion)().toString();
165
327
  const tag = `sigdb-v${version}`;
166
- progress(`fetching release ${tag} from ${repo}`);
167
- const release = await readJson(`https://api.github.com/repos/${repo}/releases/tags/${tag}`);
328
+ progress(`no sigdb.remote.json found, listing release ${tag} of ${repo}`);
329
+ const release = await withRetries(`listing ${tag}`, () => readJson(`https://api.github.com/repos/${repo}/releases/tags/${tag}`), progress);
168
330
  const assets = (release.assets ?? [])
169
331
  .filter(a => a.name.endsWith('.br') || a.name.endsWith('.zst') || a.name.endsWith('.manifest.json'));
170
332
  if (assets.length === 0) {
171
333
  throw new Error(`release ${tag} in ${repo} has no signature-database assets${typeof release.message === 'string' ? ` (${release.message})` : ''}`);
172
334
  }
173
- const dir = path_1.default.join((0, decompress_1.sigDbCacheDir)(), 'bundles', tag);
174
- fs_1.default.mkdirSync(dir, { recursive: true });
175
335
  const byName = new Map(assets.map(a => [a.name, a]));
176
- const files = [];
177
- for (const name of selectDownloadVariants(byName.keys())) {
336
+ const planned = selectDownloadVariants(byName.keys()).map(name => {
178
337
  const a = byName.get(name);
179
- const dest = path_1.default.join(dir, name);
180
- if (!opts.force && fs_1.default.existsSync(dest) && fs_1.default.statSync(dest).size === a.size) {
181
- progress(`have ${name}`);
182
- }
183
- else {
184
- progress(`downloading ${name} (${(a.size / 1e6).toFixed(1)} MB)`);
185
- await downloadTo(a.browser_download_url, dest);
186
- }
187
- files.push(dest);
188
- }
189
- return { dir, manifest: pickManifest(files), files };
338
+ return { name, url: a.browser_download_url, size: a.size };
339
+ });
340
+ return syncFiles(tag, repo, planned, opts);
190
341
  }
191
342
  /**
192
343
  * The cache dir a {@link downloadFullSigDb} for the committed link file would populate, or `undefined` if no
@@ -237,7 +388,7 @@ function sigDbCacheComplete() {
237
388
  return false;
238
389
  }
239
390
  }
240
- /** Startup check: `true` when a committed link file lists shards whose cached copies are missing or hash-mismatched */
391
+ /** Startup check: `true` when a committed link file lists shards whose cached copies are missing or mismatched */
241
392
  function sigDbNeedsSync() {
242
393
  const pointerPath = findRemotePointer();
243
394
  if (!pointerPath) {
@@ -245,11 +396,8 @@ function sigDbNeedsSync() {
245
396
  }
246
397
  try {
247
398
  const remote = readPointer(pointerPath);
248
- const dir = path_1.default.join((0, decompress_1.sigDbCacheDir)(), 'bundles', remote.tag);
249
- return Object.entries(remote.shards).some(([name, meta]) => {
250
- const dest = path_1.default.join(dir, name);
251
- return !fs_1.default.existsSync(dest) || (0, exports.sha256File)(dest) !== meta.sha256;
252
- });
399
+ const dir = path_1.default.join((0, decompress_1.sigDbCacheDir)(undefined, false), 'bundles', remote.tag);
400
+ return selectDownloadVariants(Object.keys(remote.shards)).some(name => !isCached(path_1.default.join(dir, name), { name, url: '', expected: remote.shards[name] }));
253
401
  }
254
402
  catch {
255
403
  return false;
@@ -18,13 +18,12 @@ function filterLineParser(type) {
18
18
  function singleCriterionLineParser(type, label, extra) {
19
19
  return function (output, line, _config) {
20
20
  const criterion = (0, slice_query_parser_1.sliceCriteriaParser)(line[0]);
21
- const fields = extra?.(line);
22
21
  if (!criterion || criterion.length !== 1) {
23
22
  output.stderr(output.formatter.format(`Invalid ${label} query format, a single slicing criterion must be given in the form "(criterion1)"`, { color: 1 /* Colors.Red */, effect: ansi_1.ColorEffect.Foreground, style: 1 /* FontStyles.Bold */ }));
24
23
  return { query: [] };
25
24
  }
26
25
  return {
27
- query: [{ type, criterion: criterion[0], ...fields }],
26
+ query: [{ type, criterion: criterion[0], ...extra?.(line) }],
28
27
  rCode: (0, slice_query_parser_1.queryLineCode)(line)
29
28
  };
30
29
  };
@@ -45,7 +45,7 @@ function absintQueryCompleter(line, startingNewArg, _config) {
45
45
  return { completions: [] };
46
46
  }
47
47
  function absintQueryLineParser(output, line, _config) {
48
- const type = line[0].toLowerCase();
48
+ const type = (line[0] ?? '').toLowerCase();
49
49
  if (!record_1.Record.has(exports.AbsintQueryInferences, type)) {
50
50
  output.stderr(output.formatter.format(`Invalid inference type "${type}", must be one of ${record_1.Record.keys(exports.AbsintQueryInferences).map(type => `"${type}"`).join(', ')}`, { color: 1 /* Colors.Red */, effect: ansi_1.ColorEffect.Foreground, style: 1 /* FontStyles.Bold */ }));
51
51
  return { query: [] };
@@ -4,5 +4,7 @@ export declare enum CascadeAction {
4
4
  /** The action is to continue the cascade */
5
5
  Continue = "continue",
6
6
  /** The action is to skip the current node */
7
- Skip = "skip"
7
+ Skip = "skip",
8
+ /** The action is to stop the search along this path without linking the current node */
9
+ Block = "block"
8
10
  }
@@ -9,5 +9,7 @@ var CascadeAction;
9
9
  CascadeAction["Continue"] = "continue";
10
10
  /** The action is to skip the current node */
11
11
  CascadeAction["Skip"] = "skip";
12
+ /** The action is to stop the search along this path without linking the current node */
13
+ CascadeAction["Block"] = "block";
12
14
  })(CascadeAction || (exports.CascadeAction = CascadeAction = {}));
13
15
  //# sourceMappingURL=cascade-action.js.map