@voidhash/mimic-effect 1.0.0-beta.10 → 1.0.0-beta.12

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 (41) hide show
  1. package/.turbo/turbo-build.log +33 -33
  2. package/dist/DocumentInstance.cjs +3 -1
  3. package/dist/DocumentInstance.d.cts +7 -1
  4. package/dist/DocumentInstance.d.cts.map +1 -1
  5. package/dist/DocumentInstance.d.mts +7 -1
  6. package/dist/DocumentInstance.d.mts.map +1 -1
  7. package/dist/DocumentInstance.mjs +3 -1
  8. package/dist/DocumentInstance.mjs.map +1 -1
  9. package/dist/HotStorage.cjs +7 -6
  10. package/dist/HotStorage.d.cts +6 -2
  11. package/dist/HotStorage.d.cts.map +1 -1
  12. package/dist/HotStorage.d.mts +6 -2
  13. package/dist/HotStorage.d.mts.map +1 -1
  14. package/dist/HotStorage.mjs +7 -6
  15. package/dist/HotStorage.mjs.map +1 -1
  16. package/dist/MimicClusterServerEngine.cjs +7 -0
  17. package/dist/MimicClusterServerEngine.d.cts.map +1 -1
  18. package/dist/MimicClusterServerEngine.d.mts.map +1 -1
  19. package/dist/MimicClusterServerEngine.mjs +7 -0
  20. package/dist/MimicClusterServerEngine.mjs.map +1 -1
  21. package/dist/MimicServerEngine.cjs +3 -0
  22. package/dist/MimicServerEngine.d.cts +8 -0
  23. package/dist/MimicServerEngine.d.cts.map +1 -1
  24. package/dist/MimicServerEngine.d.mts +8 -0
  25. package/dist/MimicServerEngine.d.mts.map +1 -1
  26. package/dist/MimicServerEngine.mjs +3 -0
  27. package/dist/MimicServerEngine.mjs.map +1 -1
  28. package/dist/testing/HotStorageTestSuite.cjs +38 -0
  29. package/dist/testing/HotStorageTestSuite.d.cts.map +1 -1
  30. package/dist/testing/HotStorageTestSuite.d.mts.map +1 -1
  31. package/dist/testing/HotStorageTestSuite.mjs +38 -0
  32. package/dist/testing/HotStorageTestSuite.mjs.map +1 -1
  33. package/dist/testing/types.d.cts +3 -3
  34. package/dist/testing/types.d.mts +3 -3
  35. package/package.json +3 -3
  36. package/src/DocumentInstance.ts +13 -2
  37. package/src/HotStorage.ts +24 -9
  38. package/src/MimicClusterServerEngine.ts +16 -1
  39. package/src/MimicServerEngine.ts +17 -0
  40. package/src/testing/HotStorageTestSuite.ts +56 -0
  41. package/tests/MimicServerEngine.test.ts +29 -3
@@ -744,6 +744,62 @@ const tests: StorageTestCase<HotStorageTestError, HotStorageTag>[] = [
744
744
  }),
745
745
  },
746
746
 
747
+ {
748
+ name: "appendWithCheck with baseVersion after full truncate works",
749
+ category: Categories.GapChecking,
750
+ run: Effect.gen(function* () {
751
+ const storage = yield* HotStorageTag;
752
+ // Append versions 1, 2, 3
753
+ yield* storage.appendWithCheck("gap-base-version", makeEntry(1), 1, 0);
754
+ yield* storage.appendWithCheck("gap-base-version", makeEntry(2), 2, 0);
755
+ yield* storage.appendWithCheck("gap-base-version", makeEntry(3), 3, 0);
756
+ // Truncate ALL entries (simulates snapshot at version 3)
757
+ yield* storage.truncate("gap-base-version", 3);
758
+ // Verify WAL is empty
759
+ const entriesAfterTruncate = yield* storage.getEntries("gap-base-version", 0);
760
+ yield* assertEmpty(entriesAfterTruncate, "WAL should be empty after full truncate");
761
+ // Append version 4 WITH baseVersion=3 (simulates knowing snapshot version)
762
+ yield* storage.appendWithCheck("gap-base-version", makeEntry(4), 4, 3);
763
+ const entries = yield* storage.getEntries("gap-base-version", 0);
764
+ yield* assertLength(entries, 1, "Should have version 4");
765
+ yield* assertEqual(entries[0]!.version, 4, "Entry should be version 4");
766
+ }),
767
+ },
768
+
769
+ {
770
+ name: "appendWithCheck with baseVersion still detects gaps",
771
+ category: Categories.GapChecking,
772
+ run: Effect.gen(function* () {
773
+ const storage = yield* HotStorageTag;
774
+ // Truncate (to establish empty WAL scenario)
775
+ yield* storage.truncate("gap-base-detect", 5);
776
+ // Try to append version 7 with baseVersion=5 (skipping version 6)
777
+ const result = yield* Effect.either(
778
+ storage.appendWithCheck("gap-base-detect", makeEntry(7), 7, 5)
779
+ );
780
+ yield* assertTrue(result._tag === "Left", "Should fail when skipping version 6");
781
+ if (result._tag === "Left") {
782
+ yield* assertTrue(
783
+ result.left._tag === "WalVersionGapError",
784
+ "Error should be WalVersionGapError"
785
+ );
786
+ }
787
+ }),
788
+ },
789
+
790
+ {
791
+ name: "appendWithCheck with baseVersion=0 allows version 1",
792
+ category: Categories.GapChecking,
793
+ run: Effect.gen(function* () {
794
+ const storage = yield* HotStorageTag;
795
+ // New document scenario: baseVersion=0, first entry should be version 1
796
+ yield* storage.appendWithCheck("gap-base-zero", makeEntry(1), 1, 0);
797
+ const entries = yield* storage.getEntries("gap-base-zero", 0);
798
+ yield* assertLength(entries, 1, "Should have version 1");
799
+ yield* assertEqual(entries[0]!.version, 1, "Entry should be version 1");
800
+ }),
801
+ },
802
+
747
803
  // ---------------------------------------------------------------------------
748
804
  // Transaction Encoding (Critical for OperationPath preservation)
749
805
  // ---------------------------------------------------------------------------
@@ -190,13 +190,13 @@ describe("MimicServerEngine", () => {
190
190
  Effect.scoped(
191
191
  Effect.gen(function* () {
192
192
  const engine = yield* MimicServerEngineTag;
193
-
193
+
194
194
  // Submit transaction
195
195
  const submitResult = yield* engine.submit("test-doc-2", tx);
196
-
196
+
197
197
  // Get snapshot
198
198
  const snapshot = yield* engine.getSnapshot("test-doc-2");
199
-
199
+
200
200
  return { submitResult, snapshot };
201
201
  })
202
202
  ).pipe(Effect.provide(makeTestLayer({ initial: { title: "Initial" } })))
@@ -210,6 +210,32 @@ describe("MimicServerEngine", () => {
210
210
  expect(result.snapshot.state).toEqual({ title: "Updated Title" });
211
211
  });
212
212
 
213
+ it("should get tree snapshot for rendering", async () => {
214
+ const tx = createValidTransaction("Tree Snapshot Test");
215
+
216
+ const result = await Effect.runPromise(
217
+ Effect.scoped(
218
+ Effect.gen(function* () {
219
+ const engine = yield* MimicServerEngineTag;
220
+
221
+ // Submit transaction
222
+ yield* engine.submit("test-doc-tree", tx);
223
+
224
+ // Get tree snapshot (for rendering)
225
+ const treeSnapshot = yield* engine.getTreeSnapshot("test-doc-tree");
226
+
227
+ return treeSnapshot;
228
+ })
229
+ ).pipe(Effect.provide(makeTestLayer({ initial: { title: "Initial" } })))
230
+ );
231
+
232
+ // Tree snapshot should have the expected structure with defaults resolved
233
+ expect(result).toEqual({
234
+ title: "Tree Snapshot Test",
235
+ count: 0, // Default value
236
+ });
237
+ });
238
+
213
239
  it("should touch document to update activity time", async () => {
214
240
  const result = await Effect.runPromise(
215
241
  Effect.scoped(