@trpc/tanstack-react-query 11.1.3-alpha-tmp-tsdown.24 → 11.1.3-alpha-tmp-tsdown.26
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/dist/index.cjs +465 -0
- package/dist/index.d.cts +420 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +420 -8
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +441 -4
- package/dist/index.mjs.map +1 -0
- package/package.json +12 -11
- package/dist/_virtual/rolldown_runtime.js +0 -30
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -7
- package/dist/internals/Context.d.mts +0 -27
- package/dist/internals/Context.d.mts.map +0 -1
- package/dist/internals/Context.d.ts +0 -27
- package/dist/internals/Context.d.ts.map +0 -1
- package/dist/internals/Context.js +0 -46
- package/dist/internals/Context.mjs +0 -46
- package/dist/internals/Context.mjs.map +0 -1
- package/dist/internals/createOptionsProxy.d.mts +0 -160
- package/dist/internals/createOptionsProxy.d.mts.map +0 -1
- package/dist/internals/createOptionsProxy.d.ts +0 -160
- package/dist/internals/createOptionsProxy.d.ts.map +0 -1
- package/dist/internals/createOptionsProxy.js +0 -111
- package/dist/internals/createOptionsProxy.mjs +0 -111
- package/dist/internals/createOptionsProxy.mjs.map +0 -1
- package/dist/internals/infiniteQueryOptions.d.mts +0 -54
- package/dist/internals/infiniteQueryOptions.d.mts.map +0 -1
- package/dist/internals/infiniteQueryOptions.d.ts +0 -54
- package/dist/internals/infiniteQueryOptions.d.ts.map +0 -1
- package/dist/internals/infiniteQueryOptions.js +0 -32
- package/dist/internals/infiniteQueryOptions.mjs +0 -32
- package/dist/internals/infiniteQueryOptions.mjs.map +0 -1
- package/dist/internals/mutationOptions.d.mts +0 -33
- package/dist/internals/mutationOptions.d.mts.map +0 -1
- package/dist/internals/mutationOptions.d.ts +0 -33
- package/dist/internals/mutationOptions.d.ts.map +0 -1
- package/dist/internals/mutationOptions.js +0 -34
- package/dist/internals/mutationOptions.mjs +0 -35
- package/dist/internals/mutationOptions.mjs.map +0 -1
- package/dist/internals/queryOptions.d.mts +0 -45
- package/dist/internals/queryOptions.d.mts.map +0 -1
- package/dist/internals/queryOptions.d.ts +0 -45
- package/dist/internals/queryOptions.d.ts.map +0 -1
- package/dist/internals/queryOptions.js +0 -35
- package/dist/internals/queryOptions.mjs +0 -35
- package/dist/internals/queryOptions.mjs.map +0 -1
- package/dist/internals/subscriptionOptions.d.mts +0 -65
- package/dist/internals/subscriptionOptions.d.mts.map +0 -1
- package/dist/internals/subscriptionOptions.d.ts +0 -65
- package/dist/internals/subscriptionOptions.d.ts.map +0 -1
- package/dist/internals/subscriptionOptions.js +0 -132
- package/dist/internals/subscriptionOptions.mjs +0 -131
- package/dist/internals/subscriptionOptions.mjs.map +0 -1
- package/dist/internals/types.d.mts +0 -82
- package/dist/internals/types.d.mts.map +0 -1
- package/dist/internals/types.d.ts +0 -82
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/internals/utils.js +0 -89
- package/dist/internals/utils.mjs +0 -84
- package/dist/internals/utils.mjs.map +0 -1
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { TRPCRequestOptions } from "@trpc/client";
|
|
2
|
-
import { InfiniteData } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
//#region src/internals/types.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Turn a set of optional properties into required
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
type ResolverDef = {
|
|
15
|
-
input: any;
|
|
16
|
-
output: any;
|
|
17
|
-
transformer: boolean;
|
|
18
|
-
errorShape: any;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
22
|
-
*/
|
|
23
|
-
type CursorInput = {
|
|
24
|
-
cursor?: any;
|
|
25
|
-
};
|
|
26
|
-
type OptionalCursorInput = CursorInput | void;
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
35
|
-
/**
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
39
|
-
/**
|
|
40
|
-
* Opt out of SSR for this query by passing `ssr: false`
|
|
41
|
-
*/
|
|
42
|
-
ssr?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Opt out or into aborting request on unmount
|
|
45
|
-
*/
|
|
46
|
-
abortOnUnmount?: boolean;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
interface TRPCQueryBaseOptions {
|
|
52
|
-
/**
|
|
53
|
-
* tRPC-related options
|
|
54
|
-
*/
|
|
55
|
-
trpc?: TRPCReactRequestOptions;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @public
|
|
59
|
-
*/
|
|
60
|
-
interface TRPCQueryOptionsResult {
|
|
61
|
-
trpc: {
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @public
|
|
67
|
-
*/
|
|
68
|
-
type QueryType = 'any' | 'infinite' | 'query';
|
|
69
|
-
/**
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
type TRPCQueryKey = [readonly string[], {
|
|
73
|
-
input?: unknown;
|
|
74
|
-
type?: Exclude<QueryType, 'any'>;
|
|
75
|
-
}?];
|
|
76
|
-
/**
|
|
77
|
-
* @public
|
|
78
|
-
*/
|
|
79
|
-
type TRPCMutationKey = [readonly string[]];
|
|
80
|
-
//#endregion
|
|
81
|
-
export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
|
|
82
|
-
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAOA;;AAAkD,KAAtC,YAAsC,CAAA,IAAA,EAAA,aAAA,MAAA,IAAA,CAAA,GAAQ,IAAR,GAAA,QAC1C,IADkD,KACzC,IADyC,CACpC,CADoC,CAAA,EAAI;;;AACvC;AAMX,KAAA,WAAA,GAAW;EAUlB,KAAA,EAAA,GAAA;EACO,MAAA,EAAA,GAAA;EAKA,WAAA,EAAA,OAAiB;EAAA,UAAA,EAAA,GAAA;CAAA;;;AACnB;AAMV,KAbK,WAAA,GAaO;EAAgB,MAAA,CAAA,EAAA,GAAA;CAAA;AAEI,KAdpB,mBAAA,GAAsB,WAcF,GAAA,IAAA;;;;AAF4B,KAPhD,iBAOgD,CAAA,MAAA,CAAA,GAPpB,MAOoB,SAPL,WAOK,GANxD,MAMwD,CAAA,QAAA,CAAA,GAAA,OAAA;AAQ5D;;;AAEU,KAVE,gBAUF,CAAA,MAAA,EAAA,OAAA,CAAA,GAVsC,YAUtC,CATR,OASQ,EARR,WAQQ,CARI,iBAQJ,CARsB,MAQtB,CAAA,CAAA,GAAA,IAAA,CAAA;AAAI;AAcd;AAUA;AASY,UAnCK,uBAAA,SAEP,IAiCW,CAjCN,kBAiCM,EAAA,QAAA,CAAA,CAAA;EAKT;;;EAEiC,GAAjB,CAAA,EAAA,OAAA;EAAO;AAMnC;;;;;;;UAhCiB,oBAAA;;;;SAIR;;;;;UAMQ,sBAAA;;;;;;;;KASL,SAAA;;;;KAKA,YAAA;;SAEgB,QAAQ;;;;;KAMxB,eAAA"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { InfiniteData } from "@tanstack/react-query";
|
|
2
|
-
import { TRPCRequestOptions } from "@trpc/client";
|
|
3
|
-
|
|
4
|
-
//#region src/internals/types.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Turn a set of optional properties into required
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
type ResolverDef = {
|
|
15
|
-
input: any;
|
|
16
|
-
output: any;
|
|
17
|
-
transformer: boolean;
|
|
18
|
-
errorShape: any;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
22
|
-
*/
|
|
23
|
-
type CursorInput = {
|
|
24
|
-
cursor?: any;
|
|
25
|
-
};
|
|
26
|
-
type OptionalCursorInput = CursorInput | void;
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
35
|
-
/**
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
39
|
-
/**
|
|
40
|
-
* Opt out of SSR for this query by passing `ssr: false`
|
|
41
|
-
*/
|
|
42
|
-
ssr?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Opt out or into aborting request on unmount
|
|
45
|
-
*/
|
|
46
|
-
abortOnUnmount?: boolean;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
interface TRPCQueryBaseOptions {
|
|
52
|
-
/**
|
|
53
|
-
* tRPC-related options
|
|
54
|
-
*/
|
|
55
|
-
trpc?: TRPCReactRequestOptions;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @public
|
|
59
|
-
*/
|
|
60
|
-
interface TRPCQueryOptionsResult {
|
|
61
|
-
trpc: {
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @public
|
|
67
|
-
*/
|
|
68
|
-
type QueryType = 'any' | 'infinite' | 'query';
|
|
69
|
-
/**
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
type TRPCQueryKey = [readonly string[], {
|
|
73
|
-
input?: unknown;
|
|
74
|
-
type?: Exclude<QueryType, 'any'>;
|
|
75
|
-
}?];
|
|
76
|
-
/**
|
|
77
|
-
* @public
|
|
78
|
-
*/
|
|
79
|
-
type TRPCMutationKey = [readonly string[]];
|
|
80
|
-
//#endregion
|
|
81
|
-
export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
|
|
82
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAOA;;AAAkD,KAAtC,YAAsC,CAAA,IAAA,EAAA,aAAA,MAAA,IAAA,CAAA,GAAQ,IAAR,GAAA,QAC1C,IADkD,KACzC,IADyC,CACpC,CADoC,CAAA,EAAI;;;AACvC;AAMX,KAAA,WAAA,GAAW;EAUlB,KAAA,EAAA,GAAA;EACO,MAAA,EAAA,GAAA;EAKA,WAAA,EAAA,OAAiB;EAAA,UAAA,EAAA,GAAA;CAAA;;;AACnB;AAMV,KAbK,WAAA,GAaO;EAAgB,MAAA,CAAA,EAAA,GAAA;CAAA;AAEI,KAdpB,mBAAA,GAAsB,WAcF,GAAA,IAAA;;;;AAF4B,KAPhD,iBAOgD,CAAA,MAAA,CAAA,GAPpB,MAOoB,SAPL,WAOK,GANxD,MAMwD,CAAA,QAAA,CAAA,GAAA,OAAA;AAQ5D;;;AAEU,KAVE,gBAUF,CAAA,MAAA,EAAA,OAAA,CAAA,GAVsC,YAUtC,CATR,OASQ,EARR,WAQQ,CARI,iBAQJ,CARsB,MAQtB,CAAA,CAAA,GAAA,IAAA,CAAA;AAAI;AAcd;AAUA;AASY,UAnCK,uBAAA,SAEP,IAiCW,CAjCN,kBAiCM,EAAA,QAAA,CAAA,CAAA;EAKT;;;EAEiC,GAAjB,CAAA,EAAA,OAAA;EAAO;AAMnC;;;;;;;UAhCiB,oBAAA;;;;SAIR;;;;;UAMQ,sBAAA;;;;;;;;KASL,SAAA;;;;KAKA,YAAA;;SAEgB,QAAQ;;;;;KAMxB,eAAA"}
|
package/dist/internals/utils.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
-
const __tanstack_react_query = require_rolldown_runtime.__toESM(require("@tanstack/react-query"));
|
|
3
|
-
const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
4
|
-
|
|
5
|
-
//#region src/internals/utils.ts
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
function createTRPCOptionsResult(value) {
|
|
10
|
-
const path = value.path.join(".");
|
|
11
|
-
return { path };
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
function getClientArgs(queryKey, opts, infiniteParams) {
|
|
17
|
-
const path = queryKey[0];
|
|
18
|
-
let input = queryKey[1]?.input;
|
|
19
|
-
if (infiniteParams) input = {
|
|
20
|
-
...input ?? {},
|
|
21
|
-
...infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {},
|
|
22
|
-
direction: infiniteParams.direction
|
|
23
|
-
};
|
|
24
|
-
return [
|
|
25
|
-
path.join("."),
|
|
26
|
-
input,
|
|
27
|
-
opts?.trpc
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
34
|
-
const queryCache = queryClient.getQueryCache();
|
|
35
|
-
const query = queryCache.build(queryClient, { queryKey });
|
|
36
|
-
query.setState({
|
|
37
|
-
data: [],
|
|
38
|
-
status: "success"
|
|
39
|
-
});
|
|
40
|
-
const aggregate = [];
|
|
41
|
-
for await (const value of asyncIterable) {
|
|
42
|
-
aggregate.push(value);
|
|
43
|
-
query.setState({ data: [...aggregate] });
|
|
44
|
-
}
|
|
45
|
-
return aggregate;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* To allow easy interactions with groups of related queries, such as
|
|
49
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
50
|
-
* storing in tanstack query.
|
|
51
|
-
*
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
function getQueryKeyInternal(path, input, type) {
|
|
55
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
56
|
-
if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
|
|
57
|
-
if (type === "infinite" && (0, __trpc_server_unstable_core_do_not_import.isObject)(input) && ("direction" in input || "cursor" in input)) {
|
|
58
|
-
const { cursor: _, direction: __,...inputWithoutCursorAndDirection } = input;
|
|
59
|
-
return [splitPath, {
|
|
60
|
-
input: inputWithoutCursorAndDirection,
|
|
61
|
-
type: "infinite"
|
|
62
|
-
}];
|
|
63
|
-
}
|
|
64
|
-
return [splitPath, {
|
|
65
|
-
...typeof input !== "undefined" && input !== __tanstack_react_query.skipToken && { input },
|
|
66
|
-
...type && type !== "any" && { type }
|
|
67
|
-
}];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
function getMutationKeyInternal(path) {
|
|
73
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
74
|
-
return splitPath.length ? [splitPath] : [];
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
function unwrapLazyArg(valueOrLazy) {
|
|
80
|
-
return (0, __trpc_server_unstable_core_do_not_import.isFunction)(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
exports.buildQueryFromAsyncIterable = buildQueryFromAsyncIterable;
|
|
85
|
-
exports.createTRPCOptionsResult = createTRPCOptionsResult;
|
|
86
|
-
exports.getClientArgs = getClientArgs;
|
|
87
|
-
exports.getMutationKeyInternal = getMutationKeyInternal;
|
|
88
|
-
exports.getQueryKeyInternal = getQueryKeyInternal;
|
|
89
|
-
exports.unwrapLazyArg = unwrapLazyArg;
|
package/dist/internals/utils.mjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { skipToken } from "@tanstack/react-query";
|
|
2
|
-
import { isFunction, isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
3
|
-
|
|
4
|
-
//#region src/internals/utils.ts
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
function createTRPCOptionsResult(value) {
|
|
9
|
-
const path = value.path.join(".");
|
|
10
|
-
return { path };
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
function getClientArgs(queryKey, opts, infiniteParams) {
|
|
16
|
-
const path = queryKey[0];
|
|
17
|
-
let input = queryKey[1]?.input;
|
|
18
|
-
if (infiniteParams) input = {
|
|
19
|
-
...input ?? {},
|
|
20
|
-
...infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {},
|
|
21
|
-
direction: infiniteParams.direction
|
|
22
|
-
};
|
|
23
|
-
return [
|
|
24
|
-
path.join("."),
|
|
25
|
-
input,
|
|
26
|
-
opts?.trpc
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
33
|
-
const queryCache = queryClient.getQueryCache();
|
|
34
|
-
const query = queryCache.build(queryClient, { queryKey });
|
|
35
|
-
query.setState({
|
|
36
|
-
data: [],
|
|
37
|
-
status: "success"
|
|
38
|
-
});
|
|
39
|
-
const aggregate = [];
|
|
40
|
-
for await (const value of asyncIterable) {
|
|
41
|
-
aggregate.push(value);
|
|
42
|
-
query.setState({ data: [...aggregate] });
|
|
43
|
-
}
|
|
44
|
-
return aggregate;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* To allow easy interactions with groups of related queries, such as
|
|
48
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
49
|
-
* storing in tanstack query.
|
|
50
|
-
*
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
function getQueryKeyInternal(path, input, type) {
|
|
54
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
55
|
-
if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
|
|
56
|
-
if (type === "infinite" && isObject(input) && ("direction" in input || "cursor" in input)) {
|
|
57
|
-
const { cursor: _, direction: __,...inputWithoutCursorAndDirection } = input;
|
|
58
|
-
return [splitPath, {
|
|
59
|
-
input: inputWithoutCursorAndDirection,
|
|
60
|
-
type: "infinite"
|
|
61
|
-
}];
|
|
62
|
-
}
|
|
63
|
-
return [splitPath, {
|
|
64
|
-
...typeof input !== "undefined" && input !== skipToken && { input },
|
|
65
|
-
...type && type !== "any" && { type }
|
|
66
|
-
}];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
function getMutationKeyInternal(path) {
|
|
72
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
73
|
-
return splitPath.length ? [splitPath] : [];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
function unwrapLazyArg(valueOrLazy) {
|
|
79
|
-
return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
export { buildQueryFromAsyncIterable, createTRPCOptionsResult, getClientArgs, getMutationKeyInternal, getQueryKeyInternal, unwrapLazyArg };
|
|
84
|
-
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["value: {\n path: readonly string[];\n}","queryKey: TRPCQueryKey","opts: TOptions","infiniteParams?: {\n pageParam: any;\n direction: 'forward' | 'backward';\n }","asyncIterable: AsyncIterable<unknown>","queryClient: QueryClient","aggregate: unknown[]","path: readonly string[]","input?: unknown","type?: QueryType","valueOrLazy: T | (() => T)"],"sources":["../../src/internals/utils.ts"],"sourcesContent":["import { skipToken, type QueryClient } from '@tanstack/react-query';\nimport { isFunction, isObject } from '@trpc/server/unstable-core-do-not-import';\nimport type {\n QueryType,\n TRPCMutationKey,\n TRPCQueryKey,\n TRPCQueryOptionsResult,\n} from './types';\n\n/**\n * @internal\n */\nexport function createTRPCOptionsResult(value: {\n path: readonly string[];\n}): TRPCQueryOptionsResult['trpc'] {\n const path = value.path.join('.');\n\n return {\n path,\n };\n}\n\n/**\n * @internal\n */\nexport function getClientArgs<TOptions>(\n queryKey: TRPCQueryKey,\n opts: TOptions,\n infiniteParams?: {\n pageParam: any;\n direction: 'forward' | 'backward';\n },\n) {\n const path = queryKey[0];\n let input = queryKey[1]?.input;\n if (infiniteParams) {\n input = {\n ...(input ?? {}),\n ...(infiniteParams.pageParam !== undefined\n ? { cursor: infiniteParams.pageParam }\n : {}),\n direction: infiniteParams.direction,\n };\n }\n return [path.join('.'), input, (opts as any)?.trpc] as const;\n}\n\n/**\n * @internal\n */\nexport async function buildQueryFromAsyncIterable(\n asyncIterable: AsyncIterable<unknown>,\n queryClient: QueryClient,\n queryKey: TRPCQueryKey,\n) {\n const queryCache = queryClient.getQueryCache();\n\n const query = queryCache.build(queryClient, {\n queryKey,\n });\n\n query.setState({\n data: [],\n status: 'success',\n });\n\n const aggregate: unknown[] = [];\n for await (const value of asyncIterable) {\n aggregate.push(value);\n\n query.setState({\n data: [...aggregate],\n });\n }\n return aggregate;\n}\n\n/**\n * To allow easy interactions with groups of related queries, such as\n * invalidating all queries of a router, we use an array as the path when\n * storing in tanstack query.\n *\n * @internal\n */\nexport function getQueryKeyInternal(\n path: readonly string[],\n input?: unknown,\n type?: QueryType,\n): TRPCQueryKey {\n // Construct a query key that is easy to destructure and flexible for\n // partial selecting etc.\n // https://github.com/trpc/trpc/issues/3128\n\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n if (!input && (!type || type === 'any')) {\n // this matches also all mutations (see `getMutationKeyInternal`)\n\n // for `utils.invalidate()` to match all queries (including vanilla react-query)\n // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);\n }\n\n if (\n type === 'infinite' &&\n isObject(input) &&\n ('direction' in input || 'cursor' in input)\n ) {\n const {\n cursor: _,\n direction: __,\n ...inputWithoutCursorAndDirection\n } = input;\n return [\n splitPath,\n {\n input: inputWithoutCursorAndDirection,\n type: 'infinite',\n },\n ];\n }\n\n return [\n splitPath,\n {\n ...(typeof input !== 'undefined' &&\n input !== skipToken && { input: input }),\n ...(type && type !== 'any' && { type: type }),\n },\n ];\n}\n\n/**\n * @internal\n */\nexport function getMutationKeyInternal(\n path: readonly string[],\n): TRPCMutationKey {\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCMutationKey);\n}\n\n/**\n * @internal\n */\nexport function unwrapLazyArg<T>(valueOrLazy: T | (() => T)): T {\n return (isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy) as T;\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,wBAAwBA,OAEL;CACjC,MAAM,OAAO,MAAM,KAAK,KAAK,IAAI;AAEjC,QAAO,EACL,KACD;AACF;;;;AAKD,SAAgB,cACdC,UACAC,MACAC,gBAIA;CACA,MAAM,OAAO,SAAS;CACtB,IAAI,QAAQ,SAAS,IAAI;AACzB,KAAI,eACF,SAAQ;EACN,GAAI,SAAS,CAAE;EACf,GAAI,eAAe,uBACf,EAAE,QAAQ,eAAe,UAAW,IACpC,CAAE;EACN,WAAW,eAAe;CAC3B;AAEH,QAAO;EAAC,KAAK,KAAK,IAAI;EAAE;EAAQ,MAAc;CAAK;AACpD;;;;AAKD,eAAsB,4BACpBC,eACAC,aACAJ,UACA;CACA,MAAM,aAAa,YAAY,eAAe;CAE9C,MAAM,QAAQ,WAAW,MAAM,aAAa,EAC1C,SACD,EAAC;AAEF,OAAM,SAAS;EACb,MAAM,CAAE;EACR,QAAQ;CACT,EAAC;CAEF,MAAMK,YAAuB,CAAE;AAC/B,YAAW,MAAM,SAAS,eAAe;AACvC,YAAU,KAAK,MAAM;AAErB,QAAM,SAAS,EACb,MAAM,CAAC,GAAG,SAAU,EACrB,EAAC;CACH;AACD,QAAO;AACR;;;;;;;;AASD,SAAgB,oBACdC,MACAC,OACAC,MACc;CAMd,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,CAAC;AAEzD,MAAK,WAAW,QAAQ,SAAS,OAK/B,QAAO,UAAU,SAAS,CAAC,SAAU,IAAI,CAAE;AAG7C,KACE,SAAS,cACT,SAAS,MAAM,KACd,eAAe,SAAS,YAAY,QACrC;EACA,MAAM,EACJ,QAAQ,GACR,WAAW,GACX,GAAG,gCACJ,GAAG;AACJ,SAAO,CACL,WACA;GACE,OAAO;GACP,MAAM;EACP,CACF;CACF;AAED,QAAO,CACL,WACA;EACE,UAAW,UAAU,eACnB,UAAU,aAAa,EAAS,MAAO;EACzC,GAAI,QAAQ,SAAS,SAAS,EAAQ,KAAM;CAC7C,CACF;AACF;;;;AAKD,SAAgB,uBACdF,MACiB;CAEjB,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,CAAC;AAEzD,QAAO,UAAU,SAAS,CAAC,SAAU,IAAI,CAAE;AAC5C;;;;AAKD,SAAgB,cAAiBG,aAA+B;AAC9D,QAAQ,WAAW,YAAY,GAAG,aAAa,GAAG;AACnD"}
|