Socket
Socket
Sign inDemoInstall

metro-cache

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-cache - npm Package Compare versions

Comparing version 0.29.0 to 0.30.0

src.real/Cache.js.flow

2

package.json
{
"version": "0.29.0",
"version": "0.30.0",
"name": "metro-cache",

@@ -4,0 +4,0 @@ "description": "🚇 Cache layers for Metro",

@@ -7,16 +7,16 @@ /**

*
* @flow
*
* @format
*/
'use strict';
'use strict';function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};}
import type {CacheStore} from 'metro-cache';
class Cache<T> {
_stores: $ReadOnlyArray<CacheStore<T>>;
_hits: WeakMap<Buffer, CacheStore<T>>;
class Cache {
constructor(stores: $ReadOnlyArray<CacheStore<T>>) {
constructor(stores) {
this._hits = new WeakMap();

@@ -26,24 +26,24 @@ this._stores = stores;

async get(key: Buffer): Promise<?T> {
const stores = this._stores;
const length = stores.length;
get(key) {var _this = this;return _asyncToGenerator(function* () {
const stores = _this._stores;
const length = stores.length;
for (let i = 0; i < length; i++) {
let value = stores[i].get(key);
for (let i = 0; i < length; i++) {
let value = stores[i].get(key);
if (value instanceof Promise) {
value = await value;
}
if (value instanceof Promise) {
value = yield value;
}
if (value != null) {
this._hits.set(key, stores[i]);
if (value != null) {
_this._hits.set(key, stores[i]);
return value;
return value;
}
}
}
return null;
return null;})();
}
set(key: Buffer, value: T): void {
set(key, value) {
const stores = this._stores;

@@ -63,5 +63,5 @@ const stop = this._hits.get(key);

});
}
}
}}
module.exports = Cache;
module.exports = Cache;

@@ -8,3 +8,3 @@ /**

* @format
* @flow
*
*/

@@ -18,12 +18,12 @@

import type {TransformedCode} from 'metro/src/JSTransformer/worker';
export type Options = {|
root: string,
|};
class FileStore {
_root: string;
constructor(options: Options) {
constructor(options) {
const root = options.root;

@@ -38,3 +38,3 @@

get(key: Buffer): ?TransformedCode {
get(key) {
try {

@@ -51,15 +51,15 @@ return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf-8'));

set(key: Buffer, value: TransformedCode): void {
set(key, value) {
fs.writeFileSync(this._getFilePath(key), JSON.stringify(value));
}
_getFilePath(key: Buffer): string {
_getFilePath(key) {
return path.join(
this._root,
key.slice(0, 1).toString('hex'),
key.slice(1).toString('hex'),
);
}
}
this._root,
key.slice(0, 1).toString('hex'),
key.slice(1).toString('hex'));
module.exports = FileStore;
}}
module.exports = FileStore;

@@ -7,3 +7,3 @@ /**

*
* @flow
*
* @format

@@ -19,6 +19,6 @@ */

export type {CacheStore} from './types.flow';
module.exports.Cache = Cache;
module.exports.FileStore = FileStore;
module.exports.stableHash = stableHash;
module.exports.stableHash = stableHash;

@@ -8,3 +8,3 @@ /**

* @format
* @flow
*
*/

@@ -17,15 +17,15 @@

export type Options = {|
path: string,
writeDelay: ?number,
|};
class PersistedMapStore {
_map: ?Map<string, mixed>;
_path: string;
_store: () => void;
_timeout: ?TimeoutID;
_writeDelay: number;
constructor(options: Options) {
constructor(options) {
this._path = options.path;

@@ -39,3 +39,3 @@ this._writeDelay = options.writeDelay || 5000;

get(key: Buffer): mixed {
get(key) {
this._getMap();

@@ -50,3 +50,3 @@

set(key: Buffer, value: mixed) {
set(key, value) {
this._getMap();

@@ -76,5 +76,5 @@

this._timeout = null;
}
}
}}
module.exports = PersistedMapStore;
module.exports = PersistedMapStore;

@@ -7,3 +7,3 @@ /**

*
* @flow
*
* @format

@@ -16,3 +16,3 @@ */

function canonicalize(key: string, value: mixed): mixed {
function canonicalize(key, value) {
if (!(value instanceof Object) || value instanceof Array) {

@@ -33,9 +33,9 @@ return value;

function stableHash(value: mixed) {
return crypto
.createHash('md5')
.update(JSON.stringify(value, canonicalize))
.digest();
function stableHash(value) {
return crypto.
createHash('md4').
update(JSON.stringify(value, canonicalize)).
digest();
}
module.exports = stableHash;
module.exports = stableHash;

@@ -7,11 +7,6 @@ /**

*
* @flow
*
* @format
*/
'use strict';
export type CacheStore<T> = {
get(key: Buffer): ?T | Promise<?T>,
set(key: Buffer, value: T): void | Promise<void>,
};
'use strict';

@@ -33,3 +33,3 @@ /**

return crypto.
createHash('md5').
createHash('md4').
update(JSON.stringify(value, canonicalize)).

@@ -36,0 +36,0 @@ digest();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc