@trpc/client 10.21.3-test.0 → 10.23.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 (43) hide show
  1. package/dist/{httpUtils-0e44d50d.js → httpUtils-1a07b2e6.js} +18 -8
  2. package/dist/{httpUtils-f08fd191.mjs → httpUtils-8a5c637a.mjs} +18 -8
  3. package/dist/{httpUtils-0c7ec827.js → httpUtils-90a6bccb.js} +18 -7
  4. package/dist/index.js +31 -2
  5. package/dist/index.mjs +34 -5
  6. package/dist/internals/types.d.ts +1 -1
  7. package/dist/internals/types.d.ts.map +1 -1
  8. package/dist/isObject-246cec0f.js +6 -0
  9. package/dist/isObject-3ec9fe00.mjs +6 -0
  10. package/dist/isObject-617ad59e.js +8 -0
  11. package/dist/links/httpBatchLink.js +4 -3
  12. package/dist/links/httpBatchLink.mjs +4 -3
  13. package/dist/links/httpFormDataLink.d.ts +2 -0
  14. package/dist/links/httpFormDataLink.d.ts.map +1 -0
  15. package/dist/links/httpLink.d.ts +5 -2
  16. package/dist/links/httpLink.d.ts.map +1 -1
  17. package/dist/links/httpLink.js +46 -39
  18. package/dist/links/httpLink.mjs +46 -40
  19. package/dist/links/index.d.ts +2 -1
  20. package/dist/links/index.d.ts.map +1 -1
  21. package/dist/links/internals/httpUtils.d.ts +16 -10
  22. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  23. package/dist/links/internals/isObject.d.ts +2 -0
  24. package/dist/links/internals/isObject.d.ts.map +1 -0
  25. package/dist/links/internals/transformResult.d.ts.map +1 -1
  26. package/dist/links/loggerLink.d.ts.map +1 -1
  27. package/dist/links/loggerLink.js +11 -1
  28. package/dist/links/loggerLink.mjs +11 -1
  29. package/dist/links/wsLink.js +2 -1
  30. package/dist/links/wsLink.mjs +2 -1
  31. package/dist/{transformResult-e7a1e69e.js → transformResult-12020457.js} +4 -6
  32. package/dist/{transformResult-6fb67924.mjs → transformResult-403dc1d4.mjs} +2 -4
  33. package/dist/{transformResult-4e205a12.js → transformResult-51c1bc81.js} +2 -4
  34. package/package.json +4 -4
  35. package/src/internals/types.ts +1 -1
  36. package/src/links/httpBatchLink.ts +2 -2
  37. package/src/links/httpFormDataLink.ts +30 -0
  38. package/src/links/httpLink.ts +54 -50
  39. package/src/links/index.ts +3 -1
  40. package/src/links/internals/httpUtils.ts +40 -14
  41. package/src/links/internals/isObject.ts +4 -0
  42. package/src/links/internals/transformResult.ts +1 -5
  43. package/src/links/loggerLink.ts +17 -1
@@ -54,7 +54,7 @@ function getInput(opts) {
54
54
  ? opts.runtime.transformer.serialize(opts.input)
55
55
  : arrayToDict(opts.inputs.map((_input) => opts.runtime.transformer.serialize(_input)));
56
56
  }
57
- function getUrl(opts) {
57
+ const getUrl = (opts) => {
58
58
  let url = opts.url + '/' + opts.path;
59
59
  const queryParts = [];
60
60
  if ('inputs' in opts) {
@@ -70,20 +70,28 @@ function getUrl(opts) {
70
70
  url += '?' + queryParts.join('&');
71
71
  }
72
72
  return url;
73
- }
74
- function getBody(opts) {
73
+ };
74
+ const getBody = (opts) => {
75
75
  if (opts.type === 'query') {
76
76
  return undefined;
77
77
  }
78
78
  const input = getInput(opts);
79
79
  return input !== undefined ? JSON.stringify(input) : undefined;
80
- }
80
+ };
81
+ const jsonHttpRequester = (opts) => {
82
+ return httpRequest({
83
+ ...opts,
84
+ contentTypeHeader: 'application/json',
85
+ getUrl,
86
+ getBody,
87
+ });
88
+ };
81
89
  function httpRequest(opts) {
82
90
  const { type } = opts;
83
91
  const ac = opts.AbortController ? new opts.AbortController() : null;
84
92
  const promise = new Promise((resolve, reject) => {
85
- const url = getUrl(opts);
86
- const body = getBody(opts);
93
+ const url = opts.getUrl(opts);
94
+ const body = opts.getBody(opts);
87
95
  const meta = {};
88
96
  Promise.resolve(opts.headers())
89
97
  .then((headers) => {
@@ -96,7 +104,9 @@ function httpRequest(opts) {
96
104
  signal: ac?.signal,
97
105
  body: body,
98
106
  headers: {
99
- 'content-type': 'application/json',
107
+ ...(opts.contentTypeHeader
108
+ ? { 'content-type': opts.contentTypeHeader }
109
+ : {}),
100
110
  ...headers,
101
111
  },
102
112
  });
@@ -119,4 +129,4 @@ function httpRequest(opts) {
119
129
  return { promise, cancel };
120
130
  }
121
131
 
122
- export { getUrl as a, getFetch as g, httpRequest as h, resolveHTTPLinkOptions as r };
132
+ export { getUrl as a, getFetch as g, httpRequest as h, jsonHttpRequester as j, resolveHTTPLinkOptions as r };
@@ -52,7 +52,7 @@ const METHOD = {
52
52
  function getInput(opts) {
53
53
  return 'input' in opts ? opts.runtime.transformer.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.runtime.transformer.serialize(_input)));
54
54
  }
55
- function getUrl(opts) {
55
+ const getUrl = (opts)=>{
56
56
  let url = opts.url + '/' + opts.path;
57
57
  const queryParts = [];
58
58
  if ('inputs' in opts) {
@@ -68,20 +68,28 @@ function getUrl(opts) {
68
68
  url += '?' + queryParts.join('&');
69
69
  }
70
70
  return url;
71
- }
72
- function getBody(opts) {
71
+ };
72
+ const getBody = (opts)=>{
73
73
  if (opts.type === 'query') {
74
74
  return undefined;
75
75
  }
76
76
  const input = getInput(opts);
77
77
  return input !== undefined ? JSON.stringify(input) : undefined;
78
- }
78
+ };
79
+ const jsonHttpRequester = (opts)=>{
80
+ return httpRequest({
81
+ ...opts,
82
+ contentTypeHeader: 'application/json',
83
+ getUrl,
84
+ getBody
85
+ });
86
+ };
79
87
  function httpRequest(opts) {
80
88
  const { type } = opts;
81
89
  const ac = opts.AbortController ? new opts.AbortController() : null;
82
90
  const promise = new Promise((resolve, reject)=>{
83
- const url = getUrl(opts);
84
- const body = getBody(opts);
91
+ const url = opts.getUrl(opts);
92
+ const body = opts.getBody(opts);
85
93
  const meta = {};
86
94
  Promise.resolve(opts.headers()).then((headers)=>{
87
95
  /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
@@ -92,7 +100,9 @@ function httpRequest(opts) {
92
100
  signal: ac?.signal,
93
101
  body: body,
94
102
  headers: {
95
- 'content-type': 'application/json',
103
+ ...opts.contentTypeHeader ? {
104
+ 'content-type': opts.contentTypeHeader
105
+ } : {},
96
106
  ...headers
97
107
  }
98
108
  });
@@ -115,4 +125,4 @@ function httpRequest(opts) {
115
125
  };
116
126
  }
117
127
 
118
- export { getUrl as a, getFetch as g, httpRequest as h, resolveHTTPLinkOptions as r };
128
+ export { getUrl as a, getFetch as g, httpRequest as h, jsonHttpRequester as j, resolveHTTPLinkOptions as r };
@@ -54,7 +54,7 @@ const METHOD = {
54
54
  function getInput(opts) {
55
55
  return 'input' in opts ? opts.runtime.transformer.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.runtime.transformer.serialize(_input)));
56
56
  }
57
- function getUrl(opts) {
57
+ const getUrl = (opts)=>{
58
58
  let url = opts.url + '/' + opts.path;
59
59
  const queryParts = [];
60
60
  if ('inputs' in opts) {
@@ -70,20 +70,28 @@ function getUrl(opts) {
70
70
  url += '?' + queryParts.join('&');
71
71
  }
72
72
  return url;
73
- }
74
- function getBody(opts) {
73
+ };
74
+ const getBody = (opts)=>{
75
75
  if (opts.type === 'query') {
76
76
  return undefined;
77
77
  }
78
78
  const input = getInput(opts);
79
79
  return input !== undefined ? JSON.stringify(input) : undefined;
80
- }
80
+ };
81
+ const jsonHttpRequester = (opts)=>{
82
+ return httpRequest({
83
+ ...opts,
84
+ contentTypeHeader: 'application/json',
85
+ getUrl,
86
+ getBody
87
+ });
88
+ };
81
89
  function httpRequest(opts) {
82
90
  const { type } = opts;
83
91
  const ac = opts.AbortController ? new opts.AbortController() : null;
84
92
  const promise = new Promise((resolve, reject)=>{
85
- const url = getUrl(opts);
86
- const body = getBody(opts);
93
+ const url = opts.getUrl(opts);
94
+ const body = opts.getBody(opts);
87
95
  const meta = {};
88
96
  Promise.resolve(opts.headers()).then((headers)=>{
89
97
  /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
@@ -94,7 +102,9 @@ function httpRequest(opts) {
94
102
  signal: ac?.signal,
95
103
  body: body,
96
104
  headers: {
97
- 'content-type': 'application/json',
105
+ ...opts.contentTypeHeader ? {
106
+ 'content-type': opts.contentTypeHeader
107
+ } : {},
98
108
  ...headers
99
109
  }
100
110
  });
@@ -120,4 +130,5 @@ function httpRequest(opts) {
120
130
  exports.getFetch = getFetch;
121
131
  exports.getUrl = getUrl;
122
132
  exports.httpRequest = httpRequest;
133
+ exports.jsonHttpRequester = jsonHttpRequester;
123
134
  exports.resolveHTTPLinkOptions = resolveHTTPLinkOptions;
package/dist/index.js CHANGED
@@ -3,14 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
- var transformResult = require('./transformResult-e7a1e69e.js');
6
+ var transformResult = require('./transformResult-12020457.js');
7
7
  var links_splitLink = require('./splitLink-f29e84be.js');
8
8
  var shared = require('@trpc/server/shared');
9
- var httpUtils = require('./httpUtils-0c7ec827.js');
9
+ var httpUtils = require('./httpUtils-90a6bccb.js');
10
10
  var links_httpBatchLink = require('./links/httpBatchLink.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');
14
+ require('./isObject-617ad59e.js');
14
15
 
15
16
  class TRPCUntypedClient {
16
17
  $request({ type , input , path , context ={} }) {
@@ -161,11 +162,38 @@ function createTRPCProxyClient(opts) {
161
162
  return proxy;
162
163
  }
163
164
 
165
+ const getBody = (opts)=>{
166
+ if (!('input' in opts)) {
167
+ return undefined;
168
+ }
169
+ if (!(opts.input instanceof FormData)) {
170
+ throw new Error('Input is not FormData');
171
+ }
172
+ return opts.input;
173
+ };
174
+ const formDataRequester = (opts)=>{
175
+ if (opts.type !== 'mutation') {
176
+ // TODO(?) handle formdata queries
177
+ throw new Error('We only handle mutations with formdata');
178
+ }
179
+ return httpUtils.httpRequest({
180
+ ...opts,
181
+ getUrl () {
182
+ return `${opts.url}/${opts.path}`;
183
+ },
184
+ getBody
185
+ });
186
+ };
187
+ const experimental_formDataLink = links_httpLink.httpLinkFactory({
188
+ requester: formDataRequester
189
+ });
190
+
164
191
  exports.TRPCClientError = transformResult.TRPCClientError;
165
192
  exports.splitLink = links_splitLink.splitLink;
166
193
  exports.getFetch = httpUtils.getFetch;
167
194
  exports.httpBatchLink = links_httpBatchLink.httpBatchLink;
168
195
  exports.httpLink = links_httpLink.httpLink;
196
+ exports.httpLinkFactory = links_httpLink.httpLinkFactory;
169
197
  exports.loggerLink = links_loggerLink.loggerLink;
170
198
  exports.createWSClient = links_wsLink.createWSClient;
171
199
  exports.wsLink = links_wsLink.wsLink;
@@ -173,3 +201,4 @@ exports.createTRPCClient = createTRPCClient;
173
201
  exports.createTRPCClientProxy = createTRPCClientProxy;
174
202
  exports.createTRPCProxyClient = createTRPCProxyClient;
175
203
  exports.createTRPCUntypedClient = createTRPCUntypedClient;
204
+ exports.experimental_formDataLink = experimental_formDataLink;
package/dist/index.mjs CHANGED
@@ -1,14 +1,17 @@
1
1
  import { share, observableToPromise } from '@trpc/server/observable';
2
- import { T as TRPCClientError } from './transformResult-6fb67924.mjs';
3
- export { T as TRPCClientError } from './transformResult-6fb67924.mjs';
2
+ import { T as TRPCClientError } from './transformResult-403dc1d4.mjs';
3
+ export { T as TRPCClientError } from './transformResult-403dc1d4.mjs';
4
4
  import { c as createChain } from './splitLink-4c75f7be.mjs';
5
5
  export { s as splitLink } from './splitLink-4c75f7be.mjs';
6
6
  import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
7
- export { g as getFetch } from './httpUtils-f08fd191.mjs';
7
+ import { h as httpRequest } from './httpUtils-8a5c637a.mjs';
8
+ export { g as getFetch } from './httpUtils-8a5c637a.mjs';
8
9
  export { httpBatchLink } from './links/httpBatchLink.mjs';
9
- export { httpLink } from './links/httpLink.mjs';
10
+ import { httpLinkFactory } from './links/httpLink.mjs';
11
+ export { httpLink, httpLinkFactory } from './links/httpLink.mjs';
10
12
  export { loggerLink } from './links/loggerLink.mjs';
11
13
  export { createWSClient, wsLink } from './links/wsLink.mjs';
14
+ import './isObject-3ec9fe00.mjs';
12
15
 
13
16
  class TRPCUntypedClient {
14
17
  $request({ type , input , path , context ={} }) {
@@ -159,4 +162,30 @@ function createTRPCProxyClient(opts) {
159
162
  return proxy;
160
163
  }
161
164
 
162
- export { createTRPCClient, createTRPCClientProxy, createTRPCProxyClient, createTRPCUntypedClient };
165
+ const getBody = (opts)=>{
166
+ if (!('input' in opts)) {
167
+ return undefined;
168
+ }
169
+ if (!(opts.input instanceof FormData)) {
170
+ throw new Error('Input is not FormData');
171
+ }
172
+ return opts.input;
173
+ };
174
+ const formDataRequester = (opts)=>{
175
+ if (opts.type !== 'mutation') {
176
+ // TODO(?) handle formdata queries
177
+ throw new Error('We only handle mutations with formdata');
178
+ }
179
+ return httpRequest({
180
+ ...opts,
181
+ getUrl () {
182
+ return `${opts.url}/${opts.path}`;
183
+ },
184
+ getBody
185
+ });
186
+ };
187
+ const experimental_formDataLink = httpLinkFactory({
188
+ requester: formDataRequester
189
+ });
190
+
191
+ export { createTRPCClient, createTRPCClientProxy, createTRPCProxyClient, createTRPCUntypedClient, experimental_formDataLink };
@@ -58,7 +58,7 @@ export interface RequestInitEsque {
58
58
  /**
59
59
  * Sets the request's body.
60
60
  */
61
- body?: string | ReadableStream | null;
61
+ body?: string | ReadableStream | FormData | null;
62
62
  /**
63
63
  * Sets the request's associated headers.
64
64
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,4BAA4B,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;GAMG;AACH,oBAAY,UAAU,GAAG,CACvB,KAAK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E,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,KAAK,IAAI,aAAa,CAAC;IAEvB;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,oBAAY,aAAa,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ function isObject(value) {
2
+ // check that value is object
3
+ return !!value && !Array.isArray(value) && typeof value === 'object';
4
+ }
5
+
6
+ export { isObject as i };
@@ -0,0 +1,6 @@
1
+ function isObject(value) {
2
+ // check that value is object
3
+ return !!value && !Array.isArray(value) && typeof value === 'object';
4
+ }
5
+
6
+ export { isObject as i };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ function isObject(value) {
4
+ // check that value is object
5
+ return !!value && !Array.isArray(value) && typeof value === 'object';
6
+ }
7
+
8
+ exports.isObject = isObject;
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
- var transformResult = require('../transformResult-e7a1e69e.js');
7
- var httpUtils = require('../httpUtils-0c7ec827.js');
6
+ var transformResult = require('../transformResult-12020457.js');
7
+ var httpUtils = require('../httpUtils-90a6bccb.js');
8
+ require('../isObject-617ad59e.js');
8
9
 
9
10
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
10
11
  * A function that should never be called unless we messed something up.
@@ -152,7 +153,7 @@ function httpBatchLink(opts) {
152
153
  const fetch = (batchOps)=>{
153
154
  const path = batchOps.map((op)=>op.path).join(',');
154
155
  const inputs = batchOps.map((op)=>op.input);
155
- const { promise , cancel } = httpUtils.httpRequest({
156
+ const { promise , cancel } = httpUtils.jsonHttpRequester({
156
157
  ...resolvedOpts,
157
158
  runtime,
158
159
  type,
@@ -1,6 +1,7 @@
1
1
  import { observable } from '@trpc/server/observable';
2
- import { t as transformResult, T as TRPCClientError } from '../transformResult-6fb67924.mjs';
3
- import { r as resolveHTTPLinkOptions, a as getUrl, h as httpRequest } from '../httpUtils-f08fd191.mjs';
2
+ import { t as transformResult, T as TRPCClientError } from '../transformResult-403dc1d4.mjs';
3
+ import { r as resolveHTTPLinkOptions, a as getUrl, j as jsonHttpRequester } from '../httpUtils-8a5c637a.mjs';
4
+ import '../isObject-3ec9fe00.mjs';
4
5
 
5
6
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
6
7
  * A function that should never be called unless we messed something up.
@@ -148,7 +149,7 @@ function httpBatchLink(opts) {
148
149
  const fetch = (batchOps)=>{
149
150
  const path = batchOps.map((op)=>op.path).join(',');
150
151
  const inputs = batchOps.map((op)=>op.input);
151
- const { promise , cancel } = httpRequest({
152
+ const { promise , cancel } = jsonHttpRequester({
152
153
  ...resolvedOpts,
153
154
  runtime,
154
155
  type,
@@ -0,0 +1,2 @@
1
+ export declare const experimental_formDataLink: <TRouter extends import("@trpc/server").AnyRouter>(opts: import("./httpLink").HTTPLinkOptions) => import("./types").TRPCLink<TRouter>;
2
+ //# sourceMappingURL=httpFormDataLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpFormDataLink.d.ts","sourceRoot":"","sources":["../../src/links/httpFormDataLink.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,yBAAyB,uIAEpC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
- import { HTTPLinkBaseOptions } from './internals/httpUtils';
2
+ import { HTTPLinkBaseOptions, Requester } from './internals/httpUtils';
3
3
  import { HTTPHeaders, Operation, TRPCLink } from './types';
4
4
  export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
5
5
  /**
@@ -10,5 +10,8 @@ export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
10
10
  op: Operation;
11
11
  }) => HTTPHeaders | Promise<HTTPHeaders>);
12
12
  }
13
- export declare function httpLink<TRouter extends AnyRouter>(opts: HTTPLinkOptions): TRPCLink<TRouter>;
13
+ export declare function httpLinkFactory(factoryOpts: {
14
+ requester: Requester;
15
+ }): <TRouter extends AnyRouter>(opts: HTTPLinkOptions) => TRPCLink<TRouter>;
16
+ export declare const httpLink: <TRouter extends AnyRouter>(opts: HTTPLinkOptions) => TRPCLink<TRouter>;
14
17
  //# sourceMappingURL=httpLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EACL,mBAAmB,EAGpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D;;;OAGG;IACH,OAAO,CAAC,EACJ,WAAW,GACX,CAAC,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CACvE;AAED,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,eAAe,GACpB,QAAQ,CAAC,OAAO,CAAC,CAkDnB"}
1
+ {"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EACL,mBAAmB,EACnB,SAAS,EAGV,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D;;;OAGG;IACH,OAAO,CAAC,EACJ,WAAW,GACX,CAAC,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CACvE;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE;IAAE,SAAS,EAAE,SAAS,CAAA;CAAE,qCAE3D,eAAe,uBAmDxB;AAED,eAAO,MAAM,QAAQ,oCArDX,eAAe,sBAqDgD,CAAC"}
@@ -3,49 +3,56 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
- var transformResult = require('../transformResult-e7a1e69e.js');
7
- var httpUtils = require('../httpUtils-0c7ec827.js');
6
+ var transformResult = require('../transformResult-12020457.js');
7
+ var httpUtils = require('../httpUtils-90a6bccb.js');
8
+ require('../isObject-617ad59e.js');
8
9
 
9
- function httpLink(opts) {
10
- const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
11
- return (runtime)=>({ op })=>observable.observable((observer)=>{
12
- const { path , input , type } = op;
13
- const { promise , cancel } = httpUtils.httpRequest({
14
- ...resolvedOpts,
15
- runtime,
16
- type,
17
- path,
18
- input,
19
- headers () {
20
- if (!opts.headers) {
21
- return {};
10
+ function httpLinkFactory(factoryOpts) {
11
+ return (opts)=>{
12
+ const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
13
+ return (runtime)=>({ op })=>observable.observable((observer)=>{
14
+ const { path , input , type } = op;
15
+ const { promise , cancel } = factoryOpts.requester({
16
+ ...resolvedOpts,
17
+ runtime,
18
+ type,
19
+ path,
20
+ input,
21
+ headers () {
22
+ if (!opts.headers) {
23
+ return {};
24
+ }
25
+ if (typeof opts.headers === 'function') {
26
+ return opts.headers({
27
+ op
28
+ });
29
+ }
30
+ return opts.headers;
22
31
  }
23
- if (typeof opts.headers === 'function') {
24
- return opts.headers({
25
- op
26
- });
32
+ });
33
+ promise.then((res)=>{
34
+ const transformed = transformResult.transformResult(res.json, runtime);
35
+ if (!transformed.ok) {
36
+ observer.error(transformResult.TRPCClientError.from(transformed.error, {
37
+ meta: res.meta
38
+ }));
39
+ return;
27
40
  }
28
- return opts.headers;
29
- }
41
+ observer.next({
42
+ context: res.meta,
43
+ result: transformed.result
44
+ });
45
+ observer.complete();
46
+ }).catch((cause)=>observer.error(transformResult.TRPCClientError.from(cause)));
47
+ return ()=>{
48
+ cancel();
49
+ };
30
50
  });
31
- promise.then((res)=>{
32
- const transformed = transformResult.transformResult(res.json, runtime);
33
- if (!transformed.ok) {
34
- observer.error(transformResult.TRPCClientError.from(transformed.error, {
35
- meta: res.meta
36
- }));
37
- return;
38
- }
39
- observer.next({
40
- context: res.meta,
41
- result: transformed.result
42
- });
43
- observer.complete();
44
- }).catch((cause)=>observer.error(transformResult.TRPCClientError.from(cause)));
45
- return ()=>{
46
- cancel();
47
- };
48
- });
51
+ };
49
52
  }
53
+ const httpLink = httpLinkFactory({
54
+ requester: httpUtils.jsonHttpRequester
55
+ });
50
56
 
51
57
  exports.httpLink = httpLink;
58
+ exports.httpLinkFactory = httpLinkFactory;
@@ -1,47 +1,53 @@
1
1
  import { observable } from '@trpc/server/observable';
2
- import { t as transformResult, T as TRPCClientError } from '../transformResult-6fb67924.mjs';
3
- import { r as resolveHTTPLinkOptions, h as httpRequest } from '../httpUtils-f08fd191.mjs';
2
+ import { t as transformResult, T as TRPCClientError } from '../transformResult-403dc1d4.mjs';
3
+ import { r as resolveHTTPLinkOptions, j as jsonHttpRequester } from '../httpUtils-8a5c637a.mjs';
4
+ import '../isObject-3ec9fe00.mjs';
4
5
 
5
- function httpLink(opts) {
6
- const resolvedOpts = resolveHTTPLinkOptions(opts);
7
- return (runtime)=>({ op })=>observable((observer)=>{
8
- const { path , input , type } = op;
9
- const { promise , cancel } = httpRequest({
10
- ...resolvedOpts,
11
- runtime,
12
- type,
13
- path,
14
- input,
15
- headers () {
16
- if (!opts.headers) {
17
- return {};
6
+ function httpLinkFactory(factoryOpts) {
7
+ return (opts)=>{
8
+ const resolvedOpts = resolveHTTPLinkOptions(opts);
9
+ return (runtime)=>({ op })=>observable((observer)=>{
10
+ const { path , input , type } = op;
11
+ const { promise , cancel } = factoryOpts.requester({
12
+ ...resolvedOpts,
13
+ runtime,
14
+ type,
15
+ path,
16
+ input,
17
+ headers () {
18
+ if (!opts.headers) {
19
+ return {};
20
+ }
21
+ if (typeof opts.headers === 'function') {
22
+ return opts.headers({
23
+ op
24
+ });
25
+ }
26
+ return opts.headers;
18
27
  }
19
- if (typeof opts.headers === 'function') {
20
- return opts.headers({
21
- op
22
- });
28
+ });
29
+ promise.then((res)=>{
30
+ const transformed = transformResult(res.json, runtime);
31
+ if (!transformed.ok) {
32
+ observer.error(TRPCClientError.from(transformed.error, {
33
+ meta: res.meta
34
+ }));
35
+ return;
23
36
  }
24
- return opts.headers;
25
- }
37
+ observer.next({
38
+ context: res.meta,
39
+ result: transformed.result
40
+ });
41
+ observer.complete();
42
+ }).catch((cause)=>observer.error(TRPCClientError.from(cause)));
43
+ return ()=>{
44
+ cancel();
45
+ };
26
46
  });
27
- promise.then((res)=>{
28
- const transformed = transformResult(res.json, runtime);
29
- if (!transformed.ok) {
30
- observer.error(TRPCClientError.from(transformed.error, {
31
- meta: res.meta
32
- }));
33
- return;
34
- }
35
- observer.next({
36
- context: res.meta,
37
- result: transformed.result
38
- });
39
- observer.complete();
40
- }).catch((cause)=>observer.error(TRPCClientError.from(cause)));
41
- return ()=>{
42
- cancel();
43
- };
44
- });
47
+ };
45
48
  }
49
+ const httpLink = httpLinkFactory({
50
+ requester: jsonHttpRequester
51
+ });
46
52
 
47
- export { httpLink };
53
+ export { httpLink, httpLinkFactory };
@@ -1,7 +1,8 @@
1
+ export * from './types';
1
2
  export * from './httpBatchLink';
2
3
  export * from './httpLink';
3
4
  export * from './loggerLink';
4
5
  export * from './splitLink';
5
6
  export * from './wsLink';
6
- export * from './types';
7
+ export * from './httpFormDataLink';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/links/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/links/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { ProcedureType } from '@trpc/server';
2
2
  import { TRPCResponse } from '@trpc/server/rpc';
3
- import { AbortControllerEsque, FetchEsque, ResponseEsque } from '../../internals/types';
3
+ import { AbortControllerEsque, FetchEsque, RequestInitEsque, ResponseEsque } from '../../internals/types';
4
4
  import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
5
5
  /**
6
6
  * @internal
@@ -35,18 +35,24 @@ declare type GetInputOptions = {
35
35
  } | {
36
36
  input: unknown;
37
37
  });
38
- declare type GetUrlOptions = ResolvedHTTPLinkOptions & GetInputOptions & {
38
+ export declare type HTTPBaseRequestOptions = ResolvedHTTPLinkOptions & GetInputOptions & {
39
39
  type: ProcedureType;
40
40
  path: string;
41
41
  };
42
- export declare function getUrl(opts: GetUrlOptions): string;
43
- declare type GetBodyOptions = {
44
- type: ProcedureType;
45
- } & GetInputOptions;
46
- export declare function getBody(opts: GetBodyOptions): string | undefined;
47
- export declare type HTTPRequestOptions = ResolvedHTTPLinkOptions & GetInputOptions & {
48
- type: ProcedureType;
49
- path: string;
42
+ export declare type GetUrl = (opts: HTTPBaseRequestOptions) => string;
43
+ export declare type GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];
44
+ export declare type ContentOptions = {
45
+ contentTypeHeader?: string;
46
+ getUrl: GetUrl;
47
+ getBody: GetBody;
48
+ };
49
+ export declare const getUrl: GetUrl;
50
+ export declare const getBody: GetBody;
51
+ export declare type Requester = (opts: HTTPBaseRequestOptions & {
52
+ headers: () => HTTPHeaders | Promise<HTTPHeaders>;
53
+ }) => PromiseAndCancel<HTTPResult>;
54
+ export declare const jsonHttpRequester: Requester;
55
+ export declare type HTTPRequestOptions = HTTPBaseRequestOptions & ContentOptions & {
50
56
  headers: () => HTTPHeaders | Promise<HTTPHeaders>;
51
57
  };
52
58
  export declare function httpRequest(opts: HTTPRequestOptions): PromiseAndCancel<HTTPResult>;
@@ -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,UAAU,EACV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,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,WA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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,oBAAY,kBAAkB,GAAG,sBAAsB,GACrD,cAAc,GAAG;IACf,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,CAAC;AAEJ,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CA4C9B"}
@@ -0,0 +1,2 @@
1
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
2
+ //# sourceMappingURL=isObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isObject.d.ts","sourceRoot":"","sources":["../../../src/links/internals/isObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../../src/links/internals/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAMvC,gBAAgB;AAChB,iBAAS,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAC9D,QAAQ,EACJ,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GACvD,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACpD,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAuB3B;AAOD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GACvD,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACpD,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAqBzC"}
1
+ {"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../../src/links/internals/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAOvC,gBAAgB;AAChB,iBAAS,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAC9D,QAAQ,EACJ,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GACvD,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACpD,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAuB3B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GACvD,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACpD,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAqBzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE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SAAS,EAAE,MAAM,CAAC;CACnB,CACJ,CAAC;AAEJ,aAAK,YAAY,CAAC,OAAO,SAAS,SAAS,IAAI,CAC7C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,KAC/B,IAAI,CAAC;AAOV,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;CACxB;AAgED,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CA2CnB"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var observable = require('@trpc/server/observable');
6
+ var isObject = require('../isObject-617ad59e.js');
6
7
 
7
8
  const palette = {
8
9
  query: [
@@ -18,10 +19,19 @@ const palette = {
18
19
  'd83fbe'
19
20
  ]
20
21
  };
22
+ function isFormData(value) {
23
+ if (typeof FormData === 'undefined') {
24
+ // FormData is not supported
25
+ return false;
26
+ }
27
+ return value instanceof FormData;
28
+ }
21
29
  // maybe this should be moved to it's own package
22
30
  const defaultLogger = (c = console)=>(props)=>{
23
- const { direction , input , type , path , context , id } = props;
31
+ const { direction , type , path , context , id } = props;
24
32
  const [light, dark] = palette[type];
33
+ const rawInput = props.input;
34
+ const input = isObject.isObject(rawInput) && isFormData(rawInput) ? Object.fromEntries(rawInput) : props.input;
25
35
  const css = `
26
36
  background-color: #${direction === 'up' ? light : dark};
27
37
  color: ${direction === 'up' ? 'black' : 'white'};
@@ -1,4 +1,5 @@
1
1
  import { observable, tap } from '@trpc/server/observable';
2
+ import { i as isObject } from '../isObject-3ec9fe00.mjs';
2
3
 
3
4
  const palette = {
4
5
  query: [
@@ -14,10 +15,19 @@ const palette = {
14
15
  'd83fbe'
15
16
  ]
16
17
  };
18
+ function isFormData(value) {
19
+ if (typeof FormData === 'undefined') {
20
+ // FormData is not supported
21
+ return false;
22
+ }
23
+ return value instanceof FormData;
24
+ }
17
25
  // maybe this should be moved to it's own package
18
26
  const defaultLogger = (c = console)=>(props)=>{
19
- const { direction , input , type , path , context , id } = props;
27
+ const { direction , type , path , context , id } = props;
20
28
  const [light, dark] = palette[type];
29
+ const rawInput = props.input;
30
+ const input = isObject(rawInput) && isFormData(rawInput) ? Object.fromEntries(rawInput) : props.input;
21
31
  const css = `
22
32
  background-color: #${direction === 'up' ? light : dark};
23
33
  color: ${direction === 'up' ? 'black' : 'white'};
@@ -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-e7a1e69e.js');
6
+ var transformResult = require('../transformResult-12020457.js');
7
+ require('../isObject-617ad59e.js');
7
8
 
8
9
  /* istanbul ignore next -- @preserve */ const retryDelay = (attemptIndex)=>attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
9
10
 
@@ -1,5 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
- import { T as TRPCClientError, t as transformResult } from '../transformResult-6fb67924.mjs';
2
+ import { T as TRPCClientError, t as transformResult } from '../transformResult-403dc1d4.mjs';
3
+ import '../isObject-3ec9fe00.mjs';
3
4
 
4
5
  /* istanbul ignore next -- @preserve */ const retryDelay = (attemptIndex)=>attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
5
6
 
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var isObject = require('./isObject-617ad59e.js');
4
+
3
5
  class TRPCClientError extends Error {
4
6
  static from(cause, opts = {}) {
5
7
  if (!(cause instanceof Error)) {
@@ -60,10 +62,6 @@ class TRPCClientError extends Error {
60
62
  result
61
63
  };
62
64
  }
63
- function isObject(value) {
64
- // check that value is object
65
- return !!value && !Array.isArray(value) && typeof value === 'object';
66
- }
67
65
  /**
68
66
  * Transforms and validates that the result is a valid TRPCResponse
69
67
  * @internal
@@ -76,10 +74,10 @@ function isObject(value) {
76
74
  throw new TRPCClientError('Unable to transform response from server');
77
75
  }
78
76
  // check that output of the transformers is a valid TRPCResponse
79
- if (!result.ok && (!isObject(result.error.error) || typeof result.error.error.code !== 'number')) {
77
+ if (!result.ok && (!isObject.isObject(result.error.error) || typeof result.error.error.code !== 'number')) {
80
78
  throw new TRPCClientError('Badly formatted response from server');
81
79
  }
82
- if (result.ok && !isObject(result.result)) {
80
+ if (result.ok && !isObject.isObject(result.result)) {
83
81
  throw new TRPCClientError('Badly formatted response from server');
84
82
  }
85
83
  return result;
@@ -1,3 +1,5 @@
1
+ import { i as isObject } from './isObject-3ec9fe00.mjs';
2
+
1
3
  class TRPCClientError extends Error {
2
4
  static from(cause, opts = {}) {
3
5
  if (!(cause instanceof Error)) {
@@ -58,10 +60,6 @@ class TRPCClientError extends Error {
58
60
  result
59
61
  };
60
62
  }
61
- function isObject(value) {
62
- // check that value is object
63
- return !!value && !Array.isArray(value) && typeof value === 'object';
64
- }
65
63
  /**
66
64
  * Transforms and validates that the result is a valid TRPCResponse
67
65
  * @internal
@@ -1,3 +1,5 @@
1
+ import { i as isObject } from './isObject-246cec0f.js';
2
+
1
3
  class TRPCClientError extends Error {
2
4
  constructor(message, opts) {
3
5
  const cause = opts?.cause;
@@ -54,10 +56,6 @@ function transformResultInner(response, runtime) {
54
56
  };
55
57
  return { ok: true, result };
56
58
  }
57
- function isObject(value) {
58
- // check that value is object
59
- return !!value && !Array.isArray(value) && typeof value === 'object';
60
- }
61
59
  /**
62
60
  * Transforms and validates that the result is a valid TRPCResponse
63
61
  * @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.21.3-test.0",
3
+ "version": "10.23.0",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -69,11 +69,11 @@
69
69
  "links"
70
70
  ],
71
71
  "peerDependencies": {
72
- "@trpc/server": "10.21.3-test.0"
72
+ "@trpc/server": "10.23.0"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@testing-library/dom": "^9.0.0",
76
- "@trpc/server": "10.21.3-test.0",
76
+ "@trpc/server": "10.23.0",
77
77
  "@types/isomorphic-fetch": "^0.0.36",
78
78
  "@types/node": "^18.7.20",
79
79
  "eslint": "^8.30.0",
@@ -88,5 +88,5 @@
88
88
  "publishConfig": {
89
89
  "access": "public"
90
90
  },
91
- "gitHead": "fae87059bd635f98e53b1989e5673cb50963ef18"
91
+ "gitHead": "189f81da3b02beedaf11f09f81526c5df63224b7"
92
92
  }
@@ -81,7 +81,7 @@ export interface RequestInitEsque {
81
81
  /**
82
82
  * Sets the request's body.
83
83
  */
84
- body?: string | ReadableStream | null;
84
+ body?: string | ReadableStream | FormData | null;
85
85
 
86
86
  /**
87
87
  * Sets the request's associated headers.
@@ -7,7 +7,7 @@ import {
7
7
  HTTPLinkBaseOptions,
8
8
  HTTPResult,
9
9
  getUrl,
10
- httpRequest,
10
+ jsonHttpRequester,
11
11
  resolveHTTPLinkOptions,
12
12
  } from './internals/httpUtils';
13
13
  import { transformResult } from './internals/transformResult';
@@ -58,7 +58,7 @@ export function httpBatchLink<TRouter extends AnyRouter>(
58
58
  const path = batchOps.map((op) => op.path).join(',');
59
59
  const inputs = batchOps.map((op) => op.input);
60
60
 
61
- const { promise, cancel } = httpRequest({
61
+ const { promise, cancel } = jsonHttpRequester({
62
62
  ...resolvedOpts,
63
63
  runtime,
64
64
  type,
@@ -0,0 +1,30 @@
1
+ import { httpLinkFactory } from './httpLink';
2
+ import { GetBody, Requester, httpRequest } from './internals/httpUtils';
3
+
4
+ const getBody: GetBody = (opts) => {
5
+ if (!('input' in opts)) {
6
+ return undefined;
7
+ }
8
+ if (!(opts.input instanceof FormData)) {
9
+ throw new Error('Input is not FormData');
10
+ }
11
+ return opts.input;
12
+ };
13
+
14
+ const formDataRequester: Requester = (opts) => {
15
+ if (opts.type !== 'mutation') {
16
+ // TODO(?) handle formdata queries
17
+ throw new Error('We only handle mutations with formdata');
18
+ }
19
+ return httpRequest({
20
+ ...opts,
21
+ getUrl() {
22
+ return `${opts.url}/${opts.path}`;
23
+ },
24
+ getBody,
25
+ });
26
+ };
27
+
28
+ export const experimental_formDataLink = httpLinkFactory({
29
+ requester: formDataRequester,
30
+ });
@@ -3,7 +3,8 @@ import { observable } from '@trpc/server/observable';
3
3
  import { TRPCClientError } from '../TRPCClientError';
4
4
  import {
5
5
  HTTPLinkBaseOptions,
6
- httpRequest,
6
+ Requester,
7
+ jsonHttpRequester,
7
8
  resolveHTTPLinkOptions,
8
9
  } from './internals/httpUtils';
9
10
  import { transformResult } from './internals/transformResult';
@@ -19,56 +20,59 @@ export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
19
20
  | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);
20
21
  }
21
22
 
22
- export function httpLink<TRouter extends AnyRouter>(
23
- opts: HTTPLinkOptions,
24
- ): TRPCLink<TRouter> {
25
- const resolvedOpts = resolveHTTPLinkOptions(opts);
26
- return (runtime) =>
27
- ({ op }) =>
28
- observable((observer) => {
29
- const { path, input, type } = op;
23
+ export function httpLinkFactory(factoryOpts: { requester: Requester }) {
24
+ return <TRouter extends AnyRouter>(
25
+ opts: HTTPLinkOptions,
26
+ ): TRPCLink<TRouter> => {
27
+ const resolvedOpts = resolveHTTPLinkOptions(opts);
30
28
 
31
- const { promise, cancel } = httpRequest({
32
- ...resolvedOpts,
33
- runtime,
34
- type,
35
- path,
36
- input,
37
- headers() {
38
- if (!opts.headers) {
39
- return {};
40
- }
41
- if (typeof opts.headers === 'function') {
42
- return opts.headers({
43
- op,
44
- });
45
- }
46
- return opts.headers;
47
- },
48
- });
49
-
50
- promise
51
- .then((res) => {
52
- const transformed = transformResult(res.json, runtime);
29
+ return (runtime) =>
30
+ ({ op }) =>
31
+ observable((observer) => {
32
+ const { path, input, type } = op;
33
+ const { promise, cancel } = factoryOpts.requester({
34
+ ...resolvedOpts,
35
+ runtime,
36
+ type,
37
+ path,
38
+ input,
39
+ headers() {
40
+ if (!opts.headers) {
41
+ return {};
42
+ }
43
+ if (typeof opts.headers === 'function') {
44
+ return opts.headers({
45
+ op,
46
+ });
47
+ }
48
+ return opts.headers;
49
+ },
50
+ });
51
+ promise
52
+ .then((res) => {
53
+ const transformed = transformResult(res.json, runtime);
53
54
 
54
- if (!transformed.ok) {
55
- observer.error(
56
- TRPCClientError.from(transformed.error, {
57
- meta: res.meta,
58
- }),
59
- );
60
- return;
61
- }
62
- observer.next({
63
- context: res.meta,
64
- result: transformed.result,
65
- });
66
- observer.complete();
67
- })
68
- .catch((cause) => observer.error(TRPCClientError.from(cause)));
55
+ if (!transformed.ok) {
56
+ observer.error(
57
+ TRPCClientError.from(transformed.error, {
58
+ meta: res.meta,
59
+ }),
60
+ );
61
+ return;
62
+ }
63
+ observer.next({
64
+ context: res.meta,
65
+ result: transformed.result,
66
+ });
67
+ observer.complete();
68
+ })
69
+ .catch((cause) => observer.error(TRPCClientError.from(cause)));
69
70
 
70
- return () => {
71
- cancel();
72
- };
73
- });
71
+ return () => {
72
+ cancel();
73
+ };
74
+ });
75
+ };
74
76
  }
77
+
78
+ export const httpLink = httpLinkFactory({ requester: jsonHttpRequester });
@@ -1,9 +1,11 @@
1
+ export * from './types';
2
+
1
3
  export * from './httpBatchLink';
2
4
  export * from './httpLink';
3
5
  export * from './loggerLink';
4
6
  export * from './splitLink';
5
7
  export * from './wsLink';
6
- export * from './types';
8
+ export * from './httpFormDataLink';
7
9
 
8
10
  // These are not public (yet) as we get this functionality from tanstack query
9
11
  // export * from './retryLink';
@@ -5,6 +5,7 @@ import { getAbortController } from '../../internals/getAbortController';
5
5
  import {
6
6
  AbortControllerEsque,
7
7
  FetchEsque,
8
+ RequestInitEsque,
8
9
  ResponseEsque,
9
10
  } from '../../internals/types';
10
11
  import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
@@ -74,13 +75,24 @@ function getInput(opts: GetInputOptions) {
74
75
  );
75
76
  }
76
77
 
77
- type GetUrlOptions = ResolvedHTTPLinkOptions &
78
+ export type HTTPBaseRequestOptions = ResolvedHTTPLinkOptions &
78
79
  GetInputOptions & {
79
80
  type: ProcedureType;
80
81
  path: string;
81
82
  };
82
83
 
83
- export function getUrl(opts: GetUrlOptions) {
84
+ export type GetUrl = (opts: HTTPBaseRequestOptions) => string;
85
+ export type GetBody = (
86
+ opts: HTTPBaseRequestOptions,
87
+ ) => RequestInitEsque['body'];
88
+
89
+ export type ContentOptions = {
90
+ contentTypeHeader?: string;
91
+ getUrl: GetUrl;
92
+ getBody: GetBody;
93
+ };
94
+
95
+ export const getUrl: GetUrl = (opts) => {
84
96
  let url = opts.url + '/' + opts.path;
85
97
  const queryParts: string[] = [];
86
98
  if ('inputs' in opts) {
@@ -96,22 +108,33 @@ export function getUrl(opts: GetUrlOptions) {
96
108
  url += '?' + queryParts.join('&');
97
109
  }
98
110
  return url;
99
- }
111
+ };
100
112
 
101
- type GetBodyOptions = { type: ProcedureType } & GetInputOptions;
102
-
103
- export function getBody(opts: GetBodyOptions) {
113
+ export const getBody: GetBody = (opts) => {
104
114
  if (opts.type === 'query') {
105
115
  return undefined;
106
116
  }
107
117
  const input = getInput(opts);
108
118
  return input !== undefined ? JSON.stringify(input) : undefined;
109
- }
119
+ };
110
120
 
111
- export type HTTPRequestOptions = ResolvedHTTPLinkOptions &
112
- GetInputOptions & {
113
- type: ProcedureType;
114
- path: string;
121
+ export type Requester = (
122
+ opts: HTTPBaseRequestOptions & {
123
+ headers: () => HTTPHeaders | Promise<HTTPHeaders>;
124
+ },
125
+ ) => PromiseAndCancel<HTTPResult>;
126
+
127
+ export const jsonHttpRequester: Requester = (opts) => {
128
+ return httpRequest({
129
+ ...opts,
130
+ contentTypeHeader: 'application/json',
131
+ getUrl,
132
+ getBody,
133
+ });
134
+ };
135
+
136
+ export type HTTPRequestOptions = HTTPBaseRequestOptions &
137
+ ContentOptions & {
115
138
  headers: () => HTTPHeaders | Promise<HTTPHeaders>;
116
139
  };
117
140
 
@@ -122,8 +145,8 @@ export function httpRequest(
122
145
  const ac = opts.AbortController ? new opts.AbortController() : null;
123
146
 
124
147
  const promise = new Promise<HTTPResult>((resolve, reject) => {
125
- const url = getUrl(opts);
126
- const body = getBody(opts);
148
+ const url = opts.getUrl(opts);
149
+ const body = opts.getBody(opts);
127
150
 
128
151
  const meta = {} as HTTPResult['meta'];
129
152
  Promise.resolve(opts.headers())
@@ -132,12 +155,15 @@ export function httpRequest(
132
155
  if (type === 'subscription') {
133
156
  throw new Error('Subscriptions should use wsLink');
134
157
  }
158
+
135
159
  return opts.fetch(url, {
136
160
  method: METHOD[type],
137
161
  signal: ac?.signal,
138
162
  body: body,
139
163
  headers: {
140
- 'content-type': 'application/json',
164
+ ...(opts.contentTypeHeader
165
+ ? { 'content-type': opts.contentTypeHeader }
166
+ : {}),
141
167
  ...headers,
142
168
  },
143
169
  });
@@ -0,0 +1,4 @@
1
+ export function isObject(value: unknown): value is Record<string, unknown> {
2
+ // check that value is object
3
+ return !!value && !Array.isArray(value) && typeof value === 'object';
4
+ }
@@ -6,6 +6,7 @@ import {
6
6
  } from '@trpc/server/rpc';
7
7
  import { TRPCClientRuntime } from '..';
8
8
  import { TRPCClientError } from '../../TRPCClientError';
9
+ import { isObject } from './isObject';
9
10
 
10
11
  // FIXME:
11
12
  // - the generics here are probably unnecessary
@@ -40,11 +41,6 @@ function transformResultInner<TRouter extends AnyRouter, TOutput>(
40
41
  return { ok: true, result } as const;
41
42
  }
42
43
 
43
- function isObject(value: unknown): value is Record<string, unknown> {
44
- // check that value is object
45
- return !!value && !Array.isArray(value) && typeof value === 'object';
46
- }
47
-
48
44
  /**
49
45
  * Transforms and validates that the result is a valid TRPCResponse
50
46
  * @internal
@@ -1,6 +1,7 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
2
  import { observable, tap } from '@trpc/server/observable';
3
3
  import { TRPCClientError } from '..';
4
+ import { isObject } from './internals/isObject';
4
5
  import { Operation, OperationResultEnvelope, TRPCLink } from './types';
5
6
 
6
7
  type ConsoleEsque = {
@@ -56,15 +57,30 @@ export interface LoggerLinkOptions<TRouter extends AnyRouter> {
56
57
  console?: ConsoleEsque;
57
58
  }
58
59
 
60
+ function isFormData(value: unknown): value is FormData {
61
+ if (typeof FormData === 'undefined') {
62
+ // FormData is not supported
63
+ return false;
64
+ }
65
+ return value instanceof FormData;
66
+ }
67
+
59
68
  // maybe this should be moved to it's own package
60
69
  const defaultLogger =
61
70
  <TRouter extends AnyRouter>(
62
71
  c: ConsoleEsque = console,
63
72
  ): LoggerLinkFn<TRouter> =>
64
73
  (props) => {
65
- const { direction, input, type, path, context, id } = props;
74
+ const { direction, type, path, context, id } = props;
66
75
  const [light, dark] = palette[type];
67
76
 
77
+ const rawInput = props.input;
78
+
79
+ const input =
80
+ isObject(rawInput) && isFormData(rawInput)
81
+ ? Object.fromEntries(rawInput)
82
+ : props.input;
83
+
68
84
  const css = `
69
85
  background-color: #${direction === 'up' ? light : dark};
70
86
  color: ${direction === 'up' ? 'black' : 'white'};