@@ -10,11 +10,13 @@ import {
1010 type ComplexTypeTypeSchema ,
1111 type ConstrainedChoiceInfo ,
1212 type Field ,
13+ type Identifier ,
1314 isChoiceDeclarationField ,
1415 isChoiceInstanceField ,
1516 isComplexTypeIdentifier ,
1617 isComplexTypeTypeSchema ,
1718 isLogicalTypeSchema ,
19+ isNestedIdentifier ,
1820 isProfileTypeSchema ,
1921 isResourceIdentifier ,
2022 isResourceTypeSchema ,
@@ -159,7 +161,8 @@ export type TypeSchemaIndex = {
159161 collectResources : ( ) => ResourceTypeSchema [ ] ;
160162 collectLogicalModels : ( ) => LogicalTypeSchema [ ] ;
161163 collectProfiles : ( ) => ProfileTypeSchema [ ] ;
162- resolve : ( id : TypeIdentifier ) => TypeSchema | undefined ;
164+ resolve : ( id : Identifier ) => TypeSchema | undefined ;
165+ resolveType : ( id : TypeIdentifier ) => TypeSchema | NestedTypeSchema | undefined ;
163166 resolveByUrl : ( pkgName : PkgName , url : CanonicalUrl ) => TypeSchema | undefined ;
164167 tryHierarchy : ( schema : TypeSchema ) => TypeSchema [ ] | undefined ;
165168 hierarchy : ( schema : TypeSchema ) => TypeSchema [ ] ;
@@ -223,11 +226,14 @@ export const mkTypeSchemaIndex = (
223226 }
224227 populateTypeFamily ( schemas ) ;
225228
226- const resolve = ( id : TypeIdentifier ) : TypeSchema | undefined => {
227- if ( id . kind === "nested" ) return nestedIndex [ id . url ] ?. [ id . package ] as unknown as TypeSchema | undefined ;
229+ const resolve = ( id : Identifier ) : TypeSchema | undefined => {
228230 return index [ id . url ] ?. [ id . package ] ;
229231 } ;
230- const resolveByUrl = ( pkgName : PkgName , url : CanonicalUrl ) => {
232+ const resolveType = ( id : TypeIdentifier ) : TypeSchema | NestedTypeSchema | undefined => {
233+ if ( isNestedIdentifier ( id ) ) return nestedIndex [ id . url ] ?. [ id . package ] ;
234+ return index [ id . url ] ?. [ id . package ] ;
235+ } ;
236+ const resolveByUrl = ( pkgName : PkgName , url : CanonicalUrl ) : TypeSchema | undefined => {
231237 if ( register ) {
232238 const resolutionTree = register . resolutionTree ( ) ;
233239 const resolution = resolutionTree [ pkgName ] ?. [ url ] ?. [ 0 ] ;
@@ -247,6 +253,13 @@ export const mkTypeSchemaIndex = (
247253 return index [ url ] ?. [ anyPkg ] ;
248254 }
249255 }
256+ if ( nestedIndex [ url ] ) {
257+ const anyPkg = Object . keys ( nestedIndex [ url ] ) [ 0 ] ;
258+ if ( anyPkg ) {
259+ logger ?. dryWarn ( `Type '${ url } ' fallback to package ${ anyPkg } ` ) ;
260+ return nestedIndex [ url ] ?. [ anyPkg ] as unknown as TypeSchema ;
261+ }
262+ }
250263 return undefined ;
251264 } ;
252265
@@ -257,6 +270,7 @@ export const mkTypeSchemaIndex = (
257270 res . push ( cur ) ;
258271 const base = ( cur as SpecializationTypeSchema ) . base ;
259272 if ( base === undefined ) break ;
273+ if ( isNestedIdentifier ( base ) ) break ;
260274 const resolved = resolve ( base ) ;
261275 if ( ! resolved ) {
262276 logger ?. warn (
@@ -287,6 +301,11 @@ export const mkTypeSchemaIndex = (
287301 } ;
288302
289303 const findLastSpecializationByIdentifier = ( id : TypeIdentifier ) : TypeIdentifier => {
304+ if ( isNestedIdentifier ( id ) ) {
305+ const resolved = resolveType ( id ) ;
306+ if ( ! resolved || ! ( "base" in resolved ) || ! resolved . base ) return id ;
307+ return findLastSpecializationByIdentifier ( resolved . base ) ;
308+ }
290309 const schema = resolve ( id ) ;
291310 if ( ! schema ) return id ;
292311 return findLastSpecialization ( schema ) . identifier ;
@@ -461,6 +480,7 @@ export const mkTypeSchemaIndex = (
461480 collectLogicalModels : ( ) => schemas . filter ( isLogicalTypeSchema ) ,
462481 collectProfiles : ( ) => schemas . filter ( isProfileTypeSchema ) ,
463482 resolve,
483+ resolveType,
464484 resolveByUrl,
465485 tryHierarchy,
466486 hierarchy,
0 commit comments