<commit_before>import * as extend from 'extend'
import * as _request from 'request' // for types only
import * as request from 'retry-request'

const BASE_URL = 'http://metadata.google.internal/computeMetadata/v1'

export type Options = _request.Options & { property?: string }

export type Callback = (error: Error | null,
  response?: _request.RequestResponse, metadataProp?: string) => void

export function _buildMetadataAccessor(type: string) {
  return (options: string | Options | Callback, callback: Callback) => {
    if (typeof options === 'function') {
      callback = options
      options = {} as any
    }

    if (typeof options === 'string') {
      options = {
        property: options
      } as any
    }

    let property = ''
    if (typeof options === 'object' && options.property) {
      property = '/' + options.property
    }

    const reqOpts = extend(true, {
      uri: BASE_URL + '/' + type + property,
      headers: { 'Metadata-Flavor': 'Google' }
    }, options) as Options
    delete reqOpts.property

    const retryRequestOpts = {
      noResponseRetries: 0
    }

    return request(reqOpts, retryRequestOpts, (err, res, body) => {
      if (err) {
        callback(err)
      } else if (!res) {
        callback(new Error('Invalid response from metadata service'))
      } else if (res.statusCode !== 200) {
        callback(new Error('Unsuccessful response status code'), res)
      } else {
        callback(null, res, body)<commit_msg>address typing comments<commit_after>import * as extend from 'extend'
import * as _request from 'request' // for types only
import * as request from 'retry-request'

const BASE_URL = 'http://metadata.google.internal/computeMetadata/v1'

export type Options = _request.CoreOptions & {
  property?: string,
  uri?: string
}

export type Callback = (error: Error | null,
  response?: _request.RequestResponse, metadataProp?: string) => void

export function _buildMetadataAccessor(type: string) {
  return function metadataAccessor(options: string | Options | Callback, callback?: Callback) {
    if (typeof options === 'function') {
      callback = options
      options = {}
    }

    if (typeof options === 'string') {
      options = {
        property: options
      }
    }

    let property = ''
    if (typeof options === 'object' && options.property) {
      property = '/' + options.property
    }

    const reqOpts = extend(true, {
      uri: BASE_URL + '/' + type + property,
      headers: { 'Metadata-Flavor': 'Google' }
    }, options) as _request.Options & { property?: string }
    delete reqOpts.property

    const retryRequestOpts = {
      noResponseRetries: 0
    }

    return request(reqOpts, retryRequestOpts, (err, res, body) => {
      if (callback) { // for type safety; this should already always be true
        if (err) {
          callback(err)
        } else if (!res) {
          callback(new Error('Invalid response from metadata service'))
        } else if (res.statusCode !== 200) {
          callback(new Error('Unsuccessful response status code'), res)
        } else {
          callback(null, res, body)
        }
{'fraction_non_alphanumeric': 0.12160868177465688, 'fraction_numerical': 0.0031918289179699967, 'mean_word_length': 2.826617826617827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4053091', 'n_tokens_mistral': 879, 'n_tokens_neox': 875, 'n_words': 267}