@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 +116 -1
- package/dist/index.cjs +513 -43
- package/dist/index.d.cts +56 -3
- package/dist/index.d.ts +56 -3
- package/dist/index.js +510 -42
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -3,13 +3,15 @@ import { JSONSchema7 } from 'json-schema';
|
|
|
3
3
|
/**
|
|
4
4
|
* Valid Forman Schema field types
|
|
5
5
|
*/
|
|
6
|
-
type FormanSchemaFieldType = 'account' | 'hook' | 'keychain' | 'datastore' | '
|
|
6
|
+
type FormanSchemaFieldType = 'aiagent' | 'account' | 'hook' | 'keychain' | 'datastore' | 'udt' | 'array' | 'collection' | 'text' | 'number' | 'boolean' | 'date' | 'json' | 'buffer' | 'cert' | 'color' | 'email' | 'filename' | 'file' | 'folder' | 'hidden' | 'integer' | 'uinteger' | 'path' | 'pkey' | 'port' | 'select' | 'time' | 'timestamp' | 'timezone' | 'url' | 'uuid' | `account:${string}` | `hook:${string}` | `keychain:${string}` | 'banner' | 'markdown' | 'html' | 'separator' | string;
|
|
7
7
|
/**
|
|
8
8
|
* Validation configuration for Forman Schema fields
|
|
9
9
|
*/
|
|
10
10
|
interface FormanSchemaValidation {
|
|
11
11
|
/** Pattern for string validation */
|
|
12
|
-
pattern?: string
|
|
12
|
+
pattern?: string | {
|
|
13
|
+
regexp: string;
|
|
14
|
+
};
|
|
13
15
|
/** Minimum value */
|
|
14
16
|
min?: number;
|
|
15
17
|
/** Maximum value */
|
|
@@ -53,6 +55,8 @@ type FormanSchemaField = {
|
|
|
53
55
|
mappable?: boolean;
|
|
54
56
|
/** Whether the user will be able to insert new lines in GUI (a textarea will be displayed instead of the text field) */
|
|
55
57
|
multiline?: boolean;
|
|
58
|
+
/** Whether the select field allows multiple values */
|
|
59
|
+
multiple?: boolean;
|
|
56
60
|
/** Specifies how to treat HTML tags in the field (text only) */
|
|
57
61
|
tags?: 'strip' | 'stripall' | 'escape';
|
|
58
62
|
/** Allowed extension or array of allowed extensions. (filename only) */
|
|
@@ -121,6 +125,15 @@ type FormanSchemaExtendedOptions = {
|
|
|
121
125
|
store: FormanSchemaOption[] | FormanSchemaOptionGroup[] | string;
|
|
122
126
|
/** Nested fields for every option */
|
|
123
127
|
nested?: FormanSchemaNested;
|
|
128
|
+
/** Name of the property as the label of an option */
|
|
129
|
+
label?: string;
|
|
130
|
+
/** Name of the property as the value of an option */
|
|
131
|
+
value?: string;
|
|
132
|
+
/** Label to display when no value is selected */
|
|
133
|
+
placeholder?: string | {
|
|
134
|
+
label: string;
|
|
135
|
+
nested?: FormanSchemaNested;
|
|
136
|
+
};
|
|
124
137
|
};
|
|
125
138
|
/**
|
|
126
139
|
* Nested fields
|
|
@@ -135,6 +148,28 @@ type FormanSchemaExtendedNested = {
|
|
|
135
148
|
/** Domain for the nested fields */
|
|
136
149
|
domain?: string;
|
|
137
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* Validation result
|
|
153
|
+
*/
|
|
154
|
+
type FormanValidationResult = {
|
|
155
|
+
/** Whether the object is valid */
|
|
156
|
+
valid: boolean;
|
|
157
|
+
/** Errors */
|
|
158
|
+
errors: {
|
|
159
|
+
/** Field domain */
|
|
160
|
+
domain: string;
|
|
161
|
+
/** Field path */
|
|
162
|
+
path: string;
|
|
163
|
+
/** Error message */
|
|
164
|
+
message: string;
|
|
165
|
+
}[];
|
|
166
|
+
};
|
|
167
|
+
type FormanValidationOptions = {
|
|
168
|
+
/** Unknown fields are not allowed when strict is true */
|
|
169
|
+
strict?: boolean;
|
|
170
|
+
/** Remote resource resolver */
|
|
171
|
+
resolveRemote?(path: string, data: Record<string, unknown>): Promise<unknown>;
|
|
172
|
+
};
|
|
138
173
|
|
|
139
174
|
/**
|
|
140
175
|
* Converts a JSON Schema field to its Forman Schema equivalent.
|
|
@@ -149,5 +184,23 @@ declare function toFormanSchema(field: JSONSchema7): FormanSchemaField;
|
|
|
149
184
|
* @returns The equivalent JSON Schema field
|
|
150
185
|
*/
|
|
151
186
|
declare function toJSONSchema(field: FormanSchemaField): JSONSchema7;
|
|
187
|
+
/**
|
|
188
|
+
* Validates a Forman domains against schemas
|
|
189
|
+
* @param domains The domains to validate
|
|
190
|
+
* @param options The validation options
|
|
191
|
+
* @returns The validation result
|
|
192
|
+
*/
|
|
193
|
+
declare function validateFormanWithDomains(domains: Record<string, {
|
|
194
|
+
values: Record<string, unknown>;
|
|
195
|
+
schema: FormanSchemaField[];
|
|
196
|
+
}>, options?: FormanValidationOptions): Promise<FormanValidationResult>;
|
|
197
|
+
/**
|
|
198
|
+
* Validates a simple Forman values against a schema
|
|
199
|
+
* @param values The values to validate
|
|
200
|
+
* @param schema The schema to validate against
|
|
201
|
+
* @param options The validation options
|
|
202
|
+
* @returns The validation result
|
|
203
|
+
*/
|
|
204
|
+
declare function validateForman(values: Record<string, unknown>, schema: FormanSchemaField[], options?: FormanValidationOptions): Promise<FormanValidationResult>;
|
|
152
205
|
|
|
153
|
-
export { type FormanSchemaExtendedNested, type FormanSchemaExtendedOptions, type FormanSchemaField, type FormanSchemaFieldType, type FormanSchemaNested, type FormanSchemaOption, type FormanSchemaOptionGroup, type FormanSchemaRPCButton, type FormanSchemaValue, toFormanSchema, toJSONSchema };
|
|
206
|
+
export { type FormanSchemaExtendedNested, type FormanSchemaExtendedOptions, type FormanSchemaField, type FormanSchemaFieldType, type FormanSchemaNested, type FormanSchemaOption, type FormanSchemaOptionGroup, type FormanSchemaRPCButton, type FormanSchemaValue, toFormanSchema, toJSONSchema, validateForman, validateFormanWithDomains };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,15 @@ import { JSONSchema7 } from 'json-schema';
|
|
|
3
3
|
/**
|
|
4
4
|
* Valid Forman Schema field types
|
|
5
5
|
*/
|
|
6
|
-
type FormanSchemaFieldType = 'account' | 'hook' | 'keychain' | 'datastore' | '
|
|
6
|
+
type FormanSchemaFieldType = 'aiagent' | 'account' | 'hook' | 'keychain' | 'datastore' | 'udt' | 'array' | 'collection' | 'text' | 'number' | 'boolean' | 'date' | 'json' | 'buffer' | 'cert' | 'color' | 'email' | 'filename' | 'file' | 'folder' | 'hidden' | 'integer' | 'uinteger' | 'path' | 'pkey' | 'port' | 'select' | 'time' | 'timestamp' | 'timezone' | 'url' | 'uuid' | `account:${string}` | `hook:${string}` | `keychain:${string}` | 'banner' | 'markdown' | 'html' | 'separator' | string;
|
|
7
7
|
/**
|
|
8
8
|
* Validation configuration for Forman Schema fields
|
|
9
9
|
*/
|
|
10
10
|
interface FormanSchemaValidation {
|
|
11
11
|
/** Pattern for string validation */
|
|
12
|
-
pattern?: string
|
|
12
|
+
pattern?: string | {
|
|
13
|
+
regexp: string;
|
|
14
|
+
};
|
|
13
15
|
/** Minimum value */
|
|
14
16
|
min?: number;
|
|
15
17
|
/** Maximum value */
|
|
@@ -53,6 +55,8 @@ type FormanSchemaField = {
|
|
|
53
55
|
mappable?: boolean;
|
|
54
56
|
/** Whether the user will be able to insert new lines in GUI (a textarea will be displayed instead of the text field) */
|
|
55
57
|
multiline?: boolean;
|
|
58
|
+
/** Whether the select field allows multiple values */
|
|
59
|
+
multiple?: boolean;
|
|
56
60
|
/** Specifies how to treat HTML tags in the field (text only) */
|
|
57
61
|
tags?: 'strip' | 'stripall' | 'escape';
|
|
58
62
|
/** Allowed extension or array of allowed extensions. (filename only) */
|
|
@@ -121,6 +125,15 @@ type FormanSchemaExtendedOptions = {
|
|
|
121
125
|
store: FormanSchemaOption[] | FormanSchemaOptionGroup[] | string;
|
|
122
126
|
/** Nested fields for every option */
|
|
123
127
|
nested?: FormanSchemaNested;
|
|
128
|
+
/** Name of the property as the label of an option */
|
|
129
|
+
label?: string;
|
|
130
|
+
/** Name of the property as the value of an option */
|
|
131
|
+
value?: string;
|
|
132
|
+
/** Label to display when no value is selected */
|
|
133
|
+
placeholder?: string | {
|
|
134
|
+
label: string;
|
|
135
|
+
nested?: FormanSchemaNested;
|
|
136
|
+
};
|
|
124
137
|
};
|
|
125
138
|
/**
|
|
126
139
|
* Nested fields
|
|
@@ -135,6 +148,28 @@ type FormanSchemaExtendedNested = {
|
|
|
135
148
|
/** Domain for the nested fields */
|
|
136
149
|
domain?: string;
|
|
137
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* Validation result
|
|
153
|
+
*/
|
|
154
|
+
type FormanValidationResult = {
|
|
155
|
+
/** Whether the object is valid */
|
|
156
|
+
valid: boolean;
|
|
157
|
+
/** Errors */
|
|
158
|
+
errors: {
|
|
159
|
+
/** Field domain */
|
|
160
|
+
domain: string;
|
|
161
|
+
/** Field path */
|
|
162
|
+
path: string;
|
|
163
|
+
/** Error message */
|
|
164
|
+
message: string;
|
|
165
|
+
}[];
|
|
166
|
+
};
|
|
167
|
+
type FormanValidationOptions = {
|
|
168
|
+
/** Unknown fields are not allowed when strict is true */
|
|
169
|
+
strict?: boolean;
|
|
170
|
+
/** Remote resource resolver */
|
|
171
|
+
resolveRemote?(path: string, data: Record<string, unknown>): Promise<unknown>;
|
|
172
|
+
};
|
|
138
173
|
|
|
139
174
|
/**
|
|
140
175
|
* Converts a JSON Schema field to its Forman Schema equivalent.
|
|
@@ -149,5 +184,23 @@ declare function toFormanSchema(field: JSONSchema7): FormanSchemaField;
|
|
|
149
184
|
* @returns The equivalent JSON Schema field
|
|
150
185
|
*/
|
|
151
186
|
declare function toJSONSchema(field: FormanSchemaField): JSONSchema7;
|
|
187
|
+
/**
|
|
188
|
+
* Validates a Forman domains against schemas
|
|
189
|
+
* @param domains The domains to validate
|
|
190
|
+
* @param options The validation options
|
|
191
|
+
* @returns The validation result
|
|
192
|
+
*/
|
|
193
|
+
declare function validateFormanWithDomains(domains: Record<string, {
|
|
194
|
+
values: Record<string, unknown>;
|
|
195
|
+
schema: FormanSchemaField[];
|
|
196
|
+
}>, options?: FormanValidationOptions): Promise<FormanValidationResult>;
|
|
197
|
+
/**
|
|
198
|
+
* Validates a simple Forman values against a schema
|
|
199
|
+
* @param values The values to validate
|
|
200
|
+
* @param schema The schema to validate against
|
|
201
|
+
* @param options The validation options
|
|
202
|
+
* @returns The validation result
|
|
203
|
+
*/
|
|
204
|
+
declare function validateForman(values: Record<string, unknown>, schema: FormanSchemaField[], options?: FormanValidationOptions): Promise<FormanValidationResult>;
|
|
152
205
|
|
|
153
|
-
export { type FormanSchemaExtendedNested, type FormanSchemaExtendedOptions, type FormanSchemaField, type FormanSchemaFieldType, type FormanSchemaNested, type FormanSchemaOption, type FormanSchemaOptionGroup, type FormanSchemaRPCButton, type FormanSchemaValue, toFormanSchema, toJSONSchema };
|
|
206
|
+
export { type FormanSchemaExtendedNested, type FormanSchemaExtendedOptions, type FormanSchemaField, type FormanSchemaFieldType, type FormanSchemaNested, type FormanSchemaOption, type FormanSchemaOptionGroup, type FormanSchemaRPCButton, type FormanSchemaValue, toFormanSchema, toJSONSchema, validateForman, validateFormanWithDomains };
|