@fern-api/fdr-sdk 1.2.41-f793e24db2 → 1.2.42-080b4f1d94

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.
Files changed (90) hide show
  1. package/dist/js/client/FdrClient.js +1 -0
  2. package/dist/js/client/FdrClient.js.map +1 -1
  3. package/dist/js/client/FdrClient.mjs +1 -0
  4. package/dist/js/client/FdrClient.mjs.map +1 -1
  5. package/dist/js/converters/index.js +9 -0
  6. package/dist/js/converters/index.js.map +1 -1
  7. package/dist/js/converters/index.mjs +9 -0
  8. package/dist/js/converters/index.mjs.map +1 -1
  9. package/dist/js/index.js +10 -0
  10. package/dist/js/index.js.map +1 -1
  11. package/dist/js/index.mjs +10 -0
  12. package/dist/js/index.mjs.map +1 -1
  13. package/dist/js/navigation/index.js +9 -0
  14. package/dist/js/navigation/index.js.map +1 -1
  15. package/dist/js/navigation/index.mjs +9 -0
  16. package/dist/js/navigation/index.mjs.map +1 -1
  17. package/dist/js/navigation/ledger-root-builder.js +212 -36
  18. package/dist/js/navigation/ledger-root-builder.js.map +1 -1
  19. package/dist/js/navigation/ledger-root-builder.mjs +212 -36
  20. package/dist/js/navigation/ledger-root-builder.mjs.map +1 -1
  21. package/dist/js/orpc-client.js +1 -0
  22. package/dist/js/orpc-client.js.map +1 -1
  23. package/dist/js/orpc-client.mjs +1 -0
  24. package/dist/js/orpc-client.mjs.map +1 -1
  25. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts +2 -0
  26. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts.map +1 -0
  27. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.js +267 -0
  28. package/dist/navigation/__test__/ledger-root-builder.crossProductDedup.test.js.map +1 -0
  29. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts +2 -0
  30. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts.map +1 -0
  31. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.js +306 -0
  32. package/dist/navigation/__test__/ledger-root-builder.ledgerParity.test.js.map +1 -0
  33. package/dist/navigation/__test__/ledger-root-builder.metadataPreservation.test.js +167 -4
  34. package/dist/navigation/__test__/ledger-root-builder.metadataPreservation.test.js.map +1 -1
  35. package/dist/navigation/__test__/ledger-root-builder.rootChildOrder.test.js +102 -0
  36. package/dist/navigation/__test__/ledger-root-builder.rootChildOrder.test.js.map +1 -1
  37. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts +2 -0
  38. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts.map +1 -0
  39. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.js +273 -0
  40. package/dist/navigation/__test__/ledger-root-builder.sidebarDepth.test.js.map +1 -0
  41. package/dist/navigation/__test__/ledger-root-builder.skipSlugApiReference.test.js +276 -0
  42. package/dist/navigation/__test__/ledger-root-builder.skipSlugApiReference.test.js.map +1 -1
  43. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts +2 -0
  44. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts.map +1 -0
  45. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.js +234 -0
  46. package/dist/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.js.map +1 -0
  47. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts +2 -0
  48. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts.map +1 -0
  49. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.js +360 -0
  50. package/dist/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.js.map +1 -0
  51. package/dist/navigation/ledger-root-builder.d.ts.map +1 -1
  52. package/dist/navigation/ledger-root-builder.js +312 -47
  53. package/dist/navigation/ledger-root-builder.js.map +1 -1
  54. package/dist/navigation/utils/__test__/syntheticSectionPath.test.d.ts +2 -0
  55. package/dist/navigation/utils/__test__/syntheticSectionPath.test.d.ts.map +1 -0
  56. package/dist/navigation/utils/__test__/syntheticSectionPath.test.js +29 -0
  57. package/dist/navigation/utils/__test__/syntheticSectionPath.test.js.map +1 -0
  58. package/dist/navigation/utils/index.d.ts +1 -0
  59. package/dist/navigation/utils/index.d.ts.map +1 -1
  60. package/dist/navigation/utils/index.js +1 -0
  61. package/dist/navigation/utils/index.js.map +1 -1
  62. package/dist/navigation/utils/syntheticSectionPath.d.ts +13 -0
  63. package/dist/navigation/utils/syntheticSectionPath.d.ts.map +1 -0
  64. package/dist/navigation/utils/syntheticSectionPath.js +20 -0
  65. package/dist/navigation/utils/syntheticSectionPath.js.map +1 -0
  66. package/dist/orpc-client/docs-ledger/contract.d.ts +9 -0
  67. package/dist/orpc-client/docs-ledger/contract.d.ts.map +1 -1
  68. package/dist/orpc-client/docs-ledger/contract.js +1 -0
  69. package/dist/orpc-client/docs-ledger/contract.js.map +1 -1
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/dist/types/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts +2 -0
  72. package/dist/types/navigation/__test__/ledger-root-builder.crossProductDedup.test.d.ts.map +1 -0
  73. package/dist/types/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts +2 -0
  74. package/dist/types/navigation/__test__/ledger-root-builder.ledgerParity.test.d.ts.map +1 -0
  75. package/dist/types/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts +2 -0
  76. package/dist/types/navigation/__test__/ledger-root-builder.sidebarDepth.test.d.ts.map +1 -0
  77. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts +2 -0
  78. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugGroupOrdering.test.d.ts.map +1 -0
  79. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts +2 -0
  80. package/dist/types/navigation/__test__/ledger-root-builder.skipSlugSiblingSection.test.d.ts.map +1 -0
  81. package/dist/types/navigation/ledger-root-builder.d.ts.map +1 -1
  82. package/dist/types/navigation/utils/__test__/syntheticSectionPath.test.d.ts +2 -0
  83. package/dist/types/navigation/utils/__test__/syntheticSectionPath.test.d.ts.map +1 -0
  84. package/dist/types/navigation/utils/index.d.ts +1 -0
  85. package/dist/types/navigation/utils/index.d.ts.map +1 -1
  86. package/dist/types/navigation/utils/syntheticSectionPath.d.ts +13 -0
  87. package/dist/types/navigation/utils/syntheticSectionPath.d.ts.map +1 -0
  88. package/dist/types/orpc-client/docs-ledger/contract.d.ts +9 -0
  89. package/dist/types/orpc-client/docs-ledger/contract.d.ts.map +1 -1
  90. package/package.json +1 -1
@@ -51,6 +51,17 @@ var VersionIdSchema = z.string();
51
51
  function VersionId(value) {
52
52
  return value;
53
53
  }
54
+ var Availability = {
55
+ Alpha: "Alpha",
56
+ Stable: "Stable",
57
+ GenerallyAvailable: "GenerallyAvailable",
58
+ InDevelopment: "InDevelopment",
59
+ PreRelease: "PreRelease",
60
+ Deprecated: "Deprecated",
61
+ Beta: "Beta",
62
+ Preview: "Preview",
63
+ Legacy: "Legacy"
64
+ };
54
65
  var SnippetsByEndpointMethodSchema = z.record(
55
66
  HttpMethodSchema,
56
67
  z.array(z.unknown())
@@ -804,6 +815,12 @@ function traverseDF(node, visit) {
804
815
  return dfs(node, visit, getChildren);
805
816
  }
806
817
 
818
+ // src/navigation/utils/syntheticSectionPath.ts
819
+ var SYNTHETIC_SEGMENT_RE = /^~\d+$/;
820
+ function stripSyntheticSegments(section) {
821
+ return section.split("/").filter((part) => !SYNTHETIC_SEGMENT_RE.test(part)).join("/");
822
+ }
823
+
807
824
  // src/navigation/ledger-root-builder.ts
808
825
  var STRUCTURAL_SEGMENT_TYPES = /* @__PURE__ */ new Set([
809
826
  "section",
@@ -841,6 +858,35 @@ function metaStr(metadata, key) {
841
858
  }
842
859
  return void 0;
843
860
  }
861
+ var AVAILABILITY_LOOKUP = {
862
+ // V1 lowercase values (stored by docsPublishTransform from V1 navigation tree)
863
+ alpha: Availability.Alpha,
864
+ stable: Availability.Stable,
865
+ "generally-available": Availability.GenerallyAvailable,
866
+ "in-development": Availability.InDevelopment,
867
+ "pre-release": Availability.PreRelease,
868
+ deprecated: Availability.Deprecated,
869
+ beta: Availability.Beta,
870
+ preview: Availability.Preview,
871
+ legacy: Availability.Legacy,
872
+ // Latest PascalCase values (pass-through)
873
+ Alpha: Availability.Alpha,
874
+ Stable: Availability.Stable,
875
+ GenerallyAvailable: Availability.GenerallyAvailable,
876
+ InDevelopment: Availability.InDevelopment,
877
+ PreRelease: Availability.PreRelease,
878
+ Deprecated: Availability.Deprecated,
879
+ Beta: Availability.Beta,
880
+ Preview: Availability.Preview,
881
+ Legacy: Availability.Legacy
882
+ };
883
+ function metaAvailability(metadata) {
884
+ const raw = metaStr(metadata, "availability");
885
+ if (raw == null) {
886
+ return void 0;
887
+ }
888
+ return AVAILABILITY_LOOKUP[raw];
889
+ }
844
890
  function metaBool(metadata, key) {
845
891
  if (metadata != null && typeof metadata === "object" && key in metadata) {
846
892
  const v = metadata[key];
@@ -958,7 +1004,7 @@ function artifactToNode(ctx, route) {
958
1004
  }),
959
1005
  pageId: PageId(pageId),
960
1006
  noindex: metaBool(md, "noindex"),
961
- availability: void 0
1007
+ availability: metaAvailability(md)
962
1008
  };
963
1009
  return node;
964
1010
  }
@@ -1023,7 +1069,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId2) {
1023
1069
  endpointId: EndpointId(endpointId),
1024
1070
  apiDefinitionId,
1025
1071
  isResponseStream: metaBool(md, "isResponseStream"),
1026
- availability: metaStr(md, "availability"),
1072
+ availability: metaAvailability(md),
1027
1073
  playground: void 0
1028
1074
  };
1029
1075
  }
@@ -1039,7 +1085,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId2) {
1039
1085
  method,
1040
1086
  webhookId: WebhookId(webhookId),
1041
1087
  apiDefinitionId,
1042
- availability: metaStr(md, "availability")
1088
+ availability: metaAvailability(md)
1043
1089
  };
1044
1090
  }
1045
1091
  if (route.type === "asyncapi") {
@@ -1052,7 +1098,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId2) {
1052
1098
  ...meta,
1053
1099
  webSocketId: WebSocketId(webSocketId),
1054
1100
  apiDefinitionId,
1055
- availability: metaStr(md, "availability"),
1101
+ availability: metaAvailability(md),
1056
1102
  playground: void 0
1057
1103
  };
1058
1104
  }
@@ -1068,7 +1114,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId2) {
1068
1114
  method,
1069
1115
  grpcId: GrpcId(grpcId),
1070
1116
  apiDefinitionId,
1071
- availability: metaStr(md, "availability")
1117
+ availability: metaAvailability(md)
1072
1118
  };
1073
1119
  }
1074
1120
  if (route.type === "graphql") {
@@ -1084,7 +1130,7 @@ function apiLeafNodeFromNavRouteInternal(ctx, route, segmentApiDefinitionId2) {
1084
1130
  graphqlOperationId: GraphQlOperationId(graphqlOperationId),
1085
1131
  graphqlOperationIds: void 0,
1086
1132
  apiDefinitionId,
1087
- availability: metaStr(md, "availability"),
1133
+ availability: metaAvailability(md),
1088
1134
  playground: void 0
1089
1135
  };
1090
1136
  }
@@ -1197,7 +1243,8 @@ function structuralNodeSlug(ctx, overviewFullPath, section, scopePrefix) {
1197
1243
  if (overviewFullPath != null) {
1198
1244
  return ctx.contentSlug(overviewFullPath);
1199
1245
  }
1200
- return section !== "" ? slugjoin(scopePrefix, section) : scopePrefix;
1246
+ const cleanSection = stripSyntheticSegments(section);
1247
+ return cleanSection !== "" ? slugjoin(scopePrefix, cleanSection) : scopePrefix;
1201
1248
  }
1202
1249
  function stripLeadingScopePrefix(section, scopePrefix) {
1203
1250
  const prefix = scopePrefix;
@@ -1212,6 +1259,30 @@ function stripLeadingScopePrefix(section, scopePrefix) {
1212
1259
  }
1213
1260
  return section;
1214
1261
  }
1262
+ function computeDuplicateSiblingSortBoundaries(siblings) {
1263
+ const result = /* @__PURE__ */ new Map();
1264
+ const byPath = /* @__PURE__ */ new Map();
1265
+ for (const sibling of siblings) {
1266
+ if (metaStr(sibling.seg.metadata, "type") !== "section") {
1267
+ continue;
1268
+ }
1269
+ const group = byPath.get(sibling.seg.section) ?? [];
1270
+ group.push(sibling);
1271
+ byPath.set(sibling.seg.section, group);
1272
+ }
1273
+ for (const [, group] of byPath) {
1274
+ if (group.length <= 1) {
1275
+ continue;
1276
+ }
1277
+ for (let i = 0; i < group.length; i++) {
1278
+ result.set(group[i], {
1279
+ lo: group[i].seg.sortOrder,
1280
+ hi: i + 1 < group.length ? group[i + 1].seg.sortOrder : Number.MAX_SAFE_INTEGER
1281
+ });
1282
+ }
1283
+ }
1284
+ return result;
1285
+ }
1215
1286
  function mergeChildrenByPosition(ctx, nav, sectionChildren) {
1216
1287
  const leafNodes = [];
1217
1288
  for (let i = 0; i < nav.length; i++) {
@@ -1261,17 +1332,20 @@ function sectionNode(ctx, scoped, sectionChildren, scopePrefix) {
1261
1332
  noindex: metaBool(overview?.metadata, "noindex") ?? metaBool(seg.metadata, "noindex"),
1262
1333
  collapsible: metaBool(seg.metadata, "collapsible") ?? (metaCollapsed(seg.metadata) === true ? true : void 0),
1263
1334
  collapsedByDefault: metaBool(seg.metadata, "collapsedByDefault") ?? (metaCollapsed(seg.metadata) === true ? true : void 0),
1264
- availability: metaStr(seg.metadata, "availability"),
1335
+ availability: metaAvailability(seg.metadata),
1265
1336
  pointsTo: metaPointsTo != null ? pointsToSlug(metaPointsTo) : void 0,
1266
1337
  children: mergeChildrenByPosition(ctx, nav, sectionChildren)
1267
1338
  };
1268
1339
  }
1269
- function directChildApiPackages(parentSection, scopeSegs) {
1340
+ function directChildApiPackages(parentSection, scopeSegs, apiDefinitionId) {
1270
1341
  const sectionPaths = new Set(scopeSegs.map((s) => s.seg.section));
1271
1342
  return scopeSegs.filter((s) => {
1272
1343
  if (metaStr(s.seg.metadata, "type") !== "apiPackage") {
1273
1344
  return false;
1274
1345
  }
1346
+ if (metaStr(s.seg.metadata, "apiDefinitionId") !== apiDefinitionId) {
1347
+ return false;
1348
+ }
1275
1349
  const parent = parentSectionPath(s.seg.section);
1276
1350
  if (parent === parentSection) {
1277
1351
  return true;
@@ -1285,7 +1359,17 @@ function directChildApiPackages(parentSection, scopeSegs) {
1285
1359
  function buildApiChildren(ctx, scoped, scopeSegs, apiDefinitionId, scopePrefix) {
1286
1360
  const { seg, nav } = scoped;
1287
1361
  const leafNodes = positionedApiLeafChildren(ctx, nav, apiDefinitionId);
1288
- const childPackages = directChildApiPackages(seg.section, scopeSegs);
1362
+ let childPackages = directChildApiPackages(seg.section, scopeSegs, apiDefinitionId);
1363
+ const samePathApiSiblings = scopeSegs.filter(
1364
+ (s) => s.seg.section === seg.section && s.seg.sortOrder !== seg.sortOrder && API_NODE_SEGMENT_TYPES.has(metaStr(s.seg.metadata, "type") ?? "")
1365
+ );
1366
+ const hasCollapsedGroups = samePathApiSiblings.length > 0;
1367
+ if (hasCollapsedGroups && metaStr(seg.metadata, "type") !== "apiReference") {
1368
+ const nextSibling = samePathApiSiblings.filter((s) => s.seg.sortOrder > seg.sortOrder).sort((a, b) => a.seg.sortOrder - b.seg.sortOrder)[0];
1369
+ const lo = seg.sortOrder;
1370
+ const hi = nextSibling?.seg.sortOrder ?? Number.MAX_SAFE_INTEGER;
1371
+ childPackages = childPackages.filter((c) => c.seg.sortOrder > lo && c.seg.sortOrder < hi);
1372
+ }
1289
1373
  const packageNodes = childPackages.map((child) => ({
1290
1374
  node: apiPackageChildNode(
1291
1375
  ctx,
@@ -1296,6 +1380,9 @@ function buildApiChildren(ctx, scoped, scopeSegs, apiDefinitionId, scopePrefix)
1296
1380
  ),
1297
1381
  childIndex: metaNum(child.seg.metadata, "childIndex")
1298
1382
  }));
1383
+ if (hasCollapsedGroups && metaStr(seg.metadata, "type") === "apiReference") {
1384
+ return [...leafNodes, ...packageNodes.map((p, i) => ({ node: p.node, pos: leafNodes.length + i }))].sort((a, b) => a.pos - b.pos).map((p) => p.node);
1385
+ }
1299
1386
  const hasChildIndex = packageNodes.some((p) => p.childIndex != null);
1300
1387
  if (!hasChildIndex) {
1301
1388
  return [...leafNodes, ...packageNodes.map((p) => ({ node: p.node, pos: Number.MAX_SAFE_INTEGER }))].sort((a, b) => a.pos - b.pos).map((p) => p.node);
@@ -1335,7 +1422,7 @@ function apiPackageChildNode(ctx, scoped, scopeSegs, parentApiDefinitionId, scop
1335
1422
  featureFlags: metaFeatureFlags(seg.metadata)
1336
1423
  }),
1337
1424
  apiDefinitionId: ApiDefinitionId(apiDefinitionId),
1338
- availability: metaStr(seg.metadata, "availability"),
1425
+ availability: metaAvailability(seg.metadata),
1339
1426
  overviewPageId: overviewPageId != null ? PageId(overviewPageId) : void 0,
1340
1427
  noindex: metaBool(overview?.metadata, "noindex") ?? metaBool(seg.metadata, "noindex"),
1341
1428
  pointsTo: metaPointsTo != null ? pointsToSlug(metaPointsTo) : void 0,
@@ -1423,10 +1510,10 @@ function apiReferenceNode(ctx, scoped, scopeSegs, scopePrefix) {
1423
1510
  featureFlags: metaFeatureFlags(seg.metadata)
1424
1511
  }),
1425
1512
  apiDefinitionId: ApiDefinitionId(apiDefinitionId),
1426
- availability: metaStr(seg.metadata, "availability"),
1513
+ availability: metaAvailability(seg.metadata),
1427
1514
  overviewPageId: overviewPageId != null ? PageId(overviewPageId) : void 0,
1428
1515
  noindex: metaBool(overview?.metadata, "noindex") ?? metaBool(seg.metadata, "noindex"),
1429
- paginated: true,
1516
+ paginated: metaBool(seg.metadata, "paginated"),
1430
1517
  showErrors: metaBool(seg.metadata, "showErrors"),
1431
1518
  hideTitle: metaBool(seg.metadata, "hideTitle"),
1432
1519
  pointsTo: metaPointsTo != null ? pointsToSlug(metaPointsTo) : void 0,
@@ -1444,7 +1531,10 @@ function attachedApiChangelogNode(ctx, scoped, scopeSegs, apiDefinitionId, scope
1444
1531
  }
1445
1532
  return metaStr(candidate.seg.metadata, "apiDefinitionId") === apiDefinitionId;
1446
1533
  });
1447
- const changelogSeg = candidates.find((candidate) => parentSectionPath(candidate.seg.section) === seg.section) ?? candidates[0];
1534
+ const apiReferenceCount = scopeSegs.filter((candidate) => {
1535
+ return metaStr(candidate.seg.metadata, "type") === "apiReference" && metaStr(candidate.seg.metadata, "apiDefinitionId") === apiDefinitionId;
1536
+ }).length;
1537
+ const changelogSeg = candidates.find((candidate) => parentSectionPath(candidate.seg.section) === seg.section) ?? (apiReferenceCount === 1 ? candidates[0] : void 0);
1448
1538
  return changelogSeg != null ? changelogNode(ctx, changelogSeg, scopePrefix) : void 0;
1449
1539
  }
1450
1540
  function hasOwningApiReference(scoped, scopeSegs) {
@@ -1452,12 +1542,51 @@ function hasOwningApiReference(scoped, scopeSegs) {
1452
1542
  if (apiDefinitionId == null || metaStr(scoped.seg.metadata, "type") !== "changelog") {
1453
1543
  return false;
1454
1544
  }
1455
- return scopeSegs.some((candidate) => {
1545
+ const candidates = scopeSegs.filter((candidate) => {
1456
1546
  if (metaStr(candidate.seg.metadata, "type") !== "apiReference") {
1457
1547
  return false;
1458
1548
  }
1459
1549
  return metaStr(candidate.seg.metadata, "apiDefinitionId") === apiDefinitionId;
1460
1550
  });
1551
+ return candidates.some((candidate) => parentSectionPath(scoped.seg.section) === candidate.seg.section) || candidates.length === 1;
1552
+ }
1553
+ function isNestedApiPackage(scoped, scopeSegs) {
1554
+ if (metaStr(scoped.seg.metadata, "type") !== "apiPackage") {
1555
+ return false;
1556
+ }
1557
+ const apiDefinitionId = metaStr(scoped.seg.metadata, "apiDefinitionId");
1558
+ if (apiDefinitionId == null) {
1559
+ return false;
1560
+ }
1561
+ const apiReferenceSections = new Set(
1562
+ scopeSegs.filter(
1563
+ (s) => metaStr(s.seg.metadata, "type") === "apiReference" && metaStr(s.seg.metadata, "apiDefinitionId") === apiDefinitionId
1564
+ ).map((s) => s.seg.section)
1565
+ );
1566
+ if (apiReferenceSections.size === 0) {
1567
+ return false;
1568
+ }
1569
+ const sectionPaths = new Set(scopeSegs.map((s) => s.seg.section));
1570
+ const resolveParent = (section) => {
1571
+ const parent = parentSectionPath(section);
1572
+ if (parent === "" || sectionPaths.has(parent)) {
1573
+ return parent;
1574
+ }
1575
+ return nearestExistingAncestor(section, sectionPaths);
1576
+ };
1577
+ let current = scoped.seg.section;
1578
+ const seen = /* @__PURE__ */ new Set([current]);
1579
+ for (; ; ) {
1580
+ const parent = resolveParent(current);
1581
+ if (apiReferenceSections.has(parent)) {
1582
+ return true;
1583
+ }
1584
+ if (parent === "" || seen.has(parent)) {
1585
+ return false;
1586
+ }
1587
+ seen.add(parent);
1588
+ current = parent;
1589
+ }
1461
1590
  }
1462
1591
  function changelogNode(ctx, scoped, scopePrefix) {
1463
1592
  const { seg, nav } = scoped;
@@ -1562,7 +1691,11 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
1562
1691
  if (sec === "" || type === "tabRoot") {
1563
1692
  return false;
1564
1693
  }
1565
- if (hasOwningApiReference(s, scopeSegs)) {
1694
+ if (hasOwningApiReference(s, scopeSegs) || isNestedApiPackage(s, scopeSegs)) {
1695
+ return false;
1696
+ }
1697
+ const depth = metaNum(s.seg.metadata, "sidebarDepth");
1698
+ if (depth === 0) {
1566
1699
  return false;
1567
1700
  }
1568
1701
  const parent = parentSectionPath(sec);
@@ -1574,6 +1707,7 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
1574
1707
  }
1575
1708
  return false;
1576
1709
  }).sort((a, b) => a.seg.sortOrder - b.seg.sortOrder);
1710
+ const siblingBoundaries = computeDuplicateSiblingSortBoundaries(direct);
1577
1711
  return direct.map((s) => {
1578
1712
  const type = metaStr(s.seg.metadata, "type");
1579
1713
  const childIndex = metaNum(s.seg.metadata, "childIndex");
@@ -1583,10 +1717,14 @@ function buildSectionTree(ctx, scopeSegs, parentPath, scopePrefix, changelogScop
1583
1717
  } else if (type === "changelog") {
1584
1718
  node = changelogNode(ctx, s, changelogScopePrefix ?? scopePrefix);
1585
1719
  } else {
1720
+ const boundary = siblingBoundaries.get(s);
1721
+ const childScopeSegs = boundary != null ? scopeSegs.filter(
1722
+ (candidate) => candidate.seg.sortOrder >= boundary.lo && candidate.seg.sortOrder < boundary.hi
1723
+ ) : scopeSegs;
1586
1724
  node = sectionNode(
1587
1725
  ctx,
1588
1726
  s,
1589
- buildSectionTree(ctx, scopeSegs, s.seg.section, scopePrefix, changelogScopePrefix),
1727
+ buildSectionTree(ctx, childScopeSegs, s.seg.section, scopePrefix, changelogScopePrefix),
1590
1728
  scopePrefix
1591
1729
  );
1592
1730
  }
@@ -1600,11 +1738,16 @@ function computeSiblingSortBoundaries(ordered) {
1600
1738
  for (const s of ordered) {
1601
1739
  const type = metaStr(s.seg.metadata, "type");
1602
1740
  const sec = s.seg.section;
1603
- if (type !== "section" || sec === "") {
1741
+ if (type !== "section") {
1742
+ continue;
1743
+ }
1744
+ if (sec === "") {
1745
+ rootSections.push(s);
1604
1746
  continue;
1605
1747
  }
1748
+ const depth = metaNum(s.seg.metadata, "sidebarDepth");
1606
1749
  const parent = parentSectionPath(sec);
1607
- const isRootLevel = parent === "" || !sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "";
1750
+ const isRootLevel = depth === 0 || parent === "" || !sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "";
1608
1751
  if (isRootLevel) {
1609
1752
  rootSections.push(s);
1610
1753
  }
@@ -1631,14 +1774,24 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1631
1774
  const ordered = [...scopeSegs].sort((a, b) => a.seg.sortOrder - b.seg.sortOrder);
1632
1775
  const sectionPaths = new Set(ordered.map((s) => s.seg.section));
1633
1776
  const annotated = [];
1634
- const hasRootSection = ordered.some((s) => metaStr(s.seg.metadata, "type") === "section" && s.seg.section === "");
1635
1777
  const siblingBoundaries = computeSiblingSortBoundaries(ordered);
1778
+ const hasRootSection = ordered.some(
1779
+ (s) => metaStr(s.seg.metadata, "type") === "section" && s.seg.section === "" && (metaNum(s.seg.metadata, "childIndex") == null || siblingBoundaries.has(s))
1780
+ );
1636
1781
  for (const s of ordered) {
1637
1782
  const type = metaStr(s.seg.metadata, "type");
1638
1783
  const sec = s.seg.section;
1639
- if (hasOwningApiReference(s, scopeSegs)) {
1784
+ if (hasOwningApiReference(s, scopeSegs) || isNestedApiPackage(s, scopeSegs)) {
1640
1785
  continue;
1641
1786
  }
1787
+ if (type === "apiPackage") {
1788
+ const hasApiRefSibling = ordered.some(
1789
+ (sib) => sib.seg.section === sec && metaStr(sib.seg.metadata, "type") === "apiReference"
1790
+ );
1791
+ if (hasApiRefSibling) {
1792
+ continue;
1793
+ }
1794
+ }
1642
1795
  if (type === "tabRoot" && metaBool(s.seg.metadata, "landingPage") === true) {
1643
1796
  continue;
1644
1797
  }
@@ -1651,15 +1804,18 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1651
1804
  }
1652
1805
  continue;
1653
1806
  }
1654
- if (type === "section" && sec === "") {
1655
- const sectionChildren = buildSectionTree(ctx, scopeSegs, "", scopePrefix);
1807
+ if (type === "section" && sec === "" && hasRootSection) {
1808
+ const bounds = siblingBoundaries.get(s);
1809
+ const ownedSegs = bounds != null ? scopeSegs.filter((seg) => seg.seg.sortOrder >= bounds.lo && seg.seg.sortOrder < bounds.hi) : scopeSegs;
1810
+ const sectionChildren = buildSectionTree(ctx, ownedSegs, "", scopePrefix, changelogScopePrefix);
1656
1811
  const node = sectionNode(ctx, s, sectionChildren, scopePrefix);
1657
1812
  annotated.push({ node, pos: metaNum(s.seg.metadata, "childIndex"), isLeaf: false });
1658
1813
  continue;
1659
1814
  }
1815
+ const depth = metaNum(s.seg.metadata, "sidebarDepth");
1660
1816
  const parent = parentSectionPath(sec);
1661
- const isRootLevel = parent === "" || !sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "";
1662
- if (isRootLevel && hasRootSection && sec !== "") {
1817
+ const isRootLevel = depth === 0 || parent === "" || !sectionPaths.has(parent) && nearestExistingAncestor(sec, sectionPaths) === "";
1818
+ if (isRootLevel && hasRootSection && sec !== "" && depth !== 0) {
1663
1819
  continue;
1664
1820
  }
1665
1821
  if (isRootLevel) {
@@ -1671,12 +1827,9 @@ function buildSidebarRootChildren(ctx, scopeSegs, scopePrefix, changelogScopePre
1671
1827
  } else {
1672
1828
  const bounds = siblingBoundaries.get(s);
1673
1829
  const ownedSegs = bounds != null ? scopeSegs.filter((seg) => seg.seg.sortOrder >= bounds.lo && seg.seg.sortOrder < bounds.hi) : scopeSegs;
1674
- node = sectionNode(
1675
- ctx,
1676
- s,
1677
- buildSectionTree(ctx, ownedSegs, sec, scopePrefix, changelogScopePrefix),
1678
- scopePrefix
1679
- );
1830
+ const isUnboundedSkipSlugSibling = sec === "" && metaNum(s.seg.metadata, "childIndex") != null && bounds == null;
1831
+ const sectionChildren = isUnboundedSkipSlugSibling ? [] : buildSectionTree(ctx, ownedSegs, sec, scopePrefix, changelogScopePrefix);
1832
+ node = sectionNode(ctx, s, sectionChildren, scopePrefix);
1680
1833
  }
1681
1834
  const isSharedSection = siblingBoundaries.size > 0 && scopePrefix !== "" && sec !== "" && !sec.startsWith(scopePrefix);
1682
1835
  annotated.push({
@@ -1714,10 +1867,6 @@ function groupSidebarRootChildren(ctx, children) {
1714
1867
  } else if (child.type === "section" && !child.collapsible) {
1715
1868
  flushRun();
1716
1869
  out.push(child);
1717
- } else if (child.type === "changelog") {
1718
- flushRun();
1719
- run.push(child);
1720
- flushRun();
1721
1870
  } else {
1722
1871
  run.push(child);
1723
1872
  }
@@ -1832,7 +1981,7 @@ function buildVariantedNode(ctx, variants, scopeSegs, scopePrefix) {
1832
1981
  const variantIndividualSlug = detailSlug(variant);
1833
1982
  const variantSlug = variantIndividualSlug !== "" ? asSlug(slugjoin(scopePrefix, variantIndividualSlug)) : scopePrefix;
1834
1983
  const metaPointsTo = metaStr(variant.metadata, "pointsTo");
1835
- const children = buildSidebarRootChildren(ctx, variantSegs, scopePrefix);
1984
+ const children = buildSidebarRootChildren(ctx, variantSegs, variantSlug);
1836
1985
  return {
1837
1986
  type: "variant",
1838
1987
  ...withMetadataDefaults({
@@ -2234,6 +2383,7 @@ function buildProductGroup(ctx, products, scoped, rootSlug, skipSharedSectionMer
2234
2383
  };
2235
2384
  return node;
2236
2385
  });
2386
+ markCrossProductCanonicalSlugs(children);
2237
2387
  return {
2238
2388
  type: "productgroup",
2239
2389
  id: ctx.nodeId("productgroup"),
@@ -2245,6 +2395,32 @@ function buildProductGroup(ctx, products, scoped, rootSlug, skipSharedSectionMer
2245
2395
  children
2246
2396
  };
2247
2397
  }
2398
+ function markCrossProductCanonicalSlugs(productNodes) {
2399
+ const pageIdToCanonical = /* @__PURE__ */ new Map();
2400
+ const sorted = [...productNodes].sort((a, b) => {
2401
+ if (a.default !== b.default) {
2402
+ return a.default ? -1 : 1;
2403
+ }
2404
+ return 0;
2405
+ });
2406
+ for (const product of sorted) {
2407
+ traverseDF(product, (child) => {
2408
+ if (hasMetadata(child) && isPage(child)) {
2409
+ const pid = getPageId(child);
2410
+ if (pid == null) {
2411
+ return;
2412
+ }
2413
+ const key = `pid:${pid}`;
2414
+ const canonical = pageIdToCanonical.get(key);
2415
+ if (canonical != null && !product.default) {
2416
+ child.canonicalSlug = canonical;
2417
+ } else if (canonical == null) {
2418
+ pageIdToCanonical.set(key, child.canonicalSlug ?? child.slug);
2419
+ }
2420
+ }
2421
+ });
2422
+ }
2423
+ }
2248
2424
  export {
2249
2425
  apiLeafNodeFromNavRoute,
2250
2426
  buildFullRootFromSegments,