File tree Expand file tree Collapse file tree 2 files changed +26
-18
lines changed Expand file tree Collapse file tree 2 files changed +26
-18
lines changed Original file line number Diff line number Diff line change 1
1
import { authFirst } from "./util" ;
2
2
3
+ export interface Patch {
4
+ seq : number ;
5
+ time : number ;
6
+ mesg : {
7
+ time : number ;
8
+ wall : number ;
9
+ patch : string ;
10
+ user_id : number ;
11
+ is_snapshot ?: boolean ;
12
+ parents : number [ ] ;
13
+ version ?: number ;
14
+ } ;
15
+ }
16
+
3
17
export interface Sync {
4
18
history : ( opts : {
5
19
account_id ?: string ;
6
20
project_id : string ;
7
21
path : string ;
8
- } ) => Promise < any [ ] > ;
22
+ } ) => Promise < { patches : Patch [ ] } > ;
9
23
}
10
24
11
25
export const sync = {
Original file line number Diff line number Diff line change 1
1
import { conat } from "@cocalc/backend/conat" ;
2
2
import isCollaborator from "@cocalc/server/projects/is-collaborator" ;
3
3
import { patchesStreamName } from "@cocalc/conat/sync/synctable-stream" ;
4
+ import { type Patch } from "@cocalc/conat/hub/api/sync" ;
4
5
5
6
export async function history ( {
6
7
account_id,
7
8
project_id,
8
9
path,
9
10
start_seq = 0 ,
11
+ end_seq,
10
12
} : {
11
13
account_id ?: string ;
12
14
project_id : string ;
13
15
path : string ;
14
- start_seq : number ;
15
- } ) : Promise < any [ ] > {
16
+ start_seq ?: number ;
17
+ end_seq ?: number ;
18
+ } ) : Promise < { patches : Patch [ ] } > {
16
19
if ( ! account_id || ! ( await isCollaborator ( { account_id, project_id } ) ) ) {
17
20
throw Error ( "user must be collaborator on source project" ) ;
18
21
}
@@ -24,21 +27,12 @@ export async function history({
24
27
project_id,
25
28
noInventory : true ,
26
29
} ) ;
27
- const patches : {
28
- seq : number ;
29
- time : number ;
30
- mesg : {
31
- time : number ;
32
- wall : number ;
33
- patch : string ;
34
- user_id : number ;
35
- is_snapshot ?: boolean ;
36
- parents : number [ ] ;
37
- version ?: number ;
38
- } ;
39
- } [ ] = [ ] ;
40
- for await ( const patch of await astream . getAll ( { start_seq } ) ) {
41
- patches . push ( patch ) ;
30
+ const patches : Patch [ ] = [ ] ;
31
+ for await ( const patch of await astream . getAll ( {
32
+ start_seq,
33
+ end_seq,
34
+ } ) ) {
35
+ patches . push ( patch as any ) ;
42
36
}
43
37
return { patches } ;
44
38
}
You can’t perform that action at this time.
0 commit comments