@@ -306,6 +306,37 @@ function createFeatureFlagTable(methods: Method[]) {
306
306
return lines . join ( '\n' ) ;
307
307
}
308
308
309
+ async function updateTypes ( filePath : string , betaMethods : Method [ ] ) {
310
+ const source = await fs . readFile ( filePath , 'utf-8' ) ;
311
+ const ast = recast . parse ( source ) ;
312
+ const program = ast . program ;
313
+
314
+ const clientOptions = program . body . find (
315
+ ( x ) => x . type === 'ExportNamedDeclaration' && x . declaration . id . name === 'ClientOptions' ,
316
+ ) ;
317
+
318
+ const features = clientOptions . declaration . typeAnnotation . members . find ( ( x ) => x . key . name === 'features' ) ;
319
+
320
+ features . typeAnnotation = builders . tsTypeAnnotation . from ( {
321
+ typeAnnotation : builders . tsTypeLiteral . from ( {
322
+ members : betaMethods . map ( ( method ) =>
323
+ builders . tsPropertySignature . from ( {
324
+ optional : true ,
325
+ key : builders . stringLiteral ( method . operationId ) ,
326
+ typeAnnotation : builders . tsTypeAnnotation . from ( {
327
+ typeAnnotation : builders . tsLiteralType . from ( {
328
+ literal : builders . booleanLiteral ( true ) ,
329
+ } ) ,
330
+ } ) ,
331
+ } ) ,
332
+ ) ,
333
+ } ) ,
334
+ } ) ;
335
+
336
+ const output = await recast . print ( ast , false ) ;
337
+ if ( ! output ) return ;
338
+ await fs . writeFile ( filePath , output , 'utf-8' ) ;
339
+ }
309
340
async function updateClient ( filePath : string , files : File [ ] ) {
310
341
const resources = files
311
342
. filter ( ( x ) => x . type === 'resources' && x . name . endsWith ( '.ts' ) )
@@ -366,7 +397,10 @@ async function main() {
366
397
const resources = await getResources ( argv . spec || SPEC_URL ) ;
367
398
368
399
const files : Array < File > = [ ] ;
369
- const betaMethods = resources . flatMap ( ( x ) => x . methods ) . filter ( ( x ) => x . beta ) ;
400
+ const betaMethods = resources
401
+ . flatMap ( ( x ) => x . methods )
402
+ . filter ( ( x ) => x . beta )
403
+ . sort ( ( a , b ) => a . operationId . localeCompare ( b . operationId ) ) ;
370
404
371
405
// generate ast for new resource files
372
406
for ( const rootResource of resources ) {
@@ -430,6 +464,7 @@ async function main() {
430
464
await updateReadme ( README_MD , 'FEATURE_FLAGS' , createFeatureFlagTable ( betaMethods ) ) ;
431
465
console . log ( `updated README.md` ) ;
432
466
467
+ await updateTypes ( path . join ( process . cwd ( ) , 'src' , 'types.ts' ) , betaMethods ) ;
433
468
await updateClient ( path . join ( process . cwd ( ) , 'src' , 'client.ts' ) , files ) ;
434
469
console . log ( `updated ${ path . relative ( process . cwd ( ) , path . join ( 'src' , 'client.ts' ) ) } ` ) ;
435
470
}
0 commit comments