@trpc/client 10.0.0-proxy-alpha.57 → 10.0.0-proxy-alpha.60

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/README.md CHANGED
@@ -7,8 +7,7 @@
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
- <!-- TODO: replace with new version GIF -->
11
- <img src="https://storage.googleapis.com/trpc/trpcgif.gif" alt="Demo" />
10
+ <img src="https://assets.trpc.io/www/v10/preview-dark.gif" alt="Demo" />
12
11
  </p>
13
12
 
14
13
  # `@trpc/client`
@@ -23,13 +22,13 @@ Full documentation for `@trpc/client` can be found [here](https://trpc.io/docs/v
23
22
 
24
23
  ```bash
25
24
  # npm
26
- npm install @trpc/client
25
+ npm install @trpc/client@next
27
26
 
28
27
  # Yarn
29
- yarn add @trpc/client
28
+ yarn add @trpc/client@next
30
29
 
31
30
  # pnpm
32
- pnpm add @trpc/client
31
+ pnpm add @trpc/client@next
33
32
  ```
34
33
 
35
34
  ## Basic Example
@@ -1,13 +1,13 @@
1
1
  import type { AnyRouter, OmitNeverKeys, Procedure, ProcedureArgs, ProcedureRouterRecord, inferProcedureOutput } from '@trpc/server';
2
2
  import type { Unsubscribable, inferObservableValue } from '@trpc/server/observable';
3
- import type { TRPCResultMessage } from '@trpc/server/rpc';
4
3
  import { TRPCClientError } from './TRPCClientError';
5
4
  import { CreateTRPCClientOptions } from './createTRPCClient';
6
5
  import { TRPCClient as Client, TRPCSubscriptionObserver } from './internals/TRPCClient';
6
+ export declare type inferRouterProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
7
7
  declare type Resolver<TProcedure extends Procedure<any>> = (...args: ProcedureArgs<TProcedure['_def']>) => Promise<inferProcedureOutput<TProcedure>>;
8
8
  declare type SubscriptionResolver<TProcedure extends Procedure<any>, TRouter extends AnyRouter> = (...args: [
9
9
  input: ProcedureArgs<TProcedure['_def']>[0],
10
- opts: ProcedureArgs<TProcedure['_def']>[1] & Partial<TRPCSubscriptionObserver<TRPCResultMessage<inferObservableValue<inferProcedureOutput<TProcedure>>>, TRPCClientError<TRouter>>>
10
+ opts: ProcedureArgs<TProcedure['_def']>[1] & Partial<TRPCSubscriptionObserver<inferObservableValue<inferProcedureOutput<TProcedure>>, TRPCClientError<TRouter>>>
11
11
  ]) => Unsubscribable;
12
12
  declare type DecorateProcedure<TProcedure extends Procedure<any>, TRouter extends AnyRouter> = OmitNeverKeys<{
13
13
  query: TProcedure extends {
@@ -31,7 +31,7 @@ declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord,
31
31
  * @deprecated use `createTRPCProxyClient` instead
32
32
  * @internal
33
33
  */
34
- export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>;
35
- export declare function createTRPCProxyClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>;
34
+ export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): inferRouterProxyClient<TRouter>;
35
+ export declare function createTRPCProxyClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): inferRouterProxyClient<TRouter>;
36
36
  export {};
37
37
  //# sourceMappingURL=createTRPCClientProxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,aAAa,EACb,qBAAqB,EAErB,oBAAoB,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,C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O,CAAC,GACzC,KAAK,CAAC;CACX,CAAC,CAAC;AAEH,aAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/D;;GAEG;AACH,aAAK,wBAAwB,CAC3B,WAAW,SAAS,qBAAqB,EACzC,OAAO,SAAS,SAAS,IACvB,aAAa,CAAC;KACf,IAAI,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,SAAS,GAC5D,wBAAwB,CACtB,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACnC,WAAW,CAAC,IAAI,CAAC,CAClB,GACD,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,GAC/D,KAAK,GACL,iBAAiB,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC;CACnE,CAAC,CAAC;AAWH;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,mCAWxB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,mCAKvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getFetch.d.ts","sourceRoot":"","sources":["../src/getFetch.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,GAAG,OAAO,KAAK,CAYvD"}
1
+ {"version":3,"file":"getFetch.d.ts","sourceRoot":"","sources":["../src/getFetch.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,GAAG,OAAO,KAAK,CAcvD"}
@@ -11,8 +11,7 @@ function arrayToDict(array) {
11
11
  }
12
12
  const METHOD = {
13
13
  query: 'GET',
14
- mutation: 'POST',
15
- subscription: 'PATCH'
14
+ mutation: 'POST'
16
15
  };
17
16
  function getInput(opts) {
18
17
  return 'input' in opts ? opts.runtime.transformer.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.runtime.transformer.serialize(_input)));
@@ -48,7 +47,11 @@ function httpRequest(opts) {
48
47
  const url = getUrl(opts);
49
48
  const body = getBody(opts);
50
49
  const meta = {};
51
- Promise.resolve(runtime.headers()).then((headers)=>runtime.fetch(url, {
50
+ Promise.resolve(runtime.headers()).then((headers)=>{
51
+ if (type === 'subscription') {
52
+ throw new Error('Subscriptions should use wsLink');
53
+ }
54
+ return runtime.fetch(url, {
52
55
  method: METHOD[type],
53
56
  signal: ac?.signal,
54
57
  body: body,
@@ -56,7 +59,8 @@ function httpRequest(opts) {
56
59
  'content-type': 'application/json',
57
60
  ...headers
58
61
  }
59
- })).then((_res)=>{
62
+ });
63
+ }).then((_res)=>{
60
64
  meta.response = _res;
61
65
  return _res.json();
62
66
  }).then((json)=>{
@@ -9,8 +9,7 @@ function arrayToDict(array) {
9
9
  }
10
10
  const METHOD = {
11
11
  query: 'GET',
12
- mutation: 'POST',
13
- subscription: 'PATCH'
12
+ mutation: 'POST'
14
13
  };
15
14
  function getInput(opts) {
16
15
  return 'input' in opts ? opts.runtime.transformer.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.runtime.transformer.serialize(_input)));
@@ -46,7 +45,11 @@ function httpRequest(opts) {
46
45
  const url = getUrl(opts);
47
46
  const body = getBody(opts);
48
47
  const meta = {};
49
- Promise.resolve(runtime.headers()).then((headers)=>runtime.fetch(url, {
48
+ Promise.resolve(runtime.headers()).then((headers)=>{
49
+ if (type === 'subscription') {
50
+ throw new Error('Subscriptions should use wsLink');
51
+ }
52
+ return runtime.fetch(url, {
50
53
  method: METHOD[type],
51
54
  signal: ac?.signal,
52
55
  body: body,
@@ -54,7 +57,8 @@ function httpRequest(opts) {
54
57
  'content-type': 'application/json',
55
58
  ...headers
56
59
  }
57
- })).then((_res)=>{
60
+ });
61
+ }).then((_res)=>{
58
62
  meta.response = _res;
59
63
  return _res.json();
60
64
  }).then((json)=>{
package/dist/index.js CHANGED
@@ -10,17 +10,16 @@ var shared = require('@trpc/server/shared');
10
10
  var links_httpLink = require('./links/httpLink.js');
11
11
  var links_loggerLink = require('./links/loggerLink.js');
12
12
  var links_wsLink = require('./links/wsLink.js');
13
- require('./httpUtils-801112a6.js');
13
+ require('./httpUtils-0961d5e3.js');
14
14
 
15
15
  function getWindow() {
16
16
  if (typeof window !== 'undefined') {
17
17
  return window;
18
18
  }
19
- return global;
19
+ return globalThis;
20
20
  }
21
21
  function getAbortController(ac) {
22
- const win = getWindow();
23
- return (ac ?? win.AbortController) ?? undefined;
22
+ return (ac ?? getWindow().AbortController) ?? undefined;
24
23
  }
25
24
 
26
25
  function getFetch(f) {
@@ -28,8 +27,9 @@ function getFetch(f) {
28
27
  return f;
29
28
  }
30
29
  const win = getWindow();
31
- if (win.fetch) {
32
- return typeof win.fetch.bind === 'function' ? win.fetch.bind(win) : win.fetch;
30
+ const globalFetch = win.fetch;
31
+ if (globalFetch) {
32
+ return typeof globalFetch.bind === 'function' ? globalFetch.bind(win) : globalFetch;
33
33
  }
34
34
  throw new Error('No fetch implementation found');
35
35
  }
package/dist/index.mjs CHANGED
@@ -9,17 +9,16 @@ import { createProxy } from '@trpc/server/shared';
9
9
  export { httpLink } from './links/httpLink.mjs';
10
10
  export { loggerLink } from './links/loggerLink.mjs';
11
11
  export { createWSClient, wsLink } from './links/wsLink.mjs';
12
- import './httpUtils-44781613.mjs';
12
+ import './httpUtils-ad4258b6.mjs';
13
13
 
14
14
  function getWindow() {
15
15
  if (typeof window !== 'undefined') {
16
16
  return window;
17
17
  }
18
- return global;
18
+ return globalThis;
19
19
  }
20
20
  function getAbortController(ac) {
21
- const win = getWindow();
22
- return (ac ?? win.AbortController) ?? undefined;
21
+ return (ac ?? getWindow().AbortController) ?? undefined;
23
22
  }
24
23
 
25
24
  function getFetch(f) {
@@ -27,8 +26,9 @@ function getFetch(f) {
27
26
  return f;
28
27
  }
29
28
  const win = getWindow();
30
- if (win.fetch) {
31
- return typeof win.fetch.bind === 'function' ? win.fetch.bind(win) : win.fetch;
29
+ const globalFetch = win.fetch;
30
+ if (globalFetch) {
31
+ return typeof globalFetch.bind === 'function' ? globalFetch.bind(win) : globalFetch;
32
32
  }
33
33
  throw new Error('No fetch implementation found');
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetchHelpers.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/internals/fetchHelpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,sBAKxB;AACD,wBAAgB,kBAAkB,CAChC,EAAE,CAAC,EAAE,OAAO,eAAe,GAC1B,OAAO,eAAe,GAAG,SAAS,CAGpC"}
1
+ {"version":3,"file":"fetchHelpers.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/internals/fetchHelpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,sBAKxB;AACD,wBAAgB,kBAAkB,CAChC,EAAE,CAAC,EAAE,OAAO,eAAe,GAC1B,OAAO,eAAe,GAAG,SAAS,CAEpC"}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
6
  var transformResult = require('../transformResult-e15ccdf6.js');
7
- var httpUtils = require('../httpUtils-801112a6.js');
7
+ var httpUtils = require('../httpUtils-0961d5e3.js');
8
8
 
9
9
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
10
10
  * A function that should never be called unless we messed something up.
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import { t as transformResult, T as TRPCClientError } from '../transformResult-106791d7.mjs';
3
- import { g as getUrl, h as httpRequest } from '../httpUtils-44781613.mjs';
3
+ import { g as getUrl, h as httpRequest } from '../httpUtils-ad4258b6.mjs';
4
4
 
5
5
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
6
6
  * A function that should never be called unless we messed something up.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
6
  var transformResult = require('../transformResult-e15ccdf6.js');
7
- var httpUtils = require('../httpUtils-801112a6.js');
7
+ var httpUtils = require('../httpUtils-0961d5e3.js');
8
8
 
9
9
  function httpLink(opts) {
10
10
  const { url } = opts;
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import { t as transformResult, T as TRPCClientError } from '../transformResult-106791d7.mjs';
3
- import { h as httpRequest } from '../httpUtils-44781613.mjs';
3
+ import { h as httpRequest } from '../httpUtils-ad4258b6.mjs';
4
4
 
5
5
  function httpLink(opts) {
6
6
  const { url } = opts;
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE/D,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAkBD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE;QACJ,QAAQ,EAAE,QAAQ,CAAC;KACpB,CAAC;CACH;AAED,aAAK,eAAe,GAAG;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,CAAC;IAAE,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAUjD,oBAAY,kBAAkB,GAAG,eAAe,GAC9C,eAAe,GAAG;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,IA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;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CAwC9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.0.0-proxy-alpha.57",
3
+ "version": "10.0.0-proxy-alpha.60",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -63,13 +63,13 @@
63
63
  "ts-watch": "tsc --project tsconfig.watch.json"
64
64
  },
65
65
  "peerDependencies": {
66
- "@trpc/server": "10.0.0-proxy-alpha.57"
66
+ "@trpc/server": "10.0.0-proxy-alpha.60"
67
67
  },
68
68
  "devDependencies": {
69
- "@trpc/server": "10.0.0-proxy-alpha.57"
69
+ "@trpc/server": "10.0.0-proxy-alpha.60"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "e664229c3ffcfb1d6bccb890cbddebf3630fdd45"
74
+ "gitHead": "59424cddb6ac66a0ffafb66bf9e98d3cbfec09cf"
75
75
  }
@@ -14,7 +14,6 @@ import type {
14
14
  Unsubscribable,
15
15
  inferObservableValue,
16
16
  } from '@trpc/server/observable';
17
- import type { TRPCResultMessage } from '@trpc/server/rpc';
18
17
  import { createProxy } from '@trpc/server/shared';
19
18
  import { TRPCClientError } from './TRPCClientError';
20
19
  import { CreateTRPCClientOptions, createTRPCClient } from './createTRPCClient';
@@ -23,6 +22,9 @@ import {
23
22
  TRPCSubscriptionObserver,
24
23
  } from './internals/TRPCClient';
25
24
 
25
+ export type inferRouterProxyClient<TRouter extends AnyRouter> =
26
+ DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
27
+
26
28
  type Resolver<TProcedure extends Procedure<any>> = (
27
29
  ...args: ProcedureArgs<TProcedure['_def']>
28
30
  ) => Promise<inferProcedureOutput<TProcedure>>;
@@ -36,9 +38,7 @@ type SubscriptionResolver<
36
38
  opts: ProcedureArgs<TProcedure['_def']>[1] &
37
39
  Partial<
38
40
  TRPCSubscriptionObserver<
39
- TRPCResultMessage<
40
- inferObservableValue<inferProcedureOutput<TProcedure>>
41
- >,
41
+ inferObservableValue<inferProcedureOutput<TProcedure>>,
42
42
  TRPCClientError<TRouter>
43
43
  >
44
44
  >,
@@ -101,7 +101,7 @@ export function createTRPCClientProxy<TRouter extends AnyRouter>(
101
101
  const fullPath = pathCopy.join('.');
102
102
  return (client as any)[procedureType](fullPath, ...args);
103
103
  });
104
- return proxy as DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
104
+ return proxy as inferRouterProxyClient<TRouter>;
105
105
  }
106
106
 
107
107
  export function createTRPCProxyClient<TRouter extends AnyRouter>(
package/src/getFetch.ts CHANGED
@@ -4,11 +4,13 @@ export function getFetch(f?: typeof fetch): typeof fetch {
4
4
  if (f) {
5
5
  return f;
6
6
  }
7
+
7
8
  const win = getWindow();
8
- if (win.fetch) {
9
- return typeof win.fetch.bind === 'function'
10
- ? win.fetch.bind(win)
11
- : win.fetch;
9
+ const globalFetch = win.fetch;
10
+ if (globalFetch) {
11
+ return typeof globalFetch.bind === 'function'
12
+ ? globalFetch.bind(win)
13
+ : globalFetch;
12
14
  }
13
15
 
14
16
  throw new Error('No fetch implementation found');
@@ -2,11 +2,10 @@ export function getWindow() {
2
2
  if (typeof window !== 'undefined') {
3
3
  return window;
4
4
  }
5
- return global;
5
+ return globalThis;
6
6
  }
7
7
  export function getAbortController(
8
8
  ac?: typeof AbortController,
9
9
  ): typeof AbortController | undefined {
10
- const win = getWindow();
11
- return ac ?? win.AbortController ?? undefined;
10
+ return ac ?? getWindow().AbortController ?? undefined;
12
11
  }
@@ -19,7 +19,6 @@ function arrayToDict(array: unknown[]) {
19
19
  const METHOD = {
20
20
  query: 'GET',
21
21
  mutation: 'POST',
22
- subscription: 'PATCH',
23
22
  } as const;
24
23
 
25
24
  export interface HTTPResult {
@@ -87,8 +86,11 @@ export function httpRequest(
87
86
 
88
87
  const meta = {} as HTTPResult['meta'];
89
88
  Promise.resolve(runtime.headers())
90
- .then((headers) =>
91
- runtime.fetch(url, {
89
+ .then((headers) => {
90
+ if (type === 'subscription') {
91
+ throw new Error('Subscriptions should use wsLink');
92
+ }
93
+ return runtime.fetch(url, {
92
94
  method: METHOD[type],
93
95
  signal: ac?.signal,
94
96
  body: body,
@@ -96,8 +98,8 @@ export function httpRequest(
96
98
  'content-type': 'application/json',
97
99
  ...headers,
98
100
  },
99
- }),
100
- )
101
+ });
102
+ })
101
103
  .then((_res) => {
102
104
  meta.response = _res;
103
105
  return _res.json();