@bcts/dcbor-cli 1.0.0-alpha.13 → 1.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/src-Ce085uR8.mjs.map +1 -1
- package/dist/src-M5HM-SCU.cjs.map +1 -1
- package/package.json +7 -7
- package/src/cli.ts +1 -1
- package/src/cmd/default.ts +1 -1
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","names":["Command","VERSION","Option","stdinContent: string | undefined","run","chunks: Buffer[]"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/* eslint-disable
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["Command","VERSION","Option","stdinContent: string | undefined","run","chunks: Buffer[]"],"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,oBAAQ;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,IAAIC;AACJ,KAAI,UAAU,UAAa,QAAQ,OAAO,MACxC,gBAAe,MAAM,WAAW;UACvB,QAAQ,OAAO,MACxB,gBAAe,MAAM,WAAW;CAWlC,MAAM,SAASC,gBAAI;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,IAAIF,iBAAO,sBAAsB,oBAAoB,CAClD,QAAQ;CAAC;CAAQ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AAe,uCAAuC,CAC7D,OAAO,eAAe,0CAA0C,CAChE,OAAO,cAAc,4BAA4B,CACjD,OAAO,cAAc,wCAAwC,CAC7D,OACC,OACE,SACA,OACA,YAQG;CAEH,IAAIC;AACJ,KAAI,UAAU,OACZ,gBAAe,MAAM,WAAW;CAelC,MAAM,SAASC,gBAAI;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,MAAMC,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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":["stdinContent: string | undefined","chunks: Buffer[]"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/* eslint-disable
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["stdinContent: string | undefined","chunks: Buffer[]"],"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,CAC/B,QAAQ,OAAO,CACnB,CACA,UACC,IAAI,OAAO,sBAAsB,oBAAoB,CAClD,QAAQ;CAAC;CAAQ;CAAO;CAAO;CAAO,CAAC,CACvC,QAAQ,MAAM,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QAAO;CAGT,MAAMC,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-Ce085uR8.mjs","names":["cbor: Cbor","readString","readData","inputData: Uint8Array","cbor: Cbor","parsePattern","outputFormat: OutputFormat","results: string[]","output: string"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts","../src/index.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, @typescript-eslint/strict-boolean-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","/**\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":";;;;;;;;;;;;;;AA+BA,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,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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;;;;;;;;;;;;AC5HlD,MAAa,UAAU"}
|
|
1
|
+
{"version":3,"file":"src-Ce085uR8.mjs","names":["cbor: Cbor","readString","readData","inputData: Uint8Array","cbor: Cbor","parsePattern","outputFormat: OutputFormat","results: string[]","output: string"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts","../src/index.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","/**\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":";;;;;;;;;;;;;;AA+BA,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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,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;;;;;;;;;;;;AC5HlD,MAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-M5HM-SCU.cjs","names":["cbor: Cbor","readString","readData","inputData: Uint8Array","cbor: Cbor","FormatPathsOptsBuilder","outputFormat: OutputFormat","results: string[]","output: string"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts","../src/index.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, @typescript-eslint/strict-boolean-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","/**\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":";;;;;;;;;;;;;;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;IA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E;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;;;;;;;;;;;;AC5HlD,MAAa,UAAU"}
|
|
1
|
+
{"version":3,"file":"src-M5HM-SCU.cjs","names":["cbor: Cbor","readString","readData","inputData: Uint8Array","cbor: Cbor","FormatPathsOptsBuilder","outputFormat: OutputFormat","results: string[]","output: string"],"sources":["../src/format.ts","../src/cmd/array.ts","../src/cmd/default.ts","../src/cmd/map.ts","../src/cmd/match.ts","../src/run.ts","../src/index.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","/**\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":";;;;;;;;;;;;;;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,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;I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AAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bcts/dcbor-cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Command line parser/validator for deterministic CBOR (dCBOR)",
|
|
6
6
|
"license": "BSD-2-Clause-Patent",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"node": ">=18.0.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@bcts/eslint": "
|
|
72
|
-
"@bcts/tsconfig": "
|
|
71
|
+
"@bcts/eslint": "^0.1.0",
|
|
72
|
+
"@bcts/tsconfig": "^0.1.0",
|
|
73
73
|
"@types/node": "^25.0.3",
|
|
74
74
|
"eslint": "^9.39.2",
|
|
75
75
|
"tsdown": "^0.18.3",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
"vitest": "^4.0.16"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@bcts/components": "
|
|
82
|
-
"@bcts/dcbor": "
|
|
83
|
-
"@bcts/dcbor-parse": "
|
|
84
|
-
"@bcts/dcbor-pattern": "
|
|
81
|
+
"@bcts/components": "^1.0.0-alpha.14",
|
|
82
|
+
"@bcts/dcbor": "^1.0.0-alpha.14",
|
|
83
|
+
"@bcts/dcbor-parse": "^1.0.0-alpha.14",
|
|
84
|
+
"@bcts/dcbor-pattern": "^1.0.0-alpha.14",
|
|
85
85
|
"commander": "^14.0.2"
|
|
86
86
|
}
|
|
87
87
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
3
|
/**
|
|
4
4
|
* dcbor CLI - Command line parser/validator for deterministic CBOR (dCBOR)
|
|
5
5
|
*
|
package/src/cmd/default.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Default parsing and validation behavior
|
|
3
3
|
* Equivalent to Rust's cmd/default.rs
|
|
4
4
|
*/
|
|
5
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions
|
|
5
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
6
6
|
|
|
7
7
|
import { type Cbor, type Result, decodeCbor, hexToBytes, errorMsg } from "@bcts/dcbor";
|
|
8
8
|
import { parseDcborItem, fullErrorMessage } from "@bcts/dcbor-parse";
|