statewire 0.12.2 → 0.13.1

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.
@@ -1,6 +1,9 @@
1
1
  import { useEffect } from "react";
2
2
  import type { Statewire } from "../types";
3
3
  import {
4
+ discardFailed,
5
+ failedCommands,
6
+ retryFailed,
4
7
  setContext,
5
8
  setTransport,
6
9
  useStatewireSession,
@@ -39,5 +42,10 @@ export const useStatewireRemote = <
39
42
  return !s.idle;
40
43
  },
41
44
  setContext: (value) => setContext(s, value),
45
+ failures: {
46
+ list: () => failedCommands(s),
47
+ retry: (entry) => retryFailed(s, entry),
48
+ discard: (entry) => discardFailed(s, entry),
49
+ },
42
50
  };
43
51
  };
@@ -51,6 +51,8 @@ export type ConnectionState = StatewireClient.ConnectionState;
51
51
  /** The live wire a remote session drives: connection status plus frame submission. */
52
52
  export type RemoteLink = {
53
53
  connection: StatewireClient.Connection;
54
+ /** A deferred first attach still waiting; `reconnect()` releases it. */
55
+ parked: boolean;
54
56
  send: (frame: StatewireFrame) => Promise<StatewireSubmitResult>;
55
57
  };
56
58
 
@@ -269,6 +271,7 @@ const useSseLink = (
269
271
  const [auth] = useState((): AuthState => ({ stale: false }));
270
272
  const c = useStatewireConn({
271
273
  url: options.url,
274
+ isNew: options.isNew,
272
275
  onChange: options.onChange,
273
276
  ctx,
274
277
  attemptOnce: (c, abort) => attemptStream(c, options, auth, abort),
@@ -278,6 +281,9 @@ const useSseLink = (
278
281
  get connection() {
279
282
  return c.connection;
280
283
  },
284
+ get parked() {
285
+ return c.parked;
286
+ },
281
287
  send: (frame) => sendFrame(c, latest.current, auth, frame),
282
288
  }),
283
289
  );
@@ -178,6 +178,7 @@ const useWsLink = (
178
178
  const [w] = useState((): WsChannel => ({ socket: null, authStale: false }));
179
179
  const c = useStatewireConn({
180
180
  url: options.url,
181
+ isNew: options.isNew,
181
182
  onChange: options.onChange,
182
183
  ctx,
183
184
  attemptOnce: (c, abort) => attemptSocket(c, w, options, abort),
@@ -187,6 +188,9 @@ const useWsLink = (
187
188
  get connection() {
188
189
  return c.connection;
189
190
  },
191
+ get parked() {
192
+ return c.parked;
193
+ },
190
194
  send: (frame) => sendFrame(w, frame),
191
195
  }),
192
196
  );
package/src/types.ts CHANGED
@@ -59,6 +59,12 @@ export interface Statewire<
59
59
  isBusy?: boolean;
60
60
  /** Replace this client's ambient context on the server; it rides the ctx lane (no verdict). */
61
61
  setContext?: (value: Record<string, unknown>) => void;
62
+ /** The retained failed-send lane; present on transports with a durable session. */
63
+ failures?: {
64
+ list: () => readonly StatewireClient.FailedCommand[];
65
+ retry: (entry: StatewireClient.FailedCommand) => Promise<unknown>;
66
+ discard: (entry: StatewireClient.FailedCommand) => void;
67
+ };
62
68
  }
63
69
 
64
70
  const describe = (failure: StatewireClient.SendFailure): string => {