Access an external variable from a lambda function
At present, the Pluto deducer lacks the capability to analyze and track the locations of accessed variables. Consequently, when a lambda function accesses a variable beyond its own scope, said variable will not be incorporated into the lambda.
import { HttpRequest, HttpResponse, Router } from "@plutolang/pluto";
// This will not be included in the generated compute module code.
const CONSTANT = "constant";
let variable = 1;
const router = new Router("router");
router.get("/path1", async (req: HttpRequest): Promise<HttpResponse> => {
console.log(CONSTANT); // failed
variable += 1;
// ...
});
router.get("/path2", async (req: HttpRequest): Promise<HttpResponse> => {
console.log(variable); // failed
// ...
});
Our expectation is that the constant will be treated as a regular constant and included in the generated code. However, the variable may need to be transferred to a cloud resource, such as an object in an object store, in order to preserve its state information. This cloud resource for the variable needs to be present in the architecture reference.
- [x] Support for constants access.
- [ ] Support for variable variables access.
After #73, developers can access the constants that located outside of the function code in the hander function. But, currently, only literal constants are supported.
Need support for accessing variables. Please note that these variables might be modified by other processes.