@osdk/react 0.8.0-beta.2 → 0.8.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +24 -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 +30 -12
  19. package/build/browser/new/useOsdkObjects.js.map +1 -1
  20. package/build/browser/public/experimental.js +1 -0
  21. package/build/browser/public/experimental.js.map +1 -1
  22. package/build/cjs/public/experimental.cjs +133 -39
  23. package/build/cjs/public/experimental.cjs.map +1 -1
  24. package/build/cjs/public/experimental.d.cts +183 -19
  25. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithPivot.js +35 -0
  26. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithPivot.js.map +1 -0
  27. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js +34 -0
  28. package/build/esm/intellisense.test.helpers/useOsdkObjectsWithProperties.js.map +1 -0
  29. package/build/esm/intellisense.test.js +148 -0
  30. package/build/esm/intellisense.test.js.map +1 -0
  31. package/build/esm/new/types.js +2 -0
  32. package/build/esm/new/types.js.map +1 -0
  33. package/build/esm/new/useLinks.js +14 -5
  34. package/build/esm/new/useLinks.js.map +1 -1
  35. package/build/esm/new/useObjectSet.js +31 -19
  36. package/build/esm/new/useObjectSet.js.map +1 -1
  37. package/build/esm/new/useOsdkAggregation.js +83 -0
  38. package/build/esm/new/useOsdkAggregation.js.map +1 -0
  39. package/build/esm/new/useOsdkObject.js +23 -6
  40. package/build/esm/new/useOsdkObject.js.map +1 -1
  41. package/build/esm/new/useOsdkObjects.js +30 -12
  42. package/build/esm/new/useOsdkObjects.js.map +1 -1
  43. package/build/esm/public/experimental.js +1 -0
  44. package/build/esm/public/experimental.js.map +1 -1
  45. package/build/types/intellisense.test.d.ts +1 -0
  46. package/build/types/intellisense.test.d.ts.map +1 -0
  47. package/build/types/intellisense.test.helpers/useOsdkObjectsWithPivot.d.ts +1 -0
  48. package/build/types/intellisense.test.helpers/useOsdkObjectsWithPivot.d.ts.map +1 -0
  49. package/build/types/intellisense.test.helpers/useOsdkObjectsWithProperties.d.ts +1 -0
  50. package/build/types/intellisense.test.helpers/useOsdkObjectsWithProperties.d.ts.map +1 -0
  51. package/build/types/new/types.d.ts +5 -0
  52. package/build/types/new/types.d.ts.map +1 -0
  53. package/build/types/new/useLinks.d.ts +20 -0
  54. package/build/types/new/useLinks.d.ts.map +1 -1
  55. package/build/types/new/useObjectSet.d.ts +36 -0
  56. package/build/types/new/useObjectSet.d.ts.map +1 -1
  57. package/build/types/new/useOsdkAggregation.d.ts +67 -0
  58. package/build/types/new/useOsdkAggregation.d.ts.map +1 -0
  59. package/build/types/new/useOsdkObject.d.ts +4 -2
  60. package/build/types/new/useOsdkObject.d.ts.map +1 -1
  61. package/build/types/new/useOsdkObjects.d.ts +63 -14
  62. package/build/types/new/useOsdkObjects.d.ts.map +1 -1
  63. package/build/types/public/experimental.d.ts +2 -0
  64. package/build/types/public/experimental.d.ts.map +1 -1
  65. package/package.json +9 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @osdkkit/react
2
2
 
3
+ ## 0.8.0-beta.4
4
+
5
+ ### Minor Changes
6
+
7
+ - 9961f06: fix order by via key stabilization
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [9961f06]
12
+ - @osdk/client@2.6.0-beta.12
13
+ - @osdk/api@2.6.0-beta.12
14
+
15
+ ## 0.8.0-beta.3
16
+
17
+ ### Minor Changes
18
+
19
+ - c5a3815: Add new auto fetch more behavior to useOsdkObjects
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [c5a3815]
24
+ - @osdk/client@2.6.0-beta.11
25
+ - @osdk/api@2.6.0-beta.11
26
+
3
27
  ## 0.8.0-beta.2
4
28
 
5
29
  ### Minor Changes
@@ -0,0 +1,35 @@
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
+ // WARNING!
18
+ // WARNING!
19
+ // This file is used for tests that check intellisense. Editing this file by hand will likely
20
+ // break tests that have hard coded line numbers and line offsets.
21
+
22
+ import { Employee } from "@osdk/client.test.ontology";
23
+ import { useOsdkObjects } from "@osdk/react/experimental";
24
+ function TestComponent() {
25
+ const {
26
+ data
27
+ } = useOsdkObjects(Employee, {
28
+ pivotTo: "lead"
29
+ });
30
+
31
+ // Line 31: Check that data has the correct pivoted type
32
+ data?.[0];
33
+ return null;
34
+ }
35
+ //# sourceMappingURL=useOsdkObjectsWithPivot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOsdkObjectsWithPivot.js","names":["Employee","useOsdkObjects","TestComponent","data","pivotTo"],"sources":["useOsdkObjectsWithPivot.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\n// WARNING!\n// WARNING!\n// This file is used for tests that check intellisense. Editing this file by hand will likely\n// break tests that have hard coded line numbers and line offsets.\n\nimport { Employee } from \"@osdk/client.test.ontology\";\nimport { useOsdkObjects } from \"@osdk/react/experimental\";\n\ndeclare const MyComponent: () => void;\n\nfunction TestComponent() {\n const { data } = useOsdkObjects(Employee, {\n pivotTo: \"lead\",\n });\n\n // Line 31: Check that data has the correct pivoted type\n const firstItem = data?.[0];\n\n return null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,4BAA4B;AACrD,SAASC,cAAc,QAAQ,0BAA0B;AAIzD,SAASC,aAAaA,CAAA,EAAG;EACvB,MAAM;IAAEC;EAAK,CAAC,GAAGF,cAAc,CAACD,QAAQ,EAAE;IACxCI,OAAO,EAAE;EACX,CAAC,CAAC;;EAEF;EACkBD,IAAI,GAAG,CAAC,CAAC;EAE3B,OAAO,IAAI;AACb","ignoreList":[]}
@@ -0,0 +1,34 @@
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
+ // WARNING!
18
+ // WARNING!
19
+ // This file is used for tests that check intellisense. Editing this file by hand will likely
20
+ // break tests that have hard coded line numbers and line offsets.
21
+
22
+ import { Employee } from "@osdk/client.test.ontology";
23
+ import { useOsdkObjects } from "@osdk/react/experimental";
24
+ function TestComponent() {
25
+ const {
26
+ data
27
+ } = useOsdkObjects(Employee, {
28
+ withProperties: {
29
+ constantValue: employee => employee.constant.integer(42)
30
+ }
31
+ });
32
+ return null;
33
+ }
34
+ //# sourceMappingURL=useOsdkObjectsWithProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOsdkObjectsWithProperties.js","names":["Employee","useOsdkObjects","TestComponent","data","withProperties","constantValue","employee","constant","integer"],"sources":["useOsdkObjectsWithProperties.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\n// WARNING!\n// WARNING!\n// This file is used for tests that check intellisense. Editing this file by hand will likely\n// break tests that have hard coded line numbers and line offsets.\n\nimport type { DerivedProperty } from \"@osdk/api\";\nimport { Employee } from \"@osdk/client.test.ontology\";\nimport { useOsdkObjects } from \"@osdk/react/experimental\";\n\nfunction TestComponent() {\n const withProps: DerivedProperty.Clause<typeof Employee> = {\n constantValue: (employee) => employee.constant.integer(42),\n };\n\n const { data } = useOsdkObjects(Employee, {\n withProperties: withProps,\n });\n\n return null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,QAAQ,4BAA4B;AACrD,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAASC,aAAaA,CAAA,EAAG;EAKvB,MAAM;IAAEC;EAAK,CAAC,GAAGF,cAAc,CAACD,QAAQ,EAAE;IACxCI,cAAc,EAL2C;MACzDC,aAAa,EAAGC,QAAQ,IAAKA,QAAQ,CAACC,QAAQ,CAACC,OAAO,CAAC,EAAE;IAC3D;EAIA,CAAC,CAAC;EAEF,OAAO,IAAI;AACb","ignoreList":[]}
@@ -0,0 +1,148 @@
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 { startTsServer } from "@osdk/client/internal-node";
18
+ import { findUpSync } from "find-up";
19
+ import * as path from "node:path";
20
+ import invariant from "tiny-invariant";
21
+ import * as ts from "typescript";
22
+ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
23
+
24
+ // it needs to be hoisted because its referenced from our mocked WebSocket
25
+ // which must be hoisted to work
26
+ const rootLogger = await vi.hoisted(async () => {
27
+ const pino = (await import("pino")).pino;
28
+ const pinoPretty = await import("pino-pretty");
29
+ const {
30
+ EventEmitter
31
+ } = await import("node:events");
32
+ return Promise.resolve(pino({
33
+ level: "info"
34
+ }, pinoPretty.build({
35
+ sync: true,
36
+ timestampKey: undefined,
37
+ errorLikeObjectKeys: ["error", "err", "exception"],
38
+ errorProps: "stack,cause,properties",
39
+ ignore: "time,hostname,pid",
40
+ destination: new class extends EventEmitter {
41
+ write(a) {
42
+ // remove trailing newline since console.log adds one
43
+ if (a.at(-1) === "\n") a = a.slice(0, -1);
44
+
45
+ // This lets the test framework aggregate the logs per test, whereas direct to stdout does not
46
+ console.log(a);
47
+ }
48
+ }()
49
+ })));
50
+ });
51
+
52
+ /**
53
+ * @vitest-environment node
54
+ * @vitest-pool forks
55
+ */
56
+ describe("intellisense", () => {
57
+ let packagesDir;
58
+ let reactPackagePath;
59
+ beforeAll(() => {
60
+ const reactPackageJson = findUpSync("package.json", {
61
+ cwd: import.meta.dirname
62
+ });
63
+ console.log({
64
+ reactPackageJson
65
+ });
66
+ !(reactPackageJson != null) ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
67
+ packagesDir = path.join(path.dirname(reactPackageJson), "..");
68
+ reactPackagePath = path.join(packagesDir, "react");
69
+ });
70
+ let tsServer;
71
+ let intellisenseFilePath;
72
+ beforeEach(async a => {
73
+ intellisenseFilePath = path.join(reactPackagePath, "src", "intellisense.test.helpers", `${a.task.name}.ts`);
74
+ console.log(intellisenseFilePath);
75
+ expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();
76
+ try {
77
+ tsServer = await startTsServer(rootLogger);
78
+ await tsServer.sendOpenRequest({
79
+ file: intellisenseFilePath
80
+ });
81
+ } catch (error) {
82
+ if (tsServer) {
83
+ try {
84
+ tsServer.stop();
85
+ } catch {
86
+ // Ignore cleanup errors
87
+ }
88
+ tsServer = undefined;
89
+ }
90
+ throw error;
91
+ }
92
+ });
93
+ afterEach(async () => {
94
+ if (tsServer) {
95
+ tsServer.stop();
96
+ tsServer = undefined;
97
+ }
98
+ });
99
+ it("useOsdkObjectsWithPivot", {
100
+ timeout: 40_000
101
+ }, async () => {
102
+ expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();
103
+ !tsServer ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
104
+ const {
105
+ resp
106
+ } = await tsServer.sendCompletionsRequest({
107
+ file: intellisenseFilePath,
108
+ line: 29,
109
+ offset: 15,
110
+ triggerKind: ts.CompletionTriggerKind.Invoked
111
+ });
112
+ const completions = resp.body?.entries.map(e => e.name) ?? [];
113
+ expect(completions).toContain("lead");
114
+ const {
115
+ resp: typeResp
116
+ } = await tsServer.sendQuickInfoRequest({
117
+ file: intellisenseFilePath,
118
+ line: 33,
119
+ offset: 10
120
+ });
121
+ expect(typeResp.body?.displayString).toBeDefined();
122
+ expect(typeResp.body?.displayString).toContain("Employee");
123
+ });
124
+ it("useOsdkObjectsWithProperties", {
125
+ timeout: 40_000
126
+ }, async () => {
127
+ expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();
128
+ !tsServer ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
129
+ const {
130
+ resp
131
+ } = await tsServer.sendQuickInfoRequest({
132
+ file: intellisenseFilePath,
133
+ line: 27,
134
+ offset: 10
135
+ });
136
+ expect(resp.body?.displayString).toContain("DerivedProperty.Clause");
137
+ const {
138
+ resp: dataResp
139
+ } = await tsServer.sendQuickInfoRequest({
140
+ file: intellisenseFilePath,
141
+ line: 31,
142
+ offset: 11
143
+ });
144
+ expect(dataResp.body?.displayString).toBeDefined();
145
+ expect(dataResp.body?.displayString).toContain("Osdk.Instance<Employee");
146
+ });
147
+ });
148
+ //# sourceMappingURL=intellisense.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intellisense.test.js","names":["startTsServer","findUpSync","path","invariant","ts","afterEach","beforeAll","beforeEach","describe","expect","it","vi","rootLogger","hoisted","pino","pinoPretty","EventEmitter","Promise","resolve","level","build","sync","timestampKey","undefined","errorLikeObjectKeys","errorProps","ignore","destination","write","a","at","slice","console","log","packagesDir","reactPackagePath","reactPackageJson","cwd","import","meta","dirname","process","env","NODE_ENV","join","tsServer","intellisenseFilePath","task","name","sys","fileExists","toBeTruthy","sendOpenRequest","file","error","stop","timeout","resp","sendCompletionsRequest","line","offset","triggerKind","CompletionTriggerKind","Invoked","completions","body","entries","map","e","toContain","typeResp","sendQuickInfoRequest","displayString","toBeDefined","dataResp"],"sources":["intellisense.test.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 { Logger } from \"@osdk/api\";\nimport type { TsServer } from \"@osdk/client/internal-node\";\nimport { startTsServer } from \"@osdk/client/internal-node\";\nimport { findUpSync } from \"find-up\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\nimport * as ts from \"typescript\";\nimport {\n afterEach,\n beforeAll,\n beforeEach,\n describe,\n expect,\n it,\n vi,\n} from \"vitest\";\n\n// it needs to be hoisted because its referenced from our mocked WebSocket\n// which must be hoisted to work\nconst rootLogger = await vi.hoisted(async (): Promise<Logger> => {\n const pino = (await import(\"pino\")).pino;\n const pinoPretty = await import(\"pino-pretty\");\n const { EventEmitter } = await import(\"node:events\");\n class PinoConsoleLogDestination extends EventEmitter {\n write(a: string) {\n // remove trailing newline since console.log adds one\n if (a.at(-1) === \"\\n\") a = a.slice(0, -1);\n\n // This lets the test framework aggregate the logs per test, whereas direct to stdout does not\n console.log(a);\n }\n }\n return Promise.resolve(pino(\n { level: \"info\" },\n (pinoPretty.build)({\n sync: true,\n timestampKey: undefined,\n errorLikeObjectKeys: [\"error\", \"err\", \"exception\"],\n errorProps: \"stack,cause,properties\",\n ignore: \"time,hostname,pid\",\n destination: new PinoConsoleLogDestination(),\n }),\n ));\n});\n\n/**\n * @vitest-environment node\n * @vitest-pool forks\n */\ndescribe(\"intellisense\", () => {\n let packagesDir: string;\n let reactPackagePath: string;\n\n beforeAll(() => {\n const reactPackageJson = findUpSync(\"package.json\", {\n cwd: import.meta.dirname,\n });\n console.log({ reactPackageJson });\n invariant(reactPackageJson != null);\n packagesDir = path.join(\n path.dirname(reactPackageJson),\n \"..\",\n );\n\n reactPackagePath = path.join(packagesDir, \"react\");\n });\n\n let tsServer: TsServer | undefined;\n let intellisenseFilePath: string;\n\n beforeEach(async (a) => {\n intellisenseFilePath = path.join(\n reactPackagePath,\n \"src\",\n \"intellisense.test.helpers\",\n `${a.task.name}.ts`,\n );\n\n console.log(intellisenseFilePath);\n\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n\n try {\n tsServer = await startTsServer(rootLogger);\n await tsServer.sendOpenRequest({ file: intellisenseFilePath });\n } catch (error) {\n if (tsServer) {\n try {\n tsServer.stop();\n } catch {\n // Ignore cleanup errors\n }\n tsServer = undefined;\n }\n throw error;\n }\n });\n\n afterEach(async () => {\n if (tsServer) {\n tsServer.stop();\n tsServer = undefined;\n }\n });\n\n it(\"useOsdkObjectsWithPivot\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp } = await tsServer.sendCompletionsRequest({\n file: intellisenseFilePath,\n line: 29,\n offset: 15,\n triggerKind: ts.CompletionTriggerKind.Invoked,\n });\n\n const completions = resp.body?.entries.map(e => e.name) ?? [];\n expect(completions).toContain(\"lead\");\n\n const { resp: typeResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 33,\n offset: 10,\n });\n\n expect(typeResp.body?.displayString).toBeDefined();\n expect(typeResp.body?.displayString).toContain(\"Employee\");\n });\n\n it(\"useOsdkObjectsWithProperties\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 27,\n offset: 10,\n });\n\n expect(resp.body?.displayString).toContain(\"DerivedProperty.Clause\");\n\n const { resp: dataResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 31,\n offset: 11,\n });\n\n expect(dataResp.body?.displayString).toBeDefined();\n expect(dataResp.body?.displayString).toContain(\"Osdk.Instance<Employee\");\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,UAAU,QAAQ,SAAS;AACpC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAO,KAAKC,EAAE,MAAM,YAAY;AAChC,SACEC,SAAS,EACTC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,EAAE,EACFC,EAAE,QACG,QAAQ;;AAEf;AACA;AACA,MAAMC,UAAU,GAAG,MAAMD,EAAE,CAACE,OAAO,CAAC,YAA6B;EAC/D,MAAMC,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,EAAEA,IAAI;EACxC,MAAMC,UAAU,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAC9C,MAAM;IAAEC;EAAa,CAAC,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;EAUpD,OAAOC,OAAO,CAACC,OAAO,CAACJ,IAAI,CACzB;IAAEK,KAAK,EAAE;EAAO,CAAC,EAChBJ,UAAU,CAACK,KAAK,CAAE;IACjBC,IAAI,EAAE,IAAI;IACVC,YAAY,EAAEC,SAAS;IACvBC,mBAAmB,EAAE,CAAC,OAAO,EAAE,K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MAAM,EAAE;IACV,CAAC,CAAC;IAEFnD,MAAM,CAACiE,QAAQ,CAACT,IAAI,EAAEO,aAAa,CAAC,CAACC,WAAW,CAAC,CAAC;IAClDhE,MAAM,CAACiE,QAAQ,CAACT,IAAI,EAAEO,aAAa,CAAC,CAACH,SAAS,CAAC,wBAAwB,CAAC;EAC1E,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["types.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 ObjectTypeDefinition,\n} from \"@osdk/api\";\n\nexport type InferRdpTypes<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n WP extends DerivedProperty.Clause<Q> | undefined,\n> = WP extends DerivedProperty.Clause<Q> ? {\n [K in keyof WP]: WP[K] extends DerivedProperty.Creator<Q, infer T> ? T\n : never;\n }\n : {};\n"],"mappings":"","ignoreList":[]}
@@ -31,6 +31,10 @@ export function useLinks(objects, linkName, options = {}) {
31
31
  const {
32
32
  observableClient
33
33
  } = React.useContext(OsdkContext2);
34
+ const {
35
+ enabled = true,
36
+ ...otherOptions
37
+ } = options;
34
38
 
35
39
  // Convert single object to array for consistent handling
36
40
  const objectsArray = React.useMemo(() => {
@@ -40,14 +44,19 @@ export function useLinks(objects, linkName, options = {}) {
40
44
  subscribe,
41
45
  getSnapShot
42
46
  } = React.useMemo(() => {
47
+ if (!enabled) {
48
+ return makeExternalStore(() => ({
49
+ unsubscribe: () => {}
50
+ }), `links ${linkName} for ${objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(",")} [DISABLED]`);
51
+ }
43
52
  return makeExternalStore(observer => observableClient.observeLinks(objectsArray, linkName, {
44
53
  linkName,
45
- where: options.where,
46
- pageSize: options.pageSize,
47
- orderBy: options.orderBy,
48
- mode: options.mode
54
+ where: otherOptions.where,
55
+ pageSize: otherOptions.pageSize,
56
+ orderBy: otherOptions.orderBy,
57
+ mode: otherOptions.mode
49
58
  }, observer), `links ${linkName} for ${objectsArray.map(obj => `${obj.$apiName}:${obj.$primaryKey}`).join(",")}`);
50
- }, [observableClient, objectsArray, linkName, options.where, options.pageSize, options.orderBy, options.mode]);
59
+ }, [enabled, observableClient, objectsArray, linkName, otherOptions.where, otherOptions.pageSize, otherOptions.orderBy, otherOptions.mode]);
51
60
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
52
61
  return {
53
62
  links: payload?.resolvedList,
@@ -1 +1 @@
1
- {"version":3,"file":"useLinks.js","names":["React","makeExternalStore","OsdkContext2","emptyArray","Object","freeze","useLinks","objects","linkName","options","observableClient","useContext","objectsArray","useMemo","undefined","Array","isArray","subscribe","getSnapShot","observer","observeLinks","where","pageSize","orderBy","mode","map","obj","$apiName","$primaryKey","join","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\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 // 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 return makeExternalStore<ObserveLinks.CallbackArgs<T>>(\n (observer) =>\n observableClient.observeLinks(\n objectsArray,\n linkName,\n {\n linkName,\n where: options.where,\n pageSize: options.pageSize,\n orderBy: options.orderBy,\n mode: options.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 observableClient,\n objectsArray,\n linkName,\n options.where,\n options.pageSize,\n options.orderBy,\n options.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;AAoDhD,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;EACA,MAAMU,YAA6C,GAAGZ,KAAK,CAACa,OAAO,CAAC,MAAM;IACxE,OAAON,OAAO,KAAKO,SAAS,GACxB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+ {"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;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;EACA,MAAMK,YAA6C,GAAGd,KAAK,CAACe,OAAO,CAAC,MAAM;IACxE,OAAOR,OAAO,KAAKS,SAAS,GACxBb,UAAU,GACVc,KAAK,CAACC,OAAO,CAACX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F,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":[]}
@@ -33,38 +33,50 @@ export function useObjectSet(baseObjectSet, options = {}) {
33
33
  const {
34
34
  observableClient
35
35
  } = React.useContext(OsdkContext2);
36
+ const {
37
+ enabled = true,
38
+ streamUpdates,
39
+ ...otherOptions
40
+ } = options;
36
41
 
37
42
  // Compute a stable cache key for the ObjectSet and options
38
- // dedupeIntervalMs is excluded as it doesn't affect the data, only the refresh rate
43
+ // dedupeIntervalMs and enabled are excluded as they don't affect the data
39
44
  const stableKey = computeObjectSetCacheKey(baseObjectSet, {
40
- where: options.where,
41
- withProperties: options.withProperties,
42
- union: options.union,
43
- intersect: options.intersect,
44
- subtract: options.subtract,
45
- pivotTo: options.pivotTo,
46
- pageSize: options.pageSize,
47
- orderBy: options.orderBy
45
+ where: otherOptions.where,
46
+ withProperties: otherOptions.withProperties,
47
+ union: otherOptions.union,
48
+ intersect: otherOptions.intersect,
49
+ subtract: otherOptions.subtract,
50
+ pivotTo: otherOptions.pivotTo,
51
+ pageSize: otherOptions.pageSize,
52
+ orderBy: otherOptions.orderBy
48
53
  });
49
54
  const {
50
55
  subscribe,
51
56
  getSnapShot
52
57
  } = React.useMemo(() => {
58
+ if (!enabled) {
59
+ return makeExternalStore(() => ({
60
+ unsubscribe: () => {}
61
+ }), process.env.NODE_ENV !== "production" ? `objectSet ${stableKey} [DISABLED]` : void 0);
62
+ }
53
63
  return makeExternalStore(observer => {
54
64
  const subscription = observableClient.observeObjectSet(baseObjectSet, {
55
- where: options.where,
56
- withProperties: options.withProperties,
57
- union: options.union,
58
- intersect: options.intersect,
59
- subtract: options.subtract,
60
- pivotTo: options.pivotTo,
61
- pageSize: options.pageSize,
62
- orderBy: options.orderBy,
63
- dedupeInterval: options.dedupeIntervalMs ?? 2_000
65
+ where: otherOptions.where,
66
+ withProperties: otherOptions.withProperties,
67
+ union: otherOptions.union,
68
+ intersect: otherOptions.intersect,
69
+ subtract: otherOptions.subtract,
70
+ pivotTo: otherOptions.pivotTo,
71
+ pageSize: otherOptions.pageSize,
72
+ orderBy: otherOptions.orderBy,
73
+ dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,
74
+ autoFetchMore: otherOptions.autoFetchMore,
75
+ streamUpdates
64
76
  }, observer);
65
77
  return subscription;
66
78
  }, process.env.NODE_ENV !== "production" ? `objectSet ${stableKey}` : void 0);
67
- }, [observableClient, stableKey]);
79
+ }, [enabled, observableClient, stableKey, streamUpdates]);
68
80
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
69
81
  return {
70
82
  data: payload?.resolvedList,
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","useObjectSet","baseObjectSet","options","observableClient","useContext","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","subscribe","getSnapShot","useMemo","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","process","env","NODE_ENV","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\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 // Compute a stable cache key for the ObjectSet and options\n // dedupeIntervalMs is excluded as it doesn't affect the data, only the refresh rate\n const stableKey = computeObjectSetCacheKey(baseObjectSet, {\n where: options.where,\n withProperties: options.withProperties,\n union: options.union,\n intersect: options.intersect,\n subtract: options.subtract,\n pivotTo: options.pivotTo,\n pageSize: options.pageSize,\n orderBy: options.orderBy,\n });\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n const subscription = observableClient.observeObjectSet(\n baseObjectSet as ObjectSet<Q>,\n {\n where: options.where,\n withProperties: options.withProperties,\n union: options.union,\n intersect: options.intersect,\n subtract: options.subtract,\n pivotTo: options.pivotTo,\n pageSize: options.pageSize,\n orderBy: options.orderBy,\n dedupeInterval: options.dedupeIntervalMs ?? 2_000,\n },\n observer,\n );\n return subscription;\n },\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey}`\n : void 0,\n );\n },\n [observableClient, stableKey],\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;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA4FhD;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,CAAC;;EAE3D;EACA;EACA,MAAMM,SAAS,GAAGT,wBAAwB,CAACK,aAAa,EAAE;IACxDK,KAAK,EAAEJ,OAAO,CAACI,KAAK;IACpBC,cAAc,EAAEL,OAAO,CAACK,cAAc;IACtCC,KAAK,EAAEN,OAAO,CAACM,KAAK;IACpBC,SAAS,EAAEP,OAAO,CAACO,SAAS;IAC5BC,QAAQ,EAAER,OAAO,CAACQ,QAAQ;IAC1BC,OAAO,EAAET,OAAO,CAACS,OAAO;IACxBC,QAAQ,EAAEV,OAAO,CAACU,QAAQ;IAC1BC,OAAO,EAAEX,OAAO,CAACW;EACnB,CAAC,CAAC;EAEF,MAAM;IAAEC,SAAS;IAAEC;EAAY,CAAC,GAAGlB,KAAK,CAACmB,OAAO,CAC9C,MAAM;IACJ,OAAOlB,iBAAiB,CACrBmB,QAAQ,IAAK;MACZ,MAAMC,YAAY,GAAGf,gBAAgB,CAACgB,gBAAgB,CACpDlB,aAAa,EACb;QACEK,KAAK,EAAEJ,OAAO,CAACI,KAAK;QACpBC,cAAc,EAAEL,OAAO,CAACK,cAAc;QACtCC,KAAK,EAAEN,OAAO,CAACM,KAAK;QACpBC,SAAS,EAAEP,OAAO,CAACO,SAAS;QAC5BC,QAAQ,EAAER,OAAO,CAACQ,QAAQ;QAC1BC,OAAO,EAAET,OAAO,CAACS,OAAO;QACxBC,QAAQ,EAAEV,OAAO,CAACU,QAAQ;QAC1BC,OAAO,EAAEX,OAAO,CAACW,OAAO;QACxBO,cAAc,EAAElB,OAAO,CAACmB,gBAAgB,IAAI;MAC9C,CAAC,EACDJ,QACF,CAAC;MACD,OAAOC,YAAY;IACrB,CAAC,EACDI,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,aAAanB,SAAS,EAAE,GACxB,KAAK,CACX,CAAC;EACH,CAAC,EACD,CAACF,gBAAgB,EAAEE,SAAS,CAC9B,CAAC;EAED,MAAMoB,OAAO,GAAG5B,KAAK,CAAC6B,oBAAoB,CAACZ,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAO;IACLY,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,IAA0BjC;EACzD,CAAC;AACH","ignoreList":[]}
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;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAmIhD;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,CAAC;EAE3D,MAAM;IAAEM,OAAO,GAAG,IAAI;IAAEC,aAAa;IAAE,GAAGC;EAAa,CAAC,GAAGL,OAAO;;EAElE;EACA;EACA,MAAMM,SAAS,GAAGZ,wBAAwB,CAACK,aAAa,EAAE;IACxDQ,KAAK,EAAEF,YAAY,CAACE,KAAK;IACzBC,cAAc,EAAEH,YAAY,CAACG,cAAc;IAC3CC,KAAK,EAAEJ,YAAY,CAACI,KAAK;IACzBC,SAAS,EAAEL,YAAY,CAACK,SAAS;IACjCC,QAAQ,EAAEN,YAAY,CAACM,QAAQ;IAC/BC,OAAO,EAAEP,YAAY,CAACO,OAAO;IAC7BC,QAAQ,EAAER,YAAY,CAACQ,QAAQ;IAC/BC,OAAO,EAAET,YAAY,CAACS;EACxB,CAAC,CAAC;EAEF,MAAM;IAAEC,SAAS;IAAEC;EAAY,CAAC,GAAGrB,KAAK,CAACsB,OAAO,CAC9C,MAAM;IACJ,IAAI,C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N,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":[]}
@@ -0,0 +1,83 @@
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 performing aggregations on OSDK object sets.
22
+ *
23
+ * Executes server-side aggregations with groupBy and metric calculations on filtered object sets.
24
+ * Supports runtime derived properties and where clauses.
25
+ *
26
+ * @param type - The object or interface type to aggregate
27
+ * @param options - Aggregation configuration including where clause, aggregation spec, and optional derived properties
28
+ * @returns Object containing aggregation results, loading state, error state, and refetch function
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * const { data, isLoading, error } = useOsdkAggregation(Employee, {
33
+ * where: { department: "Engineering" },
34
+ * aggregate: {
35
+ * groupBy: { department: "exact" },
36
+ * select: {
37
+ * avgSalary: { $avg: "salary" },
38
+ * count: { $count: {} }
39
+ * }
40
+ * }
41
+ * });
42
+ * ```
43
+ */
44
+ export function useOsdkAggregation(type, {
45
+ where = {},
46
+ withProperties,
47
+ aggregate,
48
+ dedupeIntervalMs
49
+ }) {
50
+ const {
51
+ observableClient
52
+ } = React.useContext(OsdkContext2);
53
+ const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});
54
+ const stableWithProperties = React.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
55
+ const stableAggregate = React.useMemo(() => aggregate, [JSON.stringify(aggregate)]);
56
+ const {
57
+ subscribe,
58
+ getSnapShot
59
+ } = React.useMemo(() => makeExternalStore(observer => observableClient.observeAggregation({
60
+ type: type,
61
+ where: canonWhere,
62
+ withProperties: stableWithProperties,
63
+ aggregate: stableAggregate,
64
+ dedupeInterval: dedupeIntervalMs ?? 2_000
65
+ }, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type.apiName, type.type, canonWhere, stableWithProperties, stableAggregate, dedupeIntervalMs]);
66
+ const payload = React.useSyncExternalStore(subscribe, getSnapShot);
67
+ let error;
68
+ if (payload && "error" in payload && payload.error) {
69
+ error = payload.error;
70
+ } else if (payload?.status === "error") {
71
+ error = new Error("Failed to execute aggregation");
72
+ }
73
+ const refetch = React.useCallback(async () => {
74
+ await observableClient.invalidateObjectType(type.apiName);
75
+ }, [observableClient, type.apiName]);
76
+ return {
77
+ data: payload?.result,
78
+ isLoading: payload?.status === "loading",
79
+ error,
80
+ refetch
81
+ };
82
+ }
83
+ //# sourceMappingURL=useOsdkAggregation.js.map
@@ -0,0 +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,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