This repository was archived by the owner on Mar 23, 2023. It is now read-only.
Commit 59081a7 1 parent 71439b9 commit 59081a7 Copy full SHA for 59081a7
File tree 1 file changed +12
-10
lines changed
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 {
54
54
return Key . withNamespaces ( key . list ( ) . slice ( 1 ) )
55
55
}
56
56
57
- static async create ( store : Datastore , shard : Shard ) : Promise < Shard > {
57
+ static async create ( store : Datastore , shard ? : Shard ) : Promise < Shard > {
58
58
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
+
62
60
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
+ }
68
67
69
- return shard
68
+ if ( shard == null ) {
69
+ shard = await readShardFun ( '/' , store )
70
70
}
71
71
72
72
// test shards
73
73
const diskShard = await readShardFun ( '/' , store )
74
74
const a = diskShard . toString ( )
75
75
const b = shard . toString ( )
76
+
76
77
if ( a !== b ) {
77
78
throw new Error ( `specified fun ${ b } does not match repo shard fun ${ a } ` )
78
79
}
80
+
79
81
return diskShard
80
82
}
81
83
You can’t perform that action at this time.
0 commit comments