@orpc/standard-server-aws-lambda 0.0.0-next.d9485b0 → 0.0.0-next.fd6982a
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 +8 -29
- package/dist/index.d.ts +8 -29
- package/dist/index.mjs +19 -144
- package/package.json +5 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
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;
|
|
@@ -59,9 +38,11 @@ interface APIGatewayProxyEventV2 {
|
|
|
59
38
|
}
|
|
60
39
|
|
|
61
40
|
declare function toStandardBody(event: APIGatewayProxyEventV2): Promise<StandardBody>;
|
|
62
|
-
interface ToLambdaBodyOptions extends
|
|
41
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
63
42
|
}
|
|
64
|
-
declare function toLambdaBody(
|
|
43
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
44
|
+
|
|
45
|
+
declare function toEventIterator(body: string | undefined): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
65
46
|
|
|
66
47
|
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
67
48
|
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
@@ -72,11 +53,9 @@ interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
|
72
53
|
}
|
|
73
54
|
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
74
55
|
|
|
75
|
-
declare function toAbortSignal(responseStream: Stream.Writable): AbortSignal;
|
|
76
|
-
|
|
77
56
|
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
78
57
|
|
|
79
58
|
type ResponseStream = Stream.Writable;
|
|
80
59
|
|
|
81
|
-
export { sendStandardResponse,
|
|
82
|
-
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions,
|
|
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,28 +1,7 @@
|
|
|
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;
|
|
@@ -59,9 +38,11 @@ interface APIGatewayProxyEventV2 {
|
|
|
59
38
|
}
|
|
60
39
|
|
|
61
40
|
declare function toStandardBody(event: APIGatewayProxyEventV2): Promise<StandardBody>;
|
|
62
|
-
interface ToLambdaBodyOptions extends
|
|
41
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
63
42
|
}
|
|
64
|
-
declare function toLambdaBody(
|
|
43
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
44
|
+
|
|
45
|
+
declare function toEventIterator(body: string | undefined): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
65
46
|
|
|
66
47
|
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
67
48
|
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
@@ -72,11 +53,9 @@ interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
|
72
53
|
}
|
|
73
54
|
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
74
55
|
|
|
75
|
-
declare function toAbortSignal(responseStream: Stream.Writable): AbortSignal;
|
|
76
|
-
|
|
77
56
|
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
78
57
|
|
|
79
58
|
type ResponseStream = Stream.Writable;
|
|
80
59
|
|
|
81
|
-
export { sendStandardResponse,
|
|
82
|
-
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions,
|
|
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,104 +1,22 @@
|
|
|
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) {
|
|
@@ -126,35 +44,10 @@ async function toStandardBody(event) {
|
|
|
126
44
|
}
|
|
127
45
|
return _parseAsFile(event.body, event.isBase64Encoded, "blob", contentType);
|
|
128
46
|
}
|
|
129
|
-
function toLambdaBody(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return [void 0, headers];
|
|
134
|
-
}
|
|
135
|
-
if (body instanceof Blob) {
|
|
136
|
-
headers["content-type"] = body.type;
|
|
137
|
-
headers["content-length"] = body.size.toString();
|
|
138
|
-
headers["content-disposition"] = currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob");
|
|
139
|
-
return [Readable.fromWeb(body.stream()), headers];
|
|
140
|
-
}
|
|
141
|
-
if (body instanceof FormData) {
|
|
142
|
-
const response = new Response(body);
|
|
143
|
-
headers["content-type"] = response.headers.get("content-type");
|
|
144
|
-
return [Readable.fromWeb(response.body), headers];
|
|
145
|
-
}
|
|
146
|
-
if (body instanceof URLSearchParams) {
|
|
147
|
-
headers["content-type"] = "application/x-www-form-urlencoded";
|
|
148
|
-
return [body.toString(), headers];
|
|
149
|
-
}
|
|
150
|
-
if (isAsyncIteratorObject(body)) {
|
|
151
|
-
headers["content-type"] = "text/event-stream";
|
|
152
|
-
headers["cache-control"] = "no-cache";
|
|
153
|
-
headers.connection = "keep-alive";
|
|
154
|
-
return [toEventStream(body, options), headers];
|
|
155
|
-
}
|
|
156
|
-
headers["content-type"] = "application/json";
|
|
157
|
-
return [stringifyJSON(body), headers];
|
|
47
|
+
function toLambdaBody(standardBody, standardHeaders, options = {}) {
|
|
48
|
+
standardHeaders = { ...standardHeaders };
|
|
49
|
+
const body = toNodeHttpBody(standardBody, standardHeaders, options);
|
|
50
|
+
return [body, standardHeaders];
|
|
158
51
|
}
|
|
159
52
|
function _parseAsFile(body, isBase64Encoded, fileName, contentType) {
|
|
160
53
|
return new File(
|
|
@@ -199,17 +92,6 @@ function toLambdaHeaders(standard) {
|
|
|
199
92
|
return [headers, setCookies];
|
|
200
93
|
}
|
|
201
94
|
|
|
202
|
-
function toAbortSignal(responseStream) {
|
|
203
|
-
const controller = new AbortController();
|
|
204
|
-
responseStream.once("error", (error) => controller.abort(error));
|
|
205
|
-
responseStream.once("close", () => {
|
|
206
|
-
if (!responseStream.writableFinished) {
|
|
207
|
-
controller.abort(new Error("Writable stream closed before it finished writing"));
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
return controller.signal;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
95
|
function toStandardUrl(event) {
|
|
214
96
|
return new URL(`https://${event.requestContext.domainName}${event.rawPath}?${event.rawQueryString}`);
|
|
215
97
|
}
|
|
@@ -218,14 +100,7 @@ function toStandardLazyRequest(event, responseStream) {
|
|
|
218
100
|
return {
|
|
219
101
|
url: toStandardUrl(event),
|
|
220
102
|
method: event.requestContext.http.method,
|
|
221
|
-
|
|
222
|
-
const headers = toStandardHeaders(event.headers, event.cookies);
|
|
223
|
-
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
224
|
-
return headers;
|
|
225
|
-
},
|
|
226
|
-
set headers(value) {
|
|
227
|
-
Object.defineProperty(this, "headers", { value, writable: true });
|
|
228
|
-
},
|
|
103
|
+
headers: toStandardHeaders(event.headers, event.cookies),
|
|
229
104
|
signal: toAbortSignal(responseStream),
|
|
230
105
|
body: once(() => toStandardBody(event))
|
|
231
106
|
};
|
|
@@ -259,4 +134,4 @@ function sendStandardResponse(responseStream, standardResponse, options = {}) {
|
|
|
259
134
|
});
|
|
260
135
|
}
|
|
261
136
|
|
|
262
|
-
export { sendStandardResponse,
|
|
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": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.fd6982a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,8 +23,10 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/shared": "0.0.0-next.
|
|
27
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
26
|
+
"@orpc/shared": "0.0.0-next.fd6982a",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.fd6982a",
|
|
28
|
+
"@orpc/standard-server-fetch": "0.0.0-next.fd6982a",
|
|
29
|
+
"@orpc/standard-server-node": "0.0.0-next.fd6982a"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@types/aws-lambda": "^8.10.149",
|