@hpx7/delta-pack-cli 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +44 -25
  2. package/dist/index.js +66 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -20,12 +20,13 @@ Generate code from a YAML schema.
20
20
  delta-pack generate <schema.yml> -l <language> [-o output]
21
21
  ```
22
22
 
23
- | Flag | Description |
24
- |------|-------------|
23
+ | Flag | Description |
24
+ | ----------------------- | ------------------------------------------------- |
25
25
  | `-l, --language <lang>` | Target language: `typescript`/`ts`, `csharp`/`cs` |
26
- | `-o, --output <file>` | Output file (default: stdout) |
26
+ | `-o, --output <file>` | Output file (default: stdout) |
27
27
 
28
28
  Examples:
29
+
29
30
  ```bash
30
31
  # Output to stdout
31
32
  delta-pack generate schema.yml -l typescript
@@ -45,13 +46,14 @@ Encode JSON to binary.
45
46
  delta-pack encode <schema.yml> -t <type> [-i input] [-o output]
46
47
  ```
47
48
 
48
- | Flag | Description |
49
- |------|-------------|
50
- | `-t, --type <name>` | Type name (required) |
51
- | `-i, --input <file>` | JSON input file (default: stdin) |
49
+ | Flag | Description |
50
+ | --------------------- | ------------------------------------ |
51
+ | `-t, --type <name>` | Type name (required) |
52
+ | `-i, --input <file>` | JSON input file (default: stdin) |
52
53
  | `-o, --output <file>` | Binary output file (default: stdout) |
53
54
 
54
55
  Examples:
56
+
55
57
  ```bash
56
58
  # File to file
57
59
  delta-pack encode schema.yml -t Player -i player.json -o player.bin
@@ -71,13 +73,14 @@ Decode binary to JSON.
71
73
  delta-pack decode <schema.yml> -t <type> [-i input] [-o output]
72
74
  ```
73
75
 
74
- | Flag | Description |
75
- |------|-------------|
76
- | `-t, --type <name>` | Type name (required) |
77
- | `-i, --input <file>` | Binary input file (default: stdin) |
76
+ | Flag | Description |
77
+ | --------------------- | ---------------------------------- |
78
+ | `-t, --type <name>` | Type name (required) |
79
+ | `-i, --input <file>` | Binary input file (default: stdin) |
78
80
  | `-o, --output <file>` | JSON output file (default: stdout) |
79
81
 
80
82
  Examples:
83
+
81
84
  ```bash
82
85
  # File to file
83
86
  delta-pack decode schema.yml -t Player -i player.bin -o player.json
@@ -97,14 +100,15 @@ Encode the diff between two JSON states to binary.
97
100
  delta-pack encode-diff <schema.yml> -t <type> --old <file> --new <file> [-o output]
98
101
  ```
99
102
 
100
- | Flag | Description |
101
- |------|-------------|
102
- | `-t, --type <name>` | Type name (required) |
103
- | `--old <file>` | Old state JSON file (required) |
104
- | `--new <file>` | New state JSON file (required) |
103
+ | Flag | Description |
104
+ | --------------------- | ------------------------------------ |
105
+ | `-t, --type <name>` | Type name (required) |
106
+ | `--old <file>` | Old state JSON file (required) |
107
+ | `--new <file>` | New state JSON file (required) |
105
108
  | `-o, --output <file>` | Binary output file (default: stdout) |
106
109
 
107
110
  Examples:
111
+
108
112
  ```bash
109
113
  # Output to file
110
114
  delta-pack encode-diff schema.yml -t GameState --old state1.json --new state2.json -o diff.bin
@@ -121,14 +125,15 @@ Apply a binary diff to a JSON state.
121
125
  delta-pack decode-diff <schema.yml> -t <type> --old <file> [--diff <file>] [-o output]
122
126
  ```
123
127
 
124
- | Flag | Description |
125
- |------|-------------|
126
- | `-t, --type <name>` | Type name (required) |
127
- | `--old <file>` | Old state JSON file (required) |
128
- | `--diff <file>` | Binary diff file (default: stdin) |
128
+ | Flag | Description |
129
+ | --------------------- | ---------------------------------- |
130
+ | `-t, --type <name>` | Type name (required) |
131
+ | `--old <file>` | Old state JSON file (required) |
132
+ | `--diff <file>` | Binary diff file (default: stdin) |
129
133
  | `-o, --output <file>` | JSON output file (default: stdout) |
130
134
 
131
135
  Examples:
136
+
132
137
  ```bash
133
138
  # File to file
134
139
  delta-pack decode-diff schema.yml -t GameState --old state1.json --diff diff.bin -o state2.json
@@ -138,12 +143,26 @@ delta-pack encode-diff schema.yml -t GameState --old state1.json --new state2.js
138
143
  delta-pack decode-diff schema.yml -t GameState --old state1.json
139
144
  ```
140
145
 
146
+ ## Inspecting Binary Output
147
+
148
+ ```bash
149
+ # View binary as hex dump
150
+ delta-pack encode schema.yml -t Player -i player.json | xxd
151
+
152
+ # Check encoded size in bytes
153
+ delta-pack encode schema.yml -t Player -i player.json | wc -c
154
+
155
+ # Compare full encode vs diff size
156
+ delta-pack encode schema.yml -t GameState -i state2.json | wc -c
157
+ delta-pack encode-diff schema.yml -t GameState --old state1.json --new state2.json | wc -c
158
+ ```
159
+
141
160
  ## Exit Codes
142
161
 
143
- | Code | Meaning |
144
- |------|---------|
145
- | 0 | Success |
146
- | 1 | Error (invalid arguments, schema error, data validation error) |
162
+ | Code | Meaning |
163
+ | ---- | -------------------------------------------------------------- |
164
+ | 0 | Success |
165
+ | 1 | Error (invalid arguments, schema error, data validation error) |
147
166
 
148
167
  ## Development
149
168
 
package/dist/index.js CHANGED
@@ -8003,6 +8003,35 @@ var require_dist = __commonJS((exports) => {
8003
8003
  exports.visit = visit.visit;
8004
8004
  exports.visitAsync = visit.visitAsync;
8005
8005
  });
8006
+ // package.json
8007
+ var package_default = {
8008
+ name: "@hpx7/delta-pack-cli",
8009
+ version: "0.1.3",
8010
+ license: "MIT",
8011
+ author: "hpx7",
8012
+ repository: {
8013
+ type: "git",
8014
+ url: "git+https://github.com/hpx7/delta-pack.git",
8015
+ directory: "cli"
8016
+ },
8017
+ type: "module",
8018
+ bin: {
8019
+ "delta-pack": "dist/index.js"
8020
+ },
8021
+ files: [
8022
+ "dist"
8023
+ ],
8024
+ scripts: {
8025
+ build: "bun build src/index.ts --outdir dist --target node",
8026
+ test: "bun test"
8027
+ },
8028
+ dependencies: {
8029
+ "@hpx7/delta-pack": "^0.2.2"
8030
+ },
8031
+ devDependencies: {
8032
+ "@types/bun": "latest"
8033
+ }
8034
+ };
8006
8035
 
8007
8036
  // src/commands/generate.ts
8008
8037
  import { readFile as readFile2 } from "node:fs/promises";
@@ -10364,15 +10393,23 @@ async function writeOutput(path, data) {
10364
10393
  }
10365
10394
  }
10366
10395
 
10396
+ // src/utils/errors.ts
10397
+ class ArgError extends Error {
10398
+ constructor(message) {
10399
+ super(message);
10400
+ this.name = "ArgError";
10401
+ }
10402
+ }
10403
+
10367
10404
  // src/commands/generate.ts
10368
10405
  async function generate(schemaPath, flags) {
10369
10406
  if (!schemaPath) {
10370
- throw new Error("Schema file required");
10407
+ throw new ArgError("generate: schema file required");
10371
10408
  }
10372
10409
  const lang = flags.get("l") ?? flags.get("language");
10373
10410
  const output = flags.get("o") ?? flags.get("output");
10374
10411
  if (!lang || lang === true) {
10375
- throw new Error("Language required: -l <typescript|csharp>");
10412
+ throw new ArgError("generate: language required (-l <typescript|csharp>)");
10376
10413
  }
10377
10414
  const content = await readFile2(schemaPath, "utf-8");
10378
10415
  const schema2 = parseSchemaYml(content);
@@ -10384,9 +10421,9 @@ async function generate(schemaPath, flags) {
10384
10421
  break;
10385
10422
  case "csharp":
10386
10423
  case "cs":
10387
- throw new Error("C# codegen not yet implemented");
10424
+ throw new ArgError("generate: C# codegen not yet implemented");
10388
10425
  default:
10389
- throw new Error(`Unknown language: ${lang}`);
10426
+ throw new ArgError(`generate: unknown language '${lang}'`);
10390
10427
  }
10391
10428
  await writeOutput(output === true ? undefined : output, code);
10392
10429
  }
@@ -10411,13 +10448,13 @@ function getRootType(schema2, typeName) {
10411
10448
  // src/commands/encode.ts
10412
10449
  async function encode(schemaPath, flags) {
10413
10450
  if (!schemaPath) {
10414
- throw new Error("Schema file required");
10451
+ throw new ArgError("encode: schema file required");
10415
10452
  }
10416
10453
  const typeName = flags.get("t") ?? flags.get("type");
10417
10454
  const input = flags.get("i") ?? flags.get("input");
10418
10455
  const output = flags.get("o") ?? flags.get("output");
10419
10456
  if (!typeName || typeName === true) {
10420
- throw new Error("Type required: -t <name>");
10457
+ throw new ArgError("encode: type required (-t <name>)");
10421
10458
  }
10422
10459
  const schema2 = await loadSchema(schemaPath);
10423
10460
  const rootType = getRootType(schema2, typeName);
@@ -10431,13 +10468,13 @@ async function encode(schemaPath, flags) {
10431
10468
  // src/commands/decode.ts
10432
10469
  async function decode(schemaPath, flags) {
10433
10470
  if (!schemaPath) {
10434
- throw new Error("Schema file required");
10471
+ throw new ArgError("decode: schema file required");
10435
10472
  }
10436
10473
  const typeName = flags.get("t") ?? flags.get("type");
10437
10474
  const input = flags.get("i") ?? flags.get("input");
10438
10475
  const output = flags.get("o") ?? flags.get("output");
10439
10476
  if (!typeName || typeName === true) {
10440
- throw new Error("Type required: -t <name>");
10477
+ throw new ArgError("decode: type required (-t <name>)");
10441
10478
  }
10442
10479
  const schema2 = await loadSchema(schemaPath);
10443
10480
  const rootType = getRootType(schema2, typeName);
@@ -10453,20 +10490,20 @@ async function decode(schemaPath, flags) {
10453
10490
  import { readFile as readFile4 } from "node:fs/promises";
10454
10491
  async function encodeDiff(schemaPath, flags) {
10455
10492
  if (!schemaPath) {
10456
- throw new Error("Schema file required");
10493
+ throw new ArgError("encode-diff: schema file required");
10457
10494
  }
10458
10495
  const typeName = flags.get("t") ?? flags.get("type");
10459
10496
  const oldPath = flags.get("old");
10460
10497
  const newPath = flags.get("new");
10461
10498
  const output = flags.get("o") ?? flags.get("output");
10462
10499
  if (!typeName || typeName === true) {
10463
- throw new Error("Type required: -t <name>");
10500
+ throw new ArgError("encode-diff: type required (-t <name>)");
10464
10501
  }
10465
10502
  if (!oldPath || oldPath === true) {
10466
- throw new Error("Old state required: --old <file>");
10503
+ throw new ArgError("encode-diff: old state required (--old <file>)");
10467
10504
  }
10468
10505
  if (!newPath || newPath === true) {
10469
- throw new Error("New state required: --new <file>");
10506
+ throw new ArgError("encode-diff: new state required (--new <file>)");
10470
10507
  }
10471
10508
  const schema2 = await loadSchema(schemaPath);
10472
10509
  const rootType = getRootType(schema2, typeName);
@@ -10483,17 +10520,17 @@ async function encodeDiff(schemaPath, flags) {
10483
10520
  import { readFile as readFile5 } from "node:fs/promises";
10484
10521
  async function decodeDiff(schemaPath, flags) {
10485
10522
  if (!schemaPath) {
10486
- throw new Error("Schema file required");
10523
+ throw new ArgError("decode-diff: schema file required");
10487
10524
  }
10488
10525
  const typeName = flags.get("t") ?? flags.get("type");
10489
10526
  const oldPath = flags.get("old");
10490
10527
  const diffPath = flags.get("diff");
10491
10528
  const output = flags.get("o") ?? flags.get("output");
10492
10529
  if (!typeName || typeName === true) {
10493
- throw new Error("Type required: -t <name>");
10530
+ throw new ArgError("decode-diff: type required (-t <name>)");
10494
10531
  }
10495
10532
  if (!oldPath || oldPath === true) {
10496
- throw new Error("Old state required: --old <file>");
10533
+ throw new ArgError("decode-diff: old state required (--old <file>)");
10497
10534
  }
10498
10535
  const schema2 = await loadSchema(schemaPath);
10499
10536
  const rootType = getRootType(schema2, typeName);
@@ -10508,6 +10545,12 @@ async function decodeDiff(schemaPath, flags) {
10508
10545
  }
10509
10546
 
10510
10547
  // src/index.ts
10548
+ process.stdout.on("error", (err) => {
10549
+ if (err.code === "EPIPE") {
10550
+ process.exit(0);
10551
+ }
10552
+ throw err;
10553
+ });
10511
10554
  var args = process.argv.slice(2);
10512
10555
  var command = args[0];
10513
10556
  function parseFlags(args2) {
@@ -10562,6 +10605,10 @@ Options:
10562
10605
  `);
10563
10606
  }
10564
10607
  async function main() {
10608
+ if (command === "--version" || command === "-v") {
10609
+ console.log(package_default.version);
10610
+ process.exit(0);
10611
+ }
10565
10612
  if (!command || command === "help" || command === "--help" || command === "-h") {
10566
10613
  printUsage();
10567
10614
  process.exit(0);
@@ -10593,6 +10640,10 @@ async function main() {
10593
10640
  }
10594
10641
  } catch (err) {
10595
10642
  console.error(err instanceof Error ? err.message : err);
10643
+ if (err instanceof ArgError) {
10644
+ console.error();
10645
+ printUsage();
10646
+ }
10596
10647
  process.exit(1);
10597
10648
  }
10598
10649
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpx7/delta-pack-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "author": "hpx7",
6
6
  "repository": {