-
Notifications
You must be signed in to change notification settings - Fork 725
Expand file tree
/
Copy pathpreloaded.ts
More file actions
29 lines (28 loc) · 879 Bytes
/
preloaded.ts
File metadata and controls
29 lines (28 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {
FunctionArgs,
FunctionReference,
makeFunctionReference,
} from "../server/api.js";
import { jsonToConvex } from "../values/index.js";
import type { Preloaded } from "./hydration.js";
/**
* Parse a preloaded query payload into its constituent parts.
*
* This is a hook-free helper that can be used by both `useQuery` and
* `usePreloadedQuery` to avoid duplicating the parsing logic.
*
* @internal
*/
export function parsePreloaded<Query extends FunctionReference<"query">>(
preloaded: Preloaded<Query>,
): {
queryReference: Query;
argsObject: FunctionArgs<Query>;
preloadedResult: Query["_returnType"];
} {
return {
queryReference: makeFunctionReference(preloaded._name) as Query,
argsObject: jsonToConvex(preloaded._argsJSON) as FunctionArgs<Query>,
preloadedResult: jsonToConvex(preloaded._valueJSON) as Query["_returnType"],
};
}