aontu 0.62.0 → 0.63.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 +1 -1
- package/dist/agentsmd.js +0 -27
- package/dist/agentsmd.js.map +1 -1
- package/dist/alias.js.map +1 -1
- package/dist/allow.js +0 -92
- package/dist/allow.js.map +1 -1
- package/dist/aontu.d.ts +1 -1
- package/dist/aontu.js +1 -79
- package/dist/aontu.js.map +1 -1
- package/dist/aontumodel.d.ts +4 -0
- package/dist/aontumodel.js +33 -0
- package/dist/aontumodel.js.map +1 -0
- package/dist/cli.js +101 -620
- package/dist/cli.js.map +1 -1
- package/dist/ctx.js +0 -48
- package/dist/ctx.js.map +1 -1
- package/dist/diff.js +0 -32
- package/dist/diff.js.map +1 -1
- package/dist/err.js +0 -40
- package/dist/err.js.map +1 -1
- package/dist/escape.js +0 -45
- package/dist/escape.js.map +1 -1
- package/dist/exactjson.d.ts +0 -35
- package/dist/exactjson.js +0 -131
- package/dist/exactjson.js.map +1 -1
- package/dist/format.js +13 -203
- package/dist/format.js.map +1 -1
- package/dist/grammar.d.ts +9 -0
- package/dist/grammar.js +54 -0
- package/dist/grammar.js.map +1 -0
- package/dist/graph.js +0 -26
- package/dist/graph.js.map +1 -1
- package/dist/hcanon.js +0 -82
- package/dist/hcanon.js.map +1 -1
- package/dist/helpdoc.js +1 -1
- package/dist/helpdoc.js.map +1 -1
- package/dist/hints.d.ts +0 -6
- package/dist/hints.js +54 -55
- package/dist/hints.js.map +1 -1
- package/dist/jsonschema.js +0 -114
- package/dist/jsonschema.js.map +1 -1
- package/dist/keyorder.d.ts +0 -7
- package/dist/keyorder.js +0 -41
- package/dist/keyorder.js.map +1 -1
- package/dist/lang.js +17 -915
- package/dist/lang.js.map +1 -1
- package/dist/lower.js +11 -61
- package/dist/lower.js.map +1 -1
- package/dist/lsp-server.js +0 -16
- package/dist/lsp-server.js.map +1 -1
- package/dist/lsp.d.ts +1 -1
- package/dist/lsp.js +12 -159
- package/dist/lsp.js.map +1 -1
- package/dist/mcp-server.js +0 -26
- package/dist/mcp-server.js.map +1 -1
- package/dist/mcp.js +0 -113
- package/dist/mcp.js.map +1 -1
- package/dist/mod-tool.js +0 -130
- package/dist/mod-tool.js.map +1 -1
- package/dist/mod.js +0 -162
- package/dist/mod.js.map +1 -1
- package/dist/patch.js +0 -217
- package/dist/patch.js.map +1 -1
- package/dist/provenance.js +0 -140
- package/dist/provenance.js.map +1 -1
- package/dist/query.js +0 -75
- package/dist/query.js.map +1 -1
- package/dist/reach.js +0 -43
- package/dist/reach.js.map +1 -1
- package/dist/relation.js +0 -61
- package/dist/relation.js.map +1 -1
- package/dist/render.js +20 -135
- package/dist/render.js.map +1 -1
- package/dist/report-sarif.d.ts +0 -11
- package/dist/report-sarif.js +0 -28
- package/dist/report-sarif.js.map +1 -1
- package/dist/sig.js +0 -35
- package/dist/sig.js.map +1 -1
- package/dist/sigdecl.js +1 -1
- package/dist/sigdecl.js.map +1 -1
- package/dist/siggate.js +0 -4
- package/dist/siggate.js.map +1 -1
- package/dist/site.js +3 -29
- package/dist/site.js.map +1 -1
- package/dist/subsume.d.ts +0 -10
- package/dist/subsume.js +0 -137
- package/dist/subsume.js.map +1 -1
- package/dist/template.d.ts +2 -1
- package/dist/template.js +58 -138
- package/dist/template.js.map +1 -1
- package/dist/trim.js +0 -41
- package/dist/trim.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.js.map +1 -1
- package/dist/unify.js +12 -242
- package/dist/unify.js.map +1 -1
- package/dist/utility.js +0 -22
- package/dist/utility.js.map +1 -1
- package/dist/val/AbnfFuncVal.d.ts +18 -0
- package/dist/val/AbnfFuncVal.js +132 -0
- package/dist/val/AbnfFuncVal.js.map +1 -0
- package/dist/val/AbsentVal.d.ts +11 -0
- package/dist/val/AbsentVal.js +30 -0
- package/dist/val/AbsentVal.js.map +1 -0
- package/dist/val/AggFuncVal.d.ts +10 -1
- package/dist/val/AggFuncVal.js +104 -116
- package/dist/val/AggFuncVal.js.map +1 -1
- package/dist/val/ArithFuncVal.js +0 -12
- package/dist/val/ArithFuncVal.js.map +1 -1
- package/dist/val/BagVal.js +1 -78
- package/dist/val/BagVal.js.map +1 -1
- package/dist/val/BigDecimalVal.js +0 -16
- package/dist/val/BigDecimalVal.js.map +1 -1
- package/dist/val/BigIntegerVal.js +0 -16
- package/dist/val/BigIntegerVal.js.map +1 -1
- package/dist/val/CloseFuncVal.js +0 -9
- package/dist/val/CloseFuncVal.js.map +1 -1
- package/dist/val/CmpFuncVal.js +2 -59
- package/dist/val/CmpFuncVal.js.map +1 -1
- package/dist/val/ConjunctVal.js +0 -29
- package/dist/val/ConjunctVal.js.map +1 -1
- package/dist/val/ConstraintVal.js +0 -500
- package/dist/val/ConstraintVal.js.map +1 -1
- package/dist/val/ContainerKindVal.js +0 -2
- package/dist/val/ContainerKindVal.js.map +1 -1
- package/dist/val/CopyFuncVal.js +0 -3
- package/dist/val/CopyFuncVal.js.map +1 -1
- package/dist/val/Decimal.js +0 -179
- package/dist/val/Decimal.js.map +1 -1
- package/dist/val/DeprecateFuncVal.js.map +1 -1
- package/dist/val/DisjunctVal.js +0 -152
- package/dist/val/DisjunctVal.js.map +1 -1
- package/dist/val/EachFuncVal.js +0 -3
- package/dist/val/EachFuncVal.js.map +1 -1
- package/dist/val/EmitFuncVal.d.ts +1 -1
- package/dist/val/EmitFuncVal.js +6 -119
- package/dist/val/EmitFuncVal.js.map +1 -1
- package/dist/val/ExpectVal.js +0 -62
- package/dist/val/ExpectVal.js.map +1 -1
- package/dist/val/FilterFuncVal.js +0 -25
- package/dist/val/FilterFuncVal.js.map +1 -1
- package/dist/val/FuncBaseVal.d.ts +1 -0
- package/dist/val/FuncBaseVal.js +7 -127
- package/dist/val/FuncBaseVal.js.map +1 -1
- package/dist/val/GraphAtomVal.js +0 -15
- package/dist/val/GraphAtomVal.js.map +1 -1
- package/dist/val/HideFuncVal.js +0 -13
- package/dist/val/HideFuncVal.js.map +1 -1
- package/dist/val/IntegerVal.js +0 -61
- package/dist/val/IntegerVal.js.map +1 -1
- package/dist/val/JunctionVal.js +0 -20
- package/dist/val/JunctionVal.js.map +1 -1
- package/dist/val/KeyFuncVal.js +0 -46
- package/dist/val/KeyFuncVal.js.map +1 -1
- package/dist/val/ListVal.js +0 -57
- package/dist/val/ListVal.js.map +1 -1
- package/dist/val/LowerFuncVal.js +0 -11
- package/dist/val/LowerFuncVal.js.map +1 -1
- package/dist/val/MapVal.js +0 -151
- package/dist/val/MapVal.js.map +1 -1
- package/dist/val/MatchFuncVal.js +0 -27
- package/dist/val/MatchFuncVal.js.map +1 -1
- package/dist/val/{FormFuncVal.d.ts → MaybeFuncVal.d.ts} +5 -5
- package/dist/val/MaybeFuncVal.js +50 -0
- package/dist/val/MaybeFuncVal.js.map +1 -0
- package/dist/val/MoveFuncVal.js +0 -18
- package/dist/val/MoveFuncVal.js.map +1 -1
- package/dist/val/NilVal.js +0 -60
- package/dist/val/NilVal.js.map +1 -1
- package/dist/val/NomFuncVal.js +8 -42
- package/dist/val/NomFuncVal.js.map +1 -1
- package/dist/val/NumberVal.js +0 -15
- package/dist/val/NumberVal.js.map +1 -1
- package/dist/val/OpBaseVal.d.ts +1 -0
- package/dist/val/OpBaseVal.js +3 -15
- package/dist/val/OpBaseVal.js.map +1 -1
- package/dist/val/PackFuncVal.js +0 -34
- package/dist/val/PackFuncVal.js.map +1 -1
- package/dist/val/PathFuncVal.js +0 -6
- package/dist/val/PathFuncVal.js.map +1 -1
- package/dist/val/PathVal.js +0 -41
- package/dist/val/PathVal.js.map +1 -1
- package/dist/val/PlaceVal.js +0 -25
- package/dist/val/PlaceVal.js.map +1 -1
- package/dist/val/PlusOpVal.d.ts +1 -7
- package/dist/val/PlusOpVal.js +13 -74
- package/dist/val/PlusOpVal.js.map +1 -1
- package/dist/val/PrefFuncVal.js +0 -1
- package/dist/val/PrefFuncVal.js.map +1 -1
- package/dist/val/PrefVal.js +0 -167
- package/dist/val/PrefVal.js.map +1 -1
- package/dist/val/RecurseVal.js +0 -55
- package/dist/val/RecurseVal.js.map +1 -1
- package/dist/val/RefVal.js +0 -282
- package/dist/val/RefVal.js.map +1 -1
- package/dist/val/ReferFuncVal.js +0 -232
- package/dist/val/ReferFuncVal.js.map +1 -1
- package/dist/val/ScalarKindVal.js +0 -49
- package/dist/val/ScalarKindVal.js.map +1 -1
- package/dist/val/ScalarVal.js +0 -11
- package/dist/val/ScalarVal.js.map +1 -1
- package/dist/val/StrFuncVal.js +0 -18
- package/dist/val/StrFuncVal.js.map +1 -1
- package/dist/val/SuperFuncVal.js +0 -32
- package/dist/val/SuperFuncVal.js.map +1 -1
- package/dist/val/TopVal.js +0 -1
- package/dist/val/TopVal.js.map +1 -1
- package/dist/val/TranslateFuncVal.js +1 -3
- package/dist/val/TranslateFuncVal.js.map +1 -1
- package/dist/val/UpperFuncVal.js +0 -11
- package/dist/val/UpperFuncVal.js.map +1 -1
- package/dist/val/Val.d.ts +1 -0
- package/dist/val/Val.js +2 -133
- package/dist/val/Val.js.map +1 -1
- package/dist/val/VarVal.js +0 -12
- package/dist/val/VarVal.js.map +1 -1
- package/dist/val/arith.js +0 -37
- package/dist/val/arith.js.map +1 -1
- package/dist/val/caserange.js +0 -61
- package/dist/val/caserange.js.map +1 -1
- package/dist/val/members.js +0 -6
- package/dist/val/members.js.map +1 -1
- package/dist/val/numcmp.js +0 -11
- package/dist/val/numcmp.js.map +1 -1
- package/dist/val/numkind.js +0 -145
- package/dist/val/numkind.js.map +1 -1
- package/dist/val/valutil.js +0 -16
- package/dist/val/valutil.js.map +1 -1
- package/dist/vet.js +0 -461
- package/dist/vet.js.map +1 -1
- package/dist/view.js +0 -414
- package/dist/view.js.map +1 -1
- package/dist/walk.js +0 -41
- package/dist/walk.js.map +1 -1
- package/grammar/aontu.abnf +8 -6
- package/grammar/aontu.gbnf +4 -4
- package/grammar/aontu.lark +4 -4
- package/grammar/aontu.tmLanguage.json +1 -1
- package/package.json +4 -2
- package/src/agentsmd.ts +0 -35
- package/src/alias.ts +0 -39
- package/src/allow.ts +1 -96
- package/src/aontu.ts +3 -110
- package/src/aontumodel.ts +32 -0
- package/src/cli.ts +113 -682
- package/src/ctx.ts +0 -103
- package/src/diff.ts +0 -40
- package/src/err.ts +0 -40
- package/src/escape.ts +0 -46
- package/src/exactjson.ts +0 -131
- package/src/format.ts +14 -257
- package/src/grammar.ts +72 -0
- package/src/graph.ts +0 -61
- package/src/hcanon.ts +0 -82
- package/src/helpdoc.ts +1 -1
- package/src/hints.ts +66 -57
- package/src/jsonschema.ts +0 -123
- package/src/keyorder.ts +0 -42
- package/src/lang.ts +19 -931
- package/src/lower.ts +12 -62
- package/src/lsp-server.ts +0 -16
- package/src/lsp.ts +12 -180
- package/src/mcp-server.ts +0 -31
- package/src/mcp.ts +0 -130
- package/src/mod-tool.ts +0 -158
- package/src/mod.ts +0 -178
- package/src/patch.ts +0 -232
- package/src/provenance.ts +0 -183
- package/src/query.ts +0 -84
- package/src/reach.ts +0 -53
- package/src/relation.ts +0 -84
- package/src/render.ts +20 -172
- package/src/report-sarif.ts +0 -48
- package/src/sig.ts +0 -35
- package/src/sigdecl.ts +1 -1
- package/src/siggate.ts +0 -30
- package/src/site.ts +3 -29
- package/src/subsume.ts +1 -161
- package/src/template.ts +69 -140
- package/src/trim.ts +0 -53
- package/src/type.ts +2 -45
- package/src/unify.ts +13 -251
- package/src/utility.ts +0 -31
- package/src/val/AbnfFuncVal.ts +181 -0
- package/src/val/AbsentVal.ts +54 -0
- package/src/val/AggFuncVal.ts +152 -188
- package/src/val/ArithFuncVal.ts +0 -20
- package/src/val/BagVal.ts +1 -78
- package/src/val/BigDecimalVal.ts +0 -16
- package/src/val/BigIntegerVal.ts +0 -16
- package/src/val/CloseFuncVal.ts +0 -9
- package/src/val/CmpFuncVal.ts +4 -166
- package/src/val/ConjunctVal.ts +0 -33
- package/src/val/ConstraintVal.ts +2 -537
- package/src/val/ContainerKindVal.ts +0 -18
- package/src/val/CopyFuncVal.ts +0 -5
- package/src/val/Decimal.ts +1 -185
- package/src/val/DeprecateFuncVal.ts +0 -10
- package/src/val/DisjunctVal.ts +0 -157
- package/src/val/EachFuncVal.ts +0 -40
- package/src/val/EmitFuncVal.ts +8 -208
- package/src/val/ExpectVal.ts +0 -62
- package/src/val/FilterFuncVal.ts +0 -55
- package/src/val/FuncBaseVal.ts +9 -130
- package/src/val/GraphAtomVal.ts +0 -42
- package/src/val/HideFuncVal.ts +0 -15
- package/src/val/IntegerVal.ts +0 -61
- package/src/val/JunctionVal.ts +0 -20
- package/src/val/KeyFuncVal.ts +0 -48
- package/src/val/ListVal.ts +0 -59
- package/src/val/LowerFuncVal.ts +0 -12
- package/src/val/MapVal.ts +0 -151
- package/src/val/MatchFuncVal.ts +0 -59
- package/src/val/MaybeFuncVal.ts +86 -0
- package/src/val/MoveFuncVal.ts +0 -20
- package/src/val/NilVal.ts +0 -60
- package/src/val/NomFuncVal.ts +8 -95
- package/src/val/NumberVal.ts +0 -16
- package/src/val/OpBaseVal.ts +4 -17
- package/src/val/PackFuncVal.ts +0 -63
- package/src/val/PathFuncVal.ts +0 -32
- package/src/val/PathVal.ts +0 -66
- package/src/val/PlaceVal.ts +0 -45
- package/src/val/PlusOpVal.ts +18 -75
- package/src/val/PrefFuncVal.ts +0 -1
- package/src/val/PrefVal.ts +0 -179
- package/src/val/RecurseVal.ts +0 -81
- package/src/val/RefVal.ts +1 -285
- package/src/val/ReferFuncVal.ts +0 -255
- package/src/val/ScalarKindVal.ts +0 -50
- package/src/val/ScalarVal.ts +0 -12
- package/src/val/StrFuncVal.ts +0 -44
- package/src/val/SuperFuncVal.ts +0 -42
- package/src/val/TopVal.ts +0 -1
- package/src/val/TranslateFuncVal.ts +1 -51
- package/src/val/UpperFuncVal.ts +0 -12
- package/src/val/Val.ts +3 -192
- package/src/val/VarVal.ts +0 -15
- package/src/val/arith.ts +0 -92
- package/src/val/caserange.ts +0 -62
- package/src/val/members.ts +0 -23
- package/src/val/numcmp.ts +1 -27
- package/src/val/numkind.ts +0 -149
- package/src/val/valutil.ts +0 -16
- package/src/vet.ts +1 -582
- package/src/view.ts +0 -507
- package/src/walk.ts +0 -41
- package/dist/std.d.ts +0 -3
- package/dist/std.js +0 -672
- package/dist/std.js.map +0 -1
- package/dist/val/FormFuncVal.js +0 -55
- package/dist/val/FormFuncVal.js.map +0 -1
- package/dist/val/NamerFuncVal.d.ts +0 -12
- package/dist/val/NamerFuncVal.js +0 -176
- package/dist/val/NamerFuncVal.js.map +0 -1
- package/src/std.ts +0 -683
package/src/jsonschema.ts
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
1
|
/* Copyright (c) 2025 Richard Rodger, MIT License */
|
|
2
2
|
import { includeOpts } from './utility'
|
|
3
3
|
|
|
4
|
-
// JSON SCHEMA EXPORT (the review's finding I / SUPPORT.md act 2).
|
|
5
|
-
//
|
|
6
|
-
// "JSON Schema's decisive 2026 advantage is not its validator ecosystem
|
|
7
|
-
// -- it is that every major LLM provider's structured-output API
|
|
8
|
-
// natively constrains generation to JSON Schema." Without an export,
|
|
9
|
-
// Aontu cannot ride that path and then apply `vet` as the semantic gate
|
|
10
|
-
// -- the hybrid an enterprise would actually deploy -- and an MCP tool's
|
|
11
|
-
// `inputSchema`, which the protocol REQUIRES to be JSON Schema, cannot
|
|
12
|
-
// be derived from an Aontu tool model at all (use case 09's interop
|
|
13
|
-
// wall).
|
|
14
|
-
//
|
|
15
|
-
// THE MAPPING IS LOSSY, AND SAYS SO PER CONSTRUCT. That is the whole
|
|
16
|
-
// design. Aontu's constraint algebra maps cleanly onto JSON Schema's
|
|
17
|
-
// core -- bounds, patterns, lengths, enums, required and closed -- and
|
|
18
|
-
// then stops: an evaluate-only `must()` is opaque by construction, an
|
|
19
|
-
// exact `0d` leaf has no JSON type that preserves it, a cross-field
|
|
20
|
-
// reference is not a property constraint at all, and `unique(k)` has no
|
|
21
|
-
// JSON Schema spelling. A converter that dropped those silently would
|
|
22
|
-
// hand its caller a schema that ADMITS MORE than the model does, which
|
|
23
|
-
// is the failure mode this whole language exists to refuse. So every
|
|
24
|
-
// loss is reported with its path, its construct and its reason, and
|
|
25
|
-
// `--strict` turns the report into a refusal.
|
|
26
|
-
//
|
|
27
|
-
// It exports the UNIFIED value, not the parse: what a document MEANS is
|
|
28
|
-
// what a consumer should be constrained to, and the meaning is what the
|
|
29
|
-
// fixpoint produced.
|
|
30
|
-
//
|
|
31
|
-
// Draft 2020-12, because that is what the structured-output APIs read.
|
|
32
4
|
|
|
33
5
|
import { Aontu } from './aontu'
|
|
34
6
|
import { makeNilErr } from './err'
|
|
@@ -54,9 +26,6 @@ export type SchemaLoss = {
|
|
|
54
26
|
export type SchemaVerdict = 'ok' | 'lossy' | 'error'
|
|
55
27
|
|
|
56
28
|
export type SchemaReport = {
|
|
57
|
-
// `ok` everything carried; `lossy` the schema is a WEAKER statement
|
|
58
|
-
// than the model; `error` the document does not stand up and there is
|
|
59
|
-
// nothing to export.
|
|
60
29
|
verdict: SchemaVerdict
|
|
61
30
|
// The JSON Schema document. Empty object on `error`.
|
|
62
31
|
schema: any
|
|
@@ -68,18 +37,12 @@ export type SchemaReport = {
|
|
|
68
37
|
}
|
|
69
38
|
|
|
70
39
|
export type SchemaOptions = {
|
|
71
|
-
// The subtree to export, as a path -- the same anchor `vet --at`
|
|
72
|
-
// takes, and parsed by the same walk, so `--at spec` means what it
|
|
73
|
-
// means everywhere else.
|
|
74
40
|
at?: string
|
|
75
41
|
// Where the document came from, so a relative `@"file"` resolves from
|
|
76
42
|
// its own directory.
|
|
77
43
|
path?: string
|
|
78
44
|
trust?: TrustOptions
|
|
79
45
|
|
|
80
|
-
// Extensions additionally read as text (the CLI's `--text-ext`).
|
|
81
|
-
// Rides beside `trust` because it is the other half of what an
|
|
82
|
-
// include may read.
|
|
83
46
|
textExt?: string[]
|
|
84
47
|
}
|
|
85
48
|
|
|
@@ -102,11 +65,6 @@ function lose(ctx: Ctx, path: string[], construct: string, reason: string) {
|
|
|
102
65
|
}
|
|
103
66
|
|
|
104
67
|
|
|
105
|
-
// The JSON type for a kind marker, by the marker CLASS's name -- the
|
|
106
|
-
// same load-bearing name canon renders (ScalarKindVal). `number` and
|
|
107
|
-
// its four leaves all become JSON's two numeric types; the exactness of
|
|
108
|
-
// `biginteger`/`bigdecimal` has no JSON type at all, which is a loss the
|
|
109
|
-
// caller is told about rather than a silent widening.
|
|
110
68
|
const KIND_TYPE: Record<string, string> = {
|
|
111
69
|
String: 'string',
|
|
112
70
|
Boolean: 'boolean',
|
|
@@ -115,17 +73,10 @@ const KIND_TYPE: Record<string, string> = {
|
|
|
115
73
|
Float: 'number',
|
|
116
74
|
BigDecimal: 'number',
|
|
117
75
|
Number: 'number',
|
|
118
|
-
// A path value is its address string at the JSON boundary
|
|
119
|
-
// (docs/design/PATHS.0.md), so the projection says `string` -- the
|
|
120
|
-
// same lossy-projection rule the exact numeric leaves follow.
|
|
121
76
|
Path: 'string',
|
|
122
77
|
}
|
|
123
78
|
|
|
124
79
|
|
|
125
|
-
// The JSON value of a concrete scalar, for `const`, `enum` and
|
|
126
|
-
// `default`. An exact leaf renders through its own digits rather than
|
|
127
|
-
// through binary64 -- and is reported as a loss where it is emitted,
|
|
128
|
-
// because JSON's number has no exactness to receive it.
|
|
129
80
|
function scalarJson(v: any): any {
|
|
130
81
|
if (v.isBigInteger) {
|
|
131
82
|
return Number(v.peg)
|
|
@@ -149,9 +100,6 @@ function scalarType(v: any): string {
|
|
|
149
100
|
}
|
|
150
101
|
|
|
151
102
|
|
|
152
|
-
// The constraint residual's atoms, onto JSON Schema's keywords. The
|
|
153
|
-
// three that map exactly (bounds, pattern, count) go across; the two
|
|
154
|
-
// that cannot (`must`, `unique(k)`) are reported.
|
|
155
103
|
function fromConstraint(ctx: Ctx, path: string[], c: any): any {
|
|
156
104
|
const out: any = {}
|
|
157
105
|
|
|
@@ -165,9 +113,6 @@ function fromConstraint(ctx: Ctx, path: string[], c: any): any {
|
|
|
165
113
|
out.type = 'number'
|
|
166
114
|
}
|
|
167
115
|
|
|
168
|
-
// Bounds. An OPEN endpoint is JSON Schema's exclusive form, which is
|
|
169
|
-
// a keyword of its own in 2020-12 rather than the boolean flag draft-4
|
|
170
|
-
// used.
|
|
171
116
|
if (null != c.lo) {
|
|
172
117
|
out[c.lo.open ? 'exclusiveMinimum' : 'minimum'] = scalarJson(c.lo.v)
|
|
173
118
|
}
|
|
@@ -181,11 +126,6 @@ function fromConstraint(ctx: Ctx, path: string[], c: any): any {
|
|
|
181
126
|
out.not = { enum: c.neqs.map(scalarJson) }
|
|
182
127
|
}
|
|
183
128
|
|
|
184
|
-
// Patterns. Aontu DEFINES its portable subset (`re`'s abbreviations
|
|
185
|
-
// mean the same in both ports); every member of that subset is also
|
|
186
|
-
// an ECMA-262 regular expression, which is what JSON Schema's
|
|
187
|
-
// `pattern` is read as, so this crosses without translation. More
|
|
188
|
-
// than one pattern needs `allOf`: `pattern` is a single keyword.
|
|
189
129
|
if (1 === c.res.length) {
|
|
190
130
|
out.pattern = c.res[0].src
|
|
191
131
|
}
|
|
@@ -193,10 +133,6 @@ function fromConstraint(ctx: Ctx, path: string[], c: any): any {
|
|
|
193
133
|
out.allOf = c.res.map((r: any) => ({ pattern: r.src }))
|
|
194
134
|
}
|
|
195
135
|
|
|
196
|
-
// A COUNT is a length or a size depending on what is counted, and the
|
|
197
|
-
// residual does not always know which. Where the domain says string,
|
|
198
|
-
// it is minLength/maxLength; otherwise the container keywords, since
|
|
199
|
-
// a count atom on a container is what `length` overwhelmingly means.
|
|
200
136
|
if (null != c.count) {
|
|
201
137
|
const lo = null == c.count.lo ? undefined : scalarJson(c.count.lo.v)
|
|
202
138
|
const hi = null == c.count.hi ? undefined : scalarJson(c.count.hi.v)
|
|
@@ -236,28 +172,6 @@ function fromConstraint(ctx: Ctx, path: string[], c: any): any {
|
|
|
236
172
|
}
|
|
237
173
|
|
|
238
174
|
|
|
239
|
-
// The exporter proper. Every arm answers a schema; the ones that cannot
|
|
240
|
-
// answer honestly report a loss and fall back to `{}`, which admits
|
|
241
|
-
// anything -- the safe direction for a document that will be checked
|
|
242
|
-
// again by `vet`, and the direction the loss report exists to make
|
|
243
|
-
// visible.
|
|
244
|
-
// NO DEFENSIVE GUARD ON `v`. Every caller walks a bag's own children
|
|
245
|
-
// and a bag holds Vals, so a non-Val here is not a degenerate input,
|
|
246
|
-
// it is a bug in this file -- and an unreachable `if` is a branch arm
|
|
247
|
-
// the ADR-002 gate counts and no `node:coverage ignore` suppresses
|
|
248
|
-
// (the marker drops LINES, not branches). Go's twin keeps its `nil ==
|
|
249
|
-
// v` arm because a missing map key there yields a typed nil rather
|
|
250
|
-
// than an absent property.
|
|
251
|
-
// DEPRECATION IS AN ANNOTATION, and 2020-12 has one: `deprecated`.
|
|
252
|
-
// The export used to drop the whole record in SILENCE -- no keyword,
|
|
253
|
-
// and no loss line even under --strict -- which is the one thing the
|
|
254
|
-
// verb's own contract says it never does (use-cases/BUGS.md §56).
|
|
255
|
-
//
|
|
256
|
-
// The boolean crosses faithfully. The record's STRINGS (msg, use,
|
|
257
|
-
// since) have no home in 2020-12, so they are reported as a loss
|
|
258
|
-
// rather than invented into `description`: this exporter emits no
|
|
259
|
-
// `description` anywhere, and quietly making it mean "deprecation
|
|
260
|
-
// note" would be a mapping a consumer cannot undo.
|
|
261
175
|
function fromVal(ctx: Ctx, path: string[], v: any): any {
|
|
262
176
|
const out = fromValInner(ctx, path, v)
|
|
263
177
|
|
|
@@ -278,18 +192,10 @@ function fromVal(ctx: Ctx, path: string[], v: any): any {
|
|
|
278
192
|
}
|
|
279
193
|
|
|
280
194
|
|
|
281
|
-
// The record's text keys -- the ones with nothing to carry them.
|
|
282
|
-
// `DEPRECATION_KEYS` in DeprecateFuncVal.ts is the authority on what a
|
|
283
|
-
// record may hold; this is that list, and a key added there without a
|
|
284
|
-
// JSON Schema home belongs here too.
|
|
285
195
|
const DEPRECATION_TEXT = ['msg', 'use', 'since']
|
|
286
196
|
|
|
287
197
|
|
|
288
198
|
function fromValInner(ctx: Ctx, path: string[], v: any): any {
|
|
289
|
-
// A preference is its inner value plus a DEFAULT. JSON Schema's
|
|
290
|
-
// `default` is annotation rather than constraint -- it does not
|
|
291
|
-
// validate -- which is exactly what a preference is when something
|
|
292
|
-
// else supplies the value.
|
|
293
199
|
if (true === v.isPref) {
|
|
294
200
|
const inner = fromVal(ctx, path, v.peg)
|
|
295
201
|
const gen = generated(v.peg)
|
|
@@ -304,12 +210,6 @@ function fromValInner(ctx: Ctx, path: string[], v: any): any {
|
|
|
304
210
|
return fromConstraint(ctx, path, v)
|
|
305
211
|
}
|
|
306
212
|
|
|
307
|
-
// A SIZING RESIDUE is a container and its own sizing atom, kept
|
|
308
|
-
// together because more members could still change the atom's reading
|
|
309
|
-
// (use-cases/BUGS.md §16). Both halves are exportable and both must
|
|
310
|
-
// be: the container gives the shape, the atom gives `uniqueItems` and
|
|
311
|
-
// the length keywords, and a walk that saw only "a conjunct" would
|
|
312
|
-
// report the whole field as unresolved and admit anything.
|
|
313
213
|
const residue = sizingResidue(v)
|
|
314
214
|
if (undefined !== residue) {
|
|
315
215
|
return {
|
|
@@ -334,10 +234,6 @@ function fromValInner(ctx: Ctx, path: string[], v: any): any {
|
|
|
334
234
|
'this leaf exists for cannot be carried; the schema says ' +
|
|
335
235
|
'"' + t + '" and a consumer may round')
|
|
336
236
|
}
|
|
337
|
-
// KIND_TYPE is TOTAL over the kinds a marker can carry, so there is
|
|
338
|
-
// no miss to fall back from -- and a fallback that cannot be taken
|
|
339
|
-
// is a branch arm the coverage gate counts. Go's twin keeps its
|
|
340
|
-
// empty-map arm, which its own ignore mechanism can carry.
|
|
341
237
|
return { type: t }
|
|
342
238
|
}
|
|
343
239
|
|
|
@@ -358,9 +254,6 @@ function fromValInner(ctx: Ctx, path: string[], v: any): any {
|
|
|
358
254
|
return { const: scalarJson(v), type: scalarType(v) }
|
|
359
255
|
}
|
|
360
256
|
|
|
361
|
-
// Everything else is residue: a reference that did not resolve, a
|
|
362
|
-
// function or operator still waiting, a nil. None of them is a
|
|
363
|
-
// property constraint, and guessing one would be inventing a promise.
|
|
364
257
|
lose(ctx, path, residueName(v),
|
|
365
258
|
'this is not a value yet, so there is nothing to constrain a ' +
|
|
366
259
|
'consumer to; the schema admits anything here')
|
|
@@ -380,10 +273,6 @@ function residueName(v: any): string {
|
|
|
380
273
|
// generate. Used for `default` and for `enum` members: both are VALUES
|
|
381
274
|
// in the schema, so a member that is itself a shape has none to give.
|
|
382
275
|
function generated(v: any): any {
|
|
383
|
-
// No try/catch: a collecting context RECORDS a failed generation on
|
|
384
|
-
// itself instead of throwing, which is the whole point of the mode.
|
|
385
|
-
// Neither `vet` nor the Go twin (`schemaGenerated`) wraps this
|
|
386
|
-
// either, and an untakeable catch is a branch arm the gate counts.
|
|
387
276
|
const a0 = new Aontu()
|
|
388
277
|
const ctx = a0.ctx({ collect: true })
|
|
389
278
|
const out = v.gen(ctx)
|
|
@@ -391,10 +280,6 @@ function generated(v: any): any {
|
|
|
391
280
|
}
|
|
392
281
|
|
|
393
282
|
|
|
394
|
-
// A disjunction of CONCRETE members is an enum -- the shape a
|
|
395
|
-
// structured-output API constrains best. Anything else is `anyOf`. A
|
|
396
|
-
// preferred member contributes the `default` either way, which is how
|
|
397
|
-
// `*"a"|"b"|"c"` reaches a provider as a defaulted enum.
|
|
398
283
|
function fromDisjunct(ctx: Ctx, path: string[], v: any): any {
|
|
399
284
|
const members: any[] = v.peg
|
|
400
285
|
let def: any = undefined
|
|
@@ -492,8 +377,6 @@ function fromList(ctx: Ctx, path: string[], v: any): any {
|
|
|
492
377
|
return out
|
|
493
378
|
}
|
|
494
379
|
|
|
495
|
-
// A written list literal is a TUPLE: position by position, and no
|
|
496
|
-
// more. 2020-12 spells that `prefixItems` plus `items: false`.
|
|
497
380
|
return {
|
|
498
381
|
type: 'array',
|
|
499
382
|
prefixItems: els.map((el: any, i: number) =>
|
|
@@ -509,12 +392,6 @@ export function jsonSchema(src: string, options?: SchemaOptions): SchemaReport {
|
|
|
509
392
|
const opts = options ?? {}
|
|
510
393
|
const aontu = new Aontu(includeOpts(opts))
|
|
511
394
|
|
|
512
|
-
// COLLECT MODE, so a syntax error arrives on the context rather than
|
|
513
|
-
// as a throw -- the same failure Go's `parseEntry` hands back as an
|
|
514
|
-
// error, reached by the branch below. No try/catch here for the same
|
|
515
|
-
// reason `vet` has none: the mode exists so the failure can be
|
|
516
|
-
// reported rather than escape, and a catch that cannot be entered is
|
|
517
|
-
// a branch arm the ADR-002 gate counts.
|
|
518
395
|
const actx = aontu.ctx({ collect: true })
|
|
519
396
|
const root: any = aontu.unify(src, { path: opts.path, collect: true }, actx)
|
|
520
397
|
|
package/src/keyorder.ts
CHANGED
|
@@ -1,47 +1,7 @@
|
|
|
1
1
|
/* Copyright (c) 2025 Richard Rodger, MIT License */
|
|
2
2
|
|
|
3
|
-
/*
|
|
4
|
-
* THE ONE MAP-KEY ORDER, shared by every site that emits keys.
|
|
5
|
-
*
|
|
6
|
-
* Map key order is not meaningful in unification, so both ports sort to
|
|
7
|
-
* make output independent of insertion and unification order. The order
|
|
8
|
-
* they sort into has to be the SAME order, and it was not.
|
|
9
|
-
*
|
|
10
|
-
* JavaScript compares strings by UTF-16 CODE UNIT. An astral character is
|
|
11
|
-
* stored as a surrogate pair beginning D800-DBFF, so `<` puts it BEFORE
|
|
12
|
-
* every character in U+E000-U+FFFF -- ahead of the private use area, of
|
|
13
|
-
* U+FFFD, of U+FFFF. Go sorts map keys as UTF-8 bytes, which is code
|
|
14
|
-
* POINT order, so it puts the astral character last. The two agree on
|
|
15
|
-
* everything below U+D800 and disagree above U+DFFF, which is why this
|
|
16
|
-
* survived: the shared suite had no key above the BMP at all, and three
|
|
17
|
-
* separate comments in the tree asserted the ports already agreed.
|
|
18
|
-
*
|
|
19
|
-
* CODE POINT ORDER WINS, and not merely because Go had it. Go's
|
|
20
|
-
* `generate()` returns a native map, so a consumer's own `json.Marshal`
|
|
21
|
-
* sorts byte-wise no matter what this engine chooses -- picking UTF-16
|
|
22
|
-
* order would leave the TypeScript output disagreeing with what a Go
|
|
23
|
-
* consumer produces from the same document.
|
|
24
|
-
*
|
|
25
|
-
* NOT Buffer.compare, which would be the obvious shortcut. A lone
|
|
26
|
-
* surrogate has no valid UTF-8 encoding, so Buffer.from replaces it with
|
|
27
|
-
* U+FFFD and two DISTINCT keys compare equal -- reintroducing exactly the
|
|
28
|
-
* insertion-order dependence the sort exists to remove. Iterating code
|
|
29
|
-
* points keeps distinct keys distinct.
|
|
30
|
-
*/
|
|
31
3
|
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Compare two map keys by Unicode CODE POINT.
|
|
35
|
-
*
|
|
36
|
-
* `String.prototype[Symbol.iterator]` yields whole code points, pairing
|
|
37
|
-
* surrogates, so this is a plain lexicographic compare of code point
|
|
38
|
-
* sequences -- the order Go's UTF-8 byte sort produces.
|
|
39
|
-
*/
|
|
40
4
|
function cmpCodePoint(a: string, b: string): number {
|
|
41
|
-
// Fast path: identical strings, and the common all-BMP case where the
|
|
42
|
-
// two orders coincide, still walk the iterator -- but the loop exits at
|
|
43
|
-
// the first differing code point, so it is one pass over the shared
|
|
44
|
-
// prefix rather than any conversion or allocation.
|
|
45
5
|
const ai = a[Symbol.iterator]()
|
|
46
6
|
const bi = b[Symbol.iterator]()
|
|
47
7
|
|
|
@@ -49,8 +9,6 @@ function cmpCodePoint(a: string, b: string): number {
|
|
|
49
9
|
const x = ai.next()
|
|
50
10
|
const y = bi.next()
|
|
51
11
|
|
|
52
|
-
// A prefix sorts before the string it is a prefix of, and two equal
|
|
53
|
-
// strings compare 0 -- the same rule a byte compare gives.
|
|
54
12
|
if (x.done) {
|
|
55
13
|
return y.done ? 0 : -1
|
|
56
14
|
}
|