@brightbeamai/chap-coordinator 0.3.1 → 0.3.3
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/{api-BkvwN42r.d.cts → api-59aU01Bs.d.cts} +48 -3
- package/dist/{api-Ddy9fqkY.d.ts → api-CxciGFHA.d.ts} +48 -3
- package/dist/api.d.cts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/index.cjs +537 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +536 -126
- package/dist/index.js.map +1 -1
- package/dist/storage/sqlite.cjs +270 -34
- package/dist/storage/sqlite.cjs.map +1 -1
- package/dist/storage/sqlite.d.cts +60 -10
- package/dist/storage/sqlite.d.ts +60 -10
- package/dist/storage/sqlite.js +270 -34
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/storage/store.cjs +150 -9
- package/dist/storage/store.cjs.map +1 -1
- package/dist/storage/store.d.cts +118 -40
- package/dist/storage/store.d.ts +118 -40
- package/dist/storage/store.js +143 -8
- package/dist/storage/store.js.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
99
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
99
|
-
*
|
|
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
|
-
/**
|
|
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-
|
|
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-
|
|
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';
|