@peers-app/peers-sdk 0.14.0 → 0.15.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.
Files changed (210) hide show
  1. package/dist/context/data-context.d.ts +4 -4
  2. package/dist/context/data-context.js +1 -1
  3. package/dist/context/index.d.ts +3 -3
  4. package/dist/context/index.js +4 -0
  5. package/dist/context/user-context-singleton.js +13 -14
  6. package/dist/context/user-context.d.ts +4 -4
  7. package/dist/context/user-context.js +48 -31
  8. package/dist/data/assistants.d.ts +1 -1
  9. package/dist/data/assistants.js +35 -24
  10. package/dist/data/change-tracking.d.ts +8 -8
  11. package/dist/data/change-tracking.js +45 -39
  12. package/dist/data/channels.js +5 -5
  13. package/dist/data/data-locks.d.ts +2 -2
  14. package/dist/data/data-locks.js +21 -23
  15. package/dist/data/data-locks.test.js +73 -75
  16. package/dist/data/device-sync-info.d.ts +1 -1
  17. package/dist/data/device-sync-info.js +4 -4
  18. package/dist/data/devices.d.ts +1 -1
  19. package/dist/data/devices.js +9 -12
  20. package/dist/data/embeddings.js +14 -11
  21. package/dist/data/files/file-read-stream.d.ts +2 -2
  22. package/dist/data/files/file-read-stream.js +23 -14
  23. package/dist/data/files/file-write-stream.d.ts +2 -2
  24. package/dist/data/files/file-write-stream.js +8 -8
  25. package/dist/data/files/file.types.d.ts +2 -2
  26. package/dist/data/files/file.types.js +17 -11
  27. package/dist/data/files/files.d.ts +6 -6
  28. package/dist/data/files/files.js +17 -19
  29. package/dist/data/files/files.test.js +213 -214
  30. package/dist/data/files/index.d.ts +4 -4
  31. package/dist/data/files/index.js +4 -4
  32. package/dist/data/group-member-roles.js +2 -2
  33. package/dist/data/group-members.d.ts +5 -5
  34. package/dist/data/group-members.js +27 -18
  35. package/dist/data/group-members.test.js +73 -73
  36. package/dist/data/group-permissions.d.ts +3 -3
  37. package/dist/data/group-permissions.js +13 -11
  38. package/dist/data/group-share.d.ts +2 -2
  39. package/dist/data/group-share.js +29 -24
  40. package/dist/data/groups.d.ts +4 -4
  41. package/dist/data/groups.js +27 -19
  42. package/dist/data/groups.test.js +44 -44
  43. package/dist/data/index.d.ts +6 -6
  44. package/dist/data/index.js +6 -6
  45. package/dist/data/knowledge/peer-types.js +9 -9
  46. package/dist/data/messages.d.ts +5 -5
  47. package/dist/data/messages.js +43 -30
  48. package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
  49. package/dist/data/orm/client-proxy.data-source.js +10 -12
  50. package/dist/data/orm/cursor.d.ts +1 -1
  51. package/dist/data/orm/cursor.js +2 -2
  52. package/dist/data/orm/cursor.test.js +92 -93
  53. package/dist/data/orm/data-query.d.ts +3 -3
  54. package/dist/data/orm/data-query.js +24 -18
  55. package/dist/data/orm/data-query.mongo.d.ts +1 -1
  56. package/dist/data/orm/data-query.mongo.js +49 -51
  57. package/dist/data/orm/data-query.mongo.test.js +173 -204
  58. package/dist/data/orm/data-query.sqlite.d.ts +1 -1
  59. package/dist/data/orm/data-query.sqlite.js +84 -73
  60. package/dist/data/orm/data-query.sqlite.test.js +164 -176
  61. package/dist/data/orm/data-query.test.js +216 -224
  62. package/dist/data/orm/decorators.js +3 -3
  63. package/dist/data/orm/dependency-injection.test.js +53 -56
  64. package/dist/data/orm/doc.d.ts +4 -4
  65. package/dist/data/orm/doc.js +17 -21
  66. package/dist/data/orm/event-registry.d.ts +1 -1
  67. package/dist/data/orm/event-registry.test.js +16 -16
  68. package/dist/data/orm/factory.d.ts +2 -2
  69. package/dist/data/orm/factory.js +33 -33
  70. package/dist/data/orm/index.d.ts +10 -10
  71. package/dist/data/orm/index.js +10 -10
  72. package/dist/data/orm/multi-cursors.d.ts +1 -1
  73. package/dist/data/orm/multi-cursors.js +6 -6
  74. package/dist/data/orm/multi-cursors.test.js +152 -144
  75. package/dist/data/orm/sql.data-source.d.ts +7 -7
  76. package/dist/data/orm/sql.data-source.js +88 -93
  77. package/dist/data/orm/sql.data-source.test.js +109 -101
  78. package/dist/data/orm/subscribable.data-source.d.ts +4 -4
  79. package/dist/data/orm/subscribable.data-source.js +5 -5
  80. package/dist/data/orm/table-container-events.test.js +34 -26
  81. package/dist/data/orm/table-container.d.ts +6 -6
  82. package/dist/data/orm/table-container.js +33 -21
  83. package/dist/data/orm/table-container.test.js +64 -53
  84. package/dist/data/orm/table-definitions.system.d.ts +3 -3
  85. package/dist/data/orm/table-definitions.system.js +3 -3
  86. package/dist/data/orm/table-definitions.type.d.ts +5 -5
  87. package/dist/data/orm/table-dependencies.d.ts +2 -2
  88. package/dist/data/orm/table.d.ts +5 -5
  89. package/dist/data/orm/table.event-source.test.js +105 -115
  90. package/dist/data/orm/table.js +35 -34
  91. package/dist/data/orm/types.d.ts +3 -3
  92. package/dist/data/orm/types.js +26 -25
  93. package/dist/data/orm/types.test.js +166 -92
  94. package/dist/data/package-permissions.d.ts +1 -1
  95. package/dist/data/package-permissions.js +2 -2
  96. package/dist/data/package-version-permissions.d.ts +1 -1
  97. package/dist/data/package-version-permissions.js +2 -2
  98. package/dist/data/package-versions.d.ts +9 -9
  99. package/dist/data/package-versions.js +47 -33
  100. package/dist/data/packages.d.ts +2 -2
  101. package/dist/data/packages.js +36 -18
  102. package/dist/data/packages.utils.d.ts +2 -2
  103. package/dist/data/packages.utils.js +4 -4
  104. package/dist/data/persistent-vars.d.ts +15 -15
  105. package/dist/data/persistent-vars.js +165 -154
  106. package/dist/data/table-definitions-table.d.ts +5 -5
  107. package/dist/data/table-definitions-table.js +13 -12
  108. package/dist/data/tool-tests.js +6 -6
  109. package/dist/data/tools.js +29 -19
  110. package/dist/data/user-permissions.d.ts +1 -1
  111. package/dist/data/user-permissions.js +5 -5
  112. package/dist/data/user-permissions.test.js +90 -88
  113. package/dist/data/user-trust-levels.js +10 -10
  114. package/dist/data/users.d.ts +4 -4
  115. package/dist/data/users.js +16 -15
  116. package/dist/data/voice-messages.d.ts +2 -2
  117. package/dist/data/voice-messages.js +13 -13
  118. package/dist/data/welcome-modal.pvar.js +3 -1
  119. package/dist/data/workflow-logs.js +26 -18
  120. package/dist/data/workflow-runs.d.ts +6 -6
  121. package/dist/data/workflow-runs.js +70 -44
  122. package/dist/data/workflows.d.ts +2 -2
  123. package/dist/data/workflows.js +7 -9
  124. package/dist/device/binary-peer-connection-v2.d.ts +7 -7
  125. package/dist/device/binary-peer-connection-v2.js +32 -28
  126. package/dist/device/binary-peer-connection-v2.test.js +80 -67
  127. package/dist/device/binary-peer-connection.d.ts +7 -7
  128. package/dist/device/binary-peer-connection.js +29 -28
  129. package/dist/device/binary-peer-connection.test.js +35 -31
  130. package/dist/device/connection.d.ts +5 -5
  131. package/dist/device/connection.js +59 -48
  132. package/dist/device/connection.test.js +74 -68
  133. package/dist/device/device-election.d.ts +2 -2
  134. package/dist/device/device-election.js +25 -20
  135. package/dist/device/device-election.test.js +35 -36
  136. package/dist/device/device.d.ts +2 -2
  137. package/dist/device/device.js +10 -4
  138. package/dist/device/device.test.js +16 -17
  139. package/dist/device/get-trust-level-fn.d.ts +2 -2
  140. package/dist/device/get-trust-level-fn.js +22 -11
  141. package/dist/device/get-trust-level-fn.test.js +58 -58
  142. package/dist/device/socket-io-binary-peer.d.ts +1 -1
  143. package/dist/device/socket-io-binary-peer.js +16 -13
  144. package/dist/device/socket.type.d.ts +2 -2
  145. package/dist/device/streamed-socket.d.ts +2 -2
  146. package/dist/device/streamed-socket.js +8 -8
  147. package/dist/device/streamed-socket.test.js +40 -40
  148. package/dist/device/tx-encoding.test.js +77 -77
  149. package/dist/events.d.ts +1 -1
  150. package/dist/events.js +5 -2
  151. package/dist/group-invite/group-invite.js +110 -19
  152. package/dist/group-invite/group-invite.pvars.d.ts +2 -2
  153. package/dist/group-invite/group-invite.pvars.js +21 -13
  154. package/dist/group-invite/group-invite.types.d.ts +1 -1
  155. package/dist/group-invite/index.d.ts +3 -3
  156. package/dist/group-invite/index.js +1 -1
  157. package/dist/index.d.ts +25 -24
  158. package/dist/index.js +30 -25
  159. package/dist/keys.d.ts +3 -3
  160. package/dist/keys.js +31 -30
  161. package/dist/keys.test.js +69 -61
  162. package/dist/logging/console-logger.d.ts +1 -1
  163. package/dist/logging/console-logger.js +35 -40
  164. package/dist/logging/console-logger.test.js +115 -115
  165. package/dist/logging/console-logs.table.d.ts +3 -3
  166. package/dist/logging/console-logs.table.js +28 -23
  167. package/dist/mentions.js +16 -12
  168. package/dist/observable.d.ts +2 -2
  169. package/dist/observable.js +15 -9
  170. package/dist/observable.test.js +47 -47
  171. package/dist/package-loader/get-require.js +3 -4
  172. package/dist/package-loader/package-loader.d.ts +2 -2
  173. package/dist/package-loader/package-loader.js +52 -34
  174. package/dist/peers-ui/peers-ui.d.ts +2 -2
  175. package/dist/peers-ui/peers-ui.js +2 -4
  176. package/dist/peers-ui/peers-ui.types.d.ts +3 -3
  177. package/dist/peers-ui/peers-ui.types.js +0 -1
  178. package/dist/rpc-types.d.ts +61 -59
  179. package/dist/rpc-types.js +61 -55
  180. package/dist/serial-json.d.ts +1 -1
  181. package/dist/serial-json.js +50 -43
  182. package/dist/serial-json.test.js +22 -22
  183. package/dist/system-ids.js +8 -8
  184. package/dist/tools/index.d.ts +1 -1
  185. package/dist/tools/tools-factory.d.ts +1 -1
  186. package/dist/tools/tools-factory.js +2 -2
  187. package/dist/types/assistant-runner-args.d.ts +3 -3
  188. package/dist/types/peer-device.d.ts +1 -1
  189. package/dist/types/peers-package.d.ts +3 -3
  190. package/dist/types/workflow-logger.d.ts +1 -1
  191. package/dist/types/workflow-run-context.d.ts +4 -4
  192. package/dist/types/workflow.d.ts +4 -4
  193. package/dist/types/workflow.js +27 -14
  194. package/dist/types/zod-types.d.ts +2 -1
  195. package/dist/types/zod-types.js +9 -3
  196. package/dist/user-connect/connection-code.d.ts +1 -1
  197. package/dist/user-connect/connection-code.js +7 -7
  198. package/dist/user-connect/connection-code.test.js +106 -106
  199. package/dist/user-connect/index.d.ts +3 -3
  200. package/dist/user-connect/index.js +1 -1
  201. package/dist/user-connect/user-connect.pvars.js +13 -11
  202. package/dist/user-connect/user-connect.types.d.ts +3 -3
  203. package/dist/users.query.d.ts +2 -2
  204. package/dist/users.query.js +40 -30
  205. package/dist/utils.d.ts +2 -2
  206. package/dist/utils.js +34 -32
  207. package/dist/utils.test.js +12 -8
  208. package/dist/workflow-log-formatter.d.ts +1 -1
  209. package/dist/workflow-log-formatter.js +17 -18
  210. package/package.json +14 -8
@@ -11,7 +11,7 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.wrapSocketIOAsBinaryPeer = wrapSocketIOAsBinaryPeer;
13
13
  // Event name for binary data transfer
14
- const BINARY_EVENT = '_bin';
14
+ const BINARY_EVENT = "_bin";
15
15
  /**
16
16
  * Wraps a socket.io socket (client or server) as an IBinaryPeer.
17
17
  * This allows websocket connections to use the same binary protocol
@@ -26,40 +26,40 @@ function wrapSocketIOAsBinaryPeer(socket) {
26
26
  socket.on(BINARY_EVENT, (data) => {
27
27
  // Ensure we have a proper Uint8Array
28
28
  const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
29
- dataHandlers.forEach(handler => {
29
+ dataHandlers.forEach((handler) => {
30
30
  try {
31
31
  handler(bytes);
32
32
  }
33
33
  catch (err) {
34
- console.error('[socket-io-binary] Error in data handler:', err);
34
+ console.error("[socket-io-binary] Error in data handler:", err);
35
35
  }
36
36
  });
37
37
  });
38
38
  // Listen for disconnect
39
- socket.on('disconnect', () => {
40
- closeHandlers.forEach(handler => {
39
+ socket.on("disconnect", () => {
40
+ closeHandlers.forEach((handler) => {
41
41
  try {
42
42
  handler();
43
43
  }
44
44
  catch (err) {
45
- console.error('[socket-io-binary] Error in close handler:', err);
45
+ console.error("[socket-io-binary] Error in close handler:", err);
46
46
  }
47
47
  });
48
48
  });
49
49
  return {
50
50
  on(event, handler) {
51
- if (event === 'data') {
51
+ if (event === "data") {
52
52
  dataHandlers.push(handler);
53
53
  }
54
- else if (event === 'close') {
54
+ else if (event === "close") {
55
55
  closeHandlers.push(handler);
56
56
  }
57
- else if (event === 'drain') {
57
+ else if (event === "drain") {
58
58
  drainHandlers.push(handler);
59
59
  }
60
60
  },
61
61
  send(data) {
62
- const bytes = typeof data === 'string'
62
+ const bytes = typeof data === "string"
63
63
  ? Buffer.from(data)
64
64
  : data instanceof Uint8Array
65
65
  ? data
@@ -70,8 +70,11 @@ function wrapSocketIOAsBinaryPeer(socket) {
70
70
  // Simulate drain after send completes
71
71
  setImmediate(() => {
72
72
  pendingBytes = Math.max(0, pendingBytes - bytes.length);
73
- if (pendingBytes < 1024 * 1024) { // Under 1MB
74
- drainHandlers.forEach(h => h());
73
+ if (pendingBytes < 1024 * 1024) {
74
+ // Under 1MB
75
+ drainHandlers.forEach((h) => {
76
+ h();
77
+ });
75
78
  }
76
79
  });
77
80
  },
@@ -92,6 +95,6 @@ function wrapSocketIOAsBinaryPeer(socket) {
92
95
  }, 0);
93
96
  }
94
97
  return pendingBytes;
95
- }
98
+ },
96
99
  };
97
100
  }
@@ -16,7 +16,7 @@ export interface ISocketStats {
16
16
  }
17
17
  /** Creates a new stats object for tracking socket throughput */
18
18
  export declare function createSocketStats(): ISocketStats;
19
- export type TransportType = 'ws' | 'wrtc' | 'unknown';
19
+ export type TransportType = "ws" | "wrtc" | "unknown";
20
20
  export interface ISocket {
21
21
  id?: string;
22
22
  connected?: boolean;
@@ -36,7 +36,7 @@ export interface ISocket {
36
36
  */
37
37
  stats?: ISocketStats;
38
38
  emit(eventName: string, args: any, callback: RPCCallback): void;
39
- on(eventName: string, handler: ((...args: any[]) => void)): void;
39
+ on(eventName: string, handler: (...args: any[]) => void): void;
40
40
  removeAllListeners(eventName?: string): void;
41
41
  disconnect(close?: boolean): void;
42
42
  /**
@@ -1,4 +1,4 @@
1
- import { ISocket, ISocketStats, RPCCallback } from "./socket.type";
1
+ import { type ISocket, type ISocketStats, type RPCCallback } from "./socket.type";
2
2
  /** Creates a new stats object for tracking socket throughput */
3
3
  export declare function createSocketStats(): ISocketStats;
4
4
  export declare class StreamedSocket implements ISocket {
@@ -14,7 +14,7 @@ export declare class StreamedSocket implements ISocket {
14
14
  private readonly callbacks;
15
15
  emit(eventName: string, args: any, callback: RPCCallback): void;
16
16
  private handlers;
17
- on(eventName: string, handler: ((...args: any[]) => void)): void;
17
+ on(eventName: string, handler: (...args: any[]) => void): void;
18
18
  removeAllListeners(eventName: string): void;
19
19
  private readonly chunkBuffers;
20
20
  private handleChunk;
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StreamedSocket = void 0;
4
4
  exports.createSocketStats = createSocketStats;
5
+ const msgpack_1 = require("@msgpack/msgpack");
5
6
  const lodash_1 = require("lodash");
6
7
  const utils_1 = require("../utils");
7
8
  const socket_type_1 = require("./socket.type");
8
9
  const tx_encoding_1 = require("./tx-encoding");
9
- const msgpack_1 = require("@msgpack/msgpack");
10
10
  /** Creates a new stats object for tracking socket throughput */
11
11
  function createSocketStats() {
12
12
  const now = Date.now();
@@ -75,8 +75,8 @@ function decodeChunk(bytes) {
75
75
  class StreamedSocket {
76
76
  socket;
77
77
  maxChunkSize;
78
- safeSocketChunkEventName = '__streamed-socket-chunk';
79
- safeSocketResponseEventName = '__streamed-socket-response';
78
+ safeSocketChunkEventName = "__streamed-socket-chunk";
79
+ safeSocketResponseEventName = "__streamed-socket-response";
80
80
  stats = createSocketStats();
81
81
  constructor(socket, maxChunkSize = socket_type_1.DEFAULT_MAX_CHUNK_SIZE) {
82
82
  this.socket = socket;
@@ -112,7 +112,7 @@ class StreamedSocket {
112
112
  const chunks = [];
113
113
  // Reserve space for metadata overhead (typically ~50-100 bytes)
114
114
  const metadataOverhead = 128;
115
- if (this.maxChunkSize < (metadataOverhead * 2)) {
115
+ if (this.maxChunkSize < metadataOverhead * 2) {
116
116
  throw new Error(`maxChunkSize ${this.maxChunkSize} is too small to accommodate metadata overhead, must be greater than ${metadataOverhead * 2}`);
117
117
  }
118
118
  const effectiveChunkSize = this.maxChunkSize - metadataOverhead;
@@ -206,8 +206,8 @@ class StreamedSocket {
206
206
  if (!handler) {
207
207
  throw new Error(`No handler registered for event ${eventName}`);
208
208
  }
209
- let error = undefined;
210
- let result = undefined;
209
+ let error;
210
+ let result;
211
211
  try {
212
212
  await new Promise((resolve) => {
213
213
  handler(args, (...params) => {
@@ -222,11 +222,11 @@ class StreamedSocket {
222
222
  this.emit(this.safeSocketResponseEventName, {
223
223
  messageId: chunkZero.messageId,
224
224
  error,
225
- result
225
+ result,
226
226
  }, lodash_1.noop);
227
227
  }
228
228
  catch (error) {
229
- if (String(error).includes('No handler registered for event')) {
229
+ if (String(error).includes("No handler registered for event")) {
230
230
  console.warn(String(error));
231
231
  }
232
232
  else {
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const streamed_socket_1 = require("./streamed-socket");
3
+ const msgpack_1 = require("@msgpack/msgpack");
4
4
  const utils_1 = require("../utils");
5
+ const streamed_socket_1 = require("./streamed-socket");
5
6
  const tx_encoding_1 = require("./tx-encoding");
6
- const msgpack_1 = require("@msgpack/msgpack");
7
7
  // Helper to decode the binary chunk format
8
8
  function decodeChunk(bytes) {
9
9
  const view = new DataView(bytes.buffer, bytes.byteOffset);
@@ -20,10 +20,10 @@ function createMockSocket() {
20
20
  emit(eventName, args, callback) {
21
21
  emittedEvents.push({ eventName, args, callback });
22
22
  },
23
- on(eventName, handler) {
23
+ on(_eventName, _handler) {
24
24
  // Simple mock - we'll manually trigger events in tests
25
25
  },
26
- removeAllListeners(eventName) {
26
+ removeAllListeners(_eventName) {
27
27
  // Simple mock
28
28
  },
29
29
  disconnect() {
@@ -32,20 +32,20 @@ function createMockSocket() {
32
32
  };
33
33
  return {
34
34
  socket,
35
- getEmittedEvents: () => emittedEvents
35
+ getEmittedEvents: () => emittedEvents,
36
36
  };
37
37
  }
38
- describe('StreamedSocket', () => {
39
- it('should emit a single chunk for small messages', () => {
38
+ describe("StreamedSocket", () => {
39
+ it("should emit a single chunk for small messages", () => {
40
40
  const mock = createMockSocket();
41
41
  const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000); // Large chunk size
42
- const testData = { message: 'hello' };
43
- streamedSocket.emit('test-event', testData, () => { });
42
+ const testData = { message: "hello" };
43
+ streamedSocket.emit("test-event", testData, () => { });
44
44
  // Should emit a single chunk
45
45
  const emittedEvents = mock.getEmittedEvents();
46
46
  expect(emittedEvents).toHaveLength(1);
47
47
  const chunkEvent = emittedEvents[0];
48
- expect(chunkEvent.eventName).toBe('__streamed-socket-chunk');
48
+ expect(chunkEvent.eventName).toBe("__streamed-socket-chunk");
49
49
  // Args should be a Uint8Array (binary encoded chunk)
50
50
  expect(chunkEvent.args).toBeInstanceOf(Uint8Array);
51
51
  // Decode the binary chunk
@@ -53,36 +53,36 @@ describe('StreamedSocket', () => {
53
53
  expect(decodedChunk.messageId).toBeTruthy();
54
54
  expect(decodedChunk.chunkIndex).toBe(0);
55
55
  expect(decodedChunk.totalChunks).toBe(1);
56
- expect(decodedChunk.eventName).toBe('test-event');
56
+ expect(decodedChunk.eventName).toBe("test-event");
57
57
  // Decode the actual data
58
58
  const decoded = (0, tx_encoding_1.txDecode)(decodedChunk.data);
59
59
  expect(decoded).toEqual(testData);
60
60
  });
61
- it('should emit multiple chunks for large messages', () => {
61
+ it("should emit multiple chunks for large messages", () => {
62
62
  const mock = createMockSocket();
63
63
  const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 256); // Small chunk size to force chunking
64
64
  // Create a large test object
65
65
  const testData = {
66
- message: 'x'.repeat(200),
66
+ message: "x".repeat(200),
67
67
  array: [1, 2, 3, 4, 5],
68
- nested: { deep: 'value' }
68
+ nested: { deep: "value" },
69
69
  };
70
- streamedSocket.emit('test-event', testData, () => { });
70
+ streamedSocket.emit("test-event", testData, () => { });
71
71
  const emittedEvents = mock.getEmittedEvents();
72
72
  expect(emittedEvents.length).toBeGreaterThan(1);
73
73
  // Decode all chunks
74
- const decodedChunks = emittedEvents.map(event => {
74
+ const decodedChunks = emittedEvents.map((event) => {
75
75
  expect(event.args).toBeInstanceOf(Uint8Array);
76
76
  return decodeChunk(event.args);
77
77
  });
78
78
  // Verify first chunk has metadata
79
79
  const firstChunk = decodedChunks[0];
80
- expect(firstChunk.eventName).toBe('test-event');
80
+ expect(firstChunk.eventName).toBe("test-event");
81
81
  expect(firstChunk.totalChunks).toBe(emittedEvents.length);
82
82
  expect(firstChunk.chunkIndex).toBe(0);
83
83
  // Verify all chunks have the same messageId
84
84
  const messageId = firstChunk.messageId;
85
- decodedChunks.forEach(chunk => {
85
+ decodedChunks.forEach((chunk) => {
86
86
  expect(chunk.messageId).toBe(messageId);
87
87
  });
88
88
  // Verify chunks are in order
@@ -90,7 +90,7 @@ describe('StreamedSocket', () => {
90
90
  expect(chunk.chunkIndex).toBe(index);
91
91
  });
92
92
  // Verify all chunk data are Uint8Arrays
93
- decodedChunks.forEach(chunk => {
93
+ decodedChunks.forEach((chunk) => {
94
94
  expect(chunk.data).toBeInstanceOf(Uint8Array);
95
95
  });
96
96
  // Reassemble chunks and verify data integrity
@@ -103,14 +103,14 @@ describe('StreamedSocket', () => {
103
103
  const decoded = (0, tx_encoding_1.txDecode)(reassembled);
104
104
  expect(decoded).toEqual(testData);
105
105
  });
106
- it('should handle binary data in messages', () => {
106
+ it("should handle binary data in messages", () => {
107
107
  const mock = createMockSocket();
108
108
  const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000);
109
109
  const testData = {
110
110
  binaryData: new Uint8Array([1, 2, 3, 4, 5]),
111
- metadata: { name: 'test' }
111
+ metadata: { name: "test" },
112
112
  };
113
- streamedSocket.emit('test-event', testData, () => { });
113
+ streamedSocket.emit("test-event", testData, () => { });
114
114
  const emittedEvents = mock.getEmittedEvents();
115
115
  expect(emittedEvents).toHaveLength(1);
116
116
  const decodedChunk = decodeChunk(emittedEvents[0].args);
@@ -119,29 +119,29 @@ describe('StreamedSocket', () => {
119
119
  expect(decoded.binaryData).toEqual(testData.binaryData);
120
120
  expect(decoded.metadata).toEqual(testData.metadata);
121
121
  });
122
- it('should handle special types in messages', () => {
122
+ it("should handle special types in messages", () => {
123
123
  const mock = createMockSocket();
124
124
  const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000);
125
125
  const testData = {
126
- date: new Date('2023-01-01T00:00:00.000Z'),
126
+ date: new Date("2023-01-01T00:00:00.000Z"),
127
127
  nan: NaN,
128
128
  infinity: Infinity,
129
129
  undef: undefined,
130
- nullVal: null
130
+ nullVal: null,
131
131
  };
132
- streamedSocket.emit('test-event', testData, () => { });
132
+ streamedSocket.emit("test-event", testData, () => { });
133
133
  const emittedEvents = mock.getEmittedEvents();
134
134
  expect(emittedEvents).toHaveLength(1);
135
135
  const decodedChunk = decodeChunk(emittedEvents[0].args);
136
136
  const decoded = (0, tx_encoding_1.txDecode)(decodedChunk.data);
137
137
  expect(decoded.date).toBeInstanceOf(Date);
138
- expect(decoded.date.toISOString()).toBe('2023-01-01T00:00:00.000Z');
138
+ expect(decoded.date.toISOString()).toBe("2023-01-01T00:00:00.000Z");
139
139
  expect(Number.isNaN(decoded.nan)).toBe(true);
140
140
  expect(decoded.infinity).toBe(Infinity);
141
141
  expect(decoded.undef).toBeUndefined();
142
142
  expect(decoded.nullVal).toBeNull();
143
143
  });
144
- it('should demonstrate msgpack efficiency: structured data vs JSON string (uncompressed)', () => {
144
+ it("should demonstrate msgpack efficiency: structured data vs JSON string (uncompressed)", () => {
145
145
  const mock1 = createMockSocket();
146
146
  const mock2 = createMockSocket();
147
147
  const streamedSocket1 = new streamed_socket_1.StreamedSocket(mock1.socket, 1000000); // Large chunk to avoid splitting
@@ -154,15 +154,15 @@ describe('StreamedSocket', () => {
154
154
  email: `user${i}@example.com`,
155
155
  score: Math.random() * 1000,
156
156
  active: i % 2 === 0,
157
- }))
157
+ })),
158
158
  };
159
159
  // Convert to JSON string
160
160
  const jsonString = JSON.stringify(smallObject);
161
161
  console.log(`Original JSON string size: ${jsonString.length} bytes`);
162
162
  // Send as structured object (msgpack can optimize)
163
- streamedSocket1.emit('test-object', smallObject, () => { });
163
+ streamedSocket1.emit("test-object", smallObject, () => { });
164
164
  // Send as JSON string (msgpack treats it as opaque string)
165
- streamedSocket2.emit('test-string', { jsonPayload: jsonString }, () => { });
165
+ streamedSocket2.emit("test-string", { jsonPayload: jsonString }, () => { });
166
166
  const objectEvents = mock1.getEmittedEvents();
167
167
  const stringEvents = mock2.getEmittedEvents();
168
168
  expect(objectEvents).toHaveLength(1);
@@ -186,22 +186,22 @@ describe('StreamedSocket', () => {
186
186
  expect(decodedObject.users).toHaveLength(5);
187
187
  expect(decodedString.jsonPayload).toBe(jsonString);
188
188
  });
189
- it('should demonstrate compression effectiveness for large repetitive data', () => {
189
+ it("should demonstrate compression effectiveness for large repetitive data", () => {
190
190
  const mock = createMockSocket();
191
191
  const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000000);
192
192
  // Create large repetitive object that will compress well
193
193
  const largeObject = {
194
194
  data: Array.from({ length: 200 }, () => ({
195
- type: 'event',
196
- status: 'active',
197
- category: 'user_action',
198
- timestamp: new Date('2024-01-01'),
199
- metadata: { app: 'test', version: '1.0.0' }
200
- }))
195
+ type: "event",
196
+ status: "active",
197
+ category: "user_action",
198
+ timestamp: new Date("2024-01-01"),
199
+ metadata: { app: "test", version: "1.0.0" },
200
+ })),
201
201
  };
202
202
  const jsonString = JSON.stringify(largeObject);
203
203
  console.log(`Large repetitive data - JSON size: ${jsonString.length} bytes`);
204
- streamedSocket.emit('test-compressed', largeObject, () => { });
204
+ streamedSocket.emit("test-compressed", largeObject, () => { });
205
205
  const events = mock.getEmittedEvents();
206
206
  const chunk = decodeChunk(events[0].args);
207
207
  console.log(`After msgpack + compression: ${chunk.data.length} bytes`);
@@ -211,6 +211,6 @@ describe('StreamedSocket', () => {
211
211
  // Verify data integrity
212
212
  const decoded = (0, tx_encoding_1.txDecode)(chunk.data);
213
213
  expect(decoded.data).toHaveLength(200);
214
- expect(decoded.data[0].type).toBe('event');
214
+ expect(decoded.data[0].type).toBe("event");
215
215
  });
216
216
  });