svelte-realtime 0.4.6 → 0.4.8
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 +103 -48
- package/vite.js +26 -23
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
|
@@ -83,26 +83,26 @@ export interface StreamOptions {
|
|
|
83
83
|
* Called when a client subscribes to this stream.
|
|
84
84
|
* Receives the context and resolved topic string.
|
|
85
85
|
*/
|
|
86
|
-
onSubscribe?(ctx: LiveContext
|
|
86
|
+
onSubscribe?(ctx: LiveContext<any>, topic: string): void | Promise<void>;
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* Called when a client disconnects from this stream.
|
|
90
90
|
* Fires for both static and dynamic topics.
|
|
91
91
|
*/
|
|
92
|
-
onUnsubscribe?(ctx: LiveContext
|
|
92
|
+
onUnsubscribe?(ctx: LiveContext<any>, topic: string): void | Promise<void>;
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* Subscribe-time access predicate. Checked once when a client subscribes.
|
|
96
96
|
* Return `false` to deny the subscription with an "Access denied" error.
|
|
97
97
|
* For per-event filtering, use `pipe.filter()`.
|
|
98
98
|
*/
|
|
99
|
-
filter?(ctx: LiveContext): boolean;
|
|
99
|
+
filter?(ctx: LiveContext<any>): boolean;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Subscribe-time access predicate (alias for `filter`).
|
|
103
103
|
* Use `live.access` helpers to build predicates.
|
|
104
104
|
*/
|
|
105
|
-
access?(ctx: LiveContext): boolean;
|
|
105
|
+
access?(ctx: LiveContext<any>): boolean;
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Schema version number. Increment when the data shape changes.
|
|
@@ -143,7 +143,7 @@ export interface HandleRpcOptions {
|
|
|
143
143
|
* Called when an RPC handler throws a non-LiveError.
|
|
144
144
|
* Use for error reporting (Sentry, logging, etc.).
|
|
145
145
|
*/
|
|
146
|
-
onError?(path: string, error: unknown, ctx: LiveContext): void;
|
|
146
|
+
onError?(path: string, error: unknown, ctx: LiveContext<any>): void;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
@@ -171,7 +171,7 @@ export interface CreateMessageOptions {
|
|
|
171
171
|
* Called when an RPC handler throws a non-LiveError.
|
|
172
172
|
* Use for error reporting (Sentry, logging, etc.).
|
|
173
173
|
*/
|
|
174
|
-
onError?(path: string, error: unknown, ctx: LiveContext): void;
|
|
174
|
+
onError?(path: string, error: unknown, ctx: LiveContext<any>): void;
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
177
|
* Called when a message is not an RPC request.
|
|
@@ -195,7 +195,7 @@ export interface CreateMessageOptions {
|
|
|
195
195
|
* });
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
|
-
export function live<T extends (ctx: LiveContext
|
|
198
|
+
export function live<T extends (ctx: LiveContext<any>, ...args: any[]) => any>(fn: T): T;
|
|
199
199
|
|
|
200
200
|
export namespace live {
|
|
201
201
|
/**
|
|
@@ -212,7 +212,7 @@ export namespace live {
|
|
|
212
212
|
* }, { merge: 'crud', key: 'id', prepend: true });
|
|
213
213
|
* ```
|
|
214
214
|
*/
|
|
215
|
-
function stream<T extends (ctx: LiveContext
|
|
215
|
+
function stream<T extends (ctx: LiveContext<any>, ...args: any[]) => any>(
|
|
216
216
|
topic: string,
|
|
217
217
|
initFn: T,
|
|
218
218
|
options?: StreamOptions
|
|
@@ -237,8 +237,8 @@ export namespace live {
|
|
|
237
237
|
* );
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
|
-
function stream<T extends (ctx: LiveContext
|
|
241
|
-
topicFn: (ctx: LiveContext
|
|
240
|
+
function stream<T extends (ctx: LiveContext<any>, ...args: any[]) => any>(
|
|
241
|
+
topicFn: (ctx: LiveContext<any>, ...args: any[]) => string,
|
|
242
242
|
initFn: T,
|
|
243
243
|
options?: StreamOptions
|
|
244
244
|
): T;
|
|
@@ -275,7 +275,7 @@ export namespace live {
|
|
|
275
275
|
* ```
|
|
276
276
|
*/
|
|
277
277
|
function channel(
|
|
278
|
-
topicFn: (ctx: LiveContext
|
|
278
|
+
topicFn: (ctx: LiveContext<any>, ...args: any[]) => string,
|
|
279
279
|
options?: { merge?: 'crud' | 'latest' | 'set' | 'presence' | 'cursor'; key?: string; max?: number }
|
|
280
280
|
): Function;
|
|
281
281
|
|
|
@@ -293,7 +293,7 @@ export namespace live {
|
|
|
293
293
|
* });
|
|
294
294
|
* ```
|
|
295
295
|
*/
|
|
296
|
-
function binary<T extends (ctx: LiveContext
|
|
296
|
+
function binary<T extends (ctx: LiveContext<any>, buffer: ArrayBuffer, ...args: any[]) => any>(
|
|
297
297
|
fn: T
|
|
298
298
|
): T;
|
|
299
299
|
|
|
@@ -314,7 +314,7 @@ export namespace live {
|
|
|
314
314
|
* });
|
|
315
315
|
* ```
|
|
316
316
|
*/
|
|
317
|
-
function middleware(fn: (ctx: LiveContext
|
|
317
|
+
function middleware(fn: (ctx: LiveContext<any>, next: () => Promise<any>) => Promise<any>): void;
|
|
318
318
|
|
|
319
319
|
/**
|
|
320
320
|
* Wrap a stream with a server-side gate predicate.
|
|
@@ -333,7 +333,7 @@ export namespace live {
|
|
|
333
333
|
* ```
|
|
334
334
|
*/
|
|
335
335
|
function gate<T extends Function>(
|
|
336
|
-
predicate: (ctx: LiveContext
|
|
336
|
+
predicate: (ctx: LiveContext<any>, ...args: any[]) => boolean,
|
|
337
337
|
fn: T
|
|
338
338
|
): T;
|
|
339
339
|
|
|
@@ -353,14 +353,14 @@ export namespace live {
|
|
|
353
353
|
* });
|
|
354
354
|
* ```
|
|
355
355
|
*/
|
|
356
|
-
function rateLimit<T extends (ctx: LiveContext
|
|
356
|
+
function rateLimit<T extends (ctx: LiveContext<any>, ...args: any[]) => any>(
|
|
357
357
|
config: {
|
|
358
358
|
/** Maximum number of calls allowed within the window. */
|
|
359
359
|
points: number;
|
|
360
360
|
/** Time window in milliseconds. */
|
|
361
361
|
window: number;
|
|
362
362
|
/** Custom key function. Defaults to `ctx.user.id`. */
|
|
363
|
-
key?(ctx: LiveContext): string;
|
|
363
|
+
key?(ctx: LiveContext<any>): string;
|
|
364
364
|
},
|
|
365
365
|
fn: T
|
|
366
366
|
): T;
|
|
@@ -381,7 +381,7 @@ export namespace live {
|
|
|
381
381
|
* });
|
|
382
382
|
* ```
|
|
383
383
|
*/
|
|
384
|
-
function validated<S, T extends (ctx: LiveContext
|
|
384
|
+
function validated<S, T extends (ctx: LiveContext<any>, input: any, ...args: any[]) => any>(
|
|
385
385
|
schema: S,
|
|
386
386
|
fn: T
|
|
387
387
|
): T;
|
|
@@ -529,21 +529,58 @@ 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()`.
|
|
535
572
|
*/
|
|
536
573
|
const access: {
|
|
537
574
|
/** Only allow subscription if `ctx.user[field]` is present. Default field: `'id'`. */
|
|
538
|
-
owner(field?: string): (ctx: LiveContext) => boolean;
|
|
575
|
+
owner(field?: string): (ctx: LiveContext<any>) => boolean;
|
|
539
576
|
/** Role-based access: map role names to boolean or predicate. */
|
|
540
|
-
role(map: Record<string, true | ((ctx: LiveContext) => boolean)>): (ctx: LiveContext) => boolean;
|
|
577
|
+
role(map: Record<string, true | ((ctx: LiveContext<any>) => boolean)>): (ctx: LiveContext<any>) => boolean;
|
|
541
578
|
/** Only allow subscription if `ctx.user.teamId` is present. */
|
|
542
|
-
team(): (ctx: LiveContext) => boolean;
|
|
579
|
+
team(): (ctx: LiveContext<any>) => boolean;
|
|
543
580
|
/** OR logic: any predicate returning true allows the subscription. */
|
|
544
|
-
any(...predicates: Array<(ctx: LiveContext) => boolean>): (ctx: LiveContext) => boolean;
|
|
581
|
+
any(...predicates: Array<(ctx: LiveContext<any>) => boolean>): (ctx: LiveContext<any>) => boolean;
|
|
545
582
|
/** AND logic: all predicates must return true. */
|
|
546
|
-
all(...predicates: Array<(ctx: LiveContext) => boolean>): (ctx: LiveContext) => boolean;
|
|
583
|
+
all(...predicates: Array<(ctx: LiveContext<any>) => boolean>): (ctx: LiveContext<any>) => boolean;
|
|
547
584
|
};
|
|
548
585
|
}
|
|
549
586
|
|
|
@@ -552,21 +589,21 @@ export namespace live {
|
|
|
552
589
|
*/
|
|
553
590
|
export interface RoomConfig {
|
|
554
591
|
/** Function that computes the room topic from context and args. */
|
|
555
|
-
topic: (ctx: LiveContext
|
|
592
|
+
topic: (ctx: LiveContext<any>, ...args: any[]) => string;
|
|
556
593
|
/** Function that returns initial data for the room. */
|
|
557
|
-
init: (ctx: LiveContext
|
|
594
|
+
init: (ctx: LiveContext<any>, ...args: any[]) => Promise<any>;
|
|
558
595
|
/** Function that returns presence data for the connecting user. */
|
|
559
|
-
presence?: (ctx: LiveContext) => any;
|
|
596
|
+
presence?: (ctx: LiveContext<any>) => any;
|
|
560
597
|
/** Enable cursor tracking. Pass `true` or `{ throttle: ms }`. */
|
|
561
598
|
cursors?: boolean | { throttle?: number };
|
|
562
599
|
/** Room-scoped RPC actions. */
|
|
563
|
-
actions?: Record<string, (ctx: LiveContext
|
|
600
|
+
actions?: Record<string, (ctx: LiveContext<any>, ...args: any[]) => any>;
|
|
564
601
|
/** Guard function run before data access and actions. */
|
|
565
|
-
guard?: (ctx: LiveContext
|
|
602
|
+
guard?: (ctx: LiveContext<any>, ...args: any[]) => void | Promise<void>;
|
|
566
603
|
/** Called when a user joins the room. */
|
|
567
|
-
onJoin?: (ctx: LiveContext
|
|
604
|
+
onJoin?: (ctx: LiveContext<any>, ...args: any[]) => void | Promise<void>;
|
|
568
605
|
/** Called when a user leaves the room. */
|
|
569
|
-
onLeave?: (ctx: LiveContext
|
|
606
|
+
onLeave?: (ctx: LiveContext<any>, topic: string) => void | Promise<void>;
|
|
570
607
|
/** Merge strategy for the data stream. @default 'crud' */
|
|
571
608
|
merge?: string;
|
|
572
609
|
/** Key field for the data stream. @default 'id' */
|
|
@@ -612,8 +649,8 @@ export interface WebhookHandler {
|
|
|
612
649
|
* A stream transform step created by `pipe.filter`, `pipe.sort`, etc.
|
|
613
650
|
*/
|
|
614
651
|
export interface PipeTransform {
|
|
615
|
-
transformInit?(data: any[], ctx: LiveContext): any[] | Promise<any[]>;
|
|
616
|
-
transformEvent?(ctx: LiveContext
|
|
652
|
+
transformInit?(data: any[], ctx: LiveContext<any>): any[] | Promise<any[]>;
|
|
653
|
+
transformEvent?(ctx: LiveContext<any>, event: string, data: any): boolean;
|
|
617
654
|
}
|
|
618
655
|
|
|
619
656
|
/**
|
|
@@ -635,7 +672,7 @@ export interface PipeTransform {
|
|
|
635
672
|
export function pipe<T extends Function>(stream: T, ...transforms: PipeTransform[]): T;
|
|
636
673
|
export namespace pipe {
|
|
637
674
|
/** Filter items from initial data and drop non-matching live events. */
|
|
638
|
-
function filter(predicate: (ctx: LiveContext
|
|
675
|
+
function filter(predicate: (ctx: LiveContext<any>, item: any) => boolean): PipeTransform;
|
|
639
676
|
/** Sort initial data by a field. */
|
|
640
677
|
function sort(field: string, direction?: 'asc' | 'desc'): PipeTransform;
|
|
641
678
|
/** Cap initial data to N items. */
|
|
@@ -655,8 +692,8 @@ export namespace pipe {
|
|
|
655
692
|
* ```
|
|
656
693
|
*/
|
|
657
694
|
export function guard(
|
|
658
|
-
...fns: Array<(ctx: LiveContext) => void | Promise<void>>
|
|
659
|
-
): (ctx: LiveContext) => void | Promise<void>;
|
|
695
|
+
...fns: Array<(ctx: LiveContext<any>) => void | Promise<void>>
|
|
696
|
+
): (ctx: LiveContext<any>) => void | Promise<void>;
|
|
660
697
|
|
|
661
698
|
/**
|
|
662
699
|
* Typed error that propagates `code` and `message` to the client.
|
|
@@ -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 }
|
package/vite.js
CHANGED
|
@@ -1551,7 +1551,7 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1551
1551
|
const exports = [];
|
|
1552
1552
|
/** @type {Set<string>} */
|
|
1553
1553
|
const handledNames = new Set();
|
|
1554
|
-
let
|
|
1554
|
+
let needsStreamStore = false;
|
|
1555
1555
|
let needsRpcError = false;
|
|
1556
1556
|
|
|
1557
1557
|
// Detect live() exports
|
|
@@ -1597,23 +1597,25 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1597
1597
|
while ((match = STREAM_EXPORT_RE.exec(source)) !== null) {
|
|
1598
1598
|
const name = match[1];
|
|
1599
1599
|
handledNames.add(name);
|
|
1600
|
-
|
|
1600
|
+
needsStreamStore = true;
|
|
1601
1601
|
needsRpcError = true;
|
|
1602
1602
|
const isDynamic = _isDynamicExport(source, name, 'live\\.stream');
|
|
1603
1603
|
if (isTS) {
|
|
1604
1604
|
const returnType = _extractStreamReturnType(source, name);
|
|
1605
|
-
const storeType = `
|
|
1605
|
+
const storeType = `StreamStore<${returnType} | undefined | { error: RpcError }>`;
|
|
1606
|
+
const loadSig = `{ load(platform: any, options?: { args?: any[] }): Promise<${returnType}> }`;
|
|
1606
1607
|
if (isDynamic) {
|
|
1607
1608
|
const factoryParams = _extractDynamicFactoryParams(source, name, 'live\\.stream');
|
|
1608
|
-
exports.push(` export const ${name}: ${factoryParams} => ${storeType};`);
|
|
1609
|
+
exports.push(` export const ${name}: (${factoryParams} => ${storeType}) & ${loadSig};`);
|
|
1609
1610
|
} else {
|
|
1610
|
-
exports.push(` export const ${name}: ${storeType};`);
|
|
1611
|
+
exports.push(` export const ${name}: ${storeType} & ${loadSig};`);
|
|
1611
1612
|
}
|
|
1612
1613
|
} else {
|
|
1614
|
+
const loadSig = `{ load(platform: any, options?: { args?: any[] }): Promise<any> }`;
|
|
1613
1615
|
if (isDynamic) {
|
|
1614
|
-
exports.push(` export const ${name}: (...args: any[]) =>
|
|
1616
|
+
exports.push(` export const ${name}: ((...args: any[]) => StreamStore<any>) & ${loadSig};`);
|
|
1615
1617
|
} else {
|
|
1616
|
-
exports.push(` export const ${name}:
|
|
1618
|
+
exports.push(` export const ${name}: StreamStore<any> & ${loadSig};`);
|
|
1617
1619
|
}
|
|
1618
1620
|
}
|
|
1619
1621
|
}
|
|
@@ -1624,17 +1626,18 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1624
1626
|
const name = match[1];
|
|
1625
1627
|
handledNames.add(name);
|
|
1626
1628
|
if (!exports.some(e => e.includes(`export const ${name}:`))) {
|
|
1627
|
-
|
|
1629
|
+
needsStreamStore = true;
|
|
1628
1630
|
const isDynamic = _isDynamicExport(source, name, 'live\\.channel');
|
|
1631
|
+
const loadSig = `{ load(platform: any, options?: { args?: any[] }): Promise<any> }`;
|
|
1629
1632
|
if (isDynamic) {
|
|
1630
1633
|
if (isTS) {
|
|
1631
1634
|
const factoryParams = _extractDynamicFactoryParams(source, name, 'live\\.channel');
|
|
1632
|
-
exports.push(` export const ${name}: ${factoryParams} =>
|
|
1635
|
+
exports.push(` export const ${name}: (${factoryParams} => StreamStore<any>) & ${loadSig};`);
|
|
1633
1636
|
} else {
|
|
1634
|
-
exports.push(` export const ${name}: (...args: any[]) =>
|
|
1637
|
+
exports.push(` export const ${name}: ((...args: any[]) => StreamStore<any>) & ${loadSig};`);
|
|
1635
1638
|
}
|
|
1636
1639
|
} else {
|
|
1637
|
-
exports.push(` export const ${name}:
|
|
1640
|
+
exports.push(` export const ${name}: StreamStore<any> & ${loadSig};`);
|
|
1638
1641
|
}
|
|
1639
1642
|
}
|
|
1640
1643
|
}
|
|
@@ -1645,8 +1648,8 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1645
1648
|
const name = match[1];
|
|
1646
1649
|
handledNames.add(name);
|
|
1647
1650
|
if (!exports.some(e => e.includes(`export const ${name}:`))) {
|
|
1648
|
-
|
|
1649
|
-
exports.push(` export const ${name}:
|
|
1651
|
+
needsStreamStore = true;
|
|
1652
|
+
exports.push(` export const ${name}: StreamStore<any> & { load(platform: any, options?: { args?: any[] }): Promise<any> };`);
|
|
1650
1653
|
}
|
|
1651
1654
|
}
|
|
1652
1655
|
|
|
@@ -1656,8 +1659,8 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1656
1659
|
const name = match[1];
|
|
1657
1660
|
handledNames.add(name);
|
|
1658
1661
|
if (!exports.some(e => e.includes(`export const ${name}:`))) {
|
|
1659
|
-
|
|
1660
|
-
exports.push(` export const ${name}:
|
|
1662
|
+
needsStreamStore = true;
|
|
1663
|
+
exports.push(` export const ${name}: StreamStore<any> & { load(platform: any, options?: { args?: any[] }): Promise<any> };`);
|
|
1661
1664
|
}
|
|
1662
1665
|
}
|
|
1663
1666
|
|
|
@@ -1692,8 +1695,8 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1692
1695
|
const name = match[1];
|
|
1693
1696
|
handledNames.add(name);
|
|
1694
1697
|
if (!exports.some(e => e.includes(`export const ${name}:`))) {
|
|
1695
|
-
|
|
1696
|
-
exports.push(` export const ${name}: { data: (...args: any[]) =>
|
|
1698
|
+
needsStreamStore = true;
|
|
1699
|
+
exports.push(` export const ${name}: { data: (...args: any[]) => StreamStore<any>, presence?: (...args: any[]) => StreamStore<any>, cursors?: (...args: any[]) => StreamStore<any>, [action: string]: (...args: any[]) => Promise<any> | ((...args: any[]) => StreamStore<any>) };`);
|
|
1697
1700
|
}
|
|
1698
1701
|
}
|
|
1699
1702
|
|
|
@@ -1702,13 +1705,13 @@ function _generateTypeDeclarations(liveDir, dir) {
|
|
|
1702
1705
|
|
|
1703
1706
|
if (exports.length > 0) {
|
|
1704
1707
|
declarations.push(`declare module '$live/${rel}' {`);
|
|
1705
|
-
if (
|
|
1706
|
-
|
|
1708
|
+
if (needsStreamStore || needsRpcError) {
|
|
1709
|
+
const clientImports = [];
|
|
1710
|
+
if (needsStreamStore) clientImports.push('StreamStore');
|
|
1711
|
+
if (needsRpcError) clientImports.push('RpcError');
|
|
1712
|
+
declarations.push(` import type { ${clientImports.join(', ')} } from 'svelte-realtime/client';`);
|
|
1707
1713
|
}
|
|
1708
|
-
if (needsRpcError) {
|
|
1709
|
-
declarations.push(" import type { RpcError } from 'svelte-realtime/client';");
|
|
1710
|
-
}
|
|
1711
|
-
if (needsReadable || needsRpcError) {
|
|
1714
|
+
if (needsStreamStore || needsRpcError) {
|
|
1712
1715
|
declarations.push('');
|
|
1713
1716
|
}
|
|
1714
1717
|
declarations.push(...exports);
|