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 RichTextOptions
- type RichTextProtocol
- type RichTextRuntime
- func (r *RichTextRuntime) AnchorAt(handle uint64, offset int) (text.Anchor, error)
- func (r *RichTextRuntime) AnchorRangeAt(handle uint64, start, end int) (text.AnchorRange, error)
- func (r *RichTextRuntime) ApplyDelta(handle uint64, encoded []byte) error
- func (r *RichTextRuntime) ApplyEditorDelta(handle uint64, operations []richtext.EditorOperation) ([]byte, error)
- func (r *RichTextRuntime) Create(replicaID string) (uint64, error)
- func (r *RichTextRuntime) Drop(handle uint64) bool
- func (r *RichTextRuntime) MarshalAnchor(anchor text.Anchor) ([]byte, error)
- func (r *RichTextRuntime) MarshalAnchorRange(anchors text.AnchorRange) ([]byte, error)
- func (r *RichTextRuntime) MaxAnchorBytes() int
- func (r *RichTextRuntime) MaxAttributesPerOperation() int
- func (r *RichTextRuntime) MaxFrameBytes() int
- func (r *RichTextRuntime) MaxLocalEditBytes() int
- func (r *RichTextRuntime) MaxLocalEditRunes() int
- func (r *RichTextRuntime) MaxLocalEditorOps() int
- func (r *RichTextRuntime) MaxStringBytes() int
- func (r *RichTextRuntime) MaxTags() int
- func (r *RichTextRuntime) Protocol() RichTextProtocol
- func (r *RichTextRuntime) ResolveAnchor(handle uint64, anchor text.Anchor) (int, error)
- func (r *RichTextRuntime) ResolveAnchorRange(handle uint64, anchors text.AnchorRange) (start, end int, err error)
- func (r *RichTextRuntime) Restore(saved RichTextSnapshot) (uint64, error)
- func (r *RichTextRuntime) Snapshot(handle uint64) (RichTextSnapshot, error)
- func (r *RichTextRuntime) Spans(handle uint64) ([]richtext.Span, error)
- func (r *RichTextRuntime) UnmarshalAnchor(encoded []byte) (text.Anchor, error)
- func (r *RichTextRuntime) UnmarshalAnchorRange(encoded []byte) (text.AnchorRange, error)
- type RichTextSnapshot
- type Runtime
- func (r *Runtime) AnchorAt(handle uint64, offset int) (text.Anchor, error)
- 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) ResolveAnchor(handle uint64, anchor text.Anchor) (int, 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 // RGAPackedStateTypeID and RGAPackedDeltaTypeID identify the explicitly // negotiated compact packed-v3 protocol. It is distinct from both scalar-v1 // and run-v2, so a runtime never accepts it as a fallback. RGAPackedStateTypeID uint64 = crdt.TypeIDRGAPackedState RGAPackedDeltaTypeID uint64 = crdt.TypeIDRGAPackedDelta // RGAPackedSemanticsVersion identifies compact packed RGA v3 semantics. RGAPackedSemanticsVersion uint64 = crdt.SemanticsVersionRGAPacked )
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 ¶
Functions ¶
This section is empty.
Types ¶
type RGAOptions ¶
type RGAOptions struct {
Text text.Options
Decoder frame.DecoderLimits
MaxLocalEditRunes int
MaxLocalEditBytes int
WireFormat RGAWireFormat
WireFormatVersion uint64
}
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 DefaultPackedRGAFrameV2Options ¶ added in v1.0.32
func DefaultPackedRGAFrameV2Options() RGAOptions
DefaultPackedRGAFrameV2Options returns browser/WebView limits for an explicitly negotiated packed-v3 group using compression-aware outer frame v2. It is not wire-compatible with the default packed-v3 artifact.
func DefaultPackedRGAOptions ¶ added in v1.0.31
func DefaultPackedRGAOptions() RGAOptions
DefaultPackedRGAOptions returns the browser/WebView limits for the explicitly negotiated packed RGA v3 protocol. Applications still need transport-level request limits before a Uint8Array is allocated.
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
WireFormatVersion uint64
}
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 RGAWireFormatPackedV3 )
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
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) AnchorAt ¶ added in v1.0.32
AnchorAt returns one stable rich-text boundary for a visible rune offset. The anchor may be persisted through MarshalAnchor but is never inserted into a rich-text state/delta frame.
func (*RichTextRuntime) AnchorRangeAt ¶ added in v1.0.32
func (r *RichTextRuntime) AnchorRangeAt(handle uint64, start, end int) (text.AnchorRange, error)
AnchorRangeAt captures two rich-text boundaries from one document revision. The ordering is preserved for selections and comment ranges.
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) MarshalAnchor ¶ added in v1.0.32
func (r *RichTextRuntime) MarshalAnchor(anchor text.Anchor) ([]byte, error)
MarshalAnchor encodes one relative position under this runtime's browser metadata limits. The caller must bind the bytes to an authenticated document and group before storing or sending them.
func (*RichTextRuntime) MarshalAnchorRange ¶ added in v1.0.32
func (r *RichTextRuntime) MarshalAnchorRange(anchors text.AnchorRange) ([]byte, error)
MarshalAnchorRange encodes a selection or comment range under this runtime's browser metadata limits.
func (*RichTextRuntime) MaxAnchorBytes ¶ added in v1.0.32
func (r *RichTextRuntime) MaxAnchorBytes() int
MaxAnchorBytes reports the maximum versioned anchor-range metadata payload accepted by this browser runtime. It is deliberately separate from CRDT frame size because relative positions are host-owned metadata, not frames.
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) ResolveAnchor ¶ added in v1.0.32
ResolveAnchor resolves one retained rich-text boundary to a visible rune offset. A compacted boundary fails closed with text.ErrAnchorGone.
func (*RichTextRuntime) ResolveAnchorRange ¶ added in v1.0.32
func (r *RichTextRuntime) ResolveAnchorRange(handle uint64, anchors text.AnchorRange) (start, end int, err error)
ResolveAnchorRange resolves both retained boundaries from one current document projection.
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.
func (*RichTextRuntime) UnmarshalAnchor ¶ added in v1.0.32
func (r *RichTextRuntime) UnmarshalAnchor(encoded []byte) (text.Anchor, error)
UnmarshalAnchor decodes one bounded relative-position metadata value. It does not claim that the value belongs to any particular document; callers must resolve it through a chosen handle.
func (*RichTextRuntime) UnmarshalAnchorRange ¶ added in v1.0.32
func (r *RichTextRuntime) UnmarshalAnchorRange(encoded []byte) (text.AnchorRange, error)
UnmarshalAnchorRange decodes a bounded selection or comment range. Resolve it through the intended document before relying on the offsets.
type RichTextSnapshot ¶ added in v1.0.28
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
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 ¶
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) ResolveAnchor ¶ added in v1.0.28
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.