kkrpc 0.0.6 → 0.0.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.
@@ -0,0 +1,15 @@
1
+
2
+ 
3
+ > kkrpc@0.0.7 build /Users/hacker/Dev/projects/kkrpc/packages/kkrpc
4
+ > rimraf dist && rollup -c
5
+
6
+ 
7
+ ./mod.ts, ./browser-mod.ts, ./http.ts → dist, dist...
8
+ (!) Unresolved dependencies
9
+ https://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency
10
+ node:buffer (imported by "src/adapters/node.ts", "src/interface.ts" and "src/adapters/deno.ts")
11
+ node:stream (imported by "src/adapters/node.ts")
12
+ (!) [plugin typescript] @rollup/plugin-typescript TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
13
+ (!) Unused external imports
14
+ Readable,Writable imported from external module "node:stream" but never used in "src/adapters/node.ts".
15
+ created dist, dist in 1s
@@ -1,43 +1,43 @@
1
1
 
2
2
  
3
- > kkrpc@0.0.5 test /Users/hacker/Dev/projects/kkrpc/packages/kkrpc
3
+ > kkrpc@0.0.7 test /Users/hacker/Dev/projects/kkrpc/packages/kkrpc
4
4
  > bun run scripts/test.ts
5
5
 
6
6
  Check file:///Users/hacker/Dev/projects/kkrpc/packages/kkrpc/__deno_tests__/deno-web-worker.test.ts
7
7
  Check file:///Users/hacker/Dev/projects/kkrpc/packages/kkrpc/__tests__/scripts/worker.ts
8
8
  running 1 test from ./__deno_tests__/deno-web-worker.test.ts
9
- Call Worker Exposed API ... ok (377ms)
9
+ Call Worker Exposed API ... ok (382ms)
10
10
 
11
- ok | 1 passed | 0 failed (379ms)
11
+ ok | 1 passed | 0 failed (385ms)
12
12
 
13
13
  bun test v1.1.34 (5e5e7c60)
14
14
 
15
15
  __tests__/http.test.ts:
16
- (pass) HTTP RPC > echo service [4.33ms]
17
- (pass) HTTP RPC > math operations [1.16ms]
18
- (pass) HTTP RPC > concurrent calls [0.59ms]
19
- (pass) HTTP RPC > stress test with concurrent calls [200.21ms]
20
- (pass) HTTP RPC > error handling - invalid endpoint [0.38ms]
21
- (pass) HTTP RPC > error handling - wrong method [0.48ms]
16
+ (pass) HTTP RPC > echo service [9.89ms]
17
+ (pass) HTTP RPC > math operations [0.88ms]
18
+ (pass) HTTP RPC > concurrent calls [0.98ms]
19
+ (pass) HTTP RPC > stress test with concurrent calls [152.69ms]
20
+ (pass) HTTP RPC > error handling - invalid endpoint [0.27ms]
21
+ (pass) HTTP RPC > error handling - wrong method [0.14ms]
22
22
 
23
23
  __tests__/websocket.test.ts:
24
- (pass) WebSocket RPC [26.99ms]
25
- (pass) WebSocket concurrent connections [2.45ms]
24
+ (pass) WebSocket RPC [23.07ms]
25
+ (pass) WebSocket concurrent connections [2.27ms]
26
26
 
27
27
  __tests__/bun.worker.test.ts:
28
- (pass) Bun Worker [35.24ms]
28
+ (pass) Bun Worker [53.44ms]
29
29
 
30
30
  __tests__/stdio-rpc.test.ts:
31
- (pass) RPCChannel Test > DenoStdio [463.95ms]
32
- (pass) RPCChannel Test > NodeStdio [339.55ms]
31
+ (pass) RPCChannel Test > DenoStdio [320.78ms]
32
+ (pass) RPCChannel Test > NodeStdio [276.50ms]
33
33
 
34
34
  __tests__/serialization.test.ts:
35
- (pass) Serializer > should serialize and deserialize a message [0.38ms]
36
- (pass) Serializer > should serialize and deserialize a response [0.17ms]
35
+ (pass) Serializer > should serialize and deserialize a message [0.69ms]
36
+ (pass) Serializer > should serialize and deserialize a response [0.16ms]
37
37
  ---------------------------|---------|---------|-------------------
38
38
  File | % Funcs | % Lines | Uncovered Line #s
39
39
  ---------------------------|---------|---------|-------------------
40
- All files | 77.97 | 70.24 |
40
+ All files | 77.73 | 70.22 |
41
41
  __tests__/scripts/api.ts | 72.73 | 87.50 | 24,41-42
42
42
  mod.ts | 100.00 | 100.00 |
43
43
  src/adapters/deno.ts | 0.00 | 20.00 | 13-28,32-35
@@ -45,7 +45,7 @@ All files | 77.97 | 70.24 |
45
45
  src/adapters/node.ts | 84.62 | 91.43 | 25,42-43
46
46
  src/adapters/websocket.ts | 77.27 | 1.61 | 3-124
47
47
  src/adapters/worker.ts | 50.00 | 1.77 | 3-113
48
- src/channel.ts | 73.08 | 88.54 | 46,164,183-189,218-224,256-257
48
+ src/channel.ts | 70.37 | 88.34 | 46,50,171,190-196,225-231,263-264
49
49
  src/interface.ts | 100.00 | 100.00 |
50
50
  src/serialization.ts | 100.00 | 81.82 | 28-29,46-47
51
51
  src/utils.ts | 100.00 | 100.00 |
@@ -54,4 +54,4 @@ All files | 77.97 | 70.24 |
54
54
  13 pass
55
55
  0 fail
56
56
  14640 expect() calls
57
- Ran 13 tests across 5 files. [1118.00ms]
57
+ Ran 13 tests across 5 files. [903.00ms]
package/browser-mod.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./src/adapters/worker.ts"
2
- export * from "./src/adapters/node.ts"
3
2
  export * from "./src/interface.ts"
4
3
  export * from "./src/channel.ts"
5
4
  export * from "./src/utils.ts"
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kunkun/kkrpc",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "tasks": {
5
5
  "dev": "deno run --watch main.ts"
6
6
  },
@@ -1,6 +1,6 @@
1
- import { HTTPClientIO, HTTPServerIO } from "./adapters/http"
2
- import { RPCChannel } from "./channel"
3
- import type { IoInterface } from "./interface"
1
+ import { HTTPClientIO, HTTPServerIO } from "./src/adapters/http"
2
+ import { RPCChannel } from "./src/channel"
3
+ import type { IoInterface } from "./src/interface"
4
4
 
5
5
  export function createHttpClient<API extends Record<string, any>>(
6
6
  url: string
@@ -20,5 +20,5 @@ export function createHttpHandler<API extends Record<string, any>>(
20
20
  new RPCChannel<{}, API>(serverIO, { expose: api })
21
21
  return serverIO
22
22
  }
23
- export { RPCChannel } from "./channel"
24
- export { HTTPClientIO, HTTPServerIO } from "./adapters/http"
23
+ export { RPCChannel } from "./src/channel"
24
+ export { HTTPClientIO, HTTPServerIO } from "./src/adapters/http"
package/package.json CHANGED
@@ -1,16 +1,31 @@
1
1
  {
2
2
  "name": "kkrpc",
3
3
  "module": "index.ts",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "type": "module",
6
6
  "exports": {
7
- ".": "./mod.ts",
8
- "./browser": "./browser-mod.ts",
9
- "./http": "./src/http.ts"
7
+ ".": {
8
+ "import": "./dist/mod.js",
9
+ "require": "./dist/mod.cjs",
10
+ "types": "./dist/mod.d.ts"
11
+ },
12
+ "./browser": {
13
+ "import": "./dist/browser-mod.js",
14
+ "require": "./dist/browser-mod.cjs",
15
+ "types": "./dist/browser-mod.d.ts"
16
+ },
17
+ "./http": {
18
+ "import": "./dist/http.js",
19
+ "require": "./dist/http.cjs",
20
+ "types": "./dist/http.d.ts"
21
+ }
10
22
  },
11
23
  "devDependencies": {
24
+ "@rollup/plugin-typescript": "^12.1.1",
12
25
  "@types/bun": "latest",
13
26
  "@types/ws": "^8.5.10",
27
+ "rimraf": "^6.0.1",
28
+ "rollup": "^4.27.3",
14
29
  "typedoc": "^0.26.11"
15
30
  },
16
31
  "peerDependencies": {
@@ -21,6 +36,7 @@
21
36
  },
22
37
  "scripts": {
23
38
  "test": "bun run scripts/test.ts",
24
- "docs": "typedoc --out docs"
39
+ "docs": "typedoc --out docs",
40
+ "build": "rimraf dist && rollup -c"
25
41
  }
26
42
  }
@@ -0,0 +1,33 @@
1
+ import { readFileSync } from "fs"
2
+ import path, { join } from "path"
3
+ import { cwd } from "process"
4
+ import typescript from "@rollup/plugin-typescript"
5
+
6
+ const pkg = JSON.parse(readFileSync(join(cwd(), "package.json"), "utf8"))
7
+
8
+ /** @type {import('rollup').RollupOptions} */
9
+ const config = {
10
+ input: ["./mod.ts", "./browser-mod.ts", "./http.ts"],
11
+ output: [
12
+ {
13
+ dir: "dist",
14
+ format: "cjs",
15
+ entryFileNames: "[name].cjs",
16
+ chunkFileNames: "[name]-[hash].js",
17
+ preserveModules: true,
18
+ preserveModulesRoot: "src"
19
+ },
20
+ {
21
+ dir: "dist",
22
+ format: "esm",
23
+ entryFileNames: "[name].js",
24
+ chunkFileNames: "[name]-[hash].js",
25
+ preserveModules: true,
26
+ preserveModulesRoot: "src"
27
+ }
28
+ ],
29
+ treeshake: true,
30
+ plugins: [typescript()]
31
+ }
32
+
33
+ export default config
package/src/channel.ts CHANGED
@@ -43,6 +43,10 @@ export class RPCChannel<
43
43
  this.listen()
44
44
  }
45
45
 
46
+ expose(api: LocalAPI) {
47
+ this.apiImplementation = api
48
+ }
49
+
46
50
  getIO(): Io {
47
51
  return this.io
48
52
  }
@@ -52,11 +56,14 @@ export class RPCChannel<
52
56
 
53
57
  while (true) {
54
58
  const buffer = await this.io.read()
55
- // console.error(`${this.io.name} buffer`, buffer?.toString("utf-8"))
56
59
  if (!buffer) {
57
60
  continue
58
61
  }
59
- this.messageStr += buffer.toString("utf-8")
62
+ const bufferStr = buffer.toString("utf-8")
63
+ if (bufferStr.trim().length === 0) {
64
+ continue
65
+ }
66
+ this.messageStr += bufferStr
60
67
  const lastChar = this.messageStr[this.messageStr.length - 1]
61
68
  const msgsSplit = this.messageStr.split("\n")
62
69
  const msgs = lastChar === "\n" ? msgsSplit : msgsSplit.slice(0, -1) // remove the last incomplete message
package/tsconfig.json CHANGED
@@ -13,6 +13,9 @@
13
13
  "allowImportingTsExtensions": true,
14
14
  "verbatimModuleSyntax": true,
15
15
  "noEmit": true,
16
+ "declaration": true,
17
+ "declarationMap": true,
18
+ "declarationDir": "dist",
16
19
 
17
20
  // Best practices
18
21
  "strict": true,