@trpc/server 11.0.0-next-alpha.153 → 11.0.0-next-alpha.154
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/adapters/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -13
- package/dist/adapters/aws-lambda/index.mjs +2 -9
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +3 -11
- package/dist/adapters/express.mjs +3 -11
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +6 -14
- package/dist/adapters/fastify/index.mjs +4 -12
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/index.js +3 -12
- package/dist/adapters/fetch/index.mjs +1 -10
- package/dist/adapters/fetch/types.d.ts +1 -1
- package/dist/adapters/next.d.ts +3 -2
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +5 -13
- package/dist/adapters/next.mjs +3 -11
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/index.js +4 -5
- package/dist/adapters/node-http/content-type/json/index.mjs +2 -3
- package/dist/adapters/node-http/index.js +3 -11
- package/dist/adapters/node-http/index.mjs +3 -11
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/types.d.ts +1 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +3 -11
- package/dist/adapters/standalone.mjs +3 -11
- package/dist/adapters/ws.d.ts +3 -3
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +25 -31
- package/dist/adapters/ws.mjs +3 -9
- package/dist/bundle-analysis.json +74 -604
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +14 -0
- package/dist/http.mjs +1 -0
- package/dist/index.d.ts +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -95
- package/dist/index.mjs +1 -90
- package/dist/{nodeHTTPRequestHandler-a7049e69.js → nodeHTTPRequestHandler-30028c9a.js} +3 -5
- package/dist/{nodeHTTPRequestHandler-ca65b7c9.mjs → nodeHTTPRequestHandler-36974696.mjs} +1 -3
- package/dist/{nodeHTTPRequestHandler-abbfb330.js → nodeHTTPRequestHandler-640c1f60.js} +1 -3
- package/dist/observable.d.ts +2 -0
- package/dist/observable.d.ts.map +1 -0
- package/dist/observable.js +14 -0
- package/dist/observable.mjs +1 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +14 -0
- package/dist/rpc.mjs +1 -0
- package/dist/unstableDoNotImportThis.d.ts +9 -0
- package/dist/unstableDoNotImportThis.d.ts.map +1 -0
- package/package.json +32 -41
- package/src/adapters/aws-lambda/index.ts +2 -3
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +4 -3
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +4 -3
- package/src/adapters/fetch/types.ts +1 -1
- package/src/adapters/next.ts +3 -8
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +4 -3
- package/src/adapters/node-http/types.ts +1 -2
- package/src/adapters/standalone.ts +1 -1
- package/src/adapters/ws.ts +14 -9
- package/src/http.ts +2 -0
- package/src/index.ts +30 -14
- package/src/observable.ts +1 -0
- package/src/rpc.ts +2 -0
- package/src/unstableDoNotImportThis.ts +9 -0
- package/dist/TRPCError-0b220715.js +0 -42
- package/dist/TRPCError-2bb6a7d0.js +0 -37
- package/dist/TRPCError-7e8e2a1b.mjs +0 -39
- package/dist/batchStreamFormatter-2c1405a1.js +0 -31
- package/dist/batchStreamFormatter-93cdcdd4.js +0 -32
- package/dist/batchStreamFormatter-fc1ffb26.mjs +0 -30
- package/dist/codes-62b059d2.js +0 -48
- package/dist/codes-87f6824b.js +0 -48
- package/dist/codes-c924c3db.mjs +0 -44
- package/dist/config-50853f49.mjs +0 -6
- package/dist/config-774dae36.js +0 -8
- package/dist/config-e3dd843b.js +0 -11
- package/dist/contentType-0447b256.js +0 -58
- package/dist/contentType-31223e57.mjs +0 -52
- package/dist/contentType-a229790b.js +0 -54
- package/dist/core/index.d.ts +0 -9
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/initTRPC.d.ts +0 -84
- package/dist/core/initTRPC.d.ts.map +0 -1
- package/dist/core/internals/config.d.ts +0 -75
- package/dist/core/internals/config.d.ts.map +0 -1
- package/dist/core/internals/getParseFn.d.ts +0 -4
- package/dist/core/internals/getParseFn.d.ts.map +0 -1
- package/dist/core/internals/mergeRouters.d.ts +0 -15
- package/dist/core/internals/mergeRouters.d.ts.map +0 -1
- package/dist/core/internals/mergeWithoutOverrides.d.ts +0 -5
- package/dist/core/internals/mergeWithoutOverrides.d.ts.map +0 -1
- package/dist/core/internals/omitPrototype.d.ts +0 -6
- package/dist/core/internals/omitPrototype.d.ts.map +0 -1
- package/dist/core/internals/procedureBuilder.d.ts +0 -99
- package/dist/core/internals/procedureBuilder.d.ts.map +0 -1
- package/dist/core/internals/utils.d.ts +0 -50
- package/dist/core/internals/utils.d.ts.map +0 -1
- package/dist/core/middleware.d.ts +0 -106
- package/dist/core/middleware.d.ts.map +0 -1
- package/dist/core/parser.d.ts +0 -28
- package/dist/core/parser.d.ts.map +0 -1
- package/dist/core/procedure.d.ts +0 -54
- package/dist/core/procedure.d.ts.map +0 -1
- package/dist/core/router.d.ts +0 -64
- package/dist/core/router.d.ts.map +0 -1
- package/dist/core/types.d.ts +0 -24
- package/dist/core/types.d.ts.map +0 -1
- package/dist/error/TRPCError.d.ts +0 -12
- package/dist/error/TRPCError.d.ts.map +0 -1
- package/dist/error/formatter.d.ts +0 -33
- package/dist/error/formatter.d.ts.map +0 -1
- package/dist/error/utils.d.ts +0 -9
- package/dist/error/utils.d.ts.map +0 -1
- package/dist/getCauseFromUnknown-2d66414a.mjs +0 -33
- package/dist/getCauseFromUnknown-ac5f46a2.js +0 -34
- package/dist/getCauseFromUnknown-d535264a.js +0 -35
- package/dist/http/batchStreamFormatter.d.ts +0 -24
- package/dist/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/http/contentType.d.ts +0 -29
- package/dist/http/contentType.d.ts.map +0 -1
- package/dist/http/getHTTPStatusCode.d.ts +0 -24
- package/dist/http/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/http/index.d.ts +0 -5
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -22
- package/dist/http/index.mjs +0 -10
- package/dist/http/internals/types.d.ts +0 -32
- package/dist/http/internals/types.d.ts.map +0 -1
- package/dist/http/resolveHTTPResponse.d.ts +0 -52
- package/dist/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/http/types.d.ts +0 -46
- package/dist/http/types.d.ts.map +0 -1
- package/dist/index-8759c3db.js +0 -48
- package/dist/index-a496f86b.js +0 -52
- package/dist/index-a9e3e610.mjs +0 -49
- package/dist/internals/invert.d.ts +0 -12
- package/dist/internals/invert.d.ts.map +0 -1
- package/dist/internals/types.d.ts +0 -26
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/observable/index.d.ts +0 -5
- package/dist/observable/index.d.ts.map +0 -1
- package/dist/observable/index.js +0 -156
- package/dist/observable/index.mjs +0 -147
- package/dist/observable/internals/identity.d.ts +0 -2
- package/dist/observable/internals/identity.d.ts.map +0 -1
- package/dist/observable/internals/observableToPromise.d.ts +0 -10
- package/dist/observable/internals/observableToPromise.d.ts.map +0 -1
- package/dist/observable/internals/pipe.d.ts +0 -4
- package/dist/observable/internals/pipe.d.ts.map +0 -1
- package/dist/observable/observable.d.ts +0 -5
- package/dist/observable/observable.d.ts.map +0 -1
- package/dist/observable/operators/index.d.ts +0 -4
- package/dist/observable/operators/index.d.ts.map +0 -1
- package/dist/observable/operators/map.d.ts +0 -3
- package/dist/observable/operators/map.d.ts.map +0 -1
- package/dist/observable/operators/share.d.ts +0 -6
- package/dist/observable/operators/share.d.ts.map +0 -1
- package/dist/observable/operators/tap.d.ts +0 -3
- package/dist/observable/operators/tap.d.ts.map +0 -1
- package/dist/observable/types.d.ts +0 -29
- package/dist/observable/types.d.ts.map +0 -1
- package/dist/observable-15588f28.js +0 -83
- package/dist/observable-464116ac.js +0 -84
- package/dist/observable-ade1bad8.mjs +0 -81
- package/dist/parseTRPCMessage-1377f305.js +0 -56
- package/dist/parseTRPCMessage-95955211.js +0 -63
- package/dist/parseTRPCMessage-a0f17853.mjs +0 -54
- package/dist/procedureBuilder-0446e596.js +0 -327
- package/dist/procedureBuilder-4b68e226.js +0 -349
- package/dist/procedureBuilder-cf58dadb.mjs +0 -340
- package/dist/resolveHTTPResponse-3ebaa4f6.mjs +0 -292
- package/dist/resolveHTTPResponse-7c84e387.js +0 -294
- package/dist/resolveHTTPResponse-fa37ffd7.js +0 -266
- package/dist/router-18d63731.js +0 -163
- package/dist/router-8dcebd61.js +0 -153
- package/dist/router-f9ce121f.mjs +0 -156
- package/dist/rpc/codes.d.ts +0 -51
- package/dist/rpc/codes.d.ts.map +0 -1
- package/dist/rpc/envelopes.d.ts +0 -95
- package/dist/rpc/envelopes.d.ts.map +0 -1
- package/dist/rpc/index.d.ts +0 -4
- package/dist/rpc/index.d.ts.map +0 -1
- package/dist/rpc/index.js +0 -12
- package/dist/rpc/index.mjs +0 -2
- package/dist/rpc/parseTRPCMessage.d.ts +0 -5
- package/dist/rpc/parseTRPCMessage.d.ts.map +0 -1
- package/dist/shared/createProxy/index.d.ts +0 -19
- package/dist/shared/createProxy/index.d.ts.map +0 -1
- package/dist/shared/getCauseFromUnknown.d.ts +0 -2
- package/dist/shared/getCauseFromUnknown.d.ts.map +0 -1
- package/dist/shared/getErrorShape.d.ts +0 -15
- package/dist/shared/getErrorShape.d.ts.map +0 -1
- package/dist/shared/index.d.ts +0 -8
- package/dist/shared/index.d.ts.map +0 -1
- package/dist/shared/index.js +0 -16
- package/dist/shared/index.mjs +0 -4
- package/dist/shared/internal/serialize.d.ts +0 -62
- package/dist/shared/internal/serialize.d.ts.map +0 -1
- package/dist/shared/jsonify.d.ts +0 -11
- package/dist/shared/jsonify.d.ts.map +0 -1
- package/dist/shared/transformTRPCResponse.d.ts +0 -9
- package/dist/shared/transformTRPCResponse.d.ts.map +0 -1
- package/dist/shared/types.d.ts +0 -6
- package/dist/shared/types.d.ts.map +0 -1
- package/dist/transformTRPCResponse-31040a38.mjs +0 -98
- package/dist/transformTRPCResponse-59486a84.js +0 -97
- package/dist/transformTRPCResponse-9f3b865f.js +0 -104
- package/dist/transformer.d.ts +0 -67
- package/dist/transformer.d.ts.map +0 -1
- package/dist/types.d.ts +0 -68
- package/dist/types.d.ts.map +0 -1
- package/dist/unstableInternalsExport.d.ts +0 -12
- package/dist/unstableInternalsExport.d.ts.map +0 -1
- package/dist/unstableInternalsExport.js +0 -16
- package/dist/unstableInternalsExport.mjs +0 -5
- package/src/core/index.ts +0 -28
- package/src/core/initTRPC.ts +0 -186
- package/src/core/internals/config.ts +0 -90
- package/src/core/internals/getParseFn.ts +0 -43
- package/src/core/internals/mergeRouters.ts +0 -90
- package/src/core/internals/mergeWithoutOverrides.ts +0 -19
- package/src/core/internals/omitPrototype.ts +0 -9
- package/src/core/internals/procedureBuilder.ts +0 -455
- package/src/core/internals/utils.ts +0 -79
- package/src/core/middleware.ts +0 -236
- package/src/core/parser.ts +0 -52
- package/src/core/procedure.ts +0 -68
- package/src/core/router.ts +0 -241
- package/src/core/types.ts +0 -67
- package/src/error/TRPCError.ts +0 -52
- package/src/error/formatter.ts +0 -54
- package/src/error/utils.ts +0 -23
- package/src/http/batchStreamFormatter.ts +0 -29
- package/src/http/contentType.ts +0 -99
- package/src/http/getHTTPStatusCode.ts +0 -61
- package/src/http/index.ts +0 -4
- package/src/http/internals/types.ts +0 -40
- package/src/http/resolveHTTPResponse.ts +0 -458
- package/src/http/types.ts +0 -51
- package/src/internals/invert.ts +0 -21
- package/src/internals/types.ts +0 -27
- package/src/observable/index.ts +0 -4
- package/src/observable/internals/identity.ts +0 -3
- package/src/observable/internals/observableToPromise.ts +0 -49
- package/src/observable/internals/pipe.ts +0 -23
- package/src/observable/observable.ts +0 -78
- package/src/observable/operators/index.ts +0 -3
- package/src/observable/operators/map.ts +0 -25
- package/src/observable/operators/share.ts +0 -65
- package/src/observable/operators/tap.ts +0 -26
- package/src/observable/types.ts +0 -80
- package/src/rpc/codes.ts +0 -44
- package/src/rpc/envelopes.ts +0 -136
- package/src/rpc/index.ts +0 -3
- package/src/rpc/parseTRPCMessage.ts +0 -84
- package/src/shared/createProxy/index.ts +0 -59
- package/src/shared/getCauseFromUnknown.ts +0 -31
- package/src/shared/getErrorShape.ts +0 -36
- package/src/shared/index.ts +0 -11
- package/src/shared/internal/serialize.ts +0 -122
- package/src/shared/jsonify.ts +0 -22
- package/src/shared/transformTRPCResponse.ts +0 -40
- package/src/shared/types.ts +0 -9
- package/src/transformer.ts +0 -84
- package/src/types.ts +0 -104
- package/src/unstableInternalsExport.ts +0 -13
- package/subscription/index.d.ts +0 -1
- package/subscription/index.js +0 -1
- package/unstableInternalsExport/index.d.ts +0 -1
- package/unstableInternalsExport/index.js +0 -1
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { pipeFromArray } from './internals/pipe';
|
|
2
|
-
import { Observable, Observer, OperatorFunction, TeardownLogic } from './types';
|
|
3
|
-
|
|
4
|
-
export type inferObservableValue<TObservable> = TObservable extends Observable<
|
|
5
|
-
infer TValue,
|
|
6
|
-
unknown
|
|
7
|
-
>
|
|
8
|
-
? TValue
|
|
9
|
-
: never;
|
|
10
|
-
|
|
11
|
-
export function isObservable(x: unknown): x is Observable<unknown, unknown> {
|
|
12
|
-
return typeof x === 'object' && x !== null && 'subscribe' in x;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function observable<TValue, TError = unknown>(
|
|
16
|
-
subscribe: (observer: Observer<TValue, TError>) => TeardownLogic,
|
|
17
|
-
): Observable<TValue, TError> {
|
|
18
|
-
const self: Observable<TValue, TError> = {
|
|
19
|
-
subscribe(observer) {
|
|
20
|
-
let teardownRef: TeardownLogic | null = null;
|
|
21
|
-
let isDone = false;
|
|
22
|
-
let unsubscribed = false;
|
|
23
|
-
let teardownImmediately = false;
|
|
24
|
-
function unsubscribe() {
|
|
25
|
-
if (teardownRef === null) {
|
|
26
|
-
teardownImmediately = true;
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (unsubscribed) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
unsubscribed = true;
|
|
33
|
-
|
|
34
|
-
if (typeof teardownRef === 'function') {
|
|
35
|
-
teardownRef();
|
|
36
|
-
} else if (teardownRef) {
|
|
37
|
-
teardownRef.unsubscribe();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
teardownRef = subscribe({
|
|
41
|
-
next(value) {
|
|
42
|
-
if (isDone) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
observer.next?.(value);
|
|
46
|
-
},
|
|
47
|
-
error(err) {
|
|
48
|
-
if (isDone) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
isDone = true;
|
|
52
|
-
observer.error?.(err);
|
|
53
|
-
unsubscribe();
|
|
54
|
-
},
|
|
55
|
-
complete() {
|
|
56
|
-
if (isDone) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
isDone = true;
|
|
60
|
-
observer.complete?.();
|
|
61
|
-
unsubscribe();
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
if (teardownImmediately) {
|
|
65
|
-
unsubscribe();
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
unsubscribe,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
pipe(
|
|
72
|
-
...operations: OperatorFunction<any, any, any, any>[]
|
|
73
|
-
): Observable<any, any> {
|
|
74
|
-
return pipeFromArray(operations)(self) as any;
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
return self;
|
|
78
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { OperatorFunction } from '../types';
|
|
2
|
-
|
|
3
|
-
export function map<TValueBefore, TError, TValueAfter>(
|
|
4
|
-
project: (value: TValueBefore, index: number) => TValueAfter,
|
|
5
|
-
): OperatorFunction<TValueBefore, TError, TValueAfter, TError> {
|
|
6
|
-
return (originalObserver) => {
|
|
7
|
-
return {
|
|
8
|
-
subscribe(observer) {
|
|
9
|
-
let index = 0;
|
|
10
|
-
const subscription = originalObserver.subscribe({
|
|
11
|
-
next(value) {
|
|
12
|
-
observer.next?.(project(value, index++));
|
|
13
|
-
},
|
|
14
|
-
error(error) {
|
|
15
|
-
observer.error?.(error);
|
|
16
|
-
},
|
|
17
|
-
complete() {
|
|
18
|
-
observer.complete?.();
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
return subscription;
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction, Observer, Unsubscribable } from '../types';
|
|
2
|
-
|
|
3
|
-
interface ShareConfig {}
|
|
4
|
-
export function share<TValue, TError>(
|
|
5
|
-
_opts?: ShareConfig,
|
|
6
|
-
): MonoTypeOperatorFunction<TValue, TError> {
|
|
7
|
-
return (originalObserver) => {
|
|
8
|
-
let refCount = 0;
|
|
9
|
-
|
|
10
|
-
let subscription: Unsubscribable | null = null;
|
|
11
|
-
const observers: Partial<Observer<TValue, TError>>[] = [];
|
|
12
|
-
|
|
13
|
-
function startIfNeeded() {
|
|
14
|
-
if (subscription) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
subscription = originalObserver.subscribe({
|
|
18
|
-
next(value) {
|
|
19
|
-
for (const observer of observers) {
|
|
20
|
-
observer.next?.(value);
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
error(error) {
|
|
24
|
-
for (const observer of observers) {
|
|
25
|
-
observer.error?.(error);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
complete() {
|
|
29
|
-
for (const observer of observers) {
|
|
30
|
-
observer.complete?.();
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function resetIfNeeded() {
|
|
36
|
-
// "resetOnRefCountZero"
|
|
37
|
-
if (refCount === 0 && subscription) {
|
|
38
|
-
const _sub = subscription;
|
|
39
|
-
subscription = null;
|
|
40
|
-
_sub.unsubscribe();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
subscribe(observer) {
|
|
46
|
-
refCount++;
|
|
47
|
-
|
|
48
|
-
observers.push(observer);
|
|
49
|
-
startIfNeeded();
|
|
50
|
-
return {
|
|
51
|
-
unsubscribe() {
|
|
52
|
-
refCount--;
|
|
53
|
-
resetIfNeeded();
|
|
54
|
-
|
|
55
|
-
const index = observers.findIndex((v) => v === observer);
|
|
56
|
-
|
|
57
|
-
if (index > -1) {
|
|
58
|
-
observers.splice(index, 1);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction, Observer } from '../types';
|
|
2
|
-
|
|
3
|
-
export function tap<TValue, TError>(
|
|
4
|
-
observer: Partial<Observer<TValue, TError>>,
|
|
5
|
-
): MonoTypeOperatorFunction<TValue, TError> {
|
|
6
|
-
return (originalObserver) => {
|
|
7
|
-
return {
|
|
8
|
-
subscribe(observer2) {
|
|
9
|
-
return originalObserver.subscribe({
|
|
10
|
-
next(v) {
|
|
11
|
-
observer.next?.(v);
|
|
12
|
-
observer2.next?.(v);
|
|
13
|
-
},
|
|
14
|
-
error(v) {
|
|
15
|
-
observer.error?.(v);
|
|
16
|
-
observer2.error?.(v);
|
|
17
|
-
},
|
|
18
|
-
complete() {
|
|
19
|
-
observer.complete?.();
|
|
20
|
-
observer2.complete?.();
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
}
|
package/src/observable/types.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
export interface Unsubscribable {
|
|
2
|
-
unsubscribe(): void;
|
|
3
|
-
}
|
|
4
|
-
export type UnsubscribeFn = () => void;
|
|
5
|
-
export interface Subscribable<TValue, TError> {
|
|
6
|
-
subscribe(observer: Partial<Observer<TValue, TError>>): Unsubscribable;
|
|
7
|
-
}
|
|
8
|
-
export interface Observable<TValue, TError>
|
|
9
|
-
extends Subscribable<TValue, TError> {
|
|
10
|
-
pipe(): Observable<TValue, TError>;
|
|
11
|
-
pipe<TValue1, TError1>(
|
|
12
|
-
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
13
|
-
): Observable<TValue1, TError1>;
|
|
14
|
-
pipe<TValue1, TError1, TValue2, TError2>(
|
|
15
|
-
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
16
|
-
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
17
|
-
): Observable<TValue2, TError2>;
|
|
18
|
-
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3>(
|
|
19
|
-
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
20
|
-
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
21
|
-
op3: OperatorFunction<TValue2, TError2, TValue3, TError3>,
|
|
22
|
-
): Observable<TValue2, TError2>;
|
|
23
|
-
pipe<TValue1, TError1, TValue2, TError2, TValue3, TError3, TValue4, TError4>(
|
|
24
|
-
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
25
|
-
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
26
|
-
op3: OperatorFunction<TValue2, TError2, TValue3, TError3>,
|
|
27
|
-
op4: OperatorFunction<TValue3, TError3, TValue4, TError4>,
|
|
28
|
-
): Observable<TValue2, TError2>;
|
|
29
|
-
pipe<
|
|
30
|
-
TValue1,
|
|
31
|
-
TError1,
|
|
32
|
-
TValue2,
|
|
33
|
-
TError2,
|
|
34
|
-
TValue3,
|
|
35
|
-
TError3,
|
|
36
|
-
TValue4,
|
|
37
|
-
TError4,
|
|
38
|
-
TValue5,
|
|
39
|
-
TError5,
|
|
40
|
-
>(
|
|
41
|
-
op1: OperatorFunction<TValue, TError, TValue1, TError1>,
|
|
42
|
-
op2: OperatorFunction<TValue1, TError1, TValue2, TError2>,
|
|
43
|
-
op3: OperatorFunction<TValue2, TError2, TValue3, TError3>,
|
|
44
|
-
op4: OperatorFunction<TValue3, TError3, TValue4, TError4>,
|
|
45
|
-
op5: OperatorFunction<TValue4, TError4, TValue5, TError5>,
|
|
46
|
-
): Observable<TValue2, TError2>;
|
|
47
|
-
}
|
|
48
|
-
export interface SubscriptionLike extends Unsubscribable {
|
|
49
|
-
unsubscribe(): void;
|
|
50
|
-
readonly closed: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface Observer<TValue, TError> {
|
|
54
|
-
next: (value: TValue) => void;
|
|
55
|
-
error: (err: TError) => void;
|
|
56
|
-
complete: () => void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type TeardownLogic =
|
|
60
|
-
// | SubscriptionLike
|
|
61
|
-
Unsubscribable | UnsubscribeFn | void;
|
|
62
|
-
|
|
63
|
-
export type UnaryFunction<TSource, TReturn> = (source: TSource) => TReturn;
|
|
64
|
-
|
|
65
|
-
export type OperatorFunction<
|
|
66
|
-
TValueBefore,
|
|
67
|
-
TErrorBefore,
|
|
68
|
-
TValueAfter,
|
|
69
|
-
TErrorAfter,
|
|
70
|
-
> = UnaryFunction<
|
|
71
|
-
Subscribable<TValueBefore, TErrorBefore>,
|
|
72
|
-
Subscribable<TValueAfter, TErrorAfter>
|
|
73
|
-
>;
|
|
74
|
-
|
|
75
|
-
export type MonoTypeOperatorFunction<TValue, TError> = OperatorFunction<
|
|
76
|
-
TValue,
|
|
77
|
-
TError,
|
|
78
|
-
TValue,
|
|
79
|
-
TError
|
|
80
|
-
>;
|
package/src/rpc/codes.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { invert } from '../internals/invert';
|
|
2
|
-
|
|
3
|
-
// reference: https://www.jsonrpc.org/specification
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* JSON-RPC 2.0 Error codes
|
|
7
|
-
*
|
|
8
|
-
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
|
9
|
-
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
|
10
|
-
*/
|
|
11
|
-
export const TRPC_ERROR_CODES_BY_KEY = {
|
|
12
|
-
/**
|
|
13
|
-
* Invalid JSON was received by the server.
|
|
14
|
-
* An error occurred on the server while parsing the JSON text.
|
|
15
|
-
*/
|
|
16
|
-
PARSE_ERROR: -32700,
|
|
17
|
-
/**
|
|
18
|
-
* The JSON sent is not a valid Request object.
|
|
19
|
-
*/
|
|
20
|
-
BAD_REQUEST: -32600, // 400
|
|
21
|
-
|
|
22
|
-
// Internal JSON-RPC error
|
|
23
|
-
INTERNAL_SERVER_ERROR: -32603,
|
|
24
|
-
NOT_IMPLEMENTED: -32603,
|
|
25
|
-
|
|
26
|
-
// Implementation specific errors
|
|
27
|
-
UNAUTHORIZED: -32001, // 401
|
|
28
|
-
FORBIDDEN: -32003, // 403
|
|
29
|
-
NOT_FOUND: -32004, // 404
|
|
30
|
-
METHOD_NOT_SUPPORTED: -32005, // 405
|
|
31
|
-
TIMEOUT: -32008, // 408
|
|
32
|
-
CONFLICT: -32009, // 409
|
|
33
|
-
PRECONDITION_FAILED: -32012, // 412
|
|
34
|
-
PAYLOAD_TOO_LARGE: -32013, // 413
|
|
35
|
-
UNPROCESSABLE_CONTENT: -32022, // 422
|
|
36
|
-
TOO_MANY_REQUESTS: -32029, // 429
|
|
37
|
-
CLIENT_CLOSED_REQUEST: -32099, // 499
|
|
38
|
-
} as const;
|
|
39
|
-
|
|
40
|
-
export const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
|
|
41
|
-
type ValueOf<TObj> = TObj[keyof TObj];
|
|
42
|
-
|
|
43
|
-
export type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
44
|
-
export type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
|
package/src/rpc/envelopes.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
-
import { ProcedureType } from '../core';
|
|
3
|
-
import { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Error response
|
|
7
|
-
*/
|
|
8
|
-
export interface TRPCErrorShape<
|
|
9
|
-
TCode extends number = TRPC_ERROR_CODE_NUMBER,
|
|
10
|
-
TData extends Record<string, unknown> = Record<string, unknown>,
|
|
11
|
-
> {
|
|
12
|
-
code: TCode;
|
|
13
|
-
message: string;
|
|
14
|
-
data: TData;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* JSON-RPC 2.0 Specification
|
|
19
|
-
*/
|
|
20
|
-
export namespace JSONRPC2 {
|
|
21
|
-
export type RequestId = number | string | null;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* All requests/responses extends this shape
|
|
25
|
-
*/
|
|
26
|
-
export interface BaseEnvelope {
|
|
27
|
-
id?: RequestId;
|
|
28
|
-
jsonrpc?: '2.0';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface BaseRequest<TMethod extends string = string>
|
|
32
|
-
extends BaseEnvelope {
|
|
33
|
-
method: TMethod;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface Request<TMethod extends string = string, TParams = unknown>
|
|
37
|
-
extends BaseRequest<TMethod> {
|
|
38
|
-
params: TParams;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ResultResponse<TResult = unknown> extends BaseEnvelope {
|
|
42
|
-
result: TResult;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface ErrorResponse<TError extends TRPCErrorShape = TRPCErrorShape>
|
|
46
|
-
extends BaseEnvelope {
|
|
47
|
-
error: TError;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/////////////////////////// HTTP envelopes ///////////////////////
|
|
52
|
-
|
|
53
|
-
export interface TRPCRequest
|
|
54
|
-
extends JSONRPC2.Request<ProcedureType, { path: string; input: unknown }> {}
|
|
55
|
-
|
|
56
|
-
export interface TRPCResult<TData = unknown> {
|
|
57
|
-
data: TData;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface TRPCSuccessResponse<TData>
|
|
61
|
-
extends JSONRPC2.ResultResponse<
|
|
62
|
-
TRPCResult<TData> & {
|
|
63
|
-
type?: 'data';
|
|
64
|
-
}
|
|
65
|
-
> {}
|
|
66
|
-
|
|
67
|
-
export interface TRPCErrorResponse<
|
|
68
|
-
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
69
|
-
> extends JSONRPC2.ErrorResponse<TError> {}
|
|
70
|
-
|
|
71
|
-
export type TRPCResponse<
|
|
72
|
-
TData = unknown,
|
|
73
|
-
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
74
|
-
> = TRPCErrorResponse<TError> | TRPCSuccessResponse<TData>;
|
|
75
|
-
|
|
76
|
-
/////////////////////////// WebSocket envelopes ///////////////////////
|
|
77
|
-
|
|
78
|
-
export type TRPCRequestMessage = TRPCRequest & {
|
|
79
|
-
id: JSONRPC2.RequestId;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The client asked the server to unsubscribe
|
|
84
|
-
*/
|
|
85
|
-
export interface TRPCSubscriptionStopNotification
|
|
86
|
-
extends JSONRPC2.BaseRequest<'subscription.stop'> {
|
|
87
|
-
id: null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The client's outgoing request types
|
|
92
|
-
*/
|
|
93
|
-
export type TRPCClientOutgoingRequest = TRPCSubscriptionStopNotification;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The client's sent messages shape
|
|
97
|
-
*/
|
|
98
|
-
export type TRPCClientOutgoingMessage =
|
|
99
|
-
| TRPCRequestMessage
|
|
100
|
-
| (JSONRPC2.BaseRequest<'subscription.stop'> & { id: JSONRPC2.RequestId });
|
|
101
|
-
|
|
102
|
-
export interface TRPCResultMessage<TData>
|
|
103
|
-
extends JSONRPC2.ResultResponse<
|
|
104
|
-
| { type: 'started' }
|
|
105
|
-
| { type: 'stopped' }
|
|
106
|
-
| (TRPCResult<TData> & { type: 'data' })
|
|
107
|
-
> {}
|
|
108
|
-
|
|
109
|
-
export type TRPCResponseMessage<
|
|
110
|
-
TData = unknown,
|
|
111
|
-
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
112
|
-
> = { id: JSONRPC2.RequestId } & (
|
|
113
|
-
| TRPCErrorResponse<TError>
|
|
114
|
-
| TRPCResultMessage<TData>
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The server asked the client to reconnect - useful when restarting/redeploying service
|
|
119
|
-
*/
|
|
120
|
-
export interface TRPCReconnectNotification
|
|
121
|
-
extends JSONRPC2.BaseRequest<'reconnect'> {
|
|
122
|
-
id: JSONRPC2.RequestId;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* The client's incoming request types
|
|
127
|
-
*/
|
|
128
|
-
export type TRPCClientIncomingRequest = TRPCReconnectNotification;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* The client's received messages shape
|
|
132
|
-
*/
|
|
133
|
-
export type TRPCClientIncomingMessage<
|
|
134
|
-
TResult = unknown,
|
|
135
|
-
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
136
|
-
> = TRPCClientIncomingRequest | TRPCResponseMessage<TResult, TError>;
|
package/src/rpc/index.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { ProcedureType } from '../core';
|
|
2
|
-
import type { CombinedDataTransformer } from '../transformer';
|
|
3
|
-
import type { TRPCClientOutgoingMessage } from './envelopes';
|
|
4
|
-
|
|
5
|
-
/* istanbul ignore next -- @preserve */
|
|
6
|
-
function assertIsObject(obj: unknown): asserts obj is Record<string, unknown> {
|
|
7
|
-
if (typeof obj !== 'object' || Array.isArray(obj) || !obj) {
|
|
8
|
-
throw new Error('Not an object');
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/* istanbul ignore next -- @preserve */
|
|
13
|
-
function assertIsProcedureType(obj: unknown): asserts obj is ProcedureType {
|
|
14
|
-
if (obj !== 'query' && obj !== 'subscription' && obj !== 'mutation') {
|
|
15
|
-
throw new Error('Invalid procedure type');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/* istanbul ignore next -- @preserve */
|
|
20
|
-
function assertIsRequestId(
|
|
21
|
-
obj: unknown,
|
|
22
|
-
): asserts obj is number | string | null {
|
|
23
|
-
if (
|
|
24
|
-
obj !== null &&
|
|
25
|
-
typeof obj === 'number' &&
|
|
26
|
-
isNaN(obj) &&
|
|
27
|
-
typeof obj !== 'string'
|
|
28
|
-
) {
|
|
29
|
-
throw new Error('Invalid request id');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/* istanbul ignore next -- @preserve */
|
|
34
|
-
function assertIsString(obj: unknown): asserts obj is string {
|
|
35
|
-
if (typeof obj !== 'string') {
|
|
36
|
-
throw new Error('Invalid string');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* istanbul ignore next -- @preserve */
|
|
41
|
-
function assertIsJSONRPC2OrUndefined(
|
|
42
|
-
obj: unknown,
|
|
43
|
-
): asserts obj is '2.0' | undefined {
|
|
44
|
-
if (typeof obj !== 'undefined' && obj !== '2.0') {
|
|
45
|
-
throw new Error('Must be JSONRPC 2.0');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** @public */
|
|
50
|
-
export function parseTRPCMessage(
|
|
51
|
-
obj: unknown,
|
|
52
|
-
transformer: CombinedDataTransformer,
|
|
53
|
-
): TRPCClientOutgoingMessage {
|
|
54
|
-
assertIsObject(obj);
|
|
55
|
-
|
|
56
|
-
const { id, jsonrpc, method, params } = obj;
|
|
57
|
-
assertIsRequestId(id);
|
|
58
|
-
assertIsJSONRPC2OrUndefined(jsonrpc);
|
|
59
|
-
|
|
60
|
-
if (method === 'subscription.stop') {
|
|
61
|
-
return {
|
|
62
|
-
id,
|
|
63
|
-
jsonrpc,
|
|
64
|
-
method,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
assertIsProcedureType(method);
|
|
68
|
-
assertIsObject(params);
|
|
69
|
-
const { input: rawInput, path } = params;
|
|
70
|
-
|
|
71
|
-
assertIsString(path);
|
|
72
|
-
|
|
73
|
-
const input = transformer.input.deserialize(rawInput);
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
id,
|
|
77
|
-
jsonrpc,
|
|
78
|
-
method,
|
|
79
|
-
params: {
|
|
80
|
-
input,
|
|
81
|
-
path,
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
interface ProxyCallbackOptions {
|
|
2
|
-
path: string[];
|
|
3
|
-
args: unknown[];
|
|
4
|
-
}
|
|
5
|
-
type ProxyCallback = (opts: ProxyCallbackOptions) => unknown;
|
|
6
|
-
|
|
7
|
-
const noop = () => {
|
|
8
|
-
// noop
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function createInnerProxy(callback: ProxyCallback, path: string[]) {
|
|
12
|
-
const proxy: unknown = new Proxy(noop, {
|
|
13
|
-
get(_obj, key) {
|
|
14
|
-
if (typeof key !== 'string' || key === 'then') {
|
|
15
|
-
// special case for if the proxy is accidentally treated
|
|
16
|
-
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
return createInnerProxy(callback, [...path, key]);
|
|
20
|
-
},
|
|
21
|
-
apply(_1, _2, args) {
|
|
22
|
-
const isApply = path[path.length - 1] === 'apply';
|
|
23
|
-
return callback({
|
|
24
|
-
args: isApply ? (args.length >= 2 ? args[1] : []) : args,
|
|
25
|
-
path: isApply ? path.slice(0, -1) : path,
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return proxy;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Creates a proxy that calls the callback with the path and arguments
|
|
35
|
-
*
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
export const createRecursiveProxy = (callback: ProxyCallback) =>
|
|
39
|
-
createInnerProxy(callback, []);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export const createFlatProxy = <TFaux>(
|
|
47
|
-
callback: (path: string & keyof TFaux) => any,
|
|
48
|
-
): TFaux => {
|
|
49
|
-
return new Proxy(noop, {
|
|
50
|
-
get(_obj, name) {
|
|
51
|
-
if (typeof name !== 'string' || name === 'then') {
|
|
52
|
-
// special case for if the proxy is accidentally treated
|
|
53
|
-
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return callback(name as any);
|
|
57
|
-
},
|
|
58
|
-
}) as TFaux;
|
|
59
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../error/utils';
|
|
2
|
-
|
|
3
|
-
class UnknownCauseError extends Error {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}
|
|
6
|
-
export function getCauseFromUnknown(cause: unknown): Error | undefined {
|
|
7
|
-
if (cause instanceof Error) {
|
|
8
|
-
return cause;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const type = typeof cause;
|
|
12
|
-
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Primitive types just get wrapped in an error
|
|
17
|
-
if (type !== 'object') {
|
|
18
|
-
return new Error(String(cause));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// If it's an object, we'll create a synthetic error
|
|
22
|
-
if (isObject(cause)) {
|
|
23
|
-
const err = new UnknownCauseError();
|
|
24
|
-
for (const key in cause) {
|
|
25
|
-
err[key] = cause[key];
|
|
26
|
-
}
|
|
27
|
-
return err;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ProcedureType } from '../core';
|
|
2
|
-
import { AnyRootConfig } from '../core/internals/config';
|
|
3
|
-
import { DefaultErrorShape } from '../error/formatter';
|
|
4
|
-
import { TRPCError } from '../error/TRPCError';
|
|
5
|
-
import { getHTTPStatusCodeFromError } from '../http/getHTTPStatusCode';
|
|
6
|
-
import { TRPC_ERROR_CODES_BY_KEY } from '../rpc';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function getErrorShape<TConfig extends AnyRootConfig>(opts: {
|
|
12
|
-
config: TConfig;
|
|
13
|
-
error: TRPCError;
|
|
14
|
-
type: ProcedureType | 'unknown';
|
|
15
|
-
path: string | undefined;
|
|
16
|
-
input: unknown;
|
|
17
|
-
ctx: TConfig['$types']['ctx'] | undefined;
|
|
18
|
-
}): TConfig['$types']['errorShape'] {
|
|
19
|
-
const { path, error, config } = opts;
|
|
20
|
-
const { code } = opts.error;
|
|
21
|
-
const shape: DefaultErrorShape = {
|
|
22
|
-
message: error.message,
|
|
23
|
-
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
24
|
-
data: {
|
|
25
|
-
code,
|
|
26
|
-
httpStatus: getHTTPStatusCodeFromError(error),
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
30
|
-
shape.data.stack = opts.error.stack;
|
|
31
|
-
}
|
|
32
|
-
if (typeof path === 'string') {
|
|
33
|
-
shape.data.path = path;
|
|
34
|
-
}
|
|
35
|
-
return config.errorFormatter({ ...opts, shape });
|
|
36
|
-
}
|
package/src/shared/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './createProxy';
|
|
2
|
-
export * from './jsonify';
|
|
3
|
-
export * from './transformTRPCResponse';
|
|
4
|
-
|
|
5
|
-
// For `.d.ts` files https://github.com/trpc/trpc/issues/3943
|
|
6
|
-
export type { SerializeObject, Serialize } from './internal/serialize';
|
|
7
|
-
|
|
8
|
-
export { getErrorShape } from './getErrorShape';
|
|
9
|
-
|
|
10
|
-
export * from './types';
|
|
11
|
-
export { getCauseFromUnknown } from './getCauseFromUnknown';
|