Skip to content

Commit

Permalink
chore(release) publish v4.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 12, 2018
1 parent 77b778f commit 4bcfe79
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 48 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions lib/common/utils/shared.utils.d.ts
Expand Up @@ -6,3 +6,4 @@ export declare const isConstructor: (fn: any) => boolean;
export declare const validatePath: (path: any) => string;
export declare const isNil: (obj: any) => boolean;
export declare const isEmpty: (array: any) => boolean;
export declare const isSymbol: (fn: any) => boolean;
1 change: 1 addition & 0 deletions lib/common/utils/shared.utils.js
Expand Up @@ -8,3 +8,4 @@ exports.isConstructor = (fn) => fn === 'constructor';
exports.validatePath = (path) => path.charAt(0) !== '/' ? '/' + path : path;
exports.isNil = (obj) => exports.isUndefined(obj) || obj === null;
exports.isEmpty = (array) => !(array && array.length > 0);
exports.isSymbol = (fn) => typeof fn === 'symbol';
2 changes: 1 addition & 1 deletion lib/core/injector/module.js
Expand Up @@ -182,7 +182,7 @@ class Module {
}
addCustomExportedComponent(exportedComponent) {
const provide = exportedComponent.provide;
if (shared_utils_1.isString(provide)) {
if (shared_utils_1.isString(provide) || shared_utils_1.isSymbol(provide)) {
return this._exports.add(provide);
}
this._exports.add(provide.name);
Expand Down
5 changes: 2 additions & 3 deletions lib/core/router/router-execution-context.d.ts
Expand Up @@ -44,9 +44,8 @@ export declare class RouterExecutionContext {
type: any;
data: any;
}, transforms: Transform<any>[]): Promise<any>;
createGuardsFn(guards: any[], instance: Controller, callback: (...args) => any): (req: any) => Promise<any>;
createGuardsFn(guards: any[], instance: Controller, callback: (...args) => any): (req: any) => Promise<void>;
createPipesFn(pipes: any[], paramsOptions: (ParamProperties & {
metatype?: any;
})[]): (...args: any[]) => Promise<any>;
createHandleResponseFn(isResponseHandled: boolean, httpStatusCode: number): (...args: any[]) => any;
})[]): (args: any, req: any, res: any, next: any) => Promise<void>;
}
16 changes: 5 additions & 11 deletions lib/core/router/router-execution-context.js
Expand Up @@ -43,16 +43,15 @@ class RouterExecutionContext {
: this.responseController.getStatusByMethod(requestMethod);
const fnCanActivate = this.createGuardsFn(guards, instance, callback);
const fnApplyPipes = this.createPipesFn(pipes, paramsOptions);
const fnHandleResponse = this.createHandleResponseFn(isResponseHandled, httpStatusCode);
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
const args = this.createNullArray(argsLength);
yield fnCanActivate(req);
fnCanActivate && (yield fnCanActivate(req));
const handler = () => __awaiter(this, void 0, void 0, function* () {
yield fnApplyPipes(args, req, res, next);
fnApplyPipes && (yield fnApplyPipes(args, req, res, next));
return callback.apply(instance, args);
});
const result = yield this.interceptorsConsumer.intercept(interceptors, req, instance, callback, handler);
fnHandleResponse(result, res);
isResponseHandled && this.responseController.apply(result, res, httpStatusCode);
});
}
mapParamType(key) {
Expand Down Expand Up @@ -117,7 +116,7 @@ class RouterExecutionContext {
throw new common_1.HttpException(constants_2.FORBIDDEN_MESSAGE, common_1.HttpStatus.FORBIDDEN);
}
});
return guards.length ? canActivateFn : (req) => __awaiter(this, void 0, void 0, function* () { return undefined; });
return guards.length ? canActivateFn : null;
}
createPipesFn(pipes, paramsOptions) {
const pipesFn = (args, req, res, next) => __awaiter(this, void 0, void 0, function* () {
Expand All @@ -127,12 +126,7 @@ class RouterExecutionContext {
args[index] = yield this.getParamValue(value, { metatype, type, data }, pipes.concat(this.pipesContextCreator.createConcreteContext(paramPipes)));
})));
});
return paramsOptions.length ? pipesFn : (...args) => __awaiter(this, void 0, void 0, function* () { return undefined; });
}
createHandleResponseFn(isResponseHandled, httpStatusCode) {
return !isResponseHandled
? (result, res) => this.responseController.apply(result, res, httpStatusCode)
: (...args) => undefined;
return paramsOptions.length ? pipesFn : null;
}
}
exports.RouterExecutionContext = RouterExecutionContext;
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nestjs",
"version": "4.5.7",
"version": "4.5.8",
"description": "Modern, fast, powerful node.js web framework",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 5 additions & 19 deletions src/core/router/router-execution-context.ts
Expand Up @@ -81,17 +81,13 @@ export class RouterExecutionContext {

const fnCanActivate = this.createGuardsFn(guards, instance, callback);
const fnApplyPipes = this.createPipesFn(pipes, paramsOptions);
const fnHandleResponse = this.createHandleResponseFn(
isResponseHandled,
httpStatusCode,
);

return async (req, res, next) => {
const args = this.createNullArray(argsLength);
await fnCanActivate(req);
fnCanActivate && await fnCanActivate(req);

const handler = async () => {
await fnApplyPipes(args, req, res, next);
fnApplyPipes && await fnApplyPipes(args, req, res, next);
return callback.apply(instance, args);
};
const result = await this.interceptorsConsumer.intercept(
Expand All @@ -101,7 +97,7 @@ export class RouterExecutionContext {
callback,
handler,
);
fnHandleResponse(result, res);
isResponseHandled && this.responseController.apply(result, res, httpStatusCode)
};
}

Expand Down Expand Up @@ -214,7 +210,7 @@ export class RouterExecutionContext {
throw new HttpException(FORBIDDEN_MESSAGE, HttpStatus.FORBIDDEN);
}
};
return guards.length ? canActivateFn : async req => undefined;
return guards.length ? canActivateFn : null;
}

public createPipesFn(
Expand Down Expand Up @@ -244,16 +240,6 @@ export class RouterExecutionContext {
}),
);
};
return paramsOptions.length ? pipesFn : async (...args) => undefined;
}

public createHandleResponseFn(
isResponseHandled: boolean,
httpStatusCode: number,
) {
return !isResponseHandled
? (result, res) =>
this.responseController.apply(result, res, httpStatusCode)
: (...args) => undefined;
return paramsOptions.length ? pipesFn : null;
}
}
15 changes: 2 additions & 13 deletions src/core/test/router/router-execution-context.spec.ts
Expand Up @@ -315,9 +315,9 @@ describe('RouterExecutionContext', () => {
});
describe('createPipesFn', () => {
describe('when "paramsOptions" is empty', () => {
it('returns identity(undefined)', async () => {
it('returns null', async () => {
const pipesFn = contextCreator.createPipesFn([], []);
expect(await pipesFn()).to.be.undefined;
expect(pipesFn).to.be.null;
});
});
});
Expand All @@ -328,15 +328,4 @@ describe('RouterExecutionContext', () => {
expect(guardsFn({})).to.eventually.throw();
});
});
describe('createHandleResponseFn', () => {
it('should throw exception when "tryActivate" returns false', () => {
const responseFn = contextCreator.createHandleResponseFn(false, 200);
const controllerApplySpy = sinon.spy(
contextCreator['responseController'] as any,
'apply',
);
responseFn();
expect(controllerApplySpy.calledOnce).to.be.true;
});
});
});

0 comments on commit 4bcfe79

Please sign in to comment.