@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/index.mjs CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  Observable,
23
23
  from
24
24
  } from "@apollo/client";
25
+ import { BatchHttpLink } from "@apollo/client/link/batch-http";
25
26
  import { RetryLink } from "@apollo/client/link/retry";
26
27
  import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
27
28
  import { getMainDefinition } from "@apollo/client/utilities";
@@ -736,6 +737,77 @@ import "graphql";
736
737
 
737
738
  // src/client.ts
738
739
  import pluralize from "pluralize";
740
+ var SYSTEM_TABLE_FIELDS = {
741
+ dubheDappMarketplaceFees: [
742
+ "dappKey",
743
+ "listingId",
744
+ "coinType",
745
+ "totalFee",
746
+ "treasuryAmount",
747
+ "dappAmount",
748
+ "updatedAtCheckpoint",
749
+ "lastUpdateDigest"
750
+ ],
751
+ dubheDappRuntimeState: [
752
+ "dappKey",
753
+ "admin",
754
+ "paused",
755
+ "settlementMode",
756
+ "creditPool",
757
+ "writeFeeShareBps",
758
+ "lastRuntimeEvent",
759
+ "lastRuntimeActor",
760
+ "lastRuntimeAmount",
761
+ "updatedAtCheckpoint",
762
+ "lastUpdateDigest"
763
+ ],
764
+ dubheDappFeeState: [
765
+ "entityId",
766
+ "baseFeePerWrite",
767
+ "bytesFeePerByte",
768
+ "freeCredit",
769
+ "creditPool",
770
+ "totalSettled",
771
+ "updatedAtTimestampMs",
772
+ "lastUpdateDigest"
773
+ ],
774
+ dubheDappRevenueState: [
775
+ "entityId",
776
+ "dappRevenue",
777
+ "coinType",
778
+ "updatedAtTimestampMs",
779
+ "lastUpdateDigest"
780
+ ],
781
+ dubheMarketplaceListings: [
782
+ "dappKey",
783
+ "listingId",
784
+ "seller",
785
+ "recordType",
786
+ "price",
787
+ "coinType",
788
+ "isFungible",
789
+ "listedUntil",
790
+ "status",
791
+ "updatedAtCheckpoint",
792
+ "lastUpdateDigest"
793
+ ],
794
+ dubheSessions: [
795
+ "dappKey",
796
+ "canonical",
797
+ "sessionWallet",
798
+ "expiresAt",
799
+ "active",
800
+ "updatedAtCheckpoint",
801
+ "lastUpdateDigest"
802
+ ],
803
+ dubheUserStorages: [
804
+ "dappKey",
805
+ "canonicalOwner",
806
+ "userStorageId",
807
+ "updatedAtCheckpoint",
808
+ "lastUpdateDigest"
809
+ ]
810
+ };
739
811
  function mapCachePolicyToFetchPolicy(cachePolicy) {
740
812
  switch (cachePolicy) {
741
813
  case "cache-first":
@@ -752,6 +824,23 @@ function mapCachePolicyToFetchPolicy(cachePolicy) {
752
824
  return "cache-first";
753
825
  }
754
826
  }
827
+ function buildHttpLink(config) {
828
+ const fetchFn = (input, init) => fetch(input, { ...config.fetchOptions, ...init ?? {} });
829
+ if (config.batchRequests) {
830
+ return new BatchHttpLink({
831
+ uri: config.endpoint,
832
+ headers: config.headers,
833
+ fetch: fetchFn,
834
+ batchInterval: config.batchInterval ?? 10,
835
+ batchMax: config.batchMax ?? 20
836
+ });
837
+ }
838
+ return createHttpLink({
839
+ uri: config.endpoint,
840
+ headers: config.headers,
841
+ fetch: fetchFn
842
+ });
843
+ }
755
844
  var DubheGraphqlClient = class {
756
845
  // Store current configuration for updates
757
846
  constructor(config) {
@@ -762,11 +851,7 @@ var DubheGraphqlClient = class {
762
851
  if (this.dubheMetadata) {
763
852
  this.parseTableInfoFromConfig();
764
853
  }
765
- const httpLink = createHttpLink({
766
- uri: config.endpoint,
767
- headers: config.headers,
768
- fetch: (input, init) => fetch(input, { ...config.fetchOptions, ...init })
769
- });
854
+ const httpLink = buildHttpLink(config);
770
855
  const retryLink = new RetryLink({
771
856
  delay: {
772
857
  // Initial retry delay time (milliseconds)
@@ -887,11 +972,7 @@ var DubheGraphqlClient = class {
887
972
  }
888
973
  this.subscriptionClient = void 0;
889
974
  }
890
- const httpLink = createHttpLink({
891
- uri: this.currentConfig.endpoint,
892
- headers: this.currentConfig.headers,
893
- fetch: (input, init) => fetch(input, { ...this.currentConfig.fetchOptions, ...init })
894
- });
975
+ const httpLink = buildHttpLink(this.currentConfig);
895
976
  const retryLink = new RetryLink({
896
977
  delay: {
897
978
  initial: this.currentConfig.retryOptions?.delay?.initial || 300,
@@ -1828,15 +1909,55 @@ var DubheGraphqlClient = class {
1828
1909
  if (customFields && customFields.length > 0) {
1829
1910
  fields = customFields;
1830
1911
  } else {
1831
- const autoFields = this.getTableFields(tableName);
1832
- if (autoFields.length > 0) {
1833
- fields = autoFields;
1912
+ const systemFields = SYSTEM_TABLE_FIELDS[tableName];
1913
+ if (systemFields) {
1914
+ fields = systemFields;
1834
1915
  } else {
1835
- fields = ["createdAtTimestampMs", "updatedAtTimestampMs", "isDeleted", "lastUpdateDigest"];
1916
+ const autoFields = this.getTableFields(tableName);
1917
+ if (autoFields.length > 0) {
1918
+ fields = autoFields;
1919
+ } else {
1920
+ fields = [
1921
+ "createdAtTimestampMs",
1922
+ "updatedAtTimestampMs",
1923
+ "isDeleted",
1924
+ "lastUpdateDigest"
1925
+ ];
1926
+ }
1836
1927
  }
1837
1928
  }
1838
1929
  return fields.join("\n ");
1839
1930
  }
1931
+ // ── Typed system-table query methods ─────────────────────────────────────
1932
+ /** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
1933
+ async getDappFeeState() {
1934
+ const result = await this.getAllTables("dubheDappFeeState", { first: 1 }).catch(
1935
+ () => null
1936
+ );
1937
+ return result?.edges?.[0]?.node ?? null;
1938
+ }
1939
+ /** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
1940
+ async getDappRevenueState() {
1941
+ const result = await this.getAllTables("dubheDappRevenueState", { first: 1 }).catch(
1942
+ () => null
1943
+ );
1944
+ return result?.edges?.[0]?.node ?? null;
1945
+ }
1946
+ /** Latest DApp runtime state (admin, settlement mode, last event). */
1947
+ async getDappRuntimeState() {
1948
+ const result = await this.getAllTables("dubheDappRuntimeState", { first: 1 }).catch(
1949
+ () => null
1950
+ );
1951
+ return result?.edges?.[0]?.node ?? null;
1952
+ }
1953
+ /** Marketplace fee records (one row per listing sold). */
1954
+ async getDappMarketplaceFees(options) {
1955
+ return this.getAllTables("dubheDappMarketplaceFees", {
1956
+ first: options?.first ?? 20,
1957
+ after: options?.after,
1958
+ orderBy: [{ field: "updatedAtCheckpoint", direction: "DESC" }]
1959
+ });
1960
+ }
1840
1961
  };
1841
1962
  function createDubheGraphqlClient(config) {
1842
1963
  return new DubheGraphqlClient(config);