Skip to content
Open
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
4 changes: 2 additions & 2 deletions cors/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
// Values
pub fn append_cors_headers(@mocket.MocketEvent, origin? : String, methods? : String, allow_headers? : String, expose_headers? : String, credentials? : Bool) -> Unit

pub fn append_cors_preflight_headers(@mocket.MocketEvent, origin? : String, methods? : String, allow_headers? : String, credentials? : Bool, max_age? : Int) -> Unit
pub fn append_cors_preflight_headers(@mocket.MocketEvent, origin? : String, methods? : String, allow_headers? : String, credentials? : Bool, max_age? : Int32) -> Unit

pub fn handle_cors(origin? : String, methods? : String, allow_headers? : String, expose_headers? : String, credentials? : Bool, max_age? : Int) -> async (@mocket.MocketEvent, async () -> &@mocket.Responder) -> &@mocket.Responder
pub fn handle_cors(origin? : String, methods? : String, allow_headers? : String, expose_headers? : String, credentials? : Bool, max_age? : Int32) -> async (@mocket.MocketEvent, async () -> &@mocket.Responder) -> &@mocket.Responder

pub fn is_preflight_request(@mocket.MocketEvent) -> Bool

Expand Down
3 changes: 2 additions & 1 deletion error_wbtest.mbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
///|
#derive(Debug)
suberror TestRequestError {
TestRequestError(String)
} derive(Debug)
}

///|
pub extend TestRequestError with Debug::{to_repr}
Expand Down
2 changes: 1 addition & 1 deletion examples/static_assets/moon.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import {

warnings = "-67"

supported_targets = "+native+wasm+js"
supported_targets = "+native+js"

pkgtype(kind: "executable")
16 changes: 9 additions & 7 deletions multipart/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import {
"moonbitlang/async/http",
"moonbitlang/async/io",
"moonbitlang/core/debug",
"moonbitlang/core/json",
}

// Values
pub fn parse_header_value(String) -> (String, Map[@http.CaseInsensitiveString, String]) raise MultipartError

// Errors
#derive(@debug.Debug)
pub suberror MultipartError {
MultipartError(String)
} derive(@debug.Debug)
}
pub fn MultipartError::to_repr(Self) -> @debug.Repr

// Types and methods
Expand All @@ -22,17 +24,17 @@ pub fn Form::Form(&@io.Reader, boundary~ : String) -> Self raise MultipartError
pub async fn Form::next_part(Self) -> FormPart?

type FormPart
pub async fn FormPart::_direct_read(Self, FixedArray[Byte], offset~ : Int, max_len~ : Int) -> Int
pub async fn FormPart::_direct_read(Self, FixedArray[Byte], offset~ : Int32, max_len~ : Int32) -> Int32
pub fn FormPart::_get_internal_buffer(Self) -> @io.ReaderBuffer
pub fn FormPart::content_type(Self) -> String
pub async fn FormPart::drop(Self, Int) -> Int
pub async fn FormPart::drop(Self, Int32) -> Int32
pub fn FormPart::filename(Self) -> String?
pub fn FormPart::headers(Self) -> Map[@http.CaseInsensitiveString, String]
pub fn FormPart::name(Self) -> String
pub async fn FormPart::read(Self, FixedArray[Byte], offset? : Int, max_len? : Int) -> Int
pub async fn FormPart::read(Self, FixedArray[Byte], offset? : Int32, max_len? : Int32) -> Int32
pub async fn FormPart::read_all(Self) -> &@io.Data
pub async fn FormPart::read_exactly(Self, Int) -> Bytes
pub async fn FormPart::read_some(Self, max_len? : Int) -> Bytes?
pub async fn FormPart::read_exactly(Self, Int32) -> Bytes
pub async fn FormPart::read_some(Self, max_len? : Int32) -> Bytes?
pub async fn FormPart::read_until(Self, StringView) -> String?
pub impl @io.Reader for FormPart

Expand All @@ -43,7 +45,7 @@ pub fn FormWriter::content_type(Self) -> String
pub async fn FormWriter::finish(Self) -> Unit
pub async fn FormWriter::write_field(Self, String, String) -> Unit
pub async fn FormWriter::write_file(Self, String, filename? : String, content_type? : String, &@io.Reader) -> Unit
pub async fn FormWriter::write_json(Self, String, Json) -> Unit
pub async fn FormWriter::write_json(Self, String, @json.Json) -> Unit
pub async fn FormWriter::write_part(Self, headers~ : Map[@http.CaseInsensitiveString, String], async (&@io.Writer) -> Unit) -> Unit

type Reader
Expand Down
3 changes: 2 additions & 1 deletion multipart/reader.mbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
///|
#derive(Debug)
pub suberror MultipartError {
MultipartError(String)
} derive(Debug)
}

///|
pub extend MultipartError with Debug::{to_repr}
Expand Down
2 changes: 1 addition & 1 deletion native/mongoose/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn __ws_emit(Bytes, Bytes, Bytes) -> Unit
pub fn listen(@mocket.App, String) -> Unit

#deprecated
pub fn serve(@mocket.App, port~ : Int) -> Unit
pub fn serve(@mocket.App, port~ : Int32) -> Unit

// Errors

Expand Down
4 changes: 2 additions & 2 deletions path_match.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn match_path_segments(
let path_part = path_parts[path_idx]

// 使用正则匹配参数模式
if template_part.view() =~ (re"^:", after=param_name) {
if template_part.clamped_view() =~ (re"^:", after=param_name) {
// 命名参数::param_name
params.set(param_name.to_owned(), path_part)
match_path_segments(
Expand Down Expand Up @@ -260,7 +260,7 @@ fn DynamicRouteTrieNode::insert(
child
}
}
} else if part.view() =~ (re"^:", after=param_name) {
} else if part.clamped_view() =~ (re"^:", after=param_name) {
let param_name = param_name.to_owned()
node = match node.param_child(param_name) {
Some(child) => child
Expand Down
35 changes: 18 additions & 17 deletions pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn html(&Show) -> &Responder
pub async fn listen_ffi(App, String) -> Unit noraise

#deprecated
pub fn new(base_path? : String, max_body_size? : Int) -> App
pub fn new(base_path? : String, max_body_size? : Int32) -> App

pub fn parse_form_data(BytesView) -> Map[String, String]

Expand All @@ -38,11 +38,11 @@ pub fn parse_request_cookie(StringView) -> Map[String, @http.Cookie]

pub fn register_ws_connection(String, (String) -> Unit, (Bytes) -> Unit, () -> Unit) -> Unit

pub fn register_ws_handler(App, Int) -> Unit
pub fn register_ws_handler(App, Int32) -> Unit

pub fn serialize_cookie(@http.Cookie) -> String

pub async fn serve_ffi(App, port~ : Int) -> Unit noraise
pub async fn serve_ffi(App, port~ : Int32) -> Unit noraise

pub async fn[T, E : Error] suspend(((T) -> Unit, (E) -> Unit) -> Unit) -> T raise E

Expand Down Expand Up @@ -93,13 +93,13 @@ pub(all) struct App {
ws_dynamic_routes : Array[(String, (WebSocketEvent) -> Unit)]
ws_clients : Map[String, Unit]
ws_channels : Map[String, Map[String, Unit]]
ws_client_port : Map[String, Int]
max_body_size : Int
ws_client_port : Map[String, Int32]
max_body_size : Int32
mut error_handler : (MocketEvent, Error) -> &Responder
// private fields
}
#alias(new, deprecated)
pub fn App::App(base_path? : String, max_body_size? : Int) -> Self
pub fn App::App(base_path? : String, max_body_size? : Int32) -> Self
pub fn App::acl(Self, String, async (MocketEvent) -> &Responder) -> Unit
pub fn App::all(Self, String, async (MocketEvent) -> &Responder) -> Unit
pub fn App::bind(Self, String, async (MocketEvent) -> &Responder) -> Unit
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn App::rebind(Self, String, async (MocketEvent) -> &Responder) -> Unit
pub fn App::report(Self, String, async (MocketEvent) -> &Responder) -> Unit
pub fn App::search(Self, String, async (MocketEvent) -> &Responder) -> Unit
#deprecated
pub async fn App::serve(Self, port~ : Int) -> Unit noraise
pub async fn App::serve(Self, port~ : Int32) -> Unit noraise
pub fn App::static_assets(Self, String, &ServeStaticProvider) -> Unit
pub fn App::trace(Self, String, async (MocketEvent) -> &Responder) -> Unit
pub fn App::unbind(Self, String, async (MocketEvent) -> &Responder) -> Unit
Expand Down Expand Up @@ -190,7 +190,7 @@ pub(all) struct HttpResponse {
pub fn HttpResponse::HttpResponse(StatusCode, headers? : Map[@http.CaseInsensitiveString, StringView], cookies? : Array[@http.Cookie], body? : &Responder) -> Self
pub fn HttpResponse::body(Self, &Responder) -> Self
pub fn HttpResponse::delete_cookie(Self, String) -> Unit
pub fn HttpResponse::json(Self, &ToJson) -> Self
pub fn HttpResponse::json(Self, &@json.ToJson) -> Self
pub fn HttpResponse::options(Self, Self) -> Unit
pub async fn HttpResponse::output(Self, &@io.Writer) -> Unit
pub async fn[T : BodyReader] HttpResponse::read_body(Self) -> T
Expand All @@ -217,7 +217,7 @@ pub(all) struct ResponseBuffer {
pub fn ResponseBuffer::bytes(Self) -> Bytes
pub fn ResponseBuffer::new() -> Self
pub async fn ResponseBuffer::write(Self, &@io.Data) -> Unit
pub async fn ResponseBuffer::write_once(Self, Bytes, offset~ : Int, len~ : Int) -> Int
pub async fn ResponseBuffer::write_once(Self, Bytes, offset~ : Int32, len~ : Int32) -> Int32
pub async fn ResponseBuffer::write_reader(Self, &@io.Reader) -> Unit
pub impl @io.Writer for ResponseBuffer

Expand All @@ -231,6 +231,7 @@ pub(all) struct StaticAssetMeta {
}
pub fn StaticAssetMeta::new(asset_type? : String, etag? : String, mtime? : Int64, path? : String, size? : Int64, encoding? : String) -> Self

#derive(Eq, @json.ToJson)
pub(all) enum StatusCode {
Continue
SwitchingProtocols
Expand Down Expand Up @@ -294,13 +295,13 @@ pub(all) enum StatusCode {
LoopDetected
NotExtended
NetworkAuthenticationRequired
Custom(Int)
} derive(Eq, ToJson)
Custom(Int32)
}
pub fn StatusCode::equal(Self, Self) -> Bool
pub fn StatusCode::from_int(Int) -> Self
pub fn StatusCode::from_int(Int32) -> Self
pub fn StatusCode::not_equal(Self, Self) -> Bool
pub fn StatusCode::to_int(Self) -> Int
pub fn StatusCode::to_json(Self) -> Json
pub fn StatusCode::to_int(Self) -> Int32
pub fn StatusCode::to_json(Self) -> @json.Json

pub(all) enum WebSocketAggregatedMessage {
Text(String)
Expand Down Expand Up @@ -345,16 +346,16 @@ pub impl BodyReader for String
pub impl BodyReader for FixedArray[Byte]
pub impl BodyReader for Bytes
pub impl BodyReader for Array[Byte]
pub impl BodyReader for Json
pub impl BodyReader for @json.Json

pub(open) trait Responder {
fn options(Self, HttpResponse) -> Unit
async fn output(Self, &@io.Writer) -> Unit
}
pub impl Responder for String
pub impl Responder for Bytes
pub impl Responder for Json
pub impl Responder for &ToJson
pub impl Responder for @json.Json
pub impl Responder for &@json.ToJson
pub impl Responder for StringView

pub(open) trait ServeStaticProvider {
Expand Down
6 changes: 3 additions & 3 deletions static.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn join_asset_id(id : String, suffix : String) -> String {
if suffix == "" {
return id
}
let suffix = if suffix.has_prefix("/") { suffix[1:] } else { suffix.view() }
let suffix = if suffix.has_prefix("/") { suffix[1:] } else { suffix.clamped_view() }
if id.has_suffix("/") {
"\{id}\{suffix}"
} else {
Expand Down Expand Up @@ -141,12 +141,12 @@ pub fn App::static_assets(
}

// Safe to slice now: `url` equals the mount or starts with "mount/".
let raw_id = if mount == "/" { url.view() } else { url[mount.length():] }
let raw_id = if mount == "/" { url.clamped_view() } else { url[mount.length():] }
// Resolve under a virtual root so ".." segments can never escape it;
// the normalized id is an absolute path confined to the mount root.
let resolved_id = Show::to_string(
@posix.Path::normalize(
(if raw_id == "" { "/".view() } else { raw_id }).to_owned(),
(if raw_id == "" { "/".clamped_view() } else { raw_id }).to_owned(),
),
)
// Parse Accept-Encoding
Expand Down
2 changes: 1 addition & 1 deletion static_file/moon.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

warnings = "-20-29"

supported_targets = "+native+wasm+js"
supported_targets = "+native+js"

options(
targets: {
Expand Down
10 changes: 6 additions & 4 deletions static_file/static_file.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ///|



///|
/// Serves static assets from a directory on the local filesystem.
///
Expand Down Expand Up @@ -63,7 +65,7 @@ test "file_extension" {
}

///|
pub impl ServeStaticProvider for StaticFileProvider with fn get_type(
pub impl @mocket.ServeStaticProvider for StaticFileProvider with fn get_type(
_,
ext : String,
) -> String? {
Expand Down Expand Up @@ -110,22 +112,22 @@ test "mime_type_of" {
}

///|
pub impl ServeStaticProvider for StaticFileProvider with fn get_encodings(_) -> Map[
pub impl @mocket.ServeStaticProvider for StaticFileProvider with fn get_encodings(_) -> Map[
String,
String,
] {
{}
}

///|
pub impl ServeStaticProvider for StaticFileProvider with fn get_index_names(
pub impl @mocket.ServeStaticProvider for StaticFileProvider with fn get_index_names(
self,
) -> Array[String] {
self.index_names
}

///|
pub impl ServeStaticProvider for StaticFileProvider with fn get_fallthrough(
pub impl @mocket.ServeStaticProvider for StaticFileProvider with fn get_fallthrough(
self,
) -> Bool {
self.fallthrough
Expand Down
3 changes: 2 additions & 1 deletion status_code.mbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
///|
/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
#derive(ToJson, Eq)
pub(all) enum StatusCode {
/// RFC 9110, 15.2.1
Continue
Expand Down Expand Up @@ -127,7 +128,7 @@ pub(all) enum StatusCode {
/// RFC 6585, 6
NetworkAuthenticationRequired
Custom(Int32)
} derive(ToJson, Eq)
}

///|
pub extend StatusCode with ToJson::{to_json}
Expand Down
11 changes: 7 additions & 4 deletions uri/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,33 @@ pub suberror ParseError {
}

// Types and methods
#derive(Eq, @debug.Debug)
pub struct Authority {
mut userinfo : BytesView?
mut host : Host
mut port : Int?
} derive(Eq, @debug.Debug)
mut port : Int32?
}
pub fn Authority::equal(Self, Self) -> Bool
pub fn Authority::not_equal(Self, Self) -> Bool
pub fn Authority::to_repr(Self) -> @debug.Repr

#derive(Eq, @debug.Debug)
pub enum Host {
IPv6Address(BytesView)
RegName(BytesView)
} derive(Eq, @debug.Debug)
}
pub fn Host::equal(Self, Self) -> Bool
pub fn Host::not_equal(Self, Self) -> Bool
pub fn Host::to_repr(Self) -> @debug.Repr

#derive(Eq, @debug.Debug)
pub struct Uri {
mut scheme : BytesView?
mut authority : Authority?
path : Array[BytesView]
mut query : BytesView?
mut fragment : BytesView?
} derive(Eq, @debug.Debug)
}
pub fn Uri::equal(Self, Self) -> Bool
pub fn Uri::not_equal(Self, Self) -> Bool
pub fn Uri::parse(BytesView) -> Self raise ParseError
Expand Down
Loading