MigrationChain
Defined in: src/persistence/migration/MigrationChain.ts:52
Linear chain of MigrationSteps for a single manifest, terminating at
a currentVersion known to the running code. On upcast(stored), the
chain locates the step starting at stored.version and applies steps
forward until it reaches currentVersion.
The chain is intentionally narrow: one manifest, one current version,
one linear path. Multiple types → multiple chains, kept inside an
EventAdapter.fromJournal switch by manifest.
const chain = MigrationChain.for
chain.upcast({ manifest: 'BankAccount.Deposited', version: 1, payload })
returns a DepositedV2.
Errors:
- manifest mismatch →
MigrationError stored.version > currentVersion(downgrade) →MigrationError- no step available at the current cursor before
currentVersionis reached (chain gap) →MigrationErrorwith the gap printed.
Type Parameters
Section titled “Type Parameters”Current
Section titled “Current”Current
Accessors
Section titled “Accessors”currentVersion
Section titled “currentVersion”Get Signature
Section titled “Get Signature”get currentVersion():
number
Defined in: src/persistence/migration/MigrationChain.ts:131
Latest version this chain knows how to produce.
Returns
Section titled “Returns”number
manifest
Section titled “manifest”Get Signature
Section titled “Get Signature”get manifest():
string
Defined in: src/persistence/migration/MigrationChain.ts:128
Manifest this chain is bound to.
Returns
Section titled “Returns”string
Methods
Section titled “Methods”add<
F,T>(step):MigrationChain<Current>
Defined in: src/persistence/migration/MigrationChain.ts:71
Append an upcaster. Returns this for chaining.
Type Parameters
Section titled “Type Parameters”F
T
Parameters
Section titled “Parameters”MigrationStep<F, T>
Returns
Section titled “Returns”MigrationChain<Current>
addDown()
Section titled “addDown()”addDown<
F,T>(step):MigrationChain<Current>
Defined in: src/persistence/migration/MigrationChain.ts:103
Append a downcaster — the inverse of MigrationStep.
Required when the actor is going to be configured with a
writeVersion lower than currentVersion (#7). Steps move
backward: fromVersion > toVersion.
chain.addDown({ fromVersion: 2, toVersion: 1, downcast: (e: DepositedV2): DepositedV1 => { const { currency, …rest } = e; void currency; return rest; }, });
Type Parameters
Section titled “Type Parameters”F
T
Parameters
Section titled “Parameters”DowncastStep<F, T>
Returns
Section titled “Returns”MigrationChain<Current>
downcast()
Section titled “downcast()”downcast(
current,targetVersion):unknown
Defined in: src/persistence/migration/MigrationChain.ts:177
Convert a current-shape value down to targetVersion for a
write-with-old-shape rolling deploy (#7). Walks the registered
downcasters from currentVersion toward targetVersion.
Errors:
targetVersion > currentVersion→MigrationError(we’re already at or above the target; user should calltoJournalAtwithversion: currentVersion).targetVersion < 1→MigrationError.- chain gap (no downcaster for the current cursor) →
MigrationErrorwith the missing step printed.
Parameters
Section titled “Parameters”current
Section titled “current”Current
targetVersion
Section titled “targetVersion”number
Returns
Section titled “Returns”unknown
toJournalAt()
Section titled “toJournalAt()”toJournalAt(
current,writeVersion?):OutboundFrame
Defined in: src/persistence/migration/MigrationChain.ts:213
Build an OutboundFrame for the write path at writeVersion
(defaults to currentVersion). Convenience that combines the
downcast + frame-shape — exactly what migratingAdapter calls
from its toJournal.
Parameters
Section titled “Parameters”current
Section titled “current”Current
writeVersion?
Section titled “writeVersion?”number
Returns
Section titled “Returns”OutboundFrame
upcast()
Section titled “upcast()”upcast(
stored):Current
Defined in: src/persistence/migration/MigrationChain.ts:134
Apply the chain to a stored frame, returning a current-version value.
Parameters
Section titled “Parameters”stored
Section titled “stored”StoredFrame
Returns
Section titled “Returns”Current
staticfor<C>(manifest,currentVersion):MigrationChain<C>
Defined in: src/persistence/migration/MigrationChain.ts:66
Build an empty chain for manifest whose latest known version is currentVersion.
Type Parameters
Section titled “Type Parameters”C
Parameters
Section titled “Parameters”manifest
Section titled “manifest”string
currentVersion
Section titled “currentVersion”number
Returns
Section titled “Returns”MigrationChain<C>