Skip to content
SheetForge

Validation and edges

This page lists the Core types for domain validation, reference scanning, edge declarations and the reference graph index.

Namespaces

SectionsNamespace
Domain validationSheetForge.Core.Validation
Reference scanning, edge contributors, edge authoring capabilitiesSheetForge.Core.Validation / .Edges
Reference graph indexSheetForge.Core.Edges

Domain validation

TypeRole
IDomainValidatorA cross-column or cross-tab rule
DomainValidationContextWhat a rule reads and where it reports

IDomainValidator

A rule reports each violation to ctx.Errors as a DomainRuleViolation with all 4 elements.

  • string Name
  • Validate(DomainValidationContext)

For the elements and a worked example, see Add a domain validator.

DomainValidationContext

  • Tables maps a tab to its SheetTable.
  • KeyIndices
  • AssetKeys is null when asset validation is skipped.
  • Errors
  • ReferenceTables and ReferenceKeyIndices hold the tabs of other workbooks.

Tables holds this run's own tabs. The run may look keys up against the tabs of other workbooks, but it never validates them or generates their code.

ReferenceTables and ReferenceKeyIndices are empty, never null, when there are no such tabs. The four-argument constructor leaves them empty. The six-argument constructor takes them. Tabs from other workbooks explains how a rule looks keys up in them.

Reference scanning

TypeRole
ReferenceScanner (static)Single source of truth for reference-occurrence enumeration
RefKeyKind (enum)Which key space a reference is matched against, if any
ReferenceOccurrence (struct)One occurrence
ReferenceOccurrenceKind (enum)The kind of an occurrence

ReferenceScanner

  • Scan(tables)
  • ScanTable
  • ScanField
  • IsReferenceField(TypeToken)
  • GetReferencedTab(TypeToken)
  • GetReferenceKind(TypeToken) returns a RefKeyKind.
  • GetReferenceKind(TypeToken, tables) is the table-aware overload.

GetReferencedTab and GetReferenceKind are the two reference predicates.

Reference predicates

GetReferencedTab(TypeToken) is the one predicate every consumer asks: is this a reference, and to where? It answers for four forms:

  • RecordId@Tab
  • IntId@Tab, the integer key space
  • The inside of a wrapper
  • A custom type stamped IsCustomReference

Because every consumer asks this one predicate, opting in once, by marking the type as a custom reference, turns them all on at once. For IntId@Tab, one widening of this predicate does the same.

GetReferenceKind(TypeToken) says whether the reference compares against the string or the integer key space. Rename propagation, the dropdown and the picker use the answer to branch correctly.

RefKeyKind

ValueMeaning
NoneNot a reference
StringKeyMatched against the string key space, as RecordId@Tab is
IntKeyMatched against the integer key space, as IntId@Tab is

ReferenceScanner.GetReferenceKind returns this enum, and consumers branch on it. The enum is append-only.

Key space of a custom reference

A core reference states its own space (RecordId / IntId). A referencing custom type has no notation to say it in, because MyType@Tab is the only spelling. Its space is derived from the target tab's identity.

Target tabKey space
Has a RecordId self keyString
Has IntId aloneInteger
Unknown tab, or null tablesString, as the fallback

The fallback is the same answer the token-only overload gives.

This derivation lets an existing IReferencingCellType implementation aim at an IntId-keyed tab without a single line changed.

ReferenceOccurrence

  • Kind
  • FromTab
  • RowNumber
  • ColumnNumber
  • FieldName
  • TargetTab
  • TargetId
  • ToCoordinate()

ReferenceOccurrenceKind

  • Scalar
  • ListElement
  • ExplicitDefault
  • WrapperElement
  • CustomElement

CustomElement is a reference that an IRefBearingValue declared out of its own notation. It carries cell-level coordinates, because the inner layout belongs to that type.

The enum is append-only, so existing values keep their meaning.

Edge contributors

TypeRole
IEdgeContributorDeclares edges the scanner cannot see
EdgeSpecOne edge
EdgeContributionContextThe read-only input of a contributor

IEdgeContributor

A contributor produces no diagnostics.

  • string Name
  • ContributeEdges(EdgeContributionContext, ICollection<EdgeSpec>)

EdgeSpec

  • FromTab / FromRecordId / ToTab / ToRecordId
  • FieldName, optional
  • PayloadTab / PayloadRecordId, optional, for record-edges
  • Label, optional

EdgeContributionContext

The context holds read-only Tables and KeyIndices. It has no error collector, because edges are not validation.

Edge authoring capabilities

Every interface in this section is an opt-in capability. Canvas editing contracts and Nodes, slots and tokens show each one in use.

TypeRole
IAuthorableEdgeContributorMakes a contributor's edge editable on the record canvas
IBatchAuthorableEdgeContributorPlans a connect or disconnect as a list of cell writes
IEdgeTokenEditorMakes the leftover of a token editable in the wire inspector
EdgeTokenDescriptionWhat one token is and how to edit its leftover
IVirtualNodeFactoryCanvas "create" gestures that are not a new sheet row
VirtualNodeKind (struct)One creatable kind
IEdgeSlotDeclarerPorts a (virtual) node opens without needing a live edge
DeclaredSlot (struct)One declared slot
EdgeAuthoringContextThe planning input
EdgeCellWrite (struct)The plan

IAuthorableEdgeContributor

An IEdgeContributor may also implement this capability so its edge can be edited on the record canvas.

  • bool TryPlanConnect(EdgeAuthoringContext, fromTab, fromRecordId, toTab, toRecordId, out EdgeCellWrite)
  • bool TryPlanDisconnect(EdgeAuthoringContext, RecordEdge, out EdgeCellWrite)

When a method returns false, nothing is staged and the affordance is disabled with a reason. Both methods run inside try/catch.

IBatchAuthorableEdgeContributor

This capability is a sibling of IAuthorableEdgeContributor, not an inheritance. Its connect and disconnect plans are a list of cell writes. It serves data where one gesture must change several paired cells together.

  • bool TryPlanConnectMany(EdgeAuthoringContext, fromTab, fromRecordId, toTab, toRecordId, out IReadOnlyList<EdgeCellWrite>)
  • bool TryPlanDisconnectMany(EdgeAuthoringContext, RecordEdge, out IReadOnlyList<EdgeCellWrite>)

The whole list is staged as one undo step or not at all.

Singular contributors keep working as the fallback. When one class implements both interfaces, batch wins.

IEdgeTokenEditor

An IEdgeContributor may also implement this capability so the leftover of its token can be edited in the wire inspector. The leftover is everything that is not the key.

  • bool TryDescribeToken(EdgeAuthoringContext, RecordEdge, out EdgeTokenDescription)
  • bool TryPlanSetModifier(EdgeAuthoringContext, RecordEdge, string newModifier, out EdgeCellWrite)

Both methods read the same cell. An edge knows where it points, not how it is spelled today.

When a method returns false, the row is hidden or disabled. Both methods run inside try/catch.

EdgeTokenDescription

  • TokenText is the fragment to highlight.
  • ModifierText
  • HasModifier
  • ModifierLabel
  • IsChoice
  • Options / OptionLabels

new EdgeTokenDescription(tokenText) means no leftover, so no row is drawn. The choice constructor falls back to free text when the option list is empty.

IVirtualNodeFactory

  • IReadOnlyList<VirtualNodeKind> KindsFor(EdgeAuthoringContext, tab, recordId)
  • bool TryPlanCreate(EdgeAuthoringContext, tab, recordId, VirtualNodeKind, out IReadOnlyList<EdgeCellWrite>)

KindsFor is called per menu build, so keep it light. When TryPlanCreate returns false, the session is untouched.

A plan cannot target a record created in the same gesture.

VirtualNodeKind

  • Id is returned verbatim on pick.
  • Label is already-translated menu text. A / nests.
  • IsUsable

The struct is null-safe and default-safe.

IEdgeSlotDeclarer

  • IReadOnlyList<DeclaredSlot> DeclareSlots(EdgeAuthoringContext, nodeTab, nodeRecordId)

Declared slots join the connect menu, the port picker and the card's port rows. The method is called per render, so implementations must be light and side-effect free.

DeclaredSlot

  • FieldName is unique per node. It must match the contributor edge's FieldName for wires to anchor.
  • TargetTab
  • IsList
  • IsUsable

The struct is null-safe and default-safe.

EdgeAuthoringContext

  • Tables
  • string CellText(tab, recordId, field)

CellText returns the cell as it reads now, which is the baseline plus the staged edits. The second of two links made in a row therefore sees the first.

EdgeCellWrite

  • TabName
  • RecordId
  • FieldName
  • NewRawText, where empty means clear
  • IsAddressable

A write is addressed by key, not row number.

Reference graph index

The index is an immutable snapshot. It merges core-scanned references and contributor edges into one model, indexed both ways.

The index is display material. It never produces diagnostics. For problems, the only source of truth is the Diagnostics of the projection, which is the baseline with the staged edits applied.

TypeRole
RecordEdge (struct)One edge, a value
RecordEdgeOrigin (enum)Where an edge comes from
ReferenceIndex (sealed class)The snapshot

RecordEdge

  • RecordEdgeOrigin Origin
  • FromTab
  • FromRecordId is empty for field-level edges.
  • FieldName
  • RowNumber / ColumnNumber are 1-based. 0 means field or tab level.
  • ToTab
  • ToRecordId is the intended id even when unresolved.
  • bool IsDangling is fixed at build time.
  • Label
  • PayloadTab / PayloadRecordId serve record-edges.

RecordEdgeOrigin

ValueSourceLevel
CoreReferenceRead from a RecordId@Tab cellHas coordinates
ContributorDeclared by an IEdgeContributorRecord-level

ReferenceIndex

  • static Build(tables, keyIndices, contributorEdges, codeRegistries, extraKeys = null)
  • AllEdges
  • OutEdges(tab, recordId) / InEdges(tab, recordId) never return null.
  • int InCount(tab, recordId)
  • bool TryGetRowKey(tab, rowNumber, out recordId)
  • DanglingEdges

AllEdges has a deterministic order: from-tab Ordinal → row → column → occurrence.

Build arguments

The last three arguments of Build may be null.

extraKeys maps a tab to keys that exist but are not parsed yet. Rows that an editing tool just staged are an example. Links to those keys are not drawn as broken.

Next steps