@mldong/jeeflow 1.6.3 → 1.6.4
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/dist/persist.d.ts +7 -0
- package/dist/persist.js +36 -14
- package/package.json +1 -1
package/dist/persist.d.ts
CHANGED
|
@@ -35,10 +35,17 @@ export declare class SqliteDynamicTableWriter implements DynamicTableWriter {
|
|
|
35
35
|
/** 用户列默认值(issues/19):优先取 data 中已注入的 apply_user_id=流程 operator,
|
|
36
36
|
* 否则用此配置值,缺省 "system"——多数框架业务表 create_user/update_user 为 BIGINT 存 userId */
|
|
37
37
|
defaultUserValue: unknown;
|
|
38
|
+
/** 列匹配(issues/20):默认宽松——驼峰↔下划线归一匹配(表单字段 companyName ↔ 表列 company_name);
|
|
39
|
+
* 需要精确控制列名的集成方显式开启严格模式(忽略大小写精确匹配) */
|
|
40
|
+
strictColumnMatch: boolean;
|
|
38
41
|
constructor(db: DatabaseSync);
|
|
39
42
|
private tableColumns;
|
|
40
43
|
filterColumns(tableName: string, columns: string[]): string[];
|
|
41
44
|
insert(tableName: string, data: Record<string, unknown>): unknown;
|
|
45
|
+
/** 列匹配(issues/20):严格=忽略大小写精确;宽松(默认)=驼峰↔下划线归一匹配 */
|
|
46
|
+
private findColumn;
|
|
47
|
+
/** 在 data 中找匹配指定表列的 key(宽松模式驼峰 key 匹配下划线列) */
|
|
48
|
+
private findDataKey;
|
|
42
49
|
exists(tableName: string, bizKey: string, bizKeyValue: unknown): boolean;
|
|
43
50
|
fillSystemFields(data: Record<string, unknown>, isInsert: boolean): void;
|
|
44
51
|
/** 默认用户值(issues/19):优先取 data 中已注入的 apply_user_id
|
package/dist/persist.js
CHANGED
|
@@ -2,6 +2,10 @@ import { KeySubmitType, KeyDeptID } from './engine.js';
|
|
|
2
2
|
import { TypeEnd, InstanceState, SubmitType } from './model.js';
|
|
3
3
|
// ─── 默认实现:node:sqlite(内置零依赖) ──────────────────────────────────────
|
|
4
4
|
const TABLE_NAME_RE = /^[A-Za-z0-9_]+$/;
|
|
5
|
+
/** 列名归一(issues/20):转小写 + 去下划线(companyName / company_name / COMPANY_NAME 等价) */
|
|
6
|
+
function normalizeColumn(name) {
|
|
7
|
+
return name.toLowerCase().replace(/_/g, '');
|
|
8
|
+
}
|
|
5
9
|
function nowText() {
|
|
6
10
|
const d = new Date();
|
|
7
11
|
const p = (n) => String(n).padStart(2, '0');
|
|
@@ -34,6 +38,9 @@ export class SqliteDynamicTableWriter {
|
|
|
34
38
|
/** 用户列默认值(issues/19):优先取 data 中已注入的 apply_user_id=流程 operator,
|
|
35
39
|
* 否则用此配置值,缺省 "system"——多数框架业务表 create_user/update_user 为 BIGINT 存 userId */
|
|
36
40
|
defaultUserValue = 'system';
|
|
41
|
+
/** 列匹配(issues/20):默认宽松——驼峰↔下划线归一匹配(表单字段 companyName ↔ 表列 company_name);
|
|
42
|
+
* 需要精确控制列名的集成方显式开启严格模式(忽略大小写精确匹配) */
|
|
43
|
+
strictColumnMatch = false;
|
|
37
44
|
constructor(db) {
|
|
38
45
|
this.db = db;
|
|
39
46
|
}
|
|
@@ -51,27 +58,21 @@ export class SqliteDynamicTableWriter {
|
|
|
51
58
|
}
|
|
52
59
|
filterColumns(tableName, columns) {
|
|
53
60
|
checkTableName(tableName);
|
|
54
|
-
const
|
|
55
|
-
return columns.filter(c =>
|
|
61
|
+
const cols = this.tableColumns(tableName);
|
|
62
|
+
return columns.filter(c => this.findColumn(cols, c) !== '');
|
|
56
63
|
}
|
|
57
64
|
insert(tableName, data) {
|
|
58
65
|
checkTableName(tableName);
|
|
59
66
|
const cols = this.tableColumns(tableName);
|
|
60
67
|
const names = [];
|
|
61
68
|
const values = [];
|
|
62
|
-
//
|
|
69
|
+
// 保持插入顺序稳定(对象键无序,按表列顺序取);写入用表列原名(issues/20)
|
|
63
70
|
for (const col of cols) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const key = Object.keys(data).find(k => k.toUpperCase() === col);
|
|
70
|
-
if (key !== undefined) {
|
|
71
|
-
names.push(col);
|
|
72
|
-
values.push(data[key]);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
71
|
+
const key = this.findDataKey(data, col);
|
|
72
|
+
if (key === '')
|
|
73
|
+
continue;
|
|
74
|
+
names.push(col);
|
|
75
|
+
values.push(data[key]);
|
|
75
76
|
}
|
|
76
77
|
if (names.length === 0)
|
|
77
78
|
throw new Error(`persist: no matching columns for ${tableName}`);
|
|
@@ -80,6 +81,27 @@ export class SqliteDynamicTableWriter {
|
|
|
80
81
|
const res = stmt.run(...values);
|
|
81
82
|
return res.lastInsertRowid;
|
|
82
83
|
}
|
|
84
|
+
/** 列匹配(issues/20):严格=忽略大小写精确;宽松(默认)=驼峰↔下划线归一匹配 */
|
|
85
|
+
findColumn(cols, key) {
|
|
86
|
+
for (const col of cols) {
|
|
87
|
+
if (this.strictColumnMatch) {
|
|
88
|
+
if (col.toUpperCase() === key.toUpperCase())
|
|
89
|
+
return col;
|
|
90
|
+
}
|
|
91
|
+
else if (normalizeColumn(col) === normalizeColumn(key)) {
|
|
92
|
+
return col;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
/** 在 data 中找匹配指定表列的 key(宽松模式驼峰 key 匹配下划线列) */
|
|
98
|
+
findDataKey(data, col) {
|
|
99
|
+
for (const k of Object.keys(data)) {
|
|
100
|
+
if (this.findColumn([col], k) !== '')
|
|
101
|
+
return k;
|
|
102
|
+
}
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
83
105
|
exists(tableName, bizKey, bizKeyValue) {
|
|
84
106
|
checkTableName(tableName);
|
|
85
107
|
this.tableColumns(tableName); // 表不存在提前报错
|