@trpc/tanstack-react-query 11.18.1-canary.9 → 11.19.0
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 +172 -245
- package/dist/index.d.cts +7 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +161 -258
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/internals/Context.tsx +1 -4
- package/src/internals/createOptionsProxy.ts +11 -8
- package/src/internals/infiniteQueryOptions.ts +19 -11
- package/src/internals/mutationOptions.ts +3 -1
- package/src/internals/queryOptions.ts +18 -6
- package/src/internals/subscriptionOptions.ts +30 -18
- package/src/internals/types.ts +2 -4
package/dist/index.mjs
CHANGED
|
@@ -1,212 +1,141 @@
|
|
|
1
|
-
import * as React$1 from "react";
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import { TRPCUntypedClient, getUntypedClient } from "@trpc/client";
|
|
4
3
|
import { callTRPCProcedure, createTRPCRecursiveProxy } from "@trpc/server";
|
|
5
4
|
import { hashKey, infiniteQueryOptions, queryOptions, skipToken } from "@tanstack/react-query";
|
|
6
5
|
import { isAsyncIterable, isFunction, isObject, run } from "@trpc/server/unstable-core-do-not-import";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var __commonJS = (cb, mod) => function() {
|
|
17
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
-
};
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
21
|
-
key = keys[i];
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
-
get: ((k) => from[k]).bind(null, key),
|
|
24
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
32
|
-
}) : target, mod));
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js
|
|
36
|
-
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
37
|
-
function _typeof$2(o) {
|
|
38
|
-
"@babel/helpers - typeof";
|
|
39
|
-
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
40
|
-
return typeof o$1;
|
|
41
|
-
} : function(o$1) {
|
|
42
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
43
|
-
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
44
|
-
}
|
|
45
|
-
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
46
|
-
} });
|
|
47
|
-
|
|
6
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
7
|
+
function _typeof(o) {
|
|
8
|
+
"@babel/helpers - typeof";
|
|
9
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
10
|
+
return typeof o;
|
|
11
|
+
} : function(o) {
|
|
12
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
13
|
+
}, _typeof(o);
|
|
14
|
+
}
|
|
48
15
|
//#endregion
|
|
49
|
-
//#region
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
if ("object" != _typeof$1(i)) return i;
|
|
58
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
59
|
-
}
|
|
60
|
-
return ("string" === r ? String : Number)(t);
|
|
16
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
17
|
+
function toPrimitive(t, r) {
|
|
18
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
19
|
+
var e = t[Symbol.toPrimitive];
|
|
20
|
+
if (void 0 !== e) {
|
|
21
|
+
var i = e.call(t, r || "default");
|
|
22
|
+
if ("object" != _typeof(i)) return i;
|
|
23
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
61
24
|
}
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
25
|
+
return ("string" === r ? String : Number)(t);
|
|
26
|
+
}
|
|
65
27
|
//#endregion
|
|
66
|
-
//#region
|
|
67
|
-
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var i = toPrimitive(t, "string");
|
|
72
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
73
|
-
}
|
|
74
|
-
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
75
|
-
} });
|
|
76
|
-
|
|
28
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
29
|
+
function toPropertyKey(t) {
|
|
30
|
+
var i = toPrimitive(t, "string");
|
|
31
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
32
|
+
}
|
|
77
33
|
//#endregion
|
|
78
|
-
//#region
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}) : e[r] = t, e;
|
|
88
|
-
}
|
|
89
|
-
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
90
|
-
} });
|
|
91
|
-
|
|
34
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
35
|
+
function _defineProperty(e, r, t) {
|
|
36
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
37
|
+
value: t,
|
|
38
|
+
enumerable: !0,
|
|
39
|
+
configurable: !0,
|
|
40
|
+
writable: !0
|
|
41
|
+
}) : e[r] = t, e;
|
|
42
|
+
}
|
|
92
43
|
//#endregion
|
|
93
|
-
//#region
|
|
94
|
-
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
102
|
-
})), t.push.apply(t, o);
|
|
103
|
-
}
|
|
104
|
-
return t;
|
|
44
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectSpread2.js
|
|
45
|
+
function ownKeys(e, r) {
|
|
46
|
+
var t = Object.keys(e);
|
|
47
|
+
if (Object.getOwnPropertySymbols) {
|
|
48
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
49
|
+
r && (o = o.filter(function(r) {
|
|
50
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
51
|
+
})), t.push.apply(t, o);
|
|
105
52
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
function _objectSpread2(e) {
|
|
56
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
57
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
58
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
59
|
+
_defineProperty(e, r, t[r]);
|
|
60
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
61
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
62
|
+
});
|
|
116
63
|
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
64
|
+
return e;
|
|
65
|
+
}
|
|
120
66
|
//#endregion
|
|
121
|
-
//#region
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
t = "@@asyncIterator", o = "@@iterator";
|
|
129
|
-
}
|
|
130
|
-
throw new TypeError("Object is not async iterable");
|
|
67
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/asyncIterator.js
|
|
68
|
+
function _asyncIterator(r) {
|
|
69
|
+
var n, t, o, e = 2;
|
|
70
|
+
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
|
|
71
|
+
if (t && null != (n = r[t])) return n.call(r);
|
|
72
|
+
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
|
73
|
+
t = "@@asyncIterator", o = "@@iterator";
|
|
131
74
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this.s = r$1, this.n = r$1.next;
|
|
145
|
-
}, AsyncFromSyncIterator.prototype = {
|
|
146
|
-
s: null,
|
|
147
|
-
n: null,
|
|
148
|
-
next: function next() {
|
|
149
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
150
|
-
},
|
|
151
|
-
"return": function _return(r$1) {
|
|
152
|
-
var n = this.s["return"];
|
|
153
|
-
return void 0 === n ? Promise.resolve({
|
|
154
|
-
value: r$1,
|
|
155
|
-
done: !0
|
|
156
|
-
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
157
|
-
},
|
|
158
|
-
"throw": function _throw(r$1) {
|
|
159
|
-
var n = this.s["return"];
|
|
160
|
-
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
161
|
-
}
|
|
162
|
-
}, new AsyncFromSyncIterator(r);
|
|
75
|
+
throw new TypeError("Object is not async iterable");
|
|
76
|
+
}
|
|
77
|
+
function AsyncFromSyncIterator(r) {
|
|
78
|
+
function AsyncFromSyncIteratorContinuation(r) {
|
|
79
|
+
if (Object(r) !== r) return Promise.reject(/* @__PURE__ */ new TypeError(r + " is not an object."));
|
|
80
|
+
var n = r.done;
|
|
81
|
+
return Promise.resolve(r.value).then(function(r) {
|
|
82
|
+
return {
|
|
83
|
+
value: r,
|
|
84
|
+
done: n
|
|
85
|
+
};
|
|
86
|
+
});
|
|
163
87
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
88
|
+
return AsyncFromSyncIterator = function AsyncFromSyncIterator(r) {
|
|
89
|
+
this.s = r, this.n = r.next;
|
|
90
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
91
|
+
s: null,
|
|
92
|
+
n: null,
|
|
93
|
+
next: function next() {
|
|
94
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
95
|
+
},
|
|
96
|
+
"return": function _return(r) {
|
|
97
|
+
var n = this.s["return"];
|
|
98
|
+
return void 0 === n ? Promise.resolve({
|
|
99
|
+
value: r,
|
|
100
|
+
done: !0
|
|
101
|
+
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
102
|
+
},
|
|
103
|
+
"throw": function _throw(r) {
|
|
104
|
+
var n = this.s["return"];
|
|
105
|
+
return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
176
106
|
}
|
|
177
|
-
|
|
107
|
+
}, new AsyncFromSyncIterator(r);
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
111
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
112
|
+
if (null == r) return {};
|
|
113
|
+
var t = {};
|
|
114
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
115
|
+
if (e.includes(n)) continue;
|
|
116
|
+
t[n] = r[n];
|
|
178
117
|
}
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
118
|
+
return t;
|
|
119
|
+
}
|
|
182
120
|
//#endregion
|
|
183
|
-
//#region
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var
|
|
189
|
-
|
|
190
|
-
var s = Object.getOwnPropertySymbols(e);
|
|
191
|
-
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
192
|
-
}
|
|
193
|
-
return i;
|
|
121
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectWithoutProperties.js
|
|
122
|
+
function _objectWithoutProperties(e, t) {
|
|
123
|
+
if (null == e) return {};
|
|
124
|
+
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
125
|
+
if (Object.getOwnPropertySymbols) {
|
|
126
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
127
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
194
128
|
}
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
129
|
+
return i;
|
|
130
|
+
}
|
|
198
131
|
//#endregion
|
|
199
132
|
//#region src/internals/utils.ts
|
|
200
|
-
var import_objectSpread2$5 = __toESM(require_objectSpread2(), 1);
|
|
201
|
-
var import_asyncIterator = __toESM(require_asyncIterator(), 1);
|
|
202
|
-
var import_objectWithoutProperties = __toESM(require_objectWithoutProperties(), 1);
|
|
203
133
|
const _excluded = ["cursor", "direction"];
|
|
204
134
|
/**
|
|
205
135
|
* @internal
|
|
206
136
|
*/
|
|
207
137
|
function createTRPCOptionsResult(value) {
|
|
208
|
-
|
|
209
|
-
return { path };
|
|
138
|
+
return { path: value.path.join(".") };
|
|
210
139
|
}
|
|
211
140
|
function isPrefixedQueryKey(queryKey) {
|
|
212
141
|
return queryKey.length >= 3;
|
|
@@ -234,7 +163,7 @@ function getClientArgs(queryKey, opts, infiniteParams) {
|
|
|
234
163
|
let input = (_queryKeyData$args = queryKeyData.args) === null || _queryKeyData$args === void 0 ? void 0 : _queryKeyData$args.input;
|
|
235
164
|
if (infiniteParams) {
|
|
236
165
|
var _queryKeyData$args$in, _queryKeyData$args2;
|
|
237
|
-
input = (
|
|
166
|
+
input = _objectSpread2(_objectSpread2(_objectSpread2({}, (_queryKeyData$args$in = (_queryKeyData$args2 = queryKeyData.args) === null || _queryKeyData$args2 === void 0 ? void 0 : _queryKeyData$args2.input) !== null && _queryKeyData$args$in !== void 0 ? _queryKeyData$args$in : {}), infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {}), {}, { direction: infiniteParams.direction });
|
|
238
167
|
}
|
|
239
168
|
return [
|
|
240
169
|
queryKeyData.path.join("."),
|
|
@@ -246,8 +175,7 @@ function getClientArgs(queryKey, opts, infiniteParams) {
|
|
|
246
175
|
* @internal
|
|
247
176
|
*/
|
|
248
177
|
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
249
|
-
const
|
|
250
|
-
const query = queryCache.build(queryClient, { queryKey });
|
|
178
|
+
const query = queryClient.getQueryCache().build(queryClient, { queryKey });
|
|
251
179
|
query.setState({
|
|
252
180
|
data: [],
|
|
253
181
|
status: "success"
|
|
@@ -257,12 +185,10 @@ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey)
|
|
|
257
185
|
var _didIteratorError = false;
|
|
258
186
|
var _iteratorError;
|
|
259
187
|
try {
|
|
260
|
-
for (var _iterator = (
|
|
188
|
+
for (var _iterator = _asyncIterator(asyncIterable), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
261
189
|
const value = _step.value;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
query.setState({ data: [...aggregate] });
|
|
265
|
-
}
|
|
190
|
+
aggregate.push(value);
|
|
191
|
+
query.setState({ data: [...aggregate] });
|
|
266
192
|
}
|
|
267
193
|
} catch (err) {
|
|
268
194
|
_didIteratorError = true;
|
|
@@ -289,13 +215,13 @@ function getQueryKeyInternal(opts) {
|
|
|
289
215
|
const splitPath = opts.path.flatMap((part) => part.split("."));
|
|
290
216
|
if (!input && type === "any") return splitPath.length ? [splitPath] : [];
|
|
291
217
|
if (type === "infinite" && isObject(input) && ("direction" in input || "cursor" in input)) {
|
|
292
|
-
const { cursor: _, direction: __ } = input
|
|
218
|
+
const { cursor: _, direction: __ } = input;
|
|
293
219
|
return [splitPath, {
|
|
294
|
-
input:
|
|
220
|
+
input: _objectWithoutProperties(input, _excluded),
|
|
295
221
|
type: "infinite"
|
|
296
222
|
}];
|
|
297
223
|
}
|
|
298
|
-
return [splitPath, (
|
|
224
|
+
return [splitPath, _objectSpread2(_objectSpread2({}, typeof input !== "undefined" && input !== skipToken && { input }), type && type !== "any" && { type })];
|
|
299
225
|
});
|
|
300
226
|
if (opts.prefix) key.unshift([opts.prefix]);
|
|
301
227
|
return key;
|
|
@@ -314,33 +240,28 @@ function getMutationKeyInternal(opts) {
|
|
|
314
240
|
function unwrapLazyArg(valueOrLazy) {
|
|
315
241
|
return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
316
242
|
}
|
|
317
|
-
|
|
318
243
|
//#endregion
|
|
319
244
|
//#region src/internals/infiniteQueryOptions.ts
|
|
320
|
-
var import_objectSpread2$4 = __toESM(require_objectSpread2());
|
|
321
245
|
function trpcInfiniteQueryOptions(args) {
|
|
322
246
|
var _opts$initialCursor;
|
|
323
247
|
const { input, query, path, queryKey, opts } = args;
|
|
324
248
|
const inputIsSkipToken = input === skipToken;
|
|
325
249
|
const queryFn = async (queryFnContext) => {
|
|
326
250
|
var _opts$trpc;
|
|
327
|
-
const actualOpts = (
|
|
328
|
-
|
|
251
|
+
const actualOpts = _objectSpread2(_objectSpread2({}, opts), {}, { trpc: _objectSpread2(_objectSpread2({}, opts === null || opts === void 0 ? void 0 : opts.trpc), (opts === null || opts === void 0 || (_opts$trpc = opts.trpc) === null || _opts$trpc === void 0 ? void 0 : _opts$trpc.abortOnUnmount) ? { signal: queryFnContext.signal } : { signal: null }) });
|
|
252
|
+
return await query(...getClientArgs(queryKey, actualOpts, {
|
|
329
253
|
direction: queryFnContext.direction,
|
|
330
254
|
pageParam: queryFnContext.pageParam
|
|
331
255
|
}));
|
|
332
|
-
return result;
|
|
333
256
|
};
|
|
334
|
-
return Object.assign(infiniteQueryOptions((
|
|
257
|
+
return Object.assign(infiniteQueryOptions(_objectSpread2(_objectSpread2({}, opts !== null && opts !== void 0 ? opts : {}), {}, {
|
|
335
258
|
queryKey,
|
|
336
259
|
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
|
337
260
|
initialPageParam: (_opts$initialCursor = opts === null || opts === void 0 ? void 0 : opts.initialCursor) !== null && _opts$initialCursor !== void 0 ? _opts$initialCursor : input === null || input === void 0 ? void 0 : input.cursor
|
|
338
261
|
})), { trpc: createTRPCOptionsResult({ path }) });
|
|
339
262
|
}
|
|
340
|
-
|
|
341
263
|
//#endregion
|
|
342
264
|
//#region src/internals/mutationOptions.ts
|
|
343
|
-
var import_objectSpread2$3 = __toESM(require_objectSpread2());
|
|
344
265
|
/**
|
|
345
266
|
* @internal
|
|
346
267
|
*/
|
|
@@ -353,19 +274,18 @@ function trpcMutationOptions(args) {
|
|
|
353
274
|
prefix: (_opts$keyPrefix = opts === null || opts === void 0 ? void 0 : opts.keyPrefix) !== null && _opts$keyPrefix !== void 0 ? _opts$keyPrefix : prefix
|
|
354
275
|
});
|
|
355
276
|
const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
|
|
356
|
-
const mutationSuccessOverride = (_overrides$onSuccess = overrides === null || overrides === void 0 ? void 0 : overrides.onSuccess) !== null && _overrides$onSuccess !== void 0 ? _overrides$onSuccess : (options) => options.originalFn();
|
|
277
|
+
const mutationSuccessOverride = (_overrides$onSuccess = overrides === null || overrides === void 0 ? void 0 : overrides.onSuccess) !== null && _overrides$onSuccess !== void 0 ? _overrides$onSuccess : ((options) => options.originalFn());
|
|
357
278
|
const mutationFn = async (input) => {
|
|
358
|
-
|
|
359
|
-
return result;
|
|
279
|
+
return await mutate(...getClientArgs([...mutationKey, { input }], opts));
|
|
360
280
|
};
|
|
361
|
-
return (
|
|
281
|
+
return _objectSpread2(_objectSpread2({}, opts), {}, {
|
|
362
282
|
mutationKey,
|
|
363
283
|
mutationFn,
|
|
364
|
-
onSuccess(...args
|
|
284
|
+
onSuccess(...args) {
|
|
365
285
|
var _ref, _opts$meta;
|
|
366
286
|
const originalFn = () => {
|
|
367
287
|
var _opts$onSuccess, _opts$onSuccess2, _defaultOpts$onSucces;
|
|
368
|
-
return (_opts$onSuccess = opts === null || opts === void 0 || (_opts$onSuccess2 = opts.onSuccess) === null || _opts$onSuccess2 === void 0 ? void 0 : _opts$onSuccess2.call(opts, ...args
|
|
288
|
+
return (_opts$onSuccess = opts === null || opts === void 0 || (_opts$onSuccess2 = opts.onSuccess) === null || _opts$onSuccess2 === void 0 ? void 0 : _opts$onSuccess2.call(opts, ...args)) !== null && _opts$onSuccess !== void 0 ? _opts$onSuccess : defaultOpts === null || defaultOpts === void 0 || (_defaultOpts$onSucces = defaultOpts.onSuccess) === null || _defaultOpts$onSucces === void 0 ? void 0 : _defaultOpts$onSucces.call(defaultOpts, ...args);
|
|
369
289
|
};
|
|
370
290
|
return mutationSuccessOverride({
|
|
371
291
|
originalFn,
|
|
@@ -376,10 +296,8 @@ function trpcMutationOptions(args) {
|
|
|
376
296
|
trpc: createTRPCOptionsResult({ path })
|
|
377
297
|
});
|
|
378
298
|
}
|
|
379
|
-
|
|
380
299
|
//#endregion
|
|
381
300
|
//#region src/internals/queryOptions.ts
|
|
382
|
-
var import_objectSpread2$2 = __toESM(require_objectSpread2());
|
|
383
301
|
/**
|
|
384
302
|
* @internal
|
|
385
303
|
*/
|
|
@@ -389,33 +307,29 @@ function trpcQueryOptions(args) {
|
|
|
389
307
|
const inputIsSkipToken = input === skipToken;
|
|
390
308
|
const queryFn = async (queryFnContext) => {
|
|
391
309
|
var _opts$trpc;
|
|
392
|
-
const actualOpts = (
|
|
393
|
-
const queryKey
|
|
394
|
-
const result = await query(...getClientArgs(queryKey
|
|
395
|
-
if (isAsyncIterable(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey
|
|
310
|
+
const actualOpts = _objectSpread2(_objectSpread2({}, opts), {}, { trpc: _objectSpread2(_objectSpread2({}, opts === null || opts === void 0 ? void 0 : opts.trpc), (opts === null || opts === void 0 || (_opts$trpc = opts.trpc) === null || _opts$trpc === void 0 ? void 0 : _opts$trpc.abortOnUnmount) ? { signal: queryFnContext.signal } : { signal: null }) });
|
|
311
|
+
const queryKey = queryFnContext.queryKey;
|
|
312
|
+
const result = await query(...getClientArgs(queryKey, actualOpts));
|
|
313
|
+
if (isAsyncIterable(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
|
396
314
|
return result;
|
|
397
315
|
};
|
|
398
|
-
return Object.assign(queryOptions((
|
|
316
|
+
return Object.assign(queryOptions(_objectSpread2(_objectSpread2({}, opts), {}, {
|
|
399
317
|
queryKey,
|
|
400
318
|
queryFn: inputIsSkipToken ? skipToken : queryFn
|
|
401
319
|
})), { trpc: createTRPCOptionsResult({ path }) });
|
|
402
320
|
}
|
|
403
|
-
|
|
404
321
|
//#endregion
|
|
405
322
|
//#region src/internals/subscriptionOptions.ts
|
|
406
|
-
var import_objectSpread2$1 = __toESM(require_objectSpread2(), 1);
|
|
407
323
|
/**
|
|
408
324
|
* @internal
|
|
409
325
|
*/
|
|
410
326
|
const trpcSubscriptionOptions = (args) => {
|
|
411
|
-
|
|
412
|
-
const { subscribe, path, queryKey, opts = {} } = args;
|
|
413
|
-
const input = (_readQueryKey = readQueryKey(queryKey)) === null || _readQueryKey === void 0 || (_readQueryKey = _readQueryKey.args) === null || _readQueryKey === void 0 ? void 0 : _readQueryKey.input;
|
|
327
|
+
const { subscribe, path, queryKey, input, opts = {} } = args;
|
|
414
328
|
const enabled = "enabled" in opts ? !!opts.enabled : input !== skipToken;
|
|
415
329
|
const _subscribe = (innerOpts) => {
|
|
416
|
-
return subscribe(path.join("."), input
|
|
330
|
+
return subscribe(path.join("."), input === skipToken ? void 0 : input, innerOpts);
|
|
417
331
|
};
|
|
418
|
-
return (
|
|
332
|
+
return _objectSpread2(_objectSpread2({}, opts), {}, {
|
|
419
333
|
enabled,
|
|
420
334
|
subscribe: _subscribe,
|
|
421
335
|
queryKey,
|
|
@@ -423,14 +337,14 @@ const trpcSubscriptionOptions = (args) => {
|
|
|
423
337
|
});
|
|
424
338
|
};
|
|
425
339
|
function useSubscription(opts) {
|
|
426
|
-
const optsRef = React
|
|
340
|
+
const optsRef = React.useRef(opts);
|
|
427
341
|
optsRef.current = opts;
|
|
428
|
-
const trackedProps = React
|
|
429
|
-
const addTrackedProp = React
|
|
342
|
+
const trackedProps = React.useRef(/* @__PURE__ */ new Set([]));
|
|
343
|
+
const addTrackedProp = React.useCallback((key) => {
|
|
430
344
|
trackedProps.current.add(key);
|
|
431
345
|
}, []);
|
|
432
|
-
const currentSubscriptionRef = React
|
|
433
|
-
const reset = React
|
|
346
|
+
const currentSubscriptionRef = React.useRef(() => {});
|
|
347
|
+
const reset = React.useCallback(() => {
|
|
434
348
|
var _currentSubscriptionR;
|
|
435
349
|
(_currentSubscriptionR = currentSubscriptionRef.current) === null || _currentSubscriptionR === void 0 || _currentSubscriptionR.call(currentSubscriptionRef);
|
|
436
350
|
updateState(getInitialState);
|
|
@@ -439,7 +353,7 @@ function useSubscription(opts) {
|
|
|
439
353
|
onStarted: () => {
|
|
440
354
|
var _optsRef$current$onSt, _optsRef$current;
|
|
441
355
|
(_optsRef$current$onSt = (_optsRef$current = optsRef.current).onStarted) === null || _optsRef$current$onSt === void 0 || _optsRef$current$onSt.call(_optsRef$current);
|
|
442
|
-
updateState((prev) => (
|
|
356
|
+
updateState((prev) => _objectSpread2(_objectSpread2({}, prev), {}, {
|
|
443
357
|
status: "pending",
|
|
444
358
|
error: null
|
|
445
359
|
}));
|
|
@@ -447,7 +361,7 @@ function useSubscription(opts) {
|
|
|
447
361
|
onData: (data) => {
|
|
448
362
|
var _optsRef$current$onDa, _optsRef$current2;
|
|
449
363
|
(_optsRef$current$onDa = (_optsRef$current2 = optsRef.current).onData) === null || _optsRef$current$onDa === void 0 || _optsRef$current$onDa.call(_optsRef$current2, data);
|
|
450
|
-
updateState((prev) => (
|
|
364
|
+
updateState((prev) => _objectSpread2(_objectSpread2({}, prev), {}, {
|
|
451
365
|
status: "pending",
|
|
452
366
|
data,
|
|
453
367
|
error: null
|
|
@@ -456,7 +370,7 @@ function useSubscription(opts) {
|
|
|
456
370
|
onError: (error) => {
|
|
457
371
|
var _optsRef$current$onEr, _optsRef$current3;
|
|
458
372
|
(_optsRef$current$onEr = (_optsRef$current3 = optsRef.current).onError) === null || _optsRef$current$onEr === void 0 || _optsRef$current$onEr.call(_optsRef$current3, error);
|
|
459
|
-
updateState((prev) => (
|
|
373
|
+
updateState((prev) => _objectSpread2(_objectSpread2({}, prev), {}, {
|
|
460
374
|
status: "error",
|
|
461
375
|
error
|
|
462
376
|
}));
|
|
@@ -466,12 +380,12 @@ function useSubscription(opts) {
|
|
|
466
380
|
(_optsRef$current$onCo = (_optsRef$current4 = optsRef.current).onConnectionStateChange) === null || _optsRef$current$onCo === void 0 || _optsRef$current$onCo.call(_optsRef$current4, result);
|
|
467
381
|
updateState((prev) => {
|
|
468
382
|
switch (result.state) {
|
|
469
|
-
case "connecting": return (
|
|
383
|
+
case "connecting": return _objectSpread2(_objectSpread2({}, prev), {}, {
|
|
470
384
|
status: "connecting",
|
|
471
385
|
error: result.error
|
|
472
386
|
});
|
|
473
387
|
case "pending": return prev;
|
|
474
|
-
case "idle": return (
|
|
388
|
+
case "idle": return _objectSpread2(_objectSpread2({}, prev), {}, {
|
|
475
389
|
status: "idle",
|
|
476
390
|
data: void 0,
|
|
477
391
|
error: null
|
|
@@ -484,7 +398,7 @@ function useSubscription(opts) {
|
|
|
484
398
|
subscription.unsubscribe();
|
|
485
399
|
};
|
|
486
400
|
}, [hashKey(opts.queryKey), opts.enabled]);
|
|
487
|
-
const getInitialState = React
|
|
401
|
+
const getInitialState = React.useCallback(() => {
|
|
488
402
|
return opts.enabled ? {
|
|
489
403
|
data: void 0,
|
|
490
404
|
error: null,
|
|
@@ -497,10 +411,10 @@ function useSubscription(opts) {
|
|
|
497
411
|
reset
|
|
498
412
|
};
|
|
499
413
|
}, [opts.enabled, reset]);
|
|
500
|
-
const resultRef = React
|
|
501
|
-
const [state, setState] = React
|
|
414
|
+
const resultRef = React.useRef(getInitialState());
|
|
415
|
+
const [state, setState] = React.useState(trackResult(resultRef, addTrackedProp));
|
|
502
416
|
state.reset = reset;
|
|
503
|
-
const updateState = React
|
|
417
|
+
const updateState = React.useCallback((callback) => {
|
|
504
418
|
const prev = resultRef.current;
|
|
505
419
|
const next = resultRef.current = callback(prev);
|
|
506
420
|
let shouldUpdate = false;
|
|
@@ -510,7 +424,7 @@ function useSubscription(opts) {
|
|
|
510
424
|
}
|
|
511
425
|
if (shouldUpdate) setState(trackResult(resultRef, addTrackedProp));
|
|
512
426
|
}, [addTrackedProp]);
|
|
513
|
-
React
|
|
427
|
+
React.useEffect(() => {
|
|
514
428
|
if (!opts.enabled) return;
|
|
515
429
|
reset();
|
|
516
430
|
return () => {
|
|
@@ -521,16 +435,13 @@ function useSubscription(opts) {
|
|
|
521
435
|
return state;
|
|
522
436
|
}
|
|
523
437
|
function trackResult(result, onTrackResult) {
|
|
524
|
-
|
|
438
|
+
return new Proxy(result.current, { get(_target, prop) {
|
|
525
439
|
onTrackResult(prop);
|
|
526
440
|
return result.current[prop];
|
|
527
441
|
} });
|
|
528
|
-
return trackedResult;
|
|
529
442
|
}
|
|
530
|
-
|
|
531
443
|
//#endregion
|
|
532
444
|
//#region src/internals/createOptionsProxy.ts
|
|
533
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
534
445
|
/**
|
|
535
446
|
* Create a typed proxy from your router types. Can also be used on the server.
|
|
536
447
|
*
|
|
@@ -550,15 +461,14 @@ function createTRPCOptionsProxy(opts) {
|
|
|
550
461
|
signal: void 0,
|
|
551
462
|
batchIndex: 0
|
|
552
463
|
}));
|
|
553
|
-
|
|
554
|
-
return untypedClient[type](path, input, trpcOpts);
|
|
464
|
+
return (opts.client instanceof TRPCUntypedClient ? opts.client : getUntypedClient(opts.client))[type](path, input, trpcOpts);
|
|
555
465
|
};
|
|
556
466
|
};
|
|
557
467
|
return createTRPCRecursiveProxy(({ args, path: _path }) => {
|
|
558
468
|
const path = [..._path];
|
|
559
469
|
const utilName = path.pop();
|
|
560
470
|
const [arg1, arg2] = args;
|
|
561
|
-
|
|
471
|
+
return {
|
|
562
472
|
"~types": void 0,
|
|
563
473
|
pathKey: () => {
|
|
564
474
|
return getQueryKeyInternal({
|
|
@@ -568,7 +478,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
568
478
|
});
|
|
569
479
|
},
|
|
570
480
|
pathFilter: () => {
|
|
571
|
-
return (
|
|
481
|
+
return _objectSpread2(_objectSpread2({}, arg1), {}, { queryKey: getQueryKeyInternal({
|
|
572
482
|
path,
|
|
573
483
|
type: "any",
|
|
574
484
|
prefix
|
|
@@ -598,7 +508,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
598
508
|
});
|
|
599
509
|
},
|
|
600
510
|
queryFilter: () => {
|
|
601
|
-
return (
|
|
511
|
+
return _objectSpread2(_objectSpread2({}, arg2), {}, { queryKey: getQueryKeyInternal({
|
|
602
512
|
path,
|
|
603
513
|
input: arg1,
|
|
604
514
|
type: "query",
|
|
@@ -629,7 +539,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
629
539
|
});
|
|
630
540
|
},
|
|
631
541
|
infiniteQueryFilter: () => {
|
|
632
|
-
return (
|
|
542
|
+
return _objectSpread2(_objectSpread2({}, arg2), {}, { queryKey: getQueryKeyInternal({
|
|
633
543
|
path,
|
|
634
544
|
input: arg1,
|
|
635
545
|
type: "infinite",
|
|
@@ -657,6 +567,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
657
567
|
return trpcSubscriptionOptions({
|
|
658
568
|
opts: arg2,
|
|
659
569
|
path,
|
|
570
|
+
input: arg1,
|
|
660
571
|
queryKey: getQueryKeyInternal({
|
|
661
572
|
path,
|
|
662
573
|
input: arg1,
|
|
@@ -666,11 +577,9 @@ function createTRPCOptionsProxy(opts) {
|
|
|
666
577
|
subscribe: callIt("subscription")
|
|
667
578
|
});
|
|
668
579
|
}
|
|
669
|
-
};
|
|
670
|
-
return contextMap[utilName]();
|
|
580
|
+
}[utilName]();
|
|
671
581
|
});
|
|
672
582
|
}
|
|
673
|
-
|
|
674
583
|
//#endregion
|
|
675
584
|
//#region src/internals/Context.tsx
|
|
676
585
|
/**
|
|
@@ -691,13 +600,7 @@ function createTRPCContext() {
|
|
|
691
600
|
props.queryClient,
|
|
692
601
|
props.keyPrefix
|
|
693
602
|
]);
|
|
694
|
-
return /* @__PURE__ */
|
|
695
|
-
value: props.trpcClient,
|
|
696
|
-
children: /* @__PURE__ */ jsx(TRPCContext.Provider, {
|
|
697
|
-
value,
|
|
698
|
-
children: props.children
|
|
699
|
-
})
|
|
700
|
-
});
|
|
603
|
+
return /* @__PURE__ */ React.createElement(TRPCClientContext.Provider, { value: props.trpcClient }, /* @__PURE__ */ React.createElement(TRPCContext.Provider, { value }, props.children));
|
|
701
604
|
};
|
|
702
605
|
TRPCProvider.displayName = "TRPCProvider";
|
|
703
606
|
function useTRPC() {
|
|
@@ -716,7 +619,7 @@ function createTRPCContext() {
|
|
|
716
619
|
useTRPCClient
|
|
717
620
|
};
|
|
718
621
|
}
|
|
719
|
-
|
|
720
622
|
//#endregion
|
|
721
623
|
export { createTRPCContext, createTRPCOptionsProxy, useSubscription };
|
|
624
|
+
|
|
722
625
|
//# sourceMappingURL=index.mjs.map
|