@0xobelisk/graphql-client 1.2.0-pre.99 → 2.0.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/dist/index.js CHANGED
@@ -37,12 +37,25 @@ var src_exports = {};
37
37
  __export(src_exports, {
38
38
  DubheGraphqlClient: () => DubheGraphqlClient,
39
39
  QueryBuilders: () => QueryBuilders,
40
- createDubheGraphqlClient: () => createDubheGraphqlClient
40
+ ZERO_ADDRESS: () => ZERO_ADDRESS,
41
+ createDubheGraphqlClient: () => createDubheGraphqlClient,
42
+ decodeAddress: () => decodeAddress,
43
+ decodeBool: () => decodeBool,
44
+ decodeString: () => decodeString,
45
+ decodeU128: () => decodeU128,
46
+ decodeU16: () => decodeU16,
47
+ decodeU32: () => decodeU32,
48
+ decodeU64: () => decodeU64,
49
+ decodeU8: () => decodeU8,
50
+ decodeVectorAddress: () => decodeVectorAddress,
51
+ hexToBytes: () => hexToBytes,
52
+ parseRecordData: () => parseRecordData
41
53
  });
42
54
  module.exports = __toCommonJS(src_exports);
43
55
 
44
56
  // src/client.ts
45
57
  var import_client2 = require("@apollo/client");
58
+ var import_batch_http = require("@apollo/client/link/batch-http");
46
59
  var import_retry = require("@apollo/client/link/retry");
47
60
  var import_subscriptions = require("@apollo/client/link/subscriptions");
48
61
  var import_utilities = require("@apollo/client/utilities");
@@ -757,6 +770,77 @@ var import_graphql = require("graphql");
757
770
 
758
771
  // src/client.ts
759
772
  var import_pluralize = __toESM(require("pluralize"));
773
+ var SYSTEM_TABLE_FIELDS = {
774
+ dubheDappMarketplaceFees: [
775
+ "dappKey",
776
+ "listingId",
777
+ "coinType",
778
+ "totalFee",
779
+ "treasuryAmount",
780
+ "dappAmount",
781
+ "updatedAtCheckpoint",
782
+ "lastUpdateDigest"
783
+ ],
784
+ dubheDappRuntimeState: [
785
+ "dappKey",
786
+ "admin",
787
+ "paused",
788
+ "settlementMode",
789
+ "creditPool",
790
+ "writeFeeShareBps",
791
+ "lastRuntimeEvent",
792
+ "lastRuntimeActor",
793
+ "lastRuntimeAmount",
794
+ "updatedAtCheckpoint",
795
+ "lastUpdateDigest"
796
+ ],
797
+ dubheDappFeeState: [
798
+ "entityId",
799
+ "baseFeePerWrite",
800
+ "bytesFeePerByte",
801
+ "freeCredit",
802
+ "creditPool",
803
+ "totalSettled",
804
+ "updatedAtTimestampMs",
805
+ "lastUpdateDigest"
806
+ ],
807
+ dubheDappRevenueState: [
808
+ "entityId",
809
+ "dappRevenue",
810
+ "coinType",
811
+ "updatedAtTimestampMs",
812
+ "lastUpdateDigest"
813
+ ],
814
+ dubheMarketplaceListings: [
815
+ "dappKey",
816
+ "listingId",
817
+ "seller",
818
+ "recordType",
819
+ "price",
820
+ "coinType",
821
+ "isFungible",
822
+ "listedUntil",
823
+ "status",
824
+ "updatedAtCheckpoint",
825
+ "lastUpdateDigest"
826
+ ],
827
+ dubheSessions: [
828
+ "dappKey",
829
+ "canonical",
830
+ "sessionWallet",
831
+ "expiresAt",
832
+ "active",
833
+ "updatedAtCheckpoint",
834
+ "lastUpdateDigest"
835
+ ],
836
+ dubheUserStorages: [
837
+ "dappKey",
838
+ "canonicalOwner",
839
+ "userStorageId",
840
+ "updatedAtCheckpoint",
841
+ "lastUpdateDigest"
842
+ ]
843
+ };
760
844
  function mapCachePolicyToFetchPolicy(cachePolicy) {
761
845
  switch (cachePolicy) {
762
846
  case "cache-first":
@@ -773,6 +857,23 @@ function mapCachePolicyToFetchPolicy(cachePolicy) {
773
857
  return "cache-first";
774
858
  }
775
859
  }
860
+ function buildHttpLink(config) {
861
+ const fetchFn = (input, init) => fetch(input, { ...config.fetchOptions, ...init ?? {} });
862
+ if (config.batchRequests) {
863
+ return new import_batch_http.BatchHttpLink({
864
+ uri: config.endpoint,
865
+ headers: config.headers,
866
+ fetch: fetchFn,
867
+ batchInterval: config.batchInterval ?? 10,
868
+ batchMax: config.batchMax ?? 20
869
+ });
870
+ }
871
+ return (0, import_client2.createHttpLink)({
872
+ uri: config.endpoint,
873
+ headers: config.headers,
874
+ fetch: fetchFn
875
+ });
876
+ }
776
877
  var DubheGraphqlClient = class {
777
878
  // Store current configuration for updates
778
879
  constructor(config) {
@@ -783,11 +884,7 @@ var DubheGraphqlClient = class {
783
884
  if (this.dubheMetadata) {
784
885
  this.parseTableInfoFromConfig();
785
886
  }
786
- const httpLink = (0, import_client2.createHttpLink)({
787
- uri: config.endpoint,
788
- headers: config.headers,
789
- fetch: (input, init) => fetch(input, { ...config.fetchOptions, ...init })
790
- });
887
+ const httpLink = buildHttpLink(config);
791
888
  const retryLink = new import_retry.RetryLink({
792
889
  delay: {
793
890
  // Initial retry delay time (milliseconds)
@@ -908,11 +1005,7 @@ var DubheGraphqlClient = class {
908
1005
  }
909
1006
  this.subscriptionClient = void 0;
910
1007
  }
911
- const httpLink = (0, import_client2.createHttpLink)({
912
- uri: this.currentConfig.endpoint,
913
- headers: this.currentConfig.headers,
914
- fetch: (input, init) => fetch(input, { ...this.currentConfig.fetchOptions, ...init })
915
- });
1008
+ const httpLink = buildHttpLink(this.currentConfig);
916
1009
  const retryLink = new import_retry.RetryLink({
917
1010
  delay: {
918
1011
  initial: this.currentConfig.retryOptions?.delay?.initial || 300,
@@ -1364,6 +1457,430 @@ var DubheGraphqlClient = class {
1364
1457
  return () => subscription.subscribe().unsubscribe();
1365
1458
  });
1366
1459
  }
1460
+ /**
1461
+ * Query marketplace listings indexed by the Dubhe indexer.
1462
+ * Uses the marketplace_listings PostgreSQL table (exposed as dubheMarketplaceListings in GraphQL).
1463
+ * The record_type field is pre-decoded text ("wheat", "corn", …) and status tracks
1464
+ * active/sold/cancelled directly — no extra RPC calls needed.
1465
+ */
1466
+ async getMarketplaceListings(options) {
1467
+ const filter = {};
1468
+ if (options?.dappKey)
1469
+ filter.dappKey = { equalTo: options.dappKey };
1470
+ if (options?.status !== void 0)
1471
+ filter.status = { equalTo: options.status };
1472
+ if (options?.recordType)
1473
+ filter.recordType = { equalTo: options.recordType };
1474
+ if (options?.seller)
1475
+ filter.seller = { equalTo: options.seller };
1476
+ const query = import_client2.gql`
1477
+ query GetMarketplaceListings(
1478
+ $first: Int
1479
+ $after: Cursor
1480
+ $filter: StoreDubheMarketplaceListingFilter
1481
+ $orderBy: [StoreDubheMarketplaceListingsOrderBy!]
1482
+ ) {
1483
+ dubheMarketplaceListings(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
1484
+ totalCount
1485
+ pageInfo {
1486
+ hasNextPage
1487
+ hasPreviousPage
1488
+ startCursor
1489
+ endCursor
1490
+ }
1491
+ edges {
1492
+ cursor
1493
+ node {
1494
+ listingId
1495
+ dappKey
1496
+ seller
1497
+ recordType
1498
+ recordDataRaw
1499
+ price
1500
+ coinType
1501
+ isFungible
1502
+ status
1503
+ buyer
1504
+ listedUntil
1505
+ createdAtCheckpoint
1506
+ updatedAtCheckpoint
1507
+ lastUpdateDigest
1508
+ }
1509
+ }
1510
+ }
1511
+ }
1512
+ `;
1513
+ const result = await this.apolloClient.query({
1514
+ query,
1515
+ variables: {
1516
+ first: options?.first ?? 100,
1517
+ after: options?.after,
1518
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
1519
+ orderBy: ["CREATED_AT_CHECKPOINT_DESC"]
1520
+ },
1521
+ fetchPolicy: "network-only"
1522
+ });
1523
+ if (result.error)
1524
+ throw result.error;
1525
+ return result.data?.dubheMarketplaceListings ?? {
1526
+ edges: [],
1527
+ pageInfo: { hasNextPage: false, hasPreviousPage: false },
1528
+ totalCount: 0
1529
+ };
1530
+ }
1531
+ /**
1532
+ * Query session keys indexed by the Dubhe indexer (dubheSessions in GraphQL).
1533
+ */
1534
+ async getDubheSessions(options) {
1535
+ const filter = {};
1536
+ if (options?.dappKey)
1537
+ filter.dappKey = { equalTo: options.dappKey };
1538
+ if (options?.canonical)
1539
+ filter.canonical = { equalTo: options.canonical };
1540
+ if (options?.active !== void 0)
1541
+ filter.active = { equalTo: options.active };
1542
+ const query = import_client2.gql`
1543
+ query GetDubheSessions(
1544
+ $first: Int
1545
+ $after: Cursor
1546
+ $filter: StoreDubheSessionFilter
1547
+ $orderBy: [StoreDubheSessionsOrderBy!]
1548
+ ) {
1549
+ dubheSessions(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
1550
+ totalCount
1551
+ pageInfo {
1552
+ hasNextPage
1553
+ hasPreviousPage
1554
+ startCursor
1555
+ endCursor
1556
+ }
1557
+ edges {
1558
+ cursor
1559
+ node {
1560
+ dappKey
1561
+ canonical
1562
+ sessionWallet
1563
+ expiresAt
1564
+ active
1565
+ updatedAtCheckpoint
1566
+ lastUpdateDigest
1567
+ lastEventSeq
1568
+ }
1569
+ }
1570
+ }
1571
+ }
1572
+ `;
1573
+ const result = await this.apolloClient.query({
1574
+ query,
1575
+ variables: {
1576
+ first: options?.first ?? 100,
1577
+ after: options?.after,
1578
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
1579
+ orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
1580
+ },
1581
+ fetchPolicy: "network-only"
1582
+ });
1583
+ if (result.error)
1584
+ throw result.error;
1585
+ return result.data?.dubheSessions ?? {
1586
+ edges: [],
1587
+ pageInfo: { hasNextPage: false, hasPreviousPage: false },
1588
+ totalCount: 0
1589
+ };
1590
+ }
1591
+ /**
1592
+ * Query user storage registrations indexed by the Dubhe indexer (dubheUserStorages in GraphQL).
1593
+ */
1594
+ async getDubheUserStorages(options) {
1595
+ const filter = {};
1596
+ if (options?.dappKey)
1597
+ filter.dappKey = { equalTo: options.dappKey };
1598
+ if (options?.canonicalOwner)
1599
+ filter.canonicalOwner = { equalTo: options.canonicalOwner };
1600
+ const query = import_client2.gql`
1601
+ query GetDubheUserStorages(
1602
+ $first: Int
1603
+ $after: Cursor
1604
+ $filter: StoreDubheUserStorageFilter
1605
+ $orderBy: [StoreDubheUserStoragesOrderBy!]
1606
+ ) {
1607
+ dubheUserStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
1608
+ totalCount
1609
+ pageInfo {
1610
+ hasNextPage
1611
+ hasPreviousPage
1612
+ startCursor
1613
+ endCursor
1614
+ }
1615
+ edges {
1616
+ cursor
1617
+ node {
1618
+ dappKey
1619
+ canonicalOwner
1620
+ userStorageId
1621
+ createdAtCheckpoint
1622
+ updatedAtCheckpoint
1623
+ lastUpdateDigest
1624
+ lastEventSeq
1625
+ }
1626
+ }
1627
+ }
1628
+ }
1629
+ `;
1630
+ const result = await this.apolloClient.query({
1631
+ query,
1632
+ variables: {
1633
+ first: options?.first ?? 100,
1634
+ after: options?.after,
1635
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
1636
+ orderBy: ["CREATED_AT_CHECKPOINT_DESC"]
1637
+ },
1638
+ fetchPolicy: "network-only"
1639
+ });
1640
+ if (result.error)
1641
+ throw result.error;
1642
+ return result.data?.dubheUserStorages ?? {
1643
+ edges: [],
1644
+ pageInfo: { hasNextPage: false, hasPreviousPage: false },
1645
+ totalCount: 0
1646
+ };
1647
+ }
1648
+ /**
1649
+ * Query SceneStorage system rows indexed by the Dubhe indexer
1650
+ * (scene_storages table, exposed as dubheSceneStorages in GraphQL).
1651
+ * Field values live in the companion scene_storage_fields table —
1652
+ * see getSceneStorageFields.
1653
+ */
1654
+ async getSceneStorages(options) {
1655
+ const filter = {};
1656
+ if (options?.dappKey)
1657
+ filter.dappKey = { equalTo: options.dappKey };
1658
+ if (options?.sceneType)
1659
+ filter.sceneType = { equalTo: options.sceneType };
1660
+ if (options?.sceneId)
1661
+ filter.sceneId = { equalTo: options.sceneId };
1662
+ if (options?.isDestroyed !== void 0)
1663
+ filter.isDestroyed = { equalTo: options.isDestroyed };
1664
+ const query = import_client2.gql`
1665
+ query GetSceneStorages(
1666
+ $first: Int
1667
+ $after: Cursor
1668
+ $filter: StoreDubheSceneStorageFilter
1669
+ $orderBy: [StoreDubheSceneStoragesOrderBy!]
1670
+ ) {
1671
+ dubheSceneStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
1672
+ totalCount
1673
+ pageInfo {
1674
+ hasNextPage
1675
+ hasPreviousPage
1676
+ startCursor
1677
+ endCursor
1678
+ }
1679
+ edges {
1680
+ cursor
1681
+ node {
1682
+ sceneId
1683
+ dappKey
1684
+ sceneType
1685
+ authorizationKind
1686
+ authorizedPermitId
1687
+ isDestroyed
1688
+ createdAtCheckpoint
1689
+ updatedAtCheckpoint
1690
+ lastUpdateDigest
1691
+ lastEventSeq
1692
+ }
1693
+ }
1694
+ }
1695
+ }
1696
+ `;
1697
+ const result = await this.apolloClient.query({
1698
+ query,
1699
+ variables: {
1700
+ first: options?.first ?? 100,
1701
+ after: options?.after,
1702
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
1703
+ orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
1704
+ },
1705
+ fetchPolicy: "network-only"
1706
+ });
1707
+ if (result.error)
1708
+ throw result.error;
1709
+ return result.data?.dubheSceneStorages ?? {
1710
+ edges: [],
1711
+ pageInfo: { hasNextPage: false, hasPreviousPage: false },
1712
+ totalCount: 0
1713
+ };
1714
+ }
1715
+ /**
1716
+ * Query raw field rows of SceneStorages (scene_storage_fields table,
1717
+ * exposed as dubheSceneStorageFields in GraphQL). Values are hex-encoded
1718
+ * BCS — decode with the decoders exported from this package.
1719
+ */
1720
+ async getSceneStorageFields(options) {
1721
+ const filter = {};
1722
+ if (options?.dappKey)
1723
+ filter.dappKey = { equalTo: options.dappKey };
1724
+ if (options?.sceneIds && options.sceneIds.length > 0)
1725
+ filter.sceneId = { in: options.sceneIds };
1726
+ if (options?.sceneId)
1727
+ filter.sceneId = { equalTo: options.sceneId };
1728
+ if (options?.fieldName)
1729
+ filter.fieldName = { equalTo: options.fieldName };
1730
+ if (options?.isDeleted !== void 0)
1731
+ filter.isDeleted = { equalTo: options.isDeleted };
1732
+ const query = import_client2.gql`
1733
+ query GetSceneStorageFields(
1734
+ $first: Int
1735
+ $after: Cursor
1736
+ $filter: StoreDubheSceneStorageFieldFilter
1737
+ $orderBy: [StoreDubheSceneStorageFieldsOrderBy!]
1738
+ ) {
1739
+ dubheSceneStorageFields(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
1740
+ totalCount
1741
+ pageInfo {
1742
+ hasNextPage
1743
+ hasPreviousPage
1744
+ startCursor
1745
+ endCursor
1746
+ }
1747
+ edges {
1748
+ cursor
1749
+ node {
1750
+ sceneId
1751
+ dappKey
1752
+ sceneType
1753
+ fieldName
1754
+ fieldValueRaw
1755
+ isDeleted
1756
+ updatedAtCheckpoint
1757
+ lastUpdateDigest
1758
+ lastEventSeq
1759
+ }
1760
+ }
1761
+ }
1762
+ }
1763
+ `;
1764
+ const result = await this.apolloClient.query({
1765
+ query,
1766
+ variables: {
1767
+ first: options?.first ?? 1e3,
1768
+ after: options?.after,
1769
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
1770
+ orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
1771
+ },
1772
+ fetchPolicy: "network-only"
1773
+ });
1774
+ if (result.error)
1775
+ throw result.error;
1776
+ return result.data?.dubheSceneStorageFields ?? {
1777
+ edges: [],
1778
+ pageInfo: { hasNextPage: false, hasPreviousPage: false },
1779
+ totalCount: 0
1780
+ };
1781
+ }
1782
+ /**
1783
+ * Query ObjectStorage system rows indexed by the Dubhe indexer
1784
+ * (object_storages table, exposed as dubheObjectStorages in GraphQL).
1785
+ */
1786
+ async getObjectStorages(options) {
1787
+ const filter = {};
1788
+ if (options?.dappKey)
1789
+ filter.dappKey = { equalTo: options.dappKey };
1790
+ if (options?.objectType)
1791
+ filter.objectType = { equalTo: options.objectType };
1792
+ if (options?.objectId)
1793
+ filter.objectId = { equalTo: options.objectId };
1794
+ if (options?.isDestroyed !== void 0)
1795
+ filter.isDestroyed = { equalTo: options.isDestroyed };
1796
+ const query = import_client2.gql`
1797
+ query GetObjectStorages(
1798
+ $first: Int
1799
+ $after: Cursor
1800
+ $filter: StoreDubheObjectStorageFilter
1801
+ $orderBy: [StoreDubheObjectStoragesOrderBy!]
1802
+ ) {
1803
+ dubheObjectStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
1804
+ totalCount
1805
+ pageInfo {
1806
+ hasNextPage
1807
+ hasPreviousPage
1808
+ startCursor
1809
+ endCursor
1810
+ }
1811
+ edges {
1812
+ cursor
1813
+ node {
1814
+ objectId
1815
+ dappKey
1816
+ objectType
1817
+ entityIdRaw
1818
+ isDestroyed
1819
+ createdAtCheckpoint
1820
+ updatedAtCheckpoint
1821
+ lastUpdateDigest
1822
+ lastEventSeq
1823
+ }
1824
+ }
1825
+ }
1826
+ }
1827
+ `;
1828
+ const result = await this.apolloClient.query({
1829
+ query,
1830
+ variables: {
1831
+ first: options?.first ?? 100,
1832
+ after: options?.after,
1833
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
1834
+ orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
1835
+ },
1836
+ fetchPolicy: "network-only"
1837
+ });
1838
+ if (result.error)
1839
+ throw result.error;
1840
+ return result.data?.dubheObjectStorages ?? {
1841
+ edges: [],
1842
+ pageInfo: { hasNextPage: false, hasPreviousPage: false },
1843
+ totalCount: 0
1844
+ };
1845
+ }
1846
+ /**
1847
+ * Query DApp runtime state (credit pool, admin, package version, etc.).
1848
+ * Exposed as dubheDappRuntimeStates in GraphQL.
1849
+ */
1850
+ async getDubheDappRuntimeState(dappKey) {
1851
+ const query = import_client2.gql`
1852
+ query GetDubheDappRuntimeState($filter: StoreDubheDappRuntimeStateFilter) {
1853
+ dubheDappRuntimeStates(first: 1, filter: $filter) {
1854
+ edges {
1855
+ node {
1856
+ dappKey
1857
+ admin
1858
+ dappStorageId
1859
+ packageId
1860
+ version
1861
+ creditPool
1862
+ paused
1863
+ settlementMode
1864
+ createdAt
1865
+ createdAtCheckpoint
1866
+ updatedAtCheckpoint
1867
+ lastUpdateDigest
1868
+ lastEventSeq
1869
+ }
1870
+ }
1871
+ }
1872
+ }
1873
+ `;
1874
+ const result = await this.apolloClient.query({
1875
+ query,
1876
+ variables: { filter: { dappKey: { equalTo: dappKey } } },
1877
+ fetchPolicy: "network-only"
1878
+ });
1879
+ if (result.error)
1880
+ throw result.error;
1881
+ const edges = result.data?.dubheDappRuntimeStates?.edges ?? [];
1882
+ return edges[0]?.node ?? null;
1883
+ }
1367
1884
  // Improved table name handling methods
1368
1885
  getFilterTypeName(tableName) {
1369
1886
  const singularName = this.getSingularTableName(tableName);
@@ -1623,15 +2140,55 @@ var DubheGraphqlClient = class {
1623
2140
  if (customFields && customFields.length > 0) {
1624
2141
  fields = customFields;
1625
2142
  } else {
1626
- const autoFields = this.getTableFields(tableName);
1627
- if (autoFields.length > 0) {
1628
- fields = autoFields;
2143
+ const systemFields = SYSTEM_TABLE_FIELDS[tableName];
2144
+ if (systemFields) {
2145
+ fields = systemFields;
1629
2146
  } else {
1630
- fields = ["createdAtTimestampMs", "updatedAtTimestampMs", "isDeleted", "lastUpdateDigest"];
2147
+ const autoFields = this.getTableFields(tableName);
2148
+ if (autoFields.length > 0) {
2149
+ fields = autoFields;
2150
+ } else {
2151
+ fields = [
2152
+ "createdAtTimestampMs",
2153
+ "updatedAtTimestampMs",
2154
+ "isDeleted",
2155
+ "lastUpdateDigest"
2156
+ ];
2157
+ }
1631
2158
  }
1632
2159
  }
1633
2160
  return fields.join("\n ");
1634
2161
  }
2162
+ // ── Typed system-table query methods ─────────────────────────────────────
2163
+ /** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
2164
+ async getDappFeeState() {
2165
+ const result = await this.getAllTables("dubheDappFeeState", { first: 1 }).catch(
2166
+ () => null
2167
+ );
2168
+ return result?.edges?.[0]?.node ?? null;
2169
+ }
2170
+ /** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
2171
+ async getDappRevenueState() {
2172
+ const result = await this.getAllTables("dubheDappRevenueState", { first: 1 }).catch(
2173
+ () => null
2174
+ );
2175
+ return result?.edges?.[0]?.node ?? null;
2176
+ }
2177
+ /** Latest DApp runtime state (admin, settlement mode, last event). */
2178
+ async getDappRuntimeState() {
2179
+ const result = await this.getAllTables("dubheDappRuntimeState", { first: 1 }).catch(
2180
+ () => null
2181
+ );
2182
+ return result?.edges?.[0]?.node ?? null;
2183
+ }
2184
+ /** Marketplace fee records (one row per listing sold). */
2185
+ async getDappMarketplaceFees(options) {
2186
+ return this.getAllTables("dubheDappMarketplaceFees", {
2187
+ first: options?.first ?? 20,
2188
+ after: options?.after,
2189
+ orderBy: [{ field: "updatedAtCheckpoint", direction: "DESC" }]
2190
+ });
2191
+ }
1635
2192
  };
1636
2193
  function createDubheGraphqlClient(config) {
1637
2194
  return new DubheGraphqlClient(config);
@@ -1692,10 +2249,97 @@ function toSnakeCaseForEnum(str) {
1692
2249
  }
1693
2250
  return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "").toUpperCase();
1694
2251
  }
2252
+
2253
+ // src/decoders.ts
2254
+ var ZERO_ADDRESS = "0x" + "0".repeat(64);
2255
+ function hexToBytes(hex) {
2256
+ const clean = hex.replace(/^0x/i, "");
2257
+ const pairs = clean.match(/../g) ?? [];
2258
+ return Uint8Array.from(pairs.map((b) => parseInt(b, 16)));
2259
+ }
2260
+ function readUIntLE(bytes, offset, width) {
2261
+ let n = 0n;
2262
+ for (let i = width - 1; i >= 0; i--) {
2263
+ n = n << 8n | BigInt(bytes[offset + i] ?? 0);
2264
+ }
2265
+ return n;
2266
+ }
2267
+ function readUleb(bytes, offset) {
2268
+ let value = 0;
2269
+ let shift = 0;
2270
+ let consumed = 0;
2271
+ for (; ; ) {
2272
+ const byte = bytes[offset + consumed] ?? 0;
2273
+ value |= (byte & 127) << shift;
2274
+ consumed++;
2275
+ if ((byte & 128) === 0)
2276
+ break;
2277
+ shift += 7;
2278
+ }
2279
+ return [value, consumed];
2280
+ }
2281
+ function decodeU8(hex) {
2282
+ return Number(readUIntLE(hexToBytes(hex), 0, 1));
2283
+ }
2284
+ function decodeU16(hex) {
2285
+ return Number(readUIntLE(hexToBytes(hex), 0, 2));
2286
+ }
2287
+ function decodeU32(hex) {
2288
+ return Number(readUIntLE(hexToBytes(hex), 0, 4));
2289
+ }
2290
+ function decodeU64(hex) {
2291
+ return readUIntLE(hexToBytes(hex), 0, 8);
2292
+ }
2293
+ function decodeU128(hex) {
2294
+ return readUIntLE(hexToBytes(hex), 0, 16);
2295
+ }
2296
+ function decodeBool(hex) {
2297
+ return (hexToBytes(hex)[0] ?? 0) !== 0;
2298
+ }
2299
+ function decodeAddress(hex) {
2300
+ const bytes = hexToBytes(hex);
2301
+ return "0x" + Array.from(bytes.slice(0, 32), (b) => b.toString(16).padStart(2, "0")).join("");
2302
+ }
2303
+ function decodeVectorAddress(hex) {
2304
+ const bytes = hexToBytes(hex);
2305
+ const [len, consumed] = readUleb(bytes, 0);
2306
+ const out = [];
2307
+ for (let i = 0; i < len; i++) {
2308
+ const start = consumed + i * 32;
2309
+ out.push(
2310
+ "0x" + Array.from(bytes.slice(start, start + 32), (b) => b.toString(16).padStart(2, "0")).join("")
2311
+ );
2312
+ }
2313
+ return out;
2314
+ }
2315
+ function decodeString(hex) {
2316
+ const bytes = hexToBytes(hex);
2317
+ const [len, consumed] = readUleb(bytes, 0);
2318
+ return new TextDecoder().decode(bytes.slice(consumed, consumed + len));
2319
+ }
2320
+ function parseRecordData(recordDataRaw) {
2321
+ try {
2322
+ return JSON.parse(recordDataRaw);
2323
+ } catch {
2324
+ return [recordDataRaw];
2325
+ }
2326
+ }
1695
2327
  // Annotate the CommonJS export names for ESM import in node:
1696
2328
  0 && (module.exports = {
1697
2329
  DubheGraphqlClient,
1698
2330
  QueryBuilders,
1699
- createDubheGraphqlClient
2331
+ ZERO_ADDRESS,
2332
+ createDubheGraphqlClient,
2333
+ decodeAddress,
2334
+ decodeBool,
2335
+ decodeString,
2336
+ decodeU128,
2337
+ decodeU16,
2338
+ decodeU32,
2339
+ decodeU64,
2340
+ decodeU8,
2341
+ decodeVectorAddress,
2342
+ hexToBytes,
2343
+ parseRecordData
1700
2344
  });
1701
2345
  //# sourceMappingURL=index.js.map