baja-lite 1.1.3 → 1.1.4
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/.eslintignore +7 -0
- package/.eslintrc.cjs +89 -0
- package/.prettierrc +4 -0
- package/ci.js +29 -0
- package/package-cjs.json +17 -0
- package/package.json +6 -6
- package/{boot-remote.js → src/boot-remote.ts} +7 -6
- package/{boot.js → src/boot.ts} +39 -32
- package/{code.js → src/code.ts} +67 -64
- package/{convert-xml.js → src/convert-xml.ts} +155 -105
- package/src/enum.ts +71 -0
- package/src/error.ts +11 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +11 -11
- package/{list.js → src/list.ts} +9 -8
- package/src/math.ts +405 -0
- package/src/object.ts +247 -0
- package/src/set-ex.ts +374 -0
- package/src/sql.ts +5281 -0
- package/{sqlite.js → src/sqlite.ts} +52 -53
- package/src/string.ts +111 -0
- package/{test-mysql.js → src/test-mysql.ts} +126 -135
- package/src/test-postgresql.ts +79 -0
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -89
- package/{test-xml.js → src/test-xml.ts} +1 -1
- package/src/test.ts +2 -0
- package/src/wx/base.ts +76 -0
- package/src/wx/mini.ts +133 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +10 -21
- package/test.json +0 -0
- package/tsconfig.base.json +80 -0
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1493 -0
- package/boot-remote.d.ts +0 -2
- package/boot.d.ts +0 -2
- package/code.d.ts +0 -2
- package/convert-xml.d.ts +0 -10
- package/enum.d.ts +0 -18
- package/enum.js +0 -59
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -11
- package/list.d.ts +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -83
- package/object.js +0 -222
- package/set-ex.d.ts +0 -198
- package/set-ex.js +0 -338
- package/sql.d.ts +0 -1858
- package/sql.js +0 -5025
- package/sqlite.d.ts +0 -32
- package/string.d.ts +0 -17
- package/string.js +0 -105
- package/test-mysql.d.ts +0 -2
- package/test-postgresql.d.ts +0 -2
- package/test-postgresql.js +0 -90
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/test.js +0 -2
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -45
- package/wx/mini.js +0 -102
- package/wx/organ.d.ts +0 -65
- package/wx/organ.js +0 -171
- package/wx/types.js +0 -1
- package/wx.js +0 -3
- /package/{README.md → Readme.md} +0 -0
- /package/{wx.d.ts → src/wx.ts} +0 -0
package/{code.js → src/code.ts}
RENAMED
|
@@ -5,6 +5,7 @@ import { start } from 'repl';
|
|
|
5
5
|
import { createPool } from 'mysql2/promise';
|
|
6
6
|
import mustache from 'mustache';
|
|
7
7
|
import { mkdir } from 'shelljs';
|
|
8
|
+
|
|
8
9
|
const lxMap = {
|
|
9
10
|
tinyint: "number",
|
|
10
11
|
smallint: "number",
|
|
@@ -128,10 +129,26 @@ console.log(`
|
|
|
128
129
|
-----
|
|
129
130
|
force: 切换是否覆盖
|
|
130
131
|
`);
|
|
132
|
+
|
|
133
|
+
|
|
131
134
|
try {
|
|
132
|
-
const outputs = new Set();
|
|
135
|
+
const outputs = new Set<string>();
|
|
133
136
|
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
134
|
-
const configData = JSON.parse(_configData)
|
|
137
|
+
const configData = JSON.parse(_configData) as {
|
|
138
|
+
host: string;
|
|
139
|
+
port: number;
|
|
140
|
+
user: string;
|
|
141
|
+
password: string;
|
|
142
|
+
database: string;
|
|
143
|
+
command: Record<string, string>;
|
|
144
|
+
commands: Record<string, string[]>;
|
|
145
|
+
output: string;
|
|
146
|
+
id: string;
|
|
147
|
+
logicDeleteK: string;
|
|
148
|
+
logicDeleteV: number;
|
|
149
|
+
NotlogicDeleteV: number;
|
|
150
|
+
tables: string;
|
|
151
|
+
};
|
|
135
152
|
const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
|
|
136
153
|
const pool = createPool({
|
|
137
154
|
host: configData.host,
|
|
@@ -140,9 +157,9 @@ try {
|
|
|
140
157
|
password: configData.password,
|
|
141
158
|
database: configData.database
|
|
142
159
|
});
|
|
143
|
-
async function getTables(tableName) {
|
|
160
|
+
async function getTables(tableName: string) {
|
|
144
161
|
const conn = await pool.getConnection();
|
|
145
|
-
const params = [configData.database];
|
|
162
|
+
const params: (string | string[])[] = [configData.database];
|
|
146
163
|
let sql = `
|
|
147
164
|
SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
|
|
148
165
|
WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
|
|
@@ -150,13 +167,13 @@ try {
|
|
|
150
167
|
sql += ` AND TABLE_NAME IN (?)`;
|
|
151
168
|
params.push(tableName.split(/,|\s/).map(r => r.trim()));
|
|
152
169
|
}
|
|
153
|
-
const [result] = await conn.query(sql, params);
|
|
170
|
+
const [result] = await conn.query<any[]>(sql, params);
|
|
154
171
|
conn.release();
|
|
155
172
|
return result;
|
|
156
173
|
}
|
|
157
|
-
async function getColumns(tableName) {
|
|
174
|
+
async function getColumns(tableName: string) {
|
|
158
175
|
const conn = await pool.getConnection();
|
|
159
|
-
const [result] = await conn.query(`
|
|
176
|
+
const [result] = await conn.query<any[]>(`
|
|
160
177
|
SELECT
|
|
161
178
|
DATA_TYPE type,
|
|
162
179
|
COLUMN_NAME \`name\`,
|
|
@@ -170,38 +187,27 @@ try {
|
|
|
170
187
|
`, [configData.database, tableName]);
|
|
171
188
|
let logicDelete = '';
|
|
172
189
|
const columns = result.map(r => {
|
|
173
|
-
if (r.id === 1) {
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
else
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
delete r.notNull;
|
|
183
|
-
const fields = new Array(`type:SqlType.${r.type}`);
|
|
184
|
-
if (r.length !== null) {
|
|
185
|
-
fields.push(`length:${r.length}`);
|
|
186
|
-
}
|
|
187
|
-
if (r.scale !== null) {
|
|
188
|
-
fields.push(`scale:${r.scale}`);
|
|
189
|
-
}
|
|
190
|
+
if (r.id === 1) { r.id = true; }
|
|
191
|
+
else delete r.id;
|
|
192
|
+
if (r.notNull === 1) { r.notNull = true; }
|
|
193
|
+
else delete r.notNull;
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
const fields = new Array<string>(`type:SqlType.${r.type}`);
|
|
197
|
+
if (r.length !== null) { fields.push(`length:${r.length}`); }
|
|
198
|
+
if (r.scale !== null) { fields.push(`scale:${r.scale}`); }
|
|
190
199
|
if (r.def !== null) {
|
|
191
|
-
r.def
|
|
200
|
+
r.def ??= '';
|
|
192
201
|
if (isNaN(r.def) || r.def === '') {
|
|
193
202
|
fields.push(`def:'${r.def}'`);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
203
|
+
} else {
|
|
196
204
|
fields.push(`def:${r.def}`);
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
if (r.id === true) {
|
|
200
208
|
fields.push(`id:true`);
|
|
201
209
|
}
|
|
202
|
-
if (r.notNull === true) {
|
|
203
|
-
fields.push(`notNull:true`);
|
|
204
|
-
}
|
|
210
|
+
if (r.notNull === true) { fields.push(`notNull:true`); }
|
|
205
211
|
if (r.id === true && configData.id) {
|
|
206
212
|
fields.push(configData.id);
|
|
207
213
|
}
|
|
@@ -209,62 +215,66 @@ try {
|
|
|
209
215
|
fields.push(`logicDelete: ${configData.logicDeleteV}`);
|
|
210
216
|
logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
|
|
211
217
|
}
|
|
212
|
-
if (r.comment) {
|
|
213
|
-
fields.push(`comment: '${r.comment}'`);
|
|
214
|
-
}
|
|
218
|
+
if (r.comment) { fields.push(`comment: '${r.comment}'`); }
|
|
215
219
|
r.comment = r.comment ?? '';
|
|
216
220
|
r.Type = lxMap[r.type];
|
|
217
221
|
r.Field = `@Field({${fields.join(',')}})`;
|
|
218
|
-
r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
219
|
-
r.NAME = r.Name.replace(/\w/, (v) => v.toUpperCase());
|
|
222
|
+
r.Name = r.name.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
223
|
+
r.NAME = r.Name.replace(/\w/, (v: string) => v.toUpperCase());
|
|
220
224
|
return r;
|
|
221
225
|
});
|
|
222
226
|
conn.release();
|
|
223
227
|
return { columns, logicDelete };
|
|
224
228
|
}
|
|
225
|
-
async function excute(command, input, modelName) {
|
|
229
|
+
async function excute(command: string, input: string, modelName: string) {
|
|
226
230
|
const tables = await getTables(input);
|
|
227
231
|
if (input !== '.') {
|
|
228
|
-
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
232
|
+
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
229
233
|
if (checkTable.length !== tables.length) {
|
|
230
234
|
console.error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
|
|
231
235
|
return;
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
|
-
modelName
|
|
238
|
+
modelName ??= '';
|
|
235
239
|
const modelPath = modelName ? `/${modelName}/` : '';
|
|
236
240
|
for (const { tableName, title } of tables) {
|
|
237
241
|
const { columns, logicDelete } = await getColumns(tableName);
|
|
238
|
-
const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
239
|
-
const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
|
|
242
|
+
const className = tableName.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
243
|
+
const ClassName = className.replace(/\w/, (v: string) => v.toUpperCase());
|
|
240
244
|
const vueName = tableName.replace(/_/g, '-');
|
|
241
245
|
const splitName = tableName.replace(/_/g, '/');
|
|
242
|
-
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
246
|
+
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
243
247
|
const data = {
|
|
244
248
|
title,
|
|
249
|
+
|
|
245
250
|
tableName,
|
|
246
251
|
className,
|
|
247
252
|
ClassName,
|
|
248
253
|
vueName,
|
|
249
254
|
splitName,
|
|
250
255
|
SplitName,
|
|
256
|
+
|
|
251
257
|
columns,
|
|
252
258
|
columnNames: columns?.map(i => i.name),
|
|
253
259
|
ColumnNames: columns?.map(i => i.Name),
|
|
254
260
|
columnNames_join: columns?.map(i => i.name).join(','),
|
|
255
261
|
ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
|
|
262
|
+
|
|
256
263
|
columns_no_id: columns?.filter(i => !i.id),
|
|
257
264
|
columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
|
|
258
265
|
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
|
259
266
|
columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
|
|
260
267
|
ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
|
|
268
|
+
|
|
261
269
|
ids: columns?.filter(i => i.id),
|
|
262
270
|
idNames: columns?.filter(i => i.id).map(i => i.name),
|
|
263
271
|
IdNames: columns?.filter(i => i.id).map(i => i.Name),
|
|
264
272
|
idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
|
|
265
273
|
IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
|
|
274
|
+
|
|
266
275
|
modelName,
|
|
267
276
|
modelPath,
|
|
277
|
+
|
|
268
278
|
logicDelete
|
|
269
279
|
};
|
|
270
280
|
const template = templates[command];
|
|
@@ -273,9 +283,9 @@ try {
|
|
|
273
283
|
return;
|
|
274
284
|
}
|
|
275
285
|
const txt = mustache.render(template, data, {}, ['<%', '%>']);
|
|
276
|
-
const _fileName = configData.command[command]
|
|
286
|
+
const _fileName = configData.command[command]!.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]);
|
|
277
287
|
const fileNames = _fileName.split(',');
|
|
278
|
-
for
|
|
288
|
+
for(const fileName of fileNames){
|
|
279
289
|
const filePath = path.join(basepath, fileName);
|
|
280
290
|
const dirname = path.dirname(filePath);
|
|
281
291
|
mkdir('-p', dirname);
|
|
@@ -290,31 +300,28 @@ try {
|
|
|
290
300
|
if (force === false) {
|
|
291
301
|
console.warn(`[跳过] ${filePath}`);
|
|
292
302
|
return;
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
303
|
+
} else {
|
|
295
304
|
console.warn(`[覆盖] ${filePath}`);
|
|
296
305
|
}
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
306
|
+
} catch (error) {
|
|
299
307
|
console.info(`[生成] ${filePath}`);
|
|
300
308
|
}
|
|
301
309
|
if (configData.output) {
|
|
302
|
-
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]));
|
|
310
|
+
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]));
|
|
303
311
|
}
|
|
304
312
|
fs.writeFileSync(path.join(basepath, fileName), txt);
|
|
305
313
|
}
|
|
306
314
|
}
|
|
307
315
|
}
|
|
308
316
|
const replServer = start();
|
|
309
|
-
function defineCommand(command, comands) {
|
|
317
|
+
function defineCommand(command: string, comands?: string[]) {
|
|
310
318
|
if (comands) {
|
|
311
319
|
console.log(`[组合]${command}>${comands.join(',')}注册成功`);
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
320
|
+
} else {
|
|
314
321
|
console.log(`[命令]${command}注册成功`);
|
|
315
322
|
}
|
|
316
323
|
if (comands) {
|
|
317
|
-
replServer.defineCommand(command, async
|
|
324
|
+
replServer.defineCommand(command, async input => {
|
|
318
325
|
outputs.clear();
|
|
319
326
|
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
320
327
|
if (inputs?.length !== 3) {
|
|
@@ -322,21 +329,20 @@ try {
|
|
|
322
329
|
}
|
|
323
330
|
const [_, tables, modelName] = inputs;
|
|
324
331
|
for (const c of comands) {
|
|
325
|
-
await excute(c, tables
|
|
332
|
+
await excute(c, tables!, modelName ?? '');
|
|
326
333
|
}
|
|
327
334
|
console.info('执行完毕!下面打印生成的输出');
|
|
328
335
|
console.info(Array.from(outputs).join(','));
|
|
329
336
|
});
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
replServer.defineCommand(command, async (input) => {
|
|
337
|
+
} else {
|
|
338
|
+
replServer.defineCommand(command, async input => {
|
|
333
339
|
outputs.clear();
|
|
334
340
|
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
335
341
|
if (inputs?.length !== 3) {
|
|
336
342
|
return console.error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
337
343
|
}
|
|
338
344
|
const [_, tables, modelName] = inputs;
|
|
339
|
-
await excute(command, tables
|
|
345
|
+
await excute(command, tables!, modelName ?? '');
|
|
340
346
|
console.info('执行完毕!下面打印生成的输出');
|
|
341
347
|
console.info(Array.from(outputs).join(','));
|
|
342
348
|
});
|
|
@@ -350,25 +356,22 @@ try {
|
|
|
350
356
|
for (const command of Object.keys(configData.command)) {
|
|
351
357
|
if (!templates[command]) {
|
|
352
358
|
console.error(`命令:${command}没有定义模板,该命令不会生效`);
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
359
|
+
} else {
|
|
355
360
|
defineCommand(command);
|
|
356
361
|
}
|
|
357
362
|
}
|
|
358
363
|
}
|
|
359
364
|
if (configData.commands) {
|
|
360
365
|
for (const [command, commands] of Object.entries(configData.commands)) {
|
|
361
|
-
const keys = commands;
|
|
366
|
+
const keys = commands as string[];
|
|
362
367
|
const error = keys.filter(k => !templates[k]).join(',');
|
|
363
368
|
if (error) {
|
|
364
369
|
console.error(`组合命令:${command}定义了${commands},但是${error}没有定义模板,该命令不会生效`);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
370
|
+
} else {
|
|
367
371
|
defineCommand(command, keys);
|
|
368
372
|
}
|
|
369
373
|
}
|
|
370
374
|
}
|
|
371
|
-
}
|
|
372
|
-
catch (error) {
|
|
375
|
+
} catch (error) {
|
|
373
376
|
console.error(error);
|
|
374
377
|
}
|