deno.land / x / replicache@v10.0.0-beta.0 / persist / gather-visitor.test.ts

gather-visitor.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import {expect} from '@esm-bundle/chai';import * as dag from '../dag/mod';import {makeNewTempHashFunction, newTempHash} from '../hash';import { addGenesis, addIndexChange, addLocal, addSnapshot, Chain,} from '../db/test-helpers';import {GatherVisitor} from './gather-visitor';import {TestMemStore} from '../kv/test-mem-store';import {sortByHash} from '../dag/test-store';
test('dag with no temp hashes gathers nothing', async () => { const dagStore = new dag.TestStore();
const chain: Chain = []; await addGenesis(chain, dagStore); await addLocal(chain, dagStore); await addIndexChange(chain, dagStore); await addLocal(chain, dagStore);
await dagStore.withRead(async dagRead => { for (const commit of chain) { const visitor = new GatherVisitor(dagRead); await visitor.visitCommit(commit.chunk.hash); expect(visitor.gatheredChunks).to.be.empty; } });
await addSnapshot(chain, dagStore, undefined);
await dagStore.withRead(async dagRead => { const visitor = new GatherVisitor(dagRead); await visitor.visitCommit(chain[chain.length - 1].chunk.hash); expect(visitor.gatheredChunks).to.be.empty; });});
test('dag with only temp hashes gathers eveything', async () => { const kvStore = new TestMemStore(); const dagStore = new dag.TestStore(kvStore, newTempHash, () => void 0); const chain: Chain = [];
const testGatheredChunks = async () => { await dagStore.withRead(async dagRead => { const visitor = new GatherVisitor(dagRead); await visitor.visitCommit(chain[chain.length - 1].chunk.hash); expect(dagStore.chunks()).to.deep.equal( sortByHash(visitor.gatheredChunks.values()), ); }); };
await addGenesis(chain, dagStore); await addLocal(chain, dagStore); await testGatheredChunks();
await addIndexChange(chain, dagStore); await addLocal(chain, dagStore); await testGatheredChunks();
await addSnapshot(chain, dagStore, undefined); await testGatheredChunks();});
test('dag with some permanent hashes and some temp hashes on top', async () => { const kvStore = new TestMemStore(); const perdag = new dag.TestStore(kvStore); const chain: Chain = [];
await addGenesis(chain, perdag); await addLocal(chain, perdag);
await perdag.withRead(async dagRead => { const visitor = new GatherVisitor(dagRead); await visitor.visitCommit(chain[chain.length - 1].chunk.hash); expect(visitor.gatheredChunks).to.be.empty; });
const memdag = new dag.TestStore( kvStore, makeNewTempHashFunction(), () => void 0, );
await addLocal(chain, memdag);
await memdag.withRead(async dagRead => { const visitor = new GatherVisitor(dagRead); await visitor.visitCommit(chain[chain.length - 1].chunk.hash); expect(Object.fromEntries(visitor.gatheredChunks)).to.deep.equal({ 't/000000000000000000000000000000': { data: [0, [['local', '2']]], hash: 't/000000000000000000000000000000', meta: [], }, 't/000000000000000000000000000001': { data: { indexes: [], meta: { basisHash: 'fakehash000000000000000000000003', mutationID: 2, mutatorArgsJSON: [2], mutatorName: 'mutator_name_2', originalHash: null, timestamp: 42, type: 2, }, valueHash: 't/000000000000000000000000000000', }, hash: 't/000000000000000000000000000001', meta: [ 't/000000000000000000000000000000', 'fakehash000000000000000000000003', ], }, }); });
await addSnapshot( chain, perdag, Object.entries({ a: 1, b: 2, c: 3, d: 4, }), ); await addIndexChange(chain, memdag);
await memdag.withRead(async dagRead => { const visitor = new GatherVisitor(dagRead); await visitor.visitCommit(chain[chain.length - 1].chunk.hash); expect(Object.fromEntries(visitor.gatheredChunks)).to.deep.equal({ 't/000000000000000000000000000002': { data: [0, [['\u00002\u0000local', '2']]], hash: 't/000000000000000000000000000002', meta: [], }, 't/000000000000000000000000000003': { data: { indexes: [ { definition: { jsonPointer: '', keyPrefix: 'local', name: '4', }, valueHash: 't/000000000000000000000000000002', }, ], meta: { basisHash: 'fakehash000000000000000000000005', lastMutationID: 3, type: 1, }, valueHash: 'fakehash000000000000000000000004', }, hash: 't/000000000000000000000000000003', meta: [ 'fakehash000000000000000000000004', 'fakehash000000000000000000000005', 't/000000000000000000000000000002', ], }, }); });});
replicache

Version Info

Tagged at
2 years ago