@interncom/diplomatic 0.0.53 → 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 +59 -38
- 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(() => {
|
|
@@ -2831,6 +2831,17 @@ function openDB(name, version, { blocked, upgrade, blocking, terminated } = {})
|
|
|
2831
2831
|
});
|
|
2832
2832
|
return openPromise;
|
|
2833
2833
|
}
|
|
2834
|
+
function deleteDB(name, { blocked } = {}) {
|
|
2835
|
+
const request = indexedDB.deleteDatabase(name);
|
|
2836
|
+
if (blocked) {
|
|
2837
|
+
request.addEventListener("blocked", (event) => blocked(
|
|
2838
|
+
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
2839
|
+
event.oldVersion,
|
|
2840
|
+
event
|
|
2841
|
+
));
|
|
2842
|
+
}
|
|
2843
|
+
return wrap(request).then(() => void 0);
|
|
2844
|
+
}
|
|
2834
2845
|
var readMethods = ["get", "getKey", "getAll", "getAllKeys", "count"];
|
|
2835
2846
|
var writeMethods = ["put", "add", "delete", "clear"];
|
|
2836
2847
|
var cachedMethods = /* @__PURE__ */ new Map();
|
|
@@ -2917,38 +2928,39 @@ replaceTraps((oldTraps) => ({
|
|
|
2917
2928
|
}));
|
|
2918
2929
|
|
|
2919
2930
|
// src/idbStore.ts
|
|
2920
|
-
var
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
db3.
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
db3.
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
db3.
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
db3.
|
|
2937
|
-
|
|
2938
|
-
|
|
2931
|
+
var initDB = () => {
|
|
2932
|
+
return openDB("client-store-db", 6, {
|
|
2933
|
+
upgrade(db3) {
|
|
2934
|
+
if (!db3.objectStoreNames.contains("metaKV")) {
|
|
2935
|
+
db3.createObjectStore("metaKV");
|
|
2936
|
+
}
|
|
2937
|
+
if (!db3.objectStoreNames.contains("ops")) {
|
|
2938
|
+
db3.createObjectStore("ops", {
|
|
2939
|
+
keyPath: "sha256"
|
|
2940
|
+
});
|
|
2941
|
+
}
|
|
2942
|
+
if (!db3.objectStoreNames.contains("uploadQueue")) {
|
|
2943
|
+
db3.createObjectStore("uploadQueue", {
|
|
2944
|
+
keyPath: "sha256"
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
if (!db3.objectStoreNames.contains("downloadQueue")) {
|
|
2948
|
+
db3.createObjectStore("downloadQueue", {
|
|
2949
|
+
keyPath: "sha256"
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2939
2952
|
}
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2953
|
+
});
|
|
2954
|
+
};
|
|
2955
|
+
var db = await initDB();
|
|
2942
2956
|
var IDBStore = class {
|
|
2943
2957
|
seed;
|
|
2944
2958
|
hostURL;
|
|
2945
2959
|
hostID;
|
|
2946
2960
|
lastFetchedAt;
|
|
2947
2961
|
async wipe() {
|
|
2948
|
-
await
|
|
2949
|
-
await
|
|
2950
|
-
await db.clear("downloadQueue");
|
|
2951
|
-
await db.clear("ops");
|
|
2962
|
+
await deleteDB("client-store-db");
|
|
2963
|
+
db = await initDB();
|
|
2952
2964
|
}
|
|
2953
2965
|
async getSeed() {
|
|
2954
2966
|
const hex = await db.get("metaKV", "seed");
|
|
@@ -11351,6 +11363,7 @@ var DiplomaticClient = class {
|
|
|
11351
11363
|
store;
|
|
11352
11364
|
stateManager;
|
|
11353
11365
|
listener;
|
|
11366
|
+
xferListener;
|
|
11354
11367
|
seed;
|
|
11355
11368
|
encKey;
|
|
11356
11369
|
hostURL;
|
|
@@ -11424,6 +11437,7 @@ var DiplomaticClient = class {
|
|
|
11424
11437
|
}
|
|
11425
11438
|
await this.sync();
|
|
11426
11439
|
this.emitUpdate();
|
|
11440
|
+
this.emitXferUpdate();
|
|
11427
11441
|
}
|
|
11428
11442
|
async loadSeed() {
|
|
11429
11443
|
const seed = await this.store.getSeed();
|
|
@@ -11489,13 +11503,20 @@ var DiplomaticClient = class {
|
|
|
11489
11503
|
const state = await this.getState();
|
|
11490
11504
|
this.listener?.(state);
|
|
11491
11505
|
}
|
|
11506
|
+
async emitXferUpdate() {
|
|
11507
|
+
const state = await this.getXferState();
|
|
11508
|
+
this.xferListener?.(state);
|
|
11509
|
+
}
|
|
11492
11510
|
async getState() {
|
|
11493
11511
|
const hasSeed = this.seed !== void 0 && this.encKey !== void 0;
|
|
11494
11512
|
const hasHost = this.hostURL !== void 0 && this.hostKeyPair !== void 0;
|
|
11495
11513
|
const connected = this.websocket === void 0 ? false : this.websocket.readyState === this.websocket.OPEN;
|
|
11514
|
+
return { hasSeed, hasHost, connected };
|
|
11515
|
+
}
|
|
11516
|
+
async getXferState() {
|
|
11496
11517
|
const numUploads = await this.store.numUploads();
|
|
11497
11518
|
const numDownloads = await this.store.numDownloads();
|
|
11498
|
-
return {
|
|
11519
|
+
return { numDownloads, numUploads };
|
|
11499
11520
|
}
|
|
11500
11521
|
async processOps() {
|
|
11501
11522
|
await this.pullOpPaths();
|
|
@@ -11511,7 +11532,7 @@ var DiplomaticClient = class {
|
|
|
11511
11532
|
const resp = await api_default.listDeltas(hostURL, begin, hostKeyPair);
|
|
11512
11533
|
for (const item of resp.deltas) {
|
|
11513
11534
|
await this.store.enqueueDownload(item.sha256, item.recordedAt);
|
|
11514
|
-
this.
|
|
11535
|
+
this.emitXferUpdate();
|
|
11515
11536
|
}
|
|
11516
11537
|
await this.store.setLastFetchedAt(new Date(resp.fetchedAt));
|
|
11517
11538
|
}
|
|
@@ -11525,7 +11546,7 @@ var DiplomaticClient = class {
|
|
|
11525
11546
|
for (const item of items) {
|
|
11526
11547
|
if (await this.store.hasOp(item.sha256)) {
|
|
11527
11548
|
await this.store.dequeueDownload(item.sha256);
|
|
11528
|
-
this.
|
|
11549
|
+
this.emitXferUpdate();
|
|
11529
11550
|
continue;
|
|
11530
11551
|
}
|
|
11531
11552
|
try {
|
|
@@ -11543,12 +11564,12 @@ var DiplomaticClient = class {
|
|
|
11543
11564
|
await this.stateManager.apply(op);
|
|
11544
11565
|
await this.store.storeOp(sha256, cipher);
|
|
11545
11566
|
await this.store.dequeueDownload(sha256);
|
|
11546
|
-
this.
|
|
11567
|
+
this.emitXferUpdate();
|
|
11547
11568
|
} catch {
|
|
11548
11569
|
const transient = true;
|
|
11549
11570
|
if (!transient) {
|
|
11550
11571
|
await this.store.dequeueDownload(item.sha256);
|
|
11551
|
-
this.
|
|
11572
|
+
this.emitXferUpdate();
|
|
11552
11573
|
}
|
|
11553
11574
|
}
|
|
11554
11575
|
}
|
|
@@ -11562,7 +11583,7 @@ var DiplomaticClient = class {
|
|
|
11562
11583
|
await api_default.putDelta(this.hostURL, cipherOp, this.hostKeyPair);
|
|
11563
11584
|
}
|
|
11564
11585
|
await this.store.dequeueUpload(sha256);
|
|
11565
|
-
this.
|
|
11586
|
+
this.emitXferUpdate();
|
|
11566
11587
|
}
|
|
11567
11588
|
async pushQueuedOps() {
|
|
11568
11589
|
for (const sha256 of await this.store.listUploads()) {
|
|
@@ -11584,13 +11605,13 @@ var DiplomaticClient = class {
|
|
|
11584
11605
|
);
|
|
11585
11606
|
const sha256 = await crypto_default.sha256Hash(cipherOp);
|
|
11586
11607
|
await this.store.enqueueUpload(sha256, cipherOp);
|
|
11587
|
-
this.
|
|
11608
|
+
this.emitXferUpdate();
|
|
11588
11609
|
try {
|
|
11589
11610
|
await this.stateManager.apply(op);
|
|
11590
11611
|
await this.store.storeOp(sha256, cipherOp);
|
|
11591
11612
|
} catch (err) {
|
|
11592
11613
|
await this.store.dequeueUpload(sha256);
|
|
11593
|
-
this.
|
|
11614
|
+
this.emitXferUpdate();
|
|
11594
11615
|
}
|
|
11595
11616
|
try {
|
|
11596
11617
|
await this.pushQueuedOp(sha256);
|
|
@@ -11631,7 +11652,7 @@ var DiplomaticClient = class {
|
|
|
11631
11652
|
const sha256 = await crypto_default.sha256Hash(cipher);
|
|
11632
11653
|
await this.stateManager.apply(op);
|
|
11633
11654
|
await this.store.storeOp(sha256, cipher);
|
|
11634
|
-
this.
|
|
11655
|
+
this.emitXferUpdate();
|
|
11635
11656
|
}
|
|
11636
11657
|
};
|
|
11637
11658
|
async upsert({ type, body, eid, gid, version = 0 }) {
|
|
@@ -11704,7 +11725,7 @@ function DotLabel({ on, label }) {
|
|
|
11704
11725
|
label
|
|
11705
11726
|
] });
|
|
11706
11727
|
}
|
|
11707
|
-
function ClientStatusBar({ state }) {
|
|
11728
|
+
function ClientStatusBar({ state, xferState }) {
|
|
11708
11729
|
return /* @__PURE__ */ jsxs2(
|
|
11709
11730
|
"div",
|
|
11710
11731
|
{
|
|
@@ -11723,11 +11744,11 @@ function ClientStatusBar({ state }) {
|
|
|
11723
11744
|
/* @__PURE__ */ jsx2(DotLabel, { on: state.connected, label: "LINK" }),
|
|
11724
11745
|
/* @__PURE__ */ jsxs2("div", { style: { marginRight: 16 }, children: [
|
|
11725
11746
|
"\u21D1 ",
|
|
11726
|
-
|
|
11747
|
+
xferState.numUploads
|
|
11727
11748
|
] }),
|
|
11728
11749
|
/* @__PURE__ */ jsxs2("div", { children: [
|
|
11729
11750
|
"\u21D3 ",
|
|
11730
|
-
|
|
11751
|
+
xferState.numDownloads
|
|
11731
11752
|
] })
|
|
11732
11753
|
]
|
|
11733
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