@osdk/react 0.7.0-beta.3 → 0.7.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @osdkkit/react
2
2
 
3
+ ## 0.7.0-beta.4
4
+
5
+ ### Minor Changes
6
+
7
+ - 46ae415: improve useOsdkObject, useOsdkObjects error handling
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [ab29baa]
12
+ - @osdk/client@2.5.0-beta.7
13
+ - @osdk/api@2.5.0-beta.7
14
+
3
15
  ## 0.7.0-beta.3
4
16
 
5
17
  ### Minor Changes
@@ -48,11 +48,17 @@ export function useOsdkObject(...args) {
48
48
  mode
49
49
  }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);
50
50
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
51
+ let error;
52
+ if (payload && "error" in payload && payload.error) {
53
+ error = payload.error;
54
+ } else if (payload?.status === "error") {
55
+ error = new Error("Failed to load object");
56
+ }
51
57
  return {
52
58
  object: payload?.object,
53
59
  isLoading: payload?.status === "loading",
54
60
  isOptimistic: !!payload?.isOptimistic,
55
- error: payload && "error" in payload ? payload.error : undefined,
61
+ error,
56
62
  forceUpdate: () => {
57
63
  throw "not implemented";
58
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","mode","length","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","observer","observeObject","payload","useSyncExternalStore","object","isLoading","status","isOptimistic","error","forceUpdate"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectTypeDefinition, Osdk, PrimaryKeyType } from \"@osdk/api\";\nimport type { ObserveObjectArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args: [obj: Osdk.Instance<Q>] | [type: Q, primaryKey: PrimaryKeyType<Q>]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n ),\n [observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAehD;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3B,GAAGC,IAAwE,EACnD;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA,MAAMK,IAAI,GAAGH,IAAI,CAACI,MAAM,KAAK,CAAC,GAAG,SAAS,GAAGC,SAAS;EACtD,MAAMC,UAAU,GAAGN,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACO,WAAW,GAAGP,IAAI,CAAC,CAAC,CAAC,CAACQ,OAAO;EAC5E,MAAMC,UAAU,GAAGT,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACU,WAAW,GAAGV,IAAI,CAAC,CAAC,CAAC;EAEpE,MAAM;IAAEW,SAAS;IAAEC;EAAY,CAAC,GAAGhB,KAAK,CAACiB,OAAO,CAC9C,MACEhB,iBAAiB,CACdiB,QAAQ,IACPb,gBAAgB,CAACc,aAAa,CAC5BT,UAAU,EACVG,UAAU,EACV;IACEN;EACF,CAAC,EACDW,QACF,CAAC,EACH,UAAUR,UAAU,IAAIG,UAAU,EACpC,CAAC,EACH,CAACR,gBAAgB,EAAEK,UAAU,EAAEG,UAAU,EAAEN,IAAI,CACjD,CAAC;EAED,MAAMa,OAAO,GAAGpB,KAAK,CAACqB,oBAAoB,CAACN,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAO;IACLM,MAAM,EAAEF,OAAO,EAAEE,MAAsC;IACvDC,SAAS,EAAEH,OAAO,EAAEI,MAAM,KAAK,SAAS;IACxCC,YAAY,EAAE,CAAC,CAACL,OAAO,EAAEK,YAAY;IACrCC,KAAK,EAAEN,OAAO,IAAI,OAAO,IAAIA,OAAO,GAAGA,OAAO,CAACM,KAAK,GAAGjB,SAAS;IAChEkB,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,iBAAiB;IACzB;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","mode","length","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","observer","observeObject","payload","useSyncExternalStore","error","status","Error","object","isLoading","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 { ObserveObjectArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args: [obj: Osdk.Instance<Q>] | [type: Q, primaryKey: PrimaryKeyType<Q>]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n ),\n [observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw \"not implemented\";\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;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,CAACE,KAAK;EACvB,CAAC,MAAM,IAAIF,OAAO,EAAEG,MAAM,KAAK,OAAO,EAAE;IACtCD,KAAK,GAAG,IAAIE,KAAK,CAAC,uBAAuB,CAAC;EAC5C;EAEA,OAAO;IACLC,MAAM,EAAEL,OAAO,EAAEK,MAAsC;IACvDC,SAAS,EAAEN,OAAO,EAAEG,MAAM,KAAK,SAAS;IACxCI,YAAY,EAAE,CAAC,CAACP,OAAO,EAAEO,YAAY;IACrCL,KAAK;IACLM,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,iBAAiB;IACzB;EACF,CAAC;AACH","ignoreList":[]}
@@ -45,10 +45,15 @@ export function useOsdkObjects(type, {
45
45
  streamUpdates
46
46
  }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);
47
47
  const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
48
- // TODO: we need to expose the error in the result
48
+ let error;
49
+ if (listPayload && "error" in listPayload && listPayload.error) {
50
+ error = listPayload.error;
51
+ } else if (listPayload?.status === "error") {
52
+ error = new Error("Failed to load objects");
53
+ }
49
54
  return {
50
55
  fetchMore: listPayload?.fetchMore,
51
- error: listPayload && "error" in listPayload ? listPayload?.error : undefined,
56
+ error,
52
57
  data: listPayload?.resolvedList,
53
58
  isLoading: listPayload?.status === "loading",
54
59
  isOptimistic: listPayload?.isOptimistic ?? false
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","observer","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","error","undefined","data","resolvedList","isLoading","status","isOptimistic"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n\n // FIXME populate error!\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n>(\n type: Q,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<Q> = {},\n): UseOsdkListResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, type, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload\n ? listPayload?.error\n : undefined,\n data: listPayload?.resolvedList as Osdk.Instance<Q>[],\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA6FhD,OAAO,SAASC,cAAcA,CAG5BC,IAAO,EACP;EACEC,QAAQ;EACRC,OAAO;EACPC,gBAAgB;EAChBC,KAAK,GAAG,CAAC,CAAC;EACVC;AACwB,CAAC,GAAG,CAAC,CAAC,EACV;EACtB,MAAM;IAAEC;EAAiB,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;;EAE3D;AACF;AACA;AACA;EACE,MAAMU,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAACL,KAAK,IAAI,CAAC,CAAC,CAAC;EAExE,MAAM;IAAEM,SAAS;IAAEC;EAAY,CAAC,GAAGf,KAAK,CAACgB,OAAO,CAC9C,MACEf,iBAAiB,CACdgB,QAAQ,IACPP,gBAAgB,CAACQ,WAAW,CAAC;IAC3Bd,IAAI;IACJI,KAAK,EAAEI,UAAU;IACjBO,cAAc,EAAEZ,gBAAgB,IAAI,KAAK;IACzCF,QAAQ;IACRC,OAAO;IACPG;EACF,CAAC,EAAEQ,QAAQ,CAAC,EACdG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,QAAQlB,IAAI,CAACmB,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,EAAE,GACpD,KAAK,CACX,CAAC,EACH,CAACF,gBAAgB,EAAEN,IAAI,EAAEQ,UAAU,EAAEL,gBAAgB,CACvD,CAAC;EAED,MAAMmB,WAAW,GAAG1B,KAAK,CAAC2B,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EACtE;EACA,OAAO;IACLa,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,KAAK,EAAEH,WAAW,IAAI,OAAO,IAAIA,WAAW,GACxCA,WAAW,EAAEG,KAAK,GAClBC,SAAS;IACbC,IAAI,EAAEL,WAAW,EAAEM,YAAkC;IACrDC,SAAS,EAAEP,WAAW,EAAEQ,MAAM,KAAK,SAAS;IAC5CC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","observer","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","error","status","Error","fetchMore","data","resolvedList","isLoading","isOptimistic"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n>(\n type: Q,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<Q> = {},\n): UseOsdkListResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, type, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.fetchMore,\n error,\n data: listPayload?.resolvedList as Osdk.Instance<Q>[],\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA2FhD,OAAO,SAASC,cAAcA,CAG5BC,IAAO,EACP;EACEC,QAAQ;EACRC,OAAO;EACPC,gBA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C,SAAS,EAAER,WAAW,EAAEG,MAAM,KAAK,SAAS;IAC5CM,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -233,11 +233,17 @@ function useOsdkObject(...args) {
233
233
  mode
234
234
  }, observer)), [observableClient, objectType, primaryKey, mode]);
235
235
  const payload = React4__default.default.useSyncExternalStore(subscribe, getSnapShot);
236
+ let error;
237
+ if (payload && "error" in payload && payload.error) {
238
+ error = payload.error;
239
+ } else if (payload?.status === "error") {
240
+ error = new Error("Failed to load object");
241
+ }
236
242
  return {
237
243
  object: payload?.object,
238
244
  isLoading: payload?.status === "loading",
239
245
  isOptimistic: !!payload?.isOptimistic,
240
- error: payload && "error" in payload ? payload.error : void 0,
246
+ error,
241
247
  forceUpdate: () => {
242
248
  throw "not implemented";
243
249
  }
@@ -266,9 +272,15 @@ function useOsdkObjects(type, {
266
272
  streamUpdates
267
273
  }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);
268
274
  const listPayload = React4__default.default.useSyncExternalStore(subscribe, getSnapShot);
275
+ let error;
276
+ if (listPayload && "error" in listPayload && listPayload.error) {
277
+ error = listPayload.error;
278
+ } else if (listPayload?.status === "error") {
279
+ error = new Error("Failed to load objects");
280
+ }
269
281
  return {
270
282
  fetchMore: listPayload?.fetchMore,
271
- error: listPayload && "error" in listPayload ? listPayload?.error : void 0,
283
+ error,
272
284
  data: listPayload?.resolvedList,
273
285
  isLoading: listPayload?.status === "loading",
274
286
  isOptimistic: listPayload?.isOptimistic ?? false
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/makeExternalStore.ts","../../../src/new/useLinks.ts","../../../src/new/useOsdkAction.ts","../../../src/new/useOsdkObject.ts","../../../src/new/useOsdkObjects.ts"],"names":["useMemo","createObservableClient","React","OsdkContext","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AAI,QAAa,KAAA,YAAA,GAAe,CAAQ,KAAA,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA,EAAI,KAAK,SAAU,CAAA,UAAU,CAAC,CAAA,CAAA,GAAK,MAAM,CAAA,EAAG,CAAC,gBAAkB,EAAA,IAAA,EAAM,UAAY,EAAA,gBAAgB,CAAC,CAAA;AAC5K,EAAA,MAAM,WAAcA,GAAAA,uBAAAA,CAAM,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AAErE,EAAO,OAAA;AAAA,IACL,WAAW,WAAa,EAAA,SAAA;AAAA,IACxB,KAAO,EAAA,WAAA,IAAe,OAAW,IAAA,WAAA,GAAc,aAAa,KAAQ,GAAA,MAAA;AAAA,IACpE,MAAM,WAAa,EAAA,YAAA;AAAA,IACnB,SAAA,EAAW,aAAa,MAAW,KAAA,SAAA;AAAA,IACnC,YAAA,EAAc,aAAa,YAAgB,IAAA;AAAA,GAC7C;AACF","file":"experimental.cjs","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nfunction fakeClientFn(..._args) {\n throw new Error(\"This is not a real client. Did you forget to <OsdkContext.Provider>?\");\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\nexport const OsdkContext2 = /*#__PURE__*/React.createContext({\n client: fakeClient,\n observableClient: undefined\n});","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React, { useMemo } from \"react\";\nimport { OsdkContext } from \"../OsdkContext.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n observableClient\n}) {\n observableClient = useMemo(() => observableClient ?? createObservableClient(client), [client, observableClient]);\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n observableClient\n }\n }, /*#__PURE__*/React.createElement(OsdkContext.Provider, {\n value: {\n client\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\nexport function makeExternalStore(createObservation, name) {\n let lastResult;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n const obs = createObservation({\n next: payload => {\n lastResult = payload;\n notifyUpdate();\n },\n error: error => {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n },\n complete: () => {}\n });\n return () => {\n obs.unsubscribe();\n };\n }\n return {\n subscribe,\n getSnapShot\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nconst emptyArray = Object.freeze([]);\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks(objects, linkName, options = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // Convert single object to array for consistent handling\n const objectsArray = React.useMemo(() => {\n return objects === undefined ? emptyArray : Array.isArray(objects) ? objects : [objects];\n }, [objects]);\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => {\n return makeExternalStore(observer => observableClient.observeLinks(objectsArray, linkName, {\n linkName,\n where: options.where,\n pageSize: options.pageSize,\n orderBy: options.orderBy,\n mode: options.mode\n }, observer), `links ${linkName} for ${objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\")}`);\n }, [observableClient, objectsArray, linkName, options.where, options.pageSize, options.orderBy, options.mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n links: payload?.resolvedList,\n isLoading: payload?.status === \"loading\",\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.fetchMore,\n hasMore: payload?.hasMore ?? 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 { ActionValidationError } from \"@osdk/client\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkAction(actionDef) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const [isPending, setPending] = React.useState(false);\n const [isValidating, setValidating] = React.useState(false);\n const [validationResult, setValidationResult] = React.useState();\n const abortControllerRef = React.useRef(null);\n const applyAction = React.useCallback(async function applyAction(hookArgs) {\n try {\n // If validation is in progress, abort it\n if (isValidating && abortControllerRef.current) {\n abortControllerRef.current.abort();\n setValidating(false);\n }\n setPending(true);\n setError(undefined);\n if (Array.isArray(hookArgs)) {\n const updates = [];\n const args = hookArgs.map(a => {\n const {\n $optimisticUpdate,\n ...args\n } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: ctx => {\n for (const update of updates) {\n update?.(ctx);\n }\n }\n });\n setData(r);\n return r;\n } else {\n const {\n $optimisticUpdate,\n ...args\n } = hookArgs;\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, actionDef, isValidating]);\n const validateAction = React.useCallback(async function validateAction(args) {\n try {\n // Check if action is being applied\n if (isPending) {\n return undefined;\n }\n\n // Abort any existing validation\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n\n // Create new AbortController\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n setValidating(true);\n setError(undefined);\n const result = await observableClient.validateAction(actionDef, args);\n\n // Check if aborted\n if (abortController.signal.aborted) {\n return undefined;\n }\n setValidationResult(result);\n return result;\n } catch (e) {\n // Check if it was aborted\n if (e instanceof Error && e.name === \"AbortError\") {\n return undefined;\n }\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n throw e;\n } finally {\n setValidating(false);\n }\n }, [observableClient, actionDef, isPending]);\n\n // Cleanup on unmount\n React.useEffect(() => {\n return () => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n };\n }, []);\n return {\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\n\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\n\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject(...args) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {\n mode\n }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n object: payload?.object,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkObjects(type, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates\n} = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, observer), process.env.NODE_ENV !== \"production\" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload ? listPayload?.error : undefined,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false\n };\n}"]}
1
+ {"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/makeExternalStore.ts","../../../src/new/useLinks.ts","../../../src/new/useOsdkAction.ts","../../../src/new/useOsdkObject.ts","../../../src/new/useOsdkObjects.ts"],"names":["useMemo","createObservableClient","React","OsdkContext","applyAction","args","ActionValidationError","validateAction"],"mappings":";;;;;;;;;;;AAiBA,SAAS,gBAAgB,KAAO,EAAA;AAC9B,EAAM,MAAA,IAAI,MAAM,sEAAsE,CAAA;AACxF;AACA,IAAM,UAAA,GAAa,MAAO,CAAA,MAAA,CAAO,YAAc,EAAA;AAAA,EAC7C,aAAe,EAAA;AACjB,CAAC,CAAA;AACM,IAAM,YAAA,2CAAkC,aAAc,CAAA;AAAA,EAC3D,MAAQ,EAAA,UAAA;AAAA,EACR,gBAAkB,EAAA;AACpB,CAAC,CAAA;;;ACNM,SAAS,aAAc,CAAA;AAAA,EAC5B,QAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAG,EAAA;AACD,EAAmB,gBAAA,GAAAA,cAAA,CAAQ,MAAM,gBAAoB,IAAAC,uCAAA,CAAuB,MAAM,CAAG,EAAA,CAAC,MAAQ,EAAA,gBAAgB,CAAC,CAAA;AAC/G,EAAA,uBAAoBC,uBAAAA,CAAM,aAAc,CAAA,YAAA,CAAa,QAAU,EAAA;AAAA,IAC7D,KAAO,EAAA;AAAA,MACL,MAAA;AAAA,MACA;AAAA;AACF,GACc,kBAAAA,uBAAM,CAAA,aAAA,CAAcC,8BAAY,QAAU,EAAA;AAAA,IACxD,KAAO,EAAA;AAAA,MACL;AAAA;AACF,GACF,EAAG,QAAQ,CAAC,CAAA;AACd;;;ACpBO,SAAS,iBAAA,CAAkB,mBAAmB,IAAM,EAAA;AACzD,EAAI,IAAA,UAAA;AACJ,EAAA,SAAS,WAAc,GAAA;AACrB,IAAO,OAAA,UAAA;AAAA;AAET,EAAA,SAAS,UAAU,YAAc,EAAA;AAC/B,IAAA,MAAM,MAAM,iBAAkB,C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* Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nfunction fakeClientFn(..._args) {\n throw new Error(\"This is not a real client. Did you forget to <OsdkContext.Provider>?\");\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\nexport const OsdkContext2 = /*#__PURE__*/React.createContext({\n client: fakeClient,\n observableClient: undefined\n});","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React, { useMemo } from \"react\";\nimport { OsdkContext } from \"../OsdkContext.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n observableClient\n}) {\n observableClient = useMemo(() => observableClient ?? createObservableClient(client), [client, observableClient]);\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n observableClient\n }\n }, /*#__PURE__*/React.createElement(OsdkContext.Provider, {\n value: {\n client\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\nexport function makeExternalStore(createObservation, name) {\n let lastResult;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n const obs = createObservation({\n next: payload => {\n lastResult = payload;\n notifyUpdate();\n },\n error: error => {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n },\n complete: () => {}\n });\n return () => {\n obs.unsubscribe();\n };\n }\n return {\n subscribe,\n getSnapShot\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nconst emptyArray = Object.freeze([]);\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks(objects, linkName, options = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // Convert single object to array for consistent handling\n const objectsArray = React.useMemo(() => {\n return objects === undefined ? emptyArray : Array.isArray(objects) ? objects : [objects];\n }, [objects]);\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => {\n return makeExternalStore(observer => observableClient.observeLinks(objectsArray, linkName, {\n linkName,\n where: options.where,\n pageSize: options.pageSize,\n orderBy: options.orderBy,\n mode: options.mode\n }, observer), `links ${linkName} for ${objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\")}`);\n }, [observableClient, objectsArray, linkName, options.where, options.pageSize, options.orderBy, options.mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n links: payload?.resolvedList,\n isLoading: payload?.status === \"loading\",\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.fetchMore,\n hasMore: payload?.hasMore ?? 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 { ActionValidationError } from \"@osdk/client\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkAction(actionDef) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const [isPending, setPending] = React.useState(false);\n const [isValidating, setValidating] = React.useState(false);\n const [validationResult, setValidationResult] = React.useState();\n const abortControllerRef = React.useRef(null);\n const applyAction = React.useCallback(async function applyAction(hookArgs) {\n try {\n // If validation is in progress, abort it\n if (isValidating && abortControllerRef.current) {\n abortControllerRef.current.abort();\n setValidating(false);\n }\n setPending(true);\n setError(undefined);\n if (Array.isArray(hookArgs)) {\n const updates = [];\n const args = hookArgs.map(a => {\n const {\n $optimisticUpdate,\n ...args\n } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: ctx => {\n for (const update of updates) {\n update?.(ctx);\n }\n }\n });\n setData(r);\n return r;\n } else {\n const {\n $optimisticUpdate,\n ...args\n } = hookArgs;\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, actionDef, isValidating]);\n const validateAction = React.useCallback(async function validateAction(args) {\n try {\n // Check if action is being applied\n if (isPending) {\n return undefined;\n }\n\n // Abort any existing validation\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n\n // Create new AbortController\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n setValidating(true);\n setError(undefined);\n const result = await observableClient.validateAction(actionDef, args);\n\n // Check if aborted\n if (abortController.signal.aborted) {\n return undefined;\n }\n setValidationResult(result);\n return result;\n } catch (e) {\n // Check if it was aborted\n if (e instanceof Error && e.name === \"AbortError\") {\n return undefined;\n }\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n throw e;\n } finally {\n setValidating(false);\n }\n }, [observableClient, actionDef, isPending]);\n\n // Cleanup on unmount\n React.useEffect(() => {\n return () => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n };\n }, []);\n return {\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\n\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\n\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject(...args) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {\n mode\n }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n let error;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n return {\n object: payload?.object,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkObjects(type, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates\n} = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, observer), process.env.NODE_ENV !== \"production\" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n let error;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n return {\n fetchMore: listPayload?.fetchMore,\n error,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false\n };\n}"]}
@@ -48,11 +48,17 @@ export function useOsdkObject(...args) {
48
48
  mode
49
49
  }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);
50
50
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
51
+ let error;
52
+ if (payload && "error" in payload && payload.error) {
53
+ error = payload.error;
54
+ } else if (payload?.status === "error") {
55
+ error = new Error("Failed to load object");
56
+ }
51
57
  return {
52
58
  object: payload?.object,
53
59
  isLoading: payload?.status === "loading",
54
60
  isOptimistic: !!payload?.isOptimistic,
55
- error: payload && "error" in payload ? payload.error : undefined,
61
+ error,
56
62
  forceUpdate: () => {
57
63
  throw "not implemented";
58
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","mode","length","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","observer","observeObject","payload","useSyncExternalStore","object","isLoading","status","isOptimistic","error","forceUpdate"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectTypeDefinition, Osdk, PrimaryKeyType } from \"@osdk/api\";\nimport type { ObserveObjectArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args: [obj: Osdk.Instance<Q>] | [type: Q, primaryKey: PrimaryKeyType<Q>]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n ),\n [observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAehD;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3B,GAAGC,IAAwE,EACnD;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA,MAAMK,IAAI,GAAGH,IAAI,CAACI,MAAM,KAAK,CAAC,GAAG,SAAS,GAAGC,SAAS;EACtD,MAAMC,UAAU,GAAGN,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACO,WAAW,GAAGP,IAAI,CAAC,CAAC,CAAC,CAACQ,OAAO;EAC5E,MAAMC,UAAU,GAAGT,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACU,WAAW,GAAGV,IAAI,CAAC,CAAC,CAAC;EAEpE,MAAM;IAAEW,SAAS;IAAEC;EAAY,CAAC,GAAGhB,KAAK,CAACiB,OAAO,CAC9C,MACEhB,iBAAiB,CACdiB,QAAQ,IACPb,gBAAgB,CAACc,aAAa,CAC5BT,UAAU,EACVG,UAAU,EACV;IACEN;EACF,CAAC,EACDW,QACF,CAAC,EACH,UAAUR,UAAU,IAAIG,UAAU,EACpC,CAAC,EACH,CAACR,gBAAgB,EAAEK,UAAU,EAAEG,UAAU,EAAEN,IAAI,CACjD,CAAC;EAED,MAAMa,OAAO,GAAGpB,KAAK,CAACqB,oBAAoB,CAACN,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAO;IACLM,MAAM,EAAEF,OAAO,EAAEE,MAAsC;IACvDC,SAAS,EAAEH,OAAO,EAAEI,MAAM,KAAK,SAAS;IACxCC,YAAY,EAAE,CAAC,CAACL,OAAO,EAAEK,YAAY;IACrCC,KAAK,EAAEN,OAAO,IAAI,OAAO,IAAIA,OAAO,GAAGA,OAAO,CAACM,KAAK,GAAGjB,SAAS;IAChEkB,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,iBAAiB;IACzB;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","mode","length","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","observer","observeObject","payload","useSyncExternalStore","error","status","Error","object","isLoading","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 { ObserveObjectArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args: [obj: Osdk.Instance<Q>] | [type: Q, primaryKey: PrimaryKeyType<Q>]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n ),\n [observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw \"not implemented\";\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAehD;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3B,GAAGC,IAAwE,EACnD;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA,MAAMK,IAAI,GAAGH,IAAI,CAACI,MAAM,KAAK,CAAC,GAAG,SAAS,GAAGC,SAAS;EACtD,MAAMC,UAAU,GAAGN,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACO,WAAW,GAAGP,IAAI,CAAC,CAAC,CAAC,CAACQ,OAAO;EAC5E,MAAMC,UAAU,GAAGT,IAAI,CAACI,MAAM,KAAK,CAAC,GAAGJ,IAAI,CAAC,CAAC,CAAC,CAACU,WAAW,GAAGV,IAAI,CAAC,CAAC,CAAC;EAEpE,MAAM;IAAEW,SAAS;IAAEC;EAAY,CAAC,GAAGhB,KAAK,CAACiB,OAAO,CAC9C,MACEhB,iBAAiB,CACdiB,QAAQ,IACPb,gBAAgB,CAACc,aAAa,CAC5BT,UAAU,EACVG,UAAU,EACV;IACEN;EACF,CAAC,EACDW,QACF,CAAC,EACH,UAAUR,UAAU,IAAIG,UAAU,EACpC,CAAC,EACH,CAACR,gBAAgB,EAAEK,UAAU,EAAEG,UAAU,EAAEN,IAAI,CACjD,CAAC;EAED,MAAMa,OAAO,GAAGpB,KAAK,CAACqB,oBAAoB,CAACN,SAAS,EAAEC,WAAW,CAAC;EAElE,IAAIM,KAAwB;EAC5B,IAAIF,OAAO,IAAI,OAAO,IAAIA,OAAO,IAAIA,OAAO,CAACE,KAAK,EAAE;IAClDA,KAAK,GAAGF,OAAO,CAACE,KAAK;EACvB,CAAC,MAAM,IAAIF,OAAO,EAAEG,MAAM,KAAK,OAAO,EAAE;IACtCD,KAAK,GAAG,IAAIE,KAAK,CAAC,uBAAuB,CAAC;EAC5C;EAEA,OAAO;IACLC,MAAM,EAAEL,OAAO,EAAEK,MAAsC;IACvDC,SAAS,EAAEN,OAAO,EAAEG,MAAM,KAAK,SAAS;IACxCI,YAAY,EAAE,CAAC,CAACP,OAAO,EAAEO,YAAY;IACrCL,KAAK;IACLM,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,iBAAiB;IACzB;EACF,CAAC;AACH","ignoreList":[]}
@@ -45,10 +45,15 @@ export function useOsdkObjects(type, {
45
45
  streamUpdates
46
46
  }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);
47
47
  const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
48
- // TODO: we need to expose the error in the result
48
+ let error;
49
+ if (listPayload && "error" in listPayload && listPayload.error) {
50
+ error = listPayload.error;
51
+ } else if (listPayload?.status === "error") {
52
+ error = new Error("Failed to load objects");
53
+ }
49
54
  return {
50
55
  fetchMore: listPayload?.fetchMore,
51
- error: listPayload && "error" in listPayload ? listPayload?.error : undefined,
56
+ error,
52
57
  data: listPayload?.resolvedList,
53
58
  isLoading: listPayload?.status === "loading",
54
59
  isOptimistic: listPayload?.isOptimistic ?? false
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","observer","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","error","undefined","data","resolvedList","isLoading","status","isOptimistic"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n\n // FIXME populate error!\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n>(\n type: Q,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<Q> = {},\n): UseOsdkListResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, type, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload\n ? listPayload?.error\n : undefined,\n data: listPayload?.resolvedList as Osdk.Instance<Q>[],\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA6FhD,OAAO,SAASC,cAAcA,CAG5BC,IAAO,EACP;EACEC,QAAQ;EACRC,OAAO;EACPC,gBAAgB;EAChBC,KAAK,GAAG,CAAC,CAAC;EACVC;AACwB,CAAC,GAAG,CAAC,CAAC,EACV;EACtB,MAAM;IAAEC;EAAiB,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;;EAE3D;AACF;AACA;AACA;EACE,MAAMU,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAACL,KAAK,IAAI,CAAC,CAAC,CAAC;EAExE,MAAM;IAAEM,SAAS;IAAEC;EAAY,CAAC,GAAGf,KAAK,CAACgB,OAAO,CAC9C,MACEf,iBAAiB,CACdgB,QAAQ,IACPP,gBAAgB,CAACQ,WAAW,CAAC;IAC3Bd,IAAI;IACJI,KAAK,EAAEI,UAAU;IACjBO,cAAc,EAAEZ,gBAAgB,IAAI,KAAK;IACzCF,QAAQ;IACRC,OAAO;IACPG;EACF,CAAC,EAAEQ,QAAQ,CAAC,EACdG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,QAAQlB,IAAI,CAACmB,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,EAAE,GACpD,KAAK,CACX,CAAC,EACH,CAACF,gBAAgB,EAAEN,IAAI,EAAEQ,UAAU,EAAEL,gBAAgB,CACvD,CAAC;EAED,MAAMmB,WAAW,GAAG1B,KAAK,CAAC2B,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EACtE;EACA,OAAO;IACLa,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,KAAK,EAAEH,WAAW,IAAI,OAAO,IAAIA,WAAW,GACxCA,WAAW,EAAEG,KAAK,GAClBC,SAAS;IACbC,IAAI,EAAEL,WAAW,EAAEM,YAAkC;IACrDC,SAAS,EAAEP,WAAW,EAAEQ,MAAM,KAAK,SAAS;IAC5CC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","observer","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","error","status","Error","fetchMore","data","resolvedList","isLoading","isOptimistic"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n>(\n type: Q,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<Q> = {},\n): UseOsdkListResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, type, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.fetchMore,\n error,\n data: listPayload?.resolvedList as Osdk.Instance<Q>[],\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;A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E,KAAK;EAC3B,CAAC,MAAM,IAAIF,WAAW,EAAEG,MAAM,KAAK,OAAO,EAAE;IAC1CD,KAAK,GAAG,IAAIE,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEA,OAAO;IACLC,SAAS,EAAEL,WAAW,EAAEK,SAAS;IACjCH,KAAK;IACLI,IAAI,EAAEN,WAAW,EAAEO,YAAkC;IACrDC,SAAS,EAAER,WAAW,EAAEG,MAAM,KAAK,SAAS;IAC5CM,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cACE,qBACA,sBACA,MACA,cACA,mBACK,cAAe;AAMtB,iBAAiB,sBACf,UAAU,uBAAuB,qBACjC;;;;CAIA,QAAQ,YAAY;;;;CAKpB;;CAGA,aACG,KAAK,aAAa,OAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCnC;;;;;;;CAUA;AACD;AAED,iBAAiB,kBACf,UAAU,uBAAuB,qBACjC;CACA,kBAAkB;CAClB,MAAM,KAAK,SAAS;CACpB;CAGA,OAAO;;;;;;;;CASP;AACD;AAQD,OAAO,iBAAS,eACd,UAAU,uBAAuB,qBAEjCA,MAAM,GACN,EACE,UACA,SACA,kBACA,OACA,eACyB,GAAxB,sBAAsB,KACxB,kBAAkB","names":["type: Q"],"sources":["../../../src/new/useOsdkObjects.ts"],"version":3,"file":"useOsdkObjects.d.ts"}
1
+ {"mappings":"AAgBA,cACE,qBACA,sBACA,MACA,cACA,mBACK,cAAe;AAMtB,iBAAiB,sBACf,UAAU,uBAAuB,qBACjC;;;;CAIA,QAAQ,YAAY;;;;CAKpB;;CAGA,aACG,KAAK,aAAa,OAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCnC;;;;;;;CAUA;AACD;AAED,iBAAiB,kBACf,UAAU,uBAAuB,qBACjC;CACA,kBAAkB;CAClB,MAAM,KAAK,SAAS;CACpB;CACA,OAAO;;;;;;;;CASP;AACD;AAQD,OAAO,iBAAS,eACd,UAAU,uBAAuB,qBAEjCA,MAAM,GACN,EACE,UACA,SACA,kBACA,OACA,eACyB,GAAxB,sBAAsB,KACxB,kBAAkB","names":["type: Q"],"sources":["../../../src/new/useOsdkObjects.ts"],"version":3,"file":"useOsdkObjects.d.ts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/react",
3
- "version": "0.7.0-beta.3",
3
+ "version": "0.7.0-beta.4",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,9 +50,9 @@
50
50
  "react": "^18.3.1",
51
51
  "tiny-invariant": "^1.3.3",
52
52
  "typescript": "~5.5.4",
53
- "@osdk/api": "2.5.0-beta.5",
53
+ "@osdk/api": "2.5.0-beta.7",
54
+ "@osdk/client": "2.5.0-beta.7",
54
55
  "@osdk/monorepo.api-extractor": "~0.4.0-beta.1",
55
- "@osdk/client": "2.5.0-beta.5",
56
56
  "@osdk/monorepo.tsconfig": "~0.4.0-beta.1"
57
57
  },
58
58
  "publishConfig": {