@osdk/react 0.3.0-beta.2 → 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.
Files changed (100) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/browser/OsdkContext.js +2 -1
  3. package/build/browser/OsdkContext.js.map +1 -1
  4. package/build/browser/OsdkProvider.js +2 -1
  5. package/build/browser/OsdkProvider.js.map +1 -1
  6. package/build/browser/index.js +5 -0
  7. package/build/browser/index.js.map +1 -1
  8. package/build/browser/new/OsdkContext2.js +28 -0
  9. package/build/browser/new/OsdkContext2.js.map +1 -0
  10. package/build/browser/new/OsdkProvider2.js +31 -0
  11. package/build/browser/new/OsdkProvider2.js.map +1 -0
  12. package/build/browser/new/makeExternalStore.js +39 -0
  13. package/build/browser/new/makeExternalStore.js.map +1 -0
  14. package/build/browser/new/useOsdkAction.js +49 -0
  15. package/build/browser/new/useOsdkAction.js.map +1 -0
  16. package/build/browser/new/useOsdkList.js +40 -0
  17. package/build/browser/new/useOsdkList.js.map +1 -0
  18. package/build/browser/new/useOsdkObject.js +60 -0
  19. package/build/browser/new/useOsdkObject.js.map +1 -0
  20. package/build/browser/public/experimental.js +22 -0
  21. package/build/browser/public/experimental.js.map +1 -0
  22. package/build/browser/useOsdkClient.js +1 -0
  23. package/build/browser/useOsdkClient.js.map +1 -1
  24. package/build/browser/useOsdkMetadata.js +1 -0
  25. package/build/browser/useOsdkMetadata.js.map +1 -1
  26. package/build/cjs/chunk-2N32USW5.cjs +28 -0
  27. package/build/cjs/chunk-2N32USW5.cjs.map +1 -0
  28. package/build/cjs/index.cjs +27 -0
  29. package/build/cjs/index.cjs.map +1 -0
  30. package/build/cjs/index.d.cts +10 -0
  31. package/build/cjs/public/experimental.cjs +142 -0
  32. package/build/cjs/public/experimental.cjs.map +1 -0
  33. package/build/cjs/public/experimental.d.cts +71 -0
  34. package/build/cjs/useOsdkClient-B4iwHO1H.d.cts +5 -0
  35. package/build/esm/OsdkContext.js +2 -1
  36. package/build/esm/OsdkContext.js.map +1 -1
  37. package/build/esm/OsdkProvider.js +2 -1
  38. package/build/esm/OsdkProvider.js.map +1 -1
  39. package/build/esm/index.js +5 -0
  40. package/build/esm/index.js.map +1 -1
  41. package/build/esm/new/OsdkContext2.js +28 -0
  42. package/build/esm/new/OsdkContext2.js.map +1 -0
  43. package/build/esm/new/OsdkProvider2.js +31 -0
  44. package/build/esm/new/OsdkProvider2.js.map +1 -0
  45. package/build/esm/new/makeExternalStore.js +39 -0
  46. package/build/esm/new/makeExternalStore.js.map +1 -0
  47. package/build/esm/new/useOsdkAction.js +49 -0
  48. package/build/esm/new/useOsdkAction.js.map +1 -0
  49. package/build/esm/new/useOsdkList.js +40 -0
  50. package/build/esm/new/useOsdkList.js.map +1 -0
  51. package/build/esm/new/useOsdkObject.js +60 -0
  52. package/build/esm/new/useOsdkObject.js.map +1 -0
  53. package/build/esm/public/experimental.js +22 -0
  54. package/build/esm/public/experimental.js.map +1 -0
  55. package/build/esm/useOsdkClient.js +1 -0
  56. package/build/esm/useOsdkClient.js.map +1 -1
  57. package/build/esm/useOsdkMetadata.js +1 -0
  58. package/build/esm/useOsdkMetadata.js.map +1 -1
  59. package/build/{browser → types}/OsdkContext.d.ts +1 -2
  60. package/build/types/OsdkContext.d.ts.map +1 -0
  61. package/build/types/OsdkProvider.d.ts +6 -0
  62. package/build/types/OsdkProvider.d.ts.map +1 -0
  63. package/build/{browser → types}/index.d.ts +3 -1
  64. package/build/types/index.d.ts.map +1 -0
  65. package/build/types/new/OsdkContext2.d.ts +9 -0
  66. package/build/types/new/OsdkContext2.d.ts.map +1 -0
  67. package/build/types/new/OsdkProvider2.d.ts +10 -0
  68. package/build/types/new/OsdkProvider2.d.ts.map +1 -0
  69. package/build/types/new/makeExternalStore.d.ts +5 -0
  70. package/build/types/new/makeExternalStore.d.ts.map +1 -0
  71. package/build/types/new/useOsdkAction.d.ts +12 -0
  72. package/build/types/new/useOsdkAction.d.ts.map +1 -0
  73. package/build/types/new/useOsdkList.d.ts +26 -0
  74. package/build/types/new/useOsdkList.d.ts.map +1 -0
  75. package/build/types/new/useOsdkObject.d.ts +21 -0
  76. package/build/types/new/useOsdkObject.d.ts.map +1 -0
  77. package/build/types/public/experimental.d.ts +5 -0
  78. package/build/types/public/experimental.d.ts.map +1 -0
  79. package/build/{browser → types}/useOsdkClient.d.ts +0 -1
  80. package/build/types/useOsdkClient.d.ts.map +1 -0
  81. package/build/{browser → types}/useOsdkMetadata.d.ts +2 -3
  82. package/build/types/useOsdkMetadata.d.ts.map +1 -0
  83. package/experimental.d.ts +17 -0
  84. package/package.json +34 -11
  85. package/build/browser/OsdkContext.d.ts.map +0 -1
  86. package/build/browser/OsdkProvider.d.ts +0 -7
  87. package/build/browser/OsdkProvider.d.ts.map +0 -1
  88. package/build/browser/index.d.ts.map +0 -1
  89. package/build/browser/useOsdkClient.d.ts.map +0 -1
  90. package/build/browser/useOsdkMetadata.d.ts.map +0 -1
  91. package/build/esm/OsdkContext.d.ts +0 -6
  92. package/build/esm/OsdkContext.d.ts.map +0 -1
  93. package/build/esm/OsdkProvider.d.ts +0 -7
  94. package/build/esm/OsdkProvider.d.ts.map +0 -1
  95. package/build/esm/index.d.ts +0 -3
  96. package/build/esm/index.d.ts.map +0 -1
  97. package/build/esm/useOsdkClient.d.ts +0 -3
  98. package/build/esm/useOsdkClient.d.ts.map +0 -1
  99. package/build/esm/useOsdkMetadata.d.ts +0 -8
  100. package/build/esm/useOsdkMetadata.d.ts.map +0 -1
@@ -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
@@ -0,0 +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":"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","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}"]}
@@ -0,0 +1,71 @@
1
+ import { Client, ActionDefinition, ActionValidationError, ObjectTypeDefinition, WhereClause, Osdk } from '@osdk/client';
2
+ import { ObservableClient, ActionSignatureFromDef } from '@osdk/client/unstable-do-not-use';
3
+ import React from 'react';
4
+ import { ObjectTypeDefinition as ObjectTypeDefinition$1, Osdk as Osdk$1, PrimaryKeyType } from '@osdk/api';
5
+ export { u as useOsdkClient } from '../useOsdkClient-B4iwHO1H.cjs';
6
+
7
+ interface OsdkProviderOptions {
8
+ children: React.ReactNode;
9
+ client: Client;
10
+ store: ObservableClient;
11
+ }
12
+ declare function OsdkProvider2({ children, client, store, }: OsdkProviderOptions): React.JSX.Element;
13
+
14
+ interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
15
+ applyAction: (args: Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0], opts: ObservableClient.ApplyActionOptions) => Promise<unknown>;
16
+ error: undefined | Partial<{
17
+ actionValidation: ActionValidationError;
18
+ unknown: unknown;
19
+ }>;
20
+ data: unknown;
21
+ }
22
+ declare function useOsdkAction<Q extends ActionDefinition<any>>(actionDef: Q): UseOsdkActionResult<Q>;
23
+
24
+ interface UseOsdkListOptions<T extends ObjectTypeDefinition> {
25
+ where: WhereClause<T>;
26
+ /**
27
+ * The number of milliseconds to wait after the last observed list change.
28
+ *
29
+ * Two uses of `useOsdkList` with the where clause will only trigger one
30
+ * network request if the second is within `dedupeIntervalMs`.
31
+ */
32
+ dedupeIntervalMs?: number;
33
+ }
34
+ interface UseOsdkListResult<T extends ObjectTypeDefinition> {
35
+ fetchMore: (() => Promise<unknown>) | undefined;
36
+ data: Osdk.Instance<T>[];
37
+ isLoading: boolean;
38
+ error: undefined;
39
+ /**
40
+ * Refers to whether the ordered list of objects (only considering the $primaryKey)
41
+ * is optimistic or not.
42
+ *
43
+ * If you need to know if the contents of the list are optimistic you can
44
+ * do that on a per object basis with useOsdkObject
45
+ */
46
+ isOptimistic: boolean;
47
+ }
48
+ declare function useOsdkList<T extends ObjectTypeDefinition>(type: T, opts: UseOsdkListOptions<T>): UseOsdkListResult<T>;
49
+
50
+ interface UseOsdkObjectResult<Q extends ObjectTypeDefinition$1> {
51
+ object: Osdk$1.Instance<Q> | undefined;
52
+ isLoading: boolean;
53
+ /**
54
+ * Refers to whether the object is optimistic or not.
55
+ */
56
+ isOptimistic: boolean;
57
+ forceUpdate: () => void;
58
+ }
59
+ /**
60
+ * @param obj an existing `Osdk.Instance` object to get metadata for.
61
+ */
62
+ declare function useOsdkObject<Q extends ObjectTypeDefinition$1>(obj: Osdk$1.Instance<Q>): UseOsdkObjectResult<Q>;
63
+ /**
64
+ * Loads an object by type and primary key.
65
+ *
66
+ * @param type
67
+ * @param primaryKey
68
+ */
69
+ declare function useOsdkObject<Q extends ObjectTypeDefinition$1>(type: Q, primaryKey: PrimaryKeyType<Q>): UseOsdkObjectResult<Q>;
70
+
71
+ export { OsdkProvider2, useOsdkAction, useOsdkList, useOsdkObject };
@@ -0,0 +1,5 @@
1
+ import { Client } from '@osdk/client';
2
+
3
+ declare function useOsdkClient(): Client;
4
+
5
+ export { useOsdkClient as u };
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import React from "react";
17
18
  function fakeClientFn(..._args) {
18
19
  throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
@@ -20,7 +21,7 @@ function fakeClientFn(..._args) {
20
21
  const fakeClient = Object.assign(fakeClientFn, {
21
22
  fetchMetadata: fakeClientFn
22
23
  });
23
- export const OsdkContext = React.createContext({
24
+ export const OsdkContext = /*#__PURE__*/React.createContext({
24
25
  client: fakeClient
25
26
  });
26
27
  //# sourceMappingURL=OsdkContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OsdkContext.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext","createContext","client"],"sources":["OsdkContext.js"],"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 */\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 = React.createContext({\n client: fakeClient,\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,YAAYA,CAAC,GAAGC,KAAK,EAAE;EAC5B,MAAM,IAAIC,KAAK,CAAC,sEAAsE,CAAC;AAC3F;AACA,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAACL,YAAY,EAAE;EAC3CM,aAAa,EAAEN;AACnB,CAAC,CAAC;AACF,OAAO,MAAMO,WAAW,GAAGR,KAAK,CAACS,aAAa,CAAC;EAC3CC,MAAM,EAAEN;AACZ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"OsdkContext.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext","createContext","client"],"sources":["OsdkContext.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 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\nexport const OsdkContext: React.Context<{\n client: Client;\n}> = React.createContext<{ client: Client }>({\n client: fakeClient,\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,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;AAEZ,OAAO,MAAMO,WAEX,gBAAGR,KAAK,CAACS,aAAa,CAAqB;EAC3CC,MAAM,EAAEN;AACV,CAAC,CAAC","ignoreList":[]}
@@ -13,13 +13,14 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import React from "react";
17
18
  import { OsdkContext } from "./OsdkContext.js";
18
19
  export function OsdkProvider({
19
20
  children,
20
21
  client
21
22
  }) {
22
- return React.createElement(OsdkContext.Provider, {
23
+ return /*#__PURE__*/React.createElement(OsdkContext.Provider, {
23
24
  value: {
24
25
  client
25
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OsdkProvider.js","names":["React","OsdkContext","OsdkProvider","children","client","createElement","Provider","value"],"sources":["OsdkProvider.js"],"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 */\nimport React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nexport function OsdkProvider({ children, client, }) {\n return (React.createElement(OsdkContext.Provider, { value: { client } }, children));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,OAAO,SAASC,YAAYA,CAAC;EAAEC,QAAQ;EAAEC;AAAQ,CAAC,EAAE;EAChD,OAAQJ,KAAK,CAACK,aAAa,CAACJ,WAAW,CAACK,QAAQ,EAAE;IAAEC,KAAK,EAAE;MAAEH;IAAO;EAAE,CAAC,EAAED,QAAQ,CAAC;AACtF","ignoreList":[]}
1
+ {"version":3,"file":"OsdkProvider.js","names":["React","OsdkContext","OsdkProvider","children","client","createElement","Provider","value"],"sources":["OsdkProvider.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 React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\nexport function OsdkProvider({\n children,\n client,\n}: {\n children: React.ReactNode;\n client: Client;\n}): React.JSX.Element {\n return (\n <OsdkContext.Provider value={{ client }}>{children}</OsdkContext.Provider>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,OAAO,SAASC,YAAYA,CAAC;EAC3BC,QAAQ;EACRC;AAIF,CAAC,EAAqB;EACpB,oBACEJ,KAAA,CAAAK,aAAA,CAACJ,WAAW,CAACK,QAAQ;IAACC,KAAK,EAAE;MAAEH;IAAO;EAAE,GAAED,QAA+B,CAAC;AAE9E","ignoreList":[]}
@@ -13,6 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
17
+ /**
18
+ * @module @osdk/react
19
+ */
20
+
16
21
  export { OsdkProvider } from "./OsdkProvider.js";
17
22
  export { useOsdkClient } from "./useOsdkClient.js";
18
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["OsdkProvider","useOsdkClient"],"sources":["index.js"],"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 */\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;AACA,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":[]}