Entity / foldkit-entity/laws

Laws

namespace · packages/entity/src/laws.ts:911

const Laws = { check, show, facts, transition, law }

In the guides

Members

Laws.check

function · packages/entity/src/laws.ts:495

check<const W extends ReadonlyArray<LawEntry>>(options: {
  readonly writes: W & {
    readonly [K in keyof W]: Checked<W[K]>
  }
  readonly operators?: MemoryOperators | undefined
}): LawReport

Checks each transition against each invariant of its Entity, and the arrows its writes make between the Entity's declared states. An entry is a declared write ({ name, write }, as Mutation.write returns), or a transition known by its footprint ({ name, entity, footprint }). Pure, and what it finds is a report, never a fault; it throws only for two entries of one name, which its report could not tell apart.

Laws.show

function · packages/entity/src/laws.ts:715

show(report: LawReport): string

The report as text: each Entity's states and arrows, then each pair, then what it stands on.

Laws.facts

function · packages/entity/src/laws.ts:787

facts(report: LawReport): LawFacts

The report as graph facts: a Law per invariant, a Transition per write in a pair or an arrow (one judged against nothing and moving no state has no law to keep), a State per local state, what each law reads and each transition writes, each arrow's from and to, and a keeps edge per transition and law whose every pair carries an Enumerated record. A write's own ensures is no law of its Entity and is left out. An Unknown footprint writes every member, so it has a writes edge to each member a law of its Entity reads: every edge a rule of the graph can ask of.

Laws.transition

const · packages/entity/src/laws.ts:255

transition: (entry: { readonly name: string }) => string

Laws.law

const · packages/entity/src/laws.ts:256

law: (invariant: { readonly id: string; readonly entity: string }) => string