@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,121 @@
1
+ /**
2
+ * @file ChRIS Connection Management
3
+ *
4
+ * This module provides the `ChRISConnection` class, responsible for managing
5
+ * the connection to a ChRIS CUBE, including authentication, token handling,
6
+ * and context setting. It abstracts away the underlying storage mechanisms
7
+ * for configuration and tokens using `IStorageProvider`.
8
+ *
9
+ * @module
10
+ */
11
+ import Client from "@fnndsc/chrisapi";
12
+ import { ConnectionConfig } from "../config/config.js";
13
+ import { IStorageProvider } from "../io/io.js";
14
+ /**
15
+ * Re-exports the ChRIS API client for convenience.
16
+ */
17
+ export { Client };
18
+ /**
19
+ * Interface defining options for establishing a ChRIS connection.
20
+ */
21
+ interface ConnectOptions {
22
+ user: string;
23
+ password: string;
24
+ debug: boolean;
25
+ url: string;
26
+ }
27
+ /**
28
+ * Manages the connection and authentication with a ChRIS CUBE.
29
+ */
30
+ export declare class ChRISConnection {
31
+ private authToken;
32
+ private tokenFile;
33
+ private user;
34
+ private chrisURL;
35
+ private client;
36
+ private _config?;
37
+ private storageProvider?;
38
+ /**
39
+ * Constructs a new ChRISConnection instance.
40
+ * @param config - The connection configuration object.
41
+ * @param storageProvider - The storage provider for persistence.
42
+ */
43
+ constructor(config?: ConnectionConfig, storageProvider?: IStorageProvider);
44
+ /**
45
+ * Access the connection configuration.
46
+ */
47
+ get config(): ConnectionConfig | undefined;
48
+ /**
49
+ * Initializes the connection with configuration and storage provider.
50
+ * @param config - The connection configuration object.
51
+ * @param storageProvider - The storage provider for persistence.
52
+ */
53
+ init(config: ConnectionConfig, storageProvider: IStorageProvider): void;
54
+ /**
55
+ * Establishes a connection to the ChRIS CUBE and authenticates the user.
56
+ * @param options - Connection options including user, password, debug flag, and URL.
57
+ * @returns A Promise resolving to the authentication token on success, or null on failure.
58
+ */
59
+ connection_connect(options: ConnectOptions): Promise<string | null>;
60
+ /**
61
+ * Sets the ChRIS context based on a context string (e.g., user@url?folder=...).
62
+ * @param context - The context string.
63
+ * @returns A Promise resolving to true on success, false otherwise.
64
+ */
65
+ context_set(context: string): Promise<boolean>;
66
+ /**
67
+ * Retrieves the authentication token.
68
+ * @param forceLoad - If true, forces loading the token from storage.
69
+ * @returns A Promise resolving to the authentication token or null.
70
+ */
71
+ authToken_get(forceLoad?: boolean): Promise<string | null>;
72
+ /**
73
+ * Retrieves the current authenticated user's username.
74
+ * @returns A Promise resolving to the username string or null if not authenticated.
75
+ */
76
+ user_get(): Promise<string | null>;
77
+ /**
78
+ * Retrieves the ChRIS CUBE URL.
79
+ * @returns A Promise resolving to the ChRIS URL or null.
80
+ */
81
+ chrisURL_get(): Promise<string | null>;
82
+ /**
83
+ * Refreshes the ChRIS API client with current token and URL.
84
+ * @returns A Promise resolving to the refreshed Client instance or null.
85
+ */
86
+ client_refresh(): Promise<Client | null>;
87
+ /**
88
+ * Retrieves the ChRIS API client instance.
89
+ * @returns A Promise resolving to the Client instance or null.
90
+ */
91
+ client_get(): Promise<Client | null>;
92
+ /**
93
+ * Checks if the client is currently connected.
94
+ * @returns True if connected, false otherwise.
95
+ */
96
+ connection_isConnected(): boolean;
97
+ /**
98
+ * Logs out the user by clearing the authentication token from storage.
99
+ */
100
+ connection_logout(): Promise<void>;
101
+ /**
102
+ * Saves data to a specified file using the storage provider.
103
+ * @param file - The path to the file.
104
+ * @param info - The string data to save.
105
+ */
106
+ private token_saveToFile;
107
+ /**
108
+ * Loads the authentication token from storage.
109
+ * @returns A Promise that resolves when the token is loaded.
110
+ */
111
+ private token_load;
112
+ }
113
+ /**
114
+ * Global instance of ChRISConnection, initialized as a constant singleton.
115
+ */
116
+ export declare let chrisConnection: ChRISConnection;
117
+ /**
118
+ * Initializes the global ChRISConnection instance.
119
+ * @param storageProvider - The storage provider to use for the connection.
120
+ */
121
+ export declare function chrisConnection_init(storageProvider: IStorageProvider): Promise<ChRISConnection>;
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+ /**
3
+ * @file ChRIS Connection Management
4
+ *
5
+ * This module provides the `ChRISConnection` class, responsible for managing
6
+ * the connection to a ChRIS CUBE, including authentication, token handling,
7
+ * and context setting. It abstracts away the underlying storage mechanisms
8
+ * for configuration and tokens using `IStorageProvider`.
9
+ *
10
+ * @module
11
+ */
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.chrisConnection = exports.ChRISConnection = exports.Client = void 0;
17
+ exports.chrisConnection_init = chrisConnection_init;
18
+ const chrisapi_1 = __importDefault(require("@fnndsc/chrisapi"));
19
+ exports.Client = chrisapi_1.default;
20
+ const config_js_1 = require("../config/config.js");
21
+ const chrisContext_js_1 = require("../context/chrisContext.js");
22
+ const chrisIO_js_1 = require("../io/chrisIO.js");
23
+ const errorStack_js_1 = require("../error/errorStack.js");
24
+ const chalk_1 = __importDefault(require("chalk"));
25
+ /**
26
+ * Helper function to validate and format a context string.
27
+ * @param context - The context string to check.
28
+ * @returns The formatted context string.
29
+ */
30
+ function contextString_check(context) {
31
+ if (context.includes("://")) {
32
+ return context;
33
+ }
34
+ if (context.startsWith("?")) {
35
+ return context;
36
+ }
37
+ return "?" + context;
38
+ }
39
+ /**
40
+ * Manages the connection and authentication with a ChRIS CUBE.
41
+ */
42
+ class ChRISConnection {
43
+ /**
44
+ * Constructs a new ChRISConnection instance.
45
+ * @param config - The connection configuration object.
46
+ * @param storageProvider - The storage provider for persistence.
47
+ */
48
+ constructor(config, storageProvider) {
49
+ this.authToken = null;
50
+ this.user = null;
51
+ this.chrisURL = null;
52
+ this.client = null;
53
+ if (config && storageProvider) {
54
+ this.init(config, storageProvider);
55
+ }
56
+ // Ensure that config and storageProvider are not undefined if no args were passed.
57
+ // This allows the initial `new ChRISConnection()` to create a valid, though uninitialized, object.
58
+ this._config = config;
59
+ this.storageProvider = storageProvider;
60
+ }
61
+ /**
62
+ * Access the connection configuration.
63
+ */
64
+ get config() {
65
+ return this._config;
66
+ }
67
+ /**
68
+ * Initializes the connection with configuration and storage provider.
69
+ * @param config - The connection configuration object.
70
+ * @param storageProvider - The storage provider for persistence.
71
+ */
72
+ init(config, storageProvider) {
73
+ this._config = config;
74
+ this.storageProvider = storageProvider;
75
+ this.tokenFile = this._config.tokenFilepath;
76
+ }
77
+ /**
78
+ * Establishes a connection to the ChRIS CUBE and authenticates the user.
79
+ * @param options - Connection options including user, password, debug flag, and URL.
80
+ * @returns A Promise resolving to the authentication token on success, or null on failure.
81
+ */
82
+ async connection_connect(options) {
83
+ const { user, password, debug, url } = options;
84
+ // Ensure configuration is initialized before use
85
+ if (this.storageProvider) {
86
+ await (0, config_js_1.config_init)(this.storageProvider);
87
+ this._config = config_js_1.connectionConfig;
88
+ }
89
+ const authUrl = url + "auth-token/";
90
+ this.user = user;
91
+ this.chrisURL = url;
92
+ console.log(`Connecting to ${url} with user ${user}`);
93
+ await this._config.context_set(user, url);
94
+ this.tokenFile = this._config.tokenFilepath;
95
+ try {
96
+ this.authToken = await chrisapi_1.default.getAuthToken(authUrl, user, password);
97
+ if (this.authToken) {
98
+ // console.log("Auth token: " + this.authToken);
99
+ await this.token_saveToFile(this.tokenFile, this.authToken);
100
+ console.log("Auth token saved successfully");
101
+ console.log("ChRIS URL saved successfully");
102
+ return this.authToken;
103
+ }
104
+ else {
105
+ console.log("Failed to receive auth token");
106
+ return null;
107
+ }
108
+ }
109
+ catch (error) {
110
+ console.error("\nSome error seems to have been thrown while attempting to log in.");
111
+ console.error("If the ChRIS CUBE is reachable, then it's quite possible this means");
112
+ console.error("an incorrect login. Please check your login credentials carefully.");
113
+ console.error("Also, if your password has 'special' character, make sure how you");
114
+ console.error("are specifying it is compatible with your shell!");
115
+ console.error("\nExiting to system with code 1...");
116
+ if (debug) {
117
+ throw error;
118
+ }
119
+ process.exit(1);
120
+ }
121
+ }
122
+ /**
123
+ * Sets the ChRIS context based on a context string (e.g., user@url?folder=...).
124
+ * @param context - The context string.
125
+ * @returns A Promise resolving to true on success, false otherwise.
126
+ */
127
+ async context_set(context) {
128
+ context = contextString_check(context);
129
+ const parsedContext = await (0, chrisContext_js_1.chrisContextURL_parse)(context);
130
+ if (errorStack_js_1.errorStack.messagesOfType_has('error')) {
131
+ const error = errorStack_js_1.errorStack.stack_pop();
132
+ console.error(chalk_1.default.red('Context error:', error?.message));
133
+ // Clear any remaining errors to prevent them from affecting subsequent operations
134
+ errorStack_js_1.errorStack.type_clear('error');
135
+ return false;
136
+ }
137
+ let status = true;
138
+ let needsRefresh = false;
139
+ if (parsedContext.user) {
140
+ status =
141
+ status &&
142
+ (await chrisContext_js_1.chrisContext.current_set(chrisContext_js_1.Context.ChRISuser, parsedContext.user)); // Await this call
143
+ this.user = parsedContext.user;
144
+ needsRefresh = true;
145
+ await this._config.context_set(parsedContext.user, parsedContext.URL || '');
146
+ }
147
+ if (parsedContext.URL) {
148
+ status =
149
+ status && (await chrisContext_js_1.chrisContext.current_set(chrisContext_js_1.Context.ChRISURL, parsedContext.URL)); // Await this call
150
+ this.chrisURL = parsedContext.URL;
151
+ needsRefresh = true;
152
+ await this._config.context_set(this.user || "", parsedContext.URL);
153
+ }
154
+ if (parsedContext.folder) {
155
+ status =
156
+ status &&
157
+ (await chrisContext_js_1.chrisContext.current_set(chrisContext_js_1.Context.ChRISfolder, parsedContext.folder)); // Await this call
158
+ }
159
+ if (parsedContext.feed) {
160
+ status =
161
+ status &&
162
+ (await chrisContext_js_1.chrisContext.current_set(chrisContext_js_1.Context.ChRISfeed, parsedContext.feed)); // Await this call
163
+ }
164
+ if (parsedContext.plugin) {
165
+ status =
166
+ status &&
167
+ (await chrisContext_js_1.chrisContext.current_set(chrisContext_js_1.Context.ChRISplugin, parsedContext.plugin)); // Await this call
168
+ }
169
+ // Refresh the client with the new context
170
+ if (needsRefresh) {
171
+ await this.client_refresh();
172
+ }
173
+ return status;
174
+ }
175
+ /**
176
+ * Retrieves the authentication token.
177
+ * @param forceLoad - If true, forces loading the token from storage.
178
+ * @returns A Promise resolving to the authentication token or null.
179
+ */
180
+ async authToken_get(forceLoad) {
181
+ if (!this.authToken || forceLoad) {
182
+ await this.token_load();
183
+ }
184
+ return this.authToken;
185
+ }
186
+ /**
187
+ * Retrieves the current authenticated user's username.
188
+ * @returns A Promise resolving to the username string or null if not authenticated.
189
+ */
190
+ async user_get() {
191
+ // Ensure token is loaded if not already present, as user is set during connection.
192
+ if (!this.user && this.authToken) {
193
+ // Re-load config if necessary, or simply return stored user.
194
+ // For now, assume this.user is reliably set during connection_connect
195
+ // or if auth token is loaded from storage (which would imply context reload).
196
+ // A more robust implementation might re-derive user from token or context.
197
+ }
198
+ return this.user;
199
+ }
200
+ /**
201
+ * Retrieves the ChRIS CUBE URL.
202
+ * @returns A Promise resolving to the ChRIS URL or null.
203
+ */
204
+ async chrisURL_get() {
205
+ if (!this.chrisURL) {
206
+ if (!this._config) {
207
+ return null; // config not initialized
208
+ }
209
+ this.chrisURL = await this._config.chrisURL_load();
210
+ }
211
+ return this.chrisURL;
212
+ }
213
+ /**
214
+ * Refreshes the ChRIS API client with current token and URL.
215
+ * @returns A Promise resolving to the refreshed Client instance or null.
216
+ */
217
+ async client_refresh() {
218
+ this.tokenFile = this._config.tokenFilepath;
219
+ this.chrisURL = await this.chrisURL_get();
220
+ this.authToken = await this.authToken_get(true); // Pass true directly
221
+ if (this.chrisURL && this.authToken) {
222
+ this.client = new chrisapi_1.default(this.chrisURL, { token: this.authToken });
223
+ }
224
+ return this.client;
225
+ }
226
+ /**
227
+ * Retrieves the ChRIS API client instance.
228
+ * @returns A Promise resolving to the Client instance or null.
229
+ */
230
+ async client_get() {
231
+ if ((await this.authToken_get()) &&
232
+ (await this.chrisURL_get()) &&
233
+ this.chrisURL &&
234
+ this.authToken) {
235
+ if (!this.client) {
236
+ this.client = new chrisapi_1.default(this.chrisURL, { token: this.authToken });
237
+ }
238
+ }
239
+ return this.client;
240
+ }
241
+ /**
242
+ * Checks if the client is currently connected.
243
+ * @returns True if connected, false otherwise.
244
+ */
245
+ connection_isConnected() {
246
+ return this.authToken !== null;
247
+ }
248
+ /**
249
+ * Logs out the user by clearing the authentication token from storage.
250
+ */
251
+ async connection_logout() {
252
+ this.authToken = null;
253
+ try {
254
+ await this.storageProvider.remove(this.tokenFile);
255
+ console.log("Logged out successfully");
256
+ }
257
+ catch (error) {
258
+ console.error("Error during logout:", error);
259
+ }
260
+ }
261
+ /**
262
+ * Saves data to a specified file using the storage provider.
263
+ * @param file - The path to the file.
264
+ * @param info - The string data to save.
265
+ */
266
+ async token_saveToFile(file, info) {
267
+ try {
268
+ await this.storageProvider.write(file, info || "");
269
+ }
270
+ catch (error) {
271
+ console.error("For info: ", info);
272
+ console.error("Error saving to file ", file, ": ", error);
273
+ }
274
+ }
275
+ /**
276
+ * Loads the authentication token from storage.
277
+ * @returns A Promise that resolves when the token is loaded.
278
+ */
279
+ async token_load() {
280
+ try {
281
+ this.authToken = await this.storageProvider.read(this.tokenFile);
282
+ }
283
+ catch (error) {
284
+ this.authToken = null;
285
+ }
286
+ }
287
+ }
288
+ exports.ChRISConnection = ChRISConnection;
289
+ /**
290
+ * Global instance of ChRISConnection, initialized as a constant singleton.
291
+ */
292
+ exports.chrisConnection = new ChRISConnection();
293
+ /**
294
+ * Initializes the global ChRISConnection instance.
295
+ * @param storageProvider - The storage provider to use for the connection.
296
+ */
297
+ async function chrisConnection_init(storageProvider) {
298
+ await (0, config_js_1.config_init)(storageProvider); // This sets the global connectionConfig
299
+ exports.chrisConnection = new ChRISConnection(config_js_1.connectionConfig, storageProvider);
300
+ chrisIO_js_1.chrisIO.storageProvider_set(storageProvider);
301
+ return exports.chrisConnection;
302
+ }
303
+ //# sourceMappingURL=chrisConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chrisConnection.js","sourceRoot":"","sources":["../../src/connect/chrisConnection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAoVH,oDAKC;AAvVD,gEAAsC;AAgB7B,iBAhBF,kBAAM,CAgBE;AAff,mDAAsF;AACtF,gEAKoC;AAEpC,iDAA2C;AAC3C,0DAAoD;AACpD,kDAA0B;AAiB1B;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,OAAe;IAC1C,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,GAAG,OAAO,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAa,eAAe;IAS1B;;;;OAIG;IACH,YAAY,MAAyB,EAAE,eAAkC;QAbjE,cAAS,GAAkB,IAAI,CAAC;QAEhC,SAAI,GAAkB,IAAI,CAAC;QAC3B,aAAQ,GAAkB,IAAI,CAAC;QAC/B,WAAM,GAAkB,IAAI,CAAC;QAUnC,IAAI,MAAM,IAAI,eAAe,EAAE,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACrC,CAAC;QACD,mFAAmF;QACnF,mGAAmG;QACnG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,MAAwB,EAAE,eAAiC;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,eAAe,GAAG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AgB,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,UAAU;QACtB,IAAI,CAAC;YACH,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,eAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpE,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAzRD,0CAyRC;AAED;;GAEG;AACQ,QAAA,eAAe,GAAoB,IAAI,eAAe,EAAE,CAAC;AAEpE;;;GAGG;AACI,KAAK,UAAU,oBAAoB,CAAC,eAAiC;IAC1E,MAAM,IAAA,uBAAW,EAAC,eAAe,CAAC,CAAC,CAAC,wCAAwC;IAC5E,uBAAe,GAAG,IAAI,eAAe,CAAC,4BAAgB,EAAE,eAAe,CAAC,CAAC;IACzE,oBAAO,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;IAC7C,OAAO,uBAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @file ChRIS Context Management
3
+ *
4
+ * This module manages the context of the ChRIS session, including the current user,
5
+ * URL, feed, folder, and plugin. It interacts with the session configuration to
6
+ * persist and retrieve context information.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Enum defining the types of context available in ChRIS.
12
+ */
13
+ export declare enum Context {
14
+ ChRISURL = "URL",
15
+ ChRISuser = "user",
16
+ ChRISfolder = "folder",
17
+ ChRISfeed = "feed",
18
+ ChRISplugin = "plugin",
19
+ PACSserver = "pacsserver"
20
+ }
21
+ /**
22
+ * Interface representing the context associated with a specific URL.
23
+ */
24
+ export interface URLContext {
25
+ folder: string | null;
26
+ feed: string | null;
27
+ plugin: string | null;
28
+ pacsserver: string | null;
29
+ token: string | null;
30
+ }
31
+ /**
32
+ * Interface representing a single context, extending URLContext with URL and user.
33
+ */
34
+ export interface SingleContext extends URLContext {
35
+ URL: string | null;
36
+ user: string | null;
37
+ }
38
+ /**
39
+ * Interface representing the context for a user, including multiple URLs.
40
+ */
41
+ export interface UserContext {
42
+ urls: {
43
+ [url: string]: URLContext;
44
+ };
45
+ currentURL: string | null;
46
+ }
47
+ /**
48
+ * Interface representing the full context of the application, including multiple users.
49
+ */
50
+ export interface FullContext {
51
+ users: {
52
+ [user: string]: UserContext;
53
+ };
54
+ currentUser: string | null;
55
+ currentURL: string | null;
56
+ }
57
+ /**
58
+ * Parses a ChRIS context URL string into a SingleContext object.
59
+ *
60
+ * @param url - The context URL string to parse.
61
+ * @returns A Promise resolving to a SingleContext object.
62
+ */
63
+ export declare function chrisContextURL_parse(url: string): Promise<SingleContext>;
64
+ /**
65
+ * Manages the ChRIS session context.
66
+ */
67
+ export declare class ChrisContext {
68
+ private fullContext;
69
+ private _singleContext;
70
+ get singleContext(): SingleContext;
71
+ constructor();
72
+ /**
73
+ * Initializes the context by loading data from the configuration directory.
74
+ */
75
+ init(): Promise<void>;
76
+ /**
77
+ * Get the full context object.
78
+ * @returns The full context.
79
+ */
80
+ fullContext_get(): FullContext;
81
+ ChRISURL_get(): Promise<string | null>;
82
+ ChRISuser_get(): Promise<string | null>;
83
+ ChRISfolder_get(): Promise<string | null>;
84
+ ChRISfeed_get(): Promise<string | null>;
85
+ ChRISfolder_set(path: string): Promise<boolean>;
86
+ ChRISfeed_set(feedID: string): Promise<boolean>;
87
+ ChRISplugin_set(pluginID: string): Promise<boolean>;
88
+ ChRISplugin_get(): Promise<string | null>;
89
+ PACSserver_set(server: string): Promise<boolean>;
90
+ PACSserver_get(): Promise<string | null>;
91
+ folderpath_get(): Promise<string | null>;
92
+ currentContext_update(): Promise<SingleContext>;
93
+ /**
94
+ * Get the current value for a specific context type.
95
+ * @param context - The context type to retrieve.
96
+ * @returns The current context value or null.
97
+ */
98
+ current_get(context: Context): Promise<string | null>;
99
+ /**
100
+ * Set the value for a specific context type.
101
+ * @param context - The context type to set.
102
+ * @param value - The value to set.
103
+ * @returns True on success, false on failure.
104
+ */
105
+ current_set(context: Context, value: string): Promise<boolean>;
106
+ }
107
+ /**
108
+ * Global ChRIS context instance.
109
+ */
110
+ export declare const chrisContext: ChrisContext;