@trpc/client 10.33.0 → 10.33.1

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":"getFetch.d.ts","sourceRoot":"","sources":["../src/getFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAWjE,wBAAgB,QAAQ,CACtB,eAAe,CAAC,EAAE,UAAU,GAAG,gBAAgB,GAC9C,UAAU,CAcZ"}
1
+ {"version":3,"file":"getFetch.d.ts","sourceRoot":"","sources":["../src/getFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAMjE,wBAAgB,QAAQ,CACtB,eAAe,CAAC,EAAE,UAAU,GAAG,gBAAgB,GAC9C,UAAU,CAcZ"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  var observable = require('@trpc/server/observable');
4
4
  var transformResult = require('./transformResult-70f95ffb.js');
5
- var httpUtils = require('./httpUtils-4e5cf721.js');
5
+ var httpUtils = require('./httpUtils-fa0d6f71.js');
6
6
 
7
7
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
8
8
  * 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-9a244fe7.mjs';
3
- import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-9d0d09cb.mjs';
3
+ import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-a9242d4e.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.
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import { t as transformResult, T as TRPCClientError } from './transformResult-ae8e970c.js';
3
- import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-c937fe75.js';
3
+ import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-a0ac1597.js';
4
4
 
5
5
  /**
6
6
  * A function that should never be called unless we messed something up.
@@ -1,17 +1,13 @@
1
1
  const isFunction = (fn) => typeof fn === 'function';
2
- function _bind(fn, thisArg) {
3
- // eslint-disable-next-line @typescript-eslint/unbound-method
4
- return isFunction(fn.bind) ? fn.bind(thisArg) : fn;
5
- }
6
2
  function getFetch(customFetchImpl) {
7
3
  if (customFetchImpl) {
8
4
  return customFetchImpl;
9
5
  }
10
6
  if (typeof window !== 'undefined' && isFunction(window.fetch)) {
11
- return _bind(window.fetch, window);
7
+ return window.fetch;
12
8
  }
13
9
  if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
14
- return _bind(globalThis.fetch, globalThis);
10
+ return globalThis.fetch;
15
11
  }
16
12
  throw new Error('No fetch implementation found');
17
13
  }
@@ -32,7 +28,7 @@ function getAbortController(customAbortControllerImpl) {
32
28
  function resolveHTTPLinkOptions(opts) {
33
29
  return {
34
30
  url: opts.url,
35
- fetch: getFetch(opts.fetch),
31
+ fetch: opts.fetch,
36
32
  AbortController: getAbortController(opts.AbortController),
37
33
  };
38
34
  }
@@ -104,7 +100,7 @@ async function fetchHTTPResponse(opts, ac) {
104
100
  : {}),
105
101
  ...resolvedHeaders,
106
102
  };
107
- return opts.fetch(url, {
103
+ return getFetch(opts.fetch)(url, {
108
104
  method: METHOD[type],
109
105
  signal: ac?.signal,
110
106
  body: body,
@@ -1,17 +1,13 @@
1
1
  const isFunction = (fn)=>typeof fn === 'function';
2
- function _bind(fn, thisArg) {
3
- // eslint-disable-next-line @typescript-eslint/unbound-method
4
- return isFunction(fn.bind) ? fn.bind(thisArg) : fn;
5
- }
6
2
  function getFetch(customFetchImpl) {
7
3
  if (customFetchImpl) {
8
4
  return customFetchImpl;
9
5
  }
10
6
  if (typeof window !== 'undefined' && isFunction(window.fetch)) {
11
- return _bind(window.fetch, window);
7
+ return window.fetch;
12
8
  }
13
9
  if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
14
- return _bind(globalThis.fetch, globalThis);
10
+ return globalThis.fetch;
15
11
  }
16
12
  throw new Error('No fetch implementation found');
17
13
  }
@@ -32,7 +28,7 @@ function getAbortController(customAbortControllerImpl) {
32
28
  function resolveHTTPLinkOptions(opts) {
33
29
  return {
34
30
  url: opts.url,
35
- fetch: getFetch(opts.fetch),
31
+ fetch: opts.fetch,
36
32
  AbortController: getAbortController(opts.AbortController)
37
33
  };
38
34
  }
@@ -101,7 +97,7 @@ async function fetchHTTPResponse(opts, ac) {
101
97
  } : {},
102
98
  ...resolvedHeaders
103
99
  };
104
- return opts.fetch(url, {
100
+ return getFetch(opts.fetch)(url, {
105
101
  method: METHOD[type],
106
102
  signal: ac?.signal,
107
103
  body: body,
@@ -1,19 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const isFunction = (fn)=>typeof fn === 'function';
4
- function _bind(fn, thisArg) {
5
- // eslint-disable-next-line @typescript-eslint/unbound-method
6
- return isFunction(fn.bind) ? fn.bind(thisArg) : fn;
7
- }
8
4
  function getFetch(customFetchImpl) {
9
5
  if (customFetchImpl) {
10
6
  return customFetchImpl;
11
7
  }
12
8
  if (typeof window !== 'undefined' && isFunction(window.fetch)) {
13
- return _bind(window.fetch, window);
9
+ return window.fetch;
14
10
  }
15
11
  if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
16
- return _bind(globalThis.fetch, globalThis);
12
+ return globalThis.fetch;
17
13
  }
18
14
  throw new Error('No fetch implementation found');
19
15
  }
@@ -34,7 +30,7 @@ function getAbortController(customAbortControllerImpl) {
34
30
  function resolveHTTPLinkOptions(opts) {
35
31
  return {
36
32
  url: opts.url,
37
- fetch: getFetch(opts.fetch),
33
+ fetch: opts.fetch,
38
34
  AbortController: getAbortController(opts.AbortController)
39
35
  };
40
36
  }
@@ -103,7 +99,7 @@ async function fetchHTTPResponse(opts, ac) {
103
99
  } : {},
104
100
  ...resolvedHeaders
105
101
  };
106
- return opts.fetch(url, {
102
+ return getFetch(opts.fetch)(url, {
107
103
  method: METHOD[type],
108
104
  signal: ac?.signal,
109
105
  body: body,
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ var observable = require('@trpc/server/observable');
6
6
  var links_splitLink = require('./splitLink-f29e84be.js');
7
7
  var transformResult = require('./transformResult-70f95ffb.js');
8
8
  var shared = require('@trpc/server/shared');
9
- var httpUtils = require('./httpUtils-4e5cf721.js');
10
- var links_httpBatchLink = require('./httpBatchLink-3e9aaa76.js');
9
+ var httpUtils = require('./httpUtils-fa0d6f71.js');
10
+ var links_httpBatchLink = require('./httpBatchLink-76c6f2d4.js');
11
11
  var links_httpLink = require('./links/httpLink.js');
12
12
  var links_loggerLink = require('./links/loggerLink.js');
13
13
  var links_wsLink = require('./links/wsLink.js');
package/dist/index.mjs CHANGED
@@ -4,10 +4,10 @@ export { s as splitLink } from './splitLink-4c75f7be.mjs';
4
4
  import { T as TRPCClientError } from './transformResult-9a244fe7.mjs';
5
5
  export { T as TRPCClientError } from './transformResult-9a244fe7.mjs';
6
6
  import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
7
- import { f as fetchHTTPResponse, g as getUrl, a as getBody$1, h as httpRequest } from './httpUtils-9d0d09cb.mjs';
8
- export { b as getFetch } from './httpUtils-9d0d09cb.mjs';
9
- import { c as createHTTPBatchLink } from './httpBatchLink-5d821c7a.mjs';
10
- export { h as httpBatchLink } from './httpBatchLink-5d821c7a.mjs';
7
+ import { f as fetchHTTPResponse, g as getUrl, a as getBody$1, h as httpRequest } from './httpUtils-a9242d4e.mjs';
8
+ export { b as getFetch } from './httpUtils-a9242d4e.mjs';
9
+ import { c as createHTTPBatchLink } from './httpBatchLink-c184c799.mjs';
10
+ export { h as httpBatchLink } from './httpBatchLink-c184c799.mjs';
11
11
  import { httpLinkFactory } from './links/httpLink.mjs';
12
12
  export { httpLink, httpLinkFactory } from './links/httpLink.mjs';
13
13
  export { loggerLink } from './links/loggerLink.mjs';
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var links_httpBatchLink = require('../httpBatchLink-3e9aaa76.js');
6
- require('../httpUtils-4e5cf721.js');
5
+ var links_httpBatchLink = require('../httpBatchLink-76c6f2d4.js');
6
+ require('../httpUtils-fa0d6f71.js');
7
7
  require('@trpc/server/observable');
8
8
  require('../transformResult-70f95ffb.js');
9
9
 
@@ -1,4 +1,4 @@
1
- export { h as httpBatchLink } from '../httpBatchLink-5d821c7a.mjs';
2
- import '../httpUtils-9d0d09cb.mjs';
1
+ export { h as httpBatchLink } from '../httpBatchLink-c184c799.mjs';
2
+ import '../httpUtils-a9242d4e.mjs';
3
3
  import '@trpc/server/observable';
4
4
  import '../transformResult-9a244fe7.mjs';
@@ -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-70f95ffb.js');
7
- var httpUtils = require('../httpUtils-4e5cf721.js');
7
+ var httpUtils = require('../httpUtils-fa0d6f71.js');
8
8
 
9
9
  function httpLinkFactory(factoryOpts) {
10
10
  return (opts)=>{
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import { t as transformResult, T as TRPCClientError } from '../transformResult-9a244fe7.mjs';
3
- import { r as resolveHTTPLinkOptions, j as jsonHttpRequester } from '../httpUtils-9d0d09cb.mjs';
3
+ import { r as resolveHTTPLinkOptions, j as jsonHttpRequester } from '../httpUtils-a9242d4e.mjs';
4
4
 
5
5
  function httpLinkFactory(factoryOpts) {
6
6
  return (opts)=>{
@@ -19,7 +19,7 @@ export interface HTTPLinkBaseOptions {
19
19
  }
20
20
  export interface ResolvedHTTPLinkOptions {
21
21
  url: string;
22
- fetch: FetchEsque;
22
+ fetch?: FetchEsque;
23
23
  AbortController: AbortControllerEsque | null;
24
24
  }
25
25
  export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions): ResolvedHTTPLinkOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC9C;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,mBAAmB,GACxB,uBAAuB,CAMzB;AAiBD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE;QACJ,QAAQ,EAAE,aAAa,CAAC;KACzB,CAAC;CACH;AAED,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,CAAC;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CAAC;AAU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K,MAAM,CAAC;AAC9D,MAAM,MAAM,OAAO,GAAG,CACpB,IAAI,EAAE,sBAAsB,KACzB,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,CAAC,EAAE,QAAQ,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAgBpB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,OAMrB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,sBAAsB,GAAG;IAC7B,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,KACE,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAElC,eAAO,MAAM,iBAAiB,EAAE,SAO/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAC7C,sBAAsB,GAAG;IACvB,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC,CAAC;AAEJ,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,EACxB,EAAE,CAAC,EAAE,4BAA4B,GAAG,IAAI,0BA0BzC;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CAsB9B"}
@@ -34,6 +34,11 @@ export interface LoggerLinkOptions<TRouter extends AnyRouter> {
34
34
  * Used in the built-in defaultLogger
35
35
  */
36
36
  console?: ConsoleEsque;
37
+ /**
38
+ * Color mode
39
+ * @default typeof window === 'undefined' ? 'ansi' : 'css'
40
+ */
41
+ colorMode?: 'ansi' | 'css';
37
42
  }
38
43
  export declare function loggerLink<TRouter extends AnyRouter = AnyRouter>(opts?: LoggerLinkOptions<TRouter>): TRPCLink<TRouter>;
39
44
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvE,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,KAAK,eAAe,CAAC,OAAO,SAAS,SAAS,IAC1C;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;CACrE,GACD,CAAC,SAAS,GAAG;IACX,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC,CAAC;AACP,KAAK,SAAS,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1C,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,KAC3B,OAAO,CAAC;AAEb,KAAK,mBAAmB,CAAC,OAAO,SAAS,SAAS,IAAI,SAAS,GAC7D,CACI;IACE;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACpE,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;CACjB,CACJ,CAAC;AAEJ,KAAK,YAAY,CAAC,OAAO,SAAS,SAAS,IAAI,CAC7C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,KAC/B,IAAI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,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACpE,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;CACjB,CACJ,CAAC;AAEJ,KAAK,YAAY,CAAC,OAAO,SAAS,SAAS,IAAI,CAC7C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,KAC/B,IAAI,CAAC;AAEV,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,SAAS;IAC1D,MAAM,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC7B;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5B;AAsID,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CA6CnB"}
@@ -5,20 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var observable = require('@trpc/server/observable');
6
6
 
7
7
  /// <reference lib="dom.iterable" />
8
- const palette = {
9
- query: [
10
- '72e3ff',
11
- '3fb0d8'
12
- ],
13
- mutation: [
14
- 'c5a3fc',
15
- '904dfc'
16
- ],
17
- subscription: [
18
- 'ff49e1',
19
- 'd83fbe'
20
- ]
21
- };
22
8
  function isFormData(value) {
23
9
  if (typeof FormData === 'undefined') {
24
10
  // FormData is not supported
@@ -26,43 +12,116 @@ function isFormData(value) {
26
12
  }
27
13
  return value instanceof FormData;
28
14
  }
29
- // maybe this should be moved to it's own package
30
- const defaultLogger = (c = console)=>(props)=>{
31
- const { direction , type , path , context , id } = props;
32
- const [light, dark] = palette[type];
33
- const rawInput = props.input;
34
- const input = isFormData(rawInput) ? Object.fromEntries(rawInput) : rawInput;
35
- const css = `
36
- background-color: #${direction === 'up' ? light : dark};
37
- color: ${direction === 'up' ? 'black' : 'white'};
38
- padding: 2px;
39
- `;
40
- const parts = [
41
- '%c',
42
- direction === 'up' ? '>>' : '<<',
43
- type,
44
- `#${id}`,
45
- `%c${path}%c`,
46
- '%O'
47
- ];
48
- const args = [
49
- css,
50
- `${css}; font-weight: bold;`,
51
- `${css}; font-weight: normal;`
52
- ];
53
- if (props.direction === 'up') {
15
+ const palettes = {
16
+ css: {
17
+ query: [
18
+ '72e3ff',
19
+ '3fb0d8'
20
+ ],
21
+ mutation: [
22
+ 'c5a3fc',
23
+ '904dfc'
24
+ ],
25
+ subscription: [
26
+ 'ff49e1',
27
+ 'd83fbe'
28
+ ]
29
+ },
30
+ ansi: {
31
+ regular: {
32
+ // Cyan background, black and white text respectively
33
+ query: [
34
+ '\x1b[30;46m',
35
+ '\x1b[97;46m'
36
+ ],
37
+ // Magenta background, black and white text respectively
38
+ mutation: [
39
+ '\x1b[30;45m',
40
+ '\x1b[97;45m'
41
+ ],
42
+ // Green background, black and white text respectively
43
+ subscription: [
44
+ '\x1b[30;42m',
45
+ '\x1b[97;42m'
46
+ ]
47
+ },
48
+ bold: {
49
+ query: [
50
+ '\x1b[1;30;46m',
51
+ '\x1b[1;97;46m'
52
+ ],
53
+ mutation: [
54
+ '\x1b[1;30;45m',
55
+ '\x1b[1;97;45m'
56
+ ],
57
+ subscription: [
58
+ '\x1b[1;30;42m',
59
+ '\x1b[1;97;42m'
60
+ ]
61
+ }
62
+ }
63
+ };
64
+ function constructPartsAndArgs(opts) {
65
+ const { direction , type , path , id , input } = opts;
66
+ const parts = [];
67
+ const args = [];
68
+ if (opts.colorMode === 'ansi') {
69
+ const [lightRegular, darkRegular] = palettes.ansi.regular[type];
70
+ const [lightBold, darkBold] = palettes.ansi.bold[type];
71
+ const reset = '\x1b[0m';
72
+ parts.push(direction === 'up' ? lightRegular : darkRegular, direction === 'up' ? '>>' : '<<', type, direction === 'up' ? lightBold : darkBold, `#${id}`, path, reset);
73
+ if (direction === 'up') {
54
74
  args.push({
55
- input,
56
- context: context
75
+ input: opts.input
57
76
  });
58
77
  } else {
59
78
  args.push({
60
- input,
61
- result: props.result,
62
- elapsedMs: props.elapsedMs,
63
- context
79
+ input: opts.input,
80
+ // strip context from result cause it's too noisy in terminal wihtout collapse mode
81
+ result: 'result' in opts.result ? opts.result.result : opts.result,
82
+ elapsedMs: opts.elapsedMs
64
83
  });
65
84
  }
85
+ return {
86
+ parts,
87
+ args
88
+ };
89
+ }
90
+ const [light, dark] = palettes.css[type];
91
+ const css = `
92
+ background-color: #${direction === 'up' ? light : dark};
93
+ color: ${direction === 'up' ? 'black' : 'white'};
94
+ padding: 2px;
95
+ `;
96
+ parts.push('%c', direction === 'up' ? '>>' : '<<', type, `#${id}`, `%c${path}%c`, '%O');
97
+ args.push(css, `${css}; font-weight: bold;`, `${css}; font-weight: normal;`);
98
+ if (direction === 'up') {
99
+ args.push({
100
+ input,
101
+ context: opts.context
102
+ });
103
+ } else {
104
+ args.push({
105
+ input,
106
+ result: opts.result,
107
+ elapsedMs: opts.elapsedMs,
108
+ context: opts.context
109
+ });
110
+ }
111
+ return {
112
+ parts,
113
+ args
114
+ };
115
+ }
116
+ // maybe this should be moved to it's own package
117
+ const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
118
+ const rawInput = props.input;
119
+ const input = isFormData(rawInput) ? Object.fromEntries(rawInput) : rawInput;
120
+ const { parts , args } = constructPartsAndArgs({
121
+ ...props,
122
+ colorMode,
123
+ input
124
+ });
66
125
  const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result) ? 'error' : 'log';
67
126
  c[fn].apply(null, [
68
127
  parts.join(' ')
@@ -70,7 +129,11 @@ const defaultLogger = (c = console)=>(props)=>{
70
129
  };
71
130
  function loggerLink(opts = {}) {
72
131
  const { enabled =()=>true } = opts;
73
- const { logger =defaultLogger(opts.console) } = opts;
132
+ const colorMode = opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
133
+ const { logger =defaultLogger({
134
+ c: opts.console,
135
+ colorMode
136
+ }) } = opts;
74
137
  return ()=>{
75
138
  return ({ op , next })=>{
76
139
  return observable.observable((observer)=>{
@@ -1,20 +1,6 @@
1
1
  import { observable, tap } from '@trpc/server/observable';
2
2
 
3
3
  /// <reference lib="dom.iterable" />
4
- const palette = {
5
- query: [
6
- '72e3ff',
7
- '3fb0d8'
8
- ],
9
- mutation: [
10
- 'c5a3fc',
11
- '904dfc'
12
- ],
13
- subscription: [
14
- 'ff49e1',
15
- 'd83fbe'
16
- ]
17
- };
18
4
  function isFormData(value) {
19
5
  if (typeof FormData === 'undefined') {
20
6
  // FormData is not supported
@@ -22,43 +8,116 @@ function isFormData(value) {
22
8
  }
23
9
  return value instanceof FormData;
24
10
  }
25
- // maybe this should be moved to it's own package
26
- const defaultLogger = (c = console)=>(props)=>{
27
- const { direction , type , path , context , id } = props;
28
- const [light, dark] = palette[type];
29
- const rawInput = props.input;
30
- const input = isFormData(rawInput) ? Object.fromEntries(rawInput) : rawInput;
31
- const css = `
32
- background-color: #${direction === 'up' ? light : dark};
33
- color: ${direction === 'up' ? 'black' : 'white'};
34
- padding: 2px;
35
- `;
36
- const parts = [
37
- '%c',
38
- direction === 'up' ? '>>' : '<<',
39
- type,
40
- `#${id}`,
41
- `%c${path}%c`,
42
- '%O'
43
- ];
44
- const args = [
45
- css,
46
- `${css}; font-weight: bold;`,
47
- `${css}; font-weight: normal;`
48
- ];
49
- if (props.direction === 'up') {
11
+ const palettes = {
12
+ css: {
13
+ query: [
14
+ '72e3ff',
15
+ '3fb0d8'
16
+ ],
17
+ mutation: [
18
+ 'c5a3fc',
19
+ '904dfc'
20
+ ],
21
+ subscription: [
22
+ 'ff49e1',
23
+ 'd83fbe'
24
+ ]
25
+ },
26
+ ansi: {
27
+ regular: {
28
+ // Cyan background, black and white text respectively
29
+ query: [
30
+ '\x1b[30;46m',
31
+ '\x1b[97;46m'
32
+ ],
33
+ // Magenta background, black and white text respectively
34
+ mutation: [
35
+ '\x1b[30;45m',
36
+ '\x1b[97;45m'
37
+ ],
38
+ // Green background, black and white text respectively
39
+ subscription: [
40
+ '\x1b[30;42m',
41
+ '\x1b[97;42m'
42
+ ]
43
+ },
44
+ bold: {
45
+ query: [
46
+ '\x1b[1;30;46m',
47
+ '\x1b[1;97;46m'
48
+ ],
49
+ mutation: [
50
+ '\x1b[1;30;45m',
51
+ '\x1b[1;97;45m'
52
+ ],
53
+ subscription: [
54
+ '\x1b[1;30;42m',
55
+ '\x1b[1;97;42m'
56
+ ]
57
+ }
58
+ }
59
+ };
60
+ function constructPartsAndArgs(opts) {
61
+ const { direction , type , path , id , input } = opts;
62
+ const parts = [];
63
+ const args = [];
64
+ if (opts.colorMode === 'ansi') {
65
+ const [lightRegular, darkRegular] = palettes.ansi.regular[type];
66
+ const [lightBold, darkBold] = palettes.ansi.bold[type];
67
+ const reset = '\x1b[0m';
68
+ parts.push(direction === 'up' ? lightRegular : darkRegular, direction === 'up' ? '>>' : '<<', type, direction === 'up' ? lightBold : darkBold, `#${id}`, path, reset);
69
+ if (direction === 'up') {
50
70
  args.push({
51
- input,
52
- context: context
71
+ input: opts.input
53
72
  });
54
73
  } else {
55
74
  args.push({
56
- input,
57
- result: props.result,
58
- elapsedMs: props.elapsedMs,
59
- context
75
+ input: opts.input,
76
+ // strip context from result cause it's too noisy in terminal wihtout collapse mode
77
+ result: 'result' in opts.result ? opts.result.result : opts.result,
78
+ elapsedMs: opts.elapsedMs
60
79
  });
61
80
  }
81
+ return {
82
+ parts,
83
+ args
84
+ };
85
+ }
86
+ const [light, dark] = palettes.css[type];
87
+ const css = `
88
+ background-color: #${direction === 'up' ? light : dark};
89
+ color: ${direction === 'up' ? 'black' : 'white'};
90
+ padding: 2px;
91
+ `;
92
+ parts.push('%c', direction === 'up' ? '>>' : '<<', type, `#${id}`, `%c${path}%c`, '%O');
93
+ args.push(css, `${css}; font-weight: bold;`, `${css}; font-weight: normal;`);
94
+ if (direction === 'up') {
95
+ args.push({
96
+ input,
97
+ context: opts.context
98
+ });
99
+ } else {
100
+ args.push({
101
+ input,
102
+ result: opts.result,
103
+ elapsedMs: opts.elapsedMs,
104
+ context: opts.context
105
+ });
106
+ }
107
+ return {
108
+ parts,
109
+ args
110
+ };
111
+ }
112
+ // maybe this should be moved to it's own package
113
+ const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
114
+ const rawInput = props.input;
115
+ const input = isFormData(rawInput) ? Object.fromEntries(rawInput) : rawInput;
116
+ const { parts , args } = constructPartsAndArgs({
117
+ ...props,
118
+ colorMode,
119
+ input
120
+ });
62
121
  const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result) ? 'error' : 'log';
63
122
  c[fn].apply(null, [
64
123
  parts.join(' ')
@@ -66,7 +125,11 @@ const defaultLogger = (c = console)=>(props)=>{
66
125
  };
67
126
  function loggerLink(opts = {}) {
68
127
  const { enabled =()=>true } = opts;
69
- const { logger =defaultLogger(opts.console) } = opts;
128
+ const colorMode = opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
129
+ const { logger =defaultLogger({
130
+ c: opts.console,
131
+ colorMode
132
+ }) } = opts;
70
133
  return ()=>{
71
134
  return ({ op , next })=>{
72
135
  return observable((observer)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.33.0",
3
+ "version": "10.33.1",
4
4
  "description": "The tRPC client library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -76,11 +76,11 @@
76
76
  "!**/*.test.*"
77
77
  ],
78
78
  "peerDependencies": {
79
- "@trpc/server": "10.33.0"
79
+ "@trpc/server": "10.33.1"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@testing-library/dom": "^9.0.0",
83
- "@trpc/server": "10.33.0",
83
+ "@trpc/server": "10.33.1",
84
84
  "@types/isomorphic-fetch": "^0.0.36",
85
85
  "@types/node": "^18.16.16",
86
86
  "eslint": "^8.40.0",
@@ -98,5 +98,5 @@
98
98
  "funding": [
99
99
  "https://trpc.io/sponsor"
100
100
  ],
101
- "gitHead": "b92f34aacd300402f4c41e3f4a5b1f236f490672"
101
+ "gitHead": "403be02df05c29a9c3a77256805674baf6b6b125"
102
102
  }
package/src/getFetch.ts CHANGED
@@ -4,11 +4,6 @@ type AnyFn = (...args: any[]) => unknown;
4
4
 
5
5
  const isFunction = (fn: unknown): fn is AnyFn => typeof fn === 'function';
6
6
 
7
- function _bind(fn: AnyFn, thisArg: unknown): AnyFn {
8
- // eslint-disable-next-line @typescript-eslint/unbound-method
9
- return isFunction(fn.bind) ? fn.bind(thisArg) : fn;
10
- }
11
-
12
7
  export function getFetch(
13
8
  customFetchImpl?: FetchEsque | NativeFetchEsque,
14
9
  ): FetchEsque {
@@ -17,11 +12,11 @@ export function getFetch(
17
12
  }
18
13
 
19
14
  if (typeof window !== 'undefined' && isFunction(window.fetch)) {
20
- return _bind(window.fetch, window) as FetchEsque;
15
+ return window.fetch as FetchEsque;
21
16
  }
22
17
 
23
18
  if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
24
- return _bind(globalThis.fetch, globalThis) as FetchEsque;
19
+ return globalThis.fetch as FetchEsque;
25
20
  }
26
21
 
27
22
  throw new Error('No fetch implementation found');
@@ -29,7 +29,7 @@ export interface HTTPLinkBaseOptions {
29
29
 
30
30
  export interface ResolvedHTTPLinkOptions {
31
31
  url: string;
32
- fetch: FetchEsque;
32
+ fetch?: FetchEsque;
33
33
  AbortController: AbortControllerEsque | null;
34
34
  }
35
35
 
@@ -38,7 +38,7 @@ export function resolveHTTPLinkOptions(
38
38
  ): ResolvedHTTPLinkOptions {
39
39
  return {
40
40
  url: opts.url,
41
- fetch: getFetch(opts.fetch),
41
+ fetch: opts.fetch,
42
42
  AbortController: getAbortController(opts.AbortController),
43
43
  };
44
44
  }
@@ -164,7 +164,7 @@ export async function fetchHTTPResponse(
164
164
  ...resolvedHeaders,
165
165
  };
166
166
 
167
- return opts.fetch(url, {
167
+ return getFetch(opts.fetch)(url, {
168
168
  method: METHOD[type],
169
169
  signal: ac?.signal,
170
170
  body: body,
@@ -49,11 +49,6 @@ type LoggerLinkFn<TRouter extends AnyRouter> = (
49
49
  opts: LoggerLinkFnOptions<TRouter>,
50
50
  ) => void;
51
51
 
52
- const palette = {
53
- query: ['72e3ff', '3fb0d8'],
54
- mutation: ['c5a3fc', '904dfc'],
55
- subscription: ['ff49e1', 'd83fbe'],
56
- };
57
52
  export interface LoggerLinkOptions<TRouter extends AnyRouter> {
58
53
  logger?: LoggerLinkFn<TRouter>;
59
54
  enabled?: EnabledFn<TRouter>;
@@ -61,6 +56,11 @@ export interface LoggerLinkOptions<TRouter extends AnyRouter> {
61
56
  * Used in the built-in defaultLogger
62
57
  */
63
58
  console?: ConsoleEsque;
59
+ /**
60
+ * Color mode
61
+ * @default typeof window === 'undefined' ? 'ansi' : 'css'
62
+ */
63
+ colorMode?: 'ansi' | 'css';
64
64
  }
65
65
 
66
66
  function isFormData(value: unknown): value is FormData {
@@ -71,50 +71,120 @@ function isFormData(value: unknown): value is FormData {
71
71
  return value instanceof FormData;
72
72
  }
73
73
 
74
+ const palettes = {
75
+ css: {
76
+ query: ['72e3ff', '3fb0d8'],
77
+ mutation: ['c5a3fc', '904dfc'],
78
+ subscription: ['ff49e1', 'd83fbe'],
79
+ },
80
+ ansi: {
81
+ regular: {
82
+ // Cyan background, black and white text respectively
83
+ query: ['\x1b[30;46m', '\x1b[97;46m'],
84
+ // Magenta background, black and white text respectively
85
+ mutation: ['\x1b[30;45m', '\x1b[97;45m'],
86
+ // Green background, black and white text respectively
87
+ subscription: ['\x1b[30;42m', '\x1b[97;42m'],
88
+ },
89
+ bold: {
90
+ query: ['\x1b[1;30;46m', '\x1b[1;97;46m'],
91
+ mutation: ['\x1b[1;30;45m', '\x1b[1;97;45m'],
92
+ subscription: ['\x1b[1;30;42m', '\x1b[1;97;42m'],
93
+ },
94
+ },
95
+ } as const;
96
+
97
+ function constructPartsAndArgs(
98
+ opts: LoggerLinkFnOptions<any> & {
99
+ colorMode: 'ansi' | 'css';
100
+ },
101
+ ) {
102
+ const { direction, type, path, id, input } = opts;
103
+
104
+ const parts: string[] = [];
105
+ const args: any[] = [];
106
+
107
+ if (opts.colorMode === 'ansi') {
108
+ const [lightRegular, darkRegular] = palettes.ansi.regular[type];
109
+ const [lightBold, darkBold] = palettes.ansi.bold[type];
110
+ const reset = '\x1b[0m';
111
+
112
+ parts.push(
113
+ direction === 'up' ? lightRegular : darkRegular,
114
+ direction === 'up' ? '>>' : '<<',
115
+ type,
116
+ direction === 'up' ? lightBold : darkBold,
117
+ `#${id}`,
118
+ path,
119
+ reset,
120
+ );
121
+
122
+ if (direction === 'up') {
123
+ args.push({ input: opts.input });
124
+ } else {
125
+ args.push({
126
+ input: opts.input,
127
+ // strip context from result cause it's too noisy in terminal wihtout collapse mode
128
+ result: 'result' in opts.result ? opts.result.result : opts.result,
129
+ elapsedMs: opts.elapsedMs,
130
+ });
131
+ }
132
+
133
+ return { parts, args };
134
+ }
135
+
136
+ const [light, dark] = palettes.css[type];
137
+ const css = `
138
+ background-color: #${direction === 'up' ? light : dark};
139
+ color: ${direction === 'up' ? 'black' : 'white'};
140
+ padding: 2px;
141
+ `;
142
+
143
+ parts.push(
144
+ '%c',
145
+ direction === 'up' ? '>>' : '<<',
146
+ type,
147
+ `#${id}`,
148
+ `%c${path}%c`,
149
+ '%O',
150
+ );
151
+ args.push(css, `${css}; font-weight: bold;`, `${css}; font-weight: normal;`);
152
+
153
+ if (direction === 'up') {
154
+ args.push({ input, context: opts.context });
155
+ } else {
156
+ args.push({
157
+ input,
158
+ result: opts.result,
159
+ elapsedMs: opts.elapsedMs,
160
+ context: opts.context,
161
+ });
162
+ }
163
+
164
+ return { parts, args };
165
+ }
166
+
74
167
  // maybe this should be moved to it's own package
75
168
  const defaultLogger =
76
- <TRouter extends AnyRouter>(
77
- c: ConsoleEsque = console,
78
- ): LoggerLinkFn<TRouter> =>
169
+ <TRouter extends AnyRouter>({
170
+ c = console,
171
+ colorMode = 'css',
172
+ }: {
173
+ c?: ConsoleEsque;
174
+ colorMode?: 'ansi' | 'css';
175
+ }): LoggerLinkFn<TRouter> =>
79
176
  (props) => {
80
- const { direction, type, path, context, id } = props;
81
- const [light, dark] = palette[type];
82
-
83
177
  const rawInput = props.input;
84
-
85
178
  const input = isFormData(rawInput)
86
179
  ? Object.fromEntries(rawInput)
87
180
  : rawInput;
88
181
 
89
- const css = `
90
- background-color: #${direction === 'up' ? light : dark};
91
- color: ${direction === 'up' ? 'black' : 'white'};
92
- padding: 2px;
93
- `;
182
+ const { parts, args } = constructPartsAndArgs({
183
+ ...props,
184
+ colorMode,
185
+ input,
186
+ });
94
187
 
95
- const parts = [
96
- '%c',
97
- direction === 'up' ? '>>' : '<<',
98
- type,
99
- `#${id}`,
100
- `%c${path}%c`,
101
- '%O',
102
- ];
103
- const args: any[] = [
104
- css,
105
- `${css}; font-weight: bold;`,
106
- `${css}; font-weight: normal;`,
107
- ];
108
- if (props.direction === 'up') {
109
- args.push({ input, context: context });
110
- } else {
111
- args.push({
112
- input,
113
- result: props.result,
114
- elapsedMs: props.elapsedMs,
115
- context,
116
- });
117
- }
118
188
  const fn: 'error' | 'log' =
119
189
  props.direction === 'down' &&
120
190
  props.result &&
@@ -124,12 +194,15 @@ const defaultLogger =
124
194
 
125
195
  c[fn].apply(null, [parts.join(' ')].concat(args));
126
196
  };
197
+
127
198
  export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
128
199
  opts: LoggerLinkOptions<TRouter> = {},
129
200
  ): TRPCLink<TRouter> {
130
201
  const { enabled = () => true } = opts;
131
202
 
132
- const { logger = defaultLogger(opts.console) } = opts;
203
+ const colorMode =
204
+ opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
205
+ const { logger = defaultLogger({ c: opts.console, colorMode }) } = opts;
133
206
 
134
207
  return () => {
135
208
  return ({ op, next }) => {