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.
- package/.turbo/turbo-build.log +15 -0
- package/.turbo/turbo-test.log +19 -19
- package/browser-mod.ts +0 -1
- package/deno.json +1 -1
- package/{src/http.ts → http.ts} +5 -5
- package/package.json +21 -5
- package/rollup.config.js +33 -0
- package/src/channel.ts +9 -2
- package/tsconfig.json +3 -0
|
@@ -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
|
+
[36m
|
|
7
|
+
[1m./mod.ts, ./browser-mod.ts, ./http.ts[22m → [1mdist, dist[22m...[39m
|
|
8
|
+
[1m[33m(!) Unresolved dependencies[39m[22m
|
|
9
|
+
[90mhttps://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency[39m
|
|
10
|
+
[1mnode:buffer[22m (imported by "src/adapters/node.ts", "src/interface.ts" and "src/adapters/deno.ts")
|
|
11
|
+
[1mnode:stream[22m (imported by "src/adapters/node.ts")
|
|
12
|
+
[1m[33m(!) [plugin typescript] @rollup/plugin-typescript TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.[39m[22m
|
|
13
|
+
[1m[33m(!) Unused external imports[39m[22m
|
|
14
|
+
Readable,Writable imported from external module "node:stream" but never used in "src/adapters/node.ts".
|
|
15
|
+
[32mcreated [1mdist, dist[22m in [1m1s[22m[39m
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> kkrpc@0.0.
|
|
3
|
+
> kkrpc@0.0.7 test /Users/hacker/Dev/projects/kkrpc/packages/kkrpc
|
|
4
4
|
> bun run scripts/test.ts
|
|
5
5
|
|
|
6
6
|
[0m[32mCheck[0m file:///Users/hacker/Dev/projects/kkrpc/packages/kkrpc/__deno_tests__/deno-web-worker.test.ts
|
|
7
7
|
[0m[32mCheck[0m file:///Users/hacker/Dev/projects/kkrpc/packages/kkrpc/__tests__/scripts/worker.ts
|
|
8
8
|
[0m[38;5;245mrunning 1 test from ./__deno_tests__/deno-web-worker.test.ts[0m
|
|
9
|
-
Call Worker Exposed API ... [0m[32mok[0m [0m[38;5;245m(
|
|
9
|
+
Call Worker Exposed API ... [0m[32mok[0m [0m[38;5;245m(382ms)[0m
|
|
10
10
|
|
|
11
|
-
[0m[32mok[0m | 1 passed | 0 failed [0m[38;5;245m(
|
|
11
|
+
[0m[32mok[0m | 1 passed | 0 failed [0m[38;5;245m(385ms)[0m
|
|
12
12
|
|
|
13
13
|
bun test v1.1.34 (5e5e7c60)
|
|
14
14
|
|
|
15
15
|
__tests__/http.test.ts:
|
|
16
|
-
(pass) HTTP RPC > echo service [
|
|
17
|
-
(pass) HTTP RPC > math operations [
|
|
18
|
-
(pass) HTTP RPC > concurrent calls [0.
|
|
19
|
-
(pass) HTTP RPC > stress test with concurrent calls [
|
|
20
|
-
(pass) HTTP RPC > error handling - invalid endpoint [0.
|
|
21
|
-
(pass) HTTP RPC > error handling - wrong method [0.
|
|
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 [
|
|
25
|
-
(pass) WebSocket concurrent connections [2.
|
|
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 [
|
|
28
|
+
(pass) Bun Worker [53.44ms]
|
|
29
29
|
|
|
30
30
|
__tests__/stdio-rpc.test.ts:
|
|
31
|
-
(pass) RPCChannel Test > DenoStdio [
|
|
32
|
-
(pass) RPCChannel Test > NodeStdio [
|
|
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.
|
|
36
|
-
(pass) Serializer > should serialize and deserialize a response [0.
|
|
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.
|
|
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 |
|
|
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. [
|
|
57
|
+
Ran 13 tests across 5 files. [903.00ms]
|
package/browser-mod.ts
CHANGED
package/deno.json
CHANGED
package/{src/http.ts → http.ts}
RENAMED
|
@@ -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.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
-
|
|
9
|
-
|
|
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
|
}
|
package/rollup.config.js
ADDED
|
@@ -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
|
-
|
|
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
|