@trpc/server 9.23.1-alpha.0 → 9.23.3
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/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +1 -1
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +1 -1
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +1 -1
- package/dist/declarations/src/internals/procedure.d.ts.map +1 -1
- package/dist/trpc-server.cjs.dev.js +24 -35
- package/dist/trpc-server.cjs.prod.js +24 -35
- package/dist/trpc-server.esm.js +24 -35
- package/package.json +4 -7
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/internals/procedure.ts +36 -24
- package/dist/declarations/src/internals/wrapCallSafe.d.ts +0 -16
- package/dist/declarations/src/internals/wrapCallSafe.d.ts.map +0 -1
- package/src/internals/wrapCallSafe.ts +0 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.d.ts","sourceRoot":"../../../../src/internals","sources":["procedure.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,
|
|
1
|
+
{"version":3,"file":"procedure.d.ts","sourceRoot":"../../../../src/internals","sources":["procedure.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EACL,kBAAkB,EAGnB,MAAM,eAAe,CAAC;AAIvB,oBAAY,uBAAuB,CAAC,MAAM,EAAE,OAAO,IAAI;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,yBAAyB,CAAC,CAAC,IAAI;IACzC,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,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sB,CAC1B,QAAQ,EACR,KAAK,EACL,MAAM,EACN,YAAY,EACZ,OAAO,EACP,aAAa,CACd,GACA,SAAS,CACV,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACN,YAAY,EACZ,OAAO,EACP,aAAa,CACd,CA0BA;AAED,oBAAY,yBAAyB,CACnC,aAAa,EACb,QAAQ,SAAS,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IACnE,QAAQ,SAAS,sBAAsB,CACzC,MAAM,QAAQ,EACd,MAAM,KAAK,EACX,MAAM,MAAM,EACZ,MAAM,YAAY,EAClB,MAAM,OAAO,EACb,MAAM,aAAa,CACpB,GACG,SAAS,CACP,aAAa,EACb,QAAQ,EACR,KAAK,EACL,OAAO,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,EAC3C,OAAO,SAAS,YAAY,GAAG,SAAS,GAAG,YAAY,EACvD,OAAO,EACP,aAAa,CACd,GACD,KAAK,CAAC"}
|
|
@@ -40,25 +40,6 @@ const requestHandler = nodeHTTPRequestHandler.nodeHTTPRequestHandler;
|
|
|
40
40
|
|
|
41
41
|
const middlewareMarker = /*#__PURE__*/Symbol('middlewareMarker');
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* Wrap a function in a safe wrapper that never throws
|
|
45
|
-
* Returns a discriminated union
|
|
46
|
-
*/
|
|
47
|
-
async function wrapCallSafe(fn) {
|
|
48
|
-
try {
|
|
49
|
-
const data = await fn();
|
|
50
|
-
return {
|
|
51
|
-
ok: true,
|
|
52
|
-
data
|
|
53
|
-
};
|
|
54
|
-
} catch (cause) {
|
|
55
|
-
return {
|
|
56
|
-
ok: false,
|
|
57
|
-
error: cause
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
43
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
63
44
|
resolveHTTPResponse.assertNotBrowser();
|
|
64
45
|
|
|
@@ -160,31 +141,39 @@ class Procedure {
|
|
|
160
141
|
data,
|
|
161
142
|
ctx
|
|
162
143
|
};
|
|
163
|
-
}]); //
|
|
144
|
+
}]); // run the middlewares recursively with the resolver as the last one
|
|
164
145
|
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
146
|
+
const callRecursive = async (callOpts = {
|
|
147
|
+
index: 0,
|
|
148
|
+
ctx: opts.ctx
|
|
149
|
+
}) => {
|
|
150
|
+
try {
|
|
151
|
+
const result = await middlewaresWithResolver[callOpts.index]({
|
|
152
|
+
ctx: callOpts.ctx,
|
|
169
153
|
type: opts.type,
|
|
170
154
|
path: opts.path,
|
|
171
155
|
rawInput: opts.rawInput,
|
|
172
156
|
meta: this.meta,
|
|
173
|
-
next:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
157
|
+
next: async nextOpts => {
|
|
158
|
+
return await callRecursive({
|
|
159
|
+
index: callOpts.index + 1,
|
|
160
|
+
ctx: nextOpts ? nextOpts.ctx : callOpts.ctx
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return result;
|
|
165
|
+
} catch (cause) {
|
|
180
166
|
return {
|
|
167
|
+
ctx: callOpts.ctx,
|
|
181
168
|
ok: false,
|
|
182
|
-
error: transformTRPCResponse.getErrorFromUnknown(
|
|
169
|
+
error: transformTRPCResponse.getErrorFromUnknown(cause),
|
|
170
|
+
marker: middlewareMarker
|
|
183
171
|
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
172
|
+
}
|
|
173
|
+
}; // there's always at least one "next" since we wrap this.resolver in a middleware
|
|
174
|
+
|
|
186
175
|
|
|
187
|
-
const result = await
|
|
176
|
+
const result = await callRecursive();
|
|
188
177
|
|
|
189
178
|
if (!result) {
|
|
190
179
|
throw new transformTRPCResponse.TRPCError({
|
|
@@ -40,25 +40,6 @@ const requestHandler = nodeHTTPRequestHandler.nodeHTTPRequestHandler;
|
|
|
40
40
|
|
|
41
41
|
const middlewareMarker = /*#__PURE__*/Symbol('middlewareMarker');
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* Wrap a function in a safe wrapper that never throws
|
|
45
|
-
* Returns a discriminated union
|
|
46
|
-
*/
|
|
47
|
-
async function wrapCallSafe(fn) {
|
|
48
|
-
try {
|
|
49
|
-
const data = await fn();
|
|
50
|
-
return {
|
|
51
|
-
ok: true,
|
|
52
|
-
data
|
|
53
|
-
};
|
|
54
|
-
} catch (cause) {
|
|
55
|
-
return {
|
|
56
|
-
ok: false,
|
|
57
|
-
error: cause
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
43
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
63
44
|
resolveHTTPResponse.assertNotBrowser();
|
|
64
45
|
|
|
@@ -160,31 +141,39 @@ class Procedure {
|
|
|
160
141
|
data,
|
|
161
142
|
ctx
|
|
162
143
|
};
|
|
163
|
-
}]); //
|
|
144
|
+
}]); // run the middlewares recursively with the resolver as the last one
|
|
164
145
|
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
146
|
+
const callRecursive = async (callOpts = {
|
|
147
|
+
index: 0,
|
|
148
|
+
ctx: opts.ctx
|
|
149
|
+
}) => {
|
|
150
|
+
try {
|
|
151
|
+
const result = await middlewaresWithResolver[callOpts.index]({
|
|
152
|
+
ctx: callOpts.ctx,
|
|
169
153
|
type: opts.type,
|
|
170
154
|
path: opts.path,
|
|
171
155
|
rawInput: opts.rawInput,
|
|
172
156
|
meta: this.meta,
|
|
173
|
-
next:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
157
|
+
next: async nextOpts => {
|
|
158
|
+
return await callRecursive({
|
|
159
|
+
index: callOpts.index + 1,
|
|
160
|
+
ctx: nextOpts ? nextOpts.ctx : callOpts.ctx
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return result;
|
|
165
|
+
} catch (cause) {
|
|
180
166
|
return {
|
|
167
|
+
ctx: callOpts.ctx,
|
|
181
168
|
ok: false,
|
|
182
|
-
error: transformTRPCResponse.getErrorFromUnknown(
|
|
169
|
+
error: transformTRPCResponse.getErrorFromUnknown(cause),
|
|
170
|
+
marker: middlewareMarker
|
|
183
171
|
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
172
|
+
}
|
|
173
|
+
}; // there's always at least one "next" since we wrap this.resolver in a middleware
|
|
174
|
+
|
|
186
175
|
|
|
187
|
-
const result = await
|
|
176
|
+
const result = await callRecursive();
|
|
188
177
|
|
|
189
178
|
if (!result) {
|
|
190
179
|
throw new transformTRPCResponse.TRPCError({
|
package/dist/trpc-server.esm.js
CHANGED
|
@@ -38,25 +38,6 @@ const requestHandler = nodeHTTPRequestHandler;
|
|
|
38
38
|
|
|
39
39
|
const middlewareMarker = /*#__PURE__*/Symbol('middlewareMarker');
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
* Wrap a function in a safe wrapper that never throws
|
|
43
|
-
* Returns a discriminated union
|
|
44
|
-
*/
|
|
45
|
-
async function wrapCallSafe(fn) {
|
|
46
|
-
try {
|
|
47
|
-
const data = await fn();
|
|
48
|
-
return {
|
|
49
|
-
ok: true,
|
|
50
|
-
data
|
|
51
|
-
};
|
|
52
|
-
} catch (cause) {
|
|
53
|
-
return {
|
|
54
|
-
ok: false,
|
|
55
|
-
error: cause
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
41
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
61
42
|
assertNotBrowser();
|
|
62
43
|
|
|
@@ -158,31 +139,39 @@ class Procedure {
|
|
|
158
139
|
data,
|
|
159
140
|
ctx
|
|
160
141
|
};
|
|
161
|
-
}]); //
|
|
142
|
+
}]); // run the middlewares recursively with the resolver as the last one
|
|
162
143
|
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
144
|
+
const callRecursive = async (callOpts = {
|
|
145
|
+
index: 0,
|
|
146
|
+
ctx: opts.ctx
|
|
147
|
+
}) => {
|
|
148
|
+
try {
|
|
149
|
+
const result = await middlewaresWithResolver[callOpts.index]({
|
|
150
|
+
ctx: callOpts.ctx,
|
|
167
151
|
type: opts.type,
|
|
168
152
|
path: opts.path,
|
|
169
153
|
rawInput: opts.rawInput,
|
|
170
154
|
meta: this.meta,
|
|
171
|
-
next:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
155
|
+
next: async nextOpts => {
|
|
156
|
+
return await callRecursive({
|
|
157
|
+
index: callOpts.index + 1,
|
|
158
|
+
ctx: nextOpts ? nextOpts.ctx : callOpts.ctx
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
} catch (cause) {
|
|
178
164
|
return {
|
|
165
|
+
ctx: callOpts.ctx,
|
|
179
166
|
ok: false,
|
|
180
|
-
error: getErrorFromUnknown(
|
|
167
|
+
error: getErrorFromUnknown(cause),
|
|
168
|
+
marker: middlewareMarker
|
|
181
169
|
};
|
|
182
|
-
}
|
|
183
|
-
}
|
|
170
|
+
}
|
|
171
|
+
}; // there's always at least one "next" since we wrap this.resolver in a middleware
|
|
172
|
+
|
|
184
173
|
|
|
185
|
-
const result = await
|
|
174
|
+
const result = await callRecursive();
|
|
186
175
|
|
|
187
176
|
if (!result) {
|
|
188
177
|
throw new TRPCError({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "9.23.
|
|
3
|
+
"version": "9.23.3",
|
|
4
4
|
"description": "tRPC Server",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,9 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@testing-library/react": "^12.0.0",
|
|
51
|
-
"@testing-library/user-event": "^14.1.0",
|
|
49
|
+
"@fastify/websocket": "^5.0.0",
|
|
52
50
|
"@types/express": "^4.17.12",
|
|
53
51
|
"@types/hash-sum": "^1.0.0",
|
|
54
52
|
"@types/ws": "^8.2.0",
|
|
@@ -57,12 +55,11 @@
|
|
|
57
55
|
"express": "^4.17.1",
|
|
58
56
|
"fastify": "^3.27.1",
|
|
59
57
|
"fastify-plugin": "^3.0.1",
|
|
60
|
-
"fastify-websocket": "^4.0.0",
|
|
61
58
|
"hash-sum": "^2.0.0",
|
|
62
59
|
"jest": "^27.1.0",
|
|
63
60
|
"konn": "^0.7.0",
|
|
64
61
|
"myzod": "^1.3.1",
|
|
65
|
-
"next": "12.1.
|
|
62
|
+
"next": "^12.1.6",
|
|
66
63
|
"node-fetch": "^2.6.1",
|
|
67
64
|
"superstruct": "^0.15.2",
|
|
68
65
|
"typescript": "4.4.4",
|
|
@@ -70,5 +67,5 @@
|
|
|
70
67
|
"yup": "^0.32.8",
|
|
71
68
|
"zod": "^3.0.0"
|
|
72
69
|
},
|
|
73
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5de8a73b07339a578675a2c479dcb8621f06b3a6"
|
|
74
71
|
}
|
|
@@ -4,8 +4,11 @@ import { assertNotBrowser } from '../assertNotBrowser';
|
|
|
4
4
|
import { ProcedureType } from '../router';
|
|
5
5
|
import { InferLast } from '../types';
|
|
6
6
|
import { getErrorFromUnknown } from './errors';
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
MiddlewareFunction,
|
|
9
|
+
MiddlewareResult,
|
|
10
|
+
middlewareMarker,
|
|
11
|
+
} from './middlewares';
|
|
9
12
|
|
|
10
13
|
assertNotBrowser();
|
|
11
14
|
|
|
@@ -167,7 +170,7 @@ export class Procedure<
|
|
|
167
170
|
): Promise<TFinalOutput> {
|
|
168
171
|
// wrap the actual resolver and treat as the last "middleware"
|
|
169
172
|
const middlewaresWithResolver = this.middlewares.concat([
|
|
170
|
-
async ({ ctx }: { ctx:
|
|
173
|
+
async ({ ctx }: { ctx: any }) => {
|
|
171
174
|
const input = await this.parseInput(opts.rawInput);
|
|
172
175
|
const rawOutput = await this.resolver({
|
|
173
176
|
...opts,
|
|
@@ -184,31 +187,40 @@ export class Procedure<
|
|
|
184
187
|
},
|
|
185
188
|
]);
|
|
186
189
|
|
|
187
|
-
//
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
190
|
+
// run the middlewares recursively with the resolver as the last one
|
|
191
|
+
const callRecursive = async (
|
|
192
|
+
callOpts: { ctx: any; index: number } = {
|
|
193
|
+
index: 0,
|
|
194
|
+
ctx: opts.ctx,
|
|
195
|
+
},
|
|
196
|
+
): Promise<MiddlewareResult<any>> => {
|
|
197
|
+
try {
|
|
198
|
+
const result = await middlewaresWithResolver[callOpts.index]({
|
|
199
|
+
ctx: callOpts.ctx,
|
|
200
|
+
type: opts.type,
|
|
201
|
+
path: opts.path,
|
|
202
|
+
rawInput: opts.rawInput,
|
|
203
|
+
meta: this.meta,
|
|
204
|
+
next: async (nextOpts?: { ctx: any }) => {
|
|
205
|
+
return await callRecursive({
|
|
206
|
+
index: callOpts.index + 1,
|
|
207
|
+
ctx: nextOpts ? nextOpts.ctx : callOpts.ctx,
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
return result;
|
|
212
|
+
} catch (cause) {
|
|
203
213
|
return {
|
|
204
|
-
|
|
205
|
-
|
|
214
|
+
ctx: callOpts.ctx,
|
|
215
|
+
ok: false,
|
|
216
|
+
error: getErrorFromUnknown(cause),
|
|
217
|
+
marker: middlewareMarker,
|
|
206
218
|
};
|
|
207
|
-
}
|
|
208
|
-
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
209
221
|
|
|
210
222
|
// there's always at least one "next" since we wrap this.resolver in a middleware
|
|
211
|
-
const result = await
|
|
223
|
+
const result = await callRecursive();
|
|
212
224
|
if (!result) {
|
|
213
225
|
throw new TRPCError({
|
|
214
226
|
code: 'INTERNAL_SERVER_ERROR',
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare type AsyncFn<T> = () => Promise<T> | T;
|
|
2
|
-
/**
|
|
3
|
-
* Wrap a function in a safe wrapper that never throws
|
|
4
|
-
* Returns a discriminated union
|
|
5
|
-
*/
|
|
6
|
-
export declare function wrapCallSafe<T>(fn: AsyncFn<T>): Promise<{
|
|
7
|
-
ok: true;
|
|
8
|
-
data: T;
|
|
9
|
-
error?: undefined;
|
|
10
|
-
} | {
|
|
11
|
-
ok: false;
|
|
12
|
-
error: unknown;
|
|
13
|
-
data?: undefined;
|
|
14
|
-
}>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=wrapCallSafe.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapCallSafe.d.ts","sourceRoot":"../../../../src/internals","sources":["wrapCallSafe.ts"],"names":[],"mappings":"AAAA,aAAK,OAAO,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACvC;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;;;;;;;;GAanD"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
type AsyncFn<T> = () => Promise<T> | T;
|
|
2
|
-
/**
|
|
3
|
-
* Wrap a function in a safe wrapper that never throws
|
|
4
|
-
* Returns a discriminated union
|
|
5
|
-
*/
|
|
6
|
-
export async function wrapCallSafe<T>(fn: AsyncFn<T>) {
|
|
7
|
-
try {
|
|
8
|
-
const data = await fn();
|
|
9
|
-
return {
|
|
10
|
-
ok: true as const,
|
|
11
|
-
data,
|
|
12
|
-
};
|
|
13
|
-
} catch (cause) {
|
|
14
|
-
return {
|
|
15
|
-
ok: false as const,
|
|
16
|
-
error: cause,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|