@osdk/react 0.4.0-beta.2 → 0.4.0-beta.4
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 +30 -0
- package/build/browser/new/OsdkContext2.js +1 -1
- package/build/browser/new/OsdkContext2.js.map +1 -1
- package/build/browser/new/OsdkProvider2.js +5 -3
- package/build/browser/new/OsdkProvider2.js.map +1 -1
- package/build/browser/new/makeExternalStore.js +13 -3
- package/build/browser/new/makeExternalStore.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +3 -3
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkObject.js +5 -4
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/{useOsdkList.js → useOsdkObjects.js} +11 -10
- package/build/browser/new/useOsdkObjects.js.map +1 -0
- package/build/browser/public/experimental.js +1 -1
- package/build/browser/public/experimental.js.map +1 -1
- package/build/cjs/public/experimental.cjs +57 -43
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +33 -32
- package/build/esm/new/OsdkContext2.js +1 -1
- package/build/esm/new/OsdkContext2.js.map +1 -1
- package/build/esm/new/OsdkProvider2.js +5 -3
- package/build/esm/new/OsdkProvider2.js.map +1 -1
- package/build/esm/new/makeExternalStore.js +13 -3
- package/build/esm/new/makeExternalStore.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +3 -3
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkObject.js +5 -4
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/{useOsdkList.js → useOsdkObjects.js} +11 -10
- package/build/esm/new/useOsdkObjects.js.map +1 -0
- package/build/esm/public/experimental.js +1 -1
- package/build/esm/public/experimental.js.map +1 -1
- package/build/types/new/OsdkContext2.d.ts +1 -1
- package/build/types/new/OsdkContext2.d.ts.map +1 -1
- package/build/types/new/OsdkProvider2.d.ts +3 -3
- package/build/types/new/OsdkProvider2.d.ts.map +1 -1
- package/build/types/new/makeExternalStore.d.ts +6 -3
- package/build/types/new/makeExternalStore.d.ts.map +1 -1
- package/build/types/new/useOsdkObject.d.ts +1 -0
- package/build/types/new/useOsdkObject.d.ts.map +1 -1
- package/build/types/new/{useOsdkList.d.ts → useOsdkObjects.d.ts} +7 -7
- package/build/types/new/useOsdkObjects.d.ts.map +1 -0
- package/build/types/public/experimental.d.ts +1 -1
- package/build/types/public/experimental.d.ts.map +1 -1
- package/package.json +3 -3
- package/build/browser/new/useOsdkList.js.map +0 -1
- package/build/esm/new/useOsdkList.js.map +0 -1
- package/build/types/new/useOsdkList.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @osdkkit/react
|
|
2
2
|
|
|
3
|
+
## 0.4.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2517750: Errors should now propagate via useOsdkObject and useOsdkObjects
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [12843cb]
|
|
12
|
+
- Updated dependencies [f82767c]
|
|
13
|
+
- Updated dependencies [2517750]
|
|
14
|
+
- Updated dependencies [2517750]
|
|
15
|
+
- Updated dependencies [2517750]
|
|
16
|
+
- Updated dependencies [2517750]
|
|
17
|
+
- @osdk/client@2.2.0-beta.9
|
|
18
|
+
- @osdk/api@2.2.0-beta.9
|
|
19
|
+
|
|
20
|
+
## 0.4.0-beta.3
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- 2f6206c: Improvements to @osdk/react
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [62e5965]
|
|
29
|
+
- Updated dependencies [2f6206c]
|
|
30
|
+
- @osdk/client@2.2.0-beta.5
|
|
31
|
+
- @osdk/api@2.2.0-beta.5
|
|
32
|
+
|
|
3
33
|
## 0.4.0-beta.2
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OsdkContext2.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext2","createContext","client","
|
|
1
|
+
{"version":3,"file":"OsdkContext2.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext2","createContext","client","observableClient","undefined"],"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\nfunction fakeClientFn(..._args: any[]) {\n throw new Error(\n \"This is not a real client. Did you forget to <OsdkContext.Provider>?\",\n );\n}\n\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn,\n} as Client);\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: undefined!,\n });\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,YAAYA,CAAC,GAAGC,KAAY,EAAE;EACrC,MAAM,IAAIC,KAAK,CACb,sEACF,CAAC;AACH;AAEA,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAACL,YAAY,EAAE;EAC7CM,aAAa,EAAEN;AACjB,CAAW,CAAC;AAWZ,OAAO,MAAMO,YAAgD,gBAAGR,KAAK,CAClES,aAAa,CAAsB;EAClCC,MAAM,EAAEN,UAAU;EAClBO,gBAAgB,EAAEC;AACpB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -14,17 +14,19 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import
|
|
17
|
+
import { createObservableClient } from "@osdk/client/unstable-do-not-use";
|
|
18
|
+
import React, { useMemo } from "react";
|
|
18
19
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
19
20
|
export function OsdkProvider2({
|
|
20
21
|
children,
|
|
21
22
|
client,
|
|
22
|
-
|
|
23
|
+
observableClient
|
|
23
24
|
}) {
|
|
25
|
+
observableClient = useMemo(() => observableClient ?? createObservableClient(client), [client, observableClient]);
|
|
24
26
|
return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {
|
|
25
27
|
value: {
|
|
26
28
|
client,
|
|
27
|
-
|
|
29
|
+
observableClient
|
|
28
30
|
}
|
|
29
31
|
}, children);
|
|
30
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OsdkProvider2.js","names":["React","OsdkContext2","OsdkProvider2","children","client","
|
|
1
|
+
{"version":3,"file":"OsdkProvider2.js","names":["createObservableClient","React","useMemo","OsdkContext2","OsdkProvider2","children","client","observableClient","createElement","Provider","value"],"sources":["OsdkProvider2.tsx"],"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 {\n createObservableClient,\n type ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React, { useMemo } from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ninterface OsdkProviderOptions {\n children: React.ReactNode;\n client: Client;\n observableClient?: ObservableClient;\n}\n\nexport function OsdkProvider2({\n children,\n client,\n observableClient,\n}: OsdkProviderOptions): React.JSX.Element {\n observableClient = useMemo(\n () => observableClient ?? createObservableClient(client),\n [client, observableClient],\n );\n return (\n <OsdkContext2.Provider value={{ client, observableClient }}>\n {children}\n </OsdkContext2.Provider>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,sBAAsB,QAEjB,kCAAkC;AACzC,OAAOC,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,YAAY,QAAQ,mBAAmB;AAQhD,OAAO,SAASC,aAAaA,CAAC;EAC5BC,QAAQ;EACRC,MAAM;EACNC;AACmB,CAAC,EAAqB;EACzCA,gBAAgB,GAAGL,OAAO,CACxB,MAAMK,gBAAgB,IAAIP,sBAAsB,CAACM,MAAM,CAAC,EACxD,CAACA,MAAM,EAAEC,gBAAgB,CAC3B,CAAC;EACD,oBACEN,KAAA,CAAAO,aAAA,CAACL,YAAY,CAACM,QAAQ;IAACC,KAAK,EAAE;MAAEJ,MAAM;MAAEC;IAAiB;EAAE,GACxDF,QACoB,CAAC;AAE5B","ignoreList":[]}
|
|
@@ -21,9 +21,19 @@ export function makeExternalStore(createObservation) {
|
|
|
21
21
|
}
|
|
22
22
|
return {
|
|
23
23
|
subscribe: function subscribe(notifyUpdate) {
|
|
24
|
-
const obs = createObservation(
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const obs = createObservation({
|
|
25
|
+
next: payload => {
|
|
26
|
+
lastResult = payload;
|
|
27
|
+
notifyUpdate();
|
|
28
|
+
},
|
|
29
|
+
error: error => {
|
|
30
|
+
lastResult = {
|
|
31
|
+
...(lastResult ?? {}),
|
|
32
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
33
|
+
};
|
|
34
|
+
notifyUpdate();
|
|
35
|
+
},
|
|
36
|
+
complete: () => {}
|
|
27
37
|
});
|
|
28
38
|
return () => {
|
|
29
39
|
obs.unsubscribe();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","lastResult","getSnapShot","subscribe","notifyUpdate","obs","payload","unsubscribe"],"sources":["makeExternalStore.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 {
|
|
1
|
+
{"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","lastResult","getSnapShot","subscribe","notifyUpdate","obs","next","payload","error","Error","String","complete","unsubscribe"],"sources":["makeExternalStore.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 Observer,\n Unsubscribable,\n} from \"@osdk/client/unstable-do-not-use\";\n\nexport type Snapshot<X> =\n | X\n | (Partial<X> & { error: Error })\n | undefined;\n\nexport function makeExternalStore<X>(\n createObservation: (callback: Observer<X | undefined>) => Unsubscribable,\n name?: string,\n): {\n subscribe: (notifyUpdate: () => void) => () => void;\n getSnapShot: () => Snapshot<X>;\n} {\n let lastResult: Snapshot<X>;\n\n function getSnapShot(): Snapshot<X> {\n return lastResult;\n }\n\n function subscribe(notifyUpdate: () => void) {\n const obs = createObservation({\n next: (payload) => {\n lastResult = payload;\n notifyUpdate();\n },\n error: (error: unknown) => {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error)),\n } as Snapshot<X>;\n notifyUpdate();\n },\n complete: () => {},\n });\n\n return (): void => {\n obs.unsubscribe();\n };\n }\n\n return {\n subscribe,\n getSnapShot,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,OAAO,SAASA,iBAAiBA,CAC/BC,iBAAwE,EAKxE;EACA,IAAIC,UAAuB;EAE3B,SAASC,WAAWA,CAAA,EAAgB;IAClC,OAAOD,UAAU;EACnB;EAuBA,OAAO;IACLE,SAAS,EAtBX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C,MAAMC,GAAG,GAAGL,iBAAiB,CAAC;QAC5BM,IAAI,EAAGC,OAAO,IAAK;UACjBN,UAAU,GAAGM,OAAO;UACpBH,YAAY,CAAC,CAAC;QAChB,CAAC;QACDI,KAAK,EAAGA,KAAc,IAAK;UACzBP,UAAU,GAAG;YACX,IAAIA,UAAU,IAAI,CAAC,CAAC,CAAC;YACrBO,KAAK,EAAEA,KAAK,YAAYC,KAAK,GAAGD,KAAK,GAAG,IAAIC,KAAK,CAACC,MAAM,CAACF,KAAK,CAAC;UACjE,CAAgB;UAChBJ,YAAY,CAAC,CAAC;QAChB,CAAC;QACDO,QAAQ,EAAEA,CAAA,KAAM,CAAC;MACnB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjBN,GAAG,CAACO,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTV;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -19,7 +19,7 @@ import React from "react";
|
|
|
19
19
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
20
|
export function useOsdkAction(actionDef) {
|
|
21
21
|
const {
|
|
22
|
-
|
|
22
|
+
observableClient
|
|
23
23
|
} = React.useContext(OsdkContext2);
|
|
24
24
|
const [error, setError] = React.useState();
|
|
25
25
|
const [data, setData] = React.useState();
|
|
@@ -32,7 +32,7 @@ export function useOsdkAction(actionDef) {
|
|
|
32
32
|
try {
|
|
33
33
|
setPending(true);
|
|
34
34
|
setError(undefined);
|
|
35
|
-
const r = await
|
|
35
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
36
36
|
optimisticUpdate: $optimisticUpdate
|
|
37
37
|
});
|
|
38
38
|
setData(r);
|
|
@@ -50,7 +50,7 @@ export function useOsdkAction(actionDef) {
|
|
|
50
50
|
} finally {
|
|
51
51
|
setPending(false);
|
|
52
52
|
}
|
|
53
|
-
}, [
|
|
53
|
+
}, [observableClient, setError]);
|
|
54
54
|
return {
|
|
55
55
|
applyAction,
|
|
56
56
|
error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","
|
|
1
|
+
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","$optimisticUpdate","args","undefined","r","optimisticUpdate","e","actionValidation","unknown"],"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 { ActionDefinition } 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>,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n\n isPending: boolean;\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<unknown>();\n const [isPending, setPending] = React.useState(false);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q>,\n ) {\n const { $optimisticUpdate, ...args } = hookArgs;\n try {\n setPending(true);\n setError(undefined);\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate,\n });\n setData(r);\n return r;\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, setError]);\n\n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AU,CAAC,KAAK,CAAC;IACnB;EACF,CAAC,EAAE,CAACR,gBAAgB,EAAEG,QAAQ,CAAC,CAAC;EAEhC,OAAO;IAAEM,WAAW;IAAEP,KAAK;IAAEG,IAAI;IAAEE;EAAU,CAAC;AAChD","ignoreList":[]}
|
|
@@ -34,7 +34,7 @@ import { OsdkContext2 } from "./OsdkContext2.js";
|
|
|
34
34
|
*/
|
|
35
35
|
export function useOsdkObject(...args) {
|
|
36
36
|
const {
|
|
37
|
-
|
|
37
|
+
observableClient
|
|
38
38
|
} = React.useContext(OsdkContext2);
|
|
39
39
|
|
|
40
40
|
// TODO: Figure out what the correct default behavior is for the various scenarios
|
|
@@ -44,14 +44,15 @@ export function useOsdkObject(...args) {
|
|
|
44
44
|
const {
|
|
45
45
|
subscribe,
|
|
46
46
|
getSnapShot
|
|
47
|
-
} = React.useMemo(() => makeExternalStore(
|
|
47
|
+
} = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {
|
|
48
48
|
mode
|
|
49
|
-
},
|
|
49
|
+
}, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);
|
|
50
50
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
51
51
|
return {
|
|
52
52
|
object: payload?.object,
|
|
53
53
|
isLoading: payload?.status === "loading",
|
|
54
|
-
isOptimistic: payload?.isOptimistic
|
|
54
|
+
isOptimistic: !!payload?.isOptimistic,
|
|
55
|
+
error: payload && "error" in payload ? payload.error : undefined,
|
|
55
56
|
forceUpdate: () => {
|
|
56
57
|
throw "not implemented";
|
|
57
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","
|
|
1
|
+
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","mode","length","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","observer","observeObject","payload","useSyncExternalStore","object","isLoading","status","isOptimistic","error","forceUpdate"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectTypeDefinition, Osdk, PrimaryKeyType } from \"@osdk/api\";\nimport type { ObserveObjectArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args: [obj: Osdk.Instance<Q>] | [type: Q, primaryKey: PrimaryKeyType<Q>]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n ),\n [observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n },\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,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAehD;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3B,GAAGC,IAAwE,EACnD;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA,MAAMK,IAAI,GAAGH,IAAI,CAACI,MAAM,KAAK,CAAC,GAAG,SAAS,GAAGC,SAAS;EACtD,MAAMC,UAAU,GAAGN,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACO,WAAW,GAAGP,IAAI,CAAC,CAAC,CAAC,CAACQ,OAAO;EAC5E,MAAMC,UAAU,GAAGT,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACU,WAAW,GAAGV,IAAI,CAAC,CAAC,CAAC;EAEpE,MAAM;IAAEW,SAAS;IAAEC;EAAY,CAAC,GAAGhB,KAAK,CAACiB,OAAO,CAC9C,MACEhB,iBAAiB,CACdiB,QAAQ,IACPb,gBAAgB,CAACc,aAAa,CAC5BT,UAAU,EACVG,UAAU,EACV;IACEN;EACF,CAAC,EACDW,QACF,CAAC,EACH,UAAUR,UAAU,IAAIG,UAAU,EACpC,CAAC,EACH,CAACR,gBAAgB,EAAEK,UAAU,EAAEG,UAAU,EAAEN,IAAI,CACjD,CAAC;EAED,MAAMa,OAAO,GAAGpB,KAAK,CAACqB,oBAAoB,CAACN,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAO;IACLM,MAAM,EAAEF,OAAO,EAAEE,MAAsC;IACvDC,SAAS,EAAEH,OAAO,EAAEI,MAAM,KAAK,SAAS;IACxCC,YAAY,EAAE,CAAC,CAACL,OAAO,EAAEK,YAAY;IACrCC,KAAK,EAAEN,OAAO,IAAI,OAAO,IAAIA,OAAO,GAAGA,OAAO,CAACM,KAAK,GAAGjB,SAAS;IAChEkB,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,iBAAiB;IACzB;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -17,40 +17,41 @@
|
|
|
17
17
|
import React from "react";
|
|
18
18
|
import { makeExternalStore } from "./makeExternalStore.js";
|
|
19
19
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
|
-
export function
|
|
20
|
+
export function useOsdkObjects(type, {
|
|
21
21
|
pageSize,
|
|
22
22
|
orderBy,
|
|
23
23
|
dedupeIntervalMs,
|
|
24
|
-
where,
|
|
24
|
+
where = {},
|
|
25
25
|
streamUpdates
|
|
26
|
-
}) {
|
|
26
|
+
} = {}) {
|
|
27
27
|
const {
|
|
28
|
-
|
|
28
|
+
observableClient
|
|
29
29
|
} = React.useContext(OsdkContext2);
|
|
30
30
|
|
|
31
31
|
/* We want the canonical where clause so that the use of `React.useMemo`
|
|
32
32
|
is stable. No real added cost as we canonicalize internal to
|
|
33
33
|
the ObservableClient anyway.
|
|
34
34
|
*/
|
|
35
|
-
const canonWhere =
|
|
35
|
+
const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
|
|
36
36
|
const {
|
|
37
37
|
subscribe,
|
|
38
38
|
getSnapShot
|
|
39
|
-
} = React.useMemo(() => makeExternalStore(
|
|
40
|
-
|
|
39
|
+
} = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({
|
|
40
|
+
type,
|
|
41
41
|
where: canonWhere,
|
|
42
42
|
dedupeInterval: dedupeIntervalMs ?? 2_000,
|
|
43
43
|
pageSize,
|
|
44
44
|
orderBy,
|
|
45
45
|
streamUpdates
|
|
46
|
-
},
|
|
46
|
+
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);
|
|
47
47
|
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
48
|
+
// TODO: we need to expose the error in the result
|
|
48
49
|
return {
|
|
49
50
|
fetchMore: listPayload?.fetchMore,
|
|
51
|
+
error: listPayload && "error" in listPayload ? listPayload?.error : undefined,
|
|
50
52
|
data: listPayload?.resolvedList,
|
|
51
53
|
isLoading: listPayload?.status === "loading",
|
|
52
|
-
error: undefined,
|
|
53
54
|
isOptimistic: listPayload?.isOptimistic ?? false
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
|
-
//# sourceMappingURL=
|
|
57
|
+
//# sourceMappingURL=useOsdkObjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","observer","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","error","undefined","data","resolvedList","isLoading","status","isOptimistic"],"sources":["useOsdkObjects.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 InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n\n // FIXME populate error!\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n>(\n type: Q,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<Q> = {},\n): UseOsdkListResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, type, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload\n ? listPayload?.error\n : undefined,\n data: listPayload?.resolvedList as Osdk.Instance<Q>[],\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA6FhD,OAAO,SAASC,cAAcA,CAG5BC,IAAO,EACP;EACEC,QAAQ;EACRC,OAAO;EACPC,gBAAgB;EAChBC,KAAK,GAAG,CAAC,CAAC;EACVC;AACwB,CAAC,GAAG,CAAC,CAAC,EACV;EACtB,MAAM;IAAEC;EAAiB,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;;EAE3D;AACF;AACA;AACA;EACE,MAAMU,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAACL,KAAK,IAAI,CAAC,CAAC,CAAC;EAExE,MAAM;IAAEM,SAAS;IAAEC;EAAY,CAAC,GAAGf,KAAK,CAACgB,OAAO,CAC9C,MACEf,iBAAiB,CACdgB,QAAQ,IACPP,gBAAgB,CAACQ,WAAW,CAAC;IAC3Bd,IAAI;IACJI,KAAK,EAAEI,UAAU;IACjBO,cAAc,EAAEZ,gBAAgB,IAAI,KAAK;IACzCF,QAAQ;IACRC,OAAO;IACPG;EACF,CAAC,EAAEQ,QAAQ,CAAC,EACdG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,QAAQlB,IAAI,CAACmB,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,EAAE,GACpD,KAAK,CACX,CAAC,EACH,CAACF,gBAAgB,EAAEN,IAAI,EAAEQ,UAAU,EAAEL,gBAAgB,CACvD,CAAC;EAED,MAAMmB,WAAW,GAAG1B,KAAK,CAAC2B,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EACtE;EACA,OAAO;IACLa,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,KAAK,EAAEH,WAAW,IAAI,OAAO,IAAIA,WAAW,GACxCA,WAAW,EAAEG,KAAK,GAClBC,SAAS;IACbC,IAAI,EAAEL,WAAW,EAAEM,YAAkC;IACrDC,SAAS,EAAEP,WAAW,EAAEQ,MAAM,KAAK,SAAS;IAC5CC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
export { OsdkProvider2 } from "../new/OsdkProvider2.js";
|
|
18
18
|
export { useOsdkAction } from "../new/useOsdkAction.js";
|
|
19
|
-
export { useOsdkList } from "../new/useOsdkList.js";
|
|
20
19
|
export { useOsdkObject } from "../new/useOsdkObject.js";
|
|
20
|
+
export { useOsdkObjects } from "../new/useOsdkObjects.js";
|
|
21
21
|
export { useOsdkClient } from "../useOsdkClient.js";
|
|
22
22
|
//# sourceMappingURL=experimental.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"experimental.js","names":["OsdkProvider2","useOsdkAction","
|
|
1
|
+
{"version":3,"file":"experimental.js","names":["OsdkProvider2","useOsdkAction","useOsdkObject","useOsdkObjects","useOsdkClient"],"sources":["experimental.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\nexport { OsdkProvider2 } from \"../new/OsdkProvider2.js\";\nexport { useOsdkAction } from \"../new/useOsdkAction.js\";\nexport { useOsdkObject } from \"../new/useOsdkObject.js\";\nexport { useOsdkObjects } from \"../new/useOsdkObjects.js\";\nexport { useOsdkClient } from \"../useOsdkClient.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,yBAAyB;AACvD,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,aAAa,QAAQ,qBAAqB","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunk2N32USW5_cjs = require('../chunk-2N32USW5.cjs');
|
|
4
|
+
var unstableDoNotUse = require('@osdk/client/unstable-do-not-use');
|
|
4
5
|
var React3 = require('react');
|
|
5
6
|
var client = require('@osdk/client');
|
|
6
7
|
|
|
@@ -16,25 +17,26 @@ var fakeClient = Object.assign(fakeClientFn, {
|
|
|
16
17
|
});
|
|
17
18
|
var OsdkContext2 = /* @__PURE__ */ React3__default.default.createContext({
|
|
18
19
|
client: fakeClient,
|
|
19
|
-
|
|
20
|
+
observableClient: undefined
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
// src/new/OsdkProvider2.tsx
|
|
23
24
|
function OsdkProvider2({
|
|
24
25
|
children,
|
|
25
26
|
client,
|
|
26
|
-
|
|
27
|
+
observableClient
|
|
27
28
|
}) {
|
|
29
|
+
observableClient = React3.useMemo(() => observableClient ?? unstableDoNotUse.createObservableClient(client), [client, observableClient]);
|
|
28
30
|
return /* @__PURE__ */ React3__default.default.createElement(OsdkContext2.Provider, {
|
|
29
31
|
value: {
|
|
30
32
|
client,
|
|
31
|
-
|
|
33
|
+
observableClient
|
|
32
34
|
}
|
|
33
35
|
}, children);
|
|
34
36
|
}
|
|
35
37
|
function useOsdkAction(actionDef) {
|
|
36
38
|
const {
|
|
37
|
-
|
|
39
|
+
observableClient
|
|
38
40
|
} = React3__default.default.useContext(OsdkContext2);
|
|
39
41
|
const [error, setError] = React3__default.default.useState();
|
|
40
42
|
const [data, setData] = React3__default.default.useState();
|
|
@@ -47,7 +49,7 @@ function useOsdkAction(actionDef) {
|
|
|
47
49
|
try {
|
|
48
50
|
setPending(true);
|
|
49
51
|
setError(void 0);
|
|
50
|
-
const r = await
|
|
52
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
51
53
|
optimisticUpdate: $optimisticUpdate
|
|
52
54
|
});
|
|
53
55
|
setData(r);
|
|
@@ -65,7 +67,7 @@ function useOsdkAction(actionDef) {
|
|
|
65
67
|
} finally {
|
|
66
68
|
setPending(false);
|
|
67
69
|
}
|
|
68
|
-
}, [
|
|
70
|
+
}, [observableClient, setError]);
|
|
69
71
|
return {
|
|
70
72
|
applyAction,
|
|
71
73
|
error,
|
|
@@ -81,9 +83,20 @@ function makeExternalStore(createObservation, name) {
|
|
|
81
83
|
return lastResult;
|
|
82
84
|
}
|
|
83
85
|
function subscribe(notifyUpdate) {
|
|
84
|
-
const obs = createObservation(
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
const obs = createObservation({
|
|
87
|
+
next: (payload) => {
|
|
88
|
+
lastResult = payload;
|
|
89
|
+
notifyUpdate();
|
|
90
|
+
},
|
|
91
|
+
error: (error) => {
|
|
92
|
+
lastResult = {
|
|
93
|
+
...lastResult ?? {},
|
|
94
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
95
|
+
};
|
|
96
|
+
notifyUpdate();
|
|
97
|
+
},
|
|
98
|
+
complete: () => {
|
|
99
|
+
}
|
|
87
100
|
});
|
|
88
101
|
return () => {
|
|
89
102
|
obs.unsubscribe();
|
|
@@ -95,61 +108,62 @@ function makeExternalStore(createObservation, name) {
|
|
|
95
108
|
};
|
|
96
109
|
}
|
|
97
110
|
|
|
98
|
-
// src/new/
|
|
99
|
-
function
|
|
111
|
+
// src/new/useOsdkObject.ts
|
|
112
|
+
function useOsdkObject(...args) {
|
|
113
|
+
const {
|
|
114
|
+
observableClient
|
|
115
|
+
} = React3__default.default.useContext(OsdkContext2);
|
|
116
|
+
const mode = args.length === 1 ? "offline" : undefined;
|
|
117
|
+
const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
|
|
118
|
+
const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];
|
|
119
|
+
const {
|
|
120
|
+
subscribe,
|
|
121
|
+
getSnapShot
|
|
122
|
+
} = React3__default.default.useMemo(() => makeExternalStore((observer) => observableClient.observeObject(objectType, primaryKey, {
|
|
123
|
+
mode
|
|
124
|
+
}, observer)), [observableClient, objectType, primaryKey, mode]);
|
|
125
|
+
const payload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
126
|
+
return {
|
|
127
|
+
object: payload?.object,
|
|
128
|
+
isLoading: payload?.status === "loading",
|
|
129
|
+
isOptimistic: !!payload?.isOptimistic,
|
|
130
|
+
error: payload && "error" in payload ? payload.error : undefined,
|
|
131
|
+
forceUpdate: () => {
|
|
132
|
+
throw "not implemented";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function useOsdkObjects(type, {
|
|
100
137
|
pageSize,
|
|
101
138
|
orderBy,
|
|
102
139
|
dedupeIntervalMs,
|
|
103
|
-
where,
|
|
140
|
+
where = {},
|
|
104
141
|
streamUpdates
|
|
105
|
-
}) {
|
|
142
|
+
} = {}) {
|
|
106
143
|
const {
|
|
107
|
-
|
|
144
|
+
observableClient
|
|
108
145
|
} = React3__default.default.useContext(OsdkContext2);
|
|
109
|
-
const canonWhere =
|
|
146
|
+
const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
|
|
110
147
|
const {
|
|
111
148
|
subscribe,
|
|
112
149
|
getSnapShot
|
|
113
|
-
} = React3__default.default.useMemo(() => makeExternalStore((
|
|
114
|
-
|
|
150
|
+
} = React3__default.default.useMemo(() => makeExternalStore((observer) => observableClient.observeList({
|
|
151
|
+
type,
|
|
115
152
|
where: canonWhere,
|
|
116
153
|
dedupeInterval: dedupeIntervalMs ?? 2e3,
|
|
117
154
|
pageSize,
|
|
118
155
|
orderBy,
|
|
119
156
|
streamUpdates
|
|
120
|
-
},
|
|
157
|
+
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : undefined), [observableClient, type, canonWhere, dedupeIntervalMs]);
|
|
121
158
|
const listPayload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
122
159
|
return {
|
|
123
160
|
fetchMore: listPayload?.fetchMore,
|
|
161
|
+
error: listPayload && "error" in listPayload ? listPayload?.error : undefined,
|
|
124
162
|
data: listPayload?.resolvedList,
|
|
125
163
|
isLoading: listPayload?.status === "loading",
|
|
126
|
-
error: undefined,
|
|
127
164
|
isOptimistic: listPayload?.isOptimistic ?? false
|
|
128
165
|
};
|
|
129
166
|
}
|
|
130
|
-
function useOsdkObject(...args) {
|
|
131
|
-
const {
|
|
132
|
-
store
|
|
133
|
-
} = React3__default.default.useContext(OsdkContext2);
|
|
134
|
-
const mode = args.length === 1 ? "offline" : undefined;
|
|
135
|
-
const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
|
|
136
|
-
const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];
|
|
137
|
-
const {
|
|
138
|
-
subscribe,
|
|
139
|
-
getSnapShot
|
|
140
|
-
} = React3__default.default.useMemo(() => makeExternalStore((payload2) => store.observeObject(objectType, primaryKey, {
|
|
141
|
-
mode
|
|
142
|
-
}, payload2)), [store, objectType, primaryKey, mode]);
|
|
143
|
-
const payload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
144
|
-
return {
|
|
145
|
-
object: payload?.object,
|
|
146
|
-
isLoading: payload?.status === "loading",
|
|
147
|
-
isOptimistic: payload?.isOptimistic ?? false,
|
|
148
|
-
forceUpdate: () => {
|
|
149
|
-
throw "not implemented";
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
167
|
|
|
154
168
|
Object.defineProperty(exports, "useOsdkClient", {
|
|
155
169
|
enumerable: true,
|
|
@@ -157,7 +171,7 @@ Object.defineProperty(exports, "useOsdkClient", {
|
|
|
157
171
|
});
|
|
158
172
|
exports.OsdkProvider2 = OsdkProvider2;
|
|
159
173
|
exports.useOsdkAction = useOsdkAction;
|
|
160
|
-
exports.useOsdkList = useOsdkList;
|
|
161
174
|
exports.useOsdkObject = useOsdkObject;
|
|
175
|
+
exports.useOsdkObjects = useOsdkObjects;
|
|
162
176
|
//# sourceMappingURL=experimental.cjs.map
|
|
163
177
|
//# sourceMappingURL=experimental.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/useOsdkAction.ts","../../../src/new/makeExternalStore.ts","../../../src/new/useOsdkList.ts","../../../src/new/useOsdkObject.ts"],"names":["React","applyAction","ActionValidationError","payload"],"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;AACM,IAAM,YAAA,2CAAkC,aAAc,CAAA;AAAA,EAC3D,MAAQ,EAAA,UAAA;AAAA,EACR,KAAO,EAAA;AACT,CAAC,CAAA;;;ACRM,SAAS,aAAc,CAAA;AAAA,EAC5B,QAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAG,EAAA;AACD,EAAA,uBAAoBA,uBAAAA,CAAM,aAAc,CAAA,YAAA,CAAa,QAAU,EA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M,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AACjE,EAAO,OAAA;AAAA,IACL,QAAQ,OAAS,EAAA,MAAA;AAAA,IACjB,SAAA,EAAW,SAAS,MAAW,KAAA,SAAA;AAAA,IAC/B,YAAA,EAAc,SAAS,YAAgB,IAAA,KAAA;AAAA,IACvC,aAAa,MAAM;AACjB,MAAM,MAAA,iBAAA;AAAA;AACR,GACF;AACF","file":"experimental.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 OsdkContext2 = /*#__PURE__*/React.createContext({\n client: fakeClient,\n store: undefined\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 { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n store\n}) {\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n store\n }\n }, children);\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\nimport { ActionValidationError } from \"@osdk/client\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkAction(actionDef) {\n const {\n store\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const [isPending, setPending] = React.useState(false);\n const applyAction = React.useCallback(async function applyAction(hookArgs) {\n const {\n $optimisticUpdate,\n ...args\n } = hookArgs;\n try {\n setPending(true);\n setError(undefined);\n const r = await store.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate\n });\n setData(r);\n return r;\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n } finally {\n setPending(false);\n }\n }, [store, setError]);\n return {\n applyAction,\n error,\n data,\n isPending\n };\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) {\n let lastResult;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n const obs = createObservation(payload => {\n lastResult = payload;\n notifyUpdate();\n });\n return () => {\n obs.unsubscribe();\n };\n }\n return {\n subscribe,\n getSnapShot\n };\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\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkList(objectType, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where,\n streamUpdates\n}) {\n const {\n store\n } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = store.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(x => store.observeList({\n objectType,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, x), process.env.NODE_ENV !== \"production\" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : void 0), [store, objectType, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false\n };\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\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\n\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\n\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject(...args) {\n const {\n store\n } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(payload => store.observeObject(objectType, primaryKey, {\n mode\n }, payload), `object ${objectType} ${primaryKey}`), [store, objectType, primaryKey, mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n object: payload?.object,\n isLoading: payload?.status === \"loading\",\n isOptimistic: payload?.isOptimistic ?? false,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/useOsdkAction.ts","../../../src/new/makeExternalStore.ts","../../../src/new/useOsdkObject.ts","../../../src/new/useOsdkObjects.ts"],"names":["useMemo","createObservableClient","React","applyAction","ActionValidationError"],"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;AACM,I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,EAAC;AAAA,EACT;AACF,CAAA,GAAI,EAAI,EAAA;AACN,EAAM,MAAA;AAAA,IACJ;AAAA,GACF,GAAIA,uBAAM,CAAA,UAAA,CAAW,YAAY,CAAA;AAMjC,EAAA,MAAM,UAAa,GAAA,gBAAA,CAAiB,uBAAwB,CAAA,KAAA,IAAS,EAAE,CAAA;AACvE,EAAM,MAAA;AAAA,IACJ,SAAA;AAAA,IACA;AAAA,MACEA,uBAAM,CAAA,OAAA,CAAQ,MAAM,iBAAkB,CAAA,CAAA,QAAA,KAAY,iBAAiB,WAAY,CAAA;AAAA,IACjF,IAAA;AAAA,IACA,KAAO,EAAA,UAAA;AAAA,IACP,gBAAgB,gBAAoB,IAAA,GAAA;AAAA,IACpC,QAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAAG,QAAQ,CAAG,EAAA,OAAA,CAAQ,IAAI,QAAa,KAAA,YAAA,GAAe,CAAQ,KAAA,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA,EAAI,KAAK,SAAU,CAAA,UAAU,CAAC,CAAA,CAAA,GAAK,SAAM,CAAA,EAAG,CAAC,gBAAkB,EAAA,IAAA,EAAM,UAAY,EAAA,gBAAgB,CAAC,CAAA;AAC5K,EAAA,MAAM,WAAcA,GAAAA,uBAAAA,CAAM,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AAErE,EAAO,OAAA;AAAA,IACL,WAAW,WAAa,EAAA,SAAA;AAAA,IACxB,KAAO,EAAA,WAAA,IAAe,OAAW,IAAA,WAAA,GAAc,aAAa,KAAQ,GAAA,SAAA;AAAA,IACpE,MAAM,WAAa,EAAA,YAAA;AAAA,IACnB,SAAA,EAAW,aAAa,MAAW,KAAA,SAAA;AAAA,IACnC,YAAA,EAAc,aAAa,YAAgB,IAAA;AAAA,GAC7C;AACF","file":"experimental.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 OsdkContext2 = /*#__PURE__*/React.createContext({\n client: fakeClient,\n observableClient: undefined\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 { createObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React, { useMemo } from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n observableClient\n}) {\n observableClient = useMemo(() => observableClient ?? createObservableClient(client), [client, observableClient]);\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n observableClient\n }\n }, children);\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\nimport { ActionValidationError } from \"@osdk/client\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkAction(actionDef) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const [isPending, setPending] = React.useState(false);\n const applyAction = React.useCallback(async function applyAction(hookArgs) {\n const {\n $optimisticUpdate,\n ...args\n } = hookArgs;\n try {\n setPending(true);\n setError(undefined);\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate\n });\n setData(r);\n return r;\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, setError]);\n return {\n applyAction,\n error,\n data,\n isPending\n };\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) {\n let lastResult;\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 * 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 React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\n\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\n\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject(...args) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {\n mode\n }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n object: payload?.object,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\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\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkObjects(type, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates\n} = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, observer), process.env.NODE_ENV !== \"production\" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload ? listPayload?.error : undefined,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false\n };\n}"]}
|