@voxgig/sdkgen 4.37.0 → 4.39.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 +13 -2
- package/dist/action/copies.d.ts +6 -1
- package/dist/action/copies.js +43 -1
- package/dist/action/copies.js.map +1 -1
- package/dist/action/doctor.d.ts +2 -0
- package/dist/action/doctor.js +25 -6
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/edition.js +3 -0
- package/dist/action/edition.js.map +1 -1
- package/dist/action/feature.js +3 -0
- package/dist/action/feature.js.map +1 -1
- package/dist/action/package.js +15 -0
- package/dist/action/package.js.map +1 -1
- package/dist/action/target.js +3 -0
- package/dist/action/target.js.map +1 -1
- package/dist/helpers/copymerge.d.ts +35 -0
- package/dist/helpers/copymerge.js +508 -0
- package/dist/helpers/copymerge.js.map +1 -0
- package/dist/helpers/flowGuard.js +4 -4
- package/dist/helpers/flowGuard.js.map +1 -1
- package/dist/helpers/liveDiscovery.d.ts +7 -0
- package/dist/helpers/liveDiscovery.js +20 -0
- package/dist/helpers/liveDiscovery.js.map +1 -0
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +4 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/pointPath.d.ts +2 -1
- package/dist/helpers/pointPath.js +6 -0
- package/dist/helpers/pointPath.js.map +1 -1
- package/dist/helpers/testPolicy.d.ts +14 -4
- package/dist/helpers/testPolicy.js +152 -54
- package/dist/helpers/testPolicy.js.map +1 -1
- package/dist/sdkgen.d.ts +8 -6
- package/dist/sdkgen.js +11 -5
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/utility.js +7 -3
- package/dist/utility.js.map +1 -1
- package/model/sdkgen.aontu +4 -0
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/TestDirect_c.ts +3 -2
- package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +3 -2
- package/project/.sdk/src/cmp/cpp/TestEntity_cpp.ts +33 -10
- package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +12 -12
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +73 -28
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +12 -10
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +67 -23
- package/project/.sdk/src/cmp/java/TestDirect_java.ts +12 -11
- package/project/.sdk/src/cmp/java/TestEntity_java.ts +71 -23
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +13 -12
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +41 -17
- package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +12 -10
- package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +64 -23
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +9 -5
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +61 -23
- package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +9 -5
- package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +58 -24
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +9 -5
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +61 -23
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +10 -6
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +59 -27
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +9 -5
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +59 -23
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +9 -8
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +56 -24
- package/project/.sdk/src/cmp/scala/TestDirect_scala.ts +3 -2
- package/project/.sdk/src/cmp/scala/TestEntity_scala.ts +36 -9
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +15 -32
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +41 -17
- package/project/.sdk/tm/c/tests/transport_test.c +33 -0
- package/project/.sdk/tm/c/utility/fetcher.c +151 -2
- package/project/.sdk/tm/c/utility/make_url.c +8 -6
- package/project/.sdk/tm/clojure/src/sdk/core.clj +17 -10
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +38 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +5 -4
- package/project/.sdk/tm/csharp/test/PrimaryUtilityTest.cs +69 -0
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +3 -1
- package/project/.sdk/tm/csharp/utility/MakeUrl.cs +5 -4
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +10 -6
- package/project/.sdk/tm/elixir/test/pipeline_test.exs +61 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +60 -0
- package/project/.sdk/tm/go/utility/fetcher.go +15 -4
- package/project/.sdk/tm/go/utility/make_url.go +4 -3
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +47 -0
- package/project/.sdk/tm/java/utility/MakeUrl.java +5 -4
- package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +5 -3
- package/project/.sdk/tm/js/test/live-runner.js +4 -3
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +40 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +41 -0
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +4 -3
- package/project/.sdk/tm/lua/test/primary_utility_test.lua +61 -0
- package/project/.sdk/tm/lua/utility/fetcher.lua +54 -6
- package/project/.sdk/tm/lua/utility/make_url.lua +5 -4
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +5 -5
- package/project/.sdk/tm/perl/t/primary_utility.t +54 -0
- package/project/.sdk/tm/perl/utility/fetcher.pm +65 -11
- package/project/.sdk/tm/perl/utility/make_url.pm +4 -3
- package/project/.sdk/tm/php/test/PipelineTest.php +52 -0
- package/project/.sdk/tm/php/utility/Fetcher.php +81 -15
- package/project/.sdk/tm/php/utility/MakeUrl.php +5 -3
- package/project/.sdk/tm/py/pkg/utility/fetcher.py +1 -0
- package/project/.sdk/tm/py/pkg/utility/make_url.py +5 -4
- package/project/.sdk/tm/py/test/test_primary_utility.py +52 -0
- package/project/.sdk/tm/rb/test/primary_utility_test.rb +46 -0
- package/project/.sdk/tm/rb/utility/fetcher.rb +41 -5
- package/project/.sdk/tm/rb/utility/make_url.rb +5 -3
- package/project/.sdk/tm/rust/tests/primary_utility_test.rs +65 -0
- package/project/.sdk/tm/rust/utility/make_url.rs +7 -6
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +47 -1
- package/project/.sdk/tm/scala/utility/Make.scala +8 -6
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +59 -15
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +4 -4
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/PrimaryUtilityTest.swift +72 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +5 -3
- package/project/.sdk/tm/ts/test/live-runner.ts +4 -3
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +40 -0
- package/project/.sdk/tm/zig/core/utility.zig +5 -5
- package/project/sdkgen-package.json +1 -1
- package/src/action/copies.ts +54 -0
- package/src/action/doctor.ts +36 -7
- package/src/action/edition.ts +9 -1
- package/src/action/feature.ts +7 -1
- package/src/action/package.ts +28 -1
- package/src/action/target.ts +7 -1
- package/src/helpers/copymerge.ts +707 -0
- package/src/helpers/flowGuard.ts +4 -4
- package/src/helpers/liveDiscovery.ts +31 -0
- package/src/helpers/opShape.ts +6 -0
- package/src/helpers/pointPath.ts +8 -0
- package/src/helpers/testPolicy.ts +193 -55
- package/src/sdkgen.ts +13 -3
- package/src/types.ts +2 -0
- package/src/utility.ts +10 -4
|
@@ -25,13 +25,13 @@ import {
|
|
|
25
25
|
buildIdNames,
|
|
26
26
|
getMatchEntries,
|
|
27
27
|
isAuthActive,
|
|
28
|
-
entityDataIdField, envName, envToken,
|
|
28
|
+
entityDataIdField, entityRecordIdField, envName, envToken, luaKey,
|
|
29
29
|
serverVarEnv,
|
|
30
30
|
serverVariables,
|
|
31
31
|
invalidRequest,
|
|
32
32
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
33
33
|
liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
|
|
34
|
-
|
|
34
|
+
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
35
35
|
liveEntity,
|
|
36
36
|
} from '@voxgig/sdkgen'
|
|
37
37
|
|
|
@@ -54,6 +54,17 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
|
|
|
54
54
|
// a lenient run observing its checks rather than failing on them.
|
|
55
55
|
function liveFlowGate(entity: any, needs: any, entidEnv: string, strict: boolean): string {
|
|
56
56
|
let out = ''
|
|
57
|
+
if (null != needs.examples) {
|
|
58
|
+
out += ` if setup.live then
|
|
59
|
+
for _live_key, _live_ex in pairs({${needs.examples
|
|
60
|
+
.map(([k, ex]: any) => '[' + JSON.stringify(k) + '] = ' + formatLuaValue(ex)).join(', ')}}) do
|
|
61
|
+
if setup.synthetic_only or setup.idmap[_live_key] == nil then
|
|
62
|
+
setup.idmap[_live_key] = _live_ex
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
`
|
|
67
|
+
}
|
|
57
68
|
if (0 < needs.keys.length) {
|
|
58
69
|
out += ` if setup.live then
|
|
59
70
|
for _, _live_key in ipairs({${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')}}) do
|
|
@@ -71,6 +82,14 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, strict: boolean
|
|
|
71
82
|
`
|
|
72
83
|
}
|
|
73
84
|
out += ' local client = setup.client\n'
|
|
85
|
+
if (null != needs.record) {
|
|
86
|
+
out += ` if setup.live then
|
|
87
|
+
runner.live_existing(pending, setup, LIVE_STRICT, ${JSON.stringify(entity.name)}, function()
|
|
88
|
+
return { { id = setup.idmap[${JSON.stringify(needs.record)}] } }
|
|
89
|
+
end)
|
|
90
|
+
end
|
|
91
|
+
`
|
|
92
|
+
}
|
|
74
93
|
if (null != needs.discover) {
|
|
75
94
|
const match = Object.entries(needs.discover)
|
|
76
95
|
.map(([k, v]: any) => `[${JSON.stringify(k)}] = setup.idmap[${JSON.stringify(v)}]`)
|
|
@@ -266,19 +285,18 @@ ${failureTests(entity)}` : ''}${validateTest(entity)}
|
|
|
266
285
|
`)
|
|
267
286
|
}
|
|
268
287
|
|
|
269
|
-
const getOnly
|
|
270
|
-
if
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
Content(` pending(${formatLuaValue(liveExcludedSummary(getOnly))})
|
|
288
|
+
for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
|
|
289
|
+
Content(` if setup.live${getOnly ? ` and os.getenv(${formatLuaValue(LIVE_GETONLY_ENV)}) == "TRUE"` : ''} then
|
|
290
|
+
${liveExcludedLines(plan).map((line) => ' print(' + formatLuaValue(line) + ')\n').join('')}`)
|
|
291
|
+
if (!runs) {
|
|
292
|
+
Content(` pending(${formatLuaValue(liveExcludedSummary(plan))})
|
|
275
293
|
return
|
|
276
294
|
end
|
|
277
295
|
|
|
278
296
|
`)
|
|
279
297
|
}
|
|
280
298
|
else {
|
|
281
|
-
flowBody(
|
|
299
|
+
flowBody(plan.flow)
|
|
282
300
|
Content(` return
|
|
283
301
|
end
|
|
284
302
|
|
|
@@ -306,7 +324,7 @@ end)
|
|
|
306
324
|
f:close()
|
|
307
325
|
|
|
308
326
|
local entity_data = json.decode(entity_data_source)
|
|
309
|
-
|
|
327
|
+
${fixtureIdentity(entity)}
|
|
310
328
|
local options = {}
|
|
311
329
|
options["entity"] = entity_data["existing"]
|
|
312
330
|
|
|
@@ -433,7 +451,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
433
451
|
assert.is_not_nil(${datavar})
|
|
434
452
|
`)
|
|
435
453
|
if (null != ctx.entity.id) {
|
|
436
|
-
Content(` assert.is_not_nil(${datavar}[
|
|
454
|
+
Content(` assert.is_not_nil(${datavar}[${rid(ctx.entity)}])
|
|
437
455
|
`)
|
|
438
456
|
}
|
|
439
457
|
}
|
|
@@ -472,7 +490,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
472
490
|
Content(` }
|
|
473
491
|
`)
|
|
474
492
|
}
|
|
475
|
-
Content(liveFill(entity, step, matchvar))
|
|
493
|
+
Content(liveFill(entity, step, matchvar, flow))
|
|
476
494
|
|
|
477
495
|
Content(`
|
|
478
496
|
local ${listvar}_result, err = ${entvar}:list(${matchvar}, nil)
|
|
@@ -493,7 +511,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
493
511
|
Content(`
|
|
494
512
|
local found_item = vs.select(
|
|
495
513
|
runner.entity_list_to_data(${listvar}_result),
|
|
496
|
-
{
|
|
514
|
+
{ ${luaKey(entityRecordIdField(entity))} = ${refDataVar}[${rid(entity)}] })
|
|
497
515
|
assert.is_false(vs.isempty(found_item))
|
|
498
516
|
`)
|
|
499
517
|
} else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
|
|
@@ -501,7 +519,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
501
519
|
Content(`
|
|
502
520
|
local not_found_item = vs.select(
|
|
503
521
|
runner.entity_list_to_data(${listvar}_result),
|
|
504
|
-
{
|
|
522
|
+
{ ${luaKey(entityRecordIdField(entity))} = ${refDataVar}[${rid(entity)}] })
|
|
505
523
|
assert.is_true(vs.isempty(not_found_item))
|
|
506
524
|
`)
|
|
507
525
|
}
|
|
@@ -534,7 +552,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
534
552
|
Content(` local ${datavar}_up = {
|
|
535
553
|
`)
|
|
536
554
|
if (hasEntIdU) {
|
|
537
|
-
Content(` id = ${srcdatavar}[
|
|
555
|
+
Content(` id = ${srcdatavar}[${rid(entity)}],
|
|
538
556
|
`)
|
|
539
557
|
}
|
|
540
558
|
|
|
@@ -570,7 +588,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
570
588
|
assert.is_not_nil(${resdatavar})
|
|
571
589
|
`)
|
|
572
590
|
if (hasEntIdU) {
|
|
573
|
-
Content(` assert.are.equal(${resdatavar}[
|
|
591
|
+
Content(` assert.are.equal(${resdatavar}[${rid(entity)}], ${datavar}_up["id"])
|
|
574
592
|
`)
|
|
575
593
|
}
|
|
576
594
|
|
|
@@ -628,18 +646,18 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
628
646
|
}
|
|
629
647
|
if (hasEntId) {
|
|
630
648
|
Content(` local ${matchvar} = {
|
|
631
|
-
id = ${srcdatavar}[
|
|
649
|
+
id = ${srcdatavar}[${rid(entity)}],
|
|
632
650
|
}
|
|
633
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
|
|
651
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
|
|
634
652
|
assert.is_nil(err)
|
|
635
653
|
local ${datavar}_load_result = helpers.to_map(type(${datavar}_loaded) == 'table' and ${datavar}_loaded.data_get and ${datavar}_loaded:data_get() or ${datavar}_loaded)
|
|
636
654
|
assert.is_not_nil(${datavar}_load_result)
|
|
637
|
-
assert.are.equal(${datavar}_load_result[
|
|
655
|
+
assert.are.equal(${datavar}_load_result[${rid(entity)}], ${srcdatavar}[${rid(entity)}])
|
|
638
656
|
`)
|
|
639
657
|
}
|
|
640
658
|
else {
|
|
641
659
|
Content(` local ${matchvar} = {}
|
|
642
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
|
|
660
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
|
|
643
661
|
assert.is_nil(err)
|
|
644
662
|
assert.is_not_nil(${datavar}_loaded)
|
|
645
663
|
`)
|
|
@@ -669,7 +687,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
669
687
|
}
|
|
670
688
|
// Always match the prior-created entity by id to avoid mock-order flakes.
|
|
671
689
|
Content(` local ${matchvar} = {
|
|
672
|
-
id = ${srcdatavar}[
|
|
690
|
+
id = ${srcdatavar}[${rid(entity)}],
|
|
673
691
|
}
|
|
674
692
|
${parentMatch(step, matchvar)} local _, err = ${entvar}:remove(${matchvar}, nil)
|
|
675
693
|
assert.is_nil(err)
|
|
@@ -678,12 +696,32 @@ ${parentMatch(step, matchvar)} local _, err = ${entvar}:remove(${matchvar}, n
|
|
|
678
696
|
|
|
679
697
|
|
|
680
698
|
|
|
699
|
+
// The record field the entity's identity is read from, as a Lua string.
|
|
700
|
+
function rid(entity: any): string {
|
|
701
|
+
return JSON.stringify(entityRecordIdField(entity))
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
706
|
+
// in another field reads the key from there too.
|
|
707
|
+
function fixtureIdentity(entity: any): string {
|
|
708
|
+
const field = entityRecordIdField(entity)
|
|
709
|
+
return 'id' === field ? '' : `
|
|
710
|
+
for _, rec in pairs(((entity_data["existing"] or {})[${JSON.stringify(entity.name)}]) or {}) do
|
|
711
|
+
if type(rec) == "table" and rec["id"] ~= nil then
|
|
712
|
+
rec[${JSON.stringify(field)}] = rec["id"]
|
|
713
|
+
end
|
|
714
|
+
end
|
|
715
|
+
`
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
|
|
681
719
|
// A child's route names its parents, and an entity no earlier step has
|
|
682
720
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
683
721
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
684
722
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
685
|
-
function liveFill(entity: any, step: any, matchvar: string): string {
|
|
686
|
-
const fills = liveStepExamples(entity, step)
|
|
723
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
|
|
724
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
687
725
|
return 0 === fills.length ? '' : ` if setup.live then
|
|
688
726
|
${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${formatLuaValue(ex)}\n`).join('')} end
|
|
689
727
|
`
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables,
|
|
17
17
|
pointParts,
|
|
18
|
+
pointSlash,
|
|
18
19
|
pointPlaceholders,
|
|
19
20
|
liveStrict,
|
|
20
21
|
liveStrictNote,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
liveQueryExamples,
|
|
25
26
|
liveEntity,
|
|
26
27
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
28
|
+
liveDirectDiscovery,
|
|
27
29
|
} from '@voxgig/sdkgen'
|
|
28
30
|
|
|
29
31
|
import { perlStringLiteral } from './utility_perl'
|
|
@@ -147,7 +149,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
147
149
|
const listOp = entity.op?.list
|
|
148
150
|
|
|
149
151
|
const loadPoint = loadOp?.points?.[0]
|
|
150
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
152
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
151
153
|
const allLoadParams = loadPoint?.g?.params || []
|
|
152
154
|
// Only path params that actually appear in the URL template drive direct-
|
|
153
155
|
// test path-param setup and URL-substitution asserts (see TestDirect_rb).
|
|
@@ -164,7 +166,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
164
166
|
_renamedPlaceholders.has(p.n) || _renamedPlaceholders.has(p.or))
|
|
165
167
|
|
|
166
168
|
const listPoint = listOp?.points?.[0]
|
|
167
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
169
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
168
170
|
const listParams = listPoint?.g?.params || []
|
|
169
171
|
|
|
170
172
|
// Required query params with spec-provided examples - needed in live mode.
|
|
@@ -285,8 +287,10 @@ ${listLiveQueryLines ? ' if ($setup->{live}) {\n' + listLiveQueryLines + ' }\n
|
|
|
285
287
|
}
|
|
286
288
|
else if (hasLoad && loadPoint) {
|
|
287
289
|
const label = 'direct-load-' + entity.name
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
291
|
+
const discover = null != discovery
|
|
292
|
+
const idParam = discovery?.param
|
|
293
|
+
const idField = discovery?.field
|
|
290
294
|
const loadLiveIdKeys: string[] = loadAllHaveExamples ? [] :
|
|
291
295
|
discover ? listParams.map(liveKey).concat(loadParams.filter((p: any) => idParam !== p.n).map(liveKey)) :
|
|
292
296
|
loadParams.map(liveKey)
|
|
@@ -328,7 +332,7 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
|
|
|
328
332
|
last DIRECT_LOAD;
|
|
329
333
|
}
|
|
330
334
|
my $first = ref $records->[0] eq 'HASH' ? $records->[0] : {};
|
|
331
|
-
my $found = $first->{'${
|
|
335
|
+
my $found = $first->{'${idField}'};
|
|
332
336
|
if (!defined $found) {
|
|
333
337
|
${N}TestRunner::live_miss(LIVE_STRICT, '${label}', 'Live load blocked: discovery returned no usable identity');
|
|
334
338
|
last DIRECT_LOAD;
|
|
@@ -18,11 +18,11 @@ import {
|
|
|
18
18
|
each,
|
|
19
19
|
buildIdNames,
|
|
20
20
|
getMatchEntries,
|
|
21
|
-
isAuthActive, envName, envToken,
|
|
21
|
+
isAuthActive, envName, envToken, entityRecordIdField,
|
|
22
22
|
serverVarEnv,
|
|
23
23
|
serverVariables,
|
|
24
24
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
25
|
-
|
|
25
|
+
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
26
26
|
liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
|
|
27
27
|
liveEntity,
|
|
28
28
|
} from '@voxgig/sdkgen'
|
|
@@ -51,6 +51,15 @@ function liveFlowGate(N: string, entity: any, needs: any, entidEnv: string,
|
|
|
51
51
|
strict: boolean): string {
|
|
52
52
|
const label = entity.name + ': basic flow'
|
|
53
53
|
let out = ''
|
|
54
|
+
if (null != needs.examples) {
|
|
55
|
+
out += ` if ($setup->{live}) {
|
|
56
|
+
my %live_ex = (${needs.examples.map(([k, ex]: any) => perlLit(k) + ' => ' + perlLit(ex)).join(', ')});
|
|
57
|
+
for my $k (sort keys %live_ex) {
|
|
58
|
+
$setup->{idmap}{$k} = $live_ex{$k} if $setup->{synthetic_only} || !defined $setup->{idmap}{$k};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
}
|
|
54
63
|
if (0 < needs.keys.length) {
|
|
55
64
|
out += ` if ($setup->{live}) {
|
|
56
65
|
my @missing = grep { $setup->{synthetic_only} || !defined $setup->{idmap}{$_} } (${needs.keys.map((k: string) => `'${k}'`).join(', ')});
|
|
@@ -69,6 +78,13 @@ function liveFlowGate(N: string, entity: any, needs: any, entidEnv: string,
|
|
|
69
78
|
`
|
|
70
79
|
}
|
|
71
80
|
out += ' my $client = $setup->{client};\n'
|
|
81
|
+
if (null != needs.record) {
|
|
82
|
+
out += ` if ($setup->{live}) {
|
|
83
|
+
${N}TestRunner::live_existing($setup, LIVE_STRICT, '${label}', '${entity.name}',
|
|
84
|
+
sub { [{ 'id' => $setup->{idmap}{${perlLit(needs.record)}} }] }) or last BASIC_FLOW;
|
|
85
|
+
}
|
|
86
|
+
`
|
|
87
|
+
}
|
|
72
88
|
if (null != needs.discover) {
|
|
73
89
|
const match = Object.entries(needs.discover)
|
|
74
90
|
.map(([k, v]: any) => `'${k}' => $setup->{idmap}{'${v}'}`)
|
|
@@ -225,20 +241,19 @@ BASIC_FLOW: {
|
|
|
225
241
|
`)
|
|
226
242
|
}
|
|
227
243
|
|
|
228
|
-
const getOnly
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
pass('${entity.name}: basic flow skipped, a GET-only live run excludes every step');
|
|
244
|
+
for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
|
|
245
|
+
Content(` if ($setup->{live}${getOnly ? ` && ($ENV{${LIVE_GETONLY_ENV}} // '') eq 'TRUE'` : ''}) {
|
|
246
|
+
${liveExcludedLines(plan).map((line) => ' note(' + perlLit(line) + ');\n').join('')}`)
|
|
247
|
+
if (!runs) {
|
|
248
|
+
Content(` note(${perlLit(liveExcludedSummary(plan))});
|
|
249
|
+
pass('${entity.name}: basic flow skipped, the live run leaves no step to run');
|
|
235
250
|
last BASIC_FLOW;
|
|
236
251
|
}
|
|
237
252
|
|
|
238
253
|
`)
|
|
239
254
|
}
|
|
240
255
|
else {
|
|
241
|
-
flowBody(
|
|
256
|
+
flowBody(plan.flow)
|
|
242
257
|
Content(` last BASIC_FLOW;
|
|
243
258
|
}
|
|
244
259
|
|
|
@@ -264,7 +279,7 @@ ${liveExcludedLines(getOnly).map((line) => ' note(' + perlLit(line) + ');\n')
|
|
|
264
279
|
local $/;
|
|
265
280
|
Voxgig::Struct::parse_json(<$fh>);
|
|
266
281
|
};
|
|
267
|
-
|
|
282
|
+
${fixtureIdentity(entity)}
|
|
268
283
|
my $options = {};
|
|
269
284
|
$options->{entity} = $entity_data->{existing};
|
|
270
285
|
|
|
@@ -371,7 +386,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
371
386
|
ok(defined $V{${datavar}}, '${entity.name} create: data');
|
|
372
387
|
`)
|
|
373
388
|
if (null != ctx.entity.id) {
|
|
374
|
-
Content(` ok(defined $V{${datavar}}{
|
|
389
|
+
Content(` ok(defined $V{${datavar}}{${rid(ctx.entity)}}, '${entity.name} create: id');
|
|
375
390
|
`)
|
|
376
391
|
}
|
|
377
392
|
}
|
|
@@ -408,7 +423,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
408
423
|
Content(` };
|
|
409
424
|
`)
|
|
410
425
|
}
|
|
411
|
-
Content(liveFill(entity, step, matchvar))
|
|
426
|
+
Content(liveFill(entity, step, matchvar, flow))
|
|
412
427
|
|
|
413
428
|
Content(`
|
|
414
429
|
$V{${listvar}_result} = $V{${entvar}}->list($V{${matchvar}}, undef);
|
|
@@ -428,7 +443,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
428
443
|
Content(`
|
|
429
444
|
$V{found_item} = Voxgig::Struct::select(
|
|
430
445
|
${N}TestRunner::entity_list_to_data($V{${listvar}_result}),
|
|
431
|
-
{ '
|
|
446
|
+
{ '${entityRecordIdField(entity)}' => $V{${refDataVar}}{${rid(entity)}} });
|
|
432
447
|
ok(!Voxgig::Struct::isempty($V{found_item}), '${entity.name} list: item exists');
|
|
433
448
|
`)
|
|
434
449
|
} else if ('ItemNotExists' === validator.apply && hasRefData) {
|
|
@@ -436,7 +451,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
436
451
|
Content(`
|
|
437
452
|
$V{not_found_item} = Voxgig::Struct::select(
|
|
438
453
|
${N}TestRunner::entity_list_to_data($V{${listvar}_result}),
|
|
439
|
-
{ '
|
|
454
|
+
{ '${entityRecordIdField(entity)}' => $V{${refDataVar}}{${rid(entity)}} });
|
|
440
455
|
ok(Voxgig::Struct::isempty($V{not_found_item}), '${entity.name} list: item not exists');
|
|
441
456
|
`)
|
|
442
457
|
}
|
|
@@ -469,7 +484,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
469
484
|
Content(` $V{${datavar}_up} = {
|
|
470
485
|
`)
|
|
471
486
|
if (hasEntIdU) {
|
|
472
|
-
Content(` 'id' => $V{${srcdatavar}}{
|
|
487
|
+
Content(` 'id' => $V{${srcdatavar}}{${rid(entity)}},
|
|
473
488
|
`)
|
|
474
489
|
}
|
|
475
490
|
|
|
@@ -504,7 +519,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
504
519
|
ok(defined $V{${resdatavar}}, '${entity.name} update: data');
|
|
505
520
|
`)
|
|
506
521
|
if (hasEntIdU) {
|
|
507
|
-
Content(` is($V{${resdatavar}}{
|
|
522
|
+
Content(` is($V{${resdatavar}}{${rid(entity)}}, $V{${datavar}_up}{id}, '${entity.name} update: id');
|
|
508
523
|
`)
|
|
509
524
|
}
|
|
510
525
|
|
|
@@ -562,17 +577,17 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
562
577
|
}
|
|
563
578
|
if (hasEntId) {
|
|
564
579
|
Content(` $V{${matchvar}} = {
|
|
565
|
-
'id' => $V{${srcdatavar}}{
|
|
580
|
+
'id' => $V{${srcdatavar}}{${rid(entity)}},
|
|
566
581
|
};
|
|
567
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
|
|
582
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
|
|
568
583
|
$V{${datavar}_load_result} = ${N}Helpers::to_map(ref($V{${datavar}_loaded}) && $V{${datavar}_loaded}->can('data_get') ? $V{${datavar}_loaded}->data_get : $V{${datavar}_loaded});
|
|
569
584
|
ok(defined $V{${datavar}_load_result}, '${entity.name} load: data');
|
|
570
|
-
is($V{${datavar}_load_result}{
|
|
585
|
+
is($V{${datavar}_load_result}{${rid(entity)}}, $V{${srcdatavar}}{${rid(entity)}}, '${entity.name} load: id');
|
|
571
586
|
`)
|
|
572
587
|
}
|
|
573
588
|
else {
|
|
574
589
|
Content(` $V{${matchvar}} = {};
|
|
575
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
|
|
590
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
|
|
576
591
|
ok(defined $V{${datavar}_loaded}, '${entity.name} load: data');
|
|
577
592
|
`)
|
|
578
593
|
}
|
|
@@ -598,7 +613,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
598
613
|
}
|
|
599
614
|
// Always match the prior-created entity by id to avoid mock-order flakes.
|
|
600
615
|
Content(` $V{${matchvar}} = {
|
|
601
|
-
'id' => $V{${srcdatavar}}{
|
|
616
|
+
'id' => $V{${srcdatavar}}{${rid(entity)}},
|
|
602
617
|
};
|
|
603
618
|
${parentMatch(step, matchvar)} $V{${entvar}}->remove($V{${matchvar}}, undef);
|
|
604
619
|
pass('${entity.name} remove: completed');
|
|
@@ -606,6 +621,25 @@ ${parentMatch(step, matchvar)} $V{${entvar}}->remove($V{${matchvar}}, undef);
|
|
|
606
621
|
}
|
|
607
622
|
|
|
608
623
|
|
|
624
|
+
// The record field the entity's identity is read from, as a Perl hash key.
|
|
625
|
+
function rid(entity: any): string {
|
|
626
|
+
const field = entityRecordIdField(entity)
|
|
627
|
+
return /^[A-Za-z_]\w*$/.test(field) ? field : `'${field}'`
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
632
|
+
// in another field reads the key from there too.
|
|
633
|
+
function fixtureIdentity(entity: any): string {
|
|
634
|
+
return 'id' === entityRecordIdField(entity) ? '' : `
|
|
635
|
+
for my $fixture_rec (values %{ $entity_data->{existing}{'${entity.name}'} // {} }) {
|
|
636
|
+
$fixture_rec->{${rid(entity)}} = $fixture_rec->{id}
|
|
637
|
+
if ref $fixture_rec eq 'HASH' && defined $fixture_rec->{id};
|
|
638
|
+
}
|
|
639
|
+
`
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
|
|
609
643
|
// A child's route names its parents, and an entity no earlier step has
|
|
610
644
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
611
645
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
@@ -616,8 +650,8 @@ function perlLit(value: any): string {
|
|
|
616
650
|
|
|
617
651
|
|
|
618
652
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
619
|
-
function liveFill(entity: any, step: any, matchvar: string): string {
|
|
620
|
-
const fills = liveStepExamples(entity, step)
|
|
653
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
|
|
654
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
621
655
|
return 0 === fills.length ? '' : ` if ($setup->{live}) {
|
|
622
656
|
${fills.map(([k, ex]) => ` $V{${matchvar}}{'${k}'} = ${perlLit(ex)};\n`).join('')} }
|
|
623
657
|
`
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables,
|
|
17
17
|
pointParts,
|
|
18
|
+
pointSlash,
|
|
18
19
|
pointPlaceholders,
|
|
19
20
|
liveStrict,
|
|
20
21
|
liveStrictNote,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
liveQueryExamples,
|
|
25
26
|
liveEntity,
|
|
26
27
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
28
|
+
liveDirectDiscovery,
|
|
27
29
|
} from '@voxgig/sdkgen'
|
|
28
30
|
|
|
29
31
|
import { formatPhpValue } from './utility_php'
|
|
@@ -133,7 +135,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
133
135
|
const listOp = entity.op?.list
|
|
134
136
|
|
|
135
137
|
const loadPoint = loadOp?.points?.[0]
|
|
136
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
138
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
137
139
|
const allLoadParams = loadPoint?.g?.params || []
|
|
138
140
|
// Some upstream OpenAPI specs declare a parameter as `in: path` even when
|
|
139
141
|
// that path has no `{name}` placeholder for it. Only path params that
|
|
@@ -153,7 +155,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
153
155
|
_renamedPlaceholders.has(p.n) || _renamedPlaceholders.has(p.or))
|
|
154
156
|
|
|
155
157
|
const listPoint = listOp?.points?.[0]
|
|
156
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
158
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
157
159
|
const listParams = listPoint?.g?.params || []
|
|
158
160
|
|
|
159
161
|
// Required query params with spec-provided examples — needed in live mode.
|
|
@@ -269,8 +271,10 @@ ${listLiveQueryLines ? ' if ($setup["live"]) {\n' + listLiveQueryLines +
|
|
|
269
271
|
`)
|
|
270
272
|
}
|
|
271
273
|
else if (hasLoad && loadPoint) {
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
275
|
+
const discover = null != discovery
|
|
276
|
+
const idParam = discovery?.param
|
|
277
|
+
const idField = discovery?.field
|
|
274
278
|
const loadLiveIdKeys: string[] = loadAllHaveExamples ? [] :
|
|
275
279
|
discover ? listParams.map(liveKey).concat(loadParams.filter((p: any) => idParam !== p.n).map(liveKey)) :
|
|
276
280
|
loadParams.map(liveKey)
|
|
@@ -308,7 +312,7 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
|
|
|
308
312
|
Runner::live_empty("The account has no ${entity.name} record to load");
|
|
309
313
|
}
|
|
310
314
|
$first = is_array($records[0]) ? $records[0] : [];
|
|
311
|
-
$found = $first["${
|
|
315
|
+
$found = $first["${idField}"] ?? null;
|
|
312
316
|
if (null === $found) {
|
|
313
317
|
Runner::live_miss(self::LIVE_STRICT, "Live load blocked: discovery returned no usable identity");
|
|
314
318
|
}
|