<commit_before>import clsify from 'cls-middleware';
import {createNamespace} from 'continuation-local-storage';

const DEFAULT_NAME = 'cls-isoflux';
const APP = 'app';

export default class Isoflux {
  constructor(name = DEFAULT_NAME) {
    this._namespace = createNamespace(name);
    this._boundClsify = clsify(this._namespace);
  }

  middleware = (req, res, next) => {
    this._boundClsify(req, res, this._middlewareInternal(next));
  };

  _middlewareInternal(next) {
    this._namespace.set(APP, this.createApp());
    next();
  }

  createApp() {
    throw Error('not implemented');
  }

  getApp() {
    return this._namespace.get(APP);
  }

  createProxy(Class, options) {
    const isoflux = this;

    class Proxy {
      _getProxiedObject() {
        return isoflux._getProxiedObject(Class, options);
      }
    }

    function defineProxiedProperty(propertyName) {
      Proxy.prototype[propertyName] = function (...args) {
        const proxiedObject = this._getProxiedObject();
        return proxiedObject[propertyName].apply(proxiedObject, args);
      };
    }

    for (let propertyName in Class.prototype) {
      // Intentially capture prototype properties as well here.
      defineProxiedProperty(propertyName);
    }

    return Proxy;
  }

  _getProxiedObject(Class, options) {  // eslint-disable-line no-unused-vars
    throw Error('not implemented');
  }<commit_msg>Fix middleware and proxy creation<commit_after>import clsify from 'cls-middleware';
import {createNamespace} from 'continuation-local-storage';

const DEFAULT_NAME = 'cls-isoflux';
const APP = 'app';

export default class Isoflux {
  constructor(name = DEFAULT_NAME) {
    this._namespace = createNamespace(name);
    this._boundClsify = clsify(this._namespace);
  }

  middleware = (req, res, next) => {
    this._boundClsify(req, res, () => this._middlewareInternal(next));
  };

  _middlewareInternal(next) {
    this._namespace.set(APP, this.createApp());
    next();
  }

  createApp() {
    throw Error('not implemented');
  }

  getApp() {
    return this._namespace.get(APP);
  }

  createProxy(Class, options) {
    class Proxy {}
    const isoflux = this;

    function defineProxiedProperty(propertyName) {
      Proxy.prototype[propertyName] = function (...args) {
        const proxiedObject = isoflux._getProxiedObject(Class, options);
        return proxiedObject[propertyName].apply(proxiedObject, args);
      };
    }

    // Intentially capture prototype properties as well here.
    for (let propertyName in Class.prototype) {
      defineProxiedProperty(propertyName);
    }

    return Proxy;
  }

  _getProxiedObject(Class, options) {  // eslint-disable-line no-unused-vars
    throw Error('not implemented');
  }
{'fraction_non_alphanumeric': 0.1208348590259978, 'fraction_numerical': 0.0, 'mean_word_length': 3.4860426929392445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2520610', 'n_tokens_mistral': 864, 'n_tokens_neox': 833, 'n_words': 173}