@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/cli.cjs CHANGED
@@ -1626,7 +1626,7 @@ function applyCustomConstraint(schema, constraint, ctx) {
1626
1626
  if (registration.emitsVocabularyKeywords) {
1627
1627
  const target = schema;
1628
1628
  for (const [key, value] of Object.entries(extensionSchema)) {
1629
- if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1629
+ if (VOCABULARY_MODE_BLOCKED_KEYWORDS.has(key)) {
1630
1630
  throw new Error(
1631
1631
  `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1632
1632
  );
@@ -1669,13 +1669,13 @@ function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPr
1669
1669
  schema[key] = value;
1670
1670
  }
1671
1671
  }
1672
- var JSON_SCHEMA_STRUCTURAL_KEYWORDS;
1672
+ var VOCABULARY_MODE_BLOCKED_KEYWORDS;
1673
1673
  var init_ir_generator = __esm({
1674
1674
  "src/json-schema/ir-generator.ts"() {
1675
1675
  "use strict";
1676
1676
  init_metadata();
1677
1677
  init_collision_guards();
1678
- JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1678
+ VOCABULARY_MODE_BLOCKED_KEYWORDS = /* @__PURE__ */ new Set([
1679
1679
  "$schema",
1680
1680
  "$ref",
1681
1681
  "$defs",
@@ -3058,6 +3058,31 @@ function isObjectType(type) {
3058
3058
  function isIntersectionType(type) {
3059
3059
  return !!(type.flags & ts3.TypeFlags.Intersection);
3060
3060
  }
3061
+ function isIntegerBrandedType(type) {
3062
+ if (!type.isIntersection()) {
3063
+ return false;
3064
+ }
3065
+ const hasNumberBase = type.types.some(
3066
+ (member) => !!(member.flags & ts3.TypeFlags.Number)
3067
+ );
3068
+ if (!hasNumberBase) {
3069
+ return false;
3070
+ }
3071
+ return type.getProperties().some((prop) => {
3072
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
3073
+ if (declaration === void 0) {
3074
+ return false;
3075
+ }
3076
+ if (!ts3.isPropertySignature(declaration) && !ts3.isPropertyDeclaration(declaration)) {
3077
+ return false;
3078
+ }
3079
+ const name = declaration.name;
3080
+ if (!ts3.isComputedPropertyName(name)) {
3081
+ return false;
3082
+ }
3083
+ return ts3.isIdentifier(name.expression) && name.expression.text === "__integerBrand";
3084
+ });
3085
+ }
3061
3086
  function isResolvableObjectLikeAliasTypeNode(typeNode) {
3062
3087
  if (ts3.isParenthesizedTypeNode(typeNode)) {
3063
3088
  return isResolvableObjectLikeAliasTypeNode(typeNode.type);
@@ -4178,6 +4203,9 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4178
4203
  if (primitiveAlias) {
4179
4204
  return primitiveAlias;
4180
4205
  }
4206
+ if (isIntegerBrandedType(type)) {
4207
+ return { kind: "primitive", primitiveKind: "integer" };
4208
+ }
4181
4209
  if (type.flags & ts3.TypeFlags.String) {
4182
4210
  return { kind: "primitive", primitiveKind: "string" };
4183
4211
  }
@@ -4280,7 +4308,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4280
4308
  return { kind: "primitive", primitiveKind: "string" };
4281
4309
  }
4282
4310
  function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
4283
- if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
4311
+ if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
4284
4312
  return null;
4285
4313
  }
4286
4314
  const aliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
@@ -4366,6 +4394,9 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
4366
4394
  visitedAliases
4367
4395
  );
4368
4396
  }
4397
+ if (isIntegerBrandedType(type)) {
4398
+ return { kind: "primitive", primitiveKind: "integer" };
4399
+ }
4369
4400
  if (type.flags & ts3.TypeFlags.String) {
4370
4401
  return { kind: "primitive", primitiveKind: "string" };
4371
4402
  }