@interncom/diplomatic 0.0.23 → 0.0.25

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/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { IOp, KeyPair } from "./shared/types";
2
- import type { IClientStateStore, Applier, IDiplomaticClientState } from "./types";
2
+ import type { IClientStateStore, IDiplomaticClientState } from "./types";
3
3
  import type { StateManager } from "./state";
4
4
  export interface IDiplomaticClientParams {
5
5
  store: IClientStateStore;
@@ -10,7 +10,7 @@ export interface IDiplomaticClientParams {
10
10
  }
11
11
  export default class DiplomaticClient {
12
12
  store: IClientStateStore;
13
- applier: Applier;
13
+ stateManager: StateManager;
14
14
  listener?: (state: IDiplomaticClientState) => void;
15
15
  seed?: Uint8Array;
16
16
  encKey?: Uint8Array;
package/dist/index.mjs CHANGED
@@ -29,8 +29,11 @@ function useClientState(client) {
29
29
  }
30
30
  function useSyncOnResume(client) {
31
31
  useEffect(() => {
32
- function handleOnline() {
33
- client.sync();
32
+ async function handleOnline() {
33
+ if (client.hostURL) {
34
+ await client.connect(client.hostURL);
35
+ }
36
+ await client.sync();
34
37
  }
35
38
  window.addEventListener("online", handleOnline);
36
39
  return () => {
@@ -68,8 +71,10 @@ var EventEmitter = class {
68
71
  var StateManager = class {
69
72
  emitter = new EventEmitter();
70
73
  applier;
71
- constructor(applier) {
74
+ clear;
75
+ constructor(applier, clear) {
72
76
  this.applier = applier;
77
+ this.clear = clear;
73
78
  }
74
79
  apply = async (op) => {
75
80
  await this.applier(op);
@@ -8776,7 +8781,7 @@ function genUpsertOp(type, body, version = 0) {
8776
8781
  // src/client.ts
8777
8782
  var DiplomaticClient = class {
8778
8783
  store;
8779
- applier;
8784
+ stateManager;
8780
8785
  listener;
8781
8786
  seed;
8782
8787
  encKey;
@@ -8785,7 +8790,7 @@ var DiplomaticClient = class {
8785
8790
  lastFetchedAt;
8786
8791
  constructor(params) {
8787
8792
  this.store = params.store;
8788
- this.applier = params.stateManager.apply;
8793
+ this.stateManager = params.stateManager;
8789
8794
  this.init(params);
8790
8795
  }
8791
8796
  wipe = async () => {
@@ -8796,6 +8801,7 @@ var DiplomaticClient = class {
8796
8801
  this.lastFetchedAt = void 0;
8797
8802
  this.websocket?.close();
8798
8803
  this.websocket = void 0;
8804
+ await this.stateManager.clear();
8799
8805
  await this.store.wipe();
8800
8806
  this.emitUpdate();
8801
8807
  };
@@ -8945,7 +8951,7 @@ var DiplomaticClient = class {
8945
8951
  const packed = await crypto_default.decryptXSalsa20Poly1305Combined(cipher, encKey);
8946
8952
  const op = decode(packed);
8947
8953
  try {
8948
- await this.applier(op);
8954
+ await this.stateManager.apply(op);
8949
8955
  await this.store.dequeueDownload(path);
8950
8956
  this.emitUpdate();
8951
8957
  } catch {
@@ -8988,7 +8994,7 @@ var DiplomaticClient = class {
8988
8994
  await this.store.enqueueUpload(shaHex, cipherOp);
8989
8995
  this.emitUpdate();
8990
8996
  try {
8991
- await this.applier(op);
8997
+ await this.stateManager.apply(op);
8992
8998
  } catch {
8993
8999
  await this.store.dequeueUpload(shaHex);
8994
9000
  this.emitUpdate();
package/dist/state.d.ts CHANGED
@@ -4,7 +4,8 @@ import type { IOp } from "./shared/types";
4
4
  export declare class StateManager {
5
5
  emitter: EventEmitter;
6
6
  applier: Applier;
7
- constructor(applier: Applier);
7
+ clear: () => void;
8
+ constructor(applier: Applier, clear: () => Promise<void>);
8
9
  apply: (op: IOp) => Promise<void>;
9
10
  on: (opType: string, listener: () => void) => void;
10
11
  off: (opType: string, listener: () => void) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interncom/diplomatic",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "description": "Secure sync layer",
6
6
  "main": "dist/index.mjs",