@osdk/react 0.10.0-beta.7 → 0.10.0-beta.8
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/AGENTS.md +46 -222
- package/CHANGELOG.md +16 -0
- package/build/browser/new/useLinks.js +6 -2
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useObjectSet.js +4 -2
- package/build/browser/new/useObjectSet.js.map +1 -1
- package/build/browser/new/useOsdkObject.js +19 -3
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +7 -2
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/browser/{intellisense.test.helpers/useOsdkObjectsWithPivot.js → public/experimental/admin.js} +4 -19
- package/build/browser/public/experimental/admin.js.map +1 -0
- package/build/browser/public/experimental.js +0 -3
- package/build/browser/public/experimental.js.map +1 -1
- package/build/cjs/chunk-SVVMLSKN.cjs +111 -0
- package/build/cjs/chunk-SVVMLSKN.cjs.map +1 -0
- package/build/cjs/public/experimental/admin.cjs +146 -0
- package/build/cjs/public/experimental/admin.cjs.map +1 -0
- package/build/cjs/public/experimental/admin.d.cts +118 -0
- package/build/cjs/public/experimental.cjs +112 -328
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +34 -117
- package/build/esm/new/useLinks.js +6 -2
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useObjectSet.js +4 -2
- package/build/esm/new/useObjectSet.js.map +1 -1
- package/build/esm/new/useOsdkObject.js +19 -3
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +7 -2
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/esm/{intellisense.test.helpers/useOsdkObjectsWithPivot.js → public/experimental/admin.js} +4 -19
- package/build/esm/public/experimental/admin.js.map +1 -0
- package/build/esm/public/experimental.js +0 -3
- package/build/esm/public/experimental.js.map +1 -1
- package/build/types/new/useLinks.d.ts +6 -0
- package/build/types/new/useLinks.d.ts.map +1 -1
- package/build/types/new/useObjectSet.d.ts +6 -0
- package/build/types/new/useObjectSet.d.ts.map +1 -1
- package/build/types/new/useOsdkObject.d.ts +12 -1
- package/build/types/new/useOsdkObject.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +10 -0
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/build/types/public/experimental/admin.d.ts +3 -0
- package/build/types/public/experimental/admin.d.ts.map +1 -0
- package/build/types/public/experimental.d.ts +0 -3
- package/build/types/public/experimental.d.ts.map +1 -1
- package/{build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js → experimental/admin.d.ts} +1 -18
- package/package.json +16 -5
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithPivot.js.map +0 -1
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js +0 -34
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +0 -1
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithRids.js +0 -37
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithRids.js.map +0 -1
- package/build/browser/intellisense.test.js +0 -172
- package/build/browser/intellisense.test.js.map +0 -1
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithPivot.js.map +0 -1
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +0 -1
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithRids.js +0 -37
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithRids.js.map +0 -1
- package/build/esm/intellisense.test.js +0 -172
- package/build/esm/intellisense.test.js.map +0 -1
- package/build/types/intellisense.test.d.ts +0 -1
- package/build/types/intellisense.test.d.ts.map +0 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithPivot.d.ts +0 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithPivot.d.ts.map +0 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithProperties.d.ts +0 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithProperties.d.ts.map +0 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithRids.d.ts +0 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithRids.d.ts.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
# @osdk/react
|
|
1
|
+
# @osdk/react
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Rules
|
|
4
4
|
|
|
5
|
-
1. **Use `OsdkProvider2
|
|
6
|
-
2. **Import from `@osdk/react/experimental
|
|
7
|
-
3. **Never conditionally call hooks
|
|
8
|
-
4. **Keep rendering during loading
|
|
5
|
+
1. **Use `OsdkProvider2`**, not `OsdkProvider`. All modern hooks require it.
|
|
6
|
+
2. **Import from `@osdk/react/experimental`**, not `@osdk/react`. Main entry only has legacy hooks.
|
|
7
|
+
3. **Never conditionally call hooks.** Use the `enabled` option instead.
|
|
8
|
+
4. **Keep rendering during loading.** No early returns like `if (isLoading) return <Spinner />`. Show loading indicators alongside existing data to prevent UI flashing. Exception: `if (!data && isLoading)` is acceptable for initial load.
|
|
9
|
+
5. **`useOsdkObject` `enabled` is positional**, not in an options object: `useOsdkObject(Type, id, false)`.
|
|
9
10
|
|
|
10
11
|
## Exports
|
|
11
12
|
|
|
12
|
-
**Stable** (`@osdk/react`):
|
|
13
|
+
**Stable** (`@osdk/react`): `OsdkProvider` (legacy), `useOsdkClient`, `useOsdkMetadata`
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
- `useOsdkClient` - Access client
|
|
16
|
-
- `useOsdkMetadata` - Fetch metadata
|
|
15
|
+
**Experimental** (`@osdk/react/experimental`): `OsdkProvider2`, `useOsdkObjects`, `useOsdkObject`, `useOsdkAction`, `useLinks`, `useObjectSet`, `useOsdkAggregation`, `useOsdkFunction`, `useDebouncedCallback`, `useCurrentFoundryUser`, `useFoundryUser`, `useFoundryUsersList`
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
## Hook Options
|
|
19
18
|
|
|
20
19
|
- `OsdkProvider2` - Modern provider (use this)
|
|
21
20
|
- `useOsdkObjects` - Query lists of objects
|
|
@@ -24,231 +23,56 @@
|
|
|
24
23
|
- `useLinks` - Navigate object relationships
|
|
25
24
|
- `useObjectSet` - Advanced set operations (union, intersect, subtract, pivot)
|
|
26
25
|
- `useOsdkAggregation` - Server-side aggregations with groupBy/select
|
|
27
|
-
- `useCurrentFoundryUser`, `useFoundryUser`, `useFoundryUsersList` - Platform APIs
|
|
28
26
|
- `useOsdkClient`, `useOsdkMetadata` - Also available from experimental
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Loading States
|
|
33
|
-
|
|
34
|
-
```tsx
|
|
35
|
-
import { Todo } from "@my/osdk";
|
|
36
|
-
import { useOsdkObjects } from "@osdk/react/experimental";
|
|
37
|
-
|
|
38
|
-
function TodoList() {
|
|
39
|
-
const { data, isLoading, error } = useOsdkObjects(Todo);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<div>
|
|
43
|
-
{isLoading && <LoadingIndicator />}
|
|
44
|
-
{error && <ErrorMessage error={error} />}
|
|
45
|
-
{data?.map(todo => <TodoItem key={todo.$primaryKey} todo={todo} />)}
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
```
|
|
28
|
+
**Experimental Admin** (`@osdk/react/experimental/admin`):
|
|
50
29
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
import { Employee } from "@my/osdk";
|
|
55
|
-
import { useOsdkObject } from "@osdk/react/experimental";
|
|
56
|
-
|
|
57
|
-
// By type + primary key (enabled is 3rd positional param)
|
|
58
|
-
const { object, isLoading, error, isOptimistic } = useOsdkObject(
|
|
59
|
-
Employee,
|
|
60
|
-
"employee-123",
|
|
61
|
-
true, // enabled (optional, defaults to true)
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// By existing instance (enabled is 2nd positional param)
|
|
65
|
-
const { object: refreshed } = useOsdkObject(existingEmployee, true);
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Conditional Fetching
|
|
69
|
-
|
|
70
|
-
```tsx
|
|
71
|
-
// useOsdkObjects uses options object
|
|
72
|
-
const { data: reports } = useOsdkObjects(Employee, {
|
|
73
|
-
where: { managerId: selectedManagerId },
|
|
74
|
-
enabled: !!selectedManagerId,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// useOsdkObject uses positional enabled parameter
|
|
78
|
-
const { object: manager } = useOsdkObject(Employee, managerId, !!managerId);
|
|
79
|
-
```
|
|
30
|
+
- `useCurrentFoundryUser`, `useFoundryUser`, `useFoundryUsersList` - Platform APIs (requires `@osdk/foundry.admin`)
|
|
80
31
|
|
|
81
|
-
|
|
32
|
+
## Correct Patterns
|
|
82
33
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
isValidating,
|
|
93
|
-
error,
|
|
94
|
-
data,
|
|
95
|
-
validationResult,
|
|
96
|
-
} = useOsdkAction($Actions.completeTodo);
|
|
97
|
-
|
|
98
|
-
// Validate before applying
|
|
99
|
-
const handleValidate = async () => {
|
|
100
|
-
const result = await validateAction({ todo, isComplete: true });
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Apply the action
|
|
104
|
-
const handleComplete = async () => {
|
|
105
|
-
await applyAction({ todo, isComplete: true });
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// With optimistic update (use $ prefix for client options)
|
|
109
|
-
const handleOptimistic = async () => {
|
|
110
|
-
await applyAction({
|
|
111
|
-
todo,
|
|
112
|
-
isComplete: true,
|
|
113
|
-
$optimisticUpdate: (ctx) => {
|
|
114
|
-
ctx.updateObject(todo, { isComplete: true });
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<button onClick={handleComplete} disabled={isPending}>
|
|
121
|
-
Complete
|
|
122
|
-
</button>
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
```
|
|
34
|
+
| Hook | Key Options |
|
|
35
|
+
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
36
|
+
| `useOsdkObjects` | `where`, `orderBy`, `pageSize`, `withProperties`, `enabled`, `autoFetchMore`, `dedupeIntervalMs`, `streamUpdates`, `intersectWith`, `pivotTo` |
|
|
37
|
+
| `useObjectSet` | Same as above plus `union`, `intersect`, `subtract`. Use when you need set operations. |
|
|
38
|
+
| `useOsdkObject` | `enabled` is **positional** (2nd param for instance, 3rd for type+key) |
|
|
39
|
+
| `useLinks` | `where`, `pageSize`, `enabled`, `mode` (`"force"` / `"offline"`), `dedupeIntervalMs`. Accepts single object or array. |
|
|
40
|
+
| `useOsdkAction` | Returns `applyAction`, `validateAction`, `isPending`, `error`, `validationResult`. Pass `$optimisticUpdate` with `$` prefix in action params. |
|
|
41
|
+
| `useOsdkAggregation` | `where`, `aggregate: { $groupBy, $select }`. Metrics: `$count`, `sum`, `avg`, `min`, `max`, `exactDistinct`, `approximateDistinct`. |
|
|
42
|
+
| `useOsdkFunction` | `params`, `dependsOn` (object types), `dependsOnObjects` (instances), `enabled`, `dedupeIntervalMs` |
|
|
126
43
|
|
|
127
|
-
|
|
44
|
+
## Text Search Filters
|
|
128
45
|
|
|
129
|
-
|
|
130
|
-
import { useLinks } from "@osdk/react/experimental";
|
|
131
|
-
|
|
132
|
-
// Single object
|
|
133
|
-
const { links, isLoading, hasMore, fetchMore, error } = useLinks(
|
|
134
|
-
employee,
|
|
135
|
-
"directReports",
|
|
136
|
-
{ pageSize: 20 },
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
// Multiple objects (returns all linked objects)
|
|
140
|
-
const { links: allReports } = useLinks(
|
|
141
|
-
[employee1, employee2],
|
|
142
|
-
"directReports",
|
|
143
|
-
);
|
|
144
|
-
```
|
|
46
|
+
`$startsWith`, `$containsAnyTerm`, `$containsAllTerms`, `$containsAllTermsInOrder`. All support `{ term, fuzzySearch: true }`.
|
|
145
47
|
|
|
146
|
-
|
|
48
|
+
## useOsdkObjects vs useObjectSet
|
|
147
49
|
|
|
148
|
-
|
|
149
|
-
import { Employee } from "@my/osdk";
|
|
150
|
-
import { useObjectSet } from "@osdk/react/experimental";
|
|
151
|
-
|
|
152
|
-
const { data, isLoading, fetchMore, objectSet } = useObjectSet(
|
|
153
|
-
Employee.all(),
|
|
154
|
-
{
|
|
155
|
-
where: { department: "Engineering" },
|
|
156
|
-
orderBy: { hireDate: "desc" },
|
|
157
|
-
pageSize: 50,
|
|
158
|
-
union: [otherObjectSet],
|
|
159
|
-
intersect: [anotherObjectSet],
|
|
160
|
-
autoFetchMore: 100, // fetch until 100 items
|
|
161
|
-
streamUpdates: true,
|
|
162
|
-
enabled: true,
|
|
163
|
-
},
|
|
164
|
-
);
|
|
165
|
-
```
|
|
50
|
+
Use `useOsdkObjects` by default (more optimized). Use `useObjectSet` only when you need `union`/`intersect`/`subtract` set operations.
|
|
166
51
|
|
|
167
|
-
|
|
52
|
+
## Cache
|
|
168
53
|
|
|
169
|
-
|
|
170
|
-
import { Employee } from "@my/osdk";
|
|
171
|
-
import { useOsdkAggregation } from "@osdk/react/experimental";
|
|
172
|
-
|
|
173
|
-
const { data, isLoading, error, refetch } = useOsdkAggregation(Employee, {
|
|
174
|
-
where: { department: "Engineering" },
|
|
175
|
-
aggregate: {
|
|
176
|
-
groupBy: { department: "exact" },
|
|
177
|
-
select: {
|
|
178
|
-
avgSalary: { $avg: "salary" },
|
|
179
|
-
count: { $count: {} },
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
```
|
|
54
|
+
The `ObservableClient` maintains a normalized cache. Objects update automatically after actions. For manual invalidation: `observableClient.invalidateObjects()`, `.invalidateObjectType()`, `.invalidateFunction()`, `.invalidateAll()`.
|
|
184
55
|
|
|
185
56
|
## Anti-Patterns
|
|
186
57
|
|
|
187
|
-
### Wrong: Conditional Hook Call
|
|
188
|
-
|
|
189
|
-
```tsx
|
|
190
|
-
if (shouldLoad) {
|
|
191
|
-
const { data } = useOsdkObjects(Todo); // NEVER do this
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Wrong: Early Return During Loading
|
|
196
|
-
|
|
197
|
-
```tsx
|
|
198
|
-
if (isLoading) return <Spinner />; // Causes UI flashing
|
|
199
|
-
if (!data) return null; // Loses state
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Wrong: Importing from Main Entry
|
|
203
|
-
|
|
204
|
-
```tsx
|
|
205
|
-
import { useOsdkObjects } from "@osdk/react"; // WRONG - doesn't exist here
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
### Wrong: Using OsdkProvider Instead of OsdkProvider2
|
|
209
|
-
|
|
210
58
|
```tsx
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
59
|
+
// WRONG: conditional hook
|
|
60
|
+
if (x) { useOsdkObjects(Todo); }
|
|
61
|
+
// CORRECT: use enabled
|
|
62
|
+
useOsdkObjects(Todo, { enabled: x });
|
|
63
|
+
|
|
64
|
+
// WRONG: early return
|
|
65
|
+
if (isLoading) return <Spinner />;
|
|
66
|
+
// CORRECT: render together
|
|
67
|
+
<div>{isLoading && <Spinner />}{data?.map(...)}</div>
|
|
68
|
+
|
|
69
|
+
// WRONG: import from main entry
|
|
70
|
+
import { useOsdkObjects } from "@osdk/react";
|
|
220
71
|
// CORRECT
|
|
221
|
-
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## Hook Options Reference
|
|
225
|
-
|
|
226
|
-
**useOsdkObjects / useObjectSet:**
|
|
227
|
-
|
|
228
|
-
- `where` - Filter conditions
|
|
229
|
-
- `orderBy` - Sort order (`{ field: "asc" | "desc" }`)
|
|
230
|
-
- `pageSize` - Results per page
|
|
231
|
-
- `withProperties` - Derived properties
|
|
232
|
-
- `enabled` - Enable/disable query
|
|
233
|
-
- `autoFetchMore` - Auto-pagination (`true` | `number`)
|
|
234
|
-
- `dedupeIntervalMs` - Request deduplication
|
|
235
|
-
- `streamUpdates` - WebSocket updates
|
|
236
|
-
|
|
237
|
-
**useObjectSet additional:**
|
|
238
|
-
|
|
239
|
-
- `union`, `intersect`, `subtract` - Set operations
|
|
240
|
-
- `pivotTo` - Pivot to linked type
|
|
241
|
-
|
|
242
|
-
**useOsdkObject:**
|
|
243
|
-
|
|
244
|
-
- `enabled` is a **positional parameter**, not in options
|
|
245
|
-
|
|
246
|
-
**useLinks:**
|
|
247
|
-
|
|
248
|
-
- `where`, `pageSize`, `enabled`
|
|
249
|
-
- `mode` - `"force"` | `"offline"`
|
|
250
|
-
- `dedupeIntervalMs` - Request deduplication (default: 2000ms, use `Infinity` to only re-fetch on invalidation)
|
|
251
|
-
|
|
252
|
-
**useOsdkAction:**
|
|
72
|
+
import { useOsdkObjects } from "@osdk/react/experimental";
|
|
253
73
|
|
|
254
|
-
|
|
74
|
+
// WRONG: useOsdkObject enabled in options
|
|
75
|
+
useOsdkObject(Employee, id, { enabled: false });
|
|
76
|
+
// CORRECT: positional
|
|
77
|
+
useOsdkObject(Employee, id, false);
|
|
78
|
+
```
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @osdkkit/react
|
|
2
2
|
|
|
3
|
+
## 0.10.0-beta.8
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9720083: Add AGENTS.md files for AI IDE context
|
|
8
|
+
- 09e5659: add $select support to observable client and react hooks
|
|
9
|
+
- 8a82492: Move admin hooks to @osdk/react/experimental/admin subpath to avoid bundler crash when @osdk/foundry.admin is not installed
|
|
10
|
+
- 2ebe62c: package and bundle size optimizations
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [09e5659]
|
|
15
|
+
- Updated dependencies [2ebe62c]
|
|
16
|
+
- @osdk/client@2.8.0-beta.16
|
|
17
|
+
- @osdk/api@2.8.0-beta.16
|
|
18
|
+
|
|
3
19
|
## 0.10.0-beta.7
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -37,6 +37,7 @@ export function useLinks(objects, linkName, options = {}) {
|
|
|
37
37
|
} = options;
|
|
38
38
|
const stableWhere = React.useMemo(() => otherOptions.where, [JSON.stringify(otherOptions.where)]);
|
|
39
39
|
const stableOrderBy = React.useMemo(() => otherOptions.orderBy, [JSON.stringify(otherOptions.orderBy)]);
|
|
40
|
+
const stableSelect = React.useMemo(() => otherOptions.$select, [JSON.stringify(otherOptions.$select)]);
|
|
40
41
|
const objectsKey = React.useMemo(() => {
|
|
41
42
|
if (objects === undefined) return "";
|
|
42
43
|
const arr = Array.isArray(objects) ? objects : [objects];
|
|
@@ -62,9 +63,12 @@ export function useLinks(objects, linkName, options = {}) {
|
|
|
62
63
|
pageSize: otherOptions.pageSize,
|
|
63
64
|
orderBy: stableOrderBy,
|
|
64
65
|
mode: otherOptions.mode,
|
|
65
|
-
dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000
|
|
66
|
+
dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,
|
|
67
|
+
...(stableSelect ? {
|
|
68
|
+
select: stableSelect
|
|
69
|
+
} : {})
|
|
66
70
|
}, observer), `links ${linkName} for ${objectsKey}`);
|
|
67
|
-
}, [enabled, observableClient, objectsArray, objectsKey, linkName, stableWhere, otherOptions.pageSize, stableOrderBy, otherOptions.mode, otherOptions.dedupeIntervalMs]);
|
|
71
|
+
}, [enabled, observableClient, objectsArray, objectsKey, linkName, stableWhere, otherOptions.pageSize, stableOrderBy, otherOptions.mode, otherOptions.dedupeIntervalMs, stableSelect]);
|
|
68
72
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
69
73
|
return React.useMemo(() => ({
|
|
70
74
|
links: payload?.resolvedList,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","stableWhere","useMemo","where","JSON","stringify","stableOrderBy","orderBy","objectsKey","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","observer","observeLinks","pageSize","mode","dedupeInterval","dedupeIntervalMs","payload","useSyncExternalStore","links","resolvedList","isLoading","status","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseLinksOptions<\n T extends ObjectOrInterfaceDefinition,\n> {\n /**\n * Standard OSDK Where clause for filtering linked objects\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the links list.\n */\n pageSize?: number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The mode to use for fetching data.\n * - undefined: Fetch data if not already in cache\n * - \"force\": Always fetch fresh data\n * - \"offline\": Only use cached data, don't make network requests\n */\n mode?: \"force\" | \"offline\";\n\n /**\n * The number of milliseconds to wait after the last observed link change.\n *\n * Two uses of `useLinks` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for employee data\n * const { object: employee } = useOsdkObject(Employee, employeeId);\n * const { links: reports } = useLinks(employee, \"reports\", {\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseLinksResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n links: Osdk.Instance<Q>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the links are optimistic or not.\n */\n isOptimistic: boolean;\n\n /**\n * Fetch more linked objects if pagination is supported\n */\n fetchMore: (() => Promise<unknown>) | undefined;\n\n /**\n * Indicates if there are more linked objects available to fetch\n */\n hasMore: boolean;\n}\n\nconst emptyArray = Object.freeze([]);\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, ...otherOptions } = options;\n\n const stableWhere = React.useMemo(\n () => otherOptions.where,\n [JSON.stringify(otherOptions.where)],\n );\n\n const stableOrderBy = React.useMemo(\n () => otherOptions.orderBy,\n [JSON.stringify(otherOptions.orderBy)],\n );\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n () => ({ unsubscribe: () => {} }),\n `links ${linkName} for ${objectsKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: stableWhere,\n pageSize: otherOptions.pageSize,\n orderBy: stableOrderBy,\n mode: otherOptions.mode,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n `links ${linkName} for ${objectsKey}`,\n );\n },\n [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n stableWhere,\n otherOptions.pageSize,\n stableOrderBy,\n otherOptions.mode,\n otherOptions.dedupeIntervalMs,\n ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\n return React.useMemo(() => ({\n links: payload?.resolvedList,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n }), [payload, enabled]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAA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K,MAAM,KAAK,MAAM,IACzD,CAACL,OAAO,GACX,KAAK;IACTM,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAEP,OAAO,EAAEO,KAAK;IACrBC,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,EAAEQ,SAAS,GAAG3B,SAAS;IAC5D4B,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC,CAAC,EAAE,CAACT,OAAO,EAAE7B,OAAO,CAAC,CAAC;AACzB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","stableWhere","useMemo","where","JSON","stringify","stableOrderBy","orderBy","stableSelect","$select","objectsKey","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","observer","observeLinks","pageSize","mode","dedupeInterval","dedupeIntervalMs","select","payload","useSyncExternalStore","links","resolvedList","isLoading","status","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseLinksOptions<\n T extends ObjectOrInterfaceDefinition,\n> {\n /**\n * Standard OSDK Where clause for filtering linked objects\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the links list.\n */\n pageSize?: number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Restrict which properties are returned for each linked object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<T>[];\n\n /**\n * The mode to use for fetching data.\n * - undefined: Fetch data if not already in cache\n * - \"force\": Always fetch fresh data\n * - \"offline\": Only use cached data, don't make network requests\n */\n mode?: \"force\" | \"offline\";\n\n /**\n * The number of milliseconds to wait after the last observed link change.\n *\n * Two uses of `useLinks` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for employee data\n * const { object: employee } = useOsdkObject(Employee, employeeId);\n * const { links: reports } = useLinks(employee, \"reports\", {\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseLinksResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n links: Osdk.Instance<Q>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the links are optimistic or not.\n */\n isOptimistic: boolean;\n\n /**\n * Fetch more linked objects if pagination is supported\n */\n fetchMore: (() => Promise<unknown>) | undefined;\n\n /**\n * Indicates if there are more linked objects available to fetch\n */\n hasMore: boolean;\n}\n\nconst emptyArray = Object.freeze([]);\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, ...otherOptions } = options;\n\n const stableWhere = React.useMemo(\n () => otherOptions.where,\n [JSON.stringify(otherOptions.where)],\n );\n\n const stableOrderBy = React.useMemo(\n () => otherOptions.orderBy,\n [JSON.stringify(otherOptions.orderBy)],\n );\n\n const stableSelect = React.useMemo(\n () => otherOptions.$select,\n [JSON.stringify(otherOptions.$select)],\n );\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n () => ({ unsubscribe: () => {} }),\n `links ${linkName} for ${objectsKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: stableWhere,\n pageSize: otherOptions.pageSize,\n orderBy: stableOrderBy,\n mode: otherOptions.mode,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n ...(stableSelect ? { select: stableSelect } : {}),\n },\n observer,\n ),\n `links ${linkName} for ${objectsKey}`,\n );\n },\n [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n stableWhere,\n otherOptions.pageSize,\n stableOrderBy,\n otherOptions.mode,\n otherOptions.dedupeIntervalMs,\n stableSelect,\n ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\n return React.useMemo(() => ({\n links: payload?.resolvedList,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n }), [payload, enabled]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAwFhD,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAItBC,OAA+D,EAC/DC,QAAW,EACXC,OAA0C,GAAG,CAAC,CAAC,EACb;EAClC,MAAM;IAAEC;EAAiB,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;EAE3D,MAAM;IAAEU,OAAO,GAAG,IAAI;IAAE,GAAGC;EAAa,CAAC,GAAGJ,OAAO;EAEnD,MAAMK,WAAW,GAAGd,KAAK,CAACe,OAAO,CAC/B,MAAMF,YAAY,CAACG,KAAK,EACxB,CAACC,IAAI,CAACC,SAAS,CAACL,YAAY,CAACG,KAAK,CAAC,CACrC,CAAC;EAED,MAAMG,aAAa,GAAGnB,KAAK,CAACe,OAAO,CACjC,MAAMF,YAAY,CAACO,OAAO,EAC1B,CAACH,IAAI,CAACC,SAAS,CAACL,YAAY,CAACO,OAAO,CAAC,CACvC,CAAC;EAED,MAAMC,YAAY,GAAGrB,K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AED,aAAa;MACtBqB,IAAI,EAAE3B,YAAY,CAAC2B,IAAI;MACvBC,cAAc,EAAE5B,YAAY,CAAC6B,gBAAgB,IAAI,KAAK;MACtD,IAAIrB,YAAY,GAAG;QAAEsB,MAAM,EAAEtB;MAAa,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC,EACDgB,QACF,CAAC,EACH,SAAS7B,QAAQ,QAAQe,UAAU,EACrC,CAAC;EACH,CAAC,EACD,CACEX,OAAO,EACPF,gBAAgB,EAChBuB,YAAY,EACZV,UAAU,EACVf,QAAQ,EACRM,WAAW,EACXD,YAAY,CAAC0B,QAAQ,EACrBpB,aAAa,EACbN,YAAY,CAAC2B,IAAI,EACjB3B,YAAY,CAAC6B,gBAAgB,EAC7BrB,YAAY,CAEhB,CAAC;EAED,MAAMuB,OAAO,GAAG5C,KAAK,CAAC6C,oBAAoB,CACxCX,SAAS,EACTC,WACF,CAAC;EAED,OAAOnC,KAAK,CAACe,OAAO,CAAC,OAAO;IAC1B+B,KAAK,EAAEF,OAAO,EAAEG,YAAY;IAC5BC,SAAS,EAAEpC,OAAO,GACbgC,OAAO,EAAEK,MAAM,KAAK,SAAS,IAAIL,OAAO,EAAEK,MAAM,KAAK,MAAM,IACzD,CAACL,OAAO,GACX,KAAK;IACTM,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAEP,OAAO,EAAEO,KAAK;IACrBC,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,EAAEQ,SAAS,GAAG5B,SAAS;IAC5D6B,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC,CAAC,EAAE,CAACT,OAAO,EAAEhC,OAAO,CAAC,CAAC;AACzB","ignoreList":[]}
|
|
@@ -60,7 +60,8 @@ export function useObjectSet(baseObjectSet, options = {}) {
|
|
|
60
60
|
subtract: otherOptions.subtract,
|
|
61
61
|
pivotTo: otherOptions.pivotTo,
|
|
62
62
|
pageSize: otherOptions.pageSize,
|
|
63
|
-
orderBy: otherOptions.orderBy
|
|
63
|
+
orderBy: otherOptions.orderBy,
|
|
64
|
+
select: otherOptions.$select
|
|
64
65
|
});
|
|
65
66
|
const {
|
|
66
67
|
subscribe,
|
|
@@ -84,7 +85,8 @@ export function useObjectSet(baseObjectSet, options = {}) {
|
|
|
84
85
|
orderBy: otherOptions.orderBy,
|
|
85
86
|
dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,
|
|
86
87
|
autoFetchMore: otherOptions.autoFetchMore,
|
|
87
|
-
streamUpdates
|
|
88
|
+
streamUpdates,
|
|
89
|
+
select: otherOptions.$select
|
|
88
90
|
}, observer);
|
|
89
91
|
return subscription;
|
|
90
92
|
}, process.env.NODE_ENV !== "production" ? `objectSet ${stableKey}` : void 0, initialValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","OBJECT_TYPE_PLACEHOLDER","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousCompletedPayloadRef","objectTypeChanged","current","undefined","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","initialValue","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","isPayloadCompleted","lastLoaded","data","resolvedList","isLoading","error","fetchMore","hasMore","objectSet","totalCount","status"],"sources":["useObjectSet.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkNames,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\n\nimport {\n computeObjectSetCacheKey,\n type ObserveObjectSetArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore, type Snapshot } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseObjectSetOptions<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Where clause for filtering\n */\n where?: WhereClause<Q, RDPs>;\n\n /**\n * Derived properties to add to the object set\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]> };\n\n /**\n * Object sets to union with\n */\n union?: ObjectSet<Q>[];\n\n /**\n * Object sets to intersect with\n */\n intersect?: ObjectSet<Q>[];\n\n /**\n * Object sets to subtract from\n */\n subtract?: ObjectSet<Q>[];\n\n /**\n * Link to pivot to (changes the type)\n */\n pivotTo?: LinkNames<Q>;\n\n /**\n * The preferred page size for the list\n */\n pageSize?: number;\n\n /**\n * Sort order for the results\n */\n orderBy?: {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Minimum time between fetch requests in milliseconds (defaults to 2000ms)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Automatically fetch additional pages on initial load.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the object set will automatically update when matching objects are\n * added, updated, or removed.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs>;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nconst OBJECT_TYPE_PLACEHOLDER = \"$__OBJECT__TYPE__PLACEHOLDER\";\n/**\n * React hook for observing and interacting with OSDK object sets.\n *\n * @typeParam Q - The object type definition\n * @typeParam BaseRDPs - Derived properties that already exist on the input ObjectSet\n * @typeParam RDPs - New derived properties to be added via options.withProperties\n *\n * @param baseObjectSet - The ObjectSet to observe (may already have derived properties)\n * @param options - Options for filtering, sorting, and adding new derived properties\n * @returns Object set data with both existing and new derived properties\n */\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs>,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, streamUpdates, ...otherOptions } = options;\n\n // Track object type to detect when we switch to a different object type\n const objectTypeKey = enabled\n ? baseObjectSet.$objectSetInternals.def.apiName\n : OBJECT_TYPE_PLACEHOLDER;\n\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousCompletedPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\n previousCompletedPayloadRef.current = undefined;\n }\n\n // Compute a stable cache key for the ObjectSet and options\n // dedupeIntervalMs and enabled are excluded as they don't affect the data\n const stableKey = computeObjectSetCacheKey(baseObjectSet, {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n });\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey} [DISABLED]`\n : void 0,\n );\n }\n\n const initialValue = objectTypeChanged\n ? undefined\n : previousCompletedPayloadRef.current;\n\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n const subscription = observableClient.observeObjectSet(\n baseObjectSet as ObjectSet<Q>,\n {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n },\n observer,\n );\n return subscription;\n },\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey}`\n : void 0,\n initialValue,\n );\n },\n [enabled, observableClient, stableKey, streamUpdates, objectTypeChanged],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n if (payload && isPayloadCompleted(payload)) {\n previousCompletedPayloadRef.current = payload;\n }\n\n return React.useMemo(() => {\n const lastLoaded = isPayloadCompleted(payload)\n ? payload\n : previousCompletedPayloadRef.current;\n return {\n data: lastLoaded?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: !isPayloadCompleted(payload),\n error: lastLoaded && \"error\" in lastLoaded ? lastLoaded.error : undefined,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\n totalCount: lastLoaded?.totalCount,\n };\n }, [payload, baseObjectSet]);\n}\n\nfunction isPayloadCompleted<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n>(\n payload: Snapshot<ObserveObjectSetArgs<Q, RDPs>>,\n): boolean {\n if (payload != null && \"error\" in payload) {\n return true;\n }\n\n if (payload?.status == null) {\n return false;\n }\n\n switch (payload.status) {\n case \"loaded\":\n case \"error\":\n return true;\n case \"loading\":\n case \"init\":\n return false;\n default:\n payload.status satisfies never;\n return false;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,SACEA,wBAAwB,QAEnB,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAuB,wBAAwB;AACzE,SAASC,YAAY,QAAQ,mBAAmB;AAwIhD,MAAMC,uBAAuB,GAAG,8BAA8B;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,S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OAAO7C,KAAK,CAACiC,OAAO,CAAC,MAAM;IACzB,MAAMe,UAAU,GAAGD,kBAAkB,CAACF,OAAO,CAAC,GAC1CA,OAAO,GACP3B,2BAA2B,CAACE,OAAO;IACvC,OAAO;MACL6B,IAAI,EAAED,UAAU,EAAEE,YAKf;MACHC,SAAS,EAAE,CAACJ,kBAAkB,CAACF,OAAO,CAAC;MACvCO,KAAK,EAAEJ,UAAU,IAAI,OAAO,IAAIA,UAAU,GAAGA,UAAU,CAACI,KAAK,GAAG/B,SAAS;MACzEgC,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,CAACQ,SAAS,GAAGhC,SAAS;MAC3DkC,SAAS,EAAEV,OAAO,EAAEU,SAAS,IAA0BlD,aAAa;MACpEmD,UAAU,EAAER,UAAU,EAAEQ;IAC1B,CAAC;EACH,CAAC,EAAE,CAACX,OAAO,EAAExC,aAAa,CAAC,CAAC;AAC9B;AAEA,SAAS0C,kBAAkBA,CAIzBF,OAAgD,EACvC;EACT,IAAIA,OAAO,IAAI,IAAI,IAAI,OAAO,IAAIA,OAAO,EAAE;IACzC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,EAAEY,MAAM,IAAI,IAAI,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,QAAQZ,OAAO,CAACY,MAAM;IACpB,KAAK,QAAQ;IACb,KAAK,OAAO;MACV,OAAO,IAAI;IACb,KAAK,SAAS;IACd,KAAK,MAAM;MACT,OAAO,KAAK;IACd;MACEZ,OAAO,CAACY,MAAM;MACd,OAAO,KAAK;EAChB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","OBJECT_TYPE_PLACEHOLDER","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousCompletedPayloadRef","objectTypeChanged","current","undefined","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","select","$select","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","initialValue","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","isPayloadCompleted","lastLoaded","data","resolvedList","isLoading","error","fetchMore","hasMore","objectSet","totalCount","status"],"sources":["useObjectSet.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkNames,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\n\nimport {\n computeObjectSetCacheKey,\n type ObserveObjectSetArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore, type Snapshot } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseObjectSetOptions<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Where clause for filtering\n */\n where?: WhereClause<Q, RDPs>;\n\n /**\n * Derived properties to add to the object set\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]> };\n\n /**\n * Object sets to union with\n */\n union?: ObjectSet<Q>[];\n\n /**\n * Object sets to intersect with\n */\n intersect?: ObjectSet<Q>[];\n\n /**\n * Object sets to subtract from\n */\n subtract?: ObjectSet<Q>[];\n\n /**\n * Link to pivot to (changes the type)\n */\n pivotTo?: LinkNames<Q>;\n\n /**\n * The preferred page size for the list\n */\n pageSize?: number;\n\n /**\n * Sort order for the results\n */\n orderBy?: {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Minimum time between fetch requests in milliseconds (defaults to 2000ms)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Automatically fetch additional pages on initial load.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the object set will automatically update when matching objects are\n * added, updated, or removed.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Restrict which properties are returned for each object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<Q>[];\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs>;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nconst OBJECT_TYPE_PLACEHOLDER = \"$__OBJECT__TYPE__PLACEHOLDER\";\n/**\n * React hook for observing and interacting with OSDK object sets.\n *\n * @typeParam Q - The object type definition\n * @typeParam BaseRDPs - Derived properties that already exist on the input ObjectSet\n * @typeParam RDPs - New derived properties to be added via options.withProperties\n *\n * @param baseObjectSet - The ObjectSet to observe (may already have derived properties)\n * @param options - Options for filtering, sorting, and adding new derived properties\n * @returns Object set data with both existing and new derived properties\n */\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs>,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, streamUpdates, ...otherOptions } = options;\n\n // Track object type to detect when we switch to a different object type\n const objectTypeKey = enabled\n ? baseObjectSet.$objectSetInternals.def.apiName\n : OBJECT_TYPE_PLACEHOLDER;\n\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousCompletedPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\n previousCompletedPayloadRef.current = undefined;\n }\n\n // Compute a stable cache key for the ObjectSet and options\n // dedupeIntervalMs and enabled are excluded as they don't affect the data\n const stableKey = computeObjectSetCacheKey(baseObjectSet, {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n select: otherOptions.$select,\n });\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey} [DISABLED]`\n : void 0,\n );\n }\n\n const initialValue = objectTypeChanged\n ? undefined\n : previousCompletedPayloadRef.current;\n\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n const subscription = observableClient.observeObjectSet(\n baseObjectSet as ObjectSet<Q>,\n {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n select: otherOptions.$select,\n },\n observer,\n );\n return subscription;\n },\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey}`\n : void 0,\n initialValue,\n );\n },\n [enabled, observableClient, stableKey, streamUpdates, objectTypeChanged],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n if (payload && isPayloadCompleted(payload)) {\n previousCompletedPayloadRef.current = payload;\n }\n\n return React.useMemo(() => {\n const lastLoaded = isPayloadCompleted(payload)\n ? payload\n : previousCompletedPayloadRef.current;\n return {\n data: lastLoaded?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: !isPayloadCompleted(payload),\n error: lastLoaded && \"error\" in lastLoaded ? lastLoaded.error : undefined,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\n totalCount: lastLoaded?.totalCount,\n };\n }, [payload, baseObjectSet]);\n}\n\nfunction isPayloadCompleted<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n>(\n payload: Snapshot<ObserveObjectSetArgs<Q, RDPs>>,\n): boolean {\n if (payload != null && \"error\" in payload) {\n return true;\n }\n\n if (payload?.status == null) {\n return false;\n }\n\n switch (payload.status) {\n case \"loaded\":\n case \"error\":\n return true;\n case \"loading\":\n case \"init\":\n return false;\n default:\n payload.status satisfies never;\n return false;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,SACEA,wBAAwB,QAEnB,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAuB,wBAAwB;AACzE,SAASC,YAAY,QAAQ,mBAAmB;AA+IhD,MAAMC,uBAAuB,GAAG,8BAA8B;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAK1BC,aAAqC,EACrCC,OAAqC,GAAG,CAAC,CAAC,EACb;EAC7B,MAAM;IAAEC;EAAiB,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACN,YAAY,CAAC;EAE3D,MAAM;IAAEO,OAAO,GAAG,IAAI;IAAEC,aAAa;IAAE,GAAGC;EAAa,CAAC,GAAGL,OAAO;;EAElE;EACA,MAAMM,aAAa,GAAGH,OAAO,GACzBJ,aAAa,CAACQ,mBAAmB,CAACC,GAAG,CAACC,OAAO,GAC7CZ,uBAAuB;EAE3B,MAAMa,qBAAqB,GAAGhB,KAAK,CAACiB,MAAM,CAASL,aAAa,CAAC;EACjE,MAAMM,2BAA2B,GAAGlB,KAAK,CAACiB,MAAM,CAE9C,CAAC;EAEH,MAAME,iBAAiB,GAAGH,qBAAqB,CAACI,OAAO,KAAKR,aAAa;EACzE,IAAIO,iBAAiB,EAAE;IACrBH,qBAAqB,CAACI,OAAO,GAAGR,aAAa;IAC7CM,2BAA2B,CAACE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O,EAAE1C,aAAa,CAAC,CAAC;AAC9B;AAEA,SAAS4C,kBAAkBA,CAIzBF,OAAgD,EACvC;EACT,IAAIA,OAAO,IAAI,IAAI,IAAI,OAAO,IAAIA,OAAO,EAAE;IACzC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,EAAEY,MAAM,IAAI,IAAI,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,QAAQZ,OAAO,CAACY,MAAM;IACpB,KAAK,QAAQ;IACb,KAAK,OAAO;MACV,OAAO,IAAI;IACb,KAAK,SAAS;IACd,KAAK,MAAM;MACT,OAAO,KAAK;IACd;MACEZ,OAAO,CAACY,MAAM;MACd,OAAO,KAAK;EAChB;AACF","ignoreList":[]}
|
|
@@ -31,6 +31,14 @@ import { OsdkContext2 } from "./OsdkContext2.js";
|
|
|
31
31
|
* @param enabled Enable or disable the query (defaults to true)
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Loads an object or interface instance by type and primary key with options.
|
|
36
|
+
*
|
|
37
|
+
* @param type The object type or interface definition
|
|
38
|
+
* @param primaryKey The primary key of the object
|
|
39
|
+
* @param options Options including $select and enabled
|
|
40
|
+
*/
|
|
41
|
+
|
|
34
42
|
/*
|
|
35
43
|
Implementation of useOsdkObject
|
|
36
44
|
*/
|
|
@@ -44,12 +52,17 @@ export function useOsdkObject(...args) {
|
|
|
44
52
|
// so we must use type assertions after runtime discrimination
|
|
45
53
|
const isInstanceSignature = "$objectType" in args[0];
|
|
46
54
|
|
|
55
|
+
// Extract options object if provided (3rd arg is an object with $select or enabled)
|
|
56
|
+
const optionsArg = !isInstanceSignature && args[2] != null && typeof args[2] === "object" ? args[2] : undefined;
|
|
57
|
+
|
|
47
58
|
// Extract enabled flag - 2nd param for instance signature, 3rd for type signature
|
|
48
|
-
const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
|
|
59
|
+
const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : optionsArg ? optionsArg.enabled ?? true : typeof args[2] === "boolean" ? args[2] : true;
|
|
60
|
+
const selectArg = optionsArg?.$select;
|
|
49
61
|
const mode = isInstanceSignature ? "offline" : undefined;
|
|
50
62
|
const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
|
|
51
63
|
const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
|
|
52
64
|
const apiNameString = typeof typeOrApiName === "string" ? typeOrApiName : typeOrApiName.apiName;
|
|
65
|
+
const stableSelect = React.useMemo(() => selectArg, [JSON.stringify(selectArg)]);
|
|
53
66
|
const {
|
|
54
67
|
subscribe,
|
|
55
68
|
getSnapShot
|
|
@@ -60,9 +73,12 @@ export function useOsdkObject(...args) {
|
|
|
60
73
|
}), `object ${apiNameString} ${primaryKey} [DISABLED]`);
|
|
61
74
|
}
|
|
62
75
|
return makeExternalStore(observer => observableClient.observeObject(typeOrApiName, primaryKey, {
|
|
63
|
-
mode
|
|
76
|
+
mode,
|
|
77
|
+
...(stableSelect ? {
|
|
78
|
+
select: stableSelect
|
|
79
|
+
} : {})
|
|
64
80
|
}, observer), `object ${apiNameString} ${primaryKey}`);
|
|
65
|
-
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode]);
|
|
81
|
+
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode, stableSelect]);
|
|
66
82
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
67
83
|
const forceUpdate = React.useCallback(() => {
|
|
68
84
|
throw new Error("not implemented");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","
|
|
1
|
+
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","optionsArg","undefined","enabled","selectArg","$select","mode","typeOrApiName","$objectType","primaryKey","$primaryKey","apiNameString","apiName","stableSelect","useMemo","JSON","stringify","subscribe","getSnapShot","unsubscribe","observer","observeObject","select","payload","useSyncExternalStore","forceUpdate","useCallback","Error","error","status","object","isLoading","isOptimistic"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n} from \"@osdk/api\";\nimport type { ObserveObjectCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n obj: Osdk.Instance<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object or interface instance by type and primary key.\n *\n * @param type The object type or interface definition\n * @param primaryKey The primary key of the object\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object or interface instance by type and primary key with options.\n *\n * @param type The object type or interface definition\n * @param primaryKey The primary key of the object\n * @param options Options including $select and enabled\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n options?: { $select?: readonly PropertyKeys<Q>[]; enabled?: boolean },\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n ...args:\n | [obj: Osdk.Instance<Q>, enabled?: boolean]\n | [type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean]\n | [\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n options?: { $select?: readonly PropertyKeys<Q>[]; enabled?: boolean },\n ]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // Check if first arg is an instance to discriminate signatures\n // TypeScript cannot narrow rest parameter unions with optional parameters,\n // so we must use type assertions after runtime discrimination\n const isInstanceSignature = \"$objectType\" in args[0];\n\n // Extract options object if provided (3rd arg is an object with $select or enabled)\n const optionsArg = !isInstanceSignature\n && args[2] != null\n && typeof args[2] === \"object\"\n ? args[2] as { $select?: readonly string[]; enabled?: boolean }\n : undefined;\n\n // Extract enabled flag - 2nd param for instance signature, 3rd for type signature\n const enabled = isInstanceSignature\n ? (typeof args[1] === \"boolean\" ? args[1] : true)\n : optionsArg\n ? (optionsArg.enabled ?? true)\n : (typeof args[2] === \"boolean\" ? args[2] : true);\n\n const selectArg = optionsArg?.$select;\n\n const mode = isInstanceSignature ? \"offline\" : undefined;\n\n const typeOrApiName = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$objectType\n : (args[0] as Q);\n\n const primaryKey = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$primaryKey\n : (args[1] as PrimaryKeyType<Q>);\n\n const apiNameString = typeof typeOrApiName === \"string\"\n ? typeOrApiName\n : typeOrApiName.apiName;\n\n const stableSelect = React.useMemo(\n () => selectArg,\n [JSON.stringify(selectArg)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n `object ${apiNameString} ${primaryKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n typeOrApiName,\n primaryKey,\n {\n mode,\n ...(stableSelect ? { select: stableSelect } : {}),\n },\n observer,\n ),\n `object ${apiNameString} ${primaryKey}`,\n );\n },\n [\n enabled,\n observableClient,\n typeOrApiName,\n apiNameString,\n primaryKey,\n mode,\n stableSelect,\n ],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const forceUpdate = React.useCallback(() => {\n throw new Error(\"not implemented\");\n }, []);\n\n return React.useMemo(() => {\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate,\n };\n }, [payload, enabled, forceUpdate]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAiBhD;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAG3B,GAAGC,IAOA,EACqB;EACxB,MAAM;IAAEC;EAAi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AO,GACX,KAAK;MACTS,YAAY,EAAE,CAAC,CAACT,OAAO,EAAES,YAAY;MACrCJ,KAAK;MACLH;IACF,CAAC;EACH,CAAC,EAAE,CAACF,OAAO,EAAEpB,OAAO,EAAEsB,WAAW,CAAC,CAAC;AACrC","ignoreList":[]}
|
|
@@ -33,7 +33,8 @@ export function useOsdkObjects(type, options) {
|
|
|
33
33
|
streamUpdates,
|
|
34
34
|
autoFetchMore,
|
|
35
35
|
intersectWith,
|
|
36
|
-
pivotTo
|
|
36
|
+
pivotTo,
|
|
37
|
+
$select
|
|
37
38
|
} = options ?? {};
|
|
38
39
|
const canonWhere = observableClient.canonicalizeWhereClause(where ?? EMPTY_WHERE);
|
|
39
40
|
const stableCanonWhere = React.useMemo(() => canonWhere, [JSON.stringify(canonWhere)]);
|
|
@@ -41,6 +42,7 @@ export function useOsdkObjects(type, options) {
|
|
|
41
42
|
const stableWithProperties = React.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
42
43
|
const stableIntersectWith = React.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
43
44
|
const stableOrderBy = React.useMemo(() => orderBy, [JSON.stringify(orderBy)]);
|
|
45
|
+
const stableSelect = React.useMemo(() => $select, [JSON.stringify($select)]);
|
|
44
46
|
const {
|
|
45
47
|
subscribe,
|
|
46
48
|
getSnapShot
|
|
@@ -65,9 +67,12 @@ export function useOsdkObjects(type, options) {
|
|
|
65
67
|
} : {}),
|
|
66
68
|
...(pivotTo ? {
|
|
67
69
|
pivotTo
|
|
70
|
+
} : {}),
|
|
71
|
+
...(stableSelect ? {
|
|
72
|
+
select: stableSelect
|
|
68
73
|
} : {})
|
|
69
74
|
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
70
|
-
}, [enabled, observableClient, type.apiName, type.type, stableRids, stableCanonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
|
|
75
|
+
}, [enabled, observableClient, type.apiName, type.type, stableRids, stableCanonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo, stableSelect]);
|
|
71
76
|
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
72
77
|
return React.useMemo(() => {
|
|
73
78
|
let error;
|