@0xobelisk/graphql-client 1.2.0-pre.123 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ApolloClient, NormalizedCacheObject, Observable, OperationVariables } from '@apollo/client';
2
- import { DubheClientConfig, Connection, BaseQueryParams, OrderBy, QueryOptions, QueryResult, SubscriptionResult, SubscriptionOptions, StoreTableRow, TypedDocumentNode, MultiTableSubscriptionConfig, MultiTableSubscriptionData, ParsedTableInfo, DubheMetadata, MarketplaceListingRow, DubheSessionRow, DubheUserStorageRow, DubheDappRuntimeStateRow } from './types';
2
+ import { DubheClientConfig, Connection, BaseQueryParams, OrderBy, QueryOptions, QueryResult, SubscriptionResult, SubscriptionOptions, StoreTableRow, TypedDocumentNode, MultiTableSubscriptionConfig, MultiTableSubscriptionData, ParsedTableInfo, DubheMetadata, MarketplaceListingRow, DubheSessionRow, DubheUserStorageRow, DubheDappRuntimeStateRow, SceneStorageRow, SceneStorageFieldRow, ObjectStorageRow } from './types';
3
3
  export declare class DubheGraphqlClient {
4
4
  private apolloClient;
5
5
  private subscriptionClient?;
@@ -162,6 +162,46 @@ export declare class DubheGraphqlClient {
162
162
  first?: number;
163
163
  after?: string;
164
164
  }): Promise<Connection<DubheUserStorageRow>>;
165
+ /**
166
+ * Query SceneStorage system rows indexed by the Dubhe indexer
167
+ * (scene_storages table, exposed as dubheSceneStorages in GraphQL).
168
+ * Field values live in the companion scene_storage_fields table —
169
+ * see getSceneStorageFields.
170
+ */
171
+ getSceneStorages(options?: {
172
+ dappKey?: string;
173
+ sceneType?: string;
174
+ sceneId?: string;
175
+ isDestroyed?: boolean;
176
+ first?: number;
177
+ after?: string;
178
+ }): Promise<Connection<SceneStorageRow>>;
179
+ /**
180
+ * Query raw field rows of SceneStorages (scene_storage_fields table,
181
+ * exposed as dubheSceneStorageFields in GraphQL). Values are hex-encoded
182
+ * BCS — decode with the decoders exported from this package.
183
+ */
184
+ getSceneStorageFields(options?: {
185
+ dappKey?: string;
186
+ sceneIds?: string[];
187
+ sceneId?: string;
188
+ fieldName?: string;
189
+ isDeleted?: boolean;
190
+ first?: number;
191
+ after?: string;
192
+ }): Promise<Connection<SceneStorageFieldRow>>;
193
+ /**
194
+ * Query ObjectStorage system rows indexed by the Dubhe indexer
195
+ * (object_storages table, exposed as dubheObjectStorages in GraphQL).
196
+ */
197
+ getObjectStorages(options?: {
198
+ dappKey?: string;
199
+ objectType?: string;
200
+ objectId?: string;
201
+ isDestroyed?: boolean;
202
+ first?: number;
203
+ after?: string;
204
+ }): Promise<Connection<ObjectStorageRow>>;
165
205
  /**
166
206
  * Query DApp runtime state (credit pool, admin, package version, etc.).
167
207
  * Exposed as dubheDappRuntimeStates in GraphQL.
@@ -255,6 +295,48 @@ export declare class DubheGraphqlClient {
255
295
  * Convert table fields to GraphQL query string
256
296
  */
257
297
  private convertTableFields;
298
+ /** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
299
+ getDappFeeState(): Promise<{
300
+ entityId: string;
301
+ baseFeePerWrite: string;
302
+ bytesFeePerByte: string;
303
+ freeCredit: string;
304
+ creditPool: string;
305
+ totalSettled: string;
306
+ updatedAtTimestampMs: string;
307
+ } | null>;
308
+ /** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
309
+ getDappRevenueState(): Promise<{
310
+ entityId: string;
311
+ dappRevenue: string;
312
+ coinType: string;
313
+ updatedAtTimestampMs: string;
314
+ } | null>;
315
+ /** Latest DApp runtime state (admin, settlement mode, last event). */
316
+ getDappRuntimeState(): Promise<{
317
+ dappKey: string;
318
+ admin: string;
319
+ paused: boolean;
320
+ settlementMode: number;
321
+ creditPool: string;
322
+ writeFeeShareBps: number;
323
+ lastRuntimeEvent: string;
324
+ lastRuntimeActor: string;
325
+ lastRuntimeAmount: string;
326
+ } | null>;
327
+ /** Marketplace fee records (one row per listing sold). */
328
+ getDappMarketplaceFees(options?: {
329
+ first?: number;
330
+ after?: string;
331
+ }): Promise<Connection<{
332
+ dappKey: string;
333
+ listingId: string;
334
+ coinType: string;
335
+ totalFee: string;
336
+ treasuryAmount: string;
337
+ dappAmount: string;
338
+ updatedAtCheckpoint: string;
339
+ }>>;
258
340
  }
259
341
  export declare function createDubheGraphqlClient(config: DubheClientConfig): DubheGraphqlClient;
260
342
  export declare const QueryBuilders: {
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Minimal BCS decoders for indexer raw values.
3
+ *
4
+ * The Dubhe indexer stores scene/object field values and marketplace record
5
+ * data as hex-encoded BCS bytes (e.g. "0x0c00000000000000" for u64 12).
6
+ * These helpers decode the primitive types commonly stored in system tables.
7
+ */
8
+ export declare const ZERO_ADDRESS: string;
9
+ export declare function hexToBytes(hex: string): Uint8Array;
10
+ export declare function decodeU8(hex: string): number;
11
+ export declare function decodeU16(hex: string): number;
12
+ export declare function decodeU32(hex: string): number;
13
+ export declare function decodeU64(hex: string): bigint;
14
+ export declare function decodeU128(hex: string): bigint;
15
+ export declare function decodeBool(hex: string): boolean;
16
+ export declare function decodeAddress(hex: string): string;
17
+ export declare function decodeVectorAddress(hex: string): string[];
18
+ /** Decode a BCS ascii/utf8 String (ULEB length prefix + bytes). */
19
+ export declare function decodeString(hex: string): string;
20
+ /**
21
+ * Marketplace recordDataRaw is a JSON array of per-field hex strings
22
+ * (non-key fields, in schema order).
23
+ */
24
+ export declare function parseRecordData(recordDataRaw: string): string[];
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { DubheGraphqlClient, createDubheGraphqlClient, QueryBuilders } from './client';
2
2
  export * from './types';
3
3
  export type * from './types';
4
+ export * from './decoders';
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,
@@ -1552,6 +1645,204 @@ var DubheGraphqlClient = class {
1552
1645
  totalCount: 0
1553
1646
  };
1554
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
+ }
1555
1846
  /**
1556
1847
  * Query DApp runtime state (credit pool, admin, package version, etc.).
1557
1848
  * Exposed as dubheDappRuntimeStates in GraphQL.
@@ -1849,15 +2140,55 @@ var DubheGraphqlClient = class {
1849
2140
  if (customFields && customFields.length > 0) {
1850
2141
  fields = customFields;
1851
2142
  } else {
1852
- const autoFields = this.getTableFields(tableName);
1853
- if (autoFields.length > 0) {
1854
- fields = autoFields;
2143
+ const systemFields = SYSTEM_TABLE_FIELDS[tableName];
2144
+ if (systemFields) {
2145
+ fields = systemFields;
1855
2146
  } else {
1856
- 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
+ }
1857
2158
  }
1858
2159
  }
1859
2160
  return fields.join("\n ");
1860
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
+ }
1861
2192
  };
1862
2193
  function createDubheGraphqlClient(config) {
1863
2194
  return new DubheGraphqlClient(config);
@@ -1918,10 +2249,97 @@ function toSnakeCaseForEnum(str) {
1918
2249
  }
1919
2250
  return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "").toUpperCase();
1920
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
+ }
1921
2327
  // Annotate the CommonJS export names for ESM import in node:
1922
2328
  0 && (module.exports = {
1923
2329
  DubheGraphqlClient,
1924
2330
  QueryBuilders,
1925
- 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
1926
2344
  });
1927
2345
  //# sourceMappingURL=index.js.map