@yangfei_93sky/biocli 0.2.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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -0
  3. package/dist/batch.d.ts +20 -0
  4. package/dist/batch.js +69 -0
  5. package/dist/build-manifest.d.ts +38 -0
  6. package/dist/build-manifest.js +186 -0
  7. package/dist/cache.d.ts +28 -0
  8. package/dist/cache.js +126 -0
  9. package/dist/cli-manifest.json +1500 -0
  10. package/dist/cli.d.ts +7 -0
  11. package/dist/cli.js +336 -0
  12. package/dist/clis/_shared/common.d.ts +8 -0
  13. package/dist/clis/_shared/common.js +13 -0
  14. package/dist/clis/_shared/eutils.d.ts +9 -0
  15. package/dist/clis/_shared/eutils.js +9 -0
  16. package/dist/clis/_shared/organism-db.d.ts +23 -0
  17. package/dist/clis/_shared/organism-db.js +58 -0
  18. package/dist/clis/_shared/xml-helpers.d.ts +58 -0
  19. package/dist/clis/_shared/xml-helpers.js +266 -0
  20. package/dist/clis/aggregate/enrichment.d.ts +7 -0
  21. package/dist/clis/aggregate/enrichment.js +105 -0
  22. package/dist/clis/aggregate/gene-dossier.d.ts +13 -0
  23. package/dist/clis/aggregate/gene-dossier.js +248 -0
  24. package/dist/clis/aggregate/gene-profile.d.ts +16 -0
  25. package/dist/clis/aggregate/gene-profile.js +305 -0
  26. package/dist/clis/aggregate/literature-brief.d.ts +7 -0
  27. package/dist/clis/aggregate/literature-brief.js +79 -0
  28. package/dist/clis/aggregate/variant-dossier.d.ts +11 -0
  29. package/dist/clis/aggregate/variant-dossier.js +161 -0
  30. package/dist/clis/aggregate/variant-interpret.d.ts +10 -0
  31. package/dist/clis/aggregate/variant-interpret.js +210 -0
  32. package/dist/clis/aggregate/workflow-prepare.d.ts +12 -0
  33. package/dist/clis/aggregate/workflow-prepare.js +228 -0
  34. package/dist/clis/aggregate/workflow-scout.d.ts +13 -0
  35. package/dist/clis/aggregate/workflow-scout.js +175 -0
  36. package/dist/clis/clinvar/search.d.ts +8 -0
  37. package/dist/clis/clinvar/search.js +61 -0
  38. package/dist/clis/clinvar/variant.d.ts +7 -0
  39. package/dist/clis/clinvar/variant.js +53 -0
  40. package/dist/clis/enrichr/analyze.d.ts +7 -0
  41. package/dist/clis/enrichr/analyze.js +48 -0
  42. package/dist/clis/ensembl/lookup.d.ts +6 -0
  43. package/dist/clis/ensembl/lookup.js +38 -0
  44. package/dist/clis/ensembl/vep.d.ts +7 -0
  45. package/dist/clis/ensembl/vep.js +86 -0
  46. package/dist/clis/ensembl/xrefs.d.ts +6 -0
  47. package/dist/clis/ensembl/xrefs.js +36 -0
  48. package/dist/clis/gene/fetch.d.ts +10 -0
  49. package/dist/clis/gene/fetch.js +96 -0
  50. package/dist/clis/gene/info.d.ts +7 -0
  51. package/dist/clis/gene/info.js +37 -0
  52. package/dist/clis/gene/search.d.ts +7 -0
  53. package/dist/clis/gene/search.js +71 -0
  54. package/dist/clis/geo/dataset.d.ts +7 -0
  55. package/dist/clis/geo/dataset.js +55 -0
  56. package/dist/clis/geo/download.d.ts +17 -0
  57. package/dist/clis/geo/download.js +115 -0
  58. package/dist/clis/geo/samples.d.ts +7 -0
  59. package/dist/clis/geo/samples.js +57 -0
  60. package/dist/clis/geo/search.d.ts +8 -0
  61. package/dist/clis/geo/search.js +66 -0
  62. package/dist/clis/kegg/convert.d.ts +7 -0
  63. package/dist/clis/kegg/convert.js +37 -0
  64. package/dist/clis/kegg/disease.d.ts +6 -0
  65. package/dist/clis/kegg/disease.js +57 -0
  66. package/dist/clis/kegg/link.d.ts +7 -0
  67. package/dist/clis/kegg/link.js +36 -0
  68. package/dist/clis/kegg/pathway.d.ts +6 -0
  69. package/dist/clis/kegg/pathway.js +37 -0
  70. package/dist/clis/pubmed/abstract.d.ts +7 -0
  71. package/dist/clis/pubmed/abstract.js +42 -0
  72. package/dist/clis/pubmed/cited-by.d.ts +7 -0
  73. package/dist/clis/pubmed/cited-by.js +77 -0
  74. package/dist/clis/pubmed/fetch.d.ts +6 -0
  75. package/dist/clis/pubmed/fetch.js +36 -0
  76. package/dist/clis/pubmed/info.yaml +22 -0
  77. package/dist/clis/pubmed/related.d.ts +7 -0
  78. package/dist/clis/pubmed/related.js +81 -0
  79. package/dist/clis/pubmed/search.d.ts +8 -0
  80. package/dist/clis/pubmed/search.js +63 -0
  81. package/dist/clis/snp/lookup.d.ts +7 -0
  82. package/dist/clis/snp/lookup.js +57 -0
  83. package/dist/clis/sra/download.d.ts +18 -0
  84. package/dist/clis/sra/download.js +217 -0
  85. package/dist/clis/sra/run.d.ts +8 -0
  86. package/dist/clis/sra/run.js +77 -0
  87. package/dist/clis/sra/search.d.ts +8 -0
  88. package/dist/clis/sra/search.js +83 -0
  89. package/dist/clis/string/enrichment.d.ts +7 -0
  90. package/dist/clis/string/enrichment.js +50 -0
  91. package/dist/clis/string/network.d.ts +7 -0
  92. package/dist/clis/string/network.js +47 -0
  93. package/dist/clis/string/partners.d.ts +4 -0
  94. package/dist/clis/string/partners.js +44 -0
  95. package/dist/clis/taxonomy/lookup.d.ts +8 -0
  96. package/dist/clis/taxonomy/lookup.js +54 -0
  97. package/dist/clis/uniprot/fetch.d.ts +7 -0
  98. package/dist/clis/uniprot/fetch.js +82 -0
  99. package/dist/clis/uniprot/search.d.ts +6 -0
  100. package/dist/clis/uniprot/search.js +65 -0
  101. package/dist/clis/uniprot/sequence.d.ts +7 -0
  102. package/dist/clis/uniprot/sequence.js +51 -0
  103. package/dist/commander-adapter.d.ts +27 -0
  104. package/dist/commander-adapter.js +286 -0
  105. package/dist/completion.d.ts +19 -0
  106. package/dist/completion.js +117 -0
  107. package/dist/config.d.ts +57 -0
  108. package/dist/config.js +94 -0
  109. package/dist/databases/enrichr.d.ts +28 -0
  110. package/dist/databases/enrichr.js +131 -0
  111. package/dist/databases/ensembl.d.ts +14 -0
  112. package/dist/databases/ensembl.js +106 -0
  113. package/dist/databases/index.d.ts +45 -0
  114. package/dist/databases/index.js +49 -0
  115. package/dist/databases/kegg.d.ts +26 -0
  116. package/dist/databases/kegg.js +136 -0
  117. package/dist/databases/ncbi.d.ts +28 -0
  118. package/dist/databases/ncbi.js +144 -0
  119. package/dist/databases/string-db.d.ts +19 -0
  120. package/dist/databases/string-db.js +105 -0
  121. package/dist/databases/uniprot.d.ts +13 -0
  122. package/dist/databases/uniprot.js +110 -0
  123. package/dist/discovery.d.ts +32 -0
  124. package/dist/discovery.js +235 -0
  125. package/dist/doctor.d.ts +19 -0
  126. package/dist/doctor.js +151 -0
  127. package/dist/errors.d.ts +68 -0
  128. package/dist/errors.js +105 -0
  129. package/dist/execution.d.ts +15 -0
  130. package/dist/execution.js +178 -0
  131. package/dist/hooks.d.ts +48 -0
  132. package/dist/hooks.js +58 -0
  133. package/dist/main.d.ts +13 -0
  134. package/dist/main.js +31 -0
  135. package/dist/ncbi-fetch.d.ts +10 -0
  136. package/dist/ncbi-fetch.js +10 -0
  137. package/dist/output.d.ts +18 -0
  138. package/dist/output.js +394 -0
  139. package/dist/pipeline/executor.d.ts +22 -0
  140. package/dist/pipeline/executor.js +40 -0
  141. package/dist/pipeline/index.d.ts +6 -0
  142. package/dist/pipeline/index.js +6 -0
  143. package/dist/pipeline/registry.d.ts +16 -0
  144. package/dist/pipeline/registry.js +31 -0
  145. package/dist/pipeline/steps/fetch.d.ts +21 -0
  146. package/dist/pipeline/steps/fetch.js +160 -0
  147. package/dist/pipeline/steps/transform.d.ts +26 -0
  148. package/dist/pipeline/steps/transform.js +92 -0
  149. package/dist/pipeline/steps/xml-parse.d.ts +12 -0
  150. package/dist/pipeline/steps/xml-parse.js +27 -0
  151. package/dist/pipeline/template.d.ts +35 -0
  152. package/dist/pipeline/template.js +312 -0
  153. package/dist/rate-limiter.d.ts +56 -0
  154. package/dist/rate-limiter.js +120 -0
  155. package/dist/registry-api.d.ts +15 -0
  156. package/dist/registry-api.js +13 -0
  157. package/dist/registry.d.ts +90 -0
  158. package/dist/registry.js +100 -0
  159. package/dist/schema.d.ts +80 -0
  160. package/dist/schema.js +72 -0
  161. package/dist/spinner.d.ts +19 -0
  162. package/dist/spinner.js +37 -0
  163. package/dist/types.d.ts +101 -0
  164. package/dist/types.js +27 -0
  165. package/dist/utils.d.ts +16 -0
  166. package/dist/utils.js +40 -0
  167. package/dist/validate.d.ts +29 -0
  168. package/dist/validate.js +136 -0
  169. package/dist/verify.d.ts +20 -0
  170. package/dist/verify.js +131 -0
  171. package/dist/version.d.ts +13 -0
  172. package/dist/version.js +36 -0
  173. package/dist/xml-parser.d.ts +19 -0
  174. package/dist/xml-parser.js +119 -0
  175. package/dist/yaml-schema.d.ts +40 -0
  176. package/dist/yaml-schema.js +62 -0
  177. package/package.json +68 -0
package/dist/cache.js ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Local file-based cache for biocli API responses.
3
+ *
4
+ * Cache layout: ~/.biocli/cache/{database}/{command}/{sha256}.json
5
+ * Each entry stores: { data, cachedAt, ttlMs, key }
6
+ *
7
+ * TTL default: 24 hours. Configurable via `biocli config set cache.ttl <hours>`.
8
+ * Disable per-request with --no-cache global flag.
9
+ */
10
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, statSync, rmSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ import { homedir } from 'node:os';
13
+ import { createHash } from 'node:crypto';
14
+ // ── Constants ────────────────────────────────────────────────────────────────
15
+ const CACHE_DIR = join(homedir(), '.biocli', 'cache');
16
+ const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
17
+ // ── Core functions ───────────────────────────────────────────────────────────
18
+ /** Generate a cache key hash from command + args. */
19
+ function cacheHash(key) {
20
+ return createHash('sha256').update(key).digest('hex').slice(0, 16);
21
+ }
22
+ /** Build the cache file path for a given database, command, and args. */
23
+ function cachePath(database, command, argsKey) {
24
+ const dir = join(CACHE_DIR, database, command);
25
+ return join(dir, `${cacheHash(argsKey)}.json`);
26
+ }
27
+ /** Build a stable cache key from command args. */
28
+ export function buildCacheKey(database, command, args) {
29
+ // Sort keys for stable hashing
30
+ const sorted = Object.keys(args).sort().map(k => `${k}=${JSON.stringify(args[k])}`).join('&');
31
+ return `${database}/${command}?${sorted}`;
32
+ }
33
+ /** Get a cached result if it exists and hasn't expired. */
34
+ export function getCached(database, command, argsKey, ttlMs) {
35
+ const path = cachePath(database, command, argsKey);
36
+ if (!existsSync(path))
37
+ return null;
38
+ try {
39
+ const raw = readFileSync(path, 'utf-8');
40
+ const entry = JSON.parse(raw);
41
+ const effectiveTtl = ttlMs ?? entry.ttlMs ?? DEFAULT_TTL_MS;
42
+ const age = Date.now() - entry.cachedAt;
43
+ if (age > effectiveTtl) {
44
+ // Expired — delete and return null
45
+ try {
46
+ rmSync(path);
47
+ }
48
+ catch { /* ignore */ }
49
+ return null;
50
+ }
51
+ return entry.data;
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ /** Store a result in the cache. */
58
+ export function setCached(database, command, argsKey, data, ttlMs = DEFAULT_TTL_MS) {
59
+ const path = cachePath(database, command, argsKey);
60
+ const dir = join(CACHE_DIR, database, command);
61
+ if (!existsSync(dir)) {
62
+ mkdirSync(dir, { recursive: true });
63
+ }
64
+ const entry = {
65
+ data,
66
+ cachedAt: Date.now(),
67
+ ttlMs,
68
+ key: argsKey,
69
+ };
70
+ writeFileSync(path, JSON.stringify(entry), 'utf-8');
71
+ }
72
+ // ── Management functions ─────────────────────────────────────────────────────
73
+ /** Get cache statistics. */
74
+ export function getStats() {
75
+ const stats = {
76
+ totalEntries: 0,
77
+ totalSizeBytes: 0,
78
+ databases: {},
79
+ oldestEntry: null,
80
+ newestEntry: null,
81
+ };
82
+ if (!existsSync(CACHE_DIR))
83
+ return stats;
84
+ let oldestTime = Infinity;
85
+ let newestTime = 0;
86
+ function walkDir(dir, dbName) {
87
+ if (!existsSync(dir))
88
+ return;
89
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
90
+ const fullPath = join(dir, entry.name);
91
+ if (entry.isDirectory()) {
92
+ walkDir(fullPath, dbName ?? entry.name);
93
+ }
94
+ else if (entry.name.endsWith('.json')) {
95
+ const st = statSync(fullPath);
96
+ stats.totalEntries++;
97
+ stats.totalSizeBytes += st.size;
98
+ if (dbName) {
99
+ stats.databases[dbName] = (stats.databases[dbName] ?? 0) + 1;
100
+ }
101
+ if (st.mtimeMs < oldestTime) {
102
+ oldestTime = st.mtimeMs;
103
+ stats.oldestEntry = new Date(st.mtimeMs).toISOString();
104
+ }
105
+ if (st.mtimeMs > newestTime) {
106
+ newestTime = st.mtimeMs;
107
+ stats.newestEntry = new Date(st.mtimeMs).toISOString();
108
+ }
109
+ }
110
+ }
111
+ }
112
+ walkDir(CACHE_DIR);
113
+ return stats;
114
+ }
115
+ /** Clear all cache entries. Returns number of entries deleted. */
116
+ export function clearCache() {
117
+ if (!existsSync(CACHE_DIR))
118
+ return 0;
119
+ const stats = getStats();
120
+ rmSync(CACHE_DIR, { recursive: true, force: true });
121
+ return stats.totalEntries;
122
+ }
123
+ /** Get the default TTL in milliseconds. */
124
+ export function getDefaultTtlMs() {
125
+ return DEFAULT_TTL_MS;
126
+ }