@osdk/react 0.10.0-beta.4 → 0.10.0-beta.5
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 +17 -0
- package/build/browser/new/makeExternalStore.js +61 -0
- package/build/browser/new/makeExternalStore.js.map +1 -1
- package/build/browser/new/useLinks.js +2 -2
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useObjectSet.js +2 -2
- package/build/browser/new/useObjectSet.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +2 -2
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkAggregation.js +63 -27
- package/build/browser/new/useOsdkAggregation.js.map +1 -1
- package/build/browser/new/useOsdkFunction.js +10 -8
- package/build/browser/new/useOsdkFunction.js.map +1 -1
- package/build/browser/new/useOsdkObject.js +26 -24
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +16 -14
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/cjs/public/experimental.cjs +159 -71
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +34 -9
- package/build/esm/new/makeExternalStore.js +61 -0
- package/build/esm/new/makeExternalStore.js.map +1 -1
- package/build/esm/new/useLinks.js +2 -2
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useObjectSet.js +2 -2
- package/build/esm/new/useObjectSet.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +2 -2
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkAggregation.js +63 -27
- package/build/esm/new/useOsdkAggregation.js.map +1 -1
- package/build/esm/new/useOsdkFunction.js +10 -8
- package/build/esm/new/useOsdkFunction.js.map +1 -1
- package/build/esm/new/useOsdkObject.js +26 -24
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +16 -14
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/types/new/makeExternalStore.d.ts +11 -0
- package/build/types/new/makeExternalStore.d.ts.map +1 -1
- package/build/types/new/useOsdkAggregation.d.ts +41 -3
- package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
- package/build/types/new/useOsdkObject.d.ts +7 -7
- package/build/types/new/useOsdkObject.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -24,10 +24,10 @@ import { OsdkContext2 } from "./OsdkContext2.js";
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Loads an object by type and primary key.
|
|
27
|
+
* Loads an object or interface instance by type and primary key.
|
|
28
28
|
*
|
|
29
|
-
* @param type
|
|
30
|
-
* @param primaryKey
|
|
29
|
+
* @param type The object type or interface definition
|
|
30
|
+
* @param primaryKey The primary key of the object
|
|
31
31
|
* @param enabled Enable or disable the query (defaults to true)
|
|
32
32
|
*/
|
|
33
33
|
|
|
@@ -46,11 +46,10 @@ export function useOsdkObject(...args) {
|
|
|
46
46
|
|
|
47
47
|
// Extract enabled flag - 2nd param for instance signature, 3rd for type signature
|
|
48
48
|
const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
|
|
49
|
-
|
|
50
|
-
// TODO: Figure out what the correct default behavior is for the various scenarios
|
|
51
49
|
const mode = isInstanceSignature ? "offline" : undefined;
|
|
52
|
-
const
|
|
50
|
+
const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
|
|
53
51
|
const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
|
|
52
|
+
const apiNameString = typeof typeOrApiName === "string" ? typeOrApiName : typeOrApiName.apiName;
|
|
54
53
|
const {
|
|
55
54
|
subscribe,
|
|
56
55
|
getSnapShot
|
|
@@ -58,27 +57,30 @@ export function useOsdkObject(...args) {
|
|
|
58
57
|
if (!enabled) {
|
|
59
58
|
return makeExternalStore(() => ({
|
|
60
59
|
unsubscribe: () => {}
|
|
61
|
-
}), `object ${
|
|
60
|
+
}), `object ${apiNameString} ${primaryKey} [DISABLED]`);
|
|
62
61
|
}
|
|
63
|
-
return makeExternalStore(observer => observableClient.observeObject(
|
|
62
|
+
return makeExternalStore(observer => observableClient.observeObject(typeOrApiName, primaryKey, {
|
|
64
63
|
mode
|
|
65
|
-
}, observer), `object ${
|
|
66
|
-
}, [enabled, observableClient,
|
|
64
|
+
}, observer), `object ${apiNameString} ${primaryKey}`);
|
|
65
|
+
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode]);
|
|
67
66
|
const payload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
error
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
isOptimistic: !!payload?.isOptimistic,
|
|
78
|
-
error,
|
|
79
|
-
forceUpdate: () => {
|
|
80
|
-
throw new Error("not implemented");
|
|
67
|
+
const forceUpdate = React.useCallback(() => {
|
|
68
|
+
throw new Error("not implemented");
|
|
69
|
+
}, []);
|
|
70
|
+
return React.useMemo(() => {
|
|
71
|
+
let error;
|
|
72
|
+
if (payload && "error" in payload && payload.error) {
|
|
73
|
+
error = payload.error;
|
|
74
|
+
} else if (payload?.status === "error") {
|
|
75
|
+
error = new Error("Failed to load object");
|
|
81
76
|
}
|
|
82
|
-
|
|
77
|
+
return {
|
|
78
|
+
object: payload?.object,
|
|
79
|
+
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
80
|
+
isOptimistic: !!payload?.isOptimistic,
|
|
81
|
+
error,
|
|
82
|
+
forceUpdate
|
|
83
|
+
};
|
|
84
|
+
}, [payload, enabled, forceUpdate]);
|
|
83
85
|
}
|
|
84
86
|
//# sourceMappingURL=useOsdkObject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","mode","undefined","
|
|
1
|
+
{"version":3,"file":"useOsdkObject.js","names":["React","makeExternalStore","OsdkContext2","useOsdkObject","args","observableClient","useContext","isInstanceSignature","enabled","mode","undefined","typeOrApiName","$objectType","primaryKey","$primaryKey","apiNameString","apiName","subscribe","getSnapShot","useMemo","unsubscribe","observer","observeObject","payload","useSyncExternalStore","forceUpdate","useCallback","Error","error","status","object","isLoading","isOptimistic"],"sources":["useOsdkObject.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PrimaryKeyType,\n} from \"@osdk/api\";\nimport type { ObserveObjectCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectResult<\n Q extends ObjectOrInterfaceDefinition,\n> {\n object: Osdk.Instance<Q> | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n /**\n * Refers to whether the object is optimistic or not.\n */\n isOptimistic: boolean;\n forceUpdate: () => void;\n}\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n obj: Osdk.Instance<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/**\n * Loads an object or interface instance by type and primary key.\n *\n * @param type The object type or interface definition\n * @param primaryKey The primary key of the object\n * @param enabled Enable or disable the query (defaults to true)\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n type: Q,\n primaryKey: PrimaryKeyType<Q>,\n enabled?: boolean,\n): UseOsdkObjectResult<Q>;\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject<\n Q extends ObjectOrInterfaceDefinition,\n>(\n ...args:\n | [obj: Osdk.Instance<Q>, enabled?: boolean]\n | [type: Q, primaryKey: PrimaryKeyType<Q>, enabled?: boolean]\n): UseOsdkObjectResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n\n // Check if first arg is an instance to discriminate signatures\n // TypeScript cannot narrow rest parameter unions with optional parameters,\n // so we must use type assertions after runtime discrimination\n const isInstanceSignature = \"$objectType\" in args[0];\n\n // Extract enabled flag - 2nd param for instance signature, 3rd for type signature\n const enabled = isInstanceSignature\n ? (typeof args[1] === \"boolean\" ? args[1] : true)\n : (typeof args[2] === \"boolean\" ? args[2] : true);\n\n const mode = isInstanceSignature ? \"offline\" : undefined;\n\n const typeOrApiName = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$objectType\n : (args[0] as Q);\n\n const primaryKey = isInstanceSignature\n ? (args[0] as Osdk.Instance<Q>).$primaryKey\n : (args[1] as PrimaryKeyType<Q>);\n\n const apiNameString = typeof typeOrApiName === \"string\"\n ? typeOrApiName\n : typeOrApiName.apiName;\n\n const { subscribe, getSnapShot } = React.useMemo(\n () => {\n if (!enabled) {\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n () => ({ unsubscribe: () => {} }),\n `object ${apiNameString} ${primaryKey} [DISABLED]`,\n );\n }\n return makeExternalStore<ObserveObjectCallbackArgs<Q>>(\n (observer) =>\n observableClient.observeObject(\n typeOrApiName,\n primaryKey,\n {\n mode,\n },\n observer,\n ),\n `object ${apiNameString} ${primaryKey}`,\n );\n },\n [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode],\n );\n\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n const forceUpdate = React.useCallback(() => {\n throw new Error(\"not implemented\");\n }, []);\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 load object\");\n }\n\n return {\n object: payload?.object as Osdk.Instance<Q> | undefined,\n isLoading: enabled\n ? (payload?.status === \"loading\" || payload?.status === \"init\"\n || !payload)\n : false,\n isOptimistic: !!payload?.isOptimistic,\n error,\n forceUpdate,\n };\n }, [payload, enabled, forceUpdate]);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAiBhD;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAG3B,GAAGC,IAE4D,EACvC;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGL,KAAK,CAACM,UAAU,CAACJ,YAAY,CAAC;;EAE3D;EACA;EACA;EACA,MAAMK,mBAAmB,GAAG,aAAa,IAAIH,IAAI,CAAC,CAAC,CAAC;;EAEpD;EACA,MAAMI,OAAO,GAAGD,mBAAmB,GAC9B,OAAOH,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,GAAGA,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAC7C,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,GAAGA,IAAI,CAAC,CAAC,CAAC,GAAG,IAAK;EAEnD,MAAMK,IAAI,GAAGF,mBAAmB,GAAG,SAAS,GAAGG,SAAS;EAExD,MAAMC,aAAa,GAAGJ,mBAAmB,GACpCH,IAAI,CAAC,CAAC,CAAC,CAAsBQ,WAAW,GACxCR,IAAI,CAAC,CAAC,CAAO;EAElB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K,CAAC,uBAAuB,CAAC;IAC5C;IAEA,OAAO;MACLG,MAAM,EAAEP,OAAO,EAAEO,MAAsC;MACvDC,SAAS,EAAEvB,OAAO,GACbe,OAAO,EAAEM,MAAM,KAAK,SAAS,IAAIN,OAAO,EAAEM,MAAM,KAAK,MAAM,IACzD,CAACN,OAAO,GACX,KAAK;MACTS,YAAY,EAAE,CAAC,CAACT,OAAO,EAAES,YAAY;MACrCJ,KAAK;MACLH;IACF,CAAC;EACH,CAAC,EAAE,CAACF,OAAO,EAAEf,OAAO,EAAEiB,WAAW,CAAC,CAAC;AACrC","ignoreList":[]}
|
|
@@ -69,19 +69,21 @@ export function useOsdkObjects(type, options) {
|
|
|
69
69
|
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
70
70
|
}, [enabled, observableClient, type.apiName, type.type, stableRids, stableCanonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
|
|
71
71
|
const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
error
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
72
|
+
return React.useMemo(() => {
|
|
73
|
+
let error;
|
|
74
|
+
if (listPayload && "error" in listPayload && listPayload.error) {
|
|
75
|
+
error = listPayload.error;
|
|
76
|
+
} else if (listPayload?.status === "error") {
|
|
77
|
+
error = new Error("Failed to load objects");
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,
|
|
81
|
+
error,
|
|
82
|
+
data: listPayload?.resolvedList,
|
|
83
|
+
isLoading: enabled ? listPayload?.status === "loading" || listPayload?.status === "init" || !listPayload : false,
|
|
84
|
+
isOptimistic: listPayload?.isOptimistic ?? false,
|
|
85
|
+
totalCount: listPayload?.totalCount
|
|
86
|
+
};
|
|
87
|
+
}, [listPayload, enabled]);
|
|
86
88
|
}
|
|
87
89
|
//# 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","canonWhere","canonicalizeWhereClause","stableCanonWhere","useMemo","JSON","stringify","stableRids","stableWithProperties","stableIntersectWith","stableOrderBy","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","length","listPayload","useSyncExternalStore","error","status","Error","fetchMore","hasMore","undefined","data","resolvedList","isLoading","isOptimistic","totalCount"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Fetch objects by their RIDs (Resource Identifiers).\n * When provided, starts with a static objectset containing these RIDs.\n * Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.\n *\n * @example\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })\n *\n * @example\n * // Fetch specific objects by RID, filtered by status\n * useOsdkObjects(Employee, {\n * rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],\n * where: { status: 'active' }\n * })\n */\n rids?: readonly string[];\n\n /**\n * Standard OSDK Where clause with RDP support.\n * When used with `rids`, filters the RID set.\n * When used alone, filters all objects of the type.\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Sort results by one or more properties.\n */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /**\n * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<T, \"$allBaseProperties\", PropertyKeys<T>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\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 },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n{\n const { observableClient } = React.useContext(OsdkContext2);\n\n const {\n pageSize,\n dedupeIntervalMs,\n withProperties,\n enabled = true,\n rids,\n where,\n orderBy,\n streamUpdates,\n autoFetchMore,\n intersectWith,\n pivotTo,\n } = options ?? {};\n\n const canonWhere = observableClient.canonicalizeWhereClause<\n Q,\n RDPs\n >(where ?? 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 { 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 }, 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 ],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n let error: Error | undefined;\n if (listPayload && \"error\" in listPayload && listPayload.error) {\n error = listPayload.error;\n } else if (listPayload?.status === \"error\") {\n error = new Error(\"Failed to load objects\");\n }\n\n return {\n fetchMore: listPayload?.hasMore ? listPayload.fetchMore : undefined,\n error,\n data: listPayload?.resolvedList,\n isLoading: enabled\n ? (listPayload?.status === \"loading\" || listPayload?.status === \"init\"\n || !listPayload)\n : false,\n isOptimistic: listPayload?.isOptimistic ?? false,\n totalCount: listPayload?.totalCount,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyIhD,MAAMC,WAAW,GAAG,CAAC,CAAC;AAwBtB,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAI1C;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;EACF,CAAC,GAAGb,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAMc,UAAU,GAAGb,gBAAgB,CAACc,uBAAuB,CAGzDP,KAAK,IAAIX,WAAW,CAAC;EAEvB,MAAMmB,gBAAgB,GAAGtB,KAAK,CAACuB,OAAO,CACpC,MAAMH,UAAU,EAChB,CAACI,IAAI,CAACC,SAAS,CAACL,UAAU,CAAC,CAC7B,CAAC;EAED,MAAMM,UAAU,GAAG1B,KAAK,CAACuB,OAAO,CAC9B,MAAMV,IAAI,EACV,CA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"useOsdkObjects.js","names":["React","makeExternalStore","OsdkContext2","EMPTY_WHERE","useOsdkObjects","type","options","observableClient","useContext","pageSize","dedupeIntervalMs","withProperties","enabled","rids","where","orderBy","streamUpdates","autoFetchMore","intersectWith","pivotTo","canonWhere","canonicalizeWhereClause","stableCanonWhere","useMemo","JSON","stringify","stableRids","stableWithProperties","stableIntersectWith","stableOrderBy","subscribe","getSnapShot","unsubscribe","process","env","NODE_ENV","apiName","observer","observeList","dedupeInterval","length","listPayload","useSyncExternalStore","error","status","Error","fetchMore","hasMore","undefined","data","resolvedList","isLoading","isOptimistic","totalCount"],"sources":["useOsdkObjects.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n LinkedType,\n LinkNames,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ObserveObjectsCallbackArgs } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkObjectsOptions<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Fetch objects by their RIDs (Resource Identifiers).\n * When provided, starts with a static objectset containing these RIDs.\n * Can be combined with `where` to filter the RID set, and with `orderBy` to sort results.\n *\n * @example\n * // Fetch specific objects by RID\n * useOsdkObjects(Employee, { rids: ['ri.foo.123', 'ri.foo.456'] })\n *\n * @example\n * // Fetch specific objects by RID, filtered by status\n * useOsdkObjects(Employee, {\n * rids: ['ri.foo.123', 'ri.foo.456', 'ri.foo.789'],\n * where: { status: 'active' }\n * })\n */\n rids?: readonly string[];\n\n /**\n * Standard OSDK Where clause with RDP support.\n * When used with `rids`, filters the RID set.\n * When used alone, filters all objects of the type.\n */\n where?: WhereClause<T, RDPs>;\n\n /**\n * Sort results by one or more properties.\n */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /**\n * Define derived properties (RDPs) to be computed server-side and attached to each object.\n * These properties will be available on the returned objects alongside their regular properties.\n */\n withProperties?: { [K in keyof RDPs]: DerivedProperty.Creator<T, RDPs[K]> };\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkObjects` with the same parameters will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute. It will still\n * return any cached data, but will not fetch from the server.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * Intersect the results with additional object sets.\n * Each element defines a where clause for an object set to intersect with.\n * The final result will only include objects that match ALL conditions.\n */\n intersectWith?: Array<{\n where: WhereClause<T, RDPs>;\n }>;\n\n /**\n * Pivot to related objects through a link.\n * This changes the return type from T to the linked object type.\n */\n pivotTo?: LinkNames<T>;\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n *\n * - `true`: Fetch all available pages automatically\n * - `number`: Fetch pages until at least this many items are loaded\n * - `undefined` (default): Only fetch the first page, user must call fetchMore()\n */\n autoFetchMore?: boolean | number;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<\n T extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Function to fetch more pages (undefined if no more pages)\n */\n fetchMore: (() => Promise<void>) | undefined;\n\n /**\n * The fetched data with derived properties\n */\n data:\n | Osdk.Instance<T, \"$allBaseProperties\", PropertyKeys<T>, RDPs>[]\n | undefined;\n\n /**\n * Whether data is currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Any error that occurred during fetching\n */\n error: Error | undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n\n /**\n * The total count of objects matching the query (if available from the API)\n */\n totalCount?: string;\n}\n\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 },\n): UseOsdkListResult<LinkedType<Q, L>>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n): UseOsdkListResult<Q, RDPs>;\n\nexport function useOsdkObjects<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n type: Q,\n options?: UseOsdkObjectsOptions<Q, RDPs>,\n):\n | UseOsdkListResult<Q, RDPs>\n | UseOsdkListResult<LinkedType<Q, LinkNames<Q>>>\n{\n const { observableClient } = React.useContext(OsdkContext2);\n\n const {\n pageSize,\n dedupeIntervalMs,\n withProperties,\n enabled = true,\n rids,\n where,\n orderBy,\n streamUpdates,\n autoFetchMore,\n intersectWith,\n pivotTo,\n } = options ?? {};\n\n const canonWhere = observableClient.canonicalizeWhereClause<\n Q,\n RDPs\n >(where ?? 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 { 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 }, 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 ],\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;AAyIhD,MAAMC,WAAW,GAAG,CAAC,CAAC;AAwBtB,OAAO,SAASC,cAAcA,CAI5BC,IAAO,EACPC,OAAwC,EAI1C;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;EACF,CAAC,GAAGb,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAMc,UAAU,GAAGb,gBAAgB,CAACc,uBAAuB,CAGzDP,KAAK,IAAIX,WAAW,CAAC;EAEvB,MAAMmB,gBAAgB,GAAGtB,KAAK,CAACuB,OAAO,CACpC,MAAMH,UAAU,EAChB,CAACI,IAAI,CAACC,SAAS,CAACL,UAAU,CAAC,CAC7B,CAAC;EAED,MAAMM,UAAU,GAAG1B,KAAK,CAACuB,OAAO,CAC9B,MAAMV,IAAI,EACV,CAACW,IAAI,CAACC,SAAS,CAACZ,IAAI,CAAC,CACvB,CAAC;EAED,MAAMc,oBAAoB,GAAG3B,KAAK,CAACuB,OAAO,CACxC,MAAMZ,cAAc,EACpB,CAACa,IAAI,CAACC,SAAS,CAACd,cAAc,CAAC,CACjC,CAAC;EAED,MAAMiB,mBAAmB,GAAG5B,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K,CACX,CAAC;EACH,CAAC,EACD,CACEV,OAAO,EACPL,gBAAgB,EAChBF,IAAI,CAAC+B,OAAO,EACZ/B,IAAI,CAACA,IAAI,EACTqB,UAAU,EACVJ,gBAAgB,EAChBZ,gBAAgB,EAChBD,QAAQ,EACRoB,aAAa,EACbb,aAAa,EACbW,oBAAoB,EACpBV,aAAa,EACbW,mBAAmB,EACnBT,OAAO,CAEX,CAAC;EAED,MAAMsB,WAAW,GAAGzC,KAAK,CAAC0C,oBAAoB,CAACZ,SAAS,EAAEC,WAAW,CAAC;EAEtE,OAAO/B,KAAK,CAACuB,OAAO,CAAC,MAAM;IACzB,IAAIoB,KAAwB;IAC5B,IAAIF,WAAW,IAAI,OAAO,IAAIA,WAAW,IAAIA,WAAW,CAACE,KAAK,EAAE;MAC9DA,KAAK,GAAGF,WAAW,CAACE,KAAK;IAC3B,CAAC,MAAM,IAAIF,WAAW,EAAEG,MAAM,KAAK,OAAO,EAAE;MAC1CD,KAAK,GAAG,IAAIE,KAAK,CAAC,wBAAwB,CAAC;IAC7C;IAEA,OAAO;MACLC,SAAS,EAAEL,WAAW,EAAEM,OAAO,GAAGN,WAAW,CAACK,SAAS,GAAGE,SAAS;MACnEL,KAAK;MACLM,IAAI,EAAER,WAAW,EAAES,YAAY;MAC/BC,SAAS,EAAEvC,OAAO,GACb6B,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,EAAE7B,OAAO,CAAC,CAAC;AAC5B","ignoreList":[]}
|
|
@@ -71,6 +71,60 @@ function makeExternalStore(createObservation, _name, initialValue) {
|
|
|
71
71
|
getSnapShot
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
function makeExternalStoreAsync(createObservation, _name, initialValue) {
|
|
75
|
+
let lastResult = initialValue;
|
|
76
|
+
function getSnapShot() {
|
|
77
|
+
return lastResult;
|
|
78
|
+
}
|
|
79
|
+
function subscribe(notifyUpdate) {
|
|
80
|
+
let isActive = true;
|
|
81
|
+
let currentSubscription;
|
|
82
|
+
const subscriptionPromise = createObservation({
|
|
83
|
+
next: (payload) => {
|
|
84
|
+
if (isActive) {
|
|
85
|
+
lastResult = payload;
|
|
86
|
+
notifyUpdate();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
error: (error) => {
|
|
90
|
+
if (isActive) {
|
|
91
|
+
lastResult = {
|
|
92
|
+
...lastResult ?? {},
|
|
93
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
94
|
+
};
|
|
95
|
+
notifyUpdate();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
complete: () => {
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
subscriptionPromise.then((sub) => {
|
|
102
|
+
if (isActive) {
|
|
103
|
+
currentSubscription = sub;
|
|
104
|
+
} else {
|
|
105
|
+
sub.unsubscribe();
|
|
106
|
+
}
|
|
107
|
+
}).catch((error) => {
|
|
108
|
+
if (isActive) {
|
|
109
|
+
lastResult = {
|
|
110
|
+
...lastResult ?? {},
|
|
111
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
112
|
+
};
|
|
113
|
+
notifyUpdate();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return () => {
|
|
117
|
+
isActive = false;
|
|
118
|
+
if (currentSubscription) {
|
|
119
|
+
currentSubscription.unsubscribe();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
subscribe,
|
|
125
|
+
getSnapShot
|
|
126
|
+
};
|
|
127
|
+
}
|
|
74
128
|
|
|
75
129
|
// src/utils/usePlatformQuery.ts
|
|
76
130
|
function usePlatformQuery({
|
|
@@ -242,14 +296,14 @@ function useLinks(objects, linkName, options = {}) {
|
|
|
242
296
|
}, observer));
|
|
243
297
|
}, [enabled, observableClient, objectsArray, objectsKey, linkName, stableWhere, otherOptions.pageSize, stableOrderBy, otherOptions.mode, otherOptions.dedupeIntervalMs]);
|
|
244
298
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
245
|
-
return {
|
|
299
|
+
return React9__default.default.useMemo(() => ({
|
|
246
300
|
links: payload?.resolvedList,
|
|
247
301
|
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
248
302
|
isOptimistic: payload?.isOptimistic ?? false,
|
|
249
303
|
error: payload?.error,
|
|
250
304
|
fetchMore: payload?.hasMore ? payload?.fetchMore : void 0,
|
|
251
305
|
hasMore: payload?.hasMore ?? false
|
|
252
|
-
};
|
|
306
|
+
}), [payload, enabled]);
|
|
253
307
|
}
|
|
254
308
|
function useObjectSet(baseObjectSet, options = {}) {
|
|
255
309
|
const {
|
|
@@ -311,14 +365,14 @@ function useObjectSet(baseObjectSet, options = {}) {
|
|
|
311
365
|
previousPayloadRef.current = payload;
|
|
312
366
|
}
|
|
313
367
|
}, [payload]);
|
|
314
|
-
return {
|
|
368
|
+
return React9__default.default.useMemo(() => ({
|
|
315
369
|
data: payload?.resolvedList,
|
|
316
370
|
isLoading: payload?.status === "loading" || !payload && true || false,
|
|
317
371
|
error: payload && "error" in payload ? payload.error : void 0,
|
|
318
372
|
fetchMore: payload?.hasMore ? payload.fetchMore : void 0,
|
|
319
373
|
objectSet: payload?.objectSet || baseObjectSet,
|
|
320
374
|
totalCount: payload?.totalCount
|
|
321
|
-
};
|
|
375
|
+
}), [payload, baseObjectSet]);
|
|
322
376
|
}
|
|
323
377
|
function useOsdkAction(actionDef) {
|
|
324
378
|
const {
|
|
@@ -427,7 +481,7 @@ function useOsdkAction(actionDef) {
|
|
|
427
481
|
}
|
|
428
482
|
};
|
|
429
483
|
}, []);
|
|
430
|
-
return {
|
|
484
|
+
return React9__default.default.useMemo(() => ({
|
|
431
485
|
applyAction,
|
|
432
486
|
validateAction,
|
|
433
487
|
error,
|
|
@@ -435,48 +489,74 @@ function useOsdkAction(actionDef) {
|
|
|
435
489
|
isPending,
|
|
436
490
|
isValidating,
|
|
437
491
|
validationResult
|
|
438
|
-
};
|
|
492
|
+
}), [applyAction, validateAction, error, data, isPending, isValidating, validationResult]);
|
|
439
493
|
}
|
|
440
494
|
var EMPTY_WHERE = {};
|
|
441
|
-
function useOsdkAggregation(type, {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
495
|
+
function useOsdkAggregation(type, options) {
|
|
496
|
+
const {
|
|
497
|
+
where = EMPTY_WHERE,
|
|
498
|
+
withProperties,
|
|
499
|
+
intersectWith,
|
|
500
|
+
aggregate,
|
|
501
|
+
dedupeIntervalMs
|
|
502
|
+
} = options;
|
|
503
|
+
const objectSet = "objectSet" in options ? options.objectSet : void 0;
|
|
447
504
|
const {
|
|
448
505
|
observableClient
|
|
449
506
|
} = React9__default.default.useContext(OsdkContext2);
|
|
450
|
-
const canonWhere = observableClient.canonicalizeWhereClause(where
|
|
507
|
+
const canonWhere = observableClient.canonicalizeWhereClause(where);
|
|
451
508
|
const stableCanonWhere = React9__default.default.useMemo(() => canonWhere, [JSON.stringify(canonWhere)]);
|
|
509
|
+
const objectSetRef = React9__default.default.useRef(objectSet);
|
|
510
|
+
objectSetRef.current = objectSet;
|
|
511
|
+
const objectSetKeyString = objectSet ? unstableDoNotUse.computeObjectSetCacheKey(objectSet) : void 0;
|
|
452
512
|
const stableWithProperties = React9__default.default.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
453
513
|
const stableAggregate = React9__default.default.useMemo(() => aggregate, [JSON.stringify(aggregate)]);
|
|
514
|
+
const stableIntersectWith = React9__default.default.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
454
515
|
const {
|
|
455
516
|
subscribe,
|
|
456
517
|
getSnapShot
|
|
457
|
-
} = React9__default.default.useMemo(() =>
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
518
|
+
} = React9__default.default.useMemo(() => {
|
|
519
|
+
if (objectSetKeyString && objectSetRef.current) {
|
|
520
|
+
return makeExternalStoreAsync((observer) => observableClient.observeAggregation({
|
|
521
|
+
type,
|
|
522
|
+
objectSet: objectSetRef.current,
|
|
523
|
+
where: stableCanonWhere,
|
|
524
|
+
withProperties: stableWithProperties,
|
|
525
|
+
intersectWith: stableIntersectWith,
|
|
526
|
+
aggregate: stableAggregate,
|
|
527
|
+
dedupeInterval: dedupeIntervalMs ?? 2e3
|
|
528
|
+
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${objectSetKeyString} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
529
|
+
}
|
|
530
|
+
return makeExternalStore((observer) => (
|
|
531
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
532
|
+
observableClient.observeAggregation({
|
|
533
|
+
type,
|
|
534
|
+
where: stableCanonWhere,
|
|
535
|
+
withProperties: stableWithProperties,
|
|
536
|
+
intersectWith: stableIntersectWith,
|
|
537
|
+
aggregate: stableAggregate,
|
|
538
|
+
dedupeInterval: dedupeIntervalMs ?? 2e3
|
|
539
|
+
}, observer)
|
|
540
|
+
), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
541
|
+
}, [observableClient, type.apiName, type.type, objectSetKeyString, stableCanonWhere, stableWithProperties, stableIntersectWith, stableAggregate, dedupeIntervalMs]);
|
|
464
542
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
465
|
-
let error;
|
|
466
|
-
if (payload && "error" in payload && payload.error) {
|
|
467
|
-
error = payload.error;
|
|
468
|
-
} else if (payload?.status === "error") {
|
|
469
|
-
error = new Error("Failed to execute aggregation");
|
|
470
|
-
}
|
|
471
543
|
const refetch = React9__default.default.useCallback(async () => {
|
|
472
544
|
await observableClient.invalidateObjectType(type.apiName);
|
|
473
545
|
}, [observableClient, type.apiName]);
|
|
474
|
-
return {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
546
|
+
return React9__default.default.useMemo(() => {
|
|
547
|
+
let error;
|
|
548
|
+
if (payload && "error" in payload && payload.error) {
|
|
549
|
+
error = payload.error;
|
|
550
|
+
} else if (payload?.status === "error") {
|
|
551
|
+
error = new Error("Failed to execute aggregation");
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
data: payload?.result,
|
|
555
|
+
isLoading: payload?.status === "loading" || payload?.status === "init" || !payload,
|
|
556
|
+
error,
|
|
557
|
+
refetch
|
|
558
|
+
};
|
|
559
|
+
}, [payload, refetch]);
|
|
480
560
|
}
|
|
481
561
|
function useOsdkFunction(queryDef, options = {}) {
|
|
482
562
|
const {
|
|
@@ -515,17 +595,19 @@ function useOsdkFunction(queryDef, options = {}) {
|
|
|
515
595
|
}, observer), process.env.NODE_ENV !== "production" ? `function ${queryDef.apiName} ${JSON.stringify(stableParams)}` : void 0);
|
|
516
596
|
}, [observableClient, queryDef.apiName, queryDef.version, paramsForApi, stableDependsOn, stableDependsOnObjects, dedupeIntervalMs, enabled]);
|
|
517
597
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
518
|
-
const error = payload?.error ?? (payload?.status === "error" ? new Error("Failed to execute function") : void 0);
|
|
519
598
|
const refetch = React9__default.default.useCallback(() => {
|
|
520
599
|
void observableClient.invalidateFunction(queryDef, paramsForApi);
|
|
521
600
|
}, [observableClient, queryDef, paramsForApi]);
|
|
522
|
-
return {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
601
|
+
return React9__default.default.useMemo(() => {
|
|
602
|
+
const error = payload?.error ?? (payload?.status === "error" ? new Error("Failed to execute function") : void 0);
|
|
603
|
+
return {
|
|
604
|
+
data: payload?.result,
|
|
605
|
+
isLoading: payload?.status === "loading",
|
|
606
|
+
error,
|
|
607
|
+
lastUpdated: payload?.lastUpdated ?? 0,
|
|
608
|
+
refetch
|
|
609
|
+
};
|
|
610
|
+
}, [payload, refetch]);
|
|
529
611
|
}
|
|
530
612
|
function useOsdkObject(...args) {
|
|
531
613
|
const {
|
|
@@ -534,8 +616,9 @@ function useOsdkObject(...args) {
|
|
|
534
616
|
const isInstanceSignature = "$objectType" in args[0];
|
|
535
617
|
const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
|
|
536
618
|
const mode = isInstanceSignature ? "offline" : void 0;
|
|
537
|
-
const
|
|
619
|
+
const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
|
|
538
620
|
const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
|
|
621
|
+
const apiNameString = typeof typeOrApiName === "string" ? typeOrApiName : typeOrApiName.apiName;
|
|
539
622
|
const {
|
|
540
623
|
subscribe,
|
|
541
624
|
getSnapShot
|
|
@@ -546,26 +629,29 @@ function useOsdkObject(...args) {
|
|
|
546
629
|
}
|
|
547
630
|
}));
|
|
548
631
|
}
|
|
549
|
-
return makeExternalStore((observer) => observableClient.observeObject(
|
|
632
|
+
return makeExternalStore((observer) => observableClient.observeObject(typeOrApiName, primaryKey, {
|
|
550
633
|
mode
|
|
551
634
|
}, observer));
|
|
552
|
-
}, [enabled, observableClient,
|
|
635
|
+
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode]);
|
|
553
636
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
error
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
isOptimistic: !!payload?.isOptimistic,
|
|
564
|
-
error,
|
|
565
|
-
forceUpdate: () => {
|
|
566
|
-
throw new Error("not implemented");
|
|
637
|
+
const forceUpdate = React9__default.default.useCallback(() => {
|
|
638
|
+
throw new Error("not implemented");
|
|
639
|
+
}, []);
|
|
640
|
+
return React9__default.default.useMemo(() => {
|
|
641
|
+
let error;
|
|
642
|
+
if (payload && "error" in payload && payload.error) {
|
|
643
|
+
error = payload.error;
|
|
644
|
+
} else if (payload?.status === "error") {
|
|
645
|
+
error = new Error("Failed to load object");
|
|
567
646
|
}
|
|
568
|
-
|
|
647
|
+
return {
|
|
648
|
+
object: payload?.object,
|
|
649
|
+
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
650
|
+
isOptimistic: !!payload?.isOptimistic,
|
|
651
|
+
error,
|
|
652
|
+
forceUpdate
|
|
653
|
+
};
|
|
654
|
+
}, [payload, enabled, forceUpdate]);
|
|
569
655
|
}
|
|
570
656
|
var EMPTY_WHERE2 = {};
|
|
571
657
|
function useOsdkObjects(type, options) {
|
|
@@ -620,20 +706,22 @@ function useOsdkObjects(type, options) {
|
|
|
620
706
|
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
621
707
|
}, [enabled, observableClient, type.apiName, type.type, stableRids, stableCanonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
|
|
622
708
|
const listPayload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
error
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
709
|
+
return React9__default.default.useMemo(() => {
|
|
710
|
+
let error;
|
|
711
|
+
if (listPayload && "error" in listPayload && listPayload.error) {
|
|
712
|
+
error = listPayload.error;
|
|
713
|
+
} else if (listPayload?.status === "error") {
|
|
714
|
+
error = new Error("Failed to load objects");
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
fetchMore: listPayload?.hasMore ? listPayload.fetchMore : void 0,
|
|
718
|
+
error,
|
|
719
|
+
data: listPayload?.resolvedList,
|
|
720
|
+
isLoading: enabled ? listPayload?.status === "loading" || listPayload?.status === "init" || !listPayload : false,
|
|
721
|
+
isOptimistic: listPayload?.isOptimistic ?? false,
|
|
722
|
+
totalCount: listPayload?.totalCount
|
|
723
|
+
};
|
|
724
|
+
}, [listPayload, enabled]);
|
|
637
725
|
}
|
|
638
726
|
function useDebouncedCallback(callback, delay) {
|
|
639
727
|
const timeoutRef = React9__default.default.useRef();
|