bmd-extension 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +14 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +9 -0
- package/DEPLOY.md +4 -0
- package/README.md +17 -0
- package/README_PRIVATE.md +1 -0
- package/build.sh +5 -0
- package/logo.png +0 -0
- package/media/dark/add.svg +40 -0
- package/media/dark/block.svg +1 -0
- package/media/dark/checklist-1.svg +1 -0
- package/media/dark/checklist.svg +1 -0
- package/media/dark/control.svg +1 -0
- package/media/dark/create.svg +1 -0
- package/media/dark/delete-1.svg +1 -0
- package/media/dark/delete.svg +1 -0
- package/media/dark/deploy-1.svg +2 -0
- package/media/dark/deploy.svg +2 -0
- package/media/dark/documents.svg +66 -0
- package/media/dark/earth.svg +68 -0
- package/media/dark/exe.svg +15 -0
- package/media/dark/export.svg +1 -0
- package/media/dark/function.svg +1 -0
- package/media/dark/game-controller.svg +77 -0
- package/media/dark/get.svg +1 -0
- package/media/dark/id-card.svg +59 -0
- package/media/dark/identity.svg +81 -0
- package/media/dark/import.svg +1 -0
- package/media/dark/information.svg +1 -0
- package/media/dark/interface.svg +1 -0
- package/media/dark/layout.svg +41 -0
- package/media/dark/leaf.svg +54 -0
- package/media/dark/list.svg +13 -0
- package/media/dark/logo.svg +249 -0
- package/media/dark/mockup.svg +1 -0
- package/media/dark/needle.svg +1 -0
- package/media/dark/pass.svg +46 -0
- package/media/dark/plus.svg +1 -0
- package/media/dark/post.svg +1 -0
- package/media/dark/quit.svg +1 -0
- package/media/dark/rocket.svg +28 -0
- package/media/dark/service.svg +1 -0
- package/media/dark/settings.svg +98 -0
- package/media/dark/social.svg +1 -0
- package/media/dark/spaceship-1.svg +1 -0
- package/media/dark/spaceship-2.svg +1 -0
- package/media/dark/spaceship.svg +1 -0
- package/media/dark/support.svg +88 -0
- package/media/dark/transfer.svg +1 -0
- package/media/dark/transform.svg +92 -0
- package/media/dark/update.svg +45 -0
- package/media/dark/upload-1.svg +1 -0
- package/media/dark/upload.svg +41 -0
- package/media/dark/vaccine.svg +1 -0
- package/media/dark/vr-gaming.svg +1 -0
- package/media/light/add.svg +40 -0
- package/media/light/block.svg +1 -0
- package/media/light/checklist-1.svg +1 -0
- package/media/light/checklist.svg +1 -0
- package/media/light/control.svg +1 -0
- package/media/light/create.svg +1 -0
- package/media/light/delete-1.svg +1 -0
- package/media/light/delete.svg +1 -0
- package/media/light/deploy-1.svg +2 -0
- package/media/light/deploy.svg +2 -0
- package/media/light/documents.svg +66 -0
- package/media/light/earth.svg +68 -0
- package/media/light/exe.svg +15 -0
- package/media/light/export.svg +1 -0
- package/media/light/function.svg +1 -0
- package/media/light/game-controller.svg +77 -0
- package/media/light/get.svg +1 -0
- package/media/light/id-card.svg +59 -0
- package/media/light/identity.svg +81 -0
- package/media/light/import.svg +1 -0
- package/media/light/information.svg +1 -0
- package/media/light/interface.svg +1 -0
- package/media/light/layout.svg +41 -0
- package/media/light/leaf.svg +54 -0
- package/media/light/list.svg +13 -0
- package/media/light/logo.svg +249 -0
- package/media/light/mockup.svg +1 -0
- package/media/light/needle.svg +1 -0
- package/media/light/pass.svg +46 -0
- package/media/light/plus.svg +1 -0
- package/media/light/post.svg +1 -0
- package/media/light/quit.svg +1 -0
- package/media/light/rocket.svg +28 -0
- package/media/light/service.svg +1 -0
- package/media/light/settings.svg +98 -0
- package/media/light/social.svg +1 -0
- package/media/light/spaceship-1.svg +1 -0
- package/media/light/spaceship-2.svg +1 -0
- package/media/light/spaceship.svg +1 -0
- package/media/light/support.svg +88 -0
- package/media/light/transfer.svg +1 -0
- package/media/light/transform.svg +92 -0
- package/media/light/update.svg +45 -0
- package/media/light/upload-1.svg +1 -0
- package/media/light/upload.svg +41 -0
- package/media/light/vaccine.svg +1 -0
- package/media/light/vr-gaming.svg +1 -0
- package/package-lock.json +6430 -0
- package/package.json +540 -0
- package/snippets-tsr.json +512 -0
- package/snippets.json +761 -0
- package/src/API.ts +14 -0
- package/src/FsProvider.ts +105 -0
- package/src/Request.ts +24 -0
- package/src/assets/api/api.txt +27 -0
- package/src/assets/configuration/AdminConfigurationController.ts.txt +72 -0
- package/src/assets/configuration/Configuration.ts.txt +37 -0
- package/src/assets/configuration/ConfigurationService.ts.txt +26 -0
- package/src/assets/contentDefine/AdminContentDefineController.ts.txt +91 -0
- package/src/assets/contentDefine/ContentDefine.ts.txt +45 -0
- package/src/assets/contentDefine/ContentDefineService.ts.txt +19 -0
- package/src/assets/contentDefine/CustomerContentDefineController.ts.txt +34 -0
- package/src/assets/controller/controller.txt +46 -0
- package/src/assets/controller/controllerResource.txt +103 -0
- package/src/assets/entity/entity.txt +22 -0
- package/src/assets/entity-request/entity-request.txt +18 -0
- package/src/assets/init/.env.example.txt +37 -0
- package/src/assets/init/.env.production.txt +37 -0
- package/src/assets/init/.gitignore.txt +8 -0
- package/src/assets/init/config.ts.txt +55 -0
- package/src/assets/init/deploy.sh.txt +46 -0
- package/src/assets/init/package-lock.json.txt +4184 -0
- package/src/assets/init/package.json.txt +79 -0
- package/src/assets/init/src/Server.ts.txt +167 -0
- package/src/assets/init/src/controllers/admin/AuthController.ts.txt +96 -0
- package/src/assets/init/src/controllers/admin/CustomerController.ts.txt +107 -0
- package/src/assets/init/src/controllers/admin/RoleController.ts.txt +143 -0
- package/src/assets/init/src/controllers/admin/StaffController.ts.txt +192 -0
- package/src/assets/init/src/controllers/customer/AuthController.ts.txt +170 -0
- package/src/assets/init/src/controllers/customer/CustomerController.ts.txt +32 -0
- package/src/assets/init/src/core/entity/CoreEntity.ts.txt +70 -0
- package/src/assets/init/src/core/services/CoreService.ts.txt +21 -0
- package/src/assets/init/src/entity/Customer.ts.txt +68 -0
- package/src/assets/init/src/entity/Permission.ts.txt +29 -0
- package/src/assets/init/src/entity/Role.ts.txt +36 -0
- package/src/assets/init/src/entity/Staff.ts.txt +54 -0
- package/src/assets/init/src/entity-request/CustomerInsert.ts.txt +42 -0
- package/src/assets/init/src/entity-request/CustomerUpdate.ts.txt +40 -0
- package/src/assets/init/src/entity-request/PermissionImport.ts.txt +12 -0
- package/src/assets/init/src/entity-request/StaffUpdate.ts.txt +33 -0
- package/src/assets/init/src/index.ts.txt +13 -0
- package/src/assets/init/src/middleware/auth/Verification.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/VerificationJWT.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/strategy/AuthStrategy.ts.txt +5 -0
- package/src/assets/init/src/middleware/auth/strategy/JWT.ts.txt +147 -0
- package/src/assets/init/src/middleware/error/handleError.ts.txt +22 -0
- package/src/assets/init/src/middleware/error/handleNotFound.ts.txt +7 -0
- package/src/assets/init/src/middleware/response/CustomSendResponse.ts.txt +35 -0
- package/src/assets/init/src/middleware/response/responseAPI.ts.txt +76 -0
- package/src/assets/init/src/middleware/validator/Validator.ts.txt +103 -0
- package/src/assets/init/src/services/CustomerService.ts.txt +79 -0
- package/src/assets/init/src/services/InitService.ts.txt +11 -0
- package/src/assets/init/src/services/MailService.ts.txt +271 -0
- package/src/assets/init/src/services/RoleService.ts.txt +66 -0
- package/src/assets/init/src/services/StaffService.ts.txt +104 -0
- package/src/assets/init/src/ssl/certificate-ca.crt +0 -0
- package/src/assets/init/src/ssl/certificate.crt +0 -0
- package/src/assets/init/src/ssl/private.key +0 -0
- package/src/assets/init/src/types/express.d.ts.txt +97 -0
- package/src/assets/init/src/util/expo.ts.txt +53 -0
- package/src/assets/init/src/util/helper.ts.txt +321 -0
- package/src/assets/init/src/util/language.ts.txt +8 -0
- package/src/assets/init/src/util/logger.ts.txt +47 -0
- package/src/assets/init/src/util/mailer.ts.txt +32 -0
- package/src/assets/init/src/util/password.ts.txt +13 -0
- package/src/assets/init/tsconfig.json.txt +26 -0
- package/src/assets/service/service.txt +34 -0
- package/src/constant.ts +83 -0
- package/src/extension.ts +459 -0
- package/src/provider/codeAction/controller/addPathParams.ts +65 -0
- package/src/provider/codeAction/controller/addTokenParam.ts +43 -0
- package/src/provider/codeAction/controller/addValidation.ts +47 -0
- package/src/provider/codeAction/controller/codeAction.ts +34 -0
- package/src/provider/codeAction/controller/util.ts +48 -0
- package/src/provider/codeAction/entity/codeAction.ts +48 -0
- package/src/provider/codeAction/entity/handleBuilder.ts +87 -0
- package/src/provider/codeAction/entity/handleFunction.ts +487 -0
- package/src/provider/codeAction/entity/handleProperty.ts +32 -0
- package/src/provider/codeAction/entity/handleRelation.ts +72 -0
- package/src/provider/codeAction/entity/helper.ts +132 -0
- package/src/provider/codeAction/entity-request/codeAction.ts +178 -0
- package/src/provider/codeAction/enum/codeAction.ts +95 -0
- package/src/provider/codeAction/service/codeAction.ts +232 -0
- package/src/provider/completion/CompletionProvider.ts +108 -0
- package/src/provider/errorChecking/checkHeaderToken.ts +60 -0
- package/src/provider/errorChecking/checkPathParam.ts +64 -0
- package/src/provider/errorChecking/checkRequired.ts +56 -0
- package/src/provider/errorChecking/errorChecking.ts +35 -0
- package/src/provider/errorChecking/util.ts +56 -0
- package/src/provider/treeDataProvider/Dependency.ts +26 -0
- package/src/provider/treeDataProvider/TreeProviderCommand.ts +60 -0
- package/src/provider/treeDataProvider/TreeProviderProject.ts +65 -0
- package/src/provider/treeDataProvider/api/createApi.ts +106 -0
- package/src/provider/treeDataProvider/controller/command/createController.ts +99 -0
- package/src/provider/treeDataProvider/controller/command/handleMethod.ts +363 -0
- package/src/provider/treeDataProvider/controller/treeData.ts +81 -0
- package/src/provider/treeDataProvider/deploy/command/handleDeploy.ts +70 -0
- package/src/provider/treeDataProvider/deploy/treeData.ts +21 -0
- package/src/provider/treeDataProvider/entity/command/addProperty.ts +144 -0
- package/src/provider/treeDataProvider/entity/command/addRelation.ts +125 -0
- package/src/provider/treeDataProvider/entity/command/createEntity.ts +53 -0
- package/src/provider/treeDataProvider/entity/command/createEntityRequest.ts +65 -0
- package/src/provider/treeDataProvider/entity/command/exportInterface.ts +130 -0
- package/src/provider/treeDataProvider/entity/treeData.ts +49 -0
- package/src/provider/treeDataProvider/module/command/configuration.ts +34 -0
- package/src/provider/treeDataProvider/module/command/contentDefine.ts +36 -0
- package/src/provider/treeDataProvider/module/command/initProject.ts +155 -0
- package/src/provider/treeDataProvider/module/treeData.ts +28 -0
- package/src/provider/treeDataProvider/project/command/addEnum.ts +0 -0
- package/src/provider/treeDataProvider/project/command/addProjectName.ts +23 -0
- package/src/provider/treeDataProvider/project/command/getProjectDetails.ts +284 -0
- package/src/provider/treeDataProvider/project/treeData.ts +28 -0
- package/src/provider/treeDataProvider/service/command/createService.ts +70 -0
- package/src/provider/treeDataProvider/service/command/handleConstructor.ts +134 -0
- package/src/provider/treeDataProvider/service/treeData.ts +25 -0
- package/src/types/project.d.ts +7 -0
- package/src/util.ts +145 -0
- package/src/utils/Password.ts +19 -0
- package/tsconfig.json +18 -0
- package/tslint.json +15 -0
- package/vsc-extension-quickstart.md +42 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { createPropertyAction } from './handleProperty';
|
3
|
+
import { createRelationAction } from './handleRelation';
|
4
|
+
import { createBuilderAction } from './handleBuilder';
|
5
|
+
import { createAddRelationFunctionAction, createAddFunctionAction } from './handleFunction';
|
6
|
+
|
7
|
+
|
8
|
+
export class EntityActionProvider implements vscode.CodeActionProvider {
|
9
|
+
|
10
|
+
public static readonly providedCodeActionKinds = [
|
11
|
+
vscode.CodeActionKind.QuickFix
|
12
|
+
];
|
13
|
+
|
14
|
+
public provideCodeActions(
|
15
|
+
document: vscode.TextDocument,
|
16
|
+
range: any
|
17
|
+
): vscode.CodeAction[] | undefined | any {
|
18
|
+
// Add properties to entity file
|
19
|
+
const addPropertiesAction = createPropertyAction(document, range)
|
20
|
+
if (addPropertiesAction && addPropertiesAction.length)
|
21
|
+
return addPropertiesAction
|
22
|
+
|
23
|
+
// // Add relation to entity file
|
24
|
+
// const addRelationAction = createRelationAction(document, range)
|
25
|
+
// if (addRelationAction && addRelationAction.length)
|
26
|
+
// return addRelationAction
|
27
|
+
|
28
|
+
// Add relation to entity function like: find, findOne
|
29
|
+
const addFunctionAction = createAddFunctionAction(document, range)
|
30
|
+
if (addFunctionAction && addFunctionAction.length)
|
31
|
+
return addFunctionAction
|
32
|
+
|
33
|
+
// Add relation to query builder
|
34
|
+
const addBuilderRelationAction = createBuilderAction(document, range)
|
35
|
+
if (addBuilderRelationAction && addBuilderRelationAction.length)
|
36
|
+
return addBuilderRelationAction
|
37
|
+
|
38
|
+
|
39
|
+
// Add relation to entity function like: find, findOne
|
40
|
+
const addRelationFunctionAction = createAddRelationFunctionAction(document, range)
|
41
|
+
if (addRelationFunctionAction && addRelationFunctionAction.length)
|
42
|
+
return addRelationFunctionAction
|
43
|
+
|
44
|
+
return []
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { EntityAction } from '../../../constant';
|
3
|
+
import { getEntityFromFunction, getRelationsEntity, findLastLineRelation } from './helper';
|
4
|
+
import { getFullTextType } from '../../../util';
|
5
|
+
|
6
|
+
export function createBuilderAction(
|
7
|
+
document: vscode.TextDocument, range: vscode.Range
|
8
|
+
) {
|
9
|
+
if (isQueryBuilder(document, range)) {
|
10
|
+
const insertBuilderRelation = createInsertBuilderRelation(document, range);
|
11
|
+
|
12
|
+
return [
|
13
|
+
insertBuilderRelation,
|
14
|
+
];
|
15
|
+
}
|
16
|
+
|
17
|
+
return []
|
18
|
+
}
|
19
|
+
|
20
|
+
function isQueryBuilder(document: vscode.TextDocument, range: vscode.Range) {
|
21
|
+
const start = range.start;
|
22
|
+
const line = document.lineAt(start.line);
|
23
|
+
return line.text.includes('createQueryBuilder')
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
function createInsertBuilderRelation(
|
28
|
+
document: vscode.TextDocument, range: vscode.Range
|
29
|
+
): vscode.CodeAction {
|
30
|
+
const entity = new vscode.CodeAction(EntityAction.AddBuilderRelation, vscode.CodeActionKind.QuickFix);
|
31
|
+
|
32
|
+
entity.command = {
|
33
|
+
command: EntityAction.AddBuilderRelation,
|
34
|
+
title: 'Add builder relation: ',
|
35
|
+
tooltip: 'Add builder relation: ',
|
36
|
+
arguments: [document, range]
|
37
|
+
};
|
38
|
+
|
39
|
+
return entity;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
export async function insertBuilderRelation(typeFunc: EntityAction, document: vscode.TextDocument, range: vscode.Range) {
|
44
|
+
const edit = new vscode.WorkspaceEdit();
|
45
|
+
|
46
|
+
const entityObj = getEntityFromFunction(document, range)
|
47
|
+
const entity = entityObj.text
|
48
|
+
|
49
|
+
if (!entity) return vscode.window.showInformationMessage('Can not get entity')
|
50
|
+
|
51
|
+
const relations = getRelationsEntity(entity)
|
52
|
+
if (!relations.length) return vscode.window.showInformationMessage('Not exist any relation')
|
53
|
+
|
54
|
+
const relation = await vscode.window.showQuickPick(
|
55
|
+
relations,
|
56
|
+
{ ignoreFocusOut: true })
|
57
|
+
if (!relation) return
|
58
|
+
|
59
|
+
let first = ''
|
60
|
+
let second = ''
|
61
|
+
|
62
|
+
if (!relation.includes('.')) {
|
63
|
+
first = `${getFullTextType(entity).camelCase}.${relation}`
|
64
|
+
second = `${relation}`
|
65
|
+
} else {
|
66
|
+
first = `${relation}`
|
67
|
+
const words = first.split('.')
|
68
|
+
second = `${words[1]}`
|
69
|
+
}
|
70
|
+
|
71
|
+
const fullText = getFullTextType(entity)
|
72
|
+
|
73
|
+
let template = `.leftJoinAndSelect('{{first}}', '{{second}}')
|
74
|
+
`
|
75
|
+
template = template.replace(/{{first}}/g, first);
|
76
|
+
template = template.replace(/{{second}}/g, second);
|
77
|
+
|
78
|
+
const start = range.start;
|
79
|
+
const line = document.lineAt(start.line)
|
80
|
+
console.log('line:', line)
|
81
|
+
const lastRelation = findLastLineRelation(document, line)
|
82
|
+
console.log('lastRelation:', lastRelation)
|
83
|
+
|
84
|
+
edit.insert(document.uri, new vscode.Position(lastRelation, 12), template);
|
85
|
+
|
86
|
+
vscode.workspace.applyEdit(edit)
|
87
|
+
}
|
@@ -0,0 +1,487 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { EntityAction } from '../../../constant';
|
3
|
+
import { FSProvider } from '../../../FsProvider';
|
4
|
+
import { getEntityFromFunction, getRelationsEntity } from './helper';
|
5
|
+
import { getFullTextType } from '../../../util';
|
6
|
+
import { Uri, commands } from 'vscode';
|
7
|
+
|
8
|
+
export function createAddRelationFunctionAction(
|
9
|
+
document: vscode.TextDocument, range: vscode.Range
|
10
|
+
) {
|
11
|
+
if (isEntityFunction(document, range)) {
|
12
|
+
|
13
|
+
const insertRelation = insertRelations(document, range)
|
14
|
+
|
15
|
+
return [
|
16
|
+
insertRelation
|
17
|
+
];
|
18
|
+
}
|
19
|
+
return []
|
20
|
+
}
|
21
|
+
|
22
|
+
function isEntityFunction(document: vscode.TextDocument, range: vscode.Range) {
|
23
|
+
const start = range.start;
|
24
|
+
const line = document.lineAt(start.line);
|
25
|
+
return line.text.includes('find')
|
26
|
+
}
|
27
|
+
|
28
|
+
function isQueryString(document: vscode.TextDocument, range: vscode.Range) {
|
29
|
+
return true
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
function insertRelations(
|
34
|
+
document: vscode.TextDocument,
|
35
|
+
range: vscode.Range
|
36
|
+
): vscode.CodeAction {
|
37
|
+
const entity = new vscode.CodeAction(EntityAction.AddRelation, vscode.CodeActionKind.QuickFix);
|
38
|
+
|
39
|
+
entity.command = {
|
40
|
+
command: EntityAction.AddRelation,
|
41
|
+
title: 'Add relation: ',
|
42
|
+
tooltip: 'Add relation: ',
|
43
|
+
arguments: [document, range]
|
44
|
+
};
|
45
|
+
|
46
|
+
return entity;
|
47
|
+
}
|
48
|
+
|
49
|
+
export async function insertEntityFunction(typeFunc: EntityAction, document: vscode.TextDocument, range: vscode.Range) {
|
50
|
+
const edit = new vscode.WorkspaceEdit();
|
51
|
+
|
52
|
+
const entityObj = getEntityFromFunction(document, range)
|
53
|
+
const entity = entityObj.text
|
54
|
+
|
55
|
+
if (!entity) return vscode.window.showInformationMessage('Can not get entity')
|
56
|
+
|
57
|
+
const relations = getRelationsEntity(entity)
|
58
|
+
if (!relations.length) return vscode.window.showInformationMessage('Not exist any relation')
|
59
|
+
|
60
|
+
const { allLine, mapLines } = getAllFunctionLine(document, range)
|
61
|
+
|
62
|
+
if (allLine.includes('relations')) {
|
63
|
+
const relationSelected = getRelationSelected(mapLines)
|
64
|
+
const relationNotSelected = relations.filter((item: string) => {
|
65
|
+
if (!relationSelected.includes(item)) return item
|
66
|
+
})
|
67
|
+
|
68
|
+
if (!relationNotSelected.length) return vscode.window.showInformationMessage('All relation was selected')
|
69
|
+
|
70
|
+
const relation = await vscode.window.showQuickPick(relationNotSelected, { ignoreFocusOut: true })
|
71
|
+
if (!relation) return
|
72
|
+
|
73
|
+
const { template, position } = handleExistRelation(relation, mapLines)
|
74
|
+
if (!position) return vscode.window.showInformationMessage('Can not find position to insert')
|
75
|
+
|
76
|
+
edit.insert(document.uri, position, template)
|
77
|
+
} else {
|
78
|
+
const relation = await vscode.window.showQuickPick(relations, { ignoreFocusOut: true })
|
79
|
+
if (!relation) return vscode.window.showInformationMessage('Please select relation')
|
80
|
+
|
81
|
+
const { template, position } = handleNotExistRelation(relation, mapLines)
|
82
|
+
if (!position) return vscode.window.showInformationMessage('Can not find position to insert')
|
83
|
+
|
84
|
+
edit.insert(document.uri, position, template);
|
85
|
+
}
|
86
|
+
|
87
|
+
vscode.workspace.applyEdit(edit)
|
88
|
+
}
|
89
|
+
|
90
|
+
function getAllFunctionLine(document: vscode.TextDocument, range: vscode.Range) {
|
91
|
+
const start = range.start;
|
92
|
+
const line = document.lineAt(start.line).text
|
93
|
+
console.log('line:', line)
|
94
|
+
let allLine = line
|
95
|
+
console.log('allLine:', allLine)
|
96
|
+
let mapLines = new Map()
|
97
|
+
|
98
|
+
mapLines.set(start.line, line)
|
99
|
+
if (line.match(/(\(\W*[a-zA-z]+\))|(\(\))|(\))/g) || line.includes('})')) {
|
100
|
+
return { allLine, mapLines }
|
101
|
+
}
|
102
|
+
|
103
|
+
const isContinue = true
|
104
|
+
let currentLine = start.line
|
105
|
+
while (isContinue) {
|
106
|
+
const nextLine = document.lineAt(currentLine + 1).text
|
107
|
+
allLine += nextLine
|
108
|
+
mapLines.set(currentLine + 1, nextLine)
|
109
|
+
if (nextLine.includes(')')) {
|
110
|
+
return { allLine, mapLines }
|
111
|
+
}
|
112
|
+
currentLine += 1
|
113
|
+
}
|
114
|
+
|
115
|
+
return { allLine, mapLines }
|
116
|
+
}
|
117
|
+
|
118
|
+
function getRelationSelected(mapLines: Map<number, string>) {
|
119
|
+
for (const [lineNumber, value] of mapLines.entries()) {
|
120
|
+
const matchRelations = value.match(/relations:.*\[/)
|
121
|
+
|
122
|
+
if (matchRelations) {
|
123
|
+
const matchRelationsProps = value.match(/('\w*'|'\w*\.\w*')/g)
|
124
|
+
|
125
|
+
if (!matchRelationsProps) return []
|
126
|
+
return matchRelationsProps.map(prop => prop.replace(/'/g, ''))
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return []
|
130
|
+
}
|
131
|
+
|
132
|
+
function handleExistRelation(relation: string, mapLines: Map<number, string>): any {
|
133
|
+
let template = `'${relation}', `
|
134
|
+
let indexOf = 0
|
135
|
+
|
136
|
+
for (const [lineNumber, value] of mapLines.entries()) {
|
137
|
+
const matchRelations = value.match(/relations:.*\[/)
|
138
|
+
if (matchRelations) {
|
139
|
+
const matched = matchRelations[0]
|
140
|
+
indexOf = value.indexOf(matched) != -1 ? value.indexOf(matched) + matched.length : 0
|
141
|
+
return { template, position: new vscode.Position(lineNumber, indexOf) }
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
function handleNotExistRelation(relation: string, mapLines: Map<number, string>): { template: string, position: vscode.Position | null } {
|
147
|
+
let template = ``
|
148
|
+
let indexOf = 0
|
149
|
+
const [firstKey, firstValue] = mapLines.entries().next().value
|
150
|
+
|
151
|
+
const matchBracket = firstValue.match(/(\(\W*[a-zA-Z-_]+,\s{)|(\({)/)
|
152
|
+
if (matchBracket?.length) {
|
153
|
+
const matched = matchBracket[0]
|
154
|
+
template = `\nrelations: ['${relation}'],`
|
155
|
+
indexOf = firstValue.indexOf(matched) != -1 ? firstValue.indexOf(matched) + matched.length : 0
|
156
|
+
return { template, position: new vscode.Position(firstKey, indexOf) }
|
157
|
+
}
|
158
|
+
|
159
|
+
const matchNoBracket = firstValue.match(/\(\W*[a-zA-Z_-\W][^\)]+|(\()/)
|
160
|
+
|
161
|
+
if (matchNoBracket?.length) {
|
162
|
+
const matched = matchNoBracket[0]
|
163
|
+
template = `{\nrelations: ['${relation}']\n}`
|
164
|
+
if (matched.match(/[a-zA-Z]/)) {
|
165
|
+
template = `, {\nrelations: ['${relation}']\n}`
|
166
|
+
}
|
167
|
+
indexOf = firstValue.indexOf(matched) != -1 ? firstValue.indexOf(matched) + matched.length : 0
|
168
|
+
return { template, position: new vscode.Position(firstKey, indexOf) }
|
169
|
+
}
|
170
|
+
|
171
|
+
return { template, position: null }
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
export function createAddFunctionAction(
|
176
|
+
document: vscode.TextDocument, range: vscode.Range
|
177
|
+
) {
|
178
|
+
if (isEntityClassNotBuilder(document, range)) {
|
179
|
+
|
180
|
+
const insertQueryBuilderPagination = createEntityFunction(document, range, EntityAction.CreateQueryBuilderPagination);
|
181
|
+
const insertQueryBuilderFindAll = createEntityFunction(document, range, EntityAction.CreateQueryBuilderFindAll);
|
182
|
+
const insertQueryBuilderFindOne = createEntityFunction(document, range, EntityAction.CreateQueryBuilderFindOne);
|
183
|
+
const insertFindOneID = createEntityFunction(document, range, EntityAction.FindOneOrThrowID);
|
184
|
+
|
185
|
+
return [
|
186
|
+
insertFindOneID,
|
187
|
+
insertQueryBuilderPagination,
|
188
|
+
insertQueryBuilderFindAll,
|
189
|
+
insertQueryBuilderFindOne,
|
190
|
+
];
|
191
|
+
}
|
192
|
+
|
193
|
+
return []
|
194
|
+
}
|
195
|
+
|
196
|
+
function isEntityClassNotBuilder(document: vscode.TextDocument, range: vscode.Range) {
|
197
|
+
const entities = FSProvider.getAllFileInFolder('/src/entity')
|
198
|
+
|
199
|
+
const start = range.start;
|
200
|
+
const line = document.lineAt(start.line);
|
201
|
+
|
202
|
+
let isIncludesEntity = false
|
203
|
+
entities.map((entity: string) => {
|
204
|
+
if (line.text.includes(entity)) {
|
205
|
+
isIncludesEntity = true
|
206
|
+
}
|
207
|
+
})
|
208
|
+
return isIncludesEntity &&
|
209
|
+
!line.text.includes('Controller') &&
|
210
|
+
!line.text.includes('Service') &&
|
211
|
+
!line.text.includes('createQueryBuilder') &&
|
212
|
+
!line.text.includes('find')
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
export async function handleOpenAndScrollToRelation(document: vscode.TextDocument, range: vscode.Range) {
|
217
|
+
const edit = new vscode.WorkspaceEdit();
|
218
|
+
const entityObj = getEntityFromFunction(document, range)
|
219
|
+
const entity = entityObj.text
|
220
|
+
|
221
|
+
if (!entity) return vscode.window.showInformationMessage('Can not get entity')
|
222
|
+
|
223
|
+
// const activeEditor1 = vscode.window.activeTextEditor;
|
224
|
+
// console.log('activeEditor 1:', activeEditor1)
|
225
|
+
|
226
|
+
|
227
|
+
const distPath = `src/entity/${entity}.ts`
|
228
|
+
let uri = Uri.file(FSProvider.getFullPath(distPath))
|
229
|
+
|
230
|
+
await commands.executeCommand('vscode.openFolder', uri)
|
231
|
+
|
232
|
+
const newDocument = vscode.window.activeTextEditor?.document
|
233
|
+
if (!newDocument) return vscode.window.showInformationMessage('Can not get new file open')
|
234
|
+
|
235
|
+
const positionRelation = getRelationsCommentLine(distPath)
|
236
|
+
console.log('positionRelation:', positionRelation)
|
237
|
+
|
238
|
+
await commands.executeCommand('moveActiveEditor', { to: 'last', by: 'tab' })
|
239
|
+
|
240
|
+
const editor = vscode.window.activeTextEditor;
|
241
|
+
if (!editor) return
|
242
|
+
const position = editor?.selection.active;
|
243
|
+
console.log('position:', position)
|
244
|
+
editor.selections = [new vscode.Selection(new vscode.Position(0, 0), new vscode.Position(0, 0))]
|
245
|
+
|
246
|
+
const result = await commands.executeCommand('cursorMove', { to: 'up', value: position.line })
|
247
|
+
console.log('result:', result)
|
248
|
+
// await commands.executeCommand('editorScroll', { to: 'down', by: 'line', value: positionRelation })
|
249
|
+
|
250
|
+
}
|
251
|
+
|
252
|
+
function getRelationsCommentLine(path: string) {
|
253
|
+
const lines = FSProvider.getLinesDocumentInFile(path)
|
254
|
+
let position = 0
|
255
|
+
for (let index = 0; index < lines.length; index++) {
|
256
|
+
const line = lines[index]
|
257
|
+
if (line.includes('RELATIONS')) position = index
|
258
|
+
}
|
259
|
+
return position
|
260
|
+
}
|
261
|
+
|
262
|
+
function createEntityFunction(document: vscode.TextDocument, range: vscode.Range, typeFunc: EntityAction): vscode.CodeAction {
|
263
|
+
const entity = new vscode.CodeAction(typeFunc, vscode.CodeActionKind.QuickFix);
|
264
|
+
switch (typeFunc) {
|
265
|
+
|
266
|
+
case EntityAction.CreateQueryBuilderPagination:
|
267
|
+
entity.command = {
|
268
|
+
command: typeFunc,
|
269
|
+
title: 'Create query build pagination: ',
|
270
|
+
tooltip: 'Create query build pagination: ',
|
271
|
+
arguments: [document, range]
|
272
|
+
};
|
273
|
+
break
|
274
|
+
|
275
|
+
case EntityAction.CreateQueryBuilderFindAll:
|
276
|
+
entity.command = {
|
277
|
+
command: typeFunc,
|
278
|
+
title: 'Create query build find all: ',
|
279
|
+
tooltip: 'Create query build find all: ',
|
280
|
+
arguments: [document, range]
|
281
|
+
};
|
282
|
+
break
|
283
|
+
|
284
|
+
case EntityAction.CreateQueryBuilderFindOne:
|
285
|
+
entity.command = {
|
286
|
+
command: typeFunc,
|
287
|
+
title: 'Create query build find one: ',
|
288
|
+
tooltip: 'Create query build find one: ',
|
289
|
+
arguments: [document, range]
|
290
|
+
};
|
291
|
+
break
|
292
|
+
|
293
|
+
case EntityAction.CreateQueryBuilderFindAll:
|
294
|
+
entity.command = {
|
295
|
+
command: typeFunc,
|
296
|
+
title: 'Create query build find all: ',
|
297
|
+
tooltip: 'Create query build find all: ',
|
298
|
+
arguments: [document, range]
|
299
|
+
};
|
300
|
+
break
|
301
|
+
|
302
|
+
case EntityAction.CreateQueryBuilderFindOne:
|
303
|
+
entity.command = {
|
304
|
+
command: typeFunc,
|
305
|
+
title: 'Create query build find one: ',
|
306
|
+
tooltip: 'Create query build find one: ',
|
307
|
+
arguments: [document, range]
|
308
|
+
};
|
309
|
+
break
|
310
|
+
|
311
|
+
case EntityAction.FindOneOrThrowID:
|
312
|
+
entity.command = {
|
313
|
+
command: typeFunc,
|
314
|
+
title: 'Find one or throw ID: ',
|
315
|
+
tooltip: 'Find one or throw ID: ',
|
316
|
+
arguments: [document, range]
|
317
|
+
};
|
318
|
+
break
|
319
|
+
|
320
|
+
case EntityAction.AddBuilderRelation:
|
321
|
+
entity.command = {
|
322
|
+
command: typeFunc,
|
323
|
+
title: 'Add builder relation: ',
|
324
|
+
tooltip: 'Add builder relation: ',
|
325
|
+
arguments: [document, range]
|
326
|
+
};
|
327
|
+
break
|
328
|
+
|
329
|
+
|
330
|
+
default:
|
331
|
+
break;
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
return entity;
|
336
|
+
}
|
337
|
+
|
338
|
+
export async function insertQueryBuilder(typeFunc: EntityAction, document: vscode.TextDocument, range: vscode.Range) {
|
339
|
+
const edit = new vscode.WorkspaceEdit();
|
340
|
+
|
341
|
+
const entityObj = getEntityFromFunction(document, range)
|
342
|
+
const entity = entityObj.text
|
343
|
+
|
344
|
+
if (!entity) return vscode.window.showInformationMessage('Can not get entity')
|
345
|
+
|
346
|
+
const fullText = getFullTextType(entity)
|
347
|
+
|
348
|
+
let template = getTemplateQueryBuilder(typeFunc)
|
349
|
+
let where = getWhereQueryBuilder(typeFunc)
|
350
|
+
|
351
|
+
template = template.replace(/{{camel}}/g, fullText.camelCase);
|
352
|
+
template = template.replace(/{{cap}}/g, fullText.classifyCase);
|
353
|
+
template = template.replace(/{{dollar}}/g, '$');
|
354
|
+
template = template.replace(/{{backtick}}/g, '`');
|
355
|
+
|
356
|
+
where = where.replace(/{{camel}}/g, fullText.camelCase);
|
357
|
+
where = where.replace(/{{cap}}/g, fullText.classifyCase);
|
358
|
+
where = where.replace(/{{dollar}}/g, '$');
|
359
|
+
where = where.replace(/{{backtick}}/g, '`');
|
360
|
+
|
361
|
+
const start = range.start;
|
362
|
+
const line = document.lineAt(start.line)
|
363
|
+
const preLine = document.lineAt(line.lineNumber - 1)
|
364
|
+
const preLineLastIndex = preLine.text
|
365
|
+
|
366
|
+
edit.insert(document.uri, new vscode.Position(line.lineNumber, line.text.length + 1), template);
|
367
|
+
edit.insert(document.uri, new vscode.Position(preLine.lineNumber, preLineLastIndex.length), where)
|
368
|
+
vscode.workspace.applyEdit(edit)
|
369
|
+
}
|
370
|
+
|
371
|
+
function getWhereQueryBuilder(typeFunc: EntityAction) {
|
372
|
+
let template = ``
|
373
|
+
|
374
|
+
switch (typeFunc) {
|
375
|
+
case EntityAction.CreateQueryBuilderPagination:
|
376
|
+
template = `\n\t\tlet where = {{backtick}}{{camel}}.name LIKE '%{{dollar}}{search}%' AND {{camel}}.isDeleted = false{{backtick}}`
|
377
|
+
break;
|
378
|
+
|
379
|
+
case EntityAction.CreateQueryBuilderFindAll:
|
380
|
+
template = `\n\t\tlet where = {{backtick}}{{camel}}.isDeleted = false{{backtick}}`
|
381
|
+
break;
|
382
|
+
|
383
|
+
case EntityAction.CreateQueryBuilderFindOne:
|
384
|
+
template = `\n\t\tlet where = {{backtick}}{{camel}}.isDeleted = false{{backtick}}`
|
385
|
+
break;
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
return template
|
390
|
+
}
|
391
|
+
|
392
|
+
function getTemplateQueryBuilder(typeFunc: EntityAction) {
|
393
|
+
let template = ``
|
394
|
+
|
395
|
+
switch (typeFunc) {
|
396
|
+
case EntityAction.CreateQueryBuilderPagination:
|
397
|
+
template = `.createQueryBuilder('{{camel}}')
|
398
|
+
.where(where)
|
399
|
+
.skip((page - 1) * limit)
|
400
|
+
.take(limit)
|
401
|
+
.orderBy('{{camel}}.id', 'DESC')
|
402
|
+
.getManyAndCount()
|
403
|
+
`
|
404
|
+
break;
|
405
|
+
|
406
|
+
case EntityAction.CreateQueryBuilderFindAll:
|
407
|
+
template = `.createQueryBuilder('{{camel}}')
|
408
|
+
.where(where)
|
409
|
+
.orderBy('{{camel}}.id', 'DESC')
|
410
|
+
.getMany()
|
411
|
+
`
|
412
|
+
break;
|
413
|
+
|
414
|
+
case EntityAction.CreateQueryBuilderFindOne:
|
415
|
+
template = `.createQueryBuilder('{{camel}}')
|
416
|
+
.where(where)
|
417
|
+
.getOne()
|
418
|
+
`
|
419
|
+
break;
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
return template
|
424
|
+
}
|
425
|
+
|
426
|
+
|
427
|
+
export async function insertFindOneOrThrow(typeFunc: EntityAction, document: vscode.TextDocument, range: vscode.Range) {
|
428
|
+
const edit = new vscode.WorkspaceEdit();
|
429
|
+
|
430
|
+
const entityObj = getEntityFromFunction(document, range)
|
431
|
+
const entity = entityObj.text
|
432
|
+
|
433
|
+
if (!entity) return vscode.window.showInformationMessage('Can not get entity')
|
434
|
+
|
435
|
+
const fullText = getFullTextType(entity)
|
436
|
+
|
437
|
+
let template = `.findOneOrThrowId({{camel}}Id, null, '')
|
438
|
+
`
|
439
|
+
template = template.replace(/{{camel}}/g, fullText.camelCase);
|
440
|
+
template = template.replace(/{{cap}}/g, fullText.classifyCase);
|
441
|
+
template = template.replace(/{{dollar}}/g, '$');
|
442
|
+
template = template.replace(/{{backtick}}/g, '`');
|
443
|
+
|
444
|
+
const start = range.start;
|
445
|
+
const line = document.lineAt(start.line)
|
446
|
+
|
447
|
+
edit.insert(document.uri, new vscode.Position(line.lineNumber, line.text.length + 1), template);
|
448
|
+
|
449
|
+
vscode.workspace.applyEdit(edit)
|
450
|
+
}
|
451
|
+
|
452
|
+
|
453
|
+
export function createGetPropertiesAction(
|
454
|
+
document: vscode.TextDocument, range: vscode.Range
|
455
|
+
) {
|
456
|
+
if (isEntityFunction(document, range)) {
|
457
|
+
const insertRelation = insertRelations(document, range)
|
458
|
+
|
459
|
+
return [
|
460
|
+
insertRelation
|
461
|
+
];
|
462
|
+
}
|
463
|
+
return []
|
464
|
+
}
|
465
|
+
|
466
|
+
export async function insertPropertiesToQuery(
|
467
|
+
document: vscode.TextDocument,
|
468
|
+
range: vscode.Range,
|
469
|
+
lastIndex: number,
|
470
|
+
property: string
|
471
|
+
) {
|
472
|
+
const edit = new vscode.WorkspaceEdit();
|
473
|
+
|
474
|
+
const entityObj = getEntityFromFunction(document, range, true)
|
475
|
+
const entity = entityObj.text
|
476
|
+
|
477
|
+
if (!entity) return vscode.window.showInformationMessage('Can not get entity')
|
478
|
+
|
479
|
+
const fullText = getFullTextType(entity)
|
480
|
+
|
481
|
+
const start = range.start;
|
482
|
+
const line = document.lineAt(start.line)
|
483
|
+
|
484
|
+
edit.insert(document.uri, new vscode.Position(line.lineNumber, lastIndex + 1), `.${property}`);
|
485
|
+
|
486
|
+
vscode.workspace.applyEdit(edit)
|
487
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { EntityAction } from '../../../constant';
|
3
|
+
|
4
|
+
export function createPropertyAction(document: vscode.TextDocument, range: vscode.Range) {
|
5
|
+
if (isEntityProperties(document, range)) {
|
6
|
+
const addProperty = createAddPropertyAction(document, range)
|
7
|
+
|
8
|
+
return [addProperty];
|
9
|
+
}
|
10
|
+
|
11
|
+
return []
|
12
|
+
}
|
13
|
+
|
14
|
+
function createAddPropertyAction(document: vscode.TextDocument, range: vscode.Range): vscode.CodeAction {
|
15
|
+
const entity = new vscode.CodeAction(EntityAction.AddProperty, vscode.CodeActionKind.QuickFix);
|
16
|
+
|
17
|
+
entity.command = {
|
18
|
+
command: EntityAction.AddProperty,
|
19
|
+
title: 'Add property: ',
|
20
|
+
tooltip: 'Add property: ',
|
21
|
+
arguments: [document]
|
22
|
+
};
|
23
|
+
|
24
|
+
return entity;
|
25
|
+
}
|
26
|
+
|
27
|
+
function isEntityProperties(document: vscode.TextDocument, range: vscode.Range) {
|
28
|
+
const start = range.start;
|
29
|
+
const line = document.lineAt(start.line);
|
30
|
+
return line.text.includes('PROPERTIES') && document.fileName.includes('entity/')
|
31
|
+
}
|
32
|
+
|