topsyde-utils 1.0.165 → 1.0.167

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.
@@ -87,7 +87,7 @@ export default class Message {
87
87
  message: reason,
88
88
  },
89
89
  channel: "alert",
90
- type: "alert",
90
+ type: "message",
91
91
  }, { client }));
92
92
  }
93
93
  serialize(message, transform) {
@@ -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,OAAO,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC5E,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QACzC,CAAC;aAAM,CAAC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AI,CAAC,MAAM,CACV;YACC,OAAO,EAAE;gBACR,OAAO,EAAE,MAAM;aACf;YACD,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,OAAO;SACb,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: \"alert\",\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,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IAC9E,CAAC;IAEM,MAAM,CAAC,OAAyB,EAAE,OAAiC;QACzE,wDAAwD;QACxD,MAAM,MAAM,G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CAAC;YACP,MAAM,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,aAAa,CAAC,OAAuC,EAAE,OAAiC;QAC9F,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;IAClH,CAAC;IAIM,IAAI,CAAC,MAAyB,EAAE,OAAsD,EAAE,OAAiC;QAC/H,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,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,2 +1,3 @@
1
- import { WebsocketStructuredMessage } from "./websocket.types";
1
+ import { I_WebsocketEntity, WebsocketStructuredMessage } from "./websocket.types";
2
2
  export declare function IsWebsocketStructuredMessage(message: any): message is WebsocketStructuredMessage;
3
+ export declare function IsWebsocketClient(entity: any): entity is I_WebsocketEntity;
@@ -1,4 +1,17 @@
1
1
  export function IsWebsocketStructuredMessage(message) {
2
2
  return typeof message === "object" && message !== null && "type" in message && "content" in message;
3
3
  }
4
+ export function IsWebsocketClient(entity) {
5
+ return (typeof entity === "object" &&
6
+ entity !== null &&
7
+ "id" in entity &&
8
+ "name" in entity &&
9
+ "ws" in entity &&
10
+ typeof entity.ws === "object" &&
11
+ entity.ws !== null &&
12
+ "send" in entity.ws &&
13
+ typeof entity.ws.send === "function" &&
14
+ "close" in entity.ws &&
15
+ typeof entity.ws.close === "function");
16
+ }
4
17
  //# sourceMappingURL=websocket.guards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.guards.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/websocket.guards.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,4BAA4B,CAAC,OAAY;IACxD,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,MAAM,IAAI,OAAO,IAAI,SAAS,IAAI,OAAO,CAAC;AACrG,CAAC","sourcesContent":["import { WebsocketStructuredMessage } from \"./websocket.types\";\n\nexport function IsWebsocketStructuredMessage(message: any): message is WebsocketStructuredMessage {\n\treturn typeof message === \"object\" && message !== null && \"type\" in message && \"content\" in message;\n}\n\n"]}
1
+ {"version":3,"file":"websocket.guards.js","sourceRoot":"","sources":["../../../../src/server/bun/websocket/websocket.guards.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,4BAA4B,CAAC,OAAY;IACxD,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,MAAM,IAAI,OAAO,IAAI,SAAS,IAAI,OAAO,CAAC;AACrG,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAW;IAC5C,OAAO,CACN,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,IAAI,IAAI,MAAM;QACd,MAAM,IAAI,MAAM;QAChB,IAAI,IAAI,MAAM;QACd,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,MAAM,CAAC,EAAE,KAAK,IAAI;QAClB,MAAM,IAAI,MAAM,CAAC,EAAE;QACnB,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,KAAK,UAAU;QACpC,OAAO,IAAI,MAAM,CAAC,EAAE;QACpB,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,KAAK,UAAU,CACrC,CAAC;AACH,CAAC","sourcesContent":["import { I_WebsocketClient, I_WebsocketEntity, WebsocketStructuredMessage } from \"./websocket.types\";\nimport { type ServerWebSocket } from \"bun\";\n\nexport function IsWebsocketStructuredMessage(message: any): message is WebsocketStructuredMessage {\n\treturn typeof message === \"object\" && message !== null && \"type\" in message && \"content\" in message;\n}\n\nexport function IsWebsocketClient(entity: any): entity is I_WebsocketEntity {\n\treturn (\n\t\ttypeof entity === \"object\" &&\n\t\tentity !== null &&\n\t\t\"id\" in entity &&\n\t\t\"name\" in entity &&\n\t\t\"ws\" in entity &&\n\t\ttypeof entity.ws === \"object\" &&\n\t\tentity.ws !== null &&\n\t\t\"send\" in entity.ws &&\n\t\ttypeof entity.ws.send === \"function\" &&\n\t\t\"close\" in entity.ws &&\n\t\ttypeof entity.ws.close === \"function\"\n\t);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topsyde-utils",
3
- "version": "1.0.165",
3
+ "version": "1.0.167",
4
4
  "description": "A bundle of TypeScript utility classes and functions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -109,7 +109,7 @@ export default class Message {
109
109
  message: reason,
110
110
  },
111
111
  channel: "alert",
112
- type: "alert",
112
+ type: "message",
113
113
  },
114
114
  { client },
115
115
  ),
@@ -1,6 +1,22 @@
1
- import { WebsocketStructuredMessage } from "./websocket.types";
1
+ import { I_WebsocketClient, I_WebsocketEntity, WebsocketStructuredMessage } from "./websocket.types";
2
+ import { type ServerWebSocket } from "bun";
2
3
 
3
4
  export function IsWebsocketStructuredMessage(message: any): message is WebsocketStructuredMessage {
4
5
  return typeof message === "object" && message !== null && "type" in message && "content" in message;
5
6
  }
6
7
 
8
+ export function IsWebsocketClient(entity: any): entity is I_WebsocketEntity {
9
+ return (
10
+ typeof entity === "object" &&
11
+ entity !== null &&
12
+ "id" in entity &&
13
+ "name" in entity &&
14
+ "ws" in entity &&
15
+ typeof entity.ws === "object" &&
16
+ entity.ws !== null &&
17
+ "send" in entity.ws &&
18
+ typeof entity.ws.send === "function" &&
19
+ "close" in entity.ws &&
20
+ typeof entity.ws.close === "function"
21
+ );
22
+ }