baja-lite 1.1.4 → 1.1.8

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.
Files changed (76) hide show
  1. package/boot-remote.d.ts +2 -0
  2. package/{src/boot-remote.ts → boot-remote.js} +6 -7
  3. package/boot.d.ts +2 -0
  4. package/{src/boot.ts → boot.js} +32 -39
  5. package/code.d.ts +2 -0
  6. package/{src/code.ts → code.js} +69 -69
  7. package/convert-xml.d.ts +10 -0
  8. package/{src/convert-xml.ts → convert-xml.js} +105 -155
  9. package/enum.d.ts +18 -0
  10. package/enum.js +59 -0
  11. package/error.d.ts +5 -0
  12. package/error.js +13 -0
  13. package/fn.d.ts +128 -0
  14. package/fn.js +172 -0
  15. package/{src/index.ts → index.d.ts} +11 -11
  16. package/index.js +11 -0
  17. package/list.d.ts +10 -0
  18. package/{src/list.ts → list.js} +8 -9
  19. package/math.d.ts +83 -0
  20. package/math.js +451 -0
  21. package/object.d.ts +83 -0
  22. package/object.js +221 -0
  23. package/package.json +2 -1
  24. package/set-ex.d.ts +198 -0
  25. package/set-ex.js +338 -0
  26. package/sql.d.ts +1858 -0
  27. package/sql.js +5025 -0
  28. package/sqlite.d.ts +32 -0
  29. package/{src/sqlite.ts → sqlite.js} +53 -52
  30. package/string.d.ts +17 -0
  31. package/string.js +105 -0
  32. package/test-mysql.d.ts +2 -0
  33. package/{src/test-mysql.ts → test-mysql.js} +135 -126
  34. package/test-postgresql.d.ts +2 -0
  35. package/test-postgresql.js +90 -0
  36. package/test-sqlite.d.ts +1 -0
  37. package/{src/test-sqlite.ts → test-sqlite.js} +89 -80
  38. package/test-xml.d.ts +1 -0
  39. package/{src/test-xml.ts → test-xml.js} +1 -1
  40. package/test.d.ts +1 -0
  41. package/test.js +2 -0
  42. package/wx/base.d.ts +11 -0
  43. package/wx/base.js +78 -0
  44. package/wx/mini.d.ts +45 -0
  45. package/wx/mini.js +102 -0
  46. package/wx/organ.d.ts +65 -0
  47. package/wx/organ.js +171 -0
  48. package/{src/wx/types.ts → wx/types.d.ts} +21 -10
  49. package/wx/types.js +1 -0
  50. package/wx.js +3 -0
  51. package/.eslintignore +0 -7
  52. package/.eslintrc.cjs +0 -89
  53. package/.prettierrc +0 -4
  54. package/ci.js +0 -29
  55. package/package-cjs.json +0 -17
  56. package/src/enum.ts +0 -71
  57. package/src/error.ts +0 -11
  58. package/src/fn.ts +0 -295
  59. package/src/math.ts +0 -405
  60. package/src/object.ts +0 -247
  61. package/src/set-ex.ts +0 -374
  62. package/src/sql.ts +0 -5281
  63. package/src/string.ts +0 -111
  64. package/src/test-postgresql.ts +0 -79
  65. package/src/test.ts +0 -2
  66. package/src/wx/base.ts +0 -76
  67. package/src/wx/mini.ts +0 -133
  68. package/src/wx/organ.ts +0 -290
  69. package/test.json +0 -0
  70. package/tsconfig.base.json +0 -80
  71. package/tsconfig.cjs.json +0 -42
  72. package/tsconfig.json +0 -44
  73. package/xml/event-report.xml +0 -13
  74. package/yarn.lock +0 -1493
  75. /package/{Readme.md → README.md} +0 -0
  76. /package/{src/wx.ts → wx.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ import { GlobalSqlOptionForWeb } from './sql.js';
2
+ export declare const BootRomote: (options: GlobalSqlOptionForWeb) => Promise<void>;
@@ -1,7 +1,6 @@
1
1
  import { getEnums } from './enum.js';
2
- import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, GlobalSqlOptionForWeb, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql.js';
3
-
4
- export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
2
+ import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql.js';
3
+ export const BootRomote = async function (options) {
5
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
6
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
7
6
  logger.level = options.log ?? 'info';
@@ -19,7 +18,8 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
19
18
  if (typeof options.SqliteRemote.db === 'string') {
20
19
  options.SqliteRemote.service.initDB(options.SqliteRemote.db);
21
20
  globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
22
- } else {
21
+ }
22
+ else {
23
23
  let flag = false;
24
24
  for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
25
25
  await options.SqliteRemote.service.initDB(fileName);
@@ -32,8 +32,7 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
32
32
  }
33
33
  }
34
34
  }
35
- }
36
-
35
+ };
37
36
  // export const AppendRomote = async function (dbName: string) {
38
37
  // if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
39
38
  // globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
@@ -43,4 +42,4 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
43
42
  // }
44
43
  // globalThis[_dao][DBType.SqliteRemote][dbName] = db;
45
44
  // }
46
- // }
45
+ // }
package/boot.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { GlobalSqlOption } from './sql.js';
2
+ export declare const Boot: (options: GlobalSqlOption) => Promise<void>;
@@ -1,7 +1,6 @@
1
1
  import { getEnums } from './enum.js';
2
- import { _GlobalSqlOption, GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql.js';
3
-
4
- export const Boot = async function (options: GlobalSqlOption) {
2
+ import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql.js';
3
+ export const Boot = async function (options) {
5
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
6
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
7
6
  if (options.sqlDir) {
@@ -33,8 +32,8 @@ export const Boot = async function (options: GlobalSqlOption) {
33
32
  decimalNumbers: true,
34
33
  supportBigNumbers: true
35
34
  }));
36
-
37
- } else {
35
+ }
36
+ else {
38
37
  let flag = false;
39
38
  for (const [key, option] of Object.entries(options.Mysql)) {
40
39
  const db = new Mysql(createPool({
@@ -43,7 +42,6 @@ export const Boot = async function (options: GlobalSqlOption) {
43
42
  decimalNumbers: true,
44
43
  supportBigNumbers: true
45
44
  }));
46
-
47
45
  if (flag === false) {
48
46
  globalThis[_dao][DBType.Mysql][_primaryDB] = db;
49
47
  flag = true;
@@ -55,7 +53,8 @@ export const Boot = async function (options: GlobalSqlOption) {
55
53
  if (options.Sqlite) {
56
54
  if (typeof options.Sqlite === 'string') {
57
55
  globalThis[_dao][DBType.Sqlite][_primaryDB] = new Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
58
- } else {
56
+ }
57
+ else {
59
58
  let flag = false;
60
59
  for (const [key, fileName] of Object.entries(options.Sqlite)) {
61
60
  const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
@@ -71,7 +70,8 @@ export const Boot = async function (options: GlobalSqlOption) {
71
70
  if (typeof options.SqliteRemote.db === 'string') {
72
71
  options.SqliteRemote.service.initDB(options.SqliteRemote.db);
73
72
  globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
74
- } else {
73
+ }
74
+ else {
75
75
  let flag = false;
76
76
  for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
77
77
  options.SqliteRemote.service.initDB(fileName);
@@ -88,7 +88,8 @@ export const Boot = async function (options: GlobalSqlOption) {
88
88
  const { Redis } = await import('ioredis');
89
89
  if (options.Redis['host']) {
90
90
  globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
91
- } else {
91
+ }
92
+ else {
92
93
  let flag = false;
93
94
  for (const [key, option] of Object.entries(options.Redis)) {
94
95
  const db = new Redis(option);
@@ -99,32 +100,25 @@ export const Boot = async function (options: GlobalSqlOption) {
99
100
  globalThis[_dao][DBType.Redis][key] = db;
100
101
  }
101
102
  }
102
- const clients = Object.values(globalThis[_dao][DBType.Redis]) as any;
103
+ const clients = Object.values(globalThis[_dao][DBType.Redis]);
103
104
  const Redlock = await import('redlock');
104
- globalThis[_dao][DBType.RedisLock] = new Redlock.default(
105
- clients,
106
- {
107
- // The expected clock drift; for more details see:
108
- // http://redis.io/topics/distlock
109
- driftFactor: 0.01, // multiplied by lock ttl to determine drift time
110
-
111
- // The max number of times Redlock will attempt to lock a resource
112
- // before erroring.
113
- retryCount: 10,
114
-
115
- // the time in ms between attempts
116
- retryDelay: 200, // time in ms
117
-
118
- // the max time in ms randomly added to retries
119
- // to improve performance under high contention
120
- // see https://www.awsarchitectureblog.com/2015/03/backoff.html
121
- retryJitter: 200, // time in ms
122
-
123
- // The minimum remaining time on a lock before an extension is automatically
124
- // attempted with the `using` API.
125
- automaticExtensionThreshold: 500, // time in ms
126
- }
127
- );
105
+ globalThis[_dao][DBType.RedisLock] = new Redlock.default(clients, {
106
+ // The expected clock drift; for more details see:
107
+ // http://redis.io/topics/distlock
108
+ driftFactor: 0.01, // multiplied by lock ttl to determine drift time
109
+ // The max number of times Redlock will attempt to lock a resource
110
+ // before erroring.
111
+ retryCount: 10,
112
+ // the time in ms between attempts
113
+ retryDelay: 200, // time in ms
114
+ // the max time in ms randomly added to retries
115
+ // to improve performance under high contention
116
+ // see https://www.awsarchitectureblog.com/2015/03/backoff.html
117
+ retryJitter: 200, // time in ms
118
+ // The minimum remaining time on a lock before an extension is automatically
119
+ // attempted with the `using` API.
120
+ automaticExtensionThreshold: 500, // time in ms
121
+ });
128
122
  const { EventEmitter } = await import('events');
129
123
  const event = new EventEmitter({ captureRejections: true });
130
124
  event.on('error', error => {
@@ -133,15 +127,14 @@ export const Boot = async function (options: GlobalSqlOption) {
133
127
  globalThis[_EventBus] = event;
134
128
  }
135
129
  if (options.Postgresql) {
136
- const Pool = await import('pg-pool');
130
+ const Pool = await import('pg-pool');
137
131
  if (options.Postgresql['host']) {
138
132
  globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
139
-
140
- } else {
133
+ }
134
+ else {
141
135
  let flag = false;
142
136
  for (const [key, option] of Object.entries(options.Postgresql)) {
143
137
  const db = new Postgresql(new Pool.default(option));
144
-
145
138
  if (flag === false) {
146
139
  globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
147
140
  flag = true;
@@ -150,4 +143,4 @@ export const Boot = async function (options: GlobalSqlOption) {
150
143
  }
151
144
  }
152
145
  }
153
- }
146
+ };
package/code.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -5,7 +5,6 @@ import { start } from 'repl';
5
5
  import { createPool } from 'mysql2/promise';
6
6
  import mustache from 'mustache';
7
7
  import { mkdir } from 'shelljs';
8
-
9
8
  const lxMap = {
10
9
  tinyint: "number",
11
10
  smallint: "number",
@@ -48,7 +47,7 @@ const lxMap = {
48
47
  geometrycollection: "Object"
49
48
  };
50
49
  let force = false;
51
- const basepath = path.join(__dirname, '..', '..', '..');
50
+ const basepath = path.join(__dirname, '..', '..');
52
51
  const config = path.join(basepath, 'baja.code.json');
53
52
  const templatePath = path.join(basepath, 'code-template');
54
53
  console.log(`
@@ -110,7 +109,8 @@ console.log(`
110
109
  ], Field(类型string),表示字段的注解, Type 表示JS类型
111
110
  columnNames_join: 'sku_id, sku_name'
112
111
  ColumnNames_join: 'sku_id skuId, sku_name skuName'
113
-
112
+ columnNames_joinT: 't.sku_id, t.sku_name'
113
+ ColumnNames_joinT: 't.sku_id skuId, t.sku_name skuName'
114
114
  columns_no_id: [], 同columns,没有ID而已
115
115
  columnNames_no_id: [],
116
116
 
@@ -129,26 +129,10 @@ console.log(`
129
129
  -----
130
130
  force: 切换是否覆盖
131
131
  `);
132
-
133
-
134
132
  try {
135
- const outputs = new Set<string>();
133
+ const outputs = new Set();
136
134
  const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
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
+ const configData = JSON.parse(_configData);
152
136
  const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
153
137
  const pool = createPool({
154
138
  host: configData.host,
@@ -157,9 +141,9 @@ try {
157
141
  password: configData.password,
158
142
  database: configData.database
159
143
  });
160
- async function getTables(tableName: string) {
144
+ async function getTables(tableName) {
161
145
  const conn = await pool.getConnection();
162
- const params: (string | string[])[] = [configData.database];
146
+ const params = [configData.database];
163
147
  let sql = `
164
148
  SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
165
149
  WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
@@ -167,13 +151,13 @@ try {
167
151
  sql += ` AND TABLE_NAME IN (?)`;
168
152
  params.push(tableName.split(/,|\s/).map(r => r.trim()));
169
153
  }
170
- const [result] = await conn.query<any[]>(sql, params);
154
+ const [result] = await conn.query(sql, params);
171
155
  conn.release();
172
156
  return result;
173
157
  }
174
- async function getColumns(tableName: string) {
158
+ async function getColumns(tableName) {
175
159
  const conn = await pool.getConnection();
176
- const [result] = await conn.query<any[]>(`
160
+ const [result] = await conn.query(`
177
161
  SELECT
178
162
  DATA_TYPE type,
179
163
  COLUMN_NAME \`name\`,
@@ -187,27 +171,38 @@ try {
187
171
  `, [configData.database, tableName]);
188
172
  let logicDelete = '';
189
173
  const columns = result.map(r => {
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}`); }
174
+ if (r.id === 1) {
175
+ r.id = true;
176
+ }
177
+ else
178
+ delete r.id;
179
+ if (r.notNull === 1) {
180
+ r.notNull = true;
181
+ }
182
+ else
183
+ delete r.notNull;
184
+ const fields = new Array(`type:SqlType.${r.type}`);
185
+ if (r.length !== null) {
186
+ fields.push(`length:${r.length}`);
187
+ }
188
+ if (r.scale !== null) {
189
+ fields.push(`scale:${r.scale}`);
190
+ }
199
191
  if (r.def !== null) {
200
- r.def ??= '';
192
+ r.def ?? (r.def = '');
201
193
  if (isNaN(r.def) || r.def === '') {
202
194
  fields.push(`def:'${r.def}'`);
203
- } else {
195
+ }
196
+ else {
204
197
  fields.push(`def:${r.def}`);
205
198
  }
206
199
  }
207
200
  if (r.id === true) {
208
201
  fields.push(`id:true`);
209
202
  }
210
- if (r.notNull === true) { fields.push(`notNull:true`); }
203
+ if (r.notNull === true) {
204
+ fields.push(`notNull:true`);
205
+ }
211
206
  if (r.id === true && configData.id) {
212
207
  fields.push(configData.id);
213
208
  }
@@ -215,66 +210,64 @@ try {
215
210
  fields.push(`logicDelete: ${configData.logicDeleteV}`);
216
211
  logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
217
212
  }
218
- if (r.comment) { fields.push(`comment: '${r.comment}'`); }
213
+ if (r.comment) {
214
+ fields.push(`comment: '${r.comment}'`);
215
+ }
219
216
  r.comment = r.comment ?? '';
220
217
  r.Type = lxMap[r.type];
221
218
  r.Field = `@Field({${fields.join(',')}})`;
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());
219
+ r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
220
+ r.NAME = r.Name.replace(/\w/, (v) => v.toUpperCase());
224
221
  return r;
225
222
  });
226
223
  conn.release();
227
224
  return { columns, logicDelete };
228
225
  }
229
- async function excute(command: string, input: string, modelName: string) {
226
+ async function excute(command, input, modelName) {
230
227
  const tables = await getTables(input);
231
228
  if (input !== '.') {
232
- const checkTable = input.split(/,|\s/).map(r => r.trim())
229
+ const checkTable = input.split(/,|\s/).map(r => r.trim());
233
230
  if (checkTable.length !== tables.length) {
234
231
  console.error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
235
232
  return;
236
233
  }
237
234
  }
238
- modelName ??= '';
235
+ modelName ?? (modelName = '');
239
236
  const modelPath = modelName ? `/${modelName}/` : '';
240
237
  for (const { tableName, title } of tables) {
241
238
  const { columns, logicDelete } = await getColumns(tableName);
242
- const className = tableName.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
243
- const ClassName = className.replace(/\w/, (v: string) => v.toUpperCase());
239
+ const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
240
+ const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
244
241
  const vueName = tableName.replace(/_/g, '-');
245
242
  const splitName = tableName.replace(/_/g, '/');
246
- const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
243
+ const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
247
244
  const data = {
248
245
  title,
249
-
250
246
  tableName,
251
247
  className,
252
248
  ClassName,
253
249
  vueName,
254
250
  splitName,
255
251
  SplitName,
256
-
257
252
  columns,
258
253
  columnNames: columns?.map(i => i.name),
259
254
  ColumnNames: columns?.map(i => i.Name),
260
255
  columnNames_join: columns?.map(i => i.name).join(','),
261
256
  ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
262
-
257
+ columnNames_joinT: columns?.map(i => `t.${i.name}`).join(','),
258
+ ColumnNames_joinT: columns?.map(i => `t.${i.name} ${i.Name}`).join(','),
263
259
  columns_no_id: columns?.filter(i => !i.id),
264
260
  columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
265
261
  ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
266
262
  columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
267
263
  ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
268
-
269
264
  ids: columns?.filter(i => i.id),
270
265
  idNames: columns?.filter(i => i.id).map(i => i.name),
271
266
  IdNames: columns?.filter(i => i.id).map(i => i.Name),
272
267
  idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
273
268
  IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
274
-
275
269
  modelName,
276
270
  modelPath,
277
-
278
271
  logicDelete
279
272
  };
280
273
  const template = templates[command];
@@ -283,9 +276,9 @@ try {
283
276
  return;
284
277
  }
285
278
  const txt = mustache.render(template, data, {}, ['<%', '%>']);
286
- const _fileName = configData.command[command]!.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]);
279
+ const _fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]);
287
280
  const fileNames = _fileName.split(',');
288
- for(const fileName of fileNames){
281
+ for (const fileName of fileNames) {
289
282
  const filePath = path.join(basepath, fileName);
290
283
  const dirname = path.dirname(filePath);
291
284
  mkdir('-p', dirname);
@@ -300,28 +293,31 @@ try {
300
293
  if (force === false) {
301
294
  console.warn(`[跳过] ${filePath}`);
302
295
  return;
303
- } else {
296
+ }
297
+ else {
304
298
  console.warn(`[覆盖] ${filePath}`);
305
299
  }
306
- } catch (error) {
300
+ }
301
+ catch (error) {
307
302
  console.info(`[生成] ${filePath}`);
308
303
  }
309
304
  if (configData.output) {
310
- outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]));
305
+ outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]));
311
306
  }
312
307
  fs.writeFileSync(path.join(basepath, fileName), txt);
313
308
  }
314
309
  }
315
310
  }
316
311
  const replServer = start();
317
- function defineCommand(command: string, comands?: string[]) {
312
+ function defineCommand(command, comands) {
318
313
  if (comands) {
319
314
  console.log(`[组合]${command}>${comands.join(',')}注册成功`);
320
- } else {
315
+ }
316
+ else {
321
317
  console.log(`[命令]${command}注册成功`);
322
318
  }
323
319
  if (comands) {
324
- replServer.defineCommand(command, async input => {
320
+ replServer.defineCommand(command, async (input) => {
325
321
  outputs.clear();
326
322
  const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
327
323
  if (inputs?.length !== 3) {
@@ -329,20 +325,21 @@ try {
329
325
  }
330
326
  const [_, tables, modelName] = inputs;
331
327
  for (const c of comands) {
332
- await excute(c, tables!, modelName ?? '');
328
+ await excute(c, tables, modelName ?? '');
333
329
  }
334
330
  console.info('执行完毕!下面打印生成的输出');
335
331
  console.info(Array.from(outputs).join(','));
336
332
  });
337
- } else {
338
- replServer.defineCommand(command, async input => {
333
+ }
334
+ else {
335
+ replServer.defineCommand(command, async (input) => {
339
336
  outputs.clear();
340
337
  const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
341
338
  if (inputs?.length !== 3) {
342
339
  return console.error(`[错误]命令格式应为: table1,table2[:模块名]`);
343
340
  }
344
341
  const [_, tables, modelName] = inputs;
345
- await excute(command, tables!, modelName ?? '');
342
+ await excute(command, tables, modelName ?? '');
346
343
  console.info('执行完毕!下面打印生成的输出');
347
344
  console.info(Array.from(outputs).join(','));
348
345
  });
@@ -356,22 +353,25 @@ try {
356
353
  for (const command of Object.keys(configData.command)) {
357
354
  if (!templates[command]) {
358
355
  console.error(`命令:${command}没有定义模板,该命令不会生效`);
359
- } else {
356
+ }
357
+ else {
360
358
  defineCommand(command);
361
359
  }
362
360
  }
363
361
  }
364
362
  if (configData.commands) {
365
363
  for (const [command, commands] of Object.entries(configData.commands)) {
366
- const keys = commands as string[];
364
+ const keys = commands;
367
365
  const error = keys.filter(k => !templates[k]).join(',');
368
366
  if (error) {
369
367
  console.error(`组合命令:${command}定义了${commands},但是${error}没有定义模板,该命令不会生效`);
370
- } else {
368
+ }
369
+ else {
371
370
  defineCommand(command, keys);
372
371
  }
373
372
  }
374
373
  }
375
- } catch (error) {
374
+ }
375
+ catch (error) {
376
376
  console.error(error);
377
377
  }
@@ -0,0 +1,10 @@
1
+ export interface XML {
2
+ type: 'tag' | 'text';
3
+ name: string;
4
+ id?: string;
5
+ voidElement: boolean;
6
+ attrs: Record<string, string>;
7
+ children: XML[];
8
+ content: string;
9
+ }
10
+ export declare const convert: (childrens: XML[], param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) => string;