@osdk/react 0.3.0-beta.3 → 0.3.0-rc.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 +6 -0
- package/build/browser/index.js +4 -0
- package/build/browser/index.js.map +1 -1
- package/build/browser/new/OsdkContext2.js +28 -0
- package/build/browser/new/OsdkContext2.js.map +1 -0
- package/build/browser/new/OsdkProvider2.js +31 -0
- package/build/browser/new/OsdkProvider2.js.map +1 -0
- package/build/browser/new/makeExternalStore.js +39 -0
- package/build/browser/new/makeExternalStore.js.map +1 -0
- package/build/browser/new/useOsdkAction.js +49 -0
- package/build/browser/new/useOsdkAction.js.map +1 -0
- package/build/browser/new/useOsdkList.js +40 -0
- package/build/browser/new/useOsdkList.js.map +1 -0
- package/build/browser/new/useOsdkObject.js +60 -0
- package/build/browser/new/useOsdkObject.js.map +1 -0
- package/build/browser/public/experimental.js +22 -0
- package/build/browser/public/experimental.js.map +1 -0
- package/build/cjs/chunk-2N32USW5.cjs +28 -0
- package/build/cjs/chunk-2N32USW5.cjs.map +1 -0
- package/build/cjs/index.cjs +6 -17
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +2 -3
- package/build/cjs/public/experimental.cjs +142 -0
- package/build/cjs/public/experimental.cjs.map +1 -0
- package/build/cjs/public/experimental.d.cts +71 -0
- package/build/cjs/useOsdkClient-B4iwHO1H.d.cts +5 -0
- package/build/esm/index.js +4 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/new/OsdkContext2.js +28 -0
- package/build/esm/new/OsdkContext2.js.map +1 -0
- package/build/esm/new/OsdkProvider2.js +31 -0
- package/build/esm/new/OsdkProvider2.js.map +1 -0
- package/build/esm/new/makeExternalStore.js +39 -0
- package/build/esm/new/makeExternalStore.js.map +1 -0
- package/build/esm/new/useOsdkAction.js +49 -0
- package/build/esm/new/useOsdkAction.js.map +1 -0
- package/build/esm/new/useOsdkList.js +40 -0
- package/build/esm/new/useOsdkList.js.map +1 -0
- package/build/esm/new/useOsdkObject.js +60 -0
- package/build/esm/new/useOsdkObject.js.map +1 -0
- package/build/esm/public/experimental.js +22 -0
- package/build/esm/public/experimental.js.map +1 -0
- package/build/types/OsdkContext.d.ts +3 -1
- package/build/types/OsdkContext.d.ts.map +1 -0
- package/build/types/OsdkProvider.d.ts +2 -2
- package/build/types/OsdkProvider.d.ts.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/new/OsdkContext2.d.ts +9 -0
- package/build/types/new/OsdkContext2.d.ts.map +1 -0
- package/build/types/new/OsdkProvider2.d.ts +10 -0
- package/build/types/new/OsdkProvider2.d.ts.map +1 -0
- package/build/types/new/makeExternalStore.d.ts +5 -0
- package/build/types/new/makeExternalStore.d.ts.map +1 -0
- package/build/types/new/useOsdkAction.d.ts +12 -0
- package/build/types/new/useOsdkAction.d.ts.map +1 -0
- package/build/types/new/useOsdkList.d.ts +26 -0
- package/build/types/new/useOsdkList.d.ts.map +1 -0
- package/build/types/new/useOsdkObject.d.ts +21 -0
- package/build/types/new/useOsdkObject.d.ts.map +1 -0
- package/build/types/public/experimental.d.ts +5 -0
- package/build/types/public/experimental.d.ts.map +1 -0
- package/build/types/useOsdkClient.d.ts.map +1 -0
- package/build/types/useOsdkMetadata.d.ts +2 -2
- package/build/types/useOsdkMetadata.d.ts.map +1 -0
- package/experimental.d.ts +17 -0
- package/package.json +14 -4
package/CHANGELOG.md
CHANGED
package/build/browser/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["OsdkProvider","useOsdkClient"],"sources":["index.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\nexport { OsdkProvider } from \"./OsdkProvider.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,YAAY,QAAQ,mBAAmB;AAChD,SAASC,aAAa,QAAQ,oBAAoB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["OsdkProvider","useOsdkClient"],"sources":["index.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\n/**\n * @module @osdk/react\n */\n\nexport { OsdkProvider } from \"./OsdkProvider.js\";\nexport { useOsdkClient } from \"./useOsdkClient.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,mBAAmB;AAChD,SAASC,aAAa,QAAQ,oBAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React from "react";
|
|
18
|
+
function fakeClientFn(..._args) {
|
|
19
|
+
throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
|
|
20
|
+
}
|
|
21
|
+
const fakeClient = Object.assign(fakeClientFn, {
|
|
22
|
+
fetchMetadata: fakeClientFn
|
|
23
|
+
});
|
|
24
|
+
export const OsdkContext2 = /*#__PURE__*/React.createContext({
|
|
25
|
+
client: fakeClient,
|
|
26
|
+
store: undefined
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=OsdkContext2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OsdkContext2.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext2","createContext","client","store","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 store: ObservableClient;\n}\n\nexport const OsdkContext2: React.Context<OsdkContextContents> = React\n .createContext<OsdkContextContents>({\n client: fakeClient,\n store: 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,KAAK,EAAEC;AACT,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React from "react";
|
|
18
|
+
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
19
|
+
export function OsdkProvider2({
|
|
20
|
+
children,
|
|
21
|
+
client,
|
|
22
|
+
store
|
|
23
|
+
}) {
|
|
24
|
+
return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {
|
|
25
|
+
value: {
|
|
26
|
+
client,
|
|
27
|
+
store
|
|
28
|
+
}
|
|
29
|
+
}, children);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=OsdkProvider2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OsdkProvider2.js","names":["React","OsdkContext2","OsdkProvider2","children","client","store","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 type { ObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ninterface OsdkProviderOptions {\n children: React.ReactNode;\n client: Client;\n store: ObservableClient;\n}\n\nexport function OsdkProvider2({\n children,\n client,\n store,\n}: OsdkProviderOptions): React.JSX.Element {\n return (\n <OsdkContext2.Provider value={{ client, store }}>\n {children}\n </OsdkContext2.Provider>\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,YAAY,QAAQ,mBAAmB;AAQhD,OAAO,SAASC,aAAaA,CAAC;EAC5BC,QAAQ;EACRC,MAAM;EACNC;AACmB,CAAC,EAAqB;EACzC,oBACEL,KAAA,CAAAM,aAAA,CAACL,YAAY,CAACM,QAAQ;IAACC,KAAK,EAAE;MAAEJ,MAAM;MAAEC;IAAM;EAAE,GAC7CF,QACoB,CAAC;AAE5B","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function makeExternalStore(createObservation, name) {
|
|
18
|
+
let lastResult;
|
|
19
|
+
function getSnapShot() {
|
|
20
|
+
return lastResult;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
subscribe: function subscribe(notifyUpdate) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.log("Subscribing", name);
|
|
26
|
+
const obs = createObservation(payload => {
|
|
27
|
+
lastResult = payload;
|
|
28
|
+
notifyUpdate();
|
|
29
|
+
});
|
|
30
|
+
return () => {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log("Unsubscribing", name);
|
|
33
|
+
obs.unsubscribe();
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
getSnapShot
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=makeExternalStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","name","lastResult","getSnapShot","subscribe","notifyUpdate","console","log","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 // eslint-disable-next-line no-console\n console.log(\"Subscribing\", name);\n const obs = createObservation((payload) => {\n lastResult = payload;\n notifyUpdate();\n });\n\n return (): void => {\n // eslint-disable-next-line no-console\n console.log(\"Unsubscribing\", name);\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,EAC3EC,IAAa,EAIb;EACA,IAAIC,UAAyB;EAE7B,SAASC,WAAWA,CAAA,EAAkB;IACpC,OAAOD,UAAU;EACnB;EAiBA,OAAO;IACLE,SAAS,EAhBX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C;MACAC,OAAO,CAACC,GAAG,CAAC,aAAa,EAAEN,IAAI,CAAC;MAChC,MAAMO,GAAG,GAAGR,iBAAiB,CAAES,OAAO,IAAK;QACzCP,UAAU,GAAGO,OAAO;QACpBJ,YAAY,CAAC,CAAC;MAChB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjB;QACAC,OAAO,CAACC,GAAG,CAAC,eAAe,EAAEN,IAAI,CAAC;QAClCO,GAAG,CAACE,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTP;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { ActionValidationError } from "@osdk/client";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
|
+
export function useOsdkAction(actionDef) {
|
|
21
|
+
const {
|
|
22
|
+
store
|
|
23
|
+
} = React.useContext(OsdkContext2);
|
|
24
|
+
const [error, setError] = React.useState();
|
|
25
|
+
const [data, setData] = React.useState();
|
|
26
|
+
const applyAction = React.useCallback(async function (args, opts) {
|
|
27
|
+
try {
|
|
28
|
+
const r = await store.applyAction(actionDef, args, opts);
|
|
29
|
+
setData(r);
|
|
30
|
+
return r;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e instanceof ActionValidationError) {
|
|
33
|
+
setError({
|
|
34
|
+
actionValidation: e
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
setError({
|
|
38
|
+
unknown: e
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, [store, setError]);
|
|
43
|
+
return {
|
|
44
|
+
applyAction,
|
|
45
|
+
error,
|
|
46
|
+
data
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=useOsdkAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","store","useContext","error","setError","useState","data","setData","applyAction","useCallback","args","opts","r","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\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { store } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<unknown>();\n\n const applyAction = React.useCallback(async function applyAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts: ObservableClient.ApplyActionOptions,\n ) {\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({ unknown: e });\n }\n }\n }, [store, setError]);\n\n return { applyAction, error, data };\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;AAiBhD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAM,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAChD,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;EAEjD,MAAMG,WAAW,GAAGX,KAAK,CAACY,WAAW,CAAC,gBACpCC,IAA6D,EAC7DC,IAAyC,EACzC;IACA,IAAI;MACF,MAAMC,CAAC,GAAG,MAAMX,KAAK,CAACO,WAAW,CAACR,SAAS,EAAEU,IAAI,EAAEC,IAAI,CAAC;MACxDJ,OAAO,CAACK,CAAC,CAAC;MACV,OAAOA,CAAC;IACV,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,IAAIA,CAAC,YAAYjB,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACPU,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACLT,QAAQ,CAAC;UAAEW,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;IACF;EACF,CAAC,EAAE,CAACZ,KAAK,EAAEG,QAAQ,CAAC,CAAC;EAErB,OAAO;IAAEI,WAAW;IAAEL,KAAK;IAAEG;EAAK,CAAC;AACrC","ignoreList":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React from "react";
|
|
18
|
+
import { makeExternalStore } from "./makeExternalStore.js";
|
|
19
|
+
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
|
+
export function useOsdkList(type, opts) {
|
|
21
|
+
const {
|
|
22
|
+
store
|
|
23
|
+
} = React.useContext(OsdkContext2);
|
|
24
|
+
const where = store.canonicalizeWhereClause(opts.where);
|
|
25
|
+
const {
|
|
26
|
+
subscribe,
|
|
27
|
+
getSnapShot
|
|
28
|
+
} = React.useMemo(() => makeExternalStore(x => store.observeList(type, where, {
|
|
29
|
+
dedupeInterval: opts.dedupeIntervalMs ?? 2_000
|
|
30
|
+
}, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.dedupeIntervalMs]);
|
|
31
|
+
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
32
|
+
return {
|
|
33
|
+
fetchMore: listPayload?.fetchMore,
|
|
34
|
+
data: listPayload?.resolvedList,
|
|
35
|
+
isLoading: listPayload?.status === "loading",
|
|
36
|
+
error: undefined,
|
|
37
|
+
isOptimistic: listPayload?.isOptimistic ?? false
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=useOsdkList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsdkList.js","names":["React","makeExternalStore","OsdkContext2","useOsdkList","type","opts","store","useContext","where","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","x","observeList","dedupeInterval","dedupeIntervalMs","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","data","resolvedList","isLoading","status","error","undefined","isOptimistic"],"sources":["useOsdkList.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, WhereClause } 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 UseOsdkListOptions<T extends ObjectTypeDefinition> {\n where: WhereClause<T>;\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkList` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n}\nexport interface UseOsdkListResult<T extends ObjectTypeDefinition> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[];\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\nexport function useOsdkList<T extends ObjectTypeDefinition>(\n type: T,\n opts: UseOsdkListOptions<T>,\n): UseOsdkListResult<T> {\n const { store } = React.useContext(OsdkContext2);\n const where = store.canonicalizeWhereClause(opts.where);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ListPayload>((x) =>\n store.observeList(\n type,\n where,\n {\n dedupeInterval: opts.dedupeIntervalMs ?? 2_000,\n },\n x,\n ), `list ${type.apiName} ${JSON.stringify(where)}`),\n [store, type, where, opts.dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList as Osdk.Instance<T>[],\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false,\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;AA+BhD,OAAO,SAASC,WAAWA,CACzBC,IAAO,EACPC,IAA2B,EACL;EACtB,MAAM;IAAEC;EAAM,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAChD,MAAMM,KAAK,GAAGF,KAAK,CAACG,uBAAuB,CAACJ,IAAI,CAACG,KAAK,CAAC;EAEvD,MAAM;IAAEE,SAAS;IAAEC;EAAY,CAAC,GAAGX,KAAK,CAACY,OAAO,CAC9C,MACEX,iBAAiB,CAAeY,CAAC,IAC/BP,KAAK,CAACQ,WAAW,CACfV,IAAI,EACJI,KAAK,EACL;IACEO,cAAc,EAAEV,IAAI,CAACW,gBAAgB,IAAI;EAC3C,CAAC,EACDH,CACF,CAAC,EAAE,QAAQT,IAAI,CAACa,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACX,KAAK,CAAC,EAAE,CAAC,EACvD,CAACF,KAAK,EAAEF,IAAI,EAAEI,KAAK,EAAEH,IAAI,CAACW,gBAAgB,CAC5C,CAAC;EAED,MAAMI,WAAW,GAAGpB,KAAK,CAACqB,oBAAoB,CAACX,SAAS,EAAEC,WAAW,CAAC;EAEtE,OAAO;IACLW,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,IAAI,EAAEH,WAAW,EAAEI,YAAkC;IACrDC,SAAS,EAAEL,WAAW,EAAEM,MAAM,KAAK,SAAS;IAC5CC,KAAK,EAAEC,SAAS;IAChBC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React from "react";
|
|
18
|
+
import { makeExternalStore } from "./makeExternalStore.js";
|
|
19
|
+
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param obj an existing `Osdk.Instance` object to get metadata for.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Loads an object by type and primary key.
|
|
27
|
+
*
|
|
28
|
+
* @param type
|
|
29
|
+
* @param primaryKey
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
Implementation of useOsdkObject
|
|
34
|
+
*/
|
|
35
|
+
export function useOsdkObject(...args) {
|
|
36
|
+
const {
|
|
37
|
+
store
|
|
38
|
+
} = React.useContext(OsdkContext2);
|
|
39
|
+
|
|
40
|
+
// TODO: Figure out what the correct default behavior is for the various scenarios
|
|
41
|
+
const mode = args.length === 1 ? "offline" : undefined;
|
|
42
|
+
const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
|
|
43
|
+
const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];
|
|
44
|
+
const {
|
|
45
|
+
subscribe,
|
|
46
|
+
getSnapShot
|
|
47
|
+
} = React.useMemo(() => makeExternalStore(payload => store.observeObject(objectType, primaryKey, {
|
|
48
|
+
mode
|
|
49
|
+
}, payload), `object ${objectType} ${primaryKey}`), [store, objectType, primaryKey, mode]);
|
|
50
|
+
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
51
|
+
return {
|
|
52
|
+
object: payload?.object,
|
|
53
|
+
isLoading: payload?.status === "loading",
|
|
54
|
+
isOptimistic: payload?.isOptimistic ?? false,
|
|
55
|
+
forceUpdate: () => {
|
|
56
|
+
throw "not implemented";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=useOsdkObject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","store","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 { store } = 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>((payload) =>\n store.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n payload,\n ), `object ${objectType} ${primaryKey}`),\n [store, 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;EAAM,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAEhD;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,CAAiBiB,OAAO,IACvCb,KAAK,CAACc,aAAa,CACjBT,UAAU,EACVG,UAAU,EACV;IACEN;EACF,CAAC,EACDW,OACF,CAAC,EAAE,UAAUR,UAAU,IAAIG,UAAU,EAAE,CAAC,EAC5C,CAACR,KAAK,EAAEK,UAAU,EAAEG,UAAU,EAAEN,IAAI,CACtC,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":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export { OsdkProvider2 } from "../new/OsdkProvider2.js";
|
|
18
|
+
export { useOsdkAction } from "../new/useOsdkAction.js";
|
|
19
|
+
export { useOsdkList } from "../new/useOsdkList.js";
|
|
20
|
+
export { useOsdkObject } from "../new/useOsdkObject.js";
|
|
21
|
+
export { useOsdkClient } from "../useOsdkClient.js";
|
|
22
|
+
//# sourceMappingURL=experimental.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experimental.js","names":["OsdkProvider2","useOsdkAction","useOsdkList","useOsdkObject","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 { useOsdkList } from \"../new/useOsdkList.js\";\nexport { useOsdkObject } from \"../new/useOsdkObject.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,WAAW,QAAQ,uBAAuB;AACnD,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,aAAa,QAAQ,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
8
|
+
|
|
9
|
+
// src/useOsdkClient.ts
|
|
10
|
+
function fakeClientFn(..._args) {
|
|
11
|
+
throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
|
|
12
|
+
}
|
|
13
|
+
var fakeClient = Object.assign(fakeClientFn, {
|
|
14
|
+
fetchMetadata: fakeClientFn
|
|
15
|
+
});
|
|
16
|
+
var OsdkContext = /* @__PURE__ */ React__default.default.createContext({
|
|
17
|
+
client: fakeClient
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// src/useOsdkClient.ts
|
|
21
|
+
function useOsdkClient() {
|
|
22
|
+
return React__default.default.useContext(OsdkContext).client;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.OsdkContext = OsdkContext;
|
|
26
|
+
exports.useOsdkClient = useOsdkClient;
|
|
27
|
+
//# sourceMappingURL=chunk-2N32USW5.cjs.map
|
|
28
|
+
//# sourceMappingURL=chunk-2N32USW5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/OsdkContext.ts","../../src/useOsdkClient.ts"],"names":["React"],"mappings":";;;;;;;;;AAiBA,SAAS,gBAAgB,KAAO,EAAA;AAC9B,EAAM,MAAA,IAAI,MAAM,sEAAsE,CAAA;AACxF;AACA,IAAM,UAAA,GAAa,MAAO,CAAA,MAAA,CAAO,YAAc,EAAA;AAAA,EAC7C,aAAe,EAAA;AACjB,CAAC,CAAA;AACY,IAAA,WAAA,0CAAiC,aAAc,CAAA;AAAA,EAC1D,MAAQ,EAAA;AACV,CAAC;;;ACPM,SAAS,aAAgB,GAAA;AAC9B,EAAOA,OAAAA,sBAAAA,CAAM,UAAW,CAAA,WAAW,CAAE,CAAA,MAAA;AACvC","file":"chunk-2N32USW5.cjs","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nfunction fakeClientFn(..._args) {\n throw new Error(\"This is not a real client. Did you forget to <OsdkContext.Provider>?\");\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\nexport const OsdkContext = /*#__PURE__*/React.createContext({\n client: fakeClient\n});","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nexport function useOsdkClient() {\n return React.useContext(OsdkContext).client;\n}"]}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk2N32USW5_cjs = require('./chunk-2N32USW5.cjs');
|
|
3
4
|
var React = require('react');
|
|
4
5
|
|
|
5
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
7
|
|
|
7
8
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
8
9
|
|
|
9
|
-
// src/OsdkProvider.tsx
|
|
10
|
-
function fakeClientFn(..._args) {
|
|
11
|
-
throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
|
|
12
|
-
}
|
|
13
|
-
var fakeClient = Object.assign(fakeClientFn, {
|
|
14
|
-
fetchMetadata: fakeClientFn
|
|
15
|
-
});
|
|
16
|
-
var OsdkContext = /* @__PURE__ */ React__default.default.createContext({
|
|
17
|
-
client: fakeClient
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// src/OsdkProvider.tsx
|
|
21
10
|
function OsdkProvider({
|
|
22
11
|
children,
|
|
23
12
|
client
|
|
24
13
|
}) {
|
|
25
|
-
return /* @__PURE__ */ React__default.default.createElement(OsdkContext.Provider, {
|
|
14
|
+
return /* @__PURE__ */ React__default.default.createElement(chunk2N32USW5_cjs.OsdkContext.Provider, {
|
|
26
15
|
value: {
|
|
27
16
|
client
|
|
28
17
|
}
|
|
29
18
|
}, children);
|
|
30
19
|
}
|
|
31
|
-
function useOsdkClient() {
|
|
32
|
-
return React__default.default.useContext(OsdkContext).client;
|
|
33
|
-
}
|
|
34
20
|
|
|
21
|
+
Object.defineProperty(exports, "useOsdkClient", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunk2N32USW5_cjs.useOsdkClient; }
|
|
24
|
+
});
|
|
35
25
|
exports.OsdkProvider = OsdkProvider;
|
|
36
|
-
exports.useOsdkClient = useOsdkClient;
|
|
37
26
|
//# sourceMappingURL=index.cjs.map
|
|
38
27
|
//# sourceMappingURL=index.cjs.map
|
package/build/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/OsdkProvider.tsx"],"names":["React","OsdkContext"],"mappings":";;;;;;;;;AAkBO,SAAS,YAAa,CAAA;AAAA,EAC3B,QAAA;AAAA,EACA;AACF,CAAG,EAAA;AACD,EAAoB,uBAAAA,sBAAA,CAAM,aAAc,CAAAC,6BAAA,CAAY,QAAU,EAAA;AAAA,IAC5D,KAAO,EAAA;AAAA,MACL;AAAA;AACF,KACC,QAAQ,CAAA;AACb","file":"index.cjs","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nexport function OsdkProvider({\n children,\n client\n}) {\n return /*#__PURE__*/React.createElement(OsdkContext.Provider, {\n value: {\n client\n }\n }, children);\n}"]}
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Client } from '@osdk/client';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
export { u as useOsdkClient } from './useOsdkClient-B4iwHO1H.cjs';
|
|
3
4
|
|
|
4
5
|
declare function OsdkProvider({ children, client, }: {
|
|
5
6
|
children: React.ReactNode;
|
|
6
7
|
client: Client;
|
|
7
8
|
}): React.JSX.Element;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export { OsdkProvider, useOsdkClient };
|
|
10
|
+
export { OsdkProvider };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2N32USW5_cjs = require('../chunk-2N32USW5.cjs');
|
|
4
|
+
var React3 = require('react');
|
|
5
|
+
var client = require('@osdk/client');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
10
|
+
|
|
11
|
+
function fakeClientFn(..._args) {
|
|
12
|
+
throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
|
|
13
|
+
}
|
|
14
|
+
var fakeClient = Object.assign(fakeClientFn, {
|
|
15
|
+
fetchMetadata: fakeClientFn
|
|
16
|
+
});
|
|
17
|
+
var OsdkContext2 = /* @__PURE__ */ React3__default.default.createContext({
|
|
18
|
+
client: fakeClient,
|
|
19
|
+
store: undefined
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/new/OsdkProvider2.tsx
|
|
23
|
+
function OsdkProvider2({
|
|
24
|
+
children,
|
|
25
|
+
client,
|
|
26
|
+
store
|
|
27
|
+
}) {
|
|
28
|
+
return /* @__PURE__ */ React3__default.default.createElement(OsdkContext2.Provider, {
|
|
29
|
+
value: {
|
|
30
|
+
client,
|
|
31
|
+
store
|
|
32
|
+
}
|
|
33
|
+
}, children);
|
|
34
|
+
}
|
|
35
|
+
function useOsdkAction(actionDef) {
|
|
36
|
+
const {
|
|
37
|
+
store
|
|
38
|
+
} = React3__default.default.useContext(OsdkContext2);
|
|
39
|
+
const [error, setError] = React3__default.default.useState();
|
|
40
|
+
const [data, setData] = React3__default.default.useState();
|
|
41
|
+
const applyAction = React3__default.default.useCallback(async function applyAction2(args, opts) {
|
|
42
|
+
try {
|
|
43
|
+
const r = await store.applyAction(actionDef, args, opts);
|
|
44
|
+
setData(r);
|
|
45
|
+
return r;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
if (e instanceof client.ActionValidationError) {
|
|
48
|
+
setError({
|
|
49
|
+
actionValidation: e
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
setError({
|
|
53
|
+
unknown: e
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, [store, setError]);
|
|
58
|
+
return {
|
|
59
|
+
applyAction,
|
|
60
|
+
error,
|
|
61
|
+
data
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/new/makeExternalStore.ts
|
|
66
|
+
function makeExternalStore(createObservation, name) {
|
|
67
|
+
let lastResult;
|
|
68
|
+
function getSnapShot() {
|
|
69
|
+
return lastResult;
|
|
70
|
+
}
|
|
71
|
+
function subscribe(notifyUpdate) {
|
|
72
|
+
console.log("Subscribing", name);
|
|
73
|
+
const obs = createObservation((payload) => {
|
|
74
|
+
lastResult = payload;
|
|
75
|
+
notifyUpdate();
|
|
76
|
+
});
|
|
77
|
+
return () => {
|
|
78
|
+
console.log("Unsubscribing", name);
|
|
79
|
+
obs.unsubscribe();
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
subscribe,
|
|
84
|
+
getSnapShot
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/new/useOsdkList.ts
|
|
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
|
+
}
|
|
109
|
+
function useOsdkObject(...args) {
|
|
110
|
+
const {
|
|
111
|
+
store
|
|
112
|
+
} = React3__default.default.useContext(OsdkContext2);
|
|
113
|
+
const mode = args.length === 1 ? "offline" : undefined;
|
|
114
|
+
const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
|
|
115
|
+
const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];
|
|
116
|
+
const {
|
|
117
|
+
subscribe,
|
|
118
|
+
getSnapShot
|
|
119
|
+
} = React3__default.default.useMemo(() => makeExternalStore((payload2) => store.observeObject(objectType, primaryKey, {
|
|
120
|
+
mode
|
|
121
|
+
}, payload2), `object ${objectType} ${primaryKey}`), [store, objectType, primaryKey, mode]);
|
|
122
|
+
const payload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
123
|
+
return {
|
|
124
|
+
object: payload?.object,
|
|
125
|
+
isLoading: payload?.status === "loading",
|
|
126
|
+
isOptimistic: payload?.isOptimistic ?? false,
|
|
127
|
+
forceUpdate: () => {
|
|
128
|
+
throw "not implemented";
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
Object.defineProperty(exports, "useOsdkClient", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () { return chunk2N32USW5_cjs.useOsdkClient; }
|
|
136
|
+
});
|
|
137
|
+
exports.OsdkProvider2 = OsdkProvider2;
|
|
138
|
+
exports.useOsdkAction = useOsdkAction;
|
|
139
|
+
exports.useOsdkList = useOsdkList;
|
|
140
|
+
exports.useOsdkObject = useOsdkObject;
|
|
141
|
+
//# sourceMappingURL=experimental.cjs.map
|
|
142
|
+
//# sourceMappingURL=experimental.cjs.map
|