<commit_before>import { Inject } from '@angular/core';
import { Headers as NgHeaders, Http, Request, Response, RequestMethod,
  RequestOptions, ResponseContentType, URLSearchParams, QueryEncoder } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/shareReplay';

const Reflect = global['Reflect'];

export class PassThroughQueryEncoder extends QueryEncoder 
{
  encodeKey(k: string): string { return k; }
  encodeValue(v: string): string { return v; }
}
/**
 * actually copied from @angular/http since it's not exported
 * @param value to encode
 */
export function standardEncoding(v) 
{ 
  return encodeURIComponent(v)
    .replace(/%40/gi, '@')
    .replace(/%3A/gi, ':')
    .replace(/%24/gi, '$')
    .replace(/%2C/gi, ',')
    .replace(/%3B/gi, ';')
    .replace(/%2B/gi, '+')
    .replace(/%3D/gi, '=')
    .replace(/%3F/gi, '?')
    .replace(/%2F/gi, '/');
}

function isObject(item)
{
  return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
}
function extend<T, U>(target: T, source: U) : T & U
{
  if ( !isObject(target) || !isObject(source) ) return target as T & U;
  Object.keys(source).forEach( key =>
  {
    if ( isObject(source[key]) )
    {
      if ( !target[key] ) Object.assign(target, { [key]: {} });
      extend( target[key], source[key] );
    }
    else
      Object.assign( target, { [key]: source[key] });
  });
  return target as T & U;
}

// abstract Api class
export abstract class AbstractApiClient
{
  constructor( @Inject(Http) protected http: Http ) { }
}

// reflect metadata key symbols
const MetadataKeys =
{
  Query: Symbol('apiClient:Query'),
  Path: Symbol('apiClient:Path'),
  Body: Symbol('apiClient:Body'),
  Header: Symbol('apiClient:Header'),
  Type: Symbol('apiClient:ResponseType'),
  Error: Symbol('apiClient:Error'),
  Cache: Symbol('apiClient:Cache')
};

/**
 * class decorator
 * 
 * @param url - will use this exact string as BaseUrl, unless `configKey` is passed; function - will get assigned to protorype.getBaseUrl
 * @param configKey - will request `url` and get this key from the resulting json
 */
export function BaseUrl(url: (() => Observable<string>) | string, configKey?: string)
{
  return function <TClass extends { new (...args: any[]): AbstractApiClient }>
  (Target: TClass): TClass
  {
    if ( url instanceof Function ) Target.prototype.getBaseUrl = url;
    // request from external
    else if ( configKey )
    {
      let cached;
      Target.prototype.getBaseUrl = function()
      {
        let x = !cached ? (cached = this.http.get(url).map( r => r.json()[configKey] ).share()) : cached;
        return x;
      };
    }
    else Target.prototype.getBaseUrl = () => Observable.fromPromise( Promise.resolve(url) );
    return Target;
  };
}

/**
 * class decorator<commit_msg>update BaseUrl type<commit_after>import { Inject } from '@angular/core';
import { Headers as NgHeaders, Http, Request, Response, RequestMethod,
  RequestOptions, ResponseContentType, URLSearchParams, QueryEncoder } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/shareReplay';

const Reflect = global['Reflect'];

export class PassThroughQueryEncoder extends QueryEncoder 
{
  encodeKey(k: string): string { return k; }
  encodeValue(v: string): string { return v; }
}
/**
 * actually copied from @angular/http since it's not exported
 * @param value to encode
 */
export function standardEncoding(v) 
{ 
  return encodeURIComponent(v)
    .replace(/%40/gi, '@')
    .replace(/%3A/gi, ':')
    .replace(/%24/gi, '$')
    .replace(/%2C/gi, ',')
    .replace(/%3B/gi, ';')
    .replace(/%2B/gi, '+')
    .replace(/%3D/gi, '=')
    .replace(/%3F/gi, '?')
    .replace(/%2F/gi, '/');
}

function isObject(item)
{
  return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
}
function extend<T, U>(target: T, source: U) : T & U
{
  if ( !isObject(target) || !isObject(source) ) return target as T & U;
  Object.keys(source).forEach( key =>
  {
    if ( isObject(source[key]) )
    {
      if ( !target[key] ) Object.assign(target, { [key]: {} });
      extend( target[key], source[key] );
    }
    else
      Object.assign( target, { [key]: source[key] });
  });
  return target as T & U;
}

// abstract Api class
export abstract class AbstractApiClient
{
  constructor( @Inject(Http) protected http: Http ) { }
}

// reflect metadata key symbols
const MetadataKeys =
{
  Query: Symbol('apiClient:Query'),
  Path: Symbol('apiClient:Path'),
  Body: Symbol('apiClient:Body'),
  Header: Symbol('apiClient:Header'),
  Type: Symbol('apiClient:ResponseType'),
  Error: Symbol('apiClient:Error'),
  Cache: Symbol('apiClient:Cache')
};

/**
 * class decorator
 * 
 * @param url - will use this exact string as BaseUrl, unless `configKey` is passed; function - will get assigned to protorype.getBaseUrl
 * @param configKey - will request `url` and get this key from the resulting json
 */
export function BaseUrl(url: ((...args: any[]) => Observable<string>) | string, configKey?: string)
{
  return function <TClass extends { new (...args: any[]): AbstractApiClient }>
  (Target: TClass): TClass
  {
    if ( url instanceof Function ) Target.prototype.getBaseUrl = url;
    // request from external
    else if ( configKey )
    {
      let cached;
      Target.prototype.getBaseUrl = function()
      {
        let x = !cached ? (cached = this.http.get(url).map( r => r.json()[configKey] ).share()) : cached;
        return x;
      };
    }
    else Target.prototype.getBaseUrl = () => Observable.fromPromise( Promise.resolve(url) );
    return Target;
  };
}

/**
 * class decorator
{'fraction_non_alphanumeric': 0.16508040695766327, 'fraction_numerical': 0.0036101083032490976, 'mean_word_length': 3.699306090979183, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4411508', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1959, 'n_words': 495}