Skip to content

Commit

Permalink
wit deps by namespace
Browse files Browse the repository at this point in the history
tidy
  • Loading branch information
StuartHarris committed Aug 13, 2024
1 parent 18d9d35 commit 2da9b19
Show file tree
Hide file tree
Showing 56 changed files with 77 additions and 139 deletions.
File renamed without changes.
29 changes: 29 additions & 0 deletions wasm-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Wasm Components

The Wasm Components and their various configurations for deployment.

They are currently written in Rust, but could be written in any language that compiles to Wasm.

## Components

### [Data init](rust/data-init)
- sets up the various data stores

### [HTTP controller](rust/http-controller)
- routes HTTP requests to the appropriate service

### [Products Service](rust/products-service)
- manages the products in **key-value store**

### [Inventory Service](rust/inventory-service)
- manages the inventory of products in **postgres**

### [Orders Service](rust/orders-service)
- manages the orders in **postgres**
- calls `inventory-service`
- does not call `products-service`, although it probs should
- publishes `OrderNotification` events to **NATS**

### [Notification Service](rust/notification-service)
- subscribes to `OrderNotification` events from **NATS**
- prints received messages to `stdout`
1 change: 1 addition & 0 deletions wasm-components/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
18 changes: 9 additions & 9 deletions wasm-components/rust/data-init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ wit_bindgen::generate!({
world: "platform-poc:di/di",
path: [
"../../wit/data-init",
"../../wit/deps/postgres",
"../../wit/deps/keyvalue",
"../../wit/deps/logging",
"../../wit/deps/wasmcloud/postgres",
"../../wit/deps/wasi/keyvalue",
"../../wit/deps/wasi/logging",
"wit",
],
generate_all,
Expand All @@ -20,13 +20,13 @@ use wasi::{
};
use wasmcloud::postgres::query::{query, PgValue};

struct HttpServer;
struct Component;

impl Guest for HttpServer {
impl Guest for Component {
fn init_all() -> Result<(), String> {
HttpServer::init_products().expect("DATA-INIT-ALL: failed to initialize products");
HttpServer::init_inventory().expect("DATA-INIT-ALL: failed to initialize inventory");
HttpServer::init_orders().expect("DATA-INIT-ALL: failed to initialize orders");
Component::init_products().expect("DATA-INIT-ALL: failed to initialize products");
Component::init_inventory().expect("DATA-INIT-ALL: failed to initialize inventory");
Component::init_orders().expect("DATA-INIT-ALL: failed to initialize orders");
Ok(())
}

Expand Down Expand Up @@ -242,4 +242,4 @@ fn sample_products() -> Vec<Product> {
]
}

export!(HttpServer);
export!(Component);
22 changes: 11 additions & 11 deletions wasm-components/rust/http-controller/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
wit_bindgen::generate!({
world: "platform-poc:http-controller/http-controller",
path: [
"../../wit/deps/io",
"../../wit/deps/random",
"../../wit/deps/clocks",
"../../wit/deps/filesystem",
"../../wit/deps/sockets",
"../../wit/deps/cli",
"../../wit/deps/http",
"../../wit/deps/logging",
"../../wit/deps/wasi/io",
"../../wit/deps/wasi/random",
"../../wit/deps/wasi/clocks",
"../../wit/deps/wasi/filesystem",
"../../wit/deps/wasi/sockets",
"../../wit/deps/wasi/cli",
"../../wit/deps/wasi/http",
"../../wit/deps/wasi/logging",
"../../wit/inventory",
"../../wit/orders",
"../../wit/data-init",
Expand Down Expand Up @@ -41,7 +41,7 @@ use wasi::{

const MAX_READ_BYTES: u32 = 2048;

struct HttpServer;
struct Component;

impl From<Product> for ProductData {
fn from(product: Product) -> Self {
Expand Down Expand Up @@ -110,7 +110,7 @@ impl From<Order> for OrderData {
}
}

impl Guest for HttpServer {
impl Guest for Component {
fn handle(request: IncomingRequest, response_out: ResponseOutparam) {
let method = request.method();
let path_and_query = request.path_with_query().unwrap();
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Routes {
}
}

export!(HttpServer);
export!(Component);

#[cfg(test)]
mod test {
Expand Down
4 changes: 2 additions & 2 deletions wasm-components/rust/http-controller/wit/world.wit
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package platform-poc:http-controller;

world http-controller {
import wasi:logging/logging;

import platform-poc:products/products@0.1.0;
import platform-poc:data-init/init-funcs@0.1.0;
import platform-poc:inventory/inventory@0.1.0;
import platform-poc:orders/orders@0.1.0;

import wasi:logging/logging;

export wasi:http/incoming-handler@0.2.0;
}
10 changes: 5 additions & 5 deletions wasm-components/rust/inventory-service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
wit_bindgen::generate!({
world: "platform-poc:inventory-service/inventory-service",
path: [
"../../wit/deps/postgres",
"../../wit/deps/logging",
"../../wit/deps/wasmcloud/postgres",
"../../wit/deps/wasi/logging",
"../../wit/inventory",
"wit",
],
Expand All @@ -18,7 +18,7 @@ use wasmcloud::postgres::types::ResultRowEntry;

use wasi::logging::logging::{log, Level};

struct HttpServer;
struct Component;

impl From<AvailabilityData> for Availability {
fn from(val: AvailabilityData) -> Self {
Expand All @@ -29,7 +29,7 @@ impl From<AvailabilityData> for Availability {
}
}

impl Guest for HttpServer {
impl Guest for Component {
fn get_inventory(skus: Vec<String>) -> Result<Vec<Availability>, Error> {
log(Level::Info, "inventory-service", "Getting inventory...");

Expand Down Expand Up @@ -78,4 +78,4 @@ impl Guest for HttpServer {
}
}

export!(HttpServer);
export!(Component);
10 changes: 5 additions & 5 deletions wasm-components/rust/notification-service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
wit_bindgen::generate!({
world: "platform-poc:notification-service/notification-service",
path: [
"../../wit/deps/logging",
"../../wit/deps/messaging",
"../../wit/deps/wasi/logging",
"../../wit/deps/wasmcloud/messaging",
"wit",
],
generate_all,
Expand All @@ -12,9 +12,9 @@ use common::notification::OrderNotification;
use exports::wasmcloud::messaging::handler::{BrokerMessage, Guest};
use wasi::logging::logging::{log, Level};

struct HttpServer;
struct Component;

impl Guest for HttpServer {
impl Guest for Component {
#[doc = r" Callback handled to invoke a function when a message is received from a subscription"]
fn handle_message(msg: BrokerMessage) -> Result<(), String> {
let body = msg.body;
Expand All @@ -26,7 +26,7 @@ impl Guest for HttpServer {
}
}

export!(HttpServer);
export!(Component);

#[macro_export]
macro_rules! loud_print {
Expand Down
12 changes: 6 additions & 6 deletions wasm-components/rust/orders-service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
wit_bindgen::generate!({
world: "platform-poc:orders-service/orders-service",
path: [
"../../wit/deps/logging",
"../../wit/deps/postgres",
"../../wit/deps/messaging",
"../../wit/deps/wasi/logging",
"../../wit/deps/wasmcloud/postgres",
"../../wit/deps/wasmcloud/messaging",
"../../wit/inventory",
"../../wit/orders",
"wit",
Expand All @@ -30,9 +30,9 @@ use wasmcloud::{
},
};

struct HttpServer;
struct Component;

impl Guest for HttpServer {
impl Guest for Component {
#[doc = r" Creates an `order` for specified line items"]
fn create_order(items: Vec<LineItem>) -> Result<(), Error> {
log(Level::Info, "orders-service", "Order request received...");
Expand Down Expand Up @@ -232,4 +232,4 @@ impl Guest for HttpServer {
}
}

export!(HttpServer);
export!(Component);
7 changes: 4 additions & 3 deletions wasm-components/rust/orders-service/wit/world.wit
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package platform-poc:orders-service;

world orders-service {
import wasmcloud:postgres/query@0.1.0-draft;
import wasi:logging/logging;
import platform-poc:inventory/inventory@0.1.0;
import wasmcloud:postgres/query@0.1.0-draft;
import wasmcloud:messaging/consumer@0.2.0;


import platform-poc:inventory/inventory@0.1.0;

export platform-poc:orders/orders@0.1.0;
}
4 changes: 2 additions & 2 deletions wasm-components/rust/products-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ wit_bindgen::generate!({
world: "platform-poc:products-service/products-service",
path: [
"../../wit/products",
"../../wit/deps/logging",
"../../wit/deps/keyvalue",
"../../wit/deps/wasi/keyvalue",
"../../wit/deps/wasi/logging",
"wit",
],
generate_all,
Expand Down
3 changes: 0 additions & 3 deletions wasm-components/rust/scripts/build.fish

This file was deleted.

3 changes: 3 additions & 0 deletions wasm-components/rust/scripts/test.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env fish

cargo insta test --review --test-runner nextest --target aarch64-apple-darwin
93 changes: 0 additions & 93 deletions wasm-components/wit/deps/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2da9b19

Please sign in to comment.