@@ -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 . fromString < 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,17 @@ 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+ // FIXME: check why and what string nodeId is.
209+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ! ;
200210 const permId = await this . db . get (
201211 this . aclNodesDbDomain ,
202- nodeId as NodeId ,
212+ nodeId . toBuffer ( ) ,
203213 true ,
204214 ) ;
205215 if ( permId == null ) {
206216 // Invalid node id
207- nodeIdsGc . add ( nodeId as NodeId ) ;
217+ nodeIdsGc . add ( nodeId ) ;
208218 continue ;
209219 }
210220 const permRef = ( await this . db . get (
@@ -213,7 +223,7 @@ class ACL {
213223 ) ) as Ref < Permission > ;
214224 if ( ! ( vaultId in permRef . object . vaults ) ) {
215225 // Vault id is missing from the perm
216- nodeIdsGc . add ( nodeId as NodeId ) ;
226+ nodeIdsGc . add ( nodeId ) ;
217227 continue ;
218228 }
219229 nodePerm [ nodeId ] = permRef . object ;
@@ -244,7 +254,11 @@ class ACL {
244254 @ready ( new aclErrors . ErrorACLNotRunning ( ) )
245255 public async getNodePerm ( nodeId : NodeId ) : Promise < Permission | undefined > {
246256 return await this . _transaction ( async ( ) => {
247- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
257+ const permId = await this . db . get (
258+ this . aclNodesDbDomain ,
259+ nodeId . toBuffer ( ) ,
260+ true ,
261+ ) ;
248262 if ( permId == null ) {
249263 return ;
250264 }
@@ -275,15 +289,16 @@ class ACL {
275289 }
276290 const perms : Record < NodeId , Permission > = { } ;
277291 const nodeIdsGc : Set < NodeId > = new Set ( ) ;
278- for ( const nodeId in nodeIds ) {
292+ for ( const nodeIdString in nodeIds ) {
293+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ! ;
279294 const permId = await this . db . get (
280295 this . aclNodesDbDomain ,
281- nodeId as NodeId ,
296+ nodeId . toBuffer ( ) ,
282297 true ,
283298 ) ;
284299 if ( permId == null ) {
285300 // Invalid node id
286- nodeIdsGc . add ( nodeId as NodeId ) ;
301+ nodeIdsGc . add ( nodeId ) ;
287302 continue ;
288303 }
289304 const permRef = ( await this . db . get (
@@ -292,7 +307,7 @@ class ACL {
292307 ) ) as Ref < Permission > ;
293308 if ( ! ( vaultId in permRef . object . vaults ) ) {
294309 // Vault id is missing from the perm
295- nodeIdsGc . add ( nodeId as NodeId ) ;
310+ nodeIdsGc . add ( nodeId ) ;
296311 continue ;
297312 }
298313 perms [ nodeId ] = permRef . object ;
@@ -318,7 +333,11 @@ class ACL {
318333 action : GestaltAction ,
319334 ) : Promise < void > {
320335 return await this . _transaction ( async ( ) => {
321- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
336+ const permId = await this . db . get (
337+ this . aclNodesDbDomain ,
338+ nodeId . toBuffer ( ) ,
339+ true ,
340+ ) ;
322341 const ops : Array < DBOp > = [ ] ;
323342 if ( permId == null ) {
324343 const permId = await aclUtils . generatePermId ( ) ;
@@ -341,7 +360,7 @@ class ACL {
341360 {
342361 type : 'put' ,
343362 domain : this . aclNodesDbDomain ,
344- key : nodeId ,
363+ key : nodeId . toBuffer ( ) ,
345364 value : idUtils . toBuffer ( permId ) ,
346365 raw : true ,
347366 } ,
@@ -369,7 +388,11 @@ class ACL {
369388 action : GestaltAction ,
370389 ) : Promise < void > {
371390 return await this . _transaction ( async ( ) => {
372- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
391+ const permId = await this . db . get (
392+ this . aclNodesDbDomain ,
393+ nodeId . toBuffer ( ) ,
394+ true ,
395+ ) ;
373396 if ( permId == null ) {
374397 return ;
375398 }
@@ -394,7 +417,11 @@ class ACL {
394417 this . aclVaultsDbDomain ,
395418 idUtils . toBuffer ( vaultId ) ,
396419 ) ) ?? { } ;
397- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
420+ const permId = await this . db . get (
421+ this . aclNodesDbDomain ,
422+ nodeId . toBuffer ( ) ,
423+ true ,
424+ ) ;
398425 if ( permId == null ) {
399426 throw new aclErrors . ErrorACLNodeIdMissing ( ) ;
400427 }
@@ -419,7 +446,7 @@ class ACL {
419446 {
420447 type : 'put' ,
421448 domain : this . aclNodesDbDomain ,
422- key : nodeId ,
449+ key : nodeId . toBuffer ( ) ,
423450 value : permId ,
424451 raw : true ,
425452 } ,
@@ -448,7 +475,11 @@ class ACL {
448475 if ( nodeIds == null || ! ( nodeId in nodeIds ) ) {
449476 return ;
450477 }
451- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
478+ const permId = await this . db . get (
479+ this . aclNodesDbDomain ,
480+ nodeId . toBuffer ( ) ,
481+ true ,
482+ ) ;
452483 if ( permId == null ) {
453484 return ;
454485 }
@@ -491,7 +522,7 @@ class ACL {
491522 for ( const nodeId of nodeIds ) {
492523 const permIdBuffer = await this . db . get (
493524 this . aclNodesDbDomain ,
494- nodeId ,
525+ nodeId . toBuffer ( ) ,
495526 true ,
496527 ) ;
497528 if ( permIdBuffer == null ) {
@@ -537,7 +568,7 @@ class ACL {
537568 ops . push ( {
538569 domain : this . aclNodesDbDomain ,
539570 type : 'put' ,
540- key : nodeId ,
571+ key : nodeId . toBuffer ( ) ,
541572 value : idUtils . toBuffer ( permId ) ,
542573 raw : true ,
543574 } ) ;
@@ -558,7 +589,11 @@ class ACL {
558589 nodeId : NodeId ,
559590 perm : Permission ,
560591 ) : Promise < Array < DBOp > > {
561- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
592+ const permId = await this . db . get (
593+ this . aclNodesDbDomain ,
594+ nodeId . toBuffer ( ) ,
595+ true ,
596+ ) ;
562597 const ops : Array < DBOp > = [ ] ;
563598 if ( permId == null ) {
564599 const permId = await aclUtils . generatePermId ( ) ;
@@ -576,7 +611,7 @@ class ACL {
576611 {
577612 type : 'put' ,
578613 domain : this . aclNodesDbDomain ,
579- key : nodeId ,
614+ key : nodeId . toBuffer ( ) ,
580615 value : idUtils . toBuffer ( permId ) ,
581616 raw : true ,
582617 } ,
@@ -608,7 +643,11 @@ class ACL {
608643
609644 @ready ( new aclErrors . ErrorACLNotRunning ( ) )
610645 public async unsetNodePermOps ( nodeId : NodeId ) : Promise < Array < DBOp > > {
611- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
646+ const permId = await this . db . get (
647+ this . aclNodesDbDomain ,
648+ nodeId . toBuffer ( ) ,
649+ true ,
650+ ) ;
612651 if ( permId == null ) {
613652 return [ ] ;
614653 }
@@ -635,7 +674,7 @@ class ACL {
635674 ops . push ( {
636675 type : 'del' ,
637676 domain : this . aclNodesDbDomain ,
638- key : nodeId ,
677+ key : nodeId . toBuffer ( ) ,
639678 } ) ;
640679 // We do not remove the node id from the vaults
641680 // they can be removed later upon inspection
@@ -653,10 +692,11 @@ class ACL {
653692 return ;
654693 }
655694 const ops : Array < DBOp > = [ ] ;
656- for ( const nodeId in nodeIds ) {
695+ for ( const nodeIdString in nodeIds ) {
696+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ! ;
657697 const permId = await this . db . get (
658698 this . aclNodesDbDomain ,
659- nodeId as NodeId ,
699+ nodeId . toBuffer ( ) ,
660700 true ,
661701 ) ;
662702 // Skip if the nodeId doesn't exist
@@ -703,7 +743,11 @@ class ACL {
703743 nodeIdsJoin : Array < NodeId > ,
704744 perm ?: Permission ,
705745 ) : Promise < Array < DBOp > > {
706- const permId = await this . db . get ( this . aclNodesDbDomain , nodeId , true ) ;
746+ const permId = await this . db . get (
747+ this . aclNodesDbDomain ,
748+ nodeId . toBuffer ( ) ,
749+ true ,
750+ ) ;
707751 if ( permId == null ) {
708752 throw new aclErrors . ErrorACLNodeIdMissing ( ) ;
709753 }
@@ -719,7 +763,7 @@ class ACL {
719763 for ( const nodeIdJoin of nodeIdsJoin ) {
720764 const permIdJoin = await this . db . get (
721765 this . aclNodesDbDomain ,
722- nodeIdJoin ,
766+ nodeIdJoin . toBuffer ( ) ,
723767 true ,
724768 ) ;
725769 if ( permIdJoin === permId ) {
@@ -750,7 +794,7 @@ class ACL {
750794 ops . push ( {
751795 type : 'put' ,
752796 domain : this . aclNodesDbDomain ,
753- key : nodeIdJoin ,
797+ key : nodeIdJoin . toBuffer ( ) ,
754798 value : permId ,
755799 raw : true ,
756800 } ) ;
@@ -789,15 +833,16 @@ class ACL {
789833 }
790834 const ops : Array < DBOp > = [ ] ;
791835 const nodeIdsGc : Set < NodeId > = new Set ( ) ;
792- for ( const nodeId in nodeIds ) {
836+ for ( const nodeIdString in nodeIds ) {
837+ const nodeId : NodeId = IdInternal . fromString ( nodeIdString ) ! ;
793838 const permId = await this . db . get (
794839 this . aclNodesDbDomain ,
795- nodeId as NodeId ,
840+ nodeId . toBuffer ( ) ,
796841 true ,
797842 ) ;
798843 if ( permId == null ) {
799844 // Invalid node id
800- nodeIdsGc . add ( nodeId as NodeId ) ;
845+ nodeIdsGc . add ( nodeId ) ;
801846 continue ;
802847 }
803848 const permRef = ( await this . db . get (
@@ -806,7 +851,7 @@ class ACL {
806851 ) ) as Ref < Permission > ;
807852 if ( ! ( vaultId in permRef . object . vaults ) ) {
808853 // Vault id is missing from the perm
809- nodeIdsGc . add ( nodeId as NodeId ) ;
854+ nodeIdsGc . add ( nodeId ) ;
810855 continue ;
811856 }
812857 const vaultActions : VaultActions | undefined =
0 commit comments