@affectively/aeon 1.0.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/LICENSE +21 -0
- package/README.md +332 -0
- package/dist/core/index.cjs +4 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +146 -0
- package/dist/core/index.d.ts +146 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/distributed/index.cjs +1874 -0
- package/dist/distributed/index.cjs.map +1 -0
- package/dist/distributed/index.d.cts +2 -0
- package/dist/distributed/index.d.ts +2 -0
- package/dist/distributed/index.js +1869 -0
- package/dist/distributed/index.js.map +1 -0
- package/dist/index-C_4CMV5c.d.cts +1207 -0
- package/dist/index-C_4CMV5c.d.ts +1207 -0
- package/dist/index.cjs +4671 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +812 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.js +4632 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.cjs +64 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +38 -0
- package/dist/utils/index.d.ts +38 -0
- package/dist/utils/index.js +57 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/versioning/index.cjs +871 -0
- package/dist/versioning/index.cjs.map +1 -0
- package/dist/versioning/index.d.cts +472 -0
- package/dist/versioning/index.d.ts +472 -0
- package/dist/versioning/index.js +866 -0
- package/dist/versioning/index.js.map +1 -0
- package/package.json +142 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Affectively AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# Aeon
|
|
2
|
+
|
|
3
|
+
> Distributed synchronization, schema versioning, and conflict resolution for real-time collaborative applications.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@affectively/aeon)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
## Philosophy
|
|
10
|
+
|
|
11
|
+
In Gnosticism, **Aeons** are not just time periods; they are divine beings or powers that emanate from the "One" (the Pleroma). They function as links or "levels" between the pure divine source and the material world, often existing in pairs (syzygies) to maintain balance.
|
|
12
|
+
|
|
13
|
+
In the Affectively framework, if "halos" are the users, then **Aeons are the collaborative structures** - the channels that allow users to communicate with the higher-level logic of the platform. They bridge the gap between individual user state and the distributed system, maintaining harmony across the network.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
**Aeon** is a comprehensive TypeScript library for building distributed, collaborative applications. It provides the primitives needed for:
|
|
18
|
+
|
|
19
|
+
- **Distributed Synchronization** - Coordinate sync sessions across multiple nodes
|
|
20
|
+
- **Schema Versioning** - Manage schema evolution with migrations and rollbacks
|
|
21
|
+
- **Data Replication** - Configure consistency levels and replication policies
|
|
22
|
+
- **Conflict Resolution** - Multiple strategies for resolving divergent state
|
|
23
|
+
- **Real-time Presence** - Track node health and status in real-time
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @affectively/aeon
|
|
29
|
+
# or
|
|
30
|
+
yarn add @affectively/aeon
|
|
31
|
+
# or
|
|
32
|
+
pnpm add @affectively/aeon
|
|
33
|
+
# or
|
|
34
|
+
bun add @affectively/aeon
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Distributed Synchronization
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { SyncCoordinator } from '@affectively/aeon';
|
|
43
|
+
|
|
44
|
+
// Create a sync coordinator
|
|
45
|
+
const coordinator = new SyncCoordinator();
|
|
46
|
+
|
|
47
|
+
// Register nodes
|
|
48
|
+
coordinator.registerNode({
|
|
49
|
+
id: 'node-1',
|
|
50
|
+
address: 'localhost',
|
|
51
|
+
port: 3000,
|
|
52
|
+
status: 'online',
|
|
53
|
+
lastHeartbeat: new Date().toISOString(),
|
|
54
|
+
version: '1.0.0',
|
|
55
|
+
capabilities: ['sync', 'replicate'],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Create a sync session
|
|
59
|
+
const session = coordinator.createSyncSession('node-1', ['node-2', 'node-3']);
|
|
60
|
+
|
|
61
|
+
// Listen for sync events
|
|
62
|
+
coordinator.on('sync-completed', (session) => {
|
|
63
|
+
console.log(`Session ${session.id} completed:`, session.itemsSynced, 'items synced');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Start heartbeat monitoring
|
|
67
|
+
coordinator.startHeartbeatMonitoring(5000);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Schema Versioning & Migrations
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { SchemaVersionManager, MigrationEngine, MigrationTracker } from '@affectively/aeon';
|
|
74
|
+
|
|
75
|
+
// Initialize version manager
|
|
76
|
+
const versionManager = new SchemaVersionManager();
|
|
77
|
+
|
|
78
|
+
// Register schema versions
|
|
79
|
+
versionManager.registerVersion({
|
|
80
|
+
major: 1,
|
|
81
|
+
minor: 0,
|
|
82
|
+
patch: 0,
|
|
83
|
+
timestamp: new Date().toISOString(),
|
|
84
|
+
description: 'Initial schema',
|
|
85
|
+
breaking: false,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
versionManager.registerVersion({
|
|
89
|
+
major: 2,
|
|
90
|
+
minor: 0,
|
|
91
|
+
patch: 0,
|
|
92
|
+
timestamp: new Date().toISOString(),
|
|
93
|
+
description: 'Added user status field',
|
|
94
|
+
breaking: true,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Create migration engine
|
|
98
|
+
const migrationEngine = new MigrationEngine();
|
|
99
|
+
|
|
100
|
+
// Register a migration
|
|
101
|
+
migrationEngine.registerMigration({
|
|
102
|
+
id: 'add-status-field',
|
|
103
|
+
version: '2.0.0',
|
|
104
|
+
name: 'Add user status field',
|
|
105
|
+
up: (data) => ({ ...data, status: 'active' }),
|
|
106
|
+
down: (data) => {
|
|
107
|
+
const { status, ...rest } = data;
|
|
108
|
+
return rest;
|
|
109
|
+
},
|
|
110
|
+
timestamp: new Date().toISOString(),
|
|
111
|
+
description: 'Adds status field to all user records',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Execute migration
|
|
115
|
+
const result = await migrationEngine.executeMigration('add-status-field', userData);
|
|
116
|
+
console.log(`Migration completed: ${result.itemsAffected} items affected`);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Data Replication
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { ReplicationManager } from '@affectively/aeon';
|
|
123
|
+
|
|
124
|
+
const replicationManager = new ReplicationManager();
|
|
125
|
+
|
|
126
|
+
// Create a replication policy
|
|
127
|
+
const policy = replicationManager.createPolicy(
|
|
128
|
+
'user-data-policy',
|
|
129
|
+
3, // replication factor
|
|
130
|
+
'read-after-write', // consistency level
|
|
131
|
+
1000, // sync interval (ms)
|
|
132
|
+
10000 // max replication lag (ms)
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Register replicas
|
|
136
|
+
replicationManager.registerReplica({
|
|
137
|
+
id: 'replica-1',
|
|
138
|
+
nodeId: 'node-1',
|
|
139
|
+
status: 'primary',
|
|
140
|
+
lastSyncTime: new Date().toISOString(),
|
|
141
|
+
lagBytes: 0,
|
|
142
|
+
lagMillis: 0,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Check replication health
|
|
146
|
+
const health = replicationManager.checkReplicationHealth(policy.id);
|
|
147
|
+
console.log('Replication healthy:', health.healthy);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Conflict Resolution
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { StateReconciler } from '@affectively/aeon';
|
|
154
|
+
|
|
155
|
+
const reconciler = new StateReconciler();
|
|
156
|
+
|
|
157
|
+
// Record state versions from different nodes
|
|
158
|
+
reconciler.recordStateVersion('user:123', '1.0', '2024-01-01T00:00:00Z', 'node-1', 'hash-a', { name: 'Alice' });
|
|
159
|
+
reconciler.recordStateVersion('user:123', '1.0', '2024-01-01T00:00:01Z', 'node-2', 'hash-b', { name: 'Bob' });
|
|
160
|
+
|
|
161
|
+
// Detect conflicts
|
|
162
|
+
if (reconciler.detectConflicts('user:123')) {
|
|
163
|
+
// Reconcile using last-write-wins strategy
|
|
164
|
+
const versions = reconciler.getStateVersions('user:123');
|
|
165
|
+
const result = reconciler.reconcileLastWriteWins(versions);
|
|
166
|
+
|
|
167
|
+
console.log('Resolved state:', result.mergedState);
|
|
168
|
+
console.log('Conflicts resolved:', result.conflictsResolved);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Modules
|
|
173
|
+
|
|
174
|
+
### Core (`@affectively/aeon/core`)
|
|
175
|
+
|
|
176
|
+
Shared types and utilities used across all modules.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import type { Operation, VectorClock, PresenceInfo } from '@affectively/aeon/core';
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Offline (`@affectively/aeon/offline`)
|
|
183
|
+
|
|
184
|
+
Offline-first operation management.
|
|
185
|
+
|
|
186
|
+
- `OfflineOperationQueue` - Priority-based offline operation queue with retry logic
|
|
187
|
+
|
|
188
|
+
### Compression (`@affectively/aeon/compression`)
|
|
189
|
+
|
|
190
|
+
Data compression and delta sync optimization.
|
|
191
|
+
|
|
192
|
+
- `CompressionEngine` - Native compression using CompressionStream API
|
|
193
|
+
- `DeltaSyncOptimizer` - Field-level change detection (70-90% payload reduction)
|
|
194
|
+
|
|
195
|
+
### Optimization (`@affectively/aeon/optimization`)
|
|
196
|
+
|
|
197
|
+
Network and performance optimization.
|
|
198
|
+
|
|
199
|
+
- `PrefetchingEngine` - Predictive pre-compression based on operation patterns
|
|
200
|
+
- `BatchTimingOptimizer` - Intelligent batch scheduling based on network conditions
|
|
201
|
+
- `AdaptiveCompressionOptimizer` - Auto-adjusting compression level (1-9)
|
|
202
|
+
|
|
203
|
+
### Presence (`@affectively/aeon/presence`)
|
|
204
|
+
|
|
205
|
+
Real-time agent presence tracking.
|
|
206
|
+
|
|
207
|
+
- `AgentPresenceManager` - Track agent status, cursors, and activity
|
|
208
|
+
|
|
209
|
+
### Versioning (`@affectively/aeon/versioning`)
|
|
210
|
+
|
|
211
|
+
Schema versioning and migration system.
|
|
212
|
+
|
|
213
|
+
- `SchemaVersionManager` - Version tracking and compatibility
|
|
214
|
+
- `MigrationEngine` - Migration execution and rollback
|
|
215
|
+
- `DataTransformer` - Data transformation during migrations
|
|
216
|
+
- `MigrationTracker` - Migration history and audit trails
|
|
217
|
+
|
|
218
|
+
### Distributed (`@affectively/aeon/distributed`)
|
|
219
|
+
|
|
220
|
+
Distributed synchronization primitives.
|
|
221
|
+
|
|
222
|
+
- `SyncCoordinator` - Sync session management
|
|
223
|
+
- `ReplicationManager` - Replica management and policies
|
|
224
|
+
- `SyncProtocol` - Protocol messages and handshaking
|
|
225
|
+
- `StateReconciler` - Conflict detection and resolution
|
|
226
|
+
|
|
227
|
+
### Utils (`@affectively/aeon/utils`)
|
|
228
|
+
|
|
229
|
+
Shared utilities including pluggable logging.
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { setLogger, disableLogging } from '@affectively/aeon/utils';
|
|
233
|
+
|
|
234
|
+
// Use custom logger
|
|
235
|
+
setLogger({
|
|
236
|
+
debug: (...args) => myLogger.debug(...args),
|
|
237
|
+
info: (...args) => myLogger.info(...args),
|
|
238
|
+
warn: (...args) => myLogger.warn(...args),
|
|
239
|
+
error: (...args) => myLogger.error(...args),
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Or disable logging entirely
|
|
243
|
+
disableLogging();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## API Reference
|
|
247
|
+
|
|
248
|
+
### SyncCoordinator
|
|
249
|
+
|
|
250
|
+
| Method | Description |
|
|
251
|
+
|--------|-------------|
|
|
252
|
+
| `registerNode(node)` | Register a node in the cluster |
|
|
253
|
+
| `deregisterNode(nodeId)` | Remove a node from the cluster |
|
|
254
|
+
| `createSyncSession(initiatorId, participantIds)` | Create a new sync session |
|
|
255
|
+
| `updateSyncSession(sessionId, updates)` | Update sync session status |
|
|
256
|
+
| `recordConflict(sessionId, nodeId, data)` | Record a conflict |
|
|
257
|
+
| `getStatistics()` | Get sync statistics |
|
|
258
|
+
| `startHeartbeatMonitoring(interval)` | Start health monitoring |
|
|
259
|
+
|
|
260
|
+
### SchemaVersionManager
|
|
261
|
+
|
|
262
|
+
| Method | Description |
|
|
263
|
+
|--------|-------------|
|
|
264
|
+
| `registerVersion(version)` | Register a schema version |
|
|
265
|
+
| `getCurrentVersion()` | Get current active version |
|
|
266
|
+
| `setCurrentVersion(version)` | Set the current version |
|
|
267
|
+
| `canMigrate(from, to)` | Check if migration path exists |
|
|
268
|
+
| `getMigrationPath(from, to)` | Get migration steps |
|
|
269
|
+
| `compareVersions(v1, v2)` | Compare two versions |
|
|
270
|
+
|
|
271
|
+
### MigrationEngine
|
|
272
|
+
|
|
273
|
+
| Method | Description |
|
|
274
|
+
|--------|-------------|
|
|
275
|
+
| `registerMigration(migration)` | Register a migration |
|
|
276
|
+
| `executeMigration(id, data)` | Execute a migration |
|
|
277
|
+
| `rollbackMigration(id, data)` | Rollback a migration |
|
|
278
|
+
| `getState()` | Get current migration state |
|
|
279
|
+
| `getPendingMigrations()` | Get pending migrations |
|
|
280
|
+
| `getStatistics()` | Get migration statistics |
|
|
281
|
+
|
|
282
|
+
### ReplicationManager
|
|
283
|
+
|
|
284
|
+
| Method | Description |
|
|
285
|
+
|--------|-------------|
|
|
286
|
+
| `registerReplica(replica)` | Register a replica |
|
|
287
|
+
| `removeReplica(replicaId)` | Remove a replica |
|
|
288
|
+
| `createPolicy(...)` | Create replication policy |
|
|
289
|
+
| `updateReplicaStatus(...)` | Update replica status |
|
|
290
|
+
| `checkReplicationHealth(policyId)` | Check replication health |
|
|
291
|
+
| `getStatistics()` | Get replication statistics |
|
|
292
|
+
|
|
293
|
+
### StateReconciler
|
|
294
|
+
|
|
295
|
+
| Method | Description |
|
|
296
|
+
|--------|-------------|
|
|
297
|
+
| `recordStateVersion(...)` | Record a state version |
|
|
298
|
+
| `detectConflicts(key)` | Detect state conflicts |
|
|
299
|
+
| `compareStates(s1, s2)` | Generate state diff |
|
|
300
|
+
| `reconcileLastWriteWins(versions)` | LWW reconciliation |
|
|
301
|
+
| `reconcileVectorClock(versions)` | Vector clock reconciliation |
|
|
302
|
+
| `reconcileMajorityVote(versions)` | Majority vote reconciliation |
|
|
303
|
+
|
|
304
|
+
## Comparison with Similar Libraries
|
|
305
|
+
|
|
306
|
+
| Feature | Aeon | Yjs | Automerge |
|
|
307
|
+
|---------|------|-----|-----------|
|
|
308
|
+
| Schema Versioning | ✅ | ❌ | ❌ |
|
|
309
|
+
| Migrations | ✅ | ❌ | ❌ |
|
|
310
|
+
| Replication Policies | ✅ | ❌ | ❌ |
|
|
311
|
+
| Multiple Merge Strategies | ✅ | ⚠️ | ⚠️ |
|
|
312
|
+
| TypeScript-first | ✅ | ⚠️ | ⚠️ |
|
|
313
|
+
| Zero Dependencies* | ✅ | ❌ | ❌ |
|
|
314
|
+
|
|
315
|
+
*Only `eventemitter3` for event handling
|
|
316
|
+
|
|
317
|
+
## Requirements
|
|
318
|
+
|
|
319
|
+
- Node.js >= 18.0.0
|
|
320
|
+
- TypeScript >= 5.0.0 (for types)
|
|
321
|
+
|
|
322
|
+
## Contributing
|
|
323
|
+
|
|
324
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
MIT - see [LICENSE](LICENSE) for details.
|
|
329
|
+
|
|
330
|
+
## Credits
|
|
331
|
+
|
|
332
|
+
Built with care by [Affectively AI](https://github.com/affectively-ai).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aeon Core Types
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions for the Aeon synchronization and versioning system.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Operation type - what action is being performed
|
|
8
|
+
*/
|
|
9
|
+
type OperationType = 'create' | 'update' | 'delete' | 'sync' | 'batch';
|
|
10
|
+
/**
|
|
11
|
+
* Operation priority for sync ordering
|
|
12
|
+
*/
|
|
13
|
+
type OperationPriority = 'high' | 'normal' | 'low';
|
|
14
|
+
/**
|
|
15
|
+
* Operation sync status
|
|
16
|
+
*/
|
|
17
|
+
type OperationStatus = 'pending' | 'syncing' | 'synced' | 'failed';
|
|
18
|
+
/**
|
|
19
|
+
* Queued operation for offline-first synchronization
|
|
20
|
+
*/
|
|
21
|
+
interface Operation {
|
|
22
|
+
id: string;
|
|
23
|
+
type: OperationType;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
status: OperationStatus;
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
priority?: OperationPriority;
|
|
28
|
+
createdAt?: number;
|
|
29
|
+
syncedAt?: number;
|
|
30
|
+
retryCount?: number;
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Conflict detection result
|
|
35
|
+
*/
|
|
36
|
+
interface ConflictDetectionResult {
|
|
37
|
+
hasConflict: boolean;
|
|
38
|
+
type?: 'update_update' | 'delete_update' | 'update_delete' | 'concurrent';
|
|
39
|
+
severity?: 'low' | 'medium' | 'high';
|
|
40
|
+
similarity?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Conflict resolution strategy
|
|
44
|
+
*/
|
|
45
|
+
type ResolutionStrategy = 'local_wins' | 'remote_wins' | 'last_modified' | 'merge' | 'manual';
|
|
46
|
+
/**
|
|
47
|
+
* Sync batch for uploading multiple operations
|
|
48
|
+
*/
|
|
49
|
+
interface SyncBatch {
|
|
50
|
+
batchId: string;
|
|
51
|
+
operations: Operation[];
|
|
52
|
+
totalSize: number;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
priority: OperationPriority;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sync result from server
|
|
58
|
+
*/
|
|
59
|
+
interface SyncResult {
|
|
60
|
+
success: boolean;
|
|
61
|
+
synced: string[];
|
|
62
|
+
failed: Array<{
|
|
63
|
+
operationId: string;
|
|
64
|
+
error: string;
|
|
65
|
+
}>;
|
|
66
|
+
conflicts: Array<{
|
|
67
|
+
operationId: string;
|
|
68
|
+
remoteVersion: Record<string, unknown>;
|
|
69
|
+
strategy: ResolutionStrategy;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Network state for adaptive sync
|
|
74
|
+
*/
|
|
75
|
+
type NetworkState = 'online' | 'offline' | 'poor' | 'unknown';
|
|
76
|
+
/**
|
|
77
|
+
* Bandwidth profile for sync adaptation
|
|
78
|
+
*/
|
|
79
|
+
interface BandwidthProfile {
|
|
80
|
+
bandwidth: number;
|
|
81
|
+
latency: number;
|
|
82
|
+
timestamp: number;
|
|
83
|
+
reliability: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Sync coordinator configuration
|
|
87
|
+
*/
|
|
88
|
+
interface SyncCoordinatorConfig {
|
|
89
|
+
maxBatchSize: number;
|
|
90
|
+
maxBatchBytes: number;
|
|
91
|
+
maxRetries: number;
|
|
92
|
+
retryDelayMs: number;
|
|
93
|
+
enableCompression: boolean;
|
|
94
|
+
enableDeltaSync: boolean;
|
|
95
|
+
adaptateBatchSize: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Vector clock for causality tracking
|
|
99
|
+
*/
|
|
100
|
+
interface VectorClock {
|
|
101
|
+
[nodeId: string]: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* CRDT operation for conflict-free updates
|
|
105
|
+
*/
|
|
106
|
+
interface CRDTOperation {
|
|
107
|
+
id: string;
|
|
108
|
+
type: 'insert' | 'delete' | 'update';
|
|
109
|
+
path: string[];
|
|
110
|
+
value?: unknown;
|
|
111
|
+
timestamp: number;
|
|
112
|
+
nodeId: string;
|
|
113
|
+
vectorClock: VectorClock;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Presence information for real-time collaboration
|
|
117
|
+
*/
|
|
118
|
+
interface PresenceInfo {
|
|
119
|
+
userId: string;
|
|
120
|
+
nodeId: string;
|
|
121
|
+
cursor?: {
|
|
122
|
+
x: number;
|
|
123
|
+
y: number;
|
|
124
|
+
};
|
|
125
|
+
selection?: {
|
|
126
|
+
start: number;
|
|
127
|
+
end: number;
|
|
128
|
+
};
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
lastActivity: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Event emitter types
|
|
134
|
+
*/
|
|
135
|
+
type EventCallback<T = unknown> = (data: T) => void;
|
|
136
|
+
type EventUnsubscribe = () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Generic event emitter interface
|
|
139
|
+
*/
|
|
140
|
+
interface IEventEmitter {
|
|
141
|
+
on<T = unknown>(event: string, callback: EventCallback<T>): EventUnsubscribe;
|
|
142
|
+
off(event: string, callback: EventCallback): void;
|
|
143
|
+
emit<T = unknown>(event: string, data?: T): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type { BandwidthProfile, CRDTOperation, ConflictDetectionResult, EventCallback, EventUnsubscribe, IEventEmitter, NetworkState, Operation, OperationPriority, OperationStatus, OperationType, PresenceInfo, ResolutionStrategy, SyncBatch, SyncCoordinatorConfig, SyncResult, VectorClock };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aeon Core Types
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions for the Aeon synchronization and versioning system.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Operation type - what action is being performed
|
|
8
|
+
*/
|
|
9
|
+
type OperationType = 'create' | 'update' | 'delete' | 'sync' | 'batch';
|
|
10
|
+
/**
|
|
11
|
+
* Operation priority for sync ordering
|
|
12
|
+
*/
|
|
13
|
+
type OperationPriority = 'high' | 'normal' | 'low';
|
|
14
|
+
/**
|
|
15
|
+
* Operation sync status
|
|
16
|
+
*/
|
|
17
|
+
type OperationStatus = 'pending' | 'syncing' | 'synced' | 'failed';
|
|
18
|
+
/**
|
|
19
|
+
* Queued operation for offline-first synchronization
|
|
20
|
+
*/
|
|
21
|
+
interface Operation {
|
|
22
|
+
id: string;
|
|
23
|
+
type: OperationType;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
status: OperationStatus;
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
priority?: OperationPriority;
|
|
28
|
+
createdAt?: number;
|
|
29
|
+
syncedAt?: number;
|
|
30
|
+
retryCount?: number;
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Conflict detection result
|
|
35
|
+
*/
|
|
36
|
+
interface ConflictDetectionResult {
|
|
37
|
+
hasConflict: boolean;
|
|
38
|
+
type?: 'update_update' | 'delete_update' | 'update_delete' | 'concurrent';
|
|
39
|
+
severity?: 'low' | 'medium' | 'high';
|
|
40
|
+
similarity?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Conflict resolution strategy
|
|
44
|
+
*/
|
|
45
|
+
type ResolutionStrategy = 'local_wins' | 'remote_wins' | 'last_modified' | 'merge' | 'manual';
|
|
46
|
+
/**
|
|
47
|
+
* Sync batch for uploading multiple operations
|
|
48
|
+
*/
|
|
49
|
+
interface SyncBatch {
|
|
50
|
+
batchId: string;
|
|
51
|
+
operations: Operation[];
|
|
52
|
+
totalSize: number;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
priority: OperationPriority;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sync result from server
|
|
58
|
+
*/
|
|
59
|
+
interface SyncResult {
|
|
60
|
+
success: boolean;
|
|
61
|
+
synced: string[];
|
|
62
|
+
failed: Array<{
|
|
63
|
+
operationId: string;
|
|
64
|
+
error: string;
|
|
65
|
+
}>;
|
|
66
|
+
conflicts: Array<{
|
|
67
|
+
operationId: string;
|
|
68
|
+
remoteVersion: Record<string, unknown>;
|
|
69
|
+
strategy: ResolutionStrategy;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Network state for adaptive sync
|
|
74
|
+
*/
|
|
75
|
+
type NetworkState = 'online' | 'offline' | 'poor' | 'unknown';
|
|
76
|
+
/**
|
|
77
|
+
* Bandwidth profile for sync adaptation
|
|
78
|
+
*/
|
|
79
|
+
interface BandwidthProfile {
|
|
80
|
+
bandwidth: number;
|
|
81
|
+
latency: number;
|
|
82
|
+
timestamp: number;
|
|
83
|
+
reliability: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Sync coordinator configuration
|
|
87
|
+
*/
|
|
88
|
+
interface SyncCoordinatorConfig {
|
|
89
|
+
maxBatchSize: number;
|
|
90
|
+
maxBatchBytes: number;
|
|
91
|
+
maxRetries: number;
|
|
92
|
+
retryDelayMs: number;
|
|
93
|
+
enableCompression: boolean;
|
|
94
|
+
enableDeltaSync: boolean;
|
|
95
|
+
adaptateBatchSize: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Vector clock for causality tracking
|
|
99
|
+
*/
|
|
100
|
+
interface VectorClock {
|
|
101
|
+
[nodeId: string]: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* CRDT operation for conflict-free updates
|
|
105
|
+
*/
|
|
106
|
+
interface CRDTOperation {
|
|
107
|
+
id: string;
|
|
108
|
+
type: 'insert' | 'delete' | 'update';
|
|
109
|
+
path: string[];
|
|
110
|
+
value?: unknown;
|
|
111
|
+
timestamp: number;
|
|
112
|
+
nodeId: string;
|
|
113
|
+
vectorClock: VectorClock;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Presence information for real-time collaboration
|
|
117
|
+
*/
|
|
118
|
+
interface PresenceInfo {
|
|
119
|
+
userId: string;
|
|
120
|
+
nodeId: string;
|
|
121
|
+
cursor?: {
|
|
122
|
+
x: number;
|
|
123
|
+
y: number;
|
|
124
|
+
};
|
|
125
|
+
selection?: {
|
|
126
|
+
start: number;
|
|
127
|
+
end: number;
|
|
128
|
+
};
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
lastActivity: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Event emitter types
|
|
134
|
+
*/
|
|
135
|
+
type EventCallback<T = unknown> = (data: T) => void;
|
|
136
|
+
type EventUnsubscribe = () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Generic event emitter interface
|
|
139
|
+
*/
|
|
140
|
+
interface IEventEmitter {
|
|
141
|
+
on<T = unknown>(event: string, callback: EventCallback<T>): EventUnsubscribe;
|
|
142
|
+
off(event: string, callback: EventCallback): void;
|
|
143
|
+
emit<T = unknown>(event: string, data?: T): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type { BandwidthProfile, CRDTOperation, ConflictDetectionResult, EventCallback, EventUnsubscribe, IEventEmitter, NetworkState, Operation, OperationPriority, OperationStatus, OperationType, PresenceInfo, ResolutionStrategy, SyncBatch, SyncCoordinatorConfig, SyncResult, VectorClock };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|