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
- Variables
- type RGAOptions
- type RGAProtocol
- type RGASnapshot
- type RGAWireFormat
- type Runtime
- func (r *Runtime) ApplyDelta(handle uint64, encoded []byte) error
- func (r *Runtime) Create(replicaID string) (uint64, error)
- func (r *Runtime) Delete(handle uint64, offset, count int) ([]byte, error)
- func (r *Runtime) Drop(handle uint64) bool
- func (r *Runtime) Insert(handle uint64, offset int, value string) ([]byte, error)
- func (r *Runtime) MaxFrameBytes() int
- func (r *Runtime) MaxLocalEditBytes() int
- func (r *Runtime) MaxLocalEditRunes() int
- func (r *Runtime) MaxStringBytes() int
- func (r *Runtime) MaxTags() int
- func (r *Runtime) PendingCount(handle uint64) (int, error)
- func (r *Runtime) Protocol() RGAProtocol
- func (r *Runtime) Replace(handle uint64, offset, count int, value string) ([]byte, error)
- func (r *Runtime) Restore(saved RGASnapshot) (uint64, error)
- func (r *Runtime) Snapshot(handle uint64) (RGASnapshot, error)
- func (r *Runtime) Text(handle uint64) (string, error)
Constants ¶
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 )
Variables ¶
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 ¶
RGAProtocol identifies the framed RGA semantics exported by one runtime.
type RGASnapshot ¶
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 ¶
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 ¶
Create allocates an RGA document owned by replicaID and returns an opaque non-zero handle.
func (*Runtime) Delete ¶
Delete performs one local rune-offset deletion and returns a canonical tombstone frame in the runtime's explicitly selected RGA wire format.
func (*Runtime) Insert ¶
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 ¶
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 ¶
MaxLocalEditBytes reports the UTF-8 input budget for one local insertion. Editors should split larger transactions before calling Insert.
func (*Runtime) MaxLocalEditRunes ¶
MaxLocalEditRunes reports the visible-rune budget for one local insertion.
func (*Runtime) MaxStringBytes ¶
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 ¶
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 ¶
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
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.