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
use std::marker::PhantomData;

use super::*;
use crate::graphql::carrier::Builtin;

/// The VARIABLE-WIDTH bytes filter — generic over the column's byte storage type `B` (`Vec<u8>`, a
/// `Bytes` newtype), mirroring polarsync's `ByteaFilter<I>`, and over the WIRE READING `I` its
/// operands cross under. Equality, ordering, membership, and byte-substring
/// `contains`/`not_contains` — and no affix operators, which a byte column has no use for.
/// Bound-free struct; the `AsRef<[u8]>` belongs on the lowering impls. `new()`/`Default` + the
/// `opt_accessor!` getter and writers per slot.
///
/// # The FIXED width is a different TYPE, not a parameter on this one
///
/// [`FixedBytesFilter<B, N, I>`](FixedBytesFilter) is the `N`-byte column's filter, and the two
/// differ in their SLOTS rather than in what a lowering does with them: a `BLOB` has
/// `instr`/`position`/`LOCATE` and a `BINARY(32)` has none of them, so the fixed type simply does
/// not carry the substring pair.
///
/// This crate carried the width as a shape PARAMETER — `BytesFilter<B, Variable | Fixed<N>, I>`,
/// ten slots for both, and a crossing that refused two of them by reading a monomorphized const.
/// What that arrangement published was a fixed-width input object advertising a `contains` field
/// that every request setting it was refused for. A door that always refuses is a door a schema
/// should not have; the split is that sentence made structural, and the refusal it replaces
/// (`BytesCrossingError::FixedSubstring`) is DELETED rather than moved — an unknown field is the
/// wire's own validation and it fires before any of this crate's code runs.
///
/// # The SECOND parameter, and what it is for
///
/// `I` names the reading the operands cross the wire under — see [`BytesWire`](crate::BytesWire) —
/// and it is what lets a DECLARING crate give its own byte newtype a wire face. The framework's wire
/// face is ONE generic row over `I`, so there is no second row for coherence to hit and the
/// PARAMETER renames nothing: [`Builtin`] carries `bytes::Bytes` under `BytesFilter`, which is the
/// roster's `bytes` row with the derivation applied — see [`roster`](crate::graphql::roster).
///
/// It DEFAULTS, so `BytesFilter<Vec<u8>>` is `BytesFilter<Vec<u8>, Builtin>`.
pub struct BytesFilter<B, I = Builtin> {
  pub(crate) eq: Option<B>,
  pub(crate) ne: Option<B>,
  pub(crate) gt: Option<B>,
  pub(crate) gte: Option<B>,
  pub(crate) lt: Option<B>,
  pub(crate) lte: Option<B>,
  pub(crate) contains: Option<B>,
  pub(crate) not_contains: Option<B>,
  pub(crate) in_: Option<Box<[B]>>,
  pub(crate) not_in: Option<Box<[B]>>,
  // `fn() -> I` (not a bare `I`) so the marker contributes no auto-trait or variance obligation:
  // the filter is `Send`/`Sync` on `B` alone, exactly as before the parameter existed.
  pub(crate) wire: PhantomData<fn() -> I>,
}

impl<B, I> BytesFilter<B, I> {
  /// The empty filter — no operator set.
  #[inline]
  pub const fn new() -> Self {
    Self {
      eq: None,
      ne: None,
      gt: None,
      gte: None,
      lt: None,
      lte: None,
      contains: None,
      not_contains: None,
      in_: None,
      not_in: None,
      wire: PhantomData,
    }
  }

  /// True while NO operator slot is set — so a lowering would emit nothing for this field.
  ///
  /// Inherent, not the backend traits' provided `is_empty`: "is anything set" is a property of the
  /// FILTER, identical on every backend, and asking it should not make a caller name a dialect (with
  /// two families compiled, `f.is_empty()` through the traits is `E0283`). The inherent method wins
  /// method resolution, so every call site reads the same either way.
  #[inline]
  pub const fn is_empty(&self) -> bool {
    self.eq.is_none()
      && self.ne.is_none()
      && self.gt.is_none()
      && self.gte.is_none()
      && self.lt.is_none()
      && self.lte.is_none()
      && self.contains.is_none()
      && self.not_contains.is_none()
      && self.in_.is_none()
      && self.not_in.is_none()
  }

  opt_accessor!(eq: B => with_eq, set_eq, maybe_eq, update_eq);
  opt_accessor!(ne: B => with_ne, set_ne, maybe_ne, update_ne);
  opt_accessor!(gt: B => with_gt, set_gt, maybe_gt, update_gt);
  opt_accessor!(gte: B => with_gte, set_gte, maybe_gte, update_gte);
  opt_accessor!(lt: B => with_lt, set_lt, maybe_lt, update_lt);
  opt_accessor!(lte: B => with_lte, set_lte, maybe_lte, update_lte);
  opt_accessor!(contains: B => with_contains, set_contains, maybe_contains, update_contains);
  opt_accessor!(
    not_contains: B => with_not_contains, set_not_contains, maybe_not_contains, update_not_contains
  );
  opt_accessor!(in_: [B] => with_in_, set_in_, maybe_in_, update_in_);
  opt_accessor!(not_in: [B] => with_not_in, set_not_in, maybe_not_in, update_not_in);

  /// True when this filter's ONLY set operator is a plain `eq` or a plain `in_` — the shape a
  /// relation may rewrite onto the PARENT's foreign key instead of running a subquery.
  ///
  /// Sound only under referential integrity: every fk references an existing child row, so
  /// `fk IN (SELECT key FROM child WHERE key = v)` is exactly `fk = v`. A negated shape
  /// (`ne`/`not_in`) is NOT equivalent under dangling references, an ordering operator does not
  /// name a single child row, and a byte-substring match names a set of them — so none of them ever
  /// collapses.
  ///
  /// The kind that answers with the fewest reservations, and the last of the four to be asked. A
  /// byte `eq` is bitwise on every backend — no collation, no case fold — so the assumption the
  /// collapse makes about two columns comparing alike is the assumption a byte column cannot get
  /// wrong, where [`TextFilter::is_referential`] carries that question as a recorded one. The
  /// omission was a legacy-wire artifact: text answered and bytes did not, which had the order
  /// backwards.
  #[inline]
  pub const fn is_referential(&self) -> bool {
    (self.eq.is_some() ^ self.in_.is_some())
      && self.ne.is_none()
      && self.gt.is_none()
      && self.gte.is_none()
      && self.lt.is_none()
      && self.lte.is_none()
      && self.contains.is_none()
      && self.not_contains.is_none()
      && self.not_in.is_none()
  }

  /// Convert every set operand with `f`, keeping the operator set exactly as it stands — see
  /// [`ScalarFilter::try_map`] for what this primitive is for and what it promises about lists.
  pub fn try_map<C, E, F>(self, mut f: F) -> Result<BytesFilter<C, I>, E>
  where
    F: FnMut(B) -> Result<C, E>,
  {
    Ok(BytesFilter {
      eq: map_operand(self.eq, &mut f)?,
      ne: map_operand(self.ne, &mut f)?,
      gt: map_operand(self.gt, &mut f)?,
      gte: map_operand(self.gte, &mut f)?,
      lt: map_operand(self.lt, &mut f)?,
      lte: map_operand(self.lte, &mut f)?,
      contains: map_operand(self.contains, &mut f)?,
      not_contains: map_operand(self.not_contains, &mut f)?,
      in_: map_operands(self.in_, &mut f)?,
      not_in: map_operands(self.not_in, &mut f)?,
      wire: PhantomData,
    })
  }
}

impl<B, I> Default for BytesFilter<B, I> {
  #[inline]
  fn default() -> Self {
    Self::new()
  }
}

/// The bound's row.
impl<B, C, I> TryMapFilter<B, C> for BytesFilter<B, I> {
  type Mapped = BytesFilter<C, I>;

  #[inline]
  fn try_map_filter<E, F>(self, f: F) -> Result<Self::Mapped, E>
  where
    F: FnMut(B) -> Result<C, E>,
  {
    self.try_map(f)
  }
}

/// The bound's row: `new()` and the inherent `with_eq`, reached where the kind is a parameter rather
/// than a spelling.
impl<B, I> EqualsFilter<B> for BytesFilter<B, I> {
  #[inline]
  fn equals(value: B) -> Self {
    Self::new().with_eq(value)
  }
}

impl<B, I> GraphqlFilter for BytesFilter<B, I> {
  #[inline]
  fn is_empty(&self) -> bool {
    Self::is_empty(self)
  }
}

// Hand-written: a derive would put `I: Debug`/`Clone`/`PartialEq` on the reading marker, which is
// uninhabited and implements none of them. `PhantomData` is `Copy`/`Eq` for every parameter.
impl<B: core::fmt::Debug, I> core::fmt::Debug for BytesFilter<B, I> {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    f.debug_struct("BytesFilter")
      .field("eq", &self.eq)
      .field("ne", &self.ne)
      .field("gt", &self.gt)
      .field("gte", &self.gte)
      .field("lt", &self.lt)
      .field("lte", &self.lte)
      .field("contains", &self.contains)
      .field("not_contains", &self.not_contains)
      .field("in_", &self.in_)
      .field("not_in", &self.not_in)
      .finish()
  }
}

impl<B: Clone, I> Clone for BytesFilter<B, I> {
  fn clone(&self) -> Self {
    Self {
      eq: self.eq.clone(),
      ne: self.ne.clone(),
      gt: self.gt.clone(),
      gte: self.gte.clone(),
      lt: self.lt.clone(),
      lte: self.lte.clone(),
      contains: self.contains.clone(),
      not_contains: self.not_contains.clone(),
      in_: self.in_.clone(),
      not_in: self.not_in.clone(),
      wire: PhantomData,
    }
  }
}

impl<B: PartialEq, I> PartialEq for BytesFilter<B, I> {
  fn eq(&self, other: &Self) -> bool {
    self.eq == other.eq
      && self.ne == other.ne
      && self.gt == other.gt
      && self.gte == other.gte
      && self.lt == other.lt
      && self.lte == other.lte
      && self.contains == other.contains
      && self.not_contains == other.not_contains
      && self.in_ == other.in_
      && self.not_in == other.not_in
  }
}

/// The FIXED-WIDTH bytes filter — exactly `N` bytes, over the same storage type `B` and the same
/// wire reading `I` its variable-width twin takes.
///
/// **EIGHT slots where [`BytesFilter`] has TEN, and the absence IS the ruling.** `contains` and
/// `not_contains` are byte-SUBSTRING matches; a fixed-width column stores a whole value of a known
/// width and no dialect in the SQL family has a substring form for one. The pair used to be on the
/// type for every shape and refused at the crossing, which published a schema field whose every use
/// was an error. Here there is no field to set: a request naming one is answered by async-graphql's
/// own unknown-field validation, before this crate's code runs, and the crossing has nothing left to
/// check.
///
/// # The WIDTH is the type's, and it is what names the face
///
/// `N` is a const parameter rather than a fact left in the Rust field type alone, so the one number
/// reaches the wire as well as the storage: this face publishes `Fixed{N}` in front of the reading's
/// name, which is why `[u8; 16]` is `Fixed16U8ArrayFilter` and `[u8; 32]` is
/// `Fixed32U8ArrayFilter`. A width is not a schema tag and never was; see the face below for the one
/// place the name is assembled.
///
/// # The shape, as the compiler sees it
///
/// A fixed-width byte column resolves to this type at ITS OWN width — the array's `N` and the
/// filter's are one number, and the field type is what supplies it:
///
/// ```
/// use ingraph::{DefaultMarker, FixedBytesFilter, ToGraphqlFilter};
///
/// // What an expansion writes for a field of type `T`: the type's interpretation, then that
/// // interpretation's filter.
/// type Column<T> = <<T as DefaultMarker>::Marker as ToGraphqlFilter>::Filter;
///
/// let f: Column<[u8; 32]> = FixedBytesFilter::<[u8; 32], 32>::new();
/// assert!(f.is_empty());
/// ```
///
/// and the WRONG width is a different type, so a 32-byte column cannot be handed a 16-byte column's
/// filter (`E0308`):
///
/// ```compile_fail,E0308
/// use ingraph::{DefaultMarker, FixedBytesFilter, ToGraphqlFilter};
///
/// type Column<T> = <<T as DefaultMarker>::Marker as ToGraphqlFilter>::Filter;
///
/// let f: Column<[u8; 32]> = FixedBytesFilter::new();
/// let _: FixedBytesFilter<[u8; 32], 16> = f;
/// ```
///
/// and it is not the variable-width filter, so a lowering cannot be handed one where it asked for
/// the other (`E0308`):
///
/// ```compile_fail,E0308
/// use ingraph::{BytesFilter, DefaultMarker, ToGraphqlFilter};
///
/// type Column<T> = <<T as DefaultMarker>::Marker as ToGraphqlFilter>::Filter;
///
/// let f: Column<[u8; 32]> = ingraph::FixedBytesFilter::new();
/// let _: BytesFilter<[u8; 32]> = f;
/// ```
///
/// The three earn their keep only together, for the reason [`Nullable`]'s pair does: stable rustdoc
/// runs a `compile_fail` block just far enough to see it fail and never checks WHY, so the negative
/// ones alone would still "pass" with `[u8; N]`'s registration deleted outright. The positive twin
/// shares that registration and must COMPILE.
pub struct FixedBytesFilter<B, const N: usize, I = Builtin> {
  pub(crate) eq: Option<B>,
  pub(crate) ne: Option<B>,
  pub(crate) gt: Option<B>,
  pub(crate) gte: Option<B>,
  pub(crate) lt: Option<B>,
  pub(crate) lte: Option<B>,
  pub(crate) in_: Option<Box<[B]>>,
  pub(crate) not_in: Option<Box<[B]>>,
  pub(crate) wire: PhantomData<fn() -> I>,
}

impl<B, const N: usize, I> FixedBytesFilter<B, N, I> {
  /// The empty filter — no operator set.
  #[inline]
  pub const fn new() -> Self {
    Self {
      eq: None,
      ne: None,
      gt: None,
      gte: None,
      lt: None,
      lte: None,
      in_: None,
      not_in: None,
      wire: PhantomData,
    }
  }

  /// True while NO operator slot is set — [`BytesFilter::is_empty`]'s reading, two slots shorter.
  #[inline]
  pub const fn is_empty(&self) -> bool {
    self.eq.is_none()
      && self.ne.is_none()
      && self.gt.is_none()
      && self.gte.is_none()
      && self.lt.is_none()
      && self.lte.is_none()
      && self.in_.is_none()
      && self.not_in.is_none()
  }

  opt_accessor!(eq: B => with_eq, set_eq, maybe_eq, update_eq);
  opt_accessor!(ne: B => with_ne, set_ne, maybe_ne, update_ne);
  opt_accessor!(gt: B => with_gt, set_gt, maybe_gt, update_gt);
  opt_accessor!(gte: B => with_gte, set_gte, maybe_gte, update_gte);
  opt_accessor!(lt: B => with_lt, set_lt, maybe_lt, update_lt);
  opt_accessor!(lte: B => with_lte, set_lte, maybe_lte, update_lte);
  opt_accessor!(in_: [B] => with_in_, set_in_, maybe_in_, update_in_);
  opt_accessor!(not_in: [B] => with_not_in, set_not_in, maybe_not_in, update_not_in);

  /// True when this filter's ONLY set operator is a plain `eq` or a plain `in_` — see
  /// [`BytesFilter::is_referential`], whose reading this is with the substring pair gone from the
  /// type rather than tested for.
  #[inline]
  pub const fn is_referential(&self) -> bool {
    (self.eq.is_some() ^ self.in_.is_some())
      && self.ne.is_none()
      && self.gt.is_none()
      && self.gte.is_none()
      && self.lt.is_none()
      && self.lte.is_none()
      && self.not_in.is_none()
  }

  /// Convert every set operand with `f`, keeping the operator set exactly as it stands.
  ///
  /// The WIDTH crosses unchanged. `N` says how the COLUMN is stored — exactly `N` bytes — which no
  /// operand conversion can alter, so mapping a fixed filter's operands into a different byte type
  /// yields a filter of the SAME width over that type and never a variable-width one.
  pub fn try_map<C, E, F>(self, mut f: F) -> Result<FixedBytesFilter<C, N, I>, E>
  where
    F: FnMut(B) -> Result<C, E>,
  {
    Ok(FixedBytesFilter {
      eq: map_operand(self.eq, &mut f)?,
      ne: map_operand(self.ne, &mut f)?,
      gt: map_operand(self.gt, &mut f)?,
      gte: map_operand(self.gte, &mut f)?,
      lt: map_operand(self.lt, &mut f)?,
      lte: map_operand(self.lte, &mut f)?,
      in_: map_operands(self.in_, &mut f)?,
      not_in: map_operands(self.not_in, &mut f)?,
      wire: PhantomData,
    })
  }
}

impl<B, const N: usize, I> Default for FixedBytesFilter<B, N, I> {
  #[inline]
  fn default() -> Self {
    Self::new()
  }
}

/// The bound's row. The WIDTH rides through untouched: `N` says how the column is declared and never
/// what an operand is made of, so converting the operands cannot move it.
impl<B, C, const N: usize, I> TryMapFilter<B, C> for FixedBytesFilter<B, N, I> {
  type Mapped = FixedBytesFilter<C, N, I>;

  #[inline]
  fn try_map_filter<E, F>(self, f: F) -> Result<Self::Mapped, E>
  where
    F: FnMut(B) -> Result<C, E>,
  {
    self.try_map(f)
  }
}

impl<B, const N: usize, I> EqualsFilter<B> for FixedBytesFilter<B, N, I> {
  #[inline]
  fn equals(value: B) -> Self {
    Self::new().with_eq(value)
  }
}

impl<B, const N: usize, I> GraphqlFilter for FixedBytesFilter<B, N, I> {
  #[inline]
  fn is_empty(&self) -> bool {
    Self::is_empty(self)
  }
}

impl<B: core::fmt::Debug, const N: usize, I> core::fmt::Debug for FixedBytesFilter<B, N, I> {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    f.debug_struct("FixedBytesFilter")
      .field("eq", &self.eq)
      .field("ne", &self.ne)
      .field("gt", &self.gt)
      .field("gte", &self.gte)
      .field("lt", &self.lt)
      .field("lte", &self.lte)
      .field("in_", &self.in_)
      .field("not_in", &self.not_in)
      .finish()
  }
}

impl<B: Clone, const N: usize, I> Clone for FixedBytesFilter<B, N, I> {
  fn clone(&self) -> Self {
    Self {
      eq: self.eq.clone(),
      ne: self.ne.clone(),
      gt: self.gt.clone(),
      gte: self.gte.clone(),
      lt: self.lt.clone(),
      lte: self.lte.clone(),
      in_: self.in_.clone(),
      not_in: self.not_in.clone(),
      wire: PhantomData,
    }
  }
}

impl<B: PartialEq, const N: usize, I> PartialEq for FixedBytesFilter<B, N, I> {
  fn eq(&self, other: &Self) -> bool {
    self.eq == other.eq
      && self.ne == other.ne
      && self.gt == other.gt
      && self.gte == other.gte
      && self.lt == other.lt
      && self.lte == other.lte
      && self.in_ == other.in_
      && self.not_in == other.not_in
  }
}

/// A byte filter's operator slots, gathered — the two a fixed-width column has no field for
/// arriving as [`None`].
///
/// Not a filter and not a comparison: the tuple a crossing moves between them, so that ONE entry
/// point can take both byte kinds. See [`ByteSlots`].
// Gated with the only thing that spends it. A CROSSING is what gathers slots, and a build with no
// backend has no crossing — so this pair rides the backend words rather than shipping as a gather
// nothing reads.
#[cfg(any(feature = "mongo", feature = "sqlx"))]
pub(crate) struct ByteOperands<B> {
  pub(crate) eq: Option<B>,
  pub(crate) ne: Option<B>,
  pub(crate) gt: Option<B>,
  pub(crate) gte: Option<B>,
  pub(crate) lt: Option<B>,
  pub(crate) lte: Option<B>,
  // THE SUBSTRING PAIR IS READ BY ONE FAMILY AND NOT THE OTHER, and the gather keeps both slots
  // anyway: its shape mirrors `BytesFilter`'s ten so that ONE crossing entry can take both byte
  // kinds, and a gather whose fields came and went with a backend word would stop being that
  // neutral tuple. The SQL crossing carries all ten across
  // (`comparison::sql::bytes::try_from_filter_with`); the MongoDB one carries EIGHT and refuses a
  // set substring UPSTREAM of the gather (`MongoBytesCrossingError::Substring`), so on a build with
  // the second backend and not the first these two are written and never read.
  //
  // `expect` under a `cfg_attr` rather than `allow`, and never unconditionally: with `sqlx` on the
  // fields ARE read, and an unfulfilled expectation is itself a warning under the same
  // `-D warnings` — so the suppression is scoped to exactly the builds that need it and stays
  // self-policing in the rest. If a MongoDB path ever starts reading them, the mongo-only lanes say
  // so.
  #[cfg_attr(
    not(feature = "sqlx"),
    expect(
      dead_code,
      reason = "only the SQL crossing carries the substring pair; see above"
    )
  )]
  pub(crate) contains: Option<B>,
  #[cfg_attr(
    not(feature = "sqlx"),
    expect(
      dead_code,
      reason = "only the SQL crossing carries the substring pair; see above"
    )
  )]
  pub(crate) not_contains: Option<B>,
  pub(crate) in_: Option<Box<[B]>>,
  pub(crate) not_in: Option<Box<[B]>>,
}

/// **WHY THE TWO BYTE KINDS SHARE ONE CROSSING ENTRY**, stated as a seam.
///
/// A comparison's `try_from_filter_with` is what an EMITTED crossing calls, and that emission is
/// type-blind: `emit::cross` writes `<Comparison>::try_from_filter_with(filter, converter)` for a
/// column's filter whatever that filter is, having only the projection to name it by. Both byte
/// kinds project to the same comparison — a storage side reads no width — so a second METHOD NAME
/// for the fixed kind would be a branch the emitter cannot take. One name, one bound, two
/// implementors.
///
/// `pub(crate)`: a declaring crate never implements this. Its own byte newtype is a MINTED filter
/// wrapping one of these two, and what it hands a crossing is [`TryMapFilter`], whose `Mapped` is
/// the framework kind that carries this row.
#[cfg(any(feature = "mongo", feature = "sqlx"))]
pub(crate) trait ByteSlots<B> {
  /// The slots, consumed — a fixed-width filter's substring pair is `None` because it has no field
  /// to be anything else.
  fn byte_operands(self) -> ByteOperands<B>;
}

#[cfg(any(feature = "mongo", feature = "sqlx"))]
impl<B, I> ByteSlots<B> for BytesFilter<B, I> {
  #[inline]
  fn byte_operands(self) -> ByteOperands<B> {
    ByteOperands {
      eq: self.eq,
      ne: self.ne,
      gt: self.gt,
      gte: self.gte,
      lt: self.lt,
      lte: self.lte,
      contains: self.contains,
      not_contains: self.not_contains,
      in_: self.in_,
      not_in: self.not_in,
    }
  }
}

#[cfg(any(feature = "mongo", feature = "sqlx"))]
impl<B, const N: usize, I> ByteSlots<B> for FixedBytesFilter<B, N, I> {
  #[inline]
  fn byte_operands(self) -> ByteOperands<B> {
    ByteOperands {
      eq: self.eq,
      ne: self.ne,
      gt: self.gt,
      gte: self.gte,
      lt: self.lt,
      lte: self.lte,
      // NOT a drop: this kind has no such field, so there is nothing here to lose. That is the
      // whole difference the split bought — the pair used to be carried and refused.
      contains: None,
      not_contains: None,
      in_: self.in_,
      not_in: self.not_in,
    }
  }
}

/// The field list the VARIABLE face registers, in declaration order.
///
/// One function read by the face and by its [`NullableFace`](crate::NullableFace) row alike, so
/// *the nullable face is the bare face's fields plus the null test* is one list read twice.
///
/// Every slot is typed `I::Carrier`, which is what admits a blob at all: `Vec<u8>` HAS an
/// `async_graphql::InputType` and it answers the wrong question — `[Int!]`, a list of small integers
/// where the column is a thumbnail — so the operand's own face is exactly what this face does not
/// ask for.
#[cfg(feature = "async-graphql")]
fn bytes_fields<B, I>(
  registry: &mut async_graphql::registry::Registry,
) -> async_graphql::indexmap::IndexMap<::std::string::String, async_graphql::registry::MetaInputValue>
where
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  __ingraph_filter_input_fields!(
    registry,
    "eq" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "ne" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "gt" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "gte" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "lt" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "lte" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "contains" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "notContains" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "in" : ::core::option::Option<::std::boxed::Box<[<I as crate::BytesWire<B>>::Carrier]>>,
    "notIn" : ::core::option::Option<::std::boxed::Box<[<I as crate::BytesWire<B>>::Carrier]>>,
  )
}

/// The object the variable face renders — the same ten names in the same order the registration
/// declares.
#[cfg(feature = "async-graphql")]
fn bytes_values<B, I>(
  filter: &BytesFilter<B, I>,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value>
where
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  let mut map = async_graphql::indexmap::IndexMap::new();
  map.insert(
    async_graphql::Name::new("eq"),
    via::carried(&filter.eq, I::carry),
  );
  map.insert(
    async_graphql::Name::new("ne"),
    via::carried(&filter.ne, I::carry),
  );
  map.insert(
    async_graphql::Name::new("gt"),
    via::carried(&filter.gt, I::carry),
  );
  map.insert(
    async_graphql::Name::new("gte"),
    via::carried(&filter.gte, I::carry),
  );
  map.insert(
    async_graphql::Name::new("lt"),
    via::carried(&filter.lt, I::carry),
  );
  map.insert(
    async_graphql::Name::new("lte"),
    via::carried(&filter.lte, I::carry),
  );
  map.insert(
    async_graphql::Name::new("contains"),
    via::carried(&filter.contains, I::carry),
  );
  map.insert(
    async_graphql::Name::new("notContains"),
    via::carried(&filter.not_contains, I::carry),
  );
  map.insert(
    async_graphql::Name::new("in"),
    via::carried_list(&filter.in_, I::carry),
  );
  map.insert(
    async_graphql::Name::new("notIn"),
    via::carried_list(&filter.not_in, I::carry),
  );
  map
}

/// The field list the FIXED face registers — [`bytes_fields`]'s list with the substring pair absent.
///
/// The absence is the whole of the ruling and it is spelled HERE, once: a name a face does not
/// register is a name async-graphql answers with its own unknown-field error, so the fixed column's
/// refusal costs this crate nothing to state and nothing to keep in step.
#[cfg(feature = "async-graphql")]
fn fixed_bytes_fields<B, I>(
  registry: &mut async_graphql::registry::Registry,
) -> async_graphql::indexmap::IndexMap<::std::string::String, async_graphql::registry::MetaInputValue>
where
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  __ingraph_filter_input_fields!(
    registry,
    "eq" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "ne" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "gt" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "gte" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "lt" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "lte" : ::core::option::Option<<I as crate::BytesWire<B>>::Carrier>,
    "in" : ::core::option::Option<::std::boxed::Box<[<I as crate::BytesWire<B>>::Carrier]>>,
    "notIn" : ::core::option::Option<::std::boxed::Box<[<I as crate::BytesWire<B>>::Carrier]>>,
  )
}

/// The object the fixed face renders — the same eight names in the same order.
#[cfg(feature = "async-graphql")]
fn fixed_bytes_values<B, const N: usize, I>(
  filter: &FixedBytesFilter<B, N, I>,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value>
where
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  let mut map = async_graphql::indexmap::IndexMap::new();
  map.insert(
    async_graphql::Name::new("eq"),
    via::carried(&filter.eq, I::carry),
  );
  map.insert(
    async_graphql::Name::new("ne"),
    via::carried(&filter.ne, I::carry),
  );
  map.insert(
    async_graphql::Name::new("gt"),
    via::carried(&filter.gt, I::carry),
  );
  map.insert(
    async_graphql::Name::new("gte"),
    via::carried(&filter.gte, I::carry),
  );
  map.insert(
    async_graphql::Name::new("lt"),
    via::carried(&filter.lt, I::carry),
  );
  map.insert(
    async_graphql::Name::new("lte"),
    via::carried(&filter.lte, I::carry),
  );
  map.insert(
    async_graphql::Name::new("in"),
    via::carried_list(&filter.in_, I::carry),
  );
  map.insert(
    async_graphql::Name::new("notIn"),
    via::carried_list(&filter.not_in, I::carry),
  );
  map
}

/// The VARIABLE WIRE FACE — ONE generic impl over the reading, where this crate carried a single
/// concrete registration and four byte vocabularies had none at all.
///
/// # What one row buys that one concrete row could not
///
/// `Vec<u8>` was registered and `bytes::Bytes`, the `smol_bytes` trio and `[u8; N]` were not — each
/// wanting a concrete impl only this crate could write, and none of them having been asked for. A
/// DECLARING crate's own digest was worse off than that: `impl InputType for BytesFilter<Sum>` is
/// `E0117` there, and a generic row here would have overlapped the concrete one (`E0119`). Every row
/// is a [`BytesWire`](crate::BytesWire) row on [`Builtin`] now, so the framework's absences are one
/// line each and a declarer's own operand joins by writing that trait on a marker it owns.
///
/// # The NAME is the reading's, undecorated
///
/// A blob publishes exactly what its row says. The width that used to decorate this name belongs to
/// [`FixedBytesFilter`] now and is spelled at that face, which is why the pair a shape-blind name
/// would have put under one GraphQL type is two types under two names — and why neither of them has
/// to ask the other what it published.
///
/// The rest of the reasoning is [`ScalarFilter`]'s, one kind over: the NAME comes from the reading,
/// the bound is the reading and not `B: InputType`, and `B: Send + Sync` is `InputType`'s own
/// supertrait reaching the operand through the ten slots.
#[cfg(feature = "async-graphql")]
impl<B, I> async_graphql::InputType for BytesFilter<B, I>
where
  B: Send + Sync,
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  type RawValueType = Self;

  #[inline]
  fn type_name() -> ::std::borrow::Cow<'static, str> {
    ::std::borrow::Cow::Borrowed(<I as crate::BytesWire<B>>::NAME)
  }

  fn create_type_info(registry: &mut async_graphql::registry::Registry) -> ::std::string::String {
    registry.create_input_type::<Self, _>(
      async_graphql::registry::MetaTypeId::InputObject,
      // The name the face ADVERTISES, read back rather than re-assembled: one spelling is what
      // keeps the registry entry and `type_name` from being two strings.
      |registry| async_graphql::registry::MetaType::InputObject {
        name: ::std::borrow::Cow::into_owned(<Self as async_graphql::InputType>::type_name()),
        description: ::std::option::Option::None,
        input_fields: bytes_fields::<B, I>(registry),
        visible: ::std::option::Option::None,
        inaccessible: false,
        tags: ::std::vec::Vec::new(),
        rust_typename: ::std::option::Option::Some(::std::any::type_name::<Self>()),
        oneof: false,
        directive_invocations: ::std::vec::Vec::new(),
      },
    )
  }

  /// The SHORTHAND LAW at the byte face — rule ①, a bare value under `eq`, crossing the reading's
  /// carrier exactly as the longhand's does.
  fn parse(
    value: ::std::option::Option<async_graphql::Value>,
  ) -> async_graphql::InputValueResult<Self> {
    let object = match super::sent(value) {
      super::Sent::Longhand(object) => object,
      super::Sent::Bare(bare) => {
        let mut object = async_graphql::indexmap::IndexMap::new();
        object.insert(async_graphql::Name::new("eq"), bare);
        object
      }
      super::Sent::Null => {
        return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(
          async_graphql::Value::Null,
        ));
      }
      super::Sent::Refused(sent) => {
        return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(sent));
      }
    };
    ::std::result::Result::Ok(Self {
      eq: via::crossed::<_, _, _, Self>(&object, "eq", I::cross)?,
      ne: via::crossed::<_, _, _, Self>(&object, "ne", I::cross)?,
      gt: via::crossed::<_, _, _, Self>(&object, "gt", I::cross)?,
      gte: via::crossed::<_, _, _, Self>(&object, "gte", I::cross)?,
      lt: via::crossed::<_, _, _, Self>(&object, "lt", I::cross)?,
      lte: via::crossed::<_, _, _, Self>(&object, "lte", I::cross)?,
      contains: via::crossed::<_, _, _, Self>(&object, "contains", I::cross)?,
      not_contains: via::crossed::<_, _, _, Self>(&object, "notContains", I::cross)?,
      in_: via::crossed_list::<_, _, _, Self>(&object, "in", I::cross)?,
      not_in: via::crossed_list::<_, _, _, Self>(&object, "notIn", I::cross)?,
      wire: PhantomData,
    })
  }

  fn to_value(&self) -> async_graphql::Value {
    async_graphql::Value::Object(bytes_values::<B, I>(self))
  }

  #[inline]
  fn as_raw_value(&self) -> ::std::option::Option<&Self::RawValueType> {
    ::std::option::Option::Some(self)
  }
}

#[cfg(feature = "async-graphql")]
impl<B, I> async_graphql::InputObjectType for BytesFilter<B, I>
where
  B: Send + Sync,
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
}

/// The NULLABLE row — the two pieces [`Nullable`]'s own blanket assembles this kind's twin from.
#[cfg(feature = "async-graphql")]
impl<B, I> crate::NullableFace for BytesFilter<B, I>
where
  B: Send + Sync,
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  fn bare_fields(
    registry: &mut async_graphql::registry::Registry,
  ) -> async_graphql::indexmap::IndexMap<
    ::std::string::String,
    async_graphql::registry::MetaInputValue,
  > {
    bytes_fields::<B, I>(registry)
  }

  fn bare_values(
    &self,
  ) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value> {
    bytes_values::<B, I>(self)
  }
}

/// The FIXED WIRE FACE — the variable one's row, over eight slots and under a decorated name.
///
/// # The WIDTH names the type, and this is the ONE place it is assembled
///
/// `Fixed{N}` in front of the reading's name, so `[u8; 16]` publishes `Fixed16U8ArrayFilter` and
/// `[u8; 32]` publishes `Fixed32U8ArrayFilter` out of one literal and one const parameter. A row per
/// width would be a table with no bound on its length. The [`Nullable`](crate::Nullable) twin
/// composes on top of the result exactly as it does over every other kind, which is what makes
/// `Option<[u8; 32]>` publish `NullableFixed32U8ArrayFilter` with no third literal anywhere.
///
/// A blob pays NOTHING for this: its face borrows the `&'static str` the reading already held, and
/// the allocation is the fixed width's alone. `type_name()` runs when a schema is built and when an
/// error is formatted, never on a query path.
///
/// # The two substring slots are not registered, and no request can reach them
///
/// See the type's own note. What used to be a runtime refusal reading a monomorphized const is now
/// an absent field, which is the earliest place a wrong question can be answered.
#[cfg(feature = "async-graphql")]
impl<B, const N: usize, I> async_graphql::InputType for FixedBytesFilter<B, N, I>
where
  B: Send + Sync,
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  type RawValueType = Self;

  #[inline]
  fn type_name() -> ::std::borrow::Cow<'static, str> {
    ::std::borrow::Cow::Owned(::std::format!(
      "Fixed{N}{}",
      <I as crate::BytesWire<B>>::NAME
    ))
  }

  fn create_type_info(registry: &mut async_graphql::registry::Registry) -> ::std::string::String {
    registry.create_input_type::<Self, _>(
      async_graphql::registry::MetaTypeId::InputObject,
      |registry| async_graphql::registry::MetaType::InputObject {
        name: ::std::borrow::Cow::into_owned(<Self as async_graphql::InputType>::type_name()),
        description: ::std::option::Option::None,
        input_fields: fixed_bytes_fields::<B, I>(registry),
        visible: ::std::option::Option::None,
        inaccessible: false,
        tags: ::std::vec::Vec::new(),
        rust_typename: ::std::option::Option::Some(::std::any::type_name::<Self>()),
        oneof: false,
        directive_invocations: ::std::vec::Vec::new(),
      },
    )
  }

  /// The SHORTHAND LAW at the fixed byte face — rule ①, unchanged: a bare value is an `eq`.
  fn parse(
    value: ::std::option::Option<async_graphql::Value>,
  ) -> async_graphql::InputValueResult<Self> {
    let object = match super::sent(value) {
      super::Sent::Longhand(object) => object,
      super::Sent::Bare(bare) => {
        let mut object = async_graphql::indexmap::IndexMap::new();
        object.insert(async_graphql::Name::new("eq"), bare);
        object
      }
      super::Sent::Null => {
        return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(
          async_graphql::Value::Null,
        ));
      }
      super::Sent::Refused(sent) => {
        return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(sent));
      }
    };
    ::std::result::Result::Ok(Self {
      eq: via::crossed::<_, _, _, Self>(&object, "eq", I::cross)?,
      ne: via::crossed::<_, _, _, Self>(&object, "ne", I::cross)?,
      gt: via::crossed::<_, _, _, Self>(&object, "gt", I::cross)?,
      gte: via::crossed::<_, _, _, Self>(&object, "gte", I::cross)?,
      lt: via::crossed::<_, _, _, Self>(&object, "lt", I::cross)?,
      lte: via::crossed::<_, _, _, Self>(&object, "lte", I::cross)?,
      in_: via::crossed_list::<_, _, _, Self>(&object, "in", I::cross)?,
      not_in: via::crossed_list::<_, _, _, Self>(&object, "notIn", I::cross)?,
      wire: PhantomData,
    })
  }

  fn to_value(&self) -> async_graphql::Value {
    async_graphql::Value::Object(fixed_bytes_values::<B, N, I>(self))
  }

  #[inline]
  fn as_raw_value(&self) -> ::std::option::Option<&Self::RawValueType> {
    ::std::option::Option::Some(self)
  }
}

#[cfg(feature = "async-graphql")]
impl<B, const N: usize, I> async_graphql::InputObjectType for FixedBytesFilter<B, N, I>
where
  B: Send + Sync,
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
}

/// The NULLABLE row — the fixed face's fields plus the null test, one list read twice.
#[cfg(feature = "async-graphql")]
impl<B, const N: usize, I> crate::NullableFace for FixedBytesFilter<B, N, I>
where
  B: Send + Sync,
  I: crate::BytesWire<B>,
  I::Carrier: async_graphql::InputType,
{
  fn bare_fields(
    registry: &mut async_graphql::registry::Registry,
  ) -> async_graphql::indexmap::IndexMap<
    ::std::string::String,
    async_graphql::registry::MetaInputValue,
  > {
    fixed_bytes_fields::<B, I>(registry)
  }

  fn bare_values(
    &self,
  ) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value> {
    fixed_bytes_values::<B, N, I>(self)
  }
}