@trpc/server 10.32.0 → 10.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{TRPCError-2b10c8d2.mjs → TRPCError-6a1653a4.mjs} +28 -20
- package/dist/{TRPCError-7c3909ea.js → TRPCError-c3de85e9.js} +28 -21
- package/dist/{TRPCError-16b2e52d.js → TRPCError-d07099d1.js} +27 -20
- package/dist/adapters/aws-lambda/index.js +7 -7
- package/dist/adapters/aws-lambda/index.mjs +7 -7
- package/dist/adapters/express.js +5 -5
- package/dist/adapters/express.mjs +5 -5
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +4 -4
- package/dist/adapters/fastify/index.mjs +4 -4
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +2 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/index.js +4 -4
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/fetch/types.d.ts +1 -1
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.js +5 -5
- package/dist/adapters/next.mjs +5 -5
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +3 -3
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +18 -13
- package/dist/adapters/node-http/content-type/form-data/index.mjs +18 -13
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +1 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +2 -2
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/index.js +2 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +2 -2
- package/dist/adapters/node-http/index.js +5 -5
- package/dist/adapters/node-http/index.mjs +5 -5
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/types.d.ts +4 -6
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.js +5 -5
- package/dist/adapters/standalone.mjs +5 -5
- package/dist/adapters/ws.d.ts +2 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +4 -3
- package/dist/adapters/ws.mjs +4 -3
- package/dist/{config-65c5b6d1.mjs → config-7eddc5bb.mjs} +1 -1
- package/dist/{config-f3ce0144.js → config-943bca43.js} +1 -1
- package/dist/{config-54786004.js → config-94ba862d.js} +1 -1
- package/dist/{contentType-acc3be52.mjs → contentType-53e30af8.mjs} +3 -3
- package/dist/{contentType-8356d528.js → contentType-5b601838.js} +3 -3
- package/dist/{contentType-7354963c.js → contentType-b87cced2.js} +3 -3
- package/dist/core/internals/getParseFn.d.ts +1 -1
- package/dist/core/internals/getParseFn.d.ts.map +1 -1
- package/dist/core/internals/mergeRouters.d.ts +5 -5
- package/dist/core/internals/mergeRouters.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +1 -1
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/parser.d.ts +3 -3
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/procedure.d.ts +1 -1
- package/dist/core/procedure.d.ts.map +1 -1
- package/dist/core/router.d.ts +4 -4
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/deprecated/internals/middlewares.d.ts +1 -1
- package/dist/deprecated/internals/middlewares.d.ts.map +1 -1
- package/dist/deprecated/internals/procedure.d.ts +5 -5
- package/dist/deprecated/internals/procedure.d.ts.map +1 -1
- package/dist/deprecated/router.d.ts +17 -17
- package/dist/deprecated/router.d.ts.map +1 -1
- package/dist/error/TRPCError.d.ts.map +1 -1
- package/dist/error/formatter.d.ts +1 -1
- package/dist/error/formatter.d.ts.map +1 -1
- package/dist/error/utils.d.ts +4 -1
- package/dist/error/utils.d.ts.map +1 -1
- package/dist/http/contentType.d.ts.map +1 -1
- package/dist/http/index.js +4 -4
- package/dist/http/index.mjs +4 -4
- package/dist/http/internals/types.d.ts +1 -1
- package/dist/http/internals/types.d.ts.map +1 -1
- package/dist/http/resolveHTTPResponse.d.ts +1 -1
- package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.mjs +11 -11
- package/dist/internals/types.d.ts +1 -1
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-51d58a23.js → nodeHTTPRequestHandler-46ec104c.js} +2 -1
- package/dist/{nodeHTTPRequestHandler-071d36b5.js → nodeHTTPRequestHandler-61ea01f2.js} +2 -1
- package/dist/{nodeHTTPRequestHandler-bb12529f.mjs → nodeHTTPRequestHandler-dbfdf9a5.mjs} +2 -1
- package/dist/observable/internals/pipe.d.ts +1 -1
- package/dist/observable/internals/pipe.d.ts.map +1 -1
- package/dist/{resolveHTTPResponse-1f03fdfd.js → resolveHTTPResponse-199d522a.js} +4 -4
- package/dist/{resolveHTTPResponse-dd3677b3.mjs → resolveHTTPResponse-25592372.mjs} +4 -4
- package/dist/{resolveHTTPResponse-e0047ea2.js → resolveHTTPResponse-33a8a5fc.js} +4 -4
- package/dist/rpc/envelopes.d.ts +11 -11
- package/dist/rpc/envelopes.d.ts.map +1 -1
- package/dist/shared/createProxy/index.d.ts +1 -1
- package/dist/shared/getErrorShape.d.ts +1 -1
- package/dist/shared/getErrorShape.d.ts.map +1 -1
- package/dist/shared/internal/serialize.d.ts +4 -4
- package/dist/shared/internal/serialize.d.ts.map +1 -1
- package/dist/shared/transformTRPCResponse.d.ts +1 -1
- package/dist/subscription.d.ts +1 -1
- package/dist/subscription.d.ts.map +1 -1
- package/dist/subscription.js +4 -2
- package/dist/subscription.mjs +4 -2
- package/dist/transformer.d.ts +2 -2
- package/dist/transformer.d.ts.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/adapters/aws-lambda/utils.ts +3 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +4 -4
- package/src/adapters/fetch/fetchRequestHandler.ts +7 -6
- package/src/adapters/fetch/types.ts +1 -1
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +13 -11
- package/src/adapters/node-http/content-type/form-data/index.ts +2 -2
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +1 -1
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +5 -3
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -0
- package/src/adapters/node-http/types.ts +29 -29
- package/src/adapters/ws.ts +8 -7
- package/src/core/internals/getParseFn.ts +1 -1
- package/src/core/internals/mergeRouters.ts +6 -6
- package/src/core/middleware.ts +4 -5
- package/src/core/parser.ts +5 -5
- package/src/core/procedure.ts +1 -1
- package/src/core/router.ts +4 -4
- package/src/core/types.ts +1 -1
- package/src/deprecated/internals/middlewares.ts +2 -2
- package/src/deprecated/internals/procedure.ts +25 -28
- package/src/deprecated/router.ts +35 -35
- package/src/error/TRPCError.ts +35 -4
- package/src/error/formatter.ts +1 -1
- package/src/error/utils.ts +1 -9
- package/src/http/contentType.ts +2 -3
- package/src/http/internals/types.ts +1 -1
- package/src/http/resolveHTTPResponse.ts +6 -6
- package/src/internals/types.ts +1 -1
- package/src/observable/internals/pipe.ts +1 -1
- package/src/rpc/envelopes.ts +7 -7
- package/src/shared/createProxy/index.ts +1 -1
- package/src/shared/getErrorShape.ts +1 -1
- package/src/shared/internal/serialize.ts +4 -14
- package/src/subscription.ts +4 -2
- package/src/transformer.ts +3 -3
- package/src/types.ts +8 -7
package/src/error/TRPCError.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
|
|
2
|
-
import {
|
|
2
|
+
import { isObject } from './utils';
|
|
3
3
|
|
|
4
4
|
export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
|
|
5
5
|
if (cause instanceof TRPCError) {
|
|
@@ -19,6 +19,37 @@ export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
|
|
|
19
19
|
return trpcError;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
class UnknownCauseError extends Error {
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getCauseFromUnknown(cause: unknown): Error | undefined {
|
|
27
|
+
if (cause instanceof Error) {
|
|
28
|
+
return cause;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const type = typeof cause;
|
|
32
|
+
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Primitive types just get wrapped in an error
|
|
37
|
+
if (type !== 'object') {
|
|
38
|
+
return new Error(String(cause));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If it's an object, we'll create a synthetic error
|
|
42
|
+
if (isObject(cause)) {
|
|
43
|
+
const err = new UnknownCauseError();
|
|
44
|
+
for (const key in cause) {
|
|
45
|
+
err[key] = cause[key];
|
|
46
|
+
}
|
|
47
|
+
return err;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
22
53
|
export class TRPCError extends Error {
|
|
23
54
|
public readonly cause?: Error;
|
|
24
55
|
public readonly code;
|
|
@@ -28,12 +59,12 @@ export class TRPCError extends Error {
|
|
|
28
59
|
code: TRPC_ERROR_CODE_KEY;
|
|
29
60
|
cause?: unknown;
|
|
30
61
|
}) {
|
|
31
|
-
const
|
|
32
|
-
|
|
62
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
63
|
+
const message = opts.message ?? cause?.message ?? opts.code;
|
|
33
64
|
|
|
34
65
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
66
|
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
36
|
-
super(message, { cause
|
|
67
|
+
super(message, { cause });
|
|
37
68
|
|
|
38
69
|
this.code = opts.code;
|
|
39
70
|
this.name = this.constructor.name;
|
package/src/error/formatter.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type ErrorFormatter<TContext, TShape extends TRPCErrorShape<number>> = ({
|
|
|
16
16
|
type: ProcedureType | 'unknown';
|
|
17
17
|
path: string | undefined;
|
|
18
18
|
input: unknown;
|
|
19
|
-
ctx:
|
|
19
|
+
ctx: TContext | undefined;
|
|
20
20
|
shape: DefaultErrorShape;
|
|
21
21
|
}) => TShape;
|
|
22
22
|
|
package/src/error/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
|
-
function isObject(value: unknown): value is Record<string, unknown> {
|
|
4
|
+
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
5
5
|
// check that value is object
|
|
6
6
|
return !!value && !Array.isArray(value) && typeof value === 'object';
|
|
7
7
|
}
|
|
@@ -21,11 +21,3 @@ export function getMessageFromUnknownError(
|
|
|
21
21
|
}
|
|
22
22
|
return fallback;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
export function getCauseFromUnknown(cause: unknown) {
|
|
26
|
-
if (cause instanceof Error) {
|
|
27
|
-
return cause;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
package/src/http/contentType.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { AnyRouter } from '../core';
|
|
3
3
|
import { TRPCError } from '../error/TRPCError';
|
|
4
|
-
import { getCauseFromUnknown } from '../error/utils';
|
|
5
4
|
import { CombinedDataTransformer } from '../transformer';
|
|
6
5
|
import { MaybePromise } from '../types';
|
|
7
6
|
import { HTTPRequest } from './types';
|
|
@@ -48,10 +47,10 @@ function getRawProcedureInputOrThrow(opts: {
|
|
|
48
47
|
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
49
48
|
}
|
|
50
49
|
return req.body;
|
|
51
|
-
} catch (
|
|
50
|
+
} catch (cause) {
|
|
52
51
|
throw new TRPCError({
|
|
53
52
|
code: 'PARSE_ERROR',
|
|
54
|
-
cause
|
|
53
|
+
cause,
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -9,7 +9,7 @@ import { TRPCResponse } from '../../rpc';
|
|
|
9
9
|
import { Dict } from '../../types';
|
|
10
10
|
import { ResponseMeta } from '../types';
|
|
11
11
|
|
|
12
|
-
export type HTTPHeaders = Dict<string | string
|
|
12
|
+
export type HTTPHeaders = Dict<string[] | string>;
|
|
13
13
|
|
|
14
14
|
export interface HTTPResponse {
|
|
15
15
|
status: number;
|
|
@@ -133,10 +133,10 @@ async function inputToProcedureCall<
|
|
|
133
133
|
>(procedureOpts: {
|
|
134
134
|
opts: Pick<
|
|
135
135
|
ResolveHTTPRequestOptions<TRouter, TRequest>,
|
|
136
|
-
'
|
|
136
|
+
'onError' | 'req' | 'router'
|
|
137
137
|
>;
|
|
138
138
|
ctx: inferRouterContext<TRouter> | undefined;
|
|
139
|
-
type: '
|
|
139
|
+
type: 'mutation' | 'query';
|
|
140
140
|
input: unknown;
|
|
141
141
|
path: string;
|
|
142
142
|
}): Promise<TRPCResponse<unknown, inferRouterError<TRouter>>> {
|
|
@@ -180,7 +180,7 @@ function caughtErrorToData<
|
|
|
180
180
|
errorOpts: {
|
|
181
181
|
opts: Pick<
|
|
182
182
|
ResolveHTTPRequestOptions<TRouter, TRequest>,
|
|
183
|
-
'
|
|
183
|
+
'onError' | 'req' | 'router'
|
|
184
184
|
>;
|
|
185
185
|
ctx: inferRouterContext<TRouter> | undefined;
|
|
186
186
|
type: ProcedureType | 'unknown';
|
|
@@ -237,7 +237,7 @@ export async function resolveHTTPResponse<
|
|
|
237
237
|
>(
|
|
238
238
|
opts: Omit<
|
|
239
239
|
ResolveHTTPRequestOptions<TRouter, TRequest>,
|
|
240
|
-
'
|
|
240
|
+
'unstable_onChunk' | 'unstable_onHead'
|
|
241
241
|
>,
|
|
242
242
|
): Promise<HTTPResponse>;
|
|
243
243
|
/**
|
|
@@ -257,7 +257,7 @@ export async function resolveHTTPResponse<
|
|
|
257
257
|
>(
|
|
258
258
|
opts: PartialBy<
|
|
259
259
|
ResolveHTTPRequestOptions<TRouter, TRequest>,
|
|
260
|
-
'
|
|
260
|
+
'unstable_onChunk' | 'unstable_onHead'
|
|
261
261
|
>,
|
|
262
262
|
): Promise<HTTPResponse | void> {
|
|
263
263
|
const { router, req, unstable_onHead, unstable_onChunk } = opts;
|
|
@@ -379,7 +379,7 @@ export async function resolveHTTPResponse<
|
|
|
379
379
|
promise.then((r) => [index, r] as const),
|
|
380
380
|
]),
|
|
381
381
|
);
|
|
382
|
-
for (
|
|
382
|
+
for (const _ of paths) {
|
|
383
383
|
const [index, untransformedJSON] = await Promise.race(
|
|
384
384
|
indexedPromises.values(),
|
|
385
385
|
);
|
package/src/internals/types.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { identity } from './identity';
|
|
|
3
3
|
|
|
4
4
|
/** @internal */
|
|
5
5
|
export function pipeFromArray<TSource, TReturn>(
|
|
6
|
-
fns:
|
|
6
|
+
fns: UnaryFunction<TSource, TReturn>[],
|
|
7
7
|
): UnaryFunction<TSource, TReturn> {
|
|
8
8
|
if (fns.length === 0) {
|
|
9
9
|
return identity as UnaryFunction<any, any>;
|
package/src/rpc/envelopes.ts
CHANGED
|
@@ -76,13 +76,13 @@ export interface TRPCErrorResponse<
|
|
|
76
76
|
export type TRPCResponse<
|
|
77
77
|
TData = unknown,
|
|
78
78
|
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
79
|
-
> =
|
|
79
|
+
> = TRPCErrorResponse<TError> | TRPCSuccessResponse<TData>;
|
|
80
80
|
|
|
81
81
|
/////////////////////////// WebSocket envelopes ///////////////////////
|
|
82
82
|
|
|
83
|
-
export type TRPCRequestMessage = {
|
|
83
|
+
export type TRPCRequestMessage = TRPCRequest & {
|
|
84
84
|
id: JSONRPC2.RequestId;
|
|
85
|
-
}
|
|
85
|
+
};
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* The client asked the server to unsubscribe
|
|
@@ -102,21 +102,21 @@ export type TRPCClientOutgoingRequest = TRPCSubscriptionStopNotification;
|
|
|
102
102
|
*/
|
|
103
103
|
export type TRPCClientOutgoingMessage =
|
|
104
104
|
| TRPCRequestMessage
|
|
105
|
-
| ({ id: JSONRPC2.RequestId }
|
|
105
|
+
| (JSONRPC2.BaseRequest<'subscription.stop'> & { id: JSONRPC2.RequestId });
|
|
106
106
|
|
|
107
107
|
export interface TRPCResultMessage<TData>
|
|
108
108
|
extends JSONRPC2.ResultResponse<
|
|
109
|
-
| (TRPCResult<TData> & { type: 'data' })
|
|
110
109
|
| { type: 'started' }
|
|
111
110
|
| { type: 'stopped' }
|
|
111
|
+
| (TRPCResult<TData> & { type: 'data' })
|
|
112
112
|
> {}
|
|
113
113
|
|
|
114
114
|
export type TRPCResponseMessage<
|
|
115
115
|
TData = unknown,
|
|
116
116
|
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
117
117
|
> = { id: JSONRPC2.RequestId } & (
|
|
118
|
-
| TRPCResultMessage<TData>
|
|
119
118
|
| TRPCErrorResponse<TError>
|
|
119
|
+
| TRPCResultMessage<TData>
|
|
120
120
|
);
|
|
121
121
|
|
|
122
122
|
/**
|
|
@@ -138,4 +138,4 @@ export type TRPCClientIncomingRequest = TRPCReconnectNotification;
|
|
|
138
138
|
export type TRPCClientIncomingMessage<
|
|
139
139
|
TResult = unknown,
|
|
140
140
|
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
141
|
-
> = TRPCResponseMessage<TResult, TError
|
|
141
|
+
> = TRPCClientIncomingRequest | TRPCResponseMessage<TResult, TError>;
|
|
@@ -44,7 +44,7 @@ export const createRecursiveProxy = (callback: ProxyCallback) =>
|
|
|
44
44
|
* @internal
|
|
45
45
|
*/
|
|
46
46
|
export const createFlatProxy = <TFaux>(
|
|
47
|
-
callback: (path: keyof TFaux
|
|
47
|
+
callback: (path: string & keyof TFaux) => any,
|
|
48
48
|
): TFaux => {
|
|
49
49
|
return new Proxy(noop, {
|
|
50
50
|
get(_obj, name) {
|
|
@@ -13,7 +13,7 @@ export function getErrorShape<TConfig extends AnyRootConfig>(opts: {
|
|
|
13
13
|
type: ProcedureType | 'unknown';
|
|
14
14
|
path: string | undefined;
|
|
15
15
|
input: unknown;
|
|
16
|
-
ctx:
|
|
16
|
+
ctx: TConfig['$types']['ctx'] | undefined;
|
|
17
17
|
}): TConfig['$types']['errorShape'] {
|
|
18
18
|
const { path, error, config } = opts;
|
|
19
19
|
const { code } = opts.error;
|
|
@@ -4,24 +4,14 @@ import { FilterKeys, Simplify } from '../../types';
|
|
|
4
4
|
/**
|
|
5
5
|
* @link https://github.com/remix-run/remix/blob/2248669ed59fd716e267ea41df5d665d4781f4a9/packages/remix-server-runtime/serialize.ts
|
|
6
6
|
*/
|
|
7
|
-
type JsonPrimitive =
|
|
8
|
-
| string
|
|
9
|
-
| number
|
|
10
|
-
| boolean
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
12
|
-
| String
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
14
|
-
| Number
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
16
|
-
| Boolean
|
|
17
|
-
| null;
|
|
7
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
18
8
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
19
|
-
type NonJsonPrimitive =
|
|
9
|
+
type NonJsonPrimitive = Function | symbol | undefined;
|
|
20
10
|
/*
|
|
21
11
|
* `any` is the only type that can let you equate `0` with `1`
|
|
22
12
|
* See https://stackoverflow.com/a/49928360/1490091
|
|
23
13
|
*/
|
|
24
|
-
type IsAny<T> = 0 extends
|
|
14
|
+
type IsAny<T> = 0 extends T & 1 ? true : false;
|
|
25
15
|
|
|
26
16
|
// `undefined` is a weird one that's technically not valid JSON,
|
|
27
17
|
// but the return value of `JSON.parse` can be `undefined` so we
|
|
@@ -37,7 +27,7 @@ export type Serialize<T> =
|
|
|
37
27
|
T extends { toJSON(): infer U } ? U :
|
|
38
28
|
T extends [] ? [] :
|
|
39
29
|
T extends [unknown, ...unknown[]] ? SerializeTuple<T> :
|
|
40
|
-
T extends
|
|
30
|
+
T extends readonly (infer U)[] ? (U extends NonJsonPrimitive ? null : Serialize<U>)[] :
|
|
41
31
|
T extends object ? Simplify<SerializeObject<UndefinedToOptional<T>>> :
|
|
42
32
|
never;
|
|
43
33
|
|
package/src/subscription.ts
CHANGED
|
@@ -10,7 +10,7 @@ export function subscriptionPullFactory<TOutput>(opts: {
|
|
|
10
10
|
* The interval of how often the function should run
|
|
11
11
|
*/
|
|
12
12
|
intervalMs: number;
|
|
13
|
-
pull(emit: Observer<TOutput, unknown>): void |
|
|
13
|
+
pull(emit: Observer<TOutput, unknown>): Promise<void> | void;
|
|
14
14
|
}): Observable<TOutput, unknown> {
|
|
15
15
|
let timer: any;
|
|
16
16
|
let stopped = false;
|
|
@@ -32,7 +32,9 @@ export function subscriptionPullFactory<TOutput>(opts: {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
return observable<TOutput>((emit) => {
|
|
35
|
-
_pull(emit).catch((err) =>
|
|
35
|
+
_pull(emit).catch((err) => {
|
|
36
|
+
emit.error(getTRPCErrorFromUnknown(err));
|
|
37
|
+
});
|
|
36
38
|
return () => {
|
|
37
39
|
clearTimeout(timer);
|
|
38
40
|
stopped = true;
|
package/src/transformer.ts
CHANGED
|
@@ -53,7 +53,7 @@ export type CombinedDataTransformerClient = {
|
|
|
53
53
|
/**
|
|
54
54
|
* @public
|
|
55
55
|
*/
|
|
56
|
-
export type DataTransformerOptions =
|
|
56
|
+
export type DataTransformerOptions = CombinedDataTransformer | DataTransformer;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @public
|
|
@@ -62,8 +62,8 @@ export type DataTransformerOptions = DataTransformer | CombinedDataTransformer;
|
|
|
62
62
|
* - https://github.com/trpc/trpc/issues/4130
|
|
63
63
|
*/
|
|
64
64
|
export type ClientDataTransformerOptions =
|
|
65
|
-
|
|
|
66
|
-
|
|
|
65
|
+
| CombinedDataTransformerClient
|
|
66
|
+
| DataTransformer;
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* @internal
|
package/src/types.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export type identity<TType> = TType;
|
|
5
5
|
|
|
6
|
-
export type InferOptional<TType, TKeys extends keyof TType> =
|
|
7
|
-
|
|
6
|
+
export type InferOptional<TType, TKeys extends keyof TType> = Omit<
|
|
7
|
+
TType,
|
|
8
|
+
TKeys
|
|
8
9
|
> &
|
|
9
|
-
|
|
10
|
+
Partial<Pick<TType, TKeys>>;
|
|
10
11
|
|
|
11
12
|
export type UndefinedKeys<TType> = {
|
|
12
13
|
[K in keyof TType]: undefined extends TType[K] ? K : never;
|
|
@@ -17,7 +18,7 @@ export type UndefinedKeys<TType> = {
|
|
|
17
18
|
*/
|
|
18
19
|
export type FlatOverwrite<TType, TWith> = InferOptional<
|
|
19
20
|
{
|
|
20
|
-
[TKey in keyof
|
|
21
|
+
[TKey in keyof TType | keyof TWith]: TKey extends keyof TWith
|
|
21
22
|
? TWith[TKey]
|
|
22
23
|
: TKey extends keyof TType
|
|
23
24
|
? TType[TKey]
|
|
@@ -38,12 +39,12 @@ export type IntersectionError<TKey extends string> =
|
|
|
38
39
|
export type ProtectedIntersection<TType, TWith> = keyof TType &
|
|
39
40
|
keyof TWith extends never
|
|
40
41
|
? TType & TWith
|
|
41
|
-
: IntersectionError<keyof TType & keyof TWith
|
|
42
|
+
: IntersectionError<string & keyof TType & keyof TWith>;
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* @public
|
|
45
46
|
*/
|
|
46
|
-
export type Maybe<TType> = TType |
|
|
47
|
+
export type Maybe<TType> = TType | null | undefined;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* @internal
|
|
@@ -67,7 +68,7 @@ export type Dict<TType> = Record<string, TType | undefined>;
|
|
|
67
68
|
/**
|
|
68
69
|
* @public
|
|
69
70
|
*/
|
|
70
|
-
export type MaybePromise<TType> = TType |
|
|
71
|
+
export type MaybePromise<TType> = Promise<TType> | TType;
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
74
|
* @internal
|