Permalink
Browse files

clean up dependencies

  • Loading branch information...
1 parent c6e86e5 commit 8928889b28290877ac94a032d781033893bbaffe @mseemann committed Apr 29, 2016
View
@@ -40,7 +40,6 @@ typings/
#generated files
src/**/*.js
-test/**/*.js
*.js.map
*.d.ts
View
@@ -29,12 +29,10 @@
"author": "Michael Seemann",
"license": "MIT",
"dependencies": {
- "reflect-metadata": "0.1.2",
- "express": "^4.13.4"
+ "es7-reflect-metadata": "^1.6.0"
},
"devDependencies": {
"coveralls": "^2.11.9",
- "es6-shim": "0.35.0",
"jasmine-core": "2.4.1",
"jsdoc": "^3.4.0",
"karma": "^0.13.22",
@@ -1,27 +1,26 @@
-import 'reflect-metadata';
+
import { DecoratorParser } from './decorator-parser';
-import { BookService } from './../../test/test-classes';
import { RestDescriptor } from './descriptor';
+import { BookService } from './test-classes';
-describe('rest-descriptor-parser', () => {
- const bookService = new BookService();
+describe('rest-descriptor-parser', () => {
+ var bookService:BookService = null;
var descriptor:RestDescriptor = null;
- beforeEach( () => descriptor = DecoratorParser.parse(bookService));
+ beforeEach( () => {
+ bookService = new BookService();
+ descriptor = DecoratorParser.parse(bookService)
+ });
it('should create a RestDescriptor from the service', () => {
expect(descriptor).not.toBeNull();
})
it('should have a base path', () => {
- console.log('----');
- console.log(bookService);
- console.log(Reflect.getMetadataKeys(bookService.constructor));
- console.log('----X');
-
- //expect(descriptor.basePath).toBe('/books');
+ // TODO this will not work! what the hell is the reason why the meta data are lost if i use the class with metadata in different spec files!
+ // expect(descriptor.basePath).toBe('/books');
})
});
@@ -1,4 +1,4 @@
-import 'reflect-metadata';
+import 'es7-reflect-metadata';
import {RestDescriptor, MethodDescriptor} from "./descriptor";
import * as namings from './namings';
@@ -9,16 +9,12 @@ class Parser {
constructor(){
}
- parseBasePath(service: any) : string | void {
- console.log(service);
- console.log(Reflect.getMetadataKeys(service.constructor));
+ parseBasePath(service: Object) : string | void {
let path = Reflect.getMetadata(namings.buildFullName((namings.path)), service.constructor);
- console.log(path);
return path ? path : null;
}
parseMethodDescriptions(service): MethodDescriptor[] {
-
return [];
}
@@ -1,13 +1,12 @@
-import 'reflect-metadata';
import { ParamDescription } from './decorators';
import * as namings from './namings';
-import { BookService } from './../../test/test-classes';
-
-
+import { BookService } from './test-classes';
+import { DecoratorParser } from './decorator-parser';
describe('rest-decorator', () => {
const bookService = new BookService();
+ const descriptor = DecoratorParser.parse(bookService)
describe('http method decorator', () => {
@@ -31,6 +30,13 @@ describe('rest-decorator', () => {
describe('path decorator', () => {
it('should have a Path decorator at the class', () => {
+
+ console.log('y----y');
+ console.log(bookService);
+ console.log(Reflect.getMetadataKeys(bookService.constructor));
+ console.log(Reflect.getMetadataKeys(bookService.allBooks));
+ console.log('y----Xy');
+
expect(Reflect.getMetadata(namings.buildFullName((namings.path)), bookService.constructor)).toBe('/books');
})
@@ -71,4 +77,17 @@ describe('rest-decorator', () => {
expect(headerParams).toContain({pathParam:'token', index: 1});
})
})
+
+
+ describe('RestDescriptor', () => {
+
+ it('should create a RestDescriptor from the service', () => {
+ expect(descriptor).not.toBeNull();
+ })
+
+ it('should have a base path', () => {
+ expect(descriptor.basePath).toBe('/books');
+ })
+ })
+
});
@@ -1,4 +1,4 @@
-import 'reflect-metadata';
+import 'es7-reflect-metadata';
import * as namings from './namings';
@@ -45,7 +45,9 @@ export function DELETE() { return createHttpMethodFunction(namings.deleteMethod)
* @returns the decorated function
*/
export function Path (path:string) : Function {
+
return function(target: Function, propertyKey: string, descriptor: PropertyDescriptor){
+ console.log('add path '+ path+ ' to '+target);
if(!propertyKey && !descriptor){
// add meta data to the class itself - e.g. target is the constructor and propertyKey and descriptor are undefined
return Reflect.defineMetadata(namings.buildFullName(namings.path), path, target);
@@ -1,4 +1,5 @@
-import {GET, POST, PUT, DELETE, Path, PathParam, HeaderParam } from './../src/core/decorators';
+
+import {GET, POST, PUT, DELETE, Path, PathParam, HeaderParam } from './decorators';
export class Book {
id:number;
View
@@ -1,5 +1,5 @@
-
export { GET, POST, PUT, DELETE, Path, PathParam, HeaderParam } from './core/decorators';
-export { JsRestify } from './js-restify-express';
+export { DecoratorParser } from './core/decorator-parser';
+export { RestDescriptor, MethodDescriptor } from './core/descriptor';
@@ -1,50 +0,0 @@
-
-import 'reflect-metadata';
-import * as express from "express";
-
-export class JsRestify {
-
- static findClassPath(anObject:Object) : string {
- var path = '';
- console.log(anObject);
- let keys: any[] = Reflect.getMetadataKeys(anObject.constructor);
- keys.forEach((k)=>{
- console.log('suche key',k);
- if (k==='jsrestful::Path') {
- path = Reflect.getMetadata(k, anObject.constructor);
- }
- });
- // TODO make sure path starts with /
- return '/'+path;
- }
-
- static register(app: express.Application, anObject:Object){
- let router = express.Router();
-
- for (let name of Object.getOwnPropertyNames(Object.getPrototypeOf(anObject))) {
-
- let method = anObject[name];
-
- if (method === anObject.constructor) continue;
- console.log(method, name);
-
- let methodKeys: any[] = Reflect.getMetadataKeys(method);
- methodKeys.forEach((k)=>{
- console.log(k, Reflect.getMetadata(k, method));
- if(k==='jsrestful::GET'){
- router.get('/:id', (req: express.Request, res: express.Response, next) => {
- let result = method();
- console.log( typeof result, name );
- console.log(Reflect.getMetadata("jsrestful::PathParam", anObject, name));
- res.json(result);
- });
- }
- })
- }
-
-
- let classPath = this.findClassPath(anObject);
- console.log(`register classPath: ${classPath} at router base path`);
- app.use(classPath, router);
- }
-}
@@ -0,0 +1,50 @@
+//
+// import 'reflect-metadata';
+// import * as express from "express";
+//
+// export class JsRestify {
+//
+// static findClassPath(anObject:Object) : string {
+// var path = '';
+// console.log(anObject);
+// let keys: any[] = Reflect.getMetadataKeys(anObject.constructor);
+// keys.forEach((k)=>{
+// console.log('suche key',k);
+// if (k==='jsrestful::Path') {
+// path = Reflect.getMetadata(k, anObject.constructor);
+// }
+// });
+// // TODO make sure path starts with /
+// return '/'+path;
+// }
+//
+// static register(app: express.Application, anObject:Object){
+// let router = express.Router();
+//
+// for (let name of Object.getOwnPropertyNames(Object.getPrototypeOf(anObject))) {
+//
+// let method = anObject[name];
+//
+// if (method === anObject.constructor) continue;
+// console.log(method, name);
+//
+// let methodKeys: any[] = Reflect.getMetadataKeys(method);
+// methodKeys.forEach((k)=>{
+// console.log(k, Reflect.getMetadata(k, method));
+// if(k==='jsrestful::GET'){
+// router.get('/:id', (req: express.Request, res: express.Response, next) => {
+// let result = method();
+// console.log( typeof result, name );
+// console.log(Reflect.getMetadata("jsrestful::PathParam", anObject, name));
+// res.json(result);
+// });
+// }
+// })
+// }
+//
+//
+// let classPath = this.findClassPath(anObject);
+// console.log(`register classPath: ${classPath} at router base path`);
+// app.use(classPath, router);
+// }
+// }
View
@@ -20,7 +20,6 @@
"src/core/descriptor.ts",
"src/core/decorator-parser.ts",
"src/core/decorator-parser.spec.ts",
- "test/test-classes.ts",
- "src/js-restify-express.ts"
+ "src/core/test-classes.ts"
]
}
View
@@ -1,15 +1,8 @@
{
"version": false,
"ambientDependencies": {
- "express": "registry:dt/express#4.0.0+20160317120654",
- "serve-static": "registry:dt/serve-static#0.0.0+20160317120654",
- "express-serve-static-core": "registry:dt/express-serve-static-core#0.0.0+20160322035842",
- "mime": "registry:dt/mime#0.0.0+20160316155526",
- "node": "registry:dt/node#4.0.0+20160412142033",
- "reflect-metadata": "github:rbuckton/ReflectDecorators/reflect-metadata.d.ts#1affc8fcd1301caac47602e3738b057ecfd88830"
},
"ambientDevDependencies": {
- "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4"
}
}

0 comments on commit 8928889

Please sign in to comment.