-
Notifications
You must be signed in to change notification settings - Fork 0
WITs
Thang Chung edited this page Apr 5, 2024
·
2 revisions
package coffeeshop:counter;
interface shared {
type id = string;
record order-item-line-dto {
item-line-id: id,
item-type: item-type,
item-status: item-status,
}
record order-dto {
id: id,
order-source: order-source,
loyalty-member-id: id,
order-status: order-status,
location: location,
item-lines: list<order-item-line-dto>
}
record command-item {
item-type: item-type
}
enum item-type {
// Beverages
cappuccino,
coffee-black,
coffee-with-room,
espresso,
espresso-double,
latte,
// Food
cakepop,
croissant,
muffin,
croissant-chocolate
}
enum item-status {
placed,
in-progress,
fulfilled
}
enum order-source {
counter,
web
}
enum order-status {
placed,
in-progress,
fulfilled
}
enum location {
hochiminh,
hanoi,
danang,
}
enum command-type {
place-order
}
}
interface api {
use shared.{id, command-type, order-source, location, command-item, order-dto, order-item-line-dto};
record place-order-command {
id: id,
command-type: command-type,
order-source: order-source,
location: location,
loyalty-member-id: id,
barista-items: option<list<command-item>>,
kitchen-items: option<list<command-item>>,
timestamp: u64
}
get-fulfillment-order: func() -> list<order-dto>;
place-order: func(command: place-order-command) -> bool;
}
interface publisher {
use shared.{id, order-item-line-dto};
// events
record order-placed {
id: id,
item-lines: list<order-item-line-dto>
}
publish-order-placed: func(dapr-uri: string, evt: order-placed) -> bool;
}
world infra {
export publisher;
}
world core {
import publisher;
export api;
}
world host {
import api;
}
cargo component build --release --manifest-path ../counter-infra/Cargo.toml
cargo component build --release --manifest-path ../counter-core/Cargo.toml
cargo component build --release
# because of `error: `counter_core` is not in kebab case (at offset 0x0)`
mv -f ../counter-infra/target/wasm32-wasi/release/counter_infra.wasm ../counter-infra/target/wasm32-wasi/release/counter-infra.wasm
mv -f ../counter-core/target/wasm32-wasi/release/counter_core.wasm ../counter-core/target/wasm32-wasi/release/counter-core.wasm
# compose it
wasm-tools compose ../counter-core/target/wasm32-wasi/release/counter-core.wasm -d ../counter-infra/target/wasm32-wasi/release/counter-infra.wasm -o core-service.wasm
wasm-tools compose target/wasm32-wasi/release/counter_api.wasm -d core-service.wasm -o service.wasm