From 0167de508cd0ac03fad86cd79233e16d39958522 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Mon, 26 Feb 2018 21:28:09 +0100 Subject: [PATCH] refactor: move specific flow types into the project --- package.json | 2 +- src/lib/local-storage.js | 3 +- src/lib/search.js | 4 +- src/lib/storage.js | 7 +-- src/lib/up-storage.js | 4 +- test/unit/auth.spec.js | 4 +- test/unit/local-storage.spec.js | 3 +- test/unit/store.spec.js | 3 +- test/unit/up-storage.spec.js | 3 +- types/index.js | 104 ++++++++++++++++++++++++++++++++ yarn.lock | Bin 327338 -> 327338 bytes 11 files changed, 118 insertions(+), 19 deletions(-) create mode 100644 types/index.js diff --git a/package.json b/package.json index ce8ae019e..0575cd486 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@commitlint/cli": "6.1.0", "@commitlint/config-conventional": "6.1.0", "@commitlint/travis-cli": "6.1.0", - "@verdaccio/types": "1.0.4", + "@verdaccio/types": "2.0.0", "axios": "0.17.1", "babel-cli": "6.26.0", "babel-core": "6.26.0", diff --git a/src/lib/local-storage.js b/src/lib/local-storage.js index e4333a60e..9853c8edf 100644 --- a/src/lib/local-storage.js +++ b/src/lib/local-storage.js @@ -19,7 +19,6 @@ import {loadPlugin} from '../lib/plugin-loader'; import LocalDatabase from '@verdaccio/local-storage'; import {UploadTarball, ReadTarball} from '@verdaccio/streams'; import type { - IStorage, Package, Config, MergeTags, @@ -32,11 +31,11 @@ import type { ILocalData, IPackageStorage, } from '@verdaccio/local-storage'; - import type { IUploadTarball, IReadTarball, } from '@verdaccio/streams'; +import type {IStorage} from '../../types'; /** * Implements Storage interface (same for storage.js, local-storage.js, up-storage.js). diff --git a/src/lib/search.js b/src/lib/search.js index 5e45a331e..eceef7267 100644 --- a/src/lib/search.js +++ b/src/lib/search.js @@ -1,8 +1,8 @@ // @flow import lunr from 'lunr'; -import type {IStorageHandler, Version, IWebSearch} from '@verdaccio/types'; - +import type {Version} from '@verdaccio/types'; +import type {IStorageHandler, IWebSearch} from '../../types'; /** * Handle the search Indexer. */ diff --git a/src/lib/storage.js b/src/lib/storage.js index 1db295e4b..53cd47449 100644 --- a/src/lib/storage.js +++ b/src/lib/storage.js @@ -12,13 +12,9 @@ import LocalStorage from './local-storage'; import {ReadTarball} from '@verdaccio/streams'; import ProxyStorage from './up-storage'; import * as Utils from './utils'; - +import type {IStorage, IProxy, IStorageHandler, ProxyList} from '../../types'; import type { - IStorage, - IProxy, - IStorageHandler, Versions, - ProxyList, Package, Config, MergeTags, @@ -27,7 +23,6 @@ import type { Callback, Logger, } from '@verdaccio/types'; - import type {IReadTarball, IUploadTarball} from '@verdaccio/streams'; const LoggerApi = require('../lib/logger'); diff --git a/src/lib/up-storage.js b/src/lib/up-storage.js index 3f9f612f5..6988e13f5 100644 --- a/src/lib/up-storage.js +++ b/src/lib/up-storage.js @@ -11,15 +11,13 @@ import {parseInterval, isObject, ErrorCode} from './utils'; import {ReadTarball} from '@verdaccio/streams'; import type { - IProxy, Config, UpLinkConf, Callback, Headers, Logger, } from '@verdaccio/types'; - -// import type {IUploadTarball, IReadTarball} from '@verdaccio/streams'; +import type {IProxy} from '../../types'; const LoggerApi = require('./logger'); const encode = function(thing) { diff --git a/test/unit/auth.spec.js b/test/unit/auth.spec.js index 4bcef213b..950cbac0f 100644 --- a/test/unit/auth.spec.js +++ b/test/unit/auth.spec.js @@ -7,8 +7,8 @@ import configExample from './partials/config'; import AppConfig from '../../src/lib/config'; import {setup} from '../../src/lib/logger'; - -import type {IAuth, Config} from '@verdaccio/types'; +import type {IAuth} from '../../types'; +import type {Config} from '@verdaccio/types'; setup(configExample.logs); diff --git a/test/unit/local-storage.spec.js b/test/unit/local-storage.spec.js index 7eec2a183..8aea6d0ac 100644 --- a/test/unit/local-storage.spec.js +++ b/test/unit/local-storage.spec.js @@ -10,7 +10,8 @@ import {readFile} from '../functional/lib/test.utils'; const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`); -import type {IStorage, Config} from '@verdaccio/types'; +import type {Config} from '@verdaccio/types'; +import type {IStorage} from '../../types'; setup([]); diff --git a/test/unit/store.spec.js b/test/unit/store.spec.js index 3878ff8f3..a82eefe53 100644 --- a/test/unit/store.spec.js +++ b/test/unit/store.spec.js @@ -8,7 +8,8 @@ import AppConfig from '../../src/lib/config'; import Storage from '../../src/lib/storage'; import {setup} from '../../src/lib/logger'; -import type {IStorageHandler, Config} from '@verdaccio/types'; +import type {Config} from '@verdaccio/types'; +import type {IStorageHandler} from '../../types'; setup(configExample.logs); diff --git a/test/unit/up-storage.spec.js b/test/unit/up-storage.spec.js index b293741fc..ed946fbab 100644 --- a/test/unit/up-storage.spec.js +++ b/test/unit/up-storage.spec.js @@ -5,7 +5,8 @@ import _ from 'lodash'; // $FlowFixMe import configExample from './partials/config'; import {setup} from '../../src/lib/logger'; -import type {Config, IProxy, UpLinkConf} from '@verdaccio/types'; +import type {Config, UpLinkConf} from '@verdaccio/types'; +import type {IProxy} from '../../types'; setup([]); diff --git a/types/index.js b/types/index.js new file mode 100644 index 000000000..d7d7ec714 --- /dev/null +++ b/types/index.js @@ -0,0 +1,104 @@ +// @flow + +import type { + UpLinkConf, + Callback, + Versions, + Version, + MergeTags, + Config, + Logger, + Package} from '@verdaccio/types'; +import type { + IUploadTarball, + IReadTarball, +} from '@verdaccio/streams'; +import type {ILocalData} from '@verdaccio/local-storage'; + +export interface IAuth { + config: Config; + logger: Logger; + secret: string; + plugins: Array; +} + +export interface IWebSearch { + index: any; + storage: IStorageHandler; + query(query: string): any; + add(pkg: Version): void; + remove(name: string): void; + reindex(): void; + configureStorage(storage: IStorageHandler): void; +} + +export interface IProxy { + config: UpLinkConf; + failed_requests: number; + userAgent: string; + ca?: string | void; + logger: Logger; + server_id: string; + url: any; + maxage: number; + timeout: number; + max_fails: number; + fail_timeout: number; + upname: string; + fetchTarball(url: string): IReadTarball; + isUplinkValid(url: string): boolean; +} + +export type ProxyList = { + [key: string]: IProxy | null; +} + +export type Utils = { + ErrorCode: any; + getLatestVersion: Callback; + isObject: (value: any) => boolean; + validate_name: (value: any) => boolean; + tag_version: (value: any, version: string, tag: string) => void; + normalize_dist_tags: (pkg: Package) => void; + semverSort: (keys: Array) => Array; +} + +export interface IStorageHandler { + config: Config; + localStorage: IStorage; + logger: Logger; + uplinks: ProxyList; + addPackage(name: string, metadata: any, callback: Function): void; + addVersion(name: string, version: string, metadata: Version, tag: string, callback: Callback): void; + mergeTags(name: string, tagHash: MergeTags, callback: Callback): void; + replace_tags(name: string, tagHash: MergeTags, callback: Callback): void; + change_package(name: string, metadata: Package, revision: string, callback: Callback): void; + remove_package(name: string, callback: Callback): void; + remove_tarball(name: string, filename: string, revision: string, callback: Callback): void; + add_tarball(name: string, filename: string): IUploadTarball; + get_tarball(name: string, filename: string): IReadTarball; + getPackage(options: any): void; + search(startkey: string, options: any): void; + getLocalDatabase(callback: Callback): void; + _syncUplinksMetadata(name: string, packageInfo: Package, options: any, callback: Callback): void; + _updateVersionsHiddenUpLink(versions: Versions, upLink: IProxy): void; + _setupUpLinks(config: Config): void; +} + +export interface IStorage { + config: Config; + localData: ILocalData; + logger: Logger; + addPackage(name: string, info: Package, callback: Callback): void; + removePackage(name: string, callback: Callback): void; + updateVersions(name: string, packageInfo: Package, callback: Callback): void; + addVersion(name: string, version: string, metadata: Version, tag: string, callback: Callback): void; + mergeTags(name: string, tags: MergeTags, callback: Callback): void; + changePackage(name: string, metadata: Package, revision: string, callback: Callback): void; + removeTarball(name: string, filename: string, revision: string, callback: Callback): void; + addTarball(name: string, filename: string): IUploadTarball; + getTarball(name: string, filename: string): IReadTarball; + getPackageMetadata(name: string, callback: Callback): void; + search(startKey: string, options: any): IUploadTarball; +} + diff --git a/yarn.lock b/yarn.lock index 2093bc892f825c0df0a5b5b721174ce457fa1dd6..bc2b8c6e9e6e71a416c1df45e40028bf8127e300 100644 GIT binary patch delta 111 zcmZ4WS9sN5;SCmYY({zpdIn0<8Q(ElPu7*?b||SVNG;aa)d$nMU|GGA^eW}FWOEA> zqm-0X6GPLaBx6g1B%>5F(^T^$3v-jS)Kn9TB;!tIG4u8#axBm8 F0|3P7Bxe8s