Skip to content

Commit

Permalink
v0.4.0: Use injector module
Browse files Browse the repository at this point in the history
  • Loading branch information
codyjdalton committed Jun 19, 2018
1 parent c87151b commit e74058d
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 227 deletions.
14 changes: 14 additions & 0 deletions .npmignore
@@ -1,2 +1,16 @@
# dependencies
/node_modules

# reports
/coverage
/.nyc_output

# distributions
/dist

# system files
.DS_Store

# project files
lib/
tsconfig.json
22 changes: 14 additions & 8 deletions .travis.yml
@@ -1,10 +1,16 @@
language : node_js
node_js :
- stable
language: node_js
node_js:
- stable
install:
- npm install
- npm install
script:
- npm run build

# Send coverage data to Coveralls
after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js"
- npm run build
after_script: cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js
deploy:
provider: npm
email: codydevbox@gmail.com
on:
branch: master
repo: codyjdalton/litstack
api_key:
secure: qpscGYgtyfwLvQMwTqN6jblTmBnKUCp1E17WJqH/V901F0zdAkIlVGk7dYgvWU+YMIEyRdcmZUN6bjZX96s0ppBrKQMelVYPPlJPB1Kkaq9y/fkjLDWypaPQxS0ouQelmvx0KxvRP83ZymkE07sfIBnr2MVYhkZuEHOArbujz3mordOAqQpIXG5nkpitjjZdeY9YK/kbwvkBclV/gFw+07iraYl6FuOjN0fDuaj5Px+TvhQJoGrPA/xBCUtsakQKA1MPree6tl4oEVamwmEOhsx3hl4Ws5ddRTkP7L/3b9isVIpyCqRXqpJ+uCUmRizXaGHrGJ7OUShO4p3Mhkvpfkonk6THHsAzHfWb3d2fbiqYWg/mFWollNMzdOXMHcguJ1QygcKn91mdLbW/BECO3/+VsqFCIAgkUYwNAcU+1uIG1FWPPC8cqGgTYzkLaADtWHr0yvTGTFHzS+B+1xHawjnRsqG3JM1z5iVjr5Hl7Ygu66TSkcauJn3VEzkNoSr0DMT4VUdhGIlydLIzz0OS/bCK2a1urwoj6yoWbtE3ekNzgS7jONm2YfyqTlXiV5ipDFICO8dAPqROaWEy8mw0Faxu/w3CT0Tu8GiNeGKwuyNhAuhV1oQALwywhk9v4MT8OAGZzbmfI2bVI5uyA6vKvFJHBR6K7sd1f+tUHiOSdS4=
1 change: 1 addition & 0 deletions PULL_REQUEST_TEMPLATE.md
Expand Up @@ -17,6 +17,7 @@
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Code Improvement (refactoring)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/classes/compiler.class.spec.ts
Expand Up @@ -8,12 +8,13 @@ import { expect } from "chai";
import { merge, Observable, of, Subscription } from "rxjs";
import { delay, mapTo } from "rxjs/operators";

import { Injector } from "super-injector";

import { LitComponent, LitModule, LitService } from "../..";
import { HttpNext, HttpRequest, HttpResponse } from "../../http";
import { DeleteMapping, GetMapping, PatchMapping, PostMapping, PutMapping } from "../../http/mappings";
import { LitComponentTest, TestBed } from "../../testing";
import { LitCompiler, ServiceCompiler } from "./compiler.class";
import { Injector } from "./injector.class";

describe("Class: Compiler", () => {

Expand Down
8 changes: 6 additions & 2 deletions lib/compiler/classes/compiler.class.ts
Expand Up @@ -6,13 +6,13 @@ import express = require("express");

import { Application, RequestHandler } from "express";

import { Injector } from "super-injector";
import { HttpResponse } from "../../http/classes/response.class";
import { RequestMethod } from "../../http/enums/request-method.enum";
import { HttpNext } from "../../http/models/next.model";
import { HttpServer } from "../../http/utils/http.utils";
import { DefaultComponent } from "../components/default.component";
import { CoreCompiler, ILitComponent, ILitModule } from "../utils/compiler.utils";
import { Injector } from "./injector.class";

export class ServiceCompiler extends CoreCompiler {

Expand Down Expand Up @@ -157,7 +157,11 @@ export class ServiceCompiler extends CoreCompiler {
* adds handler SomeComponent.someMethod
*/
private addRoute(method: RequestMethod, path: string, component: ILitComponent, name: string): void {
this.app[method]("/" + path, this.getHandler(component, name));

// method could be user input, sanitize it
const aMethod: string = method.toLowerCase();

this.app[aMethod]("/" + path, this.getHandler(component, name));
}

/**
Expand Down
133 changes: 0 additions & 133 deletions lib/compiler/classes/injector.class.spec.ts

This file was deleted.

63 changes: 0 additions & 63 deletions lib/compiler/classes/injector.class.ts

This file was deleted.

4 changes: 2 additions & 2 deletions lib/compiler/decorators/component.decorator.ts
@@ -1,8 +1,8 @@
/**
* component.decorator
*/
import { Injector } from "super-injector";
import { GenericClassDecorator, Type } from "../../utils/core.util";
import { Injector } from "./../classes/injector.class";

/**
* Classes decorated with the `@Service` decorator are stored within the injector and can be resolved by it.
Expand All @@ -11,6 +11,6 @@ import { Injector } from "./../classes/injector.class";
*/
export const LitComponent = (): GenericClassDecorator<Type<any>> => {
return (target: Type<any>): void => {
Injector.set(target);
Injector.set(target, {});
};
};
4 changes: 2 additions & 2 deletions lib/compiler/decorators/module.decorator.spec.ts
@@ -1,9 +1,9 @@
import { expect } from "chai";

import { Injector } from "super-injector";
import { LitModule } from "../..";
import { Injector } from "../classes/injector.class";

describe("Class: Injector", () => {
describe("ModuleDecorator", () => {

it("should allow passing exports to modules", () => {

Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/decorators/module.decorator.ts
@@ -1,9 +1,9 @@
/**
* module.decorator
*/
import { Injector } from "super-injector";
import { GenericClassDecorator, Type } from "../../utils/core.util";
import { ILitComponent, ILitModule } from "../utils/compiler.utils";
import { Injector } from "./../classes/injector.class";

/**
* @TODO move this into its own file!
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/decorators/service.decorator.ts
@@ -1,8 +1,8 @@
/**
* service.decorator
*/
import { Injector } from "super-injector";
import { GenericClassDecorator, Type } from "../../utils/core.util";
import { Injector } from "./../classes/injector.class";

/**
* Classes decorated with the `@Service` decorator are stored within the injector and can be resolved by it.
Expand All @@ -11,6 +11,6 @@ import { Injector } from "./../classes/injector.class";
*/
export const LitService = (): GenericClassDecorator<Type<any>> => {
return (target: Type<any>): void => {
Injector.set(target);
Injector.set(target, {});
};
};
31 changes: 30 additions & 1 deletion lib/http/classes/response.class.spec.ts
Expand Up @@ -3,7 +3,7 @@ import { expect } from "chai";
import { HttpRequest } from "..";
import { LitComponent } from "../..";
import { LitComponentTest, TestBed } from "../../testing";
import { GetMapping } from "../mappings";
import { GetMapping, RequestMapping } from "../mappings";
import { HttpResponse } from "./response.class";

describe("Class: HttpResponse", () => {
Expand Down Expand Up @@ -101,4 +101,33 @@ describe("Class: HttpResponse", () => {
done();
});
});

it("should support a custom mapping", (done) => {

@LitComponent()
class TestComponent {

@RequestMapping({
method: "post",
path: "someurl"
})
public customSuccess(req: HttpRequest, res: HttpResponse) {
res.success({
success: true
}, 200);
}
}

component = TestBed.start(TestComponent);
component
.post("/someurl")
.expect(200)
.expect((res: HttpRequest) => {
expect(res.body.toString()).to.equal({ success: true }.toString());
})
.end((err, res) => {
if (err) { return done(err); }
done();
});
});
});

0 comments on commit e74058d

Please sign in to comment.