1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
use crate::{
schemasync::TableConfig,
schemasync::mockmake::Mockmaker,
schemasync::mockmake::coordinate::CoordinationId,
schemasync::mockmake::format::Format,
types::{EnumRepresentation, FieldType, ForeignTypeRegistry, StructField, VariantData},
};
use bon::Builder;
#[cfg(feature = "mockmake")]
use chrono_tz::TZ_VARIANTS;
use convert_case::{Case, Casing};
use rand::{RngExt, rngs::ThreadRng, seq::IndexedRandom};
use std::collections::BTreeSet;
use tracing;
// The context struct is now simple again, with a direct reference.
#[derive(Clone)]
struct Frame<'a> {
field: &'a StructField,
table_config: &'a TableConfig,
field_type: &'a FieldType,
field_path: String, // Track the full path for nested fields
visited_types: BTreeSet<String>, // Track visited types to avoid infinite recursion
}
enum WorkItem<'a> {
Generate(Frame<'a>),
AssembleVec {
count: usize,
},
AssembleTuple {
count: usize,
},
AssembleStruct {
field_names: Vec<String>,
},
AssembleMap {
count: usize,
},
AssembleEnum,
WrapInVariantKey {
variant_name: String,
},
AssembleTaggedStruct {
tag_key: String,
tag_value: String,
field_names: Vec<String>,
},
}
#[derive(Debug, Builder)]
pub struct FieldValueGenerator<'a> {
mockmaker: &'a Mockmaker<'a>,
table_config: &'a TableConfig,
field: &'a StructField,
id_index: &'a usize,
registry: &'a ForeignTypeRegistry,
}
impl<'a> FieldValueGenerator<'a> {
// Was having stack overflow so created an iterative version
pub fn run(&self) -> String {
let mut work_stack: Vec<WorkItem<'a>> = Vec::new();
let mut value_stack: Vec<String> = Vec::new();
let mut rng = rand::rng();
let initial_context = Frame {
field: self.field,
table_config: self.table_config,
field_type: &self.field.field_type,
field_path: self.field.field_name.clone(),
visited_types: BTreeSet::new(),
};
work_stack.push(WorkItem::Generate(initial_context));
while let Some(work_item) = work_stack.pop() {
match work_item {
WorkItem::Generate(ctx) => {
// Tier 0: WASM plugin override (field-level or table-level)
#[cfg(feature = "wasm-plugins")]
let _plugin_name: Option<&String> = ctx.field.mock_plugin.as_ref().or(self
.table_config
.mock_generation_config
.as_ref()
.and_then(|c| c.plugin.as_ref()));
#[cfg(feature = "wasm-plugins")]
if let Some(plugin_name) = _plugin_name {
if let Some(ref pm_cell) = self.mockmaker.plugin_manager {
let pm = &mut *pm_cell.borrow_mut();
let input = super::plugin_types::PluginFieldInput {
table_name: self.table_config.table_name.to_string(),
field_name: ctx.field_path.clone(),
field_type: format!("{:?}", ctx.field_type),
record_index: *self.id_index,
total_records: self
.table_config
.mock_generation_config
.as_ref()
.map(|c| c.n)
.unwrap_or(10),
record_id: format!(
"{}:{}",
self.table_config.table_name, self.id_index
),
};
match pm.generate_field_value(plugin_name, &input) {
Ok(value) => {
value_stack.push(value);
continue;
}
Err(e) => {
let msg = e.to_string();
if msg.contains("skip") {
tracing::trace!(
"Plugin '{}' skipped field '{}', using default",
plugin_name,
ctx.field_path,
);
} else {
tracing::warn!(
"Plugin '{}' failed for field '{}': {}, falling back",
plugin_name,
ctx.field_path,
e
);
}
}
}
} else {
tracing::warn!(
"Field '{}' references plugin '{}' but wasm-plugins feature has no PluginManager initialized",
ctx.field_path,
plugin_name
);
}
}
// Tier 0 (no wasm-plugins feature): warn and fall through
#[cfg(not(feature = "wasm-plugins"))]
if ctx.field.mock_plugin.is_some()
|| self
.table_config
.mock_generation_config
.as_ref()
.and_then(|c| c.plugin.as_ref())
.is_some()
{
tracing::warn!(
"Field '{}' has a plugin configured but wasm-plugins feature is not enabled",
ctx.field_path
);
}
if let Some(coordinated_value) = self.mockmaker.coordinated_values.get(
&CoordinationId::builder()
.field_name(ctx.field_path.clone())
.table_name(self.table_config.table_name.to_string())
.build(),
) {
value_stack.push(coordinated_value.to_string());
} else if let Some(format) = &ctx.field.format {
value_stack.push(self.handle_format(format));
} else {
match ctx.field_type {
FieldType::String => {
value_stack.push(format!("'{}'", Mockmaker::random_string(8)))
}
FieldType::Char => value_stack
.push(format!("'{}'", rng.random_range(32u8..=126u8) as char)),
FieldType::Bool => {
value_stack.push(format!("{}", rng.random_bool(0.5)))
}
FieldType::Unit => value_stack.push("NONE".to_string()),
FieldType::F32 | FieldType::F64 => {
value_stack.push(format!("{:.2}f", rng.random_range(0.0..100.0)))
}
FieldType::I8
| FieldType::I16
| FieldType::I32
| FieldType::I64
| FieldType::I128
| FieldType::Isize => {
value_stack.push(format!("{}", rng.random_range(0..100)))
}
FieldType::U8
| FieldType::U16
| FieldType::U32
| FieldType::U64
| FieldType::U128
| FieldType::Usize => {
value_stack.push(format!("{}", rng.random_range(0..100)))
}
FieldType::Option(inner_type) => {
if rng.random_bool(0.5) {
value_stack.push("null".to_string());
} else {
work_stack.push(WorkItem::Generate(Frame {
field_type: inner_type,
..ctx.clone()
}));
}
}
FieldType::Vec(inner_type) => {
let count = rng.random_range(2..10);
work_stack.push(WorkItem::AssembleVec { count });
for _ in 0..count {
work_stack.push(WorkItem::Generate(Frame {
field_type: inner_type,
..ctx.clone()
}));
}
}
FieldType::Tuple(types) => {
work_stack.push(WorkItem::AssembleTuple { count: types.len() });
for inner_type in types.iter().rev() {
work_stack.push(WorkItem::Generate(Frame {
field_type: inner_type,
..ctx.clone()
}));
}
}
FieldType::Struct(fields) => {
let field_names: Vec<String> =
fields.iter().map(|(name, _)| name.clone()).collect();
work_stack.push(WorkItem::AssembleStruct { field_names });
for (nested_field_name, ftype) in fields.iter().rev() {
work_stack.push(WorkItem::Generate(Frame {
field_type: ftype,
field_path: format!(
"{}.{}",
ctx.field_path.clone(),
nested_field_name
),
..ctx.clone()
}));
}
}
FieldType::HashMap(key_ft, value_ft)
| FieldType::BTreeMap(key_ft, value_ft) => {
let count = rng.random_range(0..3);
work_stack.push(WorkItem::AssembleMap { count });
for _ in 0..count {
work_stack.push(WorkItem::Generate(Frame {
field_type: value_ft,
..ctx.clone()
}));
work_stack.push(WorkItem::Generate(Frame {
field_type: key_ft,
..ctx.clone()
}));
}
}
FieldType::RecordLink(inner_type) => {
// For relation tables, in/out fields must use relation.from/to
// to stay in sync with the DEFINE TABLE ... FROM ... TO ... clause.
if ctx.table_config.relation.is_some()
&& (ctx.field.field_name == "in"
|| ctx.field.field_name == "out")
{
value_stack.push(self.handle_record_id(
&ctx.field.field_name,
&ctx.table_config.table_name,
ctx.table_config,
&mut rng,
));
continue;
}
// RecordLink should ultimately reference a persistable table.
// If the inner type is an enum (persistable struct union), choose a variant that maps to a table.
match inner_type.as_ref() {
FieldType::Other(type_name) => {
// Helper: resolve a type name to a table key in self.mockmaker.tables
// Closure uses RNG; mark as mut so it implements FnMut
let mut resolve_table = |name: &str,
tables: &std::collections::BTreeMap<String, crate::schemasync::table::TableConfig>,
enums: &std::collections::BTreeMap<String, crate::types::TaggedUnion>,
| -> Option<String> {
// 1) Direct match: type name corresponds to a table
let snake = name.to_case(Case::Snake);
if tables.contains_key(&snake) {
return Some(snake);
}
// 2) Enum (persistable struct union): pick a variant that maps to a table
if let Some(tagged) = enums.get(name) {
// Collect candidate table names from variants
let mut candidates: Vec<String> = Vec::new();
for v in &tagged.variants {
if let Some(data) = &v.data {
match data {
crate::types::VariantData::InlineStruct(enum_struct) => {
let t = enum_struct.struct_name.to_case(Case::Snake);
if tables.contains_key(&t) {
candidates.push(t);
}
}
crate::types::VariantData::DataStructureRef(fty) => {
if let crate::types::FieldType::Other(inner_name) = fty {
let t = inner_name.to_case(Case::Snake);
if tables.contains_key(&t) {
candidates.push(t);
}
}
}
}
}
}
if !candidates.is_empty() {
// Choose a random candidate
let idx = rng.random_range(0..candidates.len());
return Some(candidates[idx].clone());
}
}
None
};
if let Some(table_key) = resolve_table(
type_name,
self.mockmaker.tables,
self.mockmaker.enums,
) {
// Generate a record ID for the resolved table
if let Some(possible_ids) =
self.mockmaker.id_map.get(&table_key)
{
if !possible_ids.is_empty() {
let id = format!(
"r'{}'",
possible_ids[rng
.random_range(0..possible_ids.len())]
);
value_stack.push(id);
} else {
panic!(
"No IDs generated for table {} in RecordLink",
table_key
);
}
} else {
// Fallback: synthesize a plausible ID using current index
let id =
format!("r'{}:{}'", table_key, &self.id_index);
value_stack.push(id);
}
} else {
panic!(
"RecordLink references type '{}' which does not map to a persistable table or persistable union in field {}",
type_name, ctx.field.field_name
);
}
}
_ => {
panic!(
"RecordLink contains non-Other type {:?} in field {}. RecordLink should reference a type name or a persistable union.",
inner_type, ctx.field.field_name
);
}
}
}
FieldType::Other(type_name) => {
// Check if this is a foreign type with a mock strategy
if let Some(ftc) = self.registry.lookup(type_name) {
let strategy = ftc.mock_strategy.as_str();
match strategy {
// SurrealQL-specific formats that need special encoding
"datetime" => {
value_stack.push(format!(
"d'{}'",
chrono::Utc::now().to_rfc3339()
));
continue;
}
"duration" => {
value_stack.push(format!(
"duration::from_nanos({})",
rng.random_range(0..86_400_000_000_000i64)
));
continue;
}
"timezone" => {
#[cfg(feature = "mockmake")]
{
let tz = &TZ_VARIANTS
[rng.random_range(0..TZ_VARIANTS.len())];
value_stack.push(format!("'{}'", tz.name()));
}
#[cfg(not(feature = "mockmake"))]
{
let timezones = [
"UTC",
"America/New_York",
"Europe/London",
"Asia/Tokyo",
];
value_stack.push(format!(
"'{}'",
timezones[rng.random_range(0..timezones.len())]
));
}
continue;
}
"decimal" => {
value_stack.push(format!(
"{:.3}dec",
rng.random_range(0.0..100.0)
));
continue;
}
"float" => {
value_stack.push(format!(
"{:.2}f",
rng.random_range(0.0..100.0)
));
continue;
}
"record_id" => {
value_stack.push(self.handle_record_id(
&ctx.field.field_name,
&ctx.table_config.table_name,
ctx.table_config,
&mut rng,
));
continue;
}
"object" => {
value_stack.push("{}".to_string());
continue;
}
_ => {
if let Ok(fmt) = strategy.parse::<Format>() {
let val = fmt.generate_formatted_value();
value_stack.push(format!("'{}'", val));
continue;
}
// Fall through to existing Other logic
}
}
}
// Check if we've already visited this type to avoid infinite recursion
if ctx.visited_types.contains(type_name) {
tracing::debug!(
type_name = %type_name,
field_path = %ctx.field_path,
"Detected circular reference, generating null"
);
value_stack.push("null".to_string());
continue;
}
let snake_case_name = type_name.to_case(Case::Snake);
if let Some((table_name, _)) = self
.mockmaker
.tables
.iter()
.find(|(_, tc)| &tc.table_name == type_name)
{
let value = if let Some(possible_ids) =
self.mockmaker.id_map.get(table_name)
{
format!(
"r'{}'",
possible_ids[rng.random_range(0..possible_ids.len())]
)
} else {
panic!(
"There were no id's for the table {}, field {}",
table_name, ctx.field.field_name
);
};
value_stack.push(value);
} else if let Some(struct_config) = self
.mockmaker
.objects
.get(type_name)
.or_else(|| self.mockmaker.objects.get(&snake_case_name))
{
let field_names: Vec<String> = struct_config
.fields
.iter()
.map(|f| f.field_name.clone())
.collect();
work_stack.push(WorkItem::AssembleStruct { field_names });
// Add current type to visited types for nested fields
let mut new_visited = ctx.visited_types.clone();
new_visited.insert(type_name.clone());
for struct_field in struct_config.fields.iter().rev() {
let new_ctx = Frame {
field: struct_field,
field_type: &struct_field.field_type,
field_path: format!(
"{}.{}",
ctx.field_path.clone(),
struct_field.field_name
),
table_config: ctx.table_config,
visited_types: new_visited.clone(),
};
work_stack.push(WorkItem::Generate(new_ctx));
}
} else if let Some(tagged_union) =
self.mockmaker.enums.get(type_name)
{
let variant = tagged_union
.variants
.choose(&mut rng)
.expect("Failed to select a random enum variant");
let repr = &tagged_union.representation;
if let Some(ref variant_data) = variant.data {
match variant_data {
VariantData::InlineStruct(enum_struct) => {
let struct_config = self.mockmaker.objects.get(&enum_struct.struct_name).expect("Inline enum struct should have corresponding object definition");
let field_names: Vec<String> = struct_config
.fields
.iter()
.map(|f| f.field_name.clone())
.collect();
match repr {
EnumRepresentation::ExternallyTagged => {
work_stack.push(
WorkItem::WrapInVariantKey {
variant_name: variant.name.clone(),
},
);
work_stack.push(WorkItem::AssembleStruct {
field_names,
});
}
EnumRepresentation::InternallyTagged {
tag,
} => {
let mut names_with_tag = vec![tag.clone()];
names_with_tag.extend(field_names);
work_stack.push(
WorkItem::AssembleTaggedStruct {
tag_key: tag.clone(),
tag_value: variant.name.clone(),
field_names: names_with_tag,
},
);
}
EnumRepresentation::AdjacentlyTagged {
tag,
content,
} => {
work_stack.push(WorkItem::AssembleStruct {
field_names: vec![
tag.clone(),
content.clone(),
],
});
work_stack.push(WorkItem::AssembleStruct {
field_names,
});
// tag value will be pushed after struct fields
}
EnumRepresentation::Untagged => {
work_stack.push(WorkItem::AssembleStruct {
field_names,
});
}
}
let mut new_visited = ctx.visited_types.clone();
new_visited.insert(type_name.clone());
for struct_field in
struct_config.fields.iter().rev()
{
let new_ctx = Frame {
field: struct_field,
field_type: &struct_field.field_type,
field_path: format!(
"{}.{}",
ctx.field_path.clone(),
struct_field.field_name
),
table_config: ctx.table_config,
visited_types: new_visited.clone(),
};
work_stack.push(WorkItem::Generate(new_ctx));
}
// For adjacently tagged, push tag value after struct fields (processed first due to LIFO)
if let EnumRepresentation::AdjacentlyTagged {
..
} = repr
{
value_stack.push(format!("'{}'", variant.name));
}
}
VariantData::DataStructureRef(field_type) => {
match repr {
EnumRepresentation::ExternallyTagged
| EnumRepresentation::InternallyTagged {
..
} => {
work_stack.push(
WorkItem::WrapInVariantKey {
variant_name: variant.name.clone(),
},
);
}
EnumRepresentation::AdjacentlyTagged {
tag,
content,
} => {
work_stack.push(WorkItem::AssembleStruct {
field_names: vec![
tag.clone(),
content.clone(),
],
});
// Push the tag value directly; inner value comes from Generate
value_stack
.push(format!("'{}'", variant.name));
}
EnumRepresentation::Untagged => {
work_stack.push(WorkItem::AssembleEnum);
}
}
work_stack.push(WorkItem::Generate(Frame {
field_type,
..ctx.clone()
}));
}
}
} else {
// Unit variant
match repr {
EnumRepresentation::InternallyTagged { tag }
| EnumRepresentation::AdjacentlyTagged {
tag, ..
} => {
value_stack.push(format!(
"{{ {}: '{}' }}",
tag, variant.name
));
}
_ => {
value_stack.push(format!("'{}'", variant.name));
}
}
}
} else {
panic!(
"This type could not be parsed: table {}, field {}",
ctx.table_config.table_name, ctx.field.field_name
);
}
}
}
}
}
WorkItem::AssembleVec { count } => {
let items: Vec<_> = value_stack.drain(value_stack.len() - count..).collect();
value_stack.push(format!("[{}]", items.join(", ")));
}
WorkItem::AssembleTuple { count } => {
let items: Vec<_> = value_stack.drain(value_stack.len() - count..).collect();
value_stack.push(format!("[{}]", items.join(", ")));
}
WorkItem::AssembleStruct { field_names } => {
let count = field_names.len();
let values: Vec<_> = value_stack.drain(value_stack.len() - count..).collect();
let assignments: Vec<String> = field_names
.into_iter()
.zip(values.into_iter())
.map(|(name, value)| format!("{}: {}", name, value))
.collect();
value_stack.push(format!("{{ {} }}", assignments.join(", ")));
}
WorkItem::AssembleMap { count } => {
let mut entries = Vec::with_capacity(count);
for _ in 0..count {
let value = value_stack.pop().unwrap();
let key = value_stack.pop().unwrap();
entries.push(format!("{}: {}", key, value));
}
entries.reverse();
value_stack.push(format!("{{ {} }}", entries.join(", ")));
}
WorkItem::AssembleEnum { .. } => {
// No action needed; the generated value just stays on the stack.
}
WorkItem::WrapInVariantKey { variant_name } => {
let inner = value_stack.pop().unwrap();
value_stack.push(format!("{{ {}: {} }}", variant_name, inner));
}
WorkItem::AssembleTaggedStruct {
tag_key,
tag_value,
field_names,
} => {
// Like AssembleStruct but the first field is the tag with a known value
let data_count = field_names.len() - 1; // minus the tag field
let data_values: Vec<_> = value_stack
.drain(value_stack.len() - data_count..)
.collect();
let mut assignments: Vec<String> =
vec![format!("{}: '{}'", tag_key, tag_value)];
for (name, value) in
field_names.into_iter().skip(1).zip(data_values.into_iter())
{
assignments.push(format!("{}: {}", name, value));
}
value_stack.push(format!("{{ {} }}", assignments.join(", ")));
}
}
}
assert_eq!(
value_stack.len(),
1,
"Generation ended with not exactly one value on the stack."
);
value_stack.pop().unwrap()
}
pub fn handle_format(&self, format: &Format) -> String {
let generated = format.generate_formatted_value();
match format {
Format::Percentage
| Format::Latitude
| Format::Longitude
| Format::CurrencyAmount
| Format::AppointmentDurationNs => generated,
Format::DateTime | Format::AppointmentDateTime | Format::DateWithinDays(_) => {
format!("d'{}'", generated)
}
_ => format!("'{}'", generated),
}
}
fn handle_record_id(
&self,
field_name: &str,
table_name: &str,
table_config: &TableConfig,
rng: &mut ThreadRng,
) -> String {
if let Some(relation) = &table_config.relation {
// Check if this field has a OneToOne coordination (sequential 1:1 mapping)
let has_one_to_one = table_config
.mock_generation_config
.as_ref()
.map(|c| {
c.coordination_rules.iter().any(|r| {
matches!(r, crate::schemasync::mockmake::coordinate::Coordination::OneToOne(f) if f == field_name)
})
})
.unwrap_or(false);
let id_index = *self.id_index;
let mut pick_relation_record = |tables: &[String], field_label: &str| -> String {
for candidate in tables {
if let Some(ids) = self.mockmaker.id_map.get(candidate) {
if ids.is_empty() {
panic!(
"There were no id's for the table {}, field {}",
candidate, field_label
);
}
if has_one_to_one {
// Sequential 1:1 mapping: record index → target ID
let idx = id_index % ids.len();
return format!("r'{}'", ids[idx]);
}
return format!("r'{}'", ids[rng.random_range(0..ids.len())].clone());
}
}
panic!(
"There were no id's for any of the tables {:?}, field {}",
tables, field_label
);
};
if field_name == "in" {
return pick_relation_record(&relation.from, field_name);
} else if field_name == "out" {
return pick_relation_record(&relation.to, field_name);
}
}
if let Some(ids) = self.mockmaker.id_map.get(table_name) {
if *self.id_index < ids.len() {
format!("r'{}'", ids[*self.id_index].clone())
} else {
panic!("Out of bounds index for {table_name}, {field_name}")
}
} else {
format!("r'{}:{}'", table_name, &self.id_index)
}
}
}