Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
semantic-release-bot authored and Romakita committed Apr 22, 2019
1 parent 7efb425 commit a90e9cf
Show file tree
Hide file tree
Showing 90 changed files with 2,437 additions and 3,201 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
themeConfig: {
version: require("../../package").version,
repo: "TypedProject/ts-express-decorators",
openCollective: 'tsed',
gitterUrl: "https://gitter.im/Tsed-io/community",
editLinks: true,
docsDir: "docs",
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"semantic-release": "semantic-release",
"semantic-release:dry-run": "semantic-release --dry-run",
"clean": "gulp clean:workspace",
"start": "ts-node -r tsconfig-paths/register -r source-map-support/register test/integration/app/app.ts",
"start": "ts-node -c tsconfig.json -r tsconfig-paths/register test/integration/app/app.ts",
"test": "npm run clean && npm run test:lint && npm run test:coverage",
"test:unit": "cross-env NODE_ENV=test mocha",
"test:coverage": "cross-env NODE_ENV=test nyc mocha",
Expand Down Expand Up @@ -65,8 +65,9 @@
"@types/json-schema": "^7.0.0",
"globby": "^9.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.4.0",
"ts-httpexceptions": "^4.0.0",
"ts-log-debug": "^5.0.1"
"ts-log-debug": "^5.1.0"
},
"devDependencies": {
"@typedproject/ts-doc": "^4.0.1",
Expand Down Expand Up @@ -141,10 +142,10 @@
"typescript": "^3.0.1",
"vue-analytics": "^5.14.0",
"vuepress": "^0.14.2",
"vuepress-theme-tsed": "^1.5.2"
"vuepress-theme-tsed": "^1.7.0"
},
"directories": {
"packages": "packages",
"test": "test"
}
}
}
5 changes: 3 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
"@types/json-schema": "^6.0.1",
"globby": "^8.0.1",
"json-schema": "^0.2.3",
"rxjs": "^6.4.0",
"ts-httpexceptions": "^3.0.0",
"ts-log-debug": "^4.0.1",
"ts-log-debug": "^5.1.0",
"tslib": "^1.9.0"
},
"peerDependencies": {
"@types/express": "^4",
"@tsed/core": "0.0.0-PLACEHOLDER",
"@tsed/di": "0.0.0-PLACEHOLDER",
"@types/express": "^4",
"express": "^4"
},
"devDependencies": {}
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/config/interfaces/IServerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface IServerMountDirectories {
export interface ILoggerSettings {
/**
* Enable debug mode. By default debug is false.
* @deprecated
*/
debug?: boolean;
/**
Expand Down
26 changes: 12 additions & 14 deletions packages/common/src/config/services/ServerSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ export class ServerSettingsService implements IServerSettings, IDISettings {
* @returns {boolean}
*/
get debug(): boolean {
return !!this.logger.debug;
return this.logger.level === "info";
}

/**
*
* @param {boolean} debug
*/
set debug(debug: boolean) {
this.logger = {...this.logger, debug, level: "debug"};
this.logger = {...this.logger, level: debug ? "debug" : "info"};
}

/**
Expand Down Expand Up @@ -301,26 +301,24 @@ export class ServerSettingsService implements IServerSettings, IDISettings {
}

get logger(): Partial<ILoggerSettings> {
const requestFields = this.get("logRequestFields");

return Object.assign(
{
requestFields
},
this.map.get("logger")
);
return this.map.get("logger") || {};
}

set logger(value: Partial<ILoggerSettings>) {
this.map.set("logger", value);
const requestFields = this.get("logRequestFields");
const logger = {requestFields, ...this.logger, ...value};
logger.debug = logger.level === "debug";

this.map.set("logger", logger);
this.map.set("debug", logger.debug);

if (value.format) {
if (logger.format) {
$log.appenders.set("stdout", {
type: "stdout",
levels: ["info", "debug"],
layout: {
type: "pattern",
pattern: value.format
pattern: logger.format
}
});

Expand All @@ -329,7 +327,7 @@ export class ServerSettingsService implements IServerSettings, IDISettings {
type: "stderr",
layout: {
type: "pattern",
pattern: value.format
pattern: logger.format
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {nameOf, Type} from "@tsed/core";
import {BadRequest} from "ts-httpexceptions";
import {IResponseError} from "../../mvc/interfaces/IResponseError";

/**
* @private
*/
export class RequiredPropertyError extends BadRequest implements IResponseError {
export class RequiredPropertyError extends BadRequest {
errors: any[];

constructor(target: Type<any>, propertyName: string | symbol) {
Expand Down
24 changes: 12 additions & 12 deletions packages/common/src/filters/class/FilterBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Type} from "@tsed/core";
import {InjectorService} from "@tsed/di";
import {ConverterService} from "../../converters/services/ConverterService";
import {ParseExpressionError} from "../../mvc";
import {ParseExpressionError} from "../errors/ParseExpressionError";
import {RequiredParamError} from "../errors/RequiredParamError";
import {UnknowFilterError} from "../errors/UnknowFilterError";
import {IFilter} from "../interfaces";
Expand All @@ -14,6 +14,17 @@ import {ParamMetadata} from "./ParamMetadata";
export class FilterBuilder {
constructor(private injector: InjectorService) {}

/**
*
* @param {Function} filter
* @param {Function} newFilter
* @param args
* @returns {(value: any) => any}
*/
private static pipe(filter: Function, newFilter: Function, ...args: any[]): Function {
return (value: any) => newFilter(filter(value), ...args);
}

/**
*
*/
Expand Down Expand Up @@ -137,15 +148,4 @@ export class FilterBuilder {
}
);
}

/**
*
* @param {Function} filter
* @param {Function} newFilter
* @param args
* @returns {(value: any) => any}
*/
private static pipe(filter: Function, newFilter: Function, ...args: any[]): Function {
return (value: any) => newFilter(filter(value), ...args);
}
}
5 changes: 4 additions & 1 deletion packages/common/src/filters/decorators/endpointInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {ParamRegistry} from "../registries/ParamRegistry";
import {EndpointMetadata} from "../../mvc/class/EndpointMetadata";
import {ENDPOINT_INFO} from "../constants";
import {ParamRegistry} from "../registries/ParamRegistry";

export type EndpointInfo = EndpointMetadata;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {BadRequest} from "ts-httpexceptions";
import {IResponseError} from "../interfaces/IResponseError";

/**
* @private
*/
export class ParseExpressionError extends BadRequest implements IResponseError {
export class ParseExpressionError extends BadRequest {
dataPath: string;
requestType: string;
errorMessage: string;
Expand Down
11 changes: 1 addition & 10 deletions packages/common/src/filters/errors/RequiredParamError.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/**
* @module common/mvc
*/
/** */

import {BadRequest} from "ts-httpexceptions";
import {IResponseError} from "../../mvc/interfaces/IResponseError";

/**
* @private
*/
export class RequiredParamError extends BadRequest implements IResponseError {
export class RequiredParamError extends BadRequest {
errors: any[];

constructor(name: string, expression: string | RegExp) {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/filters/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export * from "./interfaces";
export * from "./class/ParamMetadata";
export * from "./class/FilterBuilder";

export * from "./errors/ParseExpressionError";
export * from "./errors/RequiredParamError";
export * from "./errors/UnknowFilterError";

export * from "./decorators/bodyParams";
export * from "./decorators/cookies";
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/filters/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./Arguments";
export * from "./IFilter";
export * from "./IFilterPreHandler";
export * from "./IFilterScope";
export * from "./IInjectableParamSettings";
export * from "./IParamOptions";
Expand Down
17 changes: 1 addition & 16 deletions packages/common/src/filters/registries/ParamRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Metadata, Type} from "@tsed/core";
import {ParamMetadata} from "../class/ParamMetadata";
import {EXPRESS_NEXT_FN, PARAM_METADATA} from "../constants";
import {PARAM_METADATA} from "../constants";
import {IInjectableParamSettings} from "../interfaces";
import {IParamArgs} from "../interfaces/Arguments";

Expand Down Expand Up @@ -44,13 +44,6 @@ export class ParamRegistry {
Metadata.set(PARAM_METADATA, params, target, targetKey);
}

/**
*
* @param target
* @param method
*/
static isInjectable = (target: any, method: string): boolean => (Metadata.get(PARAM_METADATA, target, method) || []).length > 0;

/**
*
* @param service
Expand Down Expand Up @@ -154,12 +147,4 @@ export class ParamRegistry {

return param;
}

/**
*
* @param target
* @param propertyKey
*/
static hasNextFunction = (target: Type<any>, propertyKey: string) =>
ParamRegistry.getParams(target, propertyKey).findIndex(p => p.service === EXPRESS_NEXT_FN) > -1;
}
32 changes: 32 additions & 0 deletions packages/common/src/mvc/class/Context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {EndpointMetadata} from "./EndpointMetadata";

export class Context extends Map<any, any> {
readonly id: string;
readonly dateStart: Date = new Date();
public data: any;
public endpoint: EndpointMetadata;
// public auth: any; // TODO Add Auth token support
private _container: Map<string, any> = new Map();

[key: string]: any;

constructor({id}: {id: string}) {
super();
this.id = id;
}

get container(): Map<string, any> {
return this._container;
}

destroy() {
this._container.forEach((instance: any) => {
/* istanbul ignore next */
if (instance.$onDestroy) {
instance.$onDestroy();
}
});

delete this._container;
}
}
Loading

0 comments on commit a90e9cf

Please sign in to comment.