@robosystems/client 0.1.12 → 0.1.14
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/OperationClient.js +237 -283
- package/extensions/QueryClient.js +175 -230
- package/extensions/SSEClient.js +138 -156
- package/extensions/config.js +51 -43
- package/extensions/hooks.js +289 -353
- package/extensions/index.js +98 -106
- package/package.json +1 -1
- package/prepare.js +23 -26
- package/extensions/OperationClient.d.js +0 -45
- package/extensions/QueryClient.d.js +0 -22
- package/extensions/SSEClient.d.js +0 -35
- package/extensions/config.d.js +0 -25
- package/extensions/hooks.d.js +0 -80
- package/extensions/index.d.js +0 -35
package/extensions/hooks.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useQuery = useQuery;
|
|
5
|
+
exports.useStreamingQuery = useStreamingQuery;
|
|
6
|
+
exports.useOperation = useOperation;
|
|
7
|
+
exports.useMultipleOperations = useMultipleOperations;
|
|
8
|
+
exports.useSDKClients = useSDKClients;
|
|
3
9
|
/**
|
|
4
10
|
* React hooks for SDK extensions
|
|
5
11
|
* Provides easy-to-use hooks for Next.js/React applications
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { OperationClient } from './OperationClient'
|
|
13
|
-
import { QueryOptions, QueryResult } from './QueryClient'
|
|
14
|
-
import { QueryClient } from './QueryClient'
|
|
15
|
-
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const client_gen_1 = require("../client.gen");
|
|
15
|
+
const config_1 = require("./config");
|
|
16
|
+
const OperationClient_1 = require("./OperationClient");
|
|
17
|
+
const QueryClient_1 = require("./QueryClient");
|
|
16
18
|
/**
|
|
17
19
|
* Hook for executing Cypher queries with loading states and error handling
|
|
18
20
|
*
|
|
@@ -26,89 +28,69 @@ import { QueryClient } from './QueryClient'
|
|
|
26
28
|
* }
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
// Simple query method that returns just the data
|
|
94
|
-
const query = useCallback(
|
|
95
|
-
async (cypher, parameters?) => {
|
|
96
|
-
const result = await execute(cypher, parameters)
|
|
97
|
-
return result?.data || []
|
|
98
|
-
},
|
|
99
|
-
[execute]
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
execute,
|
|
104
|
-
query,
|
|
105
|
-
loading,
|
|
106
|
-
error,
|
|
107
|
-
data,
|
|
108
|
-
queuePosition,
|
|
109
|
-
}
|
|
31
|
+
function useQuery(graphId) {
|
|
32
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
33
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
34
|
+
const [data, setData] = (0, react_1.useState)(null);
|
|
35
|
+
const [queuePosition, setQueuePosition] = (0, react_1.useState)(null);
|
|
36
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
37
|
+
// Initialize client
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
const sdkConfig = (0, config_1.getSDKExtensionsConfig)();
|
|
40
|
+
const clientConfig = client_gen_1.client.getConfig();
|
|
41
|
+
clientRef.current = new QueryClient_1.QueryClient({
|
|
42
|
+
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
43
|
+
credentials: sdkConfig.credentials,
|
|
44
|
+
headers: sdkConfig.headers,
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
clientRef.current?.close();
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
const execute = (0, react_1.useCallback)(async (query, parameters, options) => {
|
|
51
|
+
if (!clientRef.current)
|
|
52
|
+
return null;
|
|
53
|
+
setLoading(true);
|
|
54
|
+
setError(null);
|
|
55
|
+
setData(null);
|
|
56
|
+
setQueuePosition(null);
|
|
57
|
+
try {
|
|
58
|
+
const result = (await clientRef.current.executeQuery(graphId, { query, parameters }, {
|
|
59
|
+
...options,
|
|
60
|
+
onQueueUpdate: (position) => {
|
|
61
|
+
setQueuePosition(position);
|
|
62
|
+
},
|
|
63
|
+
onProgress: () => {
|
|
64
|
+
setQueuePosition(null); // Clear queue position when executing
|
|
65
|
+
},
|
|
66
|
+
}));
|
|
67
|
+
setData(result);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
const error = err;
|
|
72
|
+
setError(error);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
setLoading(false);
|
|
77
|
+
setQueuePosition(null);
|
|
78
|
+
}
|
|
79
|
+
}, [graphId]);
|
|
80
|
+
// Simple query method that returns just the data
|
|
81
|
+
const query = (0, react_1.useCallback)(async (cypher, parameters) => {
|
|
82
|
+
const result = await execute(cypher, parameters);
|
|
83
|
+
return result?.data || [];
|
|
84
|
+
}, [execute]);
|
|
85
|
+
return {
|
|
86
|
+
execute,
|
|
87
|
+
query,
|
|
88
|
+
loading,
|
|
89
|
+
error,
|
|
90
|
+
data,
|
|
91
|
+
queuePosition,
|
|
92
|
+
};
|
|
110
93
|
}
|
|
111
|
-
|
|
112
94
|
/**
|
|
113
95
|
* Hook for streaming large query results
|
|
114
96
|
*
|
|
@@ -124,90 +106,74 @@ export function useQuery(graphId) {
|
|
|
124
106
|
* }
|
|
125
107
|
* ```
|
|
126
108
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
if (buffer.length >= chunkSize) {
|
|
170
|
-
setRowsReceived(count)
|
|
171
|
-
yield buffer
|
|
172
|
-
buffer = []
|
|
173
|
-
}
|
|
109
|
+
function useStreamingQuery(graphId) {
|
|
110
|
+
const [isStreaming, setIsStreaming] = (0, react_1.useState)(false);
|
|
111
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
112
|
+
const [rowsReceived, setRowsReceived] = (0, react_1.useState)(0);
|
|
113
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
114
|
+
(0, react_1.useEffect)(() => {
|
|
115
|
+
const sdkConfig = (0, config_1.getSDKExtensionsConfig)();
|
|
116
|
+
const clientConfig = client_gen_1.client.getConfig();
|
|
117
|
+
clientRef.current = new QueryClient_1.QueryClient({
|
|
118
|
+
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
119
|
+
credentials: sdkConfig.credentials,
|
|
120
|
+
headers: sdkConfig.headers,
|
|
121
|
+
});
|
|
122
|
+
return () => {
|
|
123
|
+
clientRef.current?.close();
|
|
124
|
+
};
|
|
125
|
+
}, []);
|
|
126
|
+
const stream = (0, react_1.useCallback)(async function* (query, parameters, chunkSize = 100) {
|
|
127
|
+
if (!clientRef.current)
|
|
128
|
+
return;
|
|
129
|
+
setIsStreaming(true);
|
|
130
|
+
setError(null);
|
|
131
|
+
setRowsReceived(0);
|
|
132
|
+
try {
|
|
133
|
+
const iterator = clientRef.current.streamQuery(graphId, query, parameters, chunkSize);
|
|
134
|
+
let buffer = [];
|
|
135
|
+
let count = 0;
|
|
136
|
+
for await (const row of iterator) {
|
|
137
|
+
buffer.push(row);
|
|
138
|
+
count++;
|
|
139
|
+
if (buffer.length >= chunkSize) {
|
|
140
|
+
setRowsReceived(count);
|
|
141
|
+
yield buffer;
|
|
142
|
+
buffer = [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Yield any remaining items
|
|
146
|
+
if (buffer.length > 0) {
|
|
147
|
+
setRowsReceived(count);
|
|
148
|
+
yield buffer;
|
|
149
|
+
}
|
|
174
150
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
setRowsReceived(count)
|
|
179
|
-
yield buffer
|
|
151
|
+
catch (err) {
|
|
152
|
+
setError(err);
|
|
153
|
+
throw err;
|
|
180
154
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
[
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
stream,
|
|
198
|
-
isStreaming,
|
|
199
|
-
error,
|
|
200
|
-
rowsReceived,
|
|
201
|
-
cancel,
|
|
202
|
-
}
|
|
155
|
+
finally {
|
|
156
|
+
setIsStreaming(false);
|
|
157
|
+
}
|
|
158
|
+
}, [graphId]);
|
|
159
|
+
const cancel = (0, react_1.useCallback)(() => {
|
|
160
|
+
clientRef.current?.close();
|
|
161
|
+
setIsStreaming(false);
|
|
162
|
+
}, []);
|
|
163
|
+
return {
|
|
164
|
+
stream,
|
|
165
|
+
isStreaming,
|
|
166
|
+
error,
|
|
167
|
+
rowsReceived,
|
|
168
|
+
cancel,
|
|
169
|
+
};
|
|
203
170
|
}
|
|
204
|
-
|
|
205
171
|
/**
|
|
206
172
|
* Hook for monitoring long-running operations
|
|
207
173
|
*
|
|
208
174
|
* @example
|
|
209
175
|
* ```tsx
|
|
210
|
-
* const { monitor, status, progress, error, result } = useOperation()
|
|
176
|
+
* const { monitor, status, progress, error, result } = useOperation<BackupResult>()
|
|
211
177
|
*
|
|
212
178
|
* const handleBackup = async () => {
|
|
213
179
|
* const { operation_id } = await createBackup({ ... })
|
|
@@ -216,98 +182,86 @@ export function useStreamingQuery(graphId) {
|
|
|
216
182
|
* }
|
|
217
183
|
* ```
|
|
218
184
|
*/
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
185
|
+
function useOperation(operationId) {
|
|
186
|
+
const [status, setStatus] = (0, react_1.useState)('idle');
|
|
187
|
+
const [progress, setProgress] = (0, react_1.useState)(null);
|
|
188
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
189
|
+
const [result, setResult] = (0, react_1.useState)(null);
|
|
190
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
191
|
+
(0, react_1.useEffect)(() => {
|
|
192
|
+
const sdkConfig = (0, config_1.getSDKExtensionsConfig)();
|
|
193
|
+
const clientConfig = client_gen_1.client.getConfig();
|
|
194
|
+
clientRef.current = new OperationClient_1.OperationClient({
|
|
195
|
+
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
196
|
+
credentials: sdkConfig.credentials,
|
|
197
|
+
maxRetries: sdkConfig.maxRetries,
|
|
198
|
+
retryDelay: sdkConfig.retryDelay,
|
|
199
|
+
});
|
|
200
|
+
return () => {
|
|
201
|
+
clientRef.current?.closeAll();
|
|
202
|
+
};
|
|
203
|
+
}, []);
|
|
204
|
+
const monitor = (0, react_1.useCallback)(async (id, timeout) => {
|
|
205
|
+
if (!clientRef.current)
|
|
206
|
+
return null;
|
|
207
|
+
setStatus('running');
|
|
208
|
+
setError(null);
|
|
209
|
+
setResult(null);
|
|
210
|
+
setProgress(null);
|
|
211
|
+
try {
|
|
212
|
+
const opResult = await clientRef.current.monitorOperation(id, {
|
|
213
|
+
onProgress: (p) => {
|
|
214
|
+
setProgress(p);
|
|
215
|
+
},
|
|
216
|
+
onQueueUpdate: (position, estimatedWait) => {
|
|
217
|
+
setProgress({
|
|
218
|
+
message: `Queue position: ${position}`,
|
|
219
|
+
progressPercent: 0,
|
|
220
|
+
details: { position, estimatedWait },
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
timeout,
|
|
224
|
+
});
|
|
225
|
+
setResult(opResult);
|
|
226
|
+
setStatus(opResult.success ? 'completed' : 'error');
|
|
227
|
+
if (!opResult.success && opResult.error) {
|
|
228
|
+
setError(new Error(opResult.error));
|
|
229
|
+
}
|
|
230
|
+
return opResult;
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
const error = err;
|
|
234
|
+
setError(error);
|
|
235
|
+
setStatus('error');
|
|
236
|
+
return null;
|
|
270
237
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
monitor(operationId)
|
|
298
|
-
}
|
|
299
|
-
}, [operationId, monitor, status])
|
|
300
|
-
|
|
301
|
-
return {
|
|
302
|
-
monitor,
|
|
303
|
-
cancel,
|
|
304
|
-
status,
|
|
305
|
-
progress,
|
|
306
|
-
error,
|
|
307
|
-
result,
|
|
308
|
-
}
|
|
238
|
+
}, []);
|
|
239
|
+
const cancel = (0, react_1.useCallback)(async (id) => {
|
|
240
|
+
if (!clientRef.current)
|
|
241
|
+
return;
|
|
242
|
+
try {
|
|
243
|
+
await clientRef.current.cancelOperation(id);
|
|
244
|
+
setStatus('idle');
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
setError(err);
|
|
248
|
+
}
|
|
249
|
+
}, []);
|
|
250
|
+
// Auto-monitor if operationId is provided
|
|
251
|
+
(0, react_1.useEffect)(() => {
|
|
252
|
+
if (operationId && status === 'idle') {
|
|
253
|
+
monitor(operationId);
|
|
254
|
+
}
|
|
255
|
+
}, [operationId, monitor, status]);
|
|
256
|
+
return {
|
|
257
|
+
monitor,
|
|
258
|
+
cancel,
|
|
259
|
+
status,
|
|
260
|
+
progress,
|
|
261
|
+
error,
|
|
262
|
+
result,
|
|
263
|
+
};
|
|
309
264
|
}
|
|
310
|
-
|
|
311
265
|
/**
|
|
312
266
|
* Hook for monitoring multiple operations concurrently
|
|
313
267
|
*
|
|
@@ -325,71 +279,58 @@ export function useOperation(operationId?) {
|
|
|
325
279
|
* }
|
|
326
280
|
* ```
|
|
327
281
|
*/
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
results.size > 0 && Array.from(results.values()).every((r) => r.success || r.error)
|
|
380
|
-
|
|
381
|
-
const hasErrors = errors.size > 0
|
|
382
|
-
|
|
383
|
-
return {
|
|
384
|
-
monitorAll,
|
|
385
|
-
results,
|
|
386
|
-
errors,
|
|
387
|
-
loading,
|
|
388
|
-
allCompleted,
|
|
389
|
-
hasErrors,
|
|
390
|
-
}
|
|
282
|
+
function useMultipleOperations() {
|
|
283
|
+
const [results, setResults] = (0, react_1.useState)(new Map());
|
|
284
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
285
|
+
const [errors, setErrors] = (0, react_1.useState)(new Map());
|
|
286
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
287
|
+
(0, react_1.useEffect)(() => {
|
|
288
|
+
const sdkConfig = (0, config_1.getSDKExtensionsConfig)();
|
|
289
|
+
const clientConfig = client_gen_1.client.getConfig();
|
|
290
|
+
clientRef.current = new OperationClient_1.OperationClient({
|
|
291
|
+
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
292
|
+
credentials: sdkConfig.credentials,
|
|
293
|
+
maxRetries: sdkConfig.maxRetries,
|
|
294
|
+
retryDelay: sdkConfig.retryDelay,
|
|
295
|
+
});
|
|
296
|
+
return () => {
|
|
297
|
+
clientRef.current?.closeAll();
|
|
298
|
+
};
|
|
299
|
+
}, []);
|
|
300
|
+
const monitorAll = (0, react_1.useCallback)(async (operationIds) => {
|
|
301
|
+
if (!clientRef.current)
|
|
302
|
+
return new Map();
|
|
303
|
+
setLoading(true);
|
|
304
|
+
setResults(new Map());
|
|
305
|
+
setErrors(new Map());
|
|
306
|
+
try {
|
|
307
|
+
const allResults = await clientRef.current.monitorMultiple(operationIds);
|
|
308
|
+
setResults(allResults);
|
|
309
|
+
// Extract any errors
|
|
310
|
+
const newErrors = new Map();
|
|
311
|
+
allResults.forEach((result, id) => {
|
|
312
|
+
if (!result.success && result.error) {
|
|
313
|
+
newErrors.set(id, new Error(result.error));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
setErrors(newErrors);
|
|
317
|
+
return allResults;
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
setLoading(false);
|
|
321
|
+
}
|
|
322
|
+
}, []);
|
|
323
|
+
const allCompleted = results.size > 0 && Array.from(results.values()).every((r) => r.success || r.error);
|
|
324
|
+
const hasErrors = errors.size > 0;
|
|
325
|
+
return {
|
|
326
|
+
monitorAll,
|
|
327
|
+
results,
|
|
328
|
+
errors,
|
|
329
|
+
loading,
|
|
330
|
+
allCompleted,
|
|
331
|
+
hasErrors,
|
|
332
|
+
};
|
|
391
333
|
}
|
|
392
|
-
|
|
393
334
|
/**
|
|
394
335
|
* Hook that provides access to all SDK extension clients
|
|
395
336
|
* Useful when you need direct access to the underlying clients
|
|
@@ -402,34 +343,29 @@ export function useMultipleOperations() {
|
|
|
402
343
|
* const result = await clients.query.query('graph_123', 'MATCH (n) RETURN n')
|
|
403
344
|
* ```
|
|
404
345
|
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
operationsClient.closeAll()
|
|
431
|
-
}
|
|
432
|
-
}, [])
|
|
433
|
-
|
|
434
|
-
return clients
|
|
346
|
+
function useSDKClients() {
|
|
347
|
+
const [clients, setClients] = (0, react_1.useState)({
|
|
348
|
+
query: null,
|
|
349
|
+
operations: null,
|
|
350
|
+
});
|
|
351
|
+
(0, react_1.useEffect)(() => {
|
|
352
|
+
const sdkConfig = (0, config_1.getSDKExtensionsConfig)();
|
|
353
|
+
const clientConfig = client_gen_1.client.getConfig();
|
|
354
|
+
const baseConfig = {
|
|
355
|
+
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
356
|
+
credentials: sdkConfig.credentials,
|
|
357
|
+
headers: sdkConfig.headers,
|
|
358
|
+
};
|
|
359
|
+
const queryClient = new QueryClient_1.QueryClient(baseConfig);
|
|
360
|
+
const operationsClient = new OperationClient_1.OperationClient(baseConfig);
|
|
361
|
+
setClients({
|
|
362
|
+
query: queryClient,
|
|
363
|
+
operations: operationsClient,
|
|
364
|
+
});
|
|
365
|
+
return () => {
|
|
366
|
+
queryClient.close();
|
|
367
|
+
operationsClient.closeAll();
|
|
368
|
+
};
|
|
369
|
+
}, []);
|
|
370
|
+
return clients;
|
|
435
371
|
}
|