1515 */
1616import { sha3_256 } from 'js-sha3' ;
1717import * as utilities from './Utilities' ;
18+ import { idGeneratorConst } from './Utilities' ;
1819
1920export class IdGenerator {
2021 /**
@@ -34,20 +35,21 @@ export class IdGenerator {
3435 /**
3536 * Parses a unified namespace name into a path.
3637 * @param {string } name The unified namespace name.
38+ * @param {number } maxDepth The max namespace depth (network configuration, default: 3)
3739 * @returns {array<module:coders/uint64~uint64> } The namespace path.
3840 */
39- public static generateNamespacePath = ( name : string ) => {
41+ public static generateNamespacePath = ( name : string , maxDepth : number = idGeneratorConst . default_namespace_max_depth ) => {
4042 if ( 0 >= name . length ) {
4143 utilities . throwInvalidFqn ( 'having zero length' , name ) ;
4244 }
4345 let namespaceId = utilities . idGeneratorConst . namespace_base_id ;
4446 const path = [ ] ;
4547 const start = utilities . split ( name , ( substringStart , size ) => {
4648 namespaceId = utilities . generateNamespaceId ( namespaceId , utilities . extractPartName ( name , substringStart , size ) ) ;
47- utilities . append ( path , namespaceId , name ) ;
49+ utilities . append ( path , namespaceId , name , maxDepth ) ;
4850 } ) ;
4951 namespaceId = utilities . generateNamespaceId ( namespaceId , utilities . extractPartName ( name , start , name . length - start ) ) ;
50- utilities . append ( path , namespaceId , name ) ;
52+ utilities . append ( path , namespaceId , name , maxDepth ) ;
5153 return path ;
5254 }
5355}
0 commit comments