Skip to content

Commit

Permalink
Merge branch 'main' into rybickic/bring-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Jul 25, 2023
2 parents bff36e7 + 1fa0224 commit 11cb524
Show file tree
Hide file tree
Showing 254 changed files with 757 additions and 450 deletions.
9 changes: 9 additions & 0 deletions apps/wing-console/console/app/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Contributing to Wing Console

## Start dev mode

```sh
pnpm dev
```

Also, you have to start the dev script on the `apps/wing-console/console/server` package.
2 changes: 1 addition & 1 deletion apps/wing-console/console/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"preview": "node scripts/preview.mjs",
"dev": "node scripts/dev.mjs",
"dev": "tsx watch scripts/dev.mjs",
"compile": "tsup",
"eslint": "eslint --ext .js,.cjs,.ts,.cts,.mts,.tsx --no-error-on-unmatched-pattern . --fix",
"test": "playwright test --update-snapshots",
Expand Down
26 changes: 15 additions & 11 deletions apps/wing-console/console/app/scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ const options = parseArgs({
},
});

const vite = await createViteServer({
...viteConfig,
server: { middlewareMode: true },
});

const { port } = await createConsoleServer({
const consoleServer = await createConsoleServer({
wingfile:
options.values.wingfile ??
fileURLToPath(new URL("../demo/index.w", import.meta.url)),
requestedPort: 1214,
async onExpressCreated(app) {
app.use(vite.middlewares);
},
log: {
info: console.log,
error: console.error,
Expand All @@ -49,6 +41,18 @@ const { port } = await createConsoleServer({
requireAcceptTerms: true,
});

await open(`http://localhost:${port}`);
const vite = await createViteServer({
...viteConfig,
server: {
proxy: {
"/trpc": {
target: `http://localhost:${consoleServer.port}`,
changeOrigin: true,
ws: true,
},
},
open: true,
},
});

console.log(`Wing Console is running on http://localhost:${port}/`);
await vite.listen();
22 changes: 13 additions & 9 deletions apps/wing-console/console/app/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ export const createAnalytics = (options: CreateAnalyticsOptions): Analytics => {
const sessionId = Date.now();
return {
track(event: string, properties?: Record<string, any>) {
segment.track({
anonymousId: options.anonymousId,
event: event.toLowerCase().replaceAll(/\s/g, ""),
properties,
integrations: {
"Actions Amplitude": {
session_id: sessionId,
try {
segment.track({
anonymousId: options.anonymousId,
event: event.toLowerCase().replaceAll(/\s/g, ""),
properties,
integrations: {
"Actions Amplitude": {
session_id: sessionId,
},
},
},
});
});
} catch (error) {
console.debug("failed to send analytics", error);
}
},
};
};
7 changes: 7 additions & 0 deletions apps/wing-console/console/server/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contributing to `@wingconsole/server`

## Start dev mode

```sh
pnpm dev
```
2 changes: 1 addition & 1 deletion docs/docs/01-start-here/01-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Wing addresses these challenges through several key pillars:
resources. This allows developers to build complete cloud applications without
having to be infrastructure experts.
* **Distributed computing support** - Traditional languages are designed to tell a single machine what to do, but the cloud at its core is a big distributed system.
Wing allows cloud applications to be written more naturally through the concepts of [preflight and inflight code](../concepts/inflights), which allow infrastructure and runtime code to be interleaved while
Wing allows cloud applications to be written more naturally through the concepts of [preflight and inflight code](https://www.winglang.io/docs/concepts/inflights), which allow infrastructure and runtime code to be interleaved while
giving developers the speed safety they expect from modern tooling.
* **Infrastructure as policy** - Infrastructure concerns such as deployment,
networking, security, and observability can be applied horizontally through
Expand Down
15 changes: 15 additions & 0 deletions examples/tests/valid/use_inflight_method_inside_init_closure.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
bring cloud;

class Foo {
init() {
new cloud.Function(inflight () => {
this.bar();
});
}

inflight bar() {

}
}

new Foo();
16 changes: 9 additions & 7 deletions libs/wingc/src/jsify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,16 +1039,14 @@ impl<'a> JSifier<'a> {
false
};

let mut body_code = CodeMaker::default();

// we always need a super() call because even if the class doesn't have an explicit parent, it
// will inherit from core.Resource.
if !super_called {
code.line("super(scope, id);");
body_code.line("super(scope, id);");
}

// We must jsify the statements in the constructor before adding any additional code blew
// this is to ensure if there are calls to super constructor within the statements,
// they will be jsified before any attempts to call `this` are made.
code.add_code(self.jsify_scope_body(&init_statements, ctx));
body_code.add_code(self.jsify_scope_body(&init_statements, ctx));

let inflight_fields = class.inflight_fields();
let inflight_methods = class.inflight_methods(true);
Expand All @@ -1066,9 +1064,13 @@ impl<'a> JSifier<'a> {
.chain(inflight_field_names.iter())
.map(|name| format!("\"{}\"", name))
.join(", ");
code.line(format!("this._addInflightOps({inflight_ops_string});"));

// insert as the first statement after the super() call
body_code.insert_line(1, format!("this._addInflightOps({inflight_ops_string});"));
}

code.add_code(body_code);

code.close("}");
code
}
Expand Down
25 changes: 25 additions & 0 deletions libs/wingc/src/jsify/codemaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ impl CodeMaker {
self.indent += 1;
}

/// Insert a line at the given index.
pub fn insert_line<S: Into<String>>(&mut self, index: usize, line: S) {
// get the indent of the current line at that index
let indent = self.lines.get(index).map(|(indent, _)| *indent).unwrap_or(self.indent);
self.lines.insert(index, (indent, line.into()));
}

pub fn one_line<S: Into<String>>(s: S) -> CodeMaker {
let mut code = CodeMaker::default();
code.line(s);
Expand Down Expand Up @@ -145,4 +152,22 @@ mod tests {
"#}
);
}

#[test]
fn codemaker_insert_line() {
let mut code = CodeMaker::default();
code.open("if true {");
code.line("let b = 2;");
code.close("}");
code.insert_line(1, "let a = 1;");
assert_eq!(
code.to_string(),
indoc! {r#"
if true {
let a = 1;
let b = 2;
}
"#}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class $Root extends $stdlib.std.Resource {
class Base extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.b = this.node.root.newAbstract("@winglang/sdk.cloud.Bucket",this,"cloud.Bucket");
this._addInflightOps("put", "$inflight_init");
this.b = this.node.root.newAbstract("@winglang/sdk.cloud.Bucket",this,"cloud.Bucket");
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class $Root extends $stdlib.std.Resource {
class Base extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.f = "hello";
this._addInflightOps("$inflight_init");
this.f = "hello";
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand All @@ -88,8 +88,8 @@ class $Root extends $stdlib.std.Resource {
class Derived extends Base {
constructor(scope, id, ) {
super(scope, id);
this.g = "world";
this._addInflightOps("$inflight_init");
this.g = "world";
}
foo() {
this.f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class $Root extends $stdlib.std.Resource {
class Base extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.b = this.node.root.newAbstract("@winglang/sdk.cloud.Bucket",this,"cloud.Bucket");
this._addInflightOps("$inflight_init");
this.b = this.node.root.newAbstract("@winglang/sdk.cloud.Bucket",this,"cloud.Bucket");
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class $Root extends $stdlib.std.Resource {
class Base extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.f = x;
this._addInflightOps("$inflight_init");
this.f = x;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
2 changes: 1 addition & 1 deletion libs/wingc/src/jsify/snapshots/builtins.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand All @@ -84,8 +84,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure2 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class $Root extends $stdlib.std.Resource {
class Foo extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.b = this.node.root.newAbstract("@winglang/sdk.cloud.Bucket",this,"cloud.Bucket");
this._addInflightOps("$inflight_init");
this.b = this.node.root.newAbstract("@winglang/sdk.cloud.Bucket",this,"cloud.Bucket");
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand All @@ -89,8 +89,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class $Root extends $stdlib.std.Resource {
class $Closure1 extends $stdlib.std.Resource {
constructor(scope, id, ) {
super(scope, id);
this.display.hidden = true;
this._addInflightOps("handle", "$inflight_init");
this.display.hidden = true;
}
static _toInflightType(context) {
return $stdlib.core.NodeJsCode.fromInline(`
Expand Down
Loading

0 comments on commit 11cb524

Please sign in to comment.