Skip to content

Commit

Permalink
changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-appinventiv committed Feb 25, 2019
1 parent 20c8619 commit 22c4d4c
Show file tree
Hide file tree
Showing 41 changed files with 673 additions and 4,269 deletions.
12 changes: 12 additions & 0 deletions demo/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express from 'express';
import routes from './routes';

const app = express();

const PORT = 3000;

app.use('/', routes);

app.listen(PORT, function() {
console.log(`Listening on port ${PORT}`);
});
34 changes: 0 additions & 34 deletions demo/index.html

This file was deleted.

Binary file removed demo/public/logo.png
Binary file not shown.
Empty file removed demo/public/script.js
Empty file.
71 changes: 0 additions & 71 deletions demo/public/styles.css

This file was deleted.

9 changes: 9 additions & 0 deletions demo/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Router } from 'express';

import userRoutes from './user.routes';

const router = Router();

router.use(userRoutes.path, userRoutes.router);

export default router;
15 changes: 15 additions & 0 deletions demo/routes/user.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Resource } from '../../src';
import { Request, Response } from 'express';
import { UserSchema } from '../schema';

const resource = new Resource('user', new UserSchema());

resource.onCreate(function(req: Request, res: Response) {
console.log(req.url);
res.json({
message: 'User Created.',
result: null
});
});

export default resource;
2 changes: 2 additions & 0 deletions demo/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export * from './user.schema';
11 changes: 11 additions & 0 deletions demo/schema/user.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ResourceSchema, define, input } from '../../src';

export class UserSchema extends ResourceSchema {
constructor() {
super();
}
@define()
@input()
displayName: string = 'Default User';
}

25 changes: 10 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
{
"name": "epi",
"version": "1.0.0",
"description": "A express api documentor..",
"main": "dist/lts.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/akgurjar/express-api.git",
"main": "index.js",
"repository": "https://github.com/akgurjar/epi.git",
"author": "Ashish Gurjar <[email protected]>",
"license": "GPL-3.0",
"license": "GPL-3.0-or-later",
"private": false,
"scripts": {
"start": "webpack-dev-server",
"build": "webpack",
"lint": "tslint -p tsconfig.json"
"start": "ts-node-dev ./demo/app.ts"
},
"dependencies": {
"typescript": "^3.3.3333"
},
"devDependencies": {
"html-webpack-plugin": "^3.2.0",
"ts-loader": "^5.3.3",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
"express": "^4.16.4",
"ts-node-dev": "^1.0.0-pre.32",
"tslint": "^5.13.0"
}
}
Empty file removed src/helpers/index.ts
Empty file.
16 changes: 0 additions & 16 deletions src/helpers/parser.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@

// export * from './lib/index';
// import { body, method } from './lib/index';
export * from './lib';
71 changes: 71 additions & 0 deletions src/lib/decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

import { schemaSymbol } from './helper';

interface Options {
type?: 'boolean' | 'string' | 'number' | 'object' | 'array';
required?: boolean;
}
interface InputOptions extends Options {
operations: 'create' | 'update';
}
interface OutputOptions extends Options {
operations: 'detail' | 'list';
}

export function define(options?: Options) {
console.log(options);
return (target: any, propertyKey: PropertyKey) => {
// define schema container if not present
const propSchema = propertySchema(target, propertyKey);
// if () {}
if (!target.hasOwnProperty(propertyKey)) {
Object.defineProperty(target, propertyKey, { enumerable: true, writable: true });
console.info('Define > ', target, propertyKey);
}
};
}

/**
* @description This decorator mark a property as input when a resource is created or updated.
* @param operations Input operations on which this property act as input.
*/
export function input(options?: InputOptions) {
console.log(options);
return (target: any, propertyKey: PropertyKey) => {
// define schema container if not present
if (!target[schemaSymbol]) {
Object.defineProperty(target, schemaSymbol, {enumerable: false, value: {}});
}
if (!target.hasOwnProperty(propertyKey)) {
Object.defineProperty(target, propertyKey, { enumerable: true, writable: true });
console.log('Input > ', target, propertyKey);
}
};
}
export function output(options?: OutputOptions) {
console.log(options);
return (target: any, propertyKey: PropertyKey) => {
// define schema container if not present
if (!target[schemaSymbol]) {
Object.defineProperty(target, schemaSymbol, {enumerable: false, value: {}});
}
if (!target.hasOwnProperty(propertyKey)) {
Object.defineProperty(target, propertyKey, { enumerable: true, writable: true });
console.log('Output > ', target, propertyKey);
}
};
}


function propertySchema(target: any, propertyKey: PropertyKey) {
const schema = target[schemaSymbol] || {};
if (!schema[propertyKey]) {
schema[propertyKey] = {};
}
// Init Schema Container
if (!target[schemaSymbol]) {
Object.defineProperty(target, schemaSymbol, {enumerable: false, value: schema});
}
//
return schema[propertyKey];
}
27 changes: 0 additions & 27 deletions src/lib/functions/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const schemaSymbol: unique symbol = Symbol('Schema Container.');
6 changes: 3 additions & 3 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

export * from './types/index';
export * from './locations/index';
export * from './functions/index';
export * from './decorator';
export * from './schema';
export * from './resource';
45 changes: 0 additions & 45 deletions src/lib/locations/base.location.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/lib/locations/body.location.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/lib/locations/cookie.location.ts

This file was deleted.

Loading

0 comments on commit 22c4d4c

Please sign in to comment.