@orpc/standard-server-aws-lambda 0.0.0-next.6e7c532 → 0.0.0-next.70a1a81
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/README.md +20 -17
- package/dist/index.d.mts +12 -28
- package/dist/index.d.ts +12 -28
- package/dist/index.mjs +49 -170
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
|
-
<a href="https://codecov.io/gh/
|
|
9
|
-
<img alt="codecov" src="https://codecov.io/gh/
|
|
8
|
+
<a href="https://codecov.io/gh/middleapi/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@orpc/standard-server-aws-lambda">
|
|
12
12
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fstandard-server-aws-lambda?logo=npm" />
|
|
13
13
|
</a>
|
|
14
|
-
<a href="https://github.com/
|
|
15
|
-
<img alt="MIT License" src="https://img.shields.io/github/license/
|
|
14
|
+
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
16
16
|
</a>
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/middleapi/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
34
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
36
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,25 +42,24 @@
|
|
|
38
42
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
43
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
44
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
|
49
52
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
50
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
-
- [@orpc/
|
|
55
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
57
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
53
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
54
|
-
- [@orpc/
|
|
55
|
-
- [@orpc/
|
|
56
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
57
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
59
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
58
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
-
- [@orpc/
|
|
62
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
60
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
64
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
62
65
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
@@ -68,11 +71,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
68
71
|
## Sponsors
|
|
69
72
|
|
|
70
73
|
<p align="center">
|
|
71
|
-
<a href="https://cdn.jsdelivr.net/gh/
|
|
72
|
-
<img src='https://cdn.jsdelivr.net/gh/
|
|
74
|
+
<a href="https://cdn.jsdelivr.net/gh/dinwwwh/dinwwwh/sponsors.svg">
|
|
75
|
+
<img src='https://cdn.jsdelivr.net/gh/dinwwwh/dinwwwh/sponsors.svg'/>
|
|
73
76
|
</a>
|
|
74
77
|
</p>
|
|
75
78
|
|
|
76
79
|
## License
|
|
77
80
|
|
|
78
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/
|
|
81
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
import Stream, { Readable } from 'node:stream';
|
|
2
2
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
3
|
+
import { ToNodeHttpBodyOptions } from '@orpc/standard-server-node';
|
|
4
|
+
export { ToEventStreamOptions, toAbortSignal, toEventStream } from '@orpc/standard-server-node';
|
|
5
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
6
|
|
|
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;
|
|
7
|
+
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
24
8
|
}
|
|
25
|
-
declare function
|
|
9
|
+
declare function toEventIterator(body: string | undefined, options?: ToEventIteratorOptions): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
26
10
|
|
|
27
11
|
interface APIGatewayProxyEventHeaders {
|
|
28
12
|
[name: string]: string | undefined;
|
|
@@ -58,10 +42,12 @@ interface APIGatewayProxyEventV2 {
|
|
|
58
42
|
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
59
43
|
}
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
interface ToLambdaBodyOptions extends ToEventStreamOptions {
|
|
45
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
63
46
|
}
|
|
64
|
-
declare function
|
|
47
|
+
declare function toStandardBody(event: APIGatewayProxyEventV2, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
48
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
49
|
+
}
|
|
50
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
65
51
|
|
|
66
52
|
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
67
53
|
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
@@ -72,11 +58,9 @@ interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
|
72
58
|
}
|
|
73
59
|
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
74
60
|
|
|
75
|
-
declare function toAbortSignal(responseStream: Stream.Writable): AbortSignal;
|
|
76
|
-
|
|
77
61
|
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
78
62
|
|
|
79
63
|
type ResponseStream = Stream.Writable;
|
|
80
64
|
|
|
81
|
-
export { sendStandardResponse,
|
|
82
|
-
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions,
|
|
65
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
66
|
+
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions, ToEventIteratorOptions, ToLambdaBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
import Stream, { Readable } from 'node:stream';
|
|
2
2
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
3
|
+
import { ToNodeHttpBodyOptions } from '@orpc/standard-server-node';
|
|
4
|
+
export { ToEventStreamOptions, toAbortSignal, toEventStream } from '@orpc/standard-server-node';
|
|
5
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
6
|
|
|
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;
|
|
7
|
+
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
24
8
|
}
|
|
25
|
-
declare function
|
|
9
|
+
declare function toEventIterator(body: string | undefined, options?: ToEventIteratorOptions): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
26
10
|
|
|
27
11
|
interface APIGatewayProxyEventHeaders {
|
|
28
12
|
[name: string]: string | undefined;
|
|
@@ -58,10 +42,12 @@ interface APIGatewayProxyEventV2 {
|
|
|
58
42
|
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
59
43
|
}
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
interface ToLambdaBodyOptions extends ToEventStreamOptions {
|
|
45
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
63
46
|
}
|
|
64
|
-
declare function
|
|
47
|
+
declare function toStandardBody(event: APIGatewayProxyEventV2, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
48
|
+
interface ToLambdaBodyOptions extends ToNodeHttpBodyOptions {
|
|
49
|
+
}
|
|
50
|
+
declare function toLambdaBody(standardBody: StandardBody, standardHeaders: StandardHeaders, options?: ToLambdaBodyOptions): [body: undefined | string | Readable, headers: StandardHeaders];
|
|
65
51
|
|
|
66
52
|
declare function toStandardHeaders(headers: APIGatewayProxyEventHeaders, cookies: string[] | undefined): StandardHeaders;
|
|
67
53
|
declare function toLambdaHeaders(standard: StandardHeaders): [headers: APIGatewayProxyEventHeaders, setCookies: string[]];
|
|
@@ -72,11 +58,9 @@ interface SendStandardResponseOptions extends ToLambdaBodyOptions {
|
|
|
72
58
|
}
|
|
73
59
|
declare function sendStandardResponse(responseStream: Stream.Writable, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
74
60
|
|
|
75
|
-
declare function toAbortSignal(responseStream: Stream.Writable): AbortSignal;
|
|
76
|
-
|
|
77
61
|
declare function toStandardUrl(event: APIGatewayProxyEventV2): URL;
|
|
78
62
|
|
|
79
63
|
type ResponseStream = Stream.Writable;
|
|
80
64
|
|
|
81
|
-
export { sendStandardResponse,
|
|
82
|
-
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions,
|
|
65
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
|
66
|
+
export type { APIGatewayProxyEventHeaders, APIGatewayProxyEventPathParameters, APIGatewayProxyEventQueryStringParameters, APIGatewayProxyEventStageVariables, APIGatewayProxyEventV2, ResponseStream, SendStandardResponseOptions, ToEventIteratorOptions, ToLambdaBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,160 +1,56 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { runWithSpan, 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
|
-
function toEventIterator(body) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
function toEventIterator(body, options = {}) {
|
|
9
|
+
if (body === void 0) {
|
|
10
|
+
return toEventIterator$1(null, options);
|
|
11
|
+
}
|
|
12
|
+
return toEventIterator$1(
|
|
13
|
+
new ReadableStream({
|
|
14
|
+
pull(controller) {
|
|
10
15
|
controller.enqueue(body);
|
|
16
|
+
controller.close();
|
|
11
17
|
}
|
|
12
|
-
|
|
18
|
+
}).pipeThrough(new TextEncoderStream()),
|
|
19
|
+
options
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toStandardBody(event, options = {}) {
|
|
24
|
+
return runWithSpan({ name: "parse_standard_body", signal: options.signal }, async () => {
|
|
25
|
+
const contentType = event.headers["content-type"];
|
|
26
|
+
const contentDisposition = event.headers["content-disposition"];
|
|
27
|
+
if (typeof contentDisposition === "string") {
|
|
28
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
29
|
+
return _parseAsFile(event.body, event.isBase64Encoded, fileName, contentType ?? "");
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
}
|
|
31
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
|
32
|
+
const text = _parseAsString(event.body, event.isBase64Encoded);
|
|
33
|
+
return parseEmptyableJSON(text);
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
controller.close();
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
async cancel() {
|
|
96
|
-
cancelled = true;
|
|
97
|
-
clearInterval(timeout);
|
|
98
|
-
await iterator.return?.();
|
|
35
|
+
if (contentType.startsWith("multipart/form-data")) {
|
|
36
|
+
return _parseAsFormData(event.body, event.isBase64Encoded, contentType);
|
|
37
|
+
}
|
|
38
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
39
|
+
return new URLSearchParams(_parseAsString(event.body, event.isBase64Encoded));
|
|
99
40
|
}
|
|
41
|
+
if (contentType.startsWith("text/event-stream")) {
|
|
42
|
+
return toEventIterator(_parseAsString(event.body, event.isBase64Encoded), options);
|
|
43
|
+
}
|
|
44
|
+
if (contentType.startsWith("text/plain")) {
|
|
45
|
+
return _parseAsString(event.body, event.isBase64Encoded);
|
|
46
|
+
}
|
|
47
|
+
return _parseAsFile(event.body, event.isBase64Encoded, "blob", contentType);
|
|
100
48
|
});
|
|
101
|
-
return Readable.fromWeb(stream);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function toStandardBody(event) {
|
|
105
|
-
const contentType = event.headers["content-type"];
|
|
106
|
-
const contentDisposition = event.headers["content-disposition"];
|
|
107
|
-
if (typeof contentDisposition === "string") {
|
|
108
|
-
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
109
|
-
return _parseAsFile(event.body, event.isBase64Encoded, fileName, contentType ?? "");
|
|
110
|
-
}
|
|
111
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
|
112
|
-
const text = _parseAsString(event.body, event.isBase64Encoded);
|
|
113
|
-
return parseEmptyableJSON(text);
|
|
114
|
-
}
|
|
115
|
-
if (contentType.startsWith("multipart/form-data")) {
|
|
116
|
-
return _parseAsFormData(event.body, event.isBase64Encoded, contentType);
|
|
117
|
-
}
|
|
118
|
-
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
119
|
-
return new URLSearchParams(_parseAsString(event.body, event.isBase64Encoded));
|
|
120
|
-
}
|
|
121
|
-
if (contentType.startsWith("text/event-stream")) {
|
|
122
|
-
return toEventIterator(_parseAsString(event.body, event.isBase64Encoded));
|
|
123
|
-
}
|
|
124
|
-
if (contentType.startsWith("text/plain")) {
|
|
125
|
-
return _parseAsString(event.body, event.isBase64Encoded);
|
|
126
|
-
}
|
|
127
|
-
return _parseAsFile(event.body, event.isBase64Encoded, "blob", contentType);
|
|
128
49
|
}
|
|
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];
|
|
50
|
+
function toLambdaBody(standardBody, standardHeaders, options = {}) {
|
|
51
|
+
standardHeaders = { ...standardHeaders };
|
|
52
|
+
const body = toNodeHttpBody(standardBody, standardHeaders, options);
|
|
53
|
+
return [body, standardHeaders];
|
|
158
54
|
}
|
|
159
55
|
function _parseAsFile(body, isBase64Encoded, fileName, contentType) {
|
|
160
56
|
return new File(
|
|
@@ -199,35 +95,18 @@ function toLambdaHeaders(standard) {
|
|
|
199
95
|
return [headers, setCookies];
|
|
200
96
|
}
|
|
201
97
|
|
|
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
98
|
function toStandardUrl(event) {
|
|
214
99
|
return new URL(`https://${event.requestContext.domainName}${event.rawPath}?${event.rawQueryString}`);
|
|
215
100
|
}
|
|
216
101
|
|
|
217
102
|
function toStandardLazyRequest(event, responseStream) {
|
|
103
|
+
const signal = toAbortSignal(responseStream);
|
|
218
104
|
return {
|
|
219
105
|
url: toStandardUrl(event),
|
|
220
106
|
method: event.requestContext.http.method,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return headers;
|
|
225
|
-
},
|
|
226
|
-
set headers(value) {
|
|
227
|
-
Object.defineProperty(this, "headers", { value, writable: true });
|
|
228
|
-
},
|
|
229
|
-
signal: toAbortSignal(responseStream),
|
|
230
|
-
body: once(() => toStandardBody(event))
|
|
107
|
+
headers: toStandardHeaders(event.headers, event.cookies),
|
|
108
|
+
signal,
|
|
109
|
+
body: once(() => toStandardBody(event, { signal }))
|
|
231
110
|
};
|
|
232
111
|
}
|
|
233
112
|
|
|
@@ -259,4 +138,4 @@ function sendStandardResponse(responseStream, standardResponse, options = {}) {
|
|
|
259
138
|
});
|
|
260
139
|
}
|
|
261
140
|
|
|
262
|
-
export { sendStandardResponse,
|
|
141
|
+
export { sendStandardResponse, toEventIterator, toLambdaBody, toLambdaHeaders, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardUrl };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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.70a1a81",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/middleapi/orpc.git",
|
|
10
10
|
"directory": "packages/standard-server-aws-lambda"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
@@ -23,12 +23,14 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/
|
|
27
|
-
"@orpc/
|
|
26
|
+
"@orpc/shared": "0.0.0-next.70a1a81",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.70a1a81",
|
|
28
|
+
"@orpc/standard-server-fetch": "0.0.0-next.70a1a81",
|
|
29
|
+
"@orpc/standard-server-node": "0.0.0-next.70a1a81"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
|
-
"@types/aws-lambda": "^8.10.
|
|
31
|
-
"@types/node": "^22.
|
|
32
|
+
"@types/aws-lambda": "^8.10.161",
|
|
33
|
+
"@types/node": "^22.19.3"
|
|
32
34
|
},
|
|
33
35
|
"scripts": {
|
|
34
36
|
"build": "unbuild",
|