@interncom/diplomatic 0.8.0 → 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.
@@ -1,7 +1,7 @@
1
1
  import { Status } from "../../shared/consts";
2
2
  import { ICrypto } from "../../shared/types";
3
3
  import { EntityID, Hash } from "../../shared/types";
4
- import { ApldState, IMessageStore, IStorableMessage, IStoredMessage } from "../../types";
4
+ import { ApldState, IMessageStore, IStorableMessage, IStoredMessage, ListMsgsOpts } from "../../types";
5
5
  export declare class IDBMessageStore implements IMessageStore {
6
6
  private crypto;
7
7
  db: IDBDatabase;
@@ -10,7 +10,8 @@ export declare class IDBMessageStore implements IMessageStore {
10
10
  del(keys: Iterable<Hash>): Promise<void>;
11
11
  get(key: Hash): Promise<IStoredMessage | undefined>;
12
12
  has(key: Hash): Promise<boolean>;
13
- list(apld?: ApldState): Promise<IStoredMessage[]>;
13
+ list(opts?: ListMsgsOpts): Promise<IStoredMessage[]>;
14
+ count(apld?: ApldState): Promise<number>;
14
15
  listKeys(): Promise<Hash[]>;
15
16
  last(eid: EntityID): Promise<IStoredMessage | undefined>;
16
17
  markApplied(keys: Iterable<Hash>): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { ICrypto } from "../../shared/types";
2
2
  import { EntityID, Hash } from "../../shared/types";
3
- import { ApldState, IMessageStore, IStorableMessage, IStoredMessage, IStoredMessageData } from "../../types";
3
+ import { ApldState, IMessageStore, IStorableMessage, IStoredMessage, IStoredMessageData, ListMsgsOpts } from "../../types";
4
4
  import { Status } from "../../shared/consts";
5
5
  export declare class MemoryMessageStore implements IMessageStore {
6
6
  private crypto;
@@ -10,7 +10,8 @@ export declare class MemoryMessageStore implements IMessageStore {
10
10
  del(keys: Iterable<Hash>): Promise<void>;
11
11
  get(key: Hash): Promise<IStoredMessage | undefined>;
12
12
  has(key: Hash): Promise<boolean>;
13
- list(apld?: ApldState): Promise<IStoredMessage[]>;
13
+ list(opts?: ListMsgsOpts): Promise<IStoredMessage[]>;
14
+ count(apld?: ApldState): Promise<number>;
14
15
  listKeys(): Promise<Hash[]>;
15
16
  last(eid: EntityID): Promise<IStoredMessage | undefined>;
16
17
  markApplied(keys: Iterable<Hash>): Promise<void>;
@@ -147,18 +147,35 @@ export declare function isTerminalApplyFailure(st: Status): boolean;
147
147
  * Clears `err` unless setting {@link APLD_ERROR}.
148
148
  */
149
149
  export declare function setApld(data: IStoredMessageData, apld: ApldState, err?: Status): void;
150
- export declare function toStoredMessage(hash: Hash, data: IStoredMessageData, crypto: ICrypto): Promise<IStoredMessage>;
150
+ /**
151
+ * Options for archive list / client diagnostics.
152
+ * `body` defaults to **true**. Pass `body: false` for heads + apld + err only.
153
+ */
154
+ export type ListMsgsOpts = {
155
+ /** Filter by apply lifecycle; omit for all archive rows. */
156
+ apld?: ApldState;
157
+ /**
158
+ * Include msg bodies and derive `head.hsh` from them.
159
+ * Default `true`. Pass `false` to omit body and `hsh` (cheaper diagnostics);
160
+ * `head.len` still reflects stored size.
161
+ */
162
+ body?: boolean;
163
+ };
164
+ export declare function toStoredMessage(hash: Hash, data: IStoredMessageData, crypto: ICrypto, opts?: {
165
+ body?: boolean;
166
+ }): Promise<IStoredMessage>;
151
167
  export interface IMessageStore {
152
168
  add: (messages: IStorableMessage[]) => Promise<Status[]>;
153
169
  get: (key: Hash) => Promise<IStoredMessage | undefined>;
154
170
  has: (key: Hash) => Promise<boolean>;
155
171
  del: (keys: Iterable<Hash>) => Promise<void>;
156
172
  /**
157
- * List archive rows. Pass {@link ApldState} to filter by apply lifecycle
158
- * (e.g. {@link APLD_PENDING} for the apply queue, {@link APLD_ERROR} for
159
- * diagnostics). Omit for all messages.
173
+ * List archive rows. Filter with `apld` (e.g. {@link APLD_ERROR}).
174
+ * Bodies included by default; pass `body: false` to omit.
160
175
  */
161
- list: (apld?: ApldState) => Promise<IStoredMessage[]>;
176
+ list: (opts?: ListMsgsOpts) => Promise<IStoredMessage[]>;
177
+ /** Count archive rows; optional apld filter (IDB index when available). */
178
+ count: (apld?: ApldState) => Promise<number>;
162
179
  /** Archive keys only (head hashes). Prefer over {@link list} for checksums. */
163
180
  listKeys: () => Promise<Hash[]>;
164
181
  last: (eid: EntityID) => Promise<IStoredMessage | undefined>;
@@ -219,6 +236,16 @@ export interface IClient<Handle extends HostHandle> {
219
236
  * Key encoding (e.g. b64 in IDB) is independent of this definition.
220
237
  */
221
238
  msgcheck(): Promise<Hash>;
239
+ /**
240
+ * List local archive rows for diagnostics (failed apply, pending drain, dump).
241
+ * Bodies included by default; pass `body: false` for lighter listings.
242
+ */
243
+ listMsgs(opts?: ListMsgsOpts): Promise<IStoredMessage[]>;
244
+ /**
245
+ * Count archive rows; optional apld filter.
246
+ * Prefer over list+length for badges.
247
+ */
248
+ countMsgs(apld?: ApldState): Promise<number>;
222
249
  wipe(): Promise<void>;
223
250
  import(file: File): Promise<Status>;
224
251
  export(filename: string, extension?: string): Promise<Status>;
@@ -2,7 +2,7 @@ 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
4
  import type { ValStat } from "../shared/valstat";
5
- import type { IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore } from "../types";
5
+ import type { ApldState, IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore, IStoredMessage, ListMsgsOpts } from "../types";
6
6
  /**
7
7
  * Options for attaching to an app-owned sync Worker.
8
8
  *
@@ -116,6 +116,9 @@ export declare class WorkerClient implements IClient<URL> {
116
116
  rebuild(options?: {
117
117
  checkHost?: boolean;
118
118
  }): Promise<Status>;
119
+ /** Shared message IDB on main — no worker RPC. */
120
+ listMsgs(opts?: ListMsgsOpts): Promise<IStoredMessage[]>;
121
+ countMsgs(apld?: ApldState): Promise<number>;
119
122
  /** Archive checksum via worker (listKeys + sort + blake3 off main). */
120
123
  msgcheck(): Promise<Hash>;
121
124
  /**