@robosystems/client 0.1.16 → 0.1.18

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.
@@ -7,7 +7,10 @@
7
7
 
8
8
  import { useCallback, useEffect, useRef, useState } from 'react'
9
9
  import { client } from '../client.gen'
10
+ import type { S3CopyRequest } from '../types.gen'
10
11
  import { getSDKExtensionsConfig } from './config'
12
+ import type { CopyOptions, CopyResult } from './CopyClient'
13
+ import { CopyClient } from './CopyClient'
11
14
  import type { OperationProgress, OperationResult } from './OperationClient'
12
15
  import { OperationClient } from './OperationClient'
13
16
  import type { QueryOptions, QueryResult } from './QueryClient'
@@ -404,9 +407,11 @@ export function useMultipleOperations<T = any>() {
404
407
  */
405
408
  export function useSDKClients() {
406
409
  const [clients, setClients] = useState<{
410
+ copy: CopyClient | null
407
411
  query: QueryClient | null
408
412
  operations: OperationClient | null
409
413
  }>({
414
+ copy: null,
410
415
  query: null,
411
416
  operations: null,
412
417
  })
@@ -420,15 +425,18 @@ export function useSDKClients() {
420
425
  headers: sdkConfig.headers,
421
426
  }
422
427
 
428
+ const copyClient = new CopyClient(baseConfig)
423
429
  const queryClient = new QueryClient(baseConfig)
424
430
  const operationsClient = new OperationClient(baseConfig)
425
431
 
426
432
  setClients({
433
+ copy: copyClient,
427
434
  query: queryClient,
428
435
  operations: operationsClient,
429
436
  })
430
437
 
431
438
  return () => {
439
+ copyClient.close()
432
440
  queryClient.close()
433
441
  operationsClient.closeAll()
434
442
  }
@@ -436,3 +444,134 @@ export function useSDKClients() {
436
444
 
437
445
  return clients
438
446
  }
447
+
448
+ /**
449
+ * Hook for copying data from S3 to graph database with progress monitoring
450
+ *
451
+ * @example
452
+ * ```tsx
453
+ * const { copyFromS3, loading, progress, error, result } = useCopy('graph_123')
454
+ *
455
+ * const handleImport = async () => {
456
+ * const result = await copyFromS3({
457
+ * table_name: 'companies',
458
+ * source_type: 's3',
459
+ * s3_uri: 's3://my-bucket/data.csv',
460
+ * aws_access_key_id: 'KEY',
461
+ * aws_secret_access_key: 'SECRET',
462
+ * })
463
+ * }
464
+ * ```
465
+ */
466
+ export function useCopy(graphId: string) {
467
+ const [loading, setLoading] = useState(false)
468
+ const [error, setError] = useState<Error | null>(null)
469
+ const [result, setResult] = useState<CopyResult | null>(null)
470
+ const [progress, setProgress] = useState<{
471
+ message: string
472
+ percent?: number
473
+ } | null>(null)
474
+ const [queuePosition, setQueuePosition] = useState<number | null>(null)
475
+ const clientRef = useRef<CopyClient>(null)
476
+
477
+ // Initialize client
478
+ useEffect(() => {
479
+ const sdkConfig = getSDKExtensionsConfig()
480
+ const clientConfig = client.getConfig()
481
+ clientRef.current = new CopyClient({
482
+ baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
483
+ credentials: sdkConfig.credentials,
484
+ headers: sdkConfig.headers,
485
+ })
486
+
487
+ return () => {
488
+ clientRef.current?.close()
489
+ }
490
+ }, [])
491
+
492
+ const copyFromS3 = useCallback(
493
+ async (request: S3CopyRequest, options?: CopyOptions): Promise<CopyResult | null> => {
494
+ if (!clientRef.current) return null
495
+
496
+ setLoading(true)
497
+ setError(null)
498
+ setResult(null)
499
+ setProgress(null)
500
+ setQueuePosition(null)
501
+
502
+ try {
503
+ const copyResult = await clientRef.current.copyFromS3(graphId, request, {
504
+ ...options,
505
+ onProgress: (message, progressPercent) => {
506
+ setProgress({ message, percent: progressPercent })
507
+ setQueuePosition(null) // Clear queue position when executing
508
+ },
509
+ onQueueUpdate: (position, estimatedWait) => {
510
+ setQueuePosition(position)
511
+ setProgress({
512
+ message: `Queue position: ${position} (est. ${estimatedWait}s)`,
513
+ })
514
+ },
515
+ onWarning: (warning) => {
516
+ console.warn('Copy warning:', warning)
517
+ },
518
+ })
519
+
520
+ setResult(copyResult)
521
+ return copyResult
522
+ } catch (err) {
523
+ const error = err as Error
524
+ setError(error)
525
+ return null
526
+ } finally {
527
+ setLoading(false)
528
+ setQueuePosition(null)
529
+ }
530
+ },
531
+ [graphId]
532
+ )
533
+
534
+ // Simple copy method with retry logic
535
+ const copyWithRetry = useCallback(
536
+ async (request: S3CopyRequest, maxRetries: number = 3): Promise<CopyResult | null> => {
537
+ if (!clientRef.current) return null
538
+
539
+ setLoading(true)
540
+ setError(null)
541
+
542
+ try {
543
+ const result = await clientRef.current.copyWithRetry(graphId, request, 's3', maxRetries, {
544
+ onProgress: (message, progressPercent) => {
545
+ setProgress({ message, percent: progressPercent })
546
+ },
547
+ })
548
+ setResult(result)
549
+ return result
550
+ } catch (err) {
551
+ const error = err as Error
552
+ setError(error)
553
+ return null
554
+ } finally {
555
+ setLoading(false)
556
+ }
557
+ },
558
+ [graphId]
559
+ )
560
+
561
+ // Get statistics from the last copy operation
562
+ const getStatistics = useCallback(() => {
563
+ if (!clientRef.current || !result) return null
564
+ return clientRef.current.calculateStatistics(result)
565
+ }, [result])
566
+
567
+ return {
568
+ copyFromS3,
569
+ copyWithRetry,
570
+ getStatistics,
571
+ loading,
572
+ error,
573
+ result,
574
+ progress,
575
+ queuePosition,
576
+ }
577
+ }
@@ -2,6 +2,7 @@
2
2
  * RoboSystems SDK Extensions
3
3
  * Enhanced clients with SSE support for the RoboSystems API
4
4
  */
5
+ import { CopyClient } from './CopyClient';
5
6
  import { OperationClient } from './OperationClient';
6
7
  import { QueryClient } from './QueryClient';
7
8
  import { SSEClient } from './SSEClient';
@@ -12,6 +13,7 @@ export interface RoboSystemsExtensionConfig {
12
13
  retryDelay?: number;
13
14
  }
14
15
  export declare class RoboSystemsExtensions {
16
+ readonly copy: CopyClient;
15
17
  readonly query: QueryClient;
16
18
  readonly operations: OperationClient;
17
19
  private config;
@@ -29,12 +31,14 @@ export declare class RoboSystemsExtensions {
29
31
  */
30
32
  close(): void;
31
33
  }
34
+ export * from './CopyClient';
32
35
  export * from './OperationClient';
33
36
  export * from './QueryClient';
34
37
  export * from './SSEClient';
35
- export { OperationClient, QueryClient, SSEClient };
36
- export { useMultipleOperations, useOperation, useQuery, useSDKClients, useStreamingQuery, } from './hooks';
38
+ export { CopyClient, OperationClient, QueryClient, SSEClient };
39
+ export { useCopy, useMultipleOperations, useOperation, useQuery, useSDKClients, useStreamingQuery, } from './hooks';
37
40
  export declare const extensions: {
41
+ readonly copy: CopyClient;
38
42
  readonly query: QueryClient;
39
43
  readonly operations: OperationClient;
40
44
  monitorOperation: (operationId: string, onProgress?: (progress: any) => void) => Promise<any>;
@@ -44,3 +48,4 @@ export declare const extensions: {
44
48
  export declare const monitorOperation: (operationId: string, onProgress?: (progress: any) => void) => Promise<any>;
45
49
  export declare const executeQuery: (graphId: string, query: string, parameters?: Record<string, any>) => Promise<import("./QueryClient").QueryResult>;
46
50
  export declare const streamQuery: (graphId: string, query: string, parameters?: Record<string, any>, chunkSize?: number) => AsyncIterableIterator<any>;
51
+ export declare const copyFromS3: (graphId: string, tableName: string, s3Uri: string, accessKeyId: string, secretAccessKey: string, options?: Parameters<CopyClient["copyS3"]>[5]) => Promise<import("./CopyClient").CopyResult>;
@@ -18,8 +18,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.streamQuery = exports.executeQuery = exports.monitorOperation = exports.extensions = exports.useStreamingQuery = exports.useSDKClients = exports.useQuery = exports.useOperation = exports.useMultipleOperations = exports.SSEClient = exports.QueryClient = exports.OperationClient = exports.RoboSystemsExtensions = void 0;
21
+ exports.copyFromS3 = exports.streamQuery = exports.executeQuery = exports.monitorOperation = exports.extensions = exports.useStreamingQuery = exports.useSDKClients = exports.useQuery = exports.useOperation = exports.useMultipleOperations = exports.useCopy = exports.SSEClient = exports.QueryClient = exports.OperationClient = exports.CopyClient = exports.RoboSystemsExtensions = void 0;
22
22
  const client_gen_1 = require("../client.gen");
23
+ const CopyClient_1 = require("./CopyClient");
24
+ Object.defineProperty(exports, "CopyClient", { enumerable: true, get: function () { return CopyClient_1.CopyClient; } });
23
25
  const OperationClient_1 = require("./OperationClient");
24
26
  Object.defineProperty(exports, "OperationClient", { enumerable: true, get: function () { return OperationClient_1.OperationClient; } });
25
27
  const QueryClient_1 = require("./QueryClient");
@@ -36,6 +38,10 @@ class RoboSystemsExtensions {
36
38
  maxRetries: config.maxRetries || 5,
37
39
  retryDelay: config.retryDelay || 1000,
38
40
  };
41
+ this.copy = new CopyClient_1.CopyClient({
42
+ baseUrl: this.config.baseUrl,
43
+ credentials: this.config.credentials,
44
+ });
39
45
  this.query = new QueryClient_1.QueryClient({
40
46
  baseUrl: this.config.baseUrl,
41
47
  credentials: this.config.credentials,
@@ -66,17 +72,20 @@ class RoboSystemsExtensions {
66
72
  * Clean up all active connections
67
73
  */
68
74
  close() {
75
+ this.copy.close();
69
76
  this.query.close();
70
77
  this.operations.closeAll();
71
78
  }
72
79
  }
73
80
  exports.RoboSystemsExtensions = RoboSystemsExtensions;
74
81
  // Export all types and classes
82
+ __exportStar(require("./CopyClient"), exports);
75
83
  __exportStar(require("./OperationClient"), exports);
76
84
  __exportStar(require("./QueryClient"), exports);
77
85
  __exportStar(require("./SSEClient"), exports);
78
86
  // Export React hooks
79
87
  var hooks_1 = require("./hooks");
88
+ Object.defineProperty(exports, "useCopy", { enumerable: true, get: function () { return hooks_1.useCopy; } });
80
89
  Object.defineProperty(exports, "useMultipleOperations", { enumerable: true, get: function () { return hooks_1.useMultipleOperations; } });
81
90
  Object.defineProperty(exports, "useOperation", { enumerable: true, get: function () { return hooks_1.useOperation; } });
82
91
  Object.defineProperty(exports, "useQuery", { enumerable: true, get: function () { return hooks_1.useQuery; } });
@@ -91,6 +100,9 @@ function getExtensions() {
91
100
  return _extensions;
92
101
  }
93
102
  exports.extensions = {
103
+ get copy() {
104
+ return getExtensions().copy;
105
+ },
94
106
  get query() {
95
107
  return getExtensions().query;
96
108
  },
@@ -108,3 +120,5 @@ const executeQuery = (graphId, query, parameters) => getExtensions().query.query
108
120
  exports.executeQuery = executeQuery;
109
121
  const streamQuery = (graphId, query, parameters, chunkSize) => getExtensions().query.streamQuery(graphId, query, parameters, chunkSize);
110
122
  exports.streamQuery = streamQuery;
123
+ const copyFromS3 = (graphId, tableName, s3Uri, accessKeyId, secretAccessKey, options) => getExtensions().copy.copyS3(graphId, tableName, s3Uri, accessKeyId, secretAccessKey, options);
124
+ exports.copyFromS3 = copyFromS3;
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { client } from '../client.gen'
7
+ import { CopyClient } from './CopyClient'
7
8
  import { OperationClient } from './OperationClient'
8
9
  import { QueryClient } from './QueryClient'
9
10
  import { SSEClient } from './SSEClient'
@@ -16,6 +17,7 @@ export interface RoboSystemsExtensionConfig {
16
17
  }
17
18
 
18
19
  export class RoboSystemsExtensions {
20
+ public readonly copy: CopyClient
19
21
  public readonly query: QueryClient
20
22
  public readonly operations: OperationClient
21
23
  private config: Required<RoboSystemsExtensionConfig>
@@ -31,6 +33,11 @@ export class RoboSystemsExtensions {
31
33
  retryDelay: config.retryDelay || 1000,
32
34
  }
33
35
 
36
+ this.copy = new CopyClient({
37
+ baseUrl: this.config.baseUrl,
38
+ credentials: this.config.credentials,
39
+ })
40
+
34
41
  this.query = new QueryClient({
35
42
  baseUrl: this.config.baseUrl,
36
43
  credentials: this.config.credentials,
@@ -65,19 +72,22 @@ export class RoboSystemsExtensions {
65
72
  * Clean up all active connections
66
73
  */
67
74
  close(): void {
75
+ this.copy.close()
68
76
  this.query.close()
69
77
  this.operations.closeAll()
70
78
  }
71
79
  }
72
80
 
73
81
  // Export all types and classes
82
+ export * from './CopyClient'
74
83
  export * from './OperationClient'
75
84
  export * from './QueryClient'
76
85
  export * from './SSEClient'
77
- export { OperationClient, QueryClient, SSEClient }
86
+ export { CopyClient, OperationClient, QueryClient, SSEClient }
78
87
 
79
88
  // Export React hooks
80
89
  export {
90
+ useCopy,
81
91
  useMultipleOperations,
82
92
  useOperation,
83
93
  useQuery,
@@ -96,6 +106,9 @@ function getExtensions(): RoboSystemsExtensions {
96
106
  }
97
107
 
98
108
  export const extensions = {
109
+ get copy() {
110
+ return getExtensions().copy
111
+ },
99
112
  get query() {
100
113
  return getExtensions().query
101
114
  },
@@ -121,3 +134,12 @@ export const streamQuery = (
121
134
  parameters?: Record<string, any>,
122
135
  chunkSize?: number
123
136
  ) => getExtensions().query.streamQuery(graphId, query, parameters, chunkSize)
137
+
138
+ export const copyFromS3 = (
139
+ graphId: string,
140
+ tableName: string,
141
+ s3Uri: string,
142
+ accessKeyId: string,
143
+ secretAccessKey: string,
144
+ options?: Parameters<CopyClient['copyS3']>[5]
145
+ ) => getExtensions().copy.copyS3(graphId, tableName, s3Uri, accessKeyId, secretAccessKey, options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/client",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "TypeScript client library for RoboSystems Financial Knowledge Graph API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",