Skip to content

oracular / Migrate

Type Alias: Migrate ​

ts
type Migrate = (stored, version) => EngineState;

Defined in: types.ts:359

Turns a stored state of a version this library cannot migrate itself into a current EngineState. Receives the parsed JSON as-is and the version it declares. States saved by oracular 0.1.0 to 0.5.x (versions 1 and 2) never reach it, nor does a state one version newer than STATE_VERSION: deserialize handles both on its own.

Parameters ​

ParameterType
storedunknown
versionnumber

Returns ​

EngineState

Example ​

ts
const migrate: Migrate = (stored, version) => {
  if (version === 0) return { ...(stored as object), version: 1 } as EngineState;
  throw new Error(`unknown state version ${version}`);
};

Released under the MIT License.