@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.d.cts CHANGED
@@ -125,10 +125,10 @@ declare function deserializeBinaryMessage(data: Uint8Array, offset: number, deco
125
125
  * Accepts an optional `Decoder` for reuse across calls on the same
126
126
  * connection — forwarded to `deserializeBinaryMessage`.
127
127
  */
128
- declare function splitBinaryFrame(frame: Uint8Array, decoder?: Decoder): Array<{
128
+ declare function splitBinaryFrame(frame: Uint8Array, decoder?: Decoder): {
129
129
  message: RpcMessage;
130
130
  args: unknown[];
131
- }>;
131
+ }[];
132
132
  /**
133
133
  * Serializes multiple binary messages into a single WebSocket frame.
134
134
  * Simply concatenates the already size-prefixed messages.
@@ -158,10 +158,10 @@ declare function deserializeCompactBinaryMessage(data: Uint8Array, offset: numbe
158
158
  /**
159
159
  * Splits a compact binary frame into individual deserialized messages.
160
160
  */
161
- declare function splitCompactBinaryFrame(frame: Uint8Array, registry?: RpcMethodRegistry, decoder?: Decoder): Array<{
161
+ declare function splitCompactBinaryFrame(frame: Uint8Array, registry?: RpcMethodRegistry, decoder?: Decoder): {
162
162
  message: RpcMessage;
163
163
  args: unknown[];
164
- }>;
164
+ }[];
165
165
 
166
166
  /** Parsed inbound message — result of deserialization. */
167
167
  interface RpcDeserializedMessage {
@@ -465,7 +465,7 @@ declare class RpcClientPeerReconnectDelayer extends RetryDelayer {
465
465
  constructor();
466
466
  }
467
467
 
468
- type RpcServiceImpl = Record<string, (...args: unknown[]) => unknown>;
468
+ type RpcServiceImpl = Record<string, ((...args: unknown[]) => unknown) | undefined>;
469
469
  /** Context passed to service dispatch — carries callId and connection for compute tracking. */
470
470
  interface RpcDispatchContext {
471
471
  __rpcDispatch: true;
@@ -480,6 +480,26 @@ declare class RpcServiceHost {
480
480
  getMethodDef(wireMethod: string): RpcMethodDef | undefined;
481
481
  }
482
482
 
483
+ interface MethodMeta {
484
+ argCount: number;
485
+ returns?: symbol;
486
+ [key: symbol]: unknown;
487
+ }
488
+ interface ServiceMeta {
489
+ name: string;
490
+ }
491
+ type AnyConstructor = abstract new (...args: any[]) => any;
492
+ /** Read method metadata from a decorated class. */
493
+ declare function getMethodsMeta(cls: AnyConstructor): Record<string, MethodMeta> | undefined;
494
+ /** Read service metadata from a decorated class. */
495
+ declare function getServiceMeta(cls: AnyConstructor): ServiceMeta | undefined;
496
+ /** Class decorator — stores the RPC service wire name. */
497
+ declare function rpcService(serviceName: string): <T extends AnyConstructor>(_target: T, context: ClassDecoratorContext<T>) => void;
498
+ /** Method decorator — stores RPC method metadata (argCount, returns). Does NOT wrap the method. */
499
+ declare function rpcMethod(options?: {
500
+ returns?: symbol;
501
+ }): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
502
+
483
503
  /**
484
504
  * Sends system RPC messages — like .NET's RpcSystemCallSender.
485
505
  *
@@ -545,14 +565,14 @@ declare class RpcHub {
545
565
  /** Get or create a server peer for the given ref. */
546
566
  getServerPeer(ref: string): RpcServerPeer;
547
567
  /** Register a service with optional server method wrapping for custom call types. */
548
- addService(defOrContract: RpcServiceDef | (abstract new (...args: any[]) => any), impl: RpcServiceImpl): void;
568
+ addService(defOrContract: RpcServiceDef | (AnyConstructor), impl: RpcServiceImpl): void;
549
569
  /** Create a typed client proxy for a service on a remote peer. */
550
- addClient<T extends object>(peer: RpcPeer, defOrContract: RpcServiceDef | (abstract new (...args: any[]) => any)): T;
570
+ addClient<T extends object>(peer: RpcPeer, defOrContract: RpcServiceDef | (AnyConstructor)): T;
551
571
  close(): void;
552
572
  /** Build an RpcServiceDef from decorator metadata on a contract class. Override in FusionHub for compute support. */
553
- protected _buildServiceDef(cls: abstract new (...args: any[]) => any): RpcServiceDef;
573
+ protected _buildServiceDef(cls: AnyConstructor): RpcServiceDef;
554
574
  /** Resolve a service def from either a plain RpcServiceDef or a contract class. */
555
- protected _resolveServiceDef(defOrContract: RpcServiceDef | (abstract new (...args: any[]) => any)): RpcServiceDef;
575
+ protected _resolveServiceDef(defOrContract: RpcServiceDef | (AnyConstructor)): RpcServiceDef;
556
576
  /** Override in FusionHub — default is pass-through (for methods with callTypeId !== 0). */
557
577
  protected _wrapServerMethod(_methodDef: RpcMethodDef, fn: (...args: unknown[]) => unknown, _impl: object): (...args: unknown[]) => unknown;
558
578
  /** Create a client method for the given methodDef. Override in FusionHub for custom call types. */
@@ -892,25 +912,6 @@ interface WebSocketServer {
892
912
  close(): void;
893
913
  }
894
914
 
895
- interface MethodMeta {
896
- argCount: number;
897
- returns?: symbol;
898
- [key: symbol]: unknown;
899
- }
900
- interface ServiceMeta {
901
- name: string;
902
- }
903
- /** Read method metadata from a decorated class. */
904
- declare function getMethodsMeta(cls: abstract new (...args: any[]) => any): Record<string, MethodMeta> | undefined;
905
- /** Read service metadata from a decorated class. */
906
- declare function getServiceMeta(cls: abstract new (...args: any[]) => any): ServiceMeta | undefined;
907
- /** Class decorator — stores the RPC service wire name. */
908
- declare function rpcService(serviceName: string): <T extends abstract new (...args: any[]) => any>(_target: T, context: ClassDecoratorContext<T>) => void;
909
- /** Method decorator — stores RPC method metadata (argCount, returns). Does NOT wrap the method. */
910
- declare function rpcMethod(options?: {
911
- returns?: symbol;
912
- }): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
913
-
914
915
  declare const enum RpcPeerStateKind {
915
916
  Connected = 0,
916
917
  JustDisconnected = 1,
package/dist/index.d.ts CHANGED
@@ -125,10 +125,10 @@ declare function deserializeBinaryMessage(data: Uint8Array, offset: number, deco
125
125
  * Accepts an optional `Decoder` for reuse across calls on the same
126
126
  * connection — forwarded to `deserializeBinaryMessage`.
127
127
  */
128
- declare function splitBinaryFrame(frame: Uint8Array, decoder?: Decoder): Array<{
128
+ declare function splitBinaryFrame(frame: Uint8Array, decoder?: Decoder): {
129
129
  message: RpcMessage;
130
130
  args: unknown[];
131
- }>;
131
+ }[];
132
132
  /**
133
133
  * Serializes multiple binary messages into a single WebSocket frame.
134
134
  * Simply concatenates the already size-prefixed messages.
@@ -158,10 +158,10 @@ declare function deserializeCompactBinaryMessage(data: Uint8Array, offset: numbe
158
158
  /**
159
159
  * Splits a compact binary frame into individual deserialized messages.
160
160
  */
161
- declare function splitCompactBinaryFrame(frame: Uint8Array, registry?: RpcMethodRegistry, decoder?: Decoder): Array<{
161
+ declare function splitCompactBinaryFrame(frame: Uint8Array, registry?: RpcMethodRegistry, decoder?: Decoder): {
162
162
  message: RpcMessage;
163
163
  args: unknown[];
164
- }>;
164
+ }[];
165
165
 
166
166
  /** Parsed inbound message — result of deserialization. */
167
167
  interface RpcDeserializedMessage {
@@ -465,7 +465,7 @@ declare class RpcClientPeerReconnectDelayer extends RetryDelayer {
465
465
  constructor();
466
466
  }
467
467
 
468
- type RpcServiceImpl = Record<string, (...args: unknown[]) => unknown>;
468
+ type RpcServiceImpl = Record<string, ((...args: unknown[]) => unknown) | undefined>;
469
469
  /** Context passed to service dispatch — carries callId and connection for compute tracking. */
470
470
  interface RpcDispatchContext {
471
471
  __rpcDispatch: true;
@@ -480,6 +480,26 @@ declare class RpcServiceHost {
480
480
  getMethodDef(wireMethod: string): RpcMethodDef | undefined;
481
481
  }
482
482
 
483
+ interface MethodMeta {
484
+ argCount: number;
485
+ returns?: symbol;
486
+ [key: symbol]: unknown;
487
+ }
488
+ interface ServiceMeta {
489
+ name: string;
490
+ }
491
+ type AnyConstructor = abstract new (...args: any[]) => any;
492
+ /** Read method metadata from a decorated class. */
493
+ declare function getMethodsMeta(cls: AnyConstructor): Record<string, MethodMeta> | undefined;
494
+ /** Read service metadata from a decorated class. */
495
+ declare function getServiceMeta(cls: AnyConstructor): ServiceMeta | undefined;
496
+ /** Class decorator — stores the RPC service wire name. */
497
+ declare function rpcService(serviceName: string): <T extends AnyConstructor>(_target: T, context: ClassDecoratorContext<T>) => void;
498
+ /** Method decorator — stores RPC method metadata (argCount, returns). Does NOT wrap the method. */
499
+ declare function rpcMethod(options?: {
500
+ returns?: symbol;
501
+ }): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
502
+
483
503
  /**
484
504
  * Sends system RPC messages — like .NET's RpcSystemCallSender.
485
505
  *
@@ -545,14 +565,14 @@ declare class RpcHub {
545
565
  /** Get or create a server peer for the given ref. */
546
566
  getServerPeer(ref: string): RpcServerPeer;
547
567
  /** Register a service with optional server method wrapping for custom call types. */
548
- addService(defOrContract: RpcServiceDef | (abstract new (...args: any[]) => any), impl: RpcServiceImpl): void;
568
+ addService(defOrContract: RpcServiceDef | (AnyConstructor), impl: RpcServiceImpl): void;
549
569
  /** Create a typed client proxy for a service on a remote peer. */
550
- addClient<T extends object>(peer: RpcPeer, defOrContract: RpcServiceDef | (abstract new (...args: any[]) => any)): T;
570
+ addClient<T extends object>(peer: RpcPeer, defOrContract: RpcServiceDef | (AnyConstructor)): T;
551
571
  close(): void;
552
572
  /** Build an RpcServiceDef from decorator metadata on a contract class. Override in FusionHub for compute support. */
553
- protected _buildServiceDef(cls: abstract new (...args: any[]) => any): RpcServiceDef;
573
+ protected _buildServiceDef(cls: AnyConstructor): RpcServiceDef;
554
574
  /** Resolve a service def from either a plain RpcServiceDef or a contract class. */
555
- protected _resolveServiceDef(defOrContract: RpcServiceDef | (abstract new (...args: any[]) => any)): RpcServiceDef;
575
+ protected _resolveServiceDef(defOrContract: RpcServiceDef | (AnyConstructor)): RpcServiceDef;
556
576
  /** Override in FusionHub — default is pass-through (for methods with callTypeId !== 0). */
557
577
  protected _wrapServerMethod(_methodDef: RpcMethodDef, fn: (...args: unknown[]) => unknown, _impl: object): (...args: unknown[]) => unknown;
558
578
  /** Create a client method for the given methodDef. Override in FusionHub for custom call types. */
@@ -892,25 +912,6 @@ interface WebSocketServer {
892
912
  close(): void;
893
913
  }
894
914
 
895
- interface MethodMeta {
896
- argCount: number;
897
- returns?: symbol;
898
- [key: symbol]: unknown;
899
- }
900
- interface ServiceMeta {
901
- name: string;
902
- }
903
- /** Read method metadata from a decorated class. */
904
- declare function getMethodsMeta(cls: abstract new (...args: any[]) => any): Record<string, MethodMeta> | undefined;
905
- /** Read service metadata from a decorated class. */
906
- declare function getServiceMeta(cls: abstract new (...args: any[]) => any): ServiceMeta | undefined;
907
- /** Class decorator — stores the RPC service wire name. */
908
- declare function rpcService(serviceName: string): <T extends abstract new (...args: any[]) => any>(_target: T, context: ClassDecoratorContext<T>) => void;
909
- /** Method decorator — stores RPC method metadata (argCount, returns). Does NOT wrap the method. */
910
- declare function rpcMethod(options?: {
911
- returns?: symbol;
912
- }): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
913
-
914
915
  declare const enum RpcPeerStateKind {
915
916
  Connected = 0,
916
917
  JustDisconnected = 1,
package/dist/index.js CHANGED
@@ -765,7 +765,7 @@ var RpcStreamSender = class _RpcStreamSender {
765
765
  await this._started.promise;
766
766
  const iterator = source[Symbol.asyncIterator]();
767
767
  try {
768
- while (true) {
768
+ for (; ; ) {
769
769
  const next = await iterator.next();
770
770
  if (next.done || this._ended) break;
771
771
  const item = next.value;
@@ -1051,30 +1051,29 @@ var RpcStream = class _RpcStream {
1051
1051
  if (this._iterating)
1052
1052
  throw new Error("RpcStream can only be iterated once.");
1053
1053
  this._iterating = true;
1054
- const self = this;
1055
1054
  return {
1056
- async next() {
1057
- if (!self._started) {
1058
- self._started = true;
1059
- self._sendAck(0, true);
1055
+ next: async () => {
1056
+ if (!this._started) {
1057
+ this._started = true;
1058
+ this._sendAck(0, true);
1060
1059
  }
1061
- while (true) {
1062
- if (!self._buffer.isEmpty()) {
1063
- const value = self._buffer.shift();
1060
+ for (; ; ) {
1061
+ if (!this._buffer.isEmpty()) {
1062
+ const value = this._buffer.shift();
1064
1063
  return { value, done: false };
1065
1064
  }
1066
- if (self._completed) {
1067
- if (self._completionError) throw self._completionError;
1065
+ if (this._completed) {
1066
+ if (this._completionError) throw this._completionError;
1068
1067
  return { value: void 0, done: true };
1069
1068
  }
1070
- self._consumerWaiting = new PromiseSource4();
1071
- await self._consumerWaiting.promise;
1069
+ this._consumerWaiting = new PromiseSource4();
1070
+ await this._consumerWaiting.promise;
1072
1071
  }
1073
1072
  },
1074
- async return() {
1075
- self._sendAckEnd();
1076
- self.dispose();
1077
- return { value: void 0, done: true };
1073
+ return: () => {
1074
+ this._sendAckEnd();
1075
+ this.dispose();
1076
+ return Promise.resolve({ value: void 0, done: true });
1078
1077
  }
1079
1078
  };
1080
1079
  }
@@ -1683,21 +1682,18 @@ var RpcPeer = class {
1683
1682
  }
1684
1683
  const signal = options?.signal;
1685
1684
  if (signal !== void 0) {
1686
- const peer = this;
1687
- const hub = this._hub;
1688
- const tracker = this.outbound;
1689
1685
  const onAbort = () => {
1690
- if (tracker.remove(callId) !== void 0) {
1686
+ if (this.outbound.remove(callId) !== void 0) {
1691
1687
  outboundCall.result.reject(new Error("Call cancelled."));
1692
1688
  outboundCall.onDisconnect();
1693
- if (peer._connection !== void 0)
1694
- hub.systemCallSender.cancel(peer._connection, peer.format, callId);
1689
+ if (this._connection !== void 0)
1690
+ this._hub.systemCallSender.cancel(this._connection, this.format, callId);
1695
1691
  } else {
1696
- const idx = peer._pendingSends.findIndex(
1692
+ const idx = this._pendingSends.findIndex(
1697
1693
  (c) => c.callId === callId
1698
1694
  );
1699
1695
  if (idx !== -1) {
1700
- peer._pendingSends.splice(idx, 1);
1696
+ this._pendingSends.splice(idx, 1);
1701
1697
  outboundCall.result.reject(
1702
1698
  new Error("Call cancelled.")
1703
1699
  );
@@ -1791,51 +1787,49 @@ var RpcPeer = class {
1791
1787
  this.inbound.register(call);
1792
1788
  }
1793
1789
  const serviceHost = this._hub.serviceHost;
1794
- if (serviceHost !== void 0) {
1795
- void (async () => {
1796
- try {
1797
- const context = this._connection !== void 0 ? {
1798
- __rpcDispatch: true,
1799
- callId: relatedId,
1800
- connection: this._connection
1801
- } : void 0;
1802
- const result = await serviceHost.dispatch(
1803
- method,
1804
- args,
1805
- context
1790
+ void (async () => {
1791
+ try {
1792
+ const context = this._connection !== void 0 ? {
1793
+ __rpcDispatch: true,
1794
+ callId: relatedId,
1795
+ connection: this._connection
1796
+ } : void 0;
1797
+ const result = await serviceHost.dispatch(
1798
+ method,
1799
+ args,
1800
+ context
1801
+ );
1802
+ if (methodDef?.stream === true && this._connection !== void 0) {
1803
+ const stream = result instanceof RpcStream ? result : new RpcStream(result);
1804
+ this._hub.systemCallSender.ok(
1805
+ this._connection,
1806
+ this.format,
1807
+ relatedId,
1808
+ stream.toRef(this)
1809
+ );
1810
+ } else if (!isNoWait && this._connection !== void 0) {
1811
+ this._hub.systemCallSender.ok(
1812
+ this._connection,
1813
+ this.format,
1814
+ relatedId,
1815
+ result
1806
1816
  );
1807
- if (methodDef?.stream === true && this._connection !== void 0) {
1808
- const stream = result instanceof RpcStream ? result : new RpcStream(result);
1809
- this._hub.systemCallSender.ok(
1810
- this._connection,
1811
- this.format,
1812
- relatedId,
1813
- stream.toRef(this)
1814
- );
1815
- } else if (!isNoWait && this._connection !== void 0) {
1816
- this._hub.systemCallSender.ok(
1817
- this._connection,
1818
- this.format,
1819
- relatedId,
1820
- result
1821
- );
1822
- }
1823
- } catch (e) {
1824
- if (!isNoWait && this._connection !== void 0) {
1825
- this._hub.systemCallSender.error(
1826
- this._connection,
1827
- this.format,
1828
- relatedId,
1829
- e
1830
- );
1831
- }
1832
- } finally {
1833
- if (!isNoWait) {
1834
- this.inbound.remove(relatedId);
1835
- }
1836
1817
  }
1837
- })();
1838
- }
1818
+ } catch (e) {
1819
+ if (!isNoWait && this._connection !== void 0) {
1820
+ this._hub.systemCallSender.error(
1821
+ this._connection,
1822
+ this.format,
1823
+ relatedId,
1824
+ e
1825
+ );
1826
+ }
1827
+ } finally {
1828
+ if (!isNoWait) {
1829
+ this.inbound.remove(relatedId);
1830
+ }
1831
+ }
1832
+ })();
1839
1833
  }
1840
1834
  _startKeepAlive() {
1841
1835
  this._keepAliveTimer = setInterval(() => {
@@ -2704,6 +2698,7 @@ var RpcHub = class {
2704
2698
  this.registry.registerService(def.name, def.methods);
2705
2699
  }
2706
2700
  /** Create a typed client proxy for a service on a remote peer. */
2701
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- T is used for caller-specified proxy type
2707
2702
  addClient(peer, defOrContract) {
2708
2703
  const def = this._resolveServiceDef(defOrContract);
2709
2704
  this.registry.registerService(def.name, def.methods);