@osdk/react 0.9.0-beta.8 → 0.9.0-rc.11
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/CHANGELOG.md +49 -0
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js +1 -1
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -1
- package/build/browser/new/useLinks.js +14 -7
- 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/useOsdkAggregation.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +16 -17
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/browser/public/experimental.js.map +1 -1
- package/build/cjs/public/experimental.cjs +35 -23
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +75 -80
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js +1 -1
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -1
- package/build/esm/new/useLinks.js +14 -7
- 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/useOsdkAggregation.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +16 -17
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/esm/public/experimental.js.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/useOsdkAggregation.d.ts +6 -7
- package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +63 -73
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/build/types/public/experimental.d.ts +1 -1
- package/build/types/public/experimental.d.ts.map +1 -1
- package/docs/getting-started.md +6 -10
- package/docs/querying-data.md +28 -0
- package/package.json +7 -7
- package/build/browser/new/types.js +0 -2
- package/build/browser/new/types.js.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
|
@@ -3,7 +3,7 @@ import { ObservableClient, ActionSignatureFromDef, QueryParameterType, QueryRetu
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { User, ListUsersResponse } from '@osdk/foundry.admin';
|
|
5
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,
|
|
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';
|
|
7
7
|
export { U as UseOsdkMetadataResult, u as useOsdkClient, a as useOsdkMetadata } from '../useOsdkMetadata-DFZhnhGZ.cjs';
|
|
8
8
|
|
|
9
9
|
interface OsdkProviderOptions {
|
|
@@ -294,6 +294,10 @@ interface UseObjectSetResult<Q extends ObjectTypeDefinition, RDPs extends Record
|
|
|
294
294
|
* The final ObjectSet after all transformations
|
|
295
295
|
*/
|
|
296
296
|
objectSet: ObjectSet<Q, RDPs>;
|
|
297
|
+
/**
|
|
298
|
+
* The total count of objects matching the query (if available from the API)
|
|
299
|
+
*/
|
|
300
|
+
totalCount?: string;
|
|
297
301
|
}
|
|
298
302
|
/**
|
|
299
303
|
* React hook for observing and interacting with OSDK object sets.
|
|
@@ -332,20 +336,18 @@ interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
|
|
|
332
336
|
}
|
|
333
337
|
declare function useOsdkAction<Q extends ActionDefinition<any>>(actionDef: Q): UseOsdkActionResult<Q>;
|
|
334
338
|
|
|
335
|
-
|
|
336
|
-
[K in keyof WP]: WP[K] extends DerivedProperty.Creator<Q, infer T> ? T : never;
|
|
337
|
-
} : {};
|
|
338
|
-
|
|
339
|
-
interface UseOsdkAggregationOptions<T extends ObjectOrInterfaceDefinition, 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> = {}> {
|
|
340
340
|
/**
|
|
341
341
|
* Standard OSDK Where clause to filter objects before aggregation
|
|
342
342
|
*/
|
|
343
|
-
where?: WhereClause$1<T,
|
|
343
|
+
where?: WhereClause$1<T, RDPs>;
|
|
344
344
|
/**
|
|
345
345
|
* Define derived properties (RDPs) to be computed server-side.
|
|
346
346
|
* The derived properties can be used in the where clause and aggregation groupBy/select.
|
|
347
347
|
*/
|
|
348
|
-
withProperties?:
|
|
348
|
+
withProperties?: {
|
|
349
|
+
[K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]>;
|
|
350
|
+
};
|
|
349
351
|
/**
|
|
350
352
|
* Aggregation options including groupBy and select
|
|
351
353
|
*/
|
|
@@ -388,7 +390,7 @@ interface UseOsdkAggregationResult<T extends ObjectOrInterfaceDefinition, A exte
|
|
|
388
390
|
* });
|
|
389
391
|
* ```
|
|
390
392
|
*/
|
|
391
|
-
declare function useOsdkAggregation<Q extends ObjectOrInterfaceDefinition, const A extends AggregateOpts<Q>,
|
|
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>;
|
|
392
394
|
|
|
393
395
|
interface UseOsdkFunctionOptions<Q extends QueryDefinition<unknown>> {
|
|
394
396
|
/**
|
|
@@ -525,31 +527,70 @@ declare function useOsdkObject<Q extends ObjectTypeDefinition>(obj: Osdk$1.Insta
|
|
|
525
527
|
*/
|
|
526
528
|
declare function useOsdkObject<Q extends ObjectTypeDefinition>(type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean): UseOsdkObjectResult<Q>;
|
|
527
529
|
|
|
528
|
-
interface UseOsdkObjectsOptions<T extends ObjectOrInterfaceDefinition,
|
|
530
|
+
interface UseOsdkObjectsOptions<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
529
531
|
/**
|
|
530
|
-
*
|
|
532
|
+
* Fetch objects by their RIDs (Resource Identifiers).
|
|
533
|
+
* When provided, starts with a static objectset containing these RIDs.
|
|
534
|
+
* Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* // Fetch specific objects by RID
|
|
538
|
+
* useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* // Fetch specific objects by RID, filtered by status
|
|
542
|
+
* useOsdkObjects(Employee, {
|
|
543
|
+
* rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],
|
|
544
|
+
* where: { status: 'active' }
|
|
545
|
+
* })
|
|
531
546
|
*/
|
|
532
|
-
|
|
547
|
+
rids?: readonly string[];
|
|
533
548
|
/**
|
|
534
|
-
*
|
|
549
|
+
* Standard OSDK Where clause with RDP support.
|
|
550
|
+
* When used with `rids`, filters the RID set.
|
|
551
|
+
* When used alone, filters all objects of the type.
|
|
552
|
+
*/
|
|
553
|
+
where?: WhereClause$1<T, RDPs>;
|
|
554
|
+
/**
|
|
555
|
+
* Sort results by one or more properties.
|
|
535
556
|
*/
|
|
536
|
-
pageSize?: number;
|
|
537
|
-
/** */
|
|
538
557
|
orderBy?: {
|
|
539
558
|
[K in PropertyKeys$1<T>]?: "asc" | "desc";
|
|
540
559
|
};
|
|
560
|
+
/**
|
|
561
|
+
* The preferred page size for the list.
|
|
562
|
+
*/
|
|
563
|
+
pageSize?: number;
|
|
541
564
|
/**
|
|
542
565
|
* Define derived properties (RDPs) to be computed server-side and attached to each object.
|
|
543
566
|
* These properties will be available on the returned objects alongside their regular properties.
|
|
544
567
|
*/
|
|
545
|
-
withProperties?:
|
|
568
|
+
withProperties?: {
|
|
569
|
+
[K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]>;
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* The number of milliseconds to wait after the last observed list change.
|
|
573
|
+
*
|
|
574
|
+
* Two uses of `useOsdkObjects` with the same parameters will only trigger one
|
|
575
|
+
* network request if the second is within `dedupeIntervalMs`.
|
|
576
|
+
*/
|
|
577
|
+
dedupeIntervalMs?: number;
|
|
578
|
+
/**
|
|
579
|
+
* Enable or disable the query.
|
|
580
|
+
*
|
|
581
|
+
* When `false`, the query will not automatically execute. It will still
|
|
582
|
+
* return any cached data, but will not fetch from the server.
|
|
583
|
+
*
|
|
584
|
+
* @default true
|
|
585
|
+
*/
|
|
586
|
+
enabled?: boolean;
|
|
546
587
|
/**
|
|
547
588
|
* Intersect the results with additional object sets.
|
|
548
589
|
* Each element defines a where clause for an object set to intersect with.
|
|
549
590
|
* The final result will only include objects that match ALL conditions.
|
|
550
591
|
*/
|
|
551
592
|
intersectWith?: Array<{
|
|
552
|
-
where: WhereClause$1<T,
|
|
593
|
+
where: WhereClause$1<T, RDPs>;
|
|
553
594
|
}>;
|
|
554
595
|
/**
|
|
555
596
|
* Pivot to related objects through a link.
|
|
@@ -564,76 +605,26 @@ interface UseOsdkObjectsOptions<T extends ObjectOrInterfaceDefinition, WithProps
|
|
|
564
605
|
* - `true`: Fetch all available pages automatically
|
|
565
606
|
* - `number`: Fetch pages until at least this many items are loaded
|
|
566
607
|
* - `undefined` (default): Only fetch the first page, user must call fetchMore()
|
|
567
|
-
*
|
|
568
|
-
* Note: When using `autoFetchMore: true` with large datasets, the initial
|
|
569
|
-
* load may take significant time. Consider using a specific number instead
|
|
570
|
-
* or implementing virtual scrolling.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* // Fetch all todos at once
|
|
574
|
-
* const { data } = useOsdkObjects(Todo, { autoFetchMore: true })
|
|
575
|
-
*
|
|
576
|
-
* @example
|
|
577
|
-
* // Fetch at least 100 todos (with 25 per page, fetches 4 pages)
|
|
578
|
-
* const { data } = useOsdkObjects(Todo, {
|
|
579
|
-
* autoFetchMore: 100,
|
|
580
|
-
* pageSize: 25
|
|
581
|
-
* })
|
|
582
608
|
*/
|
|
583
609
|
autoFetchMore?: boolean | number;
|
|
610
|
+
streamUpdates?: boolean;
|
|
611
|
+
}
|
|
612
|
+
interface UseOsdkListResult<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
584
613
|
/**
|
|
585
|
-
*
|
|
586
|
-
* will be re-rendered with the data.
|
|
587
|
-
*
|
|
588
|
-
* An example to help understand the options:
|
|
589
|
-
*
|
|
590
|
-
* Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is
|
|
591
|
-
* now 30 items long.
|
|
592
|
-
*
|
|
593
|
-
* Upon revalidation, we get the first 10 items of the list. The options behave
|
|
594
|
-
* as follows:
|
|
595
|
-
*
|
|
596
|
-
* - `"in-place"`: The first 10 items of the list are replaced with the new 10
|
|
597
|
-
* items. The list is now 30 items long, but only the first 10 items are valid.
|
|
598
|
-
* - `"wait"`: The old list is returned until after the next 20 items are loaded
|
|
599
|
-
* (which will happen automatically). The list is now 30 items long.
|
|
600
|
-
* - `"reset"`: The entire list is replaced with the new 10 items. The list is
|
|
601
|
-
* now 10 items long.
|
|
614
|
+
* Function to fetch more pages (undefined if no more pages)
|
|
602
615
|
*/
|
|
616
|
+
fetchMore: (() => Promise<void>) | undefined;
|
|
603
617
|
/**
|
|
604
|
-
* The
|
|
605
|
-
*
|
|
606
|
-
* Two uses of `useOsdkObjects` with the where clause will only trigger one
|
|
607
|
-
* network request if the second is within `dedupeIntervalMs`.
|
|
618
|
+
* The fetched data with derived properties
|
|
608
619
|
*/
|
|
609
|
-
|
|
610
|
-
streamUpdates?: boolean;
|
|
620
|
+
data: Osdk$1.Instance<T, "$allBaseProperties", PropertyKeys$1<T>, RDPs>[] | undefined;
|
|
611
621
|
/**
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
* When `false`, the query will not automatically execute. It will still
|
|
615
|
-
* return any cached data, but will not fetch from the server.
|
|
616
|
-
*
|
|
617
|
-
* This is useful for:
|
|
618
|
-
* - Lazy/on-demand queries that should wait for user interaction
|
|
619
|
-
* - Dependent queries that need data from another query first
|
|
620
|
-
* - Conditional queries based on component state
|
|
621
|
-
*
|
|
622
|
-
* @default true
|
|
623
|
-
* @example
|
|
624
|
-
* // Dependent query - wait for parent data
|
|
625
|
-
* const { data: employee } = useOsdkObject(Employee, employeeId);
|
|
626
|
-
* const { data: reports } = useOsdkObjects(Employee, {
|
|
627
|
-
* where: { managerId: employee?.id },
|
|
628
|
-
* enabled: !!employee
|
|
629
|
-
* });
|
|
622
|
+
* Whether data is currently being loaded
|
|
630
623
|
*/
|
|
631
|
-
enabled?: boolean;
|
|
632
|
-
}
|
|
633
|
-
interface UseOsdkListResult<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
634
|
-
fetchMore: (() => Promise<void>) | undefined;
|
|
635
|
-
data: Osdk$1.Instance<T, "$allBaseProperties", PropertyKeys$1<T>, RDPs>[] | undefined;
|
|
636
624
|
isLoading: boolean;
|
|
625
|
+
/**
|
|
626
|
+
* Any error that occurred during fetching
|
|
627
|
+
*/
|
|
637
628
|
error: Error | undefined;
|
|
638
629
|
/**
|
|
639
630
|
* Refers to whether the ordered list of objects (only considering the $primaryKey)
|
|
@@ -643,11 +634,15 @@ interface UseOsdkListResult<T extends ObjectOrInterfaceDefinition, RDPs extends
|
|
|
643
634
|
* do that on a per object basis with useOsdkObject
|
|
644
635
|
*/
|
|
645
636
|
isOptimistic: boolean;
|
|
637
|
+
/**
|
|
638
|
+
* The total count of objects matching the query (if available from the API)
|
|
639
|
+
*/
|
|
640
|
+
totalCount?: string;
|
|
646
641
|
}
|
|
647
642
|
declare function useOsdkObjects<Q extends ObjectOrInterfaceDefinition, L extends LinkNames<Q>>(type: Q, options: UseOsdkObjectsOptions<Q> & {
|
|
648
643
|
pivotTo: L;
|
|
649
644
|
}): UseOsdkListResult<LinkedType<Q, L>>;
|
|
650
|
-
declare function useOsdkObjects<Q extends ObjectOrInterfaceDefinition,
|
|
645
|
+
declare function useOsdkObjects<Q extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}>(type: Q, options?: UseOsdkObjectsOptions<Q, RDPs>): UseOsdkListResult<Q, RDPs>;
|
|
651
646
|
|
|
652
647
|
interface DebouncedCallback<TArgs extends readonly unknown[]> {
|
|
653
648
|
(...args: TArgs): void;
|
|
@@ -684,4 +679,4 @@ interface DebouncedCallback<TArgs extends readonly unknown[]> {
|
|
|
684
679
|
*/
|
|
685
680
|
declare function useDebouncedCallback<TArgs extends readonly unknown[]>(callback: (...args: TArgs) => void | Promise<void>, delay: number): DebouncedCallback<TArgs>;
|
|
686
681
|
|
|
687
|
-
export { OsdkProvider2, type UseOsdkAggregationResult, type UseOsdkFunctionOptions, type UseOsdkFunctionResult, type UseOsdkListResult, useCurrentFoundryUser, useDebouncedCallback, useFoundryUser, useFoundryUsersList, useLinks, useObjectSet, useOsdkAction, useOsdkAggregation, useOsdkFunction, useOsdkObject, useOsdkObjects };
|
|
682
|
+
export { OsdkProvider2, type UseOsdkAggregationResult, type UseOsdkFunctionOptions, type UseOsdkFunctionResult, type UseOsdkListResult, type UseOsdkObjectsOptions, 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","selectProperty"],"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.selectProperty(\"class\"),\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,cAAc,CAAC,OAAO;IAC9D;EAIA,CAAC,CAAC;EAEF,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -35,11 +35,18 @@ export function useLinks(objects, linkName, options = {}) {
|
|
|
35
35
|
enabled = true,
|
|
36
36
|
...otherOptions
|
|
37
37
|
} = options;
|
|
38
|
+
const stableWhere = React.useMemo(() => otherOptions.where, [JSON.stringify(otherOptions.where)]);
|
|
39
|
+
const stableOrderBy = React.useMemo(() => otherOptions.orderBy, [JSON.stringify(otherOptions.orderBy)]);
|
|
40
|
+
const objectsKey = React.useMemo(() => {
|
|
41
|
+
if (objects === undefined) return "";
|
|
42
|
+
const arr = Array.isArray(objects) ? objects : [objects];
|
|
43
|
+
return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(",");
|
|
44
|
+
}, [objects]);
|
|
38
45
|
|
|
39
46
|
// Convert single object to array for consistent handling
|
|
40
47
|
const objectsArray = React.useMemo(() => {
|
|
41
48
|
return objects === undefined ? emptyArray : Array.isArray(objects) ? objects : [objects];
|
|
42
|
-
}, [objects]);
|
|
49
|
+
}, [objectsKey, objects]);
|
|
43
50
|
const {
|
|
44
51
|
subscribe,
|
|
45
52
|
getSnapShot
|
|
@@ -47,23 +54,23 @@ export function useLinks(objects, linkName, options = {}) {
|
|
|
47
54
|
if (!enabled) {
|
|
48
55
|
return makeExternalStore(() => ({
|
|
49
56
|
unsubscribe: () => {}
|
|
50
|
-
}), `links ${linkName} for ${
|
|
57
|
+
}), `links ${linkName} for ${objectsKey} [DISABLED]`);
|
|
51
58
|
}
|
|
52
59
|
return makeExternalStore(observer => observableClient.observeLinks(objectsArray, linkName, {
|
|
53
60
|
linkName,
|
|
54
|
-
where:
|
|
61
|
+
where: stableWhere,
|
|
55
62
|
pageSize: otherOptions.pageSize,
|
|
56
|
-
orderBy:
|
|
63
|
+
orderBy: stableOrderBy,
|
|
57
64
|
mode: otherOptions.mode
|
|
58
|
-
}, observer), `links ${linkName} for ${
|
|
59
|
-
}, [enabled, observableClient, objectsArray, linkName,
|
|
65
|
+
}, observer), `links ${linkName} for ${objectsKey}`);
|
|
66
|
+
}, [enabled, observableClient, objectsArray, objectsKey, linkName, stableWhere, otherOptions.pageSize, stableOrderBy, otherOptions.mode]);
|
|
60
67
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
61
68
|
return {
|
|
62
69
|
links: payload?.resolvedList,
|
|
63
70
|
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
64
71
|
isOptimistic: payload?.isOptimistic ?? false,
|
|
65
72
|
error: payload?.error,
|
|
66
|
-
fetchMore: payload?.fetchMore,
|
|
73
|
+
fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,
|
|
67
74
|
hasMore: payload?.hasMore ?? false
|
|
68
75
|
};
|
|
69
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","
|
|
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","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 * 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 },\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 ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\n return {\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 };\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;AAyEhD,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,UAAU,GAAGrB,KAAK,CAACe,OAAO,CAAC,MAAM;IACrC,IAAIR,OAAO,KAAKe,SAAS,EAAE,OAAO,EAAE;IACpC,MAAMC,GAAG,GAAGC,KAAK,CAACC,OAAO,CAAClB,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AAC;EAED,MAAMC,OAAO,GAAGvC,KAAK,CAACwC,oBAAoB,CACxCR,SAAS,EACTC,WACF,CAAC;EAED,OAAO;IACLQ,KAAK,EAAEF,OAAO,EAAEG,YAAY;IAC5BC,SAAS,EAAE/B,OAAO,GACb2B,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,GAAGzB,SAAS;IAC5D0B,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC;AACH","ignoreList":[]}
|
|
@@ -97,8 +97,9 @@ export function useObjectSet(baseObjectSet, options = {}) {
|
|
|
97
97
|
data: payload?.resolvedList,
|
|
98
98
|
isLoading: payload?.status === "loading" || !payload && true || false,
|
|
99
99
|
error: payload && "error" in payload ? payload.error : undefined,
|
|
100
|
-
fetchMore: payload?.fetchMore,
|
|
101
|
-
objectSet: payload?.objectSet || baseObjectSet
|
|
100
|
+
fetchMore: payload?.hasMore ? payload.fetchMore : undefined,
|
|
101
|
+
objectSet: payload?.objectSet || baseObjectSet,
|
|
102
|
+
totalCount: payload?.totalCount
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
105
|
//# sourceMappingURL=useObjectSet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousPayloadRef","objectTypeChanged","current","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","initialValue","undefined","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","useEffect","data","resolvedList","isLoading","status","error","fetchMore","objectSet"],"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 ObjectSet,\n ObjectTypeDefinition,\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 ObjectTypeDefinition,\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 ObjectTypeDefinition,\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\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\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 ObjectTypeDefinition,\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 = baseObjectSet.$objectSetInternals.def.apiName;\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\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 : previousPayloadRef.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 React.useEffect(() => {\n if (payload) {\n previousPayloadRef.current = payload;\n }\n }, [payload]);\n\n return {\n data: payload?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: payload?.status === \"loading\" || (!payload && true) || false,\n error: payload && \"error\" in payload\n ? payload.error\n : undefined,\n fetchMore: payload?.fetchMore,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\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;AAmIhD;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,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAE3D,MAAM;IAAEM,OAAO,GAAG,IAAI;IAAEC,aAAa;IAAE,GAAGC;EAAa,CAAC,GAAGL,OAAO;;EAElE;EACA,MAAMM,aAAa,GAAGP,aAAa,CAACQ,mB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EACzD,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousPayloadRef","objectTypeChanged","current","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","initialValue","undefined","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","useEffect","data","resolvedList","isLoading","status","error","fetchMore","hasMore","objectSet","totalCount"],"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 ObjectSet,\n ObjectTypeDefinition,\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 ObjectTypeDefinition,\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 ObjectTypeDefinition,\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\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 ObjectTypeDefinition,\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 = baseObjectSet.$objectSetInternals.def.apiName;\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\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 : previousPayloadRef.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 React.useEffect(() => {\n if (payload) {\n previousPayloadRef.current = payload;\n }\n }, [payload]);\n\n return {\n data: payload?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: payload?.status === \"loading\" || (!payload && true) || false,\n error: payload && \"error\" in payload\n ? payload.error\n : undefined,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\n totalCount: payload?.totalCount,\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,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AkB,CAACE,OAAO,GAAGyB,OAAO;IACtC;EACF,CAAC,EAAE,CAACA,OAAO,CAAC,CAAC;EAEb,OAAO;IACLG,IAAI,EAAEH,OAAO,EAAEI,YAKZ;IACHC,SAAS,EAAEL,OAAO,EAAEM,MAAM,KAAK,SAAS,IAAK,CAACN,OAAO,IAAI,IAAK,IAAI,KAAK;IACvEO,KAAK,EAAEP,OAAO,IAAI,OAAO,IAAIA,OAAO,GAChCA,OAAO,CAACO,KAAK,GACbd,SAAS;IACbe,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,CAACQ,SAAS,GAAGf,SAAS;IAC3DiB,SAAS,EAAEV,OAAO,EAAEU,SAAS,IAA0BlD,aAAa;IACpEmD,UAAU,EAAEX,OAAO,EAAEW;EACvB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAggregation.js","names":["React","makeExternalStore","OsdkContext2","useOsdkAggregation","type","where","withProperties","aggregate","dedupeIntervalMs","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableWithProperties","useMemo","JSON","stringify","stableAggregate","subscribe","getSnapShot","observer","observeAggregation","dedupeInterval","process","env","NODE_ENV","apiName","payload","useSyncExternalStore","error","status","Error","refetch","useCallback","invalidateObjectType","data","result","isLoading"],"sources":["useOsdkAggregation.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 AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\
|
|
1
|
+
{"version":3,"file":"useOsdkAggregation.js","names":["React","makeExternalStore","OsdkContext2","useOsdkAggregation","type","where","withProperties","aggregate","dedupeIntervalMs","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableWithProperties","useMemo","JSON","stringify","stableAggregate","subscribe","getSnapShot","observer","observeAggregation","dedupeInterval","process","env","NODE_ENV","apiName","payload","useSyncExternalStore","error","status","Error","refetch","useCallback","invalidateObjectType","data","result","isLoading"],"sources":["useOsdkAggregation.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 AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkAggregationOptions<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Standard OSDK Where clause to filter objects before aggregation\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Define derived properties (RDPs) to be computed server-side.\n * The derived properties can be used in the where clause and aggregation groupBy/select.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * Aggregation options including groupBy and select\n */\n aggregate: A;\n\n /**\n * The number of milliseconds to wait after the last observed aggregation change.\n *\n * Two uses of `useOsdkAggregation` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n}\n\nexport interface UseOsdkAggregationResult<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n> {\n data: AggregationsResults<T, A> | undefined;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => void;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for performing aggregations on OSDK object sets.\n *\n * Executes server-side aggregations with groupBy and metric calculations on filtered object sets.\n * Supports runtime derived properties and where clauses.\n *\n * @param type - The object or interface type to aggregate\n * @param options - Aggregation configuration including where clause, aggregation spec, and optional derived properties\n * @returns Object containing aggregation results, loading state, error state, and refetch function\n *\n * @example\n * ```tsx\n * const { data, isLoading, error } = useOsdkAggregation(Employee, {\n * where: { department: \"Engineering\" },\n * aggregate: {\n * groupBy: { department: \"exact\" },\n * select: {\n * avgSalary: { $avg: \"salary\" },\n * count: { $count: {} }\n * }\n * }\n * });\n * ```\n */\nexport function useOsdkAggregation<\n Q extends ObjectOrInterfaceDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n {\n where = {},\n withProperties,\n aggregate,\n dedupeIntervalMs,\n }: UseOsdkAggregationOptions<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const canonWhere = observableClient.canonicalizeWhereClause<Q>(where ?? {});\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableAggregate = React.useMemo(\n () => aggregate,\n [JSON.stringify(aggregate)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n observableClient.observeAggregation(\n {\n type: type,\n where: canonWhere,\n withProperties: stableWithProperties,\n aggregate: stableAggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [\n observableClient,\n type.apiName,\n type.type,\n canonWhere,\n stableWithProperties,\n stableAggregate,\n dedupeIntervalMs,\n ],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\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 execute aggregation\");\n }\n\n const refetch = React.useCallback(async () => {\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName]);\n\n return {\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload,\n error,\n refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAgDhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAKhCC,IAAO,EACP;EACEC,KAAK,GAAG,CAAC,CAAC;EACVC,cAAc;EACdC,SAAS;EACTC;AACqC,CAAC,EACR;EAChC,MAAM;IAAEC;EAAiB,CAAC,GAAGT,KAAK,CAACU,UAAU,CAACR,YAAY,CAAC;EAE3D,MAAMS,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAAIP,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EA,MAAMC,OAAO,GAAGhC,KAAK,CAACiC,WAAW,CAAC,YAAY;IAC5C,MAAMxB,gBAAgB,CAACyB,oBAAoB,CAAC9B,IAAI,CAACsB,OAAO,CAAC;EAC3D,CAAC,EAAE,CAACjB,gBAAgB,EAAEL,IAAI,CAACsB,OAAO,CAAC,CAAC;EAEpC,OAAO;IACLS,IAAI,EAAER,OAAO,EAAES,MAA+C;IAC9DC,SAAS,EAAEV,OAAO,EAAEG,MAAM,KAAK,SAAS,IAAIH,OAAO,EAAEG,MAAM,KAAK,MAAM,IACjE,CAACH,OAAO;IACbE,KAAK;IACLG;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -18,27 +18,24 @@ import React from "react";
|
|
|
18
18
|
import { makeExternalStore } from "./makeExternalStore.js";
|
|
19
19
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
20
|
export function useOsdkObjects(type, options) {
|
|
21
|
+
const {
|
|
22
|
+
observableClient
|
|
23
|
+
} = React.useContext(OsdkContext2);
|
|
21
24
|
const {
|
|
22
25
|
pageSize,
|
|
23
|
-
orderBy,
|
|
24
26
|
dedupeIntervalMs,
|
|
25
|
-
where = {},
|
|
26
|
-
streamUpdates,
|
|
27
27
|
withProperties,
|
|
28
|
+
enabled = true,
|
|
29
|
+
rids,
|
|
30
|
+
where,
|
|
31
|
+
orderBy,
|
|
32
|
+
streamUpdates,
|
|
28
33
|
autoFetchMore,
|
|
29
34
|
intersectWith,
|
|
30
|
-
pivotTo
|
|
31
|
-
enabled = true
|
|
35
|
+
pivotTo
|
|
32
36
|
} = options ?? {};
|
|
33
|
-
const {
|
|
34
|
-
observableClient
|
|
35
|
-
} = React.useContext(OsdkContext2);
|
|
36
|
-
|
|
37
|
-
/* We want the canonical where clause so that the use of `React.useMemo`
|
|
38
|
-
is stable. No real added cost as we canonicalize internal to
|
|
39
|
-
the ObservableClient anyway.
|
|
40
|
-
*/
|
|
41
37
|
const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
|
|
38
|
+
const stableRids = React.useMemo(() => rids, [JSON.stringify(rids)]);
|
|
42
39
|
const stableWithProperties = React.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
43
40
|
const stableIntersectWith = React.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
44
41
|
const stableOrderBy = React.useMemo(() => orderBy, [JSON.stringify(orderBy)]);
|
|
@@ -49,10 +46,11 @@ export function useOsdkObjects(type, options) {
|
|
|
49
46
|
if (!enabled) {
|
|
50
47
|
return makeExternalStore(() => ({
|
|
51
48
|
unsubscribe: () => {}
|
|
52
|
-
}), process.env.NODE_ENV !== "production" ? `list ${type.apiName}
|
|
49
|
+
}), process.env.NODE_ENV !== "production" ? `list ${type.apiName} [DISABLED]` : void 0);
|
|
53
50
|
}
|
|
54
51
|
return makeExternalStore(observer => observableClient.observeList({
|
|
55
52
|
type,
|
|
53
|
+
rids: stableRids,
|
|
56
54
|
where: canonWhere,
|
|
57
55
|
dedupeInterval: dedupeIntervalMs ?? 2_000,
|
|
58
56
|
pageSize,
|
|
@@ -66,8 +64,8 @@ export function useOsdkObjects(type, options) {
|
|
|
66
64
|
...(pivotTo ? {
|
|
67
65
|
pivotTo
|
|
68
66
|
} : {})
|
|
69
|
-
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0);
|
|
70
|
-
}, [enabled, observableClient, type, canonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
|
|
67
|
+
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(canonWhere)}` : void 0);
|
|
68
|
+
}, [enabled, observableClient, type, stableRids, canonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
|
|
71
69
|
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
72
70
|
let error;
|
|
73
71
|
if (listPayload && "error" in listPayload && listPayload.error) {
|
|
@@ -80,7 +78,8 @@ export function useOsdkObjects(type, options) {
|
|
|
80
78
|
error,
|
|
81
79
|
data: listPayload?.resolvedList,
|
|
82
80
|
isLoading: enabled ? listPayload?.status === "loading" || listPayload?.status === "init" || !listPayload : false,
|
|
83
|
-
isOptimistic: listPayload?.isOptimistic ?? false
|
|
81
|
+
isOptimistic: listPayload?.isOptimistic ?? false,
|
|
82
|
+
totalCount: listPayload?.totalCount
|
|
84
83
|
};
|
|
85
84
|
}
|
|
86
85
|
//# sourceMappingURL=useOsdkObjects.js.map
|