Skip to content

Commit

Permalink
Release 1.0.0-alpha.7.2 WIP
Browse files Browse the repository at this point in the history
- Increased test coverage
  • Loading branch information
Jonathan committed Mar 21, 2018
1 parent d74d94a commit 0ba6229
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 110 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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)
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) [![Coverage Status](https://coveralls.io/repos/github/onixjs/core/badge.svg?branch=development)](https://coveralls.io/github/onixjs/core?branch=development) [![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)](http://npmjs.com/package/@onixjs/core)
================
![alt text](https://raw.githubusercontent.com/onixjs/core/master/misc/onix-splash.png "OnixJS")

Expand Down Expand Up @@ -63,8 +63,8 @@ $ npm install && npm run test
## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars0.githubusercontent.com/u/1533239?v=3" width="100px;"/><br /><sub>Jonathan Casarrubias</sub>](http://mean.expert/)<br />[💻](https://github.com/onixjs/core/commits?author=jonathan-casarrubias) | | | | | |
| :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars0.githubusercontent.com/u/1533239?v=3" width="100px;"/><br /><sub>Jonathan Casarrubias</sub>](http://mean.expert/)<br />[💻](https://github.com/onixjs/core/commits?author=jonathan-casarrubias) |
| :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"reflect-metadata": "^0.1.12",
"uuid": "^3.2.1",
"@onixjs/sdk": "^1.0.0-alpha.4.1",
"uws": "^9.14.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/core/app.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Constructor,
AppConstructor,
} from '../interfaces';
import {OnixRPC, Injector} from '../core';
import {Injector} from '../core';
import {getObjectMethods} from '../utils';
/**
* @class AppFactory
Expand Down Expand Up @@ -39,7 +39,7 @@ 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));
if (!this.app) this.app = new this.Class();
// Now setup its modules
this.setupModules();
// Once finished send the schema back
Expand Down
8 changes: 5 additions & 3 deletions src/core/app.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ export class AppServer {
apps.map(
(name: string) =>
new Promise<boolean>(async (resolve, reject) => {
const result: boolean = await this.factory.app.rpc
.topic(`${name}.isAlive`)
.call();
const result: boolean = await this.responser.process(<ICall>{
uuid: '1',
rpc: `${name}.isAlive`,
request: {metadata: {}, payload: {}},
});
resolve(result);
}),
),
Expand Down
16 changes: 8 additions & 8 deletions src/core/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IApp, OnixRPC, IAppConfig, IModuleDirectory} from '../index';
import {IApp, IAppConfig, IModuleDirectory} from '../index';
/**
* @class App
* @author Jonathan Casarrubias
Expand Down Expand Up @@ -27,14 +27,14 @@ export class Application implements IApp {
* Receives optional configurations as parameter.
* Otherwise will use platform default configuration.
*/
constructor(public rpc: OnixRPC) {}
constructor() {}
/**
* @method start
* @description Mock start method, this might be replaced
* by custom App level functionality
*/
async start(): Promise<null> {
return new Promise<null>((resolve, reject) => {
async start(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
Object.keys(this.modules).forEach((moduleName: string) => {
Object.keys(this.modules[moduleName]).forEach(
(componentName: string) => {
Expand All @@ -46,16 +46,16 @@ export class Application implements IApp {
},
);
});
resolve();
resolve(true);
});
}
/**
* @method stop
* @description Mock stop method, this might be replaced
* by custom App level functionality
*/
async stop(): Promise<null> {
return new Promise<null>((resolve, reject) => {
async stop(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
Object.keys(this.modules).forEach((moduleName: string) => {
Object.keys(this.modules[moduleName]).forEach(
(componentName: string) => {
Expand All @@ -68,7 +68,7 @@ export class Application implements IApp {
},
);
});
resolve();
resolve(true);
});
}
}
4 changes: 3 additions & 1 deletion src/core/call.streamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export class CallStreamer {
const segments: string[] = message.rpc.split('.');
// Component level method, RPC Exposed
if (segments.length !== 4) {
return handler(new Error(`RPC Call is invalid ${message.rpc}`));
return handler(
new Error(`OnixJS Error: RPC Call is invalid "${message.rpc}"`),
);
}
// Execute main hook, might be app/system or module level.
this.factory.app.modules[segments[1]][segments[2]][segments[3]](handler);
Expand Down
3 changes: 0 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export * from './app';
export * from './rpc';
//xport * from './roles';
//export * from './acl.rule';
export * from './injector';
export * from './lifecycle';
export * from './connection';
Expand Down
70 changes: 0 additions & 70 deletions src/core/rpc.ts

This file was deleted.

12 changes: 2 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
OnixConfig,
} from './interfaces';
import {SchemaProvider} from './core/schema.provider';
import * as uuid from 'uuid';
// Export all core modules & interfaces
export * from './core';
export * from './utils';
export * from './decorators';
export * from './interfaces';
import {Utils} from '@onixjs/sdk/dist/utils';
/**
* @class OnixJS
* @author Jonathan Casarrubias <gh: mean-expert-official>
Expand Down Expand Up @@ -148,14 +148,6 @@ export class OnixJS {
this._apps[name].config = operation.message;
resolve(this._apps[name].process);
break;
case OperationType.ONIX_REMOTE_CALL_PROCEDURE:
this._apps[name].process.send(
await this.coordinate(
(<ICall>operation.message).rpc,
(<ICall>operation.message).request,
),
);
break;
}
},
);
Expand Down Expand Up @@ -185,7 +177,7 @@ export class OnixJS {
return new Promise<IAppOperation>((resolve, reject) => {
console.log('Onix server got remote call procedure');
const operation: IAppOperation = {
uuid: uuid(),
uuid: Utils.uuid(),
type: OperationType.ONIX_REMOTE_CALL_PROCEDURE,
message: <ICall>{
rpc,
Expand Down
8 changes: 3 additions & 5 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ChildProcess} from 'child_process';
import {OnixRPC} from '../index';
import * as http from 'http';
/**
* @interface IAppConfig
Expand All @@ -20,7 +19,7 @@ export interface IAppConfig extends DomainConfig {
* that receives a OnixRPC class.
*/
export interface AppConstructor {
new (rpc: OnixRPC): IApp;
new (): IApp;
}
/**
* @interface IModuleConfig
Expand Down Expand Up @@ -111,9 +110,8 @@ export interface IInjectable {
*/
export interface IApp {
modules: IModuleDirectory;
rpc: OnixRPC;
start(): Promise<null>;
stop(): Promise<null>;
start(): Promise<boolean>;
stop(): Promise<boolean>;
isAlive(): boolean;
}
/**
Expand Down
72 changes: 70 additions & 2 deletions test/onix.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const pkg = require('../../package.json');
const cwd = path.join(process.cwd(), 'dist', 'test');
import * as WebSocket from 'uws';
import {IAppConfig, ICall} from '../src/interfaces';
import {OnixClient, AppReference, ComponentReference} from '@onixjs/sdk';
import {NodeJS} from '@onixjs/sdk/dist/core/node.adapters';
/**
* Test Onix Version
**/
Expand Down Expand Up @@ -62,7 +64,7 @@ test('Onix app greeter', async t => {
* Test Onix RPC component methods
**/
test('Onix rpc component methods from server', async t => {
const onix: OnixJS = new OnixJS({cwd, port: 8082});
const onix: OnixJS = new OnixJS({cwd, port: 8085});
await onix.load('TodoApp@todo2.app');
await onix.start();
const todo: TodoModel = new TodoModel();
Expand All @@ -86,7 +88,7 @@ test('Onix rpc component methods from server', async t => {
* Test Onix RPC component methods
**/
test('Onix rpc component methods from client', async t => {
const onix: OnixJS = new OnixJS({cwd, port: 8081});
const onix: OnixJS = new OnixJS({cwd, port: 8086});
await onix.load('TodoApp@todo.app');
await onix.start();
// Websocket should be available now
Expand Down Expand Up @@ -122,3 +124,69 @@ test('Onix rpc component methods from client', async t => {
);
});
});

/**
* Test Onix RPC component stream
***/
test('Onix rpc component stream', async t => {
const text: string = 'Hello SDK World';
const onix: OnixJS = new OnixJS({cwd, port: 8087});
await onix.load('TodoApp@todo3.app');
await onix.start();
// Websocket should be available now
const client: OnixClient = new OnixClient({
host: 'http://127.0.0.1',
port: 8087,
adapters: {
http: NodeJS.HTTP,
websocket: NodeJS.WebSocket,
},
});
// Init SDK
await client.init();
// Create a TodoApp Reference
const TodoAppRef: AppReference | Error = await client.AppReference('TodoApp');
// Verify we actually got a Reference and not an Error
if (TodoAppRef instanceof AppReference) {
const componentRef: ComponentReference = TodoAppRef.Module(
'TodoModule',
).Component('TodoComponent');
// Set on create listener
componentRef.Method('onCreate').stream(data => {
console.log('HELLO STREAM: ', data);
t.is(data.text, text);
});
// Send new todo
const result = await componentRef.Method('addTodo').call({text});
console.log('HELLO RESULT: ', result);
t.is(result.text, text);
}
console.log('HERE?');
await onix.stop();
/* Init SDK
await client.init();
// Create a TodoApp Reference
const TodoAppRef: AppReference | Error = await client.AppReference('TodoApp');
// Verify we actually got a Reference and not an Error
if (TodoAppRef instanceof AppReference) {
const componentRef: ComponentReference = TodoAppRef.Module(
'TodoModule',
).Component('TodoComponent');
// Set on create listener
componentRef.Method('onCreate').stream(data => {
console.log('HELLO STREAM: ', data);
t.is(data.text, text);
onix
.stop()
.then(() => {
console.log('STOPPED');
})
.catch(() => {});
});
console.log('SENDING: ');
// Create a new todo
await componentRef.Method('addTodo').call({text});
} else {
throw TodoAppRef;
}*/
});
Loading

0 comments on commit 0ba6229

Please sign in to comment.