@fnndsc/chili 3.2.5

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 (219) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +113 -0
  3. package/dist/chefs/chefs.d.ts +15 -0
  4. package/dist/chefs/chefs.js +195 -0
  5. package/dist/commands/compute/fields.d.ts +6 -0
  6. package/dist/commands/compute/fields.js +13 -0
  7. package/dist/commands/compute/list.d.ts +19 -0
  8. package/dist/commands/compute/list.js +20 -0
  9. package/dist/commands/connect/login.d.ts +16 -0
  10. package/dist/commands/connect/login.js +18 -0
  11. package/dist/commands/connect/logout.d.ts +6 -0
  12. package/dist/commands/connect/logout.js +16 -0
  13. package/dist/commands/feed/comments.d.ts +41 -0
  14. package/dist/commands/feed/comments.js +45 -0
  15. package/dist/commands/feed/create.d.ts +13 -0
  16. package/dist/commands/feed/create.js +40 -0
  17. package/dist/commands/feed/note.d.ts +21 -0
  18. package/dist/commands/feed/note.js +24 -0
  19. package/dist/commands/feeds/delete.d.ts +14 -0
  20. package/dist/commands/feeds/delete.js +34 -0
  21. package/dist/commands/feeds/fields.d.ts +6 -0
  22. package/dist/commands/feeds/fields.js +17 -0
  23. package/dist/commands/feeds/list.d.ts +17 -0
  24. package/dist/commands/feeds/list.js +38 -0
  25. package/dist/commands/feeds/share.d.ts +17 -0
  26. package/dist/commands/feeds/share.js +19 -0
  27. package/dist/commands/file/view.d.ts +8 -0
  28. package/dist/commands/file/view.js +25 -0
  29. package/dist/commands/files/delete.d.ts +16 -0
  30. package/dist/commands/files/delete.js +36 -0
  31. package/dist/commands/files/fields.d.ts +7 -0
  32. package/dist/commands/files/fields.js +18 -0
  33. package/dist/commands/files/list.d.ts +11 -0
  34. package/dist/commands/files/list.js +23 -0
  35. package/dist/commands/fs/cat.d.ts +15 -0
  36. package/dist/commands/fs/cat.js +26 -0
  37. package/dist/commands/fs/cp.d.ts +17 -0
  38. package/dist/commands/fs/cp.js +26 -0
  39. package/dist/commands/fs/create.d.ts +15 -0
  40. package/dist/commands/fs/create.js +83 -0
  41. package/dist/commands/fs/download.d.ts +25 -0
  42. package/dist/commands/fs/download.js +235 -0
  43. package/dist/commands/fs/edit.d.ts +16 -0
  44. package/dist/commands/fs/edit.js +25 -0
  45. package/dist/commands/fs/ls.d.ts +18 -0
  46. package/dist/commands/fs/ls.js +142 -0
  47. package/dist/commands/fs/mkdir.d.ts +8 -0
  48. package/dist/commands/fs/mkdir.js +21 -0
  49. package/dist/commands/fs/mv.d.ts +13 -0
  50. package/dist/commands/fs/mv.js +73 -0
  51. package/dist/commands/fs/rm.d.ts +24 -0
  52. package/dist/commands/fs/rm.js +108 -0
  53. package/dist/commands/fs/touch.d.ts +16 -0
  54. package/dist/commands/fs/touch.js +62 -0
  55. package/dist/commands/fs/upload.d.ts +55 -0
  56. package/dist/commands/fs/upload.js +221 -0
  57. package/dist/commands/groups/fields.d.ts +6 -0
  58. package/dist/commands/groups/fields.js +13 -0
  59. package/dist/commands/groups/list.d.ts +16 -0
  60. package/dist/commands/groups/list.js +26 -0
  61. package/dist/commands/man/doc.d.ts +16 -0
  62. package/dist/commands/man/doc.js +32 -0
  63. package/dist/commands/man/topics.d.ts +6 -0
  64. package/dist/commands/man/topics.js +27 -0
  65. package/dist/commands/pipeline/fields.d.ts +6 -0
  66. package/dist/commands/pipeline/fields.js +13 -0
  67. package/dist/commands/pipeline/run.d.ts +18 -0
  68. package/dist/commands/pipeline/run.js +33 -0
  69. package/dist/commands/plugin/readme.d.ts +14 -0
  70. package/dist/commands/plugin/readme.js +49 -0
  71. package/dist/commands/plugin/run.d.ts +10 -0
  72. package/dist/commands/plugin/run.js +29 -0
  73. package/dist/commands/plugin/search.d.ts +7 -0
  74. package/dist/commands/plugin/search.js +18 -0
  75. package/dist/commands/plugininstances/fields.d.ts +6 -0
  76. package/dist/commands/plugininstances/fields.js +13 -0
  77. package/dist/commands/plugininstances/list.d.ts +16 -0
  78. package/dist/commands/plugininstances/list.js +26 -0
  79. package/dist/commands/pluginmetas/fields.d.ts +6 -0
  80. package/dist/commands/pluginmetas/fields.js +13 -0
  81. package/dist/commands/pluginmetas/list.d.ts +16 -0
  82. package/dist/commands/pluginmetas/list.js +26 -0
  83. package/dist/commands/plugins/add.d.ts +34 -0
  84. package/dist/commands/plugins/add.js +374 -0
  85. package/dist/commands/plugins/delete.d.ts +14 -0
  86. package/dist/commands/plugins/delete.js +34 -0
  87. package/dist/commands/plugins/fields.d.ts +6 -0
  88. package/dist/commands/plugins/fields.js +17 -0
  89. package/dist/commands/plugins/list.d.ts +17 -0
  90. package/dist/commands/plugins/list.js +40 -0
  91. package/dist/commands/plugins/overview.d.ts +6 -0
  92. package/dist/commands/plugins/overview.js +17 -0
  93. package/dist/commands/store/list.d.ts +23 -0
  94. package/dist/commands/store/list.js +48 -0
  95. package/dist/commands/tags/fields.d.ts +6 -0
  96. package/dist/commands/tags/fields.js +13 -0
  97. package/dist/commands/tags/list.d.ts +16 -0
  98. package/dist/commands/tags/list.js +26 -0
  99. package/dist/commands/workflows/fields.d.ts +6 -0
  100. package/dist/commands/workflows/fields.js +13 -0
  101. package/dist/commands/workflows/list.d.ts +16 -0
  102. package/dist/commands/workflows/list.js +26 -0
  103. package/dist/config/colorConfig.d.ts +56 -0
  104. package/dist/config/colorConfig.js +161 -0
  105. package/dist/connect/connectHandler.d.ts +15 -0
  106. package/dist/connect/connectHandler.js +48 -0
  107. package/dist/context/contextCommand.d.ts +13 -0
  108. package/dist/context/contextCommand.js +193 -0
  109. package/dist/controllers/baseController.d.ts +43 -0
  110. package/dist/controllers/baseController.js +67 -0
  111. package/dist/controllers/feedController.d.ts +35 -0
  112. package/dist/controllers/feedController.js +53 -0
  113. package/dist/controllers/fileController.d.ts +56 -0
  114. package/dist/controllers/fileController.js +93 -0
  115. package/dist/controllers/pluginContextController.d.ts +24 -0
  116. package/dist/controllers/pluginContextController.js +49 -0
  117. package/dist/controllers/pluginController.d.ts +70 -0
  118. package/dist/controllers/pluginController.js +98 -0
  119. package/dist/controllers/pluginMetaController.d.ts +41 -0
  120. package/dist/controllers/pluginMetaController.js +52 -0
  121. package/dist/feeds/feedHandler.d.ts +64 -0
  122. package/dist/feeds/feedHandler.js +203 -0
  123. package/dist/filesystem/fileGroupHandler.d.ts +92 -0
  124. package/dist/filesystem/fileGroupHandler.js +318 -0
  125. package/dist/filesystem/filesystemHandler.d.ts +12 -0
  126. package/dist/filesystem/filesystemHandler.js +135 -0
  127. package/dist/filesystem/inodeCommand.d.ts +12 -0
  128. package/dist/filesystem/inodeCommand.js +37 -0
  129. package/dist/handlers/baseGroupHandler.d.ts +103 -0
  130. package/dist/handlers/baseGroupHandler.js +342 -0
  131. package/dist/index.d.ts +7 -0
  132. package/dist/index.js +239 -0
  133. package/dist/lfs/lfs.d.ts +25 -0
  134. package/dist/lfs/lfs.js +74 -0
  135. package/dist/man/man.d.ts +15 -0
  136. package/dist/man/man.js +31 -0
  137. package/dist/man/renderer.d.ts +26 -0
  138. package/dist/man/renderer.js +187 -0
  139. package/dist/models/feed.d.ts +18 -0
  140. package/dist/models/feed.js +8 -0
  141. package/dist/models/listing.d.ts +33 -0
  142. package/dist/models/listing.js +9 -0
  143. package/dist/models/plugin.d.ts +27 -0
  144. package/dist/models/plugin.js +1 -0
  145. package/dist/models/resource.d.ts +39 -0
  146. package/dist/models/resource.js +9 -0
  147. package/dist/pacs/pacsQueryHandler.d.ts +55 -0
  148. package/dist/pacs/pacsQueryHandler.js +196 -0
  149. package/dist/pacs/pacsQueryPayload.d.ts +19 -0
  150. package/dist/pacs/pacsQueryPayload.js +44 -0
  151. package/dist/pacs/pacsResultRender.d.ts +20 -0
  152. package/dist/pacs/pacsResultRender.js +141 -0
  153. package/dist/pacs/pacsRetrieveHandler.d.ts +87 -0
  154. package/dist/pacs/pacsRetrieveHandler.js +272 -0
  155. package/dist/pacs/pacsServerHandler.d.ts +15 -0
  156. package/dist/pacs/pacsServerHandler.js +32 -0
  157. package/dist/path/pathCommand.d.ts +64 -0
  158. package/dist/path/pathCommand.js +805 -0
  159. package/dist/path/pathMapper.d.ts +189 -0
  160. package/dist/path/pathMapper.js +382 -0
  161. package/dist/plugins/pluginGroupHandler.d.ts +42 -0
  162. package/dist/plugins/pluginGroupHandler.js +90 -0
  163. package/dist/plugins/pluginHandler.d.ts +87 -0
  164. package/dist/plugins/pluginHandler.js +303 -0
  165. package/dist/plugins/pluginMetaHandler.d.ts +21 -0
  166. package/dist/plugins/pluginMetaHandler.js +27 -0
  167. package/dist/screen/screen.d.ts +214 -0
  168. package/dist/screen/screen.js +478 -0
  169. package/dist/utils/admin_prompt.d.ts +42 -0
  170. package/dist/utils/admin_prompt.js +105 -0
  171. package/dist/utils/cli.d.ts +67 -0
  172. package/dist/utils/cli.js +112 -0
  173. package/dist/utils/docker.d.ts +74 -0
  174. package/dist/utils/docker.js +155 -0
  175. package/dist/utils/input_format.d.ts +77 -0
  176. package/dist/utils/input_format.js +135 -0
  177. package/dist/utils/sort.d.ts +29 -0
  178. package/dist/utils/sort.js +63 -0
  179. package/dist/utils/ui.d.ts +7 -0
  180. package/dist/utils/ui.js +26 -0
  181. package/dist/utils.d.ts +15 -0
  182. package/dist/utils.js +14 -0
  183. package/dist/views/compute.d.ts +17 -0
  184. package/dist/views/compute.js +40 -0
  185. package/dist/views/connect.d.ts +13 -0
  186. package/dist/views/connect.js +35 -0
  187. package/dist/views/feed.d.ts +44 -0
  188. package/dist/views/feed.js +110 -0
  189. package/dist/views/file.d.ts +25 -0
  190. package/dist/views/file.js +71 -0
  191. package/dist/views/fs.d.ts +51 -0
  192. package/dist/views/fs.js +105 -0
  193. package/dist/views/ls.d.ts +37 -0
  194. package/dist/views/ls.js +190 -0
  195. package/dist/views/plugin.d.ts +28 -0
  196. package/dist/views/plugin.js +71 -0
  197. package/dist/views/pluginParameters.d.ts +17 -0
  198. package/dist/views/pluginParameters.js +79 -0
  199. package/docs/00_intro.adoc +25 -0
  200. package/docs/01_setup.adoc +63 -0
  201. package/docs/02_context.adoc +128 -0
  202. package/docs/03_searchable.adoc +134 -0
  203. package/docs/10_everyday_examples.adoc +9 -0
  204. package/docs/11_upload_data.adoc +146 -0
  205. package/docs/12_create_a_feed.adoc +9 -0
  206. package/docs/13_run_a_plugin.adoc +271 -0
  207. package/docs/20_plugins.adoc +16 -0
  208. package/docs/21_pluginReadme.adoc +123 -0
  209. package/docs/30_filesystem.adoc +93 -0
  210. package/docs/31_fileops.adoc +51 -0
  211. package/docs/32_file_content.adoc +471 -0
  212. package/docs/_architecture.adoc +48 -0
  213. package/docs/_deepContext.adoc +84 -0
  214. package/docs/_roadmap.adoc +42 -0
  215. package/docs/_searchable.adoc +187 -0
  216. package/docs/_state.adoc +68 -0
  217. package/docs/pacs.adoc +101 -0
  218. package/docs/pathMapper.md +246 -0
  219. package/package.json +92 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file Fetches available fields for workflow resources.
3
+ * @module
4
+ */
5
+ import { workflowFields_get } from '@fnndsc/salsa';
6
+ /**
7
+ * Fetches the available workflow field names.
8
+ *
9
+ * @returns The workflow field names, or null on failure.
10
+ */
11
+ export async function workflowFields_fetch() {
12
+ return await workflowFields_get();
13
+ }
@@ -0,0 +1,16 @@
1
+ import { CLIoptions } from '../../utils/cli.js';
2
+ /**
3
+ * Result of listing workflows (table data plus selected fields).
4
+ */
5
+ export interface WorkflowListResult {
6
+ workflows: Record<string, unknown>[];
7
+ selectedFields: string[];
8
+ totalCount?: number;
9
+ }
10
+ /**
11
+ * Fetches a list of workflows.
12
+ *
13
+ * @param options - List and filter options.
14
+ * @returns The workflows list result.
15
+ */
16
+ export declare function workflows_fetchList(options: CLIoptions): Promise<WorkflowListResult>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file Implements listing ChRIS workflows.
3
+ * @module
4
+ */
5
+ import { workflows_list as salsaWorkflows_list, workflows_listAll as salsaWorkflows_listAll } from '@fnndsc/salsa';
6
+ import { options_toParams } from '../../utils/cli.js';
7
+ import { list_applySort } from '../../utils/sort.js';
8
+ /**
9
+ * Fetches a list of workflows.
10
+ *
11
+ * @param options - List and filter options.
12
+ * @returns The workflows list result.
13
+ */
14
+ export async function workflows_fetchList(options) {
15
+ const params = options_toParams(options);
16
+ const result = options.all
17
+ ? await salsaWorkflows_listAll(params)
18
+ : await salsaWorkflows_list(params);
19
+ if (result && result.tableData) {
20
+ let workflows = result.tableData;
21
+ if (options.sort)
22
+ workflows = list_applySort(workflows, options.sort, options.reverse);
23
+ return { workflows, selectedFields: result.selectedFields || [], totalCount: result.totalCount };
24
+ }
25
+ return { workflows: [], selectedFields: [] };
26
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Interface for color style configuration.
3
+ */
4
+ export interface ColorStyle {
5
+ color: string;
6
+ bold?: boolean;
7
+ dim?: boolean;
8
+ italic?: boolean;
9
+ underline?: boolean;
10
+ inverse?: boolean;
11
+ strikethrough?: boolean;
12
+ }
13
+ /**
14
+ * Interface for icon configuration.
15
+ */
16
+ export interface IconConfig {
17
+ enabled: boolean;
18
+ dir: string;
19
+ file: string;
20
+ link: string;
21
+ plugin: string;
22
+ pipeline: string;
23
+ vfs: string;
24
+ }
25
+ /**
26
+ * Interface for the complete color configuration.
27
+ */
28
+ export interface ColorConfig {
29
+ icons?: IconConfig;
30
+ fileTypes: {
31
+ dir: ColorStyle;
32
+ file: ColorStyle;
33
+ link: ColorStyle;
34
+ plugin: ColorStyle;
35
+ pipeline: ColorStyle;
36
+ vfs: ColorStyle;
37
+ };
38
+ specialPaths: {
39
+ [path: string]: ColorStyle;
40
+ };
41
+ }
42
+ /**
43
+ * Gets the colorized text for a file system item based on its type.
44
+ *
45
+ * @param name - The name of the item.
46
+ * @param type - The type of the item ('dir', 'file', 'link', 'plugin', 'vfs').
47
+ * @param fullPath - Optional full path for special path handling.
48
+ * @returns The colorized name with optional icon prefix.
49
+ */
50
+ export declare function fileSystemItem_colorize(name: string, type: 'dir' | 'file' | 'link' | 'plugin' | 'pipeline' | 'vfs' | 'job', fullPath?: string): string;
51
+ /**
52
+ * Gets the color configuration.
53
+ *
54
+ * @returns The current color configuration.
55
+ */
56
+ export declare function colorConfig_get(): ColorConfig;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * @file Color Configuration Loader
3
+ *
4
+ * Loads and manages color scheme configuration for file system types
5
+ * from the colors.yml configuration file.
6
+ *
7
+ * @module
8
+ */
9
+ import yaml from 'js-yaml';
10
+ import * as fs from 'fs';
11
+ import * as path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ import chalk from 'chalk';
14
+ let cachedConfig = null;
15
+ /**
16
+ * Loads the color configuration from colors.yml.
17
+ *
18
+ * @returns The parsed color configuration.
19
+ */
20
+ function colorConfig_load() {
21
+ if (cachedConfig) {
22
+ return cachedConfig;
23
+ }
24
+ // Use import.meta.url for ESM (chili is built as ESM)
25
+ const __filename = fileURLToPath(import.meta.url);
26
+ const __dirname = path.dirname(__filename);
27
+ const configPath = path.resolve(__dirname, '../../config/colors.yml');
28
+ try {
29
+ const fileContents = fs.readFileSync(configPath, 'utf8');
30
+ cachedConfig = yaml.load(fileContents);
31
+ return cachedConfig;
32
+ }
33
+ catch (e) {
34
+ const msg = e instanceof Error ? e.message : String(e);
35
+ console.error(`Warning: Could not load color config: ${msg}`);
36
+ return {
37
+ icons: {
38
+ enabled: true,
39
+ dir: '\uF07C',
40
+ file: '\uF15B',
41
+ link: '\uF0C1',
42
+ plugin: '\uF013',
43
+ pipeline: '\uF013',
44
+ vfs: '\uF0C8'
45
+ },
46
+ fileTypes: {
47
+ dir: { color: 'cyan', bold: true },
48
+ file: { color: 'white', bold: false },
49
+ link: { color: 'magenta', bold: false },
50
+ plugin: { color: 'green', bold: true },
51
+ pipeline: { color: 'magenta', bold: true },
52
+ vfs: { color: 'cyanBright', bold: true }
53
+ },
54
+ specialPaths: {
55
+ '/bin': { color: 'cyan', bold: true },
56
+ '~': { color: 'blue', bold: false }
57
+ }
58
+ };
59
+ }
60
+ }
61
+ /**
62
+ * Applies color style to text using chalk.
63
+ *
64
+ * @param text - The text to colorize.
65
+ * @param style - The color style configuration.
66
+ * @returns The colorized text.
67
+ */
68
+ function colorStyle_apply(text, style) {
69
+ let styledText = text;
70
+ // Apply color
71
+ if (style.color && typeof chalk[style.color] === 'function') {
72
+ const colorFn = chalk[style.color];
73
+ styledText = colorFn(styledText);
74
+ }
75
+ // Apply modifiers
76
+ if (style.bold)
77
+ styledText = chalk.bold(styledText);
78
+ if (style.dim)
79
+ styledText = chalk.dim(styledText);
80
+ if (style.italic)
81
+ styledText = chalk.italic(styledText);
82
+ if (style.underline)
83
+ styledText = chalk.underline(styledText);
84
+ if (style.inverse)
85
+ styledText = chalk.inverse(styledText);
86
+ if (style.strikethrough)
87
+ styledText = chalk.strikethrough(styledText);
88
+ return styledText;
89
+ }
90
+ /**
91
+ * Gets the colorized text for a file system item based on its type.
92
+ *
93
+ * @param name - The name of the item.
94
+ * @param type - The type of the item ('dir', 'file', 'link', 'plugin', 'vfs').
95
+ * @param fullPath - Optional full path for special path handling.
96
+ * @returns The colorized name with optional icon prefix.
97
+ */
98
+ export function fileSystemItem_colorize(name, type, fullPath) {
99
+ const config = colorConfig_load();
100
+ let icon = '';
101
+ if (config.icons && config.icons.enabled) {
102
+ const iconKey = type in config.icons ? type : 'file';
103
+ icon = config.icons[iconKey] + ' ';
104
+ }
105
+ if (fullPath && config.specialPaths[fullPath]) {
106
+ const styled = colorStyle_apply(name, config.specialPaths[fullPath]);
107
+ return icon ? colorStyle_apply(icon, config.specialPaths[fullPath]) + styled : styled;
108
+ }
109
+ // Fallback: check if the name itself is a special path key
110
+ if (config.specialPaths[name]) {
111
+ const styled = colorStyle_apply(name, config.specialPaths[name]);
112
+ return icon ? colorStyle_apply(icon, config.specialPaths[name]) + styled : styled;
113
+ }
114
+ // Fallback: check if /name is a special path key
115
+ if (config.specialPaths[`/${name}`]) {
116
+ const styled = colorStyle_apply(name, config.specialPaths[`/${name}`]);
117
+ return icon ? colorStyle_apply(icon, config.specialPaths[`/${name}`]) + styled : styled;
118
+ }
119
+ // Special handling for plugins with versions: color version part differently
120
+ if (type === 'plugin' && name.includes('-v')) {
121
+ const lastVIndex = name.lastIndexOf('-v');
122
+ const pluginName = name.substring(0, lastVIndex);
123
+ const version = name.substring(lastVIndex);
124
+ // Plugin name in bold green, version in dim green
125
+ const nameStyled = chalk.green.bold(pluginName);
126
+ const versionStyled = chalk.green.dim(version);
127
+ const iconStyled = icon ? chalk.green.bold(icon) : '';
128
+ return iconStyled + nameStyled + versionStyled;
129
+ }
130
+ // Special handling for plugins without versions (builtins in /usr/bin): bright green
131
+ if (type === 'plugin' && !name.includes('-v')) {
132
+ const styled = chalk.greenBright.bold(name);
133
+ const iconStyled = icon ? chalk.greenBright.bold(icon) : '';
134
+ return iconStyled + styled;
135
+ }
136
+ // Pipeline: bold magenta
137
+ if (type === 'pipeline') {
138
+ const styled = chalk.magenta.bold(name);
139
+ const iconStyled = icon ? chalk.magenta.bold(icon) : '';
140
+ return iconStyled + styled;
141
+ }
142
+ // Job (proc instance / feed dir): cyan bold like a directory — it IS navigable
143
+ if (type === 'job') {
144
+ const styled = chalk.cyan.bold(name);
145
+ const iconStyled = icon ? chalk.cyan.bold(icon) : '';
146
+ return iconStyled + styled;
147
+ }
148
+ // Apply file type styling
149
+ const style = config.fileTypes[type] ?? config.fileTypes.file;
150
+ const styled = colorStyle_apply(name, style);
151
+ const iconStyled = icon ? colorStyle_apply(icon, style) : '';
152
+ return iconStyled + styled;
153
+ }
154
+ /**
155
+ * Gets the color configuration.
156
+ *
157
+ * @returns The current color configuration.
158
+ */
159
+ export function colorConfig_get() {
160
+ return colorConfig_load();
161
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file Implements the setup for connection-related CLI commands.
3
+ *
4
+ * This module provides the `connectCommand_setup` function which configures
5
+ * the `connect` and `logout` commands in the main CLI program.
6
+ *
7
+ * @module
8
+ */
9
+ import { Command } from "commander";
10
+ /**
11
+ * Sets up the 'connect' and 'logout' commands for the CLI program.
12
+ *
13
+ * @param program - The Commander.js program instance.
14
+ */
15
+ export declare function connectCommand_setup(program: Command): void;
@@ -0,0 +1,48 @@
1
+ import { connect_login } from "../commands/connect/login.js";
2
+ import { connect_logout } from "../commands/connect/logout.js";
3
+ import { login_render, logout_render } from "../views/connect.js";
4
+ import chalk from "chalk";
5
+ /**
6
+ * Sets up the 'connect' and 'logout' commands for the CLI program.
7
+ *
8
+ * @param program - The Commander.js program instance.
9
+ */
10
+ export function connectCommand_setup(program) {
11
+ program
12
+ .command("connect <url>")
13
+ .description("Connect to a ChRIS CUBE instance")
14
+ .option("-u, --user <user>", "username")
15
+ .option("-p, --password <password>", "password")
16
+ .action(async (url, options) => {
17
+ const user = options.user || 'unknown';
18
+ const connectOptions = {
19
+ url,
20
+ user: options.user || '',
21
+ password: options.password || '',
22
+ debug: false,
23
+ };
24
+ try {
25
+ const success = await connect_login(connectOptions);
26
+ console.log(login_render(success, url, user));
27
+ }
28
+ catch (error) {
29
+ console.log(login_render(false, url, user));
30
+ const msg = error instanceof Error ? error.message : String(error);
31
+ console.error(chalk.red(`Error: ${msg}`));
32
+ }
33
+ });
34
+ program
35
+ .command("logout")
36
+ .description("Log out from ChRIS")
37
+ .action(async () => {
38
+ try {
39
+ await connect_logout();
40
+ console.log(logout_render(true));
41
+ }
42
+ catch (error) {
43
+ console.log(logout_render(false));
44
+ const msg = error instanceof Error ? error.message : String(error);
45
+ console.error(chalk.red(`Error: ${msg}`));
46
+ }
47
+ });
48
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file Commander setup for the `context` command group.
3
+ *
4
+ * @module
5
+ */
6
+ import { Command } from "commander";
7
+ /**
8
+ * Sets up the 'context' command for the CLI program, allowing users to
9
+ * get and set various ChRIS context parameters.
10
+ *
11
+ * @param program - The Commander.js program instance.
12
+ */
13
+ export declare function contextCommand_setup(program: Command): Promise<void>;
@@ -0,0 +1,193 @@
1
+ /**
2
+ * @file Commander setup for the `context` command group.
3
+ *
4
+ * @module
5
+ */
6
+ import { errorStack, } from "@fnndsc/cumin";
7
+ import { context_getFull, context_getSingle, context_set as salsa_context_set } from "@fnndsc/salsa";
8
+ import chalk from "chalk";
9
+ // import Table from "cli-table3";
10
+ import { screen, border_draw, table_display } from "../screen/screen.js";
11
+ /**
12
+ * Retrieves and formats ChRIS context information based on CLI options.
13
+ *
14
+ * @param options - CLI options for context retrieval.
15
+ * @returns A formatted string of context information.
16
+ */
17
+ async function context_get(options) {
18
+ const results = [];
19
+ if (options.all) {
20
+ return context_displayFull(options);
21
+ }
22
+ else {
23
+ return context_displaySingle(options);
24
+ }
25
+ }
26
+ /**
27
+ * Retrieves and displays the full ChRIS context, including all users and their URLs.
28
+ *
29
+ * @param options - CLI options (currently only `all` is used to trigger this function).
30
+ * @returns An empty string, as output is directly to console via `displayTable`.
31
+ */
32
+ function context_displayFull(options) {
33
+ const fullContext = context_getFull();
34
+ const currentUser = fullContext.currentUser;
35
+ const currentURL = fullContext.currentURL;
36
+ Object.entries(fullContext.users).forEach(([user, userContext]) => {
37
+ const tableData = Object.entries(userContext.urls).map(([url, urlContext]) => ({
38
+ URL: url,
39
+ Folder: urlContext.folder || "Not set",
40
+ Feed: urlContext.feed || "Not set",
41
+ Plugin: urlContext.plugin || "Not set",
42
+ PACS: urlContext.pacsserver || "Not set",
43
+ Token: urlContext.token ? "Set" : "Not set",
44
+ }));
45
+ // Apply highlighting
46
+ tableData.forEach((row) => {
47
+ if (row.URL === currentURL && user === currentUser) {
48
+ Object.keys(row).forEach((key) => {
49
+ row[key] = chalk.cyan(row[key]);
50
+ });
51
+ }
52
+ });
53
+ table_display(tableData, ["URL", "Folder", "Feed", "Plugin", "PACS", "Token"], {
54
+ title: {
55
+ title: `User: ${user}`,
56
+ justification: "center",
57
+ },
58
+ });
59
+ });
60
+ return "";
61
+ }
62
+ /**
63
+ * Retrieves and displays a single ChRIS context (current context).
64
+ *
65
+ * @param options - CLI options for context retrieval (e.g., --full, --ChRISurl).
66
+ * @returns A formatted string of context information, or an empty string if output handled by `screen.table_output`.
67
+ */
68
+ async function context_displaySingle(options) {
69
+ const singleContext = await context_getSingle();
70
+ if (options.full) {
71
+ const tableData = [
72
+ {
73
+ Context: "ChRIS URL",
74
+ Value: singleContext.URL || "Not set",
75
+ },
76
+ {
77
+ Context: "ChRIS User",
78
+ Value: singleContext.user || "Not set",
79
+ },
80
+ {
81
+ Context: "ChRIS Folder",
82
+ Value: singleContext.folder || "Not set",
83
+ },
84
+ {
85
+ Context: "ChRIS Feed",
86
+ Value: singleContext.feed || "Not set",
87
+ },
88
+ {
89
+ Context: "ChRIS Plugin",
90
+ Value: singleContext.plugin || "Not set",
91
+ },
92
+ {
93
+ Context: "PACS Server",
94
+ Value: singleContext.pacsserver || "Not set",
95
+ },
96
+ ];
97
+ console.log(screen.table_output(tableData, {
98
+ head: ["Context", "Value"],
99
+ columns: [
100
+ { color: "yellow", justification: "right" },
101
+ { color: "cyan", justification: "left" },
102
+ ],
103
+ title: {
104
+ title: "ChRIS Context",
105
+ justification: "center",
106
+ },
107
+ }));
108
+ return ""; // screen.table directly outputs to console, so we return an empty string
109
+ }
110
+ else {
111
+ const results = [];
112
+ if (options.ChRISurl) {
113
+ results.push(`ChRIS URL: ${singleContext.URL || "Not set"}`);
114
+ }
115
+ if (options.ChRISuser) {
116
+ results.push(`ChRIS User: ${singleContext.user || "Not set"}`);
117
+ }
118
+ if (options.ChRISfolder) {
119
+ results.push(`ChRIS Folder: ${singleContext.folder || "Not set"}`);
120
+ }
121
+ if (options.ChRISfeed) {
122
+ results.push(`ChRIS Feed: ${singleContext.feed || "Not set"}`);
123
+ }
124
+ if (options.ChRISplugin) {
125
+ results.push(`ChRIS Plugin: ${singleContext.plugin || "Not set"}`);
126
+ }
127
+ if (options.pacsserver) {
128
+ results.push(`PACS Server: ${singleContext.pacsserver || "Not set"}`);
129
+ }
130
+ if (results.length === 0) {
131
+ results.push("No specific context requested. Use --ChRISurl, --ChRISuser, --ChRISfolder, --ChRISfeed, --pacsserver, or --full");
132
+ }
133
+ return results.join("\n");
134
+ }
135
+ }
136
+ /**
137
+ * Sets various ChRIS context parameters based on CLI options.
138
+ *
139
+ * @param options - CLI options for setting context.
140
+ * @returns A formatted string summarizing the context changes.
141
+ */
142
+ async function context_set(options) {
143
+ const result = await salsa_context_set(options);
144
+ if (!result.ok) {
145
+ const errors = errorStack.allOfType_get('error');
146
+ border_draw(chalk.red(`ERROR: ${errors.join('\n')}`));
147
+ return "";
148
+ }
149
+ if (result.value.length === 0) {
150
+ return "No context value was set. Use --ChRISurl, --ChRISuser, --ChRISFolder, --ChRISfeed, or --ChRISPlugin";
151
+ }
152
+ return result.value.join("\n");
153
+ }
154
+ /**
155
+ * Sets up the 'context' command for the CLI program, allowing users to
156
+ * get and set various ChRIS context parameters.
157
+ *
158
+ * @param program - The Commander.js program instance.
159
+ */
160
+ export async function contextCommand_setup(program) {
161
+ const contextCommand = program
162
+ .command("context")
163
+ .description("Manipulate the ChRIS context");
164
+ contextCommand
165
+ .command("get")
166
+ .description("get information about the current context")
167
+ .option("--ChRISurl", "get the ChRIS URL for this context")
168
+ .option("--ChRISuser", "get the ChRIS user for this context")
169
+ .option("--ChRISfolder", "get the current ChRIS Folder context")
170
+ .option("--ChRISfeed", "get the current ChRIS Feed context")
171
+ .option("--ChRISplugin", "get the current ChRIS Plugin (or instance) context")
172
+ .option("--pacsserver", "get the current PACS server context")
173
+ .option("--full", "get full current context")
174
+ .option("--all", "get all contexts for current session")
175
+ .action(async (options) => {
176
+ const result = await context_get(options);
177
+ console.log(result);
178
+ });
179
+ contextCommand
180
+ .command("set")
181
+ .description("set values for the ChRIS context")
182
+ .option("--ChRISurl <url>", "set the ChRIS URL for this context")
183
+ .option("--ChRISuser <user>", "set the ChRIS user for this context")
184
+ .option("--ChRISfolder <folder>", "set the current ChRIS Folder context")
185
+ .option("--ChRISfeed <feedID>", "set the current ChRIS Feed context")
186
+ .option("--ChRISplugin <pluginID>", "set the current ChRIS Plugin (or instance) context")
187
+ .option("--pacsserver <pacsserver>", "set the current PACS server context")
188
+ .action(async (options) => {
189
+ const result = await context_set(options);
190
+ if (result.length)
191
+ border_draw(result);
192
+ });
193
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file Base controller: shared resource listing and presentation logic.
3
+ *
4
+ * @module
5
+ */
6
+ import { FilteredResourceData, ChRISPluginGroup, ChRISFeedGroup, ChRISEmbeddedResourceGroup, ResourcesByFields } from "@fnndsc/cumin";
7
+ import { CLIoptions } from "../utils/cli.js";
8
+ /**
9
+ * Base controller for managing ChRIS resources.
10
+ * Encapsulates business logic for fetching, filtering, and deleting resources.
11
+ * UI-agnostic.
12
+ */
13
+ export declare class BaseController {
14
+ chrisObject: ChRISPluginGroup | ChRISFeedGroup | ChRISEmbeddedResourceGroup<unknown>;
15
+ constructor(chrisObject: ChRISPluginGroup | ChRISFeedGroup | ChRISEmbeddedResourceGroup<unknown>);
16
+ /**
17
+ * Fetches and filters resources based on provided options.
18
+ *
19
+ * @param options - CLI options for filtering and pagination.
20
+ * @returns A Promise resolving to FilteredResourceData or null if no resources found.
21
+ */
22
+ resources_get(options: CLIoptions): Promise<FilteredResourceData | null>;
23
+ /**
24
+ * Fetches the available fields for the resource type.
25
+ *
26
+ * @returns A Promise resolving to ResourcesByFields or null.
27
+ */
28
+ resourceFields_get(): Promise<ResourcesByFields | null>;
29
+ /**
30
+ * Deletes a resource by its ID.
31
+ *
32
+ * @param id - The ID of the resource to delete.
33
+ * @returns A Promise resolving to true if successful, false otherwise.
34
+ */
35
+ resource_delete(id: number): Promise<boolean>;
36
+ /**
37
+ * Resolves search terms to a list of resource IDs.
38
+ *
39
+ * @param options - CLI options containing search terms.
40
+ * @returns A Promise resolving to an array of IDs or null.
41
+ */
42
+ resourceIDs_resolve(options: CLIoptions): Promise<number[] | null>;
43
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @file Base controller: shared resource listing and presentation logic.
3
+ *
4
+ * @module
5
+ */
6
+ import { record_extract, listParams_fromOptions } from "@fnndsc/cumin";
7
+ /**
8
+ * Base controller for managing ChRIS resources.
9
+ * Encapsulates business logic for fetching, filtering, and deleting resources.
10
+ * UI-agnostic.
11
+ */
12
+ export class BaseController {
13
+ constructor(chrisObject) {
14
+ this.chrisObject = chrisObject;
15
+ }
16
+ /**
17
+ * Fetches and filters resources based on provided options.
18
+ *
19
+ * @param options - CLI options for filtering and pagination.
20
+ * @returns A Promise resolving to FilteredResourceData or null if no resources found.
21
+ */
22
+ async resources_get(options) {
23
+ try {
24
+ const params = listParams_fromOptions(options);
25
+ const results = await this.chrisObject.asset.resources_listAndFilterByOptions(params);
26
+ return results;
27
+ }
28
+ catch (error) {
29
+ // Error handling is delegated to the caller or logged to errorStack
30
+ // For now, we let the errorStack mechanisms in cumin handle internal logging
31
+ // but we might want to bubble up specific errors.
32
+ return null;
33
+ }
34
+ }
35
+ /**
36
+ * Fetches the available fields for the resource type.
37
+ *
38
+ * @returns A Promise resolving to ResourcesByFields or null.
39
+ */
40
+ async resourceFields_get() {
41
+ return await this.chrisObject.asset.resourceFields_get();
42
+ }
43
+ /**
44
+ * Deletes a resource by its ID.
45
+ *
46
+ * @param id - The ID of the resource to delete.
47
+ * @returns A Promise resolving to true if successful, false otherwise.
48
+ */
49
+ async resource_delete(id) {
50
+ return await this.chrisObject.asset.resourceItem_delete(id);
51
+ }
52
+ /**
53
+ * Resolves search terms to a list of resource IDs.
54
+ *
55
+ * @param options - CLI options containing search terms.
56
+ * @returns A Promise resolving to an array of IDs or null.
57
+ */
58
+ async resourceIDs_resolve(options) {
59
+ const params = listParams_fromOptions(options);
60
+ const searchResults = await this.chrisObject.asset.resources_listAndFilterByOptions(params);
61
+ if (!searchResults) {
62
+ return null;
63
+ }
64
+ const queryHits = record_extract(searchResults.tableData, "id");
65
+ return queryHits.hits;
66
+ }
67
+ }