@osdk/react 0.8.0 → 0.9.0-beta.10
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 +253 -0
- package/CHANGELOG.md +105 -24
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js +1 -1
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -1
- package/build/browser/intellisense.test.js +1 -1
- package/build/browser/intellisense.test.js.map +1 -1
- package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js +44 -0
- package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useFoundryUser.js +50 -0
- package/build/browser/new/platform-apis/admin/useFoundryUser.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useFoundryUsersList.js +54 -0
- package/build/browser/new/platform-apis/admin/useFoundryUsersList.js.map +1 -0
- package/build/browser/new/useLinks.js +15 -8
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useObjectSet.js +3 -2
- package/build/browser/new/useObjectSet.js.map +1 -1
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkAggregation.js +1 -1
- package/build/browser/new/useOsdkAggregation.js.map +1 -1
- package/build/browser/new/useOsdkFunction.js +101 -0
- package/build/browser/new/useOsdkFunction.js.map +1 -0
- package/build/browser/new/useOsdkObject.js +1 -1
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +4 -3
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/browser/public/experimental.js +4 -0
- package/build/browser/public/experimental.js.map +1 -1
- package/build/browser/utils/usePlatformQuery.js +74 -0
- package/build/browser/utils/usePlatformQuery.js.map +1 -0
- package/build/cjs/{chunk-OVBG5VXE.cjs → chunk-V32JHU3O.cjs} +8 -3
- package/build/cjs/chunk-V32JHU3O.cjs.map +1 -0
- package/build/cjs/index.cjs +4 -4
- package/build/cjs/public/experimental.cjs +399 -66
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +279 -32
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js +1 -1
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -1
- package/build/esm/intellisense.test.js +1 -1
- package/build/esm/intellisense.test.js.map +1 -1
- package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js +44 -0
- package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useFoundryUser.js +50 -0
- package/build/esm/new/platform-apis/admin/useFoundryUser.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useFoundryUsersList.js +54 -0
- package/build/esm/new/platform-apis/admin/useFoundryUsersList.js.map +1 -0
- package/build/esm/new/useLinks.js +15 -8
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useObjectSet.js +3 -2
- package/build/esm/new/useObjectSet.js.map +1 -1
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkAggregation.js +1 -1
- package/build/esm/new/useOsdkAggregation.js.map +1 -1
- package/build/esm/new/useOsdkFunction.js +101 -0
- package/build/esm/new/useOsdkFunction.js.map +1 -0
- package/build/esm/new/useOsdkObject.js +1 -1
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +4 -3
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/esm/public/experimental.js +4 -0
- package/build/esm/public/experimental.js.map +1 -1
- package/build/esm/utils/usePlatformQuery.js +74 -0
- package/build/esm/utils/usePlatformQuery.js.map +1 -0
- package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts +28 -0
- package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useFoundryUser.d.ts +36 -0
- package/build/types/new/platform-apis/admin/useFoundryUser.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts +52 -0
- package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts.map +1 -0
- package/build/types/new/useLinks.d.ts +5 -5
- package/build/types/new/useLinks.d.ts.map +1 -1
- package/build/types/new/useObjectSet.d.ts +4 -0
- package/build/types/new/useObjectSet.d.ts.map +1 -1
- package/build/types/new/useOsdkAction.d.ts +3 -3
- package/build/types/new/useOsdkAction.d.ts.map +1 -1
- package/build/types/new/useOsdkAggregation.d.ts +10 -12
- package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
- package/build/types/new/useOsdkFunction.d.ts +112 -0
- package/build/types/new/useOsdkFunction.d.ts.map +1 -0
- package/build/types/new/useOsdkObjects.d.ts +31 -13
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/build/types/public/experimental.d.ts +5 -0
- package/build/types/public/experimental.d.ts.map +1 -1
- package/build/types/utils/usePlatformQuery.d.ts +25 -0
- package/build/types/utils/usePlatformQuery.d.ts.map +1 -0
- package/docs/actions.md +414 -0
- package/docs/advanced-queries.md +663 -0
- package/docs/cache-management.md +213 -0
- package/docs/getting-started.md +382 -0
- package/docs/platform-apis.md +203 -0
- package/docs/querying-data.md +648 -0
- package/package.json +10 -6
- package/build/browser/new/types.js +0 -2
- package/build/browser/new/types.js.map +0 -1
- package/build/cjs/chunk-OVBG5VXE.cjs.map +0 -1
- package/build/esm/new/types.js +0 -2
- package/build/esm/new/types.js.map +0 -1
- package/build/types/new/types.d.ts +0 -5
- package/build/types/new/types.d.ts.map +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Client,
|
|
2
|
-
import { ObservableClient, ActionSignatureFromDef } from '@osdk/client/unstable-do-not-use';
|
|
1
|
+
import { Client, Osdk, WhereClause, PropertyKeys, ActionDefinition, ActionEditResponse, ActionValidationError, ActionValidationResponse } from '@osdk/client';
|
|
2
|
+
import { ObservableClient, ActionSignatureFromDef, QueryParameterType, QueryReturnType } from '@osdk/client/unstable-do-not-use';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { User, ListUsersResponse } from '@osdk/foundry.admin';
|
|
5
|
+
import { UserStatus } from '@osdk/foundry.core';
|
|
6
|
+
import { ObjectOrInterfaceDefinition, LinkNames, LinkedType, ObjectTypeDefinition, SimplePropertyDef, ObjectSet, WhereClause as WhereClause$1, DerivedProperty, PropertyKeys as PropertyKeys$1, Osdk as Osdk$1, AggregateOpts, AggregationsResults, QueryDefinition, CompileTimeMetadata, PrimaryKeyType } from '@osdk/api';
|
|
5
7
|
export { U as UseOsdkMetadataResult, u as useOsdkClient, a as useOsdkMetadata } from '../useOsdkMetadata-DFZhnhGZ.cjs';
|
|
6
8
|
|
|
7
9
|
interface OsdkProviderOptions {
|
|
@@ -11,7 +13,121 @@ interface OsdkProviderOptions {
|
|
|
11
13
|
}
|
|
12
14
|
declare function OsdkProvider2({ children, client, observableClient, }: OsdkProviderOptions): React.JSX.Element;
|
|
13
15
|
|
|
14
|
-
interface
|
|
16
|
+
interface UseCurrentFoundryUserOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Enable or disable the query.
|
|
19
|
+
*
|
|
20
|
+
* When `false`, the query will not automatically execute.
|
|
21
|
+
*
|
|
22
|
+
* This is useful for:
|
|
23
|
+
* - Lazy/on-demand queries that should wait for user interaction
|
|
24
|
+
* - Dependent queries that need data from another query first
|
|
25
|
+
* - Conditional queries based on component state
|
|
26
|
+
*
|
|
27
|
+
* @default true
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface UseCurrentFoundryUserResult {
|
|
33
|
+
currentUser: User | undefined;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
error: Error | undefined;
|
|
36
|
+
refetch: () => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the currently signed in User.
|
|
40
|
+
* @param options Options to control the query.
|
|
41
|
+
*/
|
|
42
|
+
declare function useCurrentFoundryUser({ enabled }?: UseCurrentFoundryUserOptions): UseCurrentFoundryUserResult;
|
|
43
|
+
|
|
44
|
+
interface UseFoundryUserOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Enable or disable the query.
|
|
47
|
+
*
|
|
48
|
+
* When `false`, the query will not automatically execute.
|
|
49
|
+
*
|
|
50
|
+
* This is useful for:
|
|
51
|
+
* - Lazy/on-demand queries that should wait for user interaction
|
|
52
|
+
* - Dependent queries that need data from another query first
|
|
53
|
+
* - Conditional queries based on component state
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
enabled?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The default status of the users returned in the list.
|
|
61
|
+
*
|
|
62
|
+
* @default "ACTIVE"
|
|
63
|
+
*/
|
|
64
|
+
status?: UserStatus;
|
|
65
|
+
}
|
|
66
|
+
interface UseFoundryUserResult {
|
|
67
|
+
user: User | undefined;
|
|
68
|
+
isLoading: boolean;
|
|
69
|
+
error: Error | undefined;
|
|
70
|
+
refetch: () => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the User with the specified id.
|
|
74
|
+
* @param userId A Foundry User ID.
|
|
75
|
+
* @param options Options to control the query.
|
|
76
|
+
*/
|
|
77
|
+
declare function useFoundryUser(userId: string, { enabled, status }?: UseFoundryUserOptions): UseFoundryUserResult;
|
|
78
|
+
|
|
79
|
+
interface UseFoundryUsersListOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Enable or disable the query.
|
|
82
|
+
*
|
|
83
|
+
* When `false`, the query will not automatically execute.
|
|
84
|
+
*
|
|
85
|
+
* This is useful for:
|
|
86
|
+
* - Lazy/on-demand queries that should wait for user interaction
|
|
87
|
+
* - Dependent queries that need data from another query first
|
|
88
|
+
* - Conditional queries based on component state
|
|
89
|
+
*
|
|
90
|
+
* @default true
|
|
91
|
+
* });
|
|
92
|
+
*/
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The default status of the users returned in the list.
|
|
96
|
+
*
|
|
97
|
+
* @default "ACTIVE"
|
|
98
|
+
*/
|
|
99
|
+
include?: UserStatus;
|
|
100
|
+
/**
|
|
101
|
+
* The preferred page size for the list.
|
|
102
|
+
*
|
|
103
|
+
* @default 1000
|
|
104
|
+
*/
|
|
105
|
+
pageSize?: number;
|
|
106
|
+
/**
|
|
107
|
+
* The page token indicates where to start paging. This should be omitted from the first page's request.
|
|
108
|
+
* To fetch the next page, clients should take the value from the nextPageToken field of the previous
|
|
109
|
+
* response and use it to populate the pageToken field of the next request.
|
|
110
|
+
*/
|
|
111
|
+
pageToken?: string;
|
|
112
|
+
}
|
|
113
|
+
interface UseFoundryUsersListResult {
|
|
114
|
+
users: ListUsersResponse["data"] | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* The page token to be used for the next page of users. If this is undefined, there are no more
|
|
117
|
+
* pages of users to load.
|
|
118
|
+
*/
|
|
119
|
+
nextPageToken: string | undefined;
|
|
120
|
+
isLoading: boolean;
|
|
121
|
+
error: Error | undefined;
|
|
122
|
+
refetch: () => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Lists all Users. This is a paged endpoint. Each page may be smaller or larger than the requested page size.
|
|
126
|
+
* @param options Options to control the query.
|
|
127
|
+
*/
|
|
128
|
+
declare function useFoundryUsersList({ enabled, include, pageSize, pageToken }?: UseFoundryUsersListOptions): UseFoundryUsersListResult;
|
|
129
|
+
|
|
130
|
+
interface UseLinksOptions<T extends ObjectOrInterfaceDefinition> {
|
|
15
131
|
/**
|
|
16
132
|
* Standard OSDK Where clause for filtering linked objects
|
|
17
133
|
*/
|
|
@@ -52,7 +168,7 @@ interface UseLinksOptions<T extends ObjectTypeDefinition | InterfaceDefinition>
|
|
|
52
168
|
*/
|
|
53
169
|
enabled?: boolean;
|
|
54
170
|
}
|
|
55
|
-
interface UseLinksResult<Q extends
|
|
171
|
+
interface UseLinksResult<Q extends ObjectOrInterfaceDefinition> {
|
|
56
172
|
links: Osdk.Instance<Q>[] | undefined;
|
|
57
173
|
isLoading: boolean;
|
|
58
174
|
error: Error | undefined;
|
|
@@ -77,9 +193,9 @@ interface UseLinksResult<Q extends ObjectTypeDefinition | InterfaceDefinition> {
|
|
|
77
193
|
* @param options Optional configuration for the link query
|
|
78
194
|
* @returns UseLinksResult with links data and metadata
|
|
79
195
|
*/
|
|
80
|
-
declare function useLinks<T extends
|
|
196
|
+
declare function useLinks<T extends ObjectOrInterfaceDefinition, L extends LinkNames<T>>(objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined, linkName: L, options?: UseLinksOptions<LinkedType<T, L>>): UseLinksResult<LinkedType<T, L>>;
|
|
81
197
|
|
|
82
|
-
interface UseObjectSetOptions<Q extends ObjectTypeDefinition
|
|
198
|
+
interface UseObjectSetOptions<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
83
199
|
/**
|
|
84
200
|
* Where clause for filtering
|
|
85
201
|
*/
|
|
@@ -157,7 +273,7 @@ interface UseObjectSetOptions<Q extends ObjectTypeDefinition$1, RDPs extends Rec
|
|
|
157
273
|
*/
|
|
158
274
|
enabled?: boolean;
|
|
159
275
|
}
|
|
160
|
-
interface UseObjectSetResult<Q extends ObjectTypeDefinition
|
|
276
|
+
interface UseObjectSetResult<Q extends ObjectTypeDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
161
277
|
/**
|
|
162
278
|
* The fetched data with derived properties
|
|
163
279
|
*/
|
|
@@ -178,6 +294,10 @@ interface UseObjectSetResult<Q extends ObjectTypeDefinition$1, RDPs extends Reco
|
|
|
178
294
|
* The final ObjectSet after all transformations
|
|
179
295
|
*/
|
|
180
296
|
objectSet: ObjectSet<Q, RDPs>;
|
|
297
|
+
/**
|
|
298
|
+
* The total count of objects matching the query (if available from the API)
|
|
299
|
+
*/
|
|
300
|
+
totalCount?: string;
|
|
181
301
|
}
|
|
182
302
|
/**
|
|
183
303
|
* React hook for observing and interacting with OSDK object sets.
|
|
@@ -190,18 +310,18 @@ interface UseObjectSetResult<Q extends ObjectTypeDefinition$1, RDPs extends Reco
|
|
|
190
310
|
* @param options - Options for filtering, sorting, and adding new derived properties
|
|
191
311
|
* @returns Object set data with both existing and new derived properties
|
|
192
312
|
*/
|
|
193
|
-
declare function useObjectSet<Q extends ObjectTypeDefinition
|
|
313
|
+
declare function useObjectSet<Q extends ObjectTypeDefinition, BaseRDPs extends Record<string, SimplePropertyDef> = never, RDPs extends Record<string, SimplePropertyDef> = {}>(baseObjectSet: ObjectSet<Q, BaseRDPs>, options?: UseObjectSetOptions<Q, RDPs>): UseObjectSetResult<Q, RDPs>;
|
|
194
314
|
|
|
195
315
|
type ApplyActionParams<Q extends ActionDefinition<any>> = Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0] & {
|
|
196
316
|
[K in keyof ObservableClient.ApplyActionOptions as `$${K}`]: ObservableClient.ApplyActionOptions[K];
|
|
197
317
|
};
|
|
198
318
|
interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
|
|
199
|
-
applyAction: (args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>) => Promise<
|
|
319
|
+
applyAction: (args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>) => Promise<ActionEditResponse | undefined>;
|
|
200
320
|
error: undefined | Partial<{
|
|
201
321
|
actionValidation: ActionValidationError;
|
|
202
322
|
unknown: unknown;
|
|
203
323
|
}>;
|
|
204
|
-
data:
|
|
324
|
+
data: ActionEditResponse | undefined;
|
|
205
325
|
isPending: boolean;
|
|
206
326
|
isValidating: boolean;
|
|
207
327
|
/**
|
|
@@ -216,20 +336,18 @@ interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
|
|
|
216
336
|
}
|
|
217
337
|
declare function useOsdkAction<Q extends ActionDefinition<any>>(actionDef: Q): UseOsdkActionResult<Q>;
|
|
218
338
|
|
|
219
|
-
|
|
220
|
-
[K in keyof WP]: WP[K] extends DerivedProperty.Creator<Q, infer T> ? T : never;
|
|
221
|
-
} : {};
|
|
222
|
-
|
|
223
|
-
interface UseOsdkAggregationOptions<T extends ObjectTypeDefinition, A extends AggregateOpts<T>, WithProps extends DerivedProperty.Clause<T> | undefined = undefined> {
|
|
339
|
+
interface UseOsdkAggregationOptions<T extends ObjectOrInterfaceDefinition, A extends AggregateOpts<T>, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
224
340
|
/**
|
|
225
341
|
* Standard OSDK Where clause to filter objects before aggregation
|
|
226
342
|
*/
|
|
227
|
-
where?: WhereClause$1<T,
|
|
343
|
+
where?: WhereClause$1<T, RDPs>;
|
|
228
344
|
/**
|
|
229
345
|
* Define derived properties (RDPs) to be computed server-side.
|
|
230
346
|
* The derived properties can be used in the where clause and aggregation groupBy/select.
|
|
231
347
|
*/
|
|
232
|
-
withProperties?:
|
|
348
|
+
withProperties?: {
|
|
349
|
+
[K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]>;
|
|
350
|
+
};
|
|
233
351
|
/**
|
|
234
352
|
* Aggregation options including groupBy and select
|
|
235
353
|
*/
|
|
@@ -242,7 +360,7 @@ interface UseOsdkAggregationOptions<T extends ObjectTypeDefinition, A extends Ag
|
|
|
242
360
|
*/
|
|
243
361
|
dedupeIntervalMs?: number;
|
|
244
362
|
}
|
|
245
|
-
interface UseOsdkAggregationResult<T extends
|
|
363
|
+
interface UseOsdkAggregationResult<T extends ObjectOrInterfaceDefinition, A extends AggregateOpts<T>> {
|
|
246
364
|
data: AggregationsResults<T, A> | undefined;
|
|
247
365
|
isLoading: boolean;
|
|
248
366
|
error: Error | undefined;
|
|
@@ -272,9 +390,120 @@ interface UseOsdkAggregationResult<T extends ObjectTypeDefinition, A extends Agg
|
|
|
272
390
|
* });
|
|
273
391
|
* ```
|
|
274
392
|
*/
|
|
275
|
-
declare function useOsdkAggregation<Q extends
|
|
393
|
+
declare function useOsdkAggregation<Q extends ObjectOrInterfaceDefinition, const A extends AggregateOpts<Q>, RDPs extends Record<string, SimplePropertyDef> = {}>(type: Q, { where, withProperties, aggregate, dedupeIntervalMs, }: UseOsdkAggregationOptions<Q, A, RDPs>): UseOsdkAggregationResult<Q, A>;
|
|
394
|
+
|
|
395
|
+
interface UseOsdkFunctionOptions<Q extends QueryDefinition<unknown>> {
|
|
396
|
+
/**
|
|
397
|
+
* Parameters to pass to the function.
|
|
398
|
+
* Must include all required parameters; optional parameters can be omitted.
|
|
399
|
+
*/
|
|
400
|
+
params?: CompileTimeMetadata<Q>["parameters"] extends Record<string, never> ? undefined : QueryParameterType<CompileTimeMetadata<Q>["parameters"]>;
|
|
401
|
+
/**
|
|
402
|
+
* Object types this function depends on.
|
|
403
|
+
* When actions modify objects of these types, the function will automatically refetch.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```tsx
|
|
407
|
+
* // Refetch when any Employee object changes
|
|
408
|
+
* { dependsOn: [Employee] }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
dependsOn?: Array<ObjectTypeDefinition | string>;
|
|
412
|
+
/**
|
|
413
|
+
* Specific object instances this function depends on.
|
|
414
|
+
* When any of these specific objects change, the function will refetch.
|
|
415
|
+
* More fine-grained than dependsOn for precise invalidation control.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```tsx
|
|
419
|
+
* // Refetch when this specific employee changes
|
|
420
|
+
* { dependsOnObjects: [employee] }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
dependsOnObjects?: Array<Osdk$1.Instance<ObjectTypeDefinition>>;
|
|
424
|
+
/**
|
|
425
|
+
* The number of milliseconds to dedupe identical function calls.
|
|
426
|
+
* Two calls with the same function and params will share results
|
|
427
|
+
* if the second call is within this interval of the first.
|
|
428
|
+
* @default 2000
|
|
429
|
+
*/
|
|
430
|
+
dedupeIntervalMs?: number;
|
|
431
|
+
/**
|
|
432
|
+
* Whether to enable the query. When false, the query will not execute.
|
|
433
|
+
* Useful for:
|
|
434
|
+
* - Dependent queries that need to wait for other data
|
|
435
|
+
* - Conditional queries based on component state
|
|
436
|
+
*
|
|
437
|
+
* @default true
|
|
438
|
+
* @example
|
|
439
|
+
* // Dependent query - wait for required data
|
|
440
|
+
* const { data: employee } = useOsdkObject(Employee, employeeId);
|
|
441
|
+
* const { data: report } = useOsdkFunction(getEmployeeReport, {
|
|
442
|
+
* params: { employeeId: employee?.$primaryKey },
|
|
443
|
+
* enabled: !!employee
|
|
444
|
+
* });
|
|
445
|
+
*/
|
|
446
|
+
enabled?: boolean;
|
|
447
|
+
}
|
|
448
|
+
interface UseOsdkFunctionResult<Q extends QueryDefinition<unknown>> {
|
|
449
|
+
/**
|
|
450
|
+
* The function result, or undefined if not yet loaded or on error.
|
|
451
|
+
*/
|
|
452
|
+
data: QueryReturnType<CompileTimeMetadata<Q>["output"]> | undefined;
|
|
453
|
+
/**
|
|
454
|
+
* True while the function is executing.
|
|
455
|
+
*/
|
|
456
|
+
isLoading: boolean;
|
|
457
|
+
/**
|
|
458
|
+
* Error if the function execution failed.
|
|
459
|
+
*/
|
|
460
|
+
error: Error | undefined;
|
|
461
|
+
/**
|
|
462
|
+
* Timestamp (ms since epoch) of when the result was last fetched.
|
|
463
|
+
*/
|
|
464
|
+
lastUpdated: number;
|
|
465
|
+
/**
|
|
466
|
+
* Manually refetch the function.
|
|
467
|
+
* Useful for "pull to refresh" or retry patterns.
|
|
468
|
+
*/
|
|
469
|
+
refetch: () => void;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* React hook for executing and observing OSDK functions.
|
|
473
|
+
*
|
|
474
|
+
* Provides automatic caching, deduplication, and reactive updates for function calls.
|
|
475
|
+
* Functions are automatically re-fetched when dependencies change (configured via options).
|
|
476
|
+
*
|
|
477
|
+
* @param queryDef - The QueryDefinition to execute
|
|
478
|
+
* @param options - Configuration options for the function call
|
|
479
|
+
* @returns Object containing result, loading state, error, and refetch function
|
|
480
|
+
*
|
|
481
|
+
* @example Basic usage
|
|
482
|
+
* ```tsx
|
|
483
|
+
* const { data, isLoading, error } = useOsdkFunction(getEmployeeStats, {
|
|
484
|
+
* params: { departmentId: "engineering" }
|
|
485
|
+
* });
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @example With dependency tracking
|
|
489
|
+
* ```tsx
|
|
490
|
+
* const { data, refetch } = useOsdkFunction(calculateMetrics, {
|
|
491
|
+
* params: { startDate, endDate },
|
|
492
|
+
* dependsOn: [Employee, Project],
|
|
493
|
+
* });
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @example With specific object dependencies
|
|
497
|
+
* ```tsx
|
|
498
|
+
* const { data } = useOsdkFunction(getEmployeeReport, {
|
|
499
|
+
* params: { employeeId: employee.$primaryKey },
|
|
500
|
+
* dependsOnObjects: [employee],
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
declare function useOsdkFunction<Q extends QueryDefinition<unknown>>(queryDef: Q, options?: UseOsdkFunctionOptions<Q>): UseOsdkFunctionResult<Q>;
|
|
276
505
|
|
|
277
|
-
interface UseOsdkObjectResult<Q extends ObjectTypeDefinition
|
|
506
|
+
interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {
|
|
278
507
|
object: Osdk$1.Instance<Q> | undefined;
|
|
279
508
|
isLoading: boolean;
|
|
280
509
|
error: Error | undefined;
|
|
@@ -288,7 +517,7 @@ interface UseOsdkObjectResult<Q extends ObjectTypeDefinition$1> {
|
|
|
288
517
|
* @param obj an existing `Osdk.Instance` object to get metadata for.
|
|
289
518
|
* @param enabled Enable or disable the query (defaults to true)
|
|
290
519
|
*/
|
|
291
|
-
declare function useOsdkObject<Q extends ObjectTypeDefinition
|
|
520
|
+
declare function useOsdkObject<Q extends ObjectTypeDefinition>(obj: Osdk$1.Instance<Q>, enabled?: boolean): UseOsdkObjectResult<Q>;
|
|
292
521
|
/**
|
|
293
522
|
* Loads an object by type and primary key.
|
|
294
523
|
*
|
|
@@ -296,13 +525,13 @@ declare function useOsdkObject<Q extends ObjectTypeDefinition$1>(obj: Osdk$1.Ins
|
|
|
296
525
|
* @param primaryKey
|
|
297
526
|
* @param enabled Enable or disable the query (defaults to true)
|
|
298
527
|
*/
|
|
299
|
-
declare function useOsdkObject<Q extends ObjectTypeDefinition
|
|
528
|
+
declare function useOsdkObject<Q extends ObjectTypeDefinition>(type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean): UseOsdkObjectResult<Q>;
|
|
300
529
|
|
|
301
|
-
interface UseOsdkObjectsOptions<T extends
|
|
530
|
+
interface UseOsdkObjectsOptions<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
302
531
|
/**
|
|
303
532
|
* Standard OSDK Where with RDP support
|
|
304
533
|
*/
|
|
305
|
-
where?: WhereClause$1<T,
|
|
534
|
+
where?: WhereClause$1<T, RDPs>;
|
|
306
535
|
/**
|
|
307
536
|
* The preferred page size for the list.
|
|
308
537
|
*/
|
|
@@ -315,14 +544,16 @@ interface UseOsdkObjectsOptions<T extends ObjectTypeDefinition$1 | InterfaceDefi
|
|
|
315
544
|
* Define derived properties (RDPs) to be computed server-side and attached to each object.
|
|
316
545
|
* These properties will be available on the returned objects alongside their regular properties.
|
|
317
546
|
*/
|
|
318
|
-
withProperties?:
|
|
547
|
+
withProperties?: {
|
|
548
|
+
[K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]>;
|
|
549
|
+
};
|
|
319
550
|
/**
|
|
320
551
|
* Intersect the results with additional object sets.
|
|
321
552
|
* Each element defines a where clause for an object set to intersect with.
|
|
322
553
|
* The final result will only include objects that match ALL conditions.
|
|
323
554
|
*/
|
|
324
555
|
intersectWith?: Array<{
|
|
325
|
-
where: WhereClause$1<T,
|
|
556
|
+
where: WhereClause$1<T, RDPs>;
|
|
326
557
|
}>;
|
|
327
558
|
/**
|
|
328
559
|
* Pivot to related objects through a link.
|
|
@@ -403,10 +634,22 @@ interface UseOsdkObjectsOptions<T extends ObjectTypeDefinition$1 | InterfaceDefi
|
|
|
403
634
|
*/
|
|
404
635
|
enabled?: boolean;
|
|
405
636
|
}
|
|
406
|
-
interface UseOsdkListResult<T extends
|
|
637
|
+
interface UseOsdkListResult<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
638
|
+
/**
|
|
639
|
+
* Function to fetch more pages (undefined if no more pages)
|
|
640
|
+
*/
|
|
407
641
|
fetchMore: (() => Promise<void>) | undefined;
|
|
408
|
-
|
|
642
|
+
/**
|
|
643
|
+
* The fetched data with derived properties
|
|
644
|
+
*/
|
|
645
|
+
data: Osdk$1.Instance<T, "$allBaseProperties", PropertyKeys$1<T>, RDPs>[] | undefined;
|
|
646
|
+
/**
|
|
647
|
+
* Whether data is currently being loaded
|
|
648
|
+
*/
|
|
409
649
|
isLoading: boolean;
|
|
650
|
+
/**
|
|
651
|
+
* Any error that occurred during fetching
|
|
652
|
+
*/
|
|
410
653
|
error: Error | undefined;
|
|
411
654
|
/**
|
|
412
655
|
* Refers to whether the ordered list of objects (only considering the $primaryKey)
|
|
@@ -416,11 +659,15 @@ interface UseOsdkListResult<T extends ObjectTypeDefinition$1 | InterfaceDefiniti
|
|
|
416
659
|
* do that on a per object basis with useOsdkObject
|
|
417
660
|
*/
|
|
418
661
|
isOptimistic: boolean;
|
|
662
|
+
/**
|
|
663
|
+
* The total count of objects matching the query (if available from the API)
|
|
664
|
+
*/
|
|
665
|
+
totalCount?: string;
|
|
419
666
|
}
|
|
420
|
-
declare function useOsdkObjects<Q extends
|
|
667
|
+
declare function useOsdkObjects<Q extends ObjectOrInterfaceDefinition, L extends LinkNames<Q>>(type: Q, options: UseOsdkObjectsOptions<Q> & {
|
|
421
668
|
pivotTo: L;
|
|
422
669
|
}): UseOsdkListResult<LinkedType<Q, L>>;
|
|
423
|
-
declare function useOsdkObjects<Q extends
|
|
670
|
+
declare function useOsdkObjects<Q extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}>(type: Q, options?: UseOsdkObjectsOptions<Q, RDPs>): UseOsdkListResult<Q, RDPs>;
|
|
424
671
|
|
|
425
672
|
interface DebouncedCallback<TArgs extends readonly unknown[]> {
|
|
426
673
|
(...args: TArgs): void;
|
|
@@ -457,4 +704,4 @@ interface DebouncedCallback<TArgs extends readonly unknown[]> {
|
|
|
457
704
|
*/
|
|
458
705
|
declare function useDebouncedCallback<TArgs extends readonly unknown[]>(callback: (...args: TArgs) => void | Promise<void>, delay: number): DebouncedCallback<TArgs>;
|
|
459
706
|
|
|
460
|
-
export { OsdkProvider2, type UseOsdkAggregationResult, type UseOsdkListResult, useDebouncedCallback, useLinks, useObjectSet, useOsdkAction, useOsdkAggregation, useOsdkObject, useOsdkObjects };
|
|
707
|
+
export { OsdkProvider2, type UseOsdkAggregationResult, type UseOsdkFunctionOptions, type UseOsdkFunctionResult, type UseOsdkListResult, useCurrentFoundryUser, useDebouncedCallback, useFoundryUser, useFoundryUsersList, useLinks, useObjectSet, useOsdkAction, useOsdkAggregation, useOsdkFunction, useOsdkObject, useOsdkObjects };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkObjectsWithProperties.js","names":["Employee","useOsdkObjects","TestComponent","data","withProperties","constantValue","employee","
|
|
1
|
+
{"version":3,"file":"useOsdkObjectsWithProperties.js","names":["Employee","useOsdkObjects","TestComponent","data","withProperties","constantValue","employee","constant","integer"],"sources":["useOsdkObjectsWithProperties.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\n// WARNING!\n// WARNING!\n// This file is used for tests that check intellisense. Editing this file by hand will likely\n// break tests that have hard coded line numbers and line offsets.\n\nimport type { DerivedProperty } from \"@osdk/api\";\nimport { Employee } from \"@osdk/client.test.ontology\";\nimport { useOsdkObjects } from \"@osdk/react/experimental\";\n\nfunction TestComponent() {\n const withProps: DerivedProperty.Clause<typeof Employee> = {\n constantValue: (employee) => employee.constant.integer(42),\n };\n\n const { data } = useOsdkObjects(Employee, {\n withProperties: withProps,\n });\n\n return null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,QAAQ,4BAA4B;AACrD,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAASC,aAAaA,CAAA,EAAG;EAKvB,MAAM;IAAEC;EAAK,CAAC,GAAGF,cAAc,CAACD,QAAQ,EAAE;IACxCI,cAAc,EAL2C;MACzDC,aAAa,EAAGC,QAAQ,IAAKA,QAAQ,CAACC,QAAQ,CAACC,OAAO,CAAC,EAAE;IAC3D;EAIA,CAAC,CAAC;EAEF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intellisense.test.js","names":["startTsServer","findUpSync","path","invariant","ts","afterEach","beforeAll","beforeEach","describe","expect","it","vi","rootLogger","hoisted","pino","pinoPretty","EventEmitter","Promise","resolve","level","build","sync","timestampKey","undefined","errorLikeObjectKeys","errorProps","ignore","destination","write","a","at","slice","console","log","packagesDir","reactPackagePath","reactPackageJson","cwd","import","meta","dirname","process","env","NODE_ENV","join","tsServer","intellisenseFilePath","task","name","sys","fileExists","toBeTruthy","sendOpenRequest","file","error","stop","timeout","resp","sendCompletionsRequest","line","offset","triggerKind","CompletionTriggerKind","Invoked","completions","body","entries","map","e","toContain","typeResp","sendQuickInfoRequest","displayString","toBeDefined","dataResp"],"sources":["intellisense.test.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 { Logger } from \"@osdk/api\";\nimport type { TsServer } from \"@osdk/client/internal-node\";\nimport { startTsServer } from \"@osdk/client/internal-node\";\nimport { findUpSync } from \"find-up\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\nimport * as ts from \"typescript\";\nimport {\n afterEach,\n beforeAll,\n beforeEach,\n describe,\n expect,\n it,\n vi,\n} from \"vitest\";\n\n// it needs to be hoisted because its referenced from our mocked WebSocket\n// which must be hoisted to work\nconst rootLogger = await vi.hoisted(async (): Promise<Logger> => {\n const pino = (await import(\"pino\")).pino;\n const pinoPretty = await import(\"pino-pretty\");\n const { EventEmitter } = await import(\"node:events\");\n class PinoConsoleLogDestination extends EventEmitter {\n write(a: string) {\n // remove trailing newline since console.log adds one\n if (a.at(-1) === \"\\n\") a = a.slice(0, -1);\n\n // This lets the test framework aggregate the logs per test, whereas direct to stdout does not\n console.log(a);\n }\n }\n return Promise.resolve(pino(\n { level: \"info\" },\n (pinoPretty.build)({\n sync: true,\n timestampKey: undefined,\n errorLikeObjectKeys: [\"error\", \"err\", \"exception\"],\n errorProps: \"stack,cause,properties\",\n ignore: \"time,hostname,pid\",\n destination: new PinoConsoleLogDestination(),\n }),\n ));\n});\n\n/**\n * @vitest-environment node\n * @vitest-pool forks\n */\ndescribe(\"intellisense\", () => {\n let packagesDir: string;\n let reactPackagePath: string;\n\n beforeAll(() => {\n const reactPackageJson = findUpSync(\"package.json\", {\n cwd: import.meta.dirname,\n });\n console.log({ reactPackageJson });\n invariant(reactPackageJson != null);\n packagesDir = path.join(\n path.dirname(reactPackageJson),\n \"..\",\n );\n\n reactPackagePath = path.join(packagesDir, \"react\");\n });\n\n let tsServer: TsServer | undefined;\n let intellisenseFilePath: string;\n\n beforeEach(async (a) => {\n intellisenseFilePath = path.join(\n reactPackagePath,\n \"src\",\n \"intellisense.test.helpers\",\n `${a.task.name}.ts`,\n );\n\n console.log(intellisenseFilePath);\n\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n\n try {\n tsServer = await startTsServer(rootLogger);\n await tsServer.sendOpenRequest({ file: intellisenseFilePath });\n } catch (error) {\n if (tsServer) {\n try {\n tsServer.stop();\n } catch {\n // Ignore cleanup errors\n }\n tsServer = undefined;\n }\n throw error;\n }\n });\n\n afterEach(async () => {\n if (tsServer) {\n tsServer.stop();\n tsServer = undefined;\n }\n });\n\n it(\"useOsdkObjectsWithPivot\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp } = await tsServer.sendCompletionsRequest({\n file: intellisenseFilePath,\n line: 29,\n offset: 15,\n triggerKind: ts.CompletionTriggerKind.Invoked,\n });\n\n const completions = resp.body?.entries.map(e => e.name) ?? [];\n expect(completions).toContain(\"lead\");\n\n const { resp: typeResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 33,\n offset: 10,\n });\n\n expect(typeResp.body?.displayString).toBeDefined();\n expect(typeResp.body?.displayString).toContain(\"Employee\");\n });\n\n it(\"useOsdkObjectsWithProperties\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 27,\n offset: 10,\n });\n\n expect(resp.body?.displayString).toContain(\"DerivedProperty.Clause\");\n\n const { resp: dataResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 31,\n offset: 11,\n });\n\n expect(dataResp.body?.displayString).toBeDefined();\n expect(dataResp.body?.displayString).toContain(\"Osdk.Instance<Employee\");\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,UAAU,QAAQ,SAAS;AACpC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAO,KAAKC,EAAE,MAAM,YAAY;AAChC,SACEC,SAAS,EACTC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,EAAE,EACFC,EAAE,QACG,QAAQ;;AAEf;AACA;AACA,MAAMC,UAAU,GAAG,MAAMD,EAAE,CAACE,OAAO,CAAC,YAA6B;EAC/D,MAAMC,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,EAAEA,IAAI;EACxC,MAAMC,UAAU,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAC9C,MAAM;IAAEC;EAAa,CAAC,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAUpD,OAAOC,OAAO,CAACC,OAAO,CAACJ,IAAI,CACzB;IAAEK,KAAK,EAAE;EAAO,CAAC,EAChBJ,UAAU,CAACK,KAAK,CAAE;IACjBC,IAAI,EAAE,IAAI;IACVC,YAAY,EAAEC,SAAS;IACvBC,mBAAmB,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,CAAC;IAClDC,UAAU,EAAE,wBAAwB;IACpCC,MAAM,EAAE,mBAAmB;IAC3BC,WAAW,EAAE,IAjBjB,cAAwCX,YAAY,CAAC;MACnDY,KAAKA,CAACC,CAAS,EAAE;QACf;QACA,IAAIA,CAAC,CAACC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAED,CAAC,GAAGA,CAAC,CAACE,KAAK,CAAC,CAAC,EAAE,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.js","names":["startTsServer","findUpSync","path","invariant","ts","afterEach","beforeAll","beforeEach","describe","expect","it","vi","rootLogger","hoisted","pino","pinoPretty","EventEmitter","Promise","resolve","level","build","sync","timestampKey","undefined","errorLikeObjectKeys","errorProps","ignore","destination","write","a","at","slice","console","log","packagesDir","reactPackagePath","reactPackageJson","cwd","import","meta","dirname","process","env","NODE_ENV","join","tsServer","intellisenseFilePath","task","name","sys","fileExists","toBeTruthy","sendOpenRequest","file","error","stop","timeout","resp","sendCompletionsRequest","line","offset","triggerKind","CompletionTriggerKind","Invoked","completions","body","entries","map","e","toContain","typeResp","sendQuickInfoRequest","displayString","toBeDefined","dataResp"],"sources":["intellisense.test.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 { Logger } from \"@osdk/api\";\nimport type { TsServer } from \"@osdk/client/internal-node\";\nimport { startTsServer } from \"@osdk/client/internal-node\";\nimport { findUpSync } from \"find-up\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\nimport * as ts from \"typescript\";\nimport {\n afterEach,\n beforeAll,\n beforeEach,\n describe,\n expect,\n it,\n vi,\n} from \"vitest\";\n\n// it needs to be hoisted because its referenced from our mocked WebSocket\n// which must be hoisted to work\nconst rootLogger = await vi.hoisted(async (): Promise<Logger> => {\n const pino = (await import(\"pino\")).pino;\n const pinoPretty = await import(\"pino-pretty\");\n const { EventEmitter } = await import(\"node:events\");\n class PinoConsoleLogDestination extends EventEmitter {\n write(a: string) {\n // remove trailing newline since console.log adds one\n if (a.at(-1) === \"\\n\") a = a.slice(0, -1);\n\n // This lets the test framework aggregate the logs per test, whereas direct to stdout does not\n console.log(a);\n }\n }\n return Promise.resolve(pino(\n { level: \"info\" },\n (pinoPretty.build)({\n sync: true,\n timestampKey: undefined,\n errorLikeObjectKeys: [\"error\", \"err\", \"exception\"],\n errorProps: \"stack,cause,properties\",\n ignore: \"time,hostname,pid\",\n destination: new PinoConsoleLogDestination(),\n }),\n ));\n});\n\n/**\n * @vitest-environment node\n * @vitest-pool forks\n */\ndescribe(\"intellisense\", () => {\n let packagesDir: string;\n let reactPackagePath: string;\n\n beforeAll(() => {\n const reactPackageJson = findUpSync(\"package.json\", {\n cwd: import.meta.dirname,\n });\n console.log({ reactPackageJson });\n invariant(reactPackageJson != null);\n packagesDir = path.join(\n path.dirname(reactPackageJson),\n \"..\",\n );\n\n reactPackagePath = path.join(packagesDir, \"react\");\n });\n\n let tsServer: TsServer | undefined;\n let intellisenseFilePath: string;\n\n beforeEach(async (a) => {\n intellisenseFilePath = path.join(\n reactPackagePath,\n \"src\",\n \"intellisense.test.helpers\",\n `${a.task.name}.ts`,\n );\n\n console.log(intellisenseFilePath);\n\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n\n try {\n tsServer = await startTsServer(rootLogger);\n await tsServer.sendOpenRequest({ file: intellisenseFilePath });\n } catch (error) {\n if (tsServer) {\n try {\n tsServer.stop();\n } catch {\n // Ignore cleanup errors\n }\n tsServer = undefined;\n }\n throw error;\n }\n });\n\n afterEach(() => {\n if (tsServer) {\n tsServer.stop();\n tsServer = undefined;\n }\n });\n\n it(\"useOsdkObjectsWithPivot\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp } = await tsServer.sendCompletionsRequest({\n file: intellisenseFilePath,\n line: 29,\n offset: 15,\n triggerKind: ts.CompletionTriggerKind.Invoked,\n });\n\n const completions = resp.body?.entries.map(e => e.name) ?? [];\n expect(completions).toContain(\"lead\");\n\n const { resp: typeResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 33,\n offset: 10,\n });\n\n expect(typeResp.body?.displayString).toBeDefined();\n expect(typeResp.body?.displayString).toContain(\"Employee\");\n });\n\n it(\"useOsdkObjectsWithProperties\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 27,\n offset: 10,\n });\n\n expect(resp.body?.displayString).toContain(\"DerivedProperty.Clause\");\n\n const { resp: dataResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 31,\n offset: 11,\n });\n\n expect(dataResp.body?.displayString).toBeDefined();\n expect(dataResp.body?.displayString).toContain(\"Osdk.Instance<Employee\");\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,UAAU,QAAQ,SAAS;AACpC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAO,KAAKC,EAAE,MAAM,YAAY;AAChC,SACEC,SAAS,EACTC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,EAAE,EACFC,EAAE,QACG,QAAQ;;AAEf;AACA;AACA,MAAMC,UAAU,GAAG,MAAMD,EAAE,CAACE,OAAO,CAAC,YAA6B;EAC/D,MAAMC,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,EAAEA,IAAI;EACxC,MAAMC,UAAU,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAC9C,MAAM;IAAEC;EAAa,CAAC,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAUpD,OAAOC,OAAO,CAACC,OAAO,CAACJ,IAAI,CACzB;IAAEK,KAAK,EA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,IAAI,EAAEiB;IAAS,CAAC,GAAG,MAAM7B,QAAQ,CAAC0B,oBAAoB,CAAC;MAC7DlB,IAAI,EAAEP,oBAAoB;MAC1Ba,IAAI,EAAE,EAAE;MACRC,MAAM,EAAE;IACV,CAAC,CAAC;IAEFnD,MAAM,CAACiE,QAAQ,CAACT,IAAI,EAAEO,aAAa,CAAC,CAACC,WAAW,CAAC,CAAC;IAClDhE,MAAM,CAACiE,QAAQ,CAACT,IAAI,EAAEO,aAAa,CAAC,CAACH,SAAS,CAAC,wBAAwB,CAAC;EAC1E,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Users } from "@osdk/foundry.admin";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { usePlatformQuery } from "../../../utils/usePlatformQuery.js";
|
|
20
|
+
import { OsdkContext2 } from "../../OsdkContext2.js";
|
|
21
|
+
/**
|
|
22
|
+
* Get the currently signed in User.
|
|
23
|
+
* @param options Options to control the query.
|
|
24
|
+
*/
|
|
25
|
+
export function useCurrentFoundryUser({
|
|
26
|
+
enabled = true
|
|
27
|
+
} = {}) {
|
|
28
|
+
const {
|
|
29
|
+
client
|
|
30
|
+
} = React.useContext(OsdkContext2);
|
|
31
|
+
const handleQuery = React.useCallback(() => Users.getCurrent(client), [client]);
|
|
32
|
+
const query = usePlatformQuery({
|
|
33
|
+
query: handleQuery,
|
|
34
|
+
enabled,
|
|
35
|
+
queryName: "foundry-current-user"
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
currentUser: query.data,
|
|
39
|
+
isLoading: query.isLoading,
|
|
40
|
+
error: query.error,
|
|
41
|
+
refetch: query.refetch
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=useCurrentFoundryUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentFoundryUser.js","names":["Users","React","usePlatformQuery","OsdkContext2","useCurrentFoundryUser","enabled","client","useContext","handleQuery","useCallback","getCurrent","query","queryName","currentUser","data","isLoading","error","refetch"],"sources":["useCurrentFoundryUser.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 User, Users } from \"@osdk/foundry.admin\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface UseCurrentFoundryUserOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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 * });\n */\n enabled?: boolean;\n}\n\nexport interface UseCurrentFoundryUserResult {\n currentUser: User | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get the currently signed in User.\n * @param options Options to control the query.\n */\nexport function useCurrentFoundryUser(\n { enabled = true }: UseCurrentFoundryUserOptions = {},\n): UseCurrentFoundryUserResult {\n const { client } = React.useContext(OsdkContext2);\n\n const handleQuery = React.useCallback(\n () => Users.getCurrent(client),\n [client],\n );\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"foundry-current-user\",\n });\n\n return {\n currentUser: query.data,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAoBA,KAAK,QAAQ,qBAAqB;AACtD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,YAAY,QAAQ,uBAAuB;AA4BpD;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnC;EAAEC,OAAO,GAAG;AAAmC,CAAC,GAAG,CAAC,CAAC,EACxB;EAC7B,MAAM;IAAEC;EAAO,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;EAEjD,MAAMK,WAAW,GAAGP,KAAK,CAACQ,WAAW,CACnC,MAAMT,KAAK,CAACU,UAAU,CAACJ,MAAM,CAAC,EAC9B,CAACA,MAAM,CACT,CAAC;EAED,MAAMK,KAAK,GAAGT,gBAAgB,CAAC;IAC7BS,KAAK,EAAEH,WAAW;IAClBH,OAAO;IACPO,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,WAAW,EAAEF,KAAK,CAACG,IAAI;IACvBC,SAAS,EAAEJ,KAAK,CAACI,SAAS;IAC1BC,KAAK,EAAEL,KAAK,CAACK,KAAK;IAClBC,OAAO,EAAEN,KAAK,CAACM;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Users } from "@osdk/foundry.admin";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { usePlatformQuery } from "../../../utils/usePlatformQuery.js";
|
|
20
|
+
import { OsdkContext2 } from "../../OsdkContext2.js";
|
|
21
|
+
/**
|
|
22
|
+
* Get the User with the specified id.
|
|
23
|
+
* @param userId A Foundry User ID.
|
|
24
|
+
* @param options Options to control the query.
|
|
25
|
+
*/
|
|
26
|
+
export function useFoundryUser(userId, {
|
|
27
|
+
enabled = true,
|
|
28
|
+
status = "ACTIVE"
|
|
29
|
+
} = {}) {
|
|
30
|
+
const {
|
|
31
|
+
client
|
|
32
|
+
} = React.useContext(OsdkContext2);
|
|
33
|
+
const handleQuery = React.useCallback(() => {
|
|
34
|
+
return Users.get(client, userId, {
|
|
35
|
+
status
|
|
36
|
+
});
|
|
37
|
+
}, [client, userId, status]);
|
|
38
|
+
const query = usePlatformQuery({
|
|
39
|
+
query: handleQuery,
|
|
40
|
+
enabled,
|
|
41
|
+
queryName: "foundry-user"
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
user: query.data,
|
|
45
|
+
isLoading: query.isLoading,
|
|
46
|
+
error: query.error,
|
|
47
|
+
refetch: query.refetch
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=useFoundryUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFoundryUser.js","names":["Users","React","usePlatformQuery","OsdkContext2","useFoundryUser","userId","enabled","status","client","useContext","handleQuery","useCallback","get","query","queryName","user","data","isLoading","error","refetch"],"sources":["useFoundryUser.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 User, Users } from \"@osdk/foundry.admin\";\nimport type { UserStatus } from \"@osdk/foundry.core\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface UseFoundryUserOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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 * });\n */\n enabled?: boolean;\n\n /**\n * The default status of the users returned in the list.\n *\n * @default \"ACTIVE\"\n */\n status?: UserStatus;\n}\n\nexport interface UseFoundryUserResult {\n user: User | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get the User with the specified id.\n * @param userId A Foundry User ID.\n * @param options Options to control the query.\n */\nexport function useFoundryUser(\n userId: string,\n { enabled = true, status = \"ACTIVE\" }: UseFoundryUserOptions = {},\n): UseFoundryUserResult {\n const { client } = React.useContext(OsdkContext2);\n\n const handleQuery = React.useCallback(() => {\n return Users.get(client, userId, { status });\n }, [client, userId, status]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"foundry-user\",\n });\n\n return {\n user: query.data,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAoBA,KAAK,QAAQ,qBAAqB;AAEtD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,YAAY,QAAQ,uBAAuB;AAmCpD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAC5BC,MAAc,EACd;EAAEC,OAAO,GAAG,IAAI;EAAEC,MAAM,GAAG;AAAgC,CAAC,GAAG,CAAC,CAAC,EAC3C;EACtB,MAAM;IAAEC;EAAO,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACN,YAAY,CAAC;EAEjD,MAAMO,WAAW,GAAGT,KAAK,CAACU,WAAW,CAAC,MAAM;IAC1C,OAAOX,KAAK,CAACY,GAAG,CAACJ,MAAM,EAAEH,MAAM,EAAE;MAAEE;IAAO,CAAC,CAAC;EAC9C,CAAC,EAAE,CAACC,MAAM,EAAEH,MAAM,EAAEE,MAAM,CAAC,CAAC;EAE5B,MAAMM,KAAK,GAAGX,gBAAgB,CAAC;IAC7BW,KAAK,EAAEH,WAAW;IAClBJ,OAAO;IACPQ,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,IAAI,EAAEF,KAAK,CAACG,IAAI;IAChBC,SAAS,EAAEJ,KAAK,CAACI,SAAS;IAC1BC,KAAK,EAAEL,KAAK,CAACK,KAAK;IAClBC,OAAO,EAAEN,KAAK,CAACM;EACjB,CAAC;AACH","ignoreList":[]}
|