@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.js CHANGED
@@ -1604,7 +1604,7 @@ function applyCustomConstraint(schema, constraint, ctx) {
1604
1604
  if (registration.emitsVocabularyKeywords) {
1605
1605
  const target = schema;
1606
1606
  for (const [key, value] of Object.entries(extensionSchema)) {
1607
- if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1607
+ if (VOCABULARY_MODE_BLOCKED_KEYWORDS.has(key)) {
1608
1608
  throw new Error(
1609
1609
  `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1610
1610
  );
@@ -1647,13 +1647,13 @@ function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPr
1647
1647
  schema[key] = value;
1648
1648
  }
1649
1649
  }
1650
- var JSON_SCHEMA_STRUCTURAL_KEYWORDS;
1650
+ var VOCABULARY_MODE_BLOCKED_KEYWORDS;
1651
1651
  var init_ir_generator = __esm({
1652
1652
  "src/json-schema/ir-generator.ts"() {
1653
1653
  "use strict";
1654
1654
  init_metadata();
1655
1655
  init_collision_guards();
1656
- JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1656
+ VOCABULARY_MODE_BLOCKED_KEYWORDS = /* @__PURE__ */ new Set([
1657
1657
  "$schema",
1658
1658
  "$ref",
1659
1659
  "$defs",
@@ -3063,6 +3063,31 @@ function isObjectType(type) {
3063
3063
  function isIntersectionType(type) {
3064
3064
  return !!(type.flags & ts3.TypeFlags.Intersection);
3065
3065
  }
3066
+ function isIntegerBrandedType(type) {
3067
+ if (!type.isIntersection()) {
3068
+ return false;
3069
+ }
3070
+ const hasNumberBase = type.types.some(
3071
+ (member) => !!(member.flags & ts3.TypeFlags.Number)
3072
+ );
3073
+ if (!hasNumberBase) {
3074
+ return false;
3075
+ }
3076
+ return type.getProperties().some((prop) => {
3077
+ const declaration = prop.valueDeclaration ?? prop.declarations?.[0];
3078
+ if (declaration === void 0) {
3079
+ return false;
3080
+ }
3081
+ if (!ts3.isPropertySignature(declaration) && !ts3.isPropertyDeclaration(declaration)) {
3082
+ return false;
3083
+ }
3084
+ const name = declaration.name;
3085
+ if (!ts3.isComputedPropertyName(name)) {
3086
+ return false;
3087
+ }
3088
+ return ts3.isIdentifier(name.expression) && name.expression.text === "__integerBrand";
3089
+ });
3090
+ }
3066
3091
  function isResolvableObjectLikeAliasTypeNode(typeNode) {
3067
3092
  if (ts3.isParenthesizedTypeNode(typeNode)) {
3068
3093
  return isResolvableObjectLikeAliasTypeNode(typeNode.type);
@@ -4183,6 +4208,9 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4183
4208
  if (primitiveAlias) {
4184
4209
  return primitiveAlias;
4185
4210
  }
4211
+ if (isIntegerBrandedType(type)) {
4212
+ return { kind: "primitive", primitiveKind: "integer" };
4213
+ }
4186
4214
  if (type.flags & ts3.TypeFlags.String) {
4187
4215
  return { kind: "primitive", primitiveKind: "string" };
4188
4216
  }
@@ -4285,7 +4313,7 @@ function resolveTypeNode(type, checker, file, typeRegistry, visiting, sourceNode
4285
4313
  return { kind: "primitive", primitiveKind: "string" };
4286
4314
  }
4287
4315
  function tryResolveNamedPrimitiveAlias(type, checker, file, typeRegistry, visiting, sourceNode, metadataPolicy = createAnalyzerMetadataPolicy(void 0), extensionRegistry, diagnostics) {
4288
- if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null))) {
4316
+ if (!(type.flags & (ts3.TypeFlags.String | ts3.TypeFlags.Number | ts3.TypeFlags.BigInt | ts3.TypeFlags.BigIntLiteral | ts3.TypeFlags.Boolean | ts3.TypeFlags.Null)) && !isIntegerBrandedType(type)) {
4289
4317
  return null;
4290
4318
  }
4291
4319
  const aliasDecl = type.aliasSymbol?.declarations?.find(ts3.isTypeAliasDeclaration) ?? getReferencedTypeAliasDeclaration(sourceNode, checker);
@@ -4371,6 +4399,9 @@ function resolveAliasedPrimitiveTarget(type, checker, file, typeRegistry, visiti
4371
4399
  visitedAliases
4372
4400
  );
4373
4401
  }
4402
+ if (isIntegerBrandedType(type)) {
4403
+ return { kind: "primitive", primitiveKind: "integer" };
4404
+ }
4374
4405
  if (type.flags & ts3.TypeFlags.String) {
4375
4406
  return { kind: "primitive", primitiveKind: "string" };
4376
4407
  }