Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metro-cache

Package Overview
Dependencies
Maintainers
1
Versions
145
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.40.0 to 0.40.1

src.real/Cache.js.flow

6

package.json
{
"version": "0.40.0",
"version": "0.40.1",
"name": "metro-cache",

@@ -16,3 +16,3 @@ "description": "🚇 Cache layers for Metro",

"jest-serializer": "23.0.1",
"metro-core": "0.40.0",
"metro-core": "0.40.1",
"mkdirp": "^0.5.1",

@@ -22,4 +22,4 @@ "rimraf": "^2.5.4"

"devDependencies": {
"metro-memory-fs": "0.40.0"
"metro-memory-fs": "0.40.1"
}
}

@@ -7,25 +7,25 @@ /**

*
* @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");});};}var _require =
const {Logger} = require('metro-core');
require('metro-core');const Logger = _require.Logger;
import type {CacheStore} from 'metro-cache';
/**
* Main cache class. Receives an array of cache instances, and sequentially
* traverses them to return a previously stored value. It also ensures setting
* the value in all instances.
*
* All get/set operations are logged via Metro's logger.
*/
class Cache<T> {
_stores: $ReadOnlyArray<CacheStore<T>>;
* Main cache class. Receives an array of cache instances, and sequentially
* traverses them to return a previously stored value. It also ensures setting
* the value in all instances.
*
* All get/set operations are logged via Metro's logger.
*/
class Cache {
_hits: WeakMap<Buffer, CacheStore<T>>;
constructor(stores: $ReadOnlyArray<CacheStore<T>>) {
constructor(stores) {
this._hits = new WeakMap();

@@ -35,48 +35,48 @@ 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++) {
const store = stores[i];
const name = store.constructor.name + '::' + key.toString('hex');
let value = null;
for (let i = 0; i < length; i++) {
const store = stores[i];
const name = store.constructor.name + '::' + key.toString('hex');
let value = null;
const logStart = Logger.log(
const logStart = Logger.log(
Logger.createActionStartEntry({
action_name: 'Cache get',
log_entry_label: name,
}),
);
log_entry_label: name }));
try {
const valueOrPromise = store.get(key);
if (valueOrPromise && typeof valueOrPromise.then === 'function') {
value = await valueOrPromise;
} else {
value = valueOrPromise;
}
} finally {
Logger.log(Logger.createActionEndEntry(logStart));
Logger.log(
try {
const valueOrPromise = store.get(key);
if (valueOrPromise && typeof valueOrPromise.then === 'function') {
value = yield valueOrPromise;
} else {
value = valueOrPromise;
}
} finally {
Logger.log(Logger.createActionEndEntry(logStart));
Logger.log(
Logger.createEntry({
action_name: 'Cache ' + (value == null ? 'miss' : 'hit'),
log_entry_label: name,
}),
);
log_entry_label: name }));
if (value != null) {
this._hits.set(key, store);
return value;
if (value != null) {
_this._hits.set(key, store);
return value;
}
}
}
}
return null;
return null;})();
}
set(key: Buffer, value: T): void {
set(key, value) {
const stores = this._stores;

@@ -92,8 +92,8 @@ const stop = this._hits.get(key);

Logger.log(
Logger.createEntry({
action_name: 'Cache set',
log_entry_label: name,
}),
);
Logger.createEntry({
action_name: 'Cache set',
log_entry_label: name }));
promises.push(stores[i].set(key, value));

@@ -107,5 +107,5 @@ }

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

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

*
* @flow
*
* @format

@@ -20,6 +20,6 @@ */

export type {Options as FileOptions} from './stores/FileStore';
export type {Options as HttpOptions} from './stores/HttpStore';
export type {CacheStore} from './types.flow';
module.exports.Cache = Cache;

@@ -29,2 +29,2 @@ module.exports.FileStore = FileStore;

module.exports.stableHash = stableHash;
module.exports.stableHash = stableHash;

@@ -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('md4')
.update(JSON.stringify(value, canonicalize))
.digest('buffer');
function stableHash(value) {
return crypto.
createHash('md4').
update(JSON.stringify(value, canonicalize)).
digest('buffer');
}
module.exports = stableHash;
module.exports = stableHash;

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

* @format
* @flow
*
*/

@@ -19,10 +19,10 @@

export type Options = {|
root: string,
|};
class FileStore<T> {
_root: string;
constructor(options: Options) {
class FileStore {
constructor(options) {
this._root = options.root;

@@ -32,3 +32,3 @@ this._createDirs();

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

@@ -45,3 +45,3 @@ return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf8'));

set(key: Buffer, value: T): void {
set(key, value) {
fs.writeFileSync(this._getFilePath(key), JSON.stringify(value));

@@ -55,8 +55,8 @@ }

_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'));
}

@@ -74,5 +74,5 @@

}
}
}
}}
module.exports = FileStore;
module.exports = FileStore;

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

* @format
* @flow
*
*/

@@ -19,24 +19,24 @@

export type Options = {|
endpoint: string,
family?: 4 | 6,
timeout?: number,
|};
const ZLIB_OPTIONS = {
level: 9,
};
level: 9 };
class HttpStore<T> {
_module: typeof http | typeof https;
_timeout: number;
_host: string;
_port: number;
_path: string;
class HttpStore {
_getAgent: http$Agent;
_setAgent: http$Agent;
constructor(options: Options) {
constructor(options) {
const uri = url.parse(options.endpoint);

@@ -50,5 +50,5 @@ const module = uri.protocol === 'http:' ? http : https;

maxSockets: 64,
maxFreeSockets: 64,
};
maxFreeSockets: 64 };
if (!uri.hostname || !uri.pathname) {

@@ -69,3 +69,3 @@ throw new TypeError('Invalid endpoint: ' + options.endpoint);

get(key: Buffer): Promise<?T> {
get(key) {
return new Promise((resolve, reject) => {

@@ -78,5 +78,5 @@ const options = {

port: this._port,
timeout: this._timeout,
};
timeout: this._timeout };
const req = this._module.request(options, res => {

@@ -127,3 +127,3 @@ let data = '';

set(key: Buffer, value: T): Promise<void> {
set(key, value) {
return new Promise((resolve, reject) => {

@@ -138,5 +138,5 @@ const gzip = zlib.createGzip(ZLIB_OPTIONS);

port: this._port,
timeout: this._timeout,
};
timeout: this._timeout };
const req = this._module.request(options, res => {

@@ -166,5 +166,5 @@ res.on('error', err => {

// Not implemented.
}
}
}}
module.exports = HttpStore;
module.exports = HttpStore;

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

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

@@ -18,8 +18,8 @@ /**

/**
* Main cache class. Receives an array of cache instances, and sequentially
* traverses them to return a previously stored value. It also ensures setting
* the value in all instances.
*
* All get/set operations are logged via Metro's logger.
*/
* Main cache class. Receives an array of cache instances, and sequentially
* traverses them to return a previously stored value. It also ensures setting
* the value in all instances.
*
* All get/set operations are logged via Metro's logger.
*/
class Cache {

@@ -26,0 +26,0 @@

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