@voxgig/sdkgen 4.44.3 → 4.46.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 (161) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/check.js +15 -0
  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 +21 -2
  7. package/dist/action/doctor.js +166 -9
  8. package/dist/action/doctor.js.map +1 -1
  9. package/dist/action/package.js +9 -0
  10. package/dist/action/package.js.map +1 -1
  11. package/dist/action/remove.js +2 -1
  12. package/dist/action/remove.js.map +1 -1
  13. package/dist/action/target.d.ts +2 -1
  14. package/dist/action/target.js +50 -11
  15. package/dist/action/target.js.map +1 -1
  16. package/dist/cmp/AgentGuide.js +19 -8
  17. package/dist/cmp/AgentGuide.js.map +1 -1
  18. package/dist/cmp/AgentGuideContent.d.ts +6 -4
  19. package/dist/cmp/AgentGuideContent.js +51 -32
  20. package/dist/cmp/AgentGuideContent.js.map +1 -1
  21. package/dist/cmp/AgentGuideFeature.js +7 -4
  22. package/dist/cmp/AgentGuideFeature.js.map +1 -1
  23. package/dist/cmp/AgentGuideTop.js +84 -46
  24. package/dist/cmp/AgentGuideTop.js.map +1 -1
  25. package/dist/cmp/Changelog.js +12 -1
  26. package/dist/cmp/Changelog.js.map +1 -1
  27. package/dist/cmp/Deploy.js +22 -20
  28. package/dist/cmp/Deploy.js.map +1 -1
  29. package/dist/cmp/ExternalTarget.js +5 -5
  30. package/dist/cmp/ExternalTarget.js.map +1 -1
  31. package/dist/cmp/Feature.js +10 -3
  32. package/dist/cmp/Feature.js.map +1 -1
  33. package/dist/cmp/FeatureDocs.d.ts +6 -4
  34. package/dist/cmp/FeatureDocs.js +14 -39
  35. package/dist/cmp/FeatureDocs.js.map +1 -1
  36. package/dist/cmp/FeatureHook.d.ts +7 -1
  37. package/dist/cmp/FeatureHook.js +34 -1
  38. package/dist/cmp/FeatureHook.js.map +1 -1
  39. package/dist/cmp/PublishWorkflow.js +30 -6
  40. package/dist/cmp/PublishWorkflow.js.map +1 -1
  41. package/dist/cmp/ReadmeErrors.js +521 -18
  42. package/dist/cmp/ReadmeErrors.js.map +1 -1
  43. package/dist/cmp/ReadmeExplanation.js +280 -44
  44. package/dist/cmp/ReadmeExplanation.js.map +1 -1
  45. package/dist/cmp/ReadmeFeatures.js +16 -7
  46. package/dist/cmp/ReadmeFeatures.js.map +1 -1
  47. package/dist/cmp/ReadmeIntro.js +3 -2
  48. package/dist/cmp/ReadmeIntro.js.map +1 -1
  49. package/dist/cmp/ReadmeRefFeatures.js +34 -24
  50. package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
  51. package/dist/cmp/ReadmeStation.js +11 -8
  52. package/dist/cmp/ReadmeStation.js.map +1 -1
  53. package/dist/cmp/ReadmeTop.js +472 -373
  54. package/dist/cmp/ReadmeTop.js.map +1 -1
  55. package/dist/cmp/ReadmeUnions.js +8 -2
  56. package/dist/cmp/ReadmeUnions.js.map +1 -1
  57. package/dist/cmp/Security.js +3 -2
  58. package/dist/cmp/Security.js.map +1 -1
  59. package/dist/helpers/applicability.d.ts +2 -1
  60. package/dist/helpers/applicability.js +26 -0
  61. package/dist/helpers/applicability.js.map +1 -1
  62. package/dist/helpers/copymerge.d.ts +3 -0
  63. package/dist/helpers/copymerge.js +43 -10
  64. package/dist/helpers/copymerge.js.map +1 -1
  65. package/dist/helpers/doccheck.d.ts +11 -0
  66. package/dist/helpers/doccheck.js +146 -0
  67. package/dist/helpers/doccheck.js.map +1 -0
  68. package/dist/helpers/doctext.d.ts +11 -0
  69. package/dist/helpers/doctext.js +84 -0
  70. package/dist/helpers/doctext.js.map +1 -0
  71. package/dist/helpers/exampleCall.d.ts +16 -0
  72. package/dist/helpers/exampleCall.js +334 -0
  73. package/dist/helpers/exampleCall.js.map +1 -0
  74. package/dist/helpers/exportnames.d.ts +4 -0
  75. package/dist/helpers/exportnames.js +35 -0
  76. package/dist/helpers/exportnames.js.map +1 -0
  77. package/dist/helpers/facts.d.ts +4 -0
  78. package/dist/helpers/facts.js +92 -0
  79. package/dist/helpers/facts.js.map +1 -0
  80. package/dist/helpers/modelcheck.d.ts +2 -1
  81. package/dist/helpers/modelcheck.js +13 -0
  82. package/dist/helpers/modelcheck.js.map +1 -1
  83. package/dist/helpers/opExample.d.ts +9 -2
  84. package/dist/helpers/opExample.js +22 -2
  85. package/dist/helpers/opExample.js.map +1 -1
  86. package/dist/helpers/opShape.d.ts +2 -1
  87. package/dist/helpers/opShape.js +12 -0
  88. package/dist/helpers/opShape.js.map +1 -1
  89. package/dist/helpers/packageMeta.js +21 -8
  90. package/dist/helpers/packageMeta.js.map +1 -1
  91. package/dist/helpers/semver.d.ts +2 -1
  92. package/dist/helpers/semver.js +7 -0
  93. package/dist/helpers/semver.js.map +1 -1
  94. package/dist/helpers/shipped.d.ts +2 -1
  95. package/dist/helpers/shipped.js +4 -0
  96. package/dist/helpers/shipped.js.map +1 -1
  97. package/dist/sdkgen.d.ts +2 -1
  98. package/dist/sdkgen.js +29 -6
  99. package/dist/sdkgen.js.map +1 -1
  100. package/dist/testkit.d.ts +1 -0
  101. package/dist/testkit.js +23 -19
  102. package/dist/testkit.js.map +1 -1
  103. package/dist/tsconfig.tsbuildinfo +1 -1
  104. package/dist/utility.js +2 -1
  105. package/dist/utility.js.map +1 -1
  106. package/model/fact.aontu +59 -0
  107. package/model/sdkgen.aontu +6 -2
  108. package/package.json +3 -1
  109. package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +1 -1
  110. package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +1 -1
  111. package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +12 -3
  112. package/project/.sdk/src/cmp/scala/ReadmeRef_scala.ts +4 -1
  113. package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +1 -0
  114. package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +3 -0
  115. package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -1
  116. package/project/.sdk/src/cmp/zig/ReadmeOptions_zig.ts +1 -1
  117. package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +2 -2
  118. package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
  119. package/project/sdkgen-package.json +1 -1
  120. package/src/action/check.ts +21 -0
  121. package/src/action/copies.ts +2 -0
  122. package/src/action/doctor.ts +244 -13
  123. package/src/action/package.ts +10 -0
  124. package/src/action/remove.ts +2 -1
  125. package/src/action/target.ts +66 -15
  126. package/src/cmp/AgentGuide.ts +24 -10
  127. package/src/cmp/AgentGuideContent.ts +53 -32
  128. package/src/cmp/AgentGuideFeature.ts +8 -5
  129. package/src/cmp/AgentGuideTop.ts +108 -47
  130. package/src/cmp/Changelog.ts +13 -2
  131. package/src/cmp/Deploy.ts +23 -21
  132. package/src/cmp/ExternalTarget.ts +6 -6
  133. package/src/cmp/Feature.ts +11 -4
  134. package/src/cmp/FeatureDocs.ts +21 -40
  135. package/src/cmp/FeatureHook.ts +38 -1
  136. package/src/cmp/PublishWorkflow.ts +33 -7
  137. package/src/cmp/ReadmeErrors.ts +555 -25
  138. package/src/cmp/ReadmeExplanation.ts +316 -52
  139. package/src/cmp/ReadmeFeatures.ts +18 -8
  140. package/src/cmp/ReadmeIntro.ts +3 -2
  141. package/src/cmp/ReadmeRefFeatures.ts +39 -27
  142. package/src/cmp/ReadmeStation.ts +12 -14
  143. package/src/cmp/ReadmeTop.ts +528 -387
  144. package/src/cmp/ReadmeUnions.ts +10 -2
  145. package/src/cmp/Security.ts +3 -2
  146. package/src/helpers/applicability.ts +28 -0
  147. package/src/helpers/copymerge.ts +58 -10
  148. package/src/helpers/doccheck.ts +174 -0
  149. package/src/helpers/doctext.ts +113 -0
  150. package/src/helpers/exampleCall.ts +415 -0
  151. package/src/helpers/exportnames.ts +47 -0
  152. package/src/helpers/facts.ts +119 -0
  153. package/src/helpers/modelcheck.ts +16 -0
  154. package/src/helpers/opExample.ts +34 -2
  155. package/src/helpers/opShape.ts +13 -0
  156. package/src/helpers/packageMeta.ts +21 -8
  157. package/src/helpers/semver.ts +9 -0
  158. package/src/helpers/shipped.ts +5 -0
  159. package/src/sdkgen.ts +31 -2
  160. package/src/testkit.ts +30 -20
  161. package/src/utility.ts +2 -1
@@ -9,7 +9,8 @@ import {
9
9
 
10
10
  import { credentialPlacement } from '../utility'
11
11
  import { optionalComponent } from '../helpers/optional'
12
- import { featureDocs } from './FeatureDocs'
12
+ import { featureDocs, codeList } from './FeatureDocs'
13
+ import { PIPELINE_STAGES, pipelineLength } from './FeatureHook'
13
14
  import type { FeatureDoc } from './FeatureDocs'
14
15
 
15
16
  import {
@@ -21,7 +22,9 @@ import type { ExampleLang, PrimaryCall } from '../helpers/opExample'
21
22
  import { canonScalarKey } from '../helpers/canonType'
22
23
  import { safeVarName, exampleVarName, jsKey } from '../helpers/naming'
23
24
  import { modelText } from '../helpers/text'
25
+ import { fact } from '../helpers/facts'
24
26
  import { isConsumer } from '../helpers/alongside'
27
+ import { copyMode, MERGE } from '../helpers/copymerge'
25
28
 
26
29
  import {
27
30
  installCommand as pkgInstall,
@@ -97,243 +100,186 @@ function entityExample(lang: ExampleLang, Name: string, call: PrimaryCall | null
97
100
  }
98
101
 
99
102
 
100
- const ReadmeTop = cmp(function ReadmeTop(props: any) {
101
- const { ctx$ } = props
102
- const { model } = ctx$
103
-
104
- if (model.name && !model.Name) names(model, model.name)
105
-
106
- const info = modelText(model)
107
- const def = (model.main && model.main.def) || {}
108
-
109
- const productName = info.title || `${model.Name} API`
110
-
111
- const tagline = info.tagline
112
- || def.tagline
113
- || `${productName} client, generated from the OpenAPI spec.`
114
-
115
- const aboutMd = info.about_md || ''
116
- const homepage = info.homepage || ''
117
- const docsUrl = info.docs_url || ''
118
- const entityDesc = info.entity_desc || {}
119
-
120
- const apiSummary = (info.summary || '').trim()
121
- const apiWebsite = (info.website || '').trim()
122
- const websiteLine = apiWebsite
123
- ? `Learn more about ${productName} at ` +
124
- `[${apiWebsite.replace(/^https?:\/\//, '').replace(/\/$/, '')}](${apiWebsite}).`
125
- : ''
126
-
127
- // Attribution for API metadata sourced from a third-party catalogue (e.g.
128
- // freepublicapis.com). Rendered only when the model carries an
129
- // `info.meta_source` URL, so first-party SDKs never show it. The link points
130
- // back to the catalogue that kindly supplied the metadata.
131
- const metaSource = (info.meta_source || '').trim()
132
- const metaSourceLine = metaSource
133
- ? `Metadata kindly supplied by ` +
134
- `[${metaSource.replace(/^https?:\/\//, '').replace(/\/$/, '')}](${metaSource}).`
135
- : ''
136
-
137
- const entity = getModelPath(model, `main.${KIT}.entity`)
138
- const target = getModelPath(model, `main.${KIT}.target`)
139
- const feature = getModelPath(model, `main.${KIT}.feature`)
140
-
141
- each(entity, (ent: any) => { if (!ent.Name) names(ent, ent.name) })
142
- each(feature, (feat: any) => { if (!feat.Name) names(feat, feat.name) })
143
-
144
- const activeEntities = each(entity).filter((e: any) => e.active !== false)
145
- const activeTargets = each(target).filter((t: any) => t.active !== false)
146
-
147
- const hasCli = activeTargets.some((t: any) => t.name === 'go-cli')
148
- const hasMcp = activeTargets.some((t: any) => t.name === 'go-mcp')
149
-
150
-
151
- const docsOrder: string[] = (getModelPath(model, `main.${KIT}.config.docs_order`,
152
- { only_active: false, required: false }) as any) || []
153
-
154
- const orderOf = (name: string): number => {
155
- const i = docsOrder.indexOf(name)
156
- if (i !== -1) return i
157
- if (name === 'go-cli') return docsOrder.length + 1
158
- if (name === 'go-mcp') return docsOrder.length + 2
159
- return docsOrder.length
160
- }
103
+ const ReadmeTopTitle = cmp(function ReadmeTopTitle(props: any) {
104
+ const { model, tagline, apiSummary, websiteLine, metaSourceLine } = props.s
161
105
 
162
- const ordered = activeTargets
163
- .slice()
164
- .sort((a: any, b: any) => orderOf(a.name) - orderOf(b.name))
165
-
166
- const isCliOrMcp = (t: any) => t.name === 'go-cli' || t.name === 'go-mcp'
167
-
168
- const sdkTargets = ordered.filter((t: any) => !isConsumer(t))
169
-
170
- // The CLI and the MCP server have surfaces of their own below.
171
- const consumerTargets = ordered.filter((t: any) => isConsumer(t) && !isCliOrMcp(t))
172
-
173
- const docTargets = ordered.filter((t: any) => !isCliOrMcp(t))
174
-
175
- const pkgTargets = activeTargets
176
- .filter((t: any) => hasPackageName(model, t.name))
177
- .sort((a: any, b: any) => orderOf(a.name) - orderOf(b.name))
178
-
179
- const langList = sdkTargets.map((t: any) => t.title).join(', ')
180
- const leadTarget = pickLeadTarget(sdkTargets)
181
-
182
- File({ name: 'README.md' }, () => {
183
-
184
- Content(`# ${model.Name} SDK
106
+ Content(`# ${model.Name} SDK
185
107
 
186
108
  ${tagline}
187
109
 
188
110
  `)
189
- if (apiSummary) {
190
- Content(`${apiSummary}
111
+ if (apiSummary) {
112
+ Content(`${apiSummary}
191
113
 
192
114
  `)
193
- }
194
- if (websiteLine) {
195
- Content(`${websiteLine}
115
+ }
116
+ if (websiteLine) {
117
+ Content(`${websiteLine}
196
118
 
197
119
  `)
198
- }
199
- Content(`${nonAffiliation(model)}
120
+ }
121
+ Content(`${nonAffiliation(model)}
200
122
 
201
123
  `)
202
- if (isDefaultPublisher(model)) {
203
- Content(`Learn more about Voxgig SDKs at [voxgig.com/sdk](${VOXGIG_SDK}).
124
+ if (isDefaultPublisher(model)) {
125
+ Content(`Learn more about Voxgig SDKs at [voxgig.com/sdk](${VOXGIG_SDK}).
204
126
 
205
127
  `)
206
- }
128
+ }
207
129
 
208
- // THE GENERATED SITE, LINKED FROM THE TOP, because the repository was the
209
- // one place it could not be found from. `docs_url` further down is the
210
- // UPSTREAM API's documentation, not this, and a reader who lands on the
211
- // repo rather than arriving from a link had no route to the site at all.
212
- // Empty unless the project actually publishes one -- see docsSiteUrl.
213
- const siteUrl = docsSiteUrl(model)
214
- if (siteUrl) {
215
- Content(`Full documentation for this SDK: [${siteUrl}](${siteUrl})
130
+ // THE GENERATED SITE, LINKED FROM THE TOP, because the repository was the
131
+ // one place it could not be found from. `docs_url` further down is the
132
+ // UPSTREAM API's documentation, not this, and a reader who lands on the
133
+ // repo rather than arriving from a link had no route to the site at all.
134
+ // Empty unless the project actually publishes one -- see docsSiteUrl.
135
+ const siteUrl = docsSiteUrl(model)
136
+ if (siteUrl) {
137
+ Content(`Full documentation for this SDK: [${siteUrl}](${siteUrl})
216
138
 
217
139
  `)
218
- }
219
- if (metaSourceLine) {
220
- Content(`${metaSourceLine}
140
+ }
141
+ if (metaSourceLine) {
142
+ Content(`${metaSourceLine}
221
143
 
222
144
  `)
223
- }
145
+ }
146
+ })
147
+
224
148
 
225
- if (sdkTargets.length > 1) {
226
- const surfaces = []
227
- surfaces.push(`${langList} SDKs`)
228
- if (hasCli) surfaces.push('a CLI with an interactive REPL')
229
- if (hasMcp) surfaces.push('an MCP server for AI agents')
230
- consumerTargets.forEach((t: any) => surfaces.push(`the ${t.title} package`))
231
- const surfaceList = surfaces.length > 1
232
- ? surfaces.slice(0, -1).join(', ') + ', and ' + surfaces[surfaces.length - 1]
233
- : surfaces[0]
234
- Content(`> ${surfaceList} — all generated from one OpenAPI spec by [@voxgig/sdkgen](${SDKGEN_REPO}).
149
+ const ReadmeTopSurfaceLine = cmp(function ReadmeTopSurfaceLine(props: any) {
150
+ const { hasCli, hasMcp, sdkTargets, consumerTargets, langList } = props.s
151
+
152
+ if (sdkTargets.length > 1) {
153
+ const surfaces = []
154
+ surfaces.push(`${langList} SDKs`)
155
+ if (hasCli) surfaces.push('a CLI with an interactive REPL')
156
+ if (hasMcp) surfaces.push('an MCP server for AI agents')
157
+ consumerTargets.forEach((t: any) => surfaces.push(`the ${t.title} package`))
158
+ const surfaceList = surfaces.length > 1
159
+ ? surfaces.slice(0, -1).join(', ') + ', and ' + surfaces[surfaces.length - 1]
160
+ : surfaces[0]
161
+ Content(`> ${surfaceList} — all generated from one OpenAPI spec by [@voxgig/sdkgen](${SDKGEN_REPO}).
235
162
 
236
163
  `)
237
- }
164
+ }
165
+ })
166
+
238
167
 
239
- // FEATURES BELONG BESIDE THE TARGETS. What an SDK can do is as much a
240
- // reason to choose it as which language it is in, and a reader who has to
241
- // scroll past every language section to discover that retries, caching and
242
- // tracing are built in has already decided it is a thin HTTP wrapper.
243
- // Named here, in one line, with the detail left to each target's README.
244
- const features = featureDocs(model)
245
- if (0 < features.length) {
246
- Content(`> **Features:** ${features.map((f: FeatureDoc) => '`' + f.name + '`').join(', ')} — opt-in,
247
- > inactive until switched on, and configured per client. See the Features
168
+ const ReadmeTopFeatureLine = cmp(function ReadmeTopFeatureLine(props: any) {
169
+ const { model } = props.s
170
+
171
+ // FEATURES BELONG BESIDE THE TARGETS. What an SDK can do is as much a
172
+ // reason to choose it as which language it is in, and a reader who has to
173
+ // scroll past every language section to discover that retries, caching and
174
+ // tracing are built in has already decided it is a thin HTTP wrapper.
175
+ // Named here, in one line, with the detail left to each target's README.
176
+ const features = featureDocs(model)
177
+ if (0 < features.length) {
178
+ const on = features.filter((f: FeatureDoc) => f.on).map((f: FeatureDoc) => f.name)
179
+ const state = 0 === on.length ? `opt-in,
180
+ > inactive until switched on, and configured per client.` : `configured per client.
181
+ > ${codeList(on)} ${1 === on.length ? 'runs' : 'run'} by default${on.length < features.length ?
182
+ '; the rest are opt-in, inactive until switched on' : ''}.`
183
+ Content(`> **Features:** ${features.map((f: FeatureDoc) => '`' + f.name + '`').join(', ')} — ${state} See the Features
248
184
  > section of any SDK README below for what each one does.
249
185
 
250
186
  `)
251
- }
187
+ }
188
+ })
189
+
252
190
 
253
- if (aboutMd) {
254
- Content(`## About ${productName}
191
+ const ReadmeTopAbout = cmp(function ReadmeTopAbout(props: any) {
192
+ const { text, productName, aboutMd } = props.s
255
193
 
256
- ${aboutMd.trim()}
194
+ if (aboutMd) {
195
+ Content(`## About ${productName}
196
+
197
+ ${aboutMd}
257
198
 
258
199
  `)
259
- } else if (def.desc) {
260
- Content(`${def.desc}
200
+ } else if (text.desc.text) {
201
+ Content(`${text.desc.text}
261
202
 
262
203
  `)
263
- }
204
+ }
205
+ })
264
206
 
265
- if (activeEntities.length > 0) {
266
- const entNames = activeEntities.map((e: any) => e.Name)
267
- const entCount = entNames.length
268
- const entList = entCount > 1
269
- ? entNames.slice(0, -1).join(', ') + ' and ' + entNames[entNames.length - 1]
270
- : entNames[0]
271
- const NAME_INLINE_MAX = 6
272
- const inlineNames = entCount <= NAME_INLINE_MAX
273
- const surface = inlineNames
274
- ? `a small set of **semantic entities** — ${entList} —`
275
- : `**${entCount} semantic entities**`
276
- const seeEntities = inlineNames
277
- ? ''
278
- : ' See the [Entities](#entities) table below for the full list.'
279
- const exEnt = activeEntities[0]
280
- const ex = exEnt.Name
281
- const exLower = exampleVarName(ex.toLowerCase(), 'ts')
282
- // The example call uses the entity's PRIMARY op — an op it actually
283
- // exposes (prefer list -> the array, then load -> the record, else a
284
- // create with its required fields). A create-only entity therefore never
285
- // shows a phantom .list()/.load() that would not compile. If it exposes
286
- // only remove (or nothing), the op line is omitted entirely.
287
- const primaryOp = entityPrimaryOp(exEnt)
288
- let exCall = ''
289
- const exIdField = entityIdField(exEnt)
290
- const exListArg = listMatchArg('ts', exEnt)
291
- const exLoadArg = matchArg('ts', exEnt, 'load', exIdField,
292
- idLiteral(exEnt, 'load', exIdField))
293
-
294
- if ('list' === primaryOp) {
295
- exCall = `const items = await client.${ex}().list(${exListArg})`
296
- } else if ('load' === primaryOp) {
297
- exCall = `const ${exLower} = await client.${ex}().load(${exLoadArg})`
298
- } else if ('create' === primaryOp || 'update' === primaryOp || 'patch' === primaryOp) {
299
- const exIdF = entityIdField(exEnt)
300
- // Drop the id only when the request shape says it is OPTIONAL. It is
301
- // server-assigned on a normal create, but an op whose id comes from a
302
- // PATH PARAMETER requires it, and the typed CreateData then rejects a
303
- // body without it. Same rule as dataArg in helpers/opExample.
304
- const shapeItems = requestExampleItems(exEnt, primaryOp)
305
- .filter((it: any) =>
306
- (it.name !== exIdF && it.name !== 'id') || !it.optional)
307
- const required = shapeItems.filter((it: any) => !it.optional)
308
- const chosen = required.length ? required : shapeItems.slice(0, 3)
309
- const bodyLines = chosen.map((it: any) => ` ${jsKey(it.name)}: ${tsExampleLiteral(it.type)},`)
310
- const body = bodyLines.length ? `\n${bodyLines.join('\n')}\n` : ''
311
- exCall = `const ${exLower} = await client.${ex}().${primaryOp}({${body}})`
312
- }
313
- const CANON_OPS = ['list', 'load', 'create', 'update', 'patch', 'remove']
314
- const opSet = new Set<string>()
315
- activeEntities.forEach((e: any) => Object.keys(e.op || {})
316
- .forEach((o: string) => { if ((e.op as any)[o] && (e.op as any)[o].active !== false) opSet.add(o) }))
317
- const opNames = CANON_OPS.filter((o) => opSet.has(o)).concat([...opSet].filter((o) => !CANON_OPS.includes(o)))
318
- const opList = (opNames.length ? opNames : ['list', 'load']).map((o) => '`' + o + '`').join(', ')
319
-
320
- // In the SDK's own language: ts when it has one, else the first the
321
- // example helpers can write, else no example at all.
322
- const lang = exampleLang(model, sdkTargets)
323
- let snippet = ''
324
- if ('ts' === lang) {
325
- snippet = `const client = new ${model.Name}SDK()${exCall ? '\n' + exCall : ''}`
326
- }
327
- else if (null != lang) {
328
- const call = ['list', 'load', 'create', 'update', 'patch'].includes(String(primaryOp))
329
- ? primaryOpCall(lang, ex, exampleVarName(ex.toLowerCase(), lang), primaryOp!, exIdField, exEnt)
330
- : null
331
- snippet = entityExample(lang, model.Name, call)
332
- }
333
- const exBlock = '' === snippet ? '.' :
334
- `:\n\n\`\`\`${EXAMPLE_FENCE[lang!]}\n${snippet}\n\`\`\``
335
207
 
336
- Content(`## Entities, not endpoints
208
+ const ReadmeTopEntityModel = cmp(function ReadmeTopEntityModel(props: any) {
209
+ const { model, activeEntities, sdkTargets } = props.s
210
+
211
+ if (activeEntities.length > 0) {
212
+ const entNames = activeEntities.map((e: any) => e.Name)
213
+ const entCount = entNames.length
214
+ const entList = entCount > 1
215
+ ? entNames.slice(0, -1).join(', ') + ' and ' + entNames[entNames.length - 1]
216
+ : entNames[0]
217
+ const NAME_INLINE_MAX = 6
218
+ const inlineNames = entCount <= NAME_INLINE_MAX
219
+ const surface = inlineNames
220
+ ? `a small set of **semantic entities** — ${entList} —`
221
+ : `**${entCount} semantic entities**`
222
+ const seeEntities = inlineNames
223
+ ? ''
224
+ : ' See the [Entities](#entities) table below for the full list.'
225
+ const exEnt = activeEntities[0]
226
+ const ex = exEnt.Name
227
+ const exLower = exampleVarName(ex.toLowerCase(), 'ts')
228
+ // The example call uses the entity's PRIMARY op — an op it actually
229
+ // exposes (prefer list -> the array, then load -> the record, else a
230
+ // create with its required fields). A create-only entity therefore never
231
+ // shows a phantom .list()/.load() that would not compile. If it exposes
232
+ // only remove (or nothing), the op line is omitted entirely.
233
+ const primaryOp = entityPrimaryOp(exEnt)
234
+ let exCall = ''
235
+ const exIdField = entityIdField(exEnt)
236
+ const exListArg = listMatchArg('ts', exEnt)
237
+ const exLoadArg = matchArg('ts', exEnt, 'load', exIdField,
238
+ idLiteral(exEnt, 'load', exIdField))
239
+
240
+ if ('list' === primaryOp) {
241
+ exCall = `const items = await client.${ex}().list(${exListArg})`
242
+ } else if ('load' === primaryOp) {
243
+ exCall = `const ${exLower} = await client.${ex}().load(${exLoadArg})`
244
+ } else if ('create' === primaryOp || 'update' === primaryOp || 'patch' === primaryOp) {
245
+ const exIdF = entityIdField(exEnt)
246
+ // Drop the id only when the request shape says it is OPTIONAL. It is
247
+ // server-assigned on a normal create, but an op whose id comes from a
248
+ // PATH PARAMETER requires it, and the typed CreateData then rejects a
249
+ // body without it. Same rule as dataArg in helpers/opExample.
250
+ const shapeItems = requestExampleItems(exEnt, primaryOp)
251
+ .filter((it: any) =>
252
+ (it.name !== exIdF && it.name !== 'id') || !it.optional)
253
+ const required = shapeItems.filter((it: any) => !it.optional)
254
+ const chosen = required.length ? required : shapeItems.slice(0, 3)
255
+ const bodyLines = chosen.map((it: any) => ` ${jsKey(it.name)}: ${tsExampleLiteral(it.type)},`)
256
+ const body = bodyLines.length ? `\n${bodyLines.join('\n')}\n` : ''
257
+ exCall = `const ${exLower} = await client.${ex}().${primaryOp}({${body}})`
258
+ }
259
+ const CANON_OPS = ['list', 'load', 'create', 'update', 'patch', 'remove']
260
+ const opSet = new Set<string>()
261
+ activeEntities.forEach((e: any) => Object.keys(e.op || {})
262
+ .forEach((o: string) => { if ((e.op as any)[o] && (e.op as any)[o].active !== false) opSet.add(o) }))
263
+ const opNames = CANON_OPS.filter((o) => opSet.has(o)).concat([...opSet].filter((o) => !CANON_OPS.includes(o)))
264
+ const opList = (opNames.length ? opNames : ['list', 'load']).map((o) => '`' + o + '`').join(', ')
265
+
266
+ // In the SDK's own language: ts when it has one, else the first the
267
+ // example helpers can write, else no example at all.
268
+ const lang = exampleLang(model, sdkTargets)
269
+ let snippet = ''
270
+ if ('ts' === lang) {
271
+ snippet = `const client = new ${model.Name}SDK()${exCall ? '\n' + exCall : ''}`
272
+ }
273
+ else if (null != lang) {
274
+ const call = ['list', 'load', 'create', 'update', 'patch'].includes(String(primaryOp))
275
+ ? primaryOpCall(lang, ex, exampleVarName(ex.toLowerCase(), lang), primaryOp!, exIdField, exEnt)
276
+ : null
277
+ snippet = entityExample(lang, model.Name, call)
278
+ }
279
+ const exBlock = '' === snippet ? '.' :
280
+ `:\n\n\`\`\`${EXAMPLE_FENCE[lang!]}\n${snippet}\n\`\`\``
281
+
282
+ Content(`## Entities, not endpoints
337
283
 
338
284
  This SDK exposes the API as ${surface} that you
339
285
  call directly, instead of assembling URL paths and query strings.${seeEntities} Entities are
@@ -344,126 +290,152 @@ Thinking in entities keeps the mental model small — for people and AI agents a
344
290
  rather than reasoning about raw HTTP routes and query parameters.
345
291
 
346
292
  `)
347
- }
293
+ }
294
+ })
348
295
 
349
- if (sdkTargets.length > 0) {
350
- Content(`## Offline unit testing
296
+
297
+ const ReadmeTopTesting = cmp(function ReadmeTopTesting(props: any) {
298
+ const { ctx$, sdkTargets } = props.s
299
+
300
+ if (sdkTargets.length > 0) {
301
+ Content(`## Offline unit testing
351
302
 
352
303
  Every SDK ships a built-in **test mode** that swaps the HTTP transport for
353
304
  an in-memory mock, so your unit tests run fully offline — no server, no
354
305
  network, and no credentials:
355
306
 
356
307
  `)
357
- sdkTargets.forEach((tgt: any) => {
358
- const Test =
359
- optionalComponent(ctx$, tgt, 'ReadmeTopTest')
360
- if (Test) {
361
- Content(`### ${tgt.title}
308
+ sdkTargets.forEach((tgt: any) => {
309
+ const Test =
310
+ optionalComponent(ctx$, tgt, 'ReadmeTopTest')
311
+ if (Test) {
312
+ Content(`### ${tgt.title}
362
313
 
363
314
  `)
364
- Test['ReadmeTopTest']({ target: tgt })
365
- Content(`
315
+ Test['ReadmeTopTest']({ target: tgt })
316
+ Content(`
366
317
  `)
367
- }
368
- })
369
- }
318
+ }
319
+ })
320
+ }
321
+ })
322
+
370
323
 
371
- // 3. Packages — real published package name + install command per
372
- // ecosystem. A package that is NOT yet live on its registry (the fleet
373
- // default: 'pending') must NOT advertise a `npm install ...` that 404s —
374
- // its Install cell links to the target README's install section instead,
375
- // as do go-cli and go-mcp, which the Go proxy cannot install.
376
- if (pkgTargets.length > 0) {
377
- Content(`## Packages
324
+ const ReadmeTopPackages = cmp(function ReadmeTopPackages(props: any) {
325
+ const { model, pkgTargets } = props.s
326
+
327
+ // 3. Packages — real published package name + install command per
328
+ // ecosystem. A package that is NOT yet live on its registry (the fleet
329
+ // default: 'pending') must NOT advertise a `npm install ...` that 404s —
330
+ // its Install cell links to the target README's install section instead,
331
+ // as do go-cli and go-mcp, which the Go proxy cannot install.
332
+ if (pkgTargets.length > 0) {
333
+ Content(`## Packages
378
334
 
379
335
  | Language | Package | Install |
380
336
  | --- | --- | --- |
381
337
  `)
382
- pkgTargets.forEach((tgt: any) => {
383
- const state = registryState(model, tgt.name)
384
- let cell: string
385
- if ('active' === state) {
386
- const cmd = installCommand(tgt, model)
387
- if (!cmd) return
388
- cell = '`' + cmd + '`'
389
- } else if ('tag' === state) {
390
- const cmd = vendorCommand(model, tgt.name)
391
- cell = cmd
392
- ? '`' + cmd + '`'
393
- : `build from source — [${tgt.name}/README.md](${tgt.name}/README.md)`
394
- } else {
395
- // The target README always gives a route that works without a
396
- // tag, which a repository may not have.
397
- cell = `publish pending — [install from source](${tgt.name}/README.md#install)`
398
- }
399
- Content(`| ${tgt.title} | \`${packageName(model, tgt.name)}\` | ${cell} |
400
- `)
401
- })
402
- Content(`
338
+ pkgTargets.forEach((tgt: any) => {
339
+ const state = registryState(model, tgt.name)
340
+ let cell: string
341
+ if ('active' === state) {
342
+ const cmd = installCommand(tgt, model)
343
+ cell = cmd
344
+ ? '`' + cmd + '`'
345
+ : `see [${tgt.name}/README.md](${tgt.name}/README.md#install)`
346
+ } else if ('tag' === state) {
347
+ const cmd = vendorCommand(model, tgt.name)
348
+ cell = cmd
349
+ ? '`' + cmd + '`'
350
+ : `build from source — [${tgt.name}/README.md](${tgt.name}/README.md)`
351
+ } else {
352
+ // The target README always gives a route that works without a
353
+ // tag, which a repository may not have.
354
+ cell = `publish pending — [install from source](${tgt.name}/README.md#install)`
355
+ }
356
+ Content(`| ${tgt.title} | \`${packageName(model, tgt.name)}\` | ${cell} |
357
+ `)
358
+ })
359
+ Content(`
403
360
  `)
404
- }
361
+ }
362
+ })
363
+
405
364
 
406
- if (leadTarget) {
407
- Content(`## Quickstart
365
+ const ReadmeTopQuickstart = cmp(function ReadmeTopQuickstart(props: any) {
366
+ const { model, ctx$, leadTarget } = props.s
367
+
368
+ if (leadTarget) {
369
+ Content(`## Quickstart
408
370
 
409
371
  ### ${leadTarget.title}
410
372
 
411
373
  `)
412
- const LeadQuick =
413
- optionalComponent(ctx$, leadTarget, 'ReadmeTopQuick')
414
- if (LeadQuick) {
415
- LeadQuick['ReadmeTopQuick']({ target: leadTarget })
416
- }
417
- const placement = credentialPlacement(model)
418
- Content(`
374
+ const LeadQuick =
375
+ optionalComponent(ctx$, leadTarget, 'ReadmeTopQuick')
376
+ if (LeadQuick) {
377
+ LeadQuick['ReadmeTopQuick']({ target: leadTarget })
378
+ }
379
+ const placement = credentialPlacement(model)
380
+ Content(`
419
381
  ${'' === placement ? '' : placement + '\n\n'}See the [${leadTarget.title} README](${leadTarget.name}/README.md) for the full guide.
420
382
 
421
383
  `)
422
- }
384
+ }
385
+ })
423
386
 
424
- if (sdkTargets.length > 0 || hasCli || hasMcp || consumerTargets.length > 0) {
425
- Content(`## Surfaces
387
+
388
+ const ReadmeTopSurfaces = cmp(function ReadmeTopSurfaces(props: any) {
389
+ const { hasCli, hasMcp, sdkTargets, consumerTargets, langList } = props.s
390
+
391
+ if (sdkTargets.length > 0 || hasCli || hasMcp || consumerTargets.length > 0) {
392
+ Content(`## Surfaces
426
393
 
427
394
  | Surface | Path |
428
395
  | --- | --- |
429
396
  `)
430
- if (sdkTargets.length > 0) {
431
- const paths = sdkTargets.map((t: any) => `\`${t.name}/\``).join(' ')
432
- Content(`| **SDK** (${langList}) | ${paths} |
397
+ if (sdkTargets.length > 0) {
398
+ const paths = sdkTargets.map((t: any) => `\`${t.name}/\``).join(' ')
399
+ Content(`| **SDK** (${langList}) | ${paths} |
433
400
  `)
434
- }
435
- if (hasCli) {
436
- Content(`| **CLI** | \`go-cli/\` |
401
+ }
402
+ if (hasCli) {
403
+ Content(`| **CLI** | \`go-cli/\` |
437
404
  `)
438
- }
439
- if (hasMcp) {
440
- Content(`| **MCP server** | \`go-mcp/\` |
405
+ }
406
+ if (hasMcp) {
407
+ Content(`| **MCP server** | \`go-mcp/\` |
441
408
  `)
442
- }
443
- consumerTargets.forEach((t: any) => {
444
- Content(`| **${t.title}** | \`${t.name}/\` |
409
+ }
410
+ consumerTargets.forEach((t: any) => {
411
+ Content(`| **${t.title}** | \`${t.name}/\` |
445
412
  `)
446
- })
447
- Content(`
413
+ })
414
+ Content(`
448
415
  `)
449
- }
416
+ }
417
+ })
450
418
 
451
- if (hasMcp) {
452
- const mcpOps = mcpTools(model).map((tool) => tool.op)
453
- const mcpWrite = true === model.main?.[KIT]?.target?.['go-mcp']?.tool?.write
454
- const toggle = "`main: kit: target: 'go-mcp': tool: write: true`"
455
- const opText = mcpOps.length < 2 ? mcpOps.join('') :
456
- mcpOps.slice(0, -1).join(', ') + ' and ' + mcpOps[mcpOps.length - 1]
457
- // What the server reads and writes is what it registers, not the flag.
458
- const reads = mcpOps.some((op) => MCP_WRITE_OPS.includes(op)) ? '' : mcpWrite ?
459
- ' It only reads, as no entity has a create, update, patch or remove a plain call runs.' :
460
- ` It only reads: create, update, patch and remove become tools when the SDK's model sets
419
+
420
+ const ReadmeTopMcp = cmp(function ReadmeTopMcp(props: any) {
421
+ const { model, hasMcp } = props.s
422
+
423
+ if (hasMcp) {
424
+ const mcpOps = mcpTools(model).map((tool) => tool.op)
425
+ const mcpWrite = true === model.main?.[KIT]?.target?.['go-mcp']?.tool?.write
426
+ const toggle = "`main: kit: target: 'go-mcp': tool: write: true`"
427
+ const opText = mcpOps.length < 2 ? mcpOps.join('') :
428
+ mcpOps.slice(0, -1).join(', ') + ' and ' + mcpOps[mcpOps.length - 1]
429
+ // What the server reads and writes is what it registers, not the flag.
430
+ const reads = mcpOps.some((op) => MCP_WRITE_OPS.includes(op)) ? '' : mcpWrite ?
431
+ ' It only reads, as no entity has a create, update, patch or remove a plain call runs.' :
432
+ ` It only reads: create, update, patch and remove become tools when the SDK's model sets
461
433
  ${toggle}.`
462
- Content(0 === mcpOps.length ? `## Use it from an AI agent (MCP)
434
+ Content(0 === mcpOps.length ? `## Use it from an AI agent (MCP)
463
435
 
464
436
  The generated MCP server has no tools for this SDK: no entity has a list or
465
437
  load a plain call runs${mcpWrite ? ', or a create, update, patch or remove' :
466
- `, and create, update, patch and remove are off until the SDK's model sets
438
+ `, and create, update, patch and remove are off until the SDK's model sets
467
439
  ${toggle}`}.
468
440
 
469
441
  ` : `## Use it from an AI agent (MCP)
@@ -489,10 +461,15 @@ Then add it to your agent's MCP config (Claude Desktop, Cursor, etc.):
489
461
  \`\`\`
490
462
 
491
463
  `)
492
- }
464
+ }
465
+ })
493
466
 
494
- if (activeEntities.length > 0) {
495
- Content(`## Entities
467
+
468
+ const ReadmeTopEntities = cmp(function ReadmeTopEntities(props: any) {
469
+ const { activeEntities } = props.s
470
+
471
+ if (activeEntities.length > 0) {
472
+ Content(`## Entities
496
473
 
497
474
  The API exposes ${activeEntities.length === 1 ? 'one entity' : activeEntities.length + ' entities'}:
498
475
 
@@ -500,48 +477,56 @@ The API exposes ${activeEntities.length === 1 ? 'one entity' : activeEntities.le
500
477
  | --- | --- | --- |
501
478
  `)
502
479
 
503
- activeEntities.map((ent: any) => {
504
- const ops = ent.op || {}
505
- const opNames = Object.keys(ops).filter((o: string) => (ops as any)[o]?.active !== false)
506
- const entdesc = entityDesc[ent.name] || ent.short || ent.desc ||
507
- `The ${ent.Name} entity${opNames.length ? ' (' + opNames.join(', ') + ')' : ''}.`
508
- const path = entityPath(ent)
509
- Content(`| **${ent.Name}** | ${entdesc} | \`${path}\` |
480
+ activeEntities.map((ent: any) => {
481
+ const ops = ent.op || {}
482
+ const opNames = Object.keys(ops).filter((o: string) => (ops as any)[o]?.active !== false)
483
+ const entdesc = fact(ent, 'desc').cell ||
484
+ `The ${ent.Name} entity${opNames.length ? ' (' + opNames.join(', ') + ')' : ''}.`
485
+ const path = entityPath(ent)
486
+ Content(`| **${ent.Name}** | ${entdesc} | \`${path}\` |
510
487
  `)
511
- })
488
+ })
512
489
 
513
- const opUnion = new Set<string>()
514
- activeEntities.forEach((e: any) => Object.keys(e.op || {})
515
- .forEach((o: string) => { if ((e.op as any)[o]?.active !== false) opUnion.add(o) }))
516
- const opAvail = ['load', 'list', 'create', 'update', 'patch', 'remove'].filter((o) => opUnion.has(o))
517
- const opBold = (opAvail.length ? opAvail : ['load', 'list']).map((o) => '**' + o + '**').join(', ')
518
- Content(`
490
+ const opUnion = new Set<string>()
491
+ activeEntities.forEach((e: any) => Object.keys(e.op || {})
492
+ .forEach((o: string) => { if ((e.op as any)[o]?.active !== false) opUnion.add(o) }))
493
+ const opAvail = ['load', 'list', 'create', 'update', 'patch', 'remove'].filter((o) => opUnion.has(o))
494
+ const opBold = (opAvail.length ? opAvail : ['load', 'list']).map((o) => '**' + o + '**').join(', ')
495
+ Content(`
519
496
  The operations available across these entities are ${opBold} — see each entity's
520
497
  own list above for exactly which it supports.
521
498
 
522
499
  `)
523
- }
500
+ }
501
+ })
502
+
503
+
504
+ const ReadmeTopOtherLanguages = cmp(function ReadmeTopOtherLanguages(props: any) {
505
+ const { ctx$, sdkTargets, leadTarget } = props.s
524
506
 
525
- const otherTargets = sdkTargets.filter((t: any) => leadTarget && t.name !== leadTarget.name)
526
- if (otherTargets.length > 0) {
527
- Content(`## Quickstart in other languages
507
+ const otherTargets = sdkTargets.filter((t: any) => leadTarget && t.name !== leadTarget.name)
508
+ if (otherTargets.length > 0) {
509
+ Content(`## Quickstart in other languages
528
510
 
529
511
  `)
530
- otherTargets.forEach((tgt: any) => {
531
- const Quick =
532
- optionalComponent(ctx$, tgt, 'ReadmeTopQuick')
533
- if (Quick) {
534
- Content(`### ${tgt.title}
512
+ otherTargets.forEach((tgt: any) => {
513
+ const Quick =
514
+ optionalComponent(ctx$, tgt, 'ReadmeTopQuick')
515
+ if (Quick) {
516
+ Content(`### ${tgt.title}
535
517
 
536
518
  `)
537
- Quick['ReadmeTopQuick']({ target: tgt })
538
- Content(`
519
+ Quick['ReadmeTopQuick']({ target: tgt })
520
+ Content(`
539
521
  `)
540
- }
541
- })
542
- }
522
+ }
523
+ })
524
+ }
525
+ })
543
526
 
544
- Content(`## Direct and prepare
527
+
528
+ const ReadmeTopDirect = cmp(function ReadmeTopDirect() {
529
+ Content(`## Direct and prepare
545
530
 
546
531
  For endpoints the entity model doesn't cover, use the low-level methods:
547
532
 
@@ -552,8 +537,13 @@ Both accept a map with \`path\`, \`method\`, \`params\`, \`query\`,
552
537
  \`headers\`, and \`body\`. See the [How-to guides](#how-to-guides) below.
553
538
 
554
539
  `)
540
+ })
541
+
542
+
543
+ const ReadmeTopHowtoGuides = cmp(function ReadmeTopHowtoGuides(props: any) {
544
+ const { ctx$, sdkTargets } = props.s
555
545
 
556
- Content(`## How-to guides
546
+ Content(`## How-to guides
557
547
 
558
548
  ### Make a direct API call
559
549
 
@@ -561,70 +551,79 @@ When the entity interface does not cover an endpoint, use \`direct\`:
561
551
 
562
552
  `)
563
553
 
564
- sdkTargets.forEach((tgt: any) => {
565
- const Howto =
566
- optionalComponent(ctx$, tgt, 'ReadmeTopHowto')
567
- if (Howto) {
568
- Howto['ReadmeTopHowto']({ target: tgt })
569
- }
570
- })
554
+ sdkTargets.forEach((tgt: any) => {
555
+ const Howto =
556
+ optionalComponent(ctx$, tgt, 'ReadmeTopHowto')
557
+ if (Howto) {
558
+ Howto['ReadmeTopHowto']({ target: tgt })
559
+ }
560
+ })
561
+ })
562
+
563
+
564
+ const ReadmeTopAdvanced = cmp(function ReadmeTopAdvanced(props: any) {
565
+ const { feature } = props.s
571
566
 
572
- Content(`## Advanced
567
+ Content(`## Advanced
573
568
 
574
569
  > Everyday use only needs the sections above. This explains the internals
575
570
  > behind every call — relevant when writing custom features.
576
571
 
577
- Every SDK call runs the same five-stage pipeline:
572
+ Every entity operation runs the same ${pipelineLength()}-stage pipeline:
578
573
 
579
- 1. **Point** — resolve the API endpoint from the operation definition.
580
- 2. **Spec** — build the HTTP specification (URL, method, headers, body).
581
- 3. **Request** — send the HTTP request.
582
- 4. **Response** — receive and parse the response.
583
- 5. **Result** — extract the result data for the caller.
574
+ ${PIPELINE_STAGES.map((s, i) => (i + 1) + '. **' + s.name + '** — ' + s.purpose).join('\n')}
584
575
 
585
- A feature hook fires at each stage (e.g. \`PrePoint\`, \`PreSpec\`,
586
- \`PreRequest\`), so features can inspect or modify the pipeline without
576
+ A feature hook fires before each stage (e.g. \`${PIPELINE_STAGES[0].hook}\`, \`${PIPELINE_STAGES[1].hook}\`,
577
+ \`${PIPELINE_STAGES[2].hook}\`), so features can inspect or modify the pipeline without
587
578
  forking the SDK.
588
579
 
589
- ### Features
590
-
591
580
  `)
592
581
 
593
- Content(`| Feature | Purpose |
582
+ const active = each(feature).filter((feat: any) => feat.active)
583
+ if (0 < active.length) {
584
+ Content(`### Features
585
+
586
+ | Feature | Purpose |
594
587
  | --- | --- |
595
588
  `)
596
- each(feature, (feat: any) => {
597
- if (!feat.active) return
598
- const purpose = feat.title || feat.Name || feat.name
589
+ for (const feat of active) {
590
+ const purpose = fact(feat, 'title').cell || feat.Name || feat.name
599
591
  Content(`| **${feat.Name || feat.name}Feature** | ${purpose} |
600
592
  `)
601
- })
602
-
593
+ }
603
594
  Content(`
604
- Pass custom features via the \`extend\` option at construction time.
595
+ `)
596
+ }
597
+
598
+ Content(`Pass custom features via the \`extend\` option at construction time.
605
599
 
606
600
  `)
601
+ })
607
602
 
608
- // 11c. Customization: model-driven declarations, in-repo templates and
609
- // components, regeneration that overwrites, customising in `.sdk`, and a
610
- // map of which paths are the project's to edit. Every SDK repo carries
611
- // its own generator, so this belongs in every README. A repository that
612
- // regenerates `.sdk` in full says so, since its copies do not merge.
613
- const mapTarget = sdkTargets[0] || docTargets[0]
614
- const targetDir = mapTarget ? `\`<target>/\`, such as \`${mapTarget.name}/\`` : `\`<target>/\``
615
- const merging = 'overwrite' !== model.main?.kit?.copies
616
- const mergeNote = merging ?
617
- `An add merges toolchain updates into the
603
+
604
+ const ReadmeTopCustomizing = cmp(function ReadmeTopCustomizing(props: any) {
605
+ const { model, sdkTargets, docTargets } = props.s
606
+
607
+ // 11c. Customization: model-driven declarations, in-repo templates and
608
+ // components, regeneration that overwrites, customising in `.sdk`, and a
609
+ // map of which paths are the project's to edit. Every SDK repo carries
610
+ // its own generator, so this belongs in every README. A repository that
611
+ // regenerates `.sdk` in full says so, since its copies do not merge.
612
+ const mapTarget = sdkTargets[0] || docTargets[0]
613
+ const targetDir = mapTarget ? `\`<target>/\`, such as \`${mapTarget.name}/\`` : `\`<target>/\``
614
+ const merging = MERGE === copyMode(model.main?.[KIT]?.copies)
615
+ const mergeNote = merging ?
616
+ `An add merges toolchain updates into the
618
617
  edited copies, and \`voxgig-sdkgen doctor\` reports any drift from what a
619
618
  resync would write.` :
620
- `This repository regenerates \`.sdk\` in full
619
+ `This repository regenerates \`.sdk\` in full
621
620
  (\`main: kit: copies: 'overwrite'\`): set it to \`'merge'\` before
622
621
  customising, so that an add merges toolchain updates into the edited
623
622
  copies.`
624
- const copiesRow = merging ?
625
- `Yes. They are this project's copies, and \`target add\` merges toolchain updates into your edits.` :
626
- `Only after setting \`copies\` to \`'merge'\`. This repository regenerates them in full.`
627
- Content(`## Customizing this SDK
623
+ const copiesRow = merging ?
624
+ `Yes. They are this project's copies, and \`target add\` merges toolchain updates into your edits.` :
625
+ `Only after setting \`copies\` to \`'merge'\`. This repository regenerates them in full.`
626
+ Content(`## Customizing this SDK
628
627
 
629
628
  This repository contains its own generator (\`.sdk/\`), so the SDK is
630
629
  customizable without forking any upstream tool:
@@ -681,23 +680,31 @@ How-to: [customize and propagate templates](https://github.com/voxgig/sdkgen/blo
681
680
  The full story: [voxgig.com/sdk/custom](https://voxgig.com/sdk/custom).
682
681
 
683
682
  `)
683
+ })
684
+
685
+
686
+ const ReadmeTopPerLanguage = cmp(function ReadmeTopPerLanguage(props: any) {
687
+ const { docTargets } = props.s
684
688
 
685
- if (docTargets.length > 0) {
686
- Content(`## Per-language documentation
689
+ if (docTargets.length > 0) {
690
+ Content(`## Per-language documentation
687
691
 
688
692
  `)
689
- docTargets.forEach((tgt: any) => {
690
- Content(`- [${tgt.title}](${tgt.name}/README.md)
693
+ docTargets.forEach((tgt: any) => {
694
+ Content(`- [${tgt.title}](${tgt.name}/README.md)
691
695
  `)
692
- })
693
- Content(`
696
+ })
697
+ Content(`
694
698
  `)
695
- }
699
+ }
700
+ })
701
+
696
702
 
697
- const upstreamUrl = (info.contact && info.contact.url)
698
- || (info.servers && info.servers[0] && info.servers[0].url)
699
- || homepage
700
- Content(`## Upstream API
703
+ const ReadmeTopUpstream = cmp(function ReadmeTopUpstream(props: any) {
704
+ const { text } = props.s
705
+ const upstream = text.upstream
706
+ const docs = text.docs_url
707
+ Content(`## Upstream API
701
708
 
702
709
  This SDK is generated from the upstream OpenAPI specification. It is an
703
710
  unofficial client and is not affiliated with the API provider.
@@ -706,37 +713,171 @@ The OpenAPI spec(s) this SDK was generated from are kept in the
706
713
  [\`.sdk/def/\`](.sdk/def/) folder.
707
714
 
708
715
  `)
709
- if (upstreamUrl) {
710
- // A per-tenant server URL carries an OpenAPI server variable —
711
- // `https://{instance}.dreamapply.com/api` — and is the right thing to
712
- // SHOW, because it tells the reader the host is theirs to fill in. It is
713
- // not a thing to LINK: the braces are not a resolvable address, so a
714
- // markdown link renders as clickable and dead. Show it as code instead.
715
- const templated = /[{}]/.test(upstreamUrl)
716
- Content(templated
717
- ? `- Upstream API: \`${upstreamUrl}\`
716
+ if (upstream.raw) {
717
+ // A per-tenant server URL carries an OpenAPI server variable —
718
+ // `https://{instance}.dreamapply.com/api` — and is the right thing to
719
+ // SHOW, because it tells the reader the host is theirs to fill in. It is
720
+ // not a thing to LINK: the braces are not a resolvable address, so a
721
+ // markdown link renders as clickable and dead. Show it as code instead.
722
+ const templated = /[{}]/.test(upstream.raw)
723
+ Content(templated
724
+ ? `- Upstream API: ${upstream.code}
718
725
  `
719
- : `- Upstream API: [${upstreamUrl}](${upstreamUrl})
726
+ : `- Upstream API: [${upstream.inline}](${upstream.link})
720
727
  `)
721
- }
722
- if (docsUrl && docsUrl !== upstreamUrl) {
723
- Content(`- Documentation: [${docsUrl}](${docsUrl})
728
+ }
729
+ if (docs.raw && docs.raw !== upstream.raw) {
730
+ Content(`- Documentation: [${docs.inline}](${docs.link})
724
731
  `)
725
- }
726
- Content(`
732
+ }
733
+ Content(`
727
734
  `)
735
+ })
736
+
728
737
 
729
- Content(`## Security
738
+ const ReadmeTopSecurity = cmp(function ReadmeTopSecurity(props: any) {
739
+ const { model } = props.s
740
+
741
+ Content(`## Security
730
742
 
731
743
  Please report security issues ${securityContact(model)}. See [SECURITY.md](SECURITY.md).
732
744
  Do not open public issues for suspected vulnerabilities.
733
745
 
734
746
  `)
747
+ })
748
+
749
+
750
+ const ReadmeTopFooter = cmp(function ReadmeTopFooter(props: any) {
751
+ const { productName } = props.s
735
752
 
736
- Content(`---
753
+ Content(`---
737
754
 
738
755
  Generated from the ${productName} OpenAPI spec by [@voxgig/sdkgen](${SDKGEN_REPO}).
739
756
  `)
757
+ })
758
+
759
+
760
+ const ReadmeTop = cmp(function ReadmeTop(props: any) {
761
+ const { ctx$ } = props
762
+ const { model } = ctx$
763
+
764
+ if (model.name && !model.Name) names(model, model.name)
765
+
766
+ const info = modelText(model)
767
+ const def = (model.main && model.main.def) || {}
768
+
769
+ const text = fact(model.main[KIT], 'text')
770
+
771
+ const productName = text.title.inline || `${model.Name} API`
772
+
773
+ const tagline = text.tagline.inline
774
+ || `${productName} client, generated from the OpenAPI spec.`
775
+
776
+ const aboutMd = text.about_md.text
777
+
778
+ const apiSummary = text.summary.inline
779
+ const websiteLine = text.website.raw
780
+ ? `Learn more about ${productName} at [${text.website.label}](${text.website.link}).`
781
+ : ''
782
+
783
+ // Attribution for API metadata sourced from a third-party catalogue (e.g.
784
+ // freepublicapis.com). Rendered only when the model carries an
785
+ // `info.meta_source` URL, so first-party SDKs never show it. The link points
786
+ // back to the catalogue that kindly supplied the metadata.
787
+ const metaSourceLine = text.meta_source.raw
788
+ ? `Metadata kindly supplied by [${text.meta_source.label}](${text.meta_source.link}).`
789
+ : ''
790
+
791
+ const entity = getModelPath(model, `main.${KIT}.entity`)
792
+ const target = getModelPath(model, `main.${KIT}.target`)
793
+ const feature = getModelPath(model, `main.${KIT}.feature`)
794
+
795
+ each(entity, (ent: any) => { if (!ent.Name) names(ent, ent.name) })
796
+ each(feature, (feat: any) => { if (!feat.Name) names(feat, feat.name) })
797
+
798
+ const activeEntities = each(entity).filter((e: any) => e.active !== false)
799
+ const activeTargets = each(target).filter((t: any) => t.active !== false)
800
+
801
+ const hasCli = activeTargets.some((t: any) => t.name === 'go-cli')
802
+ const hasMcp = activeTargets.some((t: any) => t.name === 'go-mcp')
803
+
804
+
805
+ const docsOrder: string[] = (getModelPath(model, `main.${KIT}.config.docs_order`,
806
+ { only_active: false, required: false }) as any) || []
807
+
808
+ const orderOf = (name: string): number => {
809
+ const i = docsOrder.indexOf(name)
810
+ if (i !== -1) return i
811
+ if (name === 'go-cli') return docsOrder.length + 1
812
+ if (name === 'go-mcp') return docsOrder.length + 2
813
+ return docsOrder.length
814
+ }
815
+
816
+ const ordered = activeTargets
817
+ .slice()
818
+ .sort((a: any, b: any) => orderOf(a.name) - orderOf(b.name))
819
+
820
+ const isCliOrMcp = (t: any) => t.name === 'go-cli' || t.name === 'go-mcp'
821
+
822
+ const sdkTargets = ordered.filter((t: any) => !isConsumer(t))
823
+
824
+ // The CLI and the MCP server have surfaces of their own below.
825
+ const consumerTargets = ordered.filter((t: any) => isConsumer(t) && !isCliOrMcp(t))
826
+
827
+ const docTargets = ordered.filter((t: any) => !isCliOrMcp(t))
828
+
829
+ const pkgTargets = activeTargets
830
+ .filter((t: any) => hasPackageName(model, t.name))
831
+ .sort((a: any, b: any) => orderOf(a.name) - orderOf(b.name))
832
+
833
+ const langList = sdkTargets.map((t: any) => t.title).join(', ')
834
+ const leadTarget = pickLeadTarget(sdkTargets)
835
+
836
+ const s = {
837
+ model,
838
+ ctx$,
839
+ info,
840
+ def,
841
+ text,
842
+ productName,
843
+ tagline,
844
+ aboutMd,
845
+ apiSummary,
846
+ websiteLine,
847
+ metaSourceLine,
848
+ feature,
849
+ activeEntities,
850
+ hasCli,
851
+ hasMcp,
852
+ sdkTargets,
853
+ consumerTargets,
854
+ docTargets,
855
+ pkgTargets,
856
+ langList,
857
+ leadTarget,
858
+ }
859
+
860
+ File({ name: 'README.md' }, () => {
861
+ ReadmeTopTitle({ s })
862
+ ReadmeTopSurfaceLine({ s })
863
+ ReadmeTopFeatureLine({ s })
864
+ ReadmeTopAbout({ s })
865
+ ReadmeTopEntityModel({ s })
866
+ ReadmeTopTesting({ s })
867
+ ReadmeTopPackages({ s })
868
+ ReadmeTopQuickstart({ s })
869
+ ReadmeTopSurfaces({ s })
870
+ ReadmeTopMcp({ s })
871
+ ReadmeTopEntities({ s })
872
+ ReadmeTopOtherLanguages({ s })
873
+ ReadmeTopDirect({ s })
874
+ ReadmeTopHowtoGuides({ s })
875
+ ReadmeTopAdvanced({ s })
876
+ ReadmeTopCustomizing({ s })
877
+ ReadmeTopPerLanguage({ s })
878
+ ReadmeTopUpstream({ s })
879
+ ReadmeTopSecurity({ s })
880
+ ReadmeTopFooter({ s })
740
881
  })
741
882
  })
742
883