Compare commits

..

7 Commits

Author SHA1 Message Date
8830b825ac 1.0.33 2019-04-11 18:32:36 +02:00
123324bf43 fix(core): update 2019-04-11 18:32:36 +02:00
4761ff31cf 1.0.32 2019-04-11 18:31:21 +02:00
430c3ea13a fix(core): update 2019-04-11 18:31:21 +02:00
6dd3782b0d 1.0.31 2019-04-11 18:16:14 +02:00
06aa721247 1.0.30 2019-04-11 17:52:02 +02:00
f728c56016 fix(core): update 2019-04-11 17:52:01 +02:00
15 changed files with 85 additions and 39 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartuniverse", "name": "@pushrocks/smartuniverse",
"version": "1.0.29", "version": "1.0.33",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartuniverse", "name": "@pushrocks/smartuniverse",
"version": "1.0.29", "version": "1.0.33",
"private": false, "private": false,
"description": "messaging service for your micro services", "description": "messaging service for your micro services",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -20,6 +20,10 @@ messaging service for micro services
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
### What does smartuniverse all about?
Think WhatsApp, but for your microservices architecture. It allows your services to securely talk to each other in **private, shielded channels** without having to expose anything to the outside world. This allows the use of **reactive programming across your entire stack**.
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)

View File

@ -7,4 +7,5 @@ export * from './smartuniverse.classes.universe';
export * from './smartuniverse.classes.universecache'; export * from './smartuniverse.classes.universecache';
export * from './smartuniverse.classes.universechannel'; export * from './smartuniverse.classes.universechannel';
export * from './smartuniverse.classes.universemessage'; export * from './smartuniverse.classes.universemessage';
export * from './smartuniverse.interfaces';
export * from './interfaces';

View File

@ -0,0 +1,15 @@
export interface IServerGetMessagesRequestBody {
channel: string;
topic?: string;
youngerThan: number;
}
/**
* the interface for a standard request
*/
export interface IServerPutMessageRequestBody {
channel: string;
passphrase: string;
message: string;
payload: any;
}

3
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './http.interfaces';
export * from './universechannel.interfaces';
export * from './universemessage.interfaces';

View File

@ -0,0 +1 @@
export interface IUniverseChannel {}

View File

@ -0,0 +1 @@
export interface IUniverseMessage {}

View File

@ -5,10 +5,10 @@ import { Observable } from 'rxjs';
import { Smartsocket, SmartsocketClient } from '@pushrocks/smartsocket'; import { Smartsocket, SmartsocketClient } from '@pushrocks/smartsocket';
import * as url from 'url'; import * as url from 'url';
import * as interfaces from './interfaces';
import { import {
ClientUniverseChannel, ClientUniverseChannel,
IServerGetMessagesRequestBody,
IServerPutMessageRequestBody,
UniverseMessage UniverseMessage
} from './'; } from './';
@ -32,17 +32,18 @@ export class ClientUniverse {
} }
public async sendMessage(messageArg, payloadArg) { public async sendMessage(messageArg, payloadArg) {
const requestBody = { const requestBody: interfaces.IUniverseMessage = {
message: messageArg, message: messageArg,
payload: payloadArg payload: payloadArg
}; };
const requestBodyString = JSON.stringify(requestBody);
// TODO: User websocket connection if available // TODO: User websocket connection if available
await plugins.smartrequest.postJson(this.options.serverAddress, { const response = await plugins.smartrequest.postJson(`${this.options.serverAddress}/sendmessage` , {
requestBody requestBody: requestBodyString
}); });
} }
public async getChannel(channelName: string): Promise<ClientUniverseChannel> { public async getChannel(channelName: string, passphrase): Promise<ClientUniverseChannel> {
await this.checkConnection(); await this.checkConnection();
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel( const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
this, this,

View File

@ -1,8 +1,9 @@
import * as plugins from './smartuniverse.plugins'; import * as plugins from './smartuniverse.plugins';
import * as interfaces from './interfaces';
import { ClientUniverse, IUniverseChannel } from './'; import { ClientUniverse } from './';
export class ClientUniverseChannel implements IUniverseChannel { export class ClientUniverseChannel implements interfaces.IUniverseChannel {
// ====== // ======
// STATIC // STATIC
// ====== // ======

View File

@ -1,15 +1,21 @@
import * as plugins from './smartuniverse.plugins'; import * as plugins from './smartuniverse.plugins';
import { IUniverseMessage } from './'; import * as interfaces from './interfaces';
export class ClientUniverseMessage implements IUniverseMessage { export class ClientUniverseMessage implements interfaces.IUniverseMessage {
// ====== // ======
// STATIC // STATIC
// ====== // ======
createMessage(messageArg: string, payloadArg: any) {} public static createMessageFromPayload(messageArg: string, payloadArg: any) {
};
// ======== // ========
// INSTANCE // INSTANCE
// ======== // ========
constructor(messageArg, payloadArg) {} constructor(messageArg, payloadArg) {}
getAsJsonForPayload () {
}
} }

View File

@ -5,25 +5,13 @@ import { UniverseCache, UniverseChannel, UniverseMessage } from './';
import * as paths from './smartuniverse.paths'; import * as paths from './smartuniverse.paths';
import * as interfaces from './interfaces';
export interface ISmartUniverseConstructorOptions { export interface ISmartUniverseConstructorOptions {
messageExpiryInMilliseconds: number; messageExpiryInMilliseconds: number;
} }
export interface IServerGetMessagesRequestBody {
channel: string;
topic?: string;
youngerThan: number;
}
/**
* the interface for a standard request
*/
export interface IServerPutMessageRequestBody {
channel: string;
passphrase: string;
message: string;
payload: any;
}
/** /**
* main class that setsup a Universe * main class that setsup a Universe
@ -35,9 +23,16 @@ export class Universe {
// options // options
private options: ISmartUniverseConstructorOptions; private options: ISmartUniverseConstructorOptions;
// Store version handling /**
* stores the version of the universe server running
* this is done since the version is exposed through the api and multiple fs actions are avoided this way.
*/
private universeVersionStore: string; private universeVersionStore: string;
private get universeVersion() {
/**
* get the currently running version of smartuniverse
*/
public get universeVersion() {
if (this.universeVersionStore) { if (this.universeVersionStore) {
return this.universeVersionStore; return this.universeVersionStore;
} else { } else {
@ -47,7 +42,14 @@ export class Universe {
} }
} }
/**
* the smartexpress server used
*/
private smartexpressServer: plugins.smartexpress.Server; private smartexpressServer: plugins.smartexpress.Server;
/**
* the smartsocket used
*/
private smartsocket: plugins.smartsocket.Smartsocket; private smartsocket: plugins.smartsocket.Smartsocket;
constructor(optionsArg: ISmartUniverseConstructorOptions) { constructor(optionsArg: ISmartUniverseConstructorOptions) {
@ -59,14 +61,14 @@ export class Universe {
* adds a channel to the Universe * adds a channel to the Universe
*/ */
public async addChannel(nameArg: string, passphraseArg: string) { public async addChannel(nameArg: string, passphraseArg: string) {
const newChannel = new UniverseChannel(this.universeCache, nameArg, passphraseArg); const newChannel = UniverseChannel.createChannel(this.universeCache, nameArg, passphraseArg);
this.universeCache.channelMap.add(newChannel);
} }
/** /**
* initiates a server * initiates a server
*/ */
public async initServer(portArg: number | string) { public async initServer(portArg: number | string) {
// lets create the base smartexpress server
this.smartexpressServer = new plugins.smartexpress.Server({ this.smartexpressServer = new plugins.smartexpress.Server({
cors: true, cors: true,
defaultAnswer: async () => { defaultAnswer: async () => {
@ -76,31 +78,44 @@ export class Universe {
port: portArg port: portArg
}); });
// lets create the http request route
this.smartexpressServer.addRoute('/sendmessage', new Handler('POST', async (req, res) => {
this.universeCache.addMessage(req.body);
}));
// add websocket upgrade // add websocket upgrade
this.smartsocket = new plugins.smartsocket.Smartsocket({ this.smartsocket = new plugins.smartsocket.Smartsocket({
port: 12345 // fix this within smartsocket port: 12345 // fix this within smartsocket
}); });
// add a role for the clients
const ClientRole = new plugins.smartsocket.SocketRole({ const ClientRole = new plugins.smartsocket.SocketRole({
name: 'clientuniverse', name: 'clientuniverse',
passwordHash: 'clientuniverse' // authentication happens on another level passwordHash: 'clientuniverse' // authentication happens on another level
}); });
// add the role to smartsocket
this.smartsocket.addSocketRoles([ClientRole]); this.smartsocket.addSocketRoles([ClientRole]);
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({ const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
allowedRoles: [ClientRole], allowedRoles: [ClientRole],
funcName: 'channelSubscription', funcName: 'channelSubscription',
funcDef: () => {} funcDef: () => {} // TODO: implement an action upon connection of clients
}); });
// add smartsocket to the running smartexpress app
this.smartsocket.setExternalServer('express', this.smartexpressServer as any); this.smartsocket.setExternalServer('express', this.smartexpressServer as any);
// should work with express as well
// start the socket
this.smartsocket.start(); this.smartsocket.start();
// start the smartexpress instance
await this.smartexpressServer.start(); await this.smartexpressServer.start();
} }
/**
* stop everything
*/
public async stopServer() { public async stopServer() {
await this.smartsocket.stop(); await this.smartsocket.stop();
await this.smartexpressServer.stop(); await this.smartexpressServer.stop();

View File

@ -39,7 +39,7 @@ export class UniverseCache {
} }
/** /**
* add a message to the UniverseStore * add a message to the UniverseCache
* @param messageArg * @param messageArg
* @param attachedPayloadArg * @param attachedPayloadArg
*/ */
@ -50,7 +50,7 @@ export class UniverseCache {
} }
/** /**
* Read a message from the UniverseStore * Read a message from the UniverseCache
*/ */
public readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage> { public readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage> {
const messageObservable = from(this.messageMap.getArray()).pipe( const messageObservable = from(this.messageMap.getArray()).pipe(

View File

@ -23,6 +23,7 @@ export class UniverseChannel {
passphraseArg: string passphraseArg: string
) { ) {
const newChannel = new UniverseChannel(universeCacheArg, channelNameArg, passphraseArg); const newChannel = new UniverseChannel(universeCacheArg, channelNameArg, passphraseArg);
universeCacheArg.channelMap.add(newChannel);
return newChannel; return newChannel;
} }

View File

@ -1,3 +0,0 @@
export interface IUniverseChannel {}
export interface IUniverseMessage {}