starpc 0.1.9 → 0.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.
@@ -16,7 +16,7 @@ export class ClientRPC extends CommonRPC {
16
16
  rpcService: this.service,
17
17
  rpcMethod: this.method,
18
18
  data: data || new Uint8Array(0),
19
- dataIsZero: (!!data) && data.length === 0,
19
+ dataIsZero: !!data && data.length === 0,
20
20
  };
21
21
  await this.writePacket({
22
22
  body: {
@@ -29,7 +29,7 @@ export class CommonRPC {
29
29
  async writeCallData(data, complete, error) {
30
30
  const callData = {
31
31
  data: data || new Uint8Array(0),
32
- dataIsZero: (!!data) && data.length === 0,
32
+ dataIsZero: !!data && data.length === 0,
33
33
  complete: complete || false,
34
34
  error: error || '',
35
35
  };
@@ -1,5 +1,4 @@
1
- import { InvokeFn } from 'srpc';
2
- import { Handler } from './handler';
1
+ import { InvokeFn, Handler } from './handler';
3
2
  export interface Mux {
4
3
  register(handler: Handler): void;
5
4
  lookupMethod(serviceID: string, methodID: string): Promise<InvokeFn | null>;
@@ -34,8 +34,7 @@ export class ServerRPC extends CommonRPC {
34
34
  // invokeRPC starts invoking the RPC handler.
35
35
  invokeRPC(invokeFn) {
36
36
  const dataSink = this._createDataSink();
37
- invokeFn(this.rpcDataSource, dataSink)
38
- .catch((err) => {
37
+ invokeFn(this.rpcDataSource, dataSink).catch((err) => {
39
38
  this.close(err);
40
39
  });
41
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -36,6 +36,7 @@
36
36
  "scripts": {
37
37
  "build": "rimraf ./dist && tsc --project tsconfig.build.json --outDir ./dist/",
38
38
  "check": "tsc",
39
+ "deps": "depcheck",
39
40
  "codegen": "npm run gen",
40
41
  "ci": "npm run build && npm run lint:js && npm run lint:go",
41
42
  "format": "prettier --write './{srpc,echo,e2e,integration}/**/(*.ts|*.tsx|*.html|*.css)'",
@@ -56,29 +57,21 @@
56
57
  "singleQuote": true
57
58
  },
58
59
  "devDependencies": {
59
- "@babel/core": "^7.18.5",
60
- "@babel/preset-env": "^7.18.2",
61
- "@babel/preset-typescript": "^7.17.12",
62
- "@types/varint": "^6.0.0",
63
60
  "@typescript-eslint/eslint-plugin": "^5.27.1",
64
61
  "@typescript-eslint/parser": "^5.27.1",
65
- "esbuild": "^0.14.44",
66
- "eslint": "^8.17.0",
62
+ "depcheck": "^1.4.3",
63
+ "esbuild": "^0.14.46",
64
+ "eslint": "^8.18.0",
67
65
  "eslint-config-prettier": "^8.5.0",
68
- "eslint-config-standard-with-typescript": "^21.0.1",
69
- "eslint-plugin-react-hooks": "^4.6.0",
70
- "husky": "^8.0.1",
71
- "prettier": "^2.7.0",
66
+ "prettier": "^2.7.1",
72
67
  "rimraf": "^3.0.2",
73
- "ts-eager": "^2.0.2",
74
- "ts-node": "^10.8.1",
75
68
  "ts-proto": "^1.115.4",
76
- "typescript": "^4.7.3"
69
+ "typescript": "^4.7.4"
77
70
  },
78
71
  "dependencies": {
79
- "@libp2p/components": "^1.0.0",
80
- "@libp2p/interface-connection": "^1.0.1",
81
- "@libp2p/mplex": "^2.0.0",
72
+ "@libp2p/interface-connection": "^2.0.0",
73
+ "@libp2p/interface-stream-muxer": "^1.0.2",
74
+ "@libp2p/mplex": "^3.0.0",
82
75
  "event-iterator": "^2.0.0",
83
76
  "isomorphic-ws": "^4.0.1",
84
77
  "it-length-prefixed": "^7.0.1",
@@ -86,10 +79,10 @@
86
79
  "it-pushable": "^3.0.0",
87
80
  "it-stream-types": "^1.0.4",
88
81
  "it-ws": "^5.0.2",
82
+ "long": "^5.2.0",
89
83
  "patch-package": "^6.4.7",
90
84
  "protobufjs": "^6.11.3",
91
85
  "rxjs": "^7.5.5",
92
- "ts-poet": "^4.13.0",
93
86
  "ws": "^8.8.0"
94
87
  }
95
88
  }
@@ -19,7 +19,7 @@ export class ClientRPC extends CommonRPC {
19
19
  rpcService: this.service,
20
20
  rpcMethod: this.method,
21
21
  data: data || new Uint8Array(0),
22
- dataIsZero: (!!data) && data.length === 0,
22
+ dataIsZero: !!data && data.length === 0,
23
23
  }
24
24
  await this.writePacket({
25
25
  body: {
package/srpc/client.ts CHANGED
@@ -133,7 +133,7 @@ export class Client implements TsProtoRpc {
133
133
  private async startRpc(
134
134
  rpcService: string,
135
135
  rpcMethod: string,
136
- data: Uint8Array | null,
136
+ data: Uint8Array | null
137
137
  ): Promise<ClientRPC> {
138
138
  const conn = await this.openConnFn()
139
139
  const call = new ClientRPC(rpcService, rpcMethod)
@@ -48,7 +48,7 @@ export class CommonRPC {
48
48
  ) {
49
49
  const callData: CallData = {
50
50
  data: data || new Uint8Array(0),
51
- dataIsZero: (!!data) && data.length === 0,
51
+ dataIsZero: !!data && data.length === 0,
52
52
  complete: complete || false,
53
53
  error: error || '',
54
54
  }
@@ -103,8 +103,11 @@ export class CommonRPC {
103
103
  )
104
104
  }
105
105
 
106
- // pushRpcData pushes incoming rpc data to the rpc data source.
107
- protected pushRpcData(data: Uint8Array | undefined, dataIsZero: boolean | undefined) {
106
+ // pushRpcData pushes incoming rpc data to the rpc data source.
107
+ protected pushRpcData(
108
+ data: Uint8Array | undefined,
109
+ dataIsZero: boolean | undefined
110
+ ) {
108
111
  if (dataIsZero) {
109
112
  if (!data || data.length !== 0) {
110
113
  data = new Uint8Array(0)
package/srpc/handler.ts CHANGED
@@ -66,11 +66,10 @@ export class StaticHandler implements Handler {
66
66
 
67
67
  // MethodProto is a function which matches one of the RPC signatures.
68
68
  type MethodProto =
69
- ((request: unknown) => Promise<unknown>) |
70
- ((request: unknown) => Observable<unknown>) |
71
- ((request: Observable<unknown>) => Promise<unknown>) |
72
- ((request: Observable<unknown>) => Observable<unknown>)
73
-
69
+ | ((request: unknown) => Promise<unknown>)
70
+ | ((request: unknown) => Observable<unknown>)
71
+ | ((request: Observable<unknown>) => Promise<unknown>)
72
+ | ((request: Observable<unknown>) => Observable<unknown>)
74
73
 
75
74
  // createInvokeFn builds an InvokeFn from a method definition and a function prototype.
76
75
  export function createInvokeFn(
package/srpc/mux.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { InvokeFn } from 'srpc'
2
- import { Handler } from './handler'
1
+ import { InvokeFn, Handler } from './handler'
3
2
 
4
3
  // Mux contains a set of <service, method> handlers.
5
4
  export interface Mux {
@@ -44,10 +44,9 @@ export class ServerRPC extends CommonRPC {
44
44
  // invokeRPC starts invoking the RPC handler.
45
45
  private invokeRPC(invokeFn: InvokeFn) {
46
46
  const dataSink = this._createDataSink()
47
- invokeFn(this.rpcDataSource, dataSink)
48
- .catch((err) => {
49
- this.close(err)
50
- })
47
+ invokeFn(this.rpcDataSource, dataSink).catch((err) => {
48
+ this.close(err)
49
+ })
51
50
  }
52
51
 
53
52
  // _createDataSink creates a sink for outgoing data packets.