Skip to content

v2.0.0

Compare
Choose a tag to compare
@azu azu released this 19 Feb 01:55
· 26 commits to master since this release

2.0.0 (2022-02-19)

Bug Fixes

BREAKING CHANGES

  • storage: storage package sperate storags by name option

Previously, @kvs/storage does not separate key per storage.
This issue cause iteration error like #20

However, It need to change saving storage's key for fixing the issue.
We need to bump it as major update.

Affected Packages

  • @kvs/env in Node.js
    • 📝 Browser is not affected because it uses IndexedDB
  • @kvs/storage
  • @kvs/localstorage
  • @kvs/memorystorage
  • @kvs/node-localstorage
  • @kvs/storage-sync

Previous: storage save value with key

key: value

This PR: storage save value with ${name}.__.${key}.

${name}.__.${key}: value

It means that kvs package can not load value which is saved by previous version.

Migration

You need to write manuall migration code using upgrade.

If you have used @kvs/localstorage, you can write following.
Unfortunately, this migration should use raw localStorage API because @kvs/localstorage can not access the key which is created in kvs 1.x.

import { kvsLocalStorage } from "@kvs/localstorage";
type StorageSchema = {
    a1: string;
    b2: number;
    c3: boolean;
};
const databaseName = "kvs-database";
const storage = kvsStorageSync<StorageSchema>({
    name: databaseName,
    version: 2, // If previous `version` is 1, you need to update the version to 2
    storage: localStorage,
    upgrade({ oldVersion }: { kvs: KVSSync<StorageSchema>; oldVersion: number; newVersion: number }): any {
        if (oldVersion < 2) {
            // manually migration to new key format
            ["a1", "b2", "c3"].forEach((key) => {
                // CAUTION: use raw localStorage for migration
                const item = localStorage.getItem(key);
                if (item) {
                    localStorage.setItem(`${databaseName}.__.${key}`, item);
                }
            });
        }
    }
});
KVS raw localStorage
@kvs/localstorage localStorage API
@kvs/memorystorage NONE
@kvs/node-localstorage node-localstorage package
@kvs/env in Node.js node-localstorage package