-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage-sync): add storage-sync package (#11)
* feat(storage-sync): add storage-sync package * fix package homepage * chore: remove sync.ts
- Loading branch information
Showing
17 changed files
with
625 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require": [ | ||
"ts-node-test-register" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
## [0.2.1](https://github.com/azu/kvs/compare/v0.2.0...v0.2.1) (2020-08-22) | ||
|
||
**Note:** Version bump only for package @kvs/storage | ||
|
||
|
||
|
||
|
||
|
||
# [0.2.0](https://github.com/azu/kvs/compare/v0.1.0...v0.2.0) (2020-08-08) | ||
|
||
|
||
### Features | ||
|
||
* **@kvs/indexeddb:** migrate Schema Type ([ec143e2](https://github.com/azu/kvs/commit/ec143e27d174271f4ce45f657e1ae644ef01591c)) | ||
* **@kvs/localstorage:** migrate to Schema type ([0c84640](https://github.com/azu/kvs/commit/0c84640c1c1d28955c60ca83d8a01bdce936d9ef)) | ||
* **storage:** use Schema interface ([2560aae](https://github.com/azu/kvs/commit/2560aae28d642c8f2e8ee5920dc1cc15f7c8c3f6)) | ||
|
||
|
||
|
||
|
||
|
||
# 0.1.0 (2020-08-08) | ||
|
||
|
||
### Bug Fixes | ||
|
||
* add deps ([b72e91a](https://github.com/azu/kvs/commit/b72e91aaa2487d69d44200ef0a11cc0b5f8fb904)) | ||
|
||
|
||
### Features | ||
|
||
* **@kvs/node-localstorage:** add node implementation ([5160012](https://github.com/azu/kvs/commit/516001286c96ac85cb54d55fbba62549d6d7eb0e)) | ||
* add `close()` to interface ([a269d1d](https://github.com/azu/kvs/commit/a269d1dda6ce63388771e6fa4d897a26f284b72c)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2020 azu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# @kvs/storage-sync | ||
|
||
Storage-like for KVS. | ||
|
||
You can inject Storage object like localStorage, sessionStorage to this storage. | ||
|
||
[@kvs/storage] is async version, but [@kvs/storage-sync] is sync version. | ||
|
||
## Feature | ||
|
||
- Synchronize version [@kvs/storage] | ||
- Support `[Symbol.iterator]` instead of `[Symbol.asyncIterator]` | ||
- Injectable `localStorage` or `sessionStorage` | ||
|
||
## Install | ||
|
||
Install with [npm](https://www.npmjs.com/): | ||
|
||
npm install @kvs/storage-sync | ||
|
||
## Usage | ||
|
||
```ts | ||
import assert from "assert"; | ||
import { kvsStorageSync } from "@kvs/storage"; | ||
(() => { | ||
type StorageSchema = { | ||
a1: string; | ||
b2: number; | ||
c3: boolean; | ||
}; | ||
const storage = kvsStorageSync<StorageSchema>({ | ||
name: "test", | ||
version: 1, | ||
storage: localStorage | ||
}); | ||
storage.set("a1", "string"); | ||
storage.set("b2", 42); | ||
storage.set("c3", false); | ||
const a1 = storage.get("a1"); | ||
const b2 = storage.get("b2"); | ||
const c3 = storage.get("c3"); | ||
assert.strictEqual(a1, "string"); | ||
assert.strictEqual(b2, 42); | ||
assert.strictEqual(c3, false); | ||
})(); | ||
``` | ||
|
||
## Changelog | ||
|
||
See [Releases page](https://github.com/azu/kvs/releases). | ||
|
||
## Running tests | ||
|
||
Install devDependencies and Run `npm test`: | ||
|
||
npm test | ||
|
||
## Contributing | ||
|
||
Pull requests and stars are always welcome. | ||
|
||
For bugs and feature requests, [please create an issue](https://github.com/azu/kvs/issues). | ||
|
||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -am 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D | ||
|
||
## Author | ||
|
||
- [github/azu](https://github.com/azu) | ||
- [twitter/azu_re](https://twitter.com/azu_re) | ||
|
||
## License | ||
|
||
MIT © azu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = require("@jsdevtools/karma-config")({ | ||
tests: ["src/**/*.ts", "test/**/*.test.ts"], | ||
browsers: Boolean(process.env.CI) | ||
? { | ||
firefox: true, | ||
chrome: true, | ||
safari: false | ||
// MSEdge does not work correctly | ||
// edge: false, | ||
} | ||
: { | ||
// manually attach to test bed | ||
firefox: false, | ||
chrome: false, | ||
edge: false, | ||
safari: false | ||
}, | ||
config: { | ||
webpack: { | ||
resolve: { | ||
extensions: [".js", ".jsx", ".ts", ".tsx"] | ||
}, | ||
mode: "development", | ||
module: { | ||
rules: [{ test: /\.ts$/, use: "ts-loader" }] | ||
} | ||
}, | ||
client: { | ||
mocha: { | ||
timeout: 5 * 1000 // 5 sec | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "@kvs/storage-sync", | ||
"version": "0.2.1", | ||
"description": "Storage(localStorage, sessionStorage) helper for KVS.", | ||
"keywords": [ | ||
"kvs", | ||
"browser", | ||
"localstorage" | ||
], | ||
"homepage": "https://github.com/azu/kvs/tree/master/packages/storage-sync/", | ||
"bugs": { | ||
"url": "https://github.com/azu/kvs/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/azu/kvs.git" | ||
}, | ||
"license": "MIT", | ||
"author": "azu", | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "module/index.js", | ||
"types": "lib/index.d.ts", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"files": [ | ||
"bin/", | ||
"lib/", | ||
"module" | ||
], | ||
"scripts": { | ||
"build": "tsc -p . && tsc --project ./tsconfig.module.json", | ||
"clean": "rimraf lib/ module/", | ||
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", | ||
"prepublish": "npm run clean && npm run build", | ||
"test": "karma start --single-run", | ||
"watch": "tsc -p . --watch" | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"singleQuote": false, | ||
"tabWidth": 4, | ||
"trailingComma": "none" | ||
}, | ||
"dependencies": { | ||
"@kvs/types": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"@kvs/common-test-case": "^0.2.1", | ||
"@jsdevtools/karma-config": "^3.1.7", | ||
"@types/mocha": "^8.0.1", | ||
"@types/node": "^14.0.27", | ||
"karma": "^5.1.1", | ||
"karma-cli": "^2.0.0", | ||
"lerna": "^3.22.1", | ||
"mocha": "^8.1.1", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"ts-loader": "^8.0.2", | ||
"typescript": "^3.9.7" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Based on https://github.com/sindresorhus/type-fest/blob/master/source/basic.d.ts | ||
/** | ||
Matches a JSON object. | ||
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`. | ||
*/ | ||
export type JsonObject = { [Key in string]?: JsonValue }; | ||
|
||
/** | ||
Matches a JSON array. | ||
*/ | ||
export interface JsonArray extends Array<JsonValue> {} | ||
|
||
/** | ||
Matches any valid JSON value. | ||
*/ | ||
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export { | ||
kvsStorageSync, | ||
// internal | ||
deleteItem, | ||
setItem, | ||
getItem, | ||
clearItem, | ||
createIterator, | ||
hasItem, | ||
KvsStorageSync, | ||
KVSStorageKey, | ||
KvsStorageSyncOptions | ||
} from "./storage"; | ||
export { JsonValue, JsonArray, JsonObject } from "./JSONValue"; |
Oops, something went wrong.