@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.
package/dist/internals.js CHANGED
@@ -1598,6 +1598,31 @@ function isObjectType(type) {
1598
1598
  function isIntersectionType(type) {
1599
1599
  return !!(type.flags & ts3.TypeFlags.Intersection);
1600
1600
  }
1601
+ function isIntegerBrandedType(type) {
1602
+ if (!type.isIntersection()) {
1603
+ return false;
1604
+ }
1605
+ const hasNumberBase = type.types.some(
1606
+ (member) => !!(member.flags & ts3.TypeFlags.Number)
1607
+ );
1608
+ if (!hasNumberBase) {
1609
+ return false;
1610
+ }
1611
+ return type.getProperties().some((prop) => {
1612
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
1613
+ if (declaration === void 0) {
1614
+ return false;
1615
+ }
1616
+ if (!ts3.isPropertySignature(declaration) && !ts3.isPropertyDeclaration(declaration)) {
1617
+ return false;
1618
+ }
1619
+ const name = declaration.name;
1620
+ if (!ts3.isComputedPropertyName(name)) {
1621
+ return false;
1622
+ }
1623
+ return ts3.isIdentifier(name.expression) && name.expression.text === "__integerBrand";
1624
+ });
1625
+ }
1601
1626
  function isResolvableObjectLikeAliasTypeNode(typeNode) {
1602
1627
  if (ts3.isParenthesizedTypeNode(typeNode)) {
1603
1628
  return isResolvableObjectLikeAliasTypeNode(typeNode.type);
@@ -2723,6 +2748,9 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
2723
2748
  if (primitiveAlias) {
2724
2749
  return primitiveAlias;
2725
2750
  }
2751
+ if (isIntegerBrandedType(type)) {
2752
+ return { kind: "primitive", primitiveKind: "integer" };
2753
+ }
2726
2754
  if (type.flags & ts3.TypeFlags.String) {
2727
2755
  return { kind: "primitive", primitiveKind: "string" };
2728
2756
  }
@@ -2825,7 +2853,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
2825
2853
  return { kind: "primitive", primitiveKind: "string" };
2826
2854
  }
2827
2855
  function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
2828
- if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
2856
+ if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
2829
2857
  return null;
2830
2858
  }
2831
2859
  const aliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
@@ -2911,6 +2939,9 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
2911
2939
  visitedAliases
2912
2940
  );
2913
2941
  }
2942
+ if (isIntegerBrandedType(type)) {
2943
+ return { kind: "primitive", primitiveKind: "integer" };
2944
+ }
2914
2945
  if (type.flags & ts3.TypeFlags.String) {
2915
2946
  return { kind: "primitive", primitiveKind: "string" };
2916
2947
  }
@@ -4690,7 +4721,7 @@ function generateCustomType(type, ctx) {
4690
4721
  }
4691
4722
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
4692
4723
  }
4693
- var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
4724
+ var VOCABULARY_MODE_BLOCKED_KEYWORDS = /* @__PURE__ */ new Set([
4694
4725
  "$schema",
4695
4726
  "$ref",
4696
4727
  "$defs",
@@ -4761,7 +4792,7 @@ function applyCustomConstraint(schema, constraint, ctx) {
4761
4792
  if (registration.emitsVocabularyKeywords) {
4762
4793
  const target = schema;
4763
4794
  for (const [key, value] of Object.entries(extensionSchema)) {
4764
- if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
4795
+ if (VOCABULARY_MODE_BLOCKED_KEYWORDS.has(key)) {
4765
4796
  throw new Error(
4766
4797
  `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
4767
4798
  );