ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
use crate::{
  BooleanFilter, BytesFilter, DefaultMarker, DefaultVecMarker, EnumFilter, EnumFilterMarker,
  EnumMarker, FixedBytesFilter, GraphqlFilter, ListFilter, ListMarker, Nullable, ScalarFilter,
  ScalarFilterMarker, ScalarMarker, Score, TextFilter, Timestamp, ToGraphqlFilter,
};

// The wire faces need a built schema to be visible at all, so they are tested through one rather
// than beside the mapping rows.
#[cfg(feature = "async-graphql")]
mod wire;

/// The projection an expansion writes for a field of type `T`: the interpretation the type carries,
/// and that interpretation's filter.
///
/// Named once here so the rows below read as the map they are. Every one of them is also the
/// EMITTER's spelling, so a chain that stopped resolving would red this file rather than only the
/// generated code.
type Filter<T> = <<T as DefaultMarker>::Marker as ToGraphqlFilter>::Filter;

/// A field type and the filter that guards it — the smallest shape the traits are asked for
/// together, standing in for what a declaring crate writes.
struct Field;

struct FieldFilter {
  eq: Option<u8>,
}

impl ScalarFilterMarker for Field {
  type Filter = FieldFilter;
}

impl DefaultMarker for Field {
  type Marker = ScalarMarker<Field>;
}

impl GraphqlFilter for FieldFilter {
  fn is_empty(&self) -> bool {
    self.eq.is_none()
  }
}

/// The shelf path and the public export name the SAME traits.
///
/// The impls above are written through the PUBLIC paths and the projection below is spelled through
/// the shelf, which is exactly the split an expansion produces: a declarer writes
/// `impl ingraph::ScalarFilterMarker for …` and the macro emits
/// `<<… as ingraph::__private::marker::DefaultMarker>::Marker as …::ToGraphqlFilter>`. Were
/// either shelf name a distinct trait, or were it not re-exported at all, this would not compile.
///
/// BOTH links of the chain are spelled here, because an expansion names both and a glob that
/// reached one of them and not the other would be a path that reads right and denotes nothing —
/// and the two links now live on two SEGMENTS, the reading being the crate's and the filter it
/// resolves to being this axis's, so the pair also pins that the split reaches an expansion intact.
#[test]
fn the_shelf_names_the_public_traits() {
  type Shelved<T> = <<T as crate::__private::marker::DefaultMarker>::Marker as crate::__private::graphql::ToGraphqlFilter>::Filter;

  let empty: Shelved<Field> = FieldFilter { eq: None };
  assert!(GraphqlFilter::is_empty(&empty));
  assert!(!GraphqlFilter::is_empty(&FieldFilter { eq: Some(1) }));
}

// A demo media entity — the shape a schema codegen would generate, hand-written here.
#[derive(Clone, Copy)]
enum MediaKind {
  Video,
  Audio,
}

// What a DOWNSTREAM enum writes: the value reading, and the marker that reading is reached through.
// Its `Option` column follows from the framework's blanket and needs no row; its LIST column takes
// the third, which is also where a declaring crate would name `SetMarker` instead.
//
// The FAMILY is the enumeration one, which no `to_filter!` row in this crate names — nothing the
// framework registers is read as an enumeration, so this is the whole of where that family is
// answered inside `ingraph`.
impl EnumFilterMarker for MediaKind {
  type Filter = EnumFilter<MediaKind>;
}

impl DefaultMarker for MediaKind {
  type Marker = EnumMarker<MediaKind>;
}

impl DefaultVecMarker for MediaKind {
  type Marker = ListMarker<Vec<MediaKind>>;
}

/// Two type expressions name the SAME type — the assertion every mapping row is written as.
/// Unifying `A` is the whole check: rustc rejects the call when the projection and the expected
/// filter differ, so a wrong row is a compile error rather than a failed assertion.
///
/// Free-standing rather than local to one test, because the gated vocabularies' rows are their own
/// tests — a feature that is off must take its rows out of the build with it.
fn same<A>(_: core::marker::PhantomData<A>, _: core::marker::PhantomData<A>) {}

/// Every filter kind, named through all three of the paths it answers to — and each pair is ONE
/// type.
///
/// The kinds live one to a submodule and reach every name here through a glob per module, which is
/// what makes naming them worth the lines. A glob turns a re-export that went missing, or a name
/// shadowed by a sibling submodule, or one made ambiguous by a second declaration, into something no
/// reader of `filter/mod.rs` can see — where an enumerated `pub use` would simply fail to compile.
/// Spelled out, a lost path is `E0433` and a path that stopped naming its kind is `E0308`, both
/// HERE rather than in a downstream crate's expansion.
///
/// The three are the public path a declarer writes, the shelf path an expansion writes today, and
/// the per-module shelf path. The middle one is the shelf's own claim under test: emitted code says
/// `#krate::__private::<module>::<item>`, and `__private::graphql` globs `crate::graphql`, which
/// globs `filter`, which globs the kinds — so an item moving into a submodule is invisible to code
/// already generated, which is the whole reason the shelf is spelled that way.
#[test]
fn every_kind_answers_to_its_public_name_and_both_shelf_paths() {
  use core::marker::PhantomData;

  use crate::__private::{graphql as shelf, graphql::filter as kinds};

  same(
    PhantomData::<crate::ScalarFilter<i64>>,
    PhantomData::<shelf::ScalarFilter<i64>>,
  );
  same(
    PhantomData::<crate::ScalarFilter<i64>>,
    PhantomData::<kinds::ScalarFilter<i64>>,
  );
  same(
    PhantomData::<crate::EnumFilter<MediaKind>>,
    PhantomData::<shelf::EnumFilter<MediaKind>>,
  );
  same(
    PhantomData::<crate::EnumFilter<MediaKind>>,
    PhantomData::<kinds::EnumFilter<MediaKind>>,
  );
  same(
    PhantomData::<crate::BooleanFilter>,
    PhantomData::<shelf::BooleanFilter>,
  );
  same(
    PhantomData::<crate::BooleanFilter>,
    PhantomData::<kinds::BooleanFilter>,
  );
  same(
    PhantomData::<crate::TextFilter<String>>,
    PhantomData::<shelf::TextFilter<String>>,
  );
  same(
    PhantomData::<crate::TextFilter<String>>,
    PhantomData::<kinds::TextFilter<String>>,
  );
  same(
    PhantomData::<crate::BytesFilter<Vec<u8>>>,
    PhantomData::<shelf::BytesFilter<Vec<u8>>>,
  );
  same(
    PhantomData::<crate::BytesFilter<Vec<u8>>>,
    PhantomData::<kinds::BytesFilter<Vec<u8>>>,
  );
  same(
    PhantomData::<crate::ListFilter<i64>>,
    PhantomData::<shelf::ListFilter<i64>>,
  );
  same(
    PhantomData::<crate::ListFilter<i64>>,
    PhantomData::<kinds::ListFilter<i64>>,
  );
  same(
    PhantomData::<crate::Nullable<BooleanFilter>>,
    PhantomData::<shelf::Nullable<BooleanFilter>>,
  );
  same(
    PhantomData::<crate::Nullable<BooleanFilter>>,
    PhantomData::<kinds::Nullable<BooleanFilter>>,
  );

  // The duration kind is a whole feature, `mod` declaration included, so its two names are asked
  // for only where they exist.
  #[cfg(feature = "jiff")]
  {
    same(
      PhantomData::<crate::DurationFilter>,
      PhantomData::<shelf::DurationFilter>,
    );
    same(
      PhantomData::<crate::DurationFilter>,
      PhantomData::<kinds::DurationFilter>,
    );
    same(
      PhantomData::<crate::DurationOutOfRange>,
      PhantomData::<shelf::DurationOutOfRange>,
    );
    same(
      PhantomData::<crate::DurationOutOfRange>,
      PhantomData::<kinds::DurationOutOfRange>,
    );
  }

  // The contract is declared in `filter/mod.rs` rather than in a kind, so it reaches the shelf by
  // those same two routes. One filter satisfying all three bounds is one trait: were any of them a
  // distinct trait, the only impl in existence is the one written against the public name.
  fn contract<F>()
  where
    F: crate::GraphqlFilter
      + crate::__private::graphql::GraphqlFilter
      + crate::__private::graphql::filter::GraphqlFilter,
  {
  }
  contract::<BooleanFilter>();

  // The storage types a DECLARATION names, and they are the one group with exactly ONE path.
  // `<db>(type = "BeU64")` is resolved in the declarer's own scope rather than through the
  // shelf, and no expansion names one, so there is no shelf leg to lose and no family leg to lose
  // it to — the root re-export IS the surface. The assertion is therefore the crossing rather than
  // an identity: it fails if the re-export is gone, and it fails under a build with no backend if
  // one of these ever acquires a family's feature again, which is the defect that put them here.
  {
    let _: crate::BeU64 = u64::MAX.into();
    let _: crate::BeU128 = u128::MAX.into();
    let _: crate::BeI128 = i128::MIN.into();

    #[cfg(all(feature = "jiff", feature = "time"))]
    {
      let _: crate::Temporal<time::OffsetDateTime> = jiff::Timestamp::UNIX_EPOCH.into();
    }
  }

  // The affix vocabulary, which is a comparison-level item under NO feature and is therefore asked
  // for in EVERY build rather than inside a family's guard. That is the property that put it there:
  // a build with one backend family and not the other still has the name, where the enum's old home
  // inside `comparison::sql` made the second family declare its own copy. Two paths, as every
  // comparison-level item has — where it lives, and where the shelf's glob reaches it.
  same(
    PhantomData::<crate::comparison::TextMatch>,
    PhantomData::<crate::__private::comparison::TextMatch>,
  );

  // The comparison side rides in this same guard rather than a second one: what is under test is
  // not the filter module but the property that a GLOB re-export can lose a name in silence, and
  // the shelf reaches this family's items through exactly such a glob.
  //
  // How many paths an item answers to differs here, and the difference is the point. The family
  // module is PUBLIC and its implementation surface is not lifted to the root, so a comparison type
  // has TWO paths — where it lives and where an expansion names it. Only what a person writes has a
  // third one at the root, and the two groups are asserted apart so that a name sliding between them
  // fails here.
  #[cfg(feature = "sqlx")]
  {
    use crate::{
      __private::comparison as shelf,
      comparison::{TextMatch, sql as family},
    };

    same(
      PhantomData::<family::SqlScalarComparison<i64, ()>>,
      PhantomData::<shelf::sql::SqlScalarComparison<i64, ()>>,
    );
    same(
      PhantomData::<family::SqlEnumComparison<i64, ()>>,
      PhantomData::<shelf::sql::SqlEnumComparison<i64, ()>>,
    );
    same(
      PhantomData::<family::SqlBooleanComparison<bool, ()>>,
      PhantomData::<shelf::sql::SqlBooleanComparison<bool, ()>>,
    );
    same(
      PhantomData::<family::SqlTextComparison<String, ()>>,
      PhantomData::<shelf::sql::SqlTextComparison<String, ()>>,
    );
    same(
      PhantomData::<family::SqlBytesComparison<Vec<u8>, ()>>,
      PhantomData::<shelf::sql::SqlBytesComparison<Vec<u8>, ()>>,
    );
    same(
      PhantomData::<family::SqlListComparison<i64, family::SqlScalarComparison<i64, ()>, ()>>,
      PhantomData::<shelf::sql::SqlListComparison<i64, shelf::sql::SqlScalarComparison<i64, ()>, ()>>,
    );
    same(
      PhantomData::<family::SqlSetComparison<i64, family::SqlScalarComparison<i64, ()>, ()>>,
      PhantomData::<shelf::sql::SqlSetComparison<i64, shelf::sql::SqlScalarComparison<i64, ()>, ()>>,
    );
    same(
      PhantomData::<family::SqlCountComparison<i64, ()>>,
      PhantomData::<shelf::sql::SqlCountComparison<i64, ()>>,
    );
    same(
      PhantomData::<family::SqlNullable<family::SqlScalarComparison<i64, ()>, i64>>,
      PhantomData::<shelf::sql::SqlNullable<shelf::sql::SqlScalarComparison<i64, ()>, i64>>,
    );
    // The MySQL duration carrier is a storage type a DECLARATION names, and its refusal travels
    // with it. It keeps its family legs where the big-endian carriers lost theirs, and the reason is
    // in its name: a `TIME` value checked against MySQL's own range is a dialect surface, so it is
    // the one storage type that belongs inside a family.
    //
    // It rides the KIND as well as the dialect: its conversion is from the duration filter's
    // operand, so a build with the dialect and no `jiff` has no source type for it to exist over.
    #[cfg(all(feature = "mysql", feature = "jiff"))]
    {
      same(
        PhantomData::<crate::MySqlDuration>,
        PhantomData::<shelf::sql::MySqlDuration>,
      );
      same(
        PhantomData::<crate::MySqlDurationError>,
        PhantomData::<shelf::sql::MySqlDurationError>,
      );
    }

    // The family's own vocabulary — the JSON dialects' collection operations. Nothing generic names
    // it, so nothing else in this guard would notice it going missing.
    //
    // `BytesCrossingError` used to stand beside it and does not exist: the byte kinds split by slot
    // legality, so the family's one non-conversion refusal has nothing left to refuse.
    same(
      PhantomData::<family::CollectionOp>,
      PhantomData::<shelf::sql::CollectionOp>,
    );

    // The two public FUNCTIONS the family exports. A glob can lose one exactly as it can lose a
    // type, and naming it as a value is what makes the two paths one item.
    let by_path: fn(&[i64]) -> String = family::json_elements;
    let by_shelf: fn(&[i64]) -> String = shelf::sql::json_elements;
    assert_eq!(by_path(&[1, 2]), by_shelf(&[1, 2]));

    let by_path: fn(&str, TextMatch) -> String = family::like_pattern;
    let by_shelf: fn(&str, TextMatch) -> String = shelf::sql::like_pattern;
    assert_eq!(
      by_path("a%", TextMatch::Prefix),
      by_shelf("a%", TextMatch::Prefix)
    );

    // The duration comparison rides the feature its FILTER rides, so its shelf path is asked for
    // where both are compiled.
    #[cfg(feature = "jiff")]
    same(
      PhantomData::<family::SqlDurationComparison<i64, ()>>,
      PhantomData::<shelf::sql::SqlDurationComparison<i64, ()>>,
    );

    // The crossing traits stay at the `comparison` level and at the root, so they keep the filter
    // kinds' three-path shape. One type satisfying every bound is one trait.
    fn crossing<C>()
    where
      C: crate::TryFromFilter<crate::ScalarFilter<i64>>
        + crate::comparison::TryFromFilter<crate::ScalarFilter<i64>>
        + crate::__private::comparison::TryFromFilter<crate::ScalarFilter<i64>>,
    {
    }
    crossing::<family::SqlScalarComparison<i64, ()>>();

    // The remaining three name a dialect, so they are asked for where one is compiled. `Db` itself
    // needs none — every comparison struct above is bound-free, which is why `()` stands in for it.
    #[cfg(feature = "sqlite")]
    {
      fn maps<F>()
      where
        F: crate::ToDatabaseComparison<i64, sqlx::Sqlite>
          + crate::__private::comparison::ToDatabaseComparison<i64, sqlx::Sqlite>,
      {
      }
      maps::<crate::ScalarFilter<i64>>();

      // `Carrier` is implemented by a DOWNSTREAM, so it keeps its root leg beside the two the
      // family surface gives it.
      fn carried<V>()
      where
        V: crate::Carrier<sqlx::Sqlite>
          + family::Carrier<sqlx::Sqlite>
          + shelf::sql::Carrier<sqlx::Sqlite>,
      {
      }
      carried::<crate::BeU64>();

      fn encoded<V>()
      where
        V: crate::JsonElement + family::JsonElement + shelf::sql::JsonElement,
      {
      }
      encoded::<i64>();

      fn lowered<C>()
      where
        C: crate::ComplexComparison<sqlx::Sqlite>
          + crate::__private::comparison::ComplexComparison<sqlx::Sqlite>,
      {
      }
      lowered::<family::SqlScalarComparison<i64, sqlx::Sqlite>>();
    }
  }
}

/// The getters shadow [`PartialEq`]'s methods for CALL syntax and leave the operators alone.
///
/// The claim `opt_accessor!` documents is about name resolution rather than about either impl, so it
/// is measured rather than reasoned: `f.eq()` is the inherent getter — it takes no argument, which
/// no `PartialEq::eq` call could — and `==`, `!=` and `assert_eq!` still reach the trait.
#[test]
fn a_getter_named_eq_shadows_the_method_and_not_the_operator() {
  let one = ScalarFilter::<i64>::new().with_eq(1i64).with_in_([2i64, 3]);
  let same_again = ScalarFilter::new().with_eq(1i64).with_in_([2i64, 3]);
  let other = ScalarFilter::new().with_eq(2i64);

  assert_eq!(one, same_again);
  assert!(one == same_again);
  assert!(one != other);
  assert!(!(one == other));

  // The inherent getters project: the operand, and the operands, never the `Option<Box<[T]>>`.
  let _: Option<&i64> = one.eq();
  let _: Option<&[i64]> = one.in_();
  assert_eq!(one.eq(), Some(&1));
  assert_eq!(one.ne(), None);
  assert_eq!(one.in_(), Some(&[2i64, 3][..]));
  assert_eq!(one.not_in(), None);

  // A present but EMPTY list is not an absent operator, and the getter keeps the two apart.
  let empty = ScalarFilter::<i64>::new().with_in_(Vec::<i64>::new());
  assert_eq!(empty.in_(), Some(&[][..]));
  assert_eq!(empty.not_in(), None);
  assert!(!empty.is_empty());
}

/// Every kind the accessor macro serves gained the getters, not just the ones the comparison layer
/// crosses — a macro edit that reached only some of them would leave a hole no kind's own test sees.
#[test]
fn every_kind_projects_its_operands() {
  assert!(EnumFilter::new().with_eq(MediaKind::Video).eq().is_some());
  assert_eq!(BooleanFilter::new().with_ne(true).ne(), Some(&true));
  assert_eq!(
    TextFilter::<&str>::new().with_contains("x").contains(),
    Some(&"x")
  );
  assert_eq!(
    BytesFilter::<Vec<u8>>::new().with_eq(vec![1u8]).eq(),
    Some(&vec![1u8])
  );
  assert_eq!(
    ListFilter::<i64>::new().with_lte([1i64]).lte(),
    Some(&[1i64][..])
  );
  assert_eq!(
    crate::SetFilter::<i64>::new()
      .with_overlaps([1i64])
      .overlaps(),
    Some(&[1i64][..])
  );
  assert_eq!(
    Nullable::new(ScalarFilter::<i64>::new())
      .with_null(true)
      .null(),
    Some(&true)
  );
  #[cfg(feature = "jiff")]
  assert_eq!(
    crate::DurationFilter::new()
      .with_gte(jiff::SignedDuration::from_secs(1))
      .gte(),
    Some(&jiff::SignedDuration::from_secs(1))
  );
}

/// `try_map` converts operands without ever handing one out, and the operator set survives the
/// conversion unchanged.
#[test]
fn try_map_converts_operands_and_keeps_the_operator_set() {
  let mapped = ScalarFilter::<u8>::new()
    .with_eq(1u8)
    .with_in_([2u8, 3])
    .try_map(|v| Ok::<_, core::convert::Infallible>(i64::from(v) * 10))
    .unwrap();

  assert_eq!(mapped.eq(), Some(&10));
  assert_eq!(mapped.in_(), Some(&[20i64, 30][..]));
  assert_eq!(mapped.gt(), None);

  // The FIRST failure wins, and the operands already converted go with it.
  let refused = ScalarFilter::<i64>::new()
    .with_in_([1i64, 300, 2])
    .try_map(u8::try_from);
  assert!(refused.is_err());

  // The wrapper maps its own parameter — the filter — and never converts the null test.
  let nullable = Nullable::new(EnumFilter::new().with_eq(MediaKind::Audio))
    .with_null(false)
    .try_map(|inner| inner.try_map(|_| Ok::<_, core::convert::Infallible>(1i16)))
    .unwrap();
  assert_eq!(nullable.inner().eq(), Some(&1));
  assert_eq!(nullable.null(), Some(&false));
}

// The INFERENCE, row by row: a field's Rust type selects the interpretation it is read under, and
// that interpretation selects the filter. A declaration spells neither, which is what every row here
// is written to say — the left-hand side names a field type and nothing else.
//
// The `Option` rows are the NULLABILITY pin, and they are the whole guarantee stated as a type
// equation. A VALUE column resolves to `Nullable<…>` — the only type carrying a null operator — where
// a `NOT NULL` one resolves to the bare filter, which carries none. A COLLECTION column resolves to
// the bare filter EITHER WAY, because a collection has no null state for the wrapper to be about: the
// `Option` around it declares the collection, and the row above it is what it has to match. Point the
// `Option` blanket at one answer for both families and half of these rows stop compiling, in
// whichever direction it was pointed.
#[test]
fn the_default_marker_maps_each_field_type_to_its_filter() {
  same(
    core::marker::PhantomData::<Filter<i64>>,
    core::marker::PhantomData::<ScalarFilter<i64>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<i64>>>,
    core::marker::PhantomData::<Nullable<ScalarFilter<i64>>>,
  );
  same(
    core::marker::PhantomData::<Filter<Vec<i64>>>,
    core::marker::PhantomData::<ListFilter<i64>>,
  );
  // The COLLAPSE, and the pair above it is what makes it one: the optional collection resolves to
  // the SAME type its bare neighbour does, `Option` and all.
  same(
    core::marker::PhantomData::<Filter<Option<Vec<i64>>>>,
    core::marker::PhantomData::<ListFilter<i64>>,
  );
  same(
    core::marker::PhantomData::<Filter<String>>,
    core::marker::PhantomData::<TextFilter<String>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<String>>>,
    core::marker::PhantomData::<Nullable<TextFilter<String>>>,
  );
  // The collapse with the ELEMENT's filter written out, so the row says there is no `Nullable`
  // anywhere in the answer rather than only none at the top: the whole type is a sequence of text.
  same(
    core::marker::PhantomData::<Filter<Vec<String>>>,
    core::marker::PhantomData::<ListFilter<String, TextFilter<String>>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Vec<String>>>>,
    core::marker::PhantomData::<ListFilter<String, TextFilter<String>>>,
  );
  // `bool` is the one registration whose filter takes no parameter, and these rows pin what that
  // costs the other readings: nothing. The nullable row still wraps the SAME filter, and the `Vec`
  // row still lands on `ListFilter<bool>` — a collection's filter is keyed on the ELEMENT type
  // rather than on the element's filter, so narrowing the value reading leaves the collection
  // column untouched.
  same(
    core::marker::PhantomData::<Filter<bool>>,
    core::marker::PhantomData::<BooleanFilter>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<bool>>>,
    core::marker::PhantomData::<Nullable<BooleanFilter>>,
  );
  same(
    core::marker::PhantomData::<Filter<Vec<bool>>>,
    core::marker::PhantomData::<ListFilter<bool>>,
  );
  // The two impls a downstream enum writes, resolving through the same map as a registered
  // primitive. Its containers are no longer the orphan rule's problem: the `Option` row below comes
  // from the blanket and the `Vec` row from the element's own `DefaultVecMarker`, neither of which
  // that crate could have reached when the map was keyed on the type.
  same(
    core::marker::PhantomData::<Filter<MediaKind>>,
    core::marker::PhantomData::<EnumFilter<MediaKind>>,
  );
  // `Vec<u8>` is a BLOB, not a list of small integers, so it resolves to `BytesFilter` and takes
  // byte-substring `contains` rather than `ListFilter`'s element-wise `has_element`. These two
  // rows state that as a type equation; what produces it is guarded one step earlier than they are,
  // since giving `u8`'s row the ordinary `Vec` default makes the blanket and the `Vec<u8>`
  // registration claim the type at once and the crate stops compiling (`E0119`) before any test
  // runs.
  same(
    core::marker::PhantomData::<Filter<Vec<u8>>>,
    core::marker::PhantomData::<BytesFilter<Vec<u8>>>,
  );
  // The FENCE for the collapse two rows above: the shape `Option<Vec<…>>` decides nothing, the
  // FAMILY does, and a `Vec<u8>` is a blob. A blob is a value, a value can be absent, so this row
  // keeps the null test the collections read straight through.
  same(
    core::marker::PhantomData::<Filter<Option<Vec<u8>>>>,
    core::marker::PhantomData::<Nullable<BytesFilter<Vec<u8>>>>,
  );
  // …and `u8` itself keeps its scalar reading. Its row says what a `Vec` of it means and nothing
  // else, so a `u8` column is unaffected by what that `Vec` resolves to.
  same(
    core::marker::PhantomData::<Filter<u8>>,
    core::marker::PhantomData::<ScalarFilter<u8>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<u8>>>,
    core::marker::PhantomData::<Nullable<ScalarFilter<u8>>>,
  );
  // A list of blobs is a list. `Vec<u8>` carries a `Vec` row of its own like any other registered
  // type — the blob reading is spent on `u8`'s row, not inherited by what it produces.
  //
  // Which is what puts the second row on the other side of the fence from the one above it: the two
  // types differ by one `Vec` and their optional readings differ by the whole null test, because the
  // inner one is a value and this one is a collection.
  same(
    core::marker::PhantomData::<Filter<Vec<Vec<u8>>>>,
    core::marker::PhantomData::<ListFilter<Vec<u8>>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Vec<Vec<u8>>>>>,
    core::marker::PhantomData::<ListFilter<Vec<u8>>>,
  );
  // The hand-written `[u8; N]` family gets the same treatment as the macro's three rows — and all
  // four rows are pinned, not the two `legacy/ingraph` pins, because these impls are written out
  // rather than generated and so are the ones free to drift apart from each other.
  //
  // The KIND in the first two rows is the pin: a fixed-width column's filter is a different type
  // from a blob's — a different type and not a different parameter — so re-registering `[u8; N]` on
  // `BytesFilter` reds this.
  same(
    core::marker::PhantomData::<Filter<[u8; 32]>>,
    core::marker::PhantomData::<FixedBytesFilter<[u8; 32], 32>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<[u8; 32]>>>,
    core::marker::PhantomData::<Nullable<FixedBytesFilter<[u8; 32], 32>>>,
  );
  // A LIST of hashes is a list, not a blob: the element's own reading takes no part in the
  // collection's, so these two rows land on `ListFilter` rather than on a nested `BytesFilter`.
  same(
    core::marker::PhantomData::<Filter<Vec<[u8; 32]>>>,
    core::marker::PhantomData::<ListFilter<[u8; 32]>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Vec<[u8; 32]>>>>,
    core::marker::PhantomData::<ListFilter<[u8; 32]>>,
  );
}

/// **EVERY WIDTH RESOLVES TO ONE FILTER**, and these rows are where the reshape is stated at the
/// marker layer.
///
/// A confidence needs no COMPARISON kind of its own — the type excludes `NaN` at construction, which
/// is what makes its [`Ord`] total, and a total order is what `gt`/`gte`/`lt`/`lte` are DEFINED
/// over. What it needed is a FILTER kind, because its operand is widthless: see
/// [`ConfidenceFilter`](crate::ConfidenceFilter), where the four retired `Score*` names are
/// accounted for.
///
/// The `Vec` row is the one that does NOT resolve to it, and that is the collection law rather than
/// an exception: a list column's face holds the ELEMENT, so a `Vec<Score>` is `ListFilter<Score>`
/// whose seven element slots cross through the width's own roster carrier.
///
/// Ungated, unlike the vocabulary tests below: `Score` is this crate's own type, so its
/// registration costs no dependency and stands in every build.
#[test]
fn every_confidence_width_resolves_to_the_confidence_filter() {
  use crate::{Confidence, ConfidenceFilter};

  same(
    core::marker::PhantomData::<Filter<Score>>,
    core::marker::PhantomData::<ConfidenceFilter>,
  );
  same(
    core::marker::PhantomData::<Filter<Confidence<f64>>>,
    core::marker::PhantomData::<ConfidenceFilter>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Score>>>,
    core::marker::PhantomData::<Nullable<ConfidenceFilter>>,
  );
  // The plain arm's `Vec` row, so a list of confidences is a list — a keyframe's tag scores, say.
  same(
    core::marker::PhantomData::<Filter<Vec<Score>>>,
    core::marker::PhantomData::<ListFilter<Score>>,
  );
}

/// [`Timestamp`] needs no filter kind of its own either, and for the reason an instant is a scalar:
/// its [`Ord`] is total — the derive over jiff's, which compares one duration since the epoch — so
/// `ScalarFilter`'s four ordering operators are DEFINED over it rather than approximated.
///
/// Ungated like the rows above, and that is the half worth pinning: `jiff::Timestamp` resolves to a
/// filter only under the `jiff` feature, and this type resolves in every build. The two are different
/// Rust types with registrations of their own, so a declaration picks one by naming it.
#[test]
fn timestamp_resolves_to_a_scalar_filter() {
  same(
    core::marker::PhantomData::<Filter<Timestamp>>,
    core::marker::PhantomData::<ScalarFilter<Timestamp>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Timestamp>>>,
    core::marker::PhantomData::<Nullable<ScalarFilter<Timestamp>>>,
  );
  // The plain arm's `Vec` row: a list of instants is a list — a scene's cut points, say.
  same(
    core::marker::PhantomData::<Filter<Vec<Timestamp>>>,
    core::marker::PhantomData::<ListFilter<Timestamp>>,
  );
}

// The list operators' STORAGE, pinned: a boxed slice, two words where a `Vec` is three.
//
// The saving costs nothing. A list operator allocates when it is set, and in the common case every
// one of them is `None` — so the third word buys a capacity no filter ever uses. And it compounds by
// the COLUMN rather than by the query: a where struct holds one filter per column, and each filter
// holds one slot per operator, so `Nullable<ScalarFilter<i64>>` is 136 bytes where it was 152 and a
// twenty-column where struct of them 2720 where it was 3040.
//
// Written as arithmetic over the slot types rather than as literal byte counts, so it says the same
// thing on a 32-bit target and so what fails it is a REGRESSION rather than a re-measurement:
// `Option<Vec<T>>` is one word wider than `Option<Box<[T]>>`, so putting any single slot back
// overshoots its kind's sum.
#[test]
fn list_operator_slots_are_boxed_slices() {
  use core::mem::{align_of, size_of};

  let word = size_of::<usize>();
  let list = size_of::<Option<Box<[i64]>>>();
  let operand = size_of::<Option<i64>>();
  assert_eq!(list, 2 * word);
  assert_eq!(size_of::<Option<Vec<i64>>>(), 3 * word);

  // Six inline operands and the two list operators `in_`/`not_in`.
  assert_eq!(size_of::<ScalarFilter<i64>>(), 6 * operand + 2 * list);
  // Two of each.
  assert_eq!(size_of::<EnumFilter<i64>>(), 2 * operand + 2 * list);
  // SIX list operators (`eq`/`ne` and the four ordering ones) beside one inline element operand, a
  // whole ELEMENT filter and a whole cardinality filter. The two nested slots are what a collection
  // filter costs over its operators alone, and each is an `Option` of a whole kind rather than of an
  // operand — `any` because an element question is asked in the element's vocabulary, `count`
  // because a cardinality takes the eight operators a number takes.
  //
  // The cardinality slot is spelled over `usize` and the element one over the element type, which is
  // the two slots' whole difference said in the arithmetic: a length does not follow the element.
  let element = size_of::<Option<ScalarFilter<i64>>>();
  let cardinality = size_of::<Option<ScalarFilter<usize>>>();
  assert_eq!(
    size_of::<ListFilter<i64>>(),
    6 * list + operand + element + cardinality
  );
  // FIVE (`eq`/`ne`, `encloses`/`enclosed_by`/`overlaps`) beside the same inline element operand and
  // the same two nested slots. The two kinds together hold eleven list operators where the one they
  // replace held nine, which is `eq`/`ne` counted twice — the operators that MEAN something
  // different on each shape, and the whole reason the shape stopped being a marker on one struct.
  assert_eq!(
    size_of::<crate::SetFilter<i64>>(),
    5 * list + operand + element + cardinality
  );
  // Eighteen inline text operands and the two list operators.
  assert_eq!(
    size_of::<TextFilter<String>>(),
    18 * size_of::<Option<String>>() + 2 * list
  );
  // Eight inline byte operands, the two list operators, and a zero-sized shape marker.
  assert_eq!(
    size_of::<BytesFilter<Vec<u8>>>(),
    8 * size_of::<Option<Vec<u8>>>() + 2 * list
  );
  // The wrapper is its inner filter plus the null test, rounded to the inner alignment — so the
  // saving reaches a NULLABLE column undiminished rather than being re-spent on the wrapper.
  assert_eq!(
    size_of::<Nullable<ScalarFilter<i64>>>(),
    size_of::<ScalarFilter<i64>>() + align_of::<ScalarFilter<i64>>()
  );
}

#[test]
fn every_filter_is_empty_until_a_field_is_set() {
  // Guards the hand-written `is_empty` &&-chains against drifting out of lockstep with the slot
  // lists: each filter reports empty on `new()` and non-empty after a single `with_*`. Type params
  // are arbitrary here — `is_empty` reflects field presence, not value semantics.
  assert!(ScalarFilter::<i64>::new().is_empty());
  assert!(!ScalarFilter::<i64>::new().with_gt(1).is_empty());

  // Over the demo enum rather than an arbitrary integer, because an enum whose variants appear only
  // in type position is dead code — the mapping row above declares the fixture, and these rows are
  // what CONSTRUCT it. The membership row is here for the second variant and for no other reason.
  assert!(EnumFilter::<MediaKind>::new().is_empty());
  assert!(
    !EnumFilter::<MediaKind>::new()
      .with_eq(MediaKind::Video)
      .is_empty()
  );
  assert!(
    !EnumFilter::<MediaKind>::new()
      .with_in_([MediaKind::Video, MediaKind::Audio])
      .is_empty()
  );

  // All four of the boolean kind's operators, individually. `ne` and the membership pair are the
  // three slots a "two-valued domain needs only `eq`" reading would drop, and dropping any one of
  // them reds the row that sets it.
  assert!(BooleanFilter::new().is_empty());
  assert!(!BooleanFilter::new().with_eq(true).is_empty());
  assert!(!BooleanFilter::new().with_ne(true).is_empty());
  assert!(!BooleanFilter::new().with_in_([true, false]).is_empty());
  assert!(!BooleanFilter::new().with_not_in([true]).is_empty());
  // The EMPTY membership list, which is the operand a computed set arrives as when the computation
  // came out empty: the slot is SET and asks for no rows, where an absent one asks for every row. A
  // length-aware `is_empty` would read this filter as the empty one and drop the operator.
  assert!(!BooleanFilter::new().with_in_([]).is_empty());
  // `Default` is `new()`, not a derive over the slots.
  assert!(BooleanFilter::default().is_empty());

  assert!(TextFilter::<String>::new().is_empty());
  assert!(
    !TextFilter::<String>::new()
      .with_contains("x".into())
      .is_empty()
  );

  assert!(BytesFilter::<Vec<u8>>::new().is_empty());
  assert!(
    !BytesFilter::<Vec<u8>>::new()
      .with_contains(b"x".to_vec())
      .is_empty()
  );
  // The FIXED kind's emptiness is its OWN eight slots, and the substring pair is not among them —
  // `with_contains` on this type is `E0599`, which is the whole ruling. What is asserted here is
  // that the shorter reading still answers for the operators it does have.
  assert!(FixedBytesFilter::<[u8; 32], 32>::new().is_empty());
  assert!(
    !FixedBytesFilter::<[u8; 32], 32>::new()
      .with_eq([0; 32])
      .is_empty()
  );

  assert!(ListFilter::<i64>::new().is_empty());
  assert!(!ListFilter::<i64>::new().with_has_element(1).is_empty());

  // `Nullable` composes the answer from BOTH halves, so either half alone is enough to be non-empty.
  assert!(Nullable::new(ScalarFilter::<i64>::new()).is_empty());
  assert!(
    !Nullable::new(ScalarFilter::<i64>::new())
      .with_null(true)
      .is_empty()
  );
  assert!(!Nullable::new(ScalarFilter::<i64>::new().with_gt(1)).is_empty());
  // `Default` reaches the inner filter's own default, which is its empty value.
  assert!(Nullable::<ListFilter<i64>>::default().is_empty());
}

/// One exclusion row: the operator's name, and the call that sets it beside an `eq` already there.
/// Named rather than spelled inline at each of the four tables, which `clippy::type_complexity`
/// refuses.
type Exclusion<F> = (&'static str, fn(F) -> F);

/// The shape a relation may rewrite onto the parent's foreign key, on each kind that answers the
/// question — and every shape it may not.
///
/// What the predicate EXCLUDES carries the soundness argument, one reason per family: a negated
/// shape is not equivalent under dangling references, an ordering operator names a range rather than
/// a child row, a case-insensitive match compares differently on the two columns, and two operators
/// at once name two constraints. A dropped `is_none()` term widens the collapse silently — a WRONG
/// RESULT SET rather than an error — so the exclusions are enumerated rather than sampled.
///
/// Every exclusion row sets `eq` BESIDE the operator it is about, and that pairing is what makes it
/// a row at all: the `eq ^ in_` gate refuses a filter that sets the excluded operator ALONE before
/// its own term is ever reached, so a lone-operator row stays green with the term deleted.
#[test]
fn is_referential_admits_a_lone_equality_or_membership_and_nothing_else() {
  assert!(ScalarFilter::<i64>::new().with_eq(1).is_referential());
  assert!(ScalarFilter::<i64>::new().with_in_([1]).is_referential());
  assert!(
    TextFilter::<String>::new()
      .with_eq("a".into())
      .is_referential()
  );
  assert!(
    TextFilter::<String>::new()
      .with_in_(["a".into()])
      .is_referential()
  );
  assert!(
    EnumFilter::<MediaKind>::new()
      .with_eq(MediaKind::Video)
      .is_referential()
  );
  assert!(
    EnumFilter::<MediaKind>::new()
      .with_in_([MediaKind::Audio])
      .is_referential()
  );
  assert!(
    BytesFilter::<Vec<u8>>::new()
      .with_eq(b"a".to_vec())
      .is_referential()
  );
  assert!(
    BytesFilter::<Vec<u8>>::new()
      .with_in_([b"a".to_vec()])
      .is_referential()
  );

  // Both together name two constraints, not one child row — the one exclusion the gate itself makes.
  assert!(
    !ScalarFilter::<i64>::new()
      .with_eq(1)
      .with_in_([1])
      .is_referential()
  );

  // The null test has no slot HERE to be refused in: a nullable key's filter is a
  // `Nullable<ScalarFilter<i64>>` and the wrapper has no `is_referential`, so a filter carrying
  // nothing but a null question is, on the inner type, the EMPTY one. It answers false — otherwise
  // `inner().is_referential()` would collapse a nullable column and drop the null test with it.
  assert!(!ScalarFilter::<i64>::new().is_referential());

  let scalar: [Exclusion<ScalarFilter<i64>>; 6] = [
    ("ne", |f| f.with_ne(2)),
    ("gt", |f| f.with_gt(2)),
    ("gte", |f| f.with_gte(2)),
    ("lt", |f| f.with_lt(2)),
    ("lte", |f| f.with_lte(2)),
    ("not_in", |f| f.with_not_in([2])),
  ];
  for (operator, set) in scalar {
    assert!(
      !set(ScalarFilter::new().with_eq(1)).is_referential(),
      "`eq` beside `{operator}` is not a referential shape"
    );
  }

  let enumerated: [Exclusion<EnumFilter<MediaKind>>; 2] = [
    ("ne", |f| f.with_ne(MediaKind::Audio)),
    ("not_in", |f| f.with_not_in([MediaKind::Audio])),
  ];
  for (operator, set) in enumerated {
    assert!(
      !set(EnumFilter::new().with_eq(MediaKind::Video)).is_referential(),
      "`eq` beside `{operator}` is not a referential shape"
    );
  }

  // Eighteen of the twenty text slots are exclusions, the longest list of any kind and the one a
  // newly added operator rots first — so every one of them is named.
  let text: [Exclusion<TextFilter<String>>; 18] = [
    ("ne", |f| f.with_ne("b".into())),
    ("gt", |f| f.with_gt("b".into())),
    ("gte", |f| f.with_gte("b".into())),
    ("lt", |f| f.with_lt("b".into())),
    ("lte", |f| f.with_lte("b".into())),
    ("contains", |f| f.with_contains("b".into())),
    ("contains_nocase", |f| f.with_contains_nocase("b".into())),
    ("not_contains", |f| f.with_not_contains("b".into())),
    ("not_contains_nocase", |f| {
      f.with_not_contains_nocase("b".into())
    }),
    ("starts_with", |f| f.with_starts_with("b".into())),
    ("starts_with_nocase", |f| {
      f.with_starts_with_nocase("b".into())
    }),
    ("not_starts_with", |f| f.with_not_starts_with("b".into())),
    ("not_starts_with_nocase", |f| {
      f.with_not_starts_with_nocase("b".into())
    }),
    ("ends_with", |f| f.with_ends_with("b".into())),
    ("ends_with_nocase", |f| f.with_ends_with_nocase("b".into())),
    ("not_ends_with", |f| f.with_not_ends_with("b".into())),
    ("not_ends_with_nocase", |f| {
      f.with_not_ends_with_nocase("b".into())
    }),
    ("not_in", |f| f.with_not_in(["b".into()])),
  ];
  for (operator, set) in text {
    assert!(
      !set(TextFilter::new().with_eq("a".into())).is_referential(),
      "`eq` beside `{operator}` is not a referential shape"
    );
  }

  // The bytes kind's eight, and the SHAPE is absent from the table on purpose: `K` decides whether
  // the column HAS a substring form, where this question is about which operators a filter SET. A
  // fixed column that named `contains` is refused at the crossing, so the two slots are asked here
  // under the shape that can hold them.
  let bytes: [Exclusion<BytesFilter<Vec<u8>>>; 8] = [
    ("ne", |f| f.with_ne(b"b".to_vec())),
    ("gt", |f| f.with_gt(b"b".to_vec())),
    ("gte", |f| f.with_gte(b"b".to_vec())),
    ("lt", |f| f.with_lt(b"b".to_vec())),
    ("lte", |f| f.with_lte(b"b".to_vec())),
    ("contains", |f| f.with_contains(b"b".to_vec())),
    ("not_contains", |f| f.with_not_contains(b"b".to_vec())),
    ("not_in", |f| f.with_not_in([b"b".to_vec()])),
  ];
  for (operator, set) in bytes {
    assert!(
      !set(BytesFilter::new().with_eq(b"a".to_vec())).is_referential(),
      "`eq` beside `{operator}` is not a referential shape"
    );
  }
}

// The gated vocabularies' rows. Each lives behind the feature that supplies its dependency, so the
// default build neither compiles nor needs them — which is the same statement the registrations
// make, asserted from the other side.
//
// Each test pins the two shapes the FILTER KIND decides (bare + nullable) and then CONSTRUCTS one
// through an operator that kind alone has. The construction is not redundant with the mapping: a row
// proves the type resolves, and only a call proves the operand type is usable — that
// `with_contains` accepts the foreign type by value, which is what a declaration will do.

#[cfg(feature = "smol_str")]
#[test]
fn smol_str_is_a_text_column() {
  use smol_str::SmolStr;

  same(
    core::marker::PhantomData::<Filter<SmolStr>>,
    core::marker::PhantomData::<TextFilter<SmolStr>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<SmolStr>>>,
    core::marker::PhantomData::<Nullable<TextFilter<SmolStr>>>,
  );
  // An affix operator, which is what `TextFilter` has and `BytesFilter` does not.
  assert!(
    !TextFilter::<SmolStr>::new()
      .with_starts_with(SmolStr::new("x"))
      .is_empty()
  );
}

#[test]
fn the_bytes_crates_blob_is_a_byte_column_and_its_buffer_is_not_a_column_at_all() {
  use bytes::Bytes;

  same(
    core::marker::PhantomData::<Filter<Bytes>>,
    core::marker::PhantomData::<BytesFilter<Bytes>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Bytes>>>,
    core::marker::PhantomData::<Nullable<BytesFilter<Bytes>>>,
  );
  // The default shape is `Variable`, so the row takes the byte-substring operator.
  assert!(
    !BytesFilter::<Bytes>::new()
      .with_contains(Bytes::from_static(b"x"))
      .is_empty()
  );
}

#[test]
fn smol_bytes_registers_one_name_per_face_at_the_crates_own_spelling() {
  // The ROOT spellings, which are what the household publishes: `smol_bytes::Bytes` and
  // `smol_bytes::Utf8Bytes` are the `shared` pair re-exported, and the strategy modules are an
  // allocation detail that never reaches a schema.
  same(
    core::marker::PhantomData::<Filter<smol_bytes::Bytes>>,
    core::marker::PhantomData::<BytesFilter<smol_bytes::shared::Bytes>>,
  );
  // The UTF-8 face goes to `TextFilter`, and this row is where that decision is pinned: re-pointing
  // it at `BytesFilter` reds this test.
  same(
    core::marker::PhantomData::<Filter<smol_bytes::Utf8Bytes>>,
    core::marker::PhantomData::<TextFilter<smol_bytes::shared::Utf8Bytes>>,
  );

  // …and the operands are usable, byte and text side.
  assert!(
    !BytesFilter::<smol_bytes::Bytes>::new()
      .with_contains(smol_bytes::Bytes::from_static(b"x"))
      .is_empty()
  );
  assert!(
    !TextFilter::<smol_bytes::Utf8Bytes>::new()
      .with_starts_with(smol_bytes::Utf8Bytes::from(String::from("x")))
      .is_empty()
  );
}

#[cfg(feature = "jiff")]
#[test]
fn the_four_orderable_jiff_types_are_scalar_columns() {
  use jiff::{
    Timestamp, Zoned,
    civil::{Date, Time},
    tz::TimeZone,
  };

  same(
    core::marker::PhantomData::<Filter<Timestamp>>,
    core::marker::PhantomData::<ScalarFilter<Timestamp>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Timestamp>>>,
    core::marker::PhantomData::<Nullable<ScalarFilter<Timestamp>>>,
  );
  same(
    core::marker::PhantomData::<Filter<Date>>,
    core::marker::PhantomData::<ScalarFilter<Date>>,
  );
  same(
    core::marker::PhantomData::<Filter<Time>>,
    core::marker::PhantomData::<ScalarFilter<Time>>,
  );
  same(
    core::marker::PhantomData::<Filter<Zoned>>,
    core::marker::PhantomData::<ScalarFilter<Zoned>>,
  );
  // The full `to_filter!` arm, so a list of instants is a list — the Rust half of it, at least. There
  // is no `DateTimeListFilter` wire row here, unlike `legacy/ingraph`.
  same(
    core::marker::PhantomData::<Filter<Vec<Timestamp>>>,
    core::marker::PhantomData::<ListFilter<Timestamp>>,
  );

  // …and the operands are usable, each through an ordering operator, which is the family these four
  // are registered FOR.
  assert!(
    !ScalarFilter::<Timestamp>::new()
      .with_gte(Timestamp::UNIX_EPOCH)
      .is_empty()
  );
  assert!(
    !ScalarFilter::<Date>::new()
      .with_lt(Date::constant(2026, 1, 1))
      .is_empty()
  );
  assert!(
    !ScalarFilter::<Time>::new()
      .with_gt(Time::midnight())
      .is_empty()
  );
  assert!(
    !ScalarFilter::<Zoned>::new()
      .with_in_([Timestamp::UNIX_EPOCH.to_zoned(TimeZone::UTC)])
      .is_empty()
  );
}

/// The zone is not part of a `Zoned` comparand, and this is the assertion the registration's doc
/// rests on: two spellings of one instant are ONE value to every operator, though they are two
/// strings on the wire.
///
/// Built from fixed offsets rather than from named zones, so it holds in a build that resolved jiff
/// without a time-zone database — `TimeZone::UTC` and `TimeZone::fixed` need none.
#[cfg(feature = "jiff")]
#[test]
fn a_zoned_operand_compares_by_instant_and_not_by_zone() {
  use jiff::{
    Timestamp, Zoned,
    tz::{Offset, TimeZone},
  };

  let utc: Zoned = Timestamp::UNIX_EPOCH.to_zoned(TimeZone::UTC);
  let shifted: Zoned = utc
    .timestamp()
    .to_zoned(TimeZone::fixed(Offset::constant(-5)));

  assert_eq!(utc, shifted);
  assert_eq!(utc.cmp(&shifted), core::cmp::Ordering::Equal);
  // …and they are not the same text, which is the whole reason this needs saying: a client that
  // sends one and stored the other still matches.
  assert_ne!(utc.to_string(), shifted.to_string());
}

/// The two jiff behaviours the `Span` refusal rests on, since an ABSENT registration has nothing
/// else to pin it: `compare` and the fieldwise equality disagree, and `compare` cannot answer at all
/// for a calendar unit without a reference date. Either of those alone is enough to leave the type
/// without a filter — a filter would have to pick one reading on the caller's behalf.
#[cfg(feature = "jiff")]
#[test]
fn a_span_has_no_single_comparison_to_filter_by() {
  use core::cmp::Ordering;

  use jiff::{ToSpan, civil::date};

  assert_eq!(
    120
      .minutes()
      .compare(2.hours())
      .expect("both are time units"),
    Ordering::Equal
  );
  assert_ne!(120.minutes().fieldwise(), 2.hours().fieldwise());

  // A calendar unit has no length until a date says so, and jiff refuses rather than averaging — so
  // the same pair of spans orders BOTH ways depending on the month it is asked about.
  assert!(1.month().compare(30.days()).is_err());
  assert_eq!(
    1.month()
      .compare((30.days(), date(2026, 1, 1)))
      .expect("a relative date answers it"),
    Ordering::Greater
  );
  assert_eq!(
    1.month()
      .compare((30.days(), date(2026, 2, 1)))
      .expect("a relative date answers it"),
    Ordering::Less
  );
}

// The duration kind. Behind `jiff` in full — type, registration and wire name — because its operand
// IS `jiff::SignedDuration`, so without the crate there is nothing for it to parse, render or hold,
// and an `i64` field with `ScalarFilter<i64>` is the ungated path for raw nanoseconds.

#[cfg(feature = "jiff")]
#[test]
fn duration_maps_to_a_filter_of_its_own() {
  use jiff::SignedDuration;

  use crate::DurationFilter;

  // NOT `ScalarFilter<SignedDuration>`: the kind is nominal so that it can carry its own wire rendering
  // and a body, and re-pointing this row at the generic filter reds the test.
  same(
    core::marker::PhantomData::<Filter<SignedDuration>>,
    core::marker::PhantomData::<DurationFilter>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<SignedDuration>>>,
    core::marker::PhantomData::<Nullable<DurationFilter>>,
  );
  // The full `to_filter!` arm: a list of durations is a list, like any other registration's.
  same(
    core::marker::PhantomData::<Filter<Vec<SignedDuration>>>,
    core::marker::PhantomData::<ListFilter<SignedDuration>>,
  );
  same(
    core::marker::PhantomData::<Filter<Option<Vec<SignedDuration>>>>,
    core::marker::PhantomData::<ListFilter<SignedDuration>>,
  );

  assert!(DurationFilter::new().is_empty());
  assert!(DurationFilter::default().is_empty());
  assert!(
    !DurationFilter::new()
      .with_gte(SignedDuration::from_secs(1))
      .is_empty()
  );
  assert!(
    !DurationFilter::new()
      .with_in_([SignedDuration::from_millis(500)])
      .is_empty()
  );
}