@trpc/server 10.0.0-proxy-beta.14 → 10.0.0-proxy-beta.16
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/adapters/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +24 -18
- package/dist/adapters/aws-lambda/index.mjs +20 -20
- package/dist/adapters/aws-lambda/utils.d.ts +4 -1
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +4 -4
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/index.mjs +3 -3
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/next.js +3 -3
- package/dist/adapters/next.mjs +4 -4
- package/dist/adapters/node-http/index.js +3 -3
- package/dist/adapters/node-http/index.mjs +4 -4
- package/dist/adapters/node-http/types.d.ts +3 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.js +3 -3
- package/dist/adapters/standalone.mjs +4 -4
- package/dist/adapters/ws.js +2 -2
- package/dist/adapters/ws.mjs +3 -3
- package/dist/core/initTRPC.d.ts +22 -28
- package/dist/core/initTRPC.d.ts.map +1 -1
- package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +40 -100
- package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +1 -1
- package/dist/core/internals/config.d.ts +33 -11
- package/dist/core/internals/config.d.ts.map +1 -1
- package/dist/core/internals/mergeRouters.d.ts.map +1 -1
- package/dist/core/internals/procedureBuilder.d.ts +16 -21
- package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +10 -18
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/procedure.d.ts +2 -13
- package/dist/core/procedure.d.ts.map +1 -1
- package/dist/core/router.d.ts +26 -40
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.d.ts.map +1 -1
- package/dist/deprecated/interop.d.ts +18 -13
- package/dist/deprecated/interop.d.ts.map +1 -1
- package/dist/error/TRPCError.d.ts +1 -1
- package/dist/http/internals/types.d.ts +3 -3
- package/dist/http/internals/types.d.ts.map +1 -1
- package/dist/{index-5a6a2e91.mjs → index-0332d528.mjs} +1 -1
- package/dist/index.js +53 -30
- package/dist/index.mjs +51 -28
- package/dist/internals/transformTRPCResponse.d.ts.map +1 -1
- package/dist/internals/types.d.ts +2 -3
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-efc38711.js → nodeHTTPRequestHandler-0e40a231.js} +1 -1
- package/dist/{nodeHTTPRequestHandler-205f7545.mjs → nodeHTTPRequestHandler-bb607c2b.mjs} +1 -1
- package/dist/{resolveHTTPResponse-bf4c6ceb.js → resolveHTTPResponse-92daf326.js} +2 -2
- package/dist/{resolveHTTPResponse-4ceb1785.mjs → resolveHTTPResponse-9dff3dcc.mjs} +2 -2
- package/dist/shared/index.mjs +1 -1
- package/dist/{transformTRPCResponse-959de787.mjs → transformTRPCResponse-23e99f82.mjs} +20 -40
- package/dist/{transformTRPCResponse-05aa84c1.js → transformTRPCResponse-92c79c47.js} +18 -39
- package/package.json +7 -7
- package/src/adapters/aws-lambda/index.ts +5 -54
- package/src/adapters/aws-lambda/utils.ts +59 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +2 -2
- package/src/adapters/node-http/types.ts +3 -2
- package/src/adapters/ws.ts +1 -1
- package/src/core/initTRPC.ts +48 -38
- package/src/core/internals/__generated__/mergeRoutersGeneric.ts +40 -100
- package/src/core/internals/config.ts +35 -15
- package/src/core/internals/mergeRouters.ts +19 -7
- package/src/core/internals/procedureBuilder.ts +31 -34
- package/src/core/middleware.ts +7 -9
- package/src/core/procedure.ts +2 -15
- package/src/core/router.ts +56 -92
- package/src/core/types.ts +3 -3
- package/src/deprecated/interop.ts +49 -39
- package/src/http/internals/types.ts +8 -3
- package/src/http/resolveHTTPResponse.ts +1 -1
- package/src/internals/transformTRPCResponse.ts +4 -2
- package/src/internals/types.ts +2 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var transformTRPCResponse = require('./transformTRPCResponse-
|
|
3
|
+
var transformTRPCResponse = require('./transformTRPCResponse-92c79c47.js');
|
|
4
4
|
var TRPCError = require('./TRPCError-fe9113e5.js');
|
|
5
5
|
|
|
6
6
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
@@ -94,7 +94,7 @@ async function resolveHTTPResponse(opts) {
|
|
|
94
94
|
];
|
|
95
95
|
ctx = await createContext();
|
|
96
96
|
const deserializeInputValue = (rawValue)=>{
|
|
97
|
-
return typeof rawValue !== 'undefined' ? router._def.transformer.input.deserialize(rawValue) : rawValue;
|
|
97
|
+
return typeof rawValue !== 'undefined' ? router._def._config.transformer.input.deserialize(rawValue) : rawValue;
|
|
98
98
|
};
|
|
99
99
|
const getInputs = ()=>{
|
|
100
100
|
if (!isBatchCall) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as callProcedure, f as getHTTPStatusCode, t as transformTRPCResponse } from './transformTRPCResponse-
|
|
1
|
+
import { e as callProcedure, f as getHTTPStatusCode, t as transformTRPCResponse } from './transformTRPCResponse-23e99f82.mjs';
|
|
2
2
|
import { T as TRPCError, a as getTRPCErrorFromUnknown, g as getCauseFromUnknown } from './TRPCError-e99e7cbe.mjs';
|
|
3
3
|
|
|
4
4
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
@@ -92,7 +92,7 @@ async function resolveHTTPResponse(opts) {
|
|
|
92
92
|
];
|
|
93
93
|
ctx = await createContext();
|
|
94
94
|
const deserializeInputValue = (rawValue)=>{
|
|
95
|
-
return typeof rawValue !== 'undefined' ? router._def.transformer.input.deserialize(rawValue) : rawValue;
|
|
95
|
+
return typeof rawValue !== 'undefined' ? router._def._config.transformer.input.deserialize(rawValue) : rawValue;
|
|
96
96
|
};
|
|
97
97
|
const getInputs = ()=>{
|
|
98
98
|
if (!isBatchCall) {
|
package/dist/shared/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { c as createFlatProxy, a as createRecursiveProxy } from '../index-0332d528.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { T as TRPCError } from './TRPCError-e99e7cbe.mjs';
|
|
2
2
|
import { i as invert, T as TRPC_ERROR_CODES_BY_KEY } from './codes-7d21f749.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { a as createRecursiveProxy } from './index-0332d528.mjs';
|
|
4
4
|
|
|
5
5
|
const defaultFormatter = ({ shape })=>{
|
|
6
6
|
return shape;
|
|
@@ -78,21 +78,6 @@ function getHTTPStatusCodeFromError(error) {
|
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
/**
|
|
82
|
-
* Ensures there are no duplicate keys when building a procedure.
|
|
83
|
-
*/ function mergeWithoutOverrides(obj1, ...objs) {
|
|
84
|
-
const newObj = Object.assign(Object.create(null), obj1);
|
|
85
|
-
for (const overrides of objs){
|
|
86
|
-
for(const key in overrides){
|
|
87
|
-
if (key in newObj && newObj[key] !== overrides[key]) {
|
|
88
|
-
throw new Error(`Duplicate key ${key}`);
|
|
89
|
-
}
|
|
90
|
-
newObj[key] = overrides[key];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return newObj;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
81
|
/**
|
|
97
82
|
* Create an object without inheriting anything from `Object.prototype`
|
|
98
83
|
* @internal
|
|
@@ -129,9 +114,9 @@ const emptyRouter = {
|
|
|
129
114
|
];
|
|
130
115
|
/**
|
|
131
116
|
* @internal
|
|
132
|
-
*/ function createRouterFactory(
|
|
133
|
-
return function createRouterInner(
|
|
134
|
-
const reservedWordsUsed = new Set(Object.keys(
|
|
117
|
+
*/ function createRouterFactory(config) {
|
|
118
|
+
return function createRouterInner(procedures) {
|
|
119
|
+
const reservedWordsUsed = new Set(Object.keys(procedures).filter((v)=>reservedWords.includes(v)));
|
|
135
120
|
if (reservedWordsUsed.size > 0) {
|
|
136
121
|
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
137
122
|
}
|
|
@@ -143,40 +128,35 @@ const emptyRouter = {
|
|
|
143
128
|
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
144
129
|
continue;
|
|
145
130
|
}
|
|
131
|
+
if (routerProcedures[newPath]) {
|
|
132
|
+
throw new Error(`Duplicate key: ${newPath}`);
|
|
133
|
+
}
|
|
146
134
|
routerProcedures[newPath] = procedureOrRouter;
|
|
147
135
|
}
|
|
148
136
|
}
|
|
149
|
-
recursiveGetPaths(
|
|
150
|
-
const result = mergeWithoutOverrides({
|
|
151
|
-
transformer: defaults?.transformer ?? defaultTransformer,
|
|
152
|
-
errorFormatter: defaults?.errorFormatter ?? defaultFormatter
|
|
153
|
-
}, {
|
|
154
|
-
procedures: routerProcedures
|
|
155
|
-
});
|
|
137
|
+
recursiveGetPaths(procedures);
|
|
156
138
|
const _def = {
|
|
139
|
+
_config: config,
|
|
157
140
|
router: true,
|
|
158
|
-
procedures:
|
|
141
|
+
procedures: routerProcedures,
|
|
159
142
|
...emptyRouter,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
queries: Object.entries(result.procedures || {}).filter((pair)=>pair[1]._def.query).reduce((acc, [key, val])=>({
|
|
143
|
+
record: procedures,
|
|
144
|
+
queries: Object.entries(routerProcedures || {}).filter((pair)=>pair[1]._def.query).reduce((acc, [key, val])=>({
|
|
163
145
|
...acc,
|
|
164
146
|
[key]: val
|
|
165
147
|
}), {}),
|
|
166
|
-
mutations: Object.entries(
|
|
148
|
+
mutations: Object.entries(routerProcedures || {}).filter((pair)=>pair[1]._def.mutation).reduce((acc, [key, val])=>({
|
|
167
149
|
...acc,
|
|
168
150
|
[key]: val
|
|
169
151
|
}), {}),
|
|
170
|
-
subscriptions: Object.entries(
|
|
152
|
+
subscriptions: Object.entries(routerProcedures || {}).filter((pair)=>pair[1]._def.subscription).reduce((acc, [key, val])=>({
|
|
171
153
|
...acc,
|
|
172
154
|
[key]: val
|
|
173
155
|
}), {})
|
|
174
156
|
};
|
|
175
157
|
const router = {
|
|
176
|
-
...
|
|
158
|
+
...procedures,
|
|
177
159
|
_def,
|
|
178
|
-
transformer: _def.transformer,
|
|
179
|
-
errorFormatter: _def.errorFormatter,
|
|
180
160
|
createCaller (ctx) {
|
|
181
161
|
const proxy = createRecursiveProxy(({ path , args })=>{
|
|
182
162
|
// interop mode
|
|
@@ -217,13 +197,13 @@ const emptyRouter = {
|
|
|
217
197
|
httpStatus: getHTTPStatusCodeFromError(error)
|
|
218
198
|
}
|
|
219
199
|
};
|
|
220
|
-
if (
|
|
200
|
+
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
221
201
|
shape.data.stack = opts.error.stack;
|
|
222
202
|
}
|
|
223
203
|
if (typeof path === 'string') {
|
|
224
204
|
shape.data.path = path;
|
|
225
205
|
}
|
|
226
|
-
return this._def.errorFormatter({
|
|
206
|
+
return this._def._config.errorFormatter({
|
|
227
207
|
...opts,
|
|
228
208
|
shape
|
|
229
209
|
});
|
|
@@ -254,7 +234,7 @@ function transformTRPCResponseItem(router, item) {
|
|
|
254
234
|
if ('error' in item) {
|
|
255
235
|
return {
|
|
256
236
|
...item,
|
|
257
|
-
error: router._def.transformer.output.serialize(item.error)
|
|
237
|
+
error: router._def._config.transformer.output.serialize(item.error)
|
|
258
238
|
};
|
|
259
239
|
}
|
|
260
240
|
if ('data' in item.result) {
|
|
@@ -262,7 +242,7 @@ function transformTRPCResponseItem(router, item) {
|
|
|
262
242
|
...item,
|
|
263
243
|
result: {
|
|
264
244
|
...item.result,
|
|
265
|
-
data: router._def.transformer.output.serialize(item.result.data)
|
|
245
|
+
data: router._def._config.transformer.output.serialize(item.result.data)
|
|
266
246
|
}
|
|
267
247
|
};
|
|
268
248
|
}
|
|
@@ -274,4 +254,4 @@ function transformTRPCResponseItem(router, item) {
|
|
|
274
254
|
return Array.isArray(itemOrItems) ? itemOrItems.map((item)=>transformTRPCResponseItem(router, item)) : transformTRPCResponseItem(router, itemOrItems);
|
|
275
255
|
}
|
|
276
256
|
|
|
277
|
-
export { defaultTransformer as a, getHTTPStatusCodeFromError as b, createRouterFactory as c, defaultFormatter as d, callProcedure as e, getHTTPStatusCode as f, getDataTransformer as g, isServerDefault as i,
|
|
257
|
+
export { defaultTransformer as a, getHTTPStatusCodeFromError as b, createRouterFactory as c, defaultFormatter as d, callProcedure as e, getHTTPStatusCode as f, getDataTransformer as g, isServerDefault as i, procedureTypes as p, transformTRPCResponse as t };
|
|
@@ -80,21 +80,6 @@ function getHTTPStatusCodeFromError(error) {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* Ensures there are no duplicate keys when building a procedure.
|
|
85
|
-
*/ function mergeWithoutOverrides(obj1, ...objs) {
|
|
86
|
-
const newObj = Object.assign(Object.create(null), obj1);
|
|
87
|
-
for (const overrides of objs){
|
|
88
|
-
for(const key in overrides){
|
|
89
|
-
if (key in newObj && newObj[key] !== overrides[key]) {
|
|
90
|
-
throw new Error(`Duplicate key ${key}`);
|
|
91
|
-
}
|
|
92
|
-
newObj[key] = overrides[key];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return newObj;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
83
|
/**
|
|
99
84
|
* Create an object without inheriting anything from `Object.prototype`
|
|
100
85
|
* @internal
|
|
@@ -131,9 +116,9 @@ const emptyRouter = {
|
|
|
131
116
|
];
|
|
132
117
|
/**
|
|
133
118
|
* @internal
|
|
134
|
-
*/ function createRouterFactory(
|
|
135
|
-
return function createRouterInner(
|
|
136
|
-
const reservedWordsUsed = new Set(Object.keys(
|
|
119
|
+
*/ function createRouterFactory(config) {
|
|
120
|
+
return function createRouterInner(procedures) {
|
|
121
|
+
const reservedWordsUsed = new Set(Object.keys(procedures).filter((v)=>reservedWords.includes(v)));
|
|
137
122
|
if (reservedWordsUsed.size > 0) {
|
|
138
123
|
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
139
124
|
}
|
|
@@ -145,40 +130,35 @@ const emptyRouter = {
|
|
|
145
130
|
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
146
131
|
continue;
|
|
147
132
|
}
|
|
133
|
+
if (routerProcedures[newPath]) {
|
|
134
|
+
throw new Error(`Duplicate key: ${newPath}`);
|
|
135
|
+
}
|
|
148
136
|
routerProcedures[newPath] = procedureOrRouter;
|
|
149
137
|
}
|
|
150
138
|
}
|
|
151
|
-
recursiveGetPaths(
|
|
152
|
-
const result = mergeWithoutOverrides({
|
|
153
|
-
transformer: defaults?.transformer ?? defaultTransformer,
|
|
154
|
-
errorFormatter: defaults?.errorFormatter ?? defaultFormatter
|
|
155
|
-
}, {
|
|
156
|
-
procedures: routerProcedures
|
|
157
|
-
});
|
|
139
|
+
recursiveGetPaths(procedures);
|
|
158
140
|
const _def = {
|
|
141
|
+
_config: config,
|
|
159
142
|
router: true,
|
|
160
|
-
procedures:
|
|
143
|
+
procedures: routerProcedures,
|
|
161
144
|
...emptyRouter,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
queries: Object.entries(result.procedures || {}).filter((pair)=>pair[1]._def.query).reduce((acc, [key, val])=>({
|
|
145
|
+
record: procedures,
|
|
146
|
+
queries: Object.entries(routerProcedures || {}).filter((pair)=>pair[1]._def.query).reduce((acc, [key, val])=>({
|
|
165
147
|
...acc,
|
|
166
148
|
[key]: val
|
|
167
149
|
}), {}),
|
|
168
|
-
mutations: Object.entries(
|
|
150
|
+
mutations: Object.entries(routerProcedures || {}).filter((pair)=>pair[1]._def.mutation).reduce((acc, [key, val])=>({
|
|
169
151
|
...acc,
|
|
170
152
|
[key]: val
|
|
171
153
|
}), {}),
|
|
172
|
-
subscriptions: Object.entries(
|
|
154
|
+
subscriptions: Object.entries(routerProcedures || {}).filter((pair)=>pair[1]._def.subscription).reduce((acc, [key, val])=>({
|
|
173
155
|
...acc,
|
|
174
156
|
[key]: val
|
|
175
157
|
}), {})
|
|
176
158
|
};
|
|
177
159
|
const router = {
|
|
178
|
-
...
|
|
160
|
+
...procedures,
|
|
179
161
|
_def,
|
|
180
|
-
transformer: _def.transformer,
|
|
181
|
-
errorFormatter: _def.errorFormatter,
|
|
182
162
|
createCaller (ctx) {
|
|
183
163
|
const proxy = index.createRecursiveProxy(({ path , args })=>{
|
|
184
164
|
// interop mode
|
|
@@ -219,13 +199,13 @@ const emptyRouter = {
|
|
|
219
199
|
httpStatus: getHTTPStatusCodeFromError(error)
|
|
220
200
|
}
|
|
221
201
|
};
|
|
222
|
-
if (
|
|
202
|
+
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
223
203
|
shape.data.stack = opts.error.stack;
|
|
224
204
|
}
|
|
225
205
|
if (typeof path === 'string') {
|
|
226
206
|
shape.data.path = path;
|
|
227
207
|
}
|
|
228
|
-
return this._def.errorFormatter({
|
|
208
|
+
return this._def._config.errorFormatter({
|
|
229
209
|
...opts,
|
|
230
210
|
shape
|
|
231
211
|
});
|
|
@@ -256,7 +236,7 @@ function transformTRPCResponseItem(router, item) {
|
|
|
256
236
|
if ('error' in item) {
|
|
257
237
|
return {
|
|
258
238
|
...item,
|
|
259
|
-
error: router._def.transformer.output.serialize(item.error)
|
|
239
|
+
error: router._def._config.transformer.output.serialize(item.error)
|
|
260
240
|
};
|
|
261
241
|
}
|
|
262
242
|
if ('data' in item.result) {
|
|
@@ -264,7 +244,7 @@ function transformTRPCResponseItem(router, item) {
|
|
|
264
244
|
...item,
|
|
265
245
|
result: {
|
|
266
246
|
...item.result,
|
|
267
|
-
data: router._def.transformer.output.serialize(item.result.data)
|
|
247
|
+
data: router._def._config.transformer.output.serialize(item.result.data)
|
|
268
248
|
}
|
|
269
249
|
};
|
|
270
250
|
}
|
|
@@ -284,6 +264,5 @@ exports.getDataTransformer = getDataTransformer;
|
|
|
284
264
|
exports.getHTTPStatusCode = getHTTPStatusCode;
|
|
285
265
|
exports.getHTTPStatusCodeFromError = getHTTPStatusCodeFromError;
|
|
286
266
|
exports.isServerDefault = isServerDefault;
|
|
287
|
-
exports.mergeWithoutOverrides = mergeWithoutOverrides;
|
|
288
267
|
exports.procedureTypes = procedureTypes;
|
|
289
268
|
exports.transformTRPCResponse = transformTRPCResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "10.0.0-proxy-beta.
|
|
3
|
+
"version": "10.0.0-proxy-beta.16",
|
|
4
4
|
"description": "tRPC Server",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -122,10 +122,10 @@
|
|
|
122
122
|
"@testing-library/jest-dom": "^5.16.5",
|
|
123
123
|
"@testing-library/react": "^13.4.0",
|
|
124
124
|
"@testing-library/user-event": "^14.4.3",
|
|
125
|
-
"@trpc/client": "10.0.0-proxy-beta.
|
|
126
|
-
"@trpc/next": "10.0.0-proxy-beta.
|
|
127
|
-
"@trpc/react": "10.0.0-proxy-beta.
|
|
128
|
-
"@trpc/server": "10.0.0-proxy-beta.
|
|
125
|
+
"@trpc/client": "10.0.0-proxy-beta.16",
|
|
126
|
+
"@trpc/next": "10.0.0-proxy-beta.16",
|
|
127
|
+
"@trpc/react": "10.0.0-proxy-beta.16",
|
|
128
|
+
"@trpc/server": "10.0.0-proxy-beta.16",
|
|
129
129
|
"@types/aws-lambda": "^8.10.97",
|
|
130
130
|
"@types/express": "^4.17.12",
|
|
131
131
|
"@types/hash-sum": "^1.0.0",
|
|
@@ -154,12 +154,12 @@
|
|
|
154
154
|
"react": "^18.2.0",
|
|
155
155
|
"react-dom": "^18.2.0",
|
|
156
156
|
"superjson": "^1.7.4",
|
|
157
|
-
"superstruct": "^0.
|
|
157
|
+
"superstruct": "^0.16.0",
|
|
158
158
|
"ts-jest": "^27.0.5",
|
|
159
159
|
"typescript": "^4.8.3",
|
|
160
160
|
"ws": "^8.0.0",
|
|
161
161
|
"yup": "^0.32.8",
|
|
162
162
|
"zod": "^3.0.0"
|
|
163
163
|
},
|
|
164
|
-
"gitHead": "
|
|
164
|
+
"gitHead": "4e001688fbdd7de848beb431a343a08c9659618a"
|
|
165
165
|
}
|
|
@@ -7,18 +7,21 @@ import type {
|
|
|
7
7
|
} from 'aws-lambda';
|
|
8
8
|
import { TRPCError, resolveHTTPResponse } from '../..';
|
|
9
9
|
import { AnyRouter, inferRouterContext } from '../../core';
|
|
10
|
-
import {
|
|
10
|
+
import { HTTPRequest } from '../../http/internals/types';
|
|
11
11
|
import type { HTTPResponse } from '../../http/internals/types';
|
|
12
12
|
import {
|
|
13
13
|
APIGatewayEvent,
|
|
14
14
|
APIGatewayResult,
|
|
15
15
|
AWSLambdaOptions,
|
|
16
16
|
UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
17
|
+
getHTTPMethod,
|
|
18
|
+
getPath,
|
|
17
19
|
isPayloadV1,
|
|
18
20
|
isPayloadV2,
|
|
21
|
+
transformHeaders,
|
|
19
22
|
} from './utils';
|
|
20
23
|
|
|
21
|
-
export
|
|
24
|
+
export * from './utils';
|
|
22
25
|
|
|
23
26
|
function lambdaEventToHTTPRequest(event: APIGatewayEvent): HTTPRequest {
|
|
24
27
|
const query = new URLSearchParams();
|
|
@@ -38,58 +41,6 @@ function lambdaEventToHTTPRequest(event: APIGatewayEvent): HTTPRequest {
|
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
function getHTTPMethod(event: APIGatewayEvent) {
|
|
42
|
-
if (isPayloadV1(event)) {
|
|
43
|
-
return event.httpMethod;
|
|
44
|
-
}
|
|
45
|
-
if (isPayloadV2(event)) {
|
|
46
|
-
return event.requestContext.http.method;
|
|
47
|
-
}
|
|
48
|
-
throw new TRPCError({
|
|
49
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
50
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getPath(event: APIGatewayEvent) {
|
|
55
|
-
if (isPayloadV1(event)) {
|
|
56
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
57
|
-
for (const match of matches) {
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
|
-
const group = match[1]!;
|
|
60
|
-
if (group.includes('+') && event.pathParameters) {
|
|
61
|
-
return event.pathParameters[group.replace('+', '')] || '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return event.path.slice(1);
|
|
65
|
-
}
|
|
66
|
-
if (isPayloadV2(event)) {
|
|
67
|
-
const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
68
|
-
for (const match of matches) {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
-
const group = match[1]!;
|
|
71
|
-
if (group.includes('+') && event.pathParameters) {
|
|
72
|
-
return event.pathParameters[group.replace('+', '')] || '';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return event.rawPath.slice(1);
|
|
76
|
-
}
|
|
77
|
-
throw new TRPCError({
|
|
78
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
79
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'] {
|
|
83
|
-
const obj: APIGatewayResult['headers'] = {};
|
|
84
|
-
|
|
85
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
86
|
-
if (typeof value === 'undefined') {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
90
|
-
}
|
|
91
|
-
return obj;
|
|
92
|
-
}
|
|
93
44
|
function tRPCOutputToAPIGatewayOutput<
|
|
94
45
|
TEvent extends APIGatewayEvent,
|
|
95
46
|
TResult extends APIGatewayResult,
|
|
@@ -6,7 +6,8 @@ import type {
|
|
|
6
6
|
APIGatewayProxyStructuredResultV2,
|
|
7
7
|
} from 'aws-lambda';
|
|
8
8
|
import type { AnyRouter, inferRouterContext } from '../../core';
|
|
9
|
-
import
|
|
9
|
+
import { TRPCError } from '../../error/TRPCError';
|
|
10
|
+
import type { HTTPHeaders, ResponseMetaFn } from '../../http/internals/types';
|
|
10
11
|
import { OnErrorFunction } from '../../internals/types';
|
|
11
12
|
|
|
12
13
|
export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
@@ -82,6 +83,63 @@ function determinePayloadFormat(
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
}
|
|
86
|
+
|
|
87
|
+
export function getHTTPMethod(event: APIGatewayEvent) {
|
|
88
|
+
if (isPayloadV1(event)) {
|
|
89
|
+
return event.httpMethod;
|
|
90
|
+
}
|
|
91
|
+
if (isPayloadV2(event)) {
|
|
92
|
+
return event.requestContext.http.method;
|
|
93
|
+
}
|
|
94
|
+
throw new TRPCError({
|
|
95
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
96
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getPath(event: APIGatewayEvent) {
|
|
101
|
+
if (isPayloadV1(event)) {
|
|
102
|
+
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
103
|
+
for (const match of matches) {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
105
|
+
const group = match[1]!;
|
|
106
|
+
if (group.includes('+') && event.pathParameters) {
|
|
107
|
+
return event.pathParameters[group.replace('+', '')] || '';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return event.path.slice(1);
|
|
111
|
+
}
|
|
112
|
+
if (isPayloadV2(event)) {
|
|
113
|
+
const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
114
|
+
for (const match of matches) {
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
116
|
+
const group = match[1]!;
|
|
117
|
+
if (group.includes('+') && event.pathParameters) {
|
|
118
|
+
return event.pathParameters[group.replace('+', '')] || '';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return event.rawPath.slice(1);
|
|
122
|
+
}
|
|
123
|
+
throw new TRPCError({
|
|
124
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
125
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function transformHeaders(
|
|
130
|
+
headers: HTTPHeaders,
|
|
131
|
+
): APIGatewayResult['headers'] {
|
|
132
|
+
const obj: APIGatewayResult['headers'] = {};
|
|
133
|
+
|
|
134
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
135
|
+
if (typeof value === 'undefined') {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
139
|
+
}
|
|
140
|
+
return obj;
|
|
141
|
+
}
|
|
142
|
+
|
|
85
143
|
export type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
|
|
86
144
|
export type APIGatewayPayloadFormatVersion =
|
|
87
145
|
| DefinedAPIGatewayPayloadFormats
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { AnyRouter } from '../../core';
|
|
3
|
-
import {
|
|
3
|
+
import { inferRouterContext } from '../../core/types';
|
|
4
4
|
import { HTTPRequest } from '../../http/internals/types';
|
|
5
5
|
import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
|
|
6
6
|
import { getPostBody } from './internals/getPostBody';
|
|
@@ -26,7 +26,7 @@ export async function nodeHTTPRequestHandler<
|
|
|
26
26
|
TResponse extends NodeHTTPResponse,
|
|
27
27
|
>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>) {
|
|
28
28
|
const createContext = async function _createContext(): Promise<
|
|
29
|
-
|
|
29
|
+
inferRouterContext<TRouter>
|
|
30
30
|
> {
|
|
31
31
|
return await opts.createContext?.(opts);
|
|
32
32
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
-
import { AnyRouter, inferRouterContext
|
|
2
|
+
import { AnyRouter, inferRouterContext } from '../../core';
|
|
3
3
|
import { HTTPBaseHandlerOptions } from '../../http/internals/types';
|
|
4
|
+
import { MaybePromise } from '../../types';
|
|
4
5
|
|
|
5
6
|
interface ParsedQs {
|
|
6
7
|
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
|
|
@@ -48,4 +49,4 @@ export type NodeHTTPCreateContextFn<
|
|
|
48
49
|
TResponse,
|
|
49
50
|
> = (
|
|
50
51
|
opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>,
|
|
51
|
-
) =>
|
|
52
|
+
) => MaybePromise<inferRouterContext<TRouter>>;
|
package/src/adapters/ws.ts
CHANGED
|
@@ -115,7 +115,7 @@ export function applyWSSHandler<TRouter extends AnyRouter>(
|
|
|
115
115
|
) {
|
|
116
116
|
const { wss, createContext, router } = opts;
|
|
117
117
|
|
|
118
|
-
const { transformer } = router._def;
|
|
118
|
+
const { transformer } = router._def._config;
|
|
119
119
|
wss.on('connection', async (client, req) => {
|
|
120
120
|
const clientSubscriptions = new Map<number | string, Unsubscribable>();
|
|
121
121
|
|