@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.
- package/dist/TRPCClientError-8462a9bf.js +48 -0
- package/dist/TRPCClientError-dffb44e0.js +50 -0
- package/dist/TRPCClientError-fef6cf44.mjs +48 -0
- package/dist/TRPCClientError.d.ts +5 -1
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/{httpBatchLink-3e9aaa76.js → httpBatchLink-2abec973.js} +9 -4
- package/dist/{httpBatchLink-5c66d3c6.js → httpBatchLink-579b00eb.js} +8 -3
- package/dist/{httpBatchLink-5d821c7a.mjs → httpBatchLink-fbd7b43c.mjs} +8 -3
- package/dist/{httpUtils-9d0d09cb.mjs → httpUtils-1efcb902.mjs} +12 -9
- package/dist/{httpUtils-c937fe75.js → httpUtils-676ede95.js} +10 -9
- package/dist/{httpUtils-4e5cf721.js → httpUtils-cc69e11f.js} +12 -9
- package/dist/index.js +6 -5
- package/dist/index.mjs +7 -6
- package/dist/links/httpBatchLink.js +4 -3
- package/dist/links/httpBatchLink.mjs +4 -3
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +10 -5
- package/dist/links/httpLink.mjs +9 -4
- package/dist/links/internals/createHTTPBatchLink.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.d.ts +2 -1
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/loggerLink.d.ts +5 -0
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +109 -46
- package/dist/links/loggerLink.mjs +109 -46
- package/dist/links/wsLink.js +4 -3
- package/dist/links/wsLink.mjs +2 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/shared/transformResult.d.ts.map +1 -1
- package/dist/{transformResult-70f95ffb.js → transformResult-26a22823.js} +8 -38
- package/dist/{transformResult-9a244fe7.mjs → transformResult-7ab522e6.mjs} +9 -38
- package/dist/{transformResult-ae8e970c.js → transformResult-82684494.js} +9 -36
- package/package.json +4 -4
- package/src/TRPCClientError.ts +26 -3
- package/src/getFetch.ts +2 -7
- package/src/links/httpLink.ts +5 -2
- package/src/links/internals/createHTTPBatchLink.ts +7 -1
- package/src/links/internals/httpUtils.ts +9 -4
- package/src/links/loggerLink.ts +114 -41
- package/src/shared/transformResult.ts +9 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
function isTRPCClientError(cause) {
|
|
2
|
+
return (cause instanceof TRPCClientError ||
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
* Delete in next major
|
|
6
|
+
*/
|
|
7
|
+
cause.name === 'TRPCClientError');
|
|
8
|
+
}
|
|
9
|
+
class TRPCClientError extends Error {
|
|
10
|
+
constructor(message, opts) {
|
|
11
|
+
const cause = opts?.cause;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
14
|
+
super(message, { cause });
|
|
15
|
+
this.meta = opts?.meta;
|
|
16
|
+
this.cause = cause;
|
|
17
|
+
this.shape = opts?.result?.error;
|
|
18
|
+
this.data = opts?.result?.error.data;
|
|
19
|
+
this.name = 'TRPCClientError';
|
|
20
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
21
|
+
}
|
|
22
|
+
static from(cause, opts = {}) {
|
|
23
|
+
if (!(cause instanceof Error)) {
|
|
24
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
25
|
+
...opts,
|
|
26
|
+
cause: undefined,
|
|
27
|
+
result: cause,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (isTRPCClientError(cause)) {
|
|
31
|
+
if (opts.meta) {
|
|
32
|
+
// Decorate with meta error data
|
|
33
|
+
cause.meta = {
|
|
34
|
+
...cause.meta,
|
|
35
|
+
...opts.meta,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return cause;
|
|
39
|
+
}
|
|
40
|
+
return new TRPCClientError(cause.message, {
|
|
41
|
+
...opts,
|
|
42
|
+
cause,
|
|
43
|
+
result: null,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { TRPCClientError as T };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function isTRPCClientError(cause) {
|
|
4
|
+
return cause instanceof TRPCClientError || /**
|
|
5
|
+
* @deprecated
|
|
6
|
+
* Delete in next major
|
|
7
|
+
*/ cause.name === 'TRPCClientError';
|
|
8
|
+
}
|
|
9
|
+
class TRPCClientError extends Error {
|
|
10
|
+
static from(cause, opts = {}) {
|
|
11
|
+
if (!(cause instanceof Error)) {
|
|
12
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
13
|
+
...opts,
|
|
14
|
+
cause: undefined,
|
|
15
|
+
result: cause
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (isTRPCClientError(cause)) {
|
|
19
|
+
if (opts.meta) {
|
|
20
|
+
// Decorate with meta error data
|
|
21
|
+
cause.meta = {
|
|
22
|
+
...cause.meta,
|
|
23
|
+
...opts.meta
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return cause;
|
|
27
|
+
}
|
|
28
|
+
return new TRPCClientError(cause.message, {
|
|
29
|
+
...opts,
|
|
30
|
+
cause,
|
|
31
|
+
result: null
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
constructor(message, opts){
|
|
35
|
+
const cause = opts?.cause;
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
38
|
+
super(message, {
|
|
39
|
+
cause
|
|
40
|
+
});
|
|
41
|
+
this.meta = opts?.meta;
|
|
42
|
+
this.cause = cause;
|
|
43
|
+
this.shape = opts?.result?.error;
|
|
44
|
+
this.data = opts?.result?.error.data;
|
|
45
|
+
this.name = 'TRPCClientError';
|
|
46
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.TRPCClientError = TRPCClientError;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
function isTRPCClientError(cause) {
|
|
2
|
+
return cause instanceof TRPCClientError || /**
|
|
3
|
+
* @deprecated
|
|
4
|
+
* Delete in next major
|
|
5
|
+
*/ cause.name === 'TRPCClientError';
|
|
6
|
+
}
|
|
7
|
+
class TRPCClientError extends Error {
|
|
8
|
+
static from(cause, opts = {}) {
|
|
9
|
+
if (!(cause instanceof Error)) {
|
|
10
|
+
return new TRPCClientError(cause.error.message ?? '', {
|
|
11
|
+
...opts,
|
|
12
|
+
cause: undefined,
|
|
13
|
+
result: cause
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (isTRPCClientError(cause)) {
|
|
17
|
+
if (opts.meta) {
|
|
18
|
+
// Decorate with meta error data
|
|
19
|
+
cause.meta = {
|
|
20
|
+
...cause.meta,
|
|
21
|
+
...opts.meta
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return cause;
|
|
25
|
+
}
|
|
26
|
+
return new TRPCClientError(cause.message, {
|
|
27
|
+
...opts,
|
|
28
|
+
cause,
|
|
29
|
+
result: null
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
constructor(message, opts){
|
|
33
|
+
const cause = opts?.cause;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
36
|
+
super(message, {
|
|
37
|
+
cause
|
|
38
|
+
});
|
|
39
|
+
this.meta = opts?.meta;
|
|
40
|
+
this.cause = cause;
|
|
41
|
+
this.shape = opts?.result?.error;
|
|
42
|
+
this.data = opts?.result?.error.data;
|
|
43
|
+
this.name = 'TRPCClientError';
|
|
44
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { TRPCClientError as T };
|
|
@@ -12,7 +12,11 @@ export declare class TRPCClientError<TRouterOrProcedure extends ErrorInferrable>
|
|
|
12
12
|
readonly cause: Error | undefined;
|
|
13
13
|
readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>;
|
|
14
14
|
readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Additional meta data about the error
|
|
17
|
+
* In the case of HTTP-errors, we'll have `response` and potentially `responseJSON` here
|
|
18
|
+
*/
|
|
19
|
+
meta: Record<string, unknown> | undefined;
|
|
16
20
|
constructor(message: string, opts?: {
|
|
17
21
|
result?: Maybe<inferErrorShape<TRouterOrProcedure>>;
|
|
18
22
|
cause?: Error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCClientError.d.ts","sourceRoot":"","sources":["../src/TRPCClientError.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACN,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAErE,KAAK,eAAe,GAAG,YAAY,GAAG,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;AAEzE,KAAK,eAAe,CAAC,WAAW,SAAS,eAAe,IACtD,WAAW,SAAS,SAAS,GACzB,gBAAgB,CAAC,WAAW,CAAC,GAC7B,WAAW,SAAS,YAAY,GAChC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,GACtD,WAAW,CAAC;AAElB,MAAM,WAAW,mBAAmB,CAAC,MAAM,SAAS,iBAAiB;IACnE,QAAQ,CAAC,OAAO,EAAE,MAAM,C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Q,KACR,YAAW,mBAAmB,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;IAEnE,SAAgB,KAAK,oBAAC;IACtB,SAAgB,KAAK,EAAE,KAAK,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAClE,SAAgB,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzE;;;OAGG;IACI,IAAI,sCAAC;gBAGV,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACpD,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC;WAkBW,IAAI,CAAC,kBAAkB,SAAS,eAAe,EAC3D,KAAK,EAAE,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,EACrC,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAO,GAC5C,eAAe,CAAC,kBAAkB,CAAC;CA4BvC"}
|
package/dist/getFetch.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var observable = require('@trpc/server/observable');
|
|
4
|
-
var transformResult = require('./transformResult-
|
|
5
|
-
var
|
|
4
|
+
var transformResult = require('./transformResult-26a22823.js');
|
|
5
|
+
var TRPCClientError = require('./TRPCClientError-dffb44e0.js');
|
|
6
|
+
var httpUtils = require('./httpUtils-cc69e11f.js');
|
|
6
7
|
|
|
7
8
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
8
9
|
* A function that should never be called unless we messed something up.
|
|
@@ -182,10 +183,12 @@ var httpUtils = require('./httpUtils-4e5cf721.js');
|
|
|
182
183
|
return observable.observable((observer)=>{
|
|
183
184
|
const loader = loaders[op.type];
|
|
184
185
|
const { promise , cancel } = loader.load(op);
|
|
186
|
+
let _res = undefined;
|
|
185
187
|
promise.then((res)=>{
|
|
188
|
+
_res = res;
|
|
186
189
|
const transformed = transformResult.transformResult(res.json, runtime);
|
|
187
190
|
if (!transformed.ok) {
|
|
188
|
-
observer.error(
|
|
191
|
+
observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
|
|
189
192
|
meta: res.meta
|
|
190
193
|
}));
|
|
191
194
|
return;
|
|
@@ -196,7 +199,9 @@ var httpUtils = require('./httpUtils-4e5cf721.js');
|
|
|
196
199
|
});
|
|
197
200
|
observer.complete();
|
|
198
201
|
}).catch((err)=>{
|
|
199
|
-
observer.error(
|
|
202
|
+
observer.error(TRPCClientError.TRPCClientError.from(err, {
|
|
203
|
+
meta: _res?.meta
|
|
204
|
+
}));
|
|
200
205
|
});
|
|
201
206
|
return ()=>{
|
|
202
207
|
cancel();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
|
-
import { t as transformResult
|
|
3
|
-
import {
|
|
2
|
+
import { t as transformResult } from './transformResult-82684494.js';
|
|
3
|
+
import { T as TRPCClientError } from './TRPCClientError-8462a9bf.js';
|
|
4
|
+
import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-676ede95.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A function that should never be called unless we messed something up.
|
|
@@ -175,8 +176,10 @@ function createHTTPBatchLink(requester) {
|
|
|
175
176
|
return observable((observer) => {
|
|
176
177
|
const loader = loaders[op.type];
|
|
177
178
|
const { promise, cancel } = loader.load(op);
|
|
179
|
+
let _res = undefined;
|
|
178
180
|
promise
|
|
179
181
|
.then((res) => {
|
|
182
|
+
_res = res;
|
|
180
183
|
const transformed = transformResult(res.json, runtime);
|
|
181
184
|
if (!transformed.ok) {
|
|
182
185
|
observer.error(TRPCClientError.from(transformed.error, {
|
|
@@ -191,7 +194,9 @@ function createHTTPBatchLink(requester) {
|
|
|
191
194
|
observer.complete();
|
|
192
195
|
})
|
|
193
196
|
.catch((err) => {
|
|
194
|
-
observer.error(TRPCClientError.from(err
|
|
197
|
+
observer.error(TRPCClientError.from(err, {
|
|
198
|
+
meta: _res?.meta,
|
|
199
|
+
}));
|
|
195
200
|
});
|
|
196
201
|
return () => {
|
|
197
202
|
cancel();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
|
-
import { t as transformResult
|
|
3
|
-
import {
|
|
2
|
+
import { t as transformResult } from './transformResult-7ab522e6.mjs';
|
|
3
|
+
import { T as TRPCClientError } from './TRPCClientError-fef6cf44.mjs';
|
|
4
|
+
import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-1efcb902.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.
|
|
@@ -180,7 +181,9 @@ import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from
|
|
|
180
181
|
return observable((observer)=>{
|
|
181
182
|
const loader = loaders[op.type];
|
|
182
183
|
const { promise , cancel } = loader.load(op);
|
|
184
|
+
let _res = undefined;
|
|
183
185
|
promise.then((res)=>{
|
|
186
|
+
_res = res;
|
|
184
187
|
const transformed = transformResult(res.json, runtime);
|
|
185
188
|
if (!transformed.ok) {
|
|
186
189
|
observer.error(TRPCClientError.from(transformed.error, {
|
|
@@ -194,7 +197,9 @@ import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from
|
|
|
194
197
|
});
|
|
195
198
|
observer.complete();
|
|
196
199
|
}).catch((err)=>{
|
|
197
|
-
observer.error(TRPCClientError.from(err
|
|
200
|
+
observer.error(TRPCClientError.from(err, {
|
|
201
|
+
meta: _res?.meta
|
|
202
|
+
}));
|
|
198
203
|
});
|
|
199
204
|
return ()=>{
|
|
200
205
|
cancel();
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
+
import { T as TRPCClientError } from './TRPCClientError-fef6cf44.mjs';
|
|
2
|
+
|
|
1
3
|
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
4
|
function getFetch(customFetchImpl) {
|
|
7
5
|
if (customFetchImpl) {
|
|
8
6
|
return customFetchImpl;
|
|
9
7
|
}
|
|
10
8
|
if (typeof window !== 'undefined' && isFunction(window.fetch)) {
|
|
11
|
-
return
|
|
9
|
+
return window.fetch;
|
|
12
10
|
}
|
|
13
11
|
if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
|
|
14
|
-
return
|
|
12
|
+
return globalThis.fetch;
|
|
15
13
|
}
|
|
16
14
|
throw new Error('No fetch implementation found');
|
|
17
15
|
}
|
|
@@ -32,7 +30,7 @@ function getAbortController(customAbortControllerImpl) {
|
|
|
32
30
|
function resolveHTTPLinkOptions(opts) {
|
|
33
31
|
return {
|
|
34
32
|
url: opts.url,
|
|
35
|
-
fetch:
|
|
33
|
+
fetch: opts.fetch,
|
|
36
34
|
AbortController: getAbortController(opts.AbortController)
|
|
37
35
|
};
|
|
38
36
|
}
|
|
@@ -101,7 +99,7 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
101
99
|
} : {},
|
|
102
100
|
...resolvedHeaders
|
|
103
101
|
};
|
|
104
|
-
return opts.fetch(url, {
|
|
102
|
+
return getFetch(opts.fetch)(url, {
|
|
105
103
|
method: METHOD[type],
|
|
106
104
|
signal: ac?.signal,
|
|
107
105
|
body: body,
|
|
@@ -116,11 +114,16 @@ function httpRequest(opts) {
|
|
|
116
114
|
meta.response = _res;
|
|
117
115
|
return _res.json();
|
|
118
116
|
}).then((json)=>{
|
|
117
|
+
meta.responseJSON = json;
|
|
119
118
|
resolve({
|
|
120
119
|
json: json,
|
|
121
120
|
meta
|
|
122
121
|
});
|
|
123
|
-
}).catch(
|
|
122
|
+
}).catch((err)=>{
|
|
123
|
+
reject(TRPCClientError.from(err, {
|
|
124
|
+
meta
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
124
127
|
});
|
|
125
128
|
const cancel = ()=>{
|
|
126
129
|
ac?.abort();
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
+
import { T as TRPCClientError } from './TRPCClientError-8462a9bf.js';
|
|
2
|
+
|
|
1
3
|
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
4
|
function getFetch(customFetchImpl) {
|
|
7
5
|
if (customFetchImpl) {
|
|
8
6
|
return customFetchImpl;
|
|
9
7
|
}
|
|
10
8
|
if (typeof window !== 'undefined' && isFunction(window.fetch)) {
|
|
11
|
-
return
|
|
9
|
+
return window.fetch;
|
|
12
10
|
}
|
|
13
11
|
if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
|
|
14
|
-
return
|
|
12
|
+
return globalThis.fetch;
|
|
15
13
|
}
|
|
16
14
|
throw new Error('No fetch implementation found');
|
|
17
15
|
}
|
|
@@ -32,7 +30,7 @@ function getAbortController(customAbortControllerImpl) {
|
|
|
32
30
|
function resolveHTTPLinkOptions(opts) {
|
|
33
31
|
return {
|
|
34
32
|
url: opts.url,
|
|
35
|
-
fetch:
|
|
33
|
+
fetch: opts.fetch,
|
|
36
34
|
AbortController: getAbortController(opts.AbortController),
|
|
37
35
|
};
|
|
38
36
|
}
|
|
@@ -104,7 +102,7 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
104
102
|
: {}),
|
|
105
103
|
...resolvedHeaders,
|
|
106
104
|
};
|
|
107
|
-
return opts.fetch(url, {
|
|
105
|
+
return getFetch(opts.fetch)(url, {
|
|
108
106
|
method: METHOD[type],
|
|
109
107
|
signal: ac?.signal,
|
|
110
108
|
body: body,
|
|
@@ -121,12 +119,15 @@ function httpRequest(opts) {
|
|
|
121
119
|
return _res.json();
|
|
122
120
|
})
|
|
123
121
|
.then((json) => {
|
|
122
|
+
meta.responseJSON = json;
|
|
124
123
|
resolve({
|
|
125
124
|
json: json,
|
|
126
125
|
meta,
|
|
127
126
|
});
|
|
128
127
|
})
|
|
129
|
-
.catch(
|
|
128
|
+
.catch((err) => {
|
|
129
|
+
reject(TRPCClientError.from(err, { meta }));
|
|
130
|
+
});
|
|
130
131
|
});
|
|
131
132
|
const cancel = () => {
|
|
132
133
|
ac?.abort();
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var TRPCClientError = require('./TRPCClientError-dffb44e0.js');
|
|
4
|
+
|
|
3
5
|
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
6
|
function getFetch(customFetchImpl) {
|
|
9
7
|
if (customFetchImpl) {
|
|
10
8
|
return customFetchImpl;
|
|
11
9
|
}
|
|
12
10
|
if (typeof window !== 'undefined' && isFunction(window.fetch)) {
|
|
13
|
-
return
|
|
11
|
+
return window.fetch;
|
|
14
12
|
}
|
|
15
13
|
if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
|
|
16
|
-
return
|
|
14
|
+
return globalThis.fetch;
|
|
17
15
|
}
|
|
18
16
|
throw new Error('No fetch implementation found');
|
|
19
17
|
}
|
|
@@ -34,7 +32,7 @@ function getAbortController(customAbortControllerImpl) {
|
|
|
34
32
|
function resolveHTTPLinkOptions(opts) {
|
|
35
33
|
return {
|
|
36
34
|
url: opts.url,
|
|
37
|
-
fetch:
|
|
35
|
+
fetch: opts.fetch,
|
|
38
36
|
AbortController: getAbortController(opts.AbortController)
|
|
39
37
|
};
|
|
40
38
|
}
|
|
@@ -103,7 +101,7 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
103
101
|
} : {},
|
|
104
102
|
...resolvedHeaders
|
|
105
103
|
};
|
|
106
|
-
return opts.fetch(url, {
|
|
104
|
+
return getFetch(opts.fetch)(url, {
|
|
107
105
|
method: METHOD[type],
|
|
108
106
|
signal: ac?.signal,
|
|
109
107
|
body: body,
|
|
@@ -118,11 +116,16 @@ function httpRequest(opts) {
|
|
|
118
116
|
meta.response = _res;
|
|
119
117
|
return _res.json();
|
|
120
118
|
}).then((json)=>{
|
|
119
|
+
meta.responseJSON = json;
|
|
121
120
|
resolve({
|
|
122
121
|
json: json,
|
|
123
122
|
meta
|
|
124
123
|
});
|
|
125
|
-
}).catch(
|
|
124
|
+
}).catch((err)=>{
|
|
125
|
+
reject(TRPCClientError.TRPCClientError.from(err, {
|
|
126
|
+
meta
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
126
129
|
});
|
|
127
130
|
const cancel = ()=>{
|
|
128
131
|
ac?.abort();
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var observable = require('@trpc/server/observable');
|
|
6
6
|
var links_splitLink = require('./splitLink-f29e84be.js');
|
|
7
|
-
var
|
|
7
|
+
var TRPCClientError = require('./TRPCClientError-dffb44e0.js');
|
|
8
8
|
var shared = require('@trpc/server/shared');
|
|
9
|
-
var httpUtils = require('./httpUtils-
|
|
10
|
-
var links_httpBatchLink = require('./httpBatchLink-
|
|
9
|
+
var httpUtils = require('./httpUtils-cc69e11f.js');
|
|
10
|
+
var links_httpBatchLink = require('./httpBatchLink-2abec973.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('./transformResult-26a22823.js');
|
|
14
15
|
|
|
15
16
|
class TRPCUntypedClient {
|
|
16
17
|
$request({ type , input , path , context ={} }) {
|
|
@@ -34,7 +35,7 @@ class TRPCUntypedClient {
|
|
|
34
35
|
promise.then((envelope)=>{
|
|
35
36
|
resolve(envelope.result.data);
|
|
36
37
|
}).catch((err)=>{
|
|
37
|
-
reject(
|
|
38
|
+
reject(TRPCClientError.TRPCClientError.from(err));
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
return abortablePromise;
|
|
@@ -359,7 +360,7 @@ const experimental_formDataLink = links_httpLink.httpLinkFactory({
|
|
|
359
360
|
});
|
|
360
361
|
|
|
361
362
|
exports.splitLink = links_splitLink.splitLink;
|
|
362
|
-
exports.TRPCClientError =
|
|
363
|
+
exports.TRPCClientError = TRPCClientError.TRPCClientError;
|
|
363
364
|
exports.getFetch = httpUtils.getFetch;
|
|
364
365
|
exports.httpBatchLink = links_httpBatchLink.httpBatchLink;
|
|
365
366
|
exports.httpLink = links_httpLink.httpLink;
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { share, observableToPromise } from '@trpc/server/observable';
|
|
2
2
|
import { c as createChain } from './splitLink-4c75f7be.mjs';
|
|
3
3
|
export { s as splitLink } from './splitLink-4c75f7be.mjs';
|
|
4
|
-
import { T as TRPCClientError } from './
|
|
5
|
-
export { T as TRPCClientError } from './
|
|
4
|
+
import { T as TRPCClientError } from './TRPCClientError-fef6cf44.mjs';
|
|
5
|
+
export { T as TRPCClientError } from './TRPCClientError-fef6cf44.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-
|
|
8
|
-
export { b as getFetch } from './httpUtils-
|
|
9
|
-
import { c as createHTTPBatchLink } from './httpBatchLink-
|
|
10
|
-
export { h as httpBatchLink } from './httpBatchLink-
|
|
7
|
+
import { f as fetchHTTPResponse, g as getUrl, a as getBody$1, h as httpRequest } from './httpUtils-1efcb902.mjs';
|
|
8
|
+
export { b as getFetch } from './httpUtils-1efcb902.mjs';
|
|
9
|
+
import { c as createHTTPBatchLink } from './httpBatchLink-fbd7b43c.mjs';
|
|
10
|
+
export { h as httpBatchLink } from './httpBatchLink-fbd7b43c.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';
|
|
14
14
|
export { createWSClient, wsLink } from './links/wsLink.mjs';
|
|
15
|
+
import './transformResult-7ab522e6.mjs';
|
|
15
16
|
|
|
16
17
|
class TRPCUntypedClient {
|
|
17
18
|
$request({ type , input , path , context ={} }) {
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var links_httpBatchLink = require('../httpBatchLink-
|
|
6
|
-
require('../httpUtils-
|
|
5
|
+
var links_httpBatchLink = require('../httpBatchLink-2abec973.js');
|
|
6
|
+
require('../httpUtils-cc69e11f.js');
|
|
7
7
|
require('@trpc/server/observable');
|
|
8
|
-
require('../transformResult-
|
|
8
|
+
require('../transformResult-26a22823.js');
|
|
9
|
+
require('../TRPCClientError-dffb44e0.js');
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { h as httpBatchLink } from '../httpBatchLink-
|
|
2
|
-
import '../httpUtils-
|
|
1
|
+
export { h as httpBatchLink } from '../httpBatchLink-fbd7b43c.mjs';
|
|
2
|
+
import '../httpUtils-1efcb902.mjs';
|
|
3
3
|
import '@trpc/server/observable';
|
|
4
|
-
import '../transformResult-
|
|
4
|
+
import '../transformResult-7ab522e6.mjs';
|
|
5
|
+
import '../TRPCClientError-fef6cf44.mjs';
|
|
@@ -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;AAIzC,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO,EACL,mBAAmB,EAGnB,SAAS,EAEV,MAAM,uBAAuB,CAAC;AAC/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,uBAuDxB;AAED,eAAO,MAAM,QAAQ,oCAzDX,eAAe,sBAyDgD,CAAC"}
|
package/dist/links/httpLink.js
CHANGED
|
@@ -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-
|
|
7
|
-
var
|
|
6
|
+
var transformResult = require('../transformResult-26a22823.js');
|
|
7
|
+
var TRPCClientError = require('../TRPCClientError-dffb44e0.js');
|
|
8
|
+
var httpUtils = require('../httpUtils-cc69e11f.js');
|
|
8
9
|
|
|
9
10
|
function httpLinkFactory(factoryOpts) {
|
|
10
11
|
return (opts)=>{
|
|
@@ -29,11 +30,13 @@ function httpLinkFactory(factoryOpts) {
|
|
|
29
30
|
return opts.headers;
|
|
30
31
|
}
|
|
31
32
|
});
|
|
33
|
+
let meta = undefined;
|
|
32
34
|
promise.then((res)=>{
|
|
35
|
+
meta = res.meta;
|
|
33
36
|
const transformed = transformResult.transformResult(res.json, runtime);
|
|
34
37
|
if (!transformed.ok) {
|
|
35
|
-
observer.error(
|
|
36
|
-
meta
|
|
38
|
+
observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
|
|
39
|
+
meta
|
|
37
40
|
}));
|
|
38
41
|
return;
|
|
39
42
|
}
|
|
@@ -43,7 +46,9 @@ function httpLinkFactory(factoryOpts) {
|
|
|
43
46
|
});
|
|
44
47
|
observer.complete();
|
|
45
48
|
}).catch((cause)=>{
|
|
46
|
-
observer.error(
|
|
49
|
+
observer.error(TRPCClientError.TRPCClientError.from(cause, {
|
|
50
|
+
meta
|
|
51
|
+
}));
|
|
47
52
|
});
|
|
48
53
|
return ()=>{
|
|
49
54
|
cancel();
|
package/dist/links/httpLink.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
|
-
import { t as transformResult
|
|
3
|
-
import {
|
|
2
|
+
import { t as transformResult } from '../transformResult-7ab522e6.mjs';
|
|
3
|
+
import { T as TRPCClientError } from '../TRPCClientError-fef6cf44.mjs';
|
|
4
|
+
import { r as resolveHTTPLinkOptions, j as jsonHttpRequester } from '../httpUtils-1efcb902.mjs';
|
|
4
5
|
|
|
5
6
|
function httpLinkFactory(factoryOpts) {
|
|
6
7
|
return (opts)=>{
|
|
@@ -25,11 +26,13 @@ function httpLinkFactory(factoryOpts) {
|
|
|
25
26
|
return opts.headers;
|
|
26
27
|
}
|
|
27
28
|
});
|
|
29
|
+
let meta = undefined;
|
|
28
30
|
promise.then((res)=>{
|
|
31
|
+
meta = res.meta;
|
|
29
32
|
const transformed = transformResult(res.json, runtime);
|
|
30
33
|
if (!transformed.ok) {
|
|
31
34
|
observer.error(TRPCClientError.from(transformed.error, {
|
|
32
|
-
meta
|
|
35
|
+
meta
|
|
33
36
|
}));
|
|
34
37
|
return;
|
|
35
38
|
}
|
|
@@ -39,7 +42,9 @@ function httpLinkFactory(factoryOpts) {
|
|
|
39
42
|
});
|
|
40
43
|
observer.complete();
|
|
41
44
|
}).catch((cause)=>{
|
|
42
|
-
observer.error(TRPCClientError.from(cause
|
|
45
|
+
observer.error(TRPCClientError.from(cause, {
|
|
46
|
+
meta
|
|
47
|
+
}));
|
|
43
48
|
});
|
|
44
49
|
return ()=>{
|
|
45
50
|
cancel();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHTTPBatchLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/createHTTPBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAEL,UAAU,EACV,uBAAuB,EAExB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,S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,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/B,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAAS,oBAAoB,EACvE,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,qCAGxB,QAAQ,uBAsFjB"}
|
|
@@ -19,7 +19,7 @@ export interface HTTPLinkBaseOptions {
|
|
|
19
19
|
}
|
|
20
20
|
export interface ResolvedHTTPLinkOptions {
|
|
21
21
|
url: string;
|
|
22
|
-
fetch
|
|
22
|
+
fetch?: FetchEsque;
|
|
23
23
|
AbortController: AbortControllerEsque | null;
|
|
24
24
|
}
|
|
25
25
|
export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions): ResolvedHTTPLinkOptions;
|
|
@@ -27,6 +27,7 @@ export interface HTTPResult {
|
|
|
27
27
|
json: TRPCResponse;
|
|
28
28
|
meta: {
|
|
29
29
|
response: ResponseEsque;
|
|
30
|
+
responseJSON?: unknown;
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
type GetInputOptions = {
|