svelte-realtime 0.4.6 → 0.4.7
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 +9 -6
- package/client.d.ts +21 -0
- package/package.json +1 -1
- package/server.d.ts +69 -14
package/README.md
CHANGED
|
@@ -1662,18 +1662,20 @@ export const message = createMessage({
|
|
|
1662
1662
|
});
|
|
1663
1663
|
```
|
|
1664
1664
|
|
|
1665
|
-
###
|
|
1665
|
+
### Standalone onError
|
|
1666
1666
|
|
|
1667
|
-
For cron jobs, use the standalone `
|
|
1667
|
+
For errors in cron jobs, effects, and derived streams, use the standalone `onError` function:
|
|
1668
1668
|
|
|
1669
1669
|
```js
|
|
1670
|
-
import {
|
|
1670
|
+
import { onError } from 'svelte-realtime/server';
|
|
1671
1671
|
|
|
1672
|
-
|
|
1673
|
-
sentry.captureException(error, { tags: {
|
|
1672
|
+
onError((path, error) => {
|
|
1673
|
+
sentry.captureException(error, { tags: { live: path } });
|
|
1674
1674
|
});
|
|
1675
1675
|
```
|
|
1676
1676
|
|
|
1677
|
+
> `onCronError` still works but is deprecated -- use `onError` instead.
|
|
1678
|
+
|
|
1677
1679
|
---
|
|
1678
1680
|
|
|
1679
1681
|
## Custom message handling
|
|
@@ -1828,7 +1830,8 @@ Import from `svelte-realtime/server`.
|
|
|
1828
1830
|
| `close` | Ready-made close hook (fires onUnsubscribe for remaining topics) |
|
|
1829
1831
|
| `unsubscribe` | Ready-made unsubscribe hook (fires onUnsubscribe in real time) |
|
|
1830
1832
|
| `setCronPlatform(platform)` | Capture platform for cron jobs |
|
|
1831
|
-
| `
|
|
1833
|
+
| `onError(handler)` | Global error handler for cron, effects, and derived |
|
|
1834
|
+
| `onCronError(handler)` | Deprecated alias for `onError` |
|
|
1832
1835
|
| `enableSignals(ws)` | Enable point-to-point signal delivery |
|
|
1833
1836
|
| `_activateDerived(platform)` | Enable derived stream listeners |
|
|
1834
1837
|
| `live.metrics(registry)` | Opt-in Prometheus metrics |
|
package/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Readable } from 'svelte/store';
|
|
2
|
+
import type { WSEvent } from 'svelte-adapter-uws/client';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Typed error for RPC failures.
|
|
@@ -237,3 +238,23 @@ export const __devtools: {
|
|
|
237
238
|
streams: Map<string, { path: string; topic: string | null; subCount: number }>;
|
|
238
239
|
pending: Map<string, { path: string; args: any[]; startTime: number }>;
|
|
239
240
|
} | null;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Reactive derived topic subscription that auto-switches when a source store changes.
|
|
244
|
+
* Re-exported from `svelte-adapter-uws/client`.
|
|
245
|
+
*
|
|
246
|
+
* @param topicFn - Function that computes the topic from the store value
|
|
247
|
+
* @param store - Readable store whose value drives the topic
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```svelte
|
|
251
|
+
* <script>
|
|
252
|
+
* import { onDerived } from 'svelte-realtime/client';
|
|
253
|
+
* const messages = onDerived((id) => `room:${id}`, roomId);
|
|
254
|
+
* </script>
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export function onDerived<T = unknown>(
|
|
258
|
+
topicFn: (value: T) => string,
|
|
259
|
+
store: Readable<T>
|
|
260
|
+
): Readable<WSEvent | null>;
|
package/package.json
CHANGED
package/server.d.ts
CHANGED
|
@@ -529,6 +529,43 @@ export namespace live {
|
|
|
529
529
|
*/
|
|
530
530
|
function webhook(topic: string, config: WebhookConfig): WebhookHandler;
|
|
531
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Opt-in Prometheus metrics integration.
|
|
534
|
+
* Accepts a MetricsRegistry from `svelte-adapter-uws-extensions/prometheus`
|
|
535
|
+
* and instruments RPC calls, stream subscriptions, and cron executions.
|
|
536
|
+
*
|
|
537
|
+
* Zero overhead if never called.
|
|
538
|
+
*
|
|
539
|
+
* @param registry - A MetricsRegistry instance with counter(), histogram(), gauge()
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```js
|
|
543
|
+
* import { createRegistry } from 'svelte-adapter-uws-extensions/prometheus';
|
|
544
|
+
* live.metrics(createRegistry());
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
function metrics(registry: any): void;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Wrap a stream initFn call with a circuit breaker.
|
|
551
|
+
* When the breaker is open, returns the fallback value or throws SERVICE_UNAVAILABLE.
|
|
552
|
+
*
|
|
553
|
+
* @param options - Circuit breaker instance and optional fallback
|
|
554
|
+
* @param fn - The stream initFn to wrap
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```js
|
|
558
|
+
* export const messages = live.breaker(
|
|
559
|
+
* { breaker: cb, fallback: [] },
|
|
560
|
+
* live.stream('messages', async (ctx) => db.messages.latest(50))
|
|
561
|
+
* );
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
function breaker<T extends Function>(
|
|
565
|
+
options: { breaker: any; fallback?: any },
|
|
566
|
+
fn: T
|
|
567
|
+
): T;
|
|
568
|
+
|
|
532
569
|
/**
|
|
533
570
|
* Declarative access control helpers for subscribe-time gating.
|
|
534
571
|
* For per-event filtering, use `pipe.filter()`.
|
|
@@ -812,29 +849,23 @@ export function _clearCron(): void;
|
|
|
812
849
|
export function _tickCron(): Promise<void>;
|
|
813
850
|
|
|
814
851
|
/**
|
|
815
|
-
* Set a global error handler for cron
|
|
816
|
-
* Without this,
|
|
852
|
+
* Set a global error handler for server-side errors (cron, effects, derived).
|
|
853
|
+
* Without this, errors are logged in dev and silently swallowed in production.
|
|
817
854
|
*
|
|
818
|
-
* @param handler - Receives the
|
|
855
|
+
* @param handler - Receives the path and the thrown error
|
|
819
856
|
*
|
|
820
857
|
* @example
|
|
821
858
|
* ```js
|
|
822
|
-
*
|
|
823
|
-
* sentry.captureException(error, { tags: {
|
|
859
|
+
* onError((path, error) => {
|
|
860
|
+
* sentry.captureException(error, { tags: { live: path } });
|
|
824
861
|
* });
|
|
825
862
|
* ```
|
|
826
863
|
*/
|
|
864
|
+
export function onError(handler: (path: string, error: unknown) => void): void;
|
|
865
|
+
|
|
866
|
+
/** @deprecated Use `onError()` instead. */
|
|
827
867
|
export function onCronError(handler: (path: string, error: unknown) => void): void;
|
|
828
868
|
|
|
829
|
-
/**
|
|
830
|
-
* Handle a WebSocket close event. Fires `onUnsubscribe` lifecycle hooks
|
|
831
|
-
* for stream functions that define them.
|
|
832
|
-
*
|
|
833
|
-
* Re-export from your `hooks.ws.js`:
|
|
834
|
-
* ```js
|
|
835
|
-
* export { close } from 'svelte-realtime/server';
|
|
836
|
-
* ```
|
|
837
|
-
*/
|
|
838
869
|
/**
|
|
839
870
|
* Subscribe a WebSocket to its user's signal topic.
|
|
840
871
|
* Call in your `open` hook to enable signal delivery.
|
|
@@ -847,6 +878,30 @@ export function onCronError(handler: (path: string, error: unknown) => void): vo
|
|
|
847
878
|
*/
|
|
848
879
|
export function enableSignals(ws: WebSocket<any>, options?: { idField?: string }): void;
|
|
849
880
|
|
|
881
|
+
/**
|
|
882
|
+
* Handle a real-time topic unsubscribe event. Fires onUnsubscribe lifecycle
|
|
883
|
+
* hooks for the stream function that owns the topic.
|
|
884
|
+
*
|
|
885
|
+
* Re-export from your `hooks.ws.js`:
|
|
886
|
+
* ```js
|
|
887
|
+
* export { unsubscribe } from 'svelte-realtime/server';
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
export function unsubscribe(
|
|
891
|
+
ws: WebSocket<any>,
|
|
892
|
+
topic: string,
|
|
893
|
+
ctx: { platform: Platform }
|
|
894
|
+
): void;
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Handle a WebSocket close event. Fires `onUnsubscribe` lifecycle hooks
|
|
898
|
+
* for stream functions that define them.
|
|
899
|
+
*
|
|
900
|
+
* Re-export from your `hooks.ws.js`:
|
|
901
|
+
* ```js
|
|
902
|
+
* export { close } from 'svelte-realtime/server';
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
850
905
|
export function close(
|
|
851
906
|
ws: WebSocket<any>,
|
|
852
907
|
ctx: { platform: Platform }
|