@interncom/diplomatic 0.20.0 → 0.22.0

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.
@@ -20,8 +20,9 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
20
20
  private onScheduleSync?;
21
21
  connections: Map<string, DiplomaticClientAPI<Handle>>;
22
22
  /**
23
- * Serializes local mutates + exec so concurrent drainApplyQueue / apply do
24
- * not interleave markApplied (each job runs fully, in order).
23
+ * Serializes archive + markApplied so concurrent drainApplyQueue / apply
24
+ * do not interleave those IDB writes. Mem notify is kicked before this
25
+ * chain so a prior persist cannot delay the list.
25
26
  */
26
27
  private applyChain;
27
28
  /**
@@ -62,20 +63,20 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
62
63
  * Persist msgs (APLD_PENDING), exec into app state, then optionally enq upload.
63
64
  *
64
65
  * Order (do not invert — UI notify depends on it):
65
- * 1) Kick off state.apply (CachedEntDB emits in the sync prefix of apply;
66
- * the returned Promise is durable EntDB + reconcile).
67
- * 2) Durable archive (messages.add).
68
- * 3) Await apply + mark APLD_APPLIED/APLD_ERROR.
69
- * 4) Upload queue.
70
- * Crash between 2–3 → drainApplyQueue recovers.
71
- * Awaiting apply before archive makes the UI wait on EntDB IDB.
72
- *
73
- * Serialized on applyChain (with local mutates).
66
+ * 1) Kick state.apply *before* applyChain. CachedEntDB patches mem and
67
+ * notifies after the next paint. A prior job's
68
+ * archive / persist / markApplied must not delay the list.
69
+ * 2) Serialize archive (messages.add) + await apply + markApplied on
70
+ * applyChain (crash between archive and mark → drainApplyQueue).
71
+ * 3) Upload queue.
72
+ * Awaiting apply before archive, or waiting on applyChain before kicking
73
+ * apply, makes the UI wait on IndexedDB.
74
74
  */
75
75
  private apply;
76
76
  /**
77
- * Core apply without enqueue. Caller must already hold applyChain when
78
- * composing makeUpdate + apply in one job.
77
+ * Archive + await a pre-kicked state.apply + markApplied.
78
+ * Caller must already hold applyChain. `applyP` is kicked first so mem
79
+ * notify is not serialized behind a prior job's IDB.
79
80
  */
80
81
  private doApply;
81
82
  private enqueueApplyJob;
@@ -20,6 +20,11 @@ export type OpenEntDBOptions = {
20
20
  * Set false to notify only after durable commit. Ignored when `cache` is false.
21
21
  */
22
22
  optimistic?: boolean;
23
+ /**
24
+ * Timed `[dip]` traces for apply / list / persist (default false).
25
+ * Process-wide; also accepted on openDiplomaticClient / useClient.
26
+ */
27
+ verbose?: boolean;
23
28
  };
24
29
  export type CachedEntDBOptions = {
25
30
  /** Secondary mem indexes (default true). See {@link OpenEntDBOptions.indexes}. */
@@ -32,6 +37,7 @@ export type CachedEntDBOptions = {
32
37
  * Default: cached with mem indexes and optimistic notify.
33
38
  * Pass `{ cache: false }` for durable IDB only.
34
39
  * Pass `{ optimistic: false }` to notify only after durable commit.
40
+ * Pass `{ verbose: true }` for `[dip]` timings (apply, list, persist).
35
41
  */
36
42
  export declare function openEntDB(opts?: OpenEntDBOptions): Promise<IEntDB>;
37
43
  export declare class CachedEntDB implements IEntDB {
@@ -41,14 +47,18 @@ export declare class CachedEntDB implements IEntDB {
41
47
  private listeners;
42
48
  private chain;
43
49
  private optimistic;
50
+ /** Optimistic applies whose durable persist has not finished. */
51
+ private inflight;
52
+ /** In-flight warmType per type (not on the persist/ingest chain). */
53
+ private warmP;
44
54
  constructor(durable: IEntDB, init?: IEntity[], opts?: CachedEntDBOptions);
45
55
  /** UI / StateManager: fired when mem changes (immediate apply or durable ingest). */
46
56
  subscribe(listener: EntChangeListener): () => void;
47
57
  private emit;
48
58
  private run;
49
59
  /**
50
- * Fan-out write: patch mem, queue durable, notify UI on a microtask,
51
- * then reconcile. Not `async`: mem patch must run before any await.
60
+ * Fan-out write: patch mem, queue durable, notify UI after the next paint.
61
+ * Not `async`: mem patch must run before any await.
52
62
  * `{ optimistic: false }`: skip the mem prefix; notify after durable.
53
63
  */
54
64
  apply(ops: IOp[]): Promise<import("./entdb").ApplyResult>;
@@ -67,6 +77,13 @@ export declare class CachedEntDB implements IEntDB {
67
77
  */
68
78
  private pullEids;
69
79
  private warmType;
80
+ /**
81
+ * Load a type from durable into mem. Not on the persist/ingest chain —
82
+ * first UI list must not wait for dirty-eid pull after worker sync.
83
+ */
84
+ private beginWarm;
85
+ /** Background warm + notify. Does not block the caller. */
86
+ private ensureWarm;
70
87
  getRow<T>(eid: EntityID): Promise<ValStat<IEntRow<T> | undefined>>;
71
88
  getEnt<T>(eid: EntityID): Promise<ValStat<IEntity<T> | undefined>>;
72
89
  getEntities<T>(query: EntitiesQuery): Promise<ValStat<IEntity<T>[]>>;
@@ -3,8 +3,8 @@ import type { IEntDB } from "./entdb";
3
3
  /**
4
4
  * Build a StateManager for an EntDB.
5
5
  * When `edb` is a {@link CachedEntDB}, type notifies come from the cache
6
- * subscribe path (mem patch + microtask notify, then durable reconcile /
7
- * peer ingest). cacheDriven: StateManager.apply must not emit after the
8
- * applier Promise settles — that would delay UI until durable IDB.
6
+ * subscribe path (mem patch + notify after paint, then durable persist).
7
+ * cacheDriven: StateManager.apply must not emit after the applier Promise
8
+ * settles — that emit would wait until durable IDB.
9
9
  */
10
10
  export declare function entStateManager(edb: IEntDB): StateManager;
@@ -17,6 +17,7 @@ import { TypedEventEmitter } from "./shared/events";
17
17
  import { asSealedMasterKey, MASTER_SEED_LEN, SEALED_MASTER_KEY_LEN, type SealedMasterKey } from "./shared/seed";
18
18
  import { EntityID, HostHandle, ICrypto, IDeleteParams, IEntRev, IHostConnectionInfo, IMessage, IMutateOp, type IOp, IStateManager, ITransport, IUpdateParams } from "./shared/types";
19
19
  import { Enclave } from "./shared/crypto/enclave";
20
+ import type { PairRequest } from "./shared/crypto/enclave";
20
21
  import { nullStateManager, StateManager } from "./state";
21
22
  import { IDBSeedStore } from "./stores/idb/seed";
22
23
  import { IDBStore, openIDBStore } from "./stores/idb/store";
@@ -33,7 +34,7 @@ import { KEYRING_MAX, keyringCredIds, keyringKind, keyringLabel, PrfSeedStore }
33
34
  import type { Keyring, KeyringEntry, KeyringRow, PersistKeyring, PrfSeedStoreOpts } from "./passkey/prf-store";
34
35
  import type { PasskeySeedStoreOpts } from "./passkey/seed";
35
36
  import { type BundleHost } from "./shared/codecs/bundleHost";
36
- import { asDHKEReq, asDHKEResp, PairRequest } from "./shared/crypto/pairing";
37
+ import { asDHKEReq, asDHKEResp } from "./shared/crypto/pairing";
37
38
  import type { DHKEReq, DHKEResp } from "./shared/crypto/pairing";
38
39
  import { checksumEntRevs, checksumSet, cmpBytes, encodeEntRev } from "./shared/checksum";
39
40
  import { openDiplomaticClient, type OpenDiplomaticClientMainOptions, type OpenDiplomaticClientOptions, type OpenDiplomaticClientWorkerOptions, type OpenedDiplomaticClient } from "./openClient";
@@ -43,5 +44,5 @@ import type { WipeOpts } from "./types";
43
44
  /** Platform advertises largeBlob (not a guarantee the binding key has it). */
44
45
  export { largeBlobCapable } from "./shared/webauthn/largeBlob";
45
46
  export { webAuthnLastError } from "./shared/webauthn/common";
46
- export { APLD_APPLIED, APLD_ERROR, APLD_PENDING, apldFromStored, asDHKEReq, asDHKEResp, asSealedMasterKey, b64tob, b64urltob, btob64, btob64url, btoh, CachedEntDB, checksumEntRevs, checksumSet, Clock, cmpBytes, crypto, Decoder, DEFAULT_PRF_SALT, defaultPeekProgressEvery, defaultWebAuthnRpId, eidCodec, Enclave, encodeEntRev, Encoder, EntDBMemory, EntIDB, EntitiesQuery, EntityID, entStateManager, genSingletonEID, hostHTTPTransport, htob, HTTPTransport, IDBSeedStore, IDBStore, idleProgress, IEntDB, IEntity, isApldState, isLiveEnt, isPendingApply, isTerminalApplyFailure, isTombstone, IStore, KEYRING_MAX, keyringCredIds, keyringKind, keyringLabel, MASTER_SEED_LEN, MemoryStore, normalizeTags, nullEntDB, nullStateManager, openDiplomaticClient, openEntDB, openIDBStore, PairRequest, PasskeySeedStore, prfCapable, PrfSeedStore, revFromEntity, revFromHead, SEALED_MASTER_KEY_LEN, setApld, shouldEmitItemProgress, SingletonStateManager, StateManager, Status, SyncClient, TypedEventEmitter, useClient, useClientState, useClientXferState, useStateWatcher, useStateWatcherSuspense, useSyncOnResume, WorkerClient, };
47
- export type { ApldState, Applier, BundleHost, CachedEntDBOptions, DateSpec, DHKEReq, DHKEResp, EntDBMemoryOptions, HostHandle, HostStatsUpdate, IClient, ICrypto, IDateRange, IDeleteParams, IDiplomaticClientState, IEntRev, IEntRow, IHostConnectionInfo, IHostRow, IMessage, IMutateOp, IOp, IStateManager, IStoredMessage, IStoredMessageData, IStoredMessageWrite, ITagRange, ITombstone, ITransport, IUpdateParams, Keyring, KeyringEntry, KeyringRow, ListMsgsOpts, OpenDiplomaticClientMainOptions, OpenDiplomaticClientOptions, OpenDiplomaticClientWorkerOptions, OpenedDiplomaticClient, OpenEntDBOptions, PasskeySeedStoreOpts, PersistKeyring, PrfRp, PrfSeedStoreOpts, ReconcileOpts, ReconcileReport, SealedMasterKey, SetSeedOpts, SyncProgressEvent, TagSpec, WipeOpts, WorkerClientOptions, };
47
+ export { APLD_APPLIED, APLD_ERROR, APLD_PENDING, apldFromStored, asDHKEReq, asDHKEResp, asSealedMasterKey, b64tob, b64urltob, btob64, btob64url, btoh, CachedEntDB, checksumEntRevs, checksumSet, Clock, cmpBytes, crypto, Decoder, DEFAULT_PRF_SALT, defaultPeekProgressEvery, defaultWebAuthnRpId, eidCodec, Enclave, encodeEntRev, Encoder, EntDBMemory, EntIDB, EntitiesQuery, EntityID, entStateManager, genSingletonEID, hostHTTPTransport, htob, HTTPTransport, IDBSeedStore, IDBStore, idleProgress, IEntDB, IEntity, isApldState, isLiveEnt, isPendingApply, isTerminalApplyFailure, isTombstone, IStore, KEYRING_MAX, keyringCredIds, keyringKind, keyringLabel, MASTER_SEED_LEN, MemoryStore, normalizeTags, nullEntDB, nullStateManager, openDiplomaticClient, openEntDB, openIDBStore, PasskeySeedStore, prfCapable, PrfSeedStore, revFromEntity, revFromHead, SEALED_MASTER_KEY_LEN, setApld, shouldEmitItemProgress, SingletonStateManager, StateManager, Status, SyncClient, TypedEventEmitter, useClient, useClientState, useClientXferState, useStateWatcher, useStateWatcherSuspense, useSyncOnResume, WorkerClient, };
48
+ export type { ApldState, Applier, BundleHost, CachedEntDBOptions, DateSpec, DHKEReq, DHKEResp, EntDBMemoryOptions, HostHandle, HostStatsUpdate, IClient, ICrypto, IDateRange, IDeleteParams, IDiplomaticClientState, IEntRev, IEntRow, IHostConnectionInfo, IHostRow, IMessage, IMutateOp, IOp, IStateManager, IStoredMessage, IStoredMessageData, IStoredMessageWrite, ITagRange, ITombstone, ITransport, IUpdateParams, Keyring, KeyringEntry, KeyringRow, ListMsgsOpts, OpenDiplomaticClientMainOptions, OpenDiplomaticClientOptions, OpenDiplomaticClientWorkerOptions, OpenedDiplomaticClient, OpenEntDBOptions, PairRequest, PasskeySeedStoreOpts, PersistKeyring, PrfRp, PrfSeedStoreOpts, ReconcileOpts, ReconcileReport, SealedMasterKey, SetSeedOpts, SyncProgressEvent, TagSpec, WipeOpts, WorkerClientOptions, };