@atlaspack/cache 2.12.1-dev.3478 → 2.12.1-dev.3520

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/lib/FSCache.js CHANGED
@@ -32,9 +32,9 @@ function _logger() {
32
32
  };
33
33
  return data;
34
34
  }
35
- function _core() {
36
- const data = require("@atlaspack/core");
37
- _core = function () {
35
+ function _buildCache() {
36
+ const data = require("@atlaspack/build-cache");
37
+ _buildCache = function () {
38
38
  return data;
39
39
  };
40
40
  return data;
@@ -146,7 +146,7 @@ class FSCache {
146
146
  async get(key) {
147
147
  try {
148
148
  let data = await this.fs.readFile(this._getCachePath(key));
149
- return (0, _core().deserialize)(data);
149
+ return (0, _buildCache().deserialize)(data);
150
150
  } catch (err) {
151
151
  if (err.code === 'ENOENT') {
152
152
  return null;
@@ -158,7 +158,7 @@ class FSCache {
158
158
  async set(key, value) {
159
159
  try {
160
160
  let blobPath = this._getCachePath(key);
161
- let data = (0, _core().serialize)(value);
161
+ let data = (0, _buildCache().serialize)(value);
162
162
  await this.fs.writeFile(blobPath, data);
163
163
  } catch (err) {
164
164
  _logger().default.error(err, '@atlaspack/cache');
@@ -169,4 +169,4 @@ class FSCache {
169
169
  }
170
170
  }
171
171
  exports.FSCache = FSCache;
172
- (0, _core().registerSerializableClass)(`${_package.default.version}:FSCache`, FSCache);
172
+ (0, _buildCache().registerSerializableClass)(`${_package.default.version}:FSCache`, FSCache);
@@ -11,9 +11,9 @@ function _stream() {
11
11
  };
12
12
  return data;
13
13
  }
14
- function _core() {
15
- const data = require("@atlaspack/core");
16
- _core = function () {
14
+ function _buildCache() {
15
+ const data = require("@atlaspack/build-cache");
16
+ _buildCache = function () {
17
17
  return data;
18
18
  };
19
19
  return data;
@@ -25,7 +25,6 @@ function _utils() {
25
25
  };
26
26
  return data;
27
27
  }
28
- var _package = _interopRequireDefault(require("../package.json"));
29
28
  function _idb() {
30
29
  const data = require("idb");
31
30
  _idb = function () {
@@ -33,6 +32,7 @@ function _idb() {
33
32
  };
34
33
  return data;
35
34
  }
35
+ var _package = _interopRequireDefault(require("../package.json"));
36
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
37
  // $FlowFixMe[untyped-import]
38
38
  // $FlowFixMe[untyped-import]
@@ -69,10 +69,10 @@ class IDBCache {
69
69
  if (data == null) {
70
70
  return null;
71
71
  }
72
- return Promise.resolve((0, _core().deserialize)(data));
72
+ return Promise.resolve((0, _buildCache().deserialize)(data));
73
73
  }
74
74
  async set(key, value) {
75
- await (await this.store).put(STORE_NAME, (0, _core().serialize)(value), key);
75
+ await (await this.store).put(STORE_NAME, (0, _buildCache().serialize)(value), key);
76
76
  }
77
77
  getStream(key) {
78
78
  let dataPromise = this.store.then(s => s.get(STORE_NAME, key)).then(d => Buffer.from(d)).catch(e => e);
@@ -145,4 +145,4 @@ class IDBCache {
145
145
  }
146
146
  }
147
147
  exports.IDBCache = IDBCache;
148
- (0, _core().registerSerializableClass)(`${_package.default.version}:IDBCache`, IDBCache);
148
+ (0, _buildCache().registerSerializableClass)(`${_package.default.version}:IDBCache`, IDBCache);
package/lib/LMDBCache.js CHANGED
@@ -25,9 +25,9 @@ function _util() {
25
25
  };
26
26
  return data;
27
27
  }
28
- function _core() {
29
- const data = require("@atlaspack/core");
30
- _core = function () {
28
+ function _buildCache() {
29
+ const data = require("@atlaspack/build-cache");
30
+ _buildCache = function () {
31
31
  return data;
32
32
  };
33
33
  return data;
@@ -39,7 +39,6 @@ function _fs() {
39
39
  };
40
40
  return data;
41
41
  }
42
- var _package = _interopRequireDefault(require("../package.json"));
43
42
  function _lmdb() {
44
43
  const data = _interopRequireDefault(require("lmdb"));
45
44
  _lmdb = function () {
@@ -47,6 +46,7 @@ function _lmdb() {
47
46
  };
48
47
  return data;
49
48
  }
49
+ var _package = _interopRequireDefault(require("../package.json"));
50
50
  var _FSCache = require("./FSCache");
51
51
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
52
52
  // flowlint-next-line untyped-import:off
@@ -84,10 +84,10 @@ class LMDBCache {
84
84
  if (data == null) {
85
85
  return Promise.resolve(null);
86
86
  }
87
- return Promise.resolve((0, _core().deserialize)(data));
87
+ return Promise.resolve((0, _buildCache().deserialize)(data));
88
88
  }
89
89
  async set(key, value) {
90
- await this.setBlob(key, (0, _core().serialize)(value));
90
+ await this.setBlob(key, (0, _buildCache().serialize)(value));
91
91
  }
92
92
  getStream(key) {
93
93
  return this.fs.createReadStream(_path().default.join(this.dir, key));
@@ -133,4 +133,4 @@ class LMDBCache {
133
133
  }
134
134
  }
135
135
  exports.LMDBCache = LMDBCache;
136
- (0, _core().registerSerializableClass)(`${_package.default.version}:LMDBCache`, LMDBCache);
136
+ (0, _buildCache().registerSerializableClass)(`${_package.default.version}:LMDBCache`, LMDBCache);
@@ -5,6 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.LmdbWrapper = exports.LMDBLiteCache = void 0;
7
7
  exports.open = open;
8
+ function _buildCache() {
9
+ const data = require("@atlaspack/build-cache");
10
+ _buildCache = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
8
15
  function _rust() {
9
16
  const data = require("@atlaspack/rust");
10
17
  _rust = function () {
@@ -33,13 +40,6 @@ function _util() {
33
40
  };
34
41
  return data;
35
42
  }
36
- function _core() {
37
- const data = require("@atlaspack/core");
38
- _core = function () {
39
- return data;
40
- };
41
- return data;
42
- }
43
43
  function _fs() {
44
44
  const data = require("@atlaspack/fs");
45
45
  _fs = function () {
@@ -81,8 +81,6 @@ function open(directory
81
81
  }
82
82
  const pipeline = (0, _util().promisify)(_stream().default.pipeline);
83
83
  class LMDBLiteCache {
84
- // $FlowFixMe
85
-
86
84
  constructor(cacheDir) {
87
85
  this.fs = new (_fs().NodeFS)();
88
86
  this.dir = cacheDir;
@@ -93,6 +91,13 @@ class LMDBLiteCache {
93
91
  compression: true
94
92
  });
95
93
  }
94
+
95
+ /**
96
+ * Use this to pass the native LMDB instance back to Rust.
97
+ */
98
+ getNativeRef() {
99
+ return this.store.lmdb;
100
+ }
96
101
  ensure() {
97
102
  return Promise.resolve();
98
103
  }
@@ -101,8 +106,8 @@ class LMDBLiteCache {
101
106
  dir: this.dir
102
107
  };
103
108
  }
104
- static deserialize(opts) {
105
- return new LMDBLiteCache(opts.dir);
109
+ static deserialize(cache) {
110
+ return new LMDBLiteCache(cache.dir);
106
111
  }
107
112
  has(key) {
108
113
  return Promise.resolve(this.store.get(key) != null);
@@ -112,10 +117,10 @@ class LMDBLiteCache {
112
117
  if (data == null) {
113
118
  return Promise.resolve(null);
114
119
  }
115
- return Promise.resolve((0, _core().deserialize)(data));
120
+ return Promise.resolve((0, _buildCache().deserialize)(data));
116
121
  }
117
122
  async set(key, value) {
118
- await this.setBlob(key, (0, _core().serialize)(value));
123
+ await this.setBlob(key, (0, _buildCache().serialize)(value));
119
124
  }
120
125
  getStream(key) {
121
126
  return this.fs.createReadStream(_path().default.join(this.dir, key));
@@ -123,12 +128,10 @@ class LMDBLiteCache {
123
128
  setStream(key, stream) {
124
129
  return pipeline(stream, this.fs.createWriteStream(_path().default.join(this.dir, key)));
125
130
  }
126
- getBlob(key) {
127
- try {
128
- return Promise.resolve(this.getBlobSync(key));
129
- } catch (err) {
130
- return Promise.reject(err);
131
- }
131
+
132
+ // eslint-disable-next-line require-await
133
+ async getBlob(key) {
134
+ return this.getBlobSync(key);
132
135
  }
133
136
  getBlobSync(key) {
134
137
  const buffer = this.store.get(key);
@@ -171,4 +174,4 @@ class LMDBLiteCache {
171
174
  }
172
175
  }
173
176
  exports.LMDBLiteCache = LMDBLiteCache;
174
- (0, _core().registerSerializableClass)(`${_package.default.version}:LMDBLiteCache`, LMDBLiteCache);
177
+ (0, _buildCache().registerSerializableClass)(`${_package.default.version}:LMDBLiteCache`, LMDBLiteCache);
package/lib/index.js CHANGED
@@ -3,47 +3,47 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _LMDBCache = require("./LMDBCache");
7
- Object.keys(_LMDBCache).forEach(function (key) {
6
+ var _FSCache = require("./FSCache");
7
+ Object.keys(_FSCache).forEach(function (key) {
8
8
  if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _LMDBCache[key]) return;
9
+ if (key in exports && exports[key] === _FSCache[key]) return;
10
10
  Object.defineProperty(exports, key, {
11
11
  enumerable: true,
12
12
  get: function () {
13
- return _LMDBCache[key];
13
+ return _FSCache[key];
14
14
  }
15
15
  });
16
16
  });
17
- var _LMDBLiteCache = require("./LMDBLiteCache");
18
- Object.keys(_LMDBLiteCache).forEach(function (key) {
17
+ var _IDBCache = require("./IDBCache");
18
+ Object.keys(_IDBCache).forEach(function (key) {
19
19
  if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _LMDBLiteCache[key]) return;
20
+ if (key in exports && exports[key] === _IDBCache[key]) return;
21
21
  Object.defineProperty(exports, key, {
22
22
  enumerable: true,
23
23
  get: function () {
24
- return _LMDBLiteCache[key];
24
+ return _IDBCache[key];
25
25
  }
26
26
  });
27
27
  });
28
- var _FSCache = require("./FSCache");
29
- Object.keys(_FSCache).forEach(function (key) {
28
+ var _LMDBCache = require("./LMDBCache");
29
+ Object.keys(_LMDBCache).forEach(function (key) {
30
30
  if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _FSCache[key]) return;
31
+ if (key in exports && exports[key] === _LMDBCache[key]) return;
32
32
  Object.defineProperty(exports, key, {
33
33
  enumerable: true,
34
34
  get: function () {
35
- return _FSCache[key];
35
+ return _LMDBCache[key];
36
36
  }
37
37
  });
38
38
  });
39
- var _IDBCache = require("./IDBCache");
40
- Object.keys(_IDBCache).forEach(function (key) {
39
+ var _LMDBLiteCache = require("./LMDBLiteCache");
40
+ Object.keys(_LMDBLiteCache).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _IDBCache[key]) return;
42
+ if (key in exports && exports[key] === _LMDBLiteCache[key]) return;
43
43
  Object.defineProperty(exports, key, {
44
44
  enumerable: true,
45
45
  get: function () {
46
- return _IDBCache[key];
46
+ return _LMDBLiteCache[key];
47
47
  }
48
48
  });
49
49
  });
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": "2.12.1-dev.3478+5fd2da535",
4
+ "version": "2.12.1-dev.3520+8a5346e28",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -22,15 +22,13 @@
22
22
  "check-ts": "tsc --noEmit index.d.ts"
23
23
  },
24
24
  "dependencies": {
25
- "@atlaspack/fs": "2.12.1-dev.3478+5fd2da535",
26
- "@atlaspack/logger": "2.12.1-dev.3478+5fd2da535",
27
- "@atlaspack/rust": "2.12.1-dev.3478+5fd2da535",
28
- "@atlaspack/utils": "2.12.1-dev.3478+5fd2da535",
25
+ "@atlaspack/build-cache": "2.12.1-dev.3520+8a5346e28",
26
+ "@atlaspack/fs": "2.12.1-dev.3520+8a5346e28",
27
+ "@atlaspack/logger": "2.12.1-dev.3520+8a5346e28",
28
+ "@atlaspack/rust": "2.12.1-dev.3520+8a5346e28",
29
+ "@atlaspack/utils": "2.12.1-dev.3520+8a5346e28",
29
30
  "lmdb": "2.8.5"
30
31
  },
31
- "peerDependencies": {
32
- "@atlaspack/core": "^2.12.1-dev.3478+5fd2da535"
33
- },
34
32
  "devDependencies": {
35
33
  "idb": "^5.0.8"
36
34
  },
@@ -38,5 +36,5 @@
38
36
  "./src/IDBCache.js": "./src/IDBCache.browser.js",
39
37
  "./src/LMDBCache.js": false
40
38
  },
41
- "gitHead": "5fd2da535ecbe096d57e03aec15e80bb1d7601f7"
39
+ "gitHead": "8a5346e28c1bb3b9cd40f1c4e77c66dd6666f1e4"
42
40
  }
package/src/FSCache.js CHANGED
@@ -8,14 +8,17 @@ import type {Cache} from './types';
8
8
  import stream from 'stream';
9
9
  import path from 'path';
10
10
  import {promisify} from 'util';
11
+
11
12
  import logger from '@atlaspack/logger';
12
13
  import {
13
- serialize,
14
14
  deserialize,
15
15
  registerSerializableClass,
16
- } from '@atlaspack/core';
16
+ serialize,
17
+ } from '@atlaspack/build-cache';
18
+
17
19
  // flowlint-next-line untyped-import:off
18
20
  import packageJson from '../package.json';
21
+
19
22
  import {WRITE_LIMIT_CHUNK} from './constants';
20
23
 
21
24
  const pipeline: (Readable, Writable) => Promise<void> = promisify(
@@ -2,17 +2,19 @@
2
2
  import type {Cache} from './types';
3
3
 
4
4
  import {Readable} from 'stream';
5
+
5
6
  import {
6
- serialize,
7
7
  deserialize,
8
8
  registerSerializableClass,
9
- } from '@atlaspack/core';
9
+ serialize,
10
+ } from '@atlaspack/build-cache';
10
11
  import {bufferStream} from '@atlaspack/utils';
11
12
  // $FlowFixMe[untyped-import]
12
- import packageJson from '../package.json';
13
- // $FlowFixMe[untyped-import]
14
13
  import {openDB} from 'idb';
15
14
 
15
+ // $FlowFixMe[untyped-import]
16
+ import packageJson from '../package.json';
17
+
16
18
  const STORE_NAME = 'cache';
17
19
 
18
20
  export class IDBCache implements Cache {
package/src/LMDBCache.js CHANGED
@@ -6,17 +6,19 @@ import type {Readable, Writable} from 'stream';
6
6
  import stream from 'stream';
7
7
  import path from 'path';
8
8
  import {promisify} from 'util';
9
+
9
10
  import {
10
- serialize,
11
11
  deserialize,
12
12
  registerSerializableClass,
13
- } from '@atlaspack/core';
13
+ serialize,
14
+ } from '@atlaspack/build-cache';
14
15
  import {NodeFS} from '@atlaspack/fs';
15
16
  // flowlint-next-line untyped-import:off
16
- import packageJson from '../package.json';
17
- // $FlowFixMe
18
17
  import lmdb from 'lmdb';
19
18
 
19
+ // $FlowFixMe
20
+ import packageJson from '../package.json';
21
+
20
22
  import {FSCache} from './FSCache';
21
23
 
22
24
  const pipeline: (Readable, Writable) => Promise<void> = promisify(
@@ -1,5 +1,10 @@
1
1
  // @flow strict-local
2
2
 
3
+ import {
4
+ deserialize,
5
+ registerSerializableClass,
6
+ serialize,
7
+ } from '@atlaspack/build-cache';
3
8
  import {Lmdb} from '@atlaspack/rust';
4
9
  import type {FilePath} from '@atlaspack/types';
5
10
  import type {Cache} from './types';
@@ -8,12 +13,9 @@ import type {Readable, Writable} from 'stream';
8
13
  import stream from 'stream';
9
14
  import path from 'path';
10
15
  import {promisify} from 'util';
11
- import {
12
- serialize,
13
- deserialize,
14
- registerSerializableClass,
15
- } from '@atlaspack/core';
16
+
16
17
  import {NodeFS} from '@atlaspack/fs';
18
+
17
19
  // $FlowFixMe
18
20
  import packageJson from '../package.json';
19
21
 
@@ -70,11 +72,14 @@ const pipeline: (Readable, Writable) => Promise<void> = promisify(
70
72
  stream.pipeline,
71
73
  );
72
74
 
75
+ export type SerLMDBLiteCache = {|
76
+ dir: FilePath,
77
+ |};
78
+
73
79
  export class LMDBLiteCache implements Cache {
74
80
  fs: NodeFS;
75
81
  dir: FilePath;
76
- // $FlowFixMe
77
- store: any;
82
+ store: LmdbWrapper;
78
83
  fsCache: FSCache;
79
84
 
80
85
  constructor(cacheDir: FilePath) {
@@ -89,18 +94,25 @@ export class LMDBLiteCache implements Cache {
89
94
  });
90
95
  }
91
96
 
97
+ /**
98
+ * Use this to pass the native LMDB instance back to Rust.
99
+ */
100
+ getNativeRef(): Lmdb {
101
+ return this.store.lmdb;
102
+ }
103
+
92
104
  ensure(): Promise<void> {
93
105
  return Promise.resolve();
94
106
  }
95
107
 
96
- serialize(): {|dir: FilePath|} {
108
+ serialize(): SerLMDBLiteCache {
97
109
  return {
98
110
  dir: this.dir,
99
111
  };
100
112
  }
101
113
 
102
- static deserialize(opts: {|dir: FilePath|}): LMDBLiteCache {
103
- return new LMDBLiteCache(opts.dir);
114
+ static deserialize(cache: SerLMDBLiteCache): LMDBLiteCache {
115
+ return new LMDBLiteCache(cache.dir);
104
116
  }
105
117
 
106
118
  has(key: string): Promise<boolean> {
@@ -131,12 +143,9 @@ export class LMDBLiteCache implements Cache {
131
143
  );
132
144
  }
133
145
 
134
- getBlob(key: string): Promise<Buffer> {
135
- try {
136
- return Promise.resolve(this.getBlobSync(key));
137
- } catch (err) {
138
- return Promise.reject(err);
139
- }
146
+ // eslint-disable-next-line require-await
147
+ async getBlob(key: string): Promise<Buffer> {
148
+ return this.getBlobSync(key);
140
149
  }
141
150
 
142
151
  getBlobSync(key: string): Buffer {
package/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // @flow
2
- export type {Cache} from './types';
3
- export * from './LMDBCache';
4
- export * from './LMDBLiteCache';
2
+
5
3
  export * from './FSCache';
6
4
  export * from './IDBCache';
5
+ export * from './LMDBCache';
6
+ export * from './LMDBLiteCache';
7
+
8
+ export type {Cache} from './types';