Skip to content

Commit

Permalink
fix: daruk types GlobalModule,Util,Glue,Service,etc interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojue committed May 13, 2019
1 parent 56482e0 commit 7868681
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ gulp.task('build', (cb) => exec('npm run build', cb));

gulp.task('watch:src', () => {
const watcher = gulp.watch('src/**/*.ts');
watcher.on('all', gulp.series('build', 'move:build', 'move:types'));
watcher.on('all', gulp.series('build', 'move:build'));
});

gulp.task('watch:types', () => {
const watcher = gulp.watch('types/**/*.d.ts');
watcher.on('all', gulp.series('build', 'move:build', 'move:types'));
watcher.on('all', gulp.series('build', 'move:types'));
});

gulp.task('watch', gulp.parallel('watch:src', 'watch:types'));
Expand Down
1 change: 1 addition & 0 deletions src/decorators/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CONTROLLER_PREFIX_PATH } from './constants';
* @param {string} prefixPath - 路由前缀
* @return Decorator - 装饰器
*/

export default function controller(prefixPath: string) {
assert(is.string(prefixPath), '[Decorator @controller] parameter must be a string');
return (target: BaseContext) => {
Expand Down
1 change: 1 addition & 0 deletions src/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './middleware';
export * from './framework';
export * from './request';
export * from './response';
export * from './controller';
11 changes: 8 additions & 3 deletions src/decorators/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ export function type(type: string) {
* @param {string=} value
*/
export function header(key: string | { [key: string]: string }, value?: string) {
assert(is.string(key) || is.object(key), `[Decorator @${key}] parameter must be a string or object`);
assert((is.string(key) && is.string(value)) || is.object(key),
`[Decorator @${value}] parameter must be a string`);
assert(
is.string(key) || is.object(key),
`[Decorator @${key}] parameter must be a string or object`
);
assert(
(is.string(key) && is.string(value)) || is.object(key),
`[Decorator @${value}] parameter must be a string`
);

let headers: { [key: string]: string } = {};
if (typeof key === 'string') {
Expand Down
29 changes: 22 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@ declare module 'daruk' {
interface Config {
[key: string]: any;
}
interface GlobalModule {}
interface Util {}
interface Glue {}
interface Service {}
interface Controller {}
interface Request extends Koa.Request {}
interface Response extends Koa.Response {}
interface GlobalModule {
[key: string]: any;
}
interface Util {
[key: string]: any;
}
interface Glue {
[key: string]: any;
}
interface Service {
[key: string]: any;
}
interface Controller {
[key: string]: any;
}
interface Request extends Koa.Request {
[key: string]: any;
}
interface Response extends Koa.Response {
[key: string]: any;
}

type ExtractInterface<T> = { [P in keyof T]: new (ctx: Context) => T[P] };

Expand Down Expand Up @@ -102,6 +116,7 @@ declare module 'daruk' {
export const type: (type: string) => MethodDecorator;

export const middleware: (middlewareName: string) => MethodDecorator;
export const controller: (prefixPath: string) => ClassDecorator;

type PropDecoratorFunc = (field?: string) => PropertyDecorator;

Expand Down

0 comments on commit 7868681

Please sign in to comment.