@makehq/forman-schema 1.9.6 → 1.10.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/dist/index.cjs +50 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +50 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1066,6 +1066,47 @@ function extractNestedFromField(field) {
|
|
|
1066
1066
|
if (isObject(field.options) && field.options.nested) return field.options.nested;
|
|
1067
1067
|
return void 0;
|
|
1068
1068
|
}
|
|
1069
|
+
var SCHEMA_STRIP_KEYS = [
|
|
1070
|
+
"nested",
|
|
1071
|
+
"options",
|
|
1072
|
+
"help",
|
|
1073
|
+
"rpc",
|
|
1074
|
+
"sort",
|
|
1075
|
+
"disabled",
|
|
1076
|
+
"multiline",
|
|
1077
|
+
"tags",
|
|
1078
|
+
"extension",
|
|
1079
|
+
"codepage",
|
|
1080
|
+
"logic"
|
|
1081
|
+
];
|
|
1082
|
+
function clampFieldForSchema(field) {
|
|
1083
|
+
const clamped = { ...field };
|
|
1084
|
+
for (const key of SCHEMA_STRIP_KEYS) {
|
|
1085
|
+
delete clamped[key];
|
|
1086
|
+
}
|
|
1087
|
+
if (field.spec != null) {
|
|
1088
|
+
clamped.spec = Array.isArray(field.spec) ? field.spec.map(clampFieldForSchema) : clampFieldForSchema(field.spec);
|
|
1089
|
+
}
|
|
1090
|
+
if (field.type === "select" && !field.validate?.enum) {
|
|
1091
|
+
const rawOptions = isObject(field.options) ? field.options.store : field.options;
|
|
1092
|
+
if (Array.isArray(rawOptions)) {
|
|
1093
|
+
const values = [];
|
|
1094
|
+
for (const item of rawOptions) {
|
|
1095
|
+
if ("options" in item) {
|
|
1096
|
+
for (const opt of item.options) {
|
|
1097
|
+
values.push(opt.value);
|
|
1098
|
+
}
|
|
1099
|
+
} else if ("value" in item) {
|
|
1100
|
+
values.push(item.value);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (values.length > 0) {
|
|
1104
|
+
clamped.validate = { ...clamped.validate, enum: values.map(String) };
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return clamped;
|
|
1109
|
+
}
|
|
1069
1110
|
var FORMAN_TYPE_MAP2 = {
|
|
1070
1111
|
account: "number",
|
|
1071
1112
|
hook: "number",
|
|
@@ -1115,6 +1156,7 @@ async function validateFormanWithDomainsInternal(domains, options) {
|
|
|
1115
1156
|
acc[domain] = {
|
|
1116
1157
|
seenFields: /* @__PURE__ */ new Set(),
|
|
1117
1158
|
fieldStates: [],
|
|
1159
|
+
schemaFields: [],
|
|
1118
1160
|
validateFields: (fields, context) => {
|
|
1119
1161
|
return validateFormanValue(
|
|
1120
1162
|
domains[domain].values,
|
|
@@ -1210,7 +1252,8 @@ async function validateFormanWithDomainsInternal(domains, options) {
|
|
|
1210
1252
|
errors,
|
|
1211
1253
|
states: errors.length === 0 && options?.states ? buildRestoreStructure(
|
|
1212
1254
|
Object.keys(domains).map((domain) => roots[domain].fieldStates.map((state) => ({ domain, ...state }))).flat()
|
|
1213
|
-
) : void 0
|
|
1255
|
+
) : void 0,
|
|
1256
|
+
schemas: errors.length === 0 && options?.schemas ? Object.fromEntries(Object.keys(domains).map((domain) => [domain, roots[domain].schemaFields])) : void 0
|
|
1214
1257
|
};
|
|
1215
1258
|
}
|
|
1216
1259
|
async function validateFormanValue(value, field, context) {
|
|
@@ -1359,6 +1402,9 @@ async function handleCollectionType2(value, field, context) {
|
|
|
1359
1402
|
continue;
|
|
1360
1403
|
}
|
|
1361
1404
|
if (context.strict && !seen.has(subField.name)) seen.add(subField.name);
|
|
1405
|
+
if (path.length === 0) {
|
|
1406
|
+
context.roots[context.domain].schemaFields.push(clampFieldForSchema(subField));
|
|
1407
|
+
}
|
|
1362
1408
|
const result = await validateFormanValue(value[subField.name], subField, {
|
|
1363
1409
|
...context,
|
|
1364
1410
|
path: [...path, subField.name],
|
|
@@ -1376,6 +1422,9 @@ async function handleCollectionType2(value, field, context) {
|
|
|
1376
1422
|
continue;
|
|
1377
1423
|
}
|
|
1378
1424
|
if (context2.strict && !seen.has(subField2.name)) seen.add(subField2.name);
|
|
1425
|
+
if (path.length === 0) {
|
|
1426
|
+
context2.roots[context2.domain].schemaFields.push(clampFieldForSchema(subField2));
|
|
1427
|
+
}
|
|
1379
1428
|
const result2 = await validateFormanValue(value[subField2.name], subField2, {
|
|
1380
1429
|
...context2,
|
|
1381
1430
|
path: [...path, subField2.name]
|
package/dist/index.d.cts
CHANGED
|
@@ -199,6 +199,8 @@ type FormanValidationResult = {
|
|
|
199
199
|
}[];
|
|
200
200
|
/** States of fields grouped by domain */
|
|
201
201
|
states?: Record<string, FormanSchemaFieldState>;
|
|
202
|
+
/** Resolved schema fields per domain */
|
|
203
|
+
schemas?: Record<string, FormanSchemaField[]>;
|
|
202
204
|
};
|
|
203
205
|
type FormanSchemaFieldState = {
|
|
204
206
|
mode?: 'chose' | 'edit';
|
|
@@ -214,6 +216,8 @@ type FormanValidationOptions = {
|
|
|
214
216
|
strict?: boolean;
|
|
215
217
|
/** Whether to generate states for fields */
|
|
216
218
|
states?: boolean;
|
|
219
|
+
/** Whether to collect resolved schema fields per domain */
|
|
220
|
+
schemas?: boolean;
|
|
217
221
|
/** Remote resource resolver */
|
|
218
222
|
resolveRemote?(path: string, data: Record<string, unknown>): Promise<unknown>;
|
|
219
223
|
/** Maps domain names used in nested.domain to actual domain keys passed to validateFormanWithDomains */
|
package/dist/index.d.ts
CHANGED
|
@@ -199,6 +199,8 @@ type FormanValidationResult = {
|
|
|
199
199
|
}[];
|
|
200
200
|
/** States of fields grouped by domain */
|
|
201
201
|
states?: Record<string, FormanSchemaFieldState>;
|
|
202
|
+
/** Resolved schema fields per domain */
|
|
203
|
+
schemas?: Record<string, FormanSchemaField[]>;
|
|
202
204
|
};
|
|
203
205
|
type FormanSchemaFieldState = {
|
|
204
206
|
mode?: 'chose' | 'edit';
|
|
@@ -214,6 +216,8 @@ type FormanValidationOptions = {
|
|
|
214
216
|
strict?: boolean;
|
|
215
217
|
/** Whether to generate states for fields */
|
|
216
218
|
states?: boolean;
|
|
219
|
+
/** Whether to collect resolved schema fields per domain */
|
|
220
|
+
schemas?: boolean;
|
|
217
221
|
/** Remote resource resolver */
|
|
218
222
|
resolveRemote?(path: string, data: Record<string, unknown>): Promise<unknown>;
|
|
219
223
|
/** Maps domain names used in nested.domain to actual domain keys passed to validateFormanWithDomains */
|
package/dist/index.js
CHANGED
|
@@ -1037,6 +1037,47 @@ function extractNestedFromField(field) {
|
|
|
1037
1037
|
if (isObject(field.options) && field.options.nested) return field.options.nested;
|
|
1038
1038
|
return void 0;
|
|
1039
1039
|
}
|
|
1040
|
+
var SCHEMA_STRIP_KEYS = [
|
|
1041
|
+
"nested",
|
|
1042
|
+
"options",
|
|
1043
|
+
"help",
|
|
1044
|
+
"rpc",
|
|
1045
|
+
"sort",
|
|
1046
|
+
"disabled",
|
|
1047
|
+
"multiline",
|
|
1048
|
+
"tags",
|
|
1049
|
+
"extension",
|
|
1050
|
+
"codepage",
|
|
1051
|
+
"logic"
|
|
1052
|
+
];
|
|
1053
|
+
function clampFieldForSchema(field) {
|
|
1054
|
+
const clamped = { ...field };
|
|
1055
|
+
for (const key of SCHEMA_STRIP_KEYS) {
|
|
1056
|
+
delete clamped[key];
|
|
1057
|
+
}
|
|
1058
|
+
if (field.spec != null) {
|
|
1059
|
+
clamped.spec = Array.isArray(field.spec) ? field.spec.map(clampFieldForSchema) : clampFieldForSchema(field.spec);
|
|
1060
|
+
}
|
|
1061
|
+
if (field.type === "select" && !field.validate?.enum) {
|
|
1062
|
+
const rawOptions = isObject(field.options) ? field.options.store : field.options;
|
|
1063
|
+
if (Array.isArray(rawOptions)) {
|
|
1064
|
+
const values = [];
|
|
1065
|
+
for (const item of rawOptions) {
|
|
1066
|
+
if ("options" in item) {
|
|
1067
|
+
for (const opt of item.options) {
|
|
1068
|
+
values.push(opt.value);
|
|
1069
|
+
}
|
|
1070
|
+
} else if ("value" in item) {
|
|
1071
|
+
values.push(item.value);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (values.length > 0) {
|
|
1075
|
+
clamped.validate = { ...clamped.validate, enum: values.map(String) };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return clamped;
|
|
1080
|
+
}
|
|
1040
1081
|
var FORMAN_TYPE_MAP2 = {
|
|
1041
1082
|
account: "number",
|
|
1042
1083
|
hook: "number",
|
|
@@ -1086,6 +1127,7 @@ async function validateFormanWithDomainsInternal(domains, options) {
|
|
|
1086
1127
|
acc[domain] = {
|
|
1087
1128
|
seenFields: /* @__PURE__ */ new Set(),
|
|
1088
1129
|
fieldStates: [],
|
|
1130
|
+
schemaFields: [],
|
|
1089
1131
|
validateFields: (fields, context) => {
|
|
1090
1132
|
return validateFormanValue(
|
|
1091
1133
|
domains[domain].values,
|
|
@@ -1181,7 +1223,8 @@ async function validateFormanWithDomainsInternal(domains, options) {
|
|
|
1181
1223
|
errors,
|
|
1182
1224
|
states: errors.length === 0 && options?.states ? buildRestoreStructure(
|
|
1183
1225
|
Object.keys(domains).map((domain) => roots[domain].fieldStates.map((state) => ({ domain, ...state }))).flat()
|
|
1184
|
-
) : void 0
|
|
1226
|
+
) : void 0,
|
|
1227
|
+
schemas: errors.length === 0 && options?.schemas ? Object.fromEntries(Object.keys(domains).map((domain) => [domain, roots[domain].schemaFields])) : void 0
|
|
1185
1228
|
};
|
|
1186
1229
|
}
|
|
1187
1230
|
async function validateFormanValue(value, field, context) {
|
|
@@ -1330,6 +1373,9 @@ async function handleCollectionType2(value, field, context) {
|
|
|
1330
1373
|
continue;
|
|
1331
1374
|
}
|
|
1332
1375
|
if (context.strict && !seen.has(subField.name)) seen.add(subField.name);
|
|
1376
|
+
if (path.length === 0) {
|
|
1377
|
+
context.roots[context.domain].schemaFields.push(clampFieldForSchema(subField));
|
|
1378
|
+
}
|
|
1333
1379
|
const result = await validateFormanValue(value[subField.name], subField, {
|
|
1334
1380
|
...context,
|
|
1335
1381
|
path: [...path, subField.name],
|
|
@@ -1347,6 +1393,9 @@ async function handleCollectionType2(value, field, context) {
|
|
|
1347
1393
|
continue;
|
|
1348
1394
|
}
|
|
1349
1395
|
if (context2.strict && !seen.has(subField2.name)) seen.add(subField2.name);
|
|
1396
|
+
if (path.length === 0) {
|
|
1397
|
+
context2.roots[context2.domain].schemaFields.push(clampFieldForSchema(subField2));
|
|
1398
|
+
}
|
|
1350
1399
|
const result2 = await validateFormanValue(value[subField2.name], subField2, {
|
|
1351
1400
|
...context2,
|
|
1352
1401
|
path: [...path, subField2.name]
|