@sylphx/lens-server 3.0.1 → 4.0.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.
- package/dist/index.d.ts +16 -7
- package/dist/index.js +318 -114
- package/package.json +2 -2
- package/src/e2e/server.test.ts +82 -68
- package/src/handlers/framework.ts +65 -32
- package/src/handlers/http.test.ts +10 -10
- package/src/handlers/http.ts +3 -5
- package/src/handlers/ws-types.ts +1 -0
- package/src/handlers/ws.test.ts +9 -9
- package/src/handlers/ws.ts +14 -3
- package/src/index.ts +0 -2
- package/src/plugin/optimistic.ts +6 -6
- package/src/reconnect/operation-log.ts +20 -9
- package/src/server/create.test.ts +257 -350
- package/src/server/create.ts +328 -123
- package/src/server/types.ts +23 -6
- package/src/storage/memory.ts +24 -3
|
@@ -254,6 +254,9 @@ export class OperationLog {
|
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
256
|
* Remove oldest entry and update tracking.
|
|
257
|
+
*
|
|
258
|
+
* IMPORTANT: After entries.shift(), ALL indices must be decremented by 1
|
|
259
|
+
* to maintain correctness of entityIndex lookups.
|
|
257
260
|
*/
|
|
258
261
|
private removeOldest(): void {
|
|
259
262
|
const removed = this.entries.shift();
|
|
@@ -261,21 +264,29 @@ export class OperationLog {
|
|
|
261
264
|
|
|
262
265
|
this.totalMemory -= removed.patchSize;
|
|
263
266
|
|
|
264
|
-
//
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
// CRITICAL FIX: Decrement ALL indices for ALL entities since array shifted
|
|
268
|
+
// Must happen BEFORE any index lookups to ensure correctness
|
|
269
|
+
for (const indices of this.entityIndex.values()) {
|
|
270
|
+
for (let i = 0; i < indices.length; i++) {
|
|
271
|
+
indices[i]--;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Update oldest version for the removed entity
|
|
276
|
+
const removedEntityIndices = this.entityIndex.get(removed.entityKey);
|
|
277
|
+
if (removedEntityIndices && removedEntityIndices.length > 0) {
|
|
278
|
+
// Remove first index (oldest) for this entity
|
|
279
|
+
// After decrement above, this index is now -1, so shift() removes it
|
|
280
|
+
removedEntityIndices.shift();
|
|
269
281
|
|
|
270
|
-
if (
|
|
282
|
+
if (removedEntityIndices.length === 0) {
|
|
271
283
|
// No more entries for this entity
|
|
272
284
|
this.entityIndex.delete(removed.entityKey);
|
|
273
285
|
this.oldestVersionIndex.delete(removed.entityKey);
|
|
274
286
|
this.newestVersionIndex.delete(removed.entityKey);
|
|
275
287
|
} else {
|
|
276
|
-
// Update oldest version to next entry
|
|
277
|
-
|
|
278
|
-
const nextEntry = this.entries[indices[0] - 1]; // -1 because we shifted
|
|
288
|
+
// Update oldest version to next entry (indices already corrected)
|
|
289
|
+
const nextEntry = this.entries[removedEntityIndices[0]];
|
|
279
290
|
if (nextEntry) {
|
|
280
291
|
this.oldestVersionIndex.set(removed.entityKey, nextEntry.version);
|
|
281
292
|
}
|