extra-disk-store 0.1.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +141 -0
  3. package/lib/converters/index-key-converter.d.ts +7 -0
  4. package/lib/converters/index-key-converter.js +16 -0
  5. package/lib/converters/index-key-converter.js.map +1 -0
  6. package/lib/converters/index.d.ts +7 -0
  7. package/lib/converters/index.js +24 -0
  8. package/lib/converters/index.js.map +1 -0
  9. package/lib/converters/json-key-converter.d.ts +5 -0
  10. package/lib/converters/json-key-converter.js +13 -0
  11. package/lib/converters/json-key-converter.js.map +1 -0
  12. package/lib/converters/json-value-converter.d.ts +8 -0
  13. package/lib/converters/json-value-converter.js +16 -0
  14. package/lib/converters/json-value-converter.js.map +1 -0
  15. package/lib/converters/lz4-value-converter.d.ts +8 -0
  16. package/lib/converters/lz4-value-converter.js +42 -0
  17. package/lib/converters/lz4-value-converter.js.map +1 -0
  18. package/lib/converters/passthrough-key-converter.d.ts +5 -0
  19. package/lib/converters/passthrough-key-converter.js +13 -0
  20. package/lib/converters/passthrough-key-converter.js.map +1 -0
  21. package/lib/converters/passthrough-value-converter.d.ts +6 -0
  22. package/lib/converters/passthrough-value-converter.js +13 -0
  23. package/lib/converters/passthrough-value-converter.js.map +1 -0
  24. package/lib/converters/zstandard-value-converter.d.ts +10 -0
  25. package/lib/converters/zstandard-value-converter.js +47 -0
  26. package/lib/converters/zstandard-value-converter.js.map +1 -0
  27. package/lib/disk-store-async-view.d.ts +14 -0
  28. package/lib/disk-store-async-view.js +37 -0
  29. package/lib/disk-store-async-view.js.map +1 -0
  30. package/lib/disk-store-view.d.ts +14 -0
  31. package/lib/disk-store-view.js +37 -0
  32. package/lib/disk-store-view.js.map +1 -0
  33. package/lib/disk-store.d.ts +14 -0
  34. package/lib/disk-store.js +119 -0
  35. package/lib/disk-store.js.map +1 -0
  36. package/lib/index.d.ts +5 -0
  37. package/lib/index.js +22 -0
  38. package/lib/index.js.map +1 -0
  39. package/lib/types.d.ts +18 -0
  40. package/lib/types.js +3 -0
  41. package/lib/types.js.map +1 -0
  42. package/migrations/001-initial.sql +19 -0
  43. package/migrations/schema.sql +7 -0
  44. package/package.json +71 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 BlackGlory <woshenmedoubuzhidao@blackglory.me>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # extra-disk-store
2
+ A disk-based persistent store.
3
+
4
+ ## Install
5
+ ```sh
6
+ npm install --save extra-disk-store
7
+ # or
8
+ yarn add extra-disk-store
9
+ ```
10
+
11
+ ## Usage
12
+ ```ts
13
+ import { DiskStore } from 'extra-disk-store'
14
+
15
+ const store = new DiskStore('/tmp/store')
16
+ store.set('key', Buffer.from('value'))
17
+ const value = store.get('key')
18
+ ```
19
+
20
+ ## API
21
+ ### DiskStore
22
+ ```ts
23
+ class DiskStore {
24
+ static create(filename?: string): Promise<DiskStore>
25
+
26
+ close(): void
27
+
28
+ has(key: string): boolean
29
+ get(key: string): {
30
+ value: Buffer
31
+ updatedAt: number
32
+ timeToLive: number | null
33
+ }
34
+ set(key: string, value: Buffer): void
35
+ delete(key: string): void
36
+ clear(): void
37
+ keys(): Iterable<string>
38
+ }
39
+ ```
40
+
41
+ ### DiskStoreView
42
+ ```ts
43
+ interface IKeyConverter<T> {
44
+ toString: (value: T) => string
45
+ fromString: (value: string) => T
46
+ }
47
+
48
+ interface IValueConverter<T> {
49
+ toBuffer: (value: T) => Buffer
50
+ fromBuffer: (value: Buffer) => T
51
+ }
52
+
53
+ class DiskStoreView<K, V> {
54
+ constructor(
55
+ private store: DiskStore
56
+ , private keyConverter: IKeyConverter<K>
57
+ , private valueConverter: IValueConverter<V>
58
+ )
59
+
60
+ has(key: K): boolean
61
+ get(key: K): V | undefined
62
+ set(key: K, value: V): void
63
+ clear(): void
64
+ delete(key: K): void
65
+ keys(): Iterable<K>
66
+ }
67
+ ```
68
+
69
+ ### DiskStoreAsyncView
70
+ ```ts
71
+ interface IKeyAsyncConverter<T> {
72
+ toString: (value: T) => Awaitable<string>
73
+ fromString: (value: string) => Awaitable<T>
74
+ }
75
+
76
+ interface IValueAsyncConverter<T> {
77
+ toBuffer: (value: T) => Awaitable<Buffer>
78
+ fromBuffer: (value: Buffer) => Awaitable<T>
79
+ }
80
+
81
+ class DiskStoreAsyncView<K, V> {
82
+ constructor(
83
+ store: DiskStore
84
+ , keyConverter: IKeyAsyncConverter<K>
85
+ , valueConverter: IValueAsyncConverter<V>
86
+ )
87
+
88
+ has(key: K): Promise<boolean>
89
+ get(key: K): Promise<V | undefined>
90
+ set(key: K, value: V): Promise<void>
91
+ delete(key: K): Promise<void>
92
+ clear(): void
93
+ keys(): AsyncIterable<K>
94
+ }
95
+ ```
96
+
97
+ ### Converters
98
+ #### PassthroughKeyConverter
99
+ ```ts
100
+ class PassthroughKeyConverter implements IKeyConverter<string>, IKeyAsyncConverter<string>
101
+ ```
102
+
103
+ #### PassthroughValueConverter
104
+ ```ts
105
+ class PassthroughValueConverter implements IValueConverter<Buffer>, IValueAsyncConverter<Buffer>
106
+ ```
107
+
108
+ #### IndexKeyConverter
109
+ ```ts
110
+ class IndexKeyConverter implements IKeyConverter<number>, IKeyAsyncConverter<number> {
111
+ constructor(radix: number = 10)
112
+ }
113
+ ```
114
+
115
+ #### JSONKeyConverter
116
+ ```ts
117
+ class JSONKeyConverter<T> implements IKeyConverter<T>, IKeyAsyncConverter<T>
118
+ ```
119
+
120
+ #### JSONValueConverter
121
+ ```ts
122
+ class JSONValueConverter<T> implements IValueConverter<T>, IValueAsyncConverter<T> {
123
+ constructor(encoding: BufferEncoding = 'utf-8')
124
+ }
125
+ ```
126
+
127
+ #### LZ4ValueConverter
128
+ ```ts
129
+ class LZ4ValueConverter<T> implements IValueConverter<T>, IValueAsyncConverter<T> {
130
+ constructor(valueConverter: IValueConverter<T>)
131
+ }
132
+ ```
133
+
134
+ #### ZstandardValueConverter
135
+ ```ts
136
+ class ZstandardValueConverter<T> implements IValueConverter<T>, IValueAsyncConverter<T> {
137
+ static create<T>(
138
+ valueConverter: IValueConverter<T>
139
+ , level: number
140
+ ): Promise<ZstandardValueConverter<T>>
141
+ }
@@ -0,0 +1,7 @@
1
+ import { IKeyConverter, IKeyAsyncConverter } from "../types";
2
+ export declare class IndexKeyConverter implements IKeyConverter<number>, IKeyAsyncConverter<number> {
3
+ private radix;
4
+ constructor(radix?: number);
5
+ toString(value: number): string;
6
+ fromString(value: string): number;
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IndexKeyConverter = void 0;
4
+ class IndexKeyConverter {
5
+ constructor(radix = 10) {
6
+ this.radix = radix;
7
+ }
8
+ toString(value) {
9
+ return value.toString(this.radix);
10
+ }
11
+ fromString(value) {
12
+ return Number.parseInt(value, this.radix);
13
+ }
14
+ }
15
+ exports.IndexKeyConverter = IndexKeyConverter;
16
+ //# sourceMappingURL=index-key-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-key-converter.js","sourceRoot":"","sources":["../../src/converters/index-key-converter.ts"],"names":[],"mappings":";;;AAEA,MAAa,iBAAiB;IAC5B,YAAoB,QAAgB,EAAE;QAAlB,UAAK,GAAL,KAAK,CAAa;IAAG,CAAC;IAE1C,QAAQ,CAAC,KAAa;QACpB,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IAC3C,CAAC;CACF;AAVD,8CAUC"}
@@ -0,0 +1,7 @@
1
+ export * from './json-key-converter';
2
+ export * from './json-value-converter';
3
+ export * from './passthrough-key-converter';
4
+ export * from './passthrough-value-converter';
5
+ export * from './index-key-converter';
6
+ export * from './lz4-value-converter';
7
+ export * from './zstandard-value-converter';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./json-key-converter"), exports);
18
+ __exportStar(require("./json-value-converter"), exports);
19
+ __exportStar(require("./passthrough-key-converter"), exports);
20
+ __exportStar(require("./passthrough-value-converter"), exports);
21
+ __exportStar(require("./index-key-converter"), exports);
22
+ __exportStar(require("./lz4-value-converter"), exports);
23
+ __exportStar(require("./zstandard-value-converter"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/converters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAoC;AACpC,yDAAsC;AAEtC,8DAA2C;AAC3C,gEAA6C;AAE7C,wDAAqC;AAErC,wDAAqC;AACrC,8DAA2C"}
@@ -0,0 +1,5 @@
1
+ import { IKeyConverter, IKeyAsyncConverter } from "../types";
2
+ export declare class JSONKeyConverter<T> implements IKeyConverter<T>, IKeyAsyncConverter<T> {
3
+ fromString(value: string): T;
4
+ toString(value: T): string;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSONKeyConverter = void 0;
4
+ class JSONKeyConverter {
5
+ fromString(value) {
6
+ return JSON.parse(value);
7
+ }
8
+ toString(value) {
9
+ return JSON.stringify(value);
10
+ }
11
+ }
12
+ exports.JSONKeyConverter = JSONKeyConverter;
13
+ //# sourceMappingURL=json-key-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-key-converter.js","sourceRoot":"","sources":["../../src/converters/json-key-converter.ts"],"names":[],"mappings":";;;AAEA,MAAa,gBAAgB;IAC3B,UAAU,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,QAAQ,CAAC,KAAQ;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;CACF;AARD,4CAQC"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { IValueConverter, IValueAsyncConverter } from "../types";
3
+ export declare class JSONValueConverter<T> implements IValueConverter<T>, IValueAsyncConverter<T> {
4
+ private encoding;
5
+ constructor(encoding?: BufferEncoding);
6
+ fromBuffer(buffer: Buffer): T;
7
+ toBuffer(value: T): Buffer;
8
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSONValueConverter = void 0;
4
+ class JSONValueConverter {
5
+ constructor(encoding = 'utf-8') {
6
+ this.encoding = encoding;
7
+ }
8
+ fromBuffer(buffer) {
9
+ return JSON.parse(buffer.toString(this.encoding));
10
+ }
11
+ toBuffer(value) {
12
+ return Buffer.from(JSON.stringify(value), this.encoding);
13
+ }
14
+ }
15
+ exports.JSONValueConverter = JSONValueConverter;
16
+ //# sourceMappingURL=json-value-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-value-converter.js","sourceRoot":"","sources":["../../src/converters/json-value-converter.ts"],"names":[],"mappings":";;;AAEA,MAAa,kBAAkB;IAC7B,YAAoB,WAA2B,OAAO;QAAlC,aAAQ,GAAR,QAAQ,CAA0B;IAAG,CAAC;IAE1D,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IACnD,CAAC;IAED,QAAQ,CAAC,KAAQ;QACf,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC1D,CAAC;CACF;AAVD,gDAUC"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { IValueConverter, IValueAsyncConverter } from "../types";
3
+ export declare class LZ4ValueConverter<T> implements IValueConverter<T>, IValueAsyncConverter<T> {
4
+ private valueConverter;
5
+ constructor(valueConverter: IValueConverter<T>);
6
+ toBuffer(value: T): Buffer;
7
+ fromBuffer(value: Buffer): T;
8
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.LZ4ValueConverter = void 0;
27
+ const lz4 = __importStar(require("lz4-wasm-nodejs"));
28
+ class LZ4ValueConverter {
29
+ constructor(valueConverter) {
30
+ this.valueConverter = valueConverter;
31
+ }
32
+ toBuffer(value) {
33
+ const buffer = this.valueConverter.toBuffer(value);
34
+ return Buffer.from(lz4.compress(buffer));
35
+ }
36
+ fromBuffer(value) {
37
+ const buffer = Buffer.from(lz4.decompress(value));
38
+ return this.valueConverter.fromBuffer(buffer);
39
+ }
40
+ }
41
+ exports.LZ4ValueConverter = LZ4ValueConverter;
42
+ //# sourceMappingURL=lz4-value-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lz4-value-converter.js","sourceRoot":"","sources":["../../src/converters/lz4-value-converter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsC;AAGtC,MAAa,iBAAiB;IAC5B,YACU,cAAkC;QAAlC,mBAAc,GAAd,cAAc,CAAoB;IACzC,CAAC;IAEJ,QAAQ,CAAC,KAAQ;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAClD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;QACjD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;CACF;AAdD,8CAcC"}
@@ -0,0 +1,5 @@
1
+ import { IKeyConverter, IKeyAsyncConverter } from "../types";
2
+ export declare class PassthroughKeyConverter implements IKeyConverter<string>, IKeyAsyncConverter<string> {
3
+ toString(value: string): string;
4
+ fromString(value: string): string;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PassthroughKeyConverter = void 0;
4
+ class PassthroughKeyConverter {
5
+ toString(value) {
6
+ return value;
7
+ }
8
+ fromString(value) {
9
+ return value;
10
+ }
11
+ }
12
+ exports.PassthroughKeyConverter = PassthroughKeyConverter;
13
+ //# sourceMappingURL=passthrough-key-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passthrough-key-converter.js","sourceRoot":"","sources":["../../src/converters/passthrough-key-converter.ts"],"names":[],"mappings":";;;AAEA,MAAa,uBAAuB;IAClC,QAAQ,CAAC,KAAa;QACpB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AARD,0DAQC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { IValueConverter, IValueAsyncConverter } from "../types";
3
+ export declare class PassthroughValueConverter implements IValueConverter<Buffer>, IValueAsyncConverter<Buffer> {
4
+ toBuffer(value: Buffer): Buffer;
5
+ fromBuffer(value: Buffer): Buffer;
6
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PassthroughValueConverter = void 0;
4
+ class PassthroughValueConverter {
5
+ toBuffer(value) {
6
+ return value;
7
+ }
8
+ fromBuffer(value) {
9
+ return value;
10
+ }
11
+ }
12
+ exports.PassthroughValueConverter = PassthroughValueConverter;
13
+ //# sourceMappingURL=passthrough-value-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passthrough-value-converter.js","sourceRoot":"","sources":["../../src/converters/passthrough-value-converter.ts"],"names":[],"mappings":";;;AAEA,MAAa,yBAAyB;IACpC,QAAQ,CAAC,KAAa;QACpB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AARD,8DAQC"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import { IValueConverter, IValueAsyncConverter } from "../types";
3
+ export declare class ZstandardValueConverter<T> implements IValueConverter<T>, IValueAsyncConverter<T> {
4
+ private valueConverter;
5
+ private level;
6
+ private constructor();
7
+ static create<T>(valueConverter: IValueConverter<T>, level: number): Promise<ZstandardValueConverter<T>>;
8
+ toBuffer(value: T): Buffer;
9
+ fromBuffer(value: Buffer): T;
10
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ZstandardValueConverter = void 0;
27
+ const zstd = __importStar(require("@bokuweb/zstd-wasm"));
28
+ class ZstandardValueConverter {
29
+ constructor(valueConverter, level) {
30
+ this.valueConverter = valueConverter;
31
+ this.level = level;
32
+ }
33
+ static async create(valueConverter, level) {
34
+ await zstd.init();
35
+ return new ZstandardValueConverter(valueConverter, level);
36
+ }
37
+ toBuffer(value) {
38
+ const buffer = this.valueConverter.toBuffer(value);
39
+ return Buffer.from(zstd.compress(buffer, this.level));
40
+ }
41
+ fromBuffer(value) {
42
+ const buffer = Buffer.from(zstd.decompress(value));
43
+ return this.valueConverter.fromBuffer(buffer);
44
+ }
45
+ }
46
+ exports.ZstandardValueConverter = ZstandardValueConverter;
47
+ //# sourceMappingURL=zstandard-value-converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zstandard-value-converter.js","sourceRoot":"","sources":["../../src/converters/zstandard-value-converter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA0C;AAG1C,MAAa,uBAAuB;IAClC,YACU,cAAkC,EAClC,KAAa;QADb,mBAAc,GAAd,cAAc,CAAoB;QAClC,UAAK,GAAL,KAAK,CAAQ;IACpB,CAAC;IAEJ,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,cAAkC,EAClC,KAAa;QAEb,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACjB,OAAO,IAAI,uBAAuB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IAC3D,CAAC;IAED,QAAQ,CAAC,KAAQ;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAClD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;QAClD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;CACF;AAvBD,0DAuBC"}
@@ -0,0 +1,14 @@
1
+ import { DiskStore } from "./disk-store";
2
+ import { IKeyAsyncConverter, IValueAsyncConverter } from "./types";
3
+ export declare class DiskStoreAsyncView<K, V> {
4
+ private store;
5
+ private keyConverter;
6
+ private valueConverter;
7
+ constructor(store: DiskStore, keyConverter: IKeyAsyncConverter<K>, valueConverter: IValueAsyncConverter<V>);
8
+ has(key: K): Promise<boolean>;
9
+ get(key: K): Promise<V | undefined>;
10
+ set(key: K, value: V): Promise<void>;
11
+ delete(key: K): Promise<void>;
12
+ clear(): void;
13
+ keys(): AsyncIterable<K>;
14
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiskStoreAsyncView = void 0;
4
+ const iterable_operator_1 = require("iterable-operator");
5
+ class DiskStoreAsyncView {
6
+ constructor(store, keyConverter, valueConverter) {
7
+ this.store = store;
8
+ this.keyConverter = keyConverter;
9
+ this.valueConverter = valueConverter;
10
+ }
11
+ async has(key) {
12
+ return this.store.has(await this.keyConverter.toString(key));
13
+ }
14
+ async get(key) {
15
+ const buffer = this.store.get(await this.keyConverter.toString(key));
16
+ if (buffer) {
17
+ return await this.valueConverter.fromBuffer(buffer);
18
+ }
19
+ else {
20
+ return undefined;
21
+ }
22
+ }
23
+ async set(key, value) {
24
+ this.store.set(await this.keyConverter.toString(key), await this.valueConverter.toBuffer(value));
25
+ }
26
+ async delete(key) {
27
+ this.store.delete(await this.keyConverter.toString(key));
28
+ }
29
+ clear() {
30
+ this.store.clear();
31
+ }
32
+ keys() {
33
+ return (0, iterable_operator_1.mapAsync)(this.store.keys(), key => this.keyConverter.fromString(key));
34
+ }
35
+ }
36
+ exports.DiskStoreAsyncView = DiskStoreAsyncView;
37
+ //# sourceMappingURL=disk-store-async-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disk-store-async-view.js","sourceRoot":"","sources":["../src/disk-store-async-view.ts"],"names":[],"mappings":";;;AACA,yDAA4C;AAG5C,MAAa,kBAAkB;IAC7B,YACU,KAAgB,EAChB,YAAmC,EACnC,cAAuC;QAFvC,UAAK,GAAL,KAAK,CAAW;QAChB,iBAAY,GAAZ,YAAY,CAAuB;QACnC,mBAAc,GAAd,cAAc,CAAyB;IAC9C,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;QAEpE,IAAI,MAAM,EAAE;YACV,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;SACpD;aAAM;YACL,OAAO,SAAS,CAAA;SACjB;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM,EAAE,KAAQ;QACxB,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EACrC,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC1C,CAAA;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAM;QACjB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAED,IAAI;QACF,OAAO,IAAA,4BAAQ,EACb,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACjB,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CACzC,CAAA;IACH,CAAC;CACF;AA1CD,gDA0CC"}
@@ -0,0 +1,14 @@
1
+ import { DiskStore } from "./disk-store";
2
+ import { IKeyConverter, IValueConverter } from "./types";
3
+ export declare class DiskStoreView<K, V> {
4
+ private store;
5
+ private keyConverter;
6
+ private valueConverter;
7
+ constructor(store: DiskStore, keyConverter: IKeyConverter<K>, valueConverter: IValueConverter<V>);
8
+ has(key: K): boolean;
9
+ get(key: K): V | undefined;
10
+ set(key: K, value: V): void;
11
+ delete(key: K): void;
12
+ clear(): void;
13
+ keys(): Iterable<K>;
14
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiskStoreView = void 0;
4
+ const iterable_operator_1 = require("iterable-operator");
5
+ class DiskStoreView {
6
+ constructor(store, keyConverter, valueConverter) {
7
+ this.store = store;
8
+ this.keyConverter = keyConverter;
9
+ this.valueConverter = valueConverter;
10
+ }
11
+ has(key) {
12
+ return this.store.has(this.keyConverter.toString(key));
13
+ }
14
+ get(key) {
15
+ const buffer = this.store.get(this.keyConverter.toString(key));
16
+ if (buffer) {
17
+ return this.valueConverter.fromBuffer(buffer);
18
+ }
19
+ else {
20
+ return undefined;
21
+ }
22
+ }
23
+ set(key, value) {
24
+ this.store.set(this.keyConverter.toString(key), this.valueConverter.toBuffer(value));
25
+ }
26
+ delete(key) {
27
+ this.store.delete(this.keyConverter.toString(key));
28
+ }
29
+ clear() {
30
+ this.store.clear();
31
+ }
32
+ keys() {
33
+ return (0, iterable_operator_1.map)(this.store.keys(), key => this.keyConverter.fromString(key));
34
+ }
35
+ }
36
+ exports.DiskStoreView = DiskStoreView;
37
+ //# sourceMappingURL=disk-store-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disk-store-view.js","sourceRoot":"","sources":["../src/disk-store-view.ts"],"names":[],"mappings":";;;AACA,yDAAuC;AAGvC,MAAa,aAAa;IACxB,YACU,KAAgB,EAChB,YAA8B,EAC9B,cAAkC;QAFlC,UAAK,GAAL,KAAK,CAAW;QAChB,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,mBAAc,GAAd,cAAc,CAAoB;IACzC,CAAC;IAEJ,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IACxD,CAAC;IAED,GAAG,CAAC,GAAM;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;QAE9D,IAAI,MAAM,EAAE;YACV,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;SAC9C;aAAM;YACL,OAAO,SAAS,CAAA;SACjB;IACH,CAAC;IAED,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC/B,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CACpC,CAAA;IACH,CAAC;IAED,MAAM,CAAC,GAAM;QACX,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IACpD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAED,IAAI;QACF,OAAO,IAAA,uBAAG,EACR,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACjB,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CACzC,CAAA;IACH,CAAC;CACF;AA1CD,sCA0CC"}
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { Database as IDatabase } from 'better-sqlite3';
3
+ export declare class DiskStore {
4
+ _db: IDatabase;
5
+ protected constructor(_db: IDatabase);
6
+ static create(filename?: string): Promise<DiskStore>;
7
+ close(): void;
8
+ has: (key: string) => boolean;
9
+ get: (key: string) => Buffer | undefined;
10
+ set: (key: string, value: Buffer) => void;
11
+ delete: (key: string) => void;
12
+ clear: () => void;
13
+ keys: () => Iterable<string>;
14
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DiskStore = void 0;
30
+ const path_1 = __importDefault(require("path"));
31
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
32
+ const migration_files_1 = require("migration-files");
33
+ const better_sqlite3_migrations_1 = require("@blackglory/better-sqlite3-migrations");
34
+ const prelude_1 = require("@blackglory/prelude");
35
+ const extra_promise_1 = require("extra-promise");
36
+ const extra_filesystem_1 = require("extra-filesystem");
37
+ const Iter = __importStar(require("iterable-operator"));
38
+ const extra_lazy_1 = require("extra-lazy");
39
+ class DiskStore {
40
+ constructor(_db) {
41
+ this._db = _db;
42
+ this.has = (0, extra_lazy_1.withLazyStatic)((key) => {
43
+ const row = (0, extra_lazy_1.lazyStatic)(() => this._db.prepare(`
44
+ SELECT EXISTS(
45
+ SELECT *
46
+ FROM store
47
+ WHERE key = $key
48
+ ) AS item_exists
49
+ `), [this._db]).get({ key });
50
+ return row.item_exists === 1;
51
+ });
52
+ this.get = (0, extra_lazy_1.withLazyStatic)((key) => {
53
+ const row = (0, extra_lazy_1.lazyStatic)(() => this._db.prepare(`
54
+ SELECT value
55
+ FROM store
56
+ WHERE key = $key
57
+ `), [this._db]).get({ key });
58
+ if ((0, prelude_1.isUndefined)(row))
59
+ return undefined;
60
+ return row.value;
61
+ });
62
+ this.set = (0, extra_lazy_1.withLazyStatic)((key, value) => {
63
+ (0, extra_lazy_1.lazyStatic)(() => this._db.prepare(`
64
+ INSERT INTO store (
65
+ key
66
+ , value
67
+ )
68
+ VALUES ($key, $value)
69
+ ON CONFLICT(key)
70
+ DO UPDATE SET value = $value
71
+ `), [this._db]).run({ key, value });
72
+ });
73
+ this.delete = (0, extra_lazy_1.withLazyStatic)((key) => {
74
+ (0, extra_lazy_1.lazyStatic)(() => this._db.prepare(`
75
+ DELETE FROM store
76
+ WHERE key = $key
77
+ `), [this._db]).run({ key });
78
+ });
79
+ this.clear = (0, extra_lazy_1.withLazyStatic)(() => {
80
+ (0, extra_lazy_1.lazyStatic)(() => this._db.prepare(`
81
+ DELETE FROM store
82
+ `), [this._db]).run();
83
+ });
84
+ this.keys = (0, extra_lazy_1.withLazyStatic)(() => {
85
+ const iter = (0, extra_lazy_1.lazyStatic)(() => this._db.prepare(`
86
+ SELECT key
87
+ FROM store
88
+ `), [this._db]).iterate();
89
+ return Iter.map(iter, ({ key }) => key);
90
+ });
91
+ }
92
+ static async create(filename) {
93
+ const db = await (0, prelude_1.go)(async () => {
94
+ const db = new better_sqlite3_1.default(filename !== null && filename !== void 0 ? filename : ':memory:');
95
+ await migrateDatabase(db);
96
+ return db;
97
+ });
98
+ const diskStore = new this(db);
99
+ return diskStore;
100
+ async function migrateDatabase(db) {
101
+ const packageFilename = await (0, extra_filesystem_1.findUpPackageFilename)(__dirname);
102
+ (0, prelude_1.assert)(packageFilename, 'package.json not found');
103
+ const packageRoot = path_1.default.dirname(packageFilename);
104
+ const migrationsPath = path_1.default.join(packageRoot, 'migrations');
105
+ const migrationFilenames = await (0, migration_files_1.findMigrationFilenames)(migrationsPath);
106
+ const migrations = await (0, extra_promise_1.map)(migrationFilenames, migration_files_1.readMigrationFile);
107
+ (0, better_sqlite3_migrations_1.migrate)(db, migrations);
108
+ }
109
+ }
110
+ close() {
111
+ this._db.exec(`
112
+ PRAGMA analysis_limit=400;
113
+ PRAGMA optimize;
114
+ `);
115
+ this._db.close();
116
+ }
117
+ }
118
+ exports.DiskStore = DiskStore;
119
+ //# sourceMappingURL=disk-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disk-store.js","sourceRoot":"","sources":["../src/disk-store.ts"],"names":[],"mappings":"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"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './disk-store';
2
+ export * from './disk-store-view';
3
+ export * from './disk-store-async-view';
4
+ export * from './converters';
5
+ export * from './types';
package/lib/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./disk-store"), exports);
18
+ __exportStar(require("./disk-store-view"), exports);
19
+ __exportStar(require("./disk-store-async-view"), exports);
20
+ __exportStar(require("./converters"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,oDAAiC;AACjC,0DAAuC;AACvC,+CAA4B;AAC5B,0CAAuB"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ import { Awaitable } from '@blackglory/prelude';
3
+ export interface IKeyConverter<T> {
4
+ toString: (value: T) => string;
5
+ fromString: (value: string) => T;
6
+ }
7
+ export interface IValueConverter<T> {
8
+ toBuffer: (value: T) => Buffer;
9
+ fromBuffer: (value: Buffer) => T;
10
+ }
11
+ export interface IKeyAsyncConverter<T> {
12
+ toString: (value: T) => Awaitable<string>;
13
+ fromString: (value: string) => Awaitable<T>;
14
+ }
15
+ export interface IValueAsyncConverter<T> {
16
+ toBuffer: (value: T) => Awaitable<Buffer>;
17
+ fromBuffer: (value: Buffer) => Awaitable<T>;
18
+ }
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ --------------------------------------------------------------------------------
2
+ -- Up
3
+ --------------------------------------------------------------------------------
4
+
5
+ -- 在WAL模式下, better-sqlite3可充分发挥性能
6
+ PRAGMA journal_mode = WAL;
7
+
8
+ CREATE TABLE store (
9
+ key TEXT NOT NULL UNIQUE
10
+ , value BLOB NOT NULL
11
+ ) STRICT;
12
+
13
+ --------------------------------------------------------------------------------
14
+ -- Down
15
+ --------------------------------------------------------------------------------
16
+
17
+ PRAGMA journal_mode = DELETE;
18
+
19
+ DROP TABLE store;
@@ -0,0 +1,7 @@
1
+ -- 在WAL模式下, better-sqlite3可充分发挥性能
2
+ PRAGMA journal_mode = WAL;
3
+
4
+ CREATE TABLE store (
5
+ key TEXT NOT NULL UNIQUE
6
+ , value BLOB NOT NULL
7
+ ) STRICT;
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "extra-disk-store",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "files": [
7
+ "lib",
8
+ "migrations"
9
+ ],
10
+ "main": "lib/index.js",
11
+ "types": "lib/index.d.ts",
12
+ "repository": "git@github.com:BlackGlory/extra-disk-store.git",
13
+ "author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
14
+ "license": "MIT",
15
+ "sideEffects": false,
16
+ "engines": {
17
+ "node": ">=14"
18
+ },
19
+ "scripts": {
20
+ "prepare": "ts-patch install -s",
21
+ "lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
22
+ "test": "jest --runInBand --config jest.config.js",
23
+ "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --config jest.config.js",
24
+ "test:coverage": "jest --runInBand --coverage --config jest.config.js",
25
+ "prepublishOnly": "run-s prepare clean build",
26
+ "clean": "rimraf lib",
27
+ "build": "run-s build:*",
28
+ "build:compile": "tsc --project tsconfig.build.json --target es2018 --outDir lib",
29
+ "release": "standard-version"
30
+ },
31
+ "husky": {
32
+ "hooks": {
33
+ "pre-commit": "run-s prepare lint build test",
34
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
35
+ }
36
+ },
37
+ "devDependencies": {
38
+ "@blackglory/jest-matchers": "^0.5.0",
39
+ "@commitlint/cli": "^17.3.0",
40
+ "@commitlint/config-conventional": "^17.3.0",
41
+ "@types/better-sqlite3": "^7.6.2",
42
+ "@types/jest": "^29.2.3",
43
+ "@types/node": "14",
44
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
45
+ "@typescript-eslint/parser": "^5.45.0",
46
+ "eslint": "^8.28.0",
47
+ "husky": "^4.3.0",
48
+ "jest": "^29.3.1",
49
+ "npm-run-all": "^4.1.5",
50
+ "rimraf": "^3.0.2",
51
+ "standard-version": "^9.5.0",
52
+ "ts-jest": "^29.0.3",
53
+ "ts-patch": "^2.0.2",
54
+ "typescript": "4.8",
55
+ "typescript-transform-paths": "^3.4.4"
56
+ },
57
+ "dependencies": {
58
+ "@blackglory/better-sqlite3-migrations": "^0.1.16",
59
+ "@blackglory/prelude": "^0.1.8",
60
+ "@blackglory/types": "^1.4.0",
61
+ "@bokuweb/zstd-wasm": "^0.0.17",
62
+ "better-sqlite3": "^8.0.0",
63
+ "extra-filesystem": "^0.4.8",
64
+ "extra-lazy": "^1.3.1",
65
+ "extra-promise": "^4.4.0",
66
+ "extra-timers": "^0.2.5",
67
+ "iterable-operator": "^2.5.0",
68
+ "lz4-wasm-nodejs": "^0.9.2",
69
+ "migration-files": "^0.4.0"
70
+ }
71
+ }