Migration.getOriginStorage
Feature description
Previous web.tossmini.com Origin and current apps.tossmini.com Bring over Origin's localStorage, IndexedDB, and OPFS data together. Move or merge the imported data directly according to the app's rules.
Type
There are no parameters.
Migration.getOriginStorage(): Promise<{
previous: OriginStorageDump;
current: OriginStorageDump;
}>;previousand currenthave the same structure. previouscontains the previous web.tossmini.com Origin value, currentcontains the current apps.tossmini.com Origin value.
interface OriginStorageDump {
/** The Origin this snapshot was read from. */
origin: string;
/** All keys in localStorage and their original string values. */
localStorage: Record<string, string | null>;
/** The list of IndexedDB databases in Origin. */
indexedDB: Array<{
/** The database name. */
name: string;
/** The database version. */
version: number;
/** The list of object stores in the database. */
objectStores: Array<{
/** The object store name. */
name: string;
/** The keyPath of the object store. null for out-of-line keys. */
keyPath: string | string[] | null;
/** Indicates whether the object store auto-generates keys. */
autoIncrement: boolean;
/** The list of indexes defined on the object store. */
indexes: Array<{
name: string;
keyPath: string | string[];
multiEntry: boolean;
unique: boolean;
}>;
/** All records stored in the object store. */
records: Array<{
/** The record key read from the cursor. */
key: IDBValidKey;
/** The primary key of the object store the record points to. */
primaryKey: IDBValidKey;
/** The stored value. Validate it against the app's types before use. */
value: unknown;
}>;
}>;
}>;
/** The list of directories and files relative to the OPFS root. */
opfs: {
/** The relative path from the root. The path does not start with a slash. */
directories: string[];
files: Array<{
/** The file's relative path from the root. */
path: string;
/** The file's MIME type. It may be an empty string if unknown. */
type: string;
/** The last modified time. Milliseconds since the Unix epoch. */
lastModified: number;
/** The file's raw bytes. String files can be read with TextDecoder. */
data: ArrayBuffer;
}>;
};
/** Failure information by storage. If the array is empty, all three storages were read. */
errors: Array<{
storage: "localStorage" | "indexedDB" | "opfs";
message: string;
}>;
}OriginStorageDumpcan be imported directly from the package.
If the call itself fails, the Promise is rejected. If only some storages could not be read, the Promise resolves and the cause is previous.errors or current.errorsis put in.
Example code
The following example migrates the previous localStorage value only when there are no lookup errors and the current Origin has no value. If both sides have values, it keeps the current value.
Was this helpful?