-
-
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.
- Loading branch information
Showing
11 changed files
with
265 additions
and
0 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
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,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,46 @@ | ||
# @kvs/env | ||
|
||
Universal library for KVS. | ||
|
||
It detects the running platform and use suitable storage engine. | ||
|
||
## Install | ||
|
||
Install with [npm](https://www.npmjs.com/): | ||
|
||
npm install @kvs/env | ||
|
||
## Usage | ||
|
||
- [ ] Write usage instructions | ||
|
||
## 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,66 @@ | ||
{ | ||
"name": "@kvs/env", | ||
"version": "1.0.0", | ||
"description": "Universal Storage for KVS.", | ||
"keywords": [ | ||
"kvs", | ||
"browser", | ||
"env" | ||
], | ||
"homepage": "https://github.com/azu/kvs/tree/master/packages/env/", | ||
"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/node.js", | ||
"module": "module/node.js", | ||
"types": "lib/node.d.ts", | ||
"browser": "lib/browser.js", | ||
"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": "mocha \"test/**/*.ts\"", | ||
"watch": "tsc -p . --watch" | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"singleQuote": false, | ||
"tabWidth": 4, | ||
"trailingComma": "none" | ||
}, | ||
"dependencies": { | ||
"@kvs/indexeddb": "^1.0.0", | ||
"@kvs/node-localstorage": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jsdevtools/karma-config": "^3.1.7", | ||
"@types/mocha": "^8.0.1", | ||
"@types/node": "^14.0.27", | ||
"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,9 @@ | ||
import { JsonValue, KvsStorage } from "@kvs/storage"; | ||
import { kvsIndexedDB } from "@kvs/indexeddb"; | ||
import { KvsEnvStorageOptions } from "./share"; | ||
|
||
export const kvsEnvStorage = async <K extends string, V extends JsonValue>( | ||
options: KvsEnvStorageOptions<K, V> | ||
): Promise<KvsStorage<K, V>> => { | ||
return kvsIndexedDB(options); | ||
}; |
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,9 @@ | ||
import { JsonValue, KvsStorage } from "@kvs/storage"; | ||
import { kvsLocalStorage } from "@kvs/node-localstorage"; | ||
import { KvsEnvStorageOptions } from "./share"; | ||
|
||
export const kvsEnvStorage = async <K extends string, V extends JsonValue>( | ||
options: KvsEnvStorageOptions<K, V> | ||
): Promise<KvsStorage<K, V>> => { | ||
return kvsLocalStorage(options); | ||
}; |
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,6 @@ | ||
import { JsonValue, KVSStorageKey } from "@kvs/storage"; | ||
import { KVS } from "@kvs/types"; | ||
import { KvsLocalStorageOptions } from "@kvs/node-localstorage"; | ||
|
||
export type KvsEnvStorage<K extends KVSStorageKey, V extends JsonValue> = KVS<K, V>; | ||
export type KvsEnvStorageOptions<K extends KVSStorageKey, V extends JsonValue> = KvsLocalStorageOptions<K, V>; |
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,51 @@ | ||
import { kvsEnvStorage } from "../src/node"; | ||
import { createKVSTestCase } from "@kvs/common-test-case"; | ||
|
||
const databaseName = "kvs-test"; | ||
const kvsTestCase = createKVSTestCase( | ||
(options) => | ||
kvsEnvStorage({ | ||
...options, | ||
name: databaseName, | ||
debug: true | ||
}), | ||
{ | ||
setTestDataList: [ | ||
{ | ||
name: "string", | ||
value: "str" | ||
}, | ||
{ | ||
name: "number", | ||
value: 42 | ||
}, | ||
{ | ||
name: "boolean", | ||
value: false | ||
}, | ||
{ | ||
name: "object", | ||
value: { | ||
prop: "propValue" | ||
}, | ||
type: "object" | ||
} | ||
] | ||
} | ||
); | ||
const deleteAllDB = async () => { | ||
if (!kvsTestCase.ref.current) { | ||
return; | ||
} | ||
try { | ||
await kvsTestCase.ref.current.clear(); | ||
// await kvs.dropInstance(); | ||
} catch (error) { | ||
console.error("deleteAllDB", error); | ||
} | ||
}; | ||
describe("@kvs/localstorage", () => { | ||
before(deleteAllDB); | ||
afterEach(deleteAllDB); | ||
kvsTestCase.run(); | ||
}); |
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,11 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": false, | ||
"noEmit": true | ||
}, | ||
"include": [ | ||
"../src/**/*", | ||
"./**/*" | ||
] | ||
} |
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,36 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Basic Options */ | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"newLine": "LF", | ||
"outDir": "./lib/", | ||
"target": "ES2015", | ||
"sourceMap": true, | ||
"declaration": true, | ||
"jsx": "preserve", | ||
"lib": [ | ||
"esnext", | ||
"dom" | ||
], | ||
/* Strict Type-Checking Options */ | ||
"strict": true, | ||
/* Additional Checks */ | ||
/* Report errors on unused locals. */ | ||
"noUnusedLocals": true, | ||
/* Report errors on unused parameters. */ | ||
"noUnusedParameters": true, | ||
/* Report error when not all code paths in function return a value. */ | ||
"noImplicitReturns": true, | ||
/* Report errors for fallthrough cases in switch statement. */ | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
".git", | ||
"node_modules" | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"outDir": "./module/", | ||
} | ||
} |