Socket
Socket
Sign inDemoInstall

arrow-express

Package Overview
Dependencies
71
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

dist/error/configuration.error.d.ts

0

.eslintrc.js

@@ -0,0 +0,0 @@ // eslint-disable-next-line no-undef

@@ -0,0 +0,0 @@ import Express from 'express';

10

dist/application/application.js

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

var request_error_1 = require("../error/request.error");
var configuration_error_1 = require("../error/configuration.error");
var AppConfigurator = /** @class */ (function () {

@@ -58,3 +59,7 @@ function AppConfigurator(port, app, logRequests) {

var _this = this;
this._express[route.getMethod()](AppConfigurator.getRoutePath(controller.getPrefix(), route.getPath()), function (req, res) { return __awaiter(_this, void 0, void 0, function () {
var routePath = AppConfigurator.getRoutePath(controller.getPrefix(), route.getPath());
if (!route.getMethod()) {
throw new configuration_error_1.ConfigurationError("Route " + routePath + " has no method specified");
}
this._express[route.getMethod()](routePath, function (req, res) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {

@@ -148,3 +153,3 @@ switch (_a.label) {

if (this._started) {
throw new Error('Cannot start application multiple times');
throw new configuration_error_1.ConfigurationError('Cannot start application multiple times');
}

@@ -162,2 +167,3 @@ this._started = true;

this.getExpressRoutesAsStrings().forEach(function (route) { return console.log(route); });
console.log('\n');
return [2 /*return*/];

@@ -164,0 +170,0 @@ });

@@ -0,0 +0,0 @@ import { RouteConfigurator } from '../route/route';

@@ -0,0 +0,0 @@ "use strict";

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

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export { Application, AppConfigurator } from "./application/application";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import Express from 'express';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ // eslint-disable-next-line no-undef

@@ -0,0 +0,0 @@ // eslint-disable-next-line no-undef

@@ -0,0 +0,0 @@ {

@@ -0,0 +0,0 @@ # This is example application

@@ -0,0 +0,0 @@ import {RequestError} from "arrow-express";

@@ -0,0 +0,0 @@ import {Route, RouteConfigurator} from "arrow-express";

@@ -0,0 +0,0 @@ import {Route, RouteConfigurator} from "arrow-express";

@@ -0,0 +0,0 @@ import {Controller, ControllerConfiguration, RouteConfigurator} from "arrow-express";

@@ -0,0 +0,0 @@ import { User } from '../entities/user.entity';

@@ -0,0 +0,0 @@ // Express packages

@@ -0,0 +0,0 @@ {

@@ -0,0 +0,0 @@ // eslint-disable-next-line no-undef

@@ -7,2 +7,3 @@ import { Application } from './application';

import {mocked} from "ts-jest/utils";
import {ConfigurationError} from "../error/configuration.error";

@@ -47,2 +48,3 @@ const ExpressAppStub: Express.Application = {

});
it('should register get route', () => {

@@ -62,2 +64,44 @@ const handlerSpy = jest.fn();

});
it('should register route without path', () => {
const handlerSpy = jest.fn();
Application({port: 8080, app: ExpressAppStub})
.registerController(
Controller().prefix('prefix')
.registerRoute(
Route()
.method('get')
.handler(handlerSpy)
)
).start();
expect(ExpressAppStub.get).toHaveBeenCalledWith('/prefix', expect.any(Function));
});
it('should register route without path and prefix', () => {
const handlerSpy = jest.fn();
Application({port: 8080, app: ExpressAppStub})
.registerController(
Controller()
.registerRoute(
Route()
.method('get')
.handler(handlerSpy)
)
).start();
expect(ExpressAppStub.get).toHaveBeenCalledWith('/', expect.any(Function));
});
it('should throw configuration error when route without method is registered', () => {
const handlerSpy = jest.fn();
const app = Application({port: 8080, app: ExpressAppStub})
.registerController(
Controller().prefix('prefix')
.registerRoute(
Route()
.path('')
.handler(handlerSpy)
)
);
expect(() => app.start()).toThrow(ConfigurationError);
});
});

@@ -64,0 +108,0 @@ });

@@ -6,2 +6,3 @@ import Express from 'express';

import {RequestError} from '../error/request.error';
import {ConfigurationError} from "../error/configuration.error";

@@ -32,6 +33,12 @@ export class AppConfigurator {

private registerRoute(controller: ControllerConfiguration, route: RouteConfigurator) {
const routePath = AppConfigurator.getRoutePath(
controller.getPrefix(),
route.getPath());
if (!route.getMethod()) {
throw new ConfigurationError(`Route ${routePath} has no method specified`)
}
this._express[route.getMethod()](
AppConfigurator.getRoutePath(
controller.getPrefix(),
route.getPath()),
routePath,
async (req: Express.Request, res: Express.Response) => {

@@ -105,3 +112,3 @@ await this.handleRequest(req, res, route.getRequestHandler());

if(this._started) {
throw new Error('Cannot start application multiple times');
throw new ConfigurationError('Cannot start application multiple times');
}

@@ -119,2 +126,3 @@ this._started = true;

this.getExpressRoutesAsStrings().forEach(route => console.log(route));
console.log('\n');
});

@@ -121,0 +129,0 @@ }

@@ -0,0 +0,0 @@ import {Route} from "../route/route";

@@ -0,0 +0,0 @@ import {RouteConfigurator} from '../route/route';

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

@@ -0,0 +0,0 @@ export { Application, AppConfigurator } from "./application/application";

@@ -0,0 +0,0 @@ import { Route } from './route';

@@ -0,0 +0,0 @@ import Express from 'express';

{
"name": "arrow-express",
"version": "0.2.1",
"version": "0.2.2",
"description": "Library to bootstrap express applications with zero configuration",

@@ -11,3 +11,3 @@ "main": "dist/index.js",

"scripts": {
"build": "tsc --declaration",
"build": "tsc --declaration --project tsconfig.json",
"test": "jest",

@@ -14,0 +14,0 @@ "test:watch": "jest --watch",

@@ -0,0 +0,0 @@ # Arrow Express

@@ -0,0 +0,0 @@ {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc