mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-11 02:15:57 -05:00
refactor(flow): add types to new files
This commit is contained in:
parent
1740aad834
commit
484e2a6afe
4 changed files with 93 additions and 17 deletions
66
flow-typed/npm/mime_vx.x.x.js
vendored
Normal file
66
flow-typed/npm/mime_vx.x.x.js
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
// flow-typed signature: 56b4e33a3df0ef57946fd42834d344b8
|
||||
// flow-typed version: <<STUB>>/mime_v2.2.0/flow_v0.67.1
|
||||
|
||||
/**
|
||||
* This is an autogenerated libdef stub for:
|
||||
*
|
||||
* 'mime'
|
||||
*
|
||||
* Fill this stub out by replacing all the `any` types.
|
||||
*
|
||||
* Once filled out, we encourage you to share your work with the
|
||||
* community by sending a pull request to:
|
||||
* https://github.com/flowtype/flow-typed
|
||||
*/
|
||||
|
||||
declare module 'mime' {
|
||||
declare module.exports: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* We include stubs for each file inside this npm package in case you need to
|
||||
* require those files directly. Feel free to delete any files that aren't
|
||||
* needed.
|
||||
*/
|
||||
declare module 'mime/cli' {
|
||||
declare module.exports: any;
|
||||
}
|
||||
|
||||
declare module 'mime/lite' {
|
||||
declare module.exports: any;
|
||||
}
|
||||
|
||||
declare module 'mime/Mime' {
|
||||
declare module.exports: any;
|
||||
}
|
||||
|
||||
declare module 'mime/src/build' {
|
||||
declare module.exports: any;
|
||||
}
|
||||
|
||||
declare module 'mime/src/test' {
|
||||
declare module.exports: any;
|
||||
}
|
||||
|
||||
// Filename aliases
|
||||
declare module 'mime/cli.js' {
|
||||
declare module.exports: $Exports<'mime/cli'>;
|
||||
}
|
||||
declare module 'mime/index' {
|
||||
declare module.exports: $Exports<'mime'>;
|
||||
}
|
||||
declare module 'mime/index.js' {
|
||||
declare module.exports: $Exports<'mime'>;
|
||||
}
|
||||
declare module 'mime/lite.js' {
|
||||
declare module.exports: $Exports<'mime/lite'>;
|
||||
}
|
||||
declare module 'mime/Mime.js' {
|
||||
declare module.exports: $Exports<'mime/Mime'>;
|
||||
}
|
||||
declare module 'mime/src/build.js' {
|
||||
declare module.exports: $Exports<'mime/src/build'>;
|
||||
}
|
||||
declare module 'mime/src/test.js' {
|
||||
declare module.exports: $Exports<'mime/src/test'>;
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
import _ from 'lodash';
|
||||
// @flow
|
||||
|
||||
export default (app, selfPath) => {
|
||||
import _ from 'lodash';
|
||||
import type {$Application} from 'express';
|
||||
import type {$ResponseExtend, $RequestExtend, $NextFunctionVer} from '../../../types';
|
||||
|
||||
export default (app: $Application, selfPath: string) => {
|
||||
// Hook for tests only
|
||||
app.get('/-/_debug', function(req, res, next) {
|
||||
app.get('/-/_debug', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
const doGarbabeCollector = _.isNil(global.gc) === false;
|
||||
|
||||
if (doGarbabeCollector) {
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
// @flow
|
||||
|
||||
import mime from 'mime';
|
||||
import _ from 'lodash';
|
||||
import {media, allow} from '../../middleware';
|
||||
import {DIST_TAGS} from '../../../lib/utils';
|
||||
import type {Router} from 'express';
|
||||
import type {IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler} from '../../../../types';
|
||||
|
||||
|
||||
export default function(route, auth, storage) {
|
||||
export default function(route: Router, auth: IAuth, storage: IStorageHandler) {
|
||||
const can = allow(auth);
|
||||
const tag_package_version = function(req, res, next) {
|
||||
const tag_package_version = function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
if (_.isString(req.body) === false) {
|
||||
return next('route');
|
||||
}
|
||||
|
@ -32,7 +36,7 @@ export default function(route, auth, storage) {
|
|||
route.put('/-/package/:package/dist-tags/:tag',
|
||||
can('publish'), media(mime.getType('json')), tag_package_version);
|
||||
|
||||
route.delete('/-/package/:package/dist-tags/:tag', can('publish'), function(req, res, next) {
|
||||
route.delete('/-/package/:package/dist-tags/:tag', can('publish'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
const tags = {};
|
||||
tags[req.params.tag] = null;
|
||||
storage.mergeTags(req.params.package, tags, function(err) {
|
||||
|
@ -46,7 +50,7 @@ export default function(route, auth, storage) {
|
|||
});
|
||||
});
|
||||
|
||||
route.get('/-/package/:package/dist-tags', can('access'), function(req, res, next) {
|
||||
route.get('/-/package/:package/dist-tags', can('access'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
storage.getPackage({
|
||||
name: req.params.package,
|
||||
req,
|
||||
|
@ -60,7 +64,7 @@ export default function(route, auth, storage) {
|
|||
});
|
||||
});
|
||||
|
||||
route.post('/-/package/:package/dist-tags', can('publish'), function(req, res, next) {
|
||||
route.post('/-/package/:package/dist-tags', can('publish'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
storage.mergeTags(req.params.package, req.body, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
const _ = require('lodash');
|
||||
const createError = require('http-errors');
|
||||
// @flow
|
||||
|
||||
const {allow} = require('../../middleware');
|
||||
const {DIST_TAGS, filter_tarball_urls, get_version} = require('../../../lib/utils');
|
||||
import _ from 'lodash';
|
||||
import {allow} from '../../middleware';
|
||||
import {DIST_TAGS, filter_tarball_urls, get_version, ErrorCode} from '../../../lib/utils';
|
||||
import type {Router} from 'express';
|
||||
import type {Config} from '@verdaccio/types';
|
||||
import type {IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler} from '../../../../types';
|
||||
|
||||
export default function(route, auth, storage, config) {
|
||||
export default function(route: Router, auth: IAuth, storage: IStorageHandler, config: Config) {
|
||||
const can = allow(auth);
|
||||
// TODO: anonymous user?
|
||||
route.get('/:package/:version?', can('access'), function(req, res, next) {
|
||||
route.get('/:package/:version?', can('access'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
const getPackageMetaCallback = function(err, info) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
@ -33,8 +36,7 @@ export default function(route, auth, storage, config) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next( createError[404]('version not found: ' + req.params.version) );
|
||||
return next(ErrorCode.get404('version not found: ' + req.params.version));
|
||||
};
|
||||
|
||||
storage.getPackage({
|
||||
|
@ -44,7 +46,7 @@ export default function(route, auth, storage, config) {
|
|||
});
|
||||
});
|
||||
|
||||
route.get('/:package/-/:filename', can('access'), function(req, res) {
|
||||
route.get('/:package/-/:filename', can('access'), function(req: $RequestExtend, res: $ResponseExtend) {
|
||||
const stream = storage.get_tarball(req.params.package, req.params.filename);
|
||||
|
||||
stream.on('content-length', function(content) {
|
||||
|
|
Loading…
Add table
Reference in a new issue