baja-lite 1.2.2 → 1.3.1

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/boot-remote.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { DBType, _Hump } from 'baja-lite-field';
1
2
  import { getEnums } from './enum.js';
2
- import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql.js';
3
+ import { ColumnMode, SqlCache, SqliteRemote, _GlobalSqlOption, _dao, _defOption, _enums, _primaryDB, _sqlCache, logger } from './sql.js';
3
4
  export const BootRomote = async function (options) {
4
5
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
5
6
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
package/boot.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { _Hump, DBType } from 'baja-lite-field';
1
2
  import { getEnums } from './enum.js';
2
- import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql.js';
3
+ import { _dao, _defOption, _enums, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
3
4
  export const Boot = async function (options) {
4
5
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
5
6
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
package/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export * from './snowflake.js';
10
10
  export * from './sql.js';
11
11
  export * from './sqlite.js';
12
12
  export * from './string.js';
13
+ export * from './validate.js';
package/index.js CHANGED
@@ -10,3 +10,4 @@ export * from './snowflake.js';
10
10
  export * from './sql.js';
11
11
  export * from './sqlite.js';
12
12
  export * from './string.js';
13
+ export * from './validate.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
@@ -23,7 +23,6 @@
23
23
  "bin": {
24
24
  "baja": "./code.js"
25
25
  },
26
- "models": "./index.js",
27
26
  "scripts": {
28
27
  "dist": "node ./ci.js",
29
28
  "mysql": "bun --inspect ./src/test-mysql.ts",
@@ -31,14 +30,15 @@
31
30
  "postgres": "bun --inspect ./src/test-postgresql.ts",
32
31
  "postgres2": "node inspect ./dist/cjs/test-postgresql.js",
33
32
  "sqlite": "node inspect ./dist/cjs/test-sqlite.js",
34
- "xml": "bun --inspect ./src/test-xml.ts",
35
33
  "test": "bun --inspect ./src/test.ts",
36
- "test2": "node inspect ./dist/cjs/tes.js"
34
+ "test2": "node inspect ./dist/cjs/tes.js",
35
+ "xml": "bun --inspect ./src/test-xml.ts"
37
36
  },
38
37
  "dependencies": {
39
- "@msgpack/msgpack": "3.1.0",
38
+ "@msgpack/msgpack": "3.1.1",
40
39
  "@types/request-promise": "4.1.51",
41
- "axios": "1.8.1",
40
+ "axios": "1.8.4",
41
+ "baja-lite-field": "1.3.1",
42
42
  "decimal.js": "10.5.0",
43
43
  "html-parse-stringify": "3.0.1",
44
44
  "iterare": "1.2.1",
@@ -57,18 +57,18 @@
57
57
  "@types/better-sqlite3": "7.6.12",
58
58
  "@types/lodash.get": "4.4.9",
59
59
  "@types/mustache": "4.2.5",
60
- "@types/node": "22.13.0",
60
+ "@types/node": "22.13.10",
61
61
  "@types/pg-pool": "2.0.6",
62
62
  "@types/shelljs": "0.8.15",
63
63
  "@types/sqlstring": "2.3.2",
64
- "@typescript-eslint/eslint-plugin": "8.26.1",
65
- "@typescript-eslint/parser": "8.26.1",
66
- "better-sqlite3": "11.8.1",
64
+ "@typescript-eslint/eslint-plugin": "8.27.0",
65
+ "@typescript-eslint/parser": "8.27.0",
66
+ "better-sqlite3": "11.9.1",
67
67
  "ioredis": "5.6.0",
68
- "mongodb": "6.14.2",
69
- "mysql2": "3.13.0",
70
- "pg": "8.13.3",
71
- "pg-pool": "3.7.1",
68
+ "mongodb": "6.15.0",
69
+ "mysql2": "3.14.0",
70
+ "pg": "8.14.1",
71
+ "pg-pool": "3.8.0",
72
72
  "redlock": "5.0.0-beta.2",
73
73
  "shelljs": "0.8.5",
74
74
  "typescript": "5.7.3"
@@ -78,5 +78,6 @@
78
78
  },
79
79
  "publishConfig": {
80
80
  "access": "public"
81
- }
81
+ },
82
+ "models": "./index.js"
82
83
  }
package/sql.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ExtensionCodec } from "@msgpack/msgpack";
2
+ import { _columns, _columnsNoId, _def, _deleteState, _fields, _ids, _index, _logicIds, _stateFileName, AField, DBType, FieldOption } from 'baja-lite-field';
2
3
  import { XML } from './convert-xml.js';
3
4
  import { EnumMap } from './enum.js';
4
5
  import { ArrayList } from './list.js';
@@ -8,16 +9,7 @@ declare const _tableName: unique symbol;
8
9
  declare const _className: unique symbol;
9
10
  declare const _ClassName: unique symbol;
10
11
  declare const _vueName: unique symbol;
11
- declare const _ids: unique symbol;
12
- declare const _logicIds: unique symbol;
13
- declare const _columns: unique symbol;
14
- declare const _columnsNoId: unique symbol;
15
- declare const _fields: unique symbol;
16
- declare const _stateFileName: unique symbol;
17
- declare const _deleteState: unique symbol;
18
12
  declare const _transformer: unique symbol;
19
- declare const _index: unique symbol;
20
- declare const _def: unique symbol;
21
13
  declare const _comment: unique symbol;
22
14
  export declare const _sqlCache: unique symbol;
23
15
  export declare const _dao: unique symbol;
@@ -30,21 +22,11 @@ declare const _daoDB: unique symbol;
30
22
  declare const _sqliteRemoteName: unique symbol;
31
23
  declare const _SqlOption: unique symbol;
32
24
  export declare const _enums: unique symbol;
33
- export declare const _Hump: unique symbol;
34
25
  export declare const _GlobalSqlOption: unique symbol;
35
26
  export declare const _EventBus: unique symbol;
36
27
  export declare const _path: unique symbol;
37
28
  export declare const _fs: unique symbol;
38
29
  export declare const logger: import("pino").Logger<never, boolean>;
39
- export declare enum DBType {
40
- Mysql = 0,
41
- Postgresql = 1,
42
- Sqlite = 2,
43
- Mongo = 3,
44
- SqliteRemote = 4,
45
- Redis = 5,
46
- RedisLock = 6
47
- }
48
30
  export declare enum MapperIfUndefined {
49
31
  Null = 0,
50
32
  Skip = 1,
@@ -135,32 +117,6 @@ export declare enum SelectResult {
135
117
  /** 多行多列并封装ArrayList */
136
118
  RS_CS_List = 7
137
119
  }
138
- export declare enum SqlType {
139
- tinyint = 0,
140
- smallint = 1,
141
- mediumint = 2,
142
- int = 3,
143
- bigint = 4,
144
- float = 5,
145
- double = 6,
146
- decimal = 7,
147
- date = 8,
148
- time = 9,
149
- year = 10,
150
- datetime = 11,
151
- timestamp = 12,
152
- char = 13,
153
- varchar = 14,
154
- tinyblob = 15,
155
- tinytext = 16,
156
- blob = 17,
157
- text = 18,
158
- mediumblob = 19,
159
- mediumtext = 20,
160
- longblob = 21,
161
- longtext = 22,
162
- json = 23
163
- }
164
120
  export declare enum ColumnMode {
165
121
  NONE = 0,
166
122
  HUMP = 1
@@ -490,44 +446,6 @@ export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
490
446
  */
491
447
  jsMode?: boolean;
492
448
  }
493
- interface FieldOption extends Object {
494
- type?: SqlType;
495
- /** @deprecated 属性名称:TS注解不需要,JS手动注入需要 */
496
- P?: string;
497
- length?: number;
498
- scale?: number;
499
- def?: any;
500
- index?: boolean;
501
- id?: boolean;
502
- logicDelete?: string | number;
503
- /** 是否逻辑唯一,用于导入时检测数据是否存在 */
504
- logicId?: boolean;
505
- /** 仅在生成 表时有效 */
506
- notNull?: boolean;
507
- /** 注释,影响到默认导出导入标题 */
508
- comment?: string;
509
- /** 可以导入的字段,默认TRUE,ID默认FALSE */
510
- importable?: boolean;
511
- /** 可以导出的字段,默认TRUE,ID默认FALSE */
512
- exportable?: boolean;
513
- /** sqlite 无效,与UUID只能有一个 */
514
- uuidShort?: boolean;
515
- /** 与uuidShort只能有一个 */
516
- uuid?: boolean;
517
- }
518
- interface AField extends FieldOption {
519
- /** 安全列名 */
520
- C2: () => string;
521
- /** @deprecated 数据列名称 */
522
- C?: () => string;
523
- /** 查询用:b_id bId */
524
- C3: () => string;
525
- [DBType.Postgresql]: () => string;
526
- [DBType.Mysql]: () => string;
527
- [DBType.Sqlite]: () => string;
528
- [DBType.SqliteRemote]: () => string;
529
- Data2SQL: (data: any) => any;
530
- }
531
449
  export interface PageQuery<L> {
532
450
  sum?: Record<string, number>;
533
451
  total?: number;
@@ -743,7 +661,6 @@ export declare class SqlCache {
743
661
  [k: string]: any;
744
662
  }): string;
745
663
  }
746
- export declare const Field: (config: FieldOption) => (object: object, propertyName: string) => void;
747
664
  export declare const DB: (config: ServiceOption) => <C extends {
748
665
  new (...args: any[]): {};
749
666
  }>(constructor: C) => {
@@ -1447,6 +1364,11 @@ declare class StreamQuery<T extends object> {
1447
1364
  reset(): this;
1448
1365
  /** 为下次链条执行提供条件判断:非异步方法跳过,异步方法不执行并返回默认值 */
1449
1366
  if(condition: boolean): this;
1367
+ eqs(keys: (keyof T)[], value: string | number, { paramName, skipEmptyString, breakExcuteIfSkip }?: {
1368
+ paramName?: string | undefined;
1369
+ skipEmptyString?: boolean | undefined;
1370
+ breakExcuteIfSkip?: boolean | undefined;
1371
+ }): this;
1450
1372
  eq(key: keyof T, value: string | number, { paramName, skipEmptyString, breakExcuteIfSkip }?: {
1451
1373
  paramName?: string | undefined;
1452
1374
  skipEmptyString?: boolean | undefined;
@@ -1778,6 +1700,7 @@ declare class StreamQuery<T extends object> {
1778
1700
  }): number;
1779
1701
  private _where;
1780
1702
  private _;
1703
+ private __;
1781
1704
  private _null;
1782
1705
  private _key;
1783
1706
  private _between;
package/sql.js CHANGED
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var _b, _c, _d, _e;
11
11
  var _f, _g, _h, _j;
12
12
  import { decode, DecodeError, encode, ExtensionCodec } from "@msgpack/msgpack";
13
+ import { _columns, _columnsNoId, _def, _deleteState, _fields, _Hump, _ids, _index, _logicIds, _stateFileName, DBType, Field } from 'baja-lite-field';
13
14
  import HTML from 'html-parse-stringify';
14
15
  import * as ite from 'iterare';
15
16
  import LGet from 'lodash.get';
@@ -57,16 +58,7 @@ const _tableName = Symbol('tableName');
57
58
  const _className = Symbol('className');
58
59
  const _ClassName = Symbol('ClassName');
59
60
  const _vueName = Symbol('vueName');
60
- const _ids = Symbol('ids');
61
- const _logicIds = Symbol('logicIds');
62
- const _columns = Symbol('columns');
63
- const _columnsNoId = Symbol('columnsNoId');
64
- const _fields = Symbol('fields');
65
- const _stateFileName = Symbol('stateFileName');
66
- const _deleteState = Symbol('deleteState');
67
61
  const _transformer = Symbol('transformer');
68
- const _index = Symbol('index');
69
- const _def = Symbol('def');
70
62
  const _comment = Symbol('comment');
71
63
  export const _sqlCache = Symbol('sqlMap');
72
64
  export const _dao = Symbol('dao');
@@ -81,7 +73,6 @@ const _SqlOption = Symbol('SqlOption');
81
73
  const _resultMap = Symbol('resultMap');
82
74
  const _resultMap_SQLID = Symbol('resultMap_SQLID');
83
75
  export const _enums = Symbol('_enums');
84
- export const _Hump = Symbol('Hump');
85
76
  export const _GlobalSqlOption = Symbol('GlobalSqlOption');
86
77
  export const _EventBus = Symbol('EventBus');
87
78
  export const _path = Symbol('path');
@@ -95,17 +86,6 @@ export const logger = process.env['NODE_ENV'] !== 'production' ? pino({
95
86
  globalThis[_resultMap_SQLID] = {};
96
87
  // #endregion
97
88
  // #region 可选配置
98
- export var DBType;
99
- (function (DBType) {
100
- DBType[DBType["Mysql"] = 0] = "Mysql";
101
- DBType[DBType["Postgresql"] = 1] = "Postgresql";
102
- DBType[DBType["Sqlite"] = 2] = "Sqlite";
103
- DBType[DBType["Mongo"] = 3] = "Mongo";
104
- DBType[DBType["SqliteRemote"] = 4] = "SqliteRemote";
105
- DBType[DBType["Redis"] = 5] = "Redis";
106
- DBType[DBType["RedisLock"] = 6] = "RedisLock";
107
- })(DBType || (DBType = {}));
108
- ;
109
89
  export var MapperIfUndefined;
110
90
  (function (MapperIfUndefined) {
111
91
  MapperIfUndefined[MapperIfUndefined["Null"] = 0] = "Null";
@@ -214,33 +194,6 @@ export var SelectResult;
214
194
  /** 多行多列并封装ArrayList */
215
195
  SelectResult[SelectResult["RS_CS_List"] = 7] = "RS_CS_List";
216
196
  })(SelectResult || (SelectResult = {}));
217
- export var SqlType;
218
- (function (SqlType) {
219
- SqlType[SqlType["tinyint"] = 0] = "tinyint";
220
- SqlType[SqlType["smallint"] = 1] = "smallint";
221
- SqlType[SqlType["mediumint"] = 2] = "mediumint";
222
- SqlType[SqlType["int"] = 3] = "int";
223
- SqlType[SqlType["bigint"] = 4] = "bigint";
224
- SqlType[SqlType["float"] = 5] = "float";
225
- SqlType[SqlType["double"] = 6] = "double";
226
- SqlType[SqlType["decimal"] = 7] = "decimal";
227
- SqlType[SqlType["date"] = 8] = "date";
228
- SqlType[SqlType["time"] = 9] = "time";
229
- SqlType[SqlType["year"] = 10] = "year";
230
- SqlType[SqlType["datetime"] = 11] = "datetime";
231
- SqlType[SqlType["timestamp"] = 12] = "timestamp";
232
- SqlType[SqlType["char"] = 13] = "char";
233
- SqlType[SqlType["varchar"] = 14] = "varchar";
234
- SqlType[SqlType["tinyblob"] = 15] = "tinyblob";
235
- SqlType[SqlType["tinytext"] = 16] = "tinytext";
236
- SqlType[SqlType["blob"] = 17] = "blob";
237
- SqlType[SqlType["text"] = 18] = "text";
238
- SqlType[SqlType["mediumblob"] = 19] = "mediumblob";
239
- SqlType[SqlType["mediumtext"] = 20] = "mediumtext";
240
- SqlType[SqlType["longblob"] = 21] = "longblob";
241
- SqlType[SqlType["longtext"] = 22] = "longtext";
242
- SqlType[SqlType["json"] = 23] = "json";
243
- })(SqlType || (SqlType = {}));
244
197
  export var ColumnMode;
245
198
  (function (ColumnMode) {
246
199
  ColumnMode[ColumnMode["NONE"] = 0] = "NONE";
@@ -1974,233 +1927,6 @@ const FieldFilter = (K, V, def, uuidColumn, option) => {
1974
1927
  }
1975
1928
  return [ret, V];
1976
1929
  };
1977
- const MYSQLCHARSET = `CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci`;
1978
- const POSTGRESCHARSET = `COLLATE "pg_catalog"."default"`;
1979
- export const Field = (config) => {
1980
- config.type ?? (config.type = SqlType.varchar);
1981
- return (object, propertyName) => {
1982
- const field = config;
1983
- field.P = propertyName;
1984
- field.C = () => P2C(propertyName, globalThis[_Hump]);
1985
- field.C2 = () => P2C(propertyName, globalThis[_Hump]);
1986
- field.C3 = () => `${P2C(propertyName, globalThis[_Hump])} ${propertyName}`;
1987
- const hasDef = field.hasOwnProperty('def') === true;
1988
- switch (field.type) {
1989
- case SqlType.tinyint: {
1990
- field[DBType.Mysql] = () => `${field.C2()} tinyint ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
1991
- field[DBType.Postgresql] = () => `${field.C2()} int2 ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
1992
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
1993
- break;
1994
- }
1995
- case SqlType.smallint: {
1996
- field[DBType.Mysql] = () => `${field.C2()} smallint ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
1997
- field[DBType.Postgresql] = () => `${field.C2()} int2 ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
1998
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
1999
- break;
2000
- }
2001
- case SqlType.mediumint: {
2002
- field[DBType.Mysql] = () => `${field.C2()} smallint ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
2003
- field[DBType.Postgresql] = () => `${field.C2()} int4 ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
2004
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
2005
- break;
2006
- }
2007
- case SqlType.int: {
2008
- field[DBType.Mysql] = () => `${field.C2()} int ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
2009
- field[DBType.Postgresql] = () => `${field.C2()} int4 ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT ${field.def}` : ''}`;
2010
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
2011
- break;
2012
- }
2013
- case SqlType.bigint: {
2014
- field[DBType.Mysql] = () => `${field.C2()} bigint ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2015
- field[DBType.Postgresql] = () => `${field.C2()} int8 ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2016
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
2017
- field.Data2SQL = (data) => BigInt(data ?? 0);
2018
- break;
2019
- }
2020
- case SqlType.float: {
2021
- field[DBType.Mysql] = () => `${field.C2()} float4(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
2022
- field[DBType.Postgresql] = () => `${field.C2()} float4(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
2023
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} real`;
2024
- break;
2025
- }
2026
- case SqlType.double: {
2027
- field[DBType.Mysql] = () => `${field.C2()} double(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
2028
- field[DBType.Postgresql] = () => `${field.C2()} float8(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
2029
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} real`;
2030
- break;
2031
- }
2032
- case SqlType.decimal: {
2033
- field[DBType.Mysql] = () => `${field.C2()} decimal(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
2034
- field[DBType.Postgresql] = () => `${field.C2()} numeric(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
2035
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} real`;
2036
- break;
2037
- }
2038
- case SqlType.longtext: {
2039
- field[DBType.Mysql] = () => `${field.C2()} longtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2040
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2041
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2042
- break;
2043
- }
2044
- case SqlType.mediumtext: {
2045
- field[DBType.Mysql] = () => `${field.C2()} mediumtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2046
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2047
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2048
- break;
2049
- }
2050
- case SqlType.text: {
2051
- field[DBType.Mysql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2052
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2053
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2054
- break;
2055
- }
2056
- case SqlType.date: {
2057
- field[DBType.Mysql] = () => `${field.C2()} date ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2058
- field[DBType.Postgresql] = () => `${field.C2()} date ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2059
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2060
- field.Data2SQL = (data) => typeof data === 'string' ? new Date(data) : data;
2061
- break;
2062
- }
2063
- case SqlType.time: {
2064
- field[DBType.Mysql] = () => `${field.C2()} time ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2065
- field[DBType.Postgresql] = () => `${field.C2()} time ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2066
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2067
- field.Data2SQL = (data) => typeof data === 'string' ? new Date(data) : data;
2068
- break;
2069
- }
2070
- case SqlType.year: {
2071
- field[DBType.Mysql] = () => `${field.C2()} year ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2072
- field[DBType.Postgresql] = () => `${field.C2()} int4 ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2073
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2074
- field.Data2SQL = (data) => typeof data === 'string' ? new Date(data) : data;
2075
- break;
2076
- }
2077
- case SqlType.datetime: {
2078
- field[DBType.Mysql] = () => `${field.C2()} datetime ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2079
- field[DBType.Postgresql] = () => `${field.C2()} timestamp ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2080
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2081
- field.Data2SQL = (data) => typeof data === 'string' ? new Date(data) : data;
2082
- break;
2083
- }
2084
- case SqlType.timestamp: {
2085
- field[DBType.Mysql] = () => `${field.C2()} timestamp ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2086
- field[DBType.Postgresql] = () => `${field.C2()} timestamp ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2087
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
2088
- field.Data2SQL = (data) => typeof data === 'string' ? +new Date(data) : data;
2089
- break;
2090
- }
2091
- case SqlType.char: {
2092
- field[DBType.Mysql] = () => `${field.C2()} char(${config.length ?? 1}) ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2093
- field[DBType.Postgresql] = () => `${field.C2()} char(${config.length ?? 1}) ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2094
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2095
- break;
2096
- }
2097
- case SqlType.varchar: {
2098
- field[DBType.Mysql] = () => `${field.C2()} varchar(${config.length ?? 1}) ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2099
- field[DBType.Postgresql] = () => `${field.C2()} varchar(${config.length ?? 1}) ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2100
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2101
- break;
2102
- }
2103
- case SqlType.tinyblob: {
2104
- field[DBType.Mysql] = () => `${field.C2()} tinyblob ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2105
- field[DBType.Postgresql] = () => `${field.C2()} bytea ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2106
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2107
- break;
2108
- }
2109
- case SqlType.tinytext: {
2110
- field[DBType.Mysql] = () => `${field.C2()} tinytext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2111
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2112
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2113
- break;
2114
- }
2115
- case SqlType.blob: {
2116
- field[DBType.Mysql] = () => `${field.C2()} binary ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2117
- field[DBType.Postgresql] = () => `${field.C2()} bytea ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2118
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2119
- break;
2120
- }
2121
- case SqlType.text: {
2122
- field[DBType.Mysql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2123
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2124
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2125
- break;
2126
- }
2127
- case SqlType.mediumblob: {
2128
- field[DBType.Mysql] = () => `${field.C2()} mediumblob ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2129
- field[DBType.Postgresql] = () => `${field.C2()} bytea ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2130
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2131
- break;
2132
- }
2133
- case SqlType.mediumtext: {
2134
- field[DBType.Mysql] = () => `${field.C2()} mediumtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2135
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2136
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2137
- break;
2138
- }
2139
- case SqlType.longblob: {
2140
- field[DBType.Mysql] = () => `${field.C2()} longblob ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2141
- field[DBType.Postgresql] = () => `${field.C2()} bytea ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2142
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2143
- break;
2144
- }
2145
- case SqlType.longtext: {
2146
- field[DBType.Mysql] = () => `${field.C2()} longtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2147
- field[DBType.Postgresql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2148
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2149
- break;
2150
- }
2151
- case SqlType.json: {
2152
- field[DBType.Mysql] = () => `${field.C2()} json ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2153
- field[DBType.Postgresql] = () => `${field.C2()} jsonb ${config.notNull === true ? 'NOT NULL' : ''} ${POSTGRESCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
2154
- field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
2155
- break;
2156
- }
2157
- }
2158
- ;
2159
- let __fields = Reflect.getMetadata(_fields, object);
2160
- let __columns = Reflect.getMetadata(_columns, object);
2161
- let __columnsNoId = Reflect.getMetadata(_columnsNoId, object);
2162
- let __ids = Reflect.getMetadata(_ids, object);
2163
- let __logicIds = Reflect.getMetadata(_logicIds, object);
2164
- let __index = Reflect.getMetadata(_index, object);
2165
- let __def = Reflect.getMetadata(_def, object);
2166
- if (!__fields) {
2167
- __fields = {};
2168
- __columns = [];
2169
- __columnsNoId = [];
2170
- __ids = [];
2171
- __index = [];
2172
- __def = {};
2173
- }
2174
- __fields[propertyName] = field;
2175
- __columns.push(propertyName);
2176
- if (field.id === true) {
2177
- __ids.push(propertyName);
2178
- }
2179
- else {
2180
- __columnsNoId.push(propertyName);
2181
- }
2182
- if (field.logicId === true) {
2183
- __logicIds.push(propertyName);
2184
- }
2185
- if (field.index === true) {
2186
- __index.push(propertyName);
2187
- }
2188
- if (hasDef) {
2189
- __def[propertyName] = field.def;
2190
- }
2191
- Reflect.defineMetadata(_fields, __fields, object);
2192
- Reflect.defineMetadata(_columns, __columns, object);
2193
- Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
2194
- Reflect.defineMetadata(_ids, __ids, object);
2195
- Reflect.defineMetadata(_logicIds, __logicIds, object);
2196
- Reflect.defineMetadata(_index, __index, object);
2197
- Reflect.defineMetadata(_def, __def, object);
2198
- if (field.hasOwnProperty('logicDelete')) {
2199
- Reflect.defineMetadata(_deleteState, field.logicDelete, object);
2200
- Reflect.defineMetadata(_stateFileName, propertyName, object);
2201
- }
2202
- };
2203
- };
2204
1930
  const formatDialects = {
2205
1931
  [DBType.Mysql]: mysql,
2206
1932
  [DBType.Sqlite]: sqlite,
@@ -3677,6 +3403,7 @@ class StreamQuery {
3677
3403
  this.if_proceed = condition;
3678
3404
  return this;
3679
3405
  }
3406
+ eqs(keys, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this.__(keys, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3680
3407
  eq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3681
3408
  eqT(t, { name: paramName = '', breakExcuteIfSkip = false } = {}) {
3682
3409
  let exe = false;
@@ -4052,7 +3779,6 @@ class StreamQuery {
4052
3779
  this._param[this._paramKeys[paramName]] = value;
4053
3780
  }
4054
3781
  else {
4055
- paramName;
4056
3782
  const pkey = `p${this._prefix}${this._index++}`;
4057
3783
  this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} ${op} :${pkey} `);
4058
3784
  this._param[pkey] = value;
@@ -4062,6 +3788,28 @@ class StreamQuery {
4062
3788
  }
4063
3789
  return this;
4064
3790
  }
3791
+ __(keys, value, op, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3792
+ if (value === null
3793
+ || value === undefined
3794
+ || (emptyString(`${value ?? ''}`) && skipEmptyString === true)) {
3795
+ if (breakExcuteIfSkip === true) {
3796
+ this.if_exec = false;
3797
+ }
3798
+ return this;
3799
+ }
3800
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3801
+ this._param[this._paramKeys[paramName]] = value;
3802
+ }
3803
+ else {
3804
+ const pkey = `p${this._prefix}${this._index++}`;
3805
+ this._wheres.push(`AND (${keys.map(key => `${this[_fields][String(key)]?.C2()} ${not} ${op} :${pkey} `).join(' OR ')})`);
3806
+ this._param[pkey] = value;
3807
+ if (paramName) {
3808
+ this._paramKeys[paramName] = pkey;
3809
+ }
3810
+ }
3811
+ return this;
3812
+ }
4065
3813
  _null(key, not = '') {
4066
3814
  this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} IS ${not} NULL`);
4067
3815
  return this;
@@ -4233,6 +3981,12 @@ __decorate([
4233
3981
  __metadata("design:paramtypes", [Boolean]),
4234
3982
  __metadata("design:returntype", void 0)
4235
3983
  ], StreamQuery.prototype, "if", null);
3984
+ __decorate([
3985
+ IF_PROCEED(),
3986
+ __metadata("design:type", Function),
3987
+ __metadata("design:paramtypes", [Array, Object, Object]),
3988
+ __metadata("design:returntype", void 0)
3989
+ ], StreamQuery.prototype, "eqs", null);
4236
3990
  __decorate([
4237
3991
  IF_PROCEED(),
4238
3992
  __metadata("design:type", Function),
package/test-mysql.js CHANGED
@@ -7,9 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
+ import { Field, SqlType } from 'baja-lite-field';
10
11
  import 'reflect-metadata';
11
12
  import { Boot } from './boot.js';
12
- import { ColumnMode, DB, Field, SqlService, SqlType } from './sql.js';
13
+ import { ColumnMode, DB, SqlService } from './sql.js';
13
14
  class BaseAuditUser {
14
15
  }
15
16
  __decorate([
@@ -7,9 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
+ import { DBType, Field, SqlType } from 'baja-lite-field';
10
11
  import 'reflect-metadata';
11
12
  import { Boot } from './boot.js';
12
- import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql.js';
13
+ import { ColumnMode, DB, SelectResult, SqlService, } from './sql.js';
13
14
  class AmaFuck2 {
14
15
  }
15
16
  __decorate([
package/test-sqlite.js CHANGED
@@ -7,9 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
+ import { DBType, Field, SqlType } from 'baja-lite-field';
10
11
  import 'reflect-metadata';
11
12
  import { Boot } from './boot';
12
- import { SqlService, Field, SqlType, DB, DBType, SyncMode, DeleteMode, InsertMode } from './sql';
13
+ import { DB, DeleteMode, InsertMode, SqlService, SyncMode } from './sql';
13
14
  class AmaFuck {
14
15
  }
15
16
  __decorate([
package/validate.d.ts ADDED
@@ -0,0 +1,170 @@
1
+ type Patter = {
2
+ 'upper-letter': patter;
3
+ 'lower-letter': patter;
4
+ letter: patter;
5
+ 'letter-2': patter;
6
+ chinese: patter;
7
+ zonecode: patter;
8
+ qq: patter;
9
+ wechat: patter;
10
+ email: patter;
11
+ mobile: patter;
12
+ tel: patter;
13
+ allphone: patter;
14
+ license: patter;
15
+ organ: patter;
16
+ bank: patter;
17
+ float: patter;
18
+ string: patter;
19
+ plus: patter;
20
+ 'plus-int': patter;
21
+ 'plus-float': patter;
22
+ minus: patter;
23
+ 'minus-int': patter;
24
+ 'minus-float': patter;
25
+ 'un-plus': patter;
26
+ 'un-plus-int': patter;
27
+ 'un-plus-float': patter;
28
+ 'un-minus': patter;
29
+ 'un-minus-int': patter;
30
+ 'un-minus-float': patter;
31
+ 'id-card': patter;
32
+ number: patter;
33
+ number2: patter;
34
+ int: patter;
35
+ price: patter;
36
+ 'price-2': patter;
37
+ 'price-3': patter;
38
+ 'price-4': patter;
39
+ 'price-5': patter;
40
+ 'rebate-1': patter;
41
+ 'rebate-10': patter;
42
+ 'rebate-100': patter;
43
+ url: patter;
44
+ post: patter;
45
+ };
46
+ export interface ValidateProps {
47
+ label?: string;
48
+ prop?: string;
49
+ required?: boolean;
50
+ mkType?: 'string' | 'number' | 'boolean';
51
+ mkRealProp?: string | (() => string);
52
+ mkLabel?: string;
53
+ mkTrigger?: 'blur' | 'change';
54
+ mkEq?: string | number | (() => string | number);
55
+ mkNe?: string | number | (() => string | number);
56
+ mkLt?: string | number | (() => string | number);
57
+ mkLe?: string | number | (() => string | number);
58
+ mkGe?: string | number | (() => string | number);
59
+ mkGt?: string | number | (() => string | number);
60
+ mkEqProp?: string | (() => string);
61
+ mkNeProp?: string | (() => string);
62
+ mkLtProp?: string | (() => string);
63
+ mkLeProp?: string | (() => string);
64
+ mkGeProp?: string | (() => string);
65
+ mkGtProp?: string | (() => string);
66
+ mkEqLength?: number | (() => number);
67
+ mkNeLength?: number | (() => number);
68
+ mkLtLength?: number | (() => number);
69
+ mkLeLength?: number | (() => number);
70
+ mkGeLength?: number | (() => number);
71
+ mkGtLength?: number | (() => number);
72
+ mkEqLengthProp?: string | (() => string);
73
+ mkNeLengthProp?: string | (() => string);
74
+ mkLtLengthProp?: string | (() => string);
75
+ mkLeLengthProp?: string | (() => string);
76
+ mkGeLengthProp?: string | (() => string);
77
+ mkGtLengthProp?: string | (() => string);
78
+ mkEnum?: string[] | (() => string[]);
79
+ mkInlay?: keyof Patter;
80
+ mkPattern?: RegExp;
81
+ mkCustom?: <T>(value: any, prop?: string, form?: T) => Promise<Error | null>;
82
+ mkTrim?: boolean;
83
+ mkIdCard?: boolean;
84
+ }
85
+ export declare class ValidateItem<FormType> {
86
+ private props;
87
+ private data;
88
+ private value;
89
+ constructor(validItem: ValidateProps, data: FormType);
90
+ get length(): number;
91
+ get realLabel(): string;
92
+ get emptyValue(): boolean;
93
+ myValue(): any;
94
+ isEmptyValue(vl: any): boolean;
95
+ getLength(vl: any): number;
96
+ valueConvert(value: any): any;
97
+ getValue(key: any): any;
98
+ getProp(prop: any): any;
99
+ getValueLength(key: any): number;
100
+ getPropLength(prop: any): number;
101
+ patternFn(value: any, [ms, p]: patter): void;
102
+ required(): Promise<void>;
103
+ mkEnum(): Promise<void>;
104
+ mkInlay(): Promise<void>;
105
+ mkPattern(): Promise<void>;
106
+ mkCustom(): Promise<Error | null>;
107
+ mkEq(): Promise<void>;
108
+ mkNe(): Promise<void>;
109
+ mkLt(): Promise<void>;
110
+ mkLe(): Promise<void>;
111
+ mkGt(): Promise<void>;
112
+ mkGe(): Promise<void>;
113
+ mkEqProp(): Promise<void>;
114
+ mkNeProp(): Promise<void>;
115
+ mkLtProp(): Promise<void>;
116
+ mkLeProp(): Promise<void>;
117
+ mkGtProp(): Promise<void>;
118
+ mkGeProp(): Promise<void>;
119
+ mkEqLength(): Promise<void>;
120
+ mkNeLength(): Promise<void>;
121
+ mkLtLength(): Promise<void>;
122
+ mkLeLength(): Promise<void>;
123
+ mkGtLength(): Promise<void>;
124
+ mkGeLength(): Promise<void>;
125
+ mkEqLengthProp(): Promise<void>;
126
+ mkNeLengthProp(): Promise<void>;
127
+ mkLtLengthProp(): Promise<void>;
128
+ mkLeLengthProp(): Promise<void>;
129
+ mkGtLengthProp(): Promise<void>;
130
+ mkGeLengthProp(): Promise<void>;
131
+ mkIdCard(): Promise<void>;
132
+ element(): {
133
+ validator: (_rule: any, value: any, callback: (e?: Error) => void, _source: any, _op: any) => void;
134
+ trigger: "blur" | "change" | undefined;
135
+ }[];
136
+ wot(): {
137
+ required: boolean | undefined;
138
+ validator: (val: any) => Promise<unknown[]>;
139
+ }[];
140
+ service(): Promise<void>;
141
+ }
142
+ export declare class ValidateForm<FormType> {
143
+ private valids;
144
+ constructor(valids: ValidForm<FormType>, data: FormType);
145
+ element(): {
146
+ [k: string]: {
147
+ validator: (_rule: any, value: any, callback: (e?: Error) => void, _source: any, _op: any) => void;
148
+ trigger: "blur" | "change" | undefined;
149
+ }[];
150
+ };
151
+ wot(): {
152
+ [k: string]: {
153
+ required: boolean | undefined;
154
+ validator: (val: any) => Promise<unknown[]>;
155
+ }[];
156
+ };
157
+ service(): Promise<void>;
158
+ }
159
+ type Paths<T, ParentPath extends string = ''> = {
160
+ [K in keyof T]: T[K] extends Record<string, any> | Array<any> ? ParentPath extends '' ? Paths<T[K], `${K & string}`> : `${ParentPath}.${Paths<T[K], K & string>}` : ParentPath extends '' ? K & string : `${ParentPath}.${K & string}`;
161
+ }[keyof T];
162
+ type ArrayPaths<T, ParentPath extends string> = T extends Array<infer U> ? U extends Record<string, any> ? `${ParentPath}.${number}` | `${ParentPath}.${number}.${Paths<U>}` : `${ParentPath}.${number}` : never;
163
+ type AllPaths<T> = T extends Record<string, any> ? {
164
+ [K in keyof T]: T[K] extends Array<infer U> ? `${K & string}` | ArrayPaths<T[K], K & string> : T[K] extends Record<string, any> ? `${K & string}` | `${K & string}.${Paths<T[K]>}` : `${K & string}`;
165
+ }[keyof T] : never;
166
+ type ValidForm<FormType> = Partial<{
167
+ [K in AllPaths<FormType>]: ValidateProps;
168
+ }>;
169
+ type patter = [string, RegExp];
170
+ export {};
package/validate.js ADDED
@@ -0,0 +1,378 @@
1
+ import LGet from 'lodash.get';
2
+ const patterns = {
3
+ 'upper-letter': [' is not capital letters', /^[A-Z]+$/],
4
+ 'lower-letter': [' is not lowercase letters', /^[a-z]+$/],
5
+ letter: [' is not letters', /^[a-zA-Z]+$/],
6
+ 'letter-2': [' is not two letters', /^[a-zA-Z]{2}$/],
7
+ chinese: [' is not chinese', /^[\u0391-\uFFE5]+$/],
8
+ zonecode: [' is wong postal code', /^\d{6}$/],
9
+ qq: [' is wong qq', /^[1-9]\d{4,}$/],
10
+ wechat: [' is wong wechat', /^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$/],
11
+ email: [' is wong email', /^([0-9A-Za-z\-_.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/],
12
+ mobile: [' is wong mobile', /^1(3|4|5|6|7|8)\d{9}$/],
13
+ tel: [' is wong tel', /^0\d{2,3}-?\d{7,8}$/],
14
+ allphone: [' is wong tel', /^1(3|4|5|6|7|8)\d{9}$|(^0\d{2,3}-?\d{7,8}$)/],
15
+ license: [' is wong license', /^[A-Za-z0-9]{15}$|^[A-Za-z0-9]{18}$/],
16
+ organ: [' is wong organ', /^[0-9A-Za-z]{8}\-[0-9A-Za-z]$/],
17
+ bank: [' is wong bank', /^(\d{15}|\d{16}|\d{17}|\d{18}|\d{19})$/],
18
+ float: [' need float', /^-?(\d+\.\d+)$/],
19
+ string: [' enter and space not allow', /^[^\n\r\t]$/],
20
+ plus: [' need positive numbers', /^\d*[1-9]\d*$|^\d+\.\d*[0-9]\d*$/],
21
+ 'plus-int': [' need positive integers', /^\d*[1-9]\d*$/],
22
+ 'plus-float': [' need positive decimals', /^\d+\.\d*[0-9]\d*$/],
23
+ minus: [' need negative numbers', /^-\d*[1-9]\d*$|^-\d+\.\d*[0-9]\d*$/],
24
+ 'minus-int': [' need negative integers', /^-\d*[1-9]\d*$/],
25
+ 'minus-float': [' need negative decimals', /^-\d+\.\d*[0-9]\d*$/],
26
+ 'un-plus': [' need zero or negative number', /^(-[0-9]\d*|-\d+\.\d+|0[0]*|0\.[0]+)$/],
27
+ 'un-plus-int': [' need zero or negative integer', /^(-[0-9]\d*|0[0]*)$/],
28
+ 'un-plus-float': [' need zero or negative decimals', /^(-\d+\.\d+|0[0]*|0\.[0]+)$/],
29
+ 'un-minus': [' need zero or positive numbe', /^([0-9]\d*|\d+\.\d+|0[0]*)$/],
30
+ 'un-minus-int': [' need zero or positive integer', /^([0-9]\d*)$/],
31
+ 'un-minus-float': [' need zero or decimal', /^(\d+\.\d+|0[0]*|0\.[0]+)$/],
32
+ 'id-card': [' is wong idCard', /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X|x)$/],
33
+ number: [' is not number', /^[1-9]\d*$|^0\.\d*[0-9]\d*$|^[1-9]\d*\.\d*[0-9]\d*$|^-[1-9]\d*$|^-0\.\d*[0-9]\d*$|^-[1-9]\d*\.\d*[0-9]\d*$/],
34
+ number2: [' is not number', /^[1-9]\d*$|^0$|^0\.\d*[0-9]\d*$|^[1-9]\d*\.\d*[0-9]\d*$|^-[1-9]\d*$|^-0\.\d*[0-9]\d*$|^-[1-9]\d*\.\d*[0-9]\d*$/],
35
+ int: [' is not int', /^[1-9]\d*$|^-[1-9]\d*$/],
36
+ price: ['只能是正数且最多两位小数', /^([0-9]\d*|\d+\.\d{1,2}|0[0]*)$/],
37
+ 'price-2': ['金额大于0且最多两位小数', /^([1-9]\d*(\.\d{1,2})?)$|(0\.\d{1,2})$/],
38
+ 'price-3': ['只能是正数且最多3位小数', /^([0-9]\d*|\d+\.\d{1,3}|0[0]*)$/],
39
+ 'price-4': ['只能是正数且最多4位小数', /^([0-9]\d*|\d+\.\d{1,4}|0[0]*)$/],
40
+ 'price-5': ['只能是正数且最多5位小数', /^([0-9]\d*|\d+\.\d{1,5}|0[0]*)$/],
41
+ 'rebate-1': ['只能在0到1之间且最多两位小数', /^(0|1|(0\.([0-9]){1,2}))$/],
42
+ 'rebate-10': ['只能在0到10之间且最多两位小数', /^((([0-9])\.([0-9]){1,2})$)|(^([1-9]|10)$)/],
43
+ 'rebate-100': ['只能在0到100之间且最多两位小数', /^((([0-9]){1,2}\.([0-9]){1,2})$)|(^([1-9]{1,2}|10|100)$)/],
44
+ url: ['网址格式错误', /http(s)*:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!#]*([^<>\"\"])*$/],
45
+ post: ['邮编格式错误', /^\d{6}$/],
46
+ };
47
+ const ms = {
48
+ required: (realLabel) => `${realLabel} is required`,
49
+ mkEq: (vl, realLabel) => `${realLabel} must equal to ${vl}`,
50
+ mkNe: (vl, realLabel) => `${realLabel} cannot equal to ${vl}`,
51
+ mkLt: (vl, realLabel) => `${realLabel} must less than ${vl}`,
52
+ mkLe: (vl, realLabel) => `${realLabel} must less than or equal to ${vl}`,
53
+ mkGt: (vl, realLabel) => `${realLabel} must greater than ${vl}`,
54
+ mkGe: (vl, realLabel) => `${realLabel} must greater than or equal to ${vl}`,
55
+ mkEqLength: (vl, realLabel) => `${realLabel} must ${vl} words`,
56
+ mkNeLength: (vl, realLabel) => `${realLabel} cannot ${vl} words`,
57
+ mkLtLength: (vl, realLabel) => `${realLabel} must less than ${vl} words`,
58
+ mkLeLength: (vl, realLabel) => `${realLabel} at most ${vl} words`,
59
+ mkGtLength: (vl, realLabel) => `${realLabel} must more than ${vl} words`,
60
+ mkGeLength: (vl, realLabel) => `${realLabel} must least ${vl} words`,
61
+ mkEnum: (vl, realLabel) => `${realLabel} Can only be one of ${vl.join(',')}`,
62
+ mkPattern: (realLabel) => `${realLabel} error format`,
63
+ };
64
+ const defProps = {
65
+ mkType: 'string',
66
+ mkTrigger: 'change',
67
+ mkTrim: true
68
+ };
69
+ async function runSequentially(promiseFactories) {
70
+ const results = [];
71
+ try {
72
+ for (const createPromise of promiseFactories) {
73
+ const result = await createPromise();
74
+ results.push(result);
75
+ }
76
+ return results;
77
+ }
78
+ catch (error) {
79
+ throw error;
80
+ }
81
+ }
82
+ export class ValidateItem {
83
+ constructor(validItem, data) {
84
+ this.props = Object.assign({}, defProps, validItem);
85
+ this.data = data;
86
+ }
87
+ get length() {
88
+ return this.getLength(this.value);
89
+ }
90
+ get realLabel() {
91
+ return this.props.mkLabel || this.props.label || '';
92
+ }
93
+ get emptyValue() {
94
+ return this.isEmptyValue(this.value);
95
+ }
96
+ myValue() {
97
+ return this.getValue(this.props.prop);
98
+ }
99
+ isEmptyValue(vl) {
100
+ return this.value === '' || this.value === undefined || this.value === null;
101
+ }
102
+ getLength(vl) {
103
+ return this.isEmptyValue(vl) ? 0 : `${vl}`.length;
104
+ }
105
+ valueConvert(value) {
106
+ switch (this.props.mkType) {
107
+ case 'string':
108
+ return this.isEmptyValue(value) ? '' : this.props.mkTrim ? `${value}`.trim() : `${value}`;
109
+ case 'number':
110
+ return this.isEmptyValue(value) ? null : value - 0;
111
+ case 'boolean':
112
+ return this.isEmptyValue(value) ? null : value === 'true' || value === true;
113
+ default:
114
+ return value;
115
+ }
116
+ }
117
+ getValue(key) {
118
+ return this.valueConvert(typeof key === 'function' ? key() : key);
119
+ }
120
+ getProp(prop) {
121
+ let path = typeof prop === 'function' ? prop() : this.isEmptyValue(prop) ? '' : prop;
122
+ if (!path) {
123
+ return '';
124
+ }
125
+ if (path.includes(':')) {
126
+ path = path.replace(/:/g, '.');
127
+ }
128
+ const v = LGet(this.data, path);
129
+ return this.valueConvert(v);
130
+ }
131
+ getValueLength(key) {
132
+ return this.getLength(this.getValue(key));
133
+ }
134
+ getPropLength(prop) {
135
+ return this.getLength(this.getProp(prop));
136
+ }
137
+ patternFn(value, [ms, p]) {
138
+ if (this.isEmptyValue(value) !== true && p.test(value) === false) {
139
+ throw new Error(ms);
140
+ }
141
+ }
142
+ async required() {
143
+ if (this.props.required === true && this.emptyValue === true) {
144
+ throw new Error(ms.required(this.realLabel));
145
+ }
146
+ }
147
+ async mkEnum() {
148
+ const target = (typeof this.props.mkEnum === 'function' ? this.props.mkEnum() : this.props.mkEnum);
149
+ if (target.includes(this.value) === false) {
150
+ throw new Error(ms.mkEnum(target, this.realLabel));
151
+ }
152
+ }
153
+ async mkInlay() {
154
+ if (patterns.hasOwnProperty(this.props.mkInlay) === true) {
155
+ this.patternFn(this.value, patterns[this.props.mkInlay]);
156
+ }
157
+ }
158
+ async mkPattern() {
159
+ if (this.props.mkPattern.test(this.value) !== true) {
160
+ throw new Error(ms.mkPattern(this.realLabel));
161
+ }
162
+ }
163
+ async mkCustom() {
164
+ return await this.props.mkCustom(this.value, this.props.prop, this.data);
165
+ }
166
+ async mkEq() {
167
+ const target = this.getValue(this.props.mkEq);
168
+ if (this.value !== target) {
169
+ throw new Error(ms.mkEq(target, this.realLabel));
170
+ }
171
+ }
172
+ async mkNe() {
173
+ const target = this.getValue(this.props.mkNe);
174
+ if (this.value === target) {
175
+ throw new Error(ms.mkNe(target, this.realLabel));
176
+ }
177
+ }
178
+ async mkLt() {
179
+ const target = this.getValue(this.props.mkLt);
180
+ if (this.value >= target) {
181
+ throw new Error(ms.mkLt(target, this.realLabel));
182
+ }
183
+ }
184
+ async mkLe() {
185
+ const target = this.getValue(this.props.mkLe);
186
+ if (this.value > target) {
187
+ throw new Error(ms.mkLe(target, this.realLabel));
188
+ }
189
+ }
190
+ async mkGt() {
191
+ const target = this.getValue(this.props.mkGt);
192
+ if (this.value <= target) {
193
+ throw new Error(ms.mkGt(target, this.realLabel));
194
+ }
195
+ }
196
+ async mkGe() {
197
+ const target = this.getValue(this.props.mkGe);
198
+ if (this.value < target) {
199
+ throw new Error(ms.mkGe(target, this.realLabel));
200
+ }
201
+ }
202
+ async mkEqProp() {
203
+ const target = this.getProp(this.props.mkEqProp);
204
+ if (this.value !== target) {
205
+ throw new Error(ms.mkEq(target, this.realLabel));
206
+ }
207
+ }
208
+ async mkNeProp() {
209
+ const target = this.getProp(this.props.mkNeProp);
210
+ if (this.value === target) {
211
+ throw new Error(ms.mkNe(target, this.realLabel));
212
+ }
213
+ }
214
+ async mkLtProp() {
215
+ const target = this.getProp(this.props.mkLtProp);
216
+ if (this.value >= target) {
217
+ throw new Error(ms.mkLt(target, this.realLabel));
218
+ }
219
+ }
220
+ async mkLeProp() {
221
+ const target = this.getProp(this.props.mkLeProp);
222
+ if (this.value > target) {
223
+ throw new Error(ms.mkLe(target, this.realLabel));
224
+ }
225
+ }
226
+ async mkGtProp() {
227
+ const target = this.getProp(this.props.mkGtProp);
228
+ if (this.value <= target) {
229
+ throw new Error(ms.mkGt(target, this.realLabel));
230
+ }
231
+ }
232
+ async mkGeProp() {
233
+ const target = this.getProp(this.props.mkGeProp);
234
+ if (this.value < target) {
235
+ throw new Error(ms.mkGe(target, this.realLabel));
236
+ }
237
+ }
238
+ async mkEqLength() {
239
+ const target = this.getValueLength(this.props.mkEqLength);
240
+ if (this.value !== target) {
241
+ throw new Error(ms.mkEqLength(target, this.realLabel));
242
+ }
243
+ }
244
+ async mkNeLength() {
245
+ const target = this.getValueLength(this.props.mkNeLength);
246
+ if (this.value === target) {
247
+ throw new Error(ms.mkNeLength(target, this.realLabel));
248
+ }
249
+ }
250
+ async mkLtLength() {
251
+ const target = this.getValueLength(this.props.mkLtLength);
252
+ if (this.value >= target) {
253
+ throw new Error(ms.mkLtLength(target, this.realLabel));
254
+ }
255
+ }
256
+ async mkLeLength() {
257
+ const target = this.getValueLength(this.props.mkLeLength);
258
+ if (this.value > target) {
259
+ throw new Error(ms.mkLeLength(target, this.realLabel));
260
+ }
261
+ }
262
+ async mkGtLength() {
263
+ const target = this.getValueLength(this.props.mkGtLength);
264
+ if (this.value <= target) {
265
+ throw new Error(ms.mkGtLength(target, this.realLabel));
266
+ }
267
+ }
268
+ async mkGeLength() {
269
+ const target = this.getValueLength(this.props.mkGeLength);
270
+ if (this.value < target) {
271
+ throw new Error(ms.mkGeLength(target, this.realLabel));
272
+ }
273
+ }
274
+ async mkEqLengthProp() {
275
+ const target = this.getPropLength(this.props.mkEqLengthProp);
276
+ if (this.value !== target) {
277
+ throw new Error(ms.mkEqLength(target, this.realLabel));
278
+ }
279
+ }
280
+ async mkNeLengthProp() {
281
+ const target = this.getPropLength(this.props.mkNeLengthProp);
282
+ if (this.value === target) {
283
+ throw new Error(ms.mkNeLength(target, this.realLabel));
284
+ }
285
+ }
286
+ async mkLtLengthProp() {
287
+ const target = this.getPropLength(this.props.mkLtLengthProp);
288
+ if (this.value >= target) {
289
+ throw new Error(ms.mkLtLength(target, this.realLabel));
290
+ }
291
+ }
292
+ async mkLeLengthProp() {
293
+ const target = this.getPropLength(this.props.mkLeLengthProp);
294
+ if (this.value > target) {
295
+ throw new Error(ms.mkLeLength(target, this.realLabel));
296
+ }
297
+ }
298
+ async mkGtLengthProp() {
299
+ const target = this.getPropLength(this.props.mkGtLengthProp);
300
+ if (this.value <= target) {
301
+ throw new Error(ms.mkGtLength(target, this.realLabel));
302
+ }
303
+ }
304
+ async mkGeLengthProp() {
305
+ const target = this.getPropLength(this.props.mkGeLengthProp);
306
+ if (this.value < target) {
307
+ throw new Error(ms.mkGeLength(target, this.realLabel));
308
+ }
309
+ }
310
+ async mkIdCard() {
311
+ // 15位身份证号码正则表达式
312
+ const regex15 = /^[1-9]\d{5}\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}$/;
313
+ // 18位身份证号码正则表达式
314
+ const regex18 = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$/;
315
+ const value = this.value;
316
+ // 首先检查是否符合15位或18位的正则表达式
317
+ if (regex15.test(value)) {
318
+ return;
319
+ }
320
+ else if (regex18.test(value)) {
321
+ // 18位身份证号码需要进一步校验校验位
322
+ const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
323
+ const parity = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
324
+ let sum = 0;
325
+ for (let i = 0; i < 17; i++) {
326
+ sum += parseInt(value[i]) * factor[i];
327
+ }
328
+ const mod = sum % 11;
329
+ const checkDigit = value[17].toUpperCase();
330
+ if (checkDigit !== parity[mod]) {
331
+ throw new Error('身份证号码错误');
332
+ }
333
+ }
334
+ throw new Error('身份证号码错误');
335
+ }
336
+ element() {
337
+ return [{
338
+ validator: (_rule, value, callback, _source, _op) => {
339
+ this.value = value;
340
+ runSequentially(Object.keys(this.props).filter(key => this[key] && typeof this[key] === 'function').map(key => this[key])).catch(error => callback(error)).then(() => callback());
341
+ }, trigger: this.props.mkTrigger
342
+ }];
343
+ }
344
+ wot() {
345
+ return [{
346
+ required: this.props.required,
347
+ validator: (val) => {
348
+ this.value = val;
349
+ return runSequentially(Object.keys(this.props).filter(key => this[key] && typeof this[key] === 'function').map(key => this[key]));
350
+ }
351
+ }];
352
+ }
353
+ async service() {
354
+ this.value = this.getProp(this.props.mkRealProp || this.props.prop);
355
+ for (const key in this.props) {
356
+ if (this[key] && typeof this[key] === 'function') {
357
+ await this[key]();
358
+ }
359
+ }
360
+ }
361
+ }
362
+ export class ValidateForm {
363
+ constructor(valids, data) {
364
+ this.valids = Object.fromEntries(Object.entries(valids).map(([k, v]) => ([k, new ValidateItem(v, data)])));
365
+ }
366
+ element() {
367
+ return Object.fromEntries(Object.entries(this.valids).map(([k, v]) => ([k, v.element()])));
368
+ }
369
+ wot() {
370
+ return Object.fromEntries(Object.entries(this.valids).map(([k, v]) => ([k, v.wot()])));
371
+ }
372
+ async service() {
373
+ for (const key in this.valids) {
374
+ await this.valids[key]?.service();
375
+ }
376
+ }
377
+ }
378
+ // #endregion
package/wx/mini.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BaseWx } from './base';
2
- import { WxMiniConfig, WxLiveInfo, WxLiveReplay } from './types.js';
1
+ import { BaseWx } from './base.js';
2
+ import { WxLiveInfo, WxLiveReplay, WxMiniConfig } from './types.js';
3
3
  export declare class WxMini extends BaseWx {
4
4
  protected name: string;
5
5
  private config;
package/wx/mini.js CHANGED
@@ -1,6 +1,6 @@
1
- import { BaseWx } from './base';
2
1
  import crypto from 'crypto';
3
2
  import { Throw } from '../error.js';
3
+ import { BaseWx } from './base.js';
4
4
  export class WxMini extends BaseWx {
5
5
  constructor(config) {
6
6
  super();
package/wx/organ.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BaseWx } from './base';
2
- import { WxOrganConfig, WxDepartment, WxOrganUser, WxOrganUserSimply, WxOrganText, WxOrganImage, WxOrganVoice, WxOrganVideo, WxOrganFile, WxOrganTextCard, WxOrganNews, WxOrganMpNews, WxOrganMarkDown, WxOrganTaskCard, WxOrganMini } from './types.js';
1
+ import { BaseWx } from './base.js';
2
+ import { WxDepartment, WxOrganConfig, WxOrganFile, WxOrganImage, WxOrganMarkDown, WxOrganMini, WxOrganMpNews, WxOrganNews, WxOrganTaskCard, WxOrganText, WxOrganTextCard, WxOrganUser, WxOrganUserSimply, WxOrganVideo, WxOrganVoice } from './types.js';
3
3
  export declare class WxOrgan extends BaseWx {
4
4
  protected name: string;
5
5
  private config;
package/wx/organ.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseWx } from './base';
1
+ import { BaseWx } from './base.js';
2
2
  export class WxOrgan extends BaseWx {
3
3
  // private aesKey: Buffer | undefined;
4
4
  // private iv: Buffer | undefined;