@fnndsc/cumin 3.2.4

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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -0
  3. package/dist/activities/chrisActivity.d.ts +19 -0
  4. package/dist/activities/chrisActivity.js +29 -0
  5. package/dist/activities/chrisActivity.js.map +1 -0
  6. package/dist/cache/index.d.ts +9 -0
  7. package/dist/cache/index.js +15 -0
  8. package/dist/cache/index.js.map +1 -0
  9. package/dist/cache/listCache.d.ts +182 -0
  10. package/dist/cache/listCache.js +266 -0
  11. package/dist/cache/listCache.js.map +1 -0
  12. package/dist/cache/procCache.d.ts +150 -0
  13. package/dist/cache/procCache.js +257 -0
  14. package/dist/cache/procCache.js.map +1 -0
  15. package/dist/cli.d.ts +7 -0
  16. package/dist/cli.js +43 -0
  17. package/dist/cli.js.map +1 -0
  18. package/dist/compute/computeResources.d.ts +65 -0
  19. package/dist/compute/computeResources.js +113 -0
  20. package/dist/compute/computeResources.js.map +1 -0
  21. package/dist/config/config.d.ts +221 -0
  22. package/dist/config/config.js +350 -0
  23. package/dist/config/config.js.map +1 -0
  24. package/dist/connect/chrisConnection.d.ts +121 -0
  25. package/dist/connect/chrisConnection.js +303 -0
  26. package/dist/connect/chrisConnection.js.map +1 -0
  27. package/dist/context/chrisContext.d.ts +110 -0
  28. package/dist/context/chrisContext.js +324 -0
  29. package/dist/context/chrisContext.js.map +1 -0
  30. package/dist/error/errorStack.d.ts +115 -0
  31. package/dist/error/errorStack.js +175 -0
  32. package/dist/error/errorStack.js.map +1 -0
  33. package/dist/feeds/chrisFeed.d.ts +188 -0
  34. package/dist/feeds/chrisFeed.js +432 -0
  35. package/dist/feeds/chrisFeed.js.map +1 -0
  36. package/dist/filebrowser/chrisFileBrowser.d.ts +77 -0
  37. package/dist/filebrowser/chrisFileBrowser.js +134 -0
  38. package/dist/filebrowser/chrisFileBrowser.js.map +1 -0
  39. package/dist/filebrowser/chrisFiles.d.ts +67 -0
  40. package/dist/filebrowser/chrisFiles.js +130 -0
  41. package/dist/filebrowser/chrisFiles.js.map +1 -0
  42. package/dist/filebrowser/chrisPACS.d.ts +43 -0
  43. package/dist/filebrowser/chrisPACS.js +103 -0
  44. package/dist/filebrowser/chrisPACS.js.map +1 -0
  45. package/dist/filebrowser/chrisPipeline.d.ts +47 -0
  46. package/dist/filebrowser/chrisPipeline.js +118 -0
  47. package/dist/filebrowser/chrisPipeline.js.map +1 -0
  48. package/dist/groups/chrisGroups.d.ts +11 -0
  49. package/dist/groups/chrisGroups.js +18 -0
  50. package/dist/groups/chrisGroups.js.map +1 -0
  51. package/dist/index.d.ts +68 -0
  52. package/dist/index.js +86 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/io/browser_io.d.ts +97 -0
  55. package/dist/io/browser_io.js +149 -0
  56. package/dist/io/browser_io.js.map +1 -0
  57. package/dist/io/chrisIO.d.ts +110 -0
  58. package/dist/io/chrisIO.js +415 -0
  59. package/dist/io/chrisIO.js.map +1 -0
  60. package/dist/io/io.d.ts +21 -0
  61. package/dist/io/io.js +6 -0
  62. package/dist/io/io.js.map +1 -0
  63. package/dist/io/node_io.d.ts +30 -0
  64. package/dist/io/node_io.js +188 -0
  65. package/dist/io/node_io.js.map +1 -0
  66. package/dist/jobs/chrisJob.d.ts +43 -0
  67. package/dist/jobs/chrisJob.js +169 -0
  68. package/dist/jobs/chrisJob.js.map +1 -0
  69. package/dist/jobs/index.d.ts +7 -0
  70. package/dist/jobs/index.js +24 -0
  71. package/dist/jobs/index.js.map +1 -0
  72. package/dist/jobs/jobMonitor.d.ts +46 -0
  73. package/dist/jobs/jobMonitor.js +102 -0
  74. package/dist/jobs/jobMonitor.js.map +1 -0
  75. package/dist/pacs/chrisPACS.d.ts +200 -0
  76. package/dist/pacs/chrisPACS.js +562 -0
  77. package/dist/pacs/chrisPACS.js.map +1 -0
  78. package/dist/path/chrisPath.d.ts +78 -0
  79. package/dist/path/chrisPath.js +190 -0
  80. package/dist/path/chrisPath.js.map +1 -0
  81. package/dist/pipelines/chrisPipeline.d.ts +86 -0
  82. package/dist/pipelines/chrisPipeline.js +180 -0
  83. package/dist/pipelines/chrisPipeline.js.map +1 -0
  84. package/dist/pluginmetas/chrisPluginMetas.d.ts +11 -0
  85. package/dist/pluginmetas/chrisPluginMetas.js +18 -0
  86. package/dist/pluginmetas/chrisPluginMetas.js.map +1 -0
  87. package/dist/plugins/chrisPluginMetaPlugins.d.ts +12 -0
  88. package/dist/plugins/chrisPluginMetaPlugins.js +19 -0
  89. package/dist/plugins/chrisPluginMetaPlugins.js.map +1 -0
  90. package/dist/plugins/chrisPlugins.d.ts +127 -0
  91. package/dist/plugins/chrisPlugins.js +528 -0
  92. package/dist/plugins/chrisPlugins.js.map +1 -0
  93. package/dist/resources/chrisEmbeddedResourceGroup.d.ts +73 -0
  94. package/dist/resources/chrisEmbeddedResourceGroup.js +148 -0
  95. package/dist/resources/chrisEmbeddedResourceGroup.js.map +1 -0
  96. package/dist/resources/chrisObjContext.d.ts +16 -0
  97. package/dist/resources/chrisObjContext.js +109 -0
  98. package/dist/resources/chrisObjContext.js.map +1 -0
  99. package/dist/resources/chrisResourceGroup.d.ts +30 -0
  100. package/dist/resources/chrisResourceGroup.js +47 -0
  101. package/dist/resources/chrisResourceGroup.js.map +1 -0
  102. package/dist/resources/chrisResources.d.ts +163 -0
  103. package/dist/resources/chrisResources.js +415 -0
  104. package/dist/resources/chrisResources.js.map +1 -0
  105. package/dist/tags/chrisTags.d.ts +11 -0
  106. package/dist/tags/chrisTags.js +18 -0
  107. package/dist/tags/chrisTags.js.map +1 -0
  108. package/dist/users/chrisUsers.d.ts +34 -0
  109. package/dist/users/chrisUsers.js +57 -0
  110. package/dist/users/chrisUsers.js.map +1 -0
  111. package/dist/utils/keypair.d.ts +77 -0
  112. package/dist/utils/keypair.js +144 -0
  113. package/dist/utils/keypair.js.map +1 -0
  114. package/dist/utils/result.d.ts +77 -0
  115. package/dist/utils/result.js +58 -0
  116. package/dist/utils/result.js.map +1 -0
  117. package/dist/utils/searchable.d.ts +143 -0
  118. package/dist/utils/searchable.js +212 -0
  119. package/dist/utils/searchable.js.map +1 -0
  120. package/dist/workflows/chrisWorkflows.d.ts +11 -0
  121. package/dist/workflows/chrisWorkflows.js +18 -0
  122. package/dist/workflows/chrisWorkflows.js.map +1 -0
  123. package/package.json +55 -0
@@ -0,0 +1,221 @@
1
+ /**
2
+ * @file Persistent connection and session configuration storage for cumin.
3
+ *
4
+ * @module
5
+ */
6
+ import { IStorageProvider } from "../io/io.js";
7
+ /**
8
+ * Options for configuring a ChRIS connection.
9
+ */
10
+ export interface ConnectionConfigOptions {
11
+ configDir?: string;
12
+ chrisURLfile?: string;
13
+ chrisURLfilepath?: string;
14
+ userFile?: string;
15
+ userFilepath?: string;
16
+ userContextDir?: string;
17
+ userChRISContextDir?: string;
18
+ currentDirectory?: string;
19
+ tokenFile?: string;
20
+ tokenFilepath?: string;
21
+ }
22
+ /**
23
+ * Options for configuring a ChRIS session.
24
+ */
25
+ export interface SessionConfigOptions {
26
+ cwdFile?: string;
27
+ cwdFilename?: string;
28
+ feedFile?: string;
29
+ feedFilename?: string;
30
+ pluginFile?: string;
31
+ pluginFilename?: string;
32
+ pacsserverFile?: string;
33
+ pacsserverFilename?: string;
34
+ storageProvider?: IStorageProvider;
35
+ }
36
+ /**
37
+ * Manages configuration for connecting to a ChRIS instance.
38
+ * Handles storage of user credentials, URLs, and context directories.
39
+ */
40
+ export declare class ConnectionConfig {
41
+ private static instance;
42
+ private storageProvider;
43
+ get storage(): IStorageProvider;
44
+ readonly configDir: string;
45
+ userContextDir: string;
46
+ userChRISContextDir: string;
47
+ userFile: string;
48
+ userFilepath: string;
49
+ chrisURLfile: string;
50
+ chrisURLfilepath: string;
51
+ tokenFile: string;
52
+ tokenFilepath: string;
53
+ readonly currentDirectory: string;
54
+ debug: boolean;
55
+ private constructor();
56
+ /**
57
+ * Get the singleton instance of ConnectionConfig.
58
+ *
59
+ * @param storageProvider - The storage provider to use.
60
+ * @param options - Optional configuration options.
61
+ * @returns A promise resolving to the ConnectionConfig instance.
62
+ */
63
+ static instance_get(storageProvider: IStorageProvider, options?: ConnectionConfigOptions): Promise<ConnectionConfig>;
64
+ /**
65
+ * Initialize the connection configuration.
66
+ * Loads last user and ChRIS URL from storage.
67
+ */
68
+ init(): Promise<void>;
69
+ /**
70
+ * Ensure a directory exists in storage.
71
+ *
72
+ * @param dir - The directory path to check/create.
73
+ */
74
+ private dir_ensureExists;
75
+ /**
76
+ * Convert a URI to a directory-safe string.
77
+ *
78
+ * @param uri - The URI to convert.
79
+ * @returns A string safe for use as a directory name.
80
+ */
81
+ uri_toDir(uri: string): string;
82
+ /**
83
+ * Convert a directory-safe string back to a URI.
84
+ *
85
+ * @param dir - The directory name to convert.
86
+ * @returns The reconstructed URI.
87
+ * @throws Error if the directory name format is invalid.
88
+ */
89
+ dir_toUri(dir: string): string;
90
+ /**
91
+ * Set the current user and ChRIS URL context.
92
+ *
93
+ * @param user - The username.
94
+ * @param url - Optional ChRIS URL.
95
+ */
96
+ context_set(user: string, url?: string): Promise<void>;
97
+ /**
98
+ * Save the last logged-in user to storage.
99
+ *
100
+ * @param user - The username to save.
101
+ * @returns True if successful, false otherwise.
102
+ */
103
+ lastUser_save(user: string): Promise<boolean>;
104
+ /**
105
+ * Save the ChRIS URL to storage.
106
+ *
107
+ * @param url - The URL to save.
108
+ * @returns True if successful, false otherwise.
109
+ */
110
+ chrisURL_save(url: string): Promise<boolean>;
111
+ /**
112
+ * Load the last logged-in user from storage.
113
+ *
114
+ * @returns The username or null if not found.
115
+ */
116
+ lastUser_load(): Promise<string | null>;
117
+ /**
118
+ * Load the saved ChRIS URL from storage.
119
+ *
120
+ * @returns The URL or null if not found.
121
+ */
122
+ chrisURL_load(): Promise<string | null>;
123
+ }
124
+ /**
125
+ * Manages session-specific configuration such as current working directory (CWD),
126
+ * active feed, and active plugin.
127
+ */
128
+ export declare class SessionConfig {
129
+ private static instance;
130
+ cwdFile: string;
131
+ cwdFilename: string;
132
+ feedFile: string;
133
+ feedFilename: string;
134
+ pluginFile: string;
135
+ pluginFilename: string;
136
+ pacsserverFile: string;
137
+ pacsserverFilename: string;
138
+ private connectionConfig;
139
+ private storageProvider;
140
+ private constructor();
141
+ get connection(): ConnectionConfig;
142
+ /**
143
+ * Get the singleton instance of SessionConfig.
144
+ *
145
+ * @param storageProvider - The storage provider to use.
146
+ * @param options - Optional configuration options.
147
+ * @returns A promise resolving to the SessionConfig instance.
148
+ */
149
+ static instance_get(storageProvider: IStorageProvider, options?: SessionConfigOptions): Promise<SessionConfig>;
150
+ /**
151
+ * Initialize the session configuration.
152
+ * Sets up filenames based on the user's context directory.
153
+ */
154
+ init(): Promise<void>;
155
+ /**
156
+ * Set the current working directory context.
157
+ *
158
+ * @param path - The path to save.
159
+ * @returns True if successful.
160
+ */
161
+ pathContext_set(path: string): Promise<boolean>;
162
+ /**
163
+ * Get the current working directory context.
164
+ *
165
+ * @returns The saved path or null if not found.
166
+ */
167
+ pathContext_get(): Promise<string | null>;
168
+ /**
169
+ * Set the active feed context.
170
+ *
171
+ * @param feedID - The ID of the feed.
172
+ * @returns True if successful.
173
+ */
174
+ feedContext_set(feedID: string): Promise<boolean>;
175
+ /**
176
+ * Get the active feed context.
177
+ *
178
+ * @returns The saved feed ID or null if not found.
179
+ */
180
+ feedContext_get(): Promise<string | null>;
181
+ /**
182
+ * Set the active plugin context.
183
+ *
184
+ * @param pluginID - The ID of the plugin.
185
+ * @returns True if successful.
186
+ */
187
+ pluginContext_set(pluginID: string): Promise<boolean>;
188
+ /**
189
+ * Get the active plugin context.
190
+ *
191
+ * @returns The saved plugin ID or null if not found.
192
+ */
193
+ pluginContext_get(): Promise<string | null>;
194
+ /**
195
+ * Set the active PACS server context.
196
+ *
197
+ * @param pacsServer - The PACS server identifier.
198
+ * @returns True if successful.
199
+ */
200
+ pacsserverContext_set(pacsServer: string): Promise<boolean>;
201
+ /**
202
+ * Get the active PACS server context.
203
+ *
204
+ * @returns The saved PACS server identifier or null if not found.
205
+ */
206
+ pacsserverContext_get(): Promise<string | null>;
207
+ }
208
+ /**
209
+ * Global connection configuration instance.
210
+ */
211
+ export declare let connectionConfig: ConnectionConfig;
212
+ /**
213
+ * Global session configuration instance.
214
+ */
215
+ export declare let sessionConfig: SessionConfig;
216
+ /**
217
+ * Initialize both connection and session configurations.
218
+ *
219
+ * @param storageProvider - The storage provider to use.
220
+ */
221
+ export declare function config_init(storageProvider: IStorageProvider): Promise<void>;
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ /**
3
+ * @file Persistent connection and session configuration storage for cumin.
4
+ *
5
+ * @module
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.sessionConfig = exports.connectionConfig = exports.SessionConfig = exports.ConnectionConfig = void 0;
42
+ exports.config_init = config_init;
43
+ const errorStack_js_1 = require("../error/errorStack.js");
44
+ const path = __importStar(require("path"));
45
+ const os = __importStar(require("os"));
46
+ const name = "@fnndsc/cumin";
47
+ /**
48
+ * Manages configuration for connecting to a ChRIS instance.
49
+ * Handles storage of user credentials, URLs, and context directories.
50
+ */
51
+ class ConnectionConfig {
52
+ get storage() {
53
+ return this.storageProvider;
54
+ }
55
+ constructor(options = {}, storageProvider) {
56
+ this.debug = false;
57
+ this.storageProvider = storageProvider;
58
+ const configBase = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
59
+ this.configDir = path.join(configBase, name);
60
+ this.userFile = options.userFile || "lastUser.txt";
61
+ this.userFilepath =
62
+ options.userFilepath || path.join(this.configDir, this.userFile);
63
+ this.userContextDir = options.userContextDir || "";
64
+ this.userChRISContextDir = options.userChRISContextDir || "";
65
+ this.chrisURLfile = options.chrisURLfile || "chrisurl.txt";
66
+ this.chrisURLfilepath = options.chrisURLfilepath || "";
67
+ this.tokenFile = name.replace("/", "_") + "_token.txt";
68
+ this.tokenFilepath = options.tokenFilepath || "";
69
+ this.currentDirectory = options.currentDirectory || process.cwd();
70
+ this.debug = process.env.CHILI_DEBUG === 'true';
71
+ }
72
+ /**
73
+ * Get the singleton instance of ConnectionConfig.
74
+ *
75
+ * @param storageProvider - The storage provider to use.
76
+ * @param options - Optional configuration options.
77
+ * @returns A promise resolving to the ConnectionConfig instance.
78
+ */
79
+ static async instance_get(storageProvider, options) {
80
+ if (!ConnectionConfig.instance) {
81
+ ConnectionConfig.instance = new ConnectionConfig(options, storageProvider);
82
+ await ConnectionConfig.instance.init();
83
+ }
84
+ return ConnectionConfig.instance;
85
+ }
86
+ /**
87
+ * Initialize the connection configuration.
88
+ * Loads last user and ChRIS URL from storage.
89
+ */
90
+ async init() {
91
+ await this.dir_ensureExists(this.configDir);
92
+ const lastUser = await this.lastUser_load();
93
+ if (!lastUser) {
94
+ return;
95
+ }
96
+ this.userContextDir = path.join(this.configDir, lastUser);
97
+ this.chrisURLfilepath = path.join(this.userContextDir, this.chrisURLfile);
98
+ const lastURL = await this.chrisURL_load();
99
+ if (!lastURL) {
100
+ return;
101
+ }
102
+ this.userChRISContextDir = path.join(this.userContextDir, this.uri_toDir(lastURL));
103
+ this.tokenFilepath = path.join(this.userChRISContextDir, this.tokenFile);
104
+ }
105
+ /**
106
+ * Ensure a directory exists in storage.
107
+ *
108
+ * @param dir - The directory path to check/create.
109
+ */
110
+ async dir_ensureExists(dir) {
111
+ if (!(await this.storageProvider.exists(dir))) {
112
+ await this.storageProvider.mkdir(dir, { recursive: true });
113
+ }
114
+ }
115
+ /**
116
+ * Convert a URI to a directory-safe string.
117
+ *
118
+ * @param uri - The URI to convert.
119
+ * @returns A string safe for use as a directory name.
120
+ */
121
+ uri_toDir(uri) {
122
+ return uri
123
+ .replace("://", "___") // Use triple underscore for protocol separator
124
+ .replace(/:/g, "===") // Use triple equals for colon (to handle port numbers)
125
+ .replace(/[/]/g, "_") // Replace slashes with single underscore
126
+ .replace(/\./g, "--"); // Use double dash for dots
127
+ }
128
+ /**
129
+ * Convert a directory-safe string back to a URI.
130
+ *
131
+ * @param dir - The directory name to convert.
132
+ * @returns The reconstructed URI.
133
+ * @throws Error if the directory name format is invalid.
134
+ */
135
+ dir_toUri(dir) {
136
+ let uri = dir
137
+ .replace(/--/g, ".") // Convert double dashes back to dots
138
+ .replace(/___/g, "://") // Convert triple underscore back to protocol separator
139
+ .replace(/===/g, ":"); // Convert triple equals back to colon
140
+ // Split the URI into protocol, domain (including port if present), and path
141
+ const parts = uri.split("://");
142
+ if (parts.length !== 2) {
143
+ throw new Error("Invalid directory name");
144
+ }
145
+ const [protocol, rest] = parts;
146
+ // Split at the first underscore, which should be after the domain and port
147
+ const [domainPart, ...pathParts] = rest.split("_");
148
+ // Join the path parts back with slashes
149
+ const path = pathParts.join("/");
150
+ return `${protocol}://${domainPart}/${path}`;
151
+ }
152
+ /**
153
+ * Set the current user and ChRIS URL context.
154
+ *
155
+ * @param user - The username.
156
+ * @param url - Optional ChRIS URL.
157
+ */
158
+ async context_set(user, url) {
159
+ await this.lastUser_save(user);
160
+ this.userContextDir = path.join(this.configDir, user);
161
+ await this.dir_ensureExists(this.userContextDir);
162
+ this.chrisURLfilepath = path.join(this.userContextDir, this.chrisURLfile);
163
+ if (!url) {
164
+ return;
165
+ }
166
+ await this.chrisURL_save(url);
167
+ this.userChRISContextDir = path.join(this.userContextDir, this.uri_toDir(url));
168
+ await this.dir_ensureExists(this.userChRISContextDir);
169
+ this.tokenFilepath = path.join(this.userChRISContextDir, this.tokenFile);
170
+ }
171
+ /**
172
+ * Save the last logged-in user to storage.
173
+ *
174
+ * @param user - The username to save.
175
+ * @returns True if successful, false otherwise.
176
+ */
177
+ async lastUser_save(user) {
178
+ const userDir = path.dirname(this.userFilepath);
179
+ const userFolderPath = path.join(userDir, user);
180
+ if (await this.storageProvider.exists(userFolderPath)) {
181
+ await this.storageProvider.write(this.userFilepath, user);
182
+ return true;
183
+ }
184
+ errorStack_js_1.errorStack.stack_push("error", `user '${user}' has not logged in previously -- no context found`);
185
+ return false;
186
+ }
187
+ /**
188
+ * Save the ChRIS URL to storage.
189
+ *
190
+ * @param url - The URL to save.
191
+ * @returns True if successful, false otherwise.
192
+ */
193
+ async chrisURL_save(url) {
194
+ const urlDir = path.dirname(this.chrisURLfilepath);
195
+ const urlFolderPath = path.join(urlDir, this.uri_toDir(url));
196
+ if (await this.storageProvider.exists(urlFolderPath)) {
197
+ await this.storageProvider.write(this.chrisURLfilepath, url);
198
+ return true;
199
+ }
200
+ errorStack_js_1.errorStack.stack_push("error", `URL '${url}' has not been accessed previously -- no context found`);
201
+ return false;
202
+ }
203
+ /**
204
+ * Load the last logged-in user from storage.
205
+ *
206
+ * @returns The username or null if not found.
207
+ */
208
+ async lastUser_load() {
209
+ return this.storageProvider.read(this.userFilepath);
210
+ }
211
+ /**
212
+ * Load the saved ChRIS URL from storage.
213
+ *
214
+ * @returns The URL or null if not found.
215
+ */
216
+ async chrisURL_load() {
217
+ const url = await this.storageProvider.read(this.chrisURLfilepath);
218
+ return url;
219
+ }
220
+ }
221
+ exports.ConnectionConfig = ConnectionConfig;
222
+ /**
223
+ * Manages session-specific configuration such as current working directory (CWD),
224
+ * active feed, and active plugin.
225
+ */
226
+ class SessionConfig {
227
+ constructor(options = {}, connectionConfig, storageProvider) {
228
+ this.cwdFile = options.cwdFile || "cwd.txt";
229
+ this.cwdFilename = options.cwdFilename || "";
230
+ this.feedFile = options.feedFile || "feed.txt";
231
+ this.feedFilename = options.feedFilename || "";
232
+ this.pluginFile = options.pluginFile || "plugin.txt";
233
+ this.pluginFilename = options.pluginFilename || "";
234
+ this.pacsserverFile = options.pacsserverFile || "pacsserver.txt";
235
+ this.pacsserverFilename = options.pacsserverFilename || "";
236
+ this.connectionConfig = connectionConfig;
237
+ this.storageProvider = storageProvider;
238
+ }
239
+ get connection() {
240
+ return this.connectionConfig;
241
+ }
242
+ /**
243
+ * Get the singleton instance of SessionConfig.
244
+ *
245
+ * @param storageProvider - The storage provider to use.
246
+ * @param options - Optional configuration options.
247
+ * @returns A promise resolving to the SessionConfig instance.
248
+ */
249
+ static async instance_get(storageProvider, options) {
250
+ if (!SessionConfig.instance) {
251
+ const connectionConfig = await ConnectionConfig.instance_get(storageProvider);
252
+ SessionConfig.instance = new SessionConfig(options, connectionConfig, storageProvider);
253
+ await SessionConfig.instance.init();
254
+ }
255
+ return SessionConfig.instance;
256
+ }
257
+ /**
258
+ * Initialize the session configuration.
259
+ * Sets up filenames based on the user's context directory.
260
+ */
261
+ async init() {
262
+ this.cwdFilename = path.join(this.connectionConfig.userChRISContextDir, this.cwdFile);
263
+ this.feedFilename = path.join(this.connectionConfig.userChRISContextDir, this.feedFile);
264
+ this.pluginFilename = path.join(this.connectionConfig.userChRISContextDir, this.pluginFile);
265
+ this.pacsserverFilename = path.join(this.connectionConfig.userChRISContextDir, this.pacsserverFile);
266
+ }
267
+ /**
268
+ * Set the current working directory context.
269
+ *
270
+ * @param path - The path to save.
271
+ * @returns True if successful.
272
+ */
273
+ async pathContext_set(path) {
274
+ await this.storageProvider.write(this.cwdFilename, path);
275
+ return true;
276
+ }
277
+ /**
278
+ * Get the current working directory context.
279
+ *
280
+ * @returns The saved path or null if not found.
281
+ */
282
+ async pathContext_get() {
283
+ return this.storageProvider.read(this.cwdFilename);
284
+ }
285
+ /**
286
+ * Set the active feed context.
287
+ *
288
+ * @param feedID - The ID of the feed.
289
+ * @returns True if successful.
290
+ */
291
+ async feedContext_set(feedID) {
292
+ await this.storageProvider.write(this.feedFilename, feedID);
293
+ return true;
294
+ }
295
+ /**
296
+ * Get the active feed context.
297
+ *
298
+ * @returns The saved feed ID or null if not found.
299
+ */
300
+ async feedContext_get() {
301
+ return this.storageProvider.read(this.feedFilename);
302
+ }
303
+ /**
304
+ * Set the active plugin context.
305
+ *
306
+ * @param pluginID - The ID of the plugin.
307
+ * @returns True if successful.
308
+ */
309
+ async pluginContext_set(pluginID) {
310
+ await this.storageProvider.write(this.pluginFilename, pluginID);
311
+ return true;
312
+ }
313
+ /**
314
+ * Get the active plugin context.
315
+ *
316
+ * @returns The saved plugin ID or null if not found.
317
+ */
318
+ async pluginContext_get() {
319
+ return this.storageProvider.read(this.pluginFilename);
320
+ }
321
+ /**
322
+ * Set the active PACS server context.
323
+ *
324
+ * @param pacsServer - The PACS server identifier.
325
+ * @returns True if successful.
326
+ */
327
+ async pacsserverContext_set(pacsServer) {
328
+ await this.storageProvider.write(this.pacsserverFilename, pacsServer);
329
+ return true;
330
+ }
331
+ /**
332
+ * Get the active PACS server context.
333
+ *
334
+ * @returns The saved PACS server identifier or null if not found.
335
+ */
336
+ async pacsserverContext_get() {
337
+ return this.storageProvider.read(this.pacsserverFilename);
338
+ }
339
+ }
340
+ exports.SessionConfig = SessionConfig;
341
+ /**
342
+ * Initialize both connection and session configurations.
343
+ *
344
+ * @param storageProvider - The storage provider to use.
345
+ */
346
+ async function config_init(storageProvider) {
347
+ exports.connectionConfig = await ConnectionConfig.instance_get(storageProvider);
348
+ exports.sessionConfig = await SessionConfig.instance_get(storageProvider);
349
+ }
350
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgcH,kCAGC;AA/bD,0DAAoD;AACpD,2CAA6B;AAC7B,uCAAyB;AAEzB,MAAM,IAAI,GAAW,eAAe,CAAC;AAiCrC;;;GAGG;AACH,MAAa,gBAAgB;IAI3B,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAcD,YACE,UAAmC,EAAE,EACrC,eAAiC;QAJ5B,UAAK,GAAY,KAAK,CAAC;QAM5B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,MAAM,UAAU,GACd,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC;QACnD,IAAI,CAAC,YAAY;YACf,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnE,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB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