@osdk/react 0.10.0-beta.12 → 0.10.0-beta.14
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 +29 -0
- package/build/browser/new/OsdkContext2.js +22 -2
- package/build/browser/new/OsdkContext2.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +2 -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/public/unstable-do-not-use.js +18 -0
- package/build/browser/public/unstable-do-not-use.js.map +1 -0
- 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/public/experimental/admin.cjs +11 -11
- package/build/cjs/public/experimental.cjs +30 -33
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +4 -120
- 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/esm/new/OsdkContext2.js +22 -2
- package/build/esm/new/OsdkContext2.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +2 -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/public/unstable-do-not-use.js +18 -0
- package/build/esm/public/unstable-do-not-use.js.map +1 -0
- package/build/types/new/OsdkContext2.d.ts +1 -0
- package/build/types/new/OsdkContext2.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/public/unstable-do-not-use.d.ts +2 -0
- package/build/types/public/unstable-do-not-use.d.ts.map +1 -0
- package/package.json +14 -5
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @osdkkit/react
|
|
2
2
|
|
|
3
|
+
## 0.10.0-beta.14
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b0930e4: Show helpful error message when hooks are used without OsdkProvider2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [520398c]
|
|
12
|
+
- Updated dependencies [ffc6efe]
|
|
13
|
+
- Updated dependencies [4a856cb]
|
|
14
|
+
- @osdk/client@2.8.0-beta.29
|
|
15
|
+
- @osdk/api@2.8.0-beta.29
|
|
16
|
+
|
|
17
|
+
## 0.10.0-beta.13
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- f294f5a: Remove literal support before GA.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [f294f5a]
|
|
26
|
+
- Updated dependencies [2855223]
|
|
27
|
+
- Updated dependencies [d284bf2]
|
|
28
|
+
- Updated dependencies [b68cebd]
|
|
29
|
+
- @osdk/client@2.8.0-beta.28
|
|
30
|
+
- @osdk/api@2.8.0-beta.28
|
|
31
|
+
|
|
3
32
|
## 0.10.0-beta.12
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
|
@@ -15,14 +15,34 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import React from "react";
|
|
18
|
+
export const MISSING_PROVIDER_MESSAGE = "No OsdkProvider2 found. Did you forget to wrap your component tree with <OsdkProvider2>?";
|
|
18
19
|
function fakeClientFn(..._args) {
|
|
19
|
-
throw new Error(
|
|
20
|
+
throw new Error(MISSING_PROVIDER_MESSAGE);
|
|
20
21
|
}
|
|
21
22
|
const fakeClient = Object.assign(fakeClientFn, {
|
|
22
23
|
fetchMetadata: fakeClientFn
|
|
23
24
|
});
|
|
25
|
+
|
|
26
|
+
// Proxy that throws a clear error when any method is called, so hooks like
|
|
27
|
+
// useOsdkObjects get "Did you forget <OsdkProvider2>?" instead of
|
|
28
|
+
// "cannot read canonicalizeWhereClause of undefined".
|
|
29
|
+
// We intercept `get` so every property access returns a throwing function,
|
|
30
|
+
// without needing to enumerate every ObservableClient method.
|
|
31
|
+
// Symbol.toPrimitive and Symbol.toStringTag are accessed by React/devtools
|
|
32
|
+
// during rendering and logging — returning undefined for these avoids
|
|
33
|
+
// spurious throws in contexts unrelated to the user's code.
|
|
34
|
+
const fakeObservableClient = new Proxy({}, {
|
|
35
|
+
get(_target, prop) {
|
|
36
|
+
if (prop === Symbol.toPrimitive || prop === Symbol.toStringTag) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return (..._args) => {
|
|
40
|
+
throw new Error(MISSING_PROVIDER_MESSAGE);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
|
24
44
|
export const OsdkContext2 = /*#__PURE__*/React.createContext({
|
|
25
45
|
client: fakeClient,
|
|
26
|
-
observableClient:
|
|
46
|
+
observableClient: fakeObservableClient
|
|
27
47
|
});
|
|
28
48
|
//# sourceMappingURL=OsdkContext2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OsdkContext2.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext2","createContext","client","observableClient"
|
|
1
|
+
{"version":3,"file":"OsdkContext2.js","names":["React","MISSING_PROVIDER_MESSAGE","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","fakeObservableClient","Proxy","get","_target","prop","Symbol","toPrimitive","toStringTag","undefined","OsdkContext2","createContext","client","observableClient"],"sources":["OsdkContext2.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { Client } from \"@osdk/client\";\nimport type { ObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\n\nexport const MISSING_PROVIDER_MESSAGE =\n \"No OsdkProvider2 found. Did you forget to wrap your component tree with <OsdkProvider2>?\";\n\nfunction fakeClientFn(..._args: any[]) {\n throw new Error(MISSING_PROVIDER_MESSAGE);\n}\n\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn,\n} as Client);\n\n// Proxy that throws a clear error when any method is called, so hooks like\n// useOsdkObjects get \"Did you forget <OsdkProvider2>?\" instead of\n// \"cannot read canonicalizeWhereClause of undefined\".\n// We intercept `get` so every property access returns a throwing function,\n// without needing to enumerate every ObservableClient method.\n// Symbol.toPrimitive and Symbol.toStringTag are accessed by React/devtools\n// during rendering and logging — returning undefined for these avoids\n// spurious throws in contexts unrelated to the user's code.\nconst fakeObservableClient = new Proxy({} as ObservableClient, {\n get(_target, prop) {\n if (prop === Symbol.toPrimitive || prop === Symbol.toStringTag) {\n return undefined;\n }\n return (..._args: any[]) => {\n throw new Error(MISSING_PROVIDER_MESSAGE);\n };\n },\n});\n\ninterface OsdkContextContents {\n client: Client;\n // keeping the old name for now intentionally\n // in case i need both for a while\n // in the future we can just make\n // this `client: ObservableClient`\n observableClient: ObservableClient;\n}\n\nexport const OsdkContext2: React.Context<OsdkContextContents> = React\n .createContext<OsdkContextContents>({\n client: fakeClient,\n observableClient: fakeObservableClient,\n });\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AAEzB,OAAO,MAAMC,wBAAwB,GACnC,0FAA0F;AAE5F,SAASC,YAAYA,CAAC,GAAGC,KAAY,EAAE;EACrC,MAAM,IAAIC,KAAK,CAACH,wBAAwB,CAAC;AAC3C;AAEA,MAAMI,UAAU,GAAGC,MAAM,CAACC,MAAM,CAACL,YAAY,EAAE;EAC7CM,aAAa,EAAEN;AACjB,CAAW,CAAC;;AAEZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMO,oBAAoB,GAAG,IAAIC,KAAK,CAAC,CAAC,CAAC,EAAsB;EAC7DC,GAAGA,CAACC,OAAO,EAAEC,IAAI,EAAE;IACjB,IAAIA,IAAI,KAAKC,MAAM,CAACC,WAAW,IAAIF,IAAI,KAAKC,MAAM,CAACE,WAAW,EAAE;MAC9D,OAAOC,SAAS;IAClB;IACA,OAAO,CAAC,GAAGd,KAAY,KAAK;MAC1B,MAAM,IAAIC,KAAK,CAACH,wBAAwB,CAAC;IAC3C,CAAC;EACH;AACF,CAAC,CAAC;AAWF,OAAO,MAAMiB,YAAgD,gBAAGlB,KAAK,CAClEmB,aAAa,CAAsB;EAClCC,MAAM,EAAEf,UAAU;EAClBgB,gBAAgB,EAAEZ;AACpB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -91,9 +91,7 @@ export function useOsdkAction(actionDef) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// Abort any existing validation
|
|
94
|
-
|
|
95
|
-
abortControllerRef.current.abort();
|
|
96
|
-
}
|
|
94
|
+
abortControllerRef.current?.abort();
|
|
97
95
|
|
|
98
96
|
// Create new AbortController
|
|
99
97
|
const abortController = new AbortController();
|
|
@@ -131,9 +129,7 @@ export function useOsdkAction(actionDef) {
|
|
|
131
129
|
// Cleanup on unmount
|
|
132
130
|
React.useEffect(() => {
|
|
133
131
|
return () => {
|
|
134
|
-
|
|
135
|
-
abortControllerRef.current.abort();
|
|
136
|
-
}
|
|
132
|
+
abortControllerRef.current?.abort();
|
|
137
133
|
};
|
|
138
134
|
}, []);
|
|
139
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 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 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;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B,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;EAAi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. 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,qBAAqB;AAiCnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9B;EAAEC,OAAO;EAAEC,OAAO,GAAG;AAA4B,CAAC,EAC1B;EACxB,MAAMC,MAAM,GAAGJ,aAAa,CAAC,CAAC;EAE9B,MAAM,CAACK,OAAO,EAAEC,UAAU,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAE1C,MACAL,OAAO,CAACM,GAAG,CAAC,OAAO;IACjBC,IAAI,EAAEC,SAAS;IACfC,SAAS,EAAE,KAAK;IAChBC,KAAK,EAAEF,SAAS;IAChBG,WAAW,EAAE;EACf,CAAC,CAAC,CACJ,CAAC;EAED,MAAMC,kBAAkB,GAAGf,KAAK,CAACgB,MAAM,CAAyB,IAAI,CAAC;EAErEhB,KAAK,CAACiB,SAAS,CAAC,MAAM;IACpB,IAAI,CAACb,OAAO,IAAID,OAAO,CAACe,MAAM,KAAK,CAAC,EAAE;MACpC;IACF;;IAEA;IACAH,kBAAkB,CAACI,OAAO,EAAEC,KAAK,CAAC,CAAC;IAEnC,MAAMC,eAAe,GAAG,IAAIC,eAAe,CAAC,CAAC;IAC7CP,kBAA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B,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":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export { useOsdkFunctions } from "../new/useOsdkFunctions.js";
|
|
18
|
+
//# sourceMappingURL=unstable-do-not-use.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unstable-do-not-use.js","names":["useOsdkFunctions"],"sources":["unstable-do-not-use.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\nexport { useOsdkFunctions } from \"../new/useOsdkFunctions.js\";\nexport type {\n FunctionQueryParams,\n UseOsdkFunctionsProps,\n UseOsdkFunctionsResult,\n} from \"../new/useOsdkFunctions.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,QAAQ,4BAA4B","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
8
|
+
|
|
9
|
+
// src/useOsdkClient.ts
|
|
10
|
+
function fakeClientFn(..._args) {
|
|
11
|
+
throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
|
|
12
|
+
}
|
|
13
|
+
var fakeClient = Object.assign(fakeClientFn, {
|
|
14
|
+
fetchMetadata: fakeClientFn
|
|
15
|
+
});
|
|
16
|
+
var OsdkContext = /* @__PURE__ */ React__default.default.createContext({
|
|
17
|
+
client: fakeClient
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// src/useOsdkClient.ts
|
|
21
|
+
function useOsdkClient() {
|
|
22
|
+
return React__default.default.useContext(OsdkContext).client;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.OsdkContext = OsdkContext;
|
|
26
|
+
exports.useOsdkClient = useOsdkClient;
|
|
27
|
+
//# sourceMappingURL=chunk-2N32USW5.cjs.map
|
|
28
|
+
//# sourceMappingURL=chunk-2N32USW5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/OsdkContext.ts","../../src/useOsdkClient.ts"],"names":["React"],"mappings":";;;;;;;;;AAiBA,SAAS,gBAAgB,KAAO,EAAA;AAC9B,EAAM,MAAA,IAAI,MAAM,sEAAsE,CAAA;AACxF;AACA,IAAM,UAAA,GAAa,MAAO,CAAA,MAAA,CAAO,YAAc,EAAA;AAAA,EAC7C,aAAe,EAAA;AACjB,CAAC,CAAA;AACY,IAAA,WAAA,0CAAiC,aAAc,CAAA;AAAA,EAC1D,MAAQ,EAAA;AACV,CAAC;;;ACPM,SAAS,aAAgB,GAAA;AAC9B,EAAOA,OAAAA,sBAAAA,CAAM,UAAW,CAAA,WAAW,CAAE,CAAA,MAAA;AACvC","file":"chunk-2N32USW5.cjs","sourcesContent":["/*\n * Copyright 2024 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 React from \"react\";\nfunction fakeClientFn(..._args) {\n throw new Error(\"This is not a real client. Did you forget to <OsdkContext.Provider>?\");\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\nexport const OsdkContext = /*#__PURE__*/React.createContext({\n client: fakeClient\n});","/*\n * Copyright 2024 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 React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nexport function useOsdkClient() {\n return React.useContext(OsdkContext).client;\n}"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2N32USW5_cjs = require('./chunk-2N32USW5.cjs');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
9
|
+
|
|
10
|
+
function useOsdkMetadata(type) {
|
|
11
|
+
const client = chunk2N32USW5_cjs.useOsdkClient();
|
|
12
|
+
const [metadata, setMetadata] = React__default.default.useState(void 0);
|
|
13
|
+
const [error, setError] = React__default.default.useState();
|
|
14
|
+
if (!metadata && !error) {
|
|
15
|
+
client.fetchMetadata(type).then((fetchedMetadata) => {
|
|
16
|
+
setMetadata(fetchedMetadata);
|
|
17
|
+
}).catch((error2) => {
|
|
18
|
+
const errorMessage = error2 instanceof Error ? error2.message : String(error2);
|
|
19
|
+
setError(errorMessage);
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
loading: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
loading: false,
|
|
27
|
+
metadata,
|
|
28
|
+
error
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.useOsdkMetadata = useOsdkMetadata;
|
|
33
|
+
//# sourceMappingURL=chunk-R4FZ5MUH.cjs.map
|
|
34
|
+
//# sourceMappingURL=chunk-R4FZ5MUH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useOsdkMetadata.ts"],"names":["useOsdkClient","React","error"],"mappings":";;;;;;;;;AAkBO,SAAS,gBAAgB,IAAM,EAAA;AACpC,EAAA,MAAM,SAASA,+BAAc,EAAA;AAC7B,EAAA,MAAM,CAAC,QAAU,EAAA,WAAW,CAAI,GAAAC,sBAAA,CAAM,SAAS,MAAS,CAAA;AACxD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,uBAAM,QAAS,EAAA;AACzC,EAAI,IAAA,CAAC,QAAY,IAAA,CAAC,KAAO,EAAA;AACvB,IAAA,MAAA,CAAO,aAAc,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,CAAmB,eAAA,KAAA;AACjD,MAAA,WAAA,CAAY,eAAe,CAAA;AAAA,KAC5B,CAAA,CAAE,KAAM,CAAA,CAAAC,MAAS,KAAA;AAChB,MAAA,MAAM,eAAeA,MAAiB,YAAA,KAAA,GAAQA,MAAM,CAAA,OAAA,GAAU,OAAOA,MAAK,CAAA;AAC1E,MAAA,QAAA,CAAS,YAAY,CAAA;AAAA,KACtB,CAAA;AACD,IAAO,OAAA;AAAA,MACL,OAAS,EAAA;AAAA,KACX;AAAA;AAEF,EAAO,OAAA;AAAA,IACL,OAAS,EAAA,KAAA;AAAA,IACT,QAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-R4FZ5MUH.cjs","sourcesContent":["/*\n * Copyright 2024 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 React from \"react\";\nimport { useOsdkClient } from \"./useOsdkClient.js\";\nexport function useOsdkMetadata(type) {\n const client = useOsdkClient();\n const [metadata, setMetadata] = React.useState(undefined);\n const [error, setError] = React.useState();\n if (!metadata && !error) {\n client.fetchMetadata(type).then(fetchedMetadata => {\n setMetadata(fetchedMetadata);\n }).catch(error => {\n const errorMessage = error instanceof Error ? error.message : String(error);\n setError(errorMessage);\n });\n return {\n loading: true\n };\n }\n return {\n loading: false,\n metadata,\n error\n };\n}"]}
|
|
@@ -7,15 +7,26 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
7
7
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
8
8
|
|
|
9
9
|
// src/new/OsdkContext2.ts
|
|
10
|
+
var MISSING_PROVIDER_MESSAGE = "No OsdkProvider2 found. Did you forget to wrap your component tree with <OsdkProvider2>?";
|
|
10
11
|
function fakeClientFn(..._args) {
|
|
11
|
-
throw new Error(
|
|
12
|
+
throw new Error(MISSING_PROVIDER_MESSAGE);
|
|
12
13
|
}
|
|
13
14
|
var fakeClient = Object.assign(fakeClientFn, {
|
|
14
15
|
fetchMetadata: fakeClientFn
|
|
15
16
|
});
|
|
17
|
+
var fakeObservableClient = new Proxy({}, {
|
|
18
|
+
get(_target, prop) {
|
|
19
|
+
if (prop === Symbol.toPrimitive || prop === Symbol.toStringTag) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
return (..._args) => {
|
|
23
|
+
throw new Error(MISSING_PROVIDER_MESSAGE);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
16
27
|
var OsdkContext2 = /* @__PURE__ */ React__default.default.createContext({
|
|
17
28
|
client: fakeClient,
|
|
18
|
-
observableClient:
|
|
29
|
+
observableClient: fakeObservableClient
|
|
19
30
|
});
|
|
20
31
|
|
|
21
32
|
// src/new/makeExternalStore.ts
|
|
@@ -107,5 +118,5 @@ function makeExternalStoreAsync(createObservation, _name, initialValue) {
|
|
|
107
118
|
exports.OsdkContext2 = OsdkContext2;
|
|
108
119
|
exports.makeExternalStore = makeExternalStore;
|
|
109
120
|
exports.makeExternalStoreAsync = makeExternalStoreAsync;
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
111
|
-
//# sourceMappingURL=chunk-
|
|
121
|
+
//# sourceMappingURL=chunk-ZUNR45SJ.cjs.map
|
|
122
|
+
//# sourceMappingURL=chunk-ZUNR45SJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/new/OsdkContext2.ts","../../src/new/makeExternalStore.ts"],"names":[],"mappings":";;;;;;;;;AAiBO,IAAM,wBAA2B,GAAA,0FAAA;AACxC,SAAS,gBAAgB,KAAO,EAAA;AAC9B,EAAM,MAAA,IAAI,MAAM,wBAAwB,CAAA;AAC1C;AACA,IAAM,UAAA,GAAa,MAAO,CAAA,MAAA,CAAO,YAAc,EAAA;AAAA,EAC7C,aAAe,EAAA;AACjB,CAAC,CAAA;AAUD,IAAM,oBAAuB,GAAA,IAAI,KAAM,CAAA,EAAI,EAAA;AAAA,EACzC,GAAA,CAAI,SAAS,IAAM,EAAA;AACjB,IAAA,IAAI,IAAS,KAAA,MAAA,CAAO,WAAe,IAAA,IAAA,KAAS,OAAO,WAAa,EAAA;AAC9D,MAAO,OAAA,MAAA;AAAA;AAET,IAAA,OAAO,IAAI,KAAU,KAAA;AACnB,MAAM,MAAA,IAAI,MAAM,wBAAwB,CAAA;AAAA,KAC1C;AAAA;AAEJ,CAAC,CAAA;AACY,IAAA,YAAA,0CAAkC,aAAc,CAAA;AAAA,EAC3D,MAAQ,EAAA,UAAA;AAAA,EACR,gBAAkB,EAAA;AACpB,CAAC;;;AC9BM,SAAS,iBAAA,CAAkB,iBAAmB,EAAA,KAAA,EAAO,YAAc,EAAA;AACxE,EAAA,IAAI,UAAa,GAAA,YAAA;AACjB,EAAA,SAAS,WAAc,GAAA;AACrB,IAAO,OAAA,UAAA;AAAA;AAET,EAAA,SAAS,UAAU,YAAc,EAAA;AAC/B,IAAA,MAAM,MAAM,iBAAkB,CAAA;AAAA,MAC5B,MAAM,CAAW,OAAA,KAAA;AACf,QAAa,UAAA,GAAA,OAAA;AACb,QAAa,YAAA,EAAA;AAAA,OACf;AAAA,M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,EAAA;AACZ,QAAsB,mBAAA,GAAA,GAAA;AAAA,OACjB,MAAA;AACL,QAAA,GAAA,CAAI,WAAY,EAAA;AAAA;AAClB,KACD,CAAE,CAAA,KAAA,CAAM,CAAS,KAAA,KAAA;AAChB,MAAA,IAAI,QAAU,EAAA;AACZ,QAAa,UAAA,GAAA;AAAA,UACX,GAAI,cAAc,EAAC;AAAA,UACnB,KAAA,EAAO,iBAAiB,KAAQ,GAAA,KAAA,GAAQ,IAAI,KAAM,CAAA,MAAA,CAAO,KAAK,CAAC;AAAA,SACjE;AACA,QAAa,YAAA,EAAA;AAAA;AACf,KACD,CAAA;AACD,IAAA,OAAO,MAAM;AACX,MAAW,QAAA,GAAA,KAAA;AACX,MAAA,IAAI,mBAAqB,EAAA;AACvB,QAAA,mBAAA,CAAoB,WAAY,EAAA;AAAA;AAClC,KACF;AAAA;AAEF,EAAO,OAAA;AAAA,IACL,SAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-ZUNR45SJ.cjs","sourcesContent":["/*\n * Copyright 2024 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 React from \"react\";\nexport const MISSING_PROVIDER_MESSAGE = \"No OsdkProvider2 found. Did you forget to wrap your component tree with <OsdkProvider2>?\";\nfunction fakeClientFn(..._args) {\n throw new Error(MISSING_PROVIDER_MESSAGE);\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\n\n// Proxy that throws a clear error when any method is called, so hooks like\n// useOsdkObjects get \"Did you forget <OsdkProvider2>?\" instead of\n// \"cannot read canonicalizeWhereClause of undefined\".\n// We intercept `get` so every property access returns a throwing function,\n// without needing to enumerate every ObservableClient method.\n// Symbol.toPrimitive and Symbol.toStringTag are accessed by React/devtools\n// during rendering and logging — returning undefined for these avoids\n// spurious throws in contexts unrelated to the user's code.\nconst fakeObservableClient = new Proxy({}, {\n get(_target, prop) {\n if (prop === Symbol.toPrimitive || prop === Symbol.toStringTag) {\n return undefined;\n }\n return (..._args) => {\n throw new Error(MISSING_PROVIDER_MESSAGE);\n };\n }\n});\nexport const OsdkContext2 = /*#__PURE__*/React.createContext({\n client: fakeClient,\n observableClient: fakeObservableClient\n});","/*\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\nexport function makeExternalStore(createObservation, _name, initialValue) {\n let lastResult = initialValue;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n const obs = createObservation({\n next: payload => {\n lastResult = payload;\n notifyUpdate();\n },\n error: error => {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n },\n complete: () => {}\n });\n return () => {\n obs.unsubscribe();\n };\n }\n return {\n subscribe,\n getSnapShot\n };\n}\n\n/**\n * Like makeExternalStore but for async subscription creation.\n *\n * Uses an isActive flag to handle race conditions:\n * If cleanup runs before promise resolves, the stale subscription is\n * immediately unsubscribed when it eventually resolves\n */\nexport function makeExternalStoreAsync(createObservation, _name, initialValue) {\n let lastResult = initialValue;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n let isActive = true;\n let currentSubscription;\n const subscriptionPromise = createObservation({\n next: payload => {\n if (isActive) {\n lastResult = payload;\n notifyUpdate();\n }\n },\n error: error => {\n if (isActive) {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n }\n },\n complete: () => {}\n });\n subscriptionPromise.then(sub => {\n if (isActive) {\n currentSubscription = sub;\n } else {\n sub.unsubscribe();\n }\n }).catch(error => {\n if (isActive) {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n }\n });\n return () => {\n isActive = false;\n if (currentSubscription) {\n currentSubscription.unsubscribe();\n }\n };\n }\n return {\n subscribe,\n getSnapShot\n };\n}"]}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkR4FZ5MUH_cjs = require('./chunk-R4FZ5MUH.cjs');
|
|
4
|
+
var chunk2N32USW5_cjs = require('./chunk-2N32USW5.cjs');
|
|
4
5
|
var React = require('react');
|
|
5
6
|
|
|
6
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -11,20 +12,20 @@ function OsdkProvider({
|
|
|
11
12
|
children,
|
|
12
13
|
client
|
|
13
14
|
}) {
|
|
14
|
-
return /* @__PURE__ */ React__default.default.createElement(
|
|
15
|
+
return /* @__PURE__ */ React__default.default.createElement(chunk2N32USW5_cjs.OsdkContext.Provider, {
|
|
15
16
|
value: {
|
|
16
17
|
client
|
|
17
18
|
}
|
|
18
19
|
}, children);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
Object.defineProperty(exports, "
|
|
22
|
+
Object.defineProperty(exports, "useOsdkMetadata", {
|
|
22
23
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
24
|
+
get: function () { return chunkR4FZ5MUH_cjs.useOsdkMetadata; }
|
|
24
25
|
});
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "useOsdkClient", {
|
|
26
27
|
enumerable: true,
|
|
27
|
-
get: function () { return
|
|
28
|
+
get: function () { return chunk2N32USW5_cjs.useOsdkClient; }
|
|
28
29
|
});
|
|
29
30
|
exports.OsdkProvider = OsdkProvider;
|
|
30
31
|
//# sourceMappingURL=index.cjs.map
|
package/build/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/OsdkProvider.tsx"],"names":["React","OsdkContext"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/OsdkProvider.tsx"],"names":["React","OsdkContext"],"mappings":";;;;;;;;;;AAkBO,SAAS,YAAa,CAAA;AAAA,EAC3B,QAAA;AAAA,EACA;AACF,CAAG,EAAA;AACD,EAAoB,uBAAAA,sBAAA,CAAM,aAAc,CAAAC,6BAAA,CAAY,QAAU,EAAA;AAAA,IAC5D,KAAO,EAAA;AAAA,MACL;AAAA;AACF,KACC,QAAQ,CAAA;AACb","file":"index.cjs","sourcesContent":["/*\n * Copyright 2024 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 React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nexport function OsdkProvider({\n children,\n client\n}) {\n return /*#__PURE__*/React.createElement(OsdkContext.Provider, {\n value: {\n client\n }\n }, children);\n}"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZUNR45SJ_cjs = require('../../chunk-ZUNR45SJ.cjs');
|
|
4
4
|
var foundry_admin = require('@osdk/foundry.admin');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
|
|
@@ -35,12 +35,12 @@ function usePlatformQuery({
|
|
|
35
35
|
getSnapShot
|
|
36
36
|
} = React__default.default.useMemo(() => {
|
|
37
37
|
if (!enabled) {
|
|
38
|
-
return
|
|
38
|
+
return chunkZUNR45SJ_cjs.makeExternalStore(() => ({
|
|
39
39
|
unsubscribe: () => {
|
|
40
40
|
}
|
|
41
41
|
}), process.env.NODE_ENV !== "production" ? `${queryName} Query [DISABLED]` : void 0);
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return chunkZUNR45SJ_cjs.makeExternalStore((observer) => {
|
|
44
44
|
observerRef.current = observer;
|
|
45
45
|
handleQuery();
|
|
46
46
|
return {
|
|
@@ -72,7 +72,7 @@ function useCbacBanner({
|
|
|
72
72
|
}) {
|
|
73
73
|
const {
|
|
74
74
|
client
|
|
75
|
-
} = React__default.default.useContext(
|
|
75
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
76
76
|
const stableMarkingIds = React__default.default.useMemo(() => markingIds, [JSON.stringify(markingIds)]);
|
|
77
77
|
const enabled = stableMarkingIds.length > 0 && externalEnabled;
|
|
78
78
|
const handleQuery = React__default.default.useCallback(() => {
|
|
@@ -110,7 +110,7 @@ function useCbacMarkingRestrictions({
|
|
|
110
110
|
}) {
|
|
111
111
|
const {
|
|
112
112
|
client
|
|
113
|
-
} = React__default.default.useContext(
|
|
113
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
114
114
|
const stableMarkingIds = React__default.default.useMemo(() => markingIds, [JSON.stringify(markingIds)]);
|
|
115
115
|
const enabled = stableMarkingIds.length > 0 && externalEnabled;
|
|
116
116
|
const handleQuery = React__default.default.useCallback(() => {
|
|
@@ -148,7 +148,7 @@ function useCurrentFoundryUser({
|
|
|
148
148
|
} = {}) {
|
|
149
149
|
const {
|
|
150
150
|
client
|
|
151
|
-
} = React__default.default.useContext(
|
|
151
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
152
152
|
const handleQuery = React__default.default.useCallback(() => foundry_admin.Users.getCurrent(client), [client]);
|
|
153
153
|
const query = usePlatformQuery({
|
|
154
154
|
query: handleQuery,
|
|
@@ -168,7 +168,7 @@ function useFoundryUser(userId, {
|
|
|
168
168
|
} = {}) {
|
|
169
169
|
const {
|
|
170
170
|
client
|
|
171
|
-
} = React__default.default.useContext(
|
|
171
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
172
172
|
const handleQuery = React__default.default.useCallback(() => {
|
|
173
173
|
return foundry_admin.Users.get(client, userId, {
|
|
174
174
|
status
|
|
@@ -194,7 +194,7 @@ function useFoundryUsersList({
|
|
|
194
194
|
} = {}) {
|
|
195
195
|
const {
|
|
196
196
|
client
|
|
197
|
-
} = React__default.default.useContext(
|
|
197
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
198
198
|
const handleQuery = React__default.default.useCallback(() => {
|
|
199
199
|
return foundry_admin.Users.list(client, {
|
|
200
200
|
include,
|
|
@@ -220,7 +220,7 @@ function useMarkingCategories({
|
|
|
220
220
|
} = {}) {
|
|
221
221
|
const {
|
|
222
222
|
client
|
|
223
|
-
} = React__default.default.useContext(
|
|
223
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
224
224
|
const handleQuery = React__default.default.useCallback(() => {
|
|
225
225
|
return foundry_admin.MarkingCategories.list(client);
|
|
226
226
|
}, [client]);
|
|
@@ -241,7 +241,7 @@ function useMarkings({
|
|
|
241
241
|
} = {}) {
|
|
242
242
|
const {
|
|
243
243
|
client
|
|
244
|
-
} = React__default.default.useContext(
|
|
244
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
245
245
|
const handleQuery = React__default.default.useCallback(() => {
|
|
246
246
|
return foundry_admin.Markings.list(client);
|
|
247
247
|
}, [client]);
|
|
@@ -263,7 +263,7 @@ function useUserViewMarkings({
|
|
|
263
263
|
} = {}) {
|
|
264
264
|
const {
|
|
265
265
|
client
|
|
266
|
-
} = React__default.default.useContext(
|
|
266
|
+
} = React__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
267
267
|
const handleQuery = React__default.default.useCallback(async () => {
|
|
268
268
|
const resolvedUserId = userId ?? (await foundry_admin.Users.getCurrent(client)).id;
|
|
269
269
|
return foundry_admin.Users.getMarkings(client, resolvedUserId);
|