polkadot-cli 1.3.0 → 1.4.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.
Files changed (3) hide show
  1. package/README.md +10 -3
  2. package/dist/cli.mjs +29 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -251,11 +251,17 @@ dot query System.Number
251
251
  # Map entry by key
252
252
  dot query System.Account 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
253
253
 
254
- # All map entries (default limit: 100)
255
- dot query System.Account --limit 10
254
+ # Map without key — shows help/usage (use --dump to fetch all entries)
255
+ dot query System.Account
256
+
257
+ # Dump all map entries (requires --dump, default limit: 100)
258
+ dot query System.Account --dump --limit 10
259
+
260
+ # Enum variant as map key (case-insensitive)
261
+ dot query people-preview.ChunksManager.Chunks R2e9 1
256
262
 
257
263
  # Pipe-safe — stdout is clean data, progress messages go to stderr
258
- dot query System.Account --limit 5 | jq '.[0].value.data.free'
264
+ dot query System.Account --dump --limit 5 | jq '.[0].value.data.free'
259
265
  dot query System.Number --output json | jq '.+1'
260
266
 
261
267
  # Query a specific chain using chain prefix
@@ -526,6 +532,7 @@ dot tx.System.remark 0xdead # shows call help (no error)
526
532
  | `--rpc <url>` | Override RPC endpoint(s) for this call (repeat for fallback) |
527
533
  | `--light-client` | Use Smoldot light client |
528
534
  | `--output json` | Raw JSON output (default: pretty) |
535
+ | `--dump` | Dump all entries of a storage map (required for keyless map queries) |
529
536
  | `--limit <n>` | Max entries for map queries (0 = unlimited, default: 100) |
530
537
 
531
538
  ### Pipe-safe output
package/dist/cli.mjs CHANGED
@@ -807,7 +807,11 @@ async function completeDotpath(currentWord, config, knownChains, precedingWords)
807
807
  const partial = endsWithDot ? "" : parts[parts.length - 1] ?? "";
808
808
  const numComplete = completeSegments.length;
809
809
  if (numComplete === 0 && !endsWithDot) {
810
- const candidates = [...CATEGORIES.map(String), ...knownChains, ...NAMED_COMMANDS];
810
+ const candidates = [
811
+ ...CATEGORIES.map((c) => `${c}.`),
812
+ ...knownChains.map((c) => `${c}.`),
813
+ ...NAMED_COMMANDS
814
+ ];
811
815
  return filterPrefix(candidates, partial);
812
816
  }
813
817
  const first = completeSegments[0] ?? "";
@@ -822,7 +826,7 @@ async function completeDotpath(currentWord, config, knownChains, precedingWords)
822
826
  if (!pallets)
823
827
  return [];
824
828
  const filtered = filterPallets(pallets, category);
825
- const candidates = filtered.map((p) => `${first}.${p.name}`);
829
+ const candidates = filtered.map((p) => `${first}.${p.name}.`);
826
830
  return filterPrefix(candidates, currentWord.slice(0, -1));
827
831
  }
828
832
  if (numComplete === 1 && !endsWithDot) {
@@ -831,7 +835,7 @@ async function completeDotpath(currentWord, config, knownChains, precedingWords)
831
835
  if (!pallets)
832
836
  return [];
833
837
  const filtered = filterPallets(pallets, category);
834
- const candidates = filtered.map((p) => `${first}.${p.name}`);
838
+ const candidates = filtered.map((p) => `${first}.${p.name}.`);
835
839
  return filterPrefix(candidates, currentWord);
836
840
  }
837
841
  if (numComplete === 2) {
@@ -852,11 +856,11 @@ async function completeDotpath(currentWord, config, knownChains, precedingWords)
852
856
  if (firstIsChain) {
853
857
  const chainName = first;
854
858
  if (numComplete === 1 && endsWithDot) {
855
- const candidates = CATEGORIES.map((c) => `${first}.${c}`);
859
+ const candidates = CATEGORIES.map((c) => `${first}.${c}.`);
856
860
  return filterPrefix(candidates, currentWord.slice(0, -1));
857
861
  }
858
862
  if (numComplete === 1 && !endsWithDot) {
859
- const candidates = CATEGORIES.map((c) => `${first}.${c}`);
863
+ const candidates = CATEGORIES.map((c) => `${first}.${c}.`);
860
864
  return filterPrefix(candidates, currentWord);
861
865
  }
862
866
  if (numComplete === 2) {
@@ -868,7 +872,7 @@ async function completeDotpath(currentWord, config, knownChains, precedingWords)
868
872
  return [];
869
873
  const filtered = filterPallets(pallets, category);
870
874
  const prefix = `${first}.${completeSegments[1]}`;
871
- const candidates = filtered.map((p) => `${prefix}.${p.name}`);
875
+ const candidates = filtered.map((p) => `${prefix}.${p.name}.`);
872
876
  return filterPrefix(candidates, endsWithDot ? currentWord.slice(0, -1) : currentWord);
873
877
  }
874
878
  if (numComplete === 3) {
@@ -931,7 +935,7 @@ var init_complete = __esm(() => {
931
935
  // src/cli.ts
932
936
  import cac from "cac";
933
937
  // package.json
934
- var version = "1.3.0";
938
+ var version = "1.4.0";
935
939
 
936
940
  // src/commands/account.ts
937
941
  init_accounts_store();
@@ -1700,9 +1704,10 @@ async function chainDefault(name) {
1700
1704
 
1701
1705
  // src/commands/completions.ts
1702
1706
  var ZSH_SCRIPT = `_dot_completions() {
1707
+ emulate -L zsh
1703
1708
  local -a completions
1704
1709
  local current_word="\${words[CURRENT]}"
1705
- local preceding=("\${words[@]:1:CURRENT-2}")
1710
+ local preceding=("\${words[2,CURRENT-1]}")
1706
1711
 
1707
1712
  # Build args: -- <current_word> <preceding_words...>
1708
1713
  local args=("__complete" "--" "\${current_word}")
@@ -2132,13 +2137,14 @@ async function showItemHelp(category, target, opts) {
2132
2137
  if (storageItem.keyTypeId != null) {
2133
2138
  console.log(`${BOLD}Usage:${RESET}`);
2134
2139
  console.log(` dot query.${pallet.name}.${storageItem.name} <key>`);
2135
- console.log(` dot query.${pallet.name}.${storageItem.name} # all entries`);
2140
+ console.log(` dot query.${pallet.name}.${storageItem.name} --dump # all entries`);
2136
2141
  } else {
2137
2142
  console.log(`${BOLD}Usage:${RESET}`);
2138
2143
  console.log(` dot query.${pallet.name}.${storageItem.name}`);
2139
2144
  }
2140
2145
  console.log();
2141
2146
  console.log(`${BOLD}Options:${RESET}`);
2147
+ console.log(` --dump Dump all entries of a map (required for keyless map queries)`);
2142
2148
  console.log(` --limit <n> Max entries for map queries (0 = unlimited, default: 100)`);
2143
2149
  console.log();
2144
2150
  return;
@@ -2576,13 +2582,14 @@ async function showItemHelp2(category, target, opts) {
2576
2582
  if (storageItem.keyTypeId != null) {
2577
2583
  console.log(`${BOLD}Usage:${RESET}`);
2578
2584
  console.log(` dot query.${pallet.name}.${storageItem.name} <key>`);
2579
- console.log(` dot query.${pallet.name}.${storageItem.name} # all entries`);
2585
+ console.log(` dot query.${pallet.name}.${storageItem.name} --dump # all entries`);
2580
2586
  } else {
2581
2587
  console.log(`${BOLD}Usage:${RESET}`);
2582
2588
  console.log(` dot query.${pallet.name}.${storageItem.name}`);
2583
2589
  }
2584
2590
  console.log();
2585
2591
  console.log(`${BOLD}Options:${RESET}`);
2592
+ console.log(` --dump Dump all entries of a map (required for keyless map queries)`);
2586
2593
  console.log(` --limit <n> Max entries for map queries (0 = unlimited, default: 100)`);
2587
2594
  console.log();
2588
2595
  return;
@@ -3256,7 +3263,8 @@ async function parseTypedArg(meta, entry, arg) {
3256
3263
  const matched = variants.find((v) => v.toLowerCase() === arg.toLowerCase());
3257
3264
  if (matched) {
3258
3265
  const variant = entry.value[matched];
3259
- if (variant.type === "void") {
3266
+ const resolved = variant.type === "lookupEntry" ? variant.value : variant;
3267
+ if (resolved.type === "void") {
3260
3268
  return { type: matched };
3261
3269
  }
3262
3270
  }
@@ -3404,6 +3412,12 @@ async function handleQuery(target, keys, opts) {
3404
3412
  const parsedKeys = await parseStorageKeys(meta, palletInfo.name, storageItem, keys);
3405
3413
  const format = opts.output ?? "pretty";
3406
3414
  if (storageItem.type === "map" && parsedKeys.length === 0) {
3415
+ if (!opts.dump) {
3416
+ clientHandle.destroy();
3417
+ await showItemHelp("query", target, { chain: opts.chain, rpc: opts.rpc });
3418
+ console.log(`${DIM}Hint: use --dump to fetch all entries${RESET}`);
3419
+ return;
3420
+ }
3407
3421
  const entries = await storageApi.getEntries();
3408
3422
  const limit = Number(opts.limit);
3409
3423
  const truncated = limit > 0 && entries.length > limit;
@@ -4089,7 +4103,8 @@ async function parseTypedArg2(meta, entry, arg) {
4089
4103
  const matched = variants.find((v) => v.toLowerCase() === arg.toLowerCase());
4090
4104
  if (matched) {
4091
4105
  const variant = entry.value[matched];
4092
- if (variant.type === "void") {
4106
+ const resolved = variant.type === "lookupEntry" ? variant.value : variant;
4107
+ if (resolved.type === "void") {
4093
4108
  return { type: matched };
4094
4109
  }
4095
4110
  }
@@ -4557,7 +4572,7 @@ if (process.argv[2] === "__complete") {
4557
4572
  registerCompletionsCommand(cli);
4558
4573
  cli.command("[dotpath] [...args]").option("--from <name>", "Account to sign with (for tx)").option("--dry-run", "Estimate fees without submitting (for tx)").option("--encode", "Encode call to hex without signing (for tx)").option("--ext <json>", "Custom signed extension values as JSON (for tx)").option("--limit <n>", "Max entries to return for map queries (0 = unlimited)", {
4559
4574
  default: 100
4560
- }).action(async (dotpath, args, opts) => {
4575
+ }).option("--dump", "Dump all entries of a storage map (without specifying a key)").action(async (dotpath, args, opts) => {
4561
4576
  if (!dotpath) {
4562
4577
  printHelp();
4563
4578
  return;
@@ -4582,7 +4597,7 @@ if (process.argv[2] === "__complete") {
4582
4597
  }
4583
4598
  switch (parsed.category) {
4584
4599
  case "query":
4585
- await handleQuery(target, args, { ...handlerOpts, limit: opts.limit });
4600
+ await handleQuery(target, args, { ...handlerOpts, limit: opts.limit, dump: opts.dump });
4586
4601
  break;
4587
4602
  case "tx":
4588
4603
  if (parsed.pallet && /^0x[0-9a-fA-F]+$/.test(parsed.pallet)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkadot-cli",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "CLI tool for querying Polkadot-ecosystem on-chain state",
5
5
  "type": "module",
6
6
  "bin": {