Validation and edges
This page lists the Core types for domain validation, reference scanning, edge declarations and the reference graph index.
Namespaces
| Sections | Namespace |
|---|---|
| Domain validation | SheetForge.Core.Validation |
| Reference scanning, edge contributors, edge authoring capabilities | SheetForge.Core.Validation / .Edges |
| Reference graph index | SheetForge.Core.Edges |
Domain validation
| Type | Role |
|---|---|
IDomainValidator | A cross-column or cross-tab rule |
DomainValidationContext | What a rule reads and where it reports |
IDomainValidator
A rule reports each violation to ctx.Errors as a DomainRuleViolation with all 4 elements.
string NameValidate(DomainValidationContext)
For the elements and a worked example, see Add a domain validator.
DomainValidationContext
Tablesmaps a tab to itsSheetTable.KeyIndicesAssetKeysis null when asset validation is skipped.ErrorsReferenceTablesandReferenceKeyIndiceshold 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
| Type | Role |
|---|---|
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)ScanTableScanFieldIsReferenceField(TypeToken)GetReferencedTab(TypeToken)GetReferenceKind(TypeToken)returns aRefKeyKind.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@TabIntId@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
| Value | Meaning |
|---|---|
None | Not a reference |
StringKey | Matched against the string key space, as RecordId@Tab is |
IntKey | Matched 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 tab | Key space |
|---|---|
Has a RecordId self key | String |
Has IntId alone | Integer |
Unknown tab, or null tables | String, 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
KindFromTabRowNumberColumnNumberFieldNameTargetTabTargetIdToCoordinate()
ReferenceOccurrenceKind
ScalarListElementExplicitDefaultWrapperElementCustomElement
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
| Type | Role |
|---|---|
IEdgeContributor | Declares edges the scanner cannot see |
EdgeSpec | One edge |
EdgeContributionContext | The read-only input of a contributor |
IEdgeContributor
A contributor produces no diagnostics.
string NameContributeEdges(EdgeContributionContext, ICollection<EdgeSpec>)
EdgeSpec
FromTab/FromRecordId/ToTab/ToRecordIdFieldName, optionalPayloadTab/PayloadRecordId, optional, for record-edgesLabel, 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.
| Type | Role |
|---|---|
IAuthorableEdgeContributor | Makes a contributor's edge editable on the record canvas |
IBatchAuthorableEdgeContributor | Plans a connect or disconnect as a list of cell writes |
IEdgeTokenEditor | Makes the leftover of a token editable in the wire inspector |
EdgeTokenDescription | What one token is and how to edit its leftover |
IVirtualNodeFactory | Canvas "create" gestures that are not a new sheet row |
VirtualNodeKind (struct) | One creatable kind |
IEdgeSlotDeclarer | Ports a (virtual) node opens without needing a live edge |
DeclaredSlot (struct) | One declared slot |
EdgeAuthoringContext | The 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
TokenTextis the fragment to highlight.ModifierTextHasModifierModifierLabelIsChoiceOptions/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
Idis returned verbatim on pick.Labelis 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
FieldNameis unique per node. It must match the contributor edge'sFieldNamefor wires to anchor.TargetTabIsListIsUsable
The struct is null-safe and default-safe.
EdgeAuthoringContext
Tablesstring 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
TabNameRecordIdFieldNameNewRawText, where empty means clearIsAddressable
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.
| Type | Role |
|---|---|
RecordEdge (struct) | One edge, a value |
RecordEdgeOrigin (enum) | Where an edge comes from |
ReferenceIndex (sealed class) | The snapshot |
RecordEdge
RecordEdgeOrigin OriginFromTabFromRecordIdis empty for field-level edges.FieldNameRowNumber/ColumnNumberare 1-based. 0 means field or tab level.ToTabToRecordIdis the intended id even when unresolved.bool IsDanglingis fixed at build time.LabelPayloadTab/PayloadRecordIdserve record-edges.
RecordEdgeOrigin
| Value | Source | Level |
|---|---|---|
CoreReference | Read from a RecordId@Tab cell | Has coordinates |
Contributor | Declared by an IEdgeContributor | Record-level |
ReferenceIndex
- static
Build(tables, keyIndices, contributorEdges, codeRegistries, extraKeys = null) AllEdgesOutEdges(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
- IR model and errors
The tables, tokens, values and errors these contracts read and report.
- Plugin contracts
The registries that accept validators and edge contributors.
- Validators and edges
Write a domain validator and an edge contributor.
- Canvas editing contracts
Make your own edges editable on the canvas.