@@ -7,7 +7,7 @@ import type { Ref } from '../types';
77
88import { Mutex } from 'async-mutex' ;
99import Logger from '@matrixai/logger' ;
10- import { utils as idUtils } from '@matrixai/id' ;
10+ import { IdInternal , utils as idUtils } from '@matrixai/id' ;
1111import {
1212 CreateDestroyStartStop ,
1313 ready ,
@@ -130,8 +130,16 @@ class ACL {
130130 nodeId2 : NodeId ,
131131 ) : Promise < boolean > {
132132 return await this . _transaction ( async ( ) => {
133- const permId1 = await this . db . get ( this . aclNodesDbDomain , nodeId1 , true ) ;
134- const permId2 = await this . db . get ( this . aclNodesDbDomain , nodeId2 , true ) ;
133+ const permId1 = await this . db . get (
134+ this . aclNodesDbDomain ,
135+ nodeId1 . toBuffer ( ) ,
136+ true ,
137+ ) ;
138+ const permId2 = await this . db . get (
139+ this . aclNodesDbDomain ,
140+ nodeId2 . toBuffer ( ) ,
141+ true ,
142+ ) ;
135143 if ( permId1 != null && permId2 != null && permId1 === permId2 ) {
136144 return true ;
137145 }
@@ -147,7 +155,7 @@ class ACL {
147155 Record < NodeId , Permission >
148156 > = { } ;
149157 for await ( const o of this . aclNodesDb . createReadStream ( ) ) {
150- const nodeId = ( o as any ) . key as NodeId ;
158+ const nodeId = IdInternal . create < NodeId > ( ( o as any ) . key ) ;
151159 const data = ( o as any ) . value as Buffer ;
152160 const permId = makePermissionId (
153161 await this . db . deserializeDecrypt ( data , true ) ,
@@ -196,15 +204,16 @@ class ACL {
196204 ) ;
197205 const nodePerm : Record < NodeId , Permission > = { } ;
198206 const nodeIdsGc : Set < NodeId > = new Set ( ) ;
199- for ( const nodeId in nodeIds ) {
207+ for ( const nodeIdString in nodeIds ) {
208+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ;
200209 const permId = await this . db . get (
201210 this . aclNodesDbDomain ,
202- nodeId as NodeId ,
211+ nodeId . toBuffer ( ) ,
203212 true ,
204213 ) ;
205214 if ( permId == null ) {
206215 // Invalid node id
207- nodeIdsGc . add ( nodeId as NodeId ) ;
216+ nodeIdsGc . add ( nodeId ) ;
208217 continue ;
209218 }
210219 const permRef = ( await this . db . get (
@@ -213,7 +222,7 @@ class ACL {
213222 ) ) as Ref < Permission > ;
214223 if ( ! ( vaultId in permRef . object . vaults ) ) {
215224 // Vault id is missing from the perm
216- nodeIdsGc . add ( nodeId as NodeId ) ;
225+ nodeIdsGc . add ( nodeId ) ;
217226 continue ;
218227 }
219228 nodePerm [ nodeId ] = permRef . object ;
@@ -244,7 +253,11 @@ class ACL {
244253 @ready ( new aclErrors . ErrorACLNotRunning ( ) )
245254 public async getNodePerm ( nodeId : NodeId ) : Promise < Permission | undefined > {
246255 return await this . _transaction ( async ( ) => {
247- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
256+ const permId = await this . db . get (
257+ this . aclNodesDbDomain ,
258+ nodeId . toBuffer ( ) ,
259+ true ,
260+ ) ;
248261 if ( permId == null ) {
249262 return ;
250263 }
@@ -275,15 +288,16 @@ class ACL {
275288 }
276289 const perms : Record < NodeId , Permission > = { } ;
277290 const nodeIdsGc : Set < NodeId > = new Set ( ) ;
278- for ( const nodeId in nodeIds ) {
291+ for ( const nodeIdString in nodeIds ) {
292+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ;
279293 const permId = await this . db . get (
280294 this . aclNodesDbDomain ,
281- nodeId as NodeId ,
295+ nodeId . toBuffer ( ) ,
282296 true ,
283297 ) ;
284298 if ( permId == null ) {
285299 // Invalid node id
286- nodeIdsGc . add ( nodeId as NodeId ) ;
300+ nodeIdsGc . add ( nodeId ) ;
287301 continue ;
288302 }
289303 const permRef = ( await this . db . get (
@@ -292,7 +306,7 @@ class ACL {
292306 ) ) as Ref < Permission > ;
293307 if ( ! ( vaultId in permRef . object . vaults ) ) {
294308 // Vault id is missing from the perm
295- nodeIdsGc . add ( nodeId as NodeId ) ;
309+ nodeIdsGc . add ( nodeId ) ;
296310 continue ;
297311 }
298312 perms [ nodeId ] = permRef . object ;
@@ -318,7 +332,11 @@ class ACL {
318332 action : GestaltAction ,
319333 ) : Promise < void > {
320334 return await this . _transaction ( async ( ) => {
321- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
335+ const permId = await this . db . get (
336+ this . aclNodesDbDomain ,
337+ nodeId . toBuffer ( ) ,
338+ true ,
339+ ) ;
322340 const ops : Array < DBOp > = [ ] ;
323341 if ( permId == null ) {
324342 const permId = await aclUtils . generatePermId ( ) ;
@@ -341,7 +359,7 @@ class ACL {
341359 {
342360 type : 'put' ,
343361 domain : this . aclNodesDbDomain ,
344- key : nodeId ,
362+ key : nodeId . toBuffer ( ) ,
345363 value : idUtils . toBuffer ( permId ) ,
346364 raw : true ,
347365 } ,
@@ -369,7 +387,11 @@ class ACL {
369387 action : GestaltAction ,
370388 ) : Promise < void > {
371389 return await this . _transaction ( async ( ) => {
372- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
390+ const permId = await this . db . get (
391+ this . aclNodesDbDomain ,
392+ nodeId . toBuffer ( ) ,
393+ true ,
394+ ) ;
373395 if ( permId == null ) {
374396 return ;
375397 }
@@ -394,7 +416,11 @@ class ACL {
394416 this . aclVaultsDbDomain ,
395417 idUtils . toBuffer ( vaultId ) ,
396418 ) ) ?? { } ;
397- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
419+ const permId = await this . db . get (
420+ this . aclNodesDbDomain ,
421+ nodeId . toBuffer ( ) ,
422+ true ,
423+ ) ;
398424 if ( permId == null ) {
399425 throw new aclErrors . ErrorACLNodeIdMissing ( ) ;
400426 }
@@ -419,7 +445,7 @@ class ACL {
419445 {
420446 type : 'put' ,
421447 domain : this . aclNodesDbDomain ,
422- key : nodeId ,
448+ key : nodeId . toBuffer ( ) ,
423449 value : permId ,
424450 raw : true ,
425451 } ,
@@ -448,7 +474,11 @@ class ACL {
448474 if ( nodeIds == null || ! ( nodeId in nodeIds ) ) {
449475 return ;
450476 }
451- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
477+ const permId = await this . db . get (
478+ this . aclNodesDbDomain ,
479+ nodeId . toBuffer ( ) ,
480+ true ,
481+ ) ;
452482 if ( permId == null ) {
453483 return ;
454484 }
@@ -491,7 +521,7 @@ class ACL {
491521 for ( const nodeId of nodeIds ) {
492522 const permIdBuffer = await this . db . get (
493523 this . aclNodesDbDomain ,
494- nodeId ,
524+ nodeId . toBuffer ( ) ,
495525 true ,
496526 ) ;
497527 if ( permIdBuffer == null ) {
@@ -537,7 +567,7 @@ class ACL {
537567 ops . push ( {
538568 domain : this . aclNodesDbDomain ,
539569 type : 'put' ,
540- key : nodeId ,
570+ key : nodeId . toBuffer ( ) ,
541571 value : idUtils . toBuffer ( permId ) ,
542572 raw : true ,
543573 } ) ;
@@ -558,7 +588,11 @@ class ACL {
558588 nodeId : NodeId ,
559589 perm : Permission ,
560590 ) : Promise < Array < DBOp > > {
561- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
591+ const permId = await this . db . get (
592+ this . aclNodesDbDomain ,
593+ nodeId . toBuffer ( ) ,
594+ true ,
595+ ) ;
562596 const ops : Array < DBOp > = [ ] ;
563597 if ( permId == null ) {
564598 const permId = await aclUtils . generatePermId ( ) ;
@@ -576,7 +610,7 @@ class ACL {
576610 {
577611 type : 'put' ,
578612 domain : this . aclNodesDbDomain ,
579- key : nodeId ,
613+ key : nodeId . toBuffer ( ) ,
580614 value : idUtils . toBuffer ( permId ) ,
581615 raw : true ,
582616 } ,
@@ -608,7 +642,11 @@ class ACL {
608642
609643 @ready ( new aclErrors . ErrorACLNotRunning ( ) )
610644 public async unsetNodePermOps ( nodeId : NodeId ) : Promise < Array < DBOp > > {
611- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
645+ const permId = await this . db . get (
646+ this . aclNodesDbDomain ,
647+ nodeId . toBuffer ( ) ,
648+ true ,
649+ ) ;
612650 if ( permId == null ) {
613651 return [ ] ;
614652 }
@@ -635,7 +673,7 @@ class ACL {
635673 ops . push ( {
636674 type : 'del' ,
637675 domain : this . aclNodesDbDomain ,
638- key : nodeId ,
676+ key : nodeId . toBuffer ( ) ,
639677 } ) ;
640678 // We do not remove the node id from the vaults
641679 // they can be removed later upon inspection
@@ -653,10 +691,11 @@ class ACL {
653691 return ;
654692 }
655693 const ops : Array < DBOp > = [ ] ;
656- for ( const nodeId in nodeIds ) {
694+ for ( const nodeIdString in nodeIds ) {
695+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ;
657696 const permId = await this . db . get (
658697 this . aclNodesDbDomain ,
659- nodeId as NodeId ,
698+ nodeId . toBuffer ( ) ,
660699 true ,
661700 ) ;
662701 // Skip if the nodeId doesn't exist
@@ -703,7 +742,11 @@ class ACL {
703742 nodeIdsJoin : Array < NodeId > ,
704743 perm ?: Permission ,
705744 ) : Promise < Array < DBOp > > {
706- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
745+ const permId = await this . db . get (
746+ this . aclNodesDbDomain ,
747+ nodeId . toBuffer ( ) ,
748+ true ,
749+ ) ;
707750 if ( permId == null ) {
708751 throw new aclErrors . ErrorACLNodeIdMissing ( ) ;
709752 }
@@ -719,7 +762,7 @@ class ACL {
719762 for ( const nodeIdJoin of nodeIdsJoin ) {
720763 const permIdJoin = await this . db . get (
721764 this . aclNodesDbDomain ,
722- nodeIdJoin ,
765+ nodeIdJoin . toBuffer ( ) ,
723766 true ,
724767 ) ;
725768 if ( permIdJoin === permId ) {
@@ -750,7 +793,7 @@ class ACL {
750793 ops . push ( {
751794 type : 'put' ,
752795 domain : this . aclNodesDbDomain ,
753- key : nodeIdJoin ,
796+ key : nodeIdJoin . toBuffer ( ) ,
754797 value : permId ,
755798 raw : true ,
756799 } ) ;
@@ -789,15 +832,16 @@ class ACL {
789832 }
790833 const ops : Array < DBOp > = [ ] ;
791834 const nodeIdsGc : Set < NodeId > = new Set ( ) ;
792- for ( const nodeId in nodeIds ) {
835+ for ( const nodeIdString in nodeIds ) {
836+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ;
793837 const permId = await this . db . get (
794838 this . aclNodesDbDomain ,
795- nodeId as NodeId ,
839+ nodeId . toBuffer ( ) ,
796840 true ,
797841 ) ;
798842 if ( permId == null ) {
799843 // Invalid node id
800- nodeIdsGc . add ( nodeId as NodeId ) ;
844+ nodeIdsGc . add ( nodeId ) ;
801845 continue ;
802846 }
803847 const permRef = ( await this . db . get (
@@ -806,7 +850,7 @@ class ACL {
806850 ) ) as Ref < Permission > ;
807851 if ( ! ( vaultId in permRef . object . vaults ) ) {
808852 // Vault id is missing from the perm
809- nodeIdsGc . add ( nodeId as NodeId ) ;
853+ nodeIdsGc . add ( nodeId ) ;
810854 continue ;
811855 }
812856 const vaultActions : VaultActions | undefined =
0 commit comments