Skip to content

Commit 1894886

Browse files
committed
feat: 🎸 cleanup block.upd method
1 parent 30c7302 commit 1894886

File tree

7 files changed

+125
-236
lines changed

7 files changed

+125
-236
lines changed

src/__demos__/json-crdt-server/routes/block/methods/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const get =
2727
block: {
2828
id: snapshot.id,
2929
ts: snapshot.created,
30-
data: {
30+
snapshot: {
3131
blob: snapshot.blob,
3232
cur: snapshot.seq,
3333
ts: snapshot.created,

src/__demos__/json-crdt-server/routes/block/methods/new.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const new_ =
4545
ts: res.snapshot.created,
4646
},
4747
patches: res.patches.map((patch) => ({
48-
cur: patch.seq,
4948
ts: patch.created,
5049
})),
5150
};
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import {ResolveType} from 'json-joy/lib/json-type';
12
import type {RouteDeps, Router, RouterBase} from '../../types';
2-
import {BlockCurRef, BlockIdRef, BlockPatchPartialRef, BlockPatchRef} from '../schema';
3+
import {BlockCurRef, BlockIdRef, BlockPatchPartialRef, BlockPatchPartialReturnRef} from '../schema';
34

45
export const upd =
56
({t, services}: RouteDeps) =>
@@ -9,21 +10,14 @@ export const upd =
910
title: 'Document ID',
1011
description: 'The ID of the document to apply the patch to.',
1112
}),
12-
t.prop('cur', BlockCurRef).options({
13-
title: 'Last known sequence number',
14-
description:
15-
'The last known sequence number of the document. ' +
16-
'If the document has changed since this sequence number, ' +
17-
'the response will contain all the necessary patches for the client to catch up.',
18-
}),
1913
t.prop('patches', t.Array(BlockPatchPartialRef)).options({
2014
title: 'Patches',
2115
description: 'The patches to apply to the document.',
2216
}),
2317
);
2418

2519
const Response = t.Object(
26-
t.prop('patches', t.Array(BlockPatchRef)).options({
20+
t.prop('patches', t.Array(BlockPatchPartialReturnRef)).options({
2721
title: 'Latest patches',
2822
description: 'The list of patches that the client might have missed and should apply to the document.',
2923
}),
@@ -35,10 +29,13 @@ export const upd =
3529
description: 'Applies patches to an existing document and returns the latest concurrent changes.',
3630
});
3731

38-
return r.prop('block.upd', Func, async ({id, cur, patches}) => {
32+
return r.prop('block.upd', Func, async ({id, patches}) => {
3933
const res = await services.blocks.edit(id, patches);
34+
const patchesReturn: ResolveType<typeof BlockPatchPartialReturnRef>[] = res.patches.map(patch => ({
35+
ts: patch.created,
36+
}));
4037
return {
41-
patches: res.patches,
38+
patches: patchesReturn,
4239
};
4340
});
4441
};

src/__demos__/json-crdt-server/routes/block/schema.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ export const BlockPatchPartialRef = t.Ref<typeof BlockPatchPartial>('BlockPatchP
2727

2828
// prettier-ignore
2929
export const BlockPatchPartialReturn = t.Object(
30-
t.prop('cur', BlockCurRef).options({
31-
title: 'Patch Sequence Number',
32-
description: 'The sequence number of the patch in the block. A monotonically increasing integer, starting from 0.',
33-
}),
3430
t.prop('ts', t.num.options({format: 'u'})).options({
3531
title: 'Patch Creation Time',
3632
description: 'The time when the patch was created, in milliseconds since the Unix epoch.' +
@@ -82,7 +78,7 @@ export const BlockNew = t.Object(
8278
export const BlockNewRef = t.Ref<typeof BlockNew>('BlockNew');
8379

8480
export const Block = BlockNew.extend(t.Object(
85-
t.prop('data', BlockSnapshotRef),
81+
t.prop('snapshot', BlockSnapshotRef),
8682
t.prop('tip', t.Array(BlockPatchRef)),
8783
));
8884
export const BlockRef = t.Ref<typeof Block>('Block');

0 commit comments

Comments
 (0)