@formspec/build 0.1.0-alpha.43 → 0.1.0-alpha.44

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.
@@ -1632,6 +1632,31 @@ function isObjectType(type) {
1632
1632
  function isIntersectionType(type) {
1633
1633
  return !!(type.flags & ts3.TypeFlags.Intersection);
1634
1634
  }
1635
+ function isIntegerBrandedType(type) {
1636
+ if (!type.isIntersection()) {
1637
+ return false;
1638
+ }
1639
+ const hasNumberBase = type.types.some(
1640
+ (member) => !!(member.flags & ts3.TypeFlags.Number)
1641
+ );
1642
+ if (!hasNumberBase) {
1643
+ return false;
1644
+ }
1645
+ return type.getProperties().some((prop) => {
1646
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
1647
+ if (declaration === void 0) {
1648
+ return false;
1649
+ }
1650
+ if (!ts3.isPropertySignature(declaration) && !ts3.isPropertyDeclaration(declaration)) {
1651
+ return false;
1652
+ }
1653
+ const name = declaration.name;
1654
+ if (!ts3.isComputedPropertyName(name)) {
1655
+ return false;
1656
+ }
1657
+ return ts3.isIdentifier(name.expression) && name.expression.text === "__integerBrand";
1658
+ });
1659
+ }
1635
1660
  function isResolvableObjectLikeAliasTypeNode(typeNode) {
1636
1661
  if (ts3.isParenthesizedTypeNode(typeNode)) {
1637
1662
  return isResolvableObjectLikeAliasTypeNode(typeNode.type);
@@ -2757,6 +2782,9 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
2757
2782
  if (primitiveAlias) {
2758
2783
  return primitiveAlias;
2759
2784
  }
2785
+ if (isIntegerBrandedType(type)) {
2786
+ return { kind: "primitive", primitiveKind: "integer" };
2787
+ }
2760
2788
  if (type.flags & ts3.TypeFlags.String) {
2761
2789
  return { kind: "primitive", primitiveKind: "string" };
2762
2790
  }
@@ -2859,7 +2887,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
2859
2887
  return { kind: "primitive", primitiveKind: "string" };
2860
2888
  }
2861
2889
  function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
2862
- if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
2890
+ if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
2863
2891
  return null;
2864
2892
  }
2865
2893
  const aliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
@@ -2945,6 +2973,9 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
2945
2973
  visitedAliases
2946
2974
  );
2947
2975
  }
2976
+ if (isIntegerBrandedType(type)) {
2977
+ return { kind: "primitive", primitiveKind: "integer" };
2978
+ }
2948
2979
  if (type.flags & ts3.TypeFlags.String) {
2949
2980
  return { kind: "primitive", primitiveKind: "string" };
2950
2981
  }
@@ -4724,7 +4755,7 @@ function generateCustomType(type, ctx) {
4724
4755
  }
4725
4756
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
4726
4757
  }
4727
- var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
4758
+ var VOCABULARY_MODE_BLOCKED_KEYWORDS = /* @__PURE__ */ new Set([
4728
4759
  "$schema",
4729
4760
  "$ref",
4730
4761
  "$defs",
@@ -4795,7 +4826,7 @@ function applyCustomConstraint(schema, constraint, ctx) {
4795
4826
  if (registration.emitsVocabularyKeywords) {
4796
4827
  const target = schema;
4797
4828
  for (const [key, value] of Object.entries(extensionSchema)) {
4798
- if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
4829
+ if (VOCABULARY_MODE_BLOCKED_KEYWORDS.has(key)) {
4799
4830
  throw new Error(
4800
4831
  `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
4801
4832
  );