@bcts/provenance-mark-cli 1.0.0-alpha.13
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 +48 -0
- package/README.md +177 -0
- package/dist/cli.cjs +129 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +130 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +332 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +332 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/src-Bu1tG89l.mjs +705 -0
- package/dist/src-Bu1tG89l.mjs.map +1 -0
- package/dist/src-XNNUeTzh.cjs +889 -0
- package/dist/src-XNNUeTzh.cjs.map +1 -0
- package/package.json +88 -0
- package/src/cli.ts +243 -0
- package/src/cmd/index.ts +12 -0
- package/src/cmd/info.ts +147 -0
- package/src/cmd/new.ts +235 -0
- package/src/cmd/next.ts +119 -0
- package/src/cmd/print.ts +108 -0
- package/src/cmd/seed.ts +114 -0
- package/src/cmd/validate.ts +288 -0
- package/src/exec.ts +23 -0
- package/src/index.ts +55 -0
- package/src/utils.ts +130 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Copyright © 2023 Blockchain Commons, LLC
|
|
2
|
+
Copyright © 2025 Leonardo Amoroso Custodio
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
Subject to the terms and conditions of this license, each copyright holder and
|
|
15
|
+
contributor hereby grants to those receiving rights under this license a
|
|
16
|
+
perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
17
|
+
(except for failure to satisfy the conditions of this license) patent license to
|
|
18
|
+
make, have made, use, offer to sell, sell, import, and otherwise transfer this
|
|
19
|
+
software, where such license applies only to those patent claims, already
|
|
20
|
+
acquired or hereafter acquired, licensable by such copyright holder or
|
|
21
|
+
contributor that are necessarily infringed by:
|
|
22
|
+
|
|
23
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and
|
|
24
|
+
non-copyrightable additions of contributors, in source or binary form)
|
|
25
|
+
alone; or
|
|
26
|
+
|
|
27
|
+
(b) combination of their Contribution(s) with the work of authorship to
|
|
28
|
+
which such Contribution(s) was added by such copyright holder or
|
|
29
|
+
contributor, if, at the time the Contribution is added, such addition causes
|
|
30
|
+
such combination to be necessarily infringed. The patent license shall not
|
|
31
|
+
apply to any other combinations which include the Contribution.
|
|
32
|
+
|
|
33
|
+
Except as expressly stated above, no rights or licenses from any copyright
|
|
34
|
+
holder or contributor is granted under this license, whether expressly, by
|
|
35
|
+
implication, estoppel or otherwise.
|
|
36
|
+
|
|
37
|
+
DISCLAIMER
|
|
38
|
+
|
|
39
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
40
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
41
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
42
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
|
|
43
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
44
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
45
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
46
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
47
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
48
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Blockchain Commons Provenance Mark CLI (TypeScript)
|
|
2
|
+
|
|
3
|
+
> Disclaimer: This package is under active development and APIs may change.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
`@bcts/provenance-mark-cli` is a command line tool for creating and managing [Provenance Mark](https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2025-001-provenance-mark.md) chains.
|
|
8
|
+
|
|
9
|
+
Provenance Marks are cryptographically-secured markers that establish authenticity and provenance of digital works. They form chains where each mark references the previous one, creating an unforgeable timeline.
|
|
10
|
+
|
|
11
|
+
Features:
|
|
12
|
+
- Create new provenance mark chains with a genesis mark
|
|
13
|
+
- Add new marks to existing chains
|
|
14
|
+
- Print marks in publishable formats (Markdown, UR, JSON)
|
|
15
|
+
- Validate provenance mark chains for integrity
|
|
16
|
+
- Support for multiple resolution levels (low, medium, quartile, high)
|
|
17
|
+
|
|
18
|
+
## Rust Reference Implementation
|
|
19
|
+
|
|
20
|
+
This TypeScript implementation is based on [provenance-mark-cli-rust](https://github.com/BlockchainCommons/provenance-mark-cli-rust) **v0.6.0** ([commit](https://github.com/BlockchainCommons/provenance-mark-cli-rust/tree/2efd567c78ca0d457f2bc10263917d4829e422f9)).
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Install globally
|
|
26
|
+
bun add -g @bcts/provenance-mark-cli
|
|
27
|
+
|
|
28
|
+
# Or run directly with bunx
|
|
29
|
+
bunx @bcts/provenance-mark-cli --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Creating a New Chain
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Create a new provenance mark chain
|
|
38
|
+
provenance new mychain
|
|
39
|
+
|
|
40
|
+
# Create with a specific resolution
|
|
41
|
+
provenance new mychain --resolution high
|
|
42
|
+
|
|
43
|
+
# Create with a custom comment
|
|
44
|
+
provenance new mychain --comment "Genesis mark for my project"
|
|
45
|
+
|
|
46
|
+
# Create with a specific seed (base64)
|
|
47
|
+
provenance new mychain --seed "base64encodedSeed=="
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Output:
|
|
51
|
+
```
|
|
52
|
+
Provenance mark chain created at: /path/to/mychain
|
|
53
|
+
|
|
54
|
+
Mark 0 written to: /path/to/mychain/marks/mark-0.json
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
2025-01-27T21:59:52Z
|
|
59
|
+
|
|
60
|
+
#### ur:provenance/lfaohdft...
|
|
61
|
+
|
|
62
|
+
#### `🅟 PLAY WASP FLUX SWAN`
|
|
63
|
+
|
|
64
|
+
🅟 💎 🦄 🍓 🧢
|
|
65
|
+
|
|
66
|
+
Genesis mark.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Adding New Marks
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Add next mark to the chain
|
|
73
|
+
provenance next mychain --comment "New release v1.0"
|
|
74
|
+
|
|
75
|
+
# Output as UR only
|
|
76
|
+
provenance next mychain --format ur --quiet
|
|
77
|
+
|
|
78
|
+
# Output as JSON
|
|
79
|
+
provenance next mychain --format json
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Printing Marks
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Print all marks in the chain
|
|
86
|
+
provenance print mychain
|
|
87
|
+
|
|
88
|
+
# Print specific range
|
|
89
|
+
provenance print mychain --start 0 --end 5
|
|
90
|
+
|
|
91
|
+
# Print only the genesis mark
|
|
92
|
+
provenance print mychain --start 0 --end 0
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Validating Marks
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Validate a chain directory
|
|
99
|
+
provenance validate --dir mychain
|
|
100
|
+
|
|
101
|
+
# Validate specific URs
|
|
102
|
+
provenance validate ur:provenance/... ur:provenance/...
|
|
103
|
+
|
|
104
|
+
# Validate with warnings instead of errors
|
|
105
|
+
provenance validate --warn --dir mychain
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Directory Structure
|
|
109
|
+
|
|
110
|
+
When you create a new chain, the following structure is created:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
mychain/
|
|
114
|
+
├── generator.json # Chain state (KEEP SECRET!)
|
|
115
|
+
└── marks/
|
|
116
|
+
├── mark-0.json # Genesis mark
|
|
117
|
+
├── mark-1.json # Second mark
|
|
118
|
+
└── ...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Important:** The `generator.json` file contains the seed and must be kept secret. If compromised, an attacker could forge marks in your chain.
|
|
122
|
+
|
|
123
|
+
## Command Line Reference
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Usage: provenance [options] [command]
|
|
127
|
+
|
|
128
|
+
Commands:
|
|
129
|
+
new <dir> Create a new provenance mark chain
|
|
130
|
+
next <dir> Generate the next mark in a chain
|
|
131
|
+
print <dir> Print marks from a chain
|
|
132
|
+
validate Validate provenance marks
|
|
133
|
+
|
|
134
|
+
new Options:
|
|
135
|
+
--seed <base64> Seed for the chain (default: random)
|
|
136
|
+
--resolution <level> Resolution: low, medium, quartile, high (default: quartile)
|
|
137
|
+
--comment <text> Comment for genesis mark
|
|
138
|
+
|
|
139
|
+
next Options:
|
|
140
|
+
--comment <text> Comment for the new mark
|
|
141
|
+
--format <fmt> Output format: markdown, ur, json (default: markdown)
|
|
142
|
+
--quiet Suppress status messages
|
|
143
|
+
|
|
144
|
+
print Options:
|
|
145
|
+
--start <n> First mark to print (default: 0)
|
|
146
|
+
--end <n> Last mark to print (default: last)
|
|
147
|
+
|
|
148
|
+
validate Options:
|
|
149
|
+
--dir <path> Validate all marks in directory
|
|
150
|
+
--warn Warn instead of error on issues
|
|
151
|
+
|
|
152
|
+
Global Options:
|
|
153
|
+
-h, --help Display help
|
|
154
|
+
-V, --version Display version
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Mark Formats
|
|
158
|
+
|
|
159
|
+
Each mark includes:
|
|
160
|
+
- **UR**: Complete data structure in Uniform Resource format
|
|
161
|
+
- **Bytewords**: Human-readable identifier (e.g., `🅟 PLAY WASP FLUX SWAN`)
|
|
162
|
+
- **Bytemoji**: Emoji identifier (e.g., `🅟 💎 🦄 🍓 🧢`)
|
|
163
|
+
- **Comment**: Optional descriptive text
|
|
164
|
+
|
|
165
|
+
## Dependencies
|
|
166
|
+
|
|
167
|
+
- `@bcts/provenance-mark` - Provenance mark core
|
|
168
|
+
- `@bcts/dcbor` - dCBOR encoding
|
|
169
|
+
- `@bcts/envelope` - Gordian Envelope support
|
|
170
|
+
- `@bcts/uniform-resources` - UR encoding
|
|
171
|
+
- `@bcts/components` - Shared components
|
|
172
|
+
- `@bcts/known-values` - Known value registry
|
|
173
|
+
- `@bcts/tags` - CBOR tag registry
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
BSD-2-Clause-Patent
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_src = require('./src-XNNUeTzh.cjs');
|
|
3
|
+
let commander = require("commander");
|
|
4
|
+
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
/**
|
|
7
|
+
* provenance CLI - 1:1 port of main.rs
|
|
8
|
+
*
|
|
9
|
+
* Command line tool for creating and managing Provenance Marks.
|
|
10
|
+
*/
|
|
11
|
+
const program = new commander.Command();
|
|
12
|
+
program.name("provenance").description("A tool for managing provenance mark chains and generating provenance marks.").version(require_src.VERSION);
|
|
13
|
+
program.command("new").description("Initialize a directory with a new provenance mark chain.").argument("<path>", "Path to directory to be created. Must not already exist.").option("-s, --seed <seed>", "A seed to use for the provenance mark chain (base64, hex, or ur:seed). If not supplied, a random seed is generated.").addOption(new commander.Option("-r, --resolution <level>", "The resolution of the provenance mark chain.").choices([
|
|
14
|
+
"low",
|
|
15
|
+
"medium",
|
|
16
|
+
"quartile",
|
|
17
|
+
"high"
|
|
18
|
+
]).default("quartile")).option("-c, --comment <text>", "A comment to be included for the genesis mark.", "Genesis mark.").option("-d, --date <date>", "The date of the genesis mark. If not supplied, the current date is used.").option("-q, --quiet", "Suppress informational status output on stderr/stdout.", false).addOption(new commander.Option("--format <format>", "Output format for the creation summary.").choices([
|
|
19
|
+
"markdown",
|
|
20
|
+
"ur",
|
|
21
|
+
"json"
|
|
22
|
+
]).default("markdown")).option("--info <payload>", "Hex-encoded dCBOR or UR payload to embed in the mark's info field.").option("--info-tag <tag>", "CBOR tag value to associate with an unknown UR type.").action((pathArg, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const args = require_src.defaultNewCommandArgs();
|
|
25
|
+
args.path = pathArg;
|
|
26
|
+
args.resolution = require_src.parseResolution(options.resolution);
|
|
27
|
+
args.comment = options.comment;
|
|
28
|
+
args.quiet = options.quiet;
|
|
29
|
+
args.format = require_src.parseOutputFormat(options.format);
|
|
30
|
+
if (options.seed !== void 0) args.seed = require_src.parseSeed(options.seed);
|
|
31
|
+
if (options.date !== void 0) args.date = parseDate(options.date);
|
|
32
|
+
args.info = {
|
|
33
|
+
info: options.info,
|
|
34
|
+
infoTag: options.infoTag !== void 0 ? parseInt(options.infoTag, 10) : void 0
|
|
35
|
+
};
|
|
36
|
+
const output = new require_src.NewCommand(args).exec();
|
|
37
|
+
if (output !== "") console.log(output);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
40
|
+
console.error(`Error: ${message}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
program.command("next").description("Generate the next provenance mark in a chain.").argument("<path>", "Path to the chain's directory. Must already exist.").option("-c, --comment <text>", "A comment to be included for the mark.", "Blank.").option("-d, --date <date>", "The date of the next mark. If not supplied, the current date is used.").option("-q, --quiet", "Suppress informational status output on stderr/stdout.", false).addOption(new commander.Option("--format <format>", "Output format for the mark.").choices([
|
|
45
|
+
"markdown",
|
|
46
|
+
"ur",
|
|
47
|
+
"json"
|
|
48
|
+
]).default("markdown")).option("--info <payload>", "Hex-encoded dCBOR or UR payload to embed in the mark's info field.").option("--info-tag <tag>", "CBOR tag value to associate with an unknown UR type.").action((pathArg, options) => {
|
|
49
|
+
try {
|
|
50
|
+
const args = require_src.defaultNextCommandArgs();
|
|
51
|
+
args.path = pathArg;
|
|
52
|
+
args.comment = options.comment;
|
|
53
|
+
args.quiet = options.quiet;
|
|
54
|
+
args.format = require_src.parseOutputFormat(options.format);
|
|
55
|
+
if (options.date !== void 0) args.date = parseDate(options.date);
|
|
56
|
+
args.info = {
|
|
57
|
+
info: options.info,
|
|
58
|
+
infoTag: options.infoTag !== void 0 ? parseInt(options.infoTag, 10) : void 0
|
|
59
|
+
};
|
|
60
|
+
const output = new require_src.NextCommand(args).exec();
|
|
61
|
+
if (output !== "") console.log(output);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
64
|
+
console.error(`Error: ${message}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
program.command("print").description("Prints provenance marks in a chain.").argument("<path>", "Path to the chain's directory. Must already exist.").option("-s, --start <n>", "The sequence number of the first mark to print. If not supplied, the first mark (genesis mark) is used.", "0").option("-e, --end <n>", "The sequence number of the last mark to print. If not supplied, the last mark in the chain is used.").addOption(new commander.Option("--format <format>", "Output format for the rendered marks.").choices([
|
|
69
|
+
"markdown",
|
|
70
|
+
"ur",
|
|
71
|
+
"json"
|
|
72
|
+
]).default("markdown")).action((pathArg, options) => {
|
|
73
|
+
try {
|
|
74
|
+
const args = require_src.defaultPrintCommandArgs();
|
|
75
|
+
args.path = pathArg;
|
|
76
|
+
args.start = parseInt(options.start, 10);
|
|
77
|
+
args.format = require_src.parseOutputFormat(options.format);
|
|
78
|
+
if (options.end !== void 0) args.end = parseInt(options.end, 10);
|
|
79
|
+
const output = new require_src.PrintCommand(args).exec();
|
|
80
|
+
if (output !== "") console.log(output);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
83
|
+
console.error(`Error: ${message}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
program.command("validate").description("Validate one or more provenance marks.").argument("[marks...]", "One or more provenance mark URs to validate.").option("-d, --dir <path>", "Path to a chain directory containing marks to validate.").option("-w, --warn", "Report issues as warnings without failing.", false).addOption(new commander.Option("--format <format>", "Output format for the validation report.").choices([
|
|
88
|
+
"text",
|
|
89
|
+
"json-compact",
|
|
90
|
+
"json-pretty"
|
|
91
|
+
]).default("text")).action((marksArg, options) => {
|
|
92
|
+
try {
|
|
93
|
+
if (marksArg.length === 0 && options.dir === void 0) {
|
|
94
|
+
console.error("Error: Either provide marks to validate or use --dir to validate marks from a directory.");
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
if (marksArg.length > 0 && options.dir !== void 0) {
|
|
98
|
+
console.error("Error: Cannot provide both marks and --dir.");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
const args = require_src.defaultValidateCommandArgs();
|
|
102
|
+
args.marks = marksArg;
|
|
103
|
+
args.dir = options.dir;
|
|
104
|
+
args.warn = options.warn;
|
|
105
|
+
args.format = require_src.parseValidateFormat(options.format);
|
|
106
|
+
const output = new require_src.ValidateCommand(args).exec();
|
|
107
|
+
if (output !== "") console.log(output);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
110
|
+
console.error(`Error: ${message}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* Parse a date string.
|
|
116
|
+
*
|
|
117
|
+
* Supports ISO 8601 formats like:
|
|
118
|
+
* - 2023-02-08
|
|
119
|
+
* - 2023-02-08T15:30:45Z
|
|
120
|
+
*/
|
|
121
|
+
function parseDate(dateStr) {
|
|
122
|
+
const date = new Date(dateStr);
|
|
123
|
+
if (isNaN(date.getTime())) throw new Error(`Invalid date: ${dateStr}`);
|
|
124
|
+
return date;
|
|
125
|
+
}
|
|
126
|
+
program.parse();
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["Command","VERSION","Option","defaultNewCommandArgs","parseResolution","parseOutputFormat","parseSeed","NewCommand","defaultNextCommandArgs","NextCommand","defaultPrintCommandArgs","PrintCommand","defaultValidateCommandArgs","parseValidateFormat","ValidateCommand"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * provenance CLI - 1:1 port of main.rs\n *\n * Command line tool for creating and managing Provenance Marks.\n */\n\n/* eslint-disable no-console, no-undef, no-restricted-globals, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */\n\nimport { Command, Option } from \"commander\";\nimport { VERSION } from \"./index.js\";\nimport {\n NewCommand,\n defaultNewCommandArgs,\n parseResolution,\n parseOutputFormat,\n NextCommand,\n defaultNextCommandArgs,\n PrintCommand,\n defaultPrintCommandArgs,\n ValidateCommand,\n defaultValidateCommandArgs,\n parseValidateFormat,\n parseSeed,\n} from \"./cmd/index.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"provenance\")\n .description(\"A tool for managing provenance mark chains and generating provenance marks.\")\n .version(VERSION);\n\n// New command - Initialize a directory with a new provenance mark chain\nprogram\n .command(\"new\")\n .description(\"Initialize a directory with a new provenance mark chain.\")\n .argument(\"<path>\", \"Path to directory to be created. Must not already exist.\")\n .option(\n \"-s, --seed <seed>\",\n \"A seed to use for the provenance mark chain (base64, hex, or ur:seed). If not supplied, a random seed is generated.\",\n )\n .addOption(\n new Option(\"-r, --resolution <level>\", \"The resolution of the provenance mark chain.\")\n .choices([\"low\", \"medium\", \"quartile\", \"high\"])\n .default(\"quartile\"),\n )\n .option(\"-c, --comment <text>\", \"A comment to be included for the genesis mark.\", \"Genesis mark.\")\n .option(\n \"-d, --date <date>\",\n \"The date of the genesis mark. If not supplied, the current date is used.\",\n )\n .option(\"-q, --quiet\", \"Suppress informational status output on stderr/stdout.\", false)\n .addOption(\n new Option(\"--format <format>\", \"Output format for the creation summary.\")\n .choices([\"markdown\", \"ur\", \"json\"])\n .default(\"markdown\"),\n )\n .option(\"--info <payload>\", \"Hex-encoded dCBOR or UR payload to embed in the mark's info field.\")\n .option(\"--info-tag <tag>\", \"CBOR tag value to associate with an unknown UR type.\")\n .action((pathArg: string, options) => {\n try {\n const args = defaultNewCommandArgs();\n args.path = pathArg;\n args.resolution = parseResolution(options.resolution);\n args.comment = options.comment;\n args.quiet = options.quiet;\n args.format = parseOutputFormat(options.format);\n\n if (options.seed !== undefined) {\n args.seed = parseSeed(options.seed);\n }\n\n if (options.date !== undefined) {\n args.date = parseDate(options.date);\n }\n\n args.info = {\n info: options.info,\n infoTag: options.infoTag !== undefined ? parseInt(options.infoTag, 10) : undefined,\n };\n\n const cmd = new NewCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n// Next command - Generate the next provenance mark in a chain\nprogram\n .command(\"next\")\n .description(\"Generate the next provenance mark in a chain.\")\n .argument(\"<path>\", \"Path to the chain's directory. Must already exist.\")\n .option(\"-c, --comment <text>\", \"A comment to be included for the mark.\", \"Blank.\")\n .option(\n \"-d, --date <date>\",\n \"The date of the next mark. If not supplied, the current date is used.\",\n )\n .option(\"-q, --quiet\", \"Suppress informational status output on stderr/stdout.\", false)\n .addOption(\n new Option(\"--format <format>\", \"Output format for the mark.\")\n .choices([\"markdown\", \"ur\", \"json\"])\n .default(\"markdown\"),\n )\n .option(\"--info <payload>\", \"Hex-encoded dCBOR or UR payload to embed in the mark's info field.\")\n .option(\"--info-tag <tag>\", \"CBOR tag value to associate with an unknown UR type.\")\n .action((pathArg: string, options) => {\n try {\n const args = defaultNextCommandArgs();\n args.path = pathArg;\n args.comment = options.comment;\n args.quiet = options.quiet;\n args.format = parseOutputFormat(options.format);\n\n if (options.date !== undefined) {\n args.date = parseDate(options.date);\n }\n\n args.info = {\n info: options.info,\n infoTag: options.infoTag !== undefined ? parseInt(options.infoTag, 10) : undefined,\n };\n\n const cmd = new NextCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n// Print command - Print marks from a chain\nprogram\n .command(\"print\")\n .description(\"Prints provenance marks in a chain.\")\n .argument(\"<path>\", \"Path to the chain's directory. Must already exist.\")\n .option(\n \"-s, --start <n>\",\n \"The sequence number of the first mark to print. If not supplied, the first mark (genesis mark) is used.\",\n \"0\",\n )\n .option(\n \"-e, --end <n>\",\n \"The sequence number of the last mark to print. If not supplied, the last mark in the chain is used.\",\n )\n .addOption(\n new Option(\"--format <format>\", \"Output format for the rendered marks.\")\n .choices([\"markdown\", \"ur\", \"json\"])\n .default(\"markdown\"),\n )\n .action((pathArg: string, options) => {\n try {\n const args = defaultPrintCommandArgs();\n args.path = pathArg;\n args.start = parseInt(options.start, 10);\n args.format = parseOutputFormat(options.format);\n\n if (options.end !== undefined) {\n args.end = parseInt(options.end, 10);\n }\n\n const cmd = new PrintCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n// Validate command - Validate one or more provenance marks\nprogram\n .command(\"validate\")\n .description(\"Validate one or more provenance marks.\")\n .argument(\"[marks...]\", \"One or more provenance mark URs to validate.\")\n .option(\"-d, --dir <path>\", \"Path to a chain directory containing marks to validate.\")\n .option(\"-w, --warn\", \"Report issues as warnings without failing.\", false)\n .addOption(\n new Option(\"--format <format>\", \"Output format for the validation report.\")\n .choices([\"text\", \"json-compact\", \"json-pretty\"])\n .default(\"text\"),\n )\n .action((marksArg: string[], options) => {\n try {\n // Validate that either marks or dir is provided\n if (marksArg.length === 0 && options.dir === undefined) {\n console.error(\n \"Error: Either provide marks to validate or use --dir to validate marks from a directory.\",\n );\n process.exit(1);\n }\n if (marksArg.length > 0 && options.dir !== undefined) {\n console.error(\"Error: Cannot provide both marks and --dir.\");\n process.exit(1);\n }\n\n const args = defaultValidateCommandArgs();\n args.marks = marksArg;\n args.dir = options.dir;\n args.warn = options.warn;\n args.format = parseValidateFormat(options.format);\n\n const cmd = new ValidateCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n/**\n * Parse a date string.\n *\n * Supports ISO 8601 formats like:\n * - 2023-02-08\n * - 2023-02-08T15:30:45Z\n */\nfunction parseDate(dateStr: string): Date {\n const date = new Date(dateStr);\n if (isNaN(date.getTime())) {\n throw new Error(`Invalid date: ${dateStr}`);\n }\n return date;\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,UAAU,IAAIA,mBAAS;AAE7B,QAC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AAI,KAAK,QAAQ;AAC9B,KAAI,MAAM,KAAK,SAAS,CAAC,CACvB,OAAM,IAAI,MAAM,iBAAiB,UAAU;AAE7C,QAAO;;AAGT,QAAQ,OAAO"}
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as parseValidateFormat, c as NextCommand, g as parseSeed, h as parseResolution, i as defaultValidateCommandArgs, l as defaultNextCommandArgs, m as parseOutputFormat, n as ValidateCommand, o as PrintCommand, p as defaultNewCommandArgs, s as defaultPrintCommandArgs, t as VERSION, u as NewCommand } from "./src-Bu1tG89l.mjs";
|
|
3
|
+
import { Command, Option } from "commander";
|
|
4
|
+
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
/**
|
|
7
|
+
* provenance CLI - 1:1 port of main.rs
|
|
8
|
+
*
|
|
9
|
+
* Command line tool for creating and managing Provenance Marks.
|
|
10
|
+
*/
|
|
11
|
+
const program = new Command();
|
|
12
|
+
program.name("provenance").description("A tool for managing provenance mark chains and generating provenance marks.").version(VERSION);
|
|
13
|
+
program.command("new").description("Initialize a directory with a new provenance mark chain.").argument("<path>", "Path to directory to be created. Must not already exist.").option("-s, --seed <seed>", "A seed to use for the provenance mark chain (base64, hex, or ur:seed). If not supplied, a random seed is generated.").addOption(new Option("-r, --resolution <level>", "The resolution of the provenance mark chain.").choices([
|
|
14
|
+
"low",
|
|
15
|
+
"medium",
|
|
16
|
+
"quartile",
|
|
17
|
+
"high"
|
|
18
|
+
]).default("quartile")).option("-c, --comment <text>", "A comment to be included for the genesis mark.", "Genesis mark.").option("-d, --date <date>", "The date of the genesis mark. If not supplied, the current date is used.").option("-q, --quiet", "Suppress informational status output on stderr/stdout.", false).addOption(new Option("--format <format>", "Output format for the creation summary.").choices([
|
|
19
|
+
"markdown",
|
|
20
|
+
"ur",
|
|
21
|
+
"json"
|
|
22
|
+
]).default("markdown")).option("--info <payload>", "Hex-encoded dCBOR or UR payload to embed in the mark's info field.").option("--info-tag <tag>", "CBOR tag value to associate with an unknown UR type.").action((pathArg, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const args = defaultNewCommandArgs();
|
|
25
|
+
args.path = pathArg;
|
|
26
|
+
args.resolution = parseResolution(options.resolution);
|
|
27
|
+
args.comment = options.comment;
|
|
28
|
+
args.quiet = options.quiet;
|
|
29
|
+
args.format = parseOutputFormat(options.format);
|
|
30
|
+
if (options.seed !== void 0) args.seed = parseSeed(options.seed);
|
|
31
|
+
if (options.date !== void 0) args.date = parseDate(options.date);
|
|
32
|
+
args.info = {
|
|
33
|
+
info: options.info,
|
|
34
|
+
infoTag: options.infoTag !== void 0 ? parseInt(options.infoTag, 10) : void 0
|
|
35
|
+
};
|
|
36
|
+
const output = new NewCommand(args).exec();
|
|
37
|
+
if (output !== "") console.log(output);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
40
|
+
console.error(`Error: ${message}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
program.command("next").description("Generate the next provenance mark in a chain.").argument("<path>", "Path to the chain's directory. Must already exist.").option("-c, --comment <text>", "A comment to be included for the mark.", "Blank.").option("-d, --date <date>", "The date of the next mark. If not supplied, the current date is used.").option("-q, --quiet", "Suppress informational status output on stderr/stdout.", false).addOption(new Option("--format <format>", "Output format for the mark.").choices([
|
|
45
|
+
"markdown",
|
|
46
|
+
"ur",
|
|
47
|
+
"json"
|
|
48
|
+
]).default("markdown")).option("--info <payload>", "Hex-encoded dCBOR or UR payload to embed in the mark's info field.").option("--info-tag <tag>", "CBOR tag value to associate with an unknown UR type.").action((pathArg, options) => {
|
|
49
|
+
try {
|
|
50
|
+
const args = defaultNextCommandArgs();
|
|
51
|
+
args.path = pathArg;
|
|
52
|
+
args.comment = options.comment;
|
|
53
|
+
args.quiet = options.quiet;
|
|
54
|
+
args.format = parseOutputFormat(options.format);
|
|
55
|
+
if (options.date !== void 0) args.date = parseDate(options.date);
|
|
56
|
+
args.info = {
|
|
57
|
+
info: options.info,
|
|
58
|
+
infoTag: options.infoTag !== void 0 ? parseInt(options.infoTag, 10) : void 0
|
|
59
|
+
};
|
|
60
|
+
const output = new NextCommand(args).exec();
|
|
61
|
+
if (output !== "") console.log(output);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
64
|
+
console.error(`Error: ${message}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
program.command("print").description("Prints provenance marks in a chain.").argument("<path>", "Path to the chain's directory. Must already exist.").option("-s, --start <n>", "The sequence number of the first mark to print. If not supplied, the first mark (genesis mark) is used.", "0").option("-e, --end <n>", "The sequence number of the last mark to print. If not supplied, the last mark in the chain is used.").addOption(new Option("--format <format>", "Output format for the rendered marks.").choices([
|
|
69
|
+
"markdown",
|
|
70
|
+
"ur",
|
|
71
|
+
"json"
|
|
72
|
+
]).default("markdown")).action((pathArg, options) => {
|
|
73
|
+
try {
|
|
74
|
+
const args = defaultPrintCommandArgs();
|
|
75
|
+
args.path = pathArg;
|
|
76
|
+
args.start = parseInt(options.start, 10);
|
|
77
|
+
args.format = parseOutputFormat(options.format);
|
|
78
|
+
if (options.end !== void 0) args.end = parseInt(options.end, 10);
|
|
79
|
+
const output = new PrintCommand(args).exec();
|
|
80
|
+
if (output !== "") console.log(output);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
83
|
+
console.error(`Error: ${message}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
program.command("validate").description("Validate one or more provenance marks.").argument("[marks...]", "One or more provenance mark URs to validate.").option("-d, --dir <path>", "Path to a chain directory containing marks to validate.").option("-w, --warn", "Report issues as warnings without failing.", false).addOption(new Option("--format <format>", "Output format for the validation report.").choices([
|
|
88
|
+
"text",
|
|
89
|
+
"json-compact",
|
|
90
|
+
"json-pretty"
|
|
91
|
+
]).default("text")).action((marksArg, options) => {
|
|
92
|
+
try {
|
|
93
|
+
if (marksArg.length === 0 && options.dir === void 0) {
|
|
94
|
+
console.error("Error: Either provide marks to validate or use --dir to validate marks from a directory.");
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
if (marksArg.length > 0 && options.dir !== void 0) {
|
|
98
|
+
console.error("Error: Cannot provide both marks and --dir.");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
const args = defaultValidateCommandArgs();
|
|
102
|
+
args.marks = marksArg;
|
|
103
|
+
args.dir = options.dir;
|
|
104
|
+
args.warn = options.warn;
|
|
105
|
+
args.format = parseValidateFormat(options.format);
|
|
106
|
+
const output = new ValidateCommand(args).exec();
|
|
107
|
+
if (output !== "") console.log(output);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
110
|
+
console.error(`Error: ${message}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* Parse a date string.
|
|
116
|
+
*
|
|
117
|
+
* Supports ISO 8601 formats like:
|
|
118
|
+
* - 2023-02-08
|
|
119
|
+
* - 2023-02-08T15:30:45Z
|
|
120
|
+
*/
|
|
121
|
+
function parseDate(dateStr) {
|
|
122
|
+
const date = new Date(dateStr);
|
|
123
|
+
if (isNaN(date.getTime())) throw new Error(`Invalid date: ${dateStr}`);
|
|
124
|
+
return date;
|
|
125
|
+
}
|
|
126
|
+
program.parse();
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
export { };
|
|
130
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * provenance CLI - 1:1 port of main.rs\n *\n * Command line tool for creating and managing Provenance Marks.\n */\n\n/* eslint-disable no-console, no-undef, no-restricted-globals, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */\n\nimport { Command, Option } from \"commander\";\nimport { VERSION } from \"./index.js\";\nimport {\n NewCommand,\n defaultNewCommandArgs,\n parseResolution,\n parseOutputFormat,\n NextCommand,\n defaultNextCommandArgs,\n PrintCommand,\n defaultPrintCommandArgs,\n ValidateCommand,\n defaultValidateCommandArgs,\n parseValidateFormat,\n parseSeed,\n} from \"./cmd/index.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"provenance\")\n .description(\"A tool for managing provenance mark chains and generating provenance marks.\")\n .version(VERSION);\n\n// New command - Initialize a directory with a new provenance mark chain\nprogram\n .command(\"new\")\n .description(\"Initialize a directory with a new provenance mark chain.\")\n .argument(\"<path>\", \"Path to directory to be created. Must not already exist.\")\n .option(\n \"-s, --seed <seed>\",\n \"A seed to use for the provenance mark chain (base64, hex, or ur:seed). If not supplied, a random seed is generated.\",\n )\n .addOption(\n new Option(\"-r, --resolution <level>\", \"The resolution of the provenance mark chain.\")\n .choices([\"low\", \"medium\", \"quartile\", \"high\"])\n .default(\"quartile\"),\n )\n .option(\"-c, --comment <text>\", \"A comment to be included for the genesis mark.\", \"Genesis mark.\")\n .option(\n \"-d, --date <date>\",\n \"The date of the genesis mark. If not supplied, the current date is used.\",\n )\n .option(\"-q, --quiet\", \"Suppress informational status output on stderr/stdout.\", false)\n .addOption(\n new Option(\"--format <format>\", \"Output format for the creation summary.\")\n .choices([\"markdown\", \"ur\", \"json\"])\n .default(\"markdown\"),\n )\n .option(\"--info <payload>\", \"Hex-encoded dCBOR or UR payload to embed in the mark's info field.\")\n .option(\"--info-tag <tag>\", \"CBOR tag value to associate with an unknown UR type.\")\n .action((pathArg: string, options) => {\n try {\n const args = defaultNewCommandArgs();\n args.path = pathArg;\n args.resolution = parseResolution(options.resolution);\n args.comment = options.comment;\n args.quiet = options.quiet;\n args.format = parseOutputFormat(options.format);\n\n if (options.seed !== undefined) {\n args.seed = parseSeed(options.seed);\n }\n\n if (options.date !== undefined) {\n args.date = parseDate(options.date);\n }\n\n args.info = {\n info: options.info,\n infoTag: options.infoTag !== undefined ? parseInt(options.infoTag, 10) : undefined,\n };\n\n const cmd = new NewCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n// Next command - Generate the next provenance mark in a chain\nprogram\n .command(\"next\")\n .description(\"Generate the next provenance mark in a chain.\")\n .argument(\"<path>\", \"Path to the chain's directory. Must already exist.\")\n .option(\"-c, --comment <text>\", \"A comment to be included for the mark.\", \"Blank.\")\n .option(\n \"-d, --date <date>\",\n \"The date of the next mark. If not supplied, the current date is used.\",\n )\n .option(\"-q, --quiet\", \"Suppress informational status output on stderr/stdout.\", false)\n .addOption(\n new Option(\"--format <format>\", \"Output format for the mark.\")\n .choices([\"markdown\", \"ur\", \"json\"])\n .default(\"markdown\"),\n )\n .option(\"--info <payload>\", \"Hex-encoded dCBOR or UR payload to embed in the mark's info field.\")\n .option(\"--info-tag <tag>\", \"CBOR tag value to associate with an unknown UR type.\")\n .action((pathArg: string, options) => {\n try {\n const args = defaultNextCommandArgs();\n args.path = pathArg;\n args.comment = options.comment;\n args.quiet = options.quiet;\n args.format = parseOutputFormat(options.format);\n\n if (options.date !== undefined) {\n args.date = parseDate(options.date);\n }\n\n args.info = {\n info: options.info,\n infoTag: options.infoTag !== undefined ? parseInt(options.infoTag, 10) : undefined,\n };\n\n const cmd = new NextCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n// Print command - Print marks from a chain\nprogram\n .command(\"print\")\n .description(\"Prints provenance marks in a chain.\")\n .argument(\"<path>\", \"Path to the chain's directory. Must already exist.\")\n .option(\n \"-s, --start <n>\",\n \"The sequence number of the first mark to print. If not supplied, the first mark (genesis mark) is used.\",\n \"0\",\n )\n .option(\n \"-e, --end <n>\",\n \"The sequence number of the last mark to print. If not supplied, the last mark in the chain is used.\",\n )\n .addOption(\n new Option(\"--format <format>\", \"Output format for the rendered marks.\")\n .choices([\"markdown\", \"ur\", \"json\"])\n .default(\"markdown\"),\n )\n .action((pathArg: string, options) => {\n try {\n const args = defaultPrintCommandArgs();\n args.path = pathArg;\n args.start = parseInt(options.start, 10);\n args.format = parseOutputFormat(options.format);\n\n if (options.end !== undefined) {\n args.end = parseInt(options.end, 10);\n }\n\n const cmd = new PrintCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n// Validate command - Validate one or more provenance marks\nprogram\n .command(\"validate\")\n .description(\"Validate one or more provenance marks.\")\n .argument(\"[marks...]\", \"One or more provenance mark URs to validate.\")\n .option(\"-d, --dir <path>\", \"Path to a chain directory containing marks to validate.\")\n .option(\"-w, --warn\", \"Report issues as warnings without failing.\", false)\n .addOption(\n new Option(\"--format <format>\", \"Output format for the validation report.\")\n .choices([\"text\", \"json-compact\", \"json-pretty\"])\n .default(\"text\"),\n )\n .action((marksArg: string[], options) => {\n try {\n // Validate that either marks or dir is provided\n if (marksArg.length === 0 && options.dir === undefined) {\n console.error(\n \"Error: Either provide marks to validate or use --dir to validate marks from a directory.\",\n );\n process.exit(1);\n }\n if (marksArg.length > 0 && options.dir !== undefined) {\n console.error(\"Error: Cannot provide both marks and --dir.\");\n process.exit(1);\n }\n\n const args = defaultValidateCommandArgs();\n args.marks = marksArg;\n args.dir = options.dir;\n args.warn = options.warn;\n args.format = parseValidateFormat(options.format);\n\n const cmd = new ValidateCommand(args);\n const output = cmd.exec();\n if (output !== \"\") {\n console.log(output);\n }\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n console.error(`Error: ${message}`);\n process.exit(1);\n }\n });\n\n/**\n * Parse a date string.\n *\n * Supports ISO 8601 formats like:\n * - 2023-02-08\n * - 2023-02-08T15:30:45Z\n */\nfunction parseDate(dateStr: string): Date {\n const date = new Date(dateStr);\n if (isNaN(date.getTime())) {\n throw new Error(`Invalid date: ${dateStr}`);\n }\n return date;\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,UAAU,IAAI,SAAS;AAE7B,QACG,KAAK,aAAa,CAClB,YAAY,8EAA8E,CAC1F,QAAQ,QAAQ;AAGnB,QACG,QAAQ,MAAM,CACd,YAAY,2DAA2D,CACvE,SAAS,UAAU,2DAA2D,CAC9E,OACC,qBACA,sHACD,CACA,UACC,IAAI,OAAO,4BAA4B,+CAA+C,CACnF,QAAQ;CAAC;CAAO;CAAU;CAAY;CAAO,CAAC,CAC9C,QAAQ,WAAW,CACvB,CACA,OAAO,wBAAwB,kDAAkD,gBAAgB,CACjG,OACC,qBACA,2EACD,CACA,OAAO,eAAe,0DAA0D,MAAM,CACtF,UACC,IAAI,OAAO,qBAAqB,0CAA0C,CACvE,QAAQ;CAAC;CAAY;CAAM;CAAO,CAAC,CACnC,QAAQ,WAAW,CACvB,CACA,OAAO,oBAAoB,qEAAqE,CAChG,OAAO,oBAAoB,uDAAuD,CAClF,QAAQ,SAAiB,YAAY;AACpC,KAAI;EACF,MAAM,OAAO,uBAAuB;AACpC,OAAK,OAAO;AACZ,OAAK,aAAa,gBAAgB,QAAQ,WAAW;AACrD,OAAK,UAAU,QAAQ;AACvB,OAAK,QAAQ,QAAQ;AACrB,OAAK,SAAS,kBAAkB,QAAQ,OAAO;AAE/C,MAAI,QAAQ,SAAS,OACnB,MAAK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Q,KAAK,EAAE;;EAGjB,MAAM,OAAO,4BAA4B;AACzC,OAAK,QAAQ;AACb,OAAK,MAAM,QAAQ;AACnB,OAAK,OAAO,QAAQ;AACpB,OAAK,SAAS,oBAAoB,QAAQ,OAAO;EAGjD,MAAM,SADM,IAAI,gBAAgB,KAAK,CAClB,MAAM;AACzB,MAAI,WAAW,GACb,SAAQ,IAAI,OAAO;UAEd,GAAG;EACV,MAAM,UAAU,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE;AAC1D,UAAQ,MAAM,UAAU,UAAU;AAClC,UAAQ,KAAK,EAAE;;EAEjB;;;;;;;;AASJ,SAAS,UAAU,SAAuB;CACxC,MAAM,OAAO,IAAI,KAAK,QAAQ;AAC9B,KAAI,MAAM,KAAK,SAAS,CAAC,CACvB,OAAM,IAAI,MAAM,iBAAiB,UAAU;AAE7C,QAAO;;AAGT,QAAQ,OAAO"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_src = require('./src-XNNUeTzh.cjs');
|
|
2
|
+
|
|
3
|
+
exports.NewCommand = require_src.NewCommand;
|
|
4
|
+
exports.NextCommand = require_src.NextCommand;
|
|
5
|
+
exports.OutputFormat = require_src.OutputFormat;
|
|
6
|
+
exports.PrintCommand = require_src.PrintCommand;
|
|
7
|
+
exports.Resolution = require_src.Resolution;
|
|
8
|
+
exports.VERSION = require_src.VERSION;
|
|
9
|
+
exports.ValidateCommand = require_src.ValidateCommand;
|
|
10
|
+
exports.ValidateFormat = require_src.ValidateFormat;
|
|
11
|
+
exports.bytesToHex = require_src.bytesToHex;
|
|
12
|
+
exports.defaultNewCommandArgs = require_src.defaultNewCommandArgs;
|
|
13
|
+
exports.defaultNextCommandArgs = require_src.defaultNextCommandArgs;
|
|
14
|
+
exports.defaultPrintCommandArgs = require_src.defaultPrintCommandArgs;
|
|
15
|
+
exports.defaultValidateCommandArgs = require_src.defaultValidateCommandArgs;
|
|
16
|
+
exports.fromBase64 = require_src.fromBase64;
|
|
17
|
+
exports.hexToBytes = require_src.hexToBytes;
|
|
18
|
+
exports.parseInfoArgs = require_src.parseInfoArgs;
|
|
19
|
+
exports.parseOutputFormat = require_src.parseOutputFormat;
|
|
20
|
+
exports.parseResolution = require_src.parseResolution;
|
|
21
|
+
exports.parseSeed = require_src.parseSeed;
|
|
22
|
+
exports.parseValidateFormat = require_src.parseValidateFormat;
|
|
23
|
+
exports.readArgument = require_src.readArgument;
|
|
24
|
+
exports.readExistingDirectoryPath = require_src.readExistingDirectoryPath;
|
|
25
|
+
exports.readNewPath = require_src.readNewPath;
|
|
26
|
+
exports.readStdinSync = require_src.readStdinSync;
|
|
27
|
+
exports.toBase64 = require_src.toBase64;
|