ciallo-js

    JavaScript & Edge Web Fetch adapter (Cloudflare Workers, Vercel Edge, Deno, Bun, Node) for unmbt/ciallo

    web
    workers
    cloudflare
    edge
    fetch
    ciallo
    Download zip
    Author
    Version
    0.3.0
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    22

    #unmbt/ciallo-js

    JavaScript & Edge adapter for unmbt/ciallo supporting:

    • Cloudflare Workers / Vercel Edge / Deno Deploy: to_fetch_handler(app) (standard Web Fetch API, multi-value Set-Cookie, streaming SSE ReadableStream, ctx.waitUntil).
    • Node.js 18+ & Bun 1.x: serve(app, host~, port~, env_mapper?, on_listen?) -> JsHttpServer (auto-detects Bun.serve on Bun and dynamically imports node:http on Node.js with real-time chunked SSE streaming and Lifecycle start/stop; zero static node:* imports so Workers bundles stay clean).

    CfQueueEntry

    pub(all) struct CfQueueEntry {
    id : String
    queue : String
    timestamp_ms : Int64
    body :
    Json

    attempts : Int
    } derive(Eq,
    Debug
    )

    Strongly-typed Cloudflare Queue message passed to MoonBit consumers.

    CfScheduledTrigger

    pub(all) struct CfScheduledTrigger {
    cron : String
    scheduled_time_ms : Int64
    } derive(Eq,
    Debug
    )

    Strongly-typed Cloudflare Cron Trigger event passed to MoonBit scheduled handlers.

    FetchHttpClient

    pub struct FetchHttpClient {
    // private fields
    }

    JavaScript / Edge outbound HTTP client implementing @runtime.HttpClient.

    JsEnv

    #external
    pub type JsEnv

    JsExecutionContext

    #external
    pub type JsExecutionContext

    JsHttpServer

    pub struct JsHttpServer {
    // private fields
    }

    Running Node.js or Bun HTTP server handle returned by @ciallo_js.serve(...).

    JsHttpServer::close

    async fn JsHttpServer::close(self : JsHttpServer, shutdown_timeout_ms? : Int) -> Unit

    Stops accepting connections, drains in-flight requests and waitUntil promises up to shutdown_timeout_ms, closes remaining sockets, and invokes app.stop_lifecycles() in reverse order.

    JsHttpServer::port

    fn JsHttpServer::port(self : JsHttpServer) -> Int

    Returns the actual bound TCP port (useful when passing port=0).

    JsQueueBatch

    #external
    pub type JsQueueBatch

    JsQueueMessage

    #external
    pub type JsQueueMessage

    JsRequest

    #external
    pub type JsRequest

    JsResponse

    #external
    pub type JsResponse

    JsScheduledController

    #external
    pub type JsScheduledController

    JsWebSocket

    #external
    pub type JsWebSocket

    JsWsHandler

    pub(all) struct JsWsHandler {
    on_open : (JsWsSession) -> Unit
    on_message : (JsWsSession,
    WsMessage
    ) -> Unit
    on_close : (JsWsSession,
    WsCloseCode
    , String) -> Unit
    }

    JsWsHandler::JsWsHandler

    fn JsWsHandler::JsWsHandler(on_open? : (JsWsSession) -> Unit, on_message~ : (JsWsSession,
    WsMessage
    ) -> Unit, on_close? : (JsWsSession,
    WsCloseCode
    , String) -> Unit) -> JsWsHandler

    JsWsPeer

    pub struct JsWsPeer {
    // private fields
    }

    Async @runtime.WsPeer adapter wrapping any JS WebSocket object (Cloudflare WebSocketPair, Bun ServerWebSocket, or Node.js RFC 6455 upgrade socket wrapper).

    JsWsPeer::close

    async fn JsWsPeer::close(self : JsWsPeer, code? :
    WsCloseCode
    , reason? : String) -> Unit

    JsWsPeer::from_js_socket

    fn JsWsPeer::from_js_socket(ws : JsWebSocket) -> JsWsPeer

    JsWsPeer::send

    JsWsSession

    pub struct JsWsSession {
    ws : JsWebSocket
    }

    Cloudflare Workers / Edge WebSocket session wrapping the server end of WebSocketPair.

    JsWsSession::close

    fn JsWsSession::close(self : JsWsSession, code? :
    WsCloseCode
    , reason? : String) -> Unit

    JsWsSession::send

    QueueAction

    pub(all) enum QueueAction {
    Ack
    Retry(delay_seconds~ : Int?)
    } derive(Eq,
    Debug
    )

    Outcome returned by a Cloudflare Queue consumer for each message in a batch.

    fetch_http_client

    fn fetch_http_client(timeout_ms? : Int) -> FetchHttpClient

    Creates a Fetch-based @runtime.HttpClient with AbortController timeout & cancellation support.

    serve

    async fn serve(app :
    App
    , host? : String, port? : Int, env_mapper? : (JsEnv) ->
    Env
    , on_listen? : (Int) -> Unit, trust_proxy? : Bool, install_signal_handlers? : Bool, shutdown_timeout_ms? : Int) -> JsHttpServer

    Starts an HTTP/SSE server for Node.js 18+ or Bun 1.x with zero glue JS. Automatically uses Bun.serve on Bun and dynamically imports node:http on Node.js, keeping Cloudflare Workers bundles completely free of static node:* imports.

    to_fetch_handler

    to_fetch_handler_with_ws

    Creates a Fetch handler supporting both HTTP routes on app and first-class Cloudflare Workers WebSocketPair upgrades for paths registered in ws_routes.

    to_queue_handler

    Exports a Cloudflare Workers queue(batch, env, ctx) handler. Each message's return value (or raised error) drives real JS msg.ack() / msg.retry({ delaySeconds }), and ctx.waitUntil is wired into @runtime.ExecutionContext so background tasks drain cleanly.

    to_scheduled_handler

    Exports a Cloudflare Workers scheduled(controller, env, ctx) Cron Trigger handler, wiring ctx.waitUntil so async tasks are never frozen before completion.