@eagleoutice/flowr 2.11.1 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/README.md +193 -263
  2. package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
  3. package/abstract-interpretation/domains/set-range-domain.js +1 -1
  4. package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
  5. package/benchmark/slicer.d.ts +1 -1
  6. package/benchmark/slicer.js +3 -1
  7. package/benchmark/summarizer/second-phase/graph.js +5 -0
  8. package/cli/common/options.d.ts +8 -0
  9. package/cli/common/options.js +2 -0
  10. package/cli/common/scripts-info.d.ts +8 -0
  11. package/cli/repl/commands/repl-commands.d.ts +1 -0
  12. package/cli/repl/commands/repl-commands.js +66 -15
  13. package/cli/repl/commands/repl-dataflow.js +48 -4
  14. package/cli/repl/commands/repl-main.d.ts +2 -0
  15. package/cli/repl/commands/repl-main.js +5 -0
  16. package/cli/repl/commands/repl-query.d.ts +4 -1
  17. package/cli/repl/commands/repl-query.js +72 -22
  18. package/cli/repl/commands/repl-signature.d.ts +7 -0
  19. package/cli/repl/commands/repl-signature.js +119 -0
  20. package/cli/repl/core.d.ts +8 -1
  21. package/cli/repl/core.js +46 -6
  22. package/cli/repl/ghost-hint.d.ts +37 -0
  23. package/cli/repl/ghost-hint.js +72 -0
  24. package/cli/repl/parser/slice-query-parser.d.ts +11 -1
  25. package/cli/repl/parser/slice-query-parser.js +45 -16
  26. package/cli/repl/print-version.d.ts +2 -4
  27. package/cli/repl/print-version.js +41 -23
  28. package/cli/repl/server/connection.js +19 -17
  29. package/cli/slicer-app.d.ts +2 -0
  30. package/cli/slicer-app.js +3 -3
  31. package/cli/wiki.d.ts +2 -2
  32. package/cli/wiki.js +2 -2
  33. package/config.d.ts +63 -2
  34. package/config.js +64 -8
  35. package/control-flow/cfg-dead-code.js +0 -1
  36. package/control-flow/control-flow-graph.js +6 -6
  37. package/control-flow/diff-cfg.js +2 -2
  38. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  39. package/core/print/slice-diff-ansi.js +8 -8
  40. package/core/steps/all/core/20-dataflow.d.ts +2 -2
  41. package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
  42. package/core/steps/all/static-slicing/00-slice.js +1 -1
  43. package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
  44. package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
  45. package/core/steps/pipeline/default-pipelines.d.ts +20 -16
  46. package/data/r-base-packages.generated.d.ts +44 -0
  47. package/data/r-base-packages.generated.js +32 -0
  48. package/data/r-base-primitives.generated.d.ts +1 -0
  49. package/data/r-base-primitives.generated.js +15 -0
  50. package/data/sigdb/sigdb.remote.json +112 -0
  51. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  52. package/dataflow/environments/built-in-proc-name.js +4 -0
  53. package/dataflow/environments/built-in.d.ts +14 -4
  54. package/dataflow/environments/built-in.js +13 -2
  55. package/dataflow/environments/data-masking-functions.d.ts +12 -0
  56. package/dataflow/environments/data-masking-functions.js +46 -0
  57. package/dataflow/environments/default-builtin-config.d.ts +72 -19
  58. package/dataflow/environments/default-builtin-config.js +48 -14
  59. package/dataflow/environments/diff.js +1 -1
  60. package/dataflow/environments/environment.js +1 -2
  61. package/dataflow/environments/identifier.d.ts +11 -4
  62. package/dataflow/environments/identifier.js +28 -10
  63. package/dataflow/environments/resolve-by-name.js +16 -2
  64. package/dataflow/extractor.js +6 -3
  65. package/dataflow/graph/call-graph.d.ts +2 -2
  66. package/dataflow/graph/df-helper.d.ts +4 -4
  67. package/dataflow/graph/diff-dataflow-graph.js +2 -2
  68. package/dataflow/graph/edge.d.ts +3 -3
  69. package/dataflow/graph/edge.js +3 -3
  70. package/dataflow/graph/graph-helper.d.ts +2 -2
  71. package/dataflow/internal/linker.js +1 -1
  72. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
  73. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
  74. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
  75. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
  80. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
  81. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
  83. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
  84. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
  85. package/dataflow/internal/process/functions/call/common.js +8 -1
  86. package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
  87. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
  88. package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
  89. package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
  90. package/dataflow/internal/process/functions/process-argument.js +12 -1
  91. package/dataflow/internal/process/process-named-call.d.ts +18 -1
  92. package/dataflow/internal/process/process-named-call.js +94 -0
  93. package/dataflow/processor.d.ts +18 -0
  94. package/documentation/data/faq/faqs.js +5 -1
  95. package/documentation/doc-capabilities.js +1 -1
  96. package/documentation/doc-util/doc-cli-option.d.ts +10 -0
  97. package/documentation/doc-util/doc-cli-option.js +23 -0
  98. package/documentation/doc-util/doc-dfg.js +2 -1
  99. package/documentation/doc-util/doc-query.d.ts +9 -3
  100. package/documentation/doc-util/doc-query.js +9 -4
  101. package/documentation/wiki-dataflow-graph.js +8 -5
  102. package/documentation/wiki-interface.js +3 -1
  103. package/documentation/wiki-linter.js +1 -1
  104. package/documentation/wiki-linting-and-testing.js +4 -1
  105. package/documentation/wiki-mk/doc-context.d.ts +14 -0
  106. package/documentation/wiki-mk/doc-context.js +3 -0
  107. package/documentation/wiki-mk/doc-maker.js +3 -1
  108. package/documentation/wiki-query.js +19 -1
  109. package/documentation/wiki-setup.js +10 -7
  110. package/documentation/wiki-signature-database.d.ts +16 -0
  111. package/documentation/wiki-signature-database.js +293 -0
  112. package/linter/linter-format.d.ts +7 -0
  113. package/linter/linter-rules.d.ts +10 -9
  114. package/linter/rules/naming-convention.d.ts +1 -0
  115. package/linter/rules/naming-convention.js +2 -0
  116. package/linter/rules/no-leaked-credentials.js +1 -2
  117. package/linter/rules/roxygen-arguments.js +18 -5
  118. package/linter/rules/stop-with-call-arg.js +2 -2
  119. package/linter/rules/undefined-symbol-util.d.ts +36 -0
  120. package/linter/rules/undefined-symbol-util.js +149 -0
  121. package/linter/rules/undefined-symbol.d.ts +58 -17
  122. package/linter/rules/undefined-symbol.js +143 -33
  123. package/linter/rules/unused-definition.d.ts +8 -1
  124. package/linter/rules/unused-definition.js +126 -1
  125. package/package.json +22 -10
  126. package/project/context/abstract-flowr-analyzer-context.js +7 -1
  127. package/project/context/flowr-analyzer-context.d.ts +8 -0
  128. package/project/context/flowr-analyzer-context.js +10 -0
  129. package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
  130. package/project/context/flowr-analyzer-dependencies-context.js +51 -2
  131. package/project/context/flowr-analyzer-files-context.d.ts +1 -0
  132. package/project/context/flowr-analyzer-files-context.js +2 -1
  133. package/project/context/flowr-analyzer-functions-context.js +1 -1
  134. package/project/context/flowr-file.d.ts +5 -0
  135. package/project/context/flowr-file.js +5 -0
  136. package/project/flowr-analyzer-builder.js +12 -2
  137. package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
  138. package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
  139. package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
  140. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
  141. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
  142. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
  143. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
  144. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
  145. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
  146. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
  147. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
  148. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
  149. package/project/plugins/package-version-plugins/package.d.ts +5 -3
  150. package/project/plugins/package-version-plugins/package.js +27 -25
  151. package/project/plugins/plugin-registry.d.ts +3 -2
  152. package/project/plugins/plugin-registry.js +4 -2
  153. package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
  154. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
  155. package/project/sigdb/build.d.ts +131 -0
  156. package/project/sigdb/build.js +628 -0
  157. package/project/sigdb/codec.d.ts +51 -0
  158. package/project/sigdb/codec.js +122 -0
  159. package/project/sigdb/decode.d.ts +58 -0
  160. package/project/sigdb/decode.js +129 -0
  161. package/project/sigdb/decompress.d.ts +44 -0
  162. package/project/sigdb/decompress.js +176 -0
  163. package/project/sigdb/hash.d.ts +9 -0
  164. package/project/sigdb/hash.js +54 -0
  165. package/project/sigdb/index-format.d.ts +40 -0
  166. package/project/sigdb/index-format.js +28 -0
  167. package/project/sigdb/manifest.d.ts +68 -0
  168. package/project/sigdb/manifest.js +146 -0
  169. package/project/sigdb/reader.d.ts +250 -0
  170. package/project/sigdb/reader.js +692 -0
  171. package/project/sigdb/schema.d.ts +196 -0
  172. package/project/sigdb/schema.js +33 -0
  173. package/project/sigdb/sigdb-download.d.ts +65 -0
  174. package/project/sigdb/sigdb-download.js +237 -0
  175. package/project/sigdb/signature-match.d.ts +26 -0
  176. package/project/sigdb/signature-match.js +40 -0
  177. package/project/sigdb/version.d.ts +20 -0
  178. package/project/sigdb/version.js +55 -0
  179. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
  180. package/queries/catalog/config-query/config-query-format.d.ts +3 -1
  181. package/queries/catalog/config-query/config-query-format.js +68 -9
  182. package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
  183. package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
  184. package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
  185. package/queries/catalog/linter-query/linter-query-executor.js +6 -1
  186. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
  187. package/queries/catalog/linter-query/linter-query-format.js +40 -8
  188. package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
  189. package/queries/catalog/project-query/project-query-executor.js +96 -4
  190. package/queries/catalog/project-query/project-query-format.d.ts +44 -0
  191. package/queries/catalog/project-query/project-query-format.js +33 -2
  192. package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
  193. package/queries/catalog/signature-query/signature-query-executor.js +461 -0
  194. package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
  195. package/queries/catalog/signature-query/signature-query-format.js +76 -0
  196. package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
  197. package/queries/catalog/signature-query/signature-query-render.js +155 -0
  198. package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
  199. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
  200. package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
  201. package/queries/query-print.js +5 -0
  202. package/queries/query.d.ts +10 -1
  203. package/queries/query.js +5 -2
  204. package/r-bridge/init.js +5 -1
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
  207. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
  208. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
  209. package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
  210. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
  211. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
  212. package/r-bridge/parser.d.ts +2 -0
  213. package/r-bridge/retriever.js +4 -1
  214. package/r-bridge/roxygen2/documentation-provider.js +2 -1
  215. package/r-bridge/shell.d.ts +5 -0
  216. package/r-bridge/shell.js +17 -1
  217. package/reconstruct/inline/source-inline-map.d.ts +48 -0
  218. package/reconstruct/inline/source-inline-map.js +94 -0
  219. package/reconstruct/reconstruct.d.ts +19 -2
  220. package/reconstruct/reconstruct.js +79 -16
  221. package/search/search-executor/search-generators.js +5 -22
  222. package/search/search-executor/search-transformer.js +10 -6
  223. package/slicing/criterion/parse.d.ts +22 -4
  224. package/slicing/criterion/parse.js +125 -18
  225. package/slicing/static/slice-call.d.ts +24 -1
  226. package/slicing/static/slice-call.js +90 -0
  227. package/slicing/static/static-slicer.d.ts +7 -0
  228. package/slicing/static/static-slicer.js +38 -3
  229. package/util/collections/arrays.d.ts +4 -5
  230. package/util/collections/arrays.js +7 -18
  231. package/util/hash.d.ts +14 -0
  232. package/util/hash.js +31 -0
  233. package/util/mermaid/dfg.d.ts +7 -2
  234. package/util/mermaid/dfg.js +53 -13
  235. package/util/r-base-packages.d.ts +19 -0
  236. package/util/r-base-packages.js +72 -0
  237. package/util/r-license.js +2 -10
  238. package/util/r-version.d.ts +45 -15
  239. package/util/r-version.js +97 -36
  240. package/util/range.d.ts +15 -0
  241. package/util/range.js +39 -0
  242. package/util/schema.d.ts +10 -0
  243. package/util/schema.js +22 -0
  244. package/util/text/ansi.d.ts +3 -0
  245. package/util/text/ansi.js +10 -0
  246. package/util/text/args.js +1 -2
  247. package/util/version.js +28 -8
  248. package/data/pkgdb/pkgdb-latest.json.br +0 -0
  249. package/data/pkgdb/pkgdb-tiny.json.br +0 -0
  250. package/documentation/wiki-package-database.d.ts +0 -9
  251. package/documentation/wiki-package-database.js +0 -63
  252. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
  253. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -176
  254. package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
  255. package/project/plugins/package-version-plugins/pkgdb.js +0 -370
@@ -3,13 +3,29 @@ 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.ProjectQueryDefinition = void 0;
6
+ exports.ProjectQueryDefinition = exports.ProjectKind = void 0;
7
7
  const project_query_executor_1 = require("./project-query-executor");
8
8
  const ansi_1 = require("../../../util/text/ansi");
9
9
  const time_1 = require("../../../util/text/time");
10
10
  const joi_1 = __importDefault(require("joi"));
11
11
  const r_author_1 = require("../../../util/r-author");
12
12
  const r_license_1 = require("../../../util/r-license");
13
+ /** The kind of project that flowR is analyzing. */
14
+ var ProjectKind;
15
+ (function (ProjectKind) {
16
+ /** An R package (has a `DESCRIPTION` file). */
17
+ ProjectKind["Package"] = "package";
18
+ /** A single R script. */
19
+ ProjectKind["Script"] = "script";
20
+ /** A Shiny application (`app.R`, or `ui.R` together with `server.R`). */
21
+ ProjectKind["ShinyApp"] = "shiny-app";
22
+ /** A notebook or literate document (`.ipynb`, `.Rmd`, `.qmd`, `.rnw`). */
23
+ ProjectKind["Notebook"] = "notebook";
24
+ /** A multi-file project that is not a package. */
25
+ ProjectKind["Project"] = "project";
26
+ /** The kind could not be determined (e.g. before the files are known). */
27
+ ProjectKind["Unknown"] = "unknown";
28
+ })(ProjectKind || (exports.ProjectKind = ProjectKind = {}));
13
29
  function addSuffix(count, singular = '', plural = 's') {
14
30
  return `${count === 1 ? singular : plural}`;
15
31
  }
@@ -21,6 +37,9 @@ exports.ProjectQueryDefinition = {
21
37
  if (out.name) {
22
38
  result.push(` ╰ Project Name: ${out.name}`);
23
39
  }
40
+ if (out.kind) {
41
+ result.push(` ╰ Kind: ${out.kind}`);
42
+ }
24
43
  if (out.version) {
25
44
  result.push(` ╰ Version: ${out.version}`);
26
45
  }
@@ -53,8 +72,20 @@ exports.ProjectQueryDefinition = {
53
72
  }
54
73
  }
55
74
  }
75
+ if (out.dependencies) {
76
+ const d = out.dependencies;
77
+ result.push(` ╰ Dependencies: ${d.runtime} runtime (${d.imports} imports, ${d.depends} depends, ${d.linkingTo} linkingTo), ${d.suggests} suggested`);
78
+ result.push(` ╰ ${d.base} base/recommended, ${d.covered}/${Math.max(d.runtime - d.base, 0)} non-base covered by the package database`);
79
+ if (d.first.length > 0) {
80
+ const names = d.first.map(f => f.dbVersion ? `${f.name}@${f.dbVersion}` : f.name).join(', ');
81
+ result.push(` ╰ e.g. ${names}${d.runtime > d.first.length ? ', ...' : ''}`);
82
+ }
83
+ if (d.rVersion) {
84
+ result.push(` ╰ Requires R ${d.rVersion}`);
85
+ }
86
+ }
56
87
  if (analyzer.peekDataflow() === undefined) {
57
- result.push(formatter.format(' ╰ Dataflow Analysis not performed', { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground }));
88
+ result.push(formatter.format(' ╰ Dataflow not performed (run `:df#`, then re-run this query, or pass "withDf": true)', { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground }));
58
89
  }
59
90
  else {
60
91
  result.push(` ╰ Dataflow Analysis considered ${out.files.length} file${out.files.length === 1 ? '' : 's'}`);
@@ -0,0 +1,29 @@
1
+ import type { BasicQueryData } from '../../base-query-format';
2
+ import type { SignatureQuery, SignatureQueryResult, SignaturePackageView, SignatureFunctionView } from './signature-query-format';
3
+ import { type PackageSignatureSource } from '../../../project/sigdb/reader';
4
+ import type { CommandCompletions } from '../../../cli/repl/core';
5
+ /** the CRAN package landing page (only meaningful for CRAN packages, not base R) */
6
+ export declare function cranPageUrl(pkg: string): string;
7
+ /** deep-link a definition into the CRAN mirror at the package's version tag (falling back to `HEAD`) */
8
+ export declare function cranMirrorSourceUrl(pkg: string, version: string | undefined, file: string, line?: number): string;
9
+ /**
10
+ * The detailed view of a single function within a package: its signature (parameters, forced/optional,
11
+ * defaults), properties, definition location, call graph, and -- for a CRAN package -- a deep link into the
12
+ * read-only CRAN GitHub mirror. `version` defaults to the source's latest; `undefined` when the source does
13
+ * not carry that function.
14
+ */
15
+ export declare function signatureFunctionInfo(src: PackageSignatureSource, pkg: string, fnName: string, version?: string): SignatureFunctionView | undefined;
16
+ /** the full view of a package: version, kind, export breakdown, dependencies, and every function's view */
17
+ export declare function signaturePackageInfo(src: PackageSignatureSource, pkg: string, resolved?: string): SignaturePackageView | undefined;
18
+ /**
19
+ * Tab-completer for `:query \@signature` / `:signature query`: package names in the first position, a package's
20
+ * function names in the second (and after `pkg::`). Version specs and flags are left alone. Enumerating functions
21
+ * decompresses the package's shard once (then cached); enumerating packages reads only the manifest.
22
+ */
23
+ export declare function signatureQueryCompleter(line: readonly string[], startingNewArg: boolean): CommandCompletions;
24
+ /**
25
+ * Executes the signature query. With no `package` it summarizes the loaded databases. A glob in `package`/`function`
26
+ * or a multi-version `version` triggers a wildcard search (matching packages or functions). Otherwise a single
27
+ * exact package (optionally at an exact `version`) yields its full view, or the detailed function view.
28
+ */
29
+ export declare function executeSignatureQuery({ analyzer }: BasicQueryData, queries: readonly SignatureQuery[]): Promise<SignatureQueryResult>;
@@ -0,0 +1,461 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cranPageUrl = cranPageUrl;
4
+ exports.cranMirrorSourceUrl = cranMirrorSourceUrl;
5
+ exports.signatureFunctionInfo = signatureFunctionInfo;
6
+ exports.signaturePackageInfo = signaturePackageInfo;
7
+ exports.signatureQueryCompleter = signatureQueryCompleter;
8
+ exports.executeSignatureQuery = executeSignatureQuery;
9
+ const semver_1 = require("semver");
10
+ const reader_1 = require("../../../project/sigdb/reader");
11
+ const schema_1 = require("../../../project/sigdb/schema");
12
+ const manifest_1 = require("../../../project/sigdb/manifest");
13
+ const r_version_1 = require("../../../util/r-version");
14
+ /** the CRAN package landing page (only meaningful for CRAN packages, not base R) */
15
+ function cranPageUrl(pkg) {
16
+ return `https://cran.r-project.org/package=${encodeURIComponent(pkg)}`;
17
+ }
18
+ /** whether a pattern uses glob wildcards (`*`, `?`) */
19
+ function hasGlob(pattern) {
20
+ return pattern !== undefined && /[*?]/.test(pattern);
21
+ }
22
+ /** compile a glob (`*` matches any run, `?` matches one char) into an anchored, case-sensitive RegExp */
23
+ function globToRegExp(glob) {
24
+ const escaped = glob.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.');
25
+ return new RegExp(`^${escaped}$`);
26
+ }
27
+ /** a name matcher: exact equality, or a glob test when the pattern uses wildcards */
28
+ function nameMatcher(pattern) {
29
+ if (hasGlob(pattern)) {
30
+ const re = globToRegExp(pattern);
31
+ return name => re.test(name);
32
+ }
33
+ return name => name === pattern;
34
+ }
35
+ /** whether a version spec can match more than one release (a glob or a semver range, not a single exact version) */
36
+ function isMultiVersion(spec) {
37
+ return /[*?xX]/.test(spec) || /[<>~^=]/.test(spec) || spec.includes('||') || spec.includes(' - ');
38
+ }
39
+ /** a version matcher for a spec: glob (`3.*`), semver range (`>=3.0.0`, `3.x`), or an exact version */
40
+ function versionMatcher(spec) {
41
+ if (hasGlob(spec)) {
42
+ const re = globToRegExp(spec);
43
+ return v => re.test(v);
44
+ }
45
+ const range = (0, semver_1.validRange)(spec, { loose: true });
46
+ if (range !== null) {
47
+ return v => {
48
+ const parsed = r_version_1.RVersion.parse(v);
49
+ return parsed !== undefined ? (0, semver_1.satisfies)(parsed, range, { loose: true, includePrerelease: true }) : v === spec;
50
+ };
51
+ }
52
+ return v => v === spec;
53
+ }
54
+ /** the versions of a package the loaded source can answer (dated releases, base-R core releases, and the latest) */
55
+ function availableVersions(src, pkg) {
56
+ const set = new Set();
57
+ for (const r of src.releaseDates(pkg)) {
58
+ set.add(r.version.str);
59
+ }
60
+ for (const v of src.coreVersions(pkg) ?? []) {
61
+ set.add(v.str);
62
+ }
63
+ const latest = src.latestVersion(pkg);
64
+ if (latest) {
65
+ set.add(latest.str);
66
+ }
67
+ return [...set].sort((a, b) => r_version_1.RVersion.compare(a, b));
68
+ }
69
+ /** read-only CRAN GitHub mirror base; `github.com/cran/<pkg>` mirrors every CRAN package and tags each release */
70
+ const CranGithubMirror = 'https://github.com/cran';
71
+ /** the mirror repository of a CRAN package */
72
+ function cranMirrorRepoUrl(pkg) {
73
+ return `${CranGithubMirror}/${encodeURIComponent(pkg)}`;
74
+ }
75
+ /** deep-link a definition into the CRAN mirror at the package's version tag (falling back to `HEAD`) */
76
+ function cranMirrorSourceUrl(pkg, version, file, line) {
77
+ const ref = version ? encodeURIComponent(version) : 'HEAD';
78
+ const anchor = line !== undefined && line >= 0 ? `#L${line}` : '';
79
+ return `${cranMirrorRepoUrl(pkg)}/blob/${ref}/${file}${anchor}`;
80
+ }
81
+ /** function/topic names that map cleanly to an rdrr.io man page (skip operators like `+.gg`, `[.data.frame`) */
82
+ const RdrrTopicName = /^[A-Za-z.][A-Za-z0-9._]*$/;
83
+ /** best-effort rdrr.io documentation link: `/r/<pkg>/<fn>` for base R, `/cran/<pkg>/man/<fn>` for CRAN */
84
+ function rdrrDocUrl(pkg, fn, opts) {
85
+ if (!RdrrTopicName.test(fn)) {
86
+ return undefined;
87
+ }
88
+ if (opts.base) {
89
+ return `https://rdrr.io/r/${pkg}/${fn}.html`;
90
+ }
91
+ if (opts.cran) {
92
+ return `https://rdrr.io/cran/${pkg}/man/${fn}.html`;
93
+ }
94
+ return undefined;
95
+ }
96
+ /** the trailing fields shared by every function view: definition location, CRAN-mirror source link, rdrr.io doc link */
97
+ function locationFields(pkg, fn, version, base, cran) {
98
+ const doc = rdrrDocUrl(pkg, fn.name, { base, cran });
99
+ return {
100
+ ...(fn.file ? { file: fn.file } : {}),
101
+ ...(fn.line >= 0 ? { line: fn.line } : {}),
102
+ ...(cran && !base && fn.file ? { sourceUrl: cranMirrorSourceUrl(pkg, version, fn.file, fn.line) } : {}),
103
+ ...(doc ? { docUrl: doc } : {})
104
+ };
105
+ }
106
+ /** the decoded view of one function, adding the CRAN-mirror source link and rdrr.io documentation link */
107
+ function decodedToView(pkg, fn, version, opts) {
108
+ return {
109
+ name: fn.name,
110
+ package: pkg,
111
+ ...(version !== undefined ? { version } : {}),
112
+ exported: fn.exported,
113
+ properties: fn.props,
114
+ parameters: fn.signature.map(p => ({
115
+ name: p.name,
116
+ required: !p.optional,
117
+ forced: p.forced,
118
+ ...(p.default !== undefined ? { default: p.default } : {})
119
+ })),
120
+ callees: fn.callees,
121
+ ...locationFields(pkg, fn, version, opts.base, opts.cran)
122
+ };
123
+ }
124
+ /**
125
+ * The detailed view of a single function within a package: its signature (parameters, forced/optional,
126
+ * defaults), properties, definition location, call graph, and -- for a CRAN package -- a deep link into the
127
+ * read-only CRAN GitHub mirror. `version` defaults to the source's latest; `undefined` when the source does
128
+ * not carry that function.
129
+ */
130
+ function signatureFunctionInfo(src, pkg, fnName, version) {
131
+ const fns = src.functions(pkg, version) ?? src.functions(pkg);
132
+ const fn = fns?.find(f => f.name === fnName);
133
+ if (fn === undefined) {
134
+ return undefined;
135
+ }
136
+ const exports = src.lookup(pkg, version) ?? src.lookup(pkg);
137
+ const view = decodedToView(pkg, fn, exports?.version, { cran: exports?.cran ?? false, base: src.isBaseR(pkg) });
138
+ // S3 dispatch targets are the `<generic>.<class>` functions in the same package (name-based, matching flowR's
139
+ // own S3 handling). We use this rather than the stored `UseMethod` callee, which the bundled call graphs
140
+ // aggregate transitively and so cannot distinguish a real generic from one that merely reaches a dispatch.
141
+ const methods = (fns ?? [])
142
+ .filter(f => f.name !== fn.name && f.name.startsWith(fn.name + '.'))
143
+ .map(f => f.name)
144
+ .sort();
145
+ if (methods.length > 0) {
146
+ return { ...view, s3generic: true, s3methods: methods };
147
+ }
148
+ return view;
149
+ }
150
+ /** the full view of a package: version, kind, export breakdown, dependencies, and every function's view */
151
+ function signaturePackageInfo(src, pkg, resolved) {
152
+ const exports = src.lookup(pkg, resolved) ?? src.lookup(pkg);
153
+ if (exports === undefined) {
154
+ return undefined;
155
+ }
156
+ const base = src.isBaseR(pkg);
157
+ const fns = src.functions(pkg, resolved) ?? src.functions(pkg) ?? [];
158
+ const fnNames = new Set(fns.map(f => f.name));
159
+ const constants = exports.exported.filter(n => !fnNames.has(n));
160
+ const deps = (src.dependencies(pkg, resolved) ?? src.dependencies(pkg) ?? [])
161
+ .map(d => ({ type: schema_1.DepTypeNames[d.type], name: d.name, ...(d.constraint ? { constraint: d.constraint } : {}) }));
162
+ const release = src.releaseDate(pkg, resolved);
163
+ return {
164
+ name: pkg,
165
+ version: exports.version,
166
+ ...(resolved && resolved !== exports.version ? { resolved } : {}),
167
+ base,
168
+ cran: exports.cran,
169
+ ...(exports.cranUrl ? { cranUrl: exports.cranUrl } : {}),
170
+ ...(exports.cran && !base ? { cranPage: cranPageUrl(pkg), repoUrl: cranMirrorRepoUrl(pkg) } : {}),
171
+ ...(release && !Number.isNaN(release.getTime()) ? { releaseDate: release.toISOString().slice(0, 10) } : {}),
172
+ exportsTotal: exports.exported.length,
173
+ functionCount: exports.exported.length - constants.length,
174
+ constants,
175
+ internalCount: exports.internal.length,
176
+ deprecated: exports.deprecated,
177
+ ...(base && src.coreVersions(pkg) ? { coreVersions: src.coreVersions(pkg)?.map(v => v.str) } : {}),
178
+ dependencies: deps,
179
+ functions: fns.map(f => decodedToView(pkg, f, exports.version, { cran: exports.cran, base }))
180
+ };
181
+ }
182
+ /** a few near matches for a mistyped package/symbol (case-insensitive substring), for a friendly hint */
183
+ function suggest(candidates, query, limit = 6) {
184
+ const needle = query.toLowerCase();
185
+ const out = [];
186
+ for (const c of candidates) {
187
+ if (c.toLowerCase().includes(needle)) {
188
+ out.push(c);
189
+ if (out.length >= limit) {
190
+ break;
191
+ }
192
+ }
193
+ }
194
+ return out;
195
+ }
196
+ /** cap on wildcard-search hits, so a `* *` search cannot exhaust memory */
197
+ const MaxMatches = 500;
198
+ /** a compact view for a wildcard search hit (signature/call-graph omitted; the JSON dump carries those per name) */
199
+ function compactMatch(pkg, fn, version, base, cran) {
200
+ const doc = rdrrDocUrl(pkg, fn.name, { base, cran });
201
+ return {
202
+ package: pkg,
203
+ name: fn.name,
204
+ exported: fn.exported,
205
+ ...(version !== undefined ? { version } : {}),
206
+ ...(fn.file ? { file: fn.file } : {}),
207
+ ...(fn.line >= 0 ? { line: fn.line } : {}),
208
+ ...(cran && !base && fn.file ? { sourceUrl: cranMirrorSourceUrl(pkg, version, fn.file, fn.line) } : {}),
209
+ ...(doc ? { docUrl: doc } : {})
210
+ };
211
+ }
212
+ /** the versions of a package across every loaded source that holds it (current + history + any mounted extra) */
213
+ function allAvailableVersions(sources, pkg) {
214
+ const set = new Set();
215
+ for (const s of sources) {
216
+ if (s.has(pkg)) {
217
+ for (const v of availableVersions(s, pkg)) {
218
+ set.add(v);
219
+ }
220
+ }
221
+ }
222
+ return [...set].sort((a, b) => r_version_1.RVersion.compare(a, b));
223
+ }
224
+ /**
225
+ * The owning source that actually carries `version` -- `current` is checked before `history`, so a
226
+ * latest-version query never decompresses the (large) history shard. Returns the first owner when no version
227
+ * was asked, or `undefined` when an explicit version is carried by none of them.
228
+ */
229
+ function sourceForVersion(owning, pkg, version) {
230
+ if (version === undefined) {
231
+ return owning[0];
232
+ }
233
+ return owning.find(s => availableVersions(s, pkg).includes(version));
234
+ }
235
+ /** the message shown when a known package has no release matching the requested version, listing what is available */
236
+ function versionNotFoundMessage(pkg, lead, avail, base) {
237
+ // only nudge towards a full-history bundle when one is *not* already mounted (a single known version)
238
+ const hint = !base && avail.length <= 1
239
+ ? ' Only the latest CRAN version is loaded; download the full history with `:signature download` (or mount one with `:signature add <path>`).'
240
+ : '';
241
+ return `${lead}${avail.length ? ` Available: ${avail.join(', ')}.` : ''}${hint}`;
242
+ }
243
+ /** run a wildcard search across the loaded sources: matching packages (no function), or matching functions */
244
+ function searchSources(sources, allNames, q) {
245
+ const cap = MaxMatches;
246
+ const pkgMatch = nameMatcher(q.package);
247
+ const matchedPkgs = [...allNames].filter(pkgMatch).sort();
248
+ const verMatch = q.version ? versionMatcher(q.version) : undefined;
249
+ // every source holding a package (its latest lives in `current`, its older releases in `history`)
250
+ const owningOf = (pkg) => sources.filter(s => s.has(pkg));
251
+ // the versions of `pkg` matching `m`, unioned across all owning sources (so a `3.*` filter reaches history)
252
+ const matchingVersions = (owners, pkg, m) => [...new Set(owners.flatMap(s => availableVersions(s, pkg).filter(m)))];
253
+ if (!q.function) {
254
+ const packages = [];
255
+ let truncated = false;
256
+ for (const pkg of matchedPkgs) {
257
+ const owners = owningOf(pkg);
258
+ if (owners.length === 0) {
259
+ continue;
260
+ }
261
+ const base = owners[0].isBaseR(pkg);
262
+ // with a version filter, union the matching versions across all sources (so a `3.*` reaches history)
263
+ const versions = verMatch
264
+ ? matchingVersions(owners, pkg, verMatch).sort((a, b) => r_version_1.RVersion.compare(a, b))
265
+ : undefined;
266
+ if (versions !== undefined && versions.length === 0) {
267
+ continue;
268
+ }
269
+ if (packages.length >= cap) {
270
+ truncated = true;
271
+ break;
272
+ }
273
+ const cran = (owners[0].lookup(pkg)?.cran ?? false) && !base;
274
+ const latest = owners[0].latestVersion(pkg)?.str;
275
+ packages.push({ name: pkg, base, cran, ...(latest ? { latest } : {}), ...(versions ? { versions } : {}), ...(cran ? { cranPage: cranPageUrl(pkg) } : {}) });
276
+ }
277
+ return { packages, truncated };
278
+ }
279
+ const fnMatch = nameMatcher(q.function);
280
+ const matches = [];
281
+ let truncated = false;
282
+ for (const pkg of matchedPkgs) {
283
+ const owners = owningOf(pkg);
284
+ if (owners.length === 0) {
285
+ continue;
286
+ }
287
+ const base = owners[0].isBaseR(pkg);
288
+ // versions to scan: with a filter, the union of matching releases across all sources (so `3.*` reaches
289
+ // history); without one, just the latest. Each version is scanned in a single source (the first that has
290
+ // it), so a release present in more than one source is not double-counted
291
+ const versionsToScan = verMatch
292
+ ? matchingVersions(owners, pkg, verMatch)
293
+ : [undefined];
294
+ for (const v of versionsToScan) {
295
+ const s = v === undefined ? owners[0] : owners.find(o => availableVersions(o, pkg).includes(v)) ?? owners[0];
296
+ const exports = s.lookup(pkg, v) ?? s.lookup(pkg);
297
+ const cran = (exports?.cran ?? false) && !base;
298
+ for (const fn of s.functions(pkg, v) ?? s.functions(pkg) ?? []) {
299
+ if (fnMatch(fn.name)) {
300
+ if (matches.length >= cap) {
301
+ truncated = true;
302
+ break;
303
+ }
304
+ matches.push(compactMatch(pkg, fn, exports?.version, base, cran));
305
+ }
306
+ }
307
+ if (truncated) {
308
+ break;
309
+ }
310
+ }
311
+ if (truncated) {
312
+ break;
313
+ }
314
+ }
315
+ return { matches, matchCount: matches.length, truncated };
316
+ }
317
+ /** the discoverable bundle sources for Tab completion (process-wide cached; opening the manifest reads no shard) */
318
+ function completionSources() {
319
+ if (typeof process !== 'undefined' && process.env?.FLOWR_DISABLE_DEFAULT_SIGDB) {
320
+ return [];
321
+ }
322
+ const out = [];
323
+ for (const p of (0, manifest_1.defaultSigDbPaths)()) {
324
+ const src = (0, reader_1.getSharedSigSourceSync)(p);
325
+ if (src) {
326
+ out.push(src);
327
+ }
328
+ }
329
+ return out;
330
+ }
331
+ /** the package part of a spec token, dropping any `@version` and `::function` suffix */
332
+ function packageOf(spec) {
333
+ return spec.split('::')[0].split('@')[0];
334
+ }
335
+ /** cap on offered names, so an empty fragment does not dump the whole 24k-package set at the terminal */
336
+ const MaxCompletions = 200;
337
+ /**
338
+ * Tab-completer for `:query \@signature` / `:signature query`: package names in the first position, a package's
339
+ * function names in the second (and after `pkg::`). Version specs and flags are left alone. Enumerating functions
340
+ * decompresses the package's shard once (then cached); enumerating packages reads only the manifest.
341
+ */
342
+ function signatureQueryCompleter(line, startingNewArg) {
343
+ const sources = completionSources();
344
+ if (sources.length === 0) {
345
+ return { completions: [] };
346
+ }
347
+ const capped = (names, prefix, decorate) => {
348
+ const all = [];
349
+ for (const n of names) {
350
+ const d = decorate(n); // filter on the offered text (e.g. `pkg::fn`), not the bare name
351
+ if (d.startsWith(prefix)) {
352
+ all.push(d);
353
+ }
354
+ }
355
+ if (all.length <= MaxCompletions) {
356
+ return all;
357
+ }
358
+ // too many to show: sample evenly across the sorted set so the offered names span the alphabet, not just
359
+ // its head; index 0 stays first so the ghost hint still previews the true best (alphabetically first) match
360
+ const stride = all.length / MaxCompletions;
361
+ return Array.from({ length: MaxCompletions }, (_, i) => all[Math.floor(i * stride)]);
362
+ };
363
+ const packageNames = () => [...new Set(sources.flatMap(s => s.packageNames()))].sort();
364
+ const functionsOf = (pkg) => {
365
+ const src = sources.find(s => s.has(pkg));
366
+ return src ? [...new Set((src.functions(pkg) ?? []).map(f => f.name))].sort() : [];
367
+ };
368
+ // first token: a package spec (`pkg`, `pkg::fn`, `pkg@ver`)
369
+ if (line.length === 0 || (line.length === 1 && !startingNewArg)) {
370
+ const token = line[0] ?? '';
371
+ const dbl = token.indexOf('::');
372
+ if (dbl >= 0) {
373
+ const pkg = packageOf(token), frag = token.slice(0, dbl + 2);
374
+ return { completions: capped(functionsOf(pkg), token, fn => `${frag}${fn} `), argumentPart: token };
375
+ }
376
+ if (token.includes('@')) {
377
+ return { completions: [] }; // typing a version, nothing to offer
378
+ }
379
+ return { completions: capped(packageNames(), token, p => `${p} `), argumentPart: token };
380
+ }
381
+ // second token: the function within the first token's package
382
+ if ((line.length === 1 && startingNewArg) || (line.length === 2 && !startingNewArg)) {
383
+ const frag = line.length === 2 ? line[1] : '';
384
+ return { completions: capped(functionsOf(packageOf(line[0])), frag, fn => `${fn} `), argumentPart: frag };
385
+ }
386
+ return { completions: [] };
387
+ }
388
+ /**
389
+ * Executes the signature query. With no `package` it summarizes the loaded databases. A glob in `package`/`function`
390
+ * or a multi-version `version` triggers a wildcard search (matching packages or functions). Otherwise a single
391
+ * exact package (optionally at an exact `version`) yields its full view, or the detailed function view.
392
+ */
393
+ // eslint-disable-next-line @typescript-eslint/require-await -- executor contract returns a Promise; the work is synchronous
394
+ async function executeSignatureQuery({ analyzer }, queries) {
395
+ const start = Date.now();
396
+ const q = queries[queries.length - 1] ?? { type: 'signature' };
397
+ const deps = analyzer.inspectContext().deps;
398
+ const databases = deps.loadedPackageDatabases()
399
+ .map(d => ({ scope: d.scope, version: d.version, date: d.date }));
400
+ // the plugin's loaded sources (bundled default + $FLOWR_SIGDB + anything added at runtime), so the query
401
+ // reflects dynamically-mounted sources
402
+ const sources = deps.signatureSources();
403
+ const packages = new Set();
404
+ for (const s of sources) {
405
+ for (const n of s.packageNames()) {
406
+ packages.add(n);
407
+ }
408
+ }
409
+ const meta = () => ({ '.meta': { timing: Date.now() - start }, databases, packageCount: packages.size, sourceCount: sources.length });
410
+ if (!q.package) {
411
+ return meta();
412
+ }
413
+ // wildcard search: a glob in the package/function name, or a version spec matching more than one release
414
+ if (hasGlob(q.package) || (q.function !== undefined && hasGlob(q.function)) || (q.version !== undefined && isMultiVersion(q.version))) {
415
+ const found = searchSources(sources, packages, q);
416
+ // a version glob against a single concrete, known package that matched no release: point at the available versions
417
+ // (the same guidance the exact-version path gives) instead of a bare "0 matched"
418
+ if ((found.matchCount === 0 || found.packages?.length === 0) && !hasGlob(q.package) && q.version !== undefined) {
419
+ const owning = sources.filter(s => s.has(q.package));
420
+ if (owning.length > 0) {
421
+ const avail = allAvailableVersions(owning, q.package);
422
+ return { ...meta(), message: versionNotFoundMessage(q.package, `no release of '${q.package}' matches '${q.version}'.`, avail, owning[0].isBaseR(q.package)) };
423
+ }
424
+ }
425
+ return { ...meta(), ...found };
426
+ }
427
+ // every source holding the package: `current` keeps the latest, `history` the older releases, so the resolved
428
+ // version must be looked up in whichever source actually has it (not just the first one found)
429
+ const owning = sources.filter(s => s.has(q.package));
430
+ if (owning.length === 0) {
431
+ return { ...meta(), message: `The signature database does not know the package '${q.package}'.`, suggestions: suggest(packages, q.package) };
432
+ }
433
+ // the version to resolve against: an explicit `@version`, else the version flowR inferred for the script's
434
+ // dependency (which may be an older release that only `history` carries)
435
+ const version = q.version ?? deps.getDependency(q.package)?.resolvedVersion;
436
+ const src = sourceForVersion(owning, q.package, version);
437
+ if (q.version !== undefined && src === undefined) {
438
+ const avail = allAvailableVersions(owning, q.package);
439
+ return { ...meta(), message: versionNotFoundMessage(q.package, `'${q.package}@${q.version}' is not in the loaded database.`, avail, owning[0].isBaseR(q.package)) };
440
+ }
441
+ const resolvedSrc = src ?? owning[0];
442
+ if (q.function) {
443
+ const fn = signatureFunctionInfo(resolvedSrc, q.package, q.function, version);
444
+ if (fn) {
445
+ return { ...meta(), function: fn };
446
+ }
447
+ const exports = resolvedSrc.lookup(q.package, version) ?? resolvedSrc.lookup(q.package);
448
+ const universe = new Set([
449
+ ...(exports?.exported ?? []),
450
+ ...(resolvedSrc.functions(q.package, version) ?? resolvedSrc.functions(q.package) ?? []).map(f => f.name)
451
+ ]);
452
+ return {
453
+ ...meta(),
454
+ package: signaturePackageInfo(resolvedSrc, q.package, version),
455
+ message: `'${q.package}' does not define '${q.function}'.`,
456
+ suggestions: suggest(universe, q.function)
457
+ };
458
+ }
459
+ return { ...meta(), package: signaturePackageInfo(resolvedSrc, q.package, version) };
460
+ }
461
+ //# sourceMappingURL=signature-query-executor.js.map