diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e3250b..b14b4ac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/package.json b/package.json index 41ce5e8..5ed1a36 100644 --- a/package.json +++ b/package.json @@ -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" ] -} +} \ No newline at end of file diff --git a/readme.md b/readme.md index 7686dec..e459b66 100644 --- a/readme.md +++ b/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. + +## 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) diff --git a/test/test.ts b/test/test.ts index ad04ea1..7280e5f 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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({ 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(); }); diff --git a/ts/smartuniverse.classes.broadcastevent.ts b/ts/smartuniverse.classes.broadcastevent.ts index 6d0b09c..3bba428 100644 --- a/ts/smartuniverse.classes.broadcastevent.ts +++ b/ts/smartuniverse.classes.broadcastevent.ts @@ -4,7 +4,5 @@ import * as plugins from './smartuniverse.plugins'; * broadcasts an event to multiple channels */ export class BroadcastEvent { - fire() { - - } -}; \ No newline at end of file + fire() {} +} diff --git a/ts/smartuniverse.classes.broadcastsubscription.ts b/ts/smartuniverse.classes.broadcastsubscription.ts index d44a852..ae5046c 100644 --- a/ts/smartuniverse.classes.broadcastsubscription.ts +++ b/ts/smartuniverse.classes.broadcastsubscription.ts @@ -1,5 +1,3 @@ import * as plugins from './smartuniverse.plugins'; -export class BroadcastSUbscription { - -} +export class BroadcastSUbscription {} diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index d3da4f1..9bf69b2 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -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 diff --git a/ts/smartuniverse.classes.clientuniversechannel.ts b/ts/smartuniverse.classes.clientuniversechannel.ts index 2854b1e..3e42a02 100644 --- a/ts/smartuniverse.classes.clientuniversechannel.ts +++ b/ts/smartuniverse.classes.clientuniversechannel.ts @@ -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) => void) { - return this.subject.subscribe( messageArg => { observingFunctionArg(messageArg); diff --git a/ts/smartuniverse.classes.reactionrequest.ts b/ts/smartuniverse.classes.reactionrequest.ts index 06086ca..c55931c 100644 --- a/ts/smartuniverse.classes.reactionrequest.ts +++ b/ts/smartuniverse.classes.reactionrequest.ts @@ -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 { +export interface IReactionRequestConstructorOptions< + T extends plugins.typedrequestInterfaces.ITypedRequest +> { method: T['method']; } @@ -15,9 +17,9 @@ export interface ICombinatorPayload, requestDataArg: T['request'], timeoutMillisArg=5000) { + public async fire( + channelsArg: Array, + requestDataArg: T['request'], + timeoutMillisArg = 5000 + ) { const subscriptionMap = new plugins.lik.Objectmap(); const reactionResult = new ReactionResult(); const requestId = plugins.smartunique.shortId(); for (const channel of channelsArg) { - subscriptionMap.add(channel.subscribe((messageArg: UniverseMessage> | ClientUniverseMessage>) => { - if (messageArg.messageText === 'reactionResponse' && messageArg.payload.typedRequestPayload.method === this.method) { - const payload: ICombinatorPayload = messageArg.payload; - if (payload.id !== requestId) { - return; + subscriptionMap.add( + channel.subscribe( + ( + messageArg: + | UniverseMessage> + | ClientUniverseMessage> + ) => { + if ( + messageArg.messageText === 'reactionResponse' && + messageArg.payload.typedRequestPayload.method === this.method + ) { + const payload: ICombinatorPayload = messageArg.payload; + if (payload.id !== requestId) { + return; + } + reactionResult.pushReactionResponse(payload.typedRequestPayload.response); + } } - reactionResult.pushReactionResponse(payload.typedRequestPayload.response); - } - })); + ) + ); const payload: ICombinatorPayload = { id: requestId, typedRequestPayload: { diff --git a/ts/smartuniverse.classes.reactionresponse.ts b/ts/smartuniverse.classes.reactionresponse.ts index e8263eb..512020d 100644 --- a/ts/smartuniverse.classes.reactionresponse.ts +++ b/ts/smartuniverse.classes.reactionresponse.ts @@ -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 = (dataArg: T['request']) => Promise; +export type TReactionResponseFuncDef = ( + dataArg: T['request'] +) => Promise; export interface IReactionResponseConstructorOptions< T extends plugins.typedrequestInterfaces.ITypedRequest @@ -42,7 +44,9 @@ export class ReactionResponse = { ...messageArg.payload, typedRequestPayload: { @@ -52,7 +56,7 @@ export class ReactionResponse = []; private completeDeferred = plugins.smartpromise.defer>(); - constructor () { + constructor() { this.resultSubscribe(responseArg => { this.endResult.push(responseArg); }); @@ -42,7 +42,7 @@ export class ReactionResult 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) { diff --git a/ts/smartuniverse.plugins.ts b/ts/smartuniverse.plugins.ts index 5e62475..bdbe119 100644 --- a/ts/smartuniverse.plugins.ts +++ b/ts/smartuniverse.plugins.ts @@ -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';