move to typescript predominance

This commit is contained in:
Philipp Kunz 2018-04-13 15:45:48 +02:00
parent 2165a8f677
commit 95c5fb7e83
30 changed files with 81 additions and 375 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.nogit/ .nogit/
node_modules/ node_modules/
dist/
coverage/ coverage/
public/ public/
pages/ pages/

View File

@ -1 +0,0 @@
FROM hosttoday/ht-docker-node

3
dist/index.d.ts vendored
View File

@ -1,3 +0,0 @@
export * from './smartuniverse.classes.universe';
export * from './smartuniverse.classes.universeclient';
export * from './smartuniverse.classes.universemessage';

9
dist/index.js vendored
View File

@ -1,9 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartuniverse.classes.universe"));
__export(require("./smartuniverse.classes.universeclient"));
__export(require("./smartuniverse.classes.universemessage"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHNEQUFpRDtBQUNqRCw0REFBdUQ7QUFDdkQsNkRBQXdEIn0=

View File

@ -1,3 +0,0 @@
export declare class UniverseManager {
registerMember(): Promise<void>;
}

View File

@ -1,17 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
class UniverseManager {
registerMember() {
return __awaiter(this, void 0, void 0, function* () { });
}
}
exports.UniverseManager = UniverseManager;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLm1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHVuaXZlcnNlLmNsYXNzZXMubWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBSUE7SUFDZSxjQUFjOzhEQUFJLENBQUM7S0FBQTtDQUNqQztBQUZELDBDQUVDIn0=

View File

@ -1,27 +0,0 @@
import { UniverseManager } from './smartuniverse.classes.manager';
import { UniverseStore } from './smartuniverse.classes.universestore';
export interface ISmartUniverseConstructorOptions {
messageExpiryInMilliseconds: number;
}
export interface IServerGetMessagesRequestBody {
youngerThan: number;
}
export interface IServerPutMessageRequestBody {
message: string;
payload: any;
}
export declare class Universe {
universeStore: UniverseStore;
universeManager: UniverseManager;
private options;
private universeVersionStore;
private readonly universeVersion;
private smartexpressServer;
private smartsocket;
constructor(optionsArg: ISmartUniverseConstructorOptions);
/**
* initiates a server
*/
initServer(portArg: number | string): Promise<void>;
stopServer(): Promise<void>;
}

View File

@ -1,75 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartuniverse.plugins");
const smartexpress_1 = require("smartexpress");
const smartuniverse_classes_manager_1 = require("./smartuniverse.classes.manager");
const smartuniverse_classes_universestore_1 = require("./smartuniverse.classes.universestore");
const paths = require("./smartuniverse.paths");
class Universe {
get universeVersion() {
if (this.universeVersionStore) {
return this.universeVersionStore;
}
else {
const packageJson = plugins.smartfile.fs.toObjectSync(paths.packageJson);
this.universeVersionStore = packageJson.version;
return this.universeVersionStore;
}
}
constructor(optionsArg) {
this.options = optionsArg;
this.universeStore = new smartuniverse_classes_universestore_1.UniverseStore(this.options.messageExpiryInMilliseconds);
this.universeManager = new smartuniverse_classes_manager_1.UniverseManager();
}
/**
* initiates a server
*/
initServer(portArg) {
return __awaiter(this, void 0, void 0, function* () {
this.smartexpressServer = new plugins.smartexpress.Server({
cors: true,
defaultAnswer: `smartuniverse server ${this.universeVersion}`,
forceSsl: false,
port: portArg
});
this.smartsocket = new plugins.smartsocket.Smartsocket({
port: 12345 // fix this within smartsocket
});
this.smartsocket.setExternalServer('express', this.smartexpressServer); // should work with express as well
this.smartsocket.start();
// route handling
// adds messages
const addMessageHandler = new smartexpress_1.Handler('PUT', request => {
const requestBody = request.body;
this.universeStore.addMessage(requestBody.message, requestBody.payload);
console.log(requestBody);
return true;
});
// gets messages
const readMessageHandler = new smartexpress_1.Handler('GET', request => {
const requestBody = request.body;
this.universeStore.readMessagesYoungerThan(requestBody.since);
});
const messageRoute = new smartexpress_1.Route(this.smartexpressServer, 'message');
messageRoute.addHandler(addMessageHandler);
messageRoute.addHandler(readMessageHandler);
yield this.smartexpressServer.start();
});
}
stopServer() {
return __awaiter(this, void 0, void 0, function* () {
yield this.smartsocket.stop();
yield this.smartexpressServer.stop();
});
}
}
exports.Universe = Universe;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxtREFBbUQ7QUFFbkQsK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SSxDQUFDLGtCQUFrQixFQUFFLFNBQVMsQ0FBQyxDQUFDO1lBQ25FLFlBQVksQ0FBQyxVQUFVLENBQUMsaUJBQWlCLENBQUMsQ0FBQztZQUMzQyxZQUFZLENBQUMsVUFBVSxDQUFDLGtCQUFrQixDQUFDLENBQUM7WUFFNUMsTUFBTSxJQUFJLENBQUMsa0JBQWtCLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDeEMsQ0FBQztLQUFBO0lBRVksVUFBVTs7WUFDckIsTUFBTSxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksRUFBRSxDQUFDO1lBQzlCLE1BQU0sSUFBSSxDQUFDLGtCQUFrQixDQUFDLElBQUksRUFBRSxDQUFDO1FBQ3ZDLENBQUM7S0FBQTtDQUNGO0FBM0VELDRCQTJFQyJ9

View File

@ -1,14 +0,0 @@
import * as plugins from './smartuniverse.plugins';
import { UniverseMessage } from './smartuniverse.classes.universemessage';
export interface IClientOptions {
serverAddress: string;
}
export declare class UniverseClient {
options: any;
private socketClient;
private observableIntake;
constructor(optionsArg: IClientOptions);
sendMessage(messageArg: any, payloadArg: any): Promise<void>;
getMessageObservable(): plugins.smartrx.rxjs.Observable<UniverseMessage>;
close(): void;
}

View File

@ -1,49 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartuniverse.plugins");
const smartsocket_1 = require("smartsocket");
const url = require("url");
class UniverseClient {
constructor(optionsArg) {
this.options = optionsArg;
}
sendMessage(messageArg, payloadArg) {
return __awaiter(this, void 0, void 0, function* () {
const requestBody = {
message: messageArg,
payload: payloadArg
};
yield plugins.smartrequest.post(this.options.serverAddress, {
requestBody
});
});
}
getMessageObservable() {
if (!this.socketClient && !this.observableIntake) {
const parsedURL = url.parse(this.options.serverAddress);
this.socketClient = new smartsocket_1.SmartsocketClient({
alias: process.env.SOCKET_ALIAS || 'someclient',
password: 'UniverseClient',
port: parseInt(parsedURL.port, 10),
role: 'UniverseClient',
url: parsedURL.hostname,
});
this.observableIntake = new plugins.smartrx.ObservableIntake();
this.socketClient.connect();
}
return this.observableIntake.observable;
}
close() {
this.socketClient.disconnect();
}
}
exports.UniverseClient = UniverseClient;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxtREFBbUQ7QUFJbkQsNkNBQTZEO0FBQzdELDJCQUEyQjtBQVkzQjtJQUtFLFlBQVksVUFBMEI7UUFDcEMsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUM7SUFDNUIsQ0FBQztJQUVZLFdBQVcsQ0FBQyxVQUFVLEVBQUUsVUFBVTs7WUFDN0MsTUFBTSxXQUFXLEdBQUc7Z0JBQ2xCLE9BQU8sRUFBRSxVQUFVO2dCQUNuQixPQUFPLEVBQUUsVUFBVTthQUNwQixDQUFDO1lBQ0YsTUFBTSxPQUFPLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLGFBQWEsRUFBRTtnQkFDMUQsV0FBVzthQUNaLENBQUMsQ0FBQztRQUNMLENBQUM7S0FBQTtJQUVNLG9CQUFvQjtRQUN6QixFQUFFLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxZQUFZLElBQUksQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQyxDQUFDO1lBQ2pELE1BQU0sU0FBUyxHQUFHLEdBQUcsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQztZQUN4RCxJQUFJLENBQUMsWUFBWSxHQUFHLElBQUksK0JBQWlCLENBQUM7Z0JBQ3hDLEtBQUssRUFBRSxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVksSUFBSSxZQUFZO2dCQUMvQyxRQUFRLEVBQUUsZ0JBQWdCO2dCQUMxQixJQUFJLEVBQUUsUUFBUSxDQUFDLFNBQVMsQ0FBQyxJQUFJLEVBQUUsRUFBRSxDQUFDO2dCQUNsQyxJQUFJLEVBQUUsZ0JBQWdCO2dCQUN0QixHQUFHLEVBQUUsU0FBUyxDQUFDLFFBQVE7YUFDeEIsQ0FBQyxDQUFDO1lBQ0gsSUFBSSxDQUFDLGdCQUFnQixHQUFHLElBQUksT0FBTyxDQUFDLE9BQU8sQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDO1lBQy9ELElBQUksQ0FBQyxZQUFZLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDOUIsQ0FBQztRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsVUFBVSxDQUFDO0lBQzFDLENBQUM7SUFFTSxLQUFLO1FBQ1YsSUFBSSxDQUFDLFlBQVksQ0FBQyxVQUFVLEVBQUUsQ0FBQztJQUNqQyxDQUFDO0NBQ0Y7QUF0Q0Qsd0NBc0NDIn0=

View File

@ -1,17 +0,0 @@
import { Timer, TimeStamp } from 'smarttime';
import { UniverseStore } from './smartuniverse.classes.universestore';
export declare class UniverseMessage {
/**
* public and unique id
* numeric ascending
* adheres to time in milliseconds
* avoids duplications though
*/
id: number;
universeStore: UniverseStore;
timestamp: TimeStamp;
message: string;
attachedPayload: any;
destructionTimer: Timer;
constructor(parentUniverseStore: UniverseStore, messageArg: string, attachedPayloadArg: any, selfdestructAfterArg: number);
}

View File

@ -1,27 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const smarttime_1 = require("smarttime");
class UniverseMessage {
constructor(parentUniverseStore, messageArg, attachedPayloadArg, selfdestructAfterArg) {
this.universeStore = parentUniverseStore;
this.timestamp = new smarttime_1.TimeStamp();
this.message = messageArg;
this.attachedPayload = attachedPayloadArg;
this.destructionTimer = new smarttime_1.Timer(selfdestructAfterArg);
this.destructionTimer.start();
// set up self destruction by removing this from the parent messageStore
this.destructionTimer.completed.then(() => __awaiter(this, void 0, void 0, function* () {
this.universeStore.messageStore.remove(this);
}));
}
}
exports.UniverseMessage = UniverseMessage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlbWVzc2FnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0dW5pdmVyc2UuY2xhc3Nlcy51bml2ZXJzZW1lc3NhZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUVBLHlDQUE2QztBQUc3QztJQWNFLFlBQ0UsbUJBQWtDLEVBQ2xDLFVBQWtCLEVBQ2xCLGtCQUF1QixFQUN2QixvQkFBNEI7UUFFNUIsSUFBSSxDQUFDLGFBQWEsR0FBRyxtQkFBbUIsQ0FBQztRQUN6QyxJQUFJLENBQUMsU0FBUyxHQUFHLElBQUkscUJBQVMsRUFBRSxDQUFDO1FBQ2pDLElBQUksQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDO1FBQzFCLElBQUksQ0FBQyxlQUFlLEdBQUcsa0JBQWtCLENBQUM7UUFDMUMsSUFBSSxDQUFDLGdCQUFnQixHQUFHLElBQUksaUJBQUssQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDO1FBQ3hELElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUU5Qix3RUFBd0U7UUFDeEUsSUFBSSxDQUFDLGdCQUFnQixDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsR0FBUyxFQUFFO1lBQzlDLElBQUksQ0FBQyxhQUFhLENBQUMsWUFBWSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUMvQyxDQUFDLENBQUEsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztDQUNGO0FBaENELDBDQWdDQyJ9

View File

@ -1,20 +0,0 @@
import * as plugins from './smartuniverse.plugins';
import { UniverseMessage } from './smartuniverse.classes.universemessage';
import { Observable } from 'rxjs';
export declare class UniverseStore {
standardMessageExpiry: number;
destructionTime: number;
messageStore: plugins.lik.Objectmap<UniverseMessage>;
private lastId;
constructor(standardMessageExpiryArg: number);
/**
* add a message to the UniverseStore
* @param messageArg
* @param attachedPayloadArg
*/
addMessage(messageArg: any, attachedPayloadArg: any): void;
/**
* Read a message from the UniverseStore
*/
readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage>;
}

View File

@ -1,32 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const smartuniverse_classes_universemessage_1 = require("./smartuniverse.classes.universemessage");
const lik_1 = require("lik");
const smartrx_1 = require("smartrx");
class UniverseStore {
constructor(standardMessageExpiryArg) {
this.destructionTime = 60000;
this.messageStore = new lik_1.Objectmap();
this.lastId = 0; // stores the last id
this.standardMessageExpiry = standardMessageExpiryArg;
}
/**
* add a message to the UniverseStore
* @param messageArg
* @param attachedPayloadArg
*/
addMessage(messageArg, attachedPayloadArg) {
this.messageStore.add(new smartuniverse_classes_universemessage_1.UniverseMessage(this, messageArg, attachedPayloadArg, this.destructionTime));
}
/**
* Read a message from the UniverseStore
*/
readMessagesYoungerThan(unixTimeArg) {
const messageObservable = smartrx_1.rxjs.Observable.from(this.messageStore.getArray()).filter(messageArg => {
return messageArg.timestamp.isYoungerThanMilliSeconds(this.destructionTime);
});
return messageObservable;
}
}
exports.UniverseStore = UniverseStore;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlc3RvcmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHVuaXZlcnNlLmNsYXNzZXMudW5pdmVyc2VzdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLG1HQUEwRTtBQUUxRSw2QkFBZ0M7QUFHaEMscUNBQStCO0FBRS9CO0lBTUUsWUFBWSx3QkFBZ0M7UUFKckMsb0JBQWUsR0FBVyxLQUFLLENBQUM7UUFDaEMsaUJBQVksR0FBRyxJQUFJLGVBQVMsRUFBbUIsQ0FBQztRQUMvQyxXQUFNLEdBQVcsQ0FBQyxDQUFDLENBQUMscUJBQXFCO1FBRy9DLElBQUksQ0FBQyxxQkFBcUIsR0FBRyx3QkFBd0IsQ0FBQztJQUN4RCxDQUFDO0lBRUQ7Ozs7T0FJRztJQUNJLFVBQVUsQ0FBQyxVQUFVLEVBQUUsa0JBQWtCO1FBQzlDLElBQUksQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUNuQixJQUFJLHVEQUFlLENBQUMsSUFBSSxFQUFFLFVBQVUsRUFBRSxrQkFBa0IsRUFBRSxJQUFJLENBQUMsZUFBZSxDQUFDLENBQ2hGLENBQUM7SUFDSixDQUFDO0lBRUQ7O09BRUc7SUFDSSx1QkFBdUIsQ0FBQyxXQUFvQjtRQUNqRCxNQUFNLGlCQUFpQixHQUFHLGNBQUksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsUUFBUSxFQUFFLENBQUMsQ0FBQyxNQUFNLENBQ2pGLFVBQVUsQ0FBQyxFQUFFO1lBQ1gsTUFBTSxDQUFDLFVBQVUsQ0FBQyxTQUFTLENBQUMseUJBQXlCLENBQUMsSUFBSSxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQzlFLENBQUMsQ0FDRixDQUFDO1FBQ0YsTUFBTSxDQUFDLGlCQUFpQixDQUFDO0lBQzNCLENBQUM7Q0FDRjtBQWhDRCxzQ0FnQ0MifQ==

View File

@ -1 +0,0 @@
export {};

View File

@ -1,21 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartuniverse.plugins");
const index_1 = require("./index");
process.env.CLI = 'true';
const universeCli = new plugins.smartcli.Smartcli();
universeCli.standardTask().then((argvArg) => __awaiter(this, void 0, void 0, function* () {
const standardUniverse = new index_1.Universe({
messageExpiryInMilliseconds: 60000
});
yield standardUniverse.initServer(8765);
}));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHVuaXZlcnNlLmNsaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsbURBQW1EO0FBRW5ELG1DQUFtQztBQUVuQyxPQUFPLENBQUMsR0FBRyxDQUFDLEdBQUcsR0FBRyxNQUFNLENBQUM7QUFFekIsTUFBTSxXQUFXLEdBQUcsSUFBSSxPQUFPLENBQUMsUUFBUSxDQUFDLFFBQVEsRUFBRSxDQUFDO0FBRXBELFdBQVcsQ0FBQyxZQUFZLEVBQUUsQ0FBQyxJQUFJLENBQUMsQ0FBTSxPQUFPLEVBQUMsRUFBRTtJQUM5QyxNQUFNLGdCQUFnQixHQUFHLElBQUksZ0JBQVEsQ0FBQztRQUNwQywyQkFBMkIsRUFBRSxLQUFLO0tBQ25DLENBQUMsQ0FBQztJQUNILE1BQU0sZ0JBQWdCLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxDQUFDO0FBQzFDLENBQUMsQ0FBQSxDQUFDLENBQUMifQ==

View File

@ -1 +0,0 @@
export declare const packageJson: string;

View File

@ -1,5 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartuniverse.plugins");
exports.packageJson = plugins.path.join(__dirname, '../package.json');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0dW5pdmVyc2UucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxtREFBbUQ7QUFFdEMsUUFBQSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLGlCQUFpQixDQUFDLENBQUMifQ==

View File

@ -1,10 +0,0 @@
import * as lik from 'lik';
import * as path from 'path';
import * as smartcli from 'smartcli';
import * as smartexpress from 'smartexpress';
import * as smartfile from 'smartfile';
import * as smartrequest from 'smartrequest';
import * as smartrx from 'smartrx';
import * as smartsocket from 'smartsocket';
import * as smarttime from 'smarttime';
export { lik, path, smartcli, smartexpress, smartfile, smartrx, smartrequest, smartsocket, smarttime };

View File

@ -1,21 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lik = require("lik");
exports.lik = lik;
const path = require("path");
exports.path = path;
const smartcli = require("smartcli");
exports.smartcli = smartcli;
const smartexpress = require("smartexpress");
exports.smartexpress = smartexpress;
const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smartrequest = require("smartrequest");
exports.smartrequest = smartrequest;
const smartrx = require("smartrx");
exports.smartrx = smartrx;
const smartsocket = require("smartsocket");
exports.smartsocket = smartsocket;
const smarttime = require("smarttime");
exports.smarttime = smarttime;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMkJBQTJCO0FBV3pCLGtCQUFHO0FBVkwsNkJBQTZCO0FBVzNCLG9CQUFJO0FBVk4scUNBQXFDO0FBV25DLDRCQUFRO0FBVlYsNkNBQTZDO0FBVzNDLG9DQUFZO0FBVmQsdUNBQXVDO0FBV3JDLDhCQUFTO0FBVlgsNkNBQTZDO0FBWTNDLG9DQUFZO0FBWGQsbUNBQW1DO0FBVWpDLDBCQUFPO0FBVFQsMkNBQTJDO0FBV3pDLGtDQUFXO0FBVmIsdUNBQXVDO0FBV3JDLDhCQUFTIn0=

View File

@ -7,7 +7,8 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(npmts)", "test": "ts-node test/test.ts",
"build": "(npmts)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
@ -20,6 +21,7 @@
"smartcli": "^2.0.12", "smartcli": "^2.0.12",
"smartexpress": "^1.0.21", "smartexpress": "^1.0.21",
"smartfile": "^4.2.28", "smartfile": "^4.2.28",
"smartq": "^1.1.8",
"smartrequest": "^1.0.8", "smartrequest": "^1.0.8",
"smartrx": "^1.0.5", "smartrx": "^1.0.5",
"smartsocket": "^1.1.19", "smartsocket": "^1.1.19",

View File

@ -1,13 +1,16 @@
# smartuniverse # smartuniverse
messaging service for your micro services messaging service for your micro services
## Availabililty ## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/@pushrocks/smartuniverse) [![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartuniverse) [![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartuniverse)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartuniverse) [![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartuniverse)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartuniverse/) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartuniverse/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartuniverse/badges/master/build.svg)](https://GitLab.com/pushrocks/smartuniverse/commits/master) [![build status](https://GitLab.com/pushrocks/smartuniverse/badges/master/build.svg)](https://GitLab.com/pushrocks/smartuniverse/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartuniverse/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartuniverse/commits/master) [![coverage report](https://GitLab.com/pushrocks/smartuniverse/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartuniverse/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartuniverse.svg)](https://www.npmjs.com/package/@pushrocks/smartuniverse) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartuniverse.svg)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
@ -19,11 +22,12 @@ messaging service for your micro services
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
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.
> licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) > licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) > | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) [![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -36,14 +36,13 @@ tap.test('should get a observable correctly', async () => {
testMessageObservable = testUniverseClient.getMessageObservable(); testMessageObservable = testUniverseClient.getMessageObservable();
}); });
tap.test('should receive a message correctly', async () => { tap.test('should receive a message correctly', async () => {});
});
tap.test('should disconnect the client correctly', async () => { tap.test('should disconnect the client correctly', async () => {
testUniverseClient.close(); testUniverseClient.close();
}) });
tap.test('should end the server correctly', async (tools) => { tap.test('should end the server correctly', async tools => {
await testUniverse.stopServer(); await testUniverse.stopServer();
}); });

View File

@ -0,0 +1,4 @@
/**
* This file contains logic to bridge certain messages into another channel
*/
export class ChannelBridge {}

View File

@ -1,7 +1,20 @@
import * as plugins from './smartuniverse.plugins'; import * as plugins from './smartuniverse.plugins';
import { Objectmap } from 'lik'; import { Objectmap } from 'lik';
import { UniverseChannel } from './smartuniverse.classes.universechannel';
export class UniverseManager { export class UniverseManager {
public channelStore = new Objectmap<UniverseChannel>();
/**
* register a new member
*/
public async registerMember() {} public async registerMember() {}
/**
* register a new channel within the universe
* @param channelName the name of the channel
* @param authSecret the secret against which to verify members of the channel
*/
public async registerChannel(channelName: string, authSecret: string) {}
} }

View File

@ -3,8 +3,10 @@ import * as plugins from './smartuniverse.plugins';
import { Handler, Route, Server } from 'smartexpress'; import { Handler, Route, Server } from 'smartexpress';
import { UniverseManager } from './smartuniverse.classes.manager'; import { UniverseManager } from './smartuniverse.classes.manager';
import { UniverseChannel } from './smartuniverse.classes.universechannel';
import { UniverseMessage } from './smartuniverse.classes.universemessage'; import { UniverseMessage } from './smartuniverse.classes.universemessage';
import { UniverseStore } from './smartuniverse.classes.universestore'; import { UniverseStore } from './smartuniverse.classes.universestore';
import * as paths from './smartuniverse.paths'; import * as paths from './smartuniverse.paths';
export interface ISmartUniverseConstructorOptions { export interface ISmartUniverseConstructorOptions {
@ -60,16 +62,7 @@ export class Universe {
port: portArg port: portArg
}); });
this.smartsocket = new plugins.smartsocket.Smartsocket({ // message handling
port: 12345 // fix this within smartsocket
});
this.smartsocket.setExternalServer(
'express',
this.smartexpressServer as any); // should work with express as well
this.smartsocket.start();
// route handling
// adds messages // adds messages
const addMessageHandler = new Handler('PUT', request => { const addMessageHandler = new Handler('PUT', request => {
const requestBody = request.body; const requestBody = request.body;
@ -80,14 +73,31 @@ export class Universe {
// gets messages // gets messages
const readMessageHandler = new Handler('GET', request => { const readMessageHandler = new Handler('GET', request => {
const done = plugins.smartq.defer<UniverseMessage[]>();
const requestBody = request.body; const requestBody = request.body;
this.universeStore.readMessagesYoungerThan(requestBody.since); const messageObservable = this.universeStore.readMessagesYoungerThan(requestBody.since);
messageObservable.toArray().subscribe(universeMessageArrayArg => {
done.resolve(universeMessageArrayArg);
});
return done.promise;
}); });
// create new Route for messages
const messageRoute = new Route(this.smartexpressServer, 'message'); const messageRoute = new Route(this.smartexpressServer, 'message');
messageRoute.addHandler(addMessageHandler); messageRoute.addHandler(addMessageHandler);
messageRoute.addHandler(readMessageHandler); messageRoute.addHandler(readMessageHandler);
const leaderElectionRoute = new Route(this.smartexpressServer, 'leadelection');
// TODO: implement Handlers for leader election
// add websocket upgrade
this.smartsocket = new plugins.smartsocket.Smartsocket({
port: 12345 // fix this within smartsocket
});
this.smartsocket.setExternalServer('express', this.smartexpressServer as any); // should work with express as well
this.smartsocket.start();
await this.smartexpressServer.start(); await this.smartexpressServer.start();
} }

View File

@ -0,0 +1,17 @@
import * as plugins from './smartuniverse.plugins';
/**
* enables a set of apps to talk within their own limited borders.
*/
export class UniverseChannel {
topic: string;
credentials: {
user: string;
password: string;
};
/**
* authenticates a client on the server side
*/
async authenticateClient() {}
}

View File

@ -1,6 +1,5 @@
import * as plugins from './smartuniverse.plugins'; import * as plugins from './smartuniverse.plugins';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Smartsocket, SmartsocketClient } from 'smartsocket'; import { Smartsocket, SmartsocketClient } from 'smartsocket';
import * as url from 'url'; import * as url from 'url';
@ -15,6 +14,10 @@ export interface IClientOptions {
serverAddress: string; serverAddress: string;
} }
/**
* this class is for client side only!!!
* allows connecting to a universe server
*/
export class UniverseClient { export class UniverseClient {
public options; public options;
private socketClient: plugins.smartsocket.SmartsocketClient; private socketClient: plugins.smartsocket.SmartsocketClient;
@ -29,6 +32,7 @@ export class UniverseClient {
message: messageArg, message: messageArg,
payload: payloadArg payload: payloadArg
}; };
// TODO: User websocket connection if available
await plugins.smartrequest.post(this.options.serverAddress, { await plugins.smartrequest.post(this.options.serverAddress, {
requestBody requestBody
}); });
@ -42,7 +46,7 @@ export class UniverseClient {
password: 'UniverseClient', password: 'UniverseClient',
port: parseInt(parsedURL.port, 10), port: parseInt(parsedURL.port, 10),
role: 'UniverseClient', role: 'UniverseClient',
url: parsedURL.hostname, url: parsedURL.hostname
}); });
this.observableIntake = new plugins.smartrx.ObservableIntake(); this.observableIntake = new plugins.smartrx.ObservableIntake();
this.socketClient.connect(); this.socketClient.connect();

View File

@ -3,6 +3,9 @@ import * as plugins from './smartuniverse.plugins';
import { Timer, TimeStamp } from 'smarttime'; import { Timer, TimeStamp } from 'smarttime';
import { UniverseStore } from './smartuniverse.classes.universestore'; import { UniverseStore } from './smartuniverse.classes.universestore';
/**
* represents a message within a universe
*/
export class UniverseMessage { export class UniverseMessage {
/** /**
* public and unique id * public and unique id

View File

@ -3,6 +3,7 @@ import * as path from 'path';
import * as smartcli from 'smartcli'; import * as smartcli from 'smartcli';
import * as smartexpress from 'smartexpress'; import * as smartexpress from 'smartexpress';
import * as smartfile from 'smartfile'; import * as smartfile from 'smartfile';
import * as smartq from 'smartq';
import * as smartrequest from 'smartrequest'; import * as smartrequest from 'smartrequest';
import * as smartrx from 'smartrx'; import * as smartrx from 'smartrx';
import * as smartsocket from 'smartsocket'; import * as smartsocket from 'smartsocket';
@ -14,6 +15,7 @@ export {
smartcli, smartcli,
smartexpress, smartexpress,
smartfile, smartfile,
smartq,
smartrx, smartrx,
smartrequest, smartrequest,
smartsocket, smartsocket,