@0xsequence/indexer 3.0.0-beta.8 → 3.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.
@@ -1,67 +1,21 @@
1
- "use strict";
2
1
  /* eslint-disable */
3
- // sequence-indexer v0.4.0 5be4a3e78d9c7e0cc378c675ec01c518e83772e3
2
+ // sequence-indexer v0.4.0 212120aad9a46e88ead9a2183c5717e9902d8c2b
4
3
  // --
5
- // Code generated by webrpc-gen@v0.21.1 with typescript generator. DO NOT EDIT.
4
+ // Code generated by Webrpc-gen@v0.31.2 with typescript generator. DO NOT EDIT.
6
5
  //
7
- // webrpc-gen -schema=indexer.ridl -service=IndexerGateway -target=typescript -client -out=./clients/indexergw.gen.ts
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.UnavailableError = exports.InvalidArgumentError = exports.TimeoutError = exports.AtLeastOneKeyError = exports.MaxAccessKeysError = exports.NoDefaultKeyError = exports.RateLimitError = exports.QuotaExceededError = exports.UnauthorizedUserError = exports.InvalidServiceError = exports.InvalidOriginError = exports.AccessKeyMismatchError = exports.AccessKeyNotFoundError = exports.ProjectNotFoundError = exports.RateLimitedError = exports.GeoblockedError = exports.AbortedError = exports.RequestConflictError = exports.MethodNotFoundError = exports.SessionExpiredError = exports.PermissionDeniedError = exports.UnauthorizedError = exports.WebrpcStreamFinishedError = exports.WebrpcStreamLostError = exports.WebrpcClientDisconnectedError = exports.WebrpcInternalErrorError = exports.WebrpcServerPanicError = exports.WebrpcBadResponseError = exports.WebrpcBadRequestError = exports.WebrpcBadMethodError = exports.WebrpcBadRouteError = exports.WebrpcRequestFailedError = exports.WebrpcEndpointError = exports.WebrpcError = exports.IndexerGateway = exports.ContractVerificationStatus = exports.SortOrder = exports.TransactionType = exports.TransactionStatus = exports.TxnTransferType = exports.OrderStatus = exports.EventLogDataType = exports.EventLogType = exports.ContractType = exports.ResourceStatus = exports.WebRPCSchemaHash = exports.WebRPCSchemaVersion = exports.WebRPCVersion = exports.WebrpcHeaderValue = exports.WebrpcHeader = void 0;
10
- exports.errors = exports.MetadataCallFailedError = exports.NotFoundError = exports.ResourceExhaustedError = exports.QueryFailedError = void 0;
11
- exports.VersionFromHeader = VersionFromHeader;
12
- exports.WebrpcHeader = 'Webrpc';
13
- exports.WebrpcHeaderValue = 'webrpc@v0.21.1;gen-typescript@v0.15.1;sequence-indexer@v0.4.0';
14
- // WebRPC description and code-gen version
15
- exports.WebRPCVersion = 'v1';
6
+ // webrpc-gen -schema=merged.gen.json -service=IndexerGateway -target=typescript -client -out=./clients/indexergw.gen.ts
7
+ // Webrpc description and code-gen version
8
+ export const WebrpcVersion = 'v1';
16
9
  // Schema version of your RIDL schema
17
- exports.WebRPCSchemaVersion = 'v0.4.0';
10
+ export const WebrpcSchemaVersion = 'v0.4.0';
18
11
  // Schema hash generated from your RIDL schema
19
- exports.WebRPCSchemaHash = '5be4a3e78d9c7e0cc378c675ec01c518e83772e3';
20
- function VersionFromHeader(headers) {
21
- const headerValue = headers.get(exports.WebrpcHeader);
22
- if (!headerValue) {
23
- return {
24
- webrpcGenVersion: '',
25
- codeGenName: '',
26
- codeGenVersion: '',
27
- schemaName: '',
28
- schemaVersion: '',
29
- };
30
- }
31
- return parseWebrpcGenVersions(headerValue);
32
- }
33
- function parseWebrpcGenVersions(header) {
34
- const versions = header.split(';');
35
- if (versions.length < 3) {
36
- return {
37
- webrpcGenVersion: '',
38
- codeGenName: '',
39
- codeGenVersion: '',
40
- schemaName: '',
41
- schemaVersion: '',
42
- };
43
- }
44
- const [_, webrpcGenVersion] = versions[0].split('@');
45
- const [codeGenName, codeGenVersion] = versions[1].split('@');
46
- const [schemaName, schemaVersion] = versions[2].split('@');
47
- return {
48
- webrpcGenVersion: webrpcGenVersion,
49
- codeGenName: codeGenName,
50
- codeGenVersion: codeGenVersion,
51
- schemaName: schemaName,
52
- schemaVersion: schemaVersion,
53
- };
54
- }
55
- //
56
- // Types
57
- //
58
- var ResourceStatus;
59
- (function (ResourceStatus) {
60
- ResourceStatus["NOT_AVAILABLE"] = "NOT_AVAILABLE";
61
- ResourceStatus["REFRESHING"] = "REFRESHING";
62
- ResourceStatus["AVAILABLE"] = "AVAILABLE";
63
- })(ResourceStatus || (exports.ResourceStatus = ResourceStatus = {}));
64
- var ContractType;
12
+ export const WebrpcSchemaHash = '212120aad9a46e88ead9a2183c5717e9902d8c2b';
13
+ export var BackupMode;
14
+ (function (BackupMode) {
15
+ BackupMode["INCREMENTAL"] = "INCREMENTAL";
16
+ BackupMode["COMPLETE"] = "COMPLETE";
17
+ })(BackupMode || (BackupMode = {}));
18
+ export var ContractType;
65
19
  (function (ContractType) {
66
20
  ContractType["UNKNOWN"] = "UNKNOWN";
67
21
  ContractType["NATIVE"] = "NATIVE";
@@ -73,58 +27,71 @@ var ContractType;
73
27
  ContractType["ERC721_BRIDGE"] = "ERC721_BRIDGE";
74
28
  ContractType["ERC1155_BRIDGE"] = "ERC1155_BRIDGE";
75
29
  ContractType["SEQ_MARKETPLACE"] = "SEQ_MARKETPLACE";
76
- })(ContractType || (exports.ContractType = ContractType = {}));
77
- var EventLogType;
78
- (function (EventLogType) {
79
- EventLogType["UNKNOWN"] = "UNKNOWN";
80
- EventLogType["BLOCK_ADDED"] = "BLOCK_ADDED";
81
- EventLogType["BLOCK_REMOVED"] = "BLOCK_REMOVED";
82
- })(EventLogType || (exports.EventLogType = EventLogType = {}));
83
- var EventLogDataType;
30
+ ContractType["ERC6909"] = "ERC6909";
31
+ })(ContractType || (ContractType = {}));
32
+ export var ContractVerificationStatus;
33
+ (function (ContractVerificationStatus) {
34
+ ContractVerificationStatus["VERIFIED"] = "VERIFIED";
35
+ ContractVerificationStatus["UNVERIFIED"] = "UNVERIFIED";
36
+ ContractVerificationStatus["ALL"] = "ALL";
37
+ })(ContractVerificationStatus || (ContractVerificationStatus = {}));
38
+ export var EventLogDataType;
84
39
  (function (EventLogDataType) {
85
40
  EventLogDataType["EVENT"] = "EVENT";
86
41
  EventLogDataType["TOKEN_TRANSFER"] = "TOKEN_TRANSFER";
87
42
  EventLogDataType["NATIVE_TOKEN_TRANSFER"] = "NATIVE_TOKEN_TRANSFER";
88
43
  EventLogDataType["SEQUENCE_TXN"] = "SEQUENCE_TXN";
89
- })(EventLogDataType || (exports.EventLogDataType = EventLogDataType = {}));
90
- var OrderStatus;
44
+ })(EventLogDataType || (EventLogDataType = {}));
45
+ export var EventLogType;
46
+ (function (EventLogType) {
47
+ EventLogType["UNKNOWN"] = "UNKNOWN";
48
+ EventLogType["BLOCK_ADDED"] = "BLOCK_ADDED";
49
+ EventLogType["BLOCK_REMOVED"] = "BLOCK_REMOVED";
50
+ })(EventLogType || (EventLogType = {}));
51
+ export var NetworkType;
52
+ (function (NetworkType) {
53
+ NetworkType["MAINNETS"] = "MAINNETS";
54
+ NetworkType["TESTNETS"] = "TESTNETS";
55
+ NetworkType["ALL"] = "ALL";
56
+ })(NetworkType || (NetworkType = {}));
57
+ export var OrderStatus;
91
58
  (function (OrderStatus) {
92
59
  OrderStatus["OPEN"] = "OPEN";
93
60
  OrderStatus["CLOSED"] = "CLOSED";
94
61
  OrderStatus["CANCELLED"] = "CANCELLED";
95
- })(OrderStatus || (exports.OrderStatus = OrderStatus = {}));
96
- var TxnTransferType;
97
- (function (TxnTransferType) {
98
- TxnTransferType["UNKNOWN"] = "UNKNOWN";
99
- TxnTransferType["SEND"] = "SEND";
100
- TxnTransferType["RECEIVE"] = "RECEIVE";
101
- })(TxnTransferType || (exports.TxnTransferType = TxnTransferType = {}));
102
- var TransactionStatus;
62
+ })(OrderStatus || (OrderStatus = {}));
63
+ export var ResourceStatus;
64
+ (function (ResourceStatus) {
65
+ ResourceStatus["NOT_AVAILABLE"] = "NOT_AVAILABLE";
66
+ ResourceStatus["REFRESHING"] = "REFRESHING";
67
+ ResourceStatus["AVAILABLE"] = "AVAILABLE";
68
+ })(ResourceStatus || (ResourceStatus = {}));
69
+ export var SortOrder;
70
+ (function (SortOrder) {
71
+ SortOrder["DESC"] = "DESC";
72
+ SortOrder["ASC"] = "ASC";
73
+ })(SortOrder || (SortOrder = {}));
74
+ export var TransactionStatus;
103
75
  (function (TransactionStatus) {
104
76
  TransactionStatus["FAILED"] = "FAILED";
105
77
  TransactionStatus["SUCCESSFUL"] = "SUCCESSFUL";
106
- })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
107
- var TransactionType;
78
+ })(TransactionStatus || (TransactionStatus = {}));
79
+ export var TransactionType;
108
80
  (function (TransactionType) {
109
81
  TransactionType["LegacyTxnType"] = "LegacyTxnType";
110
82
  TransactionType["AccessListTxnType"] = "AccessListTxnType";
111
83
  TransactionType["DynamicFeeTxnType"] = "DynamicFeeTxnType";
112
- })(TransactionType || (exports.TransactionType = TransactionType = {}));
113
- var SortOrder;
114
- (function (SortOrder) {
115
- SortOrder["DESC"] = "DESC";
116
- SortOrder["ASC"] = "ASC";
117
- })(SortOrder || (exports.SortOrder = SortOrder = {}));
118
- var ContractVerificationStatus;
119
- (function (ContractVerificationStatus) {
120
- ContractVerificationStatus["VERIFIED"] = "VERIFIED";
121
- ContractVerificationStatus["UNVERIFIED"] = "UNVERIFIED";
122
- ContractVerificationStatus["ALL"] = "ALL";
123
- })(ContractVerificationStatus || (exports.ContractVerificationStatus = ContractVerificationStatus = {}));
84
+ })(TransactionType || (TransactionType = {}));
85
+ export var TxnTransferType;
86
+ (function (TxnTransferType) {
87
+ TxnTransferType["UNKNOWN"] = "UNKNOWN";
88
+ TxnTransferType["SEND"] = "SEND";
89
+ TxnTransferType["RECEIVE"] = "RECEIVE";
90
+ })(TxnTransferType || (TxnTransferType = {}));
124
91
  //
125
92
  // Client
126
93
  //
127
- class IndexerGateway {
94
+ export class IndexerGateway {
128
95
  hostname;
129
96
  fetch;
130
97
  path = '/rpc/IndexerGateway/';
@@ -135,138 +102,157 @@ class IndexerGateway {
135
102
  url(name) {
136
103
  return this.hostname + this.path + name;
137
104
  }
138
- getNativeTokenBalance = (args, headers, signal) => {
139
- return this.fetch(this.url('GetNativeTokenBalance'), createHTTPRequest(args, headers, signal)).then((res) => {
140
- return buildResponse(res).then((_data) => {
141
- return {
142
- balances: _data.balances,
143
- };
105
+ queryKey = {
106
+ getBalanceUpdates: (req) => ['IndexerGateway', 'getBalanceUpdates', req],
107
+ getChains: (req) => ['IndexerGateway', 'getChains', req],
108
+ getNativeTokenBalance: (req) => ['IndexerGateway', 'getNativeTokenBalance', req],
109
+ getTokenBalances: (req) => ['IndexerGateway', 'getTokenBalances', req],
110
+ getTokenBalancesByContract: (req) => ['IndexerGateway', 'getTokenBalancesByContract', req],
111
+ getTokenBalancesDetails: (req) => ['IndexerGateway', 'getTokenBalancesDetails', req],
112
+ getTokenBalancesSummary: (req) => ['IndexerGateway', 'getTokenBalancesSummary', req],
113
+ getTokenPrice: (req) => ['IndexerGateway', 'getTokenPrice', req],
114
+ getTokenPrices: (req) => ['IndexerGateway', 'getTokenPrices', req],
115
+ getTransactionHistory: (req) => ['IndexerGateway', 'getTransactionHistory', req],
116
+ ping: () => ['IndexerGateway', 'ping'],
117
+ runtimeStatus: () => ['IndexerGateway', 'runtimeStatus'],
118
+ version: () => ['IndexerGateway', 'version']
119
+ };
120
+ getBalanceUpdates = (req, headers, signal) => {
121
+ return this.fetch(this.url('GetBalanceUpdates'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
122
+ return buildResponse(res).then(_data => {
123
+ return JsonDecode(_data, 'GetBalanceUpdatesResponse');
144
124
  });
145
- }, (error) => {
146
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
125
+ }, error => {
126
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
147
127
  });
148
128
  };
149
- getTokenBalances = (args, headers, signal) => {
150
- return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then((res) => {
151
- return buildResponse(res).then((_data) => {
152
- return {
153
- page: _data.page,
154
- balances: _data.balances,
155
- };
129
+ getChains = (req, headers, signal) => {
130
+ return this.fetch(this.url('GetChains'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
131
+ return buildResponse(res).then(_data => {
132
+ return JsonDecode(_data, 'GetChainsResponse');
156
133
  });
157
- }, (error) => {
158
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
134
+ }, error => {
135
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
159
136
  });
160
137
  };
161
- getTokenBalancesSummary = (args, headers, signal) => {
162
- return this.fetch(this.url('GetTokenBalancesSummary'), createHTTPRequest(args, headers, signal)).then((res) => {
163
- return buildResponse(res).then((_data) => {
164
- return {
165
- page: _data.page,
166
- nativeBalances: _data.nativeBalances,
167
- balances: _data.balances,
168
- };
138
+ getNativeTokenBalance = (req, headers, signal) => {
139
+ return this.fetch(this.url('GetNativeTokenBalance'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
140
+ return buildResponse(res).then(_data => {
141
+ return JsonDecode(_data, 'GetNativeTokenBalanceResponse');
169
142
  });
170
- }, (error) => {
171
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
143
+ }, error => {
144
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
172
145
  });
173
146
  };
174
- getTokenBalancesDetails = (args, headers, signal) => {
175
- return this.fetch(this.url('GetTokenBalancesDetails'), createHTTPRequest(args, headers, signal)).then((res) => {
176
- return buildResponse(res).then((_data) => {
177
- return {
178
- page: _data.page,
179
- nativeBalances: _data.nativeBalances,
180
- balances: _data.balances,
181
- };
147
+ getTokenBalances = (req, headers, signal) => {
148
+ return this.fetch(this.url('GetTokenBalances'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
149
+ return buildResponse(res).then(_data => {
150
+ return JsonDecode(_data, 'GetTokenBalancesResponse');
182
151
  });
183
- }, (error) => {
184
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
152
+ }, error => {
153
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
185
154
  });
186
155
  };
187
- getTokenBalancesByContract = (args, headers, signal) => {
188
- return this.fetch(this.url('GetTokenBalancesByContract'), createHTTPRequest(args, headers, signal)).then((res) => {
189
- return buildResponse(res).then((_data) => {
190
- return {
191
- page: _data.page,
192
- balances: _data.balances,
193
- };
156
+ getTokenBalancesByContract = (req, headers, signal) => {
157
+ return this.fetch(this.url('GetTokenBalancesByContract'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
158
+ return buildResponse(res).then(_data => {
159
+ return JsonDecode(_data, 'GetTokenBalancesByContractResponse');
194
160
  });
195
- }, (error) => {
196
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
161
+ }, error => {
162
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
197
163
  });
198
164
  };
199
- getBalanceUpdates = (args, headers, signal) => {
200
- return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then((res) => {
201
- return buildResponse(res).then((_data) => {
202
- return {
203
- page: _data.page,
204
- balances: _data.balances,
205
- };
165
+ getTokenBalancesDetails = (req, headers, signal) => {
166
+ return this.fetch(this.url('GetTokenBalancesDetails'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
167
+ return buildResponse(res).then(_data => {
168
+ return JsonDecode(_data, 'GetTokenBalancesDetailsResponse');
206
169
  });
207
- }, (error) => {
208
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
170
+ }, error => {
171
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
209
172
  });
210
173
  };
211
- ping = (headers, signal) => {
212
- return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then((res) => {
213
- return buildResponse(res).then((_data) => {
214
- return {
215
- status: _data.status,
216
- };
174
+ getTokenBalancesSummary = (req, headers, signal) => {
175
+ return this.fetch(this.url('GetTokenBalancesSummary'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
176
+ return buildResponse(res).then(_data => {
177
+ return JsonDecode(_data, 'GetTokenBalancesSummaryResponse');
217
178
  });
218
- }, (error) => {
219
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
179
+ }, error => {
180
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
220
181
  });
221
182
  };
222
- version = (headers, signal) => {
223
- return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then((res) => {
224
- return buildResponse(res).then((_data) => {
225
- return {
226
- version: _data.version,
227
- };
183
+ getTokenPrice = (req, headers, signal) => {
184
+ return this.fetch(this.url('GetTokenPrice'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
185
+ return buildResponse(res).then(_data => {
186
+ return JsonDecode(_data, 'GetTokenPriceResponse');
187
+ });
188
+ }, error => {
189
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
190
+ });
191
+ };
192
+ getTokenPrices = (req, headers, signal) => {
193
+ return this.fetch(this.url('GetTokenPrices'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
194
+ return buildResponse(res).then(_data => {
195
+ return JsonDecode(_data, 'GetTokenPricesResponse');
228
196
  });
229
- }, (error) => {
230
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
197
+ }, error => {
198
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
199
+ });
200
+ };
201
+ getTransactionHistory = (req, headers, signal) => {
202
+ return this.fetch(this.url('GetTransactionHistory'), createHttpRequest(JsonEncode(req), headers, signal)).then(res => {
203
+ return buildResponse(res).then(_data => {
204
+ return JsonDecode(_data, 'GetTransactionHistoryResponse');
205
+ });
206
+ }, error => {
207
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
208
+ });
209
+ };
210
+ ping = (headers, signal) => {
211
+ return this.fetch(this.url('Ping'), createHttpRequest('{}', headers, signal)).then(res => {
212
+ return buildResponse(res).then(_data => {
213
+ return JsonDecode(_data, 'PingResponse');
214
+ });
215
+ }, error => {
216
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
231
217
  });
232
218
  };
233
219
  runtimeStatus = (headers, signal) => {
234
- return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then((res) => {
235
- return buildResponse(res).then((_data) => {
236
- return {
237
- status: _data.status,
238
- };
220
+ return this.fetch(this.url('RuntimeStatus'), createHttpRequest('{}', headers, signal)).then(res => {
221
+ return buildResponse(res).then(_data => {
222
+ return JsonDecode(_data, 'RuntimeStatusResponse');
239
223
  });
240
- }, (error) => {
241
- throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` });
224
+ }, error => {
225
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
226
+ });
227
+ };
228
+ version = (headers, signal) => {
229
+ return this.fetch(this.url('Version'), createHttpRequest('{}', headers, signal)).then(res => {
230
+ return buildResponse(res).then(_data => {
231
+ return JsonDecode(_data, 'VersionResponse');
232
+ });
233
+ }, error => {
234
+ throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` });
242
235
  });
243
236
  };
244
237
  }
245
- exports.IndexerGateway = IndexerGateway;
246
- const createHTTPRequest = (body = {}, headers = {}, signal = null) => {
247
- const reqHeaders = { ...headers, 'Content-Type': 'application/json' };
248
- reqHeaders[exports.WebrpcHeader] = exports.WebrpcHeaderValue;
249
- return {
250
- method: 'POST',
251
- headers: reqHeaders,
252
- body: JSON.stringify(body || {}),
253
- signal,
238
+ const createHttpRequest = (body = '{}', headers = {}, signal = null) => {
239
+ const reqHeaders = {
240
+ ...headers,
241
+ 'Content-Type': 'application/json',
242
+ [WebrpcHeader]: WebrpcHeaderValue
254
243
  };
244
+ return { method: 'POST', headers: reqHeaders, body, signal };
255
245
  };
256
246
  const buildResponse = (res) => {
257
- return res.text().then((text) => {
247
+ return res.text().then(text => {
258
248
  let data;
259
249
  try {
260
250
  data = JSON.parse(text);
261
251
  }
262
252
  catch (error) {
263
- let message = '';
264
- if (error instanceof Error) {
265
- message = error.message;
266
- }
267
253
  throw WebrpcBadResponseError.new({
268
254
  status: res.status,
269
- cause: `JSON.parse(): ${message}: response text: ${text}`,
255
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`
270
256
  });
271
257
  }
272
258
  if (!res.ok) {
@@ -276,294 +262,486 @@ const buildResponse = (res) => {
276
262
  return data;
277
263
  });
278
264
  };
279
- //
280
- // Errors
281
- //
282
- class WebrpcError extends Error {
283
- name;
265
+ export const JsonEncode = (obj) => {
266
+ return JSON.stringify(obj);
267
+ };
268
+ export const JsonDecode = (data, _typ = '') => {
269
+ let parsed = data;
270
+ if (typeof data === 'string') {
271
+ try {
272
+ parsed = JSON.parse(data);
273
+ }
274
+ catch (err) {
275
+ throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${err.message}` });
276
+ }
277
+ }
278
+ return parsed;
279
+ };
280
+ export class WebrpcError extends Error {
284
281
  code;
285
- message;
286
282
  status;
287
- cause;
288
- /** @deprecated Use message instead of msg. Deprecated in webrpc v0.11.0. */
289
- msg;
290
- constructor(name, code, message, status, cause) {
291
- super(message);
292
- this.name = name || 'WebrpcError';
293
- this.code = typeof code === 'number' ? code : 0;
294
- this.message = message || `endpoint error ${this.code}`;
295
- this.msg = this.message;
296
- this.status = typeof status === 'number' ? status : 0;
297
- this.cause = cause;
283
+ constructor(error = {}) {
284
+ super(error.message);
285
+ this.name = error.name || 'WebrpcEndpointError';
286
+ this.code = typeof error.code === 'number' ? error.code : 0;
287
+ this.message = error.message || `endpoint error`;
288
+ this.status = typeof error.status === 'number' ? error.status : 400;
289
+ if (error.cause !== undefined)
290
+ this.cause = error.cause;
298
291
  Object.setPrototypeOf(this, WebrpcError.prototype);
299
292
  }
300
293
  static new(payload) {
301
- return new this(payload.error, payload.code, payload.message || payload.msg, payload.status, payload.cause);
302
- }
303
- }
304
- exports.WebrpcError = WebrpcError;
305
- // Webrpc errors
306
- class WebrpcEndpointError extends WebrpcError {
307
- constructor(name = 'WebrpcEndpoint', code = 0, message = 'endpoint error', status = 0, cause) {
308
- super(name, code, message, status, cause);
294
+ return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause });
295
+ }
296
+ }
297
+ export class WebrpcEndpointError extends WebrpcError {
298
+ constructor(error = {}) {
299
+ super(error);
300
+ this.name = error.name || 'WebrpcEndpoint';
301
+ this.code = typeof error.code === 'number' ? error.code : 0;
302
+ this.message = error.message || `endpoint error`;
303
+ this.status = typeof error.status === 'number' ? error.status : 400;
304
+ if (error.cause !== undefined)
305
+ this.cause = error.cause;
309
306
  Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
310
307
  }
311
308
  }
312
- exports.WebrpcEndpointError = WebrpcEndpointError;
313
- class WebrpcRequestFailedError extends WebrpcError {
314
- constructor(name = 'WebrpcRequestFailed', code = -1, message = 'request failed', status = 0, cause) {
315
- super(name, code, message, status, cause);
309
+ export class WebrpcRequestFailedError extends WebrpcError {
310
+ constructor(error = {}) {
311
+ super(error);
312
+ this.name = error.name || 'WebrpcRequestFailed';
313
+ this.code = typeof error.code === 'number' ? error.code : -1;
314
+ this.message = error.message || `request failed`;
315
+ this.status = typeof error.status === 'number' ? error.status : 400;
316
+ if (error.cause !== undefined)
317
+ this.cause = error.cause;
316
318
  Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
317
319
  }
318
320
  }
319
- exports.WebrpcRequestFailedError = WebrpcRequestFailedError;
320
- class WebrpcBadRouteError extends WebrpcError {
321
- constructor(name = 'WebrpcBadRoute', code = -2, message = 'bad route', status = 0, cause) {
322
- super(name, code, message, status, cause);
321
+ export class WebrpcBadRouteError extends WebrpcError {
322
+ constructor(error = {}) {
323
+ super(error);
324
+ this.name = error.name || 'WebrpcBadRoute';
325
+ this.code = typeof error.code === 'number' ? error.code : -2;
326
+ this.message = error.message || `bad route`;
327
+ this.status = typeof error.status === 'number' ? error.status : 404;
328
+ if (error.cause !== undefined)
329
+ this.cause = error.cause;
323
330
  Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
324
331
  }
325
332
  }
326
- exports.WebrpcBadRouteError = WebrpcBadRouteError;
327
- class WebrpcBadMethodError extends WebrpcError {
328
- constructor(name = 'WebrpcBadMethod', code = -3, message = 'bad method', status = 0, cause) {
329
- super(name, code, message, status, cause);
333
+ export class WebrpcBadMethodError extends WebrpcError {
334
+ constructor(error = {}) {
335
+ super(error);
336
+ this.name = error.name || 'WebrpcBadMethod';
337
+ this.code = typeof error.code === 'number' ? error.code : -3;
338
+ this.message = error.message || `bad method`;
339
+ this.status = typeof error.status === 'number' ? error.status : 405;
340
+ if (error.cause !== undefined)
341
+ this.cause = error.cause;
330
342
  Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
331
343
  }
332
344
  }
333
- exports.WebrpcBadMethodError = WebrpcBadMethodError;
334
- class WebrpcBadRequestError extends WebrpcError {
335
- constructor(name = 'WebrpcBadRequest', code = -4, message = 'bad request', status = 0, cause) {
336
- super(name, code, message, status, cause);
345
+ export class WebrpcBadRequestError extends WebrpcError {
346
+ constructor(error = {}) {
347
+ super(error);
348
+ this.name = error.name || 'WebrpcBadRequest';
349
+ this.code = typeof error.code === 'number' ? error.code : -4;
350
+ this.message = error.message || `bad request`;
351
+ this.status = typeof error.status === 'number' ? error.status : 400;
352
+ if (error.cause !== undefined)
353
+ this.cause = error.cause;
337
354
  Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
338
355
  }
339
356
  }
340
- exports.WebrpcBadRequestError = WebrpcBadRequestError;
341
- class WebrpcBadResponseError extends WebrpcError {
342
- constructor(name = 'WebrpcBadResponse', code = -5, message = 'bad response', status = 0, cause) {
343
- super(name, code, message, status, cause);
357
+ export class WebrpcBadResponseError extends WebrpcError {
358
+ constructor(error = {}) {
359
+ super(error);
360
+ this.name = error.name || 'WebrpcBadResponse';
361
+ this.code = typeof error.code === 'number' ? error.code : -5;
362
+ this.message = error.message || `bad response`;
363
+ this.status = typeof error.status === 'number' ? error.status : 500;
364
+ if (error.cause !== undefined)
365
+ this.cause = error.cause;
344
366
  Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
345
367
  }
346
368
  }
347
- exports.WebrpcBadResponseError = WebrpcBadResponseError;
348
- class WebrpcServerPanicError extends WebrpcError {
349
- constructor(name = 'WebrpcServerPanic', code = -6, message = 'server panic', status = 0, cause) {
350
- super(name, code, message, status, cause);
369
+ export class WebrpcServerPanicError extends WebrpcError {
370
+ constructor(error = {}) {
371
+ super(error);
372
+ this.name = error.name || 'WebrpcServerPanic';
373
+ this.code = typeof error.code === 'number' ? error.code : -6;
374
+ this.message = error.message || `server panic`;
375
+ this.status = typeof error.status === 'number' ? error.status : 500;
376
+ if (error.cause !== undefined)
377
+ this.cause = error.cause;
351
378
  Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
352
379
  }
353
380
  }
354
- exports.WebrpcServerPanicError = WebrpcServerPanicError;
355
- class WebrpcInternalErrorError extends WebrpcError {
356
- constructor(name = 'WebrpcInternalError', code = -7, message = 'internal error', status = 0, cause) {
357
- super(name, code, message, status, cause);
381
+ export class WebrpcInternalErrorError extends WebrpcError {
382
+ constructor(error = {}) {
383
+ super(error);
384
+ this.name = error.name || 'WebrpcInternalError';
385
+ this.code = typeof error.code === 'number' ? error.code : -7;
386
+ this.message = error.message || `internal error`;
387
+ this.status = typeof error.status === 'number' ? error.status : 500;
388
+ if (error.cause !== undefined)
389
+ this.cause = error.cause;
358
390
  Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
359
391
  }
360
392
  }
361
- exports.WebrpcInternalErrorError = WebrpcInternalErrorError;
362
- class WebrpcClientDisconnectedError extends WebrpcError {
363
- constructor(name = 'WebrpcClientDisconnected', code = -8, message = 'client disconnected', status = 0, cause) {
364
- super(name, code, message, status, cause);
365
- Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype);
366
- }
367
- }
368
- exports.WebrpcClientDisconnectedError = WebrpcClientDisconnectedError;
369
- class WebrpcStreamLostError extends WebrpcError {
370
- constructor(name = 'WebrpcStreamLost', code = -9, message = 'stream lost', status = 0, cause) {
371
- super(name, code, message, status, cause);
393
+ export class WebrpcClientAbortedError extends WebrpcError {
394
+ constructor(error = {}) {
395
+ super(error);
396
+ this.name = error.name || 'WebrpcClientAborted';
397
+ this.code = typeof error.code === 'number' ? error.code : -8;
398
+ this.message = error.message || `request aborted by client`;
399
+ this.status = typeof error.status === 'number' ? error.status : 400;
400
+ if (error.cause !== undefined)
401
+ this.cause = error.cause;
402
+ Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype);
403
+ }
404
+ }
405
+ export class WebrpcStreamLostError extends WebrpcError {
406
+ constructor(error = {}) {
407
+ super(error);
408
+ this.name = error.name || 'WebrpcStreamLost';
409
+ this.code = typeof error.code === 'number' ? error.code : -9;
410
+ this.message = error.message || `stream lost`;
411
+ this.status = typeof error.status === 'number' ? error.status : 400;
412
+ if (error.cause !== undefined)
413
+ this.cause = error.cause;
372
414
  Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
373
415
  }
374
416
  }
375
- exports.WebrpcStreamLostError = WebrpcStreamLostError;
376
- class WebrpcStreamFinishedError extends WebrpcError {
377
- constructor(name = 'WebrpcStreamFinished', code = -10, message = 'stream finished', status = 0, cause) {
378
- super(name, code, message, status, cause);
417
+ export class WebrpcStreamFinishedError extends WebrpcError {
418
+ constructor(error = {}) {
419
+ super(error);
420
+ this.name = error.name || 'WebrpcStreamFinished';
421
+ this.code = typeof error.code === 'number' ? error.code : -10;
422
+ this.message = error.message || `stream finished`;
423
+ this.status = typeof error.status === 'number' ? error.status : 200;
424
+ if (error.cause !== undefined)
425
+ this.cause = error.cause;
379
426
  Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
380
427
  }
381
428
  }
382
- exports.WebrpcStreamFinishedError = WebrpcStreamFinishedError;
429
+ //
383
430
  // Schema errors
384
- class UnauthorizedError extends WebrpcError {
385
- constructor(name = 'Unauthorized', code = 1000, message = 'Unauthorized access', status = 0, cause) {
386
- super(name, code, message, status, cause);
387
- Object.setPrototypeOf(this, UnauthorizedError.prototype);
431
+ //
432
+ export class AbortedError extends WebrpcError {
433
+ constructor(error = {}) {
434
+ super(error);
435
+ this.name = error.name || 'Aborted';
436
+ this.code = typeof error.code === 'number' ? error.code : 1005;
437
+ this.message = error.message || `Request aborted`;
438
+ this.status = typeof error.status === 'number' ? error.status : 400;
439
+ if (error.cause !== undefined)
440
+ this.cause = error.cause;
441
+ Object.setPrototypeOf(this, AbortedError.prototype);
388
442
  }
389
443
  }
390
- exports.UnauthorizedError = UnauthorizedError;
391
- class PermissionDeniedError extends WebrpcError {
392
- constructor(name = 'PermissionDenied', code = 1001, message = 'Permission denied', status = 0, cause) {
393
- super(name, code, message, status, cause);
394
- Object.setPrototypeOf(this, PermissionDeniedError.prototype);
444
+ export class AccessKeyMismatchError extends WebrpcError {
445
+ constructor(error = {}) {
446
+ super(error);
447
+ this.name = error.name || 'AccessKeyMismatch';
448
+ this.code = typeof error.code === 'number' ? error.code : 1102;
449
+ this.message = error.message || `Access key mismatch`;
450
+ this.status = typeof error.status === 'number' ? error.status : 409;
451
+ if (error.cause !== undefined)
452
+ this.cause = error.cause;
453
+ Object.setPrototypeOf(this, AccessKeyMismatchError.prototype);
395
454
  }
396
455
  }
397
- exports.PermissionDeniedError = PermissionDeniedError;
398
- class SessionExpiredError extends WebrpcError {
399
- constructor(name = 'SessionExpired', code = 1002, message = 'Session expired', status = 0, cause) {
400
- super(name, code, message, status, cause);
401
- Object.setPrototypeOf(this, SessionExpiredError.prototype);
456
+ export class AccessKeyNotFoundError extends WebrpcError {
457
+ constructor(error = {}) {
458
+ super(error);
459
+ this.name = error.name || 'AccessKeyNotFound';
460
+ this.code = typeof error.code === 'number' ? error.code : 1101;
461
+ this.message = error.message || `Access key not found`;
462
+ this.status = typeof error.status === 'number' ? error.status : 401;
463
+ if (error.cause !== undefined)
464
+ this.cause = error.cause;
465
+ Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype);
402
466
  }
403
467
  }
404
- exports.SessionExpiredError = SessionExpiredError;
405
- class MethodNotFoundError extends WebrpcError {
406
- constructor(name = 'MethodNotFound', code = 1003, message = 'Method not found', status = 0, cause) {
407
- super(name, code, message, status, cause);
408
- Object.setPrototypeOf(this, MethodNotFoundError.prototype);
468
+ export class AtLeastOneKeyError extends WebrpcError {
469
+ constructor(error = {}) {
470
+ super(error);
471
+ this.name = error.name || 'AtLeastOneKey';
472
+ this.code = typeof error.code === 'number' ? error.code : 1302;
473
+ this.message = error.message || `You need at least one Access Key`;
474
+ this.status = typeof error.status === 'number' ? error.status : 403;
475
+ if (error.cause !== undefined)
476
+ this.cause = error.cause;
477
+ Object.setPrototypeOf(this, AtLeastOneKeyError.prototype);
409
478
  }
410
479
  }
411
- exports.MethodNotFoundError = MethodNotFoundError;
412
- class RequestConflictError extends WebrpcError {
413
- constructor(name = 'RequestConflict', code = 1004, message = 'Conflict with target resource', status = 0, cause) {
414
- super(name, code, message, status, cause);
415
- Object.setPrototypeOf(this, RequestConflictError.prototype);
480
+ export class GeoblockedError extends WebrpcError {
481
+ constructor(error = {}) {
482
+ super(error);
483
+ this.name = error.name || 'Geoblocked';
484
+ this.code = typeof error.code === 'number' ? error.code : 1006;
485
+ this.message = error.message || `Geoblocked region`;
486
+ this.status = typeof error.status === 'number' ? error.status : 451;
487
+ if (error.cause !== undefined)
488
+ this.cause = error.cause;
489
+ Object.setPrototypeOf(this, GeoblockedError.prototype);
416
490
  }
417
491
  }
418
- exports.RequestConflictError = RequestConflictError;
419
- class AbortedError extends WebrpcError {
420
- constructor(name = 'Aborted', code = 1005, message = 'Request aborted', status = 0, cause) {
421
- super(name, code, message, status, cause);
422
- Object.setPrototypeOf(this, AbortedError.prototype);
492
+ export class InvalidArgumentError extends WebrpcError {
493
+ constructor(error = {}) {
494
+ super(error);
495
+ this.name = error.name || 'InvalidArgument';
496
+ this.code = typeof error.code === 'number' ? error.code : 2001;
497
+ this.message = error.message || `Invalid argument`;
498
+ this.status = typeof error.status === 'number' ? error.status : 400;
499
+ if (error.cause !== undefined)
500
+ this.cause = error.cause;
501
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype);
423
502
  }
424
503
  }
425
- exports.AbortedError = AbortedError;
426
- class GeoblockedError extends WebrpcError {
427
- constructor(name = 'Geoblocked', code = 1006, message = 'Geoblocked region', status = 0, cause) {
428
- super(name, code, message, status, cause);
429
- Object.setPrototypeOf(this, GeoblockedError.prototype);
504
+ export class InvalidOriginError extends WebrpcError {
505
+ constructor(error = {}) {
506
+ super(error);
507
+ this.name = error.name || 'InvalidOrigin';
508
+ this.code = typeof error.code === 'number' ? error.code : 1103;
509
+ this.message = error.message || `Invalid origin for Access Key`;
510
+ this.status = typeof error.status === 'number' ? error.status : 403;
511
+ if (error.cause !== undefined)
512
+ this.cause = error.cause;
513
+ Object.setPrototypeOf(this, InvalidOriginError.prototype);
430
514
  }
431
515
  }
432
- exports.GeoblockedError = GeoblockedError;
433
- class RateLimitedError extends WebrpcError {
434
- constructor(name = 'RateLimited', code = 1007, message = 'Rate-limited. Please slow down.', status = 0, cause) {
435
- super(name, code, message, status, cause);
436
- Object.setPrototypeOf(this, RateLimitedError.prototype);
516
+ export class InvalidServiceError extends WebrpcError {
517
+ constructor(error = {}) {
518
+ super(error);
519
+ this.name = error.name || 'InvalidService';
520
+ this.code = typeof error.code === 'number' ? error.code : 1104;
521
+ this.message = error.message || `Service not enabled for Access key`;
522
+ this.status = typeof error.status === 'number' ? error.status : 403;
523
+ if (error.cause !== undefined)
524
+ this.cause = error.cause;
525
+ Object.setPrototypeOf(this, InvalidServiceError.prototype);
437
526
  }
438
527
  }
439
- exports.RateLimitedError = RateLimitedError;
440
- class ProjectNotFoundError extends WebrpcError {
441
- constructor(name = 'ProjectNotFound', code = 1100, message = 'Project not found', status = 0, cause) {
442
- super(name, code, message, status, cause);
443
- Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
528
+ export class MaxAccessKeysError extends WebrpcError {
529
+ constructor(error = {}) {
530
+ super(error);
531
+ this.name = error.name || 'MaxAccessKeys';
532
+ this.code = typeof error.code === 'number' ? error.code : 1301;
533
+ this.message = error.message || `Access keys limit reached`;
534
+ this.status = typeof error.status === 'number' ? error.status : 403;
535
+ if (error.cause !== undefined)
536
+ this.cause = error.cause;
537
+ Object.setPrototypeOf(this, MaxAccessKeysError.prototype);
444
538
  }
445
539
  }
446
- exports.ProjectNotFoundError = ProjectNotFoundError;
447
- class AccessKeyNotFoundError extends WebrpcError {
448
- constructor(name = 'AccessKeyNotFound', code = 1101, message = 'Access key not found', status = 0, cause) {
449
- super(name, code, message, status, cause);
450
- Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype);
540
+ export class MetadataCallFailedError extends WebrpcError {
541
+ constructor(error = {}) {
542
+ super(error);
543
+ this.name = error.name || 'MetadataCallFailed';
544
+ this.code = typeof error.code === 'number' ? error.code : 3003;
545
+ this.message = error.message || `Metadata service call failed`;
546
+ this.status = typeof error.status === 'number' ? error.status : 400;
547
+ if (error.cause !== undefined)
548
+ this.cause = error.cause;
549
+ Object.setPrototypeOf(this, MetadataCallFailedError.prototype);
451
550
  }
452
551
  }
453
- exports.AccessKeyNotFoundError = AccessKeyNotFoundError;
454
- class AccessKeyMismatchError extends WebrpcError {
455
- constructor(name = 'AccessKeyMismatch', code = 1102, message = 'Access key mismatch', status = 0, cause) {
456
- super(name, code, message, status, cause);
457
- Object.setPrototypeOf(this, AccessKeyMismatchError.prototype);
552
+ export class MethodNotFoundError extends WebrpcError {
553
+ constructor(error = {}) {
554
+ super(error);
555
+ this.name = error.name || 'MethodNotFound';
556
+ this.code = typeof error.code === 'number' ? error.code : 1003;
557
+ this.message = error.message || `Method not found`;
558
+ this.status = typeof error.status === 'number' ? error.status : 404;
559
+ if (error.cause !== undefined)
560
+ this.cause = error.cause;
561
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype);
458
562
  }
459
563
  }
460
- exports.AccessKeyMismatchError = AccessKeyMismatchError;
461
- class InvalidOriginError extends WebrpcError {
462
- constructor(name = 'InvalidOrigin', code = 1103, message = 'Invalid origin for Access Key', status = 0, cause) {
463
- super(name, code, message, status, cause);
464
- Object.setPrototypeOf(this, InvalidOriginError.prototype);
564
+ export class NoDefaultKeyError extends WebrpcError {
565
+ constructor(error = {}) {
566
+ super(error);
567
+ this.name = error.name || 'NoDefaultKey';
568
+ this.code = typeof error.code === 'number' ? error.code : 1300;
569
+ this.message = error.message || `No default access key found`;
570
+ this.status = typeof error.status === 'number' ? error.status : 403;
571
+ if (error.cause !== undefined)
572
+ this.cause = error.cause;
573
+ Object.setPrototypeOf(this, NoDefaultKeyError.prototype);
465
574
  }
466
575
  }
467
- exports.InvalidOriginError = InvalidOriginError;
468
- class InvalidServiceError extends WebrpcError {
469
- constructor(name = 'InvalidService', code = 1104, message = 'Service not enabled for Access key', status = 0, cause) {
470
- super(name, code, message, status, cause);
471
- Object.setPrototypeOf(this, InvalidServiceError.prototype);
576
+ export class NotFoundError extends WebrpcError {
577
+ constructor(error = {}) {
578
+ super(error);
579
+ this.name = error.name || 'NotFound';
580
+ this.code = typeof error.code === 'number' ? error.code : 3000;
581
+ this.message = error.message || `Resource not found`;
582
+ this.status = typeof error.status === 'number' ? error.status : 400;
583
+ if (error.cause !== undefined)
584
+ this.cause = error.cause;
585
+ Object.setPrototypeOf(this, NotFoundError.prototype);
472
586
  }
473
587
  }
474
- exports.InvalidServiceError = InvalidServiceError;
475
- class UnauthorizedUserError extends WebrpcError {
476
- constructor(name = 'UnauthorizedUser', code = 1105, message = 'Unauthorized user', status = 0, cause) {
477
- super(name, code, message, status, cause);
478
- Object.setPrototypeOf(this, UnauthorizedUserError.prototype);
588
+ export class PermissionDeniedError extends WebrpcError {
589
+ constructor(error = {}) {
590
+ super(error);
591
+ this.name = error.name || 'PermissionDenied';
592
+ this.code = typeof error.code === 'number' ? error.code : 1001;
593
+ this.message = error.message || `Permission denied`;
594
+ this.status = typeof error.status === 'number' ? error.status : 403;
595
+ if (error.cause !== undefined)
596
+ this.cause = error.cause;
597
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype);
479
598
  }
480
599
  }
481
- exports.UnauthorizedUserError = UnauthorizedUserError;
482
- class QuotaExceededError extends WebrpcError {
483
- constructor(name = 'QuotaExceeded', code = 1200, message = 'Quota exceeded', status = 0, cause) {
484
- super(name, code, message, status, cause);
485
- Object.setPrototypeOf(this, QuotaExceededError.prototype);
600
+ export class ProjectNotFoundError extends WebrpcError {
601
+ constructor(error = {}) {
602
+ super(error);
603
+ this.name = error.name || 'ProjectNotFound';
604
+ this.code = typeof error.code === 'number' ? error.code : 1100;
605
+ this.message = error.message || `Project not found`;
606
+ this.status = typeof error.status === 'number' ? error.status : 401;
607
+ if (error.cause !== undefined)
608
+ this.cause = error.cause;
609
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
486
610
  }
487
611
  }
488
- exports.QuotaExceededError = QuotaExceededError;
489
- class RateLimitError extends WebrpcError {
490
- constructor(name = 'RateLimit', code = 1201, message = 'Rate limit exceeded', status = 0, cause) {
491
- super(name, code, message, status, cause);
492
- Object.setPrototypeOf(this, RateLimitError.prototype);
612
+ export class QueryFailedError extends WebrpcError {
613
+ constructor(error = {}) {
614
+ super(error);
615
+ this.name = error.name || 'QueryFailed';
616
+ this.code = typeof error.code === 'number' ? error.code : 2003;
617
+ this.message = error.message || `Query failed`;
618
+ this.status = typeof error.status === 'number' ? error.status : 400;
619
+ if (error.cause !== undefined)
620
+ this.cause = error.cause;
621
+ Object.setPrototypeOf(this, QueryFailedError.prototype);
493
622
  }
494
623
  }
495
- exports.RateLimitError = RateLimitError;
496
- class NoDefaultKeyError extends WebrpcError {
497
- constructor(name = 'NoDefaultKey', code = 1300, message = 'No default access key found', status = 0, cause) {
498
- super(name, code, message, status, cause);
499
- Object.setPrototypeOf(this, NoDefaultKeyError.prototype);
624
+ export class QuotaExceededError extends WebrpcError {
625
+ constructor(error = {}) {
626
+ super(error);
627
+ this.name = error.name || 'QuotaExceeded';
628
+ this.code = typeof error.code === 'number' ? error.code : 1200;
629
+ this.message = error.message || `Quota exceeded`;
630
+ this.status = typeof error.status === 'number' ? error.status : 429;
631
+ if (error.cause !== undefined)
632
+ this.cause = error.cause;
633
+ Object.setPrototypeOf(this, QuotaExceededError.prototype);
500
634
  }
501
635
  }
502
- exports.NoDefaultKeyError = NoDefaultKeyError;
503
- class MaxAccessKeysError extends WebrpcError {
504
- constructor(name = 'MaxAccessKeys', code = 1301, message = 'Access keys limit reached', status = 0, cause) {
505
- super(name, code, message, status, cause);
506
- Object.setPrototypeOf(this, MaxAccessKeysError.prototype);
636
+ export class RateLimitError extends WebrpcError {
637
+ constructor(error = {}) {
638
+ super(error);
639
+ this.name = error.name || 'RateLimit';
640
+ this.code = typeof error.code === 'number' ? error.code : 1201;
641
+ this.message = error.message || `Rate limit exceeded`;
642
+ this.status = typeof error.status === 'number' ? error.status : 429;
643
+ if (error.cause !== undefined)
644
+ this.cause = error.cause;
645
+ Object.setPrototypeOf(this, RateLimitError.prototype);
507
646
  }
508
647
  }
509
- exports.MaxAccessKeysError = MaxAccessKeysError;
510
- class AtLeastOneKeyError extends WebrpcError {
511
- constructor(name = 'AtLeastOneKey', code = 1302, message = 'You need at least one Access Key', status = 0, cause) {
512
- super(name, code, message, status, cause);
513
- Object.setPrototypeOf(this, AtLeastOneKeyError.prototype);
648
+ export class RateLimitedError extends WebrpcError {
649
+ constructor(error = {}) {
650
+ super(error);
651
+ this.name = error.name || 'RateLimited';
652
+ this.code = typeof error.code === 'number' ? error.code : 1007;
653
+ this.message = error.message || `Rate-limited. Please slow down.`;
654
+ this.status = typeof error.status === 'number' ? error.status : 429;
655
+ if (error.cause !== undefined)
656
+ this.cause = error.cause;
657
+ Object.setPrototypeOf(this, RateLimitedError.prototype);
514
658
  }
515
659
  }
516
- exports.AtLeastOneKeyError = AtLeastOneKeyError;
517
- class TimeoutError extends WebrpcError {
518
- constructor(name = 'Timeout', code = 1900, message = 'Request timed out', status = 0, cause) {
519
- super(name, code, message, status, cause);
520
- Object.setPrototypeOf(this, TimeoutError.prototype);
660
+ export class RequestConflictError extends WebrpcError {
661
+ constructor(error = {}) {
662
+ super(error);
663
+ this.name = error.name || 'RequestConflict';
664
+ this.code = typeof error.code === 'number' ? error.code : 1004;
665
+ this.message = error.message || `Conflict with target resource`;
666
+ this.status = typeof error.status === 'number' ? error.status : 409;
667
+ if (error.cause !== undefined)
668
+ this.cause = error.cause;
669
+ Object.setPrototypeOf(this, RequestConflictError.prototype);
521
670
  }
522
671
  }
523
- exports.TimeoutError = TimeoutError;
524
- class InvalidArgumentError extends WebrpcError {
525
- constructor(name = 'InvalidArgument', code = 2001, message = 'Invalid argument', status = 0, cause) {
526
- super(name, code, message, status, cause);
527
- Object.setPrototypeOf(this, InvalidArgumentError.prototype);
672
+ export class ResourceExhaustedError extends WebrpcError {
673
+ constructor(error = {}) {
674
+ super(error);
675
+ this.name = error.name || 'ResourceExhausted';
676
+ this.code = typeof error.code === 'number' ? error.code : 2004;
677
+ this.message = error.message || `Resource exhausted`;
678
+ this.status = typeof error.status === 'number' ? error.status : 400;
679
+ if (error.cause !== undefined)
680
+ this.cause = error.cause;
681
+ Object.setPrototypeOf(this, ResourceExhaustedError.prototype);
528
682
  }
529
683
  }
530
- exports.InvalidArgumentError = InvalidArgumentError;
531
- class UnavailableError extends WebrpcError {
532
- constructor(name = 'Unavailable', code = 2002, message = 'Unavailable resource', status = 0, cause) {
533
- super(name, code, message, status, cause);
534
- Object.setPrototypeOf(this, UnavailableError.prototype);
684
+ export class SessionExpiredError extends WebrpcError {
685
+ constructor(error = {}) {
686
+ super(error);
687
+ this.name = error.name || 'SessionExpired';
688
+ this.code = typeof error.code === 'number' ? error.code : 1002;
689
+ this.message = error.message || `Session expired`;
690
+ this.status = typeof error.status === 'number' ? error.status : 403;
691
+ if (error.cause !== undefined)
692
+ this.cause = error.cause;
693
+ Object.setPrototypeOf(this, SessionExpiredError.prototype);
535
694
  }
536
695
  }
537
- exports.UnavailableError = UnavailableError;
538
- class QueryFailedError extends WebrpcError {
539
- constructor(name = 'QueryFailed', code = 2003, message = 'Query failed', status = 0, cause) {
540
- super(name, code, message, status, cause);
541
- Object.setPrototypeOf(this, QueryFailedError.prototype);
696
+ export class TimeoutError extends WebrpcError {
697
+ constructor(error = {}) {
698
+ super(error);
699
+ this.name = error.name || 'Timeout';
700
+ this.code = typeof error.code === 'number' ? error.code : 1900;
701
+ this.message = error.message || `Request timed out`;
702
+ this.status = typeof error.status === 'number' ? error.status : 408;
703
+ if (error.cause !== undefined)
704
+ this.cause = error.cause;
705
+ Object.setPrototypeOf(this, TimeoutError.prototype);
542
706
  }
543
707
  }
544
- exports.QueryFailedError = QueryFailedError;
545
- class ResourceExhaustedError extends WebrpcError {
546
- constructor(name = 'ResourceExhausted', code = 2004, message = 'Resource exhausted', status = 0, cause) {
547
- super(name, code, message, status, cause);
548
- Object.setPrototypeOf(this, ResourceExhaustedError.prototype);
708
+ export class UnauthorizedError extends WebrpcError {
709
+ constructor(error = {}) {
710
+ super(error);
711
+ this.name = error.name || 'Unauthorized';
712
+ this.code = typeof error.code === 'number' ? error.code : 1000;
713
+ this.message = error.message || `Unauthorized access`;
714
+ this.status = typeof error.status === 'number' ? error.status : 401;
715
+ if (error.cause !== undefined)
716
+ this.cause = error.cause;
717
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
549
718
  }
550
719
  }
551
- exports.ResourceExhaustedError = ResourceExhaustedError;
552
- class NotFoundError extends WebrpcError {
553
- constructor(name = 'NotFound', code = 3000, message = 'Resource not found', status = 0, cause) {
554
- super(name, code, message, status, cause);
555
- Object.setPrototypeOf(this, NotFoundError.prototype);
720
+ export class UnauthorizedUserError extends WebrpcError {
721
+ constructor(error = {}) {
722
+ super(error);
723
+ this.name = error.name || 'UnauthorizedUser';
724
+ this.code = typeof error.code === 'number' ? error.code : 1105;
725
+ this.message = error.message || `Unauthorized user`;
726
+ this.status = typeof error.status === 'number' ? error.status : 403;
727
+ if (error.cause !== undefined)
728
+ this.cause = error.cause;
729
+ Object.setPrototypeOf(this, UnauthorizedUserError.prototype);
556
730
  }
557
731
  }
558
- exports.NotFoundError = NotFoundError;
559
- class MetadataCallFailedError extends WebrpcError {
560
- constructor(name = 'MetadataCallFailed', code = 3003, message = 'Metadata service call failed', status = 0, cause) {
561
- super(name, code, message, status, cause);
562
- Object.setPrototypeOf(this, MetadataCallFailedError.prototype);
732
+ export class UnavailableError extends WebrpcError {
733
+ constructor(error = {}) {
734
+ super(error);
735
+ this.name = error.name || 'Unavailable';
736
+ this.code = typeof error.code === 'number' ? error.code : 2002;
737
+ this.message = error.message || `Unavailable resource`;
738
+ this.status = typeof error.status === 'number' ? error.status : 400;
739
+ if (error.cause !== undefined)
740
+ this.cause = error.cause;
741
+ Object.setPrototypeOf(this, UnavailableError.prototype);
563
742
  }
564
743
  }
565
- exports.MetadataCallFailedError = MetadataCallFailedError;
566
- var errors;
744
+ export var errors;
567
745
  (function (errors) {
568
746
  errors["WebrpcEndpoint"] = "WebrpcEndpoint";
569
747
  errors["WebrpcRequestFailed"] = "WebrpcRequestFailed";
@@ -573,37 +751,77 @@ var errors;
573
751
  errors["WebrpcBadResponse"] = "WebrpcBadResponse";
574
752
  errors["WebrpcServerPanic"] = "WebrpcServerPanic";
575
753
  errors["WebrpcInternalError"] = "WebrpcInternalError";
576
- errors["WebrpcClientDisconnected"] = "WebrpcClientDisconnected";
754
+ errors["WebrpcClientAborted"] = "WebrpcClientAborted";
577
755
  errors["WebrpcStreamLost"] = "WebrpcStreamLost";
578
756
  errors["WebrpcStreamFinished"] = "WebrpcStreamFinished";
579
- errors["Unauthorized"] = "Unauthorized";
580
- errors["PermissionDenied"] = "PermissionDenied";
581
- errors["SessionExpired"] = "SessionExpired";
582
- errors["MethodNotFound"] = "MethodNotFound";
583
- errors["RequestConflict"] = "RequestConflict";
584
757
  errors["Aborted"] = "Aborted";
585
- errors["Geoblocked"] = "Geoblocked";
586
- errors["RateLimited"] = "RateLimited";
587
- errors["ProjectNotFound"] = "ProjectNotFound";
588
- errors["AccessKeyNotFound"] = "AccessKeyNotFound";
589
758
  errors["AccessKeyMismatch"] = "AccessKeyMismatch";
759
+ errors["AccessKeyNotFound"] = "AccessKeyNotFound";
760
+ errors["AtLeastOneKey"] = "AtLeastOneKey";
761
+ errors["Geoblocked"] = "Geoblocked";
762
+ errors["InvalidArgument"] = "InvalidArgument";
590
763
  errors["InvalidOrigin"] = "InvalidOrigin";
591
764
  errors["InvalidService"] = "InvalidService";
592
- errors["UnauthorizedUser"] = "UnauthorizedUser";
765
+ errors["MaxAccessKeys"] = "MaxAccessKeys";
766
+ errors["MetadataCallFailed"] = "MetadataCallFailed";
767
+ errors["MethodNotFound"] = "MethodNotFound";
768
+ errors["NoDefaultKey"] = "NoDefaultKey";
769
+ errors["NotFound"] = "NotFound";
770
+ errors["PermissionDenied"] = "PermissionDenied";
771
+ errors["ProjectNotFound"] = "ProjectNotFound";
772
+ errors["QueryFailed"] = "QueryFailed";
593
773
  errors["QuotaExceeded"] = "QuotaExceeded";
594
774
  errors["RateLimit"] = "RateLimit";
595
- errors["NoDefaultKey"] = "NoDefaultKey";
596
- errors["MaxAccessKeys"] = "MaxAccessKeys";
597
- errors["AtLeastOneKey"] = "AtLeastOneKey";
775
+ errors["RateLimited"] = "RateLimited";
776
+ errors["RequestConflict"] = "RequestConflict";
777
+ errors["ResourceExhausted"] = "ResourceExhausted";
778
+ errors["SessionExpired"] = "SessionExpired";
598
779
  errors["Timeout"] = "Timeout";
599
- errors["InvalidArgument"] = "InvalidArgument";
780
+ errors["Unauthorized"] = "Unauthorized";
781
+ errors["UnauthorizedUser"] = "UnauthorizedUser";
600
782
  errors["Unavailable"] = "Unavailable";
601
- errors["QueryFailed"] = "QueryFailed";
602
- errors["ResourceExhausted"] = "ResourceExhausted";
603
- errors["NotFound"] = "NotFound";
604
- errors["MetadataCallFailed"] = "MetadataCallFailed";
605
- })(errors || (exports.errors = errors = {}));
606
- const webrpcErrorByCode = {
783
+ })(errors || (errors = {}));
784
+ export var WebrpcErrorCodes;
785
+ (function (WebrpcErrorCodes) {
786
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcEndpoint"] = 0] = "WebrpcEndpoint";
787
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcRequestFailed"] = -1] = "WebrpcRequestFailed";
788
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRoute"] = -2] = "WebrpcBadRoute";
789
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadMethod"] = -3] = "WebrpcBadMethod";
790
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRequest"] = -4] = "WebrpcBadRequest";
791
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadResponse"] = -5] = "WebrpcBadResponse";
792
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcServerPanic"] = -6] = "WebrpcServerPanic";
793
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcInternalError"] = -7] = "WebrpcInternalError";
794
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcClientAborted"] = -8] = "WebrpcClientAborted";
795
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamLost"] = -9] = "WebrpcStreamLost";
796
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamFinished"] = -10] = "WebrpcStreamFinished";
797
+ WebrpcErrorCodes[WebrpcErrorCodes["Aborted"] = 1005] = "Aborted";
798
+ WebrpcErrorCodes[WebrpcErrorCodes["AccessKeyMismatch"] = 1102] = "AccessKeyMismatch";
799
+ WebrpcErrorCodes[WebrpcErrorCodes["AccessKeyNotFound"] = 1101] = "AccessKeyNotFound";
800
+ WebrpcErrorCodes[WebrpcErrorCodes["AtLeastOneKey"] = 1302] = "AtLeastOneKey";
801
+ WebrpcErrorCodes[WebrpcErrorCodes["Geoblocked"] = 1006] = "Geoblocked";
802
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidArgument"] = 2001] = "InvalidArgument";
803
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidOrigin"] = 1103] = "InvalidOrigin";
804
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidService"] = 1104] = "InvalidService";
805
+ WebrpcErrorCodes[WebrpcErrorCodes["MaxAccessKeys"] = 1301] = "MaxAccessKeys";
806
+ WebrpcErrorCodes[WebrpcErrorCodes["MetadataCallFailed"] = 3003] = "MetadataCallFailed";
807
+ WebrpcErrorCodes[WebrpcErrorCodes["MethodNotFound"] = 1003] = "MethodNotFound";
808
+ WebrpcErrorCodes[WebrpcErrorCodes["NoDefaultKey"] = 1300] = "NoDefaultKey";
809
+ WebrpcErrorCodes[WebrpcErrorCodes["NotFound"] = 3000] = "NotFound";
810
+ WebrpcErrorCodes[WebrpcErrorCodes["PermissionDenied"] = 1001] = "PermissionDenied";
811
+ WebrpcErrorCodes[WebrpcErrorCodes["ProjectNotFound"] = 1100] = "ProjectNotFound";
812
+ WebrpcErrorCodes[WebrpcErrorCodes["QueryFailed"] = 2003] = "QueryFailed";
813
+ WebrpcErrorCodes[WebrpcErrorCodes["QuotaExceeded"] = 1200] = "QuotaExceeded";
814
+ WebrpcErrorCodes[WebrpcErrorCodes["RateLimit"] = 1201] = "RateLimit";
815
+ WebrpcErrorCodes[WebrpcErrorCodes["RateLimited"] = 1007] = "RateLimited";
816
+ WebrpcErrorCodes[WebrpcErrorCodes["RequestConflict"] = 1004] = "RequestConflict";
817
+ WebrpcErrorCodes[WebrpcErrorCodes["ResourceExhausted"] = 2004] = "ResourceExhausted";
818
+ WebrpcErrorCodes[WebrpcErrorCodes["SessionExpired"] = 1002] = "SessionExpired";
819
+ WebrpcErrorCodes[WebrpcErrorCodes["Timeout"] = 1900] = "Timeout";
820
+ WebrpcErrorCodes[WebrpcErrorCodes["Unauthorized"] = 1000] = "Unauthorized";
821
+ WebrpcErrorCodes[WebrpcErrorCodes["UnauthorizedUser"] = 1105] = "UnauthorizedUser";
822
+ WebrpcErrorCodes[WebrpcErrorCodes["Unavailable"] = 2002] = "Unavailable";
823
+ })(WebrpcErrorCodes || (WebrpcErrorCodes = {}));
824
+ export const webrpcErrorByCode = {
607
825
  [0]: WebrpcEndpointError,
608
826
  [-1]: WebrpcRequestFailedError,
609
827
  [-2]: WebrpcBadRouteError,
@@ -612,33 +830,73 @@ const webrpcErrorByCode = {
612
830
  [-5]: WebrpcBadResponseError,
613
831
  [-6]: WebrpcServerPanicError,
614
832
  [-7]: WebrpcInternalErrorError,
615
- [-8]: WebrpcClientDisconnectedError,
833
+ [-8]: WebrpcClientAbortedError,
616
834
  [-9]: WebrpcStreamLostError,
617
835
  [-10]: WebrpcStreamFinishedError,
618
- [1000]: UnauthorizedError,
619
- [1001]: PermissionDeniedError,
620
- [1002]: SessionExpiredError,
621
- [1003]: MethodNotFoundError,
622
- [1004]: RequestConflictError,
623
836
  [1005]: AbortedError,
624
- [1006]: GeoblockedError,
625
- [1007]: RateLimitedError,
626
- [1100]: ProjectNotFoundError,
627
- [1101]: AccessKeyNotFoundError,
628
837
  [1102]: AccessKeyMismatchError,
838
+ [1101]: AccessKeyNotFoundError,
839
+ [1302]: AtLeastOneKeyError,
840
+ [1006]: GeoblockedError,
841
+ [2001]: InvalidArgumentError,
629
842
  [1103]: InvalidOriginError,
630
843
  [1104]: InvalidServiceError,
631
- [1105]: UnauthorizedUserError,
632
- [1200]: QuotaExceededError,
633
- [1201]: RateLimitError,
634
- [1300]: NoDefaultKeyError,
635
844
  [1301]: MaxAccessKeysError,
636
- [1302]: AtLeastOneKeyError,
637
- [1900]: TimeoutError,
638
- [2001]: InvalidArgumentError,
639
- [2002]: UnavailableError,
845
+ [3003]: MetadataCallFailedError,
846
+ [1003]: MethodNotFoundError,
847
+ [1300]: NoDefaultKeyError,
848
+ [3000]: NotFoundError,
849
+ [1001]: PermissionDeniedError,
850
+ [1100]: ProjectNotFoundError,
640
851
  [2003]: QueryFailedError,
852
+ [1200]: QuotaExceededError,
853
+ [1201]: RateLimitError,
854
+ [1007]: RateLimitedError,
855
+ [1004]: RequestConflictError,
641
856
  [2004]: ResourceExhaustedError,
642
- [3000]: NotFoundError,
643
- [3003]: MetadataCallFailedError,
857
+ [1002]: SessionExpiredError,
858
+ [1900]: TimeoutError,
859
+ [1000]: UnauthorizedError,
860
+ [1105]: UnauthorizedUserError,
861
+ [2002]: UnavailableError
644
862
  };
863
+ //
864
+ // Webrpc
865
+ //
866
+ export const WebrpcHeader = 'Webrpc';
867
+ export const WebrpcHeaderValue = 'webrpc@v0.31.2;gen-typescript@v0.23.1;sequence-indexer@v0.4.0';
868
+ export function VersionFromHeader(headers) {
869
+ const headerValue = headers.get(WebrpcHeader);
870
+ if (!headerValue) {
871
+ return {
872
+ WebrpcGenVersion: '',
873
+ codeGenName: '',
874
+ codeGenVersion: '',
875
+ schemaName: '',
876
+ schemaVersion: ''
877
+ };
878
+ }
879
+ return parseWebrpcGenVersions(headerValue);
880
+ }
881
+ function parseWebrpcGenVersions(header) {
882
+ const versions = header.split(';');
883
+ if (versions.length < 3) {
884
+ return {
885
+ WebrpcGenVersion: '',
886
+ codeGenName: '',
887
+ codeGenVersion: '',
888
+ schemaName: '',
889
+ schemaVersion: ''
890
+ };
891
+ }
892
+ const [_, WebrpcGenVersion] = versions[0].split('@');
893
+ const [codeGenName, codeGenVersion] = versions[1].split('@');
894
+ const [schemaName, schemaVersion] = versions[2].split('@');
895
+ return {
896
+ WebrpcGenVersion: WebrpcGenVersion ?? '',
897
+ codeGenName: codeGenName ?? '',
898
+ codeGenVersion: codeGenVersion ?? '',
899
+ schemaName: schemaName ?? '',
900
+ schemaVersion: schemaVersion ?? ''
901
+ };
902
+ }