Skip to content

Commit

Permalink
update build
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Millent committed Jul 1, 2024
1 parent d90e9c6 commit b0163fe
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/controller/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Router from 'koa-router';
import 'reflect-metadata';
import { KoaMiddleware } from '../../src/types';
export declare class FireCatController {
decoratorBindRouter(router: Router, subPath: string, context: any): void;
decoratorBindRouter(router: Router, subPath: string, context: any, middlewares?: KoaMiddleware[]): void;
}
5 changes: 3 additions & 2 deletions lib/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var common_1 = require("../utils/common");
var FireCatController = (function () {
function FireCatController() {
}
FireCatController.prototype.decoratorBindRouter = function (router, subPath, context) {
FireCatController.prototype.decoratorBindRouter = function (router, subPath, context, middlewares) {
if (middlewares === void 0) { middlewares = []; }
var store = (0, decorator_1.getDecoratorRepositoryController)(this);
if (store) {
try {
Expand All @@ -18,7 +19,7 @@ var FireCatController = (function () {
list.forEach(function (item) {
var ins = store.getMiddlewares(item.propertyKey);
var concatPath = subPath + item.path;
router[item.method].apply(router, tslib_1.__spreadArray(tslib_1.__spreadArray([(0, common_1.fixedEndPath)(concatPath)], ins.map(function (i) { return i.controller.bind(context); }), false), [item.controller.bind(context)], false));
router[item.method].apply(router, tslib_1.__spreadArray(tslib_1.__spreadArray([(0, common_1.fixedEndPath)(concatPath)], tslib_1.__spreadArray(tslib_1.__spreadArray([], middlewares, true), ins.map(function (i) { return i.controller.bind(context); }), true), false), [item.controller.bind(context)], false));
docDesList_1.forEach(function (docItem) {
if (docItem.propertyKey == item.propertyKey) {
item.description = docItem.description;
Expand Down
4 changes: 2 additions & 2 deletions lib/decorator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var DecoratorRepository = (function () {
this.interceptors = [];
}
DecoratorRepository.prototype.addInterceptor = function (interceptor) {
this.interceptors.push(interceptor);
this.interceptors.unshift(interceptor);
};
DecoratorRepository.prototype.addRoute = function (decorator, path, method, propertyKey) {
var betterPath = path;
Expand All @@ -31,7 +31,7 @@ var DecoratorRepository = (function () {
if (!this.middlewares[propertyKey]) {
this.middlewares[propertyKey] = [];
}
this.middlewares[propertyKey].push(middleware);
this.middlewares[propertyKey].unshift(middleware);
};
DecoratorRepository.prototype.addDocDeses = function (doc) {
this.docDeses.push(doc);
Expand Down
2 changes: 1 addition & 1 deletion lib/decorators/request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Request() {
switch (_a.label) {
case 0:
if (ctx.method == 'GET') {
ctx.request.body = tslib_1.__assign({}, ctx.request.query);
ctx.request.body = tslib_1.__assign({}, (ctx.request.query || {}));
}
else {
ctx.request.body = ctx.request.body || {};
Expand Down
3 changes: 1 addition & 2 deletions lib/fire/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var FireCat = (function () {
if (config === void 0) { config = {}; }
var _this = this;
this.koa = new Koa(config.koaConfig);
this.koa.use(bodyParser());
this.koa.use(bodyParser(config.bodyParserConfig));
this.koa.use(function (ctx, next) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var err_1;
return tslib_1.__generator(this, function (_a) {
Expand All @@ -31,7 +31,6 @@ var FireCat = (function () {
}); });
}
FireCat.prototype.onError = function (ctx, err) {
console.log(err);
};
return FireCat;
}());
Expand Down
3 changes: 2 additions & 1 deletion lib/router/group.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Router from 'koa-router';
import { FireCatController } from "../controller";
import { KoaMiddleware } from '../../src/types';
export default class FireRouterGroup {
router: Router;
path: string;
Expand All @@ -13,6 +14,6 @@ export default class FireRouterGroup {
update(path: string, action: Router.IMiddleware<any, any>): any;
head(path: string, action: Router.IMiddleware<any, any>): any;
all(path: string, action: Router.IMiddleware<any, any>): any;
controller(path: string, control: FireCatController): void;
controller(path: string, control: FireCatController, middlewares?: KoaMiddleware[]): void;
group(path: string, callback: (router: FireRouterGroup) => void): void;
}
4 changes: 2 additions & 2 deletions lib/router/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var FireRouterGroup = (function () {
FireRouterGroup.prototype.all = function (path, action) {
return this.concat(path, action, 'all');
};
FireRouterGroup.prototype.controller = function (path, control) {
control.decoratorBindRouter(this.router, this.path + path.toString(), control);
FireRouterGroup.prototype.controller = function (path, control, middlewares) {
control.decoratorBindRouter(this.router, this.path + path.toString(), control, middlewares);
};
FireRouterGroup.prototype.group = function (path, callback) {
this.concatCallback(path, callback);
Expand Down
4 changes: 2 additions & 2 deletions lib/router/router.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as Router from 'koa-router';
import FireRouterGroup from "../router/group";
import { FireCatController } from "../controller";
import { FireDocumentHeadInterFace } from "../types";
import { FireDocumentHeadInterFace, KoaMiddleware } from "../types";
export declare class FireCatRouter {
router: Router;
constructor();
enableDocument(path?: string, config?: FireDocumentHeadInterFace): void;
group(path: string, callback: (router: FireRouterGroup) => void): void;
controller(path: string, control: FireCatController): void;
controller(path: string, control: FireCatController, middlewares?: KoaMiddleware[]): void;
}
4 changes: 2 additions & 2 deletions lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var FireCatRouter = (function () {
FireCatRouter.prototype.group = function (path, callback) {
callback(new group_1.default(this.router, path));
};
FireCatRouter.prototype.controller = function (path, control) {
control.decoratorBindRouter(this.router, (0, common_1.isStartRouter)(path) ? '' : path, control);
FireCatRouter.prototype.controller = function (path, control, middlewares) {
control.decoratorBindRouter(this.router, (0, common_1.isStartRouter)(path) ? '' : path, control, middlewares);
};
return FireCatRouter;
}());
Expand Down
20 changes: 19 additions & 1 deletion lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface FireValidatorErrorType {
message: string;
details: Validator.ValidationError[];
}
export type KoaMiddleware = (ctx: Context, next: Koa.Next) => Promise<void>;
export interface SyncCheckFunction extends Validator.SyncCheckFunction {
}
export interface Context extends Koa.Context {
Expand Down Expand Up @@ -68,6 +69,23 @@ export interface FireCatKoaFace {
maxIpsCount?: number | undefined;
}
export interface FireCatFace {
bodyParserConfig?: bodyParser.Options;
bodyParserConfig?: BodyParserOptions;
koaConfig?: FireCatKoaFace;
}
export declare function bodyParser(opts?: bodyParser.Options): Koa.Middleware;
export interface BodyParserOptions {
enableTypes?: string[] | undefined;
encoding?: string | undefined;
formLimit?: string | undefined;
jsonLimit?: string | undefined;
textLimit?: string | undefined;
xmlLimit?: string | undefined;
strict?: boolean | undefined;
detectJSON?: ((ctx: Koa.Context) => boolean) | undefined;
extendTypes?: {
json?: string[] | string | undefined;
form?: string[] | string | undefined;
text?: string[] | string | undefined;
} | undefined;
onerror?: ((err: Error, ctx: Koa.Context) => void) | undefined;
}

0 comments on commit b0163fe

Please sign in to comment.