@orpc/standard-server-aws-lambda 0.0.0 → 1.4.0
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/index.d.mts +29 -51
- package/dist/index.d.ts +29 -51
- package/dist/index.mjs +41 -185
- package/package.json +6 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,83 +1,61 @@
|
|
|
1
1
|
import Stream, { Readable } from 'node:stream';
|
|
2
2
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface ToEventStreamOptions {
|
|
6
|
-
/**
|
|
7
|
-
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
8
|
-
*
|
|
9
|
-
* @default true
|
|
10
|
-
*/
|
|
11
|
-
eventIteratorKeepAliveEnabled?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
14
|
-
*
|
|
15
|
-
* @default 5000
|
|
16
|
-
*/
|
|
17
|
-
eventIteratorKeepAliveInterval?: number;
|
|
18
|
-
/**
|
|
19
|
-
* The content of the ping comment. Must not include newline characters.
|
|
20
|
-
*
|
|
21
|
-
* @default ''
|
|
22
|
-
*/
|
|
23
|
-
eventIteratorKeepAliveComment?: string;
|
|
24
|
-
}
|
|
25
|
-
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): Readable;
|
|
3
|
+
import { ToNodeHttpBodyOptions } from '@orpc/standard-server-node';
|
|
4
|
+
export { ToEventStreamOptions, toAbortSignal, toEventStream } from '@orpc/standard-server-node';
|
|
26
5
|
|
|
27
6
|
interface APIGatewayProxyEventHeaders {
|
|
28
7
|
[name: string]: string | undefined;
|
|
29
8
|
}
|
|
30
|
-
interface APIGatewayProxyEventMultiValueHeaders {
|
|
31
|
-
[name: string]: string[] | undefined;
|
|
32
|
-
}
|
|
33
9
|
interface APIGatewayProxyEventPathParameters {
|
|
34
10
|
[name: string]: string | undefined;
|
|
35
11
|
}
|
|
36
12
|
interface APIGatewayProxyEventQueryStringParameters {
|
|
37
13
|
[name: string]: string | undefined;
|
|
38
14
|
}
|
|
39
|
-
interface APIGatewayProxyEventMultiValueQueryStringParameters {
|
|
40
|
-
[name: string]: string[] | undefined;
|
|
41
|
-
}
|
|
42
15
|
interface APIGatewayProxyEventStageVariables {
|
|
43
16
|
[name: string]: string | undefined;
|
|
44
17
|
}
|
|
45
|
-
interface
|
|
46
|
-
|
|
18
|
+
interface APIGatewayProxyEventV2 {
|
|
19
|
+
version: string;
|
|
20
|
+
routeKey: string;
|
|
21
|
+
rawPath: string;
|
|
22
|
+
rawQueryString: string;
|
|
23
|
+
cookies?: string[];
|
|
47
24
|
headers: APIGatewayProxyEventHeaders;
|
|
48
|
-
|
|
49
|
-
httpMethod: string;
|
|
50
|
-
isBase64Encoded: boolean;
|
|
51
|
-
path: string;
|
|
52
|
-
pathParameters: APIGatewayProxyEventPathParameters | null;
|
|
53
|
-
queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
|
|
54
|
-
multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
|
|
55
|
-
stageVariables: APIGatewayProxyEventStageVariables | null;
|
|
25
|
+
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
|
56
26
|
requestContext: {
|
|
57
|
-
domainName
|
|
27
|
+
domainName: string;
|
|
28
|
+
http: {
|
|
29
|
+
method: string;
|
|
30
|
+
path: string;
|
|
31
|
+
protocol: string;
|
|
32
|
+
};
|
|
58
33
|
};
|
|
59
|
-
|
|
34
|
+
body?: string;
|
|
35
|
+
pathParameters?: APIGatewayProxyEventPathParameters;
|
|
36
|
+
isBase64Encoded: boolean;
|
|
37
|
+
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
60
38
|
}
|
|
61
39
|
|
|
62
|
-
declare function toStandardBody(event:
|
|
63
|
-
interface ToLambdaBodyOptions extends
|
|
40
|
+
declare function toStandardBody(event: APIGatewayProxyEventV2): Promise<StandardBody>;
|
|
41
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
64
42
|
}
|
|
65
|
-
declare function toLambdaBody(
|
|
43
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
66
44
|
|
|
67
|
-
declare function
|
|
45
|
+
declare function toEventIterator(body: string | undefined): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
46
|
+
|
|
47
|
+
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
68
48
|
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
69
49
|
|
|
70
|
-
declare function toStandardLazyRequest(event:
|
|
50
|
+
declare function toStandardLazyRequest(event: APIGatewayProxyEventV2, responseStream: Stream.Writable): StandardLazyRequest;
|
|
71
51
|
|
|
72
52
|
interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
73
53
|
}
|
|
74
54
|
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
75
55
|
|
|
76
|
-
declare function
|
|
77
|
-
|
|
78
|
-
declare function toStandardUrl(event: APIGatewayProxyEvent): URL;
|
|
56
|
+
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
79
57
|
|
|
80
58
|
type ResponseStream = Stream.Writable;
|
|
81
59
|
|
|
82
|
-
export { sendStandardResponse,
|
|
83
|
-
export type {
|
|
60
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
61
|
+
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions, ToLambdaBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,83 +1,61 @@
|
|
|
1
1
|
import Stream, { Readable } from 'node:stream';
|
|
2
2
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface ToEventStreamOptions {
|
|
6
|
-
/**
|
|
7
|
-
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
8
|
-
*
|
|
9
|
-
* @default true
|
|
10
|
-
*/
|
|
11
|
-
eventIteratorKeepAliveEnabled?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
14
|
-
*
|
|
15
|
-
* @default 5000
|
|
16
|
-
*/
|
|
17
|
-
eventIteratorKeepAliveInterval?: number;
|
|
18
|
-
/**
|
|
19
|
-
* The content of the ping comment. Must not include newline characters.
|
|
20
|
-
*
|
|
21
|
-
* @default ''
|
|
22
|
-
*/
|
|
23
|
-
eventIteratorKeepAliveComment?: string;
|
|
24
|
-
}
|
|
25
|
-
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): Readable;
|
|
3
|
+
import { ToNodeHttpBodyOptions } from '@orpc/standard-server-node';
|
|
4
|
+
export { ToEventStreamOptions, toAbortSignal, toEventStream } from '@orpc/standard-server-node';
|
|
26
5
|
|
|
27
6
|
interface APIGatewayProxyEventHeaders {
|
|
28
7
|
[name: string]: string | undefined;
|
|
29
8
|
}
|
|
30
|
-
interface APIGatewayProxyEventMultiValueHeaders {
|
|
31
|
-
[name: string]: string[] | undefined;
|
|
32
|
-
}
|
|
33
9
|
interface APIGatewayProxyEventPathParameters {
|
|
34
10
|
[name: string]: string | undefined;
|
|
35
11
|
}
|
|
36
12
|
interface APIGatewayProxyEventQueryStringParameters {
|
|
37
13
|
[name: string]: string | undefined;
|
|
38
14
|
}
|
|
39
|
-
interface APIGatewayProxyEventMultiValueQueryStringParameters {
|
|
40
|
-
[name: string]: string[] | undefined;
|
|
41
|
-
}
|
|
42
15
|
interface APIGatewayProxyEventStageVariables {
|
|
43
16
|
[name: string]: string | undefined;
|
|
44
17
|
}
|
|
45
|
-
interface
|
|
46
|
-
|
|
18
|
+
interface APIGatewayProxyEventV2 {
|
|
19
|
+
version: string;
|
|
20
|
+
routeKey: string;
|
|
21
|
+
rawPath: string;
|
|
22
|
+
rawQueryString: string;
|
|
23
|
+
cookies?: string[];
|
|
47
24
|
headers: APIGatewayProxyEventHeaders;
|
|
48
|
-
|
|
49
|
-
httpMethod: string;
|
|
50
|
-
isBase64Encoded: boolean;
|
|
51
|
-
path: string;
|
|
52
|
-
pathParameters: APIGatewayProxyEventPathParameters | null;
|
|
53
|
-
queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
|
|
54
|
-
multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
|
|
55
|
-
stageVariables: APIGatewayProxyEventStageVariables | null;
|
|
25
|
+
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
|
56
26
|
requestContext: {
|
|
57
|
-
domainName
|
|
27
|
+
domainName: string;
|
|
28
|
+
http: {
|
|
29
|
+
method: string;
|
|
30
|
+
path: string;
|
|
31
|
+
protocol: string;
|
|
32
|
+
};
|
|
58
33
|
};
|
|
59
|
-
|
|
34
|
+
body?: string;
|
|
35
|
+
pathParameters?: APIGatewayProxyEventPathParameters;
|
|
36
|
+
isBase64Encoded: boolean;
|
|
37
|
+
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
60
38
|
}
|
|
61
39
|
|
|
62
|
-
declare function toStandardBody(event:
|
|
63
|
-
interface ToLambdaBodyOptions extends
|
|
40
|
+
declare function toStandardBody(event: APIGatewayProxyEventV2): Promise<StandardBody>;
|
|
41
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
64
42
|
}
|
|
65
|
-
declare function toLambdaBody(
|
|
43
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
66
44
|
|
|
67
|
-
declare function
|
|
45
|
+
declare function toEventIterator(body: string | undefined): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
46
|
+
|
|
47
|
+
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
68
48
|
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
69
49
|
|
|
70
|
-
declare function toStandardLazyRequest(event:
|
|
50
|
+
declare function toStandardLazyRequest(event: APIGatewayProxyEventV2, responseStream: Stream.Writable): StandardLazyRequest;
|
|
71
51
|
|
|
72
52
|
interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
73
53
|
}
|
|
74
54
|
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
75
55
|
|
|
76
|
-
declare function
|
|
77
|
-
|
|
78
|
-
declare function toStandardUrl(event: APIGatewayProxyEvent): URL;
|
|
56
|
+
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
79
57
|
|
|
80
58
|
type ResponseStream = Stream.Writable;
|
|
81
59
|
|
|
82
|
-
export { sendStandardResponse,
|
|
83
|
-
export type {
|
|
60
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
61
|
+
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions, ToLambdaBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,109 +1,27 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { parseEmptyableJSON, toArray, once } from '@orpc/shared';
|
|
3
|
+
import { getFilenameFromContentDisposition, flattenHeader } from '@orpc/standard-server';
|
|
4
|
+
import { toNodeHttpBody, toAbortSignal } from '@orpc/standard-server-node';
|
|
5
|
+
export { toAbortSignal, toEventStream } from '@orpc/standard-server-node';
|
|
6
|
+
import { toEventIterator as toEventIterator$1 } from '@orpc/standard-server-fetch';
|
|
5
7
|
|
|
6
8
|
function toEventIterator(body) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
if (body === void 0) {
|
|
10
|
+
return toEventIterator$1(null);
|
|
11
|
+
}
|
|
12
|
+
return toEventIterator$1(
|
|
13
|
+
new ReadableStream({
|
|
14
|
+
pull(controller) {
|
|
10
15
|
controller.enqueue(body);
|
|
11
|
-
}
|
|
12
|
-
controller.close();
|
|
13
|
-
}
|
|
14
|
-
}).pipeThrough(new EventDecoderStream());
|
|
15
|
-
const reader = eventStream.getReader();
|
|
16
|
-
return createAsyncIteratorObject(async () => {
|
|
17
|
-
while (true) {
|
|
18
|
-
const { done, value } = await reader.read();
|
|
19
|
-
if (done) {
|
|
20
|
-
return { done: true, value: void 0 };
|
|
21
|
-
}
|
|
22
|
-
switch (value.event) {
|
|
23
|
-
case "message": {
|
|
24
|
-
let message = parseEmptyableJSON(value.data);
|
|
25
|
-
if (isTypescriptObject(message)) {
|
|
26
|
-
message = withEventMeta(message, value);
|
|
27
|
-
}
|
|
28
|
-
return { done: false, value: message };
|
|
29
|
-
}
|
|
30
|
-
case "error": {
|
|
31
|
-
let error = new ErrorEvent({
|
|
32
|
-
data: parseEmptyableJSON(value.data)
|
|
33
|
-
});
|
|
34
|
-
error = withEventMeta(error, value);
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
case "done": {
|
|
38
|
-
let done2 = parseEmptyableJSON(value.data);
|
|
39
|
-
if (isTypescriptObject(done2)) {
|
|
40
|
-
done2 = withEventMeta(done2, value);
|
|
41
|
-
}
|
|
42
|
-
return { done: true, value: done2 };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, async () => {
|
|
47
|
-
await reader.cancel();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function toEventStream(iterator, options = {}) {
|
|
51
|
-
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
52
|
-
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
53
|
-
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
54
|
-
let cancelled = false;
|
|
55
|
-
let timeout;
|
|
56
|
-
const stream = new ReadableStream({
|
|
57
|
-
async pull(controller) {
|
|
58
|
-
try {
|
|
59
|
-
if (keepAliveEnabled) {
|
|
60
|
-
timeout = setInterval(() => {
|
|
61
|
-
controller.enqueue(encodeEventMessage({
|
|
62
|
-
comments: [keepAliveComment]
|
|
63
|
-
}));
|
|
64
|
-
}, keepAliveInterval);
|
|
65
|
-
}
|
|
66
|
-
const value = await iterator.next();
|
|
67
|
-
clearInterval(timeout);
|
|
68
|
-
if (cancelled) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const meta = getEventMeta(value.value);
|
|
72
|
-
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
73
|
-
controller.enqueue(encodeEventMessage({
|
|
74
|
-
...meta,
|
|
75
|
-
event: value.done ? "done" : "message",
|
|
76
|
-
data: stringifyJSON(value.value)
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
if (value.done) {
|
|
80
|
-
controller.close();
|
|
81
|
-
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
clearInterval(timeout);
|
|
84
|
-
if (cancelled) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
controller.enqueue(encodeEventMessage({
|
|
88
|
-
...getEventMeta(err),
|
|
89
|
-
event: "error",
|
|
90
|
-
data: err instanceof ErrorEvent ? stringifyJSON(err.data) : void 0
|
|
91
|
-
}));
|
|
92
16
|
controller.close();
|
|
93
17
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
cancelled = true;
|
|
97
|
-
clearInterval(timeout);
|
|
98
|
-
await iterator.return?.();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
return Readable.fromWeb(stream);
|
|
18
|
+
}).pipeThrough(new TextEncoderStream())
|
|
19
|
+
);
|
|
102
20
|
}
|
|
103
21
|
|
|
104
22
|
async function toStandardBody(event) {
|
|
105
|
-
const contentType = event.headers["content-type"]
|
|
106
|
-
const contentDisposition = event.headers["content-disposition"]
|
|
23
|
+
const contentType = event.headers["content-type"];
|
|
24
|
+
const contentDisposition = event.headers["content-disposition"];
|
|
107
25
|
if (typeof contentDisposition === "string") {
|
|
108
26
|
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
109
27
|
return _parseAsFile(event.body, event.isBase64Encoded, fileName, contentType ?? "");
|
|
@@ -116,8 +34,7 @@ async function toStandardBody(event) {
|
|
|
116
34
|
return _parseAsFormData(event.body, event.isBase64Encoded, contentType);
|
|
117
35
|
}
|
|
118
36
|
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
119
|
-
|
|
120
|
-
return new URLSearchParams(text ?? void 0);
|
|
37
|
+
return new URLSearchParams(_parseAsString(event.body, event.isBase64Encoded));
|
|
121
38
|
}
|
|
122
39
|
if (contentType.startsWith("text/event-stream")) {
|
|
123
40
|
return toEventIterator(_parseAsString(event.body, event.isBase64Encoded));
|
|
@@ -127,48 +44,23 @@ async function toStandardBody(event) {
|
|
|
127
44
|
}
|
|
128
45
|
return _parseAsFile(event.body, event.isBase64Encoded, "blob", contentType);
|
|
129
46
|
}
|
|
130
|
-
function toLambdaBody(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return [void 0, headers];
|
|
135
|
-
}
|
|
136
|
-
if (body instanceof Blob) {
|
|
137
|
-
headers["content-type"] = body.type;
|
|
138
|
-
headers["content-length"] = body.size.toString();
|
|
139
|
-
headers["content-disposition"] = currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob");
|
|
140
|
-
return [Readable.fromWeb(body.stream()), headers];
|
|
141
|
-
}
|
|
142
|
-
if (body instanceof FormData) {
|
|
143
|
-
const response = new Response(body);
|
|
144
|
-
headers["content-type"] = response.headers.get("content-type");
|
|
145
|
-
return [Readable.fromWeb(response.body), headers];
|
|
146
|
-
}
|
|
147
|
-
if (body instanceof URLSearchParams) {
|
|
148
|
-
headers["content-type"] = "application/x-www-form-urlencoded";
|
|
149
|
-
return [body.toString(), headers];
|
|
150
|
-
}
|
|
151
|
-
if (isAsyncIteratorObject(body)) {
|
|
152
|
-
headers["content-type"] = "text/event-stream";
|
|
153
|
-
headers["cache-control"] = "no-cache";
|
|
154
|
-
headers.connection = "keep-alive";
|
|
155
|
-
return [toEventStream(body, options), headers];
|
|
156
|
-
}
|
|
157
|
-
headers["content-type"] = "application/json";
|
|
158
|
-
return [stringifyJSON(body), headers];
|
|
47
|
+
function toLambdaBody(standardBody, standardHeaders, options = {}) {
|
|
48
|
+
standardHeaders = { ...standardHeaders };
|
|
49
|
+
const body = toNodeHttpBody(standardBody, standardHeaders, options);
|
|
50
|
+
return [body, standardHeaders];
|
|
159
51
|
}
|
|
160
52
|
function _parseAsFile(body, isBase64Encoded, fileName, contentType) {
|
|
161
53
|
return new File(
|
|
162
|
-
body
|
|
54
|
+
body === void 0 ? [] : [isBase64Encoded ? Buffer.from(body, "base64") : body],
|
|
163
55
|
fileName,
|
|
164
56
|
{ type: contentType }
|
|
165
57
|
);
|
|
166
58
|
}
|
|
167
59
|
function _parseAsString(body, isBase64Encoded) {
|
|
168
|
-
return isBase64Encoded && body !==
|
|
60
|
+
return isBase64Encoded && body !== void 0 ? Buffer.from(body, "base64").toString() : body;
|
|
169
61
|
}
|
|
170
62
|
function _parseAsFormData(body, isBase64Encoded, contentType) {
|
|
171
|
-
const blobPart = isBase64Encoded && body !==
|
|
63
|
+
const blobPart = isBase64Encoded && body !== void 0 ? Buffer.from(body, "base64") : body;
|
|
172
64
|
const response = new Response(blobPart, {
|
|
173
65
|
headers: {
|
|
174
66
|
"content-type": contentType
|
|
@@ -177,10 +69,10 @@ function _parseAsFormData(body, isBase64Encoded, contentType) {
|
|
|
177
69
|
return response.formData();
|
|
178
70
|
}
|
|
179
71
|
|
|
180
|
-
function toStandardHeaders(headers,
|
|
72
|
+
function toStandardHeaders(headers, cookies) {
|
|
181
73
|
return {
|
|
182
74
|
...headers,
|
|
183
|
-
|
|
75
|
+
"set-cookie": cookies
|
|
184
76
|
};
|
|
185
77
|
}
|
|
186
78
|
function toLambdaHeaders(standard) {
|
|
@@ -201,59 +93,35 @@ function toLambdaHeaders(standard) {
|
|
|
201
93
|
}
|
|
202
94
|
|
|
203
95
|
function toStandardUrl(event) {
|
|
204
|
-
|
|
205
|
-
const url = new URL(`https://${host}${event.path}`);
|
|
206
|
-
if (event.queryStringParameters) {
|
|
207
|
-
for (const key in event.queryStringParameters) {
|
|
208
|
-
const value = event.queryStringParameters[key];
|
|
209
|
-
if (typeof value === "string") {
|
|
210
|
-
url.searchParams.append(key, value);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (event.multiValueQueryStringParameters) {
|
|
215
|
-
for (const key in event.multiValueQueryStringParameters) {
|
|
216
|
-
const value = event.multiValueQueryStringParameters[key];
|
|
217
|
-
if (value) {
|
|
218
|
-
for (const v of value) {
|
|
219
|
-
url.searchParams.append(key, v);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return url;
|
|
96
|
+
return new URL(`https://${event.requestContext.domainName}${event.rawPath}?${event.rawQueryString}`);
|
|
225
97
|
}
|
|
226
98
|
|
|
227
|
-
function toStandardLazyRequest(event) {
|
|
99
|
+
function toStandardLazyRequest(event, responseStream) {
|
|
228
100
|
return {
|
|
229
101
|
url: toStandardUrl(event),
|
|
230
|
-
method: event.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
234
|
-
return headers;
|
|
235
|
-
},
|
|
236
|
-
set headers(value) {
|
|
237
|
-
Object.defineProperty(this, "headers", { value, writable: true });
|
|
238
|
-
},
|
|
239
|
-
signal: void 0,
|
|
102
|
+
method: event.requestContext.http.method,
|
|
103
|
+
headers: toStandardHeaders(event.headers, event.cookies),
|
|
104
|
+
signal: toAbortSignal(responseStream),
|
|
240
105
|
body: once(() => toStandardBody(event))
|
|
241
106
|
};
|
|
242
107
|
}
|
|
243
108
|
|
|
244
109
|
function sendStandardResponse(responseStream, standardResponse, options = {}) {
|
|
245
110
|
return new Promise((resolve, reject) => {
|
|
111
|
+
responseStream.once("error", reject);
|
|
112
|
+
responseStream.once("close", resolve);
|
|
246
113
|
const [body, standardHeaders] = toLambdaBody(standardResponse.body, standardResponse.headers, options);
|
|
247
|
-
const [headers,
|
|
248
|
-
|
|
114
|
+
const [headers, setCookies] = toLambdaHeaders(standardHeaders);
|
|
115
|
+
globalThis.awslambda.HttpResponseStream.from(responseStream, {
|
|
249
116
|
statusCode: standardResponse.status,
|
|
250
117
|
headers,
|
|
251
|
-
cookies
|
|
118
|
+
cookies: setCookies
|
|
252
119
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (
|
|
256
|
-
responseStream.
|
|
120
|
+
if (body === void 0) {
|
|
121
|
+
responseStream.end();
|
|
122
|
+
} else if (typeof body === "string") {
|
|
123
|
+
responseStream.write(body);
|
|
124
|
+
responseStream.end();
|
|
257
125
|
} else {
|
|
258
126
|
responseStream.once("close", () => {
|
|
259
127
|
if (!body.closed) {
|
|
@@ -266,16 +134,4 @@ function sendStandardResponse(responseStream, standardResponse, options = {}) {
|
|
|
266
134
|
});
|
|
267
135
|
}
|
|
268
136
|
|
|
269
|
-
|
|
270
|
-
const controller = new AbortController();
|
|
271
|
-
responseStream.once("close", () => {
|
|
272
|
-
if (responseStream.errored) {
|
|
273
|
-
controller.abort(responseStream.errored.toString());
|
|
274
|
-
} else if (!responseStream.writableFinished) {
|
|
275
|
-
controller.abort("Client connection prematurely closed.");
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
return controller.signal;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
137
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-aws-lambda",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,12 +23,14 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/shared": "1.
|
|
27
|
-
"@orpc/standard-server": "1.
|
|
26
|
+
"@orpc/shared": "1.4.0",
|
|
27
|
+
"@orpc/standard-server": "1.4.0",
|
|
28
|
+
"@orpc/standard-server-fetch": "1.4.0",
|
|
29
|
+
"@orpc/standard-server-node": "1.4.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@types/aws-lambda": "^8.10.149",
|
|
31
|
-
"@types/node": "^22.15.
|
|
33
|
+
"@types/node": "^22.15.18"
|
|
32
34
|
},
|
|
33
35
|
"scripts": {
|
|
34
36
|
"build": "unbuild",
|