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

@verdaccio/local-storage

Package Overview
Dependencies
Maintainers
1
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@verdaccio/local-storage - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

24

lib/local-data.js

@@ -43,4 +43,5 @@ 'use strict';

*/
constructor(path, logger) {
this.path = path;
constructor(config, logger) {
this.config = config;
this.path = this._buildStoragePath(config);
this.logger = logger;

@@ -52,6 +53,17 @@ this.locked = false;

/**
* Fetch local packages.
* @private
* @return {Object}
*/
* Build the local database path.
* @param {Object} config
* @return {string|String|*}
* @private
*/
_buildStoragePath(config) {
// FUTURE: the database might be parameterizable from config.yaml
return (_path || _load_path()).default.join((_path || _load_path()).default.resolve((_path || _load_path()).default.dirname(config.self_path || ''), config.storage, '.sinopia-db.json'));
}
/**
* Fetch local packages.
* @private
* @return {Object}
*/
_fetchLocalPackages() {

@@ -58,0 +70,0 @@ const emptyDatabase = { list: [] };

@@ -111,7 +111,7 @@ 'use strict';

unlink(fileName, callback) {
deleteJSON(fileName, callback) {
return (_fs || _load_fs()).default.unlink(this._getStorage(fileName), callback);
}
rmdir(dirPath, callback) {
removePackage(dirPath, callback) {
(_fs || _load_fs()).default.rmdir(this._getStorage(dirPath), callback);

@@ -118,0 +118,0 @@ }

@@ -117,20 +117,9 @@ 'use strict';

constructor(config, logger, utils) {
this.localList = new (_localData || _load_localData()).default(config, logger);
this.logger = logger.child({ sub: 'fs' });
this.config = config;
this.utils = utils;
this.localList = new (_localData || _load_localData()).default(this._buildStoragePath(this.config), logger);
this.logger = logger.child({ sub: 'fs' });
}
/**
* Build the local database path.
* @param {Object} config
* @return {string|String|*}
* @private
*/
_buildStoragePath(config) {
// FUTURE: the database might be parameterizable from config.yaml
return (_path || _load_path()).default.join((_path || _load_path()).default.resolve((_path || _load_path()).default.dirname(config.self_path || ''), config.storage, '.sinopia-db.json'));
}
/**
* Add a package.

@@ -170,4 +159,2 @@ * @param {*} name

removePackage(name, callback) {
this.logger.info({ name: name }, 'unpublishing @{name} (all)');
let storage = this._getLocalStorage(name);

@@ -189,2 +176,3 @@ if (!storage) {

let removeFailed = this.localList.remove(name);
if (removeFailed) {

@@ -195,16 +183,15 @@ // This will happen when database is locked

storage.unlink(pkgFileName, function (err) {
storage.deleteJSON(pkgFileName, function (err) {
if (err) {
return callback(err);
}
const attachments = (0, (_keys || _load_keys()).default)(data._attachments);
const files = (0, (_keys || _load_keys()).default)(data._attachments);
const unlinkNext = function unlinkNext(cb) {
if (files.length === 0) {
if (attachments.length === 0) {
return cb();
}
let file = files.shift();
storage.unlink(file, function () {
const attachment = attachments.shift();
storage.deleteJSON(attachment, function () {
unlinkNext(cb);

@@ -216,3 +203,3 @@ });

// try to unlink the directory, but ignore errors because it can fail
storage.rmdir('.', function (err) {
storage.removePackage('.', function (err) {
callback(err);

@@ -485,3 +472,3 @@ });

if (storage) {
storage.unlink(filename, callback);
storage.deleteJSON(filename, callback);
}

@@ -673,25 +660,6 @@ });

this.readJSON(storage, callback);
this._readJSON(storage, callback);
}
/**
* Read a json file from storage.
* @param {Object} storage
* @param {Function} callback
*/
readJSON(storage, callback) {
storage.readJSON(pkgFileName, (err, result) => {
if (err) {
if (err.code === noSuchFile) {
return callback(this.utils.ErrorCode.get404());
} else {
return callback(this._internalError(err, pkgFileName, 'error reading'));
}
}
this._normalizePackage(result);
callback(err, result);
});
}
/**
* Search a local package.

@@ -722,3 +690,3 @@ * @param {*} startKey

const version = data.versions[latest];
const sss = {
const pkg = {
'name': version.name,

@@ -736,8 +704,8 @@ 'description': version.description,

'time': {
modified: item.time ? new Date(item.time).toISOString() : undefined
modified: item.time ? new Date(item.time).toISOString() : stats.mtime
},
'versions': {}
'versions': { [latest]: 'latest' }
};
stream.push(sss);
stream.push(pkg);
}

@@ -752,3 +720,5 @@

}, function on_end(err) {
if (err) return stream.emit('error', err);
if (err) {
return stream.emit('error', err);
}
stream.end();

@@ -779,2 +749,21 @@ });

/**
* Read a json file from storage.
* @param {Object} storage
* @param {Function} callback
*/
_readJSON(storage, callback) {
storage.readJSON(pkgFileName, (err, result) => {
if (err) {
if (err.code === noSuchFile) {
return callback(this.utils.ErrorCode.get404());
} else {
return callback(this._internalError(err, pkgFileName, 'error reading'));
}
}
this._normalizePackage(result);
callback(err, result);
});
}
/**
* Verify the right local storage location.

@@ -882,2 +871,3 @@ * @param {String} path

}
storage.readJSON(pkgFileName, (err, data) => {

@@ -884,0 +874,0 @@ // TODO: race condition

{
"name": "@verdaccio/local-storage",
"version": "0.0.5",
"version": "0.0.6",
"description": "local storage implementation",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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