@actuallab/rpc 12.3.2 → 12.3.4

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/dist/index.cjs CHANGED
@@ -864,7 +864,7 @@ var RpcStreamSender = class _RpcStreamSender {
864
864
  await this._started.promise;
865
865
  const iterator = source[Symbol.asyncIterator]();
866
866
  try {
867
- while (true) {
867
+ for (; ; ) {
868
868
  const next = await iterator.next();
869
869
  if (next.done || this._ended) break;
870
870
  const item = next.value;
@@ -1150,30 +1150,29 @@ var RpcStream = class _RpcStream {
1150
1150
  if (this._iterating)
1151
1151
  throw new Error("RpcStream can only be iterated once.");
1152
1152
  this._iterating = true;
1153
- const self = this;
1154
1153
  return {
1155
- async next() {
1156
- if (!self._started) {
1157
- self._started = true;
1158
- self._sendAck(0, true);
1154
+ next: async () => {
1155
+ if (!this._started) {
1156
+ this._started = true;
1157
+ this._sendAck(0, true);
1159
1158
  }
1160
- while (true) {
1161
- if (!self._buffer.isEmpty()) {
1162
- const value = self._buffer.shift();
1159
+ for (; ; ) {
1160
+ if (!this._buffer.isEmpty()) {
1161
+ const value = this._buffer.shift();
1163
1162
  return { value, done: false };
1164
1163
  }
1165
- if (self._completed) {
1166
- if (self._completionError) throw self._completionError;
1164
+ if (this._completed) {
1165
+ if (this._completionError) throw this._completionError;
1167
1166
  return { value: void 0, done: true };
1168
1167
  }
1169
- self._consumerWaiting = new import_core5.PromiseSource();
1170
- await self._consumerWaiting.promise;
1168
+ this._consumerWaiting = new import_core5.PromiseSource();
1169
+ await this._consumerWaiting.promise;
1171
1170
  }
1172
1171
  },
1173
- async return() {
1174
- self._sendAckEnd();
1175
- self.dispose();
1176
- return { value: void 0, done: true };
1172
+ return: () => {
1173
+ this._sendAckEnd();
1174
+ this.dispose();
1175
+ return Promise.resolve({ value: void 0, done: true });
1177
1176
  }
1178
1177
  };
1179
1178
  }
@@ -1782,21 +1781,18 @@ var RpcPeer = class {
1782
1781
  }
1783
1782
  const signal = options?.signal;
1784
1783
  if (signal !== void 0) {
1785
- const peer = this;
1786
- const hub = this._hub;
1787
- const tracker = this.outbound;
1788
1784
  const onAbort = () => {
1789
- if (tracker.remove(callId) !== void 0) {
1785
+ if (this.outbound.remove(callId) !== void 0) {
1790
1786
  outboundCall.result.reject(new Error("Call cancelled."));
1791
1787
  outboundCall.onDisconnect();
1792
- if (peer._connection !== void 0)
1793
- hub.systemCallSender.cancel(peer._connection, peer.format, callId);
1788
+ if (this._connection !== void 0)
1789
+ this._hub.systemCallSender.cancel(this._connection, this.format, callId);
1794
1790
  } else {
1795
- const idx = peer._pendingSends.findIndex(
1791
+ const idx = this._pendingSends.findIndex(
1796
1792
  (c) => c.callId === callId
1797
1793
  );
1798
1794
  if (idx !== -1) {
1799
- peer._pendingSends.splice(idx, 1);
1795
+ this._pendingSends.splice(idx, 1);
1800
1796
  outboundCall.result.reject(
1801
1797
  new Error("Call cancelled.")
1802
1798
  );
@@ -1890,51 +1886,49 @@ var RpcPeer = class {
1890
1886
  this.inbound.register(call);
1891
1887
  }
1892
1888
  const serviceHost = this._hub.serviceHost;
1893
- if (serviceHost !== void 0) {
1894
- void (async () => {
1895
- try {
1896
- const context = this._connection !== void 0 ? {
1897
- __rpcDispatch: true,
1898
- callId: relatedId,
1899
- connection: this._connection
1900
- } : void 0;
1901
- const result = await serviceHost.dispatch(
1902
- method,
1903
- args,
1904
- context
1889
+ void (async () => {
1890
+ try {
1891
+ const context = this._connection !== void 0 ? {
1892
+ __rpcDispatch: true,
1893
+ callId: relatedId,
1894
+ connection: this._connection
1895
+ } : void 0;
1896
+ const result = await serviceHost.dispatch(
1897
+ method,
1898
+ args,
1899
+ context
1900
+ );
1901
+ if (methodDef?.stream === true && this._connection !== void 0) {
1902
+ const stream = result instanceof RpcStream ? result : new RpcStream(result);
1903
+ this._hub.systemCallSender.ok(
1904
+ this._connection,
1905
+ this.format,
1906
+ relatedId,
1907
+ stream.toRef(this)
1908
+ );
1909
+ } else if (!isNoWait && this._connection !== void 0) {
1910
+ this._hub.systemCallSender.ok(
1911
+ this._connection,
1912
+ this.format,
1913
+ relatedId,
1914
+ result
1905
1915
  );
1906
- if (methodDef?.stream === true && this._connection !== void 0) {
1907
- const stream = result instanceof RpcStream ? result : new RpcStream(result);
1908
- this._hub.systemCallSender.ok(
1909
- this._connection,
1910
- this.format,
1911
- relatedId,
1912
- stream.toRef(this)
1913
- );
1914
- } else if (!isNoWait && this._connection !== void 0) {
1915
- this._hub.systemCallSender.ok(
1916
- this._connection,
1917
- this.format,
1918
- relatedId,
1919
- result
1920
- );
1921
- }
1922
- } catch (e) {
1923
- if (!isNoWait && this._connection !== void 0) {
1924
- this._hub.systemCallSender.error(
1925
- this._connection,
1926
- this.format,
1927
- relatedId,
1928
- e
1929
- );
1930
- }
1931
- } finally {
1932
- if (!isNoWait) {
1933
- this.inbound.remove(relatedId);
1934
- }
1935
1916
  }
1936
- })();
1937
- }
1917
+ } catch (e) {
1918
+ if (!isNoWait && this._connection !== void 0) {
1919
+ this._hub.systemCallSender.error(
1920
+ this._connection,
1921
+ this.format,
1922
+ relatedId,
1923
+ e
1924
+ );
1925
+ }
1926
+ } finally {
1927
+ if (!isNoWait) {
1928
+ this.inbound.remove(relatedId);
1929
+ }
1930
+ }
1931
+ })();
1938
1932
  }
1939
1933
  _startKeepAlive() {
1940
1934
  this._keepAliveTimer = setInterval(() => {
@@ -2803,6 +2797,7 @@ var RpcHub = class {
2803
2797
  this.registry.registerService(def.name, def.methods);
2804
2798
  }
2805
2799
  /** Create a typed client proxy for a service on a remote peer. */
2800
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- T is used for caller-specified proxy type
2806
2801
  addClient(peer, defOrContract) {
2807
2802
  const def = this._resolveServiceDef(defOrContract);
2808
2803
  this.registry.registerService(def.name, def.methods);