@statesync/persistence / MigrationBuilder
Interface: MigrationBuilder<TFinal>
Defined in: persistence/src/migration.ts:175
Fluent builder interface for constructing a MigrationHandler.
Created via createMigrationBuilder. Allows chaining migration steps and an optional validator before producing the final handler.
Type Parameters
| Type Parameter | Description |
|---|---|
TFinal | The shape of the application state in the final (current) schema version. |
Methods
addMigration()
addMigration<TFrom, TTo>(fromVersion, fn): MigrationBuilder<TFinal>;Defined in: persistence/src/migration.ts:185
Register a migration function for a specific version step.
Type Parameters
| Type Parameter | Description |
|---|---|
TFrom | The data shape of the source version. |
TTo | The data shape of the target version (source version + 1). |
Parameters
| Parameter | Type | Description |
|---|---|---|
fromVersion | number | The version number to migrate from (e.g., 1 for the v1 -> v2 step). |
fn | MigrationFn<TFrom, TTo> | The function that transforms data from TFrom to TTo. |
Returns
MigrationBuilder<TFinal>
This builder instance for method chaining.
build()
build(currentVersion): MigrationHandler<TFinal>;Defined in: persistence/src/migration.ts:204
Produce the finalized MigrationHandler with all registered migrations.
Parameters
| Parameter | Type | Description |
|---|---|---|
currentVersion | number | The current schema version number that the application expects. |
Returns
MigrationHandler<TFinal>
A migration handler ready to be used with loadPersistedSnapshot or migrateData.
withValidator()
withValidator(fn): MigrationBuilder<TFinal>;Defined in: persistence/src/migration.ts:196
Attach a type-guard validator that checks the final migrated data.
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | (data) => data is TFinal | A function that returns true if data is a valid TFinal. |
Returns
MigrationBuilder<TFinal>
This builder instance for method chaining.
