@voxgig/sdkgen 4.45.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 +73 -4
- package/dist/action/check.js.map +1 -1
- package/dist/action/copies.js +1 -0
- package/dist/action/copies.js.map +1 -1
- package/dist/action/doctor.d.ts +26 -2
- package/dist/action/doctor.js +208 -11
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/package.d.ts +1 -1
- package/dist/action/package.js +15 -16
- package/dist/action/package.js.map +1 -1
- package/dist/action/remove.js +16 -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/action/target.d.ts +2 -1
- package/dist/action/target.js +50 -11
- package/dist/action/target.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 +46 -23
- package/dist/cmp/AgentGuide.js.map +1 -1
- package/dist/cmp/AgentGuideContent.d.ts +9 -7
- package/dist/cmp/AgentGuideContent.js +73 -43
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/AgentGuideFeature.js +19 -9
- package/dist/cmp/AgentGuideFeature.js.map +1 -1
- package/dist/cmp/AgentGuideTop.js +95 -49
- package/dist/cmp/AgentGuideTop.js.map +1 -1
- package/dist/cmp/Changelog.js +45 -4
- package/dist/cmp/Changelog.js.map +1 -1
- package/dist/cmp/Deploy.js +73 -35
- 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 +10 -5
- package/dist/cmp/ExternalTarget.js.map +1 -1
- package/dist/cmp/Feature.js +12 -5
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureDocs.d.ts +6 -4
- package/dist/cmp/FeatureDocs.js +14 -39
- package/dist/cmp/FeatureDocs.js.map +1 -1
- package/dist/cmp/FeatureHook.d.ts +7 -1
- package/dist/cmp/FeatureHook.js +34 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js +1 -1
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/PublishWorkflow.js +89 -55
- package/dist/cmp/PublishWorkflow.js.map +1 -1
- package/dist/cmp/ReadmeErrors.js +521 -18
- package/dist/cmp/ReadmeErrors.js.map +1 -1
- package/dist/cmp/ReadmeExplanation.js +280 -44
- package/dist/cmp/ReadmeExplanation.js.map +1 -1
- package/dist/cmp/ReadmeFeatures.js +16 -7
- package/dist/cmp/ReadmeFeatures.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +4 -3
- 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/ReadmeRefFeatures.js +34 -24
- package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
- package/dist/cmp/ReadmeStation.js +12 -9
- package/dist/cmp/ReadmeStation.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +479 -382
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/cmp/ReadmeUnions.js +8 -2
- package/dist/cmp/ReadmeUnions.js.map +1 -1
- package/dist/cmp/Registered.js +1 -1
- package/dist/cmp/Registered.js.map +1 -1
- package/dist/cmp/Security.js +26 -5
- 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 +3 -1
- package/dist/helpers/applicability.js +40 -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/copymerge.d.ts +3 -0
- package/dist/helpers/copymerge.js +43 -10
- package/dist/helpers/copymerge.js.map +1 -1
- package/dist/helpers/definitionPlan.js +0 -1
- package/dist/helpers/definitionPlan.js.map +1 -1
- package/dist/helpers/doccheck.d.ts +11 -0
- package/dist/helpers/doccheck.js +146 -0
- package/dist/helpers/doccheck.js.map +1 -0
- package/dist/helpers/doctext.d.ts +11 -0
- package/dist/helpers/doctext.js +85 -0
- package/dist/helpers/doctext.js.map +1 -0
- package/dist/helpers/exampleCall.d.ts +16 -0
- package/dist/helpers/exampleCall.js +334 -0
- package/dist/helpers/exampleCall.js.map +1 -0
- package/dist/helpers/exportnames.d.ts +4 -0
- package/dist/helpers/exportnames.js +35 -0
- package/dist/helpers/exportnames.js.map +1 -0
- package/dist/helpers/facts.d.ts +2 -1
- package/dist/helpers/facts.js +210 -5
- 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/modelcheck.d.ts +2 -1
- package/dist/helpers/modelcheck.js +13 -0
- package/dist/helpers/modelcheck.js.map +1 -1
- package/dist/helpers/opExample.d.ts +9 -2
- package/dist/helpers/opExample.js +22 -2
- package/dist/helpers/opExample.js.map +1 -1
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +29 -17
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/packageMeta.d.ts +6 -4
- package/dist/helpers/packageMeta.js +88 -53
- 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 +3 -1
- package/dist/helpers/semver.js +28 -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 +72 -63
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.d.ts +7 -2
- package/dist/testkit.js +27 -20
- package/dist/testkit.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +2 -1
- package/dist/utility.js.map +1 -1
- package/model/fact.aontu +150 -0
- package/model/sdkgen.aontu +15 -3
- package/package.json +3 -1
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +2 -2
- package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +1 -1
- package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +12 -3
- 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/scala/ReadmeRef_scala.ts +4 -1
- package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +2 -1
- package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +3 -0
- package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -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/ReadmeOptions_zig.ts +1 -1
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +3 -3
- package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
- 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 +99 -4
- package/src/action/copies.ts +2 -0
- package/src/action/doctor.ts +304 -15
- package/src/action/package.ts +11 -13
- package/src/action/remove.ts +20 -5
- package/src/action/resolve.ts +11 -4
- package/src/action/target.ts +66 -15
- package/src/admin/status.ts +25 -5
- package/src/cmp/AgentGuide.ts +52 -25
- package/src/cmp/AgentGuideContent.ts +75 -43
- package/src/cmp/AgentGuideFeature.ts +21 -10
- package/src/cmp/AgentGuideTop.ts +119 -49
- package/src/cmp/Changelog.ts +56 -5
- package/src/cmp/Deploy.ts +81 -40
- package/src/cmp/Entity.ts +1 -1
- package/src/cmp/ExternalTarget.ts +12 -6
- package/src/cmp/Feature.ts +13 -6
- package/src/cmp/FeatureDocs.ts +21 -40
- package/src/cmp/FeatureHook.ts +38 -1
- package/src/cmp/Main.ts +1 -1
- package/src/cmp/PublishWorkflow.ts +94 -60
- package/src/cmp/ReadmeErrors.ts +555 -25
- package/src/cmp/ReadmeExplanation.ts +316 -52
- package/src/cmp/ReadmeFeatures.ts +18 -8
- package/src/cmp/ReadmeIntro.ts +4 -3
- package/src/cmp/ReadmeModel.ts +2 -2
- package/src/cmp/ReadmeRefFeatures.ts +39 -27
- package/src/cmp/ReadmeStation.ts +13 -16
- package/src/cmp/ReadmeTop.ts +538 -397
- package/src/cmp/ReadmeUnions.ts +10 -2
- package/src/cmp/Registered.ts +1 -1
- package/src/cmp/Security.ts +35 -7
- package/src/cmp/Test.ts +1 -1
- package/src/helpers/alongside.ts +16 -19
- package/src/helpers/applicability.ts +44 -1
- package/src/helpers/component.ts +11 -1
- package/src/helpers/copymerge.ts +58 -10
- package/src/helpers/definitionPlan.ts +0 -1
- package/src/helpers/doccheck.ts +174 -0
- package/src/helpers/doctext.ts +115 -0
- package/src/helpers/exampleCall.ts +415 -0
- package/src/helpers/exportnames.ts +47 -0
- package/src/helpers/facts.ts +259 -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/modelcheck.ts +16 -0
- package/src/helpers/opExample.ts +34 -2
- package/src/helpers/opShape.ts +29 -16
- package/src/helpers/packageMeta.ts +89 -52
- package/src/helpers/placement.ts +114 -0
- package/src/helpers/semver.ts +35 -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 +82 -78
- package/src/testkit.ts +42 -20
- package/src/utility.ts +2 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { KIT, getModelPath } from '../types'
|
|
2
|
+
import { fact } from './facts'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// What the `surface` slot may hold, each word with the release that first
|
|
6
|
+
// reads it. The schema leaves the slot open; package check holds it to these,
|
|
7
|
+
// and a document names a target with any other word by its title alone.
|
|
8
|
+
const SURFACE_SINCE: Record<string, string> = {
|
|
9
|
+
sdk: '4.47.0',
|
|
10
|
+
cli: '4.47.0',
|
|
11
|
+
mcp: '4.47.0',
|
|
12
|
+
data: '4.47.0',
|
|
13
|
+
'seneca-provider': '4.47.0',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const SURFACES = Object.keys(SURFACE_SINCE)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const SURFACE_WORD: Record<string, string> = {
|
|
20
|
+
sdk: 'SDK',
|
|
21
|
+
cli: 'CLI',
|
|
22
|
+
mcp: 'MCP',
|
|
23
|
+
data: 'data',
|
|
24
|
+
'seneca-provider': 'Seneca provider',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const SURFACE_NOUN: Record<string, string> = {
|
|
29
|
+
sdk: 'SDK',
|
|
30
|
+
cli: 'CLI',
|
|
31
|
+
mcp: 'MCP server',
|
|
32
|
+
data: 'data package',
|
|
33
|
+
'seneca-provider': 'Seneca provider',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function surfaceOf(target: any): string {
|
|
38
|
+
const surface = fact(target, 'surface')
|
|
39
|
+
return SURFACES.includes(surface) ? surface : ''
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// The title and the noun for what the target is, with the noun's words the
|
|
44
|
+
// title already ends with said once: "Go CLI", "Python Data package".
|
|
45
|
+
function surfaceName(target: any): string {
|
|
46
|
+
const title = String(fact(target, 'title')).split(' ')
|
|
47
|
+
const noun = (SURFACE_NOUN[surfaceOf(target)] ?? 'package').split(' ')
|
|
48
|
+
for (let k = Math.min(title.length, noun.length); 0 < k; k--) {
|
|
49
|
+
if (title.slice(-k).join(' ').toLowerCase() === noun.slice(0, k).join(' ').toLowerCase()) {
|
|
50
|
+
return [...title, ...noun.slice(k)].join(' ')
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [...title, ...noun].join(' ')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// The configured languages by origin, then the rest, then the CLI and MCP server.
|
|
58
|
+
function documentOrder(model: any, targets: any[]): any[] {
|
|
59
|
+
const order: string[] = (getModelPath(model, `main.${KIT}.config.docs_order`,
|
|
60
|
+
{ only_active: false, required: false }) as any) || []
|
|
61
|
+
|
|
62
|
+
const rank = (t: any): number => {
|
|
63
|
+
const i = order.indexOf(fact(t, 'origin'))
|
|
64
|
+
if (-1 !== i) return i
|
|
65
|
+
const surface = surfaceOf(t)
|
|
66
|
+
if ('cli' === surface) return order.length + 1
|
|
67
|
+
if ('mcp' === surface) return order.length + 2
|
|
68
|
+
return order.length
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return targets.slice().sort((a: any, b: any) => rank(a) - rank(b))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
SURFACES,
|
|
77
|
+
SURFACE_SINCE,
|
|
78
|
+
SURFACE_WORD,
|
|
79
|
+
documentOrder,
|
|
80
|
+
surfaceName,
|
|
81
|
+
surfaceOf,
|
|
82
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { KIT } from '@voxgig/apidef'
|
|
2
|
+
|
|
3
|
+
import { fact } from './facts'
|
|
4
|
+
import { surfaceOf } from './surface'
|
|
5
|
+
import { SdkGenError } from '../utility'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// What every SDK target's generated suite and test mode need.
|
|
9
|
+
const REQUIRED_FEATURE = 'test'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type BrokenTarget = {
|
|
13
|
+
target: string
|
|
14
|
+
problem: 'untested' | 'entityless'
|
|
15
|
+
note: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function activeTargets(model: any): [string, any][] {
|
|
20
|
+
const kit = model.main[KIT]
|
|
21
|
+
return (fact(kit, 'active') as string[]).map((name: string) => [name, kit.target[name]])
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// An SDK, by its declared surface or by running an SDK's other phases,
|
|
26
|
+
// whose entity phase is off. A target that switches every phase off is a
|
|
27
|
+
// consumer, and one with a surface other than `sdk` says what it is.
|
|
28
|
+
function entityless(target: any): boolean {
|
|
29
|
+
const phase = fact(target, 'phase')
|
|
30
|
+
if (false !== phase.entity) {
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
const surface = fact(target, 'surface')
|
|
34
|
+
return 'sdk' === surface ||
|
|
35
|
+
('' === surface && (phase.feature || phase.readme || phase.agentguide || phase.test))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
function untestedTargets(model: any): BrokenTarget[] {
|
|
40
|
+
if (true === model.main[KIT].feature?.[REQUIRED_FEATURE]?.active) {
|
|
41
|
+
return []
|
|
42
|
+
}
|
|
43
|
+
return activeTargets(model)
|
|
44
|
+
.filter(([, target]: [string, any]) => 'sdk' === surfaceOf(target))
|
|
45
|
+
.map(([name]: [string, any]) => ({
|
|
46
|
+
target: name, problem: 'untested',
|
|
47
|
+
note: 'Target "' + name + '" is an SDK, and the model has no active `' +
|
|
48
|
+
REQUIRED_FEATURE + '` feature, which its generated tests and test mode need. ' +
|
|
49
|
+
'Run `voxgig-sdkgen target add ' + name + '`, which installs it.',
|
|
50
|
+
}))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function entitylessTargets(model: any): BrokenTarget[] {
|
|
55
|
+
return activeTargets(model)
|
|
56
|
+
.filter(([, target]: [string, any]) => entityless(target))
|
|
57
|
+
.map(([name]: [string, any]) => ({
|
|
58
|
+
target: name, problem: 'entityless',
|
|
59
|
+
note: entitylessNote(name),
|
|
60
|
+
}))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function entitylessNote(name: string): string {
|
|
65
|
+
return 'Target "' + name + '" is an SDK with its entity phase off: its main ' +
|
|
66
|
+
'module and documents name the entity classes that phase writes, so the SDK ' +
|
|
67
|
+
'does not build. Remove `phase: entity: active: false` from its model or, ' +
|
|
68
|
+
'for a target that is not an SDK, declare its `surface`.'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function refuseBrokenTargets(model: any): void {
|
|
73
|
+
const broken = [...untestedTargets(model), ...entitylessTargets(model)]
|
|
74
|
+
if (0 < broken.length) {
|
|
75
|
+
throw new SdkGenError(broken.map((b: BrokenTarget) => b.note).join('\n'))
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export type {
|
|
81
|
+
BrokenTarget,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
REQUIRED_FEATURE,
|
|
86
|
+
entityless,
|
|
87
|
+
untestedTargets,
|
|
88
|
+
entitylessTargets,
|
|
89
|
+
entitylessNote,
|
|
90
|
+
refuseBrokenTargets,
|
|
91
|
+
}
|
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
|
+
}
|