@trpc/server 11.0.0-rc.433 → 11.0.0-rc.436
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/@trpc/server/http.d.ts +1 -2
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/rpc.d.ts +1 -1
- package/dist/@trpc/server/rpc.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/ws.d.ts +2 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +76 -35
- package/dist/adapters/ws.mjs +77 -36
- package/dist/bundle-analysis.json +84 -63
- package/dist/http.js +3 -0
- package/dist/http.mjs +1 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +8 -3
- package/dist/unstable-core-do-not-import/http/contentType.mjs +8 -3
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +4 -4
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +4 -4
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.d.ts +4 -0
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.js +42 -0
- package/dist/unstable-core-do-not-import/http/parseConnectionParams.mjs +39 -0
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/types.d.ts +9 -14
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +7 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +1 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.d.ts +4 -3
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +16 -13
- package/dist/unstable-core-do-not-import.mjs +4 -3
- package/package.json +2 -2
- package/src/@trpc/server/http.ts +7 -2
- package/src/@trpc/server/rpc.ts +1 -0
- package/src/adapters/ws.ts +95 -35
- package/src/unstable-core-do-not-import/http/contentType.ts +12 -7
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +4 -7
- package/src/unstable-core-do-not-import/http/parseConnectionParams.ts +49 -0
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +8 -6
- package/src/unstable-core-do-not-import/http/types.ts +9 -17
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +9 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +1 -0
- package/src/unstable-core-do-not-import.ts +4 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TRPCError } from '../error/TRPCError';
|
|
2
|
+
import { isObject } from '../utils';
|
|
3
|
+
import type { TRPCRequestInfo } from './types';
|
|
4
|
+
|
|
5
|
+
export function parseConnectionParamsFromUnknown(
|
|
6
|
+
parsed: unknown,
|
|
7
|
+
): TRPCRequestInfo['connectionParams'] {
|
|
8
|
+
try {
|
|
9
|
+
if (parsed === null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (!isObject(parsed)) {
|
|
13
|
+
throw new Error('Expected object');
|
|
14
|
+
}
|
|
15
|
+
const nonStringValues = Object.entries(parsed).filter(
|
|
16
|
+
([_key, value]) => typeof value !== 'string',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (nonStringValues.length > 0) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Expected connectionParams to be string values. Got ${nonStringValues
|
|
22
|
+
.map(([key, value]) => `${key}: ${typeof value}`)
|
|
23
|
+
.join(', ')}`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return parsed as Record<string, string>;
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
throw new TRPCError({
|
|
29
|
+
code: 'PARSE_ERROR',
|
|
30
|
+
message: 'Invalid connection params shape',
|
|
31
|
+
cause,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function parseConnectionParamsFromString(
|
|
36
|
+
str: string,
|
|
37
|
+
): TRPCRequestInfo['connectionParams'] {
|
|
38
|
+
let parsed: unknown;
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(str);
|
|
41
|
+
} catch (cause) {
|
|
42
|
+
throw new TRPCError({
|
|
43
|
+
code: 'PARSE_ERROR',
|
|
44
|
+
message: 'Not JSON-parsable query params',
|
|
45
|
+
cause,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return parseConnectionParamsFromUnknown(parsed);
|
|
49
|
+
}
|
|
@@ -335,8 +335,8 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
335
335
|
config,
|
|
336
336
|
ctx,
|
|
337
337
|
error,
|
|
338
|
-
input: call
|
|
339
|
-
path: call
|
|
338
|
+
input: call!.result(),
|
|
339
|
+
path: call!.path,
|
|
340
340
|
type: info.type,
|
|
341
341
|
}),
|
|
342
342
|
}
|
|
@@ -370,7 +370,9 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
370
370
|
|
|
371
371
|
if (!isObservable(data) && !isAsyncIterable(data)) {
|
|
372
372
|
throw new TRPCError({
|
|
373
|
-
message: `Subscription ${
|
|
373
|
+
message: `Subscription ${
|
|
374
|
+
call!.path
|
|
375
|
+
} did not return an observable or a AsyncGenerator`,
|
|
374
376
|
code: 'INTERNAL_SERVER_ERROR',
|
|
375
377
|
});
|
|
376
378
|
}
|
|
@@ -440,9 +442,9 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
440
442
|
config,
|
|
441
443
|
ctx,
|
|
442
444
|
error,
|
|
443
|
-
input: call
|
|
444
|
-
path: call
|
|
445
|
-
type: call
|
|
445
|
+
input: call!.result(),
|
|
446
|
+
path: call!.path,
|
|
447
|
+
type: call!.procedure?._def.type ?? 'unknown',
|
|
446
448
|
}),
|
|
447
449
|
};
|
|
448
450
|
}
|
|
@@ -74,7 +74,11 @@ interface TRPCRequestInfoProcedureCall {
|
|
|
74
74
|
procedure: AnyProcedure | null;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Information about the incoming request
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export interface TRPCRequestInfo {
|
|
78
82
|
/**
|
|
79
83
|
* The `trpc-accept` header
|
|
80
84
|
*/
|
|
@@ -91,23 +95,11 @@ export interface TRPCRequestInfoBase {
|
|
|
91
95
|
* The calls being made
|
|
92
96
|
*/
|
|
93
97
|
calls: TRPCRequestInfoProcedureCall[];
|
|
98
|
+
/**
|
|
99
|
+
* Connection params when using `httpSubscriptionLink` or `createWSClient`
|
|
100
|
+
*/
|
|
101
|
+
connectionParams: Dict<string> | null;
|
|
94
102
|
}
|
|
95
|
-
interface TRPCRequestInfoBatchCall extends TRPCRequestInfoBase {
|
|
96
|
-
isBatchCall: true;
|
|
97
|
-
calls: TRPCRequestInfoProcedureCall[];
|
|
98
|
-
}
|
|
99
|
-
interface TRPCRequestInfoSingleCall extends TRPCRequestInfoBase {
|
|
100
|
-
isBatchCall: false;
|
|
101
|
-
calls: [TRPCRequestInfoProcedureCall];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Information about the incoming request
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
export type TRPCRequestInfo =
|
|
109
|
-
| TRPCRequestInfoBatchCall
|
|
110
|
-
| TRPCRequestInfoSingleCall;
|
|
111
103
|
|
|
112
104
|
/**
|
|
113
105
|
* Inner createContext function for `resolveResponse` used to forward `TRPCRequestInfo` to `createContext`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import type { TRPCRequestInfo } from '../http/types';
|
|
2
3
|
import type { ProcedureType } from '../procedure';
|
|
3
4
|
import type { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
4
5
|
|
|
@@ -131,3 +132,11 @@ export type TRPCClientIncomingMessage<
|
|
|
131
132
|
TResult = unknown,
|
|
132
133
|
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
133
134
|
> = TRPCClientIncomingRequest | TRPCResponseMessage<TResult, TError>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The client sends connection params - always sent as the first message
|
|
138
|
+
*/
|
|
139
|
+
export interface TRPCConnectionParamsMessage
|
|
140
|
+
extends JSONRPC2.BaseRequest<'connectionParams'> {
|
|
141
|
+
data: TRPCRequestInfo['connectionParams'];
|
|
142
|
+
}
|
|
@@ -12,10 +12,11 @@ export * from './unstable-core-do-not-import/clientish/inference';
|
|
|
12
12
|
export * from './unstable-core-do-not-import/clientish/inferrable';
|
|
13
13
|
export * from './unstable-core-do-not-import/clientish/serialize';
|
|
14
14
|
export * from './unstable-core-do-not-import/createProxy';
|
|
15
|
-
export * from './unstable-core-do-not-import/error/TRPCError';
|
|
16
15
|
export * from './unstable-core-do-not-import/error/formatter';
|
|
17
16
|
export * from './unstable-core-do-not-import/error/getErrorShape';
|
|
17
|
+
export * from './unstable-core-do-not-import/error/TRPCError';
|
|
18
18
|
export * from './unstable-core-do-not-import/http/batchStreamFormatter';
|
|
19
|
+
export * from './unstable-core-do-not-import/http/parseConnectionParams';
|
|
19
20
|
export * from './unstable-core-do-not-import/http/contentType';
|
|
20
21
|
export * from './unstable-core-do-not-import/http/contentTypeParsers';
|
|
21
22
|
export * from './unstable-core-do-not-import/http/getHTTPStatusCode';
|
|
@@ -30,8 +31,8 @@ export * from './unstable-core-do-not-import/procedureBuilder';
|
|
|
30
31
|
export * from './unstable-core-do-not-import/rootConfig';
|
|
31
32
|
export * from './unstable-core-do-not-import/router';
|
|
32
33
|
export * from './unstable-core-do-not-import/rpc';
|
|
34
|
+
export * from './unstable-core-do-not-import/stream/jsonl';
|
|
35
|
+
export * from './unstable-core-do-not-import/stream/sse';
|
|
33
36
|
export * from './unstable-core-do-not-import/transformer';
|
|
34
37
|
export * from './unstable-core-do-not-import/types';
|
|
35
38
|
export * from './unstable-core-do-not-import/utils';
|
|
36
|
-
export * from './unstable-core-do-not-import/stream/jsonl';
|
|
37
|
-
export * from './unstable-core-do-not-import/stream/sse';
|