@trpc/next 10.0.0-alpha.3 → 10.0.0-alpha.32
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.js +18 -16
- package/dist/index.mjs +18 -16
- package/dist/setupNext.d.ts +429 -30
- package/dist/setupNext.d.ts.map +1 -1
- package/dist/withTRPC.d.ts +4 -4
- package/dist/withTRPC.d.ts.map +1 -1
- package/package.json +18 -14
- package/src/setupNext.tsx +14 -6
- package/src/withTRPC.tsx +34 -26
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
|
10
10
|
var react = require('@trpc/react');
|
|
11
11
|
var React = require('react');
|
|
12
12
|
var reactQuery = require('react-query');
|
|
13
|
-
var hydration = require('react-query/hydration');
|
|
14
13
|
var ssrPrepass = require('react-ssr-prepass');
|
|
15
14
|
|
|
16
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -49,7 +48,7 @@ function transformQueryOrMutationCacheErrors(result) {
|
|
|
49
48
|
function withTRPC(opts) {
|
|
50
49
|
var getClientConfig = opts.config;
|
|
51
50
|
return function (AppOrPage) {
|
|
52
|
-
var trpc = react.createReactQueryHooks(
|
|
51
|
+
var trpc = react.createReactQueryHooks();
|
|
53
52
|
|
|
54
53
|
var WithTRPC = function WithTRPC(props) {
|
|
55
54
|
var _props$pageProps;
|
|
@@ -65,7 +64,7 @@ function withTRPC(opts) {
|
|
|
65
64
|
return {
|
|
66
65
|
queryClient: queryClient,
|
|
67
66
|
trpcClient: trpcClient,
|
|
68
|
-
|
|
67
|
+
ssrState: opts.ssr ? 'mounting' : false,
|
|
69
68
|
ssrContext: null
|
|
70
69
|
};
|
|
71
70
|
}),
|
|
@@ -73,18 +72,18 @@ function withTRPC(opts) {
|
|
|
73
72
|
_useState2$ = _useState2[0],
|
|
74
73
|
queryClient = _useState2$.queryClient,
|
|
75
74
|
trpcClient = _useState2$.trpcClient,
|
|
76
|
-
|
|
75
|
+
ssrState = _useState2$.ssrState,
|
|
77
76
|
ssrContext = _useState2$.ssrContext;
|
|
78
77
|
|
|
79
|
-
var hydratedState = trpc.useDehydratedState((_props$pageProps = props.pageProps) === null || _props$pageProps === void 0 ? void 0 : _props$pageProps.trpcState);
|
|
78
|
+
var hydratedState = trpc.useDehydratedState(trpcClient, (_props$pageProps = props.pageProps) === null || _props$pageProps === void 0 ? void 0 : _props$pageProps.trpcState);
|
|
80
79
|
return /*#__PURE__*/React__default["default"].createElement(trpc.Provider, {
|
|
81
80
|
client: trpcClient,
|
|
82
81
|
queryClient: queryClient,
|
|
83
|
-
|
|
82
|
+
ssrState: ssrState,
|
|
84
83
|
ssrContext: ssrContext
|
|
85
84
|
}, /*#__PURE__*/React__default["default"].createElement(reactQuery.QueryClientProvider, {
|
|
86
85
|
client: queryClient
|
|
87
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
86
|
+
}, /*#__PURE__*/React__default["default"].createElement(reactQuery.Hydrate, {
|
|
88
87
|
state: hydratedState
|
|
89
88
|
}, /*#__PURE__*/React__default["default"].createElement(AppOrPage, props))));
|
|
90
89
|
};
|
|
@@ -92,7 +91,7 @@ function withTRPC(opts) {
|
|
|
92
91
|
if (AppOrPage.getInitialProps || opts.ssr) {
|
|
93
92
|
WithTRPC.getInitialProps = /*#__PURE__*/function () {
|
|
94
93
|
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(appOrPageCtx) {
|
|
95
|
-
var _opts$responseMeta
|
|
94
|
+
var _opts$responseMeta;
|
|
96
95
|
|
|
97
96
|
var AppTree, isApp, ctx, pageProps, _originalProps$pagePr, originalProps, originalPageProps, getAppTreeProps, config, trpcClient, queryClient, trpcProp, prepassProps, dehydratedCache, dehydratedCacheWithErrors, appTreeProps, meta, _i, _Object$entries, _Object$entries$_i, key, value, _ctx$res;
|
|
98
97
|
|
|
@@ -144,7 +143,7 @@ function withTRPC(opts) {
|
|
|
144
143
|
config: config,
|
|
145
144
|
trpcClient: trpcClient,
|
|
146
145
|
queryClient: queryClient,
|
|
147
|
-
|
|
146
|
+
ssrState: 'prepass',
|
|
148
147
|
ssrContext: ctx
|
|
149
148
|
};
|
|
150
149
|
prepassProps = {
|
|
@@ -182,7 +181,7 @@ function withTRPC(opts) {
|
|
|
182
181
|
break;
|
|
183
182
|
|
|
184
183
|
case 27:
|
|
185
|
-
dehydratedCache =
|
|
184
|
+
dehydratedCache = reactQuery.dehydrate(queryClient, {
|
|
186
185
|
shouldDehydrateQuery: function shouldDehydrateQuery() {
|
|
187
186
|
// makes sure errors are also dehydrated
|
|
188
187
|
return true;
|
|
@@ -194,18 +193,18 @@ function withTRPC(opts) {
|
|
|
194
193
|
mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
|
|
195
194
|
}); // dehydrate query client's state and add it to the props
|
|
196
195
|
|
|
197
|
-
pageProps.trpcState =
|
|
196
|
+
pageProps.trpcState = trpcClient.runtime.transformer.serialize(dehydratedCacheWithErrors);
|
|
198
197
|
appTreeProps = getAppTreeProps(pageProps);
|
|
199
|
-
meta = (_opts$responseMeta =
|
|
198
|
+
meta = ((_opts$responseMeta = opts.responseMeta) === null || _opts$responseMeta === void 0 ? void 0 : _opts$responseMeta.call(opts, {
|
|
200
199
|
ctx: ctx,
|
|
201
200
|
clientErrors: [].concat(_toConsumableArray__default["default"](dehydratedCache.queries), _toConsumableArray__default["default"](dehydratedCache.mutations)).map(function (v) {
|
|
202
201
|
return v.state.error;
|
|
203
202
|
}).flatMap(function (err) {
|
|
204
203
|
return err instanceof Error && err.name === 'TRPCClientError' ? [err] : [];
|
|
205
204
|
})
|
|
206
|
-
}))
|
|
205
|
+
})) || {};
|
|
207
206
|
|
|
208
|
-
for (_i = 0, _Object$entries = Object.entries(meta); _i < _Object$entries.length; _i++) {
|
|
207
|
+
for (_i = 0, _Object$entries = Object.entries(meta.headers || {}); _i < _Object$entries.length; _i++) {
|
|
209
208
|
_Object$entries$_i = _slicedToArray__default["default"](_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
210
209
|
|
|
211
210
|
if (typeof value === 'string') {
|
|
@@ -240,17 +239,20 @@ function withTRPC(opts) {
|
|
|
240
239
|
}
|
|
241
240
|
|
|
242
241
|
function setupTRPC(opts) {
|
|
243
|
-
var hooks = react.createReactQueryHooks(
|
|
242
|
+
var hooks = react.createReactQueryHooks();
|
|
243
|
+
var proxy = react.createReactQueryProxy(); // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
|
|
244
244
|
|
|
245
245
|
var _withTRPC = withTRPC(opts);
|
|
246
246
|
|
|
247
247
|
return {
|
|
248
|
+
proxy: proxy,
|
|
248
249
|
useContext: hooks.useContext,
|
|
249
250
|
useInfiniteQuery: hooks.useInfiniteQuery,
|
|
250
251
|
useMutation: hooks.useMutation,
|
|
251
252
|
useQuery: hooks.useQuery,
|
|
252
253
|
useSubscription: hooks.useSubscription,
|
|
253
|
-
withTRPC: _withTRPC
|
|
254
|
+
withTRPC: _withTRPC,
|
|
255
|
+
queries: hooks.queries
|
|
254
256
|
};
|
|
255
257
|
}
|
|
256
258
|
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,9 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
|
3
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
5
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
6
|
-
import { createReactQueryHooks, createTRPCClient } from '@trpc/react';
|
|
6
|
+
import { createReactQueryHooks, createTRPCClient, createReactQueryProxy } from '@trpc/react';
|
|
7
7
|
import React, { useState, createElement } from 'react';
|
|
8
|
-
import { QueryClient, QueryClientProvider } from 'react-query';
|
|
9
|
-
import { Hydrate, dehydrate } from 'react-query/hydration';
|
|
8
|
+
import { QueryClient, QueryClientProvider, Hydrate, dehydrate } from 'react-query';
|
|
10
9
|
import ssrPrepass from 'react-ssr-prepass';
|
|
11
10
|
|
|
12
11
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -35,7 +34,7 @@ function transformQueryOrMutationCacheErrors(result) {
|
|
|
35
34
|
function withTRPC(opts) {
|
|
36
35
|
var getClientConfig = opts.config;
|
|
37
36
|
return function (AppOrPage) {
|
|
38
|
-
var trpc = createReactQueryHooks(
|
|
37
|
+
var trpc = createReactQueryHooks();
|
|
39
38
|
|
|
40
39
|
var WithTRPC = function WithTRPC(props) {
|
|
41
40
|
var _props$pageProps;
|
|
@@ -51,7 +50,7 @@ function withTRPC(opts) {
|
|
|
51
50
|
return {
|
|
52
51
|
queryClient: queryClient,
|
|
53
52
|
trpcClient: trpcClient,
|
|
54
|
-
|
|
53
|
+
ssrState: opts.ssr ? 'mounting' : false,
|
|
55
54
|
ssrContext: null
|
|
56
55
|
};
|
|
57
56
|
}),
|
|
@@ -59,14 +58,14 @@ function withTRPC(opts) {
|
|
|
59
58
|
_useState2$ = _useState2[0],
|
|
60
59
|
queryClient = _useState2$.queryClient,
|
|
61
60
|
trpcClient = _useState2$.trpcClient,
|
|
62
|
-
|
|
61
|
+
ssrState = _useState2$.ssrState,
|
|
63
62
|
ssrContext = _useState2$.ssrContext;
|
|
64
63
|
|
|
65
|
-
var hydratedState = trpc.useDehydratedState((_props$pageProps = props.pageProps) === null || _props$pageProps === void 0 ? void 0 : _props$pageProps.trpcState);
|
|
64
|
+
var hydratedState = trpc.useDehydratedState(trpcClient, (_props$pageProps = props.pageProps) === null || _props$pageProps === void 0 ? void 0 : _props$pageProps.trpcState);
|
|
66
65
|
return /*#__PURE__*/React.createElement(trpc.Provider, {
|
|
67
66
|
client: trpcClient,
|
|
68
67
|
queryClient: queryClient,
|
|
69
|
-
|
|
68
|
+
ssrState: ssrState,
|
|
70
69
|
ssrContext: ssrContext
|
|
71
70
|
}, /*#__PURE__*/React.createElement(QueryClientProvider, {
|
|
72
71
|
client: queryClient
|
|
@@ -78,7 +77,7 @@ function withTRPC(opts) {
|
|
|
78
77
|
if (AppOrPage.getInitialProps || opts.ssr) {
|
|
79
78
|
WithTRPC.getInitialProps = /*#__PURE__*/function () {
|
|
80
79
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(appOrPageCtx) {
|
|
81
|
-
var _opts$responseMeta
|
|
80
|
+
var _opts$responseMeta;
|
|
82
81
|
|
|
83
82
|
var AppTree, isApp, ctx, pageProps, _originalProps$pagePr, originalProps, originalPageProps, getAppTreeProps, config, trpcClient, queryClient, trpcProp, prepassProps, dehydratedCache, dehydratedCacheWithErrors, appTreeProps, meta, _i, _Object$entries, _Object$entries$_i, key, value, _ctx$res;
|
|
84
83
|
|
|
@@ -130,7 +129,7 @@ function withTRPC(opts) {
|
|
|
130
129
|
config: config,
|
|
131
130
|
trpcClient: trpcClient,
|
|
132
131
|
queryClient: queryClient,
|
|
133
|
-
|
|
132
|
+
ssrState: 'prepass',
|
|
134
133
|
ssrContext: ctx
|
|
135
134
|
};
|
|
136
135
|
prepassProps = {
|
|
@@ -180,18 +179,18 @@ function withTRPC(opts) {
|
|
|
180
179
|
mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
|
|
181
180
|
}); // dehydrate query client's state and add it to the props
|
|
182
181
|
|
|
183
|
-
pageProps.trpcState =
|
|
182
|
+
pageProps.trpcState = trpcClient.runtime.transformer.serialize(dehydratedCacheWithErrors);
|
|
184
183
|
appTreeProps = getAppTreeProps(pageProps);
|
|
185
|
-
meta = (_opts$responseMeta =
|
|
184
|
+
meta = ((_opts$responseMeta = opts.responseMeta) === null || _opts$responseMeta === void 0 ? void 0 : _opts$responseMeta.call(opts, {
|
|
186
185
|
ctx: ctx,
|
|
187
186
|
clientErrors: [].concat(_toConsumableArray(dehydratedCache.queries), _toConsumableArray(dehydratedCache.mutations)).map(function (v) {
|
|
188
187
|
return v.state.error;
|
|
189
188
|
}).flatMap(function (err) {
|
|
190
189
|
return err instanceof Error && err.name === 'TRPCClientError' ? [err] : [];
|
|
191
190
|
})
|
|
192
|
-
}))
|
|
191
|
+
})) || {};
|
|
193
192
|
|
|
194
|
-
for (_i = 0, _Object$entries = Object.entries(meta); _i < _Object$entries.length; _i++) {
|
|
193
|
+
for (_i = 0, _Object$entries = Object.entries(meta.headers || {}); _i < _Object$entries.length; _i++) {
|
|
195
194
|
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
196
195
|
|
|
197
196
|
if (typeof value === 'string') {
|
|
@@ -226,17 +225,20 @@ function withTRPC(opts) {
|
|
|
226
225
|
}
|
|
227
226
|
|
|
228
227
|
function setupTRPC(opts) {
|
|
229
|
-
var hooks = createReactQueryHooks(
|
|
228
|
+
var hooks = createReactQueryHooks();
|
|
229
|
+
var proxy = createReactQueryProxy(); // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
|
|
230
230
|
|
|
231
231
|
var _withTRPC = withTRPC(opts);
|
|
232
232
|
|
|
233
233
|
return {
|
|
234
|
+
proxy: proxy,
|
|
234
235
|
useContext: hooks.useContext,
|
|
235
236
|
useInfiniteQuery: hooks.useInfiniteQuery,
|
|
236
237
|
useMutation: hooks.useMutation,
|
|
237
238
|
useQuery: hooks.useQuery,
|
|
238
239
|
useSubscription: hooks.useSubscription,
|
|
239
|
-
withTRPC: _withTRPC
|
|
240
|
+
withTRPC: _withTRPC,
|
|
241
|
+
queries: hooks.queries
|
|
240
242
|
};
|
|
241
243
|
}
|
|
242
244
|
|