fix(core): update

This commit is contained in:
Philipp Kunz 2019-11-09 13:00:30 +01:00
parent e413a8116d
commit afb4e3339a
13 changed files with 123 additions and 89 deletions

View File

@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@ -18,10 +18,11 @@ stages:
mirror:
stage: security
script:
- npmci git mirror
- npmci git mirror
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
snyk:
stage: security
@ -31,8 +32,9 @@ snyk:
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# test stage
@ -41,37 +43,40 @@ snyk:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- priv
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install lts
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
@ -81,33 +86,35 @@ codequality:
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@ -115,5 +122,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

View File

@ -40,14 +40,14 @@
"@pushrocks/smartunique": "^3.0.1"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}
}

View File

@ -47,6 +47,11 @@ myUniverse.start(8765); // start the server and provide the port on which to lis
All your microservices represents clients in the universe that may talk to each other using the universe server.
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)

View File

@ -74,7 +74,7 @@ tap.test('a second client should be able to subscibe', async () => {
await testClientUniverse2.start();
});
tap.test('should receive a message correctly', async (tools) => {
tap.test('should receive a message correctly', async tools => {
const done = tools.defer();
const testChannel = testClientUniverse.getChannel(testChannelData.channelName);
const testChannel2 = testClientUniverse2.getChannel(testChannelData.channelName);
@ -91,7 +91,7 @@ tap.test('should receive a message correctly', async (tools) => {
});
interface IDemoReqRes {
method: 'demo',
method: 'demo';
request: {
wowso: string;
};
@ -114,19 +114,22 @@ tap.test('ReactionRequest and ReactionResponse should work', async () => {
const reactionRequest = new smartuniverse.ReactionRequest<IDemoReqRes>({
method: 'demo'
});
const reactionResult = await reactionRequest.fire([testClientUniverse2.getChannel(testChannelData.channelName)], {
wowso: 'wowza'
});
const reactionResult = await reactionRequest.fire(
[testClientUniverse2.getChannel(testChannelData.channelName)],
{
wowso: 'wowza'
}
);
const result = await reactionResult.getFirstResult();
console.log(result);
});
tap.test('should disconnect the client correctly', async (tools) => {
tap.test('should disconnect the client correctly', async tools => {
await testClientUniverse.stop();
await testClientUniverse2.stop();
});
tap.test('should end the server correctly', async (tools) => {
tap.test('should end the server correctly', async tools => {
await testUniverse.stopServer();
});

View File

@ -4,7 +4,5 @@ import * as plugins from './smartuniverse.plugins';
* broadcasts an event to multiple channels
*/
export class BroadcastEvent<T> {
fire() {
}
};
fire() {}
}

View File

@ -1,5 +1,3 @@
import * as plugins from './smartuniverse.plugins';
export class BroadcastSUbscription {
}
export class BroadcastSUbscription {}

View File

@ -98,7 +98,7 @@ export class ClientUniverse {
this.smartsocketClient = new SmartsocketClient(socketConfig);
this.smartsocketClient.eventSubject.subscribe(async eventArg => {
switch(eventArg) {
switch (eventArg) {
case 'disconnected':
this.disconnect('upstreamEvent');
}
@ -165,7 +165,10 @@ export class ClientUniverse {
}
}
public async disconnect(reason: 'upstreamEvent' | 'triggered' = 'triggered', tryReconnect = false) {
public async disconnect(
reason: 'upstreamEvent' | 'triggered' = 'triggered',
tryReconnect = false
) {
if (reason === 'triggered') {
const smartsocketToDisconnect = this.smartsocketClient;
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere

View File

@ -54,7 +54,6 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
* tells the universe about this instances interest into a channel
*/
public subscribe(observingFunctionArg: (messageArg: ClientUniverseMessage<any>) => void) {
return this.subject.subscribe(
messageArg => {
observingFunctionArg(messageArg);

View File

@ -5,7 +5,9 @@ import { ReactionResult } from './smartuniverse.classes.reactionresult';
import { UniverseMessage } from './smartuniverse.classes.universemessage';
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
export interface IReactionRequestConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
export interface IReactionRequestConstructorOptions<
T extends plugins.typedrequestInterfaces.ITypedRequest
> {
method: T['method'];
}
@ -15,9 +17,9 @@ export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITy
*/
id: string;
typedRequestPayload: {
method: T['method'],
request : T['request'],
response: T['response']
method: T['method'];
request: T['request'];
response: T['response'];
};
}
@ -28,20 +30,35 @@ export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequ
this.method = optionsArg.method;
}
public async fire(channelsArg: Array<UniverseChannel | ClientUniverseChannel>, requestDataArg: T['request'], timeoutMillisArg=5000) {
public async fire(
channelsArg: Array<UniverseChannel | ClientUniverseChannel>,
requestDataArg: T['request'],
timeoutMillisArg = 5000
) {
const subscriptionMap = new plugins.lik.Objectmap<plugins.smartrx.rxjs.Subscription>();
const reactionResult = new ReactionResult<T>();
const requestId = plugins.smartunique.shortId();
for (const channel of channelsArg) {
subscriptionMap.add(channel.subscribe((messageArg: UniverseMessage<ICombinatorPayload<T>> | ClientUniverseMessage<ICombinatorPayload<T>>) => {
if (messageArg.messageText === 'reactionResponse' && messageArg.payload.typedRequestPayload.method === this.method) {
const payload: ICombinatorPayload<T> = messageArg.payload;
if (payload.id !== requestId) {
return;
subscriptionMap.add(
channel.subscribe(
(
messageArg:
| UniverseMessage<ICombinatorPayload<T>>
| ClientUniverseMessage<ICombinatorPayload<T>>
) => {
if (
messageArg.messageText === 'reactionResponse' &&
messageArg.payload.typedRequestPayload.method === this.method
) {
const payload: ICombinatorPayload<T> = messageArg.payload;
if (payload.id !== requestId) {
return;
}
reactionResult.pushReactionResponse(payload.typedRequestPayload.response);
}
}
reactionResult.pushReactionResponse(payload.typedRequestPayload.response);
}
}));
)
);
const payload: ICombinatorPayload<T> = {
id: requestId,
typedRequestPayload: {

View File

@ -6,7 +6,9 @@ import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversecha
import { UniverseMessage } from './smartuniverse.classes.universemessage';
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
export type TReactionResponseFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (dataArg: T['request']) => Promise<T['response']>;
export type TReactionResponseFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (
dataArg: T['request']
) => Promise<T['response']>;
export interface IReactionResponseConstructorOptions<
T extends plugins.typedrequestInterfaces.ITypedRequest
@ -42,7 +44,9 @@ export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedReq
messageArg.messageText === 'reactionRequest' &&
messageArg.payload.typedRequestPayload.method === this.method
) {
const response: T['response'] = await this.funcDef(messageArg.payload.typedRequestPayload.request);
const response: T['response'] = await this.funcDef(
messageArg.payload.typedRequestPayload.request
);
const payload: ICombinatorPayload<T> = {
...messageArg.payload,
typedRequestPayload: {
@ -52,7 +56,7 @@ export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedReq
};
channelArg.sendMessage({
messageText: 'reactionResponse',
payload
payload
});
}
}

View File

@ -6,7 +6,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
private endResult: Array<T['response']> = [];
private completeDeferred = plugins.smartpromise.defer<Array<T['response']>>();
constructor () {
constructor() {
this.resultSubscribe(responseArg => {
this.endResult.push(responseArg);
});
@ -42,7 +42,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
public async pushReactionResponse(responseArg: T['response']) {
this.resultReplaySubject.next(responseArg);
}
/**
* completes the ReactionResult
*/

View File

@ -78,12 +78,14 @@ export class UniverseMessage<T> implements interfaces.IUniverseMessage {
this.destructionTimer = new Timer(selfdestructAfterArg);
this.destructionTimer.start();
// set up self destruction by removing this from the parent messageCache
this.destructionTimer.completed.then(async () => {
this.universeCache.messageMap.remove(this);
}).catch(err => {
console.log(err);
console.log(this);
});
this.destructionTimer.completed
.then(async () => {
this.universeCache.messageMap.remove(this);
})
.catch(err => {
console.log(err);
console.log(this);
});
} else {
plugins.smartdelay.delayFor(1000).then(() => {
if (!this.destructionTimer) {

View File

@ -6,9 +6,7 @@ export { path };
// apiglobal scope
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
export {
typedrequestInterfaces
};
export { typedrequestInterfaces };
// pushrocks scope
import * as lik from '@pushrocks/lik';