modality-kit 0.7.7 → 0.7.9
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 +40 -15
- package/dist/types/__tests__/jsonrpc-call.test.d.ts +11 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/schemas/jsonrpc.d.ts +46 -37
- package/dist/types/util_pending.d.ts +1 -0
- package/dist/types/util_tests/TimerMockManager.d.ts +22 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -181,7 +181,7 @@ class ModalityLogger {
|
|
|
181
181
|
}
|
|
182
182
|
break;
|
|
183
183
|
case "success":
|
|
184
|
-
console.
|
|
184
|
+
console.log(payload);
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
187
|
console.groupEnd();
|
|
@@ -4999,7 +4999,6 @@ __export(exports_jsonrpc, {
|
|
|
4999
4999
|
JSONRPCUtils: () => JSONRPCUtils,
|
|
5000
5000
|
JSONRPCErrorCode: () => JSONRPCErrorCode
|
|
5001
5001
|
});
|
|
5002
|
-
var getUUID = () => crypto.randomUUID();
|
|
5003
5002
|
var JSONRPC_VERSION = "2.0";
|
|
5004
5003
|
var JSONRPCErrorCode;
|
|
5005
5004
|
((JSONRPCErrorCode2) => {
|
|
@@ -5091,12 +5090,12 @@ class JSONRPCUtils {
|
|
|
5091
5090
|
messageType
|
|
5092
5091
|
};
|
|
5093
5092
|
}
|
|
5094
|
-
static createRequest(method, params,
|
|
5093
|
+
static createRequest(method, params, options = {}) {
|
|
5095
5094
|
return {
|
|
5096
5095
|
jsonrpc: JSONRPC_VERSION,
|
|
5097
5096
|
method,
|
|
5098
5097
|
params,
|
|
5099
|
-
id:
|
|
5098
|
+
id: options.customId ?? this.generateId()
|
|
5100
5099
|
};
|
|
5101
5100
|
}
|
|
5102
5101
|
static createNotification(method, params) {
|
|
@@ -5167,6 +5166,7 @@ var STANDARD_ERROR_MESSAGES = {
|
|
|
5167
5166
|
[-32005 /* RATE_LIMIT_ERROR */]: "Rate limit exceeded",
|
|
5168
5167
|
[-32006 /* VALIDATION_ERROR */]: "Validation error"
|
|
5169
5168
|
};
|
|
5169
|
+
var getUUID = () => crypto.randomUUID();
|
|
5170
5170
|
|
|
5171
5171
|
// src/util_pending.ts
|
|
5172
5172
|
class PendingOperationsBase {
|
|
@@ -5213,10 +5213,14 @@ class PendingOperationsBase {
|
|
|
5213
5213
|
clearTimeout(operation.timeoutHandle);
|
|
5214
5214
|
}
|
|
5215
5215
|
if (operation.type === "promise") {
|
|
5216
|
-
|
|
5216
|
+
try {
|
|
5217
|
+
operation.reject(reason);
|
|
5218
|
+
} catch (error) {}
|
|
5217
5219
|
}
|
|
5218
5220
|
if (this.eventHandlers.onReject) {
|
|
5219
|
-
|
|
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
|
|
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
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
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
|
-
|
|
5429
|
-
|
|
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 {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export { compressWithLanguageDetection as compressText } from "./util_text_compr
|
|
|
11
11
|
export { JSONRPCCall, createDataPendingOperations } from "./util_pending";
|
|
12
12
|
export type { DataPendingOperation, PendingOperation } from "./util_pending";
|
|
13
13
|
export * as JSONRPCTypes from "./schemas/jsonrpc";
|
|
14
|
-
export type { JSONRPCMessage, JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, JSONRPCBatchRequest, JSONRPCBatchResponse, JSONRPCErrorResponse, JSONRPCValidationResult, } from "./schemas/jsonrpc";
|
|
14
|
+
export type { JSONRPCMessage, JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, JSONRPCBatchRequest, JSONRPCBatchResponse, JSONRPCErrorResponse, JSONRPCValidationResult, CommandExecuteParams, JSONRPCError, JSONRPCParams, } from "./schemas/jsonrpc";
|
|
@@ -11,8 +11,49 @@
|
|
|
11
11
|
* Usage: type MyMethod = JSONRPCMethod<MyParams, MyResult>
|
|
12
12
|
* Or as object: { methodName: JSONRPCMethod<MyParams, MyResult> }
|
|
13
13
|
*/
|
|
14
|
-
export declare const getUUID: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
15
14
|
export type JSONRPCMethod<TParams = JSONRPCParams, TResult = any> = (method: string, params?: TParams, options?: any) => Promise<TResult>;
|
|
15
|
+
/**
|
|
16
|
+
* JSON-RPC 2.0 Request object
|
|
17
|
+
*/
|
|
18
|
+
export interface JSONRPCRequest {
|
|
19
|
+
/** JSON-RPC version identifier */
|
|
20
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
21
|
+
/** Method name to be invoked */
|
|
22
|
+
method: string;
|
|
23
|
+
/** Optional parameters for the method */
|
|
24
|
+
params?: JSONRPCParams;
|
|
25
|
+
/** Request identifier for correlation with response */
|
|
26
|
+
id: JSONRPCId;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* JSON-RPC 2.0 Success Response object
|
|
30
|
+
*/
|
|
31
|
+
export interface JSONRPCSuccessResponse {
|
|
32
|
+
/** JSON-RPC version identifier */
|
|
33
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
34
|
+
/** Method result */
|
|
35
|
+
result: any;
|
|
36
|
+
/** Request identifier matching the original request */
|
|
37
|
+
id: JSONRPCId;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* JSON-RPC 2.0 Error Response object
|
|
41
|
+
*/
|
|
42
|
+
export interface JSONRPCErrorResponse {
|
|
43
|
+
/** JSON-RPC version identifier */
|
|
44
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
45
|
+
/** Error information */
|
|
46
|
+
error: JSONRPCError;
|
|
47
|
+
/** Request identifier matching the original request */
|
|
48
|
+
id: JSONRPCId;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Standard method parameter interfaces
|
|
52
|
+
*/
|
|
53
|
+
export interface CommandExecuteParams {
|
|
54
|
+
command: string;
|
|
55
|
+
args?: any[];
|
|
56
|
+
}
|
|
16
57
|
/**
|
|
17
58
|
* JSON-RPC 2.0 version identifier
|
|
18
59
|
*/
|
|
@@ -69,19 +110,6 @@ export interface JSONRPCError {
|
|
|
69
110
|
/** Optional additional error data */
|
|
70
111
|
data?: any;
|
|
71
112
|
}
|
|
72
|
-
/**
|
|
73
|
-
* JSON-RPC 2.0 Request object
|
|
74
|
-
*/
|
|
75
|
-
export interface JSONRPCRequest {
|
|
76
|
-
/** JSON-RPC version identifier */
|
|
77
|
-
jsonrpc: typeof JSONRPC_VERSION;
|
|
78
|
-
/** Method name to be invoked */
|
|
79
|
-
method: string;
|
|
80
|
-
/** Optional parameters for the method */
|
|
81
|
-
params?: JSONRPCParams;
|
|
82
|
-
/** Request identifier for correlation with response */
|
|
83
|
-
id: JSONRPCId;
|
|
84
|
-
}
|
|
85
113
|
/**
|
|
86
114
|
* JSON-RPC 2.0 Notification object (request without id)
|
|
87
115
|
*/
|
|
@@ -93,28 +121,6 @@ export interface JSONRPCNotification {
|
|
|
93
121
|
/** Optional parameters for the method */
|
|
94
122
|
params?: JSONRPCParams;
|
|
95
123
|
}
|
|
96
|
-
/**
|
|
97
|
-
* JSON-RPC 2.0 Success Response object
|
|
98
|
-
*/
|
|
99
|
-
export interface JSONRPCSuccessResponse {
|
|
100
|
-
/** JSON-RPC version identifier */
|
|
101
|
-
jsonrpc: typeof JSONRPC_VERSION;
|
|
102
|
-
/** Method result */
|
|
103
|
-
result: any;
|
|
104
|
-
/** Request identifier matching the original request */
|
|
105
|
-
id: JSONRPCId;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* JSON-RPC 2.0 Error Response object
|
|
109
|
-
*/
|
|
110
|
-
export interface JSONRPCErrorResponse {
|
|
111
|
-
/** JSON-RPC version identifier */
|
|
112
|
-
jsonrpc: typeof JSONRPC_VERSION;
|
|
113
|
-
/** Error information */
|
|
114
|
-
error: JSONRPCError;
|
|
115
|
-
/** Request identifier matching the original request */
|
|
116
|
-
id: JSONRPCId;
|
|
117
|
-
}
|
|
118
124
|
/**
|
|
119
125
|
* Union type for JSON-RPC 2.0 Response objects
|
|
120
126
|
*/
|
|
@@ -158,7 +164,9 @@ export declare class JSONRPCUtils {
|
|
|
158
164
|
/**
|
|
159
165
|
* Create a JSON-RPC request
|
|
160
166
|
*/
|
|
161
|
-
static createRequest(method: string, params?: JSONRPCParams,
|
|
167
|
+
static createRequest(method: string, params?: JSONRPCParams, options?: {
|
|
168
|
+
customId?: JSONRPCId;
|
|
169
|
+
}): JSONRPCRequest;
|
|
162
170
|
/**
|
|
163
171
|
* Create a JSON-RPC notification
|
|
164
172
|
*/
|
|
@@ -212,3 +220,4 @@ export declare class JSONRPCUtils {
|
|
|
212
220
|
* Standard error messages for common JSON-RPC errors
|
|
213
221
|
*/
|
|
214
222
|
export declare const STANDARD_ERROR_MESSAGES: Record<JSONRPCErrorCode, string>;
|
|
223
|
+
export declare const getUUID: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
@@ -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