@kvs/memorystorage 0.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # @kvs/memorystorage
1
+ # @kvs/memorystorage ![](https://badgen.net/bundlephobia/minzip/@kvs/memorystorage)
2
2
 
3
- In-Memory storage for KVS.
3
+ In-Memory storage for [KVS](https://github.com/azu/kvs).
4
4
 
5
- :memo: It has not persisted storage.
5
+ :memo: It is not persisted storage.
6
6
 
7
7
  ## Dependencies
8
8
 
@@ -16,7 +16,7 @@ Install with [npm](https://www.npmjs.com/):
16
16
 
17
17
  ## Usage
18
18
 
19
- - [ ] Write usage instructions
19
+ See <https://github.com/azu/kvs#usage>
20
20
 
21
21
  ## Changelog
22
22
 
package/lib/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export declare type KvsMemoryStorage<Schema extends KvsMemoryStorageSchema> = KV
7
7
  export declare type KvsMemoryStorageOptions<Schema extends KvsMemoryStorageSchema> = KVSOptions<Schema> & {
8
8
  kvsVersionKey?: string;
9
9
  };
10
- export declare const kvsMemoryStorage: <Schema extends KvsMemoryStorageSchema>(options: KvsMemoryStorageOptions<Schema>) => Promise<KVS<Schema>>;
10
+ export declare const kvsMemoryStorage: <Schema extends KvsMemoryStorageSchema>(options: KvsMemoryStorageOptions<Schema>) => Promise<KvsStorage<Schema>>;
package/lib/index.js CHANGED
@@ -15,8 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.kvsMemoryStorage = void 0;
16
16
  const storage_1 = require("@kvs/storage");
17
17
  // @ts-ignore
18
- const localstorage_memory_1 = __importDefault(require("localstorage-memory"));
19
- exports.kvsMemoryStorage = (options) => __awaiter(void 0, void 0, void 0, function* () {
20
- return storage_1.kvsStorage(Object.assign(Object.assign({}, options), { storage: localstorage_memory_1.default }));
18
+ // import localstorage from "localstorage-memory";
19
+ const localstorage_memory_1 = __importDefault(require("./localstorage-memory"));
20
+ const kvsMemoryStorage = (options) => __awaiter(void 0, void 0, void 0, function* () {
21
+ return (0, storage_1.kvsStorage)(Object.assign(Object.assign({}, options), { storage: localstorage_memory_1.default }));
21
22
  });
23
+ exports.kvsMemoryStorage = kvsMemoryStorage;
22
24
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAiE;AAEjE,aAAa;AACb,8EAA+C;AASlC,QAAA,gBAAgB,GAAG,CAC5B,OAAwC,EACb,EAAE;IAC7B,OAAO,oBAAU,iCACV,OAAO,KACV,OAAO,EAAE,6BAAY,IACvB,CAAC;AACP,CAAC,CAAA,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAiE;AAEjE,aAAa;AACb,kDAAkD;AAClD,gFAAiD;AAS1C,MAAM,gBAAgB,GAAG,CAC5B,OAAwC,EACb,EAAE;IAC7B,OAAO,IAAA,oBAAU,kCACV,OAAO,KACV,OAAO,EAAE,6BAAY,IACvB,CAAC;AACP,CAAC,CAAA,CAAC;AAPW,QAAA,gBAAgB,oBAO3B"}
@@ -0,0 +1,13 @@
1
+ declare class LocalStorageMemory {
2
+ cache: {
3
+ [k: string]: string;
4
+ };
5
+ length: number;
6
+ getItem(key: string): string | null;
7
+ setItem(key: string, value: string): void;
8
+ removeItem(key: string): void;
9
+ key(index: any): string | null;
10
+ clear(): void;
11
+ }
12
+ declare const _default: LocalStorageMemory;
13
+ export default _default;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // another implements by https://github.com/gr2m/localstorage-memory/blob/master/lib/localstorage-memory.js
4
+ class LocalStorageMemory {
5
+ constructor() {
6
+ this.cache = {};
7
+ this.length = 0;
8
+ }
9
+ getItem(key) {
10
+ if (key in this.cache) {
11
+ return this.cache[key];
12
+ }
13
+ return null;
14
+ }
15
+ setItem(key, value) {
16
+ if (typeof value === "undefined") {
17
+ this.removeItem(key);
18
+ }
19
+ else {
20
+ if (!this.cache.hasOwnProperty(key)) {
21
+ this.length++;
22
+ }
23
+ this.cache[key] = "" + value;
24
+ }
25
+ }
26
+ removeItem(key) {
27
+ if (this.cache.hasOwnProperty(key)) {
28
+ delete this.cache[key];
29
+ this.length--;
30
+ }
31
+ }
32
+ key(index) {
33
+ return Object.keys(this.cache)[index] || null;
34
+ }
35
+ clear() {
36
+ this.cache = {};
37
+ this.length = 0;
38
+ }
39
+ }
40
+ exports.default = new LocalStorageMemory();
41
+ //# sourceMappingURL=localstorage-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localstorage-memory.js","sourceRoot":"","sources":["../src/localstorage-memory.ts"],"names":[],"mappings":";;AAAA,2GAA2G;AAC3G,MAAM,kBAAkB;IAAxB;QACI,UAAK,GAA4B,EAAE,CAAC;QACpC,WAAM,GAAG,CAAC,CAAC;IA8Bf,CAAC;IA7BG,OAAO,CAAC,GAAW;QACf,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;YACnB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,CAAC,GAAW,EAAE,KAAa;QAC9B,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAC9B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACxB;aAAM;YACH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACjC,IAAI,CAAC,MAAM,EAAE,CAAC;aACjB;YACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;SAChC;IACL,CAAC;IACD,UAAU,CAAC,GAAW;QAClB,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,EAAE,CAAC;SACjB;IACL,CAAC;IACD,GAAG,CAAC,KAAU;QACV,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAClD,CAAC;IACD,KAAK;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,CAAC;CACJ;AACD,kBAAe,IAAI,kBAAkB,EAAE,CAAC"}
package/module/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export declare type KvsMemoryStorage<Schema extends KvsMemoryStorageSchema> = KV
7
7
  export declare type KvsMemoryStorageOptions<Schema extends KvsMemoryStorageSchema> = KVSOptions<Schema> & {
8
8
  kvsVersionKey?: string;
9
9
  };
10
- export declare const kvsMemoryStorage: <Schema extends KvsMemoryStorageSchema>(options: KvsMemoryStorageOptions<Schema>) => Promise<KVS<Schema>>;
10
+ export declare const kvsMemoryStorage: <Schema extends KvsMemoryStorageSchema>(options: KvsMemoryStorageOptions<Schema>) => Promise<KvsStorage<Schema>>;
package/module/index.js CHANGED
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { kvsStorage } from "@kvs/storage";
11
11
  // @ts-ignore
12
- import localstorage from "localstorage-memory";
12
+ // import localstorage from "localstorage-memory";
13
+ import localstorage from "./localstorage-memory";
13
14
  export const kvsMemoryStorage = (options) => __awaiter(void 0, void 0, void 0, function* () {
14
15
  return kvsStorage(Object.assign(Object.assign({}, options), { storage: localstorage }));
15
16
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAyB,UAAU,EAAE,MAAM,cAAc,CAAC;AAEjE,aAAa;AACb,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAS/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,OAAwC,EACb,EAAE;IAC7B,OAAO,UAAU,iCACV,OAAO,KACV,OAAO,EAAE,YAAY,IACvB,CAAC;AACP,CAAC,CAAA,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAyB,UAAU,EAAE,MAAM,cAAc,CAAC;AAEjE,aAAa;AACb,kDAAkD;AAClD,OAAO,YAAY,MAAM,uBAAuB,CAAC;AASjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,OAAwC,EACb,EAAE;IAC7B,OAAO,UAAU,iCACV,OAAO,KACV,OAAO,EAAE,YAAY,IACvB,CAAC;AACP,CAAC,CAAA,CAAC"}
@@ -0,0 +1,13 @@
1
+ declare class LocalStorageMemory {
2
+ cache: {
3
+ [k: string]: string;
4
+ };
5
+ length: number;
6
+ getItem(key: string): string | null;
7
+ setItem(key: string, value: string): void;
8
+ removeItem(key: string): void;
9
+ key(index: any): string | null;
10
+ clear(): void;
11
+ }
12
+ declare const _default: LocalStorageMemory;
13
+ export default _default;
@@ -0,0 +1,39 @@
1
+ // another implements by https://github.com/gr2m/localstorage-memory/blob/master/lib/localstorage-memory.js
2
+ class LocalStorageMemory {
3
+ constructor() {
4
+ this.cache = {};
5
+ this.length = 0;
6
+ }
7
+ getItem(key) {
8
+ if (key in this.cache) {
9
+ return this.cache[key];
10
+ }
11
+ return null;
12
+ }
13
+ setItem(key, value) {
14
+ if (typeof value === "undefined") {
15
+ this.removeItem(key);
16
+ }
17
+ else {
18
+ if (!this.cache.hasOwnProperty(key)) {
19
+ this.length++;
20
+ }
21
+ this.cache[key] = "" + value;
22
+ }
23
+ }
24
+ removeItem(key) {
25
+ if (this.cache.hasOwnProperty(key)) {
26
+ delete this.cache[key];
27
+ this.length--;
28
+ }
29
+ }
30
+ key(index) {
31
+ return Object.keys(this.cache)[index] || null;
32
+ }
33
+ clear() {
34
+ this.cache = {};
35
+ this.length = 0;
36
+ }
37
+ }
38
+ export default new LocalStorageMemory();
39
+ //# sourceMappingURL=localstorage-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localstorage-memory.js","sourceRoot":"","sources":["../src/localstorage-memory.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,MAAM,kBAAkB;IAAxB;QACI,UAAK,GAA4B,EAAE,CAAC;QACpC,WAAM,GAAG,CAAC,CAAC;IA8Bf,CAAC;IA7BG,OAAO,CAAC,GAAW;QACf,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;YACnB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,CAAC,GAAW,EAAE,KAAa;QAC9B,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAC9B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACxB;aAAM;YACH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACjC,IAAI,CAAC,MAAM,EAAE,CAAC;aACjB;YACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;SAChC;IACL,CAAC;IACD,UAAU,CAAC,GAAW;QAClB,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,EAAE,CAAC;SACjB;IACL,CAAC;IACD,GAAG,CAAC,KAAU;QACV,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAClD,CAAC;IACD,KAAK;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,CAAC;CACJ;AACD,eAAe,IAAI,kBAAkB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,66 +1,62 @@
1
1
  {
2
- "name": "@kvs/memorystorage",
3
- "version": "0.3.0",
4
- "description": "Node.js localstorage for KVS.",
5
- "keywords": [
6
- "kvs",
7
- "browser",
8
- "localstorage"
9
- ],
10
- "homepage": "https://github.com/azu/kvs/tree/master/packages/memorystorage/",
11
- "bugs": {
12
- "url": "https://github.com/azu/kvs/issues"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/azu/kvs.git"
17
- },
18
- "license": "MIT",
19
- "author": "azu",
20
- "sideEffects": false,
21
- "main": "lib/index.js",
22
- "module": "module/index.js",
23
- "types": "lib/index.d.ts",
24
- "directories": {
25
- "lib": "lib",
26
- "test": "test"
27
- },
28
- "files": [
29
- "bin/",
30
- "lib/",
31
- "module"
32
- ],
33
- "scripts": {
34
- "build": "tsc -p . && tsc --project ./tsconfig.module.json",
35
- "clean": "rimraf lib/ module/",
36
- "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
37
- "prepublish": "npm run clean && npm run build",
38
- "test": "mocha \"test/**/*.ts\"",
39
- "watch": "tsc -p . --watch"
40
- },
41
- "prettier": {
42
- "printWidth": 120,
43
- "singleQuote": false,
44
- "tabWidth": 4,
45
- "trailingComma": "none"
46
- },
47
- "dependencies": {
48
- "localstorage-memory": "^1.0.3"
49
- },
50
- "devDependencies": {
51
- "@jsdevtools/karma-config": "^3.1.7",
52
- "@kvs/common-test-case": "^0.3.0",
53
- "@types/mocha": "^8.0.1",
54
- "@types/node": "^14.0.27",
55
- "lerna": "^3.22.1",
56
- "mocha": "^8.1.1",
57
- "prettier": "^2.0.5",
58
- "rimraf": "^3.0.2",
59
- "ts-loader": "^8.0.2",
60
- "typescript": "^3.9.7"
61
- },
62
- "publishConfig": {
63
- "access": "public"
64
- },
65
- "gitHead": "29ecd5a079ce0698ae822cc87344cf33532bad1e"
2
+ "name": "@kvs/memorystorage",
3
+ "version": "2.0.0",
4
+ "description": "Node.js localstorage for KVS.",
5
+ "keywords": [
6
+ "kvs",
7
+ "browser",
8
+ "localstorage"
9
+ ],
10
+ "homepage": "https://github.com/azu/kvs/tree/master/packages/memorystorage/",
11
+ "bugs": {
12
+ "url": "https://github.com/azu/kvs/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/azu/kvs.git"
17
+ },
18
+ "license": "MIT",
19
+ "author": "azu",
20
+ "sideEffects": false,
21
+ "main": "lib/index.js",
22
+ "module": "module/index.js",
23
+ "types": "lib/index.d.ts",
24
+ "directories": {
25
+ "lib": "lib",
26
+ "test": "test"
27
+ },
28
+ "files": [
29
+ "bin/",
30
+ "lib/",
31
+ "module"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc -p . && tsc --project ./tsconfig.module.json",
35
+ "clean": "rimraf lib/ module/",
36
+ "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
37
+ "prepublishOnly": "npm run clean && npm run build",
38
+ "test": "mocha \"test/**/*.ts\"",
39
+ "watch": "tsc -p . --watch"
40
+ },
41
+ "prettier": {
42
+ "printWidth": 120,
43
+ "singleQuote": false,
44
+ "tabWidth": 4,
45
+ "trailingComma": "none"
46
+ },
47
+ "devDependencies": {
48
+ "@jsdevtools/karma-config": "^3.1.7",
49
+ "@kvs/common-test-case": "^2.0.0",
50
+ "@types/mocha": "^9.0.0",
51
+ "@types/node": "^16.9.1",
52
+ "mocha": "^9.1.1",
53
+ "prettier": "^2.0.5",
54
+ "rimraf": "^3.0.2",
55
+ "ts-loader": "^8.2.0",
56
+ "typescript": "^4.2.4"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "gitHead": "b43dd2fdbefe4ee5714d0690b2f8f576dc8c1417"
66
62
  }
package/CHANGELOG.md DELETED
@@ -1,38 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [0.3.0](https://github.com/azu/kvs/compare/v0.2.1...v0.3.0) (2020-08-22)
7
-
8
- **Note:** Version bump only for package @kvs/memorystorage
9
-
10
-
11
-
12
-
13
-
14
- ## [0.2.1](https://github.com/azu/kvs/compare/v0.2.0...v0.2.1) (2020-08-22)
15
-
16
- **Note:** Version bump only for package @kvs/memorystorage
17
-
18
-
19
-
20
-
21
-
22
- # [0.2.0](https://github.com/azu/kvs/compare/v0.1.0...v0.2.0) (2020-08-08)
23
-
24
-
25
- ### Features
26
-
27
- * **@kvs/memorystorage:** migrate to Schema type ([84d75f4](https://github.com/azu/kvs/commit/84d75f4407b33119da6d4745adea611f2b80404e))
28
-
29
-
30
-
31
-
32
-
33
- # 0.1.0 (2020-08-08)
34
-
35
-
36
- ### Features
37
-
38
- * **@kvs/memorystorage:** add in memory implementation ([553247b](https://github.com/azu/kvs/commit/553247b76a8bbacb03deaee4cfd3b787d74ecd65))