svelte-realtime 0.4.16 → 0.4.18

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.
Files changed (3) hide show
  1. package/client.js +4 -4
  2. package/package.json +1 -1
  3. package/server.js +22 -5
package/client.js CHANGED
@@ -938,10 +938,10 @@ function _createStream(path, options, dynamicArgs) {
938
938
  for (const evt of response.data) {
939
939
  _applyMerge(evt);
940
940
  }
941
- } else if (response.channel && currentValue !== undefined) {
942
- // Channel fast-path returns an empty placeholder (null or []).
943
- // Keep the existing value (hydrated SSR data or previously
944
- // accumulated events) so the store never flashes to empty.
941
+ } else if ((response.channel || response.derived) && currentValue !== undefined) {
942
+ // Keep the existing value so the store never flashes to empty.
943
+ // Channels return an empty placeholder; derived streams may
944
+ // return stale data before their sources populate.
945
945
  } else {
946
946
  currentValue = response.data;
947
947
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-realtime",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "description": "Realtime RPC and reactive subscriptions for SvelteKit, built on svelte-adapter-uws",
5
5
  "author": "Kevin Radziszewski",
6
6
  "license": "MIT",
package/server.js CHANGED
@@ -1369,8 +1369,24 @@ export function __registerDerived(path, fn) {
1369
1369
  if (/** @type {any} */ (fn).__derivedDynamic) {
1370
1370
  const sourceFactory = /** @type {any} */ (fn).__derivedSourceFactory;
1371
1371
  const debounce = /** @type {any} */ (fn).__derivedDebounce || 0;
1372
+
1373
+ /** @type {Map<string, any[]>} */
1374
+ const topicArgs = new Map();
1375
+ const topicFn = (...args) => {
1376
+ const t = path + '\x00' + args.map(a => String(a).replace(/\x00/g, '')).join('\x00');
1377
+ topicArgs.set(t, args);
1378
+ if (topicArgs.size > 10000) {
1379
+ const iter = topicArgs.keys();
1380
+ topicArgs.delete(iter.next().value);
1381
+ }
1382
+ return t;
1383
+ };
1384
+ /** @type {any} */ (topicFn).__topicUsesCtx = false;
1385
+ /** @type {any} */ (fn).__streamTopic = topicFn;
1386
+ /** @type {any} */ (fn).__derivedTopicArgs = topicArgs;
1387
+
1372
1388
  const entry = {
1373
- sources: null, sourceFactory, fn, topic: /** @type {any} */ (fn).__streamTopic,
1389
+ sources: null, sourceFactory, fn, topic: topicFn,
1374
1390
  debounce, timer: null, dynamic: true, instances: new Map()
1375
1391
  };
1376
1392
  derivedRegistry.set(path, entry);
@@ -1379,11 +1395,11 @@ export function __registerDerived(path, fn) {
1379
1395
  return;
1380
1396
  }
1381
1397
 
1398
+ /** @type {any} */ (fn).__streamTopic = path;
1382
1399
  const sources = /** @type {any} */ (fn).__derivedSources;
1383
- const topic = /** @type {any} */ (fn).__streamTopic;
1384
1400
  const debounce = /** @type {any} */ (fn).__derivedDebounce || 0;
1385
- if (!sources || !topic) return;
1386
- derivedRegistry.set(path, { sources, fn, topic, debounce, timer: null });
1401
+ if (!sources) return;
1402
+ derivedRegistry.set(path, { sources, fn, topic: path, debounce, timer: null });
1387
1403
  for (const src of sources) {
1388
1404
  let set = _derivedBySource.get(src);
1389
1405
  if (!set) { set = new Set(); _derivedBySource.set(src, set); }
@@ -2343,7 +2359,8 @@ async function _executeSingleRpc(ws, msg, platform, options) {
2343
2359
  id, ok: true, data: resultData, topic, merge: streamOpts.merge,
2344
2360
  key: streamOpts.key, prepend: streamOpts.prepend, max: streamOpts.max,
2345
2361
  hasMore: undefined, cursor: undefined, seq: undefined,
2346
- version: undefined, schemaVersion: undefined, replay: undefined
2362
+ version: undefined, schemaVersion: undefined, replay: undefined,
2363
+ derived: /** @type {any} */ (fn).__isDerived || undefined
2347
2364
  };
2348
2365
 
2349
2366
  if (isPaginated) {