@robosystems/client 0.2.15 → 0.2.17

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 (47) hide show
  1. package/extensions/FileClient.d.ts +57 -0
  2. package/extensions/{TableIngestClient.js → FileClient.js} +55 -77
  3. package/extensions/{TableIngestClient.ts → FileClient.ts} +67 -122
  4. package/extensions/MaterializationClient.d.ts +51 -0
  5. package/extensions/MaterializationClient.js +107 -0
  6. package/extensions/MaterializationClient.ts +163 -0
  7. package/extensions/TableClient.d.ts +38 -0
  8. package/extensions/TableClient.js +92 -0
  9. package/extensions/TableClient.ts +132 -0
  10. package/extensions/hooks.d.ts +9 -11
  11. package/extensions/hooks.js +21 -56
  12. package/extensions/hooks.ts +30 -79
  13. package/extensions/index.d.ts +14 -4
  14. package/extensions/index.js +32 -5
  15. package/extensions/index.test.ts +10 -2
  16. package/extensions/index.ts +46 -5
  17. package/package.json +1 -4
  18. package/sdk/sdk.gen.d.ts +14 -14
  19. package/sdk/sdk.gen.js +14 -14
  20. package/sdk/sdk.gen.ts +14 -14
  21. package/sdk/types.gen.d.ts +7 -7
  22. package/sdk/types.gen.ts +7 -7
  23. package/sdk-extensions/FileClient.d.ts +57 -0
  24. package/sdk-extensions/{TableIngestClient.js → FileClient.js} +55 -77
  25. package/sdk-extensions/{TableIngestClient.ts → FileClient.ts} +67 -122
  26. package/sdk-extensions/MaterializationClient.d.ts +51 -0
  27. package/sdk-extensions/MaterializationClient.js +107 -0
  28. package/sdk-extensions/MaterializationClient.ts +163 -0
  29. package/sdk-extensions/TableClient.d.ts +38 -0
  30. package/sdk-extensions/TableClient.js +92 -0
  31. package/sdk-extensions/TableClient.ts +132 -0
  32. package/sdk-extensions/hooks.d.ts +9 -11
  33. package/sdk-extensions/hooks.js +21 -56
  34. package/sdk-extensions/hooks.ts +30 -79
  35. package/sdk-extensions/index.d.ts +14 -4
  36. package/sdk-extensions/index.js +32 -5
  37. package/sdk-extensions/index.test.ts +10 -2
  38. package/sdk-extensions/index.ts +46 -5
  39. package/sdk.gen.d.ts +14 -14
  40. package/sdk.gen.js +14 -14
  41. package/sdk.gen.ts +14 -14
  42. package/types.gen.d.ts +7 -7
  43. package/types.gen.ts +7 -7
  44. package/extensions/TableIngestClient.d.ts +0 -75
  45. package/extensions/TableIngestClient.test.ts +0 -304
  46. package/sdk-extensions/TableIngestClient.d.ts +0 -75
  47. package/sdk-extensions/TableIngestClient.test.ts +0 -304
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MaterializationClient = void 0;
5
+ /**
6
+ * Materialization Client for RoboSystems API
7
+ *
8
+ * Manages graph materialization from DuckDB staging tables.
9
+ * Treats the graph database as a materialized view of the mutable DuckDB data lake.
10
+ */
11
+ const sdk_gen_1 = require("../sdk.gen");
12
+ class MaterializationClient {
13
+ constructor(config) {
14
+ this.config = config;
15
+ }
16
+ /**
17
+ * Materialize graph from DuckDB staging tables
18
+ *
19
+ * Rebuilds the complete graph database from the current state of DuckDB
20
+ * staging tables. Automatically discovers all tables, materializes them in
21
+ * the correct order (nodes before relationships), and clears the staleness flag.
22
+ */
23
+ async materialize(graphId, options = {}) {
24
+ try {
25
+ options.onProgress?.('Starting graph materialization...');
26
+ const request = {
27
+ ignore_errors: options.ignoreErrors ?? true,
28
+ rebuild: options.rebuild ?? false,
29
+ force: options.force ?? false,
30
+ };
31
+ const response = await (0, sdk_gen_1.materializeGraph)({
32
+ path: { graph_id: graphId },
33
+ body: request,
34
+ });
35
+ if (response.error || !response.data) {
36
+ return {
37
+ status: 'failed',
38
+ wasStale: false,
39
+ tablesMaterialized: [],
40
+ totalRows: 0,
41
+ executionTimeMs: 0,
42
+ message: `Failed to materialize graph: ${response.error}`,
43
+ success: false,
44
+ error: `Failed to materialize graph: ${response.error}`,
45
+ };
46
+ }
47
+ const result = response.data;
48
+ options.onProgress?.(`✅ Materialization complete: ${result.tables_materialized?.length || 0} tables, ` +
49
+ `${result.total_rows?.toLocaleString() || 0} rows in ${result.execution_time_ms?.toFixed(2) || 0}ms`);
50
+ return {
51
+ status: result.status,
52
+ wasStale: result.was_stale,
53
+ staleReason: result.stale_reason,
54
+ tablesMaterialized: result.tables_materialized || [],
55
+ totalRows: result.total_rows || 0,
56
+ executionTimeMs: result.execution_time_ms || 0,
57
+ message: result.message || 'Materialization complete',
58
+ success: true,
59
+ };
60
+ }
61
+ catch (error) {
62
+ return {
63
+ status: 'failed',
64
+ wasStale: false,
65
+ tablesMaterialized: [],
66
+ totalRows: 0,
67
+ executionTimeMs: 0,
68
+ message: error instanceof Error ? error.message : String(error),
69
+ success: false,
70
+ error: error instanceof Error ? error.message : String(error),
71
+ };
72
+ }
73
+ }
74
+ /**
75
+ * Get current materialization status for the graph
76
+ *
77
+ * Shows whether the graph is stale (DuckDB has changes not yet in graph database),
78
+ * when it was last materialized, and how long since last materialization.
79
+ */
80
+ async status(graphId) {
81
+ try {
82
+ const response = await (0, sdk_gen_1.getMaterializationStatus)({
83
+ path: { graph_id: graphId },
84
+ });
85
+ if (response.error || !response.data) {
86
+ console.error('Failed to get materialization status:', response.error);
87
+ return null;
88
+ }
89
+ const status = response.data;
90
+ return {
91
+ graphId: status.graph_id,
92
+ isStale: status.is_stale,
93
+ staleReason: status.stale_reason,
94
+ staleSince: status.stale_since,
95
+ lastMaterializedAt: status.last_materialized_at,
96
+ materializationCount: status.materialization_count || 0,
97
+ hoursSinceMaterialization: status.hours_since_materialization,
98
+ message: status.message,
99
+ };
100
+ }
101
+ catch (error) {
102
+ console.error('Failed to get materialization status:', error);
103
+ return null;
104
+ }
105
+ }
106
+ }
107
+ exports.MaterializationClient = MaterializationClient;
@@ -0,0 +1,163 @@
1
+ 'use client'
2
+
3
+ /**
4
+ * Materialization Client for RoboSystems API
5
+ *
6
+ * Manages graph materialization from DuckDB staging tables.
7
+ * Treats the graph database as a materialized view of the mutable DuckDB data lake.
8
+ */
9
+
10
+ import { getMaterializationStatus, materializeGraph } from '../sdk.gen'
11
+ import type { MaterializeRequest } from '../types.gen'
12
+
13
+ export interface MaterializationOptions {
14
+ ignoreErrors?: boolean
15
+ rebuild?: boolean
16
+ force?: boolean
17
+ onProgress?: (message: string) => void
18
+ }
19
+
20
+ export interface MaterializationResult {
21
+ status: string
22
+ wasStale: boolean
23
+ staleReason?: string
24
+ tablesMaterialized: string[]
25
+ totalRows: number
26
+ executionTimeMs: number
27
+ message: string
28
+ success: boolean
29
+ error?: string
30
+ }
31
+
32
+ export interface MaterializationStatus {
33
+ graphId: string
34
+ isStale: boolean
35
+ staleReason?: string
36
+ staleSince?: string
37
+ lastMaterializedAt?: string
38
+ materializationCount: number
39
+ hoursSinceMaterialization?: number
40
+ message: string
41
+ }
42
+
43
+ export class MaterializationClient {
44
+ private config: {
45
+ baseUrl: string
46
+ credentials?: 'include' | 'same-origin' | 'omit'
47
+ headers?: Record<string, string>
48
+ token?: string
49
+ }
50
+
51
+ constructor(config: {
52
+ baseUrl: string
53
+ credentials?: 'include' | 'same-origin' | 'omit'
54
+ headers?: Record<string, string>
55
+ token?: string
56
+ }) {
57
+ this.config = config
58
+ }
59
+
60
+ /**
61
+ * Materialize graph from DuckDB staging tables
62
+ *
63
+ * Rebuilds the complete graph database from the current state of DuckDB
64
+ * staging tables. Automatically discovers all tables, materializes them in
65
+ * the correct order (nodes before relationships), and clears the staleness flag.
66
+ */
67
+ async materialize(
68
+ graphId: string,
69
+ options: MaterializationOptions = {}
70
+ ): Promise<MaterializationResult> {
71
+ try {
72
+ options.onProgress?.('Starting graph materialization...')
73
+
74
+ const request: MaterializeRequest = {
75
+ ignore_errors: options.ignoreErrors ?? true,
76
+ rebuild: options.rebuild ?? false,
77
+ force: options.force ?? false,
78
+ }
79
+
80
+ const response = await materializeGraph({
81
+ path: { graph_id: graphId },
82
+ body: request,
83
+ })
84
+
85
+ if (response.error || !response.data) {
86
+ return {
87
+ status: 'failed',
88
+ wasStale: false,
89
+ tablesMaterialized: [],
90
+ totalRows: 0,
91
+ executionTimeMs: 0,
92
+ message: `Failed to materialize graph: ${response.error}`,
93
+ success: false,
94
+ error: `Failed to materialize graph: ${response.error}`,
95
+ }
96
+ }
97
+
98
+ const result = response.data as any
99
+
100
+ options.onProgress?.(
101
+ `✅ Materialization complete: ${result.tables_materialized?.length || 0} tables, ` +
102
+ `${result.total_rows?.toLocaleString() || 0} rows in ${result.execution_time_ms?.toFixed(2) || 0}ms`
103
+ )
104
+
105
+ return {
106
+ status: result.status,
107
+ wasStale: result.was_stale,
108
+ staleReason: result.stale_reason,
109
+ tablesMaterialized: result.tables_materialized || [],
110
+ totalRows: result.total_rows || 0,
111
+ executionTimeMs: result.execution_time_ms || 0,
112
+ message: result.message || 'Materialization complete',
113
+ success: true,
114
+ }
115
+ } catch (error) {
116
+ return {
117
+ status: 'failed',
118
+ wasStale: false,
119
+ tablesMaterialized: [],
120
+ totalRows: 0,
121
+ executionTimeMs: 0,
122
+ message: error instanceof Error ? error.message : String(error),
123
+ success: false,
124
+ error: error instanceof Error ? error.message : String(error),
125
+ }
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Get current materialization status for the graph
131
+ *
132
+ * Shows whether the graph is stale (DuckDB has changes not yet in graph database),
133
+ * when it was last materialized, and how long since last materialization.
134
+ */
135
+ async status(graphId: string): Promise<MaterializationStatus | null> {
136
+ try {
137
+ const response = await getMaterializationStatus({
138
+ path: { graph_id: graphId },
139
+ })
140
+
141
+ if (response.error || !response.data) {
142
+ console.error('Failed to get materialization status:', response.error)
143
+ return null
144
+ }
145
+
146
+ const status = response.data as any
147
+
148
+ return {
149
+ graphId: status.graph_id,
150
+ isStale: status.is_stale,
151
+ staleReason: status.stale_reason,
152
+ staleSince: status.stale_since,
153
+ lastMaterializedAt: status.last_materialized_at,
154
+ materializationCount: status.materialization_count || 0,
155
+ hoursSinceMaterialization: status.hours_since_materialization,
156
+ message: status.message,
157
+ }
158
+ } catch (error) {
159
+ console.error('Failed to get materialization status:', error)
160
+ return null
161
+ }
162
+ }
163
+ }
@@ -0,0 +1,38 @@
1
+ export interface TableInfo {
2
+ tableName: string;
3
+ rowCount: number;
4
+ fileCount: number;
5
+ totalSizeBytes: number;
6
+ s3Location?: string | null;
7
+ }
8
+ export interface TableQueryResult {
9
+ columns: string[];
10
+ rows: any[][];
11
+ rowCount: number;
12
+ executionTimeMs: number;
13
+ success: boolean;
14
+ error?: string;
15
+ }
16
+ export declare class TableClient {
17
+ private config;
18
+ constructor(config: {
19
+ baseUrl: string;
20
+ credentials?: 'include' | 'same-origin' | 'omit';
21
+ headers?: Record<string, string>;
22
+ token?: string;
23
+ });
24
+ /**
25
+ * List all DuckDB staging tables in a graph
26
+ */
27
+ list(graphId: string): Promise<TableInfo[]>;
28
+ /**
29
+ * Execute SQL query against DuckDB staging tables
30
+ *
31
+ * Example:
32
+ * const result = await client.tables.query(
33
+ * graphId,
34
+ * "SELECT * FROM Entity WHERE entity_type = 'CORPORATION'"
35
+ * )
36
+ */
37
+ query(graphId: string, sqlQuery: string, limit?: number): Promise<TableQueryResult>;
38
+ }
@@ -0,0 +1,92 @@
1
+ 'use client';
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.TableClient = void 0;
5
+ /**
6
+ * Table Client for RoboSystems API
7
+ *
8
+ * Manages DuckDB staging table operations.
9
+ * Tables provide SQL-queryable staging layer before graph materialization.
10
+ */
11
+ const sdk_gen_1 = require("../sdk.gen");
12
+ class TableClient {
13
+ constructor(config) {
14
+ this.config = config;
15
+ }
16
+ /**
17
+ * List all DuckDB staging tables in a graph
18
+ */
19
+ async list(graphId) {
20
+ try {
21
+ const response = await (0, sdk_gen_1.listTables)({
22
+ path: { graph_id: graphId },
23
+ });
24
+ if (response.error || !response.data) {
25
+ console.error('Failed to list tables:', response.error);
26
+ return [];
27
+ }
28
+ const tableData = response.data;
29
+ return (tableData.tables?.map((table) => ({
30
+ tableName: table.table_name,
31
+ rowCount: table.row_count,
32
+ fileCount: table.file_count || 0,
33
+ totalSizeBytes: table.total_size_bytes || 0,
34
+ s3Location: table.s3_location,
35
+ })) || []);
36
+ }
37
+ catch (error) {
38
+ console.error('Failed to list tables:', error);
39
+ return [];
40
+ }
41
+ }
42
+ /**
43
+ * Execute SQL query against DuckDB staging tables
44
+ *
45
+ * Example:
46
+ * const result = await client.tables.query(
47
+ * graphId,
48
+ * "SELECT * FROM Entity WHERE entity_type = 'CORPORATION'"
49
+ * )
50
+ */
51
+ async query(graphId, sqlQuery, limit) {
52
+ try {
53
+ const finalQuery = limit !== undefined ? `${sqlQuery.replace(/;?\s*$/, '')} LIMIT ${limit}` : sqlQuery;
54
+ const request = {
55
+ sql: finalQuery,
56
+ };
57
+ const response = await (0, sdk_gen_1.queryTables)({
58
+ path: { graph_id: graphId },
59
+ body: request,
60
+ });
61
+ if (response.error || !response.data) {
62
+ return {
63
+ columns: [],
64
+ rows: [],
65
+ rowCount: 0,
66
+ executionTimeMs: 0,
67
+ success: false,
68
+ error: `Query failed: ${response.error}`,
69
+ };
70
+ }
71
+ const result = response.data;
72
+ return {
73
+ columns: result.columns || [],
74
+ rows: result.rows || [],
75
+ rowCount: result.rows?.length || 0,
76
+ executionTimeMs: result.execution_time_ms || 0,
77
+ success: true,
78
+ };
79
+ }
80
+ catch (error) {
81
+ return {
82
+ columns: [],
83
+ rows: [],
84
+ rowCount: 0,
85
+ executionTimeMs: 0,
86
+ success: false,
87
+ error: error instanceof Error ? error.message : String(error),
88
+ };
89
+ }
90
+ }
91
+ }
92
+ exports.TableClient = TableClient;
@@ -0,0 +1,132 @@
1
+ 'use client'
2
+
3
+ /**
4
+ * Table Client for RoboSystems API
5
+ *
6
+ * Manages DuckDB staging table operations.
7
+ * Tables provide SQL-queryable staging layer before graph materialization.
8
+ */
9
+
10
+ import { listTables, queryTables } from '../sdk.gen'
11
+ import type { TableListResponse, TableQueryRequest } from '../types.gen'
12
+
13
+ export interface TableInfo {
14
+ tableName: string
15
+ rowCount: number
16
+ fileCount: number
17
+ totalSizeBytes: number
18
+ s3Location?: string | null
19
+ }
20
+
21
+ export interface TableQueryResult {
22
+ columns: string[]
23
+ rows: any[][]
24
+ rowCount: number
25
+ executionTimeMs: number
26
+ success: boolean
27
+ error?: string
28
+ }
29
+
30
+ export class TableClient {
31
+ private config: {
32
+ baseUrl: string
33
+ credentials?: 'include' | 'same-origin' | 'omit'
34
+ headers?: Record<string, string>
35
+ token?: string
36
+ }
37
+
38
+ constructor(config: {
39
+ baseUrl: string
40
+ credentials?: 'include' | 'same-origin' | 'omit'
41
+ headers?: Record<string, string>
42
+ token?: string
43
+ }) {
44
+ this.config = config
45
+ }
46
+
47
+ /**
48
+ * List all DuckDB staging tables in a graph
49
+ */
50
+ async list(graphId: string): Promise<TableInfo[]> {
51
+ try {
52
+ const response = await listTables({
53
+ path: { graph_id: graphId },
54
+ })
55
+
56
+ if (response.error || !response.data) {
57
+ console.error('Failed to list tables:', response.error)
58
+ return []
59
+ }
60
+
61
+ const tableData = response.data as TableListResponse
62
+
63
+ return (
64
+ tableData.tables?.map((table) => ({
65
+ tableName: table.table_name,
66
+ rowCount: table.row_count,
67
+ fileCount: table.file_count || 0,
68
+ totalSizeBytes: table.total_size_bytes || 0,
69
+ s3Location: table.s3_location,
70
+ })) || []
71
+ )
72
+ } catch (error) {
73
+ console.error('Failed to list tables:', error)
74
+ return []
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Execute SQL query against DuckDB staging tables
80
+ *
81
+ * Example:
82
+ * const result = await client.tables.query(
83
+ * graphId,
84
+ * "SELECT * FROM Entity WHERE entity_type = 'CORPORATION'"
85
+ * )
86
+ */
87
+ async query(graphId: string, sqlQuery: string, limit?: number): Promise<TableQueryResult> {
88
+ try {
89
+ const finalQuery =
90
+ limit !== undefined ? `${sqlQuery.replace(/;?\s*$/, '')} LIMIT ${limit}` : sqlQuery
91
+
92
+ const request: TableQueryRequest = {
93
+ sql: finalQuery,
94
+ }
95
+
96
+ const response = await queryTables({
97
+ path: { graph_id: graphId },
98
+ body: request,
99
+ })
100
+
101
+ if (response.error || !response.data) {
102
+ return {
103
+ columns: [],
104
+ rows: [],
105
+ rowCount: 0,
106
+ executionTimeMs: 0,
107
+ success: false,
108
+ error: `Query failed: ${response.error}`,
109
+ }
110
+ }
111
+
112
+ const result = response.data as any
113
+
114
+ return {
115
+ columns: result.columns || [],
116
+ rows: result.rows || [],
117
+ rowCount: result.rows?.length || 0,
118
+ executionTimeMs: result.execution_time_ms || 0,
119
+ success: true,
120
+ }
121
+ } catch (error) {
122
+ return {
123
+ columns: [],
124
+ rows: [],
125
+ rowCount: 0,
126
+ executionTimeMs: 0,
127
+ success: false,
128
+ error: error instanceof Error ? error.message : String(error),
129
+ }
130
+ }
131
+ }
132
+ }
@@ -1,8 +1,10 @@
1
+ import type { FileInput, FileUploadOptions, FileUploadResult } from './FileClient';
2
+ import type { MaterializationOptions } from './MaterializationClient';
1
3
  import type { OperationProgress, OperationResult } from './OperationClient';
2
4
  import { OperationClient } from './OperationClient';
3
5
  import type { QueryOptions, QueryResult } from './QueryClient';
4
6
  import { QueryClient } from './QueryClient';
5
- import type { FileInput, IngestOptions, UploadOptions, UploadResult } from './TableIngestClient';
7
+ import type { TableInfo } from './TableClient';
6
8
  /**
7
9
  * Hook for executing Cypher queries with loading states and error handling
8
10
  *
@@ -110,11 +112,11 @@ export declare function useSDKClients(): {
110
112
  operations: OperationClient | null;
111
113
  };
112
114
  /**
113
- * Hook for uploading Parquet files to staging tables
115
+ * Hook for uploading Parquet files to staging and materializing graphs
114
116
  *
115
117
  * @example
116
118
  * ```tsx
117
- * const { upload, uploadAndIngest, loading, error, progress } = useTableUpload('graph_123')
119
+ * const { upload, listTables, materialize, loading, error, progress } = useTableUpload('graph_123')
118
120
  *
119
121
  * const handleFileUpload = async (file: File) => {
120
122
  * const result = await upload('Entity', file, {
@@ -129,15 +131,11 @@ export declare function useSDKClients(): {
129
131
  * ```
130
132
  */
131
133
  export declare function useTableUpload(graphId: string): {
132
- upload: (tableName: string, fileOrBuffer: FileInput, options?: UploadOptions) => Promise<UploadResult | null>;
133
- uploadAndIngest: (tableName: string, fileOrBuffer: FileInput, uploadOptions?: UploadOptions, ingestOptions?: IngestOptions) => Promise<{
134
- upload: UploadResult;
135
- ingest: any;
136
- } | null>;
137
- listTables: () => Promise<import("./TableIngestClient").TableInfo[]>;
138
- ingestAllTables: (options?: IngestOptions) => Promise<import("./TableIngestClient").IngestResult>;
134
+ upload: (tableName: string, fileOrBuffer: FileInput, options?: FileUploadOptions) => Promise<FileUploadResult | null>;
135
+ listTables: () => Promise<TableInfo[]>;
136
+ materialize: (options?: MaterializationOptions) => Promise<import("./MaterializationClient").MaterializationResult>;
139
137
  loading: boolean;
140
138
  error: Error;
141
139
  progress: string;
142
- uploadResult: UploadResult;
140
+ uploadResult: FileUploadResult;
143
141
  };