This version of the module is deprecated: This package is deprecated. moonbit-community/proton should be preferred.

    #proton/core

    justjavac/proton/core owns the bridge between native MoonBit code and page JavaScript.

    It provides:

    • extension specs and installation
    • op registration and dispatch
    • resource tables
    • window.__MoonBit__ bridge wiring
    • extension events

    Application lifecycle and app composition belong in the root proton facade, which drives the native Proton dynamic library.

    AppCommandHost

    type AppCommandHost

    Command host for user app code.

    The framework decides how this host is connected to the window runtime. App authors register commands and run the host without depending on the underlying IPC implementation.

    AppCommandHost::close

    fn AppCommandHost::close(self : AppCommandHost) -> Unit

    Closes this command host and rejects future dispatches.

    AppCommandHost::dispatch_ipc

    Dispatches one IPC request on the current async loop.

    AppCommandHost::dispatch_ipc_with_event_sender

    Dispatches one IPC request with an event sender scoped to the current async task.

    AppCommandHost::emit_extension

    async fn[Payload : ToJson] AppCommandHost::emit_extension(self : AppCommandHost, extension_namespace : String, event_name : String, payload : Payload) -> Unit

    Emits one extension event through the installed IPC event sender.

    AppCommandHost::new

    Creates an empty app command host.

    AppCommandHost::op

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op(self : AppCommandHost, name : String, callback : (Payload) -> Reply) -> Unit

    Registers a synchronous app command.

    AppCommandHost::op_async

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op_async(self : AppCommandHost, name : String, callback : async (Payload) -> Reply) -> Unit

    Registers an async app command.

    AppCommandHost::op_async_result

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op_async_result(self : AppCommandHost, name : String, callback : async (Payload) -> Result[Reply, String]) -> Unit

    Registers an async app command that can return a string error.

    AppCommandHost::op_result

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op_result(self : AppCommandHost, name : String, callback : (Payload) -> Result[Reply, String]) -> Unit

    Registers a synchronous app command that can return a string error.

    AppCommandHost::registered_ops

    fn AppCommandHost::registered_ops(self : AppCommandHost) -> Array[String]

    Returns registered command names in registration order.

    AppCommandHost::scope_events_for_op

    fn AppCommandHost::scope_events_for_op(self : AppCommandHost, name : String) -> Unit

    Marks an op as emitting extension events during request handling.

    AppCommandHost::seal_registrations

    fn AppCommandHost::seal_registrations(self : AppCommandHost) -> Unit

    Prevents later command registration while keeping existing commands usable.

    AppCommandHost::set_event_sender

    fn AppCommandHost::set_event_sender(self : AppCommandHost, emit : async (
    IpcExtensionEvent
    ) -> Unit) -> Unit

    Installs the process-level event sender used by command extensions.

    Events emitted while handling a bridged request use the request-scoped sender installed by dispatch_ipc_with_event_sender.

    Extension

    type Extension

    Runtime abstraction for a Proton extension.

    Extension::id

    fn Extension::id(self : Extension) -> String

    Returns the stable extension id.

    Extension::js_namespace

    fn Extension::js_namespace(self : Extension) -> String

    Returns the JavaScript namespace exposed by this extension.

    Extension::new

    fn Extension::new(id : String, js_namespace : String, register : (ExtensionContext) -> Unit, on_install? : (ExtensionContext) -> Unit, on_destroy? : (ExtensionContext) -> Unit, scripts? : Array[String]) -> Extension

    Builds an extension value that can later be installed on an ExtensionHost.

    Extension::scripts

    fn Extension::scripts(self : Extension) -> Array[String]

    Returns the installed JavaScript helper scripts owned by this extension.

    ExtensionBuildContext

    type ExtensionBuildContext

    Build-time context passed to an extension spec when constructing one runtime extension.

    ExtensionBuildContext::base_dir

    fn ExtensionBuildContext::base_dir(self : ExtensionBuildContext) -> String?

    Returns the manifest base directory, when app creation came from a file. Extensions typically use this to resolve relative file paths from declarative configuration.

    ExtensionBuildContext::new

    fn ExtensionBuildContext::new(options? : Json?, base_dir? : String?) -> ExtensionBuildContext

    Creates an extension build context. Specs receive this value when they need manifest-provided options or a base directory while constructing one runtime extension instance.

    ExtensionBuildContext::options

    Returns the JSON options configured for this extension. Specs can read this to interpret manifest-time configuration before constructing their runtime behavior.

    ExtensionContext

    type ExtensionContext

    Registration context handed to an extension during installation.

    ExtensionContext::emit

    fn[Payload : ToJson] ExtensionContext::emit(self : ExtensionContext, event_name : String, payload : Payload) -> Unit

    Emits an extension-scoped event through the host.

    ExtensionContext::id

    fn ExtensionContext::id(self : ExtensionContext) -> String

    Returns the stable extension id currently being installed.

    ExtensionContext::js_namespace

    fn ExtensionContext::js_namespace(self : ExtensionContext) -> String

    Returns the JavaScript namespace currently being installed.

    ExtensionContext::op

    fn[Payload :
    FromJson
    , Reply : ToJson] ExtensionContext::op(self : ExtensionContext, api_name : String, callback : (Payload) -> Reply) -> Unit

    Registers a typed extension op.

    ExtensionContext::op_result

    fn[Payload :
    FromJson
    , Reply : ToJson] ExtensionContext::op_result(self : ExtensionContext, api_name : String, callback : (Payload) -> Result[Reply, String]) -> Unit

    Registers a typed extension op that can return explicit errors.

    ExtensionHost

    type ExtensionHost

    Host wrapper for registering extension metadata and native op handlers.

    ExtensionHost::api_names

    fn ExtensionHost::api_names(self : ExtensionHost, extension_namespace : String) -> Array[String]

    Returns the API names registered for one installed extension namespace.

    ExtensionHost::destroy

    fn ExtensionHost::destroy(self : ExtensionHost) -> Unit

    Drops all registered extension metadata.

    ExtensionHost::dispatch_op

    fn ExtensionHost::dispatch_op(self : ExtensionHost, name : String, payload : Json) -> Result[Json, String]

    Dispatches one installed extension op with a raw JSON payload.

    ExtensionHost::emit

    fn[Payload : ToJson] ExtensionHost::emit(self : ExtensionHost, extension_namespace : String, event_name : String, payload : Payload) -> Unit

    Validates and records an extension-scoped event.

    ExtensionHost::install

    fn ExtensionHost::install(self : ExtensionHost, extension : Extension) -> Unit

    Installs an extension into the host.

    ExtensionHost::new

    Creates an extension host.

    ExtensionSpec

    type ExtensionSpec

    Declarative extension spec registered in application code.

    ExtensionSpec::build_default

    fn ExtensionSpec::build_default(self : ExtensionSpec) -> Result[Extension, String]

    Builds the runtime extension with default options and no base directory. It is useful for direct installation paths that do not need manifest-derived context.

    ExtensionSpec::build_extension

    fn ExtensionSpec::build_extension(self : ExtensionSpec, context : ExtensionBuildContext) -> Result[Extension, String]

    Builds the runtime extension using the provided build context. This is the low-level execution step behind app planning, generated registries, and declarative extension composition.

    ExtensionSpec::dependencies

    fn ExtensionSpec::dependencies(self : ExtensionSpec) -> Array[String]

    Returns the extension ids that must be resolved before this spec. App planning and tooling use this metadata to expand transitive dependencies deterministically.

    ExtensionSpec::id

    fn ExtensionSpec::id(self : ExtensionSpec) -> String

    Returns the extension spec id. This id is the stable manifest and tooling key used to select the extension.

    ExtensionSpec::js_namespace

    fn ExtensionSpec::js_namespace(self : ExtensionSpec) -> String

    Returns the JavaScript namespace exposed by the built runtime extension. This namespace is independent from the stable manifest/catalog id.

    ExtensionSpec::new

    fn ExtensionSpec::new(id : String, js_namespace : String, build : (ExtensionBuildContext) -> Result[Extension, String], dependencies? : Array[String]) -> ExtensionSpec

    Creates a declarative extension spec. Application code registers specs up front so app composition can stay explicit and build-time link plans remain reviewable.

    MbtProcessHost

    type MbtProcessHost

    Command host intended to run in the MBT process.

    The host is independent from the browser window, so application code can use normal MoonBit syntax, state, and async handlers without living in the GUI process.

    MbtProcessHost::close

    fn MbtProcessHost::close(self : MbtProcessHost) -> Unit

    Closes this host and rejects future dispatches.

    MbtProcessHost::dispatch

    Dispatches one decoded IPC request.

    Async handlers complete later through complete; synchronous handlers call it before this function returns.

    MbtProcessHost::dispatch_async

    Dispatches one decoded IPC request on the current async loop.

    User command hosts use this path so async ops run inside the user process event loop instead of creating a nested event loop elsewhere.

    MbtProcessHost::dispatch_json

    fn MbtProcessHost::dispatch_json(self : MbtProcessHost, raw : String, complete : (
    IpcOpResponse
    ) -> Unit) -> Unit

    Parses and dispatches one JSON IPC request payload.

    MbtProcessHost::dispatch_json_async

    async fn MbtProcessHost::dispatch_json_async(self : MbtProcessHost, raw : String) ->
    IpcOpResponse

    Parses and dispatches one JSON IPC request payload on the current async loop.

    MbtProcessHost::new

    Creates an empty MBT-side command host.

    MbtProcessHost::op

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op(self : MbtProcessHost, name : String, callback : (Payload) -> Reply) -> Unit

    Registers a synchronous MBT-side op.

    MbtProcessHost::op_async

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op_async(self : MbtProcessHost, name : String, callback : async (Payload) -> Reply) -> Unit

    Registers an async MBT-side op.

    MbtProcessHost::op_async_result

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op_async_result(self : MbtProcessHost, name : String, callback : async (Payload) -> Result[Reply, String]) -> Unit

    Registers an async MBT-side op that can return a string error.

    MbtProcessHost::op_result

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op_result(self : MbtProcessHost, name : String, callback : (Payload) -> Result[Reply, String]) -> Unit

    Registers a synchronous MBT-side op that can return a string error.

    MbtProcessHost::registered_ops

    fn MbtProcessHost::registered_ops(self : MbtProcessHost) -> Array[String]

    Returns registered op names in registration order.

    ResourceTable

    type ResourceTable[T]

    Generic resource table for long-lived native handles exposed to JavaScript.

    ResourceTable::add

    fn[T] ResourceTable::add(self : ResourceTable[T], value : T) -> Int

    Stores one value and returns its new resource id. Resource ids grow monotonically for the lifetime of the table so callers can hand them to JavaScript or native code safely.

    ResourceTable::contains

    fn[T] ResourceTable::contains(self : ResourceTable[T], rid : Int) -> Bool

    Returns whether one resource id is currently registered. Use this for validation when incoming ids may have been released already.

    ResourceTable::get

    fn[T] ResourceTable::get(self : ResourceTable[T], rid : Int) -> T?

    Returns one resource by id when it is still registered. None means the id was never issued or has already been released.

    ResourceTable::new

    fn[T] ResourceTable::new() -> ResourceTable[T]

    Creates an empty resource table. Resource ids start at 1 so 0 can remain available as a sentinel in external protocols.

    ResourceTable::remove

    fn[T] ResourceTable::remove(self : ResourceTable[T], rid : Int) -> T?

    Removes one resource and returns its previous value when present. This is the normal release path for long-lived native handles exposed to JavaScript.

    ResourceTable::rids

    fn[T] ResourceTable::rids(self : ResourceTable[T]) -> Array[Int]

    Returns every currently registered resource id. The result is useful for bulk cleanup, diagnostics, or leak detection.

    TemplateReplacement

    type TemplateReplacement

    moonbit_global_name

    fn moonbit_global_name() -> String

    Returns the root JavaScript namespace used by Proton runtime helpers. JavaScript bridges and generated helper scripts should agree on this value when exposing Proton functionality on window.

    moonbit_op_binding_name

    fn moonbit_op_binding_name() -> String

    Returns the native binding name used by the op bridge. Native dispatch glue and injected runtime scripts both use this name to route op calls through the same binding.

    render_js_template

    fn render_js_template(template : String, replacements : Array[TemplateReplacement]) -> String

    Applies a sequence of token replacements to a JavaScript template string. Replacements are processed in order, which allows later entries to build on earlier substitutions when generating runtime helper scripts.

    replacement

    fn replacement(token : String, value : String) -> TemplateReplacement

    Creates a single token replacement entry for render_js_template. This keeps call sites readable when several template tokens need to be substituted together.