@super-line/core 0.3.0 → 0.4.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.
- package/dist/index.d.cts +92 -3
- package/dist/index.d.ts +92 -3
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -78,6 +78,11 @@ interface ConnDescriptor {
|
|
|
78
78
|
userId?: string;
|
|
79
79
|
/** Room memberships (topics and node-local `lastPongAt` are not included). */
|
|
80
80
|
rooms: string[];
|
|
81
|
+
/**
|
|
82
|
+
* The client↔server transport (wire) this connection was accepted on:
|
|
83
|
+
* `'websocket' | 'sse' | 'longpoll' | 'libp2p' | 'loopback'`. Absent on conns from older nodes.
|
|
84
|
+
*/
|
|
85
|
+
transport?: string;
|
|
81
86
|
/** Extra fields contributed by the server's `describeConn` hook. */
|
|
82
87
|
[extra: string]: unknown;
|
|
83
88
|
}
|
|
@@ -498,7 +503,13 @@ interface SErrFrame {
|
|
|
498
503
|
m: string;
|
|
499
504
|
d?: unknown;
|
|
500
505
|
}
|
|
501
|
-
|
|
506
|
+
interface PingFrame {
|
|
507
|
+
t: 'ping';
|
|
508
|
+
}
|
|
509
|
+
interface PongFrame {
|
|
510
|
+
t: 'pong';
|
|
511
|
+
}
|
|
512
|
+
type ClientFrame = ReqFrame | SubFrame | UnsubFrame | SResFrame | SErrFrame | PingFrame | PongFrame;
|
|
502
513
|
interface ResFrame {
|
|
503
514
|
t: 'res';
|
|
504
515
|
i: number;
|
|
@@ -528,7 +539,85 @@ interface SReqFrame {
|
|
|
528
539
|
m: string;
|
|
529
540
|
d: unknown;
|
|
530
541
|
}
|
|
531
|
-
type ServerFrame = ResFrame | ErrFrame | EvtFrame | PubFrame | SReqFrame;
|
|
542
|
+
type ServerFrame = ResFrame | ErrFrame | EvtFrame | PubFrame | SReqFrame | PingFrame | PongFrame;
|
|
532
543
|
type Frame = ClientFrame | ServerFrame;
|
|
533
544
|
|
|
534
|
-
|
|
545
|
+
/**
|
|
546
|
+
* The client↔server transport seam. A transport moves opaque encoded bytes over a
|
|
547
|
+
* LOGICAL connection and hides all physical churn (reconnects, SSE's dual channel,
|
|
548
|
+
* libp2p signaling). The serializer and the frame protocol stay in core, above the
|
|
549
|
+
* transport — a transport never inspects a frame, it only carries bytes.
|
|
550
|
+
*/
|
|
551
|
+
/** A live logical connection, from the core's point of view. Symmetric across server + client. */
|
|
552
|
+
interface RawConn {
|
|
553
|
+
/** Send already-encoded bytes. A no-op when not {@link RawConn.writable}. */
|
|
554
|
+
send(bytes: string | Uint8Array): void;
|
|
555
|
+
/** Whether a send will be accepted now (WS derives this from `readyState` + `bufferedAmount`). */
|
|
556
|
+
readonly writable: boolean;
|
|
557
|
+
/** Register the handler for inbound frames. The transport MUST normalize each to a `Uint8Array`. */
|
|
558
|
+
onMessage(cb: (bytes: Uint8Array) => void): void;
|
|
559
|
+
/** The logical connection died. `code` is best-effort (1000 graceful / 1006 abnormal when the transport has none). */
|
|
560
|
+
onClose(cb: (code: number, reason?: string) => void): void;
|
|
561
|
+
/** The send buffer drained below the limit — safe to resume sending. */
|
|
562
|
+
onDrain(cb: () => void): void;
|
|
563
|
+
/** Graceful close (close handshake when the transport has one). */
|
|
564
|
+
close(code?: number, reason?: string): void;
|
|
565
|
+
/** Hard close with no handshake — used by heartbeat reaping. */
|
|
566
|
+
terminate(): void;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* The normalized handshake handed to `authenticate`, replacing the raw `IncomingMessage`.
|
|
570
|
+
* Each transport fills what it has: ws/sse populate `headers`/`query`; libp2p/webrtc
|
|
571
|
+
* populate `peer`. `raw` is the transport-specific escape hatch.
|
|
572
|
+
*/
|
|
573
|
+
interface Handshake {
|
|
574
|
+
/** Transport id, e.g. `'websocket'` | `'loopback'` | `'sse'` | `'libp2p'`. */
|
|
575
|
+
transport: string;
|
|
576
|
+
/** Request headers (ws/sse fill these; peer transports leave them sparse). */
|
|
577
|
+
headers: Record<string, string | string[] | undefined>;
|
|
578
|
+
/** Role + params, decoded uniformly (WS reads them from the URL query string). */
|
|
579
|
+
query: Record<string, string>;
|
|
580
|
+
/** Peer identity, for transports that authenticate one (libp2p/webrtc). */
|
|
581
|
+
peer?: {
|
|
582
|
+
id: string;
|
|
583
|
+
addr?: string;
|
|
584
|
+
};
|
|
585
|
+
/** Escape hatch: the `IncomingMessage` for WS, the signaling payload for libp2p, etc. */
|
|
586
|
+
raw: unknown;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* What `authenticate` returns. Reject by throwing — the transport then rejects in its native idiom.
|
|
590
|
+
* `transport` is injected by the server (from {@link Handshake.transport}); user `authenticate`
|
|
591
|
+
* callbacks return only `role` + `ctx`.
|
|
592
|
+
*/
|
|
593
|
+
type AuthOutcome = {
|
|
594
|
+
role: string;
|
|
595
|
+
ctx: unknown;
|
|
596
|
+
transport?: string;
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
599
|
+
* Server side: the transport listens, authenticates each inbound connection at its
|
|
600
|
+
* native moment, and surfaces only the accepted ones — so the core never holds an
|
|
601
|
+
* unauthenticated connection.
|
|
602
|
+
*/
|
|
603
|
+
interface ServerTransport {
|
|
604
|
+
start(hooks: {
|
|
605
|
+
/** Core owns the decision; the transport calls this at its native auth point and rejects natively on throw. */
|
|
606
|
+
authenticate: (h: Handshake) => Promise<AuthOutcome>;
|
|
607
|
+
/** Fires ONLY for accepted connections. */
|
|
608
|
+
onConnection: (raw: RawConn, auth: AuthOutcome) => void;
|
|
609
|
+
}): void | Promise<void>;
|
|
610
|
+
/** Stop listening and drop in-flight connections. */
|
|
611
|
+
stop(): void | Promise<void>;
|
|
612
|
+
}
|
|
613
|
+
/** Client side: dial the server, encoding `handshakeParams` (role + params) in the transport's native form. */
|
|
614
|
+
interface ClientTransport {
|
|
615
|
+
connect(handshakeParams: Record<string, string>, hooks: {
|
|
616
|
+
onOpen(): void;
|
|
617
|
+
onMessage(bytes: Uint8Array): void;
|
|
618
|
+
onClose(code: number): void;
|
|
619
|
+
onDrain(): void;
|
|
620
|
+
}): RawConn;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export { type Adapter, type AnyData, type AuthOutcome, type ClientFrame, type ClientInput, type ClientTransport, type ConnDescriptor, type ConnView, type Contract, type DataOf, type Directional, type EmitData, type ErrFrame, type ErrorCode, type EventData, type Events, type EvtFrame, type Frame, type Handshake, INSPECTOR_ROLE, INSPECTOR_SUBPROTOCOL, type InferIn, type InferOut, type InspectedContract, type InspectedDirectional, type InspectedMessage, InspectorContract, type InspectorEvent, type MessageFlavor, type NodeStat, type NodeView, type Output, PROTOCOL, type PingFrame, type PongFrame, type PresenceStore, type PubFrame, type RawConn, type ReqFrame, type RequestDef, type Requests, type ResFrame, type RoleBlock, type RoleOf, type RoleRequests, type RoleTopics, type SErrFrame, type SReqFrame, type SResFrame, type Schema, type SchemaConverter, type Serializer, type ServerEntry, type ServerFrame, type ServerInput, type ServerMessageDef, type ServerMessages, type ServerRequestDef, type ServerRequests, type ServerTransport, type SharedEvents, type SharedRequests, type SharedServerRequests, type SharedTopics, type SubFrame, SuperLineError, type SuperLineErrorCode, type Topics, type UnsubFrame, classifyContract, defineContract, jsonSerializer, validate, validateSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,11 @@ interface ConnDescriptor {
|
|
|
78
78
|
userId?: string;
|
|
79
79
|
/** Room memberships (topics and node-local `lastPongAt` are not included). */
|
|
80
80
|
rooms: string[];
|
|
81
|
+
/**
|
|
82
|
+
* The client↔server transport (wire) this connection was accepted on:
|
|
83
|
+
* `'websocket' | 'sse' | 'longpoll' | 'libp2p' | 'loopback'`. Absent on conns from older nodes.
|
|
84
|
+
*/
|
|
85
|
+
transport?: string;
|
|
81
86
|
/** Extra fields contributed by the server's `describeConn` hook. */
|
|
82
87
|
[extra: string]: unknown;
|
|
83
88
|
}
|
|
@@ -498,7 +503,13 @@ interface SErrFrame {
|
|
|
498
503
|
m: string;
|
|
499
504
|
d?: unknown;
|
|
500
505
|
}
|
|
501
|
-
|
|
506
|
+
interface PingFrame {
|
|
507
|
+
t: 'ping';
|
|
508
|
+
}
|
|
509
|
+
interface PongFrame {
|
|
510
|
+
t: 'pong';
|
|
511
|
+
}
|
|
512
|
+
type ClientFrame = ReqFrame | SubFrame | UnsubFrame | SResFrame | SErrFrame | PingFrame | PongFrame;
|
|
502
513
|
interface ResFrame {
|
|
503
514
|
t: 'res';
|
|
504
515
|
i: number;
|
|
@@ -528,7 +539,85 @@ interface SReqFrame {
|
|
|
528
539
|
m: string;
|
|
529
540
|
d: unknown;
|
|
530
541
|
}
|
|
531
|
-
type ServerFrame = ResFrame | ErrFrame | EvtFrame | PubFrame | SReqFrame;
|
|
542
|
+
type ServerFrame = ResFrame | ErrFrame | EvtFrame | PubFrame | SReqFrame | PingFrame | PongFrame;
|
|
532
543
|
type Frame = ClientFrame | ServerFrame;
|
|
533
544
|
|
|
534
|
-
|
|
545
|
+
/**
|
|
546
|
+
* The client↔server transport seam. A transport moves opaque encoded bytes over a
|
|
547
|
+
* LOGICAL connection and hides all physical churn (reconnects, SSE's dual channel,
|
|
548
|
+
* libp2p signaling). The serializer and the frame protocol stay in core, above the
|
|
549
|
+
* transport — a transport never inspects a frame, it only carries bytes.
|
|
550
|
+
*/
|
|
551
|
+
/** A live logical connection, from the core's point of view. Symmetric across server + client. */
|
|
552
|
+
interface RawConn {
|
|
553
|
+
/** Send already-encoded bytes. A no-op when not {@link RawConn.writable}. */
|
|
554
|
+
send(bytes: string | Uint8Array): void;
|
|
555
|
+
/** Whether a send will be accepted now (WS derives this from `readyState` + `bufferedAmount`). */
|
|
556
|
+
readonly writable: boolean;
|
|
557
|
+
/** Register the handler for inbound frames. The transport MUST normalize each to a `Uint8Array`. */
|
|
558
|
+
onMessage(cb: (bytes: Uint8Array) => void): void;
|
|
559
|
+
/** The logical connection died. `code` is best-effort (1000 graceful / 1006 abnormal when the transport has none). */
|
|
560
|
+
onClose(cb: (code: number, reason?: string) => void): void;
|
|
561
|
+
/** The send buffer drained below the limit — safe to resume sending. */
|
|
562
|
+
onDrain(cb: () => void): void;
|
|
563
|
+
/** Graceful close (close handshake when the transport has one). */
|
|
564
|
+
close(code?: number, reason?: string): void;
|
|
565
|
+
/** Hard close with no handshake — used by heartbeat reaping. */
|
|
566
|
+
terminate(): void;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* The normalized handshake handed to `authenticate`, replacing the raw `IncomingMessage`.
|
|
570
|
+
* Each transport fills what it has: ws/sse populate `headers`/`query`; libp2p/webrtc
|
|
571
|
+
* populate `peer`. `raw` is the transport-specific escape hatch.
|
|
572
|
+
*/
|
|
573
|
+
interface Handshake {
|
|
574
|
+
/** Transport id, e.g. `'websocket'` | `'loopback'` | `'sse'` | `'libp2p'`. */
|
|
575
|
+
transport: string;
|
|
576
|
+
/** Request headers (ws/sse fill these; peer transports leave them sparse). */
|
|
577
|
+
headers: Record<string, string | string[] | undefined>;
|
|
578
|
+
/** Role + params, decoded uniformly (WS reads them from the URL query string). */
|
|
579
|
+
query: Record<string, string>;
|
|
580
|
+
/** Peer identity, for transports that authenticate one (libp2p/webrtc). */
|
|
581
|
+
peer?: {
|
|
582
|
+
id: string;
|
|
583
|
+
addr?: string;
|
|
584
|
+
};
|
|
585
|
+
/** Escape hatch: the `IncomingMessage` for WS, the signaling payload for libp2p, etc. */
|
|
586
|
+
raw: unknown;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* What `authenticate` returns. Reject by throwing — the transport then rejects in its native idiom.
|
|
590
|
+
* `transport` is injected by the server (from {@link Handshake.transport}); user `authenticate`
|
|
591
|
+
* callbacks return only `role` + `ctx`.
|
|
592
|
+
*/
|
|
593
|
+
type AuthOutcome = {
|
|
594
|
+
role: string;
|
|
595
|
+
ctx: unknown;
|
|
596
|
+
transport?: string;
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
599
|
+
* Server side: the transport listens, authenticates each inbound connection at its
|
|
600
|
+
* native moment, and surfaces only the accepted ones — so the core never holds an
|
|
601
|
+
* unauthenticated connection.
|
|
602
|
+
*/
|
|
603
|
+
interface ServerTransport {
|
|
604
|
+
start(hooks: {
|
|
605
|
+
/** Core owns the decision; the transport calls this at its native auth point and rejects natively on throw. */
|
|
606
|
+
authenticate: (h: Handshake) => Promise<AuthOutcome>;
|
|
607
|
+
/** Fires ONLY for accepted connections. */
|
|
608
|
+
onConnection: (raw: RawConn, auth: AuthOutcome) => void;
|
|
609
|
+
}): void | Promise<void>;
|
|
610
|
+
/** Stop listening and drop in-flight connections. */
|
|
611
|
+
stop(): void | Promise<void>;
|
|
612
|
+
}
|
|
613
|
+
/** Client side: dial the server, encoding `handshakeParams` (role + params) in the transport's native form. */
|
|
614
|
+
interface ClientTransport {
|
|
615
|
+
connect(handshakeParams: Record<string, string>, hooks: {
|
|
616
|
+
onOpen(): void;
|
|
617
|
+
onMessage(bytes: Uint8Array): void;
|
|
618
|
+
onClose(code: number): void;
|
|
619
|
+
onDrain(): void;
|
|
620
|
+
}): RawConn;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export { type Adapter, type AnyData, type AuthOutcome, type ClientFrame, type ClientInput, type ClientTransport, type ConnDescriptor, type ConnView, type Contract, type DataOf, type Directional, type EmitData, type ErrFrame, type ErrorCode, type EventData, type Events, type EvtFrame, type Frame, type Handshake, INSPECTOR_ROLE, INSPECTOR_SUBPROTOCOL, type InferIn, type InferOut, type InspectedContract, type InspectedDirectional, type InspectedMessage, InspectorContract, type InspectorEvent, type MessageFlavor, type NodeStat, type NodeView, type Output, PROTOCOL, type PingFrame, type PongFrame, type PresenceStore, type PubFrame, type RawConn, type ReqFrame, type RequestDef, type Requests, type ResFrame, type RoleBlock, type RoleOf, type RoleRequests, type RoleTopics, type SErrFrame, type SReqFrame, type SResFrame, type Schema, type SchemaConverter, type Serializer, type ServerEntry, type ServerFrame, type ServerInput, type ServerMessageDef, type ServerMessages, type ServerRequestDef, type ServerRequests, type ServerTransport, type SharedEvents, type SharedRequests, type SharedServerRequests, type SharedTopics, type SubFrame, SuperLineError, type SuperLineErrorCode, type Topics, type UnsubFrame, classifyContract, defineContract, jsonSerializer, validate, validateSync };
|