@interncom/diplomatic 0.0.54 → 0.0.56
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 +4 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +40 -15
- package/dist/react/statusBar.d.ts +3 -2
- package/dist/react/useClient.d.ts +2 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GroupID, IOp, KeyPair } from "./shared/types";
|
|
2
|
-
import type { IClientStateStore, IDiplomaticClientState } from "./types";
|
|
2
|
+
import type { IClientStateStore, IDiplomaticClientState, IDiplomaticClientXferState } from "./types";
|
|
3
3
|
import type { StateManager } from "./state";
|
|
4
4
|
export interface IDiplomaticClientParams {
|
|
5
5
|
store: IClientStateStore;
|
|
@@ -12,6 +12,7 @@ export default class DiplomaticClient {
|
|
|
12
12
|
store: IClientStateStore;
|
|
13
13
|
stateManager: StateManager;
|
|
14
14
|
listener?: (state: IDiplomaticClientState) => void;
|
|
15
|
+
xferListener?: (state: IDiplomaticClientXferState) => void;
|
|
15
16
|
seed?: Uint8Array;
|
|
16
17
|
encKey?: Uint8Array;
|
|
17
18
|
hostURL?: URL;
|
|
@@ -28,7 +29,9 @@ export default class DiplomaticClient {
|
|
|
28
29
|
disconnect: () => void;
|
|
29
30
|
registerAndConnect(hostURL: string): Promise<void>;
|
|
30
31
|
emitUpdate(): Promise<void>;
|
|
32
|
+
emitXferUpdate(): Promise<void>;
|
|
31
33
|
getState(): Promise<IDiplomaticClientState>;
|
|
34
|
+
getXferState(): Promise<IDiplomaticClientXferState>;
|
|
32
35
|
processOps(): Promise<void>;
|
|
33
36
|
pullOpPaths(): Promise<never[] | undefined>;
|
|
34
37
|
fetchAndExecQueuedOps(): Promise<never[] | undefined>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useClientState, useSyncOnResume } from "./react/useClient";
|
|
2
|
-
import {
|
|
1
|
+
import { useClientState, useClientXferState, useSyncOnResume } from "./react/useClient";
|
|
2
|
+
import { opMapApplier, StateManager } from "./state";
|
|
3
3
|
import { localStorageStore } from "./localStorageStore";
|
|
4
4
|
import { idbStore } from "./idbStore";
|
|
5
5
|
import type { IDiplomaticClientState } from "./types";
|
|
@@ -11,5 +11,5 @@ import useStateWatcher from "./react/useStateWatcher";
|
|
|
11
11
|
import InitSeedView from "./react/initSeedView";
|
|
12
12
|
import ClientStatusBar from "./react/statusBar";
|
|
13
13
|
import * as EntityDB from "./entityDB";
|
|
14
|
-
export {
|
|
15
|
-
export type { IOp, IUpsertOp
|
|
14
|
+
export { btoh, ClientStatusBar, DiplomaticClient, EntityDB, htob, idbStore, InitSeedView, libsodiumCrypto, localStorageStore, opMapApplier, StateManager, useClientState, useClientXferState, useStateWatcher, useSyncOnResume, Verb, };
|
|
15
|
+
export type { IDiplomaticClientState, IOp, IUpsertOp };
|
package/dist/index.mjs
CHANGED
|
@@ -2480,7 +2480,7 @@ var require_FileSaver_min = __commonJS({
|
|
|
2480
2480
|
});
|
|
2481
2481
|
|
|
2482
2482
|
// src/react/useClient.ts
|
|
2483
|
-
import {
|
|
2483
|
+
import { useEffect, useState } from "react";
|
|
2484
2484
|
function useClientState(client) {
|
|
2485
2485
|
const [state, setState] = useState();
|
|
2486
2486
|
useEffect(() => {
|
|
@@ -2496,6 +2496,21 @@ function useClientState(client) {
|
|
|
2496
2496
|
}, [client]);
|
|
2497
2497
|
return state;
|
|
2498
2498
|
}
|
|
2499
|
+
function useClientXferState(client) {
|
|
2500
|
+
const [state, setState] = useState();
|
|
2501
|
+
useEffect(() => {
|
|
2502
|
+
async function updateState() {
|
|
2503
|
+
const state2 = await client.getXferState();
|
|
2504
|
+
setState(state2);
|
|
2505
|
+
}
|
|
2506
|
+
client.xferListener = updateState;
|
|
2507
|
+
updateState();
|
|
2508
|
+
return () => {
|
|
2509
|
+
client.xferListener = void 0;
|
|
2510
|
+
};
|
|
2511
|
+
}, [client]);
|
|
2512
|
+
return state;
|
|
2513
|
+
}
|
|
2499
2514
|
function useSyncOnResume(client) {
|
|
2500
2515
|
useEffect(() => {
|
|
2501
2516
|
async function handleOnline() {
|
|
@@ -2928,8 +2943,8 @@ replaceTraps((oldTraps) => ({
|
|
|
2928
2943
|
}));
|
|
2929
2944
|
|
|
2930
2945
|
// src/idbStore.ts
|
|
2931
|
-
var initDB =
|
|
2932
|
-
return
|
|
2946
|
+
var initDB = () => {
|
|
2947
|
+
return openDB("client-store-db", 6, {
|
|
2933
2948
|
upgrade(db3) {
|
|
2934
2949
|
if (!db3.objectStoreNames.contains("metaKV")) {
|
|
2935
2950
|
db3.createObjectStore("metaKV");
|
|
@@ -11363,6 +11378,7 @@ var DiplomaticClient = class {
|
|
|
11363
11378
|
store;
|
|
11364
11379
|
stateManager;
|
|
11365
11380
|
listener;
|
|
11381
|
+
xferListener;
|
|
11366
11382
|
seed;
|
|
11367
11383
|
encKey;
|
|
11368
11384
|
hostURL;
|
|
@@ -11436,6 +11452,7 @@ var DiplomaticClient = class {
|
|
|
11436
11452
|
}
|
|
11437
11453
|
await this.sync();
|
|
11438
11454
|
this.emitUpdate();
|
|
11455
|
+
this.emitXferUpdate();
|
|
11439
11456
|
}
|
|
11440
11457
|
async loadSeed() {
|
|
11441
11458
|
const seed = await this.store.getSeed();
|
|
@@ -11501,13 +11518,20 @@ var DiplomaticClient = class {
|
|
|
11501
11518
|
const state = await this.getState();
|
|
11502
11519
|
this.listener?.(state);
|
|
11503
11520
|
}
|
|
11521
|
+
async emitXferUpdate() {
|
|
11522
|
+
const state = await this.getXferState();
|
|
11523
|
+
this.xferListener?.(state);
|
|
11524
|
+
}
|
|
11504
11525
|
async getState() {
|
|
11505
11526
|
const hasSeed = this.seed !== void 0 && this.encKey !== void 0;
|
|
11506
11527
|
const hasHost = this.hostURL !== void 0 && this.hostKeyPair !== void 0;
|
|
11507
11528
|
const connected = this.websocket === void 0 ? false : this.websocket.readyState === this.websocket.OPEN;
|
|
11529
|
+
return { hasSeed, hasHost, connected };
|
|
11530
|
+
}
|
|
11531
|
+
async getXferState() {
|
|
11508
11532
|
const numUploads = await this.store.numUploads();
|
|
11509
11533
|
const numDownloads = await this.store.numDownloads();
|
|
11510
|
-
return {
|
|
11534
|
+
return { numDownloads, numUploads };
|
|
11511
11535
|
}
|
|
11512
11536
|
async processOps() {
|
|
11513
11537
|
await this.pullOpPaths();
|
|
@@ -11523,7 +11547,7 @@ var DiplomaticClient = class {
|
|
|
11523
11547
|
const resp = await api_default.listDeltas(hostURL, begin, hostKeyPair);
|
|
11524
11548
|
for (const item of resp.deltas) {
|
|
11525
11549
|
await this.store.enqueueDownload(item.sha256, item.recordedAt);
|
|
11526
|
-
this.
|
|
11550
|
+
this.emitXferUpdate();
|
|
11527
11551
|
}
|
|
11528
11552
|
await this.store.setLastFetchedAt(new Date(resp.fetchedAt));
|
|
11529
11553
|
}
|
|
@@ -11537,7 +11561,7 @@ var DiplomaticClient = class {
|
|
|
11537
11561
|
for (const item of items) {
|
|
11538
11562
|
if (await this.store.hasOp(item.sha256)) {
|
|
11539
11563
|
await this.store.dequeueDownload(item.sha256);
|
|
11540
|
-
this.
|
|
11564
|
+
this.emitXferUpdate();
|
|
11541
11565
|
continue;
|
|
11542
11566
|
}
|
|
11543
11567
|
try {
|
|
@@ -11555,12 +11579,12 @@ var DiplomaticClient = class {
|
|
|
11555
11579
|
await this.stateManager.apply(op);
|
|
11556
11580
|
await this.store.storeOp(sha256, cipher);
|
|
11557
11581
|
await this.store.dequeueDownload(sha256);
|
|
11558
|
-
this.
|
|
11582
|
+
this.emitXferUpdate();
|
|
11559
11583
|
} catch {
|
|
11560
11584
|
const transient = true;
|
|
11561
11585
|
if (!transient) {
|
|
11562
11586
|
await this.store.dequeueDownload(item.sha256);
|
|
11563
|
-
this.
|
|
11587
|
+
this.emitXferUpdate();
|
|
11564
11588
|
}
|
|
11565
11589
|
}
|
|
11566
11590
|
}
|
|
@@ -11574,7 +11598,7 @@ var DiplomaticClient = class {
|
|
|
11574
11598
|
await api_default.putDelta(this.hostURL, cipherOp, this.hostKeyPair);
|
|
11575
11599
|
}
|
|
11576
11600
|
await this.store.dequeueUpload(sha256);
|
|
11577
|
-
this.
|
|
11601
|
+
this.emitXferUpdate();
|
|
11578
11602
|
}
|
|
11579
11603
|
async pushQueuedOps() {
|
|
11580
11604
|
for (const sha256 of await this.store.listUploads()) {
|
|
@@ -11596,13 +11620,13 @@ var DiplomaticClient = class {
|
|
|
11596
11620
|
);
|
|
11597
11621
|
const sha256 = await crypto_default.sha256Hash(cipherOp);
|
|
11598
11622
|
await this.store.enqueueUpload(sha256, cipherOp);
|
|
11599
|
-
this.
|
|
11623
|
+
this.emitXferUpdate();
|
|
11600
11624
|
try {
|
|
11601
11625
|
await this.stateManager.apply(op);
|
|
11602
11626
|
await this.store.storeOp(sha256, cipherOp);
|
|
11603
11627
|
} catch (err) {
|
|
11604
11628
|
await this.store.dequeueUpload(sha256);
|
|
11605
|
-
this.
|
|
11629
|
+
this.emitXferUpdate();
|
|
11606
11630
|
}
|
|
11607
11631
|
try {
|
|
11608
11632
|
await this.pushQueuedOp(sha256);
|
|
@@ -11643,7 +11667,7 @@ var DiplomaticClient = class {
|
|
|
11643
11667
|
const sha256 = await crypto_default.sha256Hash(cipher);
|
|
11644
11668
|
await this.stateManager.apply(op);
|
|
11645
11669
|
await this.store.storeOp(sha256, cipher);
|
|
11646
|
-
this.
|
|
11670
|
+
this.emitXferUpdate();
|
|
11647
11671
|
}
|
|
11648
11672
|
};
|
|
11649
11673
|
async upsert({ type, body, eid, gid, version = 0 }) {
|
|
@@ -11716,7 +11740,7 @@ function DotLabel({ on, label }) {
|
|
|
11716
11740
|
label
|
|
11717
11741
|
] });
|
|
11718
11742
|
}
|
|
11719
|
-
function ClientStatusBar({ state }) {
|
|
11743
|
+
function ClientStatusBar({ state, xferState }) {
|
|
11720
11744
|
return /* @__PURE__ */ jsxs2(
|
|
11721
11745
|
"div",
|
|
11722
11746
|
{
|
|
@@ -11735,11 +11759,11 @@ function ClientStatusBar({ state }) {
|
|
|
11735
11759
|
/* @__PURE__ */ jsx2(DotLabel, { on: state.connected, label: "LINK" }),
|
|
11736
11760
|
/* @__PURE__ */ jsxs2("div", { style: { marginRight: 16 }, children: [
|
|
11737
11761
|
"\u21D1 ",
|
|
11738
|
-
|
|
11762
|
+
xferState.numUploads
|
|
11739
11763
|
] }),
|
|
11740
11764
|
/* @__PURE__ */ jsxs2("div", { children: [
|
|
11741
11765
|
"\u21D3 ",
|
|
11742
|
-
|
|
11766
|
+
xferState.numDownloads
|
|
11743
11767
|
] })
|
|
11744
11768
|
]
|
|
11745
11769
|
}
|
|
@@ -11820,6 +11844,7 @@ export {
|
|
|
11820
11844
|
localStorageStore,
|
|
11821
11845
|
opMapApplier,
|
|
11822
11846
|
useClientState,
|
|
11847
|
+
useClientXferState,
|
|
11823
11848
|
useStateWatcher,
|
|
11824
11849
|
useSyncOnResume
|
|
11825
11850
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { IDiplomaticClientState } from "../types";
|
|
1
|
+
import type { IDiplomaticClientState, IDiplomaticClientXferState } from "../types";
|
|
2
2
|
interface IProps {
|
|
3
3
|
state: IDiplomaticClientState;
|
|
4
|
+
xferState: IDiplomaticClientXferState;
|
|
4
5
|
}
|
|
5
|
-
export default function ClientStatusBar({ state }: IProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default function ClientStatusBar({ state, xferState }: IProps): import("react/jsx-runtime").JSX.Element;
|
|
6
7
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { IDiplomaticClientState } from "../types";
|
|
1
|
+
import type { IDiplomaticClientState, IDiplomaticClientXferState } from "../types";
|
|
2
2
|
import type DiplomaticClient from "../client";
|
|
3
3
|
export declare function useClientState(client: DiplomaticClient): IDiplomaticClientState | undefined;
|
|
4
|
+
export declare function useClientXferState(client: DiplomaticClient): IDiplomaticClientXferState | undefined;
|
|
4
5
|
export declare function useSyncOnResume(client: DiplomaticClient): void;
|
package/dist/types.d.ts
CHANGED