@interncom/diplomatic 0.8.1 → 0.8.2
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/web/client.d.ts +10 -1
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.mjs +1 -1
- package/dist/web/stores/idb/hosts.d.ts +2 -1
- package/dist/web/stores/memory/hosts.d.ts +4 -1
- package/dist/web/sync.d.ts +11 -1
- package/dist/web/types.d.ts +73 -0
- package/dist/web/worker/client.d.ts +7 -2
- package/dist/web/worker/protocol.d.ts +7 -0
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Status } from "../../shared/consts";
|
|
2
2
|
import { IHostConnectionInfo, IHostMetadata } from "../../shared/types";
|
|
3
|
-
import type { IHostRow, IHostStore } from "../../types";
|
|
3
|
+
import type { HostStatsUpdate, IHostRow, IHostStore } from "../../types";
|
|
4
4
|
export declare class IDBHostStore implements IHostStore<URL> {
|
|
5
5
|
db: IDBDatabase;
|
|
6
6
|
constructor(db: IDBDatabase);
|
|
7
7
|
add(info: IHostConnectionInfo<URL>): Promise<void>;
|
|
8
8
|
private put;
|
|
9
9
|
touch(label: string, seq: number): Promise<void>;
|
|
10
|
+
recordStats(label: string, u: HostStatsUpdate): Promise<void>;
|
|
10
11
|
get(label: string): Promise<IHostRow<URL> | undefined>;
|
|
11
12
|
set(label: string, meta: IHostMetadata): Promise<Status.Success | Status.NotFound | Status.DatabaseError>;
|
|
12
13
|
del(label: string): Promise<void>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Status } from "../../shared/consts";
|
|
2
2
|
import { HostHandle, IHostConnectionInfo, IHostMetadata } from "../../shared/types";
|
|
3
|
-
import type { IHostRow, IHostStore } from "../../types";
|
|
3
|
+
import type { HostStatsUpdate, IHostRow, IHostStore } from "../../types";
|
|
4
4
|
export declare class MemoryHostStore<Handle extends HostHandle> implements IHostStore<Handle> {
|
|
5
5
|
hosts: Map<string, IHostRow<Handle>>;
|
|
6
|
+
/** Serializes recordStats so concurrent peeks do not drop bag/dupe deltas. */
|
|
7
|
+
private statsChain;
|
|
6
8
|
add(info: IHostConnectionInfo<Handle>): Promise<void>;
|
|
7
9
|
touch(label: string, seq: number): Promise<void>;
|
|
10
|
+
recordStats(label: string, u: HostStatsUpdate): Promise<void>;
|
|
8
11
|
get(label: string): Promise<IHostRow<Handle> | undefined>;
|
|
9
12
|
set(label: string, meta: IHostMetadata): Promise<Status.Success | Status.NotFound>;
|
|
10
13
|
del(label: string): Promise<void>;
|
package/dist/web/sync.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Enclave } from "./shared/crypto/enclave";
|
|
|
4
4
|
import { Hash, HostHandle, IBag, ICrypto } from "./shared/types";
|
|
5
5
|
import { ValStat } from "./shared/valstat";
|
|
6
6
|
import { ProgressFn } from "./progress";
|
|
7
|
-
import { IDownloadMessage, IHostRow, IMsgParts, IStore, type IStoredMessageWrite } from "./types";
|
|
7
|
+
import { IDownloadMessage, IHostRow, IMsgParts, IStore, type IStoredMessageWrite, type ReconcileOpts, type ReconcileResult } from "./types";
|
|
8
8
|
/** Default soft cap for one push/pull request (~1 MiB). Apps with large
|
|
9
9
|
* payloads (e.g. media) should raise maxPushBytes / maxPullBytes. */
|
|
10
10
|
export declare const defaultMaxPushBytes: number;
|
|
@@ -82,3 +82,13 @@ export declare function msg2StoredMsgData({ head, body }: IMsgParts): IStoredMes
|
|
|
82
82
|
* `scheduleSync` runs full peek/push/pull (or worker handoff).
|
|
83
83
|
*/
|
|
84
84
|
export declare function handleNotif<Handle extends HostHandle>(bytes: Uint8Array, { conn, store, enclave, host, crypto, onProgress, }: ISyncParams<Handle>, scheduleSync: () => void): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Full host inventory (PEEK from seq 0): set absolute numBags/numDupes/lastSeq,
|
|
87
|
+
* and optionally enqueue downloads (msgs on host missing locally) and/or
|
|
88
|
+
* uploads (local msgs missing on host). Does not pull/push network beyond
|
|
89
|
+
* peek — caller should sync() to drain queues.
|
|
90
|
+
*
|
|
91
|
+
* lastSeq is set to the max bag seq in the inventory (0 if empty), including
|
|
92
|
+
* rewind when the host has fewer bags than a prior cursor believed.
|
|
93
|
+
*/
|
|
94
|
+
export declare function reconcileHost<Handle extends HostHandle>(params: ISyncParams<Handle>, opts?: ReconcileOpts): Promise<ValStat<ReconcileResult>>;
|
package/dist/web/types.d.ts
CHANGED
|
@@ -36,7 +36,39 @@ export interface ISeedStore {
|
|
|
36
36
|
}
|
|
37
37
|
export interface IHostRow<Handle extends HostHandle> extends IHostConnectionInfo<Handle>, Partial<IHostMetadata> {
|
|
38
38
|
lastSeq: number;
|
|
39
|
+
/**
|
|
40
|
+
* Bags known on this host (full reconcile sets absolute; incremental peek
|
|
41
|
+
* adds newly seen seqs).
|
|
42
|
+
*/
|
|
43
|
+
numBags: number;
|
|
44
|
+
/**
|
|
45
|
+
* Extra bags beyond one per msg (`Σ max(0, bags_for_msg − 1)`). Absolute on
|
|
46
|
+
* reconcile; +delta on peek when a new duplicate bag for a known msg is seen.
|
|
47
|
+
*/
|
|
48
|
+
numDupes: number;
|
|
39
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Atomic host cursor + bag/dupe stats update (one store transaction).
|
|
52
|
+
* Absolute fields replace; deltas add. `lastSeq` only advances; use
|
|
53
|
+
* `setLastSeq` for a full-inventory absolute cursor (reconcile).
|
|
54
|
+
*/
|
|
55
|
+
export type HostStatsUpdate = {
|
|
56
|
+
/** New lastSeq if greater than current (incremental peek/push). */
|
|
57
|
+
lastSeq?: number;
|
|
58
|
+
/** Absolute lastSeq, including rewind (full inventory). */
|
|
59
|
+
setLastSeq?: number;
|
|
60
|
+
/** Absolute bag count (full inventory). */
|
|
61
|
+
numBags?: number;
|
|
62
|
+
/** Absolute dupe count (full inventory). */
|
|
63
|
+
numDupes?: number;
|
|
64
|
+
/** Count of newly peeked bags to add to numBags. */
|
|
65
|
+
bagDelta?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Count of newly seen extra bags for a msg already on the host (duplicate
|
|
68
|
+
* bags for the same msg) to add to numDupes.
|
|
69
|
+
*/
|
|
70
|
+
dupeDelta?: number;
|
|
71
|
+
};
|
|
40
72
|
export interface IHostStore<Handle extends HostHandle> {
|
|
41
73
|
add: (host: IHostConnectionInfo<Handle>) => Promise<void>;
|
|
42
74
|
get: (label: string) => Promise<IHostRow<Handle> | undefined>;
|
|
@@ -45,7 +77,40 @@ export interface IHostStore<Handle extends HostHandle> {
|
|
|
45
77
|
list: () => Promise<Iterable<IHostRow<Handle>>>;
|
|
46
78
|
wipe: () => Promise<void>;
|
|
47
79
|
touch: (label: string, seq: number) => Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Apply lastSeq / numBags / numDupes in one transaction so counts do not
|
|
82
|
+
* drift vs the cursor under concurrent peek/push.
|
|
83
|
+
*/
|
|
84
|
+
recordStats: (label: string, u: HostStatsUpdate) => Promise<void>;
|
|
48
85
|
}
|
|
86
|
+
/** Options for {@link IClient.reconcile}. */
|
|
87
|
+
export type ReconcileOpts = {
|
|
88
|
+
/** Enqueue downloads for msgs on host missing locally. Default true. */
|
|
89
|
+
pull?: boolean;
|
|
90
|
+
/** Enqueue uploads for local archive msgs missing on host. Default false. */
|
|
91
|
+
push?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* After inventory, run {@link IClient.sync} to drain upload/download queues.
|
|
94
|
+
* Default true. Pass false for inventory-only (counts + checksum).
|
|
95
|
+
*/
|
|
96
|
+
sync?: boolean;
|
|
97
|
+
};
|
|
98
|
+
/** Internal result of a full host inventory (not the public client API). */
|
|
99
|
+
export type ReconcileResult = {
|
|
100
|
+
/**
|
|
101
|
+
* Set-checksum of distinct msgs on the host (archive keys; same construction
|
|
102
|
+
* as {@link IClient.msgcheck}). Ephemeral — not stored on the host row.
|
|
103
|
+
*/
|
|
104
|
+
msgcheck: Hash;
|
|
105
|
+
bagCount: number;
|
|
106
|
+
/** Distinct msgs among bags (dup bags for the same msg count once). */
|
|
107
|
+
uniqueMsgs: number;
|
|
108
|
+
numDupes: number;
|
|
109
|
+
/** Msgs on host not in local archive. */
|
|
110
|
+
missingLocal: number;
|
|
111
|
+
/** Local archive msgs not seen on host. */
|
|
112
|
+
missingHost: number;
|
|
113
|
+
};
|
|
49
114
|
export interface IUploadQueue {
|
|
50
115
|
enq: (host: string, hshs: Iterable<Hash>) => Promise<void>;
|
|
51
116
|
deq: (host: string, hshs: Iterable<Hash>) => Promise<void>;
|
|
@@ -246,6 +311,14 @@ export interface IClient<Handle extends HostHandle> {
|
|
|
246
311
|
* Prefer over list+length for badges.
|
|
247
312
|
*/
|
|
248
313
|
countMsgs(apld?: ApldState): Promise<number>;
|
|
314
|
+
/**
|
|
315
|
+
* Full host inventory (peek from seq 0): set numBags/numDupes/lastSeq on the
|
|
316
|
+
* host row; optionally enqueue downloads (`pull`) and/or uploads (`push`).
|
|
317
|
+
* Returns ephemeral host msg checksum (distinct msgs on host; same as
|
|
318
|
+
* {@link msgcheck}) for UI comparison with local archive. Call
|
|
319
|
+
* {@link sync} to drain queues. Read counts via {@link hosts}.
|
|
320
|
+
*/
|
|
321
|
+
reconcile(hostLabel: string, opts?: ReconcileOpts): Promise<ValStat<Hash>>;
|
|
249
322
|
wipe(): Promise<void>;
|
|
250
323
|
import(file: File): Promise<Status>;
|
|
251
324
|
export(filename: string, extension?: string): Promise<Status>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IClock } from "../shared/clock";
|
|
2
2
|
import { Status } from "../shared/consts";
|
|
3
3
|
import type { EntityID, Hash, IDeleteParams, IEntRev, IHostConnectionInfo, IInsertParams, IMessageHead, IStateManager, IUpdateParams, MasterSeed, SerializedContent } from "../shared/types";
|
|
4
|
-
import type
|
|
5
|
-
import type { ApldState, IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore, IStoredMessage, ListMsgsOpts } from "../types";
|
|
4
|
+
import { type ValStat } from "../shared/valstat";
|
|
5
|
+
import type { ApldState, IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore, IStoredMessage, ListMsgsOpts, ReconcileOpts } from "../types";
|
|
6
6
|
/**
|
|
7
7
|
* Options for attaching to an app-owned sync Worker.
|
|
8
8
|
*
|
|
@@ -119,6 +119,11 @@ export declare class WorkerClient implements IClient<URL> {
|
|
|
119
119
|
/** Shared message IDB on main — no worker RPC. */
|
|
120
120
|
listMsgs(opts?: ListMsgsOpts): Promise<IStoredMessage[]>;
|
|
121
121
|
countMsgs(apld?: ApldState): Promise<number>;
|
|
122
|
+
/**
|
|
123
|
+
* Full host inventory on the worker (network + crypto off main).
|
|
124
|
+
* Returns ephemeral host msg checksum; host row stats in shared IDB.
|
|
125
|
+
*/
|
|
126
|
+
reconcile(hostLabel: string, opts?: ReconcileOpts): Promise<ValStat<Hash>>;
|
|
122
127
|
/** Archive checksum via worker (listKeys + sort + blake3 off main). */
|
|
123
128
|
msgcheck(): Promise<Hash>;
|
|
124
129
|
/**
|