@api.global/typedsocket 3.0.1 → 4.0.0

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * autocreated commitinfo by @pushrocks/commitinfo
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
3
  */
4
4
  export declare const commitinfo: {
5
5
  name: string;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * autocreated commitinfo by @pushrocks/commitinfo
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@api.global/typedsocket',
6
- version: '3.0.1',
6
+ version: '4.0.0',
7
7
  description: 'A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLCtHQUErRztDQUM3SCxDQUFBIn0=
@@ -1,34 +1,81 @@
1
1
  import * as plugins from './typedsocket.plugins.js';
2
2
  export type TTypedSocketSide = 'server' | 'client';
3
+ /**
4
+ * Wrapper for SmartServe's IWebSocketPeer to provide tag compatibility
5
+ * SmartServe uses Set<string> for tags, while TypedSocket uses {id, payload} format
6
+ */
7
+ export interface ISmartServeConnectionWrapper {
8
+ peer: plugins.IWebSocketPeer;
9
+ getTagById(tagId: string): Promise<{
10
+ id: string;
11
+ payload: any;
12
+ } | undefined>;
13
+ }
3
14
  export declare class TypedSocket {
4
15
  /**
5
16
  * creates a typedsocket server
6
17
  * note: this will fail in browser environments as server libs are not bundled.
7
18
  */
8
- static createServer(typedrouterArg: plugins.typedrequest.TypedRouter, smartexpressServerArg?: any): Promise<TypedSocket>;
19
+ static createServer(typedrouterArg: plugins.typedrequest.TypedRouter): Promise<TypedSocket>;
9
20
  static createClient(typedrouterArg: plugins.typedrequest.TypedRouter, serverUrlArg: string, aliasArg?: string): Promise<TypedSocket>;
10
21
  static useWindowLocationOriginUrl: () => string;
22
+ /**
23
+ * Creates a TypedSocket server from an existing SmartServe instance.
24
+ * Use this when you want TypedSocket to work with SmartServe's WebSocket handling.
25
+ *
26
+ * @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
27
+ * @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const typedRouter = new TypedRouter();
32
+ * const smartServe = new SmartServe({
33
+ * port: 3000,
34
+ * websocket: {
35
+ * typedRouter,
36
+ * onConnectionOpen: (peer) => peer.tags.add('client')
37
+ * }
38
+ * });
39
+ * await smartServe.start();
40
+ * const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
41
+ * ```
42
+ */
43
+ static fromSmartServe(smartServeArg: plugins.SmartServe, typedRouterArg: plugins.typedrequest.TypedRouter): TypedSocket;
11
44
  side: TTypedSocketSide;
12
45
  typedrouter: plugins.typedrequest.TypedRouter;
46
+ private smartServeRef?;
47
+ private smartServeConnectionWrappers;
13
48
  get eventSubject(): plugins.smartrx.rxjs.Subject<plugins.smartsocket.TConnectionStatus>;
14
49
  private postMethod;
15
50
  private socketServerOrClient;
16
51
  constructor(sideArg: TTypedSocketSide, typedrouterArg: plugins.typedrequest.TypedRouter, postMethodArg: plugins.typedrequest.IPostMethod, socketServerOrClientArg: plugins.smartsocket.Smartsocket | plugins.smartsocket.SmartsocketClient);
17
52
  addTag<T extends plugins.typedrequestInterfaces.ITag = any>(nameArg: T['name'], payloadArg: T['payload']): void;
18
- createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(methodName: T['method'], targetConnection?: plugins.smartsocket.SocketConnection): plugins.typedrequest.TypedRequest<T>;
53
+ createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(methodName: T['method'], targetConnection?: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper): plugins.typedrequest.TypedRequest<T>;
19
54
  /**
20
- * returns all matching target connection
21
- * @param asyncFindFuncArg
22
- * @returns
55
+ * returns all matching target connections
56
+ * Works with both Smartsocket and SmartServe backends
57
+ * @param asyncFindFuncArg - async filter function
58
+ * @returns array of matching connections
23
59
  */
24
- findAllTargetConnections(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>): Promise<plugins.smartsocket.SocketConnection[]>;
60
+ findAllTargetConnections(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]>;
25
61
  /**
26
62
  * returns a single target connection by returning the first one of all matching ones
27
63
  * @param asyncFindFuncArg
28
64
  * @returns
29
65
  */
30
- findTargetConnection(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>): Promise<plugins.smartsocket.SocketConnection>;
31
- findAllTargetConnectionsByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<plugins.smartsocket.SocketConnection[]>;
32
- findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<plugins.smartsocket.SocketConnection>;
66
+ findTargetConnection(asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined>;
67
+ /**
68
+ * Find all connections that have a specific tag
69
+ * Works with both Smartsocket and SmartServe backends
70
+ */
71
+ findAllTargetConnectionsByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]>;
72
+ /**
73
+ * Find a single connection by tag
74
+ */
75
+ findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined>;
76
+ /**
77
+ * Stop the TypedSocket server/client
78
+ * Note: In SmartServe mode, SmartServe manages its own lifecycle
79
+ */
33
80
  stop(): Promise<void>;
34
81
  }
@@ -1,20 +1,33 @@
1
1
  import * as plugins from './typedsocket.plugins.js';
2
2
  const publicRoleName = 'publicRoleName';
3
3
  const publicRolePass = 'publicRolePass';
4
+ /**
5
+ * Creates a wrapper around IWebSocketPeer for tag compatibility
6
+ */
7
+ function wrapSmartServePeer(peer) {
8
+ const TAG_PREFIX = '__typedsocket_tag__';
9
+ return {
10
+ peer,
11
+ async getTagById(tagId) {
12
+ if (!peer.tags.has(tagId)) {
13
+ return undefined;
14
+ }
15
+ const payload = peer.data.get(`${TAG_PREFIX}${tagId}`);
16
+ return { id: tagId, payload };
17
+ },
18
+ };
19
+ }
4
20
  export class TypedSocket {
5
21
  // STATIC
6
22
  /**
7
23
  * creates a typedsocket server
8
24
  * note: this will fail in browser environments as server libs are not bundled.
9
25
  */
10
- static async createServer(typedrouterArg, smartexpressServerArg) {
26
+ static async createServer(typedrouterArg) {
11
27
  const smartsocketServer = new plugins.smartsocket.Smartsocket({
12
28
  alias: 'typedsocketServer',
13
29
  port: 3000,
14
30
  });
15
- if (smartexpressServerArg) {
16
- smartsocketServer.setExternalServer('smartexpress', smartexpressServerArg);
17
- }
18
31
  smartsocketServer.socketFunctions.add(new plugins.smartsocket.SocketFunction({
19
32
  funcName: 'processMessage',
20
33
  funcDef: async (dataArg, socketConnectionArg) => {
@@ -68,10 +81,75 @@ export class TypedSocket {
68
81
  const windowLocationResult = plugins.smarturl.Smarturl.createFromUrl(globalThis.location.origin).toString();
69
82
  return windowLocationResult;
70
83
  }; }
84
+ /**
85
+ * Creates a TypedSocket server from an existing SmartServe instance.
86
+ * Use this when you want TypedSocket to work with SmartServe's WebSocket handling.
87
+ *
88
+ * @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
89
+ * @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const typedRouter = new TypedRouter();
94
+ * const smartServe = new SmartServe({
95
+ * port: 3000,
96
+ * websocket: {
97
+ * typedRouter,
98
+ * onConnectionOpen: (peer) => peer.tags.add('client')
99
+ * }
100
+ * });
101
+ * await smartServe.start();
102
+ * const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
103
+ * ```
104
+ */
105
+ static fromSmartServe(smartServeArg, typedRouterArg) {
106
+ const connectionWrappers = new Map();
107
+ // Create the postMethod for server-initiated requests
108
+ const postMethod = async (dataArg, targetConnectionArg) => {
109
+ if (!targetConnectionArg) {
110
+ const allConnections = smartServeArg.getWebSocketConnections();
111
+ if (allConnections.length === 1) {
112
+ console.log('Since no targetConnection was supplied and there is only one active one present, choosing that one automatically');
113
+ const peer = allConnections[0];
114
+ let wrapper = connectionWrappers.get(peer.id);
115
+ if (!wrapper) {
116
+ wrapper = wrapSmartServePeer(peer);
117
+ connectionWrappers.set(peer.id, wrapper);
118
+ }
119
+ targetConnectionArg = wrapper;
120
+ }
121
+ else if (allConnections.length === 0) {
122
+ throw new Error('No WebSocket connections available');
123
+ }
124
+ else {
125
+ throw new Error('you need to specify the wanted targetConnection. Currently no target is selectable automatically.');
126
+ }
127
+ }
128
+ // Register interest for the response using correlation ID
129
+ const interest = await typedRouterArg.fireEventInterestMap.addInterest(dataArg.correlation.id, dataArg);
130
+ // Send the request to the client
131
+ targetConnectionArg.peer.send(plugins.smartjson.stringify(dataArg));
132
+ // Wait for the response (TypedRouter will fulfill via routeAndAddResponse when response arrives)
133
+ const response = await interest.interestFullfilled;
134
+ return response;
135
+ };
136
+ const typedSocket = new TypedSocket('server', typedRouterArg, postMethod, null // No smartsocket server/client when using SmartServe
137
+ );
138
+ typedSocket.smartServeRef = smartServeArg;
139
+ typedSocket.smartServeConnectionWrappers = connectionWrappers;
140
+ return typedSocket;
141
+ }
71
142
  get eventSubject() {
143
+ if (this.smartServeRef) {
144
+ // SmartServe doesn't provide an eventSubject, return a new Subject
145
+ // In SmartServe mode, connection events are handled via onConnectionOpen/onConnectionClose hooks
146
+ console.warn('eventSubject is not fully supported in SmartServe mode. Use SmartServe hooks instead.');
147
+ return new plugins.smartrx.rxjs.Subject();
148
+ }
72
149
  return this.socketServerOrClient.eventSubject;
73
150
  }
74
151
  constructor(sideArg, typedrouterArg, postMethodArg, socketServerOrClientArg) {
152
+ this.smartServeConnectionWrappers = new Map();
75
153
  this.side = sideArg;
76
154
  this.typedrouter = typedrouterArg;
77
155
  this.postMethod = postMethodArg;
@@ -99,11 +177,28 @@ export class TypedSocket {
99
177
  return typedrequest;
100
178
  }
101
179
  /**
102
- * returns all matching target connection
103
- * @param asyncFindFuncArg
104
- * @returns
180
+ * returns all matching target connections
181
+ * Works with both Smartsocket and SmartServe backends
182
+ * @param asyncFindFuncArg - async filter function
183
+ * @returns array of matching connections
105
184
  */
106
185
  async findAllTargetConnections(asyncFindFuncArg) {
186
+ // SmartServe mode
187
+ if (this.smartServeRef) {
188
+ const matchingConnections = [];
189
+ for (const peer of this.smartServeRef.getWebSocketConnections()) {
190
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
191
+ if (!wrapper) {
192
+ wrapper = wrapSmartServePeer(peer);
193
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
194
+ }
195
+ if (await asyncFindFuncArg(wrapper)) {
196
+ matchingConnections.push(wrapper);
197
+ }
198
+ }
199
+ return matchingConnections;
200
+ }
201
+ // Smartsocket mode
107
202
  if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) {
108
203
  const matchingSockets = [];
109
204
  for (const socketConnection of this.socketServerOrClient.socketConnections.getArray()) {
@@ -113,9 +208,7 @@ export class TypedSocket {
113
208
  }
114
209
  return matchingSockets;
115
210
  }
116
- else {
117
- throw new Error('this method >>findTargetConnection<< is only available from the server');
118
- }
211
+ throw new Error('this method >>findTargetConnection<< is only available from the server');
119
212
  }
120
213
  /**
121
214
  * returns a single target connection by returning the first one of all matching ones
@@ -126,7 +219,33 @@ export class TypedSocket {
126
219
  const allMatching = await this.findAllTargetConnections(asyncFindFuncArg);
127
220
  return allMatching[0];
128
221
  }
222
+ /**
223
+ * Find all connections that have a specific tag
224
+ * Works with both Smartsocket and SmartServe backends
225
+ */
129
226
  async findAllTargetConnectionsByTag(keyArg, payloadArg) {
227
+ // SmartServe mode - use native filtering for better performance
228
+ if (this.smartServeRef) {
229
+ const peers = this.smartServeRef.getWebSocketConnectionsByTag(keyArg);
230
+ const results = [];
231
+ for (const peer of peers) {
232
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
233
+ if (!wrapper) {
234
+ wrapper = wrapSmartServePeer(peer);
235
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
236
+ }
237
+ // If payload specified, also filter by payload stored in peer.data
238
+ if (payloadArg !== undefined) {
239
+ const tag = await wrapper.getTagById(keyArg);
240
+ if (plugins.smartjson.stringify(tag?.payload) !== plugins.smartjson.stringify(payloadArg)) {
241
+ continue;
242
+ }
243
+ }
244
+ results.push(wrapper);
245
+ }
246
+ return results;
247
+ }
248
+ // Smartsocket mode - use existing logic
130
249
  return this.findAllTargetConnections(async (socketConnectionArg) => {
131
250
  let result;
132
251
  if (!payloadArg) {
@@ -139,12 +258,25 @@ export class TypedSocket {
139
258
  return result;
140
259
  });
141
260
  }
261
+ /**
262
+ * Find a single connection by tag
263
+ */
142
264
  async findTargetConnectionByTag(keyArg, payloadArg) {
143
265
  const allResults = await this.findAllTargetConnectionsByTag(keyArg, payloadArg);
144
266
  return allResults[0];
145
267
  }
268
+ /**
269
+ * Stop the TypedSocket server/client
270
+ * Note: In SmartServe mode, SmartServe manages its own lifecycle
271
+ */
146
272
  async stop() {
273
+ if (this.smartServeRef) {
274
+ // SmartServe manages its own lifecycle
275
+ // Clear our connection wrappers
276
+ this.smartServeConnectionWrappers.clear();
277
+ return;
278
+ }
147
279
  await this.socketServerOrClient.stop();
148
280
  }
149
281
  }
150
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZWRzb2NrZXQuY2xhc3Nlcy50eXBlZHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3R5cGVkc29ja2V0LmNsYXNzZXMudHlwZWRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSwwQkFBMEIsQ0FBQztBQUVwRCxNQUFNLGNBQWMsR0FBRyxnQkFBZ0IsQ0FBQztBQUN4QyxNQUFNLGNBQWMsR0FBRyxnQkFBZ0IsQ0FBQztBQUl4QyxNQUFNLE9BQU8sV0FBVztJQUN0QixTQUFTO0lBQ1Q7OztPQUdHO0lBQ0ksTUFBTSxDQUFDLEtBQUssQ0FBQyxZQUFZLENBQzlCLGNBQWdELEVBQ2hELHFCQUEyQjtRQUUzQixNQUFNLGlCQUFpQixHQUFHLElBQUksT0FBTyxDQUFDLFdBQVcsQ0FBQyxXQUFXLENBQUM7WUFDNUQsS0FBSyxFQUFFLG1CQUFtQjtZQUMxQixJQUFJLEVBQUUsSUFBSTtTQUNYLENBQUMsQ0FBQztRQUNILElBQUkscUJBQXFCLEVBQUUsQ0FBQztZQUMxQixpQkFBaUIsQ0FBQyxpQkFBaUIsQ0FBQyxjQUFjLEVBQUUscUJBQXFCLENBQUMsQ0FBQztRQUM3RSxDQUFDO1FBRUQsaUJBQWlCLENBQUMsZUFBZSxDQUFDL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BTyxNQUFNLENBQUM7UUFDaEIsQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDO0lBRUQ7O09BRUc7SUFDSSxLQUFLLENBQUMseUJBQXlCLENBQ3BDLE1BQW9CLEVBQ3BCLFVBQTRCO1FBRTVCLE1BQU0sVUFBVSxHQUFHLE1BQU0sSUFBSSxDQUFDLDZCQUE2QixDQUFDLE1BQU0sRUFBRSxVQUFVLENBQUMsQ0FBQztRQUNoRixPQUFPLFVBQVUsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN2QixDQUFDO0lBRUQ7OztPQUdHO0lBQ0ksS0FBSyxDQUFDLElBQUk7UUFDZixJQUFJLElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQztZQUN2Qix1Q0FBdUM7WUFDdkMsZ0NBQWdDO1lBQ2hDLElBQUksQ0FBQyw0QkFBNEIsQ0FBQyxLQUFLLEVBQUUsQ0FBQztZQUMxQyxPQUFPO1FBQ1QsQ0FBQztRQUNELE1BQU0sSUFBSSxDQUFDLG9CQUFvQixDQUFDLElBQUksRUFBRSxDQUFDO0lBQ3pDLENBQUMifQ==
@@ -8,3 +8,4 @@ import * as smartsocket from '@push.rocks/smartsocket';
8
8
  import * as smartstring from '@push.rocks/smartstring';
9
9
  import * as smarturl from '@push.rocks/smarturl';
10
10
  export { isohash, smartjson, smartrx, smartsocket, smartstring, smarturl };
11
+ export type { SmartServe, IWebSocketPeer } from '@push.rocks/smartserve';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@api.global/typedsocket",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "private": false,
5
5
  "description": "A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.",
6
6
  "main": "dist_ts/index.js",
@@ -9,23 +9,32 @@
9
9
  "author": "Lossless GmbH",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
- "@git.zone/tsbuild": "^2.1.66",
13
- "@git.zone/tsbundle": "^2.0.8",
14
- "@git.zone/tsrun": "^1.2.44",
15
- "@git.zone/tstest": "^1.0.77",
16
- "@push.rocks/smartenv": "^5.0.12",
17
- "@push.rocks/tapbundle": "^5.0.23",
18
- "@types/node": "^20.12.7"
12
+ "@git.zone/tsbuild": "^3.1.2",
13
+ "@git.zone/tsbundle": "^2.6.2",
14
+ "@git.zone/tsrun": "^2.0.0",
15
+ "@git.zone/tstest": "^3.1.3",
16
+ "@push.rocks/smartenv": "^6.0.0",
17
+ "@push.rocks/smartserve": "^1.1.0",
18
+ "@push.rocks/tapbundle": "^6.0.3",
19
+ "@types/node": "^24.10.1"
19
20
  },
20
21
  "dependencies": {
21
- "@api.global/typedrequest": "^3.0.21",
22
- "@api.global/typedrequest-interfaces": "^3.0.18",
23
- "@push.rocks/isohash": "^2.0.0",
24
- "@push.rocks/smartjson": "^5.0.19",
25
- "@push.rocks/smartrx": "^3.0.7",
26
- "@push.rocks/smartsocket": "^2.0.25",
27
- "@push.rocks/smartstring": "^4.0.15",
28
- "@push.rocks/smarturl": "^3.0.5"
22
+ "@api.global/typedrequest": "^3.1.10",
23
+ "@api.global/typedrequest-interfaces": "^3.0.19",
24
+ "@push.rocks/isohash": "^2.0.1",
25
+ "@push.rocks/smartjson": "^5.2.0",
26
+ "@push.rocks/smartrx": "^3.0.10",
27
+ "@push.rocks/smartsocket": "^3.0.0",
28
+ "@push.rocks/smartstring": "^4.1.0",
29
+ "@push.rocks/smarturl": "^3.1.0"
30
+ },
31
+ "peerDependencies": {
32
+ "@push.rocks/smartserve": ">=1.0.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@push.rocks/smartserve": {
36
+ "optional": true
37
+ }
29
38
  },
30
39
  "browserslist": [
31
40
  "last 1 chrome versions"
package/readme.hints.md CHANGED
@@ -1 +1,21 @@
1
-
1
+ # TypedSocket Hints
2
+
3
+ ## SmartServe Integration (Added v3.1.0)
4
+
5
+ TypedSocket now supports SmartServe as an alternative WebSocket backend via `TypedSocket.fromSmartServe()`.
6
+
7
+ ### Key Differences from Smartsocket Mode
8
+
9
+ 1. **Tag System**: SmartServe uses `Set<string>` for tags, while Smartsocket uses `{id, payload}`. The wrapper stores payloads in `peer.data` with `__typedsocket_tag__` prefix.
10
+
11
+ 2. **Request/Response**: Uses TypedRouter's `fireEventInterestMap` for async correlation when sending server-initiated requests.
12
+
13
+ 3. **Lifecycle**: SmartServe manages WebSocket lifecycle. `typedSocket.stop()` only clears internal state.
14
+
15
+ 4. **eventSubject**: Not fully supported in SmartServe mode - use SmartServe's `onConnectionOpen`/`onConnectionClose` hooks instead.
16
+
17
+ ### Files Modified for SmartServe Support
18
+
19
+ - `ts/typedsocket.classes.typedsocket.ts` - Main implementation
20
+ - `ts/typedsocket.plugins.ts` - Type imports
21
+ - `package.json` - Optional peer dependency
package/readme.md CHANGED
@@ -1,159 +1,297 @@
1
1
  # @api.global/typedsocket
2
- a typedrequest extension supporting websockets
2
+
3
+ A TypeScript library for creating typed WebSocket connections with bi-directional communication support. Extends `@api.global/typedrequest` to bring type-safe request/response patterns to WebSocket connections.
4
+
5
+ ## Issue Reporting and Security
6
+
7
+ For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
8
+
9
+ ## Features
10
+
11
+ - 🔒 **Full Type Safety** - Leverages TypeScript for compile-time checking of all request/response payloads
12
+ - 🔄 **Bi-directional Communication** - Both server and client can initiate requests
13
+ - 🔌 **Auto-reconnect** - Client automatically reconnects on connection loss
14
+ - 🏷️ **Connection Tagging** - Tag and filter connections for targeted messaging
15
+ - 🌐 **Browser Compatible** - Works in both Node.js and browser environments
16
+ - 🚀 **SmartServe Integration** - Native support for SmartServe's WebSocket handling
3
17
 
4
18
  ## Install
5
- To install `@api.global/typedsocket` in your project, run the following command using npm:
6
19
 
7
20
  ```bash
8
- npm install @api.global/typedsocket --save
21
+ npm install @api.global/typedsocket
9
22
  ```
10
23
 
11
- For Yarn users:
24
+ Or with pnpm:
12
25
 
13
26
  ```bash
14
- yarn add @api.global/typedsocket
27
+ pnpm add @api.global/typedsocket
15
28
  ```
16
29
 
17
30
  ## Usage
18
31
 
19
- To utilize `@api.global/typedsocket` effectively, let's explore how to integrate it into a project with TypeScript. This guide provides comprehensive usage scenarios, highlighting all features of the module. `@api.global/typedsocket` extends the capabilities of `typedrequest` by integrating websocket support, allowing for real-time, bidirectional communication between a client and server.
32
+ ### Prerequisites
20
33
 
21
- ### Getting Started
34
+ - TypeScript project setup
35
+ - Basic understanding of async/await patterns
36
+ - Familiarity with `@api.global/typedrequest` concepts
22
37
 
23
- #### Prerequisites
38
+ ### Define Your Request Interface
24
39
 
25
- Before diving into examples, ensure you have the following:
40
+ First, define the typed request interface that both client and server will use:
26
41
 
27
- - A basic understanding of TypeScript and Node.js.
28
- - An existing project set up with TypeScript.
29
- - `@api.global/typedrequest` and its dependencies installed in your project.
30
-
31
- #### Initialization
42
+ ```typescript
43
+ import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
32
44
 
33
- First, let's import the required modules and initialize our server and client instances.
45
+ interface IGreetingRequest extends typedrequestInterfaces.implementsTR<
46
+ typedrequestInterfaces.ITypedRequest,
47
+ IGreetingRequest
48
+ > {
49
+ method: 'greet';
50
+ request: {
51
+ name: string;
52
+ };
53
+ response: {
54
+ message: string;
55
+ };
56
+ }
57
+ ```
34
58
 
35
- **Server Side:**
59
+ ### Server Setup
36
60
 
37
- Within your server-side code, import and set up `TypedSocket` to create a websocket server.
61
+ Create a WebSocket server that handles typed requests:
38
62
 
39
63
  ```typescript
40
64
  import { TypedSocket } from '@api.global/typedsocket';
41
65
  import * as typedrequest from '@api.global/typedrequest';
42
66
 
43
- // Initialize your TypedRouter
67
+ // Create the router and add handlers
44
68
  const typedRouter = new typedrequest.TypedRouter();
45
69
 
46
- // Create the TypedSocket server
47
- const server = await TypedSocket.createServer(typedRouter);
70
+ typedRouter.addTypedHandler<IGreetingRequest>(
71
+ new typedrequest.TypedHandler('greet', async (requestData) => {
72
+ return {
73
+ message: `Hello, ${requestData.name}! 👋`,
74
+ };
75
+ })
76
+ );
48
77
 
49
- // Optionally, you can provide a smartexpressServerArg if you have an existing SmartExpress server
78
+ // Start the TypedSocket server (defaults to port 3000)
79
+ const server = await TypedSocket.createServer(typedRouter);
50
80
  ```
51
81
 
52
- **Client Side:**
82
+ #### Integration with SmartServe
53
83
 
54
- On the client side, initialize `TypedSocket` to connect to the websocket server.
84
+ For SmartServe-based applications, use `fromSmartServe()` for native integration:
55
85
 
56
86
  ```typescript
57
87
  import { TypedSocket } from '@api.global/typedsocket';
88
+ import { SmartServe } from '@push.rocks/smartserve';
89
+ import * as typedrequest from '@api.global/typedrequest';
58
90
 
59
- // Assuming server is at http://localhost:3000
60
- const client = await TypedSocket.createClient(typedRouter, 'http://localhost:3000');
61
- ```
91
+ const typedRouter = new typedrequest.TypedRouter();
62
92
 
63
- ### Defining Typed Requests
93
+ // Add handlers for client-to-server requests
94
+ typedRouter.addTypedHandler<IGreetingRequest>(
95
+ new typedrequest.TypedHandler('greet', async (requestData) => {
96
+ return { message: `Hello, ${requestData.name}!` };
97
+ })
98
+ );
64
99
 
65
- `@api.global/typedsocket` leverages `typedrequest` for type-safe requests and responses. Here's how you can define and handle typed requests:
100
+ // Create SmartServe with typedRouter in websocket options
101
+ const smartServe = new SmartServe({
102
+ port: 3000,
103
+ websocket: {
104
+ typedRouter,
105
+ onConnectionOpen: (peer) => {
106
+ // Tag connections for later filtering
107
+ peer.tags.add('client');
108
+ }
109
+ }
110
+ });
66
111
 
67
- **Defining a Typed Request Interface:**
112
+ await smartServe.start();
68
113
 
69
- Define an interface for the request and its corresponding response.
114
+ // Create TypedSocket bound to SmartServe
115
+ const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
70
116
 
71
- ```typescript
72
- interface ExampleRequest extends typedrequestInterfaces.ITypedRequest {
73
- method: 'exampleMethod';
74
- request: {
75
- message: string;
76
- };
77
- response: {
78
- reply: string;
79
- };
117
+ // Push notifications to tagged clients
118
+ const clients = await typedSocket.findAllTargetConnectionsByTag('client');
119
+ for (const client of clients) {
120
+ const request = typedSocket.createTypedRequest<INotifyRequest>('notify', client);
121
+ await request.fire({ message: 'Hello from server!' });
80
122
  }
81
123
  ```
82
124
 
83
- **Handling Requests on the Server:**
125
+ > **Note:** When using SmartServe, the WebSocket transport is managed by SmartServe. TypedSocket acts as a convenience layer for finding connections and sending server-initiated requests.
126
+
127
+ ### Client Setup
84
128
 
85
- Add a typed handler for the request in your `TypedRouter`.
129
+ Connect to the WebSocket server from a client:
86
130
 
87
131
  ```typescript
88
- typedRouter.addTypedHandler<ExampleRequest>(
89
- new typedrequest.TypedHandler('exampleMethod', async (requestData) => {
90
- return {
91
- reply: `Server received: ${requestData.message}`,
92
- };
93
- })
132
+ import { TypedSocket } from '@api.global/typedsocket';
133
+ import * as typedrequest from '@api.global/typedrequest';
134
+
135
+ // Create a router for handling server-initiated requests (if needed)
136
+ const clientRouter = new typedrequest.TypedRouter();
137
+
138
+ // Connect to the server
139
+ const client = await TypedSocket.createClient(
140
+ clientRouter,
141
+ 'http://localhost:3000'
94
142
  );
95
143
  ```
96
144
 
97
- ### Sending Requests from the Client
145
+ #### Using Window Location (Browser)
98
146
 
99
- Use the client instance to send a request to the server and await a response.
147
+ In browser environments, you can automatically use the current page's origin:
100
148
 
101
149
  ```typescript
102
- const exampleRequest = client.createTypedRequest<ExampleRequest>('exampleMethod');
103
- const response = await exampleRequest.fire({
104
- message: 'Hello from client!',
150
+ const client = await TypedSocket.createClient(
151
+ clientRouter,
152
+ TypedSocket.useWindowLocationOriginUrl()
153
+ );
154
+ ```
155
+
156
+ ### Sending Requests
157
+
158
+ #### Client to Server
159
+
160
+ ```typescript
161
+ const request = client.createTypedRequest<IGreetingRequest>('greet');
162
+ const response = await request.fire({
163
+ name: 'World',
105
164
  });
106
165
 
107
- console.log(response.reply); // "Server received: Hello from client!"
166
+ console.log(response.message); // "Hello, World! 👋"
108
167
  ```
109
168
 
110
- ### Advanced Usage
169
+ #### Server to Client
170
+
171
+ The server can also initiate requests to connected clients:
172
+
173
+ ```typescript
174
+ // When only one client is connected, it's automatically selected
175
+ const request = server.createTypedRequest<IGreetingRequest>('greet');
176
+ const response = await request.fire({
177
+ name: 'Client',
178
+ });
179
+
180
+ // For multiple clients, specify the target connection
181
+ const connection = await server.findTargetConnection(async (conn) => {
182
+ // Your filter logic here
183
+ return true;
184
+ });
185
+ const targetedRequest = server.createTypedRequest<IGreetingRequest>('greet', connection);
186
+ ```
111
187
 
112
- #### Tagging Connections
188
+ ### Connection Tagging
113
189
 
114
- For more refined control, especially in scenarios with multiple clients, you can tag connections for targeted communication.
190
+ Tag connections for organized, targeted communication:
115
191
 
116
192
  ```typescript
117
- // Add a tag to a client
118
- client.addTag('role', 'admin');
119
-
120
- // On the server, find connections with the tag
121
- const adminConnections = await server.findAllTargetConnectionsByTag('role', 'admin');
122
-
123
- // Send a message to all admin connections
124
- for (const adminConnection of adminConnections) {
125
- const request = server.createTypedRequest<ExampleRequest>('exampleMethod', adminConnection);
126
- await request.fire({
127
- message: 'Message to admins',
128
- });
193
+ // Client side: add a tag
194
+ interface IUserTag extends typedrequestInterfaces.ITag {
195
+ name: 'userRole';
196
+ payload: 'admin' | 'user' | 'guest';
129
197
  }
198
+
199
+ client.addTag<IUserTag>('userRole', 'admin');
130
200
  ```
131
201
 
132
- #### Handling Reconnections
202
+ ```typescript
203
+ // Server side: find connections by tag
204
+ const adminConnections = await server.findAllTargetConnectionsByTag<IUserTag>(
205
+ 'userRole',
206
+ 'admin'
207
+ );
133
208
 
134
- `TypedSocket` automatically attempts to reconnect in the event of connection loss. Ensure your server and client logic accounts for reconnection, especially for maintaining state or re-subscribing to necessary events.
209
+ // Send to all admins
210
+ for (const conn of adminConnections) {
211
+ const request = server.createTypedRequest<INotificationRequest>('notify', conn);
212
+ await request.fire({ message: 'Admin notification' });
213
+ }
135
214
 
136
- ### Conclusion
215
+ // Find a single connection
216
+ const firstAdmin = await server.findTargetConnectionByTag<IUserTag>('userRole', 'admin');
217
+ ```
137
218
 
138
- Implementing `@api.global/typedsocket` provides a type-safe, real-time communication layer for your TypeScript applications, extending the functionality of `typedrequest` into the realm of websockets. This guide covered initialization, defining typed requests, sending requests, and advanced usage patterns like tagging connections and handling reconnections.
219
+ ### Event Handling
139
220
 
140
- Integrating `@api.global/typedsocket` into your project harnesses the power of websockets with the benefits of type safety and structured request/response patterns, enabling more reliable and maintainable real-time applications.
221
+ Subscribe to connection status events:
222
+
223
+ ```typescript
224
+ client.eventSubject.subscribe((status) => {
225
+ console.log('Connection status:', status);
226
+ });
227
+
228
+ server.eventSubject.subscribe((status) => {
229
+ console.log('Server connection event:', status);
230
+ });
231
+ ```
232
+
233
+ ### Cleanup
234
+
235
+ Properly close connections when done:
236
+
237
+ ```typescript
238
+ // Client
239
+ await client.stop();
240
+
241
+ // Server
242
+ await server.stop();
243
+ ```
244
+
245
+ ## API Reference
246
+
247
+ ### TypedSocket
248
+
249
+ #### Static Methods
250
+
251
+ | Method | Description |
252
+ |--------|-------------|
253
+ | `createServer(router)` | Creates a WebSocket server (defaults to port 3000). |
254
+ | `createClient(router, serverUrl, alias?)` | Creates a WebSocket client that connects to the specified server URL. |
255
+ | `fromSmartServe(smartServe, router)` | Creates a TypedSocket bound to an existing SmartServe instance. |
256
+ | `useWindowLocationOriginUrl()` | Returns the current window location origin (browser only). |
257
+
258
+ #### Instance Properties
259
+
260
+ | Property | Description |
261
+ |----------|-------------|
262
+ | `side` | Whether this instance is a `'server'` or `'client'`. |
263
+ | `typedrouter` | The TypedRouter instance handling requests. |
264
+ | `eventSubject` | RxJS Subject for connection status events. |
265
+
266
+ #### Instance Methods
267
+
268
+ | Method | Description |
269
+ |--------|-------------|
270
+ | `createTypedRequest(method, targetConnection?)` | Creates a typed request for the specified method. |
271
+ | `addTag(name, payload)` | Adds a tag to the client connection (client-side only). |
272
+ | `findAllTargetConnections(filterFn)` | Finds all connections matching the filter (server-side only). |
273
+ | `findTargetConnection(filterFn)` | Finds the first connection matching the filter (server-side only). |
274
+ | `findAllTargetConnectionsByTag(key, payload?)` | Finds all connections with the specified tag. |
275
+ | `findTargetConnectionByTag(key, payload?)` | Finds the first connection with the specified tag. |
276
+ | `stop()` | Closes the WebSocket connection. |
141
277
 
142
278
  ## License and Legal Information
143
279
 
144
- This 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.
280
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
145
281
 
146
282
  **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.
147
283
 
148
284
  ### Trademarks
149
285
 
150
- This 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.
286
+ This 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 or third parties, and are not included within the scope of the MIT license granted herein.
287
+
288
+ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
151
289
 
152
290
  ### Company Information
153
291
 
154
- Task Venture Capital GmbH
155
- Registered at District court Bremen HRB 35230 HB, Germany
292
+ Task Venture Capital GmbH
293
+ Registered at District Court Bremen HRB 35230 HB, Germany
156
294
 
157
- For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
295
+ For any legal inquiries or further information, please contact us via email at hello@task.vc.
158
296
 
159
297
  By 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.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * autocreated commitinfo by @pushrocks/commitinfo
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@api.global/typedsocket',
6
- version: '3.0.1',
6
+ version: '4.0.0',
7
7
  description: 'A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.'
8
8
  }
@@ -5,6 +5,32 @@ const publicRolePass = 'publicRolePass';
5
5
 
6
6
  export type TTypedSocketSide = 'server' | 'client';
7
7
 
8
+ /**
9
+ * Wrapper for SmartServe's IWebSocketPeer to provide tag compatibility
10
+ * SmartServe uses Set<string> for tags, while TypedSocket uses {id, payload} format
11
+ */
12
+ export interface ISmartServeConnectionWrapper {
13
+ peer: plugins.IWebSocketPeer;
14
+ getTagById(tagId: string): Promise<{ id: string; payload: any } | undefined>;
15
+ }
16
+
17
+ /**
18
+ * Creates a wrapper around IWebSocketPeer for tag compatibility
19
+ */
20
+ function wrapSmartServePeer(peer: plugins.IWebSocketPeer): ISmartServeConnectionWrapper {
21
+ const TAG_PREFIX = '__typedsocket_tag__';
22
+ return {
23
+ peer,
24
+ async getTagById(tagId: string): Promise<{ id: string; payload: any } | undefined> {
25
+ if (!peer.tags.has(tagId)) {
26
+ return undefined;
27
+ }
28
+ const payload = peer.data.get(`${TAG_PREFIX}${tagId}`);
29
+ return { id: tagId, payload };
30
+ },
31
+ };
32
+ }
33
+
8
34
  export class TypedSocket {
9
35
  // STATIC
10
36
  /**
@@ -12,16 +38,12 @@ export class TypedSocket {
12
38
  * note: this will fail in browser environments as server libs are not bundled.
13
39
  */
14
40
  public static async createServer(
15
- typedrouterArg: plugins.typedrequest.TypedRouter,
16
- smartexpressServerArg?: any
41
+ typedrouterArg: plugins.typedrequest.TypedRouter
17
42
  ): Promise<TypedSocket> {
18
43
  const smartsocketServer = new plugins.smartsocket.Smartsocket({
19
44
  alias: 'typedsocketServer',
20
45
  port: 3000,
21
46
  });
22
- if (smartexpressServerArg) {
23
- smartsocketServer.setExternalServer('smartexpress', smartexpressServerArg);
24
- }
25
47
 
26
48
  smartsocketServer.socketFunctions.add(
27
49
  new plugins.smartsocket.SocketFunction({
@@ -110,16 +132,108 @@ export class TypedSocket {
110
132
  return windowLocationResult;
111
133
  }
112
134
 
135
+ /**
136
+ * Creates a TypedSocket server from an existing SmartServe instance.
137
+ * Use this when you want TypedSocket to work with SmartServe's WebSocket handling.
138
+ *
139
+ * @param smartServeArg - SmartServe instance with typedRouter configured in websocket options
140
+ * @param typedRouterArg - TypedRouter for handling requests (must match SmartServe's typedRouter)
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const typedRouter = new TypedRouter();
145
+ * const smartServe = new SmartServe({
146
+ * port: 3000,
147
+ * websocket: {
148
+ * typedRouter,
149
+ * onConnectionOpen: (peer) => peer.tags.add('client')
150
+ * }
151
+ * });
152
+ * await smartServe.start();
153
+ * const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
154
+ * ```
155
+ */
156
+ public static fromSmartServe(
157
+ smartServeArg: plugins.SmartServe,
158
+ typedRouterArg: plugins.typedrequest.TypedRouter
159
+ ): TypedSocket {
160
+ const connectionWrappers = new Map<string, ISmartServeConnectionWrapper>();
161
+
162
+ // Create the postMethod for server-initiated requests
163
+ const postMethod = async <T extends plugins.typedrequestInterfaces.ITypedRequest>(
164
+ dataArg: T,
165
+ targetConnectionArg?: ISmartServeConnectionWrapper
166
+ ): Promise<T> => {
167
+ if (!targetConnectionArg) {
168
+ const allConnections = smartServeArg.getWebSocketConnections();
169
+ if (allConnections.length === 1) {
170
+ console.log(
171
+ 'Since no targetConnection was supplied and there is only one active one present, choosing that one automatically'
172
+ );
173
+ const peer = allConnections[0];
174
+ let wrapper = connectionWrappers.get(peer.id);
175
+ if (!wrapper) {
176
+ wrapper = wrapSmartServePeer(peer);
177
+ connectionWrappers.set(peer.id, wrapper);
178
+ }
179
+ targetConnectionArg = wrapper;
180
+ } else if (allConnections.length === 0) {
181
+ throw new Error('No WebSocket connections available');
182
+ } else {
183
+ throw new Error(
184
+ 'you need to specify the wanted targetConnection. Currently no target is selectable automatically.'
185
+ );
186
+ }
187
+ }
188
+
189
+ // Register interest for the response using correlation ID
190
+ const interest = await typedRouterArg.fireEventInterestMap.addInterest(
191
+ dataArg.correlation.id,
192
+ dataArg
193
+ );
194
+
195
+ // Send the request to the client
196
+ targetConnectionArg.peer.send(plugins.smartjson.stringify(dataArg));
197
+
198
+ // Wait for the response (TypedRouter will fulfill via routeAndAddResponse when response arrives)
199
+ const response = await interest.interestFullfilled as T;
200
+ return response;
201
+ };
202
+
203
+ const typedSocket = new TypedSocket(
204
+ 'server',
205
+ typedRouterArg,
206
+ postMethod as any,
207
+ null as any // No smartsocket server/client when using SmartServe
208
+ );
209
+
210
+ typedSocket.smartServeRef = smartServeArg;
211
+ typedSocket.smartServeConnectionWrappers = connectionWrappers;
212
+
213
+ return typedSocket;
214
+ }
215
+
113
216
  // INSTANCE
114
217
  public side: TTypedSocketSide;
115
218
  public typedrouter: plugins.typedrequest.TypedRouter;
219
+
220
+ // SmartServe mode properties
221
+ private smartServeRef?: plugins.SmartServe;
222
+ private smartServeConnectionWrappers: Map<string, ISmartServeConnectionWrapper> = new Map();
223
+
116
224
  public get eventSubject(): plugins.smartrx.rxjs.Subject<plugins.smartsocket.TConnectionStatus> {
225
+ if (this.smartServeRef) {
226
+ // SmartServe doesn't provide an eventSubject, return a new Subject
227
+ // In SmartServe mode, connection events are handled via onConnectionOpen/onConnectionClose hooks
228
+ console.warn('eventSubject is not fully supported in SmartServe mode. Use SmartServe hooks instead.');
229
+ return new plugins.smartrx.rxjs.Subject();
230
+ }
117
231
  return this.socketServerOrClient.eventSubject;
118
232
  }
119
233
  private postMethod: plugins.typedrequest.IPostMethod &
120
234
  ((
121
235
  typedRequestPostObject: plugins.typedrequestInterfaces.ITypedRequest,
122
- socketConnectionArg?: plugins.smartsocket.SocketConnection
236
+ socketConnectionArg?: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper
123
237
  ) => Promise<plugins.typedrequestInterfaces.ITypedRequest>);
124
238
  private socketServerOrClient:
125
239
  | plugins.smartsocket.Smartsocket
@@ -155,12 +269,12 @@ export class TypedSocket {
155
269
 
156
270
  public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
157
271
  methodName: T['method'],
158
- targetConnection?: plugins.smartsocket.SocketConnection
272
+ targetConnection?: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper
159
273
  ): plugins.typedrequest.TypedRequest<T> {
160
274
  const typedrequest = new plugins.typedrequest.TypedRequest<T>(
161
275
  new plugins.typedrequest.TypedTarget({
162
276
  postMethod: async (requestDataArg) => {
163
- const result = await this.postMethod(requestDataArg, targetConnection);
277
+ const result = await this.postMethod(requestDataArg, targetConnection as any);
164
278
  return result;
165
279
  },
166
280
  }),
@@ -170,13 +284,31 @@ export class TypedSocket {
170
284
  }
171
285
 
172
286
  /**
173
- * returns all matching target connection
174
- * @param asyncFindFuncArg
175
- * @returns
287
+ * returns all matching target connections
288
+ * Works with both Smartsocket and SmartServe backends
289
+ * @param asyncFindFuncArg - async filter function
290
+ * @returns array of matching connections
176
291
  */
177
292
  public async findAllTargetConnections(
178
- asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
179
- ) {
293
+ asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>
294
+ ): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]> {
295
+ // SmartServe mode
296
+ if (this.smartServeRef) {
297
+ const matchingConnections: ISmartServeConnectionWrapper[] = [];
298
+ for (const peer of this.smartServeRef.getWebSocketConnections()) {
299
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
300
+ if (!wrapper) {
301
+ wrapper = wrapSmartServePeer(peer);
302
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
303
+ }
304
+ if (await asyncFindFuncArg(wrapper)) {
305
+ matchingConnections.push(wrapper);
306
+ }
307
+ }
308
+ return matchingConnections;
309
+ }
310
+
311
+ // Smartsocket mode
180
312
  if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) {
181
313
  const matchingSockets: plugins.smartsocket.SocketConnection[] = [];
182
314
  for (const socketConnection of this.socketServerOrClient.socketConnections.getArray()) {
@@ -185,9 +317,9 @@ export class TypedSocket {
185
317
  }
186
318
  }
187
319
  return matchingSockets;
188
- } else {
189
- throw new Error('this method >>findTargetConnection<< is only available from the server');
190
320
  }
321
+
322
+ throw new Error('this method >>findTargetConnection<< is only available from the server');
191
323
  }
192
324
 
193
325
  /**
@@ -196,22 +328,51 @@ export class TypedSocket {
196
328
  * @returns
197
329
  */
198
330
  public async findTargetConnection(
199
- asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
200
- ) {
331
+ asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper) => Promise<boolean>
332
+ ): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined> {
201
333
  const allMatching = await this.findAllTargetConnections(asyncFindFuncArg);
202
334
  return allMatching[0];
203
335
  }
204
336
 
337
+ /**
338
+ * Find all connections that have a specific tag
339
+ * Works with both Smartsocket and SmartServe backends
340
+ */
205
341
  public async findAllTargetConnectionsByTag<
206
342
  TTag extends plugins.typedrequestInterfaces.ITag = any
207
- >(keyArg: TTag['name'], payloadArg?: TTag['payload']) {
343
+ >(keyArg: TTag['name'], payloadArg?: TTag['payload']): Promise<(plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper)[]> {
344
+ // SmartServe mode - use native filtering for better performance
345
+ if (this.smartServeRef) {
346
+ const peers = this.smartServeRef.getWebSocketConnectionsByTag(keyArg);
347
+ const results: ISmartServeConnectionWrapper[] = [];
348
+
349
+ for (const peer of peers) {
350
+ let wrapper = this.smartServeConnectionWrappers.get(peer.id);
351
+ if (!wrapper) {
352
+ wrapper = wrapSmartServePeer(peer);
353
+ this.smartServeConnectionWrappers.set(peer.id, wrapper);
354
+ }
355
+
356
+ // If payload specified, also filter by payload stored in peer.data
357
+ if (payloadArg !== undefined) {
358
+ const tag = await wrapper.getTagById(keyArg);
359
+ if (plugins.smartjson.stringify(tag?.payload) !== plugins.smartjson.stringify(payloadArg)) {
360
+ continue;
361
+ }
362
+ }
363
+ results.push(wrapper);
364
+ }
365
+ return results;
366
+ }
367
+
368
+ // Smartsocket mode - use existing logic
208
369
  return this.findAllTargetConnections(async (socketConnectionArg) => {
209
370
  let result: boolean;
210
371
  if (!payloadArg) {
211
- result = !!(await socketConnectionArg.getTagById(keyArg));
372
+ result = !!(await (socketConnectionArg as plugins.smartsocket.SocketConnection).getTagById(keyArg));
212
373
  } else {
213
374
  result = !!(
214
- plugins.smartjson.stringify((await socketConnectionArg.getTagById(keyArg))?.payload) ===
375
+ plugins.smartjson.stringify((await (socketConnectionArg as plugins.smartsocket.SocketConnection).getTagById(keyArg))?.payload) ===
215
376
  plugins.smartjson.stringify(payloadArg)
216
377
  );
217
378
  }
@@ -219,15 +380,28 @@ export class TypedSocket {
219
380
  });
220
381
  }
221
382
 
383
+ /**
384
+ * Find a single connection by tag
385
+ */
222
386
  public async findTargetConnectionByTag<TTag extends plugins.typedrequestInterfaces.ITag = any>(
223
387
  keyArg: TTag['name'],
224
388
  payloadArg?: TTag['payload']
225
- ) {
389
+ ): Promise<plugins.smartsocket.SocketConnection | ISmartServeConnectionWrapper | undefined> {
226
390
  const allResults = await this.findAllTargetConnectionsByTag(keyArg, payloadArg);
227
391
  return allResults[0];
228
392
  }
229
393
 
394
+ /**
395
+ * Stop the TypedSocket server/client
396
+ * Note: In SmartServe mode, SmartServe manages its own lifecycle
397
+ */
230
398
  public async stop() {
399
+ if (this.smartServeRef) {
400
+ // SmartServe manages its own lifecycle
401
+ // Clear our connection wrappers
402
+ this.smartServeConnectionWrappers.clear();
403
+ return;
404
+ }
231
405
  await this.socketServerOrClient.stop();
232
406
  }
233
407
  }
@@ -13,3 +13,6 @@ import * as smartstring from '@push.rocks/smartstring';
13
13
  import * as smarturl from '@push.rocks/smarturl';
14
14
 
15
15
  export { isohash, smartjson, smartrx, smartsocket, smartstring, smarturl };
16
+
17
+ // Optional SmartServe support (type-only imports for optional peer dependency)
18
+ export type { SmartServe, IWebSocketPeer } from '@push.rocks/smartserve';