Skip to content

Commit af459c9

Browse files
committed
feat: 🎸 update remote.scanFwd() method
1 parent 49de3cc commit af459c9

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/json-crdt-repo/remote/DemoServerRemoteHistory.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,13 @@ export class DemoServerRemoteHistory
2828
}
2929

3030
public async scanFwd(id: string, cursor: Cursor): Promise<{patches: DemoServerPatch[]}> {
31-
throw new Error('Method not implemented.');
32-
// const limit = 100;
33-
// const res = await this.client.call('block.scan', {
34-
// id,
35-
// seq: cursor,
36-
// limit: cursor + limit,
37-
// });
38-
// if (res.patches.length === 0) {
39-
// return {
40-
// cursor,
41-
// patches: [],
42-
// };
43-
// }
44-
// return {
45-
// cursor: res.patches[res.patches.length - 1].seq,
46-
// patches: res.patches,
47-
// };
31+
const limit = 100;
32+
const res = await this.client.call('block.scan', {
33+
id,
34+
cur: cursor,
35+
limit,
36+
});
37+
return res;
4838
}
4939

5040
public async scanBwd(

src/json-crdt-repo/remote/__tests__/DemoServerRemoteHistory.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('.read()', () => {
9595

9696
describe('.update()', () => {
9797
test('can apply changes to an empty document', async () => {
98-
const {remote, caller} = await setup();
98+
const {remote} = await setup();
9999
const id = genId();
100100
await remote.create(id, []);
101101
const read1 = await remote.read(id);
@@ -117,6 +117,32 @@ describe('.update()', () => {
117117
});
118118
});
119119

120+
describe('.scanFwd()', () => {
121+
test('can scan patches forward', async () => {
122+
const {remote} = await setup();
123+
const id = genId();
124+
const model1 = Model.withLogicalClock();
125+
model1.api.root({score: 42});
126+
const patch1 = model1.api.flush();
127+
const blob = patch1.toBinary();
128+
await remote.create(id, [{blob}]);
129+
const read1 = await remote.read(id);
130+
model1.api.obj([]).set({
131+
foo: 'bar',
132+
});
133+
const patch2 = model1.api.flush();
134+
const blob2 = patch2.toBinary();
135+
await remote.update(id, [{blob: blob2}]);
136+
const scan1 = await remote.scanFwd(id, read1.block.snapshot.cur + 1);
137+
expect(scan1).toMatchObject({
138+
patches: [{
139+
blob: expect.any(Uint8Array),
140+
ts: expect.any(Number),
141+
}]
142+
});
143+
});
144+
});
145+
120146
describe('.delete()', () => {
121147
test('can delete an existing block', async () => {
122148
const {remote, caller} = await setup();

0 commit comments

Comments
 (0)