@osdk/react 0.10.0-beta.8 → 0.10.0
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 +112 -0
- package/build/browser/new/OsdkContext2.js +22 -2
- package/build/browser/new/OsdkContext2.js.map +1 -1
- package/build/browser/new/platform-apis/admin/useCbacBanner.js +63 -0
- package/build/browser/new/platform-apis/admin/useCbacBanner.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useCbacMarkingRestrictions.js +64 -0
- package/build/browser/new/platform-apis/admin/useCbacMarkingRestrictions.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useMarkingCategories.js +46 -0
- package/build/browser/new/platform-apis/admin/useMarkingCategories.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useMarkings.js +46 -0
- package/build/browser/new/platform-apis/admin/useMarkings.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useUserMarkings.js +50 -0
- package/build/browser/new/platform-apis/admin/useUserMarkings.js.map +1 -0
- package/build/browser/new/useLinks.js +2 -0
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +3 -6
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkFunctions.js +137 -0
- package/build/browser/new/useOsdkFunctions.js.map +1 -0
- package/build/browser/new/useOsdkObject.js +6 -2
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +6 -2
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/browser/public/experimental/admin.js +5 -0
- package/build/browser/public/experimental/admin.js.map +1 -1
- package/build/browser/public/unstable-do-not-use.js +18 -0
- package/build/browser/public/unstable-do-not-use.js.map +1 -0
- package/build/browser/useOsdkMetadata.js.map +1 -1
- package/build/cjs/chunk-2N32USW5.cjs +28 -0
- package/build/cjs/chunk-2N32USW5.cjs.map +1 -0
- package/build/cjs/chunk-R4FZ5MUH.cjs +34 -0
- package/build/cjs/chunk-R4FZ5MUH.cjs.map +1 -0
- package/build/cjs/{chunk-SVVMLSKN.cjs → chunk-ZUNR45SJ.cjs} +15 -4
- package/build/cjs/chunk-ZUNR45SJ.cjs.map +1 -0
- package/build/cjs/index.cjs +7 -6
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +1 -1
- package/build/cjs/public/experimental/admin.cjs +154 -7
- package/build/cjs/public/experimental/admin.cjs.map +1 -1
- package/build/cjs/public/experimental/admin.d.cts +159 -2
- package/build/cjs/public/experimental.cjs +44 -36
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +19 -122
- package/build/cjs/public/unstable-do-not-use.cjs +114 -0
- package/build/cjs/public/unstable-do-not-use.cjs.map +1 -0
- package/build/cjs/public/unstable-do-not-use.d.cts +35 -0
- package/build/cjs/useOsdkFunction-B0s7lqgN.d.cts +121 -0
- package/build/cjs/useOsdkMetadata-BElt3F5s.d.cts +15 -0
- package/build/esm/new/OsdkContext2.js +22 -2
- package/build/esm/new/OsdkContext2.js.map +1 -1
- package/build/esm/new/platform-apis/admin/useCbacBanner.js +63 -0
- package/build/esm/new/platform-apis/admin/useCbacBanner.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useCbacMarkingRestrictions.js +64 -0
- package/build/esm/new/platform-apis/admin/useCbacMarkingRestrictions.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useMarkingCategories.js +46 -0
- package/build/esm/new/platform-apis/admin/useMarkingCategories.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useMarkings.js +46 -0
- package/build/esm/new/platform-apis/admin/useMarkings.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useUserMarkings.js +50 -0
- package/build/esm/new/platform-apis/admin/useUserMarkings.js.map +1 -0
- package/build/esm/new/useLinks.js +2 -0
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +3 -6
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkFunctions.js +137 -0
- package/build/esm/new/useOsdkFunctions.js.map +1 -0
- package/build/esm/new/useOsdkObject.js +6 -2
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +6 -2
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/esm/public/experimental/admin.js +5 -0
- package/build/esm/public/experimental/admin.js.map +1 -1
- package/build/esm/public/unstable-do-not-use.js +18 -0
- package/build/esm/public/unstable-do-not-use.js.map +1 -0
- package/build/esm/useOsdkMetadata.js.map +1 -1
- package/build/types/new/OsdkContext2.d.ts +1 -0
- package/build/types/new/OsdkContext2.d.ts.map +1 -1
- package/build/types/new/platform-apis/admin/useCbacBanner.d.ts +33 -0
- package/build/types/new/platform-apis/admin/useCbacBanner.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useCbacMarkingRestrictions.d.ts +34 -0
- package/build/types/new/platform-apis/admin/useCbacMarkingRestrictions.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useMarkingCategories.d.ts +27 -0
- package/build/types/new/platform-apis/admin/useMarkingCategories.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useMarkings.d.ts +27 -0
- package/build/types/new/platform-apis/admin/useMarkings.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useUserMarkings.d.ts +33 -0
- package/build/types/new/platform-apis/admin/useUserMarkings.d.ts.map +1 -0
- package/build/types/new/useLinks.d.ts +6 -0
- package/build/types/new/useLinks.d.ts.map +1 -1
- package/build/types/new/useOsdkFunctions.d.ts +31 -0
- package/build/types/new/useOsdkFunctions.d.ts.map +1 -0
- package/build/types/new/useOsdkObject.d.ts +2 -1
- package/build/types/new/useOsdkObject.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +6 -0
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/build/types/public/experimental/admin.d.ts +8 -0
- package/build/types/public/experimental/admin.d.ts.map +1 -1
- package/build/types/public/unstable-do-not-use.d.ts +2 -0
- package/build/types/public/unstable-do-not-use.d.ts.map +1 -0
- package/build/types/useOsdkMetadata.d.ts +5 -4
- package/build/types/useOsdkMetadata.d.ts.map +1 -1
- package/package.json +19 -10
- package/unstable-do-not-use.d.ts +17 -0
- package/build/cjs/chunk-OVBG5VXE.cjs +0 -50
- package/build/cjs/chunk-OVBG5VXE.cjs.map +0 -1
- package/build/cjs/chunk-SVVMLSKN.cjs.map +0 -1
- package/build/cjs/useOsdkMetadata-DFZhnhGZ.d.cts +0 -14
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 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 { CbacMarkingRestrictionsObjects } 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 CBAC marking restrictions (implied, disallowed, required) for the given marking IDs.
|
|
23
|
+
* @param options Options to control the query.
|
|
24
|
+
*/
|
|
25
|
+
export function useCbacMarkingRestrictions({
|
|
26
|
+
markingIds,
|
|
27
|
+
enabled: externalEnabled = true
|
|
28
|
+
}) {
|
|
29
|
+
const {
|
|
30
|
+
client
|
|
31
|
+
} = React.useContext(OsdkContext2);
|
|
32
|
+
const stableMarkingIds = React.useMemo(() => markingIds, [JSON.stringify(markingIds)]);
|
|
33
|
+
const enabled = stableMarkingIds.length > 0 && externalEnabled;
|
|
34
|
+
const handleQuery = React.useCallback(() => {
|
|
35
|
+
return CbacMarkingRestrictionsObjects.get(client, {
|
|
36
|
+
markingIds: stableMarkingIds,
|
|
37
|
+
preview: true
|
|
38
|
+
});
|
|
39
|
+
}, [client, stableMarkingIds]);
|
|
40
|
+
const query = usePlatformQuery({
|
|
41
|
+
query: handleQuery,
|
|
42
|
+
enabled,
|
|
43
|
+
queryName: "cbac-marking-restrictions"
|
|
44
|
+
});
|
|
45
|
+
const restrictions = React.useMemo(() => {
|
|
46
|
+
if (query.data == null) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
disallowedMarkings: query.data.disallowedMarkings.map(String),
|
|
51
|
+
impliedMarkings: query.data.impliedMarkings.map(String),
|
|
52
|
+
requiredMarkings: query.data.requiredMarkings.map(group => group.map(String)),
|
|
53
|
+
userSatisfiesMarkings: query.data.userSatisfiesMarkings,
|
|
54
|
+
isValid: query.data.isValid
|
|
55
|
+
};
|
|
56
|
+
}, [query.data]);
|
|
57
|
+
return {
|
|
58
|
+
restrictions,
|
|
59
|
+
isLoading: query.isLoading,
|
|
60
|
+
error: query.error,
|
|
61
|
+
refetch: query.refetch
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=useCbacMarkingRestrictions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCbacMarkingRestrictions.js","names":["CbacMarkingRestrictionsObjects","React","usePlatformQuery","OsdkContext2","useCbacMarkingRestrictions","markingIds","enabled","externalEnabled","client","useContext","stableMarkingIds","useMemo","JSON","stringify","length","handleQuery","useCallback","get","preview","query","queryName","restrictions","data","undefined","disallowedMarkings","map","String","impliedMarkings","requiredMarkings","group","userSatisfiesMarkings","isValid","isLoading","error","refetch"],"sources":["useCbacMarkingRestrictions.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { CbacMarkingRestrictionsObjects } from \"@osdk/foundry.admin\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface CbacMarkingRestrictionsData {\n disallowedMarkings: string[];\n impliedMarkings: string[];\n requiredMarkings: string[][];\n userSatisfiesMarkings: boolean;\n isValid: boolean;\n}\n\nexport interface UseCbacMarkingRestrictionsOptions {\n markingIds: string[];\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 enabled?: boolean;\n}\n\nexport interface UseCbacMarkingRestrictionsResult {\n restrictions: CbacMarkingRestrictionsData | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get CBAC marking restrictions (implied, disallowed, required) for the given marking IDs.\n * @param options Options to control the query.\n */\nexport function useCbacMarkingRestrictions(\n { markingIds, enabled: externalEnabled = true }:\n UseCbacMarkingRestrictionsOptions,\n): UseCbacMarkingRestrictionsResult {\n const { client } = React.useContext(OsdkContext2);\n\n const stableMarkingIds = React.useMemo(\n () => markingIds,\n [JSON.stringify(markingIds)],\n );\n\n const enabled = stableMarkingIds.length > 0 && externalEnabled;\n\n const handleQuery = React.useCallback(() => {\n return CbacMarkingRestrictionsObjects.get(client, {\n markingIds: stableMarkingIds,\n preview: true,\n });\n }, [client, stableMarkingIds]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"cbac-marking-restrictions\",\n });\n\n const restrictions = React.useMemo(\n (): CbacMarkingRestrictionsData | undefined => {\n if (query.data == null) {\n return undefined;\n }\n return {\n disallowedMarkings: query.data.disallowedMarkings.map(String),\n impliedMarkings: query.data.impliedMarkings.map(String),\n requiredMarkings: query.data.requiredMarkings.map(group =>\n group.map(String)\n ),\n userSatisfiesMarkings: query.data.userSatisfiesMarkings,\n isValid: query.data.isValid,\n };\n },\n [query.data],\n );\n\n return {\n restrictions,\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,SAASA,8BAA8B,QAAQ,qBAAqB;AACpE,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,YAAY,QAAQ,uBAAuB;AAoCpD;AACA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CACxC;EAAEC,UAAU;EAAEC,OAAO,EAAEC,eAAe,GAAG;AACP,CAAC,EACD;EAClC,MAAM;IAAEC;EAAO,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACN,YAAY,CAAC;EAEjD,MAAMO,gBAAgB,GAAGT,KAAK,CAACU,OAAO,CACpC,MAAMN,UAAU,EAChB,CAACO,IAAI,CAACC,SAAS,CAACR,UAAU,CAAC,CAC7B,CAAC;EAED,MAAMC,OAAO,GAAGI,gBAAgB,CAACI,MAAM,GAAG,CAAC,IAAIP,eAAe;EAE9D,MAAMQ,WAAW,GAAGd,KAAK,CAACe,WAAW,CAAC,MAAM;IAC1C,OAAOhB,8BAA8B,CAACiB,GAAG,CAACT,MAAM,EAAE;MAChDH,UAAU,EAAEK,gBAAgB;MAC5BQ,OAAO,EAAE;IACX,CAAC,CAAC;EACJ,CAAC,EAAE,CAACV,MAAM,EAAEE,gBAAgB,CAAC,CAAC;EAE9B,MAAMS,KAAK,GAAGjB,gBAAgB,CAAC;IAC7BiB,KAAK,EAAEJ,WAAW;IAClBT,OAAO;IACPc,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,MAAMC,YAAY,GAAGpB,KAAK,CAACU,OAAO,CAChC,MAA+C;IAC7C,IAAIQ,KAAK,CAACG,IAAI,IAAI,IAAI,EAAE;MACtB,OAAOC,SAAS;IAClB;IACA,OAAO;MACLC,kBAAkB,EAAEL,KAAK,CAACG,IAAI,CAACE,kBAAkB,CAACC,GAAG,CAACC,MAAM,CAAC;MAC7DC,eAAe,EAAER,KAAK,CAACG,IAAI,CAACK,eAAe,CAACF,GAAG,CAACC,MAAM,CAAC;MACvDE,gBAAgB,EAAET,KAAK,CAACG,IAAI,CAACM,gBAAgB,CAACH,GAAG,CAACI,KAAK,IACrDA,KAAK,CAACJ,GAAG,CAACC,MAAM,CAClB,CAAC;MACDI,qBAAqB,EAAEX,KAAK,CAACG,IAAI,CAACQ,qBAAqB;MACvDC,OAAO,EAAEZ,KAAK,CAACG,IAAI,CAACS;IACtB,CAAC;EACH,CAAC,EACD,CAACZ,KAAK,CAACG,IAAI,CACb,CAAC;EAED,OAAO;IACLD,YAAY;IACZW,SAAS,EAAEb,KAAK,CAACa,SAAS;IAC1BC,KAAK,EAAEd,KAAK,CAACc,KAAK;IAClBC,OAAO,EAAEf,KAAK,CAACe;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 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 { MarkingCategories } from "@osdk/foundry.admin";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { usePlatformQuery } from "../../../utils/usePlatformQuery.js";
|
|
20
|
+
import { OsdkContext2 } from "../../OsdkContext2.js";
|
|
21
|
+
/**
|
|
22
|
+
* List all marking categories.
|
|
23
|
+
* @param options Options to control the query.
|
|
24
|
+
*/
|
|
25
|
+
export function useMarkingCategories({
|
|
26
|
+
enabled = true
|
|
27
|
+
} = {}) {
|
|
28
|
+
const {
|
|
29
|
+
client
|
|
30
|
+
} = React.useContext(OsdkContext2);
|
|
31
|
+
const handleQuery = React.useCallback(() => {
|
|
32
|
+
return MarkingCategories.list(client);
|
|
33
|
+
}, [client]);
|
|
34
|
+
const query = usePlatformQuery({
|
|
35
|
+
query: handleQuery,
|
|
36
|
+
enabled,
|
|
37
|
+
queryName: "marking-categories"
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
categories: query.data?.data,
|
|
41
|
+
isLoading: query.isLoading,
|
|
42
|
+
error: query.error,
|
|
43
|
+
refetch: query.refetch
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=useMarkingCategories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMarkingCategories.js","names":["MarkingCategories","React","usePlatformQuery","OsdkContext2","useMarkingCategories","enabled","client","useContext","handleQuery","useCallback","list","query","queryName","categories","data","isLoading","error","refetch"],"sources":["useMarkingCategories.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { MarkingCategory } from \"@osdk/foundry.admin\";\nimport { MarkingCategories } from \"@osdk/foundry.admin\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface UseMarkingCategoriesOptions {\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 enabled?: boolean;\n}\n\nexport interface UseMarkingCategoriesResult {\n categories: MarkingCategory[] | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * List all marking categories.\n * @param options Options to control the query.\n */\nexport function useMarkingCategories(\n { enabled = true }: UseMarkingCategoriesOptions = {},\n): UseMarkingCategoriesResult {\n const { client } = React.useContext(OsdkContext2);\n\n const handleQuery = React.useCallback(() => {\n return MarkingCategories.list(client);\n }, [client]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"marking-categories\",\n });\n\n return {\n categories: query.data?.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;;AAGA,SAASA,iBAAiB,QAAQ,qBAAqB;AACvD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,YAAY,QAAQ,uBAAuB;AA2BpD;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClC;EAAEC,OAAO,GAAG;AAAkC,CAAC,GAAG,CAAC,CAAC,EACxB;EAC5B,MAAM;IAAEC;EAAO,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;EAEjD,MAAMK,WAAW,GAAGP,KAAK,CAACQ,WAAW,CAAC,MAAM;IAC1C,OAAOT,iBAAiB,CAACU,IAAI,CAACJ,MAAM,CAAC;EACvC,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEZ,MAAMK,KAAK,GAAGT,gBAAgB,CAAC;IAC7BS,KAAK,EAAEH,WAAW;IAClBH,OAAO;IACPO,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,UAAU,EAAEF,KAAK,CAACG,IAAI,EAAEA,IAAI;IAC5BC,SAAS,EAAEJ,KAAK,CAACI,SAAS;IAC1BC,KAAK,EAAEL,KAAK,CAACK,KAAK;IAClBC,OAAO,EAAEN,KAAK,CAACM;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 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 { Markings } from "@osdk/foundry.admin";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { usePlatformQuery } from "../../../utils/usePlatformQuery.js";
|
|
20
|
+
import { OsdkContext2 } from "../../OsdkContext2.js";
|
|
21
|
+
/**
|
|
22
|
+
* List all markings.
|
|
23
|
+
* @param options Options to control the query.
|
|
24
|
+
*/
|
|
25
|
+
export function useMarkings({
|
|
26
|
+
enabled = true
|
|
27
|
+
} = {}) {
|
|
28
|
+
const {
|
|
29
|
+
client
|
|
30
|
+
} = React.useContext(OsdkContext2);
|
|
31
|
+
const handleQuery = React.useCallback(() => {
|
|
32
|
+
return Markings.list(client);
|
|
33
|
+
}, [client]);
|
|
34
|
+
const query = usePlatformQuery({
|
|
35
|
+
query: handleQuery,
|
|
36
|
+
enabled,
|
|
37
|
+
queryName: "markings"
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
markings: query.data?.data,
|
|
41
|
+
isLoading: query.isLoading,
|
|
42
|
+
error: query.error,
|
|
43
|
+
refetch: query.refetch
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=useMarkings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMarkings.js","names":["Markings","React","usePlatformQuery","OsdkContext2","useMarkings","enabled","client","useContext","handleQuery","useCallback","list","query","queryName","markings","data","isLoading","error","refetch"],"sources":["useMarkings.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { Marking } from \"@osdk/foundry.admin\";\nimport { Markings } from \"@osdk/foundry.admin\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface UseMarkingsOptions {\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 enabled?: boolean;\n}\n\nexport interface UseMarkingsResult {\n markings: Marking[] | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * List all markings.\n * @param options Options to control the query.\n */\nexport function useMarkings(\n { enabled = true }: UseMarkingsOptions = {},\n): UseMarkingsResult {\n const { client } = React.useContext(OsdkContext2);\n\n const handleQuery = React.useCallback(() => {\n return Markings.list(client);\n }, [client]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"markings\",\n });\n\n return {\n markings: query.data?.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;;AAGA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,YAAY,QAAQ,uBAAuB;AA2BpD;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CACzB;EAAEC,OAAO,GAAG;AAAyB,CAAC,GAAG,CAAC,CAAC,EACxB;EACnB,MAAM;IAAEC;EAAO,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;EAEjD,MAAMK,WAAW,GAAGP,KAAK,CAACQ,WAAW,CAAC,MAAM;IAC1C,OAAOT,QAAQ,CAACU,IAAI,CAACJ,MAAM,CAAC;EAC9B,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEZ,MAAMK,KAAK,GAAGT,gBAAgB,CAAC;IAC7BS,KAAK,EAAEH,WAAW;IAClBH,OAAO;IACPO,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,QAAQ,EAAEF,KAAK,CAACG,IAAI,EAAEA,IAAI;IAC1BC,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 2026 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 view-accessible markings for a user.
|
|
23
|
+
* When `userId` is provided, fetches markings for that user.
|
|
24
|
+
* When omitted, fetches markings for the current user.
|
|
25
|
+
* @param options Options to control the query.
|
|
26
|
+
*/
|
|
27
|
+
export function useUserViewMarkings({
|
|
28
|
+
userId,
|
|
29
|
+
enabled = true
|
|
30
|
+
} = {}) {
|
|
31
|
+
const {
|
|
32
|
+
client
|
|
33
|
+
} = React.useContext(OsdkContext2);
|
|
34
|
+
const handleQuery = React.useCallback(async () => {
|
|
35
|
+
const resolvedUserId = userId ?? (await Users.getCurrent(client)).id;
|
|
36
|
+
return Users.getMarkings(client, resolvedUserId);
|
|
37
|
+
}, [client, userId]);
|
|
38
|
+
const query = usePlatformQuery({
|
|
39
|
+
query: handleQuery,
|
|
40
|
+
enabled,
|
|
41
|
+
queryName: "user-view-markings"
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
markingIds: query.data?.view,
|
|
45
|
+
isLoading: query.isLoading,
|
|
46
|
+
error: query.error,
|
|
47
|
+
refetch: query.refetch
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=useUserMarkings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUserMarkings.js","names":["Users","React","usePlatformQuery","OsdkContext2","useUserViewMarkings","userId","enabled","client","useContext","handleQuery","useCallback","resolvedUserId","getCurrent","id","getMarkings","query","queryName","markingIds","data","view","isLoading","error","refetch"],"sources":["useUserMarkings.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { Users } from \"@osdk/foundry.admin\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface UseUserViewMarkingsOptions {\n /**\n * The user ID to fetch view markings for.\n * When omitted, fetches markings for the current user.\n */\n userId?: string;\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 enabled?: boolean;\n}\n\nexport interface UseUserViewMarkingsResult {\n markingIds: string[] | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get view-accessible markings for a user.\n * When `userId` is provided, fetches markings for that user.\n * When omitted, fetches markings for the current user.\n * @param options Options to control the query.\n */\nexport function useUserViewMarkings(\n { userId, enabled = true }: UseUserViewMarkingsOptions = {},\n): UseUserViewMarkingsResult {\n const { client } = React.useContext(OsdkContext2);\n\n const handleQuery = React.useCallback(async () => {\n const resolvedUserId = userId\n ?? (await Users.getCurrent(client)).id;\n return Users.getMarkings(client, resolvedUserId);\n }, [client, userId]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"user-view-markings\",\n });\n\n return {\n markingIds: query.data?.view,\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,SAASA,KAAK,QAAQ,qBAAqB;AAC3C,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,YAAY,QAAQ,uBAAuB;AAgCpD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CACjC;EAAEC,MAAM;EAAEC,OAAO,GAAG;AAAiC,CAAC,GAAG,CAAC,CAAC,EAChC;EAC3B,MAAM;IAAEC;EAAO,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAEjD,MAAMM,WAAW,GAAGR,KAAK,CAACS,WAAW,CAAC,YAAY;IAChD,MAAMC,cAAc,GAAGN,MAAM,IACxB,CAAC,MAAML,KAAK,CAACY,UAAU,CAACL,MAAM,CAAC,EAAEM,EAAE;IACxC,OAAOb,KAAK,CAACc,WAAW,CAACP,MAAM,EAAEI,cAAc,CAAC;EAClD,CAAC,EAAE,CAACJ,MAAM,EAAEF,MAAM,CAAC,CAAC;EAEpB,MAAMU,KAAK,GAAGb,gBAAgB,CAAC;IAC7Ba,KAAK,EAAEN,WAAW;IAClBH,OAAO;IACPU,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,UAAU,EAAEF,KAAK,CAACG,IAAI,EAAEC,IAAI;IAC5BC,SAAS,EAAEL,KAAK,CAACK,SAAS;IAC1BC,KAAK,EAAEN,KAAK,CAACM,KAAK;IAClBC,OAAO,EAAEP,KAAK,CAACO;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -18,6 +18,7 @@ import React from "react";
|
|
|
18
18
|
import { makeExternalStore } from "./makeExternalStore.js";
|
|
19
19
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
20
|
const emptyArray = Object.freeze([]);
|
|
21
|
+
const emptyMap = new Map();
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Hook to observe links from an object or array of objects.
|
|
@@ -72,6 +73,7 @@ export function useLinks(objects, linkName, options = {}) {
|
|
|
72
73
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
73
74
|
return React.useMemo(() => ({
|
|
74
75
|
links: payload?.resolvedList,
|
|
76
|
+
linkedObjectsBySourcePrimaryKey: payload?.linkedObjectsBySourcePrimaryKey ?? emptyMap,
|
|
75
77
|
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
76
78
|
isOptimistic: payload?.isOptimistic ?? false,
|
|
77
79
|
error: payload?.error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","stableWhere","useMemo","where","JSON","stringify","stableOrderBy","orderBy","stableSelect","$select","objectsKey","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","observer","observeLinks","pageSize","mode","dedupeInterval","dedupeIntervalMs","select","payload","useSyncExternalStore","links","resolvedList","isLoading","status","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseLinksOptions<\n T extends ObjectOrInterfaceDefinition,\n> {\n /**\n * Standard OSDK Where clause for filtering linked objects\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the links list.\n */\n pageSize?: number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Restrict which properties are returned for each linked object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<T>[];\n\n /**\n * The mode to use for fetching data.\n * - undefined: Fetch data if not already in cache\n * - \"force\": Always fetch fresh data\n * - \"offline\": Only use cached data, don't make network requests\n */\n mode?: \"force\" | \"offline\";\n\n /**\n * The number of milliseconds to wait after the last observed link change.\n *\n * Two uses of `useLinks` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for employee data\n * const { object: employee } = useOsdkObject(Employee, employeeId);\n * const { links: reports } = useLinks(employee, \"reports\", {\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseLinksResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n links: Osdk.Instance<Q>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the links are optimistic or not.\n */\n isOptimistic: boolean;\n\n /**\n * Fetch more linked objects if pagination is supported\n */\n fetchMore: (() => Promise<unknown>) | undefined;\n\n /**\n * Indicates if there are more linked objects available to fetch\n */\n hasMore: boolean;\n}\n\nconst emptyArray = Object.freeze([]);\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, ...otherOptions } = options;\n\n const stableWhere = React.useMemo(\n () => otherOptions.where,\n [JSON.stringify(otherOptions.where)],\n );\n\n const stableOrderBy = React.useMemo(\n () => otherOptions.orderBy,\n [JSON.stringify(otherOptions.orderBy)],\n );\n\n const stableSelect = React.useMemo(\n () => otherOptions.$select,\n [JSON.stringify(otherOptions.$select)],\n );\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n () => ({ unsubscribe: () => {} }),\n `links ${linkName} for ${objectsKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: stableWhere,\n pageSize: otherOptions.pageSize,\n orderBy: stableOrderBy,\n mode: otherOptions.mode,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n ...(stableSelect ? { select: stableSelect } : {}),\n },\n observer,\n ),\n `links ${linkName} for ${objectsKey}`,\n );\n },\n [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n stableWhere,\n otherOptions.pageSize,\n stableOrderBy,\n otherOptions.mode,\n otherOptions.dedupeIntervalMs,\n stableSelect,\n ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\n return React.useMemo(() => ({\n links: payload?.resolvedList,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n }), [payload, enabled]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAwFhD,MAAMC,UAAU,G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nC,KAAK,CAACe,OAAO,CAAC,OAAO;IAC1B+B,KAAK,EAAEF,OAAO,EAAEG,YAAY;IAC5BC,SAAS,EAAEpC,OAAO,GACbgC,OAAO,EAAEK,MAAM,KAAK,SAAS,IAAIL,OAAO,EAAEK,MAAM,KAAK,MAAM,IACzD,CAACL,OAAO,GACX,KAAK;IACTM,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAEP,OAAO,EAAEO,KAAK;IACrBC,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,EAAEQ,SAAS,GAAG5B,SAAS;IAC5D6B,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC,CAAC,EAAE,CAACT,OAAO,EAAEhC,OAAO,CAAC,CAAC;AACzB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","emptyMap","Map","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","stableWhere","useMemo","where","JSON","stringify","stableOrderBy","orderBy","stableSelect","$select","objectsKey","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","observer","observeLinks","pageSize","mode","dedupeInterval","dedupeIntervalMs","select","payload","useSyncExternalStore","links","resolvedList","linkedObjectsBySourcePrimaryKey","isLoading","status","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseLinksOptions<\n T extends ObjectOrInterfaceDefinition,\n> {\n /**\n * Standard OSDK Where clause for filtering linked objects\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the links list.\n */\n pageSize?: number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Restrict which properties are returned for each linked object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<T>[];\n\n /**\n * The mode to use for fetching data.\n * - undefined: Fetch data if not already in cache\n * - \"force\": Always fetch fresh data\n * - \"offline\": Only use cached data, don't make network requests\n */\n mode?: \"force\" | \"offline\";\n\n /**\n * The number of milliseconds to wait after the last observed link change.\n *\n * Two uses of `useLinks` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for employee data\n * const { object: employee } = useOsdkObject(Employee, employeeId);\n * const { links: reports } = useLinks(employee, \"reports\", {\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseLinksResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n links: Osdk.Instance<Q>[] | undefined;\n\n /**\n * Maps each source object's primary key to its linked object instances.\n * Useful when observing links from multiple source objects to determine\n * which source links to which targets.\n */\n linkedObjectsBySourcePrimaryKey: ReadonlyMap<\n string | number,\n ReadonlyArray<Osdk.Instance<Q>>\n >;\n\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([]);\nconst emptyMap: ReadonlyMap<string | number, ReadonlyArray<never>> = new Map();\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, ...otherOptions } = options;\n\n const stableWhere = React.useMemo(\n () => otherOptions.where,\n [JSON.stringify(otherOptions.where)],\n );\n\n const stableOrderBy = React.useMemo(\n () => otherOptions.orderBy,\n [JSON.stringify(otherOptions.orderBy)],\n );\n\n const stableSelect = React.useMemo(\n () => otherOptions.$select,\n [JSON.stringify(otherOptions.$select)],\n );\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n () => ({ unsubscribe: () => {} }),\n `links ${linkName} for ${objectsKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: stableWhere,\n pageSize: otherOptions.pageSize,\n orderBy: stableOrderBy,\n mode: otherOptions.mode,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n ...(stableSelect ? { select: stableSelect } : {}),\n },\n observer,\n ),\n `links ${linkName} for ${objectsKey}`,\n );\n },\n [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n stableWhere,\n otherOptions.pageSize,\n stableOrderBy,\n otherOptions.mode,\n otherOptions.dedupeIntervalMs,\n stableSelect,\n ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\n return React.useMemo(() => ({\n links: payload?.resolvedList,\n linkedObjectsBySourcePrimaryKey: payload?.linkedObjectsBySourcePrimaryKey\n ?? emptyMap,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n }), [payload, enabled]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAmGhD,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;AACpC,MAAMC,QAA4D,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAE9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAItBC,OAA+D,EAC/DC,QAAW,EACXC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QAAQ;IACb6C,SAAS,EAAErC,OAAO,GACbgC,OAAO,EAAEM,MAAM,KAAK,SAAS,IAAIN,OAAO,EAAEM,MAAM,KAAK,MAAM,IACzD,CAACN,OAAO,GACX,KAAK;IACTO,YAAY,EAAEP,OAAO,EAAEO,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAER,OAAO,EAAEQ,KAAK;IACrBC,SAAS,EAAET,OAAO,EAAEU,OAAO,GAAGV,OAAO,EAAES,SAAS,GAAG7B,SAAS;IAC5D8B,OAAO,EAAEV,OAAO,EAAEU,OAAO,IAAI;EAC/B,CAAC,CAAC,EAAE,CAACV,OAAO,EAAEhC,OAAO,CAAC,CAAC;AACzB","ignoreList":[]}
|
|
@@ -78,6 +78,7 @@ export function useOsdkAction(actionDef) {
|
|
|
78
78
|
unknown: e
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
throw e;
|
|
81
82
|
} finally {
|
|
82
83
|
setPending(false);
|
|
83
84
|
}
|
|
@@ -90,9 +91,7 @@ export function useOsdkAction(actionDef) {
|
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
// Abort any existing validation
|
|
93
|
-
|
|
94
|
-
abortControllerRef.current.abort();
|
|
95
|
-
}
|
|
94
|
+
abortControllerRef.current?.abort();
|
|
96
95
|
|
|
97
96
|
// Create new AbortController
|
|
98
97
|
const abortController = new AbortController();
|
|
@@ -130,9 +129,7 @@ export function useOsdkAction(actionDef) {
|
|
|
130
129
|
// Cleanup on unmount
|
|
131
130
|
React.useEffect(() => {
|
|
132
131
|
return () => {
|
|
133
|
-
|
|
134
|
-
abortControllerRef.current.abort();
|
|
135
|
-
}
|
|
132
|
+
abortControllerRef.current?.abort();
|
|
136
133
|
};
|
|
137
134
|
}, []);
|
|
138
135
|
return React.useMemo(() => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","isValidating","setValidating","validationResult","setValidationResult","abortControllerRef","useRef","applyAction","useCallback","hookArgs","current","abort","undefined","Array","isArray","updates","args","map","a","$optimisticUpdate","push","r","optimisticUpdate","ctx","update","e","actionValidation","unknown","validateAction","abortController","AbortController","result","signal","aborted","Error","name","useEffect","useMemo"],"sources":["useOsdkAction.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 ActionDefinition,\n ActionEditResponse,\n ActionValidationResponse,\n} from \"@osdk/client\";\nimport { ActionValidationError } from \"@osdk/client\";\nimport type {\n ActionSignatureFromDef,\n ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ntype ApplyActionParams<Q extends ActionDefinition<any>> =\n & Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n & {\n [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]:\n ObservableClient.ApplyActionOptions[K];\n };\n\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) => Promise<ActionEditResponse | undefined>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: ActionEditResponse | undefined;\n\n isPending: boolean;\n isValidating: boolean;\n\n /**\n * Validates the action with the provided arguments without executing it.\n * Calling this function again before the previous validation finishes will cancel\n * the first validation and start a new one.\n * @param args The action arguments to validate\n * @returns A promise that resolves to the validation response, or undefined if aborted\n */\n validateAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ) => Promise<ActionValidationResponse | undefined>;\n\n validationResult?: ActionValidationResponse;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<ActionEditResponse | undefined>();\n const [isPending, setPending] = React.useState(false);\n const [isValidating, setValidating] = React.useState(false);\n const [validationResult, setValidationResult] = React.useState<\n ActionValidationResponse | undefined\n >();\n const abortControllerRef = React.useRef<AbortController | null>(null);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) {\n try {\n // If validation is in progress, abort it\n if (isValidating && abortControllerRef.current) {\n abortControllerRef.current.abort();\n setValidating(false);\n }\n\n setPending(true);\n setError(undefined);\n\n if (Array.isArray(hookArgs)) {\n const updates: Array<\n ObservableClient.ApplyActionOptions[\"optimisticUpdate\"]\n > = [];\n const args = hookArgs.map(a => {\n const { $optimisticUpdate, ...args } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: (ctx) => {\n for (const update of updates) {\n update?.(ctx);\n }\n },\n });\n setData(r);\n return r;\n } else {\n const { $optimisticUpdate, ...args } = hookArgs;\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate,\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, actionDef, isValidating]);\n\n const validateAction = React.useCallback(async function validateAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ): Promise<ActionValidationResponse | undefined> {\n try {\n // Check if action is being applied\n if (isPending) {\n return undefined;\n }\n\n // Abort any existing validation\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n\n // Create new AbortController\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n setValidating(true);\n setError(undefined);\n\n const result = await observableClient.validateAction(actionDef, args);\n\n // Check if aborted\n if (abortController.signal.aborted) {\n return undefined;\n }\n\n setValidationResult(result);\n return result;\n } catch (e) {\n // Check if it was aborted\n if (e instanceof Error && e.name === \"AbortError\") {\n return undefined;\n }\n\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n throw e;\n } finally {\n setValidating(false);\n }\n }, [observableClient, actionDef, isPending]);\n\n // Cleanup on unmount\n React.useEffect(() => {\n return () => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n };\n }, []);\n\n return React.useMemo(() => ({\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult,\n }), [\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult,\n ]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,qBAAqB,QAAQ,cAAc;AAKpD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,mBAAmB;AAuChD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAC3D,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAkC,CAAC;EAC3E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAiC,CAAC;EACxE,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAGZ,KAAK,C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AC,CAAC,OAAON,CAAC,EAAE;MACV;MACA,IAAIA,CAAC,YAAYS,KAAK,IAAIT,CAAC,CAACU,IAAI,KAAK,YAAY,EAAE;QACjD,OAAOvB,SAAS;MAClB;MAEA,IAAIa,CAAC,YAAYtC,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACP+B,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACL9B,QAAQ,CAAC;UAAEgC,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;MACA,MAAMA,CAAC;IACT,CAAC,SAAS;MACRvB,aAAa,CAAC,KAAK,CAAC;IACtB;EACF,CAAC,EAAE,CAACV,gBAAgB,EAAED,SAAS,EAAEQ,SAAS,CAAC,CAAC;;EAE5C;EACAX,KAAK,CAACgD,SAAS,CAAC,MAAM;IACpB,OAAO,MAAM;MACX,IAAI/B,kBAAkB,CAACK,OAAO,EAAE;QAC9BL,kBAAkB,CAACK,OAAO,CAACC,KAAK,CAAC,CAAC;MACpC;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOvB,KAAK,CAACiD,OAAO,CAAC,OAAO;IAC1B9B,WAAW;IACXqB,cAAc;IACdlC,KAAK;IACLG,IAAI;IACJE,SAAS;IACTE,YAAY;IACZE;EACF,CAAC,CAAC,EAAE,CACFI,WAAW,EACXqB,cAAc,EACdlC,KAAK,EACLG,IAAI,EACJE,SAAS,EACTE,YAAY,EACZE,gBAAgB,CACjB,CAAC;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","isValidating","setValidating","validationResult","setValidationResult","abortControllerRef","useRef","applyAction","useCallback","hookArgs","current","abort","undefined","Array","isArray","updates","args","map","a","$optimisticUpdate","push","r","optimisticUpdate","ctx","update","e","actionValidation","unknown","validateAction","abortController","AbortController","result","signal","aborted","Error","name","useEffect","useMemo"],"sources":["useOsdkAction.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 ActionDefinition,\n ActionEditResponse,\n ActionValidationResponse,\n} from \"@osdk/client\";\nimport { ActionValidationError } from \"@osdk/client\";\nimport type {\n ActionSignatureFromDef,\n ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ntype ApplyActionParams<Q extends ActionDefinition<any>> =\n & Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n & {\n [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]:\n ObservableClient.ApplyActionOptions[K];\n };\n\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) => Promise<ActionEditResponse | undefined>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: ActionEditResponse | undefined;\n\n isPending: boolean;\n isValidating: boolean;\n\n /**\n * Validates the action with the provided arguments without executing it.\n * Calling this function again before the previous validation finishes will cancel\n * the first validation and start a new one.\n * @param args The action arguments to validate\n * @returns A promise that resolves to the validation response, or undefined if aborted\n */\n validateAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ) => Promise<ActionValidationResponse | undefined>;\n\n validationResult?: ActionValidationResponse;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<ActionEditResponse | undefined>();\n const [isPending, setPending] = React.useState(false);\n const [isValidating, setValidating] = React.useState(false);\n const [validationResult, setValidationResult] = React.useState<\n ActionValidationResponse | undefined\n >();\n const abortControllerRef = React.useRef<AbortController | null>(null);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) {\n try {\n // If validation is in progress, abort it\n if (isValidating && abortControllerRef.current) {\n abortControllerRef.current.abort();\n setValidating(false);\n }\n\n setPending(true);\n setError(undefined);\n\n if (Array.isArray(hookArgs)) {\n const updates: Array<\n ObservableClient.ApplyActionOptions[\"optimisticUpdate\"]\n > = [];\n const args = hookArgs.map(a => {\n const { $optimisticUpdate, ...args } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: (ctx) => {\n for (const update of updates) {\n update?.(ctx);\n }\n },\n });\n setData(r);\n return r;\n } else {\n const { $optimisticUpdate, ...args } = hookArgs;\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate,\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n throw e;\n } finally {\n setPending(false);\n }\n }, [observableClient, actionDef, isValidating]);\n\n const validateAction = React.useCallback(async function validateAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ): Promise<ActionValidationResponse | undefined> {\n try {\n // Check if action is being applied\n if (isPending) {\n return undefined;\n }\n\n // Abort any existing validation\n abortControllerRef.current?.abort();\n\n // Create new AbortController\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n setValidating(true);\n setError(undefined);\n\n const result = await observableClient.validateAction(actionDef, args);\n\n // Check if aborted\n if (abortController.signal.aborted) {\n return undefined;\n }\n\n setValidationResult(result);\n return result;\n } catch (e) {\n // Check if it was aborted\n if (e instanceof Error && e.name === \"AbortError\") {\n return undefined;\n }\n\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n throw e;\n } finally {\n setValidating(false);\n }\n }, [observableClient, actionDef, isPending]);\n\n // Cleanup on unmount\n React.useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n };\n }, []);\n\n return React.useMemo(() => ({\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult,\n }), [\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult,\n ]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,qBAAqB,QAAQ,cAAc;AAKpD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,mBAAmB;AAuChD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAC3D,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAkC,CAAC;EAC3E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAiC,CAAC;EACxE,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAGZ,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAACK,YAAY,EAAEC,aAAa,CAAC,GAAGd,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EAC3D,MAAM,CAACO,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGhB,KAAK,CAACQ,QAAQ,CAE5D,CAAC;EACH,MAAMS,kBA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;QACL9B,QAAQ,CAAC;UAAEgC,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;MACA,MAAMA,CAAC;IACT,CAAC,SAAS;MACRvB,aAAa,CAAC,KAAK,CAAC;IACtB;EACF,CAAC,EAAE,CAACV,gBAAgB,EAAED,SAAS,EAAEQ,SAAS,CAAC,CAAC;;EAE5C;EACAX,KAAK,CAACgD,SAAS,CAAC,MAAM;IACpB,OAAO,MAAM;MACX/B,kBAAkB,CAACK,OAAO,EAAEC,KAAK,CAAC,CAAC;IACrC,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOvB,KAAK,CAACiD,OAAO,CAAC,OAAO;IAC1B9B,WAAW;IACXqB,cAAc;IACdlC,KAAK;IACLG,IAAI;IACJE,SAAS;IACTE,YAAY;IACZE;EACF,CAAC,CAAC,EAAE,CACFI,WAAW,EACXqB,cAAc,EACdlC,KAAK,EACLG,IAAI,EACJE,SAAS,EACTE,YAAY,EACZE,gBAAgB,CACjB,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 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 React from "react";
|
|
18
|
+
import { useOsdkClient } from "../useOsdkClient.js";
|
|
19
|
+
/**
|
|
20
|
+
* React hook for executing multiple OSDK function queries in parallel.
|
|
21
|
+
* Results are returned in the same order as the input queries.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Configuration options containing the queries to execute
|
|
24
|
+
* @returns Array of results in the same order as input queries, each with the same shape as useOsdkFunction
|
|
25
|
+
*/
|
|
26
|
+
export function useOsdkFunctions({
|
|
27
|
+
queries,
|
|
28
|
+
enabled = true
|
|
29
|
+
}) {
|
|
30
|
+
const client = useOsdkClient();
|
|
31
|
+
const [results, setResults] = React.useState(() => queries.map(() => ({
|
|
32
|
+
data: undefined,
|
|
33
|
+
isLoading: false,
|
|
34
|
+
error: undefined,
|
|
35
|
+
lastUpdated: 0
|
|
36
|
+
})));
|
|
37
|
+
const abortControllerRef = React.useRef(null);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
if (!enabled || queries.length === 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Cancel previous requests
|
|
44
|
+
abortControllerRef.current?.abort();
|
|
45
|
+
const abortController = new AbortController();
|
|
46
|
+
abortControllerRef.current = abortController;
|
|
47
|
+
void (async () => {
|
|
48
|
+
// Initialize loading state for all queries
|
|
49
|
+
setResults(prev => queries.map((_, index) => ({
|
|
50
|
+
data: prev[index]?.data,
|
|
51
|
+
// Preserving existing data
|
|
52
|
+
isLoading: queries[index].options?.enabled !== false,
|
|
53
|
+
error: undefined,
|
|
54
|
+
lastUpdated: prev[index]?.lastUpdated || 0
|
|
55
|
+
})));
|
|
56
|
+
for await (const queryResult of executeQueriesGenerator(queries, client)) {
|
|
57
|
+
const {
|
|
58
|
+
index,
|
|
59
|
+
result,
|
|
60
|
+
error
|
|
61
|
+
} = queryResult;
|
|
62
|
+
if (abortController.signal.aborted) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
setResults(prev => {
|
|
66
|
+
if (abortController.signal.aborted) {
|
|
67
|
+
return prev;
|
|
68
|
+
}
|
|
69
|
+
const newResults = [...prev];
|
|
70
|
+
newResults[index] = {
|
|
71
|
+
data: result,
|
|
72
|
+
isLoading: false,
|
|
73
|
+
error: error instanceof Error ? error : error ? new Error(typeof error === "string" ? error : JSON.stringify(error)) : undefined,
|
|
74
|
+
lastUpdated: Date.now()
|
|
75
|
+
};
|
|
76
|
+
return newResults;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
return () => {
|
|
81
|
+
abortController.abort();
|
|
82
|
+
};
|
|
83
|
+
}, [enabled, client, queries]);
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Generator function that executes queries and yields results as they complete
|
|
88
|
+
*/
|
|
89
|
+
async function* executeQueriesGenerator(queries, client) {
|
|
90
|
+
const queryPromises = queries.map((query, index) => createQueryPromise(query, index, client));
|
|
91
|
+
const pendingPromises = [...queryPromises];
|
|
92
|
+
|
|
93
|
+
// Yield results as they complete using Promise.race
|
|
94
|
+
while (pendingPromises.length > 0) {
|
|
95
|
+
const raceResult = await Promise.race(pendingPromises.map((promise, idx) => promise.then(result => ({
|
|
96
|
+
result,
|
|
97
|
+
idx
|
|
98
|
+
}))));
|
|
99
|
+
yield raceResult.result;
|
|
100
|
+
|
|
101
|
+
// Remove the completed promise from the pending list
|
|
102
|
+
void pendingPromises.splice(raceResult.idx, 1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const createQueryPromise = async (query, index, client) => {
|
|
106
|
+
// Skip disabled queries
|
|
107
|
+
if (query.options?.enabled === false) {
|
|
108
|
+
return {
|
|
109
|
+
index,
|
|
110
|
+
result: undefined,
|
|
111
|
+
error: undefined
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const queryClient = client(query.queryDefinition);
|
|
115
|
+
if ("executeFunction" in queryClient && typeof queryClient.executeFunction === "function") {
|
|
116
|
+
try {
|
|
117
|
+
const result = await queryClient.executeFunction(query.options?.params);
|
|
118
|
+
return {
|
|
119
|
+
index,
|
|
120
|
+
result,
|
|
121
|
+
error: null
|
|
122
|
+
};
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
index,
|
|
126
|
+
result: undefined,
|
|
127
|
+
error
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
index,
|
|
133
|
+
result: undefined,
|
|
134
|
+
error: new Error("Invalid query client: executeFunction method not found")
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=useOsdkFunctions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsdkFunctions.js","names":["React","useOsdkClient","useOsdkFunctions","queries","enabled","client","results","setResults","useState","map","data","undefined","isLoading","error","lastUpdated","abortControllerRef","useRef","useEffect","length","current","abort","abortController","AbortController","prev","_","index","options","queryResult","executeQueriesGenerator","result","signal","aborted","newResults","Error","JSON","stringify","Date","now","queryPromises","query","createQueryPromise","pendingPromises","raceResult","Promise","race","promise","idx","then","splice","queryClient","queryDefinition","executeFunction","params"],"sources":["useOsdkFunctions.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { CompileTimeMetadata, QueryDefinition } from \"@osdk/api\";\nimport type { Client } from \"@osdk/client\";\nimport React from \"react\";\nimport { useOsdkClient } from \"../useOsdkClient.js\";\nimport type {\n UseOsdkFunctionOptions,\n UseOsdkFunctionResult,\n} from \"./useOsdkFunction.js\";\n\nexport interface FunctionQueryParams<Q extends QueryDefinition<unknown>> {\n queryDefinition: Q;\n /**\n * Only allow params and enabled options at the query level,\n * other options are not yet supported in this batch context\n */\n options?: Pick<UseOsdkFunctionOptions<Q>, \"params\" | \"enabled\">;\n}\n\nexport interface UseOsdkFunctionsProps {\n /**\n * Array of query configurations to execute\n */\n queries: Array<FunctionQueryParams<QueryDefinition<unknown>>>;\n\n /**\n * Whether to enable all queries. When false, no queries will execute.\n * Individual query enabled states are also respected.\n * @default true\n */\n enabled?: boolean;\n}\n\nexport type UseOsdkFunctionsResult = Array<\n Omit<UseOsdkFunctionResult<QueryDefinition<unknown>>, \"refetch\">\n>;\n\n/**\n * React hook for executing multiple OSDK function queries in parallel.\n * Results are returned in the same order as the input queries.\n *\n * @param options - Configuration options containing the queries to execute\n * @returns Array of results in the same order as input queries, each with the same shape as useOsdkFunction\n */\nexport function useOsdkFunctions(\n { queries, enabled = true }: UseOsdkFunctionsProps,\n): UseOsdkFunctionsResult {\n const client = useOsdkClient();\n\n const [results, setResults] = React.useState<\n UseOsdkFunctionsResult\n >(() =>\n queries.map(() => ({\n data: undefined,\n isLoading: false,\n error: undefined,\n lastUpdated: 0,\n }))\n );\n\n const abortControllerRef = React.useRef<AbortController | null>(null);\n\n React.useEffect(() => {\n if (!enabled || queries.length === 0) {\n return;\n }\n\n // Cancel previous requests\n abortControllerRef.current?.abort();\n\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n const executeQueries = async () => {\n // Initialize loading state for all queries\n setResults(prev =>\n queries.map((_, index) => ({\n data: prev[index]?.data, // Preserving existing data\n isLoading: queries[index].options?.enabled !== false,\n error: undefined,\n lastUpdated: prev[index]?.lastUpdated || 0,\n }))\n );\n\n for await (\n const queryResult of executeQueriesGenerator(\n queries,\n client,\n )\n ) {\n const { index, result, error } = queryResult;\n\n if (abortController.signal.aborted) {\n break;\n }\n\n setResults(prev => {\n if (abortController.signal.aborted) {\n return prev;\n }\n const newResults = [...prev];\n newResults[index] = {\n data: result,\n isLoading: false,\n error: error instanceof Error\n ? error\n : error\n ? new Error(\n typeof error === \"string\" ? error : JSON.stringify(error),\n )\n : undefined,\n lastUpdated: Date.now(),\n };\n return newResults;\n });\n }\n };\n\n void executeQueries();\n\n return () => {\n abortController.abort();\n };\n }, [\n enabled,\n client,\n queries,\n ]);\n\n return results;\n}\n\ninterface QueryResult<Q extends QueryDefinition<unknown>> {\n index: number;\n result?:\n | (CompileTimeMetadata<Q>[\"signature\"] extends (...args: never[]) => infer R\n ? Awaited<R>\n : never)\n | undefined;\n error?: unknown;\n}\n/**\n * Generator function that executes queries and yields results as they complete\n */\nasync function* executeQueriesGenerator(\n queries: Array<FunctionQueryParams<QueryDefinition<unknown>>>,\n client: Client,\n): AsyncGenerator<QueryResult<QueryDefinition<unknown>>> {\n const queryPromises = queries.map((query, index) =>\n createQueryPromise<typeof query.queryDefinition>(query, index, client)\n );\n\n const pendingPromises = [...queryPromises];\n\n // Yield results as they complete using Promise.race\n while (pendingPromises.length > 0) {\n const raceResult = await Promise.race(\n pendingPromises.map((promise, idx) =>\n promise.then(result => ({ result, idx }))\n ),\n );\n\n yield raceResult.result;\n\n // Remove the completed promise from the pending list\n void pendingPromises.splice(raceResult.idx, 1);\n }\n}\n\nconst createQueryPromise = async <Q extends QueryDefinition<unknown>>(\n query: FunctionQueryParams<Q>,\n index: number,\n client: Client,\n): Promise<QueryResult<Q>> => {\n // Skip disabled queries\n if (query.options?.enabled === false) {\n return { index, result: undefined, error: undefined };\n }\n\n const queryClient = client(query.queryDefinition);\n\n if (\n \"executeFunction\" in queryClient\n && typeof queryClient.executeFunction === \"function\"\n ) {\n try {\n const result = await queryClient.executeFunction(query.options?.params);\n return { index, result, error: null };\n } catch (error) {\n return { index, result: undefined, error };\n }\n }\n\n return {\n index,\n result: undefined,\n error: new Error(\"Invalid query client: executeFunction method not found\"),\n };\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,aAAa,QAAQ,qBAAq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nCH,eAAe,CAAChC,GAAG,CAAC,CAACoC,OAAO,EAAEC,GAAG,KAC/BD,OAAO,CAACE,IAAI,CAAClB,MAAM,KAAK;MAAEA,MAAM;MAAEiB;IAAI,CAAC,CAAC,CAC1C,CACF,CAAC;IAED,MAAMJ,UAAU,CAACb,MAAM;;IAEvB;IACA,KAAKY,eAAe,CAACO,MAAM,CAACN,UAAU,CAACI,GAAG,EAAE,CAAC,CAAC;EAChD;AACF;AAEA,MAAMN,kBAAkB,GAAG,MAAAA,CACzBD,KAA6B,EAC7Bd,KAAa,EACbpB,MAAc,KACc;EAC5B;EACA,IAAIkC,KAAK,CAACb,OAAO,EAAEtB,OAAO,KAAK,KAAK,EAAE;IACpC,OAAO;MAAEqB,KAAK;MAAEI,MAAM,EAAElB,SAAS;MAAEE,KAAK,EAAEF;IAAU,CAAC;EACvD;EAEA,MAAMsC,WAAW,GAAG5C,MAAM,CAACkC,KAAK,CAACW,eAAe,CAAC;EAEjD,IACE,iBAAiB,IAAID,WAAW,IAC7B,OAAOA,WAAW,CAACE,eAAe,KAAK,UAAU,EACpD;IACA,IAAI;MACF,MAAMtB,MAAM,GAAG,MAAMoB,WAAW,CAACE,eAAe,CAACZ,KAAK,CAACb,OAAO,EAAE0B,MAAM,CAAC;MACvE,OAAO;QAAE3B,KAAK;QAAEI,MAAM;QAAEhB,KAAK,EAAE;MAAK,CAAC;IACvC,CAAC,CAAC,OAAOA,KAAK,EAAE;MACd,OAAO;QAAEY,KAAK;QAAEI,MAAM,EAAElB,SAAS;QAAEE;MAAM,CAAC;IAC5C;EACF;EAEA,OAAO;IACLY,KAAK;IACLI,MAAM,EAAElB,SAAS;IACjBE,KAAK,EAAE,IAAIoB,KAAK,CAAC,wDAAwD;EAC3E,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -36,7 +36,7 @@ import { OsdkContext2 } from "./OsdkContext2.js";
|
|
|
36
36
|
*
|
|
37
37
|
* @param type The object type or interface definition
|
|
38
38
|
* @param primaryKey The primary key of the object
|
|
39
|
-
* @param options Options including $select and
|
|
39
|
+
* @param options Options including $select, enabled, and $loadPropertySecurityMetadata
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
/*
|
|
@@ -58,6 +58,7 @@ export function useOsdkObject(...args) {
|
|
|
58
58
|
// Extract enabled flag - 2nd param for instance signature, 3rd for type signature
|
|
59
59
|
const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : optionsArg ? optionsArg.enabled ?? true : typeof args[2] === "boolean" ? args[2] : true;
|
|
60
60
|
const selectArg = optionsArg?.$select;
|
|
61
|
+
const loadPropertySecurityMetadata = optionsArg?.$loadPropertySecurityMetadata;
|
|
61
62
|
const mode = isInstanceSignature ? "offline" : undefined;
|
|
62
63
|
const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
|
|
63
64
|
const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
|
|
@@ -76,9 +77,12 @@ export function useOsdkObject(...args) {
|
|
|
76
77
|
mode,
|
|
77
78
|
...(stableSelect ? {
|
|
78
79
|
select: stableSelect
|
|
80
|
+
} : {}),
|
|
81
|
+
...(loadPropertySecurityMetadata ? {
|
|
82
|
+
$loadPropertySecurityMetadata: loadPropertySecurityMetadata
|
|
79
83
|
} : {})
|
|
80
84
|
}, observer), `object ${apiNameString} ${primaryKey}`);
|
|
81
|
-
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode, stableSelect]);
|
|
85
|
+
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode, stableSelect, loadPropertySecurityMetadata]);
|
|
82
86
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
83
87
|
const forceUpdate = React.useCallback(() => {
|
|
84
88
|
throw new Error("not implemented");
|