<commit_before>import { Class, env, Exception, IDeclarations, inject, IProvider, Kernel, Logger, Meta, state } from "oly-core";
import { olyReactRouterEvents } from "../constants/events";
import { olyReactRouterKeys } from "../constants/keys";
import {
  IHrefQuery,
  ILayer,
  IMatch,
  INode,
  IPagesMetadata,
  IPagesProperty,
  IRoute,
  ITransition,
  ITransitionError,
} from "../interfaces";
import { DefaultErrorHandler } from "../services/DefaultErrorHandler";
import { ReactRouterMatcher } from "../services/ReactRouterMatcher";
import { ReactRouterResolver } from "../services/ReactRouterResolver";

export class ReactRouterProvider implements IProvider {

  /**
   * This is the current stack.
   * All resolved components are stored here.
   * On each page update, layers is erased, there is no cache.
   */
  public layers: ILayer[] = [];

  public match?: IMatch;

  @env("OLY_REACT_ROUTER_BASE_HREF")
  public baseHref: string = "";

  @inject
  protected kernel: Kernel;

  @inject
  protected logger: Logger;

  @state
  protected routes: IRoute[];

  @inject
  protected matcher: ReactRouterMatcher;

  @inject
  protected resolver: ReactRouterResolver;

  public href(query: IHrefQuery | string): string | undefined {
    return this.matcher.href(this.routes, query, this.match);
  }

  public async transition(query: string | IHrefQuery): Promise<ITransition | undefined> {

    const options = typeof query === "string" ? {to: query} : query;

    // convert the "query" to a valid url<commit_msg>(oly-react): add basehref to href()<commit_after>import { Class, env, Exception, IDeclarations, inject, IProvider, Kernel, Logger, Meta, state } from "oly-core";
import { olyReactRouterEvents } from "../constants/events";
import { olyReactRouterKeys } from "../constants/keys";
import {
  IHrefQuery,
  ILayer,
  IMatch,
  INode,
  IPagesMetadata,
  IPagesProperty,
  IRoute,
  ITransition,
  ITransitionError,
} from "../interfaces";
import { DefaultErrorHandler } from "../services/DefaultErrorHandler";
import { ReactRouterMatcher } from "../services/ReactRouterMatcher";
import { ReactRouterResolver } from "../services/ReactRouterResolver";

export class ReactRouterProvider implements IProvider {

  /**
   * This is the current stack.
   * All resolved components are stored here.
   * On each page update, layers is erased, there is no cache.
   */
  public layers: ILayer[] = [];

  public match?: IMatch;

  @env("OLY_REACT_ROUTER_BASE_HREF")
  public baseHref: string = "";

  @inject
  protected kernel: Kernel;

  @inject
  protected logger: Logger;

  @state
  protected routes: IRoute[];

  @inject
  protected matcher: ReactRouterMatcher;

  @inject
  protected resolver: ReactRouterResolver;

  public href(query: IHrefQuery | string): string | undefined {
    return this.baseHref + this.matcher.href(this.routes, query, this.match);
  }

  public async transition(query: string | IHrefQuery): Promise<ITransition | undefined> {

    const options = typeof query === "string" ? {to: query} : query;

    // convert the "query" to a valid url
{'fraction_non_alphanumeric': 0.11493506493506493, 'fraction_numerical': 0.0, 'mean_word_length': 4.143572621035059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6271073', 'n_tokens_mistral': 918, 'n_tokens_neox': 907, 'n_words': 272}