@trpc/client 10.33.0 → 10.34.0

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.
Files changed (42) hide show
  1. package/dist/TRPCClientError-8462a9bf.js +48 -0
  2. package/dist/TRPCClientError-dffb44e0.js +50 -0
  3. package/dist/TRPCClientError-fef6cf44.mjs +48 -0
  4. package/dist/TRPCClientError.d.ts +5 -1
  5. package/dist/TRPCClientError.d.ts.map +1 -1
  6. package/dist/getFetch.d.ts.map +1 -1
  7. package/dist/{httpBatchLink-3e9aaa76.js → httpBatchLink-2abec973.js} +9 -4
  8. package/dist/{httpBatchLink-5c66d3c6.js → httpBatchLink-579b00eb.js} +8 -3
  9. package/dist/{httpBatchLink-5d821c7a.mjs → httpBatchLink-fbd7b43c.mjs} +8 -3
  10. package/dist/{httpUtils-9d0d09cb.mjs → httpUtils-1efcb902.mjs} +12 -9
  11. package/dist/{httpUtils-c937fe75.js → httpUtils-676ede95.js} +10 -9
  12. package/dist/{httpUtils-4e5cf721.js → httpUtils-cc69e11f.js} +12 -9
  13. package/dist/index.js +6 -5
  14. package/dist/index.mjs +7 -6
  15. package/dist/links/httpBatchLink.js +4 -3
  16. package/dist/links/httpBatchLink.mjs +4 -3
  17. package/dist/links/httpLink.d.ts.map +1 -1
  18. package/dist/links/httpLink.js +10 -5
  19. package/dist/links/httpLink.mjs +9 -4
  20. package/dist/links/internals/createHTTPBatchLink.d.ts.map +1 -1
  21. package/dist/links/internals/httpUtils.d.ts +2 -1
  22. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  23. package/dist/links/loggerLink.d.ts +5 -0
  24. package/dist/links/loggerLink.d.ts.map +1 -1
  25. package/dist/links/loggerLink.js +109 -46
  26. package/dist/links/loggerLink.mjs +109 -46
  27. package/dist/links/wsLink.js +4 -3
  28. package/dist/links/wsLink.mjs +2 -1
  29. package/dist/shared/index.js +1 -1
  30. package/dist/shared/index.mjs +1 -1
  31. package/dist/shared/transformResult.d.ts.map +1 -1
  32. package/dist/{transformResult-70f95ffb.js → transformResult-26a22823.js} +8 -38
  33. package/dist/{transformResult-9a244fe7.mjs → transformResult-7ab522e6.mjs} +9 -38
  34. package/dist/{transformResult-ae8e970c.js → transformResult-82684494.js} +9 -36
  35. package/package.json +4 -4
  36. package/src/TRPCClientError.ts +26 -3
  37. package/src/getFetch.ts +2 -7
  38. package/src/links/httpLink.ts +5 -2
  39. package/src/links/internals/createHTTPBatchLink.ts +7 -1
  40. package/src/links/internals/httpUtils.ts +9 -4
  41. package/src/links/loggerLink.ts +114 -41
  42. package/src/shared/transformResult.ts +9 -4
@@ -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,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BAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CAyB9B"}
@@ -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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,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,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)=>{
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
- var transformResult = require('../transformResult-70f95ffb.js');
6
+ var transformResult = require('../transformResult-26a22823.js');
7
+ var TRPCClientError = require('../TRPCClientError-dffb44e0.js');
7
8
 
8
9
  /* istanbul ignore next -- @preserve */ const retryDelay = (attemptIndex)=>attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
9
10
 
@@ -169,7 +170,7 @@ function createWSClient(opts) {
169
170
  } else {
170
171
  // Queries and mutations will error if interrupted
171
172
  delete pendingRequests[key];
172
- req.callbacks.error?.(transformResult.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
173
+ req.callbacks.error?.(TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
173
174
  }
174
175
  }
175
176
  });
@@ -254,7 +255,7 @@ function wsLink(opts) {
254
255
  next (message) {
255
256
  const transformed = transformResult.transformResult(message, runtime);
256
257
  if (!transformed.ok) {
257
- observer.error(transformResult.TRPCClientError.from(transformed.error));
258
+ observer.error(TRPCClientError.TRPCClientError.from(transformed.error));
258
259
  return;
259
260
  }
260
261
  observer.next({
@@ -1,5 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
- import { T as TRPCClientError, t as transformResult } from '../transformResult-9a244fe7.mjs';
2
+ import { t as transformResult } from '../transformResult-7ab522e6.mjs';
3
+ import { T as TRPCClientError } from '../TRPCClientError-fef6cf44.mjs';
3
4
 
4
5
  /* istanbul ignore next -- @preserve */ const retryDelay = (attemptIndex)=>attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
5
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var transformResult = require('../transformResult-70f95ffb.js');
5
+ var transformResult = require('../transformResult-26a22823.js');
6
6
 
7
7
 
8
8
 
@@ -1 +1 @@
1
- export { t as transformResult } from '../transformResult-9a244fe7.mjs';
1
+ export { t as transformResult } from '../transformResult-7ab522e6.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../src/shared/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAOlD,gBAAgB;AAChB,iBAAS,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAC9D,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAuB3B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAqBzC"}
1
+ {"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../src/shared/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMlD,gBAAgB;AAChB,iBAAS,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAC9D,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAuB3B;AAQD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAqBzC"}
@@ -1,39 +1,5 @@
1
1
  'use strict';
2
2
 
3
- class TRPCClientError extends Error {
4
- static from(cause, opts = {}) {
5
- if (!(cause instanceof Error)) {
6
- return new TRPCClientError(cause.error.message ?? '', {
7
- ...opts,
8
- cause: undefined,
9
- result: cause
10
- });
11
- }
12
- if (cause.name === 'TRPCClientError') {
13
- return cause;
14
- }
15
- return new TRPCClientError(cause.message, {
16
- ...opts,
17
- cause,
18
- result: null
19
- });
20
- }
21
- constructor(message, opts){
22
- const cause = opts?.cause;
23
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24
- // @ts-ignore https://github.com/tc39/proposal-error-cause
25
- super(message, {
26
- cause
27
- });
28
- this.meta = opts?.meta;
29
- this.cause = cause;
30
- this.shape = opts?.result?.error;
31
- this.data = opts?.result?.error.data;
32
- this.name = 'TRPCClientError';
33
- Object.setPrototypeOf(this, TRPCClientError.prototype);
34
- }
35
- }
36
-
37
3
  function isObject(value) {
38
4
  // check that value is object
39
5
  return !!value && !Array.isArray(value) && typeof value === 'object';
@@ -65,6 +31,11 @@ function isObject(value) {
65
31
  result
66
32
  };
67
33
  }
34
+ class TransformResultError extends Error {
35
+ constructor(){
36
+ super('Unable to transform response from server');
37
+ }
38
+ }
68
39
  /**
69
40
  * Transforms and validates that the result is a valid TRPCResponse
70
41
  * @internal
@@ -74,17 +45,16 @@ function isObject(value) {
74
45
  // Use the data transformers on the JSON-response
75
46
  result = transformResultInner(response, runtime);
76
47
  } catch (err) {
77
- throw new TRPCClientError('Unable to transform response from server');
48
+ throw new TransformResultError();
78
49
  }
79
50
  // check that output of the transformers is a valid TRPCResponse
80
51
  if (!result.ok && (!isObject(result.error.error) || typeof result.error.error.code !== 'number')) {
81
- throw new TRPCClientError('Badly formatted response from server');
52
+ throw new TransformResultError();
82
53
  }
83
54
  if (result.ok && !isObject(result.result)) {
84
- throw new TRPCClientError('Badly formatted response from server');
55
+ throw new TransformResultError();
85
56
  }
86
57
  return result;
87
58
  }
88
59
 
89
- exports.TRPCClientError = TRPCClientError;
90
60
  exports.transformResult = transformResult;
@@ -1,37 +1,3 @@
1
- class TRPCClientError extends Error {
2
- static from(cause, opts = {}) {
3
- if (!(cause instanceof Error)) {
4
- return new TRPCClientError(cause.error.message ?? '', {
5
- ...opts,
6
- cause: undefined,
7
- result: cause
8
- });
9
- }
10
- if (cause.name === 'TRPCClientError') {
11
- return cause;
12
- }
13
- return new TRPCClientError(cause.message, {
14
- ...opts,
15
- cause,
16
- result: null
17
- });
18
- }
19
- constructor(message, opts){
20
- const cause = opts?.cause;
21
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
- // @ts-ignore https://github.com/tc39/proposal-error-cause
23
- super(message, {
24
- cause
25
- });
26
- this.meta = opts?.meta;
27
- this.cause = cause;
28
- this.shape = opts?.result?.error;
29
- this.data = opts?.result?.error.data;
30
- this.name = 'TRPCClientError';
31
- Object.setPrototypeOf(this, TRPCClientError.prototype);
32
- }
33
- }
34
-
35
1
  function isObject(value) {
36
2
  // check that value is object
37
3
  return !!value && !Array.isArray(value) && typeof value === 'object';
@@ -63,6 +29,11 @@ function isObject(value) {
63
29
  result
64
30
  };
65
31
  }
32
+ class TransformResultError extends Error {
33
+ constructor(){
34
+ super('Unable to transform response from server');
35
+ }
36
+ }
66
37
  /**
67
38
  * Transforms and validates that the result is a valid TRPCResponse
68
39
  * @internal
@@ -72,16 +43,16 @@ function isObject(value) {
72
43
  // Use the data transformers on the JSON-response
73
44
  result = transformResultInner(response, runtime);
74
45
  } catch (err) {
75
- throw new TRPCClientError('Unable to transform response from server');
46
+ throw new TransformResultError();
76
47
  }
77
48
  // check that output of the transformers is a valid TRPCResponse
78
49
  if (!result.ok && (!isObject(result.error.error) || typeof result.error.error.code !== 'number')) {
79
- throw new TRPCClientError('Badly formatted response from server');
50
+ throw new TransformResultError();
80
51
  }
81
52
  if (result.ok && !isObject(result.result)) {
82
- throw new TRPCClientError('Badly formatted response from server');
53
+ throw new TransformResultError();
83
54
  }
84
55
  return result;
85
56
  }
86
57
 
87
- export { TRPCClientError as T, transformResult as t };
58
+ export { transformResult as t };
@@ -1,35 +1,3 @@
1
- class TRPCClientError extends Error {
2
- constructor(message, opts) {
3
- const cause = opts?.cause;
4
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
- // @ts-ignore https://github.com/tc39/proposal-error-cause
6
- super(message, { cause });
7
- this.meta = opts?.meta;
8
- this.cause = cause;
9
- this.shape = opts?.result?.error;
10
- this.data = opts?.result?.error.data;
11
- this.name = 'TRPCClientError';
12
- Object.setPrototypeOf(this, TRPCClientError.prototype);
13
- }
14
- static from(cause, opts = {}) {
15
- if (!(cause instanceof Error)) {
16
- return new TRPCClientError(cause.error.message ?? '', {
17
- ...opts,
18
- cause: undefined,
19
- result: cause,
20
- });
21
- }
22
- if (cause.name === 'TRPCClientError') {
23
- return cause;
24
- }
25
- return new TRPCClientError(cause.message, {
26
- ...opts,
27
- cause,
28
- result: null,
29
- });
30
- }
31
- }
32
-
33
1
  function isObject(value) {
34
2
  // check that value is object
35
3
  return !!value && !Array.isArray(value) && typeof value === 'object';
@@ -59,6 +27,11 @@ function transformResultInner(response, runtime) {
59
27
  };
60
28
  return { ok: true, result };
61
29
  }
30
+ class TransformResultError extends Error {
31
+ constructor() {
32
+ super('Unable to transform response from server');
33
+ }
34
+ }
62
35
  /**
63
36
  * Transforms and validates that the result is a valid TRPCResponse
64
37
  * @internal
@@ -70,18 +43,18 @@ function transformResult(response, runtime) {
70
43
  result = transformResultInner(response, runtime);
71
44
  }
72
45
  catch (err) {
73
- throw new TRPCClientError('Unable to transform response from server');
46
+ throw new TransformResultError();
74
47
  }
75
48
  // check that output of the transformers is a valid TRPCResponse
76
49
  if (!result.ok &&
77
50
  (!isObject(result.error.error) ||
78
51
  typeof result.error.error.code !== 'number')) {
79
- throw new TRPCClientError('Badly formatted response from server');
52
+ throw new TransformResultError();
80
53
  }
81
54
  if (result.ok && !isObject(result.result)) {
82
- throw new TRPCClientError('Badly formatted response from server');
55
+ throw new TransformResultError();
83
56
  }
84
57
  return result;
85
58
  }
86
59
 
87
- export { TRPCClientError as T, transformResult as t };
60
+ export { transformResult as t };