當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fp.getOr函數代碼示例

本文整理匯總了TypeScript中lodash/fp.getOr函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getOr函數的具體用法?TypeScript getOr怎麽用?TypeScript getOr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了getOr函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getTimelineDetails

  public async getTimelineDetails(
    request: FrameworkRequest,
    options: RequestDetailsOptions
  ): Promise<TimelineDetailsData> {
    const [mapResponse, searchResponse] = await Promise.all([
      this.framework.callWithRequest(request, 'indices.getMapping', {
        allowNoIndices: true,
        ignoreUnavailable: true,
        index: options.indexName,
      }),
      this.framework.callWithRequest<EventHit, TermAggregation>(
        request,
        'search',
        buildDetailsQuery(options.indexName, options.eventId)
      ),
    ]);

    const sourceData = getOr({}, 'hits.hits.0._source', searchResponse);
    const hitsData = getOr({}, 'hits.hits.0', searchResponse);
    delete hitsData._source;

    return {
      data: getSchemaFromData(
        {
          ...addBasicElasticSearchProperties(),
          ...getOr({}, [options.indexName, 'mappings', 'properties'], mapResponse),
        },
        getDataFromHits(merge(sourceData, hitsData)),
        getIndexAlias(options.defaultIndex, options.indexName)
      ),
    };
  }
開發者ID:,項目名稱:,代碼行數:32,代碼來源:

示例2: getUncommonProcesses

  public async getUncommonProcesses(
    request: FrameworkRequest,
    options: RequestOptions
  ): Promise<UncommonProcessesData> {
    const response = await this.framework.callWithRequest<UncommonProcessData, TermAggregation>(
      request,
      'search',
      buildQuery(options)
    );
    const { cursor, limit } = options.pagination;
    const totalCount = getOr(0, 'aggregations.process_count.value', response);
    const buckets = getOr([], 'aggregations.group_by_process.buckets', response);
    const hits = getHits(buckets);

    const uncommonProcessesEdges = hits.map(hit =>
      formatUncommonProcessesData(options.fields, hit, { ...processFieldsMap, ...userFieldsMap })
    );
    const hasNextPage = uncommonProcessesEdges.length === limit + 1;
    const beginning = cursor != null ? parseInt(cursor!, 10) : 0;
    const edges = uncommonProcessesEdges.splice(beginning, limit - beginning);
    return {
      edges,
      totalCount,
      pageInfo: {
        hasNextPage,
        endCursor: {
          value: String(limit),
          tiebreaker: null,
        },
      },
    };
  }
開發者ID:,項目名稱:,代碼行數:32,代碼來源:

示例3: getNetworkDns

  public async getNetworkDns(
    request: FrameworkRequest,
    options: NetworkDnsRequestOptions
  ): Promise<NetworkTopNFlowData> {
    const response = await this.framework.callWithRequest<NetworkTopNFlowData, TermAggregation>(
      request,
      'search',
      buildDnsQuery(options)
    );
    const { cursor, limit } = options.pagination;
    const totalCount = getOr(0, 'aggregations.dns_count.value', response);
    const networkDnsEdges: NetworkDnsEdges[] = formatDnsEdges(
      getOr([], 'aggregations.dns_name_query_count.buckets', response)
    );
    const hasNextPage = networkDnsEdges.length > limit;
    const beginning = cursor != null ? parseInt(cursor, 10) : 0;
    const edges = networkDnsEdges.splice(beginning, limit - beginning);

    return {
      edges,
      totalCount,
      pageInfo: {
        hasNextPage,
        endCursor: {
          value: String(limit),
          tiebreaker: null,
        },
      },
    };
  }
開發者ID:,項目名稱:,代碼行數:30,代碼來源:

示例4: getOr

 ).map((bucket: AuthenticationBucket) => ({
   _id: bucket.authentication.hits.hits[0]._id,
   _source: {
     lastSuccess: getOr(null, 'successes.lastSuccess.hits.hits[0]._source', bucket),
     lastFailure: getOr(null, 'failures.lastFailure.hits.hits[0]._source', bucket),
   },
   user: bucket.key,
   cursor: bucket.key.user_uid,
   failures: bucket.failures.doc_count,
   successes: bucket.successes.doc_count,
 }));
開發者ID:,項目名稱:,代碼行數:11,代碼來源:

示例5: getKpiHosts

 public async getKpiHosts(
   request: FrameworkRequest,
   options: RequestBasicOptions
 ): Promise<KpiHostsData> {
   const generalQuery: KpiHostsESMSearchBody[] = buildGeneralQuery(options);
   const authQuery: KpiHostsESMSearchBody[] = buildAuthQuery(options);
   const response = await this.framework.callWithRequest<
     KpiHostsGeneralHit | KpiHostsAuthHit,
     TermAggregation
   >(request, 'msearch', {
     body: [...generalQuery, ...authQuery],
   });
   return {
     hosts: getOr(null, 'responses.0.aggregations.hosts.value', response),
     hostsHistogram: getOr(null, 'responses.0.aggregations.hosts_histogram.buckets', response),
     authSuccess: getOr(
       null,
       'responses.1.aggregations.authentication_success.doc_count',
       response
     ),
     authSuccessHistogram: getOr(
       null,
       'responses.1.aggregations.authentication_success_histogram.buckets',
       response
     ),
     authFailure: getOr(
       null,
       'responses.1.aggregations.authentication_failure.doc_count',
       response
     ),
     authFailureHistogram: getOr(
       null,
       'responses.1.aggregations.authentication_failure_histogram.buckets',
       response
     ),
     uniqueSourceIps: getOr(null, 'responses.0.aggregations.unique_source_ips.value', response),
     uniqueSourceIpsHistogram: getOr(
       null,
       'responses.0.aggregations.unique_source_ips_histogram.buckets',
       response
     ),
     uniqueDestinationIps: getOr(
       null,
       'responses.0.aggregations.unique_destination_ips.value',
       response
     ),
     uniqueDestinationIpsHistogram: getOr(
       null,
       'responses.0.aggregations.unique_destination_ips_histogram.buckets',
       response
     ),
   };
 }
開發者ID:,項目名稱:,代碼行數:53,代碼來源:

示例6: getIpDetails

 public async getIpDetails(
   request: FrameworkRequest,
   options: IpOverviewRequestOptions
 ): Promise<IpOverviewData> {
   const response = await this.framework.callWithRequest<IpOverviewHit, TermAggregation>(
     request,
     'search',
     buildOverviewQuery(options)
   );
   return {
     ...getIpOverviewAgg('source', getOr({}, 'aggregations.source', response)),
     ...getIpOverviewAgg('destination', getOr({}, 'aggregations.destination', response)),
   };
 }
開發者ID:,項目名稱:,代碼行數:14,代碼來源:

示例7: persistFavorite

  public async persistFavorite(
    request: FrameworkRequest,
    timelineId: string | null
  ): Promise<ResponseFavoriteTimeline> {
    let timeline: SavedTimeline = {};
    if (timelineId != null) {
      const {
        eventIdToNoteIds,
        notes,
        noteIds,
        pinnedEventIds,
        pinnedEventsSaveObject,
        savedObjectId,
        version,
        ...savedTimeline
      } = await this.getBasicSavedTimeline(request, timelineId);
      timelineId = savedObjectId;
      timeline = savedTimeline;
    }
    const userName = getOr(null, 'credentials.username', request[internalFrameworkRequest].auth);
    const fullName = getOr(null, 'credentials.fullname', request[internalFrameworkRequest].auth);
    const userFavoriteTimeline = {
      fullName,
      userName,
      favoriteDate: new Date().valueOf(),
    };
    if (timeline.favorite != null) {
      const alreadyExistsTimelineFavoriteByUser = timeline.favorite.findIndex(
        user => user.userName === userName
      );

      timeline.favorite =
        alreadyExistsTimelineFavoriteByUser > -1
          ? [
              ...timeline.favorite.slice(0, alreadyExistsTimelineFavoriteByUser),
              ...timeline.favorite.slice(alreadyExistsTimelineFavoriteByUser + 1),
            ]
          : [...timeline.favorite, userFavoriteTimeline];
    } else if (timeline.favorite == null) {
      timeline.favorite = [userFavoriteTimeline];
    }

    const persistResponse = await this.persistTimeline(request, timelineId, null, timeline);
    return {
      savedObjectId: persistResponse.timeline.savedObjectId,
      version: persistResponse.timeline.version,
      favorite: persistResponse.timeline.favorite != null ? persistResponse.timeline.favorite : [],
    };
  }
開發者ID:,項目名稱:,代碼行數:49,代碼來源:

示例8: formatTopNFlowEdges

const getTopNFlowEdges = (
  response: DatabaseSearchResponse<NetworkTopNFlowData, TermAggregation>,
  options: NetworkTopNFlowRequestOptions
): NetworkTopNFlowEdges[] => {
  if (options.flowDirection === FlowDirection.uniDirectional) {
    return formatTopNFlowEdges(
      getOr([], 'aggregations.top_uni_flow.buckets', response),
      options.flowTarget
    );
  }
  return formatTopNFlowEdges(
    getOr([], 'aggregations.top_bi_flow.buckets', response),
    options.flowTarget
  );
};
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例9: getEvents

  public async getEvents(request: FrameworkRequest, options: RequestOptions): Promise<EventsData> {
    const queryOptions = cloneDeep(options);
    queryOptions.fields = reduceFields(options.fields, eventFieldsMap);
    const response = await this.framework.callWithRequest<EventHit, TermAggregation>(
      request,
      'search',
      buildQuery(queryOptions)
    );

    const kpiEventType: KpiItem[] =
      response.aggregations && response.aggregations.count_event_type
        ? response.aggregations.count_event_type.buckets.map(item => ({
            value: item.key,
            count: item.doc_count,
          }))
        : [];
    const { limit } = options.pagination;
    const totalCount = getOr(0, 'hits.total.value', response);
    const hits = response.hits.hits;
    const eventsEdges: EcsEdges[] = hits.map(hit =>
      formatEventsData(options.fields, hit, eventFieldsMap)
    );
    const hasNextPage = eventsEdges.length === limit + 1;
    const edges = hasNextPage ? eventsEdges.splice(0, limit) : eventsEdges;
    const lastCursor = get('cursor', last(edges));
    return { kpiEventType, edges, totalCount, pageInfo: { hasNextPage, endCursor: lastCursor } };
  }
開發者ID:,項目名稱:,代碼行數:27,代碼來源:

示例10: getTimelineData

 public async getTimelineData(
   request: FrameworkRequest,
   options: EventsRequestOptions
 ): Promise<TimelineData> {
   const queryOptions = cloneDeep(options);
   queryOptions.fields = uniq([
     ...queryOptions.fieldRequested,
     ...reduceFields(queryOptions.fields, eventFieldsMap),
   ]);
   delete queryOptions.fieldRequested;
   const response = await this.framework.callWithRequest<EventHit, TermAggregation>(
     request,
     'search',
     buildQuery(queryOptions)
   );
   const { limit } = options.pagination;
   const totalCount = getOr(0, 'hits.total.value', response);
   const hits = response.hits.hits;
   const timelineEdges: TimelineEdges[] = hits.map(hit =>
     formatTimelineData(options.fieldRequested, options.fields, hit, eventFieldsMap)
   );
   const hasNextPage = timelineEdges.length === limit + 1;
   const edges = hasNextPage ? timelineEdges.splice(0, limit) : timelineEdges;
   const lastCursor = get('cursor', last(edges));
   return { edges, totalCount, pageInfo: { hasNextPage, endCursor: lastCursor } };
 }
開發者ID:,項目名稱:,代碼行數:26,代碼來源:


注:本文中的lodash/fp.getOr函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。