diff --git a/examples/tests/sdk_tests/api/delete.w b/examples/tests/sdk_tests/api/delete.w index 123b00e8812..8a00098a98e 100644 --- a/examples/tests/sdk_tests/api/delete.w +++ b/examples/tests/sdk_tests/api/delete.w @@ -2,14 +2,10 @@ bring cloud; bring http; bring util; -// https://github.com/winglang/wing/issues/3049 -let http_DELETE = http.HttpMethod.DELETE; -let api_DELETE = cloud.HttpMethod.DELETE; - let api = new cloud.Api(); api.delete("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { - assert(req.method == api_DELETE); + assert(req.method == cloud.HttpMethod.DELETE); assert(req.query?.get("all") == "true"); assert(req.query?.get("page") == "6"); assert(req.path == "/path"); @@ -20,12 +16,11 @@ api.delete("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { }; }); -/// https://github.com/winglang/wing/issues/3342 -if (util.env("WING_TARGET") != "tf-aws") { - test "http.delete and http.fetch can preform a call to an api" { + +test "http.delete and http.fetch can preform a call to an api" { let url = "${api.url}/path?all=true&page=6"; let response: http.Response = http.delete(url); - let fetchResponse: http.Response = http.fetch(url, method: http_DELETE); + let fetchResponse: http.Response = http.fetch(url, method: http.HttpMethod.DELETE); assert(response.body == "6"); assert(response.status == 200); @@ -34,6 +29,4 @@ if (util.env("WING_TARGET") != "tf-aws") { assert(fetchResponse.body == "6"); assert(fetchResponse.status == 200); assert(fetchResponse.url == url); - - } -} \ No newline at end of file +} diff --git a/examples/tests/sdk_tests/api/get.w b/examples/tests/sdk_tests/api/get.w index 7d184f1d6b2..56a311cfb2a 100644 --- a/examples/tests/sdk_tests/api/get.w +++ b/examples/tests/sdk_tests/api/get.w @@ -2,18 +2,14 @@ bring cloud; bring http; bring util; -// https://github.com/winglang/wing/issues/3049 -let http_GET = http.HttpMethod.GET; -let api_GET = cloud.HttpMethod.GET; let api = new cloud.Api(); let body = "ok!"; api.get("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { - assert(req.method == api_GET); + assert(req.method == cloud.HttpMethod.GET); assert(req.path == "/path"); - // req.body is not a string in sim- https://github.com/winglang/wing/issues/3024 - // assert(req.body?.length == 0); + assert(req.body?.length == 0); assert(req.headers?.get("content-type") == "application/json"); return cloud.ApiResponse { @@ -22,12 +18,11 @@ api.get("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { }; }); -/// https://github.com/winglang/wing/issues/3342 -if (util.env("WING_TARGET") != "tf-aws") { - test "http.get and http.fetch can preform a call to an api" { + +test "http.get and http.fetch can preform a call to an api" { let url = api.url + "/path"; let getResponse: http.Response = http.get(url, headers: { "content-type" => "application/json" }); - let fetchResponse: http.Response = http.fetch(url, method: http_GET, headers: { "content-type" => "application/json" }); + let fetchResponse: http.Response = http.fetch(url, method: http.HttpMethod.GET, headers: { "content-type" => "application/json" }); let fetchResponseNoMethod: http.Response = http.fetch(url, headers: { "content-type" => "application/json" }); @@ -42,5 +37,4 @@ if (util.env("WING_TARGET") != "tf-aws") { assert(fetchResponseNoMethod.body == body); assert(fetchResponseNoMethod.status == 200); assert(fetchResponseNoMethod.url == url); - } } diff --git a/examples/tests/sdk_tests/api/options.w b/examples/tests/sdk_tests/api/options.w index d9488efcaf0..46d4732363b 100644 --- a/examples/tests/sdk_tests/api/options.w +++ b/examples/tests/sdk_tests/api/options.w @@ -2,25 +2,15 @@ bring cloud; bring http; bring util; -// https://github.com/winglang/wing/issues/3049 -let api_OPTIONS = cloud.HttpMethod.OPTIONS; -let http_OPTIONS = http.HttpMethod.OPTIONS; - -let api_HEAD = cloud.HttpMethod.HEAD; -let http_HEAD = http.HttpMethod.HEAD; - -let api_CONNECT = cloud.HttpMethod.CONNECT; - let api = new cloud.Api(); let path = "/path"; - api.options(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => { - assert(req.method == api_OPTIONS); + assert(req.method == cloud.HttpMethod.OPTIONS); assert(req.path == path); // req.body is not a string in sim- https://github.com/winglang/wing/issues/3024 - // assert(req.body?.length == 0); + assert(req.body?.length == 0); return cloud.ApiResponse { status: 204 @@ -28,10 +18,10 @@ api.options(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => { }); api.head(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => { - assert(req.method == api_HEAD); + assert(req.method == cloud.HttpMethod.HEAD); assert(req.path == path); // req.body is not a string in sim- https://github.com/winglang/wing/issues/3024 - // assert(req.body?.length == 0); + assert(req.body?.length == 0); return cloud.ApiResponse { status: 204 @@ -48,16 +38,14 @@ api.connect(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => { -/// https://github.com/winglang/wing/issues/3342 -if (util.env("WING_TARGET") != "tf-aws") { - test "http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS" { + +test "http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS" { let url = api.url + path; - let options: http.Response = http.fetch(url, method: http_OPTIONS); - let head: http.Response = http.fetch(url, method: http_HEAD); + let options: http.Response = http.fetch(url, method: http.HttpMethod.OPTIONS); + let head: http.Response = http.fetch(url, method: http.HttpMethod.HEAD); assert(options.status == 204); assert(options.url == url); - } } \ No newline at end of file diff --git a/examples/tests/sdk_tests/api/patch.w b/examples/tests/sdk_tests/api/patch.w index 3818902c187..6ef409c0fdc 100644 --- a/examples/tests/sdk_tests/api/patch.w +++ b/examples/tests/sdk_tests/api/patch.w @@ -2,17 +2,13 @@ bring cloud; bring http; bring util; -// https://github.com/winglang/wing/issues/3049 -let http_PATCH = http.HttpMethod.PATCH; -let api_PATCH = cloud.HttpMethod.PATCH; - let api = new cloud.Api(); let body = Json {"cat": "Tion"}; let _id = "12345"; api.patch("/path/{id}", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { - assert(req.method == api_PATCH); + assert(req.method == cloud.HttpMethod.PATCH); assert(req.vars?.get("id") == _id); assert(req.path == "/path/"+ _id); @@ -25,12 +21,11 @@ api.patch("/path/{id}", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { }; }); -/// https://github.com/winglang/wing/issues/3342 -if (util.env("WING_TARGET") != "tf-aws") { - test "http.patch and http.fetch can preform a call to an api" { + +test "http.patch and http.fetch can preform a call to an api" { let url = "${api.url}/path/${_id}"; let response: http.Response = http.patch(url, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); - let fetchResponse: http.Response = http.patch(url, method: http_PATCH, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); + let fetchResponse: http.Response = http.patch(url, method: http.HttpMethod.PATCH, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); assert(response.body == _id); assert(response.status == 200); @@ -39,6 +34,4 @@ if (util.env("WING_TARGET") != "tf-aws") { assert(fetchResponse.body == _id); assert(fetchResponse.status == 200); assert(fetchResponse.url == url); - - } } \ No newline at end of file diff --git a/examples/tests/sdk_tests/api/post.w b/examples/tests/sdk_tests/api/post.w index 61bea6e9393..ab2d6c6ca7c 100644 --- a/examples/tests/sdk_tests/api/post.w +++ b/examples/tests/sdk_tests/api/post.w @@ -2,15 +2,11 @@ bring cloud; bring http; bring util; -// https://github.com/winglang/wing/issues/3049 -let http_POST = http.HttpMethod.POST; -let api_POST = cloud.HttpMethod.POST; - let api = new cloud.Api(); let body = Json {"cat": "Tion"}; api.post("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { - assert(req.method == api_POST); + assert(req.method == cloud.HttpMethod.POST); assert(req.path == "/path"); assert(req.body == Json.stringify(body)); assert(req.headers?.get("content-type") == "application/json"); @@ -21,12 +17,11 @@ api.post("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { }; }); -/// https://github.com/winglang/wing/issues/3342 -if (util.env("WING_TARGET") != "tf-aws") { - test "http.post and http.fetch can preform a call to an api" { + +test "http.post and http.fetch can preform a call to an api" { let url = api.url + "/path"; let response: http.Response = http.post(url, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); - let fetchResponse: http.Response = http.post(url, method: http_POST, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); + let fetchResponse: http.Response = http.post(url, method: http.HttpMethod.POST, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); assert(response.body == Json.stringify(body)); assert(response.status == 200); @@ -35,6 +30,4 @@ if (util.env("WING_TARGET") != "tf-aws") { assert(fetchResponse.body == Json.stringify(body)); assert(fetchResponse.status == 200); assert(fetchResponse.url == url); - - } } \ No newline at end of file diff --git a/examples/tests/sdk_tests/api/put.w b/examples/tests/sdk_tests/api/put.w index e2d5cf7ae51..3b974bdfa85 100644 --- a/examples/tests/sdk_tests/api/put.w +++ b/examples/tests/sdk_tests/api/put.w @@ -2,10 +2,6 @@ bring cloud; bring http; bring util; -// https://github.com/winglang/wing/issues/3049 -let http_PUT = http.HttpMethod.PUT; -let api_PUT = cloud.HttpMethod.PUT; - let api = new cloud.Api(); let body = Json {"cat": "Tion"}; @@ -14,7 +10,7 @@ let _id = "12345"; api.put("/path/{id}/nn/{user}", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { let path = "/path/${_id}/nn/${user}"; - assert(req.method == api_PUT); + assert(req.method == cloud.HttpMethod.PUT); assert(req.vars?.get("id") == _id); assert(req.vars?.get("user") == user); assert(req.path == path); @@ -28,12 +24,11 @@ api.put("/path/{id}/nn/{user}", inflight (req: cloud.ApiRequest): cloud.ApiRespo }; }); -/// https://github.com/winglang/wing/issues/3342 -if (util.env("WING_TARGET") != "tf-aws") { - test "http.put and http.fetch can preform a call to an api" { + +test "http.put and http.fetch can preform a call to an api" { let url = "${api.url}/path/${_id}/nn/${user}"; let response: http.Response = http.put(url, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); - let fetchResponse: http.Response = http.put(url, method: http_PUT, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); + let fetchResponse: http.Response = http.put(url, method: http.HttpMethod.PUT, headers: { "content-type" => "application/json" }, body: Json.stringify(body)); assert(response.headers.get("content-type") == "application/json; charset=utf-8"); @@ -45,6 +40,5 @@ if (util.env("WING_TARGET") != "tf-aws") { assert(fetchResponse.body == _id); assert(fetchResponse.status == 200); assert(fetchResponse.url == url); - } } diff --git a/libs/wingsdk/src/target-sim/api.inflight.ts b/libs/wingsdk/src/target-sim/api.inflight.ts index ec85559afdc..d312c60339f 100644 --- a/libs/wingsdk/src/target-sim/api.inflight.ts +++ b/libs/wingsdk/src/target-sim/api.inflight.ts @@ -179,7 +179,7 @@ function isApiResponse(response: unknown): response is ApiResponse { function transformRequest(req: express.Request): ApiRequest { return { headers: sanitizeParamLikeObject(req.headers), - body: req.body, + body: Object.keys(req.body).length > 0 ? req.body : "", method: parseHttpMethod(req.method), path: req.path, query: sanitizeParamLikeObject(req.query as any), diff --git a/libs/wingsdk/src/target-tf-aws/api.ts b/libs/wingsdk/src/target-tf-aws/api.ts index d3b38b7bc10..1d73c5fa071 100644 --- a/libs/wingsdk/src/target-tf-aws/api.ts +++ b/libs/wingsdk/src/target-tf-aws/api.ts @@ -47,7 +47,7 @@ export class Api extends cloud.Api { } public get url(): string { - return this.api.stage.invokeUrl; + return this.api.url; } /** @@ -367,6 +367,7 @@ export class Api extends cloud.Api { * Encapsulates the API Gateway REST API as a abstraction for Terraform. */ class WingRestApi extends Construct { + public readonly url: string; public readonly api: ApiGatewayRestApi; public readonly stage: ApiGatewayStage; private readonly deployment: ApiGatewayDeployment; @@ -414,6 +415,9 @@ class WingRestApi extends Construct { stageName: STAGE_NAME, deploymentId: this.deployment.id, }); + + //should be exported from here, otherwise won't be mapped to the right token + this.url = this.stage.invokeUrl; } /** diff --git a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap index 5bebee90338..78b7dafe629 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap @@ -8,7 +8,7 @@ exports[`api handler can read the request params 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}).", "GET /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -216,7 +216,7 @@ exports[`api handler can read the request path 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -424,7 +424,7 @@ exports[`api handler can set response headers 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -632,7 +632,7 @@ exports[`api response returns Content-Type header from inflight 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -840,7 +840,7 @@ exports[`api response returns default Content-Type header 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1048,25 +1048,25 @@ exports[`api supports every method type 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "Processing \\"POST /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":{},\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "POST /hello - 200.", "Processing \\"PUT /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":{},\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "PUT /hello - 200.", "Processing \\"DELETE /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "DELETE /hello - 200.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "Processing \\"OPTIONS /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "OPTIONS /hello - 200.", "Processing \\"PATCH /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":{},\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "PATCH /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1638,10 +1638,10 @@ exports[`api with multiple methods on same route 1`] = ` "wingsdk.cloud.Function created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "Processing \\"POST /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":{},\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "POST /hello - 200.", "wingsdk.sim.EventMapping deleted.", "wingsdk.cloud.Function deleted.", @@ -1964,10 +1964,10 @@ exports[`api with multiple routes 1`] = ` "wingsdk.cloud.Function created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello/world\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello/world - 200.", "Processing \\"GET /hello/wingnuts\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello/wingnuts - 200.", "wingsdk.sim.EventMapping deleted.", "wingsdk.cloud.Function deleted.", @@ -2290,7 +2290,7 @@ exports[`api with one GET route 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /hello\\" params={}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}).", "GET /hello - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2498,7 +2498,7 @@ exports[`api with one GET route with request params 1`] = ` "wingsdk.cloud.Api created.", "wingsdk.sim.EventMapping created.", "Processing \\"GET /users/{name}\\" params={\\"name\\":\\"tsuf\\"}).", - "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":{},\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}).", + "Invoke (payload={\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}).", "GET /users/{name} - 200.", "wingsdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", diff --git a/libs/wingsdk/test/target-sim/api.test.ts b/libs/wingsdk/test/target-sim/api.test.ts index 2ea1f237259..c9501304304 100644 --- a/libs/wingsdk/test/target-sim/api.test.ts +++ b/libs/wingsdk/test/target-sim/api.test.ts @@ -449,8 +449,9 @@ test("api response returns default Content-Type header", async () => { await s.stop(); expect(response.status).toEqual(200); + // the default for no body requests expect(response.headers.get("Content-Type")).toEqual( - "application/json; charset=utf-8" + "text/html; charset=utf-8" ); expect(listMessages(s)).toMatchSnapshot(); diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/delete.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/delete.w_compile_tf-aws.md index d94229f92c0..648a3df6744 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/delete.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/delete.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $api_DELETE }) { +module.exports = function({ $cloud_HttpMethod }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -10,7 +10,7 @@ module.exports = function({ $api_DELETE }) { return $obj; } async handle(req) { - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_DELETE")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_DELETE)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.DELETE")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.DELETE)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.query?.get(\"all\") == \"true\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.query)["all"],"true")))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.query?.get(\"page\") == \"6\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.query)["page"],"6")))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == \"/path\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,"/path")))}; @@ -24,7 +24,7 @@ module.exports = function({ $api_DELETE }) { ## inflight.$Closure2-1.js ```js -module.exports = function({ $api_url, $http_DELETE, $http_Util }) { +module.exports = function({ $api_url, $http_HttpMethod, $http_Util }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -34,7 +34,7 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { async handle() { const url = String.raw({ raw: ["", "/path?all=true&page=6"] }, $api_url); const response = (await $http_Util.delete(url)); - const fetchResponse = (await $http_Util.fetch(url,{ method: $http_DELETE })); + const fetchResponse = (await $http_Util.fetch(url,{ method: $http_HttpMethod.DELETE })); {((cond) => {if (!cond) throw new Error("assertion failed: response.body == \"6\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.body,"6")))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.status == 200")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.status,200)))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.url == url")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.url,url)))}; @@ -81,7 +81,7 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { }, "output": { "WING_TEST_RUNNER_FUNCTION_ARNS": { - "value": "[]" + "value": "[[\"root/Default/Default/test:http.delete and http.fetch can preform a call to an api\",\"${aws_lambda_function.testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_98044CDF.arn}\"]]" } }, "provider": { @@ -103,7 +103,7 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "841e88388b5ba75d968430f607ebeffd3f39668c" + "redeployment": "3f2ed3e388571f5b15cbc06ba1b47979abe75776" } } }, @@ -141,6 +141,15 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRole_F3B23120": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.delete and http.fetch can preform a call to an api/Handler/IamRole", + "uniqueId": "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRole_F3B23120" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -153,6 +162,16 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_03683652": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.delete and http.fetch can preform a call to an api/Handler/IamRolePolicy", + "uniqueId": "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_03683652" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRole_F3B23120.name}" } }, "aws_iam_role_policy_attachment": { @@ -165,6 +184,16 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_A5AE872D": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.delete and http.fetch can preform a call to an api/Handler/IamRolePolicyAttachment", + "uniqueId": "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_A5AE872D" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRole_F3B23120.name}" } }, "aws_lambda_function": { @@ -193,6 +222,33 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { "security_group_ids": [], "subnet_ids": [] } + }, + "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_98044CDF": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.delete and http.fetch can preform a call to an api/Handler/Default", + "uniqueId": "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_98044CDF" + } + }, + "environment": { + "variables": { + "WING_FUNCTION_NAME": "Handler-c897cd38", + "WING_TARGET": "tf-aws", + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + } + }, + "function_name": "Handler-c897cd38", + "handler": "index.handler", + "publish": true, + "role": "${aws_iam_role.testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_IamRole_F3B23120.arn}", + "runtime": "nodejs18.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_S3Object_64313242.key}", + "timeout": 30, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_lambda_permission": { @@ -232,6 +288,17 @@ module.exports = function({ $api_url, $http_DELETE, $http_Util }) { "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_S3Object_64313242": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.delete and http.fetch can preform a call to an api/Handler/S3Object", + "uniqueId": "testhttpdeleteandhttpfetchcanpreformacalltoanapi_Handler_S3Object_64313242" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -259,7 +326,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ - $api_DELETE: ${context._lift(api_DELETE)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, }) `); } @@ -274,54 +341,43 @@ class $Root extends $stdlib.std.Resource { })()) `); } + } + class $Closure2 extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + this._addInflightOps("handle", "$inflight_init"); + this.display.hidden = true; + } + static _toInflightType(context) { + return $stdlib.core.NodeJsCode.fromInline(` + require("./inflight.$Closure2-1.js")({ + $api_url: ${context._lift(api.url)}, + $http_HttpMethod: ${context._lift(http.HttpMethod)}, + $http_Util: ${context._lift(http.Util)}, + }) + `); + } + _toInflight() { + return $stdlib.core.NodeJsCode.fromInline(` + (await (async () => { + const $Closure2Client = ${$Closure2._toInflightType(this).text}; + const client = new $Closure2Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `); + } _registerBind(host, ops) { if (ops.includes("handle")) { - $Closure1._registerBindObject(api_DELETE, host, []); + $Closure2._registerBindObject(api.url, host, []); } super._registerBind(host, ops); } } - const http_DELETE = http.HttpMethod.DELETE; - const api_DELETE = cloud.HttpMethod.DELETE; const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); (api.delete("/path",new $Closure1(this,"$Closure1"))); - if (((util.Util.env("WING_TARGET")) !== "tf-aws")) { - class $Closure2 extends $stdlib.std.Resource { - constructor(scope, id, ) { - super(scope, id); - this._addInflightOps("handle", "$inflight_init"); - this.display.hidden = true; - } - static _toInflightType(context) { - return $stdlib.core.NodeJsCode.fromInline(` - require("./inflight.$Closure2-1.js")({ - $api_url: ${context._lift(api.url)}, - $http_DELETE: ${context._lift(http_DELETE)}, - $http_Util: ${context._lift(http.Util)}, - }) - `); - } - _toInflight() { - return $stdlib.core.NodeJsCode.fromInline(` - (await (async () => { - const $Closure2Client = ${$Closure2._toInflightType(this).text}; - const client = new $Closure2Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `); - } - _registerBind(host, ops) { - if (ops.includes("handle")) { - $Closure2._registerBindObject(api.url, host, []); - $Closure2._registerBindObject(http_DELETE, host, []); - } - super._registerBind(host, ops); - } - } - this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.delete and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); - } + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.delete and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/get.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/get.w_compile_tf-aws.md index dba19613447..fcebfadc52d 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/get.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/get.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $api_GET, $body }) { +module.exports = function({ $body, $cloud_HttpMethod }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -10,8 +10,9 @@ module.exports = function({ $api_GET, $body }) { return $obj; } async handle(req) { - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_GET")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_GET)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.GET")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.GET)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == \"/path\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,"/path")))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.body?.length == 0")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.body?.length,0)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.headers?.get(\"content-type\") == \"application/json\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.headers)["content-type"],"application/json")))}; return ({"status": 200,"body": $body}); } @@ -23,7 +24,7 @@ module.exports = function({ $api_GET, $body }) { ## inflight.$Closure2-1.js ```js -module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { +module.exports = function({ $api_url, $body, $http_HttpMethod, $http_Util }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -33,7 +34,7 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { async handle() { const url = ($api_url + "/path"); const getResponse = (await $http_Util.get(url,{ headers: ({"content-type": "application/json"}) })); - const fetchResponse = (await $http_Util.fetch(url,{ method: $http_GET, headers: ({"content-type": "application/json"}) })); + const fetchResponse = (await $http_Util.fetch(url,{ method: $http_HttpMethod.GET, headers: ({"content-type": "application/json"}) })); const fetchResponseNoMethod = (await $http_Util.fetch(url,{ headers: ({"content-type": "application/json"}) })); {((cond) => {if (!cond) throw new Error("assertion failed: getResponse.body == body")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(getResponse.body,$body)))}; {((cond) => {if (!cond) throw new Error("assertion failed: getResponse.status == 200")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(getResponse.status,200)))}; @@ -84,7 +85,7 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { }, "output": { "WING_TEST_RUNNER_FUNCTION_ARNS": { - "value": "[]" + "value": "[[\"root/Default/Default/test:http.get and http.fetch can preform a call to an api\",\"${aws_lambda_function.testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_9FEA2521.arn}\"]]" } }, "provider": { @@ -106,7 +107,7 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "c3461b0b0043b244acf509a72d2abc470b20cb05" + "redeployment": "10bb301799b13187f97edf464edbfe465c48a11e" } } }, @@ -144,6 +145,15 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRole_678DDBCB": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.get and http.fetch can preform a call to an api/Handler/IamRole", + "uniqueId": "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRole_678DDBCB" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -156,6 +166,16 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_047F62EA": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.get and http.fetch can preform a call to an api/Handler/IamRolePolicy", + "uniqueId": "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_047F62EA" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRole_678DDBCB.name}" } }, "aws_iam_role_policy_attachment": { @@ -168,6 +188,16 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_328C8EF0": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.get and http.fetch can preform a call to an api/Handler/IamRolePolicyAttachment", + "uniqueId": "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_328C8EF0" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRole_678DDBCB.name}" } }, "aws_lambda_function": { @@ -196,6 +226,33 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { "security_group_ids": [], "subnet_ids": [] } + }, + "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_9FEA2521": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.get and http.fetch can preform a call to an api/Handler/Default", + "uniqueId": "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_9FEA2521" + } + }, + "environment": { + "variables": { + "WING_FUNCTION_NAME": "Handler-c838ce37", + "WING_TARGET": "tf-aws", + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + } + }, + "function_name": "Handler-c838ce37", + "handler": "index.handler", + "publish": true, + "role": "${aws_iam_role.testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_IamRole_678DDBCB.arn}", + "runtime": "nodejs18.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_S3Object_88ED484E.key}", + "timeout": 30, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_lambda_permission": { @@ -235,6 +292,17 @@ module.exports = function({ $api_url, $body, $http_GET, $http_Util }) { "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_S3Object_88ED484E": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.get and http.fetch can preform a call to an api/Handler/S3Object", + "uniqueId": "testhttpgetandhttpfetchcanpreformacalltoanapi_Handler_S3Object_88ED484E" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -262,8 +330,8 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ - $api_GET: ${context._lift(api_GET)}, $body: ${context._lift(body)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, }) `); } @@ -280,56 +348,50 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { - $Closure1._registerBindObject(api_GET, host, []); $Closure1._registerBindObject(body, host, []); } super._registerBind(host, ops); } } - const http_GET = http.HttpMethod.GET; - const api_GET = cloud.HttpMethod.GET; - const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); - const body = "ok!"; - (api.get("/path",new $Closure1(this,"$Closure1"))); - if (((util.Util.env("WING_TARGET")) !== "tf-aws")) { - class $Closure2 extends $stdlib.std.Resource { - constructor(scope, id, ) { - super(scope, id); - this._addInflightOps("handle", "$inflight_init"); - this.display.hidden = true; - } - static _toInflightType(context) { - return $stdlib.core.NodeJsCode.fromInline(` - require("./inflight.$Closure2-1.js")({ - $api_url: ${context._lift(api.url)}, - $body: ${context._lift(body)}, - $http_GET: ${context._lift(http_GET)}, - $http_Util: ${context._lift(http.Util)}, - }) - `); - } - _toInflight() { - return $stdlib.core.NodeJsCode.fromInline(` - (await (async () => { - const $Closure2Client = ${$Closure2._toInflightType(this).text}; - const client = new $Closure2Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `); - } - _registerBind(host, ops) { - if (ops.includes("handle")) { - $Closure2._registerBindObject(api.url, host, []); - $Closure2._registerBindObject(body, host, []); - $Closure2._registerBindObject(http_GET, host, []); - } - super._registerBind(host, ops); + class $Closure2 extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + this._addInflightOps("handle", "$inflight_init"); + this.display.hidden = true; + } + static _toInflightType(context) { + return $stdlib.core.NodeJsCode.fromInline(` + require("./inflight.$Closure2-1.js")({ + $api_url: ${context._lift(api.url)}, + $body: ${context._lift(body)}, + $http_HttpMethod: ${context._lift(http.HttpMethod)}, + $http_Util: ${context._lift(http.Util)}, + }) + `); + } + _toInflight() { + return $stdlib.core.NodeJsCode.fromInline(` + (await (async () => { + const $Closure2Client = ${$Closure2._toInflightType(this).text}; + const client = new $Closure2Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `); + } + _registerBind(host, ops) { + if (ops.includes("handle")) { + $Closure2._registerBindObject(api.url, host, []); + $Closure2._registerBindObject(body, host, []); } + super._registerBind(host, ops); } - this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.get and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } + const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); + const body = "ok!"; + (api.get("/path",new $Closure1(this,"$Closure1"))); + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.get and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/options.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/options.w_compile_tf-aws.md index 22ec9427cdd..0e0ad80ccdb 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/options.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/options.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $api_OPTIONS, $path }) { +module.exports = function({ $cloud_HttpMethod, $path }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -10,8 +10,9 @@ module.exports = function({ $api_OPTIONS, $path }) { return $obj; } async handle(req) { - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_OPTIONS")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_OPTIONS)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.OPTIONS")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.OPTIONS)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == path")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,$path)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.body?.length == 0")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.body?.length,0)))}; return ({"status": 204}); } } @@ -22,7 +23,7 @@ module.exports = function({ $api_OPTIONS, $path }) { ## inflight.$Closure2-1.js ```js -module.exports = function({ $api_HEAD, $path }) { +module.exports = function({ $cloud_HttpMethod, $path }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -30,8 +31,9 @@ module.exports = function({ $api_HEAD, $path }) { return $obj; } async handle(req) { - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_HEAD")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_HEAD)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.HEAD")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.HEAD)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == path")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,$path)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.body?.length == 0")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.body?.length,0)))}; return ({"status": 204}); } } @@ -60,7 +62,7 @@ module.exports = function({ }) { ## inflight.$Closure4-1.js ```js -module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $path }) { +module.exports = function({ $api_url, $http_HttpMethod, $http_Util, $path }) { class $Closure4 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -69,8 +71,8 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa } async handle() { const url = ($api_url + $path); - const options = (await $http_Util.fetch(url,{ method: $http_OPTIONS })); - const head = (await $http_Util.fetch(url,{ method: $http_HEAD })); + const options = (await $http_Util.fetch(url,{ method: $http_HttpMethod.OPTIONS })); + const head = (await $http_Util.fetch(url,{ method: $http_HttpMethod.HEAD })); {((cond) => {if (!cond) throw new Error("assertion failed: options.status == 204")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(options.status,204)))}; {((cond) => {if (!cond) throw new Error("assertion failed: options.url == url")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(options.url,url)))}; } @@ -113,7 +115,7 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa }, "output": { "WING_TEST_RUNNER_FUNCTION_ARNS": { - "value": "[]" + "value": "[[\"root/Default/Default/test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS\",\"${aws_lambda_function.testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_E8EF5111.arn}\"]]" } }, "provider": { @@ -135,7 +137,7 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "8b2f49112bd467ba9558fc860ae398e857923872" + "redeployment": "9bcd95d1a951f5b01da431cbc7b3eb0ab691fdeb" } } }, @@ -191,6 +193,15 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRole_F762CCC6": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS/Handler/IamRole", + "uniqueId": "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRole_F762CCC6" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -223,6 +234,16 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRolePolicy_665D7306": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS/Handler/IamRolePolicy", + "uniqueId": "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRolePolicy_665D7306" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRole_F762CCC6.name}" } }, "aws_iam_role_policy_attachment": { @@ -255,6 +276,16 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRolePolicyAttachment_032BCE8A": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS/Handler/IamRolePolicyAttachment", + "uniqueId": "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRolePolicyAttachment_032BCE8A" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRole_F762CCC6.name}" } }, "aws_lambda_function": { @@ -335,6 +366,33 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa "security_group_ids": [], "subnet_ids": [] } + }, + "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_E8EF5111": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS/Handler/Default", + "uniqueId": "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_E8EF5111" + } + }, + "environment": { + "variables": { + "WING_FUNCTION_NAME": "Handler-c8f5c667", + "WING_TARGET": "tf-aws", + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + } + }, + "function_name": "Handler-c8f5c667", + "handler": "index.handler", + "publish": true, + "role": "${aws_iam_role.testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_IamRole_F762CCC6.arn}", + "runtime": "nodejs18.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_S3Object_FEEF8ACC.key}", + "timeout": 30, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_lambda_permission": { @@ -422,6 +480,17 @@ module.exports = function({ $api_url, $http_HEAD, $http_OPTIONS, $http_Util, $pa "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_S3Object_FEEF8ACC": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS/Handler/S3Object", + "uniqueId": "testhttpfetchcanpreformacalltoanapitoCONNECTHEADandOPTIONS_Handler_S3Object_FEEF8ACC" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -449,7 +518,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ - $api_OPTIONS: ${context._lift(api_OPTIONS)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, $path: ${context._lift(path)}, }) `); @@ -467,7 +536,6 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { - $Closure1._registerBindObject(api_OPTIONS, host, []); $Closure1._registerBindObject(path, host, []); } super._registerBind(host, ops); @@ -482,7 +550,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure2-1.js")({ - $api_HEAD: ${context._lift(api_HEAD)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, $path: ${context._lift(path)}, }) `); @@ -500,7 +568,6 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { - $Closure2._registerBindObject(api_HEAD, host, []); $Closure2._registerBindObject(path, host, []); } super._registerBind(host, ops); @@ -530,57 +597,47 @@ class $Root extends $stdlib.std.Resource { `); } } - const api_OPTIONS = cloud.HttpMethod.OPTIONS; - const http_OPTIONS = http.HttpMethod.OPTIONS; - const api_HEAD = cloud.HttpMethod.HEAD; - const http_HEAD = http.HttpMethod.HEAD; - const api_CONNECT = cloud.HttpMethod.CONNECT; + class $Closure4 extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + this._addInflightOps("handle", "$inflight_init"); + this.display.hidden = true; + } + static _toInflightType(context) { + return $stdlib.core.NodeJsCode.fromInline(` + require("./inflight.$Closure4-1.js")({ + $api_url: ${context._lift(api.url)}, + $http_HttpMethod: ${context._lift(http.HttpMethod)}, + $http_Util: ${context._lift(http.Util)}, + $path: ${context._lift(path)}, + }) + `); + } + _toInflight() { + return $stdlib.core.NodeJsCode.fromInline(` + (await (async () => { + const $Closure4Client = ${$Closure4._toInflightType(this).text}; + const client = new $Closure4Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `); + } + _registerBind(host, ops) { + if (ops.includes("handle")) { + $Closure4._registerBindObject(api.url, host, []); + $Closure4._registerBindObject(path, host, []); + } + super._registerBind(host, ops); + } + } const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); const path = "/path"; (api.options(path,new $Closure1(this,"$Closure1"))); (api.head(path,new $Closure2(this,"$Closure2"))); (api.connect(path,new $Closure3(this,"$Closure3"))); - if (((util.Util.env("WING_TARGET")) !== "tf-aws")) { - class $Closure4 extends $stdlib.std.Resource { - constructor(scope, id, ) { - super(scope, id); - this._addInflightOps("handle", "$inflight_init"); - this.display.hidden = true; - } - static _toInflightType(context) { - return $stdlib.core.NodeJsCode.fromInline(` - require("./inflight.$Closure4-1.js")({ - $api_url: ${context._lift(api.url)}, - $http_HEAD: ${context._lift(http_HEAD)}, - $http_OPTIONS: ${context._lift(http_OPTIONS)}, - $http_Util: ${context._lift(http.Util)}, - $path: ${context._lift(path)}, - }) - `); - } - _toInflight() { - return $stdlib.core.NodeJsCode.fromInline(` - (await (async () => { - const $Closure4Client = ${$Closure4._toInflightType(this).text}; - const client = new $Closure4Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `); - } - _registerBind(host, ops) { - if (ops.includes("handle")) { - $Closure4._registerBindObject(api.url, host, []); - $Closure4._registerBindObject(http_HEAD, host, []); - $Closure4._registerBindObject(http_OPTIONS, host, []); - $Closure4._registerBindObject(path, host, []); - } - super._registerBind(host, ops); - } - } - this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS",new $Closure4(this,"$Closure4")); - } + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.fetch can preform a call to an api to CONNECT, HEAD and OPTIONS",new $Closure4(this,"$Closure4")); } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/patch.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/patch.w_compile_tf-aws.md index a3344a29e60..93c27865474 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/patch.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/patch.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $_id, $api_PATCH, $body, $std_Json }) { +module.exports = function({ $_id, $body, $cloud_HttpMethod, $std_Json }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -10,7 +10,7 @@ module.exports = function({ $_id, $api_PATCH, $body, $std_Json }) { return $obj; } async handle(req) { - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_PATCH")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_PATCH)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.PATCH")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.PATCH)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.vars?.get(\"id\") == _id")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.vars)["id"],$_id)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == \"/path/\"+ _id")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,("/path/" + $_id))))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.body == Json.stringify(body)")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.body,((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]))))}; @@ -25,7 +25,7 @@ module.exports = function({ $_id, $api_PATCH, $body, $std_Json }) { ## inflight.$Closure2-1.js ```js -module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std_Json }) { +module.exports = function({ $_id, $api_url, $body, $http_HttpMethod, $http_Util, $std_Json }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -35,7 +35,7 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std async handle() { const url = String.raw({ raw: ["", "/path/", ""] }, $api_url, $_id); const response = (await $http_Util.patch(url,{ headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); - const fetchResponse = (await $http_Util.patch(url,{ method: $http_PATCH, headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); + const fetchResponse = (await $http_Util.patch(url,{ method: $http_HttpMethod.PATCH, headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); {((cond) => {if (!cond) throw new Error("assertion failed: response.body == _id")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.body,$_id)))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.status == 200")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.status,200)))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.url == url")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.url,url)))}; @@ -82,7 +82,7 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std }, "output": { "WING_TEST_RUNNER_FUNCTION_ARNS": { - "value": "[]" + "value": "[[\"root/Default/Default/test:http.patch and http.fetch can preform a call to an api\",\"${aws_lambda_function.testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_185CBA02.arn}\"]]" } }, "provider": { @@ -104,7 +104,7 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "fea7e9f182aa5daf0c90efdf632bb2737c4ef5c4" + "redeployment": "2afd05beaf27bcecd099e20f65c2990011bdae48" } } }, @@ -142,6 +142,15 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRole_C2F43DF0": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.patch and http.fetch can preform a call to an api/Handler/IamRole", + "uniqueId": "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRole_C2F43DF0" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -154,6 +163,16 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_6D4DBF6C": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.patch and http.fetch can preform a call to an api/Handler/IamRolePolicy", + "uniqueId": "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_6D4DBF6C" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRole_C2F43DF0.name}" } }, "aws_iam_role_policy_attachment": { @@ -166,6 +185,16 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_FDA4E9BA": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.patch and http.fetch can preform a call to an api/Handler/IamRolePolicyAttachment", + "uniqueId": "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_FDA4E9BA" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRole_C2F43DF0.name}" } }, "aws_lambda_function": { @@ -194,6 +223,33 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std "security_group_ids": [], "subnet_ids": [] } + }, + "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_185CBA02": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.patch and http.fetch can preform a call to an api/Handler/Default", + "uniqueId": "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_185CBA02" + } + }, + "environment": { + "variables": { + "WING_FUNCTION_NAME": "Handler-c89df580", + "WING_TARGET": "tf-aws", + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + } + }, + "function_name": "Handler-c89df580", + "handler": "index.handler", + "publish": true, + "role": "${aws_iam_role.testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_IamRole_C2F43DF0.arn}", + "runtime": "nodejs18.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_S3Object_2CE72DAC.key}", + "timeout": 30, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_lambda_permission": { @@ -233,6 +289,17 @@ module.exports = function({ $_id, $api_url, $body, $http_PATCH, $http_Util, $std "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_S3Object_2CE72DAC": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.patch and http.fetch can preform a call to an api/Handler/S3Object", + "uniqueId": "testhttppatchandhttpfetchcanpreformacalltoanapi_Handler_S3Object_2CE72DAC" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -261,8 +328,8 @@ class $Root extends $stdlib.std.Resource { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ $_id: ${context._lift(_id)}, - $api_PATCH: ${context._lift(api_PATCH)}, $body: ${context._lift(body)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, $std_Json: ${context._lift(std.Json)}, }) `); @@ -281,60 +348,54 @@ class $Root extends $stdlib.std.Resource { _registerBind(host, ops) { if (ops.includes("handle")) { $Closure1._registerBindObject(_id, host, []); - $Closure1._registerBindObject(api_PATCH, host, []); $Closure1._registerBindObject(body, host, []); } super._registerBind(host, ops); } } - const http_PATCH = http.HttpMethod.PATCH; - const api_PATCH = cloud.HttpMethod.PATCH; + class $Closure2 extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + this._addInflightOps("handle", "$inflight_init"); + this.display.hidden = true; + } + static _toInflightType(context) { + return $stdlib.core.NodeJsCode.fromInline(` + require("./inflight.$Closure2-1.js")({ + $_id: ${context._lift(_id)}, + $api_url: ${context._lift(api.url)}, + $body: ${context._lift(body)}, + $http_HttpMethod: ${context._lift(http.HttpMethod)}, + $http_Util: ${context._lift(http.Util)}, + $std_Json: ${context._lift(std.Json)}, + }) + `); + } + _toInflight() { + return $stdlib.core.NodeJsCode.fromInline(` + (await (async () => { + const $Closure2Client = ${$Closure2._toInflightType(this).text}; + const client = new $Closure2Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `); + } + _registerBind(host, ops) { + if (ops.includes("handle")) { + $Closure2._registerBindObject(_id, host, []); + $Closure2._registerBindObject(api.url, host, []); + $Closure2._registerBindObject(body, host, []); + } + super._registerBind(host, ops); + } + } const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); const body = ({"cat": "Tion"}); const _id = "12345"; (api.patch("/path/{id}",new $Closure1(this,"$Closure1"))); - if (((util.Util.env("WING_TARGET")) !== "tf-aws")) { - class $Closure2 extends $stdlib.std.Resource { - constructor(scope, id, ) { - super(scope, id); - this._addInflightOps("handle", "$inflight_init"); - this.display.hidden = true; - } - static _toInflightType(context) { - return $stdlib.core.NodeJsCode.fromInline(` - require("./inflight.$Closure2-1.js")({ - $_id: ${context._lift(_id)}, - $api_url: ${context._lift(api.url)}, - $body: ${context._lift(body)}, - $http_PATCH: ${context._lift(http_PATCH)}, - $http_Util: ${context._lift(http.Util)}, - $std_Json: ${context._lift(std.Json)}, - }) - `); - } - _toInflight() { - return $stdlib.core.NodeJsCode.fromInline(` - (await (async () => { - const $Closure2Client = ${$Closure2._toInflightType(this).text}; - const client = new $Closure2Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `); - } - _registerBind(host, ops) { - if (ops.includes("handle")) { - $Closure2._registerBindObject(_id, host, []); - $Closure2._registerBindObject(api.url, host, []); - $Closure2._registerBindObject(body, host, []); - $Closure2._registerBindObject(http_PATCH, host, []); - } - super._registerBind(host, ops); - } - } - this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.patch and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); - } + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.patch and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/post.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/post.w_compile_tf-aws.md index a4db9fadd7b..2c1287752e3 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/post.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/post.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $api_POST, $body, $std_Json }) { +module.exports = function({ $body, $cloud_HttpMethod, $std_Json }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -10,7 +10,7 @@ module.exports = function({ $api_POST, $body, $std_Json }) { return $obj; } async handle(req) { - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_POST")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_POST)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.POST")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.POST)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == \"/path\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,"/path")))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.body == Json.stringify(body)")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.body,((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]))))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.headers?.get(\"content-type\") == \"application/json\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.headers)["content-type"],"application/json")))}; @@ -24,7 +24,7 @@ module.exports = function({ $api_POST, $body, $std_Json }) { ## inflight.$Closure2-1.js ```js -module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json }) { +module.exports = function({ $api_url, $body, $http_HttpMethod, $http_Util, $std_Json }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -34,7 +34,7 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } async handle() { const url = ($api_url + "/path"); const response = (await $http_Util.post(url,{ headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); - const fetchResponse = (await $http_Util.post(url,{ method: $http_POST, headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); + const fetchResponse = (await $http_Util.post(url,{ method: $http_HttpMethod.POST, headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); {((cond) => {if (!cond) throw new Error("assertion failed: response.body == Json.stringify(body)")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.body,((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]))))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.status == 200")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.status,200)))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.url == url")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.url,url)))}; @@ -81,7 +81,7 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } }, "output": { "WING_TEST_RUNNER_FUNCTION_ARNS": { - "value": "[]" + "value": "[[\"root/Default/Default/test:http.post and http.fetch can preform a call to an api\",\"${aws_lambda_function.testhttppostandhttpfetchcanpreformacalltoanapi_Handler_C4853DBD.arn}\"]]" } }, "provider": { @@ -103,7 +103,7 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "2e0d4578fa0f01cc502b493b801d616ab05c6da5" + "redeployment": "afb250682538f14812af9e01ecd4d6310c8cfb87" } } }, @@ -141,6 +141,15 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRole_364748FC": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.post and http.fetch can preform a call to an api/Handler/IamRole", + "uniqueId": "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRole_364748FC" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -153,6 +162,16 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_720C559E": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.post and http.fetch can preform a call to an api/Handler/IamRolePolicy", + "uniqueId": "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_720C559E" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRole_364748FC.name}" } }, "aws_iam_role_policy_attachment": { @@ -165,6 +184,16 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_E623498E": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.post and http.fetch can preform a call to an api/Handler/IamRolePolicyAttachment", + "uniqueId": "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_E623498E" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRole_364748FC.name}" } }, "aws_lambda_function": { @@ -193,6 +222,33 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } "security_group_ids": [], "subnet_ids": [] } + }, + "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_C4853DBD": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.post and http.fetch can preform a call to an api/Handler/Default", + "uniqueId": "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_C4853DBD" + } + }, + "environment": { + "variables": { + "WING_FUNCTION_NAME": "Handler-c88947b5", + "WING_TARGET": "tf-aws", + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + } + }, + "function_name": "Handler-c88947b5", + "handler": "index.handler", + "publish": true, + "role": "${aws_iam_role.testhttppostandhttpfetchcanpreformacalltoanapi_Handler_IamRole_364748FC.arn}", + "runtime": "nodejs18.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.testhttppostandhttpfetchcanpreformacalltoanapi_Handler_S3Object_BEC67279.key}", + "timeout": 30, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_lambda_permission": { @@ -232,6 +288,17 @@ module.exports = function({ $api_url, $body, $http_POST, $http_Util, $std_Json } "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_S3Object_BEC67279": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.post and http.fetch can preform a call to an api/Handler/S3Object", + "uniqueId": "testhttppostandhttpfetchcanpreformacalltoanapi_Handler_S3Object_BEC67279" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -259,8 +326,8 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ - $api_POST: ${context._lift(api_POST)}, $body: ${context._lift(body)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, $std_Json: ${context._lift(std.Json)}, }) `); @@ -278,57 +345,51 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { - $Closure1._registerBindObject(api_POST, host, []); $Closure1._registerBindObject(body, host, []); } super._registerBind(host, ops); } } - const http_POST = http.HttpMethod.POST; - const api_POST = cloud.HttpMethod.POST; - const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); - const body = ({"cat": "Tion"}); - (api.post("/path",new $Closure1(this,"$Closure1"))); - if (((util.Util.env("WING_TARGET")) !== "tf-aws")) { - class $Closure2 extends $stdlib.std.Resource { - constructor(scope, id, ) { - super(scope, id); - this._addInflightOps("handle", "$inflight_init"); - this.display.hidden = true; - } - static _toInflightType(context) { - return $stdlib.core.NodeJsCode.fromInline(` - require("./inflight.$Closure2-1.js")({ - $api_url: ${context._lift(api.url)}, - $body: ${context._lift(body)}, - $http_POST: ${context._lift(http_POST)}, - $http_Util: ${context._lift(http.Util)}, - $std_Json: ${context._lift(std.Json)}, - }) - `); - } - _toInflight() { - return $stdlib.core.NodeJsCode.fromInline(` - (await (async () => { - const $Closure2Client = ${$Closure2._toInflightType(this).text}; - const client = new $Closure2Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `); - } - _registerBind(host, ops) { - if (ops.includes("handle")) { - $Closure2._registerBindObject(api.url, host, []); - $Closure2._registerBindObject(body, host, []); - $Closure2._registerBindObject(http_POST, host, []); - } - super._registerBind(host, ops); + class $Closure2 extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + this._addInflightOps("handle", "$inflight_init"); + this.display.hidden = true; + } + static _toInflightType(context) { + return $stdlib.core.NodeJsCode.fromInline(` + require("./inflight.$Closure2-1.js")({ + $api_url: ${context._lift(api.url)}, + $body: ${context._lift(body)}, + $http_HttpMethod: ${context._lift(http.HttpMethod)}, + $http_Util: ${context._lift(http.Util)}, + $std_Json: ${context._lift(std.Json)}, + }) + `); + } + _toInflight() { + return $stdlib.core.NodeJsCode.fromInline(` + (await (async () => { + const $Closure2Client = ${$Closure2._toInflightType(this).text}; + const client = new $Closure2Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `); + } + _registerBind(host, ops) { + if (ops.includes("handle")) { + $Closure2._registerBindObject(api.url, host, []); + $Closure2._registerBindObject(body, host, []); } + super._registerBind(host, ops); } - this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.post and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } + const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); + const body = ({"cat": "Tion"}); + (api.post("/path",new $Closure1(this,"$Closure1"))); + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.post and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/put.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/put.w_compile_tf-aws.md index f4402ead238..bd7cf654bb0 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/put.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/api/put.w_compile_tf-aws.md @@ -2,7 +2,7 @@ ## inflight.$Closure1-1.js ```js -module.exports = function({ $_id, $api_PUT, $body, $std_Json, $user }) { +module.exports = function({ $_id, $body, $cloud_HttpMethod, $std_Json, $user }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -11,7 +11,7 @@ module.exports = function({ $_id, $api_PUT, $body, $std_Json, $user }) { } async handle(req) { const path = String.raw({ raw: ["/path/", "/nn/", ""] }, $_id, $user); - {((cond) => {if (!cond) throw new Error("assertion failed: req.method == api_PUT")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$api_PUT)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: req.method == cloud.HttpMethod.PUT")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.method,$cloud_HttpMethod.PUT)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.vars?.get(\"id\") == _id")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.vars)["id"],$_id)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.vars?.get(\"user\") == user")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((req.vars)["user"],$user)))}; {((cond) => {if (!cond) throw new Error("assertion failed: req.path == path")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(req.path,path)))}; @@ -27,7 +27,7 @@ module.exports = function({ $_id, $api_PUT, $body, $std_Json, $user }) { ## inflight.$Closure2-1.js ```js -module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_Json, $user }) { +module.exports = function({ $_id, $api_url, $body, $http_HttpMethod, $http_Util, $std_Json, $user }) { class $Closure2 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -37,7 +37,7 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J async handle() { const url = String.raw({ raw: ["", "/path/", "/nn/", ""] }, $api_url, $_id, $user); const response = (await $http_Util.put(url,{ headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); - const fetchResponse = (await $http_Util.put(url,{ method: $http_PUT, headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); + const fetchResponse = (await $http_Util.put(url,{ method: $http_HttpMethod.PUT, headers: ({"content-type": "application/json"}), body: ((args) => { return JSON.stringify(args[0], null, args[1]) })([$body]) })); {((cond) => {if (!cond) throw new Error("assertion failed: response.headers.get(\"content-type\") == \"application/json; charset=utf-8\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((response.headers)["content-type"],"application/json; charset=utf-8")))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.body == _id")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.body,$_id)))}; {((cond) => {if (!cond) throw new Error("assertion failed: response.status == 200")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(response.status,200)))}; @@ -86,7 +86,7 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J }, "output": { "WING_TEST_RUNNER_FUNCTION_ARNS": { - "value": "[]" + "value": "[[\"root/Default/Default/test:http.put and http.fetch can preform a call to an api\",\"${aws_lambda_function.testhttpputandhttpfetchcanpreformacalltoanapi_Handler_2B7157C1.arn}\"]]" } }, "provider": { @@ -108,7 +108,7 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "a67fe6988218a80a1321d2cf04424fe744273dd4" + "redeployment": "4c47cf4383648e8878b273255efa16fb8e65ec18" } } }, @@ -146,6 +146,15 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRole_4C35EBED": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.put and http.fetch can preform a call to an api/Handler/IamRole", + "uniqueId": "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRole_4C35EBED" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -158,6 +167,16 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_D35A09FD": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.put and http.fetch can preform a call to an api/Handler/IamRolePolicy", + "uniqueId": "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicy_D35A09FD" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRole_4C35EBED.name}" } }, "aws_iam_role_policy_attachment": { @@ -170,6 +189,16 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.cloudApi_cloudApi-OnRequest-cdafee6e_IamRole_4382C442.name}" + }, + "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_DEDD4EEB": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.put and http.fetch can preform a call to an api/Handler/IamRolePolicyAttachment", + "uniqueId": "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRolePolicyAttachment_DEDD4EEB" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRole_4C35EBED.name}" } }, "aws_lambda_function": { @@ -198,6 +227,33 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J "security_group_ids": [], "subnet_ids": [] } + }, + "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_2B7157C1": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.put and http.fetch can preform a call to an api/Handler/Default", + "uniqueId": "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_2B7157C1" + } + }, + "environment": { + "variables": { + "WING_FUNCTION_NAME": "Handler-c8e4b12f", + "WING_TARGET": "tf-aws", + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + } + }, + "function_name": "Handler-c8e4b12f", + "handler": "index.handler", + "publish": true, + "role": "${aws_iam_role.testhttpputandhttpfetchcanpreformacalltoanapi_Handler_IamRole_4C35EBED.arn}", + "runtime": "nodejs18.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.testhttpputandhttpfetchcanpreformacalltoanapi_Handler_S3Object_8E1D5390.key}", + "timeout": 30, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_lambda_permission": { @@ -237,6 +293,17 @@ module.exports = function({ $_id, $api_url, $body, $http_PUT, $http_Util, $std_J "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_S3Object_8E1D5390": { + "//": { + "metadata": { + "path": "root/Default/Default/test:http.put and http.fetch can preform a call to an api/Handler/S3Object", + "uniqueId": "testhttpputandhttpfetchcanpreformacalltoanapi_Handler_S3Object_8E1D5390" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -265,8 +332,8 @@ class $Root extends $stdlib.std.Resource { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure1-1.js")({ $_id: ${context._lift(_id)}, - $api_PUT: ${context._lift(api_PUT)}, $body: ${context._lift(body)}, + $cloud_HttpMethod: ${context._lift(cloud.HttpMethod)}, $std_Json: ${context._lift(std.Json)}, $user: ${context._lift(user)}, }) @@ -286,64 +353,58 @@ class $Root extends $stdlib.std.Resource { _registerBind(host, ops) { if (ops.includes("handle")) { $Closure1._registerBindObject(_id, host, []); - $Closure1._registerBindObject(api_PUT, host, []); $Closure1._registerBindObject(body, host, []); $Closure1._registerBindObject(user, host, []); } super._registerBind(host, ops); } } - const http_PUT = http.HttpMethod.PUT; - const api_PUT = cloud.HttpMethod.PUT; + class $Closure2 extends $stdlib.std.Resource { + constructor(scope, id, ) { + super(scope, id); + this._addInflightOps("handle", "$inflight_init"); + this.display.hidden = true; + } + static _toInflightType(context) { + return $stdlib.core.NodeJsCode.fromInline(` + require("./inflight.$Closure2-1.js")({ + $_id: ${context._lift(_id)}, + $api_url: ${context._lift(api.url)}, + $body: ${context._lift(body)}, + $http_HttpMethod: ${context._lift(http.HttpMethod)}, + $http_Util: ${context._lift(http.Util)}, + $std_Json: ${context._lift(std.Json)}, + $user: ${context._lift(user)}, + }) + `); + } + _toInflight() { + return $stdlib.core.NodeJsCode.fromInline(` + (await (async () => { + const $Closure2Client = ${$Closure2._toInflightType(this).text}; + const client = new $Closure2Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `); + } + _registerBind(host, ops) { + if (ops.includes("handle")) { + $Closure2._registerBindObject(_id, host, []); + $Closure2._registerBindObject(api.url, host, []); + $Closure2._registerBindObject(body, host, []); + $Closure2._registerBindObject(user, host, []); + } + super._registerBind(host, ops); + } + } const api = this.node.root.newAbstract("@winglang/sdk.cloud.Api",this,"cloud.Api"); const body = ({"cat": "Tion"}); const user = "guy"; const _id = "12345"; (api.put("/path/{id}/nn/{user}",new $Closure1(this,"$Closure1"))); - if (((util.Util.env("WING_TARGET")) !== "tf-aws")) { - class $Closure2 extends $stdlib.std.Resource { - constructor(scope, id, ) { - super(scope, id); - this._addInflightOps("handle", "$inflight_init"); - this.display.hidden = true; - } - static _toInflightType(context) { - return $stdlib.core.NodeJsCode.fromInline(` - require("./inflight.$Closure2-1.js")({ - $_id: ${context._lift(_id)}, - $api_url: ${context._lift(api.url)}, - $body: ${context._lift(body)}, - $http_PUT: ${context._lift(http_PUT)}, - $http_Util: ${context._lift(http.Util)}, - $std_Json: ${context._lift(std.Json)}, - $user: ${context._lift(user)}, - }) - `); - } - _toInflight() { - return $stdlib.core.NodeJsCode.fromInline(` - (await (async () => { - const $Closure2Client = ${$Closure2._toInflightType(this).text}; - const client = new $Closure2Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `); - } - _registerBind(host, ops) { - if (ops.includes("handle")) { - $Closure2._registerBindObject(_id, host, []); - $Closure2._registerBindObject(api.url, host, []); - $Closure2._registerBindObject(body, host, []); - $Closure2._registerBindObject(http_PUT, host, []); - $Closure2._registerBindObject(user, host, []); - } - super._registerBind(host, ops); - } - } - this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.put and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); - } + this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:http.put and http.fetch can preform a call to an api",new $Closure2(this,"$Closure2")); } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/api.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/api.w_compile_tf-aws.md index 5556c89fecf..3f2f3a620c3 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/api.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/api.w_compile_tf-aws.md @@ -126,7 +126,7 @@ module.exports = function({ }) { }, "rest_api_id": "${aws_api_gateway_rest_api.A_cloudApi_api_37FCEF91.id}", "triggers": { - "redeployment": "ee737a93987c97858ba9524a5b87b2ff1b0e62e4" + "redeployment": "66f9e4b69146527e1951e6308dc9128a3ca41abb" } }, "cloudApi_api_deployment_545514BF": { @@ -141,7 +141,7 @@ module.exports = function({ }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "06d5d79d88a464ffe5666fff8744c6bcc926732c" + "redeployment": "d4a66f49086c55ef3890317ca607c501380327bb" } } }, @@ -315,7 +315,7 @@ module.exports = function({ }) { "variables": { "WING_FUNCTION_NAME": "cloud-Api-OnRequest-73c5308f-c85168bb", "WING_TARGET": "tf-aws", - "WING_TOKEN_TFTOKEN_TOKEN_42": "${jsonencode(aws_api_gateway_stage.A_cloudApi_api_stage_6D822CCE.invoke_url)}" + "WING_TOKEN_TFTOKEN_TOKEN_41": "${jsonencode(aws_api_gateway_stage.A_cloudApi_api_stage_6D822CCE.invoke_url)}" } }, "function_name": "cloud-Api-OnRequest-73c5308f-c85168bb", @@ -369,7 +369,7 @@ module.exports = function({ }) { "variables": { "WING_FUNCTION_NAME": "Handler-c8315524", "WING_TARGET": "tf-aws", - "WING_TOKEN_TFTOKEN_TOKEN_21": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" } }, "function_name": "Handler-c8315524", diff --git a/tools/hangar/__snapshots__/test_corpus/valid/api_path_vars.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/api_path_vars.w_compile_tf-aws.md index 7e17e245a58..b4abcad7121 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/api_path_vars.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/api_path_vars.w_compile_tf-aws.md @@ -94,7 +94,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "ee1148d10d8bb2403dd0cc6100b576b5968ee68f" + "redeployment": "4ae1656762ef65f98b4b2e240588f473cd4e9469" } } }, @@ -225,7 +225,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) { "variables": { "WING_FUNCTION_NAME": "Handler-c8f4f2a1", "WING_TARGET": "tf-aws", - "WING_TOKEN_TFTOKEN_TOKEN_21": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" } }, "function_name": "Handler-c8f4f2a1", diff --git a/tools/hangar/__snapshots__/test_corpus/valid/api_valid_path.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/api_valid_path.w_compile_tf-aws.md index b38d20f829c..8855f56e344 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/api_valid_path.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/api_valid_path.w_compile_tf-aws.md @@ -73,7 +73,7 @@ module.exports = function({ }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "934e9973d7d898c43f960c4bc11231cc4be43a56" + "redeployment": "ca397382abb9ec6fa6cdfa8a96c26d44013057ba" } } }, diff --git a/tools/hangar/__snapshots__/test_corpus/valid/capture_tokens.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/capture_tokens.w_compile_tf-aws.md index a50a57d1062..34389110a89 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/capture_tokens.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/capture_tokens.w_compile_tf-aws.md @@ -254,9 +254,7 @@ module.exports = function({ }) { "variables": { "WING_FUNCTION_NAME": "Handler-c8ed8f29", "WING_TARGET": "tf-aws", - "WING_TOKEN_TFTOKEN_TOKEN_11": "${jsonencode(aws_api_gateway_stage.MyResource_cloudApi_api_stage_A26656F9.invoke_url)}", - "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.MyResource_cloudApi_api_stage_A26656F9.invoke_url)}", - "WING_TOKEN_TFTOKEN_TOKEN_8": "${jsonencode(aws_api_gateway_stage.MyResource_cloudApi_api_stage_A26656F9.invoke_url)}" + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.MyResource_cloudApi_api_stage_A26656F9.invoke_url)}" } }, "function_name": "Handler-c8ed8f29", @@ -283,8 +281,7 @@ module.exports = function({ }) { "variables": { "WING_FUNCTION_NAME": "Handler-c8ecc6d5", "WING_TARGET": "tf-aws", - "WING_TOKEN_TFTOKEN_TOKEN_33": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}", - "WING_TOKEN_TFTOKEN_TOKEN_34": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + "WING_TOKEN_TFTOKEN_TOKEN_30": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" } }, "function_name": "Handler-c8ecc6d5", diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md index 95c2ac44632..7920176d8b1 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md @@ -73,7 +73,7 @@ module.exports = function({ }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "06d5d79d88a464ffe5666fff8744c6bcc926732c" + "redeployment": "d4a66f49086c55ef3890317ca607c501380327bb" } } }, diff --git a/tools/hangar/__snapshots__/test_corpus/valid/issue_2889.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/issue_2889.w_compile_tf-aws.md index 36a4875e40a..44220f83751 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/issue_2889.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/issue_2889.w_compile_tf-aws.md @@ -95,7 +95,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "388c90ec9e86835eaf113a3e1c432f4758bfa061" + "redeployment": "ca2771f24c2978f810a5a1a5c3373f4ac9d7d88c" } } }, @@ -226,7 +226,7 @@ module.exports = function({ $api_url, $http_Util, $std_Json }) { "variables": { "WING_FUNCTION_NAME": "Handler-c88c3aa2", "WING_TARGET": "tf-aws", - "WING_TOKEN_TFTOKEN_TOKEN_21": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" + "WING_TOKEN_TFTOKEN_TOKEN_7": "${jsonencode(aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.invoke_url)}" } }, "function_name": "Handler-c88c3aa2", diff --git a/tools/hangar/__snapshots__/test_corpus/valid/website_with_api.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/website_with_api.w_compile_tf-aws.md index e0eb878feaf..a97c260ea86 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/website_with_api.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/website_with_api.w_compile_tf-aws.md @@ -151,7 +151,7 @@ module.exports = function({ }) { }, "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", "triggers": { - "redeployment": "53d34a77ebc006529cbee88240e663619396c753" + "redeployment": "968b3a7209054cfcc312829735646935481807e4" } } },