Skip to content

Commit

Permalink
Merge branch 'main' into ekeren/inflight-should-capture-mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
ekeren authored Jun 26, 2023
2 parents e1c2b24 + 1905c82 commit be3694d
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 39 deletions.
117 changes: 117 additions & 0 deletions apps/wing-console/console/app/demo/index.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
bring cloud;
// bring redis;

let bucket = new cloud.Bucket();
let queue = new cloud.Queue();
let api = new cloud.Api();

api.get("/test-get", inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
return cloud.ApiResponse {
status: 200,
body: Json.stringify({
query: Json (Json req).get("query"),
})
};
});
api.post("/test-post", inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
return cloud.ApiResponse {
status: 200,
body: "Hello, POST!"
};
});

let handler = inflight (message: str): str => {
bucket.put("hello.txt", "Hello, ${message}!");
log("Hello, ${message}!");
return message;
};

queue.setConsumer(handler);

let counter = new cloud.Counter(initial: 0);
new cloud.Function(inflight (message: str): str => {
counter.inc();
log("Counter is now ${counter.inc(0)}");
return message;
}) as "IncrementCounter";

let topic = new cloud.Topic() as "Topic";
topic.onMessage(inflight (message: str): str => {
log("Topic subscriber #1: ${message}");
return message;
});
topic.onMessage(inflight (message: str): str => {
log("Topic subscriber #2: ${message}");
return message;
});

// let r = new redis.Redis();
// new cloud.Function(inflight (message :str) :str => {
// log("${r.url()}");
// r.set("wing", message);
// let value = r.get("wing");
// log("${value}");
// return r.url();
// }) as "Redis interaction";


let table = new cloud.Table(cloud.TableProps{
name: "simple-table",
primaryKey: "id",
columns: {
id: cloud.ColumnType.STRING,
name: cloud.ColumnType.STRING,
date: cloud.ColumnType.DATE,
active: cloud.ColumnType.BOOLEAN,
},
});

let rateSchedule = new cloud.Schedule(cloud.ScheduleProps{
rate: 5m
}) as "Rate Schedule";

rateSchedule.onTick(inflight () => {
log("Rate schedule ticked!");
});

let cronSchedule = new cloud.Schedule(cloud.ScheduleProps{
cron: "* * * * ?"
}) as "Cron Schedule";

// cronSchedule.onTick(inflight () => {
// log("Cron schedule ticked!");
// });

test "Increment counter" {
let previous = counter.inc();
log("Assertion should fail: ${previous} === ${counter.peek()}");
assert(previous == 1);
}

test "Push message to the queue" {
queue.push("hey");
}

test "Print"{
log("Hello World!");
assert(true);
}

test "without assertions nor prints" {
}

test "Add fixtures" {
let arr = [1, 2, 3, 4, 5];

log("Adding ${arr.length} files in the bucket..");
for item in arr {
bucket.put("fixture_${item}.txt", "Content for the fixture_${item}!");
}

log("Publishing to the topic..");
topic.publish("Hello, topic!");

log("Setting up counter..");
counter.set(0);
counter.inc(100);
}
7 changes: 1 addition & 6 deletions apps/wing-console/console/app/package-lock.json

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

5 changes: 2 additions & 3 deletions apps/wing-console/console/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"dist"
],
"scripts": {
"preview": "tsx scripts/preview.ts",
"dev": "tsup --watch",
"preview": "node scripts/preview.mjs",
"dev": "node scripts/dev.mjs",
"compile": "tsup",
"vitest": "vitest run --coverage --passWithNoTests",
"eslint": "eslint --ext .js,.cjs,.ts,.cts,.mts,.tsx --no-error-on-unmatched-pattern . --fix",
Expand All @@ -28,7 +28,6 @@
"@types/react-dom": "^18.2.5",
"@vitejs/plugin-react": "^4.0.0",
"@vitest/coverage-c8": "^0.31.4",
"@wingconsole/error-message": "file:../../tools/error-message",
"@wingconsole/eslint-plugin": "file:../../tools/eslint-plugin",
"@wingconsole/tsconfig": "file:../../tools/tsconfig",
"@wingconsole/ui": "file:../ui",
Expand Down
13 changes: 13 additions & 0 deletions apps/wing-console/console/app/scripts/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import react from "@vitejs/plugin-react";
import { fileURLToPath } from "node:url";
import * as vite from "vite";

/** @type vite.InlineConfig */
export const viteConfig = {
configFile: false,
root: fileURLToPath(new URL("../web", import.meta.url)),
plugins: [react()],
build: {
outDir: fileURLToPath(new URL("../dist/vite", import.meta.url)),
},
};
35 changes: 35 additions & 0 deletions apps/wing-console/console/app/scripts/dev.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createConsoleServer } from "@wingconsole/server";
import { fileURLToPath } from "node:url";
import open from "open";

import { createServer as createViteServer } from "vite";
import { viteConfig } from "./config.mjs";

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

const { port } = await createConsoleServer({
wingfile: fileURLToPath(new URL("../demo/index.w", import.meta.url)),
async onExpressCreated(app) {
app.use(vite.middlewares);
},
log: {
info: console.log,
error: console.error,
verbose: console.log,
},
config: {
addEventListener(event, listener) {},
removeEventListener(event, listener) {},
get(key) {
return undefined;
},
set(key, value) {},
},
});

await open(`http://localhost:${port}`);

console.log(`Wing Console is running on http://localhost:${port}/`);
12 changes: 12 additions & 0 deletions apps/wing-console/console/app/scripts/preview.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fileURLToPath } from "node:url";

import open from "open";

import { createConsoleApp } from "../dist/index.js";

const { port } = await createConsoleApp({
wingfile: fileURLToPath(
new URL("../../desktop/demo/index.w", import.meta.url),
),
});
await open(`http://localhost:${port}`);
10 changes: 0 additions & 10 deletions apps/wing-console/console/app/scripts/preview.ts

This file was deleted.

12 changes: 2 additions & 10 deletions apps/wing-console/console/app/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "tsup";
import * as vite from "vite";
import { viteConfig } from "./scripts/config.mjs";

export default defineConfig({
entry: ["src/index.ts"],
Expand All @@ -12,14 +12,6 @@ export default defineConfig({
console.log("Build succeeded");

console.log("Build UI files...");
await vite.build({
configFile: false,
root: "./web",
plugins: [react()],
build: {
outDir: "../dist/vite",
},
base: "./",
});
await vite.build(viteConfig);
},
});
6 changes: 4 additions & 2 deletions apps/wing-console/console/server/src/expressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export const createExpressServer = async ({
const app = express();
app.use(cors());

onExpressCreated?.(app);

const { router } = mergeAllRouters();
const createContext = (): RouterContext => {
return {
Expand Down Expand Up @@ -83,6 +81,10 @@ export const createExpressServer = async ({
createContext,
}),
);

// Allow extending the express app (after trpc is set up).
onExpressCreated?.(app);

log.info("Looking for an open port");
const port = await getPort({ port: requestedPort });
const server = app.listen(port);
Expand Down
9 changes: 1 addition & 8 deletions apps/wing-console/console/server/src/utils/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ export interface Compiler {
): void;
}

const deduceSimfile = (wingfile: string): string => {
const dirname = path.dirname(wingfile);
const basename = path.basename(wingfile, ".w");
return path.resolve(dirname, "target", `${basename}.wsim`);
};

export const createCompiler = (wingfile: string): Compiler => {
const simfile = deduceSimfile(wingfile);
const events = new Emittery<CompilerEvents>();
let isCompiling = false;
let shouldCompileAgain = false;
Expand All @@ -41,7 +34,7 @@ export const createCompiler = (wingfile: string): Compiler => {
try {
isCompiling = true;
await events.emit("compiling");
const outdir = await wing.compile(wingfile, {
const simfile = await wing.compile(wingfile, {
target: wing.Target.SIM,
});
await events.emit("compiled", { simfile });
Expand Down
Loading

0 comments on commit be3694d

Please sign in to comment.