@hazae41/jsonrpc 1.1.10 → 1.2.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.
package/README.md CHANGED
@@ -1,16 +1,12 @@
1
1
  # JSON-RPC
2
2
 
3
- Rust-like JSON-RPC for TypeScript
3
+ JSON-RPC for the web
4
4
 
5
5
  ```bash
6
6
  npm install @hazae41/jsonrpc
7
7
  ```
8
8
 
9
- ```bash
10
- deno install jsr:@hazae41/jsonrpc
11
- ```
12
-
13
- [**📦 NPM**](https://www.npmjs.com/package/@hazae41/jsonrpc) • [**📦 JSR**](https://jsr.io/@hazae41/jsonrpc)
9
+ [**📦 NPM**](https://www.npmjs.com/package/@hazae41/jsonrpc)
14
10
 
15
11
  ## Features
16
12
 
@@ -18,7 +14,7 @@ deno install jsr:@hazae41/jsonrpc
18
14
  - 100% TypeScript and ESM
19
15
  - No external dependencies
20
16
  - Rust-like patterns
21
- - Uses `@hazae41/result`
17
+ - Uses `@hazae41/result-and-option`
22
18
  - [Specification](https://www.jsonrpc.org/specification) compliant
23
19
 
24
20
  ## Usage
@@ -1,3 +1,4 @@
1
+ // deno-lint-ignore-file no-namespace
1
2
  export var Errors;
2
3
  (function (Errors) {
3
4
  function toJSON(error) {
@@ -2,7 +2,6 @@ import { RpcRequest } from "../request/mod.js";
2
2
  export class RpcCounter {
3
3
  id = 0;
4
4
  prepare(init) {
5
- const { id = this.id++, method, params } = init;
6
- return new RpcRequest(id, method, params);
5
+ return new RpcRequest(this.id++, init.method, init.params);
7
6
  }
8
7
  }
@@ -0,0 +1,4 @@
1
+ import type { RpcRequest, RpcRequestInit } from "../request/mod.ts";
2
+ import type { RpcResponse, RpcResponseInit } from "../response/mod.ts";
3
+ export type RpcMessageInit = RpcRequestInit | RpcResponseInit;
4
+ export type RpcMessage = RpcRequest | RpcResponse;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
1
  export * from "./counter/mod.ts";
2
+ export * from "./message/mod.ts";
2
3
  export * from "./request/mod.ts";
3
4
  export * from "./response/mod.ts";
@@ -1,3 +1,4 @@
1
1
  export * from "./counter/mod.js";
2
+ export * from "./message/mod.js";
2
3
  export * from "./request/mod.js";
3
4
  export * from "./response/mod.js";
@@ -77,6 +77,6 @@ export declare class RpcErr extends Err<RpcError> {
77
77
  readonly jsonrpc = "2.0";
78
78
  constructor(id: RpcId, error: RpcError);
79
79
  static from(init: RpcErrInit): RpcErr;
80
- static rewrap<T extends Err.Infer<T>>(id: RpcId, result: T): RpcErr;
80
+ static rewrap(id: RpcId, result: Err<unknown>): RpcErr;
81
81
  toJSON(): RpcErrInit;
82
82
  }
@@ -8,7 +8,7 @@ export type RpcResponseInit<T = unknown> = RpcOkInit<T> | RpcErrInit;
8
8
  export type RpcResponse<T = unknown> = RpcOk<T> | RpcErr;
9
9
  export declare namespace RpcResponse {
10
10
  function from<T>(init: RpcResponseInit<T>): RpcResponse<T>;
11
- function rewrap<T extends Ok.Infer<T>>(id: RpcId, result: T): RpcOk<Ok.Inner<T>>;
12
- function rewrap<T extends Err.Infer<T>>(id: RpcId, result: T): RpcErr;
13
- function rewrap<T extends Result.Infer<T>>(id: RpcId, result: T): RpcResponse<Ok.Inner<T>>;
11
+ function rewrap<T>(id: RpcId, result: Ok<T>): RpcOk<T>;
12
+ function rewrap<T>(id: RpcId, result: Err<T>): RpcErr;
13
+ function rewrap<T>(id: RpcId, result: Result<T, unknown>): RpcResponse<T>;
14
14
  }
@@ -1,3 +1,4 @@
1
+ // deno-lint-ignore-file no-namespace
1
2
  export * from "./err/mod.js";
2
3
  export * from "./ok/mod.js";
3
4
  import { RpcErr } from "./err/mod.js";
@@ -7,13 +8,13 @@ export var RpcResponse;
7
8
  function from(init) {
8
9
  if ("error" in init)
9
10
  return RpcErr.from(init);
10
- return RpcOk.from(init);
11
+ if ("result" in init)
12
+ return RpcOk.from(init);
13
+ throw new Error();
11
14
  }
12
15
  RpcResponse.from = from;
13
16
  function rewrap(id, result) {
14
- if (result.isErr())
15
- return RpcErr.rewrap(id, result);
16
- return RpcOk.rewrap(id, result);
17
+ return result.isOk() ? RpcOk.rewrap(id, result) : RpcErr.rewrap(id, result);
17
18
  }
18
19
  RpcResponse.rewrap = rewrap;
19
20
  })(RpcResponse || (RpcResponse = {}));
@@ -11,6 +11,6 @@ export declare class RpcOk<T = unknown> extends Ok<T> {
11
11
  readonly jsonrpc = "2.0";
12
12
  constructor(id: RpcId, result: T);
13
13
  static from<T>(init: RpcOkInit<T>): RpcOk<T>;
14
- static rewrap<T extends Ok.Infer<T>>(id: RpcId, result: T): RpcOk<Ok.Inner<T>>;
14
+ static rewrap<T>(id: RpcId, result: Ok<T>): RpcOk<T>;
15
15
  toJSON(): RpcOkInit<T>;
16
16
  }
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/jsonrpc",
4
- "version": "1.1.10",
5
- "description": "Rust-like JSON-RPC for TypeScript",
4
+ "version": "1.2.0",
5
+ "description": "JSON-RPC for the web",
6
6
  "repository": "github:hazae41/jsonrpc",
7
7
  "author": "hazae41",
8
8
  "license": "MIT",
9
9
  "scripts": {
10
- "examine": "deno lint ./src && deno check ./src && deno test ./src",
11
- "version": "deno -RW ./x.vsync.ts && git add deno.json",
12
- "prepare": "deno -RW ./x.dsync.ts && deno install",
10
+ "examine": "deno lint ./src && deno check ./src && deno test -RW ./src",
13
11
  "prepack": "rm -rf ./out && tsc && tscousin"
14
12
  },
15
13
  "files": [
@@ -22,12 +20,14 @@
22
20
  }
23
21
  },
24
22
  "dependencies": {
25
- "@hazae41/result-and-option": "^2.0.10"
23
+ "@hazae41/result-and-option": "^2.1.1"
26
24
  },
27
25
  "devDependencies": {
28
- "@hazae41/phobos": "^2.0.13",
26
+ "@hazae41/phobos": "^2.0.16",
29
27
  "@hazae41/tscousin": "^1.0.28",
30
- "typescript": "^5.9.3"
28
+ "@types/node": "^25.9.1",
29
+ "deno": "^2.8.1",
30
+ "typescript": "^6.0.3"
31
31
  },
32
32
  "keywords": [
33
33
  "jsonrpc",