11import type { RouteDeps , Router , RouterBase } from '../../types' ;
2- import type { BlockId , BlockPatch } from '../schema' ;
2+ import { BlockCurRef , BlockIdRef , BlockPatchPartialRef , BlockPatchRef } from '../schema' ;
33
44export const upd =
55 ( { t, services} : RouteDeps ) =>
66 < R extends RouterBase > ( r : Router < R > ) => {
7- const PatchType = t . Ref < typeof BlockPatch > ( 'BlockPatch' ) ;
8-
97 const Request = t . Object (
10- t . prop ( 'id' , t . Ref < typeof BlockId > ( 'BlockId' ) ) . options ( {
8+ t . prop ( 'id' , BlockIdRef ) . options ( {
119 title : 'Document ID' ,
1210 description : 'The ID of the document to apply the patch to.' ,
1311 } ) ,
14- // This can be inferred from the "seq" of the first patch:
15- // t.prop('seq', t.Ref<typeof BlockSeq>('BlockSeq')).options({
16- // title: 'Last known sequence number',
17- // description:
18- // 'The last known sequence number of the document. ' +
19- // 'If the document has changed since this sequence number, ' +
20- // 'the response will contain all the necessary patches for the client to catch up.',
21- // }),
22- t . prop ( 'patches' , t . Array ( PatchType ) ) . options ( {
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+ } ) ,
19+ t . prop ( 'patches' , t . Array ( BlockPatchPartialRef ) ) . options ( {
2320 title : 'Patches' ,
2421 description : 'The patches to apply to the document.' ,
2522 } ) ,
2623 ) ;
2724
2825 const Response = t . Object (
29- t . prop ( 'patches' , t . Array ( PatchType ) ) . options ( {
26+ t . prop ( 'patches' , t . Array ( BlockPatchRef ) ) . options ( {
3027 title : 'Latest patches' ,
3128 description : 'The list of patches that the client might have missed and should apply to the document.' ,
3229 } ) ,
@@ -38,7 +35,7 @@ export const upd =
3835 description : 'Applies patches to an existing document and returns the latest concurrent changes.' ,
3936 } ) ;
4037
41- return r . prop ( 'block.upd' , Func , async ( { id, patches} ) => {
38+ return r . prop ( 'block.upd' , Func , async ( { id, cur , patches} ) => {
4239 const res = await services . blocks . edit ( id , patches ) ;
4340 return {
4441 patches : res . patches ,
0 commit comments