@formspec/build 0.1.0-alpha.31 → 0.1.0-alpha.33

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/browser.js CHANGED
@@ -1544,13 +1544,35 @@ function getSchemaExtension(schema, key) {
1544
1544
  }
1545
1545
 
1546
1546
  // src/extensions/registry.ts
1547
+ import {
1548
+ BUILTIN_CONSTRAINT_DEFINITIONS,
1549
+ normalizeConstraintTagName
1550
+ } from "@formspec/core/internals";
1551
+ import {
1552
+ getTagDefinition,
1553
+ normalizeFormSpecTagName
1554
+ } from "@formspec/analysis/internal";
1555
+ var BUILTIN_METADATA_TAGS = /* @__PURE__ */ new Set(["apiName", "displayName"]);
1556
+ function buildConstraintTagSources(extensions) {
1557
+ return extensions.map((extension) => ({
1558
+ extensionId: extension.extensionId,
1559
+ ...extension.constraintTags !== void 0 ? {
1560
+ constraintTags: extension.constraintTags.map((tag) => ({
1561
+ tagName: normalizeFormSpecTagName(tag.tagName)
1562
+ }))
1563
+ } : {}
1564
+ }));
1565
+ }
1547
1566
  function createExtensionRegistry(extensions) {
1567
+ const reservedTagSources = buildConstraintTagSources(extensions);
1548
1568
  const typeMap = /* @__PURE__ */ new Map();
1549
1569
  const typeNameMap = /* @__PURE__ */ new Map();
1550
1570
  const constraintMap = /* @__PURE__ */ new Map();
1551
1571
  const constraintTagMap = /* @__PURE__ */ new Map();
1552
1572
  const builtinBroadeningMap = /* @__PURE__ */ new Map();
1553
1573
  const annotationMap = /* @__PURE__ */ new Map();
1574
+ const metadataSlotMap = /* @__PURE__ */ new Map();
1575
+ const metadataTagMap = /* @__PURE__ */ new Map();
1554
1576
  for (const ext of extensions) {
1555
1577
  if (ext.types !== void 0) {
1556
1578
  for (const type of ext.types) {
@@ -1593,10 +1615,11 @@ function createExtensionRegistry(extensions) {
1593
1615
  }
1594
1616
  if (ext.constraintTags !== void 0) {
1595
1617
  for (const tag of ext.constraintTags) {
1596
- if (constraintTagMap.has(tag.tagName)) {
1597
- throw new Error(`Duplicate custom constraint tag: "@${tag.tagName}"`);
1618
+ const canonicalTagName = normalizeFormSpecTagName(tag.tagName);
1619
+ if (constraintTagMap.has(canonicalTagName)) {
1620
+ throw new Error(`Duplicate custom constraint tag: "@${canonicalTagName}"`);
1598
1621
  }
1599
- constraintTagMap.set(tag.tagName, {
1622
+ constraintTagMap.set(canonicalTagName, {
1600
1623
  extensionId: ext.extensionId,
1601
1624
  registration: tag
1602
1625
  });
@@ -1611,13 +1634,54 @@ function createExtensionRegistry(extensions) {
1611
1634
  annotationMap.set(qualifiedId, annotation);
1612
1635
  }
1613
1636
  }
1637
+ if (ext.metadataSlots !== void 0) {
1638
+ for (const slot of ext.metadataSlots) {
1639
+ if (metadataSlotMap.has(slot.slotId)) {
1640
+ throw new Error(`Duplicate metadata slot ID: "${slot.slotId}"`);
1641
+ }
1642
+ metadataSlotMap.set(slot.slotId, true);
1643
+ const canonicalTagName = normalizeFormSpecTagName(slot.tagName);
1644
+ if (slot.allowBare === false && (slot.qualifiers?.length ?? 0) === 0) {
1645
+ throw new Error(
1646
+ `Metadata tag "@${canonicalTagName}" must allow bare usage or declare at least one qualifier.`
1647
+ );
1648
+ }
1649
+ if (metadataTagMap.has(canonicalTagName)) {
1650
+ throw new Error(`Duplicate metadata tag: "@${canonicalTagName}"`);
1651
+ }
1652
+ if (BUILTIN_METADATA_TAGS.has(canonicalTagName)) {
1653
+ throw new Error(
1654
+ `Metadata tag "@${canonicalTagName}" conflicts with built-in metadata tags.`
1655
+ );
1656
+ }
1657
+ if (constraintTagMap.has(canonicalTagName)) {
1658
+ throw new Error(
1659
+ `Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${canonicalTagName}".`
1660
+ );
1661
+ }
1662
+ if (Object.hasOwn(BUILTIN_CONSTRAINT_DEFINITIONS, normalizeConstraintTagName(canonicalTagName))) {
1663
+ throw new Error(
1664
+ `Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${normalizeConstraintTagName(canonicalTagName)}".`
1665
+ );
1666
+ }
1667
+ const existingTag = getTagDefinition(canonicalTagName, reservedTagSources);
1668
+ if (existingTag !== null) {
1669
+ throw BUILTIN_METADATA_TAGS.has(existingTag.canonicalName) ? new Error(
1670
+ `Metadata tag "@${canonicalTagName}" conflicts with built-in metadata tags.`
1671
+ ) : new Error(
1672
+ `Metadata tag "@${canonicalTagName}" conflicts with existing FormSpec tag "@${existingTag.canonicalName}".`
1673
+ );
1674
+ }
1675
+ metadataTagMap.set(canonicalTagName, true);
1676
+ }
1677
+ }
1614
1678
  }
1615
1679
  return {
1616
1680
  extensions,
1617
1681
  findType: (typeId) => typeMap.get(typeId),
1618
1682
  findTypeByName: (typeName) => typeNameMap.get(typeName),
1619
1683
  findConstraint: (constraintId) => constraintMap.get(constraintId),
1620
- findConstraintTag: (tagName) => constraintTagMap.get(tagName),
1684
+ findConstraintTag: (tagName) => constraintTagMap.get(normalizeFormSpecTagName(tagName)),
1621
1685
  findBuiltinConstraintBroadening: (typeId, tagName) => builtinBroadeningMap.get(`${typeId}:${tagName}`),
1622
1686
  findAnnotation: (annotationId) => annotationMap.get(annotationId)
1623
1687
  };