@kgdiff/cli 0.0.0-stage → 0.2.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 +211 -2
- package/dist/apply-command.d.ts +34 -0
- package/dist/apply-command.d.ts.map +1 -0
- package/dist/apply-command.js +137 -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 +209 -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 +203 -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 +269 -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/dist/help.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { padEnd, stringWidth, wrap } from './width.js';
|
|
2
|
+
const MAIN = [
|
|
3
|
+
{
|
|
4
|
+
title: 'Usage',
|
|
5
|
+
lines: [
|
|
6
|
+
['kgdiff <before> <after> [options]'],
|
|
7
|
+
['kgdiff apply <graph> <delta> [-o <file>] [--no-strict]'],
|
|
8
|
+
],
|
|
9
|
+
note: 'Graphs: JSON (.json), JSON-LD (.jsonld), Turtle (.ttl), N-Triples (.nt), N-Quads (.nq), ' +
|
|
10
|
+
'TriG (.trig), RDF/XML (.rdf, .owl), OBO (.obo); gzip-compressed files work too. ' +
|
|
11
|
+
'Use - to read one side from stdin.',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
title: 'Output',
|
|
15
|
+
note: 'Default: a summary on stdout. Outputs combine, e.g. -o report.html --markdown summary.md',
|
|
16
|
+
entries: [
|
|
17
|
+
{
|
|
18
|
+
flags: '--stat',
|
|
19
|
+
text: 'Diffstat only: counters, bar, node and edge counts, changes by type',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
flags: '--name-status',
|
|
23
|
+
text: 'One line per hunk: A added, D removed, M modified, R renamed, V moved, G merged, S split, E relations',
|
|
24
|
+
},
|
|
25
|
+
{ flags: '--json [file]', text: 'Full machine-readable diff (DiffJSON)' },
|
|
26
|
+
{ flags: '--delta [file]', text: 'Invertible delta only, for kgdiff apply' },
|
|
27
|
+
{
|
|
28
|
+
flags: '--markdown [file]',
|
|
29
|
+
text: 'GitHub-flavoured Markdown for PR comments and job summaries',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
flags: '-o, --html <file>',
|
|
33
|
+
text: 'Self-contained interactive HTML report (works offline)',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
flags: '--open',
|
|
37
|
+
text: 'Open the HTML report in the browser (a temporary file without -o)',
|
|
38
|
+
},
|
|
39
|
+
{ flags: '--pretty', text: 'Indent JSON output' },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
title: 'Diff',
|
|
44
|
+
entries: [
|
|
45
|
+
{
|
|
46
|
+
flags: '-f, --format <fmt>',
|
|
47
|
+
text: 'Input format: auto, json, jsonld, turtle, ntriples, nquads, trig, rdfxml, obo',
|
|
48
|
+
default: 'auto',
|
|
49
|
+
},
|
|
50
|
+
{ flags: '--before-format <fmt>', text: 'Format of <before> only' },
|
|
51
|
+
{ flags: '--after-format <fmt>', text: 'Format of <after> only' },
|
|
52
|
+
{ flags: '--match <strategy>', text: 'Node matching: id, auto, similarity', default: 'auto' },
|
|
53
|
+
{ flags: '--threshold <n>', text: 'Similarity acceptance threshold, 0–1', default: '0.82' },
|
|
54
|
+
{
|
|
55
|
+
flags: '--edge-identity <mode>',
|
|
56
|
+
text: 'Edge identity: structure, id',
|
|
57
|
+
default: 'structure',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
flags: '--hierarchy <predicate>',
|
|
61
|
+
text: 'Hierarchy predicate (repeatable); replaces the defaults when given',
|
|
62
|
+
},
|
|
63
|
+
{ flags: '--ignore-attr <key>', text: 'Ignore an attribute when comparing (repeatable)' },
|
|
64
|
+
{ flags: '--no-merges', text: 'Do not detect merges' },
|
|
65
|
+
{ flags: '--no-splits', text: 'Do not detect splits' },
|
|
66
|
+
{
|
|
67
|
+
flags: '--lang <tags>',
|
|
68
|
+
text: 'RDF label language preference, comma-separated, e.g. zh,en',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
title: 'Report',
|
|
74
|
+
entries: [
|
|
75
|
+
{
|
|
76
|
+
flags: '--title <text>',
|
|
77
|
+
text: 'Title of the summary and report',
|
|
78
|
+
default: '<before> → <after>',
|
|
79
|
+
},
|
|
80
|
+
{ flags: '--theme <theme>', text: 'Initial theme: auto, light, dark', default: 'auto' },
|
|
81
|
+
{
|
|
82
|
+
flags: '--locale <locale>',
|
|
83
|
+
text: 'Language of hunk titles and the report: en, zh-CN',
|
|
84
|
+
default: 'from LANG, else en',
|
|
85
|
+
},
|
|
86
|
+
{ flags: '--mode <mode>', text: 'Initial viewer mode: overlay, swipe, replay, changes' },
|
|
87
|
+
{
|
|
88
|
+
flags: '--reproducible',
|
|
89
|
+
text: 'Omit the timestamp: byte-identical reports for identical input',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
flags: '--no-compute',
|
|
93
|
+
text: 'Leave out the viewer compute add-on (by default inlined for large graphs laid out around their changes, so collapsed groups can be expanded)',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
title: 'Behaviour',
|
|
99
|
+
entries: [
|
|
100
|
+
{
|
|
101
|
+
flags: '--exit-code',
|
|
102
|
+
text: 'Exit with 1 when the graphs differ, like git diff --exit-code',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
flags: '--allow-empty',
|
|
106
|
+
text: 'Treat an empty input as an empty graph (otherwise an empty file or stdin is an error)',
|
|
107
|
+
},
|
|
108
|
+
{ flags: '-q, --quiet', text: 'Print nothing on stdout (files are still written)' },
|
|
109
|
+
{
|
|
110
|
+
flags: '--color <when>',
|
|
111
|
+
text: 'auto, always, never (auto honours NO_COLOR and FORCE_COLOR)',
|
|
112
|
+
default: 'auto',
|
|
113
|
+
},
|
|
114
|
+
{ flags: '--limit <n>', text: 'Hunks listed in the summary; 0 lists all', default: '50' },
|
|
115
|
+
{ flags: '-h, --help', text: 'Show this help' },
|
|
116
|
+
{ flags: '-v, --version', text: 'Show the version' },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
title: 'Examples',
|
|
121
|
+
lines: [
|
|
122
|
+
['kgdiff v12.json v13.json', 'colored summary'],
|
|
123
|
+
['kgdiff old.obo new.obo -o report.html --open', 'interactive report'],
|
|
124
|
+
['kgdiff a.ttl b.ttl --markdown >> "$GITHUB_STEP_SUMMARY"', 'CI job summary'],
|
|
125
|
+
['kgdiff a.json b.json --exit-code -q', 'fail when the graphs differ'],
|
|
126
|
+
['kgdiff a.json b.json --delta patch.json', 'export a delta …'],
|
|
127
|
+
['kgdiff apply a.json patch.json -o b.json', '… and apply it'],
|
|
128
|
+
['curl -s https://example.org/latest.ttl | kgdiff pinned.ttl -', 'compare with stdin'],
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
title: 'Environment',
|
|
133
|
+
note: 'NO_COLOR, FORCE_COLOR (0–3) and COLORTERM control colors · LANG / LC_ALL the locale · ' +
|
|
134
|
+
'COLUMNS the width when piped · KGDIFF_MAX_INPUT the input size limit (default 1G, e.g. 4G) · ' +
|
|
135
|
+
'DEBUG=kgdiff prints stack traces',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
title: 'Exit status',
|
|
139
|
+
note: '0 success (and no differences with --exit-code) · 1 differences with --exit-code · 2 usage or input error',
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
const APPLY = [
|
|
143
|
+
{
|
|
144
|
+
title: 'Usage',
|
|
145
|
+
lines: [['kgdiff apply <graph> <delta> [-o <file>] [--no-strict]']],
|
|
146
|
+
note: 'Applies a kgdiff delta (from --delta, or the delta inside --json output) to a graph and ' +
|
|
147
|
+
'writes the result as kgdiff JSON. Use - to read the graph or the delta from stdin.',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
title: 'Options',
|
|
151
|
+
entries: [
|
|
152
|
+
{
|
|
153
|
+
flags: '-o, --output <file>',
|
|
154
|
+
text: 'Write the patched graph to a file',
|
|
155
|
+
default: 'stdout',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
flags: '--no-strict',
|
|
159
|
+
text: "Apply the operations that fit even if the graph is not the delta's base; reports how many were skipped",
|
|
160
|
+
},
|
|
161
|
+
{ flags: '--verbose', text: 'With --no-strict, list the skipped operations' },
|
|
162
|
+
{ flags: '--allow-empty', text: 'Treat an empty <graph> as an empty graph' },
|
|
163
|
+
{ flags: '-f, --format <fmt>', text: 'Format of <graph>', default: 'auto' },
|
|
164
|
+
{ flags: '--lang <tags>', text: 'RDF label language preference, e.g. zh,en' },
|
|
165
|
+
{ flags: '--pretty', text: 'Indent the JSON output' },
|
|
166
|
+
{ flags: '-q, --quiet', text: 'Print nothing on stdout' },
|
|
167
|
+
{ flags: '--color <when>', text: 'auto, always, never', default: 'auto' },
|
|
168
|
+
{ flags: '-h, --help', text: 'Show this help' },
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
title: 'Examples',
|
|
173
|
+
lines: [
|
|
174
|
+
['kgdiff v1.ttl v2.ttl --delta patch.json', 'make a delta'],
|
|
175
|
+
['kgdiff apply v1.ttl patch.json -o v2.json', 'apply it'],
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
title: 'Exit status',
|
|
180
|
+
note: '0 applied · 2 the delta does not fit the graph, or another error',
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
const INDENT = ' ';
|
|
184
|
+
const MAX_FLAGS = 26;
|
|
185
|
+
function paintFlags(flags, paint) {
|
|
186
|
+
return flags
|
|
187
|
+
.split(/(<[^>]+>|\[[^\]]+\])/)
|
|
188
|
+
.map((part) => part.startsWith('<') || part.startsWith('[') ? paint.dim(part) : paint.tone('accent', part))
|
|
189
|
+
.join('');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Render help text. `width` is the terminal width (descriptions wrap to it; below 60 columns
|
|
193
|
+
* they go under their flags).
|
|
194
|
+
*/
|
|
195
|
+
export function renderHelp(topic, version, paint, width) {
|
|
196
|
+
const sections = topic === 'apply' ? APPLY : MAIN;
|
|
197
|
+
const w = Math.max(40, Math.min(width, 100));
|
|
198
|
+
const flagWidth = Math.min(MAX_FLAGS, Math.max(...sections.flatMap((s) => (s.entries ?? []).map((e) => stringWidth(e.flags)))) + 2);
|
|
199
|
+
const stacked = w < 60;
|
|
200
|
+
const out = [
|
|
201
|
+
`${paint.bold(paint.tone('accent', 'kgdiff'))} ${version} ${paint.dim(topic === 'apply' ? 'apply a delta to a graph' : 'git diff for knowledge graphs')}`,
|
|
202
|
+
];
|
|
203
|
+
for (const section of sections) {
|
|
204
|
+
out.push('', paint.bold(section.title));
|
|
205
|
+
for (const [command, comment] of section.lines ?? []) {
|
|
206
|
+
const gap = Math.max(2, 58 - stringWidth(command));
|
|
207
|
+
if (comment && stringWidth(command) + gap + stringWidth(comment) + 4 <= w) {
|
|
208
|
+
out.push(`${INDENT}${command}${' '.repeat(gap)}${paint.dim(`# ${comment}`)}`);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (comment)
|
|
212
|
+
out.push(INDENT + paint.dim(`# ${comment}`));
|
|
213
|
+
// Long commands wrap with a hanging indent (narrow terminals).
|
|
214
|
+
wrap(command, w - INDENT.length - 4).forEach((line, i) => {
|
|
215
|
+
out.push(`${INDENT}${i > 0 ? ' ' : ''}${line}`);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (section.note && section.lines)
|
|
219
|
+
out.push('');
|
|
220
|
+
if (section.note) {
|
|
221
|
+
for (const line of wrap(section.note, w - INDENT.length))
|
|
222
|
+
out.push(INDENT + paint.dim(line));
|
|
223
|
+
}
|
|
224
|
+
for (const entry of section.entries ?? []) {
|
|
225
|
+
const room = stacked ? w - INDENT.length * 3 : w - INDENT.length - flagWidth;
|
|
226
|
+
const defaultText = entry.default ? `[default: ${entry.default}]` : '';
|
|
227
|
+
const wrapped = wrap(defaultText ? `${entry.text} ${defaultText}` : entry.text, room).map((line) => defaultText && line.endsWith(defaultText)
|
|
228
|
+
? line.slice(0, -defaultText.length) + paint.dim(defaultText)
|
|
229
|
+
: line);
|
|
230
|
+
const flagsPlain = entry.flags;
|
|
231
|
+
if (stacked || stringWidth(flagsPlain) >= flagWidth) {
|
|
232
|
+
out.push(INDENT + paintFlags(flagsPlain, paint));
|
|
233
|
+
for (const line of wrapped)
|
|
234
|
+
out.push(INDENT.repeat(stacked ? 3 : 1) + ' '.repeat(stacked ? 0 : flagWidth) + line);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
wrapped.forEach((line, i) => {
|
|
238
|
+
const lead = i === 0
|
|
239
|
+
? paintFlags(flagsPlain, paint) + ' '.repeat(flagWidth - stringWidth(flagsPlain))
|
|
240
|
+
: padEnd('', flagWidth);
|
|
241
|
+
out.push(INDENT + lead + line);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return `${out.join('\n')}\n`;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=help.js.map
|
package/dist/help.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAgBvD,MAAM,IAAI,GAAuB;IAC/B;QACE,KAAK,EAAE,OAAO;QACd,KAAK,EAAE;YACL,CAAC,mCAAmC,CAAC;YACrC,CAAC,wDAAwD,CAAC;SAC3D;QACD,IAAI,EACF,0FAA0F;YAC1F,kFAAkF;YAClF,oCAAoC;KACvC;IACD;QACE,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,0FAA0F;QAChG,OAAO,EAAE;YACP;gBACE,KAAK,EAAE,QAAQ;gBACf,IAAI,EAAE,qEAAqE;aAC5E;YACD;gBACE,KAAK,EAAE,eAAe;gBACtB,IAAI,EAAE,uGAAuG;aAC9G;YACD,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,uCAAuC,EAAE;YACzE,EAAE,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,yCAAyC,EAAE;YAC5E;gBACE,KAAK,EAAE,mBAAmB;gBA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CAAC;gBAC7D,CAAC,CAAC,IAAI,CACX,CAAC;YACF,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;YAC/B,IAAI,OAAO,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,SAAS,EAAE,CAAC;gBACpD,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjD,KAAK,MAAM,IAAI,IAAI,OAAO;oBACxB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;gBACxF,SAAS;YACX,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;gBAC1B,MAAM,IAAI,GACR,CAAC,KAAK,CAAC;oBACL,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;oBACjF,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;gBAC5B,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/B,CAAC"}
|
package/dist/html.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single-file HTML report (docs/cli.md §HTML report): the standalone viewer bundle and the
|
|
3
|
+
* `ReportPayload` inlined in one accessible document that works offline.
|
|
4
|
+
*
|
|
5
|
+
* Pure: compression is injected, so the same inputs always give the same bytes.
|
|
6
|
+
*/
|
|
7
|
+
import type { ReportPayload } from '@kgdiff/viewer';
|
|
8
|
+
/** MIME type of the payload script (`PAYLOAD_SCRIPT_TYPE` in `@kgdiff/viewer`). */
|
|
9
|
+
export declare const PAYLOAD_TYPE = "application/kgdiff+json";
|
|
10
|
+
/** Payloads larger than this (UTF-8 bytes of the JSON) are embedded gzip + base64. */
|
|
11
|
+
export declare const GZIP_THRESHOLD: number;
|
|
12
|
+
/** Escape text for HTML element content and double-quoted attribute values. */
|
|
13
|
+
export declare function escapeHtml(text: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* JSON that is safe inside a `<script>` element: `<` is written as `<` (so neither
|
|
16
|
+
* `</script` nor `<!--` can appear), and U+2028 / U+2029 are escaped. Still valid JSON.
|
|
17
|
+
*/
|
|
18
|
+
export declare function scriptSafeJson(json: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Make inline JavaScript safe inside a classic `<script>` element: `</script` becomes
|
|
21
|
+
* `<\/script` and `<!--` becomes `\x3C!--`. Both rewrites keep string, template and regular
|
|
22
|
+
* expression literals equivalent (the only places such sequences occur in real bundles).
|
|
23
|
+
*/
|
|
24
|
+
export declare function scriptSafeJs(code: string): string;
|
|
25
|
+
export interface ReportHtmlOptions {
|
|
26
|
+
readonly payload: ReportPayload;
|
|
27
|
+
/** Source of the standalone viewer bundle (an IIFE). */
|
|
28
|
+
readonly bundle: string;
|
|
29
|
+
/**
|
|
30
|
+
* Source of the optional compute add-on (diff / layout in the browser, an IIFE that sets
|
|
31
|
+
* `globalThis.KgdiffCompute`), inlined right after the viewer bundle when given.
|
|
32
|
+
*/
|
|
33
|
+
readonly compute?: string;
|
|
34
|
+
/** gzip compressor used for large payloads. Must be deterministic. */
|
|
35
|
+
readonly gzip: (data: Uint8Array) => Uint8Array;
|
|
36
|
+
/** Short description for `<meta name="description">` and `<noscript>`. */
|
|
37
|
+
readonly description: string;
|
|
38
|
+
/** Payload size above which it is compressed. Default `GZIP_THRESHOLD`. */
|
|
39
|
+
readonly gzipThreshold?: number;
|
|
40
|
+
}
|
|
41
|
+
/** Payload as embedded text plus its `data-encoding` (none, or `gzip-base64`). */
|
|
42
|
+
export declare function encodePayload(payload: ReportPayload, gzip: (data: Uint8Array) => Uint8Array, threshold?: number): {
|
|
43
|
+
readonly text: string;
|
|
44
|
+
readonly encoding?: 'gzip-base64';
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Render the report document: `<!doctype html>`, `lang`, charset, viewport, title, an inline
|
|
48
|
+
* style that paints the theme background before the viewer loads (no white flash), a
|
|
49
|
+
* full-viewport `<kgdiff-viewer>`, the payload script, the inlined viewer bundle and, when
|
|
50
|
+
* given, the compute add-on.
|
|
51
|
+
*/
|
|
52
|
+
export declare function renderReportHtml(options: ReportHtmlOptions): string;
|
|
53
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,gBAAgB,CAAC;AAGrE,mFAAmF;AACnF,eAAO,MAAM,YAAY,4BAA4B,CAAC;AAEtD,sFAAsF;AACtF,eAAO,MAAM,cAAc,QAAa,CAAC;AAQzC,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO/C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC;IAChD,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAUD,kFAAkF;AAClF,wBAAgB,aAAa,CAC3B,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,EACtC,SAAS,SAAiB,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAE,CAK9D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAkDnE"}
|
package/dist/html.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { sanitize } from './width.js';
|
|
2
|
+
/** MIME type of the payload script (`PAYLOAD_SCRIPT_TYPE` in `@kgdiff/viewer`). */
|
|
3
|
+
export const PAYLOAD_TYPE = 'application/kgdiff+json';
|
|
4
|
+
/** Payloads larger than this (UTF-8 bytes of the JSON) are embedded gzip + base64. */
|
|
5
|
+
export const GZIP_THRESHOLD = 512 * 1024;
|
|
6
|
+
const VIEWER_ID = 'kgdiff';
|
|
7
|
+
/** Theme backgrounds (docs/visual-language.md `canvas.background`, `text.primary`). */
|
|
8
|
+
const DARK = { background: '#0B0E14', text: '#E7EBF3' };
|
|
9
|
+
const LIGHT = { background: '#F7F8FA', text: '#0F172A' };
|
|
10
|
+
/** Escape text for HTML element content and double-quoted attribute values. */
|
|
11
|
+
export function escapeHtml(text) {
|
|
12
|
+
return text
|
|
13
|
+
.replace(/&/g, '&')
|
|
14
|
+
.replace(/</g, '<')
|
|
15
|
+
.replace(/>/g, '>')
|
|
16
|
+
.replace(/"/g, '"')
|
|
17
|
+
.replace(/'/g, ''');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* JSON that is safe inside a `<script>` element: `<` is written as `<` (so neither
|
|
21
|
+
* `</script` nor `<!--` can appear), and U+2028 / U+2029 are escaped. Still valid JSON.
|
|
22
|
+
*/
|
|
23
|
+
export function scriptSafeJson(json) {
|
|
24
|
+
return json
|
|
25
|
+
.replace(/</g, '\\u003c')
|
|
26
|
+
.replace(/\u2028/g, '\\u2028')
|
|
27
|
+
.replace(/\u2029/g, '\\u2029');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Make inline JavaScript safe inside a classic `<script>` element: `</script` becomes
|
|
31
|
+
* `<\/script` and `<!--` becomes `\x3C!--`. Both rewrites keep string, template and regular
|
|
32
|
+
* expression literals equivalent (the only places such sequences occur in real bundles).
|
|
33
|
+
*/
|
|
34
|
+
export function scriptSafeJs(code) {
|
|
35
|
+
return code.replace(/<\/(script)/gi, '<\\/$1').replace(/<!--/g, '\\x3C!--');
|
|
36
|
+
}
|
|
37
|
+
function themeStyle(theme) {
|
|
38
|
+
const rule = (c) => `html,body{background:${c.background};color:${c.text}}`;
|
|
39
|
+
if (theme === 'dark')
|
|
40
|
+
return `:root{color-scheme:dark}${rule(DARK)}`;
|
|
41
|
+
if (theme === 'light')
|
|
42
|
+
return `:root{color-scheme:light}${rule(LIGHT)}`;
|
|
43
|
+
return `:root{color-scheme:dark light}${rule(DARK)}@media (prefers-color-scheme:light){${rule(LIGHT)}}`;
|
|
44
|
+
}
|
|
45
|
+
/** Payload as embedded text plus its `data-encoding` (none, or `gzip-base64`). */
|
|
46
|
+
export function encodePayload(payload, gzip, threshold = GZIP_THRESHOLD) {
|
|
47
|
+
const json = JSON.stringify(payload);
|
|
48
|
+
const bytes = new TextEncoder().encode(json);
|
|
49
|
+
if (bytes.byteLength <= threshold)
|
|
50
|
+
return { text: scriptSafeJson(json) };
|
|
51
|
+
return { text: Buffer.from(gzip(bytes)).toString('base64'), encoding: 'gzip-base64' };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Render the report document: `<!doctype html>`, `lang`, charset, viewport, title, an inline
|
|
55
|
+
* style that paints the theme background before the viewer loads (no white flash), a
|
|
56
|
+
* full-viewport `<kgdiff-viewer>`, the payload script, the inlined viewer bundle and, when
|
|
57
|
+
* given, the compute add-on.
|
|
58
|
+
*/
|
|
59
|
+
export function renderReportHtml(options) {
|
|
60
|
+
const { payload } = options;
|
|
61
|
+
const view = payload.view ?? {};
|
|
62
|
+
const theme = view.theme ?? 'auto';
|
|
63
|
+
const locale = view.locale ?? 'en';
|
|
64
|
+
// Titles come from graph metadata: no control or bidi characters in the tab title.
|
|
65
|
+
const title = sanitize(payload.meta.title ?? `${payload.meta.before.name} → ${payload.meta.after.name}`);
|
|
66
|
+
const description = sanitize(options.description);
|
|
67
|
+
const encoded = encodePayload(payload, options.gzip, options.gzipThreshold);
|
|
68
|
+
const attrs = [
|
|
69
|
+
`id="${VIEWER_ID}"`,
|
|
70
|
+
// The report page is the viewer: its keyboard shortcuts apply to the whole page.
|
|
71
|
+
'global-shortcuts',
|
|
72
|
+
`theme="${escapeHtml(theme)}"`,
|
|
73
|
+
`locale="${escapeHtml(locale)}"`,
|
|
74
|
+
...(view.mode ? [`mode="${escapeHtml(view.mode)}"`] : []),
|
|
75
|
+
].join(' ');
|
|
76
|
+
const encodingAttr = encoded.encoding ? ` data-encoding="${encoded.encoding}"` : '';
|
|
77
|
+
const style = `${themeStyle(theme)}html,body{margin:0;height:100%;overflow:hidden}` +
|
|
78
|
+
'kgdiff-viewer{display:block;position:fixed;inset:0;width:100%;height:100%}' +
|
|
79
|
+
'.kgdiff-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;' +
|
|
80
|
+
'clip:rect(0 0 0 0);white-space:nowrap;border:0}' +
|
|
81
|
+
'noscript p{font:15px/1.5 system-ui,sans-serif;margin:2rem;max-width:40rem}';
|
|
82
|
+
return [
|
|
83
|
+
'<!doctype html>',
|
|
84
|
+
`<html lang="${escapeHtml(locale)}">`,
|
|
85
|
+
'<head>',
|
|
86
|
+
'<meta charset="utf-8">',
|
|
87
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
|
88
|
+
`<meta name="generator" content="${escapeHtml(payload.meta.generator)}">`,
|
|
89
|
+
`<meta name="description" content="${escapeHtml(description)}">`,
|
|
90
|
+
`<title>${escapeHtml(title)} · kgdiff</title>`,
|
|
91
|
+
`<style>${style}</style>`,
|
|
92
|
+
'</head>',
|
|
93
|
+
'<body>',
|
|
94
|
+
'<main>',
|
|
95
|
+
`<h1 class="kgdiff-sr">${escapeHtml(title)}</h1>`,
|
|
96
|
+
`<kgdiff-viewer ${attrs}></kgdiff-viewer>`,
|
|
97
|
+
`<noscript><p>${escapeHtml(description)}. This interactive report needs JavaScript.</p></noscript>`,
|
|
98
|
+
'</main>',
|
|
99
|
+
`<script type="${PAYLOAD_TYPE}" data-for="${VIEWER_ID}"${encodingAttr}>${encoded.text}</script>`,
|
|
100
|
+
`<script>${scriptSafeJs(options.bundle)}</script>`,
|
|
101
|
+
...(options.compute !== undefined ? [`<script>${scriptSafeJs(options.compute)}</script>`] : []),
|
|
102
|
+
'</body>',
|
|
103
|
+
'</html>',
|
|
104
|
+
'',
|
|
105
|
+
].join('\n');
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=html.js.map
|
package/dist/html.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,mFAAmF;AACnF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAEtD,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,GAAG,IAAI,CAAC;AAEzC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAE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,CAAC,CAAC,CAAC,CAAC,WAAW,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,SAAS;QACT,SAAS;QACT,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kgdiff CLI: `kgdiff <before> <after>` and `kgdiff apply <graph> <delta>` (docs/cli.md).
|
|
3
|
+
*
|
|
4
|
+
* `main` runs the CLI in-process against an injected `CliIO` (see `nodeIO` for the real one);
|
|
5
|
+
* the building blocks below are pure and reusable: argument parsing, terminal rendering,
|
|
6
|
+
* Markdown, the HTML report and the width / color helpers they rest on.
|
|
7
|
+
*/
|
|
8
|
+
export { readDelta } from './apply-command.js';
|
|
9
|
+
export { type ApplyCommandOptions, type Command, type CommonOptions, DEFAULT_LIMIT, type DiffCommandOptions, parseCommandLine, STDIO, } from './args.js';
|
|
10
|
+
export { defaultTitle, describeDiff, graphLabel, outputWidth } from './diff-command.js';
|
|
11
|
+
export { CliError, type CliErrorCode, describeError, formatError } from './errors.js';
|
|
12
|
+
export { renderHelp } from './help.js';
|
|
13
|
+
export { encodePayload, escapeHtml, GZIP_THRESHOLD, PAYLOAD_TYPE, type ReportHtmlOptions, renderReportHtml, scriptSafeJs, scriptSafeJson, } from './html.js';
|
|
14
|
+
export type { CliFileSystem, CliIO, OutputStream } from './io.js';
|
|
15
|
+
export { formatInt, matchLocale, messages, resolveLocale } from './locale.js';
|
|
16
|
+
export { main } from './main.js';
|
|
17
|
+
export { escapeMarkdown, MARKDOWN_HUNK_LIMIT, type MarkdownOptions, renderMarkdown, } from './markdown.js';
|
|
18
|
+
export { type ChangeFamily, hunkFamily, hunkGlyph, KIND_FAMILY, type NameStatus, nameStatus, type Overview, overview, } from './model.js';
|
|
19
|
+
export { nodeIO, openCommand } from './node-io.js';
|
|
20
|
+
export { buildReportHtml, buildReportPayload, createGzip, type ReportInfo } from './report.js';
|
|
21
|
+
export { type ColorLevel, type ColorMode, createPainter, type Painter, resolveColorLevel, stripAnsi, type Tone, } from './style.js';
|
|
22
|
+
export { diffstatBar, renderNameStatus, renderStat, renderSummary, type TextContext, totalsText, } from './summary.js';
|
|
23
|
+
export { cliVersion } from './version.js';
|
|
24
|
+
export { graphemeWidth, padEnd, padStart, sanitize, stringWidth, truncate, wrap } from './width.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EACZ,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,YAAY,EACZ,cAAc,GACf,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,KAAK,eAAe,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,YAAY,EACjB,UAAU,EACV,SAAS,EACT,WAAW,EACX,KAAK,UAAU,EACf,UAAU,EACV,KAAK,QAAQ,EACb,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,aAAa,EACb,KAAK,OAAO,EACZ,iBAAiB,EACjB,SAAS,EACT,KAAK,IAAI,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,KAAK,WAAW,EAChB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kgdiff CLI: `kgdiff <before> <after>` and `kgdiff apply <graph> <delta>` (docs/cli.md).
|
|
3
|
+
*
|
|
4
|
+
* `main` runs the CLI in-process against an injected `CliIO` (see `nodeIO` for the real one);
|
|
5
|
+
* the building blocks below are pure and reusable: argument parsing, terminal rendering,
|
|
6
|
+
* Markdown, the HTML report and the width / color helpers they rest on.
|
|
7
|
+
*/
|
|
8
|
+
export { readDelta } from './apply-command.js';
|
|
9
|
+
export { DEFAULT_LIMIT, parseCommandLine, STDIO, } from './args.js';
|
|
10
|
+
export { defaultTitle, describeDiff, graphLabel, outputWidth } from './diff-command.js';
|
|
11
|
+
export { CliError, describeError, formatError } from './errors.js';
|
|
12
|
+
export { renderHelp } from './help.js';
|
|
13
|
+
export { encodePayload, escapeHtml, GZIP_THRESHOLD, PAYLOAD_TYPE, renderReportHtml, scriptSafeJs, scriptSafeJson, } from './html.js';
|
|
14
|
+
export { formatInt, matchLocale, messages, resolveLocale } from './locale.js';
|
|
15
|
+
export { main } from './main.js';
|
|
16
|
+
export { escapeMarkdown, MARKDOWN_HUNK_LIMIT, renderMarkdown, } from './markdown.js';
|
|
17
|
+
export { hunkFamily, hunkGlyph, KIND_FAMILY, nameStatus, overview, } from './model.js';
|
|
18
|
+
export { nodeIO, openCommand } from './node-io.js';
|
|
19
|
+
export { buildReportHtml, buildReportPayload, createGzip } from './report.js';
|
|
20
|
+
export { createPainter, resolveColorLevel, stripAnsi, } from './style.js';
|
|
21
|
+
export { diffstatBar, renderNameStatus, renderStat, renderSummary, totalsText, } from './summary.js';
|
|
22
|
+
export { cliVersion } from './version.js';
|
|
23
|
+
export { graphemeWidth, padEnd, padStart, sanitize, stringWidth, truncate, wrap } from './width.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAIL,aAAa,EAEb,gBAAgB,EAChB,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAqB,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,YAAY,EAEZ,gBAAgB,EAChB,YAAY,EACZ,cAAc,GACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,cAAc,EACd,mBAAmB,EAEnB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,UAAU,EACV,SAAS,EACT,WAAW,EAEX,UAAU,EAEV,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAC/F,OAAO,EAGL,aAAa,EAEb,iBAAiB,EACjB,SAAS,GAEV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,aAAa,EAEb,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/inputs.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type FormatId, type ParseResult } from '@kgdiff/formats';
|
|
2
|
+
import type { CliIO } from './io.js';
|
|
3
|
+
import type { Env } from './style.js';
|
|
4
|
+
export declare const FORMAT_NAMES: Readonly<Record<FormatId, string>>;
|
|
5
|
+
export interface RawInput {
|
|
6
|
+
/** How the input is called in messages: the path as given, or `stdin`. */
|
|
7
|
+
readonly display: string;
|
|
8
|
+
/** File name without directories and without `.gz` (format detection, `meta.source`). */
|
|
9
|
+
readonly filename?: string;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
/** True for empty or whitespace-only input (only returned with `allowEmpty`). */
|
|
12
|
+
readonly empty: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Resolve a user-supplied path against the IO's working directory. */
|
|
15
|
+
export declare function resolvePath(io: CliIO, path: string): string;
|
|
16
|
+
/** Default input size limit (bytes, after decompression): 1 GiB. */
|
|
17
|
+
export declare const DEFAULT_MAX_INPUT: number;
|
|
18
|
+
/**
|
|
19
|
+
* Input size limit: `KGDIFF_MAX_INPUT` (bytes, or with a binary `K` / `M` / `G` suffix, e.g.
|
|
20
|
+
* `4G`), else `DEFAULT_MAX_INPUT`. Applies to files, stdin and decompressed gzip data.
|
|
21
|
+
*
|
|
22
|
+
* @throws CliError `usage` for an unreadable value.
|
|
23
|
+
*/
|
|
24
|
+
export declare function maxInputBytes(env: Env): number;
|
|
25
|
+
/**
|
|
26
|
+
* Decode input bytes: gunzip when gzip-compressed (output capped at `limit`, so a gzip bomb is
|
|
27
|
+
* an error, not an out-of-memory crash), UTF-16 by BOM, else strict UTF-8.
|
|
28
|
+
*/
|
|
29
|
+
export declare function decodeText(bytes: Uint8Array, where: string, limit: number): Promise<string>;
|
|
30
|
+
export interface ReadOptions {
|
|
31
|
+
/** Accept an empty (or whitespace-only) input as an empty graph (`--allow-empty`). */
|
|
32
|
+
readonly allowEmpty?: boolean;
|
|
33
|
+
/** Hint shown when the input is empty and that is not allowed. */
|
|
34
|
+
readonly emptyHint?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Read a file (or stdin for `-`) as text. `role` names the argument in messages. Inputs above
|
|
38
|
+
* the size limit, and empty inputs unless `allowEmpty`, are errors.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readInput(io: CliIO, path: string, role: string, options?: ReadOptions): Promise<RawInput>;
|
|
41
|
+
/**
|
|
42
|
+
* Read two inputs concurrently; when both fail, the first one's error is reported (so the
|
|
43
|
+
* message does not depend on which read finished first).
|
|
44
|
+
*/
|
|
45
|
+
export declare function readPair(first: Promise<RawInput>, second: Promise<RawInput>): Promise<[RawInput, RawInput]>;
|
|
46
|
+
export interface GraphParseOptions {
|
|
47
|
+
readonly format: FormatId | 'auto';
|
|
48
|
+
readonly languages?: readonly string[];
|
|
49
|
+
/** Flag that overrides the format of this input, for hints (`--before-format`). */
|
|
50
|
+
readonly formatFlag: string;
|
|
51
|
+
}
|
|
52
|
+
/** Parse a graph, turning parser errors into messages that name the input. */
|
|
53
|
+
export declare function parseInput(input: RawInput, options: GraphParseOptions): ParseResult;
|
|
54
|
+
//# sourceMappingURL=inputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,QAAQ,EAAqB,KAAK,WAAW,EAAc,MAAM,iBAAiB,CAAC;AAGjG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGtC,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAS3D,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAQD,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,QAAY,CAAC;AAI3C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAa9C;A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