@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/index.cjs CHANGED
@@ -1594,7 +1594,7 @@ function generateCustomType(type, ctx) {
1594
1594
  }
1595
1595
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
1596
1596
  }
1597
- var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1597
+ var VOCABULARY_MODE_BLOCKED_KEYWORDS = /* @__PURE__ */ new Set([
1598
1598
  "$schema",
1599
1599
  "$ref",
1600
1600
  "$defs",
@@ -1665,7 +1665,7 @@ function applyCustomConstraint(schema, constraint, ctx) {
1665
1665
  if (registration.emitsVocabularyKeywords) {
1666
1666
  const target = schema;
1667
1667
  for (const [key, value] of Object.entries(extensionSchema)) {
1668
- if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1668
+ if (VOCABULARY_MODE_BLOCKED_KEYWORDS.has(key)) {
1669
1669
  throw new Error(
1670
1670
  `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1671
1671
  );
@@ -2984,6 +2984,31 @@ function isObjectType(type) {
2984
2984
  function isIntersectionType(type) {
2985
2985
  return !!(type.flags & ts3.TypeFlags.Intersection);
2986
2986
  }
2987
+ function isIntegerBrandedType(type) {
2988
+ if (!type.isIntersection()) {
2989
+ return false;
2990
+ }
2991
+ const hasNumberBase = type.types.some(
2992
+ (member) => !!(member.flags & ts3.TypeFlags.Number)
2993
+ );
2994
+ if (!hasNumberBase) {
2995
+ return false;
2996
+ }
2997
+ return type.getProperties().some((prop) => {
2998
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
2999
+ if (declaration === void 0) {
3000
+ return false;
3001
+ }
3002
+ if (!ts3.isPropertySignature(declaration) && !ts3.isPropertyDeclaration(declaration)) {
3003
+ return false;
3004
+ }
3005
+ const name = declaration.name;
3006
+ if (!ts3.isComputedPropertyName(name)) {
3007
+ return false;
3008
+ }
3009
+ return ts3.isIdentifier(name.expression) && name.expression.text === "__integerBrand";
3010
+ });
3011
+ }
2987
3012
  function isResolvableObjectLikeAliasTypeNode(typeNode) {
2988
3013
  if (ts3.isParenthesizedTypeNode(typeNode)) {
2989
3014
  return isResolvableObjectLikeAliasTypeNode(typeNode.type);
@@ -4109,6 +4134,9 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4109
4134
  if (primitiveAlias) {
4110
4135
  return primitiveAlias;
4111
4136
  }
4137
+ if (isIntegerBrandedType(type)) {
4138
+ return { kind: "primitive", primitiveKind: "integer" };
4139
+ }
4112
4140
  if (type.flags & ts3.TypeFlags.String) {
4113
4141
  return { kind: "primitive", primitiveKind: "string" };
4114
4142
  }
@@ -4211,7 +4239,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4211
4239
  return { kind: "primitive", primitiveKind: "string" };
4212
4240
  }
4213
4241
  function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
4214
- if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
4242
+ if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
4215
4243
  return null;
4216
4244
  }
4217
4245
  const aliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
@@ -4297,6 +4325,9 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
4297
4325
  visitedAliases
4298
4326
  );
4299
4327
  }
4328
+ if (isIntegerBrandedType(type)) {
4329
+ return { kind: "primitive", primitiveKind: "integer" };
4330
+ }
4300
4331
  if (type.flags & ts3.TypeFlags.String) {
4301
4332
  return { kind: "primitive", primitiveKind: "string" };
4302
4333
  }