@voxgig/sdkgen 4.53.0 → 4.54.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/doctor.js +4 -4
- package/dist/action/doctor.js.map +1 -1
- package/dist/cmp/AgentGuide.js +5 -0
- package/dist/cmp/AgentGuide.js.map +1 -1
- package/dist/cmp/AgentGuideTop.js +2 -0
- package/dist/cmp/AgentGuideTop.js.map +1 -1
- package/dist/cmp/Readme.js +4 -0
- package/dist/cmp/Readme.js.map +1 -1
- package/dist/cmp/ReadmeAgentSetup.d.ts +10 -0
- package/dist/cmp/ReadmeAgentSetup.js +131 -0
- package/dist/cmp/ReadmeAgentSetup.js.map +1 -0
- package/dist/cmp/ReadmeErrors.js +41 -21
- package/dist/cmp/ReadmeErrors.js.map +1 -1
- package/dist/cmp/ReadmeShell.d.ts +2 -0
- package/dist/cmp/ReadmeShell.js +25 -0
- package/dist/cmp/ReadmeShell.js.map +1 -0
- package/dist/cmp/ReadmeStation.js +6 -4
- package/dist/cmp/ReadmeStation.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +2 -0
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/cmp/Skill.d.ts +3 -0
- package/dist/cmp/Skill.js +145 -0
- package/dist/cmp/Skill.js.map +1 -0
- package/dist/helpers/naming.d.ts +3 -1
- package/dist/helpers/naming.js +17 -0
- package/dist/helpers/naming.js.map +1 -1
- package/dist/helpers/opExample.js +1 -1
- package/dist/helpers/opExample.js.map +1 -1
- package/dist/helpers/optional.d.ts +1 -0
- package/dist/helpers/optional.js +1 -0
- package/dist/helpers/optional.js.map +1 -1
- package/dist/helpers/text.d.ts +2 -1
- package/dist/helpers/text.js +23 -0
- package/dist/helpers/text.js.map +1 -1
- package/dist/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +5 -3
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/model/sdkgen.aontu +2 -0
- package/package.json +1 -1
- package/project/.sdk/model/target/c.aontu +3 -0
- package/project/.sdk/model/target/clojure.aontu +3 -0
- package/project/.sdk/model/target/cpp.aontu +3 -0
- package/project/.sdk/model/target/csharp.aontu +3 -0
- package/project/.sdk/model/target/elixir.aontu +3 -0
- package/project/.sdk/model/target/go.aontu +3 -0
- package/project/.sdk/model/target/java.aontu +3 -0
- package/project/.sdk/model/target/js.aontu +3 -0
- package/project/.sdk/model/target/kotlin.aontu +3 -0
- package/project/.sdk/model/target/lua.aontu +3 -0
- package/project/.sdk/model/target/ocaml.aontu +3 -0
- package/project/.sdk/model/target/perl.aontu +3 -0
- package/project/.sdk/model/target/php.aontu +3 -0
- package/project/.sdk/model/target/py-data.aontu +3 -0
- package/project/.sdk/model/target/py.aontu +3 -0
- package/project/.sdk/model/target/rb.aontu +3 -0
- package/project/.sdk/model/target/rust.aontu +3 -0
- package/project/.sdk/model/target/scala.aontu +3 -0
- package/project/.sdk/model/target/swift.aontu +3 -0
- package/project/.sdk/model/target/ts.aontu +3 -0
- package/project/.sdk/model/target/zig.aontu +3 -0
- package/project/.sdk/src/cmp/c/ReadmeEntity_c.ts +4 -4
- package/project/.sdk/src/cmp/c/ReadmeHowto_c.ts +3 -3
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +4 -4
- package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +5 -5
- package/project/.sdk/src/cmp/c/ReadmeTopTest_c.ts +4 -4
- package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +2 -2
- package/project/.sdk/src/cmp/clojure/ReadmeHowto_clojure.ts +3 -3
- package/project/.sdk/src/cmp/clojure/ReadmeTopQuick_clojure.ts +2 -2
- package/project/.sdk/src/cmp/clojure/ReadmeTopTest_clojure.ts +3 -3
- package/project/.sdk/src/cmp/cpp/ReadmeEntity_cpp.ts +3 -3
- package/project/.sdk/src/cmp/cpp/ReadmeQuick_cpp.ts +3 -3
- package/project/.sdk/src/cmp/cpp/ReadmeTopQuick_cpp.ts +5 -4
- package/project/.sdk/src/cmp/csharp/ReadmeTopQuick_csharp.ts +2 -2
- package/project/.sdk/src/cmp/elixir/ReadmeEntity_elixir.ts +2 -2
- package/project/.sdk/src/cmp/elixir/ReadmeHowto_elixir.ts +4 -4
- package/project/.sdk/src/cmp/elixir/ReadmeQuick_elixir.ts +4 -4
- package/project/.sdk/src/cmp/elixir/ReadmeRef_elixir.ts +2 -2
- package/project/.sdk/src/cmp/elixir/ReadmeTopQuick_elixir.ts +5 -5
- package/project/.sdk/src/cmp/elixir/ReadmeTopTest_elixir.ts +4 -4
- package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +3 -3
- package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +3 -3
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +3 -3
- package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +4 -4
- package/project/.sdk/src/cmp/java/ReadmeTopQuick_java.ts +2 -2
- package/project/.sdk/src/cmp/js/Package_js.ts +1 -1
- package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +2 -2
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +4 -4
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +3 -3
- package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +4 -4
- package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +4 -4
- package/project/.sdk/src/cmp/kotlin/ReadmeTopQuick_kotlin.ts +2 -2
- package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +2 -2
- package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +3 -3
- package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +4 -4
- package/project/.sdk/src/cmp/ocaml/ReadmeEntity_ocaml.ts +3 -3
- package/project/.sdk/src/cmp/ocaml/ReadmeHowto_ocaml.ts +3 -3
- package/project/.sdk/src/cmp/ocaml/ReadmeQuick_ocaml.ts +3 -3
- package/project/.sdk/src/cmp/ocaml/ReadmeTopQuick_ocaml.ts +3 -3
- package/project/.sdk/src/cmp/perl/ReadmeEntity_perl.ts +3 -3
- package/project/.sdk/src/cmp/perl/ReadmeQuick_perl.ts +3 -3
- package/project/.sdk/src/cmp/perl/ReadmeTopQuick_perl.ts +4 -4
- package/project/.sdk/src/cmp/perl/ReadmeTopTest_perl.ts +2 -2
- package/project/.sdk/src/cmp/php/ReadmeEntity_php.ts +2 -2
- package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +3 -3
- package/project/.sdk/src/cmp/php/ReadmeTopQuick_php.ts +4 -4
- package/project/.sdk/src/cmp/php/ReadmeTopTest_php.ts +2 -2
- package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +2 -2
- package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +3 -3
- package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +4 -4
- package/project/.sdk/src/cmp/py/ReadmeTopTest_py.ts +3 -2
- package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +3 -3
- package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +3 -3
- package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +3 -3
- package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +4 -4
- package/project/.sdk/src/cmp/rb/ReadmeTopTest_rb.ts +3 -2
- package/project/.sdk/src/cmp/rust/ReadmeEntity_rust.ts +3 -3
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +3 -3
- package/project/.sdk/src/cmp/rust/ReadmeTopQuick_rust.ts +4 -4
- package/project/.sdk/src/cmp/scala/ReadmeTopQuick_scala.ts +2 -2
- package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -2
- package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +2 -2
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +4 -4
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +3 -3
- package/project/.sdk/src/cmp/ts/ReadmeTopQuick_ts.ts +4 -4
- package/project/.sdk/src/cmp/ts/ReadmeTopTest_ts.ts +4 -4
- package/project/.sdk/src/cmp/zig/ReadmeEntity_zig.ts +3 -3
- package/project/.sdk/src/cmp/zig/ReadmeHowto_zig.ts +3 -3
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +3 -3
- package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +4 -4
- package/project/.sdk/src/cmp/zig/ReadmeTopTest_zig.ts +3 -3
- package/project/.sdk/tm/c/Makefile +1 -1
- package/project/.sdk/tm/cpp/Makefile +1 -1
- package/project/.sdk/tm/csharp/Makefile +6 -1
- package/project/.sdk/tm/go/Makefile +1 -1
- package/project/.sdk/tm/java/Makefile +1 -1
- package/project/.sdk/tm/js/Makefile +3 -3
- package/project/.sdk/tm/kotlin/Makefile +1 -1
- package/project/.sdk/tm/lua/Makefile +1 -1
- package/project/.sdk/tm/perl/Makefile +1 -1
- package/project/.sdk/tm/php/Makefile +1 -1
- package/project/.sdk/tm/py/Makefile +1 -1
- package/project/.sdk/tm/py/pkg/utility/fetcher.py +14 -2
- package/project/.sdk/tm/py/test/test_primary_utility.py +4 -0
- package/project/.sdk/tm/py-data/Makefile +1 -1
- package/project/.sdk/tm/rb/Makefile +1 -1
- package/project/.sdk/tm/rust/Makefile +1 -1
- package/project/.sdk/tm/swift/Makefile +2 -3
- package/project/.sdk/tm/ts/Makefile +3 -3
- package/project/sdkgen-package.json +1 -1
- package/src/action/doctor.ts +4 -4
- package/src/cmp/AgentGuide.ts +6 -0
- package/src/cmp/AgentGuideTop.ts +3 -0
- package/src/cmp/Readme.ts +4 -0
- package/src/cmp/ReadmeAgentSetup.ts +159 -0
- package/src/cmp/ReadmeErrors.ts +43 -22
- package/src/cmp/ReadmeShell.ts +31 -0
- package/src/cmp/ReadmeStation.ts +6 -5
- package/src/cmp/ReadmeTop.ts +2 -0
- package/src/cmp/Skill.ts +168 -0
- package/src/helpers/naming.ts +20 -0
- package/src/helpers/opExample.ts +2 -2
- package/src/helpers/optional.ts +1 -0
- package/src/helpers/text.ts +25 -0
- package/src/sdkgen.ts +3 -1
package/src/action/doctor.ts
CHANGED
|
@@ -840,12 +840,12 @@ function compareTrees(
|
|
|
840
840
|
continue
|
|
841
841
|
}
|
|
842
842
|
|
|
843
|
-
// A component the scaffold has NEVER shipped
|
|
844
|
-
//
|
|
845
|
-
//
|
|
843
|
+
// A component or template the scaffold has NEVER shipped and no add
|
|
844
|
+
// wrote is the project's own. Anything else under a tree `target add`
|
|
845
|
+
// owns, an add's own copy included, is stale output.
|
|
846
846
|
const known = fs.existsSync(Path.join(tree.scaffold, rel)) ||
|
|
847
847
|
landed.has(rel)
|
|
848
|
-
if (
|
|
848
|
+
if (!known && null == copied[label + rel] &&
|
|
849
849
|
!RETIRED_RE.test(rel)) {
|
|
850
850
|
report.additive.push(label + rel)
|
|
851
851
|
}
|
package/src/cmp/AgentGuide.ts
CHANGED
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
} from './AgentGuideContent'
|
|
23
23
|
|
|
24
24
|
import { AgentGuideFeature } from './AgentGuideFeature'
|
|
25
|
+
import { Skill } from './Skill'
|
|
26
|
+
import { surfaceOf } from '../helpers/surface'
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
// Per-language agent guide. Emitted inside the ambient target folder (the Root
|
|
@@ -142,6 +144,10 @@ Generated by [@voxgig/sdkgen](https://github.com/voxgig/sdkgen).${'' === guide ?
|
|
|
142
144
|
Content(claudePointer(`${Name} ${title}`))
|
|
143
145
|
})
|
|
144
146
|
|
|
147
|
+
if ('sdk' === surfaceOf(target)) {
|
|
148
|
+
Skill({ target })
|
|
149
|
+
}
|
|
150
|
+
|
|
145
151
|
// Co-located per-feature guide files — only for dir-layout targets (ts/js),
|
|
146
152
|
// where each feature has its own directory to hold the guide. Flat-layout
|
|
147
153
|
// targets document features inline above; phase-disabled targets
|
package/src/cmp/AgentGuideTop.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { cmp } from '../helpers/component'
|
|
|
4
4
|
import { fact } from '../helpers/facts'
|
|
5
5
|
import { externalName, surfaceOf } from '../helpers/surface'
|
|
6
6
|
import { KIT } from '../types'
|
|
7
|
+
import { Skill } from './Skill'
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
activeTargets,
|
|
@@ -205,6 +206,8 @@ const AgentGuideTop = cmp(function AgentGuideTop(props: any) {
|
|
|
205
206
|
Content(claudePointer(`${Name} SDK`))
|
|
206
207
|
})
|
|
207
208
|
|
|
209
|
+
Skill({ targets: targets.filter((t: any) => 'sdk' === surfaceOf(t)) })
|
|
210
|
+
|
|
208
211
|
ctx$.log?.info?.({ point: 'generate-agentguide-top', note: 'name:' + Name })
|
|
209
212
|
})
|
|
210
213
|
|
package/src/cmp/Readme.ts
CHANGED
|
@@ -5,7 +5,9 @@ import { cmp } from '../helpers/component'
|
|
|
5
5
|
|
|
6
6
|
import { ReadmeIntro } from './ReadmeIntro'
|
|
7
7
|
import { ReadmeInstall } from './ReadmeInstall'
|
|
8
|
+
import { ReadmeShell } from './ReadmeShell'
|
|
8
9
|
import { ReadmeQuick } from './ReadmeQuick'
|
|
10
|
+
import { ReadmeAgentSetup } from './ReadmeAgentSetup'
|
|
9
11
|
import { ReadmeErrors } from './ReadmeErrors'
|
|
10
12
|
import { ReadmeStation } from './ReadmeStation'
|
|
11
13
|
import { ReadmeModel } from './ReadmeModel'
|
|
@@ -25,6 +27,8 @@ const Readme = cmp(function Readme(props: any) {
|
|
|
25
27
|
|
|
26
28
|
ReadmeIntro({ target })
|
|
27
29
|
ReadmeInstall({ target })
|
|
30
|
+
ReadmeShell({ target })
|
|
31
|
+
ReadmeAgentSetup({ targets: [target] })
|
|
28
32
|
ReadmeQuick({ target })
|
|
29
33
|
ReadmeStation({ target })
|
|
30
34
|
ReadmeErrors({ target })
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
|
|
2
|
+
import { Content, each } from 'jostraca'
|
|
3
|
+
import { cmp } from '../helpers/component'
|
|
4
|
+
|
|
5
|
+
import { KIT, getModelPath } from '../types'
|
|
6
|
+
import { fact } from '../helpers/facts'
|
|
7
|
+
import { isAuthActive } from '../utility'
|
|
8
|
+
import {
|
|
9
|
+
installCommand, isPublished, originName, repoInfo,
|
|
10
|
+
} from '../helpers/packageMeta'
|
|
11
|
+
import { entityOps } from '../helpers/opShape'
|
|
12
|
+
import { seriesList, wrapText } from '../helpers/text'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// Targets whose operations return their result as a plain value: lean has no
|
|
16
|
+
// entity layer, so there is no instance to return.
|
|
17
|
+
const VALUE_RESULT_ORIGINS = ['lean']
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// Each target's test-mode constructor, as its README's test mode section writes it.
|
|
21
|
+
const TEST_CLIENT: Record<string, (Name: string) => string> = {
|
|
22
|
+
ts: (N) => N + 'SDK.test()',
|
|
23
|
+
js: (N) => N + 'SDK.test()',
|
|
24
|
+
py: (N) => N + 'SDK.test()',
|
|
25
|
+
rb: (N) => N + 'SDK.test',
|
|
26
|
+
php: (N) => N + 'SDK::test()',
|
|
27
|
+
perl: (N) => N + 'SDK->test()',
|
|
28
|
+
lua: () => 'sdk.test()',
|
|
29
|
+
go: () => 'sdk.Test()',
|
|
30
|
+
java: (N) => N + 'SDK.testSDK(null, null)',
|
|
31
|
+
kotlin: (N) => N + 'SDK.testSDK(null, null)',
|
|
32
|
+
scala: (N) => N + 'SDK.testSDK(null, null)',
|
|
33
|
+
swift: (N) => N + 'SDK.testSDK(nil, nil)',
|
|
34
|
+
csharp: (N) => N + 'SDK.TestSDK(null, null)',
|
|
35
|
+
rust: () => 'test_sdk(Value::Noval, Value::Noval)',
|
|
36
|
+
c: () => 'test_sdk(NULL, NULL)',
|
|
37
|
+
cpp: (N) => N + 'SDK::testSDK()',
|
|
38
|
+
zig: () => 'sdk.test_sdk(h.vnull(), h.vnull())',
|
|
39
|
+
elixir: (N) => N + '.test()',
|
|
40
|
+
clojure: () => '(api/test-sdk nil nil)',
|
|
41
|
+
ocaml: () => 'Sdk_client.test ()',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// A target installs by its command, or from the release tag when none installs it.
|
|
46
|
+
function installCommandOf(model: any, name: string): string {
|
|
47
|
+
const cmd = installCommand(model, name)
|
|
48
|
+
return '' !== cmd && (isPublished(model, name) || 'go' === originName(model, name)) ? cmd : ''
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function installStep(model: any, name: string, tags: string): string {
|
|
53
|
+
const cmd = installCommandOf(model, name)
|
|
54
|
+
return '' !== cmd ? 'install it with `' + cmd + '`' : 'install it from the release tag' + tags
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function testClient(model: any, name: string): string {
|
|
59
|
+
const client = TEST_CLIENT[originName(model, name)]
|
|
60
|
+
return null == client ? 'its test-mode constructor, as its README shows'
|
|
61
|
+
: '`' + client(model.const.Name) + '`'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
function cap(s: string): string {
|
|
66
|
+
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
function returnsEntity(model: any, name: string): boolean {
|
|
71
|
+
return !VALUE_RESULT_ORIGINS.includes(originName(model, name))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
// Whether an active entity carries an operation a test can call.
|
|
76
|
+
function hasEntityOp(model: any): boolean {
|
|
77
|
+
const entity = getModelPath(model, `main.${KIT}.entity`) || {}
|
|
78
|
+
return each(entity).some((e: any) => e && e.active !== false && 0 < entityOps(e).length)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
// What an entity operation returns, in the targets named.
|
|
83
|
+
function resultSentence(model: any, targets: any[]): string {
|
|
84
|
+
const values = targets.filter((t: any) => !returnsEntity(model, t.name))
|
|
85
|
+
return 0 === values.length ? 'Entity operations return the entity, not plain data.'
|
|
86
|
+
: values.length === targets.length
|
|
87
|
+
? 'Entity operations return their result as a plain value, not an entity instance.'
|
|
88
|
+
: 'Entity operations return the entity, not plain data, except in ' +
|
|
89
|
+
seriesList(values.map((t: any) => String(fact(t, 'title')))) +
|
|
90
|
+
', where they return the result as a plain value.'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// Per target: its title, install step and test client, as the prompt and the skill state them.
|
|
95
|
+
function setupItems(model: any, targets: any[], tags: string): { title: string, install: string, client: string }[] {
|
|
96
|
+
return targets.map((t: any) => ({
|
|
97
|
+
title: fact(t, 'title'),
|
|
98
|
+
install: installStep(model, t.name, tags),
|
|
99
|
+
client: testClient(model, t.name),
|
|
100
|
+
}))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
// A prompt a reader pastes into a coding agent, to set the SDK up in their own project.
|
|
105
|
+
function agentPrompt(model: any, targets: any[]): string {
|
|
106
|
+
const api = fact(model.main[KIT], 'apiName').inline
|
|
107
|
+
const one = 1 === targets.length
|
|
108
|
+
const tagsUrl = repoInfo(model).tagsUrl
|
|
109
|
+
const tagged = targets.filter((t: any) => '' === installCommandOf(model, t.name))
|
|
110
|
+
const lines = one
|
|
111
|
+
? [`Add the ${api} SDK for ${fact(targets[0], 'title')} to this project.`,
|
|
112
|
+
cap(installStep(model, targets[0].name, ' at ' + tagsUrl)) +
|
|
113
|
+
`. Its test client is ${testClient(model, targets[0].name)}.`]
|
|
114
|
+
: [`Add the ${api} SDK to this project, in the project's own language:`,
|
|
115
|
+
...targets.map((t: any) => `- ${fact(t, 'title')}: ${installStep(model, t.name, '')}; ` +
|
|
116
|
+
`the test client is ${testClient(model, t.name)}.`),
|
|
117
|
+
...(0 < tagged.length ? [`The release tags are at ${tagsUrl}.`] : [])]
|
|
118
|
+
const live = isAuthActive(model)
|
|
119
|
+
? 'Then show me how to build the live client with my API key.'
|
|
120
|
+
: 'Then show me how to build the live client.'
|
|
121
|
+
const first = 'Write one test that builds the test client, which answers from an ' +
|
|
122
|
+
'in-memory mock with no network or credentials, '
|
|
123
|
+
const test = hasEntityOp(model)
|
|
124
|
+
? first + 'calls one entity operation and checks the result. ' +
|
|
125
|
+
resultSentence(model, targets) + ' Run the test until it passes.'
|
|
126
|
+
: first + "calls one route through the client's direct method and checks the result. " +
|
|
127
|
+
'Run the test until it passes.'
|
|
128
|
+
return `\`\`\`text
|
|
129
|
+
${lines.join('\n')}
|
|
130
|
+
${wrapText(test)}
|
|
131
|
+
${live}
|
|
132
|
+
\`\`\`
|
|
133
|
+
`
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
const ReadmeAgentSetup = cmp(function ReadmeAgentSetup(props: any) {
|
|
138
|
+
const { targets } = props
|
|
139
|
+
const { model } = props.ctx$
|
|
140
|
+
if (0 === targets.length) return
|
|
141
|
+
|
|
142
|
+
Content(`
|
|
143
|
+
## Set up with a coding agent
|
|
144
|
+
|
|
145
|
+
To add this SDK to a project with a coding agent, paste this prompt into
|
|
146
|
+
the agent in that project:
|
|
147
|
+
|
|
148
|
+
${agentPrompt(model, targets)}
|
|
149
|
+
`)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
export {
|
|
154
|
+
ReadmeAgentSetup,
|
|
155
|
+
agentPrompt,
|
|
156
|
+
hasEntityOp,
|
|
157
|
+
returnsEntity,
|
|
158
|
+
setupItems,
|
|
159
|
+
}
|
package/src/cmp/ReadmeErrors.ts
CHANGED
|
@@ -11,10 +11,11 @@ import { directRoute, entityIdField, pickExampleEntity } from '../helpers/opShap
|
|
|
11
11
|
import type { DirectRoute } from '../helpers/opShape'
|
|
12
12
|
import { helperLang, primaryOpCall } from '../helpers/opExample'
|
|
13
13
|
import type { PrimaryCall } from '../helpers/opExample'
|
|
14
|
-
import { exampleVarName, jsKey, luaKey } from '../helpers/naming'
|
|
14
|
+
import { exampleVarName, entityListVar, jsKey, luaKey } from '../helpers/naming'
|
|
15
15
|
import { exampleParts, entityName } from '../helpers/exampleCall'
|
|
16
16
|
import type { ExampleInput } from '../helpers/exampleCall'
|
|
17
17
|
import { originName } from '../helpers/packageMeta'
|
|
18
|
+
import { optionalComponent } from '../helpers/optional'
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
type EntityExample = ExampleInput & {
|
|
@@ -245,16 +246,17 @@ _ = result
|
|
|
245
246
|
c: {
|
|
246
247
|
entity: (x) => {
|
|
247
248
|
const { v, factory, arg } = exampleParts('c', x)
|
|
249
|
+
const vs = entityListVar(v, 'c')
|
|
248
250
|
const call = `${v}->vt->${x.op}(${v}, ${arg}, NULL, &err)`
|
|
249
|
-
const ok = 'list' === x.op ? ` for (size_t i = 0; ${
|
|
250
|
-
printf("%s\\n", voxgig_to_json(${
|
|
251
|
+
const ok = 'list' === x.op ? ` for (size_t i = 0; ${vs}[i]; i++) {
|
|
252
|
+
printf("%s\\n", voxgig_to_json(${vs}[i]->vt->data(${vs}[i], NULL)));
|
|
251
253
|
}` : ` printf("%s\\n", voxgig_to_json(${v}->vt->data(${v}, NULL)));`
|
|
252
254
|
return `Entity operations set \`*err\` on failure, so check \`err\` after each call:
|
|
253
255
|
|
|
254
256
|
\`\`\`c
|
|
255
257
|
Entity* ${v} = ${factory};
|
|
256
258
|
PNError* err = NULL;
|
|
257
|
-
${'list' === x.op ? `Entity** ${
|
|
259
|
+
${'list' === x.op ? `Entity** ${vs} = ${call};` : `${call};`}
|
|
258
260
|
if (err) {
|
|
259
261
|
fprintf(stderr, "${x.op} failed: %s\\n", err->msg);
|
|
260
262
|
} else {
|
|
@@ -284,9 +286,10 @@ if (!voxgig_as_bool(getp(result, "ok"))) {
|
|
|
284
286
|
cpp: {
|
|
285
287
|
entity: (x) => {
|
|
286
288
|
const { v, factory, arg } = exampleParts('cpp', x)
|
|
289
|
+
const vs = entityListVar(v, 'cpp')
|
|
287
290
|
const call = `${factory}->${x.op}(${arg}, Value::undef())`
|
|
288
|
-
const body = 'list' === x.op ? ` std::vector<SdkEntityPtr> ${
|
|
289
|
-
for (const auto& ${v} : ${
|
|
291
|
+
const body = 'list' === x.op ? ` std::vector<SdkEntityPtr> ${vs} = ${call};
|
|
292
|
+
for (const auto& ${v} : ${vs}) {
|
|
290
293
|
std::cout << Struct::jsonify(${v}->data()) << std::endl;
|
|
291
294
|
}` : ` SdkEntityPtr ${v} = ${call};
|
|
292
295
|
std::cout << Struct::jsonify(${v}->data()) << std::endl;`
|
|
@@ -322,8 +325,9 @@ if (!(getp(result, "ok") == Value(true))) {
|
|
|
322
325
|
rust: {
|
|
323
326
|
entity: (x) => {
|
|
324
327
|
const { v, factory, arg } = exampleParts('rust', x)
|
|
325
|
-
const
|
|
326
|
-
|
|
328
|
+
const vs = entityListVar(v, 'rust')
|
|
329
|
+
const ok = 'list' === x.op ? ` Ok(${vs}) => {
|
|
330
|
+
for ${v} in &${vs} {
|
|
327
331
|
println!("{:?}", ${v}.data(None));
|
|
328
332
|
}
|
|
329
333
|
}` : ` Ok(${v}) => println!("{:?}", ${v}.data(None)),`
|
|
@@ -360,8 +364,9 @@ match client.direct(jo(vec![
|
|
|
360
364
|
zig: {
|
|
361
365
|
entity: (x) => {
|
|
362
366
|
const { v, factory, arg } = exampleParts('zig', x)
|
|
363
|
-
const
|
|
364
|
-
|
|
367
|
+
const vs = entityListVar(v, 'zig')
|
|
368
|
+
const ok = 'list' === x.op ? ` .ok => |${vs}| {
|
|
369
|
+
for (${vs}) |${v}| {
|
|
365
370
|
std.debug.print("{s}\\n", .{h.stringify(${v}.asEntity().data(null))});
|
|
366
371
|
}
|
|
367
372
|
},` : ('remove' === x.op ? ` .ok => std.debug.print("removed\\n", .{}),` :
|
|
@@ -398,8 +403,9 @@ if (!(h.get_bool(result, "ok") orelse false)) {
|
|
|
398
403
|
ocaml: {
|
|
399
404
|
entity: (x) => {
|
|
400
405
|
const { v, factory, arg } = exampleParts('ocaml', x)
|
|
401
|
-
const
|
|
402
|
-
|
|
406
|
+
const vs = entityListVar(v, 'ocaml')
|
|
407
|
+
const body = 'list' === x.op ? ` let ${vs} = ${factory}.e_list ${arg} Noval in
|
|
408
|
+
List.iter (fun e -> print_endline (stringify (e.e_data_get ()))) ${vs}` :
|
|
403
409
|
` let ${v} = ${factory}.e_${x.op} ${arg} Noval in
|
|
404
410
|
print_endline (stringify (${v}.e_data_get ()))`
|
|
405
411
|
return `Entity operations raise \`Sdk_error.E\` on failure, so wrap them in \`try\` ... \`with\`:
|
|
@@ -432,10 +438,11 @@ let result = Sdk_client.direct client (jo [
|
|
|
432
438
|
perl: {
|
|
433
439
|
entity: (x) => {
|
|
434
440
|
const { v, factory, arg } = exampleParts('perl', x)
|
|
441
|
+
const vs = entityListVar(v, 'perl')
|
|
435
442
|
return `Entity operations die on failure, so wrap them in \`eval\` and check \`$@\`:
|
|
436
443
|
|
|
437
444
|
\`\`\`perl
|
|
438
|
-
my $${'list' === x.op ?
|
|
445
|
+
my $${'list' === x.op ? vs : v} = eval { ${factory}->${x.op}(${arg}) };
|
|
439
446
|
if (my $err = $@) {
|
|
440
447
|
warn "${x.op} failed: $err";
|
|
441
448
|
}
|
|
@@ -462,8 +469,9 @@ unless ($result->{ok}) {
|
|
|
462
469
|
java: {
|
|
463
470
|
entity: (x) => {
|
|
464
471
|
const { v, factory, arg } = exampleParts('java', x)
|
|
465
|
-
const
|
|
466
|
-
|
|
472
|
+
const vs = entityListVar(v, 'java')
|
|
473
|
+
const body = 'list' === x.op ? ` List<?> ${vs} = (List<?>) ${factory}.list(${arg}, null);
|
|
474
|
+
for (Object item : ${vs}) {
|
|
467
475
|
System.out.println(((SdkEntity) item).data());
|
|
468
476
|
}` : ` SdkEntity ${v} = (SdkEntity) ${factory}.${x.op}(${arg}, null);
|
|
469
477
|
System.out.println(${v}.data());`
|
|
@@ -499,8 +507,9 @@ if (!Boolean.TRUE.equals(result.get("ok"))) {
|
|
|
499
507
|
kotlin: {
|
|
500
508
|
entity: (x) => {
|
|
501
509
|
const { v, factory, arg } = exampleParts('kotlin', x)
|
|
502
|
-
const
|
|
503
|
-
|
|
510
|
+
const vs = entityListVar(v, 'kotlin')
|
|
511
|
+
const body = 'list' === x.op ? ` val ${vs} = ${factory}.list(${arg}, null) as List<*>
|
|
512
|
+
for (item in ${vs}) {
|
|
504
513
|
println((item as SdkEntity).data())
|
|
505
514
|
}` : ` val ${v} = ${factory}.${x.op}(${arg}, null) as SdkEntity
|
|
506
515
|
println(${v}.data())`
|
|
@@ -536,8 +545,9 @@ if (result["ok"] != true) {
|
|
|
536
545
|
scala: {
|
|
537
546
|
entity: (x) => {
|
|
538
547
|
const { v, factory, arg } = exampleParts('scala', x)
|
|
539
|
-
const
|
|
540
|
-
${
|
|
548
|
+
const vs = entityListVar(v, 'scala')
|
|
549
|
+
const body = 'list' === x.op ? ` val ${vs} = ${factory}.list(${arg}, null).asInstanceOf[java.util.List[SdkEntity]]
|
|
550
|
+
${vs}.forEach(item => println(item.data()))` :
|
|
541
551
|
` val ${v} = ${factory}.${x.op}(${arg}, null).asInstanceOf[SdkEntity]
|
|
542
552
|
println(${v}.data())`
|
|
543
553
|
return `Entity operations throw a \`RuntimeException\` on failure, so wrap them in
|
|
@@ -658,11 +668,12 @@ if result.entries["ok"] != .bool(true) {
|
|
|
658
668
|
elixir: {
|
|
659
669
|
entity: (x) => {
|
|
660
670
|
const { v, factory, arg } = exampleParts('elixir', x)
|
|
671
|
+
const vs = entityListVar(v, 'elixir')
|
|
661
672
|
const mod = `${x.model.const.Name}.Entity.${entityName(x.ent)}`
|
|
662
673
|
const args = '' === arg ? v : `${v}, ${arg}`
|
|
663
|
-
const body = 'list' === x.op ? ` ${
|
|
664
|
-
for i <- 0..(Voxgig.Struct.size(${
|
|
665
|
-
IO.puts(Voxgig.Struct.jsonify(${mod}.data_get(Voxgig.Struct.getelem(${
|
|
674
|
+
const body = 'list' === x.op ? ` ${vs} = ${mod}.list(${args})
|
|
675
|
+
for i <- 0..(Voxgig.Struct.size(${vs}) - 1)//1 do
|
|
676
|
+
IO.puts(Voxgig.Struct.jsonify(${mod}.data_get(Voxgig.Struct.getelem(${vs}, i))))
|
|
666
677
|
end` : ` ${v} = ${mod}.${x.op}(${args})
|
|
667
678
|
IO.puts(Voxgig.Struct.jsonify(${mod}.data_get(${v})))`
|
|
668
679
|
return `Entity operations raise on failure, so wrap them in \`try\` / \`rescue\`:
|
|
@@ -755,6 +766,16 @@ const ReadmeErrors = cmp(function ReadmeErrors(props: any) {
|
|
|
755
766
|
|
|
756
767
|
`)
|
|
757
768
|
|
|
769
|
+
// A target's own section, which a target from a package supplies.
|
|
770
|
+
const own = optionalComponent(ctx$, target, 'ReadmeErrors')
|
|
771
|
+
if (own) {
|
|
772
|
+
own['ReadmeErrors']({
|
|
773
|
+
target, entity: ex && primaryOp ? ex : null, op: primaryOp,
|
|
774
|
+
idF: ex && primaryOp ? entityIdField(ex) : null, route: directRoute(model),
|
|
775
|
+
})
|
|
776
|
+
return
|
|
777
|
+
}
|
|
778
|
+
|
|
758
779
|
if (ex && primaryOp && lang.entity) {
|
|
759
780
|
const eName = entityName(ex)
|
|
760
781
|
const eLower = exampleVarName(eName.toLowerCase(), origin)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import { Content } from 'jostraca'
|
|
3
|
+
|
|
4
|
+
import { cmp } from '../helpers/component'
|
|
5
|
+
import { seriesList } from '../helpers/text'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// Names the Makefile recipes the target declares as needing a Unix shell.
|
|
9
|
+
const ReadmeShell = cmp(function ReadmeShell(props: any) {
|
|
10
|
+
const { target } = props
|
|
11
|
+
|
|
12
|
+
const unix: string[] = Object.values(target?.make?.unix ?? {})
|
|
13
|
+
.filter((name: any) => 'string' === typeof name)
|
|
14
|
+
if (0 === unix.length) return
|
|
15
|
+
|
|
16
|
+
const names = seriesList(unix.map((name: string) => '`' + name + '`'))
|
|
17
|
+
const recipes = 1 === unix.length ? 'recipe runs' : 'recipes run'
|
|
18
|
+
|
|
19
|
+
Content(`
|
|
20
|
+
### On Windows
|
|
21
|
+
|
|
22
|
+
The Makefile's ${names} ${recipes} Unix shell commands: on Windows, run
|
|
23
|
+
${1 === unix.length ? 'it' : 'them'} from Git Bash or WSL. Its other recipes call the toolchain
|
|
24
|
+
directly and run from any shell, and each one names the command it runs.
|
|
25
|
+
`)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
ReadmeShell
|
|
31
|
+
}
|
package/src/cmp/ReadmeStation.ts
CHANGED
|
@@ -12,8 +12,8 @@ import { KIT } from '../types'
|
|
|
12
12
|
// else uses inverted binding through the SDK's own constructor.
|
|
13
13
|
const CONNECT_TARGETS = ['ts', 'js', 'py', 'rb', 'php', 'lua', 'perl']
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// The targets whose Main emits the load-time registration (a MainStation fragment).
|
|
16
|
+
const SELF_REGISTER_TARGETS = ['ts', 'js']
|
|
17
17
|
|
|
18
18
|
const ERROR_CATALOG_URL =
|
|
19
19
|
'https://github.com/voxgig/sdkgen/blob/main/docs/reference/station-errors.md'
|
|
@@ -73,9 +73,10 @@ code. That is what the \`package\` key above is for — it names the module
|
|
|
73
73
|
for station to load, since nothing else in this example would execute
|
|
74
74
|
it. An application that imports this SDK for its types anyway can drop
|
|
75
75
|
the key: that import is itself the bootstrap.`
|
|
76
|
-
: `
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
: `Loading this package does not register it with the station
|
|
77
|
+
library, so register the factory once at startup —
|
|
78
|
+
\`Station.provide('${slug}', ...)\`, one line — and every other line of
|
|
79
|
+
configuration stays in \`station.json\`.`}
|
|
79
80
|
|
|
80
81
|
A second instance of the same API is one more key — \`"${slug}$test"\`
|
|
81
82
|
beside \`"${slug}"\` — and \`station.sdk('${slug}$test')\` returns it.
|
package/src/cmp/ReadmeTop.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import { ReadmeAgentSetup } from './ReadmeAgentSetup'
|
|
2
3
|
import { each, names, Content, File } from 'jostraca'
|
|
3
4
|
import { cmp } from '../helpers/component'
|
|
4
5
|
|
|
@@ -909,6 +910,7 @@ const ReadmeTop = cmp(function ReadmeTop(props: any) {
|
|
|
909
910
|
ReadmeTopTesting({ s })
|
|
910
911
|
ReadmeTopPackages({ s })
|
|
911
912
|
ReadmeTopQuickstart({ s })
|
|
913
|
+
ReadmeAgentSetup({ targets: s.sdkTargets })
|
|
912
914
|
ReadmeTopSurfaces({ s })
|
|
913
915
|
ReadmeTopMcp({ s })
|
|
914
916
|
ReadmeTopEntities({ s })
|
package/src/cmp/Skill.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
|
|
2
|
+
import { each, Content, File } from 'jostraca'
|
|
3
|
+
import { cmp } from '../helpers/component'
|
|
4
|
+
|
|
5
|
+
import { KIT, getModelPath } from '../types'
|
|
6
|
+
import { fact } from '../helpers/facts'
|
|
7
|
+
import { CANON_OP_ORDER, entityOps } from '../helpers/opShape'
|
|
8
|
+
import { apiName, repoInfo } from '../helpers/packageMeta'
|
|
9
|
+
import { seriesList, wrapText } from '../helpers/text'
|
|
10
|
+
import { hasEntityOp, returnsEntity, setupItems } from './ReadmeAgentSetup'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// The Agent Skills limits on the frontmatter (agentskills.io/specification).
|
|
14
|
+
const NAME_MAX = 64
|
|
15
|
+
const DESCRIPTION_MAX = 1024
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function skillWord(part: string): string {
|
|
19
|
+
return part.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// The repository's name, then the target's: the target keeps its place in the
|
|
24
|
+
// limit however long the repository's name is, which keeps the names distinct.
|
|
25
|
+
function skillName(repo: string, target?: string): string {
|
|
26
|
+
const tail = null == target ? '' : '-' + skillWord(target).slice(0, NAME_MAX / 2 - 1)
|
|
27
|
+
return skillWord(repo).slice(0, NAME_MAX - tail.length).replace(/-$/, '') + tail
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// What an entity operation returns, in the SDKs the skill covers; `list` is
|
|
32
|
+
// named only where an entity has it.
|
|
33
|
+
function resultRule(model: any, sdks: any[], listed: boolean): string {
|
|
34
|
+
const entity = 'Every entity operation returns the entity, not plain data: ' +
|
|
35
|
+
(listed ? '`list` returns one entity per record, and the record' : 'the record') +
|
|
36
|
+
" is read through the entity's data accessor."
|
|
37
|
+
const values = sdks.filter((t: any) => !returnsEntity(model, t.name))
|
|
38
|
+
return 0 === values.length ? entity
|
|
39
|
+
: values.length === sdks.length
|
|
40
|
+
? 'Every entity operation returns its result as a plain value: this SDK has no ' +
|
|
41
|
+
'entity instance, so there is no data accessor to read.'
|
|
42
|
+
: entity + ' In ' + seriesList(values.map((t: any) => String(fact(t, 'title')))) +
|
|
43
|
+
', an operation returns its result as a plain value: that SDK has no entity instance.'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// The route an operation sends to: its first point that is not an action.
|
|
48
|
+
function opRoute(op: any): { method: string, path: string } {
|
|
49
|
+
const points: any[] = op?.points ? each(op.points) : []
|
|
50
|
+
const pick = points.find((pt: any) => null == pt?.q?.['$action']) ?? points[0]
|
|
51
|
+
return { method: String(pick?.m ?? '').toUpperCase(), path: String(pick?.o ?? '') }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function skillDescription(api: string, langs: string, entities: any[]): string {
|
|
56
|
+
const lead = `Call the ${api} API through its generated SDK${langs}: build a client, ` +
|
|
57
|
+
'test offline with the mock client, and use its entities'
|
|
58
|
+
const tail = '. Use when writing or changing code that calls this API.'
|
|
59
|
+
const names = entities.map((e: any) => e.Name)
|
|
60
|
+
for (let n = names.length; 0 <= n; n--) {
|
|
61
|
+
const list = 0 === n ? '' : ' (' + names.slice(0, n).join(', ') +
|
|
62
|
+
(n < names.length ? ', and more' : '') + ')'
|
|
63
|
+
const text = lead + list + tail
|
|
64
|
+
if (text.length <= DESCRIPTION_MAX) return text
|
|
65
|
+
}
|
|
66
|
+
return (lead + tail).slice(0, DESCRIPTION_MAX)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// An Agent Skill for the SDK: at the root for every target, or beside one target.
|
|
71
|
+
const Skill = cmp(function Skill(props: any) {
|
|
72
|
+
const { targets, target } = props
|
|
73
|
+
const { model } = props.ctx$
|
|
74
|
+
|
|
75
|
+
const kit = model.main[KIT]
|
|
76
|
+
const api = apiName(model)
|
|
77
|
+
const sdks: any[] = null == target ? targets : [target]
|
|
78
|
+
const repo = repoInfo(model).repo
|
|
79
|
+
const name = null == target ? skillName(repo) : skillName(repo, target.name)
|
|
80
|
+
const langs = 1 === sdks.length ? ' for ' + fact(sdks[0], 'title') :
|
|
81
|
+
0 === sdks.length ? '' : ' in ' + sdks.map((t: any) => fact(t, 'title')).join(', ')
|
|
82
|
+
|
|
83
|
+
const entity = getModelPath(model, `main.${KIT}.entity`) || {}
|
|
84
|
+
const entities = each(entity).filter((e: any) => e && e.active !== false)
|
|
85
|
+
|
|
86
|
+
File({ name: 'SKILL.md' }, () => {
|
|
87
|
+
Content(`---
|
|
88
|
+
name: ${name}
|
|
89
|
+
description: ${JSON.stringify(skillDescription(api, langs, entities))}
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
# ${model.const.Name} SDK${null == target ? '' : langs}
|
|
93
|
+
|
|
94
|
+
`)
|
|
95
|
+
|
|
96
|
+
const summary = fact(kit, 'text').summary.inline
|
|
97
|
+
if ('' !== summary) Content(summary + '\n\n')
|
|
98
|
+
|
|
99
|
+
if (0 < sdks.length) {
|
|
100
|
+
const tagsUrl = repoInfo(model).tagsUrl
|
|
101
|
+
Content(`## Set up
|
|
102
|
+
|
|
103
|
+
${setupItems(model, sdks, ' at ' + tagsUrl).map((s, i) =>
|
|
104
|
+
`- ${s.title}${null == target && 'folder' === fact(sdks[i], 'place') ? ' (`' + sdks[i].name + '/`)' : ''}: ${s.install}. ` +
|
|
105
|
+
`The test client is ${s.client}.`).join('\n')}
|
|
106
|
+
|
|
107
|
+
`)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const ops = hasEntityOp(model)
|
|
111
|
+
const listed = entities.some((e: any) => entityOps(e).includes('list'))
|
|
112
|
+
const rules = [
|
|
113
|
+
...(ops ? [resultRule(model, sdks, listed)] : []),
|
|
114
|
+
'The test client answers from an in-memory mock, with no network and no credentials, ' +
|
|
115
|
+
'so a first test needs neither.',
|
|
116
|
+
ops
|
|
117
|
+
? "The client's direct method sends a request to a route no entity covers, and its " +
|
|
118
|
+
'prepare method builds the request without sending it.'
|
|
119
|
+
: "No entity carries an operation: every route is reached through the client's " +
|
|
120
|
+
'direct method, and its prepare method builds the request without sending it.',
|
|
121
|
+
]
|
|
122
|
+
Content(`## Rules
|
|
123
|
+
|
|
124
|
+
${rules.map((rule) => wrapText(rule, 72, '- ', ' ')).join('\n')}
|
|
125
|
+
|
|
126
|
+
`)
|
|
127
|
+
|
|
128
|
+
if (0 < entities.length) {
|
|
129
|
+
Content(`## Entities
|
|
130
|
+
|
|
131
|
+
`)
|
|
132
|
+
for (const ent of entities) {
|
|
133
|
+
const desc = fact(ent, 'desc').inline
|
|
134
|
+
const ops = entityOps(ent)
|
|
135
|
+
Content(`### ${ent.Name}
|
|
136
|
+
|
|
137
|
+
${'' === desc ? '' : desc + '\n\n'}`)
|
|
138
|
+
if (0 === ops.length) {
|
|
139
|
+
Content(`No operation; reach its routes with \`direct()\`.
|
|
140
|
+
|
|
141
|
+
`)
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
Content(`| Operation | Method | Route |
|
|
145
|
+
| --- | --- | --- |
|
|
146
|
+
${CANON_OP_ORDER.filter((o: string) => ops.includes(o)).map((o: string) => {
|
|
147
|
+
const route = opRoute(ent.op[o])
|
|
148
|
+
return `| \`${o}\` | ${route.method} | \`${route.path}\` |`
|
|
149
|
+
}).join('\n')}
|
|
150
|
+
|
|
151
|
+
`)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
Content(`## Reference
|
|
156
|
+
|
|
157
|
+
${null == target
|
|
158
|
+
? 'Each language directory holds its own README.md, REFERENCE.md and SKILL.md.'
|
|
159
|
+
: 'README.md and REFERENCE.md beside this file give every signature and example.'}
|
|
160
|
+
`)
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
export {
|
|
166
|
+
Skill,
|
|
167
|
+
skillName,
|
|
168
|
+
}
|
package/src/helpers/naming.ts
CHANGED
|
@@ -440,6 +440,24 @@ function exampleVarName(name: string, lang: string): string {
|
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
|
|
443
|
+
// Plurals go on a fixed noun, never on an entity name.
|
|
444
|
+
function entityItemsPhrase(name: string): string {
|
|
445
|
+
return 'the ' + name + ' items'
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
const KEBAB_VARS = new Set(['clojure'])
|
|
450
|
+
const SNAKE_VARS = new Set(['py', 'rb', 'php', 'perl', 'lua', 'elixir', 'rust', 'c', 'cpp', 'zig', 'ocaml'])
|
|
451
|
+
|
|
452
|
+
// The variable holding a list result, from the variable for one of its items.
|
|
453
|
+
function entityListVar(name: string, lang: string): string {
|
|
454
|
+
const base = String(name).replace(/_+$/, '')
|
|
455
|
+
if (KEBAB_VARS.has(lang)) return base + '-list'
|
|
456
|
+
if (SNAKE_VARS.has(lang)) return base + '_list'
|
|
457
|
+
return base + 'List'
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
|
|
443
461
|
function prefixLeadingDigit(s: string): string {
|
|
444
462
|
if (null == s || '' === s) return s
|
|
445
463
|
const first = s.charCodeAt(0)
|
|
@@ -496,6 +514,8 @@ export {
|
|
|
496
514
|
isReservedName,
|
|
497
515
|
safeVarName,
|
|
498
516
|
exampleVarName,
|
|
517
|
+
entityItemsPhrase,
|
|
518
|
+
entityListVar,
|
|
499
519
|
phpEntityAccessor,
|
|
500
520
|
entityCacheField,
|
|
501
521
|
isRbCoreConstant,
|