befly 3.18.17 → 3.18.18

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/checks/config.js CHANGED
@@ -42,7 +42,7 @@ const configSchema = z
42
42
  password: noTrimString,
43
43
  database: noTrimString,
44
44
  max: z.number().min(1),
45
- stateFilter: z.union([z.literal(0), z.literal(1)]).optional()
45
+ beflyMode: z.union([z.literal(0), z.literal(1)]).optional()
46
46
  })
47
47
  .strict(),
48
48
 
@@ -26,7 +26,7 @@
26
26
  "password": "root",
27
27
  "database": "befly_dev",
28
28
  "max": 10,
29
- "stateFilter": 1
29
+ "beflyMode": 1
30
30
  },
31
31
 
32
32
  "redis": {
@@ -355,8 +355,8 @@ export function processJoinOn(on) {
355
355
  return result;
356
356
  }
357
357
 
358
- export function addDefaultStateFilter(where = {}, table, hasJoins = false, enableStateFilter = true) {
359
- if (!enableStateFilter) {
358
+ export function addDefaultStateFilter(where = {}, table, hasJoins = false, beflyMode = 1) {
359
+ if (beflyMode === 0) {
360
360
  return where;
361
361
  }
362
362
 
@@ -494,8 +494,10 @@ export function buildInsertRow(options) {
494
494
  result["id"] = options.id;
495
495
  }
496
496
 
497
- result["created_at"] = options.now;
498
- result["updated_at"] = options.now;
497
+ if (options.beflyMode !== 0) {
498
+ result["created_at"] = options.now;
499
+ result["updated_at"] = options.now;
500
+ }
499
501
  result["state"] = 1;
500
502
  return result;
501
503
  }
@@ -508,7 +510,9 @@ export function buildUpdateRow(options) {
508
510
  for (const [key, value] of Object.entries(userData)) {
509
511
  result[key] = value;
510
512
  }
511
- result["updated_at"] = options.now;
513
+ if (options.beflyMode !== 0) {
514
+ result["updated_at"] = options.now;
515
+ }
512
516
  return result;
513
517
  }
514
518
 
@@ -13,7 +13,7 @@ export const dataOpsMethods = {
13
13
  const { table, where, joins, tableQualifier } = await this.prepareQueryOptions(options, "getCount.options");
14
14
  const hasJoins = Array.isArray(joins) && joins.length > 0;
15
15
 
16
- const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.enableStateFilter);
16
+ const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.beflyMode);
17
17
  const result = await this.fetchCount({ table: table, joins: joins }, whereFiltered, "COUNT(*) as count");
18
18
 
19
19
  return {
@@ -26,7 +26,7 @@ export const dataOpsMethods = {
26
26
  const { table, fields, where, joins, tableQualifier } = await this.prepareQueryOptions(options, "getOne.options");
27
27
  const hasJoins = Array.isArray(joins) && joins.length > 0;
28
28
 
29
- const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.enableStateFilter);
29
+ const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.beflyMode);
30
30
  const builder = this.createSqlBuilder().select(fields).from(table).where(whereFiltered);
31
31
  this.applyJoins(builder, joins);
32
32
 
@@ -50,7 +50,7 @@ export const dataOpsMethods = {
50
50
  validatePageLimitRange(prepared, options.table);
51
51
 
52
52
  const hasJoins = Array.isArray(prepared.joins) && prepared.joins.length > 0;
53
- const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.enableStateFilter);
53
+ const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.beflyMode);
54
54
  const countResult = await this.fetchCount(prepared, whereFiltered, "COUNT(*) as total");
55
55
  const total = countResult.total;
56
56
 
@@ -102,7 +102,7 @@ export const dataOpsMethods = {
102
102
  const prepared = await this.prepareQueryOptions(prepareOptions, "getAll.options");
103
103
 
104
104
  const hasJoins = Array.isArray(prepared.joins) && prepared.joins.length > 0;
105
- const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.enableStateFilter);
105
+ const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.beflyMode);
106
106
  const countResult = await this.fetchCount(prepared, whereFiltered, "COUNT(*) as total");
107
107
  const total = countResult.total;
108
108
 
@@ -150,7 +150,7 @@ export const dataOpsMethods = {
150
150
  validateNoJoinReadOptions(options, "exists", "exists 不支持 joins(请使用显式 query 或拆分查询)");
151
151
  const snakeTable = snakeCase(options.table);
152
152
  const snakeWhere = whereKeysToSnake(clearDeep(options.where || {}));
153
- const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.enableStateFilter);
153
+ const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
154
154
 
155
155
  const builder = this.createSqlBuilder().selectRaw("COUNT(1) as cnt").from(snakeTable).where(whereFiltered).limit(1);
156
156
  const { sql, params } = builder.toSelectSql();
@@ -194,7 +194,7 @@ export const dataOpsMethods = {
194
194
 
195
195
  let processed;
196
196
  if (this.idMode === "autoId") {
197
- processed = buildInsertRow({ idMode: "autoId", data: data, now: now });
197
+ processed = buildInsertRow({ idMode: "autoId", data: data, now: now, beflyMode: this.beflyMode });
198
198
  } else {
199
199
  let id;
200
200
  try {
@@ -208,7 +208,7 @@ export const dataOpsMethods = {
208
208
  table: table
209
209
  });
210
210
  }
211
- processed = buildInsertRow({ idMode: "timeId", data: data, id: id, now: now });
211
+ processed = buildInsertRow({ idMode: "timeId", data: data, id: id, now: now, beflyMode: this.beflyMode });
212
212
  }
213
213
 
214
214
  assertNoUndefinedInRecord(processed, `insData 插入数据 (table: ${snakeTable})`);
@@ -253,7 +253,7 @@ export const dataOpsMethods = {
253
253
  let processedList;
254
254
  if (this.idMode === "autoId") {
255
255
  processedList = dataList.map((data) => {
256
- return buildInsertRow({ idMode: "autoId", data: data, now: now });
256
+ return buildInsertRow({ idMode: "autoId", data: data, now: now, beflyMode: this.beflyMode });
257
257
  });
258
258
  } else {
259
259
  const nextIds = [];
@@ -264,7 +264,7 @@ export const dataOpsMethods = {
264
264
  processedList = dataList.map((data, index) => {
265
265
  const id = nextIds[index];
266
266
  validateGeneratedBatchId(id, snakeTable, index);
267
- return buildInsertRow({ idMode: "timeId", data: data, id: id, now: now });
267
+ return buildInsertRow({ idMode: "timeId", data: data, id: id, now: now, beflyMode: this.beflyMode });
268
268
  });
269
269
  }
270
270
 
@@ -383,10 +383,10 @@ export const dataOpsMethods = {
383
383
  rows: processedList,
384
384
  fields: fields,
385
385
  quoteIdent: quoteIdentMySql,
386
- updatedAtField: "updated_at",
387
- updatedAtValue: now,
386
+ updatedAtField: this.beflyMode === 1 ? "updated_at" : "",
387
+ updatedAtValue: this.beflyMode === 1 ? now : null,
388
388
  stateField: "state",
389
- stateGtZero: true
389
+ stateGtZero: this.beflyMode === 1
390
390
  });
391
391
 
392
392
  const executeRes = await this.execute(query.sql, query.params);
@@ -404,8 +404,8 @@ export const dataOpsMethods = {
404
404
  const snakeTable = snakeCase(table);
405
405
  const snakeWhere = whereKeysToSnake(clearDeep(where));
406
406
 
407
- const processed = buildUpdateRow({ data: data, now: Date.now(), allowState: true });
408
- const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.enableStateFilter);
407
+ const processed = buildUpdateRow({ data: data, now: Date.now(), allowState: true, beflyMode: this.beflyMode });
408
+ const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
409
409
  const builder = this.createSqlBuilder().where(whereFiltered);
410
410
  const { sql, params } = builder.toUpdateSql(snakeTable, processed);
411
411
 
@@ -423,7 +423,7 @@ export const dataOpsMethods = {
423
423
 
424
424
  return await this.updData({
425
425
  table: table,
426
- data: { state: 0, deleted_at: Date.now() },
426
+ data: this.beflyMode === 1 ? { state: 0, deleted_at: Date.now() } : { state: 0 },
427
427
  where: where
428
428
  });
429
429
  },
@@ -478,7 +478,7 @@ export const dataOpsMethods = {
478
478
  const snakeField = snakeCase(field);
479
479
 
480
480
  const snakeWhere = whereKeysToSnake(clearDeep(where));
481
- const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.enableStateFilter);
481
+ const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
482
482
  const builder = this.createSqlBuilder().where(whereFiltered);
483
483
  const { sql: whereClause, params: whereParams } = builder.getWhereConditions();
484
484
 
@@ -19,7 +19,7 @@ function DbHelper(options) {
19
19
  this.sql = options.sql || null;
20
20
  this.isTransaction = Boolean(options.sql);
21
21
  this.idMode = options.idMode === "autoId" ? "autoId" : "timeId";
22
- this.enableStateFilter = options.stateFilter === 0 ? false : true;
22
+ this.beflyMode = options.beflyMode === 0 ? 0 : 1;
23
23
  }
24
24
 
25
25
  Object.assign(DbHelper.prototype, builderMethods, executeMethods, dataOpsMethods, transactionMethods);
@@ -26,7 +26,7 @@ export const transactionMethods = {
26
26
 
27
27
  try {
28
28
  return await sql.begin(async (tx) => {
29
- const trans = new this.constructor({ redis: this.redis, dbName: this.dbName, sql: tx, idMode: this.idMode, stateFilter: this.enableStateFilter ? 1 : 0 });
29
+ const trans = new this.constructor({ redis: this.redis, dbName: this.dbName, sql: tx, idMode: this.idMode, beflyMode: this.beflyMode });
30
30
  const result = await callback(trans);
31
31
  if (isBeflyResponse(result) && result.code !== 0) {
32
32
  throw new TransAbortError(result);
@@ -97,8 +97,10 @@ export function toUpdateCaseByIdSql(options) {
97
97
  setSqlList.push(`${quotedField} = CASE ${quotedId} ${whenList.join(" ")} ELSE ${quotedField} END`);
98
98
  }
99
99
 
100
- setSqlList.push(`${options.quoteIdent(options.updatedAtField)} = ?`);
101
- args.push(options.updatedAtValue);
100
+ if (isNonEmptyString(options.updatedAtField)) {
101
+ setSqlList.push(`${options.quoteIdent(options.updatedAtField)} = ?`);
102
+ args.push(options.updatedAtValue);
103
+ }
102
104
 
103
105
  for (const id of ids) {
104
106
  args.push(id);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.18.17",
4
- "gitHead": "6bb80da8ad441667bca408c328e11ad37d858754",
3
+ "version": "3.18.18",
4
+ "gitHead": "f6704475f6922c4f758a93a97872363bbaeaa940",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
7
7
  "keywords": [
package/plugins/mysql.js CHANGED
@@ -20,7 +20,7 @@ export default {
20
20
  dbName: befly.config?.mysql?.database,
21
21
  sql: Connect.getMysql(),
22
22
  idMode: befly.config?.mysql?.idMode,
23
- stateFilter: befly.config?.mysql?.stateFilter
23
+ beflyMode: befly.config?.mysql?.beflyMode
24
24
  });
25
25
 
26
26
  return dbManager;
@@ -68,7 +68,7 @@ export async function prepareSyncDbBaseContext(mysqlConfig) {
68
68
  dbName: mysqlConfig.database,
69
69
  sql: Connect.getMysql(),
70
70
  idMode: mysqlConfig.idMode,
71
- stateFilter: mysqlConfig.stateFilter
71
+ beflyMode: mysqlConfig.beflyMode
72
72
  });
73
73
 
74
74
  const dbColumns = await querySyncDbColumns(mysql);