@kyneta/sse-transport 1.3.1 → 1.5.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/README.md CHANGED
@@ -192,7 +192,7 @@ Both directions use the `@kyneta/wire` text pipeline — symmetric encoding with
192
192
  Every message is wrapped in a text frame — a JSON array with a 2-character prefix:
193
193
 
194
194
  ```/dev/null/text-frame-example.txt#L1-5
195
- Complete frame: ["0c", {"type":"discover","docIds":["doc-1"]}]
195
+ Complete frame: ["0c", {"type":"present","docs":[{"docId":"doc-1"}]}]
196
196
  Fragment frame: ["0f", "a1b2c3d4", 0, 3, 1500, "{\"type\":\"offer\"..."]
197
197
  ```
198
198
 
package/dist/client.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { StateTransition, TransitionListener, Program } from '@kyneta/machine';
2
- export { StateTransition, TransitionListener } from '@kyneta/machine';
3
- import { PeerId, Transport, GeneratedChannel, TransportFactory, ReconnectOptions } from '@kyneta/transport';
4
- import { b as SseClientLifecycleEvents, c as SseClientState } from './types-DaVaqfwF.js';
5
- export { D as DisconnectReason } from './types-DaVaqfwF.js';
1
+ import { n as SseClientLifecycleEvents, r as SseClientState, t as DisconnectReason } from "./types-Bg1SdZ2w.js";
2
+ import { Program, StateTransition, StateTransition as StateTransition$1, TransitionListener, TransitionListener as TransitionListener$1 } from "@kyneta/machine";
3
+ import { GeneratedChannel, PeerId, ReconnectOptions, Transport, TransportFactory } from "@kyneta/transport";
6
4
 
5
+ //#region src/client-transport.d.ts
7
6
  /**
8
7
  * Default fragment threshold in characters.
9
8
  * 60K chars provides a safety margin below typical 100KB body-parser limits,
@@ -14,32 +13,32 @@ declare const DEFAULT_FRAGMENT_THRESHOLD = 60000;
14
13
  * Options for the SSE client adapter.
15
14
  */
16
15
  interface SseClientOptions {
17
- /** URL for POST requests (client→server). String or function of peerId. */
18
- postUrl: string | ((peerId: PeerId) => string);
19
- /** URL for SSE EventSource (server→client). String or function of peerId. */
20
- eventSourceUrl: string | ((peerId: PeerId) => string);
21
- /** Reconnection options for EventSource. */
22
- reconnect?: {
23
- enabled?: boolean;
24
- maxAttempts?: number;
25
- baseDelay?: number;
26
- maxDelay?: number;
27
- };
28
- /** POST retry options. */
29
- postRetry?: {
30
- maxAttempts?: number;
31
- baseDelay?: number;
32
- maxDelay?: number;
33
- };
34
- /** Fragment threshold in characters. Default: 60000 (60K chars). */
35
- fragmentThreshold?: number;
36
- /** Lifecycle event callbacks. */
37
- lifecycle?: SseClientLifecycleEvents;
16
+ /** URL for POST requests (client→server). String or function of peerId. */
17
+ postUrl: string | ((peerId: PeerId) => string);
18
+ /** URL for SSE EventSource (server→client). String or function of peerId. */
19
+ eventSourceUrl: string | ((peerId: PeerId) => string);
20
+ /** Reconnection options for EventSource. */
21
+ reconnect?: {
22
+ enabled?: boolean;
23
+ maxAttempts?: number;
24
+ baseDelay?: number;
25
+ maxDelay?: number;
26
+ };
27
+ /** POST retry options. */
28
+ postRetry?: {
29
+ maxAttempts?: number;
30
+ baseDelay?: number;
31
+ maxDelay?: number;
32
+ };
33
+ /** Fragment threshold in characters. Default: 60000 (60K chars). */
34
+ fragmentThreshold?: number;
35
+ /** Lifecycle event callbacks. */
36
+ lifecycle?: SseClientLifecycleEvents;
38
37
  }
39
38
  /**
40
39
  * State transition event for SSE client states.
41
40
  */
42
- type SseClientStateTransition = StateTransition<SseClientState>;
41
+ type SseClientStateTransition = StateTransition$1<SseClientState>;
43
42
  /**
44
43
  * SSE client network adapter for @kyneta/exchange.
45
44
  *
@@ -47,7 +46,7 @@ type SseClientStateTransition = StateTransition<SseClientState>;
47
46
  * - **EventSource** (GET, long-lived) for server→client messages
48
47
  * - **fetch POST** for client→server messages
49
48
  *
50
- * Both directions use the text wire format (`textCodec` + text framing).
49
+ * Both directions use the alias-aware text pipeline.
51
50
  *
52
51
  * Internally, the connection lifecycle is a `Program<Msg, Model, Fx>` —
53
52
  * a pure Mealy machine whose transitions are deterministically testable.
@@ -58,7 +57,7 @@ type SseClientStateTransition = StateTransition<SseClientState>;
58
57
  * import { createSseClient } from "@kyneta/sse-transport/client"
59
58
  *
60
59
  * const exchange = new Exchange({
61
- * identity: { peerId: "browser-client" },
60
+ * id: "browser-client",
62
61
  * transports: [createSseClient({
63
62
  * postUrl: "/sync",
64
63
  * eventSourceUrl: (peerId) => `/events?peerId=${peerId}`,
@@ -68,35 +67,35 @@ type SseClientStateTransition = StateTransition<SseClientState>;
68
67
  * ```
69
68
  */
70
69
  declare class SseClientTransport extends Transport<void> {
71
- #private;
72
- constructor(options: SseClientOptions);
73
- /**
74
- * Get the current connection state.
75
- */
76
- getState(): SseClientState;
77
- /**
78
- * Subscribe to state transitions.
79
- */
80
- subscribeToTransitions(listener: TransitionListener<SseClientState>): () => void;
81
- /**
82
- * Wait for a specific state.
83
- */
84
- waitForState(predicate: (state: SseClientState) => boolean, options?: {
85
- timeoutMs?: number;
86
- }): Promise<SseClientState>;
87
- /**
88
- * Wait for a specific status.
89
- */
90
- waitForStatus(status: SseClientState["status"], options?: {
91
- timeoutMs?: number;
92
- }): Promise<SseClientState>;
93
- /**
94
- * Whether the client is connected and ready to send/receive.
95
- */
96
- get isConnected(): boolean;
97
- protected generate(): GeneratedChannel;
98
- onStart(): Promise<void>;
99
- onStop(): Promise<void>;
70
+ #private;
71
+ constructor(options: SseClientOptions);
72
+ /**
73
+ * Get the current connection state.
74
+ */
75
+ getState(): SseClientState;
76
+ /**
77
+ * Subscribe to state transitions.
78
+ */
79
+ subscribeToTransitions(listener: TransitionListener$1<SseClientState>): () => void;
80
+ /**
81
+ * Wait for a specific state.
82
+ */
83
+ waitForState(predicate: (state: SseClientState) => boolean, options?: {
84
+ timeoutMs?: number;
85
+ }): Promise<SseClientState>;
86
+ /**
87
+ * Wait for a specific status.
88
+ */
89
+ waitForStatus(status: SseClientState["status"], options?: {
90
+ timeoutMs?: number;
91
+ }): Promise<SseClientState>;
92
+ /**
93
+ * Whether the client is connected and ready to send/receive.
94
+ */
95
+ get isConnected(): boolean;
96
+ protected generate(): GeneratedChannel;
97
+ onStart(): Promise<void>;
98
+ onStop(): Promise<void>;
100
99
  }
101
100
  /**
102
101
  * Create an SSE client adapter for browser-to-server connections.
@@ -115,41 +114,42 @@ declare class SseClientTransport extends Transport<void> {
115
114
  * ```
116
115
  */
117
116
  declare function createSseClient(options: SseClientOptions): TransportFactory;
118
-
117
+ //#endregion
118
+ //#region src/client-program.d.ts
119
119
  type SseClientMsg = {
120
- type: "start";
120
+ type: "start";
121
121
  } | {
122
- type: "event-source-opened";
122
+ type: "event-source-opened";
123
123
  } | {
124
- type: "event-source-error";
124
+ type: "event-source-error";
125
125
  } | {
126
- type: "stop";
126
+ type: "stop";
127
127
  } | {
128
- type: "reconnect-timer-fired";
128
+ type: "reconnect-timer-fired";
129
129
  };
130
130
  type SseClientEffect = {
131
- type: "create-event-source";
132
- url: string;
133
- attempt: number;
131
+ type: "create-event-source";
132
+ url: string;
133
+ attempt: number;
134
134
  } | {
135
- type: "close-event-source";
135
+ type: "close-event-source";
136
136
  } | {
137
- type: "add-channel-and-establish";
137
+ type: "add-channel-and-establish";
138
138
  } | {
139
- type: "remove-channel";
139
+ type: "remove-channel";
140
140
  } | {
141
- type: "start-reconnect-timer";
142
- delayMs: number;
141
+ type: "start-reconnect-timer";
142
+ delayMs: number;
143
143
  } | {
144
- type: "cancel-reconnect-timer";
144
+ type: "cancel-reconnect-timer";
145
145
  } | {
146
- type: "abort-pending-posts";
146
+ type: "abort-pending-posts";
147
147
  };
148
148
  interface SseClientProgramOptions {
149
- url: string;
150
- reconnect?: Partial<ReconnectOptions>;
151
- /** Inject jitter source for deterministic testing. Default: () => Math.random() * 1000 */
152
- jitterFn?: () => number;
149
+ url: string;
150
+ reconnect?: Partial<ReconnectOptions>;
151
+ /** Inject jitter source for deterministic testing. Default: () => Math.random() * 1000 */
152
+ jitterFn?: () => number;
153
153
  }
154
154
  /**
155
155
  * Create the SSE client connection lifecycle program — a pure Mealy machine.
@@ -159,5 +159,6 @@ interface SseClientProgramOptions {
159
159
  * shell interprets `SseClientEffect` as actual I/O.
160
160
  */
161
161
  declare function createSseClientProgram(options: SseClientProgramOptions): Program<SseClientMsg, SseClientState, SseClientEffect>;
162
-
163
- export { DEFAULT_FRAGMENT_THRESHOLD, type SseClientEffect, SseClientLifecycleEvents, type SseClientMsg, type SseClientOptions, type SseClientProgramOptions, SseClientState, type SseClientStateTransition, SseClientTransport, createSseClient, createSseClientProgram };
162
+ //#endregion
163
+ export { DEFAULT_FRAGMENT_THRESHOLD, type DisconnectReason, type SseClientEffect, type SseClientLifecycleEvents, type SseClientMsg, type SseClientOptions, type SseClientProgramOptions, type SseClientState, type SseClientStateTransition, SseClientTransport, type StateTransition, type TransitionListener, createSseClient, createSseClientProgram };
164
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client-transport.ts","../src/client-program.ts"],"mappings":";;;;;AAmFA;;;;;AAAA,cAAa,0BAAA;;;;UAKI,gBAAA;EA0BH;EAxBZ,OAAA,aAAoB,MAAA,EAAQ,MAAA;EAwBQ;EArBpC,cAAA,aAA2B,MAAA,EAAQ,MAAA;EAHP;EAM5B,SAAA;IACE,OAAA;IACA,WAAA;IACA,SAAA;IACA,QAAA;EAAA;EAFA;EAMF,SAAA;IACE,WAAA;IACA,SAAA;IACA,QAAA;EAAA;EAAA;EAIF,iBAAA;EAGA;EAAA,SAAA,GAAY,wBAAA;AAAA;;AAmBd;;KAAY,wBAAA,GAA2B,iBAAA,CAAgB,cAAA;;;AAiCvD;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,kBAAA,SAA2B,SAAA;EAAA;cAwB1B,OAAA,EAAS,gBAAA;EAyMU;;;EAR/B,QAAA,CAAA,GAAY,cAAA;EAiBE;;;EAVd,sBAAA,CACE,QAAA,EAAU,oBAAA,CAAmB,cAAA;EAW5B;;;EAHH,YAAA,CACE,SAAA,GAAY,KAAA,EAAO,cAAA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