@robosystems/client 0.1.11 → 0.1.13
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/client/client.gen.d.ts +2 -0
- package/client/client.gen.js +153 -0
- package/client/index.d.ts +7 -0
- package/client/index.js +15 -0
- package/client/types.gen.d.ts +122 -0
- package/client/types.gen.js +4 -0
- package/client/utils.gen.d.ts +45 -0
- package/client/utils.gen.js +296 -0
- package/client.gen.d.ts +12 -0
- package/client.gen.js +8 -0
- package/core/auth.gen.d.ts +18 -0
- package/core/auth.gen.js +18 -0
- package/core/bodySerializer.gen.d.ts +17 -0
- package/core/bodySerializer.gen.js +57 -0
- package/core/params.gen.d.ts +33 -0
- package/core/params.gen.js +92 -0
- package/core/pathSerializer.gen.d.ts +33 -0
- package/core/pathSerializer.gen.js +123 -0
- package/core/types.gen.d.ts +78 -0
- package/core/types.gen.js +4 -0
- package/extensions/OperationClient.d.ts +64 -0
- package/extensions/OperationClient.js +237 -283
- package/extensions/QueryClient.d.ts +50 -0
- package/extensions/QueryClient.js +175 -230
- package/extensions/SSEClient.d.ts +48 -0
- package/extensions/SSEClient.js +138 -156
- package/extensions/config.d.ts +32 -0
- package/extensions/config.js +51 -43
- package/extensions/hooks.d.ts +110 -0
- package/extensions/hooks.js +289 -353
- package/extensions/hooks.ts +4 -4
- package/extensions/index.d.ts +46 -0
- package/extensions/index.js +98 -106
- package/package.json +2 -2
- package/prepare.js +25 -23
- package/sdk.gen.d.ts +1145 -0
- package/sdk.gen.js +2436 -0
- package/types.gen.d.ts +5712 -0
- package/types.gen.js +3 -0
|
@@ -1,245 +1,190 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.QueuedQueryError = exports.QueryClient = void 0;
|
|
3
5
|
/**
|
|
4
6
|
* Enhanced Query Client with SSE support
|
|
5
7
|
* Provides intelligent query execution with automatic strategy selection
|
|
6
8
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export class QueryClient {
|
|
21
|
-
private sseClient?
|
|
22
|
-
private config
|
|
23
|
-
|
|
24
|
-
constructor(config) {
|
|
25
|
-
this.config = config
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async executeQuery(
|
|
29
|
-
graphId,
|
|
30
|
-
request,
|
|
31
|
-
options = {}
|
|
32
|
-
)> {
|
|
33
|
-
const data = {
|
|
34
|
-
url: '/v1/{graph_id}/query',
|
|
35
|
-
path,
|
|
36
|
-
body,
|
|
37
|
-
query,
|
|
9
|
+
const sdk_gen_1 = require("../sdk/sdk.gen");
|
|
10
|
+
const SSEClient_1 = require("./SSEClient");
|
|
11
|
+
class QueryClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
38
14
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
throw new QueuedQueryError(queuedResponse)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Use SSE to monitor the operation
|
|
69
|
-
if (options.mode === 'stream') {
|
|
70
|
-
return this.streamQueryResults(queuedResponse.operation_id, options)
|
|
71
|
-
} else {
|
|
72
|
-
return this.waitForQueryCompletion(queuedResponse.operation_id, options)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Unexpected response format
|
|
77
|
-
throw new Error('Unexpected response format from query endpoint')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private async *streamQueryResults(
|
|
81
|
-
operationId,
|
|
82
|
-
options
|
|
83
|
-
) {
|
|
84
|
-
const buffer = []
|
|
85
|
-
let completed = false
|
|
86
|
-
let error | null = null
|
|
87
|
-
|
|
88
|
-
// Set up SSE connection
|
|
89
|
-
this.sseClient = new SSEClient(this.config)
|
|
90
|
-
await this.sseClient.connect(operationId)
|
|
91
|
-
|
|
92
|
-
// Listen for data chunks
|
|
93
|
-
this.sseClient.on(EventType.DATA_CHUNK, (data) => {
|
|
94
|
-
if (Array.isArray(data.rows)) {
|
|
95
|
-
buffer.push(...data.rows)
|
|
96
|
-
} else if (data.data) {
|
|
97
|
-
buffer.push(...data.data)
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
// Listen for queue updates
|
|
102
|
-
this.sseClient.on(EventType.QUEUE_UPDATE, (data) => {
|
|
103
|
-
options.onQueueUpdate?.(data.position, data.estimated_wait_seconds)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
// Listen for progress
|
|
107
|
-
this.sseClient.on(EventType.OPERATION_PROGRESS, (data) => {
|
|
108
|
-
options.onProgress?.(data.message)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
// Listen for completion
|
|
112
|
-
this.sseClient.on(EventType.OPERATION_COMPLETED, (data) => {
|
|
113
|
-
if (data.result?.data) {
|
|
114
|
-
buffer.push(...data.result.data)
|
|
115
|
-
}
|
|
116
|
-
completed = true
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
// Listen for errors
|
|
120
|
-
this.sseClient.on(EventType.OPERATION_ERROR, (err) => {
|
|
121
|
-
error = new Error(err.message || err.error)
|
|
122
|
-
completed = true
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
// Yield buffered results
|
|
126
|
-
while (!completed || buffer.length > 0) {
|
|
127
|
-
if (error) throw error
|
|
128
|
-
|
|
129
|
-
if (buffer.length > 0) {
|
|
130
|
-
const chunk = buffer.splice(0, options.chunkSize || 100)
|
|
131
|
-
for (const item of chunk) {
|
|
132
|
-
yield item
|
|
15
|
+
async executeQuery(graphId, request, options = {}) {
|
|
16
|
+
const data = {
|
|
17
|
+
url: '/v1/{graph_id}/query',
|
|
18
|
+
path: { graph_id: graphId },
|
|
19
|
+
body: {
|
|
20
|
+
query: request.query,
|
|
21
|
+
parameters: request.parameters,
|
|
22
|
+
},
|
|
23
|
+
query: {
|
|
24
|
+
mode: options.mode,
|
|
25
|
+
test_mode: options.testMode,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
// Execute the query
|
|
29
|
+
const response = await (0, sdk_gen_1.executeCypherQuery)(data);
|
|
30
|
+
const responseData = response.data;
|
|
31
|
+
// Check if this is an immediate response
|
|
32
|
+
if (responseData?.data !== undefined && responseData?.columns) {
|
|
33
|
+
return {
|
|
34
|
+
data: responseData.data,
|
|
35
|
+
columns: responseData.columns,
|
|
36
|
+
row_count: responseData.row_count || responseData.data.length,
|
|
37
|
+
execution_time_ms: responseData.execution_time_ms || 0,
|
|
38
|
+
graph_id: graphId,
|
|
39
|
+
timestamp: responseData.timestamp || new Date().toISOString(),
|
|
40
|
+
};
|
|
133
41
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
42
|
+
// Check if this is a queued response
|
|
43
|
+
if (responseData?.status === 'queued' && responseData?.operation_id) {
|
|
44
|
+
const queuedResponse = responseData;
|
|
45
|
+
// Notify about queue status
|
|
46
|
+
options.onQueueUpdate?.(queuedResponse.queue_position, queuedResponse.estimated_wait_seconds);
|
|
47
|
+
// If user doesn't want to wait, throw with queue info
|
|
48
|
+
if (options.maxWait === 0) {
|
|
49
|
+
throw new QueuedQueryError(queuedResponse);
|
|
50
|
+
}
|
|
51
|
+
// Use SSE to monitor the operation
|
|
52
|
+
if (options.mode === 'stream') {
|
|
53
|
+
return this.streamQueryResults(queuedResponse.operation_id, options);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return this.waitForQueryCompletion(queuedResponse.operation_id, options);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Unexpected response format
|
|
60
|
+
throw new Error('Unexpected response format from query endpoint');
|
|
138
61
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
62
|
+
async *streamQueryResults(operationId, options) {
|
|
63
|
+
const buffer = [];
|
|
64
|
+
let completed = false;
|
|
65
|
+
let error = null;
|
|
66
|
+
// Set up SSE connection
|
|
67
|
+
this.sseClient = new SSEClient_1.SSEClient(this.config);
|
|
68
|
+
await this.sseClient.connect(operationId);
|
|
69
|
+
// Listen for data chunks
|
|
70
|
+
this.sseClient.on(SSEClient_1.EventType.DATA_CHUNK, (data) => {
|
|
71
|
+
if (Array.isArray(data.rows)) {
|
|
72
|
+
buffer.push(...data.rows);
|
|
73
|
+
}
|
|
74
|
+
else if (data.data) {
|
|
75
|
+
buffer.push(...data.data);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// Listen for queue updates
|
|
79
|
+
this.sseClient.on(SSEClient_1.EventType.QUEUE_UPDATE, (data) => {
|
|
80
|
+
options.onQueueUpdate?.(data.position, data.estimated_wait_seconds);
|
|
81
|
+
});
|
|
82
|
+
// Listen for progress
|
|
83
|
+
this.sseClient.on(SSEClient_1.EventType.OPERATION_PROGRESS, (data) => {
|
|
84
|
+
options.onProgress?.(data.message);
|
|
85
|
+
});
|
|
86
|
+
// Listen for completion
|
|
87
|
+
this.sseClient.on(SSEClient_1.EventType.OPERATION_COMPLETED, (data) => {
|
|
88
|
+
if (data.result?.data) {
|
|
89
|
+
buffer.push(...data.result.data);
|
|
90
|
+
}
|
|
91
|
+
completed = true;
|
|
92
|
+
});
|
|
93
|
+
// Listen for errors
|
|
94
|
+
this.sseClient.on(SSEClient_1.EventType.OPERATION_ERROR, (err) => {
|
|
95
|
+
error = new Error(err.message || err.error);
|
|
96
|
+
completed = true;
|
|
97
|
+
});
|
|
98
|
+
// Yield buffered results
|
|
99
|
+
while (!completed || buffer.length > 0) {
|
|
100
|
+
if (error)
|
|
101
|
+
throw error;
|
|
102
|
+
if (buffer.length > 0) {
|
|
103
|
+
const chunk = buffer.splice(0, options.chunkSize || 100);
|
|
104
|
+
for (const item of chunk) {
|
|
105
|
+
yield item;
|
|
106
|
+
}
|
|
175
107
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
sseClient.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
// If not streaming, yield all results at once
|
|
224
|
-
yield* (result).data
|
|
108
|
+
else if (!completed) {
|
|
109
|
+
// Wait for more data
|
|
110
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.sseClient.close();
|
|
114
|
+
this.sseClient = undefined;
|
|
115
|
+
}
|
|
116
|
+
async waitForQueryCompletion(operationId, options) {
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
const sseClient = new SSEClient_1.SSEClient(this.config);
|
|
119
|
+
sseClient
|
|
120
|
+
.connect(operationId)
|
|
121
|
+
.then(() => {
|
|
122
|
+
let result = null;
|
|
123
|
+
// Listen for queue updates
|
|
124
|
+
sseClient.on(SSEClient_1.EventType.QUEUE_UPDATE, (data) => {
|
|
125
|
+
options.onQueueUpdate?.(data.position, data.estimated_wait_seconds);
|
|
126
|
+
});
|
|
127
|
+
// Listen for progress
|
|
128
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_PROGRESS, (data) => {
|
|
129
|
+
options.onProgress?.(data.message);
|
|
130
|
+
});
|
|
131
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_COMPLETED, (data) => {
|
|
132
|
+
const queryResult = data.result || data;
|
|
133
|
+
result = {
|
|
134
|
+
data: queryResult.data || [],
|
|
135
|
+
columns: queryResult.columns || [],
|
|
136
|
+
row_count: queryResult.row_count || 0,
|
|
137
|
+
execution_time_ms: queryResult.execution_time_ms || 0,
|
|
138
|
+
graph_id: queryResult.graph_id,
|
|
139
|
+
timestamp: queryResult.timestamp || new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
sseClient.close();
|
|
142
|
+
resolve(result);
|
|
143
|
+
});
|
|
144
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_ERROR, (error) => {
|
|
145
|
+
sseClient.close();
|
|
146
|
+
reject(new Error(error.message || error.error));
|
|
147
|
+
});
|
|
148
|
+
sseClient.on(SSEClient_1.EventType.OPERATION_CANCELLED, () => {
|
|
149
|
+
sseClient.close();
|
|
150
|
+
reject(new Error('Query cancelled'));
|
|
151
|
+
});
|
|
152
|
+
})
|
|
153
|
+
.catch(reject);
|
|
154
|
+
});
|
|
225
155
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
156
|
+
// Convenience method for simple queries
|
|
157
|
+
async query(graphId, cypher, parameters) {
|
|
158
|
+
return this.executeQuery(graphId, { query: cypher, parameters }, { mode: 'auto' });
|
|
159
|
+
}
|
|
160
|
+
// Streaming query for large results
|
|
161
|
+
async *streamQuery(graphId, cypher, parameters, chunkSize = 1000) {
|
|
162
|
+
const result = await this.executeQuery(graphId, { query: cypher, parameters }, { mode: 'stream', chunkSize });
|
|
163
|
+
if (Symbol.asyncIterator in result) {
|
|
164
|
+
yield* result;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// If not streaming, yield all results at once
|
|
168
|
+
yield* result.data;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Cancel any active SSE connections
|
|
172
|
+
close() {
|
|
173
|
+
if (this.sseClient) {
|
|
174
|
+
this.sseClient.close();
|
|
175
|
+
this.sseClient = undefined;
|
|
176
|
+
}
|
|
233
177
|
}
|
|
234
|
-
}
|
|
235
178
|
}
|
|
236
|
-
|
|
179
|
+
exports.QueryClient = QueryClient;
|
|
237
180
|
/**
|
|
238
181
|
* Error thrown when query is queued and maxWait is 0
|
|
239
182
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
183
|
+
class QueuedQueryError extends Error {
|
|
184
|
+
constructor(queueInfo) {
|
|
185
|
+
super('Query was queued');
|
|
186
|
+
this.queueInfo = queueInfo;
|
|
187
|
+
this.name = 'QueuedQueryError';
|
|
188
|
+
}
|
|
245
189
|
}
|
|
190
|
+
exports.QueuedQueryError = QueuedQueryError;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core SSE (Server-Sent Events) client for RoboSystems API
|
|
3
|
+
* Provides automatic reconnection, event replay, and type-safe event handling
|
|
4
|
+
*/
|
|
5
|
+
export interface SSEConfig {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
credentials?: 'include' | 'same-origin' | 'omit';
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
retryDelay?: number;
|
|
11
|
+
heartbeatInterval?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SSEEvent {
|
|
14
|
+
event: string;
|
|
15
|
+
data: any;
|
|
16
|
+
id?: string;
|
|
17
|
+
retry?: number;
|
|
18
|
+
timestamp: Date;
|
|
19
|
+
}
|
|
20
|
+
export declare enum EventType {
|
|
21
|
+
OPERATION_STARTED = "operation_started",
|
|
22
|
+
OPERATION_PROGRESS = "operation_progress",
|
|
23
|
+
OPERATION_COMPLETED = "operation_completed",
|
|
24
|
+
OPERATION_ERROR = "operation_error",
|
|
25
|
+
OPERATION_CANCELLED = "operation_cancelled",
|
|
26
|
+
DATA_CHUNK = "data_chunk",
|
|
27
|
+
METADATA = "metadata",
|
|
28
|
+
HEARTBEAT = "heartbeat",
|
|
29
|
+
QUEUE_UPDATE = "queue_update"
|
|
30
|
+
}
|
|
31
|
+
export declare class SSEClient {
|
|
32
|
+
private config;
|
|
33
|
+
private eventSource?;
|
|
34
|
+
private reconnectAttempts;
|
|
35
|
+
private lastEventId?;
|
|
36
|
+
private closed;
|
|
37
|
+
private listeners;
|
|
38
|
+
constructor(config: SSEConfig);
|
|
39
|
+
connect(operationId: string, fromSequence?: number): Promise<void>;
|
|
40
|
+
private handleMessage;
|
|
41
|
+
private handleTypedEvent;
|
|
42
|
+
private handleError;
|
|
43
|
+
on(event: string, listener: (data: any) => void): void;
|
|
44
|
+
off(event: string, listener: (data: any) => void): void;
|
|
45
|
+
private emit;
|
|
46
|
+
close(): void;
|
|
47
|
+
isConnected(): boolean;
|
|
48
|
+
}
|