@atlaspack/cache 3.1.1-canary.138 → 3.1.1-canary.139

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.
@@ -0,0 +1,27 @@
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
+ }
package/lib/FSCache.js CHANGED
@@ -57,6 +57,7 @@ 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
+
60
61
  const pipeline = (0, _util().promisify)(_stream().default.pipeline);
61
62
  class FSCache {
62
63
  constructor(fs, cacheDir) {
@@ -71,7 +72,9 @@ class FSCache {
71
72
  // This speeds up large caches on many file systems since there are fewer files in a single directory.
72
73
  let dirPromises = [];
73
74
  for (let i = 0; i < 256; i++) {
74
- dirPromises.push(this.fs.mkdirp(_path().default.join(this.dir, ('00' + i.toString(16)).slice(-2))));
75
+ dirPromises.push(
76
+ // @ts-expect-error TS2345
77
+ this.fs.mkdirp(_path().default.join(this.dir, ('00' + i.toString(16)).slice(-2))));
75
78
  }
76
79
  await Promise.all(dirPromises);
77
80
  }
@@ -138,12 +141,19 @@ class FSCache {
138
141
  const writePromises = [];
139
142
  if (chunks === 1) {
140
143
  // If there's one chunk, don't slice the content
141
- writePromises.push(this.fs.writeFile(this.#getFilePath(key, 0), contents, {
144
+ writePromises.push(
145
+ // @ts-expect-error TS2345
146
+ this.fs.writeFile(this.#getFilePath(key, 0), contents, {
147
+ // @ts-expect-error TS2353
142
148
  signal: options === null || options === void 0 ? void 0 : options.signal
143
149
  }));
144
150
  } else {
145
151
  for (let i = 0; i < chunks; i += 1) {
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), {
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
+ {
147
157
  signal: options === null || options === void 0 ? void 0 : options.signal
148
158
  }));
149
159
  }
@@ -158,6 +168,7 @@ class FSCache {
158
168
  let i = 0;
159
169
  let filePath = this.#getFilePath(key, i);
160
170
  while (await this.fs.exists(filePath)) {
171
+ // @ts-expect-error TS2345
161
172
  deletePromises.push(this.fs.rimraf(filePath));
162
173
  i += 1;
163
174
  filePath = this.#getFilePath(key, i);
@@ -0,0 +1,22 @@
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
+ }
@@ -34,12 +34,8 @@ 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]
39
37
  const STORE_NAME = 'cache';
40
38
  class IDBCache {
41
- // $FlowFixMe
42
-
43
39
  constructor() {
44
40
  this.store = (0, _idb().openDB)('REPL-parcel-cache', 1, {
45
41
  upgrade(db) {
@@ -75,9 +71,14 @@ class IDBCache {
75
71
  await (await this.store).put(STORE_NAME, (0, _buildCache().serialize)(value), key);
76
72
  }
77
73
  getStream(key) {
78
- let dataPromise = this.store.then(s => s.get(STORE_NAME, key)).then(d => Buffer.from(d)).catch(e => e);
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);
79
81
  const stream = new (_stream().Readable)({
80
- // $FlowFixMe(incompatible-call)
81
82
  async read() {
82
83
  let data = await dataPromise;
83
84
  if (data instanceof Error) {
@@ -0,0 +1,4 @@
1
+ import type { Cache } from './types';
2
+ export declare class IDBCache implements Cache {
3
+ constructor();
4
+ }
package/lib/IDBCache.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.IDBCache = void 0;
7
- // $FlowFixMe
7
+ // @ts-expect-error TS2420
8
8
  class IDBCache {
9
9
  constructor() {
10
10
  throw new Error('IDBCache is only supported in the browser');
@@ -0,0 +1,78 @@
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 {};
@@ -71,7 +71,8 @@ function _logger() {
71
71
  return data;
72
72
  }
73
73
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
74
- // $FlowFixMe
74
+ // @ts-expect-error TS7016
75
+
75
76
  const ncpAsync = (0, _util().promisify)(_ncp().default);
76
77
  class LmdbWrapper {
77
78
  constructor(lmdb) {
@@ -0,0 +1 @@
1
+ export declare const WRITE_LIMIT_CHUNK: number;
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './FSCache';
2
+ export * from './IDBCache';
3
+ export * from './LMDBLiteCache';
4
+ export type { Cache } from './types';
package/lib/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Cache } from "@atlaspack/types";
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.1.1-canary.138+eda07caaf",
4
+ "version": "3.1.1-canary.139+d2fd84977",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "type": "commonjs",
7
7
  "publishConfig": {
@@ -11,24 +11,23 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/atlassian-labs/atlaspack.git"
13
13
  },
14
- "main": "lib/index.js",
15
- "source": "src/index.js",
16
- "types": "index.d.ts",
14
+ "main": "./lib/index.js",
15
+ "source": "./src/index.ts",
16
+ "types": "./lib/index.d.ts",
17
17
  "engines": {
18
18
  "node": ">= 16.0.0"
19
19
  },
20
20
  "scripts": {
21
21
  "test": "mocha",
22
- "build-ts": "mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts",
23
- "check-ts": "tsc --noEmit index.d.ts"
22
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
24
23
  },
25
24
  "dependencies": {
26
- "@atlaspack/build-cache": "2.13.3-canary.206+eda07caaf",
27
- "@atlaspack/feature-flags": "2.14.1-canary.206+eda07caaf",
28
- "@atlaspack/fs": "2.14.5-canary.138+eda07caaf",
29
- "@atlaspack/logger": "2.14.5-canary.138+eda07caaf",
30
- "@atlaspack/rust": "3.2.1-canary.138+eda07caaf",
31
- "@atlaspack/utils": "2.14.5-canary.138+eda07caaf",
25
+ "@atlaspack/build-cache": "2.13.3-canary.207+d2fd84977",
26
+ "@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977",
27
+ "@atlaspack/fs": "2.14.5-canary.139+d2fd84977",
28
+ "@atlaspack/logger": "2.14.5-canary.139+d2fd84977",
29
+ "@atlaspack/rust": "3.2.1-canary.139+d2fd84977",
30
+ "@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
32
31
  "ncp": "^2.0.0"
33
32
  },
34
33
  "devDependencies": {
@@ -37,5 +36,5 @@
37
36
  "browser": {
38
37
  "./src/IDBCache.js": "./src/IDBCache.browser.js"
39
38
  },
40
- "gitHead": "eda07caafd2ebb814bbdbfd0ec12fa63124e213f"
41
- }
39
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
40
+ }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {Readable, Writable} from 'stream';
4
2
  import type {FilePath} from '@atlaspack/types';
5
3
  import type {FileSystem} from '@atlaspack/fs';
@@ -23,7 +21,7 @@ import packageJson from '../package.json';
23
21
 
24
22
  import {WRITE_LIMIT_CHUNK} from './constants';
25
23
 
26
- const pipeline: (Readable, Writable) => Promise<void> = promisify(
24
+ const pipeline: (arg1: Readable, arg2: Writable) => Promise<void> = promisify(
27
25
  stream.pipeline,
28
26
  );
29
27
 
@@ -42,9 +40,10 @@ export class FSCache implements Cache {
42
40
 
43
41
  // In parallel, create sub-directories for every possible hex value
44
42
  // This speeds up large caches on many file systems since there are fewer files in a single directory.
45
- let dirPromises = [];
43
+ let dirPromises: Array<Promise<undefined>> = [];
46
44
  for (let i = 0; i < 256; i++) {
47
45
  dirPromises.push(
46
+ // @ts-expect-error TS2345
48
47
  this.fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2))),
49
48
  );
50
49
  }
@@ -83,10 +82,10 @@ export class FSCache implements Cache {
83
82
  await this.fs.writeFile(this._getCachePath(key), contents);
84
83
  }
85
84
 
86
- async getBuffer(key: string): Promise<?Buffer> {
85
+ async getBuffer(key: string): Promise<Buffer | null | undefined> {
87
86
  try {
88
87
  return await this.fs.readFile(this._getCachePath(key));
89
- } catch (err) {
88
+ } catch (err: any) {
90
89
  if (err.code === 'ENOENT') {
91
90
  return null;
92
91
  } else {
@@ -102,11 +101,11 @@ export class FSCache implements Cache {
102
101
  return path.join(this.dir, `${key}-${index}`);
103
102
  }
104
103
 
105
- async #unlinkChunks(key: string, index: number): Promise<void> {
104
+ async #unlinkChunks(key: string, index: number): Promise<undefined> {
106
105
  try {
107
106
  await this.fs.unlink(this.#getFilePath(key, index));
108
107
  await this.#unlinkChunks(key, index + 1);
109
- } catch (err) {
108
+ } catch (err: any) {
110
109
  // If there's an error, no more chunks are left to delete
111
110
  }
112
111
  }
@@ -129,21 +128,26 @@ export class FSCache implements Cache {
129
128
  async setLargeBlob(
130
129
  key: string,
131
130
  contents: Buffer | string,
132
- options?: {|signal?: AbortSignal|},
131
+ options?: {
132
+ signal?: AbortSignal;
133
+ },
133
134
  ): Promise<void> {
134
135
  const chunks = Math.ceil(contents.length / WRITE_LIMIT_CHUNK);
135
136
 
136
- const writePromises: Promise<void>[] = [];
137
+ const writePromises: Promise<undefined>[] = [];
137
138
  if (chunks === 1) {
138
139
  // If there's one chunk, don't slice the content
139
140
  writePromises.push(
141
+ // @ts-expect-error TS2345
140
142
  this.fs.writeFile(this.#getFilePath(key, 0), contents, {
143
+ // @ts-expect-error TS2353
141
144
  signal: options?.signal,
142
145
  }),
143
146
  );
144
147
  } else {
145
148
  for (let i = 0; i < chunks; i += 1) {
146
149
  writePromises.push(
150
+ // @ts-expect-error TS2345
147
151
  this.fs.writeFile(
148
152
  this.#getFilePath(key, i),
149
153
  typeof contents === 'string'
@@ -155,6 +159,7 @@ export class FSCache implements Cache {
155
159
  i * WRITE_LIMIT_CHUNK,
156
160
  (i + 1) * WRITE_LIMIT_CHUNK,
157
161
  ),
162
+ // @ts-expect-error TS2353
158
163
  {signal: options?.signal},
159
164
  ),
160
165
  );
@@ -168,12 +173,13 @@ export class FSCache implements Cache {
168
173
  }
169
174
 
170
175
  async deleteLargeBlob(key: string): Promise<void> {
171
- const deletePromises: Promise<void>[] = [];
176
+ const deletePromises: Promise<undefined>[] = [];
172
177
 
173
178
  let i = 0;
174
179
  let filePath = this.#getFilePath(key, i);
175
180
 
176
181
  while (await this.fs.exists(filePath)) {
182
+ // @ts-expect-error TS2345
177
183
  deletePromises.push(this.fs.rimraf(filePath));
178
184
  i += 1;
179
185
  filePath = this.#getFilePath(key, i);
@@ -182,11 +188,11 @@ export class FSCache implements Cache {
182
188
  await Promise.all(deletePromises);
183
189
  }
184
190
 
185
- async get<T>(key: string): Promise<?T> {
191
+ async get<T>(key: string): Promise<T | null | undefined> {
186
192
  try {
187
193
  let data = await this.fs.readFile(this._getCachePath(key));
188
194
  return deserialize(data);
189
- } catch (err) {
195
+ } catch (err: any) {
190
196
  if (err.code === 'ENOENT') {
191
197
  return null;
192
198
  } else {
@@ -195,13 +201,13 @@ export class FSCache implements Cache {
195
201
  }
196
202
  }
197
203
 
198
- async set(key: string, value: mixed): Promise<void> {
204
+ async set(key: string, value: unknown): Promise<void> {
199
205
  try {
200
206
  let blobPath = this._getCachePath(key);
201
207
  let data = serialize(value);
202
208
 
203
209
  await this.fs.writeFile(blobPath, data);
204
- } catch (err) {
210
+ } catch (err: any) {
205
211
  logger.error(err, '@atlaspack/cache');
206
212
  }
207
213
  }
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  import type {Cache} from './types';
3
2
 
4
3
  import {Readable} from 'stream';
@@ -9,21 +8,18 @@ import {
9
8
  serialize,
10
9
  } from '@atlaspack/build-cache';
11
10
  import {bufferStream} from '@atlaspack/utils';
12
- // $FlowFixMe[untyped-import]
13
11
  import {openDB} from 'idb';
14
12
 
15
- // $FlowFixMe[untyped-import]
16
13
  import packageJson from '../package.json';
17
14
 
18
15
  const STORE_NAME = 'cache';
19
16
 
20
17
  export class IDBCache implements Cache {
21
- // $FlowFixMe
22
18
  store: any;
23
19
 
24
20
  constructor() {
25
21
  this.store = openDB('REPL-parcel-cache', 1, {
26
- upgrade(db) {
22
+ upgrade(db: any) {
27
23
  db.createObjectStore(STORE_NAME);
28
24
  },
29
25
  blocked() {},
@@ -36,7 +32,7 @@ export class IDBCache implements Cache {
36
32
  return Promise.resolve();
37
33
  }
38
34
 
39
- serialize(): {||} {
35
+ serialize(): Record<any, any> {
40
36
  return {
41
37
  /*::...null*/
42
38
  };
@@ -50,7 +46,7 @@ export class IDBCache implements Cache {
50
46
  return Promise.resolve(this.store.get(key) != null);
51
47
  }
52
48
 
53
- async get<T>(key: string): Promise<?T> {
49
+ async get<T>(key: string): Promise<T | null | undefined> {
54
50
  let data = await (await this.store).get(STORE_NAME, key);
55
51
  if (data == null) {
56
52
  return null;
@@ -59,17 +55,19 @@ export class IDBCache implements Cache {
59
55
  return Promise.resolve(deserialize(data));
60
56
  }
61
57
 
62
- async set(key: string, value: mixed): Promise<void> {
58
+ async set(key: string, value: unknown): Promise<void> {
63
59
  await (await this.store).put(STORE_NAME, serialize(value), key);
64
60
  }
65
61
 
66
62
  getStream(key: string): Readable {
67
63
  let dataPromise = this.store
64
+ // @ts-expect-error TS7006
68
65
  .then((s) => s.get(STORE_NAME, key))
66
+ // @ts-expect-error TS7006
69
67
  .then((d) => Buffer.from(d))
68
+ // @ts-expect-error TS7006
70
69
  .catch((e) => e);
71
70
  const stream = new Readable({
72
- // $FlowFixMe(incompatible-call)
73
71
  async read() {
74
72
  let data = await dataPromise;
75
73
  if (data instanceof Error) {
@@ -118,7 +116,7 @@ export class IDBCache implements Cache {
118
116
  // ]);
119
117
  // }
120
118
 
121
- async getBuffer(key: string): Promise<?Buffer> {
119
+ async getBuffer(key: string): Promise<Buffer | null | undefined> {
122
120
  let data = await (await this.store).get(STORE_NAME, key);
123
121
  if (data == null) {
124
122
  return null;
@@ -1,7 +1,6 @@
1
- // @flow strict-local
2
1
  import type {Cache} from './types';
3
2
 
4
- // $FlowFixMe
3
+ // @ts-expect-error TS2420
5
4
  export class IDBCache implements Cache {
6
5
  constructor() {
7
6
  throw new Error('IDBCache is only supported in the browser');
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {
4
2
  deserialize,
5
3
  registerSerializableClass,
@@ -10,12 +8,12 @@ import {Lmdb} from '@atlaspack/rust';
10
8
  import type {FilePath} from '@atlaspack/types';
11
9
  import type {Cache} from './types';
12
10
  import type {Readable, Writable} from 'stream';
11
+ // @ts-expect-error TS7016
13
12
  import ncp from 'ncp';
14
13
  import {promisify} from 'util';
15
14
  import stream from 'stream';
16
15
  import path from 'path';
17
16
  import {NodeFS} from '@atlaspack/fs';
18
- // $FlowFixMe
19
17
  import packageJson from '../package.json';
20
18
  import {FSCache} from './FSCache';
21
19
  import {instrumentAsync} from '@atlaspack/logger';
@@ -89,13 +87,13 @@ export function open(
89
87
  );
90
88
  }
91
89
 
92
- const pipeline: (Readable, Writable) => Promise<void> = promisify(
90
+ const pipeline: (arg1: Readable, arg2: Writable) => Promise<void> = promisify(
93
91
  stream.pipeline,
94
92
  );
95
93
 
96
- export type SerLMDBLiteCache = {|
97
- dir: FilePath,
98
- |};
94
+ export type SerLMDBLiteCache = {
95
+ dir: FilePath;
96
+ };
99
97
 
100
98
  export class LMDBLiteCache implements Cache {
101
99
  fs: NodeFS;
@@ -149,7 +147,7 @@ export class LMDBLiteCache implements Cache {
149
147
  return Promise.resolve(this.store.has(key));
150
148
  }
151
149
 
152
- get<T>(key: string): Promise<?T> {
150
+ get<T>(key: string): Promise<T | null | undefined> {
153
151
  let data = this.store.get(key);
154
152
  if (data == null) {
155
153
  return Promise.resolve(null);
@@ -158,7 +156,7 @@ export class LMDBLiteCache implements Cache {
158
156
  return Promise.resolve(deserialize(data));
159
157
  }
160
158
 
161
- async set(key: string, value: mixed): Promise<void> {
159
+ async set(key: string, value: unknown): Promise<void> {
162
160
  await this.setBlob(key, serialize(value));
163
161
  }
164
162
 
@@ -200,7 +198,7 @@ export class LMDBLiteCache implements Cache {
200
198
  await this.store.put(key, contents);
201
199
  }
202
200
 
203
- getBuffer(key: string): Promise<?Buffer> {
201
+ getBuffer(key: string): Promise<Buffer | null | undefined> {
204
202
  return Promise.resolve(this.store.get(key));
205
203
  }
206
204
 
@@ -222,7 +220,9 @@ export class LMDBLiteCache implements Cache {
222
220
  async setLargeBlob(
223
221
  key: string,
224
222
  contents: Buffer | string,
225
- options?: {|signal?: AbortSignal|},
223
+ options?: {
224
+ signal?: AbortSignal;
225
+ },
226
226
  ): Promise<void> {
227
227
  if (!getFeatureFlag('cachePerformanceImprovements')) {
228
228
  return this.fsCache.setLargeBlob(key, contents, options);
@@ -1,4 +1,2 @@
1
- // @flow strict-local
2
-
3
1
  // Node has a file size limit of 2 GB
4
2
  export const WRITE_LIMIT_CHUNK = 2 * 1024 ** 3;
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  export * from './FSCache';
4
2
  export * from './IDBCache';
5
3
  export * from './LMDBLiteCache';
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {Cache} from '@atlaspack/types';
3
2
 
4
3
  export type {Cache};
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import * as fs from 'fs';
4
2
  import * as path from 'path';
5
3
  import {tmpdir} from 'os';
@@ -12,7 +10,7 @@ import {initializeMonitoring} from '@atlaspack/rust';
12
10
  const cacheDir = path.join(tmpdir(), 'lmdb-lite-cache-tests');
13
11
 
14
12
  describe('LMDBLiteCache', () => {
15
- let cache;
13
+ let cache: any;
16
14
 
17
15
  beforeEach(async () => {
18
16
  await fs.promises.rm(cacheDir, {recursive: true, force: true});
@@ -129,7 +127,7 @@ describe('LMDBLiteCache', () => {
129
127
  await cache.ensure();
130
128
  await cache.setBlob(`key${i}`, Buffer.from(serialize({value: i})));
131
129
 
132
- await new Promise((resolve) => setTimeout(resolve, 10));
130
+ await new Promise((resolve: any) => setTimeout(resolve, 10));
133
131
  }
134
132
 
135
133
  const finalCache = new LMDBLiteCache(testDir);
@@ -144,7 +142,7 @@ describe('LMDBLiteCache', () => {
144
142
 
145
143
  try {
146
144
  initializeMonitoring();
147
- } catch (error) {
145
+ } catch (error: any) {
148
146
  /* empty */
149
147
  }
150
148
 
@@ -165,8 +163,8 @@ describe('LMDBLiteCache', () => {
165
163
 
166
164
  const numWorkers = 10;
167
165
 
168
- const workers = [];
169
- const responsePromises = [];
166
+ const workers: Array<any> = [];
167
+ const responsePromises: Array<any> = [];
170
168
  for (let i = 0; i < numWorkers; i++) {
171
169
  const worker = new Worker(path.join(__dirname, 'workerThreadsTest.js'), {
172
170
  workerData: {
@@ -175,16 +173,16 @@ describe('LMDBLiteCache', () => {
175
173
  });
176
174
  workers.push(worker);
177
175
 
178
- const responsePromise = new Promise((resolve, reject) => {
176
+ const responsePromise = new Promise((resolve: any, reject: any) => {
179
177
  worker.addListener('error', (error: Error) => {
180
178
  reject(error);
181
179
  });
182
- worker.addListener('message', (message) => {
180
+ worker.addListener('message', (message: any) => {
183
181
  resolve(message);
184
182
  });
185
183
  });
186
184
 
187
- worker.addListener('message', (message) => {
185
+ worker.addListener('message', (message: any) => {
188
186
  // eslint-disable-next-line no-console
189
187
  console.log('Worker message', message);
190
188
  });
@@ -236,7 +234,7 @@ describe('LMDBLiteCache', () => {
236
234
  workerId: worker.threadId,
237
235
  });
238
236
 
239
- await new Promise((resolve) => setTimeout(resolve, 500));
237
+ await new Promise((resolve: any) => setTimeout(resolve, 500));
240
238
  worker.terminate();
241
239
  }
242
240
  });
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }
package/index.d.ts DELETED
@@ -1,13 +0,0 @@
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
- };