@bcts/dcbor-cli 1.0.0-alpha.19 → 1.0.0-alpha.21

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/LICENSE CHANGED
@@ -1,5 +1,6 @@
1
1
  Copyright © 2023-2026 Blockchain Commons, LLC
2
- Copyright © 2025-2026 Leonardo Amoroso Custodio
2
+ Copyright © 2025-2026 Parity Technologies
3
+
3
4
 
4
5
  Redistribution and use in source and binary forms, with or without modification,
5
6
  are permitted provided that the following conditions are met:
package/dist/cli.cjs CHANGED
@@ -1,14 +1,19 @@
1
1
  #!/usr/bin/env node
2
- const require_run = require('./run-B28RHYgN.cjs');
2
+ const require_run = require('./run-C1YH5VEh.cjs');
3
3
  const require_index = require('./index.cjs');
4
4
  let commander = require("commander");
5
5
 
6
6
  //#region src/cli.ts
7
7
  /**
8
+ * Copyright © 2023-2026 Blockchain Commons, LLC
9
+ * Copyright © 2025-2026 Parity Technologies
10
+ *
11
+ *
8
12
  * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)
9
13
  *
10
- * A command line tool for composing, parsing and validating Gordian dCBOR.
11
- * See the main repo README: https://github.com/leonardocustodio/bcts
14
+ * A command line tool for composing, parsing, and validating Gordian dCBOR.
15
+ * See the main repo README: https://github.com/paritytech/bcts
16
+ *
12
17
  */
13
18
  const program = new commander.Command();
14
19
  program.name("dcbor").description("Command line parser/validator for deterministic CBOR (dCBOR)").version(require_index.VERSION);
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.cjs","names":["Command","VERSION","Option","run"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/**\n * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing and validating Gordian dCBOR.\n * See the main repo README: https://github.com/leonardocustodio/bcts\n */\n\nimport { Command, Option } from \"commander\";\nimport { VERSION } from \"./index.js\";\nimport { run, type Command as CmdType } from \"./run.js\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport type { MatchOutputFormat } from \"./cmd/match.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"dcbor\")\n .description(\"Command line parser/validator for deterministic CBOR (dCBOR)\")\n .version(VERSION);\n\n// Default command arguments (when no subcommand is provided)\nprogram\n .argument(\"[input]\", \"Input dCBOR in the format specified by --in\")\n .addOption(\n new Option(\"-i, --in <format>\", \"The input format\")\n .choices([\"diag\", \"hex\", \"bin\"])\n .default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n async (\n input: string | undefined,\n options: {\n in: InputFormat;\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined && options.in !== \"bin\") {\n stdinContent = await readStdin();\n } else if (options.in === \"bin\") {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"default\",\n input,\n in: options.in,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Array subcommand\nprogram\n .command(\"array\")\n .description(\"Compose a dCBOR array from the provided elements\")\n .argument(\"<elements...>\", \"Each element is parsed as a dCBOR item in diagnostic notation\")\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n elements: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"array\",\n elements,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Map subcommand\nprogram\n .command(\"map\")\n .description(\"Compose a dCBOR map from the provided keys and values\")\n .argument(\n \"<pairs...>\",\n \"Each alternating key and value is parsed as a dCBOR item in diagnostic notation\",\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n pairs: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"map\",\n kvPairs: pairs,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Match subcommand\nprogram\n .command(\"match\")\n .description(\"Match dCBOR data against a pattern\")\n .argument(\"<pattern>\", \"The pattern to match against\")\n .argument(\"[input]\", \"dCBOR input (hex, diag, or binary). If not provided, reads from stdin\")\n .addOption(\n new Option(\"-i, --in <format>\", \"Input format\").choices([\"diag\", \"hex\", \"bin\"]).default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"Output format\")\n .choices([\"paths\", \"diag\", \"hex\", \"bin\"])\n .default(\"paths\"),\n )\n .option(\"--no-indent\", \"Disable indentation of path elements\")\n .option(\"--last-only\", \"Show only the last element of each path\")\n .option(\"--annotate\", \"Add annotations to output\")\n .option(\"--captures\", \"Include capture information in output\")\n .action(\n async (\n pattern: string,\n input: string | undefined,\n options: {\n in: InputFormat;\n out: MatchOutputFormat;\n indent: boolean;\n lastOnly?: boolean;\n annotate?: boolean;\n captures?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined) {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"match\",\n pattern,\n input,\n in: options.in,\n out: options.out,\n noIndent: !options.indent,\n lastOnly: options.lastOnly ?? false,\n annotate: options.annotate ?? false,\n captures: options.captures ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n/**\n * Read from stdin\n */\nasync function readStdin(): Promise<string> {\n // Check if stdin is a TTY (interactive terminal)\n if (process.stdin.isTTY) {\n return \"\";\n }\n\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(chunk);\n }\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\n/**\n * Write output to stdout\n */\nfunction writeOutput(output: string, isBinary: boolean): void {\n if (isBinary) {\n // For binary output, decode hex back to bytes\n const bytes = Buffer.from(output, \"hex\");\n process.stdout.write(bytes);\n } else if (output.length > 0) {\n console.log(output);\n }\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,UAAU,IAAIA,mBAAS;AAE7B,QACG,KAAK,QAAQ,CACb,YAAY,+DAA+D,CAC3E,QAAQC,sBAAQ;AAGnB,QACG,SAAS,WAAW,8CAA8C,CAClE,UACC,IAAIC,iBAAO,qBAAqB,mBAAmB,CAChD,QAAQ;CAAC;CAAQ;CAAO;CAAM,CAAC,CAC/B,QAAQ,OAAO,CACnB,CACA,UACC,IAAIA,iBAAO,sBAAsB,oBAAoB,CAClD,QAAQ;CAAC;CAAQ;CAAO;CAAO;CAAO,CAAC,CACvC,QAAQ,MAAM,CAClB,CACA,OAAO,kBAAkB,6DAA6D,CACtF,OACC,OACE,OACA,YAKG;CAEH,IAAI;AACJ,KAAI,UAAU,UAAa,QAAQ,OAAO,MACxC,gBAAe,MAAM,WAAW;UACvB,QAAQ,OAAO,MACxB,gBAAe,MAAM,WAAW;CAWlC,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C5D,KAAI,UAAU;EAEZ,MAAM,QAAQ,OAAO,KAAK,QAAQ,MAAM;AACxC,UAAQ,OAAO,MAAM,MAAM;YAClB,OAAO,SAAS,EACzB,SAAQ,IAAI,OAAO;;AAIvB,QAAQ,OAAO"}
1
+ {"version":3,"file":"cli.cjs","names":["Command","VERSION","Option","run"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing, and validating Gordian dCBOR.\n * See the main repo README: https://github.com/paritytech/bcts\n *\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\nimport { Command, Option } from \"commander\";\nimport { VERSION } from \"./index.js\";\nimport { run, type Command as CmdType } from \"./run.js\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport type { MatchOutputFormat } from \"./cmd/match.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"dcbor\")\n .description(\"Command line parser/validator for deterministic CBOR (dCBOR)\")\n .version(VERSION);\n\n// Default command arguments (when no subcommand is provided)\nprogram\n .argument(\"[input]\", \"Input dCBOR in the format specified by --in\")\n .addOption(\n new Option(\"-i, --in <format>\", \"The input format\")\n .choices([\"diag\", \"hex\", \"bin\"])\n .default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n async (\n input: string | undefined,\n options: {\n in: InputFormat;\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined && options.in !== \"bin\") {\n stdinContent = await readStdin();\n } else if (options.in === \"bin\") {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"default\",\n input,\n in: options.in,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Array subcommand\nprogram\n .command(\"array\")\n .description(\"Compose a dCBOR array from the provided elements\")\n .argument(\"<elements...>\", \"Each element is parsed as a dCBOR item in diagnostic notation\")\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n elements: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"array\",\n elements,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Map subcommand\nprogram\n .command(\"map\")\n .description(\"Compose a dCBOR map from the provided keys and values\")\n .argument(\n \"<pairs...>\",\n \"Each alternating key and value is parsed as a dCBOR item in diagnostic notation\",\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n pairs: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"map\",\n kvPairs: pairs,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Match subcommand\nprogram\n .command(\"match\")\n .description(\"Match dCBOR data against a pattern\")\n .argument(\"<pattern>\", \"The pattern to match against\")\n .argument(\"[input]\", \"dCBOR input (hex, diag, or binary). If not provided, reads from stdin\")\n .addOption(\n new Option(\"-i, --in <format>\", \"Input format\").choices([\"diag\", \"hex\", \"bin\"]).default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"Output format\")\n .choices([\"paths\", \"diag\", \"hex\", \"bin\"])\n .default(\"paths\"),\n )\n .option(\"--no-indent\", \"Disable indentation of path elements\")\n .option(\"--last-only\", \"Show only the last element of each path\")\n .option(\"--annotate\", \"Add annotations to output\")\n .option(\"--captures\", \"Include capture information in output\")\n .action(\n async (\n pattern: string,\n input: string | undefined,\n options: {\n in: InputFormat;\n out: MatchOutputFormat;\n indent: boolean;\n lastOnly?: boolean;\n annotate?: boolean;\n captures?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined) {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"match\",\n pattern,\n input,\n in: options.in,\n out: options.out,\n noIndent: !options.indent,\n lastOnly: options.lastOnly ?? false,\n annotate: options.annotate ?? false,\n captures: options.captures ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n/**\n * Read from stdin\n */\nasync function readStdin(): Promise<string> {\n // Check if stdin is a TTY (interactive terminal)\n if (process.stdin.isTTY) {\n return \"\";\n }\n\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(chunk);\n }\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\n/**\n * Write output to stdout\n */\nfunction writeOutput(output: string, isBinary: boolean): void {\n if (isBinary) {\n // For binary output, decode hex back to bytes\n const bytes = Buffer.from(output, \"hex\");\n process.stdout.write(bytes);\n } else if (output.length > 0) {\n console.log(output);\n }\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,UAAU,IAAIA,m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UAAU,CAAC,QAAQ;GACnB,UAAU,QAAQ,YAAY;GAC9B,UAAU,QAAQ,YAAY;GAC9B,UAAU,QAAQ,YAAY;GAC/B;EAE6B;EAAc,CAAC;AAE7C,KAAI,CAAC,OAAO,IAAI;AACd,UAAQ,MAAM,UAAU,OAAO,MAAM,UAAU;AAC/C,UAAQ,KAAK,EAAE;;AAGjB,aAAY,OAAO,MAAM,QAAQ,OAAO,MAAM,SAAS;EAE1D;;;;AAKH,eAAe,YAA6B;AAE1C,KAAI,QAAQ,MAAM,MAChB,QAAO;CAGT,MAAM,SAAmB,EAAE;AAC3B,YAAW,MAAM,SAAS,QAAQ,MAChC,QAAO,KAAK,MAAM;AAEpB,QAAO,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO;;;;;AAM/C,SAAS,YAAY,QAAgB,UAAyB;AAC5D,KAAI,UAAU;EAEZ,MAAM,QAAQ,OAAO,KAAK,QAAQ,MAAM;AACxC,UAAQ,OAAO,MAAM,MAAM;YAClB,OAAO,SAAS,EACzB,SAAQ,IAAI,OAAO;;AAIvB,QAAQ,OAAO"}
package/dist/cli.mjs CHANGED
@@ -1,14 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import { t as run } from "./run-GBL_cAOh.mjs";
2
+ import { t as run } from "./run-DJdWarnw.mjs";
3
3
  import { VERSION } from "./index.mjs";
4
4
  import { Command, Option } from "commander";
5
5
 
6
6
  //#region src/cli.ts
7
7
  /**
8
+ * Copyright © 2023-2026 Blockchain Commons, LLC
9
+ * Copyright © 2025-2026 Parity Technologies
10
+ *
11
+ *
8
12
  * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)
9
13
  *
10
- * A command line tool for composing, parsing and validating Gordian dCBOR.
11
- * See the main repo README: https://github.com/leonardocustodio/bcts
14
+ * A command line tool for composing, parsing, and validating Gordian dCBOR.
15
+ * See the main repo README: https://github.com/paritytech/bcts
16
+ *
12
17
  */
13
18
  const program = new Command();
14
19
  program.name("dcbor").description("Command line parser/validator for deterministic CBOR (dCBOR)").version(VERSION);
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/**\n * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing and validating Gordian dCBOR.\n * See the main repo README: https://github.com/leonardocustodio/bcts\n */\n\nimport { Command, Option } from \"commander\";\nimport { VERSION } from \"./index.js\";\nimport { run, type Command as CmdType } from \"./run.js\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport type { MatchOutputFormat } from \"./cmd/match.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"dcbor\")\n .description(\"Command line parser/validator for deterministic CBOR (dCBOR)\")\n .version(VERSION);\n\n// Default command arguments (when no subcommand is provided)\nprogram\n .argument(\"[input]\", \"Input dCBOR in the format specified by --in\")\n .addOption(\n new Option(\"-i, --in <format>\", \"The input format\")\n .choices([\"diag\", \"hex\", \"bin\"])\n .default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n async (\n input: string | undefined,\n options: {\n in: InputFormat;\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined && options.in !== \"bin\") {\n stdinContent = await readStdin();\n } else if (options.in === \"bin\") {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"default\",\n input,\n in: options.in,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Array subcommand\nprogram\n .command(\"array\")\n .description(\"Compose a dCBOR array from the provided elements\")\n .argument(\"<elements...>\", \"Each element is parsed as a dCBOR item in diagnostic notation\")\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n elements: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"array\",\n elements,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Map subcommand\nprogram\n .command(\"map\")\n .description(\"Compose a dCBOR map from the provided keys and values\")\n .argument(\n \"<pairs...>\",\n \"Each alternating key and value is parsed as a dCBOR item in diagnostic notation\",\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n pairs: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"map\",\n kvPairs: pairs,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Match subcommand\nprogram\n .command(\"match\")\n .description(\"Match dCBOR data against a pattern\")\n .argument(\"<pattern>\", \"The pattern to match against\")\n .argument(\"[input]\", \"dCBOR input (hex, diag, or binary). If not provided, reads from stdin\")\n .addOption(\n new Option(\"-i, --in <format>\", \"Input format\").choices([\"diag\", \"hex\", \"bin\"]).default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"Output format\")\n .choices([\"paths\", \"diag\", \"hex\", \"bin\"])\n .default(\"paths\"),\n )\n .option(\"--no-indent\", \"Disable indentation of path elements\")\n .option(\"--last-only\", \"Show only the last element of each path\")\n .option(\"--annotate\", \"Add annotations to output\")\n .option(\"--captures\", \"Include capture information in output\")\n .action(\n async (\n pattern: string,\n input: string | undefined,\n options: {\n in: InputFormat;\n out: MatchOutputFormat;\n indent: boolean;\n lastOnly?: boolean;\n annotate?: boolean;\n captures?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined) {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"match\",\n pattern,\n input,\n in: options.in,\n out: options.out,\n noIndent: !options.indent,\n lastOnly: options.lastOnly ?? false,\n annotate: options.annotate ?? false,\n captures: options.captures ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n/**\n * Read from stdin\n */\nasync function readStdin(): Promise<string> {\n // Check if stdin is a TTY (interactive terminal)\n if (process.stdin.isTTY) {\n return \"\";\n }\n\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(chunk);\n }\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\n/**\n * Write output to stdout\n */\nfunction writeOutput(output: string, isBinary: boolean): void {\n if (isBinary) {\n // For binary output, decode hex back to bytes\n const bytes = Buffer.from(output, \"hex\");\n process.stdout.write(bytes);\n } else if (output.length > 0) {\n console.log(output);\n }\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,UAAU,IAAI,SAAS;AAE7B,QACG,KAAK,QAAQ,CACb,YAAY,+DAA+D,CAC3E,QAAQ,QAAQ;AAGnB,QACG,SAAS,WAAW,8CAA8C,CAClE,UACC,IAAI,OAAO,qBAAqB,mBAAmB,CAChD,QAAQ;CAAC;CAAQ;CAAO;CAAM,CAAC,CA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Q,KAAK,EAAE;;AAGjB,aAAY,OAAO,MAAM,QAAQ,OAAO,MAAM,SAAS;EAE1D;;;;AAKH,eAAe,YAA6B;AAE1C,KAAI,QAAQ,MAAM,MAChB,QAAO;CAGT,MAAM,SAAmB,EAAE;AAC3B,YAAW,MAAM,SAAS,QAAQ,MAChC,QAAO,KAAK,MAAM;AAEpB,QAAO,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO;;;;;AAM/C,SAAS,YAAY,QAAgB,UAAyB;AAC5D,KAAI,UAAU;EAEZ,MAAM,QAAQ,OAAO,KAAK,QAAQ,MAAM;AACxC,UAAQ,OAAO,MAAM,MAAM;YAClB,OAAO,SAAS,EACzB,SAAQ,IAAI,OAAO;;AAIvB,QAAQ,OAAO"}
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing, and validating Gordian dCBOR.\n * See the main repo README: https://github.com/paritytech/bcts\n *\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\nimport { Command, Option } from \"commander\";\nimport { VERSION } from \"./index.js\";\nimport { run, type Command as CmdType } from \"./run.js\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport type { MatchOutputFormat } from \"./cmd/match.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"dcbor\")\n .description(\"Command line parser/validator for deterministic CBOR (dCBOR)\")\n .version(VERSION);\n\n// Default command arguments (when no subcommand is provided)\nprogram\n .argument(\"[input]\", \"Input dCBOR in the format specified by --in\")\n .addOption(\n new Option(\"-i, --in <format>\", \"The input format\")\n .choices([\"diag\", \"hex\", \"bin\"])\n .default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n async (\n input: string | undefined,\n options: {\n in: InputFormat;\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined && options.in !== \"bin\") {\n stdinContent = await readStdin();\n } else if (options.in === \"bin\") {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"default\",\n input,\n in: options.in,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Array subcommand\nprogram\n .command(\"array\")\n .description(\"Compose a dCBOR array from the provided elements\")\n .argument(\"<elements...>\", \"Each element is parsed as a dCBOR item in diagnostic notation\")\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n elements: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"array\",\n elements,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Map subcommand\nprogram\n .command(\"map\")\n .description(\"Compose a dCBOR map from the provided keys and values\")\n .argument(\n \"<pairs...>\",\n \"Each alternating key and value is parsed as a dCBOR item in diagnostic notation\",\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"The output format\")\n .choices([\"diag\", \"hex\", \"bin\", \"none\"])\n .default(\"hex\"),\n )\n .option(\"-a, --annotate\", \"Output diagnostic notation or hexadecimal with annotations\")\n .action(\n (\n pairs: string[],\n options: {\n out: OutputFormat;\n annotate?: boolean;\n },\n ) => {\n const command: CmdType = {\n type: \"map\",\n kvPairs: pairs,\n out: options.out,\n annotate: options.annotate ?? false,\n };\n\n const result = run({ command });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n// Match subcommand\nprogram\n .command(\"match\")\n .description(\"Match dCBOR data against a pattern\")\n .argument(\"<pattern>\", \"The pattern to match against\")\n .argument(\"[input]\", \"dCBOR input (hex, diag, or binary). If not provided, reads from stdin\")\n .addOption(\n new Option(\"-i, --in <format>\", \"Input format\").choices([\"diag\", \"hex\", \"bin\"]).default(\"diag\"),\n )\n .addOption(\n new Option(\"-o, --out <format>\", \"Output format\")\n .choices([\"paths\", \"diag\", \"hex\", \"bin\"])\n .default(\"paths\"),\n )\n .option(\"--no-indent\", \"Disable indentation of path elements\")\n .option(\"--last-only\", \"Show only the last element of each path\")\n .option(\"--annotate\", \"Add annotations to output\")\n .option(\"--captures\", \"Include capture information in output\")\n .action(\n async (\n pattern: string,\n input: string | undefined,\n options: {\n in: InputFormat;\n out: MatchOutputFormat;\n indent: boolean;\n lastOnly?: boolean;\n annotate?: boolean;\n captures?: boolean;\n },\n ) => {\n // Read stdin if needed\n let stdinContent: string | undefined;\n if (input === undefined) {\n stdinContent = await readStdin();\n }\n\n const command: CmdType = {\n type: \"match\",\n pattern,\n input,\n in: options.in,\n out: options.out,\n noIndent: !options.indent,\n lastOnly: options.lastOnly ?? false,\n annotate: options.annotate ?? false,\n captures: options.captures ?? false,\n };\n\n const result = run({ command, stdinContent });\n\n if (!result.ok) {\n console.error(`Error: ${result.error.message}`);\n process.exit(1);\n }\n\n writeOutput(result.value.output, result.value.isBinary);\n },\n );\n\n/**\n * Read from stdin\n */\nasync function readStdin(): Promise<string> {\n // Check if stdin is a TTY (interactive terminal)\n if (process.stdin.isTTY) {\n return \"\";\n }\n\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(chunk);\n }\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\n/**\n * Write output to stdout\n */\nfunction writeOutput(output: string, isBinary: boolean): void {\n if (isBinary) {\n // For binary output, decode hex back to bytes\n const bytes = Buffer.from(output, \"hex\");\n process.stdout.write(bytes);\n } else if (output.length > 0) {\n console.log(output);\n }\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,UAAU,IAAI,SAAS;AAE7B,QACG,KAAK,QAAQ,CACb,YAAY,+DAA+D,CAC3E,QAAQ,QAAQ;AAGnB,QACG,SAAS,WAAW,8CAA8C,CAClE,UACC,IAAI,OAAO,qBAAqB,mBAAmB,CAChD,QAAQ;CAAC;CAAQ;CAAO;CAAM,CAAC,CAC/B,QAAQ,OAAO,CACnB,CACA,UACC,IAAI,OAAO,sBAAsB,oBAAoB,CAClD,QAAQ;CAAC;CAAQ;CAAO;CAAO;CAAO,CAAC,CACvC,QAAQ,MAAM,CAClB,CACA,OAAO,kBAAkB,6DAA6D,CACtF,OACC,OACE,OACA,YAKG;CAEH,IAAI;AACJ,KAAI,UAAU,UAAa,QAAQ,OAAO,MACxC,gBAAe,MAAM,WAAW;UACvB,QAAQ,OAAO,MACxB,gBAAe,MAAM,WAAW;CAWlC,MAAM,SAAS,IAAI;EAAE,SARI;GACvB,MAAM;GACN;GACA,IAAI,QAAQ;GACZ,KAAK,QAAQ;GACb,UAAU,QAAQ,YAAY;GAC/B;EAE6B;EAAc,CAAC;AAE7C,KAAI,CAAC,OAAO,IAAI;AACd,UAAQ,MAAM,UAAU,OAAO,MAAM,UAAU;AAC/C,UAAQ,KAAK,EAAE;;AAGjB,aAAY,OAAO,MAAM,QAAQ,OAAO,MAAM,SAAS;EAE1D;AAGH,QACG,QAAQ,QAAQ,CAChB,YAAY,mDAAmD,CAC/D,SAAS,iBAAiB,gEAAgE,CAC1F,UACC,IAAI,OAAO,sBAAsB,oBAAoB,CAClD,QAAQ;CAAC;CAA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AuC,CAC7D,OAAO,eAAe,0CAA0C,CAChE,OAAO,cAAc,4BAA4B,CACjD,OAAO,cAAc,wCAAwC,CAC7D,OACC,OACE,SACA,OACA,YAQG;CAEH,IAAI;AACJ,KAAI,UAAU,OACZ,gBAAe,MAAM,WAAW;CAelC,MAAM,SAAS,IAAI;EAAE,SAZI;GACvB,MAAM;GACN;GACA;GACA,IAAI,QAAQ;GACZ,KAAK,QAAQ;GACb,UAAU,CAAC,QAAQ;GACnB,UAAU,QAAQ,YAAY;GAC9B,UAAU,QAAQ,YAAY;GAC9B,UAAU,QAAQ,YAAY;GAC/B;EAE6B;EAAc,CAAC;AAE7C,KAAI,CAAC,OAAO,IAAI;AACd,UAAQ,MAAM,UAAU,OAAO,MAAM,UAAU;AAC/C,UAAQ,KAAK,EAAE;;AAGjB,aAAY,OAAO,MAAM,QAAQ,OAAO,MAAM,SAAS;EAE1D;;;;AAKH,eAAe,YAA6B;AAE1C,KAAI,QAAQ,MAAM,MAChB,QAAO;CAGT,MAAM,SAAmB,EAAE;AAC3B,YAAW,MAAM,SAAS,QAAQ,MAChC,QAAO,KAAK,MAAM;AAEpB,QAAO,OAAO,OAAO,OAAO,CAAC,SAAS,OAAO;;;;;AAM/C,SAAS,YAAY,QAAgB,UAAyB;AAC5D,KAAI,UAAU;EAEZ,MAAM,QAAQ,OAAO,KAAK,QAAQ,MAAM;AACxC,UAAQ,OAAO,MAAM,MAAM;YAClB,OAAO,SAAS,EACzB,SAAQ,IAAI,OAAO;;AAIvB,QAAQ,OAAO"}
package/dist/index.cjs CHANGED
@@ -1,8 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_run = require('./run-B28RHYgN.cjs');
2
+ const require_run = require('./run-C1YH5VEh.cjs');
3
3
 
4
4
  //#region src/index.ts
5
5
  /**
6
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7
+ * Copyright © 2025-2026 Parity Technologies
8
+ *
9
+ *
6
10
  * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)
7
11
  *
8
12
  * A command line tool for composing, parsing and validating Gordian dCBOR.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing and validating Gordian dCBOR.\n *\n * @packageDocumentation\n */\n\nexport const VERSION = \"1.0.0-alpha.13\";\n\n// Export format utilities\nexport { formatOutput, readData, readString } from \"./format.js\";\nexport type { InputFormat, OutputFormat } from \"./format.js\";\n\n// Export command modules\nexport {\n // Exec interface\n type Exec,\n // Array command\n type ArrayCommandArgs,\n execArray,\n createArrayCommand,\n // Map command\n type MapCommandArgs,\n execMap,\n createMapCommand,\n // Default command\n type DefaultCommandArgs,\n execDefault,\n execDefaultWithReader,\n createDefaultCommand,\n // Match command\n type MatchOutputFormat,\n type MatchCommandArgs,\n execMatch,\n createMatchCommand,\n} from \"./cmd/index.js\";\n\n// Export the run function for programmatic use\nexport { run } from \"./run.js\";\nexport type { RunOptions, RunResult, Command } from \"./run.js\";\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,UAAU"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing and validating Gordian dCBOR.\n *\n * @packageDocumentation\n */\n\nexport const VERSION = \"1.0.0-alpha.13\";\n\n// Export format utilities\nexport { formatOutput, readData, readString } from \"./format.js\";\nexport type { InputFormat, OutputFormat } from \"./format.js\";\n\n// Export command modules\nexport {\n // Exec interface\n type Exec,\n // Array command\n type ArrayCommandArgs,\n execArray,\n createArrayCommand,\n // Map command\n type MapCommandArgs,\n execMap,\n createMapCommand,\n // Default command\n type DefaultCommandArgs,\n execDefault,\n execDefaultWithReader,\n createDefaultCommand,\n // Match command\n type MatchOutputFormat,\n type MatchCommandArgs,\n execMatch,\n createMatchCommand,\n} from \"./cmd/index.js\";\n\n// Export the run function for programmatic use\nexport { run } from \"./run.js\";\nexport type { RunOptions, RunResult, Command } from \"./run.js\";\n"],"mappings":";;;;;;;;;;;;;;;AAYA,MAAa,UAAU"}
package/dist/index.d.cts CHANGED
@@ -189,6 +189,10 @@ declare function run(options: RunOptions): {
189
189
  //#endregion
190
190
  //#region src/index.d.ts
191
191
  /**
192
+ * Copyright © 2023-2026 Blockchain Commons, LLC
193
+ * Copyright © 2025-2026 Parity Technologies
194
+ *
195
+ *
192
196
  * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)
193
197
  *
194
198
  * A command line tool for composing, parsing and validating Gordian dCBOR.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/cmd/index.ts","../src/run.ts","../src/index.ts"],"mappings":";;;;;AAyBA;KALY,WAAA;;;;KAKA,YAAA;;;;;iBAMI,YAAA,CACd,IAAA,EAAM,IAAA,EACN,SAAA,EAAW,YAAA,EACX,QAAA,YACC,MAAA;;;;iBAqCa,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,UAAA;;;;iBAO5B,UAAA,CAAW,IAAA,EAAM,UAAA;;;;AAtDjC;;UCZiB,gBAAA;EDYO;ECVtB,QAAA;EDgBc;ECdd,GAAA,EAAK,YAAA;;EAEL,QAAA;AAAA;;;;iBAMc,SAAA,CAAU,IAAA,EAAM,gBAAA,GAAmB,MAAA;;;;iBAWnC,kBAAA,CAAmB,IAAA,EAAM,gBAAA,GAAmB,IAAA;;;;ADX5D;;UEXiB,kBAAA;EFWO;EETtB,KAAA;EFec;EEbd,EAAA,EAAI,WAAA;;EAEJ,GAAA,EAAK,YAAA;EFaM;EEXX,QAAA;AAAA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A;EACL,QAAA;AAAA;AAAA,UAGW,UAAA;EACf,OAAA,EAAS,OAAA;EACT,YAAA;AAAA;AAAA,UAGe,SAAA;EACf,MAAA;EACA,QAAA;AAAA;;;AL5BF;;iBKmCgB,GAAA,CACd,OAAA,EAAS,UAAA;EACN,EAAA;EAAU,KAAA,EAAO,SAAA;AAAA;EAAgB,EAAA;EAAW,KAAA,EAAO,KAAA;AAAA;;;;;;AN9BxD;;;;cOZa,OAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/cmd/index.ts","../src/run.ts","../src/index.ts"],"mappings":";;;;;;KAwBY,WAAA;;;;KAKA,YAAA;;;;;iBAMI,YAAA,CACd,IAAA,EAAM,IAAA,EACN,SAAA,EAAW,YAAA,EACX,QAAA,YACC,MAAA;;;;iBAqCa,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,UAAA;;;AAA5C;iBAOgB,UAAA,CAAW,IAAA,EAAM,UAAA;;;;;AAhDjC;UClBiB,gBAAA;;EAEf,QAAA;EDkBW;EChBX,GAAA,EAAK,YAAA;EDkBE;EChBP,QAAA;AAAA;;;;iBAMc,SAAA,CAAU,IAAA,EAAM,gBAAA,GAAmB,MAAA;;;;iBAWnC,kBAAA,CAAmB,IAAA,EAAM,gBAAA,GAAmB,IAAA;;;;;ADL5D;UEjBiB,kBAAA;;EAEf,KAAA;EFiBW;EEfX,EAAA,EAAI,WAAA;EFiBG;EEfP,GAAA,EAAK,YAAA;EFYC;EEVN,QAAA;AAAA;;;;iBAMc,qBAAA,CACd,IAAA,EAAM,kBAAA,EACN,UAAA,gBACA,QAAA,QAAgB,UAAA,GACf,MAAA;;AFwCH;;iBEegB,WAAA,CAAY,IAAA,EAAM,kBAAA,EAAoB,YAAA,YAAwB,MAAA;;;;iBAgB9D,oBAAA,CAAqB,IAAA,EAAM,kBAAA,EAAoB,YAAA,YAAwB,IAAA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,KAAA;AAAA;;;;;;AN9BxD;;;;;AAKA;;;cOjBa,OAAA"}
package/dist/index.d.mts CHANGED
@@ -189,6 +189,10 @@ declare function run(options: RunOptions): {
189
189
  //#endregion
190
190
  //#region src/index.d.ts
191
191
  /**
192
+ * Copyright © 2023-2026 Blockchain Commons, LLC
193
+ * Copyright © 2025-2026 Parity Technologies
194
+ *
195
+ *
192
196
  * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)
193
197
  *
194
198
  * A command line tool for composing, parsing and validating Gordian dCBOR.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/cmd/index.ts","../src/run.ts","../src/index.ts"],"mappings":";;;;;AAyBA;KALY,WAAA;;;;KAKA,YAAA;;;;;iBAMI,YAAA,CACd,IAAA,EAAM,IAAA,EACN,SAAA,EAAW,YAAA,EACX,QAAA,YACC,MAAA;;;;iBAqCa,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,UAAA;;;;iBAO5B,UAAA,CAAW,IAAA,EAAM,UAAA;;;;AAtDjC;;UCZiB,gBAAA;EDYO;ECVtB,QAAA;EDgBc;ECdd,GAAA,EAAK,YAAA;;EAEL,QAAA;AAAA;;;;iBAMc,SAAA,CAAU,IAAA,EAAM,gBAAA,GAAmB,MAAA;;;;iBAWnC,kBAAA,CAAmB,IAAA,EAAM,gBAAA,GAAmB,IAAA;;;;ADX5D;;UEXiB,kBAAA;EFWO;EETtB,KAAA;EFec;EEbd,EAAA,EAAI,WAAA;;EAEJ,GAAA,EAAK,YAAA;EFaM;EEXX,QAAA;AAAA;;;;iBAMc,qBAAA,CACd,IAAA,EAAM,kBAAA,EACN,UAAA,gBACA,QAAA,QAAgB,UAAA,GACf,MAAA;;;;iBAuDa,WAAA,CAAY,IAAA,EAAM,kBAAA,EAAoB,YAAA,YAAwB,MAAA;;AFf9E;;iBE+BgB,o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A;EAAU,KAAA,EAAO,SAAA;AAAA;EAAgB,EAAA;EAAW,KAAA,EAAO,KAAA;AAAA;;;;;;AN9BxD;;;;cOZa,OAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/cmd/index.ts","../src/run.ts","../src/index.ts"],"mappings":";;;;;;KAwBY,WAAA;;;;KAKA,YAAA;;;;;iBAMI,YAAA,CACd,IAAA,EAAM,IAAA,EACN,SAAA,EAAW,YAAA,EACX,QAAA,YACC,MAAA;;;;iBAqCa,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,UAAA;;;AAA5C;iBAOgB,UAAA,CAAW,IAAA,EAAM,UAAA;;;;;AAhDjC;UClBiB,gBAAA;;EAEf,QAAA;EDkBW;EChBX,GAAA,EAAK,YAAA;EDkBE;EChBP,QAAA;AAAA;;;;iBAMc,SAAA,CAAU,IAAA,EAAM,gBAAA,GAAmB,MAAA;;;;iBAWnC,kBAAA,CAAmB,IAAA,EAAM,gBAAA,GAAmB,IAAA;;;;;ADL5D;UEjBiB,kBAAA;;EAEf,KAAA;EFiBW;EEfX,EAAA,EAAI,WAAA;EFiBG;EEfP,GAAA,EAAK,YAAA;EFYC;EEVN,QAAA;AAAA;;;;iBAMc,qBAAA,CACd,IAAA,EAAM,kBAAA,EACN,UAAA,gBACA,QAAA,QAAgB,UAAA,GACf,MAAA;;AFwCH;;iBEegB,WAAA,CAAY,IAAA,EAAM,kBAAA,EAAoB,YAAA,YAAwB,MAAA;;;;iBAgB9D,oBAAA,CAAqB,IAAA,EAAM,kBAAA,EAAoB,YAAA,YAAwB,IAAA;;;;;AFxEvF;UGlBiB,cAAA;;EAEf,OAAA;EHkBW;EGhBX,GAAA,EAAK,YAAA;EHkBE;EGhBP,QAAA;AAAA;;;;iBAMc,OAAA,CAAQ,IAAA,EAAM,cAAA,GAAiB,MAAA;;;;iBAW/B,gBAAA,CAAiB,IAAA,EAAM,cAAA,GAAiB,IAAA;;;;;AHLxD;KITY,iBAAA;;;;UAKK,gBAAA;EJQR;EINP,OAAA;EJGM;EIDN,KAAA;EJEW;EIAX,EAAA,EAAI,WAAA;EJCJ;EICA,GAAA,EAAK,iBAAA;EJAE;EIEP,QAAA;EJmCc;EIjCd,QAAA;;EAEA,QAAA;EJ+B6B;EI7B7B,QAAA;AAAA;;;AJoCF;iBIHgB,SAAA,CAAU,IAAA,EAAM,gBAAA,EAAkB,YAAA,YAAwB,MAAA;;;;iBAmH1D,kBAAA,CAAmB,IAAA,EAAM,gBAAA,EAAkB,YAAA,YAAwB,IAAA;;;AJhKnF;;;;AAAA,UKfiB,IAAA;EACf,IAAA,IAAQ,MAAA;AAAA;;;;;;KCLE,OAAA;EACN,IAAA;EAAe,QAAA;EAAoB,GAAA,EAAK,YAAA;EAAc,QAAA;AAAA;EACtD,IAAA;EAAa,OAAA;EAAmB,GAAA,EAAK,YAAA;EAAc,QAAA;AAAA;EAEnD,IAAA;EACA,OAAA;EACA,KAAA;EACA,EAAA,EAAI,WAAA;EACJ,GAAA,EAAK,iBAAA;EACL,QAAA;EACA,QAAA;EACA,QAAA;EACA,QAAA;AAAA;EAGA,IAAA;EACA,KAAA;EACA,EAAA,EAAI,WAAA;EACJ,GAAA,EAAK,YAAA;EACL,QAAA;AAAA;AAAA,UAGW,UAAA;EACf,OAAA,EAAS,OAAA;EACT,YAAA;AAAA;AAAA,UAGe,SAAA;EACf,MAAA;EACA,QAAA;AAAA;;;;;iBAOc,GAAA,CACd,OAAA,EAAS,UAAA;EACN,EAAA;EAAU,KAAA,EAAO,SAAA;AAAA;EAAgB,EAAA;EAAW,KAAA,EAAO,KAAA;AAAA;;;;;;AN9BxD;;;;;AAKA;;;cOjBa,OAAA"}
package/dist/index.mjs CHANGED
@@ -1,7 +1,11 @@
1
- import { a as execMap, c as execDefaultWithReader, d as formatOutput, f as readData, i as createMapCommand, l as createArrayCommand, n as createMatchCommand, o as createDefaultCommand, p as readString, r as execMatch, s as execDefault, t as run, u as execArray } from "./run-GBL_cAOh.mjs";
1
+ import { a as execMap, c as execDefaultWithReader, d as formatOutput, f as readData, i as createMapCommand, l as createArrayCommand, n as createMatchCommand, o as createDefaultCommand, p as readString, r as execMatch, s as execDefault, t as run, u as execArray } from "./run-DJdWarnw.mjs";
2
2
 
3
3
  //#region src/index.ts
4
4
  /**
5
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6
+ * Copyright © 2025-2026 Parity Technologies
7
+ *
8
+ *
5
9
  * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)
6
10
  *
7
11
  * A command line tool for composing, parsing and validating Gordian dCBOR.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing and validating Gordian dCBOR.\n *\n * @packageDocumentation\n */\n\nexport const VERSION = \"1.0.0-alpha.13\";\n\n// Export format utilities\nexport { formatOutput, readData, readString } from \"./format.js\";\nexport type { InputFormat, OutputFormat } from \"./format.js\";\n\n// Export command modules\nexport {\n // Exec interface\n type Exec,\n // Array command\n type ArrayCommandArgs,\n execArray,\n createArrayCommand,\n // Map command\n type MapCommandArgs,\n execMap,\n createMapCommand,\n // Default command\n type DefaultCommandArgs,\n execDefault,\n execDefaultWithReader,\n createDefaultCommand,\n // Match command\n type MatchOutputFormat,\n type MatchCommandArgs,\n execMatch,\n createMatchCommand,\n} from \"./cmd/index.js\";\n\n// Export the run function for programmatic use\nexport { run } from \"./run.js\";\nexport type { RunOptions, RunResult, Command } from \"./run.js\";\n"],"mappings":";;;;;;;;;;AAQA,MAAa,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)\n *\n * A command line tool for composing, parsing and validating Gordian dCBOR.\n *\n * @packageDocumentation\n */\n\nexport const VERSION = \"1.0.0-alpha.13\";\n\n// Export format utilities\nexport { formatOutput, readData, readString } from \"./format.js\";\nexport type { InputFormat, OutputFormat } from \"./format.js\";\n\n// Export command modules\nexport {\n // Exec interface\n type Exec,\n // Array command\n type ArrayCommandArgs,\n execArray,\n createArrayCommand,\n // Map command\n type MapCommandArgs,\n execMap,\n createMapCommand,\n // Default command\n type DefaultCommandArgs,\n execDefault,\n execDefaultWithReader,\n createDefaultCommand,\n // Match command\n type MatchOutputFormat,\n type MatchCommandArgs,\n execMatch,\n createMatchCommand,\n} from \"./cmd/index.js\";\n\n// Export the run function for programmatic use\nexport { run } from \"./run.js\";\nexport type { RunOptions, RunResult, Command } from \"./run.js\";\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,UAAU"}
@@ -4,6 +4,10 @@ let _bcts_dcbor_pattern = require("@bcts/dcbor-pattern");
4
4
 
5
5
  //#region src/format.ts
6
6
  /**
7
+ * Copyright © 2023-2026 Blockchain Commons, LLC
8
+ * Copyright © 2025-2026 Parity Technologies
9
+ *
10
+ *
7
11
  * Format utilities for dcbor-cli
8
12
  * Contains InputFormat, OutputFormat enums and formatOutput function
9
13
  * Equivalent to the format-related code in Rust's main.rs
@@ -70,6 +74,10 @@ function readString(data) {
70
74
  //#endregion
71
75
  //#region src/cmd/array.ts
72
76
  /**
77
+ * Copyright © 2023-2026 Blockchain Commons, LLC
78
+ * Copyright © 2025-2026 Parity Technologies
79
+ *
80
+ *
73
81
  * Compose a dCBOR array from the provided elements
74
82
  * Equivalent to Rust's cmd/array.rs
75
83
  */
@@ -94,6 +102,10 @@ function createArrayCommand(args) {
94
102
  //#endregion
95
103
  //#region src/cmd/default.ts
96
104
  /**
105
+ * Copyright © 2023-2026 Blockchain Commons, LLC
106
+ * Copyright © 2025-2026 Parity Technologies
107
+ *
108
+ *
97
109
  * Default parsing and validation behavior
98
110
  * Equivalent to Rust's cmd/default.rs
99
111
  */
@@ -161,6 +173,10 @@ function createDefaultCommand(args, stdinContent) {
161
173
  //#endregion
162
174
  //#region src/cmd/map.ts
163
175
  /**
176
+ * Copyright © 2023-2026 Blockchain Commons, LLC
177
+ * Copyright © 2025-2026 Parity Technologies
178
+ *
179
+ *
164
180
  * Compose a dCBOR map from the provided keys and values
165
181
  * Equivalent to Rust's cmd/map.rs
166
182
  */
@@ -185,6 +201,10 @@ function createMapCommand(args) {
185
201
  //#endregion
186
202
  //#region src/cmd/match.ts
187
203
  /**
204
+ * Copyright © 2023-2026 Blockchain Commons, LLC
205
+ * Copyright © 2025-2026 Parity Technologies
206
+ *
207
+ *
188
208
  * Match dCBOR data against a pattern
189
209
  * Equivalent to Rust's cmd/match.rs
190
210
  */
@@ -302,6 +322,10 @@ function createMatchCommand(args, stdinContent) {
302
322
  //#endregion
303
323
  //#region src/run.ts
304
324
  /**
325
+ * Copyright © 2023-2026 Blockchain Commons, LLC
326
+ * Copyright © 2025-2026 Parity Technologies
327
+ *
328
+ *
305
329
  * Main run function for dcbor-cli
306
330
  * Equivalent to Rust's run function in main.rs
307
331
  */
@@ -313,7 +337,7 @@ function run(options) {
313
337
  (0, _bcts_dcbor.registerTags)();
314
338
  const { command, stdinContent } = options;
315
339
  let output;
316
- let isBinary = false;
340
+ let isBinary;
317
341
  switch (command.type) {
318
342
  case "array": {
319
343
  const result = execArray({
@@ -470,4 +494,4 @@ Object.defineProperty(exports, 'run', {
470
494
  return run;
471
495
  }
472
496
  });
473
- //# sourceMappingURL=run-B28RHYgN.cjs.map
497
+ //# sourceMappingURL=run-C1YH5VEh.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-C1YH5VEh.cjs","names":["FormatPathsOptsBuilder"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Format utilities for dcbor-cli\n * Contains InputFormat, OutputFormat enums and formatOutput function\n * Equivalent to the format-related code in Rust's main.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n\nimport {\n type Cbor,\n type Result,\n diagnosticOpt,\n hexOpt,\n bytesToHex,\n cborData,\n errorMsg,\n} from \"@bcts/dcbor\";\n\n/**\n * Input format options\n */\nexport type InputFormat = \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Output format options\n */\nexport type OutputFormat = \"diag\" | \"hex\" | \"bin\" | \"none\";\n\n/**\n * Format CBOR output in the specified format\n * Equivalent to Rust's format_output function\n */\nexport function formatOutput(\n cbor: Cbor,\n outFormat: OutputFormat,\n annotate: boolean,\n): Result<string> {\n try {\n switch (outFormat) {\n case \"diag\":\n // Use flat: true for compact single-line output (matching Rust CLI behavior)\n if (annotate) {\n return { ok: true, value: diagnosticOpt(cbor, { annotate: true, flat: true }) };\n } else {\n return { ok: true, value: diagnosticOpt(cbor, { flat: true }) };\n }\n\n case \"hex\":\n if (annotate) {\n return { ok: true, value: hexOpt(cbor, { annotate: true }) };\n } else {\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n }\n\n case \"bin\":\n // For binary output, return hex representation\n // The caller will handle converting to actual binary\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n\n case \"none\":\n return { ok: true, value: \"\" };\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${outFormat}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n}\n\n/**\n * Read binary data from a buffer\n */\nexport function readData(data: Uint8Array): Uint8Array {\n return data;\n}\n\n/**\n * Read string data from a buffer\n */\nexport function readString(data: Uint8Array): string {\n return new TextDecoder().decode(data);\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Compose a dCBOR array from the provided elements\n * Equivalent to Rust's cmd/array.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborArray, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for array composition\n */\nexport interface ArrayCommandArgs {\n /** Each element is parsed as a dCBOR item in diagnostic notation */\n elements: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute array command\n */\nexport function execArray(args: ArrayCommandArgs): Result<string> {\n const result = composeDcborArray(args.elements);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for array command\n */\nexport function createArrayCommand(args: ArrayCommandArgs): Exec {\n return {\n exec: () => execArray(args),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Default parsing and validation behavior\n * Equivalent to Rust's cmd/default.rs\n */\n\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type InputFormat, type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for default parsing behavior\n */\nexport interface DefaultCommandArgs {\n /** Input dCBOR in the format specified by `in`. Optional - reads from stdin if not provided */\n input?: string | undefined;\n /** The input format (default: diag) */\n in: InputFormat;\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute default command with a reader function for stdin\n */\nexport function execDefaultWithReader(\n args: DefaultCommandArgs,\n readString: () => string,\n readData: () => Uint8Array,\n): Result<string> {\n let cbor: Cbor;\n\n try {\n switch (args.in) {\n case \"diag\": {\n if (args.input !== undefined) {\n const result = parseDcborItem(args.input);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, args.input)),\n };\n }\n cbor = result.value;\n } else {\n const diag = readString();\n const result = parseDcborItem(diag);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, diag)),\n };\n }\n cbor = result.value;\n }\n break;\n }\n case \"hex\": {\n if (args.input !== undefined) {\n cbor = decodeCbor(hexToBytes(args.input));\n } else {\n const hexStr = readString().trim();\n cbor = decodeCbor(hexToBytes(hexStr));\n }\n break;\n }\n case \"bin\": {\n const data = readData();\n cbor = decodeCbor(data);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n return formatOutput(cbor, args.out, args.annotate);\n}\n\n/**\n * Execute default command (reads from stdin if input not provided)\n */\nexport function execDefault(args: DefaultCommandArgs, stdinContent?: string): Result<string> {\n return execDefaultWithReader(\n args,\n () => stdinContent ?? \"\",\n () => {\n if (stdinContent) {\n return new TextEncoder().encode(stdinContent);\n }\n return new Uint8Array(0);\n },\n );\n}\n\n/**\n * Create an Exec implementation for default command\n */\nexport function createDefaultCommand(args: DefaultCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execDefault(args, stdinContent),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Compose a dCBOR map from the provided keys and values\n * Equivalent to Rust's cmd/map.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborMap, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for map composition\n */\nexport interface MapCommandArgs {\n /** Alternating keys and values parsed as dCBOR items in diagnostic notation */\n kvPairs: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute map command\n */\nexport function execMap(args: MapCommandArgs): Result<string> {\n const result = composeDcborMap(args.kvPairs);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for map command\n */\nexport function createMapCommand(args: MapCommandArgs): Exec {\n return {\n exec: () => execMap(args),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Match dCBOR data against a pattern\n * Equivalent to Rust's cmd/match.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/switch-exhaustiveness-check */\n\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport {\n parse as parsePattern,\n pathsWithCaptures,\n formatPathsWithCaptures,\n FormatPathsOptsBuilder,\n type Error as PatternParseError,\n} from \"@bcts/dcbor-pattern\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\nimport type { InputFormat } from \"../format.js\";\n\n/**\n * Match output format options\n */\nexport type MatchOutputFormat = \"paths\" | \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Command arguments for match command\n */\nexport interface MatchCommandArgs {\n /** The pattern to match against */\n pattern: string;\n /** dCBOR input (hex, diag, or binary). If not provided, reads from stdin */\n input?: string | undefined;\n /** Input format (default: diag) */\n in: InputFormat;\n /** Output format (default: paths) */\n out: MatchOutputFormat;\n /** Disable indentation of path elements */\n noIndent: boolean;\n /** Show only the last element of each path */\n lastOnly: boolean;\n /** Add annotations to output */\n annotate: boolean;\n /** Include capture information in output */\n captures: boolean;\n}\n\n/**\n * Format a parse error with context\n */\nfunction formatPatternError(error: PatternParseError, patternStr: string): string {\n switch (error.type) {\n case \"UnrecognizedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n const end = Math.min(error.span.end, patternStr.length);\n const errorText = start < patternStr.length ? patternStr.slice(start, end) : \"<end of input>\";\n return `Failed to parse pattern at position ${start}..${end}: unrecognized token '${errorText}'\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"ExtraData\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern: extra data at position ${start}\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"UnexpectedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern at position ${start}: unexpected token\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n default:\n return `Failed to parse pattern: ${error.type}`;\n }\n}\n\n/**\n * Execute match command\n */\nexport function execMatch(args: MatchCommandArgs, stdinContent?: string): Result<string> {\n // Read input data\n let inputData: Uint8Array;\n if (args.input !== undefined) {\n inputData = new TextEncoder().encode(args.input);\n } else if (stdinContent !== undefined) {\n inputData = new TextEncoder().encode(stdinContent);\n } else {\n inputData = new Uint8Array(0);\n }\n\n // Parse input based on format\n let cbor: Cbor;\n try {\n switch (args.in) {\n case \"diag\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n const result = parseDcborItem(inputStr);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, inputStr)),\n };\n }\n cbor = result.value;\n break;\n }\n case \"hex\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n cbor = decodeCbor(hexToBytes(inputStr));\n break;\n }\n case \"bin\": {\n cbor = decodeCbor(inputData);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n // Parse pattern\n const patternResult = parsePattern(args.pattern);\n if (!patternResult.ok) {\n return {\n ok: false,\n error: errorMsg(formatPatternError(patternResult.error, args.pattern)),\n };\n }\n const pattern = patternResult.value;\n\n // Execute pattern matching\n const { paths, captures } = pathsWithCaptures(pattern, cbor);\n\n // Check for matches\n if (paths.length === 0) {\n return { ok: false, error: errorMsg(\"No match\") };\n }\n\n // Format output based on requested format\n switch (args.out) {\n case \"paths\": {\n // Build format options from command line arguments\n const formatOptions = FormatPathsOptsBuilder.new()\n .indent(!args.noIndent)\n .lastElementOnly(args.lastOnly)\n .build();\n\n // Show captures only if explicitly requested\n if (args.captures) {\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, captures, formatOptions),\n };\n } else {\n // Show paths without captures\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, new Map(), formatOptions),\n };\n }\n }\n\n case \"diag\":\n case \"hex\":\n case \"bin\": {\n // For data format outputs, extract the matched elements\n const outputFormat: OutputFormat = args.out;\n\n const elementsToOutput = args.lastOnly\n ? paths.map((path) => path[path.length - 1]).filter(Boolean)\n : paths.map((path) => path[0]).filter(Boolean);\n\n const results: string[] = [];\n for (const element of elementsToOutput) {\n const result = formatOutput(element, outputFormat, args.annotate);\n if (!result.ok) {\n return result;\n }\n results.push(result.value);\n }\n\n return { ok: true, value: results.join(\"\\n\") };\n }\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${args.out}`) };\n }\n}\n\n/**\n * Create an Exec implementation for match command\n */\nexport function createMatchCommand(args: MatchCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execMatch(args, stdinContent),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Main run function for dcbor-cli\n * Equivalent to Rust's run function in main.rs\n */\n\nimport { registerTags, errorToString } from \"@bcts/dcbor\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport { execArray, execDefault, execMap, execMatch, type MatchOutputFormat } from \"./cmd/index.js\";\n\n/**\n * Command type discriminator\n */\nexport type Command =\n | { type: \"array\"; elements: string[]; out: OutputFormat; annotate: boolean }\n | { type: \"map\"; kvPairs: string[]; out: OutputFormat; annotate: boolean }\n | {\n type: \"match\";\n pattern: string;\n input?: string | undefined;\n in: InputFormat;\n out: MatchOutputFormat;\n noIndent: boolean;\n lastOnly: boolean;\n annotate: boolean;\n captures: boolean;\n }\n | {\n type: \"default\";\n input?: string | undefined;\n in: InputFormat;\n out: OutputFormat;\n annotate: boolean;\n };\n\nexport interface RunOptions {\n command: Command;\n stdinContent?: string | undefined;\n}\n\nexport interface RunResult {\n output: string;\n isBinary: boolean;\n}\n\n/**\n * Main execution function\n * Equivalent to Rust's run<I, T, R, W> function\n */\nexport function run(\n options: RunOptions,\n): { ok: true; value: RunResult } | { ok: false; error: Error } {\n // Register BC components tags\n registerTags();\n\n const { command, stdinContent } = options;\n\n let output: string;\n let isBinary: boolean;\n\n switch (command.type) {\n case \"array\": {\n const result = execArray({\n elements: command.elements,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"map\": {\n const result = execMap({\n kvPairs: command.kvPairs,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"match\": {\n const result = execMatch(\n {\n pattern: command.pattern,\n input: command.input,\n in: command.in,\n out: command.out,\n noIndent: command.noIndent,\n lastOnly: command.lastOnly,\n annotate: command.annotate,\n captures: command.captures,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"default\": {\n const result = execDefault(\n {\n input: command.input,\n in: command.in,\n out: command.out,\n annotate: command.annotate,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n default:\n return { ok: false, error: new Error(\"Unknown command type\") };\n }\n\n return { ok: true, value: { output, isBinary } };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,SAAgB,aACd,MACA,WACA,UACgB;AAChB,KAAI;AACF,UAAQ,WAAR;GACE,KAAK,OAEH,KAAI,SACF,QAAO;IAAE,IAAI;IAAM,sCAAqB,MAAM;KAAE,UAAU;KAAM,MAAM;KAAM,CAAC;IAAE;OAE/E,QAAO;IAAE,IAAI;IAAM,sCAAqB,MAAM,EAAE,MAAM,MAAM,CAAC;IAAE;GAGnE,KAAK,MACH,KAAI,SACF,QAAO;IAAE,IAAI;IAAM,+BAAc,MAAM,EAAE,UAAU,MAAM,CAAC;IAAE;OAE5D,QAAO;IAAE,IAAI;IAAM,6DAA2B,KAAK,CAAC;IAAE;GAG1D,KAAK,MAGH,QAAO;IAAE,IAAI;IAAM,6DAA2B,KAAK,CAAC;IAAE;GAExD,KAAK,OACH,QAAO;IAAE,IAAI;IAAM,OAAO;IAAI;GAEhC,QACE,QAAO;IAAE,IAAI;IAAO,iCAAgB,0BAA0B,YAAY;IAAE;;UAEzE,GAAG;AACV,SAAO;GAAE,IAAI;GAAO,iCAAgB,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC;GAAE;;;;;;AAOrF,SAAgB,SAAS,MAA8B;AACrD,QAAO;;;;;AAMT,SAAgB,WAAW,MAA0B;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,KAAK;;;;;;;;;;;;;;;;ACvDvC,SAAgB,UAAU,MAAwC;CAChE,MAAM,kDAA2B,KAAK,SAAS;AAC/C,KAAI,CAAC,OAAO,GACV,QAAO;EAAE,IAAI;EAAO,4EAAoC,OAAO,MAAM,CAAC;EAAE;AAE1E,QAAO,aAAa,OAAO,OAAO,KAAK,KAAK,KAAK,SAAS;;;;;AAM5D,SAAgB,mBAAmB,MAA8B;AAC/D,QAAO,EACL,YAAY,UAAU,KAAK,EAC5B;;;;;;;;;;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AClB,UAAU,QAAQ;IACnB,EACD,aACD;AACD,OAAI,CAAC,OAAO,GACV,QAAO;IAAE,IAAI;IAAO,OAAO,IAAI,qCAAoB,OAAO,MAAM,CAAC;IAAE;AAErE,YAAS,OAAO;AAChB,cAAW,QAAQ,QAAQ;AAC3B;;EAGF,KAAK,WAAW;GACd,MAAM,SAAS,YACb;IACE,OAAO,QAAQ;IACf,IAAI,QAAQ;IACZ,KAAK,QAAQ;IACb,UAAU,QAAQ;IACnB,EACD,aACD;AACD,OAAI,CAAC,OAAO,GACV,QAAO;IAAE,IAAI;IAAO,OAAO,IAAI,qCAAoB,OAAO,MAAM,CAAC;IAAE;AAErE,YAAS,OAAO;AAChB,cAAW,QAAQ,QAAQ;AAC3B;;EAGF,QACE,QAAO;GAAE,IAAI;GAAO,uBAAO,IAAI,MAAM,uBAAuB;GAAE;;AAGlE,QAAO;EAAE,IAAI;EAAM,OAAO;GAAE;GAAQ;GAAU;EAAE"}
@@ -4,6 +4,10 @@ import { FormatPathsOptsBuilder, formatPathsWithCaptures, parse, pathsWithCaptur
4
4
 
5
5
  //#region src/format.ts
6
6
  /**
7
+ * Copyright © 2023-2026 Blockchain Commons, LLC
8
+ * Copyright © 2025-2026 Parity Technologies
9
+ *
10
+ *
7
11
  * Format utilities for dcbor-cli
8
12
  * Contains InputFormat, OutputFormat enums and formatOutput function
9
13
  * Equivalent to the format-related code in Rust's main.rs
@@ -70,6 +74,10 @@ function readString(data) {
70
74
  //#endregion
71
75
  //#region src/cmd/array.ts
72
76
  /**
77
+ * Copyright © 2023-2026 Blockchain Commons, LLC
78
+ * Copyright © 2025-2026 Parity Technologies
79
+ *
80
+ *
73
81
  * Compose a dCBOR array from the provided elements
74
82
  * Equivalent to Rust's cmd/array.rs
75
83
  */
@@ -94,6 +102,10 @@ function createArrayCommand(args) {
94
102
  //#endregion
95
103
  //#region src/cmd/default.ts
96
104
  /**
105
+ * Copyright © 2023-2026 Blockchain Commons, LLC
106
+ * Copyright © 2025-2026 Parity Technologies
107
+ *
108
+ *
97
109
  * Default parsing and validation behavior
98
110
  * Equivalent to Rust's cmd/default.rs
99
111
  */
@@ -161,6 +173,10 @@ function createDefaultCommand(args, stdinContent) {
161
173
  //#endregion
162
174
  //#region src/cmd/map.ts
163
175
  /**
176
+ * Copyright © 2023-2026 Blockchain Commons, LLC
177
+ * Copyright © 2025-2026 Parity Technologies
178
+ *
179
+ *
164
180
  * Compose a dCBOR map from the provided keys and values
165
181
  * Equivalent to Rust's cmd/map.rs
166
182
  */
@@ -185,6 +201,10 @@ function createMapCommand(args) {
185
201
  //#endregion
186
202
  //#region src/cmd/match.ts
187
203
  /**
204
+ * Copyright © 2023-2026 Blockchain Commons, LLC
205
+ * Copyright © 2025-2026 Parity Technologies
206
+ *
207
+ *
188
208
  * Match dCBOR data against a pattern
189
209
  * Equivalent to Rust's cmd/match.rs
190
210
  */
@@ -302,6 +322,10 @@ function createMatchCommand(args, stdinContent) {
302
322
  //#endregion
303
323
  //#region src/run.ts
304
324
  /**
325
+ * Copyright © 2023-2026 Blockchain Commons, LLC
326
+ * Copyright © 2025-2026 Parity Technologies
327
+ *
328
+ *
305
329
  * Main run function for dcbor-cli
306
330
  * Equivalent to Rust's run function in main.rs
307
331
  */
@@ -313,7 +337,7 @@ function run(options) {
313
337
  registerTags();
314
338
  const { command, stdinContent } = options;
315
339
  let output;
316
- let isBinary = false;
340
+ let isBinary;
317
341
  switch (command.type) {
318
342
  case "array": {
319
343
  const result = execArray({
@@ -393,4 +417,4 @@ function run(options) {
393
417
 
394
418
  //#endregion
395
419
  export { execMap as a, execDefaultWithReader as c, formatOutput as d, readData as f, createMapCommand as i, createArrayCommand as l, createMatchCommand as n, createDefaultCommand as o, readString as p, execMatch as r, execDefault as s, run as t, execArray as u };
396
- //# sourceMappingURL=run-GBL_cAOh.mjs.map
420
+ //# sourceMappingURL=run-DJdWarnw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-DJdWarnw.mjs","names":["parsePattern"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Format utilities for dcbor-cli\n * Contains InputFormat, OutputFormat enums and formatOutput function\n * Equivalent to the format-related code in Rust's main.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n\nimport {\n type Cbor,\n type Result,\n diagnosticOpt,\n hexOpt,\n bytesToHex,\n cborData,\n errorMsg,\n} from \"@bcts/dcbor\";\n\n/**\n * Input format options\n */\nexport type InputFormat = \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Output format options\n */\nexport type OutputFormat = \"diag\" | \"hex\" | \"bin\" | \"none\";\n\n/**\n * Format CBOR output in the specified format\n * Equivalent to Rust's format_output function\n */\nexport function formatOutput(\n cbor: Cbor,\n outFormat: OutputFormat,\n annotate: boolean,\n): Result<string> {\n try {\n switch (outFormat) {\n case \"diag\":\n // Use flat: true for compact single-line output (matching Rust CLI behavior)\n if (annotate) {\n return { ok: true, value: diagnosticOpt(cbor, { annotate: true, flat: true }) };\n } else {\n return { ok: true, value: diagnosticOpt(cbor, { flat: true }) };\n }\n\n case \"hex\":\n if (annotate) {\n return { ok: true, value: hexOpt(cbor, { annotate: true }) };\n } else {\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n }\n\n case \"bin\":\n // For binary output, return hex representation\n // The caller will handle converting to actual binary\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n\n case \"none\":\n return { ok: true, value: \"\" };\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${outFormat}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n}\n\n/**\n * Read binary data from a buffer\n */\nexport function readData(data: Uint8Array): Uint8Array {\n return data;\n}\n\n/**\n * Read string data from a buffer\n */\nexport function readString(data: Uint8Array): string {\n return new TextDecoder().decode(data);\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Compose a dCBOR array from the provided elements\n * Equivalent to Rust's cmd/array.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborArray, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for array composition\n */\nexport interface ArrayCommandArgs {\n /** Each element is parsed as a dCBOR item in diagnostic notation */\n elements: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute array command\n */\nexport function execArray(args: ArrayCommandArgs): Result<string> {\n const result = composeDcborArray(args.elements);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for array command\n */\nexport function createArrayCommand(args: ArrayCommandArgs): Exec {\n return {\n exec: () => execArray(args),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Default parsing and validation behavior\n * Equivalent to Rust's cmd/default.rs\n */\n\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type InputFormat, type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for default parsing behavior\n */\nexport interface DefaultCommandArgs {\n /** Input dCBOR in the format specified by `in`. Optional - reads from stdin if not provided */\n input?: string | undefined;\n /** The input format (default: diag) */\n in: InputFormat;\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute default command with a reader function for stdin\n */\nexport function execDefaultWithReader(\n args: DefaultCommandArgs,\n readString: () => string,\n readData: () => Uint8Array,\n): Result<string> {\n let cbor: Cbor;\n\n try {\n switch (args.in) {\n case \"diag\": {\n if (args.input !== undefined) {\n const result = parseDcborItem(args.input);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, args.input)),\n };\n }\n cbor = result.value;\n } else {\n const diag = readString();\n const result = parseDcborItem(diag);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, diag)),\n };\n }\n cbor = result.value;\n }\n break;\n }\n case \"hex\": {\n if (args.input !== undefined) {\n cbor = decodeCbor(hexToBytes(args.input));\n } else {\n const hexStr = readString().trim();\n cbor = decodeCbor(hexToBytes(hexStr));\n }\n break;\n }\n case \"bin\": {\n const data = readData();\n cbor = decodeCbor(data);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n return formatOutput(cbor, args.out, args.annotate);\n}\n\n/**\n * Execute default command (reads from stdin if input not provided)\n */\nexport function execDefault(args: DefaultCommandArgs, stdinContent?: string): Result<string> {\n return execDefaultWithReader(\n args,\n () => stdinContent ?? \"\",\n () => {\n if (stdinContent) {\n return new TextEncoder().encode(stdinContent);\n }\n return new Uint8Array(0);\n },\n );\n}\n\n/**\n * Create an Exec implementation for default command\n */\nexport function createDefaultCommand(args: DefaultCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execDefault(args, stdinContent),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Compose a dCBOR map from the provided keys and values\n * Equivalent to Rust's cmd/map.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborMap, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for map composition\n */\nexport interface MapCommandArgs {\n /** Alternating keys and values parsed as dCBOR items in diagnostic notation */\n kvPairs: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute map command\n */\nexport function execMap(args: MapCommandArgs): Result<string> {\n const result = composeDcborMap(args.kvPairs);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for map command\n */\nexport function createMapCommand(args: MapCommandArgs): Exec {\n return {\n exec: () => execMap(args),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Match dCBOR data against a pattern\n * Equivalent to Rust's cmd/match.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/switch-exhaustiveness-check */\n\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport {\n parse as parsePattern,\n pathsWithCaptures,\n formatPathsWithCaptures,\n FormatPathsOptsBuilder,\n type Error as PatternParseError,\n} from \"@bcts/dcbor-pattern\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\nimport type { InputFormat } from \"../format.js\";\n\n/**\n * Match output format options\n */\nexport type MatchOutputFormat = \"paths\" | \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Command arguments for match command\n */\nexport interface MatchCommandArgs {\n /** The pattern to match against */\n pattern: string;\n /** dCBOR input (hex, diag, or binary). If not provided, reads from stdin */\n input?: string | undefined;\n /** Input format (default: diag) */\n in: InputFormat;\n /** Output format (default: paths) */\n out: MatchOutputFormat;\n /** Disable indentation of path elements */\n noIndent: boolean;\n /** Show only the last element of each path */\n lastOnly: boolean;\n /** Add annotations to output */\n annotate: boolean;\n /** Include capture information in output */\n captures: boolean;\n}\n\n/**\n * Format a parse error with context\n */\nfunction formatPatternError(error: PatternParseError, patternStr: string): string {\n switch (error.type) {\n case \"UnrecognizedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n const end = Math.min(error.span.end, patternStr.length);\n const errorText = start < patternStr.length ? patternStr.slice(start, end) : \"<end of input>\";\n return `Failed to parse pattern at position ${start}..${end}: unrecognized token '${errorText}'\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"ExtraData\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern: extra data at position ${start}\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"UnexpectedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern at position ${start}: unexpected token\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n default:\n return `Failed to parse pattern: ${error.type}`;\n }\n}\n\n/**\n * Execute match command\n */\nexport function execMatch(args: MatchCommandArgs, stdinContent?: string): Result<string> {\n // Read input data\n let inputData: Uint8Array;\n if (args.input !== undefined) {\n inputData = new TextEncoder().encode(args.input);\n } else if (stdinContent !== undefined) {\n inputData = new TextEncoder().encode(stdinContent);\n } else {\n inputData = new Uint8Array(0);\n }\n\n // Parse input based on format\n let cbor: Cbor;\n try {\n switch (args.in) {\n case \"diag\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n const result = parseDcborItem(inputStr);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, inputStr)),\n };\n }\n cbor = result.value;\n break;\n }\n case \"hex\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n cbor = decodeCbor(hexToBytes(inputStr));\n break;\n }\n case \"bin\": {\n cbor = decodeCbor(inputData);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n // Parse pattern\n const patternResult = parsePattern(args.pattern);\n if (!patternResult.ok) {\n return {\n ok: false,\n error: errorMsg(formatPatternError(patternResult.error, args.pattern)),\n };\n }\n const pattern = patternResult.value;\n\n // Execute pattern matching\n const { paths, captures } = pathsWithCaptures(pattern, cbor);\n\n // Check for matches\n if (paths.length === 0) {\n return { ok: false, error: errorMsg(\"No match\") };\n }\n\n // Format output based on requested format\n switch (args.out) {\n case \"paths\": {\n // Build format options from command line arguments\n const formatOptions = FormatPathsOptsBuilder.new()\n .indent(!args.noIndent)\n .lastElementOnly(args.lastOnly)\n .build();\n\n // Show captures only if explicitly requested\n if (args.captures) {\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, captures, formatOptions),\n };\n } else {\n // Show paths without captures\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, new Map(), formatOptions),\n };\n }\n }\n\n case \"diag\":\n case \"hex\":\n case \"bin\": {\n // For data format outputs, extract the matched elements\n const outputFormat: OutputFormat = args.out;\n\n const elementsToOutput = args.lastOnly\n ? paths.map((path) => path[path.length - 1]).filter(Boolean)\n : paths.map((path) => path[0]).filter(Boolean);\n\n const results: string[] = [];\n for (const element of elementsToOutput) {\n const result = formatOutput(element, outputFormat, args.annotate);\n if (!result.ok) {\n return result;\n }\n results.push(result.value);\n }\n\n return { ok: true, value: results.join(\"\\n\") };\n }\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${args.out}`) };\n }\n}\n\n/**\n * Create an Exec implementation for match command\n */\nexport function createMatchCommand(args: MatchCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execMatch(args, stdinContent),\n };\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Main run function for dcbor-cli\n * Equivalent to Rust's run function in main.rs\n */\n\nimport { registerTags, errorToString } from \"@bcts/dcbor\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport { execArray, execDefault, execMap, execMatch, type MatchOutputFormat } from \"./cmd/index.js\";\n\n/**\n * Command type discriminator\n */\nexport type Command =\n | { type: \"array\"; elements: string[]; out: OutputFormat; annotate: boolean }\n | { type: \"map\"; kvPairs: string[]; out: OutputFormat; annotate: boolean }\n | {\n type: \"match\";\n pattern: string;\n input?: string | undefined;\n in: InputFormat;\n out: MatchOutputFormat;\n noIndent: boolean;\n lastOnly: boolean;\n annotate: boolean;\n captures: boolean;\n }\n | {\n type: \"default\";\n input?: string | undefined;\n in: InputFormat;\n out: OutputFormat;\n annotate: boolean;\n };\n\nexport interface RunOptions {\n command: Command;\n stdinContent?: string | undefined;\n}\n\nexport interface RunResult {\n output: string;\n isBinary: boolean;\n}\n\n/**\n * Main execution function\n * Equivalent to Rust's run<I, T, R, W> function\n */\nexport function run(\n options: RunOptions,\n): { ok: true; value: RunResult } | { ok: false; error: Error } {\n // Register BC components tags\n registerTags();\n\n const { command, stdinContent } = options;\n\n let output: string;\n let isBinary: boolean;\n\n switch (command.type) {\n case \"array\": {\n const result = execArray({\n elements: command.elements,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"map\": {\n const result = execMap({\n kvPairs: command.kvPairs,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"match\": {\n const result = execMatch(\n {\n pattern: command.pattern,\n input: command.input,\n in: command.in,\n out: command.out,\n noIndent: command.noIndent,\n lastOnly: command.lastOnly,\n annotate: command.annotate,\n captures: command.captures,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"default\": {\n const result = execDefault(\n {\n input: command.input,\n in: command.in,\n out: command.out,\n annotate: command.annotate,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n default:\n return { ok: false, error: new Error(\"Unknown command type\") };\n }\n\n return { ok: true, value: { output, isBinary } };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,SAAgB,aACd,MACA,WACA,UACgB;AAChB,KAAI;AACF,UAAQ,WAAR;GACE,KAAK,OAEH,KAAI,SACF,QAAO;IAAE,IAAI;IAAM,OAAO,cAAc,MAAM;KAAE,UAAU;KAAM,MAAM;KAAM,CAAC;IAAE;OAE/E,QAAO;IAAE,IAAI;IAAM,OAAO,cAAc,MAAM,EAAE,MAAM,MAAM,CAAC;IAAE;GAGnE,KAAK,MACH,KAAI,SACF,QAAO;IAAE,IAAI;IAAM,OAAO,OAAO,MAAM,EAAE,UAAU,MAAM,CAAC;IAAE;OAE5D,QAAO;IAAE,IAAI;IAAM,OAAO,WAAW,SAAS,KAAK,CAAC;IAAE;GAG1D,KAAK,MAGH,QAAO;IAAE,IAAI;IAAM,OAAO,WAAW,SAAS,KAAK,CAAC;IAAE;GAExD,KAAK,OACH,QAAO;IAAE,IAAI;IAAM,OAAO;IAAI;GAEhC,QACE,QAAO;IAAE,IAAI;IAAO,OAAO,SAAS,0BAA0B,YAAY;IAAE;;UAEzE,GAAG;AACV,SAAO;GAAE,IAAI;GAAO,OAAO,SAAS,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC;GAAE;;;;;;AAOrF,SAAgB,SAAS,MAA8B;AACrD,QAAO;;;;;AAMT,SAAgB,WAAW,MAA0B;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,KAAK;;;;;;;;;;;;;;;;ACvDvC,SAAgB,UAAU,MAAwC;CAChE,MAAM,SAAS,kBAAkB,KAAK,SAAS;AAC/C,KAAI,CAAC,OAAO,GACV,QAAO;EAAE,IAAI;EAAO,OAAO,SAAS,oBAAoB,OAA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F,OAAI,CAAC,OAAO,GACV,QAAO;IAAE,IAAI;IAAO,OAAO,IAAI,MAAM,cAAc,OAAO,MAAM,CAAC;IAAE;AAErE,YAAS,OAAO;AAChB,cAAW,QAAQ,QAAQ;AAC3B;;EAGF,KAAK,SAAS;GACZ,MAAM,SAAS,UACb;IACE,SAAS,QAAQ;IACjB,OAAO,QAAQ;IACf,IAAI,QAAQ;IACZ,KAAK,QAAQ;IACb,UAAU,QAAQ;IAClB,UAAU,QAAQ;IAClB,UAAU,QAAQ;IAClB,UAAU,QAAQ;IACnB,EACD,aACD;AACD,OAAI,CAAC,OAAO,GACV,QAAO;IAAE,IAAI;IAAO,OAAO,IAAI,MAAM,cAAc,OAAO,MAAM,CAAC;IAAE;AAErE,YAAS,OAAO;AAChB,cAAW,QAAQ,QAAQ;AAC3B;;EAGF,KAAK,WAAW;GACd,MAAM,SAAS,YACb;IACE,OAAO,QAAQ;IACf,IAAI,QAAQ;IACZ,KAAK,QAAQ;IACb,UAAU,QAAQ;IACnB,EACD,aACD;AACD,OAAI,CAAC,OAAO,GACV,QAAO;IAAE,IAAI;IAAO,OAAO,IAAI,MAAM,cAAc,OAAO,MAAM,CAAC;IAAE;AAErE,YAAS,OAAO;AAChB,cAAW,QAAQ,QAAQ;AAC3B;;EAGF,QACE,QAAO;GAAE,IAAI;GAAO,uBAAO,IAAI,MAAM,uBAAuB;GAAE;;AAGlE,QAAO;EAAE,IAAI;EAAM,OAAO;GAAE;GAAQ;GAAU;EAAE"}
package/package.json CHANGED
@@ -1,29 +1,18 @@
1
1
  {
2
2
  "name": "@bcts/dcbor-cli",
3
- "version": "1.0.0-alpha.19",
3
+ "version": "1.0.0-alpha.21",
4
4
  "type": "module",
5
5
  "description": "Command line parser/validator for deterministic CBOR (dCBOR)",
6
6
  "license": "BSD-2-Clause-Patent",
7
- "contributors": [
8
- {
9
- "name": "Leonardo Custodio",
10
- "email": "leonardo.custodio@parity.io",
11
- "url": "https://github.com/leonardocustodio"
12
- },
13
- {
14
- "name": "Karim Jedda",
15
- "email": "karim@parity.io",
16
- "url": "https://github.com/KarimJedda"
17
- }
18
- ],
7
+ "author": "Parity Technologies <admin@parity.io> (https://parity.io)",
19
8
  "homepage": "https://bcts.dev",
20
9
  "repository": {
21
10
  "type": "git",
22
- "url": "git+https://github.com/leonardocustodio/bcts.git",
11
+ "url": "git+https://github.com/paritytech/bcts.git",
23
12
  "directory": "tools/dcbor-cli"
24
13
  },
25
14
  "bugs": {
26
- "url": "https://github.com/leonardocustodio/bcts/issues"
15
+ "url": "https://github.com/paritytech/bcts/issues"
27
16
  },
28
17
  "bin": {
29
18
  "dcbor": "./dist/cli.mjs"
@@ -70,18 +59,18 @@
70
59
  "devDependencies": {
71
60
  "@bcts/eslint": "^0.1.0",
72
61
  "@bcts/tsconfig": "^0.1.0",
73
- "@types/node": "^25.2.1",
74
- "eslint": "^9.39.2",
62
+ "@types/node": "^25.3.2",
63
+ "eslint": "^10.0.2",
75
64
  "tsdown": "^0.20.3",
76
- "typedoc": "^0.28.16",
65
+ "typedoc": "^0.28.17",
77
66
  "typescript": "^5.9.3",
78
67
  "vitest": "^4.0.18"
79
68
  },
80
69
  "dependencies": {
81
- "@bcts/components": "^1.0.0-alpha.19",
82
- "@bcts/dcbor": "^1.0.0-alpha.19",
83
- "@bcts/dcbor-parse": "^1.0.0-alpha.19",
84
- "@bcts/dcbor-pattern": "^1.0.0-alpha.19",
70
+ "@bcts/components": "^1.0.0-alpha.21",
71
+ "@bcts/dcbor": "^1.0.0-alpha.21",
72
+ "@bcts/dcbor-parse": "^1.0.0-alpha.21",
73
+ "@bcts/dcbor-pattern": "^1.0.0-alpha.21",
85
74
  "commander": "^14.0.3"
86
75
  }
87
76
  }
package/src/cli.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
2
  /**
3
+ * Copyright © 2023-2026 Blockchain Commons, LLC
4
+ * Copyright © 2025-2026 Parity Technologies
5
+ *
6
+ *
4
7
  * dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)
5
8
  *
6
- * A command line tool for composing, parsing and validating Gordian dCBOR.
7
- * See the main repo README: https://github.com/leonardocustodio/bcts
9
+ * A command line tool for composing, parsing, and validating Gordian dCBOR.
10
+ * See the main repo README: https://github.com/paritytech/bcts
11
+ *
8
12
  */
9
13
 
14
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
10
15
  import { Command, Option } from "commander";
11
16
  import { VERSION } from "./index.js";
12
17
  import { run, type Command as CmdType } from "./run.js";
package/src/cmd/array.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Compose a dCBOR array from the provided elements
3
7
  * Equivalent to Rust's cmd/array.rs
4
8
  */
@@ -1,9 +1,13 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Default parsing and validation behavior
3
7
  * Equivalent to Rust's cmd/default.rs
4
8
  */
5
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
6
9
 
10
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
7
11
  import { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from "@bcts/dcbor";
8
12
  import { parseDcborItem, fullErrorMessage } from "@bcts/dcbor-parse";
9
13
  import type { Exec } from "./index.js";
package/src/cmd/index.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Command module organization
3
7
  * Equivalent to Rust's cmd/mod.rs
4
8
  */
package/src/cmd/map.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Compose a dCBOR map from the provided keys and values
3
7
  * Equivalent to Rust's cmd/map.rs
4
8
  */
package/src/cmd/match.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Match dCBOR data against a pattern
3
7
  * Equivalent to Rust's cmd/match.rs
4
8
  */
package/src/format.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Format utilities for dcbor-cli
3
7
  * Contains InputFormat, OutputFormat enums and formatOutput function
4
8
  * Equivalent to the format-related code in Rust's main.rs
package/src/index.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * @bcts/dcbor-cli - Command line parser/validator for deterministic CBOR (dCBOR)
3
7
  *
4
8
  * A command line tool for composing, parsing and validating Gordian dCBOR.
package/src/run.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Copyright © 2023-2026 Blockchain Commons, LLC
3
+ * Copyright © 2025-2026 Parity Technologies
4
+ *
5
+ *
2
6
  * Main run function for dcbor-cli
3
7
  * Equivalent to Rust's run function in main.rs
4
8
  */
@@ -55,7 +59,7 @@ export function run(
55
59
  const { command, stdinContent } = options;
56
60
 
57
61
  let output: string;
58
- let isBinary = false;
62
+ let isBinary: boolean;
59
63
 
60
64
  switch (command.type) {
61
65
  case "array": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-B28RHYgN.cjs","names":["FormatPathsOptsBuilder"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts"],"sourcesContent":["/**\n * Format utilities for dcbor-cli\n * Contains InputFormat, OutputFormat enums and formatOutput function\n * Equivalent to the format-related code in Rust's main.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n\nimport {\n type Cbor,\n type Result,\n diagnosticOpt,\n hexOpt,\n bytesToHex,\n cborData,\n errorMsg,\n} from \"@bcts/dcbor\";\n\n/**\n * Input format options\n */\nexport type InputFormat = \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Output format options\n */\nexport type OutputFormat = \"diag\" | \"hex\" | \"bin\" | \"none\";\n\n/**\n * Format CBOR output in the specified format\n * Equivalent to Rust's format_output function\n */\nexport function formatOutput(\n cbor: Cbor,\n outFormat: OutputFormat,\n annotate: boolean,\n): Result<string> {\n try {\n switch (outFormat) {\n case \"diag\":\n // Use flat: true for compact single-line output (matching Rust CLI behavior)\n if (annotate) {\n return { ok: true, value: diagnosticOpt(cbor, { annotate: true, flat: true }) };\n } else {\n return { ok: true, value: diagnosticOpt(cbor, { flat: true }) };\n }\n\n case \"hex\":\n if (annotate) {\n return { ok: true, value: hexOpt(cbor, { annotate: true }) };\n } else {\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n }\n\n case \"bin\":\n // For binary output, return hex representation\n // The caller will handle converting to actual binary\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n\n case \"none\":\n return { ok: true, value: \"\" };\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${outFormat}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n}\n\n/**\n * Read binary data from a buffer\n */\nexport function readData(data: Uint8Array): Uint8Array {\n return data;\n}\n\n/**\n * Read string data from a buffer\n */\nexport function readString(data: Uint8Array): string {\n return new TextDecoder().decode(data);\n}\n","/**\n * Compose a dCBOR array from the provided elements\n * Equivalent to Rust's cmd/array.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborArray, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for array composition\n */\nexport interface ArrayCommandArgs {\n /** Each element is parsed as a dCBOR item in diagnostic notation */\n elements: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute array command\n */\nexport function execArray(args: ArrayCommandArgs): Result<string> {\n const result = composeDcborArray(args.elements);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for array command\n */\nexport function createArrayCommand(args: ArrayCommandArgs): Exec {\n return {\n exec: () => execArray(args),\n };\n}\n","/**\n * Default parsing and validation behavior\n * Equivalent to Rust's cmd/default.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type InputFormat, type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for default parsing behavior\n */\nexport interface DefaultCommandArgs {\n /** Input dCBOR in the format specified by `in`. Optional - reads from stdin if not provided */\n input?: string | undefined;\n /** The input format (default: diag) */\n in: InputFormat;\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute default command with a reader function for stdin\n */\nexport function execDefaultWithReader(\n args: DefaultCommandArgs,\n readString: () => string,\n readData: () => Uint8Array,\n): Result<string> {\n let cbor: Cbor;\n\n try {\n switch (args.in) {\n case \"diag\": {\n if (args.input !== undefined) {\n const result = parseDcborItem(args.input);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, args.input)),\n };\n }\n cbor = result.value;\n } else {\n const diag = readString();\n const result = parseDcborItem(diag);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, diag)),\n };\n }\n cbor = result.value;\n }\n break;\n }\n case \"hex\": {\n if (args.input !== undefined) {\n cbor = decodeCbor(hexToBytes(args.input));\n } else {\n const hexStr = readString().trim();\n cbor = decodeCbor(hexToBytes(hexStr));\n }\n break;\n }\n case \"bin\": {\n const data = readData();\n cbor = decodeCbor(data);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n return formatOutput(cbor, args.out, args.annotate);\n}\n\n/**\n * Execute default command (reads from stdin if input not provided)\n */\nexport function execDefault(args: DefaultCommandArgs, stdinContent?: string): Result<string> {\n return execDefaultWithReader(\n args,\n () => stdinContent ?? \"\",\n () => {\n if (stdinContent) {\n return new TextEncoder().encode(stdinContent);\n }\n return new Uint8Array(0);\n },\n );\n}\n\n/**\n * Create an Exec implementation for default command\n */\nexport function createDefaultCommand(args: DefaultCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execDefault(args, stdinContent),\n };\n}\n","/**\n * Compose a dCBOR map from the provided keys and values\n * Equivalent to Rust's cmd/map.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborMap, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for map composition\n */\nexport interface MapCommandArgs {\n /** Alternating keys and values parsed as dCBOR items in diagnostic notation */\n kvPairs: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute map command\n */\nexport function execMap(args: MapCommandArgs): Result<string> {\n const result = composeDcborMap(args.kvPairs);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for map command\n */\nexport function createMapCommand(args: MapCommandArgs): Exec {\n return {\n exec: () => execMap(args),\n };\n}\n","/**\n * Match dCBOR data against a pattern\n * Equivalent to Rust's cmd/match.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/switch-exhaustiveness-check */\n\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport {\n parse as parsePattern,\n pathsWithCaptures,\n formatPathsWithCaptures,\n FormatPathsOptsBuilder,\n type Error as PatternParseError,\n} from \"@bcts/dcbor-pattern\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\nimport type { InputFormat } from \"../format.js\";\n\n/**\n * Match output format options\n */\nexport type MatchOutputFormat = \"paths\" | \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Command arguments for match command\n */\nexport interface MatchCommandArgs {\n /** The pattern to match against */\n pattern: string;\n /** dCBOR input (hex, diag, or binary). If not provided, reads from stdin */\n input?: string | undefined;\n /** Input format (default: diag) */\n in: InputFormat;\n /** Output format (default: paths) */\n out: MatchOutputFormat;\n /** Disable indentation of path elements */\n noIndent: boolean;\n /** Show only the last element of each path */\n lastOnly: boolean;\n /** Add annotations to output */\n annotate: boolean;\n /** Include capture information in output */\n captures: boolean;\n}\n\n/**\n * Format a parse error with context\n */\nfunction formatPatternError(error: PatternParseError, patternStr: string): string {\n switch (error.type) {\n case \"UnrecognizedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n const end = Math.min(error.span.end, patternStr.length);\n const errorText = start < patternStr.length ? patternStr.slice(start, end) : \"<end of input>\";\n return `Failed to parse pattern at position ${start}..${end}: unrecognized token '${errorText}'\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"ExtraData\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern: extra data at position ${start}\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"UnexpectedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern at position ${start}: unexpected token\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n default:\n return `Failed to parse pattern: ${error.type}`;\n }\n}\n\n/**\n * Execute match command\n */\nexport function execMatch(args: MatchCommandArgs, stdinContent?: string): Result<string> {\n // Read input data\n let inputData: Uint8Array;\n if (args.input !== undefined) {\n inputData = new TextEncoder().encode(args.input);\n } else if (stdinContent !== undefined) {\n inputData = new TextEncoder().encode(stdinContent);\n } else {\n inputData = new Uint8Array(0);\n }\n\n // Parse input based on format\n let cbor: Cbor;\n try {\n switch (args.in) {\n case \"diag\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n const result = parseDcborItem(inputStr);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, inputStr)),\n };\n }\n cbor = result.value;\n break;\n }\n case \"hex\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n cbor = decodeCbor(hexToBytes(inputStr));\n break;\n }\n case \"bin\": {\n cbor = decodeCbor(inputData);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n // Parse pattern\n const patternResult = parsePattern(args.pattern);\n if (!patternResult.ok) {\n return {\n ok: false,\n error: errorMsg(formatPatternError(patternResult.error, args.pattern)),\n };\n }\n const pattern = patternResult.value;\n\n // Execute pattern matching\n const { paths, captures } = pathsWithCaptures(pattern, cbor);\n\n // Check for matches\n if (paths.length === 0) {\n return { ok: false, error: errorMsg(\"No match\") };\n }\n\n // Format output based on requested format\n switch (args.out) {\n case \"paths\": {\n // Build format options from command line arguments\n const formatOptions = FormatPathsOptsBuilder.new()\n .indent(!args.noIndent)\n .lastElementOnly(args.lastOnly)\n .build();\n\n // Show captures only if explicitly requested\n if (args.captures) {\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, captures, formatOptions),\n };\n } else {\n // Show paths without captures\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, new Map(), formatOptions),\n };\n }\n }\n\n case \"diag\":\n case \"hex\":\n case \"bin\": {\n // For data format outputs, extract the matched elements\n const outputFormat: OutputFormat = args.out;\n\n const elementsToOutput = args.lastOnly\n ? paths.map((path) => path[path.length - 1]).filter(Boolean)\n : paths.map((path) => path[0]).filter(Boolean);\n\n const results: string[] = [];\n for (const element of elementsToOutput) {\n const result = formatOutput(element, outputFormat, args.annotate);\n if (!result.ok) {\n return result;\n }\n results.push(result.value);\n }\n\n return { ok: true, value: results.join(\"\\n\") };\n }\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${args.out}`) };\n }\n}\n\n/**\n * Create an Exec implementation for match command\n */\nexport function createMatchCommand(args: MatchCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execMatch(args, stdinContent),\n };\n}\n","/**\n * Main run function for dcbor-cli\n * Equivalent to Rust's run function in main.rs\n */\n\nimport { registerTags, errorToString } from \"@bcts/dcbor\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport { execArray, execDefault, execMap, execMatch, type MatchOutputFormat } from \"./cmd/index.js\";\n\n/**\n * Command type discriminator\n */\nexport type Command =\n | { type: \"array\"; elements: string[]; out: OutputFormat; annotate: boolean }\n | { type: \"map\"; kvPairs: string[]; out: OutputFormat; annotate: boolean }\n | {\n type: \"match\";\n pattern: string;\n input?: string | undefined;\n in: InputFormat;\n out: MatchOutputFormat;\n noIndent: boolean;\n lastOnly: boolean;\n annotate: boolean;\n captures: boolean;\n }\n | {\n type: \"default\";\n input?: string | undefined;\n in: InputFormat;\n out: OutputFormat;\n annotate: boolean;\n };\n\nexport interface RunOptions {\n command: Command;\n stdinContent?: string | undefined;\n}\n\nexport interface RunResult {\n output: string;\n isBinary: boolean;\n}\n\n/**\n * Main execution function\n * Equivalent to Rust's run<I, T, R, W> function\n */\nexport function run(\n options: RunOptions,\n): { ok: true; value: RunResult } | { ok: false; error: Error } {\n // Register BC components tags\n registerTags();\n\n const { command, stdinContent } = options;\n\n let output: string;\n let isBinary = false;\n\n switch (command.type) {\n case \"array\": {\n const result = execArray({\n elements: command.elements,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"map\": {\n const result = execMap({\n kvPairs: command.kvPairs,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"match\": {\n const result = execMatch(\n {\n pattern: command.pattern,\n input: command.input,\n in: command.in,\n out: command.out,\n noIndent: command.noIndent,\n lastOnly: command.lastOnly,\n annotate: command.annotate,\n captures: command.captures,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"default\": {\n const result = execDefault(\n {\n input: command.input,\n in: command.in,\n out: command.out,\n annotate: command.annotate,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n default:\n return { ok: false, error: new Error(\"Unknown command type\") };\n }\n\n return { ok: true, value: { output, isBinary } };\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,aACd,MACA,WACA,UACgB;AAChB,KAAI;AACF,UAAQ,WAAR;GACE,KAAK,OAEH,KAAI,SACF,QAAO;IAAE,IAAI;IAAM,sCAAqB,MAAM;KAAE,UAAU;KAAM,MAAM;KAAM,CAAC;IAAE;OAE/E,QAAO;IAAE,IAAI;IAAM,sCAAqB,MAAM,EAAE,MAAM,MAAM,CAAC;IAAE;GAGnE,KAAK,MACH,KAAI,SACF,QAAO;IAAE,IA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AO;AAChB,cAAW,QAAQ,QAAQ;AAC3B;;EAGF,QACE,QAAO;GAAE,IAAI;GAAO,uBAAO,IAAI,MAAM,uBAAuB;GAAE;;AAGlE,QAAO;EAAE,IAAI;EAAM,OAAO;GAAE;GAAQ;GAAU;EAAE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-GBL_cAOh.mjs","names":["parsePattern"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts"],"sourcesContent":["/**\n * Format utilities for dcbor-cli\n * Contains InputFormat, OutputFormat enums and formatOutput function\n * Equivalent to the format-related code in Rust's main.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n\nimport {\n type Cbor,\n type Result,\n diagnosticOpt,\n hexOpt,\n bytesToHex,\n cborData,\n errorMsg,\n} from \"@bcts/dcbor\";\n\n/**\n * Input format options\n */\nexport type InputFormat = \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Output format options\n */\nexport type OutputFormat = \"diag\" | \"hex\" | \"bin\" | \"none\";\n\n/**\n * Format CBOR output in the specified format\n * Equivalent to Rust's format_output function\n */\nexport function formatOutput(\n cbor: Cbor,\n outFormat: OutputFormat,\n annotate: boolean,\n): Result<string> {\n try {\n switch (outFormat) {\n case \"diag\":\n // Use flat: true for compact single-line output (matching Rust CLI behavior)\n if (annotate) {\n return { ok: true, value: diagnosticOpt(cbor, { annotate: true, flat: true }) };\n } else {\n return { ok: true, value: diagnosticOpt(cbor, { flat: true }) };\n }\n\n case \"hex\":\n if (annotate) {\n return { ok: true, value: hexOpt(cbor, { annotate: true }) };\n } else {\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n }\n\n case \"bin\":\n // For binary output, return hex representation\n // The caller will handle converting to actual binary\n return { ok: true, value: bytesToHex(cborData(cbor)) };\n\n case \"none\":\n return { ok: true, value: \"\" };\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${outFormat}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n}\n\n/**\n * Read binary data from a buffer\n */\nexport function readData(data: Uint8Array): Uint8Array {\n return data;\n}\n\n/**\n * Read string data from a buffer\n */\nexport function readString(data: Uint8Array): string {\n return new TextDecoder().decode(data);\n}\n","/**\n * Compose a dCBOR array from the provided elements\n * Equivalent to Rust's cmd/array.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborArray, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for array composition\n */\nexport interface ArrayCommandArgs {\n /** Each element is parsed as a dCBOR item in diagnostic notation */\n elements: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute array command\n */\nexport function execArray(args: ArrayCommandArgs): Result<string> {\n const result = composeDcborArray(args.elements);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for array command\n */\nexport function createArrayCommand(args: ArrayCommandArgs): Exec {\n return {\n exec: () => execArray(args),\n };\n}\n","/**\n * Default parsing and validation behavior\n * Equivalent to Rust's cmd/default.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type InputFormat, type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for default parsing behavior\n */\nexport interface DefaultCommandArgs {\n /** Input dCBOR in the format specified by `in`. Optional - reads from stdin if not provided */\n input?: string | undefined;\n /** The input format (default: diag) */\n in: InputFormat;\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute default command with a reader function for stdin\n */\nexport function execDefaultWithReader(\n args: DefaultCommandArgs,\n readString: () => string,\n readData: () => Uint8Array,\n): Result<string> {\n let cbor: Cbor;\n\n try {\n switch (args.in) {\n case \"diag\": {\n if (args.input !== undefined) {\n const result = parseDcborItem(args.input);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, args.input)),\n };\n }\n cbor = result.value;\n } else {\n const diag = readString();\n const result = parseDcborItem(diag);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, diag)),\n };\n }\n cbor = result.value;\n }\n break;\n }\n case \"hex\": {\n if (args.input !== undefined) {\n cbor = decodeCbor(hexToBytes(args.input));\n } else {\n const hexStr = readString().trim();\n cbor = decodeCbor(hexToBytes(hexStr));\n }\n break;\n }\n case \"bin\": {\n const data = readData();\n cbor = decodeCbor(data);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n return formatOutput(cbor, args.out, args.annotate);\n}\n\n/**\n * Execute default command (reads from stdin if input not provided)\n */\nexport function execDefault(args: DefaultCommandArgs, stdinContent?: string): Result<string> {\n return execDefaultWithReader(\n args,\n () => stdinContent ?? \"\",\n () => {\n if (stdinContent) {\n return new TextEncoder().encode(stdinContent);\n }\n return new Uint8Array(0);\n },\n );\n}\n\n/**\n * Create an Exec implementation for default command\n */\nexport function createDefaultCommand(args: DefaultCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execDefault(args, stdinContent),\n };\n}\n","/**\n * Compose a dCBOR map from the provided keys and values\n * Equivalent to Rust's cmd/map.rs\n */\n\nimport { type Result, errorMsg } from \"@bcts/dcbor\";\nimport { composeDcborMap, composeErrorMessage } from \"@bcts/dcbor-parse\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\n\n/**\n * Command arguments for map composition\n */\nexport interface MapCommandArgs {\n /** Alternating keys and values parsed as dCBOR items in diagnostic notation */\n kvPairs: string[];\n /** The output format (default: hex) */\n out: OutputFormat;\n /** Output with annotations */\n annotate: boolean;\n}\n\n/**\n * Execute map command\n */\nexport function execMap(args: MapCommandArgs): Result<string> {\n const result = composeDcborMap(args.kvPairs);\n if (!result.ok) {\n return { ok: false, error: errorMsg(composeErrorMessage(result.error)) };\n }\n return formatOutput(result.value, args.out, args.annotate);\n}\n\n/**\n * Create an Exec implementation for map command\n */\nexport function createMapCommand(args: MapCommandArgs): Exec {\n return {\n exec: () => execMap(args),\n };\n}\n","/**\n * Match dCBOR data against a pattern\n * Equivalent to Rust's cmd/match.rs\n */\n/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/switch-exhaustiveness-check */\n\nimport { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from \"@bcts/dcbor\";\nimport { parseDcborItem, fullErrorMessage } from \"@bcts/dcbor-parse\";\nimport {\n parse as parsePattern,\n pathsWithCaptures,\n formatPathsWithCaptures,\n FormatPathsOptsBuilder,\n type Error as PatternParseError,\n} from \"@bcts/dcbor-pattern\";\nimport type { Exec } from \"./index.js\";\nimport { type OutputFormat, formatOutput } from \"../format.js\";\nimport type { InputFormat } from \"../format.js\";\n\n/**\n * Match output format options\n */\nexport type MatchOutputFormat = \"paths\" | \"diag\" | \"hex\" | \"bin\";\n\n/**\n * Command arguments for match command\n */\nexport interface MatchCommandArgs {\n /** The pattern to match against */\n pattern: string;\n /** dCBOR input (hex, diag, or binary). If not provided, reads from stdin */\n input?: string | undefined;\n /** Input format (default: diag) */\n in: InputFormat;\n /** Output format (default: paths) */\n out: MatchOutputFormat;\n /** Disable indentation of path elements */\n noIndent: boolean;\n /** Show only the last element of each path */\n lastOnly: boolean;\n /** Add annotations to output */\n annotate: boolean;\n /** Include capture information in output */\n captures: boolean;\n}\n\n/**\n * Format a parse error with context\n */\nfunction formatPatternError(error: PatternParseError, patternStr: string): string {\n switch (error.type) {\n case \"UnrecognizedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n const end = Math.min(error.span.end, patternStr.length);\n const errorText = start < patternStr.length ? patternStr.slice(start, end) : \"<end of input>\";\n return `Failed to parse pattern at position ${start}..${end}: unrecognized token '${errorText}'\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"ExtraData\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern: extra data at position ${start}\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n case \"UnexpectedToken\": {\n const start = Math.min(error.span.start, patternStr.length);\n return `Failed to parse pattern at position ${start}: unexpected token\\nPattern: ${patternStr}\\n ${\" \".repeat(start)}^`;\n }\n\n default:\n return `Failed to parse pattern: ${error.type}`;\n }\n}\n\n/**\n * Execute match command\n */\nexport function execMatch(args: MatchCommandArgs, stdinContent?: string): Result<string> {\n // Read input data\n let inputData: Uint8Array;\n if (args.input !== undefined) {\n inputData = new TextEncoder().encode(args.input);\n } else if (stdinContent !== undefined) {\n inputData = new TextEncoder().encode(stdinContent);\n } else {\n inputData = new Uint8Array(0);\n }\n\n // Parse input based on format\n let cbor: Cbor;\n try {\n switch (args.in) {\n case \"diag\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n const result = parseDcborItem(inputStr);\n if (!result.ok) {\n return {\n ok: false,\n error: errorMsg(fullErrorMessage(result.error, inputStr)),\n };\n }\n cbor = result.value;\n break;\n }\n case \"hex\": {\n const inputStr = new TextDecoder().decode(inputData).trim();\n cbor = decodeCbor(hexToBytes(inputStr));\n break;\n }\n case \"bin\": {\n cbor = decodeCbor(inputData);\n break;\n }\n default:\n return { ok: false, error: errorMsg(`Unknown input format: ${args.in}`) };\n }\n } catch (e) {\n return { ok: false, error: errorMsg(e instanceof Error ? e.message : String(e)) };\n }\n\n // Parse pattern\n const patternResult = parsePattern(args.pattern);\n if (!patternResult.ok) {\n return {\n ok: false,\n error: errorMsg(formatPatternError(patternResult.error, args.pattern)),\n };\n }\n const pattern = patternResult.value;\n\n // Execute pattern matching\n const { paths, captures } = pathsWithCaptures(pattern, cbor);\n\n // Check for matches\n if (paths.length === 0) {\n return { ok: false, error: errorMsg(\"No match\") };\n }\n\n // Format output based on requested format\n switch (args.out) {\n case \"paths\": {\n // Build format options from command line arguments\n const formatOptions = FormatPathsOptsBuilder.new()\n .indent(!args.noIndent)\n .lastElementOnly(args.lastOnly)\n .build();\n\n // Show captures only if explicitly requested\n if (args.captures) {\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, captures, formatOptions),\n };\n } else {\n // Show paths without captures\n return {\n ok: true,\n value: formatPathsWithCaptures(paths, new Map(), formatOptions),\n };\n }\n }\n\n case \"diag\":\n case \"hex\":\n case \"bin\": {\n // For data format outputs, extract the matched elements\n const outputFormat: OutputFormat = args.out;\n\n const elementsToOutput = args.lastOnly\n ? paths.map((path) => path[path.length - 1]).filter(Boolean)\n : paths.map((path) => path[0]).filter(Boolean);\n\n const results: string[] = [];\n for (const element of elementsToOutput) {\n const result = formatOutput(element, outputFormat, args.annotate);\n if (!result.ok) {\n return result;\n }\n results.push(result.value);\n }\n\n return { ok: true, value: results.join(\"\\n\") };\n }\n\n default:\n return { ok: false, error: errorMsg(`Unknown output format: ${args.out}`) };\n }\n}\n\n/**\n * Create an Exec implementation for match command\n */\nexport function createMatchCommand(args: MatchCommandArgs, stdinContent?: string): Exec {\n return {\n exec: () => execMatch(args, stdinContent),\n };\n}\n","/**\n * Main run function for dcbor-cli\n * Equivalent to Rust's run function in main.rs\n */\n\nimport { registerTags, errorToString } from \"@bcts/dcbor\";\nimport type { InputFormat, OutputFormat } from \"./format.js\";\nimport { execArray, execDefault, execMap, execMatch, type MatchOutputFormat } from \"./cmd/index.js\";\n\n/**\n * Command type discriminator\n */\nexport type Command =\n | { type: \"array\"; elements: string[]; out: OutputFormat; annotate: boolean }\n | { type: \"map\"; kvPairs: string[]; out: OutputFormat; annotate: boolean }\n | {\n type: \"match\";\n pattern: string;\n input?: string | undefined;\n in: InputFormat;\n out: MatchOutputFormat;\n noIndent: boolean;\n lastOnly: boolean;\n annotate: boolean;\n captures: boolean;\n }\n | {\n type: \"default\";\n input?: string | undefined;\n in: InputFormat;\n out: OutputFormat;\n annotate: boolean;\n };\n\nexport interface RunOptions {\n command: Command;\n stdinContent?: string | undefined;\n}\n\nexport interface RunResult {\n output: string;\n isBinary: boolean;\n}\n\n/**\n * Main execution function\n * Equivalent to Rust's run<I, T, R, W> function\n */\nexport function run(\n options: RunOptions,\n): { ok: true; value: RunResult } | { ok: false; error: Error } {\n // Register BC components tags\n registerTags();\n\n const { command, stdinContent } = options;\n\n let output: string;\n let isBinary = false;\n\n switch (command.type) {\n case \"array\": {\n const result = execArray({\n elements: command.elements,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"map\": {\n const result = execMap({\n kvPairs: command.kvPairs,\n out: command.out,\n annotate: command.annotate,\n });\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"match\": {\n const result = execMatch(\n {\n pattern: command.pattern,\n input: command.input,\n in: command.in,\n out: command.out,\n noIndent: command.noIndent,\n lastOnly: command.lastOnly,\n annotate: command.annotate,\n captures: command.captures,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n case \"default\": {\n const result = execDefault(\n {\n input: command.input,\n in: command.in,\n out: command.out,\n annotate: command.annotate,\n },\n stdinContent,\n );\n if (!result.ok) {\n return { ok: false, error: new Error(errorToString(result.error)) };\n }\n output = result.value;\n isBinary = command.out === \"bin\";\n break;\n }\n\n default:\n return { ok: false, error: new Error(\"Unknown command type\") };\n }\n\n return {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