@affectively/aeon 1.0.0 → 1.2.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.
- package/README.md +10 -0
- package/dist/compression/index.cjs +580 -0
- package/dist/compression/index.cjs.map +1 -0
- package/dist/compression/index.d.cts +189 -0
- package/dist/compression/index.d.ts +189 -0
- package/dist/compression/index.js +573 -0
- package/dist/compression/index.js.map +1 -0
- package/dist/core/index.d.cts +70 -5
- package/dist/core/index.d.ts +70 -5
- package/dist/crypto/index.cjs +100 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +407 -0
- package/dist/crypto/index.d.ts +407 -0
- package/dist/crypto/index.js +96 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/distributed/index.cjs +420 -23
- package/dist/distributed/index.cjs.map +1 -1
- package/dist/distributed/index.d.cts +901 -2
- package/dist/distributed/index.d.ts +901 -2
- package/dist/distributed/index.js +420 -23
- package/dist/distributed/index.js.map +1 -1
- package/dist/index.cjs +1222 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -811
- package/dist/index.d.ts +11 -811
- package/dist/index.js +1221 -56
- package/dist/index.js.map +1 -1
- package/dist/offline/index.cjs +419 -0
- package/dist/offline/index.cjs.map +1 -0
- package/dist/offline/index.d.cts +148 -0
- package/dist/offline/index.d.ts +148 -0
- package/dist/offline/index.js +415 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/optimization/index.cjs +797 -0
- package/dist/optimization/index.cjs.map +1 -0
- package/dist/optimization/index.d.cts +347 -0
- package/dist/optimization/index.d.ts +347 -0
- package/dist/optimization/index.js +787 -0
- package/dist/optimization/index.js.map +1 -0
- package/dist/persistence/index.cjs +145 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +63 -0
- package/dist/persistence/index.d.ts +63 -0
- package/dist/persistence/index.js +142 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/presence/index.cjs +489 -0
- package/dist/presence/index.cjs.map +1 -0
- package/dist/presence/index.d.cts +283 -0
- package/dist/presence/index.d.ts +283 -0
- package/dist/presence/index.js +485 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/types-CMxO7QF0.d.cts +33 -0
- package/dist/types-CMxO7QF0.d.ts +33 -0
- package/dist/versioning/index.cjs +296 -14
- package/dist/versioning/index.cjs.map +1 -1
- package/dist/versioning/index.d.cts +66 -1
- package/dist/versioning/index.d.ts +66 -1
- package/dist/versioning/index.js +296 -14
- package/dist/versioning/index.js.map +1 -1
- package/package.json +51 -1
- package/dist/index-C_4CMV5c.d.cts +0 -1207
- package/dist/index-C_4CMV5c.d.ts +0 -1207
|
@@ -1,2 +1,901 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
import { ICryptoProvider, AeonEncryptionMode, AuthenticatedMessageFields } from '../crypto/index.cjs';
|
|
3
|
+
import { S as StorageAdapter, b as PersistenceSerializer, a as PersistenceDeserializer } from '../types-CMxO7QF0.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sync Coordinator
|
|
7
|
+
*
|
|
8
|
+
* Coordinates synchronization between multiple nodes in a distributed system.
|
|
9
|
+
* Manages sync sessions, node registration, and synchronization workflows.
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Node registration and discovery
|
|
13
|
+
* - Sync session management
|
|
14
|
+
* - Synchronization workflow orchestration
|
|
15
|
+
* - Node health monitoring
|
|
16
|
+
* - Conflict detection and resolution coordination
|
|
17
|
+
* - DID-based node identification
|
|
18
|
+
* - Authenticated sync sessions
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
interface SyncNode {
|
|
22
|
+
id: string;
|
|
23
|
+
address: string;
|
|
24
|
+
port: number;
|
|
25
|
+
status: 'online' | 'offline' | 'syncing';
|
|
26
|
+
lastHeartbeat: string;
|
|
27
|
+
version: string;
|
|
28
|
+
capabilities: string[];
|
|
29
|
+
did?: string;
|
|
30
|
+
publicSigningKey?: JsonWebKey;
|
|
31
|
+
publicEncryptionKey?: JsonWebKey;
|
|
32
|
+
grantedCapabilities?: string[];
|
|
33
|
+
}
|
|
34
|
+
interface SyncSession {
|
|
35
|
+
id: string;
|
|
36
|
+
initiatorId: string;
|
|
37
|
+
participantIds: string[];
|
|
38
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
39
|
+
startTime: string;
|
|
40
|
+
endTime?: string;
|
|
41
|
+
itemsSynced: number;
|
|
42
|
+
itemsFailed: number;
|
|
43
|
+
conflictsDetected: number;
|
|
44
|
+
initiatorDID?: string;
|
|
45
|
+
participantDIDs?: string[];
|
|
46
|
+
encryptionMode?: AeonEncryptionMode;
|
|
47
|
+
requiredCapabilities?: string[];
|
|
48
|
+
sessionToken?: string;
|
|
49
|
+
}
|
|
50
|
+
interface SyncEvent {
|
|
51
|
+
type: 'node-joined' | 'node-left' | 'sync-started' | 'sync-completed' | 'conflict-detected';
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
nodeId: string;
|
|
54
|
+
timestamp: string;
|
|
55
|
+
data?: unknown;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sync Coordinator
|
|
59
|
+
* Coordinates synchronization across distributed nodes
|
|
60
|
+
*/
|
|
61
|
+
declare class SyncCoordinator extends EventEmitter {
|
|
62
|
+
private nodes;
|
|
63
|
+
private sessions;
|
|
64
|
+
private syncEvents;
|
|
65
|
+
private nodeHeartbeats;
|
|
66
|
+
private heartbeatInterval;
|
|
67
|
+
private cryptoProvider;
|
|
68
|
+
private nodesByDID;
|
|
69
|
+
constructor();
|
|
70
|
+
/**
|
|
71
|
+
* Configure cryptographic provider for authenticated sync
|
|
72
|
+
*/
|
|
73
|
+
configureCrypto(provider: ICryptoProvider): void;
|
|
74
|
+
/**
|
|
75
|
+
* Check if crypto is configured
|
|
76
|
+
*/
|
|
77
|
+
isCryptoEnabled(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Register a node with DID-based identity
|
|
80
|
+
*/
|
|
81
|
+
registerAuthenticatedNode(nodeInfo: Omit<SyncNode, 'did' | 'publicSigningKey' | 'publicEncryptionKey'> & {
|
|
82
|
+
did: string;
|
|
83
|
+
publicSigningKey: JsonWebKey;
|
|
84
|
+
publicEncryptionKey?: JsonWebKey;
|
|
85
|
+
}): Promise<SyncNode>;
|
|
86
|
+
/**
|
|
87
|
+
* Get node by DID
|
|
88
|
+
*/
|
|
89
|
+
getNodeByDID(did: string): SyncNode | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Get all authenticated nodes (nodes with DIDs)
|
|
92
|
+
*/
|
|
93
|
+
getAuthenticatedNodes(): SyncNode[];
|
|
94
|
+
/**
|
|
95
|
+
* Create an authenticated sync session with UCAN-based authorization
|
|
96
|
+
*/
|
|
97
|
+
createAuthenticatedSyncSession(initiatorDID: string, participantDIDs: string[], options?: {
|
|
98
|
+
encryptionMode?: AeonEncryptionMode;
|
|
99
|
+
requiredCapabilities?: string[];
|
|
100
|
+
}): Promise<SyncSession>;
|
|
101
|
+
/**
|
|
102
|
+
* Verify a node's UCAN capabilities for a session
|
|
103
|
+
*/
|
|
104
|
+
verifyNodeCapabilities(sessionId: string, nodeDID: string, token: string): Promise<{
|
|
105
|
+
authorized: boolean;
|
|
106
|
+
error?: string;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Register a node in the cluster
|
|
110
|
+
*/
|
|
111
|
+
registerNode(node: SyncNode): void;
|
|
112
|
+
/**
|
|
113
|
+
* Deregister a node from the cluster
|
|
114
|
+
*/
|
|
115
|
+
deregisterNode(nodeId: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Create a new sync session
|
|
118
|
+
*/
|
|
119
|
+
createSyncSession(initiatorId: string, participantIds: string[]): SyncSession;
|
|
120
|
+
/**
|
|
121
|
+
* Update sync session
|
|
122
|
+
*/
|
|
123
|
+
updateSyncSession(sessionId: string, updates: Partial<SyncSession>): void;
|
|
124
|
+
/**
|
|
125
|
+
* Record a conflict during sync
|
|
126
|
+
*/
|
|
127
|
+
recordConflict(sessionId: string, nodeId: string, conflictData?: unknown): void;
|
|
128
|
+
/**
|
|
129
|
+
* Update node status
|
|
130
|
+
*/
|
|
131
|
+
updateNodeStatus(nodeId: string, status: SyncNode['status']): void;
|
|
132
|
+
/**
|
|
133
|
+
* Record heartbeat from node
|
|
134
|
+
*/
|
|
135
|
+
recordHeartbeat(nodeId: string): void;
|
|
136
|
+
/**
|
|
137
|
+
* Get all nodes
|
|
138
|
+
*/
|
|
139
|
+
getNodes(): SyncNode[];
|
|
140
|
+
/**
|
|
141
|
+
* Get node by ID
|
|
142
|
+
*/
|
|
143
|
+
getNode(nodeId: string): SyncNode | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Get online nodes
|
|
146
|
+
*/
|
|
147
|
+
getOnlineNodes(): SyncNode[];
|
|
148
|
+
/**
|
|
149
|
+
* Get nodes by capability
|
|
150
|
+
*/
|
|
151
|
+
getNodesByCapability(capability: string): SyncNode[];
|
|
152
|
+
/**
|
|
153
|
+
* Get sync session
|
|
154
|
+
*/
|
|
155
|
+
getSyncSession(sessionId: string): SyncSession | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Get all sync sessions
|
|
158
|
+
*/
|
|
159
|
+
getAllSyncSessions(): SyncSession[];
|
|
160
|
+
/**
|
|
161
|
+
* Get active sync sessions
|
|
162
|
+
*/
|
|
163
|
+
getActiveSyncSessions(): SyncSession[];
|
|
164
|
+
/**
|
|
165
|
+
* Get sessions for a node
|
|
166
|
+
*/
|
|
167
|
+
getSessionsForNode(nodeId: string): SyncSession[];
|
|
168
|
+
/**
|
|
169
|
+
* Get sync statistics
|
|
170
|
+
*/
|
|
171
|
+
getStatistics(): {
|
|
172
|
+
totalNodes: number;
|
|
173
|
+
onlineNodes: number;
|
|
174
|
+
offlineNodes: number;
|
|
175
|
+
totalSessions: number;
|
|
176
|
+
activeSessions: number;
|
|
177
|
+
completedSessions: number;
|
|
178
|
+
failedSessions: number;
|
|
179
|
+
successRate: number;
|
|
180
|
+
totalItemsSynced: number;
|
|
181
|
+
totalConflicts: number;
|
|
182
|
+
averageConflictsPerSession: number;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Get sync events
|
|
186
|
+
*/
|
|
187
|
+
getSyncEvents(limit?: number): SyncEvent[];
|
|
188
|
+
/**
|
|
189
|
+
* Get sync events for session
|
|
190
|
+
*/
|
|
191
|
+
getSessionEvents(sessionId: string): SyncEvent[];
|
|
192
|
+
/**
|
|
193
|
+
* Check node health
|
|
194
|
+
*/
|
|
195
|
+
getNodeHealth(): Record<string, {
|
|
196
|
+
isHealthy: boolean;
|
|
197
|
+
downtime: number;
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Start heartbeat monitoring
|
|
201
|
+
*/
|
|
202
|
+
startHeartbeatMonitoring(interval?: number): void;
|
|
203
|
+
/**
|
|
204
|
+
* Stop heartbeat monitoring
|
|
205
|
+
*/
|
|
206
|
+
stopHeartbeatMonitoring(): void;
|
|
207
|
+
/**
|
|
208
|
+
* Clear all state (for testing)
|
|
209
|
+
*/
|
|
210
|
+
clear(): void;
|
|
211
|
+
/**
|
|
212
|
+
* Get the crypto provider (for advanced usage)
|
|
213
|
+
*/
|
|
214
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Replication Manager
|
|
219
|
+
*
|
|
220
|
+
* Manages data replication across multiple nodes.
|
|
221
|
+
* Handles replication policies, consistency levels, and replica coordination.
|
|
222
|
+
*
|
|
223
|
+
* Features:
|
|
224
|
+
* - Replica set management
|
|
225
|
+
* - Replication policy enforcement
|
|
226
|
+
* - Consistency level tracking
|
|
227
|
+
* - Replication health monitoring
|
|
228
|
+
* - Replica synchronization coordination
|
|
229
|
+
* - End-to-end encryption for replicated data
|
|
230
|
+
* - DID-based replica authentication
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
interface Replica {
|
|
234
|
+
id: string;
|
|
235
|
+
nodeId: string;
|
|
236
|
+
status: 'primary' | 'secondary' | 'syncing' | 'failed';
|
|
237
|
+
lastSyncTime: string;
|
|
238
|
+
lagBytes: number;
|
|
239
|
+
lagMillis: number;
|
|
240
|
+
did?: string;
|
|
241
|
+
encrypted?: boolean;
|
|
242
|
+
}
|
|
243
|
+
interface ReplicationPolicy {
|
|
244
|
+
id: string;
|
|
245
|
+
name: string;
|
|
246
|
+
replicationFactor: number;
|
|
247
|
+
consistencyLevel: 'eventual' | 'read-after-write' | 'strong';
|
|
248
|
+
syncInterval: number;
|
|
249
|
+
maxReplicationLag: number;
|
|
250
|
+
encryptionMode?: AeonEncryptionMode;
|
|
251
|
+
requiredCapabilities?: string[];
|
|
252
|
+
}
|
|
253
|
+
interface ReplicationEvent {
|
|
254
|
+
type: 'replica-added' | 'replica-removed' | 'replica-synced' | 'sync-failed';
|
|
255
|
+
replicaId: string;
|
|
256
|
+
nodeId: string;
|
|
257
|
+
timestamp: string;
|
|
258
|
+
details?: unknown;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Encrypted replication data envelope
|
|
262
|
+
*/
|
|
263
|
+
interface EncryptedReplicationData {
|
|
264
|
+
/** Encrypted ciphertext (base64) */
|
|
265
|
+
ct: string;
|
|
266
|
+
/** Initialization vector (base64) */
|
|
267
|
+
iv: string;
|
|
268
|
+
/** Authentication tag (base64) */
|
|
269
|
+
tag: string;
|
|
270
|
+
/** Ephemeral public key for ECIES */
|
|
271
|
+
epk?: JsonWebKey;
|
|
272
|
+
/** Sender DID */
|
|
273
|
+
senderDID?: string;
|
|
274
|
+
/** Target replica DID */
|
|
275
|
+
targetDID?: string;
|
|
276
|
+
/** Encryption timestamp */
|
|
277
|
+
encryptedAt: number;
|
|
278
|
+
}
|
|
279
|
+
interface ReplicationPersistenceData {
|
|
280
|
+
replicas: Replica[];
|
|
281
|
+
policies: ReplicationPolicy[];
|
|
282
|
+
syncStatus: Array<{
|
|
283
|
+
nodeId: string;
|
|
284
|
+
synced: number;
|
|
285
|
+
failed: number;
|
|
286
|
+
}>;
|
|
287
|
+
}
|
|
288
|
+
interface ReplicationPersistenceConfig {
|
|
289
|
+
adapter: StorageAdapter;
|
|
290
|
+
key?: string;
|
|
291
|
+
autoPersist?: boolean;
|
|
292
|
+
autoLoad?: boolean;
|
|
293
|
+
persistDebounceMs?: number;
|
|
294
|
+
serializer?: PersistenceSerializer<ReplicationPersistenceData>;
|
|
295
|
+
deserializer?: PersistenceDeserializer<ReplicationPersistenceData>;
|
|
296
|
+
}
|
|
297
|
+
interface ReplicationManagerOptions {
|
|
298
|
+
persistence?: ReplicationPersistenceConfig;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Replication Manager
|
|
302
|
+
* Manages data replication across distributed nodes
|
|
303
|
+
*/
|
|
304
|
+
declare class ReplicationManager {
|
|
305
|
+
private static readonly DEFAULT_PERSIST_KEY;
|
|
306
|
+
private replicas;
|
|
307
|
+
private policies;
|
|
308
|
+
private replicationEvents;
|
|
309
|
+
private syncStatus;
|
|
310
|
+
private cryptoProvider;
|
|
311
|
+
private replicasByDID;
|
|
312
|
+
private persistence;
|
|
313
|
+
private persistTimer;
|
|
314
|
+
private persistInFlight;
|
|
315
|
+
private persistPending;
|
|
316
|
+
constructor(options?: ReplicationManagerOptions);
|
|
317
|
+
/**
|
|
318
|
+
* Configure cryptographic provider for encrypted replication
|
|
319
|
+
*/
|
|
320
|
+
configureCrypto(provider: ICryptoProvider): void;
|
|
321
|
+
/**
|
|
322
|
+
* Check if crypto is configured
|
|
323
|
+
*/
|
|
324
|
+
isCryptoEnabled(): boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Register an authenticated replica with DID
|
|
327
|
+
*/
|
|
328
|
+
registerAuthenticatedReplica(replica: Omit<Replica, 'did' | 'encrypted'> & {
|
|
329
|
+
did: string;
|
|
330
|
+
publicSigningKey?: JsonWebKey;
|
|
331
|
+
publicEncryptionKey?: JsonWebKey;
|
|
332
|
+
}, encrypted?: boolean): Promise<Replica>;
|
|
333
|
+
/**
|
|
334
|
+
* Get replica by DID
|
|
335
|
+
*/
|
|
336
|
+
getReplicaByDID(did: string): Replica | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Get all encrypted replicas
|
|
339
|
+
*/
|
|
340
|
+
getEncryptedReplicas(): Replica[];
|
|
341
|
+
/**
|
|
342
|
+
* Encrypt data for replication to a specific replica
|
|
343
|
+
*/
|
|
344
|
+
encryptForReplica(data: unknown, targetReplicaDID: string): Promise<EncryptedReplicationData>;
|
|
345
|
+
/**
|
|
346
|
+
* Decrypt data received from replication
|
|
347
|
+
*/
|
|
348
|
+
decryptReplicationData<T>(encrypted: EncryptedReplicationData): Promise<T>;
|
|
349
|
+
/**
|
|
350
|
+
* Create an encrypted replication policy
|
|
351
|
+
*/
|
|
352
|
+
createEncryptedPolicy(name: string, replicationFactor: number, consistencyLevel: 'eventual' | 'read-after-write' | 'strong', encryptionMode: AeonEncryptionMode, options?: {
|
|
353
|
+
syncInterval?: number;
|
|
354
|
+
maxReplicationLag?: number;
|
|
355
|
+
requiredCapabilities?: string[];
|
|
356
|
+
}): ReplicationPolicy;
|
|
357
|
+
/**
|
|
358
|
+
* Verify a replica's capabilities via UCAN
|
|
359
|
+
*/
|
|
360
|
+
verifyReplicaCapabilities(replicaDID: string, token: string, policyId?: string): Promise<{
|
|
361
|
+
authorized: boolean;
|
|
362
|
+
error?: string;
|
|
363
|
+
}>;
|
|
364
|
+
/**
|
|
365
|
+
* Register a replica
|
|
366
|
+
*/
|
|
367
|
+
registerReplica(replica: Replica): void;
|
|
368
|
+
/**
|
|
369
|
+
* Remove a replica
|
|
370
|
+
*/
|
|
371
|
+
removeReplica(replicaId: string): void;
|
|
372
|
+
/**
|
|
373
|
+
* Create a replication policy
|
|
374
|
+
*/
|
|
375
|
+
createPolicy(name: string, replicationFactor: number, consistencyLevel: 'eventual' | 'read-after-write' | 'strong', syncInterval?: number, maxReplicationLag?: number): ReplicationPolicy;
|
|
376
|
+
/**
|
|
377
|
+
* Update replica status
|
|
378
|
+
*/
|
|
379
|
+
updateReplicaStatus(replicaId: string, status: Replica['status'], lagBytes?: number, lagMillis?: number): void;
|
|
380
|
+
/**
|
|
381
|
+
* Get replicas for node
|
|
382
|
+
*/
|
|
383
|
+
getReplicasForNode(nodeId: string): Replica[];
|
|
384
|
+
/**
|
|
385
|
+
* Get healthy replicas
|
|
386
|
+
*/
|
|
387
|
+
getHealthyReplicas(): Replica[];
|
|
388
|
+
/**
|
|
389
|
+
* Get syncing replicas
|
|
390
|
+
*/
|
|
391
|
+
getSyncingReplicas(): Replica[];
|
|
392
|
+
/**
|
|
393
|
+
* Get failed replicas
|
|
394
|
+
*/
|
|
395
|
+
getFailedReplicas(): Replica[];
|
|
396
|
+
/**
|
|
397
|
+
* Check replication health for policy
|
|
398
|
+
*/
|
|
399
|
+
checkReplicationHealth(policyId: string): {
|
|
400
|
+
healthy: boolean;
|
|
401
|
+
replicasInPolicy: number;
|
|
402
|
+
healthyReplicas: number;
|
|
403
|
+
replicationLag: number;
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Get consistency level
|
|
407
|
+
*/
|
|
408
|
+
getConsistencyLevel(policyId: string): 'eventual' | 'read-after-write' | 'strong';
|
|
409
|
+
/**
|
|
410
|
+
* Get replica
|
|
411
|
+
*/
|
|
412
|
+
getReplica(replicaId: string): Replica | undefined;
|
|
413
|
+
/**
|
|
414
|
+
* Get all replicas
|
|
415
|
+
*/
|
|
416
|
+
getAllReplicas(): Replica[];
|
|
417
|
+
/**
|
|
418
|
+
* Get policy
|
|
419
|
+
*/
|
|
420
|
+
getPolicy(policyId: string): ReplicationPolicy | undefined;
|
|
421
|
+
/**
|
|
422
|
+
* Get all policies
|
|
423
|
+
*/
|
|
424
|
+
getAllPolicies(): ReplicationPolicy[];
|
|
425
|
+
/**
|
|
426
|
+
* Get replication statistics
|
|
427
|
+
*/
|
|
428
|
+
getStatistics(): {
|
|
429
|
+
totalReplicas: number;
|
|
430
|
+
healthyReplicas: number;
|
|
431
|
+
syncingReplicas: number;
|
|
432
|
+
failedReplicas: number;
|
|
433
|
+
healthiness: number;
|
|
434
|
+
averageReplicationLagMs: number;
|
|
435
|
+
maxReplicationLagMs: number;
|
|
436
|
+
totalPolicies: number;
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* Get replication events
|
|
440
|
+
*/
|
|
441
|
+
getReplicationEvents(limit?: number): ReplicationEvent[];
|
|
442
|
+
/**
|
|
443
|
+
* Get sync status for node
|
|
444
|
+
*/
|
|
445
|
+
getSyncStatus(nodeId: string): {
|
|
446
|
+
synced: number;
|
|
447
|
+
failed: number;
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Get replication lag distribution
|
|
451
|
+
*/
|
|
452
|
+
getReplicationLagDistribution(): Record<string, number>;
|
|
453
|
+
/**
|
|
454
|
+
* Check if can satisfy consistency level
|
|
455
|
+
*/
|
|
456
|
+
canSatisfyConsistency(policyId: string, _requiredAcks: number): boolean;
|
|
457
|
+
/**
|
|
458
|
+
* Persist current replication state snapshot.
|
|
459
|
+
*/
|
|
460
|
+
saveToPersistence(): Promise<void>;
|
|
461
|
+
/**
|
|
462
|
+
* Load replication snapshot from persistence.
|
|
463
|
+
*/
|
|
464
|
+
loadFromPersistence(): Promise<{
|
|
465
|
+
replicas: number;
|
|
466
|
+
policies: number;
|
|
467
|
+
syncStatus: number;
|
|
468
|
+
}>;
|
|
469
|
+
/**
|
|
470
|
+
* Remove persisted replication snapshot.
|
|
471
|
+
*/
|
|
472
|
+
clearPersistence(): Promise<void>;
|
|
473
|
+
private schedulePersist;
|
|
474
|
+
private persistSafely;
|
|
475
|
+
private isValidReplica;
|
|
476
|
+
private isValidPolicy;
|
|
477
|
+
/**
|
|
478
|
+
* Clear all state (for testing)
|
|
479
|
+
*/
|
|
480
|
+
clear(): void;
|
|
481
|
+
/**
|
|
482
|
+
* Get the crypto provider (for advanced usage)
|
|
483
|
+
*/
|
|
484
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Sync Protocol
|
|
489
|
+
*
|
|
490
|
+
* Handles synchronization protocol messages and handshaking.
|
|
491
|
+
* Manages message serialization, protocol versioning, and compatibility.
|
|
492
|
+
*
|
|
493
|
+
* Features:
|
|
494
|
+
* - Message serialization and deserialization
|
|
495
|
+
* - Protocol version management
|
|
496
|
+
* - Handshake handling
|
|
497
|
+
* - Message validation and error handling
|
|
498
|
+
* - Protocol state machine
|
|
499
|
+
* - Optional cryptographic authentication and encryption
|
|
500
|
+
*/
|
|
501
|
+
|
|
502
|
+
interface SyncMessage {
|
|
503
|
+
type: 'handshake' | 'sync-request' | 'sync-response' | 'ack' | 'error';
|
|
504
|
+
version: string;
|
|
505
|
+
sender: string;
|
|
506
|
+
receiver: string;
|
|
507
|
+
messageId: string;
|
|
508
|
+
timestamp: string;
|
|
509
|
+
payload?: unknown;
|
|
510
|
+
auth?: AuthenticatedMessageFields;
|
|
511
|
+
}
|
|
512
|
+
interface Handshake {
|
|
513
|
+
protocolVersion: string;
|
|
514
|
+
nodeId: string;
|
|
515
|
+
capabilities: string[];
|
|
516
|
+
state: 'initiating' | 'responding' | 'completed';
|
|
517
|
+
did?: string;
|
|
518
|
+
publicSigningKey?: JsonWebKey;
|
|
519
|
+
publicEncryptionKey?: JsonWebKey;
|
|
520
|
+
ucan?: string;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Crypto configuration for sync protocol
|
|
524
|
+
*/
|
|
525
|
+
interface SyncProtocolCryptoConfig {
|
|
526
|
+
/** Encryption mode for messages */
|
|
527
|
+
encryptionMode: AeonEncryptionMode;
|
|
528
|
+
/** Require all messages to be signed */
|
|
529
|
+
requireSignatures: boolean;
|
|
530
|
+
/** Require UCAN capability verification */
|
|
531
|
+
requireCapabilities: boolean;
|
|
532
|
+
/** Required capabilities for sync operations */
|
|
533
|
+
requiredCapabilities?: Array<{
|
|
534
|
+
can: string;
|
|
535
|
+
with: string;
|
|
536
|
+
}>;
|
|
537
|
+
}
|
|
538
|
+
interface SyncRequest {
|
|
539
|
+
sessionId: string;
|
|
540
|
+
fromVersion: string;
|
|
541
|
+
toVersion: string;
|
|
542
|
+
filter?: Record<string, unknown>;
|
|
543
|
+
}
|
|
544
|
+
interface SyncResponse {
|
|
545
|
+
sessionId: string;
|
|
546
|
+
fromVersion: string;
|
|
547
|
+
toVersion: string;
|
|
548
|
+
data: unknown[];
|
|
549
|
+
hasMore: boolean;
|
|
550
|
+
offset: number;
|
|
551
|
+
}
|
|
552
|
+
interface ProtocolError {
|
|
553
|
+
code: string;
|
|
554
|
+
message: string;
|
|
555
|
+
recoverable: boolean;
|
|
556
|
+
}
|
|
557
|
+
interface SyncProtocolPersistenceData {
|
|
558
|
+
protocolVersion: string;
|
|
559
|
+
messageCounter: number;
|
|
560
|
+
messageQueue: SyncMessage[];
|
|
561
|
+
handshakes: Array<{
|
|
562
|
+
nodeId: string;
|
|
563
|
+
handshake: Handshake;
|
|
564
|
+
}>;
|
|
565
|
+
protocolErrors: Array<{
|
|
566
|
+
error: ProtocolError;
|
|
567
|
+
timestamp: string;
|
|
568
|
+
}>;
|
|
569
|
+
}
|
|
570
|
+
interface SyncProtocolPersistenceConfig {
|
|
571
|
+
adapter: StorageAdapter;
|
|
572
|
+
key?: string;
|
|
573
|
+
autoPersist?: boolean;
|
|
574
|
+
autoLoad?: boolean;
|
|
575
|
+
persistDebounceMs?: number;
|
|
576
|
+
serializer?: PersistenceSerializer<SyncProtocolPersistenceData>;
|
|
577
|
+
deserializer?: PersistenceDeserializer<SyncProtocolPersistenceData>;
|
|
578
|
+
}
|
|
579
|
+
interface SyncProtocolOptions {
|
|
580
|
+
persistence?: SyncProtocolPersistenceConfig;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Sync Protocol
|
|
584
|
+
* Handles synchronization protocol messages and handshaking
|
|
585
|
+
*/
|
|
586
|
+
declare class SyncProtocol {
|
|
587
|
+
private static readonly DEFAULT_PERSIST_KEY;
|
|
588
|
+
private version;
|
|
589
|
+
private messageQueue;
|
|
590
|
+
private messageMap;
|
|
591
|
+
private handshakes;
|
|
592
|
+
private protocolErrors;
|
|
593
|
+
private messageCounter;
|
|
594
|
+
private cryptoProvider;
|
|
595
|
+
private cryptoConfig;
|
|
596
|
+
private persistence;
|
|
597
|
+
private persistTimer;
|
|
598
|
+
private persistInFlight;
|
|
599
|
+
private persistPending;
|
|
600
|
+
constructor(options?: SyncProtocolOptions);
|
|
601
|
+
/**
|
|
602
|
+
* Configure cryptographic provider for authenticated/encrypted messages
|
|
603
|
+
*/
|
|
604
|
+
configureCrypto(provider: ICryptoProvider, config?: Partial<SyncProtocolCryptoConfig>): void;
|
|
605
|
+
/**
|
|
606
|
+
* Check if crypto is configured
|
|
607
|
+
*/
|
|
608
|
+
isCryptoEnabled(): boolean;
|
|
609
|
+
/**
|
|
610
|
+
* Get crypto configuration
|
|
611
|
+
*/
|
|
612
|
+
getCryptoConfig(): SyncProtocolCryptoConfig | null;
|
|
613
|
+
/**
|
|
614
|
+
* Get protocol version
|
|
615
|
+
*/
|
|
616
|
+
getVersion(): string;
|
|
617
|
+
/**
|
|
618
|
+
* Create authenticated handshake message with DID and keys
|
|
619
|
+
*/
|
|
620
|
+
createAuthenticatedHandshake(capabilities: string[], targetDID?: string): Promise<SyncMessage>;
|
|
621
|
+
/**
|
|
622
|
+
* Verify and process an authenticated handshake
|
|
623
|
+
*/
|
|
624
|
+
verifyAuthenticatedHandshake(message: SyncMessage): Promise<{
|
|
625
|
+
valid: boolean;
|
|
626
|
+
handshake?: Handshake;
|
|
627
|
+
error?: string;
|
|
628
|
+
}>;
|
|
629
|
+
/**
|
|
630
|
+
* Sign and optionally encrypt a message payload
|
|
631
|
+
*/
|
|
632
|
+
signMessage<T>(message: SyncMessage, payload: T, encrypt?: boolean): Promise<SyncMessage>;
|
|
633
|
+
/**
|
|
634
|
+
* Verify signature and optionally decrypt a message
|
|
635
|
+
*/
|
|
636
|
+
verifyMessage<T>(message: SyncMessage): Promise<{
|
|
637
|
+
valid: boolean;
|
|
638
|
+
payload?: T;
|
|
639
|
+
error?: string;
|
|
640
|
+
}>;
|
|
641
|
+
/**
|
|
642
|
+
* Create handshake message
|
|
643
|
+
*/
|
|
644
|
+
createHandshakeMessage(nodeId: string, capabilities: string[]): SyncMessage;
|
|
645
|
+
/**
|
|
646
|
+
* Create sync request message
|
|
647
|
+
*/
|
|
648
|
+
createSyncRequestMessage(sender: string, receiver: string, sessionId: string, fromVersion: string, toVersion: string, filter?: Record<string, unknown>): SyncMessage;
|
|
649
|
+
/**
|
|
650
|
+
* Create sync response message
|
|
651
|
+
*/
|
|
652
|
+
createSyncResponseMessage(sender: string, receiver: string, sessionId: string, fromVersion: string, toVersion: string, data: unknown[], hasMore?: boolean, offset?: number): SyncMessage;
|
|
653
|
+
/**
|
|
654
|
+
* Create acknowledgement message
|
|
655
|
+
*/
|
|
656
|
+
createAckMessage(sender: string, receiver: string, messageId: string): SyncMessage;
|
|
657
|
+
/**
|
|
658
|
+
* Create error message
|
|
659
|
+
*/
|
|
660
|
+
createErrorMessage(sender: string, receiver: string, error: ProtocolError, relatedMessageId?: string): SyncMessage;
|
|
661
|
+
/**
|
|
662
|
+
* Validate message
|
|
663
|
+
*/
|
|
664
|
+
validateMessage(message: SyncMessage): {
|
|
665
|
+
valid: boolean;
|
|
666
|
+
errors: string[];
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Serialize message
|
|
670
|
+
*/
|
|
671
|
+
serializeMessage(message: SyncMessage): string;
|
|
672
|
+
/**
|
|
673
|
+
* Deserialize message
|
|
674
|
+
*/
|
|
675
|
+
deserializeMessage(data: string): SyncMessage;
|
|
676
|
+
/**
|
|
677
|
+
* Process handshake
|
|
678
|
+
*/
|
|
679
|
+
processHandshake(message: SyncMessage): Handshake;
|
|
680
|
+
/**
|
|
681
|
+
* Get message
|
|
682
|
+
*/
|
|
683
|
+
getMessage(messageId: string): SyncMessage | undefined;
|
|
684
|
+
/**
|
|
685
|
+
* Get all messages
|
|
686
|
+
*/
|
|
687
|
+
getAllMessages(): SyncMessage[];
|
|
688
|
+
/**
|
|
689
|
+
* Get messages by type
|
|
690
|
+
*/
|
|
691
|
+
getMessagesByType(type: SyncMessage['type']): SyncMessage[];
|
|
692
|
+
/**
|
|
693
|
+
* Get messages from sender
|
|
694
|
+
*/
|
|
695
|
+
getMessagesFromSender(sender: string): SyncMessage[];
|
|
696
|
+
/**
|
|
697
|
+
* Get pending messages
|
|
698
|
+
*/
|
|
699
|
+
getPendingMessages(receiver: string): SyncMessage[];
|
|
700
|
+
/**
|
|
701
|
+
* Get handshakes
|
|
702
|
+
*/
|
|
703
|
+
getHandshakes(): Map<string, Handshake>;
|
|
704
|
+
/**
|
|
705
|
+
* Get protocol statistics
|
|
706
|
+
*/
|
|
707
|
+
getStatistics(): {
|
|
708
|
+
totalMessages: number;
|
|
709
|
+
messagesByType: Record<string, number>;
|
|
710
|
+
totalHandshakes: number;
|
|
711
|
+
totalErrors: number;
|
|
712
|
+
recoverableErrors: number;
|
|
713
|
+
unrecoverableErrors: number;
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* Get protocol errors
|
|
717
|
+
*/
|
|
718
|
+
getErrors(): Array<{
|
|
719
|
+
error: ProtocolError;
|
|
720
|
+
timestamp: string;
|
|
721
|
+
}>;
|
|
722
|
+
/**
|
|
723
|
+
* Persist protocol state for reconnect/replay.
|
|
724
|
+
*/
|
|
725
|
+
saveToPersistence(): Promise<void>;
|
|
726
|
+
/**
|
|
727
|
+
* Load protocol state from persistence.
|
|
728
|
+
*/
|
|
729
|
+
loadFromPersistence(): Promise<{
|
|
730
|
+
messages: number;
|
|
731
|
+
handshakes: number;
|
|
732
|
+
errors: number;
|
|
733
|
+
}>;
|
|
734
|
+
/**
|
|
735
|
+
* Clear persisted protocol checkpoint.
|
|
736
|
+
*/
|
|
737
|
+
clearPersistence(): Promise<void>;
|
|
738
|
+
private schedulePersist;
|
|
739
|
+
private persistSafely;
|
|
740
|
+
private isValidHandshake;
|
|
741
|
+
private isValidProtocolErrorEntry;
|
|
742
|
+
/**
|
|
743
|
+
* Generate message ID
|
|
744
|
+
*/
|
|
745
|
+
private generateMessageId;
|
|
746
|
+
/**
|
|
747
|
+
* Clear all state (for testing)
|
|
748
|
+
*/
|
|
749
|
+
clear(): void;
|
|
750
|
+
/**
|
|
751
|
+
* Get the crypto provider (for advanced usage)
|
|
752
|
+
*/
|
|
753
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* State Reconciler
|
|
758
|
+
*
|
|
759
|
+
* Reconciles conflicting state across multiple nodes in a distributed system.
|
|
760
|
+
* Applies merge strategies and resolves divergent state.
|
|
761
|
+
*
|
|
762
|
+
* Features:
|
|
763
|
+
* - State comparison and diff generation
|
|
764
|
+
* - Multiple merge strategies (last-write-wins, vector-clock based, custom)
|
|
765
|
+
* - Conflict detection and resolution
|
|
766
|
+
* - State validation and verification
|
|
767
|
+
* - Version tracking
|
|
768
|
+
* - Cryptographic verification of state versions
|
|
769
|
+
* - Signed state for tamper detection
|
|
770
|
+
*/
|
|
771
|
+
|
|
772
|
+
interface StateVersion {
|
|
773
|
+
version: string;
|
|
774
|
+
timestamp: string;
|
|
775
|
+
nodeId: string;
|
|
776
|
+
hash: string;
|
|
777
|
+
data: unknown;
|
|
778
|
+
signerDID?: string;
|
|
779
|
+
signature?: string;
|
|
780
|
+
signedAt?: number;
|
|
781
|
+
}
|
|
782
|
+
interface StateDiff {
|
|
783
|
+
added: Record<string, unknown>;
|
|
784
|
+
modified: Record<string, {
|
|
785
|
+
old: unknown;
|
|
786
|
+
new: unknown;
|
|
787
|
+
}>;
|
|
788
|
+
removed: string[];
|
|
789
|
+
timestamp: string;
|
|
790
|
+
}
|
|
791
|
+
interface ReconciliationResult {
|
|
792
|
+
success: boolean;
|
|
793
|
+
mergedState: unknown;
|
|
794
|
+
conflictsResolved: number;
|
|
795
|
+
strategy: string;
|
|
796
|
+
timestamp: string;
|
|
797
|
+
}
|
|
798
|
+
type MergeStrategy = 'last-write-wins' | 'vector-clock' | 'majority-vote' | 'custom';
|
|
799
|
+
/**
|
|
800
|
+
* State Reconciler
|
|
801
|
+
* Reconciles state conflicts across distributed nodes
|
|
802
|
+
*/
|
|
803
|
+
declare class StateReconciler {
|
|
804
|
+
private stateVersions;
|
|
805
|
+
private reconciliationHistory;
|
|
806
|
+
private cryptoProvider;
|
|
807
|
+
private requireSignedVersions;
|
|
808
|
+
/**
|
|
809
|
+
* Configure cryptographic provider for signed state versions
|
|
810
|
+
*/
|
|
811
|
+
configureCrypto(provider: ICryptoProvider, requireSigned?: boolean): void;
|
|
812
|
+
/**
|
|
813
|
+
* Check if crypto is configured
|
|
814
|
+
*/
|
|
815
|
+
isCryptoEnabled(): boolean;
|
|
816
|
+
/**
|
|
817
|
+
* Record a signed state version with cryptographic verification
|
|
818
|
+
*/
|
|
819
|
+
recordSignedStateVersion(key: string, version: string, data: unknown): Promise<StateVersion>;
|
|
820
|
+
/**
|
|
821
|
+
* Verify a state version's signature
|
|
822
|
+
*/
|
|
823
|
+
verifyStateVersion(version: StateVersion): Promise<{
|
|
824
|
+
valid: boolean;
|
|
825
|
+
error?: string;
|
|
826
|
+
}>;
|
|
827
|
+
/**
|
|
828
|
+
* Reconcile with verification - only accept verified versions
|
|
829
|
+
*/
|
|
830
|
+
reconcileWithVerification(key: string, strategy?: MergeStrategy): Promise<ReconciliationResult & {
|
|
831
|
+
verificationErrors: string[];
|
|
832
|
+
}>;
|
|
833
|
+
/**
|
|
834
|
+
* Record a state version
|
|
835
|
+
*/
|
|
836
|
+
recordStateVersion(key: string, version: string, timestamp: string, nodeId: string, hash: string, data: unknown): void;
|
|
837
|
+
/**
|
|
838
|
+
* Detect conflicts in state versions
|
|
839
|
+
*/
|
|
840
|
+
detectConflicts(key: string): boolean;
|
|
841
|
+
/**
|
|
842
|
+
* Compare two states and generate diff
|
|
843
|
+
*/
|
|
844
|
+
compareStates(state1: Record<string, unknown>, state2: Record<string, unknown>): StateDiff;
|
|
845
|
+
/**
|
|
846
|
+
* Reconcile states using last-write-wins strategy
|
|
847
|
+
*/
|
|
848
|
+
reconcileLastWriteWins(versions: StateVersion[]): ReconciliationResult;
|
|
849
|
+
/**
|
|
850
|
+
* Reconcile states using vector clock strategy
|
|
851
|
+
*/
|
|
852
|
+
reconcileVectorClock(versions: StateVersion[]): ReconciliationResult;
|
|
853
|
+
/**
|
|
854
|
+
* Reconcile states using majority vote strategy
|
|
855
|
+
*/
|
|
856
|
+
reconcileMajorityVote(versions: StateVersion[]): ReconciliationResult;
|
|
857
|
+
/**
|
|
858
|
+
* Merge multiple states
|
|
859
|
+
*/
|
|
860
|
+
mergeStates(states: Record<string, unknown>[]): unknown;
|
|
861
|
+
/**
|
|
862
|
+
* Validate state after reconciliation
|
|
863
|
+
*/
|
|
864
|
+
validateState(state: unknown): {
|
|
865
|
+
valid: boolean;
|
|
866
|
+
errors: string[];
|
|
867
|
+
};
|
|
868
|
+
/**
|
|
869
|
+
* Get state versions for a key
|
|
870
|
+
*/
|
|
871
|
+
getStateVersions(key: string): StateVersion[];
|
|
872
|
+
/**
|
|
873
|
+
* Get all state versions
|
|
874
|
+
*/
|
|
875
|
+
getAllStateVersions(): Record<string, StateVersion[]>;
|
|
876
|
+
/**
|
|
877
|
+
* Get reconciliation history
|
|
878
|
+
*/
|
|
879
|
+
getReconciliationHistory(): ReconciliationResult[];
|
|
880
|
+
/**
|
|
881
|
+
* Get reconciliation statistics
|
|
882
|
+
*/
|
|
883
|
+
getStatistics(): {
|
|
884
|
+
totalReconciliations: number;
|
|
885
|
+
successfulReconciliations: number;
|
|
886
|
+
totalConflictsResolved: number;
|
|
887
|
+
averageConflictsPerReconciliation: number;
|
|
888
|
+
strategyUsage: Record<string, number>;
|
|
889
|
+
trackedKeys: number;
|
|
890
|
+
};
|
|
891
|
+
/**
|
|
892
|
+
* Clear all state (for testing)
|
|
893
|
+
*/
|
|
894
|
+
clear(): void;
|
|
895
|
+
/**
|
|
896
|
+
* Get the crypto provider (for advanced usage)
|
|
897
|
+
*/
|
|
898
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
export { type Handshake, type MergeStrategy, type ProtocolError, type ReconciliationResult, type Replica, type ReplicationEvent, ReplicationManager, type ReplicationManagerOptions, type ReplicationPersistenceConfig, type ReplicationPersistenceData, type ReplicationPolicy, type StateDiff, StateReconciler, type StateVersion, SyncCoordinator, type SyncEvent, type SyncMessage, type SyncNode, SyncProtocol, type SyncProtocolOptions, type SyncProtocolPersistenceConfig, type SyncProtocolPersistenceData, type SyncRequest, type SyncResponse, type SyncSession };
|