@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,148 @@
1
+ "use strict";
2
+ /**
3
+ * @file ChRIS Embedded Resource Group
4
+ *
5
+ * This module manages groups of ChRIS resources that are embedded within other resources
6
+ * (e.g., files within a folder, parameters of a plugin). It handles context-aware initialization.
7
+ *
8
+ * @module
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ChRISEmbeddedResourceGroup = exports.ChRISContextSpecError = exports.ChRISInitializationError = exports.ChRISConnectionError = void 0;
12
+ exports.context_split = context_split;
13
+ const chrisResourceGroup_js_1 = require("../resources/chrisResourceGroup.js");
14
+ const chrisConnection_js_1 = require("../connect/chrisConnection.js");
15
+ const errorStack_js_1 = require("../error/errorStack.js");
16
+ /**
17
+ * Error thrown when the ChRIS client is not connected.
18
+ */
19
+ class ChRISConnectionError extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "ChRISConnectionError";
23
+ }
24
+ }
25
+ exports.ChRISConnectionError = ChRISConnectionError;
26
+ /**
27
+ * Error thrown when ChRIS initialization fails.
28
+ */
29
+ class ChRISInitializationError extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = "ChRISInitializationError";
33
+ }
34
+ }
35
+ exports.ChRISInitializationError = ChRISInitializationError;
36
+ /**
37
+ * Error thrown when a context specification is invalid.
38
+ */
39
+ class ChRISContextSpecError extends Error {
40
+ constructor(message) {
41
+ super(message);
42
+ this.name = "ChRISContextSpecError";
43
+ }
44
+ }
45
+ exports.ChRISContextSpecError = ChRISContextSpecError;
46
+ /**
47
+ * Splits a context string into its type and value components on the first occurrence of a delimiter.
48
+ *
49
+ * This function parses strings like "folder:/path/to/folder" or "plugin:123" into an object
50
+ * containing the type (the prefix before the first delimiter) and the value (the rest of the string).
51
+ * If the path contains extra delimiters (e.g. "/pacs/queries/2601_AccessionNumber:22548684"), this
52
+ * function correctly preserves those extra delimiters in the value component.
53
+ *
54
+ * @param context - The context string to be split. Must be a string.
55
+ * @param delimiter - The delimiter character to split on. Defaults to ":".
56
+ * @returns An object conforming to ContextSpec with the split components.
57
+ * @throws ChRISContextSpecError If the input is not a string or the delimiter is not found.
58
+ */
59
+ function context_split(context, delimiter = ":") {
60
+ if (typeof context !== "string") {
61
+ throw new ChRISContextSpecError(`Invalid input: Expected a string, but received ${typeof context}`);
62
+ }
63
+ const delimiterIndex = context.indexOf(delimiter);
64
+ if (delimiterIndex === -1) {
65
+ throw new ChRISContextSpecError(`Invalid input string format: Expected a ${delimiter}-separated string, but got: ${context}`);
66
+ }
67
+ const type = context.slice(0, delimiterIndex);
68
+ const value = context.slice(delimiterIndex + delimiter.length);
69
+ return { type, value };
70
+ }
71
+ /**
72
+ * Group of ChRIS resources embedded within a specific context.
73
+ */
74
+ class ChRISEmbeddedResourceGroup extends chrisResourceGroup_js_1.ChRISResourceGroup {
75
+ constructor(params) {
76
+ super(params.resourceName, params.getMethod, params.chrisContext);
77
+ this.context = params.context;
78
+ this.chrisContextObj = params.chrisContext;
79
+ }
80
+ static async create(resourceName, getMethod, context) {
81
+ let params;
82
+ try {
83
+ const chrisContextObj = await this.context_init(context);
84
+ if (!chrisContextObj) {
85
+ errorStack_js_1.errorStack.stack_push("warning", `could not initialize context ${context} for ${resourceName}`);
86
+ return null;
87
+ }
88
+ const params = {
89
+ resourceName,
90
+ getMethod,
91
+ chrisContext: chrisContextObj,
92
+ context,
93
+ };
94
+ return new ChRISEmbeddedResourceGroup(params);
95
+ }
96
+ catch (error) {
97
+ const errorMessage = error instanceof Error ? error.message : String(error);
98
+ //console.error(`DEBUG: create failed for ${resourceName}:`, errorMessage); // Added
99
+ errorStack_js_1.errorStack.stack_push("error", `Error: ${context} seems invalid for resource ${resourceName}.`);
100
+ return null;
101
+ }
102
+ }
103
+ static async context_init(context) {
104
+ const client = await chrisConnection_js_1.chrisConnection.client_get();
105
+ if (!client) {
106
+ throw new ChRISConnectionError("ChRIS client is not initialized");
107
+ }
108
+ let contextSpec;
109
+ try {
110
+ contextSpec = context_split(context);
111
+ }
112
+ catch (error) {
113
+ if (error instanceof ChRISContextSpecError) {
114
+ console.error(error.message);
115
+ }
116
+ throw error;
117
+ }
118
+ let chrisContextObj = null;
119
+ try {
120
+ switch (contextSpec.type) {
121
+ case "folder":
122
+ chrisContextObj = (await client.getFileBrowserFolderByPath(contextSpec.value));
123
+ break;
124
+ case "plugin":
125
+ chrisContextObj = (await client.getPlugin(Number(contextSpec.value)));
126
+ break;
127
+ case "feed":
128
+ chrisContextObj = (await client.getFeed(Number(contextSpec.value)));
129
+ break;
130
+ default:
131
+ throw new ChRISInitializationError(`Unknown context type: ${contextSpec.type}`);
132
+ }
133
+ }
134
+ catch (error) {
135
+ const errorMessage = error instanceof Error ? error.message : String(error);
136
+ // console.error("DEBUG: initializeContext failed:", errorMessage); // Added for debugging
137
+ errorStack_js_1.errorStack.stack_push("error", `Failed to get contextObject of type ${contextSpec.type} for value ${contextSpec.value}: ${errorMessage}`);
138
+ return null;
139
+ }
140
+ if (!chrisContextObj) {
141
+ errorStack_js_1.errorStack.stack_push("warning", `could not initialize contextObject of type ${contextSpec.type} for value ${contextSpec.value}`);
142
+ return null;
143
+ }
144
+ return chrisContextObj;
145
+ }
146
+ }
147
+ exports.ChRISEmbeddedResourceGroup = ChRISEmbeddedResourceGroup;
148
+ //# sourceMappingURL=chrisEmbeddedResourceGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chrisEmbeddedResourceGroup.js","sourceRoot":"","sources":["../../src/resources/chrisEmbeddedResourceGroup.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAgEH,sCAkBC;AAhFD,8EA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CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,0BAAU,CAAC,UAAU,CACnB,SAAS,EACT,8CAA8C,WAAW,CAAC,IAAI,cAAc,WAAW,CAAC,KAAK,EAAE,CAChG,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AAzGD,gEAyGC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file Factory for creating context-bound ChRIS embedded resource groups.
3
+ *
4
+ * @module
5
+ */
6
+ import { ChRISEmbeddedResourceGroup } from "./chrisEmbeddedResourceGroup.js";
7
+ type ChRISResourceType = unknown;
8
+ /**
9
+ * Create a ChRIS Embedded Resource Group for a given context.
10
+ *
11
+ * @param type - The type of context object to create (e.g., "ComputesOfPlugin").
12
+ * @param context - The context string (e.g., "plugin:123").
13
+ * @returns A promise resolving to the created resource group, or null on failure.
14
+ */
15
+ export declare function objContext_create(type: string, context: string): Promise<ChRISEmbeddedResourceGroup<ChRISResourceType> | null>;
16
+ export {};
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /**
3
+ * @file Factory for creating context-bound ChRIS embedded resource groups.
4
+ *
5
+ * @module
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.objContext_create = objContext_create;
9
+ const chrisEmbeddedResourceGroup_js_1 = require("./chrisEmbeddedResourceGroup.js");
10
+ const errorStack_js_1 = require("../error/errorStack.js");
11
+ class ObjContextCreationError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = "ObjContextCreationError";
15
+ }
16
+ }
17
+ class ChRISObjContextFactory {
18
+ constructor(config) {
19
+ this.cache = new Map();
20
+ this.config = config;
21
+ }
22
+ async create(context) {
23
+ const cacheKey = `${this.config.name}:${context}`;
24
+ if (this.cache.has(cacheKey)) {
25
+ return this.cache.get(cacheKey);
26
+ }
27
+ try {
28
+ const objContext = await chrisEmbeddedResourceGroup_js_1.ChRISEmbeddedResourceGroup.create(this.config.name, this.config.getMethod, context);
29
+ if (!objContext) {
30
+ return null;
31
+ }
32
+ this.cache.set(cacheKey, objContext);
33
+ return objContext;
34
+ }
35
+ catch (error) {
36
+ const errorMessage = error instanceof Error ? error.message : String(error);
37
+ errorStack_js_1.errorStack.stack_push("error", `Failed to create ${this.config.name}: ${errorMessage}`);
38
+ console.log(`name = ${this.config.name} context = ${context}`);
39
+ throw new ObjContextCreationError(`Failed to create ${this.config.name}: ${errorMessage}`);
40
+ return null;
41
+ }
42
+ }
43
+ }
44
+ const ObjContexts = {
45
+ ComputesOfPlugin: {
46
+ name: "ComputesOfPlugin",
47
+ getMethod: "getPluginComputeResources",
48
+ contextType: "plugin",
49
+ },
50
+ InstancesOfPlugin: {
51
+ name: "InstancesOfPlugin",
52
+ getMethod: "getPluginInstances",
53
+ contextType: "plugin",
54
+ },
55
+ ParametersOfPlugin: {
56
+ name: "ParametersOfPlugin",
57
+ getMethod: "getPluginParameters",
58
+ contextType: "plugin",
59
+ },
60
+ ChRISFilesContext: {
61
+ name: "Files",
62
+ getMethod: "getFiles",
63
+ contextType: "folder",
64
+ },
65
+ ChRISLinksContext: {
66
+ name: "Links",
67
+ getMethod: "getLinkFiles",
68
+ contextType: "folder",
69
+ },
70
+ ChRISDirsContext: {
71
+ name: "Directories",
72
+ getMethod: "getChildren",
73
+ contextType: "folder",
74
+ },
75
+ ChRISFeedGroup: {
76
+ name: "Feed",
77
+ getMethod: "getFeeds",
78
+ contextType: "feed",
79
+ },
80
+ };
81
+ const objContextFactories = {};
82
+ for (const [key, config] of Object.entries(ObjContexts)) {
83
+ objContextFactories[key] = new ChRISObjContextFactory(config);
84
+ }
85
+ /**
86
+ * Create a ChRIS Embedded Resource Group for a given context.
87
+ *
88
+ * @param type - The type of context object to create (e.g., "ComputesOfPlugin").
89
+ * @param context - The context string (e.g., "plugin:123").
90
+ * @returns A promise resolving to the created resource group, or null on failure.
91
+ */
92
+ async function objContext_create(type, context) {
93
+ const factory = objContextFactories[type];
94
+ if (!factory) {
95
+ console.error(`Unknown object context type: ${type}`);
96
+ throw new ObjContextCreationError(`Unknown object context type: ${type}`);
97
+ }
98
+ try {
99
+ return factory.create(context);
100
+ }
101
+ catch (error) {
102
+ throw error;
103
+ return null;
104
+ }
105
+ }
106
+ // Usage examples:
107
+ // const pluginComputeResources: ChRISEmbeddedResourceGroup<Plugin> = await objContext_create('PluginComputeResources', 'plugin:123') as ChRISEmbeddedResourceGroup<Plugin>;
108
+ // const filesContext: ChRISEmbeddedResourceGroup<FileBrowserFolder> = await objContext_create('ChRISFilesContext', 'folder:/path/to/folder') as ChRISEmbeddedResourceGroup<FileBrowserFolder>;
109
+ //# sourceMappingURL=chrisObjContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chrisObjContext.js","sourceRoot":"","sources":["../../src/resources/chrisObjContext.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAqHH,8CAeC;AAlID,mFAA6E;AAC7E,0DAAoD;AAUpD,MAAM,uBAAwB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,sBAAsB;IAK1B,YAAY,MAAwB;QAH5B,UAAK,GACX,IAAI,GAAG,EAAE,CAAC;QAGV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,MAAM,CACV,OAAe;QAEf,MAAM,QAAQ,GAAW,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;QAE1D,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;QACnC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,UAAU,GACd,MAAM,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,QAAQ;KACtB;IACD,iBAAiB,EAAE;QACjB,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,cAAc;QACzB,WAAW,EAAE,QAAQ;KACtB;IACD,gBAAgB,EAAE;QAChB,IAAI,EAAE,aAAa;QACnB,SAAS,EAAE,aAAa;QACxB,WAAW,EAAE,QAAQ;KACtB;IACD,cAAc,EAAE;QACd,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,MAAM;KACpB;CACF,CAAC;AAEF,MAAM,mBAAmB,GAA8C,EAAE,CAAC;AAE1E,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;IACxD,mBAAmB,CAAC,GAAG,CAAC,GAAG,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,OAAe;IAEf,MAAM,OAAO,GAAuC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC9E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,IAAI,uBAAuB,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,KAAK,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,kBAAkB;AAClB,4KAA4K;AAC5K,+LAA+L"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @file ChRIS Resource Group
3
+ *
4
+ * This module defines the base class for grouping ChRIS resources.
5
+ * It handles the initialization and binding of resource fetching methods,
6
+ * supporting both immediate and lazy binding strategies.
7
+ *
8
+ * @module
9
+ */
10
+ import Client from "@fnndsc/chrisapi";
11
+ import { ChRISResource } from "../resources/chrisResources.js";
12
+ /**
13
+ * Abstract base class for a group of ChRIS resources.
14
+ */
15
+ export declare abstract class ChRISResourceGroup {
16
+ protected _asset: ChRISResource;
17
+ /**
18
+ * Constructor for ChRISResourceGroup.
19
+ * @param resourceName - The name of the resource.
20
+ * @param getMethod - The method name on the client/object to fetch resources.
21
+ * @param chrisObj - Optional object to bind the method to. If not provided, uses the global ChRIS client lazily.
22
+ */
23
+ constructor(resourceName: string, getMethod: string, chrisObj?: unknown);
24
+ /**
25
+ * Retrieves the ChRIS client instance asynchronously.
26
+ * @returns A Promise resolving to the Client instance or null.
27
+ */
28
+ client_get(): Promise<Client | null>;
29
+ get asset(): ChRISResource;
30
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * @file ChRIS Resource Group
4
+ *
5
+ * This module defines the base class for grouping ChRIS resources.
6
+ * It handles the initialization and binding of resource fetching methods,
7
+ * supporting both immediate and lazy binding strategies.
8
+ *
9
+ * @module
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ChRISResourceGroup = void 0;
13
+ const chrisConnection_js_1 = require("../connect/chrisConnection.js");
14
+ const chrisResources_js_1 = require("../resources/chrisResources.js");
15
+ /**
16
+ * Abstract base class for a group of ChRIS resources.
17
+ */
18
+ class ChRISResourceGroup {
19
+ /**
20
+ * Constructor for ChRISResourceGroup.
21
+ * @param resourceName - The name of the resource.
22
+ * @param getMethod - The method name on the client/object to fetch resources.
23
+ * @param chrisObj - Optional object to bind the method to. If not provided, uses the global ChRIS client lazily.
24
+ */
25
+ constructor(resourceName, getMethod, chrisObj) {
26
+ this._asset = new chrisResources_js_1.ChRISResource();
27
+ this._asset.resourceName = resourceName;
28
+ if (chrisObj) {
29
+ this._asset.binding_applyGet(chrisObj, chrisObj[getMethod]);
30
+ }
31
+ else {
32
+ this._asset.binding_applyLazy(() => chrisConnection_js_1.chrisConnection.client_get(), getMethod);
33
+ }
34
+ }
35
+ /**
36
+ * Retrieves the ChRIS client instance asynchronously.
37
+ * @returns A Promise resolving to the Client instance or null.
38
+ */
39
+ async client_get() {
40
+ return chrisConnection_js_1.chrisConnection.client_get();
41
+ }
42
+ get asset() {
43
+ return this._asset;
44
+ }
45
+ }
46
+ exports.ChRISResourceGroup = ChRISResourceGroup;
47
+ //# sourceMappingURL=chrisResourceGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chrisResourceGroup.js","sourceRoot":"","sources":["../../src/resources/chrisResourceGroup.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAGH,sEAAgE;AAChE,sEAA4E;AAE5E;;GAEG;AACH,MAAsB,kBAAkB;IAGtC;;;;;OAKG;IACH,YAAY,YAAoB,EAAE,SAAiB,EAAE,QAAkB;QACrE,IAAI,CAAC,MAAM,GAAG,IAAI,iCAAa,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QAExC,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAC1B,QAAQ,EACP,QAAsF,CAAC,SAAS,CAAC,CACnG,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAC3B,GAAG,EAAE,CAAC,oCAAe,CAAC,UAAU,EAAE,EAClC,SAAS,CACV,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,oCAAe,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AArCD,gDAqCC"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @file ChRIS Resource Management
3
+ *
4
+ * This module defines the base class and interfaces for managing ChRIS resources.
5
+ * It provides functionality for listing, filtering, and manipulating resource items.
6
+ *
7
+ * @module
8
+ */
9
+ import Client from "@fnndsc/chrisapi";
10
+ import { ListResource, Resource, ItemResource } from "@fnndsc/chrisapi";
11
+ /**
12
+ * A simple record with string keys and unknown values.
13
+ */
14
+ export interface SimpleRecord {
15
+ [key: string]: unknown;
16
+ }
17
+ /**
18
+ * Options for listing resources, including pagination.
19
+ */
20
+ export interface ListOptions extends SimpleRecord {
21
+ limit?: number;
22
+ offset?: number;
23
+ }
24
+ /**
25
+ * Represents an item in a resource collection.
26
+ */
27
+ export interface Item {
28
+ data: Array<{
29
+ name: string;
30
+ value: unknown;
31
+ }>;
32
+ href: string;
33
+ links: Array<unknown>;
34
+ }
35
+ interface ResourcesFromOptions {
36
+ resources: ListResource | Resource | null;
37
+ options?: ListOptions | null;
38
+ }
39
+ /**
40
+ * Contains items and the fields available for them.
41
+ */
42
+ export interface ResourceFieldsPerItem {
43
+ items: Item[];
44
+ fields: string[];
45
+ }
46
+ /**
47
+ * Contains resources, items, options, and selected fields.
48
+ */
49
+ export interface ResourcesByFields extends ResourcesFromOptions {
50
+ items: Item[] | null;
51
+ fields: string[];
52
+ }
53
+ /**
54
+ * Contains data filtered for table display and selected fields.
55
+ */
56
+ export interface FilteredResourceData {
57
+ tableData: Record<string, unknown>[];
58
+ selectedFields: string[];
59
+ /** Total count of items in the full collection (may exceed tableData.length when paginated). */
60
+ totalCount?: number;
61
+ }
62
+ /**
63
+ * A dictionary with string keys and primitive values.
64
+ */
65
+ export interface Dictionary {
66
+ [key: string]: string | number | boolean;
67
+ }
68
+ /**
69
+ * Base class for managing ChRIS resources.
70
+ */
71
+ export declare class ChRISResource {
72
+ private _client;
73
+ private _resourceName;
74
+ private _resourceCollection;
75
+ private _resourceArrayItems;
76
+ private _resourceArray;
77
+ private _resourceItem;
78
+ private resourceMethod;
79
+ private _lazyMethodName;
80
+ private _lazyObjProvider;
81
+ constructor();
82
+ /**
83
+ * Retrieves the ChRIS client instance asynchronously.
84
+ * @returns A Promise resolving to the Client instance or null.
85
+ */
86
+ client_get(): Promise<Client | null>;
87
+ get resourceName(): string;
88
+ set resourceName(name: string);
89
+ set resourceCollection(collection: ListResource | Resource);
90
+ /**
91
+ * Converts a resource item to a dictionary.
92
+ * @param item - The item to convert.
93
+ * @returns A dictionary representation of the item.
94
+ */
95
+ resourceItem_toDict(item: Item): Dictionary;
96
+ /**
97
+ * Converts a list of resource items to dictionaries.
98
+ * @param items - The list of items to convert.
99
+ * @returns An array of dictionaries.
100
+ */
101
+ resourceItems_toDicts(items: Item[]): Dictionary[];
102
+ /**
103
+ * Deletes a resource item by its ID.
104
+ * @param id - The ID of the item to delete.
105
+ * @returns A Promise resolving to true on success, false otherwise.
106
+ */
107
+ resourceItem_delete(id: number): Promise<boolean>;
108
+ /**
109
+ * Builds a list of items from a resource collection.
110
+ * @param resources - The resource collection.
111
+ * @returns An array of Items or null.
112
+ */
113
+ resourceItems_buildFromCollection(resources: ListResource | Resource | null): Item[] | null;
114
+ /**
115
+ * Binds a resource fetching method to an object.
116
+ * @param obj - The object context.
117
+ * @param resourceMethod - The method to bind.
118
+ * @param resourceName - Optional name for the resource.
119
+ */
120
+ binding_applyGet(obj: unknown, resourceMethod: (params: ListOptions) => Promise<ListResource | Resource>, resourceName?: string): void;
121
+ /**
122
+ * Binds a resource fetching method lazily.
123
+ * @param objProvider - A function returning a Promise to the object context.
124
+ * @param methodName - The name of the method to bind.
125
+ * @param resourceName - Optional name for the resource.
126
+ */
127
+ binding_applyLazy(objProvider: () => Promise<unknown>, methodName: string, resourceName?: string): void;
128
+ private lazyBinding_resolve;
129
+ get hasNextPage(): boolean;
130
+ /**
131
+ * Lists *all* resources by automatically handling pagination.
132
+ * @param options - Filtering options. Limit and offset will be managed internally.
133
+ * @returns A Promise resolving to FilteredResourceData containing all matching resources, or null.
134
+ */
135
+ resources_getAll(options?: Partial<ListOptions>): Promise<FilteredResourceData | null>;
136
+ /**
137
+ * Lists and filters resources based on options.
138
+ * @param options - Filtering and listing options.
139
+ * @returns A Promise resolving to filtered resource data or null.
140
+ */
141
+ resources_listAndFilterByOptions(options?: Partial<ListOptions>): Promise<FilteredResourceData | null>;
142
+ /**
143
+ * Filters resources by specific fields.
144
+ * @param resourcesByFields - The resources and fields to filter.
145
+ * @returns Filtered data suitable for table display.
146
+ */
147
+ resources_filterByFields(resourcesByFields: ResourcesByFields | null): FilteredResourceData | null;
148
+ resourcesByFields_enumerate(items: Item[] | null): ResourceFieldsPerItem | null;
149
+ fieldSpec_resolve(fieldFilter?: string, options?: ListOptions | null): string[];
150
+ resourceFields_get(options?: ListOptions | null, fields?: string): Promise<ResourcesByFields | null>;
151
+ resources_getItems(options?: Partial<ListOptions>): Promise<ItemResource[] | null>;
152
+ options_simplify(options: ListOptions): ListOptions;
153
+ private filtering_applyAdditional;
154
+ resources_getList(options?: Partial<ListOptions>, resourceMethod?: (params: ListOptions) => Promise<ListResource | Resource>): Promise<ListOptions | null>;
155
+ }
156
+ /**
157
+ * Helper to get resource fields from a resource object.
158
+ * @param obj - The resource object.
159
+ * @param fields - The fields to extract.
160
+ * @returns A SimpleRecord of fields or null.
161
+ */
162
+ export declare function resourceFields_get(obj: Resource | ListResource, fields: string[]): SimpleRecord | null;
163
+ export {};