github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/models/query.ts (about)

     1  import { Maybe } from '@webapp/util/fp';
     2  
     3  // Nominal typing
     4  // https://basarat.gitbook.io/typescript/main-1/nominaltyping
     5  enum QueryBrand {
     6    _ = '',
     7  }
     8  export type Query = QueryBrand & string;
     9  
    10  export function brandQuery(query: string) {
    11    return query as unknown as Query;
    12  }
    13  
    14  export function queryFromAppName(appName: string): Query {
    15    return `${appName}{}` as unknown as Query;
    16  }
    17  
    18  export function queryToAppName(q: Query): Maybe<string> {
    19    const query: string = q;
    20  
    21    if (!query || !query.length) {
    22      return Maybe.nothing();
    23    }
    24  
    25    const rep = query.replace(/\{.*/g, '');
    26  
    27    if (!rep.length) {
    28      return Maybe.nothing();
    29    }
    30  
    31    return Maybe.just(rep);
    32  }