Documentation
Table of Contents

Interface IMappingStore

Namespace
IntentSharp.Mapping
Assembly
IntentSharp.dll

Where compiled mappings are kept: one row per namespace, key and revision. Implement it on storage your processes share, so that every process serves the same mapping for a key; InMemoryMappingStore keeps rows in one process. Nothing is shared across namespaces.

public interface IMappingStore
Extension Methods

Remarks

A store assigns Revision and Status when it writes a row, and RetiredAt and RetiredReason when it retires one; the values a caller passes for them are ignored. Revisions count from 1 per namespace and key, and a new revision is one more than the highest the key has, whatever its status. The row a write returns is the row as stored.

A store needs no per-use writes and never deletes a retired row, so an audit can name the mapping behind any output. Rows hold no input values. The library checks every row it reads again before it runs it (namespace, key, status, versions, kind, shapes, ops, converters, and the fit of the steps to the shapes), so a store of your own needs no such checks of its own; a row that fails them is refused, never run and never compiled over.

Those checks do not prove that a row's steps do what its intent says, and the golden samples are not run again when a row is reused. Whoever can write the store decides how every process that reads it maps data, so the store is a trust boundary: limit write access to it, and keep it out of any target a model can write.

Methods

ActivateAsync(string, string, int, MappingRetiredReason, CancellationToken)

In one transaction: retires the active revision of the key, if there is one, with reason and makes the pending revision active. Returns the active row.

AddIfAbsentAsync(CompiledMapping, CancellationToken)

First writer wins: when the key has no active revision, stores mapping as the next revision (1 for a new key) with the status Active. Returns the active row: this one, or the one another writer stored first.

AddPendingAsync(CompiledMapping, CancellationToken)

Stores pending as the next revision with the status Pending and leaves the active revision as it is, for a replacement held until someone activates it. Returns the row as stored.

GetActiveAsync(string, string, CancellationToken)

The active revision of a key, or null when the key has none. A retired or pending revision is never returned.

ListAsync(string, CancellationToken)

Every revision of every key in the namespace, retired and pending ones included, ordered by key (ordinal) and then revision.

ReplaceAsync(CompiledMapping, MappingRetiredReason, CompiledMapping, CancellationToken)

In one transaction: retires retiring with reason only if that revision is still active, and then stores replacement as the next revision with the status Active. When another writer replaced retiring first, nothing is written and that writer's row is returned; when the key has no active revision at all, replacement is stored as the active one. Returns the active row.

RetireAsync(string, string, int, MappingRetiredReason, CancellationToken)

Retires an active or pending revision with reason, for example a stored row the library refused. Returns true when the revision was active or pending and is now retired, false when it does not exist or was retired already.

TryTakeRecompileAsync(string, string, int, TimeSpan, CancellationToken)

The persisted per-key cap on replacements, shared by every process on the store: takes one of limit slots in the current window of length window, which starts at the first slot taken after the previous window ended. Returns true when a slot was taken, false when the window's slots are used up or limit is 0 or less.