litestream

    Backend-independent SQLite synchronization and LTX replication

    Download zip
    Author
    Version
    0.2.0
    License
    MIT
    Last updated
    2 hours ago
    Downloads
    36

    No dependencies

    #mizchi/litestream

    Database-independent SQLite synchronization and LTX support for MoonBit. Supports JS and Wasm GC without depending on SQLike, SQLite or Turso engines.

    moon add mizchi/litestream@0.2.0

    Import "mizchi/litestream" from moon.pkg and use the @litestream APIs:

    • Generate/apply LTX v3 files and validate TXIDs and checksums.
    • Decode SQLite Session changesets and plan their SQL application.
    • Encode/decode transport frames and evaluate revision/apply decisions.
    • Use LZ4 and CRC64 helpers.

    LTX APIs accept SQLite images independently of the driver producing them. Applications supply the driver capabilities needed for Session or LTX synchronization.

    The @mizchi/litestream npm package provides JavaScript/TypeScript hosts for HTTP/P2P transports, offline edits, retries and application-defined conflict policies.

    LtxResult

    type LtxResult

    Opaque portable result; JavaScript only marshals metadata at the ABI boundary.

    apply_ltx

    fn apply_ltx(base : Bytes, txid : String, data : Bytes, version : Int) -> LtxResult

    apply_ltx_base64

    fn apply_ltx_base64(base : String, txid : String, data : String, version : Int) -> LtxResult

    assess_apply

    fn assess_apply(head : Int, base : Int, kind : Int, same_database : Bool, same_schema : Bool, matching_assertions : Bool, matching_effects : Bool) -> String

    Platform-independent, fail-closed order for application guard checks.

    decode_changeset

    fn decode_changeset(data : Bytes) -> String

    decode_frame

    fn decode_frame(data : Bytes) -> String

    encode_frame

    fn encode_frame(kind : Int, base : Int, op_id : String, payload : Bytes) -> Bytes

    Stable JS ABI: no dependency on the compiler's Result representation. Invalid input returns empty bytes; the host encoder converts that sentinel to an error.

    encode_ltx

    fn encode_ltx(base : Bytes, data : Bytes, min : String, max : String, timestamp : String) -> LtxResult

    encode_ltx_base64

    fn encode_ltx_base64(base : String, data : String, min : String, max : String, timestamp : String) -> LtxResult

    encode_ltx_pages

    fn encode_ltx_pages(state : String, metadata : String, data : Bytes) -> LtxResult

    encode_ltx_pages_base64

    fn encode_ltx_pages_base64(state : String, metadata : String, data : String) -> LtxResult

    encode_ltx_pages_binary

    fn encode_ltx_pages_binary(state : String, metadata : String, data : Bytes, previous : Bytes) -> LtxResult

    encode_ltx_pages_binary_base64

    fn encode_ltx_pages_binary_base64(state : String, metadata : String, data : String, previous : String) -> LtxResult

    ltx_data

    fn ltx_data(result : LtxResult) -> Bytes

    ltx_data_base64

    fn ltx_data_base64(result : LtxResult) -> String

    String ABI for hosts where MoonBit GC byte arrays are opaque references.

    ltx_info

    fn ltx_info(result : LtxResult) -> String

    note_policy

    fn note_policy(input : String) -> String

    Example consumer policy. The host supplies a read-only match count and score. Edit this function or register another policy; decisions are never sent as code.

    plan_changes

    fn plan_changes(changes_json : String, schema_json : String) -> String

    plan_ltx

    fn plan_ltx(catalog : String, current : String, target : String) -> String

    revision_decision

    fn revision_decision(head : Int, base : Int, kind : Int, duplicate : Bool) -> String

    Idempotency must be checked before rejecting an old revision.

    sql_allowed

    fn sql_allowed(sql : String) -> Bool

    cannot be reached through quoted identifiers or comments. SQLite parses SQL.