Lightweight key-value storage library for Browser, Node.js, and In-Memory.
MIT License
Bot releases are hidden (Show)
Full Changelog: https://github.com/azu/kvs/compare/v2.1.5...v2.2.0
Published by azu about 1 year ago
reduce install size
Full Changelog: https://github.com/azu/kvs/compare/v2.1.4...v2.1.5
Published by azu about 1 year ago
Full Changelog: https://github.com/azu/kvs/compare/v2.1.3...v2.1.4
Published by azu over 2 years ago
Republish for v2.1.0
Published by azu over 2 years ago
It aim to reduce file size.
Path | Size |
---|---|
packages/env/module/browser.js | 1.06 KB (-22.84% 🔽) |
packages/indexeddb/module/index.js | 1.05 KB (-22.06% 🔽) |
packages/localstorage/module/index.js | 853 B (-27.04% 🔽) |
This library require AsyncIterator support from the beginning.
It means that it require ES2018+ support.
Published by azu over 2 years ago
name
optionPreviously, @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.
@kvs/env
in Node.js
@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.
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 |
1.2.0 require TS 4.1+ because it use Key Remapping in Mapped Types.
SchemaTypes
(async () => {
type Scheme = {
[index:string]: string;
};
const storage = await kvsEnvStorage<Scheme>({
name: "test-data",
version: 1,
});
const value = await storage.set("key", "value");
})();
Published by azu about 4 years ago
First Stable Version.
Published by azu about 4 years ago
Introduce Schema #2
Published by azu about 4 years ago
close()
to interface (a269d1d)