@voxgig/sdkgen 4.42.0 → 4.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/action/feature.js +16 -0
- package/dist/action/feature.js.map +1 -1
- package/dist/action/kind.js +3 -0
- package/dist/action/kind.js.map +1 -1
- package/dist/action/remove.js +4 -0
- package/dist/action/remove.js.map +1 -1
- package/dist/action/resolve.d.ts +1 -0
- package/dist/action/resolve.js +30 -0
- package/dist/action/resolve.js.map +1 -1
- package/dist/action/target.js +10 -4
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/AgentGuideContent.js +12 -6
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +21 -6
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +23 -9
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +17 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +5 -4
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/ReadmeIntro_c.ts +6 -25
- package/project/.sdk/src/cmp/clojure/ReadmeIntro_clojure.ts +6 -25
- package/project/.sdk/src/cmp/cpp/ReadmeIntro_cpp.ts +6 -25
- package/project/.sdk/src/cmp/csharp/ReadmeIntro_csharp.ts +6 -25
- package/project/.sdk/src/cmp/elixir/ReadmeIntro_elixir.ts +6 -25
- package/project/.sdk/src/cmp/go/ReadmeIntro_go.ts +7 -37
- package/project/.sdk/src/cmp/java/ReadmeIntro_java.ts +6 -25
- package/project/.sdk/src/cmp/js/ReadmeIntro_js.ts +6 -25
- package/project/.sdk/src/cmp/kotlin/ReadmeIntro_kotlin.ts +6 -25
- package/project/.sdk/src/cmp/lua/ReadmeIntro_lua.ts +6 -25
- package/project/.sdk/src/cmp/ocaml/ReadmeIntro_ocaml.ts +6 -25
- package/project/.sdk/src/cmp/perl/ReadmeIntro_perl.ts +6 -25
- package/project/.sdk/src/cmp/php/ReadmeIntro_php.ts +6 -25
- package/project/.sdk/src/cmp/py/ReadmeIntro_py.ts +6 -25
- package/project/.sdk/src/cmp/rb/ReadmeIntro_rb.ts +6 -25
- package/project/.sdk/src/cmp/rust/ReadmeIntro_rust.ts +6 -25
- package/project/.sdk/src/cmp/scala/ReadmeIntro_scala.ts +6 -25
- package/project/.sdk/src/cmp/swift/ReadmeIntro_swift.ts +6 -25
- package/project/.sdk/src/cmp/ts/ReadmeIntro_ts.ts +6 -36
- package/project/.sdk/src/cmp/zig/ReadmeIntro_zig.ts +6 -25
- package/project/sdkgen-package.json +1 -1
- package/src/action/feature.ts +20 -0
- package/src/action/kind.ts +4 -0
- package/src/action/remove.ts +4 -0
- package/src/action/resolve.ts +41 -0
- package/src/action/target.ts +11 -4
- package/src/cmp/AgentGuideContent.ts +12 -6
- package/src/cmp/ReadmeIntro.ts +22 -8
- package/src/cmp/ReadmeTop.ts +23 -9
- package/src/helpers/opShape.ts +17 -0
- package/src/sdkgen.ts +2 -1
package/src/action/resolve.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { getelem } from '@voxgig/struct'
|
|
|
6
6
|
|
|
7
7
|
import { KIT } from '../types'
|
|
8
8
|
|
|
9
|
+
import { SdkGenError } from '../utility'
|
|
10
|
+
|
|
9
11
|
import { definitionPathAny } from '../helpers/definition'
|
|
10
12
|
import { readManifest, checkShape, ITEM_NAME_RE } from '../helpers/manifest'
|
|
11
13
|
|
|
@@ -33,6 +35,10 @@ type Source = {
|
|
|
33
35
|
|
|
34
36
|
// That package's version, read from the same manifest.
|
|
35
37
|
version?: string
|
|
38
|
+
|
|
39
|
+
// Defined in the project's own `.sdk` and provided by nothing else, so the
|
|
40
|
+
// project's files ARE the source: an add registers it and copies nothing.
|
|
41
|
+
owned?: boolean
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
|
|
@@ -109,6 +115,27 @@ function resolveSource(ref: string, kind: string, ctx$: any): Source {
|
|
|
109
115
|
capitalise(kind) + ' folder not found in:\n' + search.join('\n '))
|
|
110
116
|
}
|
|
111
117
|
|
|
118
|
+
if (insideProject(root, folder)) {
|
|
119
|
+
throw new SdkGenError(
|
|
120
|
+
capitalise(kind) + ' source ' + folder + ' is inside this project.' +
|
|
121
|
+
'\n A project\'s own ' + kind + ' lives in its .sdk: define it in ' +
|
|
122
|
+
'model/' + kind + '/' + origname + '.aontu, put its sources under tm/ ' +
|
|
123
|
+
'(and src/cmp/ for a target), and add it by name.' +
|
|
124
|
+
'\n A package is for sharing ' + kind + 's between projects: install ' +
|
|
125
|
+
'it from npm, or add it from a checkout outside the project.')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const ownmodel = definitionPathAny(fs, root, kind, origname)
|
|
129
|
+
if (name === origname &&
|
|
130
|
+
Path.normalize(folder) === Path.normalize(Path.join(root, BUNDLED)) &&
|
|
131
|
+
!fs.existsSync(definitionPathAny(fs, folder, kind, origname)) &&
|
|
132
|
+
fs.existsSync(ownmodel)) {
|
|
133
|
+
return {
|
|
134
|
+
name, origname, folder: Path.normalize(root), base: '.', model: ownmodel,
|
|
135
|
+
owned: true,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
112
139
|
// `base` is the folder relative to the project root. Compare with the
|
|
113
140
|
// PLATFORM separator: on Windows `root + '/'` never prefixes a normalised
|
|
114
141
|
// absolute path, so the root would not be stripped and `base` would stay
|
|
@@ -138,6 +165,20 @@ function resolveSource(ref: string, kind: string, ctx$: any): Source {
|
|
|
138
165
|
}
|
|
139
166
|
|
|
140
167
|
|
|
168
|
+
// A package folder beside `.sdk` in the same project, such as an `ext/`:
|
|
169
|
+
// the project's own items belong in `.sdk` itself.
|
|
170
|
+
function insideProject(root: string, folder: string): boolean {
|
|
171
|
+
const sdk = Path.resolve(root)
|
|
172
|
+
if ('.sdk' !== Path.basename(sdk)) {
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const abs = Path.resolve(folder)
|
|
177
|
+
return abs.startsWith(Path.dirname(sdk) + Path.sep) &&
|
|
178
|
+
!abs.startsWith(Path.join(sdk, 'node_modules') + Path.sep)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
141
182
|
function sourcePackage(
|
|
142
183
|
fs: any, folder: string, kind: string, origname: string, ctx$: any,
|
|
143
184
|
): { name: string, version?: string } | undefined {
|
package/src/action/target.ts
CHANGED
|
@@ -175,8 +175,8 @@ const TargetRoot = cmp(function TargetRoot(props: any) {
|
|
|
175
175
|
const dryrun = !!actx?.opts?.dryrun
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
// `feature add`
|
|
179
|
-
//
|
|
178
|
+
// `feature add` copies nothing for a feature it cannot resolve or that the
|
|
179
|
+
// project defines itself, so the prune must not delete those files first.
|
|
180
180
|
const unresolved = unresolvedFeatures(features ?? [], ctx$)
|
|
181
181
|
|
|
182
182
|
Project({}, () => {
|
|
@@ -221,6 +221,14 @@ const TargetRoot = cmp(function TargetRoot(props: any) {
|
|
|
221
221
|
content: ctx$.meta.content.target_index,
|
|
222
222
|
}))
|
|
223
223
|
|
|
224
|
+
if (source.owned) {
|
|
225
|
+
log.info({
|
|
226
|
+
point: 'target-owned', target: tname,
|
|
227
|
+
note: tname + ': defined in this project, so its files stay as they are'
|
|
228
|
+
})
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
|
|
224
232
|
if (aliased) {
|
|
225
233
|
aliasCmpTree(ctx$, tfolder + '/src/cmp/' + torigname,
|
|
226
234
|
'src/cmp/' + tname, torigname, tname)
|
|
@@ -354,8 +362,7 @@ function aliasCmpTree(
|
|
|
354
362
|
function unresolvedFeatures(features: string[], ctx$: any): string[] {
|
|
355
363
|
return features.filter((fname: string) => {
|
|
356
364
|
try {
|
|
357
|
-
resolveKind(fname, 'feature', ctx$)
|
|
358
|
-
return false
|
|
365
|
+
return true === resolveKind(fname, 'feature', ctx$).owned
|
|
359
366
|
}
|
|
360
367
|
catch (err: any) {
|
|
361
368
|
return true
|
|
@@ -194,18 +194,24 @@ npm run add-feature <name> # e.g. log (comma-separated for several)
|
|
|
194
194
|
npm run build && npm run generate
|
|
195
195
|
\`\`\`
|
|
196
196
|
|
|
197
|
-
To author a **new** feature:
|
|
197
|
+
To author a **new** feature, when editing a template cannot make the change:
|
|
198
198
|
|
|
199
199
|
1. Define its model at \`.sdk/model/feature/<name>.aontu\` — \`name: key()\`,
|
|
200
200
|
\`title\`, \`version\`, \`active\`, \`config.options.active\`, a \`hook\`
|
|
201
201
|
map (\`<Stage>: active: true\`), and per-language \`deps\`.
|
|
202
|
-
2.
|
|
203
|
-
\`@"<name>.aontu"\`.
|
|
204
|
-
3. Provide the per-language runtime under that target's feature template dir
|
|
202
|
+
2. Provide the per-language runtime under that target's feature template dir
|
|
205
203
|
(\`.sdk/tm/<lang>/src/feature/<name>/\` for ts/js, \`.sdk/tm/<lang>/feature/\`
|
|
206
204
|
otherwise) — the \`FEATURE_Name\` / \`FEATURE_VERSION\` placeholders are
|
|
207
|
-
substituted
|
|
208
|
-
|
|
205
|
+
substituted when \`generate\` copies it.
|
|
206
|
+
3. \`npm run add-feature <name> && npm run build && npm run generate\`. No
|
|
207
|
+
package provides the name, so the add registers the feature in
|
|
208
|
+
\`feature-index.aontu\` and copies nothing: the files in \`.sdk\` are its
|
|
209
|
+
source.
|
|
210
|
+
|
|
211
|
+
A target of the project's own is written the same way:
|
|
212
|
+
\`.sdk/model/target/<name>.aontu\`, \`.sdk/src/cmp/<name>/\` and
|
|
213
|
+
\`.sdk/tm/<name>/\`, then \`npm run add-target <name>\`. Never put a package
|
|
214
|
+
folder such as \`ext/\` inside the project: sdkgen refuses it.
|
|
209
215
|
`
|
|
210
216
|
}
|
|
211
217
|
|
package/src/cmp/ReadmeIntro.ts
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { Content } from 'jostraca'
|
|
3
3
|
|
|
4
|
+
import { cmp } from '../helpers/component'
|
|
4
5
|
import { optionalComponent } from '../helpers/optional'
|
|
6
|
+
import { modelText } from '../helpers/text'
|
|
7
|
+
import { alongsideNote } from '../helpers/alongside'
|
|
5
8
|
|
|
6
9
|
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
+
// Every language README opens the same way: the title and tagline, the
|
|
11
|
+
// target's own ReadmeIntroBody, then the note naming the rest of the project.
|
|
12
|
+
// A component exporting a whole ReadmeIntro (a project's copy from before this
|
|
13
|
+
// frame, or a pack not yet moved to it) still writes its own introduction.
|
|
10
14
|
const ReadmeIntro = cmp(function ReadmeIntro(props: any) {
|
|
11
15
|
const { target, ctx$ } = props
|
|
16
|
+
const { model } = ctx$
|
|
12
17
|
|
|
13
|
-
const
|
|
14
|
-
|
|
18
|
+
const intro = optionalComponent(ctx$, target, 'ReadmeIntro')
|
|
19
|
+
if (null == intro) return
|
|
15
20
|
|
|
16
|
-
if (
|
|
17
|
-
|
|
21
|
+
if (null == intro.ReadmeIntroBody) {
|
|
22
|
+
intro.ReadmeIntro({ target })
|
|
23
|
+
return
|
|
18
24
|
}
|
|
25
|
+
|
|
26
|
+
Content(`# ${model.Name} ${target.title} SDK
|
|
27
|
+
|
|
28
|
+
${modelText(model).tagline || ''}
|
|
29
|
+
|
|
30
|
+
`)
|
|
31
|
+
intro.ReadmeIntroBody({ target })
|
|
32
|
+
Content(alongsideNote(model, target.name))
|
|
19
33
|
})
|
|
20
34
|
|
|
21
35
|
|
package/src/cmp/ReadmeTop.ts
CHANGED
|
@@ -605,11 +605,24 @@ Pass custom features via the \`extend\` option at construction time.
|
|
|
605
605
|
`)
|
|
606
606
|
|
|
607
607
|
// 11c. Customization: model-driven declarations, in-repo templates and
|
|
608
|
-
// components, regeneration that overwrites,
|
|
609
|
-
// paths are the project's to edit. Every SDK repo carries
|
|
610
|
-
// generator, so this belongs in every README.
|
|
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.
|
|
611
612
|
const mapTarget = sdkTargets[0] || docTargets[0]
|
|
612
613
|
const targetDir = mapTarget ? `\`<target>/\`, such as \`${mapTarget.name}/\`` : `\`<target>/\``
|
|
614
|
+
const merging = 'overwrite' !== model.main?.kit?.copies
|
|
615
|
+
const mergeNote = merging ?
|
|
616
|
+
`An add merges toolchain updates into the
|
|
617
|
+
edited copies, and \`voxgig-sdkgen doctor\` reports any drift from what a
|
|
618
|
+
resync would write.` :
|
|
619
|
+
`This repository regenerates \`.sdk\` in full
|
|
620
|
+
(\`main: kit: copies: 'overwrite'\`): set it to \`'merge'\` before
|
|
621
|
+
customising, so that an add merges toolchain updates into the edited
|
|
622
|
+
copies.`
|
|
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.`
|
|
613
626
|
Content(`## Customizing this SDK
|
|
614
627
|
|
|
615
628
|
This repository contains its own generator (\`.sdk/\`), so the SDK is
|
|
@@ -630,10 +643,11 @@ customizable without forking any upstream tool:
|
|
|
630
643
|
(\`.sdk/model/project.aontu\`), or extend a target with a component of its
|
|
631
644
|
own in \`.sdk/src/cmp/<target>/\`, registered with \`registerComponent\`,
|
|
632
645
|
which \`voxgig-sdkgen doctor\` reports as an addition rather than drift.
|
|
633
|
-
- **
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
646
|
+
- **Customise in \`.sdk\`.** Edit the templates and components first. When
|
|
647
|
+
they cannot express a change, write a feature of this project's own, or
|
|
648
|
+
an entire custom target, in \`.sdk/model/\`, \`.sdk/tm/\` and
|
|
649
|
+
\`.sdk/src/cmp/\`, and add it by name (\`voxgig-sdkgen feature add\`,
|
|
650
|
+
\`voxgig-sdkgen target add\`). ${mergeNote}
|
|
637
651
|
|
|
638
652
|
### Project map
|
|
639
653
|
|
|
@@ -642,9 +656,9 @@ customizable without forking any upstream tool:
|
|
|
642
656
|
| \`.sdk/model/project.aontu\` | This project's own decisions: package names, versions, features and per-target settings | Yes. The scaffold writes it once and never again. |
|
|
643
657
|
| \`.sdk/model/text.aontu\` | The README wording, in \`main.kit.text\`: the tagline, the summary and the entity descriptions | Yes. The scaffold writes it once and never again. |
|
|
644
658
|
| \`.sdk/model/guide/guide.aontu\` | How the spec's paths map onto entities and operations | Yes. The scaffold writes it once and never again. |
|
|
645
|
-
| \`.sdk/model/\`, the rest | The API model built from the spec, and the target and feature definitions | Not by hand. Generation, \`target add\` and a new scaffold run rewrite it. |
|
|
659
|
+
| \`.sdk/model/\`, the rest | The API model built from the spec, and the target and feature definitions | Not by hand. Generation, \`target add\` and a new scaffold run rewrite it, apart from a feature or target this project defines itself. |
|
|
646
660
|
| \`.sdk/def/\` | The OpenAPI spec | Replace it when the API changes. Generation rebuilds the model from it. |
|
|
647
|
-
| \`.sdk/src/cmp/<target>/\`, \`.sdk/tm/<target>/\` | The components and templates that generate each target |
|
|
661
|
+
| \`.sdk/src/cmp/<target>/\`, \`.sdk/tm/<target>/\` | The components and templates that generate each target | ${copiesRow} |
|
|
648
662
|
| \`.sdk/test/\` | The shared test cases the generated tests run | No. |
|
|
649
663
|
| ${targetDir} | One generated SDK per target, with its own tests | No. Generation overwrites it. |
|
|
650
664
|
| \`README.md\`, \`LICENSE\`, \`Makefile\` and the other root files | The repository's generated files | No. Generation overwrites them. |
|
package/src/helpers/opShape.ts
CHANGED
|
@@ -415,6 +415,22 @@ function entityOps(ent: any): string[] {
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
|
|
418
|
+
// Unlike entityOps, keeps action-only ops: the README introductions always have.
|
|
419
|
+
function introOps(model: any): string[] {
|
|
420
|
+
const entity = model?.main?.[KIT]?.entity || {}
|
|
421
|
+
const found = new Set<string>()
|
|
422
|
+
for (const e of Object.values(entity) as any[]) {
|
|
423
|
+
if (!e || false === e.active) continue
|
|
424
|
+
for (const o of Object.keys(e.op || {})) {
|
|
425
|
+
if (e.op[o] && false !== e.op[o].active) found.add(o)
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
const names = CANON_OP_ORDER.filter((o) => found.has(o))
|
|
429
|
+
.concat([...found].filter((o) => !CANON_OP_ORDER.includes(o)))
|
|
430
|
+
return 0 < names.length ? names : ['list', 'load']
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
418
434
|
type UngeneratedOp = { entity: string, op: string, points: string[] }
|
|
419
435
|
|
|
420
436
|
|
|
@@ -779,6 +795,7 @@ export {
|
|
|
779
795
|
entityDataIdField,
|
|
780
796
|
entityRecordIdField,
|
|
781
797
|
entityOps,
|
|
798
|
+
introOps,
|
|
782
799
|
invalidRequest,
|
|
783
800
|
entityPrimaryOp,
|
|
784
801
|
pickExampleEntity,
|
package/src/sdkgen.ts
CHANGED
|
@@ -71,7 +71,7 @@ import type { DepEntry } from './helpers/collectDeps'
|
|
|
71
71
|
import { canonToType, canonToDtype, canonKey, canonScalarKey } from './helpers/canonType'
|
|
72
72
|
import { canonToSpec, entityDataSpec, entityOpSpec, entitySpecs, validateSeeds } from './helpers/canonSpec'
|
|
73
73
|
import { optionSpec, featureOptionSpec, entitySpecMap } from './helpers/optspec'
|
|
74
|
-
import { OP_SUFFIX, opTypeName, opParams, opReachable, opNeedsAction, ownPoint, opActions, entityActions, entityPath, opRequestShape, entityIdField, entityDataIdField, entityRecordIdField, entityOps, invalidRequest, entityPrimaryOp, pickExampleEntity, entityClassName, entityConstructorName, entityTypeCollisions, warnEntityTypeCollisions, ungeneratedOps, warnUngeneratedOps, deriveEntityNames, entityCollection } from './helpers/opShape'
|
|
74
|
+
import { OP_SUFFIX, opTypeName, opParams, opReachable, opNeedsAction, ownPoint, opActions, entityActions, entityPath, opRequestShape, entityIdField, entityDataIdField, entityRecordIdField, entityOps, introOps, invalidRequest, entityPrimaryOp, pickExampleEntity, entityClassName, entityConstructorName, entityTypeCollisions, warnEntityTypeCollisions, ungeneratedOps, warnUngeneratedOps, deriveEntityNames, entityCollection } from './helpers/opShape'
|
|
75
75
|
import { isReservedName, safeVarName, exampleVarName, phpEntityAccessor, entityCacheField, isRbCoreConstant, isRbSdkConstant, rbSafeTypeName, isSwiftSdkType, swiftSafeTypeName, isPhpReservedType, isPhpSdkClass, phpSafeTypeName, isTsReservedType, isTsSdkType, tsSafeTypeName, isElixirReservedType, elixirSafeTypeName, elixirTypeNames, elixirTypeName, elixirAccessorNames, elixirAccessor, tsTypeName, rbTypeName, phpTypeName, swiftTypeName, jsProp, jsOptProp, jsKey, jsQuote, luaKey, luaString, prefixLeadingDigit } from './helpers/naming'
|
|
76
76
|
import { serverVariables, hasServerVariables, serverVarEnv } from './helpers/serverVars'
|
|
77
77
|
import { mcpTools, MCP_READ_OPS, MCP_WRITE_OPS } from './helpers/mcpTools'
|
|
@@ -1176,6 +1176,7 @@ export {
|
|
|
1176
1176
|
entityDataIdField,
|
|
1177
1177
|
entityRecordIdField,
|
|
1178
1178
|
entityOps,
|
|
1179
|
+
introOps,
|
|
1179
1180
|
entityPrimaryOp,
|
|
1180
1181
|
pickExampleEntity,
|
|
1181
1182
|
entityClassName,
|