@0xobelisk/sui-client 1.0.8 → 1.0.10

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
@@ -1045,6 +1045,49 @@ var ContractDataParsingError = class extends Error {
1045
1045
  }
1046
1046
  };
1047
1047
 
1048
+ // src/libs/suiIndexerClient/utils.ts
1049
+ var parseData = (data) => {
1050
+ if (typeof data !== "object" || data === null) {
1051
+ return data;
1052
+ }
1053
+ if (Array.isArray(data)) {
1054
+ return data.map((item) => parseData(item));
1055
+ }
1056
+ const parsedData = {};
1057
+ for (const key in data) {
1058
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
1059
+ const value = data[key];
1060
+ if (typeof value === "object" && value !== null) {
1061
+ if ("variant" in value) {
1062
+ parsedData[key] = value.variant;
1063
+ } else if ("fields" in value) {
1064
+ parsedData[key] = parseData(value.fields);
1065
+ } else {
1066
+ parsedData[key] = parseData(value);
1067
+ }
1068
+ } else {
1069
+ parsedData[key] = value;
1070
+ }
1071
+ }
1072
+ }
1073
+ return parsedData;
1074
+ };
1075
+ var parseValue = (value) => {
1076
+ if (typeof value !== "object" || value === null) {
1077
+ return value;
1078
+ }
1079
+ if (Array.isArray(value)) {
1080
+ return value.map((item) => parseValue(item));
1081
+ }
1082
+ if ("variant" in value) {
1083
+ return value.variant;
1084
+ }
1085
+ if ("fields" in value) {
1086
+ return parseData(value.fields);
1087
+ }
1088
+ return parseData(value);
1089
+ };
1090
+
1048
1091
  // src/libs/suiIndexerClient/index.ts
1049
1092
  var SuiIndexerClient = class {
1050
1093
  constructor(http) {
@@ -1055,8 +1098,8 @@ var SuiIndexerClient = class {
1055
1098
  }
1056
1099
  async getTransactions(params) {
1057
1100
  const query = `
1058
- query GetTransactions($first: Int, $after: String, $last: Int, $before: String, $checkpoint: Int, $orderBy: TransactionOrderBy, $distinct: Boolean) {
1059
- transactions(first: $first, after: $after, last: $last, before: $before, checkpoint: $checkpoint, orderBy: $orderBy, distinct: $distinct) {
1101
+ query GetTransactions($first: Int, $after: String, $checkpoint: Int, $orderBy: [TransactionOrderField!]) {
1102
+ transactions(first: $first, after: $after, checkpoint: $checkpoint, orderBy: $orderBy) {
1060
1103
  edges {
1061
1104
  cursor
1062
1105
  node {
@@ -1068,10 +1111,9 @@ var SuiIndexerClient = class {
1068
1111
  }
1069
1112
  pageInfo {
1070
1113
  hasNextPage
1071
- hasPreviousPage
1072
- startCursor
1073
1114
  endCursor
1074
1115
  }
1116
+ totalCount
1075
1117
  }
1076
1118
  }
1077
1119
  `;
@@ -1080,8 +1122,8 @@ var SuiIndexerClient = class {
1080
1122
  }
1081
1123
  async getSchemas(params) {
1082
1124
  const query = `
1083
- query GetSchemas($first: Int, $after: String, $last: Int, $before: String, $name: String, $key1: String, $key2: String, $orderBy: SchemaOrderBy, $distinct: Boolean) {
1084
- schemas(first: $first, after: $after, last: $last, before: $before, name: $name, key1: $key1, key2: $key2, orderBy: $orderBy, distinct: $distinct) {
1125
+ query GetSchemas($first: Int, $after: String, $name: String, $key1: String, $key2: String, $orderBy: [SchemaOrderField!]) {
1126
+ schemas(first: $first, after: $after, name: $name, key1: $key1, key2: $key2, orderBy: $orderBy) {
1085
1127
  edges {
1086
1128
  cursor
1087
1129
  node {
@@ -1099,10 +1141,9 @@ var SuiIndexerClient = class {
1099
1141
  }
1100
1142
  pageInfo {
1101
1143
  hasNextPage
1102
- hasPreviousPage
1103
- startCursor
1104
1144
  endCursor
1105
1145
  }
1146
+ totalCount
1106
1147
  }
1107
1148
  }
1108
1149
  `;
@@ -1111,8 +1152,8 @@ var SuiIndexerClient = class {
1111
1152
  }
1112
1153
  async getEvents(params) {
1113
1154
  const query = `
1114
- query GetEvents($first: Int, $after: String, $last: Int, $before: String, $name: String, $checkpoint: String, $orderBy: EventOrderBy, $distinct: Boolean) {
1115
- events(first: $first, after: $after, last: $last, before: $before, name: $name, checkpoint: $checkpoint, orderBy: $orderBy, distinct: $distinct) {
1155
+ query GetEvents($first: Int, $after: String, $name: String, $checkpoint: String, $orderBy: [EventOrderField!]) {
1156
+ events(first: $first, after: $after, name: $name, checkpoint: $checkpoint, orderBy: $orderBy) {
1116
1157
  edges {
1117
1158
  cursor
1118
1159
  node {
@@ -1126,10 +1167,9 @@ var SuiIndexerClient = class {
1126
1167
  }
1127
1168
  pageInfo {
1128
1169
  hasNextPage
1129
- hasPreviousPage
1130
- startCursor
1131
1170
  endCursor
1132
1171
  }
1172
+ totalCount
1133
1173
  }
1134
1174
  }
1135
1175
  `;
@@ -1142,10 +1182,7 @@ var SuiIndexerClient = class {
1142
1182
  key2,
1143
1183
  first,
1144
1184
  after,
1145
- last,
1146
- before,
1147
- orderBy,
1148
- distinct
1185
+ orderBy
1149
1186
  }) {
1150
1187
  const schemas = await this.getSchemas({
1151
1188
  name,
@@ -1153,12 +1190,37 @@ var SuiIndexerClient = class {
1153
1190
  key2,
1154
1191
  first,
1155
1192
  after,
1156
- last,
1157
- before,
1158
- orderBy,
1159
- distinct
1193
+ orderBy
1160
1194
  });
1161
- return schemas;
1195
+ const data = schemas.edges.map((edge) => edge.node);
1196
+ const value = data.map((item) => parseValue(item.value));
1197
+ return {
1198
+ data,
1199
+ value,
1200
+ pageInfo: schemas.pageInfo,
1201
+ totalCount: schemas.totalCount
1202
+ };
1203
+ }
1204
+ async getStorageItem({
1205
+ name,
1206
+ key1,
1207
+ key2
1208
+ }) {
1209
+ const schemas = await this.getSchemas({
1210
+ name,
1211
+ key1,
1212
+ key2,
1213
+ first: 1
1214
+ });
1215
+ const data = schemas.edges[0]?.node;
1216
+ if (!data) {
1217
+ return void 0;
1218
+ }
1219
+ const value = parseValue(data.value);
1220
+ return {
1221
+ data,
1222
+ value
1223
+ };
1162
1224
  }
1163
1225
  async subscribe(names, handleData) {
1164
1226
  return this.http.subscribe(names, handleData);
@@ -2149,16 +2211,48 @@ var Dubhe = class {
2149
2211
  params: processedParams
2150
2212
  });
2151
2213
  }
2214
+ async getTransactions({
2215
+ first,
2216
+ after,
2217
+ orderBy
2218
+ }) {
2219
+ return await this.suiIndexerClient.getTransactions({
2220
+ first,
2221
+ after,
2222
+ orderBy
2223
+ });
2224
+ }
2225
+ async getEvents({
2226
+ first,
2227
+ after,
2228
+ orderBy
2229
+ }) {
2230
+ return await this.suiIndexerClient.getEvents({ first, after, orderBy });
2231
+ }
2232
+ async getSchemas({
2233
+ name,
2234
+ key1,
2235
+ key2,
2236
+ first,
2237
+ after,
2238
+ orderBy
2239
+ }) {
2240
+ return await this.suiIndexerClient.getSchemas({
2241
+ name,
2242
+ key1,
2243
+ key2,
2244
+ first,
2245
+ after,
2246
+ orderBy
2247
+ });
2248
+ }
2152
2249
  async getStorage({
2153
2250
  name,
2154
2251
  key1,
2155
2252
  key2,
2156
2253
  first,
2157
2254
  after,
2158
- last,
2159
- before,
2160
- orderBy,
2161
- distinct
2255
+ orderBy
2162
2256
  }) {
2163
2257
  return await this.suiIndexerClient.getStorage({
2164
2258
  name,
@@ -2166,11 +2260,20 @@ var Dubhe = class {
2166
2260
  key2,
2167
2261
  first,
2168
2262
  after,
2169
- last,
2170
- before,
2171
- orderBy,
2172
- distinct
2263
+ orderBy
2264
+ });
2265
+ }
2266
+ async getStorageItem({
2267
+ name,
2268
+ key1,
2269
+ key2
2270
+ }) {
2271
+ const response = await this.suiIndexerClient.getStorageItem({
2272
+ name,
2273
+ key1,
2274
+ key2
2173
2275
  });
2276
+ return response;
2174
2277
  }
2175
2278
  async subscribe(names, handleData) {
2176
2279
  return this.suiIndexerClient.subscribe(names, handleData);