@trpc/next 10.0.0-alpha.2 → 10.0.0-alpha.3
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/{declarations/src/index.d.ts → index.d.ts} +2 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/{trpc-next.cjs.dev.js → index.js} +23 -15
- package/dist/{trpc-next.esm.js → index.mjs} +8 -4
- package/dist/index.ts.js +1 -0
- package/dist/{declarations/src/setupNext.d.ts → setupNext.d.ts} +49 -49
- package/dist/setupNext.d.ts.map +1 -0
- package/dist/{declarations/src/withTRPC.d.ts → withTRPC.d.ts} +30 -30
- package/dist/withTRPC.d.ts.map +1 -0
- package/package.json +20 -16
- package/dist/declarations/src/index.d.ts.map +0 -1
- package/dist/declarations/src/setupNext.d.ts.map +0 -1
- package/dist/declarations/src/withTRPC.d.ts.map +0 -1
- package/dist/trpc-next.cjs.d.ts +0 -1
- package/dist/trpc-next.cjs.js +0 -7
- package/dist/trpc-next.cjs.prod.js +0 -250
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './withTRPC';
|
|
2
|
-
export * from './setupNext';
|
|
1
|
+
export * from './withTRPC';
|
|
2
|
+
export * from './setupNext';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
6
6
|
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
7
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
8
|
-
var
|
|
8
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
9
9
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
10
10
|
var react = require('@trpc/react');
|
|
11
11
|
var React = require('react');
|
|
@@ -13,11 +13,19 @@ var reactQuery = require('react-query');
|
|
|
13
13
|
var hydration = require('react-query/hydration');
|
|
14
14
|
var ssrPrepass = require('react-ssr-prepass');
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
17
|
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
18
|
+
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
19
|
+
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
20
|
+
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
21
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
22
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
23
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
24
|
+
var ssrPrepass__default = /*#__PURE__*/_interopDefaultLegacy(ssrPrepass);
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
29
|
|
|
22
30
|
function transformQueryOrMutationCacheErrors(result) {
|
|
23
31
|
var error = result.state.error;
|
|
@@ -61,7 +69,7 @@ function withTRPC(opts) {
|
|
|
61
69
|
ssrContext: null
|
|
62
70
|
};
|
|
63
71
|
}),
|
|
64
|
-
_useState2 =
|
|
72
|
+
_useState2 = _slicedToArray__default["default"](_useState, 1),
|
|
65
73
|
_useState2$ = _useState2[0],
|
|
66
74
|
queryClient = _useState2$.queryClient,
|
|
67
75
|
trpcClient = _useState2$.trpcClient,
|
|
@@ -69,26 +77,26 @@ function withTRPC(opts) {
|
|
|
69
77
|
ssrContext = _useState2$.ssrContext;
|
|
70
78
|
|
|
71
79
|
var hydratedState = trpc.useDehydratedState((_props$pageProps = props.pageProps) === null || _props$pageProps === void 0 ? void 0 : _props$pageProps.trpcState);
|
|
72
|
-
return /*#__PURE__*/React__default[
|
|
80
|
+
return /*#__PURE__*/React__default["default"].createElement(trpc.Provider, {
|
|
73
81
|
client: trpcClient,
|
|
74
82
|
queryClient: queryClient,
|
|
75
83
|
isPrepass: isPrepass,
|
|
76
84
|
ssrContext: ssrContext
|
|
77
|
-
}, /*#__PURE__*/React__default[
|
|
85
|
+
}, /*#__PURE__*/React__default["default"].createElement(reactQuery.QueryClientProvider, {
|
|
78
86
|
client: queryClient
|
|
79
|
-
}, /*#__PURE__*/React__default[
|
|
87
|
+
}, /*#__PURE__*/React__default["default"].createElement(hydration.Hydrate, {
|
|
80
88
|
state: hydratedState
|
|
81
|
-
}, /*#__PURE__*/React__default[
|
|
89
|
+
}, /*#__PURE__*/React__default["default"].createElement(AppOrPage, props))));
|
|
82
90
|
};
|
|
83
91
|
|
|
84
92
|
if (AppOrPage.getInitialProps || opts.ssr) {
|
|
85
93
|
WithTRPC.getInitialProps = /*#__PURE__*/function () {
|
|
86
|
-
var _ref =
|
|
94
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(appOrPageCtx) {
|
|
87
95
|
var _opts$responseMeta, _opts$responseMeta2;
|
|
88
96
|
|
|
89
97
|
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;
|
|
90
98
|
|
|
91
|
-
return _regeneratorRuntime__default[
|
|
99
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
92
100
|
while (1) {
|
|
93
101
|
switch (_context.prev = _context.next) {
|
|
94
102
|
case 0:
|
|
@@ -148,7 +156,7 @@ function withTRPC(opts) {
|
|
|
148
156
|
case 18:
|
|
149
157
|
|
|
150
158
|
_context.next = 21;
|
|
151
|
-
return ssrPrepass__default[
|
|
159
|
+
return ssrPrepass__default["default"]( /*#__PURE__*/React.createElement(AppTree, prepassProps));
|
|
152
160
|
|
|
153
161
|
case 21:
|
|
154
162
|
if (queryClient.isFetching()) {
|
|
@@ -190,7 +198,7 @@ function withTRPC(opts) {
|
|
|
190
198
|
appTreeProps = getAppTreeProps(pageProps);
|
|
191
199
|
meta = (_opts$responseMeta = (_opts$responseMeta2 = opts.responseMeta) === null || _opts$responseMeta2 === void 0 ? void 0 : _opts$responseMeta2.call(opts, {
|
|
192
200
|
ctx: ctx,
|
|
193
|
-
clientErrors: [].concat(
|
|
201
|
+
clientErrors: [].concat(_toConsumableArray__default["default"](dehydratedCache.queries), _toConsumableArray__default["default"](dehydratedCache.mutations)).map(function (v) {
|
|
194
202
|
return v.state.error;
|
|
195
203
|
}).flatMap(function (err) {
|
|
196
204
|
return err instanceof Error && err.name === 'TRPCClientError' ? [err] : [];
|
|
@@ -198,7 +206,7 @@ function withTRPC(opts) {
|
|
|
198
206
|
})) !== null && _opts$responseMeta !== void 0 ? _opts$responseMeta : {};
|
|
199
207
|
|
|
200
208
|
for (_i = 0, _Object$entries = Object.entries(meta); _i < _Object$entries.length; _i++) {
|
|
201
|
-
_Object$entries$_i =
|
|
209
|
+
_Object$entries$_i = _slicedToArray__default["default"](_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
202
210
|
|
|
203
211
|
if (typeof value === 'string') {
|
|
204
212
|
(_ctx$res = ctx.res) === null || _ctx$res === void 0 ? void 0 : _ctx$res.setHeader(key, value);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _toConsumableArray from '@babel/runtime/helpers/
|
|
2
|
-
import _asyncToGenerator from '@babel/runtime/helpers/
|
|
3
|
-
import _slicedToArray from '@babel/runtime/helpers/
|
|
4
|
-
import
|
|
1
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
|
+
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
3
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
5
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
6
6
|
import { createReactQueryHooks, createTRPCClient } from '@trpc/react';
|
|
7
7
|
import React, { useState, createElement } from 'react';
|
|
@@ -9,6 +9,10 @@ import { QueryClient, QueryClientProvider } from 'react-query';
|
|
|
9
9
|
import { Hydrate, dehydrate } from 'react-query/hydration';
|
|
10
10
|
import ssrPrepass from 'react-ssr-prepass';
|
|
11
11
|
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
+
|
|
12
16
|
function transformQueryOrMutationCacheErrors(result) {
|
|
13
17
|
var error = result.state.error;
|
|
14
18
|
|
package/dist/index.ts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { WithTRPCNoSSROptions, WithTRPCSSROptions } from './withTRPC';
|
|
3
|
-
export declare function setupTRPC<TRouter extends AnyRouter>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>): {
|
|
4
|
-
useContext: () => import("@trpc/react").TRPCContextState<TRouter, unknown>;
|
|
5
|
-
useInfiniteQuery: <
|
|
6
|
-
cursor?: any;
|
|
7
|
-
} ? TPath : never; }[keyof TRouter["_def"]["queries"]] & string>(pathAndInput: [path:
|
|
8
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
9
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
10
|
-
}; }[
|
|
11
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
12
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
13
|
-
}; }[
|
|
14
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
15
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
16
|
-
}; }[
|
|
17
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
18
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
19
|
-
}; }[
|
|
20
|
-
useMutation: <
|
|
21
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][
|
|
22
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][
|
|
23
|
-
}; }[
|
|
24
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][
|
|
25
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][
|
|
26
|
-
}; }[
|
|
27
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][
|
|
28
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][
|
|
29
|
-
}; }[
|
|
30
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][
|
|
31
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][
|
|
32
|
-
}; }[
|
|
33
|
-
useQuery: <
|
|
34
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
35
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
36
|
-
}; }[
|
|
37
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
38
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
39
|
-
}; }[
|
|
40
|
-
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][
|
|
41
|
-
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][
|
|
42
|
-
}; }[
|
|
43
|
-
useSubscription: <
|
|
44
|
-
enabled?: boolean | undefined;
|
|
45
|
-
error?: ((err: import("@trpc/react").TRPCClientErrorLike<TRouter>) => void) | undefined;
|
|
46
|
-
next: (data: TOutput) => void;
|
|
47
|
-
}) => void;
|
|
48
|
-
withTRPC: (AppOrPage: import("next").NextComponentType<any, any, any>) => import("next").NextComponentType<import("next").NextPageContext, {}, {}>;
|
|
49
|
-
};
|
|
1
|
+
import { AnyRouter } from '@trpc/server';
|
|
2
|
+
import { WithTRPCNoSSROptions, WithTRPCSSROptions } from './withTRPC';
|
|
3
|
+
export declare function setupTRPC<TRouter extends AnyRouter>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>): {
|
|
4
|
+
useContext: () => import("@trpc/react").TRPCContextState<TRouter, unknown>;
|
|
5
|
+
useInfiniteQuery: <TPath_3 extends { [TPath in keyof TRouter["_def"]["queries"]]: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath]> extends {
|
|
6
|
+
cursor?: any;
|
|
7
|
+
} ? TPath : never; }[keyof TRouter["_def"]["queries"]] & string>(pathAndInput: [path: TPath_3, input: Omit<{ [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
8
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
9
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
10
|
+
}; }[TPath_3]["input"], "cursor">], opts?: import("@trpc/react").UseTRPCInfiniteQueryOptions<TPath_3, Omit<{ [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
11
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
12
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
13
|
+
}; }[TPath_3]["input"], "cursor">, { [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
14
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
15
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
16
|
+
}; }[TPath_3]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>> | undefined) => import("react-query").UseInfiniteQueryResult<{ [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
17
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
18
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
19
|
+
}; }[TPath_3]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>>;
|
|
20
|
+
useMutation: <TPath_1 extends keyof TRouter["_def"]["mutations"] & string>(path: TPath_1 | [TPath_1], opts?: import("@trpc/react").UseTRPCMutationOptions<{ [TPath_2 in keyof TRouter["_def"]["mutations"]]: {
|
|
21
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][TPath_2]>;
|
|
22
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][TPath_2]["call"]>>;
|
|
23
|
+
}; }[TPath_1]["input"], import("@trpc/react").TRPCClientErrorLike<TRouter>, { [TPath_2 in keyof TRouter["_def"]["mutations"]]: {
|
|
24
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][TPath_2]>;
|
|
25
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][TPath_2]["call"]>>;
|
|
26
|
+
}; }[TPath_1]["output"]> | undefined) => import("react-query").UseMutationResult<{ [TPath_2 in keyof TRouter["_def"]["mutations"]]: {
|
|
27
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][TPath_2]>;
|
|
28
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][TPath_2]["call"]>>;
|
|
29
|
+
}; }[TPath_1]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>, { [TPath_2 in keyof TRouter["_def"]["mutations"]]: {
|
|
30
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["mutations"][TPath_2]>;
|
|
31
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["mutations"][TPath_2]["call"]>>;
|
|
32
|
+
}; }[TPath_1]["input"], unknown>;
|
|
33
|
+
useQuery: <TPath_4 extends keyof TRouter["_def"]["queries"] & string>(pathAndInput: [path: TPath_4, ...args: import("@trpc/server").inferHandlerInput<TRouter["_def"]["queries"][TPath_4]>], opts?: import("@trpc/react").UseTRPCQueryOptions<TPath_4, { [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
34
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
35
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
36
|
+
}; }[TPath_4]["input"], { [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
37
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
38
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
39
|
+
}; }[TPath_4]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>> | undefined) => import("react-query").UseQueryResult<{ [TPath_1 in keyof TRouter["_def"]["queries"]]: {
|
|
40
|
+
input: import("@trpc/server").inferProcedureInput<TRouter["_def"]["queries"][TPath_1]>;
|
|
41
|
+
output: import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["queries"][TPath_1]["call"]>>;
|
|
42
|
+
}; }[TPath_4]["output"], import("@trpc/react").TRPCClientErrorLike<TRouter>>;
|
|
43
|
+
useSubscription: <TPath_2 extends keyof TRouter["_def"]["subscriptions"] & string, TOutput extends ReturnType<import("@trpc/server").ThenArg<ReturnType<TRouter["_def"]["subscriptions"][TPath_2]["call"]>>["output"]>>(pathAndInput: [path: TPath_2, ...args: import("@trpc/server").inferHandlerInput<TRouter["_def"]["subscriptions"][TPath_2]>], opts: {
|
|
44
|
+
enabled?: boolean | undefined;
|
|
45
|
+
error?: ((err: import("@trpc/react").TRPCClientErrorLike<TRouter>) => void) | undefined;
|
|
46
|
+
next: (data: TOutput) => void;
|
|
47
|
+
}) => void;
|
|
48
|
+
withTRPC: (AppOrPage: import("next").NextComponentType<any, any, any>) => import("next").NextComponentType<import("next").NextPageContext, {}, {}>;
|
|
49
|
+
};
|
|
50
50
|
//# sourceMappingURL=setupNext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupNext.d.ts","sourceRoot":"","sources":["../src/setupNext.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAY,MAAM,YAAY,CAAC;AAEhF,wBAAgB,SAAS,CAAC,OAAO,SAAS,SAAS,EACjD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYlE"}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Heavily based on urql's ssr
|
|
3
|
-
* https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.ts
|
|
4
|
-
*/
|
|
5
|
-
import { TRPCClientError, CreateReactQueryHooksOptions } from '@trpc/react';
|
|
6
|
-
import type { AnyRouter, ResponseMeta } from '@trpc/server';
|
|
7
|
-
import { NextComponentType, NextPageContext } from 'next/dist/shared/lib/utils';
|
|
8
|
-
import type { CreateTRPCClientOptions } from '@trpc/client/src/internals/TRPCClient';
|
|
9
|
-
import { QueryClient } from 'react-query';
|
|
10
|
-
declare type QueryClientConfig = ConstructorParameters<typeof QueryClient>[0];
|
|
11
|
-
export declare type WithTRPCConfig<TRouter extends AnyRouter> = CreateTRPCClientOptions<TRouter> & {
|
|
12
|
-
queryClientConfig?: QueryClientConfig;
|
|
13
|
-
};
|
|
14
|
-
interface WithTRPCOptions<TRouter extends AnyRouter> extends CreateReactQueryHooksOptions {
|
|
15
|
-
config: (info: {
|
|
16
|
-
ctx?: NextPageContext;
|
|
17
|
-
}) => WithTRPCConfig<TRouter>;
|
|
18
|
-
}
|
|
19
|
-
export interface WithTRPCSSROptions<TRouter extends AnyRouter> extends WithTRPCOptions<TRouter> {
|
|
20
|
-
ssr: true;
|
|
21
|
-
responseMeta?: (opts: {
|
|
22
|
-
ctx: NextPageContext;
|
|
23
|
-
clientErrors: TRPCClientError<TRouter>[];
|
|
24
|
-
}) => ResponseMeta;
|
|
25
|
-
}
|
|
26
|
-
export interface WithTRPCNoSSROptions<TRouter extends AnyRouter> extends WithTRPCOptions<TRouter> {
|
|
27
|
-
ssr?: false;
|
|
28
|
-
}
|
|
29
|
-
export declare function withTRPC<TRouter extends AnyRouter>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>): (AppOrPage: NextComponentType<any, any, any>) => NextComponentType;
|
|
30
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* Heavily based on urql's ssr
|
|
3
|
+
* https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.ts
|
|
4
|
+
*/
|
|
5
|
+
import { TRPCClientError, CreateReactQueryHooksOptions } from '@trpc/react';
|
|
6
|
+
import type { AnyRouter, ResponseMeta } from '@trpc/server';
|
|
7
|
+
import { NextComponentType, NextPageContext } from 'next/dist/shared/lib/utils';
|
|
8
|
+
import type { CreateTRPCClientOptions } from '@trpc/client/src/internals/TRPCClient';
|
|
9
|
+
import { QueryClient } from 'react-query';
|
|
10
|
+
declare type QueryClientConfig = ConstructorParameters<typeof QueryClient>[0];
|
|
11
|
+
export declare type WithTRPCConfig<TRouter extends AnyRouter> = CreateTRPCClientOptions<TRouter> & {
|
|
12
|
+
queryClientConfig?: QueryClientConfig;
|
|
13
|
+
};
|
|
14
|
+
interface WithTRPCOptions<TRouter extends AnyRouter> extends CreateReactQueryHooksOptions {
|
|
15
|
+
config: (info: {
|
|
16
|
+
ctx?: NextPageContext;
|
|
17
|
+
}) => WithTRPCConfig<TRouter>;
|
|
18
|
+
}
|
|
19
|
+
export interface WithTRPCSSROptions<TRouter extends AnyRouter> extends WithTRPCOptions<TRouter> {
|
|
20
|
+
ssr: true;
|
|
21
|
+
responseMeta?: (opts: {
|
|
22
|
+
ctx: NextPageContext;
|
|
23
|
+
clientErrors: TRPCClientError<TRouter>[];
|
|
24
|
+
}) => ResponseMeta;
|
|
25
|
+
}
|
|
26
|
+
export interface WithTRPCNoSSROptions<TRouter extends AnyRouter> extends WithTRPCOptions<TRouter> {
|
|
27
|
+
ssr?: false;
|
|
28
|
+
}
|
|
29
|
+
export declare function withTRPC<TRouter extends AnyRouter>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>): (AppOrPage: NextComponentType<any, any, any>) => NextComponentType;
|
|
30
|
+
export {};
|
|
31
31
|
//# sourceMappingURL=withTRPC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withTRPC.d.ts","sourceRoot":"","sources":["../src/withTRPC.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,eAAe,EAEf,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,SAAS,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAGL,iBAAiB,EACjB,eAAe,EAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAErF,OAAO,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAC;AAI/D,aAAK,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAwBtE,oBAAY,cAAc,CAAC,OAAO,SAAS,SAAS,IAClD,uBAAuB,CAAC,OAAO,CAAC,GAAG;IACjC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC,CAAC;AAEJ,UAAU,eAAe,CAAC,OAAO,SAAS,SAAS,CACjD,SAAQ,4BAA4B;IACpC,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,CAAC,EAAE,eAAe,CAAA;KAAE,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,eAAe,CAAC,OAAO,CAAC;IAChC,GAAG,EAAE,IAAI,CAAC;IACV,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE;QACpB,GAAG,EAAE,eAAe,CAAC;QACrB,YAAY,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;KAC1C,KAAK,YAAY,CAAC;CACpB;AACD,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,SAAS,CAC7D,SAAQ,eAAe,CAAC,OAAO,CAAC;IAChC,GAAG,CAAC,EAAE,KAAK,CAAC;CACb;AAED,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,eAW9C,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,iBAAiB,CAsKxE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/next",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.3",
|
|
4
4
|
"description": "tRPC Next lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,15 +10,19 @@
|
|
|
10
10
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
11
11
|
"directory": "packages/next"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"module": "dist/index.mjs",
|
|
18
|
+
"typings": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
17
25
|
},
|
|
18
|
-
"scripts": {},
|
|
19
|
-
"main": "dist/trpc-next.cjs.js",
|
|
20
|
-
"module": "dist/trpc-next.esm.js",
|
|
21
|
-
"typings": "dist/trpc-next.cjs.d.ts",
|
|
22
26
|
"files": [
|
|
23
27
|
"README.md",
|
|
24
28
|
"dist",
|
|
@@ -30,9 +34,9 @@
|
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"peerDependencies": {
|
|
33
|
-
"@trpc/client": "10.0.0-alpha.
|
|
34
|
-
"@trpc/react": "10.0.0-alpha.
|
|
35
|
-
"@trpc/server": "10.0.0-alpha.
|
|
37
|
+
"@trpc/client": "10.0.0-alpha.3",
|
|
38
|
+
"@trpc/react": "10.0.0-alpha.3",
|
|
39
|
+
"@trpc/server": "10.0.0-alpha.3",
|
|
36
40
|
"next": "*",
|
|
37
41
|
"react": ">=16.8.0",
|
|
38
42
|
"react-dom": ">=16.8.0",
|
|
@@ -43,9 +47,9 @@
|
|
|
43
47
|
"react-ssr-prepass": "^1.5.0"
|
|
44
48
|
},
|
|
45
49
|
"devDependencies": {
|
|
46
|
-
"@trpc/client": "10.0.0-alpha.
|
|
47
|
-
"@trpc/react": "10.0.0-alpha.
|
|
48
|
-
"@trpc/server": "10.0.0-alpha.
|
|
50
|
+
"@trpc/client": "10.0.0-alpha.3",
|
|
51
|
+
"@trpc/react": "10.0.0-alpha.3",
|
|
52
|
+
"@trpc/server": "10.0.0-alpha.3",
|
|
49
53
|
"@types/express": "^4.17.12",
|
|
50
54
|
"express": "^4.17.1",
|
|
51
55
|
"next": "^12.0.1",
|
|
@@ -57,5 +61,5 @@
|
|
|
57
61
|
"publishConfig": {
|
|
58
62
|
"access": "public"
|
|
59
63
|
},
|
|
60
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "cd71a2fe5d42efc838ae3d4cebe7a9e1a36d9110"
|
|
61
65
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setupNext.d.ts","sourceRoot":"../../../src","sources":["setupNext.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAY,MAAM,YAAY,CAAC;AAEhF,wBAAgB,SAAS,CAAC,OAAO,SAAS,SAAS,EACjD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYlE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withTRPC.d.ts","sourceRoot":"../../../src","sources":["withTRPC.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,eAAe,EAEf,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,SAAS,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAGL,iBAAiB,EACjB,eAAe,EAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAErF,OAAO,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAC;AAI/D,aAAK,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAwBtE,oBAAY,cAAc,CAAC,OAAO,SAAS,SAAS,IAClD,uBAAuB,CAAC,OAAO,CAAC,GAAG;IACjC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC,CAAC;AAEJ,UAAU,eAAe,CAAC,OAAO,SAAS,SAAS,CACjD,SAAQ,4BAA4B;IACpC,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,CAAC,EAAE,eAAe,CAAA;KAAE,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,eAAe,CAAC,OAAO,CAAC;IAChC,GAAG,EAAE,IAAI,CAAC;IACV,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE;QACpB,GAAG,EAAE,eAAe,CAAC;QACrB,YAAY,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;KAC1C,KAAK,YAAY,CAAC;CACpB;AACD,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,SAAS,CAC7D,SAAQ,eAAe,CAAC,OAAO,CAAC;IAChC,GAAG,CAAC,EAAE,KAAK,CAAC;CACb;AAED,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,eAW9C,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,iBAAiB,CAsKxE"}
|
package/dist/trpc-next.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./declarations/src/index";
|
package/dist/trpc-next.cjs.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
6
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
8
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
9
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
10
|
-
var react = require('@trpc/react');
|
|
11
|
-
var React = require('react');
|
|
12
|
-
var reactQuery = require('react-query');
|
|
13
|
-
var hydration = require('react-query/hydration');
|
|
14
|
-
var ssrPrepass = require('react-ssr-prepass');
|
|
15
|
-
|
|
16
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
17
|
-
|
|
18
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
19
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
20
|
-
var ssrPrepass__default = /*#__PURE__*/_interopDefault(ssrPrepass);
|
|
21
|
-
|
|
22
|
-
function transformQueryOrMutationCacheErrors(result) {
|
|
23
|
-
var error = result.state.error;
|
|
24
|
-
|
|
25
|
-
if (error instanceof Error && error.name === 'TRPCClientError') {
|
|
26
|
-
var newError = {
|
|
27
|
-
message: error.message,
|
|
28
|
-
data: error.data,
|
|
29
|
-
shape: error.shape
|
|
30
|
-
};
|
|
31
|
-
return _objectSpread(_objectSpread({}, result), {}, {
|
|
32
|
-
state: _objectSpread(_objectSpread({}, result.state), {}, {
|
|
33
|
-
error: newError
|
|
34
|
-
})
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function withTRPC(opts) {
|
|
42
|
-
var getClientConfig = opts.config;
|
|
43
|
-
return function (AppOrPage) {
|
|
44
|
-
var trpc = react.createReactQueryHooks(opts);
|
|
45
|
-
|
|
46
|
-
var WithTRPC = function WithTRPC(props) {
|
|
47
|
-
var _props$pageProps;
|
|
48
|
-
|
|
49
|
-
var _useState = React.useState(function () {
|
|
50
|
-
if (props.trpc) {
|
|
51
|
-
return props.trpc;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var config = getClientConfig({});
|
|
55
|
-
var queryClient = new reactQuery.QueryClient(config.queryClientConfig);
|
|
56
|
-
var trpcClient = trpc.createClient(config);
|
|
57
|
-
return {
|
|
58
|
-
queryClient: queryClient,
|
|
59
|
-
trpcClient: trpcClient,
|
|
60
|
-
isPrepass: false,
|
|
61
|
-
ssrContext: null
|
|
62
|
-
};
|
|
63
|
-
}),
|
|
64
|
-
_useState2 = _slicedToArray(_useState, 1),
|
|
65
|
-
_useState2$ = _useState2[0],
|
|
66
|
-
queryClient = _useState2$.queryClient,
|
|
67
|
-
trpcClient = _useState2$.trpcClient,
|
|
68
|
-
isPrepass = _useState2$.isPrepass,
|
|
69
|
-
ssrContext = _useState2$.ssrContext;
|
|
70
|
-
|
|
71
|
-
var hydratedState = trpc.useDehydratedState((_props$pageProps = props.pageProps) === null || _props$pageProps === void 0 ? void 0 : _props$pageProps.trpcState);
|
|
72
|
-
return /*#__PURE__*/React__default['default'].createElement(trpc.Provider, {
|
|
73
|
-
client: trpcClient,
|
|
74
|
-
queryClient: queryClient,
|
|
75
|
-
isPrepass: isPrepass,
|
|
76
|
-
ssrContext: ssrContext
|
|
77
|
-
}, /*#__PURE__*/React__default['default'].createElement(reactQuery.QueryClientProvider, {
|
|
78
|
-
client: queryClient
|
|
79
|
-
}, /*#__PURE__*/React__default['default'].createElement(hydration.Hydrate, {
|
|
80
|
-
state: hydratedState
|
|
81
|
-
}, /*#__PURE__*/React__default['default'].createElement(AppOrPage, props))));
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (AppOrPage.getInitialProps || opts.ssr) {
|
|
85
|
-
WithTRPC.getInitialProps = /*#__PURE__*/function () {
|
|
86
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(appOrPageCtx) {
|
|
87
|
-
var _opts$responseMeta, _opts$responseMeta2;
|
|
88
|
-
|
|
89
|
-
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;
|
|
90
|
-
|
|
91
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
92
|
-
while (1) {
|
|
93
|
-
switch (_context.prev = _context.next) {
|
|
94
|
-
case 0:
|
|
95
|
-
AppTree = appOrPageCtx.AppTree; // Determine if we are wrapping an App component or a Page component.
|
|
96
|
-
|
|
97
|
-
isApp = !!appOrPageCtx.Component;
|
|
98
|
-
ctx = isApp ? appOrPageCtx.ctx : appOrPageCtx; // Run the wrapped component's getInitialProps function.
|
|
99
|
-
|
|
100
|
-
pageProps = {};
|
|
101
|
-
|
|
102
|
-
if (!AppOrPage.getInitialProps) {
|
|
103
|
-
_context.next = 10;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
_context.next = 7;
|
|
108
|
-
return AppOrPage.getInitialProps(appOrPageCtx);
|
|
109
|
-
|
|
110
|
-
case 7:
|
|
111
|
-
originalProps = _context.sent;
|
|
112
|
-
originalPageProps = isApp ? (_originalProps$pagePr = originalProps.pageProps) !== null && _originalProps$pagePr !== void 0 ? _originalProps$pagePr : {} : originalProps;
|
|
113
|
-
pageProps = _objectSpread(_objectSpread({}, originalPageProps), pageProps);
|
|
114
|
-
|
|
115
|
-
case 10:
|
|
116
|
-
getAppTreeProps = function getAppTreeProps(props) {
|
|
117
|
-
return isApp ? {
|
|
118
|
-
pageProps: props
|
|
119
|
-
} : props;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
if (!(typeof window !== 'undefined' || !opts.ssr)) {
|
|
123
|
-
_context.next = 13;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return _context.abrupt("return", getAppTreeProps(pageProps));
|
|
128
|
-
|
|
129
|
-
case 13:
|
|
130
|
-
config = getClientConfig({
|
|
131
|
-
ctx: ctx
|
|
132
|
-
});
|
|
133
|
-
trpcClient = react.createTRPCClient(config);
|
|
134
|
-
queryClient = new reactQuery.QueryClient(config.queryClientConfig);
|
|
135
|
-
trpcProp = {
|
|
136
|
-
config: config,
|
|
137
|
-
trpcClient: trpcClient,
|
|
138
|
-
queryClient: queryClient,
|
|
139
|
-
isPrepass: true,
|
|
140
|
-
ssrContext: ctx
|
|
141
|
-
};
|
|
142
|
-
prepassProps = {
|
|
143
|
-
pageProps: pageProps,
|
|
144
|
-
trpc: trpcProp
|
|
145
|
-
}; // Run the prepass step on AppTree. This will run all trpc queries on the server.
|
|
146
|
-
// multiple prepass ensures that we can do batching on the server
|
|
147
|
-
|
|
148
|
-
case 18:
|
|
149
|
-
|
|
150
|
-
_context.next = 21;
|
|
151
|
-
return ssrPrepass__default['default']( /*#__PURE__*/React.createElement(AppTree, prepassProps));
|
|
152
|
-
|
|
153
|
-
case 21:
|
|
154
|
-
if (queryClient.isFetching()) {
|
|
155
|
-
_context.next = 23;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return _context.abrupt("break", 27);
|
|
160
|
-
|
|
161
|
-
case 23:
|
|
162
|
-
_context.next = 25;
|
|
163
|
-
return new Promise(function (resolve) {
|
|
164
|
-
var unsub = queryClient.getQueryCache().subscribe(function (event) {
|
|
165
|
-
if ((event === null || event === void 0 ? void 0 : event.query.getObserversCount()) === 0) {
|
|
166
|
-
resolve();
|
|
167
|
-
unsub();
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
case 25:
|
|
173
|
-
_context.next = 18;
|
|
174
|
-
break;
|
|
175
|
-
|
|
176
|
-
case 27:
|
|
177
|
-
dehydratedCache = hydration.dehydrate(queryClient, {
|
|
178
|
-
shouldDehydrateQuery: function shouldDehydrateQuery() {
|
|
179
|
-
// makes sure errors are also dehydrated
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
}); // since error instances can't be serialized, let's make them into `TRPCClientErrorLike`-objects
|
|
183
|
-
|
|
184
|
-
dehydratedCacheWithErrors = _objectSpread(_objectSpread({}, dehydratedCache), {}, {
|
|
185
|
-
queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),
|
|
186
|
-
mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
|
|
187
|
-
}); // dehydrate query client's state and add it to the props
|
|
188
|
-
|
|
189
|
-
pageProps.trpcState = opts.transformer ? opts.transformer.serialize(dehydratedCacheWithErrors) : dehydratedCacheWithErrors;
|
|
190
|
-
appTreeProps = getAppTreeProps(pageProps);
|
|
191
|
-
meta = (_opts$responseMeta = (_opts$responseMeta2 = opts.responseMeta) === null || _opts$responseMeta2 === void 0 ? void 0 : _opts$responseMeta2.call(opts, {
|
|
192
|
-
ctx: ctx,
|
|
193
|
-
clientErrors: [].concat(_toConsumableArray(dehydratedCache.queries), _toConsumableArray(dehydratedCache.mutations)).map(function (v) {
|
|
194
|
-
return v.state.error;
|
|
195
|
-
}).flatMap(function (err) {
|
|
196
|
-
return err instanceof Error && err.name === 'TRPCClientError' ? [err] : [];
|
|
197
|
-
})
|
|
198
|
-
})) !== null && _opts$responseMeta !== void 0 ? _opts$responseMeta : {};
|
|
199
|
-
|
|
200
|
-
for (_i = 0, _Object$entries = Object.entries(meta); _i < _Object$entries.length; _i++) {
|
|
201
|
-
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
202
|
-
|
|
203
|
-
if (typeof value === 'string') {
|
|
204
|
-
(_ctx$res = ctx.res) === null || _ctx$res === void 0 ? void 0 : _ctx$res.setHeader(key, value);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (meta.status && ctx.res) {
|
|
209
|
-
ctx.res.statusCode = meta.status;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return _context.abrupt("return", appTreeProps);
|
|
213
|
-
|
|
214
|
-
case 35:
|
|
215
|
-
case "end":
|
|
216
|
-
return _context.stop();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}, _callee);
|
|
220
|
-
}));
|
|
221
|
-
|
|
222
|
-
return function (_x) {
|
|
223
|
-
return _ref.apply(this, arguments);
|
|
224
|
-
};
|
|
225
|
-
}();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
var displayName = AppOrPage.displayName || AppOrPage.name || 'Component';
|
|
229
|
-
WithTRPC.displayName = "withTRPC(".concat(displayName, ")");
|
|
230
|
-
return WithTRPC;
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function setupTRPC(opts) {
|
|
235
|
-
var hooks = react.createReactQueryHooks(opts);
|
|
236
|
-
|
|
237
|
-
var _withTRPC = withTRPC(opts);
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
useContext: hooks.useContext,
|
|
241
|
-
useInfiniteQuery: hooks.useInfiniteQuery,
|
|
242
|
-
useMutation: hooks.useMutation,
|
|
243
|
-
useQuery: hooks.useQuery,
|
|
244
|
-
useSubscription: hooks.useSubscription,
|
|
245
|
-
withTRPC: _withTRPC
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
exports.setupTRPC = setupTRPC;
|
|
250
|
-
exports.withTRPC = withTRPC;
|