aontu 0.52.0 → 0.53.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/README.md +88 -0
- package/bin/aontu-mcp.js +4 -0
- package/dist/agentsmd.d.ts +16 -0
- package/dist/agentsmd.js +107 -0
- package/dist/agentsmd.js.map +1 -0
- package/dist/aontu.d.ts +14 -3
- package/dist/aontu.js +145 -4
- package/dist/aontu.js.map +1 -1
- package/dist/cli.d.ts +44 -1
- package/dist/cli.js +2401 -44
- package/dist/cli.js.map +1 -1
- package/dist/ctx.d.ts +16 -0
- package/dist/ctx.js +44 -0
- package/dist/ctx.js.map +1 -1
- package/dist/diff.d.ts +22 -0
- package/dist/diff.js +141 -0
- package/dist/diff.js.map +1 -0
- package/dist/err.d.ts +3 -1
- package/dist/err.js +48 -8
- package/dist/err.js.map +1 -1
- package/dist/graph.d.ts +16 -0
- package/dist/graph.js +73 -0
- package/dist/graph.js.map +1 -0
- package/dist/hcanon.d.ts +3 -0
- package/dist/hcanon.js +146 -0
- package/dist/hcanon.js.map +1 -0
- package/dist/hints.js +223 -5
- package/dist/hints.js.map +1 -1
- package/dist/jsonschema.d.ts +20 -0
- package/dist/jsonschema.js +391 -0
- package/dist/jsonschema.js.map +1 -0
- package/dist/lang.js +698 -35
- package/dist/lang.js.map +1 -1
- package/dist/lsp.d.ts +9 -2
- package/dist/lsp.js +262 -46
- package/dist/lsp.js.map +1 -1
- package/dist/mcp-server.d.ts +20 -0
- package/dist/mcp-server.js +147 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp.d.ts +42 -0
- package/dist/mcp.js +814 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mod-tool.d.ts +58 -0
- package/dist/mod-tool.js +498 -0
- package/dist/mod-tool.js.map +1 -0
- package/dist/mod.d.ts +31 -0
- package/dist/mod.js +250 -0
- package/dist/mod.js.map +1 -0
- package/dist/patch.d.ts +44 -0
- package/dist/patch.js +506 -0
- package/dist/patch.js.map +1 -0
- package/dist/provenance.d.ts +40 -0
- package/dist/provenance.js +335 -0
- package/dist/provenance.js.map +1 -0
- package/dist/query.d.ts +27 -0
- package/dist/query.js +294 -0
- package/dist/query.js.map +1 -0
- package/dist/reach.d.ts +14 -0
- package/dist/reach.js +140 -0
- package/dist/reach.js.map +1 -0
- package/dist/relation.d.ts +19 -0
- package/dist/relation.js +305 -0
- package/dist/relation.js.map +1 -0
- package/dist/report-sarif.d.ts +14 -0
- package/dist/report-sarif.js +102 -0
- package/dist/report-sarif.js.map +1 -0
- package/dist/site.d.ts +4 -0
- package/dist/site.js +31 -0
- package/dist/site.js.map +1 -1
- package/dist/std.d.ts +1 -0
- package/dist/std.js +73 -0
- package/dist/std.js.map +1 -0
- package/dist/subsume.d.ts +39 -0
- package/dist/subsume.js +526 -0
- package/dist/subsume.js.map +1 -0
- package/dist/trim.d.ts +19 -0
- package/dist/trim.js +155 -0
- package/dist/trim.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +17 -1
- package/dist/type.js.map +1 -1
- package/dist/unify.d.ts +3 -1
- package/dist/unify.js +287 -18
- package/dist/unify.js.map +1 -1
- package/dist/utility.d.ts +9 -1
- package/dist/utility.js +122 -1
- package/dist/utility.js.map +1 -1
- package/dist/val/AggFuncVal.d.ts +33 -0
- package/dist/val/AggFuncVal.js +202 -0
- package/dist/val/AggFuncVal.js.map +1 -0
- package/dist/val/ArithFuncVal.d.ts +31 -0
- package/dist/val/ArithFuncVal.js +62 -0
- package/dist/val/ArithFuncVal.js.map +1 -0
- package/dist/val/BagVal.d.ts +5 -0
- package/dist/val/BagVal.js +96 -5
- package/dist/val/BagVal.js.map +1 -1
- package/dist/val/CloseFuncVal.js +9 -1
- package/dist/val/CloseFuncVal.js.map +1 -1
- package/dist/val/ConjunctVal.d.ts +1 -1
- package/dist/val/ConjunctVal.js +19 -0
- package/dist/val/ConjunctVal.js.map +1 -1
- package/dist/val/ConstraintVal.d.ts +48 -1
- package/dist/val/ConstraintVal.js +1501 -110
- package/dist/val/ConstraintVal.js.map +1 -1
- package/dist/val/CopyFuncVal.d.ts +1 -2
- package/dist/val/CopyFuncVal.js +7 -0
- package/dist/val/CopyFuncVal.js.map +1 -1
- package/dist/val/Decimal.d.ts +1 -0
- package/dist/val/Decimal.js +13 -0
- package/dist/val/Decimal.js.map +1 -1
- package/dist/val/DeprecateFuncVal.d.ts +11 -0
- package/dist/val/DeprecateFuncVal.js +47 -0
- package/dist/val/DeprecateFuncVal.js.map +1 -0
- package/dist/val/DisjunctVal.js +130 -21
- package/dist/val/DisjunctVal.js.map +1 -1
- package/dist/val/EachFuncVal.d.ts +15 -0
- package/dist/val/EachFuncVal.js +75 -0
- package/dist/val/EachFuncVal.js.map +1 -0
- package/dist/val/ExpectVal.d.ts +1 -0
- package/dist/val/ExpectVal.js +41 -4
- package/dist/val/ExpectVal.js.map +1 -1
- package/dist/val/FeatureVal.js +1 -1
- package/dist/val/FeatureVal.js.map +1 -1
- package/dist/val/FilterFuncVal.d.ts +15 -0
- package/dist/val/FilterFuncVal.js +91 -0
- package/dist/val/FilterFuncVal.js.map +1 -0
- package/dist/val/FuncBaseVal.d.ts +6 -1
- package/dist/val/FuncBaseVal.js +178 -2
- package/dist/val/FuncBaseVal.js.map +1 -1
- package/dist/val/HideFuncVal.js.map +1 -1
- package/dist/val/IdFuncVal.d.ts +13 -0
- package/dist/val/IdFuncVal.js +54 -0
- package/dist/val/IdFuncVal.js.map +1 -0
- package/dist/val/JunctionVal.js +7 -1
- package/dist/val/JunctionVal.js.map +1 -1
- package/dist/val/KeyFuncVal.d.ts +1 -1
- package/dist/val/KeyFuncVal.js +38 -30
- package/dist/val/KeyFuncVal.js.map +1 -1
- package/dist/val/ListVal.js +117 -17
- package/dist/val/ListVal.js.map +1 -1
- package/dist/val/LowerFuncVal.js.map +1 -1
- package/dist/val/MapVal.js +102 -8
- package/dist/val/MapVal.js.map +1 -1
- package/dist/val/MatchFuncVal.d.ts +15 -0
- package/dist/val/MatchFuncVal.js +107 -0
- package/dist/val/MatchFuncVal.js.map +1 -0
- package/dist/val/MoveFuncVal.js.map +1 -1
- package/dist/val/NilVal.js +24 -0
- package/dist/val/NilVal.js.map +1 -1
- package/dist/val/OpBaseVal.d.ts +1 -1
- package/dist/val/OpBaseVal.js +24 -2
- package/dist/val/OpBaseVal.js.map +1 -1
- package/dist/val/OpenFuncVal.js +4 -1
- package/dist/val/OpenFuncVal.js.map +1 -1
- package/dist/val/PackFuncVal.d.ts +15 -0
- package/dist/val/PackFuncVal.js +108 -0
- package/dist/val/PackFuncVal.js.map +1 -0
- package/dist/val/PathFuncVal.js.map +1 -1
- package/dist/val/PlaceVal.d.ts +13 -0
- package/dist/val/PlaceVal.js +131 -0
- package/dist/val/PlaceVal.js.map +1 -0
- package/dist/val/PlusOpVal.js +11 -2
- package/dist/val/PlusOpVal.js.map +1 -1
- package/dist/val/PrefFuncVal.js.map +1 -1
- package/dist/val/PrefVal.d.ts +2 -2
- package/dist/val/PrefVal.js +78 -23
- package/dist/val/PrefVal.js.map +1 -1
- package/dist/val/RefVal.d.ts +1 -1
- package/dist/val/RefVal.js +158 -30
- package/dist/val/RefVal.js.map +1 -1
- package/dist/val/ReferFuncVal.d.ts +36 -0
- package/dist/val/ReferFuncVal.js +303 -0
- package/dist/val/ReferFuncVal.js.map +1 -0
- package/dist/val/ScalarKindVal.d.ts +1 -2
- package/dist/val/ScalarKindVal.js +0 -11
- package/dist/val/ScalarKindVal.js.map +1 -1
- package/dist/val/TopVal.js.map +1 -1
- package/dist/val/TypeFuncVal.js.map +1 -1
- package/dist/val/UpperFuncVal.js.map +1 -1
- package/dist/val/Val.d.ts +9 -2
- package/dist/val/Val.js +150 -4
- package/dist/val/Val.js.map +1 -1
- package/dist/val/VarVal.js.map +1 -1
- package/dist/val/arith.d.ts +6 -0
- package/dist/val/arith.js +170 -0
- package/dist/val/arith.js.map +1 -0
- package/dist/vet.d.ts +45 -0
- package/dist/vet.js +776 -0
- package/dist/vet.js.map +1 -0
- package/dist/walk.d.ts +2 -0
- package/dist/walk.js +91 -0
- package/dist/walk.js.map +1 -0
- package/grammar/aontu.gbnf +130 -0
- package/grammar/aontu.lark +113 -0
- package/package.json +30 -15
- package/skill/SKILL.md +37 -0
- package/skill/error-codes.md +62 -0
- package/skill/examples.md +99 -0
- package/skill/grammar-card.md +57 -0
- package/src/agentsmd.ts +135 -0
- package/src/aontu.ts +192 -4
- package/src/cli.ts +2858 -71
- package/src/ctx.ts +81 -0
- package/src/diff.ts +196 -0
- package/src/err.ts +52 -8
- package/src/graph.ts +135 -0
- package/src/hcanon.ts +169 -0
- package/src/hints.ts +271 -5
- package/src/jsonschema.ts +511 -0
- package/src/lang.ts +779 -37
- package/src/lsp.ts +281 -47
- package/src/mcp-server.ts +187 -0
- package/src/mcp.ts +993 -0
- package/src/mod-tool.ts +679 -0
- package/src/mod.ts +344 -0
- package/src/patch.ts +624 -0
- package/src/provenance.ts +430 -0
- package/src/query.ts +379 -0
- package/src/reach.ts +184 -0
- package/src/relation.ts +395 -0
- package/src/report-sarif.ts +137 -0
- package/src/site.ts +36 -1
- package/src/std.ts +73 -0
- package/src/subsume.ts +690 -0
- package/src/trim.ts +195 -0
- package/src/tsconfig.json +10 -4
- package/src/type.ts +51 -2
- package/src/unify.ts +311 -16
- package/src/utility.ts +139 -1
- package/src/val/AggFuncVal.ts +319 -0
- package/src/val/ArithFuncVal.ts +108 -0
- package/src/val/BagVal.ts +101 -4
- package/src/val/CloseFuncVal.ts +9 -1
- package/src/val/ConjunctVal.ts +20 -0
- package/src/val/ConstraintVal.ts +1699 -116
- package/src/val/CopyFuncVal.ts +7 -1
- package/src/val/Decimal.ts +15 -0
- package/src/val/DeprecateFuncVal.ts +84 -0
- package/src/val/DisjunctVal.ts +139 -28
- package/src/val/EachFuncVal.ts +133 -0
- package/src/val/ExpectVal.ts +43 -6
- package/src/val/FeatureVal.ts +1 -1
- package/src/val/FilterFuncVal.ts +154 -0
- package/src/val/FuncBaseVal.ts +200 -3
- package/src/val/HideFuncVal.ts +0 -2
- package/src/val/IdFuncVal.ts +91 -0
- package/src/val/JunctionVal.ts +7 -1
- package/src/val/KeyFuncVal.ts +39 -35
- package/src/val/ListVal.ts +125 -18
- package/src/val/LowerFuncVal.ts +0 -1
- package/src/val/MapVal.ts +110 -8
- package/src/val/MatchFuncVal.ts +176 -0
- package/src/val/MoveFuncVal.ts +0 -2
- package/src/val/NilVal.ts +25 -0
- package/src/val/OpBaseVal.ts +26 -3
- package/src/val/OpenFuncVal.ts +4 -2
- package/src/val/PackFuncVal.ts +175 -0
- package/src/val/PathFuncVal.ts +0 -1
- package/src/val/PlaceVal.ts +193 -0
- package/src/val/PlusOpVal.ts +11 -2
- package/src/val/PrefFuncVal.ts +0 -1
- package/src/val/PrefVal.ts +79 -36
- package/src/val/RefVal.ts +163 -30
- package/src/val/ReferFuncVal.ts +387 -0
- package/src/val/ScalarKindVal.ts +0 -13
- package/src/val/TopVal.ts +0 -1
- package/src/val/TypeFuncVal.ts +0 -2
- package/src/val/UpperFuncVal.ts +0 -1
- package/src/val/Val.ts +213 -3
- package/src/val/VarVal.ts +0 -1
- package/src/val/arith.ts +316 -0
- package/src/vet.ts +992 -0
- package/src/walk.ts +99 -0
package/dist/vet.js
ADDED
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025 Richard Rodger, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.VET_MAX_ERRORS = void 0;
|
|
5
|
+
exports.displayFile = displayFile;
|
|
6
|
+
exports.failureFinding = failureFinding;
|
|
7
|
+
exports.anchorAt = anchorAt;
|
|
8
|
+
exports.vet = vet;
|
|
9
|
+
const aontu_1 = require("./aontu");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const err_1 = require("./err");
|
|
12
|
+
const ConjunctVal_1 = require("./val/ConjunctVal");
|
|
13
|
+
const walk_1 = require("./walk");
|
|
14
|
+
const BagVal_1 = require("./val/BagVal");
|
|
15
|
+
const utility_1 = require("./utility");
|
|
16
|
+
const subsume_1 = require("./subsume");
|
|
17
|
+
// The `--at` refusal is the SAME refusal `get` and `why` give for a
|
|
18
|
+
// path that names nothing, down to the "did you mean" -- so it is that
|
|
19
|
+
// one, not a second spelling of it. A cycle in the module graph
|
|
20
|
+
// (query imports anchorAt from here), and a benign one: both sides
|
|
21
|
+
// use the other only from inside a function body, never at load time.
|
|
22
|
+
const query_1 = require("./query");
|
|
23
|
+
// The default cap, exported because the CLI applies it to the WHOLE
|
|
24
|
+
// report across several data files and must not carry a second copy of
|
|
25
|
+
// the number (ts/src/cli.ts).
|
|
26
|
+
exports.VET_MAX_ERRORS = 20;
|
|
27
|
+
const DEFAULT_SCHEMA_URL = 'schema';
|
|
28
|
+
const DEFAULT_DATA_URL = 'data';
|
|
29
|
+
// Every site in a freshly parsed tree carries the same url, and for a
|
|
30
|
+
// bare parse that url is the empty string: `site.url` is only populated
|
|
31
|
+
// by the multisource loader (ts/src/lang.ts). Vet takes two documents
|
|
32
|
+
// from its CALLER, not from the filesystem, so it stamps provenance
|
|
33
|
+
// itself — which is what lets the report assign site ROLES by
|
|
34
|
+
// provenance rather than by NilVal's source-order heuristic, exactly as
|
|
35
|
+
// the design requires.
|
|
36
|
+
// EVERY SITE NAMES THE FILE WHOSE TEXT IT EXCERPTS (the review's
|
|
37
|
+
// finding F, use-cases/BUGS.md §25). The parser already names the file
|
|
38
|
+
// each value was read from -- a value loaded through `@"lib/types.aon"`
|
|
39
|
+
// carries that path, with that file's row and column -- and this walk
|
|
40
|
+
// used to OVERWRITE every url with the entry document's name. The
|
|
41
|
+
// coordinates stayed the included file's, so a finding cited
|
|
42
|
+
// `entry.aon:3:7` for text that lives three files away, at a line the
|
|
43
|
+
// entry may not even have. A repair agent that follows the site edits
|
|
44
|
+
// the wrong file.
|
|
45
|
+
//
|
|
46
|
+
// Only the values that carry no name of their own are stamped: those
|
|
47
|
+
// are the ones the engine minted rather than read, and the entry is
|
|
48
|
+
// the honest name for them. The urls actually seen are collected, so
|
|
49
|
+
// the report can still tell WHICH DOCUMENT a site belongs to without
|
|
50
|
+
// pretending they all came from one file -- see roleOf.
|
|
51
|
+
function stampUrl(v, url, seen) {
|
|
52
|
+
const urls = seen ?? new Set();
|
|
53
|
+
urls.add(url);
|
|
54
|
+
(0, walk_1.walkVals)(v, (n) => {
|
|
55
|
+
// UNDEFINED counts as unstamped, not just empty: the parser leaves
|
|
56
|
+
// the url undefined on one of its two paths (ts/src/lang.ts), and
|
|
57
|
+
// treating that as a name would put `undefined` in the url set --
|
|
58
|
+
// where the OTHER document's unstamped values would then match it,
|
|
59
|
+
// and every site would read `data`.
|
|
60
|
+
if (null == n.site.url || '' === n.site.url) {
|
|
61
|
+
n.site.url = url;
|
|
62
|
+
}
|
|
63
|
+
urls.add(n.site.url);
|
|
64
|
+
return true;
|
|
65
|
+
}, new Set());
|
|
66
|
+
return urls;
|
|
67
|
+
}
|
|
68
|
+
// A FILE THE READER CAN OPEN. The parser resolves an include to an
|
|
69
|
+
// absolute path, which is the right identity (two files loading the
|
|
70
|
+
// same library by different relative spellings must be one file) and
|
|
71
|
+
// the wrong NAME: a report whose entry reads `contract.aon` and whose
|
|
72
|
+
// included site reads `/home/someone/checkout/types.aon` is a report
|
|
73
|
+
// that cannot be uploaded as SARIF, diffed between machines, or read
|
|
74
|
+
// beside the command that produced it.
|
|
75
|
+
//
|
|
76
|
+
// So an included file is named as the ENTRY'S OWN NAME reaches it:
|
|
77
|
+
// relative to the entry's directory, then re-anchored on however the
|
|
78
|
+
// caller spelled the entry. `vet contract.aon` names `types.aon`;
|
|
79
|
+
// `vet a/b/contract.aon` names `a/b/types.aon`; an absolute entry
|
|
80
|
+
// keeps absolute includes. A caller who passed no path at all has no
|
|
81
|
+
// base to relativise against and gets the url unchanged.
|
|
82
|
+
function displayFile(url, label, path) {
|
|
83
|
+
if (url === label || null == path || '' === url || !(0, node_path_1.isAbsolute)(url)) {
|
|
84
|
+
return url;
|
|
85
|
+
}
|
|
86
|
+
const rel = (0, node_path_1.relative)((0, node_path_1.dirname)((0, node_path_1.resolve)(path)), url);
|
|
87
|
+
const dir = (0, node_path_1.dirname)(label);
|
|
88
|
+
return '.' === dir ? rel : (0, node_path_1.join)(dir, rel);
|
|
89
|
+
}
|
|
90
|
+
// The name for one site, taken from the document the site BELONGS to
|
|
91
|
+
// -- which is the role, already decided by url-set membership. Doing
|
|
92
|
+
// it here rather than from a map built at stamping time is not a
|
|
93
|
+
// shortcut: a nil's operands are off the tree by the time the report
|
|
94
|
+
// is built, so a value first seen during the MEET (the commonest
|
|
95
|
+
// schema site there is) would be missing from any such map.
|
|
96
|
+
function displayOf(file, role, prov) {
|
|
97
|
+
return 'data' === role
|
|
98
|
+
? displayFile(file, prov.dataUrl ?? file, prov.dataPath)
|
|
99
|
+
: displayFile(file, prov.schemaUrl ?? file, prov.schemaPath);
|
|
100
|
+
}
|
|
101
|
+
// The ROLE of a site: which of the two documents it belongs to. Not a
|
|
102
|
+
// name comparison -- a data document may itself include another file,
|
|
103
|
+
// and that file's values are still data. Membership of the url set the
|
|
104
|
+
// stamping walk collected is the question, and the answer is `schema`
|
|
105
|
+
// for anything the data walk never reached (an engine-minted value
|
|
106
|
+
// stamped with the schema entry, say).
|
|
107
|
+
function roleOf(file, prov) {
|
|
108
|
+
return prov.data.has(file) ? 'data' : 'schema';
|
|
109
|
+
}
|
|
110
|
+
// `$.a.b`, and `$` for the root. Deliberately NOT delimiter-escaped: a
|
|
111
|
+
// map key may contain any character, including every separator a
|
|
112
|
+
// compact summary might pick, so the path is carried as a JSON string
|
|
113
|
+
// and never parsed back out of a larger token.
|
|
114
|
+
function pathText(path) {
|
|
115
|
+
return '$' + (null != path && 0 < path.length ? '.' + path.join('.') : '');
|
|
116
|
+
}
|
|
117
|
+
// `secondary` is the only operand that can be absent — a `closed` or an
|
|
118
|
+
// incomplete finding has one side, a two-site conflict has both — so
|
|
119
|
+
// this is the one nullable input, and every Val that does arrive
|
|
120
|
+
// carries a site and a canon.
|
|
121
|
+
function siteOf(v, prov) {
|
|
122
|
+
if (null == v) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
// The report's `file` is whatever the site carries, and by the time a
|
|
126
|
+
// site reaches a report that is always a stamped name: vet walks both
|
|
127
|
+
// documents before they meet, and the walk reaches the off-peg values
|
|
128
|
+
// a finding can name (ts/src/walk.ts). A consumer therefore reads
|
|
129
|
+
// `file` without a presence check, and the Go port -- whose field is
|
|
130
|
+
// a plain string -- writes the same key.
|
|
131
|
+
//
|
|
132
|
+
// NOT coalesced. The parser leaves the url undefined on one of its
|
|
133
|
+
// two paths (ts/src/lang.ts), and a `?? ''` here would be dead code
|
|
134
|
+
// that hides it: if a value ever reaches a report unstamped, the two
|
|
135
|
+
// ports should disagree loudly rather than quietly agree on an empty
|
|
136
|
+
// name that neither of them meant.
|
|
137
|
+
const file = v.site.url;
|
|
138
|
+
// NAMED for the reader, ROLED by the raw url: the two questions are
|
|
139
|
+
// different, and only the first is about how the file is spelled
|
|
140
|
+
// (see displayFile).
|
|
141
|
+
const role = roleOf(file, prov);
|
|
142
|
+
return {
|
|
143
|
+
file: displayOf(file, role, prov),
|
|
144
|
+
row: v.site.row,
|
|
145
|
+
col: v.site.col,
|
|
146
|
+
len: v.site.len,
|
|
147
|
+
role,
|
|
148
|
+
src: v.site.src,
|
|
149
|
+
value: v.canon,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// The data site first — it is the thing to fix — then the schema site.
|
|
153
|
+
// The underlying NilVal fields are untouched: this is a report-layer
|
|
154
|
+
// projection, so the existing error.tsv assertions do not move.
|
|
155
|
+
function sitesOf(nil, prov) {
|
|
156
|
+
// `?? nil`: a failure raised about a CONSTRUCT rather than about a
|
|
157
|
+
// failed meet -- a lossy integer literal, say -- carries no operands
|
|
158
|
+
// at all, and reporting it about ITSELF is what ctx.adderr already
|
|
159
|
+
// does for the same reason. Without the fallback the report built a
|
|
160
|
+
// site out of `undefined` and threw while partitioning it, which is
|
|
161
|
+
// the one thing vet promises not to do: a bad value in the data is
|
|
162
|
+
// DATA, and the caller gets a report.
|
|
163
|
+
const sites = [siteOf(nil.primary ?? nil, prov)];
|
|
164
|
+
const secondary = siteOf(nil.secondary, prov);
|
|
165
|
+
if (null != secondary) {
|
|
166
|
+
sites.push(secondary);
|
|
167
|
+
}
|
|
168
|
+
// Partitioned rather than sorted: which of the two NilVal operands is
|
|
169
|
+
// `primary` follows source order within one document, which says
|
|
170
|
+
// nothing useful when one side is a schema and the other is data.
|
|
171
|
+
return [
|
|
172
|
+
...sites.filter((s) => 'data' === s.role),
|
|
173
|
+
...sites.filter((s) => 'schema' === s.role),
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
// The message text is MATERIALISED on demand, exactly as handleErrors
|
|
177
|
+
// materialises one before a caller sees it: makeNilErr defers it
|
|
178
|
+
// because most NilVals are transient and never rendered, and only the
|
|
179
|
+
// throwing path asks for it. Without this a finding could carry an
|
|
180
|
+
// empty `message` -- which is what the incomplete half of every report
|
|
181
|
+
// did, and what any nil built during the PARSE of a document did.
|
|
182
|
+
function materialise(nil, ctx) {
|
|
183
|
+
if (null == nil.msg || '' === nil.msg) {
|
|
184
|
+
(0, err_1.descErr)(nil, ctx);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// The terminal colour escapes the parser puts in its message text. A
|
|
188
|
+
// RegExp built from a string, not a literal: the escape is a control
|
|
189
|
+
// character, and spelling it `\u001b` keeps the source readable.
|
|
190
|
+
const ANSI_RE = new RegExp('\u001b\\[[0-9;]*m', 'g');
|
|
191
|
+
function stripAnsi(s) {
|
|
192
|
+
return s.replace(ANSI_RE, '');
|
|
193
|
+
}
|
|
194
|
+
function findingOf(nil, prov) {
|
|
195
|
+
const details = nil.details ?? {};
|
|
196
|
+
const finding = {
|
|
197
|
+
code: nil.why,
|
|
198
|
+
class: nil.class,
|
|
199
|
+
severity: 'error',
|
|
200
|
+
path: pathText(nil.path),
|
|
201
|
+
// The HEADLINE only, WITHOUT ANSI: the frames below it are for a
|
|
202
|
+
// human reading a terminal, and the first line is the part the two
|
|
203
|
+
// ports hold to byte parity. Materialised before this runs, so it
|
|
204
|
+
// is always there (see materialise above). The escapes matter for
|
|
205
|
+
// one family only -- a parse failure's text comes from the parser,
|
|
206
|
+
// which colours its marker -- and a machine-readable report is no
|
|
207
|
+
// place for terminal control codes.
|
|
208
|
+
message: stripAnsi(nil.msg.split('\n')[0]),
|
|
209
|
+
sites: sitesOf(nil, prov),
|
|
210
|
+
};
|
|
211
|
+
// The hint, whole, with its detail placeholders filled in exactly as
|
|
212
|
+
// the terminal frame fills them. Trailing whitespace is dropped
|
|
213
|
+
// because it is spacing for the frame that used to follow it, not
|
|
214
|
+
// part of the text; the deliberate blank lines INSIDE a hint are
|
|
215
|
+
// `\n \n` and survive.
|
|
216
|
+
const hint = (0, err_1.getHint)(nil.why, nil.details);
|
|
217
|
+
if (null != hint && '' !== hint) {
|
|
218
|
+
finding.hint = stripAnsi(hint).replace(/\s+$/, '');
|
|
219
|
+
}
|
|
220
|
+
// `expected`/`actual` are the admissible-alternatives contract, and
|
|
221
|
+
// the constraint algebra already produces them: G1's atoms attach the
|
|
222
|
+
// normalised residual and the offending value, and `must` attaches
|
|
223
|
+
// the author's message. Read them where they are rather than
|
|
224
|
+
// re-deriving them here.
|
|
225
|
+
if ('string' === typeof details.expected) {
|
|
226
|
+
finding.expected = details.expected;
|
|
227
|
+
}
|
|
228
|
+
if ('string' === typeof details.actual) {
|
|
229
|
+
finding.actual = details.actual;
|
|
230
|
+
}
|
|
231
|
+
if ('string' === typeof details.message) {
|
|
232
|
+
finding.note = details.message;
|
|
233
|
+
}
|
|
234
|
+
return finding;
|
|
235
|
+
}
|
|
236
|
+
// Findings are sorted BY VET, not by the walk. The underlying walk
|
|
237
|
+
// iterates raw object keys and the two hosts disagree about their order
|
|
238
|
+
// — `10:… 9:…` yields ["9","10"] in JavaScript, which hoists
|
|
239
|
+
// integer-like keys, against Go's insertion order (ts/src/keyorder.ts
|
|
240
|
+
// exists for exactly this) — so an unsorted report could never be in
|
|
241
|
+
// cross-port parity.
|
|
242
|
+
//
|
|
243
|
+
// The order is by data site (file, row, column), then code, then path.
|
|
244
|
+
// It is carried in ONE key string rather than a cascade of comparisons:
|
|
245
|
+
// the row and column are zero-padded so lexicographic order is numeric
|
|
246
|
+
// order, and NUL joins the fields because no field can contain one.
|
|
247
|
+
// A cascade would need a test per tie-breaker to stay honest; a key
|
|
248
|
+
// needs none, and cannot disagree with itself.
|
|
249
|
+
const ORDER_PAD = 9;
|
|
250
|
+
function pad(n) {
|
|
251
|
+
return String(n).padStart(ORDER_PAD, '0');
|
|
252
|
+
}
|
|
253
|
+
// The walk index is the LAST field, which makes every key unique and
|
|
254
|
+
// the sort below total: two findings can otherwise share everything the
|
|
255
|
+
// key carries — same data site, same code, same path — and a comparator
|
|
256
|
+
// that has to answer "equal" is one more thing to get right in two
|
|
257
|
+
// languages. With the index appended, ties simply keep walk order, in
|
|
258
|
+
// both ports, by construction rather than by the sort's promises.
|
|
259
|
+
function orderKey(f, index) {
|
|
260
|
+
const site = f.sites[0];
|
|
261
|
+
return [
|
|
262
|
+
site.file,
|
|
263
|
+
pad(site.row),
|
|
264
|
+
pad(site.col),
|
|
265
|
+
f.code,
|
|
266
|
+
f.path,
|
|
267
|
+
pad(index),
|
|
268
|
+
].join('\u0000');
|
|
269
|
+
}
|
|
270
|
+
// A DOCUMENT THAT DOES NOT STAND UP, in the finding shape (the
|
|
271
|
+
// review's finding F). `trim` and `relations` answered an unusable
|
|
272
|
+
// document with `verdict: error` and an EMPTY list: the caller learned
|
|
273
|
+
// that something was wrong and nothing about what, which is the one
|
|
274
|
+
// thing a repair loop cannot work with. Both verbs take ONE document,
|
|
275
|
+
// so there is no role to decide -- the document is the thing being
|
|
276
|
+
// checked and the thing to edit, which is what `data` means here.
|
|
277
|
+
//
|
|
278
|
+
// The engine's own first error IS the finding: these verbs add nothing
|
|
279
|
+
// to a diagnosis the evaluator already made, and the FIRST is enough
|
|
280
|
+
// because everything after it is a consequence.
|
|
281
|
+
//
|
|
282
|
+
// The Go twin is failureFinding in go/vet.go.
|
|
283
|
+
function failureFinding(ctx, url, failed) {
|
|
284
|
+
// ctx.err IS SOMETIMES EMPTY, and the comment that used to stand here
|
|
285
|
+
// said otherwise (use-cases/BUGS.md §43). `&: id(root)` fails with a
|
|
286
|
+
// NIL ROOT and NO COLLECTED ERROR -- the id-spread refusal is the
|
|
287
|
+
// root itself -- and every verb that reports "this document does not
|
|
288
|
+
// stand up" then read `ctx.err[0]` as undefined and died: a TypeError
|
|
289
|
+
// out of `relations`, `reaches` and `jsonschema` in TypeScript, a
|
|
290
|
+
// panic in Go. The one shape where finding F's own invariant, that a
|
|
291
|
+
// document which does not stand up SAYS SO in the finding shape, was
|
|
292
|
+
// answered with a stack trace.
|
|
293
|
+
//
|
|
294
|
+
// `failed` is the caller's own root -- every caller has it, and its
|
|
295
|
+
// condition is `0 < ctx.err.length || root.isNil`, so when the first
|
|
296
|
+
// half is false the second holds and the root IS the reason.
|
|
297
|
+
const nil = ctx.err[0] ?? failed;
|
|
298
|
+
materialise(nil, ctx);
|
|
299
|
+
// STAMPED, as vet stamps both documents before they meet: siteOf does
|
|
300
|
+
// not coalesce a missing name (deliberately -- see there), so a site
|
|
301
|
+
// that reached the report unstamped would carry `file: undefined`.
|
|
302
|
+
// The three Vals a finding can name are the nil and its two operands,
|
|
303
|
+
// and the url set collects whatever name each already had, so a value
|
|
304
|
+
// read from an included file keeps that file's name and still counts
|
|
305
|
+
// as part of the one document being checked.
|
|
306
|
+
const at = url ?? '';
|
|
307
|
+
const urls = new Set([at]);
|
|
308
|
+
for (const v of [nil, nil.primary, nil.secondary]) {
|
|
309
|
+
if (null == v || null == v.site) {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (null == v.site.url || '' === v.site.url) {
|
|
313
|
+
v.site.url = at;
|
|
314
|
+
}
|
|
315
|
+
urls.add(v.site.url);
|
|
316
|
+
}
|
|
317
|
+
return findingOf(nil, { data: urls });
|
|
318
|
+
}
|
|
319
|
+
// Walk the evaluated schema to the anchor path. `$` and `$.a.b` are
|
|
320
|
+
// both accepted, as is the bare `a.b` a shell is likely to hand over
|
|
321
|
+
// unquoted.
|
|
322
|
+
function anchorAt(root, at) {
|
|
323
|
+
const trimmed = at.startsWith('$') ? at.slice(1) : at;
|
|
324
|
+
const parts = trimmed.split('.').filter((p) => '' !== p);
|
|
325
|
+
let node = root;
|
|
326
|
+
for (const part of parts) {
|
|
327
|
+
// A SIZING RESIDUE IS ITS CONTAINER, plus a note about what the
|
|
328
|
+
// container must still satisfy (use-cases/BUGS.md §16). The path
|
|
329
|
+
// steps through it: `$.a.ports.0.port` names the same node whether
|
|
330
|
+
// or not `ports` still carries a `unique()`, and an anchor that
|
|
331
|
+
// stopped here would report `no_path` for a key the document
|
|
332
|
+
// plainly has.
|
|
333
|
+
node = throughResidue(node);
|
|
334
|
+
// TYPE-DIRECTED, not a property lookup on whatever `peg` happens to
|
|
335
|
+
// be. An anchor is a STRUCTURAL path into the schema — the same
|
|
336
|
+
// thing a reference means by `$.a.b` — so it walks map keys and
|
|
337
|
+
// list indices, and stops at anything else.
|
|
338
|
+
//
|
|
339
|
+
// Indexing the peg generically walked much further than that: into
|
|
340
|
+
// a junction's branches (`a:1|2` with `--at $.a.0` validated
|
|
341
|
+
// against ONE branch), into a constraint's atom arguments (so
|
|
342
|
+
// `min(2)` with `--at $.a.0` reported the bound's own argument as
|
|
343
|
+
// the truth), into a pref's wrapped value through the literal key
|
|
344
|
+
// `peg`, and into an array's `length` — that last one handing back
|
|
345
|
+
// a JavaScript NUMBER as the anchor, after which every document
|
|
346
|
+
// whatsoever came back valid. The Go port has always been
|
|
347
|
+
// type-directed here; this is the canonical side moving to it.
|
|
348
|
+
if (true === node?.isMap) {
|
|
349
|
+
const peg = node.peg;
|
|
350
|
+
if (null == peg || !Object.prototype.hasOwnProperty.call(peg, part)) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
node = peg[part];
|
|
354
|
+
}
|
|
355
|
+
else if (true === node?.isList) {
|
|
356
|
+
// CANONICAL DECIMAL, the spelling a reference uses for a list
|
|
357
|
+
// index (`0`, or a non-zero digit run) -- so `$.a.01` names
|
|
358
|
+
// nothing here exactly as it names nothing there.
|
|
359
|
+
const peg = node.peg;
|
|
360
|
+
const index = Number(part);
|
|
361
|
+
if (!/^(0|[1-9][0-9]*)$/.test(part) ||
|
|
362
|
+
!Array.isArray(peg) || peg.length <= index) {
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
node = peg[index];
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
// THE ANCHOR KEEPS ITS ATOM. Stepping THROUGH a residue is right --
|
|
372
|
+
// `$.x.a` names a key of the container whatever the container still
|
|
373
|
+
// has to satisfy -- but ARRIVING at one and handing back the bare
|
|
374
|
+
// container drops a constraint the author wrote, so `--at $.x` vetted
|
|
375
|
+
// clean against a `length` the evaluator enforces. The residue is the
|
|
376
|
+
// honest schema for the node: the meet drives it, and generation
|
|
377
|
+
// settles it, exactly as it does without an anchor.
|
|
378
|
+
return node;
|
|
379
|
+
}
|
|
380
|
+
// The container inside a settled sizing residue, or the value itself.
|
|
381
|
+
function throughResidue(v) {
|
|
382
|
+
return (0, BagVal_1.sizingResidue)(v)?.bag ?? v;
|
|
383
|
+
}
|
|
384
|
+
// Validate `dataSrc` against `schemaSrc`.
|
|
385
|
+
//
|
|
386
|
+
// Never throws for findings: a contradiction in the data is DATA, and
|
|
387
|
+
// the caller gets a report. It throws only when the caller's own inputs
|
|
388
|
+
// are unusable — which is why an unusable schema is a verdict (`error`)
|
|
389
|
+
// rather than an exception too: "the schema is broken" is a fact the
|
|
390
|
+
// agent loop needs to branch on, not an exceptional condition.
|
|
391
|
+
function vet(schemaSrc, dataSrc, opts) {
|
|
392
|
+
const options = opts ?? {};
|
|
393
|
+
const schemaUrl = options.schemaUrl ?? DEFAULT_SCHEMA_URL;
|
|
394
|
+
const dataUrl = options.dataUrl ?? DEFAULT_DATA_URL;
|
|
395
|
+
const maxErrors = options.maxErrors ?? exports.VET_MAX_ERRORS;
|
|
396
|
+
// ONE instance, two bases: the path rides on each CALL rather than on
|
|
397
|
+
// the constructor, because the schema and the data may live in
|
|
398
|
+
// different directories (Lang.parse takes `opts.path` per parse).
|
|
399
|
+
const aontu = new aontu_1.Aontu(null == options.trust ? undefined : { trust: options.trust });
|
|
400
|
+
const schemaOpts = null == options.schemaPath ?
|
|
401
|
+
undefined : { path: options.schemaPath };
|
|
402
|
+
const dataOpts = null == options.dataPath ?
|
|
403
|
+
undefined : { path: options.dataPath };
|
|
404
|
+
// 1. The schema alone. If it does not stand up on its own, the data
|
|
405
|
+
// is never blamed for it.
|
|
406
|
+
const schemaCtx = aontu.ctx({ collect: true });
|
|
407
|
+
const schemaVal = aontu.unify(schemaSrc, schemaOpts, schemaCtx);
|
|
408
|
+
if (0 < schemaCtx.err.length || true === schemaVal?.isNil) {
|
|
409
|
+
// A broken schema REPORTS, exactly as broken data does. It used to
|
|
410
|
+
// answer `findings: []` with exit 4 and nothing else, in both
|
|
411
|
+
// ports: the engine had collected the fault and vet threw it away,
|
|
412
|
+
// so an agent -- or a person -- was told the schema was broken and
|
|
413
|
+
// not what or where. The verdict stays `error` (the fault is in
|
|
414
|
+
// the truth, not in the data, and that distinction is the whole
|
|
415
|
+
// point of the class), but the finding travels with it.
|
|
416
|
+
//
|
|
417
|
+
// The FIRST error only, and the data path's reasoning applies
|
|
418
|
+
// unchanged: later errors in a document that does not stand up are
|
|
419
|
+
// consequences of the first rather than separate things to fix.
|
|
420
|
+
//
|
|
421
|
+
// ONE OF THE TWO IS ALWAYS THERE, and both are nils: the branch
|
|
422
|
+
// condition admits a collected error or a nil root, and every
|
|
423
|
+
// value on `schemaCtx.err` is a NilVal. There is no third case, so
|
|
424
|
+
// there is no guard here -- a guard that cannot fire is dead code,
|
|
425
|
+
// and dead code is what ADR-002 exists to keep out. (One stood
|
|
426
|
+
// here and the TypeScript line report called it covered; the Go
|
|
427
|
+
// gate, which measures blocks, refused the twin.)
|
|
428
|
+
const failure = 0 < schemaCtx.err.length ? schemaCtx.err[0] : schemaVal;
|
|
429
|
+
// The normal path stamps both documents before they meet
|
|
430
|
+
// (stampUrl(anchor...) below), and this early return never reaches
|
|
431
|
+
// it, so it stamps what it is about to report: the unified root,
|
|
432
|
+
// and the failure itself -- a COLLECTED error is minted during
|
|
433
|
+
// unification and hangs off no tree, so nothing else would name
|
|
434
|
+
// it. The walk reaches a failure's operands (ts/src/walk.ts),
|
|
435
|
+
// which is what makes the sites say which file.
|
|
436
|
+
stampUrl(schemaVal, schemaUrl);
|
|
437
|
+
stampUrl(failure, schemaUrl);
|
|
438
|
+
materialise(failure, schemaCtx);
|
|
439
|
+
return {
|
|
440
|
+
verdict: 'error',
|
|
441
|
+
truncated: false,
|
|
442
|
+
// A schema that does not stand up: nothing here is data, so the
|
|
443
|
+
// data-url set is empty and every site reads `schema`.
|
|
444
|
+
findings: [findingOf(failure, { data: new Set() })],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
// 2. The anchor: the whole schema, or the value at `--at`.
|
|
448
|
+
let anchor = schemaVal;
|
|
449
|
+
if (null != options.at) {
|
|
450
|
+
anchor = anchorAt(schemaVal, options.at);
|
|
451
|
+
if (null == anchor) {
|
|
452
|
+
// AND IT SAYS WHICH SEGMENT. `--at` naming nothing is an error
|
|
453
|
+
// verdict for the same reason a broken schema is -- the run
|
|
454
|
+
// could not be set up from the truth's side -- and it reports
|
|
455
|
+
// for the same reason too: a caller handed exit 4 and an empty
|
|
456
|
+
// list has nothing to act on.
|
|
457
|
+
return {
|
|
458
|
+
verdict: 'error',
|
|
459
|
+
truncated: false,
|
|
460
|
+
findings: [(0, query_1.noPathFinding)(schemaVal, options.at)],
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
// 3. Both documents get their provenance stamped BEFORE they meet, so
|
|
465
|
+
// every site in the result knows which document it came from.
|
|
466
|
+
const dataCtx = aontu.ctx({ collect: true });
|
|
467
|
+
const dataVal = aontu.parse(dataSrc, dataOpts, dataCtx);
|
|
468
|
+
if (0 < dataCtx.err.length || null == dataVal) {
|
|
469
|
+
// A DATA DOCUMENT THAT WILL NOT PARSE IS THE DATA'S FAULT, and the
|
|
470
|
+
// report says so: verdict `invalid`, with a finding carrying the
|
|
471
|
+
// parser's own code and a site in the data. `error` is left to mean
|
|
472
|
+
// what the exit table says it means -- the run could not be set up
|
|
473
|
+
// from the SCHEMA side.
|
|
474
|
+
//
|
|
475
|
+
// The engine already answered it this way one character earlier: a
|
|
476
|
+
// refused CONSTRUCT (`a: 9007199254740993`) reaches the tree as an
|
|
477
|
+
// ordinary nil and is reported as an invalid data finding. A stray
|
|
478
|
+
// `]` took the throwing path instead and came back as a broken
|
|
479
|
+
// SCHEMA -- the same fault, classified two opposite ways by which
|
|
480
|
+
// branch the parser happened to take.
|
|
481
|
+
//
|
|
482
|
+
// The FIRST error only: the parser stops at the first syntax error,
|
|
483
|
+
// so a second entry would be a consequence of the first rather than
|
|
484
|
+
// a separate thing to fix.
|
|
485
|
+
const failure = dataCtx.err[0];
|
|
486
|
+
if (null == failure) {
|
|
487
|
+
return { verdict: 'error', truncated: false, findings: [] };
|
|
488
|
+
}
|
|
489
|
+
failure.site.url = dataUrl;
|
|
490
|
+
materialise(failure, dataCtx);
|
|
491
|
+
return {
|
|
492
|
+
verdict: 'invalid',
|
|
493
|
+
truncated: false,
|
|
494
|
+
findings: [findingOf(failure, { data: new Set([dataUrl]) })],
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
stampUrl(anchor, schemaUrl);
|
|
498
|
+
const dataUrls = stampUrl(dataVal, dataUrl);
|
|
499
|
+
// The projection every site in this report goes through: roles by
|
|
500
|
+
// url-set membership, names by how the caller reached each document.
|
|
501
|
+
const prov = {
|
|
502
|
+
data: dataUrls,
|
|
503
|
+
schemaUrl, schemaPath: options.schemaPath,
|
|
504
|
+
dataUrl, dataPath: options.dataPath,
|
|
505
|
+
};
|
|
506
|
+
// Default-validity lint (G3 phase 5, re-examined under ADR-004): for
|
|
507
|
+
// every disjunction in the SCHEMA carrying a preference, warn when
|
|
508
|
+
// the effective default is not an instance of any REMAINING
|
|
509
|
+
// alternative (code `pref_not_instance`, class compat, severity
|
|
510
|
+
// warning).
|
|
511
|
+
//
|
|
512
|
+
// What the finding MEANS changed with the admission gate (ADR-004).
|
|
513
|
+
// Before the gate it flagged a soundness hole: the preference held
|
|
514
|
+
// the disjunction open, so `a:*5|string` both generated a value the
|
|
515
|
+
// alternatives refuse AND admitted any same-kind override. The gate
|
|
516
|
+
// closed that hole — a preferred branch now contributes exactly its
|
|
517
|
+
// own value to the admitted set, so a default can no longer be
|
|
518
|
+
// "invalid against its own disjunct" and the enum-with-default idiom
|
|
519
|
+
// (`*'auto'|'literal'|'data'`) is sound as written. The lint is KEPT,
|
|
520
|
+
// as an advisory: a default admitted only because it is the default
|
|
521
|
+
// is also the exact shape of a typo'd default
|
|
522
|
+
// (`level:*wran|info|warn|debug` — the intended `*warn` would be
|
|
523
|
+
// silent), and nothing at meet time can catch that. The
|
|
524
|
+
// repeated-branch spelling (`*warn|warn|...`) states "the default is
|
|
525
|
+
// a first-class member", silences the lint, and — unlike before the
|
|
526
|
+
// gate — enforces exactly the same admitted set. The message names
|
|
527
|
+
// the REMAINING alternatives because that is what was scanned: the
|
|
528
|
+
// preferred branch itself always admits its own default, so the old
|
|
529
|
+
// wording ("any alternative of *5|string") read as false on its face
|
|
530
|
+
// (use-cases/BUGS.md §4).
|
|
531
|
+
const lintFindings = [];
|
|
532
|
+
(0, utility_1.walkBagVals)(anchor, (v, path) => {
|
|
533
|
+
if (true === v.isDisjunct && Array.isArray(v.peg)) {
|
|
534
|
+
const d = (0, subsume_1.effectiveDefault)(v);
|
|
535
|
+
if (null != d && 'indeterminate' !== d) {
|
|
536
|
+
const rest = v.peg.filter((m) => true !== m?.isPref);
|
|
537
|
+
const state = {
|
|
538
|
+
profile: 'values', findings: [],
|
|
539
|
+
generalUrl: schemaUrl, specificUrl: schemaUrl,
|
|
540
|
+
};
|
|
541
|
+
const admitted = rest.some((m) => 'yes' === (0, subsume_1.subsumeNode)(state, path, m, d));
|
|
542
|
+
if (!admitted && 0 < rest.length) {
|
|
543
|
+
lintFindings.push({
|
|
544
|
+
code: 'pref_not_instance',
|
|
545
|
+
class: 'compat',
|
|
546
|
+
severity: 'warning',
|
|
547
|
+
path: pathText(path),
|
|
548
|
+
message: 'the default ' + d.canon +
|
|
549
|
+
' is not an instance of any remaining alternative of ' +
|
|
550
|
+
v.canon,
|
|
551
|
+
sites: [{
|
|
552
|
+
file: schemaUrl,
|
|
553
|
+
row: d.site?.row ?? -1,
|
|
554
|
+
col: d.site?.col ?? -1,
|
|
555
|
+
len: d.site?.len ?? -1,
|
|
556
|
+
role: 'schema',
|
|
557
|
+
src: d.site?.src ?? '',
|
|
558
|
+
value: d.canon,
|
|
559
|
+
}],
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
// `--closed` sets the flag `close()` itself sets, rather than wrapping
|
|
566
|
+
// the anchor in a CloseFuncVal: the anchor is an already-evaluated
|
|
567
|
+
// tree, and a func value would have to resolve again to have any
|
|
568
|
+
// effect. A scalar anchor has no keys to close, so the flag is only
|
|
569
|
+
// meaningful on a bag.
|
|
570
|
+
if (true === options.closed && (true === anchor.isMap || true === anchor.isList)) {
|
|
571
|
+
anchor.closed = true;
|
|
572
|
+
}
|
|
573
|
+
// THE MEET IS FROM A FRESH PARSE, NOT THE SETTLED SCHEMA (the
|
|
574
|
+
// review's finding C, use-cases/BUGS.md §15).
|
|
575
|
+
//
|
|
576
|
+
// Step 1 evaluated the schema ALONE, to decide whether it stands up
|
|
577
|
+
// before any data is blamed for it. That answer is a diagnosis, and
|
|
578
|
+
// it was also being used as the left side of the meet -- so every
|
|
579
|
+
// reference in the schema had already RESOLVED against the schema's
|
|
580
|
+
// own values and been replaced by them. `a:integer b:$.a` settled to
|
|
581
|
+
// `a:integer b:integer`, and data `{a:3,b:4}` then vetted VALID,
|
|
582
|
+
// while the same four lines as one document refuse with
|
|
583
|
+
// scalar_value. A reference is a statement about the FINAL model, and
|
|
584
|
+
// vet is asking about a model the data is part of.
|
|
585
|
+
//
|
|
586
|
+
// Parsing again is what makes `vet(S,D)` and `eval(S ∪ D)` the same
|
|
587
|
+
// question: the meet runs the fixpoint once, over both documents, so
|
|
588
|
+
// references, spreads and generators all see the data. Parsed trees
|
|
589
|
+
// are single-use, hence a second parse rather than a reuse of step
|
|
590
|
+
// 1's. The lint above still reads the SETTLED tree, where
|
|
591
|
+
// disjunctions are ranked and normalised.
|
|
592
|
+
//
|
|
593
|
+
// ONLY WHEN THERE IS NO `--at`. An anchor is a SUBTREE lifted out of
|
|
594
|
+
// the schema, and an absolute reference inside it (`$.OrderPlaced`,
|
|
595
|
+
// the discriminated-union idiom) names a sibling of the document
|
|
596
|
+
// root -- which the lifted subtree no longer has. The settled tree is
|
|
597
|
+
// where those references have already been resolved and substituted,
|
|
598
|
+
// so an anchored run keeps meeting that, exactly as it always has.
|
|
599
|
+
// Making the rule explicit rather than leaving it to whether
|
|
600
|
+
// anchorAt happens to find the path in an unresolved tree: the two
|
|
601
|
+
// ports answered that differently, which is an ADR-001 divergence
|
|
602
|
+
// waiting to happen.
|
|
603
|
+
const ctx = aontu.ctx({ collect: true });
|
|
604
|
+
let meetAnchor = anchor;
|
|
605
|
+
if (null == options.at) {
|
|
606
|
+
const meetCtx = aontu.ctx({ collect: true });
|
|
607
|
+
const freshSchema = aontu.parse(schemaSrc, schemaOpts, meetCtx);
|
|
608
|
+
if (0 === meetCtx.err.length && null != freshSchema) {
|
|
609
|
+
meetAnchor = freshSchema;
|
|
610
|
+
if (true === options.closed &&
|
|
611
|
+
(true === meetAnchor.isMap || true === meetAnchor.isList)) {
|
|
612
|
+
meetAnchor.closed = true;
|
|
613
|
+
}
|
|
614
|
+
stampUrl(meetAnchor, schemaUrl);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const pair = new ConjunctVal_1.ConjunctVal({ peg: [meetAnchor, dataVal] }, ctx);
|
|
618
|
+
const unified = aontu.unify(pair, undefined, ctx);
|
|
619
|
+
// 4. Contradictions: every NilVal standing in the result, PLUS the
|
|
620
|
+
// ones that never made it into the tree.
|
|
621
|
+
//
|
|
622
|
+
// The second half is not belt-and-braces. When a parent collapses to
|
|
623
|
+
// a nil the whole subtree goes with it, so `service: close({...})`
|
|
624
|
+
// meeting a typo AND a kind conflict leaves ONE nil in the tree and
|
|
625
|
+
// reports the other only on the context — the vet verb's own
|
|
626
|
+
// motivating example, reporting half of what it found. The language
|
|
627
|
+
// server already walks both for this reason; vet dedups by identity
|
|
628
|
+
// the same way, and skips the transient disjunct-trial sentinel,
|
|
629
|
+
// which is bookkeeping rather than a finding.
|
|
630
|
+
const seen = new Set();
|
|
631
|
+
const nils = (0, walk_1.collectNils)(unified, seen);
|
|
632
|
+
for (const err of ctx.err) {
|
|
633
|
+
if (true === err?.isNil && '|:trial-nil' !== err.why && !seen.has(err)) {
|
|
634
|
+
seen.add(err);
|
|
635
|
+
nils.push(err);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
const findings = nils.map((n) => {
|
|
639
|
+
materialise(n, ctx);
|
|
640
|
+
return findingOf(n, prov);
|
|
641
|
+
});
|
|
642
|
+
// 5. Incompleteness: what is left standing that cannot generate. The
|
|
643
|
+
// generate check runs in its own collect context so nothing it
|
|
644
|
+
// raises reaches the caller's error list, and so a schema that is
|
|
645
|
+
// merely unsatisfied does not look like one that is contradicted.
|
|
646
|
+
// No try/catch: in collect mode `gen` records its reasons on the
|
|
647
|
+
// context instead of throwing, which is the whole point of the mode.
|
|
648
|
+
const genCtx = aontu.ctx({ collect: true });
|
|
649
|
+
genCtx.root = unified;
|
|
650
|
+
// Under `--at` the probe descends through the OUTPUT marks: the
|
|
651
|
+
// caller named this node as the truth to validate against, so a
|
|
652
|
+
// `type()` or `hide()` on it (or propagated into it) is not a reason
|
|
653
|
+
// to check nothing. See AontuContext.probe.
|
|
654
|
+
genCtx.probe = null != options.at;
|
|
655
|
+
unified.gen(genCtx);
|
|
656
|
+
for (const err of genCtx.err) {
|
|
657
|
+
// A CONFLICT RAISED AT GENERATION COUNTS TOO (the review's finding
|
|
658
|
+
// C, use-cases/BUGS.md §16). The filter used to keep the
|
|
659
|
+
// `incomplete` class alone, on the reading that step 4 had already
|
|
660
|
+
// found every contradiction -- true while every conflict was
|
|
661
|
+
// decided during the meet, and untrue since a sizing atom or a
|
|
662
|
+
// container `must` may hold a PROVISIONAL reading until generation,
|
|
663
|
+
// which is where no more members can arrive. Dropping those left
|
|
664
|
+
// `vet` answering `valid` for data the evaluator refuses, which is
|
|
665
|
+
// the one disagreement the vet-equals-eval harness exists to catch
|
|
666
|
+
// -- and did.
|
|
667
|
+
//
|
|
668
|
+
// Deduped against step 4 by the same cause key the loop below uses,
|
|
669
|
+
// so a contradiction seen twice is still reported once.
|
|
670
|
+
if ('incomplete' === err.class || 'conflict' === err.class) {
|
|
671
|
+
materialise(err, genCtx);
|
|
672
|
+
findings.push(findingOf(err, prov));
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// 5b. Deprecation warnings (G3 phase 4): a value that carries the
|
|
676
|
+
// deprecate() record after the meet was USED — the data met a
|
|
677
|
+
// deprecated schema value, or the schema's own default will
|
|
678
|
+
// generate one. Severity `warning` (the slot G2 reserved for
|
|
679
|
+
// exactly this mark), and warnings never touch the verdict below.
|
|
680
|
+
findings.push(...lintFindings);
|
|
681
|
+
for (const { val, path } of (0, utility_1.collectDeprecations)(unified)) {
|
|
682
|
+
const v = val;
|
|
683
|
+
// The same file/role projection sitesOf makes: the url as stamped
|
|
684
|
+
// (empty when the value belongs to neither document), the role by
|
|
685
|
+
// comparing it to the data document's.
|
|
686
|
+
const file = v.site.url;
|
|
687
|
+
findings.push({
|
|
688
|
+
code: 'deprecated',
|
|
689
|
+
class: 'compat',
|
|
690
|
+
severity: 'warning',
|
|
691
|
+
path: pathText(path),
|
|
692
|
+
message: (0, utility_1.deprecationMessage)(v.deprecation),
|
|
693
|
+
sites: [{
|
|
694
|
+
file: displayOf(file, roleOf(file, prov), prov),
|
|
695
|
+
row: v.site.row ?? -1,
|
|
696
|
+
col: v.site.col ?? -1,
|
|
697
|
+
len: v.site.len ?? -1,
|
|
698
|
+
role: roleOf(file, prov),
|
|
699
|
+
src: v.site.src ?? '',
|
|
700
|
+
value: v.canon,
|
|
701
|
+
}],
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
const keyed = findings.map((f, i) => ({ key: orderKey(f, i), finding: f }));
|
|
705
|
+
keyed.sort((a, b) => a.key < b.key ? -1 : 1);
|
|
706
|
+
let ordered = keyed.map((k) => k.finding);
|
|
707
|
+
// ONE CAUSE, ONE FINDING. A reference resolves by CLONING its target,
|
|
708
|
+
// so a target that later fails can fail once per referrer — same
|
|
709
|
+
// code, same two source sites, a different path each time. Multi-pass
|
|
710
|
+
// collection (G2 phase 6) made this reachable: the pass loop now
|
|
711
|
+
// continues past the erroring pass, so the clones' own folds run too.
|
|
712
|
+
// The dedup key is the CODE plus the SITES (file, row, col, value,
|
|
713
|
+
// role): two findings that name the same meet of the same two source
|
|
714
|
+
// positions are one contradiction observed from two paths. The key is
|
|
715
|
+
// NOT (code, path) — the design's sketch — because the paths are
|
|
716
|
+
// exactly what differ. Sorted order makes the kept finding the first
|
|
717
|
+
// by data site then path, deterministically in both ports.
|
|
718
|
+
//
|
|
719
|
+
// THE KEPT PATH IS THE DEEPEST one (use-cases/BUGS.md §41). A meet
|
|
720
|
+
// that fails inside a REFERENCED map is recorded twice: once at the
|
|
721
|
+
// key that actually conflicts, and once at the enclosing map, which
|
|
722
|
+
// collapsed as a consequence and carries the child's two sites. Both
|
|
723
|
+
// are the same cause; only the deeper one names the field an author
|
|
724
|
+
// or an agent has to edit, and `$.q` for a conflict in `$.q.a` sent a
|
|
725
|
+
// repair loop to rewrite the whole record -- twice over, identically,
|
|
726
|
+
// when two of its fields conflicted. Depth first, then the sort order
|
|
727
|
+
// above, so the choice stays deterministic in both ports.
|
|
728
|
+
const causeKey = (f) => f.code + '\u0000' + f.sites.map((s) => [s.file, s.row, s.col, s.role, s.value].join('\u0000')).join('\u0000');
|
|
729
|
+
const depth = (f) => f.path.split('.').length;
|
|
730
|
+
const deepest = new Map();
|
|
731
|
+
for (const f of ordered) {
|
|
732
|
+
const cause = causeKey(f);
|
|
733
|
+
const held = deepest.get(cause);
|
|
734
|
+
if (null == held || depth(held) < depth(f)) {
|
|
735
|
+
deepest.set(cause, f);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
const causes = new Set();
|
|
739
|
+
ordered = ordered.filter((f) => {
|
|
740
|
+
const cause = causeKey(f);
|
|
741
|
+
if (causes.has(cause) || deepest.get(cause) !== f) {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
causes.add(cause);
|
|
745
|
+
return true;
|
|
746
|
+
});
|
|
747
|
+
const truncated = maxErrors < ordered.length;
|
|
748
|
+
const kept = truncated ? ordered.slice(0, maxErrors) : ordered;
|
|
749
|
+
// 6. The verdict derives from finding CLASSES, never from codes, so a
|
|
750
|
+
// new code can never change exit behaviour.
|
|
751
|
+
//
|
|
752
|
+
// BY CLASS, NOT BY STAGE. The split used to be positional -- whatever
|
|
753
|
+
// step 4 found counted as contradiction and whatever step 5 added
|
|
754
|
+
// counted as incompleteness -- which stopped being true when a sizing
|
|
755
|
+
// atom or a container `must` began holding a provisional reading
|
|
756
|
+
// until generation (the review's finding C, use-cases/BUGS.md §16). A
|
|
757
|
+
// CONTRADICTION found at generation is still a contradiction: reading
|
|
758
|
+
// it as mere incompleteness answered `incomplete` where the evaluator
|
|
759
|
+
// refuses, and `vet` and `eval` have to agree.
|
|
760
|
+
//
|
|
761
|
+
// So: an error-severity finding that is not INCOMPLETENESS makes the
|
|
762
|
+
// document invalid, wherever it was found -- a contradiction, a parse
|
|
763
|
+
// refusal, an unresolvable reference alike. Warnings (the `compat`
|
|
764
|
+
// class: lint and deprecation) never touch the verdict.
|
|
765
|
+
let verdict = 'valid';
|
|
766
|
+
const errors = ordered.filter((f) => 'error' === f.severity);
|
|
767
|
+
const unmet = errors.filter((f) => 'incomplete' === f.class).length;
|
|
768
|
+
if (unmet < errors.length) {
|
|
769
|
+
verdict = 'invalid';
|
|
770
|
+
}
|
|
771
|
+
else if (0 < unmet && true !== options.partial) {
|
|
772
|
+
verdict = 'incomplete';
|
|
773
|
+
}
|
|
774
|
+
return { verdict, truncated, findings: kept };
|
|
775
|
+
}
|
|
776
|
+
//# sourceMappingURL=vet.js.map
|