@actuallab/rpc 12.2.23 → 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. */
@@ -734,29 +754,44 @@ interface RpcStreamRef {
734
754
  readonly allowReconnect: boolean;
735
755
  readonly isRealTime: boolean;
736
756
  }
757
+ /** Configuration options for creating a local (origin-side) RpcStream. */
758
+ interface RpcStreamOptions<T> {
759
+ ackPeriod?: number;
760
+ ackAdvance?: number;
761
+ allowReconnect?: boolean;
762
+ isRealTime?: boolean;
763
+ canSkipTo?: (item: T) => boolean;
764
+ }
737
765
  /**
738
766
  * Parses a stream reference string of the form "{hostId},{localId},{ackPeriod},{ackAdvance}".
739
767
  * Returns null if the value is not a valid stream reference.
740
768
  */
741
769
  declare function parseStreamRef(value: unknown): RpcStreamRef | null;
742
770
  /**
743
- * Client-side RPC stream — consumes items sent by the server via system calls
744
- * ($sys.I, $sys.B, $sys.End) and implements AsyncIterable<T> for for-await-of consumption.
771
+ * Dual-mode RPC stream — works as both local (origin-side) and remote (target-side).
745
772
  *
746
- * Wire protocol:
747
- * - Client sends Ack(0, hostId) to start the stream
748
- * - Server sends I (single item) / B (batch) messages
749
- * - Client acks every ackPeriod items for flow control
750
- * - Server sends End to signal completion (with optional error)
751
- * - Client sends AckEnd to acknowledge completion
773
+ * **Local mode**: wraps an AsyncIterable and carries streaming configuration
774
+ * (IsRealTime, CanSkipTo, etc.). Created by service methods and sent to the
775
+ * remote peer via RpcStreamSender.
776
+ *
777
+ * **Remote mode**: consumes items sent by the server via system calls
778
+ * ($sys.I, $sys.B, $sys.End) and implements AsyncIterable for for-await-of consumption.
779
+ *
780
+ * This mirrors the .NET RpcStream<T> design where the same type serves both roles.
752
781
  */
753
782
  declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
754
783
  readonly id: RpcObjectId;
755
- readonly kind: 1;
784
+ readonly kind: RpcObjectKind;
756
785
  readonly allowReconnect: boolean;
757
- readonly peer: RpcPeer;
786
+ readonly isRealTime: boolean;
787
+ readonly canSkipTo: (item: T) => boolean;
758
788
  readonly ackPeriod: number;
759
789
  readonly ackAdvance: number;
790
+ readonly localSource?: AsyncIterable<T>;
791
+ readonly peer: RpcPeer;
792
+ private _sender?;
793
+ private _toRefValue?;
794
+ private _whenSent?;
760
795
  private _buffer;
761
796
  private _nextExpectedIndex;
762
797
  private _consumerWaiting;
@@ -766,7 +801,27 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
766
801
  private _started;
767
802
  private _iterating;
768
803
  private _ackSentUpTo;
804
+ /** Create a local (origin-side) stream wrapping an async iterable with optional configuration. */
805
+ constructor(source: AsyncIterable<T>, options?: RpcStreamOptions<T>);
806
+ /** Create a remote (target-side) stream from a parsed stream reference and peer. */
769
807
  constructor(ref: RpcStreamRef, peer: RpcPeer);
808
+ /**
809
+ * For local streams: resolves when the sender finishes pumping (after `toRef()` was called).
810
+ * Rejects if the source throws. Throws if `toRef()` hasn't been called yet.
811
+ */
812
+ get whenSent(): Promise<void>;
813
+ /**
814
+ * For local streams: bind to a peer, create and register an `RpcStreamSender`,
815
+ * start pumping items from the local source in the background, and return the
816
+ * stream reference.
817
+ *
818
+ * For binary peers the ref is a MessagePack-compatible object
819
+ * (`{ SerializedId, AckPeriod, AckAdvance, AllowReconnect }`);
820
+ * for text peers it is a comma-separated string.
821
+ *
822
+ * Can only be called once per stream.
823
+ */
824
+ toRef(peer: RpcPeer): unknown;
770
825
  /** Called by system call handler when a single item arrives ($sys.I). */
771
826
  onItem(index: number, item: T): void;
772
827
  /** Called by system call handler when a batch arrives ($sys.B). */
@@ -804,6 +859,7 @@ declare function resolveStreamRefs(value: unknown, peer: RpcPeer): unknown;
804
859
  * - Client sends AckEnd to acknowledge completion
805
860
  */
806
861
  declare class RpcStreamSender<T> implements IRpcObject {
862
+ private static readonly _emptyGuid;
807
863
  readonly id: RpcObjectId;
808
864
  readonly kind: 0;
809
865
  readonly allowReconnect: boolean;
@@ -817,11 +873,12 @@ declare class RpcStreamSender<T> implements IRpcObject {
817
873
  private _started;
818
874
  private _lastAckedIndex;
819
875
  private _ackWaiting;
876
+ private _resetRequested;
820
877
  constructor(peer: RpcPeer, ackPeriod?: number, ackAdvance?: number, allowReconnect?: boolean, isRealTime?: boolean, canSkipTo?: (item: T) => boolean);
821
878
  /** Returns the stream reference string for the $sys.Ok response. */
822
879
  toRef(): string;
823
880
  /** Called by system call handler when $sys.Ack is received from the client. */
824
- onAck(nextIndex: number, _hostId: string): void;
881
+ onAck(nextIndex: number, hostId: string): void;
825
882
  /** Called by system call handler when $sys.AckEnd is received from the client. */
826
883
  onAckEnd(_hostId: string): void;
827
884
  /** Send a single item to the client. */
@@ -855,25 +912,6 @@ interface WebSocketServer {
855
912
  close(): void;
856
913
  }
857
914
 
858
- interface MethodMeta {
859
- argCount: number;
860
- returns?: symbol;
861
- [key: symbol]: unknown;
862
- }
863
- interface ServiceMeta {
864
- name: string;
865
- }
866
- /** Read method metadata from a decorated class. */
867
- declare function getMethodsMeta(cls: abstract new (...args: any[]) => any): Record<string, MethodMeta> | undefined;
868
- /** Read service metadata from a decorated class. */
869
- declare function getServiceMeta(cls: abstract new (...args: any[]) => any): ServiceMeta | undefined;
870
- /** Class decorator — stores the RPC service wire name. */
871
- declare function rpcService(serviceName: string): <T extends abstract new (...args: any[]) => any>(_target: T, context: ClassDecoratorContext<T>) => void;
872
- /** Method decorator — stores RPC method metadata (argCount, returns). Does NOT wrap the method. */
873
- declare function rpcMethod(options?: {
874
- returns?: symbol;
875
- }): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
876
-
877
915
  declare const enum RpcPeerStateKind {
878
916
  Connected = 0,
879
917
  JustDisconnected = 1,
@@ -930,4 +968,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
930
968
  */
931
969
  declare function computeMethodHash(methodName: string): number;
932
970
 
933
- export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, RpcPeerConnectionKind, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamRef, RpcStreamSender, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
971
+ export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, RpcPeerConnectionKind, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamOptions, type RpcStreamRef, RpcStreamSender, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
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. */
@@ -734,29 +754,44 @@ interface RpcStreamRef {
734
754
  readonly allowReconnect: boolean;
735
755
  readonly isRealTime: boolean;
736
756
  }
757
+ /** Configuration options for creating a local (origin-side) RpcStream. */
758
+ interface RpcStreamOptions<T> {
759
+ ackPeriod?: number;
760
+ ackAdvance?: number;
761
+ allowReconnect?: boolean;
762
+ isRealTime?: boolean;
763
+ canSkipTo?: (item: T) => boolean;
764
+ }
737
765
  /**
738
766
  * Parses a stream reference string of the form "{hostId},{localId},{ackPeriod},{ackAdvance}".
739
767
  * Returns null if the value is not a valid stream reference.
740
768
  */
741
769
  declare function parseStreamRef(value: unknown): RpcStreamRef | null;
742
770
  /**
743
- * Client-side RPC stream — consumes items sent by the server via system calls
744
- * ($sys.I, $sys.B, $sys.End) and implements AsyncIterable<T> for for-await-of consumption.
771
+ * Dual-mode RPC stream — works as both local (origin-side) and remote (target-side).
745
772
  *
746
- * Wire protocol:
747
- * - Client sends Ack(0, hostId) to start the stream
748
- * - Server sends I (single item) / B (batch) messages
749
- * - Client acks every ackPeriod items for flow control
750
- * - Server sends End to signal completion (with optional error)
751
- * - Client sends AckEnd to acknowledge completion
773
+ * **Local mode**: wraps an AsyncIterable and carries streaming configuration
774
+ * (IsRealTime, CanSkipTo, etc.). Created by service methods and sent to the
775
+ * remote peer via RpcStreamSender.
776
+ *
777
+ * **Remote mode**: consumes items sent by the server via system calls
778
+ * ($sys.I, $sys.B, $sys.End) and implements AsyncIterable for for-await-of consumption.
779
+ *
780
+ * This mirrors the .NET RpcStream<T> design where the same type serves both roles.
752
781
  */
753
782
  declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
754
783
  readonly id: RpcObjectId;
755
- readonly kind: 1;
784
+ readonly kind: RpcObjectKind;
756
785
  readonly allowReconnect: boolean;
757
- readonly peer: RpcPeer;
786
+ readonly isRealTime: boolean;
787
+ readonly canSkipTo: (item: T) => boolean;
758
788
  readonly ackPeriod: number;
759
789
  readonly ackAdvance: number;
790
+ readonly localSource?: AsyncIterable<T>;
791
+ readonly peer: RpcPeer;
792
+ private _sender?;
793
+ private _toRefValue?;
794
+ private _whenSent?;
760
795
  private _buffer;
761
796
  private _nextExpectedIndex;
762
797
  private _consumerWaiting;
@@ -766,7 +801,27 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
766
801
  private _started;
767
802
  private _iterating;
768
803
  private _ackSentUpTo;
804
+ /** Create a local (origin-side) stream wrapping an async iterable with optional configuration. */
805
+ constructor(source: AsyncIterable<T>, options?: RpcStreamOptions<T>);
806
+ /** Create a remote (target-side) stream from a parsed stream reference and peer. */
769
807
  constructor(ref: RpcStreamRef, peer: RpcPeer);
808
+ /**
809
+ * For local streams: resolves when the sender finishes pumping (after `toRef()` was called).
810
+ * Rejects if the source throws. Throws if `toRef()` hasn't been called yet.
811
+ */
812
+ get whenSent(): Promise<void>;
813
+ /**
814
+ * For local streams: bind to a peer, create and register an `RpcStreamSender`,
815
+ * start pumping items from the local source in the background, and return the
816
+ * stream reference.
817
+ *
818
+ * For binary peers the ref is a MessagePack-compatible object
819
+ * (`{ SerializedId, AckPeriod, AckAdvance, AllowReconnect }`);
820
+ * for text peers it is a comma-separated string.
821
+ *
822
+ * Can only be called once per stream.
823
+ */
824
+ toRef(peer: RpcPeer): unknown;
770
825
  /** Called by system call handler when a single item arrives ($sys.I). */
771
826
  onItem(index: number, item: T): void;
772
827
  /** Called by system call handler when a batch arrives ($sys.B). */
@@ -804,6 +859,7 @@ declare function resolveStreamRefs(value: unknown, peer: RpcPeer): unknown;
804
859
  * - Client sends AckEnd to acknowledge completion
805
860
  */
806
861
  declare class RpcStreamSender<T> implements IRpcObject {
862
+ private static readonly _emptyGuid;
807
863
  readonly id: RpcObjectId;
808
864
  readonly kind: 0;
809
865
  readonly allowReconnect: boolean;
@@ -817,11 +873,12 @@ declare class RpcStreamSender<T> implements IRpcObject {
817
873
  private _started;
818
874
  private _lastAckedIndex;
819
875
  private _ackWaiting;
876
+ private _resetRequested;
820
877
  constructor(peer: RpcPeer, ackPeriod?: number, ackAdvance?: number, allowReconnect?: boolean, isRealTime?: boolean, canSkipTo?: (item: T) => boolean);
821
878
  /** Returns the stream reference string for the $sys.Ok response. */
822
879
  toRef(): string;
823
880
  /** Called by system call handler when $sys.Ack is received from the client. */
824
- onAck(nextIndex: number, _hostId: string): void;
881
+ onAck(nextIndex: number, hostId: string): void;
825
882
  /** Called by system call handler when $sys.AckEnd is received from the client. */
826
883
  onAckEnd(_hostId: string): void;
827
884
  /** Send a single item to the client. */
@@ -855,25 +912,6 @@ interface WebSocketServer {
855
912
  close(): void;
856
913
  }
857
914
 
858
- interface MethodMeta {
859
- argCount: number;
860
- returns?: symbol;
861
- [key: symbol]: unknown;
862
- }
863
- interface ServiceMeta {
864
- name: string;
865
- }
866
- /** Read method metadata from a decorated class. */
867
- declare function getMethodsMeta(cls: abstract new (...args: any[]) => any): Record<string, MethodMeta> | undefined;
868
- /** Read service metadata from a decorated class. */
869
- declare function getServiceMeta(cls: abstract new (...args: any[]) => any): ServiceMeta | undefined;
870
- /** Class decorator — stores the RPC service wire name. */
871
- declare function rpcService(serviceName: string): <T extends abstract new (...args: any[]) => any>(_target: T, context: ClassDecoratorContext<T>) => void;
872
- /** Method decorator — stores RPC method metadata (argCount, returns). Does NOT wrap the method. */
873
- declare function rpcMethod(options?: {
874
- returns?: symbol;
875
- }): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
876
-
877
915
  declare const enum RpcPeerStateKind {
878
916
  Connected = 0,
879
917
  JustDisconnected = 1,
@@ -930,4 +968,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
930
968
  */
931
969
  declare function computeMethodHash(methodName: string): number;
932
970
 
933
- export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, RpcPeerConnectionKind, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamRef, RpcStreamSender, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
971
+ export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, RpcPeerConnectionKind, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamOptions, type RpcStreamRef, RpcStreamSender, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };