@@ -18,6 +18,7 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation-
1818 */
1919 return function ( name ) {
2020 const ID = '[A-Za-z0-9_.-]*' ;
21+ const PROPERTY_PATTERN = new RegExp ( `@@PROP:(@@ENV:(?<envvar>${ ID } )@@)?(?<name>${ ID } )@@` , 'g' ) ;
2122 const SECRET_PATTERN = new RegExp ( `@@SECRET:(@@ENV:(?<envvar>${ ID } )@@)?(?<name>${ ID } ):(?<field>${ ID } )@@` , 'g' ) ;
2223 function WdtModel ( ) {
2324 const defaultDomainName = 'base_domain' ;
@@ -102,6 +103,40 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation-
102103 }
103104 } ;
104105
106+ this . getModelPropertiesReferenceCounts = ( ) => {
107+ const propertiesMap = new Map ( ) ;
108+
109+ [ ...this . modelContent ( ) . matchAll ( PROPERTY_PATTERN ) ] . forEach ( matches => {
110+ const propertyName = matches . groups . name ;
111+ const propertyEnvVar = matches . groups . envvar ;
112+
113+ // While this key is never used outside this function, we need the key to
114+ // match the resolved property name. For example, if the DOMAIN_UID is mydomain,
115+ // the following two fields should refer to the same property:
116+ //
117+ // field1: '@@PROP:@@ENV:DOMAIN_UID@@-value@@'
118+ // field2: '@@PROP:mydomain-value@@'
119+ //
120+ let propertyKey = propertyName ;
121+ if ( propertyEnvVar ) {
122+ propertyKey = propertyName . startsWith ( '-' ) ? `${ propertyEnvVar } ${ propertyName } ` : `${ propertyEnvVar } -${ propertyName } ` ;
123+ }
124+
125+ let propertyData ;
126+ if ( propertiesMap . has ( propertyKey ) ) {
127+ propertyData = propertiesMap . get ( propertyKey ) ;
128+ propertyData . referenceCount ++ ;
129+ } else {
130+ propertyData = { name : propertyName , referenceCount : 1 } ;
131+ if ( propertyEnvVar ) {
132+ propertyData . envVar = propertyEnvVar ;
133+ }
134+ }
135+ propertiesMap . set ( propertyKey , propertyData ) ;
136+ } ) ;
137+ return [ ...propertiesMap . values ( ) ] ;
138+ }
139+
105140 // Placeholder for when multiple model files are supported so that the domain page can reliably get all
106141 // secrets in the models.
107142 //
0 commit comments