@interncom/diplomatic 0.0.23 → 0.0.24
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 +2 -2
- package/dist/index.mjs +8 -5
- package/dist/state.d.ts +2 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IOp, KeyPair } from "./shared/types";
|
|
2
|
-
import type { IClientStateStore,
|
|
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
|
-
|
|
13
|
+
stateManager: StateManager;
|
|
14
14
|
listener?: (state: IDiplomaticClientState) => void;
|
|
15
15
|
seed?: Uint8Array;
|
|
16
16
|
encKey?: Uint8Array;
|
package/dist/index.mjs
CHANGED
|
@@ -68,8 +68,10 @@ var EventEmitter = class {
|
|
|
68
68
|
var StateManager = class {
|
|
69
69
|
emitter = new EventEmitter();
|
|
70
70
|
applier;
|
|
71
|
-
|
|
71
|
+
clear;
|
|
72
|
+
constructor(applier, clear) {
|
|
72
73
|
this.applier = applier;
|
|
74
|
+
this.clear = clear;
|
|
73
75
|
}
|
|
74
76
|
apply = async (op) => {
|
|
75
77
|
await this.applier(op);
|
|
@@ -8776,7 +8778,7 @@ function genUpsertOp(type, body, version = 0) {
|
|
|
8776
8778
|
// src/client.ts
|
|
8777
8779
|
var DiplomaticClient = class {
|
|
8778
8780
|
store;
|
|
8779
|
-
|
|
8781
|
+
stateManager;
|
|
8780
8782
|
listener;
|
|
8781
8783
|
seed;
|
|
8782
8784
|
encKey;
|
|
@@ -8785,7 +8787,7 @@ var DiplomaticClient = class {
|
|
|
8785
8787
|
lastFetchedAt;
|
|
8786
8788
|
constructor(params) {
|
|
8787
8789
|
this.store = params.store;
|
|
8788
|
-
this.
|
|
8790
|
+
this.stateManager = params.stateManager;
|
|
8789
8791
|
this.init(params);
|
|
8790
8792
|
}
|
|
8791
8793
|
wipe = async () => {
|
|
@@ -8796,6 +8798,7 @@ var DiplomaticClient = class {
|
|
|
8796
8798
|
this.lastFetchedAt = void 0;
|
|
8797
8799
|
this.websocket?.close();
|
|
8798
8800
|
this.websocket = void 0;
|
|
8801
|
+
await this.stateManager.clear();
|
|
8799
8802
|
await this.store.wipe();
|
|
8800
8803
|
this.emitUpdate();
|
|
8801
8804
|
};
|
|
@@ -8945,7 +8948,7 @@ var DiplomaticClient = class {
|
|
|
8945
8948
|
const packed = await crypto_default.decryptXSalsa20Poly1305Combined(cipher, encKey);
|
|
8946
8949
|
const op = decode(packed);
|
|
8947
8950
|
try {
|
|
8948
|
-
await this.
|
|
8951
|
+
await this.stateManager.apply(op);
|
|
8949
8952
|
await this.store.dequeueDownload(path);
|
|
8950
8953
|
this.emitUpdate();
|
|
8951
8954
|
} catch {
|
|
@@ -8988,7 +8991,7 @@ var DiplomaticClient = class {
|
|
|
8988
8991
|
await this.store.enqueueUpload(shaHex, cipherOp);
|
|
8989
8992
|
this.emitUpdate();
|
|
8990
8993
|
try {
|
|
8991
|
-
await this.
|
|
8994
|
+
await this.stateManager.apply(op);
|
|
8992
8995
|
} catch {
|
|
8993
8996
|
await this.store.dequeueUpload(shaHex);
|
|
8994
8997
|
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
|
-
|
|
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;
|