1- import { File , FileOptions } from " ../file/File" ;
2- import { CborEncoder } from " ../../json-pack/cbor/CborEncoder" ;
3- import type { CrudApi } from " memfs/lib/crud/types" ;
4- import type { Locks } from " thingies/es2020/Locks" ;
5- import type { Patch } from " ../../json-crdt-patch" ;
6- import type { PatchLog } from " ./PatchLog" ;
7- import type { LocalHistory } from " ./types" ;
1+ import { File , FileOptions } from ' ../file/File' ;
2+ import { CborEncoder } from ' ../../json-pack/cbor/CborEncoder' ;
3+ import type { CrudApi } from ' memfs/lib/crud/types' ;
4+ import type { Locks } from ' thingies/es2020/Locks' ;
5+ import type { Patch } from ' ../../json-crdt-patch' ;
6+ import type { PatchLog } from ' ./PatchLog' ;
7+ import type { LocalHistory } from ' ./types' ;
88
99export const genId = ( octets : number = 8 ) : string => {
1010 const uint8 = crypto . getRandomValues ( new Uint8Array ( octets ) ) ;
@@ -29,7 +29,7 @@ export class LocalHistoryCrud implements LocalHistory {
2929 // TODO: Remove `log.end`, just `log` should be enough.
3030 const file = new File ( log . end , log , this . fileOpts ) ;
3131 const blob = file . toBinary ( {
32- format : " seq.cbor" ,
32+ format : ' seq.cbor' ,
3333 model : 'binary' ,
3434 } ) ;
3535 const id = genId ( ) ;
@@ -39,7 +39,7 @@ export class LocalHistoryCrud implements LocalHistory {
3939 return { id} ;
4040 }
4141
42- public async read ( collection : string [ ] , id : string ) : Promise < { log : PatchLog , cursor : string } > {
42+ public async read ( collection : string [ ] , id : string ) : Promise < { log : PatchLog ; cursor : string } > {
4343 const blob = await this . crud . get ( [ ...collection , id ] , STATE_FILE_NAME ) ;
4444 const { log} = File . fromSeqCbor ( blob ) ;
4545 return {
@@ -48,7 +48,7 @@ export class LocalHistoryCrud implements LocalHistory {
4848 } ;
4949 }
5050
51- public readHistory ( collection : string [ ] , id : string , cursor : string ) : Promise < { log : PatchLog , cursor : string } > {
51+ public readHistory ( collection : string [ ] , id : string , cursor : string ) : Promise < { log : PatchLog ; cursor : string } > {
5252 throw new Error ( 'Method not implemented.' ) ;
5353 }
5454
@@ -59,7 +59,7 @@ export class LocalHistoryCrud implements LocalHistory {
5959 log . end . applyBatch ( patches ) ;
6060 const file = new File ( log . end , log , this . fileOpts ) ;
6161 const blob2 = file . toBinary ( {
62- format : " seq.cbor" ,
62+ format : ' seq.cbor' ,
6363 model : 'binary' ,
6464 } ) ;
6565 await this . crud . put ( [ ...collection , id ] , STATE_FILE_NAME , blob2 , { throwIf : 'missing' } ) ;
@@ -74,7 +74,11 @@ export class LocalHistoryCrud implements LocalHistory {
7474
7575 protected async lock ( collection : string [ ] , id : string , fn : ( ) => Promise < void > ) : Promise < void > {
7676 const key = collection . join ( '/' ) + '/' + id ;
77- await this . locks . lock ( key , 250 , 500 ) ( async ( ) => {
77+ await this . locks . lock (
78+ key ,
79+ 250 ,
80+ 500 ,
81+ ) ( async ( ) => {
7882 await fn ( ) ;
7983 } ) ;
8084 }
0 commit comments