@0xobelisk/graphql-client 1.2.0-pre.122 → 1.2.0-pre.124
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 +42 -0
- package/dist/index.js +135 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -14
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +21 -0
- package/package.json +1 -1
- package/src/client.ts +206 -17
- package/src/types.ts +21 -0
package/dist/client.d.ts
CHANGED
|
@@ -255,6 +255,48 @@ export declare class DubheGraphqlClient {
|
|
|
255
255
|
* Convert table fields to GraphQL query string
|
|
256
256
|
*/
|
|
257
257
|
private convertTableFields;
|
|
258
|
+
/** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
|
|
259
|
+
getDappFeeState(): Promise<{
|
|
260
|
+
entityId: string;
|
|
261
|
+
baseFeePerWrite: string;
|
|
262
|
+
bytesFeePerByte: string;
|
|
263
|
+
freeCredit: string;
|
|
264
|
+
creditPool: string;
|
|
265
|
+
totalSettled: string;
|
|
266
|
+
updatedAtTimestampMs: string;
|
|
267
|
+
} | null>;
|
|
268
|
+
/** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
|
|
269
|
+
getDappRevenueState(): Promise<{
|
|
270
|
+
entityId: string;
|
|
271
|
+
dappRevenue: string;
|
|
272
|
+
coinType: string;
|
|
273
|
+
updatedAtTimestampMs: string;
|
|
274
|
+
} | null>;
|
|
275
|
+
/** Latest DApp runtime state (admin, settlement mode, last event). */
|
|
276
|
+
getDappRuntimeState(): Promise<{
|
|
277
|
+
dappKey: string;
|
|
278
|
+
admin: string;
|
|
279
|
+
paused: boolean;
|
|
280
|
+
settlementMode: number;
|
|
281
|
+
creditPool: string;
|
|
282
|
+
writeFeeShareBps: number;
|
|
283
|
+
lastRuntimeEvent: string;
|
|
284
|
+
lastRuntimeActor: string;
|
|
285
|
+
lastRuntimeAmount: string;
|
|
286
|
+
} | null>;
|
|
287
|
+
/** Marketplace fee records (one row per listing sold). */
|
|
288
|
+
getDappMarketplaceFees(options?: {
|
|
289
|
+
first?: number;
|
|
290
|
+
after?: string;
|
|
291
|
+
}): Promise<Connection<{
|
|
292
|
+
dappKey: string;
|
|
293
|
+
listingId: string;
|
|
294
|
+
coinType: string;
|
|
295
|
+
totalFee: string;
|
|
296
|
+
treasuryAmount: string;
|
|
297
|
+
dappAmount: string;
|
|
298
|
+
updatedAtCheckpoint: string;
|
|
299
|
+
}>>;
|
|
258
300
|
}
|
|
259
301
|
export declare function createDubheGraphqlClient(config: DubheClientConfig): DubheGraphqlClient;
|
|
260
302
|
export declare const QueryBuilders: {
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
43
43
|
|
|
44
44
|
// src/client.ts
|
|
45
45
|
var import_client2 = require("@apollo/client");
|
|
46
|
+
var import_batch_http = require("@apollo/client/link/batch-http");
|
|
46
47
|
var import_retry = require("@apollo/client/link/retry");
|
|
47
48
|
var import_subscriptions = require("@apollo/client/link/subscriptions");
|
|
48
49
|
var import_utilities = require("@apollo/client/utilities");
|
|
@@ -757,6 +758,77 @@ var import_graphql = require("graphql");
|
|
|
757
758
|
|
|
758
759
|
// src/client.ts
|
|
759
760
|
var import_pluralize = __toESM(require("pluralize"));
|
|
761
|
+
var SYSTEM_TABLE_FIELDS = {
|
|
762
|
+
dubheDappMarketplaceFees: [
|
|
763
|
+
"dappKey",
|
|
764
|
+
"listingId",
|
|
765
|
+
"coinType",
|
|
766
|
+
"totalFee",
|
|
767
|
+
"treasuryAmount",
|
|
768
|
+
"dappAmount",
|
|
769
|
+
"updatedAtCheckpoint",
|
|
770
|
+
"lastUpdateDigest"
|
|
771
|
+
],
|
|
772
|
+
dubheDappRuntimeState: [
|
|
773
|
+
"dappKey",
|
|
774
|
+
"admin",
|
|
775
|
+
"paused",
|
|
776
|
+
"settlementMode",
|
|
777
|
+
"creditPool",
|
|
778
|
+
"writeFeeShareBps",
|
|
779
|
+
"lastRuntimeEvent",
|
|
780
|
+
"lastRuntimeActor",
|
|
781
|
+
"lastRuntimeAmount",
|
|
782
|
+
"updatedAtCheckpoint",
|
|
783
|
+
"lastUpdateDigest"
|
|
784
|
+
],
|
|
785
|
+
dubheDappFeeState: [
|
|
786
|
+
"entityId",
|
|
787
|
+
"baseFeePerWrite",
|
|
788
|
+
"bytesFeePerByte",
|
|
789
|
+
"freeCredit",
|
|
790
|
+
"creditPool",
|
|
791
|
+
"totalSettled",
|
|
792
|
+
"updatedAtTimestampMs",
|
|
793
|
+
"lastUpdateDigest"
|
|
794
|
+
],
|
|
795
|
+
dubheDappRevenueState: [
|
|
796
|
+
"entityId",
|
|
797
|
+
"dappRevenue",
|
|
798
|
+
"coinType",
|
|
799
|
+
"updatedAtTimestampMs",
|
|
800
|
+
"lastUpdateDigest"
|
|
801
|
+
],
|
|
802
|
+
dubheMarketplaceListings: [
|
|
803
|
+
"dappKey",
|
|
804
|
+
"listingId",
|
|
805
|
+
"seller",
|
|
806
|
+
"recordType",
|
|
807
|
+
"price",
|
|
808
|
+
"coinType",
|
|
809
|
+
"isFungible",
|
|
810
|
+
"listedUntil",
|
|
811
|
+
"status",
|
|
812
|
+
"updatedAtCheckpoint",
|
|
813
|
+
"lastUpdateDigest"
|
|
814
|
+
],
|
|
815
|
+
dubheSessions: [
|
|
816
|
+
"dappKey",
|
|
817
|
+
"canonical",
|
|
818
|
+
"sessionWallet",
|
|
819
|
+
"expiresAt",
|
|
820
|
+
"active",
|
|
821
|
+
"updatedAtCheckpoint",
|
|
822
|
+
"lastUpdateDigest"
|
|
823
|
+
],
|
|
824
|
+
dubheUserStorages: [
|
|
825
|
+
"dappKey",
|
|
826
|
+
"canonicalOwner",
|
|
827
|
+
"userStorageId",
|
|
828
|
+
"updatedAtCheckpoint",
|
|
829
|
+
"lastUpdateDigest"
|
|
830
|
+
]
|
|
831
|
+
};
|
|
760
832
|
function mapCachePolicyToFetchPolicy(cachePolicy) {
|
|
761
833
|
switch (cachePolicy) {
|
|
762
834
|
case "cache-first":
|
|
@@ -773,6 +845,23 @@ function mapCachePolicyToFetchPolicy(cachePolicy) {
|
|
|
773
845
|
return "cache-first";
|
|
774
846
|
}
|
|
775
847
|
}
|
|
848
|
+
function buildHttpLink(config) {
|
|
849
|
+
const fetchFn = (input, init) => fetch(input, { ...config.fetchOptions, ...init ?? {} });
|
|
850
|
+
if (config.batchRequests) {
|
|
851
|
+
return new import_batch_http.BatchHttpLink({
|
|
852
|
+
uri: config.endpoint,
|
|
853
|
+
headers: config.headers,
|
|
854
|
+
fetch: fetchFn,
|
|
855
|
+
batchInterval: config.batchInterval ?? 10,
|
|
856
|
+
batchMax: config.batchMax ?? 20
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
return (0, import_client2.createHttpLink)({
|
|
860
|
+
uri: config.endpoint,
|
|
861
|
+
headers: config.headers,
|
|
862
|
+
fetch: fetchFn
|
|
863
|
+
});
|
|
864
|
+
}
|
|
776
865
|
var DubheGraphqlClient = class {
|
|
777
866
|
// Store current configuration for updates
|
|
778
867
|
constructor(config) {
|
|
@@ -783,11 +872,7 @@ var DubheGraphqlClient = class {
|
|
|
783
872
|
if (this.dubheMetadata) {
|
|
784
873
|
this.parseTableInfoFromConfig();
|
|
785
874
|
}
|
|
786
|
-
const httpLink = (
|
|
787
|
-
uri: config.endpoint,
|
|
788
|
-
headers: config.headers,
|
|
789
|
-
fetch: (input, init) => fetch(input, { ...config.fetchOptions, ...init })
|
|
790
|
-
});
|
|
875
|
+
const httpLink = buildHttpLink(config);
|
|
791
876
|
const retryLink = new import_retry.RetryLink({
|
|
792
877
|
delay: {
|
|
793
878
|
// Initial retry delay time (milliseconds)
|
|
@@ -908,11 +993,7 @@ var DubheGraphqlClient = class {
|
|
|
908
993
|
}
|
|
909
994
|
this.subscriptionClient = void 0;
|
|
910
995
|
}
|
|
911
|
-
const httpLink = (
|
|
912
|
-
uri: this.currentConfig.endpoint,
|
|
913
|
-
headers: this.currentConfig.headers,
|
|
914
|
-
fetch: (input, init) => fetch(input, { ...this.currentConfig.fetchOptions, ...init })
|
|
915
|
-
});
|
|
996
|
+
const httpLink = buildHttpLink(this.currentConfig);
|
|
916
997
|
const retryLink = new import_retry.RetryLink({
|
|
917
998
|
delay: {
|
|
918
999
|
initial: this.currentConfig.retryOptions?.delay?.initial || 300,
|
|
@@ -1849,15 +1930,55 @@ var DubheGraphqlClient = class {
|
|
|
1849
1930
|
if (customFields && customFields.length > 0) {
|
|
1850
1931
|
fields = customFields;
|
|
1851
1932
|
} else {
|
|
1852
|
-
const
|
|
1853
|
-
if (
|
|
1854
|
-
fields =
|
|
1933
|
+
const systemFields = SYSTEM_TABLE_FIELDS[tableName];
|
|
1934
|
+
if (systemFields) {
|
|
1935
|
+
fields = systemFields;
|
|
1855
1936
|
} else {
|
|
1856
|
-
|
|
1937
|
+
const autoFields = this.getTableFields(tableName);
|
|
1938
|
+
if (autoFields.length > 0) {
|
|
1939
|
+
fields = autoFields;
|
|
1940
|
+
} else {
|
|
1941
|
+
fields = [
|
|
1942
|
+
"createdAtTimestampMs",
|
|
1943
|
+
"updatedAtTimestampMs",
|
|
1944
|
+
"isDeleted",
|
|
1945
|
+
"lastUpdateDigest"
|
|
1946
|
+
];
|
|
1947
|
+
}
|
|
1857
1948
|
}
|
|
1858
1949
|
}
|
|
1859
1950
|
return fields.join("\n ");
|
|
1860
1951
|
}
|
|
1952
|
+
// ── Typed system-table query methods ─────────────────────────────────────
|
|
1953
|
+
/** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
|
|
1954
|
+
async getDappFeeState() {
|
|
1955
|
+
const result = await this.getAllTables("dubheDappFeeState", { first: 1 }).catch(
|
|
1956
|
+
() => null
|
|
1957
|
+
);
|
|
1958
|
+
return result?.edges?.[0]?.node ?? null;
|
|
1959
|
+
}
|
|
1960
|
+
/** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
|
|
1961
|
+
async getDappRevenueState() {
|
|
1962
|
+
const result = await this.getAllTables("dubheDappRevenueState", { first: 1 }).catch(
|
|
1963
|
+
() => null
|
|
1964
|
+
);
|
|
1965
|
+
return result?.edges?.[0]?.node ?? null;
|
|
1966
|
+
}
|
|
1967
|
+
/** Latest DApp runtime state (admin, settlement mode, last event). */
|
|
1968
|
+
async getDappRuntimeState() {
|
|
1969
|
+
const result = await this.getAllTables("dubheDappRuntimeState", { first: 1 }).catch(
|
|
1970
|
+
() => null
|
|
1971
|
+
);
|
|
1972
|
+
return result?.edges?.[0]?.node ?? null;
|
|
1973
|
+
}
|
|
1974
|
+
/** Marketplace fee records (one row per listing sold). */
|
|
1975
|
+
async getDappMarketplaceFees(options) {
|
|
1976
|
+
return this.getAllTables("dubheDappMarketplaceFees", {
|
|
1977
|
+
first: options?.first ?? 20,
|
|
1978
|
+
after: options?.after,
|
|
1979
|
+
orderBy: [{ field: "updatedAtCheckpoint", direction: "DESC" }]
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1861
1982
|
};
|
|
1862
1983
|
function createDubheGraphqlClient(config) {
|
|
1863
1984
|
return new DubheGraphqlClient(config);
|