0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/docker-examples/v4/docker-plugin-external/plugins/verdaccio-memory/lib/local-memory.js
Juan Picado 418bf0d8fa add docker-examples to prettier format
include it to the ci paths list
2021-11-19 19:55:27 +01:00

96 lines
1.8 KiB
JavaScript

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true,
});
let _memoryHandler = require('./memory-handler');
let _memoryHandler2 = _interopRequireDefault(_memoryHandler);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const DEFAULT_LIMIT = 1000;
class LocalMemory {
constructor(config, options) {
this.config = config;
this.limit = config.limit || DEFAULT_LIMIT;
this.logger = options.logger;
this.data = this._createEmtpyDatabase();
}
getSecret() {
return Promise.resolve(this.data.secret);
}
setSecret(secret) {
return new Promise((resolve, reject) => {
this.data.secret = secret;
resolve(null);
});
}
add(name, cb) {
const list = this.data.list;
if (list.length < this.limit) {
if (list.indexOf(name) === -1) {
list.push(name);
}
cb(null);
} else {
this.logger.info(
{ limit: this.limit },
'Storage memory has reached limit of @{limit} packages'
);
cb(new Error('Storage memory has reached limit of limit packages'));
}
}
search(onPackage, onEnd, validateName) {
// TODO: pending to implement
onEnd();
}
remove(name, cb) {
const list = this.data.list;
const item = list.indexOf(name);
if (item !== -1) {
list.splice(item, 1);
}
cb(null);
}
get(cb) {
cb(null, this.data.list);
}
sync() {
// nothing to do
}
getPackageStorage(packageInfo) {
// eslint-disable-next-line new-cap
return new _memoryHandler2.default(packageInfo, this.data.files, this.logger);
}
_createEmtpyDatabase() {
const list = [];
const files = {};
const emptyDatabase = {
list,
files,
secret: '',
};
return emptyDatabase;
}
}
exports.default = LocalMemory;