Skip to content
Closed
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
2 changes: 1 addition & 1 deletion cookie.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn parse_cookie(cookie : StringView) -> Map[String, CookieItem] {
"(?i:max-age)" =>
{
..item,
max_age: try @strconv.parse_int(value) catch {
max_age: try @string.parse_int(value) catch {
_ => None
} noraise {
x => Some(x)
Expand Down
4 changes: 1 addition & 3 deletions examples/responder/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
// Errors

// Types and methods
type Person
pub impl ToJson for Person
pub impl @json.FromJson for Person
type Person derive(ToJson, @json.FromJson)

// Type aliases

Expand Down
2 changes: 1 addition & 1 deletion fetch.js.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn fetch(
if req_body is Some(body_str) {
options["body"] = body_str
}
if not(req_headers.is_empty()) {
if !req_headers.is_empty() {
let headers_obj = @js.Object::new()
req_headers.each(fn(k, v) { headers_obj[k] = v })
options["headers"] = headers_obj.to_value()
Expand Down
11 changes: 7 additions & 4 deletions fetch.wasm.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ pub async fn fetch(
mode? : FetchMode,
) -> HttpResponse raise Error {
ignore(url)
ignore(body)
ignore(http_method)
ignore(data)
ignore(headers)
ignore(credentials)
ignore(mode)
raise FetchError::RequestFailed("fetch is not implemented on wasm target")
ignore(body)
ignore(data)
ignore(headers)
ignore(prepare_fetch_payload)
suspend(fn(_ok_cb, reject) {
reject(FetchError::RequestFailed("fetch is not implemented on wasm target"))
})
}
4 changes: 2 additions & 2 deletions js/async_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn op3() -> String? noraise {

///|
test "Promise::wait" {
@js.async_test(fn() raise {
@js.async_test(async fn() {
// Promise::unsafe_new + Promise::wait is a noop.
let res = @js.Promise::unsafe_new(() => op1()).wait()
assert_eq(res.cast(), Some("Hello"))
Expand All @@ -25,7 +25,7 @@ test "Promise::wait" {

///|
test "async_all" {
@js.async_test(fn() raise {
@js.async_test(async fn() {
assert_eq(@js.async_all([() => op2(), () => op1(), () => op3()]), [
Some("Hello, World"),
Some("Hello"),
Expand Down
2 changes: 1 addition & 1 deletion js/cast.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub impl[A : Cast] Cast for Array[A] with into(value) {
checked_cast_array_ffi(value)
.to_option()
.bind(fn(arr) {
let is_type_a = fn(elem) { not((Cast::into(elem) : A?) is None) }
let is_type_a = fn(elem) { !((Cast::into(elem) : A?) is None) }
if arr.iter().all(is_type_a) {
Some(Value::cast_from(arr).cast())
} else {
Expand Down
2 changes: 1 addition & 1 deletion js/error.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "js" fn Error_::cause_ffi(self : Value) -> Value = "(self) => self.cause"
pub fn Error_::cause(self : Error_) -> Value? {
let Error_(inner) = self
let cause = Error_::cause_ffi(inner)
guard not(cause.is_undefined()) else { None }
guard !cause.is_undefined() else { None }
Some(cause.cast())
}

Expand Down
2 changes: 1 addition & 1 deletion js/null.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn[T] Nullable::unwrap(self : Nullable[T]) -> T {

///|
pub fn[T] Nullable::to_option(self : Nullable[T]) -> T? {
guard not(Value::cast_from(self).is_null()) else { None }
guard !Value::cast_from(self).is_null() else { None }
Some(self.get_exn())
}

Expand Down
10 changes: 6 additions & 4 deletions js/value_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ let json_str_pretty =
#|}

///|
let json_val : @js.Value = (try? @js.Value::from_json_string(json_str_pretty)).unwrap()
fn json_val() -> @js.Value {
try! @js.Value::from_json_string(json_str_pretty)
}

///|
test "Value::to_json_string" {
inspect(
json_val.to_json_string(),
json_val().to_json_string(),
content=(
#|{"_id":"67a6c712bc218526d5e1b516","index":0,"guid":"74e69a18-680a-4a74-a401-e386c30d0a35","isActive":false,"balance":"$3,140.03","picture":"http://placehold.it/32x32","age":33,"eyeColor":"blue","name":"Burt Dominguez","gender":"male","company":"GEEKWAGON","email":"burtdominguez@geekwagon.com","phone":"+1 (913) 583-3488","address":"379 Essex Street, Fresno, Minnesota, 5304","about":"Proident velit ullamco cillum occaecat irure eu proident commodo consectetur est ut elit consectetur.","registered":"2020-12-06T01:54:20 -08:00","latitude":71.680916,"longitude":-88.552886,"tags":["aute","occaecat","qui","esse","commodo","sint","proident"],"friends":[{"id":0,"name":"Gilliam Mcgowan"},{"id":1,"name":"Bryan Stanton"},{"id":2,"name":"Jenifer Elliott"}],"greeting":"Hello, Burt Dominguez! You have 4 unread messages.","favoriteFruit":"apple"}
),
Expand All @@ -74,13 +76,13 @@ test "Value::to_json_string" {

///|
test "Value::to_json" {
assert_eq(json_val.to_json(), json)
assert_eq(json_val().to_json(), json)
}

///|
test "Value::from_json" {
assert_eq(
@js.Value::from_json(json).to_json_string(),
json_val.to_json_string(),
json_val().to_json_string(),
)
}
4 changes: 2 additions & 2 deletions mocket.js.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn serve_ffi(mocket : Mocket, port~ : Int) -> Unit {
let headers_obj = (try? @js.Value::from_json(
event.res.headers.to_json(),
)).or(@js.Object::new().to_value())
if not(event.res.cookies.is_empty()) {
if !event.res.cookies.is_empty() {
let cookies = event.res.cookies
.values()
.map(fn(c) { c.to_string() })
Expand Down Expand Up @@ -358,7 +358,7 @@ extern "js" fn _init_bindings_map() -> @js.Value = "() => { if (!globalThis.ws_p
pub fn register_ws_handler(mocket : Mocket, port : Int) -> Unit {
let mut done = false
mocket.ws_static_routes.each(fn(_, handler) {
if not(done) {
if !done {
ws_handler_map.set(port, handler)
ws_mocket_map.set(port, mocket)
ignore(_init_bindings_map())
Expand Down
2 changes: 1 addition & 1 deletion mocket.native.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ let ws_handler_map : Map[Int, WebSocketHandler] = Map::new()
pub fn register_ws_handler(mocket : Mocket, port : Int) -> Unit {
let mut done = false
mocket.ws_static_routes.each(fn(_, handler) {
if not(done) {
if !done {
ws_handler_map.set(port, handler)
done = true
}
Expand Down
64 changes: 63 additions & 1 deletion mocket.wasm.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
///|
fn wasm_websocket_peer() -> WebSocketPeer {
WebSocketPeer::{ connection_id: "", subscribed_channels: [] }
}

///|
fn keep_websocket_symbols_alive() -> Unit {
ignore(WebSocketEvent::Open(wasm_websocket_peer()))
ignore(
WebSocketEvent::Message(
wasm_websocket_peer(),
WebSocketAggregatedMessage::Text(""),
),
)
ignore(WebSocketEvent::Close(wasm_websocket_peer()))
ignore(WebSocketAggregatedMessage::Binary(b""))
ignore(WebSocketAggregatedMessage::Ping)
}

///|
pub fn serve_ffi(mocket : Mocket, port~ : Int) -> Unit {
// Unimplemented
ignore(mocket.find_route("GET", "/"))
ignore(port)
keep_websocket_symbols_alive()
panic()
}

///|
pub fn ws_send(id : String, msg : String) -> Unit {
ignore(id)
ignore(msg)
panic()
}

///|
pub fn ws_send_bytes(id : String, msg : Bytes) -> Unit {
ignore(id)
ignore(msg)
panic()
}

///|
pub fn ws_pong(id : String) -> Unit {
ignore(id)
panic()
}

///|
pub fn ws_subscribe(id : String, channel : String) -> Unit {
ignore(id)
ignore(channel)
panic()
}

///|
pub fn ws_unsubscribe(id : String, channel : String) -> Unit {
ignore(id)
ignore(channel)
panic()
}

///|
pub fn ws_publish(channel : String, msg : String) -> Unit {
ignore(channel)
ignore(msg)
panic()
}
1 change: 1 addition & 0 deletions moon.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
"moonbitlang/x/codec/base64",
"moonbitlang/core/json",
"moonbitlang/core/strconv",
"moonbitlang/core/string",
"moonbitlang/core/buffer",
"moonbitlang/core/encoding/utf8",
}
Expand Down
2 changes: 1 addition & 1 deletion path_match.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 匹配路径并提取参数 - 重写版本,消除复杂性
fn match_path(template : String, path : String) -> Map[String, StringView]? {
// 静态路径直接比较 - 好品味:消除特殊情况
if not(template.contains(":")) && not(template.contains("*")) {
if !template.contains(":") && !template.contains("*") {
return if template == path { Some({}) } else { None }
}

Expand Down
36 changes: 10 additions & 26 deletions pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,15 @@ pub fn ws_subscribe(String, String) -> Unit
pub fn ws_unsubscribe(String, String) -> Unit

// Errors
pub suberror ExecError
pub impl Show for ExecError
pub suberror ExecError derive(Show)

pub suberror FetchError {
RequestFailed(String)
}
pub impl Show for FetchError
} derive(Show)

pub suberror IOError
pub impl Show for IOError
pub suberror IOError derive(Show)

pub suberror NetworkError
pub impl Show for NetworkError
pub suberror NetworkError derive(Show)

// Types and methods
pub(all) struct CookieItem {
Expand All @@ -80,28 +76,23 @@ pub(all) struct CookieItem {
secure : Bool?
http_only : Bool?
same_site : SameSiteOption?
}
pub impl Eq for CookieItem
} derive(Eq)
pub impl Show for CookieItem

pub(all) enum FetchCredentials {
Omit
SameOrigin
Include
}
} derive(Eq, Show)
pub fn FetchCredentials::to_string(Self) -> String
pub impl Eq for FetchCredentials
pub impl Show for FetchCredentials

pub(all) enum FetchMode {
Cors
NoCors
SameOrigin
Navigate
}
} derive(Eq, Show)
pub fn FetchMode::to_string(Self) -> String
pub impl Eq for FetchMode
pub impl Show for FetchMode

type Html
pub impl Responder for Html
Expand All @@ -116,9 +107,7 @@ pub(all) enum HttpMethod {
OPTIONS
TRACE
CONNECT
}
pub impl Eq for HttpMethod
pub impl Show for HttpMethod
} derive(Eq, Show)

pub(all) struct HttpRequest {
http_method : String
Expand Down Expand Up @@ -202,9 +191,7 @@ pub(all) enum SameSiteOption {
Lax
Strict
SameSiteNone
}
pub impl Eq for SameSiteOption
pub impl Show for SameSiteOption
} derive(Eq, Show)
pub impl ToJson for SameSiteOption

pub(all) struct StaticAssetMeta {
Expand Down Expand Up @@ -281,12 +268,9 @@ pub(all) enum StatusCode {
NotExtended
NetworkAuthenticationRequired
Custom(Int)
}
} derive(Eq, Show, ToJson)
pub fn StatusCode::from_int(Int) -> Self
pub fn StatusCode::to_int(Self) -> Int
pub impl Eq for StatusCode
pub impl Show for StatusCode
pub impl ToJson for StatusCode

pub enum WebSocketAggregatedMessage {
Text(String)
Expand Down
10 changes: 5 additions & 5 deletions static.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn Mocket::static_assets(
provider : &ServeStaticProvider,
) -> Unit {
self.use_middleware(async fn(event, next) noraise {
if not(match_path(path, event.req.url) is None) {
if !(match_path(path, event.req.url) is None) {
return next()
}

Expand Down Expand Up @@ -126,7 +126,7 @@ pub fn Mocket::static_assets(
}
match meta.etag {
Some(etag) => {
if not(event.res.headers.contains("ETag")) {
if !event.res.headers.contains("ETag") {
event.res.headers.set("ETag", etag)
}
if event.req.headers.get("If-None-Match") == Some(etag) {
Expand All @@ -137,7 +137,7 @@ pub fn Mocket::static_assets(
}

// Content-Type
if not(event.res.headers.contains("Content-Type")) {
if !event.res.headers.contains("Content-Type") {
match meta.asset_type {
Some(t) => event.res.headers.set("Content-Type", t)
None => {
Expand All @@ -156,7 +156,7 @@ pub fn Mocket::static_assets(
// Content-Encoding
match meta.encoding {
Some(enc) =>
if not(event.res.headers.contains("Content-Encoding")) {
if !event.res.headers.contains("Content-Encoding") {
event.res.headers.set("Content-Encoding", enc)
}
None => ()
Expand All @@ -165,7 +165,7 @@ pub fn Mocket::static_assets(
// Content-Length
match meta.size {
Some(size) =>
if size > 0L && not(event.res.headers.contains("Content-Length")) {
if size > 0L && !event.res.headers.contains("Content-Length") {
event.res.headers.set("Content-Length", size.to_string())
}
None => ()
Expand Down
Loading
Loading