befly 3.22.4 → 3.22.7

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.
Files changed (2) hide show
  1. package/lib/dbHelper.js +11 -4
  2. package/package.json +3 -3
package/lib/dbHelper.js CHANGED
@@ -442,11 +442,14 @@ class DbHelper {
442
442
  return normalizeBigIntValues(deserializedList);
443
443
  }
444
444
 
445
+ _prepareWriteInputData(data) {
446
+ return serializeArrayFields(keysToSnake(fieldClear(data, { excludeValues: [null, undefined] })));
447
+ }
448
+
445
449
  _prepareWriteUserData(data, allowState) {
446
- const cleanData = fieldClear(data, { excludeValues: [null, undefined] });
447
450
  const result = {};
448
451
 
449
- for (const [key, value] of Object.entries(serializeArrayFields(keysToSnake(cleanData)))) {
452
+ for (const [key, value] of Object.entries(this._prepareWriteInputData(data))) {
450
453
  if (key === "id") continue;
451
454
  if (key === "created_at") continue;
452
455
  if (key === "updated_at") continue;
@@ -459,7 +462,7 @@ class DbHelper {
459
462
  }
460
463
 
461
464
  _buildInsertRow(options) {
462
- const result = { ...this._prepareWriteUserData(options.data, false) };
465
+ const result = options.beflyMode === "manual" ? this._prepareWriteInputData(options.data) : this._prepareWriteUserData(options.data, false);
463
466
 
464
467
  if (options.beflyMode === "auto") {
465
468
  assertTimeIdValue(options.id);
@@ -476,7 +479,7 @@ class DbHelper {
476
479
  }
477
480
 
478
481
  _buildUpdateRow(options) {
479
- const result = { ...this._prepareWriteUserData(options.data, options.allowState) };
482
+ const result = options.beflyMode === "manual" ? this._prepareWriteInputData(options.data) : this._prepareWriteUserData(options.data, options.allowState);
480
483
  if (options.beflyMode !== "manual") {
481
484
  result.updated_at = options.now;
482
485
  }
@@ -781,6 +784,8 @@ class DbHelper {
781
784
  async insData(options) {
782
785
  const parsed = this.createDbParse().parseInsert(options);
783
786
  const { table, snakeTable, data } = parsed;
787
+ const inputData = this._prepareWriteInputData(data);
788
+ assertWriteDataHasFields(inputData, "插入数据必须至少有一个字段", snakeTable);
784
789
  const now = Date.now();
785
790
  const insertRows = await this.createInsertRows(table, snakeTable, [data], now);
786
791
  const processed = insertRows.processedList[0];
@@ -931,6 +936,8 @@ class DbHelper {
931
936
 
932
937
  async updData(options) {
933
938
  const parsed = this.createDbParse().parseUpdate(options);
939
+ const inputData = this._prepareWriteInputData(parsed.data);
940
+ assertWriteDataHasFields(inputData, "更新数据必须至少有一个字段", parsed.snakeTable);
934
941
 
935
942
  const processed = this._buildUpdateRow({ data: parsed.data, now: Date.now(), allowState: true, beflyMode: this.beflyMode });
936
943
  assertWriteDataHasFields(processed, "更新数据必须至少有一个字段", parsed.snakeTable);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.22.4",
4
- "gitHead": "8d10717424ced255e301cb474d356863ab12509a",
3
+ "version": "3.22.7",
4
+ "gitHead": "d1eaf61557b077938b7f93479d3c91b74135ea50",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
7
7
  "keywords": [
@@ -52,7 +52,7 @@
52
52
  "test": "bun test"
53
53
  },
54
54
  "dependencies": {
55
- "fast-xml-parser": "^5.5.10",
55
+ "fast-xml-parser": "^5.5.11",
56
56
  "nodemailer": "^8.0.5",
57
57
  "pathe": "^2.0.3",
58
58
  "ua-parser-js": "^2.0.9",