@osdk/react 2.94.0 → 2.95.0-main-a5bdff2e9db1a01e5858042ee5232cb13c13368a
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 +10 -0
- package/build/browser/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -1
- package/build/browser/new/platform-apis/admin/useFoundryUser.js.map +1 -1
- package/build/browser/new/platform-apis/admin/useFoundryUsersList.js.map +1 -1
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useObjectSet.js.map +1 -1
- package/build/browser/new/useOsdkAggregation.js +2 -5
- package/build/browser/new/useOsdkAggregation.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/browser/util/UserAgent.js.map +1 -1
- package/build/cjs/{chunk-EJT5W6SI.cjs → chunk-YG7PT4LT.cjs} +3 -3
- package/build/cjs/chunk-YG7PT4LT.cjs.map +1 -0
- package/build/cjs/index.cjs +15 -15
- package/build/cjs/public/experimental.cjs +16 -16
- package/build/cjs/public/experimental.d.cts +9 -12
- package/build/cjs/public/platform-apis.d.cts +1 -4
- package/build/esm/new/platform-apis/admin/useCurrentFoundryUser.js.map +1 -1
- package/build/esm/new/platform-apis/admin/useFoundryUser.js.map +1 -1
- package/build/esm/new/platform-apis/admin/useFoundryUsersList.js.map +1 -1
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useObjectSet.js.map +1 -1
- package/build/esm/new/useOsdkAggregation.js +2 -5
- package/build/esm/new/useOsdkAggregation.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/esm/util/UserAgent.js.map +1 -1
- package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts +0 -1
- package/build/types/new/platform-apis/admin/useCurrentFoundryUser.d.ts.map +1 -1
- package/build/types/new/platform-apis/admin/useFoundryUser.d.ts +1 -2
- package/build/types/new/platform-apis/admin/useFoundryUser.d.ts.map +1 -1
- package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts +0 -1
- package/build/types/new/platform-apis/admin/useFoundryUsersList.d.ts.map +1 -1
- package/build/types/new/useLinks.d.ts +2 -2
- package/build/types/new/useObjectSet.d.ts +2 -2
- package/build/types/new/useOsdkAggregation.d.ts +3 -6
- package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +2 -2
- package/docs/actions.mdx +314 -0
- package/docs/aggregations.mdx +256 -0
- package/docs/cache-invalidation.mdx +229 -0
- package/docs/devtools/cache.mdx +29 -0
- package/docs/devtools/components.mdx +40 -0
- package/docs/devtools/console.mdx +29 -0
- package/docs/devtools/index.mdx +151 -0
- package/docs/devtools/overview.mdx +45 -0
- package/docs/functions.mdx +246 -0
- package/docs/index.mdx +62 -0
- package/docs/links.mdx +270 -0
- package/docs/meta.json +30 -0
- package/docs/object-sets.mdx +296 -0
- package/docs/objects.mdx +489 -0
- package/docs/optimistic-updates.mdx +164 -0
- package/docs/platform-apis.mdx +296 -0
- package/docs/testing.mdx +348 -0
- package/package.json +7 -7
- package/build/cjs/chunk-EJT5W6SI.cjs.map +0 -1
- package/docs/actions.md +0 -432
- package/docs/advanced-queries.md +0 -678
- package/docs/cache-management.md +0 -222
- package/docs/getting-started.md +0 -319
- package/docs/platform-apis.md +0 -234
- package/docs/prerequisites.md +0 -48
- package/docs/querying-data.md +0 -810
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @osdkkit/react
|
|
2
2
|
|
|
3
|
+
## 2.95.0-main-a5bdff2e9db1a01e5858042ee5232cb13c13368a
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 718be7c: Rebuild the docs site with Markdown versions of every page for AI tools, correct hook and OAuth doc comments, and ship the rewritten React guides in the @osdk/react package
|
|
8
|
+
- Updated dependencies [a5bdff2]
|
|
9
|
+
- @osdk/api@2.95.0-main-a5bdff2e9db1a01e5858042ee5232cb13c13368a
|
|
10
|
+
- @osdk/client@2.95.0-main-a5bdff2e9db1a01e5858042ee5232cb13c13368a
|
|
11
|
+
- @osdk/aip-core@0.13.0
|
|
12
|
+
|
|
3
13
|
## 2.94.0
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentFoundryUser.js","names":["Users","React","usePlatformQuery","OsdkContext","useCurrentFoundryUser","enabled","client","useContext","handleQuery","useCallback","getCurrent","query","queryName","currentUser","data","isLoading","error","refetch"],"sources":["useCurrentFoundryUser.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 User, Users } from \"@osdk/foundry.admin\";\nimport React from \"react\";\n\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext } from \"../../OsdkContext.js\";\n\nexport interface UseCurrentFoundryUserOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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
|
|
1
|
+
{"version":3,"file":"useCurrentFoundryUser.js","names":["Users","React","usePlatformQuery","OsdkContext","useCurrentFoundryUser","enabled","client","useContext","handleQuery","useCallback","getCurrent","query","queryName","currentUser","data","isLoading","error","refetch"],"sources":["useCurrentFoundryUser.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 User, Users } from \"@osdk/foundry.admin\";\nimport React from \"react\";\n\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext } from \"../../OsdkContext.js\";\n\nexport interface UseCurrentFoundryUserOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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 */\n enabled?: boolean;\n}\n\nexport interface UseCurrentFoundryUserResult {\n currentUser: User | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get the currently signed in User.\n * @param options Options to control the query.\n */\nexport function useCurrentFoundryUser({\n enabled = true,\n}: UseCurrentFoundryUserOptions = {}): UseCurrentFoundryUserResult {\n const { client } = React.useContext(OsdkContext);\n\n const handleQuery = React.useCallback(\n () => Users.getCurrent(client),\n [client],\n );\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"foundry-current-user\",\n });\n\n return {\n currentUser: query.data,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAoBA,KAAK,QAAQ,qBAAqB;AACtD,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,WAAW,QAAQ,sBAAsB;AA2BlD;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAC;EACpCC,OAAO,GAAG;AACkB,CAAC,GAAG,CAAC,CAAC,EAA+B;EACjE,MAAM;IAAEC;EAAO,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,WAAW,CAAC;EAEhD,MAAMK,WAAW,GAAGP,KAAK,CAACQ,WAAW,CACnC,MAAMT,KAAK,CAACU,UAAU,CAACJ,MAAM,CAAC,EAC9B,CAACA,MAAM,CACT,CAAC;EAED,MAAMK,KAAK,GAAGT,gBAAgB,CAAC;IAC7BS,KAAK,EAAEH,WAAW;IAClBH,OAAO;IACPO,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,WAAW,EAAEF,KAAK,CAACG,IAAI;IACvBC,SAAS,EAAEJ,KAAK,CAACI,SAAS;IAC1BC,KAAK,EAAEL,KAAK,CAACK,KAAK;IAClBC,OAAO,EAAEN,KAAK,CAACM;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFoundryUser.js","names":["Users","React","usePlatformQuery","OsdkContext","useFoundryUser","userId","enabled","status","client","useContext","handleQuery","useCallback","get","query","queryName","user","data","isLoading","error","refetch"],"sources":["useFoundryUser.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 User, Users } from \"@osdk/foundry.admin\";\nimport type { UserStatus } from \"@osdk/foundry.core\";\nimport React from \"react\";\n\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext } from \"../../OsdkContext.js\";\n\nexport interface UseFoundryUserOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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
|
|
1
|
+
{"version":3,"file":"useFoundryUser.js","names":["Users","React","usePlatformQuery","OsdkContext","useFoundryUser","userId","enabled","status","client","useContext","handleQuery","useCallback","get","query","queryName","user","data","isLoading","error","refetch"],"sources":["useFoundryUser.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 User, Users } from \"@osdk/foundry.admin\";\nimport type { UserStatus } from \"@osdk/foundry.core\";\nimport React from \"react\";\n\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext } from \"../../OsdkContext.js\";\n\nexport interface UseFoundryUserOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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 */\n enabled?: boolean;\n\n /**\n * The status filter applied when fetching the user.\n *\n * @default \"ACTIVE\"\n */\n status?: UserStatus;\n}\n\nexport interface UseFoundryUserResult {\n user: User | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get the User with the specified id.\n * @param userId A Foundry User ID.\n * @param options Options to control the query.\n */\nexport function useFoundryUser(\n userId: string,\n { enabled = true, status = \"ACTIVE\" }: UseFoundryUserOptions = {},\n): UseFoundryUserResult {\n const { client } = React.useContext(OsdkContext);\n\n const handleQuery = React.useCallback(() => {\n return Users.get(client, userId, { status });\n }, [client, userId, status]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"foundry-user\",\n });\n\n return {\n user: query.data,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAoBA,KAAK,QAAQ,qBAAqB;AAEtD,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,WAAW,QAAQ,sBAAsB;AAkClD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAC5BC,MAAc,EACd;EAAEC,OAAO,GAAG,IAAI;EAAEC,MAAM,GAAG;AAAgC,CAAC,GAAG,CAAC,CAAC,EAC3C;EACtB,MAAM;IAAEC;EAAO,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACN,WAAW,CAAC;EAEhD,MAAMO,WAAW,GAAGT,KAAK,CAACU,WAAW,CAAC,MAAM;IAC1C,OAAOX,KAAK,CAACY,GAAG,CAACJ,MAAM,EAAEH,MAAM,EAAE;MAAEE;IAAO,CAAC,CAAC;EAC9C,CAAC,EAAE,CAACC,MAAM,EAAEH,MAAM,EAAEE,MAAM,CAAC,CAAC;EAE5B,MAAMM,KAAK,GAAGX,gBAAgB,CAAC;IAC7BW,KAAK,EAAEH,WAAW;IAClBJ,OAAO;IACPQ,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,IAAI,EAAEF,KAAK,CAACG,IAAI;IAChBC,SAAS,EAAEJ,KAAK,CAACI,SAAS;IAC1BC,KAAK,EAAEL,KAAK,CAACK,KAAK;IAClBC,OAAO,EAAEN,KAAK,CAACM;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFoundryUsersList.js","names":["Users","React","usePlatformQuery","OsdkContext","useFoundryUsersList","enabled","include","pageSize","pageToken","client","useContext","handleQuery","useCallback","list","query","queryName","users","data","nextPageToken","isLoading","error","refetch"],"sources":["useFoundryUsersList.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 ListUsersResponse, Users } from \"@osdk/foundry.admin\";\nimport type { UserStatus } from \"@osdk/foundry.core\";\nimport React from \"react\";\n\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext } from \"../../OsdkContext.js\";\n\nexport interface UseFoundryUsersListOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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
|
|
1
|
+
{"version":3,"file":"useFoundryUsersList.js","names":["Users","React","usePlatformQuery","OsdkContext","useFoundryUsersList","enabled","include","pageSize","pageToken","client","useContext","handleQuery","useCallback","list","query","queryName","users","data","nextPageToken","isLoading","error","refetch"],"sources":["useFoundryUsersList.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 ListUsersResponse, Users } from \"@osdk/foundry.admin\";\nimport type { UserStatus } from \"@osdk/foundry.core\";\nimport React from \"react\";\n\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext } from \"../../OsdkContext.js\";\n\nexport interface UseFoundryUsersListOptions {\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\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 */\n enabled?: boolean;\n\n /**\n * The default status of the users returned in the list.\n *\n * @default \"ACTIVE\"\n */\n include?: UserStatus;\n\n /**\n * The preferred page size for the list.\n *\n * @default 1000\n */\n pageSize?: number;\n\n /**\n * The page token indicates where to start paging. This should be omitted from the first page's request.\n * To fetch the next page, clients should take the value from the nextPageToken field of the previous\n * response and use it to populate the pageToken field of the next request.\n */\n pageToken?: string;\n}\n\nexport interface UseFoundryUsersListResult {\n users: ListUsersResponse[\"data\"] | undefined;\n /**\n * The page token to be used for the next page of users. If this is undefined, there are no more\n * pages of users to load.\n */\n nextPageToken: string | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Lists all Users. This is a paged endpoint. Each page may be smaller or larger than the requested page size.\n * @param options Options to control the query.\n */\nexport function useFoundryUsersList({\n enabled = true,\n include = \"ACTIVE\",\n pageSize = 1000,\n pageToken,\n}: UseFoundryUsersListOptions = {}): UseFoundryUsersListResult {\n const { client } = React.useContext(OsdkContext);\n\n const handleQuery = React.useCallback(() => {\n return Users.list(client, { include, pageSize, pageToken });\n }, [client, include, pageSize, pageToken]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"foundry-users-list\",\n });\n\n return {\n users: query.data?.data,\n nextPageToken: query.data?.nextPageToken,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAiCA,KAAK,QAAQ,qBAAqB;AAEnE,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,WAAW,QAAQ,sBAAsB;AAqDlD;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAC;EAClCC,OAAO,GAAG,IAAI;EACdC,OAAO,GAAG,QAAQ;EAClBC,QAAQ,GAAG,IAAI;EACfC;AAC0B,CAAC,GAAG,CAAC,CAAC,EAA6B;EAC7D,MAAM;IAAEC;EAAO,CAAC,GAAGR,KAAK,CAACS,UAAU,CAACP,WAAW,CAAC;EAEhD,MAAMQ,WAAW,GAAGV,KAAK,CAACW,WAAW,CAAC,MAAM;IAC1C,OAAOZ,KAAK,CAACa,IAAI,CAACJ,MAAM,EAAE;MAAEH,OAAO;MAAEC,QAAQ;MAAEC;IAAU,CAAC,CAAC;EAC7D,CAAC,EAAE,CAACC,MAAM,EAAEH,OAAO,EAAEC,QAAQ,EAAEC,SAAS,CAAC,CAAC;EAE1C,MAAMM,KAAK,GAAGZ,gBAAgB,CAAC;IAC7BY,KAAK,EAAEH,WAAW;IAClBN,OAAO;IACPU,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLC,KAAK,EAAEF,KAAK,CAACG,IAAI,EAAEA,IAAI;IACvBC,aAAa,EAAEJ,KAAK,CAACG,IAAI,EAAEC,aAAa;IACxCC,SAAS,EAAEL,KAAK,CAACK,SAAS;IAC1BC,KAAK,EAAEN,KAAK,CAACM,KAAK;IAClBC,OAAO,EAAEP,KAAK,CAACO;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinks.js","names":["React","extractPayloadError","isPayloadLoading","devToolsMetadata","makeExternalStore","OsdkContext","emptyArray","Object","freeze","emptyMap","Map","useLinks","objects","linkName","options","observableClient","useContext","enabled","$includeAllBaseObjectProperties","resolveToObjectType","otherOptions","canonOptions","canonicalizeOptions","where","orderBy","$select","objectsKey","useMemo","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","hookType","sourceObjectType","observer","observeLinks","pageSize","autoFetchMore","mode","dedupeInterval","dedupeIntervalMs","select","payload","useSyncExternalStore","links","resolvedList","linkedObjectsBySourcePrimaryKey","isLoading","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport { devToolsMetadata, makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nimport type { ResolveToObjectTypeOption } from \"./useOsdkObjects.js\";\n\nexport type UseLinksOptions<T extends ObjectOrInterfaceDefinition> =\n UseLinksBaseOptions<T> & ResolveToObjectTypeOption<T>;\n\ninterface UseLinksBaseOptions<T extends ObjectOrInterfaceDefinition> {\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 /**\n * Fetch all pages when true, or at least this many linked objects per source\n * when a number is provided. Defaults to manual pagination.\n */\n autoFetchMore?: boolean | number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Restrict which properties are returned for each linked object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<T>[];\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 * The number of milliseconds to wait after the last observed link change.\n *\n * Two uses of `useLinks` 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 * 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 * ```tsx\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 */\n enabled?: boolean;\n\n /**\n * When true, includes all properties of the underlying concrete object type\n * for interface link targets. Has no effect when the link target is a plain\n * object type.\n */\n $includeAllBaseObjectProperties?: boolean;\n}\n\nexport interface UseLinksResult<Q extends ObjectOrInterfaceDefinition> {\n links: Osdk.Instance<Q, \"$allBaseProperties\">[] | undefined;\n\n /**\n * Maps each source object's primary key to its linked object instances.\n * Useful when observing links from multiple source objects to determine\n * which source links to which targets.\n */\n linkedObjectsBySourcePrimaryKey: ReadonlyMap<\n string | number,\n ReadonlyArray<Osdk.Instance<Q, \"$allBaseProperties\">>\n >;\n\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([]);\nconst emptyMap: ReadonlyMap<string | number, ReadonlyArray<never>> = new Map();\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext);\n\n const {\n enabled = true,\n $includeAllBaseObjectProperties,\n resolveToObjectType,\n ...otherOptions\n } = options;\n\n const canonOptions = observableClient.canonicalizeOptions({\n where: otherOptions.where,\n orderBy: otherOptions.orderBy,\n $select: otherOptions.$select,\n });\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map((obj) => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<LinkedType<T, L>>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useLinks\",\n sourceObjectType: objectsArray[0]?.$apiName,\n linkName,\n }),\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<LinkedType<T, L>>>(\n (observer) =>\n observableClient.observeLinks<T, L>(\n objectsArray,\n linkName,\n {\n linkName,\n where: canonOptions.where,\n pageSize: otherOptions.pageSize,\n autoFetchMore: otherOptions.autoFetchMore,\n orderBy: canonOptions.orderBy,\n mode: otherOptions.mode,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n $includeAllBaseObjectProperties,\n resolveToObjectType,\n ...(canonOptions.$select ? { select: canonOptions.$select } : {}),\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useLinks\",\n sourceObjectType: objectsArray[0]?.$apiName,\n linkName,\n }),\n );\n }, [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n canonOptions.where,\n otherOptions.pageSize,\n otherOptions.autoFetchMore,\n canonOptions.orderBy,\n otherOptions.mode,\n otherOptions.dedupeIntervalMs,\n canonOptions.$select,\n $includeAllBaseObjectProperties,\n !!resolveToObjectType,\n ]);\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return React.useMemo(\n () => ({\n links: payload?.resolvedList,\n linkedObjectsBySourcePrimaryKey:\n payload?.linkedObjectsBySourcePrimaryKey ?? emptyMap,\n isLoading: isPayloadLoading(payload, enabled),\n isOptimistic: payload?.isOptimistic ?? false,\n error: extractPayloadError(payload, \"Failed to load links\"),\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n }),\n [payload, enabled],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,gBAAgB;AACtE,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,wBAAwB;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAkH9C,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;AACpC,MAAMC,QAA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Y,CAAC6B,gBAAgB,EAC7B5B,YAAY,CAACI,OAAO,EACpBP,+BAA+B,EAC/B,CAAC,CAACC,mBAAmB,CACtB,CAAC;EAEF,MAAMgC,OAAO,GAAGnD,KAAK,CAACoD,oBAAoB,CAACd,SAAS,EAAEC,WAAW,CAAC;EAElE,OAAOvC,KAAK,CAAC2B,OAAO,CAClB,OAAO;IACL0B,KAAK,EAAEF,OAAO,EAAEG,YAAY;IAC5BC,+BAA+B,EAC7BJ,OAAO,EAAEI,+BAA+B,IAAI9C,QAAQ;IACtD+C,SAAS,EAAEtD,gBAAgB,CAACiD,OAAO,EAAElC,OAAO,CAAC;IAC7CwC,YAAY,EAAEN,OAAO,EAAEM,YAAY,IAAI,KAAK;IAC5CC,KAAK,EAAEzD,mBAAmB,CAACkD,OAAO,EAAE,sBAAsB,CAAC;IAC3DQ,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,EAAEQ,SAAS,GAAG/B,SAAS;IAC5DgC,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC,CAAC,EACF,CAACT,OAAO,EAAElC,OAAO,CACnB,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useLinks.js","names":["React","extractPayloadError","isPayloadLoading","devToolsMetadata","makeExternalStore","OsdkContext","emptyArray","Object","freeze","emptyMap","Map","useLinks","objects","linkName","options","observableClient","useContext","enabled","$includeAllBaseObjectProperties","resolveToObjectType","otherOptions","canonOptions","canonicalizeOptions","where","orderBy","$select","objectsKey","useMemo","undefined","arr","Array","isArray","map","obj","$apiName","$primaryKey","join","objectsArray","subscribe","getSnapShot","unsubscribe","hookType","sourceObjectType","observer","observeLinks","pageSize","autoFetchMore","mode","dedupeInterval","dedupeIntervalMs","select","payload","useSyncExternalStore","links","resolvedList","linkedObjectsBySourcePrimaryKey","isLoading","isOptimistic","error","fetchMore","hasMore"],"sources":["useLinks.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { Osdk, PropertyKeys, WhereClause } from \"@osdk/client\";\nimport type { ObserveLinks } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport { devToolsMetadata, makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nimport type { ResolveToObjectTypeOption } from \"./useOsdkObjects.js\";\n\nexport type UseLinksOptions<T extends ObjectOrInterfaceDefinition> =\n UseLinksBaseOptions<T> & ResolveToObjectTypeOption<T>;\n\ninterface UseLinksBaseOptions<T extends ObjectOrInterfaceDefinition> {\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 /**\n * Fetch all pages when true, or at least this many linked objects per source\n * when a number is provided. Defaults to manual pagination.\n */\n autoFetchMore?: boolean | number;\n\n /** Sorting options for the linked objects */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Restrict which properties are returned for each linked object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<T>[];\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 * The number of milliseconds to wait after the last observed link change.\n *\n * Two uses of `useLinks` 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 does not run and the hook returns no data, even\n * if the cache already holds a result.\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 * ```tsx\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 */\n enabled?: boolean;\n\n /**\n * When true, includes all properties of the underlying concrete object type\n * for interface link targets. Has no effect when the link target is a plain\n * object type.\n */\n $includeAllBaseObjectProperties?: boolean;\n}\n\nexport interface UseLinksResult<Q extends ObjectOrInterfaceDefinition> {\n links: Osdk.Instance<Q, \"$allBaseProperties\">[] | undefined;\n\n /**\n * Maps each source object's primary key to its linked object instances.\n * Useful when observing links from multiple source objects to determine\n * which source links to which targets.\n */\n linkedObjectsBySourcePrimaryKey: ReadonlyMap<\n string | number,\n ReadonlyArray<Osdk.Instance<Q, \"$allBaseProperties\">>\n >;\n\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([]);\nconst emptyMap: ReadonlyMap<string | number, ReadonlyArray<never>> = new Map();\n\n/**\n * Hook to observe links from an object or array of objects.\n *\n * @param objects The source object(s) to observe links from\n * @param linkName The name of the link to observe\n * @param options Optional configuration for the link query\n * @returns UseLinksResult with links data and metadata\n */\nexport function useLinks<\n T extends ObjectOrInterfaceDefinition,\n L extends LinkNames<T>,\n>(\n objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined,\n linkName: L,\n options: UseLinksOptions<LinkedType<T, L>> = {},\n): UseLinksResult<LinkedType<T, L>> {\n const { observableClient } = React.useContext(OsdkContext);\n\n const {\n enabled = true,\n $includeAllBaseObjectProperties,\n resolveToObjectType,\n ...otherOptions\n } = options;\n\n const canonOptions = observableClient.canonicalizeOptions({\n where: otherOptions.where,\n orderBy: otherOptions.orderBy,\n $select: otherOptions.$select,\n });\n\n const objectsKey = React.useMemo(() => {\n if (objects === undefined) return \"\";\n const arr = Array.isArray(objects) ? objects : [objects];\n return arr.map((obj) => `${obj.$apiName}:${obj.$primaryKey}`).join(\",\");\n }, [objects]);\n\n // Convert single object to array for consistent handling\n const objectsArray: ReadonlyArray<Osdk.Instance<T>> = React.useMemo(() => {\n return objects === undefined\n ? emptyArray\n : Array.isArray(objects)\n ? objects\n : [objects];\n }, [objectsKey, objects]);\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveLinks.CallbackArgs<LinkedType<T, L>>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useLinks\",\n sourceObjectType: objectsArray[0]?.$apiName,\n linkName,\n }),\n );\n }\n return makeExternalStore<ObserveLinks.CallbackArgs<LinkedType<T, L>>>(\n (observer) =>\n observableClient.observeLinks<T, L>(\n objectsArray,\n linkName,\n {\n linkName,\n where: canonOptions.where,\n pageSize: otherOptions.pageSize,\n autoFetchMore: otherOptions.autoFetchMore,\n orderBy: canonOptions.orderBy,\n mode: otherOptions.mode,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n $includeAllBaseObjectProperties,\n resolveToObjectType,\n ...(canonOptions.$select ? { select: canonOptions.$select } : {}),\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useLinks\",\n sourceObjectType: objectsArray[0]?.$apiName,\n linkName,\n }),\n );\n }, [\n enabled,\n observableClient,\n objectsArray,\n objectsKey,\n linkName,\n canonOptions.where,\n otherOptions.pageSize,\n otherOptions.autoFetchMore,\n canonOptions.orderBy,\n otherOptions.mode,\n otherOptions.dedupeIntervalMs,\n canonOptions.$select,\n $includeAllBaseObjectProperties,\n !!resolveToObjectType,\n ]);\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return React.useMemo(\n () => ({\n links: payload?.resolvedList,\n linkedObjectsBySourcePrimaryKey:\n payload?.linkedObjectsBySourcePrimaryKey ?? emptyMap,\n isLoading: isPayloadLoading(payload, enabled),\n isOptimistic: payload?.isOptimistic ?? false,\n error: extractPayloadError(payload, \"Failed to load links\"),\n fetchMore: payload?.hasMore ? payload?.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n }),\n [payload, enabled],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,gBAAgB;AACtE,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,wBAAwB;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAkH9C,MAAMC,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;AACpC,MAAMC,QAA4D,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAE9E;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,GAAGf,KAAK,CAACgB,UAAU,CAACX,WAAW,CAAC;EAE1D,MAAM;IACJY,OAAO,GAAG,IAAI;IACdC,+BAA+B;IAC/BC,mBAAmB;IACnB,GAAGC;EACL,CAAC,GAAGN,OAAO;EAEX,MAAMO,YAAY,GAAGN,gBAAgB,CAACO,mBAAmB,CAAC;IACxDC,KAAK,EAAEH,YAAY,CAACG,KAAK;IACzBC,OAAO,EAAEJ,YAAY,CAACI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mBAAmB,CAACkD,OAAO,EAAE,sBAAsB,CAAC;IAC3DQ,SAAS,EAAER,OAAO,EAAES,OAAO,GAAGT,OAAO,EAAEQ,SAAS,GAAG/B,SAAS;IAC5DgC,OAAO,EAAET,OAAO,EAAES,OAAO,IAAI;EAC/B,CAAC,CAAC,EACF,CAACT,OAAO,EAAElC,OAAO,CACnB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectSet.js","names":["getWireObjectSet","React","extractPayloadError","devToolsMetadata","makeExternalStore","OsdkContext","OBJECT_TYPE_PLACEHOLDER","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","enabledOption","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousCompletedPayloadRef","objectTypeChanged","current","undefined","canonOptions","canonicalizeOptions","where","withProperties","orderBy","union","intersect","subtract","$select","objectSetKey","JSON","stringify","baseObjectSetRef","subscribe","getSnapShot","useMemo","unsubscribe","hookType","objectType","initialValue","observer","subscription","observeObjectSet","pivotTo","pageSize","dedupeInterval","dedupeIntervalMs","autoFetchMore","select","payload","useSyncExternalStore","isPayloadCompleted","typeApiName","refetch","useCallback","invalidateObjectType","lastLoaded","data","resolvedList","isLoading","error","isOptimistic","fetchMore","hasMore","objectSet","totalCount","status"],"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 ObjectOrInterfaceDefinition,\n ObjectSet,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport { getWireObjectSet } from \"@osdk/client\";\nimport type { ObserveObjectSetArgs } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError } from \"./hookUtils.js\";\nimport {\n devToolsMetadata,\n makeExternalStore,\n type Snapshot,\n} from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\nexport interface UseObjectSetOptions<\n Q extends ObjectOrInterfaceDefinition,\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 * Cannot be combined with `streamUpdates`. The server does not support\n * websocket subscriptions for link-traversal queries.\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 * Cannot be combined with `pivotTo`. The server does not support\n * websocket subscriptions for link-traversal queries.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Restrict which properties are returned for each object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<Q>[];\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 * ```tsx\n * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus,\n * });\n * ```\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends ObjectOrInterfaceDefinition,\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 isOptimistic: boolean;\n\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n hasMore: boolean;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs> | undefined;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n\n refetch: () => Promise<void>;\n}\n\nconst OBJECT_TYPE_PLACEHOLDER = \"$__OBJECT__TYPE__PLACEHOLDER\";\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 */\n// pivotTo overload: streamUpdates is forbidden (the server does not support\n// websocket subscriptions for link-traversal queries).\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined,\n options: UseObjectSetOptions<Q, RDPs> & {\n pivotTo: LinkNames<Q>;\n streamUpdates?: never;\n },\n): UseObjectSetResult<Q, RDPs>;\n\n// Non-pivotTo overload: pivotTo is forbidden to prevent fallthrough.\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined,\n options?: UseObjectSetOptions<Q, RDPs> & { pivotTo?: never },\n): UseObjectSetResult<Q, RDPs>;\n\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext);\n\n const {\n enabled: enabledOption = true,\n streamUpdates,\n ...otherOptions\n } = options;\n const enabled = enabledOption && baseObjectSet != null;\n\n // Track object type to detect when we switch to a different object type\n const objectTypeKey =\n enabled && baseObjectSet\n ? baseObjectSet.$objectSetInternals.def.apiName\n : OBJECT_TYPE_PLACEHOLDER;\n\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousCompletedPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n // TODO: Is it expected to only clear the previousCompletedPayloadRef when the object type changes?\n // What if the same object type is queried with different filters, should we also clear the cache?\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\n previousCompletedPayloadRef.current = undefined;\n }\n\n // canonicalizeOptions stabilizes complex query identity options.\n // pageSize is a view level concern (handled per subscriber, not part of\n // query identity), and pivotTo is a plain string that does not need\n // stabilization.\n const canonOptions = observableClient.canonicalizeOptions({\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n orderBy: otherOptions.orderBy,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n $select: otherOptions.$select,\n });\n\n const objectSetKey = baseObjectSet\n ? JSON.stringify(getWireObjectSet(baseObjectSet as ObjectSet<Q>))\n : undefined;\n\n const baseObjectSetRef = React.useRef(baseObjectSet);\n baseObjectSetRef.current = baseObjectSet;\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useObjectSet\",\n objectType: objectTypeKey,\n }),\n );\n }\n\n const initialValue = objectTypeChanged\n ? undefined\n : previousCompletedPayloadRef.current;\n\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n if (!baseObjectSetRef.current) {\n return { unsubscribe: () => {} };\n }\n const subscription = observableClient.observeObjectSet(\n baseObjectSetRef.current as ObjectSet<Q>,\n {\n where: canonOptions.where,\n withProperties: canonOptions.withProperties,\n union: canonOptions.union,\n intersect: canonOptions.intersect,\n subtract: canonOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: canonOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n select: canonOptions.$select,\n },\n observer,\n );\n return subscription;\n },\n devToolsMetadata({\n hookType: \"useObjectSet\",\n objectType: objectTypeKey,\n }),\n initialValue,\n );\n }, [\n enabled,\n observableClient,\n objectSetKey,\n canonOptions.where,\n canonOptions.withProperties,\n canonOptions.orderBy,\n canonOptions.union,\n canonOptions.intersect,\n canonOptions.subtract,\n canonOptions.$select,\n otherOptions.pivotTo,\n otherOptions.pageSize,\n otherOptions.autoFetchMore,\n otherOptions.dedupeIntervalMs,\n streamUpdates,\n objectTypeKey,\n ]);\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n if (payload && isPayloadCompleted(payload)) {\n previousCompletedPayloadRef.current = payload;\n }\n\n const typeApiName = baseObjectSet?.$objectSetInternals.def.apiName;\n\n const refetch = React.useCallback(async () => {\n if (typeApiName) {\n await observableClient.invalidateObjectType(typeApiName);\n }\n }, [observableClient, typeApiName]);\n\n return React.useMemo(() => {\n const lastLoaded = isPayloadCompleted(payload)\n ? payload\n : previousCompletedPayloadRef.current;\n return {\n data: lastLoaded?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: enabled ? !isPayloadCompleted(payload) : false,\n error: extractPayloadError(lastLoaded, \"Failed to load object set\"),\n isOptimistic: payload?.isOptimistic ?? false,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n objectSet: lastLoaded?.objectSet as ObjectSet<Q, RDPs> | undefined,\n totalCount: lastLoaded?.totalCount,\n refetch,\n };\n }, [payload, refetch, enabled]);\n}\n\nfunction isPayloadCompleted<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n>(payload: Snapshot<ObserveObjectSetArgs<Q, RDPs>>): boolean {\n if (payload != null && \"error\" in payload) {\n return true;\n }\n\n if (payload?.status == null) {\n return false;\n }\n\n switch (payload.status) {\n case \"loaded\":\n case \"error\":\n return true;\n case \"loading\":\n case \"init\":\n return false;\n default:\n payload.status satisfies never;\n return false;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASA,gBAAgB,QAAQ,cAAc;AAE/C,OAAOC,KAAK,MAAM,OAAO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gBAAgB,EAAEgD,WAAW,CAAC,CAAC;EAEnC,OAAOzD,KAAK,CAACwC,OAAO,CAAC,MAAM;IACzB,MAAMqB,UAAU,GAAGL,kBAAkB,CAACF,OAAO,CAAC,GAC1CA,OAAO,GACPjC,2BAA2B,CAACE,OAAO;IACvC,OAAO;MACLuC,IAAI,EAAED,UAAU,EAAEE,YAKf;MACHC,SAAS,EAAErD,OAAO,GAAG,CAAC6C,kBAAkB,CAACF,OAAO,CAAC,GAAG,KAAK;MACzDW,KAAK,EAAEhE,mBAAmB,CAAC4D,UAAU,EAAE,2BAA2B,CAAC;MACnEK,YAAY,EAAEZ,OAAO,EAAEY,YAAY,IAAI,KAAK;MAC5CC,SAAS,EAAEb,OAAO,EAAEc,OAAO,GAAGd,OAAO,CAACa,SAAS,GAAG3C,SAAS;MAC3D4C,OAAO,EAAEd,OAAO,EAAEc,OAAO,IAAI,KAAK;MAClCC,SAAS,EAAER,UAAU,EAAEQ,SAA2C;MAClEC,UAAU,EAAET,UAAU,EAAES,UAAU;MAClCZ;IACF,CAAC;EACH,CAAC,EAAE,CAACJ,OAAO,EAAEI,OAAO,EAAE/C,OAAO,CAAC,CAAC;AACjC;AAEA,SAAS6C,kBAAkBA,CAGzBF,OAAgD,EAAW;EAC3D,IAAIA,OAAO,IAAI,IAAI,IAAI,OAAO,IAAIA,OAAO,EAAE;IACzC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,EAAEiB,MAAM,IAAI,IAAI,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,QAAQjB,OAAO,CAACiB,MAAM;IACpB,KAAK,QAAQ;IACb,KAAK,OAAO;MACV,OAAO,IAAI;IACb,KAAK,SAAS;IACd,KAAK,MAAM;MACT,OAAO,KAAK;IACd;MACEjB,OAAO,CAACiB,MAAM;MACd,OAAO,KAAK;EAChB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useObjectSet.js","names":["getWireObjectSet","React","extractPayloadError","devToolsMetadata","makeExternalStore","OsdkContext","OBJECT_TYPE_PLACEHOLDER","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","enabledOption","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousCompletedPayloadRef","objectTypeChanged","current","undefined","canonOptions","canonicalizeOptions","where","withProperties","orderBy","union","intersect","subtract","$select","objectSetKey","JSON","stringify","baseObjectSetRef","subscribe","getSnapShot","useMemo","unsubscribe","hookType","objectType","initialValue","observer","subscription","observeObjectSet","pivotTo","pageSize","dedupeInterval","dedupeIntervalMs","autoFetchMore","select","payload","useSyncExternalStore","isPayloadCompleted","typeApiName","refetch","useCallback","invalidateObjectType","lastLoaded","data","resolvedList","isLoading","error","isOptimistic","fetchMore","hasMore","objectSet","totalCount","status"],"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 ObjectOrInterfaceDefinition,\n ObjectSet,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport { getWireObjectSet } from \"@osdk/client\";\nimport type { ObserveObjectSetArgs } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError } from \"./hookUtils.js\";\nimport {\n devToolsMetadata,\n makeExternalStore,\n type Snapshot,\n} from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\nexport interface UseObjectSetOptions<\n Q extends ObjectOrInterfaceDefinition,\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 * Cannot be combined with `streamUpdates`. The server does not support\n * websocket subscriptions for link-traversal queries.\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 * Cannot be combined with `pivotTo`. The server does not support\n * websocket subscriptions for link-traversal queries.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Restrict which properties are returned for each object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n */\n $select?: readonly PropertyKeys<Q>[];\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query does not run and the hook returns no data, even\n * if the cache already holds a result.\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 * ```tsx\n * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus,\n * });\n * ```\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends ObjectOrInterfaceDefinition,\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 isOptimistic: boolean;\n\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n hasMore: boolean;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs> | undefined;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n\n refetch: () => Promise<void>;\n}\n\nconst OBJECT_TYPE_PLACEHOLDER = \"$__OBJECT__TYPE__PLACEHOLDER\";\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 */\n// pivotTo overload: streamUpdates is forbidden (the server does not support\n// websocket subscriptions for link-traversal queries).\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined,\n options: UseObjectSetOptions<Q, RDPs> & {\n pivotTo: LinkNames<Q>;\n streamUpdates?: never;\n },\n): UseObjectSetResult<Q, RDPs>;\n\n// Non-pivotTo overload: pivotTo is forbidden to prevent fallthrough.\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined,\n options?: UseObjectSetOptions<Q, RDPs> & { pivotTo?: never },\n): UseObjectSetResult<Q, RDPs>;\n\nexport function useObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n BaseRDPs extends Record<string, SimplePropertyDef> = never,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext);\n\n const {\n enabled: enabledOption = true,\n streamUpdates,\n ...otherOptions\n } = options;\n const enabled = enabledOption && baseObjectSet != null;\n\n // Track object type to detect when we switch to a different object type\n const objectTypeKey =\n enabled && baseObjectSet\n ? baseObjectSet.$objectSetInternals.def.apiName\n : OBJECT_TYPE_PLACEHOLDER;\n\n const previousObjectTypeRef = React.useRef<string>(objectTypeKey);\n const previousCompletedPayloadRef = React.useRef<\n Snapshot<ObserveObjectSetArgs<Q, RDPs>> | undefined\n >();\n // TODO: Is it expected to only clear the previousCompletedPayloadRef when the object type changes?\n // What if the same object type is queried with different filters, should we also clear the cache?\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\n previousCompletedPayloadRef.current = undefined;\n }\n\n // canonicalizeOptions stabilizes complex query identity options.\n // pageSize is a view level concern (handled per subscriber, not part of\n // query identity), and pivotTo is a plain string that does not need\n // stabilization.\n const canonOptions = observableClient.canonicalizeOptions({\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n orderBy: otherOptions.orderBy,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n $select: otherOptions.$select,\n });\n\n const objectSetKey = baseObjectSet\n ? JSON.stringify(getWireObjectSet(baseObjectSet as ObjectSet<Q>))\n : undefined;\n\n const baseObjectSetRef = React.useRef(baseObjectSet);\n baseObjectSetRef.current = baseObjectSet;\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useObjectSet\",\n objectType: objectTypeKey,\n }),\n );\n }\n\n const initialValue = objectTypeChanged\n ? undefined\n : previousCompletedPayloadRef.current;\n\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n if (!baseObjectSetRef.current) {\n return { unsubscribe: () => {} };\n }\n const subscription = observableClient.observeObjectSet(\n baseObjectSetRef.current as ObjectSet<Q>,\n {\n where: canonOptions.where,\n withProperties: canonOptions.withProperties,\n union: canonOptions.union,\n intersect: canonOptions.intersect,\n subtract: canonOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: canonOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n select: canonOptions.$select,\n },\n observer,\n );\n return subscription;\n },\n devToolsMetadata({\n hookType: \"useObjectSet\",\n objectType: objectTypeKey,\n }),\n initialValue,\n );\n }, [\n enabled,\n observableClient,\n objectSetKey,\n canonOptions.where,\n canonOptions.withProperties,\n canonOptions.orderBy,\n canonOptions.union,\n canonOptions.intersect,\n canonOptions.subtract,\n canonOptions.$select,\n otherOptions.pivotTo,\n otherOptions.pageSize,\n otherOptions.autoFetchMore,\n otherOptions.dedupeIntervalMs,\n streamUpdates,\n objectTypeKey,\n ]);\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n if (payload && isPayloadCompleted(payload)) {\n previousCompletedPayloadRef.current = payload;\n }\n\n const typeApiName = baseObjectSet?.$objectSetInternals.def.apiName;\n\n const refetch = React.useCallback(async () => {\n if (typeApiName) {\n await observableClient.invalidateObjectType(typeApiName);\n }\n }, [observableClient, typeApiName]);\n\n return React.useMemo(() => {\n const lastLoaded = isPayloadCompleted(payload)\n ? payload\n : previousCompletedPayloadRef.current;\n return {\n data: lastLoaded?.resolvedList as Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n >[],\n isLoading: enabled ? !isPayloadCompleted(payload) : false,\n error: extractPayloadError(lastLoaded, \"Failed to load object set\"),\n isOptimistic: payload?.isOptimistic ?? false,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n hasMore: payload?.hasMore ?? false,\n objectSet: lastLoaded?.objectSet as ObjectSet<Q, RDPs> | undefined,\n totalCount: lastLoaded?.totalCount,\n refetch,\n };\n }, [payload, refetch, enabled]);\n}\n\nfunction isPayloadCompleted<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n>(payload: Snapshot<ObserveObjectSetArgs<Q, RDPs>>): boolean {\n if (payload != null && \"error\" in payload) {\n return true;\n }\n\n if (payload?.status == null) {\n return false;\n }\n\n switch (payload.status) {\n case \"loaded\":\n case \"error\":\n return true;\n case \"loading\":\n case \"init\":\n return false;\n default:\n payload.status satisfies never;\n return false;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SAASA,gBAAgB,QAAQ,cAAc;AAE/C,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,mBAAmB,QAAQ,gBAAgB;AACpD,SACEC,gBAAgB,EAChBC,iBAAiB,QAEZ,wBAAwB;AAC/B,SAASC,WAAW,QAAQ,kBAAkB;AAuJ9C,MAAMC,uBAAuB,GAAG,8BAA8B;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;;AAUA,OAAO,SAASC,YAAYA,CAK1BC,aAAiD,EACjDC,OAAqC,GAAG,CAAC,CAAC,EACb;EAC7B,MAAM;IAAEC;EAAiB,CAAC,GAAGT,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2BAA2B,CAAC;MACnEK,YAAY,EAAEZ,OAAO,EAAEY,YAAY,IAAI,KAAK;MAC5CC,SAAS,EAAEb,OAAO,EAAEc,OAAO,GAAGd,OAAO,CAACa,SAAS,GAAG3C,SAAS;MAC3D4C,OAAO,EAAEd,OAAO,EAAEc,OAAO,IAAI,KAAK;MAClCC,SAAS,EAAER,UAAU,EAAEQ,SAA2C;MAClEC,UAAU,EAAET,UAAU,EAAES,UAAU;MAClCZ;IACF,CAAC;EACH,CAAC,EAAE,CAACJ,OAAO,EAAEI,OAAO,EAAE/C,OAAO,CAAC,CAAC;AACjC;AAEA,SAAS6C,kBAAkBA,CAGzBF,OAAgD,EAAW;EAC3D,IAAIA,OAAO,IAAI,IAAI,IAAI,OAAO,IAAIA,OAAO,EAAE;IACzC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,EAAEiB,MAAM,IAAI,IAAI,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,QAAQjB,OAAO,CAACiB,MAAM;IACpB,KAAK,QAAQ;IACb,KAAK,OAAO;MACV,OAAO,IAAI;IACb,KAAK,SAAS;IACd,KAAK,MAAM;MACT,OAAO,KAAK;IACd;MACEjB,OAAO,CAACiB,MAAM;MACd,OAAO,KAAK;EAChB;AACF","ignoreList":[]}
|
|
@@ -36,11 +36,8 @@ import { OsdkContext } from "./OsdkContext.js";
|
|
|
36
36
|
* const { data, isLoading, error } = useOsdkAggregation(Employee, {
|
|
37
37
|
* where: { department: "Engineering" },
|
|
38
38
|
* aggregate: {
|
|
39
|
-
* groupBy: { department: "exact" },
|
|
40
|
-
* select: {
|
|
41
|
-
* avgSalary: { $avg: "salary" },
|
|
42
|
-
* count: { $count: {} }
|
|
43
|
-
* }
|
|
39
|
+
* $groupBy: { department: "exact" },
|
|
40
|
+
* $select: { "salary:avg": "unordered", $count: "unordered" }
|
|
44
41
|
* }
|
|
45
42
|
* });
|
|
46
43
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAggregation.js","names":["getWireObjectSet","React","extractPayloadError","isPayloadLoading","devToolsMetadata","makeExternalStore","makeExternalStoreAsync","OsdkContext","useOsdkAggregation","type","options","where","withProperties","intersectWith","aggregate","dedupeIntervalMs","enabled","objectSet","undefined","observableClient","useContext","canonOptions","canonicalizeOptions","objectSetKey","JSON","stringify","objectSetRef","useRef","current","subscribe","getSnapShot","useMemo","unsubscribe","hookType","objectType","apiName","currentObjectSet","observer","observeAggregation","dedupeInterval","payload","useSyncExternalStore","refetch","useCallback","invalidateObjectType","data","result","isLoading","error"],"sources":["useOsdkAggregation.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport { getWireObjectSet, type ObjectTypeDefinition } from \"@osdk/client\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport {\n devToolsMetadata,\n makeExternalStore,\n makeExternalStoreAsync,\n} from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\ninterface UseOsdkAggregationBaseOptions<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Standard OSDK Where clause to filter objects before aggregation\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Define derived properties (RDPs) to be computed server-side.\n * The derived properties can be used in the where clause and aggregation groupBy/select.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * Intersect the main query with additional filtered object sets.\n * Each entry creates a separate object set with its own where clause,\n * and the final result is the intersection of all sets.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\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 /**\n * Enable or disable the aggregation.\n *\n * When `false`, the hook does not subscribe or fetch from the server and\n * reports `data: undefined`, `isLoading: false`, and `error: undefined`.\n * `refetch()` is also a no-op while disabled, so it will not invalidate the\n * object type or trigger network requests. Setting it back to `true`\n * re-subscribes and fetches.\n *\n * @default true\n */\n enabled?: boolean;\n}\n\nexport interface UseOsdkAggregationOptions<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> extends UseOsdkAggregationBaseOptions<T, A, RDPs> {}\n\nexport interface UseOsdkAggregationOptionsWithObjectSet<\n T extends ObjectTypeDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> extends UseOsdkAggregationBaseOptions<T, A, RDPs> {\n /**\n * The ObjectSet to aggregate on. Enables aggregation on pivoted, filtered, or composed ObjectSets.\n */\n objectSet: ObjectSet<T>;\n}\n\nexport interface UseOsdkAggregationResult<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n> {\n data: AggregationsResults<T, A> | undefined;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\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 * // Basic aggregation without ObjectSet\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 * // With a pivoted ObjectSet\n * const pivotedSet = useMemo(() => $(Employee).pivotTo(\"primaryOffice\"), []);\n * const { data } = useOsdkAggregation(Office, {\n * objectSet: pivotedSet,\n * aggregate: { $select: { $count: \"unordered\" } }\n * });\n * ```\n */\nexport function useOsdkAggregation<\n Q extends ObjectOrInterfaceDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkAggregationOptions<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A>;\nexport function useOsdkAggregation<\n Q extends ObjectTypeDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkAggregationOptionsWithObjectSet<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A>;\nexport function useOsdkAggregation<\n Q extends ObjectTypeDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options:\n | UseOsdkAggregationOptions<Q, A, RDPs>\n | UseOsdkAggregationOptionsWithObjectSet<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A> {\n const {\n where,\n withProperties,\n intersectWith,\n aggregate,\n dedupeIntervalMs,\n enabled = true,\n } = options;\n const objectSet = \"objectSet\" in options ? options.objectSet : undefined;\n\n const { observableClient } = React.useContext(OsdkContext);\n\n const canonOptions = observableClient.canonicalizeOptions({\n where,\n withProperties,\n aggregate,\n intersectWith,\n });\n\n const objectSetKey = objectSet\n ? JSON.stringify(getWireObjectSet(objectSet as ObjectSet<Q>))\n : undefined;\n\n const objectSetRef = React.useRef(objectSet);\n objectSetRef.current = objectSet;\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveAggregationArgs<Q, A>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useOsdkAggregation\",\n objectType: type.apiName,\n }),\n );\n }\n\n const currentObjectSet = objectSetRef.current;\n if (currentObjectSet) {\n return makeExternalStoreAsync<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n observableClient.observeAggregation(\n {\n type,\n objectSet: currentObjectSet,\n where: canonOptions.where,\n withProperties: canonOptions.withProperties,\n intersectWith: canonOptions.intersectWith,\n aggregate: canonOptions.aggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useOsdkAggregation\",\n objectType: type.apiName,\n where: canonOptions.where,\n aggregate: canonOptions.aggregate,\n }),\n );\n }\n return makeExternalStore<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n observableClient.observeAggregation(\n {\n type,\n where: canonOptions.where,\n withProperties: canonOptions.withProperties,\n intersectWith: canonOptions.intersectWith,\n aggregate: canonOptions.aggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useOsdkAggregation\",\n objectType: type.apiName,\n where: canonOptions.where,\n aggregate: canonOptions.aggregate,\n }),\n );\n }, [\n enabled,\n observableClient,\n type.apiName,\n type.type,\n objectSetKey,\n canonOptions.where,\n canonOptions.withProperties,\n canonOptions.intersectWith,\n canonOptions.aggregate,\n dedupeIntervalMs,\n ]);\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const refetch = React.useCallback(async () => {\n if (!enabled) {\n return;\n }\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName, enabled]);\n\n return React.useMemo(\n () => ({\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: isPayloadLoading(payload, enabled),\n error: extractPayloadError(payload, \"Failed to execute aggregation\"),\n refetch,\n }),\n [payload, enabled, refetch],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SAASA,gBAAgB,QAAmC,cAAc;AAE1E,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,gBAAgB;AACtE,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,sBAAsB,QACjB,wBAAwB;AAC/B,SAASC,WAAW,QAAQ,kBAAkB;;AAiF9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiBA,OAAO,SAASC,kBAAkBA,CAKhCC,IAAO,EACPC,OAEsD,EACtB;EAChC,MAAM;IACJC,KAAK;IACLC,cAAc;IACdC,aAAa;IACbC,SAAS;IACTC,gBAAgB;IAChBC,OAAO,GAAG;EACZ,CAAC,GAAGN,OAAO;EACX,MAAMO,SAAS,GAAG,WAAW,IAAIP,OAAO,GAAGA,OAAO,CAACO,SAAS,GAAGC,SAAS;EAExE,MAAM;IAAEC;EAAiB,CAAC,GAAGlB,KAAK,CAACmB,UAAU,CAACb,WAAW,CAAC;EAE1D,MAAMc,YAAY,GAAGF,gBAAgB,CAACG,mBAAmB,CAAC;IACxDX,KAAK;IACLC,cAAc;IACdE,SAAS;IACTD;EACF,CAAC,CAAC;EAEF,MAAMU,YAAY,GAAGN,SAAS,GAC1BO,IAAI,CAACC,SAAS,CAACzB,gBAAgB,CAACiB,SAAyB,CAAC,CAAC,GAC3DC,SAAS;EAEb,MAAMQ,YAAY,GAAGzB,KAAK,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jectSet","React","extractPayloadError","isPayloadLoading","devToolsMetadata","makeExternalStore","makeExternalStoreAsync","OsdkContext","useOsdkAggregation","type","options","where","withProperties","intersectWith","aggregate","dedupeIntervalMs","enabled","objectSet","undefined","observableClient","useContext","canonOptions","canonicalizeOptions","objectSetKey","JSON","stringify","objectSetRef","useRef","current","subscribe","getSnapShot","useMemo","unsubscribe","hookType","objectType","apiName","currentObjectSet","observer","observeAggregation","dedupeInterval","payload","useSyncExternalStore","refetch","useCallback","invalidateObjectType","data","result","isLoading","error"],"sources":["useOsdkAggregation.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport { getWireObjectSet, type ObjectTypeDefinition } from \"@osdk/client\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport {\n devToolsMetadata,\n makeExternalStore,\n makeExternalStoreAsync,\n} from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\ninterface UseOsdkAggregationBaseOptions<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Standard OSDK Where clause to filter objects before aggregation\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Define derived properties (RDPs) to be computed server-side.\n * The derived properties can be used in the where clause and aggregation groupBy/select.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * Intersect the main query with additional filtered object sets.\n * Each entry creates a separate object set with its own where clause,\n * and the final result is the intersection of all sets.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\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 /**\n * Enable or disable the aggregation.\n *\n * When `false`, the hook does not subscribe or fetch from the server and\n * reports `data: undefined`, `isLoading: false`, and `error: undefined`.\n * `refetch()` is also a no-op while disabled, so it will not invalidate the\n * object type or trigger network requests. Setting it back to `true`\n * re-subscribes and fetches.\n *\n * @default true\n */\n enabled?: boolean;\n}\n\nexport interface UseOsdkAggregationOptions<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> extends UseOsdkAggregationBaseOptions<T, A, RDPs> {}\n\nexport interface UseOsdkAggregationOptionsWithObjectSet<\n T extends ObjectTypeDefinition,\n A extends AggregateOpts<T>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> extends UseOsdkAggregationBaseOptions<T, A, RDPs> {\n /**\n * The ObjectSet to aggregate on. Enables aggregation on pivoted, filtered, or composed ObjectSets.\n */\n objectSet: ObjectSet<T>;\n}\n\nexport interface UseOsdkAggregationResult<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n> {\n data: AggregationsResults<T, A> | undefined;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\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 * // Basic aggregation without ObjectSet\n * const { data, isLoading, error } = useOsdkAggregation(Employee, {\n * where: { department: \"Engineering\" },\n * aggregate: {\n * $groupBy: { department: \"exact\" },\n * $select: { \"salary:avg\": \"unordered\", $count: \"unordered\" }\n * }\n * });\n *\n * // With a pivoted ObjectSet\n * const pivotedSet = useMemo(() => $(Employee).pivotTo(\"primaryOffice\"), []);\n * const { data } = useOsdkAggregation(Office, {\n * objectSet: pivotedSet,\n * aggregate: { $select: { $count: \"unordered\" } }\n * });\n * ```\n */\nexport function useOsdkAggregation<\n Q extends ObjectOrInterfaceDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkAggregationOptions<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A>;\nexport function useOsdkAggregation<\n Q extends ObjectTypeDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkAggregationOptionsWithObjectSet<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A>;\nexport function useOsdkAggregation<\n Q extends ObjectTypeDefinition,\n const A extends AggregateOpts<Q>,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options:\n | UseOsdkAggregationOptions<Q, A, RDPs>\n | UseOsdkAggregationOptionsWithObjectSet<Q, A, RDPs>,\n): UseOsdkAggregationResult<Q, A> {\n const {\n where,\n withProperties,\n intersectWith,\n aggregate,\n dedupeIntervalMs,\n enabled = true,\n } = options;\n const objectSet = \"objectSet\" in options ? options.objectSet : undefined;\n\n const { observableClient } = React.useContext(OsdkContext);\n\n const canonOptions = observableClient.canonicalizeOptions({\n where,\n withProperties,\n aggregate,\n intersectWith,\n });\n\n const objectSetKey = objectSet\n ? JSON.stringify(getWireObjectSet(objectSet as ObjectSet<Q>))\n : undefined;\n\n const objectSetRef = React.useRef(objectSet);\n objectSetRef.current = objectSet;\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveAggregationArgs<Q, A>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useOsdkAggregation\",\n objectType: type.apiName,\n }),\n );\n }\n\n const currentObjectSet = objectSetRef.current;\n if (currentObjectSet) {\n return makeExternalStoreAsync<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n observableClient.observeAggregation(\n {\n type,\n objectSet: currentObjectSet,\n where: canonOptions.where,\n withProperties: canonOptions.withProperties,\n intersectWith: canonOptions.intersectWith,\n aggregate: canonOptions.aggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useOsdkAggregation\",\n objectType: type.apiName,\n where: canonOptions.where,\n aggregate: canonOptions.aggregate,\n }),\n );\n }\n return makeExternalStore<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n observableClient.observeAggregation(\n {\n type,\n where: canonOptions.where,\n withProperties: canonOptions.withProperties,\n intersectWith: canonOptions.intersectWith,\n aggregate: canonOptions.aggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useOsdkAggregation\",\n objectType: type.apiName,\n where: canonOptions.where,\n aggregate: canonOptions.aggregate,\n }),\n );\n }, [\n enabled,\n observableClient,\n type.apiName,\n type.type,\n objectSetKey,\n canonOptions.where,\n canonOptions.withProperties,\n canonOptions.intersectWith,\n canonOptions.aggregate,\n dedupeIntervalMs,\n ]);\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const refetch = React.useCallback(async () => {\n if (!enabled) {\n return;\n }\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName, enabled]);\n\n return React.useMemo(\n () => ({\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: isPayloadLoading(payload, enabled),\n error: extractPayloadError(payload, \"Failed to execute aggregation\"),\n refetch,\n }),\n [payload, enabled, refetch],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SAASA,gBAAgB,QAAmC,cAAc;AAE1E,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,gBAAgB;AACtE,SACEC,gBAAgB,EAChBC,iBAAiB,EACjBC,sBAAsB,QACjB,wBAAwB;AAC/B,SAASC,WAAW,QAAQ,kBAAkB;;AAiF9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiBA,OAAO,SAASC,kBAAkBA,CAKhCC,IAAO,EACPC,OAEsD,EACtB;EAChC,MAAM;IACJC,KAAK;IACLC,cAAc;IACdC,aAAa;IACbC,SAAS;IACTC,gBAAgB;IAChBC,OAAO,GAAG;EACZ,CAAC,GAAGN,OAAO;EACX,MAAMO,SAAS,GAAG,WAAW,IAAIP,OAAO,GAAGA,OAAO,CAACO,SAAS,GAAGC,SAAS;EAExE,MAAM;IAAEC;EAAiB,CAAC,GAAGlB,KAAK,CAACmB,UAAU,CAACb,WAAW,CAAC;EAE1D,MAAMc,YAAY,GAAGF,gBAAgB,CAACG,mBAAmB,CAAC;IACxDX,KAAK;IACLC,cAAc;IACdE,SAAS;IACTD;EACF,CAAC,CAAC;EAEF,MAAMU,YAAY,GAAGN,SAAS,GAC1BO,IAAI,CAACC,SAAS,CAACzB,gBAAgB,CAACiB,SAAyB,CAAC,CAAC,GAC3DC,SAAS;EAEb,MAAMQ,YAAY,GAAGzB,KAAK,CAAC0B,MAAM,CAACV,SAAS,CAAC;EAC5CS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,EAAExB,gBAAgB,IAAI;IACtC,CAAC,EACDsB,QACF,CAAC,EACHjC,gBAAgB,CAAC;MACf6B,QAAQ,EAAE,oBAAoB;MAC9BC,UAAU,EAAEzB,IAAI,CAAC0B,OAAO;MACxBxB,KAAK,EAAEU,YAAY,CAACV,KAAK;MACzBG,SAAS,EAAEO,YAAY,CAACP;IAC1B,CAAC,CACH,CAAC;EACH,CAAC,EAAE,CACDE,OAAO,EACPG,gBAAgB,EAChBV,IAAI,CAAC0B,OAAO,EACZ1B,IAAI,CAACA,IAAI,EACTc,YAAY,EACZF,YAAY,CAACV,KAAK,EAClBU,YAAY,CAACT,cAAc,EAC3BS,YAAY,CAACR,aAAa,EAC1BQ,YAAY,CAACP,SAAS,EACtBC,gBAAgB,CACjB,CAAC;EAEF,MAAMyB,OAAO,GAAGvC,KAAK,CAACwC,oBAAoB,CAACZ,SAAS,EAAEC,WAAW,CAAC;EAElE,MAAMY,OAAO,GAAGzC,KAAK,CAAC0C,WAAW,CAAC,YAAY;IAC5C,IAAI,CAAC3B,OAAO,EAAE;MACZ;IACF;IACA,MAAMG,gBAAgB,CAACyB,oBAAoB,CAACnC,IAAI,CAAC0B,OAAO,CAAC;EAC3D,CAAC,EAAE,CAAChB,gBAAgB,EAAEV,IAAI,CAAC0B,OAAO,EAAEnB,OAAO,CAAC,CAAC;EAE7C,OAAOf,KAAK,CAAC8B,OAAO,CAClB,OAAO;IACLc,IAAI,EAAEL,OAAO,EAAEM,MAA+C;IAC9DC,SAAS,EAAE5C,gBAAgB,CAACqC,OAAO,EAAExB,OAAO,CAAC;IAC7CgC,KAAK,EAAE9C,mBAAmB,CAACsC,OAAO,EAAE,+BAA+B,CAAC;IACpEE;EACF,CAAC,CAAC,EACF,CAACF,OAAO,EAAExB,OAAO,EAAE0B,OAAO,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkObjects.js","names":["React","extractPayloadError","isPayloadLoading","devToolsMetadata","makeExternalStore","OsdkContext","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","$select","$loadPropertySecurityMetadata","$includeAllBaseObjectProperties","resolveToObjectType","canonOptions","canonicalizeOptions","stableRids","useMemo","JSON","stringify","subscribe","getSnapShot","unsubscribe","hookType","objectType","apiName","observer","observeList","dedupeInterval","select","listPayload","useSyncExternalStore","refetch","useCallback","invalidateObjectType","fetchMore","hasMore","undefined","error","data","resolvedList","isLoading","isOptimistic","totalCount","objectSet"],"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 ObjectSet,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport { devToolsMetadata, makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\n/**\n * Restricts `resolveToObjectType` to interface queries only.\n * Object-type queries cannot pass this option.\n */\nexport type ResolveToObjectTypeOption<T extends ObjectOrInterfaceDefinition> =\n T extends { type: \"interface\" }\n ? { resolveToObjectType?: boolean }\n : { resolveToObjectType?: never };\n\nexport type UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> = UseOsdkObjectsBaseOptions<T, RDPs> & ResolveToObjectTypeOption<T>;\n\ninterface UseOsdkObjectsBaseOptions<\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 * ```tsx\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] });\n * ```\n *\n * @example\n * ```tsx\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 */\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 * Cannot be combined with `streamUpdates`. The server does not support\n * websocket subscriptions for link-traversal queries.\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 /**\n * Enable streaming updates via websocket subscription.\n *\n * Cannot be combined with `pivotTo`. The server does not support\n * websocket subscriptions for link-traversal queries.\n */\n streamUpdates?: boolean;\n\n /**\n * Restrict which properties are returned for each object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n *\n * @example\n * ```tsx\n * // Only fetch name and status properties\n * useOsdkObjects(Employee, { $select: [\"name\", \"status\"] });\n * ```\n */\n $select?: readonly PropertyKeys<T>[];\n\n /**\n * When true, loads per-property security metadata (marking requirements)\n * alongside each object. The returned objects will have `$propertySecurities`\n * populated with conjunctive/disjunctive marking requirements per property.\n */\n $loadPropertySecurityMetadata?: boolean;\n\n /**\n * When true, includes all properties of the underlying concrete object type\n * for interface queries. Has no effect for non-interface queries.\n */\n $includeAllBaseObjectProperties?: 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 hasMore: boolean;\n\n objectSet: ObjectSet<T, RDPs> | undefined;\n\n refetch: () => Promise<void>;\n}\n\n// pivotTo overloads: streamUpdates is forbidden (the server does not support\n// websocket subscriptions for link-traversal queries).\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, {}> & {\n pivotTo: L;\n rids: readonly string[];\n streamUpdates?: never;\n },\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, {}> & {\n pivotTo: L;\n streamUpdates?: never;\n },\n): UseOsdkListResult<LinkedType<Q, L>, {}>;\n\n// Non-pivotTo overloads: pivotTo is forbidden to prevent fallthrough from the\n// pivotTo overloads above (which would give the wrong return type).\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, RDPs> & {\n rids: readonly string[];\n pivotTo?: never;\n },\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> & { pivotTo?: never },\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 const { observableClient } = React.useContext(OsdkContext);\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 $select,\n $loadPropertySecurityMetadata,\n $includeAllBaseObjectProperties,\n resolveToObjectType,\n } = options ?? {};\n\n const canonOptions = observableClient.canonicalizeOptions({\n where,\n withProperties,\n orderBy,\n intersectWith,\n $select,\n });\n\n const stableRids = React.useMemo(() => rids, [JSON.stringify(rids)]);\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectsCallbackArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useOsdkObjects\",\n objectType: type.apiName,\n }),\n );\n }\n\n return makeExternalStore<ObserveObjectsCallbackArgs<Q, RDPs>>(\n (observer) =>\n observableClient.observeList<Q, RDPs>(\n {\n type,\n rids: stableRids,\n where: canonOptions.where,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: canonOptions.orderBy,\n streamUpdates,\n withProperties: canonOptions.withProperties,\n autoFetchMore,\n $includeAllBaseObjectProperties,\n ...(canonOptions.intersectWith\n ? { intersectWith: canonOptions.intersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n ...(canonOptions.$select ? { select: canonOptions.$select } : {}),\n ...($loadPropertySecurityMetadata\n ? { $loadPropertySecurityMetadata }\n : {}),\n ...(resolveToObjectType ? { resolveToObjectType: true } : {}),\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useOsdkObjects\",\n objectType: type.apiName,\n where: canonOptions.where,\n orderBy: canonOptions.orderBy,\n pageSize,\n }),\n );\n }, [\n enabled,\n observableClient,\n type.apiName,\n type.type,\n stableRids,\n canonOptions.where,\n dedupeIntervalMs,\n pageSize,\n canonOptions.orderBy,\n streamUpdates,\n canonOptions.withProperties,\n autoFetchMore,\n canonOptions.intersectWith,\n pivotTo,\n canonOptions.$select,\n $loadPropertySecurityMetadata,\n $includeAllBaseObjectProperties,\n !!resolveToObjectType,\n ]);\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const refetch = React.useCallback(async () => {\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName]);\n\n return React.useMemo<UseOsdkListResult<Q, RDPs>>(\n () => ({\n fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,\n error: extractPayloadError(listPayload, \"Failed to load objects\"),\n data: listPayload?.resolvedList,\n isLoading: isPayloadLoading(listPayload, enabled),\n isOptimistic: listPayload?.isOptimistic ?? false,\n totalCount: listPayload?.totalCount,\n hasMore: listPayload?.hasMore ?? false,\n objectSet: listPayload?.objectSet,\n refetch,\n }),\n [listPayload, enabled, refetch],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,gBAAgB;AACtE,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,wBAAwB;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;;AAE9C;AACA;AACA;AACA;;AAqMA;AACA;;AAwBA;AACA;;AAoBA,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAKqB;EAC7D,MAAM;IAAEC;EAAiB,CAAC,GAAGT,KAAK,CAACU,UAAU,CAACL,WAAW,CAAC;EAE1D,MAAM;IACJM,QAAQ;IACRC,gBAAgB;IAChBC,cAAc;IACdC,OAAO,GAAG,IAAI;IACdC,IAAI;IACJC,KAAK;IACLC,OAAO;IACPC,aAAa;IACbC,aAAa;IACbC,aAAa;IACbC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,CAACK,SAAS,GAAGE,SAAS;IACnEC,KAAK,EAAEjD,mBAAmB,CAACyC,WAAW,EAAE,wBAAwB,CAAC;IACjES,IAAI,EAAET,WAAW,EAAEU,YAAY;IAC/BC,SAAS,EAAEnD,gBAAgB,CAACwC,WAAW,EAAE5B,OAAO,CAAC;IACjDwC,YAAY,EAAEZ,WAAW,EAAEY,YAAY,IAAI,KAAK;IAChDC,UAAU,EAAEb,WAAW,EAAEa,UAAU;IACnCP,OAAO,EAAEN,WAAW,EAAEM,OAAO,IAAI,KAAK;IACtCQ,SAAS,EAAEd,WAAW,EAAEc,SAAS;IACjCZ;EACF,CAAC,CAAC,EACF,CAACF,WAAW,EAAE5B,OAAO,EAAE8B,OAAO,CAChC,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useOsdkObjects.js","names":["React","extractPayloadError","isPayloadLoading","devToolsMetadata","makeExternalStore","OsdkContext","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","$select","$loadPropertySecurityMetadata","$includeAllBaseObjectProperties","resolveToObjectType","canonOptions","canonicalizeOptions","stableRids","useMemo","JSON","stringify","subscribe","getSnapShot","unsubscribe","hookType","objectType","apiName","observer","observeList","dedupeInterval","select","listPayload","useSyncExternalStore","refetch","useCallback","invalidateObjectType","fetchMore","hasMore","undefined","error","data","resolvedList","isLoading","isOptimistic","totalCount","objectSet"],"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 ObjectSet,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/observable\";\nimport React from \"react\";\n\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport { devToolsMetadata, makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext } from \"./OsdkContext.js\";\n\n/**\n * Restricts `resolveToObjectType` to interface queries only.\n * Object-type queries cannot pass this option.\n */\nexport type ResolveToObjectTypeOption<T extends ObjectOrInterfaceDefinition> =\n T extends { type: \"interface\" }\n ? { resolveToObjectType?: boolean }\n : { resolveToObjectType?: never };\n\nexport type UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> = UseOsdkObjectsBaseOptions<T, RDPs> & ResolveToObjectTypeOption<T>;\n\ninterface UseOsdkObjectsBaseOptions<\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 * ```tsx\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] });\n * ```\n *\n * @example\n * ```tsx\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 */\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 does not run and the hook returns no data, even\n * if the cache already holds a result.\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 * Cannot be combined with `streamUpdates`. The server does not support\n * websocket subscriptions for link-traversal queries.\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 /**\n * Enable streaming updates via websocket subscription.\n *\n * Cannot be combined with `pivotTo`. The server does not support\n * websocket subscriptions for link-traversal queries.\n */\n streamUpdates?: boolean;\n\n /**\n * Restrict which properties are returned for each object.\n * When provided, only the specified properties will be fetched,\n * reducing payload sizes for list views.\n *\n * @example\n * ```tsx\n * // Only fetch name and status properties\n * useOsdkObjects(Employee, { $select: [\"name\", \"status\"] });\n * ```\n */\n $select?: readonly PropertyKeys<T>[];\n\n /**\n * When true, loads per-property security metadata (marking requirements)\n * alongside each object. The returned objects will have `$propertySecurities`\n * populated with conjunctive/disjunctive marking requirements per property.\n */\n $loadPropertySecurityMetadata?: boolean;\n\n /**\n * When true, includes all properties of the underlying concrete object type\n * for interface queries. Has no effect for non-interface queries.\n */\n $includeAllBaseObjectProperties?: 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 hasMore: boolean;\n\n objectSet: ObjectSet<T, RDPs> | undefined;\n\n refetch: () => Promise<void>;\n}\n\n// pivotTo overloads: streamUpdates is forbidden (the server does not support\n// websocket subscriptions for link-traversal queries).\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, {}> & {\n pivotTo: L;\n rids: readonly string[];\n streamUpdates?: never;\n },\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, {}> & {\n pivotTo: L;\n streamUpdates?: never;\n },\n): UseOsdkListResult<LinkedType<Q, L>, {}>;\n\n// Non-pivotTo overloads: pivotTo is forbidden to prevent fallthrough from the\n// pivotTo overloads above (which would give the wrong return type).\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, RDPs> & {\n rids: readonly string[];\n pivotTo?: never;\n },\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> & { pivotTo?: never },\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 const { observableClient } = React.useContext(OsdkContext);\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 $select,\n $loadPropertySecurityMetadata,\n $includeAllBaseObjectProperties,\n resolveToObjectType,\n } = options ?? {};\n\n const canonOptions = observableClient.canonicalizeOptions({\n where,\n withProperties,\n orderBy,\n intersectWith,\n $select,\n });\n\n const stableRids = React.useMemo(() => rids, [JSON.stringify(rids)]);\n\n const { subscribe, getSnapShot } = React.useMemo(() => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectsCallbackArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n devToolsMetadata({\n hookType: \"useOsdkObjects\",\n objectType: type.apiName,\n }),\n );\n }\n\n return makeExternalStore<ObserveObjectsCallbackArgs<Q, RDPs>>(\n (observer) =>\n observableClient.observeList<Q, RDPs>(\n {\n type,\n rids: stableRids,\n where: canonOptions.where,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: canonOptions.orderBy,\n streamUpdates,\n withProperties: canonOptions.withProperties,\n autoFetchMore,\n $includeAllBaseObjectProperties,\n ...(canonOptions.intersectWith\n ? { intersectWith: canonOptions.intersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n ...(canonOptions.$select ? { select: canonOptions.$select } : {}),\n ...($loadPropertySecurityMetadata\n ? { $loadPropertySecurityMetadata }\n : {}),\n ...(resolveToObjectType ? { resolveToObjectType: true } : {}),\n },\n observer,\n ),\n devToolsMetadata({\n hookType: \"useOsdkObjects\",\n objectType: type.apiName,\n where: canonOptions.where,\n orderBy: canonOptions.orderBy,\n pageSize,\n }),\n );\n }, [\n enabled,\n observableClient,\n type.apiName,\n type.type,\n stableRids,\n canonOptions.where,\n dedupeIntervalMs,\n pageSize,\n canonOptions.orderBy,\n streamUpdates,\n canonOptions.withProperties,\n autoFetchMore,\n canonOptions.intersectWith,\n pivotTo,\n canonOptions.$select,\n $loadPropertySecurityMetadata,\n $includeAllBaseObjectProperties,\n !!resolveToObjectType,\n ]);\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const refetch = React.useCallback(async () => {\n await observableClient.invalidateObjectType(type.apiName);\n }, [observableClient, type.apiName]);\n\n return React.useMemo<UseOsdkListResult<Q, RDPs>>(\n () => ({\n fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,\n error: extractPayloadError(listPayload, \"Failed to load objects\"),\n data: listPayload?.resolvedList,\n isLoading: isPayloadLoading(listPayload, enabled),\n isOptimistic: listPayload?.isOptimistic ?? false,\n totalCount: listPayload?.totalCount,\n hasMore: listPayload?.hasMore ?? false,\n objectSet: listPayload?.objectSet,\n refetch,\n }),\n [listPayload, enabled, refetch],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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BM,aAAa,EACbO,YAAY,CAACN,aAAa,EAC1BC,OAAO,EACPK,YAAY,CAACJ,OAAO,EACpBC,6BAA6B,EAC7BC,+BAA+B,EAC/B,CAAC,CAACC,mBAAmB,CACtB,CAAC;EAEF,MAAMiB,WAAW,GAAG1C,KAAK,CAAC2C,oBAAoB,CAACX,SAAS,EAAEC,WAAW,CAAC;EAEtE,MAAMW,OAAO,GAAG5C,KAAK,CAAC6C,WAAW,CAAC,YAAY;IAC5C,MAAMpC,gBAAgB,CAACqC,oBAAoB,CAACvC,IAAI,CAAC8B,OAAO,CAAC;EAC3D,CAAC,EAAE,CAAC5B,gBAAgB,EAAEF,IAAI,CAAC8B,OAAO,CAAC,CAAC;EAEpC,OAAOrC,KAAK,CAAC6B,OAAO,CAClB,OAAO;IACLkB,SAAS,EAAEL,WAAW,EAAEM,OAAO,GAAGN,WAAW,CAACK,SAAS,GAAGE,SAAS;IACnEC,KAAK,EAAEjD,mBAAmB,CAACyC,WAAW,EAAE,wBAAwB,CAAC;IACjES,IAAI,EAAET,WAAW,EAAEU,YAAY;IAC/BC,SAAS,EAAEnD,gBAAgB,CAACwC,WAAW,EAAE5B,OAAO,CAAC;IACjDwC,YAAY,EAAEZ,WAAW,EAAEY,YAAY,IAAI,KAAK;IAChDC,UAAU,EAAEb,WAAW,EAAEa,UAAU;IACnCP,OAAO,EAAEN,WAAW,EAAEM,OAAO,IAAI,KAAK;IACtCQ,SAAS,EAAEd,WAAW,EAAEc,SAAS;IACjCZ;EACF,CAAC,CAAC,EACF,CAACF,WAAW,EAAE5B,OAAO,EAAE8B,OAAO,CAChC,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserAgent.js","names":["REACT_USER_AGENT"],"sources":["UserAgent.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const REACT_USER_AGENT: string = `osdk-react/${process.env.PACKAGE_VERSION}`;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,gBAAwB,GAAG,
|
|
1
|
+
{"version":3,"file":"UserAgent.js","names":["REACT_USER_AGENT"],"sources":["UserAgent.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const REACT_USER_AGENT: string = `osdk-react/${process.env.PACKAGE_VERSION}`;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,gBAAwB,GAAG,sEAA2C","ignoreList":[]}
|
|
@@ -29,7 +29,7 @@ function useStableObjectSet(objectSet) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// src/util/UserAgent.ts
|
|
32
|
-
var REACT_USER_AGENT = `osdk-react/${"2.
|
|
32
|
+
var REACT_USER_AGENT = `osdk-react/${"2.95.0-main-a5bdff2e9db1a01e5858042ee5232cb13c13368a"}`;
|
|
33
33
|
function useDevToolsClient(baseClient, enabled) {
|
|
34
34
|
const stateRef = React5.useRef(null);
|
|
35
35
|
const prev = stateRef.current;
|
|
@@ -927,5 +927,5 @@ exports.useOsdkObject = useOsdkObject;
|
|
|
927
927
|
exports.useOsdkObjects = useOsdkObjects;
|
|
928
928
|
exports.useRegisterUserAgent = useRegisterUserAgent;
|
|
929
929
|
exports.useStableObjectSet = useStableObjectSet;
|
|
930
|
-
//# sourceMappingURL=chunk-
|
|
931
|
-
//# sourceMappingURL=chunk-
|
|
930
|
+
//# sourceMappingURL=chunk-YG7PT4LT.cjs.map
|
|
931
|
+
//# sourceMappingURL=chunk-YG7PT4LT.cjs.map
|