Sign in

    napi-mbt

    Generate and build Node-API bindings for MoonBit.

    Download zip
    Author
    Version
    0.3.5
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    73

    #⚡ napi-mbt

    A Native Node-API (N-API) Toolchain, Code Generator, and Runtime for MoonBit

    MoonBit Mooncakes CI License: MIT Platform Node-API


    #📖 Overview

    napi-mbt is an end-to-end toolchain and runtime library that compiles MoonBit native packages (preferred_target = "native") into ABI-stable Node.js .node addons.

    Without writing C/C++ boilerplate by hand, napi-mbt parses your MoonBit package with an embedded Tree-sitter MoonBit grammar and automatically produces:

    • Native Node-API C glue with strict boundary validation and deterministic resource cleanup
    • Compiled .node native addons via moon build --target native and host C toolchains (MSVC, GCC, or Clang)
    • Dual-mode JavaScript loaders supporting both CommonJS (index.cjs) and ES Modules (index.mjs)
    • Strict TypeScript declarations (index.d.ts) matching your MoonBit signatures
    • Cross-platform npm package manifests for per-platform binary distribution (optionalDependencies)

    Crucially, napi-mbt-cli is a standalone native binary. You can install it directly via Mooncakes (moon install) or GitHub Releases—running the CLI itself does not require Node.js or npm.


    #✨ Key Highlights

    CapabilityDescription
    🎯 Zero-Boilerplate ExportsExport pub fn and pub async fn with #export_name("..."), alongside owned pub struct and pub enum value types. Native classes are configured cleanly in napi-mbt.json.
    🛡️ Strict Boundary ValidationRejects NaN, ±Infinity, fractional floats passed to integers, out-of-range 32-bit/64-bit numbers, and invalid UTF-16/Buffer inputs at the C boundary before entering MoonBit.
    ⚡ Full Async & Concurrency StackSupports cancellable pub async fn Promises (moonbitlang/async@0.22.4 + libuv with AbortSignal), native C worker pool tasks (nativeTasks), isolated MoonBit worker process pools (workerTasks), awaited JS Promises (NapiJsPromise), and demand-driven async streams (NapiAsyncIterator).
    🧱 Safe Classes & CallbacksNative classes include constructors, static factories, getters/setters, methods, and explicit idempotent .dispose(). Callbacks support typed MoonBit signatures (Args) -> Ret raise, returned closures with .dispose(), and threadsafe functions (NapiCallback).
    🔒 Isolated, Cached BuildsCompiles inside isolated workspaces without mutating user source files. Includes content-addressed build caching, watch mode (--watch), and native symbol collision inspection (nm / dumpbin).
    📦 Precise ABI & Engine RangesTargets N-API v4 by default and automatically raises the required N-API level (up to v8) only when higher-level features are used, computing the exact engines.node intersection in package.json.


    #🖥️ Platform & Node.js Support

    #Native Host Targets

    napi-mbt builds native addons for the current host architecture and C runtime:

    OSArchitectureC Runtime / ToolchainPackage Platform Triple
    Windowsx64MSVC (cl / MSBuild + Windows SDK)win32-x64-msvc
    Linuxx64, arm64glibc (gcc / clang)linux-x64-gnu, linux-arm64-gnu
    Linuxx64, arm64musl (Alpine native toolchain)linux-x64-musl, linux-arm64-musl
    macOSx64, arm64Apple Clang (Xcode / Command Line Tools)darwin-x64, darwin-arm64

    [!NOTE] Cross-architecture compilation is intentionally rejected unless running on a matching host toolchain. On Linux (gnu and musl), compiler probes and output ELF dynamic dependencies (PT_INTERP / DT_NEEDED) are verified before installing .node binaries and again during prepublish. See Support Policy and Platform Validation.

    #Node-API Feature Matrix

    Feature SurfaceMinimum N-APIMinimum Node.js Consumer Baseline
    Scalars (Int, UInt, Double, Bool), UTF-16 String, owned struct / enum / Array / Map1Node 10.16.0 (CJS) / 12.20.0 (Dual CJS+ESM)
    Native classes (NapiClass) & callback lifecycle3Node 10.16.0 (CJS) / 12.20.0 (Dual CJS+ESM)
    Stored / threadsafe callbacks (NapiCallback, default CLI target)4>=12.20.0 <13 \|\| >=14.13.1 (Dual default)
    Exact 64-bit Int64 / UInt64 (bigint)6Node 10.7.0+ (intersected with loader mode)
    Bytes (Buffer) & synchronous borrowed NapiBufferView7Node 10.16.0+ (intersected with loader mode)
    pub async fn, NapiTask, NapiJsPromise, NapiAsyncIterator, async host cleanup8>=12.22.0 <13 \|\| >=14.17.0 <15 \|\| >=15.12.0 <16 \|\| >=16.0.0
    Web ReadableStream helper (*Stream)8Node 18.0.0+

    CI continuously validates Node 22, 24, and 26, alongside minimum-version consumer compatibility gates and Windows/Linux memory-leak verification.


    #📦 Quick Start

    #1. Install the CLI

    Install napi-mbt-cli from Mooncakes using the MoonBit toolchain:

    moon install unmbt/napi-mbt/cmd/napi-mbt-cli

    This installs the executable to ~/.moon/bin/napi-mbt-cli (%USERPROFILE%\.moon\bin\napi-mbt-cli.exe on Windows). Prebuilt archives for Windows, Linux, and macOS are also available on GitHub Releases with SHA256SUMS.txt and build provenance attestations.

    Verify your host compiler, CMake, and MoonBit environment at any time:

    napi-mbt-cli doctor

    #2. Scaffold and Build a New Addon

    napi-mbt-cli init my-addon cd my-addon moon update moon check napi-mbt-cli build

    Generated projects declare "preferred_target": "native" in moon.mod, default to N-API 4, and enable both CommonJS and ESM loaders.

    #3. Write MoonBit & Call from JavaScript / TypeScript

    Define your exports in lib.mbt:

    ///|
    pub(all) struct Summary {
    label : String
    total : Int
    }

    ///|
    #export_name("summarize")
    pub fn summarize(label : String, values : Array[Int]) -> Summary raise {
    if label.is_empty() {
    fail("label must not be empty")
    }
    let mut total = 0
    for v in values {
    total += v
    }
    { label, total }
    }

    Rebuild with napi-mbt-cli build and consume the generated addon from ES Modules, CommonJS, or TypeScript:

    import { summarize } from './index.mjs'; // or: const { summarize } = require('./index.cjs'); console.log(summarize('orders', [10, 20, 30])); // => { label: 'orders', total: 60 }


    #🧬 Type System & Runtime Capabilities

    napi-mbt enforces strict, predictable conversions across the MoonBit <-> Node.js boundary:

    MoonBit TypeJavaScript / TypeScriptSemantics & Boundary Guarantees
    Int, UIntnumberChecked 32-bit signed ([-2^31, 2^31 - 1]) and unsigned ([0, 2^32 - 1]) integers; rejects NaN, ±Infinity, and fractions.
    Int64, UInt64bigintChecked 64-bit signed/unsigned BigInt (N-API 6); rejects out-of-range 64-bit values.
    Double, Float, Bool, Unitnumber, boolean, voidPreserves IEEE-754 values, including NaN and ±Infinity.
    StringstringDirect UTF-16 string conversion without intermediate UTF-8 transcoding.
    BytesBufferOwned byte copy across the boundary (N-API 7); safe to store and return from async functions.
    NapiBufferViewBufferZero-copy synchronous borrow (N-API 7); valid only during the synchronous call frame.
    NapiUint8Array / NapiInt32Array / NapiUint32Array / NapiFloat32Array / NapiFloat64Array / NapiArrayBufferUint8Array / Int32Array / Uint32Array / Float32Array / Float64Array / ArrayBufferOwned typed-array and ArrayBuffer copies with full element length preservation.
    T?, Array[T], Map[String, T], (A, B, ...), JsonT \| null, Array<T>, Record<string, T>, [A, B, ...], JsonValueRecursive structural validation; Option::None maps to null (and accepts null or undefined on input).
    pub struct / pub enumObject / Discriminated UnionExported structs map to typed JS objects; enums map to variant name string or { tag: "Variant", args: [...] } discriminated unions.
    Configured Class (napi-mbt.json)class with dispose()Native handle wrapping with constructors, static factories, properties, methods, and deterministic disposal.
    (Args) -> Ret raise / NapiCallback(...args) => RetSupports synchronous call-scoped invocations, returned closures with dispose(), and threadsafe functions (N-API 4).
    pub async fn(...) -> TPromise<T> (with { signal?: AbortSignal })Runs on the embedded moonbitlang/async@0.22.4 + libuv loop (N-API 8) with cooperative cancellation.
    NapiJsPromise[T]Promise<T>Awaits JavaScript Promises inside MoonBit async fn exports with typed resolution.
    NapiAsyncIterator[T]AsyncIterableIterator<T> & ReadableStream<T>Demand-driven streaming input/output with backpressure and early consumer cancellation (return()).
    nativeTasks / workerTasks (napi-mbt.json)Promise<T> / Worker PoolOffloads C jobs to the libuv threadpool (nativeTasks) or pure MoonBit jobs to isolated Node worker process pools (workerTasks).


    #🛠️ CLI Reference

    napi-mbt-cli <command> [directory] [options]

    CommandDescription
    init <dir>Create the official addon template (--name <name>, --force).
    generate [dir]Generate bindings and loaders (--check to validate without writing files).
    build [dir]Build the native addon in isolation (--release, --watch, --no-cache, --dry-run, --verbose, --target <t>, --output-dir <p>).
    clean [dir]Remove this project's persistent build cache (--cache).
    doctor [dir]Check the native compiler, linker, and platform SDK (--json).
    prepublish [dir]Validate release artifacts and prepare npm platform package metadata (--target <t>).
    targetsList supported host target profiles.

    Common flags:
    • --help, -h: Print help information.
    • --version, -V: Print CLI version.

    #How the Isolated Build Pipeline Works

    1. Source & Export Analysis: napi-mbt-cli parses your .mbt files (#export_name) and napi-mbt.json, checking supported signatures and inferring the minimum N-API version.
    2. Non-Invasive Workspace Staging: The CLI prepares an isolated build workspace under .napi-mbt/cache/ (or a temporary directory) without modifying your source tree.
    3. Native Compilation & Linking: moon build --target native compiles MoonBit packages and stubs to native artifacts, linking with the generated Node-API C shim (napi_glue.c), embedded node-api-headers, and (when async is used) the moonbitlang/async libuv bridge.
    4. Symbol & Loader Emission: Exported symbols are verified against C runtime collisions (nm/dumpbin), .node binaries are copied to the artifact directory, and index.cjs, index.mjs, and index.d.ts are emitted.


    #📚 Documentation & Examples

    #Documentation Guides

    TopicGuide
    Getting Started & CLI UsageUsage Guide · Build & Loader Pipeline
    Platform & ABI PolicySupport Policy · Platform Validation · Validation Record
    Type System & ObjectsType Mapping · Classes & Callbacks · Threadsafe Functions
    Async, Streams & WorkersAsync Functions · Async Adapter · JS Promises · Async Streams · Native Tasks · Worker Pools
    Engineering & BenchmarksPerformance Benchmarks · Development Workflow · Roadmap

    #Standalone Examples

    The examples/ directory contains 9 complete, self-contained addon projects covering every runtime surface:

    ExampleDemonstrated Capabilities
    examples/hello-addonDual CJS/ESM imports and strict scalar boundary checks
    examples/structured-dataNested struct / enum records, Option, Array, Map, and Json
    examples/native-classStateful class handles configured in napi-mbt.json, getters/setters, static factories, and .dispose()
    examples/callbacksSynchronous callbacks, stored threadsafe functions, and JS exception propagation
    examples/async-filepub async fn native file I/O, AbortSignal cancellation, and error recovery
    examples/binary-processingOwned Bytes (Buffer) vs. zero-copy synchronous NapiBufferView and TypedArrays
    examples/native-tasksC worker-pool jobs (nativeTasks), cancellation, and composition with MoonBit async fn
    examples/worker-tasksPure MoonBit CPU-bound computation in isolated Node worker process pools (workerTasks)
    examples/streamsNapiAsyncIterator input/output, backpressure, cancellation, and Web ReadableStream

    To materialize any example into a standalone directory and run its test suite:

    moon run examples/setup.mbtx examples/hello-addon ../my-hello-addon cd ../my-hello-addon pnpm test


    #🧪 Development & Validation

    This repository pins MoonBit 0.10.17+093cb8f9c, CMake 4.4.4, and moonbitlang/async@0.22.4. Common repository validation commands:

    moon run scripts/toolchain-check.mbtx # Verify pinned MoonBit, CMake, and host toolchain moon check # Typecheck all MoonBit packages moon test # Run unit, whitebox, and blackbox tests moon run scripts/docs-check.mbtx # Verify Markdown links and documentation gates moon run scripts/release-check.mbtx # Verify module version and lockfile hygiene moon run scripts/examples-test.mbtx # Package the CLI and build/test all 9 standalone examples

    See Development Workflow and Validation Record for the complete verification suite.


    #📄 License & Third-Party Notices

    #Project License

    napi-mbt is licensed under the MIT License.

    #Third-Party Components & Licenses

    napi-mbt vendors parser sources under internal/syntax/vendor/ and embeds C headers and async runtime glue inside internal/assets/data/resources.json. When packaging napi-mbt-cli release archives (scripts/package-cli.mbtx), all corresponding license files are distributed under the archive's licenses/ directory:

    ComponentVersion / SourceUsage in napi-mbtLicenseRepository / Archive License Path
    Tree-sitter C Runtimev0.26.8 (cd5b087c) · tree-sitter/tree-sitterVendored C parser runtime for MoonBit AST analysisMITinternal/syntax/vendor/TREE-SITTER-LICENSE (licenses/TREE-SITTER-LICENSE)
    Unicode Character DatabaseUnicode Consortium (bundled in Tree-sitter)Unicode character tables in Tree-sitter lexerUnicode-DFS-2016internal/syntax/vendor/runtime/unicode/LICENSE (licenses/UNICODE-LICENSE)
    Tree-sitter MoonBit GrammarCommit 190881df (ABI 15) · unmbt/tree-sitter-moonbitVendored MoonBit grammar tables (parser.c / scanner.c)Apache-2.0 AND MITinternal/syntax/vendor/GRAMMAR-LICENSE (licenses/GRAMMAR-LICENSE)
    Node-API Headers (node-api-headers)v1.9.0 · nodejs/node-api-headersEmbedded node_api.h & js_native_api.h headers for standalone buildsMITEmbedded in internal/assets/data/resources.json (licenses/NODE-API-LICENSE)
    MoonBit Async Runtime (moonbitlang/async)v0.22.4 · moonbitlang/asyncEmbedded native async event-loop bridge and runtime supportApache-2.0Embedded in internal/assets/data/resources.json (licenses/MOONBIT-ASYNC-LICENSE)
    libuv Headers & Declarationslibuv/libuvEmbedded libuv declarations for Node.js event-loop integrationMITEmbedded in internal/assets/data/resources.json (licenses/LIBUV-LICENSE)

    NapiError

    pub(all) suberror NapiError {
    JavaScriptException(NapiReference)
    ApiError(status~ : Int, kind~ : NapiErrorKind, code~ : String, context~ : String)
    }

    NapiArguments

    #external
    pub type NapiArguments

    NapiArguments::get

    fn NapiArguments::get(self : NapiArguments, env : NapiEnv, index : Int) -> NapiValue raise NapiError

    NapiArguments::require

    fn NapiArguments::require(self : NapiArguments, count : Int) -> Unit raise NapiError

    NapiArrayBuffer

    pub struct NapiArrayBuffer {
    // private fields
    }

    An owned immutable byte sequence, copied from/to an independent ArrayBuffer.

    NapiArrayBuffer::byte_length

    fn NapiArrayBuffer::byte_length(self : NapiArrayBuffer) -> Int

    NapiArrayBuffer::from_bytes

    fn NapiArrayBuffer::from_bytes(data : Bytes) -> NapiArrayBuffer

    NapiArrayBuffer::to_bytes

    fn NapiArrayBuffer::to_bytes(self : NapiArrayBuffer) -> Bytes

    NapiBufferView

    pub struct NapiBufferView {
    env : NapiEnv
    value : NapiValue
    is_alive : Bool
    }

    NapiBufferView::invalidate

    fn NapiBufferView::invalidate(self : NapiBufferView) -> Unit

    Invalidates a borrowed Buffer view after the callback returns.

    NapiBufferView::length

    fn NapiBufferView::length(self : NapiBufferView) -> Int raise NapiError

    NapiBufferView::load8

    fn NapiBufferView::load8(self : NapiBufferView, offset : Int) -> Int raise NapiError

    NapiBufferView::store8

    fn NapiBufferView::store8(self : NapiBufferView, offset : Int, val : Int) -> Unit raise NapiError

    NapiCallback

    pub type NapiCallback

    An owned reference to a JavaScript function. The reference belongs to its creating environment; dispose is idempotent and GC is a fallback.

    NapiCallback::call

    fn NapiCallback::call(self : NapiCallback, args : NapiValue) -> NapiValue raise NapiError

    NapiCallback::dispose

    fn NapiCallback::dispose(self : NapiCallback) -> Unit raise NapiError

    NapiCallback::environment

    fn NapiCallback::environment(self : NapiCallback) -> NapiEnv raise NapiError

    NapiCallback::new

    fn NapiCallback::new(env : NapiEnv, value : NapiValue) -> NapiCallback raise NapiError

    NapiCallbackInfo

    #external
    pub type NapiCallbackInfo

    NapiDeferred

    #external
    pub type NapiDeferred

    NapiEnv

    #external
    pub type NapiEnv

    NapiErrorKind

    pub(all) enum NapiErrorKind {
    Error
    TypeError
    RangeError
    }

    NapiFloat32Array

    pub struct NapiFloat32Array {
    // private fields
    }

    Owned data copied from/to JavaScript. No JavaScript handles or borrowed storage.

    NapiFloat32Array::length

    fn NapiFloat32Array::length(self : NapiFloat32Array) -> Int

    NapiFloat32Array::new

    fn NapiFloat32Array::new(values : Array[Float]) -> NapiFloat32Array

    NapiFloat32Array::to_array

    fn NapiFloat32Array::to_array(self : NapiFloat32Array) -> Array[Float]

    NapiFloat64Array

    pub struct NapiFloat64Array {
    // private fields
    }

    Owned data copied from/to JavaScript. No JavaScript handles or borrowed storage.

    NapiFloat64Array::length

    fn NapiFloat64Array::length(self : NapiFloat64Array) -> Int

    NapiFloat64Array::new

    fn NapiFloat64Array::new(values : Array[Double]) -> NapiFloat64Array

    NapiFloat64Array::to_array

    fn NapiFloat64Array::to_array(self : NapiFloat64Array) -> Array[Double]

    NapiInt32Array

    pub struct NapiInt32Array {
    // private fields
    }

    Owned data copied from/to JavaScript. No JavaScript handles or borrowed storage.

    NapiInt32Array::length

    fn NapiInt32Array::length(self : NapiInt32Array) -> Int

    NapiInt32Array::new

    fn NapiInt32Array::new(values : Array[Int]) -> NapiInt32Array

    NapiInt32Array::to_array

    fn NapiInt32Array::to_array(self : NapiInt32Array) -> Array[Int]

    NapiPromise

    pub struct NapiPromise {
    promise : NapiValue
    deferred : NapiDeferred
    settled : Bool
    }

    NapiReference

    pub type NapiReference

    An owned, environment-bound JavaScript value, safe across handle scopes.

    NapiReference::dispose

    fn NapiReference::dispose(self : NapiReference) -> Unit raise NapiError

    NapiReference::get

    fn NapiReference::get(self : NapiReference, env : NapiEnv) -> NapiValue raise NapiError

    NapiReference::new

    fn NapiReference::new(env : NapiEnv, value : NapiValue) -> NapiReference raise NapiError

    NapiThreadsafeFunction

    #external
    pub type NapiThreadsafeFunction

    NapiTsfnCallMode

    pub(all) enum NapiTsfnCallMode {
    Nonblocking
    Blocking
    }

    NapiTsfnReleaseMode

    pub(all) enum NapiTsfnReleaseMode {
    Release
    Abort
    }

    NapiTsfnStatus

    pub(all) enum NapiTsfnStatus {
    Accepted
    QueueFull
    Closing
    }

    NapiUint32Array

    pub struct NapiUint32Array {
    // private fields
    }

    Owned data copied from/to JavaScript. No JavaScript handles or borrowed storage.

    NapiUint32Array::length

    fn NapiUint32Array::length(self : NapiUint32Array) -> Int

    NapiUint32Array::new

    fn NapiUint32Array::new(values : Array[UInt]) -> NapiUint32Array

    NapiUint32Array::to_array

    fn NapiUint32Array::to_array(self : NapiUint32Array) -> Array[UInt]

    NapiUint8Array

    pub struct NapiUint8Array {
    // private fields
    }

    Owned data copied from/to JavaScript. No JavaScript handles or borrowed storage.

    NapiUint8Array::length

    fn NapiUint8Array::length(self : NapiUint8Array) -> Int

    NapiUint8Array::new

    fn NapiUint8Array::new(values : Array[Byte]) -> NapiUint8Array

    NapiUint8Array::to_array

    fn NapiUint8Array::to_array(self : NapiUint8Array) -> Array[Byte]

    NapiValue

    #external
    pub type NapiValue

    UnmanagedBuffer

    #external
    pub type UnmanagedBuffer

    NAPI_MBT_RUNTIME_VERSION

    let NAPI_MBT_RUNTIME_VERSION : String

    add

    fn add(a : Int, b : Int) -> Int

    check_bool

    fn check_bool(b : Bool) -> Bool

    check_double

    fn check_double(d : Double) -> Double

    concat

    fn concat(a : String, b : String) -> String

    get_Bool

    fn get_Bool(env : NapiEnv, val : NapiValue) -> Bool raise NapiError

    get_Bytes

    fn get_Bytes(env : NapiEnv, val : NapiValue) -> Bytes raise NapiError

    get_Double

    fn get_Double(env : NapiEnv, val : NapiValue) -> Double raise NapiError

    get_Float

    fn get_Float(env : NapiEnv, value : NapiValue) -> Float raise NapiError

    get_Int

    fn get_Int(env : NapiEnv, val : NapiValue) -> Int raise NapiError

    get_Int64

    fn get_Int64(env : NapiEnv, value : NapiValue) -> Int64 raise NapiError

    get_NapiArrayBuffer

    fn get_NapiArrayBuffer(env : NapiEnv, value : NapiValue) -> NapiArrayBuffer raise NapiError

    get_NapiBufferView

    fn get_NapiBufferView(env : NapiEnv, val : NapiValue) -> NapiBufferView raise NapiError

    get_NapiFloat32Array

    fn get_NapiFloat32Array(env : NapiEnv, value : NapiValue) -> NapiFloat32Array raise NapiError

    get_NapiFloat64Array

    fn get_NapiFloat64Array(env : NapiEnv, value : NapiValue) -> NapiFloat64Array raise NapiError

    get_NapiInt32Array

    fn get_NapiInt32Array(env : NapiEnv, value : NapiValue) -> NapiInt32Array raise NapiError

    get_NapiUint32Array

    fn get_NapiUint32Array(env : NapiEnv, value : NapiValue) -> NapiUint32Array raise NapiError

    get_NapiUint8Array

    fn get_NapiUint8Array(env : NapiEnv, value : NapiValue) -> NapiUint8Array raise NapiError

    get_String

    fn get_String(env : NapiEnv, val : NapiValue) -> String raise NapiError

    get_UInt

    fn get_UInt(env : NapiEnv, value : NapiValue) -> UInt raise NapiError

    get_UInt64

    fn get_UInt64(env : NapiEnv, value : NapiValue) -> UInt64 raise NapiError

    mutate_buffer

    fn mutate_buffer(view : NapiBufferView) -> Unit raise NapiError

    napi_array_get

    fn napi_array_get(env : NapiEnv, value : NapiValue, index : Int) -> NapiValue raise NapiError

    napi_array_length

    fn napi_array_length(env : NapiEnv, value : NapiValue) -> Int raise NapiError

    napi_array_new

    fn napi_array_new(env : NapiEnv, length : Int) -> NapiValue raise NapiError

    napi_array_set

    fn napi_array_set(env : NapiEnv, value : NapiValue, index : Int, element : NapiValue) -> Unit raise NapiError

    napi_bigint_from_int64

    fn napi_bigint_from_int64(env : NapiEnv, value : Int64) -> NapiValue raise NapiError

    napi_bigint_from_uint64

    fn napi_bigint_from_uint64(env : NapiEnv, value : UInt64) -> NapiValue raise NapiError

    napi_bigint_to_int64

    fn napi_bigint_to_int64(env : NapiEnv, value : NapiValue) -> (Int64, Bool) raise NapiError

    Reads a signed BigInt and returns the value plus the lossless flag.

    napi_bigint_to_uint64

    fn napi_bigint_to_uint64(env : NapiEnv, value : NapiValue) -> (UInt64, Bool) raise NapiError

    Reads an unsigned BigInt and returns the value plus the lossless flag.

    napi_check_depth

    fn napi_check_depth(depth : Int) -> Unit raise NapiError

    napi_class_dispose

    fn napi_class_dispose(env : NapiEnv, value : NapiValue, type_id : Int) -> Unit raise NapiError

    napi_class_handle

    fn napi_class_handle(env : NapiEnv, value : NapiValue, type_id : Int) -> UnmanagedBuffer raise NapiError

    napi_closure_new

    fn napi_closure_new(env : NapiEnv, callback : (NapiEnv, NapiArguments) -> NapiValue) -> NapiValue raise NapiError

    napi_enter_value

    fn napi_enter_value(env : NapiEnv, value : NapiValue, path : Array[NapiValue]) -> Unit raise NapiError

    napi_error_value

    fn napi_error_value(env : NapiEnv, error : Error) -> NapiValue raise NapiError

    napi_field_get

    fn napi_field_get(env : NapiEnv, value : NapiValue, name : String, required : Bool) -> NapiValue raise NapiError

    napi_field_set

    fn napi_field_set(env : NapiEnv, value : NapiValue, name : String, field : NapiValue) -> Unit raise NapiError

    napi_is_nullish

    fn napi_is_nullish(env : NapiEnv, value : NapiValue) -> Bool raise NapiError

    napi_key_get

    fn napi_key_get(env : NapiEnv, value : NapiValue, key : String) -> NapiValue raise NapiError

    napi_key_set

    fn napi_key_set(env : NapiEnv, value : NapiValue, key : String, field : NapiValue) -> Unit raise NapiError

    napi_mbt_adapter_add

    fn napi_mbt_adapter_add(env : NapiEnv, a0 : NapiValue, a1 : NapiValue) -> NapiValue

    napi_mbt_adapter_check_bool

    fn napi_mbt_adapter_check_bool(env : NapiEnv, a0 : NapiValue) -> NapiValue

    napi_mbt_adapter_check_double

    fn napi_mbt_adapter_check_double(env : NapiEnv, a0 : NapiValue) -> NapiValue

    napi_mbt_adapter_concat

    fn napi_mbt_adapter_concat(env : NapiEnv, a0 : NapiValue, a1 : NapiValue) -> NapiValue

    napi_mbt_adapter_mutate_buffer

    fn napi_mbt_adapter_mutate_buffer(env : NapiEnv, a0 : NapiValue) -> NapiValue

    napi_mbt_adapter_roundtrip_bytes

    fn napi_mbt_adapter_roundtrip_bytes(env : NapiEnv, a0 : NapiValue) -> NapiValue

    napi_null

    fn napi_null(env : NapiEnv) -> NapiValue raise NapiError

    napi_object_keys

    fn napi_object_keys(env : NapiEnv, value : NapiValue) -> Array[String] raise NapiError

    napi_object_new

    fn napi_object_new(env : NapiEnv) -> NapiValue raise NapiError

    napi_promise_is

    fn napi_promise_is(env : NapiEnv, value : NapiValue) -> Bool raise NapiError

    Returns whether a value is a JavaScript Promise.

    napi_promise_new

    fn napi_promise_new(env : NapiEnv) -> NapiPromise raise NapiError

    Promise support is available in Node-API v1.

    napi_promise_reject

    fn napi_promise_reject(env : NapiEnv, promise : NapiPromise, reason : NapiValue) -> Unit raise NapiError

    napi_promise_resolve

    fn napi_promise_resolve(env : NapiEnv, promise : NapiPromise, value : NapiValue) -> Unit raise NapiError

    napi_read_json

    fn napi_read_json(env : NapiEnv, value : NapiValue, path : Array[NapiValue]) -> Json raise NapiError

    napi_require_object

    fn napi_require_object(env : NapiEnv, value : NapiValue) -> Unit raise NapiError

    napi_threadsafe_function_acquire

    fn napi_threadsafe_function_acquire(func : NapiThreadsafeFunction) -> NapiTsfnStatus raise NapiError

    napi_threadsafe_function_call

    fn napi_threadsafe_function_call(func : NapiThreadsafeFunction, data : UnmanagedBuffer, mode : NapiTsfnCallMode) -> NapiTsfnStatus raise NapiError

    napi_threadsafe_function_create

    fn napi_threadsafe_function_create(env : NapiEnv, func : NapiValue, async_resource : NapiValue, async_resource_name : NapiValue, max_queue_size : Int, initial_thread_count : Int, finalize_data : UnmanagedBuffer, finalize_cb : UnmanagedBuffer, context : UnmanagedBuffer, call_js_cb : UnmanagedBuffer) -> NapiThreadsafeFunction raise NapiError

    Creates a Threadsafe Function. Callback pointers are opaque unmanaged pointers supplied by a C layer.

    napi_threadsafe_function_release

    fn napi_threadsafe_function_release(func : NapiThreadsafeFunction, mode : NapiTsfnReleaseMode) -> NapiTsfnStatus raise NapiError

    Threadsafe Function lifecycle helper. Threadsafe Functions require N-API v4.

    napi_write_json

    fn napi_write_json(env : NapiEnv, value : Json, depth : Int) -> NapiValue raise NapiError

    roundtrip_bytes

    fn roundtrip_bytes(b : Bytes) -> Bytes

    set_Bool

    fn set_Bool(env : NapiEnv, val : Bool) -> NapiValue raise NapiError

    set_Bytes

    fn set_Bytes(env : NapiEnv, val : Bytes) -> NapiValue raise NapiError

    set_Double

    fn set_Double(env : NapiEnv, val : Double) -> NapiValue raise NapiError

    set_Float

    fn set_Float(env : NapiEnv, value : Float) -> NapiValue raise NapiError

    set_Int

    fn set_Int(env : NapiEnv, val : Int) -> NapiValue raise NapiError

    set_Int64

    fn set_Int64(env : NapiEnv, value : Int64) -> NapiValue raise NapiError

    set_NapiArrayBuffer

    fn set_NapiArrayBuffer(env : NapiEnv, value : NapiArrayBuffer) -> NapiValue raise NapiError

    set_NapiFloat32Array

    fn set_NapiFloat32Array(env : NapiEnv, value : NapiFloat32Array) -> NapiValue raise NapiError

    set_NapiFloat64Array

    fn set_NapiFloat64Array(env : NapiEnv, value : NapiFloat64Array) -> NapiValue raise NapiError

    set_NapiInt32Array

    fn set_NapiInt32Array(env : NapiEnv, value : NapiInt32Array) -> NapiValue raise NapiError

    set_NapiUint32Array

    fn set_NapiUint32Array(env : NapiEnv, value : NapiUint32Array) -> NapiValue raise NapiError

    set_NapiUint8Array

    fn set_NapiUint8Array(env : NapiEnv, value : NapiUint8Array) -> NapiValue raise NapiError

    set_String

    fn set_String(env : NapiEnv, val : String) -> NapiValue raise NapiError

    set_UInt

    fn set_UInt(env : NapiEnv, value : UInt) -> NapiValue raise NapiError

    set_UInt64

    fn set_UInt64(env : NapiEnv, value : UInt64) -> NapiValue raise NapiError

    set_Unit

    fn set_Unit(env : NapiEnv, _val : Unit) -> NapiValue raise NapiError