@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.
@@ -0,0 +1,524 @@
1
+ /**
2
+ * Core type definitions for NDEx Client Library
3
+ * Pragmatic TypeScript types allowing flexibility with any types where needed
4
+ */
5
+
6
+ // Export Cytoscape-related types
7
+ export * from './cytoscape';
8
+
9
+ // ============================================================================
10
+ // Authentication Types
11
+ // ============================================================================
12
+
13
+ export interface BasicAuth {
14
+ type: 'basic';
15
+ username: string;
16
+ password: string;
17
+ }
18
+
19
+ export interface OAuthAuth {
20
+ type: 'oauth';
21
+ idToken: string; // ID token from OAuth provider
22
+ }
23
+
24
+ export interface NDExAuthResponse {
25
+ token?: string;
26
+ userId?: string;
27
+ userName?: string;
28
+ isAdmin?: boolean;
29
+ permissions?: string[];
30
+ expirationTime?: number;
31
+ }
32
+
33
+ export interface NDExUser {
34
+ externalId: string;
35
+ userName: string;
36
+ firstName?: string;
37
+ lastName?: string;
38
+ emailAddress?: string;
39
+ website?: string;
40
+ description?: string;
41
+ image?: string;
42
+ isIndividual?: boolean;
43
+ isVerified?: boolean;
44
+ creationTime?: number;
45
+ modificationTime?: number;
46
+ }
47
+
48
+ // ============================================================================
49
+ // Network Types
50
+ // ============================================================================
51
+
52
+ export interface CX1MetaDataItem {
53
+ name: string;
54
+ elementCount: number;
55
+ version: string;
56
+ idCounter?: number;
57
+ [key: string]: any; // Allow any additional properties
58
+ }
59
+
60
+ export interface CX1MetaDataResponse {
61
+ metaData: CX1MetaDataItem[];
62
+ }
63
+
64
+ export interface CX1NetworkProperty {
65
+ predicateString: string;
66
+ value: string;
67
+ dataType?: 'string' | 'integer' | 'double' | 'boolean' | 'list_of_string';
68
+ }
69
+
70
+ export interface CX2NetworkProperties {
71
+ [key: string]: {
72
+ t: string; // type
73
+ v: any; // value
74
+ };
75
+ }
76
+
77
+ export enum NetworkIndexLevel {
78
+ NONE = 'NONE',
79
+ BASIC = 'BASIC',
80
+ FULL = 'FULL'
81
+ }
82
+
83
+ export interface NetworkSummaryV2 {
84
+ externalId: string;
85
+ name: string;
86
+ description?: string;
87
+ nodeCount: number;
88
+ edgeCount: number;
89
+ visibility: 'PUBLIC' | 'PRIVATE';
90
+ owner: string;
91
+ ownerUUID: string;
92
+ creationTime: number;
93
+ modificationTime: number;
94
+ version?: string;
95
+ properties?: CX1NetworkProperty[]; // V2 uses CX1 array format
96
+ isReadOnly: boolean;
97
+ isValid: boolean;
98
+ warnings?: string[];
99
+ hasLayout: boolean;
100
+ hasSample: boolean;
101
+
102
+ // Additional attributes for both V2 and V3
103
+ updatedBy: string; // username who modified this network last
104
+ errorMessage?: string;
105
+ cxFormat?: string;
106
+ cxFileSize?: number; // File size in bytes
107
+ cx2FileSize?: number; // File size in bytes
108
+ isShowcase?: boolean;
109
+ isCompleted?: boolean;
110
+ doi?: string;
111
+ isCertified?: boolean;
112
+ indexLevel?: NetworkIndexLevel;
113
+ parentDirUUID?: string;
114
+ showInTrash?: boolean;
115
+ subnetworkIds?: string[];
116
+ reference?: string;
117
+ organism?: string;
118
+ disease?: string;
119
+ tissue?: string;
120
+ networkType?: string[];
121
+ rightsHolder?: string;
122
+ rights?: string;
123
+ sourceFormat?: string;
124
+ }
125
+
126
+ /**
127
+ * NetworkSummaryV3 - Network summary for NDEx API v3
128
+ *
129
+ * Extends NetworkSummaryV2 but uses CX2-style properties format instead of CX1 format.
130
+ * The main difference is in how network properties are structured:
131
+ *
132
+ * | Aspect | NetworkSummaryV2 | NetworkSummaryV3 |
133
+ * |--------|------------------|------------------|
134
+ * | **Properties Format** | `CX1NetworkProperty[]` (array) | `CX2NetworkProperties` (object) |
135
+ * | **Structure** | CX1-style array of property objects | CX2-style key-value map |
136
+ * | **Example** | `[{predicateString: "name", value: "My Network"}]` | `{name: {t: "string", v: "My Network"}}` |
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * // V2 properties format (array of objects)
141
+ * const v2Summary: NetworkSummaryV2 = {
142
+ * externalId: "12345",
143
+ * name: "Sample Network",
144
+ * properties: [
145
+ * { predicateString: "description", value: "A sample network", dataType: "string" },
146
+ * { predicateString: "nodeCount", value: "100", dataType: "integer" }
147
+ * ]
148
+ * };
149
+ *
150
+ * // V3 properties format (object map)
151
+ * const v3Summary: NetworkSummaryV3 = {
152
+ * externalId: "12345",
153
+ * name: "Sample Network",
154
+ * properties: {
155
+ * description: { t: "string", v: "A sample network" },
156
+ * nodeCount: { t: "integer", v: 100 }
157
+ * }
158
+ * };
159
+ * ```
160
+ */
161
+ export interface NetworkSummaryV3 extends Omit<NetworkSummaryV2, 'properties'> {
162
+ properties?: CX2NetworkProperties; // V3 uses CX2 object/map format
163
+ // V3-specific additional attributes can be added here as needed
164
+ }
165
+
166
+
167
+ export interface NetworkPermission {
168
+ uuid: string;
169
+ permission: 'READ' | 'WRITE' | 'ADMIN';
170
+ memberUUID: string;
171
+ memberAccountName?: string;
172
+ resourceUUID: string;
173
+ }
174
+
175
+ // NetworkSet interface removed - deprecated in NDEx v3, replaced by folders with network shortcuts
176
+
177
+ // ============================================================================
178
+ // CX2 Network Types
179
+ // ============================================================================
180
+
181
+ export interface CX2Network {
182
+ CXVersion: string;
183
+ hasFragments: boolean;
184
+ metaData: CX2MetaData[];
185
+ attributeDeclarations?: CX2AttributeDeclarations;
186
+ networkAttributes?: CX2NetworkAttribute[];
187
+ nodes?: CX2Node[];
188
+ edges?: CX2Edge[];
189
+ nodeBypass?: CX2NodeBypass[];
190
+ edgeBypass?: CX2EdgeBypass[];
191
+ visualProperties?: CX2VisualProperty;
192
+ status?: CX2Status[];
193
+ }
194
+
195
+ export interface CX2MetaData {
196
+ name: string;
197
+ elementCount?: number;
198
+ }
199
+
200
+ export interface CX2AttributeDeclarations {
201
+ [aspectName: string]: {
202
+ [attributeName: string]: {
203
+ d: string; // datatype
204
+ a?: string; // alias
205
+ v?: any; // default value
206
+ };
207
+ };
208
+ }
209
+
210
+ export interface CX2AttributeSpec {
211
+ d: string; // data type
212
+ v?: any; // default value
213
+ s?: boolean; // is single
214
+ }
215
+
216
+ export interface CX2NetworkAttribute {
217
+ [key: string]: any;
218
+ }
219
+
220
+ export interface CX2Node {
221
+ id: number;
222
+ x?: number; // x coordinate
223
+ y?: number; // y coordinate
224
+ z?: number; // z coordinate (optional)
225
+ v?: Record<string, any>; // attributes
226
+ }
227
+
228
+ export interface CX2Edge {
229
+ id: number;
230
+ s: number; // source node id
231
+ t: number; // target node id
232
+ v?: Record<string, any>; // attributes
233
+ }
234
+
235
+ export interface CX1Edge {
236
+ // CX1 edge structure varies - can be any array structure
237
+ [key: string]: any;
238
+ }
239
+
240
+ export interface CX2NodeBypass {
241
+ id: number; // node id
242
+ v: VisualPropertyTable; // visual properties
243
+ }
244
+
245
+ export interface CX2EdgeBypass {
246
+ id: number; // edge id
247
+ v: VisualPropertyTable; // visual properties
248
+ }
249
+
250
+ // ============================================================================
251
+ // CX2 Visual Property Types - Based on server-side CxVisualProperty class
252
+ // ============================================================================
253
+
254
+ /**
255
+ * Visual Property Mapping Types
256
+ */
257
+ export type VPMappingType = 'DISCRETE' | 'CONTINUOUS' | 'PASSTHROUGH';
258
+
259
+ /**
260
+ * Mapping Definition for visual property mappings
261
+ * Note: Using flexible typing for mapping definitions as they vary by type
262
+ */
263
+ export interface MappingDefinition {
264
+ mapppingList?: Array<Record<string, any>>; // Note: server has typo "mapppingList"
265
+ [key: string]: any; // Allow other mapping definition properties
266
+ }
267
+
268
+ /**
269
+ * Visual Property Mapping structure
270
+ */
271
+ export interface VisualPropertyMapping {
272
+ type: VPMappingType;
273
+ definition: MappingDefinition;
274
+ }
275
+
276
+ /**
277
+ * Visual Property Table - holds visual property values
278
+ * Equivalent to server-side VisualPropertyTable class
279
+ */
280
+ export interface VisualPropertyTable {
281
+ [visualPropertyName: string]: any; // Maps visual property names to their values
282
+ }
283
+
284
+ /**
285
+ * Table Column Visual Style - for individual visual properties
286
+ */
287
+ export interface TableColumnVisualStyle {
288
+ default?: any; // Default value for the visual property
289
+ mapping?: VisualPropertyMapping; // Optional mapping definition
290
+ }
291
+
292
+ /**
293
+ * Default Visual Properties structure
294
+ */
295
+ export interface DefaultVisualProperties {
296
+ edge?: VisualPropertyTable; // Default edge visual properties
297
+ network?: Record<string, any>; // Default network visual properties
298
+ node?: VisualPropertyTable; // Default node visual properties
299
+ }
300
+
301
+ /**
302
+ * CX2 Visual Property - Main visual properties aspect
303
+ * Equivalent to server-side CxVisualProperty class
304
+ */
305
+ export interface CX2VisualProperty {
306
+ default?: DefaultVisualProperties; // Default visual properties
307
+ edgeMapping?: Record<string, VisualPropertyMapping>; // Edge visual property mappings
308
+ nodeMapping?: Record<string, VisualPropertyMapping>; // Node visual property mappings
309
+ }
310
+
311
+ export interface CX2Status {
312
+ error?: string;
313
+ success?: boolean;
314
+ }
315
+
316
+ // ============================================================================
317
+ // Search Types
318
+ // ============================================================================
319
+
320
+ export interface SearchResult {
321
+ numFound: number;
322
+ start: number;
323
+ networks: NetworkSummaryV2[] | NetworkSummaryV3[];
324
+ }
325
+
326
+ export interface SearchParameters {
327
+ searchString?: string;
328
+ accountName?: string;
329
+ permission?: string;
330
+ includeGroups?: boolean;
331
+ admin?: string;
332
+ start?: number;
333
+ size?: number;
334
+ source?: string;
335
+ }
336
+
337
+ // ============================================================================
338
+ // File/Export Types
339
+ // ============================================================================
340
+
341
+ export interface ExportFormat {
342
+ format: 'CX' | 'CX2' | 'XGMML' | 'SIF' | 'GRAPHML';
343
+ version?: string;
344
+ }
345
+
346
+ export interface ExportRequest {
347
+ networkUUID: string;
348
+ format: ExportFormat;
349
+ accesskey?: string;
350
+ }
351
+
352
+ // ============================================================================
353
+ // Task/Status Types
354
+ // ============================================================================
355
+
356
+ export interface Task {
357
+ externalId: string;
358
+ taskType: string;
359
+ status: 'submitted' | 'processing' | 'completed' | 'failed';
360
+ progress?: number;
361
+ message?: string;
362
+ resource?: string;
363
+ startTime?: number;
364
+ finishTime?: number;
365
+ attributes?: Record<string, any>;
366
+ }
367
+
368
+ // ============================================================================
369
+ // API Configuration Types
370
+ // ============================================================================
371
+
372
+ export interface NDExClientConfig {
373
+ baseURL?: string;
374
+ timeout?: number;
375
+ retries?: number;
376
+ retryDelay?: number;
377
+ debug?: boolean;
378
+ headers?: Record<string, string>;
379
+ auth?: BasicAuth | OAuthAuth; // Simplified to 2 authentication options
380
+ }
381
+
382
+ export interface APIResponse<T = any> {
383
+ data?: T;
384
+ errorCode?: string;
385
+ message?: string;
386
+ description?: string;
387
+ stackTrace?: string;
388
+ timeStamp?: number;
389
+ }
390
+
391
+ export interface APIError {
392
+ errorCode: string;
393
+ message: string;
394
+ description?: string;
395
+ stackTrace?: string;
396
+ timeStamp?: number;
397
+ }
398
+
399
+ // ============================================================================
400
+ // Service Types
401
+ // ============================================================================
402
+
403
+
404
+ /**
405
+ * Base error class for all NDEx API errors
406
+ */
407
+ export class NDExError extends Error {
408
+ constructor(
409
+ message: string,
410
+ public statusCode?: number,
411
+ public errorCode?: string,
412
+ public description?: string
413
+ ) {
414
+ super(message);
415
+ this.name = 'NDExError';
416
+ }
417
+ }
418
+
419
+ /**
420
+ * Error thrown when network or request fails
421
+ */
422
+ export class NDExNetworkError extends NDExError {
423
+ constructor(message: string, public originalError?: Error) {
424
+ super(message, undefined, 'NETWORK_ERROR');
425
+ this.name = 'NDExNetworkError';
426
+ }
427
+ }
428
+
429
+ /**
430
+ * Error thrown when authentication fails
431
+ */
432
+ export class NDExAuthError extends NDExError {
433
+ constructor(message: string = 'Authentication failed', statusCode: number = 401) {
434
+ super(message, statusCode, 'AUTH_ERROR');
435
+ this.name = 'NDExAuthError';
436
+ }
437
+ }
438
+
439
+ /**
440
+ * Error thrown when requested resource is not found
441
+ */
442
+ export class NDExNotFoundError extends NDExError {
443
+ constructor(message: string = 'Resource not found', statusCode: number = 404) {
444
+ super(message, statusCode, 'NOT_FOUND');
445
+ this.name = 'NDExNotFoundError';
446
+ }
447
+ }
448
+
449
+ /**
450
+ * Error thrown when request validation fails
451
+ */
452
+ export class NDExValidationError extends NDExError {
453
+ constructor(message: string, statusCode: number = 400) {
454
+ super(message, statusCode, 'VALIDATION_ERROR');
455
+ this.name = 'NDExValidationError';
456
+ }
457
+ }
458
+
459
+ /**
460
+ * Error thrown when server encounters an internal error
461
+ */
462
+ export class NDExServerError extends NDExError {
463
+ constructor(message: string = 'Internal server error', statusCode: number = 500) {
464
+ super(message, statusCode, 'SERVER_ERROR');
465
+ this.name = 'NDExServerError';
466
+ }
467
+ }
468
+
469
+ // ============================================================================
470
+ // Utility Types
471
+ // ============================================================================
472
+
473
+ export type UUID = string;
474
+ export type Timestamp = number;
475
+
476
+ // Allow flexible typing for gradual migration
477
+ export type NDExAny = any;
478
+
479
+ // Common parameter types
480
+ export interface PaginationParams {
481
+ start?: number;
482
+ size?: number;
483
+ }
484
+
485
+ export interface AccessParams {
486
+ accesskey?: string;
487
+ }
488
+
489
+ // ============================================================================
490
+ // Workspace Types
491
+ // ============================================================================
492
+
493
+ /**
494
+ * CyWeb workspace object structure
495
+ */
496
+ export interface CyWebWorkspace {
497
+ externalId?: string;
498
+ name: string;
499
+ description?: string;
500
+ networkIds?: string[];
501
+ [key: string]: any; // Allow additional properties
502
+ }
503
+
504
+ /**
505
+ * Network access key response structure
506
+ */
507
+ export interface AccessKeyResponse {
508
+ accessKey: string | null;
509
+ }
510
+
511
+ /**
512
+ * Valid actions for updating access keys
513
+ */
514
+ export type AccessKeyAction = 'enable' | 'disable';
515
+
516
+ /**
517
+ * NDEx object update status - returned from network creation and update operations
518
+ * Corresponds to server-side NdexObjectUpdateStatus class
519
+ */
520
+ export interface NDExObjectUpdateStatus {
521
+ uuid: string;
522
+ modificationTime: number; // Timestamp in milliseconds
523
+ }
524
+