topsyde-utils 1.0.180 → 1.0.182

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./client/rxjs/useRxjs";
11
11
  export * from "./client/vite/plugins/topsydeUtilsVitePlugin";
12
12
  export * from "./server/controller";
13
13
  export * from "./server/service";
14
+ export * from "./server/base/base.database";
14
15
  export * from "./server/bun/router/controller-discovery";
15
16
  export * from "./server/bun/router/routes";
16
17
  export * from "./server/bun/router/router";
@@ -32,6 +33,7 @@ export { default as Throwable } from "./throwable";
32
33
  export { default as TopsydeUtilsVitePlugin } from "./client/vite/plugins/topsydeUtilsVitePlugin";
33
34
  export { default as Controller } from "./server/controller";
34
35
  export { default as Service } from "./server/service";
36
+ export { default as Database } from "./server/base/base.database";
35
37
  export { default as Router } from "./server/bun/router/router";
36
38
  export { default as Router_Internal } from "./server/bun/router/router.internal";
37
39
  export { default as Client } from "./server/bun/websocket/Client";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export * from "./client/rxjs/useRxjs";
14
14
  export * from "./client/vite/plugins/topsydeUtilsVitePlugin";
15
15
  export * from "./server/controller";
16
16
  export * from "./server/service";
17
+ export * from "./server/base/base.database";
17
18
  export * from "./server/bun/router/controller-discovery";
18
19
  export * from "./server/bun/router/routes";
19
20
  export * from "./server/bun/router/router";
@@ -36,6 +37,7 @@ export { default as Throwable } from "./throwable";
36
37
  export { default as TopsydeUtilsVitePlugin } from "./client/vite/plugins/topsydeUtilsVitePlugin";
37
38
  export { default as Controller } from "./server/controller";
38
39
  export { default as Service } from "./server/service";
40
+ export { default as Database } from "./server/base/base.database";
39
41
  export { default as Router } from "./server/bun/router/router";
40
42
  export { default as Router_Internal } from "./server/bun/router/router.internal";
41
43
  export { default as Client } from "./server/bun/websocket/Client";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src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,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErD,sDAAsD;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAiC,MAAM,oBAAoB,CAAC;AAKlF,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-indexes.ts\n// Do not edit this file directly\n\n// Export all modules\nexport * from \"./errors\";\nexport * from \"./singleton\";\nexport * from \"./initializable\";\nexport * from \"./application\";\nexport * from \"./consts\";\nexport * from \"./types\";\nexport * from \"./throwable\";\nexport * from \"./enums\";\nexport * from \"./client/rxjs/rxjs\";\nexport * from \"./client/rxjs/useRxjs\";\nexport * from \"./client/vite/plugins/topsydeUtilsVitePlugin\";\nexport * from \"./server/controller\";\nexport * from \"./server/service\";\nexport * from \"./server/bun/router/controller-discovery\";\nexport * from \"./server/bun/router/routes\";\nexport * from \"./server/bun/router/router\";\nexport * from \"./server/bun/router/router.internal\";\nexport * from \"./server/bun/websocket/websocket.guards\";\nexport * from \"./server/bun/websocket/Client\";\nexport * from \"./server/bun/websocket/Websocket\";\nexport * from \"./server/bun/websocket/websocket.enums\";\nexport * from \"./server/bun/websocket/websocket.types\";\nexport * from \"./server/bun/websocket/Message\";\nexport * from \"./server/bun/websocket/Channel\";\nexport * from \"./utils/Guards\";\nexport * from \"./utils/Lib\";\nexport * from \"./utils/Console\";\n\n// Export default classes\nexport { default as Singleton } from \"./singleton\";\nexport { default as Initializable } from \"./initializable\";\nexport { default as Application } from \"./application\";\nexport { default as Throwable } from \"./throwable\";\nexport { default as TopsydeUtilsVitePlugin } from \"./client/vite/plugins/topsydeUtilsVitePlugin\";\nexport { default as Controller } from \"./server/controller\";\nexport { default as Service } from \"./server/service\";\nexport { default as Router } from \"./server/bun/router/router\";\nexport { default as Router_Internal } from \"./server/bun/router/router.internal\";\nexport { default as Client } from \"./server/bun/websocket/Client\";\nexport { default as Websocket } from \"./server/bun/websocket/Websocket\";\nexport { default as Message } from \"./server/bun/websocket/Message\";\nexport { default as Channel } from \"./server/bun/websocket/Channel\";\nexport { default as Guards } from \"./utils/Guards\";\nexport { default as Lib } from \"./utils/Lib\";\nexport { default as Console } from \"./utils/Console\";\n\n// Re-export specific items for backward compatibility\nexport { ERROR_CODE, HTTP_ERROR_CODE, WS_ERROR_CODE } from \"./errors\";\nexport { InitializableOptions, InitializableEvent } from \"./initializable\";\nexport { RESPONSE_INIT, HEADERS_INIT, RESPONSE_METHOD_OPTIONS } from \"./application\";\nexport { DEFAULT_FALSE_RESPONSE, LOG_COLORS, LOG_ICONS } from \"./consts\";\nexport { ClassConstructor, NonNullableType, ObjectKeys, KVObj, I_ApplicationResponse } from \"./types\";\nexport { E_IS, E_ENVIRONMENTS } from \"./enums\";\nexport { E_SUBJET_TYPE, I_RxjsPayload, RxjsNamespaces } from \"./client/rxjs/rxjs\";\nexport { RxjsDataType } from \"./client/rxjs/useRxjs\";\nexport { ControllerResponse, ControllerAction, ControllerMap, ControllerOptions } from \"./server/controller\";\nexport { Routes } from \"./server/bun/router/routes\";\nexport { WebsocketConstructorOptions, I_WebsocketConstructor } from \"./server/bun/websocket/Websocket\";\nexport { E_WebsocketMessageType, E_WebsocketMessagePriority } from \"./server/bun/websocket/websocket.enums\";\nexport {\n\tBunWebsocketMessage,\n\tWebsocketChannel,\n\tWebsocketClients,\n\tWebsocketMessageOptions,\n\tWebsocketMessage,\n\tWebsocketStructuredMessage,\n\tWebsocketEntityId,\n\tWebsocketEntityName,\n\tWebsocketEntityData,\n\tI_WebsocketEntity,\n\tI_WebsocketClient,\n\tI_WebsocketChannelEntity,\n\tBroadcastOptions,\n\tI_WebsocketChannel,\n\tWebsocketInterfaceHandlers,\n\tI_WebsocketInterface,\n} from \"./server/bun/websocket/websocket.types\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,iCAAiC;AAEjC,qBAAqB;AACrB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAA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,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErD,sDAAsD;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAiC,MAAM,oBAAoB,CAAC;AAKlF,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-indexes.ts\n// Do not edit this file directly\n\n// Export all modules\nexport * from \"./errors\";\nexport * from \"./singleton\";\nexport * from \"./initializable\";\nexport * from \"./application\";\nexport * from \"./consts\";\nexport * from \"./types\";\nexport * from \"./throwable\";\nexport * from \"./enums\";\nexport * from \"./client/rxjs/rxjs\";\nexport * from \"./client/rxjs/useRxjs\";\nexport * from \"./client/vite/plugins/topsydeUtilsVitePlugin\";\nexport * from \"./server/controller\";\nexport * from \"./server/service\";\nexport * from \"./server/base/base.database\";\nexport * from \"./server/bun/router/controller-discovery\";\nexport * from \"./server/bun/router/routes\";\nexport * from \"./server/bun/router/router\";\nexport * from \"./server/bun/router/router.internal\";\nexport * from \"./server/bun/websocket/websocket.guards\";\nexport * from \"./server/bun/websocket/Client\";\nexport * from \"./server/bun/websocket/Websocket\";\nexport * from \"./server/bun/websocket/websocket.enums\";\nexport * from \"./server/bun/websocket/websocket.types\";\nexport * from \"./server/bun/websocket/Message\";\nexport * from \"./server/bun/websocket/Channel\";\nexport * from \"./utils/Guards\";\nexport * from \"./utils/Lib\";\nexport * from \"./utils/Console\";\n\n// Export default classes\nexport { default as Singleton } from \"./singleton\";\nexport { default as Initializable } from \"./initializable\";\nexport { default as Application } from \"./application\";\nexport { default as Throwable } from \"./throwable\";\nexport { default as TopsydeUtilsVitePlugin } from \"./client/vite/plugins/topsydeUtilsVitePlugin\";\nexport { default as Controller } from \"./server/controller\";\nexport { default as Service } from \"./server/service\";\nexport { default as Database } from \"./server/base/base.database\";\nexport { default as Router } from \"./server/bun/router/router\";\nexport { default as Router_Internal } from \"./server/bun/router/router.internal\";\nexport { default as Client } from \"./server/bun/websocket/Client\";\nexport { default as Websocket } from \"./server/bun/websocket/Websocket\";\nexport { default as Message } from \"./server/bun/websocket/Message\";\nexport { default as Channel } from \"./server/bun/websocket/Channel\";\nexport { default as Guards } from \"./utils/Guards\";\nexport { default as Lib } from \"./utils/Lib\";\nexport { default as Console } from \"./utils/Console\";\n\n// Re-export specific items for backward compatibility\nexport { ERROR_CODE, HTTP_ERROR_CODE, WS_ERROR_CODE } from \"./errors\";\nexport { InitializableOptions, InitializableEvent } from \"./initializable\";\nexport { RESPONSE_INIT, HEADERS_INIT, RESPONSE_METHOD_OPTIONS } from \"./application\";\nexport { DEFAULT_FALSE_RESPONSE, LOG_COLORS, LOG_ICONS } from \"./consts\";\nexport { ClassConstructor, NonNullableType, ObjectKeys, KVObj, I_ApplicationResponse } from \"./types\";\nexport { E_IS, E_ENVIRONMENTS } from \"./enums\";\nexport { E_SUBJET_TYPE, I_RxjsPayload, RxjsNamespaces } from \"./client/rxjs/rxjs\";\nexport { RxjsDataType } from \"./client/rxjs/useRxjs\";\nexport { ControllerResponse, ControllerAction, ControllerMap, ControllerOptions } from \"./server/controller\";\nexport { Routes } from \"./server/bun/router/routes\";\nexport { WebsocketConstructorOptions, I_WebsocketConstructor } from \"./server/bun/websocket/Websocket\";\nexport { E_WebsocketMessageType, E_WebsocketMessagePriority } from \"./server/bun/websocket/websocket.enums\";\nexport {\n\tBunWebsocketMessage,\n\tWebsocketChannel,\n\tWebsocketClients,\n\tWebsocketMessageOptions,\n\tWebsocketMessage,\n\tWebsocketStructuredMessage,\n\tWebsocketEntityId,\n\tWebsocketEntityName,\n\tWebsocketEntityData,\n\tI_WebsocketEntity,\n\tI_WebsocketClient,\n\tI_WebsocketChannelEntity,\n\tBroadcastOptions,\n\tI_WebsocketChannel,\n\tWebsocketInterfaceHandlers,\n\tI_WebsocketInterface,\n} from \"./server/bun/websocket/websocket.types\";\n"]}
@@ -0,0 +1,10 @@
1
+ import Singleton from "../../singleton";
2
+ declare abstract class Database extends Singleton {
3
+ constructor();
4
+ abstract connect(): Promise<void>;
5
+ abstract disconnect(): Promise<void>;
6
+ protected connected: boolean;
7
+ protected processing: boolean;
8
+ static Connection<T extends (new (...args: any[]) => Database) & typeof Singleton>(this: T, ...args: ConstructorParameters<T>): Promise<InstanceType<T>>;
9
+ }
10
+ export default Database;
@@ -0,0 +1,23 @@
1
+ import Singleton from "../../singleton";
2
+ class Database extends Singleton {
3
+ constructor() {
4
+ super();
5
+ this.connected = false;
6
+ this.processing = false;
7
+ }
8
+ static async Connection(...args) {
9
+ try {
10
+ const instance = this.GetInstance(...args);
11
+ if (!instance.connected && !instance.processing) {
12
+ await instance.connect();
13
+ }
14
+ return instance;
15
+ }
16
+ catch (e) {
17
+ console.error(e);
18
+ throw e;
19
+ }
20
+ }
21
+ }
22
+ export default Database;
23
+ //# sourceMappingURL=base.database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.database.js","sourceRoot":"","sources":["../../../src/server/base/base.database.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,MAAe,QAAS,SAAQ,SAAS;IACxC;QACC,KAAK,EAAE,CAAC;QAMC,cAAS,GAAY,KAAK,CAAC;QAC3B,eAAU,GAAY,KAAK,CAAC;IANtC,CAAC;IAQM,MAAM,CAAC,KAAK,CAAC,UAAU,CAE7B,GAAG,IAA8B;QAEjC,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAoB,CAAC;YAC9D,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACjD,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;YACD,OAAO,QAAQ,CAAC;QACjB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,MAAM,CAAC,CAAC;QACT,CAAC;IACF,CAAC;CACD;AAED,eAAe,QAAQ,CAAC","sourcesContent":["import Singleton from \"../../singleton\";\n\nabstract class Database extends Singleton {\n\tconstructor() {\n\t\tsuper();\n\t}\n\n\tpublic abstract connect(): Promise<void>;\n\tpublic abstract disconnect(): Promise<void>;\n\n\tprotected connected: boolean = false;\n\tprotected processing: boolean = false;\n\n\tpublic static async Connection<T extends (new (...args: any[]) => Database) & typeof Singleton>(\n\t\tthis: T,\n\t\t...args: ConstructorParameters<T>\n\t): Promise<InstanceType<T>> {\n\t\ttry {\n\t\t\tconst instance = this.GetInstance(...args) as InstanceType<T>;\n\t\t\tif (!instance.connected && !instance.processing) {\n\t\t\t\tawait instance.connect();\n\t\t\t}\n\t\t\treturn instance;\n\t\t} catch (e) {\n\t\t\tconsole.error(e);\n\t\t\tthrow e;\n\t\t}\n\t}\n}\n\nexport default Database;\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './base.database';
2
+ export { default as Database } from './base.database';
@@ -0,0 +1,5 @@
1
+ // This file is auto-generated by scripts/generate-indexes.ts
2
+ // Do not edit this file directly
3
+ export * from './base.database';
4
+ export { default as Database } from './base.database';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/base/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,iCAAiC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-indexes.ts\n// Do not edit this file directly\n\nexport * from './base.database';\nexport { default as Database } from './base.database';\n"]}
@@ -1,5 +1,5 @@
1
1
  import { ServerWebSocket } from "bun";
2
- import type { I_WebsocketClient, WebsocketEntityData, WebsocketChannel, WebsocketStructuredMessage, I_WebsocketEntity, I_WebsocketChannel } from "./websocket.types";
2
+ import type { I_WebsocketClient, WebsocketEntityData, WebsocketChannel, WebsocketStructuredMessage, I_WebsocketEntity, I_WebsocketChannel, WebsocketMessageOptions } from "./websocket.types";
3
3
  export default class Client implements I_WebsocketClient {
4
4
  private _id;
5
5
  private _name;
@@ -22,6 +22,7 @@ export default class Client implements I_WebsocketClient {
22
22
  id: string;
23
23
  name: string;
24
24
  };
25
+ send(message: string, options?: WebsocketMessageOptions): void;
25
26
  send(message: WebsocketStructuredMessage): void;
26
27
  subscribe(channel: string): void;
27
28
  unsubscribe(channel: string): void;
@@ -1,5 +1,6 @@
1
1
  import { E_WebsocketMessageType } from "./websocket.enums";
2
- import { Lib } from "../../../utils";
2
+ import { Guards, Lib } from "../../../utils";
3
+ import Message from "./Message";
3
4
  export default class Client {
4
5
  set ws(value) {
5
6
  this._ws = value;
@@ -75,7 +76,14 @@ export default class Client {
75
76
  whoami() {
76
77
  return { id: this.id, name: this.name };
77
78
  }
78
- send(message) {
79
+ send(message, options) {
80
+ if (Guards.IsString(message)) {
81
+ const msg = {
82
+ type: "message",
83
+ content: { message },
84
+ };
85
+ message = Message.Create(msg, options);
86
+ }
79
87
  this.ws.send(JSON.stringify({ client: this.whoami(), ...message }));
80
88
  }
81
89
  subscribe(channel) {
@@ -1 +1 @@
1
- {"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/Client.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OA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;IAEM,MAAM,CAAC,MAAM;QACnB,OAA4B;YAC3B,EAAE,EAAE,QAAQ;YACZ,IAAI,EAAE,QAAQ;SACd,CAAC;IACH,CAAC;CACD","sourcesContent":["import { ServerWebSocket } from \"bun\";\nimport type {\n\tI_WebsocketClient,\n\tWebsocketEntityData,\n\tWebsocketChannel,\n\tWebsocketStructuredMessage,\n\tI_WebsocketEntity,\n\tI_WebsocketChannel,\n} from \"./websocket.types\";\nimport { E_WebsocketMessageType } from \"./websocket.enums\";\nimport { Lib } from \"../../../utils\";\n\nexport default class Client implements I_WebsocketClient {\n\tprivate _id: string;\n\tprivate _name: string;\n\tprivate _ws: ServerWebSocket<WebsocketEntityData>;\n\tprivate _channels: WebsocketChannel<I_WebsocketChannel>;\n\n\tprivate set ws(value: ServerWebSocket<WebsocketEntityData>) {\n\t\tthis._ws = value;\n\t}\n\n\tpublic get ws(): ServerWebSocket<WebsocketEntityData> {\n\t\treturn this._ws;\n\t}\n\n\tprivate set id(value: string) {\n\t\tthis._id = value;\n\t}\n\n\tpublic get id(): string {\n\t\treturn this._id;\n\t}\n\n\tpublic get name(): string {\n\t\treturn this._name;\n\t}\n\n\tprivate set name(value: string) {\n\t\tthis._name = value;\n\t}\n\n\tprivate set channels(value: WebsocketChannel<I_WebsocketChannel>) {\n\t\tthis._channels = value;\n\t}\n\n\tpublic get channels(): WebsocketChannel<I_WebsocketChannel> {\n\t\treturn this._channels;\n\t}\n\n\tconstructor(entity: I_WebsocketEntity) {\n\t\tthis._id = entity.id;\n\t\tthis._name = entity.name;\n\t\tthis._ws = entity.ws;\n\t\tthis.ws = entity.ws;\n\t\tthis._channels = new Map();\n\t}\n\n\tpublic joinChannel(channel: I_WebsocketChannel, send: boolean = true) {\n\t\tconst channel_id = channel.getId();\n\t\tthis.subscribe(channel_id);\n\t\tthis.channels.set(channel_id, channel);\n\t\tif (send)\n\t\t\tthis.send({\n\t\t\t\ttype: E_WebsocketMessageType.CLIENT_JOIN_CHANNEL,\n\t\t\t\tcontent: { message: \"Welcome to the channel\" },\n\t\t\t\tchannel: channel_id,\n\t\t\t\tclient: this.whoami(),\n\t\t\t});\n\t}\n\n\tpublic leaveChannel(channel: I_WebsocketChannel, send: boolean = true) {\n\t\tconst channel_id = channel.getId();\n\t\tthis.channels.delete(channel_id);\n\t\tthis.unsubscribe(channel_id);\n\t\tif (send)\n\t\t\tthis.send({\n\t\t\t\ttype: E_WebsocketMessageType.CLIENT_LEAVE_CHANNEL,\n\t\t\t\tcontent: { message: \"Left the channel\" },\n\t\t\t\tchannel: channel_id,\n\t\t\t\tclient: this.whoami(),\n\t\t\t});\n\t}\n\n\tpublic joinChannels(channels: I_WebsocketChannel[], send: boolean = true) {\n\t\tchannels.forEach((channel) => {\n\t\t\tthis.joinChannel(channel, false);\n\t\t});\n\t\tif (send) this.send({ type: E_WebsocketMessageType.CLIENT_JOIN_CHANNELS, content: { channels }, client: this.whoami() });\n\t}\n\n\tpublic leaveChannels(channels?: I_WebsocketChannel[], send: boolean = true) {\n\t\tif (!channels) channels = Array.from(this.channels.values());\n\t\tchannels.forEach((channel) => {\n\t\t\tthis.leaveChannel(channel, false);\n\t\t});\n\t\tif (send) this.send({ type: E_WebsocketMessageType.CLIENT_LEAVE_CHANNELS, content: { channels }, client: this.whoami() });\n\t}\n\n\tpublic whoami(): { id: string; name: string } {\n\t\treturn { id: this.id, name: this.name };\n\t}\n\n\tpublic send(message: WebsocketStructuredMessage) {\n\t\tthis.ws.send(JSON.stringify({ client: this.whoami(), ...message }));\n\t}\n\n\tpublic subscribe(channel: string): void {\n\t\tthis.ws.subscribe(channel);\n\t}\n\n\tpublic unsubscribe(channel: string): void {\n\t\tthis.ws.unsubscribe(channel);\n\t}\n\n\tpublic static GetClientType(clients: Map<string, I_WebsocketClient> | undefined): typeof Client {\n\t\tif (!clients) return Client;\n\t\tif (clients.size > 0) {\n\t\t\tconst firstClient = clients.values().next().value;\n\t\t\tif (firstClient) {\n\t\t\t\treturn firstClient.constructor as typeof Client;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to default Client class\n\t\tLib.Warn(\"Clients map is empty, using default client class\");\n\t\treturn Client;\n\t}\n\n\tpublic static System() {\n\t\treturn <WebsocketEntityData>{\n\t\t\tid: \"system\",\n\t\t\tname: \"System\",\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/Client.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,MAAM;IAM1B,IAAY,EAAE,CAAC,KAA2C;QACzD,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;IAClB,CAAC;IAED,IAAW,EAAE;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC;IACjB,CAAC;IAED,IAAY,EAAE,CAAC,KAAa;QAC3B,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;IAClB,CAAC;IAED,IAAW,EAAE;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC;IACjB,CAAC;IAED,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,IAAY,IAAI,CAAC,KAAa;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,IAAY,QAAQ,CAAC,KAA2C;QAC/D,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,YAAY,MAAyB;QACpC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,MAAM,CAA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,CAAC,CAAC,CAAC;IACrE,CAAC;IAEM,SAAS,CAAC,OAAe;QAC/B,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAEM,WAAW,CAAC,OAAe;QACjC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAEM,MAAM,CAAC,aAAa,CAAC,OAAmD;QAC9E,IAAI,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC;QAC5B,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YAClD,IAAI,WAAW,EAAE,CAAC;gBACjB,OAAO,WAAW,CAAC,WAA4B,CAAC;YACjD,CAAC;QACF,CAAC;QAED,mCAAmC;QACnC,GAAG,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QAC7D,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,MAAM,CAAC,MAAM;QACnB,OAA4B;YAC3B,EAAE,EAAE,QAAQ;YACZ,IAAI,EAAE,QAAQ;SACd,CAAC;IACH,CAAC;CACD","sourcesContent":["import { ServerWebSocket } from \"bun\";\nimport type {\n\tI_WebsocketClient,\n\tWebsocketEntityData,\n\tWebsocketChannel,\n\tWebsocketStructuredMessage,\n\tI_WebsocketEntity,\n\tI_WebsocketChannel,\n\tWebsocketMessageOptions,\n\tWebsocketMessage,\n} from \"./websocket.types\";\nimport { E_WebsocketMessageType } from \"./websocket.enums\";\nimport { Guards, Lib } from \"../../../utils\";\nimport Message from \"./Message\";\n\nexport default class Client implements I_WebsocketClient {\n\tprivate _id: string;\n\tprivate _name: string;\n\tprivate _ws: ServerWebSocket<WebsocketEntityData>;\n\tprivate _channels: WebsocketChannel<I_WebsocketChannel>;\n\n\tprivate set ws(value: ServerWebSocket<WebsocketEntityData>) {\n\t\tthis._ws = value;\n\t}\n\n\tpublic get ws(): ServerWebSocket<WebsocketEntityData> {\n\t\treturn this._ws;\n\t}\n\n\tprivate set id(value: string) {\n\t\tthis._id = value;\n\t}\n\n\tpublic get id(): string {\n\t\treturn this._id;\n\t}\n\n\tpublic get name(): string {\n\t\treturn this._name;\n\t}\n\n\tprivate set name(value: string) {\n\t\tthis._name = value;\n\t}\n\n\tprivate set channels(value: WebsocketChannel<I_WebsocketChannel>) {\n\t\tthis._channels = value;\n\t}\n\n\tpublic get channels(): WebsocketChannel<I_WebsocketChannel> {\n\t\treturn this._channels;\n\t}\n\n\tconstructor(entity: I_WebsocketEntity) {\n\t\tthis._id = entity.id;\n\t\tthis._name = entity.name;\n\t\tthis._ws = entity.ws;\n\t\tthis.ws = entity.ws;\n\t\tthis._channels = new Map();\n\t}\n\n\tpublic joinChannel(channel: I_WebsocketChannel, send: boolean = true) {\n\t\tconst channel_id = channel.getId();\n\t\tthis.subscribe(channel_id);\n\t\tthis.channels.set(channel_id, channel);\n\t\tif (send)\n\t\t\tthis.send({\n\t\t\t\ttype: E_WebsocketMessageType.CLIENT_JOIN_CHANNEL,\n\t\t\t\tcontent: { message: \"Welcome to the channel\" },\n\t\t\t\tchannel: channel_id,\n\t\t\t\tclient: this.whoami(),\n\t\t\t});\n\t}\n\n\tpublic leaveChannel(channel: I_WebsocketChannel, send: boolean = true) {\n\t\tconst channel_id = channel.getId();\n\t\tthis.channels.delete(channel_id);\n\t\tthis.unsubscribe(channel_id);\n\t\tif (send)\n\t\t\tthis.send({\n\t\t\t\ttype: E_WebsocketMessageType.CLIENT_LEAVE_CHANNEL,\n\t\t\t\tcontent: { message: \"Left the channel\" },\n\t\t\t\tchannel: channel_id,\n\t\t\t\tclient: this.whoami(),\n\t\t\t});\n\t}\n\n\tpublic joinChannels(channels: I_WebsocketChannel[], send: boolean = true) {\n\t\tchannels.forEach((channel) => {\n\t\t\tthis.joinChannel(channel, false);\n\t\t});\n\t\tif (send) this.send({ type: E_WebsocketMessageType.CLIENT_JOIN_CHANNELS, content: { channels }, client: this.whoami() });\n\t}\n\n\tpublic leaveChannels(channels?: I_WebsocketChannel[], send: boolean = true) {\n\t\tif (!channels) channels = Array.from(this.channels.values());\n\t\tchannels.forEach((channel) => {\n\t\t\tthis.leaveChannel(channel, false);\n\t\t});\n\t\tif (send) this.send({ type: E_WebsocketMessageType.CLIENT_LEAVE_CHANNELS, content: { channels }, client: this.whoami() });\n\t}\n\n\tpublic whoami(): { id: string; name: string } {\n\t\treturn { id: this.id, name: this.name };\n\t}\n\n\tpublic send(message: string, options?: WebsocketMessageOptions): void;\n\tpublic send(message: WebsocketStructuredMessage): void;\n\tpublic send(message: WebsocketStructuredMessage | string, options?: WebsocketMessageOptions): void {\n\t\tif (Guards.IsString(message)) {\n\t\t\tconst msg: WebsocketMessage = {\n\t\t\t\ttype: \"message\",\n\t\t\t\tcontent: { message },\n\t\t\t};\n\t\t\tmessage = Message.Create(msg, options);\n\t\t}\n\t\tthis.ws.send(JSON.stringify({ client: this.whoami(), ...message }));\n\t}\n\n\tpublic subscribe(channel: string): void {\n\t\tthis.ws.subscribe(channel);\n\t}\n\n\tpublic unsubscribe(channel: string): void {\n\t\tthis.ws.unsubscribe(channel);\n\t}\n\n\tpublic static GetClientType(clients: Map<string, I_WebsocketClient> | undefined): typeof Client {\n\t\tif (!clients) return Client;\n\t\tif (clients.size > 0) {\n\t\t\tconst firstClient = clients.values().next().value;\n\t\t\tif (firstClient) {\n\t\t\t\treturn firstClient.constructor as typeof Client;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to default Client class\n\t\tLib.Warn(\"Clients map is empty, using default client class\");\n\t\treturn Client;\n\t}\n\n\tpublic static System() {\n\t\treturn <WebsocketEntityData>{\n\t\t\tid: \"system\",\n\t\t\tname: \"System\",\n\t\t};\n\t}\n}\n"]}
@@ -10,4 +10,5 @@ export default class Message {
10
10
  serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T;
11
11
  static Serialize<T = string>(message: WebsocketStructuredMessage, transform: (message: WebsocketStructuredMessage) => T): T;
12
12
  static Serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T;
13
+ static Create(message: WebsocketMessage, options?: WebsocketMessageOptions): WebsocketStructuredMessage;
13
14
  }
@@ -96,5 +96,9 @@ export default class Message {
96
96
  static Serialize(message, transform) {
97
97
  return transform ? transform(message) : JSON.stringify(message);
98
98
  }
99
+ static Create(message, options) {
100
+ const msg = new Message();
101
+ return msg.create(message, options);
102
+ }
99
103
  }
100
104
  //# sourceMappingURL=Message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Message.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/Message.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAU3C,MAAM,CAAC,OAAO,OAAO,OAAO;IAG3B;QACC,IAAI,CAAC,eAAe,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IAC9E,CAAC;IAEM,MAAM,CAAC,OAAyB,EAAE,OAAiC;QACzE,wDAAwD;QACxD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACvD,8CAA8C;QAC9C,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;QAE9D,wCAAwC;QACxC,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzC,MAAM,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QAC/C,CAAC;aAAM,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,O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CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK,CAAC,MAAyB,EAAE,MAAc,EAAE,MAA4B;QACnF,MAAM,CAAC,IAAI,CACV,IAAI,CAAC,MAAM,CACV;YACC,OAAO,EAAE;gBACR,OAAO,EAAE,MAAM;aACf;YACD,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,SAAS;SACf,EACD,EAAE,MAAM,EAAE,CACV,CACD,CAAC;IACH,CAAC;IAEM,SAAS,CAAa,OAAmC,EAAE,SAAsD;QACvH,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;IAIM,MAAM,CAAC,SAAS,CAAa,OAAmC,EAAE,SAAsD;QAC9H,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;CACD","sourcesContent":["import Guards from \"../../../utils/Guards\";\nimport {\n\tWebsocketStructuredMessage,\n\tWebsocketMessage,\n\tWebsocketMessageOptions,\n\tI_WebsocketChannel,\n\tI_WebsocketClient,\n\tWebsocketEntityData,\n} from \"./websocket.types\";\n\nexport default class Message {\n\tprivate messageTemplate: WebsocketStructuredMessage<any>;\n\n\tconstructor() {\n\t\tthis.messageTemplate = { type: \"\", content: {}, channel: \"\", timestamp: \"\" };\n\t}\n\n\tpublic create(message: WebsocketMessage, options?: WebsocketMessageOptions): WebsocketStructuredMessage {\n\t\t// Clone the template (faster than creating new objects)\n\t\tconst output = Object.assign({}, this.messageTemplate);\n\t\t// Set the dynamic properties in a single pass\n\t\toutput.type = message.type;\n\t\toutput.channel = message.channel || options?.channel || \"N/A\";\n\n\t\t// Process message content based on type\n\t\tif (typeof message.content === \"string\") {\n\t\t\toutput.content = { message: message.content };\n\t\t} else if (typeof message.content === \"object\" && message.content !== null) {\n\t\t\toutput.content = { ...message.content };\n\t\t} else {\n\t\t\toutput.content = {};\n\t\t}\n\n\t\t// Process options in a single pass if provided\n\t\tif (options) {\n\t\t\t// Add data if provided\n\t\t\tif (options.data !== undefined) {\n\t\t\t\tif (typeof options.data === \"object\" && options.data !== null && !Array.isArray(options.data)) {\n\t\t\t\t\t// Merge object data with content\n\t\t\t\t\tObject.assign(output.content, options.data);\n\t\t\t\t} else {\n\t\t\t\t\t// Set as data property for other types\n\t\t\t\t\toutput.content.data = options.data;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add client information if provided\n\t\t\tif (options.client && Guards.IsObject(options.client) && Guards.IsString(options.client.id, true)) {\n\t\t\t\toutput.client = {\n\t\t\t\t\tid: options.client.id,\n\t\t\t\t\tname: options.client.name,\n\t\t\t\t};\n\t\t\t} /* else {\n\t\t\t\tdelete output.client;\n\t\t\t} */\n\n\t\t\t// Include channel metadata if requested\n\t\t\tif (options.includeMetadata !== false) output.metadata = options.metadata;\n\n\t\t\t// Add timestamp if requested (default: true)\n\t\t\tif (options.includeTimestamp !== false) {\n\t\t\t\toutput.timestamp = new Date().toISOString();\n\t\t\t} else {\n\t\t\t\t// Remove timestamp if explicitly disabled\n\t\t\t\tdelete output.timestamp;\n\t\t\t}\n\n\t\t\t// Add priority if specified\n\t\t\tif (options.priority !== undefined) {\n\t\t\t\toutput.priority = options.priority;\n\t\t\t}\n\n\t\t\t// Add expiration if specified\n\t\t\tif (options.expiresAt !== undefined) {\n\t\t\t\toutput.expiresAt = options.expiresAt;\n\t\t\t}\n\n\t\t\t// Add any custom fields to the root of the message\n\t\t\tif (options.customFields) {\n\t\t\t\tObject.assign(output, options.customFields);\n\t\t\t}\n\n\t\t\t// Apply custom transformation if provided\n\t\t\tif (options.transform) {\n\t\t\t\tconst transformed = options.transform(output);\n\t\t\t\treturn transformed;\n\t\t\t}\n\t\t} else {\n\t\t\toutput.timestamp = new Date().toISOString();\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tpublic createWhisper(message: Omit<WebsocketMessage, \"type\">, options?: WebsocketMessageOptions) {\n\t\treturn this.create({ ...message, content: message.content, channel: message.channel, type: \"whisper\" }, options);\n\t}\n\n\tpublic send(target: I_WebsocketClient, message: WebsocketStructuredMessage): void;\n\tpublic send(target: I_WebsocketClient, message: WebsocketMessage, options?: WebsocketMessageOptions): void;\n\tpublic send(target: I_WebsocketClient, message: WebsocketStructuredMessage | WebsocketMessage, options?: WebsocketMessageOptions): void {\n\t\ttarget.send(this.create(message, options));\n\t}\n\n\tpublic alert(target: I_WebsocketClient, reason: string, client?: WebsocketEntityData) {\n\t\ttarget.send(\n\t\t\tthis.create(\n\t\t\t\t{\n\t\t\t\t\tcontent: {\n\t\t\t\t\t\tmessage: reason,\n\t\t\t\t\t},\n\t\t\t\t\tchannel: \"alert\",\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t},\n\t\t\t\t{ client },\n\t\t\t),\n\t\t);\n\t}\n\n\tpublic serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T) {\n\t\treturn transform ? transform(message) : JSON.stringify(message);\n\t}\n\n\tpublic static Serialize<T = string>(message: WebsocketStructuredMessage, transform: (message: WebsocketStructuredMessage) => T): T;\n\tpublic static Serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T;\n\tpublic static Serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T {\n\t\treturn transform ? transform(message) : JSON.stringify(message);\n\t}\n}\n"]}
1
+ {"version":3,"file":"Message.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/Message.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAU3C,MAAM,CAAC,OAAO,OAAO,OAAO;IAG3B;QACC,IAAI,CAAC,eAAe,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAA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C,CAAC;IACjE,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,OAAyB,EAAE,OAAiC;QAChF,MAAM,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;CACD","sourcesContent":["import Guards from \"../../../utils/Guards\";\nimport {\n\tWebsocketStructuredMessage,\n\tWebsocketMessage,\n\tWebsocketMessageOptions,\n\tI_WebsocketChannel,\n\tI_WebsocketClient,\n\tWebsocketEntityData,\n} from \"./websocket.types\";\n\nexport default class Message {\n\tprivate messageTemplate: WebsocketStructuredMessage<any>;\n\n\tconstructor() {\n\t\tthis.messageTemplate = { type: \"\", content: {}, channel: \"\", timestamp: \"\" };\n\t}\n\n\tpublic create(message: WebsocketMessage, options?: WebsocketMessageOptions): WebsocketStructuredMessage {\n\t\t// Clone the template (faster than creating new objects)\n\t\tconst output = Object.assign({}, this.messageTemplate);\n\t\t// Set the dynamic properties in a single pass\n\t\toutput.type = message.type;\n\t\toutput.channel = message.channel || options?.channel || \"N/A\";\n\n\t\t// Process message content based on type\n\t\tif (typeof message.content === \"string\") {\n\t\t\toutput.content = { message: message.content };\n\t\t} else if (typeof message.content === \"object\" && message.content !== null) {\n\t\t\toutput.content = { ...message.content };\n\t\t} else {\n\t\t\toutput.content = {};\n\t\t}\n\n\t\t// Process options in a single pass if provided\n\t\tif (options) {\n\t\t\t// Add data if provided\n\t\t\tif (options.data !== undefined) {\n\t\t\t\tif (typeof options.data === \"object\" && options.data !== null && !Array.isArray(options.data)) {\n\t\t\t\t\t// Merge object data with content\n\t\t\t\t\tObject.assign(output.content, options.data);\n\t\t\t\t} else {\n\t\t\t\t\t// Set as data property for other types\n\t\t\t\t\toutput.content.data = options.data;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add client information if provided\n\t\t\tif (options.client && Guards.IsObject(options.client) && Guards.IsString(options.client.id, true)) {\n\t\t\t\toutput.client = {\n\t\t\t\t\tid: options.client.id,\n\t\t\t\t\tname: options.client.name,\n\t\t\t\t};\n\t\t\t} /* else {\n\t\t\t\tdelete output.client;\n\t\t\t} */\n\n\t\t\t// Include channel metadata if requested\n\t\t\tif (options.includeMetadata !== false) output.metadata = options.metadata;\n\n\t\t\t// Add timestamp if requested (default: true)\n\t\t\tif (options.includeTimestamp !== false) {\n\t\t\t\toutput.timestamp = new Date().toISOString();\n\t\t\t} else {\n\t\t\t\t// Remove timestamp if explicitly disabled\n\t\t\t\tdelete output.timestamp;\n\t\t\t}\n\n\t\t\t// Add priority if specified\n\t\t\tif (options.priority !== undefined) {\n\t\t\t\toutput.priority = options.priority;\n\t\t\t}\n\n\t\t\t// Add expiration if specified\n\t\t\tif (options.expiresAt !== undefined) {\n\t\t\t\toutput.expiresAt = options.expiresAt;\n\t\t\t}\n\n\t\t\t// Add any custom fields to the root of the message\n\t\t\tif (options.customFields) {\n\t\t\t\tObject.assign(output, options.customFields);\n\t\t\t}\n\n\t\t\t// Apply custom transformation if provided\n\t\t\tif (options.transform) {\n\t\t\t\tconst transformed = options.transform(output);\n\t\t\t\treturn transformed;\n\t\t\t}\n\t\t} else {\n\t\t\toutput.timestamp = new Date().toISOString();\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tpublic createWhisper(message: Omit<WebsocketMessage, \"type\">, options?: WebsocketMessageOptions) {\n\t\treturn this.create({ ...message, content: message.content, channel: message.channel, type: \"whisper\" }, options);\n\t}\n\n\tpublic send(target: I_WebsocketClient, message: WebsocketStructuredMessage): void;\n\tpublic send(target: I_WebsocketClient, message: WebsocketMessage, options?: WebsocketMessageOptions): void;\n\tpublic send(target: I_WebsocketClient, message: WebsocketStructuredMessage | WebsocketMessage, options?: WebsocketMessageOptions): void {\n\t\ttarget.send(this.create(message, options));\n\t}\n\n\tpublic alert(target: I_WebsocketClient, reason: string, client?: WebsocketEntityData) {\n\t\ttarget.send(\n\t\t\tthis.create(\n\t\t\t\t{\n\t\t\t\t\tcontent: {\n\t\t\t\t\t\tmessage: reason,\n\t\t\t\t\t},\n\t\t\t\t\tchannel: \"alert\",\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t},\n\t\t\t\t{ client },\n\t\t\t),\n\t\t);\n\t}\n\n\tpublic serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T) {\n\t\treturn transform ? transform(message) : JSON.stringify(message);\n\t}\n\n\tpublic static Serialize<T = string>(message: WebsocketStructuredMessage, transform: (message: WebsocketStructuredMessage) => T): T;\n\tpublic static Serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T;\n\tpublic static Serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T {\n\t\treturn transform ? transform(message) : JSON.stringify(message);\n\t}\n\n\tpublic static Create(message: WebsocketMessage, options?: WebsocketMessageOptions): WebsocketStructuredMessage{\n\t\tconst msg = new Message();\n\t\treturn msg.create(message, options);\n\t}\n}\n"]}
@@ -100,7 +100,8 @@ export interface I_WebsocketEntity extends WebsocketEntityData {
100
100
  }
101
101
  export interface I_WebsocketClient extends I_WebsocketEntity {
102
102
  channels: WebsocketChannel<I_WebsocketChannel>;
103
- send(message: WebsocketStructuredMessage): any;
103
+ send(message: string, options?: WebsocketMessageOptions): void;
104
+ send(message: WebsocketStructuredMessage): void;
104
105
  subscribe(channel: string): any;
105
106
  joinChannel(channel: I_WebsocketChannel, send?: boolean): void;
106
107
  leaveChannel(channel: I_WebsocketChannel, send?: boolean): void;
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.types.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/websocket.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ServerWebSocket, WebSocketHandler } from \"bun\";\nimport Channel from \"./Channel\";\nimport Websocket from \"./Websocket\";\n\nexport type BunWebsocketMessage = string | Buffer<ArrayBufferLike>;\n\nexport type WebsocketChannel<T extends I_WebsocketChannel = Channel> = Map<string, T>;\nexport type WebsocketClients = Map<string, I_WebsocketClient>;\nexport type WebsocketMessageOptions = {\n\t/**\n\t * Additional data to include in the message content\n\t * If an object is provided, it will be merged with the content\n\t * If a primitive value is provided, it will be added as content.data\n\t */\n\tdata?: any;\n\n\t/**\n\t * Client information to include in the message\n\t * Will be added as content.client\n\t */\n\tclient?: Partial<WebsocketEntityData> & {\n\t\t[key: string]: any;\n\t};\n\n\t/**\n\t * Channel metadata to include in the message\n\t * If true, all metadata will be included\n\t * If an array of strings, only the specified keys will be included\n\t */\n\tincludeMetadata?: boolean | string[];\n\n\t/**\n\t * Client IDs to exclude from receiving the broadcast\n\t * Useful for sending messages to all clients except the sender\n\t */\n\texcludeClients?: string[];\n\n\t/**\n\t * Channel to include in the message\n\t * Defaults to the channel of the message\n\t */\n\tchannel?: string;\n\n\t/**\n\t * Whether to include timestamp in the message\n\t * Defaults to true\n\t */\n\tincludeTimestamp?: boolean;\n\n\t/**\n\t * Custom fields to add to the root of the message\n\t * These will be merged with the message object\n\t */\n\tcustomFields?: Record<string, any>;\n\n\t/**\n\t * Transform function to modify the final message before sending\n\t * This is applied after all other processing\n\t */\n\ttransform?: (message: any) => any;\n\n\t/**\n\t * Priority of the message (higher numbers = higher priority)\n\t * Can be used by clients to determine processing order\n\t */\n\tpriority?: number;\n\n\t/**\n\t * Message expiration time in milliseconds since epoch\n\t * Can be used by clients to ignore outdated messages\n\t */\n\texpiresAt?: number;\n\n\t/**\n\t * Metadata to include in the message\n\t * If an array of strings, only the specified keys will be included\n\t */\n\tmetadata?: boolean | string[] | Record<string, string>;\n};\n\nexport type WebsocketMessage<T extends Record<string, any> = Record<string, any>> = {\n\t/**\n\t * Message type identifier used for client-side routing\n\t */\n\ttype: string;\n\t/**\n\t * Message content - can be any data structure\n\t * If a string is provided, it will be wrapped in {message: string}\n\t */\n\tcontent: T;\n\t/**\n\t * Channel ID\n\t */\n\tchannel?: string;\n\t/**\n\t * Timestamp of the message\n\t */\n\ttimestamp?: string;\n\t/**\n\t * Any additional custom fields\n\t */\n\t[key: string]: any;\n};\n\nexport type WebsocketStructuredMessage<T extends Record<string, any> = Record<string, any>> = WebsocketMessage<T> & WebsocketMessageOptions;\n\nexport type WebsocketEntityId = string;\nexport type WebsocketEntityName = string;\nexport type WebsocketEntityData = { id: WebsocketEntityId; name: WebsocketEntityName };\n\nexport interface I_WebsocketEntity extends WebsocketEntityData {\n\tws: ServerWebSocket<WebsocketEntityData>;\n}\n\nexport interface I_WebsocketClient extends I_WebsocketEntity {\n\tchannels: WebsocketChannel<I_WebsocketChannel>;\n\tsend(message: WebsocketStructuredMessage): any;\n\tsubscribe(channel: string): any;\n\tjoinChannel(channel: I_WebsocketChannel, send?: boolean): void;\n\tleaveChannel(channel: I_WebsocketChannel, send?: boolean): void;\n\tjoinChannels(channels: I_WebsocketChannel[], send?: boolean): void;\n\tleaveChannels(channels?: I_WebsocketChannel[], send?: boolean): void;\n\tunsubscribe(channel: string): any;\n\twhoami(): WebsocketEntityData;\n}\n\nexport interface I_WebsocketChannelEntity<T extends Websocket = Websocket> extends WebsocketEntityData {\n\tws: T;\n}\n\n// New types for the broadcast method\nexport type BroadcastOptions = WebsocketMessageOptions & {\n\tdebug?: boolean;\n};\nexport interface I_WebsocketChannel<T extends Websocket = Websocket> extends I_WebsocketChannelEntity<T> {\n\tlimit: number;\n\tmembers: Map<string, I_WebsocketClient>;\n\tmetadata: Record<string, string>;\n\tcreatedAt: Date;\n\tbroadcast(message: WebsocketStructuredMessage | string, options?: BroadcastOptions): void;\n\thasMember(client: I_WebsocketEntity | string): boolean;\n\taddMember(entity: I_WebsocketClient): I_WebsocketClient | false;\n\tremoveMember(entity: I_WebsocketEntity): I_WebsocketClient | false;\n\tgetMember(client: I_WebsocketEntity | string): I_WebsocketClient | undefined;\n\tgetMembers(clients?: string[] | I_WebsocketEntity[]): I_WebsocketClient[];\n\tgetMetadata(): Record<string, string>;\n\tgetCreatedAt(): Date;\n\tgetId(): string;\n\tgetSize(): number;\n\tgetLimit(): number;\n\tgetName(): string;\n\tcanAddMember(): boolean;\n}\n\n/**\n * Interface for implementing custom WebSocket behavior.\n * \n * @interface I_WebsocketInterface\n * \n * @property {Function} setup - Initializes the WebSocket handler with channels and clients\n * \n * The interface supports three optional handler methods:\n * \n * - `message`: Custom message handler that replaces the default handler\n * - `open`: Connection handler that runs after the default open handler\n * - `close`: Disconnection handler that runs before the default close handler\n */\nexport type WebsocketInterfaceHandlers = Partial<WebSocketHandler<WebsocketEntityData>>;\n\n/**\n * Interface for implementing custom WebSocket behavior.\n * \n * @interface I_WebsocketInterface\n * \n * @property {Function} setup - Initializes the WebSocket handler with channels and clients\n * \n * The interface supports three optional handler methods:\n * \n * - `message`: Custom message handler that replaces the default handler\n * - `open`: Connection handler that runs after the default open handler\n * - `close`: Disconnection handler that runs before the default close handler\n */\nexport interface I_WebsocketInterface {\n\thandlers: (channels: WebsocketChannel, clients: WebsocketClients) => WebsocketInterfaceHandlers;\n}\n\n"]}
1
+ {"version":3,"file":"websocket.types.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/websocket.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ServerWebSocket, WebSocketHandler } from \"bun\";\nimport Channel from \"./Channel\";\nimport Websocket from \"./Websocket\";\n\nexport type BunWebsocketMessage = string | Buffer<ArrayBufferLike>;\n\nexport type WebsocketChannel<T extends I_WebsocketChannel = Channel> = Map<string, T>;\nexport type WebsocketClients = Map<string, I_WebsocketClient>;\nexport type WebsocketMessageOptions = {\n\t/**\n\t * Additional data to include in the message content\n\t * If an object is provided, it will be merged with the content\n\t * If a primitive value is provided, it will be added as content.data\n\t */\n\tdata?: any;\n\n\t/**\n\t * Client information to include in the message\n\t * Will be added as content.client\n\t */\n\tclient?: Partial<WebsocketEntityData> & {\n\t\t[key: string]: any;\n\t};\n\n\t/**\n\t * Channel metadata to include in the message\n\t * If true, all metadata will be included\n\t * If an array of strings, only the specified keys will be included\n\t */\n\tincludeMetadata?: boolean | string[];\n\n\t/**\n\t * Client IDs to exclude from receiving the broadcast\n\t * Useful for sending messages to all clients except the sender\n\t */\n\texcludeClients?: string[];\n\n\t/**\n\t * Channel to include in the message\n\t * Defaults to the channel of the message\n\t */\n\tchannel?: string;\n\n\t/**\n\t * Whether to include timestamp in the message\n\t * Defaults to true\n\t */\n\tincludeTimestamp?: boolean;\n\n\t/**\n\t * Custom fields to add to the root of the message\n\t * These will be merged with the message object\n\t */\n\tcustomFields?: Record<string, any>;\n\n\t/**\n\t * Transform function to modify the final message before sending\n\t * This is applied after all other processing\n\t */\n\ttransform?: (message: any) => any;\n\n\t/**\n\t * Priority of the message (higher numbers = higher priority)\n\t * Can be used by clients to determine processing order\n\t */\n\tpriority?: number;\n\n\t/**\n\t * Message expiration time in milliseconds since epoch\n\t * Can be used by clients to ignore outdated messages\n\t */\n\texpiresAt?: number;\n\n\t/**\n\t * Metadata to include in the message\n\t * If an array of strings, only the specified keys will be included\n\t */\n\tmetadata?: boolean | string[] | Record<string, string>;\n};\n\nexport type WebsocketMessage<T extends Record<string, any> = Record<string, any>> = {\n\t/**\n\t * Message type identifier used for client-side routing\n\t */\n\ttype: string;\n\t/**\n\t * Message content - can be any data structure\n\t * If a string is provided, it will be wrapped in {message: string}\n\t */\n\tcontent: T;\n\t/**\n\t * Channel ID\n\t */\n\tchannel?: string;\n\t/**\n\t * Timestamp of the message\n\t */\n\ttimestamp?: string;\n\t/**\n\t * Any additional custom fields\n\t */\n\t[key: string]: any;\n};\n\nexport type WebsocketStructuredMessage<T extends Record<string, any> = Record<string, any>> = WebsocketMessage<T> & WebsocketMessageOptions;\n\nexport type WebsocketEntityId = string;\nexport type WebsocketEntityName = string;\nexport type WebsocketEntityData = { id: WebsocketEntityId; name: WebsocketEntityName };\n\nexport interface I_WebsocketEntity extends WebsocketEntityData {\n\tws: ServerWebSocket<WebsocketEntityData>;\n}\n\nexport interface I_WebsocketClient extends I_WebsocketEntity {\n\tchannels: WebsocketChannel<I_WebsocketChannel>;\n\tsend(message: string, options?: WebsocketMessageOptions): void;\n\tsend(message: WebsocketStructuredMessage): void;\n\tsubscribe(channel: string): any;\n\tjoinChannel(channel: I_WebsocketChannel, send?: boolean): void;\n\tleaveChannel(channel: I_WebsocketChannel, send?: boolean): void;\n\tjoinChannels(channels: I_WebsocketChannel[], send?: boolean): void;\n\tleaveChannels(channels?: I_WebsocketChannel[], send?: boolean): void;\n\tunsubscribe(channel: string): any;\n\twhoami(): WebsocketEntityData;\n}\n\nexport interface I_WebsocketChannelEntity<T extends Websocket = Websocket> extends WebsocketEntityData {\n\tws: T;\n}\n\n// New types for the broadcast method\nexport type BroadcastOptions = WebsocketMessageOptions & {\n\tdebug?: boolean;\n};\nexport interface I_WebsocketChannel<T extends Websocket = Websocket> extends I_WebsocketChannelEntity<T> {\n\tlimit: number;\n\tmembers: Map<string, I_WebsocketClient>;\n\tmetadata: Record<string, string>;\n\tcreatedAt: Date;\n\tbroadcast(message: WebsocketStructuredMessage | string, options?: BroadcastOptions): void;\n\thasMember(client: I_WebsocketEntity | string): boolean;\n\taddMember(entity: I_WebsocketClient): I_WebsocketClient | false;\n\tremoveMember(entity: I_WebsocketEntity): I_WebsocketClient | false;\n\tgetMember(client: I_WebsocketEntity | string): I_WebsocketClient | undefined;\n\tgetMembers(clients?: string[] | I_WebsocketEntity[]): I_WebsocketClient[];\n\tgetMetadata(): Record<string, string>;\n\tgetCreatedAt(): Date;\n\tgetId(): string;\n\tgetSize(): number;\n\tgetLimit(): number;\n\tgetName(): string;\n\tcanAddMember(): boolean;\n}\n\n/**\n * Interface for implementing custom WebSocket behavior.\n *\n * @interface I_WebsocketInterface\n *\n * @property {Function} setup - Initializes the WebSocket handler with channels and clients\n *\n * The interface supports three optional handler methods:\n *\n * - `message`: Custom message handler that replaces the default handler\n * - `open`: Connection handler that runs after the default open handler\n * - `close`: Disconnection handler that runs before the default close handler\n */\nexport type WebsocketInterfaceHandlers = Partial<WebSocketHandler<WebsocketEntityData>>;\n\n/**\n * Interface for implementing custom WebSocket behavior.\n *\n * @interface I_WebsocketInterface\n *\n * @property {Function} setup - Initializes the WebSocket handler with channels and clients\n *\n * The interface supports three optional handler methods:\n *\n * - `message`: Custom message handler that replaces the default handler\n * - `open`: Connection handler that runs after the default open handler\n * - `close`: Disconnection handler that runs before the default close handler\n */\nexport interface I_WebsocketInterface {\n\thandlers: (channels: WebsocketChannel, clients: WebsocketClients) => WebsocketInterfaceHandlers;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topsyde-utils",
3
- "version": "1.0.180",
3
+ "version": "1.0.182",
4
4
  "description": "A bundle of TypeScript utility classes and functions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -39,6 +39,10 @@
39
39
  "types": "./dist/client/vite/plugins/index.d.ts",
40
40
  "default": "./dist/client/vite/plugins/index.js"
41
41
  },
42
+ "./server/base": {
43
+ "types": "./dist/server/base/index.d.ts",
44
+ "default": "./dist/server/base/index.js"
45
+ },
42
46
  "./server/bun/router": {
43
47
  "types": "./dist/server/bun/router/index.d.ts",
44
48
  "default": "./dist/server/bun/router/index.js"
@@ -60,6 +64,9 @@
60
64
  "client/vite/plugins": [
61
65
  "./dist/client/vite/plugins/index.d.ts"
62
66
  ],
67
+ "server/base": [
68
+ "./dist/server/base/index.d.ts"
69
+ ],
63
70
  "server/bun/router": [
64
71
  "./dist/server/bun/router/index.d.ts"
65
72
  ],
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./client/rxjs/useRxjs";
15
15
  export * from "./client/vite/plugins/topsydeUtilsVitePlugin";
16
16
  export * from "./server/controller";
17
17
  export * from "./server/service";
18
+ export * from "./server/base/base.database";
18
19
  export * from "./server/bun/router/controller-discovery";
19
20
  export * from "./server/bun/router/routes";
20
21
  export * from "./server/bun/router/router";
@@ -38,6 +39,7 @@ export { default as Throwable } from "./throwable";
38
39
  export { default as TopsydeUtilsVitePlugin } from "./client/vite/plugins/topsydeUtilsVitePlugin";
39
40
  export { default as Controller } from "./server/controller";
40
41
  export { default as Service } from "./server/service";
42
+ export { default as Database } from "./server/base/base.database";
41
43
  export { default as Router } from "./server/bun/router/router";
42
44
  export { default as Router_Internal } from "./server/bun/router/router.internal";
43
45
  export { default as Client } from "./server/bun/websocket/Client";
@@ -0,0 +1,31 @@
1
+ import Singleton from "../../singleton";
2
+
3
+ abstract class Database extends Singleton {
4
+ constructor() {
5
+ super();
6
+ }
7
+
8
+ public abstract connect(): Promise<void>;
9
+ public abstract disconnect(): Promise<void>;
10
+
11
+ protected connected: boolean = false;
12
+ protected processing: boolean = false;
13
+
14
+ public static async Connection<T extends (new (...args: any[]) => Database) & typeof Singleton>(
15
+ this: T,
16
+ ...args: ConstructorParameters<T>
17
+ ): Promise<InstanceType<T>> {
18
+ try {
19
+ const instance = this.GetInstance(...args) as InstanceType<T>;
20
+ if (!instance.connected && !instance.processing) {
21
+ await instance.connect();
22
+ }
23
+ return instance;
24
+ } catch (e) {
25
+ console.error(e);
26
+ throw e;
27
+ }
28
+ }
29
+ }
30
+
31
+ export default Database;
@@ -0,0 +1,5 @@
1
+ // This file is auto-generated by scripts/generate-indexes.ts
2
+ // Do not edit this file directly
3
+
4
+ export * from './base.database';
5
+ export { default as Database } from './base.database';
@@ -6,9 +6,12 @@ import type {
6
6
  WebsocketStructuredMessage,
7
7
  I_WebsocketEntity,
8
8
  I_WebsocketChannel,
9
+ WebsocketMessageOptions,
10
+ WebsocketMessage,
9
11
  } from "./websocket.types";
10
12
  import { E_WebsocketMessageType } from "./websocket.enums";
11
- import { Lib } from "../../../utils";
13
+ import { Guards, Lib } from "../../../utils";
14
+ import Message from "./Message";
12
15
 
13
16
  export default class Client implements I_WebsocketClient {
14
17
  private _id: string;
@@ -101,7 +104,16 @@ export default class Client implements I_WebsocketClient {
101
104
  return { id: this.id, name: this.name };
102
105
  }
103
106
 
104
- public send(message: WebsocketStructuredMessage) {
107
+ public send(message: string, options?: WebsocketMessageOptions): void;
108
+ public send(message: WebsocketStructuredMessage): void;
109
+ public send(message: WebsocketStructuredMessage | string, options?: WebsocketMessageOptions): void {
110
+ if (Guards.IsString(message)) {
111
+ const msg: WebsocketMessage = {
112
+ type: "message",
113
+ content: { message },
114
+ };
115
+ message = Message.Create(msg, options);
116
+ }
105
117
  this.ws.send(JSON.stringify({ client: this.whoami(), ...message }));
106
118
  }
107
119
 
@@ -125,4 +125,9 @@ export default class Message {
125
125
  public static Serialize<T = string>(message: WebsocketStructuredMessage, transform?: (message: WebsocketStructuredMessage) => T): string | T {
126
126
  return transform ? transform(message) : JSON.stringify(message);
127
127
  }
128
+
129
+ public static Create(message: WebsocketMessage, options?: WebsocketMessageOptions): WebsocketStructuredMessage{
130
+ const msg = new Message();
131
+ return msg.create(message, options);
132
+ }
128
133
  }
@@ -114,7 +114,8 @@ export interface I_WebsocketEntity extends WebsocketEntityData {
114
114
 
115
115
  export interface I_WebsocketClient extends I_WebsocketEntity {
116
116
  channels: WebsocketChannel<I_WebsocketChannel>;
117
- send(message: WebsocketStructuredMessage): any;
117
+ send(message: string, options?: WebsocketMessageOptions): void;
118
+ send(message: WebsocketStructuredMessage): void;
118
119
  subscribe(channel: string): any;
119
120
  joinChannel(channel: I_WebsocketChannel, send?: boolean): void;
120
121
  leaveChannel(channel: I_WebsocketChannel, send?: boolean): void;
@@ -154,13 +155,13 @@ export interface I_WebsocketChannel<T extends Websocket = Websocket> extends I_W
154
155
 
155
156
  /**
156
157
  * Interface for implementing custom WebSocket behavior.
157
- *
158
+ *
158
159
  * @interface I_WebsocketInterface
159
- *
160
+ *
160
161
  * @property {Function} setup - Initializes the WebSocket handler with channels and clients
161
- *
162
+ *
162
163
  * The interface supports three optional handler methods:
163
- *
164
+ *
164
165
  * - `message`: Custom message handler that replaces the default handler
165
166
  * - `open`: Connection handler that runs after the default open handler
166
167
  * - `close`: Disconnection handler that runs before the default close handler
@@ -169,13 +170,13 @@ export type WebsocketInterfaceHandlers = Partial<WebSocketHandler<WebsocketEntit
169
170
 
170
171
  /**
171
172
  * Interface for implementing custom WebSocket behavior.
172
- *
173
+ *
173
174
  * @interface I_WebsocketInterface
174
- *
175
+ *
175
176
  * @property {Function} setup - Initializes the WebSocket handler with channels and clients
176
- *
177
+ *
177
178
  * The interface supports three optional handler methods:
178
- *
179
+ *
179
180
  * - `message`: Custom message handler that replaces the default handler
180
181
  * - `open`: Connection handler that runs after the default open handler
181
182
  * - `close`: Disconnection handler that runs before the default close handler
@@ -183,4 +184,3 @@ export type WebsocketInterfaceHandlers = Partial<WebSocketHandler<WebsocketEntit
183
184
  export interface I_WebsocketInterface {
184
185
  handlers: (channels: WebsocketChannel, clients: WebsocketClients) => WebsocketInterfaceHandlers;
185
186
  }
186
-