@finos/legend-application-pure-ide
Version:
Legend Pure IDE application core
186 lines • 8.81 kB
JavaScript
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed 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.
*/
import {} from '../server/models/Test.js';
import { FIND_USAGE_FUNCTION_PATH, } from '../server/models/Usage.js';
import { guaranteeNonNullable, } from '@finos/legend-shared';
import { ROOT_PACKAGE_PATH } from '../stores/PureIDEConfig.js';
export class PureServerClient {
networkClient;
// Pure IDE info
userId = 'localuser';
sessionId = `${this.userId}@${Date.now()}`; // dummy session ID
compilerMode;
mode;
constructor(networkClient) {
this.networkClient = networkClient;
}
get baseUrl() {
return guaranteeNonNullable(this.networkClient.baseUrl, `Pure server client has not been configured properly`);
}
initialize = (requestCache) => this.networkClient.get(`${this.baseUrl}/initialize`, undefined, undefined, {
requestCache,
// checkFileConflict
sessionId: this.sessionId,
mode: this.mode,
fastCompile: this.compilerMode,
});
getInitializationActivity = () => this.networkClient.get(`${this.baseUrl}/initializationActivity`, undefined, undefined, {
sessionId: this.sessionId,
});
getConceptActivity = () => this.networkClient.get(`${this.baseUrl}/conceptsActivity`, undefined, undefined, {
sessionId: this.sessionId,
});
execute = (openFiles, url, extraParams) => this.networkClient.post(`${this.baseUrl}/${url}`, {
extraParams,
openFiles,
}, undefined, undefined, {
sessionId: this.sessionId,
mode: this.mode,
fastCompile: this.compilerMode,
});
getExecutionActivity = () => this.networkClient.get(`${this.baseUrl}/executionActivity`, undefined, undefined, {
sessionId: this.sessionId,
});
// ------------------------------------------- Search -------------------------------------------
findFiles = (searchText, isRegExp) => this.networkClient.get(`${this.baseUrl}/findPureFiles`, undefined, undefined, {
file: searchText,
regex: isRegExp,
});
searchText = (searchText, isCaseSensitive, isRegExp, limit = 100) => this.networkClient.get(`${this.baseUrl}/findInSources`, undefined, undefined, {
string: searchText,
caseSensitive: isCaseSensitive,
regex: isRegExp,
limit,
});
getTextSearchPreview = (coordinates) => this.networkClient.post(`${this.baseUrl}/getTextSearchPreview`, coordinates);
// ------------------------------------------- Test -------------------------------------------
checkTestRunner = (testRunnerId) => this.networkClient.get(`${this.baseUrl}/testRunnerCheck`, undefined, undefined, {
sessionId: this.sessionId,
testRunnerId,
});
cancelTestRunner = (testRunnerId) => this.networkClient.get(`${this.baseUrl}/testRunnerCancel`, undefined, undefined, {
sessionId: this.sessionId,
testRunnerId,
});
getPCTAdapters = async () => {
const result = await this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func: 'meta::pure::ide::testing::getPCTAdapters__Pair_MANY_',
});
return (Array.isArray(result) ? result : [result]);
};
// ------------------------------------------- Concept -------------------------------------------
getConceptChildren = (path) => this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func: 'meta::pure::ide::display_ide(String[1]):String[1]',
param: path ? `'${path}'` : `'${ROOT_PACKAGE_PATH}'`,
format: 'raw',
mode: this.mode,
sessionId: this.sessionId,
});
getConceptInfo = async (file, line, column) => {
const result = await this.networkClient.get(`${this.baseUrl}/getConceptInfo`, undefined, undefined, {
file,
line,
column,
});
if (result.error) {
throw new Error(result.text);
}
return result;
};
getUsages = async (func, param) => {
const result = await this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func,
param,
});
return (Array.isArray(result) ? result : [result]);
};
renameConcept = (input) => this.networkClient.put(`${this.baseUrl}/renameConcept`, input);
movePackageableElements = (inputs) => this.networkClient.put(`${this.baseUrl}/movePackageableElements`, inputs);
getPackageableElementsUsage = async (paths) => {
const result = await this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func: FIND_USAGE_FUNCTION_PATH.MULTIPLE_PATHS,
param: [`'${paths.join(',')}'`],
});
return (Array.isArray(result) ? result : [result]);
};
getChildPackageableElements = async (packagePath) => {
const result = await this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func: 'meta::pure::ide::getChildPackageableElements_String_1__String_MANY_',
param: [`'${packagePath}'`],
});
return (Array.isArray(result) ? result : [result]).map((child) => JSON.parse(child));
};
// ------------------------------------------- IO / File Management -------------------------------------------
getFile = (path) => this.networkClient.get(`${this.baseUrl}/fileAsJson/${path}`, undefined, undefined, {
sessionId: this.sessionId,
mode: this.mode,
fastCompile: this.compilerMode,
});
getDirectoryChildren = (path) => this.networkClient.get(`${this.baseUrl}/dir`, undefined, undefined, {
parameters: path ?? '/',
mode: this.mode,
sessionId: this.sessionId,
});
updateSource = (updateInputs) => this.networkClient.put(`${this.baseUrl}/updateSource`, updateInputs);
createFile = (path) => this.networkClient.post(`${this.baseUrl}/newFile/${path}`, undefined, undefined, undefined, {
sessionId: this.sessionId,
mode: this.mode,
fastCompile: this.compilerMode,
});
createFolder = (path) => this.networkClient.post(`${this.baseUrl}/newFolder/${path}`, undefined, undefined, undefined, {
sessionId: this.sessionId,
mode: this.mode,
fastCompile: this.compilerMode,
});
renameFile = (oldPath, newPath) => this.networkClient.put(`${this.baseUrl}/renameFile`, {
oldPath,
newPath,
}, undefined);
deleteDirectoryOrFile = (path) => this.networkClient.delete(`${this.baseUrl}/deleteFile/${path}`, undefined, undefined, undefined, {
sessionId: this.sessionId,
});
// ------------------------------------------- Diagram -------------------------------------------
getDiagramInfo = async (diagramPath) => JSON.parse(await this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func: 'meta::pure::ide::diagram::getDiagramInfo_String_1__String_1_',
param: [`'${diagramPath}'`],
}));
getDiagramClassInfo = async (classPath) => JSON.parse(await this.networkClient.get(`${this.baseUrl}/execute`, undefined, undefined, {
func: 'meta::pure::ide::diagram::getDiagramClassInfo_String_1__String_1_',
param: [`'${classPath}'`],
}));
// ------------------------------------------- Suggestion -------------------------------------------
getSuggestionsForIncompletePath = (currentPackagePath, types) => this.networkClient.post(`${this.baseUrl}/suggestion/incompletePath`, {
path: currentPackagePath,
types,
});
getSuggestionsForIdentifier = (importPaths, types) => this.networkClient.post(`${this.baseUrl}/suggestion/identifier`, {
importPaths,
types,
});
getSuggestionsForAttribute = (importPaths, path) => this.networkClient.post(`${this.baseUrl}/suggestion/attribute`, {
importPaths,
path,
});
getSuggestionsForClass = (importPaths) => this.networkClient.post(`${this.baseUrl}/suggestion/class`, {
importPaths,
});
getSuggestionsForVariable = (sourceId, line, column) => this.networkClient.post(`${this.baseUrl}/suggestion/variable`, {
sourceId,
line,
column,
});
}
//# sourceMappingURL=PureServerClient.js.map