@hpx7/delta-pack-cli 0.1.2 → 0.1.4
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 +69 -46
- package/package.json +2 -2
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.4",
|
|
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.3"
|
|
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";
|
|
@@ -8218,35 +8247,11 @@ class Writer {
|
|
|
8218
8247
|
return this;
|
|
8219
8248
|
}
|
|
8220
8249
|
writeUVarint(val) {
|
|
8221
|
-
|
|
8222
|
-
this.writeUInt8(val);
|
|
8223
|
-
|
|
8224
|
-
this.writeUInt16(val & 127 | (val & 16256) << 1 | 32768);
|
|
8225
|
-
} else if (val < 2097152) {
|
|
8226
|
-
this.writeUInt8(val >> 14 | 128);
|
|
8227
|
-
this.writeUInt16(val & 127 | (val & 16256) << 1 | 32768);
|
|
8228
|
-
} else if (val < 268435456) {
|
|
8229
|
-
this.writeUInt32(val & 127 | (val & 16256) << 1 | (val & 2080768) << 2 | (val & 266338304) << 3 | 2155905024);
|
|
8230
|
-
} else if (val < 34359738368) {
|
|
8231
|
-
this.writeUInt8(Math.floor(val / 268435456) | 128);
|
|
8232
|
-
this.writeUInt32(val & 127 | (val & 16256) << 1 | (val & 2080768) << 2 | (val & 266338304) << 3 | 2155905024);
|
|
8233
|
-
} else if (val < 4398046511104) {
|
|
8234
|
-
const shiftedVal = Math.floor(val / 268435456);
|
|
8235
|
-
this.writeUInt16(shiftedVal & 127 | (shiftedVal & 16256) << 1 | 32896);
|
|
8236
|
-
this.writeUInt32(val & 127 | (val & 16256) << 1 | (val & 2080768) << 2 | (val & 266338304) << 3 | 2155905024);
|
|
8237
|
-
} else if (val < 562949953421312) {
|
|
8238
|
-
const shiftedVal = Math.floor(val / 268435456);
|
|
8239
|
-
this.writeUInt8(Math.floor(shiftedVal / 16384) & 127 | 128);
|
|
8240
|
-
this.writeUInt16(shiftedVal & 127 | (shiftedVal & 16256) << 1 | 32896);
|
|
8241
|
-
this.writeUInt32(val & 127 | (val & 16256) << 1 | (val & 2080768) << 2 | (val & 266338304) << 3 | 2155905024);
|
|
8242
|
-
} else if (val <= Number.MAX_SAFE_INTEGER) {
|
|
8243
|
-
const shiftedVal = Math.floor(val / 268435456);
|
|
8244
|
-
this.writeUInt16(Math.floor(shiftedVal / 16384) & 127 | (Math.floor(shiftedVal / 16384) & 16256) << 1 | 32896);
|
|
8245
|
-
this.writeUInt16(shiftedVal & 127 | (shiftedVal & 16256) << 1 | 32896);
|
|
8246
|
-
this.writeUInt32(val & 127 | (val & 16256) << 1 | (val & 2080768) << 2 | (val & 266338304) << 3 | 2155905024);
|
|
8247
|
-
} else {
|
|
8248
|
-
throw new Error("Value out of range");
|
|
8250
|
+
while (val >= 128) {
|
|
8251
|
+
this.writeUInt8(val & 127 | 128);
|
|
8252
|
+
val = Math.floor(val / 128);
|
|
8249
8253
|
}
|
|
8254
|
+
this.writeUInt8(val);
|
|
8250
8255
|
return this;
|
|
8251
8256
|
}
|
|
8252
8257
|
writeVarint(val) {
|
|
@@ -8374,13 +8379,15 @@ class Reader {
|
|
|
8374
8379
|
return val;
|
|
8375
8380
|
}
|
|
8376
8381
|
readUVarint() {
|
|
8377
|
-
let
|
|
8382
|
+
let result = 0;
|
|
8383
|
+
let multiplier = 1;
|
|
8378
8384
|
while (true) {
|
|
8379
8385
|
const byte = this.readUInt8();
|
|
8386
|
+
result += (byte & 127) * multiplier;
|
|
8380
8387
|
if (byte < 128) {
|
|
8381
|
-
return
|
|
8388
|
+
return result;
|
|
8382
8389
|
}
|
|
8383
|
-
|
|
8390
|
+
multiplier *= 128;
|
|
8384
8391
|
}
|
|
8385
8392
|
}
|
|
8386
8393
|
readVarint() {
|
|
@@ -10364,15 +10371,23 @@ async function writeOutput(path, data) {
|
|
|
10364
10371
|
}
|
|
10365
10372
|
}
|
|
10366
10373
|
|
|
10374
|
+
// src/utils/errors.ts
|
|
10375
|
+
class ArgError extends Error {
|
|
10376
|
+
constructor(message) {
|
|
10377
|
+
super(message);
|
|
10378
|
+
this.name = "ArgError";
|
|
10379
|
+
}
|
|
10380
|
+
}
|
|
10381
|
+
|
|
10367
10382
|
// src/commands/generate.ts
|
|
10368
10383
|
async function generate(schemaPath, flags) {
|
|
10369
10384
|
if (!schemaPath) {
|
|
10370
|
-
throw new
|
|
10385
|
+
throw new ArgError("generate: schema file required");
|
|
10371
10386
|
}
|
|
10372
10387
|
const lang = flags.get("l") ?? flags.get("language");
|
|
10373
10388
|
const output = flags.get("o") ?? flags.get("output");
|
|
10374
10389
|
if (!lang || lang === true) {
|
|
10375
|
-
throw new
|
|
10390
|
+
throw new ArgError("generate: language required (-l <typescript|csharp>)");
|
|
10376
10391
|
}
|
|
10377
10392
|
const content = await readFile2(schemaPath, "utf-8");
|
|
10378
10393
|
const schema2 = parseSchemaYml(content);
|
|
@@ -10384,9 +10399,9 @@ async function generate(schemaPath, flags) {
|
|
|
10384
10399
|
break;
|
|
10385
10400
|
case "csharp":
|
|
10386
10401
|
case "cs":
|
|
10387
|
-
throw new
|
|
10402
|
+
throw new ArgError("generate: C# codegen not yet implemented");
|
|
10388
10403
|
default:
|
|
10389
|
-
throw new
|
|
10404
|
+
throw new ArgError(`generate: unknown language '${lang}'`);
|
|
10390
10405
|
}
|
|
10391
10406
|
await writeOutput(output === true ? undefined : output, code);
|
|
10392
10407
|
}
|
|
@@ -10411,13 +10426,13 @@ function getRootType(schema2, typeName) {
|
|
|
10411
10426
|
// src/commands/encode.ts
|
|
10412
10427
|
async function encode(schemaPath, flags) {
|
|
10413
10428
|
if (!schemaPath) {
|
|
10414
|
-
throw new
|
|
10429
|
+
throw new ArgError("encode: schema file required");
|
|
10415
10430
|
}
|
|
10416
10431
|
const typeName = flags.get("t") ?? flags.get("type");
|
|
10417
10432
|
const input = flags.get("i") ?? flags.get("input");
|
|
10418
10433
|
const output = flags.get("o") ?? flags.get("output");
|
|
10419
10434
|
if (!typeName || typeName === true) {
|
|
10420
|
-
throw new
|
|
10435
|
+
throw new ArgError("encode: type required (-t <name>)");
|
|
10421
10436
|
}
|
|
10422
10437
|
const schema2 = await loadSchema(schemaPath);
|
|
10423
10438
|
const rootType = getRootType(schema2, typeName);
|
|
@@ -10431,13 +10446,13 @@ async function encode(schemaPath, flags) {
|
|
|
10431
10446
|
// src/commands/decode.ts
|
|
10432
10447
|
async function decode(schemaPath, flags) {
|
|
10433
10448
|
if (!schemaPath) {
|
|
10434
|
-
throw new
|
|
10449
|
+
throw new ArgError("decode: schema file required");
|
|
10435
10450
|
}
|
|
10436
10451
|
const typeName = flags.get("t") ?? flags.get("type");
|
|
10437
10452
|
const input = flags.get("i") ?? flags.get("input");
|
|
10438
10453
|
const output = flags.get("o") ?? flags.get("output");
|
|
10439
10454
|
if (!typeName || typeName === true) {
|
|
10440
|
-
throw new
|
|
10455
|
+
throw new ArgError("decode: type required (-t <name>)");
|
|
10441
10456
|
}
|
|
10442
10457
|
const schema2 = await loadSchema(schemaPath);
|
|
10443
10458
|
const rootType = getRootType(schema2, typeName);
|
|
@@ -10453,20 +10468,20 @@ async function decode(schemaPath, flags) {
|
|
|
10453
10468
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
10454
10469
|
async function encodeDiff(schemaPath, flags) {
|
|
10455
10470
|
if (!schemaPath) {
|
|
10456
|
-
throw new
|
|
10471
|
+
throw new ArgError("encode-diff: schema file required");
|
|
10457
10472
|
}
|
|
10458
10473
|
const typeName = flags.get("t") ?? flags.get("type");
|
|
10459
10474
|
const oldPath = flags.get("old");
|
|
10460
10475
|
const newPath = flags.get("new");
|
|
10461
10476
|
const output = flags.get("o") ?? flags.get("output");
|
|
10462
10477
|
if (!typeName || typeName === true) {
|
|
10463
|
-
throw new
|
|
10478
|
+
throw new ArgError("encode-diff: type required (-t <name>)");
|
|
10464
10479
|
}
|
|
10465
10480
|
if (!oldPath || oldPath === true) {
|
|
10466
|
-
throw new
|
|
10481
|
+
throw new ArgError("encode-diff: old state required (--old <file>)");
|
|
10467
10482
|
}
|
|
10468
10483
|
if (!newPath || newPath === true) {
|
|
10469
|
-
throw new
|
|
10484
|
+
throw new ArgError("encode-diff: new state required (--new <file>)");
|
|
10470
10485
|
}
|
|
10471
10486
|
const schema2 = await loadSchema(schemaPath);
|
|
10472
10487
|
const rootType = getRootType(schema2, typeName);
|
|
@@ -10483,17 +10498,17 @@ async function encodeDiff(schemaPath, flags) {
|
|
|
10483
10498
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
10484
10499
|
async function decodeDiff(schemaPath, flags) {
|
|
10485
10500
|
if (!schemaPath) {
|
|
10486
|
-
throw new
|
|
10501
|
+
throw new ArgError("decode-diff: schema file required");
|
|
10487
10502
|
}
|
|
10488
10503
|
const typeName = flags.get("t") ?? flags.get("type");
|
|
10489
10504
|
const oldPath = flags.get("old");
|
|
10490
10505
|
const diffPath = flags.get("diff");
|
|
10491
10506
|
const output = flags.get("o") ?? flags.get("output");
|
|
10492
10507
|
if (!typeName || typeName === true) {
|
|
10493
|
-
throw new
|
|
10508
|
+
throw new ArgError("decode-diff: type required (-t <name>)");
|
|
10494
10509
|
}
|
|
10495
10510
|
if (!oldPath || oldPath === true) {
|
|
10496
|
-
throw new
|
|
10511
|
+
throw new ArgError("decode-diff: old state required (--old <file>)");
|
|
10497
10512
|
}
|
|
10498
10513
|
const schema2 = await loadSchema(schemaPath);
|
|
10499
10514
|
const rootType = getRootType(schema2, typeName);
|
|
@@ -10568,6 +10583,10 @@ Options:
|
|
|
10568
10583
|
`);
|
|
10569
10584
|
}
|
|
10570
10585
|
async function main() {
|
|
10586
|
+
if (command === "--version" || command === "-v") {
|
|
10587
|
+
console.log(package_default.version);
|
|
10588
|
+
process.exit(0);
|
|
10589
|
+
}
|
|
10571
10590
|
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
10572
10591
|
printUsage();
|
|
10573
10592
|
process.exit(0);
|
|
@@ -10599,6 +10618,10 @@ async function main() {
|
|
|
10599
10618
|
}
|
|
10600
10619
|
} catch (err) {
|
|
10601
10620
|
console.error(err instanceof Error ? err.message : err);
|
|
10621
|
+
if (err instanceof ArgError) {
|
|
10622
|
+
console.error();
|
|
10623
|
+
printUsage();
|
|
10624
|
+
}
|
|
10602
10625
|
process.exit(1);
|
|
10603
10626
|
}
|
|
10604
10627
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpx7/delta-pack-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "hpx7",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"test": "bun test"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@hpx7/delta-pack": "^0.2.
|
|
23
|
+
"@hpx7/delta-pack": "^0.2.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/bun": "latest"
|