wasm

package
v1.0.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package wasm contains host-neutral state used by the browser-facing Wasm command. Keeping it separate from syscall/js lets the protocol boundary run under the normal Go test and race-detector toolchains.

Index

Constants

View Source
const (
	// RGAStateTypeID and RGADeltaTypeID are the only framed payloads accepted
	// by a scalar-v1 runtime. RGA remains an explicitly negotiated protocol;
	// accepting a frame here never authenticates its sender.
	RGAStateTypeID uint64 = crdt.TypeIDRGAState
	RGADeltaTypeID uint64 = crdt.TypeIDRGADelta

	// RGASemanticsVersion identifies scalar RGA v1 semantics.
	RGASemanticsVersion uint64 = 1

	// RGARunStateTypeID and RGARunDeltaTypeID identify the compact run-v2
	// protocol used by new Go RGA replication groups.
	RGARunStateTypeID uint64 = crdt.TypeIDRGARunState
	RGARunDeltaTypeID uint64 = crdt.TypeIDRGARunDelta

	// RGARunSemanticsVersion identifies compact RGA run-v2 semantics.
	RGARunSemanticsVersion uint64 = 2
)

Variables

View Source
var (
	ErrInvalidOptions  = errors.New("wasm: invalid RGA runtime options")
	ErrUnknownDocument = errors.New("wasm: unknown RGA document")
	ErrHandleExhausted = errors.New("wasm: document handle space exhausted")
)

Functions

This section is empty.

Types

type RGAOptions

type RGAOptions struct {
	Text              text.Options
	Decoder           frame.DecoderLimits
	MaxLocalEditRunes int
	MaxLocalEditBytes int
	WireFormat        RGAWireFormat
}

RGAOptions bounds both externally received frames and retained document state. These are deliberately smaller than the library defaults because a browser tab or WebView is commonly exposed to untrusted network peers.

func DefaultRGAOptions

func DefaultRGAOptions() RGAOptions

DefaultRGAOptions returns the legacy scalar-v1 browser/WebView runtime limits. It is retained for an explicitly negotiated migration group.

func DefaultRunRGAOptions

func DefaultRunRGAOptions() RGAOptions

DefaultRunRGAOptions returns the browser/WebView limits for the compact run-v2 protocol used by new Go RGA replication groups. Applications still need transport-level request limits before a Uint8Array is allocated.

type RGAProtocol

type RGAProtocol struct {
	StateTypeID      uint64
	DeltaTypeID      uint64
	SemanticsVersion uint64
}

RGAProtocol identifies the framed RGA semantics exported by one runtime.

type RGASnapshot

type RGASnapshot struct {
	State    []byte
	Frontier map[string]crdt.Tag
	Clock    clock.State
}

RGASnapshot is the complete browser persistence unit. State, Frontier, and Clock must be persisted atomically; storing only State can reuse a mutation tag when a replica ID is restored after a restart.

type RGAWireFormat

type RGAWireFormat uint8

RGAWireFormat selects exactly one separately negotiated RGA frame contract. A runtime never accepts both formats because their compatibility is a manifest-level decision, not a best-effort decoder choice.

const (
	RGAWireFormatV1 RGAWireFormat = iota + 1
	RGAWireFormatRunV2
)

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime owns browser-document handles. Individual RGA values remain independently concurrency-safe, while the registry itself is protected so native tests can exercise it with the race detector.

func NewRuntime

func NewRuntime(options RGAOptions) (*Runtime, error)

NewRuntime creates a bounded RGA client runtime.

func (*Runtime) ApplyDelta

func (r *Runtime) ApplyDelta(handle uint64, encoded []byte) error

ApplyDelta validates and joins one untrusted canonical delta frame for the runtime's selected RGA format. A malformed, mismatched, or over-limit frame leaves the document unchanged.

func (*Runtime) Create

func (r *Runtime) Create(replicaID string) (uint64, error)

Create allocates an RGA document owned by replicaID and returns an opaque non-zero handle.

func (*Runtime) Delete

func (r *Runtime) Delete(handle uint64, offset, count int) ([]byte, error)

Delete performs one local rune-offset deletion and returns a canonical tombstone frame in the runtime's explicitly selected RGA wire format.

func (*Runtime) Drop

func (r *Runtime) Drop(handle uint64) bool

Drop releases one document handle. It returns whether a document existed.

func (*Runtime) Insert

func (r *Runtime) Insert(handle uint64, offset int, value string) ([]byte, error)

Insert performs one local rune-offset insertion and returns a canonical delta frame in the runtime's explicitly selected RGA wire format.

func (*Runtime) MaxFrameBytes

func (r *Runtime) MaxFrameBytes() int

MaxFrameBytes reports the largest encoded frame accepted by this runtime. The JS boundary checks this before copying an incoming Uint8Array into Go.

func (*Runtime) MaxLocalEditBytes

func (r *Runtime) MaxLocalEditBytes() int

MaxLocalEditBytes reports the UTF-8 input budget for one local insertion. Editors should split larger transactions before calling Insert.

func (*Runtime) MaxLocalEditRunes

func (r *Runtime) MaxLocalEditRunes() int

MaxLocalEditRunes reports the visible-rune budget for one local insertion.

func (*Runtime) MaxStringBytes

func (r *Runtime) MaxStringBytes() int

MaxStringBytes reports the UTF-8 byte budget for a replica ID in a frame or persistence unit. The JS boundary uses it before copying untrusted snapshot metadata into Go.

func (*Runtime) MaxTags

func (r *Runtime) MaxTags() int

MaxTags reports the largest retained tag set accepted from one frame. The JS snapshot parser uses this to bound its own object traversal before Go receives a reconstructed persistence unit.

func (*Runtime) PendingCount

func (r *Runtime) PendingCount(handle uint64) (int, error)

PendingCount reports accepted out-of-order nodes waiting for a parent.

func (*Runtime) Protocol

func (r *Runtime) Protocol() RGAProtocol

Protocol returns the one RGA frame contract accepted and emitted by this runtime. The application must bind this value to its authenticated manifest.

func (*Runtime) Replace added in v1.0.24

func (r *Runtime) Replace(handle uint64, offset, count int, value string) ([]byte, error)

Replace performs one atomic local editor replacement and returns one framed delta. It preflights the combined insert/tombstone delta before committing so a rejected editor transaction cannot leave a half-applied local change.

func (*Runtime) Restore

func (r *Runtime) Restore(saved RGASnapshot) (uint64, error)

Restore validates one atomic persistence unit under the runtime limits, restores its clock/frontier, and returns a new opaque document handle.

func (*Runtime) Snapshot

func (r *Runtime) Snapshot(handle uint64) (RGASnapshot, error)

Snapshot returns a cloned, complete persistence unit under the runtime's output limits. Incomplete out-of-order state is deliberately not persisted.

func (*Runtime) Text

func (r *Runtime) Text(handle uint64) (string, error)

Text returns the current visible document projection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL