@atlaspack/cache 3.2.15 → 3.2.16-typescript-80839fbd5.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/LICENSE ADDED
@@ -0,0 +1,201 @@
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.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);
@@ -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) {
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');
@@ -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) {
@@ -174,10 +175,13 @@ class LMDBLiteCache {
174
175
  }
175
176
  async setStream(key, stream) {
176
177
  if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
177
- return pipeline(stream, this.fs.createWriteStream(_path().default.join(this.dir, key)));
178
+ return pipeline(stream,
179
+ // @ts-expect-error TS2554
180
+ this.fs.createWriteStream(_path().default.join(this.dir, key)));
178
181
  }
179
182
  const filePath = this.getFileKey(key);
180
183
  await this.fs.mkdirp(_path().default.dirname(filePath));
184
+ // @ts-expect-error TS2554
181
185
  return pipeline(stream, this.fs.createWriteStream(filePath));
182
186
  }
183
187
 
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.15",
4
+ "version": "3.2.16-typescript-80839fbd5.0",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "type": "commonjs",
7
7
  "publishConfig": {
@@ -12,23 +12,22 @@
12
12
  "url": "https://github.com/atlassian-labs/atlaspack.git"
13
13
  },
14
14
  "main": "lib/index.js",
15
- "source": "src/index.js",
16
- "types": "index.d.ts",
15
+ "source": "src/index.ts",
16
+ "types": "src/index.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 --noEmit"
24
23
  },
25
24
  "dependencies": {
26
- "@atlaspack/build-cache": "2.13.3",
27
- "@atlaspack/feature-flags": "2.19.2",
28
- "@atlaspack/fs": "2.15.15",
29
- "@atlaspack/logger": "2.14.13",
30
- "@atlaspack/rust": "3.4.1",
31
- "@atlaspack/utils": "2.17.2",
25
+ "@atlaspack/build-cache": "2.13.4-typescript-80839fbd5.0",
26
+ "@atlaspack/feature-flags": "2.19.3-typescript-80839fbd5.0",
27
+ "@atlaspack/fs": "2.15.16-typescript-80839fbd5.0",
28
+ "@atlaspack/logger": "2.14.14-typescript-80839fbd5.0",
29
+ "@atlaspack/rust": "3.4.2-typescript-80839fbd5.0",
30
+ "@atlaspack/utils": "2.17.3-typescript-80839fbd5.0",
32
31
  "ncp": "^2.0.0"
33
32
  },
34
33
  "devDependencies": {
@@ -36,5 +35,6 @@
36
35
  },
37
36
  "browser": {
38
37
  "./src/IDBCache.js": "./src/IDBCache.browser.js"
39
- }
38
+ },
39
+ "gitHead": "80839fbd5c6d6668c2622849856a4b25601354a8"
40
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
 
@@ -174,12 +172,14 @@ export class LMDBLiteCache implements Cache {
174
172
  if (!getFeatureFlag('cachePerformanceImprovements')) {
175
173
  return pipeline(
176
174
  stream,
175
+ // @ts-expect-error TS2554
177
176
  this.fs.createWriteStream(path.join(this.dir, key)),
178
177
  );
179
178
  }
180
179
 
181
180
  const filePath = this.getFileKey(key);
182
181
  await this.fs.mkdirp(path.dirname(filePath));
182
+ // @ts-expect-error TS2554
183
183
  return pipeline(stream, this.fs.createWriteStream(filePath));
184
184
  }
185
185
 
@@ -200,7 +200,7 @@ export class LMDBLiteCache implements Cache {
200
200
  await this.store.put(key, contents);
201
201
  }
202
202
 
203
- getBuffer(key: string): Promise<?Buffer> {
203
+ getBuffer(key: string): Promise<Buffer | null | undefined> {
204
204
  return Promise.resolve(this.store.get(key));
205
205
  }
206
206
 
@@ -222,7 +222,9 @@ export class LMDBLiteCache implements Cache {
222
222
  async setLargeBlob(
223
223
  key: string,
224
224
  contents: Buffer | string,
225
- options?: {|signal?: AbortSignal|},
225
+ options?: {
226
+ signal?: AbortSignal;
227
+ },
226
228
  ): Promise<void> {
227
229
  if (!getFeatureFlag('cachePerformanceImprovements')) {
228
230
  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/lib/types.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Cache } from "@atlaspack/types";
2
- export type { Cache };