-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
297 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
export const searchTokensProvider = { | ||
// Set defaultToken to invalid to see what you do not tokenize yet | ||
defaultToken: 'invalid', | ||
tokenPostfix: '.search', | ||
|
||
// keywords of elasticsearch | ||
keywords: [ | ||
'GET', | ||
'POST', | ||
'PUT', | ||
'DELETE', | ||
'HEAD', | ||
'OPTIONS', | ||
'PATCH', | ||
'TRACE', | ||
'index', | ||
'indices', | ||
'type', | ||
'types', | ||
'from', | ||
'size', | ||
'explain', | ||
'analyze', | ||
'default_operator', | ||
'df', | ||
'analyzer', | ||
'lenient', | ||
'lowercase_expanded_terms', | ||
'analyze_wildcard', | ||
'all_shards', | ||
'allow_no_indices', | ||
'expand_wildcards', | ||
'preference', | ||
'routing', | ||
'ignore_unavailable', | ||
'allow_no_indices', | ||
'ignore_throttled', | ||
'search_type', | ||
'batched_reduce_size', | ||
'ccs_minimize_roundtrips', | ||
'max_concurrent_shard_requests', | ||
'pre_filter_shard_size', | ||
'rest_total_hits_as_int', | ||
'scroll', | ||
'search_type', | ||
'typed_keys', | ||
'wait_for_active_shards', | ||
'wait_for_completion', | ||
'requests_per_second', | ||
'slices', | ||
'timeout', | ||
'terminate_after', | ||
'stats', | ||
'version', | ||
'version_type', | ||
'if_seq_no', | ||
'if_primary_term', | ||
'refresh', | ||
'routing', | ||
'parent', | ||
'preference', | ||
'realtime', | ||
'refresh', | ||
'retry_on_conflict', | ||
'timeout', | ||
'version', | ||
'version_type', | ||
'if_seq_no', | ||
'if_primary_term', | ||
'pipeline', | ||
'wait_for_active_shards', | ||
'wait_for_completion', | ||
'requests_per_second', | ||
'slices', | ||
'timeout', | ||
'terminate_after', | ||
'stats', | ||
'version', | ||
'version_type', | ||
'if_seq_no', | ||
'if_primary_term', | ||
'refresh', | ||
'routing', | ||
'parent', | ||
'preference', | ||
'realtime', | ||
'refresh', | ||
'retry_on_conflict', | ||
'timeout', | ||
'version', | ||
'version_type', | ||
'if_seq_no', | ||
'if_primary_term', | ||
'pipeline', | ||
'wait_for_active_shards', | ||
'wait_for_completion', | ||
'requests_per_second', | ||
'slices', | ||
'timeout', | ||
'terminate_after', | ||
'stats', | ||
'version', | ||
'version_type', | ||
'_search', | ||
], | ||
|
||
typeKeywords: ['any', 'boolean', 'number', 'object', 'string', 'undefined'], | ||
|
||
// we include these common regular expressions | ||
symbols: /[=><!~?:&|+\-*\\^%]+/, | ||
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, | ||
digits: /\d+(_+\d+)*/, | ||
octaldigits: /[0-7]+(_+[0-7]+)*/, | ||
binarydigits: /[0-1]+(_+[0-1]+)*/, | ||
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/, | ||
|
||
// The main tokenizer for our languages | ||
tokenizer: { | ||
root: [ | ||
[/^(GET|DELETE|POST|PUT)\s\w+/, 'action-execute-decoration'], | ||
[/[{}]/, 'delimiter.bracket'], | ||
{ include: 'common' }, | ||
], | ||
|
||
common: [ | ||
// identifiers and keywords | ||
[ | ||
/[a-z_$][\w$]*/, | ||
{ | ||
cases: { | ||
'@typeKeywords': 'keyword', | ||
'@keywords': 'keyword', | ||
'@default': 'identifier', | ||
}, | ||
}, | ||
], | ||
|
||
// whitespace | ||
{ include: '@whitespace' }, | ||
// json block | ||
{ include: '@json' }, | ||
], | ||
|
||
json: [ | ||
// JSON strings | ||
[/"(?:\\.|[^\\"])*"/, 'string'], | ||
|
||
// JSON numbers | ||
[/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/, 'number'], | ||
|
||
// JSON booleans | ||
[/\b(?:true|false)\b/, 'keyword'], | ||
|
||
// JSON null | ||
[/\bnull\b/, 'keyword'], | ||
|
||
// JSON property names | ||
[/"(?:\\.|[^\\"])*"(?=\s*:)/, 'key'], | ||
|
||
// JSON punctuation | ||
[/[{}[\],:]/, 'delimiter'], | ||
|
||
// JSON whitespace | ||
{ include: '@whitespace' }, | ||
], | ||
|
||
whitespace: [ | ||
[/[ \t\r\n]+/, ''], | ||
[/\/\*\*(?!\/)/, 'comment.doc'], | ||
[/\/\*/, 'comment', '@comment'], | ||
[/\/\/.*$/, 'comment'], | ||
], | ||
|
||
comment: [ | ||
[/[^/*]+/, 'comment'], | ||
[/\*\//, 'comment', '@pop'], | ||
[/[/*]/, 'comment'], | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Electron from 'electron'; | ||
import { readFile, writeFile, mkdir } from 'fs/promises'; | ||
import { existsSync } from 'fs'; | ||
import path from 'path'; | ||
import { debug } from '../common/debug'; | ||
|
||
export enum sourceFileApiMethods { | ||
SAVE_FILE = 'SAVE_FILE', | ||
READ_FILE = 'READ_FILE', | ||
} | ||
|
||
export type SourceFileApiInput = { | ||
method: sourceFileApiMethods; | ||
fileName: string; | ||
content: string; | ||
}; | ||
|
||
const saveFile = async (filePath: string, content: string) => { | ||
const resolvedPath = path.resolve(__dirname, filePath); | ||
try { | ||
await writeFile(resolvedPath, content, 'utf-8'); | ||
debug('save file success'); | ||
} catch (err) { | ||
debug(`saveFile error: ${err}`); | ||
throw err; | ||
} | ||
}; | ||
|
||
const readFromFile = async (filePath: string) => { | ||
const resolvedPath = path.resolve(__dirname, filePath); | ||
debug(`resolvedPath: ${resolvedPath}`); | ||
if (!existsSync(resolvedPath)) { | ||
debug('File does not exist. Creating a new file...'); | ||
await mkdir(path.dirname(resolvedPath), { recursive: true }); | ||
await writeFile(resolvedPath, '', { encoding: 'utf-8', flag: 'w+' }); | ||
return ''; | ||
} | ||
|
||
try { | ||
return await readFile(resolvedPath, 'utf-8'); | ||
} catch (err) { | ||
debug(`readFromFile error: ${err}`); | ||
throw err; | ||
} | ||
}; | ||
|
||
const sourceFileApi: { [key: string]: (filePath: string, content: string) => unknown } = { | ||
save_file: (filePath: string, content: string) => saveFile(filePath, content), | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
read_file: (filePath: string, _: string) => readFromFile(filePath), | ||
}; | ||
|
||
export const registerSourceFileApiListener = (ipcMain: Electron.IpcMain) => { | ||
ipcMain.handle('sourceFileAPI', (_, { content, method }: SourceFileApiInput) => | ||
sourceFileApi[method.toLowerCase()]('./data/default.search', content), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineStore } from 'pinia'; | ||
|
||
const { sourceFileAPI } = window; | ||
export const useSourceFileStore = defineStore('sourceFileStore', { | ||
state(): { defaultFile: string } { | ||
return { | ||
defaultFile: '', | ||
}; | ||
}, | ||
getters: {}, | ||
actions: { | ||
async readSourceFromFile() { | ||
this.defaultFile = await sourceFileAPI.readFile(); | ||
}, | ||
async saveSourceToFile(content: string) { | ||
this.defaultFile = content; | ||
await sourceFileAPI.saveFile(content); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.