@@ -152,25 +152,51 @@ export function isXmsResource(schema: any) {
152
152
153
153
export function isSchemaEqual ( a : any , b : any ) : boolean {
154
154
if ( a && b ) {
155
- const propsA = Object . getOwnPropertyNames ( a ) ;
156
- const propsB = Object . getOwnPropertyNames ( b ) ;
155
+ const propsA = Object . getOwnPropertyNames ( a )
156
+ const propsB = Object . getOwnPropertyNames ( b )
157
157
if ( propsA . length === propsB . length ) {
158
158
for ( let i = 0 ; i < propsA . length ; i ++ ) {
159
- const propsAName = propsA [ i ] ;
160
- const [ propA , propB ] = [ a [ propsAName ] , b [ propsAName ] ] ;
159
+ const propsAName = propsA [ i ]
160
+ const [ propA , propB ] = [ a [ propsAName ] , b [ propsAName ] ]
161
161
if ( typeof propA === "object" ) {
162
162
if ( ! isSchemaEqual ( propA , propB ) ) {
163
- return false ;
163
+ return false
164
164
} else if ( i === propsA . length - 1 ) {
165
- return true ;
165
+ return true
166
166
}
167
167
} else if ( propA !== propB ) {
168
- return false ;
168
+ return false
169
169
} else if ( propA === propB && i === propsA . length - 1 ) {
170
- return true ;
170
+ return true
171
171
}
172
172
}
173
173
}
174
174
}
175
- return false ;
175
+ return false
176
+ }
177
+
178
+ const providerAndNamespace = "/providers/[^/]+"
179
+ const resourceTypeAndResourceName = "(?:/\\w+/default|/\\w+/{[^/]+})"
180
+ const queryParam = "(?:\\?\\w+)"
181
+ const resourcePathRegEx = new RegExp ( `${ providerAndNamespace } ${ resourceTypeAndResourceName } +${ queryParam } ?$` , "gi" )
182
+ export function getResourcesPathHierarchyBasedOnResourceType ( path : string ) {
183
+ const index = path . lastIndexOf ( "/providers/" )
184
+ if ( index === - 1 ) {
185
+ return [ ]
186
+ }
187
+ const lastProvider = path . substr ( index )
188
+ const result = [ ]
189
+ const matches = lastProvider . match ( resourcePathRegEx )
190
+ if ( matches && matches . length ) {
191
+ const match = matches [ 0 ]
192
+ // slice the array to remove 'providers', provider namespace
193
+ const resourcePathSegments = match . split ( "/" ) . slice ( 3 )
194
+ for ( const resourcePathSegment of resourcePathSegments ) {
195
+ if ( resourcePathSegment . startsWith ( "{" ) || resourcePathSegment === "default" ) {
196
+ continue
197
+ }
198
+ result . push ( resourcePathSegment )
199
+ }
200
+ }
201
+ return result
176
202
}
0 commit comments