1- import {
2- BlockIdRef ,
3- BlockPatchPartialRef ,
4- BlockPatchPartialReturnRef ,
5- BlockNewRef ,
6- NewBlockSnapshotResponseRef ,
7- } from '../schema' ;
1+ import { BlockIdRef , BlockBatchPartialRef , BlockSnapshotReturnRef } from '../schema' ;
82import type { RouteDeps , Router , RouterBase } from '../../types' ;
93
104export const new_ =
@@ -16,26 +10,20 @@ export const new_ =
1610 description :
1711 'The ID of the new block. Must be a unique ID, if the block already exists it will return an error.' ,
1812 } ) ,
19- t . prop ( 'patches ', t . Array ( BlockPatchPartialRef ) ) . options ( {
20- title : 'Patches ' ,
21- description : 'The patches to apply to the document .' ,
13+ t . propOpt ( 'batch ', BlockBatchPartialRef ) . options ( {
14+ title : 'Batch ' ,
15+ description : 'A collection of patches to apply to the new block .' ,
2216 } ) ,
2317 ) ;
2418
25- const Response = t
26- . Object (
27- t . prop ( 'block' , BlockNewRef ) ,
28- t . prop ( 'snapshot' , NewBlockSnapshotResponseRef ) ,
29- t . prop ( 'patches' , t . Array ( BlockPatchPartialReturnRef ) ) . options ( {
30- title : 'Patches' ,
31- description : 'The list of patches to apply to the newly created block.' ,
32- } ) ,
33- )
34- . options ( {
35- title : 'New block creation response' ,
36- description :
37- 'The response object for the new block creation, contains server generated metadata without blobs supplied by the client.' ,
38- } ) ;
19+ // prettier-ignore
20+ const Response = t . Object (
21+ t . prop ( 'snapshot' , BlockSnapshotReturnRef ) ,
22+ ) . options ( {
23+ title : 'New block creation response' ,
24+ description :
25+ 'The response object for the new block creation, contains server generated metadata without blobs supplied by the client.' ,
26+ } ) ;
3927
4028 const Func = t . Function ( Request , Response ) . options ( {
4129 title : 'Create Block' ,
@@ -44,20 +32,15 @@ export const new_ =
4432 'Creates a new block out of supplied patches. A block starts empty with an `undefined` state, and patches are applied to it.' ,
4533 } ) ;
4634
47- return r . prop ( 'block.new' , Func , async ( { id, patches} ) => {
48- const res = await services . blocks . create ( id , patches ) ;
35+ return r . prop ( 'block.new' , Func , async ( { id, batch} ) => {
36+ const { block} = await services . blocks . create ( id , batch ) ;
37+ const snapshot = block . snapshot ;
4938 return {
50- block : {
51- id : res . snapshot . id ,
52- ts : res . snapshot . created ,
53- } ,
5439 snapshot : {
55- cur : res . snapshot . seq ,
56- ts : res . snapshot . created ,
40+ id,
41+ seq : snapshot . seq ,
42+ ts : snapshot . ts ,
5743 } ,
58- patches : res . patches . map ( ( patch ) => ( {
59- ts : patch . created ,
60- } ) ) ,
6144 } ;
6245 } ) ;
6346 } ;
0 commit comments