Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support triple quoted JSON strings and Painless highlighting to Watcher and SearchProfiler #57563

Merged
merged 16 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
useRequestReadContext,
} from '../../../../contexts';

import * as utils from '../../../../../lib/utils/utils';
import { expandLiteralStrings } from '../../../../../../../es_ui_shared/console_lang/lib';

import { subscribeResizeChecker } from '../subscribe_console_resize_checker';
import { applyCurrentSettings } from './apply_editor_settings';
Expand Down Expand Up @@ -67,7 +67,7 @@ function EditorOutputUI() {
editor.update(
data
.map(d => d.response.value as string)
.map(readOnlySettings.tripleQuotes ? utils.expandLiteralStrings : a => a)
.map(readOnlySettings.tripleQuotes ? expandLiteralStrings : a => a)
.join('\n')
);
} else if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
* under the License.
*/

import * as utils from '../../../lib/utils/utils';
import { extractDeprecationMessages } from '../../../lib/utils';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/console_lang/lib';
// @ts-ignore
import * as es from '../../../lib/es/es';
import { BaseResponseType } from '../../../types/common';
import { BaseResponseType } from '../../../types';

export interface EsRequestArgs {
requests: any;
Expand Down Expand Up @@ -73,7 +74,7 @@ export function sendRequestToES(args: EsRequestArgs): Promise<ESRequestResult[]>
const req = requests.shift();
const esPath = req.url;
const esMethod = req.method;
let esData = utils.collapseLiteralStrings(req.data.join('\n'));
let esData = collapseLiteralStrings(req.data.join('\n'));
if (esData) {
esData += '\n';
} // append a new line for bulk requests.
Expand All @@ -97,7 +98,7 @@ export function sendRequestToES(args: EsRequestArgs): Promise<ESRequestResult[]>

const warnings = xhr.getResponseHeader('warning');
if (warnings) {
const deprecationMessages = utils.extractDeprecationMessages(warnings);
const deprecationMessages = extractDeprecationMessages(warnings);
value = deprecationMessages.join('\n') + '\n' + value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import ace from 'brace';
import { workerModule } from './worker';

const oop = ace.acequire('ace/lib/oop');
const TextMode = ace.acequire('ace/mode/text').Mode;
Expand All @@ -29,7 +30,6 @@ const WorkerClient = ace.acequire('ace/worker/worker_client').WorkerClient;
const AceTokenizer = ace.acequire('ace/tokenizer').Tokenizer;

const HighlightRules = require('./input_highlight_rules').InputHighlightRules;
import { workerModule } from './worker';

export function Mode() {
this.$tokenizer = new AceTokenizer(new HighlightRules().getRules());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const ace = require('brace');
import { addToRules } from './x_json_highlight_rules';
import { addXJsonToRules } from '../../../../../../es_ui_shared/console_lang';

export function addEOL(tokens, reg, nextIfEOL, normalNext) {
if (typeof reg === 'object') {
Expand Down Expand Up @@ -101,7 +101,7 @@ export function InputHighlightRules() {
),
};

addToRules(this);
addXJsonToRules(this);

if (this.constructor === InputHighlightRules) {
this.normalizeRules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

const ace = require('brace');
import 'brace/mode/json';
import { addToRules } from './x_json_highlight_rules';
import { addXJsonToRules } from '../../../../../../es_ui_shared/console_lang';

const oop = ace.acequire('ace/lib/oop');
const JsonHighlightRules = ace.acequire('ace/mode/json_highlight_rules').JsonHighlightRules;

export function OutputJsonHighlightRules() {
this.$rules = {};

addToRules(this, 'start');
addXJsonToRules(this, 'start');

this.$rules.start.unshift(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
*/

import ace from 'brace';
import { ScriptHighlightRules } from '../../../../../../es_ui_shared/console_lang';

const oop = ace.acequire('ace/lib/oop');
const TextMode = ace.acequire('ace/mode/text').Mode;
const MatchingBraceOutdent = ace.acequire('ace/mode/matching_brace_outdent').MatchingBraceOutdent;
const CstyleBehaviour = ace.acequire('ace/mode/behaviour/cstyle').CstyleBehaviour;
const CStyleFoldMode = ace.acequire('ace/mode/folding/cstyle').FoldMode;
//const WorkerClient = ace.acequire('ace/worker/worker_client').WorkerClient;
ace.acequire('ace/tokenizer');

const ScriptHighlightRules = require('./script_highlight_rules').ScriptHighlightRules;

export function ScriptMode() {
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour();
Expand Down Expand Up @@ -57,19 +55,4 @@ oop.inherits(ScriptMode, TextMode);
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};

// this.createWorker = function (session) {
// const worker = new WorkerClient(['ace', 'sense_editor'], 'sense_editor/mode/worker', 'SenseWorker', 'sense_editor/mode/worker');
// worker.attachToDocument(session.getDocument());

// worker.on('error', function (e) {
// session.setAnnotations([e.data]);
// });

// worker.on('ok', function (anno) {
// session.setAnnotations(anno.data);
// });

// return worker;
// };
}.call(ScriptMode.prototype));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export declare const workerModule: { id: string; src: string };
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import $ from 'jquery';
import _ from 'lodash';

import { create } from '../create';
import { collapseLiteralStrings } from '../../../../../../es_ui_shared/console_lang/lib';
const editorInput1 = require('./editor_input1.txt');
const utils = require('../../../../lib/utils/utils');

describe('Editor', () => {
let input;
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Editor', () => {
const expected = {
method: 'POST',
url: '_search',
data: [utils.collapseLiteralStrings(simpleRequest.data)],
data: [collapseLiteralStrings(simpleRequest.data)],
};

compareRequest(request, expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import _ from 'lodash';
import RowParser from '../../../lib/row_parser';
import * as utils from '../../../lib/utils/utils';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/console_lang/lib';
import * as utils from '../../../lib/utils';

// @ts-ignore
import * as es from '../../../lib/es/es';

Expand Down Expand Up @@ -480,7 +482,7 @@ export class SenseEditor {
let ret = 'curl -X' + esMethod + ' "' + url + '"';
if (esData && esData.length) {
ret += " -H 'Content-Type: application/json' -d'\n";
const dataAsString = utils.collapseLiteralStrings(esData.join('\n'));
const dataAsString = collapseLiteralStrings(esData.join('\n'));
// since Sense doesn't allow single quote json string any single qoute is within a string.
ret += dataAsString.replace(/'/g, '\\"');
if (esData.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

import '../../application/models/sense_editor/sense_editor.test.mocks';

import $ from 'jquery';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
// @ts-ignore
} from '../kb/kb';

import * as utils from '../utils/utils';
import * as utils from '../utils';

// @ts-ignore
import { populateContext } from './engine';
Expand Down
Loading