@js4cytoscape/ndex-client 0.5.0-alpha.8 → 0.6.0-alpha.1
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 +248 -13
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.mts +1931 -0
- package/dist/index.d.ts +1931 -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 +79 -21
- package/src/CyNDEx.js.bak +178 -0
- package/src/NDEx.js +101 -14
- package/src/NDEx.js.bak +1107 -0
- package/src/index.ts +207 -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 +445 -0
- package/src/services/NetworkServiceV2.ts +427 -0
- package/src/services/NetworkServiceV3.ts +287 -0
- package/src/services/UnifiedNetworkService.ts +653 -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 +515 -0
- package/dist/ndexClient.common.js +0 -1057
- package/dist/ndexClient.js +0 -538
- package/src/index.js +0 -2
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { HTTPService } from './HTTPService';
|
|
2
|
+
import {
|
|
3
|
+
NetworkSummaryV2,
|
|
4
|
+
NetworkPermission,
|
|
5
|
+
PaginationParams,
|
|
6
|
+
AccessParams,
|
|
7
|
+
CX1MetaDataResponse,
|
|
8
|
+
AccessKeyResponse,
|
|
9
|
+
AccessKeyAction
|
|
10
|
+
} from '../types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* NetworkServiceV2 - NDEx API v2 network operations
|
|
14
|
+
* Handles legacy v2 endpoints with modern TypeScript interface
|
|
15
|
+
*/
|
|
16
|
+
export class NetworkServiceV2 {
|
|
17
|
+
constructor(private http: HTTPService) {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get raw network in CX1 format
|
|
21
|
+
*
|
|
22
|
+
* Returns raw CX1 data as an array of aspects. This data may contain fragmented aspects
|
|
23
|
+
* that need to be assembled into a complete CX1 network model for proper usage.
|
|
24
|
+
* For a fully assembled network object, consider using getNetworkAsCX2Object() instead.
|
|
25
|
+
*
|
|
26
|
+
* @param networkUUID - The UUID of the network to retrieve
|
|
27
|
+
* @param options - Access options including optional access key
|
|
28
|
+
* @returns Promise resolving to raw CX1 data as an array of aspects
|
|
29
|
+
*/
|
|
30
|
+
async getRawCX1Network(
|
|
31
|
+
networkUUID: string,
|
|
32
|
+
options: AccessParams = {}
|
|
33
|
+
): Promise<any[]> {
|
|
34
|
+
const params = new URLSearchParams();
|
|
35
|
+
if (options.accesskey) {
|
|
36
|
+
params.append('accesskey', options.accesskey);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const endpoint = `network/${networkUUID}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
40
|
+
return this.http.get<any[]>(endpoint, {
|
|
41
|
+
version: 'v2',
|
|
42
|
+
headers: { 'Accept': 'application/json' }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get network summary by UUID
|
|
48
|
+
*/
|
|
49
|
+
async getNetworkSummary(
|
|
50
|
+
networkUUID: string,
|
|
51
|
+
options: AccessParams = {}
|
|
52
|
+
): Promise<NetworkSummaryV2> {
|
|
53
|
+
const params = new URLSearchParams();
|
|
54
|
+
if (options.accesskey) {
|
|
55
|
+
params.append('accesskey', options.accesskey);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const endpoint = `network/${networkUUID}/summary${params.toString() ? `?${params.toString()}` : ''}`;
|
|
59
|
+
return this.http.get<NetworkSummaryV2>(endpoint, { version: 'v2' });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Copy network
|
|
64
|
+
*
|
|
65
|
+
* Creates a copy of an existing network using the server's copy endpoint.
|
|
66
|
+
* The copied network will have the same content but will be assigned a new UUID
|
|
67
|
+
* and will be owned by the authenticated user.
|
|
68
|
+
*
|
|
69
|
+
* @param networkUUID - The UUID of the network to copy
|
|
70
|
+
* @returns Promise resolving to the URL of the cloned CX1 network
|
|
71
|
+
*/
|
|
72
|
+
async copyNetwork(networkUUID: string): Promise<string> {
|
|
73
|
+
const endpoint = `network/${networkUUID}/copy`;
|
|
74
|
+
return this.http.post<string>(endpoint, {}, {
|
|
75
|
+
version: 'v2'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Search networks (migrated from original NDEx.js)
|
|
82
|
+
*
|
|
83
|
+
* Searches networks using POST request with search parameters in the request body.
|
|
84
|
+
* This implementation matches the original NDEx.js searchNetworks function.
|
|
85
|
+
*
|
|
86
|
+
* @param searchTerms - Search string to find networks
|
|
87
|
+
* @param start - Starting offset for pagination (optional)
|
|
88
|
+
* @param size - Maximum number of results to return (optional)
|
|
89
|
+
* @param optionalParameters - Additional search filters
|
|
90
|
+
* @param optionalParameters.permission - Filter by permission level
|
|
91
|
+
* @param optionalParameters.includeGroups - Whether to include group networks
|
|
92
|
+
* @param optionalParameters.accountName - Filter by account name
|
|
93
|
+
* @returns Promise resolving to search results
|
|
94
|
+
*/
|
|
95
|
+
async searchNetworks(
|
|
96
|
+
searchTerms: string,
|
|
97
|
+
start?: number,
|
|
98
|
+
size?: number,
|
|
99
|
+
optionalParameters?: {
|
|
100
|
+
permission?: string;
|
|
101
|
+
includeGroups?: boolean;
|
|
102
|
+
accountName?: string;
|
|
103
|
+
}
|
|
104
|
+
): Promise<any> {
|
|
105
|
+
const params: Record<string, string> = {};
|
|
106
|
+
|
|
107
|
+
if (start !== undefined) {
|
|
108
|
+
params.start = start.toString();
|
|
109
|
+
}
|
|
110
|
+
if (size !== undefined) {
|
|
111
|
+
params.limit = size.toString();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const data: Record<string, any> = { searchString: searchTerms };
|
|
115
|
+
|
|
116
|
+
if (optionalParameters !== undefined) {
|
|
117
|
+
if (optionalParameters.permission !== undefined) {
|
|
118
|
+
data.permission = optionalParameters.permission;
|
|
119
|
+
}
|
|
120
|
+
if (optionalParameters.includeGroups !== undefined) {
|
|
121
|
+
data.includeGroups = optionalParameters.includeGroups;
|
|
122
|
+
}
|
|
123
|
+
if (optionalParameters.accountName !== undefined) {
|
|
124
|
+
data.accountName = optionalParameters.accountName;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const endpoint = 'search/network';
|
|
129
|
+
return this.http.post<any>(endpoint, data, {
|
|
130
|
+
version: 'v2',
|
|
131
|
+
params
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Create new network from raw CX1 data
|
|
139
|
+
*
|
|
140
|
+
* Creates a new network in NDEx from raw CX1 network data. This method handles
|
|
141
|
+
* the server response parsing to extract the network UUID from the location header.
|
|
142
|
+
*
|
|
143
|
+
* @param rawCX - Raw CX1 network data as an array of aspects
|
|
144
|
+
* @param options - Optional options for network creation (visibility settings)
|
|
145
|
+
* @returns Promise resolving to the UUID string of the newly created network
|
|
146
|
+
*/
|
|
147
|
+
async createNetworkFromRawCX1(
|
|
148
|
+
rawCX: any[],
|
|
149
|
+
options: { visibility?: 'PUBLIC' | 'PRIVATE' } = {}
|
|
150
|
+
): Promise<string> {
|
|
151
|
+
const endpoint = 'network';
|
|
152
|
+
const response = await this.http.post<string>(endpoint, rawCX, {
|
|
153
|
+
version: 'v2',
|
|
154
|
+
params: options
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Extract UUID from response URL (e.g., "/v2/network/12345" -> "12345")
|
|
158
|
+
const uuidr = response.split('/');
|
|
159
|
+
const uuid = uuidr[uuidr.length - 1];
|
|
160
|
+
|
|
161
|
+
return uuid;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Update network from raw CX1 data
|
|
167
|
+
*
|
|
168
|
+
* Updates an existing network in NDEx with new raw CX1 network data.
|
|
169
|
+
* This completely replaces the network content with the provided CX1 data.
|
|
170
|
+
* Uses the legacy v2 endpoint format from the original NDEx.js implementation.
|
|
171
|
+
*
|
|
172
|
+
* @param networkUUID - The UUID of the network to update
|
|
173
|
+
* @param rawCX - Raw CX1 network data as an array of aspects
|
|
174
|
+
* @returns Promise resolving when the update is complete
|
|
175
|
+
*/
|
|
176
|
+
async updateNetworkFromRawCX1(
|
|
177
|
+
networkUUID: string,
|
|
178
|
+
rawCX: any[]
|
|
179
|
+
): Promise<void> {
|
|
180
|
+
const endpoint = `network/${networkUUID}`;
|
|
181
|
+
return this.http.put<void>(endpoint, rawCX, { version: 'v2' });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Delete network
|
|
186
|
+
*/
|
|
187
|
+
async deleteNetwork(networkUUID: string): Promise<void> {
|
|
188
|
+
const endpoint = `network/${networkUUID}`;
|
|
189
|
+
return this.http.delete<void>(endpoint, { version: 'v2' });
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get network summaries by UUIDs (migrated from original NDEx.js)
|
|
194
|
+
*
|
|
195
|
+
* Retrieves network summaries for multiple networks in a single batch request.
|
|
196
|
+
* Uses the V2 API batch endpoint for efficient bulk operations.
|
|
197
|
+
*
|
|
198
|
+
* @param uuidList - Array of network UUIDs to retrieve summaries for
|
|
199
|
+
* @param accessKey - Optional access key for private networks
|
|
200
|
+
* @returns Promise resolving to array of network summaries
|
|
201
|
+
*/
|
|
202
|
+
async getNetworkSummariesByUUIDs(
|
|
203
|
+
uuidList: string[],
|
|
204
|
+
accessKey?: string
|
|
205
|
+
): Promise<NetworkSummaryV2[]> {
|
|
206
|
+
const params = accessKey ? { accesskey: accessKey } : undefined;
|
|
207
|
+
|
|
208
|
+
const endpoint = 'batch/network/summary';
|
|
209
|
+
return this.http.post<NetworkSummaryV2[]>(endpoint, uuidList, {
|
|
210
|
+
version: 'v2',
|
|
211
|
+
params
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// The following functions need to be either reviewed or removed.
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Get user's networks
|
|
220
|
+
*/
|
|
221
|
+
async getUserNetworks(
|
|
222
|
+
accountName: string,
|
|
223
|
+
options: PaginationParams = {}
|
|
224
|
+
): Promise<NetworkSummaryV2[]> {
|
|
225
|
+
const params = new URLSearchParams();
|
|
226
|
+
if (options.start !== undefined) {
|
|
227
|
+
params.append('start', options.start.toString());
|
|
228
|
+
}
|
|
229
|
+
if (options.size !== undefined) {
|
|
230
|
+
params.append('size', options.size.toString());
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const endpoint = `user/${accountName}/networks${params.toString() ? `?${params.toString()}` : ''}`;
|
|
234
|
+
return this.http.get<NetworkSummaryV2[]>(endpoint, { version: 'v2' });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Set network system properties
|
|
240
|
+
*/
|
|
241
|
+
async setNetworkSystemProperties(
|
|
242
|
+
networkUUID: string,
|
|
243
|
+
properties: Record<string, any>
|
|
244
|
+
): Promise<void> {
|
|
245
|
+
const endpoint = `networks/${networkUUID}/systemproperty`;
|
|
246
|
+
return this.http.put<void>(endpoint, properties, { version: 'v2' });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get network permissions
|
|
251
|
+
*/
|
|
252
|
+
async getNetworkPermissions(networkUUID: string): Promise<NetworkPermission[]> {
|
|
253
|
+
const endpoint = `networks/${networkUUID}/permission`;
|
|
254
|
+
return this.http.get<NetworkPermission[]>(endpoint, { version: 'v2' });
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Set network permissions
|
|
259
|
+
*/
|
|
260
|
+
async setNetworkPermissions(
|
|
261
|
+
networkUUID: string,
|
|
262
|
+
permissions: NetworkPermission[]
|
|
263
|
+
): Promise<void> {
|
|
264
|
+
const endpoint = `networks/${networkUUID}/permission`;
|
|
265
|
+
return this.http.put<void>(endpoint, permissions, { version: 'v2' });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Grant network permission to user
|
|
270
|
+
*/
|
|
271
|
+
async grantNetworkPermission(
|
|
272
|
+
networkUUID: string,
|
|
273
|
+
userUUID: string,
|
|
274
|
+
permission: 'READ' | 'WRITE' | 'ADMIN'
|
|
275
|
+
): Promise<void> {
|
|
276
|
+
const endpoint = `networks/${networkUUID}/permission`;
|
|
277
|
+
const permissionData = {
|
|
278
|
+
memberUUID: userUUID,
|
|
279
|
+
permission: permission
|
|
280
|
+
};
|
|
281
|
+
return this.http.post<void>(endpoint, permissionData, { version: 'v2' });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Revoke network permission from user
|
|
286
|
+
*/
|
|
287
|
+
async revokeNetworkPermission(
|
|
288
|
+
networkUUID: string,
|
|
289
|
+
userUUID: string
|
|
290
|
+
): Promise<void> {
|
|
291
|
+
const endpoint = `networks/${networkUUID}/permission`;
|
|
292
|
+
return this.http.delete<void>(endpoint, {
|
|
293
|
+
version: 'v2',
|
|
294
|
+
data: { memberUUID: userUUID }
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Get network profile (additional metadata)
|
|
300
|
+
*/
|
|
301
|
+
async getNetworkProfile(networkUUID: string): Promise<any> {
|
|
302
|
+
const endpoint = `networks/${networkUUID}/profile`;
|
|
303
|
+
return this.http.get<any>(endpoint, { version: 'v2' });
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Set network profile
|
|
308
|
+
*/
|
|
309
|
+
async setNetworkProfile(
|
|
310
|
+
networkUUID: string,
|
|
311
|
+
profile: any
|
|
312
|
+
): Promise<void> {
|
|
313
|
+
const endpoint = `networks/${networkUUID}/profile`;
|
|
314
|
+
return this.http.put<void>(endpoint, profile, { version: 'v2' });
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Make network public
|
|
319
|
+
*/
|
|
320
|
+
async makeNetworkPublic(networkUUID: string): Promise<void> {
|
|
321
|
+
const endpoint = `networks/${networkUUID}/systemproperty`;
|
|
322
|
+
const properties = { visibility: 'PUBLIC' };
|
|
323
|
+
return this.http.put<void>(endpoint, properties, { version: 'v2' });
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Make network private
|
|
328
|
+
*/
|
|
329
|
+
async makeNetworkPrivate(networkUUID: string): Promise<void> {
|
|
330
|
+
const endpoint = `networks/${networkUUID}/systemproperty`;
|
|
331
|
+
const properties = { visibility: 'PRIVATE' };
|
|
332
|
+
return this.http.put<void>(endpoint, properties, { version: 'v2' });
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Get network sample (if available)
|
|
337
|
+
*/
|
|
338
|
+
async getNetworkSample(
|
|
339
|
+
networkUUID: string,
|
|
340
|
+
options: AccessParams = {}
|
|
341
|
+
): Promise<any[]> {
|
|
342
|
+
const params = new URLSearchParams();
|
|
343
|
+
if (options.accesskey) {
|
|
344
|
+
params.append('accesskey', options.accesskey);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const endpoint = `networks/${networkUUID}/sample${params.toString() ? `?${params.toString()}` : ''}`;
|
|
348
|
+
return this.http.get<any[]>(endpoint, { version: 'v2' });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Get network metadata (migrated from original NDEx.js)
|
|
353
|
+
*
|
|
354
|
+
* Retrieves metadata information about network aspects including element counts,
|
|
355
|
+
* versions, and ID counters for each aspect in the network. This provides
|
|
356
|
+
* an overview of the network's structure and content organization.
|
|
357
|
+
*
|
|
358
|
+
* @param networkUUID - The UUID of the network to get metadata for
|
|
359
|
+
* @param accessKey - Optional access key for private networks
|
|
360
|
+
* @returns Promise resolving to metadata containing aspect information
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const metadata = await networkService.getMetaData('network-uuid');
|
|
364
|
+
* // Returns: { metaData: [{ name: 'nodes', elementCount: 330, version: '1.0' }, ...] }
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
async getMetaData(
|
|
368
|
+
networkUUID: string,
|
|
369
|
+
accessKey?: string
|
|
370
|
+
): Promise<CX1MetaDataResponse> {
|
|
371
|
+
const params = new URLSearchParams();
|
|
372
|
+
if (accessKey !== undefined) {
|
|
373
|
+
params.append('accesskey', accessKey);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const endpoint = `network/${networkUUID}/aspect${params.toString() ? `?${params.toString()}` : ''}`;
|
|
377
|
+
return this.http.get<CX1MetaDataResponse>(endpoint, { version: 'v2' });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Get network access key (migrated from original NDEx.js)
|
|
382
|
+
*
|
|
383
|
+
* Retrieves the current access key for a network. Access keys allow
|
|
384
|
+
* users to share private networks without requiring individual permissions.
|
|
385
|
+
*
|
|
386
|
+
* @param networkUUID - The UUID of the network to get access key for
|
|
387
|
+
* @returns Promise resolving to access key response object
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const response = await networkService.getAccessKey('network-uuid');
|
|
392
|
+
* console.log(response.accessKey); // "acialdfeoa03430023" or null
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
async getAccessKey(networkUUID: string): Promise<AccessKeyResponse> {
|
|
396
|
+
const endpoint = `networks/${networkUUID}/accesskey`;
|
|
397
|
+
return this.http.get<AccessKeyResponse>(endpoint, { version: 'v2' });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Update network access key (migrated from original NDEx.js)
|
|
402
|
+
*
|
|
403
|
+
* Enables or disables the access key for a network. When enabled, creates
|
|
404
|
+
* a new access key that can be shared. When disabled, invalidates the
|
|
405
|
+
* current access key.
|
|
406
|
+
*
|
|
407
|
+
* @param networkUUID - The UUID of the network to update access key for
|
|
408
|
+
* @param action - Action to perform: 'enable' creates/updates key, 'disable' removes it
|
|
409
|
+
* @returns Promise resolving to access key response (accessKey will be null when disabled)
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```typescript
|
|
413
|
+
* // Enable access key
|
|
414
|
+
* const enabled = await networkService.updateAccessKey('network-uuid', 'enable');
|
|
415
|
+
* console.log(enabled.accessKey); // "new-access-key-string"
|
|
416
|
+
*
|
|
417
|
+
* // Disable access key
|
|
418
|
+
* const disabled = await networkService.updateAccessKey('network-uuid', 'disable');
|
|
419
|
+
* console.log(disabled.accessKey); // null
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
async updateAccessKey(networkUUID: string, action: AccessKeyAction): Promise<AccessKeyResponse> {
|
|
423
|
+
const endpoint = `networks/${networkUUID}/accesskey`;
|
|
424
|
+
return this.http.put<AccessKeyResponse>(endpoint, { action }, { version: 'v2' });
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { HTTPService } from './HTTPService';
|
|
2
|
+
import {
|
|
3
|
+
NetworkSummaryV3,
|
|
4
|
+
SearchResult,
|
|
5
|
+
SearchParameters,
|
|
6
|
+
PaginationParams,
|
|
7
|
+
AccessParams,
|
|
8
|
+
CX2Network as CX2NetworkType
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { CX2Network } from '../models/CX2Network';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* NetworkServiceV3 - NDEx API v3 network operations
|
|
14
|
+
* Handles modern v3 endpoints with native CX2 support
|
|
15
|
+
*/
|
|
16
|
+
export class NetworkServiceV3 {
|
|
17
|
+
constructor(private http: HTTPService) {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get network summary by UUID
|
|
21
|
+
*/
|
|
22
|
+
async getNetworkSummary(
|
|
23
|
+
networkUUID: string,
|
|
24
|
+
options: AccessParams = {}
|
|
25
|
+
): Promise<NetworkSummaryV3> {
|
|
26
|
+
const params = new URLSearchParams();
|
|
27
|
+
if (options.accesskey) {
|
|
28
|
+
params.append('accesskey', options.accesskey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const endpoint = `networks/${networkUUID}/summary${params.toString() ? `?${params.toString()}` : ''}`;
|
|
32
|
+
return this.http.get<NetworkSummaryV3>(endpoint, { version: 'v3' });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get raw network in CX2 format (native V3)
|
|
38
|
+
*
|
|
39
|
+
* Returns raw CX2 data which may contain fragmented aspects that need to be assembled
|
|
40
|
+
* into a complete CX2 network model for proper usage. The returned data follows the
|
|
41
|
+
* CX2 specification but may have aspects split across multiple fragments.
|
|
42
|
+
* For a fully assembled network object with utility methods, use getNetworkAsCX2Object() instead.
|
|
43
|
+
*
|
|
44
|
+
* @param networkUUID - The UUID of the network to retrieve
|
|
45
|
+
* @param options - Access options including optional access key
|
|
46
|
+
* @returns Promise resolving to raw CX2 network data that may be fragmented
|
|
47
|
+
*/
|
|
48
|
+
async getRawCX2Network(
|
|
49
|
+
networkUUID: string,
|
|
50
|
+
options: AccessParams = {}
|
|
51
|
+
): Promise<CX2NetworkType> {
|
|
52
|
+
const params = new URLSearchParams();
|
|
53
|
+
if (options.accesskey) {
|
|
54
|
+
params.append('accesskey', options.accesskey);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const endpoint = `networks/${networkUUID}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
58
|
+
return this.http.get<CX2NetworkType>(endpoint, { version: 'v3' });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create network DOI
|
|
64
|
+
*
|
|
65
|
+
* @param networkUUID - The UUID of the network to create a DOI for
|
|
66
|
+
* @param key - DOI creation key
|
|
67
|
+
* @param email - Email address for DOI registration
|
|
68
|
+
* @returns Promise resolving to a confirmation message string from the server
|
|
69
|
+
*/
|
|
70
|
+
async createNetworkDOI(
|
|
71
|
+
networkUUID: string,
|
|
72
|
+
key: string,
|
|
73
|
+
email: string
|
|
74
|
+
): Promise<string> {
|
|
75
|
+
const params = new URLSearchParams();
|
|
76
|
+
params.append('key', key);
|
|
77
|
+
params.append('email', email);
|
|
78
|
+
|
|
79
|
+
const endpoint = `networks/${networkUUID}/DOI?${params.toString()}`;
|
|
80
|
+
return this.http.get<string>(endpoint, { version: 'v3' });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get attributes of selected nodes
|
|
85
|
+
*
|
|
86
|
+
* Retrieves specific attributes for a set of nodes in a network. The server will return
|
|
87
|
+
* a 404 error if the network has no attributes on nodes.
|
|
88
|
+
*
|
|
89
|
+
* @param networkUUID - The UUID of the network
|
|
90
|
+
* @param nodeSelection - Object containing node IDs and attribute names to retrieve
|
|
91
|
+
* @param nodeSelection.ids - Array of node IDs (long numbers) to get attributes for
|
|
92
|
+
* @param nodeSelection.attributeNames - Array of attribute names to retrieve
|
|
93
|
+
* @param options - Access options including optional access key
|
|
94
|
+
* @returns Promise resolving to a JSON object where keys are stringified node IDs
|
|
95
|
+
* and values are the selected attributes for that node
|
|
96
|
+
* @throws {404} When the network has no attributes on nodes
|
|
97
|
+
*/
|
|
98
|
+
async getAttributesOfSelectedNodes(
|
|
99
|
+
networkUUID: string,
|
|
100
|
+
nodeSelection: { ids: number[]; attributeNames: string[] },
|
|
101
|
+
options: AccessParams = {}
|
|
102
|
+
): Promise<Record<string, any>> {
|
|
103
|
+
const params = new URLSearchParams();
|
|
104
|
+
if (options.accesskey) {
|
|
105
|
+
params.append('accesskey', options.accesskey);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const data = {
|
|
109
|
+
ids: nodeSelection.ids,
|
|
110
|
+
attributeNames: nodeSelection.attributeNames
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const endpoint = `search/networks/${networkUUID}/nodes${params.toString() ? `?${params.toString()}` : ''}`;
|
|
114
|
+
return this.http.post<Record<string, any>>(endpoint, data, { version: 'v3' });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get network summaries by UUIDs using V3 API (migrated from original NDEx.js)
|
|
119
|
+
*
|
|
120
|
+
* Retrieves network summaries for multiple networks in a single batch request using V3 API.
|
|
121
|
+
* Uses the V3 API batch endpoint with format parameter support.
|
|
122
|
+
*
|
|
123
|
+
* @param uuidList - Array of network UUIDs to retrieve summaries for
|
|
124
|
+
* @param accessKey - Optional access key for private networks
|
|
125
|
+
* @param format - Summary format ("FULL" by default, can be "BASIC" or other supported formats)
|
|
126
|
+
* @returns Promise resolving to array of V3 network summaries
|
|
127
|
+
*/
|
|
128
|
+
async getNetworkSummariesV3ByUUIDs(
|
|
129
|
+
uuidList: string[],
|
|
130
|
+
accessKey?: string,
|
|
131
|
+
format?: string
|
|
132
|
+
): Promise<NetworkSummaryV3[]> {
|
|
133
|
+
const params: Record<string, string> = {
|
|
134
|
+
format: format === undefined ? 'FULL' : format
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
if (accessKey != null) {
|
|
138
|
+
params.accesskey = accessKey;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const endpoint = 'batch/networks/summary';
|
|
142
|
+
return this.http.post<NetworkSummaryV3[]>(endpoint, uuidList, {
|
|
143
|
+
version: 'v3',
|
|
144
|
+
params
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
// following functions need to be reviewed or removed.
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Search networks with V3 enhanced features
|
|
154
|
+
*/
|
|
155
|
+
async searchNetworks(searchParams: SearchParameters = {}): Promise<SearchResult> {
|
|
156
|
+
const params = new URLSearchParams();
|
|
157
|
+
|
|
158
|
+
if (searchParams.searchString) {
|
|
159
|
+
params.append('searchString', searchParams.searchString);
|
|
160
|
+
}
|
|
161
|
+
if (searchParams.accountName) {
|
|
162
|
+
params.append('accountName', searchParams.accountName);
|
|
163
|
+
}
|
|
164
|
+
if (searchParams.permission) {
|
|
165
|
+
params.append('permission', searchParams.permission);
|
|
166
|
+
}
|
|
167
|
+
if (searchParams.includeGroups !== undefined) {
|
|
168
|
+
params.append('includeGroups', searchParams.includeGroups.toString());
|
|
169
|
+
}
|
|
170
|
+
if (searchParams.admin) {
|
|
171
|
+
params.append('admin', searchParams.admin);
|
|
172
|
+
}
|
|
173
|
+
if (searchParams.start !== undefined) {
|
|
174
|
+
params.append('start', searchParams.start.toString());
|
|
175
|
+
}
|
|
176
|
+
if (searchParams.size !== undefined) {
|
|
177
|
+
params.append('size', searchParams.size.toString());
|
|
178
|
+
}
|
|
179
|
+
if (searchParams.source) {
|
|
180
|
+
params.append('source', searchParams.source);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const endpoint = `search/network${params.toString() ? `?${params.toString()}` : ''}`;
|
|
184
|
+
return this.http.get<SearchResult>(endpoint, { version: 'v3' });
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get network as CX2Network object with utilities
|
|
188
|
+
*/
|
|
189
|
+
async getNetworkAsCX2Object(
|
|
190
|
+
networkUUID: string,
|
|
191
|
+
options: AccessParams = {}
|
|
192
|
+
): Promise<CX2Network> {
|
|
193
|
+
const cx2Data = await this.getRawCX2Network(networkUUID, options);
|
|
194
|
+
return new CX2Network(cx2Data);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Create new network from CX2
|
|
199
|
+
*/
|
|
200
|
+
async createNetworkFromCX2(
|
|
201
|
+
cx2Data: CX2NetworkType | CX2Network,
|
|
202
|
+
options: { visibility?: 'PUBLIC' | 'PRIVATE'; name?: string } = {}
|
|
203
|
+
): Promise<{ uuid: string }> {
|
|
204
|
+
const endpoint = 'networks/cx2';
|
|
205
|
+
|
|
206
|
+
// Convert CX2Network object to plain object if needed
|
|
207
|
+
const data = cx2Data instanceof CX2Network ? JSON.parse(cx2Data.toJSON()) : cx2Data;
|
|
208
|
+
|
|
209
|
+
return this.http.post<{ uuid: string }>(endpoint, data, {
|
|
210
|
+
version: 'v3',
|
|
211
|
+
params: options
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Update network with CX2 data
|
|
217
|
+
*/
|
|
218
|
+
async updateNetworkCX2(
|
|
219
|
+
networkUUID: string,
|
|
220
|
+
cx2Data: CX2NetworkType | CX2Network
|
|
221
|
+
): Promise<void> {
|
|
222
|
+
const endpoint = `networks/${networkUUID}/cx2`;
|
|
223
|
+
|
|
224
|
+
// Convert CX2Network object to plain object if needed
|
|
225
|
+
const data = cx2Data instanceof CX2Network ? JSON.parse(cx2Data.toJSON()) : cx2Data;
|
|
226
|
+
|
|
227
|
+
return this.http.put<void>(endpoint, data, { version: 'v3' });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Upload network file (CX2, CX, or other formats)
|
|
232
|
+
*/
|
|
233
|
+
async uploadNetworkFile(
|
|
234
|
+
file: File | Blob | string,
|
|
235
|
+
options: {
|
|
236
|
+
filename?: string;
|
|
237
|
+
visibility?: 'PUBLIC' | 'PRIVATE';
|
|
238
|
+
name?: string;
|
|
239
|
+
onProgress?: (progress: number) => void;
|
|
240
|
+
} = {}
|
|
241
|
+
): Promise<{ uuid: string }> {
|
|
242
|
+
return this.http.uploadFile<{ uuid: string }>('networks/upload', file, {
|
|
243
|
+
version: 'v3',
|
|
244
|
+
...options,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Get network metadata (V3 enhanced)
|
|
250
|
+
*/
|
|
251
|
+
async getNetworkMetadata(networkUUID: string): Promise<any> {
|
|
252
|
+
const endpoint = `networks/${networkUUID}/metadata`;
|
|
253
|
+
return this.http.get<any>(endpoint, { version: 'v3' });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Update network metadata
|
|
258
|
+
*/
|
|
259
|
+
async updateNetworkMetadata(
|
|
260
|
+
networkUUID: string,
|
|
261
|
+
metadata: Record<string, any>
|
|
262
|
+
): Promise<void> {
|
|
263
|
+
const endpoint = `networks/${networkUUID}/metadata`;
|
|
264
|
+
return this.http.put<void>(endpoint, metadata, { version: 'v3' });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get network aspect (specific CX2 aspect)
|
|
271
|
+
*/
|
|
272
|
+
async getNetworkAspect(
|
|
273
|
+
networkUUID: string,
|
|
274
|
+
aspectName: string,
|
|
275
|
+
options: AccessParams = {}
|
|
276
|
+
): Promise<any> {
|
|
277
|
+
const params = new URLSearchParams();
|
|
278
|
+
if (options.accesskey) {
|
|
279
|
+
params.append('accesskey', options.accesskey);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const endpoint = `networks/${networkUUID}/aspects/${aspectName}${params.toString() ? `?${params.toString()}` : ''}`;
|
|
283
|
+
return this.http.get<any>(endpoint, { version: 'v3' });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
}
|