@voxgig/sdkgen 4.34.2 → 4.34.4

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.
@@ -545,14 +545,14 @@ const generateLoad: OpGen = (ctx, step: any, index) => {
545
545
  }
546
546
  if (hasEntId) {
547
547
  Content(` Value ${matchvar} = vmap({{"id", getp(${srcdatavar}, "id")}});
548
- Value ${datavar}_loaded = ${entvar}->load(Struct::clone(${matchvar}), Value::undef())->data();
548
+ ${parentMatch(step, matchvar, ' ')} Value ${datavar}_loaded = ${entvar}->load(Struct::clone(${matchvar}), Value::undef())->data();
549
549
  Value ${datavar}_load_result = Helpers::toMapAny(${datavar}_loaded);
550
550
  ASSERT_TRUE(${datavar}_load_result.is_map(), "expected load result to be a map");
551
551
  ASSERT_EQ_VAL(getp(${datavar}_load_result, "id"), getp(${srcdatavar}, "id"), "expected load result id to match");
552
552
  `)
553
553
  } else {
554
554
  Content(` Value ${matchvar} = vmap();
555
- Value ${datavar}_loaded = ${entvar}->load(${matchvar}, Value::undef())->data();
555
+ ${parentMatch(step, matchvar, ' ')} Value ${datavar}_loaded = ${entvar}->load(${matchvar}, Value::undef())->data();
556
556
  ASSERT_TRUE(!${datavar}_loaded.is_undef(), "expected load result to be non-nil");
557
557
  `)
558
558
  }
@@ -578,12 +578,27 @@ const generateRemove: OpGen = (ctx, step: any, index) => {
578
578
  }
579
579
  Content(` {
580
580
  Value ${matchvar} = vmap({{"id", getp(${srcdatavar}, "id")}});
581
- ${entvar}->remove(Struct::clone(${matchvar}), Value::undef());
581
+ ${parentMatch(step, matchvar, ' ')} ${entvar}->remove(Struct::clone(${matchvar}), Value::undef());
582
582
  }
583
583
  `)
584
584
  }
585
585
 
586
586
 
587
+ // A child's route names its parents, and an entity no earlier step has
588
+ // filled knows none of them, so the call itself gives each parent id. A live
589
+ // ENTID may key a parent by its field name, the fixture by its own name.
590
+ function parentMatch(step: any, matchvar: string, indent: string): string {
591
+ return Object.entries(step.m || {})
592
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
593
+ .map(([key, val]: any) => `${indent}{
594
+ ${indent} Value parent_id = getp(setup.idmap, "${key}");
595
+ ${indent} if (parent_id.is_undef() || parent_id.is_null()) parent_id = getp(setup.idmap, "${val}");
596
+ ${indent} setp(${matchvar}, "${key}", parent_id);
597
+ ${indent}}
598
+ `).join('')
599
+ }
600
+
601
+
587
602
  const GENERATE_OP: Record<string, OpGen> = {
588
603
  create: generateCreate,
589
604
  list: generateList,
@@ -648,7 +648,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
648
648
  {
649
649
  ["id"] = ${srcdatavar}!["id"],
650
650
  };
651
- var ${datavar}Loaded = ${entvar}.Load(${matchvar}, null);
651
+ ${parentMatch(step, matchvar)} var ${datavar}Loaded = ${entvar}.Load(${matchvar}, null);
652
652
  var ${datavar}LoadResult = Helpers.ToMapAny(${datavar}Loaded is IEntity le ? le.Data() : ${datavar}Loaded);
653
653
  Assert.True(${datavar}LoadResult != null, "expected load result to be a map");
654
654
  Assert.True(StructRunner.DeepEqual(${datavar}LoadResult!["id"], ${srcdatavar}["id"]),
@@ -657,7 +657,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
657
657
  }
658
658
  else {
659
659
  Content(` var ${matchvar} = new Dictionary<string, object?>();
660
- var ${datavar}Loaded = ${entvar}.Load(${matchvar}, null);
660
+ ${parentMatch(step, matchvar)} var ${datavar}Loaded = ${entvar}.Load(${matchvar}, null);
661
661
  Assert.True(${datavar}Loaded != null, "expected load result to be non-null");
662
662
  `)
663
663
  }
@@ -686,11 +686,22 @@ const generateRemove: OpGen = (ctx, step, index) => {
686
686
  {
687
687
  ["id"] = ${srcdatavar}!["id"],
688
688
  };
689
- ${entvar}.Remove(${matchvar}, null);
689
+ ${parentMatch(step, matchvar)} ${entvar}.Remove(${matchvar}, null);
690
690
  `)
691
691
  }
692
692
 
693
693
 
694
+ // A child's route names its parents, and an entity no earlier step has
695
+ // filled knows none of them, so the call itself gives each parent id. A live
696
+ // ENTID may key a parent by its field name, the fixture by its own name.
697
+ function parentMatch(step: any, matchvar: string): string {
698
+ return Object.entries(step.m || {})
699
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
700
+ .map(([key, val]: any) => ` ${matchvar}["${key}"] = StructUtils.GetProp(setup.Idmap, "${key}") ?? StructUtils.GetProp(setup.Idmap, "${val}");
701
+ `).join('')
702
+ }
703
+
704
+
694
705
  const GENERATE_OP: Record<string, OpGen> = {
695
706
  create: generateCreate,
696
707
  list: generateList,
@@ -391,7 +391,8 @@ function liveFlowGate(entity: any, needs: any, strict: boolean, strictConst: str
391
391
  `
392
392
  }
393
393
  if (hasSteps) {
394
- out += '\t\tclient := setup.client\n'
394
+ // A flow whose every step is skipped (a remove with no data id) uses none.
395
+ out += '\t\tclient := setup.client\n\t\t_ = client\n'
395
396
  }
396
397
  if (null != needs.discover) {
397
398
  const match = Object.entries(needs.discover)
@@ -698,7 +699,9 @@ const generateLoad: OpGen = (ctx, step, index) => {
698
699
  Content(` ${matchvar} := map[string]any{
699
700
  "id": ${srcdatavar}["id"],
700
701
  }
701
- ${datavar}Loaded, err := ${entvar}.Load(${matchvar}, nil)
702
+ `)
703
+ parentMatch(step, matchvar)
704
+ Content(` ${datavar}Loaded, err := ${entvar}.Load(${matchvar}, nil)
702
705
  if err != nil {
703
706
  t.Fatalf("load failed: %v", err)
704
707
  }
@@ -713,7 +716,9 @@ const generateLoad: OpGen = (ctx, step, index) => {
713
716
  }
714
717
  else {
715
718
  Content(` ${matchvar} := map[string]any{}
716
- ${datavar}Loaded, err := ${entvar}.Load(${matchvar}, nil)
719
+ `)
720
+ parentMatch(step, matchvar)
721
+ Content(` ${datavar}Loaded, err := ${entvar}.Load(${matchvar}, nil)
717
722
  if err != nil {
718
723
  t.Fatalf("load failed: %v", err)
719
724
  }
@@ -753,7 +758,9 @@ const generateRemove: OpGen = (ctx, step, index) => {
753
758
  Content(` ${matchvar} := map[string]any{
754
759
  "id": ${srcdatavar}["id"],
755
760
  }
756
- _, err ${errOp} ${entvar}.Remove(${matchvar}, nil)
761
+ `)
762
+ parentMatch(step, matchvar)
763
+ Content(` _, err ${errOp} ${entvar}.Remove(${matchvar}, nil)
757
764
  if err != nil {
758
765
  t.Fatalf("remove failed: %v", err)
759
766
  }
@@ -761,6 +768,23 @@ const generateRemove: OpGen = (ctx, step, index) => {
761
768
  }
762
769
 
763
770
 
771
+ // A child's route names its parents, and an entity no earlier step has
772
+ // filled knows none of them, so the call itself gives each parent id. A live
773
+ // ENTID may key a parent by its field name, the fixture by its own name.
774
+ function parentMatch(step: any, matchvar: string) {
775
+ const parents = Object.entries(step.m || {})
776
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
777
+ for (const [key, val] of parents) {
778
+ Content(` if v := setup.idmap["${key}"]; v != nil {
779
+ ${matchvar}["${key}"] = v
780
+ } else {
781
+ ${matchvar}["${key}"] = setup.idmap["${val}"]
782
+ }
783
+ `)
784
+ }
785
+ }
786
+
787
+
764
788
  const GENERATE_OP: Record<string, OpGen> = {
765
789
  create: generateCreate,
766
790
  list: generateList,
@@ -626,7 +626,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
626
626
  `)
627
627
  if (hasEntId) {
628
628
  Content(` ${matchvar}.put("id", ${srcdatavar}.get("id"));
629
- Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
629
+ ${parentMatch(step, matchvar)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
630
630
  Map<String, Object> ${datavar}LoadResult = Helpers.toMapAny(${datavar}Loaded instanceof SdkEntity ? ((SdkEntity) ${datavar}Loaded).data() : ${datavar}Loaded);
631
631
  assertNotNull(${datavar}LoadResult, "expected load result to be a map");
632
632
  assertEquals(${srcdatavar}.get("id"), ${datavar}LoadResult.get("id"),
@@ -634,7 +634,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
634
634
  `)
635
635
  }
636
636
  else {
637
- Content(` Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
637
+ Content(`${parentMatch(step, matchvar)} Object ${datavar}Loaded = ${entvar}.load(${matchvar}, null);
638
638
  assertNotNull(${datavar}Loaded, "expected load result to be non-null");
639
639
  `)
640
640
  }
@@ -661,11 +661,23 @@ const generateRemove: OpGen = (ctx, step, index) => {
661
661
  // Always match the prior-created entity by id to avoid mock-order flakes.
662
662
  Content(` Map<String, Object> ${matchvar} = new LinkedHashMap<>();
663
663
  ${matchvar}.put("id", ${srcdatavar}.get("id"));
664
- ${entvar}.remove(${matchvar}, null);
664
+ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, null);
665
665
  `)
666
666
  }
667
667
 
668
668
 
669
+ // A child's route names its parents, and an entity no earlier step has
670
+ // filled knows none of them, so the call itself gives each parent id. A live
671
+ // ENTID may key a parent by its field name, the fixture by its own name.
672
+ function parentMatch(step: any, matchvar: string): string {
673
+ return Object.entries(step.m || {})
674
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
675
+ .map(([key, val]: any) => ` ${matchvar}.put("${key}", null != setup.idmap.get("${key}")
676
+ ? setup.idmap.get("${key}") : setup.idmap.get("${val}"));
677
+ `).join('')
678
+ }
679
+
680
+
669
681
  const GENERATE_OP: Record<string, OpGen> = {
670
682
  create: generateCreate,
671
683
  list: generateList,
@@ -84,8 +84,18 @@ console.log(${neVar}.data())
84
84
  }
85
85
 
86
86
  if (!hasCall && opnames.includes('load')) {
87
+ // The id and every required parameter: a load without them has no route.
88
+ const idF = entityIdField(exampleEntity)
89
+ const loadItems = opRequestShape(exampleEntity, 'load').items
90
+ .filter((it: any) => !it.optional || it.name === idF)
91
+ .sort((a: any, b: any) =>
92
+ (a.name === idF ? 1 : 0) - (b.name === idF ? 1 : 0))
93
+ .map((it: any) =>
94
+ ` ${jsKey(it.name)}: ${exampleValue(exampleEntity, exampleEntity.op && exampleEntity.op.load, it.name,
95
+ it.name === idF ? 'example_id' : 'example_' + it.name)},`)
96
+ const loadArg = 0 < loadItems.length ? `{\n${loadItems.join('\n')}\n}` : ''
87
97
  Content(`// Load a specific ${eName.toLowerCase()} (returns the entity)
88
- const ${eVar} = await client.${eName}().load()
98
+ const ${eVar} = await client.${eName}().load(${loadArg})
89
99
  console.log(${eVar}.data())
90
100
  `)
91
101
  }
@@ -392,9 +392,11 @@ const generateUpdate: OpGen = (ctx, step, index) => {
392
392
  `)
393
393
  }
394
394
 
395
+ // A parent id is keyed in idmap by its fixture name (step.d's value); a
396
+ // live ENTID may key it by the field name instead.
395
397
  each(step.d, (mi: any) => {
396
398
  if ('id' !== mi.key$) {
397
- Content(` ${datavar} ['${mi.key$}'] = setup.idmap['${mi.key$}']
399
+ Content(` ${datavar}['${mi.key$}'] = setup.idmap['${mi.key$}'] ?? setup.idmap['${mi.val$}']
398
400
  `)
399
401
  }
400
402
  })
@@ -478,13 +480,17 @@ const generateLoad: OpGen = (ctx, step, index) => {
478
480
  if (hasEntId) {
479
481
  Content(` const ${matchvar} = {}
480
482
  ${matchvar}.id = ${srcdatavar}.id
481
- const ${datavar} = (await ${entvar}.load(${matchvar})).data()
483
+ `)
484
+ parentMatch(step, matchvar)
485
+ Content(` const ${datavar} = (await ${entvar}.load(${matchvar})).data()
482
486
  assert(${datavar}.id === ${srcdatavar}.id)
483
487
  `)
484
488
  }
485
489
  else {
486
490
  Content(` const ${matchvar} = {}
487
- const ${datavar} = (await ${entvar}.load(${matchvar})).data()
491
+ `)
492
+ parentMatch(step, matchvar)
493
+ Content(` const ${datavar} = (await ${entvar}.load(${matchvar})).data()
488
494
  assert(null != ${datavar})
489
495
  `)
490
496
  }
@@ -520,11 +526,24 @@ const generateRemove: OpGen = (ctx, step, index) => {
520
526
  Content(` ${matchvar}.id = ${srcdatavar}.id
521
527
  `)
522
528
  }
529
+ parentMatch(step, matchvar)
523
530
  Content(` await ${entvar}.remove(${matchvar})
524
531
  `)
525
532
  }
526
533
 
527
534
 
535
+ // A child's route names its parents, and an entity no earlier step has
536
+ // filled knows none of them, so the call itself gives each parent id.
537
+ function parentMatch(step: any, matchvar: string) {
538
+ each(step.m, (mi: any) => {
539
+ if ('id' !== mi.key$ && !mi.key$.endsWith('$')) {
540
+ Content(` ${matchvar}['${mi.key$}'] = setup.idmap['${mi.key$}'] ?? setup.idmap['${mi.val$}']
541
+ `)
542
+ }
543
+ })
544
+ }
545
+
546
+
528
547
  const GENERATE_OP: Record<string, OpGen> = {
529
548
  create: generateCreate,
530
549
  list: generateList,
@@ -570,14 +570,14 @@ const generateLoad: OpGen = (ctx, step, index) => {
570
570
  `)
571
571
  if (hasEntId) {
572
572
  Content(` ${matchvar}["id"] = ${srcdatavar}["id"]
573
- val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
573
+ ${parentMatch(step, matchvar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
574
574
  val ${datavar}LoadResult = Helpers.toMapAny(if (${datavar}Loaded is SdkEntity) ${datavar}Loaded.data() else ${datavar}Loaded) ?: linkedMapOf()
575
575
  assertNotNull(${datavar}LoadResult, "expected load result to be a map")
576
576
  assertEquals(${srcdatavar}["id"], ${datavar}LoadResult["id"],
577
577
  "expected load result id to match")
578
578
  `)
579
579
  } else {
580
- Content(` val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
580
+ Content(`${parentMatch(step, matchvar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
581
581
  assertNotNull(${datavar}Loaded, "expected load result to be non-null")
582
582
  `)
583
583
  }
@@ -603,11 +603,22 @@ const generateRemove: OpGen = (ctx, step, index) => {
603
603
  }
604
604
  Content(` val ${matchvar} = linkedMapOf<String, Any?>()
605
605
  ${matchvar}["id"] = ${srcdatavar}["id"]
606
- ${entvar}.remove(${matchvar}, null)
606
+ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, null)
607
607
  `)
608
608
  }
609
609
 
610
610
 
611
+ // A child's route names its parents, and an entity no earlier step has
612
+ // filled knows none of them, so the call itself gives each parent id. A live
613
+ // ENTID may key a parent by its field name, the fixture by its own name.
614
+ function parentMatch(step: any, matchvar: string): string {
615
+ return Object.entries(step.m || {})
616
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
617
+ .map(([key, val]: any) => ` ${matchvar}["${key}"] = setup.idmap?.get("${key}") ?: setup.idmap?.get("${val}")
618
+ `).join('')
619
+ }
620
+
621
+
611
622
  const GENERATE_OP: Record<string, OpGen> = {
612
623
  create: generateCreate,
613
624
  list: generateList,
@@ -597,7 +597,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
597
597
  Content(` local ${matchvar} = {
598
598
  id = ${srcdatavar}["id"],
599
599
  }
600
- local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
600
+ ${parentMatch(step, matchvar)} local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
601
601
  assert.is_nil(err)
602
602
  local ${datavar}_load_result = helpers.to_map(type(${datavar}_loaded) == 'table' and ${datavar}_loaded.data_get and ${datavar}_loaded:data_get() or ${datavar}_loaded)
603
603
  assert.is_not_nil(${datavar}_load_result)
@@ -606,7 +606,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
606
606
  }
607
607
  else {
608
608
  Content(` local ${matchvar} = {}
609
- local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
609
+ ${parentMatch(step, matchvar)} local ${datavar}_loaded, err = ${entvar}:load(${matchvar}, nil)
610
610
  assert.is_nil(err)
611
611
  assert.is_not_nil(${datavar}_loaded)
612
612
  `)
@@ -638,12 +638,23 @@ const generateRemove: OpGen = (ctx, step, index) => {
638
638
  Content(` local ${matchvar} = {
639
639
  id = ${srcdatavar}["id"],
640
640
  }
641
- local _, err = ${entvar}:remove(${matchvar}, nil)
641
+ ${parentMatch(step, matchvar)} local _, err = ${entvar}:remove(${matchvar}, nil)
642
642
  assert.is_nil(err)
643
643
  `)
644
644
  }
645
645
 
646
646
 
647
+
648
+ // A child's route names its parents, and an entity no earlier step has
649
+ // filled knows none of them, so the call itself gives each parent id. A live
650
+ // ENTID may key a parent by its field name, the fixture by its own name.
651
+ function parentMatch(step: any, matchvar: string): string {
652
+ return Object.entries(step.m || {})
653
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
654
+ .map(([key, val]: any) => ` ${matchvar}["${key}"] = setup.idmap["${key}"] or setup.idmap["${val}"]
655
+ `).join('')
656
+ }
657
+
647
658
  const GENERATE_OP: Record<string, OpGen> = {
648
659
  create: generateCreate,
649
660
  list: generateList,
@@ -531,7 +531,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
531
531
  Content(` $V{${matchvar}} = {
532
532
  'id' => $V{${srcdatavar}}{id},
533
533
  };
534
- $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
534
+ ${parentMatch(step, matchvar)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
535
535
  $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});
536
536
  ok(defined $V{${datavar}_load_result}, '${entity.name} load: data');
537
537
  is($V{${datavar}_load_result}{id}, $V{${srcdatavar}}{id}, '${entity.name} load: id');
@@ -539,7 +539,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
539
539
  }
540
540
  else {
541
541
  Content(` $V{${matchvar}} = {};
542
- $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
542
+ ${parentMatch(step, matchvar)} $V{${datavar}_loaded} = $V{${entvar}}->load($V{${matchvar}}, undef);
543
543
  ok(defined $V{${datavar}_loaded}, '${entity.name} load: data');
544
544
  `)
545
545
  }
@@ -567,12 +567,23 @@ const generateRemove: OpGen = (ctx, step, index) => {
567
567
  Content(` $V{${matchvar}} = {
568
568
  'id' => $V{${srcdatavar}}{id},
569
569
  };
570
- $V{${entvar}}->remove($V{${matchvar}}, undef);
570
+ ${parentMatch(step, matchvar)} $V{${entvar}}->remove($V{${matchvar}}, undef);
571
571
  pass('${entity.name} remove: completed');
572
572
  `)
573
573
  }
574
574
 
575
575
 
576
+ // A child's route names its parents, and an entity no earlier step has
577
+ // filled knows none of them, so the call itself gives each parent id. A live
578
+ // ENTID may key a parent by its field name, the fixture by its own name.
579
+ function parentMatch(step: any, matchvar: string): string {
580
+ return Object.entries(step.m || {})
581
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
582
+ .map(([key, val]: any) => ` $V{${matchvar}}{'${key}'} = $setup->{idmap}{'${key}'} // $setup->{idmap}{'${val}'};
583
+ `).join('')
584
+ }
585
+
586
+
576
587
  const GENERATE_OP: Record<string, OpGen> = {
577
588
  create: generateCreate,
578
589
  list: generateList,
@@ -600,7 +600,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
600
600
  Content(` $${matchvar} = [
601
601
  "id" => $${srcdatavar}["id"],
602
602
  ];
603
- $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
603
+ ${parentMatch(step, matchvar)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
604
604
  $${datavar}_load_result = Helpers::to_map(is_object($${datavar}_loaded) && method_exists($${datavar}_loaded, 'data_get') ? $${datavar}_loaded->data_get() : $${datavar}_loaded);
605
605
  $this->assertNotNull($${datavar}_load_result);
606
606
  $this->assertEquals($${datavar}_load_result["id"], $${srcdatavar}["id"]);
@@ -608,7 +608,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
608
608
  }
609
609
  else {
610
610
  Content(` $${matchvar} = [];
611
- $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
611
+ ${parentMatch(step, matchvar)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
612
612
  $this->assertNotNull($${datavar}_loaded);
613
613
  `)
614
614
  }
@@ -639,11 +639,22 @@ const generateRemove: OpGen = (ctx, step, index) => {
639
639
  Content(` $${matchvar} = [
640
640
  "id" => $${srcdatavar}["id"],
641
641
  ];
642
- $${entvar}->remove($${matchvar}, null);
642
+ ${parentMatch(step, matchvar)} $${entvar}->remove($${matchvar}, null);
643
643
  `)
644
644
  }
645
645
 
646
646
 
647
+
648
+ // A child's route names its parents, and an entity no earlier step has
649
+ // filled knows none of them, so the call itself gives each parent id. A live
650
+ // ENTID may key a parent by its field name, the fixture by its own name.
651
+ function parentMatch(step: any, matchvar: string): string {
652
+ return Object.entries(step.m || {})
653
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
654
+ .map(([key, val]: any) => ` $${matchvar}["${key}"] = $setup["idmap"]["${key}"] ?? $setup["idmap"]["${val}"] ?? null;
655
+ `).join('')
656
+ }
657
+
647
658
  const GENERATE_OP: Record<string, OpGen> = {
648
659
  create: generateCreate,
649
660
  list: generateList,
@@ -573,7 +573,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
573
573
  Content(` ${matchvar} = {
574
574
  "id": ${srcdatavar}["id"],
575
575
  }
576
- ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
576
+ ${parentMatch(step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
577
577
  ${datavar}_load_result = helpers.to_map(runner.entity_data(${datavar}_loaded))
578
578
  assert ${datavar}_load_result is not None
579
579
  assert ${datavar}_load_result["id"] == ${srcdatavar}["id"]
@@ -581,7 +581,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
581
581
  }
582
582
  else {
583
583
  Content(` ${matchvar} = {}
584
- ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
584
+ ${parentMatch(step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
585
585
  assert ${datavar}_loaded is not None
586
586
  `)
587
587
  }
@@ -612,11 +612,22 @@ const generateRemove: OpGen = (ctx, step, index) => {
612
612
  Content(` ${matchvar} = {
613
613
  "id": ${srcdatavar}["id"],
614
614
  }
615
- ${entvar}.remove(${matchvar}, None)
615
+ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, None)
616
616
  `)
617
617
  }
618
618
 
619
619
 
620
+
621
+ // A child's route names its parents, and an entity no earlier step has
622
+ // filled knows none of them, so the call itself gives each parent id. A live
623
+ // ENTID may key a parent by its field name, the fixture by its own name.
624
+ function parentMatch(step: any, matchvar: string): string {
625
+ return Object.entries(step.m || {})
626
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
627
+ .map(([key, val]: any) => ` ${matchvar}["${key}"] = setup["idmap"].get("${key}") or setup["idmap"].get("${val}")
628
+ `).join('')
629
+ }
630
+
620
631
  const GENERATE_OP: Record<string, OpGen> = {
621
632
  create: generateCreate,
622
633
  list: generateList,
@@ -593,7 +593,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
593
593
  Content(` ${matchvar} = {
594
594
  "id" => ${srcdatavar}["id"],
595
595
  }
596
- ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
596
+ ${parentMatch(step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
597
597
  ${datavar}_load_result = Helpers.to_map(${datavar}_loaded.respond_to?(:data_get) ? ${datavar}_loaded.data_get : ${datavar}_loaded)
598
598
  assert !${datavar}_load_result.nil?
599
599
  assert_equal ${datavar}_load_result["id"], ${srcdatavar}["id"]
@@ -601,7 +601,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
601
601
  }
602
602
  else {
603
603
  Content(` ${matchvar} = {}
604
- ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
604
+ ${parentMatch(step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
605
605
  assert !${datavar}_loaded.nil?
606
606
  `)
607
607
  }
@@ -632,11 +632,22 @@ const generateRemove: OpGen = (ctx, step, index) => {
632
632
  Content(` ${matchvar} = {
633
633
  "id" => ${srcdatavar}["id"],
634
634
  }
635
- ${entvar}.remove(${matchvar}, nil)
635
+ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, nil)
636
636
  `)
637
637
  }
638
638
 
639
639
 
640
+
641
+ // A child's route names its parents, and an entity no earlier step has
642
+ // filled knows none of them, so the call itself gives each parent id. A live
643
+ // ENTID may key a parent by its field name, the fixture by its own name.
644
+ function parentMatch(step: any, matchvar: string): string {
645
+ return Object.entries(step.m || {})
646
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
647
+ .map(([key, val]: any) => ` ${matchvar}["${key}"] = setup[:idmap]["${key}"] || setup[:idmap]["${val}"]
648
+ `).join('')
649
+ }
650
+
640
651
  const GENERATE_OP: Record<string, OpGen> = {
641
652
  create: generateCreate,
642
653
  list: generateList,
@@ -662,7 +662,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
662
662
  }
663
663
  if (hasEntId) {
664
664
  Content(` let ${matchvar} = jo(vec![("id", getp(&${srcdatavar}, "id"))]);
665
- let ${datavar}_loaded = ${entvar}
665
+ ${parentMatch(step, matchvar)} let ${datavar}_loaded = ${entvar}
666
666
  .load(${matchvar}.clone(), Value::Noval)
667
667
  .expect("load failed");
668
668
  let ${datavar}_load_result = to_map(&${datavar}_loaded.data(None));
@@ -679,7 +679,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
679
679
  }
680
680
  else {
681
681
  Content(` let ${matchvar} = Value::empty_map();
682
- let ${datavar}_loaded = ${entvar}
682
+ ${parentMatch(step, matchvar)} let ${datavar}_loaded = ${entvar}
683
683
  .load(${matchvar}.clone(), Value::Noval)
684
684
  .expect("load failed");
685
685
  // load resolves to the ENTITY; the record is reached through data().
@@ -711,13 +711,27 @@ const generateRemove: OpGen = (ctx, step, index) => {
711
711
  }
712
712
  // Always match the prior-created entity by id to avoid mock-order flakes.
713
713
  Content(` let ${matchvar} = jo(vec![("id", getp(&${srcdatavar}, "id"))]);
714
- ${entvar}
714
+ ${parentMatch(step, matchvar)} ${entvar}
715
715
  .remove(${matchvar}.clone(), Value::Noval)
716
716
  .expect("remove failed");
717
717
  `)
718
718
  }
719
719
 
720
720
 
721
+ // A child's route names its parents, and an entity no earlier step has
722
+ // filled knows none of them, so the call itself gives each parent id. A live
723
+ // ENTID may key a parent by its field name, the fixture by its own name.
724
+ function parentMatch(step: any, matchvar: string): string {
725
+ return Object.entries(step.m || {})
726
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
727
+ .map(([key, val]: any) => ` setp(&${matchvar}, "${key}", match getp(&setup.idmap, "${key}") {
728
+ v if v.is_nullish() => getp(&setup.idmap, "${val}"),
729
+ v => v,
730
+ });
731
+ `).join('')
732
+ }
733
+
734
+
721
735
  const GENERATE_OP: Record<string, OpGen> = {
722
736
  create: generateCreate,
723
737
  list: generateList,
@@ -364,13 +364,13 @@ const generateLoad: OpGen = (ctx, step, index) => {
364
364
  `)
365
365
  if (hasDataId) {
366
366
  Content(` ${matchvar}.put("id", ${srcdatavar}.get("id"))
367
- val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
367
+ ${parentMatch(step, matchvar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
368
368
  val ${datavar}LoadResult = Helpers.toMapAny(${datavar}Loaded match { case e: SdkEntity => e.data(); case o => o })
369
369
  rep.check("${ENTLOWER}.load.map", ${datavar}LoadResult != null, "expected load result to be a map")
370
370
  rep.eq("${ENTLOWER}.load.id", ${srcdatavar}.get("id"), ${datavar}LoadResult.get("id"))
371
371
  `)
372
372
  } else {
373
- Content(` val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
373
+ Content(`${parentMatch(step, matchvar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
374
374
  rep.check("${ENTLOWER}.load.nonnull", ${datavar}Loaded != null, "expected load result to be non-null")
375
375
  `)
376
376
  }
@@ -402,11 +402,21 @@ const generateRemove: OpGen = (ctx, step, index) => {
402
402
  }
403
403
  Content(` val ${matchvar} = new LinkedHashMap[String, Object]()
404
404
  ${matchvar}.put("id", ${srcdatavar}.get("id"))
405
- ${entvar}.remove(${matchvar}, null)
405
+ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, null)
406
406
  `)
407
407
  }
408
408
 
409
409
 
410
+ // A child's route names its parents, and an entity no earlier step has
411
+ // filled knows none of them, so the call itself gives each parent id.
412
+ function parentMatch(step: any, matchvar: string): string {
413
+ return Object.entries(step.m || {})
414
+ .filter(([k]: any) => k !== 'id' && !k.endsWith('$'))
415
+ .map(([key, val]: any) => ` ${matchvar}.put("${key}", Option(idmap.get("${key}")).getOrElse(idmap.get("${val}")))
416
+ `).join('')
417
+ }
418
+
419
+
410
420
  const GENERATE_OP: Record<string, OpGen> = {
411
421
  create: generateCreate,
412
422
  list: generateList,
@@ -96,8 +96,18 @@ console.log(${neVar}.data())
96
96
  }
97
97
 
98
98
  if (!hasCall && opnames.includes('load')) {
99
+ // The id and every required parameter: a load without them has no route.
100
+ const idF = entityIdField(exampleEntity)
101
+ const loadItems = opRequestShape(exampleEntity, 'load').items
102
+ .filter((it: any) => !it.optional || it.name === idF)
103
+ .sort((a: any, b: any) =>
104
+ (a.name === idF ? 1 : 0) - (b.name === idF ? 1 : 0))
105
+ .map((it: any) =>
106
+ ` ${jsKey(it.name)}: ${exampleValue(exampleEntity, exampleEntity.op && exampleEntity.op.load, it.name,
107
+ it.name === idF ? 'example_id' : 'example_' + it.name)},`)
108
+ const loadArg = 0 < loadItems.length ? `{\n${loadItems.join('\n')}\n}` : ''
99
109
  Content(`// Load a specific ${eName.toLowerCase()} (returns the entity, ${/^[aeiou]/i.test(eName) ? 'an' : 'a'} ${eName}Entity)
100
- const ${eVar} = await client.${eName}().load()
110
+ const ${eVar} = await client.${eName}().load(${loadArg})
101
111
  console.log(${eVar}.data())
102
112
  `)
103
113
  hasCall = true