fix(types,client,server): improve type safety and harden client/server message handling
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"@git.zone/cli": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartuniverse",
|
||||||
|
"description": "A messaging service enabling secure, reactive communication between microservices.",
|
||||||
|
"npmPackagename": "@push.rocks/smartuniverse",
|
||||||
|
"license": "MIT",
|
||||||
|
"projectDomain": "push.rocks"
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
},
|
||||||
|
"@git.zone/tsbundle": {
|
||||||
|
"bundles": [
|
||||||
|
{
|
||||||
|
"from": "./ts/index.ts",
|
||||||
|
"to": "./dist_bundle/bundle.js",
|
||||||
|
"outputMode": "bundle",
|
||||||
|
"bundler": "esbuild"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
}
|
||||||
|
}
|
||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-05-01 - 1.0.109 - fix(types,client,server)
|
||||||
|
improve type safety and harden client/server message handling
|
||||||
|
|
||||||
|
- add explicit unsubscribe socket request typing and typed processMessage responses for authenticated, missing-channel, and unauthenticated cases
|
||||||
|
- guard client channel subscription and message posting when no socket connection is available
|
||||||
|
- tighten generic message typing and optional state handling across universe, client message, and reaction request classes
|
||||||
|
- modernize package and tooling configuration, including renamed dependencies, pnpm workspace metadata, and updated node-based tests
|
||||||
|
|
||||||
|
## 2024-05-29 - 1.0.108 - maintenance
|
||||||
|
Repository metadata and TypeScript configuration were updated across the latest release cycle.
|
||||||
|
|
||||||
|
- Updated project description
|
||||||
|
- Updated TypeScript configuration
|
||||||
|
- Updated `npmextra.json` githost settings
|
||||||
|
|
||||||
|
## 2023-07-25 - 1.0.106 - 1.0.107 - core
|
||||||
|
This version range contains repeated trivial core update fixes with no further detail.
|
||||||
|
|
||||||
|
- Applied minor `core` update fixes across versions `1.0.106` and `1.0.107`
|
||||||
|
|
||||||
|
## 2020-09-24 - 1.0.98 - 1.0.105 - core
|
||||||
|
This version range contains repeated trivial core update fixes with no further detail.
|
||||||
|
|
||||||
|
- Applied minor `core` update fixes across versions `1.0.98` through `1.0.105`
|
||||||
|
|
||||||
|
## 2019-08-13 - 1.0.57 - 1.0.97 - core
|
||||||
|
This version range contains repeated trivial core update fixes with no further detail.
|
||||||
|
|
||||||
|
- Applied minor `core` update fixes across versions `1.0.57` through `1.0.97`
|
||||||
|
|
||||||
|
## 2019-06-06 - 1.0.47 - 1.0.56 - core
|
||||||
|
This version range contains repeated trivial core update fixes with no further detail.
|
||||||
|
|
||||||
|
- Applied minor `core` update fixes across versions `1.0.47` through `1.0.56`
|
||||||
|
|
||||||
|
## 2019-04-11 - 1.0.25 - 1.0.46 - core
|
||||||
|
This version range contains repeated trivial core update fixes with no further detail.
|
||||||
|
|
||||||
|
- Applied minor `core` update fixes across versions `1.0.25` through `1.0.46`
|
||||||
|
|
||||||
|
## 2019-01-30 - 1.0.23 - dependencies
|
||||||
|
Dependency maintenance updates were made in this release cycle.
|
||||||
|
|
||||||
|
- Updated project dependencies
|
||||||
|
|
||||||
|
## 2018-05-30 - 1.0.22 - websocket
|
||||||
|
The websocket infrastructure was reworked.
|
||||||
|
|
||||||
|
- Switched to the complete websocket infrastructure
|
||||||
|
|
||||||
|
## 2018-05-28 - 1.0.21 - core
|
||||||
|
Core behavior was updated to support a transparent universe model.
|
||||||
|
|
||||||
|
- Updated core to transparent universe handling
|
||||||
|
|
||||||
|
## 2018-05-26 - 1.0.20 - UniverseMessage / UniverseChannel
|
||||||
|
Authentication handling for channel-based messages was improved.
|
||||||
|
|
||||||
|
- Improved authentication for messages associated with channels
|
||||||
|
|
||||||
|
## 2018-05-24 - 1.0.19 - dependencies
|
||||||
|
Dependency maintenance updates were made.
|
||||||
|
|
||||||
|
- Updated project dependencies
|
||||||
|
|
||||||
|
## 2018-05-24 - 1.0.18 - UniverseChannel
|
||||||
|
Channel handling was improved.
|
||||||
|
|
||||||
|
- Improved `UniverseChannel` handling
|
||||||
|
|
||||||
|
## 2018-05-23 - 1.0.17 - core
|
||||||
|
Core channel handling was improved across the release.
|
||||||
|
|
||||||
|
- Improved channel handling in core
|
||||||
|
|
||||||
|
## 2018-05-23 - 1.0.16 - structure
|
||||||
|
Project structure and formatting were cleaned up.
|
||||||
|
|
||||||
|
- Formatted the TypeScript codebase
|
||||||
|
|
||||||
|
## 2018-05-19 - 1.0.15 - core
|
||||||
|
Release preparation work was completed.
|
||||||
|
|
||||||
|
- Prepared core for release
|
||||||
|
|
||||||
|
## 2018-05-07 - 1.0.14 - message
|
||||||
|
The message layer was refactored.
|
||||||
|
|
||||||
|
- Refactored message-related functionality
|
||||||
|
|
||||||
|
## 2018-04-29 - 1.0.9 - 1.0.13 - maintenance
|
||||||
|
This version range mainly contains standards, CI, and general maintenance updates.
|
||||||
|
|
||||||
|
- Moved the project toward TypeScript predominance
|
||||||
|
- Updated the project to latest standards
|
||||||
|
- Updated CI and CI configuration
|
||||||
|
- Included general maintenance updates with limited detail
|
||||||
|
|
||||||
|
## 2018-04-05 - 1.0.8 - documentation
|
||||||
|
Documentation was improved.
|
||||||
|
|
||||||
|
- Added a better README
|
||||||
|
|
||||||
|
## 2018-04-05 - 1.0.7 - package
|
||||||
|
Package publishing configuration was updated.
|
||||||
|
|
||||||
|
- Added npm access level configuration
|
||||||
|
|
||||||
|
## 2018-04-04 - 1.0.5 - scope
|
||||||
|
Project package scope was updated.
|
||||||
|
|
||||||
|
- Migrated to the new pushrocks scope
|
||||||
|
|
||||||
|
## 2018-03-27 - 1.0.4 - networking
|
||||||
|
Connection lifecycle handling was improved.
|
||||||
|
|
||||||
|
- Fixed opening and closing behavior on both server and client sides
|
||||||
|
|
||||||
|
## 2018-03-17 - 1.0.3 - messaging
|
||||||
|
Message delivery and compatibility issues were addressed.
|
||||||
|
|
||||||
|
- Fixed RxJS incompatibility
|
||||||
|
- Corrected message sending behavior
|
||||||
|
|
||||||
|
## 2018-03-15 - 1.0.2 - core
|
||||||
|
Initial runtime functionality was established.
|
||||||
|
|
||||||
|
- Got the project running
|
||||||
|
|
||||||
|
## 2018-03-08 - 1.0.1 - testing
|
||||||
|
Initial test setup was updated.
|
||||||
|
|
||||||
|
- Updated the initial test
|
||||||
|
|
||||||
|
## 2018-03-07 - 1.0.1 - project
|
||||||
|
Initial project setup.
|
||||||
|
|
||||||
|
- Initial commit
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
Copyright (c) 2018 Lossless GmbH (hello@lossless.com)
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2026 Task Venture Capital GmbH
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
+13
-6
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"@git.zone/cli": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
@@ -21,13 +21,20 @@
|
|||||||
"websocket",
|
"websocket",
|
||||||
"scalability"
|
"scalability"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"@git.zone/tsdoc": {
|
||||||
"npmGlobalTools": [],
|
|
||||||
"npmAccessLevel": "public"
|
|
||||||
},
|
|
||||||
"tsdoc": {
|
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+23
-19
@@ -5,35 +5,36 @@
|
|||||||
"description": "A messaging service enabling secure, reactive communication between microservices.",
|
"description": "A messaging service enabling secure, reactive communication between microservices.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Task Venture Capital GmbH <hello@task.vc>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "tstest test/ --verbose",
|
||||||
"testManual": "(tsrun test/test.ts)",
|
"testManual": "tsrun test/",
|
||||||
"build": "(tsbuild --allowimplicitany && tsbundle --from ./ts/index.ts --to dist_bundle/bundle.js)",
|
"build": "tsbuild && tsbundle",
|
||||||
"format": "(gitzone format)",
|
"format": "gitzone format",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@gitzone/tsbundle": "^2.0.8",
|
"@git.zone/tsbundle": "^2.10.1",
|
||||||
"@gitzone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^2.0.3",
|
||||||
"@gitzone/tstest": "^1.0.77",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@push.rocks/tapbundle": "^5.0.12",
|
"@types/lodash.clonedeep": "^4.5.9",
|
||||||
"@types/node": "^20.4.4"
|
"@types/node": "^25.6.0",
|
||||||
|
"@types/picomatch": "^4.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest-interfaces": "^2.0.1",
|
"@api.global/typedrequest-interfaces": "^3.0.19",
|
||||||
"@apiglobal/typedserver": "^2.0.65",
|
"@api.global/typedserver": "^8.4.6",
|
||||||
"@push.rocks/isohash": "^2.0.1",
|
"@push.rocks/isohash": "^2.0.1",
|
||||||
"@push.rocks/isounique": "^1.0.5",
|
"@push.rocks/isounique": "^1.0.5",
|
||||||
"@push.rocks/lik": "^6.0.3",
|
"@push.rocks/lik": "^6.4.1",
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@push.rocks/smartlog": "^3.0.3",
|
"@push.rocks/smartlog": "^3.2.2",
|
||||||
"@push.rocks/smartpromise": "^4.0.2",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@push.rocks/smartrx": "^3.0.6",
|
"@push.rocks/smartrx": "^3.0.6",
|
||||||
"@push.rocks/smartsocket": "^2.0.20",
|
"@push.rocks/smartsocket": "^4.0.1",
|
||||||
"@push.rocks/smarttime": "^4.0.4",
|
"@push.rocks/smarttime": "^4.2.3",
|
||||||
"@push.rocks/smarturl": "^3.0.7"
|
"@push.rocks/smarturl": "^3.0.7"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -45,6 +46,8 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
@@ -68,5 +71,6 @@
|
|||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://code.foss.global/push.rocks/smartuniverse.git"
|
"url": "https://code.foss.global/push.rocks/smartuniverse.git"
|
||||||
}
|
},
|
||||||
|
"packageManager": "pnpm@10.28.2"
|
||||||
}
|
}
|
||||||
Generated
+8919
-3742
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
|||||||
|
onlyBuiltDependencies:
|
||||||
|
- esbuild
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
|
||||||
import * as smartuniverse from '../ts/index.js';
|
import * as smartuniverse from '../ts/index.js';
|
||||||
|
|
||||||
let testUniverse: smartuniverse.Universe;
|
let testUniverse: smartuniverse.Universe;
|
||||||
@@ -131,4 +130,4 @@ tap.test('should end the server correctly', async (tools) => {
|
|||||||
await testUniverse.stopServer();
|
await testUniverse.stopServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartuniverse',
|
name: '@push.rocks/smartuniverse',
|
||||||
version: '1.0.108',
|
version: '1.0.109',
|
||||||
description: 'messaging service for your micro services'
|
description: 'A messaging service enabling secure, reactive communication between microservices.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ export interface ISocketRequest_ProcessMessage {
|
|||||||
method: 'processMessage';
|
method: 'processMessage';
|
||||||
request: interfaces.IUniverseMessage;
|
request: interfaces.IUniverseMessage;
|
||||||
response: {
|
response: {
|
||||||
messageStatus: 'ok' | 'channel not found';
|
messageStatus: 'ok' | 'channel not found' | 'authentication required';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ISocketRequest_Unsubscribe {
|
||||||
|
method: 'unsubscribe';
|
||||||
|
request: interfaces.IServerUnsubscribeActionPayload;
|
||||||
|
response: {};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
export interface IMessageCreator {
|
export interface IMessageCreator<T = any> {
|
||||||
messageText: string;
|
messageText: string;
|
||||||
payload?: string | number | any;
|
payload?: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A universe
|
* A universe
|
||||||
*/
|
*/
|
||||||
export interface IUniverseMessage extends IMessageCreator {
|
export interface IUniverseMessage<T = any> extends IMessageCreator<T> {
|
||||||
id: string;
|
id: string;
|
||||||
/**
|
/**
|
||||||
* time of creation
|
* time of creation
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './smartuniverse.plugins.js';
|
import * as plugins from './smartuniverse.plugins.js';
|
||||||
import { Smartsocket, SmartsocketClient } from '@push.rocks/smartsocket';
|
import { SmartsocketClient } from '@push.rocks/smartsocket';
|
||||||
|
|
||||||
import * as interfaces from './interfaces/index.js';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export interface IClientOptions {
|
|||||||
*/
|
*/
|
||||||
export class ClientUniverse {
|
export class ClientUniverse {
|
||||||
public options: IClientOptions;
|
public options: IClientOptions;
|
||||||
public smartsocketClient: plugins.smartsocket.SmartsocketClient;
|
public smartsocketClient?: plugins.smartsocket.SmartsocketClient;
|
||||||
public messageRxjsSubject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage<any>>();
|
public messageRxjsSubject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage<any>>();
|
||||||
public clientUniverseCache = new ClientUniverseCache();
|
public clientUniverseCache = new ClientUniverseCache();
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ export class ClientUniverse {
|
|||||||
* remove a a achannel
|
* remove a a achannel
|
||||||
* @param messageArg
|
* @param messageArg
|
||||||
*/
|
*/
|
||||||
public removeChannel(channelNameArg, notifyServer = true) {
|
public removeChannel(channelNameArg: string, notifyServer = true) {
|
||||||
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemoveSync(
|
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemoveSync(
|
||||||
(channelItemArg) => {
|
(channelItemArg) => {
|
||||||
return channelItemArg.name === channelNameArg;
|
return channelItemArg.name === channelNameArg;
|
||||||
@@ -110,9 +110,10 @@ export class ClientUniverse {
|
|||||||
/**
|
/**
|
||||||
* should handle a forced unsubscription by the server
|
* should handle a forced unsubscription by the server
|
||||||
*/
|
*/
|
||||||
const socketFunctionUnsubscribe = new plugins.smartsocket.SocketFunction({
|
const socketFunctionUnsubscribe =
|
||||||
|
new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_Unsubscribe>({
|
||||||
funcName: 'unsubscribe',
|
funcName: 'unsubscribe',
|
||||||
funcDef: async (dataArg: interfaces.IServerUnsubscribeActionPayload) => {
|
funcDef: async (dataArg) => {
|
||||||
const channel = this.clientUniverseCache.channelMap.findSync((channelArg) => {
|
const channel = this.clientUniverseCache.channelMap.findSync((channelArg) => {
|
||||||
return channelArg.name === dataArg.name;
|
return channelArg.name === dataArg.name;
|
||||||
});
|
});
|
||||||
@@ -169,7 +170,7 @@ export class ClientUniverse {
|
|||||||
const instructDisconnect = async () => {
|
const instructDisconnect = async () => {
|
||||||
if (this.smartsocketClient) {
|
if (this.smartsocketClient) {
|
||||||
const smartsocketToDisconnect = this.smartsocketClient;
|
const smartsocketToDisconnect = this.smartsocketClient;
|
||||||
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
|
this.smartsocketClient = undefined; // making sure the upstreamEvent does not interfere
|
||||||
await smartsocketToDisconnect.disconnect();
|
await smartsocketToDisconnect.disconnect();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,8 +69,12 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
public async populateSubscriptionToServer() {
|
public async populateSubscriptionToServer() {
|
||||||
// lets make sure the channel is connected
|
// lets make sure the channel is connected
|
||||||
if (this.status === 'unsubscribed') {
|
if (this.status === 'unsubscribed') {
|
||||||
|
const smartsocketClient = this.clientUniverseRef.smartsocketClient;
|
||||||
|
if (!smartsocketClient) {
|
||||||
|
throw new Error('Cannot subscribe channel before the smartuniverse client is connected.');
|
||||||
|
}
|
||||||
const response =
|
const response =
|
||||||
await this.clientUniverseRef.smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
|
await smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
|
||||||
'subscribeChannel',
|
'subscribeChannel',
|
||||||
{
|
{
|
||||||
name: this.name,
|
name: this.name,
|
||||||
@@ -91,6 +95,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
*/
|
*/
|
||||||
public async postMessage(messageArg: interfaces.IMessageCreator) {
|
public async postMessage(messageArg: interfaces.IMessageCreator) {
|
||||||
await this.clientUniverseRef.start(); // its ok to call this multiple times
|
await this.clientUniverseRef.start(); // its ok to call this multiple times
|
||||||
|
const smartsocketClient = this.clientUniverseRef.smartsocketClient;
|
||||||
|
if (!smartsocketClient) {
|
||||||
|
throw new Error('Cannot post message before the smartuniverse client is connected.');
|
||||||
|
}
|
||||||
const universeMessageToSend: interfaces.IUniverseMessage = {
|
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||||
id: plugins.isounique.uni(),
|
id: plugins.isounique.uni(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
@@ -99,7 +107,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
messageText: messageArg.messageText,
|
messageText: messageArg.messageText,
|
||||||
payload: messageArg.payload,
|
payload: messageArg.payload,
|
||||||
};
|
};
|
||||||
await this.clientUniverseRef.smartsocketClient.serverCall(
|
await smartsocketClient.serverCall<interfaces.ISocketRequest_ProcessMessage>(
|
||||||
'processMessage',
|
'processMessage',
|
||||||
universeMessageToSend
|
universeMessageToSend
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import * as plugins from './smartuniverse.plugins.js';
|
|||||||
|
|
||||||
import * as interfaces from './interfaces/index.js';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
export class ClientUniverseMessage<T> implements interfaces.IUniverseMessage {
|
export class ClientUniverseMessage<T = any> implements interfaces.IUniverseMessage<T> {
|
||||||
// ======
|
// ======
|
||||||
// STATIC
|
// STATIC
|
||||||
// ======
|
// ======
|
||||||
public static createMessageFromMessageDescriptor(messageDescriptor: interfaces.IUniverseMessage) {
|
public static createMessageFromMessageDescriptor<T = any>(messageDescriptor: interfaces.IUniverseMessage<T>) {
|
||||||
const clientuniverseMessage = new ClientUniverseMessage(messageDescriptor);
|
const clientuniverseMessage = new ClientUniverseMessage<T>(messageDescriptor);
|
||||||
return clientuniverseMessage;
|
return clientuniverseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,10 +25,14 @@ export class ClientUniverseMessage<T> implements interfaces.IUniverseMessage {
|
|||||||
public payload: T;
|
public payload: T;
|
||||||
public targetChannelName: string;
|
public targetChannelName: string;
|
||||||
|
|
||||||
constructor(messageArg: interfaces.IUniverseMessage) {
|
constructor(messageArg: interfaces.IUniverseMessage<T>) {
|
||||||
for (const key of Object.keys(messageArg)) {
|
this.id = messageArg.id;
|
||||||
this[key] = messageArg[key];
|
this.timestamp = messageArg.timestamp;
|
||||||
}
|
this.smartTimestamp = new plugins.smarttime.TimeStamp(this.timestamp);
|
||||||
|
this.messageText = messageArg.messageText;
|
||||||
|
this.passphrase = messageArg.passphrase;
|
||||||
|
this.payload = messageArg.payload as T;
|
||||||
|
this.targetChannelName = messageArg.targetChannelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITy
|
|||||||
typedRequestPayload: {
|
typedRequestPayload: {
|
||||||
method: T['method'];
|
method: T['method'];
|
||||||
request: T['request'];
|
request: T['request'];
|
||||||
response: T['response'];
|
response: T['response'] | null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +54,11 @@ export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequ
|
|||||||
if (payload.id !== requestId) {
|
if (payload.id !== requestId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (payload.typedRequestPayload.response !== null) {
|
||||||
reactionResult.pushReactionResponse(payload.typedRequestPayload.response);
|
reactionResult.pushReactionResponse(payload.typedRequestPayload.response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const payload: ICombinatorPayload<T> = {
|
const payload: ICombinatorPayload<T> = {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import * as plugins from './smartuniverse.plugins.js';
|
import * as plugins from './smartuniverse.plugins.js';
|
||||||
import * as pluginsTyped from './smartuniverse.pluginstyped.js';
|
|
||||||
|
|
||||||
import { UniverseCache, UniverseChannel, UniverseMessage } from './index.js';
|
import { UniverseCache, UniverseChannel, UniverseMessage } from './index.js';
|
||||||
|
|
||||||
@@ -9,7 +8,6 @@ import { logger } from './smartuniverse.logging.js';
|
|||||||
|
|
||||||
export interface ISmartUniverseConstructorOptions {
|
export interface ISmartUniverseConstructorOptions {
|
||||||
messageExpiryInMilliseconds: number;
|
messageExpiryInMilliseconds: number;
|
||||||
externalServer?: pluginsTyped.typedserver.servertools.Server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,15 +20,10 @@ export class Universe {
|
|||||||
// options
|
// options
|
||||||
private options: ISmartUniverseConstructorOptions;
|
private options: ISmartUniverseConstructorOptions;
|
||||||
|
|
||||||
/**
|
|
||||||
* the smartexpress server used
|
|
||||||
*/
|
|
||||||
private server: pluginsTyped.typedserver.servertools.Server;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the smartsocket used
|
* the smartsocket used
|
||||||
*/
|
*/
|
||||||
private smartsocket: plugins.smartsocket.Smartsocket;
|
private smartsocket?: plugins.smartsocket.Smartsocket;
|
||||||
|
|
||||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
@@ -41,7 +34,7 @@ export class Universe {
|
|||||||
* stores the version of the universe server running
|
* stores the version of the universe server running
|
||||||
* this is done since the version is exposed through the api and multiple fs actions are avoided this way.
|
* this is done since the version is exposed through the api and multiple fs actions are avoided this way.
|
||||||
*/
|
*/
|
||||||
private universeVersionStore: string;
|
private universeVersionStore = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the currently running version of smartuniverse
|
* get the currently running version of smartuniverse
|
||||||
@@ -77,25 +70,16 @@ export class Universe {
|
|||||||
* initiates a server
|
* initiates a server
|
||||||
*/
|
*/
|
||||||
public async start(portArg?: number) {
|
public async start(portArg?: number) {
|
||||||
if (!this.options.externalServer && !portArg) {
|
if (!portArg) {
|
||||||
throw new Error(`You supplied an external error. You need to specify a portArg to start on.`);
|
throw new Error(`You need to specify a portArg to start on.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
portArg = portArg || 3000; // TODO: remove
|
|
||||||
|
|
||||||
// add websocket upgrade
|
// add websocket upgrade
|
||||||
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
||||||
alias: 'smartuniverse',
|
alias: 'smartuniverse',
|
||||||
port: portArg,
|
port: portArg,
|
||||||
});
|
});
|
||||||
|
|
||||||
// lets create the base smartexpress server
|
|
||||||
if (this.options.externalServer) {
|
|
||||||
console.log('Universe is using externally supplied server');
|
|
||||||
this.smartsocket.setExternalServer('smartexpress', this.options.externalServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const socketFunctionSubscription =
|
const socketFunctionSubscription =
|
||||||
new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_SubscribeChannel>({
|
new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_SubscribeChannel>({
|
||||||
funcName: 'subscribeChannel',
|
funcName: 'subscribeChannel',
|
||||||
@@ -112,8 +96,8 @@ export class Universe {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction<any>({
|
const socketFunctionProcessMessage =
|
||||||
// TODO proper ITypedRequest here instead of any
|
new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_ProcessMessage>({
|
||||||
funcName: 'processMessage',
|
funcName: 'processMessage',
|
||||||
funcDef: async (messageDataArg: interfaces.IUniverseMessage, socketConnectionArg) => {
|
funcDef: async (messageDataArg: interfaces.IUniverseMessage, socketConnectionArg) => {
|
||||||
const universeConnection = UniverseConnection.findUniverseConnectionBySocketConnection(
|
const universeConnection = UniverseConnection.findUniverseConnectionBySocketConnection(
|
||||||
@@ -125,7 +109,7 @@ export class Universe {
|
|||||||
} else {
|
} else {
|
||||||
logger.log('warn', 'found no Authorized channel for incoming message');
|
logger.log('warn', 'found no Authorized channel for incoming message');
|
||||||
return {
|
return {
|
||||||
error: 'You need to authenticate for a channel',
|
messageStatus: 'authentication required',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(
|
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(
|
||||||
@@ -139,7 +123,13 @@ export class Universe {
|
|||||||
if (foundChannel && unauthenticatedMessage.authenticated) {
|
if (foundChannel && unauthenticatedMessage.authenticated) {
|
||||||
const authenticatedMessage = unauthenticatedMessage;
|
const authenticatedMessage = unauthenticatedMessage;
|
||||||
await this.universeCache.addMessage(authenticatedMessage);
|
await this.universeCache.addMessage(authenticatedMessage);
|
||||||
|
return {
|
||||||
|
messageStatus: 'ok',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
messageStatus: 'channel not found',
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -156,6 +146,6 @@ export class Universe {
|
|||||||
* stop everything
|
* stop everything
|
||||||
*/
|
*/
|
||||||
public async stopServer() {
|
public async stopServer() {
|
||||||
await this.smartsocket.stop();
|
await this.smartsocket?.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export class UniverseChannel {
|
|||||||
public static authorizeAMessageForAChannel(
|
public static authorizeAMessageForAChannel(
|
||||||
universeCacheArg: UniverseCache,
|
universeCacheArg: UniverseCache,
|
||||||
universeMessageArg: UniverseMessage<any>
|
universeMessageArg: UniverseMessage<any>
|
||||||
): UniverseChannel {
|
): UniverseChannel | null {
|
||||||
const foundChannel = universeCacheArg.channelMap.findSync((universeChannel) => {
|
const foundChannel = universeCacheArg.channelMap.findSync((universeChannel) => {
|
||||||
const result = universeChannel.authenticate(universeMessageArg);
|
const result = universeChannel.authenticate(universeMessageArg);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class UniverseConnection {
|
|||||||
universeCache: UniverseCache,
|
universeCache: UniverseCache,
|
||||||
universeConnectionArg: UniverseConnection
|
universeConnectionArg: UniverseConnection
|
||||||
): Promise<UniverseConnection> {
|
): Promise<UniverseConnection> {
|
||||||
let connectionToReturn: UniverseConnection;
|
let connectionToReturn: UniverseConnection | undefined;
|
||||||
universeCache.connectionMap.forEach(async (existingConnection) => {
|
universeCache.connectionMap.forEach(async (existingConnection) => {
|
||||||
if (existingConnection.socketConnection === universeConnectionArg.socketConnection) {
|
if (existingConnection.socketConnection === universeConnectionArg.socketConnection) {
|
||||||
connectionToReturn = await this.mergeUniverseConnections(
|
connectionToReturn = await this.mergeUniverseConnections(
|
||||||
@@ -63,7 +63,7 @@ export class UniverseConnection {
|
|||||||
universeRef,
|
universeRef,
|
||||||
authenticationRequest.name
|
authenticationRequest.name
|
||||||
);
|
);
|
||||||
if (universeChannelToAuthenticateAgainst.passphrase === authenticationRequest.passphrase) {
|
if (universeChannelToAuthenticateAgainst?.passphrase === authenticationRequest.passphrase) {
|
||||||
universeConnectionArg.authenticatedChannels.push(universeChannelToAuthenticateAgainst);
|
universeConnectionArg.authenticatedChannels.push(universeChannelToAuthenticateAgainst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ export class UniverseConnection {
|
|||||||
public static findUniverseConnectionBySocketConnection(
|
public static findUniverseConnectionBySocketConnection(
|
||||||
universeCache: UniverseCache,
|
universeCache: UniverseCache,
|
||||||
socketConnectionArg: plugins.smartsocket.SocketConnection
|
socketConnectionArg: plugins.smartsocket.SocketConnection
|
||||||
): UniverseConnection {
|
): UniverseConnection | undefined {
|
||||||
const universeConnection = universeCache.connectionMap.findSync((universeConnectionArg) => {
|
const universeConnection = universeCache.connectionMap.findSync((universeConnectionArg) => {
|
||||||
return universeConnectionArg.socketConnection === socketConnectionArg;
|
return universeConnectionArg.socketConnection === socketConnectionArg;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as plugins from './smartuniverse.plugins.js';
|
import * as plugins from './smartuniverse.plugins.js';
|
||||||
import * as interfaces from './interfaces/index.js';
|
import * as interfaces from './interfaces/index.js';
|
||||||
import { Universe } from './smartuniverse.classes.universe.js';
|
|
||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel.js';
|
import { UniverseChannel } from './smartuniverse.classes.universechannel.js';
|
||||||
import { UniverseCache } from './smartuniverse.classes.universecache.js';
|
import { UniverseCache } from './smartuniverse.classes.universecache.js';
|
||||||
import { SocketConnection } from '@push.rocks/smartsocket';
|
import { SocketConnection } from '@push.rocks/smartsocket';
|
||||||
@@ -10,12 +9,12 @@ import { logger } from './smartuniverse.logging.js';
|
|||||||
* 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<T> implements interfaces.IUniverseMessage {
|
export class UniverseMessage<T = any> implements interfaces.IUniverseMessage<T> {
|
||||||
public static createMessageFromPayload(
|
public static createMessageFromPayload<T = any>(
|
||||||
socketConnectionArg: SocketConnection,
|
socketConnectionArg: SocketConnection,
|
||||||
dataArg: interfaces.IUniverseMessage
|
dataArg: interfaces.IUniverseMessage<T>
|
||||||
) {
|
) {
|
||||||
const universeMessageInstance = new UniverseMessage(dataArg);
|
const universeMessageInstance = new UniverseMessage<T>(dataArg);
|
||||||
universeMessageInstance.socketConnection = socketConnectionArg;
|
universeMessageInstance.socketConnection = socketConnectionArg;
|
||||||
return universeMessageInstance;
|
return universeMessageInstance;
|
||||||
}
|
}
|
||||||
@@ -27,12 +26,12 @@ export class UniverseMessage<T> implements interfaces.IUniverseMessage {
|
|||||||
public passphrase: string;
|
public passphrase: string;
|
||||||
public payload: T;
|
public payload: T;
|
||||||
public targetChannelName: string;
|
public targetChannelName: string;
|
||||||
public socketConnection: SocketConnection;
|
public socketConnection?: SocketConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the UniverseCache the message is attached to
|
* the UniverseCache the message is attached to
|
||||||
*/
|
*/
|
||||||
public universeCache: UniverseCache;
|
public universeCache?: UniverseCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enables unprotected grouping of messages for efficiency purposes.
|
* enables unprotected grouping of messages for efficiency purposes.
|
||||||
@@ -47,19 +46,21 @@ export class UniverseMessage<T> implements interfaces.IUniverseMessage {
|
|||||||
/**
|
/**
|
||||||
* a destruction timer for this message
|
* a destruction timer for this message
|
||||||
*/
|
*/
|
||||||
public destructionTimer: plugins.smarttime.Timer; // a timer to take care of message destruction
|
public destructionTimer?: plugins.smarttime.Timer; // a timer to take care of message destruction
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the constructor to create a universe message
|
* the constructor to create a universe message
|
||||||
* @param messageArg
|
* @param messageArg
|
||||||
* @param attachedPayloadArg
|
* @param attachedPayloadArg
|
||||||
*/
|
*/
|
||||||
constructor(messageDescriptor: interfaces.IUniverseMessage) {
|
constructor(messageDescriptor: interfaces.IUniverseMessage<T>) {
|
||||||
|
this.id = messageDescriptor.id;
|
||||||
|
this.timestamp = messageDescriptor.timestamp;
|
||||||
this.smartTimestamp = new plugins.smarttime.TimeStamp(this.timestamp);
|
this.smartTimestamp = new plugins.smarttime.TimeStamp(this.timestamp);
|
||||||
this.messageText = messageDescriptor.messageText;
|
this.messageText = messageDescriptor.messageText;
|
||||||
this.targetChannelName = messageDescriptor.targetChannelName;
|
this.targetChannelName = messageDescriptor.targetChannelName;
|
||||||
this.passphrase = messageDescriptor.passphrase;
|
this.passphrase = messageDescriptor.passphrase;
|
||||||
this.payload = messageDescriptor.payload;
|
this.payload = messageDescriptor.payload as T;
|
||||||
// prevent memory issues
|
// prevent memory issues
|
||||||
this.setDestructionTimer();
|
this.setDestructionTimer();
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,7 @@ export class UniverseMessage<T> implements interfaces.IUniverseMessage {
|
|||||||
// 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
|
this.destructionTimer.completed
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
this.universeCache.messageMap.remove(this);
|
this.universeCache?.messageMap.remove(this);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// apiglobal scope
|
// apiglobal scope
|
||||||
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
|
||||||
|
|
||||||
export { typedrequestInterfaces };
|
export { typedrequestInterfaces };
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type * as typedserver from '@apiglobal/typedserver';
|
import type * as typedserver from '@api.global/typedserver';
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
typedserver
|
typedserver
|
||||||
|
|||||||
+4
-4
@@ -5,10 +5,10 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
|
"noImplicitAny": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["dist_*/**/*.d.ts"]
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user