-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ekeren/inflight-should-capture-mutable
- Loading branch information
Showing
12 changed files
with
506 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.