This repository was archived by the owner on Mar 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -54,28 +54,30 @@ export class ShardingDatastore extends BaseDatastore {
5454 return Key . withNamespaces ( key . list ( ) . slice ( 1 ) )
5555 }
5656
57- static async create ( store : Datastore , shard : Shard ) : Promise < Shard > {
57+ static async create ( store : Datastore , shard ? : Shard ) : Promise < Shard > {
5858 const hasShard = await store . has ( shardKey )
59- if ( ! hasShard && shard == null ) {
60- throw Errors . dbOpenFailedError ( Error ( 'Shard is required when datastore doesn\'t have a shard key already.' ) )
61- }
59+
6260 if ( ! hasShard ) {
63- // @ts -expect-error i have no idea what putRaw is or saw any implementation
64- const put = typeof store . putRaw === 'function' ? store . putRaw . bind ( store ) : store . put . bind ( store )
65- await Promise . all ( [
66- put ( shardKey , new TextEncoder ( ) . encode ( shard . toString ( ) + '\n' ) )
67- ] )
61+ if ( shard == null ) {
62+ throw Errors . dbOpenFailedError ( Error ( 'Shard is required when datastore doesn\'t have a shard key already.' ) )
63+ }
64+
65+ await store . put ( shardKey , new TextEncoder ( ) . encode ( shard . toString ( ) + '\n' ) )
66+ }
6867
69- return shard
68+ if ( shard == null ) {
69+ shard = await readShardFun ( '/' , store )
7070 }
7171
7272 // test shards
7373 const diskShard = await readShardFun ( '/' , store )
7474 const a = diskShard . toString ( )
7575 const b = shard . toString ( )
76+
7677 if ( a !== b ) {
7778 throw new Error ( `specified fun ${ b } does not match repo shard fun ${ a } ` )
7879 }
80+
7981 return diskShard
8082 }
8183
You can’t perform that action at this time.
0 commit comments