@affectively/aeon 1.2.0 → 1.3.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.
Files changed (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +342 -342
  3. package/dist/compression/index.cjs.map +1 -1
  4. package/dist/compression/index.js.map +1 -1
  5. package/dist/core/index.d.cts +213 -208
  6. package/dist/core/index.d.ts +213 -208
  7. package/dist/crypto/index.cjs.map +1 -1
  8. package/dist/crypto/index.d.cts +441 -402
  9. package/dist/crypto/index.d.ts +441 -402
  10. package/dist/crypto/index.js.map +1 -1
  11. package/dist/distributed/index.cjs +8 -2
  12. package/dist/distributed/index.cjs.map +1 -1
  13. package/dist/distributed/index.d.cts +1005 -890
  14. package/dist/distributed/index.d.ts +1005 -890
  15. package/dist/distributed/index.js +8 -2
  16. package/dist/distributed/index.js.map +1 -1
  17. package/dist/index.cjs +58 -733
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +50 -5
  20. package/dist/index.d.ts +50 -5
  21. package/dist/index.js +55 -732
  22. package/dist/index.js.map +1 -1
  23. package/dist/offline/index.cjs.map +1 -1
  24. package/dist/offline/index.d.cts +148 -142
  25. package/dist/offline/index.d.ts +148 -142
  26. package/dist/offline/index.js.map +1 -1
  27. package/dist/optimization/index.cjs.map +1 -1
  28. package/dist/optimization/index.js.map +1 -1
  29. package/dist/persistence/index.cjs.map +1 -1
  30. package/dist/persistence/index.d.cts +57 -57
  31. package/dist/persistence/index.d.ts +57 -57
  32. package/dist/persistence/index.js.map +1 -1
  33. package/dist/presence/index.cjs.map +1 -1
  34. package/dist/presence/index.js.map +1 -1
  35. package/dist/{types-CMxO7QF0.d.cts → types-B7CxsoLh.d.cts} +30 -30
  36. package/dist/{types-CMxO7QF0.d.ts → types-B7CxsoLh.d.ts} +30 -30
  37. package/dist/utils/index.cjs.map +1 -1
  38. package/dist/utils/index.d.cts +35 -35
  39. package/dist/utils/index.d.ts +35 -35
  40. package/dist/utils/index.js.map +1 -1
  41. package/dist/versioning/index.cjs +18 -8
  42. package/dist/versioning/index.cjs.map +1 -1
  43. package/dist/versioning/index.d.cts +1 -1
  44. package/dist/versioning/index.d.ts +1 -1
  45. package/dist/versioning/index.js +18 -8
  46. package/dist/versioning/index.js.map +1 -1
  47. package/package.json +196 -192
package/dist/index.cjs CHANGED
@@ -195,230 +195,6 @@ var InMemoryStorageAdapter = class {
195
195
  }
196
196
  };
197
197
 
198
- // src/versioning/SchemaVersionManager.ts
199
- var SchemaVersionManager = class {
200
- versions = /* @__PURE__ */ new Map();
201
- versionHistory = [];
202
- compatibilityMatrix = /* @__PURE__ */ new Map();
203
- currentVersion = null;
204
- constructor() {
205
- this.initializeDefaultVersions();
206
- }
207
- /**
208
- * Initialize default versions
209
- */
210
- initializeDefaultVersions() {
211
- const v1_0_0 = {
212
- major: 1,
213
- minor: 0,
214
- patch: 0,
215
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
216
- description: "Initial schema version",
217
- breaking: false
218
- };
219
- this.registerVersion(v1_0_0);
220
- this.currentVersion = v1_0_0;
221
- }
222
- /**
223
- * Register a new schema version
224
- */
225
- registerVersion(version) {
226
- const versionString = this.versionToString(version);
227
- this.versions.set(versionString, version);
228
- this.versionHistory.push(version);
229
- logger.debug("[SchemaVersionManager] Version registered", {
230
- version: versionString,
231
- breaking: version.breaking,
232
- description: version.description
233
- });
234
- }
235
- /**
236
- * Get current version
237
- */
238
- getCurrentVersion() {
239
- if (!this.currentVersion) {
240
- throw new Error("No current version set");
241
- }
242
- return this.currentVersion;
243
- }
244
- /**
245
- * Set current version
246
- */
247
- setCurrentVersion(version) {
248
- if (!this.versions.has(this.versionToString(version))) {
249
- throw new Error(
250
- `Version ${this.versionToString(version)} not registered`
251
- );
252
- }
253
- this.currentVersion = version;
254
- logger.debug("[SchemaVersionManager] Current version set", {
255
- version: this.versionToString(version)
256
- });
257
- }
258
- /**
259
- * Get version history
260
- */
261
- getVersionHistory() {
262
- return [...this.versionHistory];
263
- }
264
- /**
265
- * Check if version exists
266
- */
267
- hasVersion(version) {
268
- return this.versions.has(this.versionToString(version));
269
- }
270
- /**
271
- * Get version by string (e.g., "1.2.3")
272
- */
273
- getVersion(versionString) {
274
- return this.versions.get(versionString);
275
- }
276
- /**
277
- * Register compatibility rule
278
- */
279
- registerCompatibility(rule) {
280
- if (!this.compatibilityMatrix.has(rule.from)) {
281
- this.compatibilityMatrix.set(rule.from, []);
282
- }
283
- const rules = this.compatibilityMatrix.get(rule.from);
284
- if (rules) {
285
- rules.push(rule);
286
- }
287
- logger.debug("[SchemaVersionManager] Compatibility rule registered", {
288
- from: rule.from,
289
- to: rule.to,
290
- compatible: rule.compatible,
291
- requiresMigration: rule.requiresMigration
292
- });
293
- }
294
- /**
295
- * Check if migration path exists
296
- */
297
- canMigrate(fromVersion, toVersion) {
298
- const fromStr = typeof fromVersion === "string" ? fromVersion : this.versionToString(fromVersion);
299
- const toStr = typeof toVersion === "string" ? toVersion : this.versionToString(toVersion);
300
- const rules = this.compatibilityMatrix.get(fromStr) || [];
301
- return rules.some((r) => r.to === toStr && r.requiresMigration);
302
- }
303
- /**
304
- * Get migration path
305
- */
306
- getMigrationPath(fromVersion, toVersion) {
307
- const path = [];
308
- let current = fromVersion;
309
- const maxSteps = 100;
310
- let steps = 0;
311
- while (this.compareVersions(current, toVersion) !== 0 && steps < maxSteps) {
312
- const fromStr = this.versionToString(current);
313
- const rules = this.compatibilityMatrix.get(fromStr) || [];
314
- let found = false;
315
- for (const rule of rules) {
316
- const nextVersion = this.getVersion(rule.to);
317
- if (nextVersion) {
318
- if (this.compareVersions(nextVersion, toVersion) <= 0 || this.compareVersions(current, nextVersion) < this.compareVersions(current, toVersion)) {
319
- current = nextVersion;
320
- path.push(current);
321
- found = true;
322
- break;
323
- }
324
- }
325
- }
326
- if (!found) {
327
- break;
328
- }
329
- steps++;
330
- }
331
- return path;
332
- }
333
- /**
334
- * Compare two versions
335
- * Returns: -1 if v1 < v2, 0 if equal, 1 if v1 > v2
336
- */
337
- compareVersions(v1, v2) {
338
- const ver1 = typeof v1 === "string" ? this.parseVersion(v1) : v1;
339
- const ver2 = typeof v2 === "string" ? this.parseVersion(v2) : v2;
340
- if (ver1.major !== ver2.major) {
341
- return ver1.major < ver2.major ? -1 : 1;
342
- }
343
- if (ver1.minor !== ver2.minor) {
344
- return ver1.minor < ver2.minor ? -1 : 1;
345
- }
346
- if (ver1.patch !== ver2.patch) {
347
- return ver1.patch < ver2.patch ? -1 : 1;
348
- }
349
- return 0;
350
- }
351
- /**
352
- * Parse version string to SchemaVersion
353
- */
354
- parseVersion(versionString) {
355
- const parts = versionString.split(".").map(Number);
356
- return {
357
- major: parts[0] || 0,
358
- minor: parts[1] || 0,
359
- patch: parts[2] || 0,
360
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
361
- description: "",
362
- breaking: false
363
- };
364
- }
365
- /**
366
- * Create new version
367
- */
368
- createVersion(major, minor, patch, description, breaking = false) {
369
- return {
370
- major,
371
- minor,
372
- patch,
373
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
374
- description,
375
- breaking
376
- };
377
- }
378
- /**
379
- * Convert version to string
380
- */
381
- versionToString(version) {
382
- return `${version.major}.${version.minor}.${version.patch}`;
383
- }
384
- /**
385
- * Get version metadata
386
- */
387
- getVersionMetadata(version) {
388
- const history = this.versionHistory;
389
- const currentIndex = history.findIndex(
390
- (v) => this.versionToString(v) === this.versionToString(version)
391
- );
392
- return {
393
- version,
394
- previousVersion: currentIndex > 0 ? history[currentIndex - 1] : void 0,
395
- changes: [version.description],
396
- migrationsRequired: this.canMigrate(
397
- this.currentVersion || version,
398
- version
399
- ) ? [this.versionToString(version)] : [],
400
- rollbackPossible: currentIndex > 0
401
- };
402
- }
403
- /**
404
- * Get all registered versions
405
- */
406
- getAllVersions() {
407
- return Array.from(this.versions.values()).sort(
408
- (a, b) => this.compareVersions(a, b)
409
- );
410
- }
411
- /**
412
- * Clear all versions (for testing)
413
- */
414
- clear() {
415
- this.versions.clear();
416
- this.versionHistory = [];
417
- this.compatibilityMatrix.clear();
418
- this.currentVersion = null;
419
- }
420
- };
421
-
422
198
  // src/versioning/MigrationEngine.ts
423
199
  var MigrationEngine = class {
424
200
  migrations = /* @__PURE__ */ new Map();
@@ -1088,11 +864,13 @@ var MigrationTracker = class _MigrationTracker {
1088
864
  });
1089
865
  previousHash = hash;
1090
866
  }
1091
- const persistedMigrations = normalizedMigrations.map((migration, index) => ({
1092
- ...migration,
1093
- previousHash: integrityEntries[index]?.previousHash,
1094
- integrityHash: integrityEntries[index]?.hash
1095
- }));
867
+ const persistedMigrations = normalizedMigrations.map(
868
+ (migration, index) => ({
869
+ ...migration,
870
+ previousHash: integrityEntries[index]?.previousHash,
871
+ integrityHash: integrityEntries[index]?.hash
872
+ })
873
+ );
1096
874
  const data = {
1097
875
  migrations: persistedMigrations,
1098
876
  snapshots: Array.from(this.snapshots.entries()).map(
@@ -1115,7 +893,10 @@ var MigrationTracker = class _MigrationTracker {
1115
893
  data
1116
894
  };
1117
895
  const serialize = this.persistence.serializer ?? ((value) => JSON.stringify(value));
1118
- await this.persistence.adapter.setItem(this.persistence.key, serialize(envelope));
896
+ await this.persistence.adapter.setItem(
897
+ this.persistence.key,
898
+ serialize(envelope)
899
+ );
1119
900
  }
1120
901
  /**
1121
902
  * Load tracker state and verify integrity chain.
@@ -1128,7 +909,9 @@ var MigrationTracker = class _MigrationTracker {
1128
909
  if (!raw) {
1129
910
  return { migrations: 0, snapshots: 0 };
1130
911
  }
1131
- const deserialize = this.persistence.deserializer ?? ((value) => JSON.parse(value));
912
+ const deserialize = this.persistence.deserializer ?? ((value) => JSON.parse(
913
+ value
914
+ ));
1132
915
  const envelope = deserialize(raw);
1133
916
  if (envelope.version !== 1 || !envelope.data) {
1134
917
  throw new Error("Invalid migration tracker persistence payload");
@@ -1191,7 +974,10 @@ var MigrationTracker = class _MigrationTracker {
1191
974
  migrations: this.migrations.length,
1192
975
  snapshots: this.snapshots.size
1193
976
  });
1194
- return { migrations: this.migrations.length, snapshots: this.snapshots.size };
977
+ return {
978
+ migrations: this.migrations.length,
979
+ snapshots: this.snapshots.size
980
+ };
1195
981
  }
1196
982
  /**
1197
983
  * Remove persisted migration tracker state.
@@ -1313,489 +1099,6 @@ var MigrationTracker = class _MigrationTracker {
1313
1099
  return (hash >>> 0).toString(16).padStart(8, "0");
1314
1100
  }
1315
1101
  };
1316
- var SyncCoordinator = class extends eventemitter3.EventEmitter {
1317
- nodes = /* @__PURE__ */ new Map();
1318
- sessions = /* @__PURE__ */ new Map();
1319
- syncEvents = [];
1320
- nodeHeartbeats = /* @__PURE__ */ new Map();
1321
- heartbeatInterval = null;
1322
- // Crypto support
1323
- cryptoProvider = null;
1324
- nodesByDID = /* @__PURE__ */ new Map();
1325
- // DID -> nodeId
1326
- constructor() {
1327
- super();
1328
- }
1329
- /**
1330
- * Configure cryptographic provider for authenticated sync
1331
- */
1332
- configureCrypto(provider) {
1333
- this.cryptoProvider = provider;
1334
- logger.debug("[SyncCoordinator] Crypto configured", {
1335
- initialized: provider.isInitialized()
1336
- });
1337
- }
1338
- /**
1339
- * Check if crypto is configured
1340
- */
1341
- isCryptoEnabled() {
1342
- return this.cryptoProvider !== null && this.cryptoProvider.isInitialized();
1343
- }
1344
- /**
1345
- * Register a node with DID-based identity
1346
- */
1347
- async registerAuthenticatedNode(nodeInfo) {
1348
- const node = {
1349
- ...nodeInfo
1350
- };
1351
- this.nodes.set(node.id, node);
1352
- this.nodeHeartbeats.set(node.id, Date.now());
1353
- this.nodesByDID.set(nodeInfo.did, node.id);
1354
- if (this.cryptoProvider) {
1355
- await this.cryptoProvider.registerRemoteNode({
1356
- id: node.id,
1357
- did: nodeInfo.did,
1358
- publicSigningKey: nodeInfo.publicSigningKey,
1359
- publicEncryptionKey: nodeInfo.publicEncryptionKey
1360
- });
1361
- }
1362
- const event = {
1363
- type: "node-joined",
1364
- nodeId: node.id,
1365
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1366
- data: { did: nodeInfo.did, authenticated: true }
1367
- };
1368
- this.syncEvents.push(event);
1369
- this.emit("node-joined", node);
1370
- logger.debug("[SyncCoordinator] Authenticated node registered", {
1371
- nodeId: node.id,
1372
- did: nodeInfo.did,
1373
- version: node.version
1374
- });
1375
- return node;
1376
- }
1377
- /**
1378
- * Get node by DID
1379
- */
1380
- getNodeByDID(did) {
1381
- const nodeId = this.nodesByDID.get(did);
1382
- if (!nodeId) return void 0;
1383
- return this.nodes.get(nodeId);
1384
- }
1385
- /**
1386
- * Get all authenticated nodes (nodes with DIDs)
1387
- */
1388
- getAuthenticatedNodes() {
1389
- return Array.from(this.nodes.values()).filter((n) => n.did);
1390
- }
1391
- /**
1392
- * Create an authenticated sync session with UCAN-based authorization
1393
- */
1394
- async createAuthenticatedSyncSession(initiatorDID, participantDIDs, options) {
1395
- const initiatorNodeId = this.nodesByDID.get(initiatorDID);
1396
- if (!initiatorNodeId) {
1397
- throw new Error(`Initiator node with DID ${initiatorDID} not found`);
1398
- }
1399
- const participantIds = [];
1400
- for (const did of participantDIDs) {
1401
- const nodeId = this.nodesByDID.get(did);
1402
- if (nodeId) {
1403
- participantIds.push(nodeId);
1404
- }
1405
- }
1406
- let sessionToken;
1407
- if (this.cryptoProvider && this.cryptoProvider.isInitialized()) {
1408
- const capabilities = (options?.requiredCapabilities || ["aeon:sync:read", "aeon:sync:write"]).map((cap) => ({ can: cap, with: "*" }));
1409
- if (participantDIDs.length > 0) {
1410
- sessionToken = await this.cryptoProvider.createUCAN(
1411
- participantDIDs[0],
1412
- capabilities,
1413
- { expirationSeconds: 3600 }
1414
- // 1 hour
1415
- );
1416
- }
1417
- }
1418
- const session = {
1419
- id: `sync-${Date.now()}-${Math.random().toString(36).slice(2)}`,
1420
- initiatorId: initiatorNodeId,
1421
- participantIds,
1422
- status: "pending",
1423
- startTime: (/* @__PURE__ */ new Date()).toISOString(),
1424
- itemsSynced: 0,
1425
- itemsFailed: 0,
1426
- conflictsDetected: 0,
1427
- initiatorDID,
1428
- participantDIDs,
1429
- encryptionMode: options?.encryptionMode || "none",
1430
- requiredCapabilities: options?.requiredCapabilities,
1431
- sessionToken
1432
- };
1433
- this.sessions.set(session.id, session);
1434
- const event = {
1435
- type: "sync-started",
1436
- sessionId: session.id,
1437
- nodeId: initiatorNodeId,
1438
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1439
- data: {
1440
- authenticated: true,
1441
- initiatorDID,
1442
- participantCount: participantDIDs.length,
1443
- encryptionMode: session.encryptionMode
1444
- }
1445
- };
1446
- this.syncEvents.push(event);
1447
- this.emit("sync-started", session);
1448
- logger.debug("[SyncCoordinator] Authenticated sync session created", {
1449
- sessionId: session.id,
1450
- initiatorDID,
1451
- participants: participantDIDs.length,
1452
- encryptionMode: session.encryptionMode
1453
- });
1454
- return session;
1455
- }
1456
- /**
1457
- * Verify a node's UCAN capabilities for a session
1458
- */
1459
- async verifyNodeCapabilities(sessionId, nodeDID, token) {
1460
- if (!this.cryptoProvider) {
1461
- return { authorized: true };
1462
- }
1463
- const session = this.sessions.get(sessionId);
1464
- if (!session) {
1465
- return { authorized: false, error: `Session ${sessionId} not found` };
1466
- }
1467
- const result = await this.cryptoProvider.verifyUCAN(token, {
1468
- requiredCapabilities: session.requiredCapabilities?.map((cap) => ({
1469
- can: cap,
1470
- with: "*"
1471
- }))
1472
- });
1473
- if (!result.authorized) {
1474
- logger.warn("[SyncCoordinator] Node capability verification failed", {
1475
- sessionId,
1476
- nodeDID,
1477
- error: result.error
1478
- });
1479
- }
1480
- return result;
1481
- }
1482
- /**
1483
- * Register a node in the cluster
1484
- */
1485
- registerNode(node) {
1486
- this.nodes.set(node.id, node);
1487
- this.nodeHeartbeats.set(node.id, Date.now());
1488
- const event = {
1489
- type: "node-joined",
1490
- nodeId: node.id,
1491
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1492
- };
1493
- this.syncEvents.push(event);
1494
- this.emit("node-joined", node);
1495
- logger.debug("[SyncCoordinator] Node registered", {
1496
- nodeId: node.id,
1497
- address: node.address,
1498
- version: node.version
1499
- });
1500
- }
1501
- /**
1502
- * Deregister a node from the cluster
1503
- */
1504
- deregisterNode(nodeId) {
1505
- const node = this.nodes.get(nodeId);
1506
- if (!node) {
1507
- throw new Error(`Node ${nodeId} not found`);
1508
- }
1509
- this.nodes.delete(nodeId);
1510
- this.nodeHeartbeats.delete(nodeId);
1511
- const event = {
1512
- type: "node-left",
1513
- nodeId,
1514
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1515
- };
1516
- this.syncEvents.push(event);
1517
- this.emit("node-left", node);
1518
- logger.debug("[SyncCoordinator] Node deregistered", { nodeId });
1519
- }
1520
- /**
1521
- * Create a new sync session
1522
- */
1523
- createSyncSession(initiatorId, participantIds) {
1524
- const node = this.nodes.get(initiatorId);
1525
- if (!node) {
1526
- throw new Error(`Initiator node ${initiatorId} not found`);
1527
- }
1528
- const session = {
1529
- id: `sync-${Date.now()}-${Math.random().toString(36).slice(2)}`,
1530
- initiatorId,
1531
- participantIds,
1532
- status: "pending",
1533
- startTime: (/* @__PURE__ */ new Date()).toISOString(),
1534
- itemsSynced: 0,
1535
- itemsFailed: 0,
1536
- conflictsDetected: 0
1537
- };
1538
- this.sessions.set(session.id, session);
1539
- const event = {
1540
- type: "sync-started",
1541
- sessionId: session.id,
1542
- nodeId: initiatorId,
1543
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1544
- };
1545
- this.syncEvents.push(event);
1546
- this.emit("sync-started", session);
1547
- logger.debug("[SyncCoordinator] Sync session created", {
1548
- sessionId: session.id,
1549
- initiator: initiatorId,
1550
- participants: participantIds.length
1551
- });
1552
- return session;
1553
- }
1554
- /**
1555
- * Update sync session
1556
- */
1557
- updateSyncSession(sessionId, updates) {
1558
- const session = this.sessions.get(sessionId);
1559
- if (!session) {
1560
- throw new Error(`Session ${sessionId} not found`);
1561
- }
1562
- Object.assign(session, updates);
1563
- if (updates.status === "completed" || updates.status === "failed") {
1564
- session.endTime = (/* @__PURE__ */ new Date()).toISOString();
1565
- const event = {
1566
- type: "sync-completed",
1567
- sessionId,
1568
- nodeId: session.initiatorId,
1569
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1570
- data: { status: updates.status, itemsSynced: session.itemsSynced }
1571
- };
1572
- this.syncEvents.push(event);
1573
- this.emit("sync-completed", session);
1574
- }
1575
- logger.debug("[SyncCoordinator] Sync session updated", {
1576
- sessionId,
1577
- status: session.status,
1578
- itemsSynced: session.itemsSynced
1579
- });
1580
- }
1581
- /**
1582
- * Record a conflict during sync
1583
- */
1584
- recordConflict(sessionId, nodeId, conflictData) {
1585
- const session = this.sessions.get(sessionId);
1586
- if (session) {
1587
- session.conflictsDetected++;
1588
- const event = {
1589
- type: "conflict-detected",
1590
- sessionId,
1591
- nodeId,
1592
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1593
- data: conflictData
1594
- };
1595
- this.syncEvents.push(event);
1596
- this.emit("conflict-detected", { session, nodeId, conflictData });
1597
- logger.debug("[SyncCoordinator] Conflict recorded", {
1598
- sessionId,
1599
- nodeId,
1600
- totalConflicts: session.conflictsDetected
1601
- });
1602
- }
1603
- }
1604
- /**
1605
- * Update node status
1606
- */
1607
- updateNodeStatus(nodeId, status) {
1608
- const node = this.nodes.get(nodeId);
1609
- if (!node) {
1610
- throw new Error(`Node ${nodeId} not found`);
1611
- }
1612
- node.status = status;
1613
- this.nodeHeartbeats.set(nodeId, Date.now());
1614
- logger.debug("[SyncCoordinator] Node status updated", {
1615
- nodeId,
1616
- status
1617
- });
1618
- }
1619
- /**
1620
- * Record heartbeat from node
1621
- */
1622
- recordHeartbeat(nodeId) {
1623
- const node = this.nodes.get(nodeId);
1624
- if (!node) {
1625
- return;
1626
- }
1627
- node.lastHeartbeat = (/* @__PURE__ */ new Date()).toISOString();
1628
- this.nodeHeartbeats.set(nodeId, Date.now());
1629
- }
1630
- /**
1631
- * Get all nodes
1632
- */
1633
- getNodes() {
1634
- return Array.from(this.nodes.values());
1635
- }
1636
- /**
1637
- * Get node by ID
1638
- */
1639
- getNode(nodeId) {
1640
- return this.nodes.get(nodeId);
1641
- }
1642
- /**
1643
- * Get online nodes
1644
- */
1645
- getOnlineNodes() {
1646
- return Array.from(this.nodes.values()).filter((n) => n.status === "online");
1647
- }
1648
- /**
1649
- * Get nodes by capability
1650
- */
1651
- getNodesByCapability(capability) {
1652
- return Array.from(this.nodes.values()).filter(
1653
- (n) => n.capabilities.includes(capability)
1654
- );
1655
- }
1656
- /**
1657
- * Get sync session
1658
- */
1659
- getSyncSession(sessionId) {
1660
- return this.sessions.get(sessionId);
1661
- }
1662
- /**
1663
- * Get all sync sessions
1664
- */
1665
- getAllSyncSessions() {
1666
- return Array.from(this.sessions.values());
1667
- }
1668
- /**
1669
- * Get active sync sessions
1670
- */
1671
- getActiveSyncSessions() {
1672
- return Array.from(this.sessions.values()).filter(
1673
- (s) => s.status === "active"
1674
- );
1675
- }
1676
- /**
1677
- * Get sessions for a node
1678
- */
1679
- getSessionsForNode(nodeId) {
1680
- return Array.from(this.sessions.values()).filter(
1681
- (s) => s.initiatorId === nodeId || s.participantIds.includes(nodeId)
1682
- );
1683
- }
1684
- /**
1685
- * Get sync statistics
1686
- */
1687
- getStatistics() {
1688
- const sessions = Array.from(this.sessions.values());
1689
- const completed = sessions.filter((s) => s.status === "completed").length;
1690
- const failed = sessions.filter((s) => s.status === "failed").length;
1691
- const active = sessions.filter((s) => s.status === "active").length;
1692
- const totalItemsSynced = sessions.reduce(
1693
- (sum, s) => sum + s.itemsSynced,
1694
- 0
1695
- );
1696
- const totalConflicts = sessions.reduce(
1697
- (sum, s) => sum + s.conflictsDetected,
1698
- 0
1699
- );
1700
- return {
1701
- totalNodes: this.nodes.size,
1702
- onlineNodes: this.getOnlineNodes().length,
1703
- offlineNodes: this.nodes.size - this.getOnlineNodes().length,
1704
- totalSessions: sessions.length,
1705
- activeSessions: active,
1706
- completedSessions: completed,
1707
- failedSessions: failed,
1708
- successRate: sessions.length > 0 ? completed / sessions.length * 100 : 0,
1709
- totalItemsSynced,
1710
- totalConflicts,
1711
- averageConflictsPerSession: sessions.length > 0 ? totalConflicts / sessions.length : 0
1712
- };
1713
- }
1714
- /**
1715
- * Get sync events
1716
- */
1717
- getSyncEvents(limit) {
1718
- const events = [...this.syncEvents];
1719
- if (limit) {
1720
- return events.slice(-limit);
1721
- }
1722
- return events;
1723
- }
1724
- /**
1725
- * Get sync events for session
1726
- */
1727
- getSessionEvents(sessionId) {
1728
- return this.syncEvents.filter((e) => e.sessionId === sessionId);
1729
- }
1730
- /**
1731
- * Check node health
1732
- */
1733
- getNodeHealth() {
1734
- const health = {};
1735
- for (const [nodeId, lastHeartbeat] of this.nodeHeartbeats) {
1736
- const now = Date.now();
1737
- const downtime = now - lastHeartbeat;
1738
- const isHealthy = downtime < 3e4;
1739
- health[nodeId] = {
1740
- isHealthy,
1741
- downtime
1742
- };
1743
- }
1744
- return health;
1745
- }
1746
- /**
1747
- * Start heartbeat monitoring
1748
- */
1749
- startHeartbeatMonitoring(interval = 5e3) {
1750
- if (this.heartbeatInterval) {
1751
- return;
1752
- }
1753
- this.heartbeatInterval = setInterval(() => {
1754
- const health = this.getNodeHealth();
1755
- for (const [nodeId, { isHealthy }] of Object.entries(health)) {
1756
- const node = this.nodes.get(nodeId);
1757
- if (!node) {
1758
- continue;
1759
- }
1760
- const newStatus = isHealthy ? "online" : "offline";
1761
- if (node.status !== newStatus) {
1762
- this.updateNodeStatus(nodeId, newStatus);
1763
- }
1764
- }
1765
- }, interval);
1766
- logger.debug("[SyncCoordinator] Heartbeat monitoring started", {
1767
- interval
1768
- });
1769
- }
1770
- /**
1771
- * Stop heartbeat monitoring
1772
- */
1773
- stopHeartbeatMonitoring() {
1774
- if (this.heartbeatInterval) {
1775
- clearInterval(this.heartbeatInterval);
1776
- this.heartbeatInterval = null;
1777
- logger.debug("[SyncCoordinator] Heartbeat monitoring stopped");
1778
- }
1779
- }
1780
- /**
1781
- * Clear all state (for testing)
1782
- */
1783
- clear() {
1784
- this.nodes.clear();
1785
- this.sessions.clear();
1786
- this.syncEvents = [];
1787
- this.nodeHeartbeats.clear();
1788
- this.nodesByDID.clear();
1789
- this.cryptoProvider = null;
1790
- this.stopHeartbeatMonitoring();
1791
- }
1792
- /**
1793
- * Get the crypto provider (for advanced usage)
1794
- */
1795
- getCryptoProvider() {
1796
- return this.cryptoProvider;
1797
- }
1798
- };
1799
1102
 
1800
1103
  // src/distributed/ReplicationManager.ts
1801
1104
  var ReplicationManager = class _ReplicationManager {
@@ -2277,7 +1580,10 @@ var ReplicationManager = class _ReplicationManager {
2277
1580
  data
2278
1581
  };
2279
1582
  const serialize = this.persistence.serializer ?? ((value) => JSON.stringify(value));
2280
- await this.persistence.adapter.setItem(this.persistence.key, serialize(envelope));
1583
+ await this.persistence.adapter.setItem(
1584
+ this.persistence.key,
1585
+ serialize(envelope)
1586
+ );
2281
1587
  }
2282
1588
  /**
2283
1589
  * Load replication snapshot from persistence.
@@ -2990,7 +2296,10 @@ var SyncProtocol = class _SyncProtocol {
2990
2296
  data
2991
2297
  };
2992
2298
  const serialize = this.persistence.serializer ?? ((value) => JSON.stringify(value));
2993
- await this.persistence.adapter.setItem(this.persistence.key, serialize(envelope));
2299
+ await this.persistence.adapter.setItem(
2300
+ this.persistence.key,
2301
+ serialize(envelope)
2302
+ );
2994
2303
  }
2995
2304
  /**
2996
2305
  * Load protocol state from persistence.
@@ -5234,15 +4543,7 @@ var AdaptiveCompressionOptimizer = class {
5234
4543
  };
5235
4544
  }
5236
4545
  };
5237
- var adaptiveOptimizerInstance = null;
5238
- function getAdaptiveCompressionOptimizer() {
5239
- if (!adaptiveOptimizerInstance) {
5240
- adaptiveOptimizerInstance = new AdaptiveCompressionOptimizer();
5241
- }
5242
- return adaptiveOptimizerInstance;
5243
- }
5244
4546
  function resetAdaptiveCompressionOptimizer() {
5245
- adaptiveOptimizerInstance = null;
5246
4547
  }
5247
4548
  var logger8 = getLogger();
5248
4549
  var AgentPresenceManager = class extends eventemitter3.EventEmitter {
@@ -5687,12 +4988,6 @@ var AgentPresenceManager = class extends eventemitter3.EventEmitter {
5687
4988
  }
5688
4989
  };
5689
4990
  var instances = /* @__PURE__ */ new Map();
5690
- function getAgentPresenceManager(sessionId) {
5691
- if (!instances.has(sessionId)) {
5692
- instances.set(sessionId, new AgentPresenceManager(sessionId));
5693
- }
5694
- return instances.get(sessionId);
5695
- }
5696
4991
  function clearAgentPresenceManager(sessionId) {
5697
4992
  const instance = instances.get(sessionId);
5698
4993
  if (instance) {
@@ -5794,6 +5089,34 @@ var NullCryptoProvider = class {
5794
5089
  }
5795
5090
  };
5796
5091
 
5092
+ // src/index.ts
5093
+ var Link = (() => {
5094
+ throw new Error(
5095
+ "Link: Stub called from @affectively/aeon. Import from @affectively/aeon-flux-react or mock in tests."
5096
+ );
5097
+ });
5098
+ var useAeonPage = (() => {
5099
+ throw new Error(
5100
+ "useAeonPage: Stub called from @affectively/aeon. Import from @affectively/aeon-flux-react or mock in tests."
5101
+ );
5102
+ });
5103
+ var getAdaptiveCompressionOptimizer = (() => {
5104
+ throw new Error("getAdaptiveCompressionOptimizer: Stub");
5105
+ });
5106
+ var SchemaVersionManager2 = class {
5107
+ constructor() {
5108
+ throw new Error("SchemaVersionManager: Stub");
5109
+ }
5110
+ };
5111
+ var getAgentPresenceManager = (() => {
5112
+ throw new Error("getAgentPresenceManager: Stub");
5113
+ });
5114
+ var SyncCoordinator2 = class {
5115
+ constructor() {
5116
+ throw new Error("SyncCoordinator: Stub");
5117
+ }
5118
+ };
5119
+
5797
5120
  exports.AEON_CAPABILITIES = AEON_CAPABILITIES;
5798
5121
  exports.AdaptiveCompressionOptimizer = AdaptiveCompressionOptimizer;
5799
5122
  exports.AgentPresenceManager = AgentPresenceManager;
@@ -5804,15 +5127,16 @@ exports.DashStorageAdapter = DashStorageAdapter;
5804
5127
  exports.DataTransformer = DataTransformer;
5805
5128
  exports.DeltaSyncOptimizer = DeltaSyncOptimizer;
5806
5129
  exports.InMemoryStorageAdapter = InMemoryStorageAdapter;
5130
+ exports.Link = Link;
5807
5131
  exports.MigrationEngine = MigrationEngine;
5808
5132
  exports.MigrationTracker = MigrationTracker;
5809
5133
  exports.NullCryptoProvider = NullCryptoProvider;
5810
5134
  exports.OfflineOperationQueue = OfflineOperationQueue;
5811
5135
  exports.PrefetchingEngine = PrefetchingEngine;
5812
5136
  exports.ReplicationManager = ReplicationManager;
5813
- exports.SchemaVersionManager = SchemaVersionManager;
5137
+ exports.SchemaVersionManager = SchemaVersionManager2;
5814
5138
  exports.StateReconciler = StateReconciler;
5815
- exports.SyncCoordinator = SyncCoordinator;
5139
+ exports.SyncCoordinator = SyncCoordinator2;
5816
5140
  exports.SyncProtocol = SyncProtocol;
5817
5141
  exports.clearAgentPresenceManager = clearAgentPresenceManager;
5818
5142
  exports.createNamespacedLogger = createNamespacedLogger;
@@ -5834,5 +5158,6 @@ exports.resetLogger = resetLogger;
5834
5158
  exports.resetOfflineOperationQueue = resetOfflineOperationQueue;
5835
5159
  exports.resetPrefetchingEngine = resetPrefetchingEngine;
5836
5160
  exports.setLogger = setLogger;
5161
+ exports.useAeonPage = useAeonPage;
5837
5162
  //# sourceMappingURL=index.cjs.map
5838
5163
  //# sourceMappingURL=index.cjs.map