@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
|
@@ -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 totalCount: listPayload?.totalCount,\n };\n }, [listPayload, enabled]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAiKhD,MAAMC,WAAW,GAAG,CAAC,CAAC;AAwCtB,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAM1C;EACE,MAAM;IAAEC;EAAiB,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACN,YAAY,CAAC;EAE3D,MAAM;IACJO,QAAQ;IACRC,gBAAgB;IAChBC,cAAc;IACdC,OAAO,GAAG,IAAI;IACdC,IAAI;IACJC,KAAK;IACLC,OAAO;IACPC,aAAa;IACbC,aAAa;IACbC,aAAa;IACbC,OAAO;IACPC,OAAO;IACPC;EACF,CAAC,GAAGf,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAMgB,UAAU,GAAGf,gBAAgB,CAACgB,uBAAuB,CAGzDT,KAAK,IAAIX,WAAW,CAAC;EAEvB,MAAMqB,gBAAgB,GAAGxB,KAAK,CAACyB,OAAO,CACpC,MAAMH,UAAU,EAChB,CAACI,IAAI,CAACC,SAAS,CAACL,UAAU,CAAC,CAC7B,CAAC;EAED,MAAMM,UAAU,GAAG5B,KAAK,CAACyB,OAAO,CAC9B,MAAMZ,IAAI,EACV,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AAW,CAACK,SAAS,GAAGE,SAAS;MACnEL,KAAK;MACLM,IAAI,EAAER,WAAW,EAAES,YAAY;MAC/BC,SAAS,EAAE3C,OAAO,GACbiC,WAAW,EAAEG,MAAM,KAAK,SAAS,IAAIH,WAAW,EAAEG,MAAM,KAAK,MAAM,IACjE,CAACH,WAAW,GACf,KAAK;MACTW,YAAY,EAAEX,WAAW,EAAEW,YAAY,IAAI,KAAK;MAChDC,UAAU,EAAEZ,WAAW,EAAEY;IAC3B,CAAC;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,gBAAgB,QAAQ,gBAAgB;AACtE,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA6MhD,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAM1C;EACE,MAAM;IAAEC;EAAiB,CAAC,GAAGR,KAAK,CAACS,UAAU,CAACL,YAAY,CAAC;EAE3D,MAAM;IACJM,QAAQ;IACRC,gBAAgB;IAChBC,cAAc;IACdC,OAAO,GAAG,IAAI;IACdC,IAAI;IACJC,KAAK;IACLC,OAAO;IACPC,aAAa;IACbC,aAAa;IACbC,aAAa;IACbC,OAAO;IACPC,OAAO;IACPC;EACF,CAAC,GAAGf,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAMgB,YAAY,GAAGf,gBAAgB,CAACgB,mBAAmB,CAAC;IACxDT,KAAK;IACLH,cAAc;IACdI,OAAO;IACPG,aAAa;IACbE;EACF,CAAC,CAAC;EAEF,MAAMI,UAAU,GAAGzB,KAAK,CAAC0B,OAAO,CAC9B,MAAMZ,IAAI,EACV,CAACa,IAAI,CAACC,SAAS,CAACd,IAAI,CAAC,CACvB,CAAC;EAED,MAAM;IAAEe,SAAS;IAAEC;EAAY,CAAC,GAAG9B,KAAK,CAAC0B,OAAO,CAC9C,MAAM;IACJ,IAAI,CAACb,OAAO,EAAE;MACZ,OAAOV,iBAAiB,CAGtB,OAAO;QAAE4B,WAAW,EAAEA,CAAA,KAAM,CAAC;MAAE,CAAC,CAAC,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a,YAAY,CAACP,OAAO,EACpBC,aAAa,EACbM,YAAY,CAACX,cAAc,EAC3BM,aAAa,EACbK,YAAY,CAACJ,aAAa,EAC1BC,OAAO,EACPG,YAAY,CAACF,OAAO,EACpBC,6BAA6B,CAEjC,CAAC;EAED,MAAMmB,WAAW,GAAGzC,KAAK,CAAC0C,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EAEtE,MAAMa,OAAO,GAAG3C,KAAK,CAAC4C,WAAW,CAAC,YAAY;IAC5C,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":[]}
|
|
@@ -28,6 +28,25 @@ function OsdkProvider2({
|
|
|
28
28
|
}
|
|
29
29
|
}, children));
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
// src/new/hookUtils.ts
|
|
33
|
+
function extractPayloadError(payload, fallbackMessage) {
|
|
34
|
+
if (payload && "error" in payload && payload.error) {
|
|
35
|
+
return payload.error;
|
|
36
|
+
}
|
|
37
|
+
if (payload?.status === "error") {
|
|
38
|
+
return new Error(fallbackMessage);
|
|
39
|
+
}
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
function isPayloadLoading(payload, enabled) {
|
|
43
|
+
if (!enabled) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return payload?.status === "loading" || payload?.status === "init" || !payload;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/new/useLinks.ts
|
|
31
50
|
var emptyArray = Object.freeze([]);
|
|
32
51
|
var emptyMap = /* @__PURE__ */ new Map();
|
|
33
52
|
function useLinks(objects, linkName, options = {}) {
|
|
@@ -38,9 +57,11 @@ function useLinks(objects, linkName, options = {}) {
|
|
|
38
57
|
enabled = true,
|
|
39
58
|
...otherOptions
|
|
40
59
|
} = options;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
const canonOptions = observableClient.canonicalizeOptions({
|
|
61
|
+
where: otherOptions.where,
|
|
62
|
+
orderBy: otherOptions.orderBy,
|
|
63
|
+
$select: otherOptions.$select
|
|
64
|
+
});
|
|
44
65
|
const objectsKey = React4__default.default.useMemo(() => {
|
|
45
66
|
if (objects === void 0) return "";
|
|
46
67
|
const arr = Array.isArray(objects) ? objects : [objects];
|
|
@@ -61,23 +82,23 @@ function useLinks(objects, linkName, options = {}) {
|
|
|
61
82
|
}
|
|
62
83
|
return chunkZUNR45SJ_cjs.makeExternalStore((observer) => observableClient.observeLinks(objectsArray, linkName, {
|
|
63
84
|
linkName,
|
|
64
|
-
where:
|
|
85
|
+
where: canonOptions.where,
|
|
65
86
|
pageSize: otherOptions.pageSize,
|
|
66
|
-
orderBy:
|
|
87
|
+
orderBy: canonOptions.orderBy,
|
|
67
88
|
mode: otherOptions.mode,
|
|
68
89
|
dedupeInterval: otherOptions.dedupeIntervalMs ?? 2e3,
|
|
69
|
-
...
|
|
70
|
-
select:
|
|
90
|
+
...canonOptions.$select ? {
|
|
91
|
+
select: canonOptions.$select
|
|
71
92
|
} : {}
|
|
72
93
|
}, observer), `links ${linkName} for ${objectsKey}`);
|
|
73
|
-
}, [enabled, observableClient, objectsArray, objectsKey, linkName,
|
|
94
|
+
}, [enabled, observableClient, objectsArray, objectsKey, linkName, canonOptions.where, otherOptions.pageSize, canonOptions.orderBy, otherOptions.mode, otherOptions.dedupeIntervalMs, canonOptions.$select]);
|
|
74
95
|
const payload = React4__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
75
96
|
return React4__default.default.useMemo(() => ({
|
|
76
97
|
links: payload?.resolvedList,
|
|
77
98
|
linkedObjectsBySourcePrimaryKey: payload?.linkedObjectsBySourcePrimaryKey ?? emptyMap,
|
|
78
|
-
isLoading:
|
|
99
|
+
isLoading: isPayloadLoading(payload, enabled),
|
|
79
100
|
isOptimistic: payload?.isOptimistic ?? false,
|
|
80
|
-
error: payload
|
|
101
|
+
error: extractPayloadError(payload, "Failed to load links"),
|
|
81
102
|
fetchMore: payload?.hasMore ? payload?.fetchMore : void 0,
|
|
82
103
|
hasMore: payload?.hasMore ?? false
|
|
83
104
|
}), [payload, enabled]);
|
|
@@ -88,11 +109,12 @@ function useObjectSet(baseObjectSet, options = {}) {
|
|
|
88
109
|
observableClient
|
|
89
110
|
} = React4__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
90
111
|
const {
|
|
91
|
-
enabled = true,
|
|
112
|
+
enabled: enabledOption = true,
|
|
92
113
|
streamUpdates,
|
|
93
114
|
...otherOptions
|
|
94
115
|
} = options;
|
|
95
|
-
const
|
|
116
|
+
const enabled = enabledOption && baseObjectSet != null;
|
|
117
|
+
const objectTypeKey = enabled && baseObjectSet ? baseObjectSet.$objectSetInternals.def.apiName : OBJECT_TYPE_PLACEHOLDER;
|
|
96
118
|
const previousObjectTypeRef = React4__default.default.useRef(objectTypeKey);
|
|
97
119
|
const previousCompletedPayloadRef = React4__default.default.useRef();
|
|
98
120
|
const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;
|
|
@@ -100,17 +122,18 @@ function useObjectSet(baseObjectSet, options = {}) {
|
|
|
100
122
|
previousObjectTypeRef.current = objectTypeKey;
|
|
101
123
|
previousCompletedPayloadRef.current = void 0;
|
|
102
124
|
}
|
|
103
|
-
const
|
|
125
|
+
const canonOptions = observableClient.canonicalizeOptions({
|
|
104
126
|
where: otherOptions.where,
|
|
105
127
|
withProperties: otherOptions.withProperties,
|
|
128
|
+
orderBy: otherOptions.orderBy,
|
|
106
129
|
union: otherOptions.union,
|
|
107
130
|
intersect: otherOptions.intersect,
|
|
108
131
|
subtract: otherOptions.subtract,
|
|
109
|
-
|
|
110
|
-
pageSize: otherOptions.pageSize,
|
|
111
|
-
orderBy: otherOptions.orderBy,
|
|
112
|
-
select: otherOptions.$select
|
|
132
|
+
$select: otherOptions.$select
|
|
113
133
|
});
|
|
134
|
+
const objectSetKey = baseObjectSet ? JSON.stringify(unstableDoNotUse.getWireObjectSet(baseObjectSet)) : void 0;
|
|
135
|
+
const baseObjectSetRef = React4__default.default.useRef(baseObjectSet);
|
|
136
|
+
baseObjectSetRef.current = baseObjectSet;
|
|
114
137
|
const {
|
|
115
138
|
subscribe,
|
|
116
139
|
getSnapShot
|
|
@@ -119,42 +142,57 @@ function useObjectSet(baseObjectSet, options = {}) {
|
|
|
119
142
|
return chunkZUNR45SJ_cjs.makeExternalStore(() => ({
|
|
120
143
|
unsubscribe: () => {
|
|
121
144
|
}
|
|
122
|
-
}), process.env.NODE_ENV !== "production" ? `objectSet
|
|
145
|
+
}), process.env.NODE_ENV !== "production" ? `objectSet [DISABLED]` : void 0);
|
|
123
146
|
}
|
|
124
147
|
const initialValue = objectTypeChanged ? void 0 : previousCompletedPayloadRef.current;
|
|
125
148
|
return chunkZUNR45SJ_cjs.makeExternalStore((observer) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
149
|
+
if (!baseObjectSetRef.current) {
|
|
150
|
+
return {
|
|
151
|
+
unsubscribe: () => {
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const subscription = observableClient.observeObjectSet(baseObjectSetRef.current, {
|
|
156
|
+
where: canonOptions.where,
|
|
157
|
+
withProperties: canonOptions.withProperties,
|
|
158
|
+
union: canonOptions.union,
|
|
159
|
+
intersect: canonOptions.intersect,
|
|
160
|
+
subtract: canonOptions.subtract,
|
|
132
161
|
pivotTo: otherOptions.pivotTo,
|
|
133
162
|
pageSize: otherOptions.pageSize,
|
|
134
|
-
orderBy:
|
|
163
|
+
orderBy: canonOptions.orderBy,
|
|
135
164
|
dedupeInterval: otherOptions.dedupeIntervalMs ?? 2e3,
|
|
136
165
|
autoFetchMore: otherOptions.autoFetchMore,
|
|
137
166
|
streamUpdates,
|
|
138
|
-
select:
|
|
167
|
+
select: canonOptions.$select
|
|
139
168
|
}, observer);
|
|
140
169
|
return subscription;
|
|
141
|
-
}, process.env.NODE_ENV !== "production" ? `objectSet ${
|
|
142
|
-
}, [enabled, observableClient,
|
|
170
|
+
}, process.env.NODE_ENV !== "production" ? `objectSet ${objectTypeKey}` : void 0, initialValue);
|
|
171
|
+
}, [enabled, observableClient, objectSetKey, canonOptions.where, canonOptions.withProperties, canonOptions.orderBy, canonOptions.union, canonOptions.intersect, canonOptions.subtract, canonOptions.$select, otherOptions.pivotTo, otherOptions.pageSize, otherOptions.autoFetchMore, otherOptions.dedupeIntervalMs, streamUpdates, objectTypeKey]);
|
|
143
172
|
const payload = React4__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
144
173
|
if (payload && isPayloadCompleted(payload)) {
|
|
145
174
|
previousCompletedPayloadRef.current = payload;
|
|
146
175
|
}
|
|
176
|
+
const typeApiName = baseObjectSet?.$objectSetInternals.def.apiName;
|
|
177
|
+
const refetch = React4__default.default.useCallback(async () => {
|
|
178
|
+
if (typeApiName) {
|
|
179
|
+
await observableClient.invalidateObjectType(typeApiName);
|
|
180
|
+
}
|
|
181
|
+
}, [observableClient, typeApiName]);
|
|
147
182
|
return React4__default.default.useMemo(() => {
|
|
148
183
|
const lastLoaded = isPayloadCompleted(payload) ? payload : previousCompletedPayloadRef.current;
|
|
149
184
|
return {
|
|
150
185
|
data: lastLoaded?.resolvedList,
|
|
151
|
-
isLoading: !isPayloadCompleted(payload),
|
|
152
|
-
error: lastLoaded
|
|
186
|
+
isLoading: enabled ? !isPayloadCompleted(payload) : false,
|
|
187
|
+
error: extractPayloadError(lastLoaded, "Failed to load object set"),
|
|
188
|
+
isOptimistic: payload?.isOptimistic ?? false,
|
|
153
189
|
fetchMore: payload?.hasMore ? payload.fetchMore : void 0,
|
|
154
|
-
|
|
155
|
-
|
|
190
|
+
hasMore: payload?.hasMore ?? false,
|
|
191
|
+
objectSet: lastLoaded?.objectSet,
|
|
192
|
+
totalCount: lastLoaded?.totalCount,
|
|
193
|
+
refetch
|
|
156
194
|
};
|
|
157
|
-
}, [payload,
|
|
195
|
+
}, [payload, refetch, enabled]);
|
|
158
196
|
}
|
|
159
197
|
function isPayloadCompleted(payload) {
|
|
160
198
|
if (payload != null && "error" in payload) {
|
|
@@ -289,10 +327,9 @@ function useOsdkAction(actionDef) {
|
|
|
289
327
|
validationResult
|
|
290
328
|
}), [applyAction, validateAction, error, data, isPending, isValidating, validationResult]);
|
|
291
329
|
}
|
|
292
|
-
var EMPTY_WHERE = {};
|
|
293
330
|
function useOsdkAggregation(type, options) {
|
|
294
331
|
const {
|
|
295
|
-
where
|
|
332
|
+
where,
|
|
296
333
|
withProperties,
|
|
297
334
|
intersectWith,
|
|
298
335
|
aggregate,
|
|
@@ -302,59 +339,53 @@ function useOsdkAggregation(type, options) {
|
|
|
302
339
|
const {
|
|
303
340
|
observableClient
|
|
304
341
|
} = React4__default.default.useContext(chunkZUNR45SJ_cjs.OsdkContext2);
|
|
305
|
-
const
|
|
306
|
-
|
|
342
|
+
const canonOptions = observableClient.canonicalizeOptions({
|
|
343
|
+
where,
|
|
344
|
+
withProperties,
|
|
345
|
+
aggregate,
|
|
346
|
+
intersectWith
|
|
347
|
+
});
|
|
348
|
+
const objectSetKey = objectSet ? JSON.stringify(unstableDoNotUse.getWireObjectSet(objectSet)) : void 0;
|
|
307
349
|
const objectSetRef = React4__default.default.useRef(objectSet);
|
|
308
350
|
objectSetRef.current = objectSet;
|
|
309
|
-
const objectSetKeyString = objectSet ? unstableDoNotUse.computeObjectSetCacheKey(objectSet) : void 0;
|
|
310
|
-
const stableWithProperties = React4__default.default.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
311
|
-
const stableAggregate = React4__default.default.useMemo(() => aggregate, [JSON.stringify(aggregate)]);
|
|
312
|
-
const stableIntersectWith = React4__default.default.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
313
351
|
const {
|
|
314
352
|
subscribe,
|
|
315
353
|
getSnapShot
|
|
316
354
|
} = React4__default.default.useMemo(() => {
|
|
317
|
-
|
|
355
|
+
const currentObjectSet = objectSetRef.current;
|
|
356
|
+
if (currentObjectSet) {
|
|
318
357
|
return chunkZUNR45SJ_cjs.makeExternalStoreAsync((observer) => observableClient.observeAggregation({
|
|
319
358
|
type,
|
|
320
|
-
objectSet:
|
|
321
|
-
where:
|
|
322
|
-
withProperties:
|
|
323
|
-
intersectWith:
|
|
324
|
-
aggregate:
|
|
359
|
+
objectSet: currentObjectSet,
|
|
360
|
+
where: canonOptions.where,
|
|
361
|
+
withProperties: canonOptions.withProperties,
|
|
362
|
+
intersectWith: canonOptions.intersectWith,
|
|
363
|
+
aggregate: canonOptions.aggregate,
|
|
325
364
|
dedupeInterval: dedupeIntervalMs ?? 2e3
|
|
326
|
-
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${
|
|
365
|
+
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(canonOptions.where)}` : void 0);
|
|
327
366
|
}
|
|
328
367
|
return chunkZUNR45SJ_cjs.makeExternalStore((observer) => (
|
|
329
368
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
330
369
|
observableClient.observeAggregation({
|
|
331
370
|
type,
|
|
332
|
-
where:
|
|
333
|
-
withProperties:
|
|
334
|
-
intersectWith:
|
|
335
|
-
aggregate:
|
|
371
|
+
where: canonOptions.where,
|
|
372
|
+
withProperties: canonOptions.withProperties,
|
|
373
|
+
intersectWith: canonOptions.intersectWith,
|
|
374
|
+
aggregate: canonOptions.aggregate,
|
|
336
375
|
dedupeInterval: dedupeIntervalMs ?? 2e3
|
|
337
376
|
}, observer)
|
|
338
|
-
), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(
|
|
339
|
-
}, [observableClient, type.apiName, type.type,
|
|
377
|
+
), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(canonOptions.where)}` : void 0);
|
|
378
|
+
}, [observableClient, type.apiName, type.type, objectSetKey, canonOptions.where, canonOptions.withProperties, canonOptions.intersectWith, canonOptions.aggregate, dedupeIntervalMs]);
|
|
340
379
|
const payload = React4__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
341
380
|
const refetch = React4__default.default.useCallback(async () => {
|
|
342
381
|
await observableClient.invalidateObjectType(type.apiName);
|
|
343
382
|
}, [observableClient, type.apiName]);
|
|
344
|
-
return React4__default.default.useMemo(() => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
return {
|
|
352
|
-
data: payload?.result,
|
|
353
|
-
isLoading: payload?.status === "loading" || payload?.status === "init" || !payload,
|
|
354
|
-
error,
|
|
355
|
-
refetch
|
|
356
|
-
};
|
|
357
|
-
}, [payload, refetch]);
|
|
383
|
+
return React4__default.default.useMemo(() => ({
|
|
384
|
+
data: payload?.result,
|
|
385
|
+
isLoading: isPayloadLoading(payload, true),
|
|
386
|
+
error: extractPayloadError(payload, "Failed to execute aggregation"),
|
|
387
|
+
refetch
|
|
388
|
+
}), [payload, refetch]);
|
|
358
389
|
}
|
|
359
390
|
function useOsdkFunction(queryDef, options = {}) {
|
|
360
391
|
const {
|
|
@@ -461,7 +492,6 @@ function useOsdkObject(...args) {
|
|
|
461
492
|
};
|
|
462
493
|
}, [payload, enabled, forceUpdate]);
|
|
463
494
|
}
|
|
464
|
-
var EMPTY_WHERE2 = {};
|
|
465
495
|
function useOsdkObjects(type, options) {
|
|
466
496
|
const {
|
|
467
497
|
observableClient
|
|
@@ -481,13 +511,14 @@ function useOsdkObjects(type, options) {
|
|
|
481
511
|
$select,
|
|
482
512
|
$loadPropertySecurityMetadata
|
|
483
513
|
} = options ?? {};
|
|
484
|
-
const
|
|
485
|
-
|
|
514
|
+
const canonOptions = observableClient.canonicalizeOptions({
|
|
515
|
+
where,
|
|
516
|
+
withProperties,
|
|
517
|
+
orderBy,
|
|
518
|
+
intersectWith,
|
|
519
|
+
$select
|
|
520
|
+
});
|
|
486
521
|
const stableRids = React4__default.default.useMemo(() => rids, [JSON.stringify(rids)]);
|
|
487
|
-
const stableWithProperties = React4__default.default.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
488
|
-
const stableIntersectWith = React4__default.default.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
489
|
-
const stableOrderBy = React4__default.default.useMemo(() => orderBy, [JSON.stringify(orderBy)]);
|
|
490
|
-
const stableSelect = React4__default.default.useMemo(() => $select, [JSON.stringify($select)]);
|
|
491
522
|
const {
|
|
492
523
|
subscribe,
|
|
493
524
|
getSnapShot
|
|
@@ -501,44 +532,42 @@ function useOsdkObjects(type, options) {
|
|
|
501
532
|
return chunkZUNR45SJ_cjs.makeExternalStore((observer) => observableClient.observeList({
|
|
502
533
|
type,
|
|
503
534
|
rids: stableRids,
|
|
504
|
-
where:
|
|
535
|
+
where: canonOptions.where,
|
|
505
536
|
dedupeInterval: dedupeIntervalMs ?? 2e3,
|
|
506
537
|
pageSize,
|
|
507
|
-
orderBy:
|
|
538
|
+
orderBy: canonOptions.orderBy,
|
|
508
539
|
streamUpdates,
|
|
509
|
-
withProperties:
|
|
540
|
+
withProperties: canonOptions.withProperties,
|
|
510
541
|
autoFetchMore,
|
|
511
|
-
...
|
|
512
|
-
intersectWith:
|
|
542
|
+
...canonOptions.intersectWith ? {
|
|
543
|
+
intersectWith: canonOptions.intersectWith
|
|
513
544
|
} : {},
|
|
514
545
|
...pivotTo ? {
|
|
515
546
|
pivotTo
|
|
516
547
|
} : {},
|
|
517
|
-
...
|
|
518
|
-
select:
|
|
548
|
+
...canonOptions.$select ? {
|
|
549
|
+
select: canonOptions.$select
|
|
519
550
|
} : {},
|
|
520
551
|
...$loadPropertySecurityMetadata ? {
|
|
521
552
|
$loadPropertySecurityMetadata
|
|
522
553
|
} : {}
|
|
523
|
-
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(
|
|
524
|
-
}, [enabled, observableClient, type.apiName, type.type, stableRids,
|
|
554
|
+
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(canonOptions.where)}` : void 0);
|
|
555
|
+
}, [enabled, observableClient, type.apiName, type.type, stableRids, canonOptions.where, dedupeIntervalMs, pageSize, canonOptions.orderBy, streamUpdates, canonOptions.withProperties, autoFetchMore, canonOptions.intersectWith, pivotTo, canonOptions.$select, $loadPropertySecurityMetadata]);
|
|
525
556
|
const listPayload = React4__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
};
|
|
541
|
-
}, [listPayload, enabled]);
|
|
557
|
+
const refetch = React4__default.default.useCallback(async () => {
|
|
558
|
+
await observableClient.invalidateObjectType(type.apiName);
|
|
559
|
+
}, [observableClient, type.apiName]);
|
|
560
|
+
return React4__default.default.useMemo(() => ({
|
|
561
|
+
fetchMore: listPayload?.hasMore ? listPayload.fetchMore : void 0,
|
|
562
|
+
error: extractPayloadError(listPayload, "Failed to load objects"),
|
|
563
|
+
data: listPayload?.resolvedList,
|
|
564
|
+
isLoading: isPayloadLoading(listPayload, enabled),
|
|
565
|
+
isOptimistic: listPayload?.isOptimistic ?? false,
|
|
566
|
+
totalCount: listPayload?.totalCount,
|
|
567
|
+
hasMore: listPayload?.hasMore ?? false,
|
|
568
|
+
objectSet: listPayload?.objectSet,
|
|
569
|
+
refetch
|
|
570
|
+
}), [listPayload, enabled, refetch]);
|
|
542
571
|
}
|
|
543
572
|
function useDebouncedCallback(callback, delay) {
|
|
544
573
|
const timeoutRef = React4__default.default.useRef();
|