@osdk/react 0.8.0-beta.1 → 0.8.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/browser/intellisense.test.helpers/useOsdkObjectsWithPivot.js +35 -0
  3. package/build/browser/intellisense.test.helpers/useOsdkObjectsWithPivot.js.map +1 -0
  4. package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js +34 -0
  5. package/build/browser/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -0
  6. package/build/browser/intellisense.test.js +148 -0
  7. package/build/browser/intellisense.test.js.map +1 -0
  8. package/build/browser/new/types.js +2 -0
  9. package/build/browser/new/types.js.map +1 -0
  10. package/build/browser/new/useLinks.js +14 -5
  11. package/build/browser/new/useLinks.js.map +1 -1
  12. package/build/browser/new/useObjectSet.js +31 -19
  13. package/build/browser/new/useObjectSet.js.map +1 -1
  14. package/build/browser/new/useOsdkAggregation.js +83 -0
  15. package/build/browser/new/useOsdkAggregation.js.map +1 -0
  16. package/build/browser/new/useOsdkObject.js +23 -6
  17. package/build/browser/new/useOsdkObject.js.map +1 -1
  18. package/build/browser/new/useOsdkObjects.js +38 -15
  19. package/build/browser/new/useOsdkObjects.js.map +1 -1
  20. package/build/browser/public/experimental.js +2 -0
  21. package/build/browser/public/experimental.js.map +1 -1
  22. package/build/browser/utils/useDebouncedCallback.js +81 -0
  23. package/build/browser/utils/useDebouncedCallback.js.map +1 -0
  24. package/build/cjs/public/experimental.cjs +177 -44
  25. package/build/cjs/public/experimental.cjs.map +1 -1
  26. package/build/cjs/public/experimental.d.cts +225 -19
  27. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithPivot.js +35 -0
  28. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithPivot.js.map +1 -0
  29. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js +34 -0
  30. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -0
  31. package/build/esm/intellisense.test.js +148 -0
  32. package/build/esm/intellisense.test.js.map +1 -0
  33. package/build/esm/new/types.js +2 -0
  34. package/build/esm/new/types.js.map +1 -0
  35. package/build/esm/new/useLinks.js +14 -5
  36. package/build/esm/new/useLinks.js.map +1 -1
  37. package/build/esm/new/useObjectSet.js +31 -19
  38. package/build/esm/new/useObjectSet.js.map +1 -1
  39. package/build/esm/new/useOsdkAggregation.js +83 -0
  40. package/build/esm/new/useOsdkAggregation.js.map +1 -0
  41. package/build/esm/new/useOsdkObject.js +23 -6
  42. package/build/esm/new/useOsdkObject.js.map +1 -1
  43. package/build/esm/new/useOsdkObjects.js +38 -15
  44. package/build/esm/new/useOsdkObjects.js.map +1 -1
  45. package/build/esm/public/experimental.js +2 -0
  46. package/build/esm/public/experimental.js.map +1 -1
  47. package/build/esm/utils/useDebouncedCallback.js +81 -0
  48. package/build/esm/utils/useDebouncedCallback.js.map +1 -0
  49. package/build/types/intellisense.test.d.ts +1 -0
  50. package/build/types/intellisense.test.d.ts.map +1 -0
  51. package/build/types/intellisense.test.helpers/useOsdkObjectsWithPivot.d.ts +1 -0
  52. package/build/types/intellisense.test.helpers/useOsdkObjectsWithPivot.d.ts.map +1 -0
  53. package/build/types/intellisense.test.helpers/useOsdkObjectsWithProperties.d.ts +1 -0
  54. package/build/types/intellisense.test.helpers/useOsdkObjectsWithProperties.d.ts.map +1 -0
  55. package/build/types/new/types.d.ts +5 -0
  56. package/build/types/new/types.d.ts.map +1 -0
  57. package/build/types/new/useLinks.d.ts +20 -0
  58. package/build/types/new/useLinks.d.ts.map +1 -1
  59. package/build/types/new/useObjectSet.d.ts +38 -4
  60. package/build/types/new/useObjectSet.d.ts.map +1 -1
  61. package/build/types/new/useOsdkAggregation.d.ts +67 -0
  62. package/build/types/new/useOsdkAggregation.d.ts.map +1 -0
  63. package/build/types/new/useOsdkObject.d.ts +4 -2
  64. package/build/types/new/useOsdkObject.d.ts.map +1 -1
  65. package/build/types/new/useOsdkObjects.d.ts +77 -11
  66. package/build/types/new/useOsdkObjects.d.ts.map +1 -1
  67. package/build/types/public/experimental.d.ts +3 -0
  68. package/build/types/public/experimental.d.ts.map +1 -1
  69. package/build/types/utils/useDebouncedCallback.d.ts +34 -0
  70. package/build/types/utils/useDebouncedCallback.d.ts.map +1 -0
  71. package/package.json +10 -4
@@ -20,6 +20,7 @@ import { OsdkContext2 } from "./OsdkContext2.js";
20
20
 
21
21
  /**
22
22
  * @param obj an existing `Osdk.Instance` object to get metadata for.
23
+ * @param enabled Enable or disable the query (defaults to true)
23
24
  */
24
25
 
25
26
  /**
@@ -27,6 +28,7 @@ import { OsdkContext2 } from "./OsdkContext2.js";
27
28
  *
28
29
  * @param type
29
30
  * @param primaryKey
31
+ * @param enabled Enable or disable the query (defaults to true)
30
32
  */
31
33
 
32
34
  /*
@@ -37,16 +39,31 @@ export function useOsdkObject(...args) {
37
39
  observableClient
38
40
  } = React.useContext(OsdkContext2);
39
41
 
42
+ // Check if first arg is an instance to discriminate signatures
43
+ // TypeScript cannot narrow rest parameter unions with optional parameters,
44
+ // so we must use type assertions after runtime discrimination
45
+ const isInstanceSignature = "$objectType" in args[0];
46
+
47
+ // Extract enabled flag - 2nd param for instance signature, 3rd for type signature
48
+ const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
49
+
40
50
  // TODO: Figure out what the correct default behavior is for the various scenarios
41
- const mode = args.length === 1 ? "offline" : undefined;
42
- const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
43
- const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];
51
+ const mode = isInstanceSignature ? "offline" : undefined;
52
+ const objectType = isInstanceSignature ? args[0].$objectType : args[0].apiName;
53
+ const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
44
54
  const {
45
55
  subscribe,
46
56
  getSnapShot
47
- } = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {
48
- mode
49
- }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);
57
+ } = React.useMemo(() => {
58
+ if (!enabled) {
59
+ return makeExternalStore(() => ({
60
+ unsubscribe: () => {}
61
+ }), `object ${objectType} ${primaryKey} [DISABLED]`);
62
+ }
63
+ return makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {
64
+ mode
65
+ }, observer), `object ${objectType} ${primaryKey}`);
66
+ }, [enabled, observableClient, objectType, primaryKey, mode]);
50
67
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
51
68
  let error;
52
69
  if (payload && "error" in payload && payload.error) {
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","mode","length","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","observer","observeObject","payload","useSyncExternalStore","error","status","Error","object","isLoading","isOptimistic","forceUpdate"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectTypeDefinition, Osdk, PrimaryKeyType } from \"@osdk/api\";\nimport type { ObserveObjectArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args: [obj: Osdk.Instance<Q>] | [type: Q, primaryKey: PrimaryKeyType<Q>]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n ),\n [observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw 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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E;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 { 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;;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,CAAC;;EAEpD;EACA,MAAMI,OAAO,GAAGD,mBAAmB,GAC9B,OAAOH,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,GAAGA,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAC7C,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,GAAGA,IAAI,CAAC,CAAC,CAAC,GAAG,IAAK;;EAEnD;EACA,MAAMK,IAAI,GAAGF,mBAAmB,GAAG,SAAS,GAAGG,SAAS;EACxD,MAAMC,UAAU,GAAGJ,mBAAmB,GACjCH,IAAI,CAAC,CAAC,CAAC,CAAsBQ,WAAW,G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AAIJ,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC;AACH","ignoreList":[]}
@@ -17,13 +17,19 @@
17
17
  import React from "react";
18
18
  import { makeExternalStore } from "./makeExternalStore.js";
19
19
  import { OsdkContext2 } from "./OsdkContext2.js";
20
- export function useOsdkObjects(type, {
21
- pageSize,
22
- orderBy,
23
- dedupeIntervalMs,
24
- where = {},
25
- streamUpdates
26
- } = {}) {
20
+ export function useOsdkObjects(type, options) {
21
+ const {
22
+ pageSize,
23
+ orderBy,
24
+ dedupeIntervalMs,
25
+ where = {},
26
+ streamUpdates,
27
+ withProperties,
28
+ autoFetchMore,
29
+ intersectWith,
30
+ pivotTo,
31
+ enabled = true
32
+ } = options ?? {};
27
33
  const {
28
34
  observableClient
29
35
  } = React.useContext(OsdkContext2);
@@ -33,17 +39,34 @@ export function useOsdkObjects(type, {
33
39
  the ObservableClient anyway.
34
40
  */
35
41
  const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
42
+ const stableWithProperties = React.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
43
+ const stableIntersectWith = React.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
36
44
  const {
37
45
  subscribe,
38
46
  getSnapShot
39
- } = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({
40
- type,
41
- where: canonWhere,
42
- dedupeInterval: dedupeIntervalMs ?? 2_000,
43
- pageSize,
44
- orderBy,
45
- streamUpdates
46
- }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);
47
+ } = React.useMemo(() => {
48
+ if (!enabled) {
49
+ return makeExternalStore(() => ({
50
+ unsubscribe: () => {}
51
+ }), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)} [DISABLED]` : void 0);
52
+ }
53
+ return makeExternalStore(observer => observableClient.observeList({
54
+ type,
55
+ where: canonWhere,
56
+ dedupeInterval: dedupeIntervalMs ?? 2_000,
57
+ pageSize,
58
+ orderBy,
59
+ streamUpdates,
60
+ withProperties: stableWithProperties,
61
+ autoFetchMore,
62
+ ...(stableIntersectWith ? {
63
+ intersectWith: stableIntersectWith
64
+ } : {}),
65
+ ...(pivotTo ? {
66
+ pivotTo
67
+ } : {})
68
+ }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0);
69
+ }, [enabled, observableClient, type, canonWhere, dedupeIntervalMs, pageSize, orderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
47
70
  const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
48
71
  let error;
49
72
  if (listPayload && "error" in listPayload && listPayload.error) {
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","observableClient","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","observer","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","error","status","Error","fetchMore","data","resolvedList","isLoading","isOptimistic"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ObserveObjectsArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[] | undefined;\n isLoading: boolean;\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n>(\n type: Q,\n {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates,\n }: UseOsdkObjectsOptions<Q> = {},\n): UseOsdkListResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ObserveObjectsArgs<Q>>(\n (observer) =>\n observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [observableClient, type, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.fetchMore,\n error,\n data: listPayload?.resolvedList as Osdk.Instance<Q>[],\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA2FhD,OAAO,SAASC,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AS;IACjCH,KAAK;IACLI,IAAI,EAAEN,WAAW,EAAEO,YAAkC;IACrDC,SAAS,EAAER,WAAW,EAAEG,MAAM,KAAK,SAAS;IAC5CM,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"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","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 { 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,\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 orderBy,\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;AAoKhD,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAsC,EACiC;EACvE,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,CAAIV,KAAK,IAAI,CAAC,CAAC,CAAC;EAE3E,MAAMW,oBAAoB,GAAGpB,KAAK,CAACqB,OAAO,CACxC,MAAMV,cAAc,EACpB,CAACW,IAAI,CAACC,SAAS,CAACZ,cAAc,CAAC,CACjC,CAAC;EAED,MAAMa,mBAAmB,GAAGxB,KAAK,CAACqB,OAAO,CACvC,MAAMR,aAAa,EACnB,CAACS,IAAI,CAACC,SAAS,CAACV,aAAa,CAAC,CAChC,CAAC;EAED,MAAM;IAAEY,SAAS;IAAEC;EAAY,CAAC,GAAG1B,KAAK,CAACqB,OAAO,CAC9C,MAAM;IACJ,IAAI,CAACN,OAAO,EAAE;MACZ,OAAOd,iBAAiB,CACtB,OAAO;QAAE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AAEG,MAAM,KAAK,OAAO,EAAE;IAC1CD,KAAK,GAAG,IAAIE,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEA,OAAO;IACLC,SAAS,EAAEL,WAAW,EAAEK,SAAS;IACjCH,KAAK;IACLI,IAAI,EAAEN,WAAW,EAAEO,YAAY;IAC/BC,SAAS,EAAER,WAAW,EAAEG,MAAM,KAAK,SAAS;IAC5CM,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -18,8 +18,10 @@ export { OsdkProvider2 } from "../new/OsdkProvider2.js";
18
18
  export { useLinks } from "../new/useLinks.js";
19
19
  export { useObjectSet } from "../new/useObjectSet.js";
20
20
  export { useOsdkAction } from "../new/useOsdkAction.js";
21
+ export { useOsdkAggregation } from "../new/useOsdkAggregation.js";
21
22
  export { useOsdkObject } from "../new/useOsdkObject.js";
22
23
  export { useOsdkObjects } from "../new/useOsdkObjects.js";
23
24
  export { useOsdkClient } from "../useOsdkClient.js";
24
25
  export { useOsdkMetadata } from "../useOsdkMetadata.js";
26
+ export { useDebouncedCallback } from "../utils/useDebouncedCallback.js";
25
27
  //# sourceMappingURL=experimental.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"experimental.js","names":["OsdkProvider2","useLinks","useObjectSet","useOsdkAction","useOsdkObject","useOsdkObjects","useOsdkClient","useOsdkMetadata"],"sources":["experimental.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OsdkProvider2 } from \"../new/OsdkProvider2.js\";\nexport { useLinks } from \"../new/useLinks.js\";\nexport { useObjectSet } from \"../new/useObjectSet.js\";\nexport { useOsdkAction } from \"../new/useOsdkAction.js\";\nexport { useOsdkObject } from \"../new/useOsdkObject.js\";\nexport type { UseOsdkListResult } from \"../new/useOsdkObjects.js\";\nexport { useOsdkObjects } from \"../new/useOsdkObjects.js\";\nexport { useOsdkClient } from \"../useOsdkClient.js\";\nexport { useOsdkMetadata } from \"../useOsdkMetadata.js\";\nexport type { UseOsdkMetadataResult } from \"../useOsdkMetadata.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,yBAAyB;AACvD,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,aAAa,QAAQ,yBAAyB;AAEvD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,eAAe,QAAQ,uBAAuB","ignoreList":[]}
1
+ {"version":3,"file":"experimental.js","names":["OsdkProvider2","useLinks","useObjectSet","useOsdkAction","useOsdkAggregation","useOsdkObject","useOsdkObjects","useOsdkClient","useOsdkMetadata","useDebouncedCallback"],"sources":["experimental.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OsdkProvider2 } from \"../new/OsdkProvider2.js\";\nexport { useLinks } from \"../new/useLinks.js\";\nexport { useObjectSet } from \"../new/useObjectSet.js\";\nexport { useOsdkAction } from \"../new/useOsdkAction.js\";\nexport type { UseOsdkAggregationResult } from \"../new/useOsdkAggregation.js\";\nexport { useOsdkAggregation } from \"../new/useOsdkAggregation.js\";\nexport { useOsdkObject } from \"../new/useOsdkObject.js\";\nexport type { UseOsdkListResult } from \"../new/useOsdkObjects.js\";\nexport { useOsdkObjects } from \"../new/useOsdkObjects.js\";\nexport { useOsdkClient } from \"../useOsdkClient.js\";\nexport { useOsdkMetadata } from \"../useOsdkMetadata.js\";\nexport type { UseOsdkMetadataResult } from \"../useOsdkMetadata.js\";\nexport { useDebouncedCallback } from \"../utils/useDebouncedCallback.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,yBAAyB;AACvD,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,aAAa,QAAQ,yBAAyB;AAEvD,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,aAAa,QAAQ,yBAAyB;AAEvD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,eAAe,QAAQ,uBAAuB;AAEvD,SAASC,oBAAoB,QAAQ,kCAAkC","ignoreList":[]}
@@ -0,0 +1,81 @@
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
+ /**
19
+ * Creates a debounced version of a callback function.
20
+ *
21
+ * @param callback The function to debounce
22
+ * @param delay The delay in milliseconds
23
+ * @returns A debounced function with cancel() and flush() methods
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const { applyAction } = useOsdkAction(editOffice);
28
+ *
29
+ * const debouncedSave = useDebouncedCallback(
30
+ * async (name: string) => {
31
+ * await applyAction({
32
+ * Office: office,
33
+ * name,
34
+ * location: office.location!,
35
+ * $optimisticUpdate: (ctx) => {
36
+ * ctx.updateObject(office.$clone({ name }));
37
+ * },
38
+ * });
39
+ * },
40
+ * 1000
41
+ * );
42
+ *
43
+ * <input onChange={(e) => debouncedSave(e.target.value)} />
44
+ * ```
45
+ */
46
+ export function useDebouncedCallback(callback, delay) {
47
+ const timeoutRef = React.useRef();
48
+ const callbackRef = React.useRef(callback);
49
+ const lastArgsRef = React.useRef();
50
+ callbackRef.current = callback;
51
+ const cancel = React.useCallback(() => {
52
+ if (timeoutRef.current) {
53
+ clearTimeout(timeoutRef.current);
54
+ timeoutRef.current = undefined;
55
+ }
56
+ }, []);
57
+ const flush = React.useCallback(() => {
58
+ if (timeoutRef.current && lastArgsRef.current) {
59
+ clearTimeout(timeoutRef.current);
60
+ timeoutRef.current = undefined;
61
+ void callbackRef.current(...lastArgsRef.current);
62
+ }
63
+ }, []);
64
+ const debouncedCallback = React.useCallback((...args) => {
65
+ lastArgsRef.current = args;
66
+ cancel();
67
+ timeoutRef.current = setTimeout(() => {
68
+ void callbackRef.current(...args);
69
+ }, delay);
70
+ }, [delay, cancel]);
71
+ React.useEffect(() => {
72
+ return () => {
73
+ cancel();
74
+ };
75
+ }, [cancel]);
76
+ return Object.assign(debouncedCallback, {
77
+ cancel,
78
+ flush
79
+ });
80
+ }
81
+ //# sourceMappingURL=useDebouncedCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedCallback.js","names":["React","useDebouncedCallback","callback","delay","timeoutRef","useRef","callbackRef","lastArgsRef","current","cancel","useCallback","clearTimeout","undefined","flush","debouncedCallback","args","setTimeout","useEffect","Object","assign"],"sources":["useDebouncedCallback.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 React from \"react\";\n\nexport interface DebouncedCallback<TArgs extends readonly unknown[]> {\n (...args: TArgs): void;\n cancel: () => void;\n flush: () => void;\n}\n\n/**\n * Creates a debounced version of a callback function.\n *\n * @param callback The function to debounce\n * @param delay The delay in milliseconds\n * @returns A debounced function with cancel() and flush() methods\n *\n * @example\n * ```tsx\n * const { applyAction } = useOsdkAction(editOffice);\n *\n * const debouncedSave = useDebouncedCallback(\n * async (name: string) => {\n * await applyAction({\n * Office: office,\n * name,\n * location: office.location!,\n * $optimisticUpdate: (ctx) => {\n * ctx.updateObject(office.$clone({ name }));\n * },\n * });\n * },\n * 1000\n * );\n *\n * <input onChange={(e) => debouncedSave(e.target.value)} />\n * ```\n */\nexport function useDebouncedCallback<TArgs extends readonly unknown[]>(\n callback: (...args: TArgs) => void | Promise<void>,\n delay: number,\n): DebouncedCallback<TArgs> {\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();\n const callbackRef = React.useRef(callback);\n const lastArgsRef = React.useRef<TArgs>();\n\n callbackRef.current = callback;\n\n const cancel = React.useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = undefined;\n }\n }, []);\n\n const flush = React.useCallback(() => {\n if (timeoutRef.current && lastArgsRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = undefined;\n void callbackRef.current(...lastArgsRef.current);\n }\n }, []);\n\n const debouncedCallback = React.useCallback(\n (...args: TArgs) => {\n lastArgsRef.current = args;\n cancel();\n timeoutRef.current = setTimeout(() => {\n void callbackRef.current(...args);\n }, delay);\n },\n [delay, cancel],\n );\n\n React.useEffect(() => {\n return () => {\n cancel();\n };\n }, [cancel]);\n\n return Object.assign(debouncedCallback, { cancel, flush });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,MAAM,OAAO;AAQzB;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,oBAAoBA,CAClCC,QAAkD,EAClDC,KAAa,EACa;EAC1B,MAAMC,UAAU,GAAGJ,KAAK,CAACK,MAAM,CAAgC,CAAC;EAChE,MAAMC,WAAW,GAAGN,KAAK,CAACK,MAAM,CAACH,QAAQ,CAAC;EAC1C,MAAMK,WAAW,GAAGP,KAAK,CAACK,MAAM,CAAQ,CAAC;EAEzCC,WAAW,CAACE,OAAO,GAAGN,QAAQ;EAE9B,MAAMO,MAAM,GAAGT,KAAK,CAACU,WAAW,CAAC,MAAM;IACrC,IAAIN,UAAU,CAACI,OAAO,EAAE;MACtBG,YAAY,CAACP,UAAU,CAACI,OAAO,CAAC;MAChCJ,UAAU,CAACI,OAAO,GAAGI,SAAS;IAChC;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,KAAK,GAAGb,KAAK,CAACU,WAAW,CAAC,MAAM;IACpC,IAAIN,UAAU,CAACI,OAAO,IAAID,WAAW,CAACC,OAAO,EAAE;MAC7CG,YAAY,CAACP,UAAU,CAACI,OAAO,CAAC;MAChCJ,UAAU,CAACI,OAAO,GAAGI,SAAS;MAC9B,KAAKN,WAAW,CAACE,OAAO,CAAC,GAAGD,WAAW,CAACC,OAAO,CAAC;IAClD;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMM,iBAAiB,GAAGd,KAAK,CAACU,WAAW,CACzC,CAAC,GAAGK,IAAW,KAAK;IAClBR,WAAW,CAACC,OAAO,GAAGO,IAAI;IAC1BN,MAAM,CAAC,CAAC;IACRL,UAAU,CAACI,OAAO,GAAGQ,UAAU,CAAC,MAAM;MACpC,KAAKV,WAAW,CAACE,OAAO,CAAC,GAAGO,IAAI,CAAC;IACnC,CAAC,EAAEZ,KAAK,CAAC;EACX,CAAC,EACD,CAACA,KAAK,EAAEM,MAAM,CAChB,CAAC;EAEDT,KAAK,CAACiB,SAAS,CAAC,MAAM;IACpB,OAAO,MAAM;MACXR,MAAM,CAAC,CAAC;IACV,CAAC;EACH,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEZ,OAAOS,MAAM,CAACC,MAAM,CAACL,iBAAiB,EAAE;IAAEL,MAAM;IAAEI;EAAM,CAAC,CAAC;AAC5D","ignoreList":[]}
@@ -77,6 +77,10 @@ function useLinks(objects, linkName, options = {}) {
77
77
  const {
78
78
  observableClient
79
79
  } = React5__default.default.useContext(OsdkContext2);
80
+ const {
81
+ enabled = true,
82
+ ...otherOptions
83
+ } = options;
80
84
  const objectsArray = React5__default.default.useMemo(() => {
81
85
  return objects === void 0 ? emptyArray : Array.isArray(objects) ? objects : [objects];
82
86
  }, [objects]);
@@ -84,14 +88,20 @@ function useLinks(objects, linkName, options = {}) {
84
88
  subscribe,
85
89
  getSnapShot
86
90
  } = React5__default.default.useMemo(() => {
91
+ if (!enabled) {
92
+ return makeExternalStore(() => ({
93
+ unsubscribe: () => {
94
+ }
95
+ }), `links ${linkName} for ${objectsArray.map((obj) => `${obj.$apiName}:${obj.$primaryKey}`).join(",")} [DISABLED]`);
96
+ }
87
97
  return makeExternalStore((observer) => observableClient.observeLinks(objectsArray, linkName, {
88
98
  linkName,
89
- where: options.where,
90
- pageSize: options.pageSize,
91
- orderBy: options.orderBy,
92
- mode: options.mode
99
+ where: otherOptions.where,
100
+ pageSize: otherOptions.pageSize,
101
+ orderBy: otherOptions.orderBy,
102
+ mode: otherOptions.mode
93
103
  }, observer), `links ${linkName} for ${objectsArray.map((obj) => `${obj.$apiName}:${obj.$primaryKey}`).join(",")}`);
94
- }, [observableClient, objectsArray, linkName, options.where, options.pageSize, options.orderBy, options.mode]);
104
+ }, [enabled, observableClient, objectsArray, linkName, otherOptions.where, otherOptions.pageSize, otherOptions.orderBy, otherOptions.mode]);
95
105
  const payload = React5__default.default.useSyncExternalStore(subscribe, getSnapShot);
96
106
  return {
97
107
  links: payload?.resolvedList,
@@ -106,35 +116,48 @@ function useObjectSet(baseObjectSet, options = {}) {
106
116
  const {
107
117
  observableClient
108
118
  } = React5__default.default.useContext(OsdkContext2);
119
+ const {
120
+ enabled = true,
121
+ streamUpdates,
122
+ ...otherOptions
123
+ } = options;
109
124
  const stableKey = unstableDoNotUse.computeObjectSetCacheKey(baseObjectSet, {
110
- where: options.where,
111
- withProperties: options.withProperties,
112
- union: options.union,
113
- intersect: options.intersect,
114
- subtract: options.subtract,
115
- pivotTo: options.pivotTo,
116
- pageSize: options.pageSize,
117
- orderBy: options.orderBy
125
+ where: otherOptions.where,
126
+ withProperties: otherOptions.withProperties,
127
+ union: otherOptions.union,
128
+ intersect: otherOptions.intersect,
129
+ subtract: otherOptions.subtract,
130
+ pivotTo: otherOptions.pivotTo,
131
+ pageSize: otherOptions.pageSize,
132
+ orderBy: otherOptions.orderBy
118
133
  });
119
134
  const {
120
135
  subscribe,
121
136
  getSnapShot
122
137
  } = React5__default.default.useMemo(() => {
138
+ if (!enabled) {
139
+ return makeExternalStore(() => ({
140
+ unsubscribe: () => {
141
+ }
142
+ }), process.env.NODE_ENV !== "production" ? `objectSet ${stableKey} [DISABLED]` : void 0);
143
+ }
123
144
  return makeExternalStore((observer) => {
124
145
  const subscription = observableClient.observeObjectSet(baseObjectSet, {
125
- where: options.where,
126
- withProperties: options.withProperties,
127
- union: options.union,
128
- intersect: options.intersect,
129
- subtract: options.subtract,
130
- pivotTo: options.pivotTo,
131
- pageSize: options.pageSize,
132
- orderBy: options.orderBy,
133
- dedupeInterval: options.dedupeIntervalMs ?? 2e3
146
+ where: otherOptions.where,
147
+ withProperties: otherOptions.withProperties,
148
+ union: otherOptions.union,
149
+ intersect: otherOptions.intersect,
150
+ subtract: otherOptions.subtract,
151
+ pivotTo: otherOptions.pivotTo,
152
+ pageSize: otherOptions.pageSize,
153
+ orderBy: otherOptions.orderBy,
154
+ dedupeInterval: otherOptions.dedupeIntervalMs ?? 2e3,
155
+ autoFetchMore: otherOptions.autoFetchMore,
156
+ streamUpdates
134
157
  }, observer);
135
158
  return subscription;
136
159
  }, process.env.NODE_ENV !== "production" ? `objectSet ${stableKey}` : void 0);
137
- }, [observableClient, stableKey]);
160
+ }, [enabled, observableClient, stableKey, streamUpdates]);
138
161
  const payload = React5__default.default.useSyncExternalStore(subscribe, getSnapShot);
139
162
  return {
140
163
  data: payload?.resolvedList,
@@ -261,19 +284,68 @@ function useOsdkAction(actionDef) {
261
284
  validationResult
262
285
  };
263
286
  }
287
+ function useOsdkAggregation(type, {
288
+ where = {},
289
+ withProperties,
290
+ aggregate,
291
+ dedupeIntervalMs
292
+ }) {
293
+ const {
294
+ observableClient
295
+ } = React5__default.default.useContext(OsdkContext2);
296
+ const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
297
+ const stableWithProperties = React5__default.default.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
298
+ const stableAggregate = React5__default.default.useMemo(() => aggregate, [JSON.stringify(aggregate)]);
299
+ const {
300
+ subscribe,
301
+ getSnapShot
302
+ } = React5__default.default.useMemo(() => makeExternalStore((observer) => observableClient.observeAggregation({
303
+ type,
304
+ where: canonWhere,
305
+ withProperties: stableWithProperties,
306
+ aggregate: stableAggregate,
307
+ dedupeInterval: dedupeIntervalMs ?? 2e3
308
+ }, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type.apiName, type.type, canonWhere, stableWithProperties, stableAggregate, dedupeIntervalMs]);
309
+ const payload = React5__default.default.useSyncExternalStore(subscribe, getSnapShot);
310
+ let error;
311
+ if (payload && "error" in payload && payload.error) {
312
+ error = payload.error;
313
+ } else if (payload?.status === "error") {
314
+ error = new Error("Failed to execute aggregation");
315
+ }
316
+ const refetch = React5__default.default.useCallback(async () => {
317
+ await observableClient.invalidateObjectType(type.apiName);
318
+ }, [observableClient, type.apiName]);
319
+ return {
320
+ data: payload?.result,
321
+ isLoading: payload?.status === "loading",
322
+ error,
323
+ refetch
324
+ };
325
+ }
264
326
  function useOsdkObject(...args) {
265
327
  const {
266
328
  observableClient
267
329
  } = React5__default.default.useContext(OsdkContext2);
268
- const mode = args.length === 1 ? "offline" : void 0;
269
- const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;
270
- const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];
330
+ const isInstanceSignature = "$objectType" in args[0];
331
+ const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
332
+ const mode = isInstanceSignature ? "offline" : void 0;
333
+ const objectType = isInstanceSignature ? args[0].$objectType : args[0].apiName;
334
+ const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
271
335
  const {
272
336
  subscribe,
273
337
  getSnapShot
274
- } = React5__default.default.useMemo(() => makeExternalStore((observer) => observableClient.observeObject(objectType, primaryKey, {
275
- mode
276
- }, observer)), [observableClient, objectType, primaryKey, mode]);
338
+ } = React5__default.default.useMemo(() => {
339
+ if (!enabled) {
340
+ return makeExternalStore(() => ({
341
+ unsubscribe: () => {
342
+ }
343
+ }));
344
+ }
345
+ return makeExternalStore((observer) => observableClient.observeObject(objectType, primaryKey, {
346
+ mode
347
+ }, observer));
348
+ }, [enabled, observableClient, objectType, primaryKey, mode]);
277
349
  const payload = React5__default.default.useSyncExternalStore(subscribe, getSnapShot);
278
350
  let error;
279
351
  if (payload && "error" in payload && payload.error) {
@@ -291,28 +363,52 @@ function useOsdkObject(...args) {
291
363
  }
292
364
  };
293
365
  }
294
- function useOsdkObjects(type, {
295
- pageSize,
296
- orderBy,
297
- dedupeIntervalMs,
298
- where = {},
299
- streamUpdates
300
- } = {}) {
366
+ function useOsdkObjects(type, options) {
367
+ const {
368
+ pageSize,
369
+ orderBy,
370
+ dedupeIntervalMs,
371
+ where = {},
372
+ streamUpdates,
373
+ withProperties,
374
+ autoFetchMore,
375
+ intersectWith,
376
+ pivotTo,
377
+ enabled = true
378
+ } = options ?? {};
301
379
  const {
302
380
  observableClient
303
381
  } = React5__default.default.useContext(OsdkContext2);
304
382
  const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
383
+ const stableWithProperties = React5__default.default.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
384
+ const stableIntersectWith = React5__default.default.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
305
385
  const {
306
386
  subscribe,
307
387
  getSnapShot
308
- } = React5__default.default.useMemo(() => makeExternalStore((observer) => observableClient.observeList({
309
- type,
310
- where: canonWhere,
311
- dedupeInterval: dedupeIntervalMs ?? 2e3,
312
- pageSize,
313
- orderBy,
314
- streamUpdates
315
- }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);
388
+ } = React5__default.default.useMemo(() => {
389
+ if (!enabled) {
390
+ return makeExternalStore(() => ({
391
+ unsubscribe: () => {
392
+ }
393
+ }), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)} [DISABLED]` : void 0);
394
+ }
395
+ return makeExternalStore((observer) => observableClient.observeList({
396
+ type,
397
+ where: canonWhere,
398
+ dedupeInterval: dedupeIntervalMs ?? 2e3,
399
+ pageSize,
400
+ orderBy,
401
+ streamUpdates,
402
+ withProperties: stableWithProperties,
403
+ autoFetchMore,
404
+ ...stableIntersectWith ? {
405
+ intersectWith: stableIntersectWith
406
+ } : {},
407
+ ...pivotTo ? {
408
+ pivotTo
409
+ } : {}
410
+ }, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0);
411
+ }, [enabled, observableClient, type, canonWhere, dedupeIntervalMs, pageSize, orderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
316
412
  const listPayload = React5__default.default.useSyncExternalStore(subscribe, getSnapShot);
317
413
  let error;
318
414
  if (listPayload && "error" in listPayload && listPayload.error) {
@@ -328,6 +424,41 @@ function useOsdkObjects(type, {
328
424
  isOptimistic: listPayload?.isOptimistic ?? false
329
425
  };
330
426
  }
427
+ function useDebouncedCallback(callback, delay) {
428
+ const timeoutRef = React5__default.default.useRef();
429
+ const callbackRef = React5__default.default.useRef(callback);
430
+ const lastArgsRef = React5__default.default.useRef();
431
+ callbackRef.current = callback;
432
+ const cancel = React5__default.default.useCallback(() => {
433
+ if (timeoutRef.current) {
434
+ clearTimeout(timeoutRef.current);
435
+ timeoutRef.current = void 0;
436
+ }
437
+ }, []);
438
+ const flush = React5__default.default.useCallback(() => {
439
+ if (timeoutRef.current && lastArgsRef.current) {
440
+ clearTimeout(timeoutRef.current);
441
+ timeoutRef.current = void 0;
442
+ void callbackRef.current(...lastArgsRef.current);
443
+ }
444
+ }, []);
445
+ const debouncedCallback = React5__default.default.useCallback((...args) => {
446
+ lastArgsRef.current = args;
447
+ cancel();
448
+ timeoutRef.current = setTimeout(() => {
449
+ void callbackRef.current(...args);
450
+ }, delay);
451
+ }, [delay, cancel]);
452
+ React5__default.default.useEffect(() => {
453
+ return () => {
454
+ cancel();
455
+ };
456
+ }, [cancel]);
457
+ return Object.assign(debouncedCallback, {
458
+ cancel,
459
+ flush
460
+ });
461
+ }
331
462
 
332
463
  Object.defineProperty(exports, "useOsdkClient", {
333
464
  enumerable: true,
@@ -338,9 +469,11 @@ Object.defineProperty(exports, "useOsdkMetadata", {
338
469
  get: function () { return chunkOVBG5VXE_cjs.useOsdkMetadata; }
339
470
  });
340
471
  exports.OsdkProvider2 = OsdkProvider2;
472
+ exports.useDebouncedCallback = useDebouncedCallback;
341
473
  exports.useLinks = useLinks;
342
474
  exports.useObjectSet = useObjectSet;
343
475
  exports.useOsdkAction = useOsdkAction;
476
+ exports.useOsdkAggregation = useOsdkAggregation;
344
477
  exports.useOsdkObject = useOsdkObject;
345
478
  exports.useOsdkObjects = useOsdkObjects;
346
479
  //# sourceMappingURL=experimental.cjs.map