StorageSnapshot class

What an app holds in NyStorage and Backpack, in a form that can be kept in a file or a seeder and put back into an app.

export in metro live takes one with capture; seed <file> and an exported seeder's importSnapshot() put it back with apply.

Storage values are written the way Dart types them: 7, 1.5, true, 'Jane', null, or a map or list for JSON. A value is written as {'type': ..., 'value': ...} only when the literal alone can't rebuild the storage envelope Nylo keeps it in:

  • model for a saved Model, so NyStorage.read<User>() still decodes it
  • raw for a value Nylo didn't write as an envelope, put back byte for byte
  • a ttl (seconds left) for a value that expires
  • json for a JSON object that has a type key of its own

Backpack values are written as JSON. An object is tagged with its class name - every Model, and every other class the app registered a model decoder for - and apply rebuilds it through that decoder, so Backpack.read<User>() gets a User back and not the map it was written from.

Constructors

StorageSnapshot({Map<String, Object?> storage = const {}, Map<String, Object?> backpack = const {}, List<Map<String, String>> skipped = const []})
Creates a snapshot of storage and backpack values.
const
StorageSnapshot.fromJson(Map<Object?, Object?> json)
Reads a snapshot from json, as written by toJson or held by an exported seeder. Only storage and backpack are read; both are optional.
factory

Properties

backpack Map<String, Object?>
The Backpack values, by key.
final
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether the snapshot holds nothing.
no setter
length int
How many values the snapshot holds.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
skipped List<Map<String, String>>
What capture left out, each as {store, key, reason}.
final
storage Map<String, Object?>
The storage values, by key.
final

Methods

apply() Future<int>
Writes every value into storage and Backpack, and returns how many were written.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object?>
The snapshot as JSON: {nylo, storage, backpack}.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

capture({List<String> only = const [], List<String> except = const [], bool backpack = true}) Future<StorageSnapshot>
Reads every storage and Backpack value from the running app.

Constants

formatVersion → const int
The version of the snapshot format, written as nylo by toJson.
storageTypes → const Set<String>
The type names a tagged storage value can have.