@trpc/next 10.0.0-proxy-beta.11 → 10.0.0-proxy-beta.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCNext.d.ts","sourceRoot":"","sources":["../src/createTRPCNext.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EAIzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAY,MAAM,YAAY,CAAC;AAEhF,wBAAgB,cAAc,CAC5B,OAAO,SAAS,SAAS,EACzB,WAAW,SAAS,eAAe,GAAG,eAAe,EACrD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC;kBAuCjD,sBAAsB,OAAO,EAAE,WAAW,CAAC;;4DAG5D"}
1
+ {"version":3,"file":"createTRPCNext.d.ts","sourceRoot":"","sources":["../src/createTRPCNext.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EAIzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAY,MAAM,YAAY,CAAC;AAEhF,wBAAgB,cAAc,CAC5B,OAAO,SAAS,SAAS,EACzB,WAAW,SAAS,eAAe,GAAG,eAAe,EACrD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC;kBAOjD,sBAAsB,OAAO,EAAE,WAAW,CAAC;;4DAqB5D"}
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var react = require('@trpc/react');
8
8
  var React = require('react');
9
9
  var ssrPrepass = require('react-ssr-prepass');
10
10
  var shared = require('@trpc/react/shared');
11
+ var shared$1 = require('@trpc/server/shared');
11
12
 
12
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
 
@@ -169,34 +170,23 @@ function createTRPCNext(opts) {
169
170
  const hooks = shared.createHooksInternal();
170
171
  // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
171
172
  const _withTRPC = withTRPC(opts);
172
- const proxy = new Proxy(()=>{
173
- // no-op
174
- }, {
175
- get (_obj, name) {
176
- if (name === 'then') {
177
- return undefined;
178
- }
179
- if (name === 'useContext') {
180
- return ()=>{
181
- const context = hooks.useContext();
182
- // create a stable reference of the utils context
183
- return React.useMemo(()=>{
184
- return shared.createReactQueryUtilsProxy(context);
185
- }, [
186
- context
187
- ]);
188
- };
189
- }
190
- if (name === 'withTRPC') {
191
- return _withTRPC;
192
- }
193
- if (typeof name === 'string') {
194
- return shared.createReactProxyDecoration(name, hooks);
195
- }
196
- throw new Error('Not supported');
173
+ return shared$1.createFlatProxy((key)=>{
174
+ if (key === 'useContext') {
175
+ return ()=>{
176
+ const context = hooks.useContext();
177
+ // create a stable reference of the utils context
178
+ return React.useMemo(()=>{
179
+ return shared.createReactQueryUtilsProxy(context);
180
+ }, [
181
+ context
182
+ ]);
183
+ };
184
+ }
185
+ if (key === 'withTRPC') {
186
+ return _withTRPC;
197
187
  }
188
+ return shared.createReactProxyDecoration(key, hooks);
198
189
  });
199
- return proxy;
200
190
  }
201
191
 
202
192
  exports.createTRPCNext = createTRPCNext;
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ import { createReactQueryHooks, createTRPCClient } from '@trpc/react';
4
4
  import React, { createElement, useState, useMemo } from 'react';
5
5
  import ssrPrepass from 'react-ssr-prepass';
6
6
  import { createHooksInternal, createReactQueryUtilsProxy, createReactProxyDecoration } from '@trpc/react/shared';
7
+ import { createFlatProxy } from '@trpc/server/shared';
7
8
 
8
9
  function transformQueryOrMutationCacheErrors(result) {
9
10
  const error = result.state.error;
@@ -159,34 +160,23 @@ function createTRPCNext(opts) {
159
160
  const hooks = createHooksInternal();
160
161
  // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
161
162
  const _withTRPC = withTRPC(opts);
162
- const proxy = new Proxy(()=>{
163
- // no-op
164
- }, {
165
- get (_obj, name) {
166
- if (name === 'then') {
167
- return undefined;
168
- }
169
- if (name === 'useContext') {
170
- return ()=>{
171
- const context = hooks.useContext();
172
- // create a stable reference of the utils context
173
- return useMemo(()=>{
174
- return createReactQueryUtilsProxy(context);
175
- }, [
176
- context
177
- ]);
178
- };
179
- }
180
- if (name === 'withTRPC') {
181
- return _withTRPC;
182
- }
183
- if (typeof name === 'string') {
184
- return createReactProxyDecoration(name, hooks);
185
- }
186
- throw new Error('Not supported');
163
+ return createFlatProxy((key)=>{
164
+ if (key === 'useContext') {
165
+ return ()=>{
166
+ const context = hooks.useContext();
167
+ // create a stable reference of the utils context
168
+ return useMemo(()=>{
169
+ return createReactQueryUtilsProxy(context);
170
+ }, [
171
+ context
172
+ ]);
173
+ };
174
+ }
175
+ if (key === 'withTRPC') {
176
+ return _withTRPC;
187
177
  }
178
+ return createReactProxyDecoration(key, hooks);
188
179
  });
189
- return proxy;
190
180
  }
191
181
 
192
182
  export { createTRPCNext, withTRPC };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/next",
3
- "version": "10.0.0-proxy-beta.11",
3
+ "version": "10.0.0-proxy-beta.13",
4
4
  "description": "tRPC Next lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -36,9 +36,9 @@
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@tanstack/react-query": "^4.3.8",
39
- "@trpc/client": "10.0.0-proxy-beta.11",
40
- "@trpc/react": "10.0.0-proxy-beta.11",
41
- "@trpc/server": "10.0.0-proxy-beta.11",
39
+ "@trpc/client": "10.0.0-proxy-beta.13",
40
+ "@trpc/react": "10.0.0-proxy-beta.13",
41
+ "@trpc/server": "10.0.0-proxy-beta.13",
42
42
  "next": "*",
43
43
  "react": ">=16.8.0",
44
44
  "react-dom": ">=16.8.0"
@@ -49,9 +49,9 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@tanstack/react-query": "^4.3.8",
52
- "@trpc/client": "10.0.0-proxy-beta.11",
53
- "@trpc/react": "10.0.0-proxy-beta.11",
54
- "@trpc/server": "10.0.0-proxy-beta.11",
52
+ "@trpc/client": "10.0.0-proxy-beta.13",
53
+ "@trpc/react": "10.0.0-proxy-beta.13",
54
+ "@trpc/server": "10.0.0-proxy-beta.13",
55
55
  "@types/express": "^4.17.12",
56
56
  "@types/node": "^18.7.20",
57
57
  "express": "^4.17.1",
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "d6196218c3ed0857a2f8624f150c6be187176665"
66
+ "gitHead": "017ac71d5b0cc37d6c1fa22d03377a99a17b6dde"
67
67
  }
@@ -6,6 +6,7 @@ import {
6
6
  createReactQueryUtilsProxy,
7
7
  } from '@trpc/react/shared';
8
8
  import { AnyRouter } from '@trpc/server';
9
+ import { createFlatProxy } from '@trpc/server/shared';
9
10
  import { NextPageContext } from 'next/types';
10
11
  import { useMemo } from 'react';
11
12
  import { WithTRPCNoSSROptions, WithTRPCSSROptions, withTRPC } from './withTRPC';
@@ -19,40 +20,26 @@ export function createTRPCNext<
19
20
  // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
20
21
  const _withTRPC = withTRPC<TRouter, TSSRContext>(opts);
21
22
 
22
- const proxy: unknown = new Proxy(
23
- () => {
24
- // no-op
25
- },
26
- {
27
- get(_obj, name) {
28
- if (name === 'then') {
29
- return undefined;
30
- }
31
- if (name === 'useContext') {
32
- return () => {
33
- const context = hooks.useContext();
34
- // create a stable reference of the utils context
35
- return useMemo(() => {
36
- return (createReactQueryUtilsProxy as any)(context);
37
- }, [context]);
38
- };
39
- }
40
-
41
- if (name === 'withTRPC') {
42
- return _withTRPC;
43
- }
44
-
45
- if (typeof name === 'string') {
46
- return createReactProxyDecoration(name, hooks);
47
- }
48
-
49
- throw new Error('Not supported');
50
- },
51
- },
52
- );
53
-
54
- return proxy as {
23
+ type CreateTRPCNext = {
55
24
  useContext(): CreateReactUtilsProxy<TRouter, TSSRContext>;
56
25
  withTRPC: typeof _withTRPC;
57
26
  } & DecoratedProcedureRecord<TRouter['_def']['record']>;
27
+
28
+ return createFlatProxy<CreateTRPCNext>((key) => {
29
+ if (key === 'useContext') {
30
+ return () => {
31
+ const context = hooks.useContext();
32
+ // create a stable reference of the utils context
33
+ return useMemo(() => {
34
+ return (createReactQueryUtilsProxy as any)(context);
35
+ }, [context]);
36
+ };
37
+ }
38
+
39
+ if (key === 'withTRPC') {
40
+ return _withTRPC;
41
+ }
42
+
43
+ return createReactProxyDecoration(key as string, hooks);
44
+ });
58
45
  }