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,232 @@
|
|
1
|
+
import { FSProvider } from '../../../FsProvider';
|
2
|
+
import * as vscode from 'vscode';
|
3
|
+
import { getFullTextType } from '../../../util';
|
4
|
+
|
5
|
+
export enum ServiceAction {
|
6
|
+
GetLast30 = 'BMD: Get last 30',
|
7
|
+
GetSum = 'BMD: Get sum',
|
8
|
+
GetManyAndCount = 'BMD: Get many and count'
|
9
|
+
}
|
10
|
+
|
11
|
+
export class ServiceActionProvider implements vscode.CodeActionProvider {
|
12
|
+
|
13
|
+
public static readonly providedCodeActionKinds = [
|
14
|
+
vscode.CodeActionKind.QuickFix
|
15
|
+
];
|
16
|
+
|
17
|
+
public provideCodeActions(
|
18
|
+
document: vscode.TextDocument,
|
19
|
+
range: any,
|
20
|
+
context: vscode.CodeActionContext
|
21
|
+
): vscode.CodeAction[] | undefined {
|
22
|
+
if (!this.isServiceClass(document, range)) return
|
23
|
+
|
24
|
+
const insertGetLast30 = this.createServiceFunc(document, range, ServiceAction.GetLast30);
|
25
|
+
const insertGetSum = this.createServiceFunc(document, range, ServiceAction.GetSum);
|
26
|
+
const insertGetManyAndCount = this.createServiceFunc(document, range, ServiceAction.GetManyAndCount);
|
27
|
+
|
28
|
+
return [
|
29
|
+
insertGetManyAndCount,
|
30
|
+
insertGetLast30,
|
31
|
+
insertGetSum
|
32
|
+
];
|
33
|
+
}
|
34
|
+
|
35
|
+
private isServiceClass(document: vscode.TextDocument, range: vscode.Range) {
|
36
|
+
const start = range.start;
|
37
|
+
const line = document.lineAt(start.line);
|
38
|
+
return line.text.includes('Service') && line.text.includes('class')
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
private createServiceFunc(document: vscode.TextDocument, range: vscode.Range, typeFunc: ServiceAction): vscode.CodeAction {
|
44
|
+
const service = new vscode.CodeAction(typeFunc, vscode.CodeActionKind.QuickFix);
|
45
|
+
service.command = {
|
46
|
+
command: typeFunc,
|
47
|
+
title: 'Get list with pagination.',
|
48
|
+
tooltip: 'Get list with pagination.',
|
49
|
+
arguments: [document]
|
50
|
+
};
|
51
|
+
|
52
|
+
switch (typeFunc) {
|
53
|
+
case ServiceAction.GetLast30:
|
54
|
+
service.command = {
|
55
|
+
command: typeFunc,
|
56
|
+
title: 'Get last 30.',
|
57
|
+
tooltip: 'Get last 30.',
|
58
|
+
arguments: [document]
|
59
|
+
};
|
60
|
+
break
|
61
|
+
|
62
|
+
case ServiceAction.GetSum:
|
63
|
+
service.command = {
|
64
|
+
command: typeFunc,
|
65
|
+
title: 'Get sum.',
|
66
|
+
tooltip: 'Get sum.',
|
67
|
+
arguments: [document]
|
68
|
+
};
|
69
|
+
break
|
70
|
+
|
71
|
+
case ServiceAction.GetManyAndCount:
|
72
|
+
service.command = {
|
73
|
+
command: typeFunc,
|
74
|
+
title: 'Get many and count.',
|
75
|
+
tooltip: 'Get many and count.',
|
76
|
+
arguments: [document]
|
77
|
+
};
|
78
|
+
break
|
79
|
+
|
80
|
+
default:
|
81
|
+
break;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
return service;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
public async insertServiceFunc(typeFunc: ServiceAction, document: vscode.TextDocument): Promise<void> {
|
90
|
+
const edit = new vscode.WorkspaceEdit();
|
91
|
+
let entity = 'Entity'
|
92
|
+
for (let index = 0; index < document.lineCount; index++) {
|
93
|
+
const line = document.lineAt(index)
|
94
|
+
if (line.text.includes('Service')) {
|
95
|
+
let words = line.text.split(' ')
|
96
|
+
words = words.filter(word => word.includes('Service'))
|
97
|
+
words = words.map(word => word = word.replace('Service', ''))
|
98
|
+
entity = words[0] || 'Entity'
|
99
|
+
}
|
100
|
+
if (line.text.includes('END FILE')) {
|
101
|
+
switch (typeFunc) {
|
102
|
+
case ServiceAction.GetLast30:
|
103
|
+
edit.insert(document.uri, new vscode.Position(index - 1, 0), this.generateGetLast30(entity));
|
104
|
+
break
|
105
|
+
|
106
|
+
case ServiceAction.GetSum:
|
107
|
+
edit.insert(document.uri, new vscode.Position(index - 1, 0), await this.generateGetSum(entity));
|
108
|
+
break
|
109
|
+
|
110
|
+
case ServiceAction.GetManyAndCount:
|
111
|
+
edit.insert(document.uri, new vscode.Position(index - 1, 0), this.generateGetManyAndCount(entity));
|
112
|
+
break
|
113
|
+
|
114
|
+
default:
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
vscode.workspace.applyEdit(edit)
|
121
|
+
}
|
122
|
+
|
123
|
+
private generateGetManyAndCount = (name: string) => {
|
124
|
+
const nameTextTypes = getFullTextType(name)
|
125
|
+
let template = `
|
126
|
+
// =====================GET MANY AND COUNT=====================
|
127
|
+
public async getManyAndCount({ page, limit, search }): Promise<[{{cap}}[], number]> {
|
128
|
+
let where = {{backtick}}{{camel}}.name LIKE '%{{dollar}}{search}%' AND {{camel}}.isDeleted = false{{backtick}}
|
129
|
+
|
130
|
+
const [{{camel}}, total] = await {{cap}}.createQueryBuilder('{{camel}}')
|
131
|
+
.where(where)
|
132
|
+
.skip((page - 1) * limit)
|
133
|
+
.take(limit)
|
134
|
+
.orderBy('{{camel}}.id', 'DESC')
|
135
|
+
.getManyAndCount()
|
136
|
+
|
137
|
+
return [{{camel}}, total]
|
138
|
+
}
|
139
|
+
`
|
140
|
+
template = template.replace(/{{upper}}/g, nameTextTypes.upperCase);
|
141
|
+
template = template.replace(/{{camel}}/g, nameTextTypes.camelCase);
|
142
|
+
template = template.replace(/{{cap}}/g, nameTextTypes.classifyCase);
|
143
|
+
template = template.replace(/{{dollar}}/g, '$');
|
144
|
+
template = template.replace(/{{backtick}}/g, '`');
|
145
|
+
return template
|
146
|
+
}
|
147
|
+
|
148
|
+
private generateGetLast30 = (name: string) => {
|
149
|
+
const nameTextTypes = getFullTextType(name)
|
150
|
+
let template = `
|
151
|
+
// =====================GET LAST 30 {{upper}}=====================
|
152
|
+
async get{{cap}}Last30(from: Date = null, to: Date = null) {
|
153
|
+
const { start, end } = getFromToDate(from, to)
|
154
|
+
|
155
|
+
const {{camel}} = await {{cap}}.find({
|
156
|
+
where: {
|
157
|
+
dateCreated: Between(start, end),
|
158
|
+
},
|
159
|
+
order: { dateCreated: "ASC" },
|
160
|
+
})
|
161
|
+
|
162
|
+
const {{camel}}GroupByDay = {}
|
163
|
+
{{camel}}.map(order => {
|
164
|
+
const date = convertIntToDDMMYY(order.dateCreated)
|
165
|
+
if (!{{camel}}GroupByDay[date]) {
|
166
|
+
{{camel}}GroupByDay[date] = 0
|
167
|
+
}
|
168
|
+
{{camel}}GroupByDay[date] += 1
|
169
|
+
})
|
170
|
+
|
171
|
+
const reports = []
|
172
|
+
for (const date in {{camel}}GroupByDay) {
|
173
|
+
reports.push({
|
174
|
+
date,
|
175
|
+
total: {{camel}}GroupByDay[date],
|
176
|
+
})
|
177
|
+
}
|
178
|
+
|
179
|
+
return reports
|
180
|
+
}
|
181
|
+
`
|
182
|
+
template = template.replace(/{{upper}}/g, nameTextTypes.upperCase);
|
183
|
+
template = template.replace(/{{camel}}/g, nameTextTypes.camelCase);
|
184
|
+
template = template.replace(/{{cap}}/g, nameTextTypes.classifyCase);
|
185
|
+
template = template.replace(/{{dollar}}/g, '$');
|
186
|
+
template = template.replace(/{{backtick}}/g, '`');
|
187
|
+
return template
|
188
|
+
}
|
189
|
+
|
190
|
+
private getPropertiesEntity(name: string): any {
|
191
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/entity/${name}.ts`)
|
192
|
+
if (!lines.length) return
|
193
|
+
const properties = []
|
194
|
+
for (let index = 0; index < lines.length; index++) {
|
195
|
+
const line = lines[index];
|
196
|
+
if (line.includes('@Column')) {
|
197
|
+
let lineProperty = lines[index + 2]
|
198
|
+
lineProperty = lineProperty.replace(':', '').replace(';', '')
|
199
|
+
const words = lineProperty.split(' ').filter(Boolean)
|
200
|
+
if (words.length > 1 && words[1] == 'number') properties.push(words[0])
|
201
|
+
else continue
|
202
|
+
}
|
203
|
+
}
|
204
|
+
return properties
|
205
|
+
}
|
206
|
+
|
207
|
+
private generateGetSum = async (name: string): Promise<any> => {
|
208
|
+
const properties = this.getPropertiesEntity(name)
|
209
|
+
const nameTextTypes = getFullTextType(name)
|
210
|
+
const result = await vscode.window.showQuickPick(properties, {
|
211
|
+
placeHolder: 'Sum by: ', ignoreFocusOut: true
|
212
|
+
})
|
213
|
+
if (!result) return
|
214
|
+
|
215
|
+
let template = `
|
216
|
+
// =====================GET SUM {{upper}}=====================
|
217
|
+
async getSum{{cap}}(): Promise<number> {
|
218
|
+
const { sum } = await {{cap}}
|
219
|
+
.createQueryBuilder('{{camel}}')
|
220
|
+
.select("sum({{camel}}.${result})", 'sum')
|
221
|
+
.getRawOne()
|
222
|
+
return sum
|
223
|
+
}
|
224
|
+
`
|
225
|
+
template = template.replace(/{{upper}}/g, nameTextTypes.upperCase);
|
226
|
+
template = template.replace(/{{camel}}/g, nameTextTypes.camelCase);
|
227
|
+
template = template.replace(/{{cap}}/g, nameTextTypes.classifyCase);
|
228
|
+
return template
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { getEntityFromFunction, getPropertiesEntity, getRelationsEntityDeeper } from '../codeAction/entity/helper';
|
3
|
+
import { getWordBetweenSpace, removePlural, getFullTextType } from '../../util';
|
4
|
+
import { FSProvider } from '../../FsProvider';
|
5
|
+
|
6
|
+
export const CompletionPropertyProvider = vscode.languages.registerCompletionItemProvider(
|
7
|
+
'typescript',
|
8
|
+
{
|
9
|
+
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
|
10
|
+
const linePrefix = document.lineAt(position).text.substr(0, position.character)
|
11
|
+
if (linePrefix.endsWith('.')) {
|
12
|
+
const lineWithoutEndWithDot = linePrefix.slice(0, -1)
|
13
|
+
let { text } = getWordBetweenSpace(lineWithoutEndWithDot, lineWithoutEndWithDot.length - 1)
|
14
|
+
|
15
|
+
let entity = text
|
16
|
+
let isEntity = FSProvider.isEntity(entity)
|
17
|
+
|
18
|
+
if (!isEntity) {
|
19
|
+
entity = removePlural(text)
|
20
|
+
isEntity = FSProvider.isEntity(entity)
|
21
|
+
}
|
22
|
+
|
23
|
+
const properties = getPropertiesEntity(entity)
|
24
|
+
const entities = getRelationsEntityDeeper(entity).relations
|
25
|
+
const suggestions: vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> = []
|
26
|
+
|
27
|
+
if (properties) {
|
28
|
+
properties.map(p => {
|
29
|
+
const item = new vscode.CompletionItem(`${p.name}`)
|
30
|
+
item.kind = vscode.CompletionItemKind.Field
|
31
|
+
item.insertText = p.name + ' '
|
32
|
+
item.detail = `Type: ${p.type}`
|
33
|
+
suggestions.push(item)
|
34
|
+
})
|
35
|
+
}
|
36
|
+
|
37
|
+
if (entities) {
|
38
|
+
entities.map(p => {
|
39
|
+
const item = new vscode.CompletionItem(p, vscode.CompletionItemKind.Method)
|
40
|
+
suggestions.push(item)
|
41
|
+
})
|
42
|
+
}
|
43
|
+
|
44
|
+
return suggestions;
|
45
|
+
}
|
46
|
+
|
47
|
+
return undefined;
|
48
|
+
}
|
49
|
+
},
|
50
|
+
'.'
|
51
|
+
);
|
52
|
+
|
53
|
+
|
54
|
+
export const CompletionEntityProvider = vscode.languages.registerCompletionItemProvider(
|
55
|
+
'typescript',
|
56
|
+
{
|
57
|
+
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
|
58
|
+
|
59
|
+
const entities = FSProvider.getAllFileInFolder('/src/entity')
|
60
|
+
|
61
|
+
const suggestions: vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> = []
|
62
|
+
|
63
|
+
entities.map(e => {
|
64
|
+
const texts = getFullTextType(e)
|
65
|
+
const commitCharacterCompletion = new vscode.CompletionItem(texts.camelCase);
|
66
|
+
commitCharacterCompletion.commitCharacters = ['.'];
|
67
|
+
commitCharacterCompletion.documentation = new vscode.MarkdownString(`Press '.' to get ${texts.camelCase}`);
|
68
|
+
suggestions.push(commitCharacterCompletion)
|
69
|
+
})
|
70
|
+
|
71
|
+
return suggestions.length ? suggestions : undefined
|
72
|
+
}
|
73
|
+
},
|
74
|
+
'ctrl + space'
|
75
|
+
);
|
76
|
+
|
77
|
+
const TRIGGER_QUERY = [
|
78
|
+
'A', 'B', 'C', 'I', 'L'
|
79
|
+
]
|
80
|
+
export const CompletionQueryProvider = vscode.languages.registerCompletionItemProvider(
|
81
|
+
{ language: 'typescript' },
|
82
|
+
{
|
83
|
+
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
|
84
|
+
const QUERY_KEYWORDS = [
|
85
|
+
{ label: 'AND', insert: 'AND ' },
|
86
|
+
{ label: 'IN', insert: ' IN (:...) ' },
|
87
|
+
{ label: 'BETWEEN', insert: ' BETWEEN ${} AND ${} ' },
|
88
|
+
{ label: 'LIKE', insert: "LIKE '%${search}%' " },
|
89
|
+
{ label: 'CONCAT', insert: "CONCAT( ) " },
|
90
|
+
{ label: 'IFNULL', insert: "IFNULL( , ) " },
|
91
|
+
]
|
92
|
+
|
93
|
+
|
94
|
+
const suggestions: vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> = []
|
95
|
+
|
96
|
+
QUERY_KEYWORDS.map(q => {
|
97
|
+
const item = new vscode.CompletionItem(`${q.label}`)
|
98
|
+
item.kind = vscode.CompletionItemKind.Field
|
99
|
+
item.insertText = q.insert
|
100
|
+
item.detail = q.label
|
101
|
+
suggestions.push(item)
|
102
|
+
})
|
103
|
+
|
104
|
+
return suggestions.length ? suggestions : undefined
|
105
|
+
}
|
106
|
+
},
|
107
|
+
...TRIGGER_QUERY
|
108
|
+
);
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { getParamLinesInFunction, getParams } from './util';
|
3
|
+
import { ControllerAction } from '../../constant';
|
4
|
+
|
5
|
+
export function getErrorForgetToken(document: vscode.TextDocument) {
|
6
|
+
const lines = getAllUseAuthLine(document)
|
7
|
+
if (!lines || !lines.length) return []
|
8
|
+
const errors = []
|
9
|
+
|
10
|
+
for (const l of lines) {
|
11
|
+
const lineNumber = l.lineNumber
|
12
|
+
|
13
|
+
const paramLines = getParamLinesInFunction(lineNumber, document)
|
14
|
+
const params = paramLines.map(l => getParams(l.text)).filter(Boolean)
|
15
|
+
|
16
|
+
if (!params.some(p => p == 'token')) {
|
17
|
+
let item: vscode.Diagnostic = {
|
18
|
+
code: ControllerAction.AddPathParams,
|
19
|
+
message: `"Params 'token' is required`,
|
20
|
+
range: new vscode.Range(
|
21
|
+
new vscode.Position(lineNumber, l.firstNonWhitespaceCharacterIndex),
|
22
|
+
new vscode.Position(lineNumber, l.text.length - 1)
|
23
|
+
),
|
24
|
+
severity: vscode.DiagnosticSeverity.Error,
|
25
|
+
source: 'typescript',
|
26
|
+
relatedInformation: [
|
27
|
+
new vscode.DiagnosticRelatedInformation(
|
28
|
+
new vscode.Location(
|
29
|
+
document.uri,
|
30
|
+
new vscode.Range(
|
31
|
+
new vscode.Position(lineNumber, l.firstNonWhitespaceCharacterIndex),
|
32
|
+
new vscode.Position(lineNumber, l.text.length - 1)
|
33
|
+
)
|
34
|
+
),
|
35
|
+
`Param 'token' is required`
|
36
|
+
)
|
37
|
+
]
|
38
|
+
}
|
39
|
+
errors.push(item)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
return errors
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
function getAllUseAuthLine(document: vscode.TextDocument) {
|
48
|
+
const lines = []
|
49
|
+
|
50
|
+
const totalLine = document.lineCount
|
51
|
+
for (let index = 0; index < totalLine; index++) {
|
52
|
+
const line = document.lineAt(index)
|
53
|
+
|
54
|
+
if (line.text.includes('UseAuth') && line.text.includes('VerificationJWT')) {
|
55
|
+
lines.push(line)
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
return lines
|
60
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { getParamLinesInFunction, getParams } from './util';
|
3
|
+
import { ControllerAction } from '../../constant';
|
4
|
+
import { getPathParams, getPath } from '../codeAction/controller/util';
|
5
|
+
|
6
|
+
export function getErrorPathParams(document: vscode.TextDocument) {
|
7
|
+
const lines = getAllPathLine(document)
|
8
|
+
if (!lines || !lines.length) return []
|
9
|
+
const errors = []
|
10
|
+
|
11
|
+
for (const l of lines) {
|
12
|
+
const lineNumber = l.lineNumber
|
13
|
+
|
14
|
+
const path = getPath(l.text)
|
15
|
+
const pathParams = getPathParams(path)
|
16
|
+
|
17
|
+
const paramLines = getParamLinesInFunction(lineNumber, document)
|
18
|
+
const params = paramLines.map(l => getParams(l.text)).filter(Boolean)
|
19
|
+
|
20
|
+
let paramMission = pathParams.filter(p => !params.includes(p));
|
21
|
+
|
22
|
+
if (paramMission && paramMission.length) {
|
23
|
+
let item: vscode.Diagnostic = {
|
24
|
+
code: ControllerAction.AddPathParams,
|
25
|
+
message: `"Missing path params: ${paramMission.join(', ')}`,
|
26
|
+
range: new vscode.Range(
|
27
|
+
new vscode.Position(lineNumber, l.firstNonWhitespaceCharacterIndex),
|
28
|
+
new vscode.Position(lineNumber, l.text.length - 1)
|
29
|
+
),
|
30
|
+
severity: vscode.DiagnosticSeverity.Error,
|
31
|
+
source: 'typescript'
|
32
|
+
}
|
33
|
+
errors.push(item)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return errors
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
function getAllPathLine(document: vscode.TextDocument) {
|
42
|
+
const lines = []
|
43
|
+
|
44
|
+
const totalLine = document.lineCount
|
45
|
+
for (let index = 0; index < totalLine; index++) {
|
46
|
+
const line = document.lineAt(index)
|
47
|
+
|
48
|
+
if (isPathLine(line.text)) {
|
49
|
+
lines.push(line)
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
return lines
|
54
|
+
}
|
55
|
+
|
56
|
+
function isPathLine(line: string) {
|
57
|
+
return (line.includes('@Get') ||
|
58
|
+
line.includes('@Post') ||
|
59
|
+
line.includes('@Delete') ||
|
60
|
+
line.includes('@Put') ||
|
61
|
+
line.includes('@Patch')) &&
|
62
|
+
line.includes('/:')
|
63
|
+
|
64
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { getMatch } from '../../util';
|
3
|
+
import { getParamLinesInFunction, getParams, getAllJoiRequireLine } from './util';
|
4
|
+
|
5
|
+
export function getErrorValidateRequire(document: vscode.TextDocument) {
|
6
|
+
const lines = getAllJoiRequireLine(document)
|
7
|
+
if (!lines || !lines.length) return []
|
8
|
+
|
9
|
+
const errors = []
|
10
|
+
|
11
|
+
for (const l of lines) {
|
12
|
+
const lineNumber = l.lineNumber
|
13
|
+
const property = getValidateProperty(l.text.trim())
|
14
|
+
if (!property) continue
|
15
|
+
|
16
|
+
const paramLines = getParamLinesInFunction(lineNumber, document)
|
17
|
+
const params = paramLines.map(l => getParams(l.text)).filter(Boolean)
|
18
|
+
|
19
|
+
if (!params.some(p => p == property)) {
|
20
|
+
let item: vscode.Diagnostic = {
|
21
|
+
code: 'required',
|
22
|
+
message: `"${property}" not required`,
|
23
|
+
range: new vscode.Range(
|
24
|
+
new vscode.Position(lineNumber, l.firstNonWhitespaceCharacterIndex),
|
25
|
+
new vscode.Position(lineNumber, l.text.length - 1)
|
26
|
+
),
|
27
|
+
severity: vscode.DiagnosticSeverity.Error,
|
28
|
+
source: 'typescript',
|
29
|
+
relatedInformation: [
|
30
|
+
new vscode.DiagnosticRelatedInformation(
|
31
|
+
new vscode.Location(
|
32
|
+
document.uri,
|
33
|
+
new vscode.Range(
|
34
|
+
new vscode.Position(lineNumber, l.firstNonWhitespaceCharacterIndex),
|
35
|
+
new vscode.Position(lineNumber, l.text.length - 1)
|
36
|
+
)
|
37
|
+
),
|
38
|
+
`Params: ${params.join(', ')}`
|
39
|
+
)
|
40
|
+
]
|
41
|
+
}
|
42
|
+
errors.push(item)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
return errors
|
47
|
+
}
|
48
|
+
|
49
|
+
function getValidateProperty(line: string) {
|
50
|
+
if (line.startsWith('//')) return null
|
51
|
+
|
52
|
+
const matches = getMatch(/\w*:/gm, line)
|
53
|
+
if (!matches || !matches.length) return null
|
54
|
+
else return matches[0].replace(/:/g, '')
|
55
|
+
}
|
56
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import * as path from 'path';
|
3
|
+
import { Diagnostic } from 'vscode';
|
4
|
+
import { getErrorValidateRequire } from './checkRequired';
|
5
|
+
import { getErrorForgetToken } from './checkHeaderToken';
|
6
|
+
import { getErrorPathParams } from './checkPathParam';
|
7
|
+
|
8
|
+
export function updateDiagnostics(
|
9
|
+
document: vscode.TextDocument,
|
10
|
+
collection: vscode.DiagnosticCollection
|
11
|
+
): void {
|
12
|
+
if (isControllerFile(document)) {
|
13
|
+
const errors = getErrorChecking(document)
|
14
|
+
if (!errors || !errors.length) collection.clear();
|
15
|
+
|
16
|
+
collection.set(document.uri, errors)
|
17
|
+
} else {
|
18
|
+
collection.clear();
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
function getErrorChecking(document: vscode.TextDocument) {
|
23
|
+
const errors: Diagnostic[] = []
|
24
|
+
|
25
|
+
errors.push(...getErrorValidateRequire(document))
|
26
|
+
errors.push(...getErrorForgetToken(document))
|
27
|
+
errors.push(...getErrorPathParams(document))
|
28
|
+
|
29
|
+
return errors
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
function isControllerFile(document: vscode.TextDocument) {
|
34
|
+
return document && path.basename(document.uri.fsPath).includes('Controller')
|
35
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { getMatch } from '../../util';
|
3
|
+
|
4
|
+
export function getParamLinesInFunction(lineNumber: number, document: vscode.TextDocument) {
|
5
|
+
const lines = []
|
6
|
+
|
7
|
+
const totalLine = document.lineCount
|
8
|
+
for (let index = lineNumber; index < totalLine; index++) {
|
9
|
+
const line = document.lineAt(index)
|
10
|
+
|
11
|
+
const text = line.text.trim()
|
12
|
+
|
13
|
+
if (
|
14
|
+
text.includes('@') &&
|
15
|
+
!text.includes('UseAuth') &&
|
16
|
+
!text.includes('Validator') &&
|
17
|
+
!text.includes('Validator') &&
|
18
|
+
!text.includes('@Req') &&
|
19
|
+
!text.includes('@Res') &&
|
20
|
+
!text.includes('@Get') &&
|
21
|
+
!text.includes('@Post') &&
|
22
|
+
!text.includes('@Delete') &&
|
23
|
+
!text.includes('@Put') &&
|
24
|
+
!text.includes('@Patch') &&
|
25
|
+
!text.startsWith('//')
|
26
|
+
) {
|
27
|
+
lines.push(line)
|
28
|
+
}
|
29
|
+
|
30
|
+
if (text.includes(') {') || text.includes('){')) break
|
31
|
+
}
|
32
|
+
|
33
|
+
return lines
|
34
|
+
}
|
35
|
+
|
36
|
+
export function getParams(line: string) {
|
37
|
+
const matches = getMatch(/"\w*"|'\w*'/gm, line)
|
38
|
+
if (!matches || !matches.length) return null
|
39
|
+
else return matches[0].replace(/"/g, '').replace(/'/g, '')
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
export function getAllJoiRequireLine(document: vscode.TextDocument) {
|
44
|
+
const lines = []
|
45
|
+
|
46
|
+
const totalLine = document.lineCount
|
47
|
+
for (let index = 0; index < totalLine; index++) {
|
48
|
+
const line = document.lineAt(index)
|
49
|
+
|
50
|
+
if (line.text.includes('Joi') && line.text.includes('require')) {
|
51
|
+
lines.push(line)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
return lines
|
56
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import * as path from 'path';
|
2
|
+
import * as vscode from 'vscode';
|
3
|
+
|
4
|
+
export class Dependency extends vscode.TreeItem {
|
5
|
+
constructor(
|
6
|
+
public readonly label: string,
|
7
|
+
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
|
8
|
+
public readonly command?: vscode.Command,
|
9
|
+
public readonly context?: string,
|
10
|
+
public readonly icon?: string,
|
11
|
+
) {
|
12
|
+
super(label, collapsibleState)
|
13
|
+
}
|
14
|
+
|
15
|
+
// get tooltip(): string {
|
16
|
+
// return `${this.label}`;
|
17
|
+
// }
|
18
|
+
|
19
|
+
iconPath = {
|
20
|
+
light: path.join(__filename, '..', '..', '..', '..', 'media', 'light', `${this.icon}.svg`),
|
21
|
+
dark: path.join(__filename, '..', '..', '..', '..', 'media', 'dark', `${this.icon}.svg`)
|
22
|
+
};
|
23
|
+
|
24
|
+
contextValue = this.context;
|
25
|
+
|
26
|
+
}
|