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/cjs/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/cjs/sqlite.js CHANGED
@@ -29,15 +29,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.SqliteRemoteClass = void 0;
30
30
  const sql_1 = require("./sql");
31
31
  const sqlstring_1 = __importDefault(require("sqlstring"));
32
+ const msgpack_1 = require("@msgpack/msgpack");
32
33
  class SqliteRemoteClass {
33
34
  constructor() {
34
35
  this.dbList = {};
35
36
  }
36
- async execute(dbName, sql, params) {
37
+ async execute(inData) {
38
+ const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
39
+ sql_1.logger.debug(sql, params ?? '');
37
40
  try {
38
- sql_1.logger.debug(sql, params ?? '');
39
41
  if (!sql) {
40
- return { affectedRows: 0, insertId: 0n };
42
+ return (0, msgpack_1.encode)({ affectedRows: 0, insertId: 0n });
41
43
  }
42
44
  ;
43
45
  if (this.trace) {
@@ -48,7 +50,7 @@ class SqliteRemoteClass {
48
50
  sql_1.logger.trace(result);
49
51
  }
50
52
  const { changes, lastInsertRowid } = result;
51
- return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
53
+ return (0, msgpack_1.encode)({ affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n });
52
54
  }
53
55
  catch (error) {
54
56
  sql_1.logger.error(`
@@ -59,17 +61,19 @@ class SqliteRemoteClass {
59
61
  throw error;
60
62
  }
61
63
  }
62
- async pluck(dbName, sql, params) {
64
+ async pluck(inData) {
65
+ const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
66
+ sql_1.logger.debug(sql, params ?? '');
63
67
  try {
64
68
  sql_1.logger.debug(sql, params ?? '');
65
69
  if (!sql) {
66
- return null;
70
+ return (0, msgpack_1.encode)(null);
67
71
  }
68
72
  ;
69
73
  if (this.trace) {
70
74
  sql_1.logger.trace(sqlstring_1.default.format(sql, params));
71
75
  }
72
- return this.dbList[dbName].prepare(sql).pluck().get(params ?? {});
76
+ return (0, msgpack_1.encode)(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}));
73
77
  }
74
78
  catch (error) {
75
79
  sql_1.logger.error(`
@@ -80,17 +84,14 @@ class SqliteRemoteClass {
80
84
  throw error;
81
85
  }
82
86
  }
83
- async get(dbName, sql, params) {
87
+ async get(inData) {
88
+ const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
89
+ sql_1.logger.debug(sql, params ?? '');
84
90
  try {
85
- sql_1.logger.debug(sql, params ?? '');
86
- if (!sql) {
87
- return null;
88
- }
89
- ;
90
91
  if (this.trace) {
91
92
  sql_1.logger.trace(sqlstring_1.default.format(sql, params));
92
93
  }
93
- return this.dbList[dbName].prepare(sql).get(params ?? {});
94
+ return (0, msgpack_1.encode)(this.dbList[dbName].prepare(sql).get(params ?? {}));
94
95
  }
95
96
  catch (error) {
96
97
  sql_1.logger.error(`
@@ -101,17 +102,18 @@ class SqliteRemoteClass {
101
102
  throw error;
102
103
  }
103
104
  }
104
- async raw(dbName, sql, params) {
105
+ async raw(inData) {
106
+ const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
107
+ sql_1.logger.debug(sql, params ?? '');
105
108
  try {
106
- sql_1.logger.debug(sql, params ?? '');
107
109
  if (!sql) {
108
- return [];
110
+ return (0, msgpack_1.encode)([]);
109
111
  }
110
112
  ;
111
113
  if (this.trace) {
112
114
  sql_1.logger.trace(sqlstring_1.default.format(sql, params));
113
115
  }
114
- return this.dbList[dbName].prepare(sql).raw().all(params ?? {});
116
+ return (0, msgpack_1.encode)(this.dbList[dbName].prepare(sql).raw().all(params ?? {}));
115
117
  }
116
118
  catch (error) {
117
119
  sql_1.logger.error(`
@@ -122,17 +124,18 @@ class SqliteRemoteClass {
122
124
  throw error;
123
125
  }
124
126
  }
125
- async query(dbName, sql, params) {
127
+ async query(inData) {
128
+ const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
129
+ sql_1.logger.debug(sql, params ?? '');
126
130
  try {
127
- sql_1.logger.debug(sql, params ?? '');
128
131
  if (!sql) {
129
- return [];
132
+ (0, msgpack_1.encode)([]);
130
133
  }
131
134
  ;
132
135
  if (this.trace) {
133
136
  sql_1.logger.trace(sqlstring_1.default.format(sql, params));
134
137
  }
135
- return this.dbList[dbName].prepare(sql).all(params ?? {});
138
+ return (0, msgpack_1.encode)(this.dbList[dbName].prepare(sql).all(params ?? {}));
136
139
  }
137
140
  catch (error) {
138
141
  sql_1.logger.error(`
package/cjs/test-mysql.js CHANGED
@@ -34,6 +34,12 @@ AmaService2 = __decorate([
34
34
  tableName: 'ama_fuck', clz: AmaFuck2, dbType: sql_1.DBType.Mysql
35
35
  })
36
36
  ], AmaService2);
37
+ // interface Menu {
38
+ // resourceid: string;
39
+ // resourcepid: string;
40
+ // resourcename: string;
41
+ // children: Menu[];
42
+ // }
37
43
  async function go2() {
38
44
  await (0, boot_1.Boot)({
39
45
  Mysql: {
@@ -47,7 +53,10 @@ async function go2() {
47
53
  },
48
54
  log: 'info',
49
55
  columnMode: sql_1.ColumnMode.HUMP,
50
- sqlDir: 'E:/pro/baja-lite/xml'
56
+ sqlDir: 'E:/pro/baja-lite/xml',
57
+ sqlMap: {
58
+ ['test.test']: `SELECT * FROM cp_user {{#username}} WHERE username = :username {{/username}}`
59
+ }
51
60
  });
52
61
  const service = new AmaService2();
53
62
  await service.transaction({
@@ -99,13 +108,12 @@ async function go2() {
99
108
  // templateResult: TemplateResult.Many
100
109
  // })
101
110
  // console.log(44, rt4);
102
- // const rt5 = await service.select<string>({
103
- // 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, '%')`,
104
- // params: { sku: 'SellerSKU4' },
105
- // selectResult: SelectResult.Many_Row_One_Column,
106
- // multiple: true
107
- // })
108
- // console.log(55, rt5);
111
+ const rt5 = await service.select({
112
+ sqlId: 'test.test',
113
+ params: { username: '1111' },
114
+ selectResult: sql_1.SelectResult.RS_CS
115
+ });
116
+ console.log(55, rt5.length);
109
117
  // const rt6 = await service.stream().eq('sellerSku', 'SellerSKU1').excuteSelect({
110
118
  // selectResult: SelectResult.Many_Row_Many_Column,
111
119
  // });
@@ -113,18 +121,18 @@ async function go2() {
113
121
  return 1;
114
122
  }
115
123
  });
116
- const data = await service.select({
117
- sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
118
- params: {
119
- site: '1234',
120
- matchInfo: { reportType: 'yyyy', id: '11' }
121
- },
122
- // mapper: [
123
- // ['site', ['info', 'bSist'], 989],
124
- // ['site', ['info2', 'bSist'], 33],
125
- // ['site', ['Bsite'], 0]
126
- // ]
127
- });
128
- console.log(data);
124
+ // const data = await service.select<Menu>({
125
+ // sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
126
+ // params: {
127
+ // site: '1234',
128
+ // matchInfo: { reportType: 'yyyy', id: '11' }
129
+ // },
130
+ // // mapper: [
131
+ // // ['site', ['info', 'bSist'], 989],
132
+ // // ['site', ['info2', 'bSist'], 33],
133
+ // // ['site', ['Bsite'], 0]
134
+ // // ]
135
+ // });
136
+ // console.log(data);
129
137
  }
130
138
  go2();
package/es/boot-remote.js CHANGED
@@ -1,4 +1,5 @@
1
- import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode } from './sql';
1
+ import { getEnums } from './enum';
2
+ import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql';
2
3
  export const BootRomote = async function (options) {
3
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
4
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
@@ -10,6 +11,9 @@ export const BootRomote = async function (options) {
10
11
  globalThis[_dao] = {
11
12
  [DBType.SqliteRemote]: {},
12
13
  };
14
+ if (options.enums) {
15
+ globalThis[_enums] = getEnums(options.enums);
16
+ }
13
17
  if (options.SqliteRemote) {
14
18
  if (typeof options.SqliteRemote.db === 'string') {
15
19
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
package/es/boot.js CHANGED
@@ -1,4 +1,5 @@
1
- import { _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, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode } from './sql';
2
3
  export const Boot = async function (options) {
3
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
4
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
@@ -18,6 +19,9 @@ export const Boot = async function (options) {
18
19
  [DBType.SqliteRemote]: {},
19
20
  [DBType.Redis]: {}
20
21
  };
22
+ if (options.enums) {
23
+ globalThis[_enums] = getEnums(options.enums);
24
+ }
21
25
  if (options.Mysql) {
22
26
  const { createPool } = await import('mysql2/promise');
23
27
  if (options.Mysql['host']) {
package/es/code.js 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
  const lxMap = {
8
9
  tinyint: "number",
9
10
  smallint: "number",
@@ -74,7 +75,10 @@ console.log(`
74
75
  "s": ["entity", "controller", "service", "sql", "module"]
75
76
  },
76
77
  "output": "{ClassName}Module",
77
- "id"? : "uuidShort: true, notNull: true, uuid: true"
78
+ "id"? : "uuidShort: true, notNull: true, uuid: true",
79
+ "logicDeleteK"?: "逻辑删除字段名",
80
+ "logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
81
+ "NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'"
78
82
  }
79
83
  command是生成命令,这里声明命令同时定义文件生成路径:可用下面的变量替换.同时必须有同名模板.
80
84
  路径是相对于项目根目录的
@@ -115,6 +119,8 @@ console.log(`
115
119
 
116
120
  modelName: 模块名称,可能为空字符串
117
121
  modelPath: 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
122
+
123
+ logicDelete: 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
118
124
  -----
119
125
  命令 table1,table2,table3:模块名称
120
126
  table=. 表示扫描全库表
@@ -162,6 +168,7 @@ try {
162
168
  COLUMN_COMMENT \`comment\`
163
169
  FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
164
170
  `, [configData.database, tableName]);
171
+ let logicDelete = '';
165
172
  const columns = result.map(r => {
166
173
  if (r.id === 1) {
167
174
  r.id = true;
@@ -173,7 +180,6 @@ try {
173
180
  }
174
181
  else
175
182
  delete r.notNull;
176
- r.comment = `* ${r.comment ?? ''}(\`${tableName}.${r.name}\`)`;
177
183
  const fields = new Array(`type:SqlType.${r.type}`);
178
184
  if (r.length !== null) {
179
185
  fields.push(`length:${r.length}`);
@@ -199,6 +205,14 @@ try {
199
205
  if (r.id === true && configData.id) {
200
206
  fields.push(configData.id);
201
207
  }
208
+ if (r.name === configData.logicDeleteK) {
209
+ fields.push(`logicDelete: ${configData.logicDeleteV}`);
210
+ logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
211
+ }
212
+ if (r.comment) {
213
+ fields.push(`comment: '${r.comment}'`);
214
+ }
215
+ r.comment = r.comment ?? '';
202
216
  r.Type = lxMap[r.type];
203
217
  r.Field = `@Field({${fields.join(',')}})`;
204
218
  r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
@@ -206,7 +220,7 @@ try {
206
220
  return r;
207
221
  });
208
222
  conn.release();
209
- return columns;
223
+ return { columns, logicDelete };
210
224
  }
211
225
  async function excute(command, input, modelName) {
212
226
  const tables = await getTables(input);
@@ -220,7 +234,7 @@ try {
220
234
  modelName ?? (modelName = '');
221
235
  const modelPath = modelName ? `/${modelName}/` : '';
222
236
  for (const { tableName, title } of tables) {
223
- const columns = await getColumns(tableName);
237
+ const { columns, logicDelete } = await getColumns(tableName);
224
238
  const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
225
239
  const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
226
240
  const vueName = tableName.replace(/_/g, '-');
@@ -250,7 +264,8 @@ try {
250
264
  idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
251
265
  IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
252
266
  modelName,
253
- modelPath
267
+ modelPath,
268
+ logicDelete
254
269
  };
255
270
  const template = templates[command];
256
271
  if (!template) {
@@ -261,13 +276,13 @@ try {
261
276
  const fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]);
262
277
  const filePath = path.join(basepath, fileName);
263
278
  const dirname = path.dirname(filePath);
264
- try {
265
- fs.statSync(dirname);
266
- }
267
- catch (error) {
268
- fs.mkdirSync(dirname);
269
- console.info(`[生成] ${dirname}`);
270
- }
279
+ mkdir('-p', dirname);
280
+ // try {
281
+ // fs.statSync(dirname);
282
+ // } catch (error) {
283
+ // fs.mkdirSync(dirname);
284
+ // console.info(`[生成] ${dirname}`);
285
+ // }
271
286
  try {
272
287
  fs.statSync(filePath);
273
288
  if (force === false) {
package/es/convert-xml.js CHANGED
@@ -1,3 +1,4 @@
1
+ import LGet from 'lodash.get';
1
2
  export const convert = function (childrens, param, parentIds, myBatisMapper) {
2
3
  let statement = '';
3
4
  for (let i = 0, children; children = childrens[i]; i++) {
@@ -5,9 +6,8 @@ export const convert = function (childrens, param, parentIds, myBatisMapper) {
5
6
  statement += convertChildren(children, param, parentIds, myBatisMapper);
6
7
  }
7
8
  // Check not converted Parameters
8
- var regexList = ['\\#{\\S*}', '\\${\\S*}'];
9
- for (var i = 0, regexString; regexString = regexList[i]; i++) {
10
- var regex = new RegExp(regex, 'g');
9
+ const regexList = ['\\#{\\S*}', '\\${\\S*}'];
10
+ for (let i = 0, regexString; regexString = regexList[i]; i++) {
11
11
  var checkParam = statement.match(regexString);
12
12
  if (checkParam != null && checkParam.length > 0) {
13
13
  throw new Error("Parameter " + checkParam.join(",") + " is not converted.");
@@ -86,7 +86,7 @@ const convertParametersInner = function (change, convertString, param) {
86
86
  for (let i = 0; i < _stringTarget.length; i++) {
87
87
  target = _stringTarget[i];
88
88
  const t = target.replace(change + '{', '').replace('}', '');
89
- let tempParamKey = eval('param.' + t);
89
+ let tempParamKey = LGet(param, t);
90
90
  if (tempParamKey !== undefined) {
91
91
  const reg = new RegExp('\\' + change + '{' + t + '}', 'g');
92
92
  if (tempParamKey === null) {
package/es/enum.d.ts CHANGED
@@ -8,3 +8,11 @@ export declare class Enum {
8
8
  desc(): string;
9
9
  config(): string[];
10
10
  }
11
+ export type EnumMap = Record<string, Enum>;
12
+ export type GlobalArray = Record<string, Array<[string, string]>>;
13
+ export type GlobalMap = Record<string, Record<string, string>>;
14
+ export interface EnmuJson {
15
+ GlobalArray: GlobalArray;
16
+ GlobalMap: GlobalMap;
17
+ }
18
+ export declare const getEnums: (GlobalValues?: EnumMap) => EnmuJson;
package/es/enum.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { _enums } from "./sql";
1
2
  export class Enum {
2
3
  constructor(value, desc, ...config) {
3
4
  this._value = value;
@@ -26,3 +27,33 @@ export class Enum {
26
27
  return this._config;
27
28
  }
28
29
  }
30
+ let configData = null;
31
+ export const getEnums = (GlobalValues) => {
32
+ if (!GlobalValues) {
33
+ return globalThis[_enums];
34
+ }
35
+ if (configData) {
36
+ return configData;
37
+ }
38
+ const result = {
39
+ GlobalArray: {},
40
+ GlobalMap: {}
41
+ };
42
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
43
+ Object.keys(GlobalValues).forEach((item) => {
44
+ // const guess = /([\w\W]+)_([^_]+)$/.exec(item);
45
+ const guess = item.replace(new RegExp(`_${GlobalValues[item].value()}`, 'i'), '');
46
+ if (guess) {
47
+ if (!result.GlobalArray[guess]) {
48
+ result.GlobalArray[guess] = [];
49
+ }
50
+ result.GlobalArray[guess].push([GlobalValues[item].value(), GlobalValues[item].desc()]);
51
+ if (!result.GlobalMap[guess]) {
52
+ result.GlobalMap[guess] = {};
53
+ }
54
+ result.GlobalMap[guess][GlobalValues[item].value()] = GlobalValues[item].desc();
55
+ }
56
+ });
57
+ configData = result;
58
+ return result;
59
+ };
package/es/fn.js CHANGED
@@ -85,55 +85,65 @@ export function excuteSplit(sync, datas, fn, { everyLength = 0, groupCount = 0,
85
85
  const list = arraySplit(datas, ps);
86
86
  if (sync === ExcuteSplitMode.AsyncTrust) {
87
87
  return new Promise(async (resolve, reject) => {
88
- const reasons = [];
89
- if (settled) {
90
- const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
91
- for (const item of result) {
92
- if (item.status === 'rejected') {
93
- reject(item.reason);
88
+ try {
89
+ const reasons = [];
90
+ if (settled) {
91
+ const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
92
+ for (const item of result) {
93
+ if (item.status === 'rejected') {
94
+ reject(item.reason);
95
+ }
96
+ else {
97
+ reasons.push(item.value);
98
+ }
94
99
  }
95
- else {
96
- reasons.push(item.value);
100
+ }
101
+ else {
102
+ for (let i = 0; i < list.length; i++) {
103
+ const startIndex = (i - 1) * ps.everyLength;
104
+ const endIndex = startIndex + list[i].length - 1;
105
+ reasons.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
97
106
  }
98
107
  }
108
+ resolve(reasons);
99
109
  }
100
- else {
101
- for (let i = 0; i < list.length; i++) {
102
- const startIndex = (i - 1) * ps.everyLength;
103
- const endIndex = startIndex + list[i].length - 1;
104
- reasons.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
105
- }
110
+ catch (error) {
111
+ reject(error);
106
112
  }
107
- resolve(reasons);
108
113
  });
109
114
  }
110
115
  else if (sync === ExcuteSplitMode.AsyncNoTrust) {
111
116
  return new Promise(async (resolve, reject) => {
112
- const reasons = { result: [], error: [] };
113
- if (settled) {
114
- const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
115
- for (const item of result) {
116
- if (item.status === 'rejected') {
117
- reasons.error.push(item.reason);
118
- }
119
- else {
120
- reasons.result.push(item.value);
117
+ try {
118
+ const reasons = { result: [], error: [] };
119
+ if (settled) {
120
+ const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
121
+ for (const item of result) {
122
+ if (item.status === 'rejected') {
123
+ reasons.error.push(item.reason);
124
+ }
125
+ else {
126
+ reasons.result.push(item.value);
127
+ }
121
128
  }
122
129
  }
123
- }
124
- else {
125
- for (let i = 0; i < list.length; i++) {
126
- const startIndex = (i - 1) * ps.everyLength;
127
- const endIndex = startIndex + list[i].length - 1;
128
- try {
129
- reasons.result.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
130
- }
131
- catch (error) {
132
- reasons.error.push(error);
130
+ else {
131
+ for (let i = 0; i < list.length; i++) {
132
+ const startIndex = (i - 1) * ps.everyLength;
133
+ const endIndex = startIndex + list[i].length - 1;
134
+ try {
135
+ reasons.result.push(await fn(list[i], i, list.length, extendParams[i], startIndex, endIndex));
136
+ }
137
+ catch (error) {
138
+ reasons.error.push(error);
139
+ }
133
140
  }
134
141
  }
142
+ resolve(reasons);
143
+ }
144
+ catch (error) {
145
+ reject(error);
135
146
  }
136
- resolve(reasons);
137
147
  });
138
148
  }
139
149
  else if (sync === ExcuteSplitMode.SyncTrust) {
package/es/list.js CHANGED
@@ -30,3 +30,27 @@ export class ArrayList extends Array {
30
30
  this.splice(index, 1);
31
31
  }
32
32
  }
33
+ // export class ArrayMap<T> extends Array<T> {
34
+ // private _map: Map<string, T> = new Map();
35
+ // private key: keyof T;
36
+ // constructor(key: keyof T, array?: Array<T> | T | undefined) {
37
+ // super();
38
+ // this.key = key;
39
+ // if (array instanceof Array) {
40
+ // super.push(...array);
41
+ // } else if (typeof array !== 'undefined') {
42
+ // super.push(array);
43
+ // }
44
+ // }
45
+ // override push(...items: T[]): number {
46
+ // for (const item of items) {
47
+ // const key = item[this.key] as string;
48
+ // if (!this._map.has(key)) {
49
+ // super.push(item);
50
+ // this._map.set(key, item);
51
+ // }
52
+ // }
53
+ // return this.length;
54
+ // }
55
+ // override
56
+ // }
package/es/math.d.ts CHANGED
@@ -67,3 +67,17 @@ export declare class Bus {
67
67
  }
68
68
  export declare const calc: (result: any) => Bus;
69
69
  export declare const getGeo: (p1: Point, p2: Point) => number;
70
+ /**
71
+ * 十进制转换自定义进制
72
+ * @param from 数字
73
+ * @param to 自定义进制的字符
74
+ * @returns
75
+ */
76
+ export declare function ten2Any(from: number, to?: string): string;
77
+ /**
78
+ * 自定义进制转换十进制
79
+ * @param from
80
+ * @param to
81
+ * @returns
82
+ */
83
+ export declare function any2Ten(from: string, to?: string): number;
package/es/math.js CHANGED
@@ -412,3 +412,40 @@ export const getGeo = (p1, p2) => {
412
412
  p2.long = calc(p2.longitude).mul(Math.PI).div(180).over();
413
413
  return calc(Math.round(mul(Math.asin(Math.sqrt(add(Math.pow(Math.sin(div(sub(p1.lat, p2.lat), 2)), 2), mul(Math.cos(p1.lat), Math.cos(p2.lat), Math.pow(Math.sin(div(sub(p1.long, p2.long), 2)), 2))))), 2, 6378.137, 10000))).div(10000).round(2).over();
414
414
  };
415
+ const ZM = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
416
+ /**
417
+ * 十进制转换自定义进制
418
+ * @param from 数字
419
+ * @param to 自定义进制的字符
420
+ * @returns
421
+ */
422
+ export function ten2Any(from, to = ZM) {
423
+ let result = '';
424
+ const length = to.length;
425
+ while (from > 0) {
426
+ from--;
427
+ let remainder = from % length;
428
+ result = to.charAt(remainder) + result;
429
+ from = Math.floor(from / length);
430
+ }
431
+ return result;
432
+ }
433
+ /**
434
+ * 自定义进制转换十进制
435
+ * @param from
436
+ * @param to
437
+ * @returns
438
+ */
439
+ export function any2Ten(from, to = ZM) {
440
+ let decimal = 0;
441
+ from = from.toUpperCase();
442
+ for (let i = 0; i < from.length; i++) {
443
+ const char = from[from.length - 1 - i].toUpperCase();
444
+ const index = to.indexOf(char);
445
+ if (index > -1) {
446
+ const value = to.indexOf(char) + 1;
447
+ decimal += value * Math.pow(26, i);
448
+ }
449
+ }
450
+ return decimal;
451
+ }