Skip to content

Commit 1d0ab21

Browse files
committed
fix: correctly append to the inner value of a version index
1 parent efed0b8 commit 1d0ab21

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/d2ts/src/version-index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class Index<K, V> implements IndexType<K, V> {
119119

120120
append(other: Index<K, V>): void {
121121
for (const [key, versions] of other.entries()) {
122-
const thisVersions = this.get(key)
122+
const thisVersions = this.#inner.get(key)
123123
for (const [version, data] of versions) {
124124
thisVersions.update(version, (values) => {
125125
chunkedArrayPush(values, data)

packages/d2ts/tests/version-index.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,37 @@ function createIndexTests<
342342
index.compact(frontier2)
343343
}).toThrow('Invalid compaction frontier')
344344
})
345+
346+
test.only('should append after compact', () => {
347+
const version1 = v([1])
348+
const version2 = v([2])
349+
const version3 = v([3])
350+
const frontier = new Antichain([version2])
351+
352+
index.addValue('key1', version1, [10, 1])
353+
354+
expect(index.reconstructAt('key1', version1)).toEqual([[10, 1]])
355+
356+
index.compact(frontier)
357+
358+
const other = createIndex('other')
359+
other.addValue('key1', version2, [20, 1])
360+
361+
// @ts-expect-error
362+
index.append(other)
363+
364+
const other2 = createIndex('other2')
365+
other2.addValue('key1', version3, [30, 1])
366+
367+
// @ts-expect-error
368+
index.append(other2)
369+
370+
expect(index.reconstructAt('key1', version3)).toEqual([
371+
[10, 1],
372+
[20, 1],
373+
[30, 1],
374+
])
375+
})
345376
})
346377

347378
describe('validation', () => {

0 commit comments

Comments
 (0)