> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/migration/migration.getoriginstorage.md).

# 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.

```ts
Migration.getOriginStorage(): Promise<{
  previous: OriginStorageDump;
  current: OriginStorageDump;
}>;
```

`previous`and `current`have the same structure. `previous`contains the previous `web.tossmini.com` Origin value, `current`contains the current `apps.tossmini.com` Origin value.

```ts
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;
  }>;
}
```

`OriginStorageDump`can be imported directly from the package.

```ts
import type { OriginStorageDump } from "@apps-in-toss/web-framework";
```

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.errors`is 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.

```ts
import { Migration } from "@apps-in-toss/web-framework";

const SETTINGS_KEY = "my-app:settings";

async function migrateSettings() {
  const { previous, current } = await Migration.getOriginStorage();

  if (previous.errors.length > 0 || current.errors.length > 0) {
    console.error("Could not read all storages.", {
      previous: previous.errors,
      current: current.errors,
    });
    return;
  }

  const previousValue = previous.localStorage[SETTINGS_KEY];
  const currentValue = current.localStorage[SETTINGS_KEY];

  if (currentValue == null && previousValue != null) {
    localStorage.setItem(SETTINGS_KEY, previousValue);
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/migration/migration.getoriginstorage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
