@robosystems/client 0.2.42 → 0.2.44
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 +11 -4
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +51 -9
- package/sdk/sdk.gen.js +105 -16
- package/sdk/sdk.gen.ts +101 -12
- package/sdk/types.gen.d.ts +812 -146
- package/sdk/types.gen.ts +844 -128
- 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 +51 -9
- package/sdk.gen.js +105 -16
- package/sdk.gen.ts +101 -12
- package/types.gen.d.ts +812 -146
- package/types.gen.ts +844 -128
- package/extensions/DocumentClient.d.ts +0 -77
- package/extensions/DocumentClient.js +0 -136
- package/extensions/DocumentClient.ts +0 -232
- 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 -77
- package/sdk-extensions/DocumentClient.js +0 -136
- package/sdk-extensions/DocumentClient.ts +0 -232
- 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,232 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Document Client for RoboSystems API
|
|
5
|
-
*
|
|
6
|
-
* Upload, search, list, and delete text documents indexed in OpenSearch.
|
|
7
|
-
* Documents are sectioned on markdown headings, embedded for semantic search,
|
|
8
|
-
* and searchable alongside structured graph data.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
deleteDocument,
|
|
13
|
-
getDocumentSection,
|
|
14
|
-
listDocuments,
|
|
15
|
-
searchDocuments,
|
|
16
|
-
uploadDocument,
|
|
17
|
-
uploadDocumentsBulk,
|
|
18
|
-
} from '../sdk/sdk.gen'
|
|
19
|
-
import type {
|
|
20
|
-
BulkDocumentUploadResponse,
|
|
21
|
-
DocumentListResponse,
|
|
22
|
-
DocumentSection,
|
|
23
|
-
DocumentUploadResponse,
|
|
24
|
-
SearchResponse,
|
|
25
|
-
} from '../sdk/types.gen'
|
|
26
|
-
|
|
27
|
-
export interface DocumentSearchOptions {
|
|
28
|
-
/** Filter by source type (xbrl_textblock, narrative_section, ixbrl_disclosure, uploaded_doc, memory) */
|
|
29
|
-
sourceType?: string
|
|
30
|
-
/** Filter by ticker, CIK, or entity name */
|
|
31
|
-
entity?: string
|
|
32
|
-
/** Filter by SEC form type (10-K, 10-Q) */
|
|
33
|
-
formType?: string
|
|
34
|
-
/** Filter by section ID (item_1, item_1a, item_7, etc.) */
|
|
35
|
-
section?: string
|
|
36
|
-
/** Filter by XBRL element qname (e.g., us-gaap:Goodwill) */
|
|
37
|
-
element?: string
|
|
38
|
-
/** Filter by fiscal year */
|
|
39
|
-
fiscalYear?: number
|
|
40
|
-
/** Filter filings on or after date (YYYY-MM-DD) */
|
|
41
|
-
dateFrom?: string
|
|
42
|
-
/** Filter filings on or before date (YYYY-MM-DD) */
|
|
43
|
-
dateTo?: string
|
|
44
|
-
/** Max results to return (default: 10) */
|
|
45
|
-
size?: number
|
|
46
|
-
/** Pagination offset */
|
|
47
|
-
offset?: number
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface DocumentUploadOptions {
|
|
51
|
-
/** Optional tags for filtering */
|
|
52
|
-
tags?: string[]
|
|
53
|
-
/** Optional folder/category */
|
|
54
|
-
folder?: string
|
|
55
|
-
/** Optional external ID for upsert behavior */
|
|
56
|
-
externalId?: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class DocumentClient {
|
|
60
|
-
private config: {
|
|
61
|
-
baseUrl: string
|
|
62
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
63
|
-
headers?: Record<string, string>
|
|
64
|
-
token?: string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
constructor(config: {
|
|
68
|
-
baseUrl: string
|
|
69
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
70
|
-
headers?: Record<string, string>
|
|
71
|
-
token?: string
|
|
72
|
-
}) {
|
|
73
|
-
this.config = config
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Upload a markdown document for text indexing.
|
|
78
|
-
*
|
|
79
|
-
* The document is sectioned on headings, embedded, and indexed
|
|
80
|
-
* into OpenSearch for full-text and semantic search.
|
|
81
|
-
*/
|
|
82
|
-
async upload(
|
|
83
|
-
graphId: string,
|
|
84
|
-
title: string,
|
|
85
|
-
content: string,
|
|
86
|
-
options: DocumentUploadOptions = {}
|
|
87
|
-
): Promise<DocumentUploadResponse> {
|
|
88
|
-
const response = await uploadDocument({
|
|
89
|
-
path: { graph_id: graphId },
|
|
90
|
-
body: {
|
|
91
|
-
title,
|
|
92
|
-
content,
|
|
93
|
-
tags: options.tags ?? null,
|
|
94
|
-
folder: options.folder ?? null,
|
|
95
|
-
external_id: options.externalId ?? null,
|
|
96
|
-
},
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
if (response.error) {
|
|
100
|
-
throw new Error(`Document upload failed: ${JSON.stringify(response.error)}`)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return response.data as DocumentUploadResponse
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Upload multiple markdown documents (max 50 per request).
|
|
108
|
-
*/
|
|
109
|
-
async uploadBulk(
|
|
110
|
-
graphId: string,
|
|
111
|
-
documents: Array<{
|
|
112
|
-
title: string
|
|
113
|
-
content: string
|
|
114
|
-
tags?: string[]
|
|
115
|
-
folder?: string
|
|
116
|
-
externalId?: string
|
|
117
|
-
}>
|
|
118
|
-
): Promise<BulkDocumentUploadResponse> {
|
|
119
|
-
const response = await uploadDocumentsBulk({
|
|
120
|
-
path: { graph_id: graphId },
|
|
121
|
-
body: {
|
|
122
|
-
documents: documents.map((doc) => ({
|
|
123
|
-
title: doc.title,
|
|
124
|
-
content: doc.content,
|
|
125
|
-
tags: doc.tags ?? null,
|
|
126
|
-
folder: doc.folder ?? null,
|
|
127
|
-
external_id: doc.externalId ?? null,
|
|
128
|
-
})),
|
|
129
|
-
},
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
if (response.error) {
|
|
133
|
-
throw new Error(`Bulk upload failed: ${JSON.stringify(response.error)}`)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return response.data as BulkDocumentUploadResponse
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Search documents with hybrid (BM25 + kNN) search.
|
|
141
|
-
*/
|
|
142
|
-
async search(
|
|
143
|
-
graphId: string,
|
|
144
|
-
query: string,
|
|
145
|
-
options: DocumentSearchOptions = {}
|
|
146
|
-
): Promise<SearchResponse> {
|
|
147
|
-
const response = await searchDocuments({
|
|
148
|
-
path: { graph_id: graphId },
|
|
149
|
-
body: {
|
|
150
|
-
query,
|
|
151
|
-
source_type: options.sourceType ?? null,
|
|
152
|
-
entity: options.entity ?? null,
|
|
153
|
-
form_type: options.formType ?? null,
|
|
154
|
-
section: options.section ?? null,
|
|
155
|
-
element: options.element ?? null,
|
|
156
|
-
fiscal_year: options.fiscalYear ?? null,
|
|
157
|
-
date_from: options.dateFrom ?? null,
|
|
158
|
-
date_to: options.dateTo ?? null,
|
|
159
|
-
size: options.size,
|
|
160
|
-
offset: options.offset,
|
|
161
|
-
},
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
if (response.error) {
|
|
165
|
-
throw new Error(`Document search failed: ${JSON.stringify(response.error)}`)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return response.data as SearchResponse
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Retrieve the full text of a document section by ID.
|
|
173
|
-
*
|
|
174
|
-
* @returns DocumentSection or null if not found.
|
|
175
|
-
*/
|
|
176
|
-
async getSection(graphId: string, documentId: string): Promise<DocumentSection | null> {
|
|
177
|
-
const response = await getDocumentSection({
|
|
178
|
-
path: { graph_id: graphId, document_id: documentId },
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
if (response.response.status === 404) {
|
|
182
|
-
return null
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (response.error) {
|
|
186
|
-
throw new Error(`Get section failed: ${JSON.stringify(response.error)}`)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return response.data as DocumentSection
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* List indexed documents for a graph.
|
|
194
|
-
*/
|
|
195
|
-
async list(graphId: string, sourceType?: string): Promise<DocumentListResponse> {
|
|
196
|
-
const response = await listDocuments({
|
|
197
|
-
path: { graph_id: graphId },
|
|
198
|
-
query: sourceType ? { source_type: sourceType } : undefined,
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
if (response.error) {
|
|
202
|
-
throw new Error(`List documents failed: ${JSON.stringify(response.error)}`)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return response.data as DocumentListResponse
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Delete a document and all its sections.
|
|
210
|
-
*
|
|
211
|
-
* @returns true if deleted, false if not found.
|
|
212
|
-
*/
|
|
213
|
-
async delete(graphId: string, documentId: string): Promise<boolean> {
|
|
214
|
-
const response = await deleteDocument({
|
|
215
|
-
path: { graph_id: graphId, document_id: documentId },
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
if (response.response.status === 204) {
|
|
219
|
-
return true
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (response.response.status === 404) {
|
|
223
|
-
return false
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (response.error) {
|
|
227
|
-
throw new Error(`Delete document failed: ${JSON.stringify(response.error)}`)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return true
|
|
231
|
-
}
|
|
232
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export interface FileUploadOptions {
|
|
2
|
-
onProgress?: (message: string) => void;
|
|
3
|
-
fileName?: string;
|
|
4
|
-
ingestToGraph?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface FileUploadResult {
|
|
7
|
-
fileId: string;
|
|
8
|
-
fileSize: number;
|
|
9
|
-
rowCount: number;
|
|
10
|
-
tableName: string;
|
|
11
|
-
fileName: string;
|
|
12
|
-
success: boolean;
|
|
13
|
-
error?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface FileInfo {
|
|
16
|
-
fileId: string;
|
|
17
|
-
fileName: string;
|
|
18
|
-
tableName: string;
|
|
19
|
-
status: string;
|
|
20
|
-
fileSize: number;
|
|
21
|
-
rowCount: number;
|
|
22
|
-
createdAt: string;
|
|
23
|
-
}
|
|
24
|
-
export type FileInput = File | Blob | Buffer | ReadableStream<Uint8Array>;
|
|
25
|
-
export declare class FileClient {
|
|
26
|
-
private config;
|
|
27
|
-
constructor(config: {
|
|
28
|
-
baseUrl: string;
|
|
29
|
-
credentials?: 'include' | 'same-origin' | 'omit';
|
|
30
|
-
headers?: Record<string, string>;
|
|
31
|
-
token?: string;
|
|
32
|
-
s3EndpointUrl?: string;
|
|
33
|
-
});
|
|
34
|
-
/**
|
|
35
|
-
* Upload a Parquet file to staging
|
|
36
|
-
*
|
|
37
|
-
* Handles the complete 3-step upload process:
|
|
38
|
-
* 1. Get presigned upload URL
|
|
39
|
-
* 2. Upload file to S3
|
|
40
|
-
* 3. Mark file as 'uploaded' (backend validates, calculates size/row count)
|
|
41
|
-
*/
|
|
42
|
-
upload(graphId: string, tableName: string, fileOrBuffer: FileInput, options?: FileUploadOptions): Promise<FileUploadResult>;
|
|
43
|
-
/**
|
|
44
|
-
* List files in a graph
|
|
45
|
-
*/
|
|
46
|
-
list(graphId: string, tableName?: string, status?: string): Promise<FileInfo[]>;
|
|
47
|
-
/**
|
|
48
|
-
* Get file information
|
|
49
|
-
*/
|
|
50
|
-
get(graphId: string, fileId: string): Promise<FileInfo | null>;
|
|
51
|
-
/**
|
|
52
|
-
* Delete a file
|
|
53
|
-
*/
|
|
54
|
-
delete(graphId: string, fileId: string, cascade?: boolean): Promise<boolean>;
|
|
55
|
-
private getFileName;
|
|
56
|
-
private getFileContent;
|
|
57
|
-
}
|
|
@@ -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/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;
|