/**
 * This is a custom, hand-rolled generator for TS typings for the Bungie.net API. It's meant for use
 * in DIM, but is free for anyone to use.
 */ import fs from 'fs' ; import _ from 'underscore' ; import { OpenAPIObject , PathItemObject } from 'openapi3-ts' ; import { generateIndex , generateSuperIndex } from './generate-index.js' ; import { DefInfo } from './util.js' ; import { computeTypeMaps } from './type-index.js' ; import { generateInterfaceDefinitions } from './generate-interfaces.js' ; import { generateManifestUtils } from './generate-manifest.js' ; import { generateServiceDefinition } from './generate-api.js' ; import { generatePackageJson } from './generate-package-json.js' ; ( async ( ) => { const doc = JSON . parse ( fs . readFileSync ( 'api-src/openapi.json' ) . toString ( ) ) as OpenAPIObject ; const pathPairs = _ . pairs ( doc . paths ) as [ string , PathItemObject ] [ ] ; const pathPairsByTag = _ . groupBy ( pathPairs , ( [ path , desc ] ) => { return ( desc . get || desc . post ) ! . tags ! [ 0 ] ; } ) ; pathPairsByTag [ 'Core' ] = pathPairsByTag [ '' ] ; delete pathPairsByTag [ '' ] ; const { componentsByFile , componentByDef } = computeTypeMaps ( pathPairsByTag , doc ) ; _ . each ( componentsByFile , ( components , file ) => { generateInterfaceDefinitions ( file , components , doc , componentByDef ) ; } ) ; await generateManifestUtils ( componentsByFile [ 'destiny2/interfaces.ts' ] , doc ) ; _ . each ( pathPairsByTag , ( paths , tag ) => { generateServiceDefinition ( tag , paths , doc , componentByDef ) ; } ) ; _ . each ( pathPairsByTag , ( paths , tag ) => { generateIndex ( tag , doc , componentsByFile ) ; } ) ; generateSuperIndex ( Object . keys ( pathPairsByTag ) , doc ) ; generatePackageJson ( Object . keys ( pathPairsByTag ) ) ; } ) ( ) ;