Skip to content

Commit

Permalink
chore: change request.body and ctx.config type to any
Browse files Browse the repository at this point in the history
  • Loading branch information
shepherdwind committed Feb 28, 2018
1 parent bd7100a commit 00f7cf9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 196 deletions.
196 changes: 2 additions & 194 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare class BaseContextClass { // tslint:disable-line
/**
* Application config object
*/
config: EggAppConfig;
config: any;

/**
* service
Expand All @@ -39,8 +39,6 @@ export interface Logger {
error(info: string | Error, ...args: any[]): void;
}

export type RequestArrayBody = any[];
export type RequestObjectBody = { [key: string]: any };
interface Request extends KoaApplication.Request { // tslint:disable-line
/**
* detect if response should be json
Expand Down Expand Up @@ -158,196 +156,6 @@ interface ContextView { // tslint:disable-line

export type LoggerLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';

export interface EggAppConfig {
workerStartTimeout: number;
baseDir: string;
/**
* The option of `bodyParser` middleware
*
* @member Config#bodyParser
* @property {Boolean} enable - enable bodyParser or not, default to true
* @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
* @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
* @property {String} encoding - body encoding config, default utf8
* @property {String} formLimit - form body size limit, default 100kb
* @property {String} jsonLimit - json body size limit, default 100kb
* @property {Boolean} strict - json body strict mode, if set strict value true, then only receive object and array json body
* @property {Number} queryString.arrayLimit - from item array length limit, default 100
* @property {Number} queryString.depth - json value deep lenght, default 5
* @property {Number} queryString.parameterLimit - paramter number limit ,default 1000
*/
bodyParser: {
enable: boolean;
encoding: string;
formLimit: string;
jsonLimit: string;
strict: true;
queryString: {
arrayLimit: number;
depth: number;
parameterLimit: number;
};
};

/**
* logger options
* @member Config#logger
* @property {String} dir - directory of log files
* @property {String} encoding - log file encloding, defaults to utf8
* @property {String} level - default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production
* @property {String} consoleLevel - log level of stdout, defaults to INFO in local serverEnv, defaults to WARN in unittest, defaults to NONE elsewise
* @property {Boolean} outputJSON - log as JSON or not, defaults to false
* @property {Boolean} buffer - if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true
* @property {String} errorLogName - file name of errorLogger
* @property {String} coreLogName - file name of coreLogger
* @property {String} agentLogName - file name of agent worker log
* @property {Object} coreLogger - custom config of coreLogger
*/
logger: {
dir: string;
encoding: string;
env: string;
level: LoggerLevel;
consoleLevel: LoggerLevel;
outputJSON: boolean;
buffer: boolean;
appLogName: string;
coreLogName: string;
agentLogName: string;
errorLogName: string;
coreLogger: any;
};

httpclient: {
keepAlive: boolean;
freeSocketKeepAliveTimeout: number;
timeout: number;
maxSockets: number;
maxFreeSockets: number;
enableDNSCache: boolean;
};

development: {
/**
* dirs needed watch, when files under these change, application will reload, use relative path
*/
watchDirs: string[];
/**
* dirs don't need watch, including subdirectories, use relative path
*/
ignoreDirs: string[];
/**
* don't wait all plugins ready, default is true.
*/
fastReady: boolean;
};
/**
* It will ignore special keys when dumpConfig
*/
dump: {
ignore: Set<string>;
};

/**
* The environment of egg
*/
env: string;

/**
* The current HOME directory
*/
HOME: string;

hostHeaders: string;

/**
* I18n options
*/
i18n: {
/**
* default value EN_US
*/
defaultLocale: string;
/**
* i18n resource file dir, not recommend to change default value
*/
dir: string;
/**
* custom the locale value field, default `query.locale`, you can modify this config, such as `query.lang`
*/
queryField: string;
/**
* The locale value key in the cookie, default is locale.
*/
cookieField: string;
/**
* Locale cookie expire time, default `1y`, If pass number value, the unit will be ms
*/
cookieMaxAge: string | number;
};

/**
* Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true.
*/
ipHeaders: string;

/**
* jsonp options
* @member Config#jsonp
* @property {String} callback - jsonp callback method key, default to `_callback`
* @property {Number} limit - callback method name's max length, default to `50`
* @property {Boolean} csrf - enable csrf check or not. default to false
* @property {String|RegExp|Array} whiteList - referrer white list
*/
jsonp: {
limit: number;
callback: string;
csrf: boolean;
whiteList: string | RegExp | Array<string | RegExp>;
};

/**
* The key that signing cookies. It can contain multiple keys seperated by .
*/
keys: string;

/**
* The name of the application
*/
name: string;

/**
* package.json
*/
pkg: any;

rundir: string;

security: {
domainWhiteList: string[];
protocolWhiteList: string[];
defaultMiddleware: string;
csrf: any;
xframe: {
enable: boolean;
value: 'SAMEORIGIN' | 'DENY' | 'ALLOW-FROM';
};
hsts: any;
methodnoallow: { enable: boolean };
noopen: { enable: boolean; }
xssProtection: any;
csp: any;
};

siteFile: any;

static: any;

view: any;

watcher: any;
}

export interface Router extends KoaRouter {
/**
* restful router api
Expand Down Expand Up @@ -379,7 +187,7 @@ declare interface EggApplication extends KoaApplication { // tslint:disable-line
/**
* The configuration of application
*/
config: EggAppConfig;
config: any;

/**
* app.env delegate app.config.env
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/apps/app-ts/app/controller/foo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, RequestObjectBody } from 'egg';
import { Controller } from 'egg';

// add user controller and service
declare module 'egg' {
Expand All @@ -13,7 +13,7 @@ export default class FooController extends Controller {
try {
this.ctx.body = await this.ctx.service.foo.bar();
} catch (e) {
const body: RequestObjectBody = this.ctx.request.body;
const body = this.ctx.request.body;
this.app.logger.info(e.name, body.foo);
}
}
Expand Down

0 comments on commit 00f7cf9

Please sign in to comment.