svelte-realtime 0.4.8 → 0.4.10

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
@@ -874,10 +874,25 @@ Call `configure()` once at app startup. The hooks fire on state transitions only
874
874
 
875
875
  | Option | Description |
876
876
  |---|---|
877
+ | `url` | Full WebSocket URL for cross-origin or native app usage (e.g. `'wss://api.example.com/ws'`) |
877
878
  | `onConnect()` | Called when the WebSocket connection opens after a reconnect |
878
879
  | `onDisconnect()` | Called when the WebSocket connection closes |
879
880
  | `beforeReconnect()` | Called before each reconnection attempt (can be async) |
880
881
 
882
+ ### Cross-origin and native app usage
883
+
884
+ When using svelte-realtime from a client that runs on a different origin (Svelte Native, React Native, or any standalone app), pass the `url` option to point at your SvelteKit backend:
885
+
886
+ ```js
887
+ import { configure } from 'svelte-realtime/client';
888
+
889
+ configure({
890
+ url: 'wss://my-sveltekit-app.com/ws'
891
+ });
892
+ ```
893
+
894
+ When `url` is set, the default same-origin WebSocket URL is bypassed entirely. All RPC calls, streams, and pub/sub work the same way. Requires `svelte-adapter-uws` 0.4.8+.
895
+
881
896
  ---
882
897
 
883
898
  ## Combine stores
package/client.d.ts CHANGED
@@ -157,6 +157,13 @@ export interface OfflineEntry {
157
157
  }
158
158
 
159
159
  export function configure(config: {
160
+ /**
161
+ * Full WebSocket URL to connect to. Enables cross-origin and native app usage
162
+ * (Svelte Native, React Native, standalone clients). When set, the default
163
+ * same-origin URL is bypassed entirely.
164
+ * @example 'wss://my-app.com/ws'
165
+ */
166
+ url?: string;
160
167
  /** Called when the WebSocket connection opens (not on initial connect, only reconnects). */
161
168
  onConnect?(): void;
162
169
  /** Called when the WebSocket connection closes. */
package/client.js CHANGED
@@ -1513,7 +1513,7 @@ function _checkArgs(path, args) {
1513
1513
  * @typedef {{ path: string, args: any[], queuedAt: number, resolve: Function, reject: Function }} OfflineEntry
1514
1514
  */
1515
1515
 
1516
- /** @type {{ onConnect?: () => void, onDisconnect?: () => void, timeout?: number, offline?: { queue?: boolean, maxQueue?: number, maxAge?: number, replay?: 'sequential' | 'batch' | ((queue: OfflineEntry[]) => OfflineEntry[]), beforeReplay?: (call: { path: string, args: any[], queuedAt: number }) => boolean, onReplayError?: (call: { path: string, args: any[], queuedAt: number }, error: any) => void } }} */
1516
+ /** @type {{ url?: string, onConnect?: () => void, onDisconnect?: () => void, timeout?: number, offline?: { queue?: boolean, maxQueue?: number, maxAge?: number, replay?: 'sequential' | 'batch' | ((queue: OfflineEntry[]) => OfflineEntry[]), beforeReplay?: (call: { path: string, args: any[], queuedAt: number }) => boolean, onReplayError?: (call: { path: string, args: any[], queuedAt: number }, error: any) => void } }} */
1517
1517
  let _clientConfig = {};
1518
1518
 
1519
1519
  /** @type {boolean} */
@@ -1531,11 +1531,15 @@ let _replayingQueue = false;
1531
1531
  /**
1532
1532
  * Configure client-side connection hooks and offline queue.
1533
1533
  *
1534
- * @param {{ onConnect?: () => void, onDisconnect?: () => void, offline?: { queue?: boolean, maxQueue?: number, maxAge?: number, replay?: 'sequential' | 'batch' | ((queue: OfflineEntry[]) => OfflineEntry[]), beforeReplay?: (call: { path: string, args: any[], queuedAt: number }) => boolean, onReplayError?: (call: { path: string, args: any[], queuedAt: number }, error: any) => void } }} config
1534
+ * @param {{ url?: string, onConnect?: () => void, onDisconnect?: () => void, offline?: { queue?: boolean, maxQueue?: number, maxAge?: number, replay?: 'sequential' | 'batch' | ((queue: OfflineEntry[]) => OfflineEntry[]), beforeReplay?: (call: { path: string, args: any[], queuedAt: number }) => boolean, onReplayError?: (call: { path: string, args: any[], queuedAt: number }, error: any) => void } }} config
1535
1535
  */
1536
1536
  export function configure(config) {
1537
1537
  _clientConfig = config;
1538
1538
 
1539
+ if (config.url) {
1540
+ _connect({ url: config.url });
1541
+ }
1542
+
1539
1543
  if (!_configListenerAttached) {
1540
1544
  _configListenerAttached = true;
1541
1545
  let isFirst = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-realtime",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Realtime RPC and reactive subscriptions for SvelteKit, built on svelte-adapter-uws",
5
5
  "author": "Kevin Radziszewski",
6
6
  "license": "MIT",
@@ -69,7 +69,7 @@
69
69
  "peerDependencies": {
70
70
  "@sveltejs/kit": "^2.0.0",
71
71
  "svelte": "^4.0.0 || ^5.0.0",
72
- "svelte-adapter-uws": ">=0.4.1"
72
+ "svelte-adapter-uws": ">=0.4.8"
73
73
  },
74
74
  "devDependencies": {
75
75
  "vitest": "^4.0.18"
package/vite.js CHANGED
@@ -552,13 +552,14 @@ function _generateSsrStubs(filePath, modulePath) {
552
552
 
553
553
  for (const name of storeNames) {
554
554
  if (dynamicNames.has(name)) {
555
- // Dynamic stream: return a readable store from a function so name(args) works during SSR
556
- lines.push(`const _${name} = (...args) => readable(undefined);`);
555
+ // Dynamic stream: factory returns a readable with .hydrate() for SSR rendering
556
+ lines.push(`const _${name} = (...args) => { const s = readable(undefined); s.hydrate = (d) => readable(d); return s; };`);
557
557
  lines.push(`_${name}.load = (platform, options) => __directCall(${safeModulePath(name)}, options?.args || [], platform, options);`);
558
558
  lines.push(`export { _${name} as ${name} };`);
559
559
  } else {
560
- // Static stream: plain readable store
560
+ // Static stream: readable with .hydrate() for SSR rendering
561
561
  lines.push(`const _${name} = readable(undefined);`);
562
+ lines.push(`_${name}.hydrate = (d) => readable(d);`);
562
563
  lines.push(`_${name}.load = (platform, options) => __directCall(${safeModulePath(name)}, options?.args || [], platform, options);`);
563
564
  lines.push(`export { _${name} as ${name} };`);
564
565
  }