fix(core): update
This commit is contained in:
parent
904a48d414
commit
39d3a0f2f8
19
package-lock.json
generated
19
package-lock.json
generated
@ -386,6 +386,17 @@
|
|||||||
"luxon": "^1.12.1"
|
"luxon": "^1.12.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartunique": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartunique/-/smartunique-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-xBu9ZB4C0BA0S/pbFFZn2ItPfnodPKpzrYIq1yN5XDs6OaookwcDF/iBwfS9+EYMSPENC9wAsOxg2RGMm4Qicw==",
|
||||||
|
"requires": {
|
||||||
|
"@types/shortid": "^0.0.29",
|
||||||
|
"@types/uuid": "^3.0.0",
|
||||||
|
"shortid": "^2.2.8",
|
||||||
|
"uuid": "^3.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/tapbundle": {
|
"@pushrocks/tapbundle": {
|
||||||
"version": "3.0.9",
|
"version": "3.0.9",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.9.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.9.tgz",
|
||||||
@ -566,6 +577,14 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/uuid": {
|
||||||
|
"version": "3.4.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.4.tgz",
|
||||||
|
"integrity": "sha512-tPIgT0GUmdJQNSHxp0X2jnpQfBSTfGxUMc/2CXBU2mnyTFVYVa2ojpoQ74w0U2yn2vw3jnC640+77lkFFpdVDw==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/vinyl": {
|
"@types/vinyl": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fvinyl/-/vinyl-2.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fvinyl/-/vinyl-2.0.3.tgz",
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"@pushrocks/smartrx": "^2.0.3",
|
"@pushrocks/smartrx": "^2.0.3",
|
||||||
"@pushrocks/smartsocket": "^1.1.27",
|
"@pushrocks/smartsocket": "^1.1.27",
|
||||||
"@pushrocks/smarttime": "^3.0.7"
|
"@pushrocks/smarttime": "^3.0.7",
|
||||||
|
"@pushrocks/smartunique": "^3.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,11 @@ tap.test('should get a observable correctly', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message correctly', async () => {
|
tap.test('should send a message correctly', async () => {
|
||||||
await testUniverseClient.sendMessage('greeting', {
|
await testUniverseClient.sendMessage({
|
||||||
anyBool: true
|
messageText: 'hello',
|
||||||
|
passphrase: 'wowza',
|
||||||
|
targetChannelName: 'channel1',
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
export interface IUniverseMessage {
|
export interface IMessageCreator {
|
||||||
messageText: string;
|
messageText: string;
|
||||||
targetChannelName: string;
|
|
||||||
passphrase: string;
|
|
||||||
payload?: string | number | any;
|
payload?: string | number | any;
|
||||||
payloadStringType?: 'Buffer' | 'string' | 'object';
|
payloadStringType?: 'Buffer' | 'string' | 'object';
|
||||||
|
targetChannelName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IUniverseMessage extends IMessageCreator {
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* time of creation
|
||||||
|
*/
|
||||||
|
timestamp: number;
|
||||||
|
passphrase: string;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,14 @@ export class ClientUniverse {
|
|||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendMessage(messageArg: interfaces.IUniverseMessage) {
|
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
||||||
const requestBody: interfaces.IUniverseMessage = messageArg;
|
const requestBody: interfaces.IUniverseMessage = {
|
||||||
|
id: plugins.smartunique.shortId(),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
passphrase: (await this.getChannel(messageArg.targetChannelName)).,
|
||||||
|
...messageArg,
|
||||||
|
|
||||||
|
};
|
||||||
const requestBodyString = JSON.stringify(requestBody);
|
const requestBodyString = JSON.stringify(requestBody);
|
||||||
// TODO: User websocket connection if available
|
// TODO: User websocket connection if available
|
||||||
const response = await plugins.smartrequest.postJson(`${this.options.serverAddress}/sendmessage` , {
|
const response = await plugins.smartrequest.postJson(`${this.options.serverAddress}/sendmessage` , {
|
||||||
@ -40,7 +46,7 @@ export class ClientUniverse {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getChannel(channelName: string, passphrase): Promise<ClientUniverseChannel> {
|
public async getChannel(channelName: string, passphraseArg?: string): Promise<ClientUniverseChannel> {
|
||||||
await this.checkConnection();
|
await this.checkConnection();
|
||||||
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
||||||
this,
|
this,
|
||||||
|
@ -9,9 +9,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
// ======
|
// ======
|
||||||
public static async createClientUniverseChannel(
|
public static async createClientUniverseChannel(
|
||||||
clientUniverseArg: ClientUniverse,
|
clientUniverseArg: ClientUniverse,
|
||||||
channelName: string
|
channelName: string,
|
||||||
|
passphraseArg: string
|
||||||
): Promise<ClientUniverseChannel> {
|
): Promise<ClientUniverseChannel> {
|
||||||
const clientChannel = new ClientUniverseChannel(clientUniverseArg);
|
const clientChannel = new ClientUniverseChannel(clientUniverseArg, passphraseArg);
|
||||||
await clientChannel.transmitSubscription();
|
await clientChannel.transmitSubscription();
|
||||||
return clientChannel;
|
return clientChannel;
|
||||||
}
|
}
|
||||||
@ -21,9 +22,11 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
// ========
|
// ========
|
||||||
|
|
||||||
public clientUniverse: ClientUniverse;
|
public clientUniverse: ClientUniverse;
|
||||||
|
public passphrase: string;
|
||||||
|
|
||||||
constructor(clientUniverseArg: ClientUniverse) {
|
constructor(clientUniverseArg: ClientUniverse, passphraseArg: string) {
|
||||||
this.clientUniverse = clientUniverseArg;
|
this.clientUniverse = clientUniverseArg;
|
||||||
|
this.passphrase = passphraseArg
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,13 +6,24 @@ export class ClientUniverseMessage implements interfaces.IUniverseMessage {
|
|||||||
// ======
|
// ======
|
||||||
// STATIC
|
// STATIC
|
||||||
// ======
|
// ======
|
||||||
public static createMessageFromPayload(messageArg: string, payloadArg: any) {
|
public static createMessageFromPayload(messageDescriptor: interfaces.IUniverseMessage) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========
|
// ========
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// ========
|
// ========
|
||||||
|
|
||||||
|
public id: string;
|
||||||
|
|
||||||
|
public timestamp: number;
|
||||||
|
public smartTimestamp: plugins.smarttime.TimeStamp;
|
||||||
|
|
||||||
|
public messageText: string;
|
||||||
|
public passphrase: string;
|
||||||
|
public payload: any;
|
||||||
|
public payloadStringType;
|
||||||
|
public targetChannelName: string;
|
||||||
constructor(messageArg, payloadArg) {}
|
constructor(messageArg, payloadArg) {}
|
||||||
|
|
||||||
getAsJsonForPayload () {
|
getAsJsonForPayload () {
|
||||||
|
@ -80,7 +80,8 @@ export class Universe {
|
|||||||
|
|
||||||
// lets create the http request route
|
// lets create the http request route
|
||||||
this.smartexpressServer.addRoute('/sendmessage', new Handler('POST', async (req, res) => {
|
this.smartexpressServer.addRoute('/sendmessage', new Handler('POST', async (req, res) => {
|
||||||
this.universeCache.addMessage(req.body);
|
const universeMessageInstance = new UniverseMessage(req.body);
|
||||||
|
this.universeCache.addMessage(universeMessageInstance);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// add websocket upgrade
|
// add websocket upgrade
|
||||||
|
@ -55,7 +55,7 @@ export class 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(
|
||||||
filter(messageArg => {
|
filter(messageArg => {
|
||||||
return messageArg.timestamp.isYoungerThanMilliSeconds(this.destructionTime);
|
return messageArg.smartTimestamp.isYoungerThanMilliSeconds(this.destructionTime);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return messageObservable;
|
return messageObservable;
|
||||||
|
@ -7,34 +7,30 @@ import { Timer, TimeStamp } from '@pushrocks/smarttime';
|
|||||||
import { Universe } from './smartuniverse.classes.universe';
|
import { Universe } from './smartuniverse.classes.universe';
|
||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||||
|
import { IUniverseMessage } from './interfaces';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* represents a message within a universe
|
* represents a message within a universe
|
||||||
* acts as a container to save message states like authentication status
|
* acts as a container to save message states like authentication status
|
||||||
*/
|
*/
|
||||||
export class UniverseMessage implements interfaces.IUniverseMessage {
|
export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||||
/**
|
|
||||||
* public and unique id
|
public id: string;
|
||||||
* numeric ascending
|
|
||||||
* adheres to time in milliseconds
|
public timestamp: number;
|
||||||
* -> meaning it describes the time of arrival
|
public smartTimestamp: TimeStamp;
|
||||||
* -> two messages received at the same time will count up the second one
|
|
||||||
* -> avoids duplications of messages
|
public messageText: string;
|
||||||
* -> may be changed to nanoseconds to ensure higher throughput
|
public passphrase: string;
|
||||||
*/
|
public payload: any;
|
||||||
public id: number;
|
public payloadStringType;
|
||||||
|
public targetChannelName: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the UniverseCache the message is attached to
|
* the UniverseCache the message is attached to
|
||||||
*/
|
*/
|
||||||
public universeCache: UniverseCache;
|
public universeCache: UniverseCache;
|
||||||
|
|
||||||
/**
|
|
||||||
* requestedChannelName
|
|
||||||
*/
|
|
||||||
public requestedChannelName: string;
|
|
||||||
public requestedChannelPassphrase: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enables unprotected grouping of messages for efficiency purposes.
|
* enables unprotected grouping of messages for efficiency purposes.
|
||||||
*/
|
*/
|
||||||
@ -46,19 +42,8 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
|||||||
public authenticated: boolean = null;
|
public authenticated: boolean = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* time of creation
|
* a destruction timer for this message
|
||||||
*/
|
*/
|
||||||
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
|
public destructionTimer: Timer; // a timer to take care of message destruction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,17 +51,12 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
|||||||
* @param messageArg
|
* @param messageArg
|
||||||
* @param attachedPayloadArg
|
* @param attachedPayloadArg
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(messageDescriptor: IUniverseMessage) {
|
||||||
messageArg: string,
|
this.smartTimestamp = new TimeStamp(this.timestamp);
|
||||||
requestedChannelNameArg: string,
|
this.messageText = messageDescriptor.messageText;
|
||||||
passphraseArg: string,
|
this.targetChannelName = messageDescriptor.targetChannelName;
|
||||||
attachedPayloadArg: any
|
this.passphrase = messageDescriptor.passphrase;
|
||||||
) {
|
this.payload = messageDescriptor.payload;
|
||||||
this.timestamp = new TimeStamp();
|
|
||||||
this.message = messageArg;
|
|
||||||
this.requestedChannelName = requestedChannelNameArg;
|
|
||||||
this.requestedChannelPassphrase = passphraseArg;
|
|
||||||
this.attachedPayload = attachedPayloadArg;
|
|
||||||
// prevent memory issues
|
// prevent memory issues
|
||||||
this.fallBackDestruction();
|
this.fallBackDestruction();
|
||||||
}
|
}
|
||||||
@ -102,7 +82,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
|
|||||||
/**
|
/**
|
||||||
* handles bad messages for further analysis
|
* handles bad messages for further analysis
|
||||||
*/
|
*/
|
||||||
handleAsBadMessage() {
|
public handleAsBadMessage() {
|
||||||
console.log('received a bad message');
|
console.log('received a bad message');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import * as smartrequest from '@pushrocks/smartrequest';
|
|||||||
import * as smartrx from '@pushrocks/smartrx';
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
import * as smartsocket from '@pushrocks/smartsocket';
|
import * as smartsocket from '@pushrocks/smartsocket';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
@ -25,5 +26,6 @@ export {
|
|||||||
smartrx,
|
smartrx,
|
||||||
smartrequest,
|
smartrequest,
|
||||||
smartsocket,
|
smartsocket,
|
||||||
smarttime
|
smarttime,
|
||||||
|
smartunique
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user