@dammers/use-signalr-lit 1.0.0 → 1.1.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
@@ -11,7 +11,7 @@ Reactive controllers for typed [SignalR](https://learn.microsoft.com/aspnet/core
11
11
  npm install @dammers/use-signalr-lit @microsoft/signalr
12
12
  ```
13
13
 
14
- It needs Lit ^3, `@microsoft/signalr` ^8 || ^9 || ^10, and Node 20.19 or later.
14
+ It needs Lit ^3, `@microsoft/signalr` ^8 || ^9 || ^10 || ^11, and Node 20.19 or later.
15
15
 
16
16
  ## Example
17
17
 
@@ -12,9 +12,9 @@ export declare function createSignalRClient<const H extends Record<HubString, Hu
12
12
  } | undefined) => HubController<InferContract<H>, H_1>;
13
13
  /** Changes session options, for example a new `baseUrl` or `enabled`. Values set before the first host connects apply when it connects. It restarts a stopped session. An `undefined` `accessTokenFactory` keeps the old one. */
14
14
  update: (partial: Partial<Pick<SignalRSessionOptions<`/${string}`>, "baseUrl" | "enabled" | "connectionKey" | "accessTokenFactory">>) => void;
15
- /** Stops every hub and releases the connections. The session stays stopped until the next `update()`. */
15
+ /** Stops every hub and closes the connections. A connection with a pending teardown call stays open until the send ends. The session stays stopped until the next `update()`. */
16
16
  stop: () => void;
17
- /** Escape hatch to the SignalR context (`getConnection`, `getStatus`, and `waitForConnection`). Use this only for the underlying `HubConnection` or a point read. */
17
+ /** Gives access to the SignalR context (`getConnection`, `getStatus`, and `waitForConnection`). Use this only for the underlying `HubConnection` or a one-time read. */
18
18
  context: import("@dammers/use-signalr-core").SignalRPublicContext<InferContract<H>>;
19
19
  };
20
20
  };
@@ -26,9 +26,9 @@ declare function createRuntime<T extends SignalRContract>(hubs: Array<keyof T &
26
26
  }) => HubController<T, H>;
27
27
  /** Changes session options, for example a new `baseUrl` or `enabled`. Values set before the first host connects apply when it connects. It restarts a stopped session. An `undefined` `accessTokenFactory` keeps the old one. */
28
28
  update: (partial: SignalRSessionUpdate) => void;
29
- /** Stops every hub and releases the connections. The session stays stopped until the next `update()`. */
29
+ /** Stops every hub and closes the connections. A connection with a pending teardown call stays open until the send ends. The session stays stopped until the next `update()`. */
30
30
  stop: () => void;
31
- /** Escape hatch to the SignalR context (`getConnection`, `getStatus`, and `waitForConnection`). Use this only for the underlying `HubConnection` or a point read. */
31
+ /** Gives access to the SignalR context (`getConnection`, `getStatus`, and `waitForConnection`). Use this only for the underlying `HubConnection` or a one-time read. */
32
32
  context: import("@dammers/use-signalr-core").SignalRPublicContext<T>;
33
33
  };
34
34
  export type LitSignalRSession<T extends SignalRContract> = ReturnType<typeof createRuntime<T>>;
@@ -51,19 +51,19 @@ export declare class HubController<T extends SignalRContract, H extends keyof T
51
51
  get status(): HubConnectionStatus;
52
52
  /** Lit calls this when the host connects. It acquires the hub, and does nothing during a server render. */
53
53
  hostConnected(): void;
54
- /** Lit calls this when the host disconnects. Pending calls abort at the end of the task, unless the host connects again first. */
54
+ /** Lit calls this when the host disconnects. Pending calls abort a moment later, unless the host connects again first. */
55
55
  hostDisconnected(): void;
56
56
  /** Disconnects the controller and removes it from the host. */
57
57
  dispose(): void;
58
- /** Subscribes to a typed server event while the host is connected. Handler args are inferred from your contract. Returns an unsubscribe function. */
58
+ /** Subscribes to a typed server event while the host is connected. Handler arguments are inferred from your contract. Returns an unsubscribe function. */
59
59
  on<E extends EventName<T, H>>(event: E, handler: (...args: EventArgs<T, H, E>) => void): () => void;
60
- /** Runs a callback after each reconnect, not the first connect, to refetch state that went stale while offline. */
60
+ /** Runs a callback after each reconnect, not the first connect, to refetch state that went stale while offline. It also runs after a rebuild, but only for a hub that was connected before. */
61
61
  onReconnected(callback: () => void): () => void;
62
- /** Typed invoker that waits for the connection and resolves with the method's return value. Fails fast by default. Opt in to retry for idempotent methods only. */
62
+ /** Typed invoker that waits for the connection and resolves with the method's return value. Fails fast by default. Opt in to retry for idempotent methods only. A pending call rejects with an `AbortError` when the host disconnects, unless `keepAliveOnUnmount` is true. With `keepAliveOnUnmount`, the call also holds a lazy hub open until it settles. */
63
63
  invoke<M extends MethodName<T, H>>(method: M, options?: InvokeOptions): (...args: import("@dammers/use-signalr-core").MethodArgs<T, H, M>) => Promise<import("@dammers/use-signalr-core").MethodReturn<T, H, M>>;
64
- /** Typed fire-and-forget sender. It does not wait for the connection. It resolves `true` when it sends the call, and `false` when the hub is not connected and it drops the call. It never throws, so a cleanup can call it. For a call that must land in a cleanup, use `teardown`. */
64
+ /** Typed fire-and-forget sender. It does not wait for the connection. It resolves `true` when it sends the call, and `false` when the hub is not connected and it drops the call. It also resolves `false` when the send fails. It never throws, so a cleanup can call it. For a call that must land in a cleanup, use `teardown`. */
65
65
  send<M extends MethodName<T, H>>(method: M): (...args: import("@dammers/use-signalr-core").MethodArgs<T, H, M>) => Promise<boolean>;
66
- /** Typed teardown sender for a method invoked in a cleanup. Survives host disconnect, queues while the hub is still connecting, and holds a lazy hub open until the flush completes. Never throws. */
66
+ /** Typed teardown sender for a method invoked in a cleanup. Survives the host disconnect, queues while the hub is still connecting instead of dropping, and holds a lazy hub open until the send ends. Resolves `true` if the call is sent. Resolves `false` if the hub does not connect in time, the session stops while the call waits for the hub, the session is disabled, the hub failed, or the send fails or does not end in time. Never throws. If the session stops while the call is pending on a connected hub, the call is sent before the connection closes. */
67
67
  teardown<M extends MethodName<T, H>>(method: M, options?: TeardownOptions): (...args: import("@dammers/use-signalr-core").MethodArgs<T, H, M>) => Promise<boolean>;
68
68
  private subscribeEntry;
69
69
  private unsubscribeEntry;
@@ -51,12 +51,12 @@ function createRuntime(hubs, resolve, options) {
51
51
  if (hasHost)
52
52
  sync();
53
53
  },
54
- /** Stops every hub and releases the connections. The session stays stopped until the next `update()`. */
54
+ /** Stops every hub and closes the connections. A connection with a pending teardown call stays open until the send ends. The session stays stopped until the next `update()`. */
55
55
  stop: () => {
56
56
  stopped = true;
57
57
  session.stop();
58
58
  },
59
- /** Escape hatch to the SignalR context (`getConnection`, `getStatus`, and `waitForConnection`). Use this only for the underlying `HubConnection` or a point read. */
59
+ /** Gives access to the SignalR context (`getConnection`, `getStatus`, and `waitForConnection`). Use this only for the underlying `HubConnection` or a one-time read. */
60
60
  context: session.publicContext,
61
61
  };
62
62
  }
@@ -95,7 +95,7 @@ export class HubController {
95
95
  entry.unsubscribe = this.context.registerReconnect(this.hub, entry.run);
96
96
  });
97
97
  }
98
- /** Lit calls this when the host disconnects. Pending calls abort at the end of the task, unless the host connects again first. */
98
+ /** Lit calls this when the host disconnects. Pending calls abort a moment later, unless the host connects again first. */
99
99
  hostDisconnected() {
100
100
  if (!this.connected)
101
101
  return;
@@ -118,7 +118,7 @@ export class HubController {
118
118
  this.hostDisconnected();
119
119
  this.host.removeController(this);
120
120
  }
121
- /** Subscribes to a typed server event while the host is connected. Handler args are inferred from your contract. Returns an unsubscribe function. */
121
+ /** Subscribes to a typed server event while the host is connected. Handler arguments are inferred from your contract. Returns an unsubscribe function. */
122
122
  on(event, handler) {
123
123
  const entry = {
124
124
  event: String(event),
@@ -132,7 +132,7 @@ export class HubController {
132
132
  this.eventEntries.delete(entry);
133
133
  };
134
134
  }
135
- /** Runs a callback after each reconnect, not the first connect, to refetch state that went stale while offline. */
135
+ /** Runs a callback after each reconnect, not the first connect, to refetch state that went stale while offline. It also runs after a rebuild, but only for a hub that was connected before. */
136
136
  onReconnected(callback) {
137
137
  const entry = { run: () => callback() };
138
138
  this.reconnectEntries.add(entry);
@@ -144,7 +144,7 @@ export class HubController {
144
144
  this.reconnectEntries.delete(entry);
145
145
  };
146
146
  }
147
- /** Typed invoker that waits for the connection and resolves with the method's return value. Fails fast by default. Opt in to retry for idempotent methods only. */
147
+ /** Typed invoker that waits for the connection and resolves with the method's return value. Fails fast by default. Opt in to retry for idempotent methods only. A pending call rejects with an `AbortError` when the host disconnects, unless `keepAliveOnUnmount` is true. With `keepAliveOnUnmount`, the call also holds a lazy hub open until it settles. */
148
148
  invoke(method, options) {
149
149
  return createInvoker({
150
150
  target: this.context,
@@ -154,7 +154,7 @@ export class HubController {
154
154
  getSignal: () => (options?.keepAliveOnUnmount ? undefined : this.abortScope.signal()),
155
155
  });
156
156
  }
157
- /** Typed fire-and-forget sender. It does not wait for the connection. It resolves `true` when it sends the call, and `false` when the hub is not connected and it drops the call. It never throws, so a cleanup can call it. For a call that must land in a cleanup, use `teardown`. */
157
+ /** Typed fire-and-forget sender. It does not wait for the connection. It resolves `true` when it sends the call, and `false` when the hub is not connected and it drops the call. It also resolves `false` when the send fails. It never throws, so a cleanup can call it. For a call that must land in a cleanup, use `teardown`. */
158
158
  send(method) {
159
159
  return createSender({
160
160
  getConnection: this.context.getConnection,
@@ -162,7 +162,7 @@ export class HubController {
162
162
  method,
163
163
  });
164
164
  }
165
- /** Typed teardown sender for a method invoked in a cleanup. Survives host disconnect, queues while the hub is still connecting, and holds a lazy hub open until the flush completes. Never throws. */
165
+ /** Typed teardown sender for a method invoked in a cleanup. Survives the host disconnect, queues while the hub is still connecting instead of dropping, and holds a lazy hub open until the send ends. Resolves `true` if the call is sent. Resolves `false` if the hub does not connect in time, the session stops while the call waits for the hub, the session is disabled, the hub failed, or the send fails or does not end in time. Never throws. If the session stops while the call is pending on a connected hub, the call is sent before the connection closes. */
166
166
  teardown(method, options) {
167
167
  return createTeardownSender({
168
168
  target: this.context,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dammers/use-signalr-lit",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Fully-typed SignalR Reactive Controllers for Lit.",
5
5
  "author": "Dammers",
6
6
  "license": "MIT",
@@ -47,14 +47,14 @@
47
47
  "test": "vitest run"
48
48
  },
49
49
  "dependencies": {
50
- "@dammers/use-signalr-core": "1.0.0"
50
+ "@dammers/use-signalr-core": "1.1.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0",
53
+ "@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
54
54
  "lit": "^3.0.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0",
57
+ "@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
58
58
  "lit": "^3.0.0"
59
59
  }
60
60
  }