@nocobase/flow-engine 2.3.0-beta.10 → 2.3.0-beta.11
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.
|
@@ -94,7 +94,15 @@ function jioToJoiSchema(jioConfig) {
|
|
|
94
94
|
if (name === "required") hasRequired = true;
|
|
95
95
|
if (typeof schema[name] === "function") {
|
|
96
96
|
try {
|
|
97
|
-
|
|
97
|
+
if (jioConfig.type === "number" && name === "precision") {
|
|
98
|
+
const precisionSchema = import_joi.default.number().precision(getArgs(name, args)[0]).strict();
|
|
99
|
+
schema = schema.custom((value, helpers) => {
|
|
100
|
+
const { error } = precisionSchema.validate(value);
|
|
101
|
+
return error ? helpers.error("number.precision", error.details[0].context) : value;
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
schema = schema[name](...getArgs(name, args));
|
|
105
|
+
}
|
|
98
106
|
} catch (err) {
|
|
99
107
|
console.warn(`\u8C03\u7528 Joi \u65B9\u6CD5 ${name} \u5931\u8D25:`, err);
|
|
100
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/flow-engine",
|
|
3
|
-
"version": "2.3.0-beta.
|
|
3
|
+
"version": "2.3.0-beta.11",
|
|
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.3.0-beta.
|
|
12
|
-
"@nocobase/shared": "2.3.0-beta.
|
|
11
|
+
"@nocobase/sdk": "2.3.0-beta.11",
|
|
12
|
+
"@nocobase/shared": "2.3.0-beta.11",
|
|
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": "
|
|
40
|
+
"gitHead": "e81c2c69d55f13e4d237c420a51ebad1e9dae515"
|
|
41
41
|
}
|
|
@@ -114,6 +114,34 @@ describe('DataSource & Collection APIs', () => {
|
|
|
114
114
|
await expect(rules[0].validator({}, '123')).rejects.toBe('单行文本 长度必须为 18 个字符');
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
it('enforces collection field precision in component validation rules', async () => {
|
|
118
|
+
const { m, engine } = makeManager();
|
|
119
|
+
const translate = vi.spyOn(engine, 'translate').mockImplementation((key) => key);
|
|
120
|
+
const ds = new DataSource({ key: 'main' });
|
|
121
|
+
m.addDataSource(ds);
|
|
122
|
+
ds.addCollection({
|
|
123
|
+
name: 'employees',
|
|
124
|
+
fields: [
|
|
125
|
+
{
|
|
126
|
+
name: 'years',
|
|
127
|
+
type: 'double',
|
|
128
|
+
interface: 'number',
|
|
129
|
+
title: 'Years',
|
|
130
|
+
validation: { type: 'number', rules: [{ name: 'precision', args: { limit: 2 } }] },
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
const rules = ds.getCollection('employees').getField('years').getComponentProps().rules;
|
|
135
|
+
|
|
136
|
+
await expect(rules[0].validator({}, 39.2234)).rejects.toContain('2 decimal places');
|
|
137
|
+
expect(translate).toHaveBeenCalledWith(
|
|
138
|
+
'number.precision',
|
|
139
|
+
expect.objectContaining({ ns: 'data-source-main', label: 'Years', limit: 2 }),
|
|
140
|
+
);
|
|
141
|
+
await expect(rules[0].validator({}, 39.22)).resolves.toBeUndefined();
|
|
142
|
+
translate.mockRestore();
|
|
143
|
+
});
|
|
144
|
+
|
|
117
145
|
it('ensureLoaded, reload and data source events work for main loader', async () => {
|
|
118
146
|
const { m, engine } = makeManager();
|
|
119
147
|
const loadedListener = vi.fn();
|
|
@@ -49,6 +49,57 @@ describe('jioToJoiSchema', () => {
|
|
|
49
49
|
expect(s2.validate('zz').error).toBeTruthy();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
describe('number precision', () => {
|
|
53
|
+
const schema = jioToJoiSchema({ type: 'number', rules: [{ name: 'precision', args: { limit: 2 } }] });
|
|
54
|
+
|
|
55
|
+
it.each([39.2234, -39.2234, 0.001, 1e-7])('rejects %s without rounding', (value) => {
|
|
56
|
+
const result = schema.validate(value);
|
|
57
|
+
expect(result.error?.details[0]).toMatchObject({ type: 'number.precision', context: { limit: 2 } });
|
|
58
|
+
expect(result.value).toBe(value);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it.each([39.22, -39.22, 39.2, 39, 0, 0.01, '', null, undefined])('accepts %s', (value) => {
|
|
62
|
+
expect(schema.validate(value).error).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('supports zero precision', () => {
|
|
66
|
+
const integerSchema = jioToJoiSchema({ type: 'number', rules: [{ name: 'precision', args: { limit: 0 } }] });
|
|
67
|
+
expect(integerSchema.validate(39).error).toBeUndefined();
|
|
68
|
+
expect(integerSchema.validate(39.2).error?.details[0].type).toBe('number.precision');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('validates numeric strings without rounding them', () => {
|
|
72
|
+
expect(schema.validate('39.22')).toEqual({ value: 39.22 });
|
|
73
|
+
expect(schema.validate('39.2200')).toEqual({ value: 39.22 });
|
|
74
|
+
expect(schema.validate('39.2234').error?.details[0].type).toBe('number.precision');
|
|
75
|
+
expect(schema.validate('1e-7').error?.details[0].type).toBe('number.precision');
|
|
76
|
+
expect(schema.validate('not a number').error?.details[0].type).toBe('number.base');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('preserves required and min/max validation', () => {
|
|
80
|
+
const requiredSchema = jioToJoiSchema({
|
|
81
|
+
type: 'number',
|
|
82
|
+
rules: [
|
|
83
|
+
{ name: 'precision', args: { limit: 2 } },
|
|
84
|
+
{ name: 'min', args: { limit: 1 } },
|
|
85
|
+
{ name: 'max', args: { limit: 10 } },
|
|
86
|
+
{ name: 'required' },
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
expect(requiredSchema.validate(undefined).error?.details[0].type).toBe('any.required');
|
|
90
|
+
expect(requiredSchema.validate('').error).toBeDefined();
|
|
91
|
+
expect(requiredSchema.validate(null).error).toBeDefined();
|
|
92
|
+
expect(requiredSchema.validate(0.99).error?.details[0].type).toBe('number.min');
|
|
93
|
+
expect(requiredSchema.validate(10.01).error?.details[0].type).toBe('number.max');
|
|
94
|
+
expect(requiredSchema.validate(1.23).error).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('preserves numeric string conversion when precision is not configured', () => {
|
|
98
|
+
const numberSchema = jioToJoiSchema({ type: 'number', rules: [{ name: 'min', args: { limit: 1 } }] });
|
|
99
|
+
expect(numberSchema.validate('39.2234')).toEqual({ value: 39.2234 });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
52
103
|
it('optional when no required and allows empty string', () => {
|
|
53
104
|
const schema = jioToJoiSchema({ type: 'string' });
|
|
54
105
|
expect(schema.validate('').error).toBeUndefined();
|
|
@@ -85,7 +85,16 @@ export function jioToJoiSchema<T extends JioType>(jioConfig: {
|
|
|
85
85
|
if (name === 'required') hasRequired = true;
|
|
86
86
|
if (typeof schema[name] === 'function') {
|
|
87
87
|
try {
|
|
88
|
-
|
|
88
|
+
if (jioConfig.type === 'number' && name === 'precision') {
|
|
89
|
+
// Validate precision without rounding, while preserving the outer schema's numeric string conversion.
|
|
90
|
+
const precisionSchema = Joi.number().precision(getArgs(name, args)[0]).strict();
|
|
91
|
+
schema = schema.custom((value: number, helpers: Joi.CustomHelpers) => {
|
|
92
|
+
const { error } = precisionSchema.validate(value);
|
|
93
|
+
return error ? helpers.error('number.precision', error.details[0].context) : value;
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
schema = schema[name](...getArgs(name, args));
|
|
97
|
+
}
|
|
89
98
|
} catch (err) {
|
|
90
99
|
console.warn(`调用 Joi 方法 ${name} 失败:`, err);
|
|
91
100
|
}
|