Skip to content

Commit b835d54

Browse files
committed
Initial commit
0 parents  commit b835d54

29 files changed

+5217
-0
lines changed

.tool-versions

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ruby 3.0.6
2+
nodejs 16.13.0
3+
python 3.12.3

app.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export function test(context) {
3+
return context.getInput();
4+
}

app.wasm

10 MB
Binary file not shown.

app.wit

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app:fortnox@0.0.1;
2+
3+
interface host {
4+
resource context {
5+
get-storage: func(key: string) -> string;
6+
set-storage: func(key: string, value: string);
7+
get-input: func() -> result<string, string>;
8+
get-connection: func() -> result<string, string>;
9+
}
10+
}
11+
12+
world main {
13+
use host.{context};
14+
15+
import host;
16+
17+
export test: func(context: context) -> string;
18+
}

interface/host.mjs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export class Context {
2+
#storage
3+
4+
constructor() {
5+
this.#storage = {}
6+
}
7+
8+
getStorage(key) {
9+
return this.#storage[key]
10+
}
11+
12+
setStorage(key, value) {
13+
this.#storage[key] = value
14+
}
15+
16+
getInput() {
17+
return JSON.stringify({
18+
"DocumentNumber": "1234567890",
19+
"CostCenter": "ABC",
20+
})
21+
}
22+
23+
getConnection() {
24+
return JSON.stringify({
25+
"url": "https://api.com",
26+
"headers": {
27+
"Content-Type": "application/json",
28+
"Authorization": "Bearer token-1231213131",
29+
}
30+
})
31+
}
32+
}
33+
34+
export const host = {
35+
Context
36+
}

justfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Build & Run
2+
default: build run
3+
4+
# Build WASM
5+
componentize:
6+
jco componentize app.js --wit app.wit --world-name main --out app.wasm
7+
8+
# Transpile to JS
9+
transpile-js:
10+
jco transpile app.wasm -o output --map 'app:fortnox/*=../interface/host.mjs#*'
11+
# Copy js to mjs to support modular imports
12+
cp output/app.js output/app.mjs
13+
14+
# Componentize & Transpile to JS
15+
build: componentize transpile-js
16+
17+
# Run runner.mjs
18+
run:
19+
node runner.mjs

output/app.core.wasm

9.97 MB
Binary file not shown.

output/app.core2.wasm

17.9 KB
Binary file not shown.

output/app.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Context } from './interfaces/app-fortnox-host.js';
2+
export { Context };
3+
import { AppFortnoxHost } from './interfaces/app-fortnox-host.js';
4+
import { WasiCliStderr } from './interfaces/wasi-cli-stderr.js';
5+
import { WasiCliStdin } from './interfaces/wasi-cli-stdin.js';
6+
import { WasiCliStdout } from './interfaces/wasi-cli-stdout.js';
7+
import { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input.js';
8+
import { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output.js';
9+
import { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr.js';
10+
import { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin.js';
11+
import { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout.js';
12+
import { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock.js';
13+
import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.js';
14+
import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens.js';
15+
import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types.js';
16+
import { WasiIoError } from './interfaces/wasi-io-error.js';
17+
import { WasiIoPoll } from './interfaces/wasi-io-poll.js';
18+
import { WasiIoStreams } from './interfaces/wasi-io-streams.js';
19+
import { WasiRandomRandom } from './interfaces/wasi-random-random.js';
20+
export function test(context: Context): string;

0 commit comments

Comments
 (0)