@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.
Files changed (134) hide show
  1. package/bin/voxgig-sdkgen +13 -2
  2. package/dist/action/copies.d.ts +6 -1
  3. package/dist/action/copies.js +43 -1
  4. package/dist/action/copies.js.map +1 -1
  5. package/dist/action/doctor.d.ts +2 -0
  6. package/dist/action/doctor.js +25 -6
  7. package/dist/action/doctor.js.map +1 -1
  8. package/dist/action/edition.js +3 -0
  9. package/dist/action/edition.js.map +1 -1
  10. package/dist/action/feature.js +3 -0
  11. package/dist/action/feature.js.map +1 -1
  12. package/dist/action/package.js +15 -0
  13. package/dist/action/package.js.map +1 -1
  14. package/dist/action/target.js +3 -0
  15. package/dist/action/target.js.map +1 -1
  16. package/dist/helpers/copymerge.d.ts +35 -0
  17. package/dist/helpers/copymerge.js +508 -0
  18. package/dist/helpers/copymerge.js.map +1 -0
  19. package/dist/helpers/flowGuard.js +4 -4
  20. package/dist/helpers/flowGuard.js.map +1 -1
  21. package/dist/helpers/liveDiscovery.d.ts +7 -0
  22. package/dist/helpers/liveDiscovery.js +20 -0
  23. package/dist/helpers/liveDiscovery.js.map +1 -0
  24. package/dist/helpers/opShape.d.ts +2 -1
  25. package/dist/helpers/opShape.js +4 -0
  26. package/dist/helpers/opShape.js.map +1 -1
  27. package/dist/helpers/pointPath.d.ts +2 -1
  28. package/dist/helpers/pointPath.js +6 -0
  29. package/dist/helpers/pointPath.js.map +1 -1
  30. package/dist/helpers/testPolicy.d.ts +14 -4
  31. package/dist/helpers/testPolicy.js +152 -54
  32. package/dist/helpers/testPolicy.js.map +1 -1
  33. package/dist/sdkgen.d.ts +8 -6
  34. package/dist/sdkgen.js +11 -5
  35. package/dist/sdkgen.js.map +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/dist/types.d.ts +1 -0
  38. package/dist/utility.js +7 -3
  39. package/dist/utility.js.map +1 -1
  40. package/model/sdkgen.aontu +4 -0
  41. package/package.json +1 -1
  42. package/project/.sdk/src/cmp/c/TestDirect_c.ts +3 -2
  43. package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +3 -2
  44. package/project/.sdk/src/cmp/cpp/TestEntity_cpp.ts +33 -10
  45. package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +12 -12
  46. package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +73 -28
  47. package/project/.sdk/src/cmp/go/TestDirect_go.ts +12 -10
  48. package/project/.sdk/src/cmp/go/TestEntity_go.ts +67 -23
  49. package/project/.sdk/src/cmp/java/TestDirect_java.ts +12 -11
  50. package/project/.sdk/src/cmp/java/TestEntity_java.ts +71 -23
  51. package/project/.sdk/src/cmp/js/TestDirect_js.ts +13 -12
  52. package/project/.sdk/src/cmp/js/TestEntity_js.ts +41 -17
  53. package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +12 -10
  54. package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +64 -23
  55. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +9 -5
  56. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +61 -23
  57. package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +9 -5
  58. package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +58 -24
  59. package/project/.sdk/src/cmp/php/TestDirect_php.ts +9 -5
  60. package/project/.sdk/src/cmp/php/TestEntity_php.ts +61 -23
  61. package/project/.sdk/src/cmp/py/TestDirect_py.ts +10 -6
  62. package/project/.sdk/src/cmp/py/TestEntity_py.ts +59 -27
  63. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +9 -5
  64. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +59 -23
  65. package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +9 -8
  66. package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +56 -24
  67. package/project/.sdk/src/cmp/scala/TestDirect_scala.ts +3 -2
  68. package/project/.sdk/src/cmp/scala/TestEntity_scala.ts +36 -9
  69. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +15 -32
  70. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +41 -17
  71. package/project/.sdk/tm/c/tests/transport_test.c +33 -0
  72. package/project/.sdk/tm/c/utility/fetcher.c +151 -2
  73. package/project/.sdk/tm/c/utility/make_url.c +8 -6
  74. package/project/.sdk/tm/clojure/src/sdk/core.clj +17 -10
  75. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +38 -0
  76. package/project/.sdk/tm/cpp/utility/pipeline.hpp +5 -4
  77. package/project/.sdk/tm/csharp/test/PrimaryUtilityTest.cs +69 -0
  78. package/project/.sdk/tm/csharp/utility/Fetcher.cs +3 -1
  79. package/project/.sdk/tm/csharp/utility/MakeUrl.cs +5 -4
  80. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +10 -6
  81. package/project/.sdk/tm/elixir/test/pipeline_test.exs +61 -0
  82. package/project/.sdk/tm/go/test/primary_utility_test.go +60 -0
  83. package/project/.sdk/tm/go/utility/fetcher.go +15 -4
  84. package/project/.sdk/tm/go/utility/make_url.go +4 -3
  85. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +47 -0
  86. package/project/.sdk/tm/java/utility/MakeUrl.java +5 -4
  87. package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +5 -3
  88. package/project/.sdk/tm/js/test/live-runner.js +4 -3
  89. package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +40 -0
  90. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +41 -0
  91. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +4 -3
  92. package/project/.sdk/tm/lua/test/primary_utility_test.lua +61 -0
  93. package/project/.sdk/tm/lua/utility/fetcher.lua +54 -6
  94. package/project/.sdk/tm/lua/utility/make_url.lua +5 -4
  95. package/project/.sdk/tm/ocaml/sdk_runtime.ml +5 -5
  96. package/project/.sdk/tm/perl/t/primary_utility.t +54 -0
  97. package/project/.sdk/tm/perl/utility/fetcher.pm +65 -11
  98. package/project/.sdk/tm/perl/utility/make_url.pm +4 -3
  99. package/project/.sdk/tm/php/test/PipelineTest.php +52 -0
  100. package/project/.sdk/tm/php/utility/Fetcher.php +81 -15
  101. package/project/.sdk/tm/php/utility/MakeUrl.php +5 -3
  102. package/project/.sdk/tm/py/pkg/utility/fetcher.py +1 -0
  103. package/project/.sdk/tm/py/pkg/utility/make_url.py +5 -4
  104. package/project/.sdk/tm/py/test/test_primary_utility.py +52 -0
  105. package/project/.sdk/tm/rb/test/primary_utility_test.rb +46 -0
  106. package/project/.sdk/tm/rb/utility/fetcher.rb +41 -5
  107. package/project/.sdk/tm/rb/utility/make_url.rb +5 -3
  108. package/project/.sdk/tm/rust/tests/primary_utility_test.rs +65 -0
  109. package/project/.sdk/tm/rust/utility/make_url.rs +7 -6
  110. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +47 -1
  111. package/project/.sdk/tm/scala/utility/Make.scala +8 -6
  112. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +59 -15
  113. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +4 -4
  114. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/PrimaryUtilityTest.swift +72 -0
  115. package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +5 -3
  116. package/project/.sdk/tm/ts/test/live-runner.ts +4 -3
  117. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +40 -0
  118. package/project/.sdk/tm/zig/core/utility.zig +5 -5
  119. package/project/sdkgen-package.json +1 -1
  120. package/src/action/copies.ts +54 -0
  121. package/src/action/doctor.ts +36 -7
  122. package/src/action/edition.ts +9 -1
  123. package/src/action/feature.ts +7 -1
  124. package/src/action/package.ts +28 -1
  125. package/src/action/target.ts +7 -1
  126. package/src/helpers/copymerge.ts +707 -0
  127. package/src/helpers/flowGuard.ts +4 -4
  128. package/src/helpers/liveDiscovery.ts +31 -0
  129. package/src/helpers/opShape.ts +6 -0
  130. package/src/helpers/pointPath.ts +8 -0
  131. package/src/helpers/testPolicy.ts +193 -55
  132. package/src/sdkgen.ts +13 -3
  133. package/src/types.ts +2 -0
  134. 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,
29
29
  serverVarEnv,
30
30
  serverVariables,
31
31
  invalidRequest,
32
32
  liveFlowNeeds, liveStrict, liveStrictNote,
33
33
  liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
34
- liveGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
34
+ liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
35
35
  liveEntity,
36
36
  } from '@voxgig/sdkgen'
37
37
 
@@ -42,6 +42,17 @@ import { formatRubyValue } from './utility_rb'
42
42
  // the ids it binds, and a create-less load reading the first listed record.
43
43
  function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
44
44
  let out = ''
45
+ if (null != needs.examples) {
46
+ out += ` if setup[:live]
47
+ { ${needs.examples
48
+ .map(([k, ex]: any) => JSON.stringify(k) + ' => ' + formatRubyValue(ex)).join(', ')} }.each do |_live_key, _live_ex|
49
+ if setup[:synthetic_only] || setup[:idmap][_live_key].nil?
50
+ setup[:idmap][_live_key] = _live_ex
51
+ end
52
+ end
53
+ end
54
+ `
55
+ }
45
56
  if (0 < needs.keys.length) {
46
57
  out += ` if setup[:live]
47
58
  [${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')}].each do |_live_key|
@@ -59,6 +70,14 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
59
70
  `
60
71
  }
61
72
  out += ' client = setup[:client]\n'
73
+ if (null != needs.record) {
74
+ out += ` if setup[:live]
75
+ Runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)}) do
76
+ [{ "id" => setup[:idmap][${JSON.stringify(needs.record)}] }]
77
+ end
78
+ end
79
+ `
80
+ }
62
81
  if (null != needs.discover) {
63
82
  const match = Object.entries(needs.discover)
64
83
  .map(([k, v]: any) => `${JSON.stringify(k)} => setup[:idmap][${JSON.stringify(v)}]`)
@@ -265,18 +284,17 @@ ${failureTests(model, entity)}${validateListTest(model, entity)}` : ''}${validat
265
284
  })
266
285
  }
267
286
 
268
- const getOnly = liveGetOnly(entity, basicflow)
269
- if (null != getOnly) {
270
- Content(` if setup[:live] && ENV[${formatRubyValue(LIVE_GETONLY_ENV)}] == "TRUE"
271
- ${liveExcludedLines(getOnly).map((line) => ' puts ' + formatRubyValue(line) + '\n').join('')}`)
272
- if (0 === flowSteps(getOnly.flow).length) {
273
- Content(` skip(${formatRubyValue(liveExcludedSummary(getOnly))})
287
+ for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
288
+ Content(` if setup[:live]${getOnly ? ` && ENV[${formatRubyValue(LIVE_GETONLY_ENV)}] == "TRUE"` : ''}
289
+ ${liveExcludedLines(plan).map((line) => ' puts ' + formatRubyValue(line) + '\n').join('')}`)
290
+ if (!runs) {
291
+ Content(` skip(${formatRubyValue(liveExcludedSummary(plan))})
274
292
  end
275
293
 
276
294
  `)
277
295
  }
278
296
  else {
279
- flowBody(getOnly.flow)
297
+ flowBody(plan.flow)
280
298
  Content(` return
281
299
  end
282
300
 
@@ -302,7 +320,7 @@ end
302
320
  entity_data_file = File.join(__dir__, "..", "..", ".sdk", "test", "entity", "${entity.name}", "${entity.Name}TestData.json")
303
321
  entity_data_source = File.read(entity_data_file, encoding: "UTF-8")
304
322
  entity_data = JSON.parse(entity_data_source)
305
-
323
+ ${fixtureIdentity(entity)}
306
324
  options = {}
307
325
  options["entity"] = entity_data["existing"]
308
326
 
@@ -428,7 +446,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
428
446
  assert !${datavar}.nil?
429
447
  `)
430
448
  if (null != ctx.entity.id) {
431
- Content(` assert !${datavar}["id"].nil?
449
+ Content(` assert !${datavar}[${rid(ctx.entity)}].nil?
432
450
  `)
433
451
  }
434
452
  }
@@ -467,7 +485,7 @@ const generateList: OpGen = (ctx, step, index) => {
467
485
  Content(` }
468
486
  `)
469
487
  }
470
- Content(liveFill(entity, step, matchvar))
488
+ Content(liveFill(entity, step, matchvar, flow))
471
489
 
472
490
  Content(`
473
491
  ${listvar}_result = ${entvar}.list(${matchvar}, nil)
@@ -487,7 +505,7 @@ const generateList: OpGen = (ctx, step, index) => {
487
505
  Content(`
488
506
  found_item = Vs.select(
489
507
  Runner.entity_list_to_data(${listvar}_result),
490
- { "id" => ${refDataVar}["id"] })
508
+ { ${rid(entity)} => ${refDataVar}[${rid(entity)}] })
491
509
  assert !Vs.isempty(found_item)
492
510
  `)
493
511
  } else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
@@ -495,7 +513,7 @@ const generateList: OpGen = (ctx, step, index) => {
495
513
  Content(`
496
514
  not_found_item = Vs.select(
497
515
  Runner.entity_list_to_data(${listvar}_result),
498
- { "id" => ${refDataVar}["id"] })
516
+ { ${rid(entity)} => ${refDataVar}[${rid(entity)}] })
499
517
  assert Vs.isempty(not_found_item)
500
518
  `)
501
519
  }
@@ -528,7 +546,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
528
546
  Content(` ${datavar}_up = {
529
547
  `)
530
548
  if (hasEntIdU) {
531
- Content(` "id" => ${srcdatavar}["id"],
549
+ Content(` "id" => ${srcdatavar}[${rid(entity)}],
532
550
  `)
533
551
  }
534
552
 
@@ -563,7 +581,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
563
581
  assert !${resdatavar}.nil?
564
582
  `)
565
583
  if (hasEntIdU) {
566
- Content(` assert_equal ${resdatavar}["id"], ${datavar}_up["id"]
584
+ Content(` assert_equal ${resdatavar}[${rid(entity)}], ${datavar}_up["id"]
567
585
  `)
568
586
  }
569
587
 
@@ -621,17 +639,17 @@ const generateLoad: OpGen = (ctx, step, index) => {
621
639
  }
622
640
  if (hasEntId) {
623
641
  Content(` ${matchvar} = {
624
- "id" => ${srcdatavar}["id"],
642
+ "id" => ${srcdatavar}[${rid(entity)}],
625
643
  }
626
- ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
644
+ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
627
645
  ${datavar}_load_result = Helpers.to_map(${datavar}_loaded.respond_to?(:data_get) ? ${datavar}_loaded.data_get : ${datavar}_loaded)
628
646
  assert !${datavar}_load_result.nil?
629
- assert_equal ${datavar}_load_result["id"], ${srcdatavar}["id"]
647
+ assert_equal ${datavar}_load_result[${rid(entity)}], ${srcdatavar}[${rid(entity)}]
630
648
  `)
631
649
  }
632
650
  else {
633
651
  Content(` ${matchvar} = {}
634
- ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
652
+ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
635
653
  assert !${datavar}_loaded.nil?
636
654
  `)
637
655
  }
@@ -660,7 +678,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
660
678
  }
661
679
  // Always match the prior-created entity by id to avoid mock-order flakes.
662
680
  Content(` ${matchvar} = {
663
- "id" => ${srcdatavar}["id"],
681
+ "id" => ${srcdatavar}[${rid(entity)}],
664
682
  }
665
683
  ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, nil)
666
684
  `)
@@ -668,12 +686,30 @@ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, nil)
668
686
 
669
687
 
670
688
 
689
+ // The record field the entity's identity is read from, as a Ruby string.
690
+ function rid(entity: any): string {
691
+ return JSON.stringify(entityRecordIdField(entity))
692
+ }
693
+
694
+
695
+ // The fixture keeps each record's key in `id`; an entity keeping its identity
696
+ // in another field reads the key from there too.
697
+ function fixtureIdentity(entity: any): string {
698
+ const field = entityRecordIdField(entity)
699
+ return 'id' === field ? '' : `
700
+ ((entity_data["existing"] || {})[${JSON.stringify(entity.name)}] || {}).each_value do |rec|
701
+ rec[${JSON.stringify(field)}] = rec["id"] if rec.is_a?(Hash) && !rec["id"].nil?
702
+ end
703
+ `
704
+ }
705
+
706
+
671
707
  // A child's route names its parents, and an entity no earlier step has
672
708
  // filled knows none of them, so the call itself gives each parent id. A live
673
709
  // ENTID may key a parent by its field name, the fixture by its own name.
674
710
  // A live step sends each example its route requires and the step leaves unbound.
675
- function liveFill(entity: any, step: any, matchvar: string): string {
676
- const fills = liveStepExamples(entity, step)
711
+ function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
712
+ const fills = liveStepExamples(entity, step, flow)
677
713
  return 0 === fills.length ? '' : ` if setup[:live]
678
714
  ${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${formatRubyValue(ex)}\n`).join('')} end
679
715
  `
@@ -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
 
@@ -134,7 +136,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
134
136
 
135
137
  // Load point info.
136
138
  const loadPoint = loadOp?.points?.[0]
137
- const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
139
+ const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
138
140
  const allLoadParams = loadPoint?.g?.params || []
139
141
  // Only path params that actually appear in the URL template drive the
140
142
  // direct-test path-param setup and URL-substitution asserts.
@@ -152,7 +154,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
152
154
 
153
155
  // List point info.
154
156
  const listPoint = listOp?.points?.[0]
155
- const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
157
+ const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
156
158
  const listParams = listPoint?.g?.params || []
157
159
 
158
160
  const entidEnvVar = `${PROJECTNAME}_TEST_${envToken(entity.name)}_ENTID`
@@ -392,8 +394,10 @@ fn ${evar}_direct_load() {}
392
394
  else if (hasLoad && loadPoint) {
393
395
  const examples = 0 < loadParams.length &&
394
396
  loadParams.every((p: any) => undefined !== p.ex && null !== p.ex)
395
- const discover = !examples && hasList && 0 < loadParams.length
396
- const idParam = loadParams.find((p: any) => 'id' === p.n)?.n ?? loadParams[0]?.n ?? 'id'
397
+ const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
398
+ const discover = null != discovery
399
+ const idParam = discovery?.param
400
+ const idField = discovery?.field
397
401
  const loadLiveIdKeys: string[] = examples ? [] :
398
402
  discover ? listParams.map(liveKey).concat(loadParams.filter((p: any) => idParam !== p.n).map(liveKey)) :
399
403
  loadParams.map(liveKey)
@@ -454,10 +458,7 @@ ${liveQueryBlock(loadPoint)} if setup.live {
454
458
  live_empty("The account has no ${entity.name} record to load");
455
459
  return;
456
460
  }
457
- let mut found = getp(&first, "${idParam}");
458
- if found.is_noval() {
459
- found = getp(&first, "id");
460
- }
461
+ let found = getp(&first, "${idField}");
461
462
  if found.is_noval() {
462
463
  live_miss(LIVE_STRICT, "Live load blocked: discovery returned no usable identity");
463
464
  return;
@@ -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
- liveGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
25
+ liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
26
26
  liveRouteExamples, liveStepExamples,
27
27
  liveEntity,
28
28
  } from '@voxgig/sdkgen'
@@ -48,6 +48,12 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
48
48
  function liveFlowGate(entity: any, needs: any, entidEnv: string, method: string,
49
49
  strict: boolean, hasSteps: boolean): string {
50
50
  let out = ''
51
+ for (const [k, ex] of needs.examples || []) {
52
+ out += ` if setup.live && (setup.synthetic_only || getp(&setup.idmap, ${JSON.stringify(k)}).is_noval()) {
53
+ setp(&setup.idmap, ${JSON.stringify(k)}, ${rustLit(ex)});
54
+ }
55
+ `
56
+ }
51
57
  if (0 < needs.keys.length) {
52
58
  out += ` if setup.live {
53
59
  for live_key in [${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')}] {
@@ -70,6 +76,14 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, method: string,
70
76
  return out
71
77
  }
72
78
  out += ' let client = setup.client.clone();\n'
79
+ if (null != needs.record) {
80
+ out += ` if setup.live && !live_existing(&setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)}, || {
81
+ Ok(ja(vec![jo(vec![("id", getp(&setup.idmap, ${JSON.stringify(needs.record)}))])]))
82
+ }) {
83
+ return;
84
+ }
85
+ `
86
+ }
73
87
  if (null != needs.discover) {
74
88
  const match = Object.entries(needs.discover)
75
89
  .map(([k, v]: any) => `(${JSON.stringify(k)}, getp(&setup.idmap, ${JSON.stringify(v)}))`)
@@ -289,19 +303,18 @@ ${skipBlock}`)
289
303
  `)
290
304
  }
291
305
 
292
- const getOnly = liveGetOnly(entity, basicflow)
293
- if (null != getOnly) {
294
- Content(` if setup.live && std::env::var(${JSON.stringify(LIVE_GETONLY_ENV)}).map(|v| v == "TRUE").unwrap_or(false) {
295
- ${liveExcludedLines(getOnly).map((line) => ' println!("{}", ' + JSON.stringify(line) + ');\n').join('')}`)
296
- if (0 === flowSteps(getOnly.flow).length) {
297
- Content(` eprintln!("skip: {}", ${JSON.stringify(liveExcludedSummary(getOnly))});
306
+ for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
307
+ Content(` if setup.live${getOnly ? ` && std::env::var(${JSON.stringify(LIVE_GETONLY_ENV)}).map(|v| v == "TRUE").unwrap_or(false)` : ''} {
308
+ ${liveExcludedLines(plan).map((line) => ' println!("{}", ' + JSON.stringify(line) + ');\n').join('')}`)
309
+ if (!runs) {
310
+ Content(` eprintln!("skip: {}", ${JSON.stringify(liveExcludedSummary(plan))});
298
311
  return;
299
312
  }
300
313
 
301
314
  `)
302
315
  }
303
316
  else {
304
- flowBody(getOnly.flow)
317
+ flowBody(plan.flow)
305
318
  Content(` return;
306
319
  }
307
320
 
@@ -328,7 +341,7 @@ ${liveExcludedLines(getOnly).map((line) => ' println!("{}", ' + JSON.stri
328
341
  entity_data_file.push("${entity.Name}TestData.json");
329
342
 
330
343
  let entity_data = read_json(&entity_data_file);
331
-
344
+ ${fixtureIdentity(entity)}
332
345
  let options = jo(vec![("entity", getp(&entity_data, "existing"))]);
333
346
 
334
347
  let client = test_sdk(options, extra.clone());
@@ -472,7 +485,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
472
485
  `)
473
486
  if (null != ctx.entity.id) {
474
487
  Content(` assert!(
475
- !getp(&${datavar}, "id").is_noval(),
488
+ !getp(&${datavar}, ${rid(ctx.entity)}).is_noval(),
476
489
  "expected created entity to have an id"
477
490
  );
478
491
  `)
@@ -511,7 +524,7 @@ const generateList: OpGen = (ctx, step, index) => {
511
524
  `)
512
525
  }
513
526
  }
514
- Content(liveFill(entity, step, matchvar))
527
+ Content(liveFill(entity, step, matchvar, flow))
515
528
 
516
529
  Content(`
517
530
  let ${listvar} = ${entvar}
@@ -535,7 +548,7 @@ const generateList: OpGen = (ctx, step, index) => {
535
548
  Content(`
536
549
  let found_item = vs::select(
537
550
  &entity_list_to_data(&${listvar}),
538
- &jo(vec![("id", getp(&${refDataVar}, "id"))]),
551
+ &jo(vec![(${rid(entity)}, getp(&${refDataVar}, ${rid(entity)}))]),
539
552
  );
540
553
  assert!(
541
554
  !vs::is_empty(&found_item),
@@ -547,7 +560,7 @@ const generateList: OpGen = (ctx, step, index) => {
547
560
  Content(`
548
561
  let not_found_item = vs::select(
549
562
  &entity_list_to_data(&${listvar}),
550
- &jo(vec![("id", getp(&${refDataVar}, "id"))]),
563
+ &jo(vec![(${rid(entity)}, getp(&${refDataVar}, ${rid(entity)}))]),
551
564
  );
552
565
  assert!(
553
566
  vs::is_empty(&not_found_item),
@@ -584,7 +597,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
584
597
  Content(` let ${datavar}_up = Value::empty_map();
585
598
  `)
586
599
  if (hasEntIdU) {
587
- Content(` setp(&${datavar}_up, "id", getp(&${srcdatavar}, "id"));
600
+ Content(` setp(&${datavar}_up, "id", getp(&${srcdatavar}, ${rid(entity)}));
588
601
  `)
589
602
  }
590
603
 
@@ -628,7 +641,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
628
641
  `)
629
642
  if (hasEntIdU) {
630
643
  Content(` assert_eq!(
631
- getp(&${resdatavar}, "id"),
644
+ getp(&${resdatavar}, ${rid(entity)}),
632
645
  getp(&${datavar}_up, "id"),
633
646
  "expected update result id to match"
634
647
  );
@@ -695,8 +708,8 @@ const generateLoad: OpGen = (ctx, step, index) => {
695
708
  `)
696
709
  }
697
710
  if (hasEntId) {
698
- Content(` let ${matchvar} = jo(vec![("id", getp(&${srcdatavar}, "id"))]);
699
- ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} let ${datavar}_loaded = ${entvar}
711
+ Content(` let ${matchvar} = jo(vec![("id", getp(&${srcdatavar}, ${rid(entity)}))]);
712
+ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} let ${datavar}_loaded = ${entvar}
700
713
  .load(${matchvar}.clone(), Value::Noval)
701
714
  .expect("load failed");
702
715
  let ${datavar}_load_result = to_map(&${datavar}_loaded.data(None));
@@ -705,15 +718,15 @@ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchva
705
718
  "expected load result to be a map"
706
719
  );
707
720
  assert_eq!(
708
- getp(&${datavar}_load_result, "id"),
709
- getp(&${srcdatavar}, "id"),
721
+ getp(&${datavar}_load_result, ${rid(entity)}),
722
+ getp(&${srcdatavar}, ${rid(entity)}),
710
723
  "expected load result id to match"
711
724
  );
712
725
  `)
713
726
  }
714
727
  else {
715
728
  Content(` let ${matchvar} = Value::empty_map();
716
- ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} let ${datavar}_loaded = ${entvar}
729
+ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} let ${datavar}_loaded = ${entvar}
717
730
  .load(${matchvar}.clone(), Value::Noval)
718
731
  .expect("load failed");
719
732
  // load resolves to the ENTITY; the record is reached through data().
@@ -744,7 +757,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
744
757
  `)
745
758
  }
746
759
  // Always match the prior-created entity by id to avoid mock-order flakes.
747
- Content(` let ${matchvar} = jo(vec![("id", getp(&${srcdatavar}, "id"))]);
760
+ Content(` let ${matchvar} = jo(vec![("id", getp(&${srcdatavar}, ${rid(entity)}))]);
748
761
  ${parentMatch(step, matchvar)} ${entvar}
749
762
  .remove(${matchvar}.clone(), Value::Noval)
750
763
  .expect("remove failed");
@@ -752,6 +765,25 @@ ${parentMatch(step, matchvar)} ${entvar}
752
765
  }
753
766
 
754
767
 
768
+ // The record field the entity's identity is read from, as a Rust string.
769
+ function rid(entity: any): string {
770
+ return JSON.stringify(entityRecordIdField(entity))
771
+ }
772
+
773
+
774
+ // The fixture keeps each record's key in `id`; an entity keeping its identity
775
+ // in another field reads the key from there too.
776
+ function fixtureIdentity(entity: any): string {
777
+ return 'id' === entityRecordIdField(entity) ? '' : `
778
+ for (_, fixture_rec) in vs::items_vec(&to_map(&getpath(&["existing", "${entity.name}"], &entity_data))) {
779
+ if matches!(fixture_rec, Value::Map(_)) && !getp(&fixture_rec, "id").is_noval() {
780
+ setp(&fixture_rec, ${rid(entity)}, getp(&fixture_rec, "id"));
781
+ }
782
+ }
783
+ `
784
+ }
785
+
786
+
755
787
  // A child's route names its parents, and an entity no earlier step has
756
788
  // filled knows none of them, so the call itself gives each parent id. A live
757
789
  // ENTID may key a parent by its field name, the fixture by its own name.
@@ -763,8 +795,8 @@ function rustLit(value: any): string {
763
795
 
764
796
 
765
797
  // A live step sends each example its route requires and the step leaves unbound.
766
- function liveFill(entity: any, step: any, matchvar: string): string {
767
- const fills = liveStepExamples(entity, step)
798
+ function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
799
+ const fills = liveStepExamples(entity, step, flow)
768
800
  return 0 === fills.length ? '' : ` if setup.live {
769
801
  ${fills.map(([k, ex]) => ` setp(&${matchvar}, ${JSON.stringify(k)}, ${rustLit(ex)});\n`).join('')} }
770
802
  `
@@ -12,6 +12,7 @@ import {
12
12
  cmp,
13
13
  snakify,
14
14
  pointParts,
15
+ pointSlash,
15
16
  pointPlaceholders,
16
17
  pointIsGraphql,
17
18
  graphqlDirectSkip,
@@ -83,7 +84,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
83
84
  // Load point info.
84
85
  const loadPoint = loadOp?.points?.[0]
85
86
  const loadPath = loadPoint
86
- ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param)
87
+ ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint)
87
88
  : ''
88
89
  const allLoadParams = loadPoint?.g?.params || []
89
90
  // Only path params that actually appear in the URL template drive the
@@ -103,7 +104,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
103
104
  // List point info.
104
105
  const listPoint = listOp?.points?.[0]
105
106
  const listPath = listPoint
106
- ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param)
107
+ ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint)
107
108
  : ''
108
109
  const listParams = listPoint?.g?.params || []
109
110
 
@@ -19,6 +19,7 @@ import {
19
19
  buildIdNames,
20
20
  getMatchEntries,
21
21
  entityDataIdField,
22
+ entityRecordIdField,
22
23
  } from '@voxgig/sdkgen'
23
24
 
24
25
 
@@ -104,7 +105,7 @@ ${failureScopes(SDK, entity, accessor)}
104
105
  rep.scope("${ENTLOWER}.basic") {
105
106
  val entityData = Helpers.toMapAny(SdkTestSupport.readJson(
106
107
  "../.sdk/test/entity/${ENTLOWER}/${EntityName}TestData.json"))
107
- val options = new LinkedHashMap[String, Object]()
108
+ ${fixtureIdentity(entity)} val options = new LinkedHashMap[String, Object]()
108
109
  options.put("entity", entityData.get("existing"))
109
110
  val client = ${SDK}.testSDK(options, null)
110
111
 
@@ -184,7 +185,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
184
185
  rep.check("${ENTLOWER}.create.map", ${datavar} != null, "expected create result to be a map")
185
186
  `)
186
187
  if (null != entityDataIdField(entity)) {
187
- Content(` rep.check("${ENTLOWER}.create.id", ${datavar} != null && ${datavar}.get("id") != null, "expected created entity to have an id")
188
+ Content(` rep.check("${ENTLOWER}.create.id", ${datavar} != null && ${datavar}.get(${rid(entity)}) != null, "expected created entity to have an id")
188
189
  `)
189
190
  }
190
191
  }
@@ -242,12 +243,12 @@ const generateList: OpGen = (ctx, step, index) => {
242
243
 
243
244
  if ('ItemExists' === validator.apply && hasRefData && hasDataId) {
244
245
  Content(` val ${listvar}Found = Struct.select(
245
- SdkTestSupport.entityListToData(${listvar}), SdkTestSupport.om("id" -> ${refDataVar}.get("id")))
246
+ SdkTestSupport.entityListToData(${listvar}), SdkTestSupport.om(${rid(entity)} -> ${refDataVar}.get(${rid(entity)})))
246
247
  rep.check("${ENTLOWER}.list.exists", !Struct.isempty(${listvar}Found), "expected to find created entity in list")
247
248
  `)
248
249
  } else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
249
250
  Content(` val ${listvar}NotFound = Struct.select(
250
- SdkTestSupport.entityListToData(${listvar}), SdkTestSupport.om("id" -> ${refDataVar}.get("id")))
251
+ SdkTestSupport.entityListToData(${listvar}), SdkTestSupport.om(${rid(entity)} -> ${refDataVar}.get(${rid(entity)})))
251
252
  rep.check("${ENTLOWER}.list.notexists", Struct.isempty(${listvar}NotFound), "expected removed entity to not be in list")
252
253
  `)
253
254
  }
@@ -280,7 +281,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
280
281
  Content(` val ${datavar}Up = new LinkedHashMap[String, Object]()
281
282
  `)
282
283
  if (hasDataId) {
283
- Content(` ${datavar}Up.put("id", ${srcdatavar}.get("id"))
284
+ Content(` ${datavar}Up.put("id", ${srcdatavar}.get(${rid(entity)}))
284
285
  `)
285
286
  }
286
287
 
@@ -312,7 +313,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
312
313
  rep.check("${ENTLOWER}.update.map", ${resdatavar} != null, "expected update result to be a map")
313
314
  `)
314
315
  if (hasDataId) {
315
- Content(` rep.eq("${ENTLOWER}.update.id", ${datavar}Up.get("id"), ${resdatavar}.get("id"))
316
+ Content(` rep.eq("${ENTLOWER}.update.id", ${datavar}Up.get("id"), ${resdatavar}.get(${rid(entity)}))
316
317
  `)
317
318
  }
318
319
  if (hasMark) {
@@ -363,11 +364,11 @@ const generateLoad: OpGen = (ctx, step, index) => {
363
364
  Content(` val ${matchvar} = new LinkedHashMap[String, Object]()
364
365
  `)
365
366
  if (hasDataId) {
366
- Content(` ${matchvar}.put("id", ${srcdatavar}.get("id"))
367
+ Content(` ${matchvar}.put("id", ${srcdatavar}.get(${rid(entity)}))
367
368
  ${loadMatch(entity, step, matchvar, srcdatavar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
368
369
  val ${datavar}LoadResult = Helpers.toMapAny(${datavar}Loaded match { case e: SdkEntity => e.data(); case o => o })
369
370
  rep.check("${ENTLOWER}.load.map", ${datavar}LoadResult != null, "expected load result to be a map")
370
- rep.eq("${ENTLOWER}.load.id", ${srcdatavar}.get("id"), ${datavar}LoadResult.get("id"))
371
+ rep.eq("${ENTLOWER}.load.id", ${srcdatavar}.get(${rid(entity)}), ${datavar}LoadResult.get(${rid(entity)}))
371
372
  `)
372
373
  } else {
373
374
  Content(`${loadMatch(entity, step, matchvar, srcdatavar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
@@ -401,12 +402,38 @@ const generateRemove: OpGen = (ctx, step, index) => {
401
402
  `)
402
403
  }
403
404
  Content(` val ${matchvar} = new LinkedHashMap[String, Object]()
404
- ${matchvar}.put("id", ${srcdatavar}.get("id"))
405
+ ${matchvar}.put("id", ${srcdatavar}.get(${rid(entity)}))
405
406
  ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, null)
406
407
  `)
407
408
  }
408
409
 
409
410
 
411
+ // The record field the entity's identity is read from, as a Scala string.
412
+ function rid(entity: any): string {
413
+ return JSON.stringify(entityRecordIdField(entity))
414
+ }
415
+
416
+
417
+ // The fixture keeps each record's key in `id`; an entity keeping its identity
418
+ // in another field reads the key from there too.
419
+ function fixtureIdentity(entity: any): string {
420
+ const field = entityRecordIdField(entity)
421
+ return 'id' === field ? '' : ` entityData.get("existing") match {
422
+ case fixtureEntities: java.util.Map[_, _] => fixtureEntities.get(${JSON.stringify(entity.name)}) match {
423
+ case fixtureRecords: java.util.Map[_, _] => fixtureRecords.values().toArray.foreach {
424
+ case fixtureRec: java.util.Map[_, _] if null != fixtureRec.get("id") =>
425
+ fixtureRec.asInstanceOf[java.util.Map[String, Object]]
426
+ .put(${JSON.stringify(field)}, fixtureRec.get("id").asInstanceOf[Object])
427
+ case _ =>
428
+ }
429
+ case _ =>
430
+ }
431
+ case _ =>
432
+ }
433
+ `
434
+ }
435
+
436
+
410
437
  // A child's route names its parents, and an entity no earlier step has
411
438
  // filled knows none of them, so the call itself gives each parent id.
412
439
  function parentMatch(step: any, matchvar: string): string {