Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/usuba.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Local Usuba Setup

Install some environment dependencies:

```sh
cargo install wit-deps-cli wasm-tools
rustup target add wasm32-wasi wasm32-unknown-unknown

npm install -g @bytecodealliance/jco
npm install -g @bytecodealliance/componentize-js

pip install componentize-py
```

On a Mac, also do this also:

```sh
brew install wget gsed
```

Set up an NPM project (using whatever stack) in `/typescript/packages` and add `@commontools/runtime` to your dependencies:

```sh
mkdir -p ./typescript/packages/my-project
cd ./typescript/packages/my-project

# Actually, better to copy a package.json from another package
echo '{"type": "module"}' > ./package.json
npm install --save @commontools/runtime
```

Get a web server going and note the `PORT` it is running on.

In another terminal, get `usuba` running:

```sh
cd ./rust/usuba
UPSTREAM=localhost:$PORT cargo run --bin usuba
```

Open your browser to http://localhost:8080. You should see whatever you would expect to see from the first web server you started.
8 changes: 8 additions & 0 deletions rust/usuba/src/bake/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ impl Bake for JavaScriptBaker {

debug!(?workspace, "Populated temporary input files");

Command::new("cp")
.arg("-r")
.arg(format!("{}", workspace.path().display()))
.arg("/tmp/failed")
.spawn()?
.wait()
.await?;

let mut command = Command::new("jco");

command
Expand Down
1 change: 1 addition & 0 deletions typescript/common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deps
1 change: 1 addition & 0 deletions typescript/common/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
119 changes: 119 additions & 0 deletions typescript/common/data/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"name": "@commontools/data",
"author": "The Common Authors",
"version": "0.0.1",
"description": "",
"license": "UNLICENSED",
"private": true,
"type": "module",
"files": [
"./lib/**/*"
],
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./interfaces/common-data-types.js": {
"types": "./lib/interfaces/common-data-types.js"
}
},
"scripts": {
"build": "wireit",
"clean": "wireit",
"update:wit": "wireit",
"lint:wit": "wireit",
"build:wit": "wireit"
},
"repository": {
"type": "git",
"url": "git+https://github.com/commontoolsinc/labs.git"
},
"bugs": {
"url": "https://github.com/commontoolsinc/labs/issues"
},
"homepage": "https://github.com/commontoolsinc/labs#readme",
"dependencies": {},
"devDependencies": {
"@bytecodealliance/jco": "^1.2.4",
"typescript": "^5.2.2",
"wireit": "^0.14.4"
},
"wireit": {
"install:wit": {
"command": "wit-deps",
"files": [
"./wit/deps.*"
],
"output": [
"./wit/deps/**/*"
]
},
"lint:wit": {
"dependencies": [
"install:wit"
],
"command": "wasm-tools component wit ./wit",
"files": [
"./wit/**/*"
]
},
"update:wit": {
"command": "wit-deps update",
"files": [
"./wit/deps.toml"
],
"output": [
"./wit/deps.lock",
"./wit/deps/**/*"
]
},
"build:jco": {
"dependencies": [
"install:wit",
"lint:wit"
],
"command": "jco types -o ./lib --name index ./wit",
"files": [
"./wit/**/*"
],
"output": [
"./lib/**/*"
]
},
"build:wit:index": {
"dependencies": [
"build:jco"
],
"command": "cat ./wit/*.wit | ./scripts/generate-wit-module.sh > ./lib/index.js",
"files": [
"./scripts/generate-wit-module.sh",
"./wit/*.wit"
]
},
"build:wit:types": {
"dependencies": [
"build:jco"
],
"command": "echo 'export const wit: string;' >> ./lib/index.d.ts",
"files": [
"./lib/index.d.ts"
]
},
"build:wit": {
"dependencies": [
"build:wit:index",
"build:wit:types"
]
},
"build": {
"dependencies": [
"build:jco",
"build:wit"
]
},
"clean": {
"command": "rm -rf ./src ./lib ./.wireit"
}
}
}
1 change: 1 addition & 0 deletions typescript/common/data/scripts
11 changes: 11 additions & 0 deletions typescript/common/data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["es2022", "DOM", "DOM.Iterable"],
"outDir": "./lib",
"rootDir": "./src",
},
"include": [
"src/**/*",
]
}
33 changes: 33 additions & 0 deletions typescript/common/data/wit/data.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package common:data@0.0.1;

interface types {
resource reference {
// Dereference a reference to a value
// This call is fallible (for example, if the dereference is not allowed)
// The value may be none (for example, if it is strictly opaque)
deref: func() -> result<option<value>, %string>;
}

resource dictionary {
get: func(key: %string) -> option<reference>;
}

type array = list<reference>;
type %string = string;
type boolean = bool;
type number = f64;
type buffer = list<u8>;

variant value {
%string(%string),
number(number),
boolean(boolean),
buffer(buffer),
array(array),
dictionary(dictionary)
}
}

world common {
export types;
}
Empty file.
Empty file.
112 changes: 112 additions & 0 deletions typescript/common/io/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"name": "@commontools/io",
"author": "The Common Authors",
"version": "0.0.1",
"description": "",
"license": "UNLICENSED",
"private": true,
"type": "module",
"types": "./lib/module.d.ts",
"files": [
"./lib/**/*"
],
"exports": "./lib/index.js",
"scripts": {
"build": "wireit",
"clean": "wireit",
"update:wit": "wireit",
"lint:wit": "wireit",
"build:wit:inline": "wireit"
},
"repository": {
"type": "git",
"url": "git+https://github.com/commontoolsinc/labs.git"
},
"bugs": {
"url": "https://github.com/commontoolsinc/labs/issues"
},
"homepage": "https://github.com/commontoolsinc/labs#readme",
"dependencies": {},
"devDependencies": {
"@bytecodealliance/jco": "^1.2.4",
"typescript": "^5.2.2",
"wireit": "^0.14.4"
},
"wireit": {
"install:wit": {
"command": "wit-deps",
"files": [
"./wit/deps.*"
],
"output": [
"./wit/deps/**/*"
]
},
"lint:wit": {
"dependencies": [
"install:wit"
],
"command": "wasm-tools component wit ./wit",
"files": [
"./wit/**/*"
]
},
"update:wit": {
"command": "wit-deps update",
"files": [
"./wit/deps.toml"
],
"output": [
"./wit/deps.lock",
"./wit/deps/**/*"
]
},
"build:jco": {
"dependencies": [
"install:wit",
"lint:wit"
],
"command": "jco types -o ./lib --name index ./wit",
"files": [
"./wit/**/*"
],
"output": [
"./lib/**/*"
]
},
"build:wit:index": {
"dependencies": [
"build:jco"
],
"command": "cat ./wit/*.wit | ./scripts/generate-wit-module.sh > ./lib/index.js",
"files": [
"./scripts/generate-wit-module.sh",
"./wit/*.wit"
]
},
"build:wit:types": {
"dependencies": [
"build:jco"
],
"command": "echo 'export const wit: string;' >> ./lib/index.d.ts",
"files": [
"./lib/index.d.ts"
]
},
"build:wit": {
"dependencies": [
"build:wit:index",
"build:wit:types"
]
},
"build": {
"dependencies": [
"build:jco",
"build:wit"
]
},
"clean": {
"command": "rm -rf ./src ./lib ./.wireit"
}
}
}
1 change: 1 addition & 0 deletions typescript/common/io/scripts
6 changes: 6 additions & 0 deletions typescript/common/io/wit.patch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'common:io/state@0.0.1' {
export function read(name: String): Reference | undefined;
export function write(name: String, value: Value): void;
export { Stream };
export function subscribe(name: String): Stream | undefined;
}
4 changes: 4 additions & 0 deletions typescript/common/io/wit/deps.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[data]
path = "../../data/wit"
sha256 = "e092c9d7a74aaab5a9a99dcf43ae00f3bcf70d78cb5841124dae526698888815"
sha512 = "e55af0160d09492d61567710cf0fa0c0ae032931cc9f0cc4b44a7e1f4706ca879034790d6c9f393be31711530a4751222767708c16701cf076d2053eec27d212"
1 change: 1 addition & 0 deletions typescript/common/io/wit/deps.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data = "../../data/wit"
12 changes: 12 additions & 0 deletions typescript/common/io/wit/io.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package common:io@0.0.1;

interface state {
use common:data/types@0.0.1.{reference,value,%string};

read: func(name: %string) -> option<reference>;
write: func(name: %string, value: value);
}

world common {
export state;
}
Loading