diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 38bcb346..c1787e90 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -20,6 +20,8 @@ const config = { defaultLocale: 'en', locales: ['en'], }, + // Get the index metadata for `wws` language runtimes + staticDirectories: ["static", "../metadata"], presets: [ [ diff --git a/metadata/repository/v1/files/python/3/poly.py b/metadata/repository/v1/files/python/3/poly.py new file mode 100644 index 00000000..7b90b41c --- /dev/null +++ b/metadata/repository/v1/files/python/3/poly.py @@ -0,0 +1,46 @@ +import sys, json; + +class Cache: + store = {} + + @classmethod + def init(cls, kv): + cls.store = kv + + @classmethod + def dump(cls): + return cls.store + + @classmethod + def get(cls, key): + return cls.store.get(key) + + @classmethod + def set(cls, key, value): + cls.store[key] = str(value) + +class Request: + def __init__(self, input): + self.method = input["method"] + self.url = input["url"] + self.body = input["body"] + self.headers = input["headers"] + self.params = input["params"] + + # Init the cache + Cache.init(input["kv"]) + +class Response: + def __init__(self, body): + self.body = body + self.status_code = 200 + self.headers = {} + + def to_json(self): + res = { + 'data': self.body, + 'status': self.status_code, + 'headers': self.headers, + 'kv': Cache.dump() + } + return json.dumps(res) diff --git a/metadata/repository/v1/files/python/3/wrapper.txt b/metadata/repository/v1/files/python/3/wrapper.txt new file mode 100644 index 00000000..d7fd2126 --- /dev/null +++ b/metadata/repository/v1/files/python/3/wrapper.txt @@ -0,0 +1,6 @@ +from poly import * + +{source} + +res = worker(Request(json.loads(sys.stdin.read()))) +print(res.to_json()) diff --git a/metadata/repository/v1/files/ruby/3/poly.rb b/metadata/repository/v1/files/ruby/3/poly.rb new file mode 100644 index 00000000..dd1879e1 --- /dev/null +++ b/metadata/repository/v1/files/ruby/3/poly.rb @@ -0,0 +1,80 @@ +require 'json'; + +def json_to_request(input) + json = JSON.parse(input); + + Request.new( + json['url'], + json['body'], + json['method'], + json['headers'], + json['params'], + json['kv'] + ) +end + +class Cache + @@kv = {} + + def self.init(kv) + @@kv = kv + end + + def self.dump + @@kv + end + + def self.get(key) + @@kv[key.to_s] + end + + def self.set(key, value) + @@kv[key.to_s] = value.to_s + end +end + +class Request + attr_reader :url, :body, :method, :headers, :params + + def initialize(url, body, method, headers, params, kv) + @url = url + @body = body + @method = method + @headers = headers + @params = params + + # Initializes the cache + Cache.init(kv) + end +end + +class Response + attr_accessor :body, :status_code, :headers + + def initialize(body, status_code = 200, headers = {}) + @body = body + @status_code = status_code + @headers = headers + end + + def self.ok(body) + new(body) + end + + def self.created(body) + new(body, 201) + end + + def self.not_found(body) + new(body, 404) + end + + def to_s + JSON.generate({ + data: body, + status: status_code, + headers: headers, + kv: Cache.dump + }) + end +end diff --git a/metadata/repository/v1/files/ruby/3/wrapper.txt b/metadata/repository/v1/files/ruby/3/wrapper.txt new file mode 100644 index 00000000..15f2fbff --- /dev/null +++ b/metadata/repository/v1/files/ruby/3/wrapper.txt @@ -0,0 +1,5 @@ +require_relative "./poly"; + +{source} + +puts "#{worker(json_to_request($stdin.gets.to_s))}" diff --git a/metadata/repository/v1/index.toml b/metadata/repository/v1/index.toml new file mode 100644 index 00000000..c178605b --- /dev/null +++ b/metadata/repository/v1/index.toml @@ -0,0 +1,23 @@ +version = 1 + +[[runtimes]] +name = "ruby" +version = "3.2.0+20230215" +tags = [ "latest", "3.2", "3.2.0" ] +status = "active" +args = [ "--", "/src/index.rb" ] +binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0.wasm", filename = "ruby.wasm", checksum = { type = "sha256", value = "abe348fba157a756f86194be445c77c99e8ed64ca76495ea07ed984f09eb66ae" } } +extensions = [ "rb" ] +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "044b0d4bde7d3a9b0f275821fb5b67cc2e382267904df2516a23dbec1fae6bae" } } +wrapper = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "6d808b4747cf30f82665a38a47e1176513bbdd6ad558c09db03d719e33ad2da0" } } + +[[runtimes]] +name = "python" +version = "3.11.1+20230217" +tags = [ "latest", "3.11", "3.11.1" ] +status = "active" +args = [ "--", "/src/index.py" ] +binary = { url = "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/python%2F3.11.1%2B20230217-15dfbed/python-3.11.1.wasm", filename = "python.wasm", checksum = { type = "sha256", value = "66589b289f76bd716120f76f234e4dd663064ed5b6256c92d441d84e51d7585d" } } +extensions = [ "py" ] +polyfill = { url = "https://workers.wasmlabs.dev/repository/files/python/3/poly.py", filename = "poly.py", checksum = { type = "sha256", value = "2027b73556ca02155f026cee751ab736985917d2f28bbcad5aac928c719e1112" } } +wrapper = { url = "https://workers.wasmlabs.dev/repository/files/python/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "cf1edc5b1427180ec09d18f4d169580379f1b12001f30e330759f9a0f8745357" } } \ No newline at end of file diff --git a/src/commands/runtimes.rs b/src/commands/runtimes.rs index 73581885..bce67615 100644 --- a/src/commands/runtimes.rs +++ b/src/commands/runtimes.rs @@ -16,9 +16,9 @@ use prettytable::{format, Cell, Row, Table}; use std::env; /// Default repository name -pub const DEFAULT_REPO_NAME: &str = "wlr"; +pub const DEFAULT_REPO_NAME: &str = "wasmlabs"; /// Default repository URL -pub const DEFAULT_REPO_URL: &str = "https://assets.wasmlabs.dev/repository/v1/index.toml"; +pub const DEFAULT_REPO_URL: &str = "https://workers.wasmlabs.dev/repository/v1/index.toml"; /// Environment variable to set the repository name pub const WWS_REPO_NAME: &str = "WWS_REPO_NAME";