Skip to content

Commit

Permalink
Merge dcfe681 into cd9404f
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-casarrubias committed Mar 17, 2018
2 parents cd9404f + dcfe681 commit 3a79196
Show file tree
Hide file tree
Showing 29 changed files with 551 additions and 229 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: TYjasvZlZsWxcjMT0VnnwllCI24wpgOAd
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 [![Beerpay](https://beerpay.io/onixjs/core/badge.svg?style=beer)](https://beerpay.io/onixjs/core) [![Beerpay](https://beerpay.io/onixjs/core/make-wish.svg?style=flat)](https://beerpay.io/onixjs/core?focus=wish) [![Travis](https://img.shields.io/travis/onixjs/core.svg)](https://travis-ci.org/onixjs/core) [![npm (scoped)](https://img.shields.io/npm/v/@onixjs/core.svg)](npmjs.com/package/@onixjs/core) [![Coveralls github](https://img.shields.io/coveralls/github/onixjs/core/development.svg)](https://coveralls.io/github/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
22 changes: 20 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 All @@ -43,6 +43,7 @@
"LICENSE.md"
],
"license": "MIT",
"engines" : { "node" : ">=8.10.0" },
"dependencies": {
"reflect-metadata": "^0.1.12",
"uuid": "^3.2.1",
Expand All @@ -54,8 +55,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 +68,11 @@
},
"ava": {
"files": [
"dist/test/**/*.unit.js",
"dist/test/**/*.acceptance.js"
],
"source": [
"dist/test/**/*.unit.js",
"dist/test/**/*.acceptance.js"
],
"match": [],
Expand All @@ -84,5 +89,18 @@
"optionalDependencies": {
"bufferutil": "^3.0.3",
"utf-8-validate": "^4.0.0"
},
"nyc": {
"exclude": [
"coverage/**",
"dist/test/**",
"dist6/test/**",
"test/**",
"test{,-*}.js",
"**/test/**",
"**/*.test.js",
"**/__tests__/**",
"**/node_modules/**"
]
}
}
7 changes: 4 additions & 3 deletions src/core/acl.rule.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {IACLRule, AccessType, IRole} from '../index';
//import {IACLRule, AccessType, IRole} from '../index';
/**
* @class ACLRule
* @author Jonathan Casarrubias
* @deprecated
* @license MIT
* @description This class is required to create ACL for components
*/
*
export class ACLRule implements IACLRule {
access: AccessType = AccessType.DENY;
methods: string[];
Expand All @@ -14,4 +15,4 @@ export class ACLRule implements IACLRule {
Object.assign(this, input);
}
}
}
}*/
30 changes: 10 additions & 20 deletions src/core/app.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
AppConstructor,
} from '../interfaces';
import {OnixRPC, Injector} from '../core';
import {getObjectMethods} from '..';
import {getObjectMethods} from '../utils';
/**
* @class AppFactory
* @author Jonathan Casarrubias
Expand Down Expand Up @@ -40,25 +40,15 @@ export class AppFactory {
constructor(private Class: AppConstructor, private config: IAppConfig) {
// First of all create a new class instance
if (!this.app) this.app = new this.Class(new OnixRPC(this.Class));
// Then verify it is extending the base application
if (this.app.start && this.app.stop) {
// Now setup its modules
this.setupModules();
// Once finished send the schema back
// TODO: Potentially register to a provider in here
if (process.send)
process.send({
type: OperationType.APP_CREATE_RESPONSE,
message: this.schema(),
});
} else {
// If this is not a valid app, then throw an error
throw new Error(
`OnixJS: Invalid App "${
this.Class.name
}", it must extend from Application (import {Application} from '@onixjs/core')`,
);
}
// Now setup its modules
this.setupModules();
// Once finished send the schema back
// TODO: Potentially register to a provider in here
if (process.send)
process.send({
type: OperationType.APP_CREATE_RESPONSE,
message: this.schema(),
});
}
/**
* @method setupModules
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
4 changes: 2 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './app';
export * from './rpc';
export * from './roles';
export * from './acl.rule';
//xport * from './roles';
//export * from './acl.rule';
export * from './injector';
export * from './lifecycle';
export * from './connection';
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
15 changes: 8 additions & 7 deletions src/core/roles.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import {IRole, IComponentConfig, IACLRule, AccessType} from '../index';
/*import {IRole, IComponentConfig, IACLRule, AccessType} from '../index';
/**
* @deprecated (ALL OF THIS SHOULD BE MIGRATED TO IDENTITY PROVIDER)
* @namespace Roles
* @author Jonathan Casarrubias
* @license MIT
* @description System provided roles. These come out of the box
* and helps to avoid programming basic roles on each project.
*/
*
export namespace Roles {
/**
* @class Any
* @author Jonathan Casarrubias
* @license MIT
* @description This role is used to give public access for some of
* the methdos
*/
*
export class Any implements IRole {
/**
* @method verify
* @param request
* @description This method is used by the system as a hook to provide
* verification business logic. In this case any caller is allowed
*/
*
async access(name: string, request: any): Promise<boolean> {
console.log(request);
return new Promise<boolean>((resolve, reject) => resolve(true));
Expand All @@ -35,15 +36,15 @@ export class RoleMatch {
* @author Jonathan Casarrubias
* @description This method will access if a given method name is executable
* by the current caller.
*/
*
static async access(
name: string,
request: any,
config: IComponentConfig,
): 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 All @@ -69,4 +70,4 @@ export class RoleMatch {
}
});
}
}
}*/
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,
);
};
}

0 comments on commit 3a79196

Please sign in to comment.