@trpc/server 11.0.0-alpha-tmp-issues-5557-types-node-wut.324 → 11.0.0-alpha-tmp-04-02-no-typesProxy.331
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/adapters/next-app-dir/index.d.ts +1 -0
- package/adapters/next-app-dir/index.js +1 -0
- package/dist/adapters/aws-lambda/index.js +1 -0
- package/dist/adapters/aws-lambda/index.mjs +1 -0
- package/dist/adapters/aws-lambda/utils.js +1 -0
- package/dist/adapters/aws-lambda/utils.mjs +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.js +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +1 -0
- package/dist/adapters/fetch/fetchRequestHandler.mjs +1 -0
- package/dist/adapters/next-app-dir/formDataToObject.d.ts +2 -0
- package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/formDataToObject.js +34 -0
- package/dist/adapters/next-app-dir/formDataToObject.mjs +32 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +24 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +86 -0
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +84 -0
- package/dist/adapters/next-app-dir/notFound.d.ts +7 -0
- package/dist/adapters/next-app-dir/notFound.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/notFound.js +16 -0
- package/dist/adapters/next-app-dir/notFound.mjs +14 -0
- package/dist/adapters/next-app-dir/redirect.d.ts +18 -0
- package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/redirect.js +34 -0
- package/dist/adapters/next-app-dir/redirect.mjs +31 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts +6 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts.map +1 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +23 -0
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +21 -0
- package/dist/adapters/next-app-dir.d.ts +4 -0
- package/dist/adapters/next-app-dir.d.ts.map +1 -0
- package/dist/adapters/next-app-dir.js +11 -0
- package/dist/adapters/next-app-dir.mjs +3 -0
- package/dist/adapters/next.js +1 -0
- package/dist/adapters/next.mjs +1 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.js +1 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +1 -0
- package/dist/adapters/node-http/content-type/json/index.js +1 -0
- package/dist/adapters/node-http/content-type/json/index.mjs +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +1 -0
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.js +1 -0
- package/dist/adapters/ws.mjs +1 -0
- package/dist/bundle-analysis.json +178 -92
- package/dist/http.js +1 -0
- package/dist/http.mjs +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/rpc.js +1 -0
- package/dist/rpc.mjs +1 -0
- package/dist/shared.js +1 -0
- package/dist/shared.mjs +1 -0
- package/dist/unstable-core-do-not-import/clientish/inference.d.ts +3 -3
- package/dist/unstable-core-do-not-import/clientish/inference.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +1 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +5 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/types.d.ts +7 -10
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +3 -3
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.js +2 -4
- package/dist/unstable-core-do-not-import/initTRPC.mjs +2 -4
- package/dist/unstable-core-do-not-import/procedure.d.ts +23 -5
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +36 -15
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +28 -3
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +29 -4
- package/dist/unstable-core-do-not-import/router.d.ts +12 -6
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +18 -23
- package/dist/unstable-core-do-not-import/router.mjs +20 -25
- package/dist/unstable-core-do-not-import/utils.d.ts +8 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +16 -0
- package/dist/unstable-core-do-not-import/utils.mjs +15 -1
- package/dist/unstable-core-do-not-import.js +2 -0
- package/dist/unstable-core-do-not-import.mjs +1 -1
- package/package.json +10 -5
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/next-app-dir/formDataToObject.ts +36 -0
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +129 -0
- package/src/adapters/next-app-dir/notFound.ts +12 -0
- package/src/adapters/next-app-dir/redirect.ts +30 -0
- package/src/adapters/next-app-dir/rethrowNextErrors.ts +25 -0
- package/src/adapters/next-app-dir.ts +3 -0
- package/src/unstable-core-do-not-import/clientish/inference.ts +9 -5
- package/src/unstable-core-do-not-import/http/index.ts +5 -1
- package/src/unstable-core-do-not-import/http/types.ts +9 -10
- package/src/unstable-core-do-not-import/initTRPC.ts +2 -6
- package/src/unstable-core-do-not-import/procedure.ts +27 -7
- package/src/unstable-core-do-not-import/procedureBuilder.ts +106 -27
- package/src/unstable-core-do-not-import/router.ts +49 -35
- package/src/unstable-core-do-not-import/utils.ts +20 -0
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import type { Observable } from '../observable';
|
|
2
2
|
import { TRPCError } from './error/TRPCError';
|
|
3
|
-
import type { AnyProcedure, inferProcedureInput } from './procedure';
|
|
3
|
+
import type { AnyProcedure, ErrorHandlerOptions, inferProcedureInput, inferProcedureOutput } from './procedure';
|
|
4
4
|
import type { ProcedureCallOptions } from './procedureBuilder';
|
|
5
5
|
import type { AnyRootTypes, RootConfig } from './rootConfig';
|
|
6
6
|
import type { MaybePromise } from './types';
|
|
7
7
|
export interface RouterRecord {
|
|
8
8
|
[key: string]: AnyProcedure | RouterRecord;
|
|
9
9
|
}
|
|
10
|
-
type DecorateProcedure<TProcedure extends AnyProcedure> = (input: inferProcedureInput<TProcedure>) => Promise<TProcedure['_def']['type'] extends 'subscription' ? Observable<TProcedure
|
|
10
|
+
type DecorateProcedure<TProcedure extends AnyProcedure> = (input: inferProcedureInput<TProcedure>) => Promise<TProcedure['_def']['type'] extends 'subscription' ? Observable<inferProcedureOutput<TProcedure>, TRPCError> : inferProcedureOutput<TProcedure>>;
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
|
13
13
|
*/
|
|
14
14
|
export type DecorateRouterRecord<TRecord extends RouterRecord> = {
|
|
15
15
|
[TKey in keyof TRecord]: TRecord[TKey] extends AnyProcedure ? DecorateProcedure<TRecord[TKey]> : TRecord[TKey] extends RouterRecord ? DecorateRouterRecord<TRecord[TKey]> : never;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type RouterCallerErrorHandler<TContext> = (opts: ErrorHandlerOptions<TContext>) => void;
|
|
17
21
|
/**
|
|
18
22
|
* @internal
|
|
19
23
|
*/
|
|
@@ -23,7 +27,9 @@ export type RouterCaller<TRoot extends AnyRootTypes, TRecord extends RouterRecor
|
|
|
23
27
|
* If passing a function, we recommend it's a cached function
|
|
24
28
|
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
25
29
|
*/
|
|
26
|
-
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>)
|
|
30
|
+
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>), options?: {
|
|
31
|
+
onError?: RouterCallerErrorHandler<TRoot['ctx']>;
|
|
32
|
+
}) => DecorateRouterRecord<TRecord>;
|
|
27
33
|
export interface Router<TRoot extends AnyRootTypes, TRecord extends RouterRecord> {
|
|
28
34
|
_def: {
|
|
29
35
|
_config: RootConfig<TRoot>;
|
|
@@ -60,11 +66,11 @@ export declare function createRouterFactory<TRoot extends AnyRootTypes>(config:
|
|
|
60
66
|
/**
|
|
61
67
|
* @internal
|
|
62
68
|
*/
|
|
63
|
-
export declare function callProcedure(opts: ProcedureCallOptions & {
|
|
69
|
+
export declare function callProcedure(opts: ProcedureCallOptions<unknown> & {
|
|
64
70
|
procedures: RouterRecord;
|
|
65
71
|
allowMethodOverride?: boolean;
|
|
66
|
-
}): Promise<
|
|
67
|
-
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <TRecord extends RouterRecord>(router: Router<TRoot, TRecord>) => RouterCaller<TRoot, TRecord>;
|
|
72
|
+
}): Promise<any>;
|
|
73
|
+
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <TRecord extends RouterRecord>(router: Pick<Router<TRoot, TRecord>, '_def'>) => RouterCaller<TRoot, TRecord>;
|
|
68
74
|
/** @internal */
|
|
69
75
|
type MergeRouters<TRouters extends AnyRouter[], TRoot extends AnyRootTypes = TRouters[0]['_def']['_config']['$types'], TRecord extends RouterRecord = {}> = TRouters extends [
|
|
70
76
|
infer Head extends AnyRouter,
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/router.ts"],"names":[],"mappings":"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"}
|
|
@@ -77,19 +77,9 @@ const emptyRouter = {
|
|
|
77
77
|
return {
|
|
78
78
|
...record,
|
|
79
79
|
_def,
|
|
80
|
-
createCaller (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const procedure = _def.procedures[fullPath];
|
|
84
|
-
return procedure({
|
|
85
|
-
path: fullPath,
|
|
86
|
-
getRawInput: async ()=>args[0],
|
|
87
|
-
ctx,
|
|
88
|
-
type: procedure._def.type
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
return proxy;
|
|
92
|
-
}
|
|
80
|
+
createCaller: createCallerFactory()({
|
|
81
|
+
_def
|
|
82
|
+
})
|
|
93
83
|
};
|
|
94
84
|
}
|
|
95
85
|
return createRouterInner;
|
|
@@ -113,24 +103,29 @@ function isProcedure(procedureOrRouter) {
|
|
|
113
103
|
function createCallerFactory() {
|
|
114
104
|
return function createCallerInner(router) {
|
|
115
105
|
const _def = router._def;
|
|
116
|
-
return function createCaller(
|
|
117
|
-
const proxy = createProxy.createRecursiveProxy(({ path , args })=>{
|
|
106
|
+
return function createCaller(ctxOrCallback, options) {
|
|
107
|
+
const proxy = createProxy.createRecursiveProxy(async ({ path , args })=>{
|
|
118
108
|
const fullPath = path.join('.');
|
|
119
109
|
const procedure = _def.procedures[fullPath];
|
|
120
|
-
|
|
110
|
+
let ctx = undefined;
|
|
111
|
+
try {
|
|
112
|
+
ctx = utils.isFunction(ctxOrCallback) ? await Promise.resolve(ctxOrCallback()) : ctxOrCallback;
|
|
113
|
+
return await procedure({
|
|
121
114
|
path: fullPath,
|
|
122
115
|
getRawInput: async ()=>args[0],
|
|
123
116
|
ctx,
|
|
124
117
|
type: procedure._def.type
|
|
125
118
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
} catch (cause) {
|
|
120
|
+
options?.onError?.({
|
|
121
|
+
ctx,
|
|
122
|
+
error: TRPCError.getTRPCErrorFromUnknown(cause),
|
|
123
|
+
input: args[0],
|
|
124
|
+
path: fullPath,
|
|
125
|
+
type: procedure._def.type
|
|
126
|
+
});
|
|
127
|
+
throw cause;
|
|
132
128
|
}
|
|
133
|
-
return callProc(maybeContext);
|
|
134
129
|
});
|
|
135
130
|
return proxy;
|
|
136
131
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRecursiveProxy } from './createProxy.mjs';
|
|
2
2
|
import { defaultFormatter } from './error/formatter.mjs';
|
|
3
|
-
import { TRPCError } from './error/TRPCError.mjs';
|
|
3
|
+
import { TRPCError, getTRPCErrorFromUnknown } from './error/TRPCError.mjs';
|
|
4
4
|
import { defaultTransformer } from './transformer.mjs';
|
|
5
|
-
import { mergeWithoutOverrides, omitPrototype } from './utils.mjs';
|
|
5
|
+
import { mergeWithoutOverrides, omitPrototype, isFunction } from './utils.mjs';
|
|
6
6
|
|
|
7
7
|
function isRouter(procedureOrRouter) {
|
|
8
8
|
return procedureOrRouter._def && 'router' in procedureOrRouter._def;
|
|
@@ -75,19 +75,9 @@ const emptyRouter = {
|
|
|
75
75
|
return {
|
|
76
76
|
...record,
|
|
77
77
|
_def,
|
|
78
|
-
createCaller (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const procedure = _def.procedures[fullPath];
|
|
82
|
-
return procedure({
|
|
83
|
-
path: fullPath,
|
|
84
|
-
getRawInput: async ()=>args[0],
|
|
85
|
-
ctx,
|
|
86
|
-
type: procedure._def.type
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
return proxy;
|
|
90
|
-
}
|
|
78
|
+
createCaller: createCallerFactory()({
|
|
79
|
+
_def
|
|
80
|
+
})
|
|
91
81
|
};
|
|
92
82
|
}
|
|
93
83
|
return createRouterInner;
|
|
@@ -111,24 +101,29 @@ function isProcedure(procedureOrRouter) {
|
|
|
111
101
|
function createCallerFactory() {
|
|
112
102
|
return function createCallerInner(router) {
|
|
113
103
|
const _def = router._def;
|
|
114
|
-
return function createCaller(
|
|
115
|
-
const proxy = createRecursiveProxy(({ path , args })=>{
|
|
104
|
+
return function createCaller(ctxOrCallback, options) {
|
|
105
|
+
const proxy = createRecursiveProxy(async ({ path , args })=>{
|
|
116
106
|
const fullPath = path.join('.');
|
|
117
107
|
const procedure = _def.procedures[fullPath];
|
|
118
|
-
|
|
108
|
+
let ctx = undefined;
|
|
109
|
+
try {
|
|
110
|
+
ctx = isFunction(ctxOrCallback) ? await Promise.resolve(ctxOrCallback()) : ctxOrCallback;
|
|
111
|
+
return await procedure({
|
|
119
112
|
path: fullPath,
|
|
120
113
|
getRawInput: async ()=>args[0],
|
|
121
114
|
ctx,
|
|
122
115
|
type: procedure._def.type
|
|
123
116
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
117
|
+
} catch (cause) {
|
|
118
|
+
options?.onError?.({
|
|
119
|
+
ctx,
|
|
120
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
121
|
+
input: args[0],
|
|
122
|
+
path: fullPath,
|
|
123
|
+
type: procedure._def.type
|
|
124
|
+
});
|
|
125
|
+
throw cause;
|
|
130
126
|
}
|
|
131
|
-
return callProc(maybeContext);
|
|
132
127
|
});
|
|
133
128
|
return proxy;
|
|
134
129
|
};
|
|
@@ -8,9 +8,17 @@ export declare function mergeWithoutOverrides<TType extends Record<string, unkno
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
11
|
+
type AnyFn = (...args: any[]) => unknown;
|
|
12
|
+
export declare function isFunction(fn: unknown): fn is AnyFn;
|
|
11
13
|
/**
|
|
12
14
|
* Create an object without inheriting anything from `Object.prototype`
|
|
13
15
|
* @internal
|
|
14
16
|
*/
|
|
15
17
|
export declare function omitPrototype<TObj extends Record<string, unknown>>(obj: TObj): TObj;
|
|
18
|
+
/**
|
|
19
|
+
* Prevents access to `$types` at runtime
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare const $typesProxy: any;
|
|
23
|
+
export {};
|
|
16
24
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,GACxB,KAAK,CAYP;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;AACzC,wBAAgB,UAAU,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,KAAK,CAEnD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,GAAG,EAAE,IAAI,GACR,IAAI,CAEN;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,KAOtB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var createProxy = require('./createProxy.js');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Ensures there are no duplicate keys when building a procedure.
|
|
5
7
|
* @internal
|
|
@@ -21,13 +23,27 @@
|
|
|
21
23
|
*/ function isObject(value) {
|
|
22
24
|
return !!value && !Array.isArray(value) && typeof value === 'object';
|
|
23
25
|
}
|
|
26
|
+
function isFunction(fn) {
|
|
27
|
+
return typeof fn === 'function';
|
|
28
|
+
}
|
|
24
29
|
/**
|
|
25
30
|
* Create an object without inheriting anything from `Object.prototype`
|
|
26
31
|
* @internal
|
|
27
32
|
*/ function omitPrototype(obj) {
|
|
28
33
|
return Object.assign(Object.create(null), obj);
|
|
29
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Prevents access to `$types` at runtime
|
|
37
|
+
* @internal
|
|
38
|
+
*/ const $typesProxy = createProxy.createFlatProxy((key)=>{
|
|
39
|
+
if (key === 'prototype') {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Tried to access "$types.${key}" which is not available at runtime`);
|
|
43
|
+
});
|
|
30
44
|
|
|
45
|
+
exports.$typesProxy = $typesProxy;
|
|
46
|
+
exports.isFunction = isFunction;
|
|
31
47
|
exports.isObject = isObject;
|
|
32
48
|
exports.mergeWithoutOverrides = mergeWithoutOverrides;
|
|
33
49
|
exports.omitPrototype = omitPrototype;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createFlatProxy } from './createProxy.mjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Ensures there are no duplicate keys when building a procedure.
|
|
3
5
|
* @internal
|
|
@@ -19,11 +21,23 @@
|
|
|
19
21
|
*/ function isObject(value) {
|
|
20
22
|
return !!value && !Array.isArray(value) && typeof value === 'object';
|
|
21
23
|
}
|
|
24
|
+
function isFunction(fn) {
|
|
25
|
+
return typeof fn === 'function';
|
|
26
|
+
}
|
|
22
27
|
/**
|
|
23
28
|
* Create an object without inheriting anything from `Object.prototype`
|
|
24
29
|
* @internal
|
|
25
30
|
*/ function omitPrototype(obj) {
|
|
26
31
|
return Object.assign(Object.create(null), obj);
|
|
27
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Prevents access to `$types` at runtime
|
|
35
|
+
* @internal
|
|
36
|
+
*/ const $typesProxy = createFlatProxy((key)=>{
|
|
37
|
+
if (key === 'prototype') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Tried to access "$types.${key}" which is not available at runtime`);
|
|
41
|
+
});
|
|
28
42
|
|
|
29
|
-
export { isObject, mergeWithoutOverrides, omitPrototype };
|
|
43
|
+
export { $typesProxy, isFunction, isObject, mergeWithoutOverrides, omitPrototype };
|
|
@@ -60,6 +60,8 @@ exports.getDataTransformer = transformer.getDataTransformer;
|
|
|
60
60
|
exports.transformResult = transformer.transformResult;
|
|
61
61
|
exports.transformTRPCResponse = transformer.transformTRPCResponse;
|
|
62
62
|
exports.ERROR_SYMBOL = types.ERROR_SYMBOL;
|
|
63
|
+
exports.$typesProxy = utils.$typesProxy;
|
|
64
|
+
exports.isFunction = utils.isFunction;
|
|
63
65
|
exports.isObject = utils.isObject;
|
|
64
66
|
exports.mergeWithoutOverrides = utils.mergeWithoutOverrides;
|
|
65
67
|
exports.omitPrototype = utils.omitPrototype;
|
|
@@ -18,4 +18,4 @@ export { TRPC_ERROR_CODES_BY_KEY, TRPC_ERROR_CODES_BY_NUMBER } from './unstable-
|
|
|
18
18
|
export { parseTRPCMessage } from './unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
|
|
19
19
|
export { defaultTransformer, getDataTransformer, transformResult, transformTRPCResponse } from './unstable-core-do-not-import/transformer.mjs';
|
|
20
20
|
export { ERROR_SYMBOL } from './unstable-core-do-not-import/types.mjs';
|
|
21
|
-
export { isObject, mergeWithoutOverrides, omitPrototype } from './unstable-core-do-not-import/utils.mjs';
|
|
21
|
+
export { $typesProxy, isFunction, isObject, mergeWithoutOverrides, omitPrototype } from './unstable-core-do-not-import/utils.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-alpha-tmp-
|
|
3
|
+
"version": "11.0.0-alpha-tmp-04-02-no-typesProxy.331+c9bd88605",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
"require": "./dist/adapters/fetch/index.js",
|
|
49
49
|
"default": "./dist/adapters/fetch/index.js"
|
|
50
50
|
},
|
|
51
|
+
"./adapters/next-app-dir": {
|
|
52
|
+
"import": "./dist/adapters/next-app-dir.mjs",
|
|
53
|
+
"require": "./dist/adapters/next-app-dir.js",
|
|
54
|
+
"default": "./dist/adapters/next-app-dir.js"
|
|
55
|
+
},
|
|
51
56
|
"./adapters/next": {
|
|
52
57
|
"import": "./dist/adapters/next.mjs",
|
|
53
58
|
"require": "./dist/adapters/next.js",
|
|
@@ -121,7 +126,7 @@
|
|
|
121
126
|
"access": "public"
|
|
122
127
|
},
|
|
123
128
|
"devDependencies": {
|
|
124
|
-
"@fastify/websocket": "^
|
|
129
|
+
"@fastify/websocket": "^10.0.1",
|
|
125
130
|
"@tanstack/react-query": "^5.25.0",
|
|
126
131
|
"@types/aws-lambda": "^8.10.97",
|
|
127
132
|
"@types/express": "^4.17.17",
|
|
@@ -135,11 +140,11 @@
|
|
|
135
140
|
"devalue": "^4.0.0",
|
|
136
141
|
"eslint": "^8.56.0",
|
|
137
142
|
"express": "^4.17.1",
|
|
138
|
-
"fastify": "^4.
|
|
143
|
+
"fastify": "^4.16.0",
|
|
139
144
|
"fastify-plugin": "^4.5.0",
|
|
140
145
|
"hash-sum": "^2.0.0",
|
|
141
146
|
"myzod": "^1.3.1",
|
|
142
|
-
"next": "^14.
|
|
147
|
+
"next": "^14.1.4",
|
|
143
148
|
"react": "^18.2.0",
|
|
144
149
|
"react-dom": "^18.2.0",
|
|
145
150
|
"rollup": "^4.9.5",
|
|
@@ -156,5 +161,5 @@
|
|
|
156
161
|
"funding": [
|
|
157
162
|
"https://trpc.io/sponsor"
|
|
158
163
|
],
|
|
159
|
-
"gitHead": "
|
|
164
|
+
"gitHead": "c9bd8860574d62c6d24907a0f9eada052ac45816"
|
|
160
165
|
}
|
|
@@ -60,7 +60,7 @@ export function fastifyTRPCPlugin<TRouter extends AnyRouter>(
|
|
|
60
60
|
...(opts.trpcOptions as unknown as WSSHandlerOptions<TRouter>),
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
fastify.get(prefix ?? '/', { websocket: true }, (
|
|
63
|
+
fastify.get(prefix ?? '/', { websocket: true }, (socket, req) =>
|
|
64
64
|
onConnection(socket, req.raw),
|
|
65
65
|
);
|
|
66
66
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
function set(
|
|
3
|
+
obj: Record<string, any>,
|
|
4
|
+
path: string[] | string,
|
|
5
|
+
value: unknown,
|
|
6
|
+
): void {
|
|
7
|
+
if (typeof path === 'string') {
|
|
8
|
+
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (path.length > 1) {
|
|
12
|
+
const p = path.shift()!;
|
|
13
|
+
const isArrayIndex = /^\d+$/.test(path[0]!);
|
|
14
|
+
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
15
|
+
set(obj[p], path, value);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const p = path[0]!;
|
|
19
|
+
if (obj[p] === undefined) {
|
|
20
|
+
obj[p] = value;
|
|
21
|
+
} else if (Array.isArray(obj[p])) {
|
|
22
|
+
obj[p].push(value);
|
|
23
|
+
} else {
|
|
24
|
+
obj[p] = [obj[p], value];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function formDataToObject(formData: FormData) {
|
|
29
|
+
const obj: Record<string, unknown> = {};
|
|
30
|
+
|
|
31
|
+
for (const [key, value] of formData.entries()) {
|
|
32
|
+
set(obj, key, value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { getTRPCErrorFromUnknown, TRPCError } from '../../@trpc/server';
|
|
2
|
+
// FIXME: fix lint rule, this is ok
|
|
3
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
|
+
import type { ErrorHandlerOptions } from '../../unstable-core-do-not-import/procedure';
|
|
5
|
+
// FIXME: fix lint rule, this is ok
|
|
6
|
+
// eslint-disable-next-line no-restricted-imports
|
|
7
|
+
import type { CallerOverride } from '../../unstable-core-do-not-import/procedureBuilder';
|
|
8
|
+
// FIXME: fix lint rule, this is ok
|
|
9
|
+
// eslint-disable-next-line no-restricted-imports
|
|
10
|
+
import type {
|
|
11
|
+
MaybePromise,
|
|
12
|
+
Simplify,
|
|
13
|
+
} from '../../unstable-core-do-not-import/types';
|
|
14
|
+
import { formDataToObject } from './formDataToObject';
|
|
15
|
+
import { TRPCRedirectError } from './redirect';
|
|
16
|
+
import { rethrowNextErrors } from './rethrowNextErrors';
|
|
17
|
+
|
|
18
|
+
type ContextCallback<TContext> = object extends TContext
|
|
19
|
+
? {
|
|
20
|
+
createContext?: () => MaybePromise<TContext>;
|
|
21
|
+
}
|
|
22
|
+
: {
|
|
23
|
+
createContext: () => MaybePromise<TContext>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create a caller that works with Next.js React Server Components & Server Actions
|
|
28
|
+
*/
|
|
29
|
+
export function nextAppDirCaller<TContext>(
|
|
30
|
+
config: Simplify<
|
|
31
|
+
{
|
|
32
|
+
/**
|
|
33
|
+
* Transform form data to a `Record` before passing it to the procedure
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
normalizeFormData?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Called when an error occurs in the handler
|
|
39
|
+
*/
|
|
40
|
+
onError?: (opts: ErrorHandlerOptions<TContext>) => void;
|
|
41
|
+
} & ContextCallback<TContext>
|
|
42
|
+
>,
|
|
43
|
+
): CallerOverride<TContext> {
|
|
44
|
+
const {
|
|
45
|
+
normalizeFormData = true,
|
|
46
|
+
|
|
47
|
+
// rethrowNextErrors = true
|
|
48
|
+
} = config;
|
|
49
|
+
const createContext = async (): Promise<TContext> => {
|
|
50
|
+
return config?.createContext?.() ?? ({} as TContext);
|
|
51
|
+
};
|
|
52
|
+
return async (opts) => {
|
|
53
|
+
const ctx: TContext = await createContext().catch((cause) => {
|
|
54
|
+
const error = new TRPCError({
|
|
55
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
56
|
+
message: 'Failed to create context',
|
|
57
|
+
cause,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const handleError = (cause: unknown) => {
|
|
64
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
65
|
+
|
|
66
|
+
config.onError?.({
|
|
67
|
+
ctx,
|
|
68
|
+
error,
|
|
69
|
+
input: opts.args[0],
|
|
70
|
+
path: '',
|
|
71
|
+
type: opts._def.type,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
rethrowNextErrors(error);
|
|
75
|
+
|
|
76
|
+
throw error;
|
|
77
|
+
};
|
|
78
|
+
switch (opts._def.type) {
|
|
79
|
+
case 'mutation': {
|
|
80
|
+
/**
|
|
81
|
+
* When you wrap an action with useFormState, it gets an extra argument as its first argument.
|
|
82
|
+
* The submitted form data is therefore its second argument instead of its first as it would usually be.
|
|
83
|
+
* The new first argument that gets added is the current state of the form.
|
|
84
|
+
* @see https://react.dev/reference/react-dom/hooks/useFormState#my-action-can-no-longer-read-the-submitted-form-data
|
|
85
|
+
*/
|
|
86
|
+
let input = opts.args.length === 1 ? opts.args[0] : opts.args[1];
|
|
87
|
+
if (normalizeFormData && input instanceof FormData) {
|
|
88
|
+
input = formDataToObject(input);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return await opts
|
|
92
|
+
.invoke({
|
|
93
|
+
type: opts._def.type,
|
|
94
|
+
ctx,
|
|
95
|
+
getRawInput: async () => input,
|
|
96
|
+
path: '',
|
|
97
|
+
input,
|
|
98
|
+
})
|
|
99
|
+
.then((data) => {
|
|
100
|
+
if (data instanceof TRPCRedirectError) throw data;
|
|
101
|
+
return data;
|
|
102
|
+
})
|
|
103
|
+
.catch(handleError);
|
|
104
|
+
}
|
|
105
|
+
case 'query': {
|
|
106
|
+
const input = opts.args[0];
|
|
107
|
+
return await opts
|
|
108
|
+
.invoke({
|
|
109
|
+
type: opts._def.type,
|
|
110
|
+
ctx,
|
|
111
|
+
getRawInput: async () => input,
|
|
112
|
+
path: '',
|
|
113
|
+
input,
|
|
114
|
+
})
|
|
115
|
+
.then((data) => {
|
|
116
|
+
if (data instanceof TRPCRedirectError) throw data;
|
|
117
|
+
return data;
|
|
118
|
+
})
|
|
119
|
+
.catch(handleError);
|
|
120
|
+
}
|
|
121
|
+
default: {
|
|
122
|
+
throw new TRPCError({
|
|
123
|
+
code: 'NOT_IMPLEMENTED',
|
|
124
|
+
message: `Not implemented for type ${opts._def.type}`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { notFound as __notFound } from 'next/navigation';
|
|
2
|
+
import { TRPCError } from '../../@trpc/server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Like `next/navigation`'s `notFound()` but throws a `TRPCError` that later will be handled by Next.js
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export const notFound: typeof __notFound = () => {
|
|
9
|
+
throw new TRPCError({
|
|
10
|
+
code: 'NOT_FOUND',
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RedirectType } from 'next/navigation';
|
|
2
|
+
import { TRPCError } from '../../@trpc/server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export class TRPCRedirectError extends TRPCError {
|
|
8
|
+
public readonly args;
|
|
9
|
+
constructor(url: URL | string, redirectType?: RedirectType) {
|
|
10
|
+
super({
|
|
11
|
+
// TODO(?): This should maybe a custom error code
|
|
12
|
+
code: 'UNPROCESSABLE_CONTENT',
|
|
13
|
+
message: `Redirect error to "${url}" that will be handled by Next.js`,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
this.args = [url.toString(), redirectType] as const;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Like `next/navigation`'s `redirect()` but throws a `TRPCError` that later will be handled by Next.js
|
|
22
|
+
* This provides better typesafety than the `next/navigation`'s `redirect()` since the action continues
|
|
23
|
+
* to execute on the frontend even if Next's `redirect()` has a return type of `never`.
|
|
24
|
+
* @public
|
|
25
|
+
* @remark You should only use this if you're also using `nextAppDirCaller`.
|
|
26
|
+
*/
|
|
27
|
+
export const redirect = (url: URL | string, redirectType?: RedirectType) => {
|
|
28
|
+
// We rethrow this internally so the returntype on the client is undefined.
|
|
29
|
+
return new TRPCRedirectError(url, redirectType) as unknown as undefined;
|
|
30
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isNotFoundError } from 'next/dist/client/components/not-found';
|
|
2
|
+
import { isRedirectError } from 'next/dist/client/components/redirect';
|
|
3
|
+
import {
|
|
4
|
+
notFound as __notFound,
|
|
5
|
+
redirect as __redirect,
|
|
6
|
+
} from 'next/navigation';
|
|
7
|
+
import type { TRPCError } from '../../@trpc/server';
|
|
8
|
+
import { TRPCRedirectError } from './redirect';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Rethrow errors that should be handled by Next.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const rethrowNextErrors = (error: TRPCError) => {
|
|
15
|
+
if (error.code === 'NOT_FOUND') {
|
|
16
|
+
__notFound();
|
|
17
|
+
}
|
|
18
|
+
if (error instanceof TRPCRedirectError) {
|
|
19
|
+
__redirect(...error.args);
|
|
20
|
+
}
|
|
21
|
+
const { cause } = error;
|
|
22
|
+
if (isRedirectError(cause) || isNotFoundError(cause)) {
|
|
23
|
+
throw error.cause;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { inferObservableValue } from '../../observable';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AnyProcedure,
|
|
4
|
+
inferProcedureInput,
|
|
5
|
+
inferProcedureOutput,
|
|
6
|
+
} from '../procedure';
|
|
3
7
|
import type { AnyRouter, RouterRecord } from '../router';
|
|
4
8
|
import type {
|
|
5
9
|
AnyClientTypes,
|
|
@@ -16,16 +20,16 @@ export type inferTransformedProcedureOutput<
|
|
|
16
20
|
TInferrable extends InferrableClientTypes,
|
|
17
21
|
TProcedure extends AnyProcedure,
|
|
18
22
|
> = inferClientTypes<TInferrable>['transformer'] extends false
|
|
19
|
-
? Serialize<TProcedure
|
|
20
|
-
: TProcedure
|
|
23
|
+
? Serialize<inferProcedureOutput<TProcedure>>
|
|
24
|
+
: inferProcedureOutput<TProcedure>;
|
|
21
25
|
/** @internal */
|
|
22
26
|
|
|
23
27
|
export type inferTransformedSubscriptionOutput<
|
|
24
28
|
TInferrable extends InferrableClientTypes,
|
|
25
29
|
TProcedure extends AnyProcedure,
|
|
26
30
|
> = inferClientTypes<TInferrable>['transformer'] extends false
|
|
27
|
-
? Serialize<inferObservableValue<TProcedure
|
|
28
|
-
: inferObservableValue<TProcedure
|
|
31
|
+
? Serialize<inferObservableValue<inferProcedureOutput<TProcedure>>>
|
|
32
|
+
: inferObservableValue<inferProcedureOutput<TProcedure>>;
|
|
29
33
|
|
|
30
34
|
export type GetInferenceHelpers<
|
|
31
35
|
TType extends 'input' | 'output',
|