Compare commits

...

8 Commits

Author SHA1 Message Date
3c7683d40e 1.0.20 2018-05-24 17:08:29 +02:00
c19f27e873 fix(dependencies): update 2018-05-24 17:08:28 +02:00
c1a03fec0f 1.0.19 2018-05-24 16:55:25 +02:00
8b650c5ea7 fix(UniverseChannel): improve channel handling 2018-05-24 16:55:24 +02:00
4fc6e327ec 1.0.18 2018-05-24 00:14:57 +02:00
7991baf2bf fix(core): improve channel handling 2018-05-24 00:14:57 +02:00
d033780015 1.0.17 2018-05-23 23:50:46 +02:00
eae46e6461 fix(structure): format TypeScript 2018-05-23 23:50:45 +02:00
8 changed files with 2575 additions and 1788 deletions

2505
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
{ {
"name": "@pushrocks/smartuniverse", "name": "@pushrocks/smartuniverse",
"version": "1.0.16", "version": "1.0.20",
"private": false,
"description": "messaging service for your micro services", "description": "messaging service for your micro services",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
@ -13,13 +14,15 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^9.6.0", "@types/node": "^9.6.0",
"tapbundle": "^2.0.0" "tapbundle": "^2.0.0",
"ts-node": "^6.0.3",
"typescript": "^2.8.3"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartcli": "^3.0.1",
"lik": "^2.0.5", "lik": "^2.0.5",
"nodehash": "^1.0.4", "nodehash": "^1.0.4",
"rxjs": "^5.5.8", "rxjs": "^5.5.8",
"smartcli": "^2.0.12",
"smartdelay": "^1.0.4", "smartdelay": "^1.0.4",
"smartexpress": "^1.0.21", "smartexpress": "^1.0.21",
"smartfile": "^4.2.28", "smartfile": "^4.2.28",

View File

@ -17,6 +17,9 @@ export interface IServerGetMessagesRequestBody {
youngerThan: number; youngerThan: number;
} }
/**
* the interface for a standard request
*/
export interface IServerPutMessageRequestBody { export interface IServerPutMessageRequestBody {
channel: string; channel: string;
passphrase: string; passphrase: string;
@ -24,6 +27,9 @@ export interface IServerPutMessageRequestBody {
payload: any; payload: any;
} }
/**
* main class that setsup a Universe
*/
export class Universe { export class Universe {
// subinstances // subinstances
public universeStore: UniverseStore; public universeStore: UniverseStore;
@ -66,11 +72,7 @@ export class Universe {
// adds messages // adds messages
const addMessageHandler = new Handler('PUT', request => { const addMessageHandler = new Handler('PUT', request => {
const requestBody: IServerPutMessageRequestBody = request.body; const requestBody: IServerPutMessageRequestBody = request.body;
const message = new UniverseMessage( const message = new UniverseMessage(requestBody.message, requestBody.channel, requestBody.passphrase, requestBody.payload);
requestBody.message,
requestBody.payload,
)
this.universeStore.addMessage(message); this.universeStore.addMessage(message);
console.log(requestBody); console.log(requestBody);
return true; return true;

View File

@ -6,21 +6,60 @@ import { Objectmap } from 'lik';
* enables messages to stay within a certain scope. * enables messages to stay within a certain scope.
*/ */
export class UniverseChannel { export class UniverseChannel {
// ======
// STATIC
// ======
/** /**
* stores the channels that are available within the universe * stores the channels that are available within the universe
*/ */
public static channelStore = new Objectmap(); public static channelStore = new Objectmap<UniverseChannel>();
/**
* allows messages to be processed in a blacklist mode for further analysis
*/
public static blackListChannel = new UniverseChannel('blacklist', 'nada');
/** /**
* creates new channels * creates new channels
* @param channelArg the name of the topic * @param channelArg the name of the topic
* @param passphraseArg the secret thats used for a certain topic. * @param passphraseArg the secret thats used for a certain topic.
*/ */
public static createChannel = (channelNameArg: string, passphraseArg: string) => { public static createChannel (channelNameArg: string, passphraseArg: string) {
const newChannel = new UniverseChannel(channelNameArg, passphraseArg); const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
return newChannel; return newChannel;
};
/**
* returns boolean wether certain channel exists
*/
public static async doesChannelExists (channelNameArg: string) {
const channel = this.channelStore.find(channelArg => {
return channelArg.name === channelNameArg;
});
if(channel) {
return true;
} else {
return false;
}
} }
public static authorizeForChannel (channelNameArg: string, passphraseArg: string) {
const foundChannel = this.channelStore.find(universeChannel => {
const result = universeChannel.authenticate(channelNameArg, passphraseArg);
return result;
});
if(foundChannel) {
return foundChannel;
} else {
return this.blackListChannel;
}
};
// ========
// INSTANCE
// ========
/** /**
* the name of the channel * the name of the channel
*/ */
@ -40,7 +79,7 @@ export class UniverseChannel {
/** /**
* authenticates a client on the server side * authenticates a client on the server side
*/ */
public async authenticateClient(passphraseArg: string): boolean { public authenticate(channelNameArg: string, passphraseArg: string): boolean {
return passphraseArg === this.passphrase; return (this.name === channelNameArg && this.passphrase === passphraseArg);
} }
} }

View File

@ -1,7 +1,9 @@
import * as plugins from './smartuniverse.plugins'; import * as plugins from './smartuniverse.plugins';
import { Timer, TimeStamp } from 'smarttime'; import { Timer, TimeStamp } from 'smarttime';
import { UniverseChannel } from './smartuniverse.classes.universechannel';
import { UniverseStore } from './smartuniverse.classes.universestore'; import { UniverseStore } from './smartuniverse.classes.universestore';
import { Universe } from './smartuniverse.classes.universe';
/** /**
* represents a message within a universe * represents a message within a universe
@ -22,7 +24,7 @@ export class UniverseMessage {
/** /**
* enables unprotected grouping of messages for efficiency purposes. * enables unprotected grouping of messages for efficiency purposes.
*/ */
public universeChannel: string; public universeChannel: UniverseChannel;
/** /**
* time of creation * time of creation
@ -45,21 +47,19 @@ export class UniverseMessage {
* @param messageArg * @param messageArg
* @param attachedPayloadArg * @param attachedPayloadArg
*/ */
constructor( constructor(messageArg: string, channelNameArg: string, passphraseArg: string, attachedPayloadArg: any) {
messageArg: string,
attachedPayloadArg: any
) {
this.timestamp = new TimeStamp(); this.timestamp = new TimeStamp();
this.message = messageArg; this.message = messageArg;
this.universeChannel = UniverseChannel.authorizeForChannel(channelNameArg, passphraseArg);
this.attachedPayload = attachedPayloadArg; this.attachedPayload = attachedPayloadArg;
this.fallBackDestruction(); this.fallBackDestruction();
} }
public setUniverseStore (universeStoreArg: UniverseStore) { public setUniverseStore(universeStoreArg: UniverseStore) {
this.universeStore = universeStoreArg; this.universeStore = universeStoreArg;
} }
public setDestructionTimer (selfdestructAfterArg: number) { public setDestructionTimer(selfdestructAfterArg: number) {
if (selfdestructAfterArg) { if (selfdestructAfterArg) {
this.destructionTimer = new Timer(selfdestructAfterArg); this.destructionTimer = new Timer(selfdestructAfterArg);
this.destructionTimer.start(); this.destructionTimer.start();
@ -71,13 +71,12 @@ export class UniverseMessage {
} else { } else {
this.fallBackDestruction(); this.fallBackDestruction();
} }
}
};
/** /**
* prevents memory leaks if channels have no default * prevents memory leaks if channels have no default
*/ */
private fallBackDestruction () { private fallBackDestruction() {
plugins.smartdelay.delayFor(1000).then(() => { plugins.smartdelay.delayFor(1000).then(() => {
if (!this.destructionTimer) { if (!this.destructionTimer) {
this.setDestructionTimer(6000); this.setDestructionTimer(6000);

View File

@ -6,7 +6,7 @@ process.env.CLI = 'true';
const universeCli = new plugins.smartcli.Smartcli(); const universeCli = new plugins.smartcli.Smartcli();
universeCli.standardTask().then(async argvArg => { universeCli.standardTask().subscribe(async argvArg => {
const standardUniverse = new Universe({ const standardUniverse = new Universe({
messageExpiryInMilliseconds: 60000 messageExpiryInMilliseconds: 60000
}); });

View File

@ -1,7 +1,7 @@
import * as smartcli from '@pushrocks/smartcli';
import * as lik from 'lik'; import * as lik from 'lik';
import * as nodehash from 'nodehash'; import * as nodehash from 'nodehash';
import * as path from 'path'; import * as path from 'path';
import * as smartcli from 'smartcli';
import * as smartdelay from 'smartdelay'; import * as smartdelay from 'smartdelay';
import * as smartexpress from 'smartexpress'; import * as smartexpress from 'smartexpress';
import * as smartfile from 'smartfile'; import * as smartfile from 'smartfile';

1761
yarn.lock

File diff suppressed because it is too large Load Diff