@elgora/cli 7.2.1 → 7.2.2

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.
Files changed (2) hide show
  1. package/dist/cli.js +75 -18
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4890,6 +4890,16 @@ function readArgs(argv) {
4890
4890
  };
4891
4891
  }
4892
4892
 
4893
+ // ../../packages/subgraph-client/src/errors.ts
4894
+ var SubgraphReadError = class extends Error {
4895
+ reason;
4896
+ constructor(reason, message, options) {
4897
+ super(message, options);
4898
+ this.name = "SubgraphReadError";
4899
+ this.reason = reason;
4900
+ }
4901
+ };
4902
+
4893
4903
  // ../../packages/subgraph-client/src/status.ts
4894
4904
  function mapSubgraphStatus(value) {
4895
4905
  switch (value) {
@@ -4981,6 +4991,7 @@ var GUARDIAN_ROSTER_SNAPSHOT_FIELDS = `
4981
4991
  id
4982
4992
  memberCount
4983
4993
  members {
4994
+ position
4984
4995
  account
4985
4996
  name
4986
4997
  encryptionPublicKey
@@ -5141,26 +5152,41 @@ function createElgoraSubgraphClient(options) {
5141
5152
  return options.hubAddress;
5142
5153
  }
5143
5154
  async function execute(query, variables) {
5144
- const response = await fetchImpl(
5145
- endpoint,
5146
- JSON.stringify({ query, variables })
5147
- );
5148
- const raw = await response.text();
5155
+ let response;
5156
+ let raw;
5157
+ try {
5158
+ response = await fetchImpl(
5159
+ endpoint,
5160
+ JSON.stringify({ query, variables })
5161
+ );
5162
+ raw = await response.text();
5163
+ } catch (cause) {
5164
+ throw new SubgraphReadError(
5165
+ "transport_failed",
5166
+ "Subgraph request did not complete",
5167
+ { cause }
5168
+ );
5169
+ }
5149
5170
  if (!response.ok) {
5150
- throw new Error(
5171
+ throw new SubgraphReadError(
5172
+ "request_failed",
5151
5173
  `Subgraph request failed with status ${response.status}: ${raw}`
5152
5174
  );
5153
5175
  }
5154
5176
  const parsed = parseJson(raw);
5155
5177
  const errors = readRecord(parsed).errors;
5156
5178
  if (Array.isArray(errors) && errors.length > 0) {
5157
- throw new Error(
5179
+ throw new SubgraphReadError(
5180
+ "query_errors",
5158
5181
  `Subgraph query returned errors: ${JSON.stringify(errors)}`
5159
5182
  );
5160
5183
  }
5161
5184
  const data = readRecord(parsed).data;
5162
5185
  if (data === void 0 || data === null) {
5163
- throw new Error("Subgraph response did not include a data object");
5186
+ throw new SubgraphReadError(
5187
+ "malformed_response",
5188
+ "Subgraph response did not include a data object"
5189
+ );
5164
5190
  }
5165
5191
  return data;
5166
5192
  }
@@ -5350,7 +5376,8 @@ function mapAnalyticsGuardianRoster(row) {
5350
5376
  const members = asArray(record.members, "members");
5351
5377
  const memberCount = asNumber(record.memberCount, "memberCount");
5352
5378
  if (members.length !== memberCount) {
5353
- throw new Error(
5379
+ throw new SubgraphReadError(
5380
+ "unexpected_shape",
5354
5381
  "Historical Guardian roster members do not match memberCount"
5355
5382
  );
5356
5383
  }
@@ -5457,6 +5484,7 @@ function mapSubmissionFields(row) {
5457
5484
  function mapGuardianRosterMember(row) {
5458
5485
  const record = readRecord(row);
5459
5486
  return {
5487
+ position: asSafeInteger(record.position, "members.position"),
5460
5488
  account: asHex(record.account, "account"),
5461
5489
  name: asString(record.name, "name"),
5462
5490
  encryptionPublicKey: asString(
@@ -5467,10 +5495,19 @@ function mapGuardianRosterMember(row) {
5467
5495
  }
5468
5496
  function mapGuardianRosterSnapshot(row) {
5469
5497
  const record = readRecord(row);
5498
+ const members = asArray(record.members, "members").map(mapGuardianRosterMember).sort((left, right) => left.position - right.position);
5499
+ members.forEach((member, index) => {
5500
+ if (member.position !== index) {
5501
+ throw new SubgraphReadError(
5502
+ "unexpected_shape",
5503
+ `Guardian roster snapshot positions are not 0..n-1 for '${asHex(record.id, "id")}'`
5504
+ );
5505
+ }
5506
+ });
5470
5507
  return {
5471
5508
  rosterHash: asHex(record.id, "id"),
5472
5509
  memberCount: asNumber(record.memberCount, "memberCount"),
5473
- members: asArray(record.members, "members").map(mapGuardianRosterMember),
5510
+ members: members.map(({ position: _position, ...member }) => member),
5474
5511
  recordedAt: asString(record.recordedAt, "recordedAt")
5475
5512
  };
5476
5513
  }
@@ -5549,7 +5586,10 @@ function parseJson(raw) {
5549
5586
  try {
5550
5587
  return JSON.parse(raw);
5551
5588
  } catch {
5552
- throw new Error(`Subgraph returned non-JSON response: ${raw}`);
5589
+ throw new SubgraphReadError(
5590
+ "malformed_response",
5591
+ `Subgraph returned non-JSON response: ${raw}`
5592
+ );
5553
5593
  }
5554
5594
  }
5555
5595
  function readRecord(value) {
@@ -5557,12 +5597,16 @@ function readRecord(value) {
5557
5597
  }
5558
5598
  function asString(value, field) {
5559
5599
  if (typeof value === "string") return value;
5560
- throw new Error(`Expected string for subgraph field '${field}'`);
5600
+ throw new SubgraphReadError(
5601
+ "unexpected_shape",
5602
+ `Expected string for subgraph field '${field}'`
5603
+ );
5561
5604
  }
5562
5605
  function asUnsignedBigInt(value, field) {
5563
5606
  const text = asString(value, field);
5564
5607
  if (/^(?:0|[1-9][0-9]*)$/.test(text)) return BigInt(text);
5565
- throw new Error(
5608
+ throw new SubgraphReadError(
5609
+ "unexpected_shape",
5566
5610
  `Expected non-negative integer string for subgraph field '${field}'`
5567
5611
  );
5568
5612
  }
@@ -5572,29 +5616,42 @@ function asNullableString(value, field) {
5572
5616
  }
5573
5617
  function asNumber(value, field) {
5574
5618
  if (typeof value === "number" && Number.isFinite(value)) return value;
5575
- throw new Error(`Expected number for subgraph field '${field}'`);
5619
+ throw new SubgraphReadError(
5620
+ "unexpected_shape",
5621
+ `Expected number for subgraph field '${field}'`
5622
+ );
5576
5623
  }
5577
5624
  function asSafeInteger(value, field) {
5578
5625
  if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
5579
5626
  return value;
5580
5627
  }
5581
- throw new Error(
5628
+ throw new SubgraphReadError(
5629
+ "unexpected_shape",
5582
5630
  `Expected non-negative integer for subgraph field '${field}'`
5583
5631
  );
5584
5632
  }
5585
5633
  function asBoolean(value, field) {
5586
5634
  if (typeof value === "boolean") return value;
5587
- throw new Error(`Expected boolean for subgraph field '${field}'`);
5635
+ throw new SubgraphReadError(
5636
+ "unexpected_shape",
5637
+ `Expected boolean for subgraph field '${field}'`
5638
+ );
5588
5639
  }
5589
5640
  function asArray(value, field) {
5590
5641
  if (Array.isArray(value)) return value;
5591
- throw new Error(`Expected array for subgraph field '${field}'`);
5642
+ throw new SubgraphReadError(
5643
+ "unexpected_shape",
5644
+ `Expected array for subgraph field '${field}'`
5645
+ );
5592
5646
  }
5593
5647
  function asHex(value, field) {
5594
5648
  if (typeof value === "string" && value.startsWith("0x")) {
5595
5649
  return value.toLowerCase();
5596
5650
  }
5597
- throw new Error(`Expected hex string for subgraph field '${field}'`);
5651
+ throw new SubgraphReadError(
5652
+ "unexpected_shape",
5653
+ `Expected hex string for subgraph field '${field}'`
5654
+ );
5598
5655
  }
5599
5656
  function asNullableHex(value, field) {
5600
5657
  if (value === null || value === void 0) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elgora/cli",
3
- "version": "7.2.1",
3
+ "version": "7.2.2",
4
4
  "description": "Command-line client for Elgora, a decentralized bounty marketplace for science. Lets Posters, Solvers, and Guardians interact with Elgora's public API and on-chain contracts.",
5
5
  "type": "module",
6
6
  "license": "MIT",