hypha-rpc 0.1.9 → 0.1.11

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.
@@ -243,9 +243,7 @@ class RPC extends _utils_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
243
243
  });
244
244
  }
245
245
  } else {
246
- console.log(
247
- "Connection established", connectionInfo
248
- );
246
+ console.log("Connection established", connectionInfo);
249
247
  }
250
248
  this._fire("connected", connectionInfo);
251
249
  };
@@ -388,11 +386,9 @@ class RPC extends _utils_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
388
386
  Object.assign(main, extra.value);
389
387
  }
390
388
  this._fire(main["type"], main);
391
- }
392
- else if (typeof message === "object") {
389
+ } else if (typeof message === "object") {
393
390
  this._fire(message["type"], message);
394
- }
395
- else {
391
+ } else {
396
392
  throw new Error("Invalid message format");
397
393
  }
398
394
  }
@@ -797,9 +793,9 @@ class RPC extends _utils_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
797
793
  typeof main_message === "object" && main_message.type,
798
794
  "Invalid message, must be an object with a `type` fields.",
799
795
  );
800
- if(!main_message.to) {
796
+ if (!main_message.to) {
801
797
  this._fire(main_message.type, main_message);
802
- return
798
+ return;
803
799
  }
804
800
  let message_package = (0,_msgpack_msgpack__WEBPACK_IMPORTED_MODULE_2__.encode)(main_message);
805
801
  if (extra_data) {
@@ -1118,7 +1114,18 @@ class RPC extends _utils_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1118
1114
  this._method_annotations.has(method) &&
1119
1115
  this._method_annotations.get(method).require_context
1120
1116
  ) {
1117
+ // if args.length + 1 is less than the required number of arguments we will pad with undefined
1118
+ // so we make sure the last argument is the context
1119
+ if (args.length + 1 < method.length) {
1120
+ for (let i = args.length; i < method.length - 1; i++) {
1121
+ args.push(undefined);
1122
+ }
1123
+ }
1121
1124
  args.push(data.ctx);
1125
+ (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
1126
+ args.length === method.length,
1127
+ `Runtime Error: Invalid number of arguments for method ${method_name}, expected ${method.length} but got ${args.length}`,
1128
+ );
1122
1129
  }
1123
1130
  // console.log("Executing method: " + method_name);
1124
1131
  if (data.promise) {
@@ -1989,7 +1996,8 @@ class WebRTCConnection {
1989
1996
  this._handle_connected = () => {};
1990
1997
  this.manager_id = null;
1991
1998
  this._data_channel.onopen = async () => {
1992
- this._handle_connected && this._handle_connected({channel: this._data_channel});
1999
+ this._handle_connected &&
2000
+ this._handle_connected({ channel: this._data_channel });
1993
2001
  };
1994
2002
  this._data_channel.onmessage = async (event) => {
1995
2003
  let data = event.data;
@@ -4301,7 +4309,7 @@ class WebsocketRPCConnection {
4301
4309
  console.log(
4302
4310
  `Successfully connected to the server, workspace: ${this.connection_info.workspace}, manager_id: ${this.manager_id}`,
4303
4311
  );
4304
- if(this.connection_info.announcement){
4312
+ if (this.connection_info.announcement) {
4305
4313
  console.log(`${this.connection_info.announcement}`);
4306
4314
  }
4307
4315
  resolve(this.connection_info);
@@ -4311,8 +4319,15 @@ class WebsocketRPCConnection {
4311
4319
  reject(new Error(error));
4312
4320
  return;
4313
4321
  } else {
4314
- console.error("ConnectionAbortedError: Unexpected message received from the server:", data);
4315
- reject(new Error("ConnectionAbortedError: Unexpected message received from the server"));
4322
+ console.error(
4323
+ "ConnectionAbortedError: Unexpected message received from the server:",
4324
+ data,
4325
+ );
4326
+ reject(
4327
+ new Error(
4328
+ "ConnectionAbortedError: Unexpected message received from the server",
4329
+ ),
4330
+ );
4316
4331
  return;
4317
4332
  }
4318
4333
  };
@@ -4376,7 +4391,7 @@ class WebsocketRPCConnection {
4376
4391
  ) {
4377
4392
  if ([1000, 1001].includes(event.code)) {
4378
4393
  console.info(
4379
- `Websocket connection closed (code: ${event.code}): ${event.reason}`
4394
+ `Websocket connection closed (code: ${event.code}): ${event.reason}`,
4380
4395
  );
4381
4396
  if (this._handle_disconnected) {
4382
4397
  this._handle_disconnected(event.reason);
@@ -4395,7 +4410,9 @@ class WebsocketRPCConnection {
4395
4410
  `Reconnecting to ${this._server_url.split("?")[0]} (attempt #${retry})`,
4396
4411
  );
4397
4412
  await this.open();
4398
- console.warn(`Successfully reconnected to server ${this._server_url}`);
4413
+ console.warn(
4414
+ `Successfully reconnected to server ${this._server_url}`,
4415
+ );
4399
4416
  } catch (e) {
4400
4417
  if (`${e}`.includes("ConnectionAbortedError")) {
4401
4418
  console.warn("Failed to reconnect, connection aborted:", e);