@kgdiff/cli 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +198 -2
- package/dist/apply-command.d.ts +34 -0
- package/dist/apply-command.d.ts.map +1 -0
- package/dist/apply-command.js +135 -0
- package/dist/apply-command.js.map +1 -0
- package/dist/args.d.ts +96 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +463 -0
- package/dist/args.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +17 -0
- package/dist/bin.js.map +1 -0
- package/dist/diff-command.d.ts +29 -0
- package/dist/diff-command.d.ts.map +1 -0
- package/dist/diff-command.js +236 -0
- package/dist/diff-command.js.map +1 -0
- package/dist/errors.d.ts +48 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +92 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +11 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +247 -0
- package/dist/help.js.map +1 -0
- package/dist/html.d.ts +53 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +107 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs.d.ts +54 -0
- package/dist/inputs.d.ts.map +1 -0
- package/dist/inputs.js +204 -0
- package/dist/inputs.js.map +1 -0
- package/dist/io.d.ts +64 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +2 -0
- package/dist/io.js.map +1 -0
- package/dist/locale.d.ts +58 -0
- package/dist/locale.d.ts.map +1 -0
- package/dist/locale.js +121 -0
- package/dist/locale.js.map +1 -0
- package/dist/main.d.ts +10 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +51 -0
- package/dist/main.js.map +1 -0
- package/dist/markdown.d.ts +30 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +93 -0
- package/dist/markdown.js.map +1 -0
- package/dist/model.d.ts +63 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +151 -0
- package/dist/model.js.map +1 -0
- package/dist/node-io.d.ts +12 -0
- package/dist/node-io.d.ts.map +1 -0
- package/dist/node-io.js +135 -0
- package/dist/node-io.js.map +1 -0
- package/dist/output.d.ts +27 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +50 -0
- package/dist/output.js.map +1 -0
- package/dist/overwrite.d.ts +14 -0
- package/dist/overwrite.d.ts.map +1 -0
- package/dist/overwrite.js +55 -0
- package/dist/overwrite.js.map +1 -0
- package/dist/report.d.ts +52 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +64 -0
- package/dist/report.js.map +1 -0
- package/dist/style.d.ts +46 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +140 -0
- package/dist/style.js.map +1 -0
- package/dist/summary.d.ts +40 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/summary.js +352 -0
- package/dist/summary.js.map +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +19 -0
- package/dist/version.js.map +1 -0
- package/dist/width.d.ts +45 -0
- package/dist/width.d.ts.map +1 -0
- package/dist/width.js +232 -0
- package/dist/width.js.map +1 -0
- package/package.json +56 -3
- package/src/apply-command.ts +201 -0
- package/src/args.ts +605 -0
- package/src/bin.ts +22 -0
- package/src/diff-command.ts +299 -0
- package/src/errors.ts +131 -0
- package/src/help.ts +286 -0
- package/src/html.ts +145 -0
- package/src/index.ts +71 -0
- package/src/inputs.ts +264 -0
- package/src/io.ts +68 -0
- package/src/locale.ts +177 -0
- package/src/main.ts +56 -0
- package/src/markdown.ts +119 -0
- package/src/model.ts +181 -0
- package/src/node-io.ts +146 -0
- package/src/output.ts +81 -0
- package/src/overwrite.ts +75 -0
- package/src/report.ts +101 -0
- package/src/style.ts +164 -0
- package/src/summary.ts +440 -0
- package/src/version.ts +21 -0
- package/src/width.ts +222 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iiwish and kgdiff contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,199 @@
|
|
|
1
|
-
#
|
|
1
|
+
# kgdiff
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**git diff for knowledge graphs.** Compare two versions of a graph — RDF, OBO or JSON — in the
|
|
4
|
+
terminal, in CI, or as a single-file interactive HTML report. kgdiff understands what changed:
|
|
5
|
+
a merge is a merge, a rename is a rename, a moved class is a move.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx @kgdiff/cli before.ttl after.ttl
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install --global @kgdiff/cli # or: pnpm add -g @kgdiff/cli
|
|
15
|
+
kgdiff --version
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Node.js ≥ 22. `npx @kgdiff/cli …` works without installing.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
kgdiff <before> <after> [options]
|
|
24
|
+
kgdiff apply <graph> <delta> [-o <file>] [--no-strict [--verbose]]
|
|
25
|
+
kgdiff --help | --version
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Inputs are JSON (kgdiff, d3 / NetworkX, Cytoscape.js, G6, graphology, vis-network), JSON-LD,
|
|
29
|
+
Turtle, N-Triples, N-Quads, TriG, RDF/XML (`.rdf`, `.owl` from Protégé or ROBOT) and OBO,
|
|
30
|
+
detected from the extension and the content. Gzip-compressed files (`.ttl.gz`) work too. `-`
|
|
31
|
+
reads one side from stdin. JSON-LD contexts must be inline: remote ones are never fetched.
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
kgdiff v12.json v13.json # colored summary
|
|
35
|
+
kgdiff old.obo new.obo -o report.html --open # interactive report, opened in the browser
|
|
36
|
+
kgdiff a.ttl b.ttl --stat # diffstat only
|
|
37
|
+
kgdiff a.ttl b.ttl --name-status | grep '^G' # merges, one per line (tab-separated)
|
|
38
|
+
kgdiff a.json b.json --json diff.json # full machine-readable diff
|
|
39
|
+
kgdiff a.json b.json --delta patch.json # invertible delta …
|
|
40
|
+
kgdiff apply a.json patch.json -o b.json # … and apply it
|
|
41
|
+
curl -s https://example.org/latest.ttl | kgdiff pinned.ttl -
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Outputs combine: `kgdiff a.ttl b.ttl -o report.html --markdown summary.md --json diff.json`
|
|
45
|
+
writes three files and still prints the summary. At most one output can go to stdout.
|
|
46
|
+
|
|
47
|
+
Files are written atomically (temporary file + rename). kgdiff never overwrites its inputs: an
|
|
48
|
+
output that is an input under another name — a case variant, a symlink, a hard link — is refused,
|
|
49
|
+
in `kgdiff apply` too. An empty input is an error unless `--allow-empty` (an empty graph, e.g.
|
|
50
|
+
before a first release), so a failed upstream command cannot pass for "everything removed".
|
|
51
|
+
|
|
52
|
+
### In CI
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
# Fail the job when the ontology changed, and explain what changed in the job summary.
|
|
56
|
+
- run: npx @kgdiff/cli main/ontology.ttl ontology.ttl --markdown >> "$GITHUB_STEP_SUMMARY"
|
|
57
|
+
- run: npx @kgdiff/cli main/ontology.ttl ontology.ttl --exit-code --quiet
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`--markdown` is GitHub-flavoured Markdown (a diffstat table, a family legend and the hunk list
|
|
61
|
+
in collapsible `<details>` groups), safe to paste into PR comments: labels are escaped and can
|
|
62
|
+
never mention people, link issues or inject HTML.
|
|
63
|
+
|
|
64
|
+
## Output
|
|
65
|
+
|
|
66
|
+
The default summary: a header with node and edge totals, counters per replay phase, a diffstat
|
|
67
|
+
bar, and the hunks grouped by phase (Removed, Restructured, Modified, Added). Glyphs keep it
|
|
68
|
+
readable without color: `+` added, `−` removed, `~` modified, `⇄` structure (moves,
|
|
69
|
+
relations), `⊕` merge, `⑂` split.
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
kgdiff mhd 2026-09-01 → 2026-10-01 179 → 184 nodes · 351 → 353 edges
|
|
73
|
+
|
|
74
|
+
+3 added ~12 modified ⇄7 restructured 58 changes in 22 hunks
|
|
75
|
+
+++++~~~~~~~~~~~~⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄⇄
|
|
76
|
+
|
|
77
|
+
Restructured 7
|
|
78
|
+
⑂ Split “obsolete diabetes insipidus” into “obsolete diabetes i… identity · inferred · 80% conf…
|
|
79
|
+
⊕ Merged “juvenile diabetes” and “insulin-dependent diabetes me… identity · via replacement hin…
|
|
80
|
+
⊕ Merged “heart attack” into “myocardial infarction” identity · via replacement hin…
|
|
81
|
+
⇄ Moved “Crohn disease” under “inflammatory bowel disease” structure · from “intestinal d…
|
|
82
|
+
Modified 12
|
|
83
|
+
~ Renamed “alcoholic liver disease” → “alcohol-related liver di… content · ~1 attribute · +1 sy…
|
|
84
|
+
…
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Counters count hunks (reviewable changes); "58 changes" counts changed nodes and edges, which
|
|
88
|
+
the bar splits by phase. Colors follow kgdiff's meaning families (green added, red removed,
|
|
89
|
+
amber content, blue structure, violet identity) in truecolor, 256 or 16 colors. Lines fit the
|
|
90
|
+
terminal down to 40 columns; CJK and emoji are measured correctly, and control, bidi and
|
|
91
|
+
invisible characters in labels are shown as `␛` / `⟨U+202E⟩` instead of being interpreted. `--limit <n>` caps the list (default 50, `0`
|
|
92
|
+
lists all). Hunk titles and the summary are localized (`--locale zh-CN`, or from `LANG`).
|
|
93
|
+
|
|
94
|
+
`--stat` adds a nodes / edges table and changes by node type:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
added removed modified unchanged
|
|
98
|
+
nodes 5 0 23 156
|
|
99
|
+
edges 10 8 12 331
|
|
100
|
+
|
|
101
|
+
By type
|
|
102
|
+
Term 28 +++++~~~~~~~~~~~~~~~~~~~~~~~
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`--name-status` prints one line per hunk: a letter (`A` added, `D` removed, `M` modified,
|
|
106
|
+
`R` renamed, `V` moved, `G` merged, `S` split, `E` relations), the anchor node id and the
|
|
107
|
+
title, tab-separated when piped:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
S MHD:0000067 Split “obsolete diabetes insipidus” into …
|
|
111
|
+
G MHD:0000062 Merged “juvenile diabetes” and “insulin-dependent diabetes mellitus” into …
|
|
112
|
+
V MHD:0000087 Moved “Crohn disease” under “inflammatory bowel disease”
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### HTML report
|
|
116
|
+
|
|
117
|
+
`-o report.html` writes one self-contained file: the viewer plus the precomputed diff and
|
|
118
|
+
layout (gzip-compressed above 512 kB). It opens instantly, works offline and can be attached to
|
|
119
|
+
a PR or an e-mail. `--theme`, `--mode`, `--locale` and `--title` set the initial view;
|
|
120
|
+
`--reproducible` omits the timestamp so identical inputs give byte-identical reports.
|
|
121
|
+
|
|
122
|
+
Large graphs are laid out around their changes, with unchanged neighbourhoods collapsed. For
|
|
123
|
+
those reports kgdiff also inlines the viewer's small compute add-on, so collapsed groups can be
|
|
124
|
+
expanded in the browser; reports with a full layout leave it out. `--no-compute` always leaves
|
|
125
|
+
it out (smaller file, groups stay collapsed).
|
|
126
|
+
|
|
127
|
+
### Applying deltas
|
|
128
|
+
|
|
129
|
+
`kgdiff apply` applies a delta (from `--delta`, or the delta inside `--json` output) and writes
|
|
130
|
+
the patched graph as kgdiff JSON. By default it checks that the graph is the delta's base and
|
|
131
|
+
that every operation's precondition holds. Parse the graph as when the delta was made (same
|
|
132
|
+
`--format` / `--lang`), or its hash will differ. `--no-strict` applies every operation that fits
|
|
133
|
+
and reports how many were skipped; add `--verbose` to list them.
|
|
134
|
+
|
|
135
|
+
## Options
|
|
136
|
+
|
|
137
|
+
Run `kgdiff --help` for the full list. The most useful:
|
|
138
|
+
|
|
139
|
+
| Option | Meaning |
|
|
140
|
+
| ------------------------------ | ----------------------------------------------------------------------------- |
|
|
141
|
+
| `--match id\|auto\|similarity` | How nodes are paired (default `auto`: ids, then similarity) |
|
|
142
|
+
| `--hierarchy <predicate>` | Hierarchy predicate, repeatable (e.g. `--hierarchy is_a`) |
|
|
143
|
+
| `--ignore-attr <key>` | Ignore an attribute when comparing, repeatable |
|
|
144
|
+
| `-f, --format <fmt>` | Force the input format (`json jsonld turtle ntriples nquads trig rdfxml obo`) |
|
|
145
|
+
| `--lang zh,en` | RDF label language preference |
|
|
146
|
+
| `--exit-code`, `-q` | Exit 1 on differences; print nothing on stdout |
|
|
147
|
+
| `--color auto\|always\|never` | Colors (auto: only on a terminal, honours `NO_COLOR`) |
|
|
148
|
+
|
|
149
|
+
## Exit codes
|
|
150
|
+
|
|
151
|
+
| Code | Meaning |
|
|
152
|
+
| ---- | ------------------------------------------------------------------------- |
|
|
153
|
+
| `0` | Success (and, with `--exit-code`, no differences) |
|
|
154
|
+
| `1` | The graphs differ (only with `--exit-code`) |
|
|
155
|
+
| `2` | Usage or input error: one line on stderr with a hint, never a stack trace |
|
|
156
|
+
|
|
157
|
+
## Environment
|
|
158
|
+
|
|
159
|
+
| Variable | Effect |
|
|
160
|
+
| -------------------------------- | ----------------------------------------------------------------------- |
|
|
161
|
+
| `NO_COLOR` | Disable colors (unless `--color always`) |
|
|
162
|
+
| `FORCE_COLOR` | `0` disables; `1` / `2` / `3` force exactly 16 / 256 / truecolor colors |
|
|
163
|
+
| `COLORTERM`, `TERM`, `COLORFGBG` | Color depth and light-background detection |
|
|
164
|
+
| `LC_ALL`, `LC_MESSAGES`, `LANG` | Default locale (`zh*` → `zh-CN`, otherwise `en`) |
|
|
165
|
+
| `COLUMNS` | Line width when stdout is not a terminal (default 120) |
|
|
166
|
+
| `KGDIFF_MAX_INPUT` | Input size limit after decompression (default `1G`; e.g. `4G`, `512M`) |
|
|
167
|
+
| `DEBUG=kgdiff` | Print stack traces with errors |
|
|
168
|
+
|
|
169
|
+
## Programmatic use
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { main, nodeIO } from 'kgdiff';
|
|
173
|
+
|
|
174
|
+
process.exitCode = await main(['a.ttl', 'b.ttl', '--stat'], nodeIO());
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`main(argv, io)` never throws and takes every side effect from `io` (streams, files, clock,
|
|
178
|
+
environment, terminal size), so it runs in-process in tests. The renderers (`renderSummary`,
|
|
179
|
+
`renderStat`, `renderNameStatus`, `renderMarkdown`, `renderReportHtml`) and helpers
|
|
180
|
+
(`stringWidth`, `truncate`, `resolveColorLevel`, `parseCommandLine`) are exported too.
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
From the repository root:
|
|
185
|
+
|
|
186
|
+
```sh
|
|
187
|
+
pnpm tsx packages/cli/src/bin.ts examples/datasets/ontology-release/before.obo \
|
|
188
|
+
examples/datasets/ontology-release/after.obo --hierarchy is_a
|
|
189
|
+
pnpm vitest run packages/cli # tests, including golden outputs in test/__snapshots__
|
|
190
|
+
pnpm --filter kgdiff typecheck
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
HTML reports need the standalone viewer bundle: `pnpm --filter @kgdiff/viewer build`.
|
|
194
|
+
Golden snapshots follow the diff engine; after an intended change run
|
|
195
|
+
`pnpm vitest run packages/cli -u` and review the snapshot diff.
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Delta, type GraphJSON, type KGraph } from '@kgdiff/core';
|
|
2
|
+
import { type ApplyCommandOptions } from './args.js';
|
|
3
|
+
import { type RawInput } from './inputs.js';
|
|
4
|
+
import type { CliIO } from './io.js';
|
|
5
|
+
/**
|
|
6
|
+
* Read a delta from JSON text. Accepts a `kgdiff.delta` document, or a `kgdiff.diff` document
|
|
7
|
+
* (`--json` output), whose delta is used. Version checks are left to `applyDelta`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readDelta(input: RawInput): Delta;
|
|
10
|
+
/**
|
|
11
|
+
* The patched graph as kgdiff JSON (`graphToJSON`, which `kgdiff` reads back losslessly).
|
|
12
|
+
*
|
|
13
|
+
* Meta: `name` / `version` come from the delta's target (`applyDelta`); `source` names the
|
|
14
|
+
* output file (`source` argument), or is dropped when writing to stdout, so the result never
|
|
15
|
+
* claims to be the input file.
|
|
16
|
+
*/
|
|
17
|
+
export declare function graphOutputJSON(graph: KGraph, source?: string): GraphJSON;
|
|
18
|
+
export interface SkippedOp {
|
|
19
|
+
/** Index in `delta.ops`. */
|
|
20
|
+
readonly index: number;
|
|
21
|
+
readonly op: string;
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `--no-strict`: apply every operation whose precondition holds, in one pass, and collect the
|
|
26
|
+
* skipped ones (core's `onSkip`, in op order).
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyLeniently(graph: KGraph, delta: Delta): {
|
|
29
|
+
readonly result: KGraph;
|
|
30
|
+
readonly skipped: readonly SkippedOp[];
|
|
31
|
+
};
|
|
32
|
+
/** Run the apply command. Returns the exit code. */
|
|
33
|
+
export declare function runApply(o: ApplyCommandOptions, io: CliIO): Promise<number>;
|
|
34
|
+
//# sourceMappingURL=apply-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-command.d.ts","sourceRoot":"","sources":["../src/apply-command.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,KAAK,EAEV,KAAK,SAAS,EAGd,KAAK,MAAM,EAEZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,mBAAmB,EAAS,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAc,KAAK,QAAQ,EAAuB,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAUrC;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAwBhD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAKzE;AAID,MAAM,WAAW,SAAS;IACxB,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,KAAK,GACX;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAOrE;AAMD,oDAAoD;AACpD,wBAAsB,QAAQ,CAAC,CAAC,EAAE,mBAAmB,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAkGjF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `kgdiff apply <graph> <delta>`: apply a delta (docs/delta-format.md) and write the patched
|
|
3
|
+
* graph as kgdiff JSON.
|
|
4
|
+
*/
|
|
5
|
+
import { basename } from 'node:path';
|
|
6
|
+
import { applyDelta, graphToJSON, hashGraph, normalize, } from '@kgdiff/core';
|
|
7
|
+
import { STDIO } from './args.js';
|
|
8
|
+
import { CliError, formatWarning, isKgdiffError } from './errors.js';
|
|
9
|
+
import { parseInput, readInput, readPair } from './inputs.js';
|
|
10
|
+
import { formatInt } from './locale.js';
|
|
11
|
+
import { outputContext, writeOutputFile } from './output.js';
|
|
12
|
+
import { checkNoOverwrite } from './overwrite.js';
|
|
13
|
+
import { sanitize } from './width.js';
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Read a delta from JSON text. Accepts a `kgdiff.delta` document, or a `kgdiff.diff` document
|
|
19
|
+
* (`--json` output), whose delta is used. Version checks are left to `applyDelta`.
|
|
20
|
+
*/
|
|
21
|
+
export function readDelta(input) {
|
|
22
|
+
const where = input.display === 'stdin' ? 'stdin' : `"${input.display}"`;
|
|
23
|
+
let value;
|
|
24
|
+
try {
|
|
25
|
+
value = JSON.parse(input.text);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new CliError('input', `${where} is not valid JSON: ${error instanceof Error ? error.message : String(error)}.`, 'Create a delta with `kgdiff <before> <after> --delta <file>`.', { cause: error });
|
|
29
|
+
}
|
|
30
|
+
if (isRecord(value) && value.format === 'kgdiff.diff' && isRecord(value.delta)) {
|
|
31
|
+
return value.delta;
|
|
32
|
+
}
|
|
33
|
+
if (!isRecord(value) || value.format !== 'kgdiff.delta') {
|
|
34
|
+
throw new CliError('input', `${where} is not a kgdiff delta (expected "format": "kgdiff.delta").`, 'Create one with `kgdiff <before> <after> --delta <file>`. Is the order <graph> <delta>?');
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The patched graph as kgdiff JSON (`graphToJSON`, which `kgdiff` reads back losslessly).
|
|
40
|
+
*
|
|
41
|
+
* Meta: `name` / `version` come from the delta's target (`applyDelta`); `source` names the
|
|
42
|
+
* output file (`source` argument), or is dropped when writing to stdout, so the result never
|
|
43
|
+
* claims to be the input file.
|
|
44
|
+
*/
|
|
45
|
+
export function graphOutputJSON(graph, source) {
|
|
46
|
+
const { meta, ...json } = graphToJSON(graph);
|
|
47
|
+
const { source: _inputSource, ...rest } = meta ?? {};
|
|
48
|
+
const outMeta = source !== undefined ? { ...rest, source } : rest;
|
|
49
|
+
return Object.keys(outMeta).length > 0 ? { meta: outMeta, ...json } : json;
|
|
50
|
+
}
|
|
51
|
+
const EDGE_IDENTITIES = ['structure', 'id'];
|
|
52
|
+
/**
|
|
53
|
+
* `--no-strict`: apply every operation whose precondition holds, in one pass, and collect the
|
|
54
|
+
* skipped ones (core's `onSkip`, in op order).
|
|
55
|
+
*/
|
|
56
|
+
export function applyLeniently(graph, delta) {
|
|
57
|
+
const skipped = [];
|
|
58
|
+
const result = applyDelta(graph, delta, {
|
|
59
|
+
strict: false,
|
|
60
|
+
onSkip: ({ index, op, reason }) => skipped.push({ index, op: String(op.op), reason }),
|
|
61
|
+
});
|
|
62
|
+
return { result, skipped };
|
|
63
|
+
}
|
|
64
|
+
const PARSE_OPTIONS_HINT = 'If it is the same graph, parse it as when the delta was made: --format and --lang must match ' +
|
|
65
|
+
'the options given to `kgdiff … --delta` (they change what the graph contains).';
|
|
66
|
+
/** Run the apply command. Returns the exit code. */
|
|
67
|
+
export async function runApply(o, io) {
|
|
68
|
+
const ctx = outputContext(io, o);
|
|
69
|
+
await checkNoOverwrite(io, [
|
|
70
|
+
{ role: '<graph>', path: o.graph },
|
|
71
|
+
{ role: '<delta>', path: o.delta },
|
|
72
|
+
], [{ role: '-o', path: o.output }]);
|
|
73
|
+
const [graphInput, deltaInput] = await readPair(readInput(io, o.graph, '<graph>', { allowEmpty: o.allowEmpty }), readInput(io, o.delta, '<delta>', {
|
|
74
|
+
emptyHint: 'Create a delta with `kgdiff <before> <after> --delta <file>`.',
|
|
75
|
+
}));
|
|
76
|
+
const delta = readDelta(deltaInput);
|
|
77
|
+
const parsed = parseInput(graphInput, {
|
|
78
|
+
format: o.format,
|
|
79
|
+
formatFlag: '--format',
|
|
80
|
+
...(o.languages ? { languages: o.languages } : {}),
|
|
81
|
+
});
|
|
82
|
+
const edgeIdentity = EDGE_IDENTITIES.includes(delta.edgeIdentity)
|
|
83
|
+
? { edgeIdentity: delta.edgeIdentity }
|
|
84
|
+
: {};
|
|
85
|
+
const graph = normalize(parsed.graph, edgeIdentity);
|
|
86
|
+
let result;
|
|
87
|
+
let skipped = [];
|
|
88
|
+
if (o.strict) {
|
|
89
|
+
try {
|
|
90
|
+
result = applyDelta(graph, delta, { strict: true });
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (isKgdiffError(error) && error.code === 'delta-base-mismatch') {
|
|
94
|
+
const { expected, actual } = error.details ?? {};
|
|
95
|
+
const where = o.graph === STDIO ? '<graph> (stdin)' : `<graph> "${o.graph}"`;
|
|
96
|
+
throw new CliError('input', `${where} is not the base of this delta (graph ${String(actual)}, delta base ${String(expected)}).`, `${PARSE_OPTIONS_HINT} Otherwise --no-strict applies what fits and reports the rest.`, { cause: error });
|
|
97
|
+
}
|
|
98
|
+
if (isKgdiffError(error) && error.code === 'delta-conflict') {
|
|
99
|
+
throw new CliError('input', error.message, `The graph differs from the delta's base. --no-strict applies the operations that fit and reports the others. ${PARSE_OPTIONS_HINT}`, { cause: error });
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const lenient = applyLeniently(graph, delta);
|
|
106
|
+
result = lenient.result;
|
|
107
|
+
skipped = lenient.skipped;
|
|
108
|
+
if (skipped.length > 0) {
|
|
109
|
+
const total = delta.ops.length;
|
|
110
|
+
const count = formatInt(skipped.length);
|
|
111
|
+
ctx.notice(formatWarning(`Skipped ${count} of ${formatInt(total)} ${total === 1 ? 'operation' : 'operations'} that do not fit this graph${o.verbose ? ':' : ' (--verbose lists them).'}`, ctx.errPaint));
|
|
112
|
+
if (o.verbose) {
|
|
113
|
+
for (const s of skipped) {
|
|
114
|
+
ctx.notice(` #${s.index} ${sanitize(s.op)}: ${sanitize(s.reason)}\n`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const hash = hashGraph(result);
|
|
120
|
+
const target = isRecord(delta.target) ? delta.target.hash : undefined;
|
|
121
|
+
if (typeof target === 'string' && hash !== target && skipped.length === 0) {
|
|
122
|
+
ctx.notice(formatWarning(`The result (${hash}) differs from the delta's target (${target}).`, ctx.errPaint));
|
|
123
|
+
}
|
|
124
|
+
const source = o.output === STDIO ? undefined : basename(o.output);
|
|
125
|
+
const text = `${JSON.stringify(graphOutputJSON(result, source), null, o.pretty ? 2 : undefined)}\n`;
|
|
126
|
+
if (o.output === STDIO) {
|
|
127
|
+
ctx.stdout(text);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const ops = delta.ops.length - skipped.length;
|
|
131
|
+
await writeOutputFile(ctx, o.output, text, `patched graph (${formatInt(ops)} ${ops === 1 ? 'operation' : 'operations'} applied, ${hash})`);
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=apply-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-command.js","sourceRoot":"","sources":["../src/apply-command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EACL,UAAU,EAIV,WAAW,EACX,SAAS,EAET,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAA4B,KAAK,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAiB,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAAe;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,GAAG,CAAC;IACzE,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IA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AkB,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,aAAa,IAAI,GAAG,CAC/F,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { DiffOptions, Locale } from '@kgdiff/core';
|
|
2
|
+
import type { FormatId } from '@kgdiff/formats';
|
|
3
|
+
import type { ThemePreference, ViewerMode } from '@kgdiff/viewer';
|
|
4
|
+
import type { ColorMode } from './style.js';
|
|
5
|
+
/** Path value meaning "write to stdout" / "read from stdin". */
|
|
6
|
+
export declare const STDIO = "-";
|
|
7
|
+
export declare const FORMATS: readonly (FormatId | 'auto')[];
|
|
8
|
+
/** Default `--limit`. */
|
|
9
|
+
export declare const DEFAULT_LIMIT = 50;
|
|
10
|
+
export interface CommonOptions {
|
|
11
|
+
readonly color: ColorMode;
|
|
12
|
+
readonly quiet: boolean;
|
|
13
|
+
readonly locale?: Locale;
|
|
14
|
+
}
|
|
15
|
+
export interface DiffCommandOptions extends CommonOptions {
|
|
16
|
+
/** Paths, or `-` for stdin. */
|
|
17
|
+
readonly before: string;
|
|
18
|
+
readonly after: string;
|
|
19
|
+
readonly beforeFormat: FormatId | 'auto';
|
|
20
|
+
readonly afterFormat: FormatId | 'auto';
|
|
21
|
+
/** `--lang`: RDF label language preference. */
|
|
22
|
+
readonly languages?: readonly string[];
|
|
23
|
+
readonly diff: DiffOptions;
|
|
24
|
+
readonly stat: boolean;
|
|
25
|
+
readonly nameStatus: boolean;
|
|
26
|
+
/** Output path, or `-` for stdout. */
|
|
27
|
+
readonly json?: string;
|
|
28
|
+
readonly delta?: string;
|
|
29
|
+
readonly markdown?: string;
|
|
30
|
+
readonly html?: string;
|
|
31
|
+
readonly open: boolean;
|
|
32
|
+
readonly pretty: boolean;
|
|
33
|
+
readonly title?: string;
|
|
34
|
+
readonly theme?: ThemePreference;
|
|
35
|
+
readonly mode?: ViewerMode;
|
|
36
|
+
readonly reproducible: boolean;
|
|
37
|
+
/** `--allow-empty`: an empty input is an empty graph instead of an error. */
|
|
38
|
+
readonly allowEmpty: boolean;
|
|
39
|
+
/** Inline the viewer's compute add-on when the report needs it (`--no-compute` disables). */
|
|
40
|
+
readonly compute: boolean;
|
|
41
|
+
readonly exitCode: boolean;
|
|
42
|
+
/** Max hunks in the summary; 0 = all. */
|
|
43
|
+
readonly limit: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ApplyCommandOptions extends CommonOptions {
|
|
46
|
+
readonly graph: string;
|
|
47
|
+
readonly delta: string;
|
|
48
|
+
/** Output path, or `-` for stdout. */
|
|
49
|
+
readonly output: string;
|
|
50
|
+
readonly strict: boolean;
|
|
51
|
+
readonly format: FormatId | 'auto';
|
|
52
|
+
readonly languages?: readonly string[];
|
|
53
|
+
readonly pretty: boolean;
|
|
54
|
+
/** `--allow-empty`: an empty <graph> is an empty graph instead of an error. */
|
|
55
|
+
readonly allowEmpty: boolean;
|
|
56
|
+
/** `--verbose`: list the operations `--no-strict` skipped. */
|
|
57
|
+
readonly verbose: boolean;
|
|
58
|
+
}
|
|
59
|
+
export type Command = {
|
|
60
|
+
readonly kind: 'help';
|
|
61
|
+
readonly topic: 'main' | 'apply';
|
|
62
|
+
readonly color: ColorMode;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: 'version';
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: 'diff';
|
|
67
|
+
readonly options: DiffCommandOptions;
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: 'apply';
|
|
70
|
+
readonly options: ApplyCommandOptions;
|
|
71
|
+
};
|
|
72
|
+
interface OptionSpec {
|
|
73
|
+
readonly type: 'boolean' | 'string';
|
|
74
|
+
readonly short?: string;
|
|
75
|
+
readonly multiple?: boolean;
|
|
76
|
+
/** `--json [file]`: a string option whose value may be omitted. */
|
|
77
|
+
readonly optionalValue?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** Options of `kgdiff <before> <after>`. */
|
|
80
|
+
export declare const DIFF_OPTIONS: Readonly<Record<string, OptionSpec>>;
|
|
81
|
+
/** Options of `kgdiff apply <graph> <delta>`. */
|
|
82
|
+
export declare const APPLY_OPTIONS: Readonly<Record<string, OptionSpec>>;
|
|
83
|
+
/** Edit distance (insertions, deletions, substitutions, adjacent transpositions). */
|
|
84
|
+
export declare function editDistance(a: string, b: string): number;
|
|
85
|
+
/** Closest candidate within a small edit distance (or sharing a prefix), if any. */
|
|
86
|
+
export declare function suggest(input: string, candidates: readonly string[]): string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Parse `argv` (without `node` and the script) into a command.
|
|
89
|
+
*
|
|
90
|
+
* @throws CliError `usage` with a message and a hint for any invalid command line.
|
|
91
|
+
*/
|
|
92
|
+
export declare function parseCommandLine(argv: readonly string[]): Command;
|
|
93
|
+
/** Best-effort `--color` value for printing an error about the command line itself. */
|
|
94
|
+
export declare function peekColorMode(argv: readonly string[]): ColorMode;
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,EAAgB,MAAM,cAAc,CAAC;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGlE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,gEAAgE;AAChE,eAAO,MAAM,KAAK,MAAM,CAAC;AAEzB,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC,EAUjD,CAAC;AAOF,yBAAyB;AACzB,eAAO,MAAM,aAAa,KAAK,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