Skip to content

@statesync/persistence


@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 ParameterDescription
TFinalThe shape of the application state in the final (current) schema version.

Methods

addMigration()

ts
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 ParameterDescription
TFromThe data shape of the source version.
TToThe data shape of the target version (source version + 1).

Parameters

ParameterTypeDescription
fromVersionnumberThe version number to migrate from (e.g., 1 for the v1 -> v2 step).
fnMigrationFn<TFrom, TTo>The function that transforms data from TFrom to TTo.

Returns

MigrationBuilder<TFinal>

This builder instance for method chaining.


build()

ts
build(currentVersion): MigrationHandler<TFinal>;

Defined in: persistence/src/migration.ts:204

Produce the finalized MigrationHandler with all registered migrations.

Parameters

ParameterTypeDescription
currentVersionnumberThe current schema version number that the application expects.

Returns

MigrationHandler<TFinal>

A migration handler ready to be used with loadPersistedSnapshot or migrateData.


withValidator()

ts
withValidator(fn): MigrationBuilder<TFinal>;

Defined in: persistence/src/migration.ts:196

Attach a type-guard validator that checks the final migrated data.

Parameters

ParameterTypeDescription
fn(data) => data is TFinalA function that returns true if data is a valid TFinal.

Returns

MigrationBuilder<TFinal>

This builder instance for method chaining.

Released under the MIT License.