@nocobase/flow-engine 2.0.48 → 2.0.50

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.
@@ -778,7 +778,17 @@ const _CollectionField = class _CollectionField {
778
778
  abortEarly: false
779
779
  });
780
780
  if (error) {
781
- const message = error.details.map((d) => d.message.replace(/"value"/g, `"${label}"`)).join(", ");
781
+ const message = error.details.map((d) => {
782
+ const translated = this.flowEngine.translate(d.type, {
783
+ ...d.context,
784
+ ns: "data-source-main",
785
+ label
786
+ });
787
+ if (translated && translated !== d.type) {
788
+ return translated;
789
+ }
790
+ return d.message.replace(/"value"/g, `"${label}"`);
791
+ }).join(", ");
782
792
  return Promise.reject(message);
783
793
  }
784
794
  return Promise.resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.0.48",
3
+ "version": "2.0.50",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.0.48",
12
- "@nocobase/shared": "2.0.48",
11
+ "@nocobase/sdk": "2.0.50",
12
+ "@nocobase/shared": "2.0.50",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "9a7e1e19953b501dedce4526a7231ea6c74dfa98"
40
+ "gitHead": "cd183287e7be7bb75349ad91a006f5fa53993962"
41
41
  }
@@ -79,4 +79,38 @@ describe('DataSource & Collection APIs', () => {
79
79
  ]),
80
80
  ).toThrow(/circular/);
81
81
  });
82
+
83
+ it('translates validation messages from data-source-main in component rules', async () => {
84
+ const { m, engine } = makeManager();
85
+ engine.context.i18n = {
86
+ t: (key: string, options?: Record<string, any>) => {
87
+ if (key === 'string.length' && options?.ns === 'data-source-main') {
88
+ return `${options.label} 长度必须为 ${options.limit} 个字符`;
89
+ }
90
+ return key;
91
+ },
92
+ } as any;
93
+
94
+ const ds = new DataSource({ key: 'main' });
95
+ m.addDataSource(ds);
96
+ ds.addCollection({
97
+ name: 'posts',
98
+ fields: [
99
+ {
100
+ name: 'title',
101
+ type: 'string',
102
+ interface: 'text',
103
+ title: '单行文本',
104
+ validation: {
105
+ type: 'string',
106
+ rules: [{ name: 'length', args: { limit: 18 } }],
107
+ },
108
+ },
109
+ ],
110
+ });
111
+
112
+ const rules = ds.getCollection('posts')!.getField('title')!.getComponentProps().rules;
113
+
114
+ await expect(rules[0].validator({}, '123')).rejects.toBe('单行文本 长度必须为 18 个字符');
115
+ });
82
116
  });
@@ -862,7 +862,21 @@ export class CollectionField {
862
862
  });
863
863
 
864
864
  if (error) {
865
- const message = error.details.map((d: any) => d.message.replace(/"value"/g, `"${label}"`)).join(', ');
865
+ const message = error.details
866
+ .map((d: any) => {
867
+ const translated = this.flowEngine.translate(d.type, {
868
+ ...d.context,
869
+ ns: 'data-source-main',
870
+ label,
871
+ });
872
+
873
+ if (translated && translated !== d.type) {
874
+ return translated;
875
+ }
876
+
877
+ return d.message.replace(/"value"/g, `"${label}"`);
878
+ })
879
+ .join(', ');
866
880
  return Promise.reject(message);
867
881
  }
868
882