@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.js CHANGED
@@ -1535,7 +1535,7 @@ function generateCustomType(type, ctx) {
1535
1535
  }
1536
1536
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
1537
1537
  }
1538
- var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1538
+ var VOCABULARY_MODE_BLOCKED_KEYWORDS = /* @__PURE__ */ new Set([
1539
1539
  "$schema",
1540
1540
  "$ref",
1541
1541
  "$defs",
@@ -1606,7 +1606,7 @@ function applyCustomConstraint(schema, constraint, ctx) {
1606
1606
  if (registration.emitsVocabularyKeywords) {
1607
1607
  const target = schema;
1608
1608
  for (const [key, value] of Object.entries(extensionSchema)) {
1609
- if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1609
+ if (VOCABULARY_MODE_BLOCKED_KEYWORDS.has(key)) {
1610
1610
  throw new Error(
1611
1611
  `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1612
1612
  );
@@ -2952,6 +2952,31 @@ function isObjectType(type) {
2952
2952
  function isIntersectionType(type) {
2953
2953
  return !!(type.flags & ts3.TypeFlags.Intersection);
2954
2954
  }
2955
+ function isIntegerBrandedType(type) {
2956
+ if (!type.isIntersection()) {
2957
+ return false;
2958
+ }
2959
+ const hasNumberBase = type.types.some(
2960
+ (member) => !!(member.flags & ts3.TypeFlags.Number)
2961
+ );
2962
+ if (!hasNumberBase) {
2963
+ return false;
2964
+ }
2965
+ return type.getProperties().some((prop) => {
2966
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
2967
+ if (declaration === void 0) {
2968
+ return false;
2969
+ }
2970
+ if (!ts3.isPropertySignature(declaration) && !ts3.isPropertyDeclaration(declaration)) {
2971
+ return false;
2972
+ }
2973
+ const name = declaration.name;
2974
+ if (!ts3.isComputedPropertyName(name)) {
2975
+ return false;
2976
+ }
2977
+ return ts3.isIdentifier(name.expression) && name.expression.text === "__integerBrand";
2978
+ });
2979
+ }
2955
2980
  function isResolvableObjectLikeAliasTypeNode(typeNode) {
2956
2981
  if (ts3.isParenthesizedTypeNode(typeNode)) {
2957
2982
  return isResolvableObjectLikeAliasTypeNode(typeNode.type);
@@ -4077,6 +4102,9 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4077
4102
  if (primitiveAlias) {
4078
4103
  return primitiveAlias;
4079
4104
  }
4105
+ if (isIntegerBrandedType(type)) {
4106
+ return { kind: "primitive", primitiveKind: "integer" };
4107
+ }
4080
4108
  if (type.flags & ts3.TypeFlags.String) {
4081
4109
  return { kind: "primitive", primitiveKind: "string" };
4082
4110
  }
@@ -4179,7 +4207,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4179
4207
  return { kind: "primitive", primitiveKind: "string" };
4180
4208
  }
4181
4209
  function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
4182
- if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
4210
+ if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
4183
4211
  return null;
4184
4212
  }
4185
4213
  const aliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
@@ -4265,6 +4293,9 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
4265
4293
  visitedAliases
4266
4294
  );
4267
4295
  }
4296
+ if (isIntegerBrandedType(type)) {
4297
+ return { kind: "primitive", primitiveKind: "integer" };
4298
+ }
4268
4299
  if (type.flags & ts3.TypeFlags.String) {
4269
4300
  return { kind: "primitive", primitiveKind: "string" };
4270
4301
  }