API reference@evolu/commonRelation › RefCountedRelation

Defined in: packages/common/src/Relation.ts:323

Bidirectional relation with a positive retain count for every active pair.

Logical equality and canonical representatives follow the same lookup rules as Relation. The first active representative on each side remains canonical until that value has no active pairs. Increment and decrement return those representatives so callers can reliably handle pair transitions without repeating lookup or canonicalization logic.

Unlike Relation's live iterators, directional and entry reads return snapshots so callers can mutate this relation while iterating. Their order follows first insertion of the current canonical representatives and pairs.

Properties

clear

readonly clear: () => void;

Defined in: packages/common/src/Relation.ts:369

Removes all pair counts and both directional indexes.

decrement

readonly decrement: (a: A, b: B) => {
  a: A;
  b: B;
  count: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
};

Defined in: packages/common/src/Relation.ts:339

Decrements a pair count and returns its canonical values and new count. Decrementing a missing pair is a programmer error checked with assert.

getAs

readonly getAs: (b: B) => readonly A[];

Defined in: packages/common/src/Relation.ts:352

Returns a snapshot of canonical A values related to b.

getBs

readonly getBs: (a: A) => readonly B[];

Defined in: packages/common/src/Relation.ts:355

Returns a snapshot of canonical B values related to a.

getCount

readonly getCount: (a: A, b: B) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;

Defined in: packages/common/src/Relation.ts:349

Returns the pair count, or zero when the pair is absent.

getEntries

readonly getEntries: () => readonly readonly [A, B, number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">][];

Defined in: packages/common/src/Relation.ts:364

Returns a snapshot of every canonical pair and its positive count.

hasA

readonly hasA: (a: A) => boolean;

Defined in: packages/common/src/Relation.ts:358

Returns whether an A value has at least one active pair.

hasB

readonly hasB: (b: B) => boolean;

Defined in: packages/common/src/Relation.ts:361

Returns whether a B value has at least one active pair.

increment

readonly increment: (a: A, b: B) => {
  a: A;
  b: B;
  count: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
};

Defined in: packages/common/src/Relation.ts:325

Increments a pair count and returns its canonical values and new count.