@@ -90,6 +90,7 @@ public void run() {
90
90
91
91
// Import Pagination types
92
92
writer .addImport ("Paginator" , "Paginator" , TypeScriptDependency .SMITHY_TYPES );
93
+ writer .addImport ("createPaginator" , "createPaginator" , TypeScriptDependency .SMITHY_CORE );
93
94
writer .addRelativeImport (paginationType , paginationType ,
94
95
Paths .get ("." , getInterfaceFilelocation ().replace (".ts" , "" )));
95
96
@@ -134,56 +135,19 @@ static void generateServicePaginationInterfaces(TypeScriptWriter writer) {
134
135
});
135
136
}
136
137
137
- private String destructurePath (String path ) {
138
- return "." + path .replace ("." , "!." );
139
- }
140
-
141
138
private void writePager () {
142
- String inputTokenName = paginatedInfo .getPaginatedTrait ().getInputToken ().get ();
143
- String outputTokenName = paginatedInfo .getPaginatedTrait ().getOutputToken ().get ();
144
-
145
- writer .writeDocs ("@public\n \n "
146
- + String .format ("@param %s - {@link %s}%n" , inputTypeName , inputTypeName )
147
- + String .format ("@returns {@link %s}%n" , outputTypeName )
148
- );
149
- writer .openBlock (
150
- "export async function* paginate$L(config: $L, input: $L, ...additionalArguments: any): Paginator<$L>{" ,
151
- "}" , operationName , paginationType , inputTypeName , outputTypeName , () -> {
152
- String destructuredInputTokenName = destructurePath (inputTokenName );
153
- writer .write ("// ToDo: replace with actual type instead of typeof input$L" , destructuredInputTokenName );
154
- writer .write ("let token: typeof input$L | undefined = config.startingToken || undefined;" ,
155
- destructuredInputTokenName );
156
-
157
- writer .write ("let hasNext = true;" );
158
- writer .write ("let page: $L;" , outputTypeName );
159
- writer .openBlock ("while (hasNext) {" , "}" , () -> {
160
- writer .write ("input$L = token;" , destructuredInputTokenName );
161
-
162
- if (paginatedInfo .getPageSizeMember ().isPresent ()) {
163
- String pageSize = paginatedInfo .getPageSizeMember ().get ().getMemberName ();
164
- writer .write ("input[$S] = config.pageSize;" , pageSize );
165
- }
166
-
167
- writer .openBlock ("if (config.client instanceof $L) {" , "}" , DocumentClientUtils .CLIENT_NAME ,
168
- () -> {
169
- writer .write (
170
- "page = await makePagedClientRequest(config.client, input, ...additionalArguments);" );
171
- }
172
- );
173
- writer .openBlock ("else {" , "}" , () -> {
174
- writer .write ("throw new Error(\" Invalid client, expected $L | $L\" );" ,
175
- DocumentClientUtils .CLIENT_FULL_NAME , DocumentClientUtils .CLIENT_NAME );
176
- });
177
-
178
- writer .write ("yield page;" );
179
- writer .write ("token = page$L;" , destructurePath (outputTokenName ));
180
-
181
- writer .write ("hasNext = !!(token);" );
182
- });
183
-
184
- writer .write ("// @ts-ignore" );
185
- writer .write ("return undefined;" );
186
- });
139
+ writer .writeDocs ("@public" );
140
+ writer .write ("""
141
+ export const paginate$1L: (
142
+ config: $2L,
143
+ input: $3L,
144
+ ...additionalArguments: any
145
+ ) => Paginator<$4L> = createPaginator<
146
+ $2L,
147
+ $3L,
148
+ $4L
149
+ >(DynamoDBDocumentClient, $1LCommand, "ExclusiveStartKey", "LastEvaluatedKey", "Limit");
150
+ """ , operationName , paginationType , inputTypeName , outputTypeName );
187
151
}
188
152
189
153
@@ -192,13 +156,5 @@ private void writePager() {
192
156
* environments and does not generally expose the entire service.
193
157
*/
194
158
private void writeCommandRequest () {
195
- writer .writeDocs ("@internal" );
196
- writer .openBlock (
197
- "const makePagedClientRequest = async (client: $L, input: $L, ...args: any): Promise<$L> => {" ,
198
- "}" , DocumentClientUtils .CLIENT_NAME , inputTypeName ,
199
- outputTypeName , () -> {
200
- writer .write ("// @ts-ignore" );
201
- writer .write ("return await client.send(new $L(input), ...args);" , operationTypeName );
202
- });
203
159
}
204
160
}
0 commit comments