@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
package/src/cmp/ReadmeErrors.ts
CHANGED
|
@@ -10,22 +10,31 @@ import {
|
|
|
10
10
|
import { entityIdField, pickExampleEntity } from '../helpers/opShape'
|
|
11
11
|
import { helperLang, primaryOpCall } from '../helpers/opExample'
|
|
12
12
|
import type { PrimaryCall } from '../helpers/opExample'
|
|
13
|
-
import {
|
|
13
|
+
import { exampleVarName } from '../helpers/naming'
|
|
14
|
+
import { exampleParts, entityName } from '../helpers/exampleCall'
|
|
15
|
+
import type { ExampleInput } from '../helpers/exampleCall'
|
|
16
|
+
import { originName } from '../helpers/packageMeta'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
type EntityExample = ExampleInput & {
|
|
20
|
+
// The call in the languages opExample writes.
|
|
21
|
+
call: PrimaryCall
|
|
22
|
+
}
|
|
14
23
|
|
|
15
24
|
|
|
16
25
|
type LangErrors = {
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
entity
|
|
20
|
-
//
|
|
21
|
-
direct: string
|
|
26
|
+
// Prose and snippet for an entity operation's failure. A language without
|
|
27
|
+
// one writes only its direct() section.
|
|
28
|
+
entity?: (x: EntityExample) => string
|
|
29
|
+
// Prose and snippet for the direct()/prepare() convention.
|
|
30
|
+
direct: string | ((model: any) => string)
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
|
|
25
|
-
const
|
|
26
|
-
|
|
34
|
+
const TS_ENTITY = (fence: string) => ({ call, op }: EntityExample) =>
|
|
35
|
+
`Entity operations reject on failure, so wrap them in \`try\` / \`catch\`:
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
\`\`\`${fence}
|
|
29
38
|
try {
|
|
30
39
|
const ${call.resultVar} = await ${call.expr}
|
|
31
40
|
console.log(${'list' === op ? call.resultVar + '.map((item) => item.data())' : call.resultVar + '.data()'})
|
|
@@ -34,12 +43,13 @@ try {
|
|
|
34
43
|
}
|
|
35
44
|
\`\`\`
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
const TS_DIRECT = (fence: string) => `The low-level \`direct()\` method does **not** throw — it returns the
|
|
39
49
|
result envelope. Branch on \`ok\`; on failure \`status\` holds the HTTP status
|
|
40
50
|
(for error responses) and \`err\` holds the error:
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
\`\`\`${fence}
|
|
43
53
|
const result = await client.direct({
|
|
44
54
|
path: '/api/resource/{id}',
|
|
45
55
|
method: 'GET',
|
|
@@ -51,13 +61,31 @@ if (!result.ok) {
|
|
|
51
61
|
}
|
|
52
62
|
\`\`\`
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
`
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// The direct() paragraph every row shares, with its own name for the call and for not failing.
|
|
68
|
+
function directLead(call: string, fails: string, returns: string): string {
|
|
69
|
+
return `\`${call}\` does **not** ${fails} — it
|
|
70
|
+
returns ${returns}. Branch on \`ok\`; on failure \`status\` holds the HTTP
|
|
71
|
+
status (for error responses) and \`err\` holds a transport error:
|
|
72
|
+
|
|
73
|
+
`
|
|
55
74
|
}
|
|
56
75
|
|
|
57
76
|
|
|
77
|
+
// A language with no row writes neutral prose and no code.
|
|
78
|
+
const DEFAULT_LANG: LangErrors = {
|
|
79
|
+
direct: `The low-level \`direct\` method does not fail on an error response — it
|
|
80
|
+
returns the result envelope. Branch on \`ok\`; on failure \`status\` holds the
|
|
81
|
+
HTTP status (for error responses) and \`err\` holds the error.
|
|
82
|
+
|
|
83
|
+
`,
|
|
84
|
+
}
|
|
85
|
+
|
|
58
86
|
const LANGS: Record<string, LangErrors> = {
|
|
59
87
|
py: {
|
|
60
|
-
entity: (call, op) => `Entity operations raise on failure, so wrap them in \`try\` / \`except\`:
|
|
88
|
+
entity: ({ call, op }) => `Entity operations raise on failure, so wrap them in \`try\` / \`except\`:
|
|
61
89
|
|
|
62
90
|
\`\`\`python
|
|
63
91
|
try:
|
|
@@ -87,7 +115,7 @@ if not result["ok"]:
|
|
|
87
115
|
},
|
|
88
116
|
|
|
89
117
|
php: {
|
|
90
|
-
entity: (call, op) => `Entity operations throw a \`\\Throwable\` on failure, so wrap them in
|
|
118
|
+
entity: ({ call, op }) => `Entity operations throw a \`\\Throwable\` on failure, so wrap them in
|
|
91
119
|
\`try\` / \`catch\`:
|
|
92
120
|
|
|
93
121
|
\`\`\`php
|
|
@@ -120,7 +148,7 @@ if (! $result["ok"]) {
|
|
|
120
148
|
},
|
|
121
149
|
|
|
122
150
|
rb: {
|
|
123
|
-
entity: (call, op) => `Entity operations raise on failure, so rescue them:
|
|
151
|
+
entity: ({ call, op }) => `Entity operations raise on failure, so rescue them:
|
|
124
152
|
|
|
125
153
|
\`\`\`ruby
|
|
126
154
|
begin
|
|
@@ -149,7 +177,7 @@ warn "request failed: #{result["err"] || "HTTP #{result["status"]}"}" unless res
|
|
|
149
177
|
},
|
|
150
178
|
|
|
151
179
|
lua: {
|
|
152
|
-
entity: (call, op) => `Entity operations return \`(value, err)\`. Check \`err\` before using
|
|
180
|
+
entity: ({ call, op }) => `Entity operations return \`(value, err)\`. Check \`err\` before using
|
|
153
181
|
the value:
|
|
154
182
|
|
|
155
183
|
\`\`\`lua
|
|
@@ -173,7 +201,7 @@ if err then error(err) end
|
|
|
173
201
|
},
|
|
174
202
|
|
|
175
203
|
go: {
|
|
176
|
-
entity: (call, op) => `Every entity operation returns \`(value, error)\`. Check \`err\` before
|
|
204
|
+
entity: ({ call, op }) => `Every entity operation returns \`(value, error)\`. Check \`err\` before
|
|
177
205
|
using the value — there is no exception to catch:
|
|
178
206
|
|
|
179
207
|
\`\`\`go
|
|
@@ -200,6 +228,506 @@ if err != nil {
|
|
|
200
228
|
_ = result
|
|
201
229
|
\`\`\`
|
|
202
230
|
|
|
231
|
+
`,
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
ts: {
|
|
235
|
+
entity: TS_ENTITY('ts'),
|
|
236
|
+
direct: TS_DIRECT('ts'),
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
js: {
|
|
240
|
+
entity: TS_ENTITY('js'),
|
|
241
|
+
direct: TS_DIRECT('js'),
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
c: {
|
|
245
|
+
entity: (x) => {
|
|
246
|
+
const { v, factory, arg } = exampleParts('c', x)
|
|
247
|
+
const call = `${v}->vt->${x.op}(${v}, ${arg}, NULL, &err)`
|
|
248
|
+
const ok = 'list' === x.op ? ` for (size_t i = 0; ${v}s[i]; i++) {
|
|
249
|
+
printf("%s\\n", voxgig_to_json(${v}s[i]->vt->data(${v}s[i], NULL)));
|
|
250
|
+
}` : ` printf("%s\\n", voxgig_to_json(${v}->vt->data(${v}, NULL)));`
|
|
251
|
+
return `Entity operations set \`*err\` on failure, so check \`err\` after each call:
|
|
252
|
+
|
|
253
|
+
\`\`\`c
|
|
254
|
+
Entity* ${v} = ${factory};
|
|
255
|
+
PNError* err = NULL;
|
|
256
|
+
${'list' === x.op ? `Entity** ${v}s = ${call};` : `${call};`}
|
|
257
|
+
if (err) {
|
|
258
|
+
fprintf(stderr, "${x.op} failed: %s\\n", err->msg);
|
|
259
|
+
} else {
|
|
260
|
+
${ok}
|
|
261
|
+
}
|
|
262
|
+
\`\`\`
|
|
263
|
+
|
|
264
|
+
`
|
|
265
|
+
},
|
|
266
|
+
direct: directLead('sdk_direct()', 'set `*err` for an error response', 'the result map') +
|
|
267
|
+
`\`\`\`c
|
|
268
|
+
PNError* err = NULL;
|
|
269
|
+
voxgig_value* result = sdk_direct(client, cmap(3,
|
|
270
|
+
"path", v_str("/api/resource/{id}"),
|
|
271
|
+
"method", v_str("GET"),
|
|
272
|
+
"params", cmap(1, "id", v_str("example_id"))), &err);
|
|
273
|
+
|
|
274
|
+
if (!voxgig_as_bool(getp(result, "ok"))) {
|
|
275
|
+
fprintf(stderr, "request failed: %lld %s\\n",
|
|
276
|
+
(long long)to_int(getp(result, "status")), voxgig_to_json(getp(result, "err")));
|
|
277
|
+
}
|
|
278
|
+
\`\`\`
|
|
279
|
+
|
|
280
|
+
`,
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
cpp: {
|
|
284
|
+
entity: (x) => {
|
|
285
|
+
const { v, factory, arg } = exampleParts('cpp', x)
|
|
286
|
+
const call = `${factory}->${x.op}(${arg}, Value::undef())`
|
|
287
|
+
const body = 'list' === x.op ? ` std::vector<SdkEntityPtr> ${v}s = ${call};
|
|
288
|
+
for (const auto& ${v} : ${v}s) {
|
|
289
|
+
std::cout << Struct::jsonify(${v}->data()) << std::endl;
|
|
290
|
+
}` : ` SdkEntityPtr ${v} = ${call};
|
|
291
|
+
std::cout << Struct::jsonify(${v}->data()) << std::endl;`
|
|
292
|
+
return `Entity operations throw \`SdkErrorPtr\` on failure, so wrap them in \`try\` / \`catch\`:
|
|
293
|
+
|
|
294
|
+
\`\`\`cpp
|
|
295
|
+
try {
|
|
296
|
+
${body}
|
|
297
|
+
} catch (const SdkErrorPtr& err) {
|
|
298
|
+
std::cerr << "${x.op} failed: " << err->msg << std::endl;
|
|
299
|
+
}
|
|
300
|
+
\`\`\`
|
|
301
|
+
|
|
302
|
+
`
|
|
303
|
+
},
|
|
304
|
+
direct: directLead('direct()', 'throw', 'the result `Value`') +
|
|
305
|
+
`\`\`\`cpp
|
|
306
|
+
Value result = client->direct(vmap({
|
|
307
|
+
{"path", Value("/api/resource/{id}")},
|
|
308
|
+
{"method", Value("GET")},
|
|
309
|
+
{"params", vmap({{"id", Value("example_id")}})},
|
|
310
|
+
}));
|
|
311
|
+
|
|
312
|
+
if (!(getp(result, "ok") == Value(true))) {
|
|
313
|
+
std::cerr << "request failed: " << Helpers::toInt(getp(result, "status")) << " "
|
|
314
|
+
<< Struct::jsonify(getp(result, "err")) << std::endl;
|
|
315
|
+
}
|
|
316
|
+
\`\`\`
|
|
317
|
+
|
|
318
|
+
`,
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
rust: {
|
|
322
|
+
entity: (x) => {
|
|
323
|
+
const { v, factory, arg } = exampleParts('rust', x)
|
|
324
|
+
const ok = 'list' === x.op ? ` Ok(${v}s) => {
|
|
325
|
+
for ${v} in &${v}s {
|
|
326
|
+
println!("{:?}", ${v}.data(None));
|
|
327
|
+
}
|
|
328
|
+
}` : ` Ok(${v}) => println!("{:?}", ${v}.data(None)),`
|
|
329
|
+
return `Entity operations return a \`Result\`, so match on \`Ok\` and \`Err\`:
|
|
330
|
+
|
|
331
|
+
\`\`\`rust
|
|
332
|
+
match ${factory}.${x.op}(${arg}, Value::Noval) {
|
|
333
|
+
${ok}
|
|
334
|
+
Err(err) => eprintln!("${x.op} failed: {}", err),
|
|
335
|
+
}
|
|
336
|
+
\`\`\`
|
|
337
|
+
|
|
338
|
+
`
|
|
339
|
+
},
|
|
340
|
+
direct: directLead('direct()', 'return `Err` for an error response', '`Ok` with the result map') +
|
|
341
|
+
`\`\`\`rust
|
|
342
|
+
match client.direct(jo(vec![
|
|
343
|
+
("path", Value::str("/api/resource/{id}")),
|
|
344
|
+
("method", Value::str("GET")),
|
|
345
|
+
("params", jo(vec![("id", Value::str("example_id"))])),
|
|
346
|
+
])) {
|
|
347
|
+
Ok(result) => {
|
|
348
|
+
if getp(&result, "ok") != Value::Bool(true) {
|
|
349
|
+
eprintln!("request failed: {:?} {:?}", getp(&result, "status"), getp(&result, "err"));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
Err(err) => eprintln!("request failed: {}", err),
|
|
353
|
+
}
|
|
354
|
+
\`\`\`
|
|
355
|
+
|
|
356
|
+
`,
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
zig: {
|
|
360
|
+
entity: (x) => {
|
|
361
|
+
const { v, factory, arg } = exampleParts('zig', x)
|
|
362
|
+
const ok = 'list' === x.op ? ` .ok => |${v}s| {
|
|
363
|
+
for (${v}s) |${v}| {
|
|
364
|
+
std.debug.print("{s}\\n", .{h.stringify(${v}.asEntity().data(null))});
|
|
365
|
+
}
|
|
366
|
+
},` : ('remove' === x.op ? ` .ok => std.debug.print("removed\\n", .{}),` :
|
|
367
|
+
` .ok => |${v}| std.debug.print("{s}\\n", .{h.stringify(${v}.asEntity().data(null))}),`)
|
|
368
|
+
return `Entity operations return a union of \`.ok\` and \`.err\`, so \`switch\` on the result:
|
|
369
|
+
|
|
370
|
+
\`\`\`zig
|
|
371
|
+
switch (${factory}.${x.op}(${arg}, h.vnull())) {
|
|
372
|
+
${ok}
|
|
373
|
+
.err => |e| std.debug.print("${x.op} failed: {s}\\n", .{e.msg}),
|
|
374
|
+
}
|
|
375
|
+
\`\`\`
|
|
376
|
+
|
|
377
|
+
`
|
|
378
|
+
},
|
|
379
|
+
direct: directLead('direct()', 'fail on an error response', 'the result map') +
|
|
380
|
+
`\`\`\`zig
|
|
381
|
+
const result = client.direct(h.jo(&.{
|
|
382
|
+
.{ "path", h.vstr("/api/resource/{id}") },
|
|
383
|
+
.{ "method", h.vstr("GET") },
|
|
384
|
+
.{ "params", h.jo(&.{.{ "id", h.vstr("example_id") }}) },
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
if (!(h.get_bool(result, "ok") orelse false)) {
|
|
388
|
+
std.debug.print("request failed: {d} {s}\\n", .{
|
|
389
|
+
h.to_int(h.getp(result, "status")), h.stringify(h.getp(result, "err")),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
\`\`\`
|
|
393
|
+
|
|
394
|
+
`,
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
ocaml: {
|
|
398
|
+
entity: (x) => {
|
|
399
|
+
const { v, factory, arg } = exampleParts('ocaml', x)
|
|
400
|
+
const body = 'list' === x.op ? ` let ${v}s = ${factory}.e_list ${arg} Noval in
|
|
401
|
+
List.iter (fun e -> print_endline (stringify (e.e_data_get ()))) ${v}s` :
|
|
402
|
+
` let ${v} = ${factory}.e_${x.op} ${arg} Noval in
|
|
403
|
+
print_endline (stringify (${v}.e_data_get ()))`
|
|
404
|
+
return `Entity operations raise \`Sdk_error.E\` on failure, so wrap them in \`try\` ... \`with\`:
|
|
405
|
+
|
|
406
|
+
\`\`\`ocaml
|
|
407
|
+
(try
|
|
408
|
+
${body}
|
|
409
|
+
with Sdk_error.E err -> Printf.eprintf "${x.op} failed: %s\\n" (Sdk_error.message err))
|
|
410
|
+
\`\`\`
|
|
411
|
+
|
|
412
|
+
`
|
|
413
|
+
},
|
|
414
|
+
direct: directLead('Sdk_client.direct', 'raise', 'the result map') +
|
|
415
|
+
`\`\`\`ocaml
|
|
416
|
+
let result = Sdk_client.direct client (jo [
|
|
417
|
+
("path", Str "/api/resource/{id}");
|
|
418
|
+
("method", Str "GET");
|
|
419
|
+
("params", jo [("id", Str "example_id")]);
|
|
420
|
+
]) in
|
|
421
|
+
(match getp result "ok" with
|
|
422
|
+
| Bool true -> ()
|
|
423
|
+
| _ ->
|
|
424
|
+
Printf.eprintf "request failed: %s %s\\n"
|
|
425
|
+
(stringify (getp result "status")) (stringify (getp result "err")))
|
|
426
|
+
\`\`\`
|
|
427
|
+
|
|
428
|
+
`,
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
perl: {
|
|
432
|
+
entity: (x) => {
|
|
433
|
+
const { v, factory, arg } = exampleParts('perl', x)
|
|
434
|
+
return `Entity operations die on failure, so wrap them in \`eval\` and check \`$@\`:
|
|
435
|
+
|
|
436
|
+
\`\`\`perl
|
|
437
|
+
my $${'list' === x.op ? v + 's' : v} = eval { ${factory}->${x.op}(${arg}) };
|
|
438
|
+
if (my $err = $@) {
|
|
439
|
+
warn "${x.op} failed: $err";
|
|
440
|
+
}
|
|
441
|
+
\`\`\`
|
|
442
|
+
|
|
443
|
+
`
|
|
444
|
+
},
|
|
445
|
+
direct: directLead('direct', 'die', 'the result hashref') +
|
|
446
|
+
`\`\`\`perl
|
|
447
|
+
my $result = $client->direct({
|
|
448
|
+
'path' => '/api/resource/{id}',
|
|
449
|
+
'method' => 'GET',
|
|
450
|
+
'params' => { 'id' => 'example_id' },
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
unless ($result->{ok}) {
|
|
454
|
+
warn 'request failed: ', ($result->{status} // ''), ' ', ($result->{err} // ''), "\\n";
|
|
455
|
+
}
|
|
456
|
+
\`\`\`
|
|
457
|
+
|
|
458
|
+
`,
|
|
459
|
+
},
|
|
460
|
+
|
|
461
|
+
java: {
|
|
462
|
+
entity: (x) => {
|
|
463
|
+
const { v, factory, arg } = exampleParts('java', x)
|
|
464
|
+
const body = 'list' === x.op ? ` List<?> ${v}s = (List<?>) ${factory}.list(${arg}, null);
|
|
465
|
+
for (Object item : ${v}s) {
|
|
466
|
+
System.out.println(((SdkEntity) item).data());
|
|
467
|
+
}` : ` SdkEntity ${v} = (SdkEntity) ${factory}.${x.op}(${arg}, null);
|
|
468
|
+
System.out.println(${v}.data());`
|
|
469
|
+
return `Entity operations throw a \`RuntimeException\` on failure, so wrap them in
|
|
470
|
+
\`try\` / \`catch\`:
|
|
471
|
+
|
|
472
|
+
\`\`\`java
|
|
473
|
+
try {
|
|
474
|
+
${body}
|
|
475
|
+
}
|
|
476
|
+
catch (RuntimeException err) {
|
|
477
|
+
System.out.println("${x.op} failed: " + err.getMessage());
|
|
478
|
+
}
|
|
479
|
+
\`\`\`
|
|
480
|
+
|
|
481
|
+
`
|
|
482
|
+
},
|
|
483
|
+
direct: directLead('direct()', 'throw', 'the result map') +
|
|
484
|
+
`\`\`\`java
|
|
485
|
+
Map<String, Object> result = client.direct(Map.of(
|
|
486
|
+
"path", "/api/resource/{id}",
|
|
487
|
+
"method", "GET",
|
|
488
|
+
"params", Map.of("id", "example_id")));
|
|
489
|
+
|
|
490
|
+
if (!Boolean.TRUE.equals(result.get("ok"))) {
|
|
491
|
+
System.out.println("request failed: " + result.get("status") + " " + result.get("err"));
|
|
492
|
+
}
|
|
493
|
+
\`\`\`
|
|
494
|
+
|
|
495
|
+
`,
|
|
496
|
+
},
|
|
497
|
+
|
|
498
|
+
kotlin: {
|
|
499
|
+
entity: (x) => {
|
|
500
|
+
const { v, factory, arg } = exampleParts('kotlin', x)
|
|
501
|
+
const body = 'list' === x.op ? ` val ${v}s = ${factory}.list(${arg}, null) as List<*>
|
|
502
|
+
for (item in ${v}s) {
|
|
503
|
+
println((item as SdkEntity).data())
|
|
504
|
+
}` : ` val ${v} = ${factory}.${x.op}(${arg}, null) as SdkEntity
|
|
505
|
+
println(${v}.data())`
|
|
506
|
+
return `Entity operations throw a \`RuntimeException\` on failure, so wrap them in
|
|
507
|
+
\`try\` / \`catch\`:
|
|
508
|
+
|
|
509
|
+
\`\`\`kotlin
|
|
510
|
+
try {
|
|
511
|
+
${body}
|
|
512
|
+
}
|
|
513
|
+
catch (err: RuntimeException) {
|
|
514
|
+
println("${x.op} failed: " + err.message)
|
|
515
|
+
}
|
|
516
|
+
\`\`\`
|
|
517
|
+
|
|
518
|
+
`
|
|
519
|
+
},
|
|
520
|
+
direct: directLead('direct()', 'throw', 'the result map') +
|
|
521
|
+
`\`\`\`kotlin
|
|
522
|
+
val result = client.direct(mutableMapOf<String, Any?>(
|
|
523
|
+
"path" to "/api/resource/{id}",
|
|
524
|
+
"method" to "GET",
|
|
525
|
+
"params" to mapOf("id" to "example_id")))
|
|
526
|
+
|
|
527
|
+
if (result["ok"] != true) {
|
|
528
|
+
println("request failed: " + result["status"] + " " + result["err"])
|
|
529
|
+
}
|
|
530
|
+
\`\`\`
|
|
531
|
+
|
|
532
|
+
`,
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
scala: {
|
|
536
|
+
entity: (x) => {
|
|
537
|
+
const { v, factory, arg } = exampleParts('scala', x)
|
|
538
|
+
const body = 'list' === x.op ? ` val ${v}s = ${factory}.list(${arg}, null).asInstanceOf[java.util.List[SdkEntity]]
|
|
539
|
+
${v}s.forEach(item => println(item.data()))` :
|
|
540
|
+
` val ${v} = ${factory}.${x.op}(${arg}, null).asInstanceOf[SdkEntity]
|
|
541
|
+
println(${v}.data())`
|
|
542
|
+
return `Entity operations throw a \`RuntimeException\` on failure, so wrap them in
|
|
543
|
+
\`try\` / \`catch\`:
|
|
544
|
+
|
|
545
|
+
\`\`\`scala
|
|
546
|
+
try {
|
|
547
|
+
${body}
|
|
548
|
+
}
|
|
549
|
+
catch {
|
|
550
|
+
case err: RuntimeException => println("${x.op} failed: " + err.getMessage)
|
|
551
|
+
}
|
|
552
|
+
\`\`\`
|
|
553
|
+
|
|
554
|
+
`
|
|
555
|
+
},
|
|
556
|
+
direct: directLead('direct()', 'throw', 'the result map') +
|
|
557
|
+
`\`\`\`scala
|
|
558
|
+
val result = client.direct(java.util.Map.of(
|
|
559
|
+
"path", "/api/resource/{id}",
|
|
560
|
+
"method", "GET",
|
|
561
|
+
"params", java.util.Map.of("id", "example_id")))
|
|
562
|
+
|
|
563
|
+
if (java.lang.Boolean.TRUE != result.get("ok")) {
|
|
564
|
+
println("request failed: " + result.get("status") + " " + result.get("err"))
|
|
565
|
+
}
|
|
566
|
+
\`\`\`
|
|
567
|
+
|
|
568
|
+
`,
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
csharp: {
|
|
572
|
+
entity: (x) => {
|
|
573
|
+
const { v, factory, arg } = exampleParts('csharp', x)
|
|
574
|
+
const method = x.op.charAt(0).toUpperCase() + x.op.slice(1)
|
|
575
|
+
const body = 'list' === x.op ? ` var ${v}List = (List<object?>)${factory}.List(${arg})!;
|
|
576
|
+
foreach (var ${v}Item in ${v}List)
|
|
577
|
+
{
|
|
578
|
+
Console.WriteLine(StructUtils.Jsonify(((IEntity)${v}Item!).Data()));
|
|
579
|
+
}` : ` var ${v} = (IEntity)${factory}.${method}(${arg})!;
|
|
580
|
+
Console.WriteLine(StructUtils.Jsonify(${v}.Data()));`
|
|
581
|
+
return `Entity operations throw on failure, so wrap them in \`try\` / \`catch\`:
|
|
582
|
+
|
|
583
|
+
\`\`\`csharp
|
|
584
|
+
try
|
|
585
|
+
{
|
|
586
|
+
${body}
|
|
587
|
+
}
|
|
588
|
+
catch (Exception err)
|
|
589
|
+
{
|
|
590
|
+
Console.WriteLine($"${x.op} failed: {err.Message}");
|
|
591
|
+
}
|
|
592
|
+
\`\`\`
|
|
593
|
+
|
|
594
|
+
`
|
|
595
|
+
},
|
|
596
|
+
direct: directLead('Direct()', 'throw', 'the result dictionary') +
|
|
597
|
+
`\`\`\`csharp
|
|
598
|
+
var result = client.Direct(new Dictionary<string, object?>
|
|
599
|
+
{
|
|
600
|
+
["path"] = "/api/resource/{id}",
|
|
601
|
+
["method"] = "GET",
|
|
602
|
+
["params"] = new Dictionary<string, object?> { ["id"] = "example_id" },
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
if (!Equals(result["ok"], true))
|
|
606
|
+
{
|
|
607
|
+
result.TryGetValue("status", out var status);
|
|
608
|
+
result.TryGetValue("err", out var err);
|
|
609
|
+
Console.WriteLine($"request failed: {status} {err}");
|
|
610
|
+
}
|
|
611
|
+
\`\`\`
|
|
612
|
+
|
|
613
|
+
`,
|
|
614
|
+
},
|
|
615
|
+
|
|
616
|
+
swift: {
|
|
617
|
+
entity: (x) => {
|
|
618
|
+
const { v, factory, arg } = exampleParts('swift', x)
|
|
619
|
+
const body = 'list' === x.op ? ` let ${v}List = try ${factory}.list(${arg}, nil)
|
|
620
|
+
for ${v}Item in ${v}List.asList?.items ?? [] {
|
|
621
|
+
if let ${v}Entity = ${v}Item.asNative as? Entity {
|
|
622
|
+
print(${v}Entity.data())
|
|
623
|
+
}
|
|
624
|
+
}` : ` let ${v} = try ${factory}.${x.op}(${arg}, nil)
|
|
625
|
+
if let ${v}Entity = ${v}.asNative as? Entity {
|
|
626
|
+
print(${v}Entity.data())
|
|
627
|
+
}`
|
|
628
|
+
return `Entity operations throw on failure, so call them with \`try\` inside \`do\` / \`catch\`:
|
|
629
|
+
|
|
630
|
+
\`\`\`swift
|
|
631
|
+
do {
|
|
632
|
+
${body}
|
|
633
|
+
}
|
|
634
|
+
catch {
|
|
635
|
+
print("${x.op} failed: \\(error)")
|
|
636
|
+
}
|
|
637
|
+
\`\`\`
|
|
638
|
+
|
|
639
|
+
`
|
|
640
|
+
},
|
|
641
|
+
direct: directLead('direct()', 'throw', 'the result map') +
|
|
642
|
+
`\`\`\`swift
|
|
643
|
+
let result = client.direct(VMap([
|
|
644
|
+
("path", .string("/api/resource/{id}")),
|
|
645
|
+
("method", .string("GET")),
|
|
646
|
+
("params", .map([("id", .string("example_id"))])),
|
|
647
|
+
]))
|
|
648
|
+
|
|
649
|
+
if result.entries["ok"] != .bool(true) {
|
|
650
|
+
print("request failed:", result.entries["status"] ?? .noval, result.entries["err"] ?? .noval)
|
|
651
|
+
}
|
|
652
|
+
\`\`\`
|
|
653
|
+
|
|
654
|
+
`,
|
|
655
|
+
},
|
|
656
|
+
|
|
657
|
+
elixir: {
|
|
658
|
+
entity: (x) => {
|
|
659
|
+
const { v, factory, arg } = exampleParts('elixir', x)
|
|
660
|
+
const mod = `${x.model.const.Name}.Entity.${entityName(x.ent)}`
|
|
661
|
+
const args = '' === arg ? v : `${v}, ${arg}`
|
|
662
|
+
const body = 'list' === x.op ? ` ${v}s = ${mod}.list(${args})
|
|
663
|
+
for i <- 0..(Voxgig.Struct.size(${v}s) - 1)//1 do
|
|
664
|
+
IO.puts(Voxgig.Struct.jsonify(${mod}.data_get(Voxgig.Struct.getelem(${v}s, i))))
|
|
665
|
+
end` : ` ${v} = ${mod}.${x.op}(${args})
|
|
666
|
+
IO.puts(Voxgig.Struct.jsonify(${mod}.data_get(${v})))`
|
|
667
|
+
return `Entity operations raise on failure, so wrap them in \`try\` / \`rescue\`:
|
|
668
|
+
|
|
669
|
+
\`\`\`elixir
|
|
670
|
+
try do
|
|
671
|
+
${v} = ${factory}
|
|
672
|
+
${body}
|
|
673
|
+
rescue
|
|
674
|
+
err -> IO.puts("${x.op} failed: " <> inspect(err))
|
|
675
|
+
end
|
|
676
|
+
\`\`\`
|
|
677
|
+
|
|
678
|
+
`
|
|
679
|
+
},
|
|
680
|
+
direct: (model) => directLead('direct/2', 'raise', 'a result node') +
|
|
681
|
+
`\`\`\`elixir
|
|
682
|
+
result = ${model.const.Name}.direct(sdk, ${model.const.Name}.Helpers.deep(%{
|
|
683
|
+
"path" => "/api/resource/{id}",
|
|
684
|
+
"method" => "GET",
|
|
685
|
+
"params" => %{"id" => "example_id"}
|
|
686
|
+
}))
|
|
687
|
+
|
|
688
|
+
unless Voxgig.Struct.getprop(result, "ok") do
|
|
689
|
+
IO.puts("request failed: " <> inspect(Voxgig.Struct.getprop(result, "status")) <>
|
|
690
|
+
" " <> inspect(Voxgig.Struct.getprop(result, "err")))
|
|
691
|
+
end
|
|
692
|
+
\`\`\`
|
|
693
|
+
|
|
694
|
+
`,
|
|
695
|
+
},
|
|
696
|
+
|
|
697
|
+
clojure: {
|
|
698
|
+
entity: (x) => {
|
|
699
|
+
const { v, factory, arg } = exampleParts('clojure', x)
|
|
700
|
+
const ns = 'e-' + x.ent.name
|
|
701
|
+
const body = 'list' === x.op ? ` (doseq [${v} (${ns}/list ${factory} ${arg} nil)]
|
|
702
|
+
(println ((:data-get ${v}))))` : ` (let [${v} (${ns}/${x.op} ${factory} ${arg} nil)]
|
|
703
|
+
(println ((:data-get ${v}))))`
|
|
704
|
+
return `Entity operations throw on failure, so wrap them in \`try\` / \`catch\`:
|
|
705
|
+
|
|
706
|
+
\`\`\`clojure
|
|
707
|
+
(require '[sdk.api :as api]
|
|
708
|
+
'[sdk.entity.${x.ent.name} :as ${ns}]
|
|
709
|
+
'[voxgig.struct :as vs])
|
|
710
|
+
|
|
711
|
+
(try
|
|
712
|
+
${body}
|
|
713
|
+
(catch Exception err
|
|
714
|
+
(println "${x.op} failed:" (.getMessage err))))
|
|
715
|
+
\`\`\`
|
|
716
|
+
|
|
717
|
+
`
|
|
718
|
+
},
|
|
719
|
+
direct: directLead('api/direct', 'throw', 'the result map') +
|
|
720
|
+
`\`\`\`clojure
|
|
721
|
+
(def result
|
|
722
|
+
(api/direct client
|
|
723
|
+
(vs/jm "path" "/api/resource/{id}"
|
|
724
|
+
"method" "GET"
|
|
725
|
+
"params" (vs/jm "id" "example_id"))))
|
|
726
|
+
|
|
727
|
+
(when-not (vs/getprop result "ok")
|
|
728
|
+
(println "request failed:" (vs/getprop result "status") (vs/getprop result "err")))
|
|
729
|
+
\`\`\`
|
|
730
|
+
|
|
203
731
|
`,
|
|
204
732
|
},
|
|
205
733
|
}
|
|
@@ -209,7 +737,9 @@ const ReadmeErrors = cmp(function ReadmeErrors(props: any) {
|
|
|
209
737
|
const { target, ctx$ } = props
|
|
210
738
|
const { model } = ctx$
|
|
211
739
|
|
|
212
|
-
|
|
740
|
+
// An alias writes its origin's row.
|
|
741
|
+
const origin = originName(model, target.name)
|
|
742
|
+
const lang = LANGS[origin] || DEFAULT_LANG
|
|
213
743
|
|
|
214
744
|
// Pick a real example entity WITH a real op (prefer a read op) so the
|
|
215
745
|
// error-handling snippet never references a phantom entity or fabricates a
|
|
@@ -224,15 +754,15 @@ const ReadmeErrors = cmp(function ReadmeErrors(props: any) {
|
|
|
224
754
|
|
|
225
755
|
`)
|
|
226
756
|
|
|
227
|
-
if (ex && primaryOp) {
|
|
228
|
-
const eName =
|
|
229
|
-
const eLower = exampleVarName(eName.toLowerCase(),
|
|
757
|
+
if (ex && primaryOp && lang.entity) {
|
|
758
|
+
const eName = entityName(ex)
|
|
759
|
+
const eLower = exampleVarName(eName.toLowerCase(), origin)
|
|
230
760
|
const idF = entityIdField(ex)
|
|
231
|
-
const call = primaryOpCall(helperLang(
|
|
232
|
-
Content(lang.entity(
|
|
761
|
+
const call = primaryOpCall(helperLang(origin), eName, eLower, primaryOp, idF, ex)
|
|
762
|
+
Content(lang.entity({ model, ent: ex, op: primaryOp, idF, call }))
|
|
233
763
|
}
|
|
234
764
|
|
|
235
|
-
Content(lang.direct)
|
|
765
|
+
Content('function' === typeof lang.direct ? lang.direct(model) : lang.direct)
|
|
236
766
|
})
|
|
237
767
|
|
|
238
768
|
|