@vercube/serverless 0.0.33 → 0.0.35
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 -226
- package/dist/Adapters/aws-lambda/index.d.mts +288 -2
- package/dist/Adapters/azure-functions/index.d.mts +132 -2
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -1,246 +1,40 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
2
|
+
<img src="https://raw.githubusercontent.com/vercube/vercube/refs/heads/main/.github/assets/cover.png" width="100%" alt="Vercube - Unleash your server development." />
|
|
3
3
|
<br>
|
|
4
4
|
<br>
|
|
5
5
|
|
|
6
6
|
# @vercube/serverless
|
|
7
7
|
|
|
8
|
-
Serverless
|
|
8
|
+
### Serverless adapters for Vercube
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<img src="https://img.shields.io/npm/dm/%40vercube%2Fserverless?style=for-the-badge&logo=npm&color=%23767eff" alt="npm"/>
|
|
15
|
-
</a>
|
|
16
|
-
<a href="https://github.com/vercube/vercube/blob/main/LICENSE" target="_blank">
|
|
17
|
-
<img src="https://img.shields.io/npm/l/%40vercube%2Fserverless?style=for-the-badge&color=%23767eff" alt="License"/>
|
|
18
|
-
</a>
|
|
19
|
-
<a href="https://codecov.io/gh/vercube/vercube" target="_blank">
|
|
20
|
-
<img src="https://img.shields.io/codecov/c/github/vercube/vercube?style=for-the-badge&color=%23767eff" alt="Coverage"/>
|
|
21
|
-
</a>
|
|
22
|
-
<br/>
|
|
23
|
-
<br/>
|
|
24
|
-
</div>
|
|
25
|
-
|
|
26
|
-
Deploy your Vercube applications to serverless platforms with zero configuration. This package provides seamless adapters for AWS Lambda, Vercel, and other serverless providers, allowing you to run your Vercube apps anywhere without code changes.
|
|
27
|
-
|
|
28
|
-
---
|
|
10
|
+
[&labelColor=%23000&color=%232f2f2f>)](https://deepwiki.com/vercube/vercube)
|
|
11
|
+
&labelColor=%23000&color=%232e2e2e&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40vercube%2Fserverless>)
|
|
12
|
+
&labelColor=%23000&color=%232f2f2f>)
|
|
13
|
+
&labelColor=%23000&color=%232f2f2f>)
|
|
29
14
|
|
|
30
|
-
|
|
15
|
+
**Deploy your Vercube app to AWS Lambda or Azure Functions. Same code, different platform - just swap the adapter.**
|
|
31
16
|
|
|
32
|
-
|
|
17
|
+
[Website](https://vercube.dev) • [Documentation](https://vercube.dev/docs/getting-started)
|
|
33
18
|
|
|
34
|
-
|
|
19
|
+
</div>
|
|
35
20
|
|
|
36
|
-
|
|
37
|
-
- **Azure Functions Integration** - Complete support for Azure Functions HTTP triggers
|
|
38
|
-
- **Zero Configuration** - Works out-of-the-box with existing Vercube apps
|
|
39
|
-
- **Type Safety** - Complete TypeScript support with proper type definitions
|
|
40
|
-
- **Binary Support** - Automatic handling of binary content with base64 encoding
|
|
41
|
-
- **Cookie Support** - Proper cookie handling for both API Gateway versions and Azure Functions
|
|
42
|
-
- **Error Handling** - Robust error handling and validation
|
|
43
|
-
- **Performance Optimized** - Efficient request/response conversion
|
|
21
|
+
## ✨ Features
|
|
44
22
|
|
|
45
|
-
|
|
23
|
+
- **AWS Lambda** - full API Gateway v1 and v2 support
|
|
24
|
+
- **Azure Functions** - HTTP triggers, streaming, the works
|
|
25
|
+
- **Zero config** - works with your existing Vercube app
|
|
26
|
+
- **Binary support** - handles images, files, whatever you throw at it
|
|
46
27
|
|
|
47
|
-
##
|
|
28
|
+
## 📦 Installation
|
|
48
29
|
|
|
49
30
|
```bash
|
|
50
|
-
pnpm
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## ⚙️ Usage
|
|
56
|
-
|
|
57
|
-
### AWS Lambda Integration
|
|
58
|
-
|
|
59
|
-
Deploy your Vercube application to AWS Lambda with API Gateway:
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
// lambda.ts
|
|
63
|
-
import { createApp } from '@vercube/core';
|
|
64
|
-
import { toServerlessHandler } from '@vercube/serverless/aws-lambda';
|
|
65
|
-
|
|
66
|
-
const app = createApp();
|
|
67
|
-
export const handler = toServerlessHandler(app);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Azure Functions Integration
|
|
71
|
-
|
|
72
|
-
Deploy your Vercube application to Azure Functions:
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
// httpTrigger.ts
|
|
76
|
-
import { createApp } from '@vercube/core';
|
|
77
|
-
import { toServerlessHandler } from '@vercube/serverless/azure-functions';
|
|
78
|
-
import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
|
|
79
|
-
|
|
80
|
-
const vercubeApp = createApp();
|
|
81
|
-
const handler = toServerlessHandler(vercubeApp);
|
|
82
|
-
|
|
83
|
-
export async function httpTrigger(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
|
|
84
|
-
return await handler(request);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
app.http('httpTrigger', {
|
|
88
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'],
|
|
89
|
-
authLevel: 'anonymous',
|
|
90
|
-
handler: httpTrigger,
|
|
91
|
-
});
|
|
31
|
+
pnpm add @vercube/serverless
|
|
92
32
|
```
|
|
93
33
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```yaml
|
|
97
|
-
# serverless.yml
|
|
98
|
-
service: vercube-app
|
|
99
|
-
|
|
100
|
-
provider:
|
|
101
|
-
name: aws
|
|
102
|
-
runtime: nodejs22.x
|
|
103
|
-
region: us-east-1
|
|
104
|
-
|
|
105
|
-
functions:
|
|
106
|
-
api:
|
|
107
|
-
handler: lambda.handler
|
|
108
|
-
events:
|
|
109
|
-
- http:
|
|
110
|
-
path: /{proxy+}
|
|
111
|
-
method: ANY
|
|
112
|
-
cors: true
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## 🔧 Supported Platforms
|
|
118
|
-
|
|
119
|
-
### AWS Lambda
|
|
120
|
-
|
|
121
|
-
Full support for AWS Lambda with API Gateway integration:
|
|
122
|
-
|
|
123
|
-
- **API Gateway v1** - Complete compatibility with `APIGatewayProxyEvent`
|
|
124
|
-
- **API Gateway v2** - Full support for `APIGatewayProxyEventV2`
|
|
125
|
-
- **Binary Content** - Automatic base64 encoding for binary responses
|
|
126
|
-
- **Cookies** - Proper cookie handling for both API Gateway versions
|
|
127
|
-
- **Headers** - Complete header conversion and processing
|
|
128
|
-
|
|
129
|
-
### Azure Functions
|
|
130
|
-
|
|
131
|
-
Complete support for Azure Functions HTTP triggers:
|
|
132
|
-
|
|
133
|
-
- **HTTP Triggers** - Full compatibility with Azure Functions HTTP triggers
|
|
134
|
-
- **Request/Response Conversion** - Seamless conversion between Azure Functions and web standards
|
|
135
|
-
- **Cookie Support** - Proper handling of Set-Cookie headers and cookie parsing
|
|
136
|
-
- **Headers** - Complete header conversion and processing
|
|
137
|
-
- **Streaming Support** - Efficient handling of request/response bodies with AsyncIterableIterator
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## 📋 API Reference
|
|
142
|
-
|
|
143
|
-
### `toServerlessHandler(app: App)`
|
|
144
|
-
|
|
145
|
-
Converts a Vercube App instance into a serverless handler function.
|
|
146
|
-
|
|
147
|
-
**Parameters:**
|
|
148
|
-
|
|
149
|
-
- `app` - The Vercube App instance that will handle requests
|
|
150
|
-
|
|
151
|
-
**Returns:**
|
|
152
|
-
|
|
153
|
-
- An async function that accepts serverless events and returns platform-specific responses
|
|
154
|
-
|
|
155
|
-
**Examples:**
|
|
156
|
-
|
|
157
|
-
```ts
|
|
158
|
-
// AWS Lambda
|
|
159
|
-
import { createApp } from '@vercube/core';
|
|
160
|
-
import { toServerlessHandler } from '@vercube/serverless/aws-lambda';
|
|
161
|
-
|
|
162
|
-
const app = createApp();
|
|
163
|
-
export const handler = toServerlessHandler(app);
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
```ts
|
|
167
|
-
// Azure Functions
|
|
168
|
-
import { createApp } from '@vercube/core';
|
|
169
|
-
import { toServerlessHandler } from '@vercube/serverless/azure-functions';
|
|
170
|
-
|
|
171
|
-
const app = createApp();
|
|
172
|
-
export const handler = toServerlessHandler(app);
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
## 🔄 Request/Response Conversion
|
|
178
|
-
|
|
179
|
-
The serverless adapters handle automatic conversion between platform-specific events and standard web requests:
|
|
180
|
-
|
|
181
|
-
### Request Conversion
|
|
182
|
-
|
|
183
|
-
- **HTTP Method** - Extracted from event properties
|
|
184
|
-
- **URL Construction** - Built from path, query parameters, and headers
|
|
185
|
-
- **Headers** - Converted to standard Headers object
|
|
186
|
-
- **Body** - Properly decoded and converted to Request body
|
|
187
|
-
|
|
188
|
-
### Response Conversion
|
|
189
|
-
|
|
190
|
-
- **Status Code** - Mapped from Response status
|
|
191
|
-
- **Headers** - Converted to platform-specific format
|
|
192
|
-
- **Body** - Encoded appropriately (text vs binary for AWS, AsyncIterableIterator for Azure)
|
|
193
|
-
- **Cookies** - Handled for both API Gateway versions and Azure Functions
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
|
-
## 🚀 Performance Considerations
|
|
198
|
-
|
|
199
|
-
- **Streaming Support** - Efficient handling of large request/response bodies
|
|
200
|
-
- **Memory Optimization** - Minimal memory footprint for serverless environments
|
|
201
|
-
- **Cold Start Optimization** - Fast initialization and request processing
|
|
202
|
-
- **Binary Content** - Optimized base64 encoding for binary responses (AWS Lambda)
|
|
203
|
-
- **AsyncIterableIterator** - Efficient streaming for Azure Functions responses
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
## 🔍 Debugging
|
|
208
|
-
|
|
209
|
-
Enable debug logging to troubleshoot serverless deployments:
|
|
210
|
-
|
|
211
|
-
```ts
|
|
212
|
-
import { createApp } from '@vercube/core';
|
|
213
|
-
import { toServerlessHandler } from '@vercube/serverless/aws-lambda';
|
|
214
|
-
|
|
215
|
-
const app = createApp({
|
|
216
|
-
logger: {
|
|
217
|
-
level: 'debug',
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
export const handler = toServerlessHandler(app);
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
---
|
|
225
|
-
|
|
226
|
-
## 📚 Documentation
|
|
227
|
-
|
|
228
|
-
Full documentation is available at [**vercube.dev**](https://vercube.dev).
|
|
229
|
-
Explore guides, API references, and best practices to master Vercube serverless deployment.
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
## 🙌 Credits
|
|
234
|
-
|
|
235
|
-
This module is inspired by:
|
|
236
|
-
|
|
237
|
-
- [Nitro AWS Lambda Preset](https://nitro.build/presets/aws-lambda)
|
|
238
|
-
- [Hono AWS Lambda Adapter](https://hono.dev/guides/aws-lambda)
|
|
239
|
-
- [Vercel Serverless Functions](https://vercel.com/docs/functions)
|
|
240
|
-
- [hono-azurefunc-adapter](https://github.com/Marplex/hono-azurefunc-adapter)
|
|
34
|
+
## 📖 Usage
|
|
241
35
|
|
|
242
|
-
|
|
36
|
+
Check out the full [documentation](https://vercube.dev/docs/modules/serverless/overview)
|
|
243
37
|
|
|
244
|
-
##
|
|
38
|
+
## 📜 License
|
|
245
39
|
|
|
246
|
-
[MIT
|
|
40
|
+
[MIT](https://github.com/vercube/vercube/blob/main/LICENSE)
|
|
@@ -1,9 +1,295 @@
|
|
|
1
1
|
import { t as ServerlessHandler } from "../../ServerlessTypes-CIdGp_-x.mjs";
|
|
2
2
|
import { App } from "@vercube/core";
|
|
3
|
-
import {
|
|
3
|
+
import { Writable } from "node:stream";
|
|
4
4
|
|
|
5
|
+
//#region ../../node_modules/.pnpm/@types+aws-lambda@8.10.160/node_modules/@types/aws-lambda/common/api-gateway.d.ts
|
|
6
|
+
// Default authorizer type, prefer using a specific type with the "...WithAuthorizer..." variant types.
|
|
7
|
+
// Note that this doesn't have to be a context from a custom lambda outhorizer, AWS also has a cognito
|
|
8
|
+
// authorizer type and could add more, so the property won't always be a string.
|
|
9
|
+
type APIGatewayEventDefaultAuthorizerContext = undefined | null | {
|
|
10
|
+
[name: string]: any;
|
|
11
|
+
};
|
|
12
|
+
// The requestContext property of both request authorizer and proxy integration events.
|
|
13
|
+
interface APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext> {
|
|
14
|
+
accountId: string;
|
|
15
|
+
apiId: string; // This one is a bit confusing: it is not actually present in authorizer calls
|
|
16
|
+
// and proxy calls without an authorizer. We model this by allowing undefined in the type,
|
|
17
|
+
// since it ends up the same and avoids breaking users that are testing the property.
|
|
18
|
+
// This lets us allow parameterizing the authorizer for proxy events that know what authorizer
|
|
19
|
+
// context values they have.
|
|
20
|
+
authorizer: TAuthorizerContext;
|
|
21
|
+
connectedAt?: number | undefined;
|
|
22
|
+
connectionId?: string | undefined;
|
|
23
|
+
domainName?: string | undefined;
|
|
24
|
+
domainPrefix?: string | undefined;
|
|
25
|
+
eventType?: string | undefined;
|
|
26
|
+
extendedRequestId?: string | undefined;
|
|
27
|
+
protocol: string;
|
|
28
|
+
httpMethod: string;
|
|
29
|
+
identity: APIGatewayEventIdentity;
|
|
30
|
+
messageDirection?: string | undefined;
|
|
31
|
+
messageId?: string | null | undefined;
|
|
32
|
+
path: string;
|
|
33
|
+
stage: string;
|
|
34
|
+
requestId: string;
|
|
35
|
+
requestTime?: string | undefined;
|
|
36
|
+
requestTimeEpoch: number;
|
|
37
|
+
resourceId: string;
|
|
38
|
+
resourcePath: string;
|
|
39
|
+
routeKey?: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
interface APIGatewayEventClientCertificate {
|
|
42
|
+
clientCertPem: string;
|
|
43
|
+
serialNumber: string;
|
|
44
|
+
subjectDN: string;
|
|
45
|
+
issuerDN: string;
|
|
46
|
+
validity: {
|
|
47
|
+
notAfter: string;
|
|
48
|
+
notBefore: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface APIGatewayEventIdentity {
|
|
52
|
+
accessKey: string | null;
|
|
53
|
+
accountId: string | null;
|
|
54
|
+
apiKey: string | null;
|
|
55
|
+
apiKeyId: string | null;
|
|
56
|
+
caller: string | null;
|
|
57
|
+
clientCert: APIGatewayEventClientCertificate | null;
|
|
58
|
+
cognitoAuthenticationProvider: string | null;
|
|
59
|
+
cognitoAuthenticationType: string | null;
|
|
60
|
+
cognitoIdentityId: string | null;
|
|
61
|
+
cognitoIdentityPoolId: string | null;
|
|
62
|
+
principalOrgId: string | null;
|
|
63
|
+
sourceIp: string;
|
|
64
|
+
user: string | null;
|
|
65
|
+
userAgent: string | null;
|
|
66
|
+
userArn: string | null;
|
|
67
|
+
vpcId?: string | undefined;
|
|
68
|
+
vpceId?: string | undefined;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../../node_modules/.pnpm/@types+aws-lambda@8.10.160/node_modules/@types/aws-lambda/handler.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* {@link Handler} context parameter.
|
|
74
|
+
* See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}.
|
|
75
|
+
*/
|
|
76
|
+
interface Context {
|
|
77
|
+
callbackWaitsForEmptyEventLoop: boolean;
|
|
78
|
+
functionName: string;
|
|
79
|
+
functionVersion: string;
|
|
80
|
+
invokedFunctionArn: string;
|
|
81
|
+
memoryLimitInMB: string;
|
|
82
|
+
awsRequestId: string;
|
|
83
|
+
logGroupName: string;
|
|
84
|
+
logStreamName: string;
|
|
85
|
+
identity?: CognitoIdentity | undefined;
|
|
86
|
+
clientContext?: ClientContext | undefined;
|
|
87
|
+
tenantId?: string | undefined;
|
|
88
|
+
getRemainingTimeInMillis(): number; // Functions for compatibility with earlier Node.js Runtime v0.10.42
|
|
89
|
+
// No longer documented, so they are deprecated, but they still work
|
|
90
|
+
// as of the 12.x runtime, so they are not removed from the types.
|
|
91
|
+
/** @deprecated Use handler callback or promise result */
|
|
92
|
+
done(error?: Error, result?: any): void;
|
|
93
|
+
/** @deprecated Use handler callback with first argument or reject a promise result */
|
|
94
|
+
fail(error: Error | string): void;
|
|
95
|
+
/** @deprecated Use handler callback with second argument or resolve a promise result */
|
|
96
|
+
succeed(messageOrObject: any): void; // Unclear what behavior this is supposed to have, I couldn't find any still extant reference,
|
|
97
|
+
// and it behaves like the above, ignoring the object parameter.
|
|
98
|
+
/** @deprecated Use handler callback or promise result */
|
|
99
|
+
succeed(message: string, object: any): void;
|
|
100
|
+
}
|
|
101
|
+
interface CognitoIdentity {
|
|
102
|
+
cognitoIdentityId: string;
|
|
103
|
+
cognitoIdentityPoolId: string;
|
|
104
|
+
}
|
|
105
|
+
interface ClientContext {
|
|
106
|
+
client: ClientContextClient;
|
|
107
|
+
custom?: any;
|
|
108
|
+
env: ClientContextEnv;
|
|
109
|
+
}
|
|
110
|
+
interface ClientContextClient {
|
|
111
|
+
installationId: string;
|
|
112
|
+
appTitle: string;
|
|
113
|
+
appVersionName: string;
|
|
114
|
+
appVersionCode: string;
|
|
115
|
+
appPackageName: string;
|
|
116
|
+
}
|
|
117
|
+
interface ClientContextEnv {
|
|
118
|
+
platformVersion: string;
|
|
119
|
+
platform: string;
|
|
120
|
+
make: string;
|
|
121
|
+
model: string;
|
|
122
|
+
locale: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Interface for using response streaming from AWS Lambda.
|
|
126
|
+
* To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
|
|
127
|
+
*
|
|
128
|
+
* The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
|
|
129
|
+
* The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
|
|
130
|
+
*
|
|
131
|
+
* {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
|
|
132
|
+
* {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
|
|
133
|
+
*
|
|
134
|
+
* @example <caption>Writing to the response stream</caption>
|
|
135
|
+
* import 'aws-lambda';
|
|
136
|
+
*
|
|
137
|
+
* export const handler = awslambda.streamifyResponse(
|
|
138
|
+
* async (event, responseStream, context) => {
|
|
139
|
+
* responseStream.setContentType("text/plain");
|
|
140
|
+
* responseStream.write("Hello, world!");
|
|
141
|
+
* responseStream.end();
|
|
142
|
+
* }
|
|
143
|
+
* );
|
|
144
|
+
*
|
|
145
|
+
* @example <caption>Using pipeline</caption>
|
|
146
|
+
* import 'aws-lambda';
|
|
147
|
+
* import { Readable } from 'stream';
|
|
148
|
+
* import { pipeline } from 'stream/promises';
|
|
149
|
+
* import zlib from 'zlib';
|
|
150
|
+
*
|
|
151
|
+
* export const handler = awslambda.streamifyResponse(
|
|
152
|
+
* async (event, responseStream, context) => {
|
|
153
|
+
* // As an example, convert event to a readable stream.
|
|
154
|
+
* const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
|
|
155
|
+
*
|
|
156
|
+
* await pipeline(requestStream, zlib.createGzip(), responseStream);
|
|
157
|
+
* }
|
|
158
|
+
* );
|
|
159
|
+
*/
|
|
160
|
+
type StreamifyHandler<TEvent = any, TResult = any> = (event: TEvent, responseStream: awslambda.HttpResponseStream, context: Context) => TResult | Promise<TResult>;
|
|
161
|
+
declare global {
|
|
162
|
+
namespace awslambda {
|
|
163
|
+
class HttpResponseStream extends Writable {
|
|
164
|
+
static from(writable: Writable, metadata: Record<string, unknown>): HttpResponseStream;
|
|
165
|
+
setContentType: (contentType: string) => void;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Decorator for using response streaming from AWS Lambda.
|
|
169
|
+
* To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
|
|
170
|
+
*
|
|
171
|
+
* The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
|
|
172
|
+
* The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
|
|
173
|
+
*
|
|
174
|
+
* {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
|
|
175
|
+
* {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
|
|
176
|
+
*
|
|
177
|
+
* @example <caption>Writing to the response stream</caption>
|
|
178
|
+
* import 'aws-lambda';
|
|
179
|
+
*
|
|
180
|
+
* export const handler = awslambda.streamifyResponse(
|
|
181
|
+
* async (event, responseStream, context) => {
|
|
182
|
+
* responseStream.setContentType("text/plain");
|
|
183
|
+
* responseStream.write("Hello, world!");
|
|
184
|
+
* responseStream.end();
|
|
185
|
+
* }
|
|
186
|
+
* );
|
|
187
|
+
*
|
|
188
|
+
* @example <caption>Using pipeline</caption>
|
|
189
|
+
* import 'aws-lambda';
|
|
190
|
+
* import { Readable } from 'stream';
|
|
191
|
+
* import { pipeline } from 'stream/promises';
|
|
192
|
+
* import zlib from 'zlib';
|
|
193
|
+
*
|
|
194
|
+
* export const handler = awslambda.streamifyResponse(
|
|
195
|
+
* async (event, responseStream, context) => {
|
|
196
|
+
* // As an example, convert event to a readable stream.
|
|
197
|
+
* const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
|
|
198
|
+
*
|
|
199
|
+
* await pipeline(requestStream, zlib.createGzip(), responseStream);
|
|
200
|
+
* }
|
|
201
|
+
* );
|
|
202
|
+
*/
|
|
203
|
+
function streamifyResponse<TEvent = any, TResult = void>(handler: StreamifyHandler<TEvent, TResult>): StreamifyHandler<TEvent, TResult>;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region ../../node_modules/.pnpm/@types+aws-lambda@8.10.160/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
|
|
210
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
211
|
+
*/
|
|
212
|
+
type APIGatewayProxyEvent = APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
213
|
+
interface APIGatewayProxyEventHeaders {
|
|
214
|
+
[name: string]: string | undefined;
|
|
215
|
+
}
|
|
216
|
+
interface APIGatewayProxyEventMultiValueHeaders {
|
|
217
|
+
[name: string]: string[] | undefined;
|
|
218
|
+
}
|
|
219
|
+
interface APIGatewayProxyEventPathParameters {
|
|
220
|
+
[name: string]: string | undefined;
|
|
221
|
+
}
|
|
222
|
+
interface APIGatewayProxyEventQueryStringParameters {
|
|
223
|
+
[name: string]: string | undefined;
|
|
224
|
+
}
|
|
225
|
+
interface APIGatewayProxyEventMultiValueQueryStringParameters {
|
|
226
|
+
[name: string]: string[] | undefined;
|
|
227
|
+
}
|
|
228
|
+
interface APIGatewayProxyEventStageVariables {
|
|
229
|
+
[name: string]: string | undefined;
|
|
230
|
+
}
|
|
231
|
+
interface APIGatewayProxyEventBase<TAuthorizerContext> {
|
|
232
|
+
body: string | null;
|
|
233
|
+
headers: APIGatewayProxyEventHeaders;
|
|
234
|
+
multiValueHeaders: APIGatewayProxyEventMultiValueHeaders;
|
|
235
|
+
httpMethod: string;
|
|
236
|
+
isBase64Encoded: boolean;
|
|
237
|
+
path: string;
|
|
238
|
+
pathParameters: APIGatewayProxyEventPathParameters | null;
|
|
239
|
+
queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
|
|
240
|
+
multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
|
|
241
|
+
stageVariables: APIGatewayProxyEventStageVariables | null;
|
|
242
|
+
requestContext: APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext>;
|
|
243
|
+
resource: string;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Works with HTTP API integration Payload Format version 2.0
|
|
247
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
248
|
+
*/
|
|
249
|
+
interface APIGatewayEventRequestContextV2 {
|
|
250
|
+
accountId: string;
|
|
251
|
+
apiId: string;
|
|
252
|
+
authentication?: {
|
|
253
|
+
clientCert: APIGatewayEventClientCertificate;
|
|
254
|
+
};
|
|
255
|
+
domainName: string;
|
|
256
|
+
domainPrefix: string;
|
|
257
|
+
http: {
|
|
258
|
+
method: string;
|
|
259
|
+
path: string;
|
|
260
|
+
protocol: string;
|
|
261
|
+
sourceIp: string;
|
|
262
|
+
userAgent: string;
|
|
263
|
+
};
|
|
264
|
+
requestId: string;
|
|
265
|
+
routeKey: string;
|
|
266
|
+
stage: string;
|
|
267
|
+
time: string;
|
|
268
|
+
timeEpoch: number;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Proxy Event with adaptable requestContext for different authorizer scenarios
|
|
272
|
+
*/
|
|
273
|
+
interface APIGatewayProxyEventV2WithRequestContext<TRequestContext> {
|
|
274
|
+
version: string;
|
|
275
|
+
routeKey: string;
|
|
276
|
+
rawPath: string;
|
|
277
|
+
rawQueryString: string;
|
|
278
|
+
cookies?: string[];
|
|
279
|
+
headers: APIGatewayProxyEventHeaders;
|
|
280
|
+
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
|
281
|
+
requestContext: TRequestContext;
|
|
282
|
+
body?: string;
|
|
283
|
+
pathParameters?: APIGatewayProxyEventPathParameters;
|
|
284
|
+
isBase64Encoded: boolean;
|
|
285
|
+
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Default Proxy event with no Authorizer
|
|
289
|
+
*/
|
|
290
|
+
type APIGatewayProxyEventV2 = APIGatewayProxyEventV2WithRequestContext<APIGatewayEventRequestContextV2>;
|
|
291
|
+
//#endregion
|
|
5
292
|
//#region src/Adapters/aws-lambda/index.d.ts
|
|
6
|
-
|
|
7
293
|
/**
|
|
8
294
|
* Converts a Vercube App instance into an AWS Lambda handler function for API Gateway integration.
|
|
9
295
|
*
|
|
@@ -1,9 +1,139 @@
|
|
|
1
1
|
import { t as ServerlessHandler } from "../../ServerlessTypes-CIdGp_-x.mjs";
|
|
2
2
|
import { App } from "@vercube/core";
|
|
3
|
-
import {
|
|
3
|
+
import { Blob } from "buffer";
|
|
4
|
+
import { ReadableStream } from "stream/web";
|
|
5
|
+
import { URLSearchParams } from "url";
|
|
4
6
|
|
|
7
|
+
//#region ../../node_modules/.pnpm/@azure+functions@4.11.0/node_modules/@azure/functions/types/http.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* HTTP request object. Provided to your function when using HTTP Bindings.
|
|
10
|
+
*/
|
|
11
|
+
declare class HttpRequest {
|
|
12
|
+
/**
|
|
13
|
+
* For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
|
|
14
|
+
*/
|
|
15
|
+
constructor(httpRequestInit: HttpRequestInit);
|
|
16
|
+
/**
|
|
17
|
+
* HTTP request method used to invoke this function.
|
|
18
|
+
*/
|
|
19
|
+
readonly method: string;
|
|
20
|
+
/**
|
|
21
|
+
* Request URL.
|
|
22
|
+
*/
|
|
23
|
+
readonly url: string;
|
|
24
|
+
/**
|
|
25
|
+
* HTTP request headers.
|
|
26
|
+
*/
|
|
27
|
+
readonly headers: Headers;
|
|
28
|
+
/**
|
|
29
|
+
* Query string parameter keys and values from the URL.
|
|
30
|
+
*/
|
|
31
|
+
readonly query: URLSearchParams;
|
|
32
|
+
/**
|
|
33
|
+
* Route parameter keys and values.
|
|
34
|
+
*/
|
|
35
|
+
readonly params: HttpRequestParams;
|
|
36
|
+
/**
|
|
37
|
+
* Object representing logged-in user, either through
|
|
38
|
+
* AppService/Functions authentication, or SWA Authentication
|
|
39
|
+
* null when no such user is logged in.
|
|
40
|
+
*/
|
|
41
|
+
readonly user: HttpRequestUser | null;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the body as a ReadableStream
|
|
44
|
+
*/
|
|
45
|
+
readonly body: ReadableStream | null;
|
|
46
|
+
/**
|
|
47
|
+
* Returns whether the body has been read from
|
|
48
|
+
*/
|
|
49
|
+
readonly bodyUsed: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a promise fulfilled with the body as an ArrayBuffer
|
|
52
|
+
*/
|
|
53
|
+
readonly arrayBuffer: () => Promise<ArrayBuffer>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns a promise fulfilled with the body as a Blob
|
|
56
|
+
*/
|
|
57
|
+
readonly blob: () => Promise<Blob>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a promise fulfilled with the body as FormData
|
|
60
|
+
*/
|
|
61
|
+
readonly formData: () => Promise<FormData>;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a promise fulfilled with the body parsed as JSON
|
|
64
|
+
*/
|
|
65
|
+
readonly json: () => Promise<unknown>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns a promise fulfilled with the body as a string
|
|
68
|
+
*/
|
|
69
|
+
readonly text: () => Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a copy of the request object, with special handling of the body.
|
|
72
|
+
* [Learn more here](https://developer.mozilla.org/docs/Web/API/Request/clone)
|
|
73
|
+
*/
|
|
74
|
+
readonly clone: () => HttpRequest;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Route parameter keys and values.
|
|
78
|
+
*/
|
|
79
|
+
type HttpRequestParams = Record<string, string>;
|
|
80
|
+
/**
|
|
81
|
+
* Object representing logged-in user, either through
|
|
82
|
+
* AppService/Functions authentication, or SWA Authentication
|
|
83
|
+
*/
|
|
84
|
+
interface HttpRequestUser {
|
|
85
|
+
/**
|
|
86
|
+
* Type of authentication, either AppService or StaticWebApps
|
|
87
|
+
*/
|
|
88
|
+
type: HttpRequestUserType;
|
|
89
|
+
/**
|
|
90
|
+
* unique user GUID
|
|
91
|
+
*/
|
|
92
|
+
id: string;
|
|
93
|
+
/**
|
|
94
|
+
* unique username
|
|
95
|
+
*/
|
|
96
|
+
username: string;
|
|
97
|
+
/**
|
|
98
|
+
* provider of authentication service
|
|
99
|
+
*/
|
|
100
|
+
identityProvider: string;
|
|
101
|
+
/**
|
|
102
|
+
* Extra authentication information, dependent on auth type
|
|
103
|
+
* and auth provider
|
|
104
|
+
*/
|
|
105
|
+
claimsPrincipalData: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Possible values for an HTTP Request user type
|
|
109
|
+
*/
|
|
110
|
+
type HttpRequestUserType = 'AppService' | 'StaticWebApps';
|
|
111
|
+
/**
|
|
112
|
+
* For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
|
|
113
|
+
*/
|
|
114
|
+
interface HttpRequestInit {
|
|
115
|
+
method?: string;
|
|
116
|
+
url?: string;
|
|
117
|
+
body?: HttpRequestBodyInit;
|
|
118
|
+
headers?: Record<string, string>;
|
|
119
|
+
query?: Record<string, string>;
|
|
120
|
+
params?: Record<string, string>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* For testing purposes only. This will always be constructed for you when run in the context of the Azure Functions runtime
|
|
124
|
+
*/
|
|
125
|
+
interface HttpRequestBodyInit {
|
|
126
|
+
/**
|
|
127
|
+
* The body as a buffer. You only need to specify one of the `bytes` or `string` properties
|
|
128
|
+
*/
|
|
129
|
+
bytes?: Uint8Array;
|
|
130
|
+
/**
|
|
131
|
+
* The body as a string. You only need to specify one of the `bytes` or `string` properties
|
|
132
|
+
*/
|
|
133
|
+
string?: string;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
5
136
|
//#region src/Adapters/azure-functions/index.d.ts
|
|
6
|
-
|
|
7
137
|
/**
|
|
8
138
|
* Converts a Vercube App instance into an Azure Functions handler function for HTTP integration.
|
|
9
139
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/serverless",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "Serverless module for Vercube framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"type": "module",
|
|
13
|
-
"main": "./dist/index.mjs",
|
|
14
|
-
"module": "./dist/index.mjs",
|
|
15
13
|
"exports": {
|
|
16
14
|
".": "./dist/index.mjs",
|
|
17
15
|
"./package.json": "./package.json",
|
|
@@ -32,21 +30,24 @@
|
|
|
32
30
|
"aws-serverless",
|
|
33
31
|
"aws-api-gateway",
|
|
34
32
|
"aws-apigw",
|
|
35
|
-
"aws-apigw-lambda"
|
|
33
|
+
"aws-apigw-lambda",
|
|
34
|
+
"azure-functions",
|
|
35
|
+
"azure-function",
|
|
36
|
+
"azure-function-http"
|
|
36
37
|
],
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"ufo": "1.6.
|
|
39
|
-
"@vercube/core": "0.0.
|
|
40
|
-
"@vercube/di": "0.0.
|
|
39
|
+
"ufo": "1.6.3",
|
|
40
|
+
"@vercube/core": "0.0.35",
|
|
41
|
+
"@vercube/di": "0.0.35"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@azure/functions": "4.
|
|
44
|
-
"@types/aws-lambda": "8.10.
|
|
44
|
+
"@azure/functions": "4.11.0",
|
|
45
|
+
"@types/aws-lambda": "8.10.160"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
|
-
"build": "tsdown --config tsdown.config.ts"
|
|
51
|
+
"build": "tsdown --config tsdown.config.ts --config-loader=unrun"
|
|
51
52
|
}
|
|
52
53
|
}
|