@voxgig/apidef 8.18.1 → 8.20.0

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/src/utility.ts CHANGED
@@ -1624,7 +1624,19 @@ function envelopeProp(resprops: any, opname: string): string | null {
1624
1624
  return null
1625
1625
  }
1626
1626
 
1627
- const structured = keys.filter((k: string) => isEntityWrapperProp(resprops[k]))
1627
+ let structured = keys.filter((k: string) => isEntityWrapperProp(resprops[k]))
1628
+
1629
+ // A page's own metadata object, such as Vapi's `metadata` or Neon's
1630
+ // `pagination`, sits beside its records and is not a second candidate. A
1631
+ // list under such a name is records, such as Maxio's custom field metadata.
1632
+ if ('list' === opname) {
1633
+ const records = structured.filter((k: string) =>
1634
+ !isPageMetaProp(k) || true === propIsList(resprops[k]))
1635
+ if (1 === records.length && isRecordList(resprops[records[0]])) {
1636
+ structured = records
1637
+ }
1638
+ }
1639
+
1628
1640
  if (1 !== structured.length) {
1629
1641
  return null
1630
1642
  }
@@ -1666,10 +1678,11 @@ function isEnvelopeStatusProp(name: string): boolean {
1666
1678
  const ENVELOPE_PAGING_PROPS = new Set([
1667
1679
  'count', 'total', 'totalcount', 'totalhits', 'totalitems', 'totalpages',
1668
1680
  'totalresults', 'page', 'pages', 'pagecount', 'pagenumber', 'pagesize',
1669
- 'perpage', 'limit', 'offset', 'cursor', 'next', 'nextcursor', 'nextpage',
1681
+ 'size', 'perpage', 'limit', 'offset', 'cursor', 'next', 'nextcursor', 'nextpage',
1670
1682
  'nextpagetoken', 'nexttoken', 'nexturl', 'previous', 'prev',
1671
1683
  'previouscursor', 'prevcursor', 'previouspage', 'prevpage', 'previousurl',
1672
1684
  'prevurl', 'hasmore', 'hasnext', 'hasprevious', 'object', 'url',
1685
+ 'currentpage',
1673
1686
  ])
1674
1687
 
1675
1688
 
@@ -1678,10 +1691,44 @@ function isEnvelopePagingProp(name: string): boolean {
1678
1691
  }
1679
1692
 
1680
1693
 
1681
- // Paging, or a count that describes the page, such as the number of Lob's QR
1682
- // codes on the page that were scanned at least once.
1694
+ // A list whose items are objects. GitHub's feed holds a list of URL strings
1695
+ // beside its links, and a page of strings is not a page of records.
1696
+ function isRecordList(prop: any): boolean {
1697
+ return isObjectSchema(true === propIsList(prop) ? prop?.items : null)
1698
+ }
1699
+
1700
+
1701
+ // An object, or a composition with a branch that is one. A nullable string
1702
+ // written as a oneOf is not.
1703
+ function isObjectSchema(schema: any): boolean {
1704
+ if (null == schema || 'object' !== typeof schema) {
1705
+ return false
1706
+ }
1707
+ if (null != schema.$ref || null != schema.properties || 'object' === schema.type) {
1708
+ return true
1709
+ }
1710
+ return ['allOf', 'oneOf', 'anyOf'].some((k: string) =>
1711
+ Array.isArray(schema[k]) && schema[k].some(isObjectSchema))
1712
+ }
1713
+
1714
+
1715
+ // The object a page may carry about itself beside its records, compared as
1716
+ // the paging names are.
1717
+ const PAGE_META_PROPS = new Set([
1718
+ 'meta', 'metadata', 'pagination', 'paging', 'pageinfo', 'links',
1719
+ ])
1720
+
1721
+
1722
+ function isPageMetaProp(name: string): boolean {
1723
+ return PAGE_META_PROPS.has(name.toLowerCase().replace(/[_-]/g, ''))
1724
+ }
1725
+
1726
+
1727
+ // Paging, the page's own metadata, or a count that describes the page, such
1728
+ // as the number of Lob's QR codes on the page that were scanned at least once.
1683
1729
  function isEnvelopePageProp(name: string): boolean {
1684
- return isEnvelopePagingProp(name) || name.toLowerCase().replace(/[_-]/g, '').endsWith('count')
1730
+ return isEnvelopePagingProp(name) || isPageMetaProp(name) ||
1731
+ name.toLowerCase().replace(/[_-]/g, '').endsWith('count')
1685
1732
  }
1686
1733
 
1687
1734