@js4cytoscape/ndex-client 0.5.0-alpha.9 → 0.6.0-alpha.2
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.
- package/README.md +339 -13
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.mts +1906 -0
- package/dist/index.d.ts +1906 -0
- package/dist/index.global.js +9 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +80 -21
- package/src/CyNDEx.js.bak +178 -0
- package/src/NDEx.js +66 -13
- package/src/NDEx.js.bak +1107 -0
- package/src/index.ts +230 -0
- package/src/models/CX2Network.ts +423 -0
- package/src/services/AdminService.ts +10 -0
- package/src/services/CyNDExService.ts +338 -0
- package/src/services/FilesService.ts +234 -0
- package/src/services/HTTPService.ts +442 -0
- package/src/services/NetworkServiceV2.ts +427 -0
- package/src/services/NetworkServiceV3.ts +288 -0
- package/src/services/UnifiedNetworkService.ts +641 -0
- package/src/services/UserService.ts +233 -0
- package/src/services/WorkspaceService.ts +159 -0
- package/src/types/cytoscape.ts +81 -0
- package/src/types/index.ts +524 -0
- package/dist/ndexClient.common.js +0 -1057
- package/dist/ndexClient.js +0 -538
- package/src/index.js +0 -2
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import { HTTPService } from './HTTPService';
|
|
2
|
+
import { NetworkServiceV2 } from './NetworkServiceV2';
|
|
3
|
+
import { NetworkServiceV3 } from './NetworkServiceV3';
|
|
4
|
+
import {
|
|
5
|
+
NetworkSummaryV3,
|
|
6
|
+
PaginationParams,
|
|
7
|
+
AccessParams,
|
|
8
|
+
CX2Network as CX2NetworkType,
|
|
9
|
+
CX2Edge,
|
|
10
|
+
CX1Edge,
|
|
11
|
+
CX2MetaData,
|
|
12
|
+
NetworkPermission,
|
|
13
|
+
NDExObjectUpdateStatus
|
|
14
|
+
} from '../types';
|
|
15
|
+
import { CX2Network } from '../models/CX2Network';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* UnifiedNetworkService - Provides access to both V2/V3 network services
|
|
19
|
+
* Allows individual function calls to choose between v2 and v3 APIs
|
|
20
|
+
*/
|
|
21
|
+
export class UnifiedNetworkService {
|
|
22
|
+
private v2Service: NetworkServiceV2;
|
|
23
|
+
private v3Service: NetworkServiceV3;
|
|
24
|
+
|
|
25
|
+
constructor(private http: HTTPService) {
|
|
26
|
+
this.v2Service = new NetworkServiceV2(http);
|
|
27
|
+
this.v3Service = new NetworkServiceV3(http);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get network summary using specified API version
|
|
32
|
+
*/
|
|
33
|
+
async getNetworkSummary(
|
|
34
|
+
networkUUID: string,
|
|
35
|
+
options: AccessParams = {}
|
|
36
|
+
): Promise<NetworkSummaryV3> {
|
|
37
|
+
return this.v3Service.getNetworkSummary(networkUUID, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Search networks using specified API version
|
|
42
|
+
* NOTE: This method is temporarily commented out as the V2 searchNetworks
|
|
43
|
+
* signature has been migrated from NDEx.js and needs separate integration
|
|
44
|
+
*/
|
|
45
|
+
// async searchNetworks(
|
|
46
|
+
// searchParams: SearchParameters & { useV3?: boolean } = {}
|
|
47
|
+
// ): Promise<SearchResult> {
|
|
48
|
+
// const { useV3, ...params } = searchParams;
|
|
49
|
+
//
|
|
50
|
+
// if (useV3) {
|
|
51
|
+
// return this.v3Service.searchNetworks(params);
|
|
52
|
+
// }
|
|
53
|
+
//
|
|
54
|
+
// return this.v2Service.searchNetworks(params);
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get network in CX1 format (V2 API)
|
|
60
|
+
*/
|
|
61
|
+
async getRawCX1Network(
|
|
62
|
+
networkUUID: string,
|
|
63
|
+
options: AccessParams = {}
|
|
64
|
+
): Promise<any[]> {
|
|
65
|
+
return this.v2Service.getRawCX1Network(networkUUID, options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get network in CX2 format (V3 API)
|
|
70
|
+
*/
|
|
71
|
+
async getRawCX2Network(
|
|
72
|
+
networkUUID: string,
|
|
73
|
+
options: AccessParams = {}
|
|
74
|
+
): Promise<CX2NetworkType> {
|
|
75
|
+
return this.v3Service.getRawCX2Network(networkUUID, options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Delete network
|
|
82
|
+
*/
|
|
83
|
+
async deleteNetwork(networkUUID: string): Promise<void> {
|
|
84
|
+
return this.v2Service.deleteNetwork(networkUUID);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Create network DOI
|
|
90
|
+
*
|
|
91
|
+
* @param networkUUID - The UUID of the network to create a DOI for
|
|
92
|
+
* @param key - DOI creation key
|
|
93
|
+
* @param email - Email address for DOI registration
|
|
94
|
+
* @returns Promise resolving to a confirmation message string from the server
|
|
95
|
+
*/
|
|
96
|
+
async createNetworkDOI(
|
|
97
|
+
networkUUID: string,
|
|
98
|
+
key: string,
|
|
99
|
+
email: string
|
|
100
|
+
): Promise<string> {
|
|
101
|
+
return this.v3Service.createNetworkDOI(networkUUID, key, email);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get attributes of selected nodes
|
|
106
|
+
*
|
|
107
|
+
* Retrieves specific attributes for a set of nodes in a network. The server will return
|
|
108
|
+
* a 404 error if the network has no attributes on nodes.
|
|
109
|
+
*
|
|
110
|
+
* @param networkUUID - The UUID of the network
|
|
111
|
+
* @param nodeSelection - Object containing node IDs and attribute names to retrieve
|
|
112
|
+
* @param nodeSelection.ids - Array of node IDs (long numbers) to get attributes for
|
|
113
|
+
* @param nodeSelection.attributeNames - Array of attribute names to retrieve
|
|
114
|
+
* @param options - Access options including optional access key
|
|
115
|
+
* @returns Promise resolving to a JSON object where keys are stringified node IDs
|
|
116
|
+
* and values are the selected attributes for that node
|
|
117
|
+
* @throws {404} When the network has no attributes on nodes
|
|
118
|
+
*/
|
|
119
|
+
async getAttributesOfSelectedNodes(
|
|
120
|
+
networkUUID: string,
|
|
121
|
+
nodeSelection: { ids: number[]; attributeNames: string[] },
|
|
122
|
+
options: AccessParams = {}
|
|
123
|
+
): Promise<Record<string, any>> {
|
|
124
|
+
return this.v3Service.getAttributesOfSelectedNodes(networkUUID, nodeSelection, options);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Neighborhood query (migrated from original NDEx.js)
|
|
129
|
+
*
|
|
130
|
+
* Performs a neighborhood search within a network, returning nodes and edges
|
|
131
|
+
* within the specified search depth from nodes matching the search terms.
|
|
132
|
+
* Can return either raw CX1 or CX2 format based on outputCX2 parameter.
|
|
133
|
+
*
|
|
134
|
+
* @param networkUUID - The UUID of the network to search
|
|
135
|
+
* @param searchTerms - Search string to find starting nodes
|
|
136
|
+
* @param saveResult - Whether to save the query result as a new network
|
|
137
|
+
* @param parameters - Additional query parameters
|
|
138
|
+
* @param parameters.searchDepth - How many hops to search (default: 1)
|
|
139
|
+
* @param parameters.edgeLimit - Maximum number of edges to return
|
|
140
|
+
* @param parameters.errorWhenLimitIsOver - Throw error if edge limit exceeded
|
|
141
|
+
* @param parameters.directOnly - Only include direct connections
|
|
142
|
+
* @param parameters.nodeIds - Specific node IDs to start search from
|
|
143
|
+
* @param outputCX2 - If true, return CX2 format via V3 API; if false, return CX1 format via V2 API
|
|
144
|
+
* @returns Promise resolving to raw CX1 or CX2 network data
|
|
145
|
+
*/
|
|
146
|
+
async neighborhoodQuery(
|
|
147
|
+
networkUUID: string,
|
|
148
|
+
searchTerms: string,
|
|
149
|
+
saveResult?: boolean,
|
|
150
|
+
parameters?: {
|
|
151
|
+
searchDepth?: number;
|
|
152
|
+
edgeLimit?: number;
|
|
153
|
+
errorWhenLimitIsOver?: boolean;
|
|
154
|
+
directOnly?: boolean;
|
|
155
|
+
nodeIds?: number[];
|
|
156
|
+
},
|
|
157
|
+
outputCX2: boolean = false
|
|
158
|
+
): Promise<any[] | CX2NetworkType> {
|
|
159
|
+
const params: Record<string, string> = {};
|
|
160
|
+
|
|
161
|
+
if (saveResult !== undefined && saveResult === true) {
|
|
162
|
+
params.save = 'true';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const data: Record<string, any> = {
|
|
166
|
+
searchString: searchTerms,
|
|
167
|
+
searchDepth: 1
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (parameters !== undefined) {
|
|
171
|
+
if (parameters.searchDepth !== undefined) {
|
|
172
|
+
data.searchDepth = parameters.searchDepth;
|
|
173
|
+
}
|
|
174
|
+
if (parameters.edgeLimit !== undefined) {
|
|
175
|
+
data.edgeLimit = parameters.edgeLimit;
|
|
176
|
+
}
|
|
177
|
+
if (parameters.errorWhenLimitIsOver !== undefined) {
|
|
178
|
+
data.errorWhenLimitIsOver = parameters.errorWhenLimitIsOver;
|
|
179
|
+
}
|
|
180
|
+
if (parameters.directOnly !== undefined) {
|
|
181
|
+
data.directOnly = parameters.directOnly;
|
|
182
|
+
}
|
|
183
|
+
if (parameters.nodeIds != null) {
|
|
184
|
+
data.nodeIds = parameters.nodeIds;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (outputCX2) {
|
|
189
|
+
const endpoint = `search/network/${networkUUID}/query`;
|
|
190
|
+
return this.http.post<CX2NetworkType>(endpoint, data, {
|
|
191
|
+
version: 'v3',
|
|
192
|
+
params
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const endpoint = `search/network/${networkUUID}/query`;
|
|
197
|
+
return this.http.post<any[]>(endpoint, data, {
|
|
198
|
+
version: 'v2',
|
|
199
|
+
params
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Interconnect query (migrated from original NDEx.js)
|
|
205
|
+
*
|
|
206
|
+
* Finds connections between nodes matching the search terms within a network.
|
|
207
|
+
* Returns the interconnected subnetwork as either raw CX1 or CX2 format.
|
|
208
|
+
* Can return either raw CX1 or CX2 format based on outputCX2 parameter.
|
|
209
|
+
*
|
|
210
|
+
* @param networkUUID - The UUID of the network to search
|
|
211
|
+
* @param searchTerms - Search string to find nodes to interconnect
|
|
212
|
+
* @param saveResult - Whether to save the query result as a new network
|
|
213
|
+
* @param parameters - Additional query parameters
|
|
214
|
+
* @param parameters.edgeLimit - Maximum number of edges to return
|
|
215
|
+
* @param parameters.errorWhenLimitIsOver - Throw error if edge limit exceeded
|
|
216
|
+
* @param parameters.nodeIds - Specific node IDs to find connections between
|
|
217
|
+
* @param outputCX2 - If true, return CX2 format via V3 API; if false, return CX1 format via V2 API
|
|
218
|
+
* @returns Promise resolving to raw CX1 or CX2 network data
|
|
219
|
+
*/
|
|
220
|
+
async interConnectQuery(
|
|
221
|
+
networkUUID: string,
|
|
222
|
+
searchTerms: string,
|
|
223
|
+
saveResult?: boolean,
|
|
224
|
+
parameters?: {
|
|
225
|
+
edgeLimit?: number;
|
|
226
|
+
errorWhenLimitIsOver?: boolean;
|
|
227
|
+
nodeIds?: number[];
|
|
228
|
+
},
|
|
229
|
+
outputCX2: boolean = false
|
|
230
|
+
): Promise<any[] | CX2NetworkType> {
|
|
231
|
+
const params: Record<string, string> = {};
|
|
232
|
+
|
|
233
|
+
if (saveResult !== undefined && saveResult === true) {
|
|
234
|
+
params.save = 'true';
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const data: Record<string, any> = { searchString: searchTerms };
|
|
238
|
+
|
|
239
|
+
if (parameters !== undefined) {
|
|
240
|
+
if (parameters.edgeLimit !== undefined) {
|
|
241
|
+
data.edgeLimit = parameters.edgeLimit;
|
|
242
|
+
}
|
|
243
|
+
if (parameters.errorWhenLimitIsOver !== undefined) {
|
|
244
|
+
data.errorWhenLimitIsOver = parameters.errorWhenLimitIsOver;
|
|
245
|
+
}
|
|
246
|
+
if (parameters.nodeIds != null) {
|
|
247
|
+
data.nodeIds = parameters.nodeIds;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (outputCX2) {
|
|
252
|
+
const endpoint = `search/networks/${networkUUID}/interconnectquery`;
|
|
253
|
+
return this.http.post<CX2NetworkType>(endpoint, data, {
|
|
254
|
+
version: 'v3',
|
|
255
|
+
params
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const endpoint = `search/network/${networkUUID}/interconnectquery`;
|
|
260
|
+
return this.http.post<any[]>(endpoint, data, {
|
|
261
|
+
version: 'v2',
|
|
262
|
+
params
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Get network permissions by UUIDs (migrated from original NDEx.js)
|
|
268
|
+
*
|
|
269
|
+
* Retrieves network permissions for multiple networks in a single batch request.
|
|
270
|
+
* Uses the V2 API batch endpoint to efficiently get permission information.
|
|
271
|
+
*
|
|
272
|
+
* @param uuidList - Array of network UUIDs to retrieve permissions for
|
|
273
|
+
* @returns Promise resolving to permission information for the specified networks
|
|
274
|
+
*/
|
|
275
|
+
async getNetworkPermissionsByUUIDs(uuidList: string[]): Promise<any[]> {
|
|
276
|
+
const endpoint = 'batch/network/permission';
|
|
277
|
+
return this.http.post<any[]>(endpoint, uuidList, { version: 'v2' });
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Export networks (migrated from original NDEx.js)
|
|
282
|
+
*
|
|
283
|
+
* Creates an export job for networks using the V2 batch export endpoint.
|
|
284
|
+
* This allows exporting multiple networks in various formats.
|
|
285
|
+
*
|
|
286
|
+
* @param exportJob - Export job configuration specifying networks and format
|
|
287
|
+
* @returns Promise resolving to export job result
|
|
288
|
+
*/
|
|
289
|
+
async exportNetworks(exportJob: any): Promise<any> {
|
|
290
|
+
const endpoint = 'batch/network/export';
|
|
291
|
+
return this.http.post<any>(endpoint, exportJob, { version: 'v2' });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Move networks to folder (migrated from original NDEx.js)
|
|
296
|
+
*
|
|
297
|
+
* Moves multiple networks to a specified folder using the V3 API.
|
|
298
|
+
* This is a V3-specific feature for organizing networks in folders.
|
|
299
|
+
*
|
|
300
|
+
* @param networkIds - Array of network IDs to move
|
|
301
|
+
* @param folderId - Target folder ID to move networks to
|
|
302
|
+
* @returns Promise resolving when networks are moved
|
|
303
|
+
*/
|
|
304
|
+
async moveNetworks(networkIds: string[], folderId: string): Promise<any> {
|
|
305
|
+
if (!Array.isArray(networkIds)) {
|
|
306
|
+
throw new Error('Invalid networkIds - must be an array');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const endpoint = 'batch/networks/move';
|
|
310
|
+
const data = {
|
|
311
|
+
targetFolder: folderId,
|
|
312
|
+
networks: networkIds
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
return this.http.post<any>(endpoint, data, { version: 'v3' });
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Set networks visibility (migrated from original NDEx.js)
|
|
320
|
+
*
|
|
321
|
+
* Changes visibility settings for multiple networks using the V3 API.
|
|
322
|
+
* Requires proper file validation to ensure data integrity.
|
|
323
|
+
*
|
|
324
|
+
* @param files - Object containing files with their types (must have 'files' property)
|
|
325
|
+
* @param visibility - Visibility setting (e.g., 'PUBLIC', 'PRIVATE')
|
|
326
|
+
* @returns Promise resolving when visibility is updated
|
|
327
|
+
*/
|
|
328
|
+
async setNetworksVisibility(
|
|
329
|
+
files: { files: Record<string, 'NETWORK' | 'FOLDER' | 'SHORTCUT'> },
|
|
330
|
+
visibility: string
|
|
331
|
+
): Promise<any> {
|
|
332
|
+
this.validateShareData(files);
|
|
333
|
+
|
|
334
|
+
const endpoint = 'batch/networks/visibility';
|
|
335
|
+
const data = {
|
|
336
|
+
items: files,
|
|
337
|
+
visibility: visibility
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
return this.http.post<any>(endpoint, data, { version: 'v3' });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Get random edges from network (migrated from original NDEx.js)
|
|
345
|
+
*
|
|
346
|
+
* Retrieves a random sample of edges from a network using the V3 API.
|
|
347
|
+
* This is useful for previewing large networks or sampling edge data.
|
|
348
|
+
*
|
|
349
|
+
* @param networkUUID - The UUID of the network to get edges from
|
|
350
|
+
* @param limit - Number of random edges to retrieve (must be greater than 0)
|
|
351
|
+
* @param accessKey - Optional access key for private networks
|
|
352
|
+
* @returns Promise resolving to array of CX2Edge objects
|
|
353
|
+
* @throws Error if limit is less than or equal to 0
|
|
354
|
+
*/
|
|
355
|
+
async getRandomEdges(
|
|
356
|
+
networkUUID: string,
|
|
357
|
+
limit: number,
|
|
358
|
+
accessKey?: string
|
|
359
|
+
): Promise<CX2Edge[]> {
|
|
360
|
+
if (limit <= 0) {
|
|
361
|
+
throw new Error("Value of parameter limit has to be greater than 0.");
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const params: Record<string, string> = {
|
|
365
|
+
size: limit.toString(),
|
|
366
|
+
method: "random"
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
if (accessKey !== undefined) {
|
|
370
|
+
params.accesskey = accessKey;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const endpoint = `networks/${networkUUID}/aspects/edges`;
|
|
374
|
+
return this.http.get<CX2Edge[]>(endpoint, {
|
|
375
|
+
version: 'v3',
|
|
376
|
+
params
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Validate share data format (helper method for file operations)
|
|
382
|
+
*
|
|
383
|
+
* Validates the structure and content of file data used in sharing operations.
|
|
384
|
+
* Ensures proper UUID format and valid file types.
|
|
385
|
+
*
|
|
386
|
+
* @param data - Data object to validate (must contain 'files' property)
|
|
387
|
+
* @throws Error if validation fails
|
|
388
|
+
*/
|
|
389
|
+
private validateShareData(data: any): void {
|
|
390
|
+
// Check if data is an object and has files property
|
|
391
|
+
if (typeof data !== 'object' || data === null || data.files === undefined) {
|
|
392
|
+
throw new Error('Data must be an object with a "files" property');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Check if files is an object
|
|
396
|
+
if (typeof data.files !== 'object' || data.files === null) {
|
|
397
|
+
throw new Error('The "files" property must be an object');
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Check each key-value pair in files
|
|
401
|
+
const validValues = ['NETWORK', 'FOLDER', 'SHORTCUT'];
|
|
402
|
+
|
|
403
|
+
for (const [uuid, fileType] of Object.entries(data.files)) {
|
|
404
|
+
// Validate UUID format (basic validation)
|
|
405
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)) {
|
|
406
|
+
throw new Error(`Invalid UUID format: ${uuid}`);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Validate file type
|
|
410
|
+
if (!validValues.includes(fileType as string)) {
|
|
411
|
+
throw new Error(`Invalid file type for ${uuid}: ${fileType}. Must be one of: ${validValues.join(', ')}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Get aspect elements (migrated from original NDEx.js)
|
|
418
|
+
*
|
|
419
|
+
* Retrieves elements from a specific aspect of a network using the V3 API.
|
|
420
|
+
* This function can be used to get nodes, edges, or other aspect data
|
|
421
|
+
* with optional size limiting and access key support for private networks.
|
|
422
|
+
*
|
|
423
|
+
* @param networkUUID - The UUID of the network to get aspect elements from
|
|
424
|
+
* @param aspectName - Name of the aspect to retrieve (e.g., 'nodes', 'edges', 'networkAttributes')
|
|
425
|
+
* @param limit - Optional maximum number of elements to return
|
|
426
|
+
* @param accessKey - Optional access key for private networks
|
|
427
|
+
* @returns Promise resolving to array of aspect elements
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* // Get first 100 nodes from a network
|
|
431
|
+
* const nodes = await client.networks.getAspectElements('network-uuid', 'nodes', 100);
|
|
432
|
+
*
|
|
433
|
+
* // Get all edges from a network
|
|
434
|
+
* const edges = await client.networks.getAspectElements('network-uuid', 'edges');
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
async getAspectElements(
|
|
438
|
+
networkUUID: string,
|
|
439
|
+
aspectName: string,
|
|
440
|
+
limit?: number,
|
|
441
|
+
accessKey?: string
|
|
442
|
+
): Promise<any[]> {
|
|
443
|
+
const params: Record<string, string> = {};
|
|
444
|
+
|
|
445
|
+
if (limit !== undefined) {
|
|
446
|
+
params.size = limit.toString();
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (accessKey !== undefined) {
|
|
450
|
+
params.accesskey = accessKey;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const endpoint = `networks/${networkUUID}/aspects/${aspectName}`;
|
|
454
|
+
return this.http.get<any[]>(endpoint, {
|
|
455
|
+
version: 'v3',
|
|
456
|
+
params
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Get filtered edges (migrated from original NDEx.js)
|
|
462
|
+
*
|
|
463
|
+
* Retrieves edges from a network that match specific filtering criteria on a column value.
|
|
464
|
+
* The function supports both CX1 and CX2 formats based on the format parameter, with CX2
|
|
465
|
+
* being the default format used by the server.
|
|
466
|
+
*
|
|
467
|
+
* @param networkUUID - The UUID of the network to get filtered edges from
|
|
468
|
+
* @param columnName - Name of the edge attribute column to filter on
|
|
469
|
+
* @param valueString - Value to filter by (converted to string for comparison)
|
|
470
|
+
* @param operator - Filtering operation: '>' | '<' | '=' | '!='
|
|
471
|
+
* @param limit - Optional maximum number of edges to return (default: -1 = all matching edges)
|
|
472
|
+
* @param order - Optional sort order for edges before applying limit: 'asc' | 'desc' (default: 'desc')
|
|
473
|
+
* @param format - Optional output format: 'cx' | 'cx2' (default: 'cx2')
|
|
474
|
+
* @param accessKey - Optional access key for private networks
|
|
475
|
+
* @returns Promise resolving to array of edges in the specified format
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* // Get edges with weight > 0.5 in CX2 format (default)
|
|
480
|
+
* const cx2Edges = await client.networks.getFilteredEdges(
|
|
481
|
+
* 'network-uuid', 'weight', '0.5', '>'
|
|
482
|
+
* );
|
|
483
|
+
*
|
|
484
|
+
* // Get top 10 edges with highest score in CX1 format
|
|
485
|
+
* const cx1Edges = await client.networks.getFilteredEdges(
|
|
486
|
+
* 'network-uuid', 'score', '0', '>', 10, 'desc', 'cx'
|
|
487
|
+
* );
|
|
488
|
+
*
|
|
489
|
+
* // Get edges where interaction equals 'pp'
|
|
490
|
+
* const ppEdges = await client.networks.getFilteredEdges(
|
|
491
|
+
* 'network-uuid', 'interaction', 'pp', '=', undefined, undefined, 'cx2'
|
|
492
|
+
* );
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
async getFilteredEdges(
|
|
496
|
+
networkUUID: string,
|
|
497
|
+
columnName: string,
|
|
498
|
+
valueString: string,
|
|
499
|
+
operator: '>' | '<' | '=' | '!=',
|
|
500
|
+
limit?: number,
|
|
501
|
+
order?: 'asc' | 'desc',
|
|
502
|
+
format?: 'cx' | 'cx2',
|
|
503
|
+
accessKey?: string
|
|
504
|
+
): Promise<CX2Edge[] | CX1Edge[]> {
|
|
505
|
+
const params: Record<string, string> = {};
|
|
506
|
+
|
|
507
|
+
if (limit !== undefined) {
|
|
508
|
+
params.size = limit.toString();
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (order !== undefined) {
|
|
512
|
+
params.order = order;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (accessKey !== undefined) {
|
|
516
|
+
params.accesskey = accessKey;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (format !== undefined) {
|
|
520
|
+
params.format = format;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const data = {
|
|
524
|
+
name: columnName,
|
|
525
|
+
value: valueString,
|
|
526
|
+
operator: operator
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
const endpoint = `search/networks/${networkUUID}/edges`;
|
|
530
|
+
return this.http.post<CX2Edge[] | CX1Edge[]>(endpoint, data, {
|
|
531
|
+
version: 'v3',
|
|
532
|
+
params
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Get CX2 metadata (migrated from original NDEx.js)
|
|
538
|
+
*
|
|
539
|
+
* Retrieves metadata information for all aspects in a CX2 network format.
|
|
540
|
+
* This function provides aspect metadata including element counts for each
|
|
541
|
+
* aspect in the network using the V3 API.
|
|
542
|
+
*
|
|
543
|
+
* @param networkUUID - The UUID of the network to get CX2 metadata for
|
|
544
|
+
* @param accessKey - Optional access key for private networks
|
|
545
|
+
* @returns Promise resolving to array of CX2MetaData objects
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```typescript
|
|
549
|
+
* // Get CX2 metadata for a network
|
|
550
|
+
* const metaData = await client.networks.getCX2MetaData('network-uuid');
|
|
551
|
+
* console.log(metaData); // [{ name: 'nodes', elementCount: 100 }, { name: 'edges', elementCount: 150 }]
|
|
552
|
+
*
|
|
553
|
+
* // Get CX2 metadata for a private network
|
|
554
|
+
* const privateMetaData = await client.networks.getCX2MetaData('private-network-uuid', 'access-key');
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
async getCX2MetaData(
|
|
558
|
+
networkUUID: string,
|
|
559
|
+
accessKey?: string
|
|
560
|
+
): Promise<CX2MetaData[]> {
|
|
561
|
+
const params: Record<string, string> = {};
|
|
562
|
+
|
|
563
|
+
if (accessKey !== undefined) {
|
|
564
|
+
params.accesskey = accessKey;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const endpoint = `networks/${networkUUID}/aspects`;
|
|
568
|
+
return this.http.get<CX2MetaData[]>(endpoint, {
|
|
569
|
+
version: 'v3',
|
|
570
|
+
params
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Create network from raw CX2 data (migrated from original NDEx.js)
|
|
576
|
+
*
|
|
577
|
+
* Creates a new network on NDEx from raw CX2 data using the V3 API.
|
|
578
|
+
* This function delegates to the NetworkServiceV3 implementation.
|
|
579
|
+
*
|
|
580
|
+
* @param cx2Data - Raw CX2 network data as an object or CX2Network instance
|
|
581
|
+
* @param options - Creation options including visibility and folderId
|
|
582
|
+
* @param options.visibility - Network visibility: 'PUBLIC' or 'PRIVATE' (default: 'PRIVATE')
|
|
583
|
+
* @param options.folderId - UUID of the folder to create the network in. If omitted, network is created in user's home directory
|
|
584
|
+
* @returns Promise resolving to NDExObjectUpdateStatus with uuid and modificationTime
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```typescript
|
|
588
|
+
* // Create private network from raw CX2 data in user's home directory
|
|
589
|
+
* const result = await client.networks.createNetworkFromRawCX2(cx2Data);
|
|
590
|
+
* console.log(result.uuid); // "12345678-1234-1234-1234-123456789abc"
|
|
591
|
+
*
|
|
592
|
+
* // Create public network from raw CX2 data in a specific folder
|
|
593
|
+
* const publicResult = await client.networks.createNetworkFromRawCX2(cx2Data, {
|
|
594
|
+
* visibility: 'PUBLIC',
|
|
595
|
+
* folderId: '87654321-4321-4321-4321-876543210fed'
|
|
596
|
+
* });
|
|
597
|
+
* console.log(publicResult.uuid);
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
async createNetworkFromRawCX2(
|
|
601
|
+
cx2Data: CX2NetworkType | CX2Network,
|
|
602
|
+
options: { visibility?: 'PUBLIC' | 'PRIVATE'; folderId?: string } = {}
|
|
603
|
+
): Promise<NDExObjectUpdateStatus> {
|
|
604
|
+
return this.v3.createNetworkFromCX2(cx2Data, options);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Update network from raw CX2 data (migrated from original NDEx.js)
|
|
609
|
+
*
|
|
610
|
+
* Updates an existing network with new raw CX2 data using the V3 API.
|
|
611
|
+
* This function replaces the entire network content with the provided CX2 data.
|
|
612
|
+
*
|
|
613
|
+
* @param networkUUID - The UUID of the network to update
|
|
614
|
+
* @param rawCX2 - Raw CX2 network data as an object or CX2Network instance
|
|
615
|
+
* @returns Promise resolving when the network update is complete
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```typescript
|
|
619
|
+
* // Update existing network with new CX2 data
|
|
620
|
+
* await client.networks.updateNetworkFromRawCX2('network-uuid', updatedCx2Data);
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
async updateNetworkFromRawCX2(
|
|
624
|
+
networkUUID: string,
|
|
625
|
+
rawCX2: CX2NetworkType | any
|
|
626
|
+
): Promise<void> {
|
|
627
|
+
const endpoint = `networks/${networkUUID}`;
|
|
628
|
+
return this.http.put<void>(endpoint, rawCX2, { version: 'v3' });
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Access to underlying service instances for advanced usage
|
|
633
|
+
*/
|
|
634
|
+
get v2(): NetworkServiceV2 {
|
|
635
|
+
return this.v2Service;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
get v3(): NetworkServiceV3 {
|
|
639
|
+
return this.v3Service;
|
|
640
|
+
}
|
|
641
|
+
}
|