remote-state-sync 1.0.2 → 1.0.3

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { SuperJSONResult } from 'superjson';
1
2
  import Nanobus from 'nanobus';
2
3
  import { Ref, ShallowRef } from '@vue/reactivity';
3
4
 
@@ -9,7 +10,7 @@ interface Patch {
9
10
  value?: unknown;
10
11
  }
11
12
  interface SyncOptions {
12
- snapshotGetter: (namespace: string) => Promise<Record<string, unknown>>;
13
+ snapshotGetter: (namespace: string) => Promise<SyncSnapshot>;
13
14
  }
14
15
  type SyncUpdater<T> = (state: T) => T | void;
15
16
  type SyncBusDefinition = {
@@ -19,13 +20,14 @@ type SyncBusDefinition = {
19
20
  type ReceiverItemBusDefinition<T> = {
20
21
  update: (newValue: T, oldValue: T, patches: Patch[]) => void;
21
22
  };
23
+ type SyncSnapshot = SuperJSONResult;
22
24
 
23
25
  declare class SyncProvider {
24
26
  private namespaces;
25
27
  readonly bus: Nanobus<SyncBusDefinition>;
26
28
  constructor();
27
29
  register(namespace: string): SyncNamespaceProvider;
28
- getStateSnapshot(namespace: string): Promise<Record<string, unknown>>;
30
+ getStateSnapshot(namespace: string): SyncSnapshot;
29
31
  }
30
32
  declare class SyncNamespaceProvider {
31
33
  readonly namespace: string;
@@ -35,7 +37,7 @@ declare class SyncNamespaceProvider {
35
37
  private emitTimeout;
36
38
  constructor(namespace: string, bus: Nanobus<SyncBusDefinition>);
37
39
  sync<T>(key: string, initialValue?: T): SyncItemProvider<T>;
38
- getSnapshot(): Record<string, unknown>;
40
+ getSnapshot(): SyncSnapshot;
39
41
  private queuePatch;
40
42
  private emitPatches;
41
43
  }
@@ -60,7 +62,7 @@ declare class SyncNamespaceReceiver {
60
62
  readonly namespace: string;
61
63
  private snapshot;
62
64
  private items;
63
- constructor(namespace: string, snapshot: Record<string, unknown>);
65
+ constructor(namespace: string, snapshot: SyncSnapshot);
64
66
  sync<T>(key: string): SyncItemReceiver<T>;
65
67
  applyPatches(patches: Patch[]): void;
66
68
  private applyPatchToObject;
@@ -81,4 +83,4 @@ declare class SyncItemReceiver<T> {
81
83
  dispose(): void;
82
84
  }
83
85
 
84
- export { type Patch, type PatchOperation, type ReceiverItemBusDefinition, type SyncBusDefinition, SyncItemProvider, SyncItemReceiver, SyncNamespaceProvider, SyncNamespaceReceiver, type SyncOptions, SyncProvider, SyncReceiver, type SyncUpdater };
86
+ export { type Patch, type PatchOperation, type ReceiverItemBusDefinition, type SyncBusDefinition, SyncItemProvider, SyncItemReceiver, SyncNamespaceProvider, SyncNamespaceReceiver, type SyncOptions, SyncProvider, SyncReceiver, type SyncSnapshot, type SyncUpdater };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/provider.ts
2
2
  import Nanobus from "nanobus";
3
+ import SuperJSON from "superjson";
3
4
 
4
5
  // src/utils.ts
5
6
  function isObject(val) {
@@ -250,7 +251,7 @@ var SyncProvider = class {
250
251
  this.bus.emit("register", namespace);
251
252
  return ns;
252
253
  }
253
- async getStateSnapshot(namespace) {
254
+ getStateSnapshot(namespace) {
254
255
  const ns = this.namespaces.get(namespace);
255
256
  if (!ns) {
256
257
  throw new Error(`Namespace ${namespace} not found`);
@@ -281,7 +282,7 @@ var SyncNamespaceProvider = class {
281
282
  for (const [key, item] of this.items.entries()) {
282
283
  snapshot[key] = item.toValue();
283
284
  }
284
- return snapshot;
285
+ return SuperJSON.serialize(snapshot);
285
286
  }
286
287
  queuePatch(patch) {
287
288
  this.queuedPatches.push(patch);
@@ -336,6 +337,7 @@ var SyncItemProvider = class {
336
337
  // src/receiver.ts
337
338
  import Nanobus2 from "nanobus";
338
339
  import { shallowRef, ref, triggerRef } from "@vue/reactivity";
340
+ import SuperJSON2 from "superjson";
339
341
  var SyncReceiver = class {
340
342
  constructor(options) {
341
343
  this.options = options;
@@ -367,7 +369,8 @@ var SyncNamespaceReceiver = class {
367
369
  if (this.items.has(key)) {
368
370
  return this.items.get(key);
369
371
  }
370
- const val = this.snapshot[key];
372
+ const snapshot = SuperJSON2.deserialize(this.snapshot);
373
+ const val = snapshot[key];
371
374
  const item = new SyncItemReceiver(key, val);
372
375
  this.items.set(key, item);
373
376
  return item;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remote-state-sync",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A lightweight, fully type-safe unidirectional remote state synchronization library.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -26,9 +26,11 @@
26
26
  "types": "./dist/index.d.ts",
27
27
  "exports": {
28
28
  ".": {
29
+ "types": "./dist/index.d.ts",
29
30
  "import": "./dist/index.js",
30
- "types": "./dist/index.d.ts"
31
- }
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./package.json": "./package.json"
32
34
  },
33
35
  "files": [
34
36
  "dist"
@@ -66,6 +68,7 @@
66
68
  },
67
69
  "dependencies": {
68
70
  "@vue/reactivity": "^3.5.28",
69
- "nanobus": "^4.5.0"
71
+ "nanobus": "^4.5.0",
72
+ "superjson": "^2.2.6"
70
73
  }
71
74
  }