@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
package/extensions/FileClient.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.FileClient = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* File Client for RoboSystems API
|
|
7
|
-
*
|
|
8
|
-
* Manages file upload operations including presigned URLs, S3 uploads,
|
|
9
|
-
* and file status tracking.
|
|
10
|
-
*/
|
|
11
|
-
const sdk_gen_1 = require("../sdk.gen");
|
|
12
|
-
class FileClient {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Upload a Parquet file to staging
|
|
18
|
-
*
|
|
19
|
-
* Handles the complete 3-step upload process:
|
|
20
|
-
* 1. Get presigned upload URL
|
|
21
|
-
* 2. Upload file to S3
|
|
22
|
-
* 3. Mark file as 'uploaded' (backend validates, calculates size/row count)
|
|
23
|
-
*/
|
|
24
|
-
async upload(graphId, tableName, fileOrBuffer, options = {}) {
|
|
25
|
-
const fileName = this.getFileName(fileOrBuffer, options.fileName);
|
|
26
|
-
try {
|
|
27
|
-
options.onProgress?.(`Getting upload URL for ${fileName} -> table '${tableName}'...`);
|
|
28
|
-
const uploadRequest = {
|
|
29
|
-
file_name: fileName,
|
|
30
|
-
content_type: 'application/x-parquet',
|
|
31
|
-
table_name: tableName,
|
|
32
|
-
};
|
|
33
|
-
const uploadUrlResponse = await (0, sdk_gen_1.createFileUpload)({
|
|
34
|
-
path: { graph_id: graphId },
|
|
35
|
-
body: uploadRequest,
|
|
36
|
-
});
|
|
37
|
-
if (uploadUrlResponse.error || !uploadUrlResponse.data) {
|
|
38
|
-
return {
|
|
39
|
-
fileId: '',
|
|
40
|
-
fileSize: 0,
|
|
41
|
-
rowCount: 0,
|
|
42
|
-
tableName,
|
|
43
|
-
fileName,
|
|
44
|
-
success: false,
|
|
45
|
-
error: `Failed to get upload URL: ${uploadUrlResponse.error}`,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const uploadData = uploadUrlResponse.data;
|
|
49
|
-
let uploadUrl = uploadData.upload_url;
|
|
50
|
-
const fileId = uploadData.file_id;
|
|
51
|
-
// Override S3 endpoint if configured (e.g., for LocalStack)
|
|
52
|
-
if (this.config.s3EndpointUrl) {
|
|
53
|
-
const originalUrl = new URL(uploadUrl);
|
|
54
|
-
const overrideUrl = new URL(this.config.s3EndpointUrl);
|
|
55
|
-
// Replace scheme, host, and port with the override endpoint
|
|
56
|
-
originalUrl.protocol = overrideUrl.protocol;
|
|
57
|
-
originalUrl.host = overrideUrl.host;
|
|
58
|
-
uploadUrl = originalUrl.toString();
|
|
59
|
-
}
|
|
60
|
-
options.onProgress?.(`Uploading ${fileName} to S3...`);
|
|
61
|
-
const fileContent = await this.getFileContent(fileOrBuffer);
|
|
62
|
-
const fileSize = fileContent.byteLength;
|
|
63
|
-
const s3Response = await fetch(uploadUrl, {
|
|
64
|
-
method: 'PUT',
|
|
65
|
-
body: fileContent,
|
|
66
|
-
headers: {
|
|
67
|
-
'Content-Type': 'application/x-parquet',
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
if (!s3Response.ok) {
|
|
71
|
-
return {
|
|
72
|
-
fileId,
|
|
73
|
-
fileSize,
|
|
74
|
-
rowCount: 0,
|
|
75
|
-
tableName,
|
|
76
|
-
fileName,
|
|
77
|
-
success: false,
|
|
78
|
-
error: `S3 upload failed: ${s3Response.status} ${s3Response.statusText}`,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
options.onProgress?.(`Marking ${fileName} as uploaded...`);
|
|
82
|
-
const statusUpdate = {
|
|
83
|
-
status: 'uploaded',
|
|
84
|
-
};
|
|
85
|
-
const updateResponse = await (0, sdk_gen_1.updateFile)({
|
|
86
|
-
path: { graph_id: graphId, file_id: fileId },
|
|
87
|
-
body: statusUpdate,
|
|
88
|
-
});
|
|
89
|
-
if (updateResponse.error || !updateResponse.data) {
|
|
90
|
-
return {
|
|
91
|
-
fileId,
|
|
92
|
-
fileSize,
|
|
93
|
-
rowCount: 0,
|
|
94
|
-
tableName,
|
|
95
|
-
fileName,
|
|
96
|
-
success: false,
|
|
97
|
-
error: 'Failed to complete file upload',
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
const responseData = updateResponse.data;
|
|
101
|
-
const actualFileSize = responseData.file_size_bytes || 0;
|
|
102
|
-
const actualRowCount = responseData.row_count || 0;
|
|
103
|
-
options.onProgress?.(`✅ Uploaded ${fileName} (${actualFileSize.toLocaleString()} bytes, ${actualRowCount.toLocaleString()} rows)`);
|
|
104
|
-
return {
|
|
105
|
-
fileId,
|
|
106
|
-
fileSize: actualFileSize,
|
|
107
|
-
rowCount: actualRowCount,
|
|
108
|
-
tableName,
|
|
109
|
-
fileName,
|
|
110
|
-
success: true,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
return {
|
|
115
|
-
fileId: '',
|
|
116
|
-
fileSize: 0,
|
|
117
|
-
rowCount: 0,
|
|
118
|
-
tableName,
|
|
119
|
-
fileName,
|
|
120
|
-
success: false,
|
|
121
|
-
error: error instanceof Error ? error.message : String(error),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* List files in a graph
|
|
127
|
-
*/
|
|
128
|
-
async list(graphId, tableName, status) {
|
|
129
|
-
try {
|
|
130
|
-
const response = await (0, sdk_gen_1.listFiles)({
|
|
131
|
-
path: { graph_id: graphId },
|
|
132
|
-
query: {
|
|
133
|
-
table_name: tableName,
|
|
134
|
-
status: status,
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
if (response.error || !response.data) {
|
|
138
|
-
console.error('Failed to list files:', response.error);
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
const fileData = response.data;
|
|
142
|
-
return (fileData.files?.map((file) => ({
|
|
143
|
-
fileId: file.file_id,
|
|
144
|
-
fileName: file.file_name,
|
|
145
|
-
tableName: file.table_name,
|
|
146
|
-
status: file.status,
|
|
147
|
-
fileSize: file.file_size_bytes || 0,
|
|
148
|
-
rowCount: file.row_count || 0,
|
|
149
|
-
createdAt: file.created_at,
|
|
150
|
-
})) || []);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
console.error('Failed to list files:', error);
|
|
154
|
-
return [];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Get file information
|
|
159
|
-
*/
|
|
160
|
-
async get(graphId, fileId) {
|
|
161
|
-
try {
|
|
162
|
-
const response = await (0, sdk_gen_1.getFile)({
|
|
163
|
-
path: { graph_id: graphId, file_id: fileId },
|
|
164
|
-
});
|
|
165
|
-
if (response.error || !response.data) {
|
|
166
|
-
console.error('Failed to get file:', response.error);
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
const file = response.data;
|
|
170
|
-
return {
|
|
171
|
-
fileId: file.file_id,
|
|
172
|
-
fileName: file.file_name,
|
|
173
|
-
tableName: file.table_name,
|
|
174
|
-
status: file.status,
|
|
175
|
-
fileSize: file.file_size_bytes || 0,
|
|
176
|
-
rowCount: file.row_count || 0,
|
|
177
|
-
createdAt: file.created_at,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
console.error('Failed to get file:', error);
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Delete a file
|
|
187
|
-
*/
|
|
188
|
-
async delete(graphId, fileId, cascade = false) {
|
|
189
|
-
try {
|
|
190
|
-
const response = await (0, sdk_gen_1.deleteFile)({
|
|
191
|
-
path: { graph_id: graphId, file_id: fileId },
|
|
192
|
-
query: { cascade },
|
|
193
|
-
});
|
|
194
|
-
return !response.error;
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
console.error('Failed to delete file:', error);
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
getFileName(fileOrBuffer, override) {
|
|
202
|
-
if (override)
|
|
203
|
-
return override;
|
|
204
|
-
if ('name' in fileOrBuffer && typeof fileOrBuffer.name === 'string') {
|
|
205
|
-
return fileOrBuffer.name;
|
|
206
|
-
}
|
|
207
|
-
return 'data.parquet';
|
|
208
|
-
}
|
|
209
|
-
async getFileContent(fileOrBuffer) {
|
|
210
|
-
if (fileOrBuffer instanceof Blob || fileOrBuffer instanceof File) {
|
|
211
|
-
return fileOrBuffer.arrayBuffer();
|
|
212
|
-
}
|
|
213
|
-
if (Buffer.isBuffer(fileOrBuffer)) {
|
|
214
|
-
const buffer = fileOrBuffer.buffer.slice(fileOrBuffer.byteOffset, fileOrBuffer.byteOffset + fileOrBuffer.byteLength);
|
|
215
|
-
// Convert SharedArrayBuffer to ArrayBuffer if needed
|
|
216
|
-
if (buffer instanceof ArrayBuffer) {
|
|
217
|
-
return buffer;
|
|
218
|
-
}
|
|
219
|
-
// Handle SharedArrayBuffer by copying to ArrayBuffer
|
|
220
|
-
const arrayBuffer = new ArrayBuffer(buffer.byteLength);
|
|
221
|
-
new Uint8Array(arrayBuffer).set(new Uint8Array(buffer));
|
|
222
|
-
return arrayBuffer;
|
|
223
|
-
}
|
|
224
|
-
if ('getReader' in fileOrBuffer) {
|
|
225
|
-
const reader = fileOrBuffer.getReader();
|
|
226
|
-
const chunks = [];
|
|
227
|
-
while (true) {
|
|
228
|
-
const { done, value } = await reader.read();
|
|
229
|
-
if (done)
|
|
230
|
-
break;
|
|
231
|
-
if (value)
|
|
232
|
-
chunks.push(value);
|
|
233
|
-
}
|
|
234
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
235
|
-
const result = new Uint8Array(totalLength);
|
|
236
|
-
let offset = 0;
|
|
237
|
-
for (const chunk of chunks) {
|
|
238
|
-
result.set(chunk, offset);
|
|
239
|
-
offset += chunk.length;
|
|
240
|
-
}
|
|
241
|
-
return result.buffer;
|
|
242
|
-
}
|
|
243
|
-
throw new Error('Unsupported file input type');
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
exports.FileClient = FileClient;
|
package/extensions/FileClient.ts
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* File Client for RoboSystems API
|
|
5
|
-
*
|
|
6
|
-
* Manages file upload operations including presigned URLs, S3 uploads,
|
|
7
|
-
* and file status tracking.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createFileUpload, deleteFile, getFile, listFiles, updateFile } from '../sdk.gen'
|
|
11
|
-
import type { FileStatusUpdate, FileUploadRequest, FileUploadResponse } from '../types.gen'
|
|
12
|
-
|
|
13
|
-
export interface FileUploadOptions {
|
|
14
|
-
onProgress?: (message: string) => void
|
|
15
|
-
fileName?: string
|
|
16
|
-
ingestToGraph?: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface FileUploadResult {
|
|
20
|
-
fileId: string
|
|
21
|
-
fileSize: number
|
|
22
|
-
rowCount: number
|
|
23
|
-
tableName: string
|
|
24
|
-
fileName: string
|
|
25
|
-
success: boolean
|
|
26
|
-
error?: string
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface FileInfo {
|
|
30
|
-
fileId: string
|
|
31
|
-
fileName: string
|
|
32
|
-
tableName: string
|
|
33
|
-
status: string
|
|
34
|
-
fileSize: number
|
|
35
|
-
rowCount: number
|
|
36
|
-
createdAt: string
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type FileInput = File | Blob | Buffer | ReadableStream<Uint8Array>
|
|
40
|
-
|
|
41
|
-
export class FileClient {
|
|
42
|
-
private config: {
|
|
43
|
-
baseUrl: string
|
|
44
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
45
|
-
headers?: Record<string, string>
|
|
46
|
-
token?: string
|
|
47
|
-
s3EndpointUrl?: string // Override S3 endpoint (e.g., for LocalStack)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
constructor(config: {
|
|
51
|
-
baseUrl: string
|
|
52
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
53
|
-
headers?: Record<string, string>
|
|
54
|
-
token?: string
|
|
55
|
-
s3EndpointUrl?: string
|
|
56
|
-
}) {
|
|
57
|
-
this.config = config
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Upload a Parquet file to staging
|
|
62
|
-
*
|
|
63
|
-
* Handles the complete 3-step upload process:
|
|
64
|
-
* 1. Get presigned upload URL
|
|
65
|
-
* 2. Upload file to S3
|
|
66
|
-
* 3. Mark file as 'uploaded' (backend validates, calculates size/row count)
|
|
67
|
-
*/
|
|
68
|
-
async upload(
|
|
69
|
-
graphId: string,
|
|
70
|
-
tableName: string,
|
|
71
|
-
fileOrBuffer: FileInput,
|
|
72
|
-
options: FileUploadOptions = {}
|
|
73
|
-
): Promise<FileUploadResult> {
|
|
74
|
-
const fileName = this.getFileName(fileOrBuffer, options.fileName)
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
options.onProgress?.(`Getting upload URL for ${fileName} -> table '${tableName}'...`)
|
|
78
|
-
|
|
79
|
-
const uploadRequest: FileUploadRequest = {
|
|
80
|
-
file_name: fileName,
|
|
81
|
-
content_type: 'application/x-parquet',
|
|
82
|
-
table_name: tableName,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const uploadUrlResponse = await createFileUpload({
|
|
86
|
-
path: { graph_id: graphId },
|
|
87
|
-
body: uploadRequest,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
if (uploadUrlResponse.error || !uploadUrlResponse.data) {
|
|
91
|
-
return {
|
|
92
|
-
fileId: '',
|
|
93
|
-
fileSize: 0,
|
|
94
|
-
rowCount: 0,
|
|
95
|
-
tableName,
|
|
96
|
-
fileName,
|
|
97
|
-
success: false,
|
|
98
|
-
error: `Failed to get upload URL: ${uploadUrlResponse.error}`,
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const uploadData = uploadUrlResponse.data as FileUploadResponse
|
|
103
|
-
let uploadUrl = uploadData.upload_url
|
|
104
|
-
const fileId = uploadData.file_id
|
|
105
|
-
|
|
106
|
-
// Override S3 endpoint if configured (e.g., for LocalStack)
|
|
107
|
-
if (this.config.s3EndpointUrl) {
|
|
108
|
-
const originalUrl = new URL(uploadUrl)
|
|
109
|
-
const overrideUrl = new URL(this.config.s3EndpointUrl)
|
|
110
|
-
// Replace scheme, host, and port with the override endpoint
|
|
111
|
-
originalUrl.protocol = overrideUrl.protocol
|
|
112
|
-
originalUrl.host = overrideUrl.host
|
|
113
|
-
uploadUrl = originalUrl.toString()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
options.onProgress?.(`Uploading ${fileName} to S3...`)
|
|
117
|
-
|
|
118
|
-
const fileContent = await this.getFileContent(fileOrBuffer)
|
|
119
|
-
const fileSize = fileContent.byteLength
|
|
120
|
-
|
|
121
|
-
const s3Response = await fetch(uploadUrl, {
|
|
122
|
-
method: 'PUT',
|
|
123
|
-
body: fileContent,
|
|
124
|
-
headers: {
|
|
125
|
-
'Content-Type': 'application/x-parquet',
|
|
126
|
-
},
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
if (!s3Response.ok) {
|
|
130
|
-
return {
|
|
131
|
-
fileId,
|
|
132
|
-
fileSize,
|
|
133
|
-
rowCount: 0,
|
|
134
|
-
tableName,
|
|
135
|
-
fileName,
|
|
136
|
-
success: false,
|
|
137
|
-
error: `S3 upload failed: ${s3Response.status} ${s3Response.statusText}`,
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
options.onProgress?.(`Marking ${fileName} as uploaded...`)
|
|
142
|
-
|
|
143
|
-
const statusUpdate: FileStatusUpdate = {
|
|
144
|
-
status: 'uploaded',
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const updateResponse = await updateFile({
|
|
148
|
-
path: { graph_id: graphId, file_id: fileId },
|
|
149
|
-
body: statusUpdate,
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
if (updateResponse.error || !updateResponse.data) {
|
|
153
|
-
return {
|
|
154
|
-
fileId,
|
|
155
|
-
fileSize,
|
|
156
|
-
rowCount: 0,
|
|
157
|
-
tableName,
|
|
158
|
-
fileName,
|
|
159
|
-
success: false,
|
|
160
|
-
error: 'Failed to complete file upload',
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const responseData = updateResponse.data as any
|
|
165
|
-
const actualFileSize = responseData.file_size_bytes || 0
|
|
166
|
-
const actualRowCount = responseData.row_count || 0
|
|
167
|
-
|
|
168
|
-
options.onProgress?.(
|
|
169
|
-
`✅ Uploaded ${fileName} (${actualFileSize.toLocaleString()} bytes, ${actualRowCount.toLocaleString()} rows)`
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
return {
|
|
173
|
-
fileId,
|
|
174
|
-
fileSize: actualFileSize,
|
|
175
|
-
rowCount: actualRowCount,
|
|
176
|
-
tableName,
|
|
177
|
-
fileName,
|
|
178
|
-
success: true,
|
|
179
|
-
}
|
|
180
|
-
} catch (error) {
|
|
181
|
-
return {
|
|
182
|
-
fileId: '',
|
|
183
|
-
fileSize: 0,
|
|
184
|
-
rowCount: 0,
|
|
185
|
-
tableName,
|
|
186
|
-
fileName,
|
|
187
|
-
success: false,
|
|
188
|
-
error: error instanceof Error ? error.message : String(error),
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* List files in a graph
|
|
195
|
-
*/
|
|
196
|
-
async list(graphId: string, tableName?: string, status?: string): Promise<FileInfo[]> {
|
|
197
|
-
try {
|
|
198
|
-
const response = await listFiles({
|
|
199
|
-
path: { graph_id: graphId },
|
|
200
|
-
query: {
|
|
201
|
-
table_name: tableName,
|
|
202
|
-
status: status as any,
|
|
203
|
-
},
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
if (response.error || !response.data) {
|
|
207
|
-
console.error('Failed to list files:', response.error)
|
|
208
|
-
return []
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const fileData = response.data as any
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
fileData.files?.map((file: any) => ({
|
|
215
|
-
fileId: file.file_id,
|
|
216
|
-
fileName: file.file_name,
|
|
217
|
-
tableName: file.table_name,
|
|
218
|
-
status: file.status,
|
|
219
|
-
fileSize: file.file_size_bytes || 0,
|
|
220
|
-
rowCount: file.row_count || 0,
|
|
221
|
-
createdAt: file.created_at,
|
|
222
|
-
})) || []
|
|
223
|
-
)
|
|
224
|
-
} catch (error) {
|
|
225
|
-
console.error('Failed to list files:', error)
|
|
226
|
-
return []
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get file information
|
|
232
|
-
*/
|
|
233
|
-
async get(graphId: string, fileId: string): Promise<FileInfo | null> {
|
|
234
|
-
try {
|
|
235
|
-
const response = await getFile({
|
|
236
|
-
path: { graph_id: graphId, file_id: fileId },
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
if (response.error || !response.data) {
|
|
240
|
-
console.error('Failed to get file:', response.error)
|
|
241
|
-
return null
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const file = response.data as any
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
fileId: file.file_id,
|
|
248
|
-
fileName: file.file_name,
|
|
249
|
-
tableName: file.table_name,
|
|
250
|
-
status: file.status,
|
|
251
|
-
fileSize: file.file_size_bytes || 0,
|
|
252
|
-
rowCount: file.row_count || 0,
|
|
253
|
-
createdAt: file.created_at,
|
|
254
|
-
}
|
|
255
|
-
} catch (error) {
|
|
256
|
-
console.error('Failed to get file:', error)
|
|
257
|
-
return null
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Delete a file
|
|
263
|
-
*/
|
|
264
|
-
async delete(graphId: string, fileId: string, cascade: boolean = false): Promise<boolean> {
|
|
265
|
-
try {
|
|
266
|
-
const response = await deleteFile({
|
|
267
|
-
path: { graph_id: graphId, file_id: fileId },
|
|
268
|
-
query: { cascade },
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
return !response.error
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.error('Failed to delete file:', error)
|
|
274
|
-
return false
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
private getFileName(fileOrBuffer: FileInput, override?: string): string {
|
|
279
|
-
if (override) return override
|
|
280
|
-
|
|
281
|
-
if ('name' in fileOrBuffer && typeof fileOrBuffer.name === 'string') {
|
|
282
|
-
return fileOrBuffer.name
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return 'data.parquet'
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
private async getFileContent(fileOrBuffer: FileInput): Promise<ArrayBuffer> {
|
|
289
|
-
if (fileOrBuffer instanceof Blob || fileOrBuffer instanceof File) {
|
|
290
|
-
return fileOrBuffer.arrayBuffer()
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (Buffer.isBuffer(fileOrBuffer)) {
|
|
294
|
-
const buffer = fileOrBuffer.buffer.slice(
|
|
295
|
-
fileOrBuffer.byteOffset,
|
|
296
|
-
fileOrBuffer.byteOffset + fileOrBuffer.byteLength
|
|
297
|
-
)
|
|
298
|
-
// Convert SharedArrayBuffer to ArrayBuffer if needed
|
|
299
|
-
if (buffer instanceof ArrayBuffer) {
|
|
300
|
-
return buffer
|
|
301
|
-
}
|
|
302
|
-
// Handle SharedArrayBuffer by copying to ArrayBuffer
|
|
303
|
-
const arrayBuffer = new ArrayBuffer(buffer.byteLength)
|
|
304
|
-
new Uint8Array(arrayBuffer).set(new Uint8Array(buffer))
|
|
305
|
-
return arrayBuffer
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if ('getReader' in fileOrBuffer) {
|
|
309
|
-
const reader = fileOrBuffer.getReader()
|
|
310
|
-
const chunks: Uint8Array[] = []
|
|
311
|
-
|
|
312
|
-
while (true) {
|
|
313
|
-
const { done, value } = await reader.read()
|
|
314
|
-
if (done) break
|
|
315
|
-
if (value) chunks.push(value)
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0)
|
|
319
|
-
const result = new Uint8Array(totalLength)
|
|
320
|
-
let offset = 0
|
|
321
|
-
for (const chunk of chunks) {
|
|
322
|
-
result.set(chunk, offset)
|
|
323
|
-
offset += chunk.length
|
|
324
|
-
}
|
|
325
|
-
return result.buffer
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
throw new Error('Unsupported file input type')
|
|
329
|
-
}
|
|
330
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a graph operation fails (as reported by the server)
|
|
3
|
-
* This is distinct from connection/SSE errors
|
|
4
|
-
*/
|
|
5
|
-
export declare class GraphOperationError extends Error {
|
|
6
|
-
constructor(message: string);
|
|
7
|
-
}
|
|
8
|
-
export interface GraphMetadataInput {
|
|
9
|
-
graphName: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
schemaExtensions?: string[];
|
|
12
|
-
tags?: string[];
|
|
13
|
-
}
|
|
14
|
-
export interface InitialEntityInput {
|
|
15
|
-
name: string;
|
|
16
|
-
uri: string;
|
|
17
|
-
category?: string;
|
|
18
|
-
sic?: string;
|
|
19
|
-
sicDescription?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface GraphInfo {
|
|
22
|
-
graphId: string;
|
|
23
|
-
graphName: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
schemaExtensions?: string[];
|
|
26
|
-
tags?: string[];
|
|
27
|
-
createdAt?: string;
|
|
28
|
-
status?: string;
|
|
29
|
-
}
|
|
30
|
-
export interface CreateGraphOptions {
|
|
31
|
-
createEntity?: boolean;
|
|
32
|
-
timeout?: number;
|
|
33
|
-
pollInterval?: number;
|
|
34
|
-
onProgress?: (message: string) => void;
|
|
35
|
-
useSSE?: boolean;
|
|
36
|
-
}
|
|
37
|
-
export declare class GraphClient {
|
|
38
|
-
private operationClient;
|
|
39
|
-
private config;
|
|
40
|
-
constructor(config: {
|
|
41
|
-
baseUrl: string;
|
|
42
|
-
credentials?: 'include' | 'same-origin' | 'omit';
|
|
43
|
-
headers?: Record<string, string>;
|
|
44
|
-
token?: string;
|
|
45
|
-
});
|
|
46
|
-
/**
|
|
47
|
-
* Create a graph and wait for completion
|
|
48
|
-
*
|
|
49
|
-
* Uses SSE (Server-Sent Events) for real-time progress updates with
|
|
50
|
-
* automatic fallback to polling if SSE connection fails.
|
|
51
|
-
*
|
|
52
|
-
* @param metadata - Graph metadata (name, description, etc.)
|
|
53
|
-
* @param initialEntity - Optional initial entity to create
|
|
54
|
-
* @param options - Additional options including:
|
|
55
|
-
* - createEntity: Whether to create the entity node and upload initial data.
|
|
56
|
-
* Only applies when initialEntity is provided. Set to false to
|
|
57
|
-
* create graph without populating entity data (useful for file-based ingestion).
|
|
58
|
-
* Defaults to true.
|
|
59
|
-
* - timeout: Maximum time to wait in milliseconds (default: 60000)
|
|
60
|
-
* - pollInterval: Time between status checks in milliseconds (default: 2000, for polling fallback)
|
|
61
|
-
* - onProgress: Callback for progress updates
|
|
62
|
-
* - useSSE: Whether to try SSE first (default: true). Falls back to polling on failure.
|
|
63
|
-
* @returns The graph ID when creation completes
|
|
64
|
-
*/
|
|
65
|
-
createGraphAndWait(metadata: GraphMetadataInput, initialEntity?: InitialEntityInput, options?: CreateGraphOptions): Promise<string>;
|
|
66
|
-
/**
|
|
67
|
-
* Wait for operation completion using SSE stream
|
|
68
|
-
*/
|
|
69
|
-
private waitWithSSE;
|
|
70
|
-
/**
|
|
71
|
-
* Wait for operation completion using polling
|
|
72
|
-
*/
|
|
73
|
-
private waitWithPolling;
|
|
74
|
-
/**
|
|
75
|
-
* Get information about a graph
|
|
76
|
-
*/
|
|
77
|
-
getGraphInfo(graphId: string): Promise<GraphInfo>;
|
|
78
|
-
/**
|
|
79
|
-
* List all graphs
|
|
80
|
-
*/
|
|
81
|
-
listGraphs(): Promise<GraphInfo[]>;
|
|
82
|
-
/**
|
|
83
|
-
* Delete a graph
|
|
84
|
-
* Note: This will be implemented when the deleteGraph endpoint is available in the SDK
|
|
85
|
-
*/
|
|
86
|
-
deleteGraph(_graphId: string): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Clean up resources
|
|
89
|
-
*/
|
|
90
|
-
close(): void;
|
|
91
|
-
}
|