@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.
Files changed (276) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/check.js +73 -4
  3. package/dist/action/check.js.map +1 -1
  4. package/dist/action/copies.js +1 -0
  5. package/dist/action/copies.js.map +1 -1
  6. package/dist/action/doctor.d.ts +26 -2
  7. package/dist/action/doctor.js +208 -11
  8. package/dist/action/doctor.js.map +1 -1
  9. package/dist/action/package.d.ts +1 -1
  10. package/dist/action/package.js +15 -16
  11. package/dist/action/package.js.map +1 -1
  12. package/dist/action/remove.js +16 -4
  13. package/dist/action/remove.js.map +1 -1
  14. package/dist/action/resolve.d.ts +1 -0
  15. package/dist/action/resolve.js +10 -4
  16. package/dist/action/resolve.js.map +1 -1
  17. package/dist/action/target.d.ts +2 -1
  18. package/dist/action/target.js +50 -11
  19. package/dist/action/target.js.map +1 -1
  20. package/dist/admin/status.d.ts +7 -1
  21. package/dist/admin/status.js +34 -5
  22. package/dist/admin/status.js.map +1 -1
  23. package/dist/cmp/AgentGuide.js +46 -23
  24. package/dist/cmp/AgentGuide.js.map +1 -1
  25. package/dist/cmp/AgentGuideContent.d.ts +9 -7
  26. package/dist/cmp/AgentGuideContent.js +73 -43
  27. package/dist/cmp/AgentGuideContent.js.map +1 -1
  28. package/dist/cmp/AgentGuideFeature.js +19 -9
  29. package/dist/cmp/AgentGuideFeature.js.map +1 -1
  30. package/dist/cmp/AgentGuideTop.js +95 -49
  31. package/dist/cmp/AgentGuideTop.js.map +1 -1
  32. package/dist/cmp/Changelog.js +45 -4
  33. package/dist/cmp/Changelog.js.map +1 -1
  34. package/dist/cmp/Deploy.js +73 -35
  35. package/dist/cmp/Deploy.js.map +1 -1
  36. package/dist/cmp/Entity.js +1 -1
  37. package/dist/cmp/Entity.js.map +1 -1
  38. package/dist/cmp/ExternalTarget.js +10 -5
  39. package/dist/cmp/ExternalTarget.js.map +1 -1
  40. package/dist/cmp/Feature.js +12 -5
  41. package/dist/cmp/Feature.js.map +1 -1
  42. package/dist/cmp/FeatureDocs.d.ts +6 -4
  43. package/dist/cmp/FeatureDocs.js +14 -39
  44. package/dist/cmp/FeatureDocs.js.map +1 -1
  45. package/dist/cmp/FeatureHook.d.ts +7 -1
  46. package/dist/cmp/FeatureHook.js +34 -1
  47. package/dist/cmp/FeatureHook.js.map +1 -1
  48. package/dist/cmp/Main.js +1 -1
  49. package/dist/cmp/Main.js.map +1 -1
  50. package/dist/cmp/PublishWorkflow.js +89 -55
  51. package/dist/cmp/PublishWorkflow.js.map +1 -1
  52. package/dist/cmp/ReadmeErrors.js +521 -18
  53. package/dist/cmp/ReadmeErrors.js.map +1 -1
  54. package/dist/cmp/ReadmeExplanation.js +280 -44
  55. package/dist/cmp/ReadmeExplanation.js.map +1 -1
  56. package/dist/cmp/ReadmeFeatures.js +16 -7
  57. package/dist/cmp/ReadmeFeatures.js.map +1 -1
  58. package/dist/cmp/ReadmeIntro.js +4 -3
  59. package/dist/cmp/ReadmeIntro.js.map +1 -1
  60. package/dist/cmp/ReadmeModel.js +2 -2
  61. package/dist/cmp/ReadmeModel.js.map +1 -1
  62. package/dist/cmp/ReadmeRefFeatures.js +34 -24
  63. package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
  64. package/dist/cmp/ReadmeStation.js +12 -9
  65. package/dist/cmp/ReadmeStation.js.map +1 -1
  66. package/dist/cmp/ReadmeTop.js +479 -382
  67. package/dist/cmp/ReadmeTop.js.map +1 -1
  68. package/dist/cmp/ReadmeUnions.js +8 -2
  69. package/dist/cmp/ReadmeUnions.js.map +1 -1
  70. package/dist/cmp/Registered.js +1 -1
  71. package/dist/cmp/Registered.js.map +1 -1
  72. package/dist/cmp/Security.js +26 -5
  73. package/dist/cmp/Security.js.map +1 -1
  74. package/dist/cmp/Test.js +1 -1
  75. package/dist/cmp/Test.js.map +1 -1
  76. package/dist/helpers/alongside.d.ts +2 -3
  77. package/dist/helpers/alongside.js +16 -15
  78. package/dist/helpers/alongside.js.map +1 -1
  79. package/dist/helpers/applicability.d.ts +3 -1
  80. package/dist/helpers/applicability.js +40 -1
  81. package/dist/helpers/applicability.js.map +1 -1
  82. package/dist/helpers/component.js +9 -1
  83. package/dist/helpers/component.js.map +1 -1
  84. package/dist/helpers/copymerge.d.ts +3 -0
  85. package/dist/helpers/copymerge.js +43 -10
  86. package/dist/helpers/copymerge.js.map +1 -1
  87. package/dist/helpers/definitionPlan.js +0 -1
  88. package/dist/helpers/definitionPlan.js.map +1 -1
  89. package/dist/helpers/doccheck.d.ts +11 -0
  90. package/dist/helpers/doccheck.js +146 -0
  91. package/dist/helpers/doccheck.js.map +1 -0
  92. package/dist/helpers/doctext.d.ts +11 -0
  93. package/dist/helpers/doctext.js +85 -0
  94. package/dist/helpers/doctext.js.map +1 -0
  95. package/dist/helpers/exampleCall.d.ts +16 -0
  96. package/dist/helpers/exampleCall.js +334 -0
  97. package/dist/helpers/exampleCall.js.map +1 -0
  98. package/dist/helpers/exportnames.d.ts +4 -0
  99. package/dist/helpers/exportnames.js +35 -0
  100. package/dist/helpers/exportnames.js.map +1 -0
  101. package/dist/helpers/facts.d.ts +2 -1
  102. package/dist/helpers/facts.js +210 -5
  103. package/dist/helpers/facts.js.map +1 -1
  104. package/dist/helpers/flowGuard.d.ts +1 -1
  105. package/dist/helpers/flowGuard.js +20 -7
  106. package/dist/helpers/flowGuard.js.map +1 -1
  107. package/dist/helpers/generated.d.ts +1 -0
  108. package/dist/helpers/generated.js +1 -1
  109. package/dist/helpers/generated.js.map +1 -1
  110. package/dist/helpers/graphqlPoint.d.ts +2 -1
  111. package/dist/helpers/graphqlPoint.js +17 -0
  112. package/dist/helpers/graphqlPoint.js.map +1 -1
  113. package/dist/helpers/guardModel.d.ts +2 -0
  114. package/dist/helpers/guardModel.js +41 -0
  115. package/dist/helpers/guardModel.js.map +1 -0
  116. package/dist/helpers/manifest.d.ts +2 -1
  117. package/dist/helpers/manifest.js +16 -0
  118. package/dist/helpers/manifest.js.map +1 -1
  119. package/dist/helpers/mcpTools.d.ts +2 -1
  120. package/dist/helpers/mcpTools.js +8 -1
  121. package/dist/helpers/mcpTools.js.map +1 -1
  122. package/dist/helpers/modelcheck.d.ts +2 -1
  123. package/dist/helpers/modelcheck.js +13 -0
  124. package/dist/helpers/modelcheck.js.map +1 -1
  125. package/dist/helpers/opExample.d.ts +9 -2
  126. package/dist/helpers/opExample.js +22 -2
  127. package/dist/helpers/opExample.js.map +1 -1
  128. package/dist/helpers/opShape.d.ts +2 -1
  129. package/dist/helpers/opShape.js +29 -17
  130. package/dist/helpers/opShape.js.map +1 -1
  131. package/dist/helpers/packageMeta.d.ts +6 -4
  132. package/dist/helpers/packageMeta.js +88 -53
  133. package/dist/helpers/packageMeta.js.map +1 -1
  134. package/dist/helpers/placement.d.ts +15 -0
  135. package/dist/helpers/placement.js +76 -0
  136. package/dist/helpers/placement.js.map +1 -0
  137. package/dist/helpers/semver.d.ts +3 -1
  138. package/dist/helpers/semver.js +28 -0
  139. package/dist/helpers/semver.js.map +1 -1
  140. package/dist/helpers/serverVars.js +3 -2
  141. package/dist/helpers/serverVars.js.map +1 -1
  142. package/dist/helpers/shipped.d.ts +2 -1
  143. package/dist/helpers/shipped.js +12 -0
  144. package/dist/helpers/shipped.js.map +1 -1
  145. package/dist/helpers/sourcestring.d.ts +3 -0
  146. package/dist/helpers/sourcestring.js +43 -0
  147. package/dist/helpers/sourcestring.js.map +1 -0
  148. package/dist/helpers/stdrep.d.ts +1 -1
  149. package/dist/helpers/stdrep.js +5 -1
  150. package/dist/helpers/stdrep.js.map +1 -1
  151. package/dist/helpers/surface.d.ts +7 -0
  152. package/dist/helpers/surface.js +69 -0
  153. package/dist/helpers/surface.js.map +1 -0
  154. package/dist/helpers/targetguard.d.ts +13 -0
  155. package/dist/helpers/targetguard.js +65 -0
  156. package/dist/helpers/targetguard.js.map +1 -0
  157. package/dist/helpers/text.d.ts +3 -1
  158. package/dist/helpers/text.js +16 -0
  159. package/dist/helpers/text.js.map +1 -1
  160. package/dist/helpers/textguard.d.ts +31 -0
  161. package/dist/helpers/textguard.js +157 -0
  162. package/dist/helpers/textguard.js.map +1 -0
  163. package/dist/helpers/title.d.ts +4 -0
  164. package/dist/helpers/title.js +52 -0
  165. package/dist/helpers/title.js.map +1 -0
  166. package/dist/sdkgen.d.ts +4 -6
  167. package/dist/sdkgen.js +72 -63
  168. package/dist/sdkgen.js.map +1 -1
  169. package/dist/testkit.d.ts +7 -2
  170. package/dist/testkit.js +27 -20
  171. package/dist/testkit.js.map +1 -1
  172. package/dist/tsconfig.tsbuildinfo +1 -1
  173. package/dist/utility.js +2 -1
  174. package/dist/utility.js.map +1 -1
  175. package/model/fact.aontu +150 -0
  176. package/model/sdkgen.aontu +15 -3
  177. package/package.json +3 -1
  178. package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +2 -2
  179. package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +1 -1
  180. package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +12 -3
  181. package/project/.sdk/src/cmp/clojure/ReadmeQuick_clojure.ts +1 -1
  182. package/project/.sdk/src/cmp/cpp/ReadmeQuick_cpp.ts +1 -1
  183. package/project/.sdk/src/cmp/csharp/ReadmeQuick_csharp.ts +1 -1
  184. package/project/.sdk/src/cmp/elixir/ReadmeQuick_elixir.ts +1 -1
  185. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
  186. package/project/.sdk/src/cmp/java/ReadmeQuick_java.ts +1 -1
  187. package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +1 -1
  188. package/project/.sdk/src/cmp/kotlin/ReadmeQuick_kotlin.ts +1 -1
  189. package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +1 -1
  190. package/project/.sdk/src/cmp/ocaml/ReadmeQuick_ocaml.ts +1 -1
  191. package/project/.sdk/src/cmp/perl/ReadmeQuick_perl.ts +1 -1
  192. package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +1 -1
  193. package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +1 -1
  194. package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +1 -1
  195. package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +1 -1
  196. package/project/.sdk/src/cmp/scala/ReadmeQuick_scala.ts +1 -1
  197. package/project/.sdk/src/cmp/scala/ReadmeRef_scala.ts +4 -1
  198. package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +2 -1
  199. package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +3 -0
  200. package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -1
  201. package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +1 -1
  202. package/project/.sdk/src/cmp/ts/TestDefinition_ts.ts +3 -1
  203. package/project/.sdk/src/cmp/zig/ReadmeOptions_zig.ts +1 -1
  204. package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +3 -3
  205. package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
  206. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +3 -1
  207. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +2 -1
  208. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +11 -2
  209. package/project/sdkgen-package.json +1 -1
  210. package/src/action/check.ts +99 -4
  211. package/src/action/copies.ts +2 -0
  212. package/src/action/doctor.ts +304 -15
  213. package/src/action/package.ts +11 -13
  214. package/src/action/remove.ts +20 -5
  215. package/src/action/resolve.ts +11 -4
  216. package/src/action/target.ts +66 -15
  217. package/src/admin/status.ts +25 -5
  218. package/src/cmp/AgentGuide.ts +52 -25
  219. package/src/cmp/AgentGuideContent.ts +75 -43
  220. package/src/cmp/AgentGuideFeature.ts +21 -10
  221. package/src/cmp/AgentGuideTop.ts +119 -49
  222. package/src/cmp/Changelog.ts +56 -5
  223. package/src/cmp/Deploy.ts +81 -40
  224. package/src/cmp/Entity.ts +1 -1
  225. package/src/cmp/ExternalTarget.ts +12 -6
  226. package/src/cmp/Feature.ts +13 -6
  227. package/src/cmp/FeatureDocs.ts +21 -40
  228. package/src/cmp/FeatureHook.ts +38 -1
  229. package/src/cmp/Main.ts +1 -1
  230. package/src/cmp/PublishWorkflow.ts +94 -60
  231. package/src/cmp/ReadmeErrors.ts +555 -25
  232. package/src/cmp/ReadmeExplanation.ts +316 -52
  233. package/src/cmp/ReadmeFeatures.ts +18 -8
  234. package/src/cmp/ReadmeIntro.ts +4 -3
  235. package/src/cmp/ReadmeModel.ts +2 -2
  236. package/src/cmp/ReadmeRefFeatures.ts +39 -27
  237. package/src/cmp/ReadmeStation.ts +13 -16
  238. package/src/cmp/ReadmeTop.ts +538 -397
  239. package/src/cmp/ReadmeUnions.ts +10 -2
  240. package/src/cmp/Registered.ts +1 -1
  241. package/src/cmp/Security.ts +35 -7
  242. package/src/cmp/Test.ts +1 -1
  243. package/src/helpers/alongside.ts +16 -19
  244. package/src/helpers/applicability.ts +44 -1
  245. package/src/helpers/component.ts +11 -1
  246. package/src/helpers/copymerge.ts +58 -10
  247. package/src/helpers/definitionPlan.ts +0 -1
  248. package/src/helpers/doccheck.ts +174 -0
  249. package/src/helpers/doctext.ts +115 -0
  250. package/src/helpers/exampleCall.ts +415 -0
  251. package/src/helpers/exportnames.ts +47 -0
  252. package/src/helpers/facts.ts +259 -5
  253. package/src/helpers/flowGuard.ts +22 -7
  254. package/src/helpers/generated.ts +3 -1
  255. package/src/helpers/graphqlPoint.ts +20 -1
  256. package/src/helpers/guardModel.ts +50 -0
  257. package/src/helpers/manifest.ts +19 -0
  258. package/src/helpers/mcpTools.ts +11 -1
  259. package/src/helpers/modelcheck.ts +16 -0
  260. package/src/helpers/opExample.ts +34 -2
  261. package/src/helpers/opShape.ts +29 -16
  262. package/src/helpers/packageMeta.ts +89 -52
  263. package/src/helpers/placement.ts +114 -0
  264. package/src/helpers/semver.ts +35 -0
  265. package/src/helpers/serverVars.ts +4 -2
  266. package/src/helpers/shipped.ts +13 -0
  267. package/src/helpers/sourcestring.ts +47 -0
  268. package/src/helpers/stdrep.ts +6 -1
  269. package/src/helpers/surface.ts +82 -0
  270. package/src/helpers/targetguard.ts +91 -0
  271. package/src/helpers/text.ts +22 -0
  272. package/src/helpers/textguard.ts +208 -0
  273. package/src/helpers/title.ts +59 -0
  274. package/src/sdkgen.ts +82 -78
  275. package/src/testkit.ts +42 -20
  276. 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
+ }
@@ -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
+ }