accountvalues

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package accountvalues defines the tech-space carrier for account-scoped values and the pure diff that mirrors carrier state into target-space records. See docs/scoped-properties-proposal.md § "Account transport".

Topology: the tech space hosts ONE derived carrier object per target space (bounded DAG, 1:1 lifecycle, one-tree GC on space leave). Its `account_values` dataset holds one record per (objectId, dataset, recordId) of the target space; record fields are the account-scoped paths VERBATIM (`{typeId}.{propId}` for the objects row), so the record's own `_ver` — tech-tree versionIds, including entries retained by $unset — is the version source the mirror replays.

Index

Constants

View Source
const Dataset = "account_values"

Dataset is the carrier dataset name on the per-space carrier object.

View Source
const DeriveSeedPrefix = "builtin:accountValues/"

DeriveSeedPrefix builds the deterministic derive seed for a target space's carrier object: every device of the account mints the same carrier object id for the same target space.

View Source
const HandlerVersion = "accountValuesHandler-v1"

HandlerVersion is the DataVersion stamped on carrier changes. The tech space is account-private (owner-only ACL) — the only writer is the SDK itself; bump if the record shape ever changes incompatibly.

Variables

This section is empty.

Functions

func DeriveSeed

func DeriveSeed(spaceId string) string

DeriveSeed returns the carrier object's derive seed for spaceId.

func Key

func Key(objectId, dataset, recordId string) string

Key builds a carrier record id for a target (objectId, dataset, recordId). Colon is not a valid character in any-sync's content-addressable ids, so the segments can't collide. The objects row is the degenerate case: Key(objId, "objects", objId).

func KeyPrefixForObject

func KeyPrefixForObject(objectId string) string

KeyPrefixForObject returns the id range prefix selecting every carrier record of one target object (any dataset/recordId). Used by the object-delete GC.

func ParseKey

func ParseKey(key string) (objectId, dataset, recordId string, ok bool)

ParseKey splits a carrier record id. ok=false on a malformed key.

func Schema

func Schema() schema.Dataset

Sanity guard used by tests and the techspace registration: the dataset must stay Dynamic (carrier records carry free-form typeId heads).

Types

type Batch

type Batch struct {
	VersionId crdt.VersionId
	Ops       []crdt.Op
}

Batch is one injected apply: every op in it carries the same carrier-tree versionId. The mirror issues one InjectedSet per Batch so per-path gating replays the carrier's converged order EXACTLY — stamping a single max version over many paths would over-claim.

func Diff

func Diff(arena *anyenc.Arena, carrier, target *anyenc.Value, resolve ScopeResolver) []Batch

Diff computes the injected applies that bring the target record's account-scoped paths in line with the carrier record. Pure function — both mirror paths (live carrier events and the on-load state re-mirror) share it, and it's table-testable.

  • carrier value present ⇒ $set at the path's carrier version;
  • carrier value absent but the carrier `_ver` retains (or covers) a version for a path the TARGET still holds ⇒ $unset at that version — this is how unsets reach devices that were offline;
  • unknown propId (resolver) ⇒ skip — Hole A, retried by the next re-mirror once the definition syncs;
  • declared scope ≠ account ⇒ skip (defensive — a buggy or stale carrier entry must not touch synced/local paths);
  • target version ≥ carrier version ⇒ no-op (already applied; the injected gate would drop it anyway, skipping avoids event noise).

Op payloads are deep-cloned onto arena so the result outlives the carrier record's buffer. Batches are ordered by ascending VersionId. Returns nil when the records are already in sync.

type ScopeResolver

type ScopeResolver func(typeId, propId string) (scope schema.Scope, known bool)

ScopeResolver reports the declared scope of a (typeId, propId) pair in the TARGET space. known=false means the definition hasn't synced to this device yet — the diff skips such paths (never drops them: the carrier retains the value and the next re-mirror retries once the schema arrives).

Jump to

Keyboard shortcuts

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