@dvina/sdk 3.3.124
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/LICENSE +21 -0
- package/README.md +449 -0
- package/dist/_generated_documents-DF34ZUJ3.js +4 -0
- package/dist/_generated_documents-DF34ZUJ3.js.map +1 -0
- package/dist/_generated_documents-W4RHWJ4B.cjs +2041 -0
- package/dist/_generated_documents-W4RHWJ4B.cjs.map +1 -0
- package/dist/adapters/angular/index.cjs +163 -0
- package/dist/adapters/angular/index.cjs.map +1 -0
- package/dist/adapters/angular/index.d.cts +254 -0
- package/dist/adapters/angular/index.d.ts +254 -0
- package/dist/adapters/angular/index.js +159 -0
- package/dist/adapters/angular/index.js.map +1 -0
- package/dist/adapters/react/index.cjs +51 -0
- package/dist/adapters/react/index.cjs.map +1 -0
- package/dist/adapters/react/index.d.cts +62 -0
- package/dist/adapters/react/index.d.ts +62 -0
- package/dist/adapters/react/index.js +49 -0
- package/dist/adapters/react/index.js.map +1 -0
- package/dist/billing/index.cjs +26 -0
- package/dist/billing/index.cjs.map +1 -0
- package/dist/billing/index.d.cts +338 -0
- package/dist/billing/index.d.ts +338 -0
- package/dist/billing/index.js +5 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/chunk-4QKWHQT2.cjs +104 -0
- package/dist/chunk-4QKWHQT2.cjs.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/chunk-7JUBGIQ2.js +1008 -0
- package/dist/chunk-7JUBGIQ2.js.map +1 -0
- package/dist/chunk-7XBJ77RJ.js +103 -0
- package/dist/chunk-7XBJ77RJ.js.map +1 -0
- package/dist/chunk-DHUFVGJR.cjs +20389 -0
- package/dist/chunk-DHUFVGJR.cjs.map +1 -0
- package/dist/chunk-DZUJEN5N.cjs +32 -0
- package/dist/chunk-DZUJEN5N.cjs.map +1 -0
- package/dist/chunk-GDK2HJTF.cjs +1346 -0
- package/dist/chunk-GDK2HJTF.cjs.map +1 -0
- package/dist/chunk-KG3GNTYI.js +1339 -0
- package/dist/chunk-KG3GNTYI.js.map +1 -0
- package/dist/chunk-KV5SP7RP.cjs +114 -0
- package/dist/chunk-KV5SP7RP.cjs.map +1 -0
- package/dist/chunk-NPIKZKLU.cjs +27 -0
- package/dist/chunk-NPIKZKLU.cjs.map +1 -0
- package/dist/chunk-OAAZZUYL.cjs +1517 -0
- package/dist/chunk-OAAZZUYL.cjs.map +1 -0
- package/dist/chunk-P4BYTXZ7.js +98 -0
- package/dist/chunk-P4BYTXZ7.js.map +1 -0
- package/dist/chunk-PDM2KR7T.js +392 -0
- package/dist/chunk-PDM2KR7T.js.map +1 -0
- package/dist/chunk-QOZI2HY5.js +24 -0
- package/dist/chunk-QOZI2HY5.js.map +1 -0
- package/dist/chunk-RFBLNKW6.js +20035 -0
- package/dist/chunk-RFBLNKW6.js.map +1 -0
- package/dist/chunk-UELAE75E.cjs +408 -0
- package/dist/chunk-UELAE75E.cjs.map +1 -0
- package/dist/client-9Rwj21T9.d.cts +77 -0
- package/dist/client-Bskq7sc_.d.ts +77 -0
- package/dist/client-CLhQragb.d.cts +446 -0
- package/dist/client-CLhQragb.d.ts +446 -0
- package/dist/error-CsVoUTY8.d.cts +95 -0
- package/dist/error-CsVoUTY8.d.ts +95 -0
- package/dist/index-BrGSfyXq.d.cts +79 -0
- package/dist/index-zPcVLagO.d.ts +79 -0
- package/dist/index.cjs +1675 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9943 -0
- package/dist/index.d.ts +9943 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/inference/index.cjs +70 -0
- package/dist/inference/index.cjs.map +1 -0
- package/dist/inference/index.d.cts +80 -0
- package/dist/inference/index.d.ts +80 -0
- package/dist/inference/index.js +5 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/pagination/index.cjs +34 -0
- package/dist/pagination/index.cjs.map +1 -0
- package/dist/pagination/index.d.cts +6 -0
- package/dist/pagination/index.d.ts +6 -0
- package/dist/pagination/index.js +5 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/sync-engine-DVKQO-1-.d.cts +423 -0
- package/dist/sync-engine-cLwTqdjv.d.ts +423 -0
- package/dist/types-2RotD0Ab.d.cts +102 -0
- package/dist/types-2RotD0Ab.d.ts +102 -0
- package/package.json +143 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dvina Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
# @dvina/sdk
|
|
2
|
+
|
|
3
|
+
Type-safe SDK for the Dvina GraphQL API. Offline-first architecture with normalized local store (IndexedDB), real-time sync, and framework adapters for Angular and React.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @dvina/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Workspace Development
|
|
12
|
+
|
|
13
|
+
From the repository root:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm bootstrap
|
|
17
|
+
pnpm --filter @dvina/sdk run generate:workspace
|
|
18
|
+
pnpm --filter @dvina/sdk run build
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or use the root shortcut:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm build:sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`generate:workspace` first builds the codegen helper packages, then regenerates SDK sources. `build:workspace` runs the full generate + build flow in one command.
|
|
28
|
+
|
|
29
|
+
Peer dependency:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i graphql
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Framework adapters (optional):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Angular
|
|
39
|
+
npm i @angular/core
|
|
40
|
+
|
|
41
|
+
# React
|
|
42
|
+
npm i react
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { DvinaSdk } from '@dvina/sdk';
|
|
49
|
+
|
|
50
|
+
const sdk = new DvinaSdk({ token: 'your-auth-token' });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For production apps with token refresh:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const sdk = new DvinaSdk({
|
|
57
|
+
getToken: async () => {
|
|
58
|
+
// return a fresh token from your auth provider
|
|
59
|
+
return await authService.getAccessToken();
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Options
|
|
65
|
+
|
|
66
|
+
| Option | Type | Description |
|
|
67
|
+
| ---------- | -------------------------- | ------------------------------------------------------ |
|
|
68
|
+
| `token` | `string` | Static auth token (scripts, CLI, tests) |
|
|
69
|
+
| `getToken` | `() => Promise<string>` | Async token callback (production apps) |
|
|
70
|
+
| `baseUrl` | `string` | API base URL without protocol. Default: `api.dvina.ai` |
|
|
71
|
+
| `language` | `string \| (() => string)` | Preferred language for API responses |
|
|
72
|
+
|
|
73
|
+
## Queries
|
|
74
|
+
|
|
75
|
+
### Fetching a Single Entity
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const chat = await sdk.chat({ id: 'chat-id' }).fetch();
|
|
79
|
+
|
|
80
|
+
console.log(chat.id);
|
|
81
|
+
console.log(chat.title);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Fetching a Connection (List)
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const reports = await sdk.reports({ first: 20 }).fetch();
|
|
88
|
+
|
|
89
|
+
for (const report of reports.nodes) {
|
|
90
|
+
console.log(report.id, report.name);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
console.log(reports.totalCount);
|
|
94
|
+
console.log(reports.pageInfo.hasNextPage);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Smart Fetch (Including Relations)
|
|
98
|
+
|
|
99
|
+
Chain relation methods before `.fetch()` to include related data in a single request:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// Include agent data inline with each chat
|
|
103
|
+
const chats = await sdk.chats({ first: 50 }).agent().fetch();
|
|
104
|
+
|
|
105
|
+
// agent is directly available on each node (no extra request)
|
|
106
|
+
for (const chat of chats.nodes) {
|
|
107
|
+
console.log(chat.agent.id, chat.agent.name);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Single entity with includes
|
|
111
|
+
const chat = await sdk.chat({ id: 'chat-id' }).agent().fetch();
|
|
112
|
+
console.log(chat.agent.name);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Nested includes with variables:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const reports = await sdk.reports({ first: 100 }).insights({ first: 10 }).fetch();
|
|
119
|
+
|
|
120
|
+
for (const report of reports.nodes) {
|
|
121
|
+
for (const insight of report.insights.nodes) {
|
|
122
|
+
console.log(insight.title);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Lazy Relation Fetching
|
|
128
|
+
|
|
129
|
+
Without Smart Fetch, relations are fetched on demand via method calls:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const chat = await sdk.chat({ id: 'chat-id' }).fetch();
|
|
133
|
+
|
|
134
|
+
// Separate request for the agent
|
|
135
|
+
const agent = await chat.agent().fetch();
|
|
136
|
+
console.log(agent.name);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Pagination
|
|
140
|
+
|
|
141
|
+
Connections follow the Relay cursor specification with built-in pagination helpers:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const reports = await sdk.reports({ first: 20 }).fetch();
|
|
145
|
+
|
|
146
|
+
// Load next page (appends nodes, updates pageInfo)
|
|
147
|
+
if (reports.pageInfo.hasNextPage) {
|
|
148
|
+
await reports.fetchNext();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Load previous page (prepends nodes, updates pageInfo)
|
|
152
|
+
if (reports.pageInfo.hasPreviousPage) {
|
|
153
|
+
await reports.fetchPrevious();
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Utility functions:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { extractNodes, mergeConnections } from '@dvina/sdk/pagination';
|
|
161
|
+
|
|
162
|
+
const allNodes = extractNodes(reports);
|
|
163
|
+
|
|
164
|
+
// Returns a new connection without modifying the originals
|
|
165
|
+
const merged = mergeConnections(firstPage, secondPage);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Mutations
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Create
|
|
172
|
+
const agent = await sdk.createAgent({
|
|
173
|
+
data: { name: 'My Agent', description: 'An assistant' },
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Update
|
|
177
|
+
const updated = await sdk.updateReport({
|
|
178
|
+
where: { id: 'report-id' },
|
|
179
|
+
data: { name: 'Updated Name' },
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Delete
|
|
183
|
+
await sdk.deleteChat({ where: { id: 'chat-id' } });
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Mutations automatically update the local store with optimistic updates and cache rules.
|
|
187
|
+
|
|
188
|
+
## Reactive Queries (watch)
|
|
189
|
+
|
|
190
|
+
Use `.watch()` instead of `.fetch()` to get a reactive `DvinaQueryRef` that emits new values whenever the underlying data changes (via local mutations, delta sync, or cache updates):
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const ref = sdk.reports({ first: 20 }).watch();
|
|
194
|
+
|
|
195
|
+
// Vanilla JavaScript — AsyncIterable
|
|
196
|
+
for await (const reports of ref) {
|
|
197
|
+
console.log('Updated:', reports.nodes.length);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Clean up when done
|
|
201
|
+
ref.dispose();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`DvinaQueryRef` properties:
|
|
205
|
+
|
|
206
|
+
| Property/Method | Description |
|
|
207
|
+
| --------------- | ------------------------------------------ |
|
|
208
|
+
| `current` | Most recently emitted value (or undefined) |
|
|
209
|
+
| `refetch()` | Force re-fetch from network |
|
|
210
|
+
| `fetchMore()` | Fetch additional pages and merge |
|
|
211
|
+
| `dispose()` | Unsubscribe and clean up |
|
|
212
|
+
|
|
213
|
+
## Subscriptions
|
|
214
|
+
|
|
215
|
+
Real-time data via WebSocket (graphql-ws protocol):
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
const stream = sdk.sendMessageStream({
|
|
219
|
+
chatId: 'chat-id',
|
|
220
|
+
content: 'Hello!',
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
for await (const event of stream) {
|
|
224
|
+
console.log(event);
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## File Upload
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const file = new File(['content'], 'document.pdf', { type: 'application/pdf' });
|
|
232
|
+
|
|
233
|
+
const result = await sdk.uploadFile(file, 'document.pdf', {
|
|
234
|
+
onProgress: (event) => {
|
|
235
|
+
console.log(`${event.percent}% uploaded`);
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
console.log('File ID:', result.id);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Framework Adapters
|
|
243
|
+
|
|
244
|
+
### Angular
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { toSignal } from '@dvina/sdk/angular';
|
|
248
|
+
|
|
249
|
+
@Component({
|
|
250
|
+
selector: 'app-reports',
|
|
251
|
+
template: `
|
|
252
|
+
@for (report of reports()?.nodes; track report.id) {
|
|
253
|
+
<div>{{ report.name }}</div>
|
|
254
|
+
}
|
|
255
|
+
`,
|
|
256
|
+
})
|
|
257
|
+
class ReportsComponent {
|
|
258
|
+
private sdk = inject(DvinaSdk);
|
|
259
|
+
|
|
260
|
+
reports = toSignal(this.sdk.reports({ first: 20 }).watch());
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`toSignal` automatically disposes the query ref when the component is destroyed via Angular's `DestroyRef`.
|
|
265
|
+
|
|
266
|
+
For usage outside an injection context:
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const destroyRef = inject(DestroyRef);
|
|
270
|
+
|
|
271
|
+
// Later, in a method:
|
|
272
|
+
this.reports = toSignal(ref, { destroyRef });
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### `dvnResource`
|
|
276
|
+
|
|
277
|
+
A resource primitive inspired by Angular's `resource()` API. It wraps both `Promise` (`.fetch()`) and `AsyncIterable` (`.watch()`) loaders into a signal-based interface with status and error tracking.
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { dvnResource } from '@dvina/sdk/angular';
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**With reactive params — one-shot fetch (Promise):**
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
@Component({ ... })
|
|
287
|
+
class UserComponent {
|
|
288
|
+
private sdk = inject(DvinaSdk);
|
|
289
|
+
userId = input.required<string>();
|
|
290
|
+
|
|
291
|
+
userResource = dvnResource({
|
|
292
|
+
params: () => ({ id: this.userId() }),
|
|
293
|
+
loader: ({ params }) => this.sdk.user(params).fetch(),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// template:
|
|
297
|
+
// @if (userResource.isLoading()) { <spinner /> }
|
|
298
|
+
// @if (userResource.value(); as user) { <h1>{{ user.name }}</h1> }
|
|
299
|
+
// @if (userResource.error(); as err) { <p>{{ err.message }}</p> }
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**With reactive params — live query (AsyncIterable):**
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
@Component({ ... })
|
|
307
|
+
class ReportsComponent {
|
|
308
|
+
private sdk = inject(DvinaSdk);
|
|
309
|
+
|
|
310
|
+
reportsResource = dvnResource({
|
|
311
|
+
params: () => ({ first: 20 }),
|
|
312
|
+
loader: ({ params }) => this.sdk.reports(params).watch(),
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Value updates automatically whenever the underlying store changes
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Without params — runs immediately:**
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
configResource = dvnResource({
|
|
323
|
+
loader: () => this.sdk.config().fetch(),
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
The loader return type is detected at runtime:
|
|
328
|
+
|
|
329
|
+
- Returns a `Promise` → resolved once, status becomes `'resolved'`
|
|
330
|
+
- Returns an `AsyncIterable` / `DvinaQueryRef` → consumed as a live stream, value updates on every emission
|
|
331
|
+
|
|
332
|
+
When `params()` returns `undefined`, the resource enters `'idle'` status and the loader does not run. This is useful for conditional fetching:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
reportResource = dvnResource({
|
|
336
|
+
params: () => {
|
|
337
|
+
const id = this.reportId();
|
|
338
|
+
return id ? { id } : undefined; // undefined → idle, no request
|
|
339
|
+
},
|
|
340
|
+
loader: ({ params }) => this.sdk.report(params).fetch(),
|
|
341
|
+
});
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**`DvnResourceRef` API:**
|
|
345
|
+
|
|
346
|
+
| Property/Method | Type | Description |
|
|
347
|
+
| --------------- | ---------------------------- | --------------------------------------------------------------------- |
|
|
348
|
+
| `value` | `Signal<T \| undefined>` | Most recently resolved value |
|
|
349
|
+
| `status` | `Signal<DvnResourceStatus>` | `'idle'` \| `'loading'` \| `'reloading'` \| `'resolved'` \| `'error'` |
|
|
350
|
+
| `isLoading` | `Signal<boolean>` | `true` when `'loading'` or `'reloading'` |
|
|
351
|
+
| `error` | `Signal<Error \| undefined>` | Last error thrown by the loader |
|
|
352
|
+
| `hasValue()` | `boolean` | Whether `value()` is not `undefined` |
|
|
353
|
+
| `reload()` | `void` | Re-run the loader with current params |
|
|
354
|
+
| `destroy()` | `void` | Abort/dispose active loader, reset to `'idle'` |
|
|
355
|
+
|
|
356
|
+
Cleanup is automatic via `DestroyRef` — the loader is aborted (Promise) or disposed (AsyncIterable) when the component is destroyed.
|
|
357
|
+
|
|
358
|
+
### React
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
import { useLiveQuery } from '@dvina/sdk/react';
|
|
362
|
+
|
|
363
|
+
function ReportsPage() {
|
|
364
|
+
const reports = useLiveQuery(() => sdk.reports({ first: 20 }).watch(), []);
|
|
365
|
+
|
|
366
|
+
if (!reports) return <div>Loading...</div>;
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<ul>
|
|
370
|
+
{reports.nodes.map((r) => (
|
|
371
|
+
<li key={r.id}>{r.name}</li>
|
|
372
|
+
))}
|
|
373
|
+
</ul>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
The factory function is memoized internally — the query ref is only created when the dependency array changes. This prevents infinite dispose-subscribe loops that would occur with inline `.watch()` calls.
|
|
379
|
+
|
|
380
|
+
```tsx
|
|
381
|
+
// Reactive query — ref recreated when `id` changes
|
|
382
|
+
function ReportDetail({ id }: { id: string }) {
|
|
383
|
+
const report = useLiveQuery(() => sdk.report({ id }).watch(), [id]);
|
|
384
|
+
|
|
385
|
+
if (!report) return <div>Loading...</div>;
|
|
386
|
+
return <h1>{report.name}</h1>;
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
`useLiveQuery` automatically disposes the query ref when the component unmounts or when dependencies change.
|
|
391
|
+
|
|
392
|
+
## Error Handling
|
|
393
|
+
|
|
394
|
+
The SDK provides a typed error hierarchy:
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
import { DvinaError, DvinaGraphQLError, DvinaNetworkError, DvinaAuthenticationError } from '@dvina/sdk';
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
await sdk.chat({ id: 'invalid' }).fetch();
|
|
401
|
+
} catch (error) {
|
|
402
|
+
if (error instanceof DvinaAuthenticationError) {
|
|
403
|
+
// 401/403 — redirect to login
|
|
404
|
+
} else if (error instanceof DvinaGraphQLError) {
|
|
405
|
+
// Server returned GraphQL errors
|
|
406
|
+
console.error(error.errors);
|
|
407
|
+
} else if (error instanceof DvinaNetworkError) {
|
|
408
|
+
// Connection failure, timeout, etc.
|
|
409
|
+
console.error(error.status);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
| Error Class | When |
|
|
415
|
+
| -------------------------- | ------------------------------------- |
|
|
416
|
+
| `DvinaError` | Base class for all SDK errors |
|
|
417
|
+
| `DvinaGraphQLError` | GraphQL response contains errors |
|
|
418
|
+
| `DvinaNetworkError` | Network failure, timeout, non-OK HTTP |
|
|
419
|
+
| `DvinaAuthenticationError` | 401/403 authentication failure |
|
|
420
|
+
|
|
421
|
+
## Architecture
|
|
422
|
+
|
|
423
|
+
The SDK uses an **offline-first, normalized store** architecture:
|
|
424
|
+
|
|
425
|
+
- **Queries** are routed through the `SyncEngine`, which normalizes GraphQL responses into entity tables in IndexedDB (via Dexie).
|
|
426
|
+
- **Mutations** apply optimistic updates immediately, then reconcile with server responses.
|
|
427
|
+
- **Delta Sync** maintains a persistent SSE connection that streams entity changes, keeping the local store up to date in real-time.
|
|
428
|
+
- **Reactive queries** (`watch()`) are backed by Dexie's `liveQuery` — any write to a relevant table automatically re-emits.
|
|
429
|
+
|
|
430
|
+
```
|
|
431
|
+
DvinaSdk
|
|
432
|
+
├── Queries/Mutations → HTTP Transport → SyncEngine → IndexedDB (Dexie)
|
|
433
|
+
├── Subscriptions → WebSocket Transport (graphql-ws)
|
|
434
|
+
└── Delta Sync → SSE Transport → IndexedDB (Dexie)
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## Cleanup
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
// Stop delta sync
|
|
441
|
+
sdk.stopSync();
|
|
442
|
+
|
|
443
|
+
// Full teardown (stops sync, terminates WebSocket)
|
|
444
|
+
sdk.destroy();
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## License
|
|
448
|
+
|
|
449
|
+
MIT
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ActionAvgAggregateFragmentDoc, ActionCountAggregateFragmentDoc, ActionFragmentDoc, ActionMaxAggregateFragmentDoc, ActionMinAggregateFragmentDoc, ActionSumAggregateFragmentDoc, ActionType, ActiveWindowType, AddInsightToReportDocument, AddTeamMemberDocument, AgentConnectionFragmentDoc, AgentCountAggregateFragmentDoc, AgentDocument, AgentFragmentDoc, AgentMaxAggregateFragmentDoc, AgentMinAggregateFragmentDoc, AgentOrderByRelevanceFieldEnum, Agent_ChatsDocument, Agent_DocumentsDocument, AgentsDocument, AiResourceType, AudioEventOutputFragmentDoc, CancelOauthFlowDocument, CancelWorkspaceDeletionDocument, CapabilityType, ChatConnectionFragmentDoc, ChatCountAggregateFragmentDoc, ChatDocument, ChatFragmentDoc, ChatMaxAggregateFragmentDoc, ChatMessageConnectionFragmentDoc, ChatMessageCountAggregateFragmentDoc, ChatMessageDocument, ChatMessageFragmentDoc, ChatMessageFromEnum, ChatMessageMaxAggregateFragmentDoc, ChatMessageMinAggregateFragmentDoc, ChatMessageOrderByRelevanceFieldEnum, ChatMessage_AttachmentsDocument, ChatMessage_Attachments_ChatDocument, ChatMessage_Attachments_DataSourceDocument, ChatMessage_Attachments_FolderDocument, ChatMessage_Attachments_InsightDocument, ChatMessage_Attachments_PublicDocument, ChatMessage_Attachments_ReportDocument, ChatMessage_Attachments_TableDocument, ChatMessage_ChatDocument, ChatMessage_Chat_AgentDocument, ChatMessage_Chat_InsightDocument, ChatMessage_Chat_ResourceDocument, ChatMessage_ContentsDocument, ChatMessage_Contents_MasksDocument, ChatMessage_FeedbackDocument, ChatMessagesDocument, ChatMinAggregateFragmentDoc, ChatOrderByRelevanceFieldEnum, ChatTitleEventOutputFragmentDoc, Chat_AgentDocument, Chat_InsightDocument, Chat_Insight_ReportMembersDocument, Chat_Insight_ResourceDocument, Chat_MessagesDocument, Chat_ResourceDocument, Chat_Resource_DataSourceDocument, Chat_Resource_FolderDocument, Chat_Resource_InsightDocument, Chat_Resource_PublicDocument, Chat_Resource_ReportDocument, Chat_Resource_TableDocument, ChatsDocument, CloseToPublicDocument, ContentBlockAvgAggregateFragmentDoc, ContentBlockCountAggregateFragmentDoc, ContentBlockFragmentDoc, ContentBlockMaxAggregateFragmentDoc, ContentBlockMinAggregateFragmentDoc, ContentBlockSumAggregateFragmentDoc, ContentBlockType, ContentMaskCountAggregateFragmentDoc, ContentMaskFragmentDoc, ContentMaskMaxAggregateFragmentDoc, ContentMaskMinAggregateFragmentDoc, ContinueInterpretationDocument, CreateAgentDocument, CreateChatDocument, CreateDataSourceDocument, CreateFeedbackDocument, CreateFolderDocument, CreateInsightDocument, CreateIntegratedDataSourceDocument, CreateIntegrationDocument, CreateIntegrationOutputFragmentDoc, CreateRelationDocument, CreateReportDocument, CreateTableDocument, CreateTeamDocument, CubeModelCountAggregateFragmentDoc, CubeModelFragmentDoc, CubeModelMaxAggregateFragmentDoc, CubeModelMinAggregateFragmentDoc, DataSourceCategoryEnum, DataSourceConnectionFragmentDoc, DataSourceCountAggregateFragmentDoc, DataSourceDocument, DataSourceFragmentDoc, DataSourceMaxAggregateFragmentDoc, DataSourceMinAggregateFragmentDoc, DataSourceOrderByRelevanceFieldEnum, DataSourceType, DataSourceTypeDetailsAvgAggregateFragmentDoc, DataSourceTypeDetailsConnectionFragmentDoc, DataSourceTypeDetailsCountAggregateFragmentDoc, DataSourceTypeDetailsFragmentDoc, DataSourceTypeDetailsIconType, DataSourceTypeDetailsMaxAggregateFragmentDoc, DataSourceTypeDetailsMinAggregateFragmentDoc, DataSourceTypeDetailsOrderByRelevanceFieldEnum, DataSourceTypeDetailsSumAggregateFragmentDoc, DataSourceTypeDocument, DataSourceType_DataSourcesDocument, DataSourceTypesDocument, DataSource_ContentsDocument, DataSource_IntegratedSourceDocument, DataSource_IntegratedSource_IntegrationDocument, DataSource_ResourceDocument, DataSource_Resource_ChatDocument, DataSource_Resource_FolderDocument, DataSource_Resource_InsightDocument, DataSource_Resource_PublicDocument, DataSource_Resource_ReportDocument, DataSource_Resource_TableDocument, DataSource_TablesDocument, DataSource_TypeDetailsDocument, DataSourcesDocument, DeepAnalysisUsageAvgAggregateFragmentDoc, DeepAnalysisUsageCountAggregateFragmentDoc, DeepAnalysisUsageFragmentDoc, DeepAnalysisUsageMaxAggregateFragmentDoc, DeepAnalysisUsageMinAggregateFragmentDoc, DeepAnalysisUsageSumAggregateFragmentDoc, DeepAnalyzeDocument, DeleteAgentDocument, DeleteChatDocument, DeleteDataSourceDocument, DeleteFolderDocument, DeleteInsightDocument, DeleteInsightsDocument, DeleteIntegrationDocument, DeleteRelationDocument, DeleteReportDocument, DeleteTableDocument, DeleteTeamDocument, DevAccessTokenOutputFragmentDoc, DocumentContentAvgAggregateFragmentDoc, DocumentContentCountAggregateFragmentDoc, DocumentContentFragmentDoc, DocumentContentMaxAggregateFragmentDoc, DocumentContentMinAggregateFragmentDoc, DocumentContentSumAggregateFragmentDoc, DriveItemFragmentDoc, DropConnectionDocument, EntitlementTier, ExportDocument, ExportWithInsightIdDocument, FeedbackCountAggregateFragmentDoc, FeedbackFragmentDoc, FeedbackMaxAggregateFragmentDoc, FeedbackMinAggregateFragmentDoc, FeedbackOrderByRelevanceFieldEnum, FeedbackType, FileAvgAggregateFragmentDoc, FileCountAggregateFragmentDoc, FileDocument, FileFragmentDoc, FileMaxAggregateFragmentDoc, FileMetaDocument, FileMinAggregateFragmentDoc, FileModelFragmentDoc, FileSumAggregateFragmentDoc, FinalContentEventOutputFragmentDoc, FindFitTierDocument, FolderConnectionFragmentDoc, FolderCountAggregateFragmentDoc, FolderDocument, FolderFragmentDoc, FolderMaxAggregateFragmentDoc, FolderMinAggregateFragmentDoc, FolderOrderByRelevanceFieldEnum, Folder_ResourceDocument, Folder_Resource_ChatDocument, Folder_Resource_DataSourceDocument, Folder_Resource_InsightDocument, Folder_Resource_PublicDocument, Folder_Resource_ReportDocument, Folder_Resource_TableDocument, FoldersDocument, GenerateUploadUriDocument, GetAccessTokenDocument, GetAuthUrlDocument, GetCapabilityDocument, GetDevAccessTokenDocument, GetLimitDocument, GetRemainingDocument, GetSchemaWithIdDocument, GetSchemaWithParamsDocument, GetTokenUsageByModelDocument, GetTokenUsageHistoryDocument, GetTokenUsageStatusDocument, GetTokenUsageStatus_WindowsDocument, GetTokenUsageStatus_Windows_DayDocument, GetTokenUsageStatus_Windows_FiveHourDocument, GetTokenUsageStatus_Windows_WeekDocument, GetUsageDocument, GetVectorStoreStatesDocument, GetZombieDocumentsDocument, IndexContentObjectFragmentDoc, IndexType, InsightConnectionFragmentDoc, InsightCountAggregateFragmentDoc, InsightDocument, InsightFragmentDoc, InsightMaxAggregateFragmentDoc, InsightMinAggregateFragmentDoc, InsightOrderByRelevanceFieldEnum, Insight_ChatDocument, Insight_Chat_AgentDocument, Insight_Chat_ResourceDocument, Insight_ReportMembersDocument, Insight_ReportMembers_ReportDocument, Insight_ReportsDocument, Insight_ResourceDocument, Insight_Resource_ChatDocument, Insight_Resource_DataSourceDocument, Insight_Resource_FolderDocument, Insight_Resource_PublicDocument, Insight_Resource_ReportDocument, Insight_Resource_TableDocument, InsightsDocument, IntegratedSourceCountAggregateFragmentDoc, IntegratedSourceFragmentDoc, IntegratedSourceMaxAggregateFragmentDoc, IntegratedSourceMinAggregateFragmentDoc, IntegratedSourceResponseFragmentDoc, IntegrationCountAggregateFragmentDoc, IntegrationFragmentDoc, IntegrationMaxAggregateFragmentDoc, IntegrationMinAggregateFragmentDoc, IntegrationType, InterpretationConnectionFragmentDoc, InterpretationCountAggregateFragmentDoc, InterpretationFragmentDoc, InterpretationMaxAggregateFragmentDoc, InterpretationMinAggregateFragmentDoc, InterpretationOrderByRelevanceFieldEnum, InterpretationType, InterpretationsDocument, InvocationAvgAggregateFragmentDoc, InvocationCountAggregateFragmentDoc, InvocationFragmentDoc, InvocationMaxAggregateFragmentDoc, InvocationMinAggregateFragmentDoc, InvocationSumAggregateFragmentDoc, LimitType, ListItemsDocument, ListItems_ItemsDocument, McpAuthUpdateModelFragmentDoc, McpAuthUpdatesDocument, McpClientInformationCountAggregateFragmentDoc, McpClientInformationFragmentDoc, McpClientInformationMaxAggregateFragmentDoc, McpClientInformationMinAggregateFragmentDoc, McpCodeVerifierCountAggregateFragmentDoc, McpCodeVerifierFragmentDoc, McpCodeVerifierMaxAggregateFragmentDoc, McpCodeVerifierMinAggregateFragmentDoc, McpServerCountAggregateFragmentDoc, McpServerFragmentDoc, McpServerMaxAggregateFragmentDoc, McpServerMinAggregateFragmentDoc, McpTokensCountAggregateFragmentDoc, McpTokensFragmentDoc, McpTokensMaxAggregateFragmentDoc, McpTokensMinAggregateFragmentDoc, McpToolCountAggregateFragmentDoc, McpToolFragmentDoc, McpToolMaxAggregateFragmentDoc, McpToolMinAggregateFragmentDoc, MessageEndEventOutputFragmentDoc, MessageStartEventOutputFragmentDoc, MinTierBySourceDocument, ModelTokenUsageFragmentDoc, NotUsedDataSourceTypesDocument, NotificationCategory, NotificationConnectionFragmentDoc, NotificationCountAggregateFragmentDoc, NotificationDocument, NotificationFragmentDoc, NotificationMaxAggregateFragmentDoc, NotificationMinAggregateFragmentDoc, NotificationOrderByRelevanceFieldEnum, NotificationPriority, NotificationStatus, NotificationUpdatesDocument, NotificationsByReferenceDocument, NotificationsDocument, NullsOrder, OAuthCredentialCountAggregateFragmentDoc, OAuthCredentialFragmentDoc, OAuthCredentialMaxAggregateFragmentDoc, OAuthCredentialMinAggregateFragmentDoc, OAuthResultFragmentDoc, OauthResultDocument, OpenToPublicDocument, OpenToWorkspaceDocument, PageInfoFragmentDoc, PaginatedDriveItemsFragmentDoc, Presentation, PrivacyStatsDocument, PrivacyStatsFragmentDoc, QueryDocument, QueryMode, QueryWithInsightIdDocument, QueryWithMessageIdDocument, ReasoningEventOutputFragmentDoc, RefreshSchemaDocument, ReinterpretSourceDocument, ReinterpretSourcesOfuserDocument, RelationCountAggregateFragmentDoc, RelationDocument, RelationFragmentDoc, RelationMaxAggregateFragmentDoc, RelationMinAggregateFragmentDoc, RelationType, Relation_FromTableDocument, Relation_FromTable_DataSourceDocument, Relation_FromTable_ResourceDocument, Relation_ToTableDocument, Relation_ToTable_DataSourceDocument, Relation_ToTable_ResourceDocument, RelocateInsightDocument, RemoveInsightFromReportDocument, RemoveTeamMemberDocument, RepopulareVectorStoreDocument, ReportConnectionFragmentDoc, ReportCountAggregateFragmentDoc, ReportDocument, ReportFragmentDoc, ReportMaxAggregateFragmentDoc, ReportMemberAvgAggregateFragmentDoc, ReportMemberCountAggregateFragmentDoc, ReportMemberFragmentDoc, ReportMemberMaxAggregateFragmentDoc, ReportMemberMinAggregateFragmentDoc, ReportMemberSize, ReportMemberSumAggregateFragmentDoc, ReportMinAggregateFragmentDoc, ReportOrderByRelevanceFieldEnum, Report_InsightsDocument, Report_LayoutDocument, Report_Layout_InsightDocument, Report_ResourceDocument, Report_Resource_ChatDocument, Report_Resource_DataSourceDocument, Report_Resource_FolderDocument, Report_Resource_InsightDocument, Report_Resource_PublicDocument, Report_Resource_TableDocument, ReportsDocument, ResetWorkspaceDocument, ResourceConnectionFragmentDoc, ResourceCountAggregateFragmentDoc, ResourceDocument, ResourceFragmentDoc, ResourceMaxAggregateFragmentDoc, ResourceMinAggregateFragmentDoc, ResourceOrderByRelevanceFieldEnum, ResourcePrivilege, ResourcePublicCountAggregateFragmentDoc, ResourcePublicFragmentDoc, ResourcePublicMaxAggregateFragmentDoc, ResourcePublicMinAggregateFragmentDoc, ResourceSharingConnectionFragmentDoc, ResourceSharingCountAggregateFragmentDoc, ResourceSharingFragmentDoc, ResourceSharingMaxAggregateFragmentDoc, ResourceSharingMinAggregateFragmentDoc, ResourceSharingOrderByRelevanceFieldEnum, ResourceType, Resource_AgentsDocument, Resource_AttachedChatMessagesDocument, Resource_ChatDocument, Resource_Chat_AgentDocument, Resource_Chat_InsightDocument, Resource_DataSourceDocument, Resource_DataSource_ContentsDocument, Resource_DataSource_IntegratedSourceDocument, Resource_DataSource_TypeDetailsDocument, Resource_FolderDocument, Resource_InsightDocument, Resource_Insight_ChatDocument, Resource_Insight_ReportMembersDocument, Resource_PublicDocument, Resource_ReportDocument, Resource_Report_LayoutDocument, Resource_SharedWithDocument, Resource_TableDocument, Resource_Table_DataSourceDocument, Resource_Table_FromRelationsDocument, Resource_Table_ToRelationsDocument, ResourcesDocument, ScheduleWorkspaceDeletionDocument, SearchDocument, SendMessageModel, SendMessageStreamDocument, SetPrimaryKeyDocument, ShareResourceDocument, SharingDocument, Sharing_ResourceDocument, Sharing_Resource_ChatDocument, Sharing_Resource_DataSourceDocument, Sharing_Resource_FolderDocument, Sharing_Resource_InsightDocument, Sharing_Resource_PublicDocument, Sharing_Resource_ReportDocument, Sharing_Resource_TableDocument, Sharing_TeamDocument, SharingsDocument, SortOrder, SyncCubeFilesFromDbDocument, SyncEventAvgAggregateFragmentDoc, SyncEventCountAggregateFragmentDoc, SyncEventFragmentDoc, SyncEventMaxAggregateFragmentDoc, SyncEventMinAggregateFragmentDoc, SyncEventSumAggregateFragmentDoc, TableConnectionFragmentDoc, TableCountAggregateFragmentDoc, TableDocument, TableFragmentDoc, TableMaxAggregateFragmentDoc, TableMinAggregateFragmentDoc, TableOrderByRelevanceFieldEnum, TableStatus, Table_DataSourceDocument, Table_DataSource_ContentsDocument, Table_DataSource_IntegratedSourceDocument, Table_DataSource_ResourceDocument, Table_DataSource_TypeDetailsDocument, Table_FromRelationsDocument, Table_ResourceDocument, Table_Resource_ChatDocument, Table_Resource_DataSourceDocument, Table_Resource_FolderDocument, Table_Resource_InsightDocument, Table_Resource_PublicDocument, Table_Resource_ReportDocument, Table_ToRelationsDocument, TablesDocument, TeamConnectionFragmentDoc, TeamCountAggregateFragmentDoc, TeamDocument, TeamFragmentDoc, TeamMaxAggregateFragmentDoc, TeamMinAggregateFragmentDoc, TeamOrderByRelevanceFieldEnum, TeamsDocument, TextBlockEventOutputFragmentDoc, TextDeltaEventOutputFragmentDoc, TokenUsageAvgAggregateFragmentDoc, TokenUsageCountAggregateFragmentDoc, TokenUsageFragmentDoc, TokenUsageLimit, TokenUsageMaxAggregateFragmentDoc, TokenUsageMinAggregateFragmentDoc, TokenUsageSumAggregateFragmentDoc, TokenUsageUpdatesDocument, ToolInputDeltaEventOutputFragmentDoc, ToolResultEventOutputFragmentDoc, ToolStartEventOutputFragmentDoc, UnshareResourceDocument, UpdateAgentDocument, UpdateChatDocument, UpdateDataSourceDocument, UpdateFolderDocument, UpdateInsightDocument, UpdateInsightInReportDocument, UpdateInterpDocument, UpdateRelationDocument, UpdateReportDocument, UpdateResourceDocument, UpdateResourceSharingDocument, UpdateTableDocument, UpdateTeamDocument, UsageHistoryGranularity, UsageMetaOutputFragmentDoc, UsageStatusFragmentDoc, UsageWindowsDocument, UsageWindowsStatusTypeFragmentDoc, UsageWindowsUpdatesDocument, UsageWindows_DayDocument, UsageWindows_FiveHourDocument, UsageWindows_WeekDocument, WindowDetailTypeFragmentDoc, WorkspaceDeleteScheduleCountAggregateFragmentDoc, WorkspaceDeleteScheduleFragmentDoc, WorkspaceDeleteScheduleMaxAggregateFragmentDoc, WorkspaceDeleteScheduleMinAggregateFragmentDoc, WorkspaceDeletionScheduleDocument } from './chunk-7JUBGIQ2.js';
|
|
2
|
+
import './chunk-5WRI5ZAA.js';
|
|
3
|
+
//# sourceMappingURL=_generated_documents-DF34ZUJ3.js.map
|
|
4
|
+
//# sourceMappingURL=_generated_documents-DF34ZUJ3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"_generated_documents-DF34ZUJ3.js"}
|