Skip to content

Commit

Permalink
Merge c539a85 into ff0fde5
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-casarrubias committed Mar 16, 2018
2 parents ff0fde5 + c539a85 commit c025b9f
Show file tree
Hide file tree
Showing 25 changed files with 590 additions and 174 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
.nyc_output
coverage
node_modules
documentation
dist
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "9"
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
OnixJS - FrameWork
OnixJS - FrameWork [![Travis](https://img.shields.io/travis/onixjs/core.svg)](https://github.com/onixjs/core) [![Coveralls github](https://img.shields.io/coveralls/github/onixjs/core/development.svg)](https://github.com/onixjs/core)
================
![alt text](https://raw.githubusercontent.com/onixjs/core/master/misc/onix-splash.png "OnixJS")
The High-Performance SOA Real-Time Framework for Node.JS.

> **Disclaimer**: This framework is in active development and won't be ready for production until we reach release candidate.
- **Alpha release date**: Feb 2018
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onixjs/core",
"version": "1.0.0-alpha.6",
"version": "1.0.0-alpha.7",
"description": "The High-Performance SOA Real-Time Framework for Node.JS",
"main": "dist/src/index.js",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"tslint:fix": "npm run lint -- --fix",
"prepublish": "npm run build",
"pretest": "npm run lint:fix && npm run clean && npm run build",
"test": "ava",
"test": "nyc ava && nyc report --reporter=text-lcov | coveralls",
"posttest": "npm run lint",
"serve:docs": "npm run build && node ./dist/documentation"
},
Expand Down Expand Up @@ -54,8 +54,10 @@
"@types/node": "^9.4.6",
"@types/uws": "^0.13.1",
"ava": "^0.25.0",
"coveralls": "^3.0.0",
"finalhandler": "^1.1.0",
"mongoose": "^5.0.4",
"nyc": "^11.6.0",
"prettier": "^1.10.2",
"serve-static": "^1.13.1",
"tslint": "^5.9.1",
Expand All @@ -65,9 +67,11 @@
},
"ava": {
"files": [
"dist/test/**/*.unit.js",
"dist/test/**/*.acceptance.js"
],
"source": [
"dist/test/**/*.unit.js",
"dist/test/**/*.acceptance.js"
],
"match": [],
Expand Down
37 changes: 22 additions & 15 deletions src/core/app.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,38 @@ export class AppServer {
case OperationType.APP_START:
// Start WebSocket Server
await Promise.all([
// Start up Micra WebSocket Server
new Promise<WebSocket.Server>(resolve => {
this.server = new WebSocket.Server(
{host: this.config.host, port: this.config.port},
() => resolve(),
);
new Promise((resolve, reject) => {
// Start up Micra WebSocket Server
if (!this.config.disableNetwork) {
this.server = new WebSocket.Server(
{host: this.config.host, port: this.config.port},
() => resolve(),
);
// Wait for client connections
this.server.on(
'connection',
(ws: WebSocket) =>
new ClientConnection(ws, this.responser, this.streamer),
);
} else {
resolve();
}
}),
// Start up application
this.factory.app.start(),
]);
// Wait for client connections
this.server.on(
'connection',
(ws: WebSocket) =>
new ClientConnection(ws, this.responser, this.streamer),
);
if (process.send)
process.send({type: OperationType.APP_START_RESPONSE});
break;
// Event sent from the broker when stoping a project
case OperationType.APP_STOP:
const close = async () =>
new Promise((resolve, reject) => this.server.close(resolve));
// If network enabled, turn off the server
if (!this.config.disableNetwork) {
const close = async () =>
new Promise((resolve, reject) => this.server.close(resolve));
await close();
}
await this.factory.app.stop();
await close();
if (process.send) process.send({type: OperationType.APP_STOP_RESPONSE});
break;
// Event sent from caller -> broker -> currentApp
Expand Down
8 changes: 5 additions & 3 deletions src/core/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Injector {
if (
Reflect.hasMetadata(
ReflectionKeys.INJECTABLE_MODEL,
injectable.Class,
injectable.Class.prototype,
)
)
Object.defineProperty(instance, prop, {
Expand All @@ -100,7 +100,7 @@ export class Injector {
if (
Reflect.hasMetadata(
ReflectionKeys.INJECTABLE_SERVICE,
injectable.Class,
injectable.Class.prototype,
)
)
Object.defineProperty(instance, prop, {
Expand Down Expand Up @@ -129,7 +129,7 @@ export class Injector {
// Get model configuration
const modelConfig: IModelConfig = Reflect.getMetadata(
ReflectionKeys.INJECTABLE_MODEL,
Model,
Model.prototype,
);
// If there is no config this is an invalid model
if (!modelConfig)
Expand All @@ -142,6 +142,8 @@ export class Injector {
datasource = this.get(modelConfig.datasource.name);
} else {
datasource = new modelConfig.datasource();
// TODO: Validate it is a registered datasource
// Or problems will arise
datasource.connect();
this.set(modelConfig.datasource.name, datasource);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class RoleMatch {
): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
// First filter any rule specified for this method
const rules: IACLRule[] = config.ACL.filter(
const rules: IACLRule[] = (config.ACL || []).filter(
(rule: IACLRule) =>
rule.methods.indexOf(name) >= 0 && rule.access === AccessType.ALLOW,
);
Expand Down
6 changes: 5 additions & 1 deletion src/decorators/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {IDataSource, ReflectionKeys} from '../interfaces';
*/
export function DataSource() {
return (target: new () => IDataSource) => {
Reflect.defineMetadata(ReflectionKeys.INJECTABLE_DATASOURCE, true, target);
Reflect.defineMetadata(
ReflectionKeys.INJECTABLE_DATASOURCE,
true,
target.prototype,
);
};
}
124 changes: 65 additions & 59 deletions src/decorators/inject.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,69 @@
import {Constructor, ReflectionKeys} from '../interfaces';
/**
* @function InjectModel
* @author Jonathan Casarrubias
* @param Class
* @license MIT
* @description Decorator used to inject models
*/
export function InjectModel(Class: Constructor) {
return (target: any, property: string) => {
// Verify the class is actually a model class
if (!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_MODEL, Class)) {
throw new Error(
`ONIXJS Error: Invalid injectable model class ${
Class.name
}, it is not a valid model.`,
export namespace Inject {
/**
* @function Model
* @author Jonathan Casarrubias
* @param Class
* @license MIT
* @description Decorator used to inject models
*/
export function Model(Class: Constructor) {
return (target: any, property: string) => {
// Verify the class is actually a model class
if (
!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_MODEL, Class.prototype)
) {
throw new Error(
`ONIXJS Error: Invalid injectable model class ${
Class.name
}, it is not a valid model.`,
);
}
// Temporaly intialize the property otherwise will be "invisible"
// By the moment we iterate over these properties in a future
target[property] = true;
// Adding this class as possible injectable class.
// System will verify if this class is actually installed within the module.
// It is a request because not necessarily an instance will be injected.
Reflect.defineMetadata(
ReflectionKeys.INJECT_REQUEST,
{Class, type: 'model'},
target,
property,
);
}
// Temporaly intialize the property otherwise will be "invisible"
// By the moment we iterate over these properties in a future
target[property] = true;
// Adding this class as possible injectable class.
// System will verify if this class is actually installed within the module.
// It is a request because not necessarily an instance will be injected.
Reflect.defineMetadata(
ReflectionKeys.INJECT_REQUEST,
{Class, type: 'model'},
target,
property,
);
};
}
/**
* @function InjectService
* @author Jonathan Casarrubias
* @param Class
* @license MIT
* @description Decorator used to inject services
*/
export function InjectService(Class: Constructor) {
return (target: any, property: string) => {
// Verify the class is actually a model class
if (!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_SERVICE, Class)) {
throw new Error(
`ONIXJS Error: Invalid injectable service class ${
Class.name
}, it is not a valid service.`,
};
}
/**
* @function Service
* @author Jonathan Casarrubias
* @param Class
* @license MIT
* @description Decorator used to inject services
*/
export function Service(Class: Constructor) {
return (target: any, property: string) => {
// Verify the class is actually a model class
if (
!Reflect.hasMetadata(ReflectionKeys.INJECTABLE_SERVICE, Class.prototype)
) {
throw new Error(
`ONIXJS Error: Invalid injectable service class ${
Class.name
}, it is not a valid service.`,
);
}
// Temporaly intialize the property otherwise will be "invisible"
// By the moment we iterate over these properties in a future
target[property] = true;
// Adding this class as possible injectable class.
// System will verify if this class is actually installed within the module.
// It is a request because not necessarily an instance will be injected.
Reflect.defineMetadata(
ReflectionKeys.INJECT_REQUEST,
{Class, type: 'service'},
target,
property,
);
}
// Temporaly intialize the property otherwise will be "invisible"
// By the moment we iterate over these properties in a future
target[property] = true;
// Adding this class as possible injectable class.
// System will verify if this class is actually installed within the module.
// It is a request because not necessarily an instance will be injected.
Reflect.defineMetadata(
ReflectionKeys.INJECT_REQUEST,
{Class, type: 'service'},
target,
property,
);
};
};
}
}
6 changes: 5 additions & 1 deletion src/decorators/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {ReflectionKeys, IModelConfig, Constructor} from '../index';
*/
export function Model(config: IModelConfig) {
return (target: Constructor) => {
Reflect.defineMetadata(ReflectionKeys.INJECTABLE_MODEL, config, target);
Reflect.defineMetadata(
ReflectionKeys.INJECTABLE_MODEL,
config,
target.prototype,
);
};
}
Loading

0 comments on commit c025b9f

Please sign in to comment.