async function downloadDiscoveryDocs(options) {
    await exports.gfs.rimraf(options.downloadPath);
    await exports.gfs.mkdir(options.downloadPath);
    const headers = options.includePrivate
        ? {}
        : { 'X-User-Ip': '0.0.0.0' };
    console.log(`sending request to ${options.discoveryUrl}`);
    const res = await gaxios_1.request({ url: options.discoveryUrl, headers });
    const apis = res.data.items;
    const indexPath = path.join(options.downloadPath, 'index.json');
    exports.gfs.writeFile(indexPath, res.data);
    const queue = new p_queue_1.default({ concurrency: 25 });
    console.log(`Downloading ${apis.length} APIs...`);
    queue.addAll(apis.map(api => {
        return async () => {
            console.log(`Downloading ${api.id}...`);
            const apiPath = path.join(options.downloadPath, api.id.replace(':', '-') + '.json');
            const url = api.discoveryRestUrl;
            const res = await gaxios_1.request({ url });
            // The keys in the downloaded JSON come back in an arbitrary order from
            // request to request. Sort them before storing.
            const data = sortKeys(res.data);
            exports.gfs.writeFile(apiPath, data);
        };
    }));
    await queue.onIdle();
}
/**
 * Download all discovery documents into the /discovery directory.
 * @param options
 */
Download all discovery documents into the /discovery directory.
@param options
Download all discovery documents into the / discovery directory . @param options
async function downloadDiscoveryDocs(options) {
    await exports.gfs.rimraf(options.downloadPath);
    await exports.gfs.mkdir(options.downloadPath);
    const headers = options.includePrivate
        ? {}
        : { 'X-User-Ip': '0.0.0.0' };
    console.log(`sending request to ${options.discoveryUrl}`);
    const res = await gaxios_1.request({ url: options.discoveryUrl, headers });
    const apis = res.data.items;
    const indexPath = path.join(options.downloadPath, 'index.json');
    exports.gfs.writeFile(indexPath, res.data);
    const queue = new p_queue_1.default({ concurrency: 25 });
    console.log(`Downloading ${apis.length} APIs...`);
    queue.addAll(apis.map(api => {
        return async () => {
            console.log(`Downloading ${api.id}...`);
            const apiPath = path.join(options.downloadPath, api.id.replace(':', '-') + '.json');
            const url = api.discoveryRestUrl;
            const res = await gaxios_1.request({ url });
            const data = sortKeys(res.data);
            exports.gfs.writeFile(apiPath, data);
        };
    }));
    await queue.onIdle();
}
async function downloadDiscoveryDocs ( options ) { await exports . gfs . rimraf ( options . downloadPath ) ; await exports . gfs . mkdir ( options . downloadPath ) ; const headers = options . includePrivate ? { } : { 'X-User-Ip' : '0.0.0.0' } ; console . log ( ` ${ options . discoveryUrl } ` ) ; const res = await gaxios_1 . request ( { url : options . discoveryUrl , headers } ) ; const apis = res . data . items ; const indexPath = path . join ( options . downloadPath , 'index.json' ) ; exports . gfs . writeFile ( indexPath , res . data ) ; const queue = new p_queue_1 . default ( { concurrency : 25 } ) ; console . log ( ` ${ apis . length } ` ) ; queue . addAll ( apis . map ( api => { return async ( ) => { console . log ( ` ${ api . id } ` ) ; const apiPath = path . join ( options . downloadPath , api . id . replace ( ':' , '-' ) + '.json' ) ; const url = api . discoveryRestUrl ; const res = await gaxios_1 . request ( { url } ) ; const data = sortKeys ( res . data ) ; exports . gfs . writeFile ( apiPath , data ) ; } ; } ) ) ; await queue . onIdle ( ) ; }
Download all discovery documents into the /discovery directory.
Download all discovery documents into the / discovery directory .
// The keys in the downloaded JSON come back in an arbitrary order from // request to request. Sort them before storing.