@robosystems/client 0.2.43 → 0.2.45
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/extensions/LedgerClient.d.ts +88 -0
- package/extensions/LedgerClient.js +143 -0
- package/extensions/LedgerClient.ts +267 -0
- package/extensions/ReportClient.d.ts +14 -6
- package/extensions/ReportClient.js +19 -15
- package/extensions/ReportClient.ts +37 -21
- package/extensions/hooks.d.ts +1 -40
- package/extensions/hooks.js +0 -134
- package/extensions/hooks.ts +0 -156
- package/extensions/index.d.ts +2 -24
- package/extensions/index.js +1 -65
- package/extensions/index.test.ts +4 -38
- package/extensions/index.ts +0 -78
- package/index.ts +2 -2
- package/package.json +1 -1
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +9 -6
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +33 -34
- package/sdk/sdk.gen.js +68 -46
- package/sdk/sdk.gen.ts +66 -44
- package/sdk/types.gen.d.ts +709 -278
- package/sdk/types.gen.ts +730 -270
- package/sdk-extensions/LedgerClient.d.ts +88 -0
- package/sdk-extensions/LedgerClient.js +143 -0
- package/sdk-extensions/LedgerClient.ts +267 -0
- package/sdk-extensions/ReportClient.d.ts +14 -6
- package/sdk-extensions/ReportClient.js +19 -15
- package/sdk-extensions/ReportClient.ts +37 -21
- package/sdk-extensions/hooks.d.ts +1 -40
- package/sdk-extensions/hooks.js +0 -134
- package/sdk-extensions/hooks.ts +0 -156
- package/sdk-extensions/index.d.ts +2 -24
- package/sdk-extensions/index.js +1 -65
- package/sdk-extensions/index.test.ts +4 -38
- package/sdk-extensions/index.ts +0 -78
- package/sdk.gen.d.ts +33 -34
- package/sdk.gen.js +68 -46
- package/sdk.gen.ts +66 -44
- package/types.gen.d.ts +709 -278
- package/types.gen.ts +730 -270
- package/extensions/DocumentClient.d.ts +0 -102
- package/extensions/DocumentClient.js +0 -176
- package/extensions/DocumentClient.ts +0 -297
- package/extensions/FileClient.d.ts +0 -57
- package/extensions/FileClient.js +0 -246
- package/extensions/FileClient.ts +0 -330
- package/extensions/GraphClient.d.ts +0 -91
- package/extensions/GraphClient.js +0 -244
- package/extensions/GraphClient.test.ts +0 -455
- package/extensions/GraphClient.ts +0 -371
- package/extensions/MaterializationClient.d.ts +0 -61
- package/extensions/MaterializationClient.js +0 -157
- package/extensions/MaterializationClient.ts +0 -223
- package/extensions/TableClient.d.ts +0 -38
- package/extensions/TableClient.js +0 -92
- package/extensions/TableClient.ts +0 -132
- package/sdk-extensions/DocumentClient.d.ts +0 -102
- package/sdk-extensions/DocumentClient.js +0 -176
- package/sdk-extensions/DocumentClient.ts +0 -297
- package/sdk-extensions/FileClient.d.ts +0 -57
- package/sdk-extensions/FileClient.js +0 -246
- package/sdk-extensions/FileClient.ts +0 -330
- package/sdk-extensions/GraphClient.d.ts +0 -91
- package/sdk-extensions/GraphClient.js +0 -244
- package/sdk-extensions/GraphClient.test.ts +0 -455
- package/sdk-extensions/GraphClient.ts +0 -371
- package/sdk-extensions/MaterializationClient.d.ts +0 -61
- package/sdk-extensions/MaterializationClient.js +0 -157
- package/sdk-extensions/MaterializationClient.ts +0 -223
- package/sdk-extensions/TableClient.d.ts +0 -38
- package/sdk-extensions/TableClient.js +0 -92
- package/sdk-extensions/TableClient.ts +0 -132
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Materialization Client for RoboSystems API
|
|
5
|
-
*
|
|
6
|
-
* Manages graph materialization from DuckDB staging tables.
|
|
7
|
-
* Submits materialization jobs to Dagster and monitors progress via SSE.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { getMaterializationStatus, materializeGraph } from '../sdk/sdk.gen'
|
|
11
|
-
import type { MaterializeRequest } from '../sdk/types.gen'
|
|
12
|
-
import { OperationClient, type OperationResult } from './OperationClient'
|
|
13
|
-
|
|
14
|
-
export interface MaterializationOptions {
|
|
15
|
-
ignoreErrors?: boolean
|
|
16
|
-
rebuild?: boolean
|
|
17
|
-
force?: boolean
|
|
18
|
-
timeout?: number // Default 10 minutes
|
|
19
|
-
onProgress?: (message: string) => void
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface MaterializationResult {
|
|
23
|
-
status: string
|
|
24
|
-
wasStale: boolean
|
|
25
|
-
staleReason?: string
|
|
26
|
-
tablesMaterialized: string[]
|
|
27
|
-
totalRows: number
|
|
28
|
-
executionTimeMs: number
|
|
29
|
-
message: string
|
|
30
|
-
success: boolean
|
|
31
|
-
error?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface MaterializationStatus {
|
|
35
|
-
graphId: string
|
|
36
|
-
isStale: boolean
|
|
37
|
-
staleReason?: string
|
|
38
|
-
staleSince?: string
|
|
39
|
-
lastMaterializedAt?: string
|
|
40
|
-
materializationCount: number
|
|
41
|
-
hoursSinceMaterialization?: number
|
|
42
|
-
message: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class MaterializationClient {
|
|
46
|
-
private config: {
|
|
47
|
-
baseUrl: string
|
|
48
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
49
|
-
headers?: Record<string, string>
|
|
50
|
-
token?: string
|
|
51
|
-
}
|
|
52
|
-
private operationClient: OperationClient
|
|
53
|
-
|
|
54
|
-
constructor(config: {
|
|
55
|
-
baseUrl: string
|
|
56
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
57
|
-
headers?: Record<string, string>
|
|
58
|
-
token?: string
|
|
59
|
-
}) {
|
|
60
|
-
this.config = config
|
|
61
|
-
this.operationClient = new OperationClient(config)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Materialize graph from DuckDB staging tables
|
|
66
|
-
*
|
|
67
|
-
* Submits a materialization job to Dagster and monitors progress via SSE.
|
|
68
|
-
* The operation runs asynchronously on the server but this method waits
|
|
69
|
-
* for completion and returns the final result.
|
|
70
|
-
*/
|
|
71
|
-
async materialize(
|
|
72
|
-
graphId: string,
|
|
73
|
-
options: MaterializationOptions = {}
|
|
74
|
-
): Promise<MaterializationResult> {
|
|
75
|
-
try {
|
|
76
|
-
options.onProgress?.('Submitting materialization job...')
|
|
77
|
-
|
|
78
|
-
const request: MaterializeRequest = {
|
|
79
|
-
ignore_errors: options.ignoreErrors ?? true,
|
|
80
|
-
rebuild: options.rebuild ?? false,
|
|
81
|
-
force: options.force ?? false,
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const response = await materializeGraph({
|
|
85
|
-
path: { graph_id: graphId },
|
|
86
|
-
body: request,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
if (response.error || !response.data) {
|
|
90
|
-
return {
|
|
91
|
-
status: 'failed',
|
|
92
|
-
wasStale: false,
|
|
93
|
-
tablesMaterialized: [],
|
|
94
|
-
totalRows: 0,
|
|
95
|
-
executionTimeMs: 0,
|
|
96
|
-
message: `Failed to materialize graph: ${response.error}`,
|
|
97
|
-
success: false,
|
|
98
|
-
error: `Failed to materialize graph: ${response.error}`,
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const queuedResponse = response.data as { operation_id: string; message: string }
|
|
103
|
-
const operationId = queuedResponse.operation_id
|
|
104
|
-
|
|
105
|
-
options.onProgress?.(`Materialization queued (operation: ${operationId})`)
|
|
106
|
-
|
|
107
|
-
// Monitor the operation via SSE until completion
|
|
108
|
-
const opResult = await this.operationClient.monitorOperation(operationId, {
|
|
109
|
-
timeout: (options.timeout ?? 600) * 1000, // Convert to milliseconds, 10 minute default
|
|
110
|
-
onProgress: (progress) => {
|
|
111
|
-
if (options.onProgress) {
|
|
112
|
-
let msg = progress.message
|
|
113
|
-
if (progress.progressPercent !== undefined) {
|
|
114
|
-
msg += ` (${progress.progressPercent.toFixed(0)}%)`
|
|
115
|
-
}
|
|
116
|
-
options.onProgress(msg)
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// Convert operation result to materialization result
|
|
122
|
-
return this.convertOperationResult(opResult, options)
|
|
123
|
-
} catch (error) {
|
|
124
|
-
return {
|
|
125
|
-
status: 'failed',
|
|
126
|
-
wasStale: false,
|
|
127
|
-
tablesMaterialized: [],
|
|
128
|
-
totalRows: 0,
|
|
129
|
-
executionTimeMs: 0,
|
|
130
|
-
message: error instanceof Error ? error.message : String(error),
|
|
131
|
-
success: false,
|
|
132
|
-
error: error instanceof Error ? error.message : String(error),
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Convert SSE operation result to MaterializationResult
|
|
139
|
-
*/
|
|
140
|
-
private convertOperationResult(
|
|
141
|
-
opResult: OperationResult,
|
|
142
|
-
options: MaterializationOptions
|
|
143
|
-
): MaterializationResult {
|
|
144
|
-
if (opResult.success) {
|
|
145
|
-
// Extract details from SSE completion event result
|
|
146
|
-
const sseResult = opResult.result || {}
|
|
147
|
-
|
|
148
|
-
const tables = sseResult.tables_materialized || []
|
|
149
|
-
const rows = sseResult.total_rows || 0
|
|
150
|
-
const timeMs = sseResult.execution_time_ms || 0
|
|
151
|
-
|
|
152
|
-
options.onProgress?.(
|
|
153
|
-
`✅ Materialization complete: ${tables.length} tables, ` +
|
|
154
|
-
`${rows.toLocaleString()} rows in ${timeMs.toFixed(2)}ms`
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
status: 'success',
|
|
159
|
-
wasStale: sseResult.was_stale || false,
|
|
160
|
-
staleReason: sseResult.stale_reason,
|
|
161
|
-
tablesMaterialized: tables,
|
|
162
|
-
totalRows: rows,
|
|
163
|
-
executionTimeMs: timeMs,
|
|
164
|
-
message: sseResult.message || 'Graph materialized successfully',
|
|
165
|
-
success: true,
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
// Operation failed or was cancelled
|
|
169
|
-
return {
|
|
170
|
-
status: 'failed',
|
|
171
|
-
wasStale: false,
|
|
172
|
-
tablesMaterialized: [],
|
|
173
|
-
totalRows: 0,
|
|
174
|
-
executionTimeMs: 0,
|
|
175
|
-
message: opResult.error || 'Operation failed',
|
|
176
|
-
success: false,
|
|
177
|
-
error: opResult.error,
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Get current materialization status for the graph
|
|
184
|
-
*
|
|
185
|
-
* Shows whether the graph is stale (DuckDB has changes not yet in graph database),
|
|
186
|
-
* when it was last materialized, and how long since last materialization.
|
|
187
|
-
*/
|
|
188
|
-
async status(graphId: string): Promise<MaterializationStatus | null> {
|
|
189
|
-
try {
|
|
190
|
-
const response = await getMaterializationStatus({
|
|
191
|
-
path: { graph_id: graphId },
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
if (response.error || !response.data) {
|
|
195
|
-
console.error('Failed to get materialization status:', response.error)
|
|
196
|
-
return null
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const status = response.data as any
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
graphId: status.graph_id,
|
|
203
|
-
isStale: status.is_stale,
|
|
204
|
-
staleReason: status.stale_reason,
|
|
205
|
-
staleSince: status.stale_since,
|
|
206
|
-
lastMaterializedAt: status.last_materialized_at,
|
|
207
|
-
materializationCount: status.materialization_count || 0,
|
|
208
|
-
hoursSinceMaterialization: status.hours_since_materialization,
|
|
209
|
-
message: status.message,
|
|
210
|
-
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.error('Failed to get materialization status:', error)
|
|
213
|
-
return null
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Close any active SSE connections
|
|
219
|
-
*/
|
|
220
|
-
close(): void {
|
|
221
|
-
this.operationClient.closeAll()
|
|
222
|
-
}
|
|
223
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
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/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;
|
|
@@ -1,132 +0,0 @@
|
|
|
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/sdk.gen'
|
|
11
|
-
import type { TableListResponse, TableQueryRequest } from '../sdk/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
|
-
}
|