bank20baht-validator 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -39,13 +39,14 @@ export function validateFormData(form, input, registry) {
39
39
  return { valid: false, issues: [{ ref: '$', message: 'data must be an object' }], data: {} };
40
40
  }
41
41
  const issues = [];
42
+ const fields = sorted(form.field_data).filter((f) => f.type !== 'label');
43
+ // canonical data first, so compare validators see every sibling
42
44
  const data = {};
43
- for (const field of sorted(form.field_data)) {
44
- if (field.type === 'label')
45
- continue;
46
- const value = field.key in input ? input[field.key] : defaultValue(field);
47
- data[field.key] = value;
48
- for (const err of validateField(field, value, registry)) {
45
+ for (const field of fields) {
46
+ data[field.key] = field.key in input ? input[field.key] : defaultValue(field);
47
+ }
48
+ for (const field of fields) {
49
+ for (const err of validateField(field, data[field.key], registry, data)) {
49
50
  issues.push({ ref: err.key, message: err.message });
50
51
  }
51
52
  }
@@ -89,8 +90,8 @@ export function validateWorkflowData(workflow, input, registry) {
89
90
  continue; // hidden fields excluded (spec 02 §5)
90
91
  const required = state ? state.required : !!field.required;
91
92
  const descriptor = required === !!field.required ? field : { ...field, required };
92
- const value = derived.data[form.formName]?.[field.key];
93
- for (const err of validateField(descriptor, value, registry)) {
93
+ const formData = derived.data[form.formName] ?? {};
94
+ for (const err of validateField(descriptor, formData[field.key], registry, formData)) {
94
95
  issues.push({ ref, message: err.message });
95
96
  }
96
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bank20baht-validator",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "Runtime validation for bahtui form/workflow JSON — the exact engine rules the client runs, on the server.",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "test:watch": "vitest"
40
40
  },
41
41
  "dependencies": {
42
- "bank20baht-ui": "^0.0.7"
42
+ "bank20baht-ui": "^0.0.8"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.8.3",