bank20baht-validator 0.0.2 → 0.0.4

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, validateField, type FormDefinition, type NestedData, type Registry, type WorkflowDefinition, type WorkflowForm } from 'bank20baht-ui/engine';
1
+ import { applyFlags, approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, validateField, type FormDefinition, type NestedData, type Registry, type WorkflowDefinition, type WorkflowForm } from 'bank20baht-ui/engine';
2
2
  export type SchemaDefinition = FormDefinition | WorkflowDefinition;
3
3
  /** One violation. `ref` is the field key for forms, `formName.key` for workflows. */
4
4
  export interface ValidationIssue {
@@ -46,6 +46,6 @@ export declare function validateSubmission(schema: SchemaDefinition, data: unkno
46
46
  * render. Throws with a human-readable message on bad input.
47
47
  */
48
48
  export declare function parseSchema(json: unknown): SchemaDefinition;
49
- export { approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, validateField };
49
+ export { applyFlags, approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, validateField, };
50
50
  export type { FormDefinition, NestedData, Registry, WorkflowDefinition, WorkflowForm };
51
- export type { FormViewSpec, Locale, MessageCatalog } from 'bank20baht-ui/engine';
51
+ export type { FeatureFlags, FormViewSpec, Locale, MessageCatalog } from 'bank20baht-ui/engine';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  // request that bypasses the frontend hits the exact same rules — no codegen,
8
8
  // no recompile: swap the stored JSON and validation follows.
9
9
  // ---------------------------------------------------------------------------
10
- import { approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, t, validateField, } from 'bank20baht-ui/engine';
10
+ import { applyFlags, approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, t, validateField, } from 'bank20baht-ui/engine';
11
11
  export function isWorkflowDefinition(schema) {
12
12
  return (isRecord(schema) &&
13
13
  typeof schema['workflowId'] === 'string' &&
@@ -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
  }
@@ -216,5 +217,7 @@ function assertValidViews(form) {
216
217
  }
217
218
  // Re-exported so servers can type stores and registries without a direct
218
219
  // dependency on bank20baht-ui. `setLocale` localizes the issues this package
219
- // emits (same catalog the client renders).
220
- export { approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, validateField };
220
+ // emits (same catalog the client renders). `applyFlags` resolves feature
221
+ // flags server-side — validate flag-gated schemas as
222
+ // `validateSubmission(applyFlags(schema, flags), data)`.
223
+ export { applyFlags, approvalFields, defaultValue, evaluate, resolveViewFields, setLocale, validateField, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bank20baht-validator",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
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.10"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.8.3",