@voxgig/sdkgen 4.45.0 → 4.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/action/check.js +15 -0
- 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 +21 -2
- package/dist/action/doctor.js +166 -9
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/package.js +9 -0
- package/dist/action/package.js.map +1 -1
- package/dist/action/remove.js +2 -1
- package/dist/action/remove.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/cmp/AgentGuide.js +19 -8
- package/dist/cmp/AgentGuide.js.map +1 -1
- package/dist/cmp/AgentGuideContent.d.ts +6 -4
- package/dist/cmp/AgentGuideContent.js +51 -32
- package/dist/cmp/AgentGuideContent.js.map +1 -1
- package/dist/cmp/AgentGuideFeature.js +5 -3
- package/dist/cmp/AgentGuideFeature.js.map +1 -1
- package/dist/cmp/AgentGuideTop.js +84 -46
- package/dist/cmp/AgentGuideTop.js.map +1 -1
- package/dist/cmp/Changelog.js +12 -1
- package/dist/cmp/Changelog.js.map +1 -1
- package/dist/cmp/Deploy.js +22 -20
- package/dist/cmp/Deploy.js.map +1 -1
- package/dist/cmp/ExternalTarget.js +5 -5
- package/dist/cmp/ExternalTarget.js.map +1 -1
- package/dist/cmp/Feature.js +10 -3
- 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/PublishWorkflow.js +30 -6
- 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 +3 -2
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeRefFeatures.js +34 -24
- package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
- package/dist/cmp/ReadmeStation.js +11 -8
- package/dist/cmp/ReadmeStation.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +472 -373
- 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/Security.js +3 -2
- package/dist/cmp/Security.js.map +1 -1
- package/dist/helpers/applicability.d.ts +2 -1
- package/dist/helpers/applicability.js +26 -0
- package/dist/helpers/applicability.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/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 +84 -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 +37 -2
- package/dist/helpers/facts.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 +12 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/packageMeta.js +21 -8
- package/dist/helpers/packageMeta.js.map +1 -1
- package/dist/helpers/semver.d.ts +2 -1
- package/dist/helpers/semver.js +7 -0
- package/dist/helpers/semver.js.map +1 -1
- package/dist/sdkgen.js +21 -2
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.d.ts +1 -0
- package/dist/testkit.js +23 -19
- 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 +44 -0
- package/model/sdkgen.aontu +6 -2
- package/package.json +3 -1
- package/project/.sdk/src/cmp/c/ReadmeQuick_c.ts +1 -1
- 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/scala/ReadmeRef_scala.ts +4 -1
- package/project/.sdk/src/cmp/swift/ReadmeQuick_swift.ts +1 -0
- 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/zig/ReadmeOptions_zig.ts +1 -1
- package/project/.sdk/src/cmp/zig/ReadmeQuick_zig.ts +2 -2
- package/project/.sdk/src/cmp/zig/ReadmeTopQuick_zig.ts +2 -2
- package/project/sdkgen-package.json +1 -1
- package/src/action/check.ts +21 -0
- package/src/action/copies.ts +2 -0
- package/src/action/doctor.ts +244 -13
- package/src/action/package.ts +10 -0
- package/src/action/remove.ts +2 -1
- package/src/action/target.ts +66 -15
- package/src/cmp/AgentGuide.ts +24 -10
- package/src/cmp/AgentGuideContent.ts +53 -32
- package/src/cmp/AgentGuideFeature.ts +6 -4
- package/src/cmp/AgentGuideTop.ts +108 -47
- package/src/cmp/Changelog.ts +13 -2
- package/src/cmp/Deploy.ts +23 -21
- package/src/cmp/ExternalTarget.ts +6 -6
- package/src/cmp/Feature.ts +11 -4
- package/src/cmp/FeatureDocs.ts +21 -40
- package/src/cmp/FeatureHook.ts +38 -1
- package/src/cmp/PublishWorkflow.ts +33 -7
- 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 +3 -2
- package/src/cmp/ReadmeRefFeatures.ts +39 -27
- package/src/cmp/ReadmeStation.ts +12 -14
- package/src/cmp/ReadmeTop.ts +528 -387
- package/src/cmp/ReadmeUnions.ts +10 -2
- package/src/cmp/Security.ts +3 -2
- package/src/helpers/applicability.ts +28 -0
- package/src/helpers/copymerge.ts +58 -10
- package/src/helpers/doccheck.ts +174 -0
- package/src/helpers/doctext.ts +113 -0
- package/src/helpers/exampleCall.ts +415 -0
- package/src/helpers/exportnames.ts +47 -0
- package/src/helpers/facts.ts +47 -2
- package/src/helpers/modelcheck.ts +16 -0
- package/src/helpers/opExample.ts +34 -2
- package/src/helpers/opShape.ts +13 -0
- package/src/helpers/packageMeta.ts +21 -8
- package/src/helpers/semver.ts +9 -0
- package/src/sdkgen.ts +27 -3
- package/src/testkit.ts +30 -20
- package/src/utility.ts +2 -1
|
@@ -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
|
+
}
|
package/src/helpers/facts.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { readFileSync } from 'node:fs'
|
|
|
3
3
|
import { Aontu } from 'aontu'
|
|
4
4
|
import { KIT } from '@voxgig/apidef'
|
|
5
5
|
|
|
6
|
+
import { docTexts } from './doctext'
|
|
6
7
|
import { factRulesFile } from './shipped'
|
|
8
|
+
import { SdkGenError } from '../utility'
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
// No fact rule reads these, and they are most of a large model.
|
|
@@ -18,7 +20,9 @@ function isMap(v: any): boolean {
|
|
|
18
20
|
function copyFacts(from: any, to: any): void {
|
|
19
21
|
for (const [key, val] of Object.entries(from)) {
|
|
20
22
|
if ('fact' === key) {
|
|
21
|
-
|
|
23
|
+
if (isMap(val) && 0 < Object.keys(val as object).length) {
|
|
24
|
+
to.fact = val
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
else if (isMap(val) && isMap(to[key])) {
|
|
24
28
|
copyFacts(val, to[key])
|
|
@@ -42,8 +46,11 @@ function applyFacts(model: any): any {
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
const texts = docTexts(model)
|
|
50
|
+
const escape = Object.fromEntries(texts.map((t, i) => ['t' + i, { raw: t.raw, vendor: t.vendor }]))
|
|
51
|
+
|
|
45
52
|
const path = factRulesFile()
|
|
46
|
-
const src = JSON.stringify({ main: { [KIT]: input } }).slice(1, -1) +
|
|
53
|
+
const src = JSON.stringify({ main: { [KIT]: input }, escape }).slice(1, -1) +
|
|
47
54
|
'\n' + readFileSync(path, 'utf8')
|
|
48
55
|
|
|
49
56
|
const errs: any[] = []
|
|
@@ -54,10 +61,20 @@ function applyFacts(model: any): any {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
copyFacts(out.main[KIT], kit)
|
|
64
|
+
texts.forEach((t, i) => place(t.at, t.path, out.escape['t' + i]))
|
|
57
65
|
return model
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
|
|
69
|
+
function place(at: any, path: string[], forms: any): void {
|
|
70
|
+
let node = at.fact = isMap(at.fact) ? at.fact : {}
|
|
71
|
+
for (const key of path.slice(0, -1)) {
|
|
72
|
+
node = node[key] = isMap(node[key]) ? node[key] : {}
|
|
73
|
+
}
|
|
74
|
+
node[path[path.length - 1]] = forms
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
61
78
|
function fact(node: any, name: string): any {
|
|
62
79
|
const facts = node?.fact
|
|
63
80
|
if (!isMap(facts) || !(name in facts)) {
|
|
@@ -68,7 +85,35 @@ function fact(node: any, name: string): any {
|
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
|
|
88
|
+
// A plan no Root can write: several targets claiming the project root, or a
|
|
89
|
+
// target there beside the root documents, which would overwrite its own.
|
|
90
|
+
// `external` names the targets this run writes elsewhere; a target with no
|
|
91
|
+
// `output` claims no place at all.
|
|
92
|
+
function refuseRootPlan(model: any, external: string[] = []): void {
|
|
93
|
+
const kit = model.main[KIT]
|
|
94
|
+
const target = kit.target || {}
|
|
95
|
+
const atRoot = Object.keys(target).sort().filter((name: string) =>
|
|
96
|
+
!external.includes(name) && false !== target[name].active &&
|
|
97
|
+
null != target[name].output && 'root' === fact(target[name], 'place'))
|
|
98
|
+
|
|
99
|
+
if (1 < atRoot.length) {
|
|
100
|
+
throw new SdkGenError(
|
|
101
|
+
'Only one target can be generated at the project root, and ' +
|
|
102
|
+
atRoot.length + ' declare `output: root: true`: ' + atRoot.join(', ') + '.')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (1 === atRoot.length && fact(kit, 'top')) {
|
|
106
|
+
throw new SdkGenError(
|
|
107
|
+
'Target "' + atRoot[0] + '" is generated at the project root, where the ' +
|
|
108
|
+
'SDK repository files (README, LICENSE, Makefile, workflows) would ' +
|
|
109
|
+
'overwrite its own. Declare `main: kit: phase: top: active: false` in ' +
|
|
110
|
+
'model/project.aontu.')
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
71
115
|
export {
|
|
72
116
|
applyFacts,
|
|
73
117
|
fact,
|
|
118
|
+
refuseRootPlan,
|
|
74
119
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { Aontu } from 'aontu'
|
|
3
3
|
import { createRequire } from 'node:module'
|
|
4
|
+
import Fs from 'node:fs'
|
|
4
5
|
import Path from 'node:path'
|
|
5
6
|
|
|
6
7
|
import { schemaFile } from './shipped'
|
|
@@ -159,6 +160,20 @@ function publishOverrideProbe(
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
|
|
163
|
+
// A feature hook the schema does not list still unifies, through `hook: &:`,
|
|
164
|
+
// so a misspelled one is caught only by comparing against this list.
|
|
165
|
+
let schemaHookNames: string[] | null = null
|
|
166
|
+
|
|
167
|
+
function schemaHooks(): string[] {
|
|
168
|
+
if (null == schemaHookNames) {
|
|
169
|
+
const probe = compileModel(Fs.readFileSync(schemaFile(), 'utf8') +
|
|
170
|
+
"\nmain: kit: feature: 'hook$': title: ''\n", schemaFile(), { strict: false })
|
|
171
|
+
schemaHookNames = Object.keys(probe.model?.main?.kit?.feature?.['hook$']?.hook ?? {}).sort()
|
|
172
|
+
}
|
|
173
|
+
return schemaHookNames
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
162
177
|
export type {
|
|
163
178
|
CompileResult,
|
|
164
179
|
}
|
|
@@ -171,6 +186,7 @@ export {
|
|
|
171
186
|
compileModel,
|
|
172
187
|
includeLine,
|
|
173
188
|
publishOverrideProbe,
|
|
189
|
+
schemaHooks,
|
|
174
190
|
slashComments,
|
|
175
191
|
strictAontu,
|
|
176
192
|
unquoted,
|
package/src/helpers/opExample.ts
CHANGED
|
@@ -186,7 +186,7 @@ function seededList(lang: LiteralLang, ent: any, idF: string | null, key: string
|
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
// An update or patch addressed only by id and route also changes a field.
|
|
189
|
-
function
|
|
189
|
+
function dataItems(ent: any, op: string, idF: string | null): any[] {
|
|
190
190
|
const routed = new Set(opParams(ent?.op?.[op]).map((p: any) => p.n))
|
|
191
191
|
const addresses = (it: any) => it.name === idF || it.name === 'id' || routed.has(it.name)
|
|
192
192
|
const items = requestExampleItems(ent, op)
|
|
@@ -195,7 +195,12 @@ function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): s
|
|
|
195
195
|
const required = items.filter((it: any) => !it.optional)
|
|
196
196
|
const changed = ('update' === op || 'patch' === op) && required.every(addresses) ?
|
|
197
197
|
items.filter((it: any) => it.optional && !addresses(it)).slice(0, 1) : []
|
|
198
|
-
|
|
198
|
+
return required.length ? [...required, ...changed] : items.slice(0, 3)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): string {
|
|
203
|
+
const chosen = dataItems(ent, op, idF)
|
|
199
204
|
const pairs = chosen.map((it: any) => litPair(lang, it.name, litFor(lang, it.type)))
|
|
200
205
|
switch (lang) {
|
|
201
206
|
case 'php': return `[${pairs.join(', ')}]`
|
|
@@ -206,6 +211,30 @@ function dataArg(lang: LiteralLang, ent: any, op: string, idF: string | null): s
|
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
|
|
214
|
+
type ArgItem = {
|
|
215
|
+
name: string
|
|
216
|
+
type: any
|
|
217
|
+
id: boolean
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
// The members a primary-op example sends: those matchArg, listMatchArg and
|
|
222
|
+
// dataArg write, each marked when it carries the entity's id.
|
|
223
|
+
function exampleArgItems(ent: any, op: string, idF: string | null): ArgItem[] {
|
|
224
|
+
const item = (it: any, id: boolean) => ({ name: it.name, type: it.type, id })
|
|
225
|
+
if ('list' === op) {
|
|
226
|
+
return requiredItems(ent, 'list').map((it: any) => item(it, false))
|
|
227
|
+
}
|
|
228
|
+
if ('load' === op || 'remove' === op) {
|
|
229
|
+
return requiredItems(ent, op).map((it: any) => item(it, it.name === idF))
|
|
230
|
+
}
|
|
231
|
+
if ('create' === op || 'update' === op || 'patch' === op) {
|
|
232
|
+
return dataItems(ent, op, idF).map((it: any) => item(it, false))
|
|
233
|
+
}
|
|
234
|
+
return []
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
209
238
|
type PrimaryCall = {
|
|
210
239
|
expr: string
|
|
211
240
|
resultVar: string
|
|
@@ -275,6 +304,8 @@ export {
|
|
|
275
304
|
listMatchArg,
|
|
276
305
|
seededList,
|
|
277
306
|
dataArg,
|
|
307
|
+
dataItems,
|
|
308
|
+
exampleArgItems,
|
|
278
309
|
javaMap,
|
|
279
310
|
javaMapOf,
|
|
280
311
|
javaMapItems,
|
|
@@ -284,6 +315,7 @@ export {
|
|
|
284
315
|
}
|
|
285
316
|
|
|
286
317
|
export type {
|
|
318
|
+
ArgItem,
|
|
287
319
|
ExampleLang,
|
|
288
320
|
LiteralLang,
|
|
289
321
|
PrimaryCall,
|