@interncom/diplomatic 0.0.54 → 0.0.55
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.mjs +24 -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.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(() => {
|
|
@@ -2928,8 +2928,8 @@ replaceTraps((oldTraps) => ({
|
|
|
2928
2928
|
}));
|
|
2929
2929
|
|
|
2930
2930
|
// src/idbStore.ts
|
|
2931
|
-
var initDB =
|
|
2932
|
-
return
|
|
2931
|
+
var initDB = () => {
|
|
2932
|
+
return openDB("client-store-db", 6, {
|
|
2933
2933
|
upgrade(db3) {
|
|
2934
2934
|
if (!db3.objectStoreNames.contains("metaKV")) {
|
|
2935
2935
|
db3.createObjectStore("metaKV");
|
|
@@ -11363,6 +11363,7 @@ var DiplomaticClient = class {
|
|
|
11363
11363
|
store;
|
|
11364
11364
|
stateManager;
|
|
11365
11365
|
listener;
|
|
11366
|
+
xferListener;
|
|
11366
11367
|
seed;
|
|
11367
11368
|
encKey;
|
|
11368
11369
|
hostURL;
|
|
@@ -11436,6 +11437,7 @@ var DiplomaticClient = class {
|
|
|
11436
11437
|
}
|
|
11437
11438
|
await this.sync();
|
|
11438
11439
|
this.emitUpdate();
|
|
11440
|
+
this.emitXferUpdate();
|
|
11439
11441
|
}
|
|
11440
11442
|
async loadSeed() {
|
|
11441
11443
|
const seed = await this.store.getSeed();
|
|
@@ -11501,13 +11503,20 @@ var DiplomaticClient = class {
|
|
|
11501
11503
|
const state = await this.getState();
|
|
11502
11504
|
this.listener?.(state);
|
|
11503
11505
|
}
|
|
11506
|
+
async emitXferUpdate() {
|
|
11507
|
+
const state = await this.getXferState();
|
|
11508
|
+
this.xferListener?.(state);
|
|
11509
|
+
}
|
|
11504
11510
|
async getState() {
|
|
11505
11511
|
const hasSeed = this.seed !== void 0 && this.encKey !== void 0;
|
|
11506
11512
|
const hasHost = this.hostURL !== void 0 && this.hostKeyPair !== void 0;
|
|
11507
11513
|
const connected = this.websocket === void 0 ? false : this.websocket.readyState === this.websocket.OPEN;
|
|
11514
|
+
return { hasSeed, hasHost, connected };
|
|
11515
|
+
}
|
|
11516
|
+
async getXferState() {
|
|
11508
11517
|
const numUploads = await this.store.numUploads();
|
|
11509
11518
|
const numDownloads = await this.store.numDownloads();
|
|
11510
|
-
return {
|
|
11519
|
+
return { numDownloads, numUploads };
|
|
11511
11520
|
}
|
|
11512
11521
|
async processOps() {
|
|
11513
11522
|
await this.pullOpPaths();
|
|
@@ -11523,7 +11532,7 @@ var DiplomaticClient = class {
|
|
|
11523
11532
|
const resp = await api_default.listDeltas(hostURL, begin, hostKeyPair);
|
|
11524
11533
|
for (const item of resp.deltas) {
|
|
11525
11534
|
await this.store.enqueueDownload(item.sha256, item.recordedAt);
|
|
11526
|
-
this.
|
|
11535
|
+
this.emitXferUpdate();
|
|
11527
11536
|
}
|
|
11528
11537
|
await this.store.setLastFetchedAt(new Date(resp.fetchedAt));
|
|
11529
11538
|
}
|
|
@@ -11537,7 +11546,7 @@ var DiplomaticClient = class {
|
|
|
11537
11546
|
for (const item of items) {
|
|
11538
11547
|
if (await this.store.hasOp(item.sha256)) {
|
|
11539
11548
|
await this.store.dequeueDownload(item.sha256);
|
|
11540
|
-
this.
|
|
11549
|
+
this.emitXferUpdate();
|
|
11541
11550
|
continue;
|
|
11542
11551
|
}
|
|
11543
11552
|
try {
|
|
@@ -11555,12 +11564,12 @@ var DiplomaticClient = class {
|
|
|
11555
11564
|
await this.stateManager.apply(op);
|
|
11556
11565
|
await this.store.storeOp(sha256, cipher);
|
|
11557
11566
|
await this.store.dequeueDownload(sha256);
|
|
11558
|
-
this.
|
|
11567
|
+
this.emitXferUpdate();
|
|
11559
11568
|
} catch {
|
|
11560
11569
|
const transient = true;
|
|
11561
11570
|
if (!transient) {
|
|
11562
11571
|
await this.store.dequeueDownload(item.sha256);
|
|
11563
|
-
this.
|
|
11572
|
+
this.emitXferUpdate();
|
|
11564
11573
|
}
|
|
11565
11574
|
}
|
|
11566
11575
|
}
|
|
@@ -11574,7 +11583,7 @@ var DiplomaticClient = class {
|
|
|
11574
11583
|
await api_default.putDelta(this.hostURL, cipherOp, this.hostKeyPair);
|
|
11575
11584
|
}
|
|
11576
11585
|
await this.store.dequeueUpload(sha256);
|
|
11577
|
-
this.
|
|
11586
|
+
this.emitXferUpdate();
|
|
11578
11587
|
}
|
|
11579
11588
|
async pushQueuedOps() {
|
|
11580
11589
|
for (const sha256 of await this.store.listUploads()) {
|
|
@@ -11596,13 +11605,13 @@ var DiplomaticClient = class {
|
|
|
11596
11605
|
);
|
|
11597
11606
|
const sha256 = await crypto_default.sha256Hash(cipherOp);
|
|
11598
11607
|
await this.store.enqueueUpload(sha256, cipherOp);
|
|
11599
|
-
this.
|
|
11608
|
+
this.emitXferUpdate();
|
|
11600
11609
|
try {
|
|
11601
11610
|
await this.stateManager.apply(op);
|
|
11602
11611
|
await this.store.storeOp(sha256, cipherOp);
|
|
11603
11612
|
} catch (err) {
|
|
11604
11613
|
await this.store.dequeueUpload(sha256);
|
|
11605
|
-
this.
|
|
11614
|
+
this.emitXferUpdate();
|
|
11606
11615
|
}
|
|
11607
11616
|
try {
|
|
11608
11617
|
await this.pushQueuedOp(sha256);
|
|
@@ -11643,7 +11652,7 @@ var DiplomaticClient = class {
|
|
|
11643
11652
|
const sha256 = await crypto_default.sha256Hash(cipher);
|
|
11644
11653
|
await this.stateManager.apply(op);
|
|
11645
11654
|
await this.store.storeOp(sha256, cipher);
|
|
11646
|
-
this.
|
|
11655
|
+
this.emitXferUpdate();
|
|
11647
11656
|
}
|
|
11648
11657
|
};
|
|
11649
11658
|
async upsert({ type, body, eid, gid, version = 0 }) {
|
|
@@ -11716,7 +11725,7 @@ function DotLabel({ on, label }) {
|
|
|
11716
11725
|
label
|
|
11717
11726
|
] });
|
|
11718
11727
|
}
|
|
11719
|
-
function ClientStatusBar({ state }) {
|
|
11728
|
+
function ClientStatusBar({ state, xferState }) {
|
|
11720
11729
|
return /* @__PURE__ */ jsxs2(
|
|
11721
11730
|
"div",
|
|
11722
11731
|
{
|
|
@@ -11735,11 +11744,11 @@ function ClientStatusBar({ state }) {
|
|
|
11735
11744
|
/* @__PURE__ */ jsx2(DotLabel, { on: state.connected, label: "LINK" }),
|
|
11736
11745
|
/* @__PURE__ */ jsxs2("div", { style: { marginRight: 16 }, children: [
|
|
11737
11746
|
"\u21D1 ",
|
|
11738
|
-
|
|
11747
|
+
xferState.numUploads
|
|
11739
11748
|
] }),
|
|
11740
11749
|
/* @__PURE__ */ jsxs2("div", { children: [
|
|
11741
11750
|
"\u21D3 ",
|
|
11742
|
-
|
|
11751
|
+
xferState.numDownloads
|
|
11743
11752
|
] })
|
|
11744
11753
|
]
|
|
11745
11754
|
}
|
|
@@ -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