Skip to content

Commit

Permalink
fix: suport multipline of Painless script (#115)
Browse files Browse the repository at this point in the history
fix: summary title of the PR

transform script format to valid JSON before send to the server

Refs: #113

---------

Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll authored Oct 13, 2024
1 parent 38585b5 commit 7f9d7b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: |
echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
Expand Down
29 changes: 15 additions & 14 deletions src/common/monaco/lexerRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ export const search = {
{ include: '@json5' },
],
json5: [
[
/["']?(.*_?script|inline|source)["']?(\s*?)(:)(\s*?)("""|''')/,
[
'variable',
'whitespace',
'delimiter',
'whitespace',
{
token: 'punctuation.start_triple_quote',
nextEmbedded: 'painless',
next: 'search_painless',
},
],
],
// @TODO add painless highlighting & tokenization support
// [
// /["']?(.*_?script|inline|source)["']?(\s*?)(:)(\s*?)("""|''')/,
// [
// 'variable',
// 'whitespace',
// 'delimiter',
// 'whitespace',
// {
// token: 'punctuation.start_triple_quote',
// nextEmbedded: 'painless',
// next: 'search_painless',
// },
// ],
// ],
[
/(:)(\s*?)("""|''')(sql)/,
[
Expand Down
10 changes: 8 additions & 2 deletions src/common/monaco/tokenlizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export const formatQDSL = (
return lines.map(line => JSON5.stringify(line)).join('\n');
};

const replaceTripleQuotes = (value: string) =>
value
.replace(/'''(.*?)'''/gs, (_, match) => JSON.stringify(match))
.replace(/"""(.*?)"""/gs, (_, match) => JSON.stringify(match));

export const transformQDSL = ({ path, qdsl }: Pick<SearchAction, 'path' | 'qdsl'>) => {
try {
const bulkAction = path.includes('_bulk');
Expand All @@ -138,7 +143,7 @@ export const transformQDSL = ({ path, qdsl }: Pick<SearchAction, 'path' | 'qdsl'
return `${bulkQdsl}\n`;
}

return qdsl ? JSON.stringify(JSON5.parse(qdsl), null, 2) : undefined;
return qdsl ? JSON.stringify(JSON5.parse(replaceTripleQuotes(qdsl)), null, 2) : undefined;
} catch (err) {
throw new CustomError(400, (err as Error).message);
}
Expand Down Expand Up @@ -169,7 +174,8 @@ export const transformToCurl = ({
.join('');
}
if (qdsl) {
curlCmd += ` -d '${transformQDSL({ path: url, qdsl })}'`;
const qdslCmd = transformQDSL({ path: url, qdsl })?.replace(/'/g, "'\\''");
curlCmd += ` -d '${qdslCmd}'`;
}

return curlCmd;
Expand Down

0 comments on commit 7f9d7b0

Please sign in to comment.