@hpx7/delta-pack-cli 0.1.2 → 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.
- package/README.md +30 -25
- package/dist/index.js +60 -15
- 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
|
|
24
|
-
|
|
23
|
+
| Flag | Description |
|
|
24
|
+
| ----------------------- | ------------------------------------------------- |
|
|
25
25
|
| `-l, --language <lang>` | Target language: `typescript`/`ts`, `csharp`/`cs` |
|
|
26
|
-
| `-o, --output <file>`
|
|
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
|
|
49
|
-
|
|
50
|
-
| `-t, --type <name>`
|
|
51
|
-
| `-i, --input <file>`
|
|
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
|
|
75
|
-
|
|
76
|
-
| `-t, --type <name>`
|
|
77
|
-
| `-i, --input <file>`
|
|
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
|
|
101
|
-
|
|
102
|
-
| `-t, --type <name>`
|
|
103
|
-
| `--old <file>`
|
|
104
|
-
| `--new <file>`
|
|
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
|
|
125
|
-
|
|
126
|
-
| `-t, --type <name>`
|
|
127
|
-
| `--old <file>`
|
|
128
|
-
| `--diff <file>`
|
|
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
|
|
@@ -154,10 +159,10 @@ delta-pack encode-diff schema.yml -t GameState --old state1.json --new state2.js
|
|
|
154
159
|
|
|
155
160
|
## Exit Codes
|
|
156
161
|
|
|
157
|
-
| Code | Meaning
|
|
158
|
-
|
|
159
|
-
| 0
|
|
160
|
-
| 1
|
|
162
|
+
| Code | Meaning |
|
|
163
|
+
| ---- | -------------------------------------------------------------- |
|
|
164
|
+
| 0 | Success |
|
|
165
|
+
| 1 | Error (invalid arguments, schema error, data validation error) |
|
|
161
166
|
|
|
162
167
|
## Development
|
|
163
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
|
|
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
|
|
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
|
|
10424
|
+
throw new ArgError("generate: C# codegen not yet implemented");
|
|
10388
10425
|
default:
|
|
10389
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
10500
|
+
throw new ArgError("encode-diff: type required (-t <name>)");
|
|
10464
10501
|
}
|
|
10465
10502
|
if (!oldPath || oldPath === true) {
|
|
10466
|
-
throw new
|
|
10503
|
+
throw new ArgError("encode-diff: old state required (--old <file>)");
|
|
10467
10504
|
}
|
|
10468
10505
|
if (!newPath || newPath === true) {
|
|
10469
|
-
throw new
|
|
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
|
|
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
|
|
10530
|
+
throw new ArgError("decode-diff: type required (-t <name>)");
|
|
10494
10531
|
}
|
|
10495
10532
|
if (!oldPath || oldPath === true) {
|
|
10496
|
-
throw new
|
|
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);
|
|
@@ -10568,6 +10605,10 @@ Options:
|
|
|
10568
10605
|
`);
|
|
10569
10606
|
}
|
|
10570
10607
|
async function main() {
|
|
10608
|
+
if (command === "--version" || command === "-v") {
|
|
10609
|
+
console.log(package_default.version);
|
|
10610
|
+
process.exit(0);
|
|
10611
|
+
}
|
|
10571
10612
|
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
10572
10613
|
printUsage();
|
|
10573
10614
|
process.exit(0);
|
|
@@ -10599,6 +10640,10 @@ async function main() {
|
|
|
10599
10640
|
}
|
|
10600
10641
|
} catch (err) {
|
|
10601
10642
|
console.error(err instanceof Error ? err.message : err);
|
|
10643
|
+
if (err instanceof ArgError) {
|
|
10644
|
+
console.error();
|
|
10645
|
+
printUsage();
|
|
10646
|
+
}
|
|
10602
10647
|
process.exit(1);
|
|
10603
10648
|
}
|
|
10604
10649
|
}
|