@voxgig/sdkgen 4.46.0 → 4.47.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/bin/voxgig-sdkgen +1 -1
- package/dist/action/check.js +58 -4
- package/dist/action/check.js.map +1 -1
- package/dist/action/doctor.d.ts +5 -0
- package/dist/action/doctor.js +44 -4
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/package.d.ts +1 -1
- package/dist/action/package.js +6 -16
- package/dist/action/package.js.map +1 -1
- package/dist/action/remove.js +15 -4
- package/dist/action/remove.js.map +1 -1
- package/dist/action/resolve.d.ts +1 -0
- package/dist/action/resolve.js +10 -4
- package/dist/action/resolve.js.map +1 -1
- package/dist/admin/status.d.ts +7 -1
- package/dist/admin/status.js +34 -5
- package/dist/admin/status.js.map +1 -1
- package/dist/cmp/AgentGuide.js +27 -15
- package/dist/cmp/AgentGuide.js.map +1 -1
- package/dist/cmp/AgentGuideContent.d.ts +3 -3
- package/dist/cmp/AgentGuideContent.js +22 -11
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/AgentGuideFeature.js +14 -6
- package/dist/cmp/AgentGuideFeature.js.map +1 -1
- package/dist/cmp/AgentGuideTop.js +16 -8
- package/dist/cmp/AgentGuideTop.js.map +1 -1
- package/dist/cmp/Changelog.js +37 -7
- package/dist/cmp/Changelog.js.map +1 -1
- package/dist/cmp/Deploy.js +52 -16
- package/dist/cmp/Deploy.js.map +1 -1
- package/dist/cmp/Entity.js +1 -1
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/ExternalTarget.js +5 -0
- package/dist/cmp/ExternalTarget.js.map +1 -1
- package/dist/cmp/Feature.js +2 -2
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/Main.js +1 -1
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/PublishWorkflow.js +63 -53
- package/dist/cmp/PublishWorkflow.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +1 -1
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeModel.js +2 -2
- package/dist/cmp/ReadmeModel.js.map +1 -1
- package/dist/cmp/ReadmeStation.js +3 -3
- package/dist/cmp/ReadmeStation.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +57 -59
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/cmp/Registered.js +1 -1
- package/dist/cmp/Registered.js.map +1 -1
- package/dist/cmp/Security.js +23 -3
- package/dist/cmp/Security.js.map +1 -1
- package/dist/cmp/Test.js +1 -1
- package/dist/cmp/Test.js.map +1 -1
- package/dist/helpers/alongside.d.ts +2 -3
- package/dist/helpers/alongside.js +16 -15
- package/dist/helpers/alongside.js.map +1 -1
- package/dist/helpers/applicability.d.ts +2 -1
- package/dist/helpers/applicability.js +14 -1
- package/dist/helpers/applicability.js.map +1 -1
- package/dist/helpers/component.js +9 -1
- package/dist/helpers/component.js.map +1 -1
- package/dist/helpers/definitionPlan.js +0 -1
- package/dist/helpers/definitionPlan.js.map +1 -1
- package/dist/helpers/doctext.js +1 -0
- package/dist/helpers/doctext.js.map +1 -1
- package/dist/helpers/facts.js +174 -4
- package/dist/helpers/facts.js.map +1 -1
- package/dist/helpers/flowGuard.d.ts +1 -1
- package/dist/helpers/flowGuard.js +20 -7
- package/dist/helpers/flowGuard.js.map +1 -1
- package/dist/helpers/generated.d.ts +1 -0
- package/dist/helpers/generated.js +1 -1
- package/dist/helpers/generated.js.map +1 -1
- package/dist/helpers/graphqlPoint.d.ts +2 -1
- package/dist/helpers/graphqlPoint.js +17 -0
- package/dist/helpers/graphqlPoint.js.map +1 -1
- package/dist/helpers/guardModel.d.ts +2 -0
- package/dist/helpers/guardModel.js +41 -0
- package/dist/helpers/guardModel.js.map +1 -0
- package/dist/helpers/manifest.d.ts +2 -1
- package/dist/helpers/manifest.js +16 -0
- package/dist/helpers/manifest.js.map +1 -1
- package/dist/helpers/mcpTools.d.ts +2 -1
- package/dist/helpers/mcpTools.js +8 -1
- package/dist/helpers/mcpTools.js.map +1 -1
- package/dist/helpers/opShape.js +17 -17
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/packageMeta.d.ts +6 -4
- package/dist/helpers/packageMeta.js +68 -46
- package/dist/helpers/packageMeta.js.map +1 -1
- package/dist/helpers/placement.d.ts +15 -0
- package/dist/helpers/placement.js +76 -0
- package/dist/helpers/placement.js.map +1 -0
- package/dist/helpers/semver.d.ts +2 -1
- package/dist/helpers/semver.js +21 -0
- package/dist/helpers/semver.js.map +1 -1
- package/dist/helpers/serverVars.js +3 -2
- package/dist/helpers/serverVars.js.map +1 -1
- package/dist/helpers/shipped.d.ts +2 -1
- package/dist/helpers/shipped.js +12 -0
- package/dist/helpers/shipped.js.map +1 -1
- package/dist/helpers/sourcestring.d.ts +3 -0
- package/dist/helpers/sourcestring.js +43 -0
- package/dist/helpers/sourcestring.js.map +1 -0
- package/dist/helpers/stdrep.d.ts +1 -1
- package/dist/helpers/stdrep.js +5 -1
- package/dist/helpers/stdrep.js.map +1 -1
- package/dist/helpers/surface.d.ts +7 -0
- package/dist/helpers/surface.js +69 -0
- package/dist/helpers/surface.js.map +1 -0
- package/dist/helpers/targetguard.d.ts +13 -0
- package/dist/helpers/targetguard.js +65 -0
- package/dist/helpers/targetguard.js.map +1 -0
- package/dist/helpers/text.d.ts +3 -1
- package/dist/helpers/text.js +16 -0
- package/dist/helpers/text.js.map +1 -1
- package/dist/helpers/textguard.d.ts +31 -0
- package/dist/helpers/textguard.js +157 -0
- package/dist/helpers/textguard.js.map +1 -0
- package/dist/helpers/title.d.ts +4 -0
- package/dist/helpers/title.js +52 -0
- package/dist/helpers/title.js.map +1 -0
- package/dist/sdkgen.d.ts +4 -6
- package/dist/sdkgen.js +59 -69
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.d.ts +6 -2
- package/dist/testkit.js +4 -1
- package/dist/testkit.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/model/fact.aontu +106 -0
- package/model/sdkgen.aontu +9 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +1 -1
- package/project/.sdk/src/cmp/clojure/ReadmeQuick_clojure.ts +1 -1
- package/project/.sdk/src/cmp/cpp/ReadmeQuick_cpp.ts +1 -1
- package/project/.sdk/src/cmp/csharp/ReadmeQuick_csharp.ts +1 -1
- package/project/.sdk/src/cmp/elixir/ReadmeQuick_elixir.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
- package/project/.sdk/src/cmp/java/ReadmeQuick_java.ts +1 -1
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +1 -1
- package/project/.sdk/src/cmp/kotlin/ReadmeQuick_kotlin.ts +1 -1
- package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +1 -1
- package/project/.sdk/src/cmp/ocaml/ReadmeQuick_ocaml.ts +1 -1
- package/project/.sdk/src/cmp/perl/ReadmeQuick_perl.ts +1 -1
- package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +1 -1
- package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +1 -1
- package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +1 -1
- package/project/.sdk/src/cmp/scala/ReadmeQuick_scala.ts +1 -1
- package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +1 -1
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/TestDefinition_ts.ts +3 -1
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +1 -1
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +3 -1
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +2 -1
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +11 -2
- package/project/sdkgen-package.json +1 -1
- package/src/action/check.ts +78 -4
- package/src/action/doctor.ts +62 -4
- package/src/action/package.ts +1 -13
- package/src/action/remove.ts +19 -5
- package/src/action/resolve.ts +11 -4
- package/src/admin/status.ts +25 -5
- package/src/cmp/AgentGuide.ts +28 -15
- package/src/cmp/AgentGuideContent.ts +22 -11
- package/src/cmp/AgentGuideFeature.ts +15 -6
- package/src/cmp/AgentGuideTop.ts +17 -8
- package/src/cmp/Changelog.ts +46 -6
- package/src/cmp/Deploy.ts +59 -20
- package/src/cmp/Entity.ts +1 -1
- package/src/cmp/ExternalTarget.ts +6 -0
- package/src/cmp/Feature.ts +3 -3
- package/src/cmp/Main.ts +1 -1
- package/src/cmp/PublishWorkflow.ts +66 -58
- package/src/cmp/ReadmeIntro.ts +1 -1
- package/src/cmp/ReadmeModel.ts +2 -2
- package/src/cmp/ReadmeStation.ts +4 -5
- package/src/cmp/ReadmeTop.ts +60 -60
- package/src/cmp/Registered.ts +1 -1
- package/src/cmp/Security.ts +32 -5
- package/src/cmp/Test.ts +1 -1
- package/src/helpers/alongside.ts +16 -19
- package/src/helpers/applicability.ts +16 -1
- package/src/helpers/component.ts +11 -1
- package/src/helpers/definitionPlan.ts +0 -1
- package/src/helpers/doctext.ts +3 -1
- package/src/helpers/facts.ts +214 -5
- package/src/helpers/flowGuard.ts +22 -7
- package/src/helpers/generated.ts +3 -1
- package/src/helpers/graphqlPoint.ts +20 -1
- package/src/helpers/guardModel.ts +50 -0
- package/src/helpers/manifest.ts +19 -0
- package/src/helpers/mcpTools.ts +11 -1
- package/src/helpers/opShape.ts +16 -16
- package/src/helpers/packageMeta.ts +67 -43
- package/src/helpers/placement.ts +114 -0
- package/src/helpers/semver.ts +26 -0
- package/src/helpers/serverVars.ts +4 -2
- package/src/helpers/shipped.ts +13 -0
- package/src/helpers/sourcestring.ts +47 -0
- package/src/helpers/stdrep.ts +6 -1
- package/src/helpers/surface.ts +82 -0
- package/src/helpers/targetguard.ts +91 -0
- package/src/helpers/text.ts +22 -0
- package/src/helpers/textguard.ts +208 -0
- package/src/helpers/title.ts +59 -0
- package/src/sdkgen.ts +65 -85
- package/src/testkit.ts +12 -0
package/src/helpers/text.ts
CHANGED
|
@@ -28,6 +28,28 @@ function given(value: any): boolean {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
const DEFINITION_NAME: Record<string, [string, string]> = {
|
|
32
|
+
openapi: ['OpenAPI spec', 'OpenAPI specification'],
|
|
33
|
+
graphql: ['GraphQL schema', 'GraphQL schema'],
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// What a document calls the definition an SDK is generated from, by the
|
|
38
|
+
// definition-kind fact: in short, or in full.
|
|
39
|
+
function definitionName(kind: string, full = false): string {
|
|
40
|
+
return DEFINITION_NAME[kind]?.[full ? 1 : 0] ?? 'API definition'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// "a", "a and b", "a, b, and c".
|
|
45
|
+
function seriesList(items: string[]): string {
|
|
46
|
+
return items.length < 3 ? items.join(' and ') :
|
|
47
|
+
items.slice(0, -1).join(', ') + ', and ' + items[items.length - 1]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
31
51
|
export {
|
|
52
|
+
definitionName,
|
|
32
53
|
modelText,
|
|
54
|
+
seriesList,
|
|
33
55
|
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import Path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { anchors } from './doccheck'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// A document line, with the chain of labelled components that wrote it where
|
|
7
|
+
// the caller knows it.
|
|
8
|
+
type GuardLine = { text: string, chain: string }
|
|
9
|
+
|
|
10
|
+
type GuardFinding = {
|
|
11
|
+
relation: string
|
|
12
|
+
chain: string
|
|
13
|
+
cause: string
|
|
14
|
+
doc: string
|
|
15
|
+
line: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
type TextFinding = {
|
|
20
|
+
relation: 'link' | 'marker' | 'fence' | 'off'
|
|
21
|
+
doc: string
|
|
22
|
+
line: string
|
|
23
|
+
cause: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type TextGuardOptions = {
|
|
27
|
+
fences?: Record<string, string>
|
|
28
|
+
absent?: (string | RegExp)[]
|
|
29
|
+
present?: string[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// The code-block tag of each bundled SDK target's documents. A consumer, whose
|
|
34
|
+
// directory is the name of what it wraps and a suffix, writes that language.
|
|
35
|
+
const FENCES: Record<string, string> = {
|
|
36
|
+
c: 'c', clojure: 'clojure', cpp: 'cpp', csharp: 'csharp', elixir: 'elixir', go: 'go',
|
|
37
|
+
java: 'java', js: 'js', kotlin: 'kotlin', lua: 'lua', ocaml: 'ocaml', perl: 'perl',
|
|
38
|
+
php: 'php', py: 'python', rb: 'ruby', rust: 'rust', scala: 'scala', swift: 'swift',
|
|
39
|
+
ts: 'ts', zig: 'zig',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const NEUTRAL_FENCES = new Set(['', 'bash', 'sh', 'shell', 'console', 'text', 'json', 'jsonc',
|
|
43
|
+
'toml', 'yaml', 'xml', 'ini', 'diff'])
|
|
44
|
+
|
|
45
|
+
const MARKER = /\$\$[A-Za-z_][\w.$]*\$\$/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// A word only where no letter, `+` or `#` continues it: `C` is not a mention
|
|
49
|
+
// inside `C++` or `C#`.
|
|
50
|
+
function mention(w: string): RegExp {
|
|
51
|
+
return new RegExp('(?<![A-Za-z0-9_+#-])' + w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') +
|
|
52
|
+
'(?![A-Za-z0-9_+#])')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function docLines(files: Record<string, string>): Record<string, GuardLine[]> {
|
|
57
|
+
return Object.fromEntries(Object.entries(files)
|
|
58
|
+
.filter(([path, text]: [string, any]) => path.endsWith('.md') && 'string' === typeof text)
|
|
59
|
+
.map(([path, text]: [string, string]) =>
|
|
60
|
+
[path, text.split('\n').map((t: string) => ({ text: t, chain: '' }))]))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function isDir(present: Set<string>, dir: string): boolean {
|
|
65
|
+
const d = dir.replace(/\/+$/, '')
|
|
66
|
+
if ('' === d || '.' === d || '.sdk' === d || d.startsWith('.sdk/')) return true
|
|
67
|
+
for (const p of present) if (p.startsWith(d + '/')) return true
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// A relative link or anchor, or a `cd` in a shell block, that resolves to
|
|
73
|
+
// nothing the run wrote.
|
|
74
|
+
function linkFindings(
|
|
75
|
+
lines: Record<string, GuardLine[]>, files: Record<string, string>, present: Set<string>,
|
|
76
|
+
): GuardFinding[] {
|
|
77
|
+
const out: GuardFinding[] = []
|
|
78
|
+
for (const [doc, docLines] of Object.entries(lines)) {
|
|
79
|
+
const dir = Path.posix.dirname(doc)
|
|
80
|
+
let fence = ''
|
|
81
|
+
for (const { text, chain } of docLines) {
|
|
82
|
+
const open = /^\s*(```|~~~)\s*(\S*)/.exec(text)
|
|
83
|
+
if (open) {
|
|
84
|
+
fence = '' === fence ? (open[2] || 'text') : ''
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
if ('' !== fence) {
|
|
88
|
+
if (/^(bash|sh|shell|console)$/.test(fence)) {
|
|
89
|
+
const cd = /^\s*(?:\$\s*)?cd\s+([^\s;&|)]+)/.exec(text)
|
|
90
|
+
if (cd && !/^[~$\/]/.test(cd[1])) {
|
|
91
|
+
const fromDoc = Path.posix.normalize(Path.posix.join(dir, cd[1]))
|
|
92
|
+
const fromRoot = Path.posix.normalize(cd[1])
|
|
93
|
+
if (!isDir(present, fromDoc) && !isDir(present, fromRoot)) {
|
|
94
|
+
out.push({ relation: 'link', chain, cause: 'cd ' + cd[1], doc, line: text })
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
const bare = text.replace(/`[^`]*`/g, '')
|
|
101
|
+
for (const m of bare.matchAll(/\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g)) {
|
|
102
|
+
const href = m[1]
|
|
103
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith('/')) continue
|
|
104
|
+
const [rel, frag] = href.split('#')
|
|
105
|
+
const target = '' === rel ? doc : Path.posix.normalize(Path.posix.join(dir, rel))
|
|
106
|
+
if ('' !== rel && !present.has(target) && !isDir(present, target)) {
|
|
107
|
+
out.push({ relation: 'link', chain, cause: target, doc, line: text })
|
|
108
|
+
continue
|
|
109
|
+
}
|
|
110
|
+
if (null != frag && '' !== frag && target.endsWith('.md') && null != files[target] &&
|
|
111
|
+
!anchors(files[target]).has(frag)) {
|
|
112
|
+
out.push({ relation: 'link', chain, cause: target + '#' + frag, doc, line: text })
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
function markerFindings(lines: Record<string, GuardLine[]>): GuardFinding[] {
|
|
122
|
+
const out: GuardFinding[] = []
|
|
123
|
+
for (const [doc, docLines] of Object.entries(lines)) {
|
|
124
|
+
for (const { text, chain } of docLines) {
|
|
125
|
+
const found = MARKER.exec(text.replace(/`[^`]*`/g, ''))
|
|
126
|
+
if (null != found) {
|
|
127
|
+
out.push({ relation: 'marker', chain, cause: 'unfired', doc, line: text })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
// A code block in a target's documents is in that target's language, or is
|
|
136
|
+
// data or a shell session.
|
|
137
|
+
function fenceFindings(lines: Record<string, GuardLine[]>, fences: Record<string, string>): GuardFinding[] {
|
|
138
|
+
const out: GuardFinding[] = []
|
|
139
|
+
const keys = Object.keys(fences).sort()
|
|
140
|
+
for (const [doc, docLines] of Object.entries(lines)) {
|
|
141
|
+
const dir = doc.slice(0, Math.max(0, doc.indexOf('/')))
|
|
142
|
+
const own = fences[dir] ?? fences[keys.find((k: string) => dir.startsWith(k + '-')) ?? '']
|
|
143
|
+
if (null == own) continue
|
|
144
|
+
let open = false
|
|
145
|
+
for (const { text, chain } of docLines) {
|
|
146
|
+
const m = /^\s*```\s*(\S*)\s*$/.exec(text)
|
|
147
|
+
if (null == m) continue
|
|
148
|
+
if (!open && own !== m[1] && !NEUTRAL_FENCES.has(m[1])) {
|
|
149
|
+
out.push({ relation: 'fence', chain, cause: m[1], doc, line: text })
|
|
150
|
+
}
|
|
151
|
+
open = !open
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return out
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
// A line naming something the run removed; each mention is its cause.
|
|
159
|
+
function offFindings(lines: Record<string, GuardLine[]>, mentions: [string, RegExp][]): GuardFinding[] {
|
|
160
|
+
const out: GuardFinding[] = []
|
|
161
|
+
if (0 === mentions.length) return out
|
|
162
|
+
for (const [doc, docLines] of Object.entries(lines)) {
|
|
163
|
+
for (const { text, chain } of docLines) {
|
|
164
|
+
const hit = mentions.find(([, re]: [string, RegExp]) => re.test(text))
|
|
165
|
+
if (null != hit) {
|
|
166
|
+
out.push({ relation: 'off', chain, cause: hit[0], doc, line: text })
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return out
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
// The text guard over one generation: the Markdown in `files`, read for links
|
|
175
|
+
// and `cd`s that resolve to nothing written, unfired `$$path$$` markers, code
|
|
176
|
+
// blocks in another target's language, and lines naming an `absent` word.
|
|
177
|
+
function textGuard(files: Record<string, string>, opts: TextGuardOptions = {}): TextFinding[] {
|
|
178
|
+
const lines = docLines(files)
|
|
179
|
+
const present = new Set<string>([...Object.keys(files), ...(opts.present ?? [])])
|
|
180
|
+
const absent: [string, RegExp][] = (opts.absent ?? []).map((w: string | RegExp) =>
|
|
181
|
+
'string' === typeof w ? [w, mention(w)] : [w.source, new RegExp(w.source, w.flags.replace(/[gy]/g, ''))])
|
|
182
|
+
|
|
183
|
+
return [
|
|
184
|
+
...linkFindings(lines, files, present),
|
|
185
|
+
...markerFindings(lines),
|
|
186
|
+
...fenceFindings(lines, { ...FENCES, ...(opts.fences ?? {}) }),
|
|
187
|
+
...offFindings(lines, absent),
|
|
188
|
+
].map(({ relation, doc, line, cause }: GuardFinding) =>
|
|
189
|
+
({ relation, doc, line, cause }) as TextFinding)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
export type {
|
|
194
|
+
GuardFinding,
|
|
195
|
+
GuardLine,
|
|
196
|
+
TextFinding,
|
|
197
|
+
TextGuardOptions,
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export {
|
|
201
|
+
FENCES,
|
|
202
|
+
mention,
|
|
203
|
+
linkFindings,
|
|
204
|
+
markerFindings,
|
|
205
|
+
fenceFindings,
|
|
206
|
+
offFindings,
|
|
207
|
+
textGuard,
|
|
208
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
// A target's display name when its model declares no title, by the target's
|
|
3
|
+
// origin. A test holds each equal to the title its bundled model declares.
|
|
4
|
+
const LANG_LABEL: Record<string, string> = {
|
|
5
|
+
c: 'C',
|
|
6
|
+
clojure: 'Clojure',
|
|
7
|
+
cpp: 'C++',
|
|
8
|
+
csharp: 'C#',
|
|
9
|
+
elixir: 'Elixir',
|
|
10
|
+
go: 'Golang',
|
|
11
|
+
'go-cli': 'Go CLI',
|
|
12
|
+
'go-mcp': 'Go MCP server',
|
|
13
|
+
java: 'Java',
|
|
14
|
+
js: 'JavaScript',
|
|
15
|
+
kotlin: 'Kotlin',
|
|
16
|
+
lua: 'Lua',
|
|
17
|
+
ocaml: 'OCaml',
|
|
18
|
+
perl: 'Perl',
|
|
19
|
+
php: 'PHP',
|
|
20
|
+
py: 'Python',
|
|
21
|
+
'py-data': 'Python Data',
|
|
22
|
+
rb: 'Ruby',
|
|
23
|
+
rust: 'Rust',
|
|
24
|
+
scala: 'Scala',
|
|
25
|
+
swift: 'Swift',
|
|
26
|
+
ts: 'TypeScript',
|
|
27
|
+
zig: 'Zig',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
function langLabel(target: string): string {
|
|
32
|
+
return LANG_LABEL[target] || target
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function given(value: any): boolean {
|
|
37
|
+
return null != value && '' !== value
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// The title fact: the declared title, else the origin's label, else the key.
|
|
42
|
+
// Code, not a rule: aontu has no fallback for a member's absent field
|
|
43
|
+
// (aontu-lang/aontu#849).
|
|
44
|
+
function titleFacts(target: any): void {
|
|
45
|
+
for (const [name, t] of Object.entries(target || {})) {
|
|
46
|
+
const decl: any = t
|
|
47
|
+
if (null != decl?.fact && 'object' === typeof decl.fact) {
|
|
48
|
+
decl.fact.title = given(decl.title) ? String(decl.title) :
|
|
49
|
+
(LANG_LABEL[decl.fact.origin] ?? name)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
LANG_LABEL,
|
|
57
|
+
langLabel,
|
|
58
|
+
titleFacts,
|
|
59
|
+
}
|
package/src/sdkgen.ts
CHANGED
|
@@ -24,6 +24,9 @@ import { SdkGenError, requirePath, isAuthActive, resolveAuthPrefix, resolveAuthI
|
|
|
24
24
|
import { Main } from './cmp/Main'
|
|
25
25
|
import { featureApplies, targetFeatures, featureTags, unknownTags, TAGS } from './helpers/applicability'
|
|
26
26
|
import { ExternalTarget } from './cmp/ExternalTarget'
|
|
27
|
+
import { readOverride, runOutput } from './helpers/placement'
|
|
28
|
+
import { refuseBrokenTargets } from './helpers/targetguard'
|
|
29
|
+
import type { ExternalOverride } from './helpers/placement'
|
|
27
30
|
|
|
28
31
|
import { KIT, resolvedSpec } from '@voxgig/apidef'
|
|
29
32
|
import { Deploy } from './cmp/Deploy'
|
|
@@ -65,6 +68,8 @@ import { getMatchEntries } from './helpers/getMatchEntries'
|
|
|
65
68
|
import { collectDeps } from './helpers/collectDeps'
|
|
66
69
|
import { guardModelNames } from './helpers/modelNames'
|
|
67
70
|
import { guardFlowSteps } from './helpers/flowGuard'
|
|
71
|
+
import { guardModel } from './helpers/guardModel'
|
|
72
|
+
import { sourceString } from './helpers/sourcestring'
|
|
68
73
|
import { applyFacts, fact, refuseRootPlan } from './helpers/facts'
|
|
69
74
|
import { docFindings } from './helpers/doccheck'
|
|
70
75
|
import { claimedFiles, pruneGenerated } from './helpers/generated'
|
|
@@ -230,13 +235,6 @@ type SdkGenOptions = {
|
|
|
230
235
|
}
|
|
231
236
|
|
|
232
237
|
|
|
233
|
-
type ExternalOverride = {
|
|
234
|
-
path?: string
|
|
235
|
-
sdkrel?: string
|
|
236
|
-
enclosing?: boolean
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
238
|
const { Jostraca } = JostracaModule
|
|
241
239
|
|
|
242
240
|
|
|
@@ -322,20 +320,20 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
322
320
|
log.info({ point: 'generate-start', start, note: opts.dryrun ? '** DRY RUN **' : '' })
|
|
323
321
|
log.debug({ point: 'generate-spec', spec })
|
|
324
322
|
|
|
325
|
-
// BEFORE ANYTHING READS A NAME
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
guardModelNames(model, log)
|
|
331
|
-
warnUngeneratedOps(model, log, targetOrigins(model))
|
|
332
|
-
|
|
333
|
-
// A flow step whose call the runtime would refuse is switched off, so no
|
|
334
|
-
// generated test makes it; see helpers/flowGuard.
|
|
335
|
-
guardFlowSteps(model, log)
|
|
323
|
+
// BEFORE ANYTHING READS A NAME: the consumer's own Root.ts re-derives the
|
|
324
|
+
// names per target, so only a correction made to the model itself
|
|
325
|
+
// survives. A flow step whose call the runtime would refuse is switched
|
|
326
|
+
// off too. See helpers/modelNames and helpers/flowGuard.
|
|
327
|
+
guardModel(model, log)
|
|
336
328
|
|
|
337
329
|
applyFacts(model)
|
|
338
330
|
|
|
331
|
+
// A target that would generate an SDK broken at build or run time is a
|
|
332
|
+
// named error, so no document is gated on its state; see helpers/targetguard.
|
|
333
|
+
refuseBrokenTargets(model)
|
|
334
|
+
|
|
335
|
+
warnUngeneratedOps(model, log, targetOrigins(model))
|
|
336
|
+
|
|
339
337
|
let Root = spec.root
|
|
340
338
|
|
|
341
339
|
if (null == Root && null != config?.root) {
|
|
@@ -384,15 +382,23 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
384
382
|
checkExternalFolders(external, root, fs)
|
|
385
383
|
refuseRootPlan(model, external.map((ext) => ext.name))
|
|
386
384
|
|
|
385
|
+
// A run override moves a target for this run only, so the committed files
|
|
386
|
+
// keep describing the declared layout: the Root keeps the target, and the
|
|
387
|
+
// components that write the target's own files skip it.
|
|
388
|
+
const declaredOut = external.filter((ext) =>
|
|
389
|
+
'' !== String(model.main[KIT][ext.kind]?.[ext.name]?.output?.path ?? ''))
|
|
390
|
+
const relocated = external.filter((ext) => !declaredOut.includes(ext)).map((ext) => ext.name)
|
|
391
|
+
warnStale(fs, log, root, external.filter((ext) => relocated.includes(ext.name)))
|
|
392
|
+
|
|
387
393
|
const tree: { root?: any } = {}
|
|
388
|
-
const jres = await jostraca.generate(jopts, keepingTree(
|
|
389
|
-
() => Root({ model: 0 ===
|
|
394
|
+
const jres = await jostraca.generate({ ...jopts, meta: { ...jopts.meta, relocated } }, keepingTree(
|
|
395
|
+
() => Root({ model: 0 === declaredOut.length ? model : withoutExternal(model, declaredOut) }), tree))
|
|
390
396
|
|
|
391
397
|
showChanges(jopts.log, 'generate-result', jres, Path.dirname(process.cwd()))
|
|
392
398
|
checkDocs(tree.root, folder)
|
|
393
399
|
pruneGenerated({
|
|
394
400
|
fs, log, project: root, out: root, jres, claims: claimedFiles(tree.root, folder),
|
|
395
|
-
dryrun: !!opts.dryrun,
|
|
401
|
+
dryrun: !!opts.dryrun, keep: relocated.map((name: string) => name + '/'),
|
|
396
402
|
})
|
|
397
403
|
|
|
398
404
|
// Docgen owns editions, destinations, templates, text QA and deployment.
|
|
@@ -408,7 +414,7 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
408
414
|
const gone = false === ext.target.output?.create && !fs.existsSync(ext.folder)
|
|
409
415
|
|
|
410
416
|
if (null != ext.skip || gone) {
|
|
411
|
-
log.info({
|
|
417
|
+
log[ext.active ? 'warn' : 'info']({
|
|
412
418
|
point: 'generate-external-skip', target: ext.name, folder: ext.folder,
|
|
413
419
|
note: ext.skip ?? (ext.name + ' output folder disappeared after ' +
|
|
414
420
|
'preflight and output.create=false, not generated')
|
|
@@ -571,6 +577,10 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
571
577
|
|
|
572
578
|
model.const = projectConst(model)
|
|
573
579
|
|
|
580
|
+
// The model a generate prepares, without the notices, which belong to it.
|
|
581
|
+
guardModel(model)
|
|
582
|
+
applyFacts(model)
|
|
583
|
+
|
|
574
584
|
return {
|
|
575
585
|
model,
|
|
576
586
|
url: path,
|
|
@@ -710,60 +720,20 @@ type ExternalPlan = ExternalSpec & {
|
|
|
710
720
|
function resolveExternalOverride(
|
|
711
721
|
opts: SdkGenOptions, log: any, targets: string[],
|
|
712
722
|
): Record<string, ExternalOverride> {
|
|
713
|
-
const
|
|
714
|
-
const raw = process.env.SDKGEN_EXTERNAL
|
|
715
|
-
|
|
716
|
-
if (null == raw || '' === raw.trim()) {
|
|
717
|
-
return declared
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
let parsed: any
|
|
721
|
-
|
|
722
|
-
try {
|
|
723
|
-
parsed = JSON.parse(raw)
|
|
724
|
-
}
|
|
725
|
-
catch (err: any) {
|
|
726
|
-
throw new SdkGenError(
|
|
727
|
-
'SDKGEN_EXTERNAL is not valid JSON: ' + (err?.message || err) +
|
|
728
|
-
'\n Expected an object keyed by item name, for example:' +
|
|
729
|
-
'\n {"seneca-provider":{"path":"../..","sdkrel":".sdksrc/acme-sdk","enclosing":true}}' +
|
|
730
|
-
'\n Got: ' + raw.slice(0, 200))
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
if (null == parsed || 'object' !== typeof parsed || Array.isArray(parsed)) {
|
|
734
|
-
throw new SdkGenError(
|
|
735
|
-
'SDKGEN_EXTERNAL must be a JSON OBJECT keyed by item name, for example:' +
|
|
736
|
-
'\n {"seneca-provider":{"path":"../..","sdkrel":".sdksrc/acme-sdk","enclosing":true}}' +
|
|
737
|
-
'\n Got: ' + raw.slice(0, 200))
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// A misspelled name would otherwise change nothing and still be logged as
|
|
741
|
-
// an override.
|
|
742
|
-
const unknown = Object.keys(parsed).filter((name: string) => !targets.includes(name)).sort()
|
|
743
|
-
if (0 < unknown.length) {
|
|
744
|
-
throw new SdkGenError(
|
|
745
|
-
'SDKGEN_EXTERNAL names ' + unknown.join(', ') + ', which ' +
|
|
746
|
-
(1 === unknown.length ? 'is not a target' : 'are not targets') + ' of this model' +
|
|
747
|
-
'\n Its targets are: ' + [...targets].sort().join(', '))
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
const merged: Record<string, ExternalOverride> = { ...declared }
|
|
751
|
-
|
|
752
|
-
for (const name of Object.keys(parsed)) {
|
|
753
|
-
merged[name] = { ...(declared[name] || {}), ...(parsed[name] || {}) }
|
|
754
|
-
}
|
|
723
|
+
const { override, named } = readOverride(opts.external, process.env.SDKGEN_EXTERNAL, targets)
|
|
755
724
|
|
|
756
725
|
// LOUDLY. Generation writing somewhere other than the model says is
|
|
757
726
|
// exactly the thing whose only previous trace was one INFO line naming a
|
|
758
727
|
// resolved folder, and that cost a silent green run that emitted nothing.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
728
|
+
if (0 < named.length) {
|
|
729
|
+
log.info({
|
|
730
|
+
point: 'external-override',
|
|
731
|
+
items: named.join(','),
|
|
732
|
+
note: 'SDKGEN_EXTERNAL overrides the output of: ' + named.join(', '),
|
|
733
|
+
})
|
|
734
|
+
}
|
|
765
735
|
|
|
766
|
-
return
|
|
736
|
+
return override
|
|
767
737
|
}
|
|
768
738
|
|
|
769
739
|
|
|
@@ -781,20 +751,9 @@ function externalItems(
|
|
|
781
751
|
// Overrides are keyed by installed target name.
|
|
782
752
|
const ov = override[name] || {}
|
|
783
753
|
|
|
784
|
-
// A
|
|
785
|
-
//
|
|
786
|
-
|
|
787
|
-
// identity — withoutExternal keys by kind:name.
|
|
788
|
-
const output = { ...(items[name]?.output || {}) }
|
|
789
|
-
|
|
790
|
-
if (null != ov.path && '' !== ov.path) {
|
|
791
|
-
output.path = ov.path
|
|
792
|
-
// The override relocates this run's output, root placement included.
|
|
793
|
-
delete output.root
|
|
794
|
-
}
|
|
795
|
-
if (null != ov.sdkrel && '' !== ov.sdkrel) {
|
|
796
|
-
output.sdkrel = ov.sdkrel
|
|
797
|
-
}
|
|
754
|
+
// A copy, so the override never writes back into the model: the
|
|
755
|
+
// in-tree pass still reads it, and `target add` round-trips it to disk.
|
|
756
|
+
const output = runOutput(items[name]?.output, ov)
|
|
798
757
|
|
|
799
758
|
return { kind, name, target: { ...items[name], output }, ov }
|
|
800
759
|
})
|
|
@@ -818,6 +777,21 @@ function externalItems(
|
|
|
818
777
|
}
|
|
819
778
|
|
|
820
779
|
|
|
780
|
+
// A target this run writes elsewhere leaves its earlier in-tree output as it was.
|
|
781
|
+
function warnStale(fs: any, log: any, root: string, moved: ExternalSpec[]): void {
|
|
782
|
+
for (const ext of moved) {
|
|
783
|
+
const folder = Path.join(root, ext.name)
|
|
784
|
+
if (fs.existsSync(folder)) {
|
|
785
|
+
log.warn({
|
|
786
|
+
point: 'generate-external-stale', target: ext.name, folder,
|
|
787
|
+
note: ext.name + '/ holds an earlier in-tree generation, and this run writes ' +
|
|
788
|
+
ext.name + ' to ' + ext.folder + ': the in-tree copy is left as it was, and is stale'
|
|
789
|
+
})
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
|
|
821
795
|
function externalSkipReason(ext: ExternalSpec, fs: any): string | null {
|
|
822
796
|
if (!ext.active) {
|
|
823
797
|
return ext.name + ' inactive, not generated'
|
|
@@ -984,6 +958,10 @@ function withoutExternal(
|
|
|
984
958
|
kit[kind] = kept
|
|
985
959
|
}
|
|
986
960
|
|
|
961
|
+
if (Array.isArray(kit.fact?.active)) {
|
|
962
|
+
kit.fact = { ...kit.fact, active: kit.fact.active.filter((name: string) => !drop.has('target:' + name)) }
|
|
963
|
+
}
|
|
964
|
+
|
|
987
965
|
return {
|
|
988
966
|
...model,
|
|
989
967
|
main: { ...model.main, [KIT]: kit },
|
|
@@ -1217,6 +1195,8 @@ export {
|
|
|
1217
1195
|
entityCollection,
|
|
1218
1196
|
guardModelNames,
|
|
1219
1197
|
guardFlowSteps,
|
|
1198
|
+
guardModel,
|
|
1199
|
+
sourceString,
|
|
1220
1200
|
applyFacts,
|
|
1221
1201
|
fact,
|
|
1222
1202
|
projectConst,
|
package/src/testkit.ts
CHANGED
|
@@ -14,6 +14,11 @@ import { ACTION_MAP } from './action/dispatch'
|
|
|
14
14
|
|
|
15
15
|
import { KIT } from './types'
|
|
16
16
|
|
|
17
|
+
import type { ExternalOverride } from './helpers/placement'
|
|
18
|
+
|
|
19
|
+
import { textGuard } from './helpers/textguard'
|
|
20
|
+
import type { TextFinding, TextGuardOptions } from './helpers/textguard'
|
|
21
|
+
|
|
17
22
|
|
|
18
23
|
// This package's own root — `<...>/node_modules/@voxgig/sdkgen` for a
|
|
19
24
|
// consumer, or the checkout when sdkgen tests itself. Computed from this
|
|
@@ -402,6 +407,9 @@ type GenerateOptions = {
|
|
|
402
407
|
allowPlaceholder?: (path: string, token: string) => boolean
|
|
403
408
|
|
|
404
409
|
outside?: string[]
|
|
410
|
+
|
|
411
|
+
// Generate's `external` option: SDKGEN_EXTERNAL for this call alone.
|
|
412
|
+
external?: Record<string, ExternalOverride>
|
|
405
413
|
}
|
|
406
414
|
|
|
407
415
|
|
|
@@ -444,6 +452,7 @@ async function generateInto(
|
|
|
444
452
|
folder: consumer.root,
|
|
445
453
|
root: '',
|
|
446
454
|
pino: consumer.log,
|
|
455
|
+
external: opts.external,
|
|
447
456
|
})
|
|
448
457
|
|
|
449
458
|
const prevcwd = process.cwd()
|
|
@@ -660,6 +669,8 @@ export type {
|
|
|
660
669
|
StageOptions,
|
|
661
670
|
GenerateOptions,
|
|
662
671
|
GenerateResult,
|
|
672
|
+
TextFinding,
|
|
673
|
+
TextGuardOptions,
|
|
663
674
|
}
|
|
664
675
|
|
|
665
676
|
export {
|
|
@@ -669,4 +680,5 @@ export {
|
|
|
669
680
|
stageConsumer,
|
|
670
681
|
generateInto,
|
|
671
682
|
manifestParity,
|
|
683
|
+
textGuard,
|
|
672
684
|
}
|