@interncom/diplomatic 0.7.1 → 0.8.1

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.
@@ -2,9 +2,9 @@ import DiplomaticClientAPI from "./shared/client";
2
2
  import { IClock } from "./shared/clock";
3
3
  import { Status } from "./shared/consts";
4
4
  import { EncodedMessage } from "./shared/message";
5
- import { EntityID, HostHandle, ICrypto, IDeleteParams, IEntRev, IHostConnectionInfo, IInsertParams, IMessageHead, IStateManager, ITransport, IUpdateParams, MasterSeed } from "./shared/types";
5
+ import { EntityID, Hash, HostHandle, ICrypto, IDeleteParams, IEntRev, IHostConnectionInfo, IInsertParams, IMessageHead, IStateManager, ITransport, IUpdateParams, MasterSeed } from "./shared/types";
6
6
  import { ValStat } from "./shared/valstat";
7
- import { IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore } from "./types";
7
+ import { ApldState, IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore, IStoredMessage, ListMsgsOpts } from "./types";
8
8
  export declare class SyncClient<Handle extends HostHandle> implements IClient<Handle> {
9
9
  private clock;
10
10
  private state;
@@ -132,6 +132,43 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
132
132
  */
133
133
  sync(): Promise<Status>;
134
134
  private doSync;
135
+ /**
136
+ * Rebuild application state from the local message archive.
137
+ *
138
+ * By default, inventories each linked host from seq 0 (full header list),
139
+ * enqueues and pulls any bags missing from the archive, then clears EntDB
140
+ * (or other app state) and re-executes every archived msg. Use after a
141
+ * schema/applier change when derived ents diverge from the durable archive.
142
+ *
143
+ * Pass `{ checkHost: false }` to skip the host inventory (offline / local-only).
144
+ * Does not wipe the message archive, seed, or hosts.
145
+ */
146
+ rebuild(options?: {
147
+ checkHost?: boolean;
148
+ }): Promise<Status>;
149
+ /**
150
+ * Checksum of the local msg archive (set of head hashes).
151
+ * listKeys → raw bytes → sort → blake3(concat); empty → blake3(∅).
152
+ * Store key encoding is irrelevant; we always sort decoded (binary) hashes.
153
+ */
154
+ msgcheck(): Promise<Hash>;
155
+ /**
156
+ * List local archive rows (failed apply, pending drain, full dump).
157
+ * Bodies included by default; pass `body: false` for lighter listings.
158
+ */
159
+ listMsgs(opts?: ListMsgsOpts): Promise<IStoredMessage[]>;
160
+ /** Count archive rows; optional apld filter. Prefer over list+length. */
161
+ countMsgs(apld?: ApldState): Promise<number>;
162
+ /**
163
+ * Peek each host from seq 0 and pull any bags not already in the archive.
164
+ * Leaves open msgs as APLD_PENDING; does not exec (rebuild replays everything).
165
+ */
166
+ private repull;
167
+ /**
168
+ * Clear app state and re-exec every archived msg (HLC newest-first batches).
169
+ * Caller must hold applyChain.
170
+ */
171
+ private replay;
135
172
  wipe(): Promise<void>;
136
173
  import: (file: File, options?: {
137
174
  onProgress?: (index: number, total: number, status: Status) => void;
@@ -1,5 +1,5 @@
1
1
  import { Status } from "../shared/consts";
2
- import { EntityID, IOp } from "../shared/types";
2
+ import { EntityID, Hash, ICrypto, IOp } from "../shared/types";
3
3
  import { ValStat } from "../shared/valstat";
4
4
  import { EntitiesQuery, IEntDB, IEntity } from "./entdb";
5
5
  export type EntChangeListener = (types: Set<string>) => void;
@@ -59,4 +59,6 @@ export declare class CachedEntDB implements IEntDB {
59
59
  countEntities({ type }: {
60
60
  type: string;
61
61
  }): Promise<ValStat<number>>;
62
+ /** Durable authority — mem may be only partially warm. */
63
+ checksum(crypto: ICrypto): Promise<ValStat<Hash>>;
62
64
  }
@@ -1,6 +1,6 @@
1
1
  import { Status } from "../shared/consts";
2
2
  import { ValStat } from "../shared/valstat";
3
- import { EntityID, GroupID, IEntRev, IMessageHead, IMsgEntBody, IOp } from "../shared/types";
3
+ import { EntityID, GroupID, Hash, ICrypto, IEntRev, IMessageHead, IMsgEntBody, IOp } from "../shared/types";
4
4
  export { entStateManager } from "./manager.ts";
5
5
  export interface IEntity<T = unknown> extends Omit<IMsgEntBody<T>, "body"> {
6
6
  eid: EntityID;
@@ -49,6 +49,11 @@ export interface IEntDB {
49
49
  countEntities({ type }: {
50
50
  type: string;
51
51
  }): Promise<ValStat<number>>;
52
+ /**
53
+ * Frontier checksum of live rows: eid + updatedAt + ctr per ent
54
+ * (see encodeEntRev / checksumEntRevs). Not a content hash of bodies.
55
+ */
56
+ checksum(crypto: ICrypto): Promise<ValStat<Hash>>;
52
57
  }
53
58
  /** Prior rev from a loaded entity (typical update/delete input). */
54
59
  export declare function revFromEntity(ent: IEntity): IEntRev;
@@ -1,5 +1,5 @@
1
1
  import { Status } from "../shared/consts";
2
- import { EntityID, GroupID, IOp } from "../shared/types";
2
+ import { EntityID, GroupID, Hash, ICrypto, IOp } from "../shared/types";
3
3
  import { ValStat } from "../shared/valstat.ts";
4
4
  import { EntitiesQuery, IEntDB, IEntity } from "./entdb";
5
5
  export declare const entityTableName = "entities";
@@ -40,6 +40,7 @@ export declare class EntIDB implements IEntDB {
40
40
  countEntities({ type }: {
41
41
  type: string;
42
42
  }): Promise<ValStat<number>>;
43
+ checksum(crypto: ICrypto): Promise<ValStat<Hash>>;
43
44
  }
44
45
  /** Durable IndexedDB EntDB. Internal-only. Apps use {@link openEntDB} instead. */
45
46
  export declare function openEntIDB(): Promise<EntIDB>;
@@ -1,6 +1,6 @@
1
1
  import { IEntDB, IEntity } from "./entdb";
2
2
  import { Status } from "../shared/consts";
3
- import { EntityID, GroupID, IOp } from "../shared/types";
3
+ import { EntityID, GroupID, Hash, ICrypto, IOp } from "../shared/types";
4
4
  import { ValStat } from "../shared/valstat.ts";
5
5
  interface IDateRange {
6
6
  start: Date;
@@ -53,5 +53,6 @@ export declare class EntDBMemory implements IEntDB {
53
53
  countEntities({ type }: {
54
54
  type: string;
55
55
  }): Promise<ValStat<number>>;
56
+ checksum(crypto: ICrypto): Promise<ValStat<Hash>>;
56
57
  }
57
58
  export {};
@@ -18,10 +18,11 @@ import { nullStateManager, StateManager } from "./state";
18
18
  import { IDBStore, openIDBStore } from "./stores/idb/store";
19
19
  import { MemoryStore } from "./stores/memory/store";
20
20
  import { SingletonStateManager } from "./shared/singleton";
21
- import type { ApldState, Applier, IClient, IDiplomaticClientState, IHostRow, IStore, IStoredMessage, IStoredMessageData, IStoredMessageWrite } from "./types";
21
+ import type { ApldState, Applier, IClient, IDiplomaticClientState, IHostRow, IStore, IStoredMessage, IStoredMessageData, IStoredMessageWrite, ListMsgsOpts } from "./types";
22
22
  import { APLD_APPLIED, APLD_ERROR, APLD_PENDING, apldFromStored, isApldState, isPendingApply, isTerminalApplyFailure, setApld } from "./types";
23
23
  import type { SyncProgressEvent } from "./progress";
24
24
  import { defaultPeekProgressEvery, idleProgress, shouldEmitItemProgress } from "./progress";
25
+ import { checksumEntRevs, checksumSet, cmpBytes, encodeEntRev } from "./shared/checksum";
25
26
  import { openDiplomaticClient, type OpenDiplomaticClientMainOptions, type OpenDiplomaticClientOptions, type OpenDiplomaticClientWorkerOptions, type OpenedDiplomaticClient } from "./openClient";
26
27
  import { WorkerClient } from "./worker/client";
27
28
  import type { WorkerClientOptions } from "./worker/client";
@@ -29,5 +30,5 @@ export declare function genWebClient(stateMgr: IStateManager, url: URL): Promise
29
30
  client: SyncClient<URL>;
30
31
  setSeed: (seedHex: string) => Promise<void>;
31
32
  }>;
32
- export { APLD_APPLIED, APLD_ERROR, APLD_PENDING, apldFromStored, b64tob, btob64, btoh, CachedEntDB, Clock, crypto, Decoder, defaultPeekProgressEvery, eidCodec, Encoder, EntDBMemory, EntIDB, EntitiesQuery, EntityID, entStateManager, genSingletonEID, GroupID, hostHTTPTransport, htob, HTTPTransport, IDBStore, idleProgress, IEntDB, IEntity, isApldState, isPendingApply, isTerminalApplyFailure, IStore, MasterSeed, MemoryStore, normalizeTags, nullEntDB, nullStateManager, openDiplomaticClient, openEntDB, openIDBStore, revFromEntity, revFromHead, setApld, shouldEmitItemProgress, SingletonStateManager, StateManager, Status, SyncClient, TypedEventEmitter, useClient, useClientState, useClientXferState, useStateWatcher, useStateWatcherSuspense, useSyncOnResume, WorkerClient, };
33
- export type { ApldState, Applier, CachedEntDBOptions, EntDBMemoryOptions, HostHandle, IClient, ICrypto, IDeleteParams, IDiplomaticClientState, IEntRev, IHostConnectionInfo, IHostRow, IMessage, IMutateOp, IOp, IStateManager, IStoredMessage, IStoredMessageData, IStoredMessageWrite, ITransport, IUpdateParams, OpenDiplomaticClientMainOptions, OpenDiplomaticClientOptions, OpenDiplomaticClientWorkerOptions, OpenedDiplomaticClient, OpenEntDBOptions, SyncProgressEvent, WorkerClientOptions, };
33
+ export { APLD_APPLIED, APLD_ERROR, APLD_PENDING, apldFromStored, b64tob, btob64, btoh, CachedEntDB, checksumEntRevs, checksumSet, Clock, cmpBytes, crypto, Decoder, defaultPeekProgressEvery, eidCodec, encodeEntRev, Encoder, EntDBMemory, EntIDB, EntitiesQuery, EntityID, entStateManager, genSingletonEID, GroupID, hostHTTPTransport, htob, HTTPTransport, IDBStore, idleProgress, IEntDB, IEntity, isApldState, isPendingApply, isTerminalApplyFailure, IStore, MasterSeed, MemoryStore, normalizeTags, nullEntDB, nullStateManager, openDiplomaticClient, openEntDB, openIDBStore, revFromEntity, revFromHead, setApld, shouldEmitItemProgress, SingletonStateManager, StateManager, Status, SyncClient, TypedEventEmitter, useClient, useClientState, useClientXferState, useStateWatcher, useStateWatcherSuspense, useSyncOnResume, WorkerClient, };
34
+ export type { ApldState, Applier, CachedEntDBOptions, EntDBMemoryOptions, HostHandle, IClient, ICrypto, IDeleteParams, IDiplomaticClientState, IEntRev, IHostConnectionInfo, IHostRow, IMessage, IMutateOp, IOp, IStateManager, IStoredMessage, IStoredMessageData, IStoredMessageWrite, ITransport, IUpdateParams, ListMsgsOpts, OpenDiplomaticClientMainOptions, OpenDiplomaticClientOptions, OpenDiplomaticClientWorkerOptions, OpenedDiplomaticClient, OpenEntDBOptions, SyncProgressEvent, WorkerClientOptions, };