electron-json-rpc 1.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +978 -0
  3. package/README.zh-CN.md +978 -0
  4. package/dist/debug.d.mts +92 -0
  5. package/dist/debug.d.mts.map +1 -0
  6. package/dist/debug.mjs +206 -0
  7. package/dist/debug.mjs.map +1 -0
  8. package/dist/error-xVRu7Lxq.mjs +131 -0
  9. package/dist/error-xVRu7Lxq.mjs.map +1 -0
  10. package/dist/event.d.mts +71 -0
  11. package/dist/event.d.mts.map +1 -0
  12. package/dist/event.mjs +60 -0
  13. package/dist/event.mjs.map +1 -0
  14. package/dist/index.d.mts +78 -0
  15. package/dist/index.d.mts.map +1 -0
  16. package/dist/index.mjs +4 -0
  17. package/dist/internal-BZK_0O3n.mjs +23 -0
  18. package/dist/internal-BZK_0O3n.mjs.map +1 -0
  19. package/dist/main.d.mts +151 -0
  20. package/dist/main.d.mts.map +1 -0
  21. package/dist/main.mjs +329 -0
  22. package/dist/main.mjs.map +1 -0
  23. package/dist/preload.d.mts +23 -0
  24. package/dist/preload.d.mts.map +1 -0
  25. package/dist/preload.mjs +417 -0
  26. package/dist/preload.mjs.map +1 -0
  27. package/dist/renderer/builder.d.mts +64 -0
  28. package/dist/renderer/builder.d.mts.map +1 -0
  29. package/dist/renderer/builder.mjs +101 -0
  30. package/dist/renderer/builder.mjs.map +1 -0
  31. package/dist/renderer/client.d.mts +42 -0
  32. package/dist/renderer/client.d.mts.map +1 -0
  33. package/dist/renderer/client.mjs +136 -0
  34. package/dist/renderer/client.mjs.map +1 -0
  35. package/dist/renderer/event.d.mts +17 -0
  36. package/dist/renderer/event.d.mts.map +1 -0
  37. package/dist/renderer/event.mjs +117 -0
  38. package/dist/renderer/event.mjs.map +1 -0
  39. package/dist/renderer/index.d.mts +6 -0
  40. package/dist/renderer/index.mjs +6 -0
  41. package/dist/stream.d.mts +38 -0
  42. package/dist/stream.d.mts.map +1 -0
  43. package/dist/stream.mjs +80 -0
  44. package/dist/stream.mjs.map +1 -0
  45. package/dist/types-BnGse9DF.d.mts +201 -0
  46. package/dist/types-BnGse9DF.d.mts.map +1 -0
  47. package/package.json +92 -0
@@ -0,0 +1,92 @@
1
+ import { h as RpcLogger } from "./types-BnGse9DF.mjs";
2
+
3
+ //#region src/debug.d.ts
4
+ /**
5
+ * Set global debug mode for all RPC clients
6
+ *
7
+ * @param enabled - Whether to enable debug logging
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { setRpcDebug } from 'electron-json-rpc/renderer';
12
+ *
13
+ * // Enable debug logging for all RPC clients
14
+ * setRpcDebug(true);
15
+ *
16
+ * // Disable debug logging
17
+ * setRpcDebug(false);
18
+ * ```
19
+ */
20
+ declare function setRpcDebug(enabled: boolean): void;
21
+ /**
22
+ * Check if global debug mode is enabled
23
+ *
24
+ * @returns True if debug mode is enabled
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { isRpcDebug } from 'electron-json-rpc/renderer';
29
+ *
30
+ * if (isRpcDebug()) {
31
+ * console.log('Debug logging is enabled');
32
+ * }
33
+ * ```
34
+ */
35
+ declare function isRpcDebug(): boolean;
36
+ /**
37
+ * Set a custom logger for RPC debug output
38
+ *
39
+ * @param logger - Logger function or null to reset to default
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { setRpcLogger } from 'electron-json-rpc/renderer';
44
+ *
45
+ * // Set custom logger
46
+ * setRpcLogger((entry) => {
47
+ * console.log(`[${entry.type.toUpperCase()}] ${entry.method}`, entry);
48
+ * });
49
+ *
50
+ * // Reset to default logger
51
+ * setRpcLogger(null);
52
+ * ```
53
+ */
54
+ declare function setRpcLogger(logger: RpcLogger | null): void;
55
+ /**
56
+ * Get the current logger (custom or default)
57
+ *
58
+ * @internal
59
+ */
60
+ declare function getLogger(): RpcLogger;
61
+ /**
62
+ * Check if debug is enabled (either globally or via option)
63
+ *
64
+ * @internal
65
+ */
66
+ declare function isDebugEnabled(debugOption?: boolean): boolean;
67
+ /**
68
+ * Format timestamp for debug output
69
+ *
70
+ * @internal
71
+ */
72
+ declare function formatTimestamp(timestamp: number): string;
73
+ /**
74
+ * Debug tracker interface
75
+ */
76
+ interface DebugTracker {
77
+ onRequest: (method: string, params: unknown[], requestId: number) => void;
78
+ onResponse: (method: string, params: unknown[], result: unknown, duration: number, requestId: number) => void;
79
+ onError: (method: string, params: unknown[], error: string, duration: number, requestId: number) => void;
80
+ onNotify: (method: string, params: unknown[]) => void;
81
+ onStream: (method: string, params: unknown[]) => void;
82
+ onEvent: (eventName: string, data: unknown) => void;
83
+ }
84
+ /**
85
+ * Create a debug wrapper for tracking RPC calls
86
+ *
87
+ * @internal
88
+ */
89
+ declare function createDebugTracker(enabled: boolean, logger: RpcLogger): DebugTracker;
90
+ //#endregion
91
+ export { DebugTracker, createDebugTracker, formatTimestamp, getLogger, isDebugEnabled, isRpcDebug, setRpcDebug, setRpcLogger };
92
+ //# sourceMappingURL=debug.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.mts","names":[],"sources":["../src/debug.ts"],"mappings":";;;;AA4BA;AAkBA;AAsBA;AASA;AASA;AASA;AAqFA;AA0BA;;;;;;;;iBAlLgB,WAAA,CAAA,OAAA;AAAA;AAkBhB;AAsBA;AASA;AASA;AASA;AAqFA;AA0BA;;;;;;;AAlLgB,iBAkBA,UAAA,CAAA;AAAA;AAsBhB;AASA;AASA;AASA;AAqFA;AA0BA;;;;;;;;;;;;AAhKgB,iBAsBA,YAAA,CAAA,MAAA,EAAqB,SAAA;AAAA;AASrC;AASA;AASA;AAqFA;AAhHqC,iBASrB,SAAA,CAAA,GAAa,SAAA;AAAA;AAS7B;AASA;AAqFA;AA0BA;AAjI6B,iBASb,cAAA,CAAA,WAAA;AAAA;AAShB;AAqFA;AA0BA;;AAxHgB,iBASA,eAAA,CAAA,SAAA;AAAA;AAqFhB;AA0BA;AA/GgB,UAqFC,YAAA;EAAA,SAAA,GAAA,MAAA,UAAA,MAAA,aAAA,SAAA;EAAA,UAAA,GAAA,MAAA,UAAA,MAAA,aAAA,MAAA,WAAA,QAAA,UAAA,SAAA;EAAA,OAAA,GAAA,MAAA,UAAA,MAAA,aAAA,KAAA,UAAA,QAAA,UAAA,SAAA;EAAA,QAAA,GAAA,MAAA,UAAA,MAAA;EAAA,QAAA,GAAA,MAAA,UAAA,MAAA;EAAA,OAAA,GAAA,SAAA,UAAA,IAAA;AAAA;AAAA;AA0BjB;;;;AA1BiB,iBA0BD,kBAAA,CAAA,OAAA,WAAA,MAAA,EAA6C,SAAA,GAAY,YAAA"}
package/dist/debug.mjs ADDED
@@ -0,0 +1,206 @@
1
+ //#region src/debug.ts
2
+ /**
3
+ * Global debug state
4
+ */
5
+ let globalDebugEnabled = false;
6
+ let customLogger = null;
7
+ /**
8
+ * Set global debug mode for all RPC clients
9
+ *
10
+ * @param enabled - Whether to enable debug logging
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { setRpcDebug } from 'electron-json-rpc/renderer';
15
+ *
16
+ * // Enable debug logging for all RPC clients
17
+ * setRpcDebug(true);
18
+ *
19
+ * // Disable debug logging
20
+ * setRpcDebug(false);
21
+ * ```
22
+ */
23
+ function setRpcDebug(enabled) {
24
+ globalDebugEnabled = enabled;
25
+ }
26
+ /**
27
+ * Check if global debug mode is enabled
28
+ *
29
+ * @returns True if debug mode is enabled
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { isRpcDebug } from 'electron-json-rpc/renderer';
34
+ *
35
+ * if (isRpcDebug()) {
36
+ * console.log('Debug logging is enabled');
37
+ * }
38
+ * ```
39
+ */
40
+ function isRpcDebug() {
41
+ return globalDebugEnabled;
42
+ }
43
+ /**
44
+ * Set a custom logger for RPC debug output
45
+ *
46
+ * @param logger - Logger function or null to reset to default
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { setRpcLogger } from 'electron-json-rpc/renderer';
51
+ *
52
+ * // Set custom logger
53
+ * setRpcLogger((entry) => {
54
+ * console.log(`[${entry.type.toUpperCase()}] ${entry.method}`, entry);
55
+ * });
56
+ *
57
+ * // Reset to default logger
58
+ * setRpcLogger(null);
59
+ * ```
60
+ */
61
+ function setRpcLogger(logger) {
62
+ customLogger = logger;
63
+ }
64
+ /**
65
+ * Get the current logger (custom or default)
66
+ *
67
+ * @internal
68
+ */
69
+ function getLogger() {
70
+ return customLogger ?? defaultLogger;
71
+ }
72
+ /**
73
+ * Check if debug is enabled (either globally or via option)
74
+ *
75
+ * @internal
76
+ */
77
+ function isDebugEnabled(debugOption) {
78
+ return globalDebugEnabled || debugOption === true;
79
+ }
80
+ /**
81
+ * Format timestamp for debug output
82
+ *
83
+ * @internal
84
+ */
85
+ function formatTimestamp(timestamp) {
86
+ return new Date(timestamp).toLocaleTimeString("en-US", {
87
+ hour12: false,
88
+ hour: "2-digit",
89
+ minute: "2-digit",
90
+ second: "2-digit",
91
+ fractionalSecondDigits: 3
92
+ });
93
+ }
94
+ /**
95
+ * ANSI color codes for terminal output
96
+ *
97
+ * @internal
98
+ */
99
+ const colors = {
100
+ reset: "\x1B[0m",
101
+ cyan: "\x1B[36m",
102
+ green: "\x1B[32m",
103
+ yellow: "\x1B[33m",
104
+ red: "\x1B[31m",
105
+ gray: "\x1B[90m",
106
+ dim: "\x1B[2m"
107
+ };
108
+ /**
109
+ * Default logger implementation with formatted console output
110
+ *
111
+ * @internal
112
+ */
113
+ const defaultLogger = (entry) => {
114
+ const timeStr = formatTimestamp(entry.timestamp);
115
+ const arrow = entry.type === "request" || entry.type === "notify" || entry.type === "event" ? "→" : entry.type === "stream" ? "↦" : "←";
116
+ let typeColor = colors.cyan;
117
+ if (entry.type === "error") typeColor = colors.red;
118
+ else if (entry.type === "response") typeColor = colors.green;
119
+ else if (entry.type === "stream") typeColor = colors.yellow;
120
+ else if (entry.type === "event") typeColor = colors.cyan;
121
+ else if (entry.type === "notify") typeColor = colors.gray;
122
+ let durationSuffix = "";
123
+ if (entry.duration !== void 0) durationSuffix = ` ${entry.duration > 1e3 ? colors.yellow : colors.dim}(${entry.duration}ms)${colors.reset}`;
124
+ let idSuffix = "";
125
+ if (entry.requestId !== void 0) idSuffix = `${colors.dim} [#${entry.requestId}]${colors.reset}`;
126
+ console.log(`${typeColor}[RPC]${colors.reset} ${colors.dim}${timeStr}${colors.reset} ${arrow} ${entry.type} ${entry.method}${idSuffix}${durationSuffix}`);
127
+ if (entry.params !== void 0 && entry.params.length > 0) console.log(`${colors.dim} params:${colors.reset}`, entry.params);
128
+ if (entry.result !== void 0) console.log(`${colors.dim} result:${colors.reset}`, entry.result);
129
+ if (entry.error) console.log(`${colors.red} error:${colors.reset}`, entry.error);
130
+ };
131
+ /**
132
+ * Create a debug wrapper for tracking RPC calls
133
+ *
134
+ * @internal
135
+ */
136
+ function createDebugTracker(enabled, logger) {
137
+ if (!enabled) return {
138
+ onRequest: () => {},
139
+ onResponse: () => {},
140
+ onError: () => {},
141
+ onNotify: () => {},
142
+ onStream: () => {},
143
+ onEvent: () => {}
144
+ };
145
+ return {
146
+ onRequest: (method, params, requestId) => {
147
+ logger({
148
+ type: "request",
149
+ method,
150
+ params,
151
+ timestamp: Date.now(),
152
+ requestId
153
+ });
154
+ },
155
+ onResponse: (method, params, result, duration, requestId) => {
156
+ logger({
157
+ type: "response",
158
+ method,
159
+ params,
160
+ result,
161
+ timestamp: Date.now(),
162
+ duration,
163
+ requestId
164
+ });
165
+ },
166
+ onError: (method, params, error, duration, requestId) => {
167
+ logger({
168
+ type: "error",
169
+ method,
170
+ params,
171
+ error,
172
+ timestamp: Date.now(),
173
+ duration,
174
+ requestId
175
+ });
176
+ },
177
+ onNotify: (method, params) => {
178
+ logger({
179
+ type: "notify",
180
+ method,
181
+ params,
182
+ timestamp: Date.now()
183
+ });
184
+ },
185
+ onStream: (method, params) => {
186
+ logger({
187
+ type: "stream",
188
+ method,
189
+ params,
190
+ timestamp: Date.now()
191
+ });
192
+ },
193
+ onEvent: (eventName, data) => {
194
+ logger({
195
+ type: "event",
196
+ method: eventName,
197
+ params: data !== void 0 ? [data] : void 0,
198
+ timestamp: Date.now()
199
+ });
200
+ }
201
+ };
202
+ }
203
+
204
+ //#endregion
205
+ export { createDebugTracker, formatTimestamp, getLogger, isDebugEnabled, isRpcDebug, setRpcDebug, setRpcLogger };
206
+ //# sourceMappingURL=debug.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.mjs","names":[],"sources":["../src/debug.ts"],"sourcesContent":["/**\n * Debug logging utilities for JSON-RPC clients\n */\n\nimport type { RpcLogEntry, RpcLogger } from \"./types.js\";\n\n/**\n * Global debug state\n */\nlet globalDebugEnabled = false;\nlet customLogger: RpcLogger | null = null;\n\n/**\n * Set global debug mode for all RPC clients\n *\n * @param enabled - Whether to enable debug logging\n *\n * @example\n * ```typescript\n * import { setRpcDebug } from 'electron-json-rpc/renderer';\n *\n * // Enable debug logging for all RPC clients\n * setRpcDebug(true);\n *\n * // Disable debug logging\n * setRpcDebug(false);\n * ```\n */\nexport function setRpcDebug(enabled: boolean): void {\n globalDebugEnabled = enabled;\n}\n\n/**\n * Check if global debug mode is enabled\n *\n * @returns True if debug mode is enabled\n *\n * @example\n * ```typescript\n * import { isRpcDebug } from 'electron-json-rpc/renderer';\n *\n * if (isRpcDebug()) {\n * console.log('Debug logging is enabled');\n * }\n * ```\n */\nexport function isRpcDebug(): boolean {\n return globalDebugEnabled;\n}\n\n/**\n * Set a custom logger for RPC debug output\n *\n * @param logger - Logger function or null to reset to default\n *\n * @example\n * ```typescript\n * import { setRpcLogger } from 'electron-json-rpc/renderer';\n *\n * // Set custom logger\n * setRpcLogger((entry) => {\n * console.log(`[${entry.type.toUpperCase()}] ${entry.method}`, entry);\n * });\n *\n * // Reset to default logger\n * setRpcLogger(null);\n * ```\n */\nexport function setRpcLogger(logger: RpcLogger | null): void {\n customLogger = logger;\n}\n\n/**\n * Get the current logger (custom or default)\n *\n * @internal\n */\nexport function getLogger(): RpcLogger {\n return customLogger ?? defaultLogger;\n}\n\n/**\n * Check if debug is enabled (either globally or via option)\n *\n * @internal\n */\nexport function isDebugEnabled(debugOption?: boolean): boolean {\n return globalDebugEnabled || debugOption === true;\n}\n\n/**\n * Format timestamp for debug output\n *\n * @internal\n */\nexport function formatTimestamp(timestamp: number): string {\n const time = new Date(timestamp);\n return time.toLocaleTimeString(\"en-US\", {\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n fractionalSecondDigits: 3,\n });\n}\n\n/**\n * ANSI color codes for terminal output\n *\n * @internal\n */\nconst colors = {\n reset: \"\\x1b[0m\",\n cyan: \"\\x1b[36m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n red: \"\\x1b[31m\",\n gray: \"\\x1b[90m\",\n dim: \"\\x1b[2m\",\n};\n\n/**\n * Default logger implementation with formatted console output\n *\n * @internal\n */\nconst defaultLogger: RpcLogger = (entry: RpcLogEntry) => {\n const timeStr = formatTimestamp(entry.timestamp);\n const arrow =\n entry.type === \"request\" || entry.type === \"notify\" || entry.type === \"event\"\n ? \"→\"\n : entry.type === \"stream\"\n ? \"↦\"\n : \"←\";\n\n // Select color based on entry type\n let typeColor = colors.cyan;\n if (entry.type === \"error\") typeColor = colors.red;\n else if (entry.type === \"response\") typeColor = colors.green;\n else if (entry.type === \"stream\") typeColor = colors.yellow;\n else if (entry.type === \"event\") typeColor = colors.cyan;\n else if (entry.type === \"notify\") typeColor = colors.gray;\n\n // Build duration suffix\n let durationSuffix = \"\";\n if (entry.duration !== undefined) {\n const durationColor = entry.duration > 1000 ? colors.yellow : colors.dim;\n durationSuffix = ` ${durationColor}(${entry.duration}ms)${colors.reset}`;\n }\n\n // Build request ID suffix\n let idSuffix = \"\";\n if (entry.requestId !== undefined) {\n idSuffix = `${colors.dim} [#${entry.requestId}]${colors.reset}`;\n }\n\n // Main log line\n console.log(\n `${typeColor}[RPC]${colors.reset} ${colors.dim}${timeStr}${colors.reset} ${arrow} ${entry.type} ${entry.method}${idSuffix}${durationSuffix}`,\n );\n\n // Log params\n if (entry.params !== undefined && entry.params.length > 0) {\n console.log(`${colors.dim} params:${colors.reset}`, entry.params);\n }\n\n // Log result\n if (entry.result !== undefined) {\n console.log(`${colors.dim} result:${colors.reset}`, entry.result);\n }\n\n // Log error\n if (entry.error) {\n console.log(`${colors.red} error:${colors.reset}`, entry.error);\n }\n};\n\n/**\n * Debug tracker interface\n */\nexport interface DebugTracker {\n onRequest: (method: string, params: unknown[], requestId: number) => void;\n onResponse: (\n method: string,\n params: unknown[],\n result: unknown,\n duration: number,\n requestId: number,\n ) => void;\n onError: (\n method: string,\n params: unknown[],\n error: string,\n duration: number,\n requestId: number,\n ) => void;\n onNotify: (method: string, params: unknown[]) => void;\n onStream: (method: string, params: unknown[]) => void;\n onEvent: (eventName: string, data: unknown) => void;\n}\n\n/**\n * Create a debug wrapper for tracking RPC calls\n *\n * @internal\n */\nexport function createDebugTracker(enabled: boolean, logger: RpcLogger): DebugTracker {\n if (!enabled) {\n return {\n onRequest: () => {},\n onResponse: () => {},\n onError: () => {},\n onNotify: () => {},\n onStream: () => {},\n onEvent: () => {},\n };\n }\n\n return {\n onRequest: (method, params, requestId) => {\n logger({\n type: \"request\",\n method,\n params,\n timestamp: Date.now(),\n requestId,\n });\n },\n onResponse: (method, params, result, duration, requestId) => {\n logger({\n type: \"response\",\n method,\n params,\n result,\n timestamp: Date.now(),\n duration,\n requestId,\n });\n },\n onError: (method, params, error, duration, requestId) => {\n logger({\n type: \"error\",\n method,\n params,\n error,\n timestamp: Date.now(),\n duration,\n requestId,\n });\n },\n onNotify: (method, params) => {\n logger({\n type: \"notify\",\n method,\n params,\n timestamp: Date.now(),\n });\n },\n onStream: (method, params) => {\n logger({\n type: \"stream\",\n method,\n params,\n timestamp: Date.now(),\n });\n },\n onEvent: (eventName, data) => {\n logger({\n type: \"event\",\n method: eventName,\n params: data !== undefined ? [data] : undefined,\n timestamp: Date.now(),\n });\n },\n };\n}\n"],"mappings":"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"}
@@ -0,0 +1,131 @@
1
+ //#region src/types.ts
2
+ /**
3
+ * JSON-RPC 2.0 Error codes
4
+ */
5
+ let JsonRpcErrorCode = /* @__PURE__ */ function(JsonRpcErrorCode) {
6
+ JsonRpcErrorCode[JsonRpcErrorCode["ParseError"] = -32700] = "ParseError";
7
+ JsonRpcErrorCode[JsonRpcErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
8
+ JsonRpcErrorCode[JsonRpcErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
9
+ JsonRpcErrorCode[JsonRpcErrorCode["InvalidParams"] = -32602] = "InvalidParams";
10
+ JsonRpcErrorCode[JsonRpcErrorCode["InternalError"] = -32603] = "InternalError";
11
+ return JsonRpcErrorCode;
12
+ }({});
13
+
14
+ //#endregion
15
+ //#region src/error.ts
16
+ /**
17
+ * Create a JSON-RPC error object
18
+ */
19
+ function createJsonRpcError(code, message, data) {
20
+ return {
21
+ code,
22
+ message,
23
+ data
24
+ };
25
+ }
26
+ /**
27
+ * Predefined error creators
28
+ */
29
+ const errors = {
30
+ parseError: (data) => createJsonRpcError(JsonRpcErrorCode.ParseError, "Parse error", data),
31
+ invalidRequest: (data) => createJsonRpcError(JsonRpcErrorCode.InvalidRequest, "Invalid Request", data),
32
+ methodNotFound: (method) => createJsonRpcError(JsonRpcErrorCode.MethodNotFound, `Method not found${method ? `: ${method}` : ""}`),
33
+ invalidParams: (data) => createJsonRpcError(JsonRpcErrorCode.InvalidParams, "Invalid params", data),
34
+ internalError: (data) => createJsonRpcError(JsonRpcErrorCode.InternalError, "Internal error", data)
35
+ };
36
+ /**
37
+ * Check if an error is a JSON-RPC error
38
+ */
39
+ function isJsonRpcError(error) {
40
+ return typeof error === "object" && error !== null && "code" in error && typeof error.code === "number" && "message" in error && typeof error.message === "string";
41
+ }
42
+ /**
43
+ * Convert an Error object to JSON-RPC error
44
+ */
45
+ function errorToJsonRpc(error) {
46
+ if (isJsonRpcError(error)) return error;
47
+ if (error instanceof Error) return {
48
+ code: JsonRpcErrorCode.InternalError,
49
+ message: error.message,
50
+ data: error.name
51
+ };
52
+ return {
53
+ code: JsonRpcErrorCode.InternalError,
54
+ message: "Unknown error",
55
+ data: error
56
+ };
57
+ }
58
+ /**
59
+ * Timeout error class
60
+ */
61
+ var RpcTimeoutError = class extends Error {
62
+ timeout;
63
+ constructor(timeout) {
64
+ super(`RPC call timed out after ${timeout}ms`);
65
+ this.name = "RpcTimeoutError";
66
+ this.timeout = timeout;
67
+ }
68
+ };
69
+ /**
70
+ * Check if an error is a timeout error
71
+ */
72
+ function isTimeoutError(error) {
73
+ return error instanceof RpcTimeoutError;
74
+ }
75
+ /**
76
+ * Error thrown when queue is full and fullBehavior is 'reject'
77
+ */
78
+ var RpcQueueFullError = class extends Error {
79
+ currentSize;
80
+ maxSize;
81
+ constructor(currentSize, maxSize) {
82
+ super(`RPC queue is full (${currentSize}/${maxSize})`);
83
+ this.name = "RpcQueueFullError";
84
+ this.currentSize = currentSize;
85
+ this.maxSize = maxSize;
86
+ }
87
+ };
88
+ /**
89
+ * Error thrown when connection to main process is lost
90
+ */
91
+ var RpcConnectionError = class extends Error {
92
+ code;
93
+ constructor(message, code) {
94
+ super(message);
95
+ this.name = "RpcConnectionError";
96
+ this.code = code;
97
+ }
98
+ };
99
+ /**
100
+ * Error thrown when request is evicted from queue
101
+ */
102
+ var RpcQueueEvictedError = class extends Error {
103
+ reason;
104
+ constructor(reason) {
105
+ super(`Request evicted from queue: ${reason}`);
106
+ this.name = "RpcQueueEvictedError";
107
+ this.reason = reason;
108
+ }
109
+ };
110
+ /**
111
+ * Check if an error is a queue full error
112
+ */
113
+ function isQueueFullError(error) {
114
+ return error instanceof RpcQueueFullError;
115
+ }
116
+ /**
117
+ * Check if an error is a connection error
118
+ */
119
+ function isConnectionError(error) {
120
+ return error instanceof RpcConnectionError;
121
+ }
122
+ /**
123
+ * Check if an error is a queue evicted error
124
+ */
125
+ function isQueueEvictedError(error) {
126
+ return error instanceof RpcQueueEvictedError;
127
+ }
128
+
129
+ //#endregion
130
+ export { createJsonRpcError as a, isConnectionError as c, isQueueFullError as d, isTimeoutError as f, RpcTimeoutError as i, isJsonRpcError as l, RpcQueueEvictedError as n, errorToJsonRpc as o, JsonRpcErrorCode as p, RpcQueueFullError as r, errors as s, RpcConnectionError as t, isQueueEvictedError as u };
131
+ //# sourceMappingURL=error-xVRu7Lxq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-xVRu7Lxq.mjs","names":[],"sources":["../src/types.ts","../src/error.ts"],"sourcesContent":["/**\n * JSON-RPC 2.0 types for Electron IPC communication\n */\n\n/**\n * JSON-RPC 2.0 Request\n * id is optional for notifications (one-way calls)\n */\nexport interface JsonRpcRequest {\n jsonrpc: \"2.0\";\n id?: string | number | null;\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/**\n * JSON-RPC 2.0 Response\n */\nexport interface JsonRpcResponse {\n jsonrpc: \"2.0\";\n id: string | number | null;\n result?: unknown;\n error?: JsonRpcError;\n}\n\n/**\n * JSON-RPC 2.0 Error\n */\nexport interface JsonRpcError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n/**\n * JSON-RPC 2.0 Error codes\n */\nexport enum JsonRpcErrorCode {\n ParseError = -32700,\n InvalidRequest = -32600,\n MethodNotFound = -32601,\n InvalidParams = -32602,\n InternalError = -32603,\n}\n\n/**\n * RPC method handler type\n */\nexport type RpcHandler = (...params: unknown[]) => unknown | Promise<unknown>;\n\n/**\n * Validator function for params\n * Throw an error to reject the request with InvalidParams error\n */\nexport type RpcValidator = (params: unknown[]) => void | Promise<void>;\n\n/**\n * RPC method registration options\n */\nexport interface RpcMethodOptions {\n /** Optional validator for parameters */\n validate?: RpcValidator;\n /** Optional description for documentation */\n description?: string;\n}\n\n/**\n * Typed API interface for RPC client\n * Converts method signatures to match JSON-RPC behavior\n */\nexport type RpcApi<T extends Record<string, (...args: any[]) => any>> = {\n [K in keyof T]: T[K] extends (...args: infer P) => infer R\n ? R extends void\n ? (...params: P) => void // Notification (void return)\n : (...params: P) => Promise<Awaited<R>> // Regular method\n : never;\n};\n\n/**\n * Options for RPC client\n */\nexport interface RpcClientOptions {\n /** Timeout in milliseconds (default: 30000) */\n timeout?: number;\n /** API name exposed by preload (default: 'rpc') */\n apiName?: string;\n}\n\n/**\n * Options for exposing RPC API in preload\n */\nexport interface ExposeRpcApiOptions {\n contextBridge: {\n exposeInMainWorld: (name: string, api: Record<string, unknown>) => void;\n };\n ipcRenderer: {\n send: (channel: string, ...args: unknown[]) => void;\n on: (channel: string, listener: (event: unknown, ...args: unknown[]) => void) => void;\n removeListener: (channel: string, listener: (...args: unknown[]) => void) => void;\n };\n /** Optional whitelist of methods to expose */\n methods?: string[];\n /** API name exposed to renderer (default: 'rpc') */\n apiName?: string;\n}\n\n/**\n * Stream chunk message for IPC\n */\nexport interface StreamChunk {\n streamId: string | number;\n type: \"chunk\" | \"end\" | \"error\";\n data?: unknown;\n error?: JsonRpcError;\n}\n\n/**\n * Stream request with stream flag\n */\nexport interface StreamRequest extends JsonRpcRequest {\n stream?: true;\n}\n\n/**\n * Stream handler - returns a ReadableStream\n */\nexport type StreamHandler = (...params: unknown[]) => ReadableStream;\n\n/**\n * Stream method registration options\n */\nexport interface StreamMethodOptions extends RpcMethodOptions {\n /** Indicates this method returns a stream */\n stream?: true;\n}\n\n/**\n * Underlying source for ReadableStream\n */\nexport type UnderlyingSource<T> = {\n start?: (controller: ReadableStreamDefaultController<T>) => void | Promise<void>;\n pull?: (controller: ReadableStreamDefaultController<T>) => void | Promise<void>;\n cancel?: (reason?: unknown) => void | Promise<void>;\n type?: undefined;\n};\n\n/**\n * Event handler callback type\n */\nexport type EventHandler<T = unknown> = (data: T) => void;\n\n/**\n * Event subscriber information\n */\nexport interface EventSubscriber {\n windowId: number;\n eventName: string;\n}\n\n/**\n * Event bus API type\n * Maps event names to their data types\n */\nexport type EventBusEvents<T extends Record<string, unknown>> = {\n [K in keyof T]: T[K];\n};\n\n/**\n * Typed event bus interface\n */\nexport type EventBus<T extends Record<string, unknown> = Record<string, unknown>> = {\n /**\n * Subscribe to an event\n * @returns Unsubscribe function\n */\n on<K extends keyof T>(eventName: K, callback: EventHandler<T[K]>): () => void;\n\n /**\n * Unsubscribe from an event\n * If no callback is provided, removes all handlers for the event\n */\n off<K extends keyof T>(eventName: K, callback?: EventHandler<T[K]>): void;\n\n /**\n * Subscribe to an event once (auto-unsubscribe after first call)\n */\n once<K extends keyof T>(eventName: K, callback: EventHandler<T[K]>): void;\n\n /**\n * Get list of subscribed event names\n */\n getSubscribedEvents(): string[];\n};\n\n/**\n * RPC debug log entry type\n */\nexport interface RpcLogEntry {\n /** Log entry type */\n type: \"request\" | \"response\" | \"error\" | \"notify\" | \"stream\" | \"event\";\n /** RPC method or event name */\n method: string;\n /** Request parameters */\n params?: unknown[];\n /** Response result */\n result?: unknown;\n /** Error message */\n error?: string;\n /** Timestamp in milliseconds */\n timestamp: number;\n /** Duration in milliseconds (for responses/errors) */\n duration?: number;\n /** Request ID for correlating request/response */\n requestId?: string | number;\n}\n\n/**\n * RPC logger function type\n */\nexport type RpcLogger = (entry: RpcLogEntry) => void;\n\n/**\n * Debug options for RPC clients\n */\nexport interface RpcDebugOptions {\n /** Enable debug logging */\n debug?: boolean;\n /** Custom logger function */\n logger?: RpcLogger;\n}\n","/**\n * JSON-RPC error utilities\n */\n\nimport type { JsonRpcError } from \"./types.js\";\nimport { JsonRpcErrorCode } from \"./types.js\";\n\n/**\n * Create a JSON-RPC error object\n */\nexport function createJsonRpcError(code: number, message: string, data?: unknown): JsonRpcError {\n return { code, message, data };\n}\n\n/**\n * Predefined error creators\n */\nexport const errors = {\n parseError: (data?: unknown) =>\n createJsonRpcError(JsonRpcErrorCode.ParseError, \"Parse error\", data),\n invalidRequest: (data?: unknown) =>\n createJsonRpcError(JsonRpcErrorCode.InvalidRequest, \"Invalid Request\", data),\n methodNotFound: (method?: string) =>\n createJsonRpcError(\n JsonRpcErrorCode.MethodNotFound,\n `Method not found${method ? `: ${method}` : \"\"}`,\n ),\n invalidParams: (data?: unknown) =>\n createJsonRpcError(JsonRpcErrorCode.InvalidParams, \"Invalid params\", data),\n internalError: (data?: unknown) =>\n createJsonRpcError(JsonRpcErrorCode.InternalError, \"Internal error\", data),\n};\n\n/**\n * Check if an error is a JSON-RPC error\n */\nexport function isJsonRpcError(error: unknown): error is JsonRpcError {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n typeof (error as JsonRpcError).code === \"number\" &&\n \"message\" in error &&\n typeof (error as JsonRpcError).message === \"string\"\n );\n}\n\n/**\n * Convert an Error object to JSON-RPC error\n */\nexport function errorToJsonRpc(error: unknown): JsonRpcError {\n if (isJsonRpcError(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n return {\n code: JsonRpcErrorCode.InternalError,\n message: error.message,\n data: error.name,\n };\n }\n\n return {\n code: JsonRpcErrorCode.InternalError,\n message: \"Unknown error\",\n data: error,\n };\n}\n\n/**\n * Timeout error class\n */\nexport class RpcTimeoutError extends Error {\n declare readonly name: \"RpcTimeoutError\";\n readonly timeout: number;\n\n constructor(timeout: number) {\n super(`RPC call timed out after ${timeout}ms`);\n this.name = \"RpcTimeoutError\";\n this.timeout = timeout;\n }\n}\n\n/**\n * Check if an error is a timeout error\n */\nexport function isTimeoutError(error: unknown): error is RpcTimeoutError {\n return error instanceof RpcTimeoutError;\n}\n\n/**\n * Error thrown when queue is full and fullBehavior is 'reject'\n */\nexport class RpcQueueFullError extends Error {\n declare readonly name: \"RpcQueueFullError\";\n readonly currentSize: number;\n readonly maxSize: number;\n\n constructor(currentSize: number, maxSize: number) {\n super(`RPC queue is full (${currentSize}/${maxSize})`);\n this.name = \"RpcQueueFullError\";\n this.currentSize = currentSize;\n this.maxSize = maxSize;\n }\n}\n\n/**\n * Error thrown when connection to main process is lost\n */\nexport class RpcConnectionError extends Error {\n declare readonly name: \"RpcConnectionError\";\n readonly code?: string;\n\n constructor(message: string, code?: string) {\n super(message);\n this.name = \"RpcConnectionError\";\n this.code = code;\n }\n}\n\n/**\n * Error thrown when request is evicted from queue\n */\nexport class RpcQueueEvictedError extends Error {\n declare readonly name: \"RpcQueueEvictedError\";\n readonly reason: \"full\" | \"timeout\";\n\n constructor(reason: \"full\" | \"timeout\") {\n super(`Request evicted from queue: ${reason}`);\n this.name = \"RpcQueueEvictedError\";\n this.reason = reason;\n }\n}\n\n/**\n * Check if an error is a queue full error\n */\nexport function isQueueFullError(error: unknown): error is RpcQueueFullError {\n return error instanceof RpcQueueFullError;\n}\n\n/**\n * Check if an error is a connection error\n */\nexport function isConnectionError(error: unknown): error is RpcConnectionError {\n return error instanceof RpcConnectionError;\n}\n\n/**\n * Check if an error is a queue evicted error\n */\nexport function isQueueEvictedError(error: unknown): error is RpcQueueEvictedError {\n return error instanceof RpcQueueEvictedError;\n}\n"],"mappings":";;;;AAqCA,IAAY,8DAAL;AACL;AACA;AACA;AACA;AACA;;;;;;;;;AChCF,SAAgB,mBAAmB,MAAc,SAAiB,MAA8B;AAC9F,QAAO;EAAE;EAAM;EAAS;EAAM;;;;;AAMhC,MAAa,SAAS;CACpB,aAAa,SACX,mBAAmB,iBAAiB,YAAY,eAAe,KAAK;CACtE,iBAAiB,SACf,mBAAmB,iBAAiB,gBAAgB,mBAAmB,KAAK;CAC9E,iBAAiB,WACf,mBACE,iBAAiB,gBACjB,mBAAmB,SAAS,KAAK,WAAW,KAC7C;CACH,gBAAgB,SACd,mBAAmB,iBAAiB,eAAe,kBAAkB,KAAK;CAC5E,gBAAgB,SACd,mBAAmB,iBAAiB,eAAe,kBAAkB,KAAK;CAC7E;;;;AAKD,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAQ,MAAuB,SAAS,YACxC,aAAa,SACb,OAAQ,MAAuB,YAAY;;;;;AAO/C,SAAgB,eAAe,OAA8B;AAC3D,KAAI,eAAe,MAAM,CACvB,QAAO;AAGT,KAAI,iBAAiB,MACnB,QAAO;EACL,MAAM,iBAAiB;EACvB,SAAS,MAAM;EACf,MAAM,MAAM;EACb;AAGH,QAAO;EACL,MAAM,iBAAiB;EACvB,SAAS;EACT,MAAM;EACP;;;;;AAMH,IAAa,kBAAb,cAAqC,MAAM;CAEzC,AAAS;CAET,YAAY,SAAiB;AAC3B,QAAM,4BAA4B,QAAQ,IAAI;AAC9C,OAAK,OAAO;AACZ,OAAK,UAAU;;;;;;AAOnB,SAAgB,eAAe,OAA0C;AACvE,QAAO,iBAAiB;;;;;AAM1B,IAAa,oBAAb,cAAuC,MAAM;CAE3C,AAAS;CACT,AAAS;CAET,YAAY,aAAqB,SAAiB;AAChD,QAAM,sBAAsB,YAAY,GAAG,QAAQ,GAAG;AACtD,OAAK,OAAO;AACZ,OAAK,cAAc;AACnB,OAAK,UAAU;;;;;;AAOnB,IAAa,qBAAb,cAAwC,MAAM;CAE5C,AAAS;CAET,YAAY,SAAiB,MAAe;AAC1C,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;AAOhB,IAAa,uBAAb,cAA0C,MAAM;CAE9C,AAAS;CAET,YAAY,QAA4B;AACtC,QAAM,+BAA+B,SAAS;AAC9C,OAAK,OAAO;AACZ,OAAK,SAAS;;;;;;AAOlB,SAAgB,iBAAiB,OAA4C;AAC3E,QAAO,iBAAiB;;;;;AAM1B,SAAgB,kBAAkB,OAA6C;AAC7E,QAAO,iBAAiB;;;;;AAM1B,SAAgB,oBAAoB,OAA+C;AACjF,QAAO,iBAAiB"}
@@ -0,0 +1,71 @@
1
+ //#region src/event.d.ts
2
+ /**
3
+ * Event Bus utilities for electron-json-rpc
4
+ *
5
+ * Implements publish-subscribe pattern for main-to-renderer communication
6
+ */
7
+ /**
8
+ * IPC channel name for event bus messages
9
+ */
10
+ declare const EVENT_CHANNEL = "json-rpc-events";
11
+ /**
12
+ * Message types for event bus communication
13
+ */
14
+ type EventMessageType = "subscribe" | "unsubscribe" | "event";
15
+ /**
16
+ * Event bus message sent between main and renderer
17
+ */
18
+ interface EventMessage {
19
+ type: EventMessageType;
20
+ eventName: string;
21
+ data?: unknown;
22
+ }
23
+ /**
24
+ * Subscribe message sent from renderer to main
25
+ */
26
+ interface SubscribeMessage extends EventMessage {
27
+ type: "subscribe";
28
+ eventName: string;
29
+ }
30
+ /**
31
+ * Unsubscribe message sent from renderer to main
32
+ */
33
+ interface UnsubscribeMessage extends EventMessage {
34
+ type: "unsubscribe";
35
+ eventName: string;
36
+ }
37
+ /**
38
+ * Event message sent from main to renderer
39
+ */
40
+ interface EventEmitMessage extends EventMessage {
41
+ type: "event";
42
+ eventName: string;
43
+ data?: unknown;
44
+ }
45
+ /**
46
+ * Create a subscribe message
47
+ */
48
+ declare function createSubscribeMessage(eventName: string): SubscribeMessage;
49
+ /**
50
+ * Create an unsubscribe message
51
+ */
52
+ declare function createUnsubscribeMessage(eventName: string): UnsubscribeMessage;
53
+ /**
54
+ * Create an event emit message
55
+ */
56
+ declare function createEventMessage(eventName: string, data?: unknown): EventEmitMessage;
57
+ /**
58
+ * Check if a message is an event emit message
59
+ */
60
+ declare function isEventMessage(message: EventMessage): message is EventEmitMessage;
61
+ /**
62
+ * Check if a message is a subscribe message
63
+ */
64
+ declare function isSubscribeMessage(message: EventMessage): message is SubscribeMessage;
65
+ /**
66
+ * Check if a message is an unsubscribe message
67
+ */
68
+ declare function isUnsubscribeMessage(message: EventMessage): message is UnsubscribeMessage;
69
+ //#endregion
70
+ export { EVENT_CHANNEL, EventEmitMessage, EventMessage, EventMessageType, SubscribeMessage, UnsubscribeMessage, createEventMessage, createSubscribeMessage, createUnsubscribeMessage, isEventMessage, isSubscribeMessage, isUnsubscribeMessage };
71
+ //# sourceMappingURL=event.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.mts","names":[],"sources":["../src/event.ts"],"mappings":";;AASA;AAKA;AAKA;AASA;;AAnBA;AAKA;cALa,aAAA;AAAA;AAKb;AAKA;AAVa,KAKD,gBAAA;AAAA;AAKZ;AASA;AAdY,UAKK,YAAA;EAAA,IAAA,EACT,gBAAA;EAAA,SAAA;EAAA,IAAA;AAAA;AAAA;AAQR;AAQA;AAhBQ,UAQS,gBAAA,SAAyB,YAAA;EAAA,IAAA;EAAA,SAAA;AAAA;AAAA;AAQ1C;AAQA;AAhB0C,UAQzB,kBAAA,SAA2B,YAAA;EAAA,IAAA;EAAA,SAAA;AAAA;AAAA;AAQ5C;AASA;AAjB4C,UAQ3B,gBAAA,SAAyB,YAAA;EAAA,IAAA;EAAA,SAAA;EAAA,IAAA;AAAA;AAAA;AAS1C;AAUA;AAnB0C,iBAS1B,sBAAA,CAAA,SAAA,WAA2C,gBAAA;AAAA;AAU3D;AAUA;AApB2D,iBAU3C,wBAAA,CAAA,SAAA,WAA6C,kBAAA;AAAA;AAU7D;AAWA;AArB6D,iBAU7C,kBAAA,CAAA,SAAA,UAAA,IAAA,aAAuD,gBAAA;AAAA;AAWvE;AAOA;AAlBuE,iBAWvD,cAAA,CAAA,OAAA,EAAwB,YAAA,GAAA,OAAA,IAA0B,gBAAA;AAAA;AAOlE;AAOA;AAdkE,iBAOlD,kBAAA,CAAA,OAAA,EAA4B,YAAA,GAAA,OAAA,IAA0B,gBAAA;AAAA;AAOtE;;AAPsE,iBAOtD,oBAAA,CAAA,OAAA,EAA8B,YAAA,GAAA,OAAA,IAA0B,kBAAA"}
package/dist/event.mjs ADDED
@@ -0,0 +1,60 @@
1
+ //#region src/event.ts
2
+ /**
3
+ * Event Bus utilities for electron-json-rpc
4
+ *
5
+ * Implements publish-subscribe pattern for main-to-renderer communication
6
+ */
7
+ /**
8
+ * IPC channel name for event bus messages
9
+ */
10
+ const EVENT_CHANNEL = "json-rpc-events";
11
+ /**
12
+ * Create a subscribe message
13
+ */
14
+ function createSubscribeMessage(eventName) {
15
+ return {
16
+ type: "subscribe",
17
+ eventName
18
+ };
19
+ }
20
+ /**
21
+ * Create an unsubscribe message
22
+ */
23
+ function createUnsubscribeMessage(eventName) {
24
+ return {
25
+ type: "unsubscribe",
26
+ eventName
27
+ };
28
+ }
29
+ /**
30
+ * Create an event emit message
31
+ */
32
+ function createEventMessage(eventName, data) {
33
+ return {
34
+ type: "event",
35
+ eventName,
36
+ data
37
+ };
38
+ }
39
+ /**
40
+ * Check if a message is an event emit message
41
+ */
42
+ function isEventMessage(message) {
43
+ return message.type === "event";
44
+ }
45
+ /**
46
+ * Check if a message is a subscribe message
47
+ */
48
+ function isSubscribeMessage(message) {
49
+ return message.type === "subscribe";
50
+ }
51
+ /**
52
+ * Check if a message is an unsubscribe message
53
+ */
54
+ function isUnsubscribeMessage(message) {
55
+ return message.type === "unsubscribe";
56
+ }
57
+
58
+ //#endregion
59
+ export { EVENT_CHANNEL, createEventMessage, createSubscribeMessage, createUnsubscribeMessage, isEventMessage, isSubscribeMessage, isUnsubscribeMessage };
60
+ //# sourceMappingURL=event.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.mjs","names":[],"sources":["../src/event.ts"],"sourcesContent":["/**\n * Event Bus utilities for electron-json-rpc\n *\n * Implements publish-subscribe pattern for main-to-renderer communication\n */\n\n/**\n * IPC channel name for event bus messages\n */\nexport const EVENT_CHANNEL = \"json-rpc-events\";\n\n/**\n * Message types for event bus communication\n */\nexport type EventMessageType = \"subscribe\" | \"unsubscribe\" | \"event\";\n\n/**\n * Event bus message sent between main and renderer\n */\nexport interface EventMessage {\n type: EventMessageType;\n eventName: string;\n data?: unknown;\n}\n\n/**\n * Subscribe message sent from renderer to main\n */\nexport interface SubscribeMessage extends EventMessage {\n type: \"subscribe\";\n eventName: string;\n}\n\n/**\n * Unsubscribe message sent from renderer to main\n */\nexport interface UnsubscribeMessage extends EventMessage {\n type: \"unsubscribe\";\n eventName: string;\n}\n\n/**\n * Event message sent from main to renderer\n */\nexport interface EventEmitMessage extends EventMessage {\n type: \"event\";\n eventName: string;\n data?: unknown;\n}\n\n/**\n * Create a subscribe message\n */\nexport function createSubscribeMessage(eventName: string): SubscribeMessage {\n return {\n type: \"subscribe\",\n eventName,\n };\n}\n\n/**\n * Create an unsubscribe message\n */\nexport function createUnsubscribeMessage(eventName: string): UnsubscribeMessage {\n return {\n type: \"unsubscribe\",\n eventName,\n };\n}\n\n/**\n * Create an event emit message\n */\nexport function createEventMessage(eventName: string, data?: unknown): EventEmitMessage {\n return {\n type: \"event\",\n eventName,\n data,\n };\n}\n\n/**\n * Check if a message is an event emit message\n */\nexport function isEventMessage(message: EventMessage): message is EventEmitMessage {\n return message.type === \"event\";\n}\n\n/**\n * Check if a message is a subscribe message\n */\nexport function isSubscribeMessage(message: EventMessage): message is SubscribeMessage {\n return message.type === \"subscribe\";\n}\n\n/**\n * Check if a message is an unsubscribe message\n */\nexport function isUnsubscribeMessage(message: EventMessage): message is UnsubscribeMessage {\n return message.type === \"unsubscribe\";\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,gBAAgB;;;;AA4C7B,SAAgB,uBAAuB,WAAqC;AAC1E,QAAO;EACL,MAAM;EACN;EACD;;;;;AAMH,SAAgB,yBAAyB,WAAuC;AAC9E,QAAO;EACL,MAAM;EACN;EACD;;;;;AAMH,SAAgB,mBAAmB,WAAmB,MAAkC;AACtF,QAAO;EACL,MAAM;EACN;EACA;EACD;;;;;AAMH,SAAgB,eAAe,SAAoD;AACjF,QAAO,QAAQ,SAAS;;;;;AAM1B,SAAgB,mBAAmB,SAAoD;AACrF,QAAO,QAAQ,SAAS;;;;;AAM1B,SAAgB,qBAAqB,SAAsD;AACzF,QAAO,QAAQ,SAAS"}