baja-lite 1.3.25 → 1.3.27
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/.vscode/settings.json +8 -0
- package/ci.js +29 -0
- package/package-cjs.json +17 -0
- package/package.json +2 -2
- package/{boot-remote.js → src/boot-remote.ts} +7 -6
- package/{boot.js → src/boot.ts} +38 -31
- package/{code.js → src/code.ts} +66 -71
- 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} +12 -11
- package/{list.js → src/list.ts} +9 -8
- package/src/math.ts +405 -0
- package/src/object.ts +247 -0
- package/{snowflake.js → src/snowflake.ts} +52 -33
- package/src/sql.ts +5023 -0
- package/{sqlite.js → src/sqlite.ts} +52 -53
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +144 -0
- package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
- package/{test-xml.js → src/test-xml.ts} +1 -1
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +76 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +10 -21
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1757 -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 -221
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -1788
- package/sql.js +0 -4765
- 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-mysql.js +0 -109
- package/test-postgresql.d.ts +0 -2
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -52
- package/wx/mini.js +0 -112
- 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/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// https://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy
|
|
3
|
+
// This option interrupts the configuration hierarchy at this file
|
|
4
|
+
// Remove this if you have an higher level ESLint config file (it usually happens into a monorepos)
|
|
5
|
+
root: true,
|
|
6
|
+
|
|
7
|
+
// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
|
|
8
|
+
// Must use parserOptions instead of "parser" to allow vue-eslint-parser to keep working
|
|
9
|
+
// `parser: 'vue-eslint-parser'` is already included with any 'plugin:vue/**' config and should be omitted
|
|
10
|
+
parserOptions: {
|
|
11
|
+
parser: require.resolve('@typescript-eslint/parser'),
|
|
12
|
+
extraFileExtensions: [ '.vue' ]
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
env: {
|
|
16
|
+
browser: true,
|
|
17
|
+
es2021: true,
|
|
18
|
+
node: true
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// Rules order is important, please avoid shuffling them
|
|
22
|
+
extends: [
|
|
23
|
+
// Base ESLint recommended rules
|
|
24
|
+
// 'eslint:recommended',
|
|
25
|
+
|
|
26
|
+
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage
|
|
27
|
+
// ESLint typescript rules
|
|
28
|
+
'plugin:@typescript-eslint/recommended',
|
|
29
|
+
|
|
30
|
+
// Uncomment any of the lines below to choose desired strictness,
|
|
31
|
+
// but leave only one uncommented!
|
|
32
|
+
// See https://eslint.vuejs.org/rules/#available-rules
|
|
33
|
+
'plugin:vue/vue3-essential', // Priority A: Essential (Error Prevention)
|
|
34
|
+
// 'plugin:vue/vue3-strongly-recommended', // Priority B: Strongly Recommended (Improving Readability)
|
|
35
|
+
// 'plugin:vue/vue3-recommended', // Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead)
|
|
36
|
+
|
|
37
|
+
// https://github.com/prettier/eslint-config-prettier#installation
|
|
38
|
+
// usage with Prettier, provided by 'eslint-config-prettier'.
|
|
39
|
+
'prettier'
|
|
40
|
+
],
|
|
41
|
+
|
|
42
|
+
plugins: [
|
|
43
|
+
// required to apply rules which need type information
|
|
44
|
+
'@typescript-eslint',
|
|
45
|
+
|
|
46
|
+
// https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-files
|
|
47
|
+
// required to lint *.vue files
|
|
48
|
+
'vue'
|
|
49
|
+
|
|
50
|
+
// https://github.com/typescript-eslint/typescript-eslint/issues/389#issuecomment-509292674
|
|
51
|
+
// Prettier has not been included as plugin to avoid performance impact
|
|
52
|
+
// add it as an extension for your IDE
|
|
53
|
+
|
|
54
|
+
],
|
|
55
|
+
|
|
56
|
+
globals: {
|
|
57
|
+
ga: 'readonly', // Google Analytics
|
|
58
|
+
cordova: 'readonly',
|
|
59
|
+
__statics: 'readonly',
|
|
60
|
+
__QUASAR_SSR__: 'readonly',
|
|
61
|
+
__QUASAR_SSR_SERVER__: 'readonly',
|
|
62
|
+
__QUASAR_SSR_CLIENT__: 'readonly',
|
|
63
|
+
__QUASAR_SSR_PWA__: 'readonly',
|
|
64
|
+
process: 'readonly',
|
|
65
|
+
Capacitor: 'readonly',
|
|
66
|
+
chrome: 'readonly'
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// add your custom rules here
|
|
70
|
+
rules: {
|
|
71
|
+
|
|
72
|
+
'prefer-promise-reject-errors': 'off',
|
|
73
|
+
|
|
74
|
+
quotes: ['warn', 'single', { avoidEscape: true }],
|
|
75
|
+
|
|
76
|
+
// this rule, if on, would require explicit return type on the `render` function
|
|
77
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
78
|
+
|
|
79
|
+
// in plain CommonJS modules, you can't use `import foo = require('foo')` to pass this rule, so it has to be disabled
|
|
80
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
81
|
+
|
|
82
|
+
// The core 'no-unused-vars' rules (in the eslint:recommended ruleset)
|
|
83
|
+
// does not work with type definitions
|
|
84
|
+
'no-unused-vars': 'off',
|
|
85
|
+
|
|
86
|
+
// allow debugger during development only
|
|
87
|
+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
|
|
88
|
+
}
|
|
89
|
+
}
|
package/.prettierrc
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 控制相关文件嵌套展示
|
|
3
|
+
"explorer.fileNesting.enabled": true,
|
|
4
|
+
"explorer.fileNesting.expand": false,
|
|
5
|
+
"explorer.fileNesting.patterns": {
|
|
6
|
+
"package.json": "nest-cli.json,.eslintrc.cjs,.eslintignore,eslint.config.js,package-cjs.json,bun.lockb,baja.code.json,.prettierrc,.eslintrc.js,$(capture).env.*,,pnpm-lock.yaml,pnpm-workspace.yaml,LICENSE,.gitattributes,.gitignore,.gitpod.yml,CNAME,README*,.npmrc,.browserslistrc,yarn.lock,verify-commit.mjs,tsconfig.json,nuxt.config.ts,uno.config.ts",
|
|
7
|
+
}
|
|
8
|
+
}
|
package/ci.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// import { rm, exec, cp } from 'shelljs';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import pkg from 'shelljs';
|
|
4
|
+
import cjs from './package-cjs.json' with { type: "json" };
|
|
5
|
+
import def from './package.json' with { type: "json" };
|
|
6
|
+
const { rm, exec, cp } = pkg;
|
|
7
|
+
|
|
8
|
+
rm('-rf', './dist/');
|
|
9
|
+
rm('-rf', './tsconfig.tsbuildinfo');
|
|
10
|
+
exec('yarn tsc');
|
|
11
|
+
rm('-rf', './tsconfig.tsbuildinfo');
|
|
12
|
+
cp('./package.json', './dist/package.json');
|
|
13
|
+
cp('./README.md', './dist/README.md');
|
|
14
|
+
cp('./LICENSE', './dist/LICENSE');
|
|
15
|
+
rm('-rf', './dist/tsconfig.tsbuildinfo');
|
|
16
|
+
|
|
17
|
+
rm('-rf', './dist-cjs/');
|
|
18
|
+
rm('-rf', './tsconfig.cjs.tsbuildinfo');
|
|
19
|
+
exec('yarn tsc -p tsconfig.cjs.json');
|
|
20
|
+
rm('-rf', './tsconfig.cjs.tsbuildinfo');
|
|
21
|
+
fs.writeFileSync('./dist-cjs/package.json', JSON.stringify(Object.assign(def, cjs), null, 2));
|
|
22
|
+
cp('./README.md', './dist-cjs/README.md');
|
|
23
|
+
cp('./LICENSE', './dist-cjs/LICENSE');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
cp('-R', './dist/*', 'E:\\pro\\v\\apps-services\\fast-start\\node_modules\\baja-lite');
|
|
27
|
+
cp('-R', './dist/*', 'E:\\pro\\v\\apps-services\\attack-service\\node_modules\\baja-lite');
|
|
28
|
+
cp('-R', './dist/*', 'E:\\pro\\v\\apps-services\\attack-front\\node_modules\\baja-lite');
|
|
29
|
+
console.log('cp over');
|
package/package-cjs.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "baja-lite-cjs",
|
|
3
|
+
"type": "commonjs",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": {
|
|
6
|
+
"require": "./index.js"
|
|
7
|
+
},
|
|
8
|
+
"./boot.js":"./boot.js",
|
|
9
|
+
"./boot-remote.js":"./boot-remote.js",
|
|
10
|
+
"./wx.js": "./wx.js"
|
|
11
|
+
},
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"baja": "./code.js"
|
|
15
|
+
},
|
|
16
|
+
"main": "./index.js"
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baja-lite",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.27",
|
|
4
4
|
"description": "some util for self",
|
|
5
5
|
"homepage": "https://github.com/void-soul/util-man",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@msgpack/msgpack": "3.1.1",
|
|
39
39
|
"@types/request-promise": "4.1.51",
|
|
40
40
|
"axios": "1.8.4",
|
|
41
|
-
"baja-lite-field": "1.3.
|
|
41
|
+
"baja-lite-field": "1.3.27",
|
|
42
42
|
"decimal.js": "10.5.0",
|
|
43
43
|
"html-parse-stringify": "3.0.1",
|
|
44
44
|
"iterare": "1.2.1",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DBType, _Hump } from 'baja-lite-field';
|
|
2
2
|
import { getEnums } from './enum.js';
|
|
3
|
-
import { ColumnMode, SqlCache, SqliteRemote, _GlobalSqlOption, _dao, _defOption, _enums, _primaryDB, _sqlCache, logger } from './sql.js';
|
|
4
|
-
|
|
3
|
+
import { ColumnMode, GlobalSqlOptionForWeb, SqlCache, SqliteRemote, _GlobalSqlOption, _dao, _defOption, _enums, _primaryDB, _sqlCache, logger } from './sql.js';
|
|
4
|
+
|
|
5
|
+
export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
|
|
5
6
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
|
|
6
7
|
globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
|
|
7
8
|
logger.level = options.log ?? 'info';
|
|
@@ -19,8 +20,7 @@ export const BootRomote = async function (options) {
|
|
|
19
20
|
if (typeof options.SqliteRemote.db === 'string') {
|
|
20
21
|
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
21
22
|
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
23
|
+
} else {
|
|
24
24
|
let flag = false;
|
|
25
25
|
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
26
26
|
await options.SqliteRemote.service.initDB(fileName);
|
|
@@ -33,7 +33,8 @@ export const BootRomote = async function (options) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
|
37
38
|
// export const AppendRomote = async function (dbName: string) {
|
|
38
39
|
// if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
|
|
39
40
|
// globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
@@ -43,4 +44,4 @@ export const BootRomote = async function (options) {
|
|
|
43
44
|
// }
|
|
44
45
|
// globalThis[_dao][DBType.SqliteRemote][dbName] = db;
|
|
45
46
|
// }
|
|
46
|
-
// }
|
|
47
|
+
// }
|
package/{boot.js → src/boot.ts}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { _Hump, DBType } from 'baja-lite-field';
|
|
2
2
|
import { getEnums } from './enum.js';
|
|
3
|
-
import { _dao, _defOption, _enums, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
4
|
-
|
|
3
|
+
import { _dao, _defOption, _enums, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, GlobalSqlOption, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
4
|
+
|
|
5
|
+
export const Boot = async function (options: GlobalSqlOption) {
|
|
5
6
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
|
|
6
7
|
globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
|
|
7
8
|
if (options.sqlDir) {
|
|
@@ -33,8 +34,8 @@ export const Boot = async function (options) {
|
|
|
33
34
|
decimalNumbers: true,
|
|
34
35
|
supportBigNumbers: true
|
|
35
36
|
}));
|
|
36
|
-
|
|
37
|
-
else {
|
|
37
|
+
|
|
38
|
+
} else {
|
|
38
39
|
let flag = false;
|
|
39
40
|
for (const [key, option] of Object.entries(options.Mysql)) {
|
|
40
41
|
const db = new Mysql(createPool({
|
|
@@ -43,6 +44,7 @@ export const Boot = async function (options) {
|
|
|
43
44
|
decimalNumbers: true,
|
|
44
45
|
supportBigNumbers: true
|
|
45
46
|
}));
|
|
47
|
+
|
|
46
48
|
if (flag === false) {
|
|
47
49
|
globalThis[_dao][DBType.Mysql][_primaryDB] = db;
|
|
48
50
|
flag = true;
|
|
@@ -54,8 +56,7 @@ export const Boot = async function (options) {
|
|
|
54
56
|
if (options.Sqlite) {
|
|
55
57
|
if (typeof options.Sqlite === 'string') {
|
|
56
58
|
globalThis[_dao][DBType.Sqlite][_primaryDB] = new Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
+
} else {
|
|
59
60
|
let flag = false;
|
|
60
61
|
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
61
62
|
const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
@@ -71,8 +72,7 @@ export const Boot = async function (options) {
|
|
|
71
72
|
if (typeof options.SqliteRemote.db === 'string') {
|
|
72
73
|
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
73
74
|
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
75
|
+
} else {
|
|
76
76
|
let flag = false;
|
|
77
77
|
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
78
78
|
options.SqliteRemote.service.initDB(fileName);
|
|
@@ -89,8 +89,7 @@ export const Boot = async function (options) {
|
|
|
89
89
|
const { Redis } = await import('ioredis');
|
|
90
90
|
if (options.Redis['host']) {
|
|
91
91
|
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
92
|
+
} else {
|
|
94
93
|
let flag = false;
|
|
95
94
|
for (const [key, option] of Object.entries(options.Redis)) {
|
|
96
95
|
const db = new Redis(option);
|
|
@@ -101,25 +100,32 @@ export const Boot = async function (options) {
|
|
|
101
100
|
globalThis[_dao][DBType.Redis][key] = db;
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
const clients = Object.values(globalThis[_dao][DBType.Redis]);
|
|
103
|
+
const clients = Object.values(globalThis[_dao][DBType.Redis]) as any;
|
|
105
104
|
const Redlock = await import('redlock');
|
|
106
|
-
globalThis[_dao][DBType.RedisLock] = new Redlock.default(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
globalThis[_dao][DBType.RedisLock] = new Redlock.default(
|
|
106
|
+
clients,
|
|
107
|
+
{
|
|
108
|
+
// The expected clock drift; for more details see:
|
|
109
|
+
// http://redis.io/topics/distlock
|
|
110
|
+
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
111
|
+
|
|
112
|
+
// The max number of times Redlock will attempt to lock a resource
|
|
113
|
+
// before erroring.
|
|
114
|
+
retryCount: 10,
|
|
115
|
+
|
|
116
|
+
// the time in ms between attempts
|
|
117
|
+
retryDelay: 200, // time in ms
|
|
118
|
+
|
|
119
|
+
// the max time in ms randomly added to retries
|
|
120
|
+
// to improve performance under high contention
|
|
121
|
+
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
122
|
+
retryJitter: 200, // time in ms
|
|
123
|
+
|
|
124
|
+
// The minimum remaining time on a lock before an extension is automatically
|
|
125
|
+
// attempted with the `using` API.
|
|
126
|
+
automaticExtensionThreshold: 500, // time in ms
|
|
127
|
+
}
|
|
128
|
+
);
|
|
123
129
|
const { EventEmitter } = await import('events');
|
|
124
130
|
const event = new EventEmitter({ captureRejections: true });
|
|
125
131
|
event.on('error', error => {
|
|
@@ -131,11 +137,12 @@ export const Boot = async function (options) {
|
|
|
131
137
|
const Pool = await import('pg-pool');
|
|
132
138
|
if (options.Postgresql['host']) {
|
|
133
139
|
globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
|
|
134
|
-
|
|
135
|
-
else {
|
|
140
|
+
|
|
141
|
+
} else {
|
|
136
142
|
let flag = false;
|
|
137
143
|
for (const [key, option] of Object.entries(options.Postgresql)) {
|
|
138
144
|
const db = new Postgresql(new Pool.default(option));
|
|
145
|
+
|
|
139
146
|
if (flag === false) {
|
|
140
147
|
globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
|
|
141
148
|
flag = true;
|
|
@@ -144,4 +151,4 @@ export const Boot = async function (options) {
|
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
|
-
}
|
|
154
|
+
}
|
package/{code.js → src/code.ts}
RENAMED
|
@@ -132,10 +132,25 @@ console.log(`
|
|
|
132
132
|
-----
|
|
133
133
|
force: 切换是否覆盖
|
|
134
134
|
`);
|
|
135
|
+
|
|
135
136
|
try {
|
|
136
|
-
const outputs = new Set();
|
|
137
|
+
const outputs = new Set<string>();
|
|
137
138
|
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
138
|
-
const configData = JSON.parse(_configData)
|
|
139
|
+
const configData = JSON.parse(_configData) as {
|
|
140
|
+
host: string;
|
|
141
|
+
port: number;
|
|
142
|
+
user: string;
|
|
143
|
+
password: string;
|
|
144
|
+
database: string;
|
|
145
|
+
command: Record<string, string>;
|
|
146
|
+
commands: Record<string, string[]>;
|
|
147
|
+
output: string;
|
|
148
|
+
id: string;
|
|
149
|
+
logicDeleteK: string;
|
|
150
|
+
logicDeleteV: number;
|
|
151
|
+
NotlogicDeleteV: number;
|
|
152
|
+
tables: string;
|
|
153
|
+
};
|
|
139
154
|
const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
|
|
140
155
|
const pool = createPool({
|
|
141
156
|
host: configData.host,
|
|
@@ -144,9 +159,9 @@ try {
|
|
|
144
159
|
password: configData.password,
|
|
145
160
|
database: configData.database
|
|
146
161
|
});
|
|
147
|
-
async function getTables(tableName) {
|
|
162
|
+
async function getTables(tableName: string) {
|
|
148
163
|
const conn = await pool.getConnection();
|
|
149
|
-
const params = [configData.database];
|
|
164
|
+
const params: (string | string[])[] = [configData.database];
|
|
150
165
|
let sql = `
|
|
151
166
|
SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
|
|
152
167
|
WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
|
|
@@ -154,13 +169,13 @@ try {
|
|
|
154
169
|
sql += ` AND TABLE_NAME IN (?)`;
|
|
155
170
|
params.push(tableName.split(/,|\s/).map(r => r.trim()));
|
|
156
171
|
}
|
|
157
|
-
const [result] = await conn.query(sql, params);
|
|
172
|
+
const [result] = await conn.query<any[]>(sql, params);
|
|
158
173
|
conn.release();
|
|
159
174
|
return result;
|
|
160
175
|
}
|
|
161
|
-
async function getColumns(tableName) {
|
|
176
|
+
async function getColumns(tableName: string) {
|
|
162
177
|
const conn = await pool.getConnection();
|
|
163
|
-
const [result] = await conn.query(`
|
|
178
|
+
const [result] = await conn.query<any[]>(`
|
|
164
179
|
SELECT
|
|
165
180
|
DATA_TYPE type,
|
|
166
181
|
COLUMN_NAME \`name\`,
|
|
@@ -174,31 +189,20 @@ try {
|
|
|
174
189
|
`, [configData.database, tableName]);
|
|
175
190
|
let logicDelete = '';
|
|
176
191
|
const columns = result.map(r => {
|
|
177
|
-
if (r.id === 1) {
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
else
|
|
181
|
-
|
|
182
|
-
if (r.notNull === 1) {
|
|
183
|
-
r.notNull = true;
|
|
184
|
-
}
|
|
185
|
-
else
|
|
186
|
-
delete r.notNull;
|
|
187
|
-
const fields = new Array(`type:SqlType.${r.type}`);
|
|
192
|
+
if (r.id === 1) { r.id = true; }
|
|
193
|
+
else delete r.id;
|
|
194
|
+
if (r.notNull === 1) { r.notNull = true; }
|
|
195
|
+
else delete r.notNull;
|
|
196
|
+
const fields = new Array<string>(`type:SqlType.${r.type}`);
|
|
188
197
|
r.Type = lxMap[r.type];
|
|
189
|
-
if (r.length !== null) {
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
if (r.scale !== null) {
|
|
193
|
-
fields.push(`scale:${r.scale}`);
|
|
194
|
-
}
|
|
198
|
+
if (r.length !== null) { fields.push(`length:${r.length}`); }
|
|
199
|
+
if (r.scale !== null) { fields.push(`scale:${r.scale}`); }
|
|
195
200
|
if (r.def !== null) {
|
|
196
|
-
r.def
|
|
201
|
+
r.def ??= '';
|
|
197
202
|
if (r.def !== '') {
|
|
198
203
|
if (isNaN(r.def)) {
|
|
199
204
|
fields.push(`def:'${r.def}'`);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
205
|
+
} else {
|
|
202
206
|
fields.push(`def:${r.def}`);
|
|
203
207
|
}
|
|
204
208
|
}
|
|
@@ -206,26 +210,20 @@ try {
|
|
|
206
210
|
if (r.Type === 'string') {
|
|
207
211
|
if (r.def === '' || r.def === null) {
|
|
208
212
|
r.def = "''";
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
213
|
+
} else {
|
|
211
214
|
r.def = `'${r.def}'`;
|
|
212
215
|
}
|
|
213
|
-
}
|
|
214
|
-
else if (r.Type === 'number') {
|
|
216
|
+
} else if (r.Type === 'number') {
|
|
215
217
|
r.def = 0;
|
|
216
|
-
}
|
|
217
|
-
else if (r.Type === 'Date') {
|
|
218
|
+
} else if (r.Type === 'Date') {
|
|
218
219
|
r.def = 'new Date()';
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
220
|
+
} else {
|
|
221
221
|
r.def = 'null';
|
|
222
222
|
}
|
|
223
223
|
if (r.id === true) {
|
|
224
224
|
fields.push(`id:true`);
|
|
225
225
|
}
|
|
226
|
-
if (r.notNull === true) {
|
|
227
|
-
fields.push(`notNull:true`);
|
|
228
|
-
}
|
|
226
|
+
if (r.notNull === true) { fields.push(`notNull:true`); }
|
|
229
227
|
if (r.id === true && configData.id) {
|
|
230
228
|
fields.push(configData.id);
|
|
231
229
|
}
|
|
@@ -233,40 +231,40 @@ try {
|
|
|
233
231
|
fields.push(`logicDelete: ${configData.logicDeleteV}`);
|
|
234
232
|
logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
|
|
235
233
|
}
|
|
236
|
-
if (r.comment) {
|
|
237
|
-
fields.push(`comment: '${r.comment}'`);
|
|
238
|
-
}
|
|
234
|
+
if (r.comment) { fields.push(`comment: '${r.comment}'`); }
|
|
239
235
|
r.comment = r.comment ?? '';
|
|
236
|
+
|
|
240
237
|
r.Field = `@Field({${fields.join(',')}})`;
|
|
241
|
-
r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
242
|
-
r.NAME = r.Name.replace(/\w/, (v) => v.toUpperCase());
|
|
238
|
+
r.Name = r.name.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
239
|
+
r.NAME = r.Name.replace(/\w/, (v: string) => v.toUpperCase());
|
|
243
240
|
return r;
|
|
244
241
|
});
|
|
245
242
|
conn.release();
|
|
246
243
|
return { columns, logicDelete };
|
|
247
244
|
}
|
|
248
|
-
async function excute(command, input, modelName) {
|
|
245
|
+
async function excute(command: string, input: string, modelName: string) {
|
|
249
246
|
const tables = await getTables(input);
|
|
250
247
|
if (input !== '.') {
|
|
251
|
-
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
248
|
+
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
252
249
|
if (checkTable.length !== tables.length) {
|
|
253
250
|
console.error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
|
|
254
251
|
return;
|
|
255
252
|
}
|
|
256
253
|
}
|
|
257
|
-
modelName
|
|
254
|
+
modelName ??= '';
|
|
258
255
|
const modelPath = modelName ? `/${modelName}/` : '';
|
|
259
256
|
for (const { tableName, title } of tables) {
|
|
260
257
|
const { columns, logicDelete } = await getColumns(tableName);
|
|
261
|
-
const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
262
|
-
const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
|
|
258
|
+
const className = tableName.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
259
|
+
const ClassName = className.replace(/\w/, (v: string) => v.toUpperCase());
|
|
263
260
|
const vueName = tableName.replace(/_/g, '-');
|
|
264
261
|
const splitVueName = tableName.replace(/_/, '/').replace(/_/g, '-');
|
|
265
262
|
const modelName = tableName.substring(0, tableName.indexOf('_'));
|
|
266
263
|
const splitName = tableName.replace(/_/g, '/');
|
|
267
|
-
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
264
|
+
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
268
265
|
const data = {
|
|
269
266
|
title,
|
|
267
|
+
|
|
270
268
|
tableName,
|
|
271
269
|
className,
|
|
272
270
|
ClassName,
|
|
@@ -274,6 +272,7 @@ try {
|
|
|
274
272
|
splitVueName,
|
|
275
273
|
splitName,
|
|
276
274
|
SplitName,
|
|
275
|
+
|
|
277
276
|
columns,
|
|
278
277
|
columnNames: columns?.map(i => i.name),
|
|
279
278
|
ColumnNames: columns?.map(i => i.Name),
|
|
@@ -286,13 +285,16 @@ try {
|
|
|
286
285
|
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
|
287
286
|
columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
|
|
288
287
|
ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
|
|
288
|
+
|
|
289
289
|
ids: columns?.filter(i => i.id),
|
|
290
290
|
idNames: columns?.filter(i => i.id).map(i => i.name),
|
|
291
291
|
IdNames: columns?.filter(i => i.id).map(i => i.Name),
|
|
292
292
|
idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
|
|
293
293
|
IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
|
|
294
|
+
|
|
294
295
|
modelName,
|
|
295
296
|
modelPath,
|
|
297
|
+
|
|
296
298
|
logicDelete
|
|
297
299
|
};
|
|
298
300
|
const template = templates[command];
|
|
@@ -301,7 +303,7 @@ try {
|
|
|
301
303
|
return;
|
|
302
304
|
}
|
|
303
305
|
const txt = mustache.render(template, data, {}, ['<%', '%>']);
|
|
304
|
-
const _fileName = configData.command[command]
|
|
306
|
+
const _fileName = configData.command[command]!.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]);
|
|
305
307
|
const fileNames = _fileName.split(',');
|
|
306
308
|
for (const fileName of fileNames) {
|
|
307
309
|
const filePath = path.join(basepath, fileName);
|
|
@@ -318,31 +320,28 @@ try {
|
|
|
318
320
|
if (force === false) {
|
|
319
321
|
console.warn(`[跳过] ${filePath}`);
|
|
320
322
|
return;
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
+
} else {
|
|
323
324
|
console.warn(`[覆盖] ${filePath}`);
|
|
324
325
|
}
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
326
|
+
} catch (error) {
|
|
327
327
|
console.info(`[生成] ${filePath}`);
|
|
328
328
|
}
|
|
329
329
|
if (configData.output) {
|
|
330
|
-
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]));
|
|
330
|
+
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]));
|
|
331
331
|
}
|
|
332
332
|
fs.writeFileSync(path.join(basepath, fileName), txt);
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
const replServer = start();
|
|
337
|
-
function defineCommand(command, comands) {
|
|
337
|
+
function defineCommand(command: string, comands?: string[]) {
|
|
338
338
|
if (comands) {
|
|
339
339
|
console.log(`[组合]${command}>${comands.join(',')}注册成功`);
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
340
|
+
} else {
|
|
342
341
|
console.log(`[命令]${command}注册成功`);
|
|
343
342
|
}
|
|
344
343
|
if (comands) {
|
|
345
|
-
replServer.defineCommand(command, async
|
|
344
|
+
replServer.defineCommand(command, async input => {
|
|
346
345
|
outputs.clear();
|
|
347
346
|
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
348
347
|
if (inputs?.length !== 3) {
|
|
@@ -350,21 +349,20 @@ try {
|
|
|
350
349
|
}
|
|
351
350
|
const [_, tables, modelName] = inputs;
|
|
352
351
|
for (const c of comands) {
|
|
353
|
-
await excute(c, tables
|
|
352
|
+
await excute(c, tables!, modelName ?? '');
|
|
354
353
|
}
|
|
355
354
|
console.info('执行完毕!下面打印生成的输出');
|
|
356
355
|
console.info(Array.from(outputs).join(','));
|
|
357
356
|
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
replServer.defineCommand(command, async (input) => {
|
|
357
|
+
} else {
|
|
358
|
+
replServer.defineCommand(command, async input => {
|
|
361
359
|
outputs.clear();
|
|
362
360
|
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
363
361
|
if (inputs?.length !== 3) {
|
|
364
362
|
return console.error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
365
363
|
}
|
|
366
364
|
const [_, tables, modelName] = inputs;
|
|
367
|
-
await excute(command, tables
|
|
365
|
+
await excute(command, tables!, modelName ?? '');
|
|
368
366
|
console.info('执行完毕!下面打印生成的输出');
|
|
369
367
|
console.info(Array.from(outputs).join(','));
|
|
370
368
|
});
|
|
@@ -378,25 +376,22 @@ try {
|
|
|
378
376
|
for (const command of Object.keys(configData.command)) {
|
|
379
377
|
if (!templates[command]) {
|
|
380
378
|
console.error(`命令:${command}没有定义模板,该命令不会生效`);
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
379
|
+
} else {
|
|
383
380
|
defineCommand(command);
|
|
384
381
|
}
|
|
385
382
|
}
|
|
386
383
|
}
|
|
387
384
|
if (configData.commands) {
|
|
388
385
|
for (const [command, commands] of Object.entries(configData.commands)) {
|
|
389
|
-
const keys = commands;
|
|
386
|
+
const keys = commands as string[];
|
|
390
387
|
const error = keys.filter(k => !templates[k]).join(',');
|
|
391
388
|
if (error) {
|
|
392
389
|
console.error(`组合命令:${command}定义了${commands},但是${error}没有定义模板,该命令不会生效`);
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
390
|
+
} else {
|
|
395
391
|
defineCommand(command, keys);
|
|
396
392
|
}
|
|
397
393
|
}
|
|
398
394
|
}
|
|
399
|
-
}
|
|
400
|
-
catch (error) {
|
|
395
|
+
} catch (error) {
|
|
401
396
|
console.error(error);
|
|
402
397
|
}
|