@@ -78,43 +78,38 @@ writer.finish():
78
78
*/
79
79
export class CredentialStatusWriter {
80
80
constructor ( {
81
- documentLoader, documentStore ,
82
- issuer, statusListConfig , suite
81
+ statusListConfig , documentLoader, edvClient ,
82
+ issuer, suite
83
83
} = { } ) {
84
+ assert . object ( statusListConfig , 'statusListConfig' ) ;
84
85
assert . func ( documentLoader , 'documentLoader' ) ;
85
- // FIXME: use `edvClient` directly
86
- assert . object ( documentStore , 'documentStore' ) ;
86
+ assert . object ( edvClient , 'edvClient' ) ;
87
87
assert . string ( issuer , 'issuer' ) ;
88
- assert . object ( statusListConfig , 'statusListConfig' ) ;
89
88
assert . object ( suite , 'suite' ) ;
90
89
if ( ! issuer ) {
91
90
throw new TypeError ( '"issuer" must be a non-empty string.' ) ;
92
91
}
92
+ this . statusListConfig = statusListConfig ;
93
93
this . documentLoader = documentLoader ;
94
- this . documentStore = documentStore ;
94
+ this . edvClient = edvClient ;
95
95
this . issuer = issuer ;
96
- this . statusListConfig = statusListConfig ;
97
96
this . suite = suite ;
98
97
this . listShard = null ;
99
98
}
100
99
101
100
async write ( { credential} = { } ) {
102
101
assert . object ( credential , 'credential' ) ;
103
102
104
- const { documentStore : { serviceObjectId} , statusListConfig} = this ;
105
- let shardQueue = SHARD_QUEUE_CACHE . get ( serviceObjectId ) ;
103
+ const { edvClient, statusListConfig, listShard} = this ;
104
+ const { indexAllocator} = statusListConfig ;
105
+ let shardQueue = SHARD_QUEUE_CACHE . get ( indexAllocator ) ;
106
106
if ( ! shardQueue ) {
107
107
shardQueue = [ ] ;
108
- SHARD_QUEUE_CACHE . set ( serviceObjectId , shardQueue ) ;
108
+ SHARD_QUEUE_CACHE . set ( indexAllocator , shardQueue ) ;
109
109
}
110
110
111
- // get `edvClient` directly; do not use cache in `documentStore` to ensure
112
- // latest docs are used
113
- const { documentStore : { edvClient} } = this ;
114
-
115
111
// 1. If an LS has been assigned to the writer instance (then a duplicate
116
112
// error for the VC is being handled):
117
- const { listShard} = this ;
118
113
let existingCredentialStatus ;
119
114
if ( listShard ) {
120
115
// FIXME: might be multiple `credentialStatus` results for a given
@@ -183,13 +178,11 @@ export class CredentialStatusWriter {
183
178
if ( shardQueue . length === 0 ) {
184
179
// 2.1. Create a ListManager instance `listManager`.
185
180
// 2.2. Call listManager.getShard() and store result in the instance.
186
- const { documentLoader, documentStore, issuer, suite} = this ;
187
- // pass `edvClient` directly; do not use cache in `documentStore` to
188
- // ensure latest docs are used in list management
181
+ const { documentLoader, edvClient, issuer, suite} = this ;
189
182
const listManager = new ListManager ( {
190
183
statusListConfig,
191
184
documentLoader,
192
- edvClient : documentStore . edvClient ,
185
+ edvClient,
193
186
issuer,
194
187
suite
195
188
} ) ;
@@ -222,17 +215,13 @@ export class CredentialStatusWriter {
222
215
}
223
216
224
217
async finish ( ) {
225
- const { listShard} = this ;
218
+ const { edvClient , listShard} = this ;
226
219
if ( ! listShard ) {
227
220
// `finish` should never be called when no `listShard` is available
228
221
throw new Error (
229
222
'Invalid state error; "finish()" must only be called after "write()".' ) ;
230
223
}
231
224
232
- // get `edvClient` directly; do not use cache in `documentStore` to ensure
233
- // latest docs are used
234
- const { documentStore : { edvClient, serviceObjectId} } = this ;
235
-
236
225
// 1. Increment instance's IAD's latest index value.
237
226
const {
238
227
indexAssignmentDoc,
@@ -282,10 +271,11 @@ export class CredentialStatusWriter {
282
271
}
283
272
} else {
284
273
// 4. Otherwise, add LS back to in-memory set.
285
- let shardQueue = SHARD_QUEUE_CACHE . get ( serviceObjectId ) ;
274
+ const { statusListConfig : { indexAllocator} } = this ;
275
+ let shardQueue = SHARD_QUEUE_CACHE . get ( indexAllocator ) ;
286
276
if ( ! shardQueue ) {
287
277
shardQueue = [ ] ;
288
- SHARD_QUEUE_CACHE . set ( serviceObjectId , shardQueue ) ;
278
+ SHARD_QUEUE_CACHE . set ( indexAllocator , shardQueue ) ;
289
279
}
290
280
shardQueue . push ( listShard ) ;
291
281
}
@@ -297,7 +287,7 @@ export class CredentialStatusWriter {
297
287
assert . object ( statusMeta , 'statusMeta' ) ;
298
288
// check every `statusMeta`'s `credentialStatus.id` for duplicates
299
289
const counts = await Promise . all ( statusMeta . map (
300
- async ( { credentialStatus} ) => this . documentStore . edvClient . count ( {
290
+ async ( { credentialStatus} ) => this . edvClient . count ( {
301
291
equals : { 'meta.credentialStatus.id' : credentialStatus . id }
302
292
} ) ) ) ;
303
293
return counts . some ( count => count !== 0 ) ;
0 commit comments