Socket
Socket
Sign inDemoInstall

@alterior/core

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alterior/core - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

lib/response.d.ts

2

.vscode/launch.json

@@ -9,4 +9,4 @@ {

"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": ["--no-timeouts", "**/*.test.js"],
"stopOnEntry": false,
"args": ["--no-timeouts", "**/*.test.js"],
"cwd": "${workspaceRoot}",

@@ -13,0 +13,0 @@ "preLaunchTask": null,

@@ -11,1 +11,2 @@ export * from './lib/accesscontrol';

export * from './lib/errors';
export * from './lib/response';

@@ -14,2 +14,3 @@ "use strict";

__export(require('./lib/errors'));
__export(require('./lib/response'));
//# sourceMappingURL=index.js.map

@@ -11,2 +11,3 @@

export * from './lib/bootstrap';
export * from './lib/errors';
export * from './lib/errors';
export * from './lib/response';

@@ -34,3 +34,3 @@ import { Provider } from '@angular/core';

*/
providers?: Provider[];
providers?: (Provider | Promise<Provider>)[];
/**

@@ -37,0 +37,0 @@ * Global and mounted middleware. Middleware included here will be

@@ -42,3 +42,3 @@ import { Provider } from '@angular/core';

*/
providers? : Provider[];
providers? : (Provider | Promise<Provider>)[];

@@ -45,0 +45,0 @@ /**

@@ -8,2 +8,3 @@ "use strict";

var route_1 = require('./route');
var response_1 = require('./response');
var express_1 = require('./express');

@@ -65,2 +66,8 @@ var errors_1 = require('./errors');

(appOptions.middleware || [])
.map(function (x, i) {
if (x == null) {
throw new Error("AppOptions provided null middleware at position " + i);
}
return x;
})
.filter(function (x) { return Reflect.getMetadata('alterior:middleware', x) != null; })

@@ -111,11 +118,20 @@ .forEach(function (x) { return providers.push(x); });

var childProviders = [];
for (var _i = 0, routes_1 = routes; _i < routes_1.length; _i++) {
var route = routes_1[_i];
var _loop_2 = function(route) {
(route.options.middleware || [])
.map(function (x, i) {
if (x == null) {
throw new Error("Route " + route.path + " provided null middleware at position " + i);
}
return x;
})
.filter(function (x) { return Reflect.getMetadata('alterior:middleware', x) != null; })
.forEach(function (x) { return childProviders.push(x); });
};
for (var _i = 0, routes_1 = routes; _i < routes_1.length; _i++) {
var route = routes_1[_i];
_loop_2(route);
}
var childInjector = injector.resolveAndCreateChild(childProviders);
// Register all of our routes with Express
var _loop_2 = function(route) {
var _loop_3 = function(route) {
allRoutes.push({

@@ -139,3 +155,3 @@ controller: controller,

if (paramTypes) {
var _loop_3 = function(i, max) {
var _loop_4 = function(i, max) {
var paramName = paramNames[i];

@@ -168,3 +184,3 @@ var paramType = paramTypes[i];

for (var i = 0, max = paramNames.length; i < max; ++i) {
_loop_3(i, max);
_loop_4(i, max);
}

@@ -192,3 +208,6 @@ }

var httpException = e;
res.status(httpException.statusCode).send(httpException.body);
res.status(httpException.statusCode);
httpException.headers
.forEach(function (header) { return res.header(header[0], header[1]); });
res.send(httpException.body);
}

@@ -214,3 +233,6 @@ else {

var httpException = e;
res.status(httpException.statusCode).send(httpException.body);
res.status(httpException.statusCode);
httpException.headers
.forEach(function (header) { return res.header(header[0], header[1]); });
res.send(httpException.body);
}

@@ -225,3 +247,3 @@ else {

}
else if (result.constructor === route_1.Response) {
else if (result.constructor === response_1.Response) {
var response = result;

@@ -241,3 +263,3 @@ res.status(response.status);

var route = routes_2[_a];
_loop_2(route);
_loop_3(route);
}

@@ -244,0 +266,0 @@ };

@@ -8,3 +8,4 @@ import 'reflect-metadata';

import { Middleware, prepareMiddleware } from './middleware';
import { RouteReflector, RouteEvent, Response } from './route';
import { RouteReflector, RouteEvent } from './route';
import { Response } from './response';
import { ExpressRef } from './express';

@@ -87,2 +88,8 @@ import { HttpException } from './errors';

(appOptions.middleware || [])
.map((x, i) => {
if (x == null) {
throw new Error("AppOptions provided null middleware at position "+i);
}
return x;
})
.filter(x => Reflect.getMetadata('alterior:middleware', x) != null)

@@ -155,2 +162,8 @@ .forEach(x => providers.push(x))

(route.options.middleware || [])
.map((x, i) => {
if (x == null) {
throw new Error("Route "+route.path+" provided null middleware at position "+i);
}
return x;
})
.filter(x => Reflect.getMetadata('alterior:middleware', x) != null)

@@ -240,3 +253,8 @@ .forEach(x => childProviders.push(x));

let httpException = <HttpException>e;
res.status(httpException.statusCode).send(httpException.body);
res.status(httpException.statusCode);
httpException.headers
.forEach(header => res.header(header[0], header[1]));
res.send(httpException.body);
} else {

@@ -265,3 +283,8 @@ res.status(500).send(JSON.stringify({

let httpException = <HttpException>e;
res.status(httpException.statusCode).send(httpException.body);
res.status(httpException.statusCode);
httpException.headers
.forEach(header => res.header(header[0], header[1]));
res.send(httpException.body);
} else {

@@ -268,0 +291,0 @@ res.status(500).send(JSON.stringify({

@@ -0,1 +1,2 @@

export declare function shallowClone(obj: Object): any;
export declare function clone(obj: any): any;
"use strict";
function shallowClone(obj) {
if (typeof obj !== 'object')
return obj;
var clone = Object.create(obj.constructor.prototype);
Object.assign(clone, obj);
return clone;
}
exports.shallowClone = shallowClone;
function clone(obj) {

@@ -3,0 +11,0 @@ return JSON.parse(JSON.stringify(obj));

@@ -0,3 +1,13 @@

export function shallowClone(obj : Object) {
if (typeof obj !== 'object')
return obj;
let clone = Object.create(obj.constructor.prototype);
Object.assign(clone, obj);
return clone;
}
export function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
export declare class HttpException {
statusCode: number;
headers: string[][];
body: any;
constructor(statusCode: number, body: any);
constructor(statusCode: number, headers: string[][], body: any);
}
"use strict";
var HttpException = (function () {
function HttpException(statusCode, body) {
function HttpException(statusCode, headers, body) {
this.statusCode = statusCode;
this.headers = headers;
this.body = body;

@@ -6,0 +7,0 @@ if (typeof body === 'object')

export class HttpException {
constructor(public statusCode : number, public body : any) {
constructor(public statusCode : number, public headers : string[][], public body : any) {
if (typeof body === 'object')

@@ -4,0 +4,0 @@ body = JSON.stringify(body);

import * as express from 'express';
export declare class Response {
status: number;
headers: string[][];
body: string;
constructor(status: number, headers: string[][], body: string);
}
export declare class RouteReflector {

@@ -9,0 +3,0 @@ constructor(type: Function);

"use strict";
var clone_1 = require('./clone');
var Response = (function () {
function Response(status, headers, body) {
this.status = status;
this.headers = headers;
this.body = body;
}
return Response;
}());
exports.Response = Response;
var RouteReflector = (function () {

@@ -20,3 +11,3 @@ function RouteReflector(type) {

}
this.routes = (type.prototype['alterior:routes'] || []).map(function (x) { return clone_1.clone(x); });
this.routes = (type.prototype['alterior:routes'] || []).map(function (x) { return clone_1.shallowClone(x); });
if (controllerMetadata.basePath) {

@@ -23,0 +14,0 @@ this.routes.forEach(function (route) {

@@ -340,3 +340,3 @@ "use strict";

};
RouteDecorator.prototype['should allow raw data to be returned via Response'] = function (done) {
RouteDecorator.prototype['should 500 when a method returns a promise that rejects'] = function (done) {
var TestController = (function () {

@@ -346,3 +346,3 @@ function TestController() {

TestController.prototype.getX = function (req, res) {
return new route_1.Response(201, [['Content-Type', 'text/plain; charset=utf-8']], "token string");
return Promise.reject(new Error("All the things went wrong"));
};

@@ -379,4 +379,3 @@ __decorate([

.get('/foo')
.expect(201, 'token string')
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(500)
.end(function (err, res) {

@@ -390,3 +389,3 @@ app.stop();

};
RouteDecorator.prototype['should 500 when a method returns a promise that rejects'] = function (done) {
RouteDecorator.prototype['should act accordingly when a method returns a promise that rejects with an HttpException'] = function (done) {
var TestController = (function () {

@@ -396,3 +395,3 @@ function TestController() {

TestController.prototype.getX = function (req, res) {
return Promise.reject(new Error("All the things went wrong"));
return Promise.reject(new errors_1.HttpException(300, [['X-Test', 'pass']], { bar: 777 }));
};

@@ -429,3 +428,6 @@ __decorate([

.get('/foo')
.expect(500)
.expect(300, {
bar: 777
})
.expect('X-Test', 'pass')
.end(function (err, res) {

@@ -439,3 +441,3 @@ app.stop();

};
RouteDecorator.prototype['should act accordingly when a method returns a promise that rejects with an HttpException'] = function (done) {
RouteDecorator.prototype['should apply route-specific middleware'] = function (done) {
var TestController = (function () {

@@ -445,6 +447,13 @@ function TestController() {

TestController.prototype.getX = function (req, res) {
return Promise.reject(new errors_1.HttpException(300, { bar: 777 }));
return req['fun'];
};
__decorate([
route_1.Get('/foo'),
route_1.Get('/foo', {
middleware: [
function (req, res, next) {
req.fun = 'funfun';
next();
}
]
}),
__metadata('design:type', Function),

@@ -478,5 +487,3 @@ __metadata('design:paramtypes', [Object, Object]),

.get('/foo')
.expect(300, {
bar: 777
})
.expect(200, '"funfun"')
.end(function (err, res) {

@@ -747,3 +754,3 @@ app.stop();

__metadata('design:returntype', void 0)
], RouteDecorator.prototype, 'should allow raw data to be returned via Response', null);
], RouteDecorator.prototype, 'should 500 when a method returns a promise that rejects', null);
__decorate([

@@ -754,3 +761,3 @@ mocha_typescript_1.test,

__metadata('design:returntype', void 0)
], RouteDecorator.prototype, 'should 500 when a method returns a promise that rejects', null);
], RouteDecorator.prototype, 'should act accordingly when a method returns a promise that rejects with an HttpException', null);
__decorate([

@@ -761,3 +768,3 @@ mocha_typescript_1.test,

__metadata('design:returntype', void 0)
], RouteDecorator.prototype, 'should act accordingly when a method returns a promise that rejects with an HttpException', null);
], RouteDecorator.prototype, 'should apply route-specific middleware', null);
__decorate([

@@ -764,0 +771,0 @@ mocha_typescript_1.test,

import { controllerClasses, Controller as _Controller } from './controller';
import { Get, Post, Put, Patch, Delete, Options, RouteEvent, Response } from './route';
import { Get, Post, Put, Patch, Delete, Options, RouteEvent } from './route';
import { suite, test as it } from 'mocha-typescript';

@@ -237,3 +237,3 @@ import * as assert from 'assert';

@it 'should allow raw data to be returned via Response' (done) {
@it 'should 500 when a method returns a promise that rejects' (done) {

@@ -244,3 +244,3 @@ @_Controller()

getX(req : express.Request, res : express.Response) {
return new Response(201, [['Content-Type', 'text/plain; charset=utf-8']], "token string");
return Promise.reject(new Error("All the things went wrong"));
}

@@ -254,3 +254,3 @@ }

(req, res, next) => { res.header('Content-Type', 'application/json'); next(); }
]
]
})

@@ -263,4 +263,3 @@ class FakeApp {

.get('/foo')
.expect(201, <any>'token string')
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(500)
.end((err, res) => {

@@ -270,3 +269,2 @@ app.stop();

return done(err);
done();

@@ -277,3 +275,3 @@ });

@it 'should 500 when a method returns a promise that rejects' (done) {
@it 'should act accordingly when a method returns a promise that rejects with an HttpException' (done) {

@@ -284,3 +282,3 @@ @_Controller()

getX(req : express.Request, res : express.Response) {
return Promise.reject(new Error("All the things went wrong"));
return Promise.reject(new HttpException(300, [['X-Test', 'pass']], {bar:777}));
}

@@ -302,3 +300,6 @@ }

.get('/foo')
.expect(500)
.expect(300, <any>{
bar: 777
})
.expect('X-Test', 'pass')
.end((err, res) => {

@@ -313,9 +314,16 @@ app.stop();

@it 'should act accordingly when a method returns a promise that rejects with an HttpException' (done) {
@it 'should apply route-specific middleware' (done) {
@_Controller()
class TestController {
@Get('/foo')
@Get('/foo', {
middleware: [
(req, res, next) => {
req.fun = 'funfun';
next();
}
]
})
getX(req : express.Request, res : express.Response) {
return Promise.reject(new HttpException(300, {bar:777}));
return req['fun'];
}

@@ -337,5 +345,3 @@ }

.get('/foo')
.expect(300, <any>{
bar: 777
})
.expect(200, <any>'"funfun"')
.end((err, res) => {

@@ -342,0 +348,0 @@ app.stop();

import * as express from 'express';
import { clone } from './clone';
import { shallowClone, clone } from './clone';
export class Response {
constructor(
public status : number,
public headers : string[][],
public body : string
) {
}
}
export class RouteReflector {

@@ -24,3 +15,3 @@ constructor(type : Function) {

this.routes = (type.prototype['alterior:routes'] || []).map(x => clone(x));
this.routes = (type.prototype['alterior:routes'] || []).map(x => shallowClone(x));

@@ -27,0 +18,0 @@ if (controllerMetadata.basePath) {

{
"name": "@alterior/core",
"version": "0.0.7",
"version": "0.0.8",
"private": false,

@@ -31,2 +31,3 @@ "description": "An Express-based Typescript MVC framework using decorators and Angular 2 dependency injection.",

"devDependencies": {
"chai": "^3.5.0",
"jasmine": "^2.5.2",

@@ -33,0 +34,0 @@ "jasmine-core": "^2.5.2",

{
"dependencies": {
"body-parser": "registry:npm/body-parser#1.15.2+20160815132839",
"chai": "registry:npm/chai#3.5.0+20160723033700",
"express": "registry:npm/express#4.14.0+20160815112707",

@@ -5,0 +6,0 @@ "mkdirp": "registry:npm/mkdirp#0.5.0+20160723033700"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc