kkrpc 0.2.0 → 0.2.2

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/http.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RPCChannel, I as IoInterface } from './channel-D6ZClufP.cjs';
2
- export { H as HTTPClientIO, a as HTTPServerIO } from './http-CvGfNM3D.cjs';
1
+ import { R as RPCChannel, I as IoInterface } from './channel-C01VCxab.cjs';
2
+ export { H as HTTPClientIO, a as HTTPServerIO } from './http-D0k1TiAJ.cjs';
3
3
  import 'node:buffer';
4
4
 
5
5
  declare function createHttpClient<API extends Record<string, any>>(url: string): {
package/dist/http.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RPCChannel, I as IoInterface } from './channel-D6ZClufP.js';
2
- export { H as HTTPClientIO, a as HTTPServerIO } from './http-Bz7mwStC.js';
1
+ import { R as RPCChannel, I as IoInterface } from './channel-C01VCxab.js';
2
+ export { H as HTTPClientIO, a as HTTPServerIO } from './http-D6N0U5-p.js';
3
3
  import 'node:buffer';
4
4
 
5
5
  declare function createHttpClient<API extends Record<string, any>>(url: string): {
package/dist/http.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-SZGZ2RBM.js";
5
5
  import {
6
6
  RPCChannel
7
- } from "./chunk-ZSSFWNSX.js";
7
+ } from "./chunk-YIQVRWAJ.js";
8
8
 
9
9
  // http.ts
10
10
  function createHttpClient(url) {
package/dist/mod.cjs CHANGED
@@ -44,10 +44,8 @@ __export(mod_exports, {
44
44
  WorkerChildIO: () => WorkerChildIO,
45
45
  WorkerParentIO: () => WorkerParentIO,
46
46
  deserializeMessage: () => deserializeMessage,
47
- deserializeResponse: () => deserializeResponse,
48
47
  generateUUID: () => generateUUID,
49
- serializeMessage: () => serializeMessage,
50
- serializeResponse: () => serializeResponse
48
+ serializeMessage: () => serializeMessage
51
49
  });
52
50
  module.exports = __toCommonJS(mod_exports);
53
51
 
@@ -503,30 +501,39 @@ var TauriShellStdio = class {
503
501
 
504
502
  // src/serialization.ts
505
503
  var import_superjson2 = __toESM(require("superjson"), 1);
506
- function serializeMessage(message) {
507
- return import_superjson2.default.stringify(message) + "\n";
504
+ function replacer(key, value) {
505
+ if (value instanceof Uint8Array) {
506
+ return {
507
+ type: "Uint8Array",
508
+ data: Array.from(value)
509
+ // Convert to regular array
510
+ };
511
+ }
512
+ return value;
508
513
  }
509
- function deserializeMessage(message) {
510
- return new Promise((resolve, reject) => {
511
- try {
512
- const parsed = import_superjson2.default.parse(message);
513
- resolve(parsed);
514
- } catch (error) {
515
- console.error("failed to parse message", typeof message, message, error);
516
- reject(error);
517
- }
518
- });
514
+ function reviver(key, value) {
515
+ if (value && value.type === "Uint8Array" && Array.isArray(value.data)) {
516
+ return new Uint8Array(value.data);
517
+ }
518
+ return value;
519
519
  }
520
- function serializeResponse(response) {
521
- return import_superjson2.default.stringify(response) + "\n";
520
+ function serializeMessage(message, options = {}) {
521
+ const version = options.version || "superjson";
522
+ const msgWithVersion = { ...message, version };
523
+ return version === "json" ? JSON.stringify(msgWithVersion, replacer) + "\n" : import_superjson2.default.stringify(msgWithVersion) + "\n";
522
524
  }
523
- function deserializeResponse(response) {
525
+ function deserializeMessage(message) {
524
526
  return new Promise((resolve, reject) => {
525
527
  try {
526
- const parsed = import_superjson2.default.parse(response);
527
- resolve(parsed);
528
+ if (message.startsWith('{"json":')) {
529
+ const parsed = import_superjson2.default.parse(message);
530
+ resolve(parsed);
531
+ } else {
532
+ const parsed = JSON.parse(message, reviver);
533
+ resolve(parsed);
534
+ }
528
535
  } catch (error) {
529
- console.error("failed to parse response", response);
536
+ console.error("failed to parse message", typeof message, message, error);
530
537
  reject(error);
531
538
  }
532
539
  });
@@ -542,6 +549,7 @@ var RPCChannel = class {
542
549
  constructor(io, options) {
543
550
  this.io = io;
544
551
  this.apiImplementation = options?.expose;
552
+ this.serializationOptions = options?.serialization || {};
545
553
  this.listen();
546
554
  }
547
555
  pendingRequests = {};
@@ -550,6 +558,7 @@ var RPCChannel = class {
550
558
  count = 0;
551
559
  messageStr = "";
552
560
  apiImplementation;
561
+ serializationOptions;
553
562
  /**
554
563
  * Exposes a local API implementation that can be called remotely
555
564
  * @param api The local API implementation to expose
@@ -596,7 +605,7 @@ var RPCChannel = class {
596
605
  /**
597
606
  * Handles a single message string by parsing and routing it
598
607
  * @param messageStr The message string to handle
599
- * @private
608
+ * @private
600
609
  */
601
610
  async handleMessageStr(messageStr) {
602
611
  this.count++;
@@ -646,7 +655,7 @@ var RPCChannel = class {
646
655
  type: "request",
647
656
  callbackIds: callbackIds.length > 0 ? callbackIds : void 0
648
657
  };
649
- this.io.write(serializeMessage(message));
658
+ this.io.write(serializeMessage(message, this.serializationOptions));
650
659
  });
651
660
  }
652
661
  /**
@@ -720,7 +729,7 @@ var RPCChannel = class {
720
729
  args,
721
730
  type: "callback"
722
731
  };
723
- this.io.write(serializeMessage(message));
732
+ this.io.write(serializeMessage(message, this.serializationOptions));
724
733
  }
725
734
  /**
726
735
  * Handles callback invocations received from the remote endpoint
@@ -749,7 +758,7 @@ var RPCChannel = class {
749
758
  args: { result },
750
759
  type: "response"
751
760
  };
752
- this.io.write(serializeMessage(response));
761
+ this.io.write(serializeMessage(response, this.serializationOptions));
753
762
  }
754
763
  /**
755
764
  * Sends an error response back to the remote endpoint
@@ -764,7 +773,7 @@ var RPCChannel = class {
764
773
  args: { error },
765
774
  type: "response"
766
775
  };
767
- this.io.write(serializeMessage(response));
776
+ this.io.write(serializeMessage(response, this.serializationOptions));
768
777
  }
769
778
  /**
770
779
  * Creates a nested proxy object for chaining remote method calls
@@ -844,8 +853,6 @@ var DenoIo = class {
844
853
  WorkerChildIO,
845
854
  WorkerParentIO,
846
855
  deserializeMessage,
847
- deserializeResponse,
848
856
  generateUUID,
849
- serializeMessage,
850
- serializeResponse
857
+ serializeMessage
851
858
  });
package/dist/mod.d.cts CHANGED
@@ -1,10 +1,11 @@
1
- export { T as TauriShellStdio, a as WorkerChildIO, W as WorkerParentIO } from './tauri-CRNRbu3f.cjs';
2
- export { ChromeBackgroundIO, ChromeContentIO, Message, Response, deserializeMessage, deserializeResponse, generateUUID, serializeMessage, serializeResponse } from './chrome.cjs';
1
+ export { T as TauriShellStdio, a as WorkerChildIO, W as WorkerParentIO } from './tauri-ohph68oo.cjs';
2
+ export { ChromeBackgroundIO, ChromeContentIO, generateUUID } from './chrome.cjs';
3
3
  import { Buffer } from 'node:buffer';
4
- import { I as IoInterface, D as DestroyableIoInterface } from './channel-D6ZClufP.cjs';
5
- export { R as RPCChannel } from './channel-D6ZClufP.cjs';
4
+ import { I as IoInterface, D as DestroyableIoInterface } from './channel-C01VCxab.cjs';
5
+ export { M as Message, R as RPCChannel, a as Response, S as SerializationOptions, d as deserializeMessage, s as serializeMessage } from './channel-C01VCxab.cjs';
6
6
  import { Readable, Writable } from 'node:stream';
7
- export { H as HTTPClientIO, a as HTTPServerIO } from './http-CvGfNM3D.cjs';
7
+ export { H as HTTPClientIO, a as HTTPServerIO } from './http-D0k1TiAJ.cjs';
8
+ export { DenoIo } from './deno-mod.cjs';
8
9
  import '@tauri-apps/plugin-shell';
9
10
 
10
11
  /**
@@ -80,18 +81,4 @@ declare class WebSocketServerIO implements DestroyableIoInterface {
80
81
  signalDestroy(): void;
81
82
  }
82
83
 
83
- /**
84
- * Stdio implementation for Deno
85
- * Deno doesn't have `process` object, and have a completely different stdio API,
86
- * This implementation wrap Deno's `Deno.stdin` and `Deno.stdout` to follow StdioInterface
87
- */
88
- declare class DenoIo implements IoInterface {
89
- private readStream;
90
- private reader;
91
- name: string;
92
- constructor(readStream: ReadableStream<Uint8Array>);
93
- read(): Promise<Buffer | null>;
94
- write(data: string): Promise<void>;
95
- }
96
-
97
- export { BunIo, DenoIo, DestroyableIoInterface, IoInterface, NodeIo, WebSocketClientIO, WebSocketServerIO };
84
+ export { BunIo, DestroyableIoInterface, IoInterface, NodeIo, WebSocketClientIO, WebSocketServerIO };
package/dist/mod.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export { T as TauriShellStdio, a as WorkerChildIO, W as WorkerParentIO } from './tauri-PdcZTVUI.js';
2
- export { ChromeBackgroundIO, ChromeContentIO, Message, Response, deserializeMessage, deserializeResponse, generateUUID, serializeMessage, serializeResponse } from './chrome.js';
1
+ export { T as TauriShellStdio, a as WorkerChildIO, W as WorkerParentIO } from './tauri-pC0wuvjw.js';
2
+ export { ChromeBackgroundIO, ChromeContentIO, generateUUID } from './chrome.js';
3
3
  import { Buffer } from 'node:buffer';
4
- import { I as IoInterface, D as DestroyableIoInterface } from './channel-D6ZClufP.js';
5
- export { R as RPCChannel } from './channel-D6ZClufP.js';
4
+ import { I as IoInterface, D as DestroyableIoInterface } from './channel-C01VCxab.js';
5
+ export { M as Message, R as RPCChannel, a as Response, S as SerializationOptions, d as deserializeMessage, s as serializeMessage } from './channel-C01VCxab.js';
6
6
  import { Readable, Writable } from 'node:stream';
7
- export { H as HTTPClientIO, a as HTTPServerIO } from './http-Bz7mwStC.js';
7
+ export { H as HTTPClientIO, a as HTTPServerIO } from './http-D6N0U5-p.js';
8
+ export { DenoIo } from './deno-mod.js';
8
9
  import '@tauri-apps/plugin-shell';
9
10
 
10
11
  /**
@@ -80,18 +81,4 @@ declare class WebSocketServerIO implements DestroyableIoInterface {
80
81
  signalDestroy(): void;
81
82
  }
82
83
 
83
- /**
84
- * Stdio implementation for Deno
85
- * Deno doesn't have `process` object, and have a completely different stdio API,
86
- * This implementation wrap Deno's `Deno.stdin` and `Deno.stdout` to follow StdioInterface
87
- */
88
- declare class DenoIo implements IoInterface {
89
- private readStream;
90
- private reader;
91
- name: string;
92
- constructor(readStream: ReadableStream<Uint8Array>);
93
- read(): Promise<Buffer | null>;
94
- write(data: string): Promise<void>;
95
- }
96
-
97
- export { BunIo, DenoIo, DestroyableIoInterface, IoInterface, NodeIo, WebSocketClientIO, WebSocketServerIO };
84
+ export { BunIo, DestroyableIoInterface, IoInterface, NodeIo, WebSocketClientIO, WebSocketServerIO };
package/dist/mod.js CHANGED
@@ -7,6 +7,9 @@ import {
7
7
  ChromeBackgroundIO,
8
8
  ChromeContentIO
9
9
  } from "./chunk-INKNKSKA.js";
10
+ import {
11
+ DenoIo
12
+ } from "./chunk-GRCUBSPR.js";
10
13
  import {
11
14
  HTTPClientIO,
12
15
  HTTPServerIO
@@ -14,11 +17,9 @@ import {
14
17
  import {
15
18
  RPCChannel,
16
19
  deserializeMessage,
17
- deserializeResponse,
18
20
  generateUUID,
19
- serializeMessage,
20
- serializeResponse
21
- } from "./chunk-ZSSFWNSX.js";
21
+ serializeMessage
22
+ } from "./chunk-YIQVRWAJ.js";
22
23
 
23
24
  // src/adapters/bun.ts
24
25
  import { Buffer } from "node:buffer";
@@ -188,30 +189,6 @@ var WebSocketServerIO = class {
188
189
  this.write(DESTROY_SIGNAL);
189
190
  }
190
191
  };
191
-
192
- // src/adapters/deno.ts
193
- import { Buffer as Buffer2 } from "node:buffer";
194
- var DenoIo = class {
195
- constructor(readStream) {
196
- this.readStream = readStream;
197
- this.reader = this.readStream.getReader();
198
- }
199
- reader;
200
- name = "deno-io";
201
- async read() {
202
- const { value, done } = await this.reader.read();
203
- if (done) {
204
- return null;
205
- }
206
- return Buffer2.from(value);
207
- }
208
- write(data) {
209
- const encoder = new TextEncoder();
210
- const encodedData = encoder.encode(data + "\n");
211
- Deno.stdout.writeSync(encodedData);
212
- return Promise.resolve();
213
- }
214
- };
215
192
  export {
216
193
  BunIo,
217
194
  ChromeBackgroundIO,
@@ -227,8 +204,6 @@ export {
227
204
  WorkerChildIO,
228
205
  WorkerParentIO,
229
206
  deserializeMessage,
230
- deserializeResponse,
231
207
  generateUUID,
232
- serializeMessage,
233
- serializeResponse
208
+ serializeMessage
234
209
  };
@@ -1,4 +1,4 @@
1
- import { D as DestroyableIoInterface, I as IoInterface } from './channel-D6ZClufP.cjs';
1
+ import { D as DestroyableIoInterface, I as IoInterface } from './channel-C01VCxab.cjs';
2
2
  import { EventEmitter, OutputEvents, Child } from '@tauri-apps/plugin-shell';
3
3
 
4
4
  declare class WorkerParentIO implements DestroyableIoInterface {
@@ -1,4 +1,4 @@
1
- import { D as DestroyableIoInterface, I as IoInterface } from './channel-D6ZClufP.js';
1
+ import { D as DestroyableIoInterface, I as IoInterface } from './channel-C01VCxab.js';
2
2
  import { EventEmitter, OutputEvents, Child } from '@tauri-apps/plugin-shell';
3
3
 
4
4
  declare class WorkerParentIO implements DestroyableIoInterface {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kkrpc",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,6 +43,15 @@
43
43
  "import": "./dist/http.js",
44
44
  "require": "./dist/http.cjs"
45
45
  },
46
+ "./deno": {
47
+ "types": {
48
+ "import": "./dist/deno-mod.d.ts",
49
+ "require": "./dist/deno-mod.cjs",
50
+ "default": "./dist/deno-mod.js"
51
+ },
52
+ "import": "./dist/deno-mod.js",
53
+ "require": "./dist/deno-mod.cjs"
54
+ },
46
55
  "./chrome": {
47
56
  "types": {
48
57
  "import": "./dist/chrome.d.ts",