@osdk/react 0.10.0 → 0.10.1-main-20260406220320
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/hookUtils.js +32 -0
- package/build/browser/new/hookUtils.js.map +1 -0
- package/build/browser/new/useLinks.js +13 -10
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useObjectSet.js +45 -26
- package/build/browser/new/useObjectSet.js.map +1 -1
- package/build/browser/new/useOsdkAggregation.js +32 -38
- package/build/browser/new/useOsdkAggregation.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +31 -32
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/cjs/public/experimental.cjs +129 -100
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +9 -3
- package/build/esm/new/hookUtils.js +32 -0
- package/build/esm/new/hookUtils.js.map +1 -0
- package/build/esm/new/useLinks.js +13 -10
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useObjectSet.js +45 -26
- package/build/esm/new/useObjectSet.js.map +1 -1
- package/build/esm/new/useOsdkAggregation.js +32 -38
- package/build/esm/new/useOsdkAggregation.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +31 -32
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/types/new/hookUtils.d.ts +7 -0
- package/build/types/new/hookUtils.d.ts.map +1 -0
- package/build/types/new/useLinks.d.ts.map +1 -1
- package/build/types/new/useObjectSet.d.ts +5 -2
- package/build/types/new/useObjectSet.d.ts.map +1 -1
- package/build/types/new/useOsdkAggregation.d.ts +1 -1
- package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +4 -1
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectSet.js","names":["computeObjectSetCacheKey","React","makeExternalStore","OsdkContext2","OBJECT_TYPE_PLACEHOLDER","useObjectSet","baseObjectSet","options","observableClient","useContext","enabled","streamUpdates","otherOptions","objectTypeKey","$objectSetInternals","def","apiName","previousObjectTypeRef","useRef","previousCompletedPayloadRef","objectTypeChanged","current","undefined","stableKey","where","withProperties","union","intersect","subtract","pivotTo","pageSize","orderBy","select","$select","subscribe","getSnapShot","useMemo","unsubscribe","process","env","NODE_ENV","initialValue","observer","subscription","observeObjectSet","dedupeInterval","dedupeIntervalMs","autoFetchMore","payload","useSyncExternalStore","isPayloadCompleted","lastLoaded","data","resolvedList","isLoading","error","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\";\n\nimport {\n computeObjectSetCacheKey,\n type ObserveObjectSetArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore, type Snapshot } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseObjectSetOptions<\n Q extends 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 pivotTo?: LinkNames<Q>;\n\n /**\n * The preferred page size for the list\n */\n pageSize?: number;\n\n /**\n * Sort order for the results\n */\n orderBy?: {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Minimum time between fetch requests in milliseconds (defaults to 2000ms)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Automatically fetch additional pages on initial load.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the object set will automatically update when matching objects are\n * added, updated, or removed.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * 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 * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends 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 /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The final ObjectSet after all transformations\n */\n objectSet: ObjectSet<Q, RDPs>;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\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 */\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>,\n options: UseObjectSetOptions<Q, RDPs> = {},\n): UseObjectSetResult<Q, RDPs> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n const { enabled = true, streamUpdates, ...otherOptions } = options;\n\n // Track object type to detect when we switch to a different object type\n const objectTypeKey = enabled\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\n const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;\n if (objectTypeChanged) {\n previousObjectTypeRef.current = objectTypeKey;\n previousCompletedPayloadRef.current = undefined;\n }\n\n // Compute a stable cache key for the ObjectSet and options\n // dedupeIntervalMs and enabled are excluded as they don't affect the data\n const stableKey = computeObjectSetCacheKey(baseObjectSet, {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n select: otherOptions.$select,\n });\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey} [DISABLED]`\n : void 0,\n );\n }\n\n const initialValue = objectTypeChanged\n ? undefined\n : previousCompletedPayloadRef.current;\n\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n (observer) => {\n const subscription = observableClient.observeObjectSet(\n baseObjectSet as ObjectSet<Q>,\n {\n where: otherOptions.where,\n withProperties: otherOptions.withProperties,\n union: otherOptions.union,\n intersect: otherOptions.intersect,\n subtract: otherOptions.subtract,\n pivotTo: otherOptions.pivotTo,\n pageSize: otherOptions.pageSize,\n orderBy: otherOptions.orderBy,\n dedupeInterval: otherOptions.dedupeIntervalMs ?? 2_000,\n autoFetchMore: otherOptions.autoFetchMore,\n streamUpdates,\n select: otherOptions.$select,\n },\n observer,\n );\n return subscription;\n },\n process.env.NODE_ENV !== \"production\"\n ? `objectSet ${stableKey}`\n : void 0,\n initialValue,\n );\n },\n [enabled, observableClient, stableKey, streamUpdates, objectTypeChanged],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n if (payload && isPayloadCompleted(payload)) {\n previousCompletedPayloadRef.current = payload;\n }\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: !isPayloadCompleted(payload),\n error: lastLoaded && \"error\" in lastLoaded ? lastLoaded.error : undefined,\n fetchMore: payload?.hasMore ? payload.fetchMore : undefined,\n objectSet: payload?.objectSet as ObjectSet<Q, RDPs> || baseObjectSet,\n totalCount: lastLoaded?.totalCount,\n };\n }, [payload, baseObjectSet]);\n}\n\nfunction isPayloadCompleted<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n>(\n payload: Snapshot<ObserveObjectSetArgs<Q, RDPs>>,\n): 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;;AAaA,SACEA,wBAAwB,QAEnB,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAuB,wBAAwB;AACzE,SAASC,YAAY,QAAQ,mBAAmB;AA+IhD,MAAMC,uBAAuB,GAAG,8BAA8B;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAK1BC,aAAqC,EACrCC,OAAqC,GAAG,CAAC,CAAC,EACb;EAC7B,MAAM;IAAEC;EAAiB,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACN,YAAY,CAAC;EAE3D,MAAM;IAAEO,OAAO,GAAG,IAAI;IAAEC,aAAa;IAAE,GAAGC;EAAa,CAAC,GAAGL,OAAO;;EAElE;EACA,MAAMM,aAAa,GAAGH,OAAO,GACzBJ,aAAa,CAACQ,mBAAmB,CAACC,GAAG,CAACC,OAAO,GAC7CZ,uBAAuB;EAE3B,MAAMa,qBAAqB,GAAGhB,KAAK,CAACiB,MAAM,CAASL,aAAa,CAAC;EACjE,MAAMM,2BAA2B,GAA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AO,EAAES,OAAO,GAAGT,OAAO,CAACQ,SAAS,GAAGlC,SAAS;MAC3DoC,SAAS,EAAEV,OAAO,EAAEU,SAAS,IAA0BpD,aAAa;MACpEqD,UAAU,EAAER,UAAU,EAAEQ;IAC1B,CAAC;EACH,CAAC,EAAE,CAACX,OAAO,EAAE1C,aAAa,CAAC,CAAC;AAC9B;AAEA,SAAS4C,kBAAkBA,CAIzBF,OAAgD,EACvC;EACT,IAAIA,OAAO,IAAI,IAAI,IAAI,OAAO,IAAIA,OAAO,EAAE;IACzC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,EAAEY,MAAM,IAAI,IAAI,EAAE;IAC3B,OAAO,KAAK;EACd;EAEA,QAAQZ,OAAO,CAACY,MAAM;IACpB,KAAK,QAAQ;IACb,KAAK,OAAO;MACV,OAAO,IAAI;IACb,KAAK,SAAS;IACd,KAAK,MAAM;MACT,OAAO,KAAK;IACd;MACEZ,OAAO,CAACY,MAAM;MACd,OAAO,KAAK;EAChB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useObjectSet.js","names":["getWireObjectSet","React","extractPayloadError","makeExternalStore","OsdkContext2","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","process","env","NODE_ENV","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\";\n\nimport {\n getWireObjectSet,\n type ObserveObjectSetArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { extractPayloadError } from \"./hookUtils.js\";\nimport { makeExternalStore, type Snapshot } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.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 pivotTo?: LinkNames<Q>;\n\n /**\n * The preferred page size for the list\n */\n pageSize?: number;\n\n /**\n * Sort order for the results\n */\n orderBy?: {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Minimum time between fetch requests in milliseconds (defaults to 2000ms)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Automatically fetch additional pages on initial load.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the object set will automatically update when matching objects are\n * added, updated, or removed.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * 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 * // Dependent query - wait for filter selection\n * const { data: filteredObjects } = useObjectSet(MyObject.all(), {\n * where: { status: selectedStatus },\n * enabled: !!selectedStatus\n * });\n */\n enabled?: boolean;\n}\n\nexport interface UseObjectSetResult<\n Q extends 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\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\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 */\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(OsdkContext2);\n\n const { enabled: enabledOption = true, streamUpdates, ...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 = 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\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 () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectSetArgs<Q, RDPs>>(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `objectSet [DISABLED]`\n : void 0,\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 process.env.NODE_ENV !== \"production\"\n ? `objectSet ${objectTypeKey}`\n : void 0,\n initialValue,\n );\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\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\n ? !isPayloadCompleted(payload)\n : 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>(\n payload: Snapshot<ObserveObjectSetArgs<Q, RDPs>>,\n): 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;;AAaA,SACEA,gBAAgB,QAEX,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,QAAQ,gBAAgB;AACpD,SAASC,iBAAiB,QAAuB,wBAAwB;AACzE,SAASC,YAAY,QAAQ,mBAAmB;AAqJhD,MAAMC,uBAAuB,GAAG,8BAA8B;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAK1BC,aAAiD,EACjDC,OAAqC,GAAG,CAAC,CAAC,EACb;EAC7B,MAAM;IAAEC;EAAiB,CAAC,GAAGR,KAAK,CAACS,UAAU,CAACN,YAAY,CAAC;EAE3D,MAAM;IAA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IAAI,KAAK;MAC5CC,SAAS,EAAEb,OAAO,EAAEc,OAAO,GAAGd,OAAO,CAACa,SAAS,GAAG5C,SAAS;MAC3D6C,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,EAAEhD,OAAO,CAAC,CAAC;AACjC;AAEA,SAAS8C,kBAAkBA,CAIzBF,OAAgD,EACvC;EACT,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":[]}
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { getWireObjectSet } from "@osdk/client/unstable-do-not-use";
|
|
18
18
|
import React from "react";
|
|
19
|
+
import { extractPayloadError, isPayloadLoading } from "./hookUtils.js";
|
|
19
20
|
import { makeExternalStore, makeExternalStoreAsync } from "./makeExternalStore.js";
|
|
20
21
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
21
|
-
const EMPTY_WHERE = {};
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* React hook for performing aggregations on OSDK object sets.
|
|
@@ -55,7 +55,7 @@ const EMPTY_WHERE = {};
|
|
|
55
55
|
|
|
56
56
|
export function useOsdkAggregation(type, options) {
|
|
57
57
|
const {
|
|
58
|
-
where
|
|
58
|
+
where,
|
|
59
59
|
withProperties,
|
|
60
60
|
intersectWith,
|
|
61
61
|
aggregate,
|
|
@@ -65,57 +65,51 @@ export function useOsdkAggregation(type, options) {
|
|
|
65
65
|
const {
|
|
66
66
|
observableClient
|
|
67
67
|
} = React.useContext(OsdkContext2);
|
|
68
|
-
const
|
|
69
|
-
|
|
68
|
+
const canonOptions = observableClient.canonicalizeOptions({
|
|
69
|
+
where,
|
|
70
|
+
withProperties,
|
|
71
|
+
aggregate,
|
|
72
|
+
intersectWith
|
|
73
|
+
});
|
|
74
|
+
const objectSetKey = objectSet ? JSON.stringify(getWireObjectSet(objectSet)) : undefined;
|
|
70
75
|
const objectSetRef = React.useRef(objectSet);
|
|
71
76
|
objectSetRef.current = objectSet;
|
|
72
|
-
const objectSetKeyString = objectSet ? computeObjectSetCacheKey(objectSet) : undefined;
|
|
73
|
-
const stableWithProperties = React.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
74
|
-
const stableAggregate = React.useMemo(() => aggregate, [JSON.stringify(aggregate)]);
|
|
75
|
-
const stableIntersectWith = React.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
76
77
|
const {
|
|
77
78
|
subscribe,
|
|
78
79
|
getSnapShot
|
|
79
80
|
} = React.useMemo(() => {
|
|
80
|
-
|
|
81
|
+
const currentObjectSet = objectSetRef.current;
|
|
82
|
+
if (currentObjectSet) {
|
|
81
83
|
return makeExternalStoreAsync(observer => observableClient.observeAggregation({
|
|
82
|
-
type
|
|
83
|
-
objectSet:
|
|
84
|
-
where:
|
|
85
|
-
withProperties:
|
|
86
|
-
intersectWith:
|
|
87
|
-
aggregate:
|
|
84
|
+
type,
|
|
85
|
+
objectSet: currentObjectSet,
|
|
86
|
+
where: canonOptions.where,
|
|
87
|
+
withProperties: canonOptions.withProperties,
|
|
88
|
+
intersectWith: canonOptions.intersectWith,
|
|
89
|
+
aggregate: canonOptions.aggregate,
|
|
88
90
|
dedupeInterval: dedupeIntervalMs ?? 2_000
|
|
89
|
-
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${
|
|
91
|
+
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(canonOptions.where)}` : void 0);
|
|
90
92
|
}
|
|
91
93
|
return makeExternalStore(observer =>
|
|
92
94
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
93
95
|
observableClient.observeAggregation({
|
|
94
|
-
type
|
|
95
|
-
where:
|
|
96
|
-
withProperties:
|
|
97
|
-
intersectWith:
|
|
98
|
-
aggregate:
|
|
96
|
+
type,
|
|
97
|
+
where: canonOptions.where,
|
|
98
|
+
withProperties: canonOptions.withProperties,
|
|
99
|
+
intersectWith: canonOptions.intersectWith,
|
|
100
|
+
aggregate: canonOptions.aggregate,
|
|
99
101
|
dedupeInterval: dedupeIntervalMs ?? 2_000
|
|
100
|
-
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(
|
|
101
|
-
}, [observableClient, type.apiName, type.type,
|
|
102
|
+
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(canonOptions.where)}` : void 0);
|
|
103
|
+
}, [observableClient, type.apiName, type.type, objectSetKey, canonOptions.where, canonOptions.withProperties, canonOptions.intersectWith, canonOptions.aggregate, dedupeIntervalMs]);
|
|
102
104
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
103
105
|
const refetch = React.useCallback(async () => {
|
|
104
106
|
await observableClient.invalidateObjectType(type.apiName);
|
|
105
107
|
}, [observableClient, type.apiName]);
|
|
106
|
-
return React.useMemo(() => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
data: payload?.result,
|
|
115
|
-
isLoading: payload?.status === "loading" || payload?.status === "init" || !payload,
|
|
116
|
-
error,
|
|
117
|
-
refetch
|
|
118
|
-
};
|
|
119
|
-
}, [payload, refetch]);
|
|
108
|
+
return React.useMemo(() => ({
|
|
109
|
+
data: payload?.result,
|
|
110
|
+
isLoading: isPayloadLoading(payload, true),
|
|
111
|
+
error: extractPayloadError(payload, "Failed to execute aggregation"),
|
|
112
|
+
refetch
|
|
113
|
+
}), [payload, refetch]);
|
|
120
114
|
}
|
|
121
115
|
//# sourceMappingURL=useOsdkAggregation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAggregation.js","names":["computeObjectSetCacheKey","React","makeExternalStore","makeExternalStoreAsync","OsdkContext2","EMPTY_WHERE","useOsdkAggregation","type","options","where","withProperties","intersectWith","aggregate","dedupeIntervalMs","objectSet","undefined","observableClient","useContext","canonWhere","canonicalizeWhereClause","stableCanonWhere","useMemo","JSON","stringify","objectSetRef","useRef","current","objectSetKeyString","stableWithProperties","stableAggregate","stableIntersectWith","subscribe","getSnapShot","observer","observeAggregation","dedupeInterval","process","env","NODE_ENV","apiName","payload","useSyncExternalStore","refetch","useCallback","invalidateObjectType","error","status","Error","data","result","isLoading"],"sources":["useOsdkAggregation.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregateOpts,\n AggregationsResults,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObjectTypeDefinition } from \"@osdk/client\";\nimport type { ObserveAggregationArgs } from \"@osdk/client/unstable-do-not-use\";\nimport { computeObjectSetCacheKey } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport {\n makeExternalStore,\n makeExternalStoreAsync,\n} from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.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\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\nconst EMPTY_WHERE = {};\n\nexport interface UseOsdkAggregationResult<\n T extends ObjectOrInterfaceDefinition,\n A extends AggregateOpts<T>,\n> {\n data: AggregationsResults<T, A> | undefined;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => void;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for performing aggregations on OSDK object sets.\n *\n * Executes server-side aggregations with groupBy and metric calculations on filtered object sets.\n * Supports runtime derived properties and where clauses.\n *\n * @param type - The object or interface type to aggregate\n * @param options - Aggregation configuration including where clause, aggregation spec, and optional derived properties\n * @returns Object containing aggregation results, loading state, error state, and refetch function\n *\n * @example\n * ```tsx\n * // 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 = EMPTY_WHERE,\n withProperties,\n intersectWith,\n aggregate,\n dedupeIntervalMs,\n } = options;\n const objectSet = \"objectSet\" in options ? options.objectSet : undefined;\n\n const { observableClient } = React.useContext(OsdkContext2);\n\n const canonWhere = observableClient.canonicalizeWhereClause<Q>(where);\n\n const stableCanonWhere = React.useMemo(\n () => canonWhere,\n [JSON.stringify(canonWhere)],\n );\n\n const objectSetRef = React.useRef(objectSet);\n objectSetRef.current = objectSet;\n\n const objectSetKeyString = objectSet\n ? computeObjectSetCacheKey(objectSet)\n : undefined;\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableAggregate = React.useMemo(\n () => aggregate,\n [JSON.stringify(aggregate)],\n );\n\n const stableIntersectWith = React.useMemo(\n () => intersectWith,\n [JSON.stringify(intersectWith)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (objectSetKeyString && objectSetRef.current) {\n return makeExternalStoreAsync<ObserveAggregationArgs<Q, A>>(\n (observer) =>\n observableClient.observeAggregation(\n {\n type: type,\n objectSet: objectSetRef.current!,\n where: stableCanonWhere,\n withProperties: stableWithProperties,\n intersectWith: stableIntersectWith,\n aggregate: stableAggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${objectSetKeyString} ${\n JSON.stringify(stableCanonWhere)\n }`\n : void 0,\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: type,\n where: stableCanonWhere,\n withProperties: stableWithProperties,\n intersectWith: stableIntersectWith,\n aggregate: stableAggregate,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n },\n observer,\n ),\n process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${JSON.stringify(stableCanonWhere)}`\n : void 0,\n );\n },\n [\n observableClient,\n type.apiName,\n type.type,\n objectSetKeyString,\n stableCanonWhere,\n stableWithProperties,\n stableIntersectWith,\n stableAggregate,\n dedupeIntervalMs,\n ],\n );\n\n const payload = 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(() => {\n let error: Error | undefined;\n if (payload && \"error\" in payload && payload.error) {\n error = payload.error;\n } else if (payload?.status === \"error\") {\n error = new Error(\"Failed to execute aggregation\");\n }\n\n return {\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload,\n error,\n refetch,\n };\n }, [payload, refetch]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,SAASA,wBAAwB,QAAQ,kCAAkC;AAC3E,OAAOC,KAAK,MAAM,OAAO;AACzB,SACEC,iBAAiB,EACjBC,sBAAsB,QACjB,wBAAwB;AAC/B,SAASC,YAAY,QAAQ,mBAAmB;AA0DhD,MAAMC,WAAW,GAAG,CAAC,CAAC;;AAkBtB;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,GAAGJ,WAAW;IACnBK,cAAc;IACdC,aAAa;IACbC,SAAS;IACTC;EACF,CAAC,GAAGL,OAAO;EACX,MAAMM,SAAS,GAAG,WAAW,IAAIN,OAAO,GAAGA,OAAO,CAACM,SAAS,GAAGC,SAAS;EAExE,MAAM;IAAEC;EAAiB,CAAC,GAAGf,KAAK,CAACgB,UAAU,CAACb,YAAY,CAAC;EAE3D,MAAMc,UAAU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AE;MAClDA,KAAK,GAAGL,OAAO,CAACK,KAAK;IACvB,CAAC,MAAM,IAAIL,OAAO,EAAEM,MAAM,KAAK,OAAO,EAAE;MACtCD,KAAK,GAAG,IAAIE,KAAK,CAAC,+BAA+B,CAAC;IACpD;IAEA,OAAO;MACLC,IAAI,EAAER,OAAO,EAAES,MAA+C;MAC9DC,SAAS,EAAEV,OAAO,EAAEM,MAAM,KAAK,SAAS,IAAIN,OAAO,EAAEM,MAAM,KAAK,MAAM,IACjE,CAACN,OAAO;MACbK,KAAK;MACLH;IACF,CAAC;EACH,CAAC,EAAE,CAACF,OAAO,EAAEE,OAAO,CAAC,CAAC;AACxB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useOsdkAggregation.js","names":["getWireObjectSet","React","extractPayloadError","isPayloadLoading","makeExternalStore","makeExternalStoreAsync","OsdkContext2","useOsdkAggregation","type","options","where","withProperties","intersectWith","aggregate","dedupeIntervalMs","objectSet","undefined","observableClient","useContext","canonOptions","canonicalizeOptions","objectSetKey","JSON","stringify","objectSetRef","useRef","current","subscribe","getSnapShot","useMemo","currentObjectSet","observer","observeAggregation","dedupeInterval","process","env","NODE_ENV","apiName","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 type { ObjectTypeDefinition } from \"@osdk/client\";\nimport {\n getWireObjectSet,\n type ObserveAggregationArgs,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport {\n makeExternalStore,\n makeExternalStoreAsync,\n} from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.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\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\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\n/**\n * React hook for performing aggregations on OSDK object sets.\n *\n * Executes server-side aggregations with groupBy and metric calculations on filtered object sets.\n * Supports runtime derived properties and where clauses.\n *\n * @param type - The object or interface type to aggregate\n * @param options - Aggregation configuration including where clause, aggregation spec, and optional derived properties\n * @returns Object containing aggregation results, loading state, error state, and refetch function\n *\n * @example\n * ```tsx\n * // 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 } = options;\n const objectSet = \"objectSet\" in options ? options.objectSet : undefined;\n\n const { observableClient } = React.useContext(OsdkContext2);\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 () => {\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 process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${\n JSON.stringify(canonOptions.where)\n }`\n : void 0,\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 process.env.NODE_ENV !== \"production\"\n ? `aggregation ${type.apiName} ${JSON.stringify(canonOptions.where)}`\n : void 0,\n );\n },\n [\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\n const payload = 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(() => ({\n data: payload?.result as AggregationsResults<Q, A> | undefined,\n isLoading: isPayloadLoading(payload, true),\n error: extractPayloadError(payload, \"Failed to execute aggregation\"),\n refetch,\n }), [payload, refetch]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SACEA,gBAAgB,QAEX,kCAAkC;AACzC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,gBAAgB;AACtE,SACEC,iBAAiB,EACjBC,sBAAsB,QACjB,wBAAwB;AAC/B,SAASC,YAAY,QAAQ,mBAAmB;;AA0EhD;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;EACF,CAAC,GAAGL,OAAO;EACX,MAAMM,SAAS,GAAG,WAAW,IAAIN,OAAO,GAAGA,OAAO,CAACM,SAAS,GAAGC,SAAS;EAExE,MAAM;IAAEC;EAAiB,CAAC,GAAGhB,KAAK,CAACiB,UAAU,CAACZ,YAAY,CAAC;EAE3D,MAAMa,YAAY,GAAGF,gBAAgB,CAACG,mBAAmB,CAAC;IACxDV,KAAK;IACLC,cAAc;IACdE,SAAS;IACTD;EACF,CAAC,CAAC;EAEF,MAAMS,YAAY,GAAGN,SAAS,GAC1BO,IAAI,CAACC,SAAS,CAACvB,gBAAgB,CAACe,SAAyB,CAAC,CAAC,GAC3DC,SAAS;EAEb,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GACnE,KAAK,CACX,CAAC;EACH,CAAC,EACD,CACEO,gBAAgB,EAChBT,IAAI,CAAC6B,OAAO,EACZ7B,IAAI,CAACA,IAAI,EACTa,YAAY,EACZF,YAAY,CAACT,KAAK,EAClBS,YAAY,CAACR,cAAc,EAC3BQ,YAAY,CAACP,aAAa,EAC1BO,YAAY,CAACN,SAAS,EACtBC,gBAAgB,CAEpB,CAAC;EAED,MAAMwB,OAAO,GAAGrC,KAAK,CAACsC,oBAAoB,CAACZ,SAAS,EAAEC,WAAW,CAAC;EAElE,MAAMY,OAAO,GAAGvC,KAAK,CAACwC,WAAW,CAAC,YAAY;IAC5C,MAAMxB,gBAAgB,CAACyB,oBAAoB,CAAClC,IAAI,CAAC6B,OAAO,CAAC;EAC3D,CAAC,EAAE,CAACpB,gBAAgB,EAAET,IAAI,CAAC6B,OAAO,CAAC,CAAC;EAEpC,OAAOpC,KAAK,CAAC4B,OAAO,CAAC,OAAO;IAC1Bc,IAAI,EAAEL,OAAO,EAAEM,MAA+C;IAC9DC,SAAS,EAAE1C,gBAAgB,CAACmC,OAAO,EAAE,IAAI,CAAC;IAC1CQ,KAAK,EAAE5C,mBAAmB,CAACoC,OAAO,EAAE,+BAA+B,CAAC;IACpEE;EACF,CAAC,CAAC,EAAE,CAACF,OAAO,EAAEE,OAAO,CAAC,CAAC;AACzB","ignoreList":[]}
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import React from "react";
|
|
18
|
+
import { extractPayloadError, isPayloadLoading } from "./hookUtils.js";
|
|
18
19
|
import { makeExternalStore } from "./makeExternalStore.js";
|
|
19
20
|
import { OsdkContext2 } from "./OsdkContext2.js";
|
|
20
|
-
const EMPTY_WHERE = {};
|
|
21
21
|
export function useOsdkObjects(type, options) {
|
|
22
22
|
const {
|
|
23
23
|
observableClient
|
|
@@ -37,13 +37,14 @@ export function useOsdkObjects(type, options) {
|
|
|
37
37
|
$select,
|
|
38
38
|
$loadPropertySecurityMetadata
|
|
39
39
|
} = options ?? {};
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const canonOptions = observableClient.canonicalizeOptions({
|
|
41
|
+
where,
|
|
42
|
+
withProperties,
|
|
43
|
+
orderBy,
|
|
44
|
+
intersectWith,
|
|
45
|
+
$select
|
|
46
|
+
});
|
|
42
47
|
const stableRids = React.useMemo(() => rids, [JSON.stringify(rids)]);
|
|
43
|
-
const stableWithProperties = React.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
44
|
-
const stableIntersectWith = React.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
45
|
-
const stableOrderBy = React.useMemo(() => orderBy, [JSON.stringify(orderBy)]);
|
|
46
|
-
const stableSelect = React.useMemo(() => $select, [JSON.stringify($select)]);
|
|
47
48
|
const {
|
|
48
49
|
subscribe,
|
|
49
50
|
getSnapShot
|
|
@@ -56,43 +57,41 @@ export function useOsdkObjects(type, options) {
|
|
|
56
57
|
return makeExternalStore(observer => observableClient.observeList({
|
|
57
58
|
type,
|
|
58
59
|
rids: stableRids,
|
|
59
|
-
where:
|
|
60
|
+
where: canonOptions.where,
|
|
60
61
|
dedupeInterval: dedupeIntervalMs ?? 2_000,
|
|
61
62
|
pageSize,
|
|
62
|
-
orderBy:
|
|
63
|
+
orderBy: canonOptions.orderBy,
|
|
63
64
|
streamUpdates,
|
|
64
|
-
withProperties:
|
|
65
|
+
withProperties: canonOptions.withProperties,
|
|
65
66
|
autoFetchMore,
|
|
66
|
-
...(
|
|
67
|
-
intersectWith:
|
|
67
|
+
...(canonOptions.intersectWith ? {
|
|
68
|
+
intersectWith: canonOptions.intersectWith
|
|
68
69
|
} : {}),
|
|
69
70
|
...(pivotTo ? {
|
|
70
71
|
pivotTo
|
|
71
72
|
} : {}),
|
|
72
|
-
...(
|
|
73
|
-
select:
|
|
73
|
+
...(canonOptions.$select ? {
|
|
74
|
+
select: canonOptions.$select
|
|
74
75
|
} : {}),
|
|
75
76
|
...($loadPropertySecurityMetadata ? {
|
|
76
77
|
$loadPropertySecurityMetadata
|
|
77
78
|
} : {})
|
|
78
|
-
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(
|
|
79
|
-
}, [enabled, observableClient, type.apiName, type.type, stableRids,
|
|
79
|
+
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(canonOptions.where)}` : void 0);
|
|
80
|
+
}, [enabled, observableClient, type.apiName, type.type, stableRids, canonOptions.where, dedupeIntervalMs, pageSize, canonOptions.orderBy, streamUpdates, canonOptions.withProperties, autoFetchMore, canonOptions.intersectWith, pivotTo, canonOptions.$select, $loadPropertySecurityMetadata]);
|
|
80
81
|
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
}, [listPayload, enabled]);
|
|
82
|
+
const refetch = React.useCallback(async () => {
|
|
83
|
+
await observableClient.invalidateObjectType(type.apiName);
|
|
84
|
+
}, [observableClient, type.apiName]);
|
|
85
|
+
return React.useMemo(() => ({
|
|
86
|
+
fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,
|
|
87
|
+
error: extractPayloadError(listPayload, "Failed to load objects"),
|
|
88
|
+
data: listPayload?.resolvedList,
|
|
89
|
+
isLoading: isPayloadLoading(listPayload, enabled),
|
|
90
|
+
isOptimistic: listPayload?.isOptimistic ?? false,
|
|
91
|
+
totalCount: listPayload?.totalCount,
|
|
92
|
+
hasMore: listPayload?.hasMore ?? false,
|
|
93
|
+
objectSet: listPayload?.objectSet,
|
|
94
|
+
refetch
|
|
95
|
+
}), [listPayload, enabled, refetch]);
|
|
97
96
|
}
|
|
98
97
|
//# sourceMappingURL=useOsdkObjects.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","EMPTY_WHERE","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","$select","$loadPropertySecurityMetadata","canonWhere","canonicalizeWhereClause","stableCanonWhere","useMemo","JSON","stringify","stableRids","stableWithProperties","stableIntersectWith","stableOrderBy","stableSelect","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","select","length","listPayload","useSyncExternalStore","error","status","Error","fetchMore","hasMore","undefined","data","resolvedList","isLoading","isOptimistic","totalCount"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Fetch objects by their RIDs (Resource Identifiers).\n * When provided, starts with a static objectset containing these RIDs.\n * Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.\n *\n * @example\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })\n *\n * @example\n * // Fetch specific objects by RID, filtered by status\n * useOsdkObjects(Employee, {\n * rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],\n * where: { status: 'active' }\n * })\n */\n rids?: readonly string[];\n\n /**\n * Standard OSDK Where clause with RDP support.\n * When used with `rids`, filters the RID set.\n * When used alone, filters all objects of the type.\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Sort results by one or more properties.\n */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /**\n * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n streamUpdates?: boolean;\n\n /**\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 * // Only fetch name and status properties\n * useOsdkObjects(Employee, { $select: [\"name\", \"status\"] })\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\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\nconst EMPTY_WHERE = {};\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L; rids: readonly string[] },\n): UseOsdkListResult<LinkedType<Q, L>, {}, \"$rid\">;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, RDPs> & { rids: readonly string[] },\n): UseOsdkListResult<Q, RDPs, \"$rid\">;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<Q, RDPs, \"$rid\">\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>, {}, \"$rid\">\n{\n const { observableClient } = React.useContext(OsdkContext2);\n\n const {\n pageSize,\n dedupeIntervalMs,\n withProperties,\n enabled = true,\n rids,\n where,\n orderBy,\n streamUpdates,\n autoFetchMore,\n intersectWith,\n pivotTo,\n $select,\n $loadPropertySecurityMetadata,\n } = options ?? {};\n\n const canonWhere = observableClient.canonicalizeWhereClause<\n Q,\n RDPs\n >(where ?? EMPTY_WHERE);\n\n const stableCanonWhere = React.useMemo(\n () => canonWhere,\n [JSON.stringify(canonWhere)],\n );\n\n const stableRids = React.useMemo(\n () => rids,\n [JSON.stringify(rids)],\n );\n\n const stableWithProperties = React.useMemo(\n () => withProperties,\n [JSON.stringify(withProperties)],\n );\n\n const stableIntersectWith = React.useMemo(\n () => intersectWith,\n [JSON.stringify(intersectWith)],\n );\n\n const stableOrderBy = React.useMemo(\n () => orderBy,\n [JSON.stringify(orderBy)],\n );\n\n const stableSelect = React.useMemo(\n () => $select,\n [JSON.stringify($select)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} [DISABLED]`\n : void 0,\n );\n }\n\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n (observer) =>\n observableClient.observeList({\n type,\n rids: stableRids,\n where: stableCanonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: stableOrderBy,\n streamUpdates,\n withProperties: stableWithProperties,\n autoFetchMore,\n ...(stableIntersectWith\n ? { intersectWith: stableIntersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n ...(stableSelect ? { select: stableSelect } : {}),\n ...($loadPropertySecurityMetadata\n ? { $loadPropertySecurityMetadata }\n : {}),\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${\n stableRids ? `[${stableRids.length} rids]` : \"\"\n } ${JSON.stringify(stableCanonWhere)}`\n : void 0,\n );\n },\n [\n enabled,\n observableClient,\n type.apiName,\n type.type,\n stableRids,\n stableCanonWhere,\n dedupeIntervalMs,\n pageSize,\n stableOrderBy,\n streamUpdates,\n stableWithProperties,\n autoFetchMore,\n stableIntersectWith,\n pivotTo,\n stableSelect,\n $loadPropertySecurityMetadata,\n ],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return React.useMemo(() => {\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,\n error,\n data: listPayload?.resolvedList,\n isLoading: enabled\n ? (listPayload?.status === \"loading\" || listPayload?.status === \"init\"\n || !listPayload)\n : false,\n isOptimistic: listPayload?.isOptimistic ?? false,\n total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AC;EACH,CAAC,EAAE,CAACZ,WAAW,EAAEjC,OAAO,CAAC,CAAC;AAC5B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useOsdkObjects.js","names":["React","extractPayloadError","isPayloadLoading","makeExternalStore","OsdkContext2","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","$select","$loadPropertySecurityMetadata","canonOptions","canonicalizeOptions","stableRids","useMemo","JSON","stringify","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","select","length","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/unstable-do-not-use\";\nimport React from \"react\";\nimport { extractPayloadError, isPayloadLoading } from \"./hookUtils.js\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Fetch objects by their RIDs (Resource Identifiers).\n * When provided, starts with a static objectset containing these RIDs.\n * Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.\n *\n * @example\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })\n *\n * @example\n * // Fetch specific objects by RID, filtered by status\n * useOsdkObjects(Employee, {\n * rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],\n * where: { status: 'active' }\n * })\n */\n rids?: readonly string[];\n\n /**\n * Standard OSDK Where clause with RDP support.\n * When used with `rids`, filters the RID set.\n * When used alone, filters all objects of the type.\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Sort results by one or more properties.\n */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /**\n * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n streamUpdates?: boolean;\n\n /**\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 * // Only fetch name and status properties\n * useOsdkObjects(Employee, { $select: [\"name\", \"status\"] })\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\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\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L; rids: readonly string[] },\n): UseOsdkListResult<LinkedType<Q, L>, {}, \"$rid\">;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n L extends LinkNames<Q>,\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q> & { pivotTo: L },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options: UseOsdkObjectsOptions<Q, RDPs> & { rids: readonly string[] },\n): UseOsdkListResult<Q, RDPs, \"$rid\">;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<Q, RDPs, \"$rid\">\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>, {}, \"$rid\">\n{\n const { observableClient } = React.useContext(OsdkContext2);\n\n const {\n pageSize,\n dedupeIntervalMs,\n withProperties,\n enabled = true,\n rids,\n where,\n orderBy,\n streamUpdates,\n autoFetchMore,\n intersectWith,\n pivotTo,\n $select,\n $loadPropertySecurityMetadata,\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(\n () => rids,\n [JSON.stringify(rids)],\n );\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n () => ({ unsubscribe: () => {} }),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} [DISABLED]`\n : void 0,\n );\n }\n\n return makeExternalStore<\n ObserveObjectsCallbackArgs<Q, RDPs>\n >(\n (observer) =>\n observableClient.observeList({\n type,\n rids: stableRids,\n where: canonOptions.where,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy: canonOptions.orderBy,\n streamUpdates,\n withProperties: canonOptions.withProperties,\n autoFetchMore,\n ...(canonOptions.intersectWith\n ? { intersectWith: canonOptions.intersectWith }\n : {}),\n ...(pivotTo ? { pivotTo } : {}),\n ...(canonOptions.$select ? { select: canonOptions.$select } : {}),\n ...($loadPropertySecurityMetadata\n ? { $loadPropertySecurityMetadata }\n : {}),\n }, observer),\n process.env.NODE_ENV !== \"production\"\n ? `list ${type.apiName} ${\n stableRids ? `[${stableRids.length} rids]` : \"\"\n } ${JSON.stringify(canonOptions.where)}`\n : void 0,\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 ],\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(() => ({\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 }), [listPayload, enabled, refetch]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,mBAAmB,EAAEC,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AC5C,MAAMpC,gBAAgB,CAACqC,oBAAoB,CAACvC,IAAI,CAAC6B,OAAO,CAAC;EAC3D,CAAC,EAAE,CAAC3B,gBAAgB,EAAEF,IAAI,CAAC6B,OAAO,CAAC,CAAC;EAEpC,OAAOnC,KAAK,CAAC0B,OAAO,CAAC,OAAO;IAC1BoB,SAAS,EAAEL,WAAW,EAAEM,OAAO,GAAGN,WAAW,CAACK,SAAS,GAAGE,SAAS;IACnEC,KAAK,EAAEhD,mBAAmB,CAACwC,WAAW,EAAE,wBAAwB,CAAC;IACjES,IAAI,EAAET,WAAW,EAAEU,YAAY;IAC/BC,SAAS,EAAElD,gBAAgB,CAACuC,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,EAAE,CAACF,WAAW,EAAE5B,OAAO,EAAE8B,OAAO,CAAC,CAAC;AACtC","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function extractPayloadError(payload: {
|
|
2
|
+
error?: Error
|
|
3
|
+
status?: string
|
|
4
|
+
} | undefined | null, fallbackMessage: string): Error | undefined;
|
|
5
|
+
export declare function isPayloadLoading(payload: {
|
|
6
|
+
status?: string
|
|
7
|
+
} | undefined | null, enabled: boolean): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,OAAO,iBAAS,oBACdA,SAAS;CAAE,QAAQ;CAAO;AAAiB,sBAC3CC,0BACC;AAUH,OAAO,iBAAS,iBACdC,SAAS;CAAE;AAAiB,sBAC5BC","names":["payload: { error?: Error; status?: string } | undefined | null","fallbackMessage: string","payload: { status?: string } | undefined | null","enabled: boolean"],"sources":["../../../src/new/hookUtils.ts"],"version":3,"file":"hookUtils.d.ts"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cACE,YACA,WACA,mCACK,WAAY;AACnB,cAAc,MAAM,cAAc,mBAAmB,cAAe;
|
|
1
|
+
{"mappings":"AAgBA,cACE,YACA,WACA,mCACK,WAAY;AACnB,cAAc,MAAM,cAAc,mBAAmB,cAAe;AAOpE,iBAAiB,gBACf,UAAU,6BACV;;;;CAIA,QAAQ,YAAY;;;;CAKpB;;CAGA,aACG,KAAK,aAAa,OAAM,QAAQ;;;;;;CAQnC,mBAAmB,aAAa;;;;;;;CAQhC,OAAO,UAAU;;;;;;;CAQjB;;;;;;;;;;;;;;;;;;;;CAqBA;AACD;AAED,iBAAiB,eACf,UAAU,6BACV;CACA,OAAO,KAAK,SAAS;;;;;;CAOrB,iCAAiC,6BAE/B,cAAc,KAAK,SAAS;CAG9B;CACA,OAAO;;;;CAKP;;;;CAKA,kBAAkB;;;;CAKlB;AACD;;;;;;;;;AAaD,OAAO,iBAAS;CACd,UAAU;CACV,UAAU,UAAU;EAEpBA,SAAS,KAAK,SAAS,KAAK,MAAM,KAAK,SAAS,iBAChDC,UAAU,GACVC,UAAS,gBAAgB,WAAW,GAAG,MACtC,eAAe,WAAW,GAAG","names":["objects: Osdk.Instance<T> | Array<Osdk.Instance<T>> | undefined","linkName: L","options: UseLinksOptions<LinkedType<T, L>>"],"sources":["../../../src/new/useLinks.ts"],"version":3,"file":"useLinks.d.ts"}
|
|
@@ -98,18 +98,21 @@ export interface UseObjectSetResult<
|
|
|
98
98
|
* Any error that occurred during fetching
|
|
99
99
|
*/
|
|
100
100
|
error: Error | undefined;
|
|
101
|
+
isOptimistic: boolean;
|
|
101
102
|
/**
|
|
102
103
|
* Function to fetch more pages (undefined if no more pages)
|
|
103
104
|
*/
|
|
104
105
|
fetchMore: (() => Promise<void>) | undefined;
|
|
106
|
+
hasMore: boolean;
|
|
105
107
|
/**
|
|
106
108
|
* The final ObjectSet after all transformations
|
|
107
109
|
*/
|
|
108
|
-
objectSet: ObjectSet<Q, RDPs
|
|
110
|
+
objectSet: ObjectSet<Q, RDPs> | undefined;
|
|
109
111
|
/**
|
|
110
112
|
* The total count of objects matching the query (if available from the API)
|
|
111
113
|
*/
|
|
112
114
|
totalCount?: string;
|
|
115
|
+
refetch: () => Promise<void>;
|
|
113
116
|
}
|
|
114
117
|
/**
|
|
115
118
|
* React hook for observing and interacting with OSDK object sets.
|
|
@@ -126,4 +129,4 @@ export declare function useObjectSet<
|
|
|
126
129
|
Q extends ObjectOrInterfaceDefinition,
|
|
127
130
|
BaseRDPs extends Record<string, SimplePropertyDef> = never,
|
|
128
131
|
RDPs extends Record<string, SimplePropertyDef> = {}
|
|
129
|
-
>(baseObjectSet: ObjectSet<Q, BaseRDPs
|
|
132
|
+
>(baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined, options?: UseObjectSetOptions<Q, RDPs>): UseObjectSetResult<Q, RDPs>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cACE,iBACA,WACA,6BACA,WACA,MACA,cACA,mBACA,mBACK,WAAY;
|
|
1
|
+
{"mappings":"AAgBA,cACE,iBACA,WACA,6BACA,WACA,MACA,cACA,mBACA,mBACK,WAAY;AAWnB,iBAAiB;CACf,UAAU;CACV,aAAa,eAAe,qBAAqB,CAAE;EACnD;;;;CAIA,QAAQ,YAAY,GAAG;;;;CAKvB,oBAAoB,WAAW,QAAO,gBAAgB,QAAQ,GAAG,KAAK;;;;CAKtE,QAAQ,UAAU;;;;CAKlB,YAAY,UAAU;;;;CAKtB,WAAW,UAAU;;;;CAKrB,UAAU,UAAU;;;;CAKpB;;;;CAKA,aACG,KAAK,aAAa,OAAM,QAAQ;;;;CAMnC;;;;;;;;CASA;;;;;;;;CASA;;;;;;CAOA,mBAAmB,aAAa;;;;;;;;;;;;;;;;;;;;CAqBhC;AACD;AAED,iBAAiB;CACf,UAAU;CACV,aAAa,eAAe,qBAAqB,CAAE;EACnD;;;;CAIA,MACI,KAAK,SAAS,GAAG,sBAAsB,aAAa,IAAI;;;;CAM5D;;;;CAKA,OAAO;CAEP;;;;CAKA,kBAAkB;CAElB;;;;CAKA,WAAW,UAAU,GAAG;;;;CAKxB;CAEA,eAAe;AAChB;;;;;;;;;;;;AAoBD,OAAO,iBAAS;CACd,UAAU;CACV,iBAAiB,eAAe;CAChC,aAAa,eAAe,qBAAqB,CAAE;EAEnDA,eAAe,UAAU,GAAG,uBAC5BC,UAAS,oBAAoB,GAAG,QAC/B,mBAAmB,GAAG","names":["baseObjectSet: ObjectSet<Q, BaseRDPs> | undefined","options: UseObjectSetOptions<Q, RDPs>"],"sources":["../../../src/new/useObjectSet.tsx"],"version":3,"file":"useObjectSet.d.ts"}
|
|
@@ -56,7 +56,7 @@ export interface UseOsdkAggregationResult<
|
|
|
56
56
|
data: AggregationsResults<T, A> | undefined;
|
|
57
57
|
isLoading: boolean;
|
|
58
58
|
error: Error | undefined;
|
|
59
|
-
refetch: () => void
|
|
59
|
+
refetch: () => Promise<void>;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* React hook for performing aggregations on OSDK object sets.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cACE,eACA,qBACA,iBACA,6BACA,WACA,mBACA,mBACK,WAAY;AACnB,cAAc,4BAA4B,cAAe;
|
|
1
|
+
{"mappings":"AAgBA,cACE,eACA,qBACA,iBACA,6BACA,WACA,mBACA,mBACK,WAAY;AACnB,cAAc,4BAA4B,cAAe;UAa/C;CACR,UAAU;CACV,UAAU,cAAc;CACxB,aAAa,eAAe,qBAAqB,CAAE;EACnD;;;;CAIA,QAAQ,YAAY,GAAG;;;;;CAMvB,oBAAoB,WAAW,QAAO,gBAAgB,QAAQ,GAAG,KAAK;;;;;;CAOtE,gBAAgB,MAAM;EACpB,OAAO,YAAY,GAAG;CACvB;;;;CAKD,WAAW;;;;;;;CAQX;AACD;AAED,iBAAiB;CACf,UAAU;CACV,UAAU,cAAc;CACxB,aAAa,eAAe,qBAAqB,CAAE;UAC3C,8BAA8B,GAAG,GAAG,MAAM,CAAE;AAEtD,iBAAiB;CACf,UAAU;CACV,UAAU,cAAc;CACxB,aAAa,eAAe,qBAAqB,CAAE;UAC3C,8BAA8B,GAAG,GAAG,MAAM;;;;CAIlD,WAAW,UAAU;AACtB;AAED,iBAAiB;CACf,UAAU;CACV,UAAU,cAAc;EACxB;CACA,MAAM,oBAAoB,GAAG;CAC7B;CACA,OAAO;CACP,eAAe;AAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCD,OAAO,iBAAS;CACd,UAAU;OACJ,UAAU,cAAc;CAC9B,aAAa,eAAe,qBAAqB,CAAE;EAEnDA,MAAM,GACNC,SAAS,0BAA0B,GAAG,GAAG,QACxC,yBAAyB,GAAG;AAC/B,OAAO,iBAAS;CACd,UAAU;OACJ,UAAU,cAAc;CAC9B,aAAa,eAAe,qBAAqB,CAAE;EAEnDD,MAAM,GACNE,SAAS,uCAAuC,GAAG,GAAG,QACrD,yBAAyB,GAAG","names":["type: Q","options: UseOsdkAggregationOptions<Q, A, RDPs>","options: UseOsdkAggregationOptionsWithObjectSet<Q, A, RDPs>"],"sources":["../../../src/new/useOsdkAggregation.ts"],"version":3,"file":"useOsdkAggregation.d.ts"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DerivedProperty, LinkedType, LinkNames, ObjectOrInterfaceDefinition, Osdk, PropertyKeys, SimplePropertyDef, WhereClause } from "@osdk/api";
|
|
1
|
+
import type { DerivedProperty, LinkedType, LinkNames, ObjectOrInterfaceDefinition, ObjectSet, Osdk, PropertyKeys, SimplePropertyDef, WhereClause } from "@osdk/api";
|
|
2
2
|
export interface UseOsdkObjectsOptions<
|
|
3
3
|
T extends ObjectOrInterfaceDefinition,
|
|
4
4
|
RDPs extends Record<string, SimplePropertyDef> = {}
|
|
@@ -129,6 +129,9 @@ export interface UseOsdkListResult<
|
|
|
129
129
|
* The total count of objects matching the query (if available from the API)
|
|
130
130
|
*/
|
|
131
131
|
totalCount?: string;
|
|
132
|
+
hasMore: boolean;
|
|
133
|
+
objectSet: ObjectSet<T, RDPs> | undefined;
|
|
134
|
+
refetch: () => Promise<void>;
|
|
132
135
|
}
|
|
133
136
|
export declare function useOsdkObjects<
|
|
134
137
|
Q extends ObjectOrInterfaceDefinition,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cACE,iBACA,YACA,WACA,6BACA,MACA,cACA,mBACA,mBACK,WAAY;
|
|
1
|
+
{"mappings":"AAgBA,cACE,iBACA,YACA,WACA,6BACA,WACA,MACA,cACA,mBACA,mBACK,WAAY;AAOnB,iBAAiB;CACf,UAAU;CACV,aAAa,eAAe,qBAAqB,CAAE;EACnD;;;;;;;;;;;;;;;;;CAiBA;;;;;;CAOA,QAAQ,YAAY,GAAG;;;;CAKvB,aACG,KAAK,aAAa,OAAM,QAAQ;;;;CAMnC;;;;;CAMA,oBAAoB,WAAW,QAAO,gBAAgB,QAAQ,GAAG,KAAK;;;;;;;CAQtE;;;;;;;;;CAUA;;;;;;CAOA,gBAAgB,MAAM;EACpB,OAAO,YAAY,GAAG;CACvB;;;;;CAMD,UAAU,UAAU;;;;;;;;;;CAWpB;CAEA;;;;;;;;;;CAWA,mBAAmB,aAAa;;;;;;CAOhC;AACD;AAED,iBAAiB;CACf,UAAU;CACV,aAAa,eAAe,qBAAqB,CAAE;CACnD,8BAA8B;EAC9B;;;;CAIA,kBAAkB;;;;CAKlB,MACI,KAAK,SACL,GACA,uBAAuB,eACvB,aAAa,IACb;;;;CAOJ;;;;CAKA,OAAO;;;;;;;;CASP;;;;CAKA;CAEA;CAEA,WAAW,UAAU,GAAG;CAExB,eAAe;AAChB;AAQD,OAAO,iBAAS;CACd,UAAU;CACV,UAAU,UAAU;EAEpBA,MAAM,GACNC,SAAS,sBAAsB,KAAK;CAAE,SAAS;CAAG;AAAyB,IAC1E,kBAAkB,WAAW,GAAG,IAAI,CAAE,GAAE;AAE3C,OAAO,iBAAS;CACd,UAAU;CACV,UAAU,UAAU;EAEpBD,MAAM,GACNE,SAAS,sBAAsB,KAAK;CAAE,SAAS;AAAG,IACjD,kBAAkB,WAAW,GAAG;AAEnC,OAAO,iBAAS;CACd,UAAU;CACV,aAAa,eAAe,qBAAqB,CAAE;EAEnDF,MAAM,GACNG,SAAS,sBAAsB,GAAG,QAAQ;CAAE;AAAyB,IACpE,kBAAkB,GAAG,MAAM;AAE9B,OAAO,iBAAS;CACd,UAAU;CACV,aAAa,eAAe,qBAAqB,CAAE;EAEnDH,MAAM,GACNI,UAAU,sBAAsB,GAAG,QAClC,kBAAkB,GAAG","names":["type: Q","options: UseOsdkObjectsOptions<Q> & { pivotTo: L; rids: readonly string[] }","options: UseOsdkObjectsOptions<Q> & { pivotTo: L }","options: UseOsdkObjectsOptions<Q, RDPs> & { rids: readonly string[] }","options?: UseOsdkObjectsOptions<Q, RDPs>"],"sources":["../../../src/new/useOsdkObjects.ts"],"version":3,"file":"useOsdkObjects.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/react",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1-main-20260406220320",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@osdk/api": "^2.8.0",
|
|
58
|
-
"@osdk/client": "^2.8.0",
|
|
57
|
+
"@osdk/api": "^2.8.0 || >=2.8.1-beta.0",
|
|
58
|
+
"@osdk/client": "^2.8.0 || >=2.8.1-beta.0",
|
|
59
59
|
"@osdk/foundry.admin": "*",
|
|
60
60
|
"@osdk/foundry.core": "*",
|
|
61
61
|
"@types/react": "^17 || ^18 || ^19",
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"react": "^18.3.1",
|
|
86
86
|
"tiny-invariant": "^1.3.3",
|
|
87
87
|
"typescript": "~5.5.4",
|
|
88
|
-
"@osdk/api": "2.8.
|
|
89
|
-
"@osdk/client
|
|
90
|
-
"@osdk/client": "2.8.
|
|
88
|
+
"@osdk/api": "2.8.1-main-20260406220320",
|
|
89
|
+
"@osdk/client": "2.8.1-main-20260406220320",
|
|
90
|
+
"@osdk/client.test.ontology": "2.8.1-main-20260406220320",
|
|
91
91
|
"@osdk/monorepo.api-extractor": "~0.7.0",
|
|
92
92
|
"@osdk/monorepo.tsconfig": "~0.7.0"
|
|
93
93
|
},
|