@voxgig/sdkgen 4.45.0 → 4.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/action/check.js +73 -4
- package/dist/action/check.js.map +1 -1
- package/dist/action/copies.js +1 -0
- package/dist/action/copies.js.map +1 -1
- package/dist/action/doctor.d.ts +26 -2
- package/dist/action/doctor.js +208 -11
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/package.d.ts +1 -1
- package/dist/action/package.js +15 -16
- package/dist/action/package.js.map +1 -1
- package/dist/action/remove.js +16 -4
- package/dist/action/remove.js.map +1 -1
- package/dist/action/resolve.d.ts +1 -0
- package/dist/action/resolve.js +10 -4
- package/dist/action/resolve.js.map +1 -1
- package/dist/action/target.d.ts +2 -1
- package/dist/action/target.js +50 -11
- package/dist/action/target.js.map +1 -1
- package/dist/admin/status.d.ts +7 -1
- package/dist/admin/status.js +34 -5
- package/dist/admin/status.js.map +1 -1
- package/dist/cmp/AgentGuide.js +46 -23
- package/dist/cmp/AgentGuide.js.map +1 -1
- package/dist/cmp/AgentGuideContent.d.ts +9 -7
- package/dist/cmp/AgentGuideContent.js +73 -43
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/AgentGuideFeature.js +19 -9
- package/dist/cmp/AgentGuideFeature.js.map +1 -1
- package/dist/cmp/AgentGuideTop.js +95 -49
- package/dist/cmp/AgentGuideTop.js.map +1 -1
- package/dist/cmp/Changelog.js +45 -4
- package/dist/cmp/Changelog.js.map +1 -1
- package/dist/cmp/Deploy.js +73 -35
- package/dist/cmp/Deploy.js.map +1 -1
- package/dist/cmp/Entity.js +1 -1
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/ExternalTarget.js +10 -5
- package/dist/cmp/ExternalTarget.js.map +1 -1
- package/dist/cmp/Feature.js +12 -5
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureDocs.d.ts +6 -4
- package/dist/cmp/FeatureDocs.js +14 -39
- package/dist/cmp/FeatureDocs.js.map +1 -1
- package/dist/cmp/FeatureHook.d.ts +7 -1
- package/dist/cmp/FeatureHook.js +34 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js +1 -1
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/PublishWorkflow.js +89 -55
- package/dist/cmp/PublishWorkflow.js.map +1 -1
- package/dist/cmp/ReadmeErrors.js +521 -18
- package/dist/cmp/ReadmeErrors.js.map +1 -1
- package/dist/cmp/ReadmeExplanation.js +280 -44
- package/dist/cmp/ReadmeExplanation.js.map +1 -1
- package/dist/cmp/ReadmeFeatures.js +16 -7
- package/dist/cmp/ReadmeFeatures.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +4 -3
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeModel.js +2 -2
- package/dist/cmp/ReadmeModel.js.map +1 -1
- package/dist/cmp/ReadmeRefFeatures.js +34 -24
- package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
- package/dist/cmp/ReadmeStation.js +12 -9
- package/dist/cmp/ReadmeStation.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +479 -382
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/cmp/ReadmeUnions.js +8 -2
- package/dist/cmp/ReadmeUnions.js.map +1 -1
- package/dist/cmp/Registered.js +1 -1
- package/dist/cmp/Registered.js.map +1 -1
- package/dist/cmp/Security.js +26 -5
- package/dist/cmp/Security.js.map +1 -1
- package/dist/cmp/Test.js +1 -1
- package/dist/cmp/Test.js.map +1 -1
- package/dist/helpers/alongside.d.ts +2 -3
- package/dist/helpers/alongside.js +16 -15
- package/dist/helpers/alongside.js.map +1 -1
- package/dist/helpers/applicability.d.ts +3 -1
- package/dist/helpers/applicability.js +40 -1
- package/dist/helpers/applicability.js.map +1 -1
- package/dist/helpers/component.js +9 -1
- package/dist/helpers/component.js.map +1 -1
- package/dist/helpers/copymerge.d.ts +3 -0
- package/dist/helpers/copymerge.js +43 -10
- package/dist/helpers/copymerge.js.map +1 -1
- package/dist/helpers/definitionPlan.js +0 -1
- package/dist/helpers/definitionPlan.js.map +1 -1
- package/dist/helpers/doccheck.d.ts +11 -0
- package/dist/helpers/doccheck.js +146 -0
- package/dist/helpers/doccheck.js.map +1 -0
- package/dist/helpers/doctext.d.ts +11 -0
- package/dist/helpers/doctext.js +85 -0
- package/dist/helpers/doctext.js.map +1 -0
- package/dist/helpers/exampleCall.d.ts +16 -0
- package/dist/helpers/exampleCall.js +334 -0
- package/dist/helpers/exampleCall.js.map +1 -0
- package/dist/helpers/exportnames.d.ts +4 -0
- package/dist/helpers/exportnames.js +35 -0
- package/dist/helpers/exportnames.js.map +1 -0
- package/dist/helpers/facts.d.ts +2 -1
- package/dist/helpers/facts.js +210 -5
- package/dist/helpers/facts.js.map +1 -1
- package/dist/helpers/flowGuard.d.ts +1 -1
- package/dist/helpers/flowGuard.js +20 -7
- package/dist/helpers/flowGuard.js.map +1 -1
- package/dist/helpers/generated.d.ts +1 -0
- package/dist/helpers/generated.js +1 -1
- package/dist/helpers/generated.js.map +1 -1
- package/dist/helpers/graphqlPoint.d.ts +2 -1
- package/dist/helpers/graphqlPoint.js +17 -0
- package/dist/helpers/graphqlPoint.js.map +1 -1
- package/dist/helpers/guardModel.d.ts +2 -0
- package/dist/helpers/guardModel.js +41 -0
- package/dist/helpers/guardModel.js.map +1 -0
- package/dist/helpers/manifest.d.ts +2 -1
- package/dist/helpers/manifest.js +16 -0
- package/dist/helpers/manifest.js.map +1 -1
- package/dist/helpers/mcpTools.d.ts +2 -1
- package/dist/helpers/mcpTools.js +8 -1
- package/dist/helpers/mcpTools.js.map +1 -1
- package/dist/helpers/modelcheck.d.ts +2 -1
- package/dist/helpers/modelcheck.js +13 -0
- package/dist/helpers/modelcheck.js.map +1 -1
- package/dist/helpers/opExample.d.ts +9 -2
- package/dist/helpers/opExample.js +22 -2
- package/dist/helpers/opExample.js.map +1 -1
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +29 -17
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/packageMeta.d.ts +6 -4
- package/dist/helpers/packageMeta.js +88 -53
- package/dist/helpers/packageMeta.js.map +1 -1
- package/dist/helpers/placement.d.ts +15 -0
- package/dist/helpers/placement.js +76 -0
- package/dist/helpers/placement.js.map +1 -0
- package/dist/helpers/semver.d.ts +3 -1
- package/dist/helpers/semver.js +28 -0
- package/dist/helpers/semver.js.map +1 -1
- package/dist/helpers/serverVars.js +3 -2
- package/dist/helpers/serverVars.js.map +1 -1
- package/dist/helpers/shipped.d.ts +2 -1
- package/dist/helpers/shipped.js +12 -0
- package/dist/helpers/shipped.js.map +1 -1
- package/dist/helpers/sourcestring.d.ts +3 -0
- package/dist/helpers/sourcestring.js +43 -0
- package/dist/helpers/sourcestring.js.map +1 -0
- package/dist/helpers/stdrep.d.ts +1 -1
- package/dist/helpers/stdrep.js +5 -1
- package/dist/helpers/stdrep.js.map +1 -1
- package/dist/helpers/surface.d.ts +7 -0
- package/dist/helpers/surface.js +69 -0
- package/dist/helpers/surface.js.map +1 -0
- package/dist/helpers/targetguard.d.ts +13 -0
- package/dist/helpers/targetguard.js +65 -0
- package/dist/helpers/targetguard.js.map +1 -0
- package/dist/helpers/text.d.ts +3 -1
- package/dist/helpers/text.js +16 -0
- package/dist/helpers/text.js.map +1 -1
- package/dist/helpers/textguard.d.ts +31 -0
- package/dist/helpers/textguard.js +157 -0
- package/dist/helpers/textguard.js.map +1 -0
- package/dist/helpers/title.d.ts +4 -0
- package/dist/helpers/title.js +52 -0
- package/dist/helpers/title.js.map +1 -0
- package/dist/sdkgen.d.ts +4 -6
- package/dist/sdkgen.js +72 -63
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.d.ts +7 -2
- package/dist/testkit.js +27 -20
- package/dist/testkit.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +2 -1
- package/dist/utility.js.map +1 -1
- package/model/fact.aontu +150 -0
- package/model/sdkgen.aontu +15 -3
- package/package.json +3 -1
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +2 -2
- package/project/.sdk/src/cmp/c/ReadmeTopQuick_c.ts +1 -1
- package/project/.sdk/src/cmp/clojure/ReadmeEntity_clojure.ts +12 -3
- package/project/.sdk/src/cmp/clojure/ReadmeQuick_clojure.ts +1 -1
- package/project/.sdk/src/cmp/cpp/ReadmeQuick_cpp.ts +1 -1
- package/project/.sdk/src/cmp/csharp/ReadmeQuick_csharp.ts +1 -1
- package/project/.sdk/src/cmp/elixir/ReadmeQuick_elixir.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
- package/project/.sdk/src/cmp/java/ReadmeQuick_java.ts +1 -1
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +1 -1
- package/project/.sdk/src/cmp/kotlin/ReadmeQuick_kotlin.ts +1 -1
- package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +1 -1
- package/project/.sdk/src/cmp/ocaml/ReadmeQuick_ocaml.ts +1 -1
- package/project/.sdk/src/cmp/perl/ReadmeQuick_perl.ts +1 -1
- package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +1 -1
- package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +1 -1
- package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +1 -1
- package/project/.sdk/src/cmp/scala/ReadmeQuick_scala.ts +1 -1
- package/project/.sdk/src/cmp/scala/ReadmeRef_scala.ts +4 -1
- package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +2 -1
- package/project/.sdk/src/cmp/swift/ReadmeRef_swift.ts +3 -0
- package/project/.sdk/src/cmp/swift/ReadmeTopQuick_swift.ts +2 -1
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/TestDefinition_ts.ts +3 -1
- package/project/.sdk/src/cmp/zig/ReadmeOptions_zig.ts +1 -1
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +3 -3
- package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +3 -1
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +2 -1
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +11 -2
- package/project/sdkgen-package.json +1 -1
- package/src/action/check.ts +99 -4
- package/src/action/copies.ts +2 -0
- package/src/action/doctor.ts +304 -15
- package/src/action/package.ts +11 -13
- package/src/action/remove.ts +20 -5
- package/src/action/resolve.ts +11 -4
- package/src/action/target.ts +66 -15
- package/src/admin/status.ts +25 -5
- package/src/cmp/AgentGuide.ts +52 -25
- package/src/cmp/AgentGuideContent.ts +75 -43
- package/src/cmp/AgentGuideFeature.ts +21 -10
- package/src/cmp/AgentGuideTop.ts +119 -49
- package/src/cmp/Changelog.ts +56 -5
- package/src/cmp/Deploy.ts +81 -40
- package/src/cmp/Entity.ts +1 -1
- package/src/cmp/ExternalTarget.ts +12 -6
- package/src/cmp/Feature.ts +13 -6
- package/src/cmp/FeatureDocs.ts +21 -40
- package/src/cmp/FeatureHook.ts +38 -1
- package/src/cmp/Main.ts +1 -1
- package/src/cmp/PublishWorkflow.ts +94 -60
- package/src/cmp/ReadmeErrors.ts +555 -25
- package/src/cmp/ReadmeExplanation.ts +316 -52
- package/src/cmp/ReadmeFeatures.ts +18 -8
- package/src/cmp/ReadmeIntro.ts +4 -3
- package/src/cmp/ReadmeModel.ts +2 -2
- package/src/cmp/ReadmeRefFeatures.ts +39 -27
- package/src/cmp/ReadmeStation.ts +13 -16
- package/src/cmp/ReadmeTop.ts +538 -397
- package/src/cmp/ReadmeUnions.ts +10 -2
- package/src/cmp/Registered.ts +1 -1
- package/src/cmp/Security.ts +35 -7
- package/src/cmp/Test.ts +1 -1
- package/src/helpers/alongside.ts +16 -19
- package/src/helpers/applicability.ts +44 -1
- package/src/helpers/component.ts +11 -1
- package/src/helpers/copymerge.ts +58 -10
- package/src/helpers/definitionPlan.ts +0 -1
- package/src/helpers/doccheck.ts +174 -0
- package/src/helpers/doctext.ts +115 -0
- package/src/helpers/exampleCall.ts +415 -0
- package/src/helpers/exportnames.ts +47 -0
- package/src/helpers/facts.ts +259 -5
- package/src/helpers/flowGuard.ts +22 -7
- package/src/helpers/generated.ts +3 -1
- package/src/helpers/graphqlPoint.ts +20 -1
- package/src/helpers/guardModel.ts +50 -0
- package/src/helpers/manifest.ts +19 -0
- package/src/helpers/mcpTools.ts +11 -1
- package/src/helpers/modelcheck.ts +16 -0
- package/src/helpers/opExample.ts +34 -2
- package/src/helpers/opShape.ts +29 -16
- package/src/helpers/packageMeta.ts +89 -52
- package/src/helpers/placement.ts +114 -0
- package/src/helpers/semver.ts +35 -0
- package/src/helpers/serverVars.ts +4 -2
- package/src/helpers/shipped.ts +13 -0
- package/src/helpers/sourcestring.ts +47 -0
- package/src/helpers/stdrep.ts +6 -1
- package/src/helpers/surface.ts +82 -0
- package/src/helpers/targetguard.ts +91 -0
- package/src/helpers/text.ts +22 -0
- package/src/helpers/textguard.ts +208 -0
- package/src/helpers/title.ts +59 -0
- package/src/sdkgen.ts +82 -78
- package/src/testkit.ts +42 -20
- package/src/utility.ts +2 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { KIT, nom } from '@voxgig/apidef'
|
|
2
|
+
|
|
3
|
+
import { modelText } from './text'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// One text a neutral document prints. `vendor` marks text from the spec, whose
|
|
7
|
+
// relative links resolve against the spec's site rather than this repository.
|
|
8
|
+
type DocText = {
|
|
9
|
+
raw: string
|
|
10
|
+
vendor: boolean
|
|
11
|
+
at: any
|
|
12
|
+
path: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// A struct.validate sentinel as a reader's word for it: '`$FUNCTION`' ->
|
|
17
|
+
// 'function'. A union renders its members, so netsim's latency reads
|
|
18
|
+
// 'number | map'. Anything unrecognised renders verbatim rather than being
|
|
19
|
+
// dropped — a doc table that silently omits an option is the failure this
|
|
20
|
+
// whole path exists to fix.
|
|
21
|
+
function sentinelName(v: any): string {
|
|
22
|
+
if (Array.isArray(v)) {
|
|
23
|
+
const members = v.slice(1).map((m: any) => sentinelName(m))
|
|
24
|
+
.filter((m: string) => 'one' !== m)
|
|
25
|
+
return 0 === members.length ? 'any' : members.join(' | ')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if ('string' !== typeof v) {
|
|
29
|
+
return 'any'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const bare = v.replace(/[`$]/g, '').trim().toLowerCase()
|
|
33
|
+
return '' === bare ? 'any' : bare
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function renderValue(v: any): string {
|
|
38
|
+
if (null == v) { return '' }
|
|
39
|
+
if (Array.isArray(v)) { return '[' + v.map((x) => renderValue(x)).join(', ') + ']' }
|
|
40
|
+
if ('object' === typeof v) {
|
|
41
|
+
const keys = Object.keys(v)
|
|
42
|
+
return 0 === keys.length ? '{}' :
|
|
43
|
+
'{' + keys.map((k) => k + ': ' + renderValue(v[k])).join(', ') + '}'
|
|
44
|
+
}
|
|
45
|
+
if ('string' === typeof v) { return `'${v}'` }
|
|
46
|
+
return String(v)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function given(value: any): boolean {
|
|
51
|
+
return null != value && '' !== value
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function str(value: any, trim = false): string {
|
|
56
|
+
return !given(value) ? '' : trim ? String(value).trim() : String(value)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Every text the neutral documents print from the model, as they print it,
|
|
61
|
+
// with the node its escaped forms are written beside.
|
|
62
|
+
function docTexts(model: any): DocText[] {
|
|
63
|
+
const kit = model.main[KIT]
|
|
64
|
+
const info = modelText(model)
|
|
65
|
+
const own = kit.text || {}
|
|
66
|
+
const def = model.main.def || {}
|
|
67
|
+
const texts: DocText[] = []
|
|
68
|
+
|
|
69
|
+
const add = (at: any, path: string[], raw: string, vendor: boolean) =>
|
|
70
|
+
texts.push({ raw, vendor, at, path })
|
|
71
|
+
|
|
72
|
+
const slot = (name: string, raw: string) =>
|
|
73
|
+
add(kit, ['text', name], raw, !given(own[name]))
|
|
74
|
+
|
|
75
|
+
slot('title', str(info.title))
|
|
76
|
+
add(kit, ['apiName'], str(info.title) || nom(model, 'Name') + ' API',
|
|
77
|
+
given(info.title) && !given(own.title))
|
|
78
|
+
slot('tagline', str(info.tagline) || str(def.tagline))
|
|
79
|
+
slot('summary', str(info.summary, true))
|
|
80
|
+
slot('about_md', str(info.about_md, true))
|
|
81
|
+
slot('website', str(info.website, true))
|
|
82
|
+
slot('meta_source', str(info.meta_source, true))
|
|
83
|
+
slot('docs_url', str(info.docs_url))
|
|
84
|
+
add(kit, ['text', 'desc'], str(def.desc), true)
|
|
85
|
+
add(kit, ['text', 'upstream'], str(info.contact?.url) || str(info.servers?.[0]?.url) ||
|
|
86
|
+
str(info.homepage), true)
|
|
87
|
+
|
|
88
|
+
for (const [name, ent] of Object.entries(kit.entity || {}) as [string, any][]) {
|
|
89
|
+
add(ent, ['desc'], str(info.entity_desc[name]) || str(ent.short) || str(ent.desc),
|
|
90
|
+
!given(own.entity_desc?.[name]))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const f of Object.values(kit.feature || {}) as any[]) {
|
|
94
|
+
add(f, ['title'], str(f.title), false)
|
|
95
|
+
const opts = f.config?.options || {}
|
|
96
|
+
const spec = f.config?.optspec || {}
|
|
97
|
+
for (const k of Object.keys(opts)) {
|
|
98
|
+
add(f, ['option', k, 'value'], renderValue(opts[k]), false)
|
|
99
|
+
}
|
|
100
|
+
for (const k of Object.keys(spec).filter((k) => null == opts[k])) {
|
|
101
|
+
add(f, ['option', k, 'type'], sentinelName(spec[k]), false)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return texts
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
docTexts,
|
|
111
|
+
renderValue,
|
|
112
|
+
sentinelName,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type { DocText }
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
|
|
2
|
+
import { camelify } from 'jostraca'
|
|
3
|
+
|
|
4
|
+
import { canonScalarKey } from './canonType'
|
|
5
|
+
import { entityCollection } from './opShape'
|
|
6
|
+
import { exampleArgItems, javaMapOf } from './opExample'
|
|
7
|
+
import type { ArgItem } from './opExample'
|
|
8
|
+
import { elixirAccessor, exampleVarName } from './naming'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// The bundled languages outside EXAMPLE_LANGS, whose call text the wording
|
|
12
|
+
// tables write themselves. Each grammar follows the language's own quick start.
|
|
13
|
+
type CallLang = 'c' | 'clojure' | 'cpp' | 'csharp' | 'elixir' | 'java' | 'kotlin' |
|
|
14
|
+
'ocaml' | 'perl' | 'rust' | 'scala' | 'swift' | 'zig'
|
|
15
|
+
|
|
16
|
+
type ExampleInput = {
|
|
17
|
+
model: any
|
|
18
|
+
ent: any
|
|
19
|
+
op: string
|
|
20
|
+
idF: string | null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type ExampleParts = {
|
|
24
|
+
// A local naming the entity, clear of the names the examples declare.
|
|
25
|
+
v: string
|
|
26
|
+
// The expression that makes the entity, from `client` (`sdk` in elixir).
|
|
27
|
+
factory: string
|
|
28
|
+
// The primary op's argument, or the language's empty value.
|
|
29
|
+
arg: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Grammar = {
|
|
33
|
+
str: (s: string) => string
|
|
34
|
+
int: string
|
|
35
|
+
float: string
|
|
36
|
+
bool: string
|
|
37
|
+
nul: string
|
|
38
|
+
arr: string
|
|
39
|
+
obj: string
|
|
40
|
+
map: (pairs: [string, string][], x: ExampleInput) => string
|
|
41
|
+
none: (op: string, x: ExampleInput) => string
|
|
42
|
+
// Map.of rejects a null value.
|
|
43
|
+
dropNull?: boolean
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const C_RESERVED = new Set([
|
|
48
|
+
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
|
|
49
|
+
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if', 'inline',
|
|
50
|
+
'int', 'long', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof',
|
|
51
|
+
'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void',
|
|
52
|
+
'volatile', 'while', 'bool', 'true', 'false',
|
|
53
|
+
])
|
|
54
|
+
|
|
55
|
+
const CPP_RESERVED = new Set([
|
|
56
|
+
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor',
|
|
57
|
+
'bool', 'break', 'case', 'catch', 'char', 'char16_t', 'char32_t', 'class',
|
|
58
|
+
'compl', 'const', 'constexpr', 'const_cast', 'continue', 'decltype',
|
|
59
|
+
'default', 'delete', 'do', 'double', 'dynamic_cast', 'else', 'enum',
|
|
60
|
+
'explicit', 'export', 'extern', 'false', 'float', 'for', 'friend', 'goto',
|
|
61
|
+
'if', 'inline', 'int', 'long', 'mutable', 'namespace', 'new', 'noexcept',
|
|
62
|
+
'not', 'not_eq', 'nullptr', 'operator', 'or', 'or_eq', 'private',
|
|
63
|
+
'protected', 'public', 'register', 'reinterpret_cast', 'return', 'short',
|
|
64
|
+
'signed', 'sizeof', 'static', 'static_assert', 'static_cast', 'struct',
|
|
65
|
+
'switch', 'template', 'this', 'thread_local', 'throw', 'true', 'try',
|
|
66
|
+
'typedef', 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual',
|
|
67
|
+
'void', 'volatile', 'wchar_t', 'while', 'xor', 'xor_eq',
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
const RUST_RESERVED = new Set([
|
|
71
|
+
'as', 'async', 'await', 'break', 'const', 'continue', 'crate', 'dyn',
|
|
72
|
+
'else', 'enum', 'extern', 'false', 'fn', 'for', 'if', 'impl', 'in',
|
|
73
|
+
'let', 'loop', 'match', 'mod', 'move', 'mut', 'pub', 'ref', 'return',
|
|
74
|
+
'self', 'Self', 'static', 'struct', 'super', 'trait', 'true', 'type',
|
|
75
|
+
'unsafe', 'use', 'where', 'while',
|
|
76
|
+
'abstract', 'become', 'box', 'do', 'final', 'macro', 'override', 'priv',
|
|
77
|
+
'try', 'typeof', 'unsized', 'virtual', 'yield',
|
|
78
|
+
])
|
|
79
|
+
|
|
80
|
+
// Methods every rust entity already has, which an accessor must not shadow.
|
|
81
|
+
const RUST_METHOD_RESERVED = new Set([
|
|
82
|
+
'clone', 'new', 'default', 'drop', 'from', 'into', 'to_string',
|
|
83
|
+
'as_ref', 'as_mut', 'borrow', 'borrow_mut', 'deref', 'deref_mut',
|
|
84
|
+
'eq', 'ne', 'cmp', 'partial_cmp', 'hash', 'fmt', 'next', 'iter',
|
|
85
|
+
])
|
|
86
|
+
|
|
87
|
+
const ZIG_RESERVED = new Set([
|
|
88
|
+
'addrspace', 'align', 'allowzero', 'and', 'anyframe', 'anytype', 'asm',
|
|
89
|
+
'async', 'await', 'break', 'callconv', 'catch', 'comptime', 'const',
|
|
90
|
+
'continue', 'defer', 'else', 'enum', 'errdefer', 'error', 'export',
|
|
91
|
+
'extern', 'fn', 'for', 'if', 'inline', 'noalias', 'nosuspend', 'noinline',
|
|
92
|
+
'opaque', 'or', 'orelse', 'packed', 'pub', 'resume', 'return',
|
|
93
|
+
'linksection', 'struct', 'suspend', 'switch', 'test', 'threadlocal', 'try',
|
|
94
|
+
'union', 'unreachable', 'usingnamespace', 'var', 'volatile', 'while',
|
|
95
|
+
])
|
|
96
|
+
|
|
97
|
+
const OCAML_RESERVED = new Set([
|
|
98
|
+
'and', 'as', 'assert', 'asr', 'begin', 'class', 'constraint', 'do', 'done',
|
|
99
|
+
'downto', 'else', 'end', 'exception', 'external', 'false', 'for', 'fun',
|
|
100
|
+
'function', 'functor', 'if', 'in', 'include', 'inherit', 'initializer',
|
|
101
|
+
'land', 'lazy', 'let', 'lor', 'lsl', 'lsr', 'lxor', 'match', 'method', 'mod',
|
|
102
|
+
'module', 'mutable', 'new', 'nonrec', 'object', 'of', 'open', 'or', 'private',
|
|
103
|
+
'rec', 'sig', 'struct', 'then', 'to', 'true', 'try', 'type', 'val', 'virtual',
|
|
104
|
+
'when', 'while', 'with',
|
|
105
|
+
])
|
|
106
|
+
|
|
107
|
+
const JAVA_RESERVED = new Set([
|
|
108
|
+
'abstract', 'assert', 'boolean', 'break', 'byte', 'case', 'catch', 'char',
|
|
109
|
+
'class', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum',
|
|
110
|
+
'extends', 'final', 'finally', 'float', 'for', 'goto', 'if', 'implements',
|
|
111
|
+
'import', 'instanceof', 'int', 'interface', 'long', 'native', 'new',
|
|
112
|
+
'package', 'private', 'protected', 'public', 'return', 'short', 'static',
|
|
113
|
+
'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws',
|
|
114
|
+
'transient', 'try', 'void', 'volatile', 'while',
|
|
115
|
+
'true', 'false', 'null', 'var', 'record', 'yield',
|
|
116
|
+
])
|
|
117
|
+
|
|
118
|
+
const KOTLIN_RESERVED = new Set([
|
|
119
|
+
'as', 'break', 'class', 'continue', 'do', 'else', 'false', 'for', 'fun',
|
|
120
|
+
'if', 'in', 'interface', 'is', 'null', 'object', 'package', 'return',
|
|
121
|
+
'super', 'this', 'throw', 'true', 'try', 'typealias', 'typeof', 'val',
|
|
122
|
+
'var', 'when', 'while',
|
|
123
|
+
])
|
|
124
|
+
|
|
125
|
+
const SCALA_RESERVED = new Set([
|
|
126
|
+
'abstract', 'case', 'catch', 'class', 'def', 'do', 'else', 'enum', 'export',
|
|
127
|
+
'extends', 'false', 'final', 'finally', 'for', 'forSome', 'given', 'if',
|
|
128
|
+
'implicit', 'import', 'lazy', 'match', 'new', 'null', 'object', 'override',
|
|
129
|
+
'package', 'private', 'protected', 'return', 'sealed', 'super', 'then',
|
|
130
|
+
'this', 'throw', 'trait', 'true', 'try', 'type', 'val', 'var', 'while',
|
|
131
|
+
'with', 'yield',
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
const CS_RESERVED = new Set([
|
|
135
|
+
'abstract', 'as', 'base', 'bool', 'break', 'byte', 'case', 'catch',
|
|
136
|
+
'char', 'checked', 'class', 'const', 'continue', 'decimal', 'default',
|
|
137
|
+
'delegate', 'do', 'double', 'else', 'enum', 'event', 'explicit',
|
|
138
|
+
'extern', 'false', 'finally', 'fixed', 'float', 'for', 'foreach',
|
|
139
|
+
'goto', 'if', 'implicit', 'in', 'int', 'interface', 'internal', 'is',
|
|
140
|
+
'lock', 'long', 'namespace', 'new', 'null', 'object', 'operator',
|
|
141
|
+
'out', 'override', 'params', 'private', 'protected', 'public',
|
|
142
|
+
'readonly', 'ref', 'return', 'sbyte', 'sealed', 'short', 'sizeof',
|
|
143
|
+
'stackalloc', 'static', 'string', 'struct', 'switch', 'this', 'throw',
|
|
144
|
+
'true', 'try', 'typeof', 'uint', 'ulong', 'unchecked', 'unsafe',
|
|
145
|
+
'ushort', 'using', 'virtual', 'void', 'volatile', 'while',
|
|
146
|
+
])
|
|
147
|
+
|
|
148
|
+
const SWIFT_RESERVED = new Set([
|
|
149
|
+
'associatedtype', 'class', 'deinit', 'enum', 'extension', 'fileprivate',
|
|
150
|
+
'func', 'import', 'init', 'inout', 'internal', 'let', 'open', 'operator',
|
|
151
|
+
'private', 'precedencegroup', 'protocol', 'public', 'rethrows', 'static',
|
|
152
|
+
'struct', 'subscript', 'typealias', 'var', 'break', 'case', 'catch',
|
|
153
|
+
'continue', 'default', 'defer', 'do', 'else', 'fallthrough', 'for', 'guard',
|
|
154
|
+
'if', 'in', 'repeat', 'return', 'switch', 'where', 'while', 'as', 'false',
|
|
155
|
+
'is', 'nil', 'self', 'super', 'throw', 'throws', 'true', 'try', 'any',
|
|
156
|
+
'some', 'await', 'actor',
|
|
157
|
+
])
|
|
158
|
+
|
|
159
|
+
// The names the wording tables' own examples declare or are given, which an
|
|
160
|
+
// entity variable would shadow; zig refuses any shadowing outright.
|
|
161
|
+
const EXAMPLE_TAKEN = new Set(['client', 'err', 'result', 'sdk', 'std', 'h', 'e', 'i', 'item'])
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
function snake(name: string): string {
|
|
165
|
+
return String(name).replace(/[^a-zA-Z0-9_]/g, '_').toLowerCase()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function lowerCamel(name: string): string {
|
|
169
|
+
const pascal = camelify(name)
|
|
170
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function suffixed(name: string, reserved: Set<string>): string {
|
|
174
|
+
return reserved.has(name) ? name + '_' : name
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function cVarName(name: string): string {
|
|
178
|
+
const s = snake(name)
|
|
179
|
+
return suffixed(/^[0-9]/.test(s) ? '_' + s : s, C_RESERVED)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function rustVarName(name: string): string {
|
|
183
|
+
const s = snake(name)
|
|
184
|
+
return suffixed(/^[0-9]/.test(s) ? '_' + s : s, RUST_RESERVED)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function ocamlVarName(name: string): string {
|
|
188
|
+
const s = snake(name)
|
|
189
|
+
return suffixed('' === s || !/^[a-z_]/.test(s) ? '_' + s : s, OCAML_RESERVED)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function swiftVarName(name: string): string {
|
|
193
|
+
const lower = lowerCamel(String(name).replace(/[^\p{L}\p{N}_]/gu, '_'))
|
|
194
|
+
if (SWIFT_RESERVED.has(lower)) {
|
|
195
|
+
return lower + '_'
|
|
196
|
+
}
|
|
197
|
+
return /^[0-9]/.test(lower) ? '_' + lower : lower
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
// Each language's own name for an entity variable and for its accessor.
|
|
202
|
+
const VAR_NAME: Record<CallLang, (name: string) => string> = {
|
|
203
|
+
c: cVarName,
|
|
204
|
+
clojure: (name) => name,
|
|
205
|
+
cpp: (name) => suffixed(snake(name), CPP_RESERVED),
|
|
206
|
+
csharp: (name) => suffixed(lowerCamel(name), CS_RESERVED),
|
|
207
|
+
elixir: (name) => exampleVarName(name, 'elixir'),
|
|
208
|
+
java: (name) => suffixed(lowerCamel(name), JAVA_RESERVED),
|
|
209
|
+
kotlin: (name) => suffixed(lowerCamel(name), KOTLIN_RESERVED),
|
|
210
|
+
ocaml: ocamlVarName,
|
|
211
|
+
perl: (name) => camelify(name).toLowerCase(),
|
|
212
|
+
rust: rustVarName,
|
|
213
|
+
scala: (name) => suffixed(lowerCamel(name), SCALA_RESERVED),
|
|
214
|
+
swift: swiftVarName,
|
|
215
|
+
zig: (name) => suffixed(snake(name), ZIG_RESERVED),
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function entityName(ent: any): string {
|
|
219
|
+
return ent.Name || (ent.name[0].toUpperCase() + ent.name.slice(1))
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const FACTORY: Record<CallLang, (x: ExampleInput) => string> = {
|
|
223
|
+
c: (x) => String(x.model.name).toLowerCase().replace(/[^a-z0-9]/g, '') + '_' +
|
|
224
|
+
cVarName(x.ent.name) + '(client, NULL)',
|
|
225
|
+
clojure: (x) => `(api/${x.ent.name} client nil)`,
|
|
226
|
+
cpp: (x) => `client->${VAR_NAME.cpp(x.ent.name)}()`,
|
|
227
|
+
csharp: (x) => `client.${entityName(x.ent)}()`,
|
|
228
|
+
elixir: (x) => `${x.model.const.Name}.${elixirAccessor(x.ent, entityCollection(x.model))}(sdk)`,
|
|
229
|
+
java: (x) => `client.${VAR_NAME.java(x.ent.name)}(null)`,
|
|
230
|
+
kotlin: (x) => `client.${VAR_NAME.kotlin(x.ent.name)}(null)`,
|
|
231
|
+
ocaml: (x) => `(Sdk_client.${ocamlVarName(x.ent.name)} client Noval)`,
|
|
232
|
+
perl: (x) => `$client->${entityName(x.ent)}`,
|
|
233
|
+
rust: (x) => {
|
|
234
|
+
const ident = rustVarName(x.ent.name)
|
|
235
|
+
return `client.${suffixed(ident, RUST_METHOD_RESERVED)}(Value::Noval)`
|
|
236
|
+
},
|
|
237
|
+
scala: (x) => `client.${VAR_NAME.scala(x.ent.name)}(null)`,
|
|
238
|
+
swift: (x) => `client.${entityName(x.ent)}()`,
|
|
239
|
+
zig: (x) => `client.${VAR_NAME.zig(x.ent.name)}(h.vnull())`,
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
function cString(s: string): string {
|
|
244
|
+
return '"' + s.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function ocamlString(s: string): string {
|
|
248
|
+
let out = ''
|
|
249
|
+
for (const c of s) {
|
|
250
|
+
const code = c.charCodeAt(0)
|
|
251
|
+
if ('\\' === c) out += '\\\\'
|
|
252
|
+
else if ('"' === c) out += '\\"'
|
|
253
|
+
else if ('\n' === c) out += '\\n'
|
|
254
|
+
else if ('\r' === c) out += '\\r'
|
|
255
|
+
else if ('\t' === c) out += '\\t'
|
|
256
|
+
else if (code < 0x20) out += '\\' + String(code).padStart(3, '0')
|
|
257
|
+
else out += c
|
|
258
|
+
}
|
|
259
|
+
return '"' + out + '"'
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function swiftString(s: string): string {
|
|
263
|
+
return '"' + s.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
|
|
264
|
+
.replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t') + '"'
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// `#` too: a double-quoted elixir string interpolates `#{...}`.
|
|
268
|
+
function elixirString(s: string): string {
|
|
269
|
+
return '"' + s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/#/g, '\\#')
|
|
270
|
+
.replace(/\n/g, '\\n').replace(/\t/g, '\\t') + '"'
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function cljString(s: string): string {
|
|
274
|
+
return '"' + s.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
|
|
275
|
+
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r') + '"'
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// A single-quoted perl string, so a `$` or `@` in it is never interpolated.
|
|
279
|
+
function perlString(s: string): string {
|
|
280
|
+
return "'" + s.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'"
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// U+0085, U+2028 and U+2029 end a C# string literal.
|
|
284
|
+
function csString(s: string): string {
|
|
285
|
+
return JSON.stringify(s).replace(/[\u0085\u2028\u2029]/g,
|
|
286
|
+
(c) => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0'))
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const jsonString = (s: string) => JSON.stringify(s)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
const GRAMMAR: Record<CallLang, Grammar> = {
|
|
293
|
+
c: {
|
|
294
|
+
str: (s) => `v_str(${cString(s)})`, int: 'v_num(1)', float: 'v_num(1)',
|
|
295
|
+
bool: 'v_bool(true)', nul: 'v_null()', arr: 'v_list()', obj: 'v_map()',
|
|
296
|
+
map: (pairs) => `cmap(${pairs.length}, ${pairs.map(([k, v]) => `${cString(k)}, ${v}`).join(', ')})`,
|
|
297
|
+
none: () => 'NULL',
|
|
298
|
+
},
|
|
299
|
+
clojure: {
|
|
300
|
+
str: cljString, int: '1', float: '1', bool: 'true', nul: 'nil', arr: '(vs/jt)', obj: '(vs/jm)',
|
|
301
|
+
map: (pairs) => `(vs/jm ${pairs.map(([k, v]) => `${cljString(k)} ${v}`).join(' ')})`,
|
|
302
|
+
none: () => 'nil',
|
|
303
|
+
},
|
|
304
|
+
cpp: {
|
|
305
|
+
str: (s) => `Value(${cString(s)})`, int: 'Value(1)', float: 'Value(1)',
|
|
306
|
+
bool: 'Value(true)', nul: 'Value(nullptr)', arr: 'vlist()', obj: 'vmap()',
|
|
307
|
+
map: (pairs) => `vmap({${pairs.map(([k, v]) => `{${cString(k)}, ${v}}`).join(', ')}})`,
|
|
308
|
+
none: () => 'Value::undef()',
|
|
309
|
+
},
|
|
310
|
+
csharp: {
|
|
311
|
+
str: csString, int: '1L', float: '1.0', bool: 'true', nul: 'null',
|
|
312
|
+
arr: 'new List<object?>()', obj: 'new Dictionary<string, object?>()',
|
|
313
|
+
map: (pairs) => `new Dictionary<string, object?> {${pairs.map(([k, v]) => ` [${csString(k)}] = ${v}`).join(',')} }`,
|
|
314
|
+
none: () => 'null',
|
|
315
|
+
},
|
|
316
|
+
elixir: {
|
|
317
|
+
str: elixirString, int: '1', float: '1', bool: 'true', nul: 'nil', arr: '[]', obj: '%{}',
|
|
318
|
+
map: (pairs, x) => `${x.model.const.Name}.Helpers.deep(%{${pairs.map(([k, v]) => `${elixirString(k)} => ${v}`).join(', ')}})`,
|
|
319
|
+
// list takes no match at all; the other ops take an empty one.
|
|
320
|
+
none: (op, x) => 'list' === op ? '' : `${x.model.const.Name}.Helpers.deep(%{})`,
|
|
321
|
+
},
|
|
322
|
+
java: {
|
|
323
|
+
str: jsonString, int: '1L', float: '1.0', bool: 'true', nul: 'null', arr: 'List.of()', obj: 'Map.of()',
|
|
324
|
+
map: (pairs) => javaMapOf(pairs.map(([k, v]) => `${jsonString(k)}, ${v}`)),
|
|
325
|
+
none: () => 'null',
|
|
326
|
+
dropNull: true,
|
|
327
|
+
},
|
|
328
|
+
kotlin: {
|
|
329
|
+
str: (s) => JSON.stringify(s).replace(/\$/g, '\\$'), int: '1L', float: '1.0', bool: 'true',
|
|
330
|
+
nul: 'null', arr: 'listOf<Any?>()', obj: 'mapOf<String, Any?>()',
|
|
331
|
+
map: (pairs) => `mutableMapOf<String, Any?>(${pairs.map(([k, v]) =>
|
|
332
|
+
`${JSON.stringify(k).replace(/\$/g, '\\$')} to ${v}`).join(', ')})`,
|
|
333
|
+
none: () => 'null',
|
|
334
|
+
},
|
|
335
|
+
ocaml: {
|
|
336
|
+
str: (s) => `(Str ${ocamlString(s)})`, int: '(Num 1.)', float: '(Num 1.)', bool: '(Bool true)',
|
|
337
|
+
nul: 'Null', arr: '(empty_list ())', obj: '(empty_map ())',
|
|
338
|
+
map: (pairs) => `(jo [${pairs.map(([k, v]) => `(${ocamlString(k)}, ${v})`).join('; ')}])`,
|
|
339
|
+
none: (op) => 'list' === op ? '(empty_map ())' : 'Noval',
|
|
340
|
+
},
|
|
341
|
+
perl: {
|
|
342
|
+
str: perlString, int: '1', float: '1', bool: '1', nul: 'undef', arr: '[]', obj: '{}',
|
|
343
|
+
map: (pairs) => `{ ${pairs.map(([k, v]) => `${perlString(k)} => ${v}`).join(', ')} }`,
|
|
344
|
+
none: () => '',
|
|
345
|
+
},
|
|
346
|
+
rust: {
|
|
347
|
+
str: (s) => `Value::str(${jsonString(s)})`, int: 'Value::Num(1.0)', float: 'Value::Num(1.0)',
|
|
348
|
+
bool: 'Value::Bool(true)', nul: 'Value::Null', arr: 'Value::empty_list()', obj: 'Value::empty_map()',
|
|
349
|
+
map: (pairs) => `jo(vec![${pairs.map(([k, v]) => `(${jsonString(k)}, ${v})`).join(', ')}])`,
|
|
350
|
+
none: () => 'Value::Noval',
|
|
351
|
+
},
|
|
352
|
+
scala: {
|
|
353
|
+
str: jsonString, int: '1L', float: '1.0', bool: 'true', nul: 'null',
|
|
354
|
+
arr: 'java.util.List.of()', obj: 'java.util.Map.of()',
|
|
355
|
+
map: (pairs) => javaMapOf(pairs.map(([k, v]) => `${jsonString(k)}, ${v}`), 'java.util.'),
|
|
356
|
+
none: () => 'null',
|
|
357
|
+
dropNull: true,
|
|
358
|
+
},
|
|
359
|
+
swift: {
|
|
360
|
+
str: (s) => `.string(${swiftString(s)})`, int: '.int(1)', float: '.double(1.0)', bool: '.bool(true)',
|
|
361
|
+
nul: '.null', arr: '.list([])', obj: '.map(VMap())',
|
|
362
|
+
map: (pairs) => `VMap([${pairs.map(([k, v]) => `(${swiftString(k)}, ${v})`).join(', ')}])`,
|
|
363
|
+
none: () => 'nil',
|
|
364
|
+
},
|
|
365
|
+
zig: {
|
|
366
|
+
str: (s) => `h.vstr(${jsonString(s)})`, int: 'h.vnum(1)', float: 'h.vnum(1)', bool: 'h.vbool(true)',
|
|
367
|
+
nul: 'h.vnull()', arr: 'h.olist()', obj: 'h.omap()',
|
|
368
|
+
map: (pairs) => `h.jo(&.{${pairs.map(([k, v]) => `.{ ${jsonString(k)}, ${v} }`).join(', ')}})`,
|
|
369
|
+
none: () => 'h.vnull()',
|
|
370
|
+
},
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
// An id is numeric when its type is, and otherwise the string the ts row sends.
|
|
375
|
+
function valueFor(g: Grammar, it: ArgItem): string {
|
|
376
|
+
const k = canonScalarKey(it.type)
|
|
377
|
+
if (it.id) {
|
|
378
|
+
return 'INTEGER' === k ? g.int : ('NUMBER' === k ? g.float : g.str('example_id'))
|
|
379
|
+
}
|
|
380
|
+
switch (k) {
|
|
381
|
+
case 'NULL': return g.nul
|
|
382
|
+
case 'INTEGER': return g.int
|
|
383
|
+
case 'NUMBER': return g.float
|
|
384
|
+
case 'BOOLEAN': return g.bool
|
|
385
|
+
case 'ARRAY': return g.arr
|
|
386
|
+
case 'OBJECT': return g.obj
|
|
387
|
+
default: return g.str('example')
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
function exampleParts(lang: CallLang, x: ExampleInput): ExampleParts {
|
|
393
|
+
const g = GRAMMAR[lang]
|
|
394
|
+
const items = exampleArgItems(x.ent, x.op, x.idF)
|
|
395
|
+
.filter((it: ArgItem) => !g.dropNull || 'NULL' !== canonScalarKey(it.type))
|
|
396
|
+
const v = VAR_NAME[lang](x.ent.name)
|
|
397
|
+
return {
|
|
398
|
+
v: EXAMPLE_TAKEN.has(v) ? v + '_' : v,
|
|
399
|
+
factory: FACTORY[lang](x),
|
|
400
|
+
arg: 0 === items.length ? g.none(x.op, x) :
|
|
401
|
+
g.map(items.map((it: ArgItem) => [it.name, valueFor(g, it)]), x),
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
export {
|
|
407
|
+
exampleParts,
|
|
408
|
+
entityName,
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export type {
|
|
412
|
+
CallLang,
|
|
413
|
+
ExampleInput,
|
|
414
|
+
ExampleParts,
|
|
415
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Read lexically, from lines that start in the first column: the components
|
|
2
|
+
// also hold generated TypeScript in template strings, and its interpolated
|
|
3
|
+
// names never parse as identifiers here.
|
|
4
|
+
const DECLARED_RE = /^export\s+(?:declare\s+)?(?:default\s+)?(?:abstract\s+)?(?:async\s+)?(?:function\*?|class|const|let|var|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)(?=[\s(<:=;,]|$)/gm
|
|
5
|
+
|
|
6
|
+
const LISTED_RE = /^export\s+(?:type\s+)?\{([^}]*)\}/gm
|
|
7
|
+
|
|
8
|
+
const NAME_RE = /^[A-Za-z_$][\w$]*$/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function exportedNames(src: string): Set<string> {
|
|
12
|
+
const names = new Set<string>()
|
|
13
|
+
|
|
14
|
+
for (const m of src.matchAll(DECLARED_RE)) {
|
|
15
|
+
names.add(m[1])
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (const m of src.matchAll(LISTED_RE)) {
|
|
19
|
+
for (const part of m[1].split(',')) {
|
|
20
|
+
const name = part.trim().replace(/^type\s+/, '').split(/\s+as\s+/).pop()?.trim() ?? ''
|
|
21
|
+
if (NAME_RE.test(name)) {
|
|
22
|
+
names.add(name)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return names
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// What another copy may import from `incoming` that `local` does not export.
|
|
32
|
+
function missingExports(incoming: string, local: string): string[] {
|
|
33
|
+
const have = exportedNames(local)
|
|
34
|
+
return [...exportedNames(incoming)].filter((name: string) => !have.has(name)).sort()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function isTypeScript(rel: string): boolean {
|
|
39
|
+
return rel.endsWith('.ts')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
exportedNames,
|
|
45
|
+
missingExports,
|
|
46
|
+
isTypeScript,
|
|
47
|
+
}
|