@jaypie/express 1.2.3 → 1.2.4-rc0
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/cjs/adapter/LambdaRequest.d.ts +53 -0
- package/dist/cjs/adapter/LambdaResponseBuffered.d.ts +41 -0
- package/dist/cjs/adapter/LambdaResponseStreaming.d.ts +40 -0
- package/dist/cjs/adapter/__tests__/LambdaRequest.spec.d.ts +1 -0
- package/dist/cjs/adapter/__tests__/LambdaResponseBuffered.spec.d.ts +1 -0
- package/dist/cjs/adapter/__tests__/LambdaResponseStreaming.spec.d.ts +1 -0
- package/dist/cjs/adapter/__tests__/integration.spec.d.ts +1 -0
- package/dist/cjs/adapter/index.d.ts +50 -0
- package/dist/cjs/adapter/types.d.ts +75 -0
- package/dist/cjs/getCurrentInvokeUuid.adapter.d.ts +3 -3
- package/dist/cjs/index.cjs +650 -56
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +4 -2
- package/dist/esm/adapter/LambdaRequest.d.ts +53 -0
- package/dist/esm/adapter/LambdaResponseBuffered.d.ts +41 -0
- package/dist/esm/adapter/LambdaResponseStreaming.d.ts +40 -0
- package/dist/esm/adapter/__tests__/LambdaRequest.spec.d.ts +1 -0
- package/dist/esm/adapter/__tests__/LambdaResponseBuffered.spec.d.ts +1 -0
- package/dist/esm/adapter/__tests__/LambdaResponseStreaming.spec.d.ts +1 -0
- package/dist/esm/adapter/__tests__/integration.spec.d.ts +1 -0
- package/dist/esm/adapter/index.d.ts +50 -0
- package/dist/esm/adapter/types.d.ts +75 -0
- package/dist/esm/getCurrentInvokeUuid.adapter.d.ts +3 -3
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +644 -56
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Application } from "express";
|
|
2
|
+
import type { CreateLambdaHandlerOptions, FunctionUrlEvent, LambdaContext, LambdaHandler, LambdaStreamHandler } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Get the current Lambda invoke context.
|
|
5
|
+
* Used by getCurrentInvokeUuid adapter to get the request ID.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getCurrentInvoke(): {
|
|
8
|
+
context: LambdaContext;
|
|
9
|
+
event: FunctionUrlEvent;
|
|
10
|
+
} | null;
|
|
11
|
+
/**
|
|
12
|
+
* Create a Lambda handler that buffers the Express response.
|
|
13
|
+
* Returns the complete response as a Lambda response object.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import express from "express";
|
|
18
|
+
* import { createLambdaHandler } from "@jaypie/express";
|
|
19
|
+
*
|
|
20
|
+
* const app = express();
|
|
21
|
+
* app.get("/", (req, res) => res.json({ message: "Hello" }));
|
|
22
|
+
*
|
|
23
|
+
* export const handler = createLambdaHandler(app);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createLambdaHandler(app: Application, _options?: CreateLambdaHandlerOptions): LambdaHandler;
|
|
27
|
+
/**
|
|
28
|
+
* Create a Lambda handler that streams the Express response.
|
|
29
|
+
* Uses awslambda.streamifyResponse() for Lambda response streaming.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import express from "express";
|
|
34
|
+
* import { createLambdaStreamHandler } from "@jaypie/express";
|
|
35
|
+
*
|
|
36
|
+
* const app = express();
|
|
37
|
+
* app.get("/stream", (req, res) => {
|
|
38
|
+
* res.setHeader("Content-Type", "text/event-stream");
|
|
39
|
+
* res.write("data: Hello\n\n");
|
|
40
|
+
* res.end();
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* export const handler = createLambdaStreamHandler(app);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function createLambdaStreamHandler(app: Application, _options?: CreateLambdaHandlerOptions): LambdaStreamHandler;
|
|
47
|
+
export { LambdaRequest, createLambdaRequest } from "./LambdaRequest.js";
|
|
48
|
+
export { LambdaResponseBuffered } from "./LambdaResponseBuffered.js";
|
|
49
|
+
export { LambdaResponseStreaming } from "./LambdaResponseStreaming.js";
|
|
50
|
+
export type { AwsLambdaGlobal, CreateLambdaHandlerOptions, FunctionUrlEvent, HttpResponseStreamMetadata, LambdaContext, LambdaHandler, LambdaHandlerFactory, LambdaResponse, LambdaStreamHandler, LambdaStreamHandlerFactory, ResponseStream, } from "./types.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Application } from "express";
|
|
2
|
+
export interface LambdaContext {
|
|
3
|
+
awsRequestId: string;
|
|
4
|
+
callbackWaitsForEmptyEventLoop?: boolean;
|
|
5
|
+
functionName?: string;
|
|
6
|
+
functionVersion?: string;
|
|
7
|
+
invokedFunctionArn?: string;
|
|
8
|
+
logGroupName?: string;
|
|
9
|
+
logStreamName?: string;
|
|
10
|
+
memoryLimitInMB?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface FunctionUrlEvent {
|
|
14
|
+
body?: string;
|
|
15
|
+
cookies?: string[];
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
isBase64Encoded: boolean;
|
|
18
|
+
rawPath: string;
|
|
19
|
+
rawQueryString: string;
|
|
20
|
+
requestContext: {
|
|
21
|
+
accountId: string;
|
|
22
|
+
apiId: string;
|
|
23
|
+
domainName: string;
|
|
24
|
+
domainPrefix: string;
|
|
25
|
+
http: {
|
|
26
|
+
method: string;
|
|
27
|
+
path: string;
|
|
28
|
+
protocol: string;
|
|
29
|
+
sourceIp: string;
|
|
30
|
+
userAgent: string;
|
|
31
|
+
};
|
|
32
|
+
requestId: string;
|
|
33
|
+
routeKey: string;
|
|
34
|
+
stage: string;
|
|
35
|
+
time: string;
|
|
36
|
+
timeEpoch: number;
|
|
37
|
+
};
|
|
38
|
+
routeKey: string;
|
|
39
|
+
version: "2.0";
|
|
40
|
+
}
|
|
41
|
+
export interface LambdaResponse {
|
|
42
|
+
body: string;
|
|
43
|
+
cookies?: string[];
|
|
44
|
+
headers: Record<string, string>;
|
|
45
|
+
isBase64Encoded: boolean;
|
|
46
|
+
statusCode: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ResponseStream {
|
|
49
|
+
end(): void;
|
|
50
|
+
write(chunk: string | Uint8Array): void;
|
|
51
|
+
}
|
|
52
|
+
export interface HttpResponseStreamMetadata {
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
statusCode: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Global awslambda object provided by Lambda runtime.
|
|
58
|
+
* This is only available when running in AWS Lambda.
|
|
59
|
+
*/
|
|
60
|
+
export interface AwsLambdaGlobal {
|
|
61
|
+
HttpResponseStream: {
|
|
62
|
+
from(stream: ResponseStream, metadata: HttpResponseStreamMetadata): ResponseStream;
|
|
63
|
+
};
|
|
64
|
+
streamifyResponse<TEvent = unknown>(handler: (event: TEvent, responseStream: ResponseStream, context: LambdaContext) => Promise<void>): (event: TEvent, context: LambdaContext) => Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export type LambdaHandler = (event: FunctionUrlEvent, context: LambdaContext) => Promise<LambdaResponse>;
|
|
67
|
+
export type LambdaStreamHandler = (event: FunctionUrlEvent, context: LambdaContext) => Promise<void>;
|
|
68
|
+
export type CreateLambdaHandlerOptions = {
|
|
69
|
+
/**
|
|
70
|
+
* Optional name for logging and debugging
|
|
71
|
+
*/
|
|
72
|
+
name?: string;
|
|
73
|
+
};
|
|
74
|
+
export type LambdaHandlerFactory = (app: Application, options?: CreateLambdaHandlerOptions) => LambdaHandler;
|
|
75
|
+
export type LambdaStreamHandlerFactory = (app: Application, options?: CreateLambdaHandlerOptions) => LambdaStreamHandler;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Request } from "express";
|
|
2
2
|
/**
|
|
3
3
|
* Get the current invoke UUID from Lambda context.
|
|
4
|
-
* Works
|
|
4
|
+
* Works with Jaypie Lambda adapter and Lambda Web Adapter mode.
|
|
5
5
|
*
|
|
6
|
-
* @param req - Optional Express request object.
|
|
7
|
-
*
|
|
6
|
+
* @param req - Optional Express request object. Used to extract context
|
|
7
|
+
* from Web Adapter headers or Jaypie adapter's _lambdaContext.
|
|
8
8
|
* @returns The AWS request ID or undefined if not in Lambda context
|
|
9
9
|
*/
|
|
10
10
|
declare function getCurrentInvokeUuid(req?: Request): string | undefined;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
export { createLambdaHandler, createLambdaStreamHandler, getCurrentInvoke, LambdaRequest, LambdaResponseBuffered, LambdaResponseStreaming, } from "./adapter/index.js";
|
|
2
|
+
export type { CreateLambdaHandlerOptions, FunctionUrlEvent, LambdaHandler, LambdaResponse, LambdaStreamHandler, } from "./adapter/index.js";
|
|
1
3
|
export { EXPRESS } from "./constants.js";
|
|
2
4
|
export { default as cors } from "./cors.helper.js";
|
|
5
|
+
export type { CorsConfig } from "./cors.helper.js";
|
|
3
6
|
export { default as createServer } from "./createServer.js";
|
|
4
7
|
export type { CreateServerOptions, ServerResult } from "./createServer.js";
|
|
5
8
|
export { default as expressHandler } from "./expressHandler.js";
|
|
6
9
|
export type { ExpressHandlerLocals, ExpressHandlerOptions, JaypieHandlerSetup, JaypieHandlerTeardown, JaypieHandlerValidate, } from "./expressHandler.js";
|
|
10
|
+
export { default as expressHttpCodeHandler } from "./http.handler.js";
|
|
7
11
|
export { default as expressStreamHandler } from "./expressStreamHandler.js";
|
|
8
12
|
export type { ExpressStreamHandler, ExpressStreamHandlerLocals, ExpressStreamHandlerOptions, JaypieStreamHandlerSetup, JaypieStreamHandlerTeardown, JaypieStreamHandlerValidate, } from "./expressStreamHandler.js";
|
|
9
|
-
export type { CorsConfig } from "./cors.helper.js";
|
|
10
13
|
export { default as getCurrentInvokeUuid } from "./getCurrentInvokeUuid.adapter.js";
|
|
11
|
-
export { default as expressHttpCodeHandler } from "./http.handler.js";
|
|
12
14
|
export * from "./routes.js";
|