@voxgig/sdkgen 4.40.0 → 4.41.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 (85) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Main.js +4 -0
  3. package/dist/cmp/Main.js.map +1 -1
  4. package/dist/helpers/testPolicy.d.ts +5 -1
  5. package/dist/helpers/testPolicy.js +32 -3
  6. package/dist/helpers/testPolicy.js.map +1 -1
  7. package/dist/helpers/useragent.d.ts +2 -0
  8. package/dist/helpers/useragent.js +31 -0
  9. package/dist/helpers/useragent.js.map +1 -0
  10. package/dist/sdkgen.d.ts +2 -2
  11. package/dist/sdkgen.js +6 -3
  12. package/dist/sdkgen.js.map +1 -1
  13. package/dist/testkit.js +1 -1
  14. package/dist/testkit.js.map +1 -1
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/model/sdkgen.aontu +6 -0
  17. package/package.json +2 -2
  18. package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +35 -16
  19. package/project/.sdk/src/cmp/go/ReadmeExamplesTest_go.ts +7 -6
  20. package/project/.sdk/src/cmp/go/TestEntity_go.ts +24 -13
  21. package/project/.sdk/src/cmp/java/TestEntity_java.ts +21 -11
  22. package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +26 -14
  23. package/project/.sdk/src/cmp/lua/ReadmeExamplesTest_lua.ts +7 -5
  24. package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +12 -0
  25. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +25 -13
  26. package/project/.sdk/src/cmp/perl/ReadmeExamplesTest_perl.ts +15 -1
  27. package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +23 -13
  28. package/project/.sdk/src/cmp/php/ReadmeExamplesTest_php.ts +31 -2
  29. package/project/.sdk/src/cmp/php/TestEntity_php.ts +29 -14
  30. package/project/.sdk/src/cmp/py/ReadmeExamplesTest_py.ts +14 -1
  31. package/project/.sdk/src/cmp/py/TestEntity_py.ts +28 -14
  32. package/project/.sdk/src/cmp/rb/ReadmeExamplesTest_rb.ts +18 -1
  33. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +24 -13
  34. package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +27 -14
  35. package/project/.sdk/src/cmp/ts/ReadmeExamplesTest_ts.ts +7 -2
  36. package/project/.sdk/tm/c/feature/test.c +22 -2
  37. package/project/.sdk/tm/c/tests/transport_test.c +2 -2
  38. package/project/.sdk/tm/c/utility/http.c +1 -1
  39. package/project/.sdk/tm/clojure/src/sdk/core.clj +1 -1
  40. package/project/.sdk/tm/clojure/src/sdk/features.clj +13 -1
  41. package/project/.sdk/tm/cpp/feature/test.hpp +16 -2
  42. package/project/.sdk/tm/csharp/feature/TestFeature.cs +18 -0
  43. package/project/.sdk/tm/csharp/utility/Fetcher.cs +5 -4
  44. package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +19 -1
  45. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +1 -1
  46. package/project/.sdk/tm/go/feature/test_feature.go +16 -0
  47. package/project/.sdk/tm/go/utility/fetcher.go +4 -3
  48. package/project/.sdk/tm/java/feature/TestFeature.java +15 -0
  49. package/project/.sdk/tm/java/utility/Fetcher.java +4 -4
  50. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +16 -0
  51. package/project/.sdk/tm/js/src/utility/FetcherUtility.js +4 -3
  52. package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +19 -1
  53. package/project/.sdk/tm/js/test/live-entity.js +2 -1
  54. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +15 -0
  55. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +1 -1
  56. package/project/.sdk/tm/lua/feature/secrets_feature.lua +9 -2
  57. package/project/.sdk/tm/lua/feature/test_feature.lua +18 -0
  58. package/project/.sdk/tm/lua/utility/fetcher.lua +11 -25
  59. package/project/.sdk/tm/lua/utility/tls.lua +241 -0
  60. package/project/.sdk/tm/ocaml/sdk_features.ml +18 -1
  61. package/project/.sdk/tm/perl/feature/test_feature.pm +12 -0
  62. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -4
  63. package/project/.sdk/tm/php/feature/TestFeature.php +18 -1
  64. package/project/.sdk/tm/php/utility/Fetcher.php +4 -4
  65. package/project/.sdk/tm/py/pkg/feature/test_feature.py +20 -4
  66. package/project/.sdk/tm/py/pkg/utility/fetcher.py +4 -4
  67. package/project/.sdk/tm/rb/feature/test_feature.rb +14 -1
  68. package/project/.sdk/tm/rb/utility/fetcher.rb +56 -6
  69. package/project/.sdk/tm/rust/feature/test.rs +18 -0
  70. package/project/.sdk/tm/rust/utility/fetcher.rs +4 -4
  71. package/project/.sdk/tm/scala/feature/TestFeature.scala +12 -0
  72. package/project/.sdk/tm/scala/utility/Fetcher.scala +1 -1
  73. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +15 -0
  74. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +1 -1
  75. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +26 -5
  76. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +4 -3
  77. package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +19 -1
  78. package/project/.sdk/tm/ts/test/live-entity.ts +2 -1
  79. package/project/.sdk/tm/zig/feature/test.zig +23 -0
  80. package/project/sdkgen-package.json +1 -1
  81. package/src/cmp/Main.ts +5 -0
  82. package/src/helpers/testPolicy.ts +32 -3
  83. package/src/helpers/useragent.ts +41 -0
  84. package/src/sdkgen.ts +4 -0
  85. package/src/testkit.ts +1 -1
@@ -18,13 +18,13 @@ import {
18
18
  each,
19
19
  buildIdNames,
20
20
  getMatchEntries,
21
- isAuthActive, envName, envToken, entityDataIdField, entityRecordIdField,
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
- liveEntity, liveIdentity,
27
+ liveEntity, liveIdentity, liveRepeatsId, liveLoadComparesId, liveUnrouted,
28
28
  } from '@voxgig/sdkgen'
29
29
 
30
30
  import { perlStringLiteral } from './utility_perl'
@@ -87,16 +87,18 @@ function liveFlowGate(N: string, entity: any, needs: any, identity: any, entidEn
87
87
  `
88
88
  }
89
89
  if (null != needs.discover) {
90
- const match = Object.entries(needs.discover)
90
+ const match = '{' + Object.entries(needs.discover)
91
91
  .map(([k, v]: any) => `'${k}' => $setup->{idmap}{'${v}'}`)
92
92
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
93
- .map(([k, ex]) => `'${k}' => ${perlLit(ex)}`)).join(', ')
93
+ .map(([k, ex]) => `'${k}' => ${perlLit(ex)}`)).join(', ') + '}'
94
+ const omit = needs.unrouted || []
94
95
  out += ` if ($setup->{live}) {
95
96
  my $live_id = $setup->{synthetic_only} ? undef : $setup->{idmap}{${perlLit(identity.key)}};
96
97
  ${undefined === identity.ex ? '' : ` $live_id //= ${perlLit(identity.ex)};
97
- `} ${N}TestRunner::live_pace();
98
+ `}${0 === omit.length ? '' : ` my $live_match = ${match};
99
+ ${omit.map(([name, key]: [string, string]) => ` delete $live_match->{${perlLit(name)}} if ${unsupplied(key)};\n`).join('')}`} ${N}TestRunner::live_pace();
98
100
  ${N}TestRunner::live_existing($setup, LIVE_STRICT, '${label}', '${entity.name}',
99
- sub { $client->${entity.Name}(undef)->list({${match}}, undef) }, ${perlLit(identity.field)}, $live_id)
101
+ sub { $client->${entity.Name}(undef)->list(${0 === omit.length ? match : '$live_match'}, undef) }, ${perlLit(identity.field)}, $live_id)
100
102
  or last BASIC_FLOW;
101
103
  }
102
104
  `
@@ -526,7 +528,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
526
528
  ok(defined $V{${resdatavar}}, '${entity.name} update: data');
527
529
  `)
528
530
  if (hasEntIdU) {
529
- Content(` is($V{${resdatavar}}{${rid(entity)}}, $V{${datavar}_up}{id}, '${entity.name} update: id')${liveDeclared(entity)};
531
+ Content(` is($V{${resdatavar}}{${rid(entity)}}, $V{${datavar}_up}{id}, '${entity.name} update: id')${liveDeclared(liveRepeatsId(entity))};
530
532
  `)
531
533
  }
532
534
 
@@ -589,7 +591,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
589
591
  ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
590
592
  $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});
591
593
  ok(defined $V{${datavar}_load_result}, '${entity.name} load: data');
592
- is($V{${datavar}_load_result}{${rid(entity)}}, $V{${srcdatavar}}{${rid(entity)}}, '${entity.name} load: id')${liveDeclared(entity)};
594
+ is($V{${datavar}_load_result}{${rid(entity)}}, $V{${srcdatavar}}{${rid(entity)}}, '${entity.name} load: id')${liveDeclared(liveLoadComparesId(entity, flow))};
593
595
  `)
594
596
  }
595
597
  else {
@@ -636,9 +638,9 @@ function rid(entity: any): string {
636
638
 
637
639
 
638
640
  // `is` compares string forms, so a number matches the path value naming it;
639
- // a record whose schema has no field for the identity is not compared live.
640
- function liveDeclared(entity: any): string {
641
- return null == entityDataIdField(entity) ? ' unless $setup->{live}' : ''
641
+ // live, it compares only as the live entity harness does.
642
+ function liveDeclared(compares: boolean): string {
643
+ return compares ? '' : ' unless $setup->{live}'
642
644
  }
643
645
 
644
646
 
@@ -666,12 +668,20 @@ function perlLit(value: any): string {
666
668
  // A live step sends each example its route requires and the step leaves unbound.
667
669
  function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
668
670
  const fills = liveStepExamples(entity, step, flow)
669
- return 0 === fills.length ? '' : ` if ($setup->{live}) {
670
- ${fills.map(([k, ex]) => ` $V{${matchvar}}{'${k}'} = ${perlLit(ex)};\n`).join('')} }
671
+ const omit = liveUnrouted(entity, step, flow)
672
+ return 0 === fills.length + omit.length ? '' : ` if ($setup->{live}) {
673
+ ${fills.map(([k, ex]) => ` $V{${matchvar}}{'${k}'} = ${perlLit(ex)};\n`).join('')}${omit.map(([name, key]) =>
674
+ ` delete $V{${matchvar}}{${perlLit(name)}} if ${unsupplied(key)};\n`).join('')} }
671
675
  `
672
676
  }
673
677
 
674
678
 
679
+ // A binding the live route does not take is sent only as *_ENTID gives it.
680
+ function unsupplied(key: string): string {
681
+ return `$setup->{synthetic_only} || !defined $setup->{idmap}{${perlLit(key)}}`
682
+ }
683
+
684
+
675
685
  function parentMatch(step: any, matchvar: string): string {
676
686
  return Object.entries(step.m || {})
677
687
  .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
@@ -7,6 +7,12 @@ import {
7
7
  } from '@voxgig/apidef'
8
8
 
9
9
 
10
+ // A PHP single-quoted literal: no interpolation, whatever the name holds.
11
+ function phpQuote(text: string): string {
12
+ return "'" + String(text).replace(/[\\']/g, '\\$&') + "'"
13
+ }
14
+
15
+
10
16
  const ReadmeExamplesTest = cmp(function ReadmeExamplesTest(props: any) {
11
17
  const { target } = props
12
18
  const { model } = props.ctx$
@@ -22,6 +28,14 @@ const ReadmeExamplesTest = cmp(function ReadmeExamplesTest(props: any) {
22
28
  .map((e: any) => ` ${JSON.stringify(e.Name)} => ${JSON.stringify(e.name)},`)
23
29
  .join('\n')
24
30
 
31
+ // The declared identity field of each entity that names one other than
32
+ // `id`, by fixture key: the mock keys a record by it, so the seed does too.
33
+ const idFieldLines = Object.values(entity)
34
+ .filter((e: any) => e && e.active !== false &&
35
+ 'string' === typeof e.id?.field && '' !== e.id.field && 'id' !== e.id.field)
36
+ .map((e: any) => ` ${phpQuote(e.name)} => ${phpQuote(e.id.field)},`)
37
+ .join('\n')
38
+
25
39
  File({ name: 'ReadmeExamplesTest.' + target.ext }, () => {
26
40
  Content(`<?php
27
41
  declare(strict_types=1);
@@ -68,6 +82,11 @@ class ReadmeExamplesTest extends TestCase
68
82
  ${entityLines}
69
83
  ];
70
84
 
85
+ // Fixture key => the entity's declared identity field, where it is not "id".
86
+ private const ID_FIELDS = [
87
+ ${idFieldLines}
88
+ ];
89
+
71
90
  // Documented SDK method names — used only to recognise the NARROW
72
91
  // signature/method-table "illustration" class.
73
92
  private const METHODS = [
@@ -238,6 +257,16 @@ ${entityLines}
238
257
  $this->assertSame([], $failures, "docs php blocks with syntax errors:\\n" . implode("\\n\\n", $failures));
239
258
  }
240
259
 
260
+ /** The one mock record seeded per entity, keyed as the mock keys it. */
261
+ private static function seedRecord(string $storage): array
262
+ {
263
+ $record = ["id" => "test01"];
264
+ if (isset(self::ID_FIELDS[$storage])) {
265
+ $record[self::ID_FIELDS[$storage]] = "test01";
266
+ }
267
+ return $record;
268
+ }
269
+
241
270
  /**
242
271
  * Build the SDK 'entity' fixture option for the entities a block references,
243
272
  * falling back to seeding all entities when none are named.
@@ -247,12 +276,12 @@ ${entityLines}
247
276
  $refs = [];
248
277
  foreach (self::ENTITIES as $name => $storage) {
249
278
  if (preg_match('/\\$client->' . preg_quote($name, '/') . '\\b/', $block)) {
250
- $refs[$storage] = ["test01" => ["id" => "test01"]];
279
+ $refs[$storage] = ["test01" => self::seedRecord($storage)];
251
280
  }
252
281
  }
253
282
  if (empty($refs)) {
254
283
  foreach (self::ENTITIES as $storage) {
255
- $refs[$storage] = ["test01" => ["id" => "test01"]];
284
+ $refs[$storage] = ["test01" => self::seedRecord($storage)];
256
285
  }
257
286
  }
258
287
  return ["entity" => $refs];
@@ -33,7 +33,7 @@ import {
33
33
  liveFlowNeeds, liveStrict, liveStrictNote,
34
34
  liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
35
35
  liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
36
- liveEntity, liveIdentity,
36
+ liveEntity, liveIdentity, liveRepeatsId, liveLoadComparesId, liveUnrouted,
37
37
  } from '@voxgig/sdkgen'
38
38
 
39
39
  import { formatPhpValue } from './utility_php'
@@ -82,16 +82,18 @@ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string,
82
82
  `
83
83
  }
84
84
  if (null != needs.discover) {
85
- const match = Object.entries(needs.discover)
85
+ const match = '[' + Object.entries(needs.discover)
86
86
  .map(([k, v]: any) => `${JSON.stringify(k)} => $setup["idmap"][${JSON.stringify(v)}] ?? null`)
87
87
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
88
- .map(([k, ex]) => `${JSON.stringify(k)} => ${formatPhpValue(ex)}`)).join(', ')
88
+ .map(([k, ex]) => `${JSON.stringify(k)} => ${formatPhpValue(ex)}`)).join(', ') + ']'
89
+ const omit = needs.unrouted || []
89
90
  out += ` if (!empty($setup["live"])) {
90
91
  $_liveId = empty($setup["synthetic_only"]) ? ($setup["idmap"][${JSON.stringify(identity.key)}] ?? null) : null;
91
92
  ${undefined === identity.ex ? '' : ` $_liveId = $_liveId ?? ${formatPhpValue(identity.ex)};
92
- `} Runner::live_pace();
93
+ `}${0 === omit.length ? '' : ` $_liveMatch = ${match};
94
+ ${liveOmit(omit, '_liveMatch', ' ')}`} Runner::live_pace();
93
95
  Runner::live_existing($setup, self::LIVE_STRICT, ${JSON.stringify(entity.name)},
94
- fn() => $client->${accessor}(null)->list([${match}], null), ${JSON.stringify(identity.field)}, $_liveId);
96
+ fn() => $client->${accessor}(null)->list(${0 === omit.length ? match : '$_liveMatch'}, null), ${JSON.stringify(identity.field)}, $_liveId);
95
97
  }
96
98
  `
97
99
  }
@@ -493,8 +495,10 @@ const generateList: OpGen = (ctx, step, index) => {
493
495
  } else {
494
496
  Content(` $${matchvar} = [
495
497
  `)
498
+ // *_ENTID may not give a binding the live route does not take.
499
+ const unrouted = liveUnrouted(entity, step, flow).map(([name]) => name)
496
500
  for (const [key, val] of matchEntries) {
497
- Content(` "${key}" => $setup["idmap"]["${val}"],
501
+ Content(` "${key}" => $setup["idmap"]["${val}"]${unrouted.includes(key) ? ' ?? null' : ''},
498
502
  `)
499
503
  }
500
504
  Content(` ];
@@ -596,7 +600,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
596
600
  $this->assertNotNull($${resdatavar});
597
601
  `)
598
602
  if (hasEntIdU) {
599
- Content(sameId(entity, `$${resdatavar}[${rid(entity)}] ?? null`, `$${datavar}_up["id"]`))
603
+ Content(sameId(liveRepeatsId(entity), `$${resdatavar}[${rid(entity)}] ?? null`, `$${datavar}_up["id"]`))
600
604
  }
601
605
 
602
606
  if (step.s) {
@@ -658,7 +662,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
658
662
  ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
659
663
  $${datavar}_load_result = Helpers::to_map(is_object($${datavar}_loaded) && method_exists($${datavar}_loaded, 'data_get') ? $${datavar}_loaded->data_get() : $${datavar}_loaded);
660
664
  $this->assertNotNull($${datavar}_load_result);
661
- ${sameId(entity, `$${datavar}_load_result[${rid(entity)}] ?? null`, `$${srcdatavar}[${rid(entity)}]`)}`)
665
+ ${sameId(liveLoadComparesId(entity, flow), `$${datavar}_load_result[${rid(entity)}] ?? null`, `$${srcdatavar}[${rid(entity)}]`)}`)
662
666
  }
663
667
  else {
664
668
  Content(` $${matchvar} = [];
@@ -711,11 +715,11 @@ const LIVE_PACE = ` if (!empty($setup["live"])) {
711
715
  `
712
716
 
713
717
 
714
- // A result's identity matches the one asked for, live only where the
715
- // record's schema has a field to repeat it in.
716
- function sameId(entity: any, result: string, expected: string): string {
718
+ // A result's identity matches the one asked for, live only as the live
719
+ // entity harness compares it.
720
+ function sameId(compares: boolean, result: string, expected: string): string {
717
721
  const check = `$this->assertTrue(Runner::live_same_id(${result}, ${expected}));`
718
- return null == entityDataIdField(entity) ? ` if (empty($setup["live"])) {
722
+ return !compares ? ` if (empty($setup["live"])) {
719
723
  ${check}
720
724
  }
721
725
  ` : ` ${check}
@@ -744,12 +748,23 @@ function fixtureIdentity(entity: any): string {
744
748
  // A live step sends each example its route requires and the step leaves unbound.
745
749
  function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
746
750
  const fills = liveStepExamples(entity, step, flow)
747
- return 0 === fills.length ? '' : ` if (!empty($setup["live"])) {
748
- ${fills.map(([k, ex]) => ` $${matchvar}[${JSON.stringify(k)}] = ${formatPhpValue(ex)};\n`).join('')} }
751
+ const omit = liveUnrouted(entity, step, flow)
752
+ return 0 === fills.length + omit.length ? '' : ` if (!empty($setup["live"])) {
753
+ ${fills.map(([k, ex]) => ` $${matchvar}[${JSON.stringify(k)}] = ${formatPhpValue(ex)};\n`).join('')}${liveOmit(omit, matchvar, ' ')} }
749
754
  `
750
755
  }
751
756
 
752
757
 
758
+ // A binding the live route does not take is sent only as *_ENTID gives it.
759
+ function liveOmit(omit: [string, string][], matchvar: string, indent: string): string {
760
+ return omit.map(([name, key]) =>
761
+ `${indent}if (!empty($setup["synthetic_only"]) || null === ($setup["idmap"][${JSON.stringify(key)}] ?? null)) {
762
+ ${indent} unset($${matchvar}[${JSON.stringify(name)}]);
763
+ ${indent}}
764
+ `).join('')
765
+ }
766
+
767
+
753
768
  function parentMatch(step: any, matchvar: string): string {
754
769
  return Object.entries(step.m || {})
755
770
  .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
@@ -26,6 +26,13 @@ const ReadmeExamplesTest = cmp(function ReadmeExamplesTest(props: any) {
26
26
  .map((e: any) => ` "${nom(e, 'Name')}": "${e.name}",`)
27
27
  .join('\n') + '\n}'
28
28
 
29
+ // The declared identity field of each entity that names one other than
30
+ // `id`, by fixture key: the mock keys a record by it, so the seed does too.
31
+ const idFieldsLiteral = '{' + entities
32
+ .filter((e: any) => 'string' === typeof e.id?.field && '' !== e.id.field && 'id' !== e.id.field)
33
+ .map((e: any) => `${JSON.stringify(e.name)}: ${JSON.stringify(e.id.field)}`)
34
+ .join(', ') + '}'
35
+
29
36
  File({ name: 'test_readme_examples.' + target.ext }, () => {
30
37
  Content(`# ${Name} SDK — documentation python-examples COMPLETENESS gate.
31
38
  #
@@ -106,6 +113,9 @@ _CLIENT_VARS = ("client", "sdk")
106
113
  # The API's capitalised semantic entities -> lowercase fixture key.
107
114
  _ENTITIES = ${entitiesLiteral}
108
115
 
116
+ # Fixture key -> the entity's declared identity field, where it is not "id".
117
+ _ID_FIELDS = ${idFieldsLiteral}
118
+
109
119
  # The three documents held to the gate, tagged by human label.
110
120
  _DOCS = (
111
121
  ("root README", _README),
@@ -377,7 +387,10 @@ def _seed_literal(block):
377
387
  seeded = {}
378
388
  for cap, key in _ENTITIES.items():
379
389
  if ("." + cap + "(") in block:
380
- seeded[key] = {"test01": {"id": "test01"}}
390
+ record = {"id": "test01"}
391
+ if key in _ID_FIELDS:
392
+ record[_ID_FIELDS[key]] = "test01"
393
+ seeded[key] = {"test01": record}
381
394
  return {"entity": seeded}
382
395
 
383
396
 
@@ -32,7 +32,7 @@ import {
32
32
  liveFlowNeeds, liveStrict, liveStrictNote,
33
33
  liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
34
34
  liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
35
- liveEntity, liveIdentity,
35
+ liveEntity, liveIdentity, liveRepeatsId, liveLoadComparesId, liveUnrouted,
36
36
  } from '@voxgig/sdkgen'
37
37
 
38
38
 
@@ -69,17 +69,19 @@ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string):
69
69
  `
70
70
  }
71
71
  if (null != needs.discover) {
72
- const match = Object.entries(needs.discover)
72
+ const match = '{' + Object.entries(needs.discover)
73
73
  .map(([k, v]: any) => `${JSON.stringify(k)}: setup["idmap"].get(${JSON.stringify(v)})`)
74
74
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
75
- .map(([k, ex]) => `${JSON.stringify(k)}: ${pyLit(ex)}`)).join(', ')
75
+ .map(([k, ex]) => `${JSON.stringify(k)}: ${pyLit(ex)}`)).join(', ') + '}'
76
+ const omit = needs.unrouted || []
76
77
  out += ` if setup["live"]:
77
78
  _live_id = None if setup.get("synthetic_only") else setup["idmap"].get(${JSON.stringify(identity.key)})
78
79
  ${undefined === identity.ex ? '' : ` if _live_id is None:
79
80
  _live_id = ${pyLit(identity.ex)}
80
- `} runner.live_pace()
81
+ `}${0 === omit.length ? '' : ` _live_match = ${match}
82
+ ${liveOmit(omit, '_live_match', ' ')}`} runner.live_pace()
81
83
  runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)},
82
- lambda: client.${entity.Name}(None).list({${match}}, None),
84
+ lambda: client.${entity.Name}(None).list(${0 === omit.length ? match : '_live_match'}, None),
83
85
  ${JSON.stringify(identity.field)}, _live_id)
84
86
  `
85
87
  }
@@ -463,8 +465,11 @@ const generateList: OpGen = (ctx, step, index) => {
463
465
  } else {
464
466
  Content(` ${matchvar} = {
465
467
  `)
468
+ // *_ENTID may not give a binding the live route does not take.
469
+ const unrouted = liveUnrouted(entity, step, flow).map(([name]) => name)
466
470
  for (const [key, val] of matchEntries) {
467
- Content(` "${key}": setup["idmap"]["${val}"],
471
+ Content(unrouted.includes(key) ? ` "${key}": setup["idmap"].get("${val}"),
472
+ ` : ` "${key}": setup["idmap"]["${val}"],
468
473
  `)
469
474
  }
470
475
  Content(` }
@@ -565,7 +570,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
565
570
  assert ${resdatavar} is not None
566
571
  `)
567
572
  if (hasEntIdU) {
568
- Content(sameId(entity, `${resdatavar}.get(${rid(entity)})`, `${datavar}_up["id"]`))
573
+ Content(sameId(liveRepeatsId(entity), `${resdatavar}.get(${rid(entity)})`, `${datavar}_up["id"]`))
569
574
  }
570
575
 
571
576
  if (step.s) {
@@ -626,7 +631,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
626
631
  ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
627
632
  ${datavar}_load_result = helpers.to_map(runner.entity_data(${datavar}_loaded))
628
633
  assert ${datavar}_load_result is not None
629
- ${sameId(entity, `${datavar}_load_result.get(${rid(entity)})`, `${srcdatavar}[${rid(entity)}]`)}`)
634
+ ${sameId(liveLoadComparesId(entity, flow), `${datavar}_load_result.get(${rid(entity)})`, `${srcdatavar}[${rid(entity)}]`)}`)
630
635
  }
631
636
  else {
632
637
  Content(` ${matchvar} = {}
@@ -678,11 +683,11 @@ const LIVE_PACE = ` if setup["live"]:
678
683
  `
679
684
 
680
685
 
681
- // A result's identity matches the one asked for, live only where the
682
- // record's schema has a field to repeat it in.
683
- function sameId(entity: any, result: string, expected: string): string {
686
+ // A result's identity matches the one asked for, live only as the live
687
+ // entity harness compares it.
688
+ function sameId(compares: boolean, result: string, expected: string): string {
684
689
  const check = `assert runner.live_same_id(${result}, ${expected})`
685
- return null == entityDataIdField(entity) ? ` if not setup["live"]:
690
+ return !compares ? ` if not setup["live"]:
686
691
  ${check}
687
692
  ` : ` ${check}
688
693
  `
@@ -707,8 +712,17 @@ function fixtureIdentity(entity: any): string {
707
712
  // A live step sends each example its route requires and the step leaves unbound.
708
713
  function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
709
714
  const fills = liveStepExamples(entity, step, flow)
710
- return 0 === fills.length ? '' : ` if setup["live"]:
711
- ${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${pyLit(ex)}\n`).join('')}`
715
+ const omit = liveUnrouted(entity, step, flow)
716
+ return 0 === fills.length + omit.length ? '' : ` if setup["live"]:
717
+ ${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${pyLit(ex)}\n`).join('')}${liveOmit(omit, matchvar, ' ')}`
718
+ }
719
+
720
+
721
+ // A binding the live route does not take is sent only as *_ENTID gives it.
722
+ function liveOmit(omit: [string, string][], matchvar: string, indent: string): string {
723
+ return omit.map(([name, key]) => `${indent}if setup.get("synthetic_only") or setup["idmap"].get(${JSON.stringify(key)}) is None:
724
+ ${indent} ${matchvar}.pop(${JSON.stringify(name)}, None)
725
+ `).join('')
712
726
  }
713
727
 
714
728
 
@@ -22,6 +22,14 @@ const ReadmeExamplesTest = cmp(function ReadmeExamplesTest(props: any) {
22
22
  .map((e: any) => ` ${JSON.stringify(e.Name)} => ${JSON.stringify(e.name)},`)
23
23
  .join('\n')
24
24
 
25
+ // The declared identity field of each entity that names one other than
26
+ // `id`, by fixture key: the mock keys a record by it, so the seed does too.
27
+ const idFieldLines = Object.values(entity)
28
+ .filter((e: any) => e && e.active !== false &&
29
+ 'string' === typeof e.id?.field && '' !== e.id.field && 'id' !== e.id.field)
30
+ .map((e: any) => ` ${JSON.stringify(e.name)} => ${JSON.stringify(e.id.field)},`)
31
+ .join('\n')
32
+
25
33
  File({ name: 'readme_examples_test.' + target.ext }, () => {
26
34
  Content(`# ${model.const.Name} SDK — documentation example COMPLETENESS GATE.
27
35
  #
@@ -71,6 +79,11 @@ class ReadmeExamplesTest < Minitest::Test
71
79
  ${entityLines}
72
80
  }
73
81
 
82
+ # Fixture key => the entity's declared identity field, where it is not "id".
83
+ ID_FIELDS = {
84
+ ${idFieldLines}
85
+ }
86
+
74
87
  # Documented SDK method names — used only to recognise the NARROW
75
88
  # signature/method-table "illustration" class.
76
89
  METHODS = %w[options_map get_utility prepare direct data_get data_set match_get match_set make get_name]
@@ -170,7 +183,11 @@ ${entityLines}
170
183
  refs = ENTITIES.select { |name, _| block =~ /#{CLIENT}\\.#{Regexp.escape(name)}\\b/ }
171
184
  refs = ENTITIES if refs.empty?
172
185
  entity = {}
173
- refs.each_value { |storage| entity[storage] = { "test01" => { "id" => "test01" } } }
186
+ refs.each_value do |storage|
187
+ record = { "id" => "test01" }
188
+ record[ID_FIELDS[storage]] = "test01" if ID_FIELDS.key?(storage)
189
+ entity[storage] = { "test01" => record }
190
+ end
174
191
  { "entity" => entity }.inspect
175
192
  end
176
193
 
@@ -32,7 +32,7 @@ import {
32
32
  liveFlowNeeds, liveStrict, liveStrictNote,
33
33
  liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
34
34
  liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
35
- liveEntity, liveIdentity,
35
+ liveEntity, liveIdentity, liveRepeatsId, liveLoadComparesId, liveUnrouted,
36
36
  } from '@voxgig/sdkgen'
37
37
 
38
38
  import { formatRubyValue } from './utility_rb'
@@ -80,16 +80,18 @@ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string):
80
80
  `
81
81
  }
82
82
  if (null != needs.discover) {
83
- const match = Object.entries(needs.discover)
83
+ const match = '{' + Object.entries(needs.discover)
84
84
  .map(([k, v]: any) => `${JSON.stringify(k)} => setup[:idmap][${JSON.stringify(v)}]`)
85
85
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
86
- .map(([k, ex]) => `${JSON.stringify(k)} => ${formatRubyValue(ex)}`)).join(', ')
86
+ .map(([k, ex]) => `${JSON.stringify(k)} => ${formatRubyValue(ex)}`)).join(', ') + '}'
87
+ const omit = needs.unrouted || []
87
88
  out += ` if setup[:live]
88
89
  _live_id = setup[:synthetic_only] ? nil : setup[:idmap][${JSON.stringify(identity.key)}]
89
90
  ${undefined === identity.ex ? '' : ` _live_id = ${formatRubyValue(identity.ex)} if _live_id.nil?
90
- `} Runner.live_pace
91
+ `}${0 === omit.length ? '' : ` _live_match = ${match}
92
+ ${liveOmit(omit, '_live_match', ' ')}`} Runner.live_pace
91
93
  Runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, _live_id) do
92
- client.${entity.Name}(nil).list({${match}}, nil)
94
+ client.${entity.Name}(nil).list(${0 === omit.length ? match : '_live_match'}, nil)
93
95
  end
94
96
  end
95
97
  `
@@ -586,7 +588,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
586
588
  assert !${resdatavar}.nil?
587
589
  `)
588
590
  if (hasEntIdU) {
589
- Content(sameId(entity, `${resdatavar}[${rid(entity)}]`, `${datavar}_up["id"]`))
591
+ Content(sameId(liveRepeatsId(entity), `${resdatavar}[${rid(entity)}]`, `${datavar}_up["id"]`))
590
592
  }
591
593
 
592
594
  if (step.s) {
@@ -648,7 +650,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
648
650
  ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
649
651
  ${datavar}_load_result = Helpers.to_map(${datavar}_loaded.respond_to?(:data_get) ? ${datavar}_loaded.data_get : ${datavar}_loaded)
650
652
  assert !${datavar}_load_result.nil?
651
- ${sameId(entity, `${datavar}_load_result[${rid(entity)}]`, `${srcdatavar}[${rid(entity)}]`)}`)
653
+ ${sameId(liveLoadComparesId(entity, flow), `${datavar}_load_result[${rid(entity)}]`, `${srcdatavar}[${rid(entity)}]`)}`)
652
654
  }
653
655
  else {
654
656
  Content(` ${matchvar} = {}
@@ -699,10 +701,10 @@ const LIVE_PACE = ` Runner.live_pace if setup[:live]
699
701
  `
700
702
 
701
703
 
702
- // A result's identity matches the one asked for, live only where the
703
- // record's schema has a field to repeat it in.
704
- function sameId(entity: any, result: string, expected: string): string {
705
- return ` assert Runner.live_same_id(${result}, ${expected})${null == entityDataIdField(entity) ? ' unless setup[:live]' : ''}
704
+ // A result's identity matches the one asked for, live only as the live
705
+ // entity harness compares it.
706
+ function sameId(compares: boolean, result: string, expected: string): string {
707
+ return ` assert Runner.live_same_id(${result}, ${expected})${compares ? '' : ' unless setup[:live]'}
706
708
  `
707
709
  }
708
710
 
@@ -725,12 +727,21 @@ function fixtureIdentity(entity: any): string {
725
727
  // A live step sends each example its route requires and the step leaves unbound.
726
728
  function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
727
729
  const fills = liveStepExamples(entity, step, flow)
728
- return 0 === fills.length ? '' : ` if setup[:live]
729
- ${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${formatRubyValue(ex)}\n`).join('')} end
730
+ const omit = liveUnrouted(entity, step, flow)
731
+ return 0 === fills.length + omit.length ? '' : ` if setup[:live]
732
+ ${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${formatRubyValue(ex)}\n`).join('')}${liveOmit(omit, matchvar, ' ')} end
730
733
  `
731
734
  }
732
735
 
733
736
 
737
+ // A binding the live route does not take is sent only as *_ENTID gives it.
738
+ function liveOmit(omit: [string, string][], matchvar: string, indent: string): string {
739
+ return omit.map(([name, key]) =>
740
+ `${indent}${matchvar}.delete(${JSON.stringify(name)}) if setup[:synthetic_only] || setup[:idmap][${JSON.stringify(key)}].nil?
741
+ `).join('')
742
+ }
743
+
744
+
734
745
  function parentMatch(step: any, matchvar: string): string {
735
746
  return Object.entries(step.m || {})
736
747
  .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
@@ -18,13 +18,13 @@ import {
18
18
  each,
19
19
  buildIdNames,
20
20
  getMatchEntries,
21
- isAuthActive, envName, envToken, entityDataIdField, entityRecordIdField,
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,
27
- liveEntity, liveIdentity,
27
+ liveEntity, liveIdentity, liveRepeatsId, liveLoadComparesId, liveUnrouted,
28
28
  } from '@voxgig/sdkgen'
29
29
 
30
30
 
@@ -86,10 +86,11 @@ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string,
86
86
  `
87
87
  }
88
88
  if (null != needs.discover) {
89
- const match = Object.entries(needs.discover)
89
+ const match = 'jo(vec![' + Object.entries(needs.discover)
90
90
  .map(([k, v]: any) => `(${JSON.stringify(k)}, getp(&setup.idmap, ${JSON.stringify(v)}))`)
91
91
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
92
- .map(([k, ex]) => `(${JSON.stringify(k)}, ${rustLit(ex)})`)).join(', ')
92
+ .map(([k, ex]) => `(${JSON.stringify(k)}, ${rustLit(ex)})`)).join(', ') + '])'
93
+ const omit = needs.unrouted || []
93
94
  const given = `if setup.synthetic_only { Value::Noval } else { getp(&setup.idmap, ${JSON.stringify(identity.key)}) }`
94
95
  out += ` if setup.live {
95
96
  ${undefined === identity.ex ? ` let live_id = ${given};
@@ -97,11 +98,12 @@ ${undefined === identity.ex ? ` let live_id = ${given};
97
98
  if live_id.is_noval() || live_id.is_null() {
98
99
  live_id = ${rustLit(identity.ex)};
99
100
  }
100
- `} live_pace();
101
+ `}${0 === omit.length ? '' : ` let live_match = ${match};
102
+ ${liveOmit(omit, 'live_match', ' ')}`} live_pace();
101
103
  if !live_existing(&setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, live_id, || {
102
104
  client
103
105
  .${method}(Value::Noval)
104
- .list(jo(vec![${match}]), Value::Noval)
106
+ .list(${0 === omit.length ? match : 'live_match.clone()'}, Value::Noval)
105
107
  .map(|list| ja(list.iter().map(|e| e.data(None)).collect::<Vec<Value>>()))
106
108
  }) {
107
109
  return;
@@ -651,7 +653,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
651
653
  );
652
654
  `)
653
655
  if (hasEntIdU) {
654
- Content(sameId(entity, `getp(&${resdatavar}, ${rid(entity)})`, `getp(&${datavar}_up, "id")`,
656
+ Content(sameId(liveRepeatsId(entity), `getp(&${resdatavar}, ${rid(entity)})`, `getp(&${datavar}_up, "id")`,
655
657
  'expected update result id to match'))
656
658
  }
657
659
 
@@ -724,7 +726,7 @@ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchva
724
726
  matches!(${datavar}_load_result, Value::Map(_)),
725
727
  "expected load result to be a map"
726
728
  );
727
- ${sameId(entity, `getp(&${datavar}_load_result, ${rid(entity)})`, `getp(&${srcdatavar}, ${rid(entity)})`,
729
+ ${sameId(liveLoadComparesId(entity, flow), `getp(&${datavar}_load_result, ${rid(entity)})`, `getp(&${srcdatavar}, ${rid(entity)})`,
728
730
  'expected load result id to match')}`)
729
731
  }
730
732
  else {
@@ -780,11 +782,11 @@ const LIVE_PACE = ` if setup.live {
780
782
  `
781
783
 
782
784
 
783
- // A result's identity matches the one asked for, live only where the
784
- // record's schema has a field to repeat it in.
785
- function sameId(entity: any, result: string, expected: string, message: string): string {
785
+ // A result's identity matches the one asked for, live only as the live
786
+ // entity harness compares it.
787
+ function sameId(compares: boolean, result: string, expected: string, message: string): string {
786
788
  const check = `assert!(live_same_id(&${result}, &${expected}), ${JSON.stringify(message)});`
787
- return null == entityDataIdField(entity) ? ` if !setup.live {
789
+ return !compares ? ` if !setup.live {
788
790
  ${check}
789
791
  }
790
792
  ` : ` ${check}
@@ -818,12 +820,23 @@ function rustLit(value: any): string {
818
820
  // A live step sends each example its route requires and the step leaves unbound.
819
821
  function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
820
822
  const fills = liveStepExamples(entity, step, flow)
821
- return 0 === fills.length ? '' : ` if setup.live {
822
- ${fills.map(([k, ex]) => ` setp(&${matchvar}, ${JSON.stringify(k)}, ${rustLit(ex)});\n`).join('')} }
823
+ const omit = liveUnrouted(entity, step, flow)
824
+ return 0 === fills.length + omit.length ? '' : ` if setup.live {
825
+ ${fills.map(([k, ex]) => ` setp(&${matchvar}, ${JSON.stringify(k)}, ${rustLit(ex)});\n`).join('')}${liveOmit(omit, matchvar, ' ')} }
823
826
  `
824
827
  }
825
828
 
826
829
 
830
+ // A binding the live route does not take is sent only as *_ENTID gives it.
831
+ function liveOmit(omit: [string, string][], matchvar: string, indent: string): string {
832
+ return omit.map(([name, key]) =>
833
+ `${indent}if setup.synthetic_only || getp(&setup.idmap, ${JSON.stringify(key)}).is_noval() {
834
+ ${indent} vs::del_prop(${matchvar}.clone(), &Value::str(${JSON.stringify(name)}));
835
+ ${indent}}
836
+ `).join('')
837
+ }
838
+
839
+
827
840
  function parentMatch(step: any, matchvar: string): string {
828
841
  return Object.entries(step.m || {})
829
842
  .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))