"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.isPartialResponse = exports.isErrorResponse = exports.isCompleteResponse = exports.getUserTimeZone = void 0; var _momentTimezone = _interopRequireDefault(require("moment-timezone")); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ /** * From https://github.com/elastic/elasticsearch/issues/55572: "When is_running is false, the query has stopped, which * may happen due to ... the search failed, in which case is_partial is set to true to indicate that any results that * may be included in the search response come only from a subset of the shards that the query should have hit." * @returns true if response had an error while executing in ES */ const isErrorResponse = response => { var _response$rawResponse, _response$rawResponse2; return !response || !response.rawResponse || !response.isRunning && !!response.isPartial && // See https://github.com/elastic/elasticsearch/pull/97731. For CCS with ccs_minimize_roundtrips=true, isPartial // is true if the search is complete but there are shard failures. In that case, the _clusters.details section // will have information about those failures. This will also likely be the behavior of CCS with // ccs_minimize_roundtrips=false and non-CCS after https://github.com/elastic/elasticsearch/issues/98913 is // resolved. !((_response$rawResponse = response.rawResponse) !== null && _response$rawResponse !== void 0 && (_response$rawResponse2 = _response$rawResponse._clusters) !== null && _response$rawResponse2 !== void 0 && _response$rawResponse2.details); }; /** * @returns true if response is completed successfully */ exports.isErrorResponse = isErrorResponse; const isCompleteResponse = response => { // Some custom search strategies do not indicate whether they are still running. In this case, assume it is complete. if (response && !response.hasOwnProperty('isRunning')) { return true; } return !isErrorResponse(response) && Boolean(response && !response.isRunning); }; /** * @returns true if request is still running an/d response contains partial results */ exports.isCompleteResponse = isCompleteResponse; const isPartialResponse = response => { return Boolean(response && response.isRunning && response.isPartial); }; exports.isPartialResponse = isPartialResponse; const getUserTimeZone = (getConfig, shouldDetectTimezone = true) => { const defaultTimeZone = 'UTC'; const userTimeZone = getConfig('dateFormat:tz'); if (userTimeZone === 'Browser') { if (!shouldDetectTimezone) { return defaultTimeZone; } // If the typeMeta data index template does not have a timezone assigned to the selected field, use the configured tz const detectedTimezone = _momentTimezone.default.tz.guess(); const tzOffset = (0, _momentTimezone.default)().format('Z'); return detectedTimezone || tzOffset; } return userTimeZone !== null && userTimeZone !== void 0 ? userTimeZone : defaultTimeZone; }; exports.getUserTimeZone = getUserTimeZone;