0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/flow/plugins/storage/example.storage.plugin.js
Juan Picado @jotadeveloper 66f4197236
feat: convert project to typescript (#1374)
* chore: test

* chore: add

* chore: more progress

* chore: progress in migration, fix prettier parser

* chore: reduce tsc errors

* chore: refactor storage utils types

* chore: refactor utils types

* chore: refactor local storage types

* chore: refactor config utils types

* chore: refactor tsc types

* refactor: apply eslint fix, tabs etc

* chore: fix lint errors

* test: update unit test conf to typescript setup

few test refactored to typescript

* chore: enable more unit test

migrate to typescript

* chore: migrate storage test to tsc

* chore: migrate up storage test to tsc

* refactor: enable plugin and auth test

* chore: migrate plugin loader test

* chore: update dependencies

* chore: migrate functional test to typescript

* chore: add codecove

* chore: update express

* chore: downgrade puppeteer

The latest version does not seems to work properly fine.

* chore: update dependencies
2019-07-16 08:40:01 +02:00

139 lines
3.2 KiB
JavaScript

// @flow
// this file is not aim to be tested, just to check flow definitions
import Config from '../../../../src/lib/config';
import LoggerApi from '../../../../src/lib/logger';
import {generatePackageTemplate} from '../../../../src/lib/storage-utils';
import { UploadTarball, ReadTarball } from '@verdaccio/streams';
import {
Callback,
Config as AppConfig,
Logger,
Package,
// PluginOptions
} from '@verdaccio/types';
import {
IPluginStorage,
IPackageStorageManager,
IPackageStorage
} from '@verdaccio/local-storage';
import { IUploadTarball, IReadTarball } from '@verdaccio/streams';
class PackageStorage implements IPackageStorageManager {
path: string;
logger: Logger;
constructor(path: string, logger: Logger) {
this.path = path;
this.logger = logger;
}
updatePackage(name: string, updateHandler: Callback,
onWrite: Callback,
transformPackage: Function,
onEnd: Callback) {
onEnd();
}
deletePackage(fileName: string, callback: Callback) {
callback();
}
removePackage(callback: Callback): void {
callback();
}
createPackage(name: string, value: Package, cb: Callback) {
cb();
}
savePackage(name: string, value: Package, cb: Callback) {
cb();
}
readPackage(name: string, cb: Callback) {
cb();
}
writeTarball(name: string): IUploadTarball {
const uploadStream = new UploadTarball();
return uploadStream;
}
readTarball(name: string): IReadTarball {
const readTarballStream: IReadTarball = new ReadTarball();
return readTarballStream;
}
}
class ExampleStoragePlugin implements IPluginStorage {
logger: Logger;
config: AppConfig;
constructor(config: AppConfig, logger: Logger) {
this.config = config;
this.logger = logger;
}
getSecret(): Promise<any> {
return Promise.resolve();
}
setSecret(secret: string): Promise<any> {
return Promise.resolve();
}
add(name: string, cb: Callback) {
cb();
}
remove(name: string, cb: Callback) {
cb();
}
get(cb: Callback) {
cb();
}
getPackageStorage(packageInfo: string): IPackageStorage {
return new PackageStorage(packageInfo, this.logger);
}
search(onPackage: Callback, onEnd: Callback, validateName: any): void {
onPackage(onEnd());
}
}
export default ExampleStoragePlugin;
const config1: AppConfig = new Config({
storage: './storage',
self_path: '/home/sotrage'
});
const storage = new ExampleStoragePlugin(config1, LoggerApi.logger.child());
storage.add('test', () => {});
storage.remove('test', () => {});
storage.getSecret().then(() => {});
storage.setSecret('newSecret').then(() => {});
storage.search(() => {}, () => {}, 'validateName');
storage.get(() => {});
const storageManager: IPackageStorage = storage.getPackageStorage('test');
if (storageManager) {
storageManager.createPackage('test', generatePackageTemplate('test'), () => {});
storageManager.savePackage('fileName', generatePackageTemplate('test'), () => {});
storageManager.updatePackage('pkgFileName', () =>{}, () => {}, () => {}, () => {});
storageManager.deletePackage('test', () => {});
storageManager.removePackage(() => {});
storageManager.readPackage('test', () => {});
storageManager.writeTarball('test');
}