@trpc/server 11.0.0-rc.750 → 11.0.0-rc.752
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/bundle-analysis.json +28 -28
- package/dist/unstable-core-do-not-import/router.d.ts +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +26 -22
- package/dist/unstable-core-do-not-import/router.mjs +27 -23
- package/package.json +3 -3
- package/src/unstable-core-do-not-import/router.ts +31 -26
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 13.
|
|
2
|
+
"bundleSize": 198979,
|
|
3
|
+
"bundleOrigSize": 230695,
|
|
4
|
+
"bundleReduction": 13.75,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
"id": "/src/unstable-core-do-not-import/router.ts",
|
|
85
|
-
"size":
|
|
86
|
-
"origSize":
|
|
85
|
+
"size": 10112,
|
|
86
|
+
"origSize": 14424,
|
|
87
87
|
"renderedExports": [
|
|
88
88
|
"lazy",
|
|
89
89
|
"createRouterFactory",
|
|
@@ -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.08,
|
|
102
|
+
"reduction": 29.89
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
"id": "/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts",
|
|
@@ -246,7 +246,7 @@
|
|
|
246
246
|
"dependents": [
|
|
247
247
|
"/src/observable/index.ts"
|
|
248
248
|
],
|
|
249
|
-
"percent": 1.
|
|
249
|
+
"percent": 1.97,
|
|
250
250
|
"reduction": 1.66
|
|
251
251
|
},
|
|
252
252
|
{
|
|
@@ -291,9 +291,9 @@
|
|
|
291
291
|
"removedExports": [],
|
|
292
292
|
"dependents": [
|
|
293
293
|
"/src/unstable-core-do-not-import.ts",
|
|
294
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
295
294
|
"/src/unstable-core-do-not-import/router.ts",
|
|
296
|
-
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
295
|
+
"/src/unstable-core-do-not-import/initTRPC.ts",
|
|
296
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
297
297
|
],
|
|
298
298
|
"percent": 1.38,
|
|
299
299
|
"reduction": 45.98
|
|
@@ -353,14 +353,14 @@
|
|
|
353
353
|
"removedExports": [],
|
|
354
354
|
"dependents": [
|
|
355
355
|
"/src/unstable-core-do-not-import.ts",
|
|
356
|
-
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
357
|
-
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
358
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
359
|
-
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
360
356
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
361
357
|
"/src/unstable-core-do-not-import/router.ts",
|
|
362
358
|
"/src/unstable-core-do-not-import/transformer.ts",
|
|
363
359
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
360
|
+
"/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
|
|
361
|
+
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
362
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.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",
|
|
@@ -382,10 +382,10 @@
|
|
|
382
382
|
"removedExports": [],
|
|
383
383
|
"dependents": [
|
|
384
384
|
"/src/unstable-core-do-not-import.ts",
|
|
385
|
-
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
386
|
-
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
387
385
|
"/src/unstable-core-do-not-import/router.ts",
|
|
388
386
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
387
|
+
"/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
|
|
388
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts",
|
|
389
389
|
"/src/unstable-core-do-not-import/http/contentType.ts",
|
|
390
390
|
"/src/unstable-core-do-not-import/procedureBuilder.ts",
|
|
391
391
|
"/src/unstable-core-do-not-import/stream/sse.ts"
|
|
@@ -452,8 +452,8 @@
|
|
|
452
452
|
"removedExports": [],
|
|
453
453
|
"dependents": [
|
|
454
454
|
"/src/unstable-core-do-not-import.ts",
|
|
455
|
-
"/src/unstable-core-do-not-import/
|
|
456
|
-
"/src/unstable-core-do-not-import/
|
|
455
|
+
"/src/unstable-core-do-not-import/error/getErrorShape.ts",
|
|
456
|
+
"/src/unstable-core-do-not-import/http/resolveResponse.ts"
|
|
457
457
|
],
|
|
458
458
|
"percent": 1.05,
|
|
459
459
|
"reduction": 18.54
|
|
@@ -860,31 +860,31 @@
|
|
|
860
860
|
"reduction": 93.9
|
|
861
861
|
},
|
|
862
862
|
{
|
|
863
|
-
"id": "/src/
|
|
863
|
+
"id": "/src/index.ts",
|
|
864
864
|
"size": 0,
|
|
865
|
-
"origSize":
|
|
865
|
+
"origSize": 32,
|
|
866
866
|
"renderedExports": [],
|
|
867
867
|
"removedExports": [],
|
|
868
|
-
"dependents": [
|
|
869
|
-
"/src/adapters/ws.ts"
|
|
870
|
-
],
|
|
868
|
+
"dependents": [],
|
|
871
869
|
"percent": 0,
|
|
872
870
|
"reduction": 100
|
|
873
871
|
},
|
|
874
872
|
{
|
|
875
|
-
"id": "/src/
|
|
873
|
+
"id": "/src/http.ts",
|
|
876
874
|
"size": 0,
|
|
877
|
-
"origSize":
|
|
875
|
+
"origSize": 37,
|
|
878
876
|
"renderedExports": [],
|
|
879
877
|
"removedExports": [],
|
|
880
|
-
"dependents": [
|
|
878
|
+
"dependents": [
|
|
879
|
+
"/src/adapters/ws.ts"
|
|
880
|
+
],
|
|
881
881
|
"percent": 0,
|
|
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": [],
|
|
@@ -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> {
|
|
@@ -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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KAAK,YAAY,CACf,QAAQ,SAAS,SAAS,EAAE,EAC5B,KAAK,SAAS,YAAY,GAAG,QAAQ,CAAC,CAAC,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 = []) {
|
|
@@ -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 = []) {
|
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.752+e31a1f599",
|
|
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": "e31a1f59920f20a5bcf690dc01ebda0c9ecf3e1b"
|
|
156
156
|
}
|
|
@@ -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> {
|
|
@@ -250,7 +255,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
250
255
|
}): LazyLoader<AnyRouter> {
|
|
251
256
|
return {
|
|
252
257
|
ref: opts.ref,
|
|
253
|
-
load: async () => {
|
|
258
|
+
load: once(async () => {
|
|
254
259
|
const router = await opts.ref();
|
|
255
260
|
const lazyPath = [...opts.path, opts.key];
|
|
256
261
|
const lazyKey = lazyPath.join('.');
|
|
@@ -273,7 +278,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
273
278
|
aggregate: opts.aggregate[opts.key] as RouterRecord,
|
|
274
279
|
});
|
|
275
280
|
}
|
|
276
|
-
},
|
|
281
|
+
}),
|
|
277
282
|
};
|
|
278
283
|
}
|
|
279
284
|
|