v1.2.2 - Fix network error on background, auto-retry streaming with reconnect
This commit is contained in:
19
node_modules/@kvs/node-localstorage/LICENSE
generated
vendored
Normal file
19
node_modules/@kvs/node-localstorage/LICENSE
generated
vendored
Normal file
@@ -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.
|
||||
48
node_modules/@kvs/node-localstorage/README.md
generated
vendored
Normal file
48
node_modules/@kvs/node-localstorage/README.md
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# @kvs/node-localstorage
|
||||
|
||||
Node.js localstorage for [KVS](https://github.com/azu/kvs).
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [lmaccherone/node-localstorage: A drop-in substitute for the browser native localStorage API that runs on node.js.](https://github.com/lmaccherone/node-localstorage)
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
npm install @kvs/node-localstorage
|
||||
|
||||
## Usage
|
||||
|
||||
See <https://github.com/azu/kvs#usage>
|
||||
|
||||
## 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
|
||||
12
node_modules/@kvs/node-localstorage/lib/index.d.ts
generated
vendored
Normal file
12
node_modules/@kvs/node-localstorage/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { JsonValue, KvsStorage } from "@kvs/storage";
|
||||
import { KVS, KVSOptions } from "@kvs/types";
|
||||
export type KvsLocalStorageSchema = {
|
||||
[index: string]: JsonValue;
|
||||
};
|
||||
export type KvsLocalStorage<Schema extends KvsLocalStorageSchema> = KVS<Schema>;
|
||||
export type KvsLocalStorageOptions<Schema extends KvsLocalStorageSchema> = KVSOptions<Schema> & {
|
||||
kvsVersionKey?: string;
|
||||
storeFilePath?: string;
|
||||
storeQuota?: number;
|
||||
};
|
||||
export declare const kvsLocalStorage: <Schema extends KvsLocalStorageSchema>(options: KvsLocalStorageOptions<Schema>) => Promise<KvsStorage<Schema>>;
|
||||
31
node_modules/@kvs/node-localstorage/lib/index.js
generated
vendored
Normal file
31
node_modules/@kvs/node-localstorage/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.kvsLocalStorage = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const storage_1 = require("@kvs/storage");
|
||||
const promises_1 = __importDefault(require("node:fs/promises"));
|
||||
// @ts-ignore
|
||||
const node_localstorage_1 = require("node-localstorage");
|
||||
// @ts-ignore
|
||||
const app_root_path_1 = __importDefault(require("app-root-path"));
|
||||
const kvsLocalStorage = async (options) => {
|
||||
const defaultCacheDir = path_1.default.join(app_root_path_1.default.toString(), ".cache");
|
||||
if (!options.storeFilePath) {
|
||||
await promises_1.default.mkdir(defaultCacheDir, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
const saveFilePath = options.storeFilePath
|
||||
? options.storeFilePath
|
||||
: path_1.default.join(defaultCacheDir, "kvs-node-localstorage");
|
||||
const storeQuota = options.storeQuota ? options.storeQuota : 5 * 1024 * 1024;
|
||||
return (0, storage_1.kvsStorage)({
|
||||
...options,
|
||||
storage: new node_localstorage_1.LocalStorage(saveFilePath, storeQuota)
|
||||
});
|
||||
};
|
||||
exports.kvsLocalStorage = kvsLocalStorage;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kvs/node-localstorage/lib/index.js.map
generated
vendored
Normal file
1
node_modules/@kvs/node-localstorage/lib/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,0CAAiE;AAEjE,gEAAkC;AAClC,aAAa;AACb,yDAAiD;AACjD,aAAa;AACb,kEAAoC;AAW7B,MAAM,eAAe,GAAG,KAAK,EAChC,OAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,uBAAO,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,kBAAE,CAAC,KAAK,CAAC,eAAe,EAAE;YAC5B,SAAS,EAAE,IAAI;SAClB,CAAC,CAAC;IACP,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa;QACtC,CAAC,CAAC,OAAO,CAAC,aAAa;QACvB,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAC7E,OAAO,IAAA,oBAAU,EAAC;QACd,GAAG,OAAO;QACV,OAAO,EAAE,IAAI,gCAAY,CAAC,YAAY,EAAE,UAAU,CAAC;KACtD,CAAC,CAAC;AACP,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}
|
||||
12
node_modules/@kvs/node-localstorage/module/index.d.ts
generated
vendored
Normal file
12
node_modules/@kvs/node-localstorage/module/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { JsonValue, KvsStorage } from "@kvs/storage";
|
||||
import { KVS, KVSOptions } from "@kvs/types";
|
||||
export type KvsLocalStorageSchema = {
|
||||
[index: string]: JsonValue;
|
||||
};
|
||||
export type KvsLocalStorage<Schema extends KvsLocalStorageSchema> = KVS<Schema>;
|
||||
export type KvsLocalStorageOptions<Schema extends KvsLocalStorageSchema> = KVSOptions<Schema> & {
|
||||
kvsVersionKey?: string;
|
||||
storeFilePath?: string;
|
||||
storeQuota?: number;
|
||||
};
|
||||
export declare const kvsLocalStorage: <Schema extends KvsLocalStorageSchema>(options: KvsLocalStorageOptions<Schema>) => Promise<KvsStorage<Schema>>;
|
||||
24
node_modules/@kvs/node-localstorage/module/index.js
generated
vendored
Normal file
24
node_modules/@kvs/node-localstorage/module/index.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import path from "path";
|
||||
import { kvsStorage } from "@kvs/storage";
|
||||
import fs from "node:fs/promises";
|
||||
// @ts-ignore
|
||||
import { LocalStorage } from "node-localstorage";
|
||||
// @ts-ignore
|
||||
import appRoot from "app-root-path";
|
||||
export const kvsLocalStorage = async (options) => {
|
||||
const defaultCacheDir = path.join(appRoot.toString(), ".cache");
|
||||
if (!options.storeFilePath) {
|
||||
await fs.mkdir(defaultCacheDir, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
const saveFilePath = options.storeFilePath
|
||||
? options.storeFilePath
|
||||
: path.join(defaultCacheDir, "kvs-node-localstorage");
|
||||
const storeQuota = options.storeQuota ? options.storeQuota : 5 * 1024 * 1024;
|
||||
return kvsStorage({
|
||||
...options,
|
||||
storage: new LocalStorage(saveFilePath, storeQuota)
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kvs/node-localstorage/module/index.js.map
generated
vendored
Normal file
1
node_modules/@kvs/node-localstorage/module/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAyB,UAAU,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,aAAa;AACb,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,aAAa;AACb,OAAO,OAAO,MAAM,eAAe,CAAC;AAWpC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAChC,OAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,EAAE,CAAC,KAAK,CAAC,eAAe,EAAE;YAC5B,SAAS,EAAE,IAAI;SAClB,CAAC,CAAC;IACP,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa;QACtC,CAAC,CAAC,OAAO,CAAC,aAAa;QACvB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAC7E,OAAO,UAAU,CAAC;QACd,GAAG,OAAO;QACV,OAAO,EAAE,IAAI,YAAY,CAAC,YAAY,EAAE,UAAU,CAAC;KACtD,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
67
node_modules/@kvs/node-localstorage/package.json
generated
vendored
Normal file
67
node_modules/@kvs/node-localstorage/package.json
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "@kvs/node-localstorage",
|
||||
"version": "2.2.2",
|
||||
"description": "Node.js localstorage for KVS.",
|
||||
"keywords": [
|
||||
"kvs",
|
||||
"browser",
|
||||
"localstorage"
|
||||
],
|
||||
"homepage": "https://github.com/azu/kvs/tree/master/packages/node-localstorage/",
|
||||
"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}\"",
|
||||
"prepublishOnly": "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/storage": "^2.2.2",
|
||||
"@kvs/types": "^2.2.2",
|
||||
"app-root-path": "^3.1.0",
|
||||
"node-localstorage": "^2.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kvs/common-test-case": "^2.2.2",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "^20.4.2",
|
||||
"mocha": "^10.2.0",
|
||||
"prettier": "^3.0.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"ts-loader": "^9.4.4",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "d8a7098f37e551532dbcc8c411fe26ec493cd898"
|
||||
}
|
||||
19
node_modules/@kvs/storage/LICENSE
generated
vendored
Normal file
19
node_modules/@kvs/storage/LICENSE
generated
vendored
Normal file
@@ -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.
|
||||
70
node_modules/@kvs/storage/README.md
generated
vendored
Normal file
70
node_modules/@kvs/storage/README.md
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
# @kvs/storage
|
||||
|
||||
Storage-like for KVS.
|
||||
|
||||
You can inject Storage object like localStorage, sessionStorage to this storage.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
npm install @kvs/storage
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import assert from "assert";
|
||||
import { kvsStorage } from "@kvs/storage";
|
||||
(async () => {
|
||||
type StorageSchema = {
|
||||
a1: string;
|
||||
b2: number;
|
||||
c3: boolean;
|
||||
};
|
||||
const storage = await kvsStorage<StorageSchema>({
|
||||
name: "test",
|
||||
version: 1,
|
||||
storage: localStorage
|
||||
});
|
||||
await storage.set("a1", "string");
|
||||
await storage.set("b2", 42);
|
||||
await storage.set("c3", false);
|
||||
const a1 = await storage.get("a1");
|
||||
const b2 = await storage.get("b2");
|
||||
const c3 = await 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
|
||||
16
node_modules/@kvs/storage/lib/JSONValue.d.ts
generated
vendored
Normal file
16
node_modules/@kvs/storage/lib/JSONValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
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;
|
||||
3
node_modules/@kvs/storage/lib/JSONValue.js
generated
vendored
Normal file
3
node_modules/@kvs/storage/lib/JSONValue.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=JSONValue.js.map
|
||||
1
node_modules/@kvs/storage/lib/JSONValue.js.map
generated
vendored
Normal file
1
node_modules/@kvs/storage/lib/JSONValue.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"JSONValue.js","sourceRoot":"","sources":["../src/JSONValue.ts"],"names":[],"mappings":""}
|
||||
2
node_modules/@kvs/storage/lib/index.d.ts
generated
vendored
Normal file
2
node_modules/@kvs/storage/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { kvsStorage, deleteItem, setItem, getItem, clearItem, createIterator, hasItem, KvsStorage, KVSStorageKey, KvsStorageOptions } from "./storage";
|
||||
export { JsonValue, JsonArray, JsonObject } from "./JSONValue";
|
||||
12
node_modules/@kvs/storage/lib/index.js
generated
vendored
Normal file
12
node_modules/@kvs/storage/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hasItem = exports.createIterator = exports.clearItem = exports.getItem = exports.setItem = exports.deleteItem = exports.kvsStorage = void 0;
|
||||
var storage_1 = require("./storage");
|
||||
Object.defineProperty(exports, "kvsStorage", { enumerable: true, get: function () { return storage_1.kvsStorage; } });
|
||||
Object.defineProperty(exports, "deleteItem", { enumerable: true, get: function () { return storage_1.deleteItem; } });
|
||||
Object.defineProperty(exports, "setItem", { enumerable: true, get: function () { return storage_1.setItem; } });
|
||||
Object.defineProperty(exports, "getItem", { enumerable: true, get: function () { return storage_1.getItem; } });
|
||||
Object.defineProperty(exports, "clearItem", { enumerable: true, get: function () { return storage_1.clearItem; } });
|
||||
Object.defineProperty(exports, "createIterator", { enumerable: true, get: function () { return storage_1.createIterator; } });
|
||||
Object.defineProperty(exports, "hasItem", { enumerable: true, get: function () { return storage_1.hasItem; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kvs/storage/lib/index.js.map
generated
vendored
Normal file
1
node_modules/@kvs/storage/lib/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAWmB;AAVf,qGAAA,UAAU,OAAA;AACV,qGAAA,UAAU,OAAA;AACV,kGAAA,OAAO,OAAA;AACP,kGAAA,OAAO,OAAA;AACP,oGAAA,SAAS,OAAA;AACT,yGAAA,cAAc,OAAA;AACd,kGAAA,OAAO,OAAA"}
|
||||
20
node_modules/@kvs/storage/lib/storage.d.ts
generated
vendored
Normal file
20
node_modules/@kvs/storage/lib/storage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { KVS, KVSOptions, StoreNames, StoreValue } from "@kvs/types";
|
||||
import { JsonValue } from "./JSONValue";
|
||||
export type KVSStorageKey = string;
|
||||
export declare const getItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>) => any;
|
||||
export declare const hasItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>) => boolean;
|
||||
export declare const setItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>, value: StoreValue<Schema, StoreNames<Schema>> | undefined) => boolean | void;
|
||||
export declare const clearItem: (storage: Storage, tableName: string, kvsVersionKey: string, options: {
|
||||
force: boolean;
|
||||
}) => void;
|
||||
export declare const deleteItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>) => boolean;
|
||||
export declare function createIterator<Schema extends StorageSchema>(storage: Storage, tableName: string, kvsVersionKey: string): Iterator<[StoreNames<Schema>, StoreValue<Schema, StoreNames<Schema>>]>;
|
||||
export type StorageSchema = {
|
||||
[index: string]: JsonValue;
|
||||
};
|
||||
export type KvsStorage<Schema extends StorageSchema> = KVS<Schema>;
|
||||
export type KvsStorageOptions<Schema extends StorageSchema> = KVSOptions<Schema> & {
|
||||
kvsVersionKey?: string;
|
||||
storage: Storage;
|
||||
};
|
||||
export declare const kvsStorage: <Schema extends StorageSchema>(options: KvsStorageOptions<Schema>) => Promise<KvsStorage<Schema>>;
|
||||
183
node_modules/@kvs/storage/lib/storage.js
generated
vendored
Normal file
183
node_modules/@kvs/storage/lib/storage.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.kvsStorage = exports.deleteItem = exports.clearItem = exports.setItem = exports.hasItem = exports.getItem = void 0;
|
||||
exports.createIterator = createIterator;
|
||||
function invariant(condition, message) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
const TABLE_KEY_MARKER = ".__.";
|
||||
const getItem = (storage, tableName, key) => {
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
const item = storage.getItem(storageKey);
|
||||
return item !== null ? JSON.parse(item) : undefined;
|
||||
};
|
||||
exports.getItem = getItem;
|
||||
const hasItem = (storage, tableName, key) => {
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
return storage.getItem(storageKey) !== null;
|
||||
};
|
||||
exports.hasItem = hasItem;
|
||||
const setItem = (storage, tableName, key, value) => {
|
||||
// It is difference with IndexedDB implementation.
|
||||
// This behavior compatible with localStorage.
|
||||
if (value === undefined) {
|
||||
return (0, exports.deleteItem)(storage, tableName, key);
|
||||
}
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
return storage.setItem(storageKey, JSON.stringify(value));
|
||||
};
|
||||
exports.setItem = setItem;
|
||||
const clearItem = (storage, tableName, kvsVersionKey, options) => {
|
||||
// TODO: kvsVersionKey is special type
|
||||
const currentVersion = (0, exports.getItem)(storage, tableName, kvsVersionKey);
|
||||
// clear all
|
||||
storage.clear();
|
||||
// if option.force is true, does not restore metadata.
|
||||
if (options.force) {
|
||||
return;
|
||||
}
|
||||
// set kvs version again
|
||||
if (currentVersion !== undefined) {
|
||||
(0, exports.setItem)(storage, tableName, kvsVersionKey, currentVersion);
|
||||
}
|
||||
};
|
||||
exports.clearItem = clearItem;
|
||||
const deleteItem = (storage, tableName, key) => {
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
try {
|
||||
storage.removeItem(storageKey);
|
||||
return true;
|
||||
}
|
||||
catch (_a) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
exports.deleteItem = deleteItem;
|
||||
function* createIterator(storage, tableName, kvsVersionKey) {
|
||||
const tableKeyPrefix = `${tableName}${TABLE_KEY_MARKER}`;
|
||||
for (let i = 0; i < storage.length; i++) {
|
||||
const key = storage.key(i);
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
// skip another storage
|
||||
if (!key.startsWith(tableKeyPrefix)) {
|
||||
continue;
|
||||
}
|
||||
// skip meta key
|
||||
const keyWithoutPrefix = key.replace(tableKeyPrefix, "");
|
||||
if (keyWithoutPrefix === kvsVersionKey) {
|
||||
continue;
|
||||
}
|
||||
const value = (0, exports.getItem)(storage, tableName, keyWithoutPrefix);
|
||||
yield [keyWithoutPrefix, value];
|
||||
}
|
||||
}
|
||||
const DEFAULT_KVS_VERSION = 1;
|
||||
const openStorage = async ({ storage, version, tableName, kvsVersionKey, onUpgrade }) => {
|
||||
// kvsVersionKey is special type
|
||||
// first `oldVersion` is `0`
|
||||
let oldVersion = (0, exports.getItem)(storage, tableName, kvsVersionKey);
|
||||
if (oldVersion === undefined) {
|
||||
(0, exports.setItem)(storage, tableName, kvsVersionKey, DEFAULT_KVS_VERSION);
|
||||
// first `oldVersion` is `0`
|
||||
// https://github.com/azu/kvs/issues/8
|
||||
oldVersion = 0;
|
||||
}
|
||||
// if user set newVersion, upgrade it
|
||||
if (oldVersion !== version) {
|
||||
await onUpgrade({
|
||||
oldVersion,
|
||||
newVersion: version,
|
||||
storage
|
||||
});
|
||||
// save current version if upgrade is success
|
||||
(0, exports.setItem)(storage, tableName, kvsVersionKey, version);
|
||||
return storage;
|
||||
}
|
||||
return storage;
|
||||
};
|
||||
const createStore = ({ tableName, storage, kvsVersionKey }) => {
|
||||
const store = {
|
||||
get(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
return (0, exports.getItem)(storage, tableName, key);
|
||||
});
|
||||
},
|
||||
has(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
return (0, exports.hasItem)(storage, tableName, key);
|
||||
});
|
||||
},
|
||||
set(key, value) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
return (0, exports.setItem)(storage, tableName, key, value);
|
||||
})
|
||||
.then(() => {
|
||||
return store;
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
return Promise.resolve().then(() => {
|
||||
return (0, exports.clearItem)(storage, tableName, kvsVersionKey, { force: false });
|
||||
});
|
||||
},
|
||||
delete(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
return (0, exports.deleteItem)(storage, tableName, key);
|
||||
});
|
||||
},
|
||||
dropInstance() {
|
||||
return Promise.resolve().then(() => {
|
||||
return (0, exports.clearItem)(storage, tableName, kvsVersionKey, { force: true });
|
||||
});
|
||||
},
|
||||
close() {
|
||||
// Noop function
|
||||
return Promise.resolve();
|
||||
},
|
||||
[Symbol.asyncIterator]() {
|
||||
const iterator = createIterator(storage, tableName, kvsVersionKey);
|
||||
return {
|
||||
next() {
|
||||
return Promise.resolve().then(() => {
|
||||
return iterator.next();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
return store;
|
||||
};
|
||||
const kvsStorage = async (options) => {
|
||||
var _a;
|
||||
const { name, version, upgrade, ...kvStorageOptions } = options;
|
||||
invariant(typeof name === "string", "name should be string");
|
||||
invariant(name.length > 0, "name should not be empty");
|
||||
invariant(!name.includes(TABLE_KEY_MARKER), `name can not include ${TABLE_KEY_MARKER}. It is reserved in kvs.`);
|
||||
invariant(typeof version === "number", `version should be number`);
|
||||
const kvsVersionKey = (_a = kvStorageOptions.kvsVersionKey) !== null && _a !== void 0 ? _a : "__kvs_version__";
|
||||
const storage = await openStorage({
|
||||
storage: options.storage,
|
||||
version: options.version,
|
||||
tableName: name,
|
||||
onUpgrade: ({ oldVersion, newVersion, storage }) => {
|
||||
if (!options.upgrade) {
|
||||
return;
|
||||
}
|
||||
return options.upgrade({
|
||||
kvs: createStore({ tableName: name, storage, kvsVersionKey }),
|
||||
oldVersion,
|
||||
newVersion
|
||||
});
|
||||
},
|
||||
kvsVersionKey
|
||||
});
|
||||
return createStore({ tableName: name, storage, kvsVersionKey });
|
||||
};
|
||||
exports.kvsStorage = kvsStorage;
|
||||
//# sourceMappingURL=storage.js.map
|
||||
1
node_modules/@kvs/storage/lib/storage.js.map
generated
vendored
Normal file
1
node_modules/@kvs/storage/lib/storage.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
16
node_modules/@kvs/storage/module/JSONValue.d.ts
generated
vendored
Normal file
16
node_modules/@kvs/storage/module/JSONValue.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
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;
|
||||
2
node_modules/@kvs/storage/module/JSONValue.js
generated
vendored
Normal file
2
node_modules/@kvs/storage/module/JSONValue.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=JSONValue.js.map
|
||||
1
node_modules/@kvs/storage/module/JSONValue.js.map
generated
vendored
Normal file
1
node_modules/@kvs/storage/module/JSONValue.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"JSONValue.js","sourceRoot":"","sources":["../src/JSONValue.ts"],"names":[],"mappings":""}
|
||||
2
node_modules/@kvs/storage/module/index.d.ts
generated
vendored
Normal file
2
node_modules/@kvs/storage/module/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { kvsStorage, deleteItem, setItem, getItem, clearItem, createIterator, hasItem, KvsStorage, KVSStorageKey, KvsStorageOptions } from "./storage";
|
||||
export { JsonValue, JsonArray, JsonObject } from "./JSONValue";
|
||||
2
node_modules/@kvs/storage/module/index.js
generated
vendored
Normal file
2
node_modules/@kvs/storage/module/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { kvsStorage, deleteItem, setItem, getItem, clearItem, createIterator, hasItem } from "./storage";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kvs/storage/module/index.js.map
generated
vendored
Normal file
1
node_modules/@kvs/storage/module/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,UAAU,EACV,OAAO,EACP,OAAO,EACP,SAAS,EACT,cAAc,EACd,OAAO,EAIV,MAAM,WAAW,CAAC"}
|
||||
20
node_modules/@kvs/storage/module/storage.d.ts
generated
vendored
Normal file
20
node_modules/@kvs/storage/module/storage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { KVS, KVSOptions, StoreNames, StoreValue } from "@kvs/types";
|
||||
import { JsonValue } from "./JSONValue";
|
||||
export type KVSStorageKey = string;
|
||||
export declare const getItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>) => any;
|
||||
export declare const hasItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>) => boolean;
|
||||
export declare const setItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>, value: StoreValue<Schema, StoreNames<Schema>> | undefined) => boolean | void;
|
||||
export declare const clearItem: (storage: Storage, tableName: string, kvsVersionKey: string, options: {
|
||||
force: boolean;
|
||||
}) => void;
|
||||
export declare const deleteItem: <Schema extends StorageSchema>(storage: Storage, tableName: string, key: StoreNames<Schema>) => boolean;
|
||||
export declare function createIterator<Schema extends StorageSchema>(storage: Storage, tableName: string, kvsVersionKey: string): Iterator<[StoreNames<Schema>, StoreValue<Schema, StoreNames<Schema>>]>;
|
||||
export type StorageSchema = {
|
||||
[index: string]: JsonValue;
|
||||
};
|
||||
export type KvsStorage<Schema extends StorageSchema> = KVS<Schema>;
|
||||
export type KvsStorageOptions<Schema extends StorageSchema> = KVSOptions<Schema> & {
|
||||
kvsVersionKey?: string;
|
||||
storage: Storage;
|
||||
};
|
||||
export declare const kvsStorage: <Schema extends StorageSchema>(options: KvsStorageOptions<Schema>) => Promise<KvsStorage<Schema>>;
|
||||
173
node_modules/@kvs/storage/module/storage.js
generated
vendored
Normal file
173
node_modules/@kvs/storage/module/storage.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
function invariant(condition, message) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
const TABLE_KEY_MARKER = ".__.";
|
||||
export const getItem = (storage, tableName, key) => {
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
const item = storage.getItem(storageKey);
|
||||
return item !== null ? JSON.parse(item) : undefined;
|
||||
};
|
||||
export const hasItem = (storage, tableName, key) => {
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
return storage.getItem(storageKey) !== null;
|
||||
};
|
||||
export const setItem = (storage, tableName, key, value) => {
|
||||
// It is difference with IndexedDB implementation.
|
||||
// This behavior compatible with localStorage.
|
||||
if (value === undefined) {
|
||||
return deleteItem(storage, tableName, key);
|
||||
}
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
return storage.setItem(storageKey, JSON.stringify(value));
|
||||
};
|
||||
export const clearItem = (storage, tableName, kvsVersionKey, options) => {
|
||||
// TODO: kvsVersionKey is special type
|
||||
const currentVersion = getItem(storage, tableName, kvsVersionKey);
|
||||
// clear all
|
||||
storage.clear();
|
||||
// if option.force is true, does not restore metadata.
|
||||
if (options.force) {
|
||||
return;
|
||||
}
|
||||
// set kvs version again
|
||||
if (currentVersion !== undefined) {
|
||||
setItem(storage, tableName, kvsVersionKey, currentVersion);
|
||||
}
|
||||
};
|
||||
export const deleteItem = (storage, tableName, key) => {
|
||||
const storageKey = `${tableName}${TABLE_KEY_MARKER}${String(key)}`;
|
||||
try {
|
||||
storage.removeItem(storageKey);
|
||||
return true;
|
||||
}
|
||||
catch (_a) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
export function* createIterator(storage, tableName, kvsVersionKey) {
|
||||
const tableKeyPrefix = `${tableName}${TABLE_KEY_MARKER}`;
|
||||
for (let i = 0; i < storage.length; i++) {
|
||||
const key = storage.key(i);
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
// skip another storage
|
||||
if (!key.startsWith(tableKeyPrefix)) {
|
||||
continue;
|
||||
}
|
||||
// skip meta key
|
||||
const keyWithoutPrefix = key.replace(tableKeyPrefix, "");
|
||||
if (keyWithoutPrefix === kvsVersionKey) {
|
||||
continue;
|
||||
}
|
||||
const value = getItem(storage, tableName, keyWithoutPrefix);
|
||||
yield [keyWithoutPrefix, value];
|
||||
}
|
||||
}
|
||||
const DEFAULT_KVS_VERSION = 1;
|
||||
const openStorage = async ({ storage, version, tableName, kvsVersionKey, onUpgrade }) => {
|
||||
// kvsVersionKey is special type
|
||||
// first `oldVersion` is `0`
|
||||
let oldVersion = getItem(storage, tableName, kvsVersionKey);
|
||||
if (oldVersion === undefined) {
|
||||
setItem(storage, tableName, kvsVersionKey, DEFAULT_KVS_VERSION);
|
||||
// first `oldVersion` is `0`
|
||||
// https://github.com/azu/kvs/issues/8
|
||||
oldVersion = 0;
|
||||
}
|
||||
// if user set newVersion, upgrade it
|
||||
if (oldVersion !== version) {
|
||||
await onUpgrade({
|
||||
oldVersion,
|
||||
newVersion: version,
|
||||
storage
|
||||
});
|
||||
// save current version if upgrade is success
|
||||
setItem(storage, tableName, kvsVersionKey, version);
|
||||
return storage;
|
||||
}
|
||||
return storage;
|
||||
};
|
||||
const createStore = ({ tableName, storage, kvsVersionKey }) => {
|
||||
const store = {
|
||||
get(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
return getItem(storage, tableName, key);
|
||||
});
|
||||
},
|
||||
has(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
return hasItem(storage, tableName, key);
|
||||
});
|
||||
},
|
||||
set(key, value) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
return setItem(storage, tableName, key, value);
|
||||
})
|
||||
.then(() => {
|
||||
return store;
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
return Promise.resolve().then(() => {
|
||||
return clearItem(storage, tableName, kvsVersionKey, { force: false });
|
||||
});
|
||||
},
|
||||
delete(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
return deleteItem(storage, tableName, key);
|
||||
});
|
||||
},
|
||||
dropInstance() {
|
||||
return Promise.resolve().then(() => {
|
||||
return clearItem(storage, tableName, kvsVersionKey, { force: true });
|
||||
});
|
||||
},
|
||||
close() {
|
||||
// Noop function
|
||||
return Promise.resolve();
|
||||
},
|
||||
[Symbol.asyncIterator]() {
|
||||
const iterator = createIterator(storage, tableName, kvsVersionKey);
|
||||
return {
|
||||
next() {
|
||||
return Promise.resolve().then(() => {
|
||||
return iterator.next();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
return store;
|
||||
};
|
||||
export const kvsStorage = async (options) => {
|
||||
var _a;
|
||||
const { name, version, upgrade, ...kvStorageOptions } = options;
|
||||
invariant(typeof name === "string", "name should be string");
|
||||
invariant(name.length > 0, "name should not be empty");
|
||||
invariant(!name.includes(TABLE_KEY_MARKER), `name can not include ${TABLE_KEY_MARKER}. It is reserved in kvs.`);
|
||||
invariant(typeof version === "number", `version should be number`);
|
||||
const kvsVersionKey = (_a = kvStorageOptions.kvsVersionKey) !== null && _a !== void 0 ? _a : "__kvs_version__";
|
||||
const storage = await openStorage({
|
||||
storage: options.storage,
|
||||
version: options.version,
|
||||
tableName: name,
|
||||
onUpgrade: ({ oldVersion, newVersion, storage }) => {
|
||||
if (!options.upgrade) {
|
||||
return;
|
||||
}
|
||||
return options.upgrade({
|
||||
kvs: createStore({ tableName: name, storage, kvsVersionKey }),
|
||||
oldVersion,
|
||||
newVersion
|
||||
});
|
||||
},
|
||||
kvsVersionKey
|
||||
});
|
||||
return createStore({ tableName: name, storage, kvsVersionKey });
|
||||
};
|
||||
//# sourceMappingURL=storage.js.map
|
||||
1
node_modules/@kvs/storage/module/storage.js.map
generated
vendored
Normal file
1
node_modules/@kvs/storage/module/storage.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
69
node_modules/@kvs/storage/package.json
generated
vendored
Normal file
69
node_modules/@kvs/storage/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "@kvs/storage",
|
||||
"version": "2.2.2",
|
||||
"description": "Storage(localStorage, sessionStorage) helper for KVS.",
|
||||
"keywords": [
|
||||
"kvs",
|
||||
"browser",
|
||||
"localstorage"
|
||||
],
|
||||
"homepage": "https://github.com/azu/kvs/tree/master/packages/storage/",
|
||||
"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}\"",
|
||||
"prepublishOnly": "npm run clean && npm run build",
|
||||
"test": "tsc -p .",
|
||||
"test:browser": "npm run test:chrome && npm run test:firefox && npm run test:webkit",
|
||||
"test:chrome": "playwright-test ./test/index.test.ts --runner=mocha --browser=chromium",
|
||||
"test:firefox": "playwright-test ./test/index.test.ts --runner=mocha --browser=firefox",
|
||||
"test:webkit": "playwright-test ./test/index.test.ts --runner=mocha --browser=webkit",
|
||||
"watch": "tsc -p . --watch"
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120,
|
||||
"singleQuote": false,
|
||||
"tabWidth": 4,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kvs/types": "^2.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kvs/common-test-case": "^2.2.2",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "^20.4.2",
|
||||
"mocha": "^10.2.0",
|
||||
"playwright-test": "^14.1.12",
|
||||
"prettier": "^3.0.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"ts-loader": "^9.4.4",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "d8a7098f37e551532dbcc8c411fe26ec493cd898"
|
||||
}
|
||||
19
node_modules/@kvs/types/LICENSE
generated
vendored
Normal file
19
node_modules/@kvs/types/LICENSE
generated
vendored
Normal file
@@ -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.
|
||||
46
node_modules/@kvs/types/README.md
generated
vendored
Normal file
46
node_modules/@kvs/types/README.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# @kvs/types
|
||||
|
||||
A type definition for KVS.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
npm install @kvs/types
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import type { KVS } from "@kvs/types";
|
||||
```
|
||||
|
||||
## 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
|
||||
110
node_modules/@kvs/types/lib/index.d.ts
generated
vendored
Normal file
110
node_modules/@kvs/types/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
export type StorageSchema = {
|
||||
[index: string]: any;
|
||||
};
|
||||
type HasIndexSignature<T> = T extends Record<infer K, any> ? K : never;
|
||||
export type RemoveIndex<T> = {
|
||||
[K in keyof T as symbol extends K ? never : string extends K ? never : number extends K ? never : K]: T[K];
|
||||
};
|
||||
export type KnownKeys<T> = keyof RemoveIndex<T>;
|
||||
/**
|
||||
* Extract known object store names from the DB schema type.
|
||||
*
|
||||
* @template DBTypes DB schema type, or unknown if the DB isn't typed.
|
||||
*/
|
||||
export type StoreNames<DBTypes extends StorageSchema | unknown> = DBTypes extends StorageSchema ? string extends HasIndexSignature<DBTypes> ? string : KnownKeys<DBTypes> : string;
|
||||
/**
|
||||
* Extract database value types from the DB schema type.
|
||||
*
|
||||
* @template DBTypes DB schema type, or unknown if the DB isn't typed.
|
||||
* @template StoreName Names of the object stores to get the types of.
|
||||
*/
|
||||
export type StoreValue<DBTypes extends StorageSchema | unknown, StoreName extends StoreNames<DBTypes>> = DBTypes extends StorageSchema ? DBTypes[StoreName] : any;
|
||||
export type KVS<Schema extends StorageSchema> = {
|
||||
/**
|
||||
* Returns the value associated to the key.
|
||||
* If the key does not exist, returns `undefined`.
|
||||
*/
|
||||
get<K extends StoreNames<Schema>>(key: K): Promise<StoreValue<Schema, K> | undefined>;
|
||||
/**
|
||||
* Sets the value for the key in the storage. Returns the storage.
|
||||
*/
|
||||
set<K extends StoreNames<Schema>>(key: K, value: StoreValue<Schema, K> | undefined): Promise<KVS<Schema>>;
|
||||
/**
|
||||
* Returns a boolean asserting whether a value has been associated to the key in the storage.
|
||||
*/
|
||||
has(key: StoreNames<Schema>): Promise<boolean>;
|
||||
/**
|
||||
* Returns true if an key in the storage existed and has been removed.
|
||||
* Returns false if the key does not exist.
|
||||
*/
|
||||
delete(key: StoreNames<Schema>): Promise<boolean>;
|
||||
/**
|
||||
* Removes all key-value pairs from the storage.
|
||||
* Note: clear method does not delete the storage.
|
||||
* In other words, after clear(), the storage still has internal metadata like version.
|
||||
*/
|
||||
clear(): Promise<void>;
|
||||
/**
|
||||
* Drop the storage.
|
||||
* It delete all data that includes metadata completely.
|
||||
*/
|
||||
dropInstance(): Promise<void>;
|
||||
close(): Promise<void>;
|
||||
} & AsyncIterable<[StoreNames<Schema>, StoreValue<Schema, StoreNames<Schema>>]>;
|
||||
export type KVSOptions<Schema extends StorageSchema> = {
|
||||
name: string;
|
||||
version: number;
|
||||
upgrade?({ kvs, oldVersion, newVersion }: {
|
||||
kvs: KVS<Schema>;
|
||||
oldVersion: number;
|
||||
newVersion: number;
|
||||
}): Promise<any>;
|
||||
} & {
|
||||
[index: string]: any;
|
||||
};
|
||||
export type KVSConstructor<Schema extends StorageSchema> = (options: KVSOptions<Schema>) => Promise<KVS<Schema>>;
|
||||
/**
|
||||
* Sync Version
|
||||
*/
|
||||
export type KVSSync<Schema extends StorageSchema> = {
|
||||
/**
|
||||
* Returns the value associated to the key.
|
||||
* If the key does not exist, returns `undefined`.
|
||||
*/
|
||||
get<K extends StoreNames<Schema>>(key: K): StoreValue<Schema, K> | undefined;
|
||||
/**
|
||||
* Sets the value for the key in the storage. Returns the storage.
|
||||
*/
|
||||
set<K extends StoreNames<Schema>>(key: K, value: StoreValue<Schema, K> | undefined): KVSSync<Schema>;
|
||||
/**
|
||||
* Returns a boolean asserting whether a value has been associated to the key in the storage.
|
||||
*/
|
||||
has(key: StoreNames<Schema>): boolean;
|
||||
/**
|
||||
* Returns true if an key in the storage existed and has been removed.
|
||||
* Returns false if the key does not exist.
|
||||
*/
|
||||
delete(key: StoreNames<Schema>): boolean;
|
||||
/**
|
||||
* Removes all key-value pairs from the storage.
|
||||
* Note: clear method does not delete the storage.
|
||||
* In other words, after clear(), the storage still has internal metadata like version.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Drop the storage.
|
||||
* It delete all data that includes metadata completely.
|
||||
*/
|
||||
dropInstance(): void;
|
||||
close(): void;
|
||||
} & Iterable<[StoreNames<Schema>, StoreValue<Schema, StoreNames<Schema>>]>;
|
||||
export type KVSSyncOptions<Schema extends StorageSchema> = {
|
||||
name: string;
|
||||
version: number;
|
||||
upgrade?({ kvs, oldVersion, newVersion }: {
|
||||
kvs: KVSSync<Schema>;
|
||||
oldVersion: number;
|
||||
newVersion: number;
|
||||
}): any;
|
||||
};
|
||||
export {};
|
||||
3
node_modules/@kvs/types/lib/index.js
generated
vendored
Normal file
3
node_modules/@kvs/types/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@kvs/types/lib/index.js.map
generated
vendored
Normal file
1
node_modules/@kvs/types/lib/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
||||
58
node_modules/@kvs/types/package.json
generated
vendored
Normal file
58
node_modules/@kvs/types/package.json
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "@kvs/types",
|
||||
"version": "2.2.2",
|
||||
"description": "A type definition for KVS.",
|
||||
"keywords": [
|
||||
"types",
|
||||
"kvs"
|
||||
],
|
||||
"homepage": "https://github.com/azu/kvs/tree/master/packages/types/",
|
||||
"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",
|
||||
"types": "lib/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc -p .",
|
||||
"clean": "rimraf lib/ module/",
|
||||
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
|
||||
"prepublishOnly": "npm run clean && npm run build",
|
||||
"test": "tsc -p test",
|
||||
"watch": "tsc -p . --watch"
|
||||
},
|
||||
"tsd": {
|
||||
"directory": "test"
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120,
|
||||
"singleQuote": false,
|
||||
"tabWidth": 4,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.4.2",
|
||||
"prettier": "^3.0.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"tsd": "^0.28.1",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "d8a7098f37e551532dbcc8c411fe26ec493cd898"
|
||||
}
|
||||
Reference in New Issue
Block a user