@verdaccio/local-storage
Advanced tools
Comparing version 10.3.3 to 10.3.4
@@ -1,4 +0,7 @@ | ||
import { Callback, Config, IPackageStorage, IPluginStorage, LocalStorage, Logger } from '@verdaccio/legacy-types'; | ||
import { Callback, Config, Logger } from '@verdaccio/types'; | ||
import { searchUtils } from '@verdaccio/core'; | ||
import { LocalStorage } from './utils'; | ||
import LocalDriver from './local-fs'; | ||
import TokenActions from './token'; | ||
declare class LocalDatabase extends TokenActions implements IPluginStorage<{}> { | ||
declare class LocalDatabase extends TokenActions { | ||
path: string; | ||
@@ -13,3 +16,9 @@ logger: Logger; | ||
add(name: string, cb: Callback): void; | ||
search(onPackage: Callback, onEnd: Callback, validateName: (name: string) => boolean): void; | ||
/** | ||
* Filter and only match those values that the query define. | ||
**/ | ||
filterByQuery(results: searchUtils.SearchItemPkg[], query: searchUtils.SearchQuery): Promise<searchUtils.SearchItemPkg[]>; | ||
getScore(_pkg: searchUtils.SearchItemPkg): Promise<searchUtils.Score>; | ||
private _getCustomPackageLocalStorages; | ||
search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>; | ||
remove(name: string, cb: Callback): void; | ||
@@ -21,6 +30,5 @@ /** | ||
get(cb: Callback): void; | ||
getPackageStorage(packageName: string): IPackageStorage; | ||
getPackageStorage(packageName: string): LocalDriver | undefined; | ||
clean(): void; | ||
private getTime; | ||
private _getCustomPackageLocalStorages; | ||
/** | ||
@@ -31,3 +39,10 @@ * Syncronize {create} database whether does not exist. | ||
private _sync; | ||
private getBaseConfigPath; | ||
/** | ||
* The field storage could be absolute or relative. | ||
* If relative, it will be resolved against the config path. | ||
* If absolute, it will be returned as is. | ||
**/ | ||
private getStoragePath; | ||
/** | ||
* Verify the right local storage location. | ||
@@ -40,9 +55,2 @@ * @param {String} path | ||
/** | ||
* Build the local database path. | ||
* @param {Object} config | ||
* @return {string|String|*} | ||
* @private | ||
*/ | ||
private _buildStoragePath; | ||
/** | ||
* Fetch local packages. | ||
@@ -49,0 +57,0 @@ * @private |
@@ -11,5 +11,5 @@ "use strict"; | ||
var _lodash = _interopRequireDefault(require("lodash")); | ||
var _async = _interopRequireDefault(require("async")); | ||
var _mkdirp = _interopRequireDefault(require("mkdirp")); | ||
var _commonsApi = require("@verdaccio/commons-api"); | ||
var _dirUtils = require("./dir-utils"); | ||
var _core = require("@verdaccio/core"); | ||
var _localFs = _interopRequireWildcard(require("./local-fs")); | ||
@@ -21,5 +21,3 @@ var _pkgUtils = require("./pkg-utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const DEPRECATED_DB_NAME = '.sinopia-db.json'; | ||
const DB_NAME = '.verdaccio-db.json'; | ||
const debug = (0, _debug.default)('verdaccio:plugin:local-storage'); | ||
const debug = (0, _debug.default)('verdaccio:plugin:local-storage:database'); | ||
class LocalDatabase extends _token.default { | ||
@@ -29,3 +27,3 @@ constructor(config, logger) { | ||
this.config = config; | ||
this.path = this._buildStoragePath(config); | ||
this.path = this._dbGenPath(_core.fileUtils.Files.DatabaseName, config); | ||
this.logger = logger; | ||
@@ -55,80 +53,72 @@ this.locked = false; | ||
} | ||
search(onPackage, onEnd, validateName) { | ||
const storages = this._getCustomPackageLocalStorages(); | ||
debug(`search custom local packages: %o`, JSON.stringify(storages)); | ||
const base = _path.default.dirname(this.config.self_path); | ||
const self = this; | ||
const storageKeys = Object.keys(storages); | ||
debug(`search base: %o keys: %o`, base, storageKeys); | ||
_async.default.eachSeries(storageKeys, function (storage, cb) { | ||
const position = storageKeys.indexOf(storage); | ||
const base2 = _path.default.join(position !== 0 ? storageKeys[0] : ''); | ||
const storagePath = _path.default.resolve(base, base2, storage); | ||
debug('search path: %o : %o', storagePath, storage); | ||
_fs.default.readdir(storagePath, (err, files) => { | ||
if (err) { | ||
return cb(err); | ||
/** | ||
* Filter and only match those values that the query define. | ||
**/ | ||
async filterByQuery(results, query) { | ||
// FUTURE: apply new filters, keyword, version, ... | ||
return results.filter(item => { | ||
var _item$name; | ||
return (item === null || item === void 0 ? void 0 : (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.match(query.text)) !== null; | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async getScore(_pkg) { | ||
// TODO: there is no particular reason to predefined scores | ||
// could be improved by using | ||
return Promise.resolve({ | ||
final: 1, | ||
detail: { | ||
maintenance: 0, | ||
popularity: 1, | ||
quality: 1 | ||
} | ||
}); | ||
} | ||
_getCustomPackageLocalStorages() { | ||
const storages = new Map(); | ||
const { | ||
packages | ||
} = this.config; | ||
if (packages) { | ||
Object.keys(packages || {}).map(pkg => { | ||
const { | ||
storage | ||
} = packages[pkg]; | ||
if (typeof storage === 'string') { | ||
const storagePath = _path.default.join(this.getStoragePath(), storage); | ||
debug('add custom storage for %s on %s', storage, storagePath); | ||
storages.set(storage, storagePath); | ||
} | ||
_async.default.eachSeries(files, function (file, cb) { | ||
debug('local-storage: [search] search file path: %o', file); | ||
if (storageKeys.includes(file)) { | ||
return cb(); | ||
} | ||
if (file.match(/^@/)) { | ||
// scoped | ||
const fileLocation = _path.default.resolve(base, storage, file); | ||
debug('search scoped file location: %o', fileLocation); | ||
_fs.default.readdir(fileLocation, function (err, files) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
_async.default.eachSeries(files, (file2, cb) => { | ||
if (validateName(file2)) { | ||
const packagePath = _path.default.resolve(base, storage, file, file2); | ||
_fs.default.stat(packagePath, (err, stats) => { | ||
if (_lodash.default.isNil(err) === false) { | ||
return cb(err); | ||
} | ||
const item = { | ||
name: `${file}/${file2}`, | ||
path: packagePath, | ||
time: stats.mtime.getTime() | ||
}; | ||
onPackage(item, cb); | ||
}); | ||
} else { | ||
cb(); | ||
} | ||
}, cb); | ||
}); | ||
} else if (validateName(file)) { | ||
const base2 = _path.default.join(position !== 0 ? storageKeys[0] : ''); | ||
const packagePath = _path.default.resolve(base, base2, storage, file); | ||
debug('search file location: %o', packagePath); | ||
_fs.default.stat(packagePath, (err, stats) => { | ||
if (_lodash.default.isNil(err) === false) { | ||
return cb(err); | ||
} | ||
onPackage({ | ||
name: file, | ||
path: packagePath, | ||
time: self.getTime(stats.mtime.getTime(), stats.mtime) | ||
}, cb); | ||
}); | ||
} else { | ||
cb(); | ||
} | ||
}, cb); | ||
}); | ||
}, | ||
// @ts-ignore | ||
onEnd); | ||
} | ||
return storages; | ||
} | ||
async search(query) { | ||
const results = []; | ||
const storagePath = this.getStoragePath(); | ||
const storages = this._getCustomPackageLocalStorages(); | ||
const packagesOnStorage = await this.filterByQuery(await (0, _dirUtils.searchOnStorage)(storagePath, storages), query); | ||
debug('packages found %o', packagesOnStorage.length); | ||
for (let storage of packagesOnStorage) { | ||
// check if package is listed on the cache private database | ||
const isPrivate = this.data.list.includes(storage.name); | ||
const score = await this.getScore(storage); | ||
results.push({ | ||
package: storage, | ||
verdaccioPrivate: isPrivate, | ||
verdaccioPkgCached: !isPrivate, | ||
score | ||
}); | ||
} | ||
return results; | ||
} | ||
remove(name, cb) { | ||
this.get((err, data) => { | ||
if (err) { | ||
cb((0, _commonsApi.getInternalError)('error remove private package')); | ||
cb(_core.errorUtils.getInternalError('error remove private package')); | ||
this.logger.error({ | ||
err | ||
}, '[local-storage/remove]: remove the private package has failed @{err}'); | ||
}, 'remove the private package has failed @{err}'); | ||
debug('error on remove package %o', name); | ||
@@ -173,24 +163,3 @@ } | ||
} | ||
_getCustomPackageLocalStorages() { | ||
const storages = {}; | ||
// add custom storage if exist | ||
if (this.config.storage) { | ||
storages[this.config.storage] = true; | ||
} | ||
const { | ||
packages | ||
} = this.config; | ||
if (packages) { | ||
const listPackagesConf = Object.keys(packages || {}); | ||
listPackagesConf.map(pkg => { | ||
const storage = packages[pkg].storage; | ||
if (storage) { | ||
storages[storage] = false; | ||
} | ||
}); | ||
} | ||
return storages; | ||
} | ||
/** | ||
@@ -225,4 +194,24 @@ * Syncronize {create} database whether does not exist. | ||
} | ||
getBaseConfigPath() { | ||
return _path.default.dirname(this.config.configPath); | ||
} | ||
/** | ||
* The field storage could be absolute or relative. | ||
* If relative, it will be resolved against the config path. | ||
* If absolute, it will be returned as is. | ||
**/ | ||
getStoragePath() { | ||
const { | ||
storage | ||
} = this.config; | ||
if (typeof storage !== 'string') { | ||
throw new TypeError('storage field is mandatory'); | ||
} | ||
const storagePath = _path.default.isAbsolute(storage) ? storage : _path.default.normalize(_path.default.join(this.getBaseConfigPath(), storage)); | ||
debug('storage path %o', storagePath); | ||
return storagePath; | ||
} | ||
/** | ||
* Verify the right local storage location. | ||
@@ -246,26 +235,2 @@ * @param {String} path | ||
/** | ||
* Build the local database path. | ||
* @param {Object} config | ||
* @return {string|String|*} | ||
* @private | ||
*/ | ||
_buildStoragePath(config) { | ||
const sinopiadbPath = this._dbGenPath(DEPRECATED_DB_NAME, config); | ||
try { | ||
_fs.default.accessSync(sinopiadbPath, _fs.default.constants.F_OK); | ||
// @ts-ignore | ||
process.emitWarning('Database name deprecated!', { | ||
code: 'VERCODE01', | ||
detail: `Please rename database name from ${DEPRECATED_DB_NAME} to ${DB_NAME}` | ||
}); | ||
return sinopiadbPath; | ||
} catch (err) { | ||
if (err.code === _localFs.noSuchFile) { | ||
return this._dbGenPath(DB_NAME, config); | ||
} | ||
throw err; | ||
} | ||
} | ||
/** | ||
* Fetch local packages. | ||
@@ -272,0 +237,0 @@ * @private |
/// <reference types="node" /> | ||
import { ReadTarball } from '@verdaccio/streams'; | ||
import { Callback, Logger, Package, ILocalPackageManager, IUploadTarball } from '@verdaccio/legacy-types'; | ||
import { VerdaccioError } from '@verdaccio/commons-api'; | ||
import { UploadTarball, ReadTarball } from '@verdaccio/streams'; | ||
import { Callback, Logger, Package } from '@verdaccio/types'; | ||
import { VerdaccioError } from '@verdaccio/core'; | ||
export declare const fileExist = "EEXISTS"; | ||
@@ -10,7 +10,4 @@ export declare const noSuchFile = "ENOENT"; | ||
export declare const fSError: (message: string, code?: number) => VerdaccioError; | ||
export declare type ILocalFSPackageManager = ILocalPackageManager & { | ||
export default class LocalFS { | ||
path: string; | ||
}; | ||
export default class LocalFS implements ILocalFSPackageManager { | ||
path: string; | ||
logger: Logger; | ||
@@ -39,3 +36,3 @@ constructor(path: string, logger: Logger); | ||
readPackage(name: string, cb: Callback): void; | ||
writeTarball(name: string): IUploadTarball; | ||
writeTarball(name: string): UploadTarball; | ||
readTarball(name: string): ReadTarball; | ||
@@ -42,0 +39,0 @@ private _createFile; |
@@ -14,3 +14,3 @@ "use strict"; | ||
var _fileLocking = require("@verdaccio/file-locking"); | ||
var _commonsApi = require("@verdaccio/commons-api"); | ||
var _core = require("@verdaccio/core"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -29,3 +29,3 @@ /* eslint-disable no-undef */ | ||
const fSError = function (message, code = 409) { | ||
const err = (0, _commonsApi.getCode)(code, message); | ||
const err = _core.errorUtils.getCode(code, message); | ||
// FIXME: we should return http-status codes here instead, future improvement | ||
@@ -109,5 +109,5 @@ // @ts-ignore | ||
if (err.code === resourceNotAvailable) { | ||
return unLockCallback((0, _commonsApi.getInternalError)('resource temporarily unavailable')); | ||
return unLockCallback(_core.errorUtils.getInternalError('resource temporarily unavailable')); | ||
} else if (err.code === noSuchFile) { | ||
return unLockCallback((0, _commonsApi.getNotFound)()); | ||
return unLockCallback(_core.errorUtils.getNotFound()); | ||
} else { | ||
@@ -114,0 +114,0 @@ return unLockCallback(err); |
@@ -1,2 +0,3 @@ | ||
import { LocalStorage, Logger } from '@verdaccio/legacy-types'; | ||
import { Logger } from '@verdaccio/types'; | ||
import { LocalStorage } from './utils'; | ||
export declare function loadPrivatePackages(path: string, logger: Logger): LocalStorage; |
import low from 'lowdb'; | ||
import { ITokenActions, Config, Token, TokenFilter } from '@verdaccio/legacy-types'; | ||
import { ITokenActions, Config, Token, TokenFilter } from '@verdaccio/types'; | ||
export default class TokenActions implements ITokenActions { | ||
@@ -4,0 +4,0 @@ config: Config; |
@@ -22,3 +22,7 @@ "use strict"; | ||
_dbGenPath(dbName, config) { | ||
return _path.default.join(_path.default.resolve(_path.default.dirname(config.self_path || ''), config.storage, dbName)); | ||
var _config$configPath; | ||
// TODO: self_path is a legacy property and is deprecated | ||
// TODO: display deprecation warning for self_path | ||
const selfPath = (_config$configPath = config.configPath) !== null && _config$configPath !== void 0 ? _config$configPath : config.self_path; | ||
return _path.default.join(_path.default.resolve(_path.default.dirname(selfPath || ''), config.storage, dbName)); | ||
} | ||
@@ -25,0 +29,0 @@ async getTokenDb() { |
/// <reference types="node" /> | ||
import fs from 'fs'; | ||
export declare type LocalStorage = { | ||
list: any; | ||
secret: string; | ||
}; | ||
export declare function getFileStats(packagePath: string): Promise<fs.Stats>; | ||
@@ -4,0 +8,0 @@ export declare function readDirectory(packagePath: string): Promise<string[]>; |
{ | ||
"name": "@verdaccio/local-storage", | ||
"version": "10.3.3", | ||
"version": "10.3.4", | ||
"description": "Local storage implementation", | ||
@@ -34,7 +34,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@verdaccio/commons-api": "10.2.0", | ||
"@verdaccio/core": "7.0.0-next.1", | ||
"@verdaccio/file-locking": "10.3.1", | ||
"@verdaccio/streams": "10.2.1", | ||
"async": "3.2.4", | ||
"debug": "4.3.4", | ||
"globby": "11.1.0", | ||
"lodash": "4.17.21", | ||
@@ -45,5 +45,7 @@ "lowdb": "1.0.0", | ||
"devDependencies": { | ||
"@types/express": "^4.17.17", | ||
"@types/minimatch": "^3.0.3", | ||
"@types/node": "^14.0.0", | ||
"@verdaccio/legacy-types": "1.0.1", | ||
"@types/node": "^20.5.8", | ||
"@verdaccio/config": "7.0.0-next.1", | ||
"@verdaccio/types": "12.0.0-next.0", | ||
"minimatch": "^4.0.0", | ||
@@ -50,0 +52,0 @@ "rmdir-sync": "^1.0.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104844
24
1049
7
61802
4
+ Added@verdaccio/core@7.0.0-next.1
+ Addedglobby@11.1.0
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@verdaccio/core@7.0.0-next.1(transitive)
+ Addedajv@8.12.0(transitive)
+ Addedarray-union@2.1.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedcore-js@3.30.2(transitive)
+ Addeddir-glob@3.0.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobby@11.1.0(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedpath-type@4.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedprocess-warning@1.0.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsemver@7.5.4(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedyallist@4.0.0(transitive)
- Removed@verdaccio/commons-api@10.2.0
- Removedasync@3.2.4
- Removed@verdaccio/commons-api@10.2.0(transitive)
- Removedasync@3.2.4(transitive)