baja-lite 1.0.6 → 1.0.10

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/es/sqlite.d.ts CHANGED
@@ -23,14 +23,11 @@ export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface
23
23
  */
24
24
  abstract setMod(name: string): void;
25
25
  abstract trace: boolean;
26
- execute(dbName: string, sql?: string | undefined, params?: any): Promise<{
27
- affectedRows: number;
28
- insertId: bigint;
29
- }>;
30
- pluck<One_Row_Many_Column = any>(dbName: string, sql?: string | undefined, params?: any): Promise<One_Row_Many_Column | null>;
31
- get<One_Row_Many_Column = any>(dbName: string, sql?: string | undefined, params?: any): Promise<One_Row_Many_Column | null>;
32
- raw<Many_Row_One_Column = any>(dbName: string, sql?: string | undefined, params?: any): Promise<Many_Row_One_Column[]>;
33
- query<Many_Row_Many_Column = any>(dbName: string, sql?: string | undefined, params?: any): Promise<Many_Row_Many_Column[]>;
26
+ execute(inData: Uint8Array): Promise<Uint8Array>;
27
+ pluck(inData: Uint8Array): Promise<Uint8Array>;
28
+ get(inData: Uint8Array): Promise<Uint8Array>;
29
+ raw(inData: Uint8Array): Promise<Uint8Array>;
30
+ query(inData: Uint8Array): Promise<Uint8Array>;
34
31
  initDB(dbName: string): Promise<void>;
35
32
  export(dbName: string): Promise<void>;
36
33
  restore(dbName: string): Promise<void>;
package/es/sqlite.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { logger } from './sql';
2
2
  import Sqlstring from 'sqlstring';
3
+ import { encode, decode } from "@msgpack/msgpack";
3
4
  export class SqliteRemoteClass {
4
5
  constructor() {
5
6
  this.dbList = {};
6
7
  }
7
- async execute(dbName, sql, params) {
8
+ async execute(inData) {
9
+ const [dbName, sql, params] = decode(inData);
10
+ logger.debug(sql, params ?? '');
8
11
  try {
9
- logger.debug(sql, params ?? '');
10
12
  if (!sql) {
11
- return { affectedRows: 0, insertId: 0n };
13
+ return encode({ affectedRows: 0, insertId: 0n });
12
14
  }
13
15
  ;
14
16
  if (this.trace) {
@@ -19,7 +21,7 @@ export class SqliteRemoteClass {
19
21
  logger.trace(result);
20
22
  }
21
23
  const { changes, lastInsertRowid } = result;
22
- return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
24
+ return encode({ affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n });
23
25
  }
24
26
  catch (error) {
25
27
  logger.error(`
@@ -30,17 +32,19 @@ export class SqliteRemoteClass {
30
32
  throw error;
31
33
  }
32
34
  }
33
- async pluck(dbName, sql, params) {
35
+ async pluck(inData) {
36
+ const [dbName, sql, params] = decode(inData);
37
+ logger.debug(sql, params ?? '');
34
38
  try {
35
39
  logger.debug(sql, params ?? '');
36
40
  if (!sql) {
37
- return null;
41
+ return encode(null);
38
42
  }
39
43
  ;
40
44
  if (this.trace) {
41
45
  logger.trace(Sqlstring.format(sql, params));
42
46
  }
43
- return this.dbList[dbName].prepare(sql).pluck().get(params ?? {});
47
+ return encode(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}));
44
48
  }
45
49
  catch (error) {
46
50
  logger.error(`
@@ -51,17 +55,14 @@ export class SqliteRemoteClass {
51
55
  throw error;
52
56
  }
53
57
  }
54
- async get(dbName, sql, params) {
58
+ async get(inData) {
59
+ const [dbName, sql, params] = decode(inData);
60
+ logger.debug(sql, params ?? '');
55
61
  try {
56
- logger.debug(sql, params ?? '');
57
- if (!sql) {
58
- return null;
59
- }
60
- ;
61
62
  if (this.trace) {
62
63
  logger.trace(Sqlstring.format(sql, params));
63
64
  }
64
- return this.dbList[dbName].prepare(sql).get(params ?? {});
65
+ return encode(this.dbList[dbName].prepare(sql).get(params ?? {}));
65
66
  }
66
67
  catch (error) {
67
68
  logger.error(`
@@ -72,17 +73,18 @@ export class SqliteRemoteClass {
72
73
  throw error;
73
74
  }
74
75
  }
75
- async raw(dbName, sql, params) {
76
+ async raw(inData) {
77
+ const [dbName, sql, params] = decode(inData);
78
+ logger.debug(sql, params ?? '');
76
79
  try {
77
- logger.debug(sql, params ?? '');
78
80
  if (!sql) {
79
- return [];
81
+ return encode([]);
80
82
  }
81
83
  ;
82
84
  if (this.trace) {
83
85
  logger.trace(Sqlstring.format(sql, params));
84
86
  }
85
- return this.dbList[dbName].prepare(sql).raw().all(params ?? {});
87
+ return encode(this.dbList[dbName].prepare(sql).raw().all(params ?? {}));
86
88
  }
87
89
  catch (error) {
88
90
  logger.error(`
@@ -93,17 +95,18 @@ export class SqliteRemoteClass {
93
95
  throw error;
94
96
  }
95
97
  }
96
- async query(dbName, sql, params) {
98
+ async query(inData) {
99
+ const [dbName, sql, params] = decode(inData);
100
+ logger.debug(sql, params ?? '');
97
101
  try {
98
- logger.debug(sql, params ?? '');
99
102
  if (!sql) {
100
- return [];
103
+ encode([]);
101
104
  }
102
105
  ;
103
106
  if (this.trace) {
104
107
  logger.trace(Sqlstring.format(sql, params));
105
108
  }
106
- return this.dbList[dbName].prepare(sql).all(params ?? {});
109
+ return encode(this.dbList[dbName].prepare(sql).all(params ?? {}));
107
110
  }
108
111
  catch (error) {
109
112
  logger.error(`
package/es/test-mysql.js CHANGED
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import 'reflect-metadata';
11
11
  import { Boot } from './boot';
12
- import { SqlService, Field, DB, DBType, SqlType, ColumnMode, } from './sql';
12
+ import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql';
13
13
  class AmaFuck2 {
14
14
  }
15
15
  __decorate([
@@ -31,6 +31,12 @@ AmaService2 = __decorate([
31
31
  tableName: 'ama_fuck', clz: AmaFuck2, dbType: DBType.Mysql
32
32
  })
33
33
  ], AmaService2);
34
+ // interface Menu {
35
+ // resourceid: string;
36
+ // resourcepid: string;
37
+ // resourcename: string;
38
+ // children: Menu[];
39
+ // }
34
40
  export async function go2() {
35
41
  await Boot({
36
42
  Mysql: {
@@ -44,7 +50,10 @@ export async function go2() {
44
50
  },
45
51
  log: 'info',
46
52
  columnMode: ColumnMode.HUMP,
47
- sqlDir: 'E:/pro/baja-lite/xml'
53
+ sqlDir: 'E:/pro/baja-lite/xml',
54
+ sqlMap: {
55
+ ['test.test']: `SELECT * FROM cp_user {{#username}} WHERE username = :username {{/username}}`
56
+ }
48
57
  });
49
58
  const service = new AmaService2();
50
59
  await service.transaction({
@@ -96,13 +105,12 @@ export async function go2() {
96
105
  // templateResult: TemplateResult.Many
97
106
  // })
98
107
  // console.log(44, rt4);
99
- // const rt5 = await service.select<string>({
100
- // sql: `SELECT seller_sku FROM ama_fuck WHERE seller_sku LIKE CONCAT(:sku, '%');SELECT seller_sku FROM ama_fuck WHERE seller_sku LIKE CONCAT(:sku, '%');SELECT seller_sku FROM ama_fuck WHERE seller_sku LIKE CONCAT(:sku, '%')`,
101
- // params: { sku: 'SellerSKU4' },
102
- // selectResult: SelectResult.Many_Row_One_Column,
103
- // multiple: true
104
- // })
105
- // console.log(55, rt5);
108
+ const rt5 = await service.select({
109
+ sqlId: 'test.test',
110
+ params: { username: '1111' },
111
+ selectResult: SelectResult.RS_CS
112
+ });
113
+ console.log(55, rt5.length);
106
114
  // const rt6 = await service.stream().eq('sellerSku', 'SellerSKU1').excuteSelect({
107
115
  // selectResult: SelectResult.Many_Row_Many_Column,
108
116
  // });
@@ -110,18 +118,18 @@ export async function go2() {
110
118
  return 1;
111
119
  }
112
120
  });
113
- const data = await service.select({
114
- sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
115
- params: {
116
- site: '1234',
117
- matchInfo: { reportType: 'yyyy', id: '11' }
118
- },
119
- // mapper: [
120
- // ['site', ['info', 'bSist'], 989],
121
- // ['site', ['info2', 'bSist'], 33],
122
- // ['site', ['Bsite'], 0]
123
- // ]
124
- });
125
- console.log(data);
121
+ // const data = await service.select<Menu>({
122
+ // sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
123
+ // params: {
124
+ // site: '1234',
125
+ // matchInfo: { reportType: 'yyyy', id: '11' }
126
+ // },
127
+ // // mapper: [
128
+ // // ['site', ['info', 'bSist'], 989],
129
+ // // ['site', ['info2', 'bSist'], 33],
130
+ // // ['site', ['Bsite'], 0]
131
+ // // ]
132
+ // });
133
+ // console.log(data);
126
134
  }
127
135
  go2();
package/package.json CHANGED
@@ -1,70 +1,70 @@
1
- {
2
- "name": "baja-lite",
3
- "version": "1.0.6",
4
- "description": "some util for self",
5
- "homepage": "https://github.com/void-soul/util-man",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/void-soul/util-man.git"
9
- },
10
- "license": "MIT",
11
- "author": "void-soul",
12
- "exports": {
13
- ".": {
14
- "types": "./es/index.d.ts",
15
- "import": "./es/index.js",
16
- "require": "./cjs/index.js"
17
- },
18
- "./*": "./*"
19
- },
20
- "bin": {
21
- "baja": "./cjs/code.js"
22
- },
23
- "main": "./cjs/index.js",
24
- "types": "./es/index.d.ts",
25
- "scripts": {
26
- "dist": "bun ./ci.ts",
27
- "mysql": "bun --inspect ./src/test-mysql.ts",
28
- "xml": "bun --inspect ./src/test-xml.ts",
29
- "mysql2": "node inspect ./dist/cjs/test-mysql.js",
30
- "sqlite": "node inspect ./dist/cjs/test-sqlite.js"
31
- },
32
- "dependencies": {
33
- "@types/lodash.get": "^4.4.9",
34
- "decimal.js": "10.4.3",
35
- "html-parse-stringify": "3.0.1",
36
- "iterare": "1.2.1",
37
- "lodash.get": "^4.4.2",
38
- "mustache": "4.2.0",
39
- "pino": "9.2.0",
40
- "pino-pretty": "11.2.1",
41
- "reflect-metadata": "0.2.2",
42
- "sql-formatter": "15.3.2",
43
- "sqlstring": "2.3.3",
44
- "tslib": "2.6.3"
45
- },
46
- "devDependencies": {
47
- "@types/better-sqlite3": "7.6.10",
48
- "@types/mustache": "4.2.5",
49
- "@types/node": "20.14.9",
50
- "@types/sqlstring": "2.3.2",
51
- "@typescript-eslint/eslint-plugin": "7.14.1",
52
- "@typescript-eslint/parser": "7.14.1",
53
- "better-sqlite3": "11.0.0",
54
- "ioredis": "5.4.1",
55
- "mongodb": "6.7.0",
56
- "mysql2": "3.10.1",
57
- "redlock": "5.0.0-beta.2",
58
- "shelljs": "0.8.5",
59
- "typescript": "5.5.2"
60
- },
61
- "engines": {
62
- "node": "20",
63
- "npm": ">= 6.13.4",
64
- "yarn": ">= 1.22.19"
65
- },
66
- "publishConfig": {
67
- "access": "public"
68
- },
69
- "models": "./es/index.js"
70
- }
1
+ {
2
+ "name": "baja-lite",
3
+ "version": "1.0.10",
4
+ "description": "some util for self",
5
+ "homepage": "https://github.com/void-soul/util-man",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/void-soul/util-man.git"
9
+ },
10
+ "license": "MIT",
11
+ "author": "void-soul",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./es/index.d.ts",
15
+ "import": "./es/index.js",
16
+ "require": "./cjs/index.js"
17
+ },
18
+ "./*": "./*"
19
+ },
20
+ "bin": {
21
+ "baja": "./cjs/code.js"
22
+ },
23
+ "main": "./cjs/index.js",
24
+ "types": "./es/index.d.ts",
25
+ "scripts": {
26
+ "dist": "node ./ci.js",
27
+ "mysql": "bun --inspect ./src/test-mysql.ts",
28
+ "xml": "bun --inspect ./src/test-xml.ts",
29
+ "mysql2": "node inspect ./dist/cjs/test-mysql.js",
30
+ "sqlite": "node inspect ./dist/cjs/test-sqlite.js"
31
+ },
32
+ "dependencies": {
33
+ "@msgpack/msgpack": "^3.0.0-beta2",
34
+ "@types/lodash.get": "^4.4.9",
35
+ "@types/shelljs": "^0.8.15",
36
+ "decimal.js": "10.4.3",
37
+ "html-parse-stringify": "3.0.1",
38
+ "iterare": "1.2.1",
39
+ "lodash.get": "^4.4.2",
40
+ "mustache": "4.2.0",
41
+ "pino": "9.2.0",
42
+ "pino-pretty": "11.2.1",
43
+ "reflect-metadata": "0.2.2",
44
+ "sql-formatter": "15.3.2",
45
+ "sqlstring": "2.3.3",
46
+ "tslib": "2.6.3"
47
+ },
48
+ "devDependencies": {
49
+ "@types/better-sqlite3": "7.6.11",
50
+ "@types/mustache": "4.2.5",
51
+ "@types/node": "20.14.10",
52
+ "@types/sqlstring": "2.3.2",
53
+ "@typescript-eslint/eslint-plugin": "7.15.0",
54
+ "@typescript-eslint/parser": "7.15.0",
55
+ "better-sqlite3": "11.0.0",
56
+ "ioredis": "5.4.1",
57
+ "mongodb": "6.8.0",
58
+ "mysql2": "3.10.2",
59
+ "redlock": "5.0.0-beta.2",
60
+ "shelljs": "0.8.5",
61
+ "typescript": "5.5.3"
62
+ },
63
+ "engines": {
64
+ "node": ">=20"
65
+ },
66
+ "models": "./es/index.js",
67
+ "publishConfig": {
68
+ "access": "public"
69
+ }
70
+ }
@@ -1,4 +1,5 @@
1
- import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, GlobalSqlOptionForWeb, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode } from './sql';
1
+ import { getEnums } from './enum';
2
+ import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, GlobalSqlOptionForWeb, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql';
2
3
 
3
4
  export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
4
5
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
@@ -11,6 +12,9 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
11
12
  globalThis[_dao] = {
12
13
  [DBType.SqliteRemote]: {},
13
14
  };
15
+ if (options.enums) {
16
+ globalThis[_enums] = getEnums(options.enums);
17
+ }
14
18
  if (options.SqliteRemote) {
15
19
  if (typeof options.SqliteRemote.db === 'string') {
16
20
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
package/src/boot.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { _GlobalSqlOption, GlobalSqlOption, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode } from './sql';
1
+ import { getEnums } from './enum';
2
+ import { _GlobalSqlOption, GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode } from './sql';
2
3
 
3
4
  export const Boot = async function (options: GlobalSqlOption) {
4
5
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
@@ -19,6 +20,9 @@ export const Boot = async function (options: GlobalSqlOption) {
19
20
  [DBType.SqliteRemote]: {},
20
21
  [DBType.Redis]: {}
21
22
  };
23
+ if (options.enums) {
24
+ globalThis[_enums] = getEnums(options.enums);
25
+ }
22
26
  if (options.Mysql) {
23
27
  const { createPool } = await import('mysql2/promise');
24
28
  if (options.Mysql['host']) {
package/src/code.ts CHANGED
@@ -4,6 +4,7 @@ import fs from 'fs';
4
4
  import { start } from 'repl';
5
5
  import { createPool } from 'mysql2/promise';
6
6
  import mustache from 'mustache';
7
+ import { mkdir } from 'shelljs';
7
8
 
8
9
  const lxMap = {
9
10
  tinyint: "number",
@@ -75,7 +76,10 @@ console.log(`
75
76
  "s": ["entity", "controller", "service", "sql", "module"]
76
77
  },
77
78
  "output": "{ClassName}Module",
78
- "id"? : "uuidShort: true, notNull: true, uuid: true"
79
+ "id"? : "uuidShort: true, notNull: true, uuid: true",
80
+ "logicDeleteK"?: "逻辑删除字段名",
81
+ "logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
82
+ "NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'"
79
83
  }
80
84
  command是生成命令,这里声明命令同时定义文件生成路径:可用下面的变量替换.同时必须有同名模板.
81
85
  路径是相对于项目根目录的
@@ -116,6 +120,8 @@ console.log(`
116
120
 
117
121
  modelName: 模块名称,可能为空字符串
118
122
  modelPath: 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
123
+
124
+ logicDelete: 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
119
125
  -----
120
126
  命令 table1,table2,table3:模块名称
121
127
  table=. 表示扫描全库表
@@ -128,7 +134,21 @@ console.log(`
128
134
  try {
129
135
  const outputs = new Set<string>();
130
136
  const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
131
- 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
+ };
132
152
  const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
133
153
  const pool = createPool({
134
154
  host: configData.host,
@@ -139,7 +159,7 @@ try {
139
159
  });
140
160
  async function getTables(tableName: string) {
141
161
  const conn = await pool.getConnection();
142
- const params = [configData.database];
162
+ const params: (string | string[])[] = [configData.database];
143
163
  let sql = `
144
164
  SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
145
165
  WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
@@ -165,12 +185,14 @@ try {
165
185
  COLUMN_COMMENT \`comment\`
166
186
  FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
167
187
  `, [configData.database, tableName]);
188
+ let logicDelete = '';
168
189
  const columns = result.map(r => {
169
190
  if (r.id === 1) { r.id = true; }
170
191
  else delete r.id;
171
192
  if (r.notNull === 1) { r.notNull = true; }
172
193
  else delete r.notNull;
173
- r.comment = `* ${r.comment ?? ''}(\`${tableName}.${r.name}\`)`;
194
+
195
+
174
196
  const fields = new Array<string>(`type:SqlType.${r.type}`);
175
197
  if (r.length !== null) { fields.push(`length:${r.length}`); }
176
198
  if (r.scale !== null) { fields.push(`scale:${r.scale}`); }
@@ -189,6 +211,12 @@ try {
189
211
  if (r.id === true && configData.id) {
190
212
  fields.push(configData.id);
191
213
  }
214
+ if (r.name === configData.logicDeleteK) {
215
+ fields.push(`logicDelete: ${configData.logicDeleteV}`);
216
+ logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
217
+ }
218
+ if (r.comment) { fields.push(`comment: '${r.comment}'`); }
219
+ r.comment = r.comment ?? '';
192
220
  r.Type = lxMap[r.type];
193
221
  r.Field = `@Field({${fields.join(',')}})`;
194
222
  r.Name = r.name.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
@@ -196,7 +224,7 @@ try {
196
224
  return r;
197
225
  });
198
226
  conn.release();
199
- return columns;
227
+ return { columns, logicDelete };
200
228
  }
201
229
  async function excute(command: string, input: string, modelName: string) {
202
230
  const tables = await getTables(input);
@@ -210,7 +238,7 @@ try {
210
238
  modelName ??= '';
211
239
  const modelPath = modelName ? `/${modelName}/` : '';
212
240
  for (const { tableName, title } of tables) {
213
- const columns = await getColumns(tableName);
241
+ const { columns, logicDelete } = await getColumns(tableName);
214
242
  const className = tableName.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
215
243
  const ClassName = className.replace(/\w/, (v: string) => v.toUpperCase());
216
244
  const vueName = tableName.replace(/_/g, '-');
@@ -245,7 +273,9 @@ try {
245
273
  IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
246
274
 
247
275
  modelName,
248
- modelPath
276
+ modelPath,
277
+
278
+ logicDelete
249
279
  };
250
280
  const template = templates[command];
251
281
  if (!template) {
@@ -253,15 +283,16 @@ try {
253
283
  return;
254
284
  }
255
285
  const txt = mustache.render(template, data, {}, ['<%', '%>']);
256
- const fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]);
286
+ const fileName = configData.command[command]!.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]);
257
287
  const filePath = path.join(basepath, fileName);
258
288
  const dirname = path.dirname(filePath);
259
- try {
260
- fs.statSync(dirname);
261
- } catch (error) {
262
- fs.mkdirSync(dirname);
263
- console.info(`[生成] ${dirname}`);
264
- }
289
+ mkdir('-p', dirname);
290
+ // try {
291
+ // fs.statSync(dirname);
292
+ // } catch (error) {
293
+ // fs.mkdirSync(dirname);
294
+ // console.info(`[生成] ${dirname}`);
295
+ // }
265
296
  try {
266
297
  fs.statSync(filePath);
267
298
  if (force === false) {
@@ -1,3 +1,4 @@
1
+ import LGet from 'lodash.get';
1
2
  export interface XML {
2
3
  type: 'tag' | 'text';
3
4
  name: string;
@@ -14,11 +15,9 @@ export const convert = function (childrens: XML[], param: Record<string, any>, p
14
15
  statement += convertChildren(children, param, parentIds, myBatisMapper);
15
16
  }
16
17
  // Check not converted Parameters
17
- var regexList = ['\\#{\\S*}', '\\${\\S*}'];
18
- for (var i = 0, regexString: string; regexString = regexList[i]!; i++) {
19
- var regex = new RegExp(regex, 'g');
18
+ const regexList = ['\\#{\\S*}', '\\${\\S*}'];
19
+ for (let i = 0, regexString: string; regexString = regexList[i]!; i++) {
20
20
  var checkParam = statement.match(regexString);
21
-
22
21
  if (checkParam != null && checkParam.length > 0) {
23
22
  throw new Error("Parameter " + checkParam.join(",") + " is not converted.");
24
23
  }
@@ -102,8 +101,7 @@ const convertParametersInner = function (change: string, convertString: string,
102
101
  for (let i = 0; i < _stringTarget.length; i++) {
103
102
  target = _stringTarget[i];
104
103
  const t = target!.replace(change + '{', '').replace('}', '');
105
- let tempParamKey = eval('param.' + t);
106
-
104
+ let tempParamKey = LGet(param, t);
107
105
  if (tempParamKey !== undefined) {
108
106
  const reg = new RegExp('\\' + change + '{' + t + '}', 'g');
109
107
 
package/src/enum.ts CHANGED
@@ -1,8 +1,10 @@
1
+ import { _enums } from "./sql";
2
+
1
3
  export class Enum {
2
4
  private _value: string;
3
5
  private _desc: string;
4
6
  private _config: string[];
5
- constructor (value: string, desc: string, ...config: string[]) {
7
+ constructor(value: string, desc: string, ...config: string[]) {
6
8
  this._value = value;
7
9
  this._desc = desc;
8
10
  this._config = config;
@@ -15,9 +17,9 @@ export class Enum {
15
17
  return false;
16
18
  }
17
19
  if (typeof value === 'number') {
18
- return this._value === `${ value }`;
20
+ return this._value === `${value}`;
19
21
  }
20
- return this._value === `${ value }`;
22
+ return this._value === `${value}`;
21
23
  }
22
24
  value(): string {
23
25
  return this._value;
@@ -29,3 +31,41 @@ export class Enum {
29
31
  return this._config;
30
32
  }
31
33
  }
34
+ export type EnumMap = Record<string, Enum>;
35
+ export type GlobalArray = Record<string, Array<[string, string]>>;
36
+ export type GlobalMap = Record<string, Record<string, string>>;
37
+ export interface EnmuJson {
38
+ GlobalArray: GlobalArray;
39
+ GlobalMap: GlobalMap;
40
+ }
41
+ let configData: EnmuJson | null = null;
42
+ export const getEnums = (GlobalValues?: EnumMap): EnmuJson => {
43
+ if (!GlobalValues) {
44
+ return globalThis[_enums];
45
+ }
46
+ if (configData) {
47
+ return configData;
48
+ }
49
+ const result: EnmuJson = {
50
+ GlobalArray: {},
51
+ GlobalMap: {}
52
+ };
53
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
54
+ Object.keys(GlobalValues).forEach((item) => {
55
+ // const guess = /([\w\W]+)_([^_]+)$/.exec(item);
56
+ const guess = item.replace(new RegExp(`_${GlobalValues[item]!.value()}`, 'i'), '');
57
+ if (guess) {
58
+ if (!result.GlobalArray[guess]) {
59
+ result.GlobalArray[guess] = [];
60
+ }
61
+ result.GlobalArray[guess]!.push([GlobalValues[item]!.value(), GlobalValues[item]!.desc()]);
62
+
63
+ if (!result.GlobalMap[guess]) {
64
+ result.GlobalMap[guess] = {};
65
+ }
66
+ result.GlobalMap[guess]![GlobalValues[item]!.value()] = GlobalValues[item]!.desc();
67
+ }
68
+ });
69
+ configData = result;
70
+ return result;
71
+ };