@formspec/build 0.1.0-alpha.54 → 0.1.0-alpha.57

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/browser.js CHANGED
@@ -832,20 +832,29 @@ function assertNoSerializedNameCollisions(ir) {
832
832
  }
833
833
 
834
834
  // src/json-schema/ir-generator.ts
835
+ function parseEnumSerialization(value) {
836
+ switch (value) {
837
+ case void 0:
838
+ case "enum":
839
+ return "enum";
840
+ case "oneOf":
841
+ return "oneOf";
842
+ case "smart-size":
843
+ return "smart-size";
844
+ default:
845
+ throw new Error(
846
+ `Invalid enumSerialization "${String(value)}". Expected "enum", "oneOf", or "smart-size".`
847
+ );
848
+ }
849
+ }
835
850
  function makeContext(options) {
836
851
  const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
837
- const rawEnumSerialization = options?.enumSerialization;
852
+ const enumSerialization = parseEnumSerialization(options?.enumSerialization);
838
853
  if (!vendorPrefix.startsWith("x-")) {
839
854
  throw new Error(
840
855
  `Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
841
856
  );
842
857
  }
843
- if (rawEnumSerialization !== void 0 && rawEnumSerialization !== "enum" && rawEnumSerialization !== "oneOf") {
844
- throw new Error(
845
- `Invalid enumSerialization "${rawEnumSerialization}". Expected "enum" or "oneOf".`
846
- );
847
- }
848
- const enumSerialization = rawEnumSerialization ?? "enum";
849
858
  return {
850
859
  defs: {},
851
860
  typeNameMap: {},
@@ -1053,21 +1062,31 @@ function generatePrimitiveType(type) {
1053
1062
  };
1054
1063
  }
1055
1064
  function generateEnumType(type, ctx) {
1056
- if (ctx.enumSerialization === "oneOf") {
1065
+ if (ctx.enumSerialization === "oneOf" || ctx.enumSerialization === "smart-size" && shouldSerializeEnumAsOneOf(type)) {
1057
1066
  return {
1058
- oneOf: type.members.map((m) => ({
1059
- const: m.value,
1060
- title: m.displayName ?? String(m.value)
1061
- }))
1067
+ oneOf: type.members.map((m) => {
1068
+ const stringValue = String(m.value);
1069
+ const title = m.displayName !== void 0 && m.displayName !== stringValue ? m.displayName : void 0;
1070
+ return title !== void 0 ? { const: m.value, title } : { const: m.value };
1071
+ })
1062
1072
  };
1063
1073
  }
1064
1074
  const schema = { enum: type.members.map((m) => m.value) };
1075
+ if (ctx.enumSerialization === "smart-size") {
1076
+ return schema;
1077
+ }
1065
1078
  const displayNames = buildEnumDisplayNameExtension(type);
1066
1079
  if (displayNames !== void 0) {
1067
1080
  schema[`${ctx.vendorPrefix}-display-names`] = displayNames;
1068
1081
  }
1069
1082
  return schema;
1070
1083
  }
1084
+ function shouldSerializeEnumAsOneOf(type) {
1085
+ return type.members.some((member) => {
1086
+ const title = member.displayName ?? String(member.value);
1087
+ return title !== String(member.value);
1088
+ });
1089
+ }
1071
1090
  function buildEnumDisplayNameExtension(type) {
1072
1091
  if (!type.members.some((member) => member.displayName !== void 0)) {
1073
1092
  return void 0;
@@ -1851,7 +1870,8 @@ import {
1851
1870
  } from "@formspec/core/internals";
1852
1871
  import {
1853
1872
  getTagDefinition,
1854
- normalizeFormSpecTagName
1873
+ normalizeFormSpecTagName,
1874
+ getSyntheticLogger
1855
1875
  } from "@formspec/analysis/internal";
1856
1876
  var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
1857
1877
  function buildConstraintTagSources(extensions) {
@@ -1865,6 +1885,11 @@ function buildConstraintTagSources(extensions) {
1865
1885
  }));
1866
1886
  }
1867
1887
  function createExtensionRegistry(extensions) {
1888
+ const registryLog = getSyntheticLogger();
1889
+ registryLog.debug("createExtensionRegistry: constructing", {
1890
+ extensionCount: extensions.length,
1891
+ extensionIds: extensions.map((e) => e.extensionId)
1892
+ });
1868
1893
  const reservedTagSources = buildConstraintTagSources(extensions);
1869
1894
  let symbolMap = /* @__PURE__ */ new Map();
1870
1895
  const typeMap = /* @__PURE__ */ new Map();
@@ -1996,6 +2021,14 @@ function createExtensionRegistry(extensions) {
1996
2021
  }
1997
2022
  }
1998
2023
  }
2024
+ registryLog.debug("createExtensionRegistry: complete", {
2025
+ typeCount: typeMap.size,
2026
+ constraintCount: constraintMap.size,
2027
+ constraintTagCount: constraintTagMap.size,
2028
+ broadeningCount: builtinBroadeningMap.size,
2029
+ annotationCount: annotationMap.size,
2030
+ metadataSlotCount: metadataSlotMap.size
2031
+ });
1999
2032
  return {
2000
2033
  extensions,
2001
2034
  findType: (typeId) => typeMap.get(typeId),