@trpc/server 11.1.4 → 11.1.5-canary.1
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/getPlanner.d.ts +2 -0
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.js +18 -1
- package/dist/adapters/aws-lambda/getPlanner.mjs +18 -1
- package/dist/adapters/aws-lambda/index.d.ts +2 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +30 -0
- package/dist/adapters/aws-lambda/index.mjs +30 -1
- package/dist/bundle-analysis.json +998 -0
- package/package.json +3 -3
- package/src/adapters/aws-lambda/getPlanner.ts +22 -0
- package/src/adapters/aws-lambda/index.ts +40 -1
- package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
- package/adapters/node-http/content-type/form-data/index.js +0 -1
- package/adapters/node-http/content-type/json/index.d.ts +0 -1
- package/adapters/node-http/content-type/json/index.js +0 -1
- package/src/adapters/node-http/__generated__/cert.csr +0 -16
- package/src/adapters/node-http/__generated__/certificate/cert.csr +0 -16
- package/src/adapters/node-http/__generated__/certificate/certificate.crt +0 -21
- package/src/adapters/node-http/__generated__/certificate/private.key +0 -28
- package/src/adapters/node-http/__generated__/certificate.crt +0 -21
- package/src/adapters/node-http/__generated__/private.key +0 -28
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Writable } from 'node:stream';
|
|
1
2
|
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
|
|
2
3
|
export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
3
4
|
export type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
@@ -9,5 +10,6 @@ export declare function getPlanner<TEvent extends LambdaEvent>(event: TEvent): {
|
|
|
9
10
|
path: string;
|
|
10
11
|
request: Request;
|
|
11
12
|
toResult: (response: Response) => Promise<inferAPIGWReturn<TEvent>>;
|
|
13
|
+
toStream: ((response: Response, stream: Writable) => Promise<void>) | undefined;
|
|
12
14
|
};
|
|
13
15
|
//# sourceMappingURL=getPlanner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPlanner.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/getPlanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EAClC,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,WAAW,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAExE,MAAM,MAAM,gBAAgB,GACxB,qBAAqB,GACrB,iCAAiC,CAAC;AActC;;IAEI;AACJ,MAAM,MAAM,gBAAgB,CAAC,MAAM,IAAI,MAAM,SAAS,oBAAoB,GACtE,qBAAqB,GACrB,MAAM,SAAS,sBAAsB,GACnC,iCAAiC,GACjC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"getPlanner.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/getPlanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EAClC,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,WAAW,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAExE,MAAM,MAAM,gBAAgB,GACxB,qBAAqB,GACrB,iCAAiC,CAAC;AActC;;IAEI;AACJ,MAAM,MAAM,gBAAgB,CAAC,MAAM,IAAI,MAAM,SAAS,oBAAoB,GACtE,qBAAqB,GACrB,MAAM,SAAS,sBAAsB,GACnC,iCAAiC,GACjC,KAAK,CAAC;AA+JZ,wBAAgB,UAAU,CAAC,MAAM,SAAS,WAAW,EAAE,KAAK,EAAE,MAAM;;;yBAxJ7C,QAAQ;0BACP,QAAQ,UAAU,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC;EA4LnE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var node_stream = require('node:stream');
|
|
4
|
+
var promises = require('node:stream/promises');
|
|
3
5
|
var split = require('../../vendor/cookie-es/set-cookie/split.js');
|
|
4
6
|
|
|
5
7
|
function determinePayloadFormat(event) {
|
|
@@ -125,6 +127,20 @@ const v2Processor = {
|
|
|
125
127
|
headers
|
|
126
128
|
};
|
|
127
129
|
return result;
|
|
130
|
+
},
|
|
131
|
+
toStream: async (response, stream)=>{
|
|
132
|
+
const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
|
|
133
|
+
const metadata = {
|
|
134
|
+
statusCode: response.status,
|
|
135
|
+
headers,
|
|
136
|
+
cookies
|
|
137
|
+
};
|
|
138
|
+
const responseStream = awslambda.HttpResponseStream.from(stream, metadata);
|
|
139
|
+
if (response.body) {
|
|
140
|
+
await promises.pipeline(node_stream.Readable.fromWeb(response.body), responseStream);
|
|
141
|
+
} else {
|
|
142
|
+
responseStream.end();
|
|
143
|
+
}
|
|
128
144
|
}
|
|
129
145
|
};
|
|
130
146
|
function getPlanner(event) {
|
|
@@ -155,7 +171,8 @@ function getPlanner(event) {
|
|
|
155
171
|
return {
|
|
156
172
|
path: processor.getTRPCPath(event),
|
|
157
173
|
request,
|
|
158
|
-
toResult: processor.toResult
|
|
174
|
+
toResult: processor.toResult,
|
|
175
|
+
toStream: processor.toStream
|
|
159
176
|
};
|
|
160
177
|
}
|
|
161
178
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
|
1
3
|
import { splitSetCookieString } from '../../vendor/cookie-es/set-cookie/split.mjs';
|
|
2
4
|
|
|
3
5
|
function determinePayloadFormat(event) {
|
|
@@ -123,6 +125,20 @@ const v2Processor = {
|
|
|
123
125
|
headers
|
|
124
126
|
};
|
|
125
127
|
return result;
|
|
128
|
+
},
|
|
129
|
+
toStream: async (response, stream)=>{
|
|
130
|
+
const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
|
|
131
|
+
const metadata = {
|
|
132
|
+
statusCode: response.status,
|
|
133
|
+
headers,
|
|
134
|
+
cookies
|
|
135
|
+
};
|
|
136
|
+
const responseStream = awslambda.HttpResponseStream.from(stream, metadata);
|
|
137
|
+
if (response.body) {
|
|
138
|
+
await pipeline(Readable.fromWeb(response.body), responseStream);
|
|
139
|
+
} else {
|
|
140
|
+
responseStream.end();
|
|
141
|
+
}
|
|
126
142
|
}
|
|
127
143
|
};
|
|
128
144
|
function getPlanner(event) {
|
|
@@ -153,7 +169,8 @@ function getPlanner(event) {
|
|
|
153
169
|
return {
|
|
154
170
|
path: processor.getTRPCPath(event),
|
|
155
171
|
request,
|
|
156
|
-
toResult: processor.toResult
|
|
172
|
+
toResult: processor.toResult,
|
|
173
|
+
toStream: processor.toStream
|
|
157
174
|
};
|
|
158
175
|
}
|
|
159
176
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
import type { Context as APIGWContext } from 'aws-lambda';
|
|
10
|
+
import type { APIGatewayProxyEventV2, Context as APIGWContext, StreamifyHandler } from 'aws-lambda';
|
|
11
11
|
import type { AnyRouter, CreateContextCallback, inferRouterContext } from '../../@trpc/server';
|
|
12
12
|
import type { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../@trpc/server/http';
|
|
13
13
|
import type { inferAPIGWReturn, LambdaEvent } from './getPlanner';
|
|
@@ -19,4 +19,5 @@ export type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {
|
|
|
19
19
|
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends LambdaEvent> = HTTPBaseHandlerOptions<TRouter, TEvent> & CreateContextCallback<inferRouterContext<AnyRouter>, AWSLambdaCreateContextFn<TRouter, TEvent>>;
|
|
20
20
|
export type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends LambdaEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
21
21
|
export declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends LambdaEvent>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: APIGWContext) => Promise<inferAPIGWReturn<TEvent>>;
|
|
22
|
+
export declare function awsLambdaStreamingRequestHandler<TRouter extends AnyRouter, TEvent extends APIGatewayProxyEventV2>(opts: AWSLambdaOptions<TRouter, TEvent>): StreamifyHandler<TEvent>;
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,sBAAsB,EACtB,OAAO,IAAI,YAAY,EACvB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,sBAAsB,EAEtB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGlE,MAAM,MAAM,6BAA6B,CAAC,MAAM,SAAS,WAAW,IAAI;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAC1B,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,WAAW,IACxB,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,GACzC,qBAAqB,CACnB,kBAAkB,CAAC,SAAS,CAAC,EAC7B,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAC1C,CAAC;AAEJ,MAAM,MAAM,wBAAwB,CAClC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,WAAW,IACxB,CAAC,EACH,KAAK,EACL,OAAO,EACP,IAAI,GACL,EAAE,6BAA6B,CAAC,MAAM,CAAC,KACpC,kBAAkB,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzC,wBAAgB,uBAAuB,CACrC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,WAAW,EAE1B,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACtC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CA0B7E;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,sBAAsB,EACrC,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CA8BnE"}
|
|
@@ -32,5 +32,35 @@ function awsLambdaRequestHandler(opts) {
|
|
|
32
32
|
return await planner.toResult(response);
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
+
function awsLambdaStreamingRequestHandler(opts) {
|
|
36
|
+
return async (event, responseStream, context)=>{
|
|
37
|
+
const planner = getPlanner.getPlanner(event);
|
|
38
|
+
if (!planner.toStream) {
|
|
39
|
+
throw new Error('Streaming is not supported for this event version');
|
|
40
|
+
}
|
|
41
|
+
const createContext = async (innerOpts)=>{
|
|
42
|
+
return await opts.createContext?.({
|
|
43
|
+
event,
|
|
44
|
+
context,
|
|
45
|
+
...innerOpts
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const response = await resolveResponse.resolveResponse({
|
|
49
|
+
...opts,
|
|
50
|
+
createContext,
|
|
51
|
+
req: planner.request,
|
|
52
|
+
path: planner.path,
|
|
53
|
+
error: null,
|
|
54
|
+
onError (o) {
|
|
55
|
+
opts?.onError?.({
|
|
56
|
+
...o,
|
|
57
|
+
req: event
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
await planner.toStream(response, responseStream);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
35
64
|
|
|
36
65
|
exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
|
|
66
|
+
exports.awsLambdaStreamingRequestHandler = awsLambdaStreamingRequestHandler;
|
|
@@ -30,5 +30,34 @@ function awsLambdaRequestHandler(opts) {
|
|
|
30
30
|
return await planner.toResult(response);
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
function awsLambdaStreamingRequestHandler(opts) {
|
|
34
|
+
return async (event, responseStream, context)=>{
|
|
35
|
+
const planner = getPlanner(event);
|
|
36
|
+
if (!planner.toStream) {
|
|
37
|
+
throw new Error('Streaming is not supported for this event version');
|
|
38
|
+
}
|
|
39
|
+
const createContext = async (innerOpts)=>{
|
|
40
|
+
return await opts.createContext?.({
|
|
41
|
+
event,
|
|
42
|
+
context,
|
|
43
|
+
...innerOpts
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const response = await resolveResponse({
|
|
47
|
+
...opts,
|
|
48
|
+
createContext,
|
|
49
|
+
req: planner.request,
|
|
50
|
+
path: planner.path,
|
|
51
|
+
error: null,
|
|
52
|
+
onError (o) {
|
|
53
|
+
opts?.onError?.({
|
|
54
|
+
...o,
|
|
55
|
+
req: event
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
await planner.toStream(response, responseStream);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
33
62
|
|
|
34
|
-
export { awsLambdaRequestHandler };
|
|
63
|
+
export { awsLambdaRequestHandler, awsLambdaStreamingRequestHandler };
|