@brightbeamai/chap-coordinator 0.3.0 → 0.3.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.
@@ -79,6 +79,12 @@ interface CoordinatorOptions {
79
79
  maxEnvelopeBytes?: number;
80
80
  onAudit?: AuditListener;
81
81
  onAutoEscalate?: (task: Task, to: ParticipantUri) => void;
82
+ /**
83
+ * Called when a write to the store fails, with the workspace and the
84
+ * version the write would have reached. When unset, the failure is written
85
+ * to stderr. The call itself has already succeeded in memory; the next
86
+ * write to the workspace carries what this one did not.
87
+ */
82
88
  onStoreError?: (err: unknown, record: {
83
89
  id: string;
84
90
  version: number;
@@ -95,8 +101,9 @@ interface CoordinatorOptions {
95
101
  * Persistence backend. Defaults to MemoryStore (no persistence).
96
102
  * Pass SqliteStore or any other Store implementation to persist
97
103
  * workspaces between process restarts. The Coordinator calls
98
- * `store.load()` once during `start()` and `store.save()` after
99
- * every successful mutation.
104
+ * `store.load()` once when it starts, and after each call that adds to a
105
+ * workspace's log it calls `store.apply()` with what changed, or
106
+ * `store.save()` with the whole workspace when the store has no `apply`.
100
107
  */
101
108
  store?: Store;
102
109
  }
@@ -115,6 +122,14 @@ declare class Coordinator {
115
122
  readonly store: Store;
116
123
  private wsVersions;
117
124
  private saveChains;
125
+ /** Records which objects change, for stores that implement `apply`. */
126
+ private readonly tracker;
127
+ /** What the store holds of each workspace, as far as this instance knows. */
128
+ private persisted;
129
+ /** Workspaces with entries not yet written in the call being handled. */
130
+ private unflushed;
131
+ /** Workspaces with a write queued behind an async write in flight. */
132
+ private flushQueued;
118
133
  private clockMs?;
119
134
  private frozenNow?;
120
135
  private auditListeners;
@@ -139,8 +154,32 @@ declare class Coordinator {
139
154
  */
140
155
  start(): Promise<void>;
141
156
  private applyRecords;
142
- /** Persist the current snapshot of one workspace to the store. */
157
+ /** A map for a workspace collection, tracked for stores that implement `apply`. */
158
+ private newMap;
159
+ /** Record that the store holds this workspace exactly as it is in memory. */
160
+ private markWritten;
161
+ /**
162
+ * What the store holds of a workspace. A workspace this instance did not
163
+ * create or load, such as one an application put in `workspaces` itself,
164
+ * or one whose maps an application replaced, is tracked from here on and
165
+ * written whole once.
166
+ */
167
+ private persistedOf;
168
+ /** Record that a task.create idempotency key was written or removed. */
169
+ private markKey;
170
+ /** After an entry is appended: write now, or when the call being handled ends. */
143
171
  private persist;
172
+ private flushUnflushed;
173
+ /** Write what changed in one workspace since its last write. */
174
+ private flush;
175
+ private chainWrite;
176
+ private writeChange;
177
+ /** The change since the last write, taking the recorded keys with it. */
178
+ private takeChange;
179
+ /** A failed write's keys go back, so the next write carries them again. */
180
+ private giveBack;
181
+ /** Persist the whole workspace, for a store that implements only `save`. */
182
+ private persistSnapshot;
144
183
  private trackSave;
145
184
  private reportStoreError;
146
185
  drainSaves(): Promise<void>;
@@ -172,9 +211,15 @@ declare class Coordinator {
172
211
  private requireReviewer;
173
212
  /** Serialise all workspaces to a JSON-safe structure for persistence. */
174
213
  snapshot(): unknown;
214
+ /** The workspace's own fields: everything except its collections and log. */
215
+ private metaOf;
216
+ /** One workspace as `snapshot()` holds it. Reads nothing as a change. */
217
+ private snapshotOf;
175
218
  /** Restore from a snapshot produced by ``snapshot()``. Replaces
176
219
  * any existing in-memory workspaces. */
177
220
  restore(data: unknown): void;
221
+ /** One workspace from a snapshot entry, its maps tracked. */
222
+ private rebuild;
178
223
  dispatch(envelope: Envelope): Envelope;
179
224
  private _dispatch;
180
225
  recordAudit(ws: Workspace, envelope: Envelope): void;
@@ -79,6 +79,12 @@ interface CoordinatorOptions {
79
79
  maxEnvelopeBytes?: number;
80
80
  onAudit?: AuditListener;
81
81
  onAutoEscalate?: (task: Task, to: ParticipantUri) => void;
82
+ /**
83
+ * Called when a write to the store fails, with the workspace and the
84
+ * version the write would have reached. When unset, the failure is written
85
+ * to stderr. The call itself has already succeeded in memory; the next
86
+ * write to the workspace carries what this one did not.
87
+ */
82
88
  onStoreError?: (err: unknown, record: {
83
89
  id: string;
84
90
  version: number;
@@ -95,8 +101,9 @@ interface CoordinatorOptions {
95
101
  * Persistence backend. Defaults to MemoryStore (no persistence).
96
102
  * Pass SqliteStore or any other Store implementation to persist
97
103
  * workspaces between process restarts. The Coordinator calls
98
- * `store.load()` once during `start()` and `store.save()` after
99
- * every successful mutation.
104
+ * `store.load()` once when it starts, and after each call that adds to a
105
+ * workspace's log it calls `store.apply()` with what changed, or
106
+ * `store.save()` with the whole workspace when the store has no `apply`.
100
107
  */
101
108
  store?: Store;
102
109
  }
@@ -115,6 +122,14 @@ declare class Coordinator {
115
122
  readonly store: Store;
116
123
  private wsVersions;
117
124
  private saveChains;
125
+ /** Records which objects change, for stores that implement `apply`. */
126
+ private readonly tracker;
127
+ /** What the store holds of each workspace, as far as this instance knows. */
128
+ private persisted;
129
+ /** Workspaces with entries not yet written in the call being handled. */
130
+ private unflushed;
131
+ /** Workspaces with a write queued behind an async write in flight. */
132
+ private flushQueued;
118
133
  private clockMs?;
119
134
  private frozenNow?;
120
135
  private auditListeners;
@@ -139,8 +154,32 @@ declare class Coordinator {
139
154
  */
140
155
  start(): Promise<void>;
141
156
  private applyRecords;
142
- /** Persist the current snapshot of one workspace to the store. */
157
+ /** A map for a workspace collection, tracked for stores that implement `apply`. */
158
+ private newMap;
159
+ /** Record that the store holds this workspace exactly as it is in memory. */
160
+ private markWritten;
161
+ /**
162
+ * What the store holds of a workspace. A workspace this instance did not
163
+ * create or load, such as one an application put in `workspaces` itself,
164
+ * or one whose maps an application replaced, is tracked from here on and
165
+ * written whole once.
166
+ */
167
+ private persistedOf;
168
+ /** Record that a task.create idempotency key was written or removed. */
169
+ private markKey;
170
+ /** After an entry is appended: write now, or when the call being handled ends. */
143
171
  private persist;
172
+ private flushUnflushed;
173
+ /** Write what changed in one workspace since its last write. */
174
+ private flush;
175
+ private chainWrite;
176
+ private writeChange;
177
+ /** The change since the last write, taking the recorded keys with it. */
178
+ private takeChange;
179
+ /** A failed write's keys go back, so the next write carries them again. */
180
+ private giveBack;
181
+ /** Persist the whole workspace, for a store that implements only `save`. */
182
+ private persistSnapshot;
144
183
  private trackSave;
145
184
  private reportStoreError;
146
185
  drainSaves(): Promise<void>;
@@ -172,9 +211,15 @@ declare class Coordinator {
172
211
  private requireReviewer;
173
212
  /** Serialise all workspaces to a JSON-safe structure for persistence. */
174
213
  snapshot(): unknown;
214
+ /** The workspace's own fields: everything except its collections and log. */
215
+ private metaOf;
216
+ /** One workspace as `snapshot()` holds it. Reads nothing as a change. */
217
+ private snapshotOf;
175
218
  /** Restore from a snapshot produced by ``snapshot()``. Replaces
176
219
  * any existing in-memory workspaces. */
177
220
  restore(data: unknown): void;
221
+ /** One workspace from a snapshot entry, its maps tracked. */
222
+ private rebuild;
178
223
  dispatch(envelope: Envelope): Envelope;
179
224
  private _dispatch;
180
225
  recordAudit(ws: Workspace, envelope: Envelope): void;
package/dist/api.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  import './methods.cjs';
2
- export { b as CoordinatorApi, c as CoordinatorError, g as call, m as makeApi } from './api-BkvwN42r.cjs';
2
+ export { b as CoordinatorApi, c as CoordinatorError, g as call, m as makeApi } from './api-59aU01Bs.cjs';
3
3
  import './types.cjs';
4
4
  import './storage/store.cjs';
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import './methods.js';
2
- export { b as CoordinatorApi, c as CoordinatorError, g as call, m as makeApi } from './api-Ddy9fqkY.js';
2
+ export { b as CoordinatorApi, c as CoordinatorError, g as call, m as makeApi } from './api-CxciGFHA.js';
3
3
  import './types.js';
4
4
  import './storage/store.js';