@dammers/use-signalr-svelte 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 +1 -1
- package/dist/create-signalr-client.d.ts +12 -11
- package/dist/create-signalr-client.js +12 -11
- package/dist/internal/create-hooks.js +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Context and stores for typed [SignalR](https://learn.microsoft.com/aspnet/core/s
|
|
|
11
11
|
npm install @dammers/use-signalr-svelte @microsoft/signalr
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
It needs Svelte ^5.15, `@microsoft/signalr` ^8 || ^9 || ^10, and Node 20.19 or later.
|
|
14
|
+
It needs Svelte ^5.15, `@microsoft/signalr` ^8 || ^9 || ^10 || ^11, and Node 20.19 or later.
|
|
15
15
|
|
|
16
16
|
## Example
|
|
17
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HubDef, HubString, InferContract, SignalRClientConfig } from "@dammers/use-signalr-core";
|
|
2
2
|
/**
|
|
3
|
-
* Creates a
|
|
3
|
+
* Creates a typed SignalR client. Returns a provider function and a set
|
|
4
4
|
* of stores/functions, typed against the contract inferred from
|
|
5
5
|
* `config.hubs`: the keys declare the hubs, and each hub's
|
|
6
6
|
* `event()`/`method()` declarations declare its events and methods.
|
|
@@ -16,10 +16,10 @@ export declare function createSignalRClient<const H extends Record<HubString, Hu
|
|
|
16
16
|
*/
|
|
17
17
|
provideSignalR: (props: import("./types.js").SignalRProviderProps<keyof H & `/${string}`>) => void;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Gives access to the SignalR context (`getConnection`, `getStatus`,
|
|
20
20
|
* and `waitForConnection`). Call it during component init, below
|
|
21
21
|
* `provideSignalR`. Prefer the typed functions below. Use this only for
|
|
22
|
-
* the underlying `HubConnection` or a
|
|
22
|
+
* the underlying `HubConnection` or a one-time read.
|
|
23
23
|
*/
|
|
24
24
|
getSignalR: () => import("@dammers/use-signalr-core").SignalRPublicContext<InferContract<H>>;
|
|
25
25
|
/**
|
|
@@ -46,30 +46,31 @@ export declare function createSignalRClient<const H extends Record<HubString, Hu
|
|
|
46
46
|
/**
|
|
47
47
|
* Typed fire-and-forget sender. Call it during component init. It does
|
|
48
48
|
* not wait for the connection. It resolves `true` when it sends the call,
|
|
49
|
-
* and `false` when the hub is not connected
|
|
50
|
-
*
|
|
51
|
-
* cleanup, use `hubTeardown`.
|
|
49
|
+
* and `false` when the hub is not connected and it drops the call. It also
|
|
50
|
+
* resolves `false` when the send fails. It never throws, so a cleanup can
|
|
51
|
+
* call it. For a call that must land in a cleanup, use `hubTeardown`.
|
|
52
52
|
*/
|
|
53
53
|
hubSend: <H_1 extends keyof H & `/${string}`, M extends import("@dammers/use-signalr-core").MethodName<InferContract<H>, H_1>>(hub: H_1, method: M) => (...args: import("@dammers/use-signalr-core").MethodArgs<InferContract<H>, H_1, M>) => Promise<boolean>;
|
|
54
54
|
/**
|
|
55
55
|
* Typed teardown sender for a method that you call in `onDestroy`. Call
|
|
56
56
|
* it during component init. It survives the destroy of the component,
|
|
57
57
|
* queues while the hub is still connecting instead of dropping, and holds
|
|
58
|
-
* a lazy hub open until the
|
|
59
|
-
*
|
|
60
|
-
*
|
|
58
|
+
* a lazy hub open until the send ends. It resolves `true` if the call
|
|
59
|
+
* is sent. It 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. It never throws.
|
|
60
|
+
* If the session stops while the call is pending on a connected hub, the call is sent before the connection closes.
|
|
61
61
|
*/
|
|
62
62
|
hubTeardown: <H_1 extends keyof H & `/${string}`, M extends import("@dammers/use-signalr-core").MethodName<InferContract<H>, H_1>>(hub: H_1, method: M, options?: import("@dammers/use-signalr-core").TeardownOptions) => (...args: import("@dammers/use-signalr-core").MethodArgs<InferContract<H>, H_1, M>) => Promise<boolean>;
|
|
63
63
|
/**
|
|
64
64
|
* Live connection status of a hub, as a Svelte store. Call it during
|
|
65
|
-
* component init. Subscribe with `$` to
|
|
65
|
+
* component init. Subscribe with `$` to run again only when this hub's
|
|
66
66
|
* status changes. It also keeps a lazy hub connected until the component
|
|
67
67
|
* is destroyed.
|
|
68
68
|
*/
|
|
69
69
|
hubStatus: <H_1 extends keyof H & `/${string}`>(hub: H_1) => import("svelte/store").Readable<import("@dammers/use-signalr-core").HubConnectionStatus>;
|
|
70
70
|
/**
|
|
71
71
|
* Runs a callback after each reconnect, not the first connect, to refetch
|
|
72
|
-
* state that went stale while offline.
|
|
72
|
+
* state that went stale while offline. It also runs after a rebuild, but
|
|
73
|
+
* only for a hub that was connected before. Call it during component init.
|
|
73
74
|
*/
|
|
74
75
|
onReconnected: <H_1 extends keyof H & `/${string}`>(hub: H_1, callback: () => void) => void;
|
|
75
76
|
};
|
|
@@ -2,7 +2,7 @@ import { hubKeys, resolveHubConfig } from "@dammers/use-signalr-core";
|
|
|
2
2
|
import { createSignalRProvider } from "./internal/create-provider.js";
|
|
3
3
|
import { createSignalRHooks } from "./internal/create-hooks.js";
|
|
4
4
|
/**
|
|
5
|
-
* Creates a
|
|
5
|
+
* Creates a typed SignalR client. Returns a provider function and a set
|
|
6
6
|
* of stores/functions, typed against the contract inferred from
|
|
7
7
|
* `config.hubs`: the keys declare the hubs, and each hub's
|
|
8
8
|
* `event()`/`method()` declarations declare its events and methods.
|
|
@@ -25,10 +25,10 @@ export function createSignalRClient(config) {
|
|
|
25
25
|
*/
|
|
26
26
|
provideSignalR,
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Gives access to the SignalR context (`getConnection`, `getStatus`,
|
|
29
29
|
* and `waitForConnection`). Call it during component init, below
|
|
30
30
|
* `provideSignalR`. Prefer the typed functions below. Use this only for
|
|
31
|
-
* the underlying `HubConnection` or a
|
|
31
|
+
* the underlying `HubConnection` or a one-time read.
|
|
32
32
|
*/
|
|
33
33
|
getSignalR: hooks.getSignalR,
|
|
34
34
|
/**
|
|
@@ -55,30 +55,31 @@ export function createSignalRClient(config) {
|
|
|
55
55
|
/**
|
|
56
56
|
* Typed fire-and-forget sender. Call it during component init. It does
|
|
57
57
|
* not wait for the connection. It resolves `true` when it sends the call,
|
|
58
|
-
* and `false` when the hub is not connected
|
|
59
|
-
*
|
|
60
|
-
* cleanup, use `hubTeardown`.
|
|
58
|
+
* and `false` when the hub is not connected and it drops the call. It also
|
|
59
|
+
* resolves `false` when the send fails. It never throws, so a cleanup can
|
|
60
|
+
* call it. For a call that must land in a cleanup, use `hubTeardown`.
|
|
61
61
|
*/
|
|
62
62
|
hubSend: hooks.hubSend,
|
|
63
63
|
/**
|
|
64
64
|
* Typed teardown sender for a method that you call in `onDestroy`. Call
|
|
65
65
|
* it during component init. It survives the destroy of the component,
|
|
66
66
|
* queues while the hub is still connecting instead of dropping, and holds
|
|
67
|
-
* a lazy hub open until the
|
|
68
|
-
*
|
|
69
|
-
*
|
|
67
|
+
* a lazy hub open until the send ends. It resolves `true` if the call
|
|
68
|
+
* is sent. It 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. It never throws.
|
|
69
|
+
* If the session stops while the call is pending on a connected hub, the call is sent before the connection closes.
|
|
70
70
|
*/
|
|
71
71
|
hubTeardown: hooks.hubTeardown,
|
|
72
72
|
/**
|
|
73
73
|
* Live connection status of a hub, as a Svelte store. Call it during
|
|
74
|
-
* component init. Subscribe with `$` to
|
|
74
|
+
* component init. Subscribe with `$` to run again only when this hub's
|
|
75
75
|
* status changes. It also keeps a lazy hub connected until the component
|
|
76
76
|
* is destroyed.
|
|
77
77
|
*/
|
|
78
78
|
hubStatus: hooks.hubStatus,
|
|
79
79
|
/**
|
|
80
80
|
* Runs a callback after each reconnect, not the first connect, to refetch
|
|
81
|
-
* state that went stale while offline.
|
|
81
|
+
* state that went stale while offline. It also runs after a rebuild, but
|
|
82
|
+
* only for a hub that was connected before. Call it during component init.
|
|
82
83
|
*/
|
|
83
84
|
onReconnected: hooks.onReconnected,
|
|
84
85
|
};
|
|
@@ -55,10 +55,10 @@ export function createSignalRHooks(contextKey) {
|
|
|
55
55
|
return createSender({ getConnection, hub, method });
|
|
56
56
|
}
|
|
57
57
|
function hubTeardown(hub, method, options) {
|
|
58
|
-
const { acquire, release, waitForConnection } = getInternalContext("hubTeardown");
|
|
58
|
+
const { acquire, release, waitForConnection, beginSend } = getInternalContext("hubTeardown");
|
|
59
59
|
keepHubAlive(hub);
|
|
60
60
|
return createTeardownSender({
|
|
61
|
-
target: { acquire, release, waitForConnection },
|
|
61
|
+
target: { acquire, release, waitForConnection, beginSend },
|
|
62
62
|
hub,
|
|
63
63
|
method,
|
|
64
64
|
getOptions: () => options,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dammers/use-signalr-svelte",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Fully-typed multi-hub SignalR provider + stores for Svelte: auto-reconnect, invoke retry, lazy hubs, live status.",
|
|
5
5
|
"author": "Dammers",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"test": "vitest run"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@dammers/use-signalr-core": "1.
|
|
51
|
+
"@dammers/use-signalr-core": "1.1.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
54
|
+
"@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
55
55
|
"svelte": "^5.15.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
58
|
+
"@microsoft/signalr": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
59
59
|
"svelte": "^5.15.0",
|
|
60
60
|
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
61
61
|
"@testing-library/svelte": "^5.4.2"
|