Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Aug 24, 2023
1 parent 802c9cb commit dacaf7f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libs/wing-fixture/lib.w
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bring cloud;
bring "./subdir/util.w" as myutil;

class Store {
data: cloud.Bucket;
Expand All @@ -7,6 +8,6 @@ class Store {
}

inflight set(message: str) {
this.data.put("data.txt", message);
this.data.put("data.txt", myutil.double(message));
}
}
5 changes: 5 additions & 0 deletions libs/wing-fixture/subdir/util.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Util {
static inflight double(msg: str): str {
return "${msg}${msg}";
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
# [bring_wing_library.w](../../../../../examples/tests/valid/bring_wing_library.w) | compile | tf-aws

## inflight.Store-1.js
## inflight.Store-2.js
```js
module.exports = function({ }) {
module.exports = function({ $myutil_Util }) {
class Store {
constructor({ $this_data }) {
this.$this_data = $this_data;
}
async set(message) {
(await this.$this_data.put("data.txt",message));
(await this.$this_data.put("data.txt",(await $myutil_Util.double(message))));
}
}
return Store;
}

```

## inflight.Util-1.js
```js
module.exports = function({ }) {
class Util {
constructor({ }) {
}
static async double(msg) {
return String.raw({ raw: ["", "", ""] }, msg, msg);
}
}
return Util;
}

```

## main.tf.json
```json
{
Expand Down Expand Up @@ -86,7 +101,7 @@ const $stdlib = require('@winglang/sdk');
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
const $wing_is_test = process.env.WING_IS_TEST === "true";
const std = $stdlib.std;
const fixture = require("./preflight.lib-1.js")({ $stdlib });
const fixture = require("./preflight.lib-2.js")({ $stdlib });
class $Root extends $stdlib.std.Resource {
constructor(scope, id) {
super(scope, id);
Expand All @@ -98,11 +113,12 @@ new $App({ outdir: $outdir, name: "bring_wing_library", rootConstruct: $Root, pl

```
## preflight.lib-1.js
## preflight.lib-2.js
```js
module.exports = function({ $stdlib }) {
const std = $stdlib.std;
const cloud = $stdlib.cloud;
const myutil = require("./preflight.util-1.js")({ $stdlib });
class Store extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
Expand All @@ -111,7 +127,8 @@ module.exports = function({ $stdlib }) {
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
require("./inflight.Store-1.js")({
require("./inflight.Store-2.js")({
$myutil_Util: ${context._lift(myutil.Util)},
})
`);
}
Expand All @@ -132,6 +149,7 @@ module.exports = function({ $stdlib }) {
Store._registerBindObject(this.data, host, []);
}
if (ops.includes("set")) {
Store._registerBindObject(myutil.Util, host, ["double"]);
Store._registerBindObject(this.data, host, ["put"]);
}
super._registerBind(host, ops);
Expand All @@ -142,3 +160,35 @@ module.exports = function({ $stdlib }) {

```
## preflight.util-1.js
```js
module.exports = function({ $stdlib }) {
const std = $stdlib.std;
class Util extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this._addInflightOps("double", "$inflight_init");
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
require("./inflight.Util-1.js")({
})
`);
}
_toInflight() {
return $stdlib.core.NodeJsCode.fromInline(`
(await (async () => {
const UtilClient = ${Util._toInflightType(this).text};
const client = new UtilClient({
});
if (client.$inflight_init) { await client.$inflight_init(); }
return client;
})())
`);
}
}
return { Util };
};

```

0 comments on commit dacaf7f

Please sign in to comment.