fix(core): update
This commit is contained in:
parent
e413a8116d
commit
afb4e3339a
@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,10 +18,11 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
@ -31,8 +32,9 @@ snyk:
|
|||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -41,37 +43,40 @@ snyk:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -81,33 +86,35 @@ codequality:
|
|||||||
allow_failure: true
|
allow_failure: true
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -115,5 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
12
package.json
12
package.json
@ -40,12 +40,12 @@
|
|||||||
"@pushrocks/smartunique": "^3.0.1"
|
"@pushrocks/smartunique": "^3.0.1"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_web/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
@ -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.
|
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.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
17
test/test.ts
17
test/test.ts
@ -74,7 +74,7 @@ tap.test('a second client should be able to subscibe', async () => {
|
|||||||
await testClientUniverse2.start();
|
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 done = tools.defer();
|
||||||
const testChannel = testClientUniverse.getChannel(testChannelData.channelName);
|
const testChannel = testClientUniverse.getChannel(testChannelData.channelName);
|
||||||
const testChannel2 = testClientUniverse2.getChannel(testChannelData.channelName);
|
const testChannel2 = testClientUniverse2.getChannel(testChannelData.channelName);
|
||||||
@ -91,7 +91,7 @@ tap.test('should receive a message correctly', async (tools) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
interface IDemoReqRes {
|
interface IDemoReqRes {
|
||||||
method: 'demo',
|
method: 'demo';
|
||||||
request: {
|
request: {
|
||||||
wowso: string;
|
wowso: string;
|
||||||
};
|
};
|
||||||
@ -114,19 +114,22 @@ tap.test('ReactionRequest and ReactionResponse should work', async () => {
|
|||||||
const reactionRequest = new smartuniverse.ReactionRequest<IDemoReqRes>({
|
const reactionRequest = new smartuniverse.ReactionRequest<IDemoReqRes>({
|
||||||
method: 'demo'
|
method: 'demo'
|
||||||
});
|
});
|
||||||
const reactionResult = await reactionRequest.fire([testClientUniverse2.getChannel(testChannelData.channelName)], {
|
const reactionResult = await reactionRequest.fire(
|
||||||
wowso: 'wowza'
|
[testClientUniverse2.getChannel(testChannelData.channelName)],
|
||||||
});
|
{
|
||||||
|
wowso: 'wowza'
|
||||||
|
}
|
||||||
|
);
|
||||||
const result = await reactionResult.getFirstResult();
|
const result = await reactionResult.getFirstResult();
|
||||||
console.log(result);
|
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 testClientUniverse.stop();
|
||||||
await testClientUniverse2.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();
|
await testUniverse.stopServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,7 +4,5 @@ import * as plugins from './smartuniverse.plugins';
|
|||||||
* broadcasts an event to multiple channels
|
* broadcasts an event to multiple channels
|
||||||
*/
|
*/
|
||||||
export class BroadcastEvent<T> {
|
export class BroadcastEvent<T> {
|
||||||
fire() {
|
fire() {}
|
||||||
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
export class BroadcastSUbscription {
|
export class BroadcastSUbscription {}
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -98,7 +98,7 @@ export class ClientUniverse {
|
|||||||
this.smartsocketClient = new SmartsocketClient(socketConfig);
|
this.smartsocketClient = new SmartsocketClient(socketConfig);
|
||||||
|
|
||||||
this.smartsocketClient.eventSubject.subscribe(async eventArg => {
|
this.smartsocketClient.eventSubject.subscribe(async eventArg => {
|
||||||
switch(eventArg) {
|
switch (eventArg) {
|
||||||
case 'disconnected':
|
case 'disconnected':
|
||||||
this.disconnect('upstreamEvent');
|
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') {
|
if (reason === 'triggered') {
|
||||||
const smartsocketToDisconnect = this.smartsocketClient;
|
const smartsocketToDisconnect = this.smartsocketClient;
|
||||||
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
|
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
|
||||||
|
@ -54,7 +54,6 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
* tells the universe about this instances interest into a channel
|
* tells the universe about this instances interest into a channel
|
||||||
*/
|
*/
|
||||||
public subscribe(observingFunctionArg: (messageArg: ClientUniverseMessage<any>) => void) {
|
public subscribe(observingFunctionArg: (messageArg: ClientUniverseMessage<any>) => void) {
|
||||||
|
|
||||||
return this.subject.subscribe(
|
return this.subject.subscribe(
|
||||||
messageArg => {
|
messageArg => {
|
||||||
observingFunctionArg(messageArg);
|
observingFunctionArg(messageArg);
|
||||||
|
@ -5,7 +5,9 @@ import { ReactionResult } from './smartuniverse.classes.reactionresult';
|
|||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
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'];
|
method: T['method'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,9 +17,9 @@ export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITy
|
|||||||
*/
|
*/
|
||||||
id: string;
|
id: string;
|
||||||
typedRequestPayload: {
|
typedRequestPayload: {
|
||||||
method: T['method'],
|
method: T['method'];
|
||||||
request : T['request'],
|
request: T['request'];
|
||||||
response: T['response']
|
response: T['response'];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,20 +30,35 @@ export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequ
|
|||||||
this.method = optionsArg.method;
|
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 subscriptionMap = new plugins.lik.Objectmap<plugins.smartrx.rxjs.Subscription>();
|
||||||
const reactionResult = new ReactionResult<T>();
|
const reactionResult = new ReactionResult<T>();
|
||||||
const requestId = plugins.smartunique.shortId();
|
const requestId = plugins.smartunique.shortId();
|
||||||
for (const channel of channelsArg) {
|
for (const channel of channelsArg) {
|
||||||
subscriptionMap.add(channel.subscribe((messageArg: UniverseMessage<ICombinatorPayload<T>> | ClientUniverseMessage<ICombinatorPayload<T>>) => {
|
subscriptionMap.add(
|
||||||
if (messageArg.messageText === 'reactionResponse' && messageArg.payload.typedRequestPayload.method === this.method) {
|
channel.subscribe(
|
||||||
const payload: ICombinatorPayload<T> = messageArg.payload;
|
(
|
||||||
if (payload.id !== requestId) {
|
messageArg:
|
||||||
return;
|
| 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> = {
|
const payload: ICombinatorPayload<T> = {
|
||||||
id: requestId,
|
id: requestId,
|
||||||
typedRequestPayload: {
|
typedRequestPayload: {
|
||||||
|
@ -6,7 +6,9 @@ import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversecha
|
|||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
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<
|
export interface IReactionResponseConstructorOptions<
|
||||||
T extends plugins.typedrequestInterfaces.ITypedRequest
|
T extends plugins.typedrequestInterfaces.ITypedRequest
|
||||||
@ -42,7 +44,9 @@ export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedReq
|
|||||||
messageArg.messageText === 'reactionRequest' &&
|
messageArg.messageText === 'reactionRequest' &&
|
||||||
messageArg.payload.typedRequestPayload.method === this.method
|
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> = {
|
const payload: ICombinatorPayload<T> = {
|
||||||
...messageArg.payload,
|
...messageArg.payload,
|
||||||
typedRequestPayload: {
|
typedRequestPayload: {
|
||||||
|
@ -6,7 +6,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
|
|||||||
private endResult: Array<T['response']> = [];
|
private endResult: Array<T['response']> = [];
|
||||||
private completeDeferred = plugins.smartpromise.defer<Array<T['response']>>();
|
private completeDeferred = plugins.smartpromise.defer<Array<T['response']>>();
|
||||||
|
|
||||||
constructor () {
|
constructor() {
|
||||||
this.resultSubscribe(responseArg => {
|
this.resultSubscribe(responseArg => {
|
||||||
this.endResult.push(responseArg);
|
this.endResult.push(responseArg);
|
||||||
});
|
});
|
||||||
|
@ -78,12 +78,14 @@ export class UniverseMessage<T> implements interfaces.IUniverseMessage {
|
|||||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||||
this.destructionTimer.start();
|
this.destructionTimer.start();
|
||||||
// set up self destruction by removing this from the parent messageCache
|
// set up self destruction by removing this from the parent messageCache
|
||||||
this.destructionTimer.completed.then(async () => {
|
this.destructionTimer.completed
|
||||||
this.universeCache.messageMap.remove(this);
|
.then(async () => {
|
||||||
}).catch(err => {
|
this.universeCache.messageMap.remove(this);
|
||||||
console.log(err);
|
})
|
||||||
console.log(this);
|
.catch(err => {
|
||||||
});
|
console.log(err);
|
||||||
|
console.log(this);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
plugins.smartdelay.delayFor(1000).then(() => {
|
plugins.smartdelay.delayFor(1000).then(() => {
|
||||||
if (!this.destructionTimer) {
|
if (!this.destructionTimer) {
|
||||||
|
@ -6,9 +6,7 @@ export { path };
|
|||||||
// apiglobal scope
|
// apiglobal scope
|
||||||
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||||
|
|
||||||
export {
|
export { typedrequestInterfaces };
|
||||||
typedrequestInterfaces
|
|
||||||
};
|
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
|
Loading…
Reference in New Issue
Block a user