@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
@@ -1,13 +1,22 @@
1
1
  import { readFileSync } from 'node:fs'
2
2
 
3
3
  import { Aontu } from 'aontu'
4
+ import { names } from 'jostraca'
4
5
  import { KIT } from '@voxgig/apidef'
5
6
 
7
+ import { docTexts, sentinelName } from './doctext'
6
8
  import { factRulesFile } from './shipped'
9
+ import { CANON_OP_ORDER } from './opShape'
10
+ import { hasPackageName, packageName, registryState } from './packageMeta'
11
+ import { SdkGenError } from '../utility'
12
+ import { resolvesBundled } from '../action/resolve'
13
+ import { titleFacts } from './title'
14
+ import { definitionKind } from './graphqlPoint'
7
15
 
8
16
 
9
- // No fact rule reads these, and they are most of a large model.
10
- const UNREAD = ['entity', 'flow']
17
+ // No fact rule reads these, and they are most of a large model. A model's
18
+ // facts are left out too: the rules compute every one afresh.
19
+ const UNREAD = ['entity', 'flow', 'fact']
11
20
 
12
21
 
13
22
  function isMap(v: any): boolean {
@@ -18,7 +27,9 @@ function isMap(v: any): boolean {
18
27
  function copyFacts(from: any, to: any): void {
19
28
  for (const [key, val] of Object.entries(from)) {
20
29
  if ('fact' === key) {
21
- to.fact = val
30
+ if (isMap(val) && 0 < Object.keys(val as object).length) {
31
+ to.fact = val
32
+ }
22
33
  }
23
34
  else if (isMap(val) && isMap(to[key])) {
24
35
  copyFacts(val, to[key])
@@ -41,10 +52,26 @@ function applyFacts(model: any): any {
41
52
  input[key] = val
42
53
  }
43
54
  }
55
+ if (isMap(kit.target)) {
56
+ input.target = ruleTargets(kit.target)
57
+ }
58
+ if (isMap(kit.feature)) {
59
+ input.feature = withoutFacts(kit.feature)
60
+ }
61
+ input.config = { ...(isMap(kit.config) ? kit.config : {}), auth: mapOr(kit.config?.auth) }
62
+ input.info = { ...(isMap(kit.info) ? kit.info : {}), security: mapOr(kit.info?.security) }
63
+
64
+ const server = ruleServer(kit.info)
65
+ const entity = Object.fromEntries(Object.keys(mapOr(kit.entity)).map((name) => [name, {}]))
66
+
67
+ const texts = docTexts(model)
68
+ const escape = Object.fromEntries(texts.map((t, i) => ['t' + i, { raw: t.raw, vendor: t.vendor }]))
44
69
 
45
70
  const path = factRulesFile()
46
- const src = JSON.stringify({ main: { [KIT]: input } }).slice(1, -1) +
47
- '\n' + readFileSync(path, 'utf8')
71
+ const src = JSON.stringify({
72
+ name: 'string' === typeof model.name ? model.name : '',
73
+ main: { [KIT]: input }, server: server.rule, entity, escape,
74
+ }).slice(1, -1) + '\n' + readFileSync(path, 'utf8')
48
75
 
49
76
  const errs: any[] = []
50
77
  const out = new Aontu().generate(src, { path, errs })
@@ -54,10 +81,209 @@ function applyFacts(model: any): any {
54
81
  }
55
82
 
56
83
  copyFacts(out.main[KIT], kit)
84
+ linkConsumers(kit.target, out.main[KIT].target)
85
+ kit.fact = isMap(kit.fact) ? kit.fact : {}
86
+ kit.fact.active = activeNames(kit.target)
87
+ serverFacts(kit.fact, server, out.server.variables)
88
+ kit.fact.env.entid = Object.fromEntries(Object.keys(entity).map((name) =>
89
+ [name, out.entity[name].fact.entid]))
90
+ kit.fact.ops = entityOps(kit.entity)
91
+ kit.fact.package = projectPackages(model)
92
+ kit.fact.option = optionRows(kit.optspec)
93
+ releaseTags(model)
94
+ texts.forEach((t, i) => place(t.at, t.path, out.escape['t' + i]))
95
+ titleFacts(kit.target)
96
+ place(kit, ['definitionKind'], definitionKind(model))
57
97
  return model
58
98
  }
59
99
 
60
100
 
101
+ function mapOr(value: any): any {
102
+ return isMap(value) ? value : {}
103
+ }
104
+
105
+
106
+ function withoutFacts(items: any): any {
107
+ return Object.fromEntries(Object.entries(items).map(([name, item]: [string, any]) =>
108
+ [name, isMap(item) ? { ...item, fact: undefined } : item]))
109
+ }
110
+
111
+
112
+ // The URL's variables in the order serverVariables gives them: as the URL names
113
+ // them, then the declared ones it does not. A variable the URL names but the
114
+ // spec omits is declared here, empty, so the rules decide it with the rest.
115
+ const SERVER_VAR_RE = /\{([A-Za-z0-9_]+)\}/g
116
+
117
+ function ruleServer(info: any): { rule: any, order: string[], declared: any } {
118
+ const server = info?.servers?.[0]
119
+ const url: string = 'string' === typeof server?.url ? server.url : ''
120
+ const declared = mapOr(server?.variables)
121
+
122
+ const order = [...new Set([...url.matchAll(SERVER_VAR_RE)].map((m) => m[1]))]
123
+ order.push(...Object.keys(declared).filter((name) => !order.includes(name)))
124
+
125
+ const variables = Object.fromEntries(order.map((name) => {
126
+ const decl = mapOr(declared[name])
127
+ return [name, { default: 'string' === typeof decl.default ? decl.default : '' }]
128
+ }))
129
+ return { rule: { url, variables }, order, declared }
130
+ }
131
+
132
+
133
+ // aontu lists no map's keys, so the variables the rules decided are listed here.
134
+ function serverFacts(facts: any, server: any, decided: any): void {
135
+ facts.server = server.order.map((name: string) => {
136
+ const decl = mapOr(server.declared[name])
137
+ return {
138
+ name,
139
+ dflt: server.rule.variables[name].default,
140
+ required: decided[name].fact.required,
141
+ description: 'string' === typeof decl.description ? decl.description : '',
142
+ }
143
+ })
144
+ facts.env.server = Object.fromEntries(server.order.map((name: string) =>
145
+ [name, decided[name].fact.env]))
146
+ }
147
+
148
+
149
+ // Each entity's canonical operations, in canonical order: the list aontu
150
+ // cannot build from a map. An action-only operation counts. They sit outside
151
+ // the entities, which some tests print whole into generated source.
152
+ function entityOps(entity: any): Record<string, string[]> {
153
+ return Object.fromEntries(Object.entries(mapOr(entity))
154
+ .filter(([, ent]) => isMap(ent))
155
+ .map(([name, ent]: [string, any]) => [name, CANON_OP_ORDER.filter((op: string) =>
156
+ isMap(ent.op?.[op]) && false !== ent.op[op].active)]))
157
+ }
158
+
159
+
160
+ // The JVM package of java, kotlin and scala, and the Python package py and
161
+ // py-data import. py's is jostraca's Name for the project, lower-cased, as the
162
+ // Root names it; aontu's nom splits words differently.
163
+ function projectPackages(model: any): { jvm: string, py: string } {
164
+ const word = (s: any) => String(s ?? '').replace(/[^a-zA-Z0-9]/g, '').toLowerCase()
165
+ const project: any = {}
166
+ names(project, String(model.name ?? ''))
167
+ return {
168
+ jvm: word(String(model.origin || 'voxgig-sdk').replace(/-sdk$/, '')) + '.' + word(model.name) + 'sdk',
169
+ py: String(project.Name ?? '').toLowerCase() + '_sdk',
170
+ }
171
+ }
172
+
173
+
174
+ // One row per client option, in the order main.kit.optspec declares them.
175
+ function optionRows(optspec: any): { name: string, type: string }[] {
176
+ return Object.entries(mapOr(optspec)).map(([name, spec]) => ({ name, type: optionType(spec) }))
177
+ }
178
+
179
+
180
+ function optionType(spec: any): string {
181
+ if (isMap(spec)) {
182
+ return 'object'
183
+ }
184
+ if ('string' === typeof spec && spec.startsWith('`$')) {
185
+ return sentinelName(spec)
186
+ }
187
+ return typeof spec
188
+ }
189
+
190
+
191
+ // The tag before a version: `<prefix>/v`, else `v` for the tree's one npm
192
+ // package or the ts SDK's, else `<target>/v`, and empty when switched off.
193
+ // Only code compares package names, so this is the pass's, not a rule's.
194
+ function releaseTags(model: any): void {
195
+ const kit = model.main[KIT]
196
+ const target = mapOr(kit.target)
197
+ const npm = kit.fact.active.filter((name: string) => isMap(target[name]?.fact) &&
198
+ 'external' !== target[name].fact.place &&
199
+ 'npm' === (target[name].publish?.registry?.name || '') && hasPackageName(model, name) &&
200
+ 'inactive' !== registryState(model, name))
201
+ // A model with no name, built by hand, has no package names to compare.
202
+ const primary = (name: string) => npm.includes(name) && (1 === npm.length ||
203
+ (null != model.name && packageName(model, name) === packageName(model, 'npm')))
204
+
205
+ for (const name of Object.keys(target)) {
206
+ if (isMap(target[name]?.fact)) {
207
+ const tag = mapOr(target[name].publish?.tag)
208
+ const prefix = 'string' === typeof tag.prefix ? tag.prefix : ''
209
+ target[name].fact.tag = false === tag.active ? '' :
210
+ '' !== prefix ? prefix + '/v' : primary(name) ? 'v' : name + '/v'
211
+ }
212
+ }
213
+ }
214
+
215
+
216
+ // aontu lists no map's keys, so the active targets are named here.
217
+ function activeNames(target: any): string[] {
218
+ return !isMap(target) ? [] : Object.keys(target).sort()
219
+ .filter((name: string) => isMap(target[name]) && false !== target[name].active)
220
+ }
221
+
222
+
223
+ // A hand-built model may lack the slots the rules read, and only code can say
224
+ // whether a target's provenance leads to the bundled scaffold.
225
+ function ruleTargets(target: any): any {
226
+ const out: any = {}
227
+ for (const [name, decl] of Object.entries(withoutFacts(target)) as [string, any][]) {
228
+ out[name] = !isMap(decl) ? decl : {
229
+ ...decl,
230
+ name: null == decl.name ? name : decl.name,
231
+ origname: null == decl.origname ? '' : decl.origname,
232
+ surface: null == decl.surface ? '' : decl.surface,
233
+ consumes: null == decl.consumes ? '' : decl.consumes,
234
+ scaffold: resolvesBundled(decl, name),
235
+ }
236
+ }
237
+ return out
238
+ }
239
+
240
+
241
+ // The rules name the origin a target builds on; only the installed keys can
242
+ // say which target that is, and which targets build on each one.
243
+ function linkConsumers(target: any, derived: any): void {
244
+ if (!isMap(target) || !isMap(derived)) {
245
+ return
246
+ }
247
+
248
+ const names = Object.keys(target).sort().filter((name: string) => isMap(target[name]?.fact))
249
+ for (const name of names) {
250
+ target[name].fact.consumes = consumed(target, name, derived[name]?.derive?.wraps)
251
+ }
252
+ for (const name of names) {
253
+ target[name].fact.consumers = names.filter((other: string) =>
254
+ false !== target[other].active && name === target[other].fact.consumes)
255
+ }
256
+ }
257
+
258
+
259
+ function consumed(target: any, name: string, wraps: any): string {
260
+ if ('string' !== typeof wraps || '' === wraps) {
261
+ return ''
262
+ }
263
+ if (isMap(target[wraps])) {
264
+ return wraps
265
+ }
266
+
267
+ const found = Object.keys(target).sort().filter((other: string) =>
268
+ other !== name && wraps === target[other]?.fact?.origin)
269
+ if (1 < found.length) {
270
+ throw new SdkGenError('Target "' + name + '" builds on ' + wraps + ', and ' +
271
+ found.length + ' installed targets come from it: ' + found.join(', ') +
272
+ '. Name one in its own model, as `consumes: \'<target>\'`.')
273
+ }
274
+ return found[0] ?? ''
275
+ }
276
+
277
+
278
+ function place(at: any, path: string[], forms: any): void {
279
+ let node = at.fact = isMap(at.fact) ? at.fact : {}
280
+ for (const key of path.slice(0, -1)) {
281
+ node = node[key] = isMap(node[key]) ? node[key] : {}
282
+ }
283
+ node[path[path.length - 1]] = forms
284
+ }
285
+
286
+
61
287
  function fact(node: any, name: string): any {
62
288
  const facts = node?.fact
63
289
  if (!isMap(facts) || !(name in facts)) {
@@ -68,7 +294,35 @@ function fact(node: any, name: string): any {
68
294
  }
69
295
 
70
296
 
297
+ // A plan no Root can write: several targets claiming the project root, or a
298
+ // target there beside the root documents, which would overwrite its own.
299
+ // `external` names the targets this run writes elsewhere; a target with no
300
+ // `output` claims no place at all.
301
+ function refuseRootPlan(model: any, external: string[] = []): void {
302
+ const kit = model.main[KIT]
303
+ const target = kit.target || {}
304
+ const atRoot = Object.keys(target).sort().filter((name: string) =>
305
+ !external.includes(name) && false !== target[name].active &&
306
+ null != target[name].output && 'root' === fact(target[name], 'place'))
307
+
308
+ if (1 < atRoot.length) {
309
+ throw new SdkGenError(
310
+ 'Only one target can be generated at the project root, and ' +
311
+ atRoot.length + ' declare `output: root: true`: ' + atRoot.join(', ') + '.')
312
+ }
313
+
314
+ if (1 === atRoot.length && fact(kit, 'top')) {
315
+ throw new SdkGenError(
316
+ 'Target "' + atRoot[0] + '" is generated at the project root, where the ' +
317
+ 'SDK repository files (README, LICENSE, Makefile, workflows) would ' +
318
+ 'overwrite its own. Declare `main: kit: phase: top: active: false` in ' +
319
+ 'model/project.aontu.')
320
+ }
321
+ }
322
+
323
+
71
324
  export {
72
325
  applyFacts,
73
326
  fact,
327
+ refuseRootPlan,
74
328
  }
@@ -22,7 +22,7 @@ const GENERATED = ['create', 'list', 'load', 'update', 'remove']
22
22
  // the record's id where the op acts on one, and what the entity instance
23
23
  // holds. A step whose op is absent, or whose call reaches no route, is
24
24
  // switched off and marked unreachable for the live harness to resolve.
25
- function guardFlowSteps(model: any, log?: any): Unreachable[] {
25
+ function guardFlowSteps(model: any, log?: any, dropped?: Set<string>): Unreachable[] {
26
26
  const kit = model?.main?.[KIT]
27
27
  const flows = kit?.flow
28
28
  const entities = kit?.entity
@@ -89,20 +89,35 @@ function guardFlowSteps(model: any, log?: any): Unreachable[] {
89
89
  })
90
90
  }
91
91
 
92
- if (0 < ungenerated.length && log?.warn) {
92
+ // A step on an operation the project switched off is no surprise.
93
+ const off = (s: Unreachable) => true === dropped?.has(flows[s.flow].entity + '.' + s.op)
94
+ const switchedOff = [...ungenerated, ...out].filter(off)
95
+ const ungen = ungenerated.filter((s) => !off(s))
96
+ const unreached = out.filter((s) => !off(s))
97
+
98
+ if (0 < switchedOff.length && log?.info) {
99
+ log.info({
100
+ point: 'flow-step-dropped',
101
+ steps: switchedOff.map((s) => s.flow + '.' + s.step + ':' + s.op),
102
+ note: 'flow step(s) ' + switchedOff.map((s) => s.flow + '#' + s.step + ' (' + s.op + ')').join(', ') +
103
+ ' switched off: the model switches their operation off.',
104
+ })
105
+ }
106
+
107
+ if (0 < ungen.length && log?.warn) {
93
108
  log.warn({
94
109
  point: 'flow-step-ungenerated',
95
- steps: ungenerated.map((s) => s.flow + '.' + s.step + ':' + s.op),
96
- note: 'flow step(s) ' + ungenerated.map((s) => s.flow + '#' + s.step + ' (' + s.op + ')').join(', ') +
110
+ steps: ungen.map((s) => s.flow + '.' + s.step + ':' + s.op),
111
+ note: 'flow step(s) ' + ungen.map((s) => s.flow + '#' + s.step + ' (' + s.op + ')').join(', ') +
97
112
  ' switched off: a generated flow test calls ' + GENERATED.join(', ') + ' and no other operation.',
98
113
  })
99
114
  }
100
115
 
101
- if (0 < out.length && log?.warn) {
116
+ if (0 < unreached.length && log?.warn) {
102
117
  log.warn({
103
118
  point: 'flow-step-unreachable',
104
- steps: out.map((s) => s.flow + '.' + s.step + ':' + s.op),
105
- note: 'flow step(s) ' + out.map((s) => s.flow + '#' + s.step + ' (' + s.op + ')').join(', ') +
119
+ steps: unreached.map((s) => s.flow + '.' + s.step + ':' + s.op),
120
+ note: 'flow step(s) ' + unreached.map((s) => s.flow + '#' + s.step + ' (' + s.op + ')').join(', ') +
106
121
  ' switched off: the entity has no such operation, the call they make reaches no route of it, ' +
107
122
  'or they check a removal such a step was to make. ' +
108
123
  'Every route needs an action, or a path parameter the step does not give.',
@@ -49,6 +49,8 @@ type PruneContext = {
49
49
  jres: any
50
50
  claims?: Claims
51
51
  dryrun: boolean
52
+ // Path prefixes never pruned: a relocated target's in-tree output.
53
+ keep?: string[]
52
54
  }
53
55
 
54
56
 
@@ -406,7 +408,7 @@ function pruneGenerated(ctx: PruneContext): string[] {
406
408
 
407
409
  for (const [rel, owner] of known ?? []) {
408
410
  if (emitted.has(rel) || seen.has(rel) || declared.has(rel) || injected.has(rel) ||
409
- canonical(out, rel) !== rel) {
411
+ canonical(out, rel) !== rel || true === ctx.keep?.some((prefix: string) => rel.startsWith(prefix))) {
410
412
  continue
411
413
  }
412
414
 
@@ -1,5 +1,5 @@
1
1
  import { snakify } from 'jostraca'
2
- import { depluralize } from '@voxgig/apidef'
2
+ import { KIT, depluralize } from '@voxgig/apidef'
3
3
 
4
4
 
5
5
  function pointIsGraphql(point: any): boolean {
@@ -7,6 +7,24 @@ function pointIsGraphql(point: any): boolean {
7
7
  }
8
8
 
9
9
 
10
+ // What the model was built from, as its active entities' points agree: '' when
11
+ // they do not, or there are none.
12
+ function definitionKind(model: any): string {
13
+ const kinds = new Set<string>()
14
+ for (const ent of Object.values(model?.main?.[KIT]?.entity || {}) as any[]) {
15
+ if (false === ent?.active) {
16
+ continue
17
+ }
18
+ for (const op of Object.values(ent?.op || {}) as any[]) {
19
+ for (const point of Object.values(op?.points || {})) {
20
+ kinds.add(pointIsGraphql(point) ? 'graphql' : 'openapi')
21
+ }
22
+ }
23
+ }
24
+ return 1 === kinds.size ? [...kinds][0] : ''
25
+ }
26
+
27
+
10
28
  // A list's own field is the entity's plural (`teams`), any other op's the singular.
11
29
  function ownField(point: any, entityName: string, opname: string): boolean {
12
30
  const field = point?.gq?.field
@@ -83,6 +101,7 @@ function graphqlDirectSkip(opname: string, entityName: string): string {
83
101
 
84
102
 
85
103
  export {
104
+ definitionKind,
86
105
  pointIsGraphql,
87
106
  pointGraphql,
88
107
  ownPointFirst,
@@ -0,0 +1,50 @@
1
+ /* Copyright (c) 2024-2026 Voxgig Ltd, MIT License */
2
+
3
+
4
+ import { KIT } from '@voxgig/apidef'
5
+
6
+ import { guardModelNames } from './modelNames'
7
+ import { guardFlowSteps } from './flowGuard'
8
+
9
+
10
+ // The changes made to a model before any fact is computed over it. It is
11
+ // idempotent, so docgen may apply it to a model generate already prepared.
12
+ function guardModel(model: any, log?: any): any {
13
+ guardModelNames(model, log)
14
+ const dropped = dropInactiveOps(model)
15
+ guardFlowSteps(model, log, dropped)
16
+ return model
17
+ }
18
+
19
+
20
+ // An inactive operation is an absent one: every reader then agrees on it. An
21
+ // active one keeps no flag, so the model reads as it did before the slot.
22
+ function dropInactiveOps(model: any): Set<string> {
23
+ const dropped = new Set<string>()
24
+ const entity = model?.main?.[KIT]?.entity
25
+ if (null == entity || 'object' !== typeof entity) {
26
+ return dropped
27
+ }
28
+
29
+ for (const [name, ent] of Object.entries(entity) as [string, any][]) {
30
+ const op = ent?.op
31
+ if (null == op || 'object' !== typeof op) {
32
+ continue
33
+ }
34
+ for (const opname of Object.keys(op)) {
35
+ if (false === op[opname]?.active) {
36
+ delete op[opname]
37
+ dropped.add(name + '.' + opname)
38
+ }
39
+ else if (null != op[opname] && 'object' === typeof op[opname]) {
40
+ delete op[opname].active
41
+ }
42
+ }
43
+ }
44
+ return dropped
45
+ }
46
+
47
+
48
+ export {
49
+ guardModel,
50
+ }
@@ -373,10 +373,29 @@ export type {
373
373
  Finding,
374
374
  }
375
375
 
376
+ // A target is graded CONSUMER exactly when its surface is not `sdk`: the
377
+ // corpus tiers grade an SDK, and nothing else runs the corpus.
378
+ function parityFinding(file: string, name: string, tier: string, surface: string): Finding[] {
379
+ if (!PARITY.includes(tier) || ('CONSUMER' === tier) === ('sdk' !== surface)) {
380
+ return []
381
+ }
382
+
383
+ const what = '' === surface ? 'a surface the model does not say' : 'surface `' + surface + '`'
384
+ return [{
385
+ level: 'error', point: 'manifest-parity-surface', file, kind: 'target', name,
386
+ note: file + ': `parity.' + name + '` is ' + tier + ', and the target has ' + what +
387
+ ' — ' + ('CONSUMER' === tier ?
388
+ 'CONSUMER grades a target that is not an SDK; grade an SDK FULL, MIRRORED or UNCOVERED' :
389
+ 'a target that is not an SDK runs no corpus, so it is graded CONSUMER'),
390
+ }]
391
+ }
392
+
393
+
376
394
  export {
377
395
  MANIFEST,
378
396
  SCHEMA,
379
397
  PARITY,
398
+ parityFinding,
380
399
  ITEM_NAME_RE,
381
400
  manifestPath,
382
401
  probePackage,
@@ -4,6 +4,7 @@ import { KIT, getModelPath } from '@voxgig/apidef'
4
4
  import type { ModelEntity, SdkModel } from '../types'
5
5
 
6
6
  import { entityOps } from './opShape'
7
+ import { surfaceOf } from './surface'
7
8
 
8
9
 
9
10
  type McpTool = {
@@ -20,7 +21,7 @@ const MCP_WRITE_OPS = ['create', 'update', 'patch', 'remove']
20
21
  // The tools the go-mcp server registers, each for the entities a plain call of
21
22
  // its operation runs on, in name order. A tool no entity can serve is left
22
23
  // out. The write tools need the target's `tool.write`.
23
- function mcpTools(model: SdkModel, target: string = 'go-mcp'): McpTool[] {
24
+ function mcpTools(model: SdkModel, target: string = mcpTarget(model)): McpTool[] {
24
25
  const write = true === model.main?.[KIT]?.target?.[target]?.tool?.write
25
26
  const slug = String(model.name ?? '').toLowerCase()
26
27
  const entities: ModelEntity[] = each(getModelPath(model, `main.${KIT}.entity`) || {})
@@ -36,12 +37,21 @@ function mcpTools(model: SdkModel, target: string = 'go-mcp'): McpTool[] {
36
37
  }
37
38
 
38
39
 
40
+ // The installed name of the MCP server, which an alias or a package can change.
41
+ function mcpTarget(model: SdkModel): string {
42
+ const targets: any = model.main?.[KIT]?.target || {}
43
+ return Object.keys(targets).sort().find((name: string) =>
44
+ false !== targets[name]?.active && 'mcp' === surfaceOf(targets[name])) ?? 'go-mcp'
45
+ }
46
+
47
+
39
48
  export type {
40
49
  McpTool,
41
50
  }
42
51
 
43
52
  export {
44
53
  mcpTools,
54
+ mcpTarget,
45
55
  MCP_READ_OPS,
46
56
  MCP_WRITE_OPS,
47
57
  }
@@ -1,6 +1,7 @@
1
1
 
2
2
  import { Aontu } from 'aontu'
3
3
  import { createRequire } from 'node:module'
4
+ import Fs from 'node:fs'
4
5
  import Path from 'node:path'
5
6
 
6
7
  import { schemaFile } from './shipped'
@@ -159,6 +160,20 @@ function publishOverrideProbe(
159
160
  }
160
161
 
161
162
 
163
+ // A feature hook the schema does not list still unifies, through `hook: &:`,
164
+ // so a misspelled one is caught only by comparing against this list.
165
+ let schemaHookNames: string[] | null = null
166
+
167
+ function schemaHooks(): string[] {
168
+ if (null == schemaHookNames) {
169
+ const probe = compileModel(Fs.readFileSync(schemaFile(), 'utf8') +
170
+ "\nmain: kit: feature: 'hook$': title: ''\n", schemaFile(), { strict: false })
171
+ schemaHookNames = Object.keys(probe.model?.main?.kit?.feature?.['hook$']?.hook ?? {}).sort()
172
+ }
173
+ return schemaHookNames
174
+ }
175
+
176
+
162
177
  export type {
163
178
  CompileResult,
164
179
  }
@@ -171,6 +186,7 @@ export {
171
186
  compileModel,
172
187
  includeLine,
173
188
  publishOverrideProbe,
189
+ schemaHooks,
174
190
  slashComments,
175
191
  strictAontu,
176
192
  unquoted,
@@ -186,7 +186,7 @@ function seededList(lang: LiteralLang, ent: any, idF: string | null, key: string
186
186
 
187
187
 
188
188
  // An update or patch addressed only by id and route also changes a field.
189
- function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): string {
189
+ function dataItems(ent: any, op: string, idF: string | null): any[] {
190
190
  const routed = new Set(opParams(ent?.op?.[op]).map((p: any) => p.n))
191
191
  const addresses = (it: any) => it.name === idF || it.name === 'id' || routed.has(it.name)
192
192
  const items = requestExampleItems(ent, op)
@@ -195,7 +195,12 @@ function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): s
195
195
  const required = items.filter((it: any) => !it.optional)
196
196
  const changed = ('update' === op || 'patch' === op) && required.every(addresses) ?
197
197
  items.filter((it: any) => it.optional && !addresses(it)).slice(0, 1) : []
198
- const chosen = required.length ? [...required, ...changed] : items.slice(0, 3)
198
+ return required.length ? [...required, ...changed] : items.slice(0, 3)
199
+ }
200
+
201
+
202
+ function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): string {
203
+ const chosen = dataItems(ent, op, idF)
199
204
  const pairs = chosen.map((it: any) => litPair(lang, it.name, litFor(lang, it.type)))
200
205
  switch (lang) {
201
206
  case 'php': return `[${pairs.join(', ')}]`
@@ -206,6 +211,30 @@ function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): s
206
211
  }
207
212
 
208
213
 
214
+ type ArgItem = {
215
+ name: string
216
+ type: any
217
+ id: boolean
218
+ }
219
+
220
+
221
+ // The members a primary-op example sends: those matchArg, listMatchArg and
222
+ // dataArg write, each marked when it carries the entity's id.
223
+ function exampleArgItems(ent: any, op: string, idF: string | null): ArgItem[] {
224
+ const item = (it: any, id: boolean) => ({ name: it.name, type: it.type, id })
225
+ if ('list' === op) {
226
+ return requiredItems(ent, 'list').map((it: any) => item(it, false))
227
+ }
228
+ if ('load' === op || 'remove' === op) {
229
+ return requiredItems(ent, op).map((it: any) => item(it, it.name === idF))
230
+ }
231
+ if ('create' === op || 'update' === op || 'patch' === op) {
232
+ return dataItems(ent, op, idF).map((it: any) => item(it, false))
233
+ }
234
+ return []
235
+ }
236
+
237
+
209
238
  type PrimaryCall = {
210
239
  expr: string
211
240
  resultVar: string
@@ -275,6 +304,8 @@ export {
275
304
  listMatchArg,
276
305
  seededList,
277
306
  dataArg,
307
+ dataItems,
308
+ exampleArgItems,
278
309
  javaMap,
279
310
  javaMapOf,
280
311
  javaMapItems,
@@ -284,6 +315,7 @@ export {
284
315
  }
285
316
 
286
317
  export type {
318
+ ArgItem,
287
319
  ExampleLang,
288
320
  LiteralLang,
289
321
  PrimaryCall,