@atlaspack/cache 2.13.3 → 3.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/CHANGELOG.md +14 -0
- package/index.d.ts +0 -4
- package/lib/index.js +0 -11
- package/package.json +6 -8
- package/src/index.js +0 -1
- package/lib/LMDBCache.js +0 -136
- package/src/LMDBCache.js +0 -139
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @atlaspack/cache
|
2
2
|
|
3
|
+
## 3.0.0
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- [#512](https://github.com/atlassian-labs/atlaspack/pull/512) [`8f4e6c1`](https://github.com/atlassian-labs/atlaspack/commit/8f4e6c1b0e7c1fd48624afda48c1dcc599f1460f) Thanks [@yamadapc](https://github.com/yamadapc)! - Remove LMDB cache back-end
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- Updated dependencies [[`a891d65`](https://github.com/atlassian-labs/atlaspack/commit/a891d652bc4eb3d757d381adf65c5083f706effc), [`d02eab9`](https://github.com/atlassian-labs/atlaspack/commit/d02eab95eb60bf7457e0869af0b773608592c0e6), [`fb87a90`](https://github.com/atlassian-labs/atlaspack/commit/fb87a901973776b33ca4ce530e9d71669a9bd36d), [`7b9e8cf`](https://github.com/atlassian-labs/atlaspack/commit/7b9e8cf29e01a98e72e46b2b2fb74ccc514f4463)]:
|
12
|
+
- @atlaspack/rust@3.1.0
|
13
|
+
- @atlaspack/fs@2.14.2
|
14
|
+
- @atlaspack/utils@2.14.2
|
15
|
+
- @atlaspack/logger@2.14.2
|
16
|
+
|
3
17
|
## 2.13.3
|
4
18
|
|
5
19
|
### Patch Changes
|
package/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -25,17 +25,6 @@ Object.keys(_IDBCache).forEach(function (key) {
|
|
25
25
|
}
|
26
26
|
});
|
27
27
|
});
|
28
|
-
var _LMDBCache = require("./LMDBCache");
|
29
|
-
Object.keys(_LMDBCache).forEach(function (key) {
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
31
|
-
if (key in exports && exports[key] === _LMDBCache[key]) return;
|
32
|
-
Object.defineProperty(exports, key, {
|
33
|
-
enumerable: true,
|
34
|
-
get: function () {
|
35
|
-
return _LMDBCache[key];
|
36
|
-
}
|
37
|
-
});
|
38
|
-
});
|
39
28
|
var _LMDBLiteCache = require("./LMDBLiteCache");
|
40
29
|
Object.keys(_LMDBLiteCache).forEach(function (key) {
|
41
30
|
if (key === "default" || key === "__esModule") return;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/cache",
|
3
3
|
"description": "Interface for defining caches and file-system, IDB and LMDB implementations.",
|
4
|
-
"version": "
|
4
|
+
"version": "3.0.0",
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
6
6
|
"type": "commonjs",
|
7
7
|
"publishConfig": {
|
@@ -24,17 +24,15 @@
|
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
26
|
"@atlaspack/build-cache": "2.13.3",
|
27
|
-
"@atlaspack/fs": "2.14.
|
28
|
-
"@atlaspack/logger": "2.14.
|
29
|
-
"@atlaspack/rust": "3.0
|
30
|
-
"@atlaspack/utils": "2.14.
|
31
|
-
"lmdb": "2.8.5"
|
27
|
+
"@atlaspack/fs": "2.14.2",
|
28
|
+
"@atlaspack/logger": "2.14.2",
|
29
|
+
"@atlaspack/rust": "3.1.0",
|
30
|
+
"@atlaspack/utils": "2.14.2"
|
32
31
|
},
|
33
32
|
"devDependencies": {
|
34
33
|
"idb": "^5.0.8"
|
35
34
|
},
|
36
35
|
"browser": {
|
37
|
-
"./src/IDBCache.js": "./src/IDBCache.browser.js"
|
38
|
-
"./src/LMDBCache.js": false
|
36
|
+
"./src/IDBCache.js": "./src/IDBCache.browser.js"
|
39
37
|
}
|
40
38
|
}
|
package/src/index.js
CHANGED
package/lib/LMDBCache.js
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.LMDBCache = void 0;
|
7
|
-
function _stream() {
|
8
|
-
const data = _interopRequireDefault(require("stream"));
|
9
|
-
_stream = function () {
|
10
|
-
return data;
|
11
|
-
};
|
12
|
-
return data;
|
13
|
-
}
|
14
|
-
function _path() {
|
15
|
-
const data = _interopRequireDefault(require("path"));
|
16
|
-
_path = function () {
|
17
|
-
return data;
|
18
|
-
};
|
19
|
-
return data;
|
20
|
-
}
|
21
|
-
function _util() {
|
22
|
-
const data = require("util");
|
23
|
-
_util = function () {
|
24
|
-
return data;
|
25
|
-
};
|
26
|
-
return data;
|
27
|
-
}
|
28
|
-
function _buildCache() {
|
29
|
-
const data = require("@atlaspack/build-cache");
|
30
|
-
_buildCache = function () {
|
31
|
-
return data;
|
32
|
-
};
|
33
|
-
return data;
|
34
|
-
}
|
35
|
-
function _fs() {
|
36
|
-
const data = require("@atlaspack/fs");
|
37
|
-
_fs = function () {
|
38
|
-
return data;
|
39
|
-
};
|
40
|
-
return data;
|
41
|
-
}
|
42
|
-
function _lmdb() {
|
43
|
-
const data = _interopRequireDefault(require("lmdb"));
|
44
|
-
_lmdb = function () {
|
45
|
-
return data;
|
46
|
-
};
|
47
|
-
return data;
|
48
|
-
}
|
49
|
-
var _package = _interopRequireDefault(require("../package.json"));
|
50
|
-
var _FSCache = require("./FSCache");
|
51
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
52
|
-
// flowlint-next-line untyped-import:off
|
53
|
-
// $FlowFixMe
|
54
|
-
const pipeline = (0, _util().promisify)(_stream().default.pipeline);
|
55
|
-
class LMDBCache {
|
56
|
-
// $FlowFixMe
|
57
|
-
|
58
|
-
constructor(cacheDir) {
|
59
|
-
this.fs = new (_fs().NodeFS)();
|
60
|
-
this.dir = cacheDir;
|
61
|
-
this.fsCache = new _FSCache.FSCache(this.fs, cacheDir);
|
62
|
-
this.store = _lmdb().default.open(cacheDir, {
|
63
|
-
name: 'parcel-cache',
|
64
|
-
encoding: 'binary',
|
65
|
-
compression: true
|
66
|
-
});
|
67
|
-
}
|
68
|
-
ensure() {
|
69
|
-
return Promise.resolve();
|
70
|
-
}
|
71
|
-
serialize() {
|
72
|
-
return {
|
73
|
-
dir: this.dir
|
74
|
-
};
|
75
|
-
}
|
76
|
-
static deserialize(opts) {
|
77
|
-
return new LMDBCache(opts.dir);
|
78
|
-
}
|
79
|
-
has(key) {
|
80
|
-
return Promise.resolve(this.store.get(key) != null);
|
81
|
-
}
|
82
|
-
get(key) {
|
83
|
-
let data = this.store.get(key);
|
84
|
-
if (data == null) {
|
85
|
-
return Promise.resolve(null);
|
86
|
-
}
|
87
|
-
return Promise.resolve((0, _buildCache().deserialize)(data));
|
88
|
-
}
|
89
|
-
async set(key, value) {
|
90
|
-
await this.setBlob(key, (0, _buildCache().serialize)(value));
|
91
|
-
}
|
92
|
-
getStream(key) {
|
93
|
-
return this.fs.createReadStream(_path().default.join(this.dir, key));
|
94
|
-
}
|
95
|
-
setStream(key, stream) {
|
96
|
-
return pipeline(stream, this.fs.createWriteStream(_path().default.join(this.dir, key)));
|
97
|
-
}
|
98
|
-
getBlob(key) {
|
99
|
-
let buffer = this.store.get(key);
|
100
|
-
return buffer != null ? Promise.resolve(buffer) : Promise.reject(new Error(`Key ${key} not found in cache`));
|
101
|
-
}
|
102
|
-
async setBlob(key, contents) {
|
103
|
-
await this.store.put(key, contents);
|
104
|
-
}
|
105
|
-
getBuffer(key) {
|
106
|
-
return Promise.resolve(this.store.get(key));
|
107
|
-
}
|
108
|
-
#getFilePath(key, index) {
|
109
|
-
return _path().default.join(this.dir, `${key}-${index}`);
|
110
|
-
}
|
111
|
-
hasLargeBlob(key) {
|
112
|
-
return this.fs.exists(this.#getFilePath(key, 0));
|
113
|
-
}
|
114
|
-
|
115
|
-
// eslint-disable-next-line require-await
|
116
|
-
async getLargeBlob(key) {
|
117
|
-
return this.fsCache.getLargeBlob(key);
|
118
|
-
}
|
119
|
-
|
120
|
-
// eslint-disable-next-line require-await
|
121
|
-
async setLargeBlob(key, contents, options) {
|
122
|
-
return this.fsCache.setLargeBlob(key, contents, options);
|
123
|
-
}
|
124
|
-
deleteLargeBlob(key) {
|
125
|
-
return this.fsCache.deleteLargeBlob(key);
|
126
|
-
}
|
127
|
-
refresh() {
|
128
|
-
// Reset the read transaction for the store. This guarantees that
|
129
|
-
// the next read will see the latest changes to the store.
|
130
|
-
// Useful in scenarios where reads and writes are multi-threaded.
|
131
|
-
// See https://github.com/kriszyp/lmdb-js#resetreadtxn-void
|
132
|
-
this.store.resetReadTxn();
|
133
|
-
}
|
134
|
-
}
|
135
|
-
exports.LMDBCache = LMDBCache;
|
136
|
-
(0, _buildCache().registerSerializableClass)(`${_package.default.version}:LMDBCache`, LMDBCache);
|
package/src/LMDBCache.js
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
// @flow strict-local
|
2
|
-
import type {FilePath} from '@atlaspack/types';
|
3
|
-
import type {Cache} from './types';
|
4
|
-
import type {Readable, Writable} from 'stream';
|
5
|
-
|
6
|
-
import stream from 'stream';
|
7
|
-
import path from 'path';
|
8
|
-
import {promisify} from 'util';
|
9
|
-
|
10
|
-
import {
|
11
|
-
deserialize,
|
12
|
-
registerSerializableClass,
|
13
|
-
serialize,
|
14
|
-
} from '@atlaspack/build-cache';
|
15
|
-
import {NodeFS} from '@atlaspack/fs';
|
16
|
-
// flowlint-next-line untyped-import:off
|
17
|
-
import lmdb from 'lmdb';
|
18
|
-
|
19
|
-
// $FlowFixMe
|
20
|
-
import packageJson from '../package.json';
|
21
|
-
|
22
|
-
import {FSCache} from './FSCache';
|
23
|
-
|
24
|
-
const pipeline: (Readable, Writable) => Promise<void> = promisify(
|
25
|
-
stream.pipeline,
|
26
|
-
);
|
27
|
-
|
28
|
-
export class LMDBCache implements Cache {
|
29
|
-
fs: NodeFS;
|
30
|
-
dir: FilePath;
|
31
|
-
// $FlowFixMe
|
32
|
-
store: any;
|
33
|
-
fsCache: FSCache;
|
34
|
-
|
35
|
-
constructor(cacheDir: FilePath) {
|
36
|
-
this.fs = new NodeFS();
|
37
|
-
this.dir = cacheDir;
|
38
|
-
this.fsCache = new FSCache(this.fs, cacheDir);
|
39
|
-
|
40
|
-
this.store = lmdb.open(cacheDir, {
|
41
|
-
name: 'parcel-cache',
|
42
|
-
encoding: 'binary',
|
43
|
-
compression: true,
|
44
|
-
});
|
45
|
-
}
|
46
|
-
|
47
|
-
ensure(): Promise<void> {
|
48
|
-
return Promise.resolve();
|
49
|
-
}
|
50
|
-
|
51
|
-
serialize(): {|dir: FilePath|} {
|
52
|
-
return {
|
53
|
-
dir: this.dir,
|
54
|
-
};
|
55
|
-
}
|
56
|
-
|
57
|
-
static deserialize(opts: {|dir: FilePath|}): LMDBCache {
|
58
|
-
return new LMDBCache(opts.dir);
|
59
|
-
}
|
60
|
-
|
61
|
-
has(key: string): Promise<boolean> {
|
62
|
-
return Promise.resolve(this.store.get(key) != null);
|
63
|
-
}
|
64
|
-
|
65
|
-
get<T>(key: string): Promise<?T> {
|
66
|
-
let data = this.store.get(key);
|
67
|
-
if (data == null) {
|
68
|
-
return Promise.resolve(null);
|
69
|
-
}
|
70
|
-
|
71
|
-
return Promise.resolve(deserialize(data));
|
72
|
-
}
|
73
|
-
|
74
|
-
async set(key: string, value: mixed): Promise<void> {
|
75
|
-
await this.setBlob(key, serialize(value));
|
76
|
-
}
|
77
|
-
|
78
|
-
getStream(key: string): Readable {
|
79
|
-
return this.fs.createReadStream(path.join(this.dir, key));
|
80
|
-
}
|
81
|
-
|
82
|
-
setStream(key: string, stream: Readable): Promise<void> {
|
83
|
-
return pipeline(
|
84
|
-
stream,
|
85
|
-
this.fs.createWriteStream(path.join(this.dir, key)),
|
86
|
-
);
|
87
|
-
}
|
88
|
-
|
89
|
-
getBlob(key: string): Promise<Buffer> {
|
90
|
-
let buffer = this.store.get(key);
|
91
|
-
return buffer != null
|
92
|
-
? Promise.resolve(buffer)
|
93
|
-
: Promise.reject(new Error(`Key ${key} not found in cache`));
|
94
|
-
}
|
95
|
-
|
96
|
-
async setBlob(key: string, contents: Buffer | string): Promise<void> {
|
97
|
-
await this.store.put(key, contents);
|
98
|
-
}
|
99
|
-
|
100
|
-
getBuffer(key: string): Promise<?Buffer> {
|
101
|
-
return Promise.resolve(this.store.get(key));
|
102
|
-
}
|
103
|
-
|
104
|
-
#getFilePath(key: string, index: number): string {
|
105
|
-
return path.join(this.dir, `${key}-${index}`);
|
106
|
-
}
|
107
|
-
|
108
|
-
hasLargeBlob(key: string): Promise<boolean> {
|
109
|
-
return this.fs.exists(this.#getFilePath(key, 0));
|
110
|
-
}
|
111
|
-
|
112
|
-
// eslint-disable-next-line require-await
|
113
|
-
async getLargeBlob(key: string): Promise<Buffer> {
|
114
|
-
return this.fsCache.getLargeBlob(key);
|
115
|
-
}
|
116
|
-
|
117
|
-
// eslint-disable-next-line require-await
|
118
|
-
async setLargeBlob(
|
119
|
-
key: string,
|
120
|
-
contents: Buffer | string,
|
121
|
-
options?: {|signal?: AbortSignal|},
|
122
|
-
): Promise<void> {
|
123
|
-
return this.fsCache.setLargeBlob(key, contents, options);
|
124
|
-
}
|
125
|
-
|
126
|
-
deleteLargeBlob(key: string): Promise<void> {
|
127
|
-
return this.fsCache.deleteLargeBlob(key);
|
128
|
-
}
|
129
|
-
|
130
|
-
refresh(): void {
|
131
|
-
// Reset the read transaction for the store. This guarantees that
|
132
|
-
// the next read will see the latest changes to the store.
|
133
|
-
// Useful in scenarios where reads and writes are multi-threaded.
|
134
|
-
// See https://github.com/kriszyp/lmdb-js#resetreadtxn-void
|
135
|
-
this.store.resetReadTxn();
|
136
|
-
}
|
137
|
-
}
|
138
|
-
|
139
|
-
registerSerializableClass(`${packageJson.version}:LMDBCache`, LMDBCache);
|