@robosystems/client 0.1.15 → 0.1.17

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.
Files changed (67) hide show
  1. package/extensions/hooks.d.ts +1 -1
  2. package/package.json +48 -6
  3. package/sdk/client/client.gen.d.ts +2 -0
  4. package/sdk/client/client.gen.js +153 -0
  5. package/sdk/client/client.gen.ts +200 -0
  6. package/sdk/client/index.d.ts +7 -0
  7. package/sdk/client/index.js +15 -0
  8. package/sdk/client/index.ts +25 -0
  9. package/sdk/client/types.gen.d.ts +122 -0
  10. package/sdk/client/types.gen.js +4 -0
  11. package/sdk/client/types.gen.ts +233 -0
  12. package/sdk/client/utils.gen.d.ts +45 -0
  13. package/sdk/client/utils.gen.js +296 -0
  14. package/sdk/client/utils.gen.ts +419 -0
  15. package/sdk/client.gen.d.ts +12 -0
  16. package/sdk/client.gen.js +8 -0
  17. package/sdk/client.gen.ts +18 -0
  18. package/sdk/core/auth.gen.d.ts +18 -0
  19. package/sdk/core/auth.gen.js +18 -0
  20. package/sdk/core/auth.gen.ts +42 -0
  21. package/sdk/core/bodySerializer.gen.d.ts +17 -0
  22. package/sdk/core/bodySerializer.gen.js +57 -0
  23. package/sdk/core/bodySerializer.gen.ts +90 -0
  24. package/sdk/core/params.gen.d.ts +33 -0
  25. package/sdk/core/params.gen.js +92 -0
  26. package/sdk/core/params.gen.ts +153 -0
  27. package/sdk/core/pathSerializer.gen.d.ts +33 -0
  28. package/sdk/core/pathSerializer.gen.js +123 -0
  29. package/sdk/core/pathSerializer.gen.ts +181 -0
  30. package/sdk/core/types.gen.d.ts +78 -0
  31. package/sdk/core/types.gen.js +4 -0
  32. package/sdk/core/types.gen.ts +121 -0
  33. package/sdk/index.d.ts +2 -0
  34. package/sdk/index.js +19 -0
  35. package/sdk/index.ts +3 -0
  36. package/sdk/sdk.gen.d.ts +1249 -0
  37. package/sdk/sdk.gen.js +2572 -0
  38. package/sdk/sdk.gen.ts +2585 -0
  39. package/sdk/types.gen.d.ts +6347 -0
  40. package/sdk/types.gen.js +3 -0
  41. package/sdk/types.gen.ts +6852 -0
  42. package/sdk-extensions/OperationClient.d.ts +64 -0
  43. package/sdk-extensions/OperationClient.js +251 -0
  44. package/sdk-extensions/OperationClient.ts +322 -0
  45. package/sdk-extensions/QueryClient.d.ts +50 -0
  46. package/sdk-extensions/QueryClient.js +190 -0
  47. package/sdk-extensions/QueryClient.ts +283 -0
  48. package/sdk-extensions/README.md +672 -0
  49. package/sdk-extensions/SSEClient.d.ts +48 -0
  50. package/sdk-extensions/SSEClient.js +148 -0
  51. package/sdk-extensions/SSEClient.ts +189 -0
  52. package/sdk-extensions/config.d.ts +32 -0
  53. package/sdk-extensions/config.js +74 -0
  54. package/sdk-extensions/config.ts +91 -0
  55. package/sdk-extensions/hooks.d.ts +110 -0
  56. package/sdk-extensions/hooks.js +371 -0
  57. package/sdk-extensions/hooks.ts +438 -0
  58. package/sdk-extensions/index.d.ts +46 -0
  59. package/sdk-extensions/index.js +110 -0
  60. package/sdk-extensions/index.ts +123 -0
  61. package/sdk.gen.d.ts +210 -104
  62. package/sdk.gen.js +409 -287
  63. package/sdk.gen.ts +404 -282
  64. package/types.gen.d.ts +1218 -567
  65. package/types.gen.ts +1236 -566
  66. package/openapi-ts.config.js +0 -9
  67. package/prepare.js +0 -220
@@ -0,0 +1,371 @@
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;
9
+ /**
10
+ * React hooks for SDK extensions
11
+ * Provides easy-to-use hooks for Next.js/React applications
12
+ */
13
+ const react_1 = require("react");
14
+ const client_gen_1 = require("../sdk/client.gen");
15
+ const config_1 = require("./config");
16
+ const OperationClient_1 = require("./OperationClient");
17
+ const QueryClient_1 = require("./QueryClient");
18
+ /**
19
+ * Hook for executing Cypher queries with loading states and error handling
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { execute, loading, error, data } = useQuery('graph_123')
24
+ *
25
+ * const handleSearch = async () => {
26
+ * const result = await execute('MATCH (n:Company) RETURN n LIMIT 10')
27
+ * console.log(result.data)
28
+ * }
29
+ * ```
30
+ */
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
+ };
93
+ }
94
+ /**
95
+ * Hook for streaming large query results
96
+ *
97
+ * @example
98
+ * ```tsx
99
+ * const { stream, isStreaming, error, cancel } = useStreamingQuery('graph_123')
100
+ *
101
+ * const handleStream = async () => {
102
+ * const iterator = stream('MATCH (n) RETURN n')
103
+ * for await (const batch of iterator) {
104
+ * console.log('Received batch:', batch)
105
+ * }
106
+ * }
107
+ * ```
108
+ */
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
+ }
150
+ }
151
+ catch (err) {
152
+ setError(err);
153
+ throw err;
154
+ }
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
+ };
170
+ }
171
+ /**
172
+ * Hook for monitoring long-running operations
173
+ *
174
+ * @example
175
+ * ```tsx
176
+ * const { monitor, status, progress, error, result } = useOperation<BackupResult>()
177
+ *
178
+ * const handleBackup = async () => {
179
+ * const { operation_id } = await createBackup({ ... })
180
+ * const result = await monitor(operation_id)
181
+ * console.log('Backup completed:', result)
182
+ * }
183
+ * ```
184
+ */
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;
237
+ }
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
+ };
264
+ }
265
+ /**
266
+ * Hook for monitoring multiple operations concurrently
267
+ *
268
+ * @example
269
+ * ```tsx
270
+ * const { monitorAll, results, allCompleted, hasErrors } = useMultipleOperations()
271
+ *
272
+ * const handleMultiple = async () => {
273
+ * const operations = await Promise.all([
274
+ * createBackup(...),
275
+ * createExport(...),
276
+ * ])
277
+ *
278
+ * const results = await monitorAll(operations.map(op => op.operation_id))
279
+ * }
280
+ * ```
281
+ */
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
+ };
333
+ }
334
+ /**
335
+ * Hook that provides access to all SDK extension clients
336
+ * Useful when you need direct access to the underlying clients
337
+ *
338
+ * @example
339
+ * ```tsx
340
+ * const clients = useSDKClients()
341
+ *
342
+ * // Direct access to clients
343
+ * const result = await clients.query.query('graph_123', 'MATCH (n) RETURN n')
344
+ * ```
345
+ */
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;
371
+ }