@posx/core 5.5.568 → 5.5.570

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.
@@ -0,0 +1,37 @@
1
+ # Boolean 字段默认值设计陷阱
2
+
3
+ **日期:** 2026-05-06
4
+ **类型:** 设计审查
5
+ **严重程度:** 高(若未发现会导致生产事故)
6
+
7
+ ## 问题描述
8
+
9
+ 在为 Category 和 Item 添加 `is_searchable` 字段时,若设计为:
10
+ - `is_searchable: boolean` 默认 `true`
11
+
12
+ 会导致兼容性问题:
13
+ - 现有数据库记录没有此字段
14
+ - JavaScript 读取时值为 `undefined`
15
+ - `undefined` 是 falsy,逻辑上等同于 `false`
16
+ - **结果:所有现有 item/category 突然变得不可搜索**
17
+
18
+ ## 正确方案
19
+
20
+ 使用**反向布尔字段**:`is_not_searchable`
21
+ - 默认值:`false`(可搜索)
22
+ - 现有数据无此字段 = `undefined` = falsy = 可搜索
23
+ - 显式设为 `true` 才会排除搜索
24
+
25
+ ## 通用规则
26
+
27
+ 新增布尔字段时,确保:
28
+ - `undefined`/缺失值 = 系统原有行为
29
+ - 新行为需要显式设置 `true`
30
+
31
+ **命名模式:**
32
+ - 原行为是 X → 新字段应为 `is_not_X` 或 `disable_X`
33
+ - 这样 `undefined` = 保持原行为
34
+
35
+ ## 相关文件
36
+
37
+ - `src/types/product.type.ts` - ICategory, IItem 接口
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.568",
3
+ "version": "5.5.570",
4
4
  "description": "POSX core libraries",
5
5
  "main": "./build/index.js",
6
6
  "author": "Steven Lee",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.568",
3
+ "version": "5.5.570",
4
4
  "description": "POSX core libraries",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",