@@ -4,11 +4,14 @@ import { Component, RendererComponent } from "typedoc/dist/lib/output/components
4
4
import { PageEvent } from "typedoc/dist/lib/output/events" ;
5
5
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem" ;
6
6
7
+ /**
8
+ * Group the ToC for easier observability.
9
+ */
7
10
@Component ( { name : "SdkClientTocPlugin" } )
8
11
export class SdkClientTocPlugin extends RendererComponent {
9
- private commandToNavigationItems : Map < string , NavigationItem > = new Map ( ) ;
10
12
private commandsNavigationItem ?: NavigationItem ;
11
- private exceptionsNavigationItem ?: NavigationItem ;
13
+ private clientsNavigationItem ?: NavigationItem ;
14
+ private paginatorsNavigationItem ?: NavigationItem ;
12
15
13
16
initialize ( ) {
14
17
// disable existing toc plugin
@@ -40,36 +43,43 @@ export class SdkClientTocPlugin extends RendererComponent {
40
43
page . toc = new NavigationItem ( model . name ) ;
41
44
42
45
if ( ! model . parent && ! trail . length ) {
46
+ this . clientsNavigationItem = new NavigationItem ( "Clients" , void 0 , page . toc ) ;
43
47
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 ) ;
45
49
}
46
50
47
51
this . buildToc ( model , trail , page . toc , tocRestriction ) ;
48
52
}
49
53
50
- private isCommand ( { implementedTypes = [ ] } : DeclarationReflection ) : boolean {
54
+ private isClient ( model : DeclarationReflection ) : boolean {
55
+ const { extendedTypes = [ ] } = model ;
51
56
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 */
55
62
) ;
56
63
}
57
64
58
- private isException ( model : DeclarationReflection ) : boolean {
59
- const extendedTypes = model . extendedTypes || [ ] ;
65
+ private isCommand ( model : DeclarationReflection ) : boolean {
60
66
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" )
64
71
) ;
65
72
}
66
73
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 ) ;
69
76
}
70
77
71
78
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
+ ) ;
73
83
}
74
84
75
85
/**
@@ -92,57 +102,33 @@ export class SdkClientTocPlugin extends RendererComponent {
92
102
this . buildToc ( child , trail , item ) ;
93
103
} else {
94
104
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 ) ) {
96
106
return ;
97
107
}
98
108
99
109
if ( child . kindOf ( ReflectionKind . SomeModule ) ) {
100
110
return ;
101
111
}
102
112
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 ) ;
131
119
} 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 ) ;
137
121
} else {
138
122
const item = NavigationItem . create ( child , parent , true ) ;
139
- if ( trail . indexOf ( child ) !== - 1 ) {
123
+ if ( trail . includes ( child ) ) {
140
124
item . isInPath = true ;
141
125
item . isCurrent = trail [ trail . length - 1 ] === child ;
142
126
this . buildToc ( child , trail , item ) ;
143
127
}
144
128
}
145
129
} ) ;
130
+ // Group commands and input/output interface of each command.
131
+ this . commandsNavigationItem ?. children . sort ( ( childA , childB ) => childA . title . localeCompare ( childB . title ) ) ;
146
132
}
147
133
}
148
134
}
0 commit comments