@trpc/server 11.0.0-alpha-tmp-app-router-example.388 → 11.0.0-alpha-tmp-issues-5851-take-two.448
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/index.d.ts +1 -1
- package/dist/@trpc/server/index.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/aws-lambda/getPlanner.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.js +19 -2
- package/dist/adapters/aws-lambda/getPlanner.mjs +19 -2
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -1
- package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +0 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +3 -1
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +3 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +30 -7
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +30 -7
- package/dist/adapters/node-http/types.d.ts +0 -1
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +0 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/ws.d.ts +3 -4
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +172 -114
- package/dist/adapters/ws.mjs +172 -114
- package/dist/bundle-analysis.json +236 -155
- package/dist/http.js +3 -0
- package/dist/http.mjs +1 -0
- package/dist/index.js +7 -5
- package/dist/index.mjs +3 -2
- package/dist/observable/observable.d.ts +1 -0
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/observable/observable.js +55 -0
- package/dist/observable/observable.mjs +55 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts +3 -3
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/createProxy.js +15 -6
- package/dist/unstable-core-do-not-import/createProxy.mjs +15 -6
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +7 -4
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +60 -17
- package/dist/unstable-core-do-not-import/http/contentType.mjs +61 -18
- package/dist/unstable-core-do-not-import/http/formDataToObject.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/formDataToObject.js +40 -0
- package/dist/unstable-core-do-not-import/http/formDataToObject.mjs +38 -0
- 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/resolveResponse.js +302 -149
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +301 -148
- package/dist/unstable-core-do-not-import/http/types.d.ts +26 -2
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +12 -12
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts +3 -3
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +3 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +12 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +2 -2
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +7 -2
- package/dist/unstable-core-do-not-import/router.mjs +7 -2
- 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/stream/{stream.d.ts → jsonl.d.ts} +5 -5
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/{stream.js → jsonl.js} +148 -111
- package/dist/unstable-core-do-not-import/stream/{stream.mjs → jsonl.mjs} +147 -110
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +86 -0
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/sse.js +178 -0
- package/dist/unstable-core-do-not-import/stream/sse.mjs +172 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts +18 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.js +46 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +43 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +10 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +31 -0
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +29 -0
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts +7 -0
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +5 -5
- package/dist/unstable-core-do-not-import/utils.d.ts +4 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +4 -0
- package/dist/unstable-core-do-not-import/utils.mjs +4 -1
- package/dist/unstable-core-do-not-import.d.ts +5 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +19 -7
- package/dist/unstable-core-do-not-import.mjs +6 -3
- package/package.json +6 -6
- package/src/@trpc/server/http.ts +7 -2
- package/src/@trpc/server/index.ts +1 -0
- package/src/@trpc/server/rpc.ts +1 -0
- package/src/adapters/aws-lambda/getPlanner.ts +21 -2
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +3 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +32 -7
- package/src/adapters/ws.ts +193 -107
- package/src/observable/observable.ts +63 -0
- package/src/unstable-core-do-not-import/createProxy.ts +23 -8
- package/src/unstable-core-do-not-import/http/contentType.ts +83 -21
- package/src/{adapters/next-app-dir → unstable-core-do-not-import/http}/formDataToObject.ts +18 -10
- 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 +333 -164
- package/src/unstable-core-do-not-import/http/types.ts +31 -2
- package/src/unstable-core-do-not-import/procedureBuilder.ts +8 -1
- package/src/unstable-core-do-not-import/rootConfig.ts +12 -0
- package/src/unstable-core-do-not-import/router.ts +47 -35
- 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/stream/{stream.ts → jsonl.ts} +163 -110
- package/src/unstable-core-do-not-import/stream/sse.ts +288 -0
- package/src/unstable-core-do-not-import/stream/utils/createDeferred.ts +48 -0
- package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +31 -0
- package/src/unstable-core-do-not-import/stream/utils/createServer.ts +44 -0
- package/src/unstable-core-do-not-import/utils.ts +5 -0
- package/src/unstable-core-do-not-import.ts +5 -2
- package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +0 -1
- package/dist/adapters/next-app-dir/formDataToObject.js +0 -34
- package/dist/adapters/next-app-dir/formDataToObject.mjs +0 -32
- package/dist/unstable-core-do-not-import/stream/stream.d.ts.map +0 -1
- /package/dist/{adapters/next-app-dir → unstable-core-do-not-import/http}/formDataToObject.d.ts +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { TRPCError } from '../error/TRPCError';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AnyProcedure,
|
|
4
|
+
ErrorHandlerOptions,
|
|
5
|
+
ProcedureType,
|
|
6
|
+
} from '../procedure';
|
|
3
7
|
import type {
|
|
4
8
|
AnyRouter,
|
|
5
9
|
inferRouterContext,
|
|
@@ -28,7 +32,7 @@ export type ResponseMetaFn<TRouter extends AnyRouter> = (opts: {
|
|
|
28
32
|
* The different tRPC paths requested
|
|
29
33
|
* @deprecated use `info` instead, this will be removed in v12
|
|
30
34
|
**/
|
|
31
|
-
paths: string[] | undefined;
|
|
35
|
+
paths: readonly string[] | undefined;
|
|
32
36
|
info: TRPCRequestInfo | undefined;
|
|
33
37
|
type: ProcedureType | 'unknown';
|
|
34
38
|
errors: TRPCError[];
|
|
@@ -51,6 +55,8 @@ export interface HTTPBaseHandlerOptions<TRouter extends AnyRouter, TRequest>
|
|
|
51
55
|
responseMeta?: ResponseMetaFn<TRouter>;
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
export type TRPCAcceptHeader = 'application/jsonl';
|
|
59
|
+
|
|
54
60
|
interface TRPCRequestInfoProcedureCall {
|
|
55
61
|
path: string;
|
|
56
62
|
/**
|
|
@@ -61,6 +67,11 @@ interface TRPCRequestInfoProcedureCall {
|
|
|
61
67
|
* Get already parsed inputs - won't trigger reading the body or parsing the inputs
|
|
62
68
|
*/
|
|
63
69
|
result: () => unknown;
|
|
70
|
+
/**
|
|
71
|
+
* The procedure being called, `null` if not found
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
procedure: AnyProcedure | null;
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
/**
|
|
@@ -68,8 +79,26 @@ interface TRPCRequestInfoProcedureCall {
|
|
|
68
79
|
* @public
|
|
69
80
|
*/
|
|
70
81
|
export interface TRPCRequestInfo {
|
|
82
|
+
/**
|
|
83
|
+
* The `trpc-accept` header
|
|
84
|
+
*/
|
|
85
|
+
accept: TRPCAcceptHeader | null;
|
|
86
|
+
/**
|
|
87
|
+
* The type of the request
|
|
88
|
+
*/
|
|
89
|
+
type: ProcedureType | 'unknown';
|
|
90
|
+
/**
|
|
91
|
+
* If the content type handler has detected that this is a batch call
|
|
92
|
+
*/
|
|
71
93
|
isBatchCall: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The calls being made
|
|
96
|
+
*/
|
|
72
97
|
calls: TRPCRequestInfoProcedureCall[];
|
|
98
|
+
/**
|
|
99
|
+
* Connection params when using `httpSubscriptionLink` or `createWSClient`
|
|
100
|
+
*/
|
|
101
|
+
connectionParams: Dict<string> | null;
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
/**
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
QueryProcedure,
|
|
24
24
|
SubscriptionProcedure,
|
|
25
25
|
} from './procedure';
|
|
26
|
+
import type { inferSSEOutput } from './stream/sse';
|
|
26
27
|
import type {
|
|
27
28
|
GetRawInputFn,
|
|
28
29
|
MaybePromise,
|
|
@@ -43,6 +44,12 @@ type DefaultValue<TValue, TFallback> = TValue extends UnsetMarker
|
|
|
43
44
|
? TFallback
|
|
44
45
|
: TValue;
|
|
45
46
|
|
|
47
|
+
type inferSubscriptionOutput<TOutput> = TOutput extends AsyncIterable<
|
|
48
|
+
infer $Output
|
|
49
|
+
>
|
|
50
|
+
? inferSSEOutput<$Output>
|
|
51
|
+
: inferObservableValue<TOutput>;
|
|
52
|
+
|
|
46
53
|
export type CallerOverride<TContext> = (opts: {
|
|
47
54
|
args: unknown[];
|
|
48
55
|
invoke: (opts: ProcedureCallOptions<TContext>) => Promise<unknown>;
|
|
@@ -347,7 +354,7 @@ export interface ProcedureBuilder<
|
|
|
347
354
|
? TypeError<'Not implemented'>
|
|
348
355
|
: SubscriptionProcedure<{
|
|
349
356
|
input: DefaultValue<TInputIn, void>;
|
|
350
|
-
output: DefaultValue<TOutputOut,
|
|
357
|
+
output: DefaultValue<TOutputOut, inferSubscriptionOutput<$Output>>;
|
|
351
358
|
}>;
|
|
352
359
|
|
|
353
360
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CombinedDataTransformer } from '../unstable-core-do-not-import';
|
|
2
2
|
import type { DefaultErrorShape, ErrorFormatter } from './error/formatter';
|
|
3
|
+
import type { SSEStreamProducerOptions } from './stream/sse';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The initial generics that are used in the init function
|
|
@@ -67,8 +68,19 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
67
68
|
experimental?: {
|
|
68
69
|
/**
|
|
69
70
|
* Enable support for returning async iterables and returning deferred promises when using `httpBatchStreamLink`
|
|
71
|
+
* @default true
|
|
70
72
|
*/
|
|
71
73
|
iterablesAndDeferreds?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Enable support for server-sent events (SSE) subscriptions
|
|
76
|
+
*/
|
|
77
|
+
sseSubscriptions?: {
|
|
78
|
+
/**
|
|
79
|
+
* Enable server-sent events (SSE) subscriptions
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
} & Omit<SSEStreamProducerOptions, 'maxDepth' | 'data' | 'serialize'>;
|
|
72
84
|
};
|
|
73
85
|
}
|
|
74
86
|
|
|
@@ -174,7 +174,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
174
174
|
|
|
175
175
|
const procedures: Record<string, AnyProcedure> = omitPrototype({});
|
|
176
176
|
|
|
177
|
-
function step(from: CreateRouterOptions, path: string[] = []) {
|
|
177
|
+
function step(from: CreateRouterOptions, path: readonly string[] = []) {
|
|
178
178
|
const aggregate: RouterRecord = omitPrototype({});
|
|
179
179
|
for (const [key, item] of Object.entries(from ?? {})) {
|
|
180
180
|
if (isRouter(item)) {
|
|
@@ -248,6 +248,18 @@ export function callProcedure(
|
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
/* istanbul ignore if -- @preserve */
|
|
252
|
+
if (
|
|
253
|
+
proc._def.type !== type &&
|
|
254
|
+
opts.allowMethodOverride &&
|
|
255
|
+
proc._def.type === 'subscription'
|
|
256
|
+
) {
|
|
257
|
+
throw new TRPCError({
|
|
258
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
259
|
+
message: `Method override is not supported for subscriptions`,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
251
263
|
return proc(opts);
|
|
252
264
|
}
|
|
253
265
|
|
|
@@ -264,40 +276,40 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
264
276
|
onError?: RouterCallerErrorHandler<Context>;
|
|
265
277
|
},
|
|
266
278
|
) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
279
|
+
return createRecursiveProxy<ReturnType<RouterCaller<any, any>>>(
|
|
280
|
+
async ({ path, args }) => {
|
|
281
|
+
const fullPath = path.join('.');
|
|
282
|
+
|
|
283
|
+
if (path.length === 1 && path[0] === '_def') {
|
|
284
|
+
return _def;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const procedure = _def.procedures[fullPath] as AnyProcedure;
|
|
288
|
+
|
|
289
|
+
let ctx: Context | undefined = undefined;
|
|
290
|
+
try {
|
|
291
|
+
ctx = isFunction(ctxOrCallback)
|
|
292
|
+
? await Promise.resolve(ctxOrCallback())
|
|
293
|
+
: ctxOrCallback;
|
|
294
|
+
|
|
295
|
+
return await procedure({
|
|
296
|
+
path: fullPath,
|
|
297
|
+
getRawInput: async () => args[0],
|
|
298
|
+
ctx,
|
|
299
|
+
type: procedure._def.type,
|
|
300
|
+
});
|
|
301
|
+
} catch (cause) {
|
|
302
|
+
options?.onError?.({
|
|
303
|
+
ctx,
|
|
304
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
305
|
+
input: args[0],
|
|
306
|
+
path: fullPath,
|
|
307
|
+
type: procedure._def.type,
|
|
308
|
+
});
|
|
309
|
+
throw cause;
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
);
|
|
301
313
|
};
|
|
302
314
|
};
|
|
303
315
|
}
|
|
@@ -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
|
+
}
|