@atlaspack/cache 3.2.16-typescript-bc4459c37.0 → 3.2.16
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 +9 -0
- package/index.d.ts +13 -0
- package/lib/FSCache.js +3 -14
- package/lib/IDBCache.browser.js +6 -7
- package/lib/IDBCache.js +1 -1
- package/lib/LMDBLiteCache.js +1 -2
- package/lib/types.d.ts +1 -1
- package/package.json +14 -14
- package/src/{FSCache.ts → FSCache.js} +15 -21
- package/src/{IDBCache.browser.ts → IDBCache.browser.js} +10 -8
- package/src/{IDBCache.ts → IDBCache.js} +2 -1
- package/src/{LMDBLiteCache.ts → LMDBLiteCache.js} +11 -11
- package/src/{constants.ts → constants.js} +2 -0
- package/src/{index.ts → index.js} +2 -0
- package/src/{types.ts → types.js} +1 -0
- package/test/{LMDBLiteCache.test.ts → LMDBLiteCache.test.js} +11 -9
- package/LICENSE +0 -201
- package/lib/FSCache.d.ts +0 -27
- package/lib/IDBCache.browser.d.ts +0 -22
- package/lib/IDBCache.d.ts +0 -4
- package/lib/LMDBLiteCache.d.ts +0 -78
- package/lib/constants.d.ts +0 -1
- package/lib/index.d.ts +0 -4
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# @atlaspack/cache
|
2
2
|
|
3
|
+
## 3.2.16
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
|
8
|
+
- @atlaspack/feature-flags@2.20.0
|
9
|
+
- @atlaspack/fs@2.15.16
|
10
|
+
- @atlaspack/utils@2.17.3
|
11
|
+
|
3
12
|
## 3.2.15
|
4
13
|
|
5
14
|
### Patch Changes
|
package/index.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import type {FilePath} from '@atlaspack/types';
|
2
|
+
|
3
|
+
import type {Cache} from './lib/types';
|
4
|
+
|
5
|
+
export type {Cache} from './lib/types';
|
6
|
+
|
7
|
+
export const FSCache: {
|
8
|
+
new (cacheDir: FilePath): Cache;
|
9
|
+
};
|
10
|
+
|
11
|
+
export const LMDBLiteCache: {
|
12
|
+
new (cacheDir: FilePath): Cache;
|
13
|
+
};
|
package/lib/FSCache.js
CHANGED
@@ -57,7 +57,6 @@ var _package = _interopRequireDefault(require("../package.json"));
|
|
57
57
|
var _constants = require("./constants");
|
58
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
59
59
|
// flowlint-next-line untyped-import:off
|
60
|
-
|
61
60
|
const pipeline = (0, _util().promisify)(_stream().default.pipeline);
|
62
61
|
class FSCache {
|
63
62
|
constructor(fs, cacheDir) {
|
@@ -72,9 +71,7 @@ class FSCache {
|
|
72
71
|
// This speeds up large caches on many file systems since there are fewer files in a single directory.
|
73
72
|
let dirPromises = [];
|
74
73
|
for (let i = 0; i < 256; i++) {
|
75
|
-
dirPromises.push(
|
76
|
-
// @ts-expect-error TS2345
|
77
|
-
this.fs.mkdirp(_path().default.join(this.dir, ('00' + i.toString(16)).slice(-2))));
|
74
|
+
dirPromises.push(this.fs.mkdirp(_path().default.join(this.dir, ('00' + i.toString(16)).slice(-2))));
|
78
75
|
}
|
79
76
|
await Promise.all(dirPromises);
|
80
77
|
}
|
@@ -141,19 +138,12 @@ class FSCache {
|
|
141
138
|
const writePromises = [];
|
142
139
|
if (chunks === 1) {
|
143
140
|
// If there's one chunk, don't slice the content
|
144
|
-
writePromises.push(
|
145
|
-
// @ts-expect-error TS2345
|
146
|
-
this.fs.writeFile(this.#getFilePath(key, 0), contents, {
|
147
|
-
// @ts-expect-error TS2353
|
141
|
+
writePromises.push(this.fs.writeFile(this.#getFilePath(key, 0), contents, {
|
148
142
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
149
143
|
}));
|
150
144
|
} else {
|
151
145
|
for (let i = 0; i < chunks; i += 1) {
|
152
|
-
writePromises.push(
|
153
|
-
// @ts-expect-error TS2345
|
154
|
-
this.fs.writeFile(this.#getFilePath(key, i), typeof contents === 'string' ? contents.slice(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK) : contents.subarray(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK),
|
155
|
-
// @ts-expect-error TS2353
|
156
|
-
{
|
146
|
+
writePromises.push(this.fs.writeFile(this.#getFilePath(key, i), typeof contents === 'string' ? contents.slice(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK) : contents.subarray(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK), {
|
157
147
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
158
148
|
}));
|
159
149
|
}
|
@@ -168,7 +158,6 @@ class FSCache {
|
|
168
158
|
let i = 0;
|
169
159
|
let filePath = this.#getFilePath(key, i);
|
170
160
|
while (await this.fs.exists(filePath)) {
|
171
|
-
// @ts-expect-error TS2345
|
172
161
|
deletePromises.push(this.fs.rimraf(filePath));
|
173
162
|
i += 1;
|
174
163
|
filePath = this.#getFilePath(key, i);
|
package/lib/IDBCache.browser.js
CHANGED
@@ -34,8 +34,12 @@ function _idb() {
|
|
34
34
|
}
|
35
35
|
var _package = _interopRequireDefault(require("../package.json"));
|
36
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37
|
+
// $FlowFixMe[untyped-import]
|
38
|
+
// $FlowFixMe[untyped-import]
|
37
39
|
const STORE_NAME = 'cache';
|
38
40
|
class IDBCache {
|
41
|
+
// $FlowFixMe
|
42
|
+
|
39
43
|
constructor() {
|
40
44
|
this.store = (0, _idb().openDB)('REPL-parcel-cache', 1, {
|
41
45
|
upgrade(db) {
|
@@ -71,14 +75,9 @@ class IDBCache {
|
|
71
75
|
await (await this.store).put(STORE_NAME, (0, _buildCache().serialize)(value), key);
|
72
76
|
}
|
73
77
|
getStream(key) {
|
74
|
-
let dataPromise = this.store
|
75
|
-
// @ts-expect-error TS7006
|
76
|
-
.then(s => s.get(STORE_NAME, key))
|
77
|
-
// @ts-expect-error TS7006
|
78
|
-
.then(d => Buffer.from(d))
|
79
|
-
// @ts-expect-error TS7006
|
80
|
-
.catch(e => e);
|
78
|
+
let dataPromise = this.store.then(s => s.get(STORE_NAME, key)).then(d => Buffer.from(d)).catch(e => e);
|
81
79
|
const stream = new (_stream().Readable)({
|
80
|
+
// $FlowFixMe(incompatible-call)
|
82
81
|
async read() {
|
83
82
|
let data = await dataPromise;
|
84
83
|
if (data instanceof Error) {
|
package/lib/IDBCache.js
CHANGED
package/lib/LMDBLiteCache.js
CHANGED
@@ -71,8 +71,7 @@ function _logger() {
|
|
71
71
|
return data;
|
72
72
|
}
|
73
73
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
74
|
-
//
|
75
|
-
|
74
|
+
// $FlowFixMe
|
76
75
|
const ncpAsync = (0, _util().promisify)(_ncp().default);
|
77
76
|
class LmdbWrapper {
|
78
77
|
constructor(lmdb) {
|
package/lib/types.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import type { Cache } from
|
1
|
+
import type { Cache } from "@atlaspack/types";
|
2
2
|
export type { Cache };
|
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": "3.2.16
|
4
|
+
"version": "3.2.16",
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
6
6
|
"type": "commonjs",
|
7
7
|
"publishConfig": {
|
@@ -11,23 +11,24 @@
|
|
11
11
|
"type": "git",
|
12
12
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
13
13
|
},
|
14
|
-
"main": "
|
15
|
-
"source": "
|
16
|
-
"types": "
|
14
|
+
"main": "lib/index.js",
|
15
|
+
"source": "src/index.js",
|
16
|
+
"types": "index.d.ts",
|
17
17
|
"engines": {
|
18
18
|
"node": ">= 16.0.0"
|
19
19
|
},
|
20
20
|
"scripts": {
|
21
21
|
"test": "mocha",
|
22
|
-
"
|
22
|
+
"build-ts": "mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts",
|
23
|
+
"check-ts": "tsc --noEmit index.d.ts"
|
23
24
|
},
|
24
25
|
"dependencies": {
|
25
|
-
"@atlaspack/build-cache": "2.13.
|
26
|
-
"@atlaspack/feature-flags": "2.
|
27
|
-
"@atlaspack/fs": "2.15.16
|
28
|
-
"@atlaspack/logger": "2.14.
|
29
|
-
"@atlaspack/rust": "3.4.
|
30
|
-
"@atlaspack/utils": "2.17.3
|
26
|
+
"@atlaspack/build-cache": "2.13.3",
|
27
|
+
"@atlaspack/feature-flags": "2.20.0",
|
28
|
+
"@atlaspack/fs": "2.15.16",
|
29
|
+
"@atlaspack/logger": "2.14.13",
|
30
|
+
"@atlaspack/rust": "3.4.1",
|
31
|
+
"@atlaspack/utils": "2.17.3",
|
31
32
|
"ncp": "^2.0.0"
|
32
33
|
},
|
33
34
|
"devDependencies": {
|
@@ -35,6 +36,5 @@
|
|
35
36
|
},
|
36
37
|
"browser": {
|
37
38
|
"./src/IDBCache.js": "./src/IDBCache.browser.js"
|
38
|
-
}
|
39
|
-
|
40
|
-
}
|
39
|
+
}
|
40
|
+
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
1
3
|
import type {Readable, Writable} from 'stream';
|
2
4
|
import type {FilePath} from '@atlaspack/types';
|
3
5
|
import type {FileSystem} from '@atlaspack/fs';
|
@@ -21,7 +23,7 @@ import packageJson from '../package.json';
|
|
21
23
|
|
22
24
|
import {WRITE_LIMIT_CHUNK} from './constants';
|
23
25
|
|
24
|
-
const pipeline: (
|
26
|
+
const pipeline: (Readable, Writable) => Promise<void> = promisify(
|
25
27
|
stream.pipeline,
|
26
28
|
);
|
27
29
|
|
@@ -40,10 +42,9 @@ export class FSCache implements Cache {
|
|
40
42
|
|
41
43
|
// In parallel, create sub-directories for every possible hex value
|
42
44
|
// This speeds up large caches on many file systems since there are fewer files in a single directory.
|
43
|
-
let dirPromises
|
45
|
+
let dirPromises = [];
|
44
46
|
for (let i = 0; i < 256; i++) {
|
45
47
|
dirPromises.push(
|
46
|
-
// @ts-expect-error TS2345
|
47
48
|
this.fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2))),
|
48
49
|
);
|
49
50
|
}
|
@@ -82,10 +83,10 @@ export class FSCache implements Cache {
|
|
82
83
|
await this.fs.writeFile(this._getCachePath(key), contents);
|
83
84
|
}
|
84
85
|
|
85
|
-
async getBuffer(key: string): Promise
|
86
|
+
async getBuffer(key: string): Promise<?Buffer> {
|
86
87
|
try {
|
87
88
|
return await this.fs.readFile(this._getCachePath(key));
|
88
|
-
} catch (err
|
89
|
+
} catch (err) {
|
89
90
|
if (err.code === 'ENOENT') {
|
90
91
|
return null;
|
91
92
|
} else {
|
@@ -101,11 +102,11 @@ export class FSCache implements Cache {
|
|
101
102
|
return path.join(this.dir, `${key}-${index}`);
|
102
103
|
}
|
103
104
|
|
104
|
-
async #unlinkChunks(key: string, index: number): Promise<
|
105
|
+
async #unlinkChunks(key: string, index: number): Promise<void> {
|
105
106
|
try {
|
106
107
|
await this.fs.unlink(this.#getFilePath(key, index));
|
107
108
|
await this.#unlinkChunks(key, index + 1);
|
108
|
-
} catch (err
|
109
|
+
} catch (err) {
|
109
110
|
// If there's an error, no more chunks are left to delete
|
110
111
|
}
|
111
112
|
}
|
@@ -128,26 +129,21 @@ export class FSCache implements Cache {
|
|
128
129
|
async setLargeBlob(
|
129
130
|
key: string,
|
130
131
|
contents: Buffer | string,
|
131
|
-
options?: {
|
132
|
-
signal?: AbortSignal;
|
133
|
-
},
|
132
|
+
options?: {|signal?: AbortSignal|},
|
134
133
|
): Promise<void> {
|
135
134
|
const chunks = Math.ceil(contents.length / WRITE_LIMIT_CHUNK);
|
136
135
|
|
137
|
-
const writePromises: Promise<
|
136
|
+
const writePromises: Promise<void>[] = [];
|
138
137
|
if (chunks === 1) {
|
139
138
|
// If there's one chunk, don't slice the content
|
140
139
|
writePromises.push(
|
141
|
-
// @ts-expect-error TS2345
|
142
140
|
this.fs.writeFile(this.#getFilePath(key, 0), contents, {
|
143
|
-
// @ts-expect-error TS2353
|
144
141
|
signal: options?.signal,
|
145
142
|
}),
|
146
143
|
);
|
147
144
|
} else {
|
148
145
|
for (let i = 0; i < chunks; i += 1) {
|
149
146
|
writePromises.push(
|
150
|
-
// @ts-expect-error TS2345
|
151
147
|
this.fs.writeFile(
|
152
148
|
this.#getFilePath(key, i),
|
153
149
|
typeof contents === 'string'
|
@@ -159,7 +155,6 @@ export class FSCache implements Cache {
|
|
159
155
|
i * WRITE_LIMIT_CHUNK,
|
160
156
|
(i + 1) * WRITE_LIMIT_CHUNK,
|
161
157
|
),
|
162
|
-
// @ts-expect-error TS2353
|
163
158
|
{signal: options?.signal},
|
164
159
|
),
|
165
160
|
);
|
@@ -173,13 +168,12 @@ export class FSCache implements Cache {
|
|
173
168
|
}
|
174
169
|
|
175
170
|
async deleteLargeBlob(key: string): Promise<void> {
|
176
|
-
const deletePromises: Promise<
|
171
|
+
const deletePromises: Promise<void>[] = [];
|
177
172
|
|
178
173
|
let i = 0;
|
179
174
|
let filePath = this.#getFilePath(key, i);
|
180
175
|
|
181
176
|
while (await this.fs.exists(filePath)) {
|
182
|
-
// @ts-expect-error TS2345
|
183
177
|
deletePromises.push(this.fs.rimraf(filePath));
|
184
178
|
i += 1;
|
185
179
|
filePath = this.#getFilePath(key, i);
|
@@ -188,11 +182,11 @@ export class FSCache implements Cache {
|
|
188
182
|
await Promise.all(deletePromises);
|
189
183
|
}
|
190
184
|
|
191
|
-
async get<T>(key: string): Promise
|
185
|
+
async get<T>(key: string): Promise<?T> {
|
192
186
|
try {
|
193
187
|
let data = await this.fs.readFile(this._getCachePath(key));
|
194
188
|
return deserialize(data);
|
195
|
-
} catch (err
|
189
|
+
} catch (err) {
|
196
190
|
if (err.code === 'ENOENT') {
|
197
191
|
return null;
|
198
192
|
} else {
|
@@ -201,13 +195,13 @@ export class FSCache implements Cache {
|
|
201
195
|
}
|
202
196
|
}
|
203
197
|
|
204
|
-
async set(key: string, value:
|
198
|
+
async set(key: string, value: mixed): Promise<void> {
|
205
199
|
try {
|
206
200
|
let blobPath = this._getCachePath(key);
|
207
201
|
let data = serialize(value);
|
208
202
|
|
209
203
|
await this.fs.writeFile(blobPath, data);
|
210
|
-
} catch (err
|
204
|
+
} catch (err) {
|
211
205
|
logger.error(err, '@atlaspack/cache');
|
212
206
|
}
|
213
207
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
// @flow strict-local
|
1
2
|
import type {Cache} from './types';
|
2
3
|
|
3
4
|
import {Readable} from 'stream';
|
@@ -8,18 +9,21 @@ import {
|
|
8
9
|
serialize,
|
9
10
|
} from '@atlaspack/build-cache';
|
10
11
|
import {bufferStream} from '@atlaspack/utils';
|
12
|
+
// $FlowFixMe[untyped-import]
|
11
13
|
import {openDB} from 'idb';
|
12
14
|
|
15
|
+
// $FlowFixMe[untyped-import]
|
13
16
|
import packageJson from '../package.json';
|
14
17
|
|
15
18
|
const STORE_NAME = 'cache';
|
16
19
|
|
17
20
|
export class IDBCache implements Cache {
|
21
|
+
// $FlowFixMe
|
18
22
|
store: any;
|
19
23
|
|
20
24
|
constructor() {
|
21
25
|
this.store = openDB('REPL-parcel-cache', 1, {
|
22
|
-
upgrade(db
|
26
|
+
upgrade(db) {
|
23
27
|
db.createObjectStore(STORE_NAME);
|
24
28
|
},
|
25
29
|
blocked() {},
|
@@ -32,7 +36,7 @@ export class IDBCache implements Cache {
|
|
32
36
|
return Promise.resolve();
|
33
37
|
}
|
34
38
|
|
35
|
-
serialize():
|
39
|
+
serialize(): {||} {
|
36
40
|
return {
|
37
41
|
/*::...null*/
|
38
42
|
};
|
@@ -46,7 +50,7 @@ export class IDBCache implements Cache {
|
|
46
50
|
return Promise.resolve(this.store.get(key) != null);
|
47
51
|
}
|
48
52
|
|
49
|
-
async get<T>(key: string): Promise
|
53
|
+
async get<T>(key: string): Promise<?T> {
|
50
54
|
let data = await (await this.store).get(STORE_NAME, key);
|
51
55
|
if (data == null) {
|
52
56
|
return null;
|
@@ -55,19 +59,17 @@ export class IDBCache implements Cache {
|
|
55
59
|
return Promise.resolve(deserialize(data));
|
56
60
|
}
|
57
61
|
|
58
|
-
async set(key: string, value:
|
62
|
+
async set(key: string, value: mixed): Promise<void> {
|
59
63
|
await (await this.store).put(STORE_NAME, serialize(value), key);
|
60
64
|
}
|
61
65
|
|
62
66
|
getStream(key: string): Readable {
|
63
67
|
let dataPromise = this.store
|
64
|
-
// @ts-expect-error TS7006
|
65
68
|
.then((s) => s.get(STORE_NAME, key))
|
66
|
-
// @ts-expect-error TS7006
|
67
69
|
.then((d) => Buffer.from(d))
|
68
|
-
// @ts-expect-error TS7006
|
69
70
|
.catch((e) => e);
|
70
71
|
const stream = new Readable({
|
72
|
+
// $FlowFixMe(incompatible-call)
|
71
73
|
async read() {
|
72
74
|
let data = await dataPromise;
|
73
75
|
if (data instanceof Error) {
|
@@ -116,7 +118,7 @@ export class IDBCache implements Cache {
|
|
116
118
|
// ]);
|
117
119
|
// }
|
118
120
|
|
119
|
-
async getBuffer(key: string): Promise
|
121
|
+
async getBuffer(key: string): Promise<?Buffer> {
|
120
122
|
let data = await (await this.store).get(STORE_NAME, key);
|
121
123
|
if (data == null) {
|
122
124
|
return null;
|
@@ -1,3 +1,5 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
1
3
|
import {
|
2
4
|
deserialize,
|
3
5
|
registerSerializableClass,
|
@@ -8,12 +10,12 @@ import {Lmdb} from '@atlaspack/rust';
|
|
8
10
|
import type {FilePath} from '@atlaspack/types';
|
9
11
|
import type {Cache} from './types';
|
10
12
|
import type {Readable, Writable} from 'stream';
|
11
|
-
// @ts-expect-error TS7016
|
12
13
|
import ncp from 'ncp';
|
13
14
|
import {promisify} from 'util';
|
14
15
|
import stream from 'stream';
|
15
16
|
import path from 'path';
|
16
17
|
import {NodeFS} from '@atlaspack/fs';
|
18
|
+
// $FlowFixMe
|
17
19
|
import packageJson from '../package.json';
|
18
20
|
import {FSCache} from './FSCache';
|
19
21
|
import {instrumentAsync} from '@atlaspack/logger';
|
@@ -87,13 +89,13 @@ export function open(
|
|
87
89
|
);
|
88
90
|
}
|
89
91
|
|
90
|
-
const pipeline: (
|
92
|
+
const pipeline: (Readable, Writable) => Promise<void> = promisify(
|
91
93
|
stream.pipeline,
|
92
94
|
);
|
93
95
|
|
94
|
-
export type SerLMDBLiteCache = {
|
95
|
-
dir: FilePath
|
96
|
-
};
|
96
|
+
export type SerLMDBLiteCache = {|
|
97
|
+
dir: FilePath,
|
98
|
+
|};
|
97
99
|
|
98
100
|
export class LMDBLiteCache implements Cache {
|
99
101
|
fs: NodeFS;
|
@@ -147,7 +149,7 @@ export class LMDBLiteCache implements Cache {
|
|
147
149
|
return Promise.resolve(this.store.has(key));
|
148
150
|
}
|
149
151
|
|
150
|
-
get<T>(key: string): Promise
|
152
|
+
get<T>(key: string): Promise<?T> {
|
151
153
|
let data = this.store.get(key);
|
152
154
|
if (data == null) {
|
153
155
|
return Promise.resolve(null);
|
@@ -156,7 +158,7 @@ export class LMDBLiteCache implements Cache {
|
|
156
158
|
return Promise.resolve(deserialize(data));
|
157
159
|
}
|
158
160
|
|
159
|
-
async set(key: string, value:
|
161
|
+
async set(key: string, value: mixed): Promise<void> {
|
160
162
|
await this.setBlob(key, serialize(value));
|
161
163
|
}
|
162
164
|
|
@@ -198,7 +200,7 @@ export class LMDBLiteCache implements Cache {
|
|
198
200
|
await this.store.put(key, contents);
|
199
201
|
}
|
200
202
|
|
201
|
-
getBuffer(key: string): Promise
|
203
|
+
getBuffer(key: string): Promise<?Buffer> {
|
202
204
|
return Promise.resolve(this.store.get(key));
|
203
205
|
}
|
204
206
|
|
@@ -220,9 +222,7 @@ export class LMDBLiteCache implements Cache {
|
|
220
222
|
async setLargeBlob(
|
221
223
|
key: string,
|
222
224
|
contents: Buffer | string,
|
223
|
-
options?: {
|
224
|
-
signal?: AbortSignal;
|
225
|
-
},
|
225
|
+
options?: {|signal?: AbortSignal|},
|
226
226
|
): Promise<void> {
|
227
227
|
if (!getFeatureFlag('cachePerformanceImprovements')) {
|
228
228
|
return this.fsCache.setLargeBlob(key, contents, options);
|
@@ -1,3 +1,5 @@
|
|
1
|
+
// @flow
|
2
|
+
|
1
3
|
import * as fs from 'fs';
|
2
4
|
import * as path from 'path';
|
3
5
|
import {tmpdir} from 'os';
|
@@ -10,7 +12,7 @@ import {initializeMonitoring} from '@atlaspack/rust';
|
|
10
12
|
const cacheDir = path.join(tmpdir(), 'lmdb-lite-cache-tests');
|
11
13
|
|
12
14
|
describe('LMDBLiteCache', () => {
|
13
|
-
let cache
|
15
|
+
let cache;
|
14
16
|
|
15
17
|
beforeEach(async () => {
|
16
18
|
await fs.promises.rm(cacheDir, {recursive: true, force: true});
|
@@ -127,7 +129,7 @@ describe('LMDBLiteCache', () => {
|
|
127
129
|
await cache.ensure();
|
128
130
|
await cache.setBlob(`key${i}`, Buffer.from(serialize({value: i})));
|
129
131
|
|
130
|
-
await new Promise((resolve
|
132
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
131
133
|
}
|
132
134
|
|
133
135
|
const finalCache = new LMDBLiteCache(testDir);
|
@@ -142,7 +144,7 @@ describe('LMDBLiteCache', () => {
|
|
142
144
|
|
143
145
|
try {
|
144
146
|
initializeMonitoring();
|
145
|
-
} catch (error
|
147
|
+
} catch (error) {
|
146
148
|
/* empty */
|
147
149
|
}
|
148
150
|
|
@@ -163,8 +165,8 @@ describe('LMDBLiteCache', () => {
|
|
163
165
|
|
164
166
|
const numWorkers = 10;
|
165
167
|
|
166
|
-
const workers
|
167
|
-
const responsePromises
|
168
|
+
const workers = [];
|
169
|
+
const responsePromises = [];
|
168
170
|
for (let i = 0; i < numWorkers; i++) {
|
169
171
|
const worker = new Worker(path.join(__dirname, 'workerThreadsTest.js'), {
|
170
172
|
workerData: {
|
@@ -173,16 +175,16 @@ describe('LMDBLiteCache', () => {
|
|
173
175
|
});
|
174
176
|
workers.push(worker);
|
175
177
|
|
176
|
-
const responsePromise = new Promise((resolve
|
178
|
+
const responsePromise = new Promise((resolve, reject) => {
|
177
179
|
worker.addListener('error', (error: Error) => {
|
178
180
|
reject(error);
|
179
181
|
});
|
180
|
-
worker.addListener('message', (message
|
182
|
+
worker.addListener('message', (message) => {
|
181
183
|
resolve(message);
|
182
184
|
});
|
183
185
|
});
|
184
186
|
|
185
|
-
worker.addListener('message', (message
|
187
|
+
worker.addListener('message', (message) => {
|
186
188
|
// eslint-disable-next-line no-console
|
187
189
|
console.log('Worker message', message);
|
188
190
|
});
|
@@ -234,7 +236,7 @@ describe('LMDBLiteCache', () => {
|
|
234
236
|
workerId: worker.threadId,
|
235
237
|
});
|
236
238
|
|
237
|
-
await new Promise((resolve
|
239
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
238
240
|
worker.terminate();
|
239
241
|
}
|
240
242
|
});
|
package/LICENSE
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
Apache License
|
2
|
-
Version 2.0, January 2004
|
3
|
-
http://www.apache.org/licenses/
|
4
|
-
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
-
|
7
|
-
1. Definitions.
|
8
|
-
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
-
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
-
the copyright owner that is granting the License.
|
14
|
-
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
-
other entities that control, are controlled by, or are under common
|
17
|
-
control with that entity. For the purposes of this definition,
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
19
|
-
direction or management of such entity, whether by contract or
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
-
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
-
exercising permissions granted by this License.
|
25
|
-
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
27
|
-
including but not limited to software source code, documentation
|
28
|
-
source, and configuration files.
|
29
|
-
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
31
|
-
transformation or translation of a Source form, including but
|
32
|
-
not limited to compiled object code, generated documentation,
|
33
|
-
and conversions to other media types.
|
34
|
-
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
36
|
-
Object form, made available under the License, as indicated by a
|
37
|
-
copyright notice that is included in or attached to the work
|
38
|
-
(an example is provided in the Appendix below).
|
39
|
-
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
-
the Work and Derivative Works thereof.
|
47
|
-
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
49
|
-
the original version of the Work and any modifications or additions
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
-
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
64
|
-
subsequently incorporated within the Work.
|
65
|
-
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
72
|
-
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
-
where such license applies only to those patent claims licensable
|
79
|
-
by such Contributor that are necessarily infringed by their
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
82
|
-
institute patent litigation against any entity (including a
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
85
|
-
or contributory patent infringement, then any patent licenses
|
86
|
-
granted to You under this License for that Work shall terminate
|
87
|
-
as of the date such litigation is filed.
|
88
|
-
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
91
|
-
modifications, and in Source or Object form, provided that You
|
92
|
-
meet the following conditions:
|
93
|
-
|
94
|
-
(a) You must give any other recipients of the Work or
|
95
|
-
Derivative Works a copy of this License; and
|
96
|
-
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
98
|
-
stating that You changed the files; and
|
99
|
-
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
102
|
-
attribution notices from the Source form of the Work,
|
103
|
-
excluding those notices that do not pertain to any part of
|
104
|
-
the Derivative Works; and
|
105
|
-
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
108
|
-
include a readable copy of the attribution notices contained
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
111
|
-
of the following places: within a NOTICE text file distributed
|
112
|
-
as part of the Derivative Works; within the Source form or
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
114
|
-
within a display generated by the Derivative Works, if and
|
115
|
-
wherever such third-party notices normally appear. The contents
|
116
|
-
of the NOTICE file are for informational purposes only and
|
117
|
-
do not modify the License. You may add Your own attribution
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
120
|
-
that such additional attribution notices cannot be construed
|
121
|
-
as modifying the License.
|
122
|
-
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
124
|
-
may provide additional or different license terms and conditions
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
128
|
-
the conditions stated in this License.
|
129
|
-
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
133
|
-
this License, without any additional terms or conditions.
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
-
the terms of any separate license agreement you may have executed
|
136
|
-
with Licensor regarding such Contributions.
|
137
|
-
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
140
|
-
except as required for reasonable and customary use in describing the
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
-
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
152
|
-
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
158
|
-
incidental, or consequential damages of any character arising as a
|
159
|
-
result of this License or out of the use or inability to use the
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
162
|
-
other commercial damages or losses), even if such Contributor
|
163
|
-
has been advised of the possibility of such damages.
|
164
|
-
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
-
or other liability obligations and/or rights consistent with this
|
169
|
-
License. However, in accepting such obligations, You may act only
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
174
|
-
of your accepting any such warranty or additional liability.
|
175
|
-
|
176
|
-
END OF TERMS AND CONDITIONS
|
177
|
-
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
179
|
-
|
180
|
-
To apply the Apache License to your work, attach the following
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
-
replaced with your own identifying information. (Don't include
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
184
|
-
comment syntax for the file format. We also recommend that a
|
185
|
-
file or class name and description of purpose be included on the
|
186
|
-
same "printed page" as the copyright notice for easier
|
187
|
-
identification within third-party archives.
|
188
|
-
|
189
|
-
Copyright (c) 2024 Atlassian US., Inc.
|
190
|
-
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
-
you may not use this file except in compliance with the License.
|
193
|
-
You may obtain a copy of the License at
|
194
|
-
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
-
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
-
See the License for the specific language governing permissions and
|
201
|
-
limitations under the License.
|
package/lib/FSCache.d.ts
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
import type { Readable } from 'stream';
|
2
|
-
import type { FilePath } from '@atlaspack/types';
|
3
|
-
import type { FileSystem } from '@atlaspack/fs';
|
4
|
-
import type { Cache } from './types';
|
5
|
-
export declare class FSCache implements Cache {
|
6
|
-
#private;
|
7
|
-
fs: FileSystem;
|
8
|
-
dir: FilePath;
|
9
|
-
constructor(fs: FileSystem, cacheDir: FilePath);
|
10
|
-
ensure(): Promise<void>;
|
11
|
-
_getCachePath(cacheId: string): FilePath;
|
12
|
-
getStream(key: string): Readable;
|
13
|
-
setStream(key: string, stream: Readable): Promise<void>;
|
14
|
-
has(key: string): Promise<boolean>;
|
15
|
-
getBlob(key: string): Promise<Buffer>;
|
16
|
-
setBlob(key: string, contents: Buffer | string): Promise<void>;
|
17
|
-
getBuffer(key: string): Promise<Buffer | null | undefined>;
|
18
|
-
hasLargeBlob(key: string): Promise<boolean>;
|
19
|
-
getLargeBlob(key: string): Promise<Buffer>;
|
20
|
-
setLargeBlob(key: string, contents: Buffer | string, options?: {
|
21
|
-
signal?: AbortSignal;
|
22
|
-
}): Promise<void>;
|
23
|
-
deleteLargeBlob(key: string): Promise<void>;
|
24
|
-
get<T>(key: string): Promise<T | null | undefined>;
|
25
|
-
set(key: string, value: unknown): Promise<void>;
|
26
|
-
refresh(): void;
|
27
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import type { Cache } from './types';
|
2
|
-
import { Readable } from 'stream';
|
3
|
-
export declare class IDBCache implements Cache {
|
4
|
-
store: any;
|
5
|
-
constructor();
|
6
|
-
ensure(): Promise<void>;
|
7
|
-
serialize(): Record<any, any>;
|
8
|
-
static deserialize(): IDBCache;
|
9
|
-
has(key: string): Promise<boolean>;
|
10
|
-
get<T>(key: string): Promise<T | null | undefined>;
|
11
|
-
set(key: string, value: unknown): Promise<void>;
|
12
|
-
getStream(key: string): Readable;
|
13
|
-
setStream(key: string, stream: Readable): Promise<void>;
|
14
|
-
getBlob(key: string): Promise<Buffer>;
|
15
|
-
setBlob(key: string, contents: Buffer | string): Promise<void>;
|
16
|
-
getBuffer(key: string): Promise<Buffer | null | undefined>;
|
17
|
-
hasLargeBlob(key: string): Promise<boolean>;
|
18
|
-
getLargeBlob(key: string): Promise<Buffer>;
|
19
|
-
setLargeBlob(key: string, contents: Buffer | string): Promise<void>;
|
20
|
-
deleteLargeBlob(key: string): Promise<void>;
|
21
|
-
refresh(): void;
|
22
|
-
}
|
package/lib/IDBCache.d.ts
DELETED
package/lib/LMDBLiteCache.d.ts
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
import { Lmdb } from '@atlaspack/rust';
|
2
|
-
import type { FilePath } from '@atlaspack/types';
|
3
|
-
import type { Cache } from './types';
|
4
|
-
import type { Readable } from 'stream';
|
5
|
-
import { NodeFS } from '@atlaspack/fs';
|
6
|
-
import { FSCache } from './FSCache';
|
7
|
-
interface DBOpenOptions {
|
8
|
-
name: string;
|
9
|
-
encoding: string;
|
10
|
-
compression: boolean;
|
11
|
-
}
|
12
|
-
export declare class LmdbWrapper {
|
13
|
-
lmdb: Lmdb;
|
14
|
-
constructor(lmdb: Lmdb);
|
15
|
-
has(key: string): boolean;
|
16
|
-
delete(key: string): Promise<void>;
|
17
|
-
get(key: string): Buffer | null;
|
18
|
-
put(key: string, value: Buffer | string): Promise<void>;
|
19
|
-
keys(): Iterable<string>;
|
20
|
-
compact(targetPath: string): void;
|
21
|
-
}
|
22
|
-
export declare function open(directory: string, openOptions: DBOpenOptions): LmdbWrapper;
|
23
|
-
export type SerLMDBLiteCache = {
|
24
|
-
dir: FilePath;
|
25
|
-
};
|
26
|
-
export declare class LMDBLiteCache implements Cache {
|
27
|
-
fs: NodeFS;
|
28
|
-
dir: FilePath;
|
29
|
-
store: LmdbWrapper;
|
30
|
-
fsCache: FSCache;
|
31
|
-
/**
|
32
|
-
* Directory where we store raw files.
|
33
|
-
*/
|
34
|
-
cacheFilesDirectory: FilePath;
|
35
|
-
constructor(cacheDir: FilePath);
|
36
|
-
/**
|
37
|
-
* Use this to pass the native LMDB instance back to Rust.
|
38
|
-
*/
|
39
|
-
getNativeRef(): Lmdb;
|
40
|
-
ensure(): Promise<void>;
|
41
|
-
serialize(): SerLMDBLiteCache;
|
42
|
-
static deserialize(cache: SerLMDBLiteCache): LMDBLiteCache;
|
43
|
-
has(key: string): Promise<boolean>;
|
44
|
-
get<T>(key: string): Promise<T | null | undefined>;
|
45
|
-
set(key: string, value: unknown): Promise<void>;
|
46
|
-
getStream(key: string): Readable;
|
47
|
-
setStream(key: string, stream: Readable): Promise<void>;
|
48
|
-
getBlob(key: string): Promise<Buffer>;
|
49
|
-
getBlobSync(key: string): Buffer;
|
50
|
-
setBlob(key: string, contents: Buffer | string): Promise<void>;
|
51
|
-
getBuffer(key: string): Promise<Buffer | null | undefined>;
|
52
|
-
hasLargeBlob(key: string): Promise<boolean>;
|
53
|
-
getLargeBlob(key: string): Promise<Buffer>;
|
54
|
-
setLargeBlob(key: string, contents: Buffer | string, options?: {
|
55
|
-
signal?: AbortSignal;
|
56
|
-
}): Promise<void>;
|
57
|
-
/**
|
58
|
-
* @deprecated Use store.delete instead.
|
59
|
-
*/
|
60
|
-
deleteLargeBlob(key: string): Promise<void>;
|
61
|
-
keys(): Iterable<string>;
|
62
|
-
compact(targetPath: string): Promise<void>;
|
63
|
-
refresh(): void;
|
64
|
-
/**
|
65
|
-
* Streams, packages are stored in files instead of LMDB.
|
66
|
-
*
|
67
|
-
* On this case, if a cache key happens to have a parent traversal, ../..
|
68
|
-
* it is treated specially
|
69
|
-
*
|
70
|
-
* That is, something/../something and something are meant to be different
|
71
|
-
* keys.
|
72
|
-
*
|
73
|
-
* Plus we do not want to store values outside of the cache directory.
|
74
|
-
*/
|
75
|
-
getFileKey(key: string): string;
|
76
|
-
clear(): Promise<void>;
|
77
|
-
}
|
78
|
-
export {};
|
package/lib/constants.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export declare const WRITE_LIMIT_CHUNK: number;
|
package/lib/index.d.ts
DELETED
package/tsconfig.json
DELETED