@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 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.
@@ -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,7 +37,19 @@ 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
 
@@ -1633,6 +1645,204 @@ var DubheGraphqlClient = class {
1633
1645
  totalCount: 0
1634
1646
  };
1635
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
+ }
1636
1846
  /**
1637
1847
  * Query DApp runtime state (credit pool, admin, package version, etc.).
1638
1848
  * Exposed as dubheDappRuntimeStates in GraphQL.
@@ -2039,10 +2249,97 @@ function toSnakeCaseForEnum(str) {
2039
2249
  }
2040
2250
  return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "").toUpperCase();
2041
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
+ }
2042
2327
  // Annotate the CommonJS export names for ESM import in node:
2043
2328
  0 && (module.exports = {
2044
2329
  DubheGraphqlClient,
2045
2330
  QueryBuilders,
2046
- 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
2047
2344
  });
2048
2345
  //# sourceMappingURL=index.js.map