@trpc/server 11.0.0-rc.750 → 11.0.0-rc.753
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/index.d.ts +1 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +20 -20
- package/dist/index.js +0 -1
- package/dist/index.mjs +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +3 -3
- package/dist/unstable-core-do-not-import/http/contentType.mjs +3 -3
- package/dist/unstable-core-do-not-import/router.d.ts +6 -4
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +33 -26
- package/dist/unstable-core-do-not-import/router.mjs +34 -27
- package/package.json +3 -3
- package/src/@trpc/server/index.ts +0 -1
- package/src/adapters/ws.ts +1 -1
- package/src/unstable-core-do-not-import/http/contentType.ts +3 -3
- package/src/unstable-core-do-not-import/router.ts +40 -32
|
@@ -2,7 +2,7 @@ export { TRPCError,
|
|
|
2
2
|
/**
|
|
3
3
|
* @deprecated use `experimental_trpcMiddleware` instead
|
|
4
4
|
*/
|
|
5
|
-
experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC,
|
|
5
|
+
experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type CreateContextCallback, type MutationProcedure as TRPCMutationProcedure, type QueryProcedure as TRPCQueryProcedure, type SubscriptionProcedure as TRPCSubscriptionProcedure, type TRPCBuilder, StandardSchemaV1Error,
|
|
6
6
|
/**
|
|
7
7
|
* @deprecated use `tracked(id, data)` instead
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,IAAI,mBAAmB,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oCAAoC,EACzC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,IAAI,oBAAoB,EAC7C,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACvC,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,SAAS,IAAI,aAAa,EAC/B,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,oBAAoB,IAAI,wBAAwB,EACrD,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,wBAAwB,IAAI,4BAA4B,EAC7D,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,WAAW,EAChB,qBAAqB;AACrB;;GAEG;AACH,GAAG,EACH,OAAO,EACP,KAAK,eAAe,EACpB,iBAAiB,EACjB,IAAI,IAAI,iBAAiB,GAC1B,MAAM,mCAAmC,CAAC;AAE3C,YAAY;AACV;;GAEG;AACH,YAAY;AACZ;;GAEG;AACH,SAAS;AACT;;GAEG;AACH,qBAAqB;AACrB;;GAEG;AACH,uBAAuB;AAEvB;;GAEG;AACH,IAAI;AAEJ;;GAEG;AACH,WAAW;AACX;;GAEG;AACH,aAAa;AACb;;GAEG;AACH,oBAAoB;AAEpB;;GAEG;AACH,iBAAiB;AACjB;;GAEG;AACH,wBAAwB,GACzB,MAAM,mCAAmC,CAAC;AAE3C,OAAO;AACL;;GAEG;AACH,aAAa;AAEb;;GAEG;AACH,aAAa,GACd,MAAM,mCAAmC,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACxE,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
package/dist/adapters/ws.js
CHANGED
|
@@ -180,7 +180,7 @@ function getWSConnectionHandler(opts) {
|
|
|
180
180
|
await ctxPromise; // asserts context has been set
|
|
181
181
|
const abortController = new AbortController();
|
|
182
182
|
const result = await router.callProcedure({
|
|
183
|
-
|
|
183
|
+
router: router$1,
|
|
184
184
|
path,
|
|
185
185
|
getRawInput: async ()=>input,
|
|
186
186
|
ctx,
|
package/dist/adapters/ws.mjs
CHANGED
|
@@ -178,7 +178,7 @@ function getWSConnectionHandler(opts) {
|
|
|
178
178
|
await ctxPromise; // asserts context has been set
|
|
179
179
|
const abortController = new AbortController();
|
|
180
180
|
const result = await callProcedure({
|
|
181
|
-
|
|
181
|
+
router,
|
|
182
182
|
path,
|
|
183
183
|
getRawInput: async ()=>input,
|
|
184
184
|
ctx,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 13.
|
|
2
|
+
"bundleSize": 199016,
|
|
3
|
+
"bundleOrigSize": 230668,
|
|
4
|
+
"bundleReduction": 13.72,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"id": "/src/adapters/ws.ts",
|
|
22
|
-
"size":
|
|
23
|
-
"origSize":
|
|
22
|
+
"size": 20148,
|
|
23
|
+
"origSize": 15927,
|
|
24
24
|
"renderedExports": [
|
|
25
25
|
"getWSConnectionHandler",
|
|
26
26
|
"handleKeepAlive",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependents": [
|
|
31
31
|
"/src/adapters/fastify/fastifyTRPCPlugin.ts"
|
|
32
32
|
],
|
|
33
|
-
"percent": 10.
|
|
33
|
+
"percent": 10.12,
|
|
34
34
|
"reduction": 0
|
|
35
35
|
},
|
|
36
36
|
{
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
"id": "/src/unstable-core-do-not-import/router.ts",
|
|
85
|
-
"size":
|
|
85
|
+
"size": 10167,
|
|
86
86
|
"origSize": 14423,
|
|
87
87
|
"renderedExports": [
|
|
88
88
|
"lazy",
|
|
@@ -98,8 +98,8 @@
|
|
|
98
98
|
"/src/unstable-core-do-not-import/initTRPC.ts",
|
|
99
99
|
"/src/unstable-core-do-not-import/http/contentType.ts"
|
|
100
100
|
],
|
|
101
|
-
"percent": 5.
|
|
102
|
-
"reduction": 29.
|
|
101
|
+
"percent": 5.11,
|
|
102
|
+
"reduction": 29.51
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
"id": "/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts",
|
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
119
|
"id": "/src/unstable-core-do-not-import/http/contentType.ts",
|
|
120
|
-
"size":
|
|
121
|
-
"origSize":
|
|
120
|
+
"size": 7874,
|
|
121
|
+
"origSize": 7940,
|
|
122
122
|
"renderedExports": [
|
|
123
123
|
"getRequestInfo"
|
|
124
124
|
],
|
|
@@ -356,11 +356,11 @@
|
|
|
356
356
|
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
357
357
|
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
358
358
|
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
359
|
-
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
360
359
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
361
360
|
"/src/unstable-core-do-not-import/router.ts",
|
|
362
361
|
"/src/unstable-core-do-not-import/transformer.ts",
|
|
363
362
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
363
|
+
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
364
364
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
365
365
|
"/src/unstable-core-do-not-import/http/abortError.ts",
|
|
366
366
|
"/src/unstable-core-do-not-import/procedureBuilder.ts",
|
|
@@ -872,9 +872,9 @@
|
|
|
872
872
|
"reduction": 100
|
|
873
873
|
},
|
|
874
874
|
{
|
|
875
|
-
"id": "/src/
|
|
875
|
+
"id": "/src/index.ts",
|
|
876
876
|
"size": 0,
|
|
877
|
-
"origSize":
|
|
877
|
+
"origSize": 32,
|
|
878
878
|
"renderedExports": [],
|
|
879
879
|
"removedExports": [],
|
|
880
880
|
"dependents": [],
|
|
@@ -882,9 +882,9 @@
|
|
|
882
882
|
"reduction": 100
|
|
883
883
|
},
|
|
884
884
|
{
|
|
885
|
-
"id": "/src/
|
|
885
|
+
"id": "/src/rpc.ts",
|
|
886
886
|
"size": 0,
|
|
887
|
-
"origSize":
|
|
887
|
+
"origSize": 36,
|
|
888
888
|
"renderedExports": [],
|
|
889
889
|
"removedExports": [],
|
|
890
890
|
"dependents": [],
|
|
@@ -942,9 +942,9 @@
|
|
|
942
942
|
"reduction": 100
|
|
943
943
|
},
|
|
944
944
|
{
|
|
945
|
-
"id": "/src/adapters/
|
|
945
|
+
"id": "/src/adapters/fetch/index.ts",
|
|
946
946
|
"size": 0,
|
|
947
|
-
"origSize":
|
|
947
|
+
"origSize": 64,
|
|
948
948
|
"renderedExports": [],
|
|
949
949
|
"removedExports": [],
|
|
950
950
|
"dependents": [],
|
|
@@ -952,9 +952,9 @@
|
|
|
952
952
|
"reduction": 100
|
|
953
953
|
},
|
|
954
954
|
{
|
|
955
|
-
"id": "/src/adapters/
|
|
955
|
+
"id": "/src/adapters/fastify/index.ts",
|
|
956
956
|
"size": 0,
|
|
957
|
-
"origSize":
|
|
957
|
+
"origSize": 78,
|
|
958
958
|
"renderedExports": [],
|
|
959
959
|
"removedExports": [],
|
|
960
960
|
"dependents": [],
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,6 @@ exports.getErrorShape = getErrorShape.getErrorShape;
|
|
|
20
20
|
exports.TRPCError = TRPCError.TRPCError;
|
|
21
21
|
exports.getTRPCErrorFromUnknown = TRPCError.getTRPCErrorFromUnknown;
|
|
22
22
|
exports.callProcedure = router.callProcedure;
|
|
23
|
-
exports.callTRPCProcedure = router.callProcedure;
|
|
24
23
|
exports.experimental_lazy = router.lazy;
|
|
25
24
|
exports.isTrackedEnvelope = tracked.isTrackedEnvelope;
|
|
26
25
|
exports.sse = tracked.sse;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createFlatProxy as createTRPCFlatProxy } from './unstable-core-do-not-import/createProxy.mjs';
|
|
2
2
|
export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
|
|
3
3
|
export { TRPCError, getTRPCErrorFromUnknown } from './unstable-core-do-not-import/error/TRPCError.mjs';
|
|
4
|
-
export { callProcedure,
|
|
4
|
+
export { callProcedure, lazy as experimental_lazy } from './unstable-core-do-not-import/router.mjs';
|
|
5
5
|
import './vendor/unpromise/unpromise.mjs';
|
|
6
6
|
import './unstable-core-do-not-import/stream/utils/disposable.mjs';
|
|
7
7
|
export { isTrackedEnvelope, sse, tracked } from './unstable-core-do-not-import/stream/tracked.mjs';
|
|
@@ -86,7 +86,7 @@ const jsonContentTypeHandler = {
|
|
|
86
86
|
return acc;
|
|
87
87
|
});
|
|
88
88
|
const calls = await Promise.all(paths.map(async (path, index)=>{
|
|
89
|
-
const procedure = await router.getProcedureAtPath(opts.router
|
|
89
|
+
const procedure = await router.getProcedureAtPath(opts.router, path);
|
|
90
90
|
return {
|
|
91
91
|
path,
|
|
92
92
|
procedure,
|
|
@@ -152,7 +152,7 @@ const formDataContentTypeHandler = {
|
|
|
152
152
|
const fd = await req.formData();
|
|
153
153
|
return fd;
|
|
154
154
|
});
|
|
155
|
-
const procedure = await router.getProcedureAtPath(opts.router
|
|
155
|
+
const procedure = await router.getProcedureAtPath(opts.router, opts.path);
|
|
156
156
|
return {
|
|
157
157
|
accept: null,
|
|
158
158
|
calls: [
|
|
@@ -192,7 +192,7 @@ const octetStreamContentTypeHandler = {
|
|
|
192
192
|
path: opts.path,
|
|
193
193
|
getRawInput: getInputs.read,
|
|
194
194
|
result: getInputs.result,
|
|
195
|
-
procedure: await router.getProcedureAtPath(opts.router
|
|
195
|
+
procedure: await router.getProcedureAtPath(opts.router, opts.path)
|
|
196
196
|
}
|
|
197
197
|
],
|
|
198
198
|
isBatchCall: false,
|
|
@@ -84,7 +84,7 @@ const jsonContentTypeHandler = {
|
|
|
84
84
|
return acc;
|
|
85
85
|
});
|
|
86
86
|
const calls = await Promise.all(paths.map(async (path, index)=>{
|
|
87
|
-
const procedure = await getProcedureAtPath(opts.router
|
|
87
|
+
const procedure = await getProcedureAtPath(opts.router, path);
|
|
88
88
|
return {
|
|
89
89
|
path,
|
|
90
90
|
procedure,
|
|
@@ -150,7 +150,7 @@ const formDataContentTypeHandler = {
|
|
|
150
150
|
const fd = await req.formData();
|
|
151
151
|
return fd;
|
|
152
152
|
});
|
|
153
|
-
const procedure = await getProcedureAtPath(opts.router
|
|
153
|
+
const procedure = await getProcedureAtPath(opts.router, opts.path);
|
|
154
154
|
return {
|
|
155
155
|
accept: null,
|
|
156
156
|
calls: [
|
|
@@ -190,7 +190,7 @@ const octetStreamContentTypeHandler = {
|
|
|
190
190
|
path: opts.path,
|
|
191
191
|
getRawInput: getInputs.read,
|
|
192
192
|
result: getInputs.result,
|
|
193
|
-
procedure: await getProcedureAtPath(opts.router
|
|
193
|
+
procedure: await getProcedureAtPath(opts.router, opts.path)
|
|
194
194
|
}
|
|
195
195
|
],
|
|
196
196
|
isBatchCall: false,
|
|
@@ -43,7 +43,7 @@ type LazyLoader<TAny> = {
|
|
|
43
43
|
* Lazy load a router
|
|
44
44
|
* @see https://trpc.io/docs/server/merging-routers#lazy-load
|
|
45
45
|
*/
|
|
46
|
-
export declare function lazy<TRouter extends AnyRouter>(
|
|
46
|
+
export declare function lazy<TRouter extends AnyRouter>(importRouter: () => Promise<TRouter | {
|
|
47
47
|
[key: string]: TRouter;
|
|
48
48
|
}>): Lazy<NoInfer<TRouter>>;
|
|
49
49
|
export interface Router<TRoot extends AnyRootTypes, TRecord extends RouterRecord> {
|
|
@@ -56,7 +56,6 @@ export interface Router<TRoot extends AnyRootTypes, TRecord extends RouterRecord
|
|
|
56
56
|
lazy: Record<string, LazyLoader<AnyRouter>>;
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
59
|
-
* @deprecated use `t.createCallerFactory(router)` instead
|
|
60
59
|
* @see https://trpc.io/docs/v11/server/server-side-calls
|
|
61
60
|
*/
|
|
62
61
|
createCaller: RouterCaller<TRoot, TRecord>;
|
|
@@ -77,12 +76,15 @@ export type DecorateCreateRouterOptions<TRouterOptions extends CreateRouterOptio
|
|
|
77
76
|
* @internal
|
|
78
77
|
*/
|
|
79
78
|
export declare function createRouterFactory<TRoot extends AnyRootTypes>(config: RootConfig<TRoot>): <TInput extends CreateRouterOptions>(input: TInput) => BuiltRouter<TRoot, DecorateCreateRouterOptions<TInput>>;
|
|
80
|
-
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export declare function getProcedureAtPath(router: Pick<Router<any, any>, '_def'>, path: string): Promise<AnyProcedure | null>;
|
|
81
83
|
/**
|
|
82
84
|
* @internal
|
|
83
85
|
*/
|
|
84
86
|
export declare function callProcedure(opts: ProcedureCallOptions<unknown> & {
|
|
85
|
-
|
|
87
|
+
router: AnyRouter;
|
|
86
88
|
allowMethodOverride?: boolean;
|
|
87
89
|
}): Promise<any>;
|
|
88
90
|
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <TRecord extends RouterRecord>(router: Pick<Router<TRoot, TRecord>, "_def">) => RouterCaller<TRoot, TRecord>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAA2B,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qCAAqC,EACtC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAA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CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EACrE,OAAO,SAAS,YAAY,GAAG,EAAE,IAC/B,QAAQ,SAAS;IACnB,MAAM,IAAI,SAAS,SAAS;IAC5B,GAAG,MAAM,IAAI,SAAS,SAAS,EAAE;CAClC,GACG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,GAC3D,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAEhC,wBAAgB,YAAY,CAAC,QAAQ,SAAS,SAAS,EAAE,EACvD,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,GAC3B,YAAY,CAAC,QAAQ,CAAC,CAoDxB"}
|
|
@@ -7,30 +7,34 @@ var transformer = require('./transformer.js');
|
|
|
7
7
|
var utils = require('./utils.js');
|
|
8
8
|
|
|
9
9
|
const lazySymbol = Symbol('lazy');
|
|
10
|
+
function once(fn) {
|
|
11
|
+
const uncalled = Symbol();
|
|
12
|
+
let result = uncalled;
|
|
13
|
+
return ()=>{
|
|
14
|
+
if (result === uncalled) {
|
|
15
|
+
result = fn();
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
10
20
|
/**
|
|
11
21
|
* Lazy load a router
|
|
12
22
|
* @see https://trpc.io/docs/server/merging-routers#lazy-load
|
|
13
|
-
*/ function lazy(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// if the module is a router, return it
|
|
20
|
-
if (isRouter(mod)) {
|
|
21
|
-
return mod;
|
|
22
|
-
}
|
|
23
|
-
const routers = Object.values(mod);
|
|
24
|
-
if (routers.length !== 1 || !isRouter(routers[0])) {
|
|
25
|
-
throw new Error("Invalid router module - either define exactly 1 export or return the router directly.\nExample: `experimental_lazy(() => import('./slow.js').then((m) => m.slowRouter))`");
|
|
26
|
-
}
|
|
27
|
-
return routers[0];
|
|
28
|
-
});
|
|
23
|
+
*/ function lazy(importRouter) {
|
|
24
|
+
async function resolve() {
|
|
25
|
+
const mod = await importRouter();
|
|
26
|
+
// if the module is a router, return it
|
|
27
|
+
if (isRouter(mod)) {
|
|
28
|
+
return mod;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const routers = Object.values(mod);
|
|
31
|
+
if (routers.length !== 1 || !isRouter(routers[0])) {
|
|
32
|
+
throw new Error("Invalid router module - either define exactly 1 export or return the router directly.\nExample: `experimental_lazy(() => import('./slow.js').then((m) => m.slowRouter))`");
|
|
33
|
+
}
|
|
34
|
+
return routers[0];
|
|
35
|
+
}
|
|
36
|
+
resolve[lazySymbol] = true;
|
|
37
|
+
return resolve;
|
|
34
38
|
}
|
|
35
39
|
function isLazy(input) {
|
|
36
40
|
return typeof input === 'function' && lazySymbol in input;
|
|
@@ -73,7 +77,7 @@ const emptyRouter = {
|
|
|
73
77
|
function createLazyLoader(opts) {
|
|
74
78
|
return {
|
|
75
79
|
ref: opts.ref,
|
|
76
|
-
load: async ()=>{
|
|
80
|
+
load: once(async ()=>{
|
|
77
81
|
const router = await opts.ref();
|
|
78
82
|
const lazyPath = [
|
|
79
83
|
...opts.path,
|
|
@@ -96,7 +100,7 @@ const emptyRouter = {
|
|
|
96
100
|
aggregate: opts.aggregate[opts.key]
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
|
-
}
|
|
103
|
+
})
|
|
100
104
|
};
|
|
101
105
|
}
|
|
102
106
|
function step(from, path = []) {
|
|
@@ -164,7 +168,10 @@ const emptyRouter = {
|
|
|
164
168
|
function isProcedure(procedureOrRouter) {
|
|
165
169
|
return typeof procedureOrRouter === 'function';
|
|
166
170
|
}
|
|
167
|
-
|
|
171
|
+
/**
|
|
172
|
+
* @internal
|
|
173
|
+
*/ async function getProcedureAtPath(router, path) {
|
|
174
|
+
const { _def } = router;
|
|
168
175
|
let procedure = _def.procedures[path];
|
|
169
176
|
while(!procedure){
|
|
170
177
|
const key = Object.keys(_def.lazy).find((key)=>path.startsWith(key));
|
|
@@ -184,7 +191,7 @@ async function getProcedureAtPath(_def, path) {
|
|
|
184
191
|
* @internal
|
|
185
192
|
*/ async function callProcedure(opts) {
|
|
186
193
|
const { type, path } = opts;
|
|
187
|
-
const proc = await getProcedureAtPath(opts.
|
|
194
|
+
const proc = await getProcedureAtPath(opts.router, path);
|
|
188
195
|
if (!proc || !isProcedure(proc) || proc._def.type !== type && !opts.allowMethodOverride) {
|
|
189
196
|
throw new TRPCError.TRPCError({
|
|
190
197
|
code: 'NOT_FOUND',
|
|
@@ -201,14 +208,14 @@ async function getProcedureAtPath(_def, path) {
|
|
|
201
208
|
}
|
|
202
209
|
function createCallerFactory() {
|
|
203
210
|
return function createCallerInner(router) {
|
|
204
|
-
const _def = router
|
|
211
|
+
const { _def } = router;
|
|
205
212
|
return function createCaller(ctxOrCallback, opts) {
|
|
206
213
|
return createProxy.createRecursiveProxy(async ({ path, args })=>{
|
|
207
214
|
const fullPath = path.join('.');
|
|
208
215
|
if (path.length === 1 && path[0] === '_def') {
|
|
209
216
|
return _def;
|
|
210
217
|
}
|
|
211
|
-
const procedure = await getProcedureAtPath(
|
|
218
|
+
const procedure = await getProcedureAtPath(router, fullPath);
|
|
212
219
|
let ctx = undefined;
|
|
213
220
|
try {
|
|
214
221
|
if (!procedure) {
|
|
@@ -2,33 +2,37 @@ import { createRecursiveProxy } from './createProxy.mjs';
|
|
|
2
2
|
import { defaultFormatter } from './error/formatter.mjs';
|
|
3
3
|
import { TRPCError, getTRPCErrorFromUnknown } from './error/TRPCError.mjs';
|
|
4
4
|
import { defaultTransformer } from './transformer.mjs';
|
|
5
|
-
import { mergeWithoutOverrides,
|
|
5
|
+
import { mergeWithoutOverrides, isObject, omitPrototype, isFunction } from './utils.mjs';
|
|
6
6
|
|
|
7
7
|
const lazySymbol = Symbol('lazy');
|
|
8
|
+
function once(fn) {
|
|
9
|
+
const uncalled = Symbol();
|
|
10
|
+
let result = uncalled;
|
|
11
|
+
return ()=>{
|
|
12
|
+
if (result === uncalled) {
|
|
13
|
+
result = fn();
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
8
18
|
/**
|
|
9
19
|
* Lazy load a router
|
|
10
20
|
* @see https://trpc.io/docs/server/merging-routers#lazy-load
|
|
11
|
-
*/ function lazy(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// if the module is a router, return it
|
|
18
|
-
if (isRouter(mod)) {
|
|
19
|
-
return mod;
|
|
20
|
-
}
|
|
21
|
-
const routers = Object.values(mod);
|
|
22
|
-
if (routers.length !== 1 || !isRouter(routers[0])) {
|
|
23
|
-
throw new Error("Invalid router module - either define exactly 1 export or return the router directly.\nExample: `experimental_lazy(() => import('./slow.js').then((m) => m.slowRouter))`");
|
|
24
|
-
}
|
|
25
|
-
return routers[0];
|
|
26
|
-
});
|
|
21
|
+
*/ function lazy(importRouter) {
|
|
22
|
+
async function resolve() {
|
|
23
|
+
const mod = await importRouter();
|
|
24
|
+
// if the module is a router, return it
|
|
25
|
+
if (isRouter(mod)) {
|
|
26
|
+
return mod;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const routers = Object.values(mod);
|
|
29
|
+
if (routers.length !== 1 || !isRouter(routers[0])) {
|
|
30
|
+
throw new Error("Invalid router module - either define exactly 1 export or return the router directly.\nExample: `experimental_lazy(() => import('./slow.js').then((m) => m.slowRouter))`");
|
|
31
|
+
}
|
|
32
|
+
return routers[0];
|
|
33
|
+
}
|
|
34
|
+
resolve[lazySymbol] = true;
|
|
35
|
+
return resolve;
|
|
32
36
|
}
|
|
33
37
|
function isLazy(input) {
|
|
34
38
|
return typeof input === 'function' && lazySymbol in input;
|
|
@@ -71,7 +75,7 @@ const emptyRouter = {
|
|
|
71
75
|
function createLazyLoader(opts) {
|
|
72
76
|
return {
|
|
73
77
|
ref: opts.ref,
|
|
74
|
-
load: async ()=>{
|
|
78
|
+
load: once(async ()=>{
|
|
75
79
|
const router = await opts.ref();
|
|
76
80
|
const lazyPath = [
|
|
77
81
|
...opts.path,
|
|
@@ -94,7 +98,7 @@ const emptyRouter = {
|
|
|
94
98
|
aggregate: opts.aggregate[opts.key]
|
|
95
99
|
});
|
|
96
100
|
}
|
|
97
|
-
}
|
|
101
|
+
})
|
|
98
102
|
};
|
|
99
103
|
}
|
|
100
104
|
function step(from, path = []) {
|
|
@@ -162,7 +166,10 @@ const emptyRouter = {
|
|
|
162
166
|
function isProcedure(procedureOrRouter) {
|
|
163
167
|
return typeof procedureOrRouter === 'function';
|
|
164
168
|
}
|
|
165
|
-
|
|
169
|
+
/**
|
|
170
|
+
* @internal
|
|
171
|
+
*/ async function getProcedureAtPath(router, path) {
|
|
172
|
+
const { _def } = router;
|
|
166
173
|
let procedure = _def.procedures[path];
|
|
167
174
|
while(!procedure){
|
|
168
175
|
const key = Object.keys(_def.lazy).find((key)=>path.startsWith(key));
|
|
@@ -182,7 +189,7 @@ async function getProcedureAtPath(_def, path) {
|
|
|
182
189
|
* @internal
|
|
183
190
|
*/ async function callProcedure(opts) {
|
|
184
191
|
const { type, path } = opts;
|
|
185
|
-
const proc = await getProcedureAtPath(opts.
|
|
192
|
+
const proc = await getProcedureAtPath(opts.router, path);
|
|
186
193
|
if (!proc || !isProcedure(proc) || proc._def.type !== type && !opts.allowMethodOverride) {
|
|
187
194
|
throw new TRPCError({
|
|
188
195
|
code: 'NOT_FOUND',
|
|
@@ -199,14 +206,14 @@ async function getProcedureAtPath(_def, path) {
|
|
|
199
206
|
}
|
|
200
207
|
function createCallerFactory() {
|
|
201
208
|
return function createCallerInner(router) {
|
|
202
|
-
const _def = router
|
|
209
|
+
const { _def } = router;
|
|
203
210
|
return function createCaller(ctxOrCallback, opts) {
|
|
204
211
|
return createRecursiveProxy(async ({ path, args })=>{
|
|
205
212
|
const fullPath = path.join('.');
|
|
206
213
|
if (path.length === 1 && path[0] === '_def') {
|
|
207
214
|
return _def;
|
|
208
215
|
}
|
|
209
|
-
const procedure = await getProcedureAtPath(
|
|
216
|
+
const procedure = await getProcedureAtPath(router, fullPath);
|
|
210
217
|
let ctx = undefined;
|
|
211
218
|
try {
|
|
212
219
|
if (!procedure) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.753+a0ce6809f",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"superstruct": "^2.0.0",
|
|
142
142
|
"tsx": "^4.0.0",
|
|
143
143
|
"typescript": "^5.7.2",
|
|
144
|
-
"valibot": "1.0.0-
|
|
144
|
+
"valibot": "1.0.0-rc.0",
|
|
145
145
|
"ws": "^8.0.0",
|
|
146
146
|
"yup": "^1.0.0",
|
|
147
147
|
"zod": "^3.0.0"
|
|
@@ -152,5 +152,5 @@
|
|
|
152
152
|
"peerDependencies": {
|
|
153
153
|
"typescript": ">=5.7.2"
|
|
154
154
|
},
|
|
155
|
-
"gitHead": "
|
|
155
|
+
"gitHead": "a0ce6809f9411c748490eb1e9414ca1c0da70c57"
|
|
156
156
|
}
|
|
@@ -7,7 +7,6 @@ export {
|
|
|
7
7
|
experimental_standaloneMiddleware as experimental_trpcMiddleware,
|
|
8
8
|
initTRPC,
|
|
9
9
|
// --- FIXME a bunch of these exports are only useful for plugins - move them somewhere else? ----
|
|
10
|
-
callProcedure as callTRPCProcedure,
|
|
11
10
|
getTRPCErrorFromUnknown,
|
|
12
11
|
transformTRPCResponse,
|
|
13
12
|
createFlatProxy as createTRPCFlatProxy,
|
package/src/adapters/ws.ts
CHANGED
|
@@ -219,7 +219,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
|
|
|
219
219
|
|
|
220
220
|
const abortController = new AbortController();
|
|
221
221
|
const result = await callProcedure({
|
|
222
|
-
|
|
222
|
+
router,
|
|
223
223
|
path,
|
|
224
224
|
getRawInput: async () => input,
|
|
225
225
|
ctx,
|
|
@@ -113,7 +113,7 @@ const jsonContentTypeHandler: ContentTypeHandler = {
|
|
|
113
113
|
const calls = await Promise.all(
|
|
114
114
|
paths.map(
|
|
115
115
|
async (path, index): Promise<TRPCRequestInfo['calls'][number]> => {
|
|
116
|
-
const procedure = await getProcedureAtPath(opts.router
|
|
116
|
+
const procedure = await getProcedureAtPath(opts.router, path);
|
|
117
117
|
return {
|
|
118
118
|
path,
|
|
119
119
|
procedure,
|
|
@@ -201,7 +201,7 @@ const formDataContentTypeHandler: ContentTypeHandler = {
|
|
|
201
201
|
const fd = await req.formData();
|
|
202
202
|
return fd;
|
|
203
203
|
});
|
|
204
|
-
const procedure = await getProcedureAtPath(opts.router
|
|
204
|
+
const procedure = await getProcedureAtPath(opts.router, opts.path);
|
|
205
205
|
return {
|
|
206
206
|
accept: null,
|
|
207
207
|
calls: [
|
|
@@ -245,7 +245,7 @@ const octetStreamContentTypeHandler: ContentTypeHandler = {
|
|
|
245
245
|
path: opts.path,
|
|
246
246
|
getRawInput: getInputs.read,
|
|
247
247
|
result: getInputs.result,
|
|
248
|
-
procedure: await getProcedureAtPath(opts.router
|
|
248
|
+
procedure: await getProcedureAtPath(opts.router, opts.path),
|
|
249
249
|
},
|
|
250
250
|
],
|
|
251
251
|
isBatchCall: false,
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
isObject,
|
|
19
19
|
mergeWithoutOverrides,
|
|
20
20
|
omitPrototype,
|
|
21
|
-
run,
|
|
22
21
|
} from './utils';
|
|
23
22
|
|
|
24
23
|
export interface RouterRecord {
|
|
@@ -83,44 +82,50 @@ type LazyLoader<TAny> = {
|
|
|
83
82
|
ref: Lazy<TAny>;
|
|
84
83
|
};
|
|
85
84
|
|
|
85
|
+
function once<T>(fn: () => T): () => T {
|
|
86
|
+
const uncalled = Symbol();
|
|
87
|
+
let result: T | typeof uncalled = uncalled;
|
|
88
|
+
return (): T => {
|
|
89
|
+
if (result === uncalled) {
|
|
90
|
+
result = fn();
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
86
96
|
/**
|
|
87
97
|
* Lazy load a router
|
|
88
98
|
* @see https://trpc.io/docs/server/merging-routers#lazy-load
|
|
89
99
|
*/
|
|
90
100
|
export function lazy<TRouter extends AnyRouter>(
|
|
91
|
-
|
|
101
|
+
importRouter: () => Promise<
|
|
92
102
|
| TRouter
|
|
93
103
|
| {
|
|
94
104
|
[key: string]: TRouter;
|
|
95
105
|
}
|
|
96
106
|
>,
|
|
97
107
|
): Lazy<NoInfer<TRouter>> {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!cachedPromise) {
|
|
101
|
-
cachedPromise = run(async (): Promise<TRouter> => {
|
|
102
|
-
const mod = await getRouter();
|
|
103
|
-
|
|
104
|
-
// if the module is a router, return it
|
|
105
|
-
if (isRouter(mod)) {
|
|
106
|
-
return mod;
|
|
107
|
-
}
|
|
108
|
+
async function resolve(): Promise<TRouter> {
|
|
109
|
+
const mod = await importRouter();
|
|
108
110
|
|
|
109
|
-
|
|
111
|
+
// if the module is a router, return it
|
|
112
|
+
if (isRouter(mod)) {
|
|
113
|
+
return mod;
|
|
114
|
+
}
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
throw new Error(
|
|
113
|
-
"Invalid router module - either define exactly 1 export or return the router directly.\nExample: `experimental_lazy(() => import('./slow.js').then((m) => m.slowRouter))`",
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
+
const routers = Object.values(mod);
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
if (routers.length !== 1 || !isRouter(routers[0])) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
"Invalid router module - either define exactly 1 export or return the router directly.\nExample: `experimental_lazy(() => import('./slow.js').then((m) => m.slowRouter))`",
|
|
121
|
+
);
|
|
119
122
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
|
|
124
|
+
return routers[0];
|
|
125
|
+
}
|
|
126
|
+
resolve[lazySymbol] = true as const;
|
|
127
|
+
|
|
128
|
+
return resolve;
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
function isLazy<TAny>(input: unknown): input is Lazy<TAny> {
|
|
@@ -140,7 +145,6 @@ export interface Router<
|
|
|
140
145
|
lazy: Record<string, LazyLoader<AnyRouter>>;
|
|
141
146
|
};
|
|
142
147
|
/**
|
|
143
|
-
* @deprecated use `t.createCallerFactory(router)` instead
|
|
144
148
|
* @see https://trpc.io/docs/v11/server/server-side-calls
|
|
145
149
|
*/
|
|
146
150
|
createCaller: RouterCaller<TRoot, TRecord>;
|
|
@@ -250,7 +254,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
250
254
|
}): LazyLoader<AnyRouter> {
|
|
251
255
|
return {
|
|
252
256
|
ref: opts.ref,
|
|
253
|
-
load: async () => {
|
|
257
|
+
load: once(async () => {
|
|
254
258
|
const router = await opts.ref();
|
|
255
259
|
const lazyPath = [...opts.path, opts.key];
|
|
256
260
|
const lazyKey = lazyPath.join('.');
|
|
@@ -273,7 +277,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
273
277
|
aggregate: opts.aggregate[opts.key] as RouterRecord,
|
|
274
278
|
});
|
|
275
279
|
}
|
|
276
|
-
},
|
|
280
|
+
}),
|
|
277
281
|
};
|
|
278
282
|
}
|
|
279
283
|
|
|
@@ -341,10 +345,14 @@ function isProcedure(
|
|
|
341
345
|
return typeof procedureOrRouter === 'function';
|
|
342
346
|
}
|
|
343
347
|
|
|
348
|
+
/**
|
|
349
|
+
* @internal
|
|
350
|
+
*/
|
|
344
351
|
export async function getProcedureAtPath(
|
|
345
|
-
|
|
352
|
+
router: Pick<Router<any, any>, '_def'>,
|
|
346
353
|
path: string,
|
|
347
354
|
): Promise<AnyProcedure | null> {
|
|
355
|
+
const { _def } = router;
|
|
348
356
|
let procedure = _def.procedures[path];
|
|
349
357
|
|
|
350
358
|
while (!procedure) {
|
|
@@ -370,12 +378,12 @@ export async function getProcedureAtPath(
|
|
|
370
378
|
*/
|
|
371
379
|
export async function callProcedure(
|
|
372
380
|
opts: ProcedureCallOptions<unknown> & {
|
|
373
|
-
|
|
381
|
+
router: AnyRouter;
|
|
374
382
|
allowMethodOverride?: boolean;
|
|
375
383
|
},
|
|
376
384
|
) {
|
|
377
385
|
const { type, path } = opts;
|
|
378
|
-
const proc = await getProcedureAtPath(opts.
|
|
386
|
+
const proc = await getProcedureAtPath(opts.router, path);
|
|
379
387
|
if (
|
|
380
388
|
!proc ||
|
|
381
389
|
!isProcedure(proc) ||
|
|
@@ -406,7 +414,7 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
406
414
|
return function createCallerInner<TRecord extends RouterRecord>(
|
|
407
415
|
router: Pick<Router<TRoot, TRecord>, '_def'>,
|
|
408
416
|
): RouterCaller<TRoot, TRecord> {
|
|
409
|
-
const _def = router
|
|
417
|
+
const { _def } = router;
|
|
410
418
|
type Context = TRoot['ctx'];
|
|
411
419
|
|
|
412
420
|
return function createCaller(ctxOrCallback, opts) {
|
|
@@ -418,7 +426,7 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
418
426
|
return _def;
|
|
419
427
|
}
|
|
420
428
|
|
|
421
|
-
const procedure = await getProcedureAtPath(
|
|
429
|
+
const procedure = await getProcedureAtPath(router, fullPath);
|
|
422
430
|
|
|
423
431
|
let ctx: Context | undefined = undefined;
|
|
424
432
|
try {
|