Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
785acfaba4 | |||
5a4dceb75d | |||
a17834a8f0 | |||
01765fa50f | |||
547c159dc4 | |||
046d7d646d | |||
f6985bd7b2 | |||
241e44e19d | |||
99561166e2 | |||
0e95774f30 | |||
011af15866 | |||
77a13786d1 | |||
d0e4c1c44a | |||
1c8d6bf96e | |||
95c5fb7e83 | |||
2165a8f677 | |||
aa52ceeeca | |||
78e57394c9 | |||
5f9f670546 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
dist/
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
@ -10,15 +10,18 @@ stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
@ -28,7 +31,11 @@ snyk:
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
@ -38,6 +45,7 @@ testLEGACY:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
@ -49,6 +57,7 @@ testLTS:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
@ -59,34 +68,60 @@ testSTABLE:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
|
@ -1 +0,0 @@
|
||||
FROM hosttoday/ht-docker-node
|
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
export * from './smartuniverse.classes.universe';
|
||||
export * from './smartuniverse.classes.universeclient';
|
||||
export * from './smartuniverse.classes.universemessage';
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -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=
|
3
dist/smartuniverse.classes.manager.d.ts
vendored
3
dist/smartuniverse.classes.manager.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
export declare class UniverseManager {
|
||||
registerMember(): Promise<void>;
|
||||
}
|
17
dist/smartuniverse.classes.manager.js
vendored
17
dist/smartuniverse.classes.manager.js
vendored
@ -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=
|
27
dist/smartuniverse.classes.universe.d.ts
vendored
27
dist/smartuniverse.classes.universe.d.ts
vendored
@ -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>;
|
||||
}
|
75
dist/smartuniverse.classes.universe.js
vendored
75
dist/smartuniverse.classes.universe.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxtREFBbUQ7QUFFbkQsK0NBQXNEO0FBRXRELG1GQUFrRTtBQUVsRSwrRkFBc0U7QUFDdEUsK0NBQStDO0FBZS9DO0lBVUUsSUFBWSxlQUFlO1FBQ3pCLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLENBQUM7WUFDOUIsTUFBTSxDQUFDLElBQUksQ0FBQyxvQkFBb0IsQ0FBQztRQUNuQyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDTixNQUFNLFdBQVcsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsS0FBSyxDQUFDLFdBQVcsQ0FBQyxDQUFDO1lBQ3pFLElBQUksQ0FBQyxvQkFBb0IsR0FBRyxXQUFXLENBQUMsT0FBTyxDQUFDO1lBQ2hELE1BQU0sQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUM7UUFDbkMsQ0FBQztJQUNILENBQUM7SUFLRCxZQUFZLFVBQTRDO1FBQ3RELElBQUksQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDO1FBQzFCLElBQUksQ0FBQyxhQUFhLEdBQUcsSUFBSSxtREFBYSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsMkJBQTJCLENBQUMsQ0FBQztRQUNqRixJQUFJLENBQUMsZUFBZSxHQUFHLElBQUksK0NBQWUsRUFBRSxDQUFDO0lBQy9DLENBQUM7SUFFRDs7T0FFRztJQUNVLFVBQVUsQ0FBQyxPQUF3Qjs7WUFDOUMsSUFBSSxDQUFDLGtCQUFrQixHQUFHLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxNQUFNLENBQUM7Z0JBQ3hELElBQUksRUFBRSxJQUFJO2dCQUNWLGFBQWEsRUFBRSx3QkFBd0IsSUFBSSxDQUFDLGVBQWUsRUFBRTtnQkFDN0QsUUFBUSxFQUFFLEtBQUs7Z0JBQ2YsSUFBSSxFQUFFLE9BQU87YUFDZCxDQUFDLENBQUM7WUFFSCxJQUFJLENBQUMsV0FBVyxHQUFHLElBQUksT0FBTyxDQUFDLFdBQVcsQ0FBQyxXQUFXLENBQUM7Z0JBQ3JELElBQUksRUFBRSxLQUFLLENBQUMsOEJBQThCO2FBQzNDLENBQUMsQ0FBQztZQUVILElBQUksQ0FBQyxXQUFXLENBQUMsaUJBQWlCLENBQ2hDLFNBQVMsRUFDVCxJQUFJLENBQUMsa0JBQXlCLENBQUMsQ0FBQyxDQUFDLG1DQUFtQztZQUN0RSxJQUFJLENBQUMsV0FBVyxDQUFDLEtBQUssRUFBRSxDQUFDO1lBRXpCLGlCQUFpQjtZQUNqQixnQkFBZ0I7WUFDaEIsTUFBTSxpQkFBaUIsR0FBRyxJQUFJLHNCQUFPLENBQUMsS0FBSyxFQUFFLE9BQU8sQ0FBQyxFQUFFO2dCQUNyRCxNQUFNLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDO2dCQUNqQyxJQUFJLENBQUMsYUFBYSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUMsT0FBTyxFQUFFLFdBQVcsQ0FBQyxPQUFPLENBQUMsQ0FBQztnQkFDeEUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLENBQUMsQ0FBQztnQkFDekIsTUFBTSxDQUFDLElBQUksQ0FBQztZQUNkLENBQUMsQ0FBQyxDQUFDO1lBRUgsZ0JBQWdCO1lBQ2hCLE1BQU0sa0JBQWtCLEdBQUcsSUFBSSxzQkFBTyxDQUFDLEtBQUssRUFBRSxPQUFPLENBQUMsRUFBRTtnQkFDdEQsTUFBTSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQztnQkFDakMsSUFBSSxDQUFDLGFBQWEsQ0FBQyx1QkFBdUIsQ0FBQyxXQUFXLENBQUMsS0FBSyxDQUFDLENBQUM7WUFDaEUsQ0FBQyxDQUFDLENBQUM7WUFFSCxNQUFNLFlBQVksR0FBRyxJQUFJLG9CQUFLLENBQUMsSUFBSSxDQUFDLGtCQUFrQixFQUFFLFNBQVMsQ0FBQyxDQUFDO1lBQ25FLFlBQVksQ0FBQyxVQUFVLENBQUMsaUJBQWlCLENBQUMsQ0FBQztZQUMzQyxZQUFZLENBQUMsVUFBVSxDQUFDLGtCQUFrQixDQUFDLENBQUM7WUFFNUMsTUFBTSxJQUFJLENBQUMsa0JBQWtCLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDeEMsQ0FBQztLQUFBO0lBRVksVUFBVTs7WUFDckIsTUFBTSxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksRUFBRSxDQUFDO1lBQzlCLE1BQU0sSUFBSSxDQUFDLGtCQUFrQixDQUFDLElBQUksRUFBRSxDQUFDO1FBQ3ZDLENBQUM7S0FBQTtDQUNGO0FBM0VELDRCQTJFQyJ9
|
14
dist/smartuniverse.classes.universeclient.d.ts
vendored
14
dist/smartuniverse.classes.universeclient.d.ts
vendored
@ -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;
|
||||
}
|
49
dist/smartuniverse.classes.universeclient.js
vendored
49
dist/smartuniverse.classes.universeclient.js
vendored
@ -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=
|
17
dist/smartuniverse.classes.universemessage.d.ts
vendored
17
dist/smartuniverse.classes.universemessage.d.ts
vendored
@ -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);
|
||||
}
|
27
dist/smartuniverse.classes.universemessage.js
vendored
27
dist/smartuniverse.classes.universemessage.js
vendored
@ -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
|
20
dist/smartuniverse.classes.universestore.d.ts
vendored
20
dist/smartuniverse.classes.universestore.d.ts
vendored
@ -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>;
|
||||
}
|
32
dist/smartuniverse.classes.universestore.js
vendored
32
dist/smartuniverse.classes.universestore.js
vendored
@ -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==
|
1
dist/smartuniverse.cli.d.ts
vendored
1
dist/smartuniverse.cli.d.ts
vendored
@ -1 +0,0 @@
|
||||
export {};
|
21
dist/smartuniverse.cli.js
vendored
21
dist/smartuniverse.cli.js
vendored
@ -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==
|
1
dist/smartuniverse.paths.d.ts
vendored
1
dist/smartuniverse.paths.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare const packageJson: string;
|
5
dist/smartuniverse.paths.js
vendored
5
dist/smartuniverse.paths.js
vendored
@ -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==
|
10
dist/smartuniverse.plugins.d.ts
vendored
10
dist/smartuniverse.plugins.d.ts
vendored
@ -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 };
|
21
dist/smartuniverse.plugins.js
vendored
21
dist/smartuniverse.plugins.js
vendored
@ -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=
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"npmts"
|
||||
]
|
||||
"@gitzone/npmts",
|
||||
"ts-node"
|
||||
],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "@pushrocks/smartuniverse",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.16",
|
||||
"description": "messaging service for your micro services",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(npmts)",
|
||||
"test": "(ts-node -O '{\"lib\": [ \"es2015\" ]}' test/test.ts)",
|
||||
"build": "(npmts)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -16,10 +17,13 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"lik": "^2.0.5",
|
||||
"nodehash": "^1.0.4",
|
||||
"rxjs": "^5.5.8",
|
||||
"smartcli": "^2.0.12",
|
||||
"smartdelay": "^1.0.4",
|
||||
"smartexpress": "^1.0.21",
|
||||
"smartfile": "^4.2.28",
|
||||
"smartq": "^1.1.8",
|
||||
"smartrequest": "^1.0.8",
|
||||
"smartrx": "^1.0.5",
|
||||
"smartsocket": "^1.1.19",
|
||||
|
12
readme.md
12
readme.md
@ -1,29 +1,33 @@
|
||||
# smartuniverse
|
||||
|
||||
messaging service for your micro services
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||
[](https://GitLab.com/pushrocks/smartuniverse)
|
||||
[](https://github.com/pushrocks/smartuniverse)
|
||||
[](https://pushrocks.gitlab.io/smartuniverse/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartuniverse/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartuniverse/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/@pushrocks/smartuniverse)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||
[](https://www.bithound.io/github/pushrocks/smartuniverse/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartuniverse)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
> licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
||||
|
@ -36,14 +36,13 @@ tap.test('should get a observable correctly', async () => {
|
||||
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 () => {
|
||||
testUniverseClient.close();
|
||||
})
|
||||
});
|
||||
|
||||
tap.test('should end the server correctly', async (tools) => {
|
||||
tap.test('should end the server correctly', async tools => {
|
||||
await testUniverse.stopServer();
|
||||
});
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Objectmap } from 'lik';
|
||||
|
||||
export class UniverseManager {
|
||||
public async registerMember() {}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Handler, Route, Server } from 'smartexpress';
|
||||
|
||||
import { UniverseManager } from './smartuniverse.classes.manager';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||
|
||||
import * as paths from './smartuniverse.paths';
|
||||
|
||||
export interface ISmartUniverseConstructorOptions {
|
||||
@ -12,10 +12,14 @@ export interface ISmartUniverseConstructorOptions {
|
||||
}
|
||||
|
||||
export interface IServerGetMessagesRequestBody {
|
||||
channel: string;
|
||||
topic?: string;
|
||||
youngerThan: number;
|
||||
}
|
||||
|
||||
export interface IServerPutMessageRequestBody {
|
||||
channel: string;
|
||||
passphrase: string;
|
||||
message: string;
|
||||
payload: any;
|
||||
}
|
||||
@ -23,7 +27,6 @@ export interface IServerPutMessageRequestBody {
|
||||
export class Universe {
|
||||
// subinstances
|
||||
public universeStore: UniverseStore;
|
||||
public universeManager: UniverseManager;
|
||||
|
||||
// options
|
||||
private options: ISmartUniverseConstructorOptions;
|
||||
@ -46,7 +49,6 @@ export class Universe {
|
||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
this.universeStore = new UniverseStore(this.options.messageExpiryInMilliseconds);
|
||||
this.universeManager = new UniverseManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,34 +62,47 @@ export class Universe {
|
||||
port: portArg
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
// route handling
|
||||
// message handling
|
||||
// adds messages
|
||||
const addMessageHandler = new Handler('PUT', request => {
|
||||
const requestBody = request.body;
|
||||
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
||||
const requestBody: IServerPutMessageRequestBody = request.body;
|
||||
const message = new UniverseMessage(
|
||||
requestBody.message,
|
||||
requestBody.payload,
|
||||
|
||||
)
|
||||
this.universeStore.addMessage(message);
|
||||
console.log(requestBody);
|
||||
return true;
|
||||
});
|
||||
|
||||
// gets messages
|
||||
const readMessageHandler = new Handler('GET', request => {
|
||||
const done = plugins.smartq.defer<UniverseMessage[]>();
|
||||
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');
|
||||
messageRoute.addHandler(addMessageHandler);
|
||||
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();
|
||||
}
|
||||
|
||||
|
46
ts/smartuniverse.classes.universechannel.ts
Normal file
46
ts/smartuniverse.classes.universechannel.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Objectmap } from 'lik';
|
||||
|
||||
/**
|
||||
* enables messages to stay within a certain scope.
|
||||
*/
|
||||
export class UniverseChannel {
|
||||
/**
|
||||
* stores the channels that are available within the universe
|
||||
*/
|
||||
public static channelStore = new Objectmap();
|
||||
|
||||
/**
|
||||
* creates new channels
|
||||
* @param channelArg the name of the topic
|
||||
* @param passphraseArg the secret thats used for a certain topic.
|
||||
*/
|
||||
public static createChannel = (channelNameArg: string, passphraseArg: string) => {
|
||||
const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* the name of the channel
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* the passphrase for the channel
|
||||
*/
|
||||
public passphrase: string;
|
||||
|
||||
constructor(channelNameArg: string, passphraseArg: string) {
|
||||
this.name = channelNameArg;
|
||||
this.passphrase = passphraseArg;
|
||||
UniverseChannel.channelStore.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticates a client on the server side
|
||||
*/
|
||||
public async authenticateClient(passphraseArg: string): boolean {
|
||||
return passphraseArg === this.passphrase;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { Smartsocket, SmartsocketClient } from 'smartsocket';
|
||||
import * as url from 'url';
|
||||
@ -15,6 +14,10 @@ export interface IClientOptions {
|
||||
serverAddress: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* this class is for client side only!!!
|
||||
* allows connecting to a universe server
|
||||
*/
|
||||
export class UniverseClient {
|
||||
public options;
|
||||
private socketClient: plugins.smartsocket.SmartsocketClient;
|
||||
@ -29,11 +32,12 @@ export class UniverseClient {
|
||||
message: messageArg,
|
||||
payload: payloadArg
|
||||
};
|
||||
// TODO: User websocket connection if available
|
||||
await plugins.smartrequest.post(this.options.serverAddress, {
|
||||
requestBody
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public getMessageObservable() {
|
||||
if (!this.socketClient && !this.observableIntake) {
|
||||
const parsedURL = url.parse(this.options.serverAddress);
|
||||
@ -42,7 +46,7 @@ export class UniverseClient {
|
||||
password: 'UniverseClient',
|
||||
port: parseInt(parsedURL.port, 10),
|
||||
role: 'UniverseClient',
|
||||
url: parsedURL.hostname,
|
||||
url: parsedURL.hostname
|
||||
});
|
||||
this.observableIntake = new plugins.smartrx.ObservableIntake();
|
||||
this.socketClient.connect();
|
||||
@ -50,7 +54,7 @@ export class UniverseClient {
|
||||
return this.observableIntake.observable;
|
||||
}
|
||||
|
||||
public close () {
|
||||
public close() {
|
||||
this.socketClient.disconnect();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ import * as plugins from './smartuniverse.plugins';
|
||||
import { Timer, TimeStamp } from 'smarttime';
|
||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||
|
||||
/**
|
||||
* represents a message within a universe
|
||||
*/
|
||||
export class UniverseMessage {
|
||||
/**
|
||||
* public and unique id
|
||||
@ -11,28 +14,74 @@ export class UniverseMessage {
|
||||
* avoids duplications though
|
||||
*/
|
||||
public id: number;
|
||||
public universeStore: UniverseStore;
|
||||
public timestamp: TimeStamp;
|
||||
public message: string;
|
||||
public attachedPayload: any;
|
||||
public destructionTimer: Timer;
|
||||
|
||||
/**
|
||||
* the universe store the message is attached to
|
||||
*/
|
||||
public universeStore: UniverseStore;
|
||||
/**
|
||||
* enables unprotected grouping of messages for efficiency purposes.
|
||||
*/
|
||||
public universeChannel: string;
|
||||
|
||||
/**
|
||||
* time of creation
|
||||
*/
|
||||
public timestamp: TimeStamp;
|
||||
|
||||
/**
|
||||
* the actual message
|
||||
*/
|
||||
public message: string;
|
||||
|
||||
/**
|
||||
* any attached payloads. Can be of binary format.
|
||||
*/
|
||||
public attachedPayload: any;
|
||||
public destructionTimer: Timer; // a timer to take care of message destruction
|
||||
|
||||
/**
|
||||
* the constructor to create a universe message
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
constructor(
|
||||
parentUniverseStore: UniverseStore,
|
||||
messageArg: string,
|
||||
attachedPayloadArg: any,
|
||||
selfdestructAfterArg: number
|
||||
attachedPayloadArg: any
|
||||
) {
|
||||
this.universeStore = parentUniverseStore;
|
||||
this.timestamp = new TimeStamp();
|
||||
this.message = messageArg;
|
||||
this.attachedPayload = attachedPayloadArg;
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
this.destructionTimer.start();
|
||||
this.fallBackDestruction();
|
||||
}
|
||||
|
||||
// set up self destruction by removing this from the parent messageStore
|
||||
this.destructionTimer.completed.then(async () => {
|
||||
this.universeStore.messageStore.remove(this);
|
||||
public setUniverseStore (universeStoreArg: UniverseStore) {
|
||||
this.universeStore = universeStoreArg;
|
||||
}
|
||||
|
||||
public setDestructionTimer (selfdestructAfterArg: number) {
|
||||
if (selfdestructAfterArg) {
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
this.destructionTimer.start();
|
||||
|
||||
// set up self destruction by removing this from the parent messageStore
|
||||
this.destructionTimer.completed.then(async () => {
|
||||
this.universeStore.messageStore.remove(this);
|
||||
});
|
||||
} else {
|
||||
this.fallBackDestruction();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* prevents memory leaks if channels have no default
|
||||
*/
|
||||
private fallBackDestruction () {
|
||||
plugins.smartdelay.delayFor(1000).then(() => {
|
||||
if (!this.destructionTimer) {
|
||||
this.setDestructionTimer(6000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import { Objectmap } from 'lik';
|
||||
import { Observable } from 'rxjs';
|
||||
import { rxjs } from 'smartrx';
|
||||
|
||||
/**
|
||||
* universe store handles the creation, storage and retrieval of messages.
|
||||
*/
|
||||
export class UniverseStore {
|
||||
public standardMessageExpiry: number;
|
||||
public destructionTime: number = 60000;
|
||||
@ -22,10 +25,8 @@ export class UniverseStore {
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
public addMessage(messageArg, attachedPayloadArg) {
|
||||
this.messageStore.add(
|
||||
new UniverseMessage(this, messageArg, attachedPayloadArg, this.destructionTime)
|
||||
);
|
||||
public addMessage(messageArg: UniverseMessage) {
|
||||
this.messageStore.add(messageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,11 @@
|
||||
import * as lik from 'lik';
|
||||
import * as nodehash from 'nodehash';
|
||||
import * as path from 'path';
|
||||
import * as smartcli from 'smartcli';
|
||||
import * as smartdelay from 'smartdelay';
|
||||
import * as smartexpress from 'smartexpress';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartq from 'smartq';
|
||||
import * as smartrequest from 'smartrequest';
|
||||
import * as smartrx from 'smartrx';
|
||||
import * as smartsocket from 'smartsocket';
|
||||
@ -10,10 +13,13 @@ import * as smarttime from 'smarttime';
|
||||
|
||||
export {
|
||||
lik,
|
||||
nodehash,
|
||||
path,
|
||||
smartcli,
|
||||
smartdelay,
|
||||
smartexpress,
|
||||
smartfile,
|
||||
smartq,
|
||||
smartrx,
|
||||
smartrequest,
|
||||
smartsocket,
|
||||
|
Reference in New Issue
Block a user