@makehq/forman-schema 1.2.5 → 1.3.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Forman Schema
2
2
 
3
- A utility for converting between Forman Schema and JSON Schema.
3
+ Conversion and validation utilities for Forman Schema.
4
4
 
5
5
  ## Installation
6
6
 
@@ -54,6 +54,121 @@ const jsonSchemaField = {
54
54
  const formanSchema = toFormanSchema(jsonSchemaField);
55
55
  ```
56
56
 
57
+ ### Validation
58
+
59
+ Validate Forman values against a Forman Schema. Two entry points are available:
60
+
61
+ - `validateForman(values, schema, options?)` — validate without domains.
62
+ - `validateFormanWithDomains(domains, options?)` — validate multiple domains at once.
63
+
64
+ Both return `{ valid: boolean, errors: { path: string, message: string }[] }`.
65
+
66
+ #### Basic validation
67
+
68
+ ```typescript
69
+ import { validateForman } from '@makehq/forman-schema';
70
+
71
+ const values = { array: [1, 2, 3], text: 'hello' };
72
+ const schema = [
73
+ { name: 'array', type: 'array', spec: { type: 'number' } },
74
+ { name: 'text', type: 'text' },
75
+ ];
76
+
77
+ const result = await validateForman(values, schema);
78
+ // { valid: true, errors: [] }
79
+ ```
80
+
81
+ #### Strict mode (unknown fields)
82
+
83
+ ```typescript
84
+ const values = { text: 15, unknown: true };
85
+ const schema = [
86
+ {
87
+ name: 'text',
88
+ type: 'text',
89
+ },
90
+ ];
91
+
92
+ const result = await validateForman(values, schema, { strict: true });
93
+ // {
94
+ // valid: false,
95
+ // errors: [
96
+ // { path: 'default.text', message: "Expected type 'string', got type 'number'" },
97
+ // { path: 'default', message: "Unknown field 'unknown'" }
98
+ // ]
99
+ // }
100
+ ```
101
+
102
+ #### Select with nested fields
103
+
104
+ ```typescript
105
+ const values = { sheet: 'sheet 1', row: 1 };
106
+ const schema = [
107
+ {
108
+ name: 'sheet',
109
+ type: 'select',
110
+ options: [
111
+ { value: 'sheet 1', nested: [{ name: 'row', type: 'number', required: true }] },
112
+ { value: 'sheet 2' },
113
+ ],
114
+ },
115
+ ];
116
+
117
+ const result = await validateForman(values, schema);
118
+ ```
119
+
120
+ #### Remote options and nested stores
121
+
122
+ You can resolve options or nested field stores by providing `resolveRemote(path, data)`.
123
+
124
+ ```typescript
125
+ const values = { sheet: 'sheet 1', column: 'A1' };
126
+ const schema = [
127
+ {
128
+ name: 'sheet',
129
+ type: 'select',
130
+ options: {
131
+ store: 'rpc://sheets',
132
+ nested: [{ name: 'column', type: 'select', options: 'rpc://columns' }],
133
+ },
134
+ },
135
+ ];
136
+
137
+ const result = await validateForman(values, schema, {
138
+ async resolveRemote(path, data) {
139
+ if (path === 'rpc://sheets') return [{ value: 'sheet 1' }, { value: 'sheet 2' }];
140
+ if (path === 'rpc://columns') return [{ value: 'A1' }, { value: 'B1' }];
141
+ throw new Error('Unknown resource');
142
+ },
143
+ });
144
+ ```
145
+
146
+ #### Multi-domain validation
147
+
148
+ Use `validateFormanWithDomains` to validate cross-domain schemas (e.g., `default` and `additional`).
149
+
150
+ ```typescript
151
+ import { validateFormanWithDomains } from '@makehq/forman-schema';
152
+
153
+ const result = await validateFormanWithDomains(
154
+ {
155
+ default: {
156
+ values: { ... },
157
+ schema: defaultSchema
158
+ },
159
+ additional: {
160
+ values: { ... },
161
+ schema: additionalSchema
162
+ },
163
+ },
164
+ {
165
+ async resolveRemote(path, data) {
166
+ // resolve API-backed options/nested fields here
167
+ },
168
+ },
169
+ );
170
+ ```
171
+
57
172
  ## Supported Types
58
173
 
59
174
  ### Forman Schema Types