@osdk/react 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @osdkkit/react
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 17d4115: add interface support to useOsdkObject
8
+
3
9
  ## 0.9.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2026 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: ridsData
27
+ } = useOsdkObjects(Employee, {
28
+ rids: ["ri.foo.123"]
29
+ });
30
+ ridsData?.[0];
31
+ const {
32
+ data: noRidsData
33
+ } = useOsdkObjects(Employee);
34
+ noRidsData?.[0];
35
+ return null;
36
+ }
37
+ //# sourceMappingURL=useOsdkObjectsWithRids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOsdkObjectsWithRids.js","names":["Employee","useOsdkObjects","TestComponent","data","ridsData","rids","noRidsData"],"sources":["useOsdkObjectsWithRids.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nfunction TestComponent() {\n const { data: ridsData } = useOsdkObjects(Employee, {\n rids: [\"ri.foo.123\"],\n });\n\n const ridsItem = ridsData?.[0];\n\n const { data: noRidsData } = useOsdkObjects(Employee);\n\n const noRidsItem = noRidsData?.[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;AAEzD,SAASC,aAAaA,CAAA,EAAG;EACvB,MAAM;IAAEC,IAAI,EAAEC;EAAS,CAAC,GAAGH,cAAc,CAACD,QAAQ,EAAE;IAClDK,IAAI,EAAE,CAAC,YAAY;EACrB,CAAC,CAAC;EAEeD,QAAQ,GAAG,CAAC,CAAC;EAE9B,MAAM;IAAED,IAAI,EAAEG;EAAW,CAAC,GAAGL,cAAc,CAACD,QAAQ,CAAC;EAElCM,UAAU,GAAG,CAAC,CAAC;EAElC,OAAO,IAAI;AACb","ignoreList":[]}
@@ -121,6 +121,30 @@ describe("intellisense", () => {
121
121
  expect(typeResp.body?.displayString).toBeDefined();
122
122
  expect(typeResp.body?.displayString).toContain("Employee");
123
123
  });
124
+ it("useOsdkObjectsWithRids", {
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: ridsResp
131
+ } = await tsServer.sendQuickInfoRequest({
132
+ file: intellisenseFilePath,
133
+ line: 30,
134
+ offset: 9
135
+ });
136
+ expect(ridsResp.body?.displayString).toBeDefined();
137
+ expect(ridsResp.body?.displayString).toContain("$rid");
138
+ const {
139
+ resp: noRidsResp
140
+ } = await tsServer.sendQuickInfoRequest({
141
+ file: intellisenseFilePath,
142
+ line: 34,
143
+ offset: 9
144
+ });
145
+ expect(noRidsResp.body?.displayString).toBeDefined();
146
+ expect(noRidsResp.body?.displayString).not.toContain("$rid");
147
+ });
124
148
  it("useOsdkObjectsWithProperties", {
125
149
  timeout: 40_000
126
150
  }, async () => {
@@ -1 +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(() => {\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,4B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AAC,UAAU,CAAC;EAC5D,CAAC,CAAC;EAEF3D,EAAE,CAAC,8BAA8B,EAAE;IAAE8C,OAAO,EAAE;EAAO,CAAC,EAAE,YAAY;IAClE/C,MAAM,CAACL,EAAE,CAAC6C,GAAG,CAACC,UAAU,CAACJ,oBAAoB,CAAC,CAAC,CAACK,UAAU,CAAC,CAAC;IAC5D,CAAUN,QAAQ,GAAAJ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAlBxC,SAAS,UAATA,SAAS;IAET,MAAM;MAAEsD;IAAK,CAAC,GAAG,MAAMZ,QAAQ,CAAC0B,oBAAoB,CAAC;MACnDlB,IAAI,EAAEP,oBAAoB;MAC1Ba,IAAI,EAAE,EAAE;MACRC,MAAM,EAAE;IACV,CAAC,CAAC;IAEFnD,MAAM,CAACgD,IAAI,CAACQ,IAAI,EAAEO,aAAa,CAAC,CAACH,SAAS,CAAC,wBAAwB,CAAC;IAEpE,MAAM;MAAEZ,IAAI,EAAEiB;IAAS,CAAC,GAAG,MAAM7B,QAAQ,CAAC0B,oBAAoB,CAAC;MAC7DlB,IAAI,EAAEP,oBAAoB;MAC1Ba,IAAI,EAAE,EAAE;MACRC,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":[]}
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","ridsResp","noRidsResp","not","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(() => {\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(\"useOsdkObjectsWithRids\", { timeout: 40_000 }, async () => {\n expect(ts.sys.fileExists(intellisenseFilePath)).toBeTruthy();\n invariant(tsServer);\n\n const { resp: ridsResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 30,\n offset: 9,\n });\n\n expect(ridsResp.body?.displayString).toBeDefined();\n expect(ridsResp.body?.displayString).toContain(\"$rid\");\n\n const { resp: noRidsResp } = await tsServer.sendQuickInfoRequest({\n file: intellisenseFilePath,\n line: 34,\n offset: 9,\n });\n\n expect(noRidsResp.body?.displayString).toBeDefined();\n expect(noRidsResp.body?.displayString).not.toContain(\"$rid\");\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,EAA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I,EAAEoB;IAAS,CAAC,GAAG,MAAMhC,QAAQ,CAAC0B,oBAAoB,CAAC;MAC7DlB,IAAI,EAAEP,oBAAoB;MAC1Ba,IAAI,EAAE,EAAE;MACRC,MAAM,EAAE;IACV,CAAC,CAAC;IAEFnD,MAAM,CAACoE,QAAQ,CAACZ,IAAI,EAAEO,aAAa,CAAC,CAACC,WAAW,CAAC,CAAC;IAClDhE,MAAM,CAACoE,QAAQ,CAACZ,IAAI,EAAEO,aAAa,CAAC,CAACH,SAAS,CAAC,wBAAwB,CAAC;EAC1E,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -24,10 +24,10 @@ import { OsdkContext2 } from "./OsdkContext2.js";
24
24
  */
25
25
 
26
26
  /**
27
- * Loads an object by type and primary key.
27
+ * Loads an object or interface instance by type and primary key.
28
28
  *
29
- * @param type
30
- * @param primaryKey
29
+ * @param type The object type or interface definition
30
+ * @param primaryKey The primary key of the object
31
31
  * @param enabled Enable or disable the query (defaults to true)
32
32
  */
33
33
 
@@ -46,11 +46,10 @@ export function useOsdkObject(...args) {
46
46
 
47
47
  // Extract enabled flag - 2nd param for instance signature, 3rd for type signature
48
48
  const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
49
-
50
- // TODO: Figure out what the correct default behavior is for the various scenarios
51
49
  const mode = isInstanceSignature ? "offline" : undefined;
52
- const objectType = isInstanceSignature ? args[0].$objectType : args[0].apiName;
50
+ const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
53
51
  const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
52
+ const apiNameString = typeof typeOrApiName === "string" ? typeOrApiName : typeOrApiName.apiName;
54
53
  const {
55
54
  subscribe,
56
55
  getSnapShot
@@ -58,12 +57,12 @@ export function useOsdkObject(...args) {
58
57
  if (!enabled) {
59
58
  return makeExternalStore(() => ({
60
59
  unsubscribe: () => {}
61
- }), `object ${objectType} ${primaryKey} [DISABLED]`);
60
+ }), `object ${apiNameString} ${primaryKey} [DISABLED]`);
62
61
  }
63
- return makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {
62
+ return makeExternalStore(observer => observableClient.observeObject(typeOrApiName, primaryKey, {
64
63
  mode
65
- }, observer), `object ${objectType} ${primaryKey}`);
66
- }, [enabled, observableClient, objectType, primaryKey, mode]);
64
+ }, observer), `object ${apiNameString} ${primaryKey}`);
65
+ }, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode]);
67
66
  const payload = React.useSyncExternalStore(subscribe, getSnapShot);
68
67
  let error;
69
68
  if (payload && "error" in payload && payload.error) {
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","mode","undefined","objectType","$objectType","apiName","primaryKey","$primaryKey","subscribe","getSnapShot","useMemo","unsubscribe","observer","observeObject","payload","useSyncExternalStore","error","status","Error","object","isLoading","isOptimistic","forceUpdate"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectTypeDefinition, Osdk, PrimaryKeyType } from \"@osdk/api\";\nimport type { ObserveObjectCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<Q extends ObjectTypeDefinition> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n obj: Osdk.Instance<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<Q extends ObjectTypeDefinition>(\n ...args:\n | [obj: Osdk.Instance<Q>, enabled?: boolean]\n | [type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // Check if first arg is an instance to discriminate signatures\n // TypeScript cannot narrow rest parameter unions with optional parameters,\n // so we must use type assertions after runtime discrimination\n const isInstanceSignature = \"$objectType\" in args[0];\n\n // Extract enabled flag - 2nd param for instance signature, 3rd for type signature\n const enabled = isInstanceSignature\n ? (typeof args[1] === \"boolean\" ? args[1] : true)\n : (typeof args[2] === \"boolean\" ? args[2] : true);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = isInstanceSignature ? \"offline\" : undefined;\n const objectType = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$objectType\n : (args[0] as Q).apiName;\n const primaryKey = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$primaryKey\n : (args[1] as PrimaryKeyType<Q>);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n `object ${objectType} ${primaryKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n objectType,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${objectType} ${primaryKey}`,\n );\n },\n [enabled, observableClient, objectType, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw new Error(\"not implemented\");\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAehD;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3B,GAAGC,IAE4D,EACvC;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA;EACA;EACA,MAAMK,mBAAmB,GAAG,aAAa,IAAIH,IAAI,CAAC,CAAC,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,GAA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,EAAEG,MAAM,KAAK,SAAS,IAAIH,OAAO,EAAEG,MAAM,KAAK,MAAM,IACzD,CAACH,OAAO,GACX,KAAK;IACTO,YAAY,EAAE,CAAC,CAACP,OAAO,EAAEO,YAAY;IACrCL,KAAK;IACLM,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,IAAIJ,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","mode","undefined","typeOrApiName","$objectType","primaryKey","$primaryKey","apiNameString","apiName","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 {\n ObjectOrInterfaceDefinition,\n Osdk,\n PrimaryKeyType,\n} from \"@osdk/api\";\nimport type { ObserveObjectCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\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<\n Q extends ObjectOrInterfaceDefinition,\n>(\n obj: Osdk.Instance<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object or interface instance by type and primary key.\n *\n * @param type The object type or interface definition\n * @param primaryKey The primary key of the object\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\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 const mode = isInstanceSignature ? \"offline\" : undefined;\n\n const typeOrApiName = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$objectType\n : (args[0] as Q);\n\n const primaryKey = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$primaryKey\n : (args[1] as PrimaryKeyType<Q>);\n\n const apiNameString = typeof typeOrApiName === \"string\"\n ? typeOrApiName\n : typeOrApiName.apiName;\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n `object ${apiNameString} ${primaryKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n typeOrApiName,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${apiNameString} ${primaryKey}`,\n );\n },\n [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate: () => {\n throw new Error(\"not implemented\");\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAiBhD;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAG3B,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,MAAMK,IA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AAC;EAC5C;EAEA,OAAO;IACLC,MAAM,EAAEL,OAAO,EAAEK,MAAsC;IACvDC,SAAS,EAAErB,OAAO,GACbe,OAAO,EAAEG,MAAM,KAAK,SAAS,IAAIH,OAAO,EAAEG,MAAM,KAAK,MAAM,IACzD,CAACH,OAAO,GACX,KAAK;IACTO,YAAY,EAAE,CAAC,CAACP,OAAO,EAAEO,YAAY;IACrCL,KAAK;IACLM,WAAW,EAAEA,CAAA,KAAM;MACjB,MAAM,IAAIJ,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC;AACH","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","canonWhere","canonicalizeWhereClause","stableRids","useMemo","JSON","stringify","stableWithProperties","stableIntersectWith","stableOrderBy","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","length","listPayload","useSyncExternalStore","error","status","Error","fetchMore","hasMore","undefined","data","resolvedList","isLoading","isOptimistic","totalCount"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Fetch objects by their RIDs (Resource Identifiers).\n * When provided, starts with a static objectset containing these RIDs.\n * Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.\n *\n * @example\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })\n *\n * @example\n * // Fetch specific objects by RID, filtered by status\n * useOsdkObjects(Employee, {\n * rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],\n * where: { status: 'active' }\n * })\n */\n rids?: readonly string[];\n\n /**\n * Standard OSDK Where clause with RDP support.\n * When used with `rids`, filters the RID set.\n * When used alone, filters all objects of the type.\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Sort results by one or more properties.\n */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /**\n * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\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 * @default true\n */\n enabled?: boolean;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<T, \"$allBaseProperties\", PropertyKeys<T>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n{\n const { observableClient } = React.useContext(OsdkContext2);\n\n const {\n pageSize,\n dedupeIntervalMs,\n withProperties,\n enabled = true,\n rids,\n where,\n orderBy,\n streamUpdates,\n autoFetchMore,\n intersectWith,\n pivotTo,\n } = options ?? {};\n\n const canonWhere = observableClient.canonicalizeWhereClause<\n Q,\n RDPs\n >(where ?? {});\n\n const stableRids = React.useMemo(\n () => rids,\n [JSON.stringify(rids)],\n );\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableIntersectWith = React.useMemo(\n () => intersectWith,\n [JSON.stringify(intersectWith)],\n );\n\n const stableOrderBy = React.useMemo(\n () => orderBy,\n [JSON.stringify(orderBy)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} [DISABLED]`\n : void 0,\n );\n }\n\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n (observer) =>\n observableClient.observeList({\n type,\n rids: stableRids,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: stableOrderBy,\n streamUpdates,\n withProperties: stableWithProperties,\n autoFetchMore,\n ...(stableIntersectWith\n ? { intersectWith: stableIntersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${\n stableRids ? `[${stableRids.length} rids]` : \"\"\n } ${JSON.stringify(canonWhere)}`\n : void 0,\n );\n },\n [\n enabled,\n observableClient,\n type,\n stableRids,\n canonWhere,\n dedupeIntervalMs,\n pageSize,\n stableOrderBy,\n streamUpdates,\n stableWithProperties,\n autoFetchMore,\n stableIntersectWith,\n pivotTo,\n ],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,\n error,\n data: listPayload?.resolvedList,\n isLoading: enabled\n ? (listPayload?.status === \"loading\" || listPayload?.status === \"init\"\n || !listPayload)\n : false,\n isOptimistic: listPayload?.isOptimistic ?? false,\n totalCount: listPayload?.totalCount,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA+JhD,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAI1C;EACE,MAAM;IAAEC;EAAiB,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAE3D,MAAM;IACJM,QAAQ;IACRC,gBAAgB;IAChBC,cAAc;IACdC,OAAO,GAAG,IAAI;IACdC,IAAI;IACJC,KAAK;IACLC,OAAO;IACPC,aAAa;IACbC,aAAa;IACbC,aAAa;IACbC;EACF,CAAC,GAAGb,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAMc,UAAU,GAAGb,gBAAgB,CAACc,uBAAuB,CAGzDP,KAAK,IAAI,CAAC,CAAC,CAAC;EAEd,MAAMQ,UAAU,GAAGrB,KAAK,CAACsB,OAAO,CAC9B,MAAMV,IAAI,EACV,CAACW,IAAI,CAACC,SAAS,CAACZ,IAAI,CAAC,CACvB,CAAC;EAED,MAAMa,oBAAoB,GAAGzB,KAAK,CAACsB,OAAO,CACxC,MAAMZ,cAAc,EACpB,CAACa,IAAI,CAACC,SAAS,CAACd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CAACC,SAAS,CAACL,UAAU,CAAC,EAAE,GAC9B,KAAK,CACX,CAAC;EACH,CAAC,EACD,CACER,OAAO,EACPL,gBAAgB,EAChBF,IAAI,EACJiB,UAAU,EACVF,UAAU,EACVV,gBAAgB,EAChBD,QAAQ,EACRmB,aAAa,EACbZ,aAAa,EACbU,oBAAoB,EACpBT,aAAa,EACbU,mBAAmB,EACnBR,OAAO,CAEX,CAAC;EAED,MAAMqB,WAAW,GAAGvC,KAAK,CAACwC,oBAAoB,CAACZ,SAAS,EAAEC,WAAW,CAAC;EAEtE,IAAIY,KAAwB;EAC5B,IAAIF,WAAW,IAAI,OAAO,IAAIA,WAAW,IAAIA,WAAW,CAACE,KAAK,EAAE;IAC9DA,KAAK,GAAGF,WAAW,CAACE,KAAK;EAC3B,CAAC,MAAM,IAAIF,WAAW,EAAEG,MAAM,KAAK,OAAO,EAAE;IAC1CD,KAAK,GAAG,IAAIE,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEA,OAAO;IACLC,SAAS,EAAEL,WAAW,EAAEM,OAAO,GAAGN,WAAW,CAACK,SAAS,GAAGE,SAAS;IACnEL,KAAK;IACLM,IAAI,EAAER,WAAW,EAAES,YAAY;IAC/BC,SAAS,EAAEtC,OAAO,GACb4B,WAAW,EAAEG,MAAM,KAAK,SAAS,IAAIH,WAAW,EAAEG,MAAM,KAAK,MAAM,IACjE,CAACH,WAAW,GACf,KAAK;IACTW,YAAY,EAAEX,WAAW,EAAEW,YAAY,IAAI,KAAK;IAChDC,UAAU,EAAEZ,WAAW,EAAEY;EAC3B,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","canonWhere","canonicalizeWhereClause","stableRids","useMemo","JSON","stringify","stableWithProperties","stableIntersectWith","stableOrderBy","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","length","listPayload","useSyncExternalStore","error","status","Error","fetchMore","hasMore","undefined","data","resolvedList","isLoading","isOptimistic","totalCount"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Fetch objects by their RIDs (Resource Identifiers).\n * When provided, starts with a static objectset containing these RIDs.\n * Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.\n *\n * @example\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })\n *\n * @example\n * // Fetch specific objects by RID, filtered by status\n * useOsdkObjects(Employee, {\n * rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],\n * where: { status: 'active' }\n * })\n */\n rids?: readonly string[];\n\n /**\n * Standard OSDK Where clause with RDP support.\n * When used with `rids`, filters the RID set.\n * When used alone, filters all objects of the type.\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Sort results by one or more properties.\n */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /**\n * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\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 * @default true\n */\n enabled?: boolean;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n EXTRA_OPTIONS extends never | \"$rid\" = never,\n> {\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<\n T,\n \"$allBaseProperties\" | EXTRA_OPTIONS,\n PropertyKeys<T>,\n RDPs\n >[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L; rids: readonly string[] },\n): UseOsdkListResult<LinkedType<Q, L>, {}, \"$rid\">;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, RDPs> & { rids: readonly string[] },\n): UseOsdkListResult<Q, RDPs, \"$rid\">;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<Q, RDPs, \"$rid\">\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>, {}, \"$rid\">\n{\n const { observableClient } = React.useContext(OsdkContext2);\n\n const {\n pageSize,\n dedupeIntervalMs,\n withProperties,\n enabled = true,\n rids,\n where,\n orderBy,\n streamUpdates,\n autoFetchMore,\n intersectWith,\n pivotTo,\n } = options ?? {};\n\n const canonWhere = observableClient.canonicalizeWhereClause<\n Q,\n RDPs\n >(where ?? {});\n\n const stableRids = React.useMemo(\n () => rids,\n [JSON.stringify(rids)],\n );\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableIntersectWith = React.useMemo(\n () => intersectWith,\n [JSON.stringify(intersectWith)],\n );\n\n const stableOrderBy = React.useMemo(\n () => orderBy,\n [JSON.stringify(orderBy)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} [DISABLED]`\n : void 0,\n );\n }\n\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n (observer) =>\n observableClient.observeList({\n type,\n rids: stableRids,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: stableOrderBy,\n streamUpdates,\n withProperties: stableWithProperties,\n autoFetchMore,\n ...(stableIntersectWith\n ? { intersectWith: stableIntersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${\n stableRids ? `[${stableRids.length} rids]` : \"\"\n } ${JSON.stringify(canonWhere)}`\n : void 0,\n );\n },\n [\n enabled,\n observableClient,\n type,\n stableRids,\n canonWhere,\n dedupeIntervalMs,\n pageSize,\n stableOrderBy,\n streamUpdates,\n stableWithProperties,\n autoFetchMore,\n stableIntersectWith,\n pivotTo,\n ],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,\n error,\n data: listPayload?.resolvedList,\n isLoading: enabled\n ? (listPayload?.status === \"loading\" || listPayload?.status === \"init\"\n || !listPayload)\n : false,\n isOptimistic: listPayload?.isOptimistic ?? false,\n totalCount: listPayload?.totalCount,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAqLhD,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAM1C;EACE,MAAM;IAAEC;EAAiB,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAE3D,MAAM;IACJM,QAAQ;IACRC,gBAAgB;IAChBC,cAAc;IACdC,OAAO,GAAG,IAAI;IACdC,IAAI;IACJC,KAAK;IACLC,OAAO;IACPC,aAAa;IACbC,aAAa;IACbC,aAAa;IACbC;EACF,CAAC,GAAGb,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAMc,UAAU,GAAGb,gBAAgB,CAACc,uBAAuB,CAGzDP,KAAK,IAAI,CAAC,CAAC,CAAC;EAEd,MAAMQ,UAAU,GAAGrB,KAAK,CAACsB,OAAO,CAC9B,MAAMV,IAAI,EACV,CAACW,IAAI,CAACC,SAAS,CAACZ,IAAI,CAAC,CACvB,CAAC;EAED,MAAMa,oBAAoB,GAAGzB,KAAK,CAACsB,OAAO,CACxC,MAAMZ,cAAc,EACpB,CAACa,IAAI,CAACC,SAAS,CAACd,cAAc,CAAC,CACjC,CAAC;EAED,MAAMgB,mBAAmB,GAAG1B,KAAK,CAACsB,OAAO,CACvC,MAAML,aAAa,EACnB,CAACM,IAAI,CAACC,SAAS,CAACP,a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VF,UAAU,EACVV,gBAAgB,EAChBD,QAAQ,EACRmB,aAAa,EACbZ,aAAa,EACbU,oBAAoB,EACpBT,aAAa,EACbU,mBAAmB,EACnBR,OAAO,CAEX,CAAC;EAED,MAAMqB,WAAW,GAAGvC,KAAK,CAACwC,oBAAoB,CAACZ,SAAS,EAAEC,WAAW,CAAC;EAEtE,IAAIY,KAAwB;EAC5B,IAAIF,WAAW,IAAI,OAAO,IAAIA,WAAW,IAAIA,WAAW,CAACE,KAAK,EAAE;IAC9DA,KAAK,GAAGF,WAAW,CAACE,KAAK;EAC3B,CAAC,MAAM,IAAIF,WAAW,EAAEG,MAAM,KAAK,OAAO,EAAE;IAC1CD,KAAK,GAAG,IAAIE,KAAK,CAAC,wBAAwB,CAAC;EAC7C;EAEA,OAAO;IACLC,SAAS,EAAEL,WAAW,EAAEM,OAAO,GAAGN,WAAW,CAACK,SAAS,GAAGE,SAAS;IACnEL,KAAK;IACLM,IAAI,EAAER,WAAW,EAAES,YAAY;IAC/BC,SAAS,EAAEtC,OAAO,GACb4B,WAAW,EAAEG,MAAM,KAAK,SAAS,IAAIH,WAAW,EAAEG,MAAM,KAAK,MAAM,IACjE,CAACH,WAAW,GACf,KAAK;IACTW,YAAY,EAAEX,WAAW,EAAEW,YAAY,IAAI,KAAK;IAChDC,UAAU,EAAEZ,WAAW,EAAEY;EAC3B,CAAC;AACH","ignoreList":[]}
@@ -671,8 +671,9 @@ function useOsdkObject(...args) {
671
671
  const isInstanceSignature = "$objectType" in args[0];
672
672
  const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
673
673
  const mode = isInstanceSignature ? "offline" : void 0;
674
- const objectType = isInstanceSignature ? args[0].$objectType : args[0].apiName;
674
+ const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
675
675
  const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
676
+ const apiNameString = typeof typeOrApiName === "string" ? typeOrApiName : typeOrApiName.apiName;
676
677
  const {
677
678
  subscribe,
678
679
  getSnapShot
@@ -683,10 +684,10 @@ function useOsdkObject(...args) {
683
684
  }
684
685
  }));
685
686
  }
686
- return makeExternalStore((observer) => observableClient.observeObject(objectType, primaryKey, {
687
+ return makeExternalStore((observer) => observableClient.observeObject(typeOrApiName, primaryKey, {
687
688
  mode
688
689
  }, observer));
689
- }, [enabled, observableClient, objectType, primaryKey, mode]);
690
+ }, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode]);
690
691
  const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
691
692
  let error;
692
693
  if (payload && "error" in payload && payload.error) {