当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Boom.internal函数代码示例

本文整理汇总了TypeScript中Boom.internal函数的典型用法代码示例。如果您正苦于以下问题:TypeScript internal函数的具体用法?TypeScript internal怎么用?TypeScript internal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了internal函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: interceptRequest

  return async function interceptRequest(
    req: Request,
    h: ResponseToolkit
  ): Promise<Lifecycle.ReturnValue> {
    try {
      const result = await fn(KibanaRequest.from(req, undefined), toolkit);
      if (OnRequestResult.isValidResult(result)) {
        if (result.isNext()) {
          return h.continue;
        }
        if (result.isRedirected()) {
          return h.redirect(result.payload).takeover();
        }
        if (result.isRejected()) {
          const { error, statusCode } = result.payload;
          return Boom.boomify(error, { statusCode });
        }
      }

      throw new Error(
        `Unexpected result from OnRequest. Expected OnRequestResult, but given: ${result}.`
      );
    } catch (error) {
      return Boom.internal(error.message, { statusCode: 500 });
    }
  };
开发者ID:horacimacias,项目名称:kibana,代码行数:26,代码来源:on_request.ts

示例2: interceptRequest

  return async function interceptRequest(
    request: Request,
    h: ResponseToolkit
  ): Promise<Lifecycle.ReturnValue> {
    try {
      const result = await fn(KibanaRequest.from(request, undefined), {
        next: OnRequestResult.next,
        redirected: OnRequestResult.redirected,
        rejected: OnRequestResult.rejected,
        setUrl: (newUrl: string | Url) => {
          request.setUrl(newUrl);
          // We should update raw request as well since it can be proxied to the old platform
          request.raw.req.url = typeof newUrl === 'string' ? newUrl : newUrl.href;
        },
      });
      if (OnRequestResult.isValidResult(result)) {
        if (result.isNext()) {
          return h.continue;
        }
        if (result.isRedirected()) {
          return h.redirect(result.payload).takeover();
        }
        if (result.isRejected()) {
          const { error, statusCode } = result.payload;
          return Boom.boomify(error, { statusCode });
        }
      }

      throw new Error(
        `Unexpected result from OnRequest. Expected OnRequestResult, but given: ${result}.`
      );
    } catch (error) {
      return Boom.internal(error.message, { statusCode: 500 });
    }
  };
开发者ID:elastic,项目名称:kibana,代码行数:35,代码来源:on_request.ts

示例3: interceptAuth

  return async function interceptAuth(
    req: Request,
    h: ResponseToolkit
  ): Promise<Lifecycle.ReturnValue> {
    try {
      const result = await fn(req, sessionStorage.asScoped(req), toolkit);

      if (AuthResult.isValidResult(result)) {
        if (result.isAuthenticated()) {
          return h.authenticated({ credentials: result.payload });
        }
        if (result.isRedirected()) {
          return h.redirect(result.payload).takeover();
        }
        if (result.isRejected()) {
          const { error, statusCode } = result.payload;
          return Boom.boomify(error, { statusCode });
        }
      }
      throw new Error(
        `Unexpected result from Authenticate. Expected AuthResult, but given: ${result}.`
      );
    } catch (error) {
      return Boom.internal(error.message, { statusCode: 500 });
    }
  };
开发者ID:elastic,项目名称:kibana,代码行数:26,代码来源:auth.ts

示例4: async

  const symbolSearchHandler = async (req: hapi.Request) => {
    let page = 1;
    const { p, q, repoScope } = req.query as hapi.RequestQuery;
    if (p) {
      page = parseInt(p as string, 10);
    }

    let scope: string[] = [];
    if (typeof repoScope === 'string') {
      scope = repoScope.split(',');
    }

    const searchReq: SymbolSearchRequest = {
      query: q as string,
      page,
      repoScope: scope,
    };
    try {
      const symbolSearchClient = new SymbolSearchClient(new EsClientWithRequest(req), log);
      const res = await symbolSearchClient.suggest(searchReq);
      return res;
    } catch (error) {
      return Boom.internal(`Search Exception`);
    }
  };
开发者ID:elastic,项目名称:kibana,代码行数:25,代码来源:search.ts

示例5: async

  handler: async (request: FrameworkRequest) => {
    const numTokens = get(request, 'payload.num_tokens', DEFAULT_NUM_TOKENS);

    try {
      const tokens = await libs.tokens.createEnrollmentTokens(request.user, numTokens);
      return { tokens };
    } catch (err) {
      libs.framework.log(err.message);
      return Boom.internal();
    }
  },
开发者ID:gingerwizard,项目名称:kibana,代码行数:11,代码来源:create.ts

示例6: symbolByQnameRoute

export function symbolByQnameRoute(server: CodeServerRouter, log: Logger) {
  server.route({
    path: '/api/code/lsp/symbol/{qname}',
    method: 'GET',
    async handler(req) {
      try {
        const symbolSearchClient = new SymbolSearchClient(new EsClientWithRequest(req), log);
        const res = await symbolSearchClient.findByQname(req.params.qname);
        return res;
      } catch (error) {
        return Boom.internal(`Search Exception`);
      }
    },
  });
}
开发者ID:elastic,项目名称:kibana,代码行数:15,代码来源:lsp.ts

示例7: historyHandler

 async function historyHandler(req: hapi.Request) {
   const gitOperations = new GitOperations(options.repoPath);
   const { uri, ref, path } = req.params;
   const queries = req.query as RequestQuery;
   const count = queries.count ? parseInt(queries.count as string, 10) : 10;
   const after = queries.after !== undefined;
   try {
     const repoExist = await repoExists(req, uri);
     if (!repoExist) {
       return Boom.notFound(`repo ${uri} not found`);
     }
     const repository = await gitOperations.openRepo(uri);
     const commit = await gitOperations.getCommit(repository, decodeURIComponent(ref));
     const walk = repository.createRevWalk();
     walk.sorting(Revwalk.SORT.TIME);
     walk.push(commit.id());
     let commits: Commit[];
     if (path) {
       // magic number 10000: how many commits at the most to iterate in order to find the commits contains the path
       const results = await walk.fileHistoryWalk(path, count, 10000);
       commits = results.map(result => result.commit);
     } else {
       walk.push(commit.id());
       commits = await walk.getCommits(count);
     }
     if (after && commits.length > 0) {
       if (commits[0].id().equal(commit.id())) {
         commits = commits.slice(1);
       }
     }
     return commits.map(commitInfo);
   } catch (e) {
     if (e.isBoom) {
       return e;
     } else {
       return Boom.internal(e.message || e.name);
     }
   }
 }
开发者ID:elastic,项目名称:kibana,代码行数:39,代码来源:file.ts

示例8: fileRoute

export function fileRoute(server: CodeServerRouter, options: ServerOptions) {
  async function repoExists(req: hapi.Request, repoUri: string) {
    const repoObjectClient = new RepositoryObjectClient(new EsClientWithRequest(req));

    try {
      // Check if the repository already exists
      await repoObjectClient.getRepository(repoUri);
      return true;
    } catch (e) {
      return false;
    }
  }

  server.route({
    path: '/api/code/repo/{uri*3}/tree/{ref}/{path*}',
    method: 'GET',
    async handler(req: hapi.Request) {
      const fileResolver = new GitOperations(options.repoPath);
      const { uri, path, ref } = req.params;
      const queries = req.query as RequestQuery;
      const limit = queries.limit
        ? parseInt(queries.limit as string, 10)
        : DEFAULT_TREE_CHILDREN_LIMIT;
      const skip = queries.skip ? parseInt(queries.skip as string, 10) : 0;
      const depth = queries.depth ? parseInt(queries.depth as string, 10) : 0;
      const withParents = 'parents' in queries;
      const flatten = 'flatten' in queries;
      const repoExist = await repoExists(req, uri);
      if (!repoExist) {
        return Boom.notFound(`repo ${uri} not found`);
      }

      try {
        return await fileResolver.fileTree(
          uri,
          path,
          ref,
          skip,
          limit,
          withParents,
          depth,
          flatten
        );
      } catch (e) {
        if (e.isBoom) {
          return e;
        } else {
          return Boom.internal(e.message || e.name);
        }
      }
    },
  });

  server.route({
    path: '/api/code/repo/{uri*3}/blob/{ref}/{path*}',
    method: 'GET',
    async handler(req: hapi.Request, h: hapi.ResponseToolkit) {
      const fileResolver = new GitOperations(options.repoPath);
      const { uri, path, ref } = req.params;
      const repoExist = await repoExists(req, uri);
      if (!repoExist) {
        return Boom.notFound(`repo ${uri} not found`);
      }
      try {
        const blob = await fileResolver.fileContent(uri, path, decodeURIComponent(ref));
        if (blob.isBinary()) {
          const type = fileType(blob.content());
          if (type && type.mime && type.mime.startsWith('image/')) {
            const response = h.response(blob.content());
            response.type(type.mime);
            return response;
          } else {
            // this api will return a empty response with http code 204
            return h
              .response('')
              .type('application/octet-stream')
              .code(204);
          }
        } else {
          const line = (req.query as RequestQuery).line as string;
          if (line) {
            const [from, to] = line.split(',');
            let fromLine = parseInt(from, 10);
            let toLine = to === undefined ? fromLine + 1 : parseInt(to, 10);
            if (fromLine > toLine) {
              [fromLine, toLine] = [toLine, fromLine];
            }
            const lines = extractLines(blob.content(), fromLine, toLine);
            const lang = await detectLanguage(path, lines);
            return h.response(lines).type(`text/${lang || 'plain'}`);
          } else if (blob.content().length <= TEXT_FILE_LIMIT) {
            const lang = await detectLanguage(path, blob.content());
            return h.response(blob.content()).type(`text/${lang || 'plain'}`);
          } else {
            return h.response('').type(`text/big`);
          }
        }
      } catch (e) {
        if (e.isBoom) {
          return e;
//.........这里部分代码省略.........
开发者ID:elastic,项目名称:kibana,代码行数:101,代码来源:file.ts

示例9: documentSearchRoute

export function documentSearchRoute(server: CodeServerRouter, log: Logger) {
  server.route({
    path: '/api/code/search/doc',
    method: 'GET',
    async handler(req) {
      let page = 1;
      const { p, q, langs, repos, repoScope } = req.query as hapi.RequestQuery;
      if (p) {
        page = parseInt(p as string, 10);
      }

      let scope: string[] = [];
      if (typeof repoScope === 'string') {
        scope = repoScope.split(',');
      }

      const searchReq: DocumentSearchRequest = {
        query: q as string,
        page,
        langFilters: langs ? (langs as string).split(',') : [],
        repoFilters: repos ? decodeURIComponent(repos as string).split(',') : [],
        repoScope: scope,
      };
      try {
        const docSearchClient = new DocumentSearchClient(new EsClientWithRequest(req), log);
        const res = await docSearchClient.search(searchReq);
        return res;
      } catch (error) {
        return Boom.internal(`Search Exception`);
      }
    },
  });

  server.route({
    path: '/api/code/suggestions/doc',
    method: 'GET',
    async handler(req) {
      let page = 1;
      const { p, q, repoScope } = req.query as hapi.RequestQuery;
      if (p) {
        page = parseInt(p as string, 10);
      }

      let scope: string[] = [];
      if (typeof repoScope === 'string') {
        scope = repoScope.split(',');
      }

      const searchReq: DocumentSearchRequest = {
        query: q as string,
        page,
        repoScope: scope,
      };
      try {
        const docSearchClient = new DocumentSearchClient(new EsClientWithRequest(req), log);
        const res = await docSearchClient.suggest(searchReq);
        return res;
      } catch (error) {
        return Boom.internal(`Search Exception`);
      }
    },
  });
}
开发者ID:elastic,项目名称:kibana,代码行数:63,代码来源:search.ts

示例10: repositorySearchRoute

export function repositorySearchRoute(server: CodeServerRouter, log: Logger) {
  server.route({
    path: '/api/code/search/repo',
    method: 'GET',
    async handler(req) {
      let page = 1;
      const { p, q, repoScope } = req.query as hapi.RequestQuery;
      if (p) {
        page = parseInt(p as string, 10);
      }

      let scope: string[] = [];
      if (typeof repoScope === 'string') {
        scope = repoScope.split(',');
      }

      const searchReq: RepositorySearchRequest = {
        query: q as string,
        page,
        repoScope: scope,
      };
      try {
        const repoSearchClient = new RepositorySearchClient(new EsClientWithRequest(req), log);
        const res = await repoSearchClient.search(searchReq);
        return res;
      } catch (error) {
        return Boom.internal(`Search Exception`);
      }
    },
  });

  server.route({
    path: '/api/code/suggestions/repo',
    method: 'GET',
    async handler(req) {
      let page = 1;
      const { p, q, repoScope } = req.query as hapi.RequestQuery;
      if (p) {
        page = parseInt(p as string, 10);
      }

      let scope: string[] = [];
      if (typeof repoScope === 'string') {
        scope = repoScope.split(',');
      }

      const searchReq: RepositorySearchRequest = {
        query: q as string,
        page,
        repoScope: scope,
      };
      try {
        const repoSearchClient = new RepositorySearchClient(new EsClientWithRequest(req), log);
        const res = await repoSearchClient.suggest(searchReq);
        return res;
      } catch (error) {
        return Boom.internal(`Search Exception`);
      }
    },
  });
}
开发者ID:elastic,项目名称:kibana,代码行数:61,代码来源:search.ts


注:本文中的Boom.internal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。