@osdk/react 2.94.0 → 2.94.1-main-718be7c10524d5aa3086fbfd38785c0abd0a2c87

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 (64) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -1
  3. package/build/browser/new/platform-apis/admin/useFoundryUser.js.map +1 -1
  4. package/build/browser/new/platform-apis/admin/useFoundryUsersList.js.map +1 -1
  5. package/build/browser/new/useLinks.js.map +1 -1
  6. package/build/browser/new/useObjectSet.js.map +1 -1
  7. package/build/browser/new/useOsdkAggregation.js +2 -5
  8. package/build/browser/new/useOsdkAggregation.js.map +1 -1
  9. package/build/browser/new/useOsdkObjects.js.map +1 -1
  10. package/build/browser/util/UserAgent.js +1 -1
  11. package/build/browser/util/UserAgent.js.map +1 -1
  12. package/build/cjs/{chunk-EJT5W6SI.cjs → chunk-4PFYL4UI.cjs} +3 -3
  13. package/build/cjs/chunk-4PFYL4UI.cjs.map +1 -0
  14. package/build/cjs/index.cjs +15 -15
  15. package/build/cjs/public/experimental.cjs +16 -16
  16. package/build/cjs/public/experimental.d.cts +9 -12
  17. package/build/cjs/public/platform-apis.d.cts +1 -4
  18. package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -1
  19. package/build/esm/new/platform-apis/admin/useFoundryUser.js.map +1 -1
  20. package/build/esm/new/platform-apis/admin/useFoundryUsersList.js.map +1 -1
  21. package/build/esm/new/useLinks.js.map +1 -1
  22. package/build/esm/new/useObjectSet.js.map +1 -1
  23. package/build/esm/new/useOsdkAggregation.js +2 -5
  24. package/build/esm/new/useOsdkAggregation.js.map +1 -1
  25. package/build/esm/new/useOsdkObjects.js.map +1 -1
  26. package/build/esm/util/UserAgent.js +1 -1
  27. package/build/esm/util/UserAgent.js.map +1 -1
  28. package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts +0 -1
  29. package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts.map +1 -1
  30. package/build/types/new/platform-apis/admin/useFoundryUser.d.ts +1 -2
  31. package/build/types/new/platform-apis/admin/useFoundryUser.d.ts.map +1 -1
  32. package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts +0 -1
  33. package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts.map +1 -1
  34. package/build/types/new/useLinks.d.ts +2 -2
  35. package/build/types/new/useObjectSet.d.ts +2 -2
  36. package/build/types/new/useOsdkAggregation.d.ts +3 -6
  37. package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
  38. package/build/types/new/useOsdkObjects.d.ts +2 -2
  39. package/docs/actions.mdx +314 -0
  40. package/docs/aggregations.mdx +256 -0
  41. package/docs/cache-invalidation.mdx +229 -0
  42. package/docs/devtools/cache.mdx +29 -0
  43. package/docs/devtools/components.mdx +40 -0
  44. package/docs/devtools/console.mdx +29 -0
  45. package/docs/devtools/index.mdx +151 -0
  46. package/docs/devtools/overview.mdx +45 -0
  47. package/docs/functions.mdx +246 -0
  48. package/docs/index.mdx +62 -0
  49. package/docs/links.mdx +270 -0
  50. package/docs/meta.json +30 -0
  51. package/docs/object-sets.mdx +296 -0
  52. package/docs/objects.mdx +489 -0
  53. package/docs/optimistic-updates.mdx +164 -0
  54. package/docs/platform-apis.mdx +296 -0
  55. package/docs/testing.mdx +348 -0
  56. package/package.json +6 -6
  57. package/build/cjs/chunk-EJT5W6SI.cjs.map +0 -1
  58. package/docs/actions.md +0 -432
  59. package/docs/advanced-queries.md +0 -678
  60. package/docs/cache-management.md +0 -222
  61. package/docs/getting-started.md +0 -319
  62. package/docs/platform-apis.md +0 -234
  63. package/docs/prerequisites.md +0 -48
  64. package/docs/querying-data.md +0 -810
@@ -1,678 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # Advanced Queries
6
-
7
- This guide covers advanced querying patterns including useObjectSet, derived properties, aggregations, and metadata.
8
-
9
- ## useObjectSet
10
-
11
- Advanced querying with set operations, derived properties, and link traversal.
12
-
13
- ### When to Use useObjectSet vs useOsdkObjects
14
-
15
- Prefer `useOsdkObjects` when both hooks would work. Both support filtering, sorting, pagination, derived properties, pivoting, and streaming updates — they differ in their **starting point**.
16
-
17
- **Use `useOsdkObjects(Type, options)`** when your query starts from an object type or interface.
18
-
19
- **Use `useObjectSet(objectSet, options)`** when you already hold an `ObjectSet` instance you want to observe — typically because:
20
-
21
- - You composed sets with `union` / `intersect` / `subtract`
22
- - You received an `ObjectSet` from another hook (e.g. `useOsdkObjects(...).objectSet`) and want to observe a transformation of it
23
-
24
- Note that `pivotTo` and `streamUpdates` cannot be combined — see the note below.
25
-
26
- ```tsx
27
- import { Todo } from "@my/osdk";
28
- import { useObjectSet, useOsdkObjects } from "@osdk/react";
29
- import client from "./client";
30
-
31
- // Simple query - use useOsdkObjects
32
- const { data: simpleData } = useOsdkObjects(Todo, {
33
- where: { isComplete: false },
34
- orderBy: { createdAt: "desc" },
35
- });
36
-
37
- // Set operations - use useObjectSet
38
- const urgentTodos = client(Todo).where({ isUrgent: true });
39
- const completedTodos = client(Todo).where({ isComplete: true });
40
-
41
- const { data: setData } = useObjectSet(client(Todo), {
42
- union: [urgentTodos],
43
- subtract: [completedTodos],
44
- });
45
- ```
46
-
47
- :::note Building ObjectSets
48
- Call your OSDK client with an object type — `client(Todo)` — to create an `ObjectSet`. You can then filter, union, intersect, or subtract it before passing it to `useObjectSet`. The `client` here is whatever you exported from `createClient(...)` in your app (`./client` in these examples).
49
- :::
50
-
51
- ### Basic Usage
52
-
53
- ```tsx
54
- import { Todo } from "@my/osdk";
55
- import { useObjectSet } from "@osdk/react";
56
- import client from "./client";
57
-
58
- function TodosWithSetOperations() {
59
- const allTodos = client(Todo);
60
- const completedTodos = client(Todo).where({ isComplete: true });
61
-
62
- const { data, isLoading, fetchMore } = useObjectSet(allTodos, {
63
- subtract: [completedTodos],
64
- where: { priority: "high" },
65
- orderBy: { createdAt: "desc" },
66
- pageSize: 20,
67
- });
68
-
69
- return (
70
- <div>
71
- {data?.map(todo => (
72
- <div key={todo.$primaryKey}>
73
- {todo.title}
74
- </div>
75
- ))}
76
- </div>
77
- );
78
- }
79
- ```
80
-
81
- ### Set Operations
82
-
83
- #### Union
84
-
85
- Combine multiple object sets:
86
-
87
- ```tsx
88
- import { Todo } from "@my/osdk";
89
- import { useObjectSet } from "@osdk/react";
90
- import client from "./client";
91
-
92
- function CombinedTodoQuery() {
93
- const highPriorityTodos = client(Todo).where({ priority: "high" });
94
- const urgentTodos = client(Todo).where({ isUrgent: true });
95
-
96
- const { data } = useObjectSet(highPriorityTodos, {
97
- union: [urgentTodos], // High priority OR urgent
98
- });
99
-
100
- return <div>High priority or urgent: {data?.length}</div>;
101
- }
102
- ```
103
-
104
- #### Intersect
105
-
106
- Find objects that exist in all sets:
107
-
108
- ```tsx
109
- import { Todo } from "@my/osdk";
110
- import { useObjectSet } from "@osdk/react";
111
- import client from "./client";
112
-
113
- function StarredAndIncompleteTodos() {
114
- const starred = client(Todo).where({ isStarred: true });
115
- const incomplete = client(Todo).where({ isComplete: false });
116
-
117
- const { data } = useObjectSet(starred, {
118
- intersect: [incomplete],
119
- });
120
-
121
- return (
122
- <div>
123
- <h3>Starred todos that are still open</h3>
124
- {data?.map(todo => <div key={todo.$primaryKey}>{todo.title}</div>)}
125
- </div>
126
- );
127
- }
128
- ```
129
-
130
- #### Subtract
131
-
132
- Remove objects that exist in another set:
133
-
134
- ```tsx
135
- import { Todo } from "@my/osdk";
136
- import { useObjectSet } from "@osdk/react";
137
- import client from "./client";
138
-
139
- function ActiveTodos() {
140
- const allTodos = client(Todo);
141
- const completedTodos = client(Todo).where({ isComplete: true });
142
-
143
- const { data } = useObjectSet(allTodos, {
144
- subtract: [completedTodos],
145
- });
146
-
147
- return <div>Active todos: {data?.length}</div>;
148
- }
149
- ```
150
-
151
- #### Combined Operations
152
-
153
- ```tsx
154
- import { Todo } from "@my/osdk";
155
- import { useObjectSet } from "@osdk/react";
156
- import client from "./client";
157
-
158
- function ComplexTodoQuery() {
159
- const highPriorityTodos = client(Todo).where({ priority: "high" });
160
- const urgentTodos = client(Todo).where({ isUrgent: true });
161
- const completedTodos = client(Todo).where({ isComplete: true });
162
-
163
- const { data } = useObjectSet(highPriorityTodos, {
164
- union: [urgentTodos], // High priority OR urgent
165
- subtract: [completedTodos], // But not completed
166
- });
167
-
168
- return <div>High priority or urgent (but not completed): {data?.length}</div>;
169
- }
170
- ```
171
-
172
- ### Link Traversal with pivotTo
173
-
174
- Navigate to linked objects:
175
-
176
- ```tsx
177
- import { Employee } from "@my/osdk";
178
- import { useObjectSet } from "@osdk/react";
179
- import client from "./client";
180
-
181
- function EmployeeDepartments(
182
- { employee }: { employee: Employee.OsdkInstance },
183
- ) {
184
- const employeeSet = client(Employee).where({ id: employee.id });
185
-
186
- const { data } = useObjectSet(employeeSet, {
187
- pivotTo: "department",
188
- });
189
-
190
- return (
191
- <div>
192
- Departments: {data?.map(dept => dept.name).join(", ")}
193
- </div>
194
- );
195
- }
196
- ```
197
-
198
- ### Auto-Fetching and Streaming
199
-
200
- ```tsx
201
- import { Todo } from "@my/osdk";
202
- import { useObjectSet } from "@osdk/react";
203
- import client from "./client";
204
-
205
- const { data, isLoading } = useObjectSet(client(Todo), {
206
- where: { isComplete: false },
207
- autoFetchMore: 200, // Fetch at least 200 items
208
- streamUpdates: true, // Real-time WebSocket updates
209
- });
210
- ```
211
-
212
- :::note
213
- `streamUpdates` cannot be used together with `pivotTo`. The server does not support
214
- websocket subscriptions for link-traversal queries. Queries using `pivotTo` will
215
- still fetch data normally but won't receive real-time updates.
216
- :::
217
-
218
- ### All Options
219
-
220
- - `where` — Filter objects
221
- - `withProperties` — Add derived/computed properties
222
- - `$select` — Restrict which properties are returned for each object
223
- - `union` — Combine with other ObjectSets
224
- - `intersect` — Find common objects with other ObjectSets
225
- - `subtract` — Remove objects that exist in other ObjectSets
226
- - `pivotTo` — Traverse to linked objects (changes result type). Cannot be combined with `streamUpdates`.
227
- - `pageSize` — Number of objects per page
228
- - `orderBy` — Sort order
229
- - `dedupeIntervalMs` — Minimum time between re-fetches (default: 2000ms)
230
- - `streamUpdates` — Enable real-time websocket updates (default: false). Cannot be combined with `pivotTo` or `withProperties`.
231
- - `autoFetchMore` — Auto-fetch additional pages
232
- - `enabled` — Enable/disable the query
233
-
234
- ### Return Values
235
-
236
- - `data` - Array of objects with derived properties
237
- - `isLoading` - True while fetching
238
- - `error` - Error object if fetch failed
239
- - `fetchMore` - Function to load next page
240
- - `objectSet` - The transformed ObjectSet after all operations
241
-
242
- ---
243
-
244
- ## Derived Properties
245
-
246
- _Available in both useOsdkObjects and useObjectSet_
247
-
248
- Add computed properties calculated server-side using the builder pattern.
249
-
250
- ### Basic Usage
251
-
252
- Derived properties use a builder function that receives a `DerivedProperty.Builder`:
253
-
254
- ```tsx
255
- import { Employee } from "@my/osdk";
256
- import type { DerivedProperty } from "@osdk/client";
257
- import { useOsdkObjects } from "@osdk/react";
258
-
259
- const { data } = useOsdkObjects(Employee, {
260
- where: { department: "Engineering" },
261
- withProperties: {
262
- // Get manager's name via link traversal
263
- managerName: (base: DerivedProperty.Builder<Employee, false>) =>
264
- base.pivotTo("manager").selectProperty("fullName"),
265
-
266
- // Count direct reports
267
- reportCount: (base: DerivedProperty.Builder<Employee, false>) =>
268
- base.pivotTo("reports").aggregate("$count"),
269
- },
270
- });
271
- ```
272
-
273
- ### Builder Methods
274
-
275
- The builder provides these methods:
276
-
277
- - `.pivotTo(linkName)` — Navigate to linked objects
278
- - `.selectProperty(propertyName)` — Select a property value
279
- - `.aggregate(specifier)` — Aggregate values; specifier is `"$count"` or `"propertyName:metric"` (see [Aggregation Syntax](#aggregation-syntax) for the full list)
280
- - `.where(clause)` — Filter before aggregating
281
- - `.constant.{double|integer|long|datetime|timestamp}(value)` — Lift a literal into the builder
282
-
283
- #### What does `DerivedProperty.Builder<Employee, false>` mean?
284
-
285
- You usually don't need this annotation — TypeScript infers it. The flag flips from `false` to `true` after pivoting through a one-to-many link, where you must call `.aggregate()` instead of `.selectProperty()` because there's no single value to select.
286
-
287
- #### When an aggregate has no data
288
-
289
- For numeric aggregates (`sum`, `avg`, `min`, `max`) over an empty result set, the property resolves to `null` rather than a number. `$count` resolves to `0`. Plan your UI for these cases when filtering can produce empty groups.
290
-
291
- ### Advanced Examples
292
-
293
- ```tsx
294
- import { Employee } from "@my/osdk";
295
- import type { DerivedProperty } from "@osdk/client";
296
- import { useOsdkObjects } from "@osdk/react";
297
-
298
- const { data } = useOsdkObjects(Employee, {
299
- where: { department: "Engineering" },
300
- withProperties: {
301
- // Chained traversal
302
- departmentSize: (base: DerivedProperty.Builder<Employee, false>) =>
303
- base.pivotTo("manager")
304
- .pivotTo("reports")
305
- .aggregate("$count"),
306
-
307
- // Aggregate a specific property — `propertyName:metric` keys
308
- avgReportSalary: (base: DerivedProperty.Builder<Employee, false>) =>
309
- base.pivotTo("reports").aggregate("salary:avg"),
310
- },
311
- });
312
- ```
313
-
314
- ### Filtering on Derived Properties
315
-
316
- You can filter on derived properties in your where clause:
317
-
318
- ```tsx
319
- import { Employee } from "@my/osdk";
320
- import type { DerivedProperty } from "@osdk/client";
321
- import { useOsdkObjects } from "@osdk/react";
322
-
323
- const { data } = useOsdkObjects(Employee, {
324
- withProperties: {
325
- reportCount: (base: DerivedProperty.Builder<Employee, false>) =>
326
- base.pivotTo("reports").aggregate("$count"),
327
- },
328
- where: {
329
- department: "Engineering",
330
- reportCount: { $gt: 0 }, // Only managers
331
- },
332
- });
333
- ```
334
-
335
- ---
336
-
337
- ## useOsdkFunction
338
-
339
- Execute and observe functions with request deduplication and configurable dependency tracking for automatic refetching.
340
-
341
- ### Basic Usage
342
-
343
- ```tsx
344
- import { addOne } from "@my/osdk";
345
- import { useOsdkFunction } from "@osdk/react";
346
-
347
- function AddOneDemo() {
348
- const { data, isLoading, error } = useOsdkFunction(addOne, {
349
- params: { n: 5 },
350
- });
351
-
352
- if (isLoading && data === undefined) {
353
- return <div>Calculating...</div>;
354
- }
355
-
356
- if (error) {
357
- return <div>Error: {error.message}</div>;
358
- }
359
-
360
- return <div>Result: {data}</div>;
361
- }
362
- ```
363
-
364
- ### Functions Without Parameters
365
-
366
- ```tsx
367
- import { getTodoCount } from "@my/osdk";
368
- import { useOsdkFunction } from "@osdk/react";
369
-
370
- function TodoCount() {
371
- const { data, isLoading } = useOsdkFunction(getTodoCount);
372
-
373
- return (
374
- <div>
375
- {isLoading && <span>Loading...</span>}
376
- {data !== undefined && <span>Total todos: {data}</span>}
377
- </div>
378
- );
379
- }
380
- ```
381
-
382
- ### Dependency Tracking
383
-
384
- Automatically refetch when actions modify objects of specified types:
385
-
386
- ```tsx
387
- import { Employee, getEmployeeMetrics } from "@my/osdk";
388
- import { useOsdkFunction } from "@osdk/react";
389
-
390
- function EmployeeMetrics({ departmentId }: { departmentId: string }) {
391
- const { data, isLoading, refetch } = useOsdkFunction(getEmployeeMetrics, {
392
- params: { departmentId },
393
- dependsOn: [Employee], // Refetch when any Employee changes
394
- });
395
-
396
- return (
397
- <div>
398
- {isLoading && <span>Updating...</span>}
399
- {data && <span>Headcount: {data.headcount}</span>}
400
- <button onClick={refetch}>Refresh</button>
401
- </div>
402
- );
403
- }
404
- ```
405
-
406
- ### Specific Object Dependencies
407
-
408
- For finer-grained control, depend on specific object instances:
409
-
410
- ```tsx
411
- import { Employee, getEmployeeReport } from "@my/osdk";
412
- import { useOsdkFunction } from "@osdk/react";
413
-
414
- function EmployeeReport({ employee }: { employee: Employee.OsdkInstance }) {
415
- const { data, isLoading } = useOsdkFunction(getEmployeeReport, {
416
- params: { employeeId: employee.$primaryKey },
417
- dependsOnObjects: [employee], // Refetch only when this employee changes
418
- });
419
-
420
- return (
421
- <div>
422
- {isLoading && <span>Loading report...</span>}
423
- {data && <pre>{JSON.stringify(data, null, 2)}</pre>}
424
- </div>
425
- );
426
- }
427
- ```
428
-
429
- ### Conditional Execution
430
-
431
- Use `enabled` to control when the function executes:
432
-
433
- ```tsx
434
- import { Employee, getEmployeeReport } from "@my/osdk";
435
- import { useOsdkFunction, useOsdkObject } from "@osdk/react";
436
-
437
- function ConditionalReport({ employeeId }: { employeeId: string }) {
438
- const { object: employee } = useOsdkObject(Employee, employeeId);
439
-
440
- const { data, isLoading } = useOsdkFunction(getEmployeeReport, {
441
- params: { employeeId },
442
- enabled: employee !== undefined, // Wait for employee to load
443
- });
444
-
445
- if (!employee) {
446
- return <div>Loading employee...</div>;
447
- }
448
-
449
- return (
450
- <div>
451
- <h2>{employee.fullName}</h2>
452
- {isLoading && <span>Loading report...</span>}
453
- {data && <div>Report: {JSON.stringify(data)}</div>}
454
- </div>
455
- );
456
- }
457
- ```
458
-
459
- ### Options
460
-
461
- - `params` - Parameters to pass to the function (required if function has parameters)
462
- - `dependsOn` - Array of object types; refetch when any object of these types changes
463
- - `dependsOnObjects` - Array of specific object instances; refetch when these objects change
464
- - `dedupeIntervalMs` - Milliseconds to dedupe identical calls (default: 2000)
465
- - `enabled` - Enable/disable execution (default: true)
466
-
467
- ### Return Values
468
-
469
- - `data` - Function result, or undefined if not loaded or on error
470
- - `isLoading` - True while the function is executing
471
- - `error` - Error object if execution failed
472
- - `lastUpdated` - Timestamp (ms since epoch) when result was last fetched
473
- - `refetch` - Function to manually trigger a refetch
474
-
475
- ---
476
-
477
- ## useOsdkAggregation
478
-
479
- Server-side grouping and aggregation.
480
-
481
- ### Simple Aggregation
482
-
483
- ```tsx
484
- import { Todo } from "@my/osdk";
485
- import { useOsdkAggregation } from "@osdk/react";
486
-
487
- function TodoStats() {
488
- const { data, isLoading, error } = useOsdkAggregation(Todo, {
489
- aggregate: {
490
- $select: {
491
- $count: "unordered",
492
- "priority:avg": "unordered",
493
- "dueDate:max": "unordered",
494
- },
495
- },
496
- });
497
-
498
- if (isLoading) {
499
- return <div>Calculating stats...</div>;
500
- }
501
-
502
- if (error) {
503
- return <div>Error: {JSON.stringify(error)}</div>;
504
- }
505
-
506
- // Results: "propertyName:metric" in $select becomes data.propertyName.metric
507
- return (
508
- <div>
509
- <p>Total Todos: {data?.$count}</p>
510
- <p>Average Priority: {data?.priority.avg}</p>
511
- <p>Latest Due Date: {data?.dueDate.max}</p>
512
- </div>
513
- );
514
- }
515
- ```
516
-
517
- ### Grouped Aggregations
518
-
519
- ```tsx
520
- import { Todo } from "@my/osdk";
521
- import { useOsdkAggregation } from "@osdk/react";
522
-
523
- function TodosByStatus() {
524
- const { data, isLoading } = useOsdkAggregation(Todo, {
525
- aggregate: {
526
- $groupBy: { status: "exact" },
527
- $select: {
528
- $count: "unordered",
529
- "priority:avg": "unordered",
530
- },
531
- },
532
- });
533
-
534
- if (isLoading) {
535
- return <div>Loading...</div>;
536
- }
537
-
538
- return (
539
- <div>
540
- {data?.map((group, idx) => (
541
- <div key={idx}>
542
- <h3>Status: {group.$group.status}</h3>
543
- <p>Count: {group.$count}</p>
544
- <p>Avg Priority: {group.priority.avg}</p>
545
- </div>
546
- ))}
547
- </div>
548
- );
549
- }
550
- ```
551
-
552
- ### Filtered Aggregations
553
-
554
- ```tsx
555
- import { Todo } from "@my/osdk";
556
- import { useOsdkAggregation } from "@osdk/react";
557
-
558
- function HighPriorityStats() {
559
- const { data, isLoading } = useOsdkAggregation(Todo, {
560
- where: { priority: "high", isComplete: false },
561
- aggregate: {
562
- $select: {
563
- $count: "unordered",
564
- "dueDate:min": "unordered",
565
- },
566
- },
567
- });
568
-
569
- if (isLoading || !data) return <div>Loading...</div>;
570
-
571
- return (
572
- <div>
573
- <p>High Priority Incomplete: {data.$count}</p>
574
- <p>Earliest Due: {data.dueDate.min}</p>
575
- </div>
576
- );
577
- }
578
- ```
579
-
580
- ### Aggregation Syntax
581
-
582
- The `$select` object uses a special key format where each key is a metric and each value is an ordering directive (`"unordered"`, `"asc"`, or `"desc"`). When using `$groupBy`, the ordering determines the order results are returned.
583
-
584
- **Key formats:**
585
-
586
- - `$count` - Count of objects
587
- - `"propertyName:sum"` - Sum of a numeric property
588
- - `"propertyName:avg"` - Average of a numeric property
589
- - `"propertyName:min"` - Minimum value of a property
590
- - `"propertyName:max"` - Maximum value of a property
591
- - `"propertyName:exactDistinct"` - Exact distinct count
592
- - `"propertyName:approximateDistinct"` - Approximate distinct count (more performant for large datasets)
593
-
594
- ### Options
595
-
596
- - `where` - Filter objects before aggregation
597
- - `withProperties` - Add derived properties for computed values
598
- - `aggregate` - Aggregation configuration:
599
- - `$select` (required) - Object mapping metric keys (e.g., `$count`, `"salary:avg"`) to ordering (`"unordered"`, `"asc"`, or `"desc"`)
600
- - `$groupBy` (optional) - Object mapping property names to grouping strategy (e.g., `"exact"`, `{ $fixedWidth: 10 }`)
601
- - `dedupeIntervalMs` - Minimum time between re-fetches (default: 2000ms)
602
-
603
- ### Return Values
604
-
605
- - `data` - Aggregation result (single object for non-grouped, array for grouped). For `$count`, access via `data.$count`. For property metrics like `"salary:avg"`, access via `data.salary.avg`
606
- - `isLoading` - True while fetching
607
- - `error` - Error object if fetch failed
608
- - `refetch` - Manual refetch function
609
-
610
- ---
611
-
612
- ## useOsdkMetadata
613
-
614
- _Stable - import from `@osdk/react`_
615
-
616
- Fetch metadata about object types or interfaces.
617
-
618
- ```tsx
619
- import { Todo } from "@my/osdk";
620
- import { useOsdkMetadata } from "@osdk/react";
621
-
622
- function TodoMetadataViewer() {
623
- const { metadata, loading, error } = useOsdkMetadata(Todo);
624
-
625
- if (loading) {
626
- return <div>Loading metadata...</div>;
627
- }
628
-
629
- if (error) {
630
- return <div>Error: {error}</div>;
631
- }
632
-
633
- return (
634
- <div>
635
- <h2>{metadata?.displayName}</h2>
636
- <p>Description: {metadata?.description}</p>
637
- <h3>Properties:</h3>
638
- <ul>
639
- {Object.entries(metadata?.properties || {}).map(([key, prop]) => (
640
- <li key={key}>
641
- {key}: {prop.dataType.type}
642
- {prop.displayName && ` (${prop.displayName})`}
643
- </li>
644
- ))}
645
- </ul>
646
- </div>
647
- );
648
- }
649
- ```
650
-
651
- ### Return Values
652
-
653
- - `metadata` - ObjectMetadata or InterfaceMetadata with type information
654
- - `loading` - True while fetching metadata
655
- - `error` - Error message string if fetch failed
656
-
657
- ---
658
-
659
- ## Performance Considerations
660
-
661
- ### useObjectSet
662
-
663
- - Set operations (union, intersect, subtract) are performed on the server
664
- - Each unique combination of options creates a separate cache entry
665
- - Using `pivotTo` creates a new query for the linked type
666
- - Consider using `pageSize` to limit initial data load
667
-
668
- ### Derived Properties
669
-
670
- - Computed server-side, so no client-side overhead
671
- - Complex derived properties with many link traversals may be slower
672
- - Filtering on derived properties happens server-side
673
-
674
- ### Aggregations
675
-
676
- - Aggregations are always computed server-side
677
- - Use `where` to reduce the dataset before aggregation
678
- - Group by produces array results that may be large