@trpc/tanstack-react-query 11.3.1-canary.1 → 11.3.2-canary.2
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 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +442 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +21 -17
- package/dist/bundle-analysis.json +0 -128
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -11
- package/dist/internals/Context.d.ts +0 -21
- package/dist/internals/Context.d.ts.map +0 -1
- package/dist/internals/Context.js +0 -67
- package/dist/internals/Context.mjs +0 -46
- package/dist/internals/createOptionsProxy.d.ts +0 -161
- package/dist/internals/createOptionsProxy.d.ts.map +0 -1
- package/dist/internals/createOptionsProxy.js +0 -113
- package/dist/internals/createOptionsProxy.mjs +0 -111
- package/dist/internals/infiniteQueryOptions.d.ts +0 -61
- package/dist/internals/infiniteQueryOptions.d.ts.map +0 -1
- package/dist/internals/infiniteQueryOptions.js +0 -39
- package/dist/internals/infiniteQueryOptions.mjs +0 -37
- package/dist/internals/mutationOptions.d.ts +0 -43
- package/dist/internals/mutationOptions.d.ts.map +0 -1
- package/dist/internals/mutationOptions.js +0 -40
- package/dist/internals/mutationOptions.mjs +0 -38
- package/dist/internals/queryOptions.d.ts +0 -58
- package/dist/internals/queryOptions.d.ts.map +0 -1
- package/dist/internals/queryOptions.js +0 -43
- package/dist/internals/queryOptions.mjs +0 -41
- package/dist/internals/subscriptionOptions.d.ts +0 -73
- package/dist/internals/subscriptionOptions.d.ts.map +0 -1
- package/dist/internals/subscriptionOptions.js +0 -181
- package/dist/internals/subscriptionOptions.mjs +0 -159
- package/dist/internals/types.d.ts +0 -83
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/internals/utils.d.ts +0 -36
- package/dist/internals/utils.d.ts.map +0 -1
- package/dist/internals/utils.js +0 -118
- package/dist/internals/utils.mjs +0 -111
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
4
|
-
var React = require('react');
|
|
5
|
-
var utils = require('./utils.js');
|
|
6
|
-
|
|
7
|
-
function _interopNamespaceDefault(e) {
|
|
8
|
-
var n = Object.create(null);
|
|
9
|
-
if (e) {
|
|
10
|
-
Object.keys(e).forEach(function (k) {
|
|
11
|
-
if (k !== 'default') {
|
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/ const trpcSubscriptionOptions = (args)=>{
|
|
29
|
-
const { subscribe, path, queryKey, opts = {} } = args;
|
|
30
|
-
const input = queryKey[1]?.input;
|
|
31
|
-
const enabled = 'enabled' in opts ? !!opts.enabled : input !== reactQuery.skipToken;
|
|
32
|
-
const _subscribe = (innerOpts)=>{
|
|
33
|
-
return subscribe(path.join('.'), input ?? undefined, innerOpts);
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
...opts,
|
|
37
|
-
enabled,
|
|
38
|
-
subscribe: _subscribe,
|
|
39
|
-
queryKey,
|
|
40
|
-
trpc: utils.createTRPCOptionsResult({
|
|
41
|
-
path
|
|
42
|
-
})
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
function useSubscription(opts) {
|
|
46
|
-
const optsRef = React__namespace.useRef(opts);
|
|
47
|
-
optsRef.current = opts;
|
|
48
|
-
const trackedProps = React__namespace.useRef(new Set([]));
|
|
49
|
-
const addTrackedProp = React__namespace.useCallback((key)=>{
|
|
50
|
-
trackedProps.current.add(key);
|
|
51
|
-
}, []);
|
|
52
|
-
const currentSubscriptionRef = React__namespace.useRef(()=>{
|
|
53
|
-
// noop
|
|
54
|
-
});
|
|
55
|
-
const reset = React__namespace.useCallback(()=>{
|
|
56
|
-
// unsubscribe from the previous subscription
|
|
57
|
-
currentSubscriptionRef.current?.();
|
|
58
|
-
updateState(getInitialState);
|
|
59
|
-
if (!opts.enabled) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const subscription = opts.subscribe({
|
|
63
|
-
onStarted: ()=>{
|
|
64
|
-
optsRef.current.onStarted?.();
|
|
65
|
-
updateState((prev)=>({
|
|
66
|
-
...prev,
|
|
67
|
-
status: 'pending',
|
|
68
|
-
error: null
|
|
69
|
-
}));
|
|
70
|
-
},
|
|
71
|
-
onData: (data)=>{
|
|
72
|
-
optsRef.current.onData?.(data);
|
|
73
|
-
updateState((prev)=>({
|
|
74
|
-
...prev,
|
|
75
|
-
status: 'pending',
|
|
76
|
-
data,
|
|
77
|
-
error: null
|
|
78
|
-
}));
|
|
79
|
-
},
|
|
80
|
-
onError: (error)=>{
|
|
81
|
-
optsRef.current.onError?.(error);
|
|
82
|
-
updateState((prev)=>({
|
|
83
|
-
...prev,
|
|
84
|
-
status: 'error',
|
|
85
|
-
error
|
|
86
|
-
}));
|
|
87
|
-
},
|
|
88
|
-
onConnectionStateChange: (result)=>{
|
|
89
|
-
optsRef.current.onConnectionStateChange?.(result);
|
|
90
|
-
updateState((prev)=>{
|
|
91
|
-
switch(result.state){
|
|
92
|
-
case 'connecting':
|
|
93
|
-
return {
|
|
94
|
-
...prev,
|
|
95
|
-
status: 'connecting',
|
|
96
|
-
error: result.error
|
|
97
|
-
};
|
|
98
|
-
case 'pending':
|
|
99
|
-
// handled in onStarted
|
|
100
|
-
return prev;
|
|
101
|
-
case 'idle':
|
|
102
|
-
return {
|
|
103
|
-
...prev,
|
|
104
|
-
status: 'idle',
|
|
105
|
-
data: undefined,
|
|
106
|
-
error: null
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
currentSubscriptionRef.current = ()=>{
|
|
113
|
-
subscription.unsubscribe();
|
|
114
|
-
};
|
|
115
|
-
// eslint-disable-next-line react-hooks/react-compiler
|
|
116
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
-
}, [
|
|
118
|
-
reactQuery.hashKey(opts.queryKey),
|
|
119
|
-
opts.enabled
|
|
120
|
-
]);
|
|
121
|
-
const getInitialState = React__namespace.useCallback(()=>{
|
|
122
|
-
return opts.enabled ? {
|
|
123
|
-
data: undefined,
|
|
124
|
-
error: null,
|
|
125
|
-
status: 'connecting',
|
|
126
|
-
reset
|
|
127
|
-
} : {
|
|
128
|
-
data: undefined,
|
|
129
|
-
error: null,
|
|
130
|
-
status: 'idle',
|
|
131
|
-
reset
|
|
132
|
-
};
|
|
133
|
-
}, [
|
|
134
|
-
opts.enabled,
|
|
135
|
-
reset
|
|
136
|
-
]);
|
|
137
|
-
const resultRef = React__namespace.useRef(getInitialState());
|
|
138
|
-
const [state, setState] = React__namespace.useState(trackResult(resultRef.current, addTrackedProp));
|
|
139
|
-
state.reset = reset;
|
|
140
|
-
const updateState = React__namespace.useCallback((callback)=>{
|
|
141
|
-
const prev = resultRef.current;
|
|
142
|
-
const next = resultRef.current = callback(prev);
|
|
143
|
-
let shouldUpdate = false;
|
|
144
|
-
for (const key of trackedProps.current){
|
|
145
|
-
if (prev[key] !== next[key]) {
|
|
146
|
-
shouldUpdate = true;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (shouldUpdate) {
|
|
151
|
-
setState(trackResult(next, addTrackedProp));
|
|
152
|
-
}
|
|
153
|
-
}, [
|
|
154
|
-
addTrackedProp
|
|
155
|
-
]);
|
|
156
|
-
React__namespace.useEffect(()=>{
|
|
157
|
-
if (!opts.enabled) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
reset();
|
|
161
|
-
return ()=>{
|
|
162
|
-
currentSubscriptionRef.current?.();
|
|
163
|
-
};
|
|
164
|
-
}, [
|
|
165
|
-
reset,
|
|
166
|
-
opts.enabled
|
|
167
|
-
]);
|
|
168
|
-
return state;
|
|
169
|
-
}
|
|
170
|
-
function trackResult(result, onTrackResult) {
|
|
171
|
-
const trackedResult = new Proxy(result, {
|
|
172
|
-
get (target, prop) {
|
|
173
|
-
onTrackResult(prop);
|
|
174
|
-
return target[prop];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
return trackedResult;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
exports.trpcSubscriptionOptions = trpcSubscriptionOptions;
|
|
181
|
-
exports.useSubscription = useSubscription;
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { hashKey, skipToken } from '@tanstack/react-query';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { createTRPCOptionsResult } from './utils.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/ const trpcSubscriptionOptions = (args)=>{
|
|
8
|
-
const { subscribe, path, queryKey, opts = {} } = args;
|
|
9
|
-
const input = queryKey[1]?.input;
|
|
10
|
-
const enabled = 'enabled' in opts ? !!opts.enabled : input !== skipToken;
|
|
11
|
-
const _subscribe = (innerOpts)=>{
|
|
12
|
-
return subscribe(path.join('.'), input ?? undefined, innerOpts);
|
|
13
|
-
};
|
|
14
|
-
return {
|
|
15
|
-
...opts,
|
|
16
|
-
enabled,
|
|
17
|
-
subscribe: _subscribe,
|
|
18
|
-
queryKey,
|
|
19
|
-
trpc: createTRPCOptionsResult({
|
|
20
|
-
path
|
|
21
|
-
})
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
function useSubscription(opts) {
|
|
25
|
-
const optsRef = React.useRef(opts);
|
|
26
|
-
optsRef.current = opts;
|
|
27
|
-
const trackedProps = React.useRef(new Set([]));
|
|
28
|
-
const addTrackedProp = React.useCallback((key)=>{
|
|
29
|
-
trackedProps.current.add(key);
|
|
30
|
-
}, []);
|
|
31
|
-
const currentSubscriptionRef = React.useRef(()=>{
|
|
32
|
-
// noop
|
|
33
|
-
});
|
|
34
|
-
const reset = React.useCallback(()=>{
|
|
35
|
-
// unsubscribe from the previous subscription
|
|
36
|
-
currentSubscriptionRef.current?.();
|
|
37
|
-
updateState(getInitialState);
|
|
38
|
-
if (!opts.enabled) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const subscription = opts.subscribe({
|
|
42
|
-
onStarted: ()=>{
|
|
43
|
-
optsRef.current.onStarted?.();
|
|
44
|
-
updateState((prev)=>({
|
|
45
|
-
...prev,
|
|
46
|
-
status: 'pending',
|
|
47
|
-
error: null
|
|
48
|
-
}));
|
|
49
|
-
},
|
|
50
|
-
onData: (data)=>{
|
|
51
|
-
optsRef.current.onData?.(data);
|
|
52
|
-
updateState((prev)=>({
|
|
53
|
-
...prev,
|
|
54
|
-
status: 'pending',
|
|
55
|
-
data,
|
|
56
|
-
error: null
|
|
57
|
-
}));
|
|
58
|
-
},
|
|
59
|
-
onError: (error)=>{
|
|
60
|
-
optsRef.current.onError?.(error);
|
|
61
|
-
updateState((prev)=>({
|
|
62
|
-
...prev,
|
|
63
|
-
status: 'error',
|
|
64
|
-
error
|
|
65
|
-
}));
|
|
66
|
-
},
|
|
67
|
-
onConnectionStateChange: (result)=>{
|
|
68
|
-
optsRef.current.onConnectionStateChange?.(result);
|
|
69
|
-
updateState((prev)=>{
|
|
70
|
-
switch(result.state){
|
|
71
|
-
case 'connecting':
|
|
72
|
-
return {
|
|
73
|
-
...prev,
|
|
74
|
-
status: 'connecting',
|
|
75
|
-
error: result.error
|
|
76
|
-
};
|
|
77
|
-
case 'pending':
|
|
78
|
-
// handled in onStarted
|
|
79
|
-
return prev;
|
|
80
|
-
case 'idle':
|
|
81
|
-
return {
|
|
82
|
-
...prev,
|
|
83
|
-
status: 'idle',
|
|
84
|
-
data: undefined,
|
|
85
|
-
error: null
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
currentSubscriptionRef.current = ()=>{
|
|
92
|
-
subscription.unsubscribe();
|
|
93
|
-
};
|
|
94
|
-
// eslint-disable-next-line react-hooks/react-compiler
|
|
95
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
-
}, [
|
|
97
|
-
hashKey(opts.queryKey),
|
|
98
|
-
opts.enabled
|
|
99
|
-
]);
|
|
100
|
-
const getInitialState = React.useCallback(()=>{
|
|
101
|
-
return opts.enabled ? {
|
|
102
|
-
data: undefined,
|
|
103
|
-
error: null,
|
|
104
|
-
status: 'connecting',
|
|
105
|
-
reset
|
|
106
|
-
} : {
|
|
107
|
-
data: undefined,
|
|
108
|
-
error: null,
|
|
109
|
-
status: 'idle',
|
|
110
|
-
reset
|
|
111
|
-
};
|
|
112
|
-
}, [
|
|
113
|
-
opts.enabled,
|
|
114
|
-
reset
|
|
115
|
-
]);
|
|
116
|
-
const resultRef = React.useRef(getInitialState());
|
|
117
|
-
const [state, setState] = React.useState(trackResult(resultRef.current, addTrackedProp));
|
|
118
|
-
state.reset = reset;
|
|
119
|
-
const updateState = React.useCallback((callback)=>{
|
|
120
|
-
const prev = resultRef.current;
|
|
121
|
-
const next = resultRef.current = callback(prev);
|
|
122
|
-
let shouldUpdate = false;
|
|
123
|
-
for (const key of trackedProps.current){
|
|
124
|
-
if (prev[key] !== next[key]) {
|
|
125
|
-
shouldUpdate = true;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (shouldUpdate) {
|
|
130
|
-
setState(trackResult(next, addTrackedProp));
|
|
131
|
-
}
|
|
132
|
-
}, [
|
|
133
|
-
addTrackedProp
|
|
134
|
-
]);
|
|
135
|
-
React.useEffect(()=>{
|
|
136
|
-
if (!opts.enabled) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
reset();
|
|
140
|
-
return ()=>{
|
|
141
|
-
currentSubscriptionRef.current?.();
|
|
142
|
-
};
|
|
143
|
-
}, [
|
|
144
|
-
reset,
|
|
145
|
-
opts.enabled
|
|
146
|
-
]);
|
|
147
|
-
return state;
|
|
148
|
-
}
|
|
149
|
-
function trackResult(result, onTrackResult) {
|
|
150
|
-
const trackedResult = new Proxy(result, {
|
|
151
|
-
get (target, prop) {
|
|
152
|
-
onTrackResult(prop);
|
|
153
|
-
return target[prop];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
return trackedResult;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export { trpcSubscriptionOptions, useSubscription };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { InfiniteData } from '@tanstack/react-query';
|
|
2
|
-
import type { TRPCRequestOptions } from '@trpc/client';
|
|
3
|
-
/**
|
|
4
|
-
* Turn a set of optional properties into required
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export type WithRequired<TObj, TKey extends keyof TObj> = TObj & {
|
|
8
|
-
[P in TKey]-?: TObj[P];
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export type ResolverDef = {
|
|
14
|
-
input: any;
|
|
15
|
-
output: any;
|
|
16
|
-
transformer: boolean;
|
|
17
|
-
errorShape: any;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
21
|
-
*/
|
|
22
|
-
type CursorInput = {
|
|
23
|
-
cursor?: any;
|
|
24
|
-
};
|
|
25
|
-
export type OptionalCursorInput = CursorInput | void;
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
export type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
34
|
-
/**
|
|
35
|
-
* @public
|
|
36
|
-
*/
|
|
37
|
-
export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
38
|
-
/**
|
|
39
|
-
* Opt out of SSR for this query by passing `ssr: false`
|
|
40
|
-
*/
|
|
41
|
-
ssr?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Opt out or into aborting request on unmount
|
|
44
|
-
*/
|
|
45
|
-
abortOnUnmount?: boolean;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export interface TRPCQueryBaseOptions {
|
|
51
|
-
/**
|
|
52
|
-
* tRPC-related options
|
|
53
|
-
*/
|
|
54
|
-
trpc?: TRPCReactRequestOptions;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
export interface TRPCQueryOptionsResult {
|
|
60
|
-
trpc: {
|
|
61
|
-
path: string;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @public
|
|
66
|
-
*/
|
|
67
|
-
export type QueryType = 'any' | 'infinite' | 'query';
|
|
68
|
-
/**
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
export type TRPCQueryKey = [
|
|
72
|
-
readonly string[],
|
|
73
|
-
{
|
|
74
|
-
input?: unknown;
|
|
75
|
-
type?: Exclude<QueryType, 'any'>;
|
|
76
|
-
}?
|
|
77
|
-
];
|
|
78
|
-
/**
|
|
79
|
-
* @public
|
|
80
|
-
*/
|
|
81
|
-
export type TRPCMutationKey = [readonly string[]];
|
|
82
|
-
export {};
|
|
83
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,EAAE,IAAI,SAAS,MAAM,IAAI,IAAI,IAAI,GAAG;KAC9D,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,KAAK,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AACpC,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,MAAM,IAAI,MAAM,SAAS,WAAW,GAC9D,MAAM,CAAC,QAAQ,CAAC,GAChB,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,IAAI,YAAY,CAC1D,OAAO,EACP,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,uBAEf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,MAAM,EAAE;IACjB;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import type { QueryType, TRPCMutationKey, TRPCQueryKey, TRPCQueryOptionsResult } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export declare function createTRPCOptionsResult(value: {
|
|
7
|
-
path: readonly string[];
|
|
8
|
-
}): TRPCQueryOptionsResult['trpc'];
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export declare function getClientArgs<TOptions>(queryKey: TRPCQueryKey, opts: TOptions, infiniteParams?: {
|
|
13
|
-
pageParam: any;
|
|
14
|
-
direction: 'forward' | 'backward';
|
|
15
|
-
}): readonly [string, unknown, any];
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export declare function buildQueryFromAsyncIterable(asyncIterable: AsyncIterable<unknown>, queryClient: QueryClient, queryKey: TRPCQueryKey): Promise<unknown[]>;
|
|
20
|
-
/**
|
|
21
|
-
* To allow easy interactions with groups of related queries, such as
|
|
22
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
23
|
-
* storing in tanstack query.
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export declare function getQueryKeyInternal(path: readonly string[], input?: unknown, type?: QueryType): TRPCQueryKey;
|
|
28
|
-
/**
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export declare function getMutationKeyInternal(path: readonly string[]): TRPCMutationKey;
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
export declare function unwrapLazyArg<T>(valueOrLazy: T | (() => T)): T;
|
|
36
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internals/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAMjC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EACpC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,EACd,cAAc,CAAC,EAAE;IACf,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;CACnC,mCAcF;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,EACrC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,YAAY,sBAsBvB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,CAAC,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,SAAS,GACf,YAAY,CA2Cd;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,eAAe,CAKjB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAE9D"}
|
package/dist/internals/utils.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
4
|
-
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/ function createTRPCOptionsResult(value) {
|
|
9
|
-
const path = value.path.join('.');
|
|
10
|
-
return {
|
|
11
|
-
path
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/ function getClientArgs(queryKey, opts, infiniteParams) {
|
|
17
|
-
const path = queryKey[0];
|
|
18
|
-
let input = queryKey[1]?.input;
|
|
19
|
-
if (infiniteParams) {
|
|
20
|
-
input = {
|
|
21
|
-
...input ?? {},
|
|
22
|
-
...infiniteParams.pageParam !== undefined ? {
|
|
23
|
-
cursor: infiniteParams.pageParam
|
|
24
|
-
} : {},
|
|
25
|
-
direction: infiniteParams.direction
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return [
|
|
29
|
-
path.join('.'),
|
|
30
|
-
input,
|
|
31
|
-
opts?.trpc
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @internal
|
|
36
|
-
*/ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
37
|
-
const queryCache = queryClient.getQueryCache();
|
|
38
|
-
const query = queryCache.build(queryClient, {
|
|
39
|
-
queryKey
|
|
40
|
-
});
|
|
41
|
-
query.setState({
|
|
42
|
-
data: [],
|
|
43
|
-
status: 'success'
|
|
44
|
-
});
|
|
45
|
-
const aggregate = [];
|
|
46
|
-
for await (const value of asyncIterable){
|
|
47
|
-
aggregate.push(value);
|
|
48
|
-
query.setState({
|
|
49
|
-
data: [
|
|
50
|
-
...aggregate
|
|
51
|
-
]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return aggregate;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* To allow easy interactions with groups of related queries, such as
|
|
58
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
59
|
-
* storing in tanstack query.
|
|
60
|
-
*
|
|
61
|
-
* @internal
|
|
62
|
-
*/ function getQueryKeyInternal(path, input, type) {
|
|
63
|
-
// Construct a query key that is easy to destructure and flexible for
|
|
64
|
-
// partial selecting etc.
|
|
65
|
-
// https://github.com/trpc/trpc/issues/3128
|
|
66
|
-
// some parts of the path may be dot-separated, split them up
|
|
67
|
-
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
68
|
-
if (!input && (!type || type === 'any')) {
|
|
69
|
-
// this matches also all mutations (see `getMutationKeyInternal`)
|
|
70
|
-
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
71
|
-
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
72
|
-
return splitPath.length ? [
|
|
73
|
-
splitPath
|
|
74
|
-
] : [];
|
|
75
|
-
}
|
|
76
|
-
if (type === 'infinite' && unstableCoreDoNotImport.isObject(input) && ('direction' in input || 'cursor' in input)) {
|
|
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
|
-
];
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/ function getMutationKeyInternal(path) {
|
|
101
|
-
// some parts of the path may be dot-separated, split them up
|
|
102
|
-
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
103
|
-
return splitPath.length ? [
|
|
104
|
-
splitPath
|
|
105
|
-
] : [];
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @internal
|
|
109
|
-
*/ function unwrapLazyArg(valueOrLazy) {
|
|
110
|
-
return unstableCoreDoNotImport.isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
exports.buildQueryFromAsyncIterable = buildQueryFromAsyncIterable;
|
|
114
|
-
exports.createTRPCOptionsResult = createTRPCOptionsResult;
|
|
115
|
-
exports.getClientArgs = getClientArgs;
|
|
116
|
-
exports.getMutationKeyInternal = getMutationKeyInternal;
|
|
117
|
-
exports.getQueryKeyInternal = getQueryKeyInternal;
|
|
118
|
-
exports.unwrapLazyArg = unwrapLazyArg;
|
package/dist/internals/utils.mjs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { skipToken } from '@tanstack/react-query';
|
|
2
|
-
import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/ function createTRPCOptionsResult(value) {
|
|
7
|
-
const path = value.path.join('.');
|
|
8
|
-
return {
|
|
9
|
-
path
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/ function getClientArgs(queryKey, opts, infiniteParams) {
|
|
15
|
-
const path = queryKey[0];
|
|
16
|
-
let input = queryKey[1]?.input;
|
|
17
|
-
if (infiniteParams) {
|
|
18
|
-
input = {
|
|
19
|
-
...input ?? {},
|
|
20
|
-
...infiniteParams.pageParam !== undefined ? {
|
|
21
|
-
cursor: infiniteParams.pageParam
|
|
22
|
-
} : {},
|
|
23
|
-
direction: infiniteParams.direction
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return [
|
|
27
|
-
path.join('.'),
|
|
28
|
-
input,
|
|
29
|
-
opts?.trpc
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
35
|
-
const queryCache = queryClient.getQueryCache();
|
|
36
|
-
const query = queryCache.build(queryClient, {
|
|
37
|
-
queryKey
|
|
38
|
-
});
|
|
39
|
-
query.setState({
|
|
40
|
-
data: [],
|
|
41
|
-
status: 'success'
|
|
42
|
-
});
|
|
43
|
-
const aggregate = [];
|
|
44
|
-
for await (const value of asyncIterable){
|
|
45
|
-
aggregate.push(value);
|
|
46
|
-
query.setState({
|
|
47
|
-
data: [
|
|
48
|
-
...aggregate
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return aggregate;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* To allow easy interactions with groups of related queries, such as
|
|
56
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
57
|
-
* storing in tanstack query.
|
|
58
|
-
*
|
|
59
|
-
* @internal
|
|
60
|
-
*/ function getQueryKeyInternal(path, input, type) {
|
|
61
|
-
// Construct a query key that is easy to destructure and flexible for
|
|
62
|
-
// partial selecting etc.
|
|
63
|
-
// https://github.com/trpc/trpc/issues/3128
|
|
64
|
-
// some parts of the path may be dot-separated, split them up
|
|
65
|
-
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
66
|
-
if (!input && (!type || type === 'any')) {
|
|
67
|
-
// this matches also all mutations (see `getMutationKeyInternal`)
|
|
68
|
-
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
69
|
-
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
70
|
-
return splitPath.length ? [
|
|
71
|
-
splitPath
|
|
72
|
-
] : [];
|
|
73
|
-
}
|
|
74
|
-
if (type === 'infinite' && isObject(input) && ('direction' in input || 'cursor' in input)) {
|
|
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
|
-
];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* @internal
|
|
98
|
-
*/ function getMutationKeyInternal(path) {
|
|
99
|
-
// some parts of the path may be dot-separated, split them up
|
|
100
|
-
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
101
|
-
return splitPath.length ? [
|
|
102
|
-
splitPath
|
|
103
|
-
] : [];
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* @internal
|
|
107
|
-
*/ function unwrapLazyArg(valueOrLazy) {
|
|
108
|
-
return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { buildQueryFromAsyncIterable, createTRPCOptionsResult, getClientArgs, getMutationKeyInternal, getQueryKeyInternal, unwrapLazyArg };
|