@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.
@@ -0,0 +1,100 @@
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
+
9
+ export const ZERO_ADDRESS = '0x' + '0'.repeat(64);
10
+
11
+ export function hexToBytes(hex: string): Uint8Array {
12
+ const clean = hex.replace(/^0x/i, '');
13
+ const pairs = clean.match(/../g) ?? [];
14
+ return Uint8Array.from(pairs.map((b) => parseInt(b, 16)));
15
+ }
16
+
17
+ function readUIntLE(bytes: Uint8Array, offset: number, width: number): bigint {
18
+ let n = 0n;
19
+ for (let i = width - 1; i >= 0; i--) {
20
+ n = (n << 8n) | BigInt(bytes[offset + i] ?? 0);
21
+ }
22
+ return n;
23
+ }
24
+
25
+ /** Read a ULEB128-encoded length prefix. Returns [value, bytesConsumed]. */
26
+ function readUleb(bytes: Uint8Array, offset: number): [number, number] {
27
+ let value = 0;
28
+ let shift = 0;
29
+ let consumed = 0;
30
+ for (;;) {
31
+ const byte = bytes[offset + consumed] ?? 0;
32
+ value |= (byte & 0x7f) << shift;
33
+ consumed++;
34
+ if ((byte & 0x80) === 0) break;
35
+ shift += 7;
36
+ }
37
+ return [value, consumed];
38
+ }
39
+
40
+ export function decodeU8(hex: string): number {
41
+ return Number(readUIntLE(hexToBytes(hex), 0, 1));
42
+ }
43
+
44
+ export function decodeU16(hex: string): number {
45
+ return Number(readUIntLE(hexToBytes(hex), 0, 2));
46
+ }
47
+
48
+ export function decodeU32(hex: string): number {
49
+ return Number(readUIntLE(hexToBytes(hex), 0, 4));
50
+ }
51
+
52
+ export function decodeU64(hex: string): bigint {
53
+ return readUIntLE(hexToBytes(hex), 0, 8);
54
+ }
55
+
56
+ export function decodeU128(hex: string): bigint {
57
+ return readUIntLE(hexToBytes(hex), 0, 16);
58
+ }
59
+
60
+ export function decodeBool(hex: string): boolean {
61
+ return (hexToBytes(hex)[0] ?? 0) !== 0;
62
+ }
63
+
64
+ export function decodeAddress(hex: string): string {
65
+ const bytes = hexToBytes(hex);
66
+ return '0x' + Array.from(bytes.slice(0, 32), (b) => b.toString(16).padStart(2, '0')).join('');
67
+ }
68
+
69
+ export function decodeVectorAddress(hex: string): string[] {
70
+ const bytes = hexToBytes(hex);
71
+ const [len, consumed] = readUleb(bytes, 0);
72
+ const out: string[] = [];
73
+ for (let i = 0; i < len; i++) {
74
+ const start = consumed + i * 32;
75
+ out.push(
76
+ '0x' +
77
+ Array.from(bytes.slice(start, start + 32), (b) => b.toString(16).padStart(2, '0')).join('')
78
+ );
79
+ }
80
+ return out;
81
+ }
82
+
83
+ /** Decode a BCS ascii/utf8 String (ULEB length prefix + bytes). */
84
+ export function decodeString(hex: string): string {
85
+ const bytes = hexToBytes(hex);
86
+ const [len, consumed] = readUleb(bytes, 0);
87
+ return new TextDecoder().decode(bytes.slice(consumed, consumed + len));
88
+ }
89
+
90
+ /**
91
+ * Marketplace recordDataRaw is a JSON array of per-field hex strings
92
+ * (non-key fields, in schema order).
93
+ */
94
+ export function parseRecordData(recordDataRaw: string): string[] {
95
+ try {
96
+ return JSON.parse(recordDataRaw) as string[];
97
+ } catch {
98
+ return [recordDataRaw];
99
+ }
100
+ }
package/src/index.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/src/types.ts CHANGED
@@ -116,6 +116,105 @@ export interface StoreTableRow {
116
116
  [key: string]: any;
117
117
  }
118
118
 
119
+ export interface MarketplaceListingRow {
120
+ listingId: string;
121
+ dappKey: string;
122
+ seller: string;
123
+ recordType: string;
124
+ recordDataRaw: string;
125
+ price: string;
126
+ coinType: string;
127
+ isFungible: boolean;
128
+ status: 'listed' | 'sold' | 'cancelled' | 'expired';
129
+ buyer?: string | null;
130
+ listedUntil?: string | null;
131
+ createdAtCheckpoint: string;
132
+ updatedAtCheckpoint: string;
133
+ lastUpdateDigest: string;
134
+ }
135
+
136
+ export interface DubheSessionRow {
137
+ dappKey: string;
138
+ canonical: string;
139
+ sessionWallet: string;
140
+ expiresAt?: string | null;
141
+ active: boolean;
142
+ updatedAtCheckpoint: string;
143
+ lastUpdateDigest: string;
144
+ lastEventSeq: string;
145
+ }
146
+
147
+ export interface DubheUserStorageRow {
148
+ dappKey: string;
149
+ canonicalOwner: string;
150
+ userStorageId: string;
151
+ createdAtCheckpoint: string;
152
+ updatedAtCheckpoint: string;
153
+ lastUpdateDigest: string;
154
+ lastEventSeq: string;
155
+ }
156
+
157
+ export interface SceneStorageRow {
158
+ sceneId: string;
159
+ dappKey: string;
160
+ sceneType: string;
161
+ sceneTypeRaw: string;
162
+ authorizationKind?: string | null;
163
+ authorizationKindRaw?: string | null;
164
+ authorizedPermitId?: string | null;
165
+ isDestroyed: boolean;
166
+ createdAtCheckpoint: string;
167
+ destroyedAtCheckpoint?: string | null;
168
+ updatedAtCheckpoint: string;
169
+ lastUpdateDigest: string;
170
+ lastEventSeq: string;
171
+ }
172
+
173
+ export interface SceneStorageFieldRow {
174
+ sceneId: string;
175
+ fieldNameRaw: string;
176
+ dappKey: string;
177
+ sceneType: string;
178
+ sceneTypeRaw: string;
179
+ fieldName: string;
180
+ fieldValueRaw?: string | null;
181
+ isDeleted: boolean;
182
+ deletedAtCheckpoint?: string | null;
183
+ updatedAtCheckpoint: string;
184
+ lastUpdateDigest: string;
185
+ lastEventSeq: string;
186
+ }
187
+
188
+ export interface ObjectStorageRow {
189
+ objectId: string;
190
+ dappKey: string;
191
+ objectType: string;
192
+ objectTypeRaw: string;
193
+ entityIdRaw: string;
194
+ isDestroyed: boolean;
195
+ createdAtCheckpoint: string;
196
+ destroyedAtCheckpoint?: string | null;
197
+ updatedAtCheckpoint: string;
198
+ lastUpdateDigest: string;
199
+ lastEventSeq: string;
200
+ }
201
+
202
+ export interface DubheDappRuntimeStateRow {
203
+ dappKey: string;
204
+ admin?: string | null;
205
+ dappStorageId?: string | null;
206
+ packageId?: string | null;
207
+ version?: string | null;
208
+ creditPool?: string | null;
209
+ paused?: boolean | null;
210
+ settlementMode?: string | null;
211
+ createdAt?: string | null;
212
+ createdAtCheckpoint: string;
213
+ updatedAtCheckpoint: string;
214
+ lastUpdateDigest: string;
215
+ lastEventSeq: string;
216
+ }
217
+
119
218
  // Query builder type
120
219
  export interface QueryBuilder<_T> {
121
220
  where?: Record<string, any>;
@@ -274,6 +373,27 @@ export interface DubheClientConfig {
274
373
  fetchOptions?: RequestInit;
275
374
  retryOptions?: RetryOptions;
276
375
  dubheMetadata?: any;
376
+ /**
377
+ * When true, outgoing HTTP queries are collected within `batchInterval` ms
378
+ * and sent as a single batched POST request. The server must have
379
+ * `enableQueryBatching` / `allowBatchedHttpRequests` enabled (PostGraphile
380
+ * already sets this by default).
381
+ *
382
+ * Default: false
383
+ */
384
+ batchRequests?: boolean;
385
+ /**
386
+ * Time window (ms) to collect queries before flushing a batch.
387
+ * Only used when `batchRequests` is true.
388
+ * Default: 10
389
+ */
390
+ batchInterval?: number;
391
+ /**
392
+ * Maximum number of operations per batch.
393
+ * Only used when `batchRequests` is true.
394
+ * Default: 20
395
+ */
396
+ batchMax?: number;
277
397
  cacheConfig?: {
278
398
  paginatedTables?: string[];
279
399
  strategy?: PaginationCacheStrategy;