@0xobelisk/graphql-client 1.2.0-pre.118 → 1.2.0-pre.119
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 +39 -1
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +226 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +50 -0
- package/package.json +1 -1
- package/src/client.ts +257 -1
- package/src/types.ts +54 -0
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 } from './types';
|
|
2
|
+
import { DubheClientConfig, Connection, BaseQueryParams, OrderBy, QueryOptions, QueryResult, SubscriptionResult, SubscriptionOptions, StoreTableRow, TypedDocumentNode, MultiTableSubscriptionConfig, MultiTableSubscriptionData, ParsedTableInfo, DubheMetadata, MarketplaceListingRow, DubheSessionRow, DubheUserStorageRow, DubheDappRuntimeStateRow } from './types';
|
|
3
3
|
export declare class DubheGraphqlClient {
|
|
4
4
|
private apolloClient;
|
|
5
5
|
private subscriptionClient?;
|
|
@@ -129,6 +129,44 @@ export declare class DubheGraphqlClient {
|
|
|
129
129
|
createRealTimeDataStream<T extends StoreTableRow>(tableName: string, initialQuery?: BaseQueryParams & {
|
|
130
130
|
filter?: Record<string, any>;
|
|
131
131
|
}): Observable<Connection<T>>;
|
|
132
|
+
/**
|
|
133
|
+
* Query marketplace listings indexed by the Dubhe indexer.
|
|
134
|
+
* Uses the marketplace_listings PostgreSQL table (exposed as dubheMarketplaceListings in GraphQL).
|
|
135
|
+
* The record_type field is pre-decoded text ("wheat", "corn", …) and status tracks
|
|
136
|
+
* active/sold/cancelled directly — no extra RPC calls needed.
|
|
137
|
+
*/
|
|
138
|
+
getMarketplaceListings(options?: {
|
|
139
|
+
dappKey?: string;
|
|
140
|
+
status?: 'listed' | 'sold' | 'cancelled' | 'expired';
|
|
141
|
+
recordType?: string;
|
|
142
|
+
seller?: string;
|
|
143
|
+
first?: number;
|
|
144
|
+
after?: string;
|
|
145
|
+
}): Promise<Connection<MarketplaceListingRow>>;
|
|
146
|
+
/**
|
|
147
|
+
* Query session keys indexed by the Dubhe indexer (dubheSessions in GraphQL).
|
|
148
|
+
*/
|
|
149
|
+
getDubheSessions(options?: {
|
|
150
|
+
dappKey?: string;
|
|
151
|
+
canonical?: string;
|
|
152
|
+
active?: boolean;
|
|
153
|
+
first?: number;
|
|
154
|
+
after?: string;
|
|
155
|
+
}): Promise<Connection<DubheSessionRow>>;
|
|
156
|
+
/**
|
|
157
|
+
* Query user storage registrations indexed by the Dubhe indexer (dubheUserStorages in GraphQL).
|
|
158
|
+
*/
|
|
159
|
+
getDubheUserStorages(options?: {
|
|
160
|
+
dappKey?: string;
|
|
161
|
+
canonicalOwner?: string;
|
|
162
|
+
first?: number;
|
|
163
|
+
after?: string;
|
|
164
|
+
}): Promise<Connection<DubheUserStorageRow>>;
|
|
165
|
+
/**
|
|
166
|
+
* Query DApp runtime state (credit pool, admin, package version, etc.).
|
|
167
|
+
* Exposed as dubheDappRuntimeStates in GraphQL.
|
|
168
|
+
*/
|
|
169
|
+
getDubheDappRuntimeState(dappKey: string): Promise<DubheDappRuntimeStateRow | null>;
|
|
132
170
|
private getFilterTypeName;
|
|
133
171
|
private getOrderByTypeName;
|
|
134
172
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1364,6 +1364,232 @@ var DubheGraphqlClient = class {
|
|
|
1364
1364
|
return () => subscription.subscribe().unsubscribe();
|
|
1365
1365
|
});
|
|
1366
1366
|
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Query marketplace listings indexed by the Dubhe indexer.
|
|
1369
|
+
* Uses the marketplace_listings PostgreSQL table (exposed as dubheMarketplaceListings in GraphQL).
|
|
1370
|
+
* The record_type field is pre-decoded text ("wheat", "corn", …) and status tracks
|
|
1371
|
+
* active/sold/cancelled directly — no extra RPC calls needed.
|
|
1372
|
+
*/
|
|
1373
|
+
async getMarketplaceListings(options) {
|
|
1374
|
+
const filter = {};
|
|
1375
|
+
if (options?.dappKey)
|
|
1376
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1377
|
+
if (options?.status !== void 0)
|
|
1378
|
+
filter.status = { equalTo: options.status };
|
|
1379
|
+
if (options?.recordType)
|
|
1380
|
+
filter.recordType = { equalTo: options.recordType };
|
|
1381
|
+
if (options?.seller)
|
|
1382
|
+
filter.seller = { equalTo: options.seller };
|
|
1383
|
+
const query = import_client2.gql`
|
|
1384
|
+
query GetMarketplaceListings(
|
|
1385
|
+
$first: Int
|
|
1386
|
+
$after: Cursor
|
|
1387
|
+
$filter: StoreDubheMarketplaceListingFilter
|
|
1388
|
+
$orderBy: [StoreDubheMarketplaceListingsOrderBy!]
|
|
1389
|
+
) {
|
|
1390
|
+
dubheMarketplaceListings(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1391
|
+
totalCount
|
|
1392
|
+
pageInfo {
|
|
1393
|
+
hasNextPage
|
|
1394
|
+
hasPreviousPage
|
|
1395
|
+
startCursor
|
|
1396
|
+
endCursor
|
|
1397
|
+
}
|
|
1398
|
+
edges {
|
|
1399
|
+
cursor
|
|
1400
|
+
node {
|
|
1401
|
+
listingId
|
|
1402
|
+
dappKey
|
|
1403
|
+
seller
|
|
1404
|
+
recordType
|
|
1405
|
+
recordDataRaw
|
|
1406
|
+
price
|
|
1407
|
+
coinType
|
|
1408
|
+
isFungible
|
|
1409
|
+
status
|
|
1410
|
+
buyer
|
|
1411
|
+
listedUntil
|
|
1412
|
+
createdAtCheckpoint
|
|
1413
|
+
updatedAtCheckpoint
|
|
1414
|
+
lastUpdateDigest
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
`;
|
|
1420
|
+
const result = await this.apolloClient.query({
|
|
1421
|
+
query,
|
|
1422
|
+
variables: {
|
|
1423
|
+
first: options?.first ?? 100,
|
|
1424
|
+
after: options?.after,
|
|
1425
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1426
|
+
orderBy: ["CREATED_AT_CHECKPOINT_DESC"]
|
|
1427
|
+
},
|
|
1428
|
+
fetchPolicy: "network-only"
|
|
1429
|
+
});
|
|
1430
|
+
if (result.error)
|
|
1431
|
+
throw result.error;
|
|
1432
|
+
return result.data?.dubheMarketplaceListings ?? {
|
|
1433
|
+
edges: [],
|
|
1434
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1435
|
+
totalCount: 0
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Query session keys indexed by the Dubhe indexer (dubheSessions in GraphQL).
|
|
1440
|
+
*/
|
|
1441
|
+
async getDubheSessions(options) {
|
|
1442
|
+
const filter = {};
|
|
1443
|
+
if (options?.dappKey)
|
|
1444
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1445
|
+
if (options?.canonical)
|
|
1446
|
+
filter.canonical = { equalTo: options.canonical };
|
|
1447
|
+
if (options?.active !== void 0)
|
|
1448
|
+
filter.active = { equalTo: options.active };
|
|
1449
|
+
const query = import_client2.gql`
|
|
1450
|
+
query GetDubheSessions(
|
|
1451
|
+
$first: Int
|
|
1452
|
+
$after: Cursor
|
|
1453
|
+
$filter: StoreDubheSessionFilter
|
|
1454
|
+
$orderBy: [StoreDubheSessionsOrderBy!]
|
|
1455
|
+
) {
|
|
1456
|
+
dubheSessions(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1457
|
+
totalCount
|
|
1458
|
+
pageInfo {
|
|
1459
|
+
hasNextPage
|
|
1460
|
+
hasPreviousPage
|
|
1461
|
+
startCursor
|
|
1462
|
+
endCursor
|
|
1463
|
+
}
|
|
1464
|
+
edges {
|
|
1465
|
+
cursor
|
|
1466
|
+
node {
|
|
1467
|
+
dappKey
|
|
1468
|
+
canonical
|
|
1469
|
+
sessionWallet
|
|
1470
|
+
expiresAt
|
|
1471
|
+
active
|
|
1472
|
+
updatedAtCheckpoint
|
|
1473
|
+
lastUpdateDigest
|
|
1474
|
+
lastEventSeq
|
|
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: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1487
|
+
},
|
|
1488
|
+
fetchPolicy: "network-only"
|
|
1489
|
+
});
|
|
1490
|
+
if (result.error)
|
|
1491
|
+
throw result.error;
|
|
1492
|
+
return result.data?.dubheSessions ?? {
|
|
1493
|
+
edges: [],
|
|
1494
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1495
|
+
totalCount: 0
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Query user storage registrations indexed by the Dubhe indexer (dubheUserStorages in GraphQL).
|
|
1500
|
+
*/
|
|
1501
|
+
async getDubheUserStorages(options) {
|
|
1502
|
+
const filter = {};
|
|
1503
|
+
if (options?.dappKey)
|
|
1504
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1505
|
+
if (options?.canonicalOwner)
|
|
1506
|
+
filter.canonicalOwner = { equalTo: options.canonicalOwner };
|
|
1507
|
+
const query = import_client2.gql`
|
|
1508
|
+
query GetDubheUserStorages(
|
|
1509
|
+
$first: Int
|
|
1510
|
+
$after: Cursor
|
|
1511
|
+
$filter: StoreDubheUserStorageFilter
|
|
1512
|
+
$orderBy: [StoreDubheUserStoragesOrderBy!]
|
|
1513
|
+
) {
|
|
1514
|
+
dubheUserStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1515
|
+
totalCount
|
|
1516
|
+
pageInfo {
|
|
1517
|
+
hasNextPage
|
|
1518
|
+
hasPreviousPage
|
|
1519
|
+
startCursor
|
|
1520
|
+
endCursor
|
|
1521
|
+
}
|
|
1522
|
+
edges {
|
|
1523
|
+
cursor
|
|
1524
|
+
node {
|
|
1525
|
+
dappKey
|
|
1526
|
+
canonicalOwner
|
|
1527
|
+
userStorageId
|
|
1528
|
+
createdAtCheckpoint
|
|
1529
|
+
updatedAtCheckpoint
|
|
1530
|
+
lastUpdateDigest
|
|
1531
|
+
lastEventSeq
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
`;
|
|
1537
|
+
const result = await this.apolloClient.query({
|
|
1538
|
+
query,
|
|
1539
|
+
variables: {
|
|
1540
|
+
first: options?.first ?? 100,
|
|
1541
|
+
after: options?.after,
|
|
1542
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1543
|
+
orderBy: ["CREATED_AT_CHECKPOINT_DESC"]
|
|
1544
|
+
},
|
|
1545
|
+
fetchPolicy: "network-only"
|
|
1546
|
+
});
|
|
1547
|
+
if (result.error)
|
|
1548
|
+
throw result.error;
|
|
1549
|
+
return result.data?.dubheUserStorages ?? {
|
|
1550
|
+
edges: [],
|
|
1551
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1552
|
+
totalCount: 0
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Query DApp runtime state (credit pool, admin, package version, etc.).
|
|
1557
|
+
* Exposed as dubheDappRuntimeStates in GraphQL.
|
|
1558
|
+
*/
|
|
1559
|
+
async getDubheDappRuntimeState(dappKey) {
|
|
1560
|
+
const query = import_client2.gql`
|
|
1561
|
+
query GetDubheDappRuntimeState($filter: StoreDubheDappRuntimeStateFilter) {
|
|
1562
|
+
dubheDappRuntimeStates(first: 1, filter: $filter) {
|
|
1563
|
+
edges {
|
|
1564
|
+
node {
|
|
1565
|
+
dappKey
|
|
1566
|
+
admin
|
|
1567
|
+
dappStorageId
|
|
1568
|
+
packageId
|
|
1569
|
+
version
|
|
1570
|
+
creditPool
|
|
1571
|
+
paused
|
|
1572
|
+
settlementMode
|
|
1573
|
+
createdAt
|
|
1574
|
+
createdAtCheckpoint
|
|
1575
|
+
updatedAtCheckpoint
|
|
1576
|
+
lastUpdateDigest
|
|
1577
|
+
lastEventSeq
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
`;
|
|
1583
|
+
const result = await this.apolloClient.query({
|
|
1584
|
+
query,
|
|
1585
|
+
variables: { filter: { dappKey: { equalTo: dappKey } } },
|
|
1586
|
+
fetchPolicy: "network-only"
|
|
1587
|
+
});
|
|
1588
|
+
if (result.error)
|
|
1589
|
+
throw result.error;
|
|
1590
|
+
const edges = result.data?.dubheDappRuntimeStates?.edges ?? [];
|
|
1591
|
+
return edges[0]?.node ?? null;
|
|
1592
|
+
}
|
|
1367
1593
|
// Improved table name handling methods
|
|
1368
1594
|
getFilterTypeName(tableName) {
|
|
1369
1595
|
const singularName = this.getSingularTableName(tableName);
|