modality-kit 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -181,7 +181,7 @@ class ModalityLogger {
181
181
  }
182
182
  break;
183
183
  case "success":
184
- console.error(payload);
184
+ console.log(payload);
185
185
  break;
186
186
  }
187
187
  console.groupEnd();
@@ -5091,12 +5091,12 @@ class JSONRPCUtils {
5091
5091
  messageType
5092
5092
  };
5093
5093
  }
5094
- static createRequest(method, params, id) {
5094
+ static createRequest(method, params, options = {}) {
5095
5095
  return {
5096
5096
  jsonrpc: JSONRPC_VERSION,
5097
5097
  method,
5098
5098
  params,
5099
- id: id ?? this.generateId()
5099
+ id: options.customId ?? this.generateId()
5100
5100
  };
5101
5101
  }
5102
5102
  static createNotification(method, params) {
@@ -5213,10 +5213,14 @@ class PendingOperationsBase {
5213
5213
  clearTimeout(operation.timeoutHandle);
5214
5214
  }
5215
5215
  if (operation.type === "promise") {
5216
- operation.reject(reason);
5216
+ try {
5217
+ operation.reject(reason);
5218
+ } catch (error) {}
5217
5219
  }
5218
5220
  if (this.eventHandlers.onReject) {
5219
- this.eventHandlers.onReject(operation, reason);
5221
+ try {
5222
+ this.eventHandlers.onReject(operation, reason);
5223
+ } catch (error) {}
5220
5224
  }
5221
5225
  this.operations.delete(id);
5222
5226
  return true;
@@ -5335,9 +5339,9 @@ class PendingOperationsBase {
5335
5339
  this.eventHandlers = { ...this.eventHandlers, ...handlers };
5336
5340
  }
5337
5341
  handleAdd(options = {}) {
5338
- const id = options.customId ?? this.config.generateId();
5342
+ const id = options.customId != null ? options.customId : this.config.generateId();
5339
5343
  const timeout = options.timeout ?? this.config.defaultTimeout;
5340
- if (options.customId && this.operations.has(options.customId)) {
5344
+ if (options.customId != null && this.operations.has(options.customId)) {
5341
5345
  throw new Error(`Operation with ID '${options.customId}' already exists`);
5342
5346
  }
5343
5347
  const timeoutHandle = timeout > 0 ? setTimeout(() => {
@@ -5363,6 +5367,7 @@ class PromisePendingOperations extends PendingOperationsBase {
5363
5367
  };
5364
5368
  this.operations.set(id, operation);
5365
5369
  });
5370
+ promise.catch(() => {});
5366
5371
  return { id, promise };
5367
5372
  }
5368
5373
  }
@@ -5401,32 +5406,51 @@ function createDataPendingOperations(config, eventHandlers) {
5401
5406
 
5402
5407
  class JSONRPCCall {
5403
5408
  pendingRequests;
5409
+ isDestroyed = false;
5404
5410
  constructor(config = {}) {
5405
5411
  const pendingEventHandlers = {
5406
5412
  onTimeout: (operation) => {
5413
+ if (this.isDestroyed)
5414
+ return;
5407
5415
  console.warn(`JSON-RPC operation timed out:`, operation.id);
5408
5416
  },
5409
5417
  onResolve: (operation, _result) => {
5418
+ if (this.isDestroyed)
5419
+ return;
5410
5420
  console.log(`JSON-RPC operation resolved:`, operation.id);
5411
5421
  },
5412
5422
  onReject: (operation, reason) => {
5423
+ if (this.isDestroyed)
5424
+ return;
5413
5425
  console.error(`JSON-RPC operation rejected:`, operation.id, reason);
5414
5426
  }
5415
5427
  };
5416
5428
  this.pendingRequests = createPromisePendingOperations(config, pendingEventHandlers);
5417
5429
  }
5418
5430
  handleResponse(response) {
5431
+ if (this.isDestroyed)
5432
+ return;
5419
5433
  const id = response.id;
5420
- if (JSONRPCUtils.isSuccessResponse(response)) {
5421
- this.pendingRequests.resolve(id, response.result);
5422
- } else {
5423
- this.pendingRequests.reject(id, new Error(response.error.message));
5434
+ try {
5435
+ if (JSONRPCUtils.isSuccessResponse(response)) {
5436
+ this.pendingRequests.resolve(id, response.result);
5437
+ } else {
5438
+ this.pendingRequests.reject(id, new Error(response.error.message));
5439
+ }
5440
+ } catch (error) {
5441
+ if (!this.isDestroyed) {
5442
+ throw error;
5443
+ }
5424
5444
  }
5425
5445
  }
5426
5446
  handleRequest(method, params, options = {}) {
5427
- const request = JSONRPCUtils.createRequest(method, params);
5428
- options.customId = request.id;
5429
- const { promise } = this.pendingRequests.add({ method, params }, options);
5447
+ const request = JSONRPCUtils.createRequest(method, params, {
5448
+ customId: options.customId
5449
+ });
5450
+ const { promise } = this.pendingRequests.add({ method, params }, {
5451
+ timeout: options.timeout,
5452
+ customId: request.id
5453
+ });
5430
5454
  return { promise, request };
5431
5455
  }
5432
5456
  getStats() {
@@ -5435,6 +5459,7 @@ class JSONRPCCall {
5435
5459
  };
5436
5460
  }
5437
5461
  destroy() {
5462
+ this.isDestroyed = true;
5438
5463
  this.pendingRequests.destroy("JSONRPCManager destroyed");
5439
5464
  }
5440
5465
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Unit Tests for JSONRPCCall Class
3
+ *
4
+ * Tests all functionality of the JSONRPCCall class including:
5
+ * - Request creation and handling
6
+ * - Response processing (success and error)
7
+ * - Promise-based operation management
8
+ * - Timeout handling
9
+ * - Statistics and cleanup
10
+ */
11
+ export {};
@@ -158,7 +158,9 @@ export declare class JSONRPCUtils {
158
158
  /**
159
159
  * Create a JSON-RPC request
160
160
  */
161
- static createRequest(method: string, params?: JSONRPCParams, id?: JSONRPCId): JSONRPCRequest;
161
+ static createRequest(method: string, params?: JSONRPCParams, options?: {
162
+ customId?: JSONRPCId;
163
+ }): JSONRPCRequest;
162
164
  /**
163
165
  * Create a JSON-RPC notification
164
166
  */
@@ -306,6 +306,7 @@ export declare function createPromisePendingOperations(config?: PendingOperation
306
306
  export declare function createDataPendingOperations(config?: PendingOperationsConfig, eventHandlers?: PendingOperationEventHandlers): DataPendingOperations;
307
307
  export declare class JSONRPCCall {
308
308
  private pendingRequests;
309
+ private isDestroyed;
309
310
  constructor(config?: PendingOperationsConfig);
310
311
  /**
311
312
  * Process a JSON-RPC response
@@ -31,9 +31,15 @@
31
31
  */
32
32
  export declare class TimerMockManager {
33
33
  private originalSetTimeout?;
34
+ private originalClearTimeout?;
34
35
  private originalMathRandom?;
35
36
  private mockSetTimeout?;
37
+ private mockClearTimeout?;
38
+ private activeTimers;
39
+ private timerIdCounter;
36
40
  private virtualClock;
41
+ private isDestroyed;
42
+ private suppressTimeouts;
37
43
  /**
38
44
  * Setup timer mocks
39
45
  * @param executeImmediately - Whether to execute callbacks immediately (default: true for fast tests)
@@ -56,6 +62,22 @@ export declare class TimerMockManager {
56
62
  * Get the mock setTimeout function for assertions
57
63
  */
58
64
  getMockSetTimeout(): any;
65
+ /**
66
+ * Clear all active timers
67
+ */
68
+ clearAllActiveTimers(): void;
69
+ /**
70
+ * Get the number of active timers
71
+ */
72
+ getActiveTimerCount(): number;
73
+ /**
74
+ * Suppress timeout execution temporarily
75
+ */
76
+ suppressTimeoutExecution(): void;
77
+ /**
78
+ * Resume timeout execution
79
+ */
80
+ resumeTimeoutExecution(): void;
59
81
  /**
60
82
  * Verify that setTimeout was called with expected parameters
61
83
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.7",
2
+ "version": "0.7.8",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",