Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the initial repository index #88

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const config = {
defaultLocale: 'en',
locales: ['en'],
},
// Get the index metadata for `wws` language runtimes
staticDirectories: ["static", "../metadata"],

presets: [
[
Expand Down
25 changes: 25 additions & 0 deletions metadata/repository/v1/files/python/3/poly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys, json;

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"]

class Response:
def __init__(self, body):
self.body = body
self.status_code = 200
self.headers = {}
self.kv = {}

def to_json(self):
res = {
'data': self.body,
'status': self.status_code,
'headers': self.headers,
'kv': self.kv
}
return json.dumps(res)
6 changes: 6 additions & 0 deletions metadata/repository/v1/files/python/3/wrapper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from poly import *

{source}

res = worker(Request(json.loads(sys.stdin.read())))
print(res.to_json())
56 changes: 56 additions & 0 deletions metadata/repository/v1/files/ruby/3/poly.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'json';

def json_to_request(input)
json = JSON.parse(input);

Request.new(
json['url'],
json['body'],
json['method'],
json['headers'],
json['params']
)
end

class Request
attr_reader :url, :body, :method, :headers, :params

def initialize(url, body, method, headers, params)
@url = url
@body = body
@method = method
@headers = headers
@params = params
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: {}
})
end
end
5 changes: 5 additions & 0 deletions metadata/repository/v1/files/ruby/3/wrapper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "./poly";

{source}

puts "#{worker(json_to_request($stdin.gets.to_s))}"
23 changes: 23 additions & 0 deletions metadata/repository/v1/index.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = 1

[[runtimes]]
name = "ruby"
version = "3.2.0+TBD"
tags = [ "latest", "3.2.0" ]
status = "active"
args = [ "--", "/src/index.rb" ]
binary = { url = "TBD", filename = "ruby.wasm", checksum = { type = "sha256", value = "TBD" } }
extensions = [ "rb" ]
polyfill = { url = "https://workers.wasmlabs.dev/repository/files/ruby/3/poly.rb", filename = "poly.rb", checksum = { type = "sha256", value = "3987988ae3f4cbdbd3a9f3d68350a2f233316c2ad240843240c231b333943521" } }
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+TBD"
tags = [ "latest", "3.11.1" ]
status = "active"
args = [ "--", "/src/index.py" ]
binary = { url = "TBD", filename = "python.wasm", checksum = { type = "sha256", value = "TBD" } }
extensions = [ "py" ]
polyfill = { url = "https://workers.wasmlabs.dev/repository/files/python/3/poly.py", filename = "poly.py", checksum = { type = "sha256", value = "ce179a41a02ef4e71f4f6e0c84d06509393b104b3bc3238b4d30fac8d1b6884d" } }
wrapper = { url = "https://workers.wasmlabs.dev/repository/files/python/3/wrapper.txt", filename = "wrapper.txt", checksum = { type = "sha256", value = "cf1edc5b1427180ec09d18f4d169580379f1b12001f30e330759f9a0f8745357" } }
4 changes: 2 additions & 2 deletions src/commands/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down