wasm

package
v1.0.29 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 10 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 = crdt.SemanticsVersionRGA

	// 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 = crdt.SemanticsVersionRGARun
)
View Source
const (
	// RichTextStateTypeID and RichTextDeltaTypeID identify the only rich-text
	// v1 frames accepted by the browser runtime.
	RichTextStateTypeID uint64 = crdt.TypeIDRichTextState
	RichTextDeltaTypeID uint64 = crdt.TypeIDRichTextDelta

	// RichTextSemanticsVersion must be bound to the rich-text renderer schema
	// in the authenticated manifest. It is not an RGA run-v2 protocol.
	RichTextSemanticsVersion uint64 = richtext.SemanticsVersion
)

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 RichTextOptions added in v1.0.28

type RichTextOptions struct {
	Document          richtext.Options
	Decoder           frame.DecoderLimits
	MaxLocalEditRunes int
	MaxLocalEditBytes int
	MaxLocalEditorOps int
}

RichTextOptions bounds untrusted rich-text frames and one local editor transaction. They are intentionally browser-sized rather than inheriting the process-wide library defaults.

func DefaultRichTextOptions added in v1.0.28

func DefaultRichTextOptions() RichTextOptions

DefaultRichTextOptions returns the rich-text v1 browser/WebView limits.

type RichTextProtocol added in v1.0.28

type RichTextProtocol struct {
	StateTypeID      uint64
	DeltaTypeID      uint64
	SemanticsVersion uint64
}

RichTextProtocol identifies the one rich-text contract exported to a browser/WebView. Attribute schemas remain manifest-selected application policy; this value identifies only the CRDT wire and merge semantics.

type RichTextRuntime added in v1.0.28

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

RichTextRuntime owns bounded browser rich-text document handles.

func NewRichTextRuntime added in v1.0.28

func NewRichTextRuntime(options RichTextOptions) (*RichTextRuntime, error)

NewRichTextRuntime constructs one bounded rich-text v1 browser runtime.

func (*RichTextRuntime) ApplyDelta added in v1.0.28

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

ApplyDelta validates then joins one untrusted rich-text v1 frame.

func (*RichTextRuntime) ApplyEditorDelta added in v1.0.28

func (r *RichTextRuntime) ApplyEditorDelta(handle uint64, operations []richtext.EditorOperation) ([]byte, error)

ApplyEditorDelta turns one local rich-editor transaction into exactly one canonical rich-text frame. The core document preflights complete text and formatting state before it applies anything.

func (*RichTextRuntime) Create added in v1.0.28

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

Create allocates one empty rich-text document for replicaID.

func (*RichTextRuntime) Drop added in v1.0.28

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

Drop releases one document handle.

func (*RichTextRuntime) MaxAttributesPerOperation added in v1.0.28

func (r *RichTextRuntime) MaxAttributesPerOperation() int

MaxAttributesPerOperation reports the configured retained-format fan-out.

func (*RichTextRuntime) MaxFrameBytes added in v1.0.28

func (r *RichTextRuntime) MaxFrameBytes() int

MaxFrameBytes reports the largest rich-text frame accepted by this runtime.

func (*RichTextRuntime) MaxLocalEditBytes added in v1.0.28

func (r *RichTextRuntime) MaxLocalEditBytes() int

MaxLocalEditBytes reports the combined inserted bytes accepted per editor transaction.

func (*RichTextRuntime) MaxLocalEditRunes added in v1.0.28

func (r *RichTextRuntime) MaxLocalEditRunes() int

MaxLocalEditRunes reports the combined inserted runes accepted per editor transaction.

func (*RichTextRuntime) MaxLocalEditorOps added in v1.0.28

func (r *RichTextRuntime) MaxLocalEditorOps() int

MaxLocalEditorOps reports the accepted operation count for one local transaction.

func (*RichTextRuntime) MaxStringBytes added in v1.0.28

func (r *RichTextRuntime) MaxStringBytes() int

MaxStringBytes reports the maximum attribute, replica, and editor string size.

func (*RichTextRuntime) MaxTags added in v1.0.28

func (r *RichTextRuntime) MaxTags() int

MaxTags reports the largest retained tag set accepted from one frame.

func (*RichTextRuntime) Protocol added in v1.0.28

func (r *RichTextRuntime) Protocol() RichTextProtocol

Protocol returns the exact rich-text v1 frame contract emitted and accepted.

func (*RichTextRuntime) Restore added in v1.0.28

func (r *RichTextRuntime) Restore(saved RichTextSnapshot) (uint64, error)

Restore validates and installs one atomic rich-text persistence unit.

func (*RichTextRuntime) Snapshot added in v1.0.28

func (r *RichTextRuntime) Snapshot(handle uint64) (RichTextSnapshot, error)

Snapshot returns a complete, bounded rich-text persistence unit.

func (*RichTextRuntime) Spans added in v1.0.28

func (r *RichTextRuntime) Spans(handle uint64) ([]richtext.Span, error)

Spans returns a caller-owned presentation projection. It does not authorize attribute values; renderers must still enforce their manifest schema.

type RichTextSnapshot added in v1.0.28

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

RichTextSnapshot is the complete persistence unit for one browser document. State, frontier, and HLC clock must be written atomically before restoring a replica ID. It deliberately has the same data contract as RGASnapshot but can only contain rich-text v1 frames.

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) AnchorAt added in v1.0.28

func (r *Runtime) AnchorAt(handle uint64, offset int) (text.Anchor, error)

AnchorAt returns a stable Position/Tag-backed boundary for a visible rune offset. It is local/editor metadata, not a framed RGA operation. Hosts may send it only through an authenticated, bounded presence contract.

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) ResolveAnchor added in v1.0.28

func (r *Runtime) ResolveAnchor(handle uint64, anchor text.Anchor) (int, error)

ResolveAnchor maps a retained Position/Tag-backed boundary back to the current visible rune offset. A compacted marker fails closed with text.ErrAnchorGone; callers must clear or refresh the editor selection.

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