@osdk/react 0.4.0-beta.1 → 0.4.0-beta.3
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 +25 -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 +1 -5
- package/build/browser/new/makeExternalStore.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +17 -5
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkObject.js +3 -3
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/{useOsdkList.js → useOsdkObjects.js} +24 -8
- 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 -35
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +79 -34
- 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 +1 -5
- package/build/esm/new/makeExternalStore.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +17 -5
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkObject.js +3 -3
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/{useOsdkList.js → useOsdkObjects.js} +24 -8
- 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/useOsdkAction.d.ts +4 -1
- package/build/types/new/useOsdkAction.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +65 -0
- 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 +5 -5
- 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 +0 -26
- package/build/types/new/useOsdkList.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @osdkkit/react
|
|
2
2
|
|
|
3
|
+
## 0.4.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2f6206c: Improvements to @osdk/react
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [62e5965]
|
|
12
|
+
- Updated dependencies [2f6206c]
|
|
13
|
+
- @osdk/client@2.2.0-beta.5
|
|
14
|
+
- @osdk/api@2.2.0-beta.5
|
|
15
|
+
|
|
16
|
+
## 0.4.0-beta.2
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- fe0cc43: Experimental react changes
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [fe0cc43]
|
|
25
|
+
- @osdk/client@2.2.0-beta.4
|
|
26
|
+
- @osdk/api@2.2.0-beta.4
|
|
27
|
+
|
|
3
28
|
## 0.3.0-beta.3
|
|
4
29
|
|
|
5
30
|
### 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":[]}
|
|
@@ -14,22 +14,18 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
export function makeExternalStore(createObservation
|
|
17
|
+
export function makeExternalStore(createObservation) {
|
|
18
18
|
let lastResult;
|
|
19
19
|
function getSnapShot() {
|
|
20
20
|
return lastResult;
|
|
21
21
|
}
|
|
22
22
|
return {
|
|
23
23
|
subscribe: function subscribe(notifyUpdate) {
|
|
24
|
-
// eslint-disable-next-line no-console
|
|
25
|
-
console.log("Subscribing", name);
|
|
26
24
|
const obs = createObservation(payload => {
|
|
27
25
|
lastResult = payload;
|
|
28
26
|
notifyUpdate();
|
|
29
27
|
});
|
|
30
28
|
return () => {
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
console.log("Unsubscribing", name);
|
|
33
29
|
obs.unsubscribe();
|
|
34
30
|
};
|
|
35
31
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","
|
|
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 { Unsubscribable } from \"@osdk/client/unstable-do-not-use\";\n\nexport function makeExternalStore<X>(\n createObservation: (callback: (x: X | undefined) => void) => Unsubscribable,\n name?: string,\n): {\n subscribe: (notifyUpdate: () => void) => () => void;\n getSnapShot: () => X | undefined;\n} {\n let lastResult: X | undefined;\n\n function getSnapShot(): X | undefined {\n return lastResult;\n }\n\n function subscribe(notifyUpdate: () => void) {\n const obs = createObservation((payload) => {\n lastResult = payload;\n notifyUpdate();\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;;AAIA,OAAO,SAASA,iBAAiBA,CAC/BC,iBAA2E,EAK3E;EACA,IAAIC,UAAyB;EAE7B,SAASC,WAAWA,CAAA,EAAkB;IACpC,OAAOD,UAAU;EACnB;EAaA,OAAO;IACLE,SAAS,EAZX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C,MAAMC,GAAG,GAAGL,iBAAiB,CAAEM,OAAO,IAAK;QACzCL,UAAU,GAAGK,OAAO;QACpBF,YAAY,CAAC,CAAC;MAChB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjBC,GAAG,CAACE,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTL;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -19,13 +19,22 @@ 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();
|
|
26
|
-
const
|
|
26
|
+
const [isPending, setPending] = React.useState(false);
|
|
27
|
+
const applyAction = React.useCallback(async function (hookArgs) {
|
|
28
|
+
const {
|
|
29
|
+
$optimisticUpdate,
|
|
30
|
+
...args
|
|
31
|
+
} = hookArgs;
|
|
27
32
|
try {
|
|
28
|
-
|
|
33
|
+
setPending(true);
|
|
34
|
+
setError(undefined);
|
|
35
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
36
|
+
optimisticUpdate: $optimisticUpdate
|
|
37
|
+
});
|
|
29
38
|
setData(r);
|
|
30
39
|
return r;
|
|
31
40
|
} catch (e) {
|
|
@@ -38,12 +47,15 @@ export function useOsdkAction(actionDef) {
|
|
|
38
47
|
unknown: e
|
|
39
48
|
});
|
|
40
49
|
}
|
|
50
|
+
} finally {
|
|
51
|
+
setPending(false);
|
|
41
52
|
}
|
|
42
|
-
}, [
|
|
53
|
+
}, [observableClient, setError]);
|
|
43
54
|
return {
|
|
44
55
|
applyAction,
|
|
45
56
|
error,
|
|
46
|
-
data
|
|
57
|
+
data,
|
|
58
|
+
isPending
|
|
47
59
|
};
|
|
48
60
|
}
|
|
49
61
|
//# sourceMappingURL=useOsdkAction.js.map
|
|
@@ -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 return { applyAction, error, data, isPending };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,qBAAqB,QAAQ,cAAc;AAKpD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,mBAAmB;AAyBhD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAC3D,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAkC,CAAC;EAC3E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAU,CAAC;EACjD,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAGZ,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EAErD,MAAMK,WAAW,GAAGb,KAAK,CAACc,WAAW,CAAC,gBACpCC,QAA8B,EAC9B;IACA,MAAM;MAAEC,iBAAiB;MAAE,GAAGC;IAAK,CAAC,GAAGF,QAAQ;IAC/C,IAAI;MACFH,UAAU,CAAC,IAAI,CAAC;MAChBL,QAAQ,CAACW,SAAS,CAAC;MACnB,MAAMC,CAAC,GAAG,MAAMf,gBAAgB,CAACS,WAAW,CAACV,SAAS,EAAEc,IAAI,EAAE;QAC5DG,gBAAgB,EAAEJ;MACpB,CAAC,CAAC;MACFN,OAAO,CAACS,CAAC,CAAC;MACV,OAAOA,CAAC;IACV,CAAC,CAAC,OAAOE,CAAC,EAAE;MACV,IAAIA,CAAC,YAAYtB,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACPe,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACLd,QAAQ,CAAC;UAAEgB,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;IACF,CAAC,SAAS;MACRT,UAAU,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,9 +44,9 @@ export function useOsdkObject(...args) {
|
|
|
44
44
|
const {
|
|
45
45
|
subscribe,
|
|
46
46
|
getSnapShot
|
|
47
|
-
} = React.useMemo(() => makeExternalStore(payload =>
|
|
47
|
+
} = React.useMemo(() => makeExternalStore(payload => observableClient.observeObject(objectType, primaryKey, {
|
|
48
48
|
mode
|
|
49
|
-
}, payload), `object ${objectType} ${primaryKey}`), [
|
|
49
|
+
}, payload), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);
|
|
50
50
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
51
51
|
return {
|
|
52
52
|
object: payload?.object,
|
|
@@ -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","payload","observeObject","useSyncExternalStore","object","isLoading","status","isOptimistic","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 { ObjectPayload } 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 /**\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<ObjectPayload>(\n (payload) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n payload,\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 ?? false,\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;;AAahD;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,OAAO,IACNb,gBAAgB,CAACc,aAAa,CAC5BT,UAAU,EACVG,UAAU,EACV;IACEN;EACF,CAAC,EACDW,OACF,CAAC,EACH,UAAUR,UAAU,IAAIG,UAAU,EACpC,CAAC,EACH,CAACR,gBAAgB,EAAEK,UAAU,EAAEG,UAAU,EAAEN,IAAI,CACjD,CAAC;EAED,MAAMW,OAAO,GAAGlB,KAAK,CAACoB,oBAAoB,CAACL,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAO;IACLK,MAAM,EAAEH,OAAO,EAAEG,MAAsC;IACvDC,SAAS,EAAEJ,OAAO,EAAEK,MAAM,KAAK,SAAS;IACxCC,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,iBAAiB;IACzB;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -17,24 +17,40 @@
|
|
|
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(objectType, {
|
|
21
|
+
pageSize,
|
|
22
|
+
orderBy,
|
|
23
|
+
dedupeIntervalMs,
|
|
24
|
+
where = {},
|
|
25
|
+
streamUpdates
|
|
26
|
+
} = {}) {
|
|
21
27
|
const {
|
|
22
|
-
|
|
28
|
+
observableClient
|
|
23
29
|
} = React.useContext(OsdkContext2);
|
|
24
|
-
|
|
30
|
+
|
|
31
|
+
/* We want the canonical where clause so that the use of `React.useMemo`
|
|
32
|
+
is stable. No real added cost as we canonicalize internal to
|
|
33
|
+
the ObservableClient anyway.
|
|
34
|
+
*/
|
|
35
|
+
const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
|
|
25
36
|
const {
|
|
26
37
|
subscribe,
|
|
27
38
|
getSnapShot
|
|
28
|
-
} = React.useMemo(() => makeExternalStore(x =>
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
} = React.useMemo(() => makeExternalStore(x => observableClient.observeList({
|
|
40
|
+
objectType,
|
|
41
|
+
where: canonWhere,
|
|
42
|
+
dedupeInterval: dedupeIntervalMs ?? 2_000,
|
|
43
|
+
pageSize,
|
|
44
|
+
orderBy,
|
|
45
|
+
streamUpdates
|
|
46
|
+
}, x), process.env.NODE_ENV !== "production" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, objectType, canonWhere, dedupeIntervalMs]);
|
|
31
47
|
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
48
|
+
// TODO: we need to expose the error in the result
|
|
32
49
|
return {
|
|
33
50
|
fetchMore: listPayload?.fetchMore,
|
|
34
51
|
data: listPayload?.resolvedList,
|
|
35
52
|
isLoading: listPayload?.status === "loading",
|
|
36
|
-
error: undefined,
|
|
37
53
|
isOptimistic: listPayload?.isOptimistic ?? false
|
|
38
54
|
};
|
|
39
55
|
}
|
|
40
|
-
//# sourceMappingURL=
|
|
56
|
+
//# sourceMappingURL=useOsdkObjects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","objectType","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","x","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","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 ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ListPayload } 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<T extends ObjectTypeDefinition> {\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<T extends ObjectTypeDefinition> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n\n // FIXME populate error!\n // 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<T extends ObjectTypeDefinition>(\n objectType: T,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<T> = {},\n): UseOsdkListResult<T> {\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<ListPayload>(\n (x) =>\n observableClient.observeList({\n objectType,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, x),\n process.env.NODE_ENV !== \"production\"\n ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, objectType, 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 data: listPayload?.resolvedList as Osdk.Instance<T>[],\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;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyFhD,OAAO,SAASC,cAAcA,CAC5BC,UAAa,EACb;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,CAAC,IACAP,gBAAgB,CAACQ,WAAW,CAAC;IAC3Bd,UAAU;IACVI,KAAK,EAAEI,UAAU;IACjBO,cAAc,EAAEZ,gBAAgB,IAAI,KAAK;IACzCF,QAAQ;IACRC,OAAO;IACPG;EACF,CAAC,EAAEQ,CAAC,CAAC,EACPG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,QAAQlB,UAAU,CAACmB,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,EAAE,GAC1D,KAAK,CACX,CAAC,EACH,CAACF,gBAAgB,EAAEN,UAAU,EAAEQ,UAAU,EAAEL,gBAAgB,CAC7D,CAAC;EAED,MAAMmB,WAAW,GAAG1B,KAAK,CAAC2B,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EACtE;EACA,OAAO;IACLa,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,IAAI,EAAEH,WAAW,EAAEI,YAAkC;IACrDC,SAAS,EAAEL,WAAW,EAAEM,MAAM,KAAK,SAAS;IAC5CC,YAAY,EAAEP,WAAW,EAAEO,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,31 +17,41 @@ 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();
|
|
41
|
-
const
|
|
43
|
+
const [isPending, setPending] = React3__default.default.useState(false);
|
|
44
|
+
const applyAction = React3__default.default.useCallback(async function applyAction2(hookArgs) {
|
|
45
|
+
const {
|
|
46
|
+
$optimisticUpdate,
|
|
47
|
+
...args
|
|
48
|
+
} = hookArgs;
|
|
42
49
|
try {
|
|
43
|
-
|
|
50
|
+
setPending(true);
|
|
51
|
+
setError(void 0);
|
|
52
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
53
|
+
optimisticUpdate: $optimisticUpdate
|
|
54
|
+
});
|
|
44
55
|
setData(r);
|
|
45
56
|
return r;
|
|
46
57
|
} catch (e) {
|
|
@@ -53,12 +64,15 @@ function useOsdkAction(actionDef) {
|
|
|
53
64
|
unknown: e
|
|
54
65
|
});
|
|
55
66
|
}
|
|
67
|
+
} finally {
|
|
68
|
+
setPending(false);
|
|
56
69
|
}
|
|
57
|
-
}, [
|
|
70
|
+
}, [observableClient, setError]);
|
|
58
71
|
return {
|
|
59
72
|
applyAction,
|
|
60
73
|
error,
|
|
61
|
-
data
|
|
74
|
+
data,
|
|
75
|
+
isPending
|
|
62
76
|
};
|
|
63
77
|
}
|
|
64
78
|
|
|
@@ -69,13 +83,11 @@ function makeExternalStore(createObservation, name) {
|
|
|
69
83
|
return lastResult;
|
|
70
84
|
}
|
|
71
85
|
function subscribe(notifyUpdate) {
|
|
72
|
-
console.log("Subscribing", name);
|
|
73
86
|
const obs = createObservation((payload) => {
|
|
74
87
|
lastResult = payload;
|
|
75
88
|
notifyUpdate();
|
|
76
89
|
});
|
|
77
90
|
return () => {
|
|
78
|
-
console.log("Unsubscribing", name);
|
|
79
91
|
obs.unsubscribe();
|
|
80
92
|
};
|
|
81
93
|
}
|
|
@@ -85,30 +97,10 @@ function makeExternalStore(createObservation, name) {
|
|
|
85
97
|
};
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
// src/new/
|
|
89
|
-
function useOsdkList(type, opts) {
|
|
90
|
-
const {
|
|
91
|
-
store
|
|
92
|
-
} = React3__default.default.useContext(OsdkContext2);
|
|
93
|
-
const where = store.canonicalizeWhereClause(opts.where);
|
|
94
|
-
const {
|
|
95
|
-
subscribe,
|
|
96
|
-
getSnapShot
|
|
97
|
-
} = React3__default.default.useMemo(() => makeExternalStore((x) => store.observeList(type, where, {
|
|
98
|
-
dedupeInterval: opts.dedupeIntervalMs ?? 2e3
|
|
99
|
-
}, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.dedupeIntervalMs]);
|
|
100
|
-
const listPayload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
101
|
-
return {
|
|
102
|
-
fetchMore: listPayload?.fetchMore,
|
|
103
|
-
data: listPayload?.resolvedList,
|
|
104
|
-
isLoading: listPayload?.status === "loading",
|
|
105
|
-
error: undefined,
|
|
106
|
-
isOptimistic: listPayload?.isOptimistic ?? false
|
|
107
|
-
};
|
|
108
|
-
}
|
|
100
|
+
// src/new/useOsdkObject.ts
|
|
109
101
|
function useOsdkObject(...args) {
|
|
110
102
|
const {
|
|
111
|
-
|
|
103
|
+
observableClient
|
|
112
104
|
} = React3__default.default.useContext(OsdkContext2);
|
|
113
105
|
const mode = args.length === 1 ? "offline" : undefined;
|
|
114
106
|
const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
|
|
@@ -116,9 +108,9 @@ function useOsdkObject(...args) {
|
|
|
116
108
|
const {
|
|
117
109
|
subscribe,
|
|
118
110
|
getSnapShot
|
|
119
|
-
} = React3__default.default.useMemo(() => makeExternalStore((payload2) =>
|
|
111
|
+
} = React3__default.default.useMemo(() => makeExternalStore((payload2) => observableClient.observeObject(objectType, primaryKey, {
|
|
120
112
|
mode
|
|
121
|
-
}, payload2)
|
|
113
|
+
}, payload2)), [observableClient, objectType, primaryKey, mode]);
|
|
122
114
|
const payload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
123
115
|
return {
|
|
124
116
|
object: payload?.object,
|
|
@@ -129,6 +121,36 @@ function useOsdkObject(...args) {
|
|
|
129
121
|
}
|
|
130
122
|
};
|
|
131
123
|
}
|
|
124
|
+
function useOsdkObjects(objectType, {
|
|
125
|
+
pageSize,
|
|
126
|
+
orderBy,
|
|
127
|
+
dedupeIntervalMs,
|
|
128
|
+
where = {},
|
|
129
|
+
streamUpdates
|
|
130
|
+
} = {}) {
|
|
131
|
+
const {
|
|
132
|
+
observableClient
|
|
133
|
+
} = React3__default.default.useContext(OsdkContext2);
|
|
134
|
+
const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
|
|
135
|
+
const {
|
|
136
|
+
subscribe,
|
|
137
|
+
getSnapShot
|
|
138
|
+
} = React3__default.default.useMemo(() => makeExternalStore((x) => observableClient.observeList({
|
|
139
|
+
objectType,
|
|
140
|
+
where: canonWhere,
|
|
141
|
+
dedupeInterval: dedupeIntervalMs ?? 2e3,
|
|
142
|
+
pageSize,
|
|
143
|
+
orderBy,
|
|
144
|
+
streamUpdates
|
|
145
|
+
}, x), process.env.NODE_ENV !== "production" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : undefined), [observableClient, objectType, canonWhere, dedupeIntervalMs]);
|
|
146
|
+
const listPayload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
147
|
+
return {
|
|
148
|
+
fetchMore: listPayload?.fetchMore,
|
|
149
|
+
data: listPayload?.resolvedList,
|
|
150
|
+
isLoading: listPayload?.status === "loading",
|
|
151
|
+
isOptimistic: listPayload?.isOptimistic ?? false
|
|
152
|
+
};
|
|
153
|
+
}
|
|
132
154
|
|
|
133
155
|
Object.defineProperty(exports, "useOsdkClient", {
|
|
134
156
|
enumerable: true,
|
|
@@ -136,7 +158,7 @@ Object.defineProperty(exports, "useOsdkClient", {
|
|
|
136
158
|
});
|
|
137
159
|
exports.OsdkProvider2 = OsdkProvider2;
|
|
138
160
|
exports.useOsdkAction = useOsdkAction;
|
|
139
|
-
exports.useOsdkList = useOsdkList;
|
|
140
161
|
exports.useOsdkObject = useOsdkObject;
|
|
162
|
+
exports.useOsdkObjects = useOsdkObjects;
|
|
141
163
|
//# sourceMappingURL=experimental.cjs.map
|
|
142
164
|
//# 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,EAAA;AAAA,IAC7D,KAAO,EAAA;AAAA,MACL,MAAA;AAAA,MACA;AAAA;AACF,KACC,QAAQ,CAAA;AACb;ACVO,SAAS,cAAc,SAAW,EAAA;AACvC,EAAM,MAAA;AAAA,IACJ;AAAA,GACF,GAAIA,uBAAM,CAAA,UAAA,CAAW,YAAY,CAAA;AACjC,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,wBAAM,QAAS,EAAA;AACzC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,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A,GAAa,KAAK,MAAW,KAAA,CAAA,GAAI,KAAK,CAAC,CAAA,CAAE,WAAc,GAAA,IAAA,CAAK,CAAC,CAAA;AACnE,EAAM,MAAA;AAAA,IACJ,SAAA;AAAA,IACA;AAAA,GACF,GAAIA,uBAAM,CAAA,OAAA,CAAQ,MAAM,iBAAA,CAAkB,CAAAG,QAAW,KAAA,KAAA,CAAM,aAAc,CAAA,UAAA,EAAY,UAAY,EAAA;AAAA,IAC/F;AAAA,GACCA,EAAAA,QAAO,CAAG,EAAA,CAAA,OAAA,EAAU,UAAU,CAAI,CAAA,EAAA,UAAU,CAAE,CAAA,CAAA,EAAG,CAAC,KAAA,EAAO,UAAY,EAAA,UAAA,EAAY,IAAI,CAAC,CAAA;AACzF,EAAA,MAAM,OAAUH,GAAAA,uBAAAA,CAAM,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 applyAction = React.useCallback(async function applyAction(args, opts) {\n try {\n const r = await store.applyAction(actionDef, args, opts);\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 }\n }, [store, setError]);\n return {\n applyAction,\n error,\n data\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 // eslint-disable-next-line no-console\n console.log(\"Subscribing\", name);\n const obs = createObservation(payload => {\n lastResult = payload;\n notifyUpdate();\n });\n return () => {\n // eslint-disable-next-line no-console\n console.log(\"Unsubscribing\", name);\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(type, opts) {\n const {\n store\n } = React.useContext(OsdkContext2);\n const where = store.canonicalizeWhereClause(opts.where);\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(x => store.observeList(type, where, {\n dedupeInterval: opts.dedupeIntervalMs ?? 2_000\n }, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.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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,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,CAAA,KAAK,iBAAiB,WAAY,CAAA;AAAA,IAC1E,UAAA;AAAA,IACA,KAAO,EAAA,UAAA;AAAA,IACP,gBAAgB,gBAAoB,IAAA,GAAA;AAAA,IACpC,QAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAAG,CAAC,CAAG,EAAA,OAAA,CAAQ,IAAI,QAAa,KAAA,YAAA,GAAe,CAAQ,KAAA,EAAA,UAAA,CAAW,OAAO,CAAA,CAAA,EAAI,KAAK,SAAU,CAAA,UAAU,CAAC,CAAA,CAAA,GAAK,SAAM,CAAA,EAAG,CAAC,gBAAkB,EAAA,UAAA,EAAY,UAAY,EAAA,gBAAgB,CAAC,CAAA;AACjL,EAAA,MAAM,WAAcA,GAAAA,uBAAAA,CAAM,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AAErE,EAAO,OAAA;AAAA,IACL,WAAW,WAAa,EAAA,SAAA;AAAA,IACxB,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(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\";\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(payload => observableClient.observeObject(objectType, primaryKey, {\n mode\n }, payload), `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 ?? false,\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(objectType, {\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(x => observableClient.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), [observableClient, objectType, 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 data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false\n };\n}"]}
|