-
Notifications
You must be signed in to change notification settings - Fork 14
/
wplatform.js
48 lines (46 loc) · 1.75 KB
/
wplatform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { Function: SimFunction } = require("./sim/function.js");
const { Function: TfAwsFunction } = require("./tfaws/function.js");
const { Queue: TfAwsQueue } = require("./tfaws/queue.js");
const { Topic: TfAwsTopic } = require("./tfaws/topic.js");
const { Bucket: TfAwsBucket } = require("./tfaws/bucket.js");
const { Api: TfAwsApi } = require("./tfaws/api.js");
const { tryGetPythonInflight } = require("./inflight.js");
const FUNCTION_FQN = "@winglang/sdk.cloud.Function";
const QUEUE_FQN = "@winglang/sdk.cloud.Queue";
const TOPIC_FQN = "@winglang/sdk.cloud.Topic";
const BUCKET_FQN = "@winglang/sdk.cloud.Bucket";
const API_FQN = "@winglang/sdk.cloud.Api";
const createFunction = (target, scope, id, inflight, props) => {
const pythonInflight = tryGetPythonInflight(inflight);
if (pythonInflight) {
if (target === "tf-aws") {
return new TfAwsFunction(scope, id, inflight, props, pythonInflight);
} else if (target === "sim") {
return new SimFunction(scope, id, inflight, props, pythonInflight);
}
}
};
module.exports.Platform = class Platform {
newInstance(type, scope, id, ...props) {
const target = process.env["WING_TARGET"];
if (type === FUNCTION_FQN) {
return createFunction(target, scope, id, ...props);
} else if (type === QUEUE_FQN) {
if (target === "tf-aws") {
return new TfAwsQueue(scope, id, ...props);
}
} else if (type === TOPIC_FQN) {
if (target === "tf-aws") {
return new TfAwsTopic(scope, id, ...props);
}
} else if (type === BUCKET_FQN) {
if (target === "tf-aws") {
return new TfAwsBucket(scope, id, ...props);
}
} else if (type === API_FQN) {
if (target === "tf-aws") {
return new TfAwsApi(scope, id, ...props);
}
}
}
};