@voxgig/sdkgen 4.39.1 → 4.40.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/helpers/testPolicy.d.ts +8 -2
- package/dist/helpers/testPolicy.js +18 -0
- package/dist/helpers/testPolicy.js.map +1 -1
- package/dist/sdkgen.d.ts +4 -4
- package/dist/sdkgen.js +4 -3
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/target/rust.aontu +1 -0
- package/project/.sdk/src/cmp/c/fragment/Main.fragment.c +15 -0
- package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +2 -0
- package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +20 -3
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +43 -15
- package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +17 -0
- package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +10 -0
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +23 -4
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +37 -12
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +14 -0
- package/project/.sdk/src/cmp/java/TestDirect_java.ts +18 -3
- package/project/.sdk/src/cmp/java/TestEntity_java.ts +39 -14
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +7 -1
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +7 -0
- package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +18 -3
- package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +37 -14
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +13 -3
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +36 -10
- package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +14 -0
- package/project/.sdk/src/cmp/ocaml/TestDirect_ocaml.ts +3 -1
- package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +9 -3
- package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +22 -8
- package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +6 -0
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +13 -3
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +31 -9
- package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +14 -0
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +11 -3
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +30 -9
- package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +6 -0
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +9 -3
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +25 -10
- package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +7 -0
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +13 -3
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +48 -27
- package/project/.sdk/src/cmp/rust/fragment/Main.fragment.rs +15 -0
- package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +7 -0
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +7 -1
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +8 -2
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +7 -0
- package/project/.sdk/src/cmp/zig/TestDirect_zig.ts +1 -0
- package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +16 -0
- package/project/.sdk/tm/c/utility/http.c +256 -0
- package/project/.sdk/tm/clojure/src/sdk/client.clj +7 -0
- package/project/.sdk/tm/clojure/src/sdk/core.clj +24 -1
- package/project/.sdk/tm/cpp/core/types.hpp +14 -0
- package/project/.sdk/tm/csharp/test/Runner.cs +49 -3
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +5 -1
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +54 -19
- package/project/.sdk/tm/go/test/testsupport_test.go +44 -3
- package/project/.sdk/tm/go/utility/fetcher.go +40 -0
- package/project/.sdk/tm/java/core/SdkClient.java +7 -0
- package/project/.sdk/tm/java/test/RunnerSupport.java +45 -2
- package/project/.sdk/tm/java/utility/Fetcher.java +67 -1
- package/project/.sdk/tm/js/src/utility/MakeResultUtility.js +3 -1
- package/project/.sdk/tm/js/test/live-entity.js +7 -3
- package/project/.sdk/tm/kotlin/core/SdkClient.kt +7 -0
- package/project/.sdk/tm/kotlin/test/RunnerSupport.kt +40 -3
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +52 -1
- package/project/.sdk/tm/lua/test/runner.lua +49 -2
- package/project/.sdk/tm/lua/utility/fetcher.lua +228 -0
- package/project/.sdk/tm/ocaml/sdk_features.ml +8 -0
- package/project/.sdk/tm/perl/t/runner.pm +18 -3
- package/project/.sdk/tm/perl/utility/fetcher.pm +42 -3
- package/project/.sdk/tm/php/test/Runner.php +43 -5
- package/project/.sdk/tm/php/utility/Fetcher.php +36 -0
- package/project/.sdk/tm/php/utility/MakeResult.php +3 -1
- package/project/.sdk/tm/py/test/runner.py +32 -3
- package/project/.sdk/tm/rb/test/runner.rb +24 -1
- package/project/.sdk/tm/rust/tests/common/mod.rs +53 -5
- package/project/.sdk/tm/rust/utility/fetcher.rs +43 -3
- package/project/.sdk/tm/scala/core/SdkClient.scala +7 -0
- package/project/.sdk/tm/scala/utility/Fetcher.scala +48 -1
- package/project/.sdk/tm/ts/src/utility/MakeResultUtility.ts +3 -1
- package/project/.sdk/tm/ts/test/live-entity.ts +8 -3
- package/project/sdkgen-package.json +1 -1
- package/src/helpers/testPolicy.ts +23 -2
- package/src/sdkgen.ts +4 -2
|
@@ -149,6 +149,21 @@ voxgig_value* sdk_prepare(ProjectNameSDK* sdk, voxgig_value* fetchargs, PNError*
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
// A raw request has no point to declare its response type, so it asks for
|
|
153
|
+
// the JSON it reads: an API that negotiates on Accept otherwise answers in
|
|
154
|
+
// its own default format. A caller's own accept wins.
|
|
155
|
+
int has_accept = 0;
|
|
156
|
+
if (voxgig_is_map(spec->headers)) {
|
|
157
|
+
voxgig_map* hm = voxgig_as_map(spec->headers);
|
|
158
|
+
for (size_t i = 0; i < hm->len && !has_accept; i++) {
|
|
159
|
+
const char* k = hm->entries[i].key;
|
|
160
|
+
const char* a = "accept";
|
|
161
|
+
while (*k && *a && tolower((unsigned char)*k) == *a) { k++; a++; }
|
|
162
|
+
has_accept = '\0' == *k && '\0' == *a;
|
|
163
|
+
}
|
|
164
|
+
if (!has_accept) setp(spec->headers, "accept", v_str("application/json"));
|
|
165
|
+
}
|
|
166
|
+
|
|
152
167
|
prepare_auth_util(ctx, err);
|
|
153
168
|
if (*err) return NULL;
|
|
154
169
|
|
|
@@ -248,6 +248,8 @@ static void ${evar}_direct_load() {
|
|
|
248
248
|
ASSERT_EQ((int)setup.calls.as_list()->size(), 1, "expected 1 call");
|
|
249
249
|
Value call = (*setup.calls.as_list())[0];
|
|
250
250
|
ASSERT_EQ_VAL(getp(getp(call, "init"), "method"), Value("GET"), "expected method GET");
|
|
251
|
+
ASSERT_EQ_VAL(getp(getp(getp(call, "init"), "headers"), "accept"), Value("application/json"),
|
|
252
|
+
"expected accept application/json");
|
|
251
253
|
std::string url = as_str(getp(call, "url"));
|
|
252
254
|
`)
|
|
253
255
|
for (let i = 0; i < loadParams.length; i++) {
|
|
@@ -240,7 +240,11 @@ ${liveStrictNote(liveStrict(model, target.name), '//', ' ')}
|
|
|
240
240
|
{
|
|
241
241
|
return; // skipped via sdk-test-control.json
|
|
242
242
|
}
|
|
243
|
-
${listSkipBlock}
|
|
243
|
+
${listSkipBlock} if (setup.Live)
|
|
244
|
+
{
|
|
245
|
+
TestRunner.LivePace();
|
|
246
|
+
}
|
|
247
|
+
var client = setup.Client;
|
|
244
248
|
|
|
245
249
|
`)
|
|
246
250
|
|
|
@@ -375,7 +379,11 @@ ${listLiveQueryLines ? ' if (setup.Live)\n {\n' + listLiveQueryLin
|
|
|
375
379
|
{
|
|
376
380
|
return; // skipped via sdk-test-control.json
|
|
377
381
|
}
|
|
378
|
-
${loadSkipBlock}
|
|
382
|
+
${loadSkipBlock} if (setup.Live)
|
|
383
|
+
{
|
|
384
|
+
TestRunner.LivePace();
|
|
385
|
+
}
|
|
386
|
+
var client = setup.Client;
|
|
379
387
|
|
|
380
388
|
`)
|
|
381
389
|
|
|
@@ -406,11 +414,20 @@ ${loadSkipBlock} var client = setup.Client;
|
|
|
406
414
|
`)
|
|
407
415
|
}
|
|
408
416
|
|
|
417
|
+
// The list sends the query its route requires, as direct-list does.
|
|
418
|
+
const listQueryLines = liveQueryExamples(listPoint)
|
|
419
|
+
.map(([name, ex]) => ` listQuery[${formatCsValue(name)}] = ${formatCsValue(ex)};\n`).join('')
|
|
420
|
+
if ('' !== listQueryLines) {
|
|
421
|
+
Content(` var listQuery = new Dictionary<string, object?>();
|
|
422
|
+
` + listQueryLines)
|
|
423
|
+
}
|
|
424
|
+
|
|
409
425
|
Content(` var listResult = client.Direct(new Dictionary<string, object?>
|
|
410
426
|
{
|
|
411
427
|
["path"] = "${listPath}",
|
|
412
428
|
["method"] = "GET",
|
|
413
|
-
["params"] = listParams
|
|
429
|
+
["params"] = listParams,${'' === listQueryLines ? '' : `
|
|
430
|
+
["query"] = listQuery,`}
|
|
414
431
|
});
|
|
415
432
|
if (!TestRunner.LiveOk(listResult))
|
|
416
433
|
{
|
|
@@ -18,13 +18,13 @@ import {
|
|
|
18
18
|
each,
|
|
19
19
|
buildIdNames,
|
|
20
20
|
getMatchEntries,
|
|
21
|
-
isAuthActive, envName, envToken, entityRecordIdField,
|
|
21
|
+
isAuthActive, envName, envToken, entityDataIdField, entityRecordIdField,
|
|
22
22
|
serverVarEnv,
|
|
23
23
|
serverVariables,
|
|
24
24
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
25
25
|
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
26
26
|
liveRouteExamples, liveStepExamples,
|
|
27
|
-
liveEntity,
|
|
27
|
+
liveEntity, liveIdentity,
|
|
28
28
|
} from '@voxgig/sdkgen'
|
|
29
29
|
|
|
30
30
|
|
|
@@ -50,7 +50,7 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
|
|
|
50
50
|
// The live prologue of a flow built from offline fixtures: blocked without
|
|
51
51
|
// the ids it binds, a create-less load reading the first listed record, and
|
|
52
52
|
// a lenient run observing its checks rather than failing on them.
|
|
53
|
-
function liveFlowGate(entity: any, needs: any, entidEnv: string, strict: boolean,
|
|
53
|
+
function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string, strict: boolean,
|
|
54
54
|
hasSteps: boolean): string {
|
|
55
55
|
let out = ''
|
|
56
56
|
for (const [k, ex] of needs.examples || []) {
|
|
@@ -87,9 +87,10 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, strict: boolean
|
|
|
87
87
|
}
|
|
88
88
|
out += ' var client = setup.Client;\n'
|
|
89
89
|
if (null != needs.record) {
|
|
90
|
+
const id = `StructUtils.GetProp(setup.Idmap, ${JSON.stringify(needs.record)})`
|
|
90
91
|
out += ` if (setup.Live && !TestRunner.LiveExisting(setup.Data, LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
91
|
-
()
|
|
92
|
-
|
|
92
|
+
${JSON.stringify(identity.field)}, ${id},
|
|
93
|
+
() => new List<object?> { new Dictionary<string, object?> { ["id"] = ${id} } }))
|
|
93
94
|
{
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
@@ -100,10 +101,17 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, strict: boolean
|
|
|
100
101
|
.map(([k, v]: any) => ` [${JSON.stringify(k)}] = setup.Idmap[${JSON.stringify(v)}],`)
|
|
101
102
|
.concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
|
|
102
103
|
.map(([k, ex]) => ` [${JSON.stringify(k)}] = ${formatCsValue(ex)},`)).join('')
|
|
103
|
-
out += ` if (setup.Live
|
|
104
|
-
() => client.${entity.Name}().List(new Dictionary<string, object?> {${match} }, null)))
|
|
104
|
+
out += ` if (setup.Live)
|
|
105
105
|
{
|
|
106
|
-
|
|
106
|
+
var liveId = setup.SyntheticOnly ? null : StructUtils.GetProp(setup.Idmap, ${JSON.stringify(identity.key)});
|
|
107
|
+
${undefined === identity.ex ? '' : ` liveId ??= ${formatCsValue(identity.ex)};
|
|
108
|
+
`} TestRunner.LivePace();
|
|
109
|
+
if (!TestRunner.LiveExisting(setup.Data, LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
110
|
+
${JSON.stringify(identity.field)}, liveId,
|
|
111
|
+
() => client.${entity.Name}().List(new Dictionary<string, object?> {${match} }, null)))
|
|
112
|
+
{
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
107
115
|
}
|
|
108
116
|
`
|
|
109
117
|
}
|
|
@@ -225,7 +233,8 @@ ${skipBlock}`)
|
|
|
225
233
|
|
|
226
234
|
const flowBody = (flow: any) => {
|
|
227
235
|
const steps = flowSteps(flow) as any[]
|
|
228
|
-
Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), entidEnvVar, strict,
|
|
236
|
+
Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), liveIdentity(entity, flow), entidEnvVar, strict,
|
|
237
|
+
steps.length > 0))
|
|
229
238
|
|
|
230
239
|
// Check if the flow has a create step; if not, bootstrap entity data
|
|
231
240
|
const flowHasCreate = steps.some((s: any) => s.o === 'create')
|
|
@@ -246,6 +255,7 @@ ${skipBlock}`)
|
|
|
246
255
|
each(steps, (step: any, index: any) => {
|
|
247
256
|
const opgen: OpGen = GENERATE_OP[step.o]
|
|
248
257
|
if (opgen) {
|
|
258
|
+
Content(LIVE_PACE)
|
|
249
259
|
opgen({ ...genCtx, flow }, step, index)
|
|
250
260
|
Content('\n')
|
|
251
261
|
}
|
|
@@ -639,9 +649,8 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
639
649
|
Assert.True(${resdatavar} != null, "expected update result to be a map");
|
|
640
650
|
`)
|
|
641
651
|
if (hasEntIdU) {
|
|
642
|
-
Content(`
|
|
643
|
-
|
|
644
|
-
`)
|
|
652
|
+
Content(sameId(entity, `StructUtils.GetProp(${resdatavar}, ${rid(entity)})`, `${datavar}Up["id"]`,
|
|
653
|
+
'expected update result id to match'))
|
|
645
654
|
}
|
|
646
655
|
|
|
647
656
|
// Assert TextFieldMark
|
|
@@ -706,9 +715,8 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
706
715
|
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} var ${datavar}Loaded = ${entvar}.Load(${matchvar}, null);
|
|
707
716
|
var ${datavar}LoadResult = Helpers.ToMapAny(${datavar}Loaded is IEntity le ? le.Data() : ${datavar}Loaded);
|
|
708
717
|
Assert.True(${datavar}LoadResult != null, "expected load result to be a map");
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
`)
|
|
718
|
+
${sameId(entity, `StructUtils.GetProp(${datavar}LoadResult, ${rid(entity)})`,
|
|
719
|
+
`StructUtils.GetProp(${srcdatavar}, ${rid(entity)})`, 'expected load result id to match')}`)
|
|
712
720
|
}
|
|
713
721
|
else {
|
|
714
722
|
Content(` var ${matchvar} = new Dictionary<string, object?>();
|
|
@@ -752,6 +760,26 @@ function rid(entity: any): string {
|
|
|
752
760
|
}
|
|
753
761
|
|
|
754
762
|
|
|
763
|
+
const LIVE_PACE = ` if (setup.Live)
|
|
764
|
+
{
|
|
765
|
+
TestRunner.LivePace();
|
|
766
|
+
}
|
|
767
|
+
`
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
// A result's identity matches the one asked for, live only where the
|
|
771
|
+
// record's schema has a field to repeat it in.
|
|
772
|
+
function sameId(entity: any, result: string, expected: string, message: string): string {
|
|
773
|
+
const check = `Assert.True(TestRunner.LiveSameId(${result}, ${expected}), ${JSON.stringify(message)});`
|
|
774
|
+
return null == entityDataIdField(entity) ? ` if (!setup.Live)
|
|
775
|
+
{
|
|
776
|
+
${check}
|
|
777
|
+
}
|
|
778
|
+
` : ` ${check}
|
|
779
|
+
`
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
|
|
755
783
|
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
756
784
|
// in another field reads the key from there too.
|
|
757
785
|
function fixtureIdentity(entity: any): string {
|
|
@@ -177,6 +177,23 @@ public class ProjectNameSDK
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
// A raw request has no point to declare its response type, so it asks
|
|
181
|
+
// for the JSON it reads: an API that negotiates on Accept otherwise
|
|
182
|
+
// answers in its own default format. A caller's own accept wins.
|
|
183
|
+
var hasAccept = false;
|
|
184
|
+
foreach (var key in ctx.Spec.Headers.Keys)
|
|
185
|
+
{
|
|
186
|
+
if (string.Equals(key, "accept", StringComparison.OrdinalIgnoreCase))
|
|
187
|
+
{
|
|
188
|
+
hasAccept = true;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (!hasAccept)
|
|
193
|
+
{
|
|
194
|
+
ctx.Spec.Headers["accept"] = "application/json";
|
|
195
|
+
}
|
|
196
|
+
|
|
180
197
|
utility.PrepareAuth(ctx);
|
|
181
198
|
|
|
182
199
|
return utility.MakeFetchDef(ctx);
|
|
@@ -151,6 +151,16 @@ defmodule ProjectName do
|
|
|
151
151
|
Enum.each(H.entries(uh), fn {k, v} -> S.setprop(S.getprop(spec, "headers"), k, v) end)
|
|
152
152
|
end
|
|
153
153
|
|
|
154
|
+
# A raw request has no point to declare its response type, so it asks
|
|
155
|
+
# for the JSON it reads: an API that negotiates on Accept otherwise
|
|
156
|
+
# answers in its own default format. A caller's own accept wins.
|
|
157
|
+
spec_headers = S.getprop(spec, "headers")
|
|
158
|
+
|
|
159
|
+
if S.ismap(spec_headers) and
|
|
160
|
+
not Enum.any?(H.entries(spec_headers), fn {k, _} -> String.downcase(to_string(k)) == "accept" end) do
|
|
161
|
+
S.setprop(spec_headers, "accept", "application/json")
|
|
162
|
+
end
|
|
163
|
+
|
|
154
164
|
{_spec, err} = Utility.prepare_auth(ctx)
|
|
155
165
|
if err != nil, do: raise(err)
|
|
156
166
|
|
|
@@ -248,7 +248,10 @@ func Test${entity.Name}Direct(t *testing.T) {
|
|
|
248
248
|
t.Skip(_reason)
|
|
249
249
|
return
|
|
250
250
|
}
|
|
251
|
-
${listSkipBlock}
|
|
251
|
+
${listSkipBlock} if setup.live {
|
|
252
|
+
livePace()
|
|
253
|
+
}
|
|
254
|
+
client := setup.client
|
|
252
255
|
|
|
253
256
|
`)
|
|
254
257
|
|
|
@@ -396,7 +399,10 @@ ${listLiveQueryLines}
|
|
|
396
399
|
t.Skip(_reason)
|
|
397
400
|
return
|
|
398
401
|
}
|
|
399
|
-
${loadSkipBlock}
|
|
402
|
+
${loadSkipBlock} if setup.live {
|
|
403
|
+
livePace()
|
|
404
|
+
}
|
|
405
|
+
client := setup.client
|
|
400
406
|
|
|
401
407
|
`)
|
|
402
408
|
|
|
@@ -428,10 +434,20 @@ ${loadSkipBlock} client := setup.client
|
|
|
428
434
|
`)
|
|
429
435
|
}
|
|
430
436
|
|
|
437
|
+
// The list sends the query its route requires, as direct-list does.
|
|
438
|
+
const listQueryLines = liveQueryExamples(listPoint)
|
|
439
|
+
.map(([name, ex]) => `\t\t\tlistQuery[${JSON.stringify(name)}] = ${JSON.stringify(ex)}\n`)
|
|
440
|
+
.join('')
|
|
441
|
+
if ('' !== listQueryLines) {
|
|
442
|
+
Content(` listQuery := map[string]any{}
|
|
443
|
+
` + listQueryLines)
|
|
444
|
+
}
|
|
445
|
+
|
|
431
446
|
Content(` listResult, listErr := client.Direct(map[string]any{
|
|
432
447
|
"path": "${listPath}",
|
|
433
448
|
"method": "GET",
|
|
434
|
-
"params": listParams
|
|
449
|
+
"params": listParams,${'' === listQueryLines ? '' : `
|
|
450
|
+
"query": listQuery,`}
|
|
435
451
|
})
|
|
436
452
|
if listErr != nil {
|
|
437
453
|
liveMiss(t, ${strictConst}, "Live list discovery failed: %v", listErr)
|
|
@@ -716,7 +732,10 @@ function generateDirectGraphqlGo(
|
|
|
716
732
|
t.Skip(_reason)
|
|
717
733
|
return
|
|
718
734
|
}
|
|
719
|
-
${getOnlySkip}${skipBlock}
|
|
735
|
+
${getOnlySkip}${skipBlock} if setup.live {
|
|
736
|
+
livePace()
|
|
737
|
+
}
|
|
738
|
+
client := setup.client
|
|
720
739
|
|
|
721
740
|
variables := map[string]any{}
|
|
722
741
|
if setup.live {
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
33
33
|
liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
|
|
34
34
|
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
35
|
-
liveEntity,
|
|
35
|
+
liveEntity, liveIdentity,
|
|
36
36
|
} from '@voxgig/sdkgen'
|
|
37
37
|
|
|
38
38
|
|
|
@@ -229,8 +229,8 @@ ${failureTests(model, entity)}` : ''}${validateTest(model, entity)}
|
|
|
229
229
|
|
|
230
230
|
const flowBody = (flow: any) => {
|
|
231
231
|
const steps = flowSteps(flow) as any[]
|
|
232
|
-
Content(liveFlowGate(entity, liveFlowNeeds(entity, flow),
|
|
233
|
-
PROJUPPER + '_TEST_' + envToken(entity.name) + '_ENTID', steps.length > 0))
|
|
232
|
+
Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), liveIdentity(entity, flow), strict,
|
|
233
|
+
strictConst, PROJUPPER + '_TEST_' + envToken(entity.name) + '_ENTID', steps.length > 0))
|
|
234
234
|
|
|
235
235
|
// Check if the flow has a create step; if not, bootstrap entity data
|
|
236
236
|
const flowHasCreate = steps.some((s: any) => s.o === 'create')
|
|
@@ -262,6 +262,7 @@ ${failureTests(model, entity)}` : ''}${validateTest(model, entity)}
|
|
|
262
262
|
}
|
|
263
263
|
const opgen: OpGen = GENERATE_OP[step.o]
|
|
264
264
|
if (opgen) {
|
|
265
|
+
Content(LIVE_PACE)
|
|
265
266
|
opgen({ ...genCtx, flow }, step, index)
|
|
266
267
|
Content('\n')
|
|
267
268
|
}
|
|
@@ -397,10 +398,16 @@ ${fixtureIdentity(entity)}
|
|
|
397
398
|
})
|
|
398
399
|
|
|
399
400
|
|
|
401
|
+
const LIVE_PACE = ` if setup.live {
|
|
402
|
+
livePace()
|
|
403
|
+
}
|
|
404
|
+
`
|
|
405
|
+
|
|
406
|
+
|
|
400
407
|
// The live prologue of a flow built from offline fixtures: blocked without
|
|
401
408
|
// the ids it binds, a create-less load reading the first listed record, and
|
|
402
409
|
// a lenient run observing its checks rather than failing on them.
|
|
403
|
-
function liveFlowGate(entity: any, needs: any, strict: boolean, strictConst: string,
|
|
410
|
+
function liveFlowGate(entity: any, needs: any, identity: any, strict: boolean, strictConst: string,
|
|
404
411
|
entidEnv: string, hasSteps: boolean): string {
|
|
405
412
|
let out = ''
|
|
406
413
|
if (null != needs.examples) {
|
|
@@ -435,10 +442,12 @@ function liveFlowGate(entity: any, needs: any, strict: boolean, strictConst: str
|
|
|
435
442
|
out += '\t\tclient := setup.client\n\t\t_ = client\n'
|
|
436
443
|
}
|
|
437
444
|
if (null != needs.record) {
|
|
445
|
+
const id = `setup.idmap[${JSON.stringify(needs.record)}]`
|
|
438
446
|
out += ` if setup.live {
|
|
439
|
-
liveExisting(t, ${strictConst}, setup.data, ${JSON.stringify(entity.name)},
|
|
440
|
-
|
|
441
|
-
|
|
447
|
+
liveExisting(t, ${strictConst}, setup.data, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, ${id},
|
|
448
|
+
func() (any, error) {
|
|
449
|
+
return []any{map[string]any{"id": ${id}}}, nil
|
|
450
|
+
})
|
|
442
451
|
}
|
|
443
452
|
`
|
|
444
453
|
}
|
|
@@ -448,9 +457,18 @@ function liveFlowGate(entity: any, needs: any, strict: boolean, strictConst: str
|
|
|
448
457
|
.concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
|
|
449
458
|
.map(([k, ex]) => `${JSON.stringify(k)}: ${JSON.stringify(ex)}`)).join(', ')
|
|
450
459
|
out += ` if setup.live {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
460
|
+
var _liveId any
|
|
461
|
+
if !setup.syntheticOnly {
|
|
462
|
+
_liveId = setup.idmap[${JSON.stringify(identity.key)}]
|
|
463
|
+
}
|
|
464
|
+
${undefined === identity.ex ? '' : ` if _liveId == nil {
|
|
465
|
+
_liveId = ${goIdLit(identity.ex)}
|
|
466
|
+
}
|
|
467
|
+
`} livePace()
|
|
468
|
+
liveExisting(t, ${strictConst}, setup.data, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, _liveId,
|
|
469
|
+
func() (any, error) {
|
|
470
|
+
return client.${entity.Name}(nil).List(map[string]any{${match}}, nil)
|
|
471
|
+
})
|
|
454
472
|
}
|
|
455
473
|
`
|
|
456
474
|
}
|
|
@@ -685,7 +703,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
685
703
|
}
|
|
686
704
|
`)
|
|
687
705
|
if (hasEntIdU) {
|
|
688
|
-
Content(` if ${resdatavar}[${rid(entity)}]
|
|
706
|
+
Content(` if ${liveDeclared(entity)}!liveSameId(${resdatavar}[${rid(entity)}], ${datavar}Up["id"]) {
|
|
689
707
|
t.Fatal("expected update result id to match")
|
|
690
708
|
}
|
|
691
709
|
`)
|
|
@@ -761,7 +779,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
761
779
|
if ${datavar}LoadResult == nil {
|
|
762
780
|
t.Fatal("expected load result to be a map")
|
|
763
781
|
}
|
|
764
|
-
if ${datavar}LoadResult[${rid(entity)}]
|
|
782
|
+
if ${liveDeclared(entity)}!liveSameId(${datavar}LoadResult[${rid(entity)}], ${srcdatavar}[${rid(entity)}]) {
|
|
765
783
|
t.Fatal("expected load result id to match")
|
|
766
784
|
}
|
|
767
785
|
`)
|
|
@@ -827,6 +845,13 @@ function rid(entity: any): string {
|
|
|
827
845
|
}
|
|
828
846
|
|
|
829
847
|
|
|
848
|
+
// A record whose schema has no field for the identity cannot repeat it, so a
|
|
849
|
+
// live result is not compared on it.
|
|
850
|
+
function liveDeclared(entity: any): string {
|
|
851
|
+
return null == entityDataIdField(entity) ? '!setup.live && ' : ''
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
|
|
830
855
|
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
831
856
|
// in another field reads the key from there too.
|
|
832
857
|
function fixtureIdentity(entity: any): string {
|
|
@@ -192,6 +192,20 @@ func (sdk *ProjectNameSDK) Prepare(fetchargs map[string]any) (map[string]any, er
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
// A raw request has no point to declare its response type, so it asks
|
|
196
|
+
// for the JSON it reads: an API that negotiates on Accept otherwise
|
|
197
|
+
// answers in its own default format. A caller's own accept wins.
|
|
198
|
+
hasAccept := false
|
|
199
|
+
for k := range ctx.Spec.Headers {
|
|
200
|
+
if strings.ToLower(k) == "accept" {
|
|
201
|
+
hasAccept = true
|
|
202
|
+
break
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if !hasAccept {
|
|
206
|
+
ctx.Spec.Headers["accept"] = "application/json"
|
|
207
|
+
}
|
|
208
|
+
|
|
195
209
|
_, err := utility.PrepareAuth(ctx)
|
|
196
210
|
if err != nil {
|
|
197
211
|
return nil, err
|
|
@@ -263,7 +263,10 @@ ${liveStrictNote(liveStrict(model, target.name), '//', ' ')}
|
|
|
263
263
|
Assumptions.assumeTrue(reason == null,
|
|
264
264
|
reason == null || "".equals(reason)
|
|
265
265
|
? "skipped via sdk-test-control.json" : reason);
|
|
266
|
-
${listSkipBlock}
|
|
266
|
+
${listSkipBlock} if (setup.live) {
|
|
267
|
+
RunnerSupport.livePace();
|
|
268
|
+
}
|
|
269
|
+
${SDK} client = setup.client;
|
|
267
270
|
|
|
268
271
|
`)
|
|
269
272
|
|
|
@@ -378,7 +381,10 @@ ${listLiveQueryLines ? ' if (setup.live) {\n' + listLiveQueryLines + ' }\n
|
|
|
378
381
|
Assumptions.assumeTrue(reason == null,
|
|
379
382
|
reason == null || "".equals(reason)
|
|
380
383
|
? "skipped via sdk-test-control.json" : reason);
|
|
381
|
-
${loadSkipBlock}
|
|
384
|
+
${loadSkipBlock} if (setup.live) {
|
|
385
|
+
RunnerSupport.livePace();
|
|
386
|
+
}
|
|
387
|
+
${SDK} client = setup.client;
|
|
382
388
|
|
|
383
389
|
`)
|
|
384
390
|
|
|
@@ -408,10 +414,19 @@ ${loadSkipBlock} ${SDK} client = setup.client;
|
|
|
408
414
|
`)
|
|
409
415
|
}
|
|
410
416
|
|
|
417
|
+
// The list sends the query its route requires, as direct-list does.
|
|
418
|
+
const listQueryLines = liveQueryExamples(listPoint)
|
|
419
|
+
.map(([name, ex]) => ` listQuery.put(${JSON.stringify(name)}, ${javaLiteral(ex)});\n`).join('')
|
|
420
|
+
if ('' !== listQueryLines) {
|
|
421
|
+
Content(` Map<String, Object> listQuery = new LinkedHashMap<>();
|
|
422
|
+
` + listQueryLines)
|
|
423
|
+
}
|
|
424
|
+
|
|
411
425
|
Content(` Map<String, Object> listResult = client.direct(jm(
|
|
412
426
|
"path", "${listPath}",
|
|
413
427
|
"method", "GET",
|
|
414
|
-
"params", listParams
|
|
428
|
+
"params", listParams${'' === listQueryLines ? '' : `,
|
|
429
|
+
"query", listQuery`}));
|
|
415
430
|
if (!liveOk(listResult)) {
|
|
416
431
|
RunnerSupport.liveMiss(LIVE_STRICT, "Live list discovery failed: " + RunnerSupport.liveDescribe(listResult));
|
|
417
432
|
}
|
|
@@ -20,11 +20,11 @@ import {
|
|
|
20
20
|
getMatchEntries,
|
|
21
21
|
isAuthActive,
|
|
22
22
|
serverVarEnv,
|
|
23
|
-
serverVariables, envName, envToken, entityRecordIdField,
|
|
23
|
+
serverVariables, envName, envToken, entityDataIdField, entityRecordIdField,
|
|
24
24
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
25
25
|
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
26
26
|
liveRouteExamples, liveStepExamples,
|
|
27
|
-
liveEntity,
|
|
27
|
+
liveEntity, liveIdentity,
|
|
28
28
|
} from '@voxgig/sdkgen'
|
|
29
29
|
|
|
30
30
|
|
|
@@ -54,7 +54,7 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
|
|
|
54
54
|
// The live prologue of a flow built from offline fixtures: blocked without
|
|
55
55
|
// the ids it binds, a create-less load reading the first listed record, and
|
|
56
56
|
// a lenient run observing its checks rather than failing on them.
|
|
57
|
-
function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: string,
|
|
57
|
+
function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string, accessor: string,
|
|
58
58
|
SDK: string, strict: boolean, hasSteps: boolean): string {
|
|
59
59
|
let out = ''
|
|
60
60
|
for (const [k, ex] of needs.examples || []) {
|
|
@@ -84,10 +84,12 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: strin
|
|
|
84
84
|
}
|
|
85
85
|
out += ` ${SDK} client = setup.client;\n`
|
|
86
86
|
if (null != needs.record) {
|
|
87
|
+
const id = `setup.idmap.get(${JSON.stringify(needs.record)})`
|
|
87
88
|
out += ` if (setup.live) {
|
|
88
|
-
RunnerSupport.liveExisting(setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
89
|
+
RunnerSupport.liveExisting(setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
90
|
+
${JSON.stringify(identity.field)}, ${id}, () -> {
|
|
89
91
|
Map<String, Object> record = new LinkedHashMap<>();
|
|
90
|
-
record.put("id",
|
|
92
|
+
record.put("id", ${id});
|
|
91
93
|
return List.of(record);
|
|
92
94
|
});
|
|
93
95
|
}
|
|
@@ -99,7 +101,13 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: strin
|
|
|
99
101
|
.concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
|
|
100
102
|
.map(([k, ex]) => `match.put(${JSON.stringify(k)}, ${javaLit(ex)});`)).join(' ')
|
|
101
103
|
out += ` if (setup.live) {
|
|
102
|
-
|
|
104
|
+
Object liveId = setup.syntheticOnly ? null : setup.idmap.get(${JSON.stringify(identity.key)});
|
|
105
|
+
${undefined === identity.ex ? '' : ` if (liveId == null) {
|
|
106
|
+
liveId = ${javaIdLit(identity.ex)};
|
|
107
|
+
}
|
|
108
|
+
`} RunnerSupport.livePace();
|
|
109
|
+
RunnerSupport.liveExisting(setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
110
|
+
${JSON.stringify(identity.field)}, liveId, () -> {
|
|
103
111
|
Map<String, Object> match = new LinkedHashMap<>();${match ? ' ' + match : ''}
|
|
104
112
|
return client.${accessor}(null).list(match, null);
|
|
105
113
|
});
|
|
@@ -227,8 +235,8 @@ ${liveStrictNote(strict, '//', ' ')}
|
|
|
227
235
|
|
|
228
236
|
const flowBody = (flow: any) => {
|
|
229
237
|
const steps = flowSteps(flow) as any[]
|
|
230
|
-
Content(liveFlowGate(entity, liveFlowNeeds(entity, flow),
|
|
231
|
-
steps.length > 0))
|
|
238
|
+
Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), liveIdentity(entity, flow), entidEnvVar,
|
|
239
|
+
accessor, SDK, strict, steps.length > 0))
|
|
232
240
|
|
|
233
241
|
// Check if the flow has a create step; if not, bootstrap entity data
|
|
234
242
|
const flowHasCreate = steps.some((s: any) => s.o === 'create')
|
|
@@ -248,6 +256,7 @@ ${liveStrictNote(strict, '//', ' ')}
|
|
|
248
256
|
each(steps, (step: any, index: any) => {
|
|
249
257
|
const opgen: OpGen = GENERATE_OP[step.o]
|
|
250
258
|
if (opgen) {
|
|
259
|
+
Content(LIVE_PACE)
|
|
251
260
|
opgen({ ...genCtx, flow }, step, index)
|
|
252
261
|
Content('\n')
|
|
253
262
|
}
|
|
@@ -614,9 +623,8 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
614
623
|
assertNotNull(${resdatavar}, "expected update result to be a map");
|
|
615
624
|
`)
|
|
616
625
|
if (hasEntIdU) {
|
|
617
|
-
Content(
|
|
618
|
-
|
|
619
|
-
`)
|
|
626
|
+
Content(sameId(entity, `${resdatavar}.get(${rid(entity)})`, `${datavar}Up.get("id")`,
|
|
627
|
+
'expected update result id to match'))
|
|
620
628
|
}
|
|
621
629
|
|
|
622
630
|
// Assert TextFieldMark
|
|
@@ -679,9 +687,8 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
679
687
|
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
|
|
680
688
|
Map<String, Object> ${datavar}LoadResult = Helpers.toMapAny(${datavar}Loaded instanceof SdkEntity ? ((SdkEntity) ${datavar}Loaded).data() : ${datavar}Loaded);
|
|
681
689
|
assertNotNull(${datavar}LoadResult, "expected load result to be a map");
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
`)
|
|
690
|
+
${sameId(entity, `${datavar}LoadResult.get(${rid(entity)})`, `${srcdatavar}.get(${rid(entity)})`,
|
|
691
|
+
'expected load result id to match')}`)
|
|
685
692
|
}
|
|
686
693
|
else {
|
|
687
694
|
Content(`${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
|
|
@@ -722,6 +729,24 @@ function rid(entity: any): string {
|
|
|
722
729
|
}
|
|
723
730
|
|
|
724
731
|
|
|
732
|
+
const LIVE_PACE = ` if (setup.live) {
|
|
733
|
+
RunnerSupport.livePace();
|
|
734
|
+
}
|
|
735
|
+
`
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
// A result's identity matches the one asked for, live only where the
|
|
739
|
+
// record's schema has a field to repeat it in.
|
|
740
|
+
function sameId(entity: any, result: string, expected: string, message: string): string {
|
|
741
|
+
const check = `assertTrue(RunnerSupport.liveSameId(${result}, ${expected}), ${JSON.stringify(message)});`
|
|
742
|
+
return null == entityDataIdField(entity) ? ` if (!setup.live) {
|
|
743
|
+
${check}
|
|
744
|
+
}
|
|
745
|
+
` : ` ${check}
|
|
746
|
+
`
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
|
|
725
750
|
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
726
751
|
// in another field reads the key from there too.
|
|
727
752
|
function fixtureIdentity(entity: any): string {
|
|
@@ -217,6 +217,12 @@ function generateDirectLoad(model: Model, entity: ModelEntity) {
|
|
|
217
217
|
` ${lp.name}: setup.idmap['${lp.key}'],`).join('\n')
|
|
218
218
|
const ancestorParamLines = liveAncestorParams.map((lp: any) =>
|
|
219
219
|
` ${jsProp('params', lp.name)} = setup.idmap['${lp.key}']`).join('\n')
|
|
220
|
+
// The list sends the query its route requires, as direct-list does.
|
|
221
|
+
const listQueryLines = liveQueryExamples(listPoint)
|
|
222
|
+
.map(([name, ex]) => `\n ${jsKey(name)}: ${jsLit(ex)},`).join('')
|
|
223
|
+
const listQueryBlock = '' === listQueryLines ? '' : `
|
|
224
|
+
query: {${listQueryLines}
|
|
225
|
+
},`
|
|
220
226
|
|
|
221
227
|
liveParamsBlock = ` if (setup.live) {
|
|
222
228
|
${liveQueryLines} const listResult = await client.direct({
|
|
@@ -224,7 +230,7 @@ ${liveQueryLines} const listResult = await client.direct({
|
|
|
224
230
|
method: 'GET',
|
|
225
231
|
params: {
|
|
226
232
|
${listParamLines}
|
|
227
|
-
}
|
|
233
|
+
},${listQueryBlock}
|
|
228
234
|
})
|
|
229
235
|
if (!listResult.ok || listResult.status < 200 || listResult.status >= 300) {
|
|
230
236
|
return void liveMiss(t, LIVE_STRICT, 'Live list discovery failed: ' + describeLive(listResult))
|
|
@@ -158,6 +158,13 @@ class ProjectNameSDK {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
// A raw request has no point to declare its response type, so it asks
|
|
162
|
+
// for the JSON it reads: an API that negotiates on Accept otherwise
|
|
163
|
+
// answers in its own default format. A caller's own accept wins.
|
|
164
|
+
if (!Object.keys(spec.headers).some((key) => 'accept' === key.toLowerCase())) {
|
|
165
|
+
spec.headers.accept = 'application/json'
|
|
166
|
+
}
|
|
167
|
+
|
|
161
168
|
// #SecretsResolve
|
|
162
169
|
|
|
163
170
|
// Apply SDK auth (apikey, auth prefix, etc.)
|