@makehq/forman-schema 1.9.4 → 1.9.5

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 CHANGED
@@ -524,6 +524,7 @@ function udtspecCollapse(field) {
524
524
  }
525
525
 
526
526
  // src/forman.ts
527
+ var EMPTY_OPTION_DESCRIPTION = "Optional field, can be left empty.";
527
528
  var SchemaConversionError = class extends Error {
528
529
  /** Field that caused the error */
529
530
  field;
@@ -886,11 +887,10 @@ function handleSelectOrPathType(field, result, context) {
886
887
  const placeholder = field.options.placeholder;
887
888
  if (isObject(placeholder) && placeholder.nested) {
888
889
  (options ||= []).push({
889
- value: null,
890
+ value: "",
890
891
  label: placeholder.label,
891
892
  nested: placeholder.nested
892
893
  });
893
- result.type = [result.type, "null"];
894
894
  }
895
895
  }
896
896
  if (options?.some((option) => {
@@ -944,6 +944,19 @@ function handleSelectOrPathType(field, result, context) {
944
944
  result.enum = (options || []).map((option) => option.value);
945
945
  }
946
946
  }
947
+ if (!field.required) {
948
+ if (result.enum && !result.enum.includes("")) {
949
+ result.enum = ["", ...result.enum];
950
+ } else if (result.oneOf && !result.oneOf.some((entry) => isObject(entry) && entry.const === "")) {
951
+ result.oneOf = [{ title: "Empty", const: "" }, ...result.oneOf];
952
+ }
953
+ if (result.default === void 0) {
954
+ result.default = "";
955
+ }
956
+ if (!result.description) {
957
+ result.description = EMPTY_OPTION_DESCRIPTION;
958
+ }
959
+ }
947
960
  result = handleNestedWithDomain(field, nested, domain, result, context);
948
961
  if (field.rpc) result = processRpcDirective(field, result, context);
949
962
  return result;
@@ -1207,7 +1220,7 @@ async function validateFormanValue(value, field, context) {
1207
1220
  ]
1208
1221
  };
1209
1222
  }
1210
- if (value == null) {
1223
+ if (value == null || value === "") {
1211
1224
  if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
1212
1225
  return handleSelectType(value, normalizedField, context);
1213
1226
  }
@@ -1687,7 +1700,7 @@ async function handleSelectType(value, field, context) {
1687
1700
  });
1688
1701
  }
1689
1702
  }
1690
- } else if (value == null && hasPlaceholderNested(field)) {
1703
+ } else if ((value == null || value === "") && hasPlaceholderNested(field)) {
1691
1704
  const placeholder = field.options.placeholder;
1692
1705
  if (placeholder.label) {
1693
1706
  context.roots[context.domain].fieldStates.push({
@@ -1919,10 +1932,11 @@ function toFormanSchema(field) {
1919
1932
  case "string":
1920
1933
  const pathInfo = Object.getOwnPropertyDescriptor(field, "x-path");
1921
1934
  if (pathInfo) {
1935
+ const help = field.description === EMPTY_OPTION_DESCRIPTION ? void 0 : noEmpty(field.description);
1922
1936
  return {
1923
1937
  type: pathInfo.value.type,
1924
1938
  label: noEmpty(field.title),
1925
- help: noEmpty(field.description),
1939
+ help,
1926
1940
  options: {
1927
1941
  store: Object.getOwnPropertyDescriptor(field, "x-fetch")?.value,
1928
1942
  showRoot: pathInfo.value.showRoot,
@@ -1931,18 +1945,20 @@ function toFormanSchema(field) {
1931
1945
  };
1932
1946
  }
1933
1947
  if (field.enum) {
1948
+ const help = field.description === EMPTY_OPTION_DESCRIPTION ? void 0 : noEmpty(field.description);
1934
1949
  return {
1935
1950
  type: "select",
1936
1951
  label: noEmpty(field.title),
1937
- help: noEmpty(field.description),
1938
- options: field.enum.map((value) => ({ value }))
1952
+ help,
1953
+ options: field.enum.filter((value) => value !== "").map((value) => ({ value }))
1939
1954
  };
1940
1955
  } else if (field.oneOf) {
1956
+ const help = field.description === EMPTY_OPTION_DESCRIPTION ? void 0 : noEmpty(field.description);
1941
1957
  return {
1942
1958
  type: "select",
1943
1959
  label: noEmpty(field.title),
1944
- help: noEmpty(field.description),
1945
- options: field.oneOf.filter((value) => value).map((value) => ({ value: value.const }))
1960
+ help,
1961
+ options: field.oneOf.filter((value) => value && value.const !== "").map((value) => ({ value: value.const }))
1946
1962
  };
1947
1963
  }
1948
1964
  let textField = {
package/dist/index.js CHANGED
@@ -495,6 +495,7 @@ function udtspecCollapse(field) {
495
495
  }
496
496
 
497
497
  // src/forman.ts
498
+ var EMPTY_OPTION_DESCRIPTION = "Optional field, can be left empty.";
498
499
  var SchemaConversionError = class extends Error {
499
500
  /** Field that caused the error */
500
501
  field;
@@ -857,11 +858,10 @@ function handleSelectOrPathType(field, result, context) {
857
858
  const placeholder = field.options.placeholder;
858
859
  if (isObject(placeholder) && placeholder.nested) {
859
860
  (options ||= []).push({
860
- value: null,
861
+ value: "",
861
862
  label: placeholder.label,
862
863
  nested: placeholder.nested
863
864
  });
864
- result.type = [result.type, "null"];
865
865
  }
866
866
  }
867
867
  if (options?.some((option) => {
@@ -915,6 +915,19 @@ function handleSelectOrPathType(field, result, context) {
915
915
  result.enum = (options || []).map((option) => option.value);
916
916
  }
917
917
  }
918
+ if (!field.required) {
919
+ if (result.enum && !result.enum.includes("")) {
920
+ result.enum = ["", ...result.enum];
921
+ } else if (result.oneOf && !result.oneOf.some((entry) => isObject(entry) && entry.const === "")) {
922
+ result.oneOf = [{ title: "Empty", const: "" }, ...result.oneOf];
923
+ }
924
+ if (result.default === void 0) {
925
+ result.default = "";
926
+ }
927
+ if (!result.description) {
928
+ result.description = EMPTY_OPTION_DESCRIPTION;
929
+ }
930
+ }
918
931
  result = handleNestedWithDomain(field, nested, domain, result, context);
919
932
  if (field.rpc) result = processRpcDirective(field, result, context);
920
933
  return result;
@@ -1178,7 +1191,7 @@ async function validateFormanValue(value, field, context) {
1178
1191
  ]
1179
1192
  };
1180
1193
  }
1181
- if (value == null) {
1194
+ if (value == null || value === "") {
1182
1195
  if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
1183
1196
  return handleSelectType(value, normalizedField, context);
1184
1197
  }
@@ -1658,7 +1671,7 @@ async function handleSelectType(value, field, context) {
1658
1671
  });
1659
1672
  }
1660
1673
  }
1661
- } else if (value == null && hasPlaceholderNested(field)) {
1674
+ } else if ((value == null || value === "") && hasPlaceholderNested(field)) {
1662
1675
  const placeholder = field.options.placeholder;
1663
1676
  if (placeholder.label) {
1664
1677
  context.roots[context.domain].fieldStates.push({
@@ -1890,10 +1903,11 @@ function toFormanSchema(field) {
1890
1903
  case "string":
1891
1904
  const pathInfo = Object.getOwnPropertyDescriptor(field, "x-path");
1892
1905
  if (pathInfo) {
1906
+ const help = field.description === EMPTY_OPTION_DESCRIPTION ? void 0 : noEmpty(field.description);
1893
1907
  return {
1894
1908
  type: pathInfo.value.type,
1895
1909
  label: noEmpty(field.title),
1896
- help: noEmpty(field.description),
1910
+ help,
1897
1911
  options: {
1898
1912
  store: Object.getOwnPropertyDescriptor(field, "x-fetch")?.value,
1899
1913
  showRoot: pathInfo.value.showRoot,
@@ -1902,18 +1916,20 @@ function toFormanSchema(field) {
1902
1916
  };
1903
1917
  }
1904
1918
  if (field.enum) {
1919
+ const help = field.description === EMPTY_OPTION_DESCRIPTION ? void 0 : noEmpty(field.description);
1905
1920
  return {
1906
1921
  type: "select",
1907
1922
  label: noEmpty(field.title),
1908
- help: noEmpty(field.description),
1909
- options: field.enum.map((value) => ({ value }))
1923
+ help,
1924
+ options: field.enum.filter((value) => value !== "").map((value) => ({ value }))
1910
1925
  };
1911
1926
  } else if (field.oneOf) {
1927
+ const help = field.description === EMPTY_OPTION_DESCRIPTION ? void 0 : noEmpty(field.description);
1912
1928
  return {
1913
1929
  type: "select",
1914
1930
  label: noEmpty(field.title),
1915
- help: noEmpty(field.description),
1916
- options: field.oneOf.filter((value) => value).map((value) => ({ value: value.const }))
1931
+ help,
1932
+ options: field.oneOf.filter((value) => value && value.const !== "").map((value) => ({ value: value.const }))
1917
1933
  };
1918
1934
  }
1919
1935
  let textField = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makehq/forman-schema",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "description": "Forman Schema Tools",
5
5
  "license": "MIT",
6
6
  "author": "Make",