<commit_before>import {classOf, DecoratorParameters, descriptorOf, getDecoratorType, methodsOf, prototypeOf, Store} from "@tsed/core";
import {AuthenticatedMiddleware} from "../../components/AuthenticatedMiddleware";
import {UseBefore} from "./useBefore";

function decorate(options: any) {
  return Store.decorate((store: Store) => {
    store.set(AuthenticatedMiddleware, options).merge("responses", {"403": {description: "Forbidden"}});

    return UseBefore(AuthenticatedMiddleware);
  });
}

/**
 * Set authentication strategy on your endpoint.
 *
 * ```typescript
 * @ControllerProvider('/mypath')
 * class MyCtrl {
 *
 *   @Get('/')
 *   @Authenticated({role: 'admin'})
 *   public getResource(){}
 * }
 * ```
 *
 * @param options
 * @returns {Function}
 * @decorator
 */
export function Authenticated(options?: any) {
  return <T>(...parameters: DecoratorParameters): TypedPropertyDescriptor<T> | void => {
    switch (getDecoratorType(parameters, true)) {
      case "method":
        return decorate(options)(...parameters);

      case "class":
        const [klass] = parameters;

        methodsOf(klass).forEach(({target, propertyKey}) => {
          if (target !== classOf(klass)) {
            prototypeOf(klass)[propertyKey] = function anonymous(...args: any) {
              return prototypeOf(target)[propertyKey].apply(this, args);
            };
          }<commit_msg>fix(mvc): Fix signature Authenticated decorator<commit_after>import {classOf, DecoratorParameters, descriptorOf, getDecoratorType, methodsOf, prototypeOf, Store} from "@tsed/core";
import {AuthenticatedMiddleware} from "../../components/AuthenticatedMiddleware";
import {UseBefore} from "./useBefore";

function decorate(options: any) {
  return Store.decorate((store: Store) => {
    store.set(AuthenticatedMiddleware, options).merge("responses", {"403": {description: "Forbidden"}});

    return UseBefore(AuthenticatedMiddleware);
  });
}

/**
 * Set authentication strategy on your endpoint.
 *
 * ```typescript
 * @ControllerProvider('/mypath')
 * class MyCtrl {
 *
 *   @Get('/')
 *   @Authenticated({role: 'admin'})
 *   public getResource(){}
 * }
 * ```
 *
 * @param options
 * @returns {Function}
 * @decorator
 */
export function Authenticated(options?: any): Function {
  return <T>(...parameters: DecoratorParameters): TypedPropertyDescriptor<T> | void => {
    switch (getDecoratorType(parameters, true)) {
      case "method":
        return decorate(options)(...parameters);

      case "class":
        const [klass] = parameters;

        methodsOf(klass).forEach(({target, propertyKey}) => {
          if (target !== classOf(klass)) {
            prototypeOf(klass)[propertyKey] = function anonymous(...args: any) {
              return prototypeOf(target)[propertyKey].apply(this, args);
            };
          }
{'fraction_non_alphanumeric': 0.15793201133144477, 'fraction_numerical': 0.002124645892351275, 'mean_word_length': 3.8208191126279862, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 13, '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': '4041386', 'n_tokens_mistral': 803, 'n_tokens_neox': 813, 'n_words': 173}