unmbt/ciallo/core does not have a README file

    ContextHook

    type ContextHook = async (Context) -> Unit

    EarlyHook

    type EarlyHook = async (Context) ->
    Response
    ?

    ErrorMapper

    type ErrorMapper = async (Context, Error) ->
    Response
    ?

    Handler

    TraceListener

    type TraceListener = (TraceSummary) -> Unit

    CapabilityBundle

    pub(open) trait CapabilityBundle {
    fn meta(Self) -> PluginMeta
    fn install(Self, app : App) -> Unit raise AppBuildError
    }

    FromParam

    pub(open) trait FromParam {
    fn from_param(name : String, raw : StringView) -> Self raise
    ValidationError

    }

    impl FromParam for Bool
    impl FromParam for Int
    impl FromParam for Int64
    impl FromParam for UInt
    impl FromParam for UInt64
    impl FromParam for String

    AppBuildError

    pub(all) suberror AppBuildError {
    DuplicateRoute(meth~ :
    Method
    , path~ : String, loc~ : SourceLoc?)
    AmbiguousParam(path~ : String, existing~ : String, incoming~ : String, loc~ : SourceLoc?)
    InvalidPattern(pattern~ : String, reason~ : String, loc~ : SourceLoc?)
    DuplicateProvider(key_name~ : String, loc~ : SourceLoc?)
    DuplicateOperationId(operation_id~ : String, routes~ : (String, String))
    AlreadyFrozen(loc~ : SourceLoc?)
    } derive(
    Debug
    )

    统一应用组装期受检异常(覆盖路由冲突、重复依赖注册、重复 operation_id 与运行期冻结后篡改)
    impl Eq for AppBuildError

    HttpError

    pub(all) suberror HttpError {
    BadRequest(String, loc~ : SourceLoc?)
    Unauthorized(String, loc~ : SourceLoc?)
    Forbidden(String, loc~ : SourceLoc?)
    NotFound(String, loc~ : SourceLoc?)
    MethodNotAllowed(Array[
    Method
    ], loc~ : SourceLoc?)
    PayloadTooLarge(Int64, loc~ : SourceLoc?)
    UnsupportedMediaType(String, loc~ : SourceLoc?)
    UnprocessableEntity(Array[
    ValidationIssue
    ], loc~ : SourceLoc?)
    TooManyRequests(String, loc~ : SourceLoc?)
    InternalError(String, loc~ : SourceLoc?)
    Custom(status~ : Int, code~ : String, message~ : String, extensions~ : Map[String,
    Json
    ]?, loc~ : SourceLoc?)
    }

    HttpError::bad_request

    #callsite(autofill(loc))
    fn HttpError::bad_request(detail : String, loc~ : SourceLoc) -> HttpError

    HttpError::custom

    #callsite(autofill(loc))
    fn HttpError::custom(status~ : Int, code~ : String, message~ : String, extensions? : Map[String,
    Json
    ], loc~ : SourceLoc) -> HttpError

    HttpError::forbidden

    #callsite(autofill(loc))
    fn HttpError::forbidden(detail : String, loc~ : SourceLoc) -> HttpError

    HttpError::internal

    #callsite(autofill(loc))
    fn HttpError::internal(detail : String, loc~ : SourceLoc) -> HttpError

    HttpError::method_not_allowed

    #callsite(autofill(loc))
    fn HttpError::method_not_allowed(allowed : Array[
    Method
    ], loc~ : SourceLoc) -> HttpError

    HttpError::not_found

    #callsite(autofill(loc))
    fn HttpError::not_found(detail : String, loc~ : SourceLoc) -> HttpError

    HttpError::payload_too_large

    #callsite(autofill(loc))
    fn HttpError::payload_too_large(max_bytes : Int64, loc~ : SourceLoc) -> HttpError

    HttpError::to_problem

    fn HttpError::to_problem(self : HttpError, trace_id? : String, instance? : String, debug? : Bool) -> ProblemDetails

    HttpError::to_response

    fn HttpError::to_response(self : HttpError, trace_id? : String, instance? : String, debug? : Bool) ->
    Response

    HttpError::too_many_requests

    #callsite(autofill(loc))
    fn HttpError::too_many_requests(detail : String, loc~ : SourceLoc) -> HttpError

    HttpError::unauthorized

    #callsite(autofill(loc))
    fn HttpError::unauthorized(detail : String, loc~ : SourceLoc) -> HttpError

    HttpError::unprocessable

    #callsite(autofill(loc))
    fn HttpError::unprocessable(issues : Array[
    ValidationIssue
    ], loc~ : SourceLoc) -> HttpError

    HttpError::unsupported_media_type

    #callsite(autofill(loc))
    fn HttpError::unsupported_media_type(detail : String, loc~ : SourceLoc) -> HttpError

    App

    pub struct App {
    // private fields
    }

    ciallo 应用引擎(组装期可变 Builder,首次调用 App::fetch 或显式 App::freeze 后拍平冻结为只读结构,此后篡改抛 AppBuildError::AlreadyFrozen)

    App::App

    fn App::App(prefix? : String, options? : AppOptions, clock? : &
    Clock
    ) -> App

    App::delete

    fn App::delete(self : App, path : StringView, options? : RouteOptions, handler : async (Context) ->
    Response
    ) -> App raise AppBuildError

    App::delete_typed

    fn[Resp :
    ToJson
    +
    Schema
    ] App::delete_typed(self : App, path : StringView, status? : Int, options? : RouteOptions, handler : async (Context) -> Resp) -> App raise AppBuildError

    App::fetch

    框架唯一中立调度入口(Total Function:所有异常与校验错误内部收口为标准 @http.Response)

    App::freeze

    fn App::freeze(self : App) -> App

    App::get

    fn App::get(self : App, path : StringView, options? : RouteOptions, handler : async (Context) ->
    Response
    ) -> App raise AppBuildError

    App::get_sse_typed

    fn[Frame :
    ToJson
    +
    Schema
    ] App::get_sse_typed(self : App, path : StringView, options? : RouteOptions, handler : async (Context) -> (async () ->
    TypedSseEvent
    [Frame]?)) -> App raise AppBuildError

    App::get_typed

    fn[Resp :
    ToJson
    +
    Schema
    ] App::get_typed(self : App, path : StringView, status? : Int, options? : RouteOptions, handler : async (Context) -> Resp) -> App raise AppBuildError

    App::guard_group

    fn App::guard_group(self : App, prefix? : String, before_handle? : Array[async (Context) ->
    Response
    ?], params_schema? :
    SchemaNode
    , query_schema? :
    SchemaNode
    , bearer_auth? : Bool, configure : (App) -> Unit raise AppBuildError) -> App raise AppBuildError

    App::health_checks

    App::on_after_handle

    fn App::on_after_handle(self : App, scope? : Scope, hook : async (Context,
    Response
    ) ->
    Response
    ) -> App raise AppBuildError

    App::on_after_response

    fn App::on_after_response(self : App, scope? : Scope, hook : async (Context,
    Response
    ) -> Unit) -> App raise AppBuildError

    App::on_before_handle

    fn App::on_before_handle(self : App, scope? : Scope, hook : async (Context) ->
    Response
    ?) -> App raise AppBuildError

    App::on_error

    fn App::on_error(self : App, scope? : Scope, mapper : async (Context, Error) ->
    Response
    ?) -> App raise AppBuildError

    App::on_map_response

    fn App::on_map_response(self : App, scope? : Scope, hook : async (Context,
    Response
    ) ->
    Response
    ) -> App raise AppBuildError

    App::on_parse

    fn App::on_parse(self : App, scope? : Scope, hook : async (Context) -> Unit) -> App raise AppBuildError

    App::on_request

    fn App::on_request(self : App, hook : async (Context) ->
    Response
    ?) -> App raise AppBuildError

    App::on_trace

    fn App::on_trace(self : App, scope? : Scope, listener : (TraceSummary) -> Unit) -> App raise AppBuildError

    App::on_transform

    fn App::on_transform(self : App, scope? : Scope, hook : async (Context) -> Unit) -> App raise AppBuildError

    App::patch

    fn App::patch(self : App, path : StringView, options? : RouteOptions, handler : async (Context) ->
    Response
    ) -> App raise AppBuildError

    App::patch_typed

    fn[Req :
    FromJson
    +
    Schema
    , Resp :
    ToJson
    +
    Schema
    ] App::patch_typed(self : App, path : StringView, status? : Int, options? : RouteOptions, handler : async (Context, Req) -> Resp) -> App raise AppBuildError

    App::post

    fn App::post(self : App, path : StringView, options? : RouteOptions, handler : async (Context) ->
    Response
    ) -> App raise AppBuildError

    App::post_ndjson_typed

    fn[Req :
    FromJson
    +
    Schema
    , Item :
    ToJson
    +
    Schema
    ] App::post_ndjson_typed(self : App, path : StringView, options? : RouteOptions, handler : async (Context, Req) -> (async () -> Item?)) -> App raise AppBuildError

    App::post_sse_typed

    App::post_typed

    fn[Req :
    FromJson
    +
    Schema
    , Resp :
    ToJson
    +
    Schema
    ] App::post_typed(self : App, path : StringView, status? : Int, options? : RouteOptions, handler : async (Context, Req) -> Resp) -> App raise AppBuildError

    App::provide

    fn[T] App::provide(self : App, key :
    ContextKey
    [T], value : T, allow_override? : Bool) -> App raise AppBuildError

    App::put

    fn App::put(self : App, path : StringView, options? : RouteOptions, handler : async (Context) ->
    Response
    ) -> App raise AppBuildError

    App::put_typed

    fn[Req :
    FromJson
    +
    Schema
    , Resp :
    ToJson
    +
    Schema
    ] App::put_typed(self : App, path : StringView, status? : Int, options? : RouteOptions, handler : async (Context, Req) -> Resp) -> App raise AppBuildError

    App::register_health_check

    fn App::register_health_check(self : App, probe : &
    HealthCheck
    ) -> App raise AppBuildError

    App::register_lifecycle

    fn App::register_lifecycle(self : App, component : &
    Lifecycle
    ) -> App raise AppBuildError

    App::route

    fn App::route(self : App, meth :
    Method
    , path : StringView, options? : RouteOptions, handler : async (Context) ->
    Response
    ) -> App raise AppBuildError

    App::start_lifecycles

    async fn App::start_lifecycles(self : App) -> Unit

    App::stop_lifecycles

    async fn App::stop_lifecycles(self : App) -> Unit

    App::use_bundle

    fn App::use_bundle(self : App, bundle : &CapabilityBundle) -> App raise AppBuildError

    App::use_plugin

    fn App::use_plugin(self : App, meta? : PluginMeta, plugin : App) -> App raise AppBuildError

    深拷贝挂载子应用容器快照(保证同一 plugin 实例可安全复用于多个父应用/单测互不污染)

    AppOptions

    pub(all) struct AppOptions {
    prefix : String?
    debug : Bool
    default_max_body_bytes : Int64
    strict_trailing_slash_redirect : Bool
    default_sse_heartbeat_ms : Int?
    } derive(Eq,
    Debug
    )

    AppOptions::AppOptions

    fn AppOptions::AppOptions(prefix? : String, debug? : Bool, default_max_body_bytes? : Int64, strict_trailing_slash_redirect? : Bool, default_sse_heartbeat_ms? : Int?) -> AppOptions

    Context

    pub struct Context {
    // private fields
    }

    请求级上下文(内部采用 Unread | Buffered(Bytes, Json?) | StreamConsumed 三态缓存与头/Cookie 操作队列)

    Context::append_header

    fn Context::append_header(self : Context, name : StringView, value : StringView) -> Unit

    Context::bytes

    async fn Context::bytes(self : Context, max_bytes? : Int64) -> Bytes

    Context::cookie

    fn Context::cookie(self : Context, name : StringView) -> String?

    Context::cookies

    fn Context::cookies(self : Context) -> Map[String, String]

    Context::decode_json

    fn Context::delete_cookie(self : Context, name : StringView, path? : String, domain? : String) -> Unit

    Context::env

    Context::get

    Context::get_state

    fn[T] Context::get_state(self : Context, key :
    ContextKey
    [T]) -> T?

    Context::header

    fn Context::header(self : Context, name : StringView) -> String?

    Context::json

    async fn Context::json(self : Context, max_bytes? : Int64) ->
    Json

    Context::json_as

    async fn[T :
    FromJson
    +
    Schema
    ] Context::json_as(self : Context, max_bytes? : Int64) -> T

    Context::json_response

    fn Context::json_response(_self : Context, value :
    Json
    , status? : Int) ->
    Response

    Context::ndjson

    Context::no_content

    Context::param

    fn Context::param(self : Context, name : StringView) -> String?

    Context::param_as

    fn[T : FromParam] Context::param_as(self : Context, name : StringView) -> T raise
    ValidationError

    Context::queries

    fn Context::queries(self : Context) -> Map[String, Array[String]] raise HttpError

    Context::query

    fn Context::query(self : Context, key : StringView) -> String? raise HttpError

    Context::remove_header

    fn Context::remove_header(self : Context, name : StringView) -> Unit

    Context::request

    Context::require

    fn[T] Context::require(self : Context, key :
    ContextKey
    [T]) -> T raise HttpError

    Context::set

    fn[T] Context::set(self : Context, key :
    ContextKey
    [T], value : T) -> Unit

    fn Context::set_cookie(self : Context, cookie :
    Cookie
    ) -> Unit

    Context::set_header

    fn Context::set_header(self : Context, name : StringView, value : StringView) -> Unit

    Context::sse_events

    fn Context::sse_events(self : Context, next_event : async () ->
    SseEvent
    ?) ->
    Response

    SSE 响应(在 core 层内建基于有界 @async.Queue + with_timeout_opt(queue.get) 的取消安全 : ping\n\n 心跳,Native 与 JS 共享)

    Context::state

    fn[T] Context::state(self : Context, key :
    ContextKey
    [T]) -> T raise HttpError

    Context::status

    fn Context::status(self : Context, code : Int) -> Unit

    Context::text

    async fn Context::text(self : Context, max_bytes? : Int64) -> String

    Context::text_response

    fn Context::text_response(_self : Context, text : StringView, status? : Int) ->
    Response

    Context::trace_ctx

    Context::trace_id

    fn Context::trace_id(self : Context) -> String

    LifecyclePhase

    pub(all) enum LifecyclePhase {
    Request
    Parse
    Transform
    BeforeHandle
    Handle
    AfterHandle
    MapResponse
    AfterResponse
    OnError
    } derive(Eq, Hash,
    Debug
    )

    PluginMeta

    pub(all) struct PluginMeta {
    name : String
    seed : String?
    } derive(Eq, Hash,
    Debug
    )

    PluginMeta::PluginMeta

    fn PluginMeta::PluginMeta(name~ : String, seed? : String) -> PluginMeta

    ProblemDetails

    pub(all) struct ProblemDetails {
    type_uri : String
    title : String
    status : Int
    detail : String
    instance : String?
    code : String
    trace_id : String?
    errors : Array[
    ValidationIssue
    ]?
    source_loc : String?
    extensions : Map[String,
    Json
    ]
    } derive(Eq,
    Debug
    )

    RFC 9457 (Problem Details) 标准化错误输出(application/problem+json)

    ProblemDetails::to_json

    RouteOptions

    pub(all) struct RouteOptions {
    operation_id : String?
    status : Int?
    summary : String?
    description : String?
    tags : Array[String]
    deprecated : Bool
    max_body_bytes : Int64?
    sse_heartbeat_ms : Int?
    params_schema :
    SchemaNode
    ?
    query_schema :
    SchemaNode
    ?
    body_schema :
    SchemaNode
    ?
    response_schema :
    SchemaNode
    ?
    response_kind :
    ResponseKind
    ?
    error_responses : Array[
    ResponseSpec
    ]
    bearer_auth : Bool
    allow_sparse_fields : Bool
    before_handle : Array[async (Context) ->
    Response
    ?]
    after_handle : Array[async (Context,
    Response
    ) ->
    Response
    ]
    }

    RouteOptions::RouteOptions

    fn RouteOptions::RouteOptions(operation_id? : String, status? : Int, summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, max_body_bytes? : Int64, sse_heartbeat_ms? : Int, params_schema? :
    SchemaNode
    , query_schema? :
    SchemaNode
    , body_schema? :
    SchemaNode
    , response_schema? :
    SchemaNode
    , response_kind? :
    ResponseKind
    , error_responses? : Array[
    ResponseSpec
    ], bearer_auth? : Bool, allow_sparse_fields? : Bool, before_handle? : Array[async (Context) ->
    Response
    ?], after_handle? : Array[async (Context,
    Response
    ) ->
    Response
    ]) -> RouteOptions

    RouteOptions::with_params

    fn[P :
    Schema
    ] RouteOptions::with_params(self : RouteOptions, _proxy : P?) -> RouteOptions

    RouteOptions::with_query

    fn[Q :
    Schema
    ] RouteOptions::with_query(self : RouteOptions, _proxy : Q?) -> RouteOptions

    Scope

    pub(all) enum Scope {
    Local
    Scoped
    Global
    } derive(Eq, Hash,
    Debug
    )

    TraceEvent

    pub(all) struct TraceEvent {
    phase : LifecyclePhase
    start_micros : Int64
    end_micros : Int64
    duration_micros : Int64
    } derive(Eq,
    Debug
    )

    TraceSummary

    pub(all) struct TraceSummary {
    meth :
    Method

    path : String
    pattern : String?
    status : Int
    total_micros : Int64
    events : Array[TraceEvent]
    } derive(Eq,
    Debug
    )

    remote_addr_key

    let remote_addr_key :
    ContextKey
    [String]