@voxgig/sdkgen 4.36.0 → 4.38.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/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/utility.js +7 -3
- package/dist/utility.js.map +1 -1
- 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/Entity_go.ts +1 -1
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +1 -1
- package/project/.sdk/src/cmp/go/Main_go.ts +7 -3
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +3 -3
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +1 -1
- 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/go-cli/fragment/words.fragment.go +1 -1
- package/project/.sdk/src/cmp/go-mcp/fragment/tools.fragment.go +1 -1
- 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/EntityOperation_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/Main_rust.ts +3 -1
- package/project/.sdk/src/cmp/rust/ReadmeHowto_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeModel_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeRef_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeTopQuick_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeTopTest_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +9 -8
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +57 -25
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +2 -2
- 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/core/sdk.h +2 -2
- 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/core/helpers.go +1 -1
- package/project/.sdk/tm/go/core/types.go +9 -1
- 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/core/helpers.rs +1 -1
- package/project/.sdk/tm/rust/core/types.rs +2 -2
- 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/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/utility.ts +10 -4
|
@@ -119,7 +119,7 @@ client := sdk.TestSDK(testopts, sdkopts)
|
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
publishedEntities.map((ent: any) => {
|
|
122
|
-
Content(`#### \`${ent.Name}(data map[string]any) ${model.const.Name}
|
|
122
|
+
Content(`#### \`${ent.Name}(data map[string]any) ${model.const.Name}EntityBase\`
|
|
123
123
|
|
|
124
124
|
Create a new \`${ent.Name}\` entity instance. Pass \`nil\` for no initial data.
|
|
125
125
|
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables, envName, envToken, liveStrict, liveStrictNote,
|
|
17
17
|
pointParts,
|
|
18
|
+
pointSlash,
|
|
18
19
|
pointPlaceholders,
|
|
19
20
|
pointIsGraphql,
|
|
20
21
|
primaryPoint,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
liveEntity,
|
|
24
25
|
liveGetOnlyReason, LIVE_GETONLY_ENV,
|
|
25
26
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary,
|
|
27
|
+
liveDirectDiscovery,
|
|
26
28
|
} from '@voxgig/sdkgen'
|
|
27
29
|
|
|
28
30
|
|
|
@@ -117,7 +119,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
117
119
|
const loadPoint = null == loadOp?.points ? undefined :
|
|
118
120
|
primaryPoint(loadOp.points, entity.name, 'load')
|
|
119
121
|
const loadIsGraphql = pointIsGraphql(loadPoint)
|
|
120
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
122
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
121
123
|
const allLoadParams = loadPoint?.g?.params || []
|
|
122
124
|
// Some upstream OpenAPI specs declare a parameter as `in: path` even when
|
|
123
125
|
// that path has no `{name}` placeholder for it. Only path params that
|
|
@@ -139,7 +141,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
139
141
|
const listPoint = null == listOp?.points ? undefined :
|
|
140
142
|
primaryPoint(listOp.points, entity.name, 'list')
|
|
141
143
|
const listIsGraphql = pointIsGraphql(listPoint)
|
|
142
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
144
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
143
145
|
const listParams = listPoint?.g?.params || []
|
|
144
146
|
|
|
145
147
|
const liveQueryLines = (point: any) => liveQueryExamples(point)
|
|
@@ -359,13 +361,14 @@ ${listLiveQueryLines}
|
|
|
359
361
|
`"${p.n}": "direct0${i + 1}"`).join(', ')
|
|
360
362
|
: ''
|
|
361
363
|
|
|
362
|
-
const
|
|
364
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
365
|
+
const ancestorParams = loadParams.filter((p: any) => p.n !== discovery?.param)
|
|
363
366
|
|
|
364
367
|
const liveKey = (p: any) => p.n === 'id' ? entity.name + '01' : p.n.replace(/_id$/, '') + '01'
|
|
365
368
|
let loadLiveIdKeys: string[] = []
|
|
366
369
|
if (loadParams.length > 0 && !loadAllHaveExamples) {
|
|
367
|
-
loadLiveIdKeys = [...new Set((
|
|
368
|
-
[...listParams, ...
|
|
370
|
+
loadLiveIdKeys = [...new Set((discovery ?
|
|
371
|
+
[...listParams, ...ancestorParams] : loadParams).map(liveKey))]
|
|
369
372
|
}
|
|
370
373
|
const loadSkipBlock = getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, loadLiveIdKeys) +
|
|
371
374
|
(loadLiveIdKeys.length > 0
|
|
@@ -414,7 +417,7 @@ ${loadSkipBlock} client := setup.client
|
|
|
414
417
|
|
|
415
418
|
if (loadAllHaveExamples) {
|
|
416
419
|
Content(loadExampleLines + '\n')
|
|
417
|
-
} else if (
|
|
420
|
+
} else if (discovery) {
|
|
418
421
|
Content(` listParams := map[string]any{}
|
|
419
422
|
`)
|
|
420
423
|
for (const p of listParams) {
|
|
@@ -444,14 +447,13 @@ ${loadSkipBlock} client := setup.client
|
|
|
444
447
|
liveEmpty(t, "The account has no ${entity.name} record to load")
|
|
445
448
|
}
|
|
446
449
|
firstEnt := core.ToMapAny(listData[0])
|
|
447
|
-
if firstEnt[
|
|
450
|
+
if firstEnt[${JSON.stringify(discovery.field)}] == nil {
|
|
448
451
|
liveMiss(t, ${strictConst}, "Live load blocked: discovery returned no usable identity")
|
|
449
452
|
}
|
|
450
|
-
params[
|
|
453
|
+
params[${JSON.stringify(discovery.param)}] = firstEnt[${JSON.stringify(discovery.field)}]
|
|
451
454
|
`)
|
|
452
455
|
for (const p of ancestorParams) {
|
|
453
|
-
|
|
454
|
-
Content(` params["${p.n}"] = setup.idmap["${key}"]
|
|
456
|
+
Content(` params["${p.n}"] = setup.idmap["${liveKey(p)}"]
|
|
455
457
|
`)
|
|
456
458
|
}
|
|
457
459
|
} else if (loadParams.length > 0) {
|
|
@@ -27,11 +27,11 @@ import {
|
|
|
27
27
|
isAuthActive,
|
|
28
28
|
serverVarEnv,
|
|
29
29
|
serverVariables,
|
|
30
|
-
entityDataIdField, envName, envToken,
|
|
30
|
+
entityDataIdField, entityRecordIdField, envName, envToken,
|
|
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
|
|
|
@@ -268,19 +268,18 @@ ${failureTests(model, entity)}` : ''}${validateTest(model, entity)}
|
|
|
268
268
|
})
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
const getOnly
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
Content(` t.Skip(${JSON.stringify(liveExcludedSummary(getOnly))})
|
|
271
|
+
for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
|
|
272
|
+
Content(` if setup.live${getOnly ? ` && os.Getenv(${JSON.stringify(LIVE_GETONLY_ENV)}) == "TRUE"` : ''} {
|
|
273
|
+
${liveExcludedLines(plan).map((line) => '\t\t\tt.Log(' + JSON.stringify(line) + ')\n').join('')}`)
|
|
274
|
+
if (!runs) {
|
|
275
|
+
Content(` t.Skip(${JSON.stringify(liveExcludedSummary(plan))})
|
|
277
276
|
return
|
|
278
277
|
}
|
|
279
278
|
|
|
280
279
|
`)
|
|
281
280
|
}
|
|
282
281
|
else {
|
|
283
|
-
flowBody(
|
|
282
|
+
flowBody(plan.flow)
|
|
284
283
|
Content(` return
|
|
285
284
|
}
|
|
286
285
|
|
|
@@ -313,7 +312,7 @@ ${liveExcludedLines(getOnly).map((line) => '\t\t\tt.Log(' + JSON.stringify(line)
|
|
|
313
312
|
if err := json.Unmarshal(entityDataSource, &entityData); err != nil {
|
|
314
313
|
panic("failed to parse ${entity.name} test data: " + err.Error())
|
|
315
314
|
}
|
|
316
|
-
|
|
315
|
+
${fixtureIdentity(entity)}
|
|
317
316
|
options := map[string]any{}
|
|
318
317
|
options["entity"] = entityData["existing"]
|
|
319
318
|
|
|
@@ -404,6 +403,17 @@ ${liveExcludedLines(getOnly).map((line) => '\t\t\tt.Log(' + JSON.stringify(line)
|
|
|
404
403
|
function liveFlowGate(entity: any, needs: any, strict: boolean, strictConst: string,
|
|
405
404
|
entidEnv: string, hasSteps: boolean): string {
|
|
406
405
|
let out = ''
|
|
406
|
+
if (null != needs.examples) {
|
|
407
|
+
out += ` if setup.live {
|
|
408
|
+
for _liveKey, _liveEx := range map[string]any{${needs.examples
|
|
409
|
+
.map(([k, ex]: any) => JSON.stringify(k) + ': ' + goIdLit(ex)).join(', ')}} {
|
|
410
|
+
if setup.syntheticOnly || setup.idmap[_liveKey] == nil {
|
|
411
|
+
setup.idmap[_liveKey] = _liveEx
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
`
|
|
416
|
+
}
|
|
407
417
|
if (0 < needs.keys.length) {
|
|
408
418
|
out += ` if setup.live {
|
|
409
419
|
for _, _liveKey := range []string{${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')}} {
|
|
@@ -424,6 +434,14 @@ function liveFlowGate(entity: any, needs: any, strict: boolean, strictConst: str
|
|
|
424
434
|
// A flow whose every step is skipped (a remove with no data id) uses none.
|
|
425
435
|
out += '\t\tclient := setup.client\n\t\t_ = client\n'
|
|
426
436
|
}
|
|
437
|
+
if (null != needs.record) {
|
|
438
|
+
out += ` if setup.live {
|
|
439
|
+
liveExisting(t, ${strictConst}, setup.data, ${JSON.stringify(entity.name)}, func() (any, error) {
|
|
440
|
+
return []any{map[string]any{"id": setup.idmap[${JSON.stringify(needs.record)}]}}, nil
|
|
441
|
+
})
|
|
442
|
+
}
|
|
443
|
+
`
|
|
444
|
+
}
|
|
427
445
|
if (null != needs.discover) {
|
|
428
446
|
const match = Object.entries(needs.discover)
|
|
429
447
|
.map(([k, v]: any) => `${JSON.stringify(k)}: setup.idmap[${JSON.stringify(v)}]`)
|
|
@@ -501,7 +519,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
501
519
|
}
|
|
502
520
|
`)
|
|
503
521
|
if (null != ctx.entity.id) {
|
|
504
|
-
Content(` if ${datavar}[
|
|
522
|
+
Content(` if ${datavar}[${rid(ctx.entity)}] == nil {
|
|
505
523
|
t.Fatal("expected created entity to have an id")
|
|
506
524
|
}
|
|
507
525
|
`)
|
|
@@ -543,7 +561,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
543
561
|
Content(` }
|
|
544
562
|
`)
|
|
545
563
|
}
|
|
546
|
-
liveFill(entity, step, matchvar)
|
|
564
|
+
liveFill(entity, step, matchvar, flow)
|
|
547
565
|
|
|
548
566
|
// Only declare ${listvar} as a real var when a downstream validator
|
|
549
567
|
// actually uses it; otherwise `_` to satisfy Go's unused-var check.
|
|
@@ -582,7 +600,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
582
600
|
if ('ItemExists' === validator.apply && hasRefData && hasDataId) {
|
|
583
601
|
const refDataVar = goVar(validRef + '_data')
|
|
584
602
|
Content(`
|
|
585
|
-
foundItem := vs.Select(entityListToData(${listvar}), map[string]any{
|
|
603
|
+
foundItem := vs.Select(entityListToData(${listvar}), map[string]any{${rid(entity)}: ${refDataVar}[${rid(entity)}]})
|
|
586
604
|
if vs.IsEmpty(foundItem) {
|
|
587
605
|
t.Fatal("expected to find created entity in list")
|
|
588
606
|
}
|
|
@@ -590,7 +608,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
590
608
|
} else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
|
|
591
609
|
const refDataVar = goVar(validRef + '_data')
|
|
592
610
|
Content(`
|
|
593
|
-
notFoundItem := vs.Select(entityListToData(${listvar}), map[string]any{
|
|
611
|
+
notFoundItem := vs.Select(entityListToData(${listvar}), map[string]any{${rid(entity)}: ${refDataVar}[${rid(entity)}]})
|
|
594
612
|
if !vs.IsEmpty(notFoundItem) {
|
|
595
613
|
t.Fatal("expected removed entity to not be in list")
|
|
596
614
|
}
|
|
@@ -625,7 +643,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
625
643
|
Content(` ${datavar}Up := map[string]any{
|
|
626
644
|
`)
|
|
627
645
|
if (hasEntIdU) {
|
|
628
|
-
Content(` "id": ${srcdatavar}[
|
|
646
|
+
Content(` "id": ${srcdatavar}[${rid(entity)}],
|
|
629
647
|
`)
|
|
630
648
|
}
|
|
631
649
|
|
|
@@ -667,7 +685,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
667
685
|
}
|
|
668
686
|
`)
|
|
669
687
|
if (hasEntIdU) {
|
|
670
|
-
Content(` if ${resdatavar}[
|
|
688
|
+
Content(` if ${resdatavar}[${rid(entity)}] != ${datavar}Up["id"] {
|
|
671
689
|
t.Fatal("expected update result id to match")
|
|
672
690
|
}
|
|
673
691
|
`)
|
|
@@ -730,11 +748,11 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
730
748
|
}
|
|
731
749
|
if (hasEntId) {
|
|
732
750
|
Content(` ${matchvar} := map[string]any{
|
|
733
|
-
"id": ${srcdatavar}[
|
|
751
|
+
"id": ${srcdatavar}[${rid(entity)}],
|
|
734
752
|
}
|
|
735
753
|
`)
|
|
736
754
|
loadMatch(entity, step, matchvar, srcdatavar)
|
|
737
|
-
liveFill(entity, step, matchvar)
|
|
755
|
+
liveFill(entity, step, matchvar, flow)
|
|
738
756
|
Content(` ${datavar}Loaded, err := ${entvar}.Load(${matchvar}, nil)
|
|
739
757
|
if err != nil {
|
|
740
758
|
t.Fatalf("load failed: %v", err)
|
|
@@ -743,7 +761,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
743
761
|
if ${datavar}LoadResult == nil {
|
|
744
762
|
t.Fatal("expected load result to be a map")
|
|
745
763
|
}
|
|
746
|
-
if ${datavar}LoadResult[
|
|
764
|
+
if ${datavar}LoadResult[${rid(entity)}] != ${srcdatavar}[${rid(entity)}] {
|
|
747
765
|
t.Fatal("expected load result id to match")
|
|
748
766
|
}
|
|
749
767
|
`)
|
|
@@ -752,7 +770,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
752
770
|
Content(` ${matchvar} := map[string]any{}
|
|
753
771
|
`)
|
|
754
772
|
loadMatch(entity, step, matchvar, srcdatavar)
|
|
755
|
-
liveFill(entity, step, matchvar)
|
|
773
|
+
liveFill(entity, step, matchvar, flow)
|
|
756
774
|
Content(` ${datavar}Loaded, err := ${entvar}.Load(${matchvar}, nil)
|
|
757
775
|
if err != nil {
|
|
758
776
|
t.Fatalf("load failed: %v", err)
|
|
@@ -791,7 +809,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
791
809
|
}
|
|
792
810
|
// Always match the prior-created entity by id to avoid mock-order flakes.
|
|
793
811
|
Content(` ${matchvar} := map[string]any{
|
|
794
|
-
"id": ${srcdatavar}[
|
|
812
|
+
"id": ${srcdatavar}[${rid(entity)}],
|
|
795
813
|
}
|
|
796
814
|
`)
|
|
797
815
|
parentMatch(step, matchvar)
|
|
@@ -803,12 +821,32 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
803
821
|
}
|
|
804
822
|
|
|
805
823
|
|
|
824
|
+
// The record field the entity's identity is read from, as a Go string literal.
|
|
825
|
+
function rid(entity: any): string {
|
|
826
|
+
return JSON.stringify(entityRecordIdField(entity))
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
831
|
+
// in another field reads the key from there too.
|
|
832
|
+
function fixtureIdentity(entity: any): string {
|
|
833
|
+
const field = entityRecordIdField(entity)
|
|
834
|
+
return 'id' === field ? '' : `
|
|
835
|
+
for _, rec := range core.ToMapAny(vs.GetPath(entityData, "existing.${entity.name}")) {
|
|
836
|
+
if recMap := core.ToMapAny(rec); recMap != nil && recMap["id"] != nil {
|
|
837
|
+
recMap[${JSON.stringify(field)}] = recMap["id"]
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
`
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
|
|
806
844
|
// A child's route names its parents, and an entity no earlier step has
|
|
807
845
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
808
846
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
809
847
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
810
|
-
function liveFill(entity: any, step: any, matchvar: string) {
|
|
811
|
-
const fills = liveStepExamples(entity, step)
|
|
848
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any) {
|
|
849
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
812
850
|
if (0 < fills.length) {
|
|
813
851
|
Content(` if setup.live {
|
|
814
852
|
${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${JSON.stringify(ex)}\n`).join('')} }
|
|
@@ -817,6 +855,12 @@ ${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${JSON.stringif
|
|
|
817
855
|
}
|
|
818
856
|
|
|
819
857
|
|
|
858
|
+
// A number as JSON decodes one, so an example compares equal to a record's id.
|
|
859
|
+
function goIdLit(value: any): string {
|
|
860
|
+
return 'number' === typeof value ? 'float64(' + value + ')' : JSON.stringify(value)
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
|
|
820
864
|
function parentMatch(step: any, matchvar: string) {
|
|
821
865
|
const parents = Object.entries(step.m || {})
|
|
822
866
|
.filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
|
|
@@ -75,7 +75,7 @@ func runOp(client *sdk.ProjectNameSDK, op string, query *eng.Value, entityAtom e
|
|
|
75
75
|
|
|
76
76
|
// entityFor dispatches on the lowercase entity name. The generator
|
|
77
77
|
// emits one `case "<name>":` per entity defined in the SDK model.
|
|
78
|
-
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.
|
|
78
|
+
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.ProjectNameEntityBase, error) {
|
|
79
79
|
switch strings.ToLower(name) {
|
|
80
80
|
// <[SLOT:entityCases]>
|
|
81
81
|
}
|
|
@@ -76,7 +76,7 @@ func runOp(_ context.Context, client *sdk.ProjectNameSDK, op string, entity stri
|
|
|
76
76
|
|
|
77
77
|
// entityFor dispatches on the lowercase entity name. The generator
|
|
78
78
|
// emits one `case "<name>":` per entity defined in the SDK model.
|
|
79
|
-
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.
|
|
79
|
+
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.ProjectNameEntityBase, error) {
|
|
80
80
|
switch strings.ToLower(name) {
|
|
81
81
|
// <[SLOT:entityCases]>
|
|
82
82
|
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables, envName, envToken,
|
|
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
|
|
|
@@ -131,7 +133,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
131
133
|
|
|
132
134
|
// Get load point info
|
|
133
135
|
const loadPoint = loadOp?.points?.[0]
|
|
134
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
136
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
135
137
|
const allLoadParams = loadPoint?.g?.params || []
|
|
136
138
|
// Only path params that actually appear in the URL template drive
|
|
137
139
|
// direct-test path-param setup and URL-substitution asserts.
|
|
@@ -149,7 +151,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
149
151
|
|
|
150
152
|
// Get list point info
|
|
151
153
|
const listPoint = listOp?.points?.[0]
|
|
152
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
154
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
153
155
|
const listParams = listPoint?.g?.params || []
|
|
154
156
|
|
|
155
157
|
// Required query params with spec-provided examples — needed in live mode.
|
|
@@ -347,14 +349,14 @@ ${listLiveQueryLines ? ' if (setup.live) {\n' + listLiveQueryLines + ' }\n
|
|
|
347
349
|
`)
|
|
348
350
|
}
|
|
349
351
|
else if (hasLoad && loadPoint) {
|
|
350
|
-
|
|
351
|
-
const ancestorParams = loadParams.filter((p: any) => p.n !==
|
|
352
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
353
|
+
const ancestorParams = loadParams.filter((p: any) => p.n !== discovery?.param)
|
|
352
354
|
|
|
353
355
|
const liveKey = (p: any) => p.n === 'id' ? entity.name + '01' : p.n.replace(/_id$/, '') + '01'
|
|
354
356
|
let loadLiveIdKeys: string[] = []
|
|
355
357
|
if (loadParams.length > 0 && !loadAllHaveExamples) {
|
|
356
|
-
loadLiveIdKeys = [...new Set((
|
|
357
|
-
[...listParams, ...
|
|
358
|
+
loadLiveIdKeys = [...new Set((discovery ?
|
|
359
|
+
[...listParams, ...ancestorParams] : loadParams).map(liveKey))]
|
|
358
360
|
}
|
|
359
361
|
const loadSkipBlock = getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, loadLiveIdKeys) +
|
|
360
362
|
(loadLiveIdKeys.length > 0
|
|
@@ -395,7 +397,7 @@ ${loadSkipBlock} ${SDK} client = setup.client;
|
|
|
395
397
|
|
|
396
398
|
if (loadAllHaveExamples) {
|
|
397
399
|
Content(loadExampleLines + '\n')
|
|
398
|
-
} else if (
|
|
400
|
+
} else if (discovery) {
|
|
399
401
|
Content(` Map<String, Object> listParams = new LinkedHashMap<>();
|
|
400
402
|
`)
|
|
401
403
|
for (const p of listParams) {
|
|
@@ -421,14 +423,13 @@ ${loadSkipBlock} ${SDK} client = setup.client;
|
|
|
421
423
|
RunnerSupport.liveEmpty("The account has no ${entity.name} record to load");
|
|
422
424
|
}
|
|
423
425
|
Map<String, Object> firstEnt = Helpers.toMapAny(listData.get(0));
|
|
424
|
-
if (firstEnt == null || firstEnt.get("
|
|
426
|
+
if (firstEnt == null || firstEnt.get("${discovery.field}") == null) {
|
|
425
427
|
RunnerSupport.liveMiss(LIVE_STRICT, "Live load blocked: discovery returned no usable identity");
|
|
426
428
|
}
|
|
427
|
-
params.put("
|
|
429
|
+
params.put("${discovery.param}", firstEnt.get("${discovery.field}"));
|
|
428
430
|
`)
|
|
429
431
|
for (const p of ancestorParams) {
|
|
430
|
-
|
|
431
|
-
Content(` params.put("${p.n}", setup.idmap.get("${key}"));
|
|
432
|
+
Content(` params.put("${p.n}", setup.idmap.get("${liveKey(p)}"));
|
|
432
433
|
`)
|
|
433
434
|
}
|
|
434
435
|
} else if (loadParams.length > 0) {
|
|
@@ -20,9 +20,9 @@ import {
|
|
|
20
20
|
getMatchEntries,
|
|
21
21
|
isAuthActive,
|
|
22
22
|
serverVarEnv,
|
|
23
|
-
serverVariables, envName, envToken,
|
|
23
|
+
serverVariables, envName, envToken, entityRecordIdField,
|
|
24
24
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
25
|
-
|
|
25
|
+
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
26
26
|
liveRouteExamples, liveStepExamples,
|
|
27
27
|
liveEntity,
|
|
28
28
|
} from '@voxgig/sdkgen'
|
|
@@ -57,6 +57,12 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
|
|
|
57
57
|
function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: string,
|
|
58
58
|
SDK: string, strict: boolean, hasSteps: boolean): string {
|
|
59
59
|
let out = ''
|
|
60
|
+
for (const [k, ex] of needs.examples || []) {
|
|
61
|
+
out += ` if (setup.live && (setup.syntheticOnly || setup.idmap.get(${JSON.stringify(k)}) == null)) {
|
|
62
|
+
setup.idmap.put(${JSON.stringify(k)}, ${javaIdLit(ex)});
|
|
63
|
+
}
|
|
64
|
+
`
|
|
65
|
+
}
|
|
60
66
|
if (0 < needs.keys.length) {
|
|
61
67
|
out += ` if (setup.live) {
|
|
62
68
|
for (String liveKey : new String[] { ${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')} }) {
|
|
@@ -77,6 +83,16 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: strin
|
|
|
77
83
|
return out
|
|
78
84
|
}
|
|
79
85
|
out += ` ${SDK} client = setup.client;\n`
|
|
86
|
+
if (null != needs.record) {
|
|
87
|
+
out += ` if (setup.live) {
|
|
88
|
+
RunnerSupport.liveExisting(setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)}, () -> {
|
|
89
|
+
Map<String, Object> record = new LinkedHashMap<>();
|
|
90
|
+
record.put("id", setup.idmap.get(${JSON.stringify(needs.record)}));
|
|
91
|
+
return List.of(record);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
`
|
|
95
|
+
}
|
|
80
96
|
if (null != needs.discover) {
|
|
81
97
|
const match = Object.entries(needs.discover)
|
|
82
98
|
.map(([k, v]: any) => `match.put(${JSON.stringify(k)}, setup.idmap.get(${JSON.stringify(v)}));`)
|
|
@@ -244,19 +260,18 @@ ${liveStrictNote(strict, '//', ' ')}
|
|
|
244
260
|
`)
|
|
245
261
|
}
|
|
246
262
|
|
|
247
|
-
const getOnly
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
Content(` Assumptions.abort(${javaLit(liveExcludedSummary(getOnly))});
|
|
263
|
+
for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
|
|
264
|
+
Content(` if (setup.live${getOnly ? ` && "TRUE".equals(System.getenv(${javaLit(LIVE_GETONLY_ENV)}))` : ''}) {
|
|
265
|
+
${liveExcludedLines(plan).map((line) => ' System.out.println(' + javaLit(line) + ');\n').join('')}`)
|
|
266
|
+
if (!runs) {
|
|
267
|
+
Content(` Assumptions.abort(${javaLit(liveExcludedSummary(plan))});
|
|
253
268
|
return;
|
|
254
269
|
}
|
|
255
270
|
|
|
256
271
|
`)
|
|
257
272
|
}
|
|
258
273
|
else {
|
|
259
|
-
flowBody(
|
|
274
|
+
flowBody(plan.flow)
|
|
260
275
|
Content(` return;
|
|
261
276
|
}
|
|
262
277
|
|
|
@@ -331,7 +346,7 @@ ${liveExcludedLines(getOnly).map((line) => ' System.out.println(' + javaLit
|
|
|
331
346
|
catch (Exception e) {
|
|
332
347
|
throw new AssertionError("failed to read ${entity.name} test data: " + e.getMessage(), e);
|
|
333
348
|
}
|
|
334
|
-
|
|
349
|
+
${fixtureIdentity(entity)}
|
|
335
350
|
Map<String, Object> options = new LinkedHashMap<>();
|
|
336
351
|
options.put("entity", entityData.get("existing"));
|
|
337
352
|
|
|
@@ -458,7 +473,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
458
473
|
assertNotNull(${datavar}, "expected create result to be a map");
|
|
459
474
|
`)
|
|
460
475
|
if (null != ctx.entity.id) {
|
|
461
|
-
Content(` assertNotNull(${datavar}.get(
|
|
476
|
+
Content(` assertNotNull(${datavar}.get(${rid(ctx.entity)}), "expected created entity to have an id");
|
|
462
477
|
`)
|
|
463
478
|
}
|
|
464
479
|
}
|
|
@@ -490,7 +505,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
490
505
|
Content(` ${matchvar}.put("${key}", setup.idmap.get("${val}"));
|
|
491
506
|
`)
|
|
492
507
|
}
|
|
493
|
-
Content(liveFill(entity, step, matchvar))
|
|
508
|
+
Content(liveFill(entity, step, matchvar, flow))
|
|
494
509
|
|
|
495
510
|
// Only declare ${listvar} as a real var when a downstream validator
|
|
496
511
|
// actually uses it.
|
|
@@ -524,7 +539,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
524
539
|
Content(`
|
|
525
540
|
List<Object> foundItem = Struct.select(
|
|
526
541
|
RunnerSupport.entityListToData(${listvar}),
|
|
527
|
-
Struct.jm(
|
|
542
|
+
Struct.jm(${rid(entity)}, ${refDataVar}.get(${rid(entity)})));
|
|
528
543
|
assertFalse(Struct.isempty(foundItem), "expected to find created entity in list");
|
|
529
544
|
`)
|
|
530
545
|
} else if ('ItemNotExists' === validator.apply && hasRefData) {
|
|
@@ -532,7 +547,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
532
547
|
Content(`
|
|
533
548
|
List<Object> notFoundItem = Struct.select(
|
|
534
549
|
RunnerSupport.entityListToData(${listvar}),
|
|
535
|
-
Struct.jm(
|
|
550
|
+
Struct.jm(${rid(entity)}, ${refDataVar}.get(${rid(entity)})));
|
|
536
551
|
assertTrue(Struct.isempty(notFoundItem), "expected removed entity to not be in list");
|
|
537
552
|
`)
|
|
538
553
|
}
|
|
@@ -565,7 +580,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
565
580
|
Content(` Map<String, Object> ${datavar}Up = new LinkedHashMap<>();
|
|
566
581
|
`)
|
|
567
582
|
if (hasEntIdU) {
|
|
568
|
-
Content(` ${datavar}Up.put("id", ${srcdatavar}.get(
|
|
583
|
+
Content(` ${datavar}Up.put("id", ${srcdatavar}.get(${rid(entity)}));
|
|
569
584
|
`)
|
|
570
585
|
}
|
|
571
586
|
|
|
@@ -599,7 +614,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
599
614
|
assertNotNull(${resdatavar}, "expected update result to be a map");
|
|
600
615
|
`)
|
|
601
616
|
if (hasEntIdU) {
|
|
602
|
-
Content(` assertEquals(${datavar}Up.get("id"), ${resdatavar}.get(
|
|
617
|
+
Content(` assertEquals(${datavar}Up.get("id"), ${resdatavar}.get(${rid(entity)}),
|
|
603
618
|
"expected update result id to match");
|
|
604
619
|
`)
|
|
605
620
|
}
|
|
@@ -660,16 +675,16 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
660
675
|
Content(` Map<String, Object> ${matchvar} = new LinkedHashMap<>();
|
|
661
676
|
`)
|
|
662
677
|
if (hasEntId) {
|
|
663
|
-
Content(` ${matchvar}.put("id", ${srcdatavar}.get(
|
|
664
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
|
|
678
|
+
Content(` ${matchvar}.put("id", ${srcdatavar}.get(${rid(entity)}));
|
|
679
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
|
|
665
680
|
Map<String, Object> ${datavar}LoadResult = Helpers.toMapAny(${datavar}Loaded instanceof SdkEntity ? ((SdkEntity) ${datavar}Loaded).data() : ${datavar}Loaded);
|
|
666
681
|
assertNotNull(${datavar}LoadResult, "expected load result to be a map");
|
|
667
|
-
assertEquals(${srcdatavar}.get(
|
|
682
|
+
assertEquals(${srcdatavar}.get(${rid(entity)}), ${datavar}LoadResult.get(${rid(entity)}),
|
|
668
683
|
"expected load result id to match");
|
|
669
684
|
`)
|
|
670
685
|
}
|
|
671
686
|
else {
|
|
672
|
-
Content(`${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
|
|
687
|
+
Content(`${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
|
|
673
688
|
assertNotNull(${datavar}Loaded, "expected load result to be non-null");
|
|
674
689
|
`)
|
|
675
690
|
}
|
|
@@ -695,12 +710,39 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
695
710
|
}
|
|
696
711
|
// Always match the prior-created entity by id to avoid mock-order flakes.
|
|
697
712
|
Content(` Map<String, Object> ${matchvar} = new LinkedHashMap<>();
|
|
698
|
-
${matchvar}.put("id", ${srcdatavar}.get(
|
|
713
|
+
${matchvar}.put("id", ${srcdatavar}.get(${rid(entity)}));
|
|
699
714
|
${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, null);
|
|
700
715
|
`)
|
|
701
716
|
}
|
|
702
717
|
|
|
703
718
|
|
|
719
|
+
// The record field the entity's identity is read from, as a Java string.
|
|
720
|
+
function rid(entity: any): string {
|
|
721
|
+
return JSON.stringify(entityRecordIdField(entity))
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
726
|
+
// in another field reads the key from there too.
|
|
727
|
+
function fixtureIdentity(entity: any): string {
|
|
728
|
+
const field = entityRecordIdField(entity)
|
|
729
|
+
return 'id' === field ? '' : `
|
|
730
|
+
Object fixtureEntities = entityData.get("existing");
|
|
731
|
+
Object fixtureRecords = fixtureEntities instanceof Map
|
|
732
|
+
? ((Map<?, ?>) fixtureEntities).get(${JSON.stringify(entity.name)}) : null;
|
|
733
|
+
if (fixtureRecords instanceof Map) {
|
|
734
|
+
for (Object fixtureRec : ((Map<?, ?>) fixtureRecords).values()) {
|
|
735
|
+
if (fixtureRec instanceof Map && null != ((Map<?, ?>) fixtureRec).get("id")) {
|
|
736
|
+
@SuppressWarnings("unchecked")
|
|
737
|
+
Map<String, Object> fixtureRecMap = (Map<String, Object>) fixtureRec;
|
|
738
|
+
fixtureRecMap.put(${JSON.stringify(field)}, fixtureRecMap.get("id"));
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
`
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
|
|
704
746
|
// A child's route names its parents, and an entity no earlier step has
|
|
705
747
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
706
748
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
@@ -710,9 +752,15 @@ function javaLit(value: any): string {
|
|
|
710
752
|
}
|
|
711
753
|
|
|
712
754
|
|
|
755
|
+
// A whole number as Json.parse decodes one, so an example equals a record's id.
|
|
756
|
+
function javaIdLit(value: any): string {
|
|
757
|
+
return Number.isSafeInteger(value) ? value + 'L' : javaLit(value)
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
|
|
713
761
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
714
|
-
function liveFill(entity: any, step: any, matchvar: string): string {
|
|
715
|
-
const fills = liveStepExamples(entity, step)
|
|
762
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
|
|
763
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
716
764
|
return 0 === fills.length ? '' : ` if (setup.live) {
|
|
717
765
|
${fills.map(([k, ex]) => ` ${matchvar}.put(${JSON.stringify(k)}, ${javaLit(ex)});\n`).join('')} }
|
|
718
766
|
`
|