Skip to content

JavaScript/TypeScript Native Runtime Notes

Native backend hosts use role packages:

RolePackageMain API
Client@nnrp/native-clientClient API
Server@nnrp/native-serverServer API

TCP, QUIC, IPC, and WebSocket are not hidden inside the role packages. Install the corresponding @nnrp/transport-* packages for the carriers allowed to participate in selection.

Each role manifest advertises only its own session capability: @nnrp/native-client advertises client.session, while @nnrp/native-server advertises server.session. Its transport list is derived from the installed providers; role packages do not claim native.loader or infer carriers from a generic runtime library.

Native FFI Binding

Role packages accept explicit FFI bindings for controlled integration and tests. Packaged transport artifacts are owned by the transport packages.

Role bindings and transport bindings are separate contracts. NnrpNativeFfiBinding owns client or server runtime operations after a carrier has been selected. Carrier packages use NnrpNativeTransportBinding for endpoint probing and framed connection/listener lifecycle. A role binding must not impersonate a transport binding, and a transport package must not fall back to a JavaScript socket implementation when its Rust artifact is missing.

Client NnrpNativeFfiBinding

PropertyTypeRequiredDescription
mode"native-addon" | "node-ffi" | "deno-ffi" | "nano-ffi" | "test"NoBinding implementation label.
runtimeCapabilitiesfunctionNoReturns native runtime capability probe data.
validateSubmitfunctionNoValidates and normalizes a submit at the ABI edge.
submitResultCompactfunctionNoCoarse submit/result hot path.
submitNoWaitfunctionNoCoarse no-wait submit path.
sendRuntimeFramefunctionNoCoarse Preview4 control/object/cache frame path.
patchSessionfunctionNoCoarse session patch path.
awaitEvents(request: NnrpNativeEventBatchRequest) => readonly NnrpNativeClientEventBatchItem[] | Promise<readonly NnrpNativeClientEventBatchItem[]>NoCoarse, session-routed batch event polling path.
closefunctionNoBinding cleanup hook.

NnrpNativeClientEventBatchItem is the closed batch envelope below:

FieldTypeRequiredSemantics
sessionIdnumberYesNegotiated, non-zero u32 session identity used to route the event.
eventNnrpClientEventYesExactly one runtime or lifecycle client-role event.

When item.event.type === "runtime", item.sessionId must equal item.event.event.header.sessionId; a mismatch is a protocol error. When item.event.type === "lifecycle", the event has no wire header and is routed only by item.sessionId. Bindings must not infer its session from the currently waiting consumer or manufacture a zero-filled header.

Cancellation and abort are protocol frames sent through sendRuntimeFrame; they are not standalone FFI methods. Published role packages do not expose a package-owned direct Deno loader or a self-echo benchmark binding. Production calls run through the selected transport package's client/server role carrier; an explicit NnrpNativeFfiBinding is a controlled integration and test seam only.

Server NnrpNativeFfiBinding

PropertyTypeRequiredDescription
mode"native-addon" | "node-ffi" | "deno-ffi" | "nano-ffi" | "test"NoBinding implementation label.
runtimeCapabilitiesfunctionNoReturns native runtime capability probe data.
sendRuntimeFramefunctionNoCoarse Preview4 control/object/cache frame path.
acceptfunctionNoAccepts a server session.
receivefunctionNoReceives the next typed server event.
closefunctionNoBinding cleanup hook.

Artifact Boundary

PackageNative artifact ownership
@nnrp/native-clientNone; client role only.
@nnrp/native-serverNone; server role only.
@nnrp/transport-tcpTCP native transport artifacts.
@nnrp/transport-quicQUIC native transport artifacts.
@nnrp/transport-ipcIPC native transport artifacts.
@nnrp/transport-websocketWebSocket native transport artifacts.

NNRP Documentation