@nahisaho/yata-scale 1.8.5

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 (158) hide show
  1. package/README.md +66 -0
  2. package/dist/CacheManager.d.ts +107 -0
  3. package/dist/CacheManager.d.ts.map +1 -0
  4. package/dist/CacheManager.js +343 -0
  5. package/dist/CacheManager.js.map +1 -0
  6. package/dist/IndexManager.d.ts +103 -0
  7. package/dist/IndexManager.d.ts.map +1 -0
  8. package/dist/IndexManager.js +385 -0
  9. package/dist/IndexManager.js.map +1 -0
  10. package/dist/MigrationHelper.d.ts +91 -0
  11. package/dist/MigrationHelper.d.ts.map +1 -0
  12. package/dist/MigrationHelper.js +220 -0
  13. package/dist/MigrationHelper.js.map +1 -0
  14. package/dist/QueryCoordinator.d.ts +76 -0
  15. package/dist/QueryCoordinator.d.ts.map +1 -0
  16. package/dist/QueryCoordinator.js +298 -0
  17. package/dist/QueryCoordinator.js.map +1 -0
  18. package/dist/ShardManager.d.ts +48 -0
  19. package/dist/ShardManager.d.ts.map +1 -0
  20. package/dist/ShardManager.js +193 -0
  21. package/dist/ShardManager.js.map +1 -0
  22. package/dist/SyncController.d.ts +102 -0
  23. package/dist/SyncController.d.ts.map +1 -0
  24. package/dist/SyncController.js +286 -0
  25. package/dist/SyncController.js.map +1 -0
  26. package/dist/YataScaleManager.d.ts +75 -0
  27. package/dist/YataScaleManager.d.ts.map +1 -0
  28. package/dist/YataScaleManager.js +265 -0
  29. package/dist/YataScaleManager.js.map +1 -0
  30. package/dist/cache/CacheManager.d.ts +116 -0
  31. package/dist/cache/CacheManager.d.ts.map +1 -0
  32. package/dist/cache/CacheManager.js +286 -0
  33. package/dist/cache/CacheManager.js.map +1 -0
  34. package/dist/cache/InvalidationManager.d.ts +91 -0
  35. package/dist/cache/InvalidationManager.d.ts.map +1 -0
  36. package/dist/cache/InvalidationManager.js +155 -0
  37. package/dist/cache/InvalidationManager.js.map +1 -0
  38. package/dist/cache/L1Cache.d.ts +97 -0
  39. package/dist/cache/L1Cache.d.ts.map +1 -0
  40. package/dist/cache/L1Cache.js +225 -0
  41. package/dist/cache/L1Cache.js.map +1 -0
  42. package/dist/cache/L2Cache.d.ts +93 -0
  43. package/dist/cache/L2Cache.d.ts.map +1 -0
  44. package/dist/cache/L2Cache.js +248 -0
  45. package/dist/cache/L2Cache.js.map +1 -0
  46. package/dist/cache/L3Cache.d.ts +101 -0
  47. package/dist/cache/L3Cache.d.ts.map +1 -0
  48. package/dist/cache/L3Cache.js +229 -0
  49. package/dist/cache/L3Cache.js.map +1 -0
  50. package/dist/cache/index.d.ts +12 -0
  51. package/dist/cache/index.d.ts.map +1 -0
  52. package/dist/cache/index.js +11 -0
  53. package/dist/cache/index.js.map +1 -0
  54. package/dist/errors.d.ts +255 -0
  55. package/dist/errors.d.ts.map +1 -0
  56. package/dist/errors.js +515 -0
  57. package/dist/errors.js.map +1 -0
  58. package/dist/index/BPlusTreeIndex.d.ts +101 -0
  59. package/dist/index/BPlusTreeIndex.d.ts.map +1 -0
  60. package/dist/index/BPlusTreeIndex.js +310 -0
  61. package/dist/index/BPlusTreeIndex.js.map +1 -0
  62. package/dist/index/BloomFilter.d.ts +85 -0
  63. package/dist/index/BloomFilter.d.ts.map +1 -0
  64. package/dist/index/BloomFilter.js +215 -0
  65. package/dist/index/BloomFilter.js.map +1 -0
  66. package/dist/index/FullTextIndex.d.ts +87 -0
  67. package/dist/index/FullTextIndex.d.ts.map +1 -0
  68. package/dist/index/FullTextIndex.js +213 -0
  69. package/dist/index/FullTextIndex.js.map +1 -0
  70. package/dist/index/GraphIndex.d.ts +116 -0
  71. package/dist/index/GraphIndex.d.ts.map +1 -0
  72. package/dist/index/GraphIndex.js +308 -0
  73. package/dist/index/GraphIndex.js.map +1 -0
  74. package/dist/index/IndexManager.d.ts +105 -0
  75. package/dist/index/IndexManager.d.ts.map +1 -0
  76. package/dist/index/IndexManager.js +287 -0
  77. package/dist/index/IndexManager.js.map +1 -0
  78. package/dist/index/index.d.ts +12 -0
  79. package/dist/index/index.d.ts.map +1 -0
  80. package/dist/index/index.js +11 -0
  81. package/dist/index/index.js.map +1 -0
  82. package/dist/index.d.ts +12 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +12 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/query/DistributedExecutor.d.ts +78 -0
  87. package/dist/query/DistributedExecutor.d.ts.map +1 -0
  88. package/dist/query/DistributedExecutor.js +232 -0
  89. package/dist/query/DistributedExecutor.js.map +1 -0
  90. package/dist/query/QueryCoordinator.d.ts +98 -0
  91. package/dist/query/QueryCoordinator.d.ts.map +1 -0
  92. package/dist/query/QueryCoordinator.js +246 -0
  93. package/dist/query/QueryCoordinator.js.map +1 -0
  94. package/dist/query/QueryPlanner.d.ts +88 -0
  95. package/dist/query/QueryPlanner.d.ts.map +1 -0
  96. package/dist/query/QueryPlanner.js +235 -0
  97. package/dist/query/QueryPlanner.js.map +1 -0
  98. package/dist/query/WorkerPool.d.ts +108 -0
  99. package/dist/query/WorkerPool.d.ts.map +1 -0
  100. package/dist/query/WorkerPool.js +195 -0
  101. package/dist/query/WorkerPool.js.map +1 -0
  102. package/dist/query/index.d.ts +11 -0
  103. package/dist/query/index.d.ts.map +1 -0
  104. package/dist/query/index.js +10 -0
  105. package/dist/query/index.js.map +1 -0
  106. package/dist/shard/GraphPartitionStrategy.d.ts +65 -0
  107. package/dist/shard/GraphPartitionStrategy.d.ts.map +1 -0
  108. package/dist/shard/GraphPartitionStrategy.js +208 -0
  109. package/dist/shard/GraphPartitionStrategy.js.map +1 -0
  110. package/dist/shard/HashPartitionStrategy.d.ts +56 -0
  111. package/dist/shard/HashPartitionStrategy.d.ts.map +1 -0
  112. package/dist/shard/HashPartitionStrategy.js +169 -0
  113. package/dist/shard/HashPartitionStrategy.js.map +1 -0
  114. package/dist/shard/RangePartitionStrategy.d.ts +63 -0
  115. package/dist/shard/RangePartitionStrategy.d.ts.map +1 -0
  116. package/dist/shard/RangePartitionStrategy.js +157 -0
  117. package/dist/shard/RangePartitionStrategy.js.map +1 -0
  118. package/dist/shard/Rebalancer.d.ts +70 -0
  119. package/dist/shard/Rebalancer.d.ts.map +1 -0
  120. package/dist/shard/Rebalancer.js +184 -0
  121. package/dist/shard/Rebalancer.js.map +1 -0
  122. package/dist/shard/ShardManager.d.ts +123 -0
  123. package/dist/shard/ShardManager.d.ts.map +1 -0
  124. package/dist/shard/ShardManager.js +353 -0
  125. package/dist/shard/ShardManager.js.map +1 -0
  126. package/dist/shard/ShardRouter.d.ts +102 -0
  127. package/dist/shard/ShardRouter.d.ts.map +1 -0
  128. package/dist/shard/ShardRouter.js +181 -0
  129. package/dist/shard/ShardRouter.js.map +1 -0
  130. package/dist/shard/index.d.ts +13 -0
  131. package/dist/shard/index.d.ts.map +1 -0
  132. package/dist/shard/index.js +12 -0
  133. package/dist/shard/index.js.map +1 -0
  134. package/dist/sync/ConflictResolver.d.ts +71 -0
  135. package/dist/sync/ConflictResolver.d.ts.map +1 -0
  136. package/dist/sync/ConflictResolver.js +214 -0
  137. package/dist/sync/ConflictResolver.js.map +1 -0
  138. package/dist/sync/SyncController.d.ts +150 -0
  139. package/dist/sync/SyncController.d.ts.map +1 -0
  140. package/dist/sync/SyncController.js +304 -0
  141. package/dist/sync/SyncController.js.map +1 -0
  142. package/dist/sync/VectorClock.d.ts +102 -0
  143. package/dist/sync/VectorClock.d.ts.map +1 -0
  144. package/dist/sync/VectorClock.js +189 -0
  145. package/dist/sync/VectorClock.js.map +1 -0
  146. package/dist/sync/WALManager.d.ts +120 -0
  147. package/dist/sync/WALManager.d.ts.map +1 -0
  148. package/dist/sync/WALManager.js +240 -0
  149. package/dist/sync/WALManager.js.map +1 -0
  150. package/dist/sync/index.d.ts +11 -0
  151. package/dist/sync/index.d.ts.map +1 -0
  152. package/dist/sync/index.js +10 -0
  153. package/dist/sync/index.js.map +1 -0
  154. package/dist/types.d.ts +323 -0
  155. package/dist/types.d.ts.map +1 -0
  156. package/dist/types.js +7 -0
  157. package/dist/types.js.map +1 -0
  158. package/package.json +86 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @nahisaho/yata-scale - WAL Manager
3
+ *
4
+ * Write-Ahead Log for durability and sync
5
+ */
6
+ import type { Entity, Relationship, WALEntry } from '../types.js';
7
+ /**
8
+ * WAL operation type
9
+ */
10
+ export type WALOperation = 'create' | 'update' | 'delete';
11
+ /**
12
+ * WAL entry with full data
13
+ */
14
+ export interface WALRecord {
15
+ readonly sequenceNumber: number;
16
+ readonly timestamp: Date;
17
+ readonly operation: WALOperation;
18
+ readonly entityType: 'entity' | 'relationship';
19
+ readonly entityId: string;
20
+ readonly data?: Entity | Relationship;
21
+ readonly previousData?: Entity | Relationship;
22
+ readonly checksum: number;
23
+ }
24
+ /**
25
+ * Write-Ahead Log manager
26
+ */
27
+ export declare class WALManager {
28
+ private currentSegment;
29
+ private closedSegments;
30
+ private sequenceNumber;
31
+ private readonly maxEntriesPerSegment;
32
+ private readonly maxSegments;
33
+ constructor(maxEntriesPerSegment?: number, maxSegments?: number);
34
+ /**
35
+ * Create a new segment
36
+ */
37
+ private createSegment;
38
+ /**
39
+ * Append entity create operation
40
+ */
41
+ appendCreate(entity: Entity): WALRecord;
42
+ /**
43
+ * Append entity update operation
44
+ */
45
+ appendUpdate(entity: Entity, previous?: Entity): WALRecord;
46
+ /**
47
+ * Append entity delete operation
48
+ */
49
+ appendDelete(entityId: string, previous?: Entity): WALRecord;
50
+ /**
51
+ * Append relationship create operation
52
+ */
53
+ appendRelationshipCreate(relationship: Relationship): WALRecord;
54
+ /**
55
+ * Append relationship update operation
56
+ */
57
+ appendRelationshipUpdate(relationship: Relationship, previous?: Relationship): WALRecord;
58
+ /**
59
+ * Append relationship delete operation
60
+ */
61
+ appendRelationshipDelete(relationshipId: string, previous?: Relationship): WALRecord;
62
+ /**
63
+ * Append a record to the WAL
64
+ */
65
+ private append;
66
+ /**
67
+ * Rotate to a new segment
68
+ */
69
+ private rotateSegment;
70
+ /**
71
+ * Compact old segments
72
+ */
73
+ private compact;
74
+ /**
75
+ * Calculate checksum for a record
76
+ */
77
+ private calculateChecksum;
78
+ /**
79
+ * Get entries since a sequence number
80
+ */
81
+ getEntriesSince(sequenceNumber: number): WALRecord[];
82
+ /**
83
+ * Get entries in a range
84
+ */
85
+ getEntriesInRange(start: number, end: number): WALRecord[];
86
+ /**
87
+ * Get latest sequence number
88
+ */
89
+ getLatestSequence(): number;
90
+ /**
91
+ * Convert to WALEntry format for sync
92
+ */
93
+ toWALEntries(records: WALRecord[]): WALEntry[];
94
+ /**
95
+ * Replay WAL entries
96
+ */
97
+ replay(fromSequence?: number): Generator<WALRecord>;
98
+ /**
99
+ * Validate a record's checksum
100
+ */
101
+ validateRecord(record: WALRecord): boolean;
102
+ /**
103
+ * Get statistics
104
+ */
105
+ getStats(): {
106
+ currentSequence: number;
107
+ totalSegments: number;
108
+ currentSegmentEntries: number;
109
+ totalEntries: number;
110
+ };
111
+ /**
112
+ * Clear all segments
113
+ */
114
+ clear(): void;
115
+ /**
116
+ * Force segment rotation
117
+ */
118
+ forceRotate(): void;
119
+ }
120
+ //# sourceMappingURL=WALManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WALManager.d.ts","sourceRoot":"","sources":["../../src/sync/WALManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,cAAc,CA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AM,GAAG,SAAS,EAAE;IAwBpD;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE;IAwB1D;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAI3B;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE;IAW9C;;OAEG;IACF,MAAM,CAAC,YAAY,GAAE,MAAU,GAAG,SAAS,CAAC,SAAS,CAAC;IAOvD;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO;IAU1C;;OAEG;IACH,QAAQ,IAAI;QACV,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,qBAAqB,EAAE,MAAM,CAAC;QAC9B,YAAY,EAAE,MAAM,CAAC;KACtB;IAcD;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,WAAW,IAAI,IAAI;CAKpB"}
@@ -0,0 +1,240 @@
1
+ /**
2
+ * @nahisaho/yata-scale - WAL Manager
3
+ *
4
+ * Write-Ahead Log for durability and sync
5
+ */
6
+ /**
7
+ * Write-Ahead Log manager
8
+ */
9
+ export class WALManager {
10
+ currentSegment;
11
+ closedSegments = [];
12
+ sequenceNumber = 0;
13
+ maxEntriesPerSegment;
14
+ maxSegments;
15
+ constructor(maxEntriesPerSegment = 10000, maxSegments = 100) {
16
+ this.maxEntriesPerSegment = maxEntriesPerSegment;
17
+ this.maxSegments = maxSegments;
18
+ this.currentSegment = this.createSegment();
19
+ }
20
+ /**
21
+ * Create a new segment
22
+ */
23
+ createSegment() {
24
+ return {
25
+ id: `segment_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
26
+ startSequence: this.sequenceNumber,
27
+ endSequence: this.sequenceNumber,
28
+ entries: [],
29
+ closed: false,
30
+ };
31
+ }
32
+ /**
33
+ * Append entity create operation
34
+ */
35
+ appendCreate(entity) {
36
+ return this.append('create', 'entity', entity.id, entity);
37
+ }
38
+ /**
39
+ * Append entity update operation
40
+ */
41
+ appendUpdate(entity, previous) {
42
+ return this.append('update', 'entity', entity.id, entity, previous);
43
+ }
44
+ /**
45
+ * Append entity delete operation
46
+ */
47
+ appendDelete(entityId, previous) {
48
+ return this.append('delete', 'entity', entityId, undefined, previous);
49
+ }
50
+ /**
51
+ * Append relationship create operation
52
+ */
53
+ appendRelationshipCreate(relationship) {
54
+ return this.append('create', 'relationship', relationship.id, relationship);
55
+ }
56
+ /**
57
+ * Append relationship update operation
58
+ */
59
+ appendRelationshipUpdate(relationship, previous) {
60
+ return this.append('update', 'relationship', relationship.id, relationship, previous);
61
+ }
62
+ /**
63
+ * Append relationship delete operation
64
+ */
65
+ appendRelationshipDelete(relationshipId, previous) {
66
+ return this.append('delete', 'relationship', relationshipId, undefined, previous);
67
+ }
68
+ /**
69
+ * Append a record to the WAL
70
+ */
71
+ append(operation, entityType, entityId, data, previousData) {
72
+ const record = {
73
+ sequenceNumber: this.sequenceNumber++,
74
+ timestamp: new Date(),
75
+ operation,
76
+ entityType,
77
+ entityId,
78
+ data,
79
+ previousData,
80
+ checksum: this.calculateChecksum(operation, entityType, entityId, data),
81
+ };
82
+ this.currentSegment.entries.push(record);
83
+ this.currentSegment.endSequence = record.sequenceNumber;
84
+ // Check if segment is full
85
+ if (this.currentSegment.entries.length >= this.maxEntriesPerSegment) {
86
+ this.rotateSegment();
87
+ }
88
+ return record;
89
+ }
90
+ /**
91
+ * Rotate to a new segment
92
+ */
93
+ rotateSegment() {
94
+ // Close current segment
95
+ this.currentSegment.closed = true;
96
+ this.closedSegments.push(this.currentSegment);
97
+ // Compact if too many segments
98
+ if (this.closedSegments.length > this.maxSegments) {
99
+ this.compact();
100
+ }
101
+ // Create new segment
102
+ this.currentSegment = this.createSegment();
103
+ }
104
+ /**
105
+ * Compact old segments
106
+ */
107
+ compact() {
108
+ // Remove oldest segments
109
+ const toRemove = this.closedSegments.length - this.maxSegments;
110
+ if (toRemove > 0) {
111
+ this.closedSegments = this.closedSegments.slice(toRemove);
112
+ }
113
+ }
114
+ /**
115
+ * Calculate checksum for a record
116
+ */
117
+ calculateChecksum(operation, entityType, entityId, data) {
118
+ const str = `${operation}:${entityType}:${entityId}:${JSON.stringify(data ?? {})}`;
119
+ let hash = 0;
120
+ for (let i = 0; i < str.length; i++) {
121
+ const char = str.charCodeAt(i);
122
+ hash = ((hash << 5) - hash) + char;
123
+ hash = hash & hash;
124
+ }
125
+ return hash;
126
+ }
127
+ /**
128
+ * Get entries since a sequence number
129
+ */
130
+ getEntriesSince(sequenceNumber) {
131
+ const entries = [];
132
+ // Search closed segments
133
+ for (const segment of this.closedSegments) {
134
+ if (segment.endSequence >= sequenceNumber) {
135
+ for (const entry of segment.entries) {
136
+ if (entry.sequenceNumber >= sequenceNumber) {
137
+ entries.push(entry);
138
+ }
139
+ }
140
+ }
141
+ }
142
+ // Search current segment
143
+ for (const entry of this.currentSegment.entries) {
144
+ if (entry.sequenceNumber >= sequenceNumber) {
145
+ entries.push(entry);
146
+ }
147
+ }
148
+ return entries;
149
+ }
150
+ /**
151
+ * Get entries in a range
152
+ */
153
+ getEntriesInRange(start, end) {
154
+ const entries = [];
155
+ // Search closed segments
156
+ for (const segment of this.closedSegments) {
157
+ if (segment.endSequence >= start && segment.startSequence <= end) {
158
+ for (const entry of segment.entries) {
159
+ if (entry.sequenceNumber >= start && entry.sequenceNumber <= end) {
160
+ entries.push(entry);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ // Search current segment
166
+ for (const entry of this.currentSegment.entries) {
167
+ if (entry.sequenceNumber >= start && entry.sequenceNumber <= end) {
168
+ entries.push(entry);
169
+ }
170
+ }
171
+ return entries;
172
+ }
173
+ /**
174
+ * Get latest sequence number
175
+ */
176
+ getLatestSequence() {
177
+ return this.sequenceNumber - 1;
178
+ }
179
+ /**
180
+ * Convert to WALEntry format for sync
181
+ */
182
+ toWALEntries(records) {
183
+ return records.map((record) => ({
184
+ sequenceNumber: record.sequenceNumber,
185
+ timestamp: record.timestamp,
186
+ operation: record.operation,
187
+ entityType: record.entityType,
188
+ entityId: record.entityId,
189
+ data: record.data,
190
+ }));
191
+ }
192
+ /**
193
+ * Replay WAL entries
194
+ */
195
+ *replay(fromSequence = 0) {
196
+ const entries = this.getEntriesSince(fromSequence);
197
+ for (const entry of entries) {
198
+ yield entry;
199
+ }
200
+ }
201
+ /**
202
+ * Validate a record's checksum
203
+ */
204
+ validateRecord(record) {
205
+ const expected = this.calculateChecksum(record.operation, record.entityType, record.entityId, record.data);
206
+ return record.checksum === expected;
207
+ }
208
+ /**
209
+ * Get statistics
210
+ */
211
+ getStats() {
212
+ let totalEntries = this.currentSegment.entries.length;
213
+ for (const segment of this.closedSegments) {
214
+ totalEntries += segment.entries.length;
215
+ }
216
+ return {
217
+ currentSequence: this.sequenceNumber,
218
+ totalSegments: this.closedSegments.length + 1,
219
+ currentSegmentEntries: this.currentSegment.entries.length,
220
+ totalEntries,
221
+ };
222
+ }
223
+ /**
224
+ * Clear all segments
225
+ */
226
+ clear() {
227
+ this.closedSegments = [];
228
+ this.currentSegment = this.createSegment();
229
+ this.sequenceNumber = 0;
230
+ }
231
+ /**
232
+ * Force segment rotation
233
+ */
234
+ forceRotate() {
235
+ if (this.currentSegment.entries.length > 0) {
236
+ this.rotateSegment();
237
+ }
238
+ }
239
+ }
240
+ //# sourceMappingURL=WALManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WALManager.js","sourceRoot":"","sources":["../../src/sync/WALManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkCH;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,cAAc,CAAa;IAC3B,cAAc,GAAiB,EAAE,CAAC;IAClC,cAAc,GAAW,CAAC,CAAC;IAClB,oBAAoB,CAAS;IAC7B,WAAW,CAAS;IAErC,YACE,uBAA+B,KAAK,EACpC,cAAsB,GAAG;QAEzB,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACjD,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,MAAM;YACzD,YAAY;SACb,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAC3C,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,WAAW;QACT,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @nahisaho/yata-scale - Sync Module
3
+ *
4
+ * Exports for synchronization functionality
5
+ */
6
+ export { SyncController } from './SyncController.js';
7
+ export { VectorClock } from './VectorClock.js';
8
+ export { ConflictResolver } from './ConflictResolver.js';
9
+ export { WALManager } from './WALManager.js';
10
+ export type { SyncConfig, SyncSession, Conflict, ConflictResolution, VectorClockValue, WALEntry, } from '../types.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,YAAY,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,GACT,MAAM,aAAa,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @nahisaho/yata-scale - Sync Module
3
+ *
4
+ * Exports for synchronization functionality
5
+ */
6
+ export { SyncController } from './SyncController.js';
7
+ export { VectorClock } from './VectorClock.js';
8
+ export { ConflictResolver } from './ConflictResolver.js';
9
+ export { WALManager } from './WALManager.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}