@restatedev/restate-sdk-cloudflare-workers 1.10.4 → 1.11.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/context_impl.cjs +17 -6
- package/dist/context_impl.js +17 -6
- package/dist/context_impl.js.map +1 -1
- package/dist/endpoint/endpoint.cjs +2 -2
- package/dist/endpoint/endpoint.js +2 -2
- package/dist/endpoint/fetch_endpoint.cjs +2 -2
- package/dist/endpoint/fetch_endpoint.js +2 -2
- package/dist/endpoint/fetch_endpoint.js.map +1 -1
- package/dist/endpoint/handlers/core_logging.cjs +52 -0
- package/dist/endpoint/handlers/core_logging.js +51 -0
- package/dist/endpoint/handlers/core_logging.js.map +1 -0
- package/dist/endpoint/handlers/discovery.cjs +58 -0
- package/dist/endpoint/handlers/discovery.js +59 -0
- package/dist/endpoint/handlers/discovery.js.map +1 -0
- package/dist/endpoint/handlers/fetch.cjs +23 -11
- package/dist/endpoint/handlers/fetch.js +24 -11
- package/dist/endpoint/handlers/fetch.js.map +1 -1
- package/dist/endpoint/handlers/generic.cjs +167 -253
- package/dist/endpoint/handlers/generic.js +166 -249
- package/dist/endpoint/handlers/generic.js.map +1 -1
- package/dist/endpoint/handlers/lambda.cjs +64 -61
- package/dist/endpoint/handlers/lambda.js +64 -60
- package/dist/endpoint/handlers/lambda.js.map +1 -1
- package/dist/endpoint/handlers/utils.cjs +51 -0
- package/dist/endpoint/handlers/utils.js +48 -0
- package/dist/endpoint/handlers/utils.js.map +1 -0
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +13 -13
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.js +20 -20
- package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm +0 -0
- package/dist/endpoint/lambda_endpoint.cjs +2 -2
- package/dist/endpoint/lambda_endpoint.js +2 -2
- package/dist/endpoint/lambda_endpoint.js.map +1 -1
- package/dist/endpoint/node_endpoint.cjs +41 -41
- package/dist/endpoint/node_endpoint.js +41 -40
- package/dist/endpoint/node_endpoint.js.map +1 -1
- package/dist/io.cjs +2 -2
- package/dist/io.js +2 -2
- package/dist/io.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/types/errors.cjs +2 -0
- package/dist/types/errors.d.cts +8 -0
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +8 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +2 -0
- package/dist/types/errors.js.map +1 -1
- package/package.json +3 -3
- package/dist/utils/streams.cjs +0 -14
- package/dist/utils/streams.js +0 -13
- package/dist/utils/streams.js.map +0 -1
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_errors = require('../../types/errors.cjs');
|
|
3
3
|
const require_user_agent = require('../../user_agent.cjs');
|
|
4
|
-
const
|
|
5
|
-
const require_generic = require('./generic.cjs');
|
|
6
|
-
let node_stream_web = require("node:stream/web");
|
|
7
|
-
node_stream_web = require_rolldown_runtime.__toESM(node_stream_web);
|
|
4
|
+
const require_utils = require('./utils.cjs');
|
|
8
5
|
let node_buffer = require("node:buffer");
|
|
9
6
|
node_buffer = require_rolldown_runtime.__toESM(node_buffer);
|
|
10
7
|
let node_zlib = require("node:zlib");
|
|
@@ -18,70 +15,76 @@ var LambdaHandler = class {
|
|
|
18
15
|
this.compressionSupported = compressionSupported;
|
|
19
16
|
}
|
|
20
17
|
async handleRequest(event, context) {
|
|
21
|
-
const path = "path" in event ? event.path : event.rawPath;
|
|
22
|
-
let requestContentEncoding;
|
|
23
|
-
let requestAcceptEncoding;
|
|
24
|
-
for (const [key, value] of Object.entries(event.headers)) if (key.localeCompare("content-encoding", void 0, { sensitivity: "accent" }) === 0) requestContentEncoding = value;
|
|
25
|
-
else if (key.localeCompare("accept-encoding", void 0, { sensitivity: "accent" }) === 0) requestAcceptEncoding = value;
|
|
26
|
-
let bodyStream;
|
|
27
|
-
if (!event.body) bodyStream = null;
|
|
28
|
-
else {
|
|
29
|
-
let bodyBuffer;
|
|
30
|
-
if (event.isBase64Encoded) bodyBuffer = node_buffer.Buffer.from(event.body, "base64");
|
|
31
|
-
else bodyBuffer = node_buffer.Buffer.from(new TextEncoder().encode(event.body));
|
|
32
|
-
if (requestContentEncoding && requestContentEncoding.includes("zstd")) {
|
|
33
|
-
if (!this.compressionSupported) throw new Error("The input is compressed using zstd, but this lambda deployment doesn't support compression. Make sure to deploy the Lambda using Node > 22");
|
|
34
|
-
bodyBuffer = node_zlib.zstdDecompressSync(bodyBuffer);
|
|
35
|
-
}
|
|
36
|
-
bodyStream = require_streams.OnceStream(bodyBuffer);
|
|
37
|
-
}
|
|
38
18
|
const abortController = new AbortController();
|
|
39
|
-
const request = {
|
|
40
|
-
body: bodyStream,
|
|
41
|
-
headers: event.headers,
|
|
42
|
-
url: path,
|
|
43
|
-
extraArgs: [context],
|
|
44
|
-
abortSignal: abortController.signal
|
|
45
|
-
};
|
|
46
|
-
let response;
|
|
47
|
-
try {
|
|
48
|
-
response = await this.handler.handle(request, { AWSRequestId: context.awsRequestId });
|
|
49
|
-
} catch (e) {
|
|
50
|
-
abortController.abort();
|
|
51
|
-
throw e;
|
|
52
|
-
}
|
|
53
|
-
const chunks = [];
|
|
54
19
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
20
|
+
const path = "path" in event ? event.path : event.rawPath;
|
|
21
|
+
let requestContentEncoding;
|
|
22
|
+
let requestAcceptEncoding;
|
|
23
|
+
for (const [key, value] of Object.entries(event.headers)) if (key.localeCompare("content-encoding", void 0, { sensitivity: "accent" }) === 0) requestContentEncoding = value;
|
|
24
|
+
else if (key.localeCompare("accept-encoding", void 0, { sensitivity: "accent" }) === 0) requestAcceptEncoding = value;
|
|
25
|
+
let inputReader;
|
|
26
|
+
if (!event.body) inputReader = require_utils.emptyInputReader();
|
|
27
|
+
else {
|
|
28
|
+
let bodyBuffer;
|
|
29
|
+
if (event.isBase64Encoded) bodyBuffer = node_buffer.Buffer.from(event.body, "base64");
|
|
30
|
+
else bodyBuffer = node_buffer.Buffer.from(new TextEncoder().encode(event.body));
|
|
31
|
+
if (requestContentEncoding && requestContentEncoding.includes("zstd")) {
|
|
32
|
+
if (!this.compressionSupported) throw new Error("The input is compressed using zstd, but this lambda deployment doesn't support compression. Make sure to deploy the Lambda using Node > 22");
|
|
33
|
+
bodyBuffer = node_zlib.zstdDecompressSync(bodyBuffer);
|
|
34
|
+
}
|
|
35
|
+
inputReader = (async function* () {
|
|
36
|
+
yield bodyBuffer;
|
|
37
|
+
})()[Symbol.asyncIterator]();
|
|
38
|
+
}
|
|
39
|
+
const chunks = [];
|
|
40
|
+
const outputWriter = {
|
|
41
|
+
write: function(value) {
|
|
42
|
+
chunks.push(value);
|
|
43
|
+
return Promise.resolve();
|
|
65
44
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
45
|
+
close: function() {
|
|
46
|
+
return Promise.resolve();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const response = this.handler.handle({
|
|
50
|
+
headers: event.headers,
|
|
51
|
+
url: path,
|
|
52
|
+
extraArgs: [context]
|
|
53
|
+
}, { AWSRequestId: context.awsRequestId });
|
|
54
|
+
try {
|
|
55
|
+
await response.process({
|
|
56
|
+
inputReader,
|
|
57
|
+
outputWriter,
|
|
58
|
+
abortSignal: abortController.signal
|
|
59
|
+
});
|
|
60
|
+
} catch (e) {
|
|
61
|
+
const error = require_errors.ensureError(e);
|
|
62
|
+
(require_utils.tryCreateContextualLogger(this.handler.endpoint.loggerTransport, path, event.headers) ?? this.handler.endpoint.rlog).error("Unexpected error: " + (error.stack ?? error.message));
|
|
63
|
+
return {
|
|
64
|
+
headers: {
|
|
65
|
+
"content-type": "application/json",
|
|
66
|
+
"x-restate-server": require_user_agent.X_RESTATE_SERVER
|
|
67
|
+
},
|
|
68
|
+
statusCode: 500,
|
|
69
|
+
isBase64Encoded: false,
|
|
70
|
+
body: JSON.stringify({ message: error.message })
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const responseBodyBuffer = node_buffer.Buffer.concat(chunks);
|
|
74
|
+
let responseBody;
|
|
75
|
+
if (this.compressionSupported && responseBodyBuffer.length > RESPONSE_COMPRESSION_THRESHOLD && requestAcceptEncoding && requestAcceptEncoding.includes("zstd")) {
|
|
76
|
+
response.headers["content-encoding"] = "zstd";
|
|
77
|
+
responseBody = node_zlib.zstdCompressSync(responseBodyBuffer).toString("base64");
|
|
78
|
+
} else responseBody = responseBodyBuffer.toString("base64");
|
|
79
|
+
return {
|
|
80
|
+
headers: response.headers,
|
|
81
|
+
statusCode: response.statusCode,
|
|
82
|
+
isBase64Encoded: true,
|
|
83
|
+
body: responseBody
|
|
69
84
|
};
|
|
70
85
|
} finally {
|
|
71
86
|
abortController.abort();
|
|
72
87
|
}
|
|
73
|
-
const responseBodyBuffer = node_buffer.Buffer.concat(chunks);
|
|
74
|
-
let responseBody;
|
|
75
|
-
if (this.compressionSupported && responseBodyBuffer.length > RESPONSE_COMPRESSION_THRESHOLD && requestAcceptEncoding && requestAcceptEncoding.includes("zstd")) {
|
|
76
|
-
response.headers["content-encoding"] = "zstd";
|
|
77
|
-
responseBody = node_zlib.zstdCompressSync(responseBodyBuffer).toString("base64");
|
|
78
|
-
} else responseBody = responseBodyBuffer.toString("base64");
|
|
79
|
-
return {
|
|
80
|
-
headers: response.headers,
|
|
81
|
-
statusCode: response.statusCode,
|
|
82
|
-
isBase64Encoded: true,
|
|
83
|
-
body: responseBody
|
|
84
|
-
};
|
|
85
88
|
}
|
|
86
89
|
};
|
|
87
90
|
function isCompressionSupported() {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ensureError } from "../../types/errors.js";
|
|
2
2
|
import { X_RESTATE_SERVER } from "../../user_agent.js";
|
|
3
|
-
import {
|
|
4
|
-
import { tryCreateContextualLogger } from "./generic.js";
|
|
5
|
-
import { WritableStream } from "node:stream/web";
|
|
3
|
+
import { emptyInputReader, tryCreateContextualLogger } from "./utils.js";
|
|
6
4
|
import { Buffer } from "node:buffer";
|
|
7
5
|
import * as zlib from "node:zlib";
|
|
8
6
|
|
|
@@ -14,70 +12,76 @@ var LambdaHandler = class {
|
|
|
14
12
|
this.compressionSupported = compressionSupported;
|
|
15
13
|
}
|
|
16
14
|
async handleRequest(event, context) {
|
|
17
|
-
const path = "path" in event ? event.path : event.rawPath;
|
|
18
|
-
let requestContentEncoding;
|
|
19
|
-
let requestAcceptEncoding;
|
|
20
|
-
for (const [key, value] of Object.entries(event.headers)) if (key.localeCompare("content-encoding", void 0, { sensitivity: "accent" }) === 0) requestContentEncoding = value;
|
|
21
|
-
else if (key.localeCompare("accept-encoding", void 0, { sensitivity: "accent" }) === 0) requestAcceptEncoding = value;
|
|
22
|
-
let bodyStream;
|
|
23
|
-
if (!event.body) bodyStream = null;
|
|
24
|
-
else {
|
|
25
|
-
let bodyBuffer;
|
|
26
|
-
if (event.isBase64Encoded) bodyBuffer = Buffer.from(event.body, "base64");
|
|
27
|
-
else bodyBuffer = Buffer.from(new TextEncoder().encode(event.body));
|
|
28
|
-
if (requestContentEncoding && requestContentEncoding.includes("zstd")) {
|
|
29
|
-
if (!this.compressionSupported) throw new Error("The input is compressed using zstd, but this lambda deployment doesn't support compression. Make sure to deploy the Lambda using Node > 22");
|
|
30
|
-
bodyBuffer = zlib.zstdDecompressSync(bodyBuffer);
|
|
31
|
-
}
|
|
32
|
-
bodyStream = OnceStream(bodyBuffer);
|
|
33
|
-
}
|
|
34
15
|
const abortController = new AbortController();
|
|
35
|
-
const request = {
|
|
36
|
-
body: bodyStream,
|
|
37
|
-
headers: event.headers,
|
|
38
|
-
url: path,
|
|
39
|
-
extraArgs: [context],
|
|
40
|
-
abortSignal: abortController.signal
|
|
41
|
-
};
|
|
42
|
-
let response;
|
|
43
|
-
try {
|
|
44
|
-
response = await this.handler.handle(request, { AWSRequestId: context.awsRequestId });
|
|
45
|
-
} catch (e) {
|
|
46
|
-
abortController.abort();
|
|
47
|
-
throw e;
|
|
48
|
-
}
|
|
49
|
-
const chunks = [];
|
|
50
16
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
17
|
+
const path = "path" in event ? event.path : event.rawPath;
|
|
18
|
+
let requestContentEncoding;
|
|
19
|
+
let requestAcceptEncoding;
|
|
20
|
+
for (const [key, value] of Object.entries(event.headers)) if (key.localeCompare("content-encoding", void 0, { sensitivity: "accent" }) === 0) requestContentEncoding = value;
|
|
21
|
+
else if (key.localeCompare("accept-encoding", void 0, { sensitivity: "accent" }) === 0) requestAcceptEncoding = value;
|
|
22
|
+
let inputReader;
|
|
23
|
+
if (!event.body) inputReader = emptyInputReader();
|
|
24
|
+
else {
|
|
25
|
+
let bodyBuffer;
|
|
26
|
+
if (event.isBase64Encoded) bodyBuffer = Buffer.from(event.body, "base64");
|
|
27
|
+
else bodyBuffer = Buffer.from(new TextEncoder().encode(event.body));
|
|
28
|
+
if (requestContentEncoding && requestContentEncoding.includes("zstd")) {
|
|
29
|
+
if (!this.compressionSupported) throw new Error("The input is compressed using zstd, but this lambda deployment doesn't support compression. Make sure to deploy the Lambda using Node > 22");
|
|
30
|
+
bodyBuffer = zlib.zstdDecompressSync(bodyBuffer);
|
|
31
|
+
}
|
|
32
|
+
inputReader = (async function* () {
|
|
33
|
+
yield bodyBuffer;
|
|
34
|
+
})()[Symbol.asyncIterator]();
|
|
35
|
+
}
|
|
36
|
+
const chunks = [];
|
|
37
|
+
const outputWriter = {
|
|
38
|
+
write: function(value) {
|
|
39
|
+
chunks.push(value);
|
|
40
|
+
return Promise.resolve();
|
|
61
41
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
42
|
+
close: function() {
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const response = this.handler.handle({
|
|
47
|
+
headers: event.headers,
|
|
48
|
+
url: path,
|
|
49
|
+
extraArgs: [context]
|
|
50
|
+
}, { AWSRequestId: context.awsRequestId });
|
|
51
|
+
try {
|
|
52
|
+
await response.process({
|
|
53
|
+
inputReader,
|
|
54
|
+
outputWriter,
|
|
55
|
+
abortSignal: abortController.signal
|
|
56
|
+
});
|
|
57
|
+
} catch (e) {
|
|
58
|
+
const error = ensureError(e);
|
|
59
|
+
(tryCreateContextualLogger(this.handler.endpoint.loggerTransport, path, event.headers) ?? this.handler.endpoint.rlog).error("Unexpected error: " + (error.stack ?? error.message));
|
|
60
|
+
return {
|
|
61
|
+
headers: {
|
|
62
|
+
"content-type": "application/json",
|
|
63
|
+
"x-restate-server": X_RESTATE_SERVER
|
|
64
|
+
},
|
|
65
|
+
statusCode: 500,
|
|
66
|
+
isBase64Encoded: false,
|
|
67
|
+
body: JSON.stringify({ message: error.message })
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const responseBodyBuffer = Buffer.concat(chunks);
|
|
71
|
+
let responseBody;
|
|
72
|
+
if (this.compressionSupported && responseBodyBuffer.length > RESPONSE_COMPRESSION_THRESHOLD && requestAcceptEncoding && requestAcceptEncoding.includes("zstd")) {
|
|
73
|
+
response.headers["content-encoding"] = "zstd";
|
|
74
|
+
responseBody = zlib.zstdCompressSync(responseBodyBuffer).toString("base64");
|
|
75
|
+
} else responseBody = responseBodyBuffer.toString("base64");
|
|
76
|
+
return {
|
|
77
|
+
headers: response.headers,
|
|
78
|
+
statusCode: response.statusCode,
|
|
79
|
+
isBase64Encoded: true,
|
|
80
|
+
body: responseBody
|
|
65
81
|
};
|
|
66
82
|
} finally {
|
|
67
83
|
abortController.abort();
|
|
68
84
|
}
|
|
69
|
-
const responseBodyBuffer = Buffer.concat(chunks);
|
|
70
|
-
let responseBody;
|
|
71
|
-
if (this.compressionSupported && responseBodyBuffer.length > RESPONSE_COMPRESSION_THRESHOLD && requestAcceptEncoding && requestAcceptEncoding.includes("zstd")) {
|
|
72
|
-
response.headers["content-encoding"] = "zstd";
|
|
73
|
-
responseBody = zlib.zstdCompressSync(responseBodyBuffer).toString("base64");
|
|
74
|
-
} else responseBody = responseBodyBuffer.toString("base64");
|
|
75
|
-
return {
|
|
76
|
-
headers: response.headers,
|
|
77
|
-
statusCode: response.statusCode,
|
|
78
|
-
isBase64Encoded: true,
|
|
79
|
-
body: responseBody
|
|
80
|
-
};
|
|
81
85
|
}
|
|
82
86
|
};
|
|
83
87
|
function isCompressionSupported() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda.js","names":["handler:
|
|
1
|
+
{"version":3,"file":"lambda.js","names":["handler: RestateHandler","compressionSupported: boolean","inputReader: InputReader","bodyBuffer: Buffer | undefined","chunks: Uint8Array[]","outputWriter: OutputWriter"],"sources":["../../../src/endpoint/handlers/lambda.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nimport type {\n APIGatewayProxyEvent,\n APIGatewayProxyEventV2,\n APIGatewayProxyResult,\n APIGatewayProxyStructuredResultV2,\n Context,\n} from \"aws-lambda\";\nimport { Buffer } from \"node:buffer\";\nimport { X_RESTATE_SERVER } from \"../../user_agent.js\";\nimport { ensureError } from \"../../types/errors.js\";\nimport * as zlib from \"node:zlib\";\nimport { InputReader, OutputWriter, RestateHandler } from \"./types.js\";\nimport { emptyInputReader, tryCreateContextualLogger } from \"./utils.js\";\n\nconst RESPONSE_COMPRESSION_THRESHOLD = 3 * 1024 * 1024;\n\nexport class LambdaHandler {\n constructor(\n private readonly handler: RestateHandler,\n private readonly compressionSupported: boolean\n ) {}\n\n async handleRequest(\n event: APIGatewayProxyEvent | APIGatewayProxyEventV2,\n context: Context\n ): Promise<APIGatewayProxyResult | APIGatewayProxyStructuredResultV2> {\n const abortController = new AbortController();\n try {\n //\n // Request path\n //\n const path = \"path\" in event ? event.path : event.rawPath;\n\n // Deal with content-encoding\n let requestContentEncoding;\n let requestAcceptEncoding;\n for (const [key, value] of Object.entries(event.headers)) {\n if (\n key.localeCompare(\"content-encoding\", undefined, {\n sensitivity: \"accent\",\n }) === 0\n ) {\n requestContentEncoding = value;\n } else if (\n key.localeCompare(\"accept-encoding\", undefined, {\n sensitivity: \"accent\",\n }) === 0\n ) {\n requestAcceptEncoding = value;\n }\n }\n\n //\n // Convert the request body to a Uint8Array stream\n // Lambda functions receive the body as base64 encoded string\n //\n let inputReader: InputReader;\n if (!event.body) {\n inputReader = emptyInputReader();\n } else {\n let bodyBuffer: Buffer | undefined;\n if (event.isBase64Encoded) {\n bodyBuffer = Buffer.from(event.body, \"base64\");\n } else {\n bodyBuffer = Buffer.from(new TextEncoder().encode(event.body));\n }\n\n // Now decode if needed\n if (requestContentEncoding && requestContentEncoding.includes(\"zstd\")) {\n if (!this.compressionSupported) {\n throw new Error(\n \"The input is compressed using zstd, but this lambda deployment doesn't support compression. Make sure to deploy the Lambda using Node > 22\"\n );\n }\n\n // Input encoded with zstd, let's decode it!\n bodyBuffer = (\n zlib as unknown as { zstdDecompressSync: (b: Buffer) => Buffer }\n ).zstdDecompressSync(bodyBuffer);\n }\n\n // Prep the stream to pass through the endpoint handler\n // eslint-disable-next-line @typescript-eslint/require-await\n inputReader = (async function* () {\n yield bodyBuffer as Uint8Array;\n })()[Symbol.asyncIterator]();\n }\n\n const chunks: Uint8Array[] = [];\n const outputWriter: OutputWriter = {\n write: function (value: Uint8Array): Promise<void> {\n chunks.push(value);\n return Promise.resolve();\n },\n close: function (): Promise<void> {\n return Promise.resolve();\n },\n };\n\n const response = this.handler.handle(\n {\n headers: event.headers,\n url: path,\n extraArgs: [context],\n },\n {\n AWSRequestId: context.awsRequestId,\n }\n );\n\n try {\n await response.process({\n inputReader,\n outputWriter,\n abortSignal: abortController.signal,\n });\n } catch (e) {\n // handle should never throw\n const error = ensureError(e);\n const logger =\n tryCreateContextualLogger(\n this.handler.endpoint.loggerTransport,\n path,\n event.headers\n ) ?? this.handler.endpoint.rlog;\n logger.error(\"Unexpected error: \" + (error.stack ?? error.message));\n return {\n headers: {\n \"content-type\": \"application/json\",\n \"x-restate-server\": X_RESTATE_SERVER,\n },\n statusCode: 500,\n isBase64Encoded: false,\n body: JSON.stringify({ message: error.message }),\n };\n }\n\n const responseBodyBuffer = Buffer.concat(chunks);\n let responseBody;\n\n // Now let's encode if we need to.\n if (\n this.compressionSupported &&\n responseBodyBuffer.length > RESPONSE_COMPRESSION_THRESHOLD &&\n requestAcceptEncoding &&\n requestAcceptEncoding.includes(\"zstd\")\n ) {\n response.headers[\"content-encoding\"] = \"zstd\";\n\n responseBody = (\n zlib as unknown as { zstdCompressSync: (b: Buffer) => Buffer }\n )\n .zstdCompressSync(responseBodyBuffer)\n .toString(\"base64\");\n } else {\n responseBody = responseBodyBuffer.toString(\"base64\");\n }\n return {\n headers: response.headers,\n statusCode: response.statusCode,\n isBase64Encoded: true,\n body: responseBody,\n };\n } finally {\n abortController.abort();\n }\n }\n}\n\nexport function isCompressionSupported() {\n return \"zstdDecompressSync\" in zlib && \"zstdCompressSync\" in zlib;\n}\n"],"mappings":";;;;;;;AAyBA,MAAM,iCAAiC,IAAI,OAAO;AAElD,IAAa,gBAAb,MAA2B;CACzB,YACE,AAAiBA,SACjB,AAAiBC,sBACjB;EAFiB;EACA;;CAGnB,MAAM,cACJ,OACA,SACoE;EACpE,MAAM,kBAAkB,IAAI,iBAAiB;AAC7C,MAAI;GAIF,MAAM,OAAO,UAAU,QAAQ,MAAM,OAAO,MAAM;GAGlD,IAAI;GACJ,IAAI;AACJ,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,QAAQ,CACtD,KACE,IAAI,cAAc,oBAAoB,QAAW,EAC/C,aAAa,UACd,CAAC,KAAK,EAEP,0BAAyB;YAEzB,IAAI,cAAc,mBAAmB,QAAW,EAC9C,aAAa,UACd,CAAC,KAAK,EAEP,yBAAwB;GAQ5B,IAAIC;AACJ,OAAI,CAAC,MAAM,KACT,eAAc,kBAAkB;QAC3B;IACL,IAAIC;AACJ,QAAI,MAAM,gBACR,cAAa,OAAO,KAAK,MAAM,MAAM,SAAS;QAE9C,cAAa,OAAO,KAAK,IAAI,aAAa,CAAC,OAAO,MAAM,KAAK,CAAC;AAIhE,QAAI,0BAA0B,uBAAuB,SAAS,OAAO,EAAE;AACrE,SAAI,CAAC,KAAK,qBACR,OAAM,IAAI,MACR,6IACD;AAIH,kBACE,KACA,mBAAmB,WAAW;;AAKlC,mBAAe,mBAAmB;AAChC,WAAM;QACJ,CAAC,OAAO,gBAAgB;;GAG9B,MAAMC,SAAuB,EAAE;GAC/B,MAAMC,eAA6B;IACjC,OAAO,SAAU,OAAkC;AACjD,YAAO,KAAK,MAAM;AAClB,YAAO,QAAQ,SAAS;;IAE1B,OAAO,WAA2B;AAChC,YAAO,QAAQ,SAAS;;IAE3B;GAED,MAAM,WAAW,KAAK,QAAQ,OAC5B;IACE,SAAS,MAAM;IACf,KAAK;IACL,WAAW,CAAC,QAAQ;IACrB,EACD,EACE,cAAc,QAAQ,cACvB,CACF;AAED,OAAI;AACF,UAAM,SAAS,QAAQ;KACrB;KACA;KACA,aAAa,gBAAgB;KAC9B,CAAC;YACK,GAAG;IAEV,MAAM,QAAQ,YAAY,EAAE;AAO5B,KALE,0BACE,KAAK,QAAQ,SAAS,iBACtB,MACA,MAAM,QACP,IAAI,KAAK,QAAQ,SAAS,MACtB,MAAM,wBAAwB,MAAM,SAAS,MAAM,SAAS;AACnE,WAAO;KACL,SAAS;MACP,gBAAgB;MAChB,oBAAoB;MACrB;KACD,YAAY;KACZ,iBAAiB;KACjB,MAAM,KAAK,UAAU,EAAE,SAAS,MAAM,SAAS,CAAC;KACjD;;GAGH,MAAM,qBAAqB,OAAO,OAAO,OAAO;GAChD,IAAI;AAGJ,OACE,KAAK,wBACL,mBAAmB,SAAS,kCAC5B,yBACA,sBAAsB,SAAS,OAAO,EACtC;AACA,aAAS,QAAQ,sBAAsB;AAEvC,mBACE,KAEC,iBAAiB,mBAAmB,CACpC,SAAS,SAAS;SAErB,gBAAe,mBAAmB,SAAS,SAAS;AAEtD,UAAO;IACL,SAAS,SAAS;IAClB,YAAY,SAAS;IACrB,iBAAiB;IACjB,MAAM;IACP;YACO;AACR,mBAAgB,OAAO;;;;AAK7B,SAAgB,yBAAyB;AACvC,QAAO,wBAAwB,QAAQ,sBAAsB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const require_logger_transport = require('../../logging/logger_transport.cjs');
|
|
2
|
+
const require_components = require('../components.cjs');
|
|
3
|
+
const require_logger = require('../../logging/logger.cjs');
|
|
4
|
+
const require_user_agent = require('../../user_agent.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/endpoint/handlers/utils.ts
|
|
7
|
+
function tryCreateContextualLogger(loggerTransport, url, headers, additionalContext) {
|
|
8
|
+
try {
|
|
9
|
+
const path = new URL(url, "https://example.com").pathname;
|
|
10
|
+
const parsed = require_components.parseUrlComponents(path);
|
|
11
|
+
if (parsed.type !== "invoke") return;
|
|
12
|
+
const invocationId = invocationIdFromHeaders(headers);
|
|
13
|
+
return require_logger.createLogger(loggerTransport, require_logger_transport.LogSource.SYSTEM, new require_logger_transport.LoggerContext(invocationId, parsed.componentName, parsed.handlerName, void 0, void 0, additionalContext));
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function invocationIdFromHeaders(headers) {
|
|
19
|
+
const invocationIdHeader = headers["x-restate-invocation-id"];
|
|
20
|
+
return typeof invocationIdHeader === "string" ? invocationIdHeader : Array.isArray(invocationIdHeader) ? invocationIdHeader[0] ?? "unknown id" : "unknown id";
|
|
21
|
+
}
|
|
22
|
+
function errorResponse(code, message) {
|
|
23
|
+
return simpleResponse(code, {
|
|
24
|
+
"content-type": "application/json",
|
|
25
|
+
"x-restate-server": require_user_agent.X_RESTATE_SERVER
|
|
26
|
+
}, new TextEncoder().encode(JSON.stringify({ message })));
|
|
27
|
+
}
|
|
28
|
+
function simpleResponse(statusCode, headers, body) {
|
|
29
|
+
return {
|
|
30
|
+
headers,
|
|
31
|
+
statusCode,
|
|
32
|
+
async process({ inputReader, outputWriter }) {
|
|
33
|
+
if (inputReader !== void 0) while (true) {
|
|
34
|
+
const { done } = await inputReader.next();
|
|
35
|
+
if (done) break;
|
|
36
|
+
}
|
|
37
|
+
await outputWriter.write(body);
|
|
38
|
+
await outputWriter.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function emptyInputReader() {
|
|
43
|
+
return (async function* () {})()[Symbol.asyncIterator]();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.emptyInputReader = emptyInputReader;
|
|
48
|
+
exports.errorResponse = errorResponse;
|
|
49
|
+
exports.invocationIdFromHeaders = invocationIdFromHeaders;
|
|
50
|
+
exports.simpleResponse = simpleResponse;
|
|
51
|
+
exports.tryCreateContextualLogger = tryCreateContextualLogger;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LogSource, LoggerContext } from "../../logging/logger_transport.js";
|
|
2
|
+
import { parseUrlComponents } from "../components.js";
|
|
3
|
+
import { createLogger } from "../../logging/logger.js";
|
|
4
|
+
import { X_RESTATE_SERVER } from "../../user_agent.js";
|
|
5
|
+
|
|
6
|
+
//#region src/endpoint/handlers/utils.ts
|
|
7
|
+
function tryCreateContextualLogger(loggerTransport, url, headers, additionalContext) {
|
|
8
|
+
try {
|
|
9
|
+
const path = new URL(url, "https://example.com").pathname;
|
|
10
|
+
const parsed = parseUrlComponents(path);
|
|
11
|
+
if (parsed.type !== "invoke") return;
|
|
12
|
+
const invocationId = invocationIdFromHeaders(headers);
|
|
13
|
+
return createLogger(loggerTransport, LogSource.SYSTEM, new LoggerContext(invocationId, parsed.componentName, parsed.handlerName, void 0, void 0, additionalContext));
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function invocationIdFromHeaders(headers) {
|
|
19
|
+
const invocationIdHeader = headers["x-restate-invocation-id"];
|
|
20
|
+
return typeof invocationIdHeader === "string" ? invocationIdHeader : Array.isArray(invocationIdHeader) ? invocationIdHeader[0] ?? "unknown id" : "unknown id";
|
|
21
|
+
}
|
|
22
|
+
function errorResponse(code, message) {
|
|
23
|
+
return simpleResponse(code, {
|
|
24
|
+
"content-type": "application/json",
|
|
25
|
+
"x-restate-server": X_RESTATE_SERVER
|
|
26
|
+
}, new TextEncoder().encode(JSON.stringify({ message })));
|
|
27
|
+
}
|
|
28
|
+
function simpleResponse(statusCode, headers, body) {
|
|
29
|
+
return {
|
|
30
|
+
headers,
|
|
31
|
+
statusCode,
|
|
32
|
+
async process({ inputReader, outputWriter }) {
|
|
33
|
+
if (inputReader !== void 0) while (true) {
|
|
34
|
+
const { done } = await inputReader.next();
|
|
35
|
+
if (done) break;
|
|
36
|
+
}
|
|
37
|
+
await outputWriter.write(body);
|
|
38
|
+
await outputWriter.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function emptyInputReader() {
|
|
43
|
+
return (async function* () {})()[Symbol.asyncIterator]();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { emptyInputReader, errorResponse, invocationIdFromHeaders, simpleResponse, tryCreateContextualLogger };
|
|
48
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/endpoint/handlers/utils.ts"],"sourcesContent":["import {\n LoggerContext,\n LogSource,\n LoggerTransport,\n} from \"../../logging/logger_transport.js\";\nimport type {\n Headers,\n InputReader,\n ResponseHeaders,\n RestateResponse,\n} from \"./types.js\";\nimport { createLogger, Logger } from \"../../logging/logger.js\";\nimport { parseUrlComponents } from \"../components.js\";\nimport { X_RESTATE_SERVER } from \"../../user_agent.js\";\n\nexport function tryCreateContextualLogger(\n loggerTransport: LoggerTransport,\n url: string,\n headers: Headers,\n additionalContext?: { [name: string]: string }\n): Logger | undefined {\n try {\n const path = new URL(url, \"https://example.com\").pathname;\n const parsed = parseUrlComponents(path);\n if (parsed.type !== \"invoke\") {\n return undefined;\n }\n const invocationId = invocationIdFromHeaders(headers);\n return createLogger(\n loggerTransport,\n LogSource.SYSTEM,\n new LoggerContext(\n invocationId,\n parsed.componentName,\n parsed.handlerName,\n undefined,\n undefined,\n additionalContext\n )\n );\n } catch {\n return undefined;\n }\n}\n\nexport function invocationIdFromHeaders(headers: Headers) {\n const invocationIdHeader = headers[\"x-restate-invocation-id\"];\n const invocationId =\n typeof invocationIdHeader === \"string\"\n ? invocationIdHeader\n : Array.isArray(invocationIdHeader)\n ? (invocationIdHeader[0] ?? \"unknown id\")\n : \"unknown id\";\n return invocationId;\n}\n\nexport function errorResponse(code: number, message: string): RestateResponse {\n return simpleResponse(\n code,\n {\n \"content-type\": \"application/json\",\n \"x-restate-server\": X_RESTATE_SERVER,\n },\n new TextEncoder().encode(JSON.stringify({ message }))\n );\n}\n\nexport function simpleResponse(\n statusCode: number,\n headers: ResponseHeaders,\n body: Uint8Array\n): RestateResponse {\n return {\n headers,\n statusCode,\n async process({ inputReader, outputWriter }): Promise<void> {\n if (inputReader !== undefined) {\n // Drain the input stream\n while (true) {\n const { done } = await inputReader.next();\n if (done) break;\n }\n }\n\n await outputWriter.write(body);\n // This closes both the writer and the stream!!!\n await outputWriter.close();\n },\n };\n}\n\nexport function emptyInputReader(): InputReader {\n return (async function* () {})()[Symbol.asyncIterator]();\n}\n"],"mappings":";;;;;;AAeA,SAAgB,0BACd,iBACA,KACA,SACA,mBACoB;AACpB,KAAI;EACF,MAAM,OAAO,IAAI,IAAI,KAAK,sBAAsB,CAAC;EACjD,MAAM,SAAS,mBAAmB,KAAK;AACvC,MAAI,OAAO,SAAS,SAClB;EAEF,MAAM,eAAe,wBAAwB,QAAQ;AACrD,SAAO,aACL,iBACA,UAAU,QACV,IAAI,cACF,cACA,OAAO,eACP,OAAO,aACP,QACA,QACA,kBACD,CACF;SACK;AACN;;;AAIJ,SAAgB,wBAAwB,SAAkB;CACxD,MAAM,qBAAqB,QAAQ;AAOnC,QALE,OAAO,uBAAuB,WAC1B,qBACA,MAAM,QAAQ,mBAAmB,GAC9B,mBAAmB,MAAM,eAC1B;;AAIV,SAAgB,cAAc,MAAc,SAAkC;AAC5E,QAAO,eACL,MACA;EACE,gBAAgB;EAChB,oBAAoB;EACrB,EACD,IAAI,aAAa,CAAC,OAAO,KAAK,UAAU,EAAE,SAAS,CAAC,CAAC,CACtD;;AAGH,SAAgB,eACd,YACA,SACA,MACiB;AACjB,QAAO;EACL;EACA;EACA,MAAM,QAAQ,EAAE,aAAa,gBAA+B;AAC1D,OAAI,gBAAgB,OAElB,QAAO,MAAM;IACX,MAAM,EAAE,SAAS,MAAM,YAAY,MAAM;AACzC,QAAI,KAAM;;AAId,SAAM,aAAa,MAAM,KAAK;AAE9B,SAAM,aAAa,OAAO;;EAE7B;;AAGH,SAAgB,mBAAgC;AAC9C,SAAQ,mBAAmB,KAAK,CAAC,OAAO,gBAAgB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
export function cancel_handle(): number;
|
|
3
4
|
/**
|
|
4
5
|
* This will set the log level of the overall log subscriber.
|
|
5
6
|
*/
|
|
6
7
|
export function set_log_level(level: LogLevel): void;
|
|
7
|
-
export function cancel_handle(): number;
|
|
8
8
|
/**
|
|
9
9
|
* Setups the WASM module
|
|
10
10
|
*/
|
|
@@ -45,35 +45,35 @@ export interface WasmExponentialRetryConfig {
|
|
|
45
45
|
max_duration: number | undefined;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export interface
|
|
48
|
+
export interface WasmFailure {
|
|
49
|
+
code: number;
|
|
50
|
+
message: string;
|
|
51
|
+
metadata: WasmFailureMetadata[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface WasmCallHandle {
|
|
49
55
|
invocation_id_completion_id: number;
|
|
56
|
+
call_completion_id: number;
|
|
50
57
|
}
|
|
51
58
|
|
|
59
|
+
export type WasmAsyncResultValue = "NotReady" | "Empty" | { Success: Uint8Array } | { Failure: WasmFailure } | { StateKeys: string[] } | { InvocationId: string };
|
|
60
|
+
|
|
52
61
|
export interface WasmAwakeable {
|
|
53
62
|
id: string;
|
|
54
63
|
handle: number;
|
|
55
64
|
}
|
|
56
65
|
|
|
57
|
-
export
|
|
58
|
-
code: number;
|
|
59
|
-
message: string;
|
|
60
|
-
metadata: WasmFailureMetadata[];
|
|
61
|
-
}
|
|
66
|
+
export type WasmDoProgressResult = "AnyCompleted" | "ReadFromInput" | "WaitingPendingRun" | { ExecuteRun: number } | "CancelSignalReceived";
|
|
62
67
|
|
|
63
68
|
export interface WasmFailureMetadata {
|
|
64
69
|
key: string;
|
|
65
70
|
value: string;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
export interface WasmCallHandle {
|
|
73
|
+
export interface WasmSendHandle {
|
|
71
74
|
invocation_id_completion_id: number;
|
|
72
|
-
call_completion_id: number;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
export type WasmAsyncResultValue = "NotReady" | "Empty" | { Success: Uint8Array } | { Failure: WasmFailure } | { StateKeys: string[] } | { InvocationId: string };
|
|
76
|
-
|
|
77
77
|
export class WasmHeader {
|
|
78
78
|
free(): void;
|
|
79
79
|
constructor(key: string, value: string);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { vm_log } from '../
|
|
1
|
+
import { vm_log } from '../core_logging.js';
|
|
2
2
|
|
|
3
3
|
let wasm;
|
|
4
4
|
export function __wbg_set_wasm(val) {
|
|
@@ -181,17 +181,14 @@ function debugString(val) {
|
|
|
181
181
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
182
182
|
return className;
|
|
183
183
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
191
|
-
}
|
|
192
|
-
wasm.__externref_drop_slice(ptr, len);
|
|
193
|
-
return result;
|
|
184
|
+
/**
|
|
185
|
+
* @returns {number}
|
|
186
|
+
*/
|
|
187
|
+
export function cancel_handle() {
|
|
188
|
+
const ret = wasm.cancel_handle();
|
|
189
|
+
return ret >>> 0;
|
|
194
190
|
}
|
|
191
|
+
|
|
195
192
|
/**
|
|
196
193
|
* This will set the log level of the overall log subscriber.
|
|
197
194
|
* @param {LogLevel} level
|
|
@@ -200,14 +197,6 @@ export function set_log_level(level) {
|
|
|
200
197
|
wasm.set_log_level(level);
|
|
201
198
|
}
|
|
202
199
|
|
|
203
|
-
/**
|
|
204
|
-
* @returns {number}
|
|
205
|
-
*/
|
|
206
|
-
export function cancel_handle() {
|
|
207
|
-
const ret = wasm.cancel_handle();
|
|
208
|
-
return ret >>> 0;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
200
|
/**
|
|
212
201
|
* Setups the WASM module
|
|
213
202
|
*/
|
|
@@ -215,6 +204,17 @@ export function start() {
|
|
|
215
204
|
wasm.start();
|
|
216
205
|
}
|
|
217
206
|
|
|
207
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
208
|
+
ptr = ptr >>> 0;
|
|
209
|
+
const mem = getDataViewMemory0();
|
|
210
|
+
const result = [];
|
|
211
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
212
|
+
result.push(wasm.__wbindgen_export_4.get(mem.getUint32(i, true)));
|
|
213
|
+
}
|
|
214
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
218
|
function passArrayJsValueToWasm0(array, malloc) {
|
|
219
219
|
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
220
220
|
for (let i = 0; i < array.length; i++) {
|
|
@@ -1330,7 +1330,7 @@ export function __wbg_versions_4e31226f5e8dc909(arg0) {
|
|
|
1330
1330
|
return ret;
|
|
1331
1331
|
};
|
|
1332
1332
|
|
|
1333
|
-
export function
|
|
1333
|
+
export function __wbg_vmlog_e24d27eb6bf17053(arg0, arg1, arg2, arg3) {
|
|
1334
1334
|
vm_log(arg0, getArrayU8FromWasm0(arg1, arg2), arg3 === 0x100000001 ? undefined : arg3);
|
|
1335
1335
|
};
|
|
1336
1336
|
|
|
Binary file
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_generic = require('./handlers/generic.cjs');
|
|
2
1
|
const require_endpoint = require('./endpoint.cjs');
|
|
2
|
+
const require_generic = require('./handlers/generic.cjs');
|
|
3
3
|
const require_lambda = require('./handlers/lambda.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/endpoint/lambda_endpoint.ts
|
|
@@ -27,7 +27,7 @@ var LambdaEndpointImpl = class {
|
|
|
27
27
|
}
|
|
28
28
|
handler() {
|
|
29
29
|
const compressionEnabled = require_lambda.isCompressionSupported();
|
|
30
|
-
const lambdaHandler = new require_lambda.LambdaHandler(
|
|
30
|
+
const lambdaHandler = new require_lambda.LambdaHandler(require_generic.createRestateHandler(this.builder.build(), "REQUEST_RESPONSE", compressionEnabled ? { lambdaCompression: "zstd" } : {}), compressionEnabled);
|
|
31
31
|
return lambdaHandler.handleRequest.bind(lambdaHandler);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericHandler } from "./handlers/generic.js";
|
|
2
1
|
import { EndpointBuilder } from "./endpoint.js";
|
|
2
|
+
import { createRestateHandler } from "./handlers/generic.js";
|
|
3
3
|
import { LambdaHandler, isCompressionSupported } from "./handlers/lambda.js";
|
|
4
4
|
|
|
5
5
|
//#region src/endpoint/lambda_endpoint.ts
|
|
@@ -27,7 +27,7 @@ var LambdaEndpointImpl = class {
|
|
|
27
27
|
}
|
|
28
28
|
handler() {
|
|
29
29
|
const compressionEnabled = isCompressionSupported();
|
|
30
|
-
const lambdaHandler = new LambdaHandler(
|
|
30
|
+
const lambdaHandler = new LambdaHandler(createRestateHandler(this.builder.build(), "REQUEST_RESPONSE", compressionEnabled ? { lambdaCompression: "zstd" } : {}), compressionEnabled);
|
|
31
31
|
return lambdaHandler.handleRequest.bind(lambdaHandler);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda_endpoint.js","names":[],"sources":["../../src/endpoint/lambda_endpoint.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nimport type {\n JournalValueCodec,\n ServiceDefinition,\n VirtualObjectDefinition,\n WorkflowDefinition,\n} from \"@restatedev/restate-sdk-core\";\nimport { EndpointBuilder } from \"./endpoint.js\";\nimport type {\n DefaultServiceOptions,\n RestateEndpointBase,\n} from \"../endpoint.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"lambda_endpoint.js","names":[],"sources":["../../src/endpoint/lambda_endpoint.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nimport type {\n JournalValueCodec,\n ServiceDefinition,\n VirtualObjectDefinition,\n WorkflowDefinition,\n} from \"@restatedev/restate-sdk-core\";\nimport { EndpointBuilder } from \"./endpoint.js\";\nimport type {\n DefaultServiceOptions,\n RestateEndpointBase,\n} from \"../endpoint.js\";\nimport { createRestateHandler } from \"./handlers/generic.js\";\nimport { isCompressionSupported, LambdaHandler } from \"./handlers/lambda.js\";\nimport type { LoggerTransport } from \"../logging/logger_transport.js\";\n\n/**\n * LambdaEndpoint encapsulates all the Restate services served by this endpoint.\n *\n *\n * @example\n * A typical endpoint served as Lambda would look like this:\n * ```\n * import * as restate from \"@restatedev/restate-sdk/lambda\";\n *\n * export const handler = restate\n * .endpoint()\n * .bind(myService)\n * .handler();\n */\nexport interface LambdaEndpoint extends RestateEndpointBase<LambdaEndpoint> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handler(): (event: any, ctx: any) => Promise<any>;\n}\n\nexport class LambdaEndpointImpl implements LambdaEndpoint {\n private builder: EndpointBuilder = new EndpointBuilder();\n\n public bind<P extends string, M>(\n definition:\n | ServiceDefinition<P, M>\n | VirtualObjectDefinition<P, M>\n | WorkflowDefinition<P, M>\n ): LambdaEndpoint {\n this.builder.bind(definition);\n return this;\n }\n\n public withIdentityV1(...keys: string[]): LambdaEndpoint {\n this.builder.addIdentityKeys(...keys);\n return this;\n }\n\n public defaultServiceOptions(options: DefaultServiceOptions): LambdaEndpoint {\n this.builder.setDefaultServiceOptions(options);\n return this;\n }\n\n public setLogger(logger: LoggerTransport): LambdaEndpoint {\n this.builder.setLogger(logger);\n return this;\n }\n\n public journalValueCodecProvider(\n codecProvider: () => Promise<JournalValueCodec>\n ): LambdaEndpoint {\n this.builder.setJournalValueCodecProvider(codecProvider);\n return this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handler(): (event: any, ctx: any) => Promise<any> {\n const compressionEnabled = isCompressionSupported();\n\n const genericHandler = createRestateHandler(\n this.builder.build(),\n \"REQUEST_RESPONSE\",\n compressionEnabled\n ? {\n lambdaCompression: \"zstd\",\n }\n : {}\n );\n const lambdaHandler = new LambdaHandler(genericHandler, compressionEnabled);\n return lambdaHandler.handleRequest.bind(lambdaHandler);\n }\n}\n"],"mappings":";;;;;AA6CA,IAAa,qBAAb,MAA0D;CACxD,AAAQ,UAA2B,IAAI,iBAAiB;CAExD,AAAO,KACL,YAIgB;AAChB,OAAK,QAAQ,KAAK,WAAW;AAC7B,SAAO;;CAGT,AAAO,eAAe,GAAG,MAAgC;AACvD,OAAK,QAAQ,gBAAgB,GAAG,KAAK;AACrC,SAAO;;CAGT,AAAO,sBAAsB,SAAgD;AAC3E,OAAK,QAAQ,yBAAyB,QAAQ;AAC9C,SAAO;;CAGT,AAAO,UAAU,QAAyC;AACxD,OAAK,QAAQ,UAAU,OAAO;AAC9B,SAAO;;CAGT,AAAO,0BACL,eACgB;AAChB,OAAK,QAAQ,6BAA6B,cAAc;AACxD,SAAO;;CAIT,UAAkD;EAChD,MAAM,qBAAqB,wBAAwB;EAWnD,MAAM,gBAAgB,IAAI,cATH,qBACrB,KAAK,QAAQ,OAAO,EACpB,oBACA,qBACI,EACE,mBAAmB,QACpB,GACD,EAAE,CACP,EACuD,mBAAmB;AAC3E,SAAO,cAAc,cAAc,KAAK,cAAc"}
|