@trpc/tanstack-react-query 11.1.3-alpha-tmp-issues-6785.34 → 11.1.3-alpha-tmp-tsdown.23
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/_virtual/rolldown_runtime.js +30 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -10
- package/dist/index.js +6 -10
- package/dist/index.mjs +5 -3
- package/dist/internals/Context.d.mts +28 -0
- package/dist/internals/Context.d.mts.map +1 -0
- package/dist/internals/Context.d.ts +21 -14
- package/dist/internals/Context.d.ts.map +1 -1
- package/dist/internals/Context.js +42 -63
- package/dist/internals/Context.mjs +41 -41
- package/dist/internals/Context.mjs.map +1 -0
- package/dist/internals/createOptionsProxy.d.mts +161 -0
- package/dist/internals/createOptionsProxy.d.mts.map +1 -0
- package/dist/internals/createOptionsProxy.d.ts +141 -141
- package/dist/internals/createOptionsProxy.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.js +107 -109
- package/dist/internals/createOptionsProxy.mjs +106 -106
- package/dist/internals/createOptionsProxy.mjs.map +1 -0
- package/dist/internals/infiniteQueryOptions.d.mts +55 -0
- package/dist/internals/infiniteQueryOptions.d.mts.map +1 -0
- package/dist/internals/infiniteQueryOptions.d.ts +40 -46
- package/dist/internals/infiniteQueryOptions.d.ts.map +1 -1
- package/dist/internals/infiniteQueryOptions.js +28 -35
- package/dist/internals/infiniteQueryOptions.mjs +27 -32
- package/dist/internals/infiniteQueryOptions.mjs.map +1 -0
- package/dist/internals/mutationOptions.d.mts +34 -0
- package/dist/internals/mutationOptions.d.mts.map +1 -0
- package/dist/internals/mutationOptions.d.ts +25 -34
- package/dist/internals/mutationOptions.d.ts.map +1 -1
- package/dist/internals/mutationOptions.js +30 -36
- package/dist/internals/mutationOptions.mjs +30 -33
- package/dist/internals/mutationOptions.mjs.map +1 -0
- package/dist/internals/queryOptions.d.mts +46 -0
- package/dist/internals/queryOptions.d.mts.map +1 -0
- package/dist/internals/queryOptions.d.ts +37 -49
- package/dist/internals/queryOptions.d.ts.map +1 -1
- package/dist/internals/queryOptions.js +31 -39
- package/dist/internals/queryOptions.mjs +30 -36
- package/dist/internals/queryOptions.mjs.map +1 -0
- package/dist/internals/subscriptionOptions.d.mts +66 -0
- package/dist/internals/subscriptionOptions.d.mts.map +1 -0
- package/dist/internals/subscriptionOptions.d.ts +53 -60
- package/dist/internals/subscriptionOptions.d.ts.map +1 -1
- package/dist/internals/subscriptionOptions.js +123 -171
- package/dist/internals/subscriptionOptions.mjs +122 -149
- package/dist/internals/subscriptionOptions.mjs.map +1 -0
- package/dist/internals/types.d.mts +84 -0
- package/dist/internals/types.d.mts.map +1 -0
- package/dist/internals/types.d.ts +43 -42
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/internals/utils.js +70 -99
- package/dist/internals/utils.mjs +69 -96
- package/dist/internals/utils.mjs.map +1 -0
- package/package.json +20 -15
- package/src/internals/mutationOptions.ts +2 -2
- package/src/internals/queryOptions.ts +1 -1
- package/src/internals/subscriptionOptions.ts +1 -0
- package/dist/bundle-analysis.json +0 -128
- package/dist/index.d.ts.map +0 -1
- package/dist/internals/utils.d.ts +0 -36
- package/dist/internals/utils.d.ts.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { TRPCRequestOptions } from "@trpc/client";
|
|
2
|
+
import { InfiniteData } from "@tanstack/react-query";
|
|
3
|
+
|
|
4
|
+
//#region src/internals/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Turn a set of optional properties into required
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Turn a set of optional properties into required
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
type ResolverDef = {
|
|
18
|
+
input: any;
|
|
19
|
+
output: any;
|
|
20
|
+
transformer: boolean;
|
|
21
|
+
errorShape: any;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
25
|
+
*/
|
|
26
|
+
type CursorInput = {
|
|
27
|
+
cursor?: any;
|
|
28
|
+
};
|
|
29
|
+
type OptionalCursorInput = CursorInput | void;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
42
|
+
/**
|
|
43
|
+
* Opt out of SSR for this query by passing `ssr: false`
|
|
44
|
+
*/
|
|
45
|
+
ssr?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Opt out or into aborting request on unmount
|
|
48
|
+
*/
|
|
49
|
+
abortOnUnmount?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface TRPCQueryBaseOptions {
|
|
55
|
+
/**
|
|
56
|
+
* tRPC-related options
|
|
57
|
+
*/
|
|
58
|
+
trpc?: TRPCReactRequestOptions;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
interface TRPCQueryOptionsResult {
|
|
64
|
+
trpc: {
|
|
65
|
+
path: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
type QueryType = 'any' | 'infinite' | 'query';
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
type TRPCQueryKey = [readonly string[], {
|
|
76
|
+
input?: unknown;
|
|
77
|
+
type?: Exclude<QueryType, 'any'>;
|
|
78
|
+
}?];
|
|
79
|
+
/**
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
type TRPCMutationKey = [readonly string[]]; //#endregion
|
|
83
|
+
export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
|
|
84
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAOY,sCAAsC,QAAQ,eAClD,SAAS,KAAK,IADtB;;;;AACQ,KAMI,WAAA,GANJ;EAAI,KAAK,EAAA,GAAA;EAAI,MAAC,EAAA,GAAA;EAAC,WAAA,EAAA,OAAA;;;;AAMvB;;KAUK,WAAA;;AAHL,CAAA;AAIY,KAAA,mBAAA,GAAsB,WAAA,GAAW,IAAA;;;;AAKjC,KAAA,iBAAiB,CAAA,MAAA,CAAA,GAAW,MAAX,SAA0B,WAA1B,GACzB,MADyB,CAAA,QAAA,CAAA,GAAA,OAAA;;;;AACzB,KAMQ,gBANR,CAAA,MAAA,EAAA,OAAA,CAAA,GAM4C,YAN5C,CAOF,OAPE,EAQF,WARE,CAQU,iBARV,CAQ4B,MAR5B,CAAA,CAAA,GAAA,IAAA,CAAA;AAAM;;;UAcO,uBAAA,SAEP,KAAK;EAVH;;;EACH,GACuB,CAAA,EAAA,OAAA;EAAM;;;EAFsB,cAAA,CAAA,EAAA,OAAA;;;;AAQ5D;AAEE,UAce,oBAAA,CAdf;EAAA;;AAAY;SAkBL;;;AAJT;;UAUiB,sBAAA;;IAAA,IAAA,EAAA,MAAA;;;;AASjB;;KAAY,SAAA;;AAKZ;;AAEoC,KAFxB,YAAA,GAEwB,CAAS,SAAjB,MAAA,EAAA,EAAO;;SAAP,QAAQ;GAMpC;;;;KAAY,eAAA"}
|
|
@@ -1,83 +1,84 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { InfiniteData } from "@tanstack/react-query";
|
|
2
|
+
import { TRPCRequestOptions } from "@trpc/client";
|
|
3
|
+
|
|
4
|
+
//#region src/internals/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Turn a set of optional properties into required
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
3
9
|
/**
|
|
4
10
|
* Turn a set of optional properties into required
|
|
5
11
|
* @internal
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
[P in TKey]-?: TObj[P];
|
|
9
|
-
};
|
|
13
|
+
type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
|
|
10
14
|
/**
|
|
11
15
|
* @internal
|
|
12
16
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
type ResolverDef = {
|
|
18
|
+
input: any;
|
|
19
|
+
output: any;
|
|
20
|
+
transformer: boolean;
|
|
21
|
+
errorShape: any;
|
|
18
22
|
};
|
|
19
23
|
/**
|
|
20
24
|
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
21
25
|
*/
|
|
22
26
|
type CursorInput = {
|
|
23
|
-
|
|
27
|
+
cursor?: any;
|
|
24
28
|
};
|
|
25
|
-
|
|
29
|
+
type OptionalCursorInput = CursorInput | void;
|
|
26
30
|
/**
|
|
27
31
|
* @internal
|
|
28
32
|
*/
|
|
29
|
-
|
|
33
|
+
type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
30
34
|
/**
|
|
31
35
|
* @internal
|
|
32
36
|
*/
|
|
33
|
-
|
|
37
|
+
type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
34
38
|
/**
|
|
35
39
|
* @public
|
|
36
40
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
42
|
+
/**
|
|
43
|
+
* Opt out of SSR for this query by passing `ssr: false`
|
|
44
|
+
*/
|
|
45
|
+
ssr?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Opt out or into aborting request on unmount
|
|
48
|
+
*/
|
|
49
|
+
abortOnUnmount?: boolean;
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* @public
|
|
49
53
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
interface TRPCQueryBaseOptions {
|
|
55
|
+
/**
|
|
56
|
+
* tRPC-related options
|
|
57
|
+
*/
|
|
58
|
+
trpc?: TRPCReactRequestOptions;
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* @public
|
|
58
62
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
interface TRPCQueryOptionsResult {
|
|
64
|
+
trpc: {
|
|
65
|
+
path: string;
|
|
66
|
+
};
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
65
69
|
* @public
|
|
66
70
|
*/
|
|
67
|
-
|
|
71
|
+
type QueryType = 'any' | 'infinite' | 'query';
|
|
68
72
|
/**
|
|
69
73
|
* @public
|
|
70
74
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
type?: Exclude<QueryType, 'any'>;
|
|
76
|
-
}?
|
|
77
|
-
];
|
|
75
|
+
type TRPCQueryKey = [readonly string[], {
|
|
76
|
+
input?: unknown;
|
|
77
|
+
type?: Exclude<QueryType, 'any'>;
|
|
78
|
+
}?];
|
|
78
79
|
/**
|
|
79
80
|
* @public
|
|
80
81
|
*/
|
|
81
|
-
|
|
82
|
-
export {};
|
|
82
|
+
type TRPCMutationKey = [readonly string[]]; //#endregion
|
|
83
|
+
export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
|
|
83
84
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAOY,sCAAsC,QAAQ,eAClD,SAAS,KAAK,IADtB;;;;AACQ,KAMI,WAAA,GANJ;EAAI,KAAK,EAAA,GAAA;EAAI,MAAC,EAAA,GAAA;EAAC,WAAA,EAAA,OAAA;;;;AAMvB;;KAUK,WAAA;;AAHL,CAAA;AAIY,KAAA,mBAAA,GAAsB,WAAA,GAAW,IAAA;;;;AAKjC,KAAA,iBAAiB,CAAA,MAAA,CAAA,GAAW,MAAX,SAA0B,WAA1B,GACzB,MADyB,CAAA,QAAA,CAAA,GAAA,OAAA;;;;AACzB,KAMQ,gBANR,CAAA,MAAA,EAAA,OAAA,CAAA,GAM4C,YAN5C,CAOF,OAPE,EAQF,WARE,CAQU,iBARV,CAQ4B,MAR5B,CAAA,CAAA,GAAA,IAAA,CAAA;AAAM;;;UAcO,uBAAA,SAEP,KAAK;EAVH;;;EACH,GACuB,CAAA,EAAA,OAAA;EAAM;;;EAFsB,cAAA,CAAA,EAAA,OAAA;;;;AAQ5D;AAEE,UAce,oBAAA,CAdf;EAAA;;AAAY;SAkBL;;;AAJT;;UAUiB,sBAAA;;IAAA,IAAA,EAAA,MAAA;;;;AASjB;;KAAY,SAAA;;AAKZ;;AAEoC,KAFxB,YAAA,GAEwB,CAAS,SAAjB,MAAA,EAAA,EAAO;;SAAP,QAAQ;GAMpC;;;;KAAY,eAAA"}
|
package/dist/internals/utils.js
CHANGED
|
@@ -1,118 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
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"));
|
|
5
4
|
|
|
5
|
+
//#region src/internals/utils.ts
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function createTRPCOptionsResult(value) {
|
|
10
|
+
const path = value.path.join(".");
|
|
11
|
+
return { path };
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
input,
|
|
31
|
-
opts?.trpc
|
|
32
|
-
];
|
|
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
|
+
];
|
|
33
29
|
}
|
|
34
30
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...aggregate
|
|
51
|
-
]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return aggregate;
|
|
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;
|
|
55
46
|
}
|
|
56
47
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const { cursor: _, direction: __, ...inputWithoutCursorAndDirection } = input;
|
|
78
|
-
return [
|
|
79
|
-
splitPath,
|
|
80
|
-
{
|
|
81
|
-
input: inputWithoutCursorAndDirection,
|
|
82
|
-
type: 'infinite'
|
|
83
|
-
}
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
return [
|
|
87
|
-
splitPath,
|
|
88
|
-
{
|
|
89
|
-
...typeof input !== 'undefined' && input !== reactQuery.skipToken && {
|
|
90
|
-
input: input
|
|
91
|
-
},
|
|
92
|
-
...type && type !== 'any' && {
|
|
93
|
-
type: type
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
];
|
|
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
|
+
}];
|
|
97
68
|
}
|
|
98
69
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
splitPath
|
|
105
|
-
] : [];
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
function getMutationKeyInternal(path) {
|
|
73
|
+
const splitPath = path.flatMap((part) => part.split("."));
|
|
74
|
+
return splitPath.length ? [splitPath] : [];
|
|
106
75
|
}
|
|
107
76
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
function unwrapLazyArg(valueOrLazy) {
|
|
80
|
+
return (0, __trpc_server_unstable_core_do_not_import.isFunction)(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
111
81
|
}
|
|
112
82
|
|
|
83
|
+
//#endregion
|
|
113
84
|
exports.buildQueryFromAsyncIterable = buildQueryFromAsyncIterable;
|
|
114
85
|
exports.createTRPCOptionsResult = createTRPCOptionsResult;
|
|
115
86
|
exports.getClientArgs = getClientArgs;
|
|
116
87
|
exports.getMutationKeyInternal = getMutationKeyInternal;
|
|
117
88
|
exports.getQueryKeyInternal = getQueryKeyInternal;
|
|
118
|
-
exports.unwrapLazyArg = unwrapLazyArg;
|
|
89
|
+
exports.unwrapLazyArg = unwrapLazyArg;
|
package/dist/internals/utils.mjs
CHANGED
|
@@ -1,111 +1,84 @@
|
|
|
1
|
-
import { skipToken } from
|
|
2
|
-
import {
|
|
1
|
+
import { skipToken } from "@tanstack/react-query";
|
|
2
|
+
import { isFunction, isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
3
3
|
|
|
4
|
+
//#region src/internals/utils.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
function createTRPCOptionsResult(value) {
|
|
9
|
+
const path = value.path.join(".");
|
|
10
|
+
return { path };
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
input,
|
|
29
|
-
opts?.trpc
|
|
30
|
-
];
|
|
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
|
+
];
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
...aggregate
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return aggregate;
|
|
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;
|
|
53
45
|
}
|
|
54
46
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const { cursor: _, direction: __, ...inputWithoutCursorAndDirection } = input;
|
|
76
|
-
return [
|
|
77
|
-
splitPath,
|
|
78
|
-
{
|
|
79
|
-
input: inputWithoutCursorAndDirection,
|
|
80
|
-
type: 'infinite'
|
|
81
|
-
}
|
|
82
|
-
];
|
|
83
|
-
}
|
|
84
|
-
return [
|
|
85
|
-
splitPath,
|
|
86
|
-
{
|
|
87
|
-
...typeof input !== 'undefined' && input !== skipToken && {
|
|
88
|
-
input: input
|
|
89
|
-
},
|
|
90
|
-
...type && type !== 'any' && {
|
|
91
|
-
type: type
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
];
|
|
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
|
+
}];
|
|
95
67
|
}
|
|
96
68
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
splitPath
|
|
103
|
-
] : [];
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
function getMutationKeyInternal(path) {
|
|
72
|
+
const splitPath = path.flatMap((part) => part.split("."));
|
|
73
|
+
return splitPath.length ? [splitPath] : [];
|
|
104
74
|
}
|
|
105
75
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
function unwrapLazyArg(valueOrLazy) {
|
|
79
|
+
return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
109
80
|
}
|
|
110
81
|
|
|
82
|
+
//#endregion
|
|
111
83
|
export { buildQueryFromAsyncIterable, createTRPCOptionsResult, getClientArgs, getMutationKeyInternal, getQueryKeyInternal, unwrapLazyArg };
|
|
84
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|