diff --git a/python/function.test.w b/python/function.test.w index 1535fb24..1a5a59ed 100644 --- a/python/function.test.w +++ b/python/function.test.w @@ -8,6 +8,14 @@ bring ses; bring fs; bring "./lib.w" as python; +class CustomLiftable impl python.ILiftable { + pub liftData(): Json { + return { + "info": "CustomData", + }; + } +} + let table = new dynamodb.Table( attributes: [ { @@ -42,6 +50,10 @@ let func = new cloud.Function(new python.InflightFunction( obj: emailClient, allow: ["sendEmail"], }, + "custom": { + obj: new CustomLiftable(), + allow: [], + } }, ), { env: { "FOO": "bar" } }); @@ -51,5 +63,5 @@ new std.Test(inflight () => { let res = func.invoke("function1"); log("res: {res ?? "null"}"); expect.equal(Json.parse(res!).get("body"), "Hello!"); - expect.equal(bucket.get("test.txt"), "Hello, world!function1bardynamoDbValue"); + expect.equal(bucket.get("test.txt"), "Hello, world!function1bardynamoDbValueCustomData"); }, timeout: 3m) as "invokes the function"; diff --git a/python/lib.w b/python/lib.w index 2036bd7d..f13b6a22 100644 --- a/python/lib.w +++ b/python/lib.w @@ -7,6 +7,10 @@ bring "./sim/api_onrequest_inflight.w" as simapi; bring "./tfaws/inflight.w" as aws; bring "./tfaws/api_onrequest_inflight.w" as tfawsapi; +pub interface ILiftable { + liftData(): Json; +} + pub class InflightFunction impl cloud.IFunctionHandler { _inflightType: str; inner: types.IInflight; diff --git a/python/test-assets/main.py b/python/test-assets/main.py index 836c3642..c62619cd 100644 --- a/python/test-assets/main.py +++ b/python/test-assets/main.py @@ -21,11 +21,14 @@ def handler(event, context): table = lifted("table") response = table.get(Key={"id":"test"}) table_value = response["Item"]["body"] + + custom = lifted("custom") + custom_data = custom["liftData"]["info"] bucket = lifted("bucket") value = bucket.get("test.txt") - bucket.put("test.txt", value + payload + foo_env + table_value) - + bucket.put("test.txt", value + payload + foo_env + table_value + custom_data) + return { "statusCode": 200, "body": "Hello!" diff --git a/python/test-assets/requirements.txt b/python/test-assets/requirements.txt index f74c2c75..e72933c0 100644 --- a/python/test-assets/requirements.txt +++ b/python/test-assets/requirements.txt @@ -1,4 +1,4 @@ -wingsdk == 0.0.4 +wingsdk == 0.0.6 requests boto3 Faker diff --git a/python/tfaws/function.js b/python/tfaws/function.js index d339586a..bb638ad5 100644 --- a/python/tfaws/function.js +++ b/python/tfaws/function.js @@ -96,6 +96,15 @@ module.exports.Function = class Function extends Construct { target: "aws", props: {}, } + } else if (typeof client.liftData === "function") { + client.onLift(this.dummy, allow); + clients[clientId] = { + type: "@winglibs.python.ILiftable", + target: "aws", + props: { + liftData: client.liftData(), + }, + } } } diff --git a/python/util.js b/python/util.js index 8679031a..fee27baf 100644 --- a/python/util.js +++ b/python/util.js @@ -227,6 +227,18 @@ const getLifted = (resource, id) => { props: {}, } } + } else if (typeof resource.liftData === "function") { + lifted = { + id, + path: resource.node.path, + handle: makeEnvVarName("LIFT_DATA", resource), + type: "@winglibs.python.ILiftable", + target: "sim", + resource, + props: { + liftData: resource.liftData(), + }, + }; } return lifted;