@0xobelisk/graphql-client 1.2.0-pre.124 → 1.2.0-pre.125
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/client.d.ts +41 -1
- package/dist/decoders.d.ts +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +299 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +286 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +42 -0
- package/package.json +1 -1
- package/src/client.ts +226 -1
- package/src/decoders.ts +100 -0
- package/src/index.ts +1 -0
- package/src/types.ts +45 -0
package/dist/index.mjs
CHANGED
|
@@ -1612,6 +1612,204 @@ var DubheGraphqlClient = class {
|
|
|
1612
1612
|
totalCount: 0
|
|
1613
1613
|
};
|
|
1614
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
|
+
}
|
|
1615
1813
|
/**
|
|
1616
1814
|
* Query DApp runtime state (credit pool, admin, package version, etc.).
|
|
1617
1815
|
* Exposed as dubheDappRuntimeStates in GraphQL.
|
|
@@ -2018,9 +2216,96 @@ function toSnakeCaseForEnum(str) {
|
|
|
2018
2216
|
}
|
|
2019
2217
|
return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "").toUpperCase();
|
|
2020
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
|
+
}
|
|
2021
2294
|
export {
|
|
2022
2295
|
DubheGraphqlClient,
|
|
2023
2296
|
QueryBuilders,
|
|
2024
|
-
|
|
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
|
|
2025
2310
|
};
|
|
2026
2311
|
//# sourceMappingURL=index.mjs.map
|