@voxgig/sdkgen 4.46.0 → 4.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/check.js +58 -4
  3. package/dist/action/check.js.map +1 -1
  4. package/dist/action/doctor.d.ts +5 -0
  5. package/dist/action/doctor.js +44 -4
  6. package/dist/action/doctor.js.map +1 -1
  7. package/dist/action/package.d.ts +1 -1
  8. package/dist/action/package.js +6 -16
  9. package/dist/action/package.js.map +1 -1
  10. package/dist/action/remove.js +15 -4
  11. package/dist/action/remove.js.map +1 -1
  12. package/dist/action/resolve.d.ts +1 -0
  13. package/dist/action/resolve.js +10 -4
  14. package/dist/action/resolve.js.map +1 -1
  15. package/dist/admin/status.d.ts +7 -1
  16. package/dist/admin/status.js +34 -5
  17. package/dist/admin/status.js.map +1 -1
  18. package/dist/cmp/AgentGuide.js +27 -15
  19. package/dist/cmp/AgentGuide.js.map +1 -1
  20. package/dist/cmp/AgentGuideContent.d.ts +3 -3
  21. package/dist/cmp/AgentGuideContent.js +22 -11
  22. package/dist/cmp/AgentGuideContent.js.map +1 -1
  23. package/dist/cmp/AgentGuideFeature.js +14 -6
  24. package/dist/cmp/AgentGuideFeature.js.map +1 -1
  25. package/dist/cmp/AgentGuideTop.js +16 -8
  26. package/dist/cmp/AgentGuideTop.js.map +1 -1
  27. package/dist/cmp/Changelog.js +37 -7
  28. package/dist/cmp/Changelog.js.map +1 -1
  29. package/dist/cmp/Deploy.js +52 -16
  30. package/dist/cmp/Deploy.js.map +1 -1
  31. package/dist/cmp/Entity.js +1 -1
  32. package/dist/cmp/Entity.js.map +1 -1
  33. package/dist/cmp/ExternalTarget.js +5 -0
  34. package/dist/cmp/ExternalTarget.js.map +1 -1
  35. package/dist/cmp/Feature.js +2 -2
  36. package/dist/cmp/Feature.js.map +1 -1
  37. package/dist/cmp/Main.js +1 -1
  38. package/dist/cmp/Main.js.map +1 -1
  39. package/dist/cmp/PublishWorkflow.js +63 -53
  40. package/dist/cmp/PublishWorkflow.js.map +1 -1
  41. package/dist/cmp/ReadmeIntro.js +1 -1
  42. package/dist/cmp/ReadmeIntro.js.map +1 -1
  43. package/dist/cmp/ReadmeModel.js +2 -2
  44. package/dist/cmp/ReadmeModel.js.map +1 -1
  45. package/dist/cmp/ReadmeStation.js +3 -3
  46. package/dist/cmp/ReadmeStation.js.map +1 -1
  47. package/dist/cmp/ReadmeTop.js +57 -59
  48. package/dist/cmp/ReadmeTop.js.map +1 -1
  49. package/dist/cmp/Registered.js +1 -1
  50. package/dist/cmp/Registered.js.map +1 -1
  51. package/dist/cmp/Security.js +23 -3
  52. package/dist/cmp/Security.js.map +1 -1
  53. package/dist/cmp/Test.js +1 -1
  54. package/dist/cmp/Test.js.map +1 -1
  55. package/dist/helpers/alongside.d.ts +2 -3
  56. package/dist/helpers/alongside.js +16 -15
  57. package/dist/helpers/alongside.js.map +1 -1
  58. package/dist/helpers/applicability.d.ts +2 -1
  59. package/dist/helpers/applicability.js +14 -1
  60. package/dist/helpers/applicability.js.map +1 -1
  61. package/dist/helpers/component.js +9 -1
  62. package/dist/helpers/component.js.map +1 -1
  63. package/dist/helpers/definitionPlan.js +0 -1
  64. package/dist/helpers/definitionPlan.js.map +1 -1
  65. package/dist/helpers/doctext.js +1 -0
  66. package/dist/helpers/doctext.js.map +1 -1
  67. package/dist/helpers/facts.js +174 -4
  68. package/dist/helpers/facts.js.map +1 -1
  69. package/dist/helpers/flowGuard.d.ts +1 -1
  70. package/dist/helpers/flowGuard.js +20 -7
  71. package/dist/helpers/flowGuard.js.map +1 -1
  72. package/dist/helpers/generated.d.ts +1 -0
  73. package/dist/helpers/generated.js +1 -1
  74. package/dist/helpers/generated.js.map +1 -1
  75. package/dist/helpers/graphqlPoint.d.ts +2 -1
  76. package/dist/helpers/graphqlPoint.js +17 -0
  77. package/dist/helpers/graphqlPoint.js.map +1 -1
  78. package/dist/helpers/guardModel.d.ts +2 -0
  79. package/dist/helpers/guardModel.js +41 -0
  80. package/dist/helpers/guardModel.js.map +1 -0
  81. package/dist/helpers/manifest.d.ts +2 -1
  82. package/dist/helpers/manifest.js +16 -0
  83. package/dist/helpers/manifest.js.map +1 -1
  84. package/dist/helpers/mcpTools.d.ts +2 -1
  85. package/dist/helpers/mcpTools.js +8 -1
  86. package/dist/helpers/mcpTools.js.map +1 -1
  87. package/dist/helpers/opShape.js +17 -17
  88. package/dist/helpers/opShape.js.map +1 -1
  89. package/dist/helpers/packageMeta.d.ts +6 -4
  90. package/dist/helpers/packageMeta.js +68 -46
  91. package/dist/helpers/packageMeta.js.map +1 -1
  92. package/dist/helpers/placement.d.ts +15 -0
  93. package/dist/helpers/placement.js +76 -0
  94. package/dist/helpers/placement.js.map +1 -0
  95. package/dist/helpers/semver.d.ts +2 -1
  96. package/dist/helpers/semver.js +21 -0
  97. package/dist/helpers/semver.js.map +1 -1
  98. package/dist/helpers/serverVars.js +3 -2
  99. package/dist/helpers/serverVars.js.map +1 -1
  100. package/dist/helpers/shipped.d.ts +2 -1
  101. package/dist/helpers/shipped.js +12 -0
  102. package/dist/helpers/shipped.js.map +1 -1
  103. package/dist/helpers/sourcestring.d.ts +3 -0
  104. package/dist/helpers/sourcestring.js +43 -0
  105. package/dist/helpers/sourcestring.js.map +1 -0
  106. package/dist/helpers/stdrep.d.ts +1 -1
  107. package/dist/helpers/stdrep.js +5 -1
  108. package/dist/helpers/stdrep.js.map +1 -1
  109. package/dist/helpers/surface.d.ts +7 -0
  110. package/dist/helpers/surface.js +69 -0
  111. package/dist/helpers/surface.js.map +1 -0
  112. package/dist/helpers/targetguard.d.ts +13 -0
  113. package/dist/helpers/targetguard.js +65 -0
  114. package/dist/helpers/targetguard.js.map +1 -0
  115. package/dist/helpers/text.d.ts +3 -1
  116. package/dist/helpers/text.js +16 -0
  117. package/dist/helpers/text.js.map +1 -1
  118. package/dist/helpers/textguard.d.ts +31 -0
  119. package/dist/helpers/textguard.js +157 -0
  120. package/dist/helpers/textguard.js.map +1 -0
  121. package/dist/helpers/title.d.ts +4 -0
  122. package/dist/helpers/title.js +52 -0
  123. package/dist/helpers/title.js.map +1 -0
  124. package/dist/sdkgen.d.ts +4 -6
  125. package/dist/sdkgen.js +59 -69
  126. package/dist/sdkgen.js.map +1 -1
  127. package/dist/testkit.d.ts +6 -2
  128. package/dist/testkit.js +4 -1
  129. package/dist/testkit.js.map +1 -1
  130. package/dist/tsconfig.tsbuildinfo +1 -1
  131. package/model/fact.aontu +106 -0
  132. package/model/sdkgen.aontu +9 -1
  133. package/package.json +1 -1
  134. package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +1 -1
  135. package/project/.sdk/src/cmp/clojure/ReadmeQuick_clojure.ts +1 -1
  136. package/project/.sdk/src/cmp/cpp/ReadmeQuick_cpp.ts +1 -1
  137. package/project/.sdk/src/cmp/csharp/ReadmeQuick_csharp.ts +1 -1
  138. package/project/.sdk/src/cmp/elixir/ReadmeQuick_elixir.ts +1 -1
  139. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
  140. package/project/.sdk/src/cmp/java/ReadmeQuick_java.ts +1 -1
  141. package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +1 -1
  142. package/project/.sdk/src/cmp/kotlin/ReadmeQuick_kotlin.ts +1 -1
  143. package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +1 -1
  144. package/project/.sdk/src/cmp/ocaml/ReadmeQuick_ocaml.ts +1 -1
  145. package/project/.sdk/src/cmp/perl/ReadmeQuick_perl.ts +1 -1
  146. package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +1 -1
  147. package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +1 -1
  148. package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +1 -1
  149. package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +1 -1
  150. package/project/.sdk/src/cmp/scala/ReadmeQuick_scala.ts +1 -1
  151. package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +1 -1
  152. package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +1 -1
  153. package/project/.sdk/src/cmp/ts/TestDefinition_ts.ts +3 -1
  154. package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +1 -1
  155. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +3 -1
  156. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +2 -1
  157. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +11 -2
  158. package/project/sdkgen-package.json +1 -1
  159. package/src/action/check.ts +78 -4
  160. package/src/action/doctor.ts +62 -4
  161. package/src/action/package.ts +1 -13
  162. package/src/action/remove.ts +19 -5
  163. package/src/action/resolve.ts +11 -4
  164. package/src/admin/status.ts +25 -5
  165. package/src/cmp/AgentGuide.ts +28 -15
  166. package/src/cmp/AgentGuideContent.ts +22 -11
  167. package/src/cmp/AgentGuideFeature.ts +15 -6
  168. package/src/cmp/AgentGuideTop.ts +17 -8
  169. package/src/cmp/Changelog.ts +46 -6
  170. package/src/cmp/Deploy.ts +59 -20
  171. package/src/cmp/Entity.ts +1 -1
  172. package/src/cmp/ExternalTarget.ts +6 -0
  173. package/src/cmp/Feature.ts +3 -3
  174. package/src/cmp/Main.ts +1 -1
  175. package/src/cmp/PublishWorkflow.ts +66 -58
  176. package/src/cmp/ReadmeIntro.ts +1 -1
  177. package/src/cmp/ReadmeModel.ts +2 -2
  178. package/src/cmp/ReadmeStation.ts +4 -5
  179. package/src/cmp/ReadmeTop.ts +60 -60
  180. package/src/cmp/Registered.ts +1 -1
  181. package/src/cmp/Security.ts +32 -5
  182. package/src/cmp/Test.ts +1 -1
  183. package/src/helpers/alongside.ts +16 -19
  184. package/src/helpers/applicability.ts +16 -1
  185. package/src/helpers/component.ts +11 -1
  186. package/src/helpers/definitionPlan.ts +0 -1
  187. package/src/helpers/doctext.ts +3 -1
  188. package/src/helpers/facts.ts +214 -5
  189. package/src/helpers/flowGuard.ts +22 -7
  190. package/src/helpers/generated.ts +3 -1
  191. package/src/helpers/graphqlPoint.ts +20 -1
  192. package/src/helpers/guardModel.ts +50 -0
  193. package/src/helpers/manifest.ts +19 -0
  194. package/src/helpers/mcpTools.ts +11 -1
  195. package/src/helpers/opShape.ts +16 -16
  196. package/src/helpers/packageMeta.ts +67 -43
  197. package/src/helpers/placement.ts +114 -0
  198. package/src/helpers/semver.ts +26 -0
  199. package/src/helpers/serverVars.ts +4 -2
  200. package/src/helpers/shipped.ts +13 -0
  201. package/src/helpers/sourcestring.ts +47 -0
  202. package/src/helpers/stdrep.ts +6 -1
  203. package/src/helpers/surface.ts +82 -0
  204. package/src/helpers/targetguard.ts +91 -0
  205. package/src/helpers/text.ts +22 -0
  206. package/src/helpers/textguard.ts +208 -0
  207. package/src/helpers/title.ts +59 -0
  208. package/src/sdkgen.ts +65 -85
  209. package/src/testkit.ts +12 -0
@@ -1,15 +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
 
6
- import { docTexts } from './doctext'
7
+ import { docTexts, sentinelName } from './doctext'
7
8
  import { factRulesFile } from './shipped'
9
+ import { CANON_OP_ORDER } from './opShape'
10
+ import { hasPackageName, packageName, registryState } from './packageMeta'
8
11
  import { SdkGenError } from '../utility'
12
+ import { resolvesBundled } from '../action/resolve'
13
+ import { titleFacts } from './title'
14
+ import { definitionKind } from './graphqlPoint'
9
15
 
10
16
 
11
- // No fact rule reads these, and they are most of a large model.
12
- 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']
13
20
 
14
21
 
15
22
  function isMap(v: any): boolean {
@@ -45,13 +52,26 @@ function applyFacts(model: any): any {
45
52
  input[key] = val
46
53
  }
47
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, {}]))
48
66
 
49
67
  const texts = docTexts(model)
50
68
  const escape = Object.fromEntries(texts.map((t, i) => ['t' + i, { raw: t.raw, vendor: t.vendor }]))
51
69
 
52
70
  const path = factRulesFile()
53
- const src = JSON.stringify({ main: { [KIT]: input }, escape }).slice(1, -1) +
54
- '\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')
55
75
 
56
76
  const errs: any[] = []
57
77
  const out = new Aontu().generate(src, { path, errs })
@@ -61,11 +81,200 @@ function applyFacts(model: any): any {
61
81
  }
62
82
 
63
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)
64
94
  texts.forEach((t, i) => place(t.at, t.path, out.escape['t' + i]))
95
+ titleFacts(kit.target)
96
+ place(kit, ['definitionKind'], definitionKind(model))
65
97
  return model
66
98
  }
67
99
 
68
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
+
69
278
  function place(at: any, path: string[], forms: any): void {
70
279
  let node = at.fact = isMap(at.fact) ? at.fact : {}
71
280
  for (const key of path.slice(0, -1)) {
@@ -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
  }
@@ -395,19 +395,17 @@ function invalidRequest(ent: any):
395
395
  }
396
396
 
397
397
 
398
- // The entity's ACTIVE op names, in canonical CRUD order, then any others
399
- // sorted. Doc generators gate an op example on this, NOT on the raw
400
- // `Object.keys(ent.op)`: an `active: false` op generates no method, and an op
401
- // whose every route is an action is refused without one, so a plain example
402
- // of either would fail.
398
+ // The entity's ACTIVE op names that the bundled targets generate, in canonical
399
+ // CRUD order. Doc generators gate an op example on this, NOT on the raw
400
+ // `Object.keys(ent.op)`: an op outside `CANON_OP_ORDER` generates no method,
401
+ // and an op whose every route is an action is refused without one, so a plain
402
+ // example of either would fail.
403
403
  const CANON_OP_ORDER = ['list', 'load', 'create', 'update', 'patch', 'remove']
404
404
 
405
405
  function entityOps(ent: any): string[] {
406
406
  const ops = (ent && ent.op) || {}
407
- const active = Object.keys(ops).filter((o: string) =>
407
+ return CANON_OP_ORDER.filter((o: string) =>
408
408
  ops[o] && ops[o].active !== false && !opNeedsAction(ops[o]))
409
- return CANON_OP_ORDER.filter((o) => active.includes(o))
410
- .concat(active.filter((o) => !CANON_OP_ORDER.includes(o)).sort())
411
409
  }
412
410
 
413
411
 
@@ -422,7 +420,6 @@ function introOps(model: any): string[] {
422
420
  }
423
421
  }
424
422
  const names = CANON_OP_ORDER.filter((o) => found.has(o))
425
- .concat([...found].filter((o) => !CANON_OP_ORDER.includes(o)))
426
423
  return 0 < names.length ? names : ['list', 'load']
427
424
  }
428
425
 
@@ -482,8 +479,8 @@ function ungeneratedOps(model: any): UngeneratedOp[] {
482
479
  }
483
480
 
484
481
 
485
- // Speaks only for the bundled targets: a target from another package may
486
- // generate more ops, so it is named as outside the claim rather than judged.
482
+ // Speaks only for the bundled targets: a target from another package or the
483
+ // project's own may generate more ops, so it is named outside the claim.
487
484
  function warnUngeneratedOps(
488
485
  model: any, log: any, origins: TargetOrigins,
489
486
  ): UngeneratedOp[] {
@@ -493,11 +490,14 @@ function warnUngeneratedOps(
493
490
  (0 < d.points.length ? ` (${d.points.join(', ')})` : ''))
494
491
  const generated = CANON_OP_ORDER.slice(0, -1).join(', ') + ' and ' +
495
492
  CANON_OP_ORDER[CANON_OP_ORDER.length - 1]
496
- const external = origins.external.map((t) => `${t.name} from ${t.from}`)
493
+ const outside = [
494
+ ...origins.external.map((t) => `${t.name} from ${t.from}`),
495
+ ...origins.owned.map((name) => `${name} (the project's own)`),
496
+ ]
497
497
  log.warn({
498
498
  point: 'entity-op-ungenerated', ops: dropped,
499
- bundled: origins.bundled, external: origins.external,
500
- note: 0 === external.length
499
+ bundled: origins.bundled, external: origins.external, owned: origins.owned,
500
+ note: 0 === outside.length
501
501
  ? `operation(s) in the model that the bundled targets do not ` +
502
502
  `generate (each generates ${generated} only), so the SDK has no ` +
503
503
  `method for them: ${listed.join(', ')}. To reach one, reclassify it ` +
@@ -506,8 +506,8 @@ function warnUngeneratedOps(
506
506
  : `operation(s) in the model that the bundled targets ` +
507
507
  `(${origins.bundled.join(', ')}) do not generate (each generates ` +
508
508
  `${generated} only), so their SDKs have no method for them: ` +
509
- `${listed.join(', ')}. Targets installed from elsewhere may ` +
510
- `generate them, so they are not judged here: ${external.join(', ')}. ` +
509
+ `${listed.join(', ')}. Targets from elsewhere may generate them, ` +
510
+ `so they are not judged here: ${outside.join(', ')}. ` +
511
511
  `To reach one in a bundled target, reclassify it in the guide ` +
512
512
  `(.sdk/model/guide/guide.aontu)`,
513
513
  })