@0xobelisk/graphql-client 1.2.0-pre.98 → 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/LICENSE +92 -0
- package/dist/client.d.ts +121 -1
- package/dist/decoders.d.ts +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +660 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +647 -15
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +113 -0
- package/package.json +21 -21
- package/src/client.ts +688 -18
- package/src/decoders.ts +100 -0
- package/src/index.ts +1 -0
- package/src/types.ts +120 -0
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
Observable,
|
|
23
23
|
from
|
|
24
24
|
} from "@apollo/client";
|
|
25
|
+
import { BatchHttpLink } from "@apollo/client/link/batch-http";
|
|
25
26
|
import { RetryLink } from "@apollo/client/link/retry";
|
|
26
27
|
import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
|
|
27
28
|
import { getMainDefinition } from "@apollo/client/utilities";
|
|
@@ -736,6 +737,77 @@ import "graphql";
|
|
|
736
737
|
|
|
737
738
|
// src/client.ts
|
|
738
739
|
import pluralize from "pluralize";
|
|
740
|
+
var SYSTEM_TABLE_FIELDS = {
|
|
741
|
+
dubheDappMarketplaceFees: [
|
|
742
|
+
"dappKey",
|
|
743
|
+
"listingId",
|
|
744
|
+
"coinType",
|
|
745
|
+
"totalFee",
|
|
746
|
+
"treasuryAmount",
|
|
747
|
+
"dappAmount",
|
|
748
|
+
"updatedAtCheckpoint",
|
|
749
|
+
"lastUpdateDigest"
|
|
750
|
+
],
|
|
751
|
+
dubheDappRuntimeState: [
|
|
752
|
+
"dappKey",
|
|
753
|
+
"admin",
|
|
754
|
+
"paused",
|
|
755
|
+
"settlementMode",
|
|
756
|
+
"creditPool",
|
|
757
|
+
"writeFeeShareBps",
|
|
758
|
+
"lastRuntimeEvent",
|
|
759
|
+
"lastRuntimeActor",
|
|
760
|
+
"lastRuntimeAmount",
|
|
761
|
+
"updatedAtCheckpoint",
|
|
762
|
+
"lastUpdateDigest"
|
|
763
|
+
],
|
|
764
|
+
dubheDappFeeState: [
|
|
765
|
+
"entityId",
|
|
766
|
+
"baseFeePerWrite",
|
|
767
|
+
"bytesFeePerByte",
|
|
768
|
+
"freeCredit",
|
|
769
|
+
"creditPool",
|
|
770
|
+
"totalSettled",
|
|
771
|
+
"updatedAtTimestampMs",
|
|
772
|
+
"lastUpdateDigest"
|
|
773
|
+
],
|
|
774
|
+
dubheDappRevenueState: [
|
|
775
|
+
"entityId",
|
|
776
|
+
"dappRevenue",
|
|
777
|
+
"coinType",
|
|
778
|
+
"updatedAtTimestampMs",
|
|
779
|
+
"lastUpdateDigest"
|
|
780
|
+
],
|
|
781
|
+
dubheMarketplaceListings: [
|
|
782
|
+
"dappKey",
|
|
783
|
+
"listingId",
|
|
784
|
+
"seller",
|
|
785
|
+
"recordType",
|
|
786
|
+
"price",
|
|
787
|
+
"coinType",
|
|
788
|
+
"isFungible",
|
|
789
|
+
"listedUntil",
|
|
790
|
+
"status",
|
|
791
|
+
"updatedAtCheckpoint",
|
|
792
|
+
"lastUpdateDigest"
|
|
793
|
+
],
|
|
794
|
+
dubheSessions: [
|
|
795
|
+
"dappKey",
|
|
796
|
+
"canonical",
|
|
797
|
+
"sessionWallet",
|
|
798
|
+
"expiresAt",
|
|
799
|
+
"active",
|
|
800
|
+
"updatedAtCheckpoint",
|
|
801
|
+
"lastUpdateDigest"
|
|
802
|
+
],
|
|
803
|
+
dubheUserStorages: [
|
|
804
|
+
"dappKey",
|
|
805
|
+
"canonicalOwner",
|
|
806
|
+
"userStorageId",
|
|
807
|
+
"updatedAtCheckpoint",
|
|
808
|
+
"lastUpdateDigest"
|
|
809
|
+
]
|
|
810
|
+
};
|
|
739
811
|
function mapCachePolicyToFetchPolicy(cachePolicy) {
|
|
740
812
|
switch (cachePolicy) {
|
|
741
813
|
case "cache-first":
|
|
@@ -752,6 +824,23 @@ function mapCachePolicyToFetchPolicy(cachePolicy) {
|
|
|
752
824
|
return "cache-first";
|
|
753
825
|
}
|
|
754
826
|
}
|
|
827
|
+
function buildHttpLink(config) {
|
|
828
|
+
const fetchFn = (input, init) => fetch(input, { ...config.fetchOptions, ...init ?? {} });
|
|
829
|
+
if (config.batchRequests) {
|
|
830
|
+
return new BatchHttpLink({
|
|
831
|
+
uri: config.endpoint,
|
|
832
|
+
headers: config.headers,
|
|
833
|
+
fetch: fetchFn,
|
|
834
|
+
batchInterval: config.batchInterval ?? 10,
|
|
835
|
+
batchMax: config.batchMax ?? 20
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
return createHttpLink({
|
|
839
|
+
uri: config.endpoint,
|
|
840
|
+
headers: config.headers,
|
|
841
|
+
fetch: fetchFn
|
|
842
|
+
});
|
|
843
|
+
}
|
|
755
844
|
var DubheGraphqlClient = class {
|
|
756
845
|
// Store current configuration for updates
|
|
757
846
|
constructor(config) {
|
|
@@ -762,11 +851,7 @@ var DubheGraphqlClient = class {
|
|
|
762
851
|
if (this.dubheMetadata) {
|
|
763
852
|
this.parseTableInfoFromConfig();
|
|
764
853
|
}
|
|
765
|
-
const httpLink =
|
|
766
|
-
uri: config.endpoint,
|
|
767
|
-
headers: config.headers,
|
|
768
|
-
fetch: (input, init) => fetch(input, { ...config.fetchOptions, ...init })
|
|
769
|
-
});
|
|
854
|
+
const httpLink = buildHttpLink(config);
|
|
770
855
|
const retryLink = new RetryLink({
|
|
771
856
|
delay: {
|
|
772
857
|
// Initial retry delay time (milliseconds)
|
|
@@ -887,11 +972,7 @@ var DubheGraphqlClient = class {
|
|
|
887
972
|
}
|
|
888
973
|
this.subscriptionClient = void 0;
|
|
889
974
|
}
|
|
890
|
-
const httpLink =
|
|
891
|
-
uri: this.currentConfig.endpoint,
|
|
892
|
-
headers: this.currentConfig.headers,
|
|
893
|
-
fetch: (input, init) => fetch(input, { ...this.currentConfig.fetchOptions, ...init })
|
|
894
|
-
});
|
|
975
|
+
const httpLink = buildHttpLink(this.currentConfig);
|
|
895
976
|
const retryLink = new RetryLink({
|
|
896
977
|
delay: {
|
|
897
978
|
initial: this.currentConfig.retryOptions?.delay?.initial || 300,
|
|
@@ -1343,6 +1424,430 @@ var DubheGraphqlClient = class {
|
|
|
1343
1424
|
return () => subscription.subscribe().unsubscribe();
|
|
1344
1425
|
});
|
|
1345
1426
|
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Query marketplace listings indexed by the Dubhe indexer.
|
|
1429
|
+
* Uses the marketplace_listings PostgreSQL table (exposed as dubheMarketplaceListings in GraphQL).
|
|
1430
|
+
* The record_type field is pre-decoded text ("wheat", "corn", …) and status tracks
|
|
1431
|
+
* active/sold/cancelled directly — no extra RPC calls needed.
|
|
1432
|
+
*/
|
|
1433
|
+
async getMarketplaceListings(options) {
|
|
1434
|
+
const filter = {};
|
|
1435
|
+
if (options?.dappKey)
|
|
1436
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1437
|
+
if (options?.status !== void 0)
|
|
1438
|
+
filter.status = { equalTo: options.status };
|
|
1439
|
+
if (options?.recordType)
|
|
1440
|
+
filter.recordType = { equalTo: options.recordType };
|
|
1441
|
+
if (options?.seller)
|
|
1442
|
+
filter.seller = { equalTo: options.seller };
|
|
1443
|
+
const query = gql`
|
|
1444
|
+
query GetMarketplaceListings(
|
|
1445
|
+
$first: Int
|
|
1446
|
+
$after: Cursor
|
|
1447
|
+
$filter: StoreDubheMarketplaceListingFilter
|
|
1448
|
+
$orderBy: [StoreDubheMarketplaceListingsOrderBy!]
|
|
1449
|
+
) {
|
|
1450
|
+
dubheMarketplaceListings(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1451
|
+
totalCount
|
|
1452
|
+
pageInfo {
|
|
1453
|
+
hasNextPage
|
|
1454
|
+
hasPreviousPage
|
|
1455
|
+
startCursor
|
|
1456
|
+
endCursor
|
|
1457
|
+
}
|
|
1458
|
+
edges {
|
|
1459
|
+
cursor
|
|
1460
|
+
node {
|
|
1461
|
+
listingId
|
|
1462
|
+
dappKey
|
|
1463
|
+
seller
|
|
1464
|
+
recordType
|
|
1465
|
+
recordDataRaw
|
|
1466
|
+
price
|
|
1467
|
+
coinType
|
|
1468
|
+
isFungible
|
|
1469
|
+
status
|
|
1470
|
+
buyer
|
|
1471
|
+
listedUntil
|
|
1472
|
+
createdAtCheckpoint
|
|
1473
|
+
updatedAtCheckpoint
|
|
1474
|
+
lastUpdateDigest
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
`;
|
|
1480
|
+
const result = await this.apolloClient.query({
|
|
1481
|
+
query,
|
|
1482
|
+
variables: {
|
|
1483
|
+
first: options?.first ?? 100,
|
|
1484
|
+
after: options?.after,
|
|
1485
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1486
|
+
orderBy: ["CREATED_AT_CHECKPOINT_DESC"]
|
|
1487
|
+
},
|
|
1488
|
+
fetchPolicy: "network-only"
|
|
1489
|
+
});
|
|
1490
|
+
if (result.error)
|
|
1491
|
+
throw result.error;
|
|
1492
|
+
return result.data?.dubheMarketplaceListings ?? {
|
|
1493
|
+
edges: [],
|
|
1494
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1495
|
+
totalCount: 0
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Query session keys indexed by the Dubhe indexer (dubheSessions in GraphQL).
|
|
1500
|
+
*/
|
|
1501
|
+
async getDubheSessions(options) {
|
|
1502
|
+
const filter = {};
|
|
1503
|
+
if (options?.dappKey)
|
|
1504
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1505
|
+
if (options?.canonical)
|
|
1506
|
+
filter.canonical = { equalTo: options.canonical };
|
|
1507
|
+
if (options?.active !== void 0)
|
|
1508
|
+
filter.active = { equalTo: options.active };
|
|
1509
|
+
const query = gql`
|
|
1510
|
+
query GetDubheSessions(
|
|
1511
|
+
$first: Int
|
|
1512
|
+
$after: Cursor
|
|
1513
|
+
$filter: StoreDubheSessionFilter
|
|
1514
|
+
$orderBy: [StoreDubheSessionsOrderBy!]
|
|
1515
|
+
) {
|
|
1516
|
+
dubheSessions(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1517
|
+
totalCount
|
|
1518
|
+
pageInfo {
|
|
1519
|
+
hasNextPage
|
|
1520
|
+
hasPreviousPage
|
|
1521
|
+
startCursor
|
|
1522
|
+
endCursor
|
|
1523
|
+
}
|
|
1524
|
+
edges {
|
|
1525
|
+
cursor
|
|
1526
|
+
node {
|
|
1527
|
+
dappKey
|
|
1528
|
+
canonical
|
|
1529
|
+
sessionWallet
|
|
1530
|
+
expiresAt
|
|
1531
|
+
active
|
|
1532
|
+
updatedAtCheckpoint
|
|
1533
|
+
lastUpdateDigest
|
|
1534
|
+
lastEventSeq
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
`;
|
|
1540
|
+
const result = await this.apolloClient.query({
|
|
1541
|
+
query,
|
|
1542
|
+
variables: {
|
|
1543
|
+
first: options?.first ?? 100,
|
|
1544
|
+
after: options?.after,
|
|
1545
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1546
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1547
|
+
},
|
|
1548
|
+
fetchPolicy: "network-only"
|
|
1549
|
+
});
|
|
1550
|
+
if (result.error)
|
|
1551
|
+
throw result.error;
|
|
1552
|
+
return result.data?.dubheSessions ?? {
|
|
1553
|
+
edges: [],
|
|
1554
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1555
|
+
totalCount: 0
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Query user storage registrations indexed by the Dubhe indexer (dubheUserStorages in GraphQL).
|
|
1560
|
+
*/
|
|
1561
|
+
async getDubheUserStorages(options) {
|
|
1562
|
+
const filter = {};
|
|
1563
|
+
if (options?.dappKey)
|
|
1564
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1565
|
+
if (options?.canonicalOwner)
|
|
1566
|
+
filter.canonicalOwner = { equalTo: options.canonicalOwner };
|
|
1567
|
+
const query = gql`
|
|
1568
|
+
query GetDubheUserStorages(
|
|
1569
|
+
$first: Int
|
|
1570
|
+
$after: Cursor
|
|
1571
|
+
$filter: StoreDubheUserStorageFilter
|
|
1572
|
+
$orderBy: [StoreDubheUserStoragesOrderBy!]
|
|
1573
|
+
) {
|
|
1574
|
+
dubheUserStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1575
|
+
totalCount
|
|
1576
|
+
pageInfo {
|
|
1577
|
+
hasNextPage
|
|
1578
|
+
hasPreviousPage
|
|
1579
|
+
startCursor
|
|
1580
|
+
endCursor
|
|
1581
|
+
}
|
|
1582
|
+
edges {
|
|
1583
|
+
cursor
|
|
1584
|
+
node {
|
|
1585
|
+
dappKey
|
|
1586
|
+
canonicalOwner
|
|
1587
|
+
userStorageId
|
|
1588
|
+
createdAtCheckpoint
|
|
1589
|
+
updatedAtCheckpoint
|
|
1590
|
+
lastUpdateDigest
|
|
1591
|
+
lastEventSeq
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
`;
|
|
1597
|
+
const result = await this.apolloClient.query({
|
|
1598
|
+
query,
|
|
1599
|
+
variables: {
|
|
1600
|
+
first: options?.first ?? 100,
|
|
1601
|
+
after: options?.after,
|
|
1602
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1603
|
+
orderBy: ["CREATED_AT_CHECKPOINT_DESC"]
|
|
1604
|
+
},
|
|
1605
|
+
fetchPolicy: "network-only"
|
|
1606
|
+
});
|
|
1607
|
+
if (result.error)
|
|
1608
|
+
throw result.error;
|
|
1609
|
+
return result.data?.dubheUserStorages ?? {
|
|
1610
|
+
edges: [],
|
|
1611
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1612
|
+
totalCount: 0
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Query SceneStorage system rows indexed by the Dubhe indexer
|
|
1617
|
+
* (scene_storages table, exposed as dubheSceneStorages in GraphQL).
|
|
1618
|
+
* Field values live in the companion scene_storage_fields table —
|
|
1619
|
+
* see getSceneStorageFields.
|
|
1620
|
+
*/
|
|
1621
|
+
async getSceneStorages(options) {
|
|
1622
|
+
const filter = {};
|
|
1623
|
+
if (options?.dappKey)
|
|
1624
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1625
|
+
if (options?.sceneType)
|
|
1626
|
+
filter.sceneType = { equalTo: options.sceneType };
|
|
1627
|
+
if (options?.sceneId)
|
|
1628
|
+
filter.sceneId = { equalTo: options.sceneId };
|
|
1629
|
+
if (options?.isDestroyed !== void 0)
|
|
1630
|
+
filter.isDestroyed = { equalTo: options.isDestroyed };
|
|
1631
|
+
const query = gql`
|
|
1632
|
+
query GetSceneStorages(
|
|
1633
|
+
$first: Int
|
|
1634
|
+
$after: Cursor
|
|
1635
|
+
$filter: StoreDubheSceneStorageFilter
|
|
1636
|
+
$orderBy: [StoreDubheSceneStoragesOrderBy!]
|
|
1637
|
+
) {
|
|
1638
|
+
dubheSceneStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1639
|
+
totalCount
|
|
1640
|
+
pageInfo {
|
|
1641
|
+
hasNextPage
|
|
1642
|
+
hasPreviousPage
|
|
1643
|
+
startCursor
|
|
1644
|
+
endCursor
|
|
1645
|
+
}
|
|
1646
|
+
edges {
|
|
1647
|
+
cursor
|
|
1648
|
+
node {
|
|
1649
|
+
sceneId
|
|
1650
|
+
dappKey
|
|
1651
|
+
sceneType
|
|
1652
|
+
authorizationKind
|
|
1653
|
+
authorizedPermitId
|
|
1654
|
+
isDestroyed
|
|
1655
|
+
createdAtCheckpoint
|
|
1656
|
+
updatedAtCheckpoint
|
|
1657
|
+
lastUpdateDigest
|
|
1658
|
+
lastEventSeq
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
`;
|
|
1664
|
+
const result = await this.apolloClient.query({
|
|
1665
|
+
query,
|
|
1666
|
+
variables: {
|
|
1667
|
+
first: options?.first ?? 100,
|
|
1668
|
+
after: options?.after,
|
|
1669
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1670
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1671
|
+
},
|
|
1672
|
+
fetchPolicy: "network-only"
|
|
1673
|
+
});
|
|
1674
|
+
if (result.error)
|
|
1675
|
+
throw result.error;
|
|
1676
|
+
return result.data?.dubheSceneStorages ?? {
|
|
1677
|
+
edges: [],
|
|
1678
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1679
|
+
totalCount: 0
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Query raw field rows of SceneStorages (scene_storage_fields table,
|
|
1684
|
+
* exposed as dubheSceneStorageFields in GraphQL). Values are hex-encoded
|
|
1685
|
+
* BCS — decode with the decoders exported from this package.
|
|
1686
|
+
*/
|
|
1687
|
+
async getSceneStorageFields(options) {
|
|
1688
|
+
const filter = {};
|
|
1689
|
+
if (options?.dappKey)
|
|
1690
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1691
|
+
if (options?.sceneIds && options.sceneIds.length > 0)
|
|
1692
|
+
filter.sceneId = { in: options.sceneIds };
|
|
1693
|
+
if (options?.sceneId)
|
|
1694
|
+
filter.sceneId = { equalTo: options.sceneId };
|
|
1695
|
+
if (options?.fieldName)
|
|
1696
|
+
filter.fieldName = { equalTo: options.fieldName };
|
|
1697
|
+
if (options?.isDeleted !== void 0)
|
|
1698
|
+
filter.isDeleted = { equalTo: options.isDeleted };
|
|
1699
|
+
const query = gql`
|
|
1700
|
+
query GetSceneStorageFields(
|
|
1701
|
+
$first: Int
|
|
1702
|
+
$after: Cursor
|
|
1703
|
+
$filter: StoreDubheSceneStorageFieldFilter
|
|
1704
|
+
$orderBy: [StoreDubheSceneStorageFieldsOrderBy!]
|
|
1705
|
+
) {
|
|
1706
|
+
dubheSceneStorageFields(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1707
|
+
totalCount
|
|
1708
|
+
pageInfo {
|
|
1709
|
+
hasNextPage
|
|
1710
|
+
hasPreviousPage
|
|
1711
|
+
startCursor
|
|
1712
|
+
endCursor
|
|
1713
|
+
}
|
|
1714
|
+
edges {
|
|
1715
|
+
cursor
|
|
1716
|
+
node {
|
|
1717
|
+
sceneId
|
|
1718
|
+
dappKey
|
|
1719
|
+
sceneType
|
|
1720
|
+
fieldName
|
|
1721
|
+
fieldValueRaw
|
|
1722
|
+
isDeleted
|
|
1723
|
+
updatedAtCheckpoint
|
|
1724
|
+
lastUpdateDigest
|
|
1725
|
+
lastEventSeq
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
`;
|
|
1731
|
+
const result = await this.apolloClient.query({
|
|
1732
|
+
query,
|
|
1733
|
+
variables: {
|
|
1734
|
+
first: options?.first ?? 1e3,
|
|
1735
|
+
after: options?.after,
|
|
1736
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1737
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1738
|
+
},
|
|
1739
|
+
fetchPolicy: "network-only"
|
|
1740
|
+
});
|
|
1741
|
+
if (result.error)
|
|
1742
|
+
throw result.error;
|
|
1743
|
+
return result.data?.dubheSceneStorageFields ?? {
|
|
1744
|
+
edges: [],
|
|
1745
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1746
|
+
totalCount: 0
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Query ObjectStorage system rows indexed by the Dubhe indexer
|
|
1751
|
+
* (object_storages table, exposed as dubheObjectStorages in GraphQL).
|
|
1752
|
+
*/
|
|
1753
|
+
async getObjectStorages(options) {
|
|
1754
|
+
const filter = {};
|
|
1755
|
+
if (options?.dappKey)
|
|
1756
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1757
|
+
if (options?.objectType)
|
|
1758
|
+
filter.objectType = { equalTo: options.objectType };
|
|
1759
|
+
if (options?.objectId)
|
|
1760
|
+
filter.objectId = { equalTo: options.objectId };
|
|
1761
|
+
if (options?.isDestroyed !== void 0)
|
|
1762
|
+
filter.isDestroyed = { equalTo: options.isDestroyed };
|
|
1763
|
+
const query = gql`
|
|
1764
|
+
query GetObjectStorages(
|
|
1765
|
+
$first: Int
|
|
1766
|
+
$after: Cursor
|
|
1767
|
+
$filter: StoreDubheObjectStorageFilter
|
|
1768
|
+
$orderBy: [StoreDubheObjectStoragesOrderBy!]
|
|
1769
|
+
) {
|
|
1770
|
+
dubheObjectStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1771
|
+
totalCount
|
|
1772
|
+
pageInfo {
|
|
1773
|
+
hasNextPage
|
|
1774
|
+
hasPreviousPage
|
|
1775
|
+
startCursor
|
|
1776
|
+
endCursor
|
|
1777
|
+
}
|
|
1778
|
+
edges {
|
|
1779
|
+
cursor
|
|
1780
|
+
node {
|
|
1781
|
+
objectId
|
|
1782
|
+
dappKey
|
|
1783
|
+
objectType
|
|
1784
|
+
entityIdRaw
|
|
1785
|
+
isDestroyed
|
|
1786
|
+
createdAtCheckpoint
|
|
1787
|
+
updatedAtCheckpoint
|
|
1788
|
+
lastUpdateDigest
|
|
1789
|
+
lastEventSeq
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
`;
|
|
1795
|
+
const result = await this.apolloClient.query({
|
|
1796
|
+
query,
|
|
1797
|
+
variables: {
|
|
1798
|
+
first: options?.first ?? 100,
|
|
1799
|
+
after: options?.after,
|
|
1800
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1801
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1802
|
+
},
|
|
1803
|
+
fetchPolicy: "network-only"
|
|
1804
|
+
});
|
|
1805
|
+
if (result.error)
|
|
1806
|
+
throw result.error;
|
|
1807
|
+
return result.data?.dubheObjectStorages ?? {
|
|
1808
|
+
edges: [],
|
|
1809
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1810
|
+
totalCount: 0
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Query DApp runtime state (credit pool, admin, package version, etc.).
|
|
1815
|
+
* Exposed as dubheDappRuntimeStates in GraphQL.
|
|
1816
|
+
*/
|
|
1817
|
+
async getDubheDappRuntimeState(dappKey) {
|
|
1818
|
+
const query = gql`
|
|
1819
|
+
query GetDubheDappRuntimeState($filter: StoreDubheDappRuntimeStateFilter) {
|
|
1820
|
+
dubheDappRuntimeStates(first: 1, filter: $filter) {
|
|
1821
|
+
edges {
|
|
1822
|
+
node {
|
|
1823
|
+
dappKey
|
|
1824
|
+
admin
|
|
1825
|
+
dappStorageId
|
|
1826
|
+
packageId
|
|
1827
|
+
version
|
|
1828
|
+
creditPool
|
|
1829
|
+
paused
|
|
1830
|
+
settlementMode
|
|
1831
|
+
createdAt
|
|
1832
|
+
createdAtCheckpoint
|
|
1833
|
+
updatedAtCheckpoint
|
|
1834
|
+
lastUpdateDigest
|
|
1835
|
+
lastEventSeq
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
`;
|
|
1841
|
+
const result = await this.apolloClient.query({
|
|
1842
|
+
query,
|
|
1843
|
+
variables: { filter: { dappKey: { equalTo: dappKey } } },
|
|
1844
|
+
fetchPolicy: "network-only"
|
|
1845
|
+
});
|
|
1846
|
+
if (result.error)
|
|
1847
|
+
throw result.error;
|
|
1848
|
+
const edges = result.data?.dubheDappRuntimeStates?.edges ?? [];
|
|
1849
|
+
return edges[0]?.node ?? null;
|
|
1850
|
+
}
|
|
1346
1851
|
// Improved table name handling methods
|
|
1347
1852
|
getFilterTypeName(tableName) {
|
|
1348
1853
|
const singularName = this.getSingularTableName(tableName);
|
|
@@ -1602,15 +2107,55 @@ var DubheGraphqlClient = class {
|
|
|
1602
2107
|
if (customFields && customFields.length > 0) {
|
|
1603
2108
|
fields = customFields;
|
|
1604
2109
|
} else {
|
|
1605
|
-
const
|
|
1606
|
-
if (
|
|
1607
|
-
fields =
|
|
2110
|
+
const systemFields = SYSTEM_TABLE_FIELDS[tableName];
|
|
2111
|
+
if (systemFields) {
|
|
2112
|
+
fields = systemFields;
|
|
1608
2113
|
} else {
|
|
1609
|
-
|
|
2114
|
+
const autoFields = this.getTableFields(tableName);
|
|
2115
|
+
if (autoFields.length > 0) {
|
|
2116
|
+
fields = autoFields;
|
|
2117
|
+
} else {
|
|
2118
|
+
fields = [
|
|
2119
|
+
"createdAtTimestampMs",
|
|
2120
|
+
"updatedAtTimestampMs",
|
|
2121
|
+
"isDeleted",
|
|
2122
|
+
"lastUpdateDigest"
|
|
2123
|
+
];
|
|
2124
|
+
}
|
|
1610
2125
|
}
|
|
1611
2126
|
}
|
|
1612
2127
|
return fields.join("\n ");
|
|
1613
2128
|
}
|
|
2129
|
+
// ── Typed system-table query methods ─────────────────────────────────────
|
|
2130
|
+
/** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
|
|
2131
|
+
async getDappFeeState() {
|
|
2132
|
+
const result = await this.getAllTables("dubheDappFeeState", { first: 1 }).catch(
|
|
2133
|
+
() => null
|
|
2134
|
+
);
|
|
2135
|
+
return result?.edges?.[0]?.node ?? null;
|
|
2136
|
+
}
|
|
2137
|
+
/** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
|
|
2138
|
+
async getDappRevenueState() {
|
|
2139
|
+
const result = await this.getAllTables("dubheDappRevenueState", { first: 1 }).catch(
|
|
2140
|
+
() => null
|
|
2141
|
+
);
|
|
2142
|
+
return result?.edges?.[0]?.node ?? null;
|
|
2143
|
+
}
|
|
2144
|
+
/** Latest DApp runtime state (admin, settlement mode, last event). */
|
|
2145
|
+
async getDappRuntimeState() {
|
|
2146
|
+
const result = await this.getAllTables("dubheDappRuntimeState", { first: 1 }).catch(
|
|
2147
|
+
() => null
|
|
2148
|
+
);
|
|
2149
|
+
return result?.edges?.[0]?.node ?? null;
|
|
2150
|
+
}
|
|
2151
|
+
/** Marketplace fee records (one row per listing sold). */
|
|
2152
|
+
async getDappMarketplaceFees(options) {
|
|
2153
|
+
return this.getAllTables("dubheDappMarketplaceFees", {
|
|
2154
|
+
first: options?.first ?? 20,
|
|
2155
|
+
after: options?.after,
|
|
2156
|
+
orderBy: [{ field: "updatedAtCheckpoint", direction: "DESC" }]
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
1614
2159
|
};
|
|
1615
2160
|
function createDubheGraphqlClient(config) {
|
|
1616
2161
|
return new DubheGraphqlClient(config);
|
|
@@ -1671,9 +2216,96 @@ function toSnakeCaseForEnum(str) {
|
|
|
1671
2216
|
}
|
|
1672
2217
|
return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "").toUpperCase();
|
|
1673
2218
|
}
|
|
2219
|
+
|
|
2220
|
+
// src/decoders.ts
|
|
2221
|
+
var ZERO_ADDRESS = "0x" + "0".repeat(64);
|
|
2222
|
+
function hexToBytes(hex) {
|
|
2223
|
+
const clean = hex.replace(/^0x/i, "");
|
|
2224
|
+
const pairs = clean.match(/../g) ?? [];
|
|
2225
|
+
return Uint8Array.from(pairs.map((b) => parseInt(b, 16)));
|
|
2226
|
+
}
|
|
2227
|
+
function readUIntLE(bytes, offset, width) {
|
|
2228
|
+
let n = 0n;
|
|
2229
|
+
for (let i = width - 1; i >= 0; i--) {
|
|
2230
|
+
n = n << 8n | BigInt(bytes[offset + i] ?? 0);
|
|
2231
|
+
}
|
|
2232
|
+
return n;
|
|
2233
|
+
}
|
|
2234
|
+
function readUleb(bytes, offset) {
|
|
2235
|
+
let value = 0;
|
|
2236
|
+
let shift = 0;
|
|
2237
|
+
let consumed = 0;
|
|
2238
|
+
for (; ; ) {
|
|
2239
|
+
const byte = bytes[offset + consumed] ?? 0;
|
|
2240
|
+
value |= (byte & 127) << shift;
|
|
2241
|
+
consumed++;
|
|
2242
|
+
if ((byte & 128) === 0)
|
|
2243
|
+
break;
|
|
2244
|
+
shift += 7;
|
|
2245
|
+
}
|
|
2246
|
+
return [value, consumed];
|
|
2247
|
+
}
|
|
2248
|
+
function decodeU8(hex) {
|
|
2249
|
+
return Number(readUIntLE(hexToBytes(hex), 0, 1));
|
|
2250
|
+
}
|
|
2251
|
+
function decodeU16(hex) {
|
|
2252
|
+
return Number(readUIntLE(hexToBytes(hex), 0, 2));
|
|
2253
|
+
}
|
|
2254
|
+
function decodeU32(hex) {
|
|
2255
|
+
return Number(readUIntLE(hexToBytes(hex), 0, 4));
|
|
2256
|
+
}
|
|
2257
|
+
function decodeU64(hex) {
|
|
2258
|
+
return readUIntLE(hexToBytes(hex), 0, 8);
|
|
2259
|
+
}
|
|
2260
|
+
function decodeU128(hex) {
|
|
2261
|
+
return readUIntLE(hexToBytes(hex), 0, 16);
|
|
2262
|
+
}
|
|
2263
|
+
function decodeBool(hex) {
|
|
2264
|
+
return (hexToBytes(hex)[0] ?? 0) !== 0;
|
|
2265
|
+
}
|
|
2266
|
+
function decodeAddress(hex) {
|
|
2267
|
+
const bytes = hexToBytes(hex);
|
|
2268
|
+
return "0x" + Array.from(bytes.slice(0, 32), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
2269
|
+
}
|
|
2270
|
+
function decodeVectorAddress(hex) {
|
|
2271
|
+
const bytes = hexToBytes(hex);
|
|
2272
|
+
const [len, consumed] = readUleb(bytes, 0);
|
|
2273
|
+
const out = [];
|
|
2274
|
+
for (let i = 0; i < len; i++) {
|
|
2275
|
+
const start = consumed + i * 32;
|
|
2276
|
+
out.push(
|
|
2277
|
+
"0x" + Array.from(bytes.slice(start, start + 32), (b) => b.toString(16).padStart(2, "0")).join("")
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
return out;
|
|
2281
|
+
}
|
|
2282
|
+
function decodeString(hex) {
|
|
2283
|
+
const bytes = hexToBytes(hex);
|
|
2284
|
+
const [len, consumed] = readUleb(bytes, 0);
|
|
2285
|
+
return new TextDecoder().decode(bytes.slice(consumed, consumed + len));
|
|
2286
|
+
}
|
|
2287
|
+
function parseRecordData(recordDataRaw) {
|
|
2288
|
+
try {
|
|
2289
|
+
return JSON.parse(recordDataRaw);
|
|
2290
|
+
} catch {
|
|
2291
|
+
return [recordDataRaw];
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
1674
2294
|
export {
|
|
1675
2295
|
DubheGraphqlClient,
|
|
1676
2296
|
QueryBuilders,
|
|
1677
|
-
|
|
2297
|
+
ZERO_ADDRESS,
|
|
2298
|
+
createDubheGraphqlClient,
|
|
2299
|
+
decodeAddress,
|
|
2300
|
+
decodeBool,
|
|
2301
|
+
decodeString,
|
|
2302
|
+
decodeU128,
|
|
2303
|
+
decodeU16,
|
|
2304
|
+
decodeU32,
|
|
2305
|
+
decodeU64,
|
|
2306
|
+
decodeU8,
|
|
2307
|
+
decodeVectorAddress,
|
|
2308
|
+
hexToBytes,
|
|
2309
|
+
parseRecordData
|
|
1678
2310
|
};
|
|
1679
2311
|
//# sourceMappingURL=index.mjs.map
|