@osdk/react 0.9.0-beta.1 → 0.9.0-beta.10

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/AGENTS.md +253 -0
  2. package/CHANGELOG.md +118 -0
  3. package/build/browser/intellisense.test.js +1 -1
  4. package/build/browser/intellisense.test.js.map +1 -1
  5. package/build/browser/new/makeExternalStore.js +2 -2
  6. package/build/browser/new/makeExternalStore.js.map +1 -1
  7. package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js +44 -0
  8. package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -0
  9. package/build/browser/new/platform-apis/admin/useFoundryUser.js +50 -0
  10. package/build/browser/new/platform-apis/admin/useFoundryUser.js.map +1 -0
  11. package/build/browser/new/platform-apis/admin/useFoundryUsersList.js +54 -0
  12. package/build/browser/new/platform-apis/admin/useFoundryUsersList.js.map +1 -0
  13. package/build/browser/new/useLinks.js +15 -8
  14. package/build/browser/new/useLinks.js.map +1 -1
  15. package/build/browser/new/useObjectSet.js +20 -4
  16. package/build/browser/new/useObjectSet.js.map +1 -1
  17. package/build/browser/new/useOsdkAction.js.map +1 -1
  18. package/build/browser/new/useOsdkAggregation.js +1 -1
  19. package/build/browser/new/useOsdkAggregation.js.map +1 -1
  20. package/build/browser/new/useOsdkFunction.js +101 -0
  21. package/build/browser/new/useOsdkFunction.js.map +1 -0
  22. package/build/browser/new/useOsdkObject.js +1 -1
  23. package/build/browser/new/useOsdkObject.js.map +1 -1
  24. package/build/browser/new/useOsdkObjects.js +4 -3
  25. package/build/browser/new/useOsdkObjects.js.map +1 -1
  26. package/build/browser/public/experimental.js +4 -0
  27. package/build/browser/public/experimental.js.map +1 -1
  28. package/build/browser/utils/usePlatformQuery.js +74 -0
  29. package/build/browser/utils/usePlatformQuery.js.map +1 -0
  30. package/build/cjs/{chunk-OVBG5VXE.cjs → chunk-V32JHU3O.cjs} +8 -3
  31. package/build/cjs/chunk-V32JHU3O.cjs.map +1 -0
  32. package/build/cjs/index.cjs +4 -4
  33. package/build/cjs/public/experimental.cjs +413 -67
  34. package/build/cjs/public/experimental.cjs.map +1 -1
  35. package/build/cjs/public/experimental.d.cts +279 -32
  36. package/build/esm/intellisense.test.js +1 -1
  37. package/build/esm/intellisense.test.js.map +1 -1
  38. package/build/esm/new/makeExternalStore.js +2 -2
  39. package/build/esm/new/makeExternalStore.js.map +1 -1
  40. package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js +44 -0
  41. package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -0
  42. package/build/esm/new/platform-apis/admin/useFoundryUser.js +50 -0
  43. package/build/esm/new/platform-apis/admin/useFoundryUser.js.map +1 -0
  44. package/build/esm/new/platform-apis/admin/useFoundryUsersList.js +54 -0
  45. package/build/esm/new/platform-apis/admin/useFoundryUsersList.js.map +1 -0
  46. package/build/esm/new/useLinks.js +15 -8
  47. package/build/esm/new/useLinks.js.map +1 -1
  48. package/build/esm/new/useObjectSet.js +20 -4
  49. package/build/esm/new/useObjectSet.js.map +1 -1
  50. package/build/esm/new/useOsdkAction.js.map +1 -1
  51. package/build/esm/new/useOsdkAggregation.js +1 -1
  52. package/build/esm/new/useOsdkAggregation.js.map +1 -1
  53. package/build/esm/new/useOsdkFunction.js +101 -0
  54. package/build/esm/new/useOsdkFunction.js.map +1 -0
  55. package/build/esm/new/useOsdkObject.js +1 -1
  56. package/build/esm/new/useOsdkObject.js.map +1 -1
  57. package/build/esm/new/useOsdkObjects.js +4 -3
  58. package/build/esm/new/useOsdkObjects.js.map +1 -1
  59. package/build/esm/public/experimental.js +4 -0
  60. package/build/esm/public/experimental.js.map +1 -1
  61. package/build/esm/utils/usePlatformQuery.js +74 -0
  62. package/build/esm/utils/usePlatformQuery.js.map +1 -0
  63. package/build/types/new/makeExternalStore.d.ts +1 -1
  64. package/build/types/new/makeExternalStore.d.ts.map +1 -1
  65. package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts +28 -0
  66. package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts.map +1 -0
  67. package/build/types/new/platform-apis/admin/useFoundryUser.d.ts +36 -0
  68. package/build/types/new/platform-apis/admin/useFoundryUser.d.ts.map +1 -0
  69. package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts +52 -0
  70. package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts.map +1 -0
  71. package/build/types/new/useLinks.d.ts +5 -5
  72. package/build/types/new/useLinks.d.ts.map +1 -1
  73. package/build/types/new/useObjectSet.d.ts +4 -0
  74. package/build/types/new/useObjectSet.d.ts.map +1 -1
  75. package/build/types/new/useOsdkAction.d.ts +3 -3
  76. package/build/types/new/useOsdkAction.d.ts.map +1 -1
  77. package/build/types/new/useOsdkAggregation.d.ts +10 -12
  78. package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
  79. package/build/types/new/useOsdkFunction.d.ts +112 -0
  80. package/build/types/new/useOsdkFunction.d.ts.map +1 -0
  81. package/build/types/new/useOsdkObjects.d.ts +31 -13
  82. package/build/types/new/useOsdkObjects.d.ts.map +1 -1
  83. package/build/types/public/experimental.d.ts +5 -0
  84. package/build/types/public/experimental.d.ts.map +1 -1
  85. package/build/types/utils/usePlatformQuery.d.ts +25 -0
  86. package/build/types/utils/usePlatformQuery.d.ts.map +1 -0
  87. package/docs/actions.md +414 -0
  88. package/docs/advanced-queries.md +663 -0
  89. package/docs/cache-management.md +213 -0
  90. package/docs/getting-started.md +382 -0
  91. package/docs/platform-apis.md +203 -0
  92. package/docs/querying-data.md +648 -0
  93. package/package.json +8 -4
  94. package/build/browser/new/types.js +0 -2
  95. package/build/browser/new/types.js.map +0 -1
  96. package/build/cjs/chunk-OVBG5VXE.cjs.map +0 -1
  97. package/build/esm/new/types.js +0 -2
  98. package/build/esm/new/types.js.map +0 -1
  99. package/build/types/new/types.d.ts +0 -5
  100. package/build/types/new/types.d.ts.map +0 -1
@@ -35,11 +35,18 @@ export function useLinks(objects, linkName, options = {}) {
35
35
  enabled = true,
36
36
  ...otherOptions
37
37
  } = options;
38
+ const stableWhere = React.useMemo(() => otherOptions.where, [JSON.stringify(otherOptions.where)]);
39
+ const stableOrderBy = React.useMemo(() => otherOptions.orderBy, [JSON.stringify(otherOptions.orderBy)]);
40
+ const objectsKey = React.useMemo(() => {
41
+ if (objects === undefined) return "";
42
+ const arr = Array.isArray(objects) ? objects : [objects];
43
+ return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(",");
44
+ }, [objects]);
38
45
 
39
46
  // Convert single object to array for consistent handling
40
47
  const objectsArray = React.useMemo(() => {
41
48
  return objects === undefined ? emptyArray : Array.isArray(objects) ? objects : [objects];
42
- }, [objects]);
49
+ }, [objectsKey, objects]);
43
50
  const {
44
51
  subscribe,
45
52
  getSnapShot
@@ -47,23 +54,23 @@ export function useLinks(objects, linkName, options = {}) {
47
54
  if (!enabled) {
48
55
  return makeExternalStore(() => ({
49
56
  unsubscribe: () => {}
50
- }), `links ${linkName} for ${objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(",")} [DISABLED]`);
57
+ }), `links ${linkName} for ${objectsKey} [DISABLED]`);
51
58
  }
52
59
  return makeExternalStore(observer => observableClient.observeLinks(objectsArray, linkName, {
53
60
  linkName,
54
- where: otherOptions.where,
61
+ where: stableWhere,
55
62
  pageSize: otherOptions.pageSize,
56
- orderBy: otherOptions.orderBy,
63
+ orderBy: stableOrderBy,
57
64
  mode: otherOptions.mode
58
- }, observer), `links ${linkName} for ${objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(",")}`);
59
- }, [enabled, observableClient, objectsArray, linkName, otherOptions.where, otherOptions.pageSize, otherOptions.orderBy, otherOptions.mode]);
65
+ }, observer), `links ${linkName} for ${objectsKey}`);
66
+ }, [enabled, observableClient, objectsArray, objectsKey, linkName, stableWhere, otherOptions.pageSize, stableOrderBy, otherOptions.mode]);
60
67
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
61
68
  return {
62
69
  links: payload?.resolvedList,
63
- isLoading: payload?.status === "loading",
70
+ isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
64
71
  isOptimistic: payload?.isOptimistic ?? false,
65
72
  error: payload?.error,
66
- fetchMore: payload?.fetchMore,
73
+ fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,
67
74
  hasMore: payload?.hasMore ?? false
68
75
  };
69
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","objectsArray","useMemo","undefined","Array","isArray","subscribe","getSnapShot","unsubscribe","map","obj","$apiName","$primaryKey","join","observer","observeLinks","where","pageSize","orderBy","mode","payload","useSyncExternalStore","links","resolvedList","isLoading","status","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.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 { LinkedType, LinkNames } from \"@osdk/api\";\nimport type {\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseLinksOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where clause for filtering linked objects\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the links list.\n */\n pageSize?: number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The mode to use for fetching data.\n * - undefined: Fetch data if not already in cache\n * - \"force\": Always fetch fresh data\n * - \"offline\": Only use cached data, don't make network requests\n */\n mode?: \"force\" | \"offline\";\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for employee data\n * const { object: employee } = useOsdkObject(Employee, employeeId);\n * const { links: reports } = useLinks(employee, \"reports\", {\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseLinksResult<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n links: Osdk.Instance<Q>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the links are optimistic or not.\n */\n isOptimistic: boolean;\n\n /**\n * Fetch more linked objects if pagination is supported\n */\n fetchMore: (() => Promise<unknown>) | undefined;\n\n /**\n * Indicates if there are more linked objects available to fetch\n */\n hasMore: boolean;\n}\n\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<\n T extends ObjectTypeDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, ...otherOptions } = options;\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n () => ({ unsubscribe: () => {} }),\n `links ${linkName} for ${\n objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\n \",\",\n )\n } [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: otherOptions.where,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n mode: otherOptions.mode,\n },\n observer,\n ),\n `links ${linkName} for ${\n objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\n \",\",\n )\n }`,\n );\n },\n [\n enabled,\n observableClient,\n objectsArray,\n linkName,\n otherOptions.where,\n otherOptions.pageSize,\n otherOptions.orderBy,\n otherOptions.mode,\n ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\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"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyEhD,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAItBC,OAA+D,EAC/DC,QAAW,EACXC,OAA0C,GAAG,CAAC,CAAC,EACb;EACl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AAC,EACD,CACEd,OAAO,EACPF,gBAAgB,EAChBI,YAAY,EACZN,QAAQ,EACRK,YAAY,CAACgB,KAAK,EAClBhB,YAAY,CAACiB,QAAQ,EACrBjB,YAAY,CAACkB,OAAO,EACpBlB,YAAY,CAACmB,IAAI,CAErB,CAAC;EAED,MAAMC,OAAO,GAAGjC,KAAK,CAACkC,oBAAoB,CACxCf,SAAS,EACTC,WACF,CAAC;EAED,OAAO;IACLe,KAAK,EAAEF,OAAO,EAAEG,YAAY;IAC5BC,SAAS,EAAEJ,OAAO,EAAEK,MAAM,KAAK,SAAS;IACxCC,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAEP,OAAO,EAAEO,KAAK;IACrBC,SAAS,EAAER,OAAO,EAAEQ,SAAS;IAC7BC,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","enabled","otherOptions","stableWhere","useMemo","where","JSON","stringify","stableOrderBy","orderBy","objectsKey","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","observer","observeLinks","pageSize","mode","payload","useSyncExternalStore","links","resolvedList","isLoading","status","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.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 LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseLinksOptions<\n T extends ObjectOrInterfaceDefinition,\n> {\n /**\n * Standard OSDK Where clause for filtering linked objects\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the links list.\n */\n pageSize?: number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The mode to use for fetching data.\n * - undefined: Fetch data if not already in cache\n * - \"force\": Always fetch fresh data\n * - \"offline\": Only use cached data, don't make network requests\n */\n mode?: \"force\" | \"offline\";\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for employee data\n * const { object: employee } = useOsdkObject(Employee, employeeId);\n * const { links: reports } = useLinks(employee, \"reports\", {\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseLinksResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n links: Osdk.Instance<Q>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the links are optimistic or not.\n */\n isOptimistic: boolean;\n\n /**\n * Fetch more linked objects if pagination is supported\n */\n fetchMore: (() => Promise<unknown>) | undefined;\n\n /**\n * Indicates if there are more linked objects available to fetch\n */\n hasMore: boolean;\n}\n\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<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, ...otherOptions } = options;\n\n const stableWhere = React.useMemo(\n () => otherOptions.where,\n [JSON.stringify(otherOptions.where)],\n );\n\n const stableOrderBy = React.useMemo(\n () => otherOptions.orderBy,\n [JSON.stringify(otherOptions.orderBy)],\n );\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n () => ({ unsubscribe: () => {} }),\n `links ${linkName} for ${objectsKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: stableWhere,\n pageSize: otherOptions.pageSize,\n orderBy: stableOrderBy,\n mode: otherOptions.mode,\n },\n observer,\n ),\n `links ${linkName} for ${objectsKey}`,\n );\n },\n [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n stableWhere,\n otherOptions.pageSize,\n stableOrderBy,\n otherOptions.mode,\n ],\n );\n\n const payload = React.useSyncExternalStore(\n subscribe,\n getSnapShot,\n );\n\n return {\n links: payload?.resolvedList,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: payload?.isOptimistic ?? false,\n error: payload?.error,\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyEhD,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAItBC,OAA+D,EAC/DC,QAAW,EACXC,OAA0C,GAAG,CAAC,CAAC,EACb;EAClC,MAAM;IAAEC;EAAiB,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;EAE3D,MAAM;IAAEU,OAAO,GAAG,IAAI;IAAE,GAAGC;EAAa,CAAC,GAAGJ,OAAO;EAEnD,MAAMK,WAAW,GAAGd,KAAK,CAACe,OAAO,CAC/B,MAAMF,YAAY,CAACG,KAAK,EACxB,CAACC,IAAI,CAACC,SAAS,CAACL,YAAY,CAACG,KAAK,CAAC,CACrC,CAAC;EAED,MAAMG,aAAa,GAAGnB,KAAK,CAACe,OAAO,CACjC,MAAMF,YAAY,CAACO,OAAO,EAC1B,CAACH,IAAI,CAACC,SAAS,CAACL,YAAY,CAACO,OAAO,CAAC,CACvC,CAAC;EAED,MAAMC,UAAU,GAAGrB,KAAK,CAACe,OAAO,CAAC,MAAM;IACrC,IAAIR,OAAO,KAAKe,SAAS,EAAE,OAAO,EAAE;IACpC,MAAMC,GAAG,GAAGC,KAAK,CAACC,OAAO,CAAClB,OAAO,CAAC,GAAGA,OAAO,GAAG,CAACA,OAAO,CAAC;IACxD,OAAOgB,GAAG,CAACG,GAAG,CAACC,GAAG,IAAI,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,KAAK,EAAEF,OAAO,EAAEG,YAAY;IAC5BC,SAAS,EAAE/B,OAAO,GACb2B,OAAO,EAAEK,MAAM,KAAK,SAAS,IAAIL,OAAO,EAAEK,MAAM,KAAK,MAAM,IACzD,CAACL,OAAO,GACX,KAAK;IACTM,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAEP,OAAO,EAAEO,KAAK;IACrBC,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,EAAEQ,SAAS,GAAGzB,SAAS;IAC5D0B,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC;AACH","ignoreList":[]}
@@ -39,6 +39,15 @@ export function useObjectSet(baseObjectSet, options = {}) {
39
39
  ...otherOptions
40
40
  } = options;
41
41
 
42
+ // Track object type to detect when we switch to a different object type
43
+ const objectTypeKey = baseObjectSet.$objectSetInternals.def.apiName;
44
+ const previousObjectTypeRef = React.useRef(objectTypeKey);
45
+ const previousPayloadRef = React.useRef();
46
+ const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;
47
+ if (objectTypeChanged) {
48
+ previousObjectTypeRef.current = objectTypeKey;
49
+ }
50
+
42
51
  // Compute a stable cache key for the ObjectSet and options
43
52
  // dedupeIntervalMs and enabled are excluded as they don't affect the data
44
53
  const stableKey = computeObjectSetCacheKey(baseObjectSet, {
@@ -60,6 +69,7 @@ export function useObjectSet(baseObjectSet, options = {}) {
60
69
  unsubscribe: () => {}
61
70
  }), process.env.NODE_ENV !== "production" ? `objectSet ${stableKey} [DISABLED]` : void 0);
62
71
  }
72
+ const initialValue = objectTypeChanged ? undefined : previousPayloadRef.current;
63
73
  return makeExternalStore(observer => {
64
74
  const subscription = observableClient.observeObjectSet(baseObjectSet, {
65
75
  where: otherOptions.where,
@@ -75,15 +85,21 @@ export function useObjectSet(baseObjectSet, options = {}) {
75
85
  streamUpdates
76
86
  }, observer);
77
87
  return subscription;
78
- }, process.env.NODE_ENV !== "production" ? `objectSet ${stableKey}` : void 0);
79
- }, [enabled, observableClient, stableKey, streamUpdates]);
88
+ }, process.env.NODE_ENV !== "production" ? `objectSet ${stableKey}` : void 0, initialValue);
89
+ }, [enabled, observableClient, stableKey, streamUpdates, objectTypeChanged]);
80
90
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
91
+ React.useEffect(() => {
92
+ if (payload) {
93
+ previousPayloadRef.current = payload;
94
+ }
95
+ }, [payload]);
81
96
  return {
82
97
  data: payload?.resolvedList,
83
98
  isLoading: payload?.status === "loading" || !payload && true || false,
84
99
  error: payload && "error" in payload ? payload.error : undefined,
85
- fetchMore: payload?.fetchMore,
86
- objectSet: payload?.objectSet || baseObjectSet
100
+ fetchMore: payload?.hasMore ? payload.fetchMore : undefined,
101
+ objectSet: payload?.objectSet || baseObjectSet,
102
+ totalCount: payload?.totalCount
87
103
  };
88
104
  }
89
105
  //# sourceMappingURL=useObjectSet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","data","resolvedList","isLoading","status","error","undefined","fetchMore","objectSet"],"sources":["useObjectSet.tsx"],"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 DerivedProperty,\n LinkNames,\n ObjectSet,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\n\nimport {\n computeObjectSetCacheKey,\n type ObserveObjectSetArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseObjectSetOptions<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Where clause for filtering\n */\n where?: WhereClause<Q, RDPs>;\n\n /**\n * Derived properties to add to the object set\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]> };\n\n /**\n * Object sets to union with\n */\n union?: ObjectSet<Q>[];\n\n /**\n * Object sets to intersect with\n */\n intersect?: ObjectSet<Q>[];\n\n /**\n * Object sets to subtract from\n */\n subtract?: ObjectSet<Q>[];\n\n /**\n * Link to pivot to (changes the type)\n */\n pivotTo?: LinkNames<Q>;\n\n /**\n * The preferred page size for the list\n */\n pageSize?: number;\n\n /**\n * Sort order for the results\n */\n orderBy?: {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Minimum time between fetch requests in milliseconds (defaults to 2000ms)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Automatically fetch additional pages on initial load.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the object set will automatically update when matching objects are\n * added, updated, or removed.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs>;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for observing and interacting with OSDK object sets.\n *\n * @typeParam Q - The object type definition\n * @typeParam BaseRDPs - Derived properties that already exist on the input ObjectSet\n * @typeParam RDPs - New derived properties to be added via options.withProperties\n *\n * @param baseObjectSet - The ObjectSet to observe (may already have derived properties)\n * @param options - Options for filtering, sorting, and adding new derived properties\n * @returns Object set data with both existing and new derived properties\n */\nexport function useObjectSet<\n Q extends ObjectTypeDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs>,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, streamUpdates, ...otherOptions } = options;\n\n // Compute a stable cache key for the ObjectSet and options\n // dedupeIntervalMs and enabled are excluded as they don't affect the data\n const stableKey = computeObjectSetCacheKey(baseObjectSet, {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n });\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey} [DISABLED]`\n : void 0,\n );\n }\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n const subscription = observableClient.observeObjectSet(\n baseObjectSet as ObjectSet<Q>,\n {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n },\n observer,\n );\n return subscription;\n },\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey}`\n : void 0,\n );\n },\n [enabled, observableClient, stableKey, streamUpdates],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n data: payload?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: payload?.status === \"loading\" || (!payload && true) || false,\n error: payload && \"error\" in payload\n ? payload.error\n : undefined,\n fetchMore: payload?.fetchMore,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,SACEA,wBAAwB,QAEnB,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;A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AC3CC,KAAK,EAAEJ,YAAY,CAACI,KAAK;QACzBC,SAAS,EAAEL,YAAY,CAACK,SAAS;QACjCC,QAAQ,EAAEN,YAAY,CAACM,QAAQ;QAC/BC,OAAO,EAAEP,YAAY,CAACO,OAAO;QAC7BC,QAAQ,EAAER,YAAY,CAACQ,QAAQ;QAC/BC,OAAO,EAAET,YAAY,CAACS,OAAO;QAC7BW,cAAc,EAAEpB,YAAY,CAACqB,gBAAgB,IAAI,KAAK;QACtDC,aAAa,EAAEtB,YAAY,CAACsB,aAAa;QACzCvB;MACF,CAAC,EACDkB,QACF,CAAC;MACD,OAAOC,YAAY;IACrB,CAAC,EACDJ,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,aAAaf,SAAS,EAAE,GACxB,KAAK,CACX,CAAC;EACH,CAAC,EACD,CAACH,OAAO,EAAEF,gBAAgB,EAAEK,SAAS,EAAEF,aAAa,CACtD,CAAC;EAED,MAAMwB,OAAO,GAAGjC,KAAK,CAACkC,oBAAoB,CAACd,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAO;IACLc,IAAI,EAAEF,OAAO,EAAEG,YAKZ;IACHC,SAAS,EAAEJ,OAAO,EAAEK,MAAM,KAAK,SAAS,IAAK,CAACL,OAAO,IAAI,IAAK,IAAI,KAAK;IACvEM,KAAK,EAAEN,OAAO,IAAI,OAAO,IAAIA,OAAO,GAChCA,OAAO,CAACM,KAAK,GACbC,SAAS;IACbC,SAAS,EAAER,OAAO,EAAEQ,SAAS;IAC7BC,SAAS,EAAET,OAAO,EAAES,SAAS,IAA0BtC;EACzD,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousPayloadRef","objectTypeChanged","current","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","initialValue","undefined","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","useEffect","data","resolvedList","isLoading","status","error","fetchMore","hasMore","objectSet","totalCount"],"sources":["useObjectSet.tsx"],"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 DerivedProperty,\n LinkNames,\n ObjectSet,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\n\nimport {\n computeObjectSetCacheKey,\n type ObserveObjectSetArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore, type Snapshot } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseObjectSetOptions<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Where clause for filtering\n */\n where?: WhereClause<Q, RDPs>;\n\n /**\n * Derived properties to add to the object set\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]> };\n\n /**\n * Object sets to union with\n */\n union?: ObjectSet<Q>[];\n\n /**\n * Object sets to intersect with\n */\n intersect?: ObjectSet<Q>[];\n\n /**\n * Object sets to subtract from\n */\n subtract?: ObjectSet<Q>[];\n\n /**\n * Link to pivot to (changes the type)\n */\n pivotTo?: LinkNames<Q>;\n\n /**\n * The preferred page size for the list\n */\n pageSize?: number;\n\n /**\n * Sort order for the results\n */\n orderBy?: {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Minimum time between fetch requests in milliseconds (defaults to 2000ms)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Automatically fetch additional pages on initial load.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the object set will automatically update when matching objects are\n * added, updated, or removed.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs>;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for observing and interacting with OSDK object sets.\n *\n * @typeParam Q - The object type definition\n * @typeParam BaseRDPs - Derived properties that already exist on the input ObjectSet\n * @typeParam RDPs - New derived properties to be added via options.withProperties\n *\n * @param baseObjectSet - The ObjectSet to observe (may already have derived properties)\n * @param options - Options for filtering, sorting, and adding new derived properties\n * @returns Object set data with both existing and new derived properties\n */\nexport function useObjectSet<\n Q extends ObjectTypeDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs>,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, streamUpdates, ...otherOptions } = options;\n\n // Track object type to detect when we switch to a different object type\n const objectTypeKey = baseObjectSet.$objectSetInternals.def.apiName;\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\n }\n\n // Compute a stable cache key for the ObjectSet and options\n // dedupeIntervalMs and enabled are excluded as they don't affect the data\n const stableKey = computeObjectSetCacheKey(baseObjectSet, {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n });\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey} [DISABLED]`\n : void 0,\n );\n }\n\n const initialValue = objectTypeChanged\n ? undefined\n : previousPayloadRef.current;\n\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n const subscription = observableClient.observeObjectSet(\n baseObjectSet as ObjectSet<Q>,\n {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n },\n observer,\n );\n return subscription;\n },\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey}`\n : void 0,\n initialValue,\n );\n },\n [enabled, observableClient, stableKey, streamUpdates, objectTypeChanged],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n React.useEffect(() => {\n if (payload) {\n previousPayloadRef.current = payload;\n }\n }, [payload]);\n\n return {\n data: payload?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: payload?.status === \"loading\" || (!payload && true) || false,\n error: payload && \"error\" in payload\n ? payload.error\n : undefined,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\n totalCount: payload?.totalCount,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,SACEA,wBAAwB,QAEnB,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAuB,wBAAwB;AACzE,SAASC,YAAY,QAAQ,mBAAmB;AAwIhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAK1BC,aAAqC,EACrCC,OAAqC,GAAG,CAAC,CAAC,EACb;EAC7B,MAAM;IAAEC;EAAiB,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY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I,OAAO,IAAIA,OAAO,GAChCA,OAAO,CAACO,KAAK,GACbd,SAAS;IACbe,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,CAACQ,SAAS,GAAGf,SAAS;IAC3DiB,SAAS,EAAEV,OAAO,EAAEU,SAAS,IAA0BlD,aAAa;IACpEmD,UAAU,EAAEX,OAAO,EAAEW;EACvB,CAAC;AACH","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","isValidating","setValidating","validationResult","setValidationResult","abortControllerRef","useRef","applyAction","useCallback","hookArgs","current","abort","undefined","Array","isArray","updates","args","map","a","$optimisticUpdate","push","r","optimisticUpdate","ctx","update","e","actionValidation","unknown","validateAction","abortController","AbortController","result","signal","aborted","Error","name","useEffect"],"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, ActionValidationResponse } from \"@osdk/client\";\nimport { ActionValidationError } from \"@osdk/client\";\nimport type {\n ActionSignatureFromDef,\n ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ntype ApplyActionParams<Q extends ActionDefinition<any>> =\n & Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n & {\n [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]:\n ObservableClient.ApplyActionOptions[K];\n };\n\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n\n isPending: boolean;\n isValidating: boolean;\n\n /**\n * Validates the action with the provided arguments without executing it.\n * Calling this function again before the previous validation finishes will cancel\n * the first validation and start a new one.\n * @param args The action arguments to validate\n * @returns A promise that resolves to the validation response, or undefined if aborted\n */\n validateAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ) => Promise<ActionValidationResponse | undefined>;\n\n validationResult?: ActionValidationResponse;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<unknown>();\n const [isPending, setPending] = React.useState(false);\n const [isValidating, setValidating] = React.useState(false);\n const [validationResult, setValidationResult] = React.useState<\n ActionValidationResponse | undefined\n >();\n const abortControllerRef = React.useRef<AbortController | null>(null);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) {\n try {\n // If validation is in progress, abort it\n if (isValidating && abortControllerRef.current) {\n abortControllerRef.current.abort();\n setValidating(false);\n }\n\n setPending(true);\n setError(undefined);\n\n if (Array.isArray(hookArgs)) {\n const updates: Array<\n ObservableClient.ApplyActionOptions[\"optimisticUpdate\"]\n > = [];\n const args = hookArgs.map(a => {\n const { $optimisticUpdate, ...args } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\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 { $optimisticUpdate, ...args } = hookArgs;\n\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({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, actionDef, isValidating]);\n\n const validateAction = React.useCallback(async function validateAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ): Promise<ActionValidationResponse | undefined> {\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\n setValidating(true);\n setError(undefined);\n\n const result = await observableClient.validateAction(actionDef, args);\n\n // Check if aborted\n if (abortController.signal.aborted) {\n return undefined;\n }\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\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\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\n return {\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult,\n };\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;AAuChD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;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MAAMmB,MAAM,GAAG,MAAMvC,gBAAgB,CAACoC,cAAc,CAACrC,SAAS,EAAEyB,IAAI,CAAC;;MAErE;MACA,IAAIa,eAAe,CAACG,MAAM,CAACC,OAAO,EAAE;QAClC,OAAOrB,SAAS;MAClB;MAEAR,mBAAmB,CAAC2B,MAAM,CAAC;MAC3B,OAAOA,MAAM;IACf,CAAC,CAAC,OAAON,CAAC,EAAE;MACV;MACA,IAAIA,CAAC,YAAYS,KAAK,IAAIT,CAAC,CAACU,IAAI,KAAK,YAAY,EAAE;QACjD,OAAOvB,SAAS;MAClB;MAEA,IAAIa,CAAC,YAAYtC,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACP+B,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACL9B,QAAQ,CAAC;UAAEgC,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;MACA,MAAMA,CAAC;IACT,CAAC,SAAS;MACRvB,aAAa,CAAC,KAAK,CAAC;IACtB;EACF,CAAC,EAAE,CAACV,gBAAgB,EAAED,SAAS,EAAEQ,SAAS,CAAC,CAAC;;EAE5C;EACAX,KAAK,CAACgD,SAAS,CAAC,MAAM;IACpB,OAAO,MAAM;MACX,IAAI/B,kBAAkB,CAACK,OAAO,EAAE;QAC9BL,kBAAkB,CAACK,OAAO,CAACC,KAAK,CAAC,CAAC;MACpC;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACLJ,WAAW;IACXqB,cAAc;IACdlC,KAAK;IACLG,IAAI;IACJE,SAAS;IACTE,YAAY;IACZE;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","isValidating","setValidating","validationResult","setValidationResult","abortControllerRef","useRef","applyAction","useCallback","hookArgs","current","abort","undefined","Array","isArray","updates","args","map","a","$optimisticUpdate","push","r","optimisticUpdate","ctx","update","e","actionValidation","unknown","validateAction","abortController","AbortController","result","signal","aborted","Error","name","useEffect"],"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 {\n ActionDefinition,\n ActionEditResponse,\n ActionValidationResponse,\n} from \"@osdk/client\";\nimport { ActionValidationError } from \"@osdk/client\";\nimport type {\n ActionSignatureFromDef,\n ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ntype ApplyActionParams<Q extends ActionDefinition<any>> =\n & Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n & {\n [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]:\n ObservableClient.ApplyActionOptions[K];\n };\n\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) => Promise<ActionEditResponse | undefined>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: ActionEditResponse | undefined;\n\n isPending: boolean;\n isValidating: boolean;\n\n /**\n * Validates the action with the provided arguments without executing it.\n * Calling this function again before the previous validation finishes will cancel\n * the first validation and start a new one.\n * @param args The action arguments to validate\n * @returns A promise that resolves to the validation response, or undefined if aborted\n */\n validateAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ) => Promise<ActionValidationResponse | undefined>;\n\n validationResult?: ActionValidationResponse;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<ActionEditResponse | undefined>();\n const [isPending, setPending] = React.useState(false);\n const [isValidating, setValidating] = React.useState(false);\n const [validationResult, setValidationResult] = React.useState<\n ActionValidationResponse | undefined\n >();\n const abortControllerRef = React.useRef<AbortController | null>(null);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) {\n try {\n // If validation is in progress, abort it\n if (isValidating && abortControllerRef.current) {\n abortControllerRef.current.abort();\n setValidating(false);\n }\n\n setPending(true);\n setError(undefined);\n\n if (Array.isArray(hookArgs)) {\n const updates: Array<\n ObservableClient.ApplyActionOptions[\"optimisticUpdate\"]\n > = [];\n const args = hookArgs.map(a => {\n const { $optimisticUpdate, ...args } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\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 { $optimisticUpdate, ...args } = hookArgs;\n\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({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, actionDef, isValidating]);\n\n const validateAction = React.useCallback(async function validateAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n ): Promise<ActionValidationResponse | undefined> {\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\n setValidating(true);\n setError(undefined);\n\n const result = await observableClient.validateAction(actionDef, args);\n\n // Check if aborted\n if (abortController.signal.aborted) {\n return undefined;\n }\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\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\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\n return {\n applyAction,\n validateAction,\n error,\n data,\n isPending,\n isValidating,\n validationResult,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,qBAAqB,QAAQ,cAAc;AAKpD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,mBAAmB;AAuChD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAC3D,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAkC,CAAC;EAC3E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAiC,CAAC;EACxE,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAGZ,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAACK,YAAY,EAAEC,aAAa,CAAC,GAAGd,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EAC3D,MAAM,CAACO,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGhB,KAAK,CAACQ,QAAQ,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ACP+B,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACL9B,QAAQ,CAAC;UAAEgC,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;MACA,MAAMA,CAAC;IACT,CAAC,SAAS;MACRvB,aAAa,CAAC,KAAK,CAAC;IACtB;EACF,CAAC,EAAE,CAACV,gBAAgB,EAAED,SAAS,EAAEQ,SAAS,CAAC,CAAC;;EAE5C;EACAX,KAAK,CAACgD,SAAS,CAAC,MAAM;IACpB,OAAO,MAAM;MACX,IAAI/B,kBAAkB,CAACK,OAAO,EAAE;QAC9BL,kBAAkB,CAACK,OAAO,CAACC,KAAK,CAAC,CAAC;MACpC;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACLJ,WAAW;IACXqB,cAAc;IACdlC,KAAK;IACLG,IAAI;IACJE,SAAS;IACTE,YAAY;IACZE;EACF,CAAC;AACH","ignoreList":[]}
@@ -75,7 +75,7 @@ export function useOsdkAggregation(type, {
75
75
  }, [observableClient, type.apiName]);
76
76
  return {
77
77
  data: payload?.result,
78
- isLoading: payload?.status === "loading",
78
+ isLoading: payload?.status === "loading" || payload?.status === "init" || !payload,
79
79
  error,
80
80
  refetch
81
81
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkAggregation.js","names":["React","makeExternalStore","OsdkContext2","useOsdkAggregation","type","where","withProperties","aggregate","dedupeIntervalMs","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableWithProperties","useMemo","JSON","stringify","stableAggregate","subscribe","getSnapShot","observer","observeAggregation","dedupeInterval","process","env","NODE_ENV","apiName","payload","useSyncExternalStore","error","status","Error","refetch","useCallback","invalidateObjectType","data","result","isLoading"],"sources":["useOsdkAggregation.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 AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObjectTypeDefinition } from \"@osdk/client\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nimport type { InferRdpTypes } from \"./types.js\";\n\nexport interface UseOsdkAggregationOptions<\n T extends ObjectTypeDefinition,\n A extends AggregateOpts<T>,\n WithProps extends DerivedProperty.Clause<T> | undefined = undefined,\n> {\n /**\n * Standard OSDK Where clause to filter objects before aggregation\n */\n where?: WhereClause<T, InferRdpTypes<T, WithProps>>;\n\n /**\n * Define derived properties (RDPs) to be computed server-side.\n * The derived properties can be used in the where clause and aggregation groupBy/select.\n */\n withProperties?: WithProps;\n\n /**\n * Aggregation options including groupBy and select\n */\n aggregate: A;\n\n /**\n * The number of milliseconds to wait after the last observed aggregation change.\n *\n * Two uses of `useOsdkAggregation` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n}\n\nexport interface UseOsdkAggregationResult<\n T extends ObjectTypeDefinition,\n A extends AggregateOpts<T>,\n> {\n data: AggregationsResults<T, A> | undefined;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => void;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for performing aggregations on OSDK object sets.\n *\n * Executes server-side aggregations with groupBy and metric calculations on filtered object sets.\n * Supports runtime derived properties and where clauses.\n *\n * @param type - The object or interface type to aggregate\n * @param options - Aggregation configuration including where clause, aggregation spec, and optional derived properties\n * @returns Object containing aggregation results, loading state, error state, and refetch function\n *\n * @example\n * ```tsx\n * const { data, isLoading, error } = useOsdkAggregation(Employee, {\n * where: { department: \"Engineering\" },\n * aggregate: {\n * groupBy: { department: \"exact\" },\n * select: {\n * avgSalary: { $avg: \"salary\" },\n * count: { $count: {} }\n * }\n * }\n * });\n * ```\n */\nexport function useOsdkAggregation<\n Q extends ObjectTypeDefinition,\n A extends AggregateOpts<Q>,\n WP extends DerivedProperty.Clause<Q> | undefined = undefined,\n>(\n type: Q,\n {\n where = {},\n withProperties,\n aggregate,\n dedupeIntervalMs,\n }: UseOsdkAggregationOptions<Q, A, WP>,\n): UseOsdkAggregationResult<Q, A> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const canonWhere = observableClient.canonicalizeWhereClause<Q>(where ?? {});\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableAggregate = React.useMemo(\n () => aggregate,\n [JSON.stringify(aggregate)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n observableClient.observeAggregation(\n {\n type: type,\n where: canonWhere,\n withProperties: stableWithProperties,\n aggregate: stableAggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [\n observableClient,\n type.apiName,\n type.type,\n canonWhere,\n stableWithProperties,\n stableAggregate,\n dedupeIntervalMs,\n ],\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 execute aggregation\");\n }\n\n const refetch = React.useCallback(async () => {\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName]);\n\n return {\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: payload?.status === \"loading\",\n error,\n refetch,\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;AAiDhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAKhCC,IAAO,EACP;EACEC,KAAK,GAAG,CAAC,CAAC;EACVC,cAAc;EACdC,SAAS;EACTC;AACmC,CAAC,EACN;EAChC,MAAM;IAAEC;EAAiB,CAAC,GAAGT,KAAK,CAACU,UAAU,CAACR,YAAY,CAAC;EAE3D,MAAMS,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAAIP,KAAK,IAAI,CAAC,CAAC,CAAC;EAE3E,MAAMQ,oBAAoB,GAAGb,KAAK,CAACc,OAAO,CACxC,MAAMR,cAAc,EACpB,CAACS,IAAI,CAACC,SAAS,CAACV,cAAc,CAAC,CACjC,CAAC;EAED,MAAMW,eAAe,GAAGjB,KAAK,CAACc,OAAO,CACnC,MAAMP,SAAS,EACf,CAACQ,IAAI,CAACC,SAAS,CAACT,SAAS,CAAC,CAC5B,CAAC;EAED,MAAM;IAAEW,SAAS;IAAEC;EAAY,CAAC,GAAGnB,KAAK,CAACc,OAAO,CAC9C,MACEb,iBAAiB,CACdmB,QAAQ,IACPX,gBAAgB,CAACY,kBAAkB,CACjC;IACEjB,IAAI,EAAEA,IAAI;IACVC,KAAK,EAAEM,UAAU;IACjBL,cAAc,EAAEO,oBAAoB;IACpCN,SAAS,EAAEU,eAAe;IAC1BK,cAAc,EAAEd,gBAAgB,IAAI;EACtC,CAAC,EACDY,QACF,CAAC,EACHG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,eAAerB,IAAI,CAACsB,OAAO,IAAIX,IAAI,CAACC,SAAS,CAACL,UAAU,CAAC,EAAE,GAC3D,KAAK,CACX,CAAC,EACH,CACEF,gBAAgB,EAChBL,IAAI,CAACsB,OAAO,EACZtB,IAAI,CAACA,IAAI,EACTO,UAAU,EACVE,oBAAoB,EACpBI,eAAe,EACfT,gBAAgB,CAEpB,CAAC;EAED,MAAMmB,OAAO,GAAG3B,KAAK,CAAC4B,oBAAoB,CAACV,SAAS,EAAEC,WAAW,CAAC;EAElE,IAAIU,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,+BAA+B,CAAC;EACpD;EAEA,MAAMC,OAAO,GAAGhC,KAAK,CAACiC,WAAW,CAAC,YAAY;IAC5C,MAAMxB,gBAAgB,CAACyB,oBAAoB,CAAC9B,IAAI,CAACsB,OAAO,CAAC;EAC3D,CAAC,EAAE,CAACjB,gBAAgB,EAAEL,IAAI,CAACsB,OAAO,CAAC,CAAC;EAEpC,OAAO;IACLS,IAAI,EAAER,OAAO,EAAES,MAA+C;IAC9DC,SAAS,EAAEV,OAAO,EAAEG,MAAM,KAAK,SAAS;IACxCD,KAAK;IACLG;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkAggregation.js","names":["React","makeExternalStore","OsdkContext2","useOsdkAggregation","type","where","withProperties","aggregate","dedupeIntervalMs","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableWithProperties","useMemo","JSON","stringify","stableAggregate","subscribe","getSnapShot","observer","observeAggregation","dedupeInterval","process","env","NODE_ENV","apiName","payload","useSyncExternalStore","error","status","Error","refetch","useCallback","invalidateObjectType","data","result","isLoading"],"sources":["useOsdkAggregation.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 AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkAggregationOptions<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Standard OSDK Where clause to filter objects before aggregation\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Define derived properties (RDPs) to be computed server-side.\n * The derived properties can be used in the where clause and aggregation groupBy/select.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * Aggregation options including groupBy and select\n */\n aggregate: A;\n\n /**\n * The number of milliseconds to wait after the last observed aggregation change.\n *\n * Two uses of `useOsdkAggregation` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n}\n\nexport interface UseOsdkAggregationResult<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n> {\n data: AggregationsResults<T, A> | undefined;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => void;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for performing aggregations on OSDK object sets.\n *\n * Executes server-side aggregations with groupBy and metric calculations on filtered object sets.\n * Supports runtime derived properties and where clauses.\n *\n * @param type - The object or interface type to aggregate\n * @param options - Aggregation configuration including where clause, aggregation spec, and optional derived properties\n * @returns Object containing aggregation results, loading state, error state, and refetch function\n *\n * @example\n * ```tsx\n * const { data, isLoading, error } = useOsdkAggregation(Employee, {\n * where: { department: \"Engineering\" },\n * aggregate: {\n * groupBy: { department: \"exact\" },\n * select: {\n * avgSalary: { $avg: \"salary\" },\n * count: { $count: {} }\n * }\n * }\n * });\n * ```\n */\nexport function useOsdkAggregation<\n Q extends ObjectOrInterfaceDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n {\n where = {},\n withProperties,\n aggregate,\n dedupeIntervalMs,\n }: UseOsdkAggregationOptions<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const canonWhere = observableClient.canonicalizeWhereClause<Q>(where ?? {});\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableAggregate = React.useMemo(\n () => aggregate,\n [JSON.stringify(aggregate)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n observableClient.observeAggregation(\n {\n type: type,\n where: canonWhere,\n withProperties: stableWithProperties,\n aggregate: stableAggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [\n observableClient,\n type.apiName,\n type.type,\n canonWhere,\n stableWithProperties,\n stableAggregate,\n dedupeIntervalMs,\n ],\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 execute aggregation\");\n }\n\n const refetch = React.useCallback(async () => {\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName]);\n\n return {\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload,\n error,\n refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAgDhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAKhCC,IAAO,EACP;EACEC,KAAK,GAAG,CAAC,CAAC;EACVC,cAAc;EACdC,SAAS;EACTC;AACqC,CAAC,EACR;EAChC,MAAM;IAAEC;EAAiB,CAAC,GAAGT,KAAK,CAACU,UAAU,CAACR,YAAY,CAAC;EAE3D,MAAMS,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAAIP,KAAK,IAAI,CAAC,CAAC,CAAC;EAE3E,MAAMQ,oBAAoB,GAAGb,KAAK,CAACc,OAAO,CACxC,MAAMR,cAAc,EACpB,CAACS,IAAI,CAACC,SAAS,CAACV,cAAc,CAAC,CACjC,CAAC;EAED,MAAMW,eAAe,GAAGjB,KAAK,CAACc,OAAO,CACnC,MAAMP,SAAS,EACf,CAACQ,IAAI,CAACC,SAAS,CAACT,SAAS,CAAC,CAC5B,CAAC;EAED,MAAM;IAAEW,SAAS;IAAEC;EAAY,CAAC,GAAGnB,KAAK,CAACc,OAAO,CAC9C,MACEb,iBAAiB,CACdmB,QAAQ,IACPX,gBAAgB,CAACY,kB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-0,0 +1,101 @@
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
+ * React hook for executing and observing OSDK functions.
22
+ *
23
+ * Provides automatic caching, deduplication, and reactive updates for function calls.
24
+ * Functions are automatically re-fetched when dependencies change (configured via options).
25
+ *
26
+ * @param queryDef - The QueryDefinition to execute
27
+ * @param options - Configuration options for the function call
28
+ * @returns Object containing result, loading state, error, and refetch function
29
+ *
30
+ * @example Basic usage
31
+ * ```tsx
32
+ * const { data, isLoading, error } = useOsdkFunction(getEmployeeStats, {
33
+ * params: { departmentId: "engineering" }
34
+ * });
35
+ * ```
36
+ *
37
+ * @example With dependency tracking
38
+ * ```tsx
39
+ * const { data, refetch } = useOsdkFunction(calculateMetrics, {
40
+ * params: { startDate, endDate },
41
+ * dependsOn: [Employee, Project],
42
+ * });
43
+ * ```
44
+ *
45
+ * @example With specific object dependencies
46
+ * ```tsx
47
+ * const { data } = useOsdkFunction(getEmployeeReport, {
48
+ * params: { employeeId: employee.$primaryKey },
49
+ * dependsOnObjects: [employee],
50
+ * });
51
+ * ```
52
+ */
53
+ export function useOsdkFunction(queryDef, options = {}) {
54
+ const {
55
+ observableClient
56
+ } = React.useContext(OsdkContext2);
57
+ const {
58
+ params,
59
+ dependsOn,
60
+ dependsOnObjects,
61
+ dedupeIntervalMs,
62
+ enabled = true
63
+ } = options;
64
+ const stableParams = React.useMemo(() => params, [JSON.stringify(params)]);
65
+ const stableDependsOn = React.useMemo(() => dependsOn, [JSON.stringify(dependsOn?.map(d => typeof d === "string" ? d : d.apiName))]);
66
+ const stableDependsOnObjects = React.useMemo(() => dependsOnObjects, [JSON.stringify(dependsOnObjects?.map(o => ({
67
+ $apiName: o.$apiName,
68
+ $primaryKey: o.$primaryKey
69
+ })))]);
70
+
71
+ // Record<string, unknown> required as typing is figured out at runtime
72
+ const paramsForApi = stableParams;
73
+ const {
74
+ subscribe,
75
+ getSnapShot
76
+ } = React.useMemo(() => {
77
+ if (!enabled) {
78
+ return makeExternalStore(() => ({
79
+ unsubscribe: () => {}
80
+ }), process.env.NODE_ENV !== "production" ? `function ${queryDef.apiName} ${JSON.stringify(stableParams)} [DISABLED]` : void 0);
81
+ }
82
+ return makeExternalStore(observer => observableClient.observeFunction(queryDef, paramsForApi, {
83
+ dependsOn: stableDependsOn,
84
+ dependsOnObjects: stableDependsOnObjects,
85
+ dedupeInterval: dedupeIntervalMs ?? 2_000
86
+ }, observer), process.env.NODE_ENV !== "production" ? `function ${queryDef.apiName} ${JSON.stringify(stableParams)}` : void 0);
87
+ }, [observableClient, queryDef.apiName, queryDef.version, paramsForApi, stableDependsOn, stableDependsOnObjects, dedupeIntervalMs, enabled]);
88
+ const payload = React.useSyncExternalStore(subscribe, getSnapShot);
89
+ const error = payload?.error ?? (payload?.status === "error" ? new Error("Failed to execute function") : undefined);
90
+ const refetch = React.useCallback(() => {
91
+ void observableClient.invalidateFunction(queryDef, paramsForApi);
92
+ }, [observableClient, queryDef, paramsForApi]);
93
+ return {
94
+ data: payload?.result,
95
+ isLoading: payload?.status === "loading",
96
+ error,
97
+ lastUpdated: payload?.lastUpdated ?? 0,
98
+ refetch
99
+ };
100
+ }
101
+ //# sourceMappingURL=useOsdkFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOsdkFunction.js","names":["React","makeExternalStore","OsdkContext2","useOsdkFunction","queryDef","options","observableClient","useContext","params","dependsOn","dependsOnObjects","dedupeIntervalMs","enabled","stableParams","useMemo","JSON","stringify","stableDependsOn","map","d","apiName","stableDependsOnObjects","o","$apiName","$primaryKey","paramsForApi","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","observer","observeFunction","dedupeInterval","version","payload","useSyncExternalStore","error","status","Error","undefined","refetch","useCallback","invalidateFunction","data","result","isLoading","lastUpdated"],"sources":["useOsdkFunction.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 CompileTimeMetadata,\n ObjectTypeDefinition,\n Osdk,\n QueryDefinition,\n} from \"@osdk/api\";\nimport type {\n ObserveFunctionCallbackArgs,\n QueryParameterType,\n QueryReturnType,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkFunctionOptions<Q extends QueryDefinition<unknown>> {\n /**\n * Parameters to pass to the function.\n * Must include all required parameters; optional parameters can be omitted.\n */\n params?: CompileTimeMetadata<Q>[\"parameters\"] extends Record<string, never>\n ? undefined\n : QueryParameterType<CompileTimeMetadata<Q>[\"parameters\"]>;\n\n /**\n * Object types this function depends on.\n * When actions modify objects of these types, the function will automatically refetch.\n *\n * @example\n * ```tsx\n * // Refetch when any Employee object changes\n * { dependsOn: [Employee] }\n * ```\n */\n dependsOn?: Array<ObjectTypeDefinition | string>;\n\n /**\n * Specific object instances this function depends on.\n * When any of these specific objects change, the function will refetch.\n * More fine-grained than dependsOn for precise invalidation control.\n *\n * @example\n * ```tsx\n * // Refetch when this specific employee changes\n * { dependsOnObjects: [employee] }\n * ```\n */\n dependsOnObjects?: Array<Osdk.Instance<ObjectTypeDefinition>>;\n\n /**\n * The number of milliseconds to dedupe identical function calls.\n * Two calls with the same function and params will share results\n * if the second call is within this interval of the first.\n * @default 2000\n */\n dedupeIntervalMs?: number;\n\n /**\n * Whether to enable the query. When false, the query will not execute.\n * Useful for:\n * - Dependent queries that need to wait for other data\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for required data\n * const { data: employee } = useOsdkObject(Employee, employeeId);\n * const { data: report } = useOsdkFunction(getEmployeeReport, {\n * params: { employeeId: employee?.$primaryKey },\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseOsdkFunctionResult<Q extends QueryDefinition<unknown>> {\n /**\n * The function result, or undefined if not yet loaded or on error.\n */\n data: QueryReturnType<CompileTimeMetadata<Q>[\"output\"]> | undefined;\n\n /**\n * True while the function is executing.\n */\n isLoading: boolean;\n\n /**\n * Error if the function execution failed.\n */\n error: Error | undefined;\n\n /**\n * Timestamp (ms since epoch) of when the result was last fetched.\n */\n lastUpdated: number;\n\n /**\n * Manually refetch the function.\n * Useful for \"pull to refresh\" or retry patterns.\n */\n refetch: () => void;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for executing and observing OSDK functions.\n *\n * Provides automatic caching, deduplication, and reactive updates for function calls.\n * Functions are automatically re-fetched when dependencies change (configured via options).\n *\n * @param queryDef - The QueryDefinition to execute\n * @param options - Configuration options for the function call\n * @returns Object containing result, loading state, error, and refetch function\n *\n * @example Basic usage\n * ```tsx\n * const { data, isLoading, error } = useOsdkFunction(getEmployeeStats, {\n * params: { departmentId: \"engineering\" }\n * });\n * ```\n *\n * @example With dependency tracking\n * ```tsx\n * const { data, refetch } = useOsdkFunction(calculateMetrics, {\n * params: { startDate, endDate },\n * dependsOn: [Employee, Project],\n * });\n * ```\n *\n * @example With specific object dependencies\n * ```tsx\n * const { data } = useOsdkFunction(getEmployeeReport, {\n * params: { employeeId: employee.$primaryKey },\n * dependsOnObjects: [employee],\n * });\n * ```\n */\nexport function useOsdkFunction<Q extends QueryDefinition<unknown>>(\n queryDef: Q,\n options: UseOsdkFunctionOptions<Q> = {},\n): UseOsdkFunctionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const {\n params,\n dependsOn,\n dependsOnObjects,\n dedupeIntervalMs,\n enabled = true,\n } = options;\n\n const stableParams = React.useMemo(\n () => params,\n [JSON.stringify(params)],\n );\n const stableDependsOn = React.useMemo(\n () => dependsOn,\n [JSON.stringify(\n dependsOn?.map(d => typeof d === \"string\" ? d : d.apiName),\n )],\n );\n const stableDependsOnObjects = React.useMemo(\n () => dependsOnObjects,\n [JSON.stringify(\n dependsOnObjects?.map(o => ({\n $apiName: o.$apiName,\n $primaryKey: o.$primaryKey,\n })),\n )],\n );\n\n // Record<string, unknown> required as typing is figured out at runtime\n const paramsForApi = stableParams as Record<string, unknown> | undefined;\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveFunctionCallbackArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `function ${queryDef.apiName} ${\n JSON.stringify(stableParams)\n } [DISABLED]`\n : void 0,\n );\n }\n return makeExternalStore<ObserveFunctionCallbackArgs<Q>>(\n (observer) =>\n observableClient.observeFunction(\n queryDef,\n paramsForApi,\n {\n dependsOn: stableDependsOn,\n dependsOnObjects: stableDependsOnObjects,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n process.env.NODE_ENV !== \"production\"\n ? `function ${queryDef.apiName} ${JSON.stringify(stableParams)}`\n : void 0,\n );\n },\n [\n observableClient,\n queryDef.apiName,\n queryDef.version,\n paramsForApi,\n stableDependsOn,\n stableDependsOnObjects,\n dedupeIntervalMs,\n enabled,\n ],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const error = payload?.error\n ?? (payload?.status === \"error\"\n ? new Error(\"Failed to execute function\")\n : undefined);\n\n const refetch = React.useCallback(() => {\n void observableClient.invalidateFunction(queryDef, paramsForApi);\n }, [observableClient, queryDef, paramsForApi]);\n\n return {\n data: payload?.result as\n | QueryReturnType<CompileTimeMetadata<Q>[\"output\"]>\n | undefined,\n isLoading: payload?.status === \"loading\",\n error,\n lastUpdated: payload?.lastUpdated ?? 0,\n refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAgGhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,QAAW,EACXC,OAAkC,GAAG,CAAC,CAAC,EACb;EAC1B,MAAM;IAAEC;EAAiB,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAC3D,MAAM;IACJM,MAAM;IACNC,SAAS;IACTC,gBAAgB;IAChBC,gBAAgB;IAChBC,OAAO,GAAG;EACZ,CAAC,GAAGP,OAAO;EAEX,MAAMQ,YAAY,GAAGb,KAAK,CAACc,OAAO,CAChC,MAAMN,MAAM,EACZ,CAACO,IAAI,CAACC,SAAS,CAACR,MAAM,CAAC,CACzB,CAAC;EACD,MAAMS,eAAe,GAAGjB,KAAK,CAACc,OAAO,CACnC,MAAML,SAAS,EACf,CAACM,IAAI,CAACC,SAAS,CACbP,SAAS,EAAES,GAAG,CAACC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,CAAC+B,OAAO,EAChBV,YAAY,EACZR,eAAe,EACfI,sBAAsB,EACtBV,gBAAgB,EAChBC,OAAO,CAEX,CAAC;EAED,MAAMwB,OAAO,GAAGpC,KAAK,CAACqC,oBAAoB,CAACX,SAAS,EAAEC,WAAW,CAAC;EAElE,MAAMW,KAAK,GAAGF,OAAO,EAAEE,KAAK,KACtBF,OAAO,EAAEG,MAAM,KAAK,OAAO,GAC3B,IAAIC,KAAK,CAAC,4BAA4B,CAAC,GACvCC,SAAS,CAAC;EAEhB,MAAMC,OAAO,GAAG1C,KAAK,CAAC2C,WAAW,CAAC,MAAM;IACtC,KAAKrC,gBAAgB,CAACsC,kBAAkB,CAACxC,QAAQ,EAAEqB,YAAY,CAAC;EAClE,CAAC,EAAE,CAACnB,gBAAgB,EAAEF,QAAQ,EAAEqB,YAAY,CAAC,CAAC;EAE9C,OAAO;IACLoB,IAAI,EAAET,OAAO,EAAEU,MAEF;IACbC,SAAS,EAAEX,OAAO,EAAEG,MAAM,KAAK,SAAS;IACxCD,KAAK;IACLU,WAAW,EAAEZ,OAAO,EAAEY,WAAW,IAAI,CAAC;IACtCN;EACF,CAAC;AACH","ignoreList":[]}
@@ -73,7 +73,7 @@ export function useOsdkObject(...args) {
73
73
  }
74
74
  return {
75
75
  object: payload?.object,
76
- isLoading: payload?.status === "loading",
76
+ isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
77
77
  isOptimistic: !!payload?.isOptimistic,
78
78
  error,
79
79
  forceUpdate: () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","mode","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","unsubscribe","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 * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args:\n | [obj: Osdk.Instance<Q>, enabled?: boolean]\n | [type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // Check if first arg is an instance to discriminate signatures\n // TypeScript cannot narrow rest parameter unions with optional parameters,\n // so we must use type assertions after runtime discrimination\n const isInstanceSignature = \"$objectType\" in args[0];\n\n // Extract enabled flag - 2nd param for instance signature, 3rd for type signature\n const enabled = isInstanceSignature\n ? (typeof args[1] === \"boolean\" ? args[1] : true)\n : (typeof args[2] === \"boolean\" ? args[2] : true);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = isInstanceSignature ? \"offline\" : undefined;\n const objectType = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$objectType\n : (args[0] as Q).apiName;\n const primaryKey = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$primaryKey\n : (args[1] as PrimaryKeyType<Q>);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n `object ${objectType} ${primaryKey} [DISABLED]`,\n );\n }\n return 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 },\n [enabled, 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 new Error(\"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;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA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BAAgB,EAAEM,UAAU,EAAEG,UAAU,EAAEL,IAAI,CAC1D,CAAC;EAED,MAAMa,OAAO,GAAGtB,KAAK,CAACuB,oBAAoB,CAACP,SAAS,EAAEC,WAAW,CAAC;EAElE,IAAIO,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,IAAIJ,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","mode","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","unsubscribe","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 { ObserveObjectCallbackArgs } 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 * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args:\n | [obj: Osdk.Instance<Q>, enabled?: boolean]\n | [type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // Check if first arg is an instance to discriminate signatures\n // TypeScript cannot narrow rest parameter unions with optional parameters,\n // so we must use type assertions after runtime discrimination\n const isInstanceSignature = \"$objectType\" in args[0];\n\n // Extract enabled flag - 2nd param for instance signature, 3rd for type signature\n const enabled = isInstanceSignature\n ? (typeof args[1] === \"boolean\" ? args[1] : true)\n : (typeof args[2] === \"boolean\" ? args[2] : true);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = isInstanceSignature ? \"offline\" : undefined;\n const objectType = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$objectType\n : (args[0] as Q).apiName;\n const primaryKey = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$primaryKey\n : (args[1] as PrimaryKeyType<Q>);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n `object ${objectType} ${primaryKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n );\n },\n [enabled, 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: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw new Error(\"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;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3B,GAAGC,IAE4D,EACvC;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA;EACA;EACA,MAAMK,mBAAmB,GAAG,aAAa,IAAIH,IAAI,CAAC,CAAC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ACE,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,EAAEpB,OAAO,GACbc,OAAO,EAAEG,MAAM,KAAK,SAAS,IAAIH,OAAO,EAAEG,MAAM,KAAK,MAAM,IACzD,CAACH,OAAO,GACX,KAAK;IACTO,YAAY,EAAE,CAAC,CAACP,OAAO,EAAEO,YAAY;IACrCL,KAAK;IACLM,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,IAAIJ,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC;AACH","ignoreList":[]}
@@ -76,11 +76,12 @@ export function useOsdkObjects(type, options) {
76
76
  error = new Error("Failed to load objects");
77
77
  }
78
78
  return {
79
- fetchMore: listPayload?.fetchMore,
79
+ fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,
80
80
  error,
81
81
  data: listPayload?.resolvedList,
82
- isLoading: listPayload?.status === "loading",
83
- isOptimistic: listPayload?.isOptimistic ?? false
82
+ isLoading: enabled ? listPayload?.status === "loading" || listPayload?.status === "init" || !listPayload : false,
83
+ isOptimistic: listPayload?.isOptimistic ?? false,
84
+ totalCount: listPayload?.totalCount
84
85
  };
85
86
  }
86
87
  //# sourceMappingURL=useOsdkObjects.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","options","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","withProperties","autoFetchMore","intersectWith","pivotTo","enabled","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableWithProperties","useMemo","JSON","stringify","stableIntersectWith","stableOrderBy","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","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 DerivedProperty,\n InterfaceDefinition,\n LinkedType,\n LinkNames,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nimport type { InferRdpTypes } from \"./types.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n WithProps extends DerivedProperty.Clause<T> | undefined = undefined,\n> {\n /**\n * Standard OSDK Where with RDP support\n */\n where?: WhereClause<T, InferRdpTypes<T, WithProps>>;\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 * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: WithProps;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, InferRdpTypes<T, WithProps>>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\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 * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n *\n * Note: When using `autoFetchMore: true` with large datasets, the initial\n * load may take significant time. Consider using a specific number instead\n * or implementing virtual scrolling.\n *\n * @example\n * // Fetch all todos at once\n * const { data } = useOsdkObjects(Todo, { autoFetchMore: true })\n *\n * @example\n * // Fetch at least 100 todos (with 25 per page, fetches 4 pages)\n * const { data } = useOsdkObjects(Todo, {\n * autoFetchMore: 100,\n * pageSize: 25\n * })\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 streamUpdates?: boolean;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for parent data\n * const { data: employee } = useOsdkObject(Employee, employeeId);\n * const { data: reports } = useOsdkObjects(Employee, {\n * where: { managerId: employee?.id },\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<void>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n\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,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n WP extends DerivedProperty.Clause<Q> | undefined,\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, WP>,\n): UseOsdkListResult<Q>;\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n WP extends DerivedProperty.Clause<Q> | undefined,\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, WP>,\n): UseOsdkListResult<Q> | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>> {\n const {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n withProperties,\n autoFetchMore,\n intersectWith,\n pivotTo,\n enabled = true,\n } = options ?? {};\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<Q>(where ?? {});\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableIntersectWith = React.useMemo(\n () => intersectWith,\n [JSON.stringify(intersectWith)],\n );\n\n const stableOrderBy = React.useMemo(\n () => orderBy,\n [JSON.stringify(orderBy)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectsArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)} [DISABLED]`\n : void 0,\n );\n }\n return makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: stableOrderBy,\n streamUpdates,\n withProperties: stableWithProperties,\n autoFetchMore,\n ...(stableIntersectWith\n ? { intersectWith: stableIntersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n );\n },\n [\n enabled,\n observableClient,\n type,\n canonWhere,\n dedupeIntervalMs,\n pageSize,\n stableOrderBy,\n streamUpdates,\n stableWithProperties,\n autoFetchMore,\n stableIntersectWith,\n pivotTo,\n ],\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,\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;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA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G,MAAM,KAAK,SAAS;IAC5CM,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","options","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","withProperties","autoFetchMore","intersectWith","pivotTo","enabled","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableWithProperties","useMemo","JSON","stringify","stableIntersectWith","stableOrderBy","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","listPayload","useSyncExternalStore","error","status","Error","fetchMore","hasMore","undefined","data","resolvedList","isLoading","isOptimistic","totalCount"],"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 DerivedProperty,\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } 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 ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Standard OSDK Where with RDP support\n */\n where?: WhereClause<T, RDPs>;\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 * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\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 * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n *\n * Note: When using `autoFetchMore: true` with large datasets, the initial\n * load may take significant time. Consider using a specific number instead\n * or implementing virtual scrolling.\n *\n * @example\n * // Fetch all todos at once\n * const { data } = useOsdkObjects(Todo, { autoFetchMore: true })\n *\n * @example\n * // Fetch at least 100 todos (with 25 per page, fetches 4 pages)\n * const { data } = useOsdkObjects(Todo, {\n * autoFetchMore: 100,\n * pageSize: 25\n * })\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 streamUpdates?: boolean;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n * @example\n * // Dependent query - wait for parent data\n * const { data: employee } = useOsdkObject(Employee, employeeId);\n * const { data: reports } = useOsdkObjects(Employee, {\n * where: { managerId: employee?.id },\n * enabled: !!employee\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<T, \"$allBaseProperties\", PropertyKeys<T>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\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 /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n{\n const {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n withProperties,\n autoFetchMore,\n intersectWith,\n pivotTo,\n enabled = true,\n } = options ?? {};\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<\n Q,\n RDPs\n >(where ?? {});\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableIntersectWith = React.useMemo(\n () => intersectWith,\n [JSON.stringify(intersectWith)],\n );\n\n const stableOrderBy = React.useMemo(\n () => orderBy,\n [JSON.stringify(orderBy)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)} [DISABLED]`\n : void 0,\n );\n }\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: stableOrderBy,\n streamUpdates,\n withProperties: stableWithProperties,\n autoFetchMore,\n ...(stableIntersectWith\n ? { intersectWith: stableIntersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n );\n },\n [\n enabled,\n observableClient,\n type,\n canonWhere,\n dedupeIntervalMs,\n pageSize,\n stableOrderBy,\n streamUpdates,\n stableWithProperties,\n autoFetchMore,\n stableIntersectWith,\n pivotTo,\n ],\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?.hasMore ? listPayload.fetchMore : undefined,\n error,\n data: listPayload?.resolvedList,\n isLoading: enabled\n ? (listPayload?.status === \"loading\" || listPayload?.status === \"init\"\n || !listPayload)\n : false,\n isOptimistic: listPayload?.isOptimistic ?? false,\n totalCount: listPayload?.totalCount,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyLhD,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAI1C;EACE,MAAM;IACJC,QAAQ;IACRC,OAAO;IACPC,gBAAgB;IAChBC,KAAK,GAAG,CAAC,CAAC;IACVC,aAAa;IACbC,cAAc;IACdC,aAAa;IACbC,aAAa;IACbC,OAAO;IACPC,OAAO,GAAG;EACZ,CAAC,GAAGV,OAAO,IAAI,CAAC,CAAC;EACjB,MAAM;IAAEW;EAAiB,CAAC,GAAGhB,KAAK,CAACiB,UAAU,CAACf,YAAY,CAAC;;EAE3D;AACF;AACA;AACA;EACE,MAAMgB,UAAU,GAAGF,gBAAgB,CAACG,uBAAuB,CAGzDV,KAAK,IAAI,CAAC,CAAC,CAAC;EAEd,MAAMW,oBAAoB,GAAGpB,KAAK,CAACqB,OAAO,CACxC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,CAACC,SAAS,CAACL,UAAU,CAAC,EAAE,GACpD,KAAK,CACX,CAAC;EACH,CAAC,EACD,CACEH,OAAO,EACPC,gBAAgB,EAChBZ,IAAI,EACJc,UAAU,EACVV,gBAAgB,EAChBF,QAAQ,EACRmB,aAAa,EACbf,aAAa,EACbU,oBAAoB,EACpBR,aAAa,EACbY,mBAAmB,EACnBV,OAAO,CAEX,CAAC;EAED,MAAMsB,WAAW,GAAGpC,KAAK,CAACqC,oBAAoB,CAACX,SAAS,EAAEC,WAAW,CAAC;EAEtE,IAAIW,KAAwB;EAC5B,IAAIF,WAAW,IAAI,OAAO,IAAIA,WAAW,IAAIA,WAAW,CAACE,KAAK,EAAE;IAC9DA,KAAK,GAAGF,WAAW,CAACE,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,EAAEM,OAAO,GAAGN,WAAW,CAACK,SAAS,GAAGE,SAAS;IACnEL,KAAK;IACLM,IAAI,EAAER,WAAW,EAAES,YAAY;IAC/BC,SAAS,EAAE/B,OAAO,GACbqB,WAAW,EAAEG,MAAM,KAAK,SAAS,IAAIH,WAAW,EAAEG,MAAM,KAAK,MAAM,IACjE,CAACH,WAAW,GACf,KAAK;IACTW,YAAY,EAAEX,WAAW,EAAEW,YAAY,IAAI,KAAK;IAChDC,UAAU,EAAEZ,WAAW,EAAEY;EAC3B,CAAC;AACH","ignoreList":[]}
@@ -15,10 +15,14 @@
15
15
  */
16
16
 
17
17
  export { OsdkProvider2 } from "../new/OsdkProvider2.js";
18
+ export { useCurrentFoundryUser } from "../new/platform-apis/admin/useCurrentFoundryUser.js";
19
+ export { useFoundryUser } from "../new/platform-apis/admin/useFoundryUser.js";
20
+ export { useFoundryUsersList } from "../new/platform-apis/admin/useFoundryUsersList.js";
18
21
  export { useLinks } from "../new/useLinks.js";
19
22
  export { useObjectSet } from "../new/useObjectSet.js";
20
23
  export { useOsdkAction } from "../new/useOsdkAction.js";
21
24
  export { useOsdkAggregation } from "../new/useOsdkAggregation.js";
25
+ export { useOsdkFunction } from "../new/useOsdkFunction.js";
22
26
  export { useOsdkObject } from "../new/useOsdkObject.js";
23
27
  export { useOsdkObjects } from "../new/useOsdkObjects.js";
24
28
  export { useOsdkClient } from "../useOsdkClient.js";