schema-dsl 1.1.4 → 1.1.5

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.
@@ -17,6 +17,7 @@ module.exports = {
17
17
  'conditional.blocked': '账号已被封禁',
18
18
  'conditional.notAllowed': '不允许注册',
19
19
 
20
+ // I18nError - 通用错误消息 (v1.1.1)
20
21
  // I18nError - 通用错误消息 (v1.1.1)
21
22
  'error.notFound': '找不到{{#resource}}',
22
23
  'error.forbidden': '没有权限访问{{#resource}}',
@@ -26,10 +27,17 @@ module.exports = {
26
27
  'error.conflict': '操作冲突: {{#reason}}',
27
28
 
28
29
  // I18nError - 账户相关 (v1.1.1)
29
- 'account.notFound': '账户不存在',
30
+ // v1.1.5: 部分使用对象格式示例
31
+ 'account.notFound': {
32
+ code: 'ACCOUNT_NOT_FOUND',
33
+ message: '账户不存在'
34
+ },
30
35
  'account.inactive': '账户未激活',
31
36
  'account.banned': '账户已被封禁',
32
- 'account.insufficientBalance': '余额不足,当前余额{{#balance}},需要{{#required}}',
37
+ 'account.insufficientBalance': {
38
+ code: 'INSUFFICIENT_BALANCE',
39
+ message: '余额不足,当前余额{{#balance}},需要{{#required}}'
40
+ },
33
41
  'account.insufficientCredits': '积分不足,当前积分{{#credits}},需要{{#required}}',
34
42
 
35
43
  // I18nError - 用户相关 (v1.1.1)
@@ -38,7 +46,10 @@ module.exports = {
38
46
  'user.noPermission': '没有管理员权限',
39
47
 
40
48
  // I18nError - 订单相关 (v1.1.1)
41
- 'order.notPaid': '订单未支付',
49
+ 'order.notPaid': {
50
+ code: 'ORDER_NOT_PAID',
51
+ message: '订单未支付'
52
+ },
42
53
  'order.paymentMissing': '缺少支付信息',
43
54
  'order.addressMissing': '缺少收货地址',
44
55
 
@@ -90,12 +90,20 @@ class CustomKeywords {
90
90
  // ajv 默认不支持同步验证中的异步操作
91
91
  // 这里我们只能抛出错误提示
92
92
  // 真正的异步支持需要 Validator.validateAsync
93
- throw new Error(Locale.getMessage('ASYNC_VALIDATION_NOT_SUPPORTED'));
93
+ const messageConfig = Locale.getMessage('ASYNC_VALIDATION_NOT_SUPPORTED');
94
+ const errorMessage = typeof messageConfig === 'object' && messageConfig.message
95
+ ? messageConfig.message
96
+ : messageConfig;
97
+ throw new Error(errorMessage);
94
98
  }
95
99
 
96
100
  // 处理返回值
97
101
  if (result === false) {
98
- validate.errors = [{ message: Locale.getMessage('CUSTOM_VALIDATION_FAILED') }];
102
+ const messageConfig = Locale.getMessage('CUSTOM_VALIDATION_FAILED');
103
+ const errorMessage = typeof messageConfig === 'object' && messageConfig.message
104
+ ? messageConfig.message
105
+ : messageConfig;
106
+ validate.errors = [{ message: errorMessage }];
99
107
  return false;
100
108
  }
101
109
  if (typeof result === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-dsl",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "简洁强大的JSON Schema验证库 - DSL语法 + String扩展 + 便捷validate",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",