@@ -4,11 +4,14 @@ import { Component, RendererComponent } from "typedoc/dist/lib/output/components
44import { PageEvent } from "typedoc/dist/lib/output/events" ;
55import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem" ;
66
7+ /**
8+ * Group the ToC for easier observability.
9+ */
710@Component ( { name : "SdkClientTocPlugin" } )
811export class SdkClientTocPlugin extends RendererComponent {
9- private commandToNavigationItems : Map < string , NavigationItem > = new Map ( ) ;
1012 private commandsNavigationItem ?: NavigationItem ;
11- private exceptionsNavigationItem ?: NavigationItem ;
13+ private clientsNavigationItem ?: NavigationItem ;
14+ private paginatorsNavigationItem ?: NavigationItem ;
1215
1316 initialize ( ) {
1417 // disable existing toc plugin
@@ -40,36 +43,43 @@ export class SdkClientTocPlugin extends RendererComponent {
4043 page . toc = new NavigationItem ( model . name ) ;
4144
4245 if ( ! model . parent && ! trail . length ) {
46+ this . clientsNavigationItem = new NavigationItem ( "Clients" , void 0 , page . toc ) ;
4347 this . commandsNavigationItem = new NavigationItem ( "Commands" , void 0 , page . toc ) ;
44- this . exceptionsNavigationItem = new NavigationItem ( "Exceptions " , void 0 , page . toc ) ;
48+ this . paginatorsNavigationItem = new NavigationItem ( "Paginators " , void 0 , page . toc ) ;
4549 }
4650
4751 this . buildToc ( model , trail , page . toc , tocRestriction ) ;
4852 }
4953
50- private isCommand ( { implementedTypes = [ ] } : DeclarationReflection ) : boolean {
54+ private isClient ( model : DeclarationReflection ) : boolean {
55+ const { extendedTypes = [ ] } = model ;
5156 return (
52- implementedTypes . length === 1 &&
53- implementedTypes [ 0 ] . type === "reference" &&
54- ( implementedTypes [ 0 ] as ReferenceType ) . name === "Command"
57+ model . kindOf ( ReflectionKind . Class ) &&
58+ model . getFullName ( ) !== "Client" && // Exclude the Smithy Client class.
59+ ( model . name . endsWith ( "Client" ) /* Modular client like S3Client */ ||
60+ ( extendedTypes . length === 1 &&
61+ ( extendedTypes [ 0 ] as ReferenceType ) . name . endsWith ( "Client" ) ) ) /* Legacy client like S3 */
5562 ) ;
5663 }
5764
58- private isException ( model : DeclarationReflection ) : boolean {
59- const extendedTypes = model . extendedTypes || [ ] ;
65+ private isCommand ( model : DeclarationReflection ) : boolean {
6066 return (
61- extendedTypes . length === 1 &&
62- extendedTypes [ 0 ] . type === "reference" &&
63- ( extendedTypes [ 0 ] as ReferenceType ) . name === "ServiceException"
67+ model . kindOf ( ReflectionKind . Class ) &&
68+ model . getFullName ( ) !== "Command" && // Exclude the Smithy Command class.
69+ model . name . endsWith ( "Command" ) &&
70+ model . children ?. some ( ( child ) => child . name === "resolveMiddleware" )
6471 ) ;
6572 }
6673
67- private isUnion ( model : DeclarationReflection ) : boolean {
68- return model . type ?. type === "union" ;
74+ private isPaginator ( model : DeclarationReflection ) : boolean {
75+ return model . name . startsWith ( "paginate" ) && model . kindOf ( ReflectionKind . Function ) ;
6976 }
7077
7178 private isInputOrOutput ( model : DeclarationReflection ) : boolean {
72- return model . kindString === "Interface" && ( model . name . endsWith ( "Input" ) || model . name . endsWith ( "Output" ) ) ;
79+ return (
80+ model . kindOf ( ReflectionKind . TypeAlias ) &&
81+ ( model . name . endsWith ( "CommandInput" ) || model . name . endsWith ( "CommandOutput" ) )
82+ ) ;
7383 }
7484
7585 /**
@@ -92,57 +102,33 @@ export class SdkClientTocPlugin extends RendererComponent {
92102 this . buildToc ( child , trail , item ) ;
93103 } else {
94104 children . forEach ( ( child : DeclarationReflection ) => {
95- if ( restriction && restriction . length > 0 && restriction . indexOf ( child . name ) === - 1 ) {
105+ if ( restriction && restriction . length > 0 && ! restriction . includes ( child . name ) ) {
96106 return ;
97107 }
98108
99109 if ( child . kindOf ( ReflectionKind . SomeModule ) ) {
100110 return ;
101111 }
102112
103- if ( trail . length ) {
104- const item = NavigationItem . create ( child , parent , true ) ;
105- if ( trail . indexOf ( child ) !== - 1 ) {
106- item . isInPath = true ;
107- item . isCurrent = trail [ trail . length - 1 ] === child ;
108- this . buildToc ( child , trail , item ) ;
109- }
110- return ;
111- }
112-
113- if ( this . isCommand ( child ) ) {
114- const item = NavigationItem . create ( child , this . commandsNavigationItem , true ) ;
115- // create an entry for the command
116- const commandName = child . name . toLowerCase ( ) ;
117- if ( ! this . commandToNavigationItems . get ( commandName ) ) {
118- this . commandToNavigationItems . set ( commandName , item ) ;
119- }
120- } else if ( this . isException ( child ) ) {
121- NavigationItem . create ( child , this . exceptionsNavigationItem , true ) ;
122- } else if (
123- this . isUnion ( child ) &&
124- ( child as any ) . type . types . every ( ( type : ReferenceType ) => {
125- return type . reflection && this . isException ( type . reflection as DeclarationReflection ) ;
126- } )
127- ) {
128- // get command from name
129- const commandName = child . name . replace ( "ExceptionsUnion" , "" ) . toLowerCase ( ) + "command" ;
130- NavigationItem . create ( child , this . commandToNavigationItems . get ( commandName ) , true ) ;
113+ if ( this . isClient ( child ) ) {
114+ NavigationItem . create ( child , this . clientsNavigationItem , true ) ;
115+ } else if ( this . isCommand ( child ) ) {
116+ NavigationItem . create ( child , this . commandsNavigationItem , true ) ;
117+ } else if ( this . isPaginator ( child ) ) {
118+ NavigationItem . create ( child , this . paginatorsNavigationItem , true ) ;
131119 } else if ( this . isInputOrOutput ( child ) ) {
132- // get command from name
133- const commandName = child . name . replace ( / I n p u t | O u t p u t / , "" ) . toLowerCase ( ) + "command" ;
134- NavigationItem . create ( child , this . commandToNavigationItems . get ( commandName ) , true ) ;
135- } else if ( child . name . startsWith ( "_" ) ) {
136- return ;
120+ NavigationItem . create ( child , this . commandsNavigationItem , true ) ;
137121 } else {
138122 const item = NavigationItem . create ( child , parent , true ) ;
139- if ( trail . indexOf ( child ) !== - 1 ) {
123+ if ( trail . includes ( child ) ) {
140124 item . isInPath = true ;
141125 item . isCurrent = trail [ trail . length - 1 ] === child ;
142126 this . buildToc ( child , trail , item ) ;
143127 }
144128 }
145129 } ) ;
130+ // Group commands and input/output interface of each command.
131+ this . commandsNavigationItem ?. children . sort ( ( childA , childB ) => childA . title . localeCompare ( childB . title ) ) ;
146132 }
147133 }
148134}
0 commit comments