Skip to content

Commit

Permalink
chore: update libraries to use nodeof
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Jun 17, 2024
1 parent 066409a commit 826065c
Show file tree
Hide file tree
Showing 54 changed files with 769 additions and 97 deletions.
3 changes: 3 additions & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .mkrepo/gitattributes.w
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ pub class GitAttributes {
lines.push("");
lines.push("/.github/workflows/*-pull.yaml linguist-generated");
lines.push("/.github/workflows/*-release.yaml linguist-generated");
lines.push("/.github/workflows/canary.yaml linguist-generated");
lines.push("/**/package-lock.json linguist-generated");
lines.push("/**/*.extern.d.ts linguist-generated");
lines.push("/package-lock.json linguist-generated");
lines.push("/.mergify.yml linguist-generated");
lines.push("/.gitattributes linguist-generated");
lines.push("");
fs.writeFile(".gitattributes", lines.join("\n"));
}
Expand Down
2 changes: 1 addition & 1 deletion bedrock/bedrock.w
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub class Model impl a.IModel {

let target = util.env("WING_TARGET");
if target == "sim" {
if std.Node.of(this).app.isTestEnvironment {
if nodeof(this).app.isTestEnvironment {
// in case of test running on sim, use simulator version
this.inner = new s.Model_sim(modelId) as "sim";
} else {
Expand Down
6 changes: 3 additions & 3 deletions bedrock/joke.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ let joke = new j.JokeMaker();

// an experimental pattern for mocking responses
// this will only kick in if is in sim and test mode
if util.env("WING_TARGET") == "sim" && std.Node.of(joke).app.isTestEnvironment {
let model = std.Node.of(joke).findChild("claude").node.findChild("sim");
if util.env("WING_TARGET") == "sim" && nodeof(joke).app.isTestEnvironment {
let model = nodeof(nodeof(joke).findChild("claude")).findChild("sim");
let sim: s.Model_sim = unsafeCast(model);
sim.setMockResponse(inflight (body) => {
return {
Expand All @@ -21,4 +21,4 @@ if util.env("WING_TARGET") == "sim" && std.Node.of(joke).app.isTestEnvironment {
test "make a joke" {
let res = joke.makeJoke("oranges");
log(res);
}
}
2 changes: 1 addition & 1 deletion bedrock/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/bedrock",
"description": "A Wing library for Amazon Bedrock",
"version": "0.0.6",
"version": "0.0.7",
"author": {
"name": "Eyal Keren",
"email": "[email protected]"
Expand Down
20 changes: 12 additions & 8 deletions cdk8s/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cdk8s/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/cdk8s",
"description": "cdk8s library for Wing",
"version": "0.0.1",
"version": "0.0.2",
"author": {
"name": "Elad Ben-Israel",
"email": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion checks/check.w
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub class Check impl ICheck {
}

if props?.testing ?? true {
new std.Test(handler) as "check {this.node.id}";
new std.Test(handler) as "check {nodeof(this).id}";
}

this.invoker = new cloud.Function(wrapper) as "run";
Expand Down
4 changes: 2 additions & 2 deletions checks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/checks",
"version": "0.0.11",
"version": "0.0.12",
"description": "Cloud checks",
"publishConfig": {
"access": "public",
Expand All @@ -26,4 +26,4 @@
]
},
"license": "MIT"
}
}
8 changes: 4 additions & 4 deletions checks/results.w
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct CheckResult {
/** Centralized storage for check results */
pub class Results {
pub static of(scope: std.IResource): Results {
let var root = std.Node.of(scope).root;
let rootNode = std.Node.of(root);
let var root = nodeof(scope).root;
let rootNode = nodeof(root);

// special case where the root is an app with a test runner (which means we are running inside a test context)
// in this case our app is actually the child called "Default". yes this is horribly hacky.
Expand All @@ -33,7 +33,7 @@ pub class Results {
}

let id = "checks.Results";
let exists: Results? = unsafeCast(std.Node.of(root).tryFindChild(id));
let exists: Results? = unsafeCast(nodeof(root).tryFindChild(id));
let rootAsResource: Results = unsafeCast(root);
return exists ?? new Results() as id in rootAsResource;
}
Expand Down Expand Up @@ -69,4 +69,4 @@ pub class Results {
inflight makeLatestKey(checkid: str): str {
return this.makeKey(checkid, "latest.json");
}
}
}
2 changes: 1 addition & 1 deletion cognito/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/cognito",
"version": "0.0.10",
"version": "0.0.11",
"description": "A wing library to work with AWS Cognito",
"author": {
"name": "Elad Cohen",
Expand Down
2 changes: 1 addition & 1 deletion cognito/platform/sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub class Cognito_sim impl types.ICognito {
return cloud.ApiResponse.parseJson(res!);
});

this.api.node.tryRemoveChild(handler.mapping.node.id);
nodeof(this.api).tryRemoveChild(handler.mapping.node.id);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions containers/aws.w
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub class Aws {
pub static getOrCreate(scope: std.IResource): Aws {
let stack = nodeof(scope).root;
let id = "WingAwsUtil";
let existing: Aws? = unsafeCast(stack.node.tryFindChild(id));
let existing: Aws? = unsafeCast(nodeof(stack).tryFindChild(id));
return (existing ?? new Aws() as id in stack);
}

Expand All @@ -25,4 +25,4 @@ pub class Aws {
pub accountId(): str {
return this.accountData.accountId;
}
}
}
7 changes: 3 additions & 4 deletions containers/helm.extern.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions containers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion containers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/containers",
"version": "0.1.1",
"version": "0.1.2",
"description": "Container support for Wing",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion containers/tfaws-ecr.w
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub class Repository {
// null provider singleton
let root = nodeof(this).root;
let nullProviderId = "NullProvider";
if !root.node.tryFindChild(nullProviderId)? {
if !nodeof(root).tryFindChild(nullProviderId)? {
new null_provider.provider.NullProvider() as nullProviderId in root;
}

Expand Down
8 changes: 4 additions & 4 deletions containers/tfaws-eks.w
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub class ClusterBase impl ICluster {
let root = nodeof(this).root;
let singletonKey = "WingKubernetesProvider";
let attributes = this.attributes();
let existing = root.node.tryFindChild(singletonKey);
let existing = nodeof(root).tryFindChild(singletonKey);
if existing? {
return unsafeCast(existing);
}
Expand All @@ -49,7 +49,7 @@ pub class ClusterBase impl ICluster {
let root = nodeof(this).root;
let singletonKey = "WingHelmProvider";
let attributes = this.attributes();
let existing = root.node.tryFindChild(singletonKey);
let existing = nodeof(root).tryFindChild(singletonKey);
if existing? {
return unsafeCast(existing);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ pub class Cluster extends ClusterBase impl ICluster {
pub static getOrCreate(scope: std.IResource): ICluster {
let root = nodeof(scope).root;
let uid = "WingEksCluster";
let existing: ICluster? = unsafeCast(root.node.tryFindChild(uid));
let existing: ICluster? = unsafeCast(nodeof(root).tryFindChild(uid));

let newCluster = (): ICluster => {
if let attrs = Cluster.tryReadParameters(scope) {
Expand Down Expand Up @@ -189,7 +189,7 @@ pub class Cluster extends ClusterBase impl ICluster {
let lbRole = new cdktf.TerraformHclModule(
source: "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks",
variables: {
role_name: "eks-lb-role-{this.node.addr}",
role_name: "eks-lb-role-{nodeof(this).addr}",
attach_load_balancer_controller_policy: true,
oidc_providers: {
main: {
Expand Down
6 changes: 3 additions & 3 deletions dynamodb/dynamodb.sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class Host {

pub static of(scope: std.IResource): Host {
let uid = "DynamodbHost-7JOQ92VWh6OavMXYpWx9O";
let root = std.Node.of(scope).root;
let rootNode = std.Node.of(root);
let root = nodeof(scope).root;
let rootNode = nodeof(root);
let host = unsafeCast(rootNode.tryFindChild(uid)) ?? new Host() as uid in root;
nodeof(host).hidden = true;
return host;
Expand All @@ -111,7 +111,7 @@ pub class Table_sim impl dynamodb_types.ITable {
this.host = Host.of(this);

this.adminEndpoint = this.host.ui?.endpoint;
let tableName = props.name ?? this.node.addr;
let tableName = props.name ?? nodeof(this).addr;
let state = new sim.State();
this.tableName = state.token("tableName");

Expand Down
2 changes: 1 addition & 1 deletion dynamodb/dynamodb.tf-aws.w
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub class Table_tfaws impl dynamodb_types.ITable {
// - Get rid of the initial "root/Default/Default/" part (21 characters)
// - Make room for the last 8 digits of the address (9 characters including hyphen). 255 is the maximum length of an AWS resource name
// - Add the last 8 digits of the address
name: props.name ?? "{this.node.path.replaceAll("/", "-").substring(21, (255+21)-9)}-{this.node.addr.substring(42-8)}",
name: props.name ?? "{nodeof(this).path.replaceAll("/", "-").substring(21, (255+21)-9)}-{nodeof(this).addr.substring(42-8)}",
attribute: props.attributes,
hashKey: props.hashKey,
rangeKey: props.rangeKey,
Expand Down
2 changes: 1 addition & 1 deletion dynamodb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/dynamodb",
"version": "0.1.11",
"version": "0.1.12",
"description": "DynamoDB library for Wing",
"author": {
"name": "Cristian Pallarés",
Expand Down
2 changes: 1 addition & 1 deletion eventbridge/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@winglibs/eventbridge",
"description": "Amazon EventBridge library for Wing",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"type": "git",
"url": "https://github.com/winglang/winglibs.git",
Expand Down
2 changes: 1 addition & 1 deletion eventbridge/platform/awscdk/eventbridge.w
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub class Bus impl types.IBus {
if let eventBridgeName = app.parameters.value("eventBridgeName") {
this.eventBridge = cdk.aws_events.EventBus.fromEventBusName(this, "EventBridge", eventBridgeName);
} else {
this.eventBridge = new cdk.aws_events.EventBus(eventBusName: props?.name ?? "eventbridge-{this.node.addr.substring(0, 8)}") as "EventBridge";
this.eventBridge = new cdk.aws_events.EventBus(eventBusName: props?.name ?? "eventbridge-{nodeof(this).addr.substring(0, 8)}") as "EventBridge";
}
}

Expand Down
4 changes: 2 additions & 2 deletions eventbridge/platform/sim/bus.w
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub class EventBridgeBus {
}

let handler = new MyHandler(this.topic) as "EventBridgeOnMessageHandler{this.handlerCount}";
let node = std.Node.of(handler);
let node = nodeof(handler);

let handlerNode = std.Node.of(handler.onMessageHandler);
let handlerNode = nodeof(handler.onMessageHandler);
this.handlerCount += 1;

return handler.onMessageHandler;
Expand Down
Loading

0 comments on commit 826065c

Please sign in to comment.