Skip to content
SheetForge

Pipeline and sources

Observe what an import produced, add an import source of your own, and drive SheetForge from your own code. This page also lists the surfaces that stay internal.

Watch the pipeline

A cross-product bridge, domain telemetry or a follow-on generator often needs to know what an import produced without re-parsing it. A pipeline observer receives that result. Observing is opt-in.

Implement IPipelineObserver and register it through ISheetForgePipelinePlugin.

using SheetForge.Core.Model;
using SheetForge.Core.Plugins;
 
public sealed class ExampleImportObserver : IPipelineObserver, ISheetForgePipelinePlugin
{
    public void RegisterPipelineObservers(PipelineObserverRegistry observers) => observers.Register(this);
 
    public void OnImportCompleted(PipelineRunView view)
    {
        // view = Success · Tables · Diagnostics · SkippedTabs · EnumTabs — an immutable snapshot.
        if (!view.Success) return;
        // … cache what you need; do not hold the tables ...
    }
}

Observers cannot change the outcome

An observer receives one immutable snapshot and returns nothing. There is deliberately no hook to alter a value or add a diagnostic. Those jobs belong to other contracts.

JobContract
Interpret a valueA cell type. See Add a custom cell type
Report a rule violationA domain validator. See Add a domain validator

Mixing participation into an observation contract would make "observers cannot change the result" false in practice.

When the observer runs

The observer runs once per explicit import cycle, at its end, whether the import succeeded or failed.

It does not run on the pre-flight projection that recomputes while you edit. The projection is the imported data with your staged edits applied. No third-party code is attached to keystroke frequency.

What a failed run reports

A failed run still reports what it parsed. Tables carries the tabs that parsed before validation failed. The quarantine flow uses the same material, so an observer sees a truthful picture of a failed run rather than nothing at all.

Runs that never fire the observer

The observer fires from the import cycle's own completion point. A run that never reaches that point does not fire at all. There are two such gaps.

The first is an import aborted before the pipeline runs. That happens with no active settings, or when the delivery mode's availability check refuses. The second is a codegen→compile leg that a compile error interrupts.

So the observer can miss a run, but it never reports a wrong one. If you need "an import was attempted", pair the observer with the editor-side ImportEvents bus.

Exceptions in an observer

If an observer throws, the exception stays inside that observer, and the reason is collected. The import's output does not change at all.

Future observation points

Future observation points, such as right after parsing or an export cycle, will arrive as sibling capability interfaces. SheetForge discovers them by casting the registered observer. Adding one will not break an implementation written today.

Add a custom import source

A new source joins with zero Core or Editor edits. The source can be a database, a REST endpoint or an in-house format.

Implement ISheetSourceProvider in an Editor assembly. SourceProviderRegistry discovers it through TypeCache. The provider then appears in the Source Mode dropdown of the settings, alongside the built-ins.

What a provider answers

A provider answers four things.

QuestionMemberAnswer
FetchCreateTabSource(settings)An ITabSource that supplies tab name → raw TSV text
Write-backCreateReflectTarget(dispatcher, settings)An ISourceReflectTarget that plugs into the authoring dispatcher
VisibilityGetVisibility(settings)Which settings fields the inspector shows for you
AuthoringCanAuthorfalse for a read-only source

Fetching is async. Environment problems are diagnostics, not exceptions. Partial output is allowed.

To assemble your reflect target, use the dispatcher's public Session, Callbacks and Baselines. Return a target only if your source can be written.

When CanAuthor returns false, the Data Studio disables its editing UI for that source. A Google ExportUrl source behaves the same way.

Provider id

The stable string Id persists in sourceProviderId.

ValueMeaning
"LocalFile", "GoogleSheet"The Ids that the built-ins use
An empty sourceProviderIdResolves to the built-in LocalFile default
An empty IdOpts the provider out of the UI. Useful for test probes

Why providers live in the Editor assembly

Providers live in the Editor assembly because sources are the IO boundary. Keeping IO out of Core preserves its purity, so the Core contracts stay pure C#.

Drive SheetForge from your own code

Beyond the registration contracts, several public entry points exist for code that drives SheetForge rather than extending it. Such code can be a CI script, a build hook, your own inspector button, or a second product that bakes its own assets from the same sheets.

Run a cycle

Call SheetForge.Editor.Pipeline.SheetForgeActions.

SheetForgeActions.RunImport();        // exactly what the toolbar's "Import" does
SheetForgeActions.RunExport();
SheetForgeActions.RunPush();
SheetForgeActions.RunHealthCheck();

Each call is the whole cycle:

  • Settings resolution
  • The delivery mode's availability check
  • Mutual exclusion
  • Confirmation and approval modals
  • The progress bar
  • The codegen→compile→bake resume across the domain reload

There is no half-cycle to assemble, and therefore no gate to skip by accident.

RunImport and RunPush are fire-and-forget. Their bodies are async void, because the editor main thread must not block on network IO. The return is therefore not completion. To learn when the import completes, subscribe to ImportEvents.ImportCompleted.

Push still shows its approval modal, so an unattended script cannot send without a person.

Take the exclusive lock

A custom source provider that writes to its own backend takes the same lock the built-ins take.

if (!SheetForgeActions.TryBeginExclusiveScope(out IDisposable scope)) return;   // something is running
using (scope) { /* write to your source */ }        // Dispose releases; a second Dispose is harmless
// schedule any re-import AFTER the scope closes — the lock is not re-entrant

SheetForgeActions.IsBusy answers the same question without taking anything.

The lock itself stays internal on purpose. If it were public, calling its End() could release somebody else's run. The scope makes that impossible, because only the holder can release.

Finish a write-back

AuthoringDispatcher.FinalizeReflectSuccess(writtenTabs) runs the ending that an ISourceReflectTarget has to reach:

  • Pruning of retained staged edits for the tabs it wrote
  • The ClearUndo confirmation boundary
  • The automatic re-import

The built-in local and Google paths run the same body, so your provider ends identically instead of approximating it. An empty writtenTabs list is a no-op that keeps staging intact.

BuildProjectedTabs() beside it hands you the projection as TSV per tab. That is what you are about to send, so a provider can preview or transform it without writing.

Show the product's sentences in your UI

ImportReportText.Render(report) returns the human-readable report as a string, with nothing written to the console. It lives in Core.Tooling.

SheetForgeActions.RenderReportText(report) is the same thing in the user's current editor language. Use it with AuthoringDispatchCallbacks.RenderReport, so that a second editing tool reports failures in exactly the words the product uses.

Enumerate a baked tab

DefinitionDatabase.RecordsUntyped enumerates a baked tab without knowing its generated type.

foreach (DefinitionDatabase db in myBakedDatabases)
    foreach (object record in db.RecordsUntyped)     // reflect on the fields you care about
        ;

This is the sanctioned path for a second baker, a different product that turns the same sheets into its own assets.

Do not reflect on the private records field. Doing so turns a field name into an undeclared contract that breaks silently the day codegen renames it.

The list is read-only, because the sheet is canonical. On generated code written before this member existed, the list defaults to empty. One re-import emits the override.

Extend the generated classes

Both generated classes are partial. A derived member can live in your own file beside them and survive every re-import. Such a member can be a computed property, an interface implementation or an operator.

Add no serialized fields

The baked ScriptableObject is rebuilt from the sheet on each import. A field that only your part serializes comes back at its default. If a value belongs to the data, it belongs in a column.

What stays closed

The surfaces above are the sanctioned outer edge. The following stay internal, no matter how convenient opening them would look. Each is a trust or integrity boundary, not a convenience boundary.

  • Credentials and signing. The service-account key locator, the JWT/PEM/PKCS8 primitives and the Google access-token provider. Opening them would hand any plugin a bearer token scoped to your spreadsheet.
  • The raw push chain. The push runner, sheet gateways and cell writes. Approval (IPushApprover) is enforced inside that orchestration. A public raw writer would be a sheet write with no approval step.
  • Pre-send verification and the reflect write engines. External code enters through AuthoringDispatcher.Reflect() only. That call passes stale-anchor checks, preflight validation and approval on the way. The writing engine underneath is not a contract.
  • The bake and codegen integrity chain, and the build freshness gate. The chain covers schema fingerprints, the generated-source writer and orphan cleanup. Opening them would make forging or bypassing bake state a one-liner.
  • The ephemeral SO overlay. "The sheet is the source of truth" has exactly one sanctioned exception, the inspector test-edit toggle. It is deliberately not offered as API.

If a workflow seems to need one of these, it needs a feature request, not reflection.

Next steps