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
//! OCPQ (Object-Centric Process Query) shapes — **query structure only, no execution**.
//!
//! This module represents the *shape* of an object-centric process query: an
//! object scope plus a tree of predicates (event, object, relation, temporal,
//! cardinality, nested) that together form a constraint over an OCEL log.
//!
//! ## What this module **IS**
//!
//! - The structural vocabulary of OCPQ: [`crate::ocpq::ObjectScope`], [`crate::ocpq::Predicate`],
//! [`crate::ocpq::OcpqQuery`], and the predicate witness markers ([`crate::ocpq::EventPredicate`],
//! [`crate::ocpq::ObjectPredicate`], [`crate::ocpq::RelationPredicate`], [`crate::ocpq::TemporalPredicate`],
//! [`crate::ocpq::CardinalityPredicate`], [`crate::ocpq::NestedQuery`], [`crate::ocpq::Constraint`]).
//! - A first-class [`crate::ocpq::OcpqRefusal`] surface naming exactly why a query shape is
//! inadmissible.
//!
//! ## What this module is **NOT**
//!
//! - **Not** a query planner, evaluator, or execution engine. It builds and
//! refuses *query shapes*; it never *runs* them against a log.
//! - **Not** a flattening tool. Any projection that would require flattening the
//! object-centric log is refused with [`crate::ocpq::OcpqRefusal::FlatteningRequired`].
//!
//! ## Graduation
//!
//! When you need to **evaluate, plan, or optimize** an OCPQ query against an
//! OCEL log, graduate this shape to the `wasm4pm` engine (via the `wasm4pm`
//! feature). This module only certifies that the *query structure* is
//! well-formed.
use ConstParamTy;
use PhantomData;
// ── Object scope const-param kind ───────────────────────────────────────────
/// The binding strategy of an [`ObjectScopeConst`] — whether the scope is
/// open (any object type may match), closed (only declared types are in scope),
/// or typed to a single object type.
///
/// Used as a const generic parameter on [`ObjectScopeConst`] so that a function
/// requiring a `{OcpqScopeKind::Closed}` scope cannot silently receive an
/// `{OcpqScopeKind::Open}` scope at the type level.
///
/// Structure-only: names the scope strategy. Resolving scope membership against
/// an OCEL log graduates to `wasm4pm`.
/// A typed object scope with the scope strategy encoded as a const generic
/// parameter.
///
/// `ObjectScopeConst<{OcpqScopeKind::Closed}>` and
/// `ObjectScopeConst<{OcpqScopeKind::Open}>` are **different types** at
/// compile time — a function that requires a closed scope rejects an open
/// scope with a type error rather than a runtime refusal.
///
/// Structure-only: the scope is a list of declared object-type names and a
/// const kind. Scope resolution against an OCEL log graduates to `wasm4pm`.
///
/// ```
/// use wasm4pm_compat::ocpq::{ObjectScopeConst, OcpqScopeKind};
/// let s = ObjectScopeConst::<{ OcpqScopeKind::Closed }>::new(["order", "item"]);
/// assert_eq!(s.object_types(), &["order".to_string(), "item".to_string()]);
/// ```
extern crate alloc;
// ── Predicate family const-param kinds ──────────────────────────────────────
/// The structural sub-kind of an event predicate.
///
/// OCPQ Section 3 defines three distinct event-predicate shapes:
/// - [`EventPredicateKind::ActivityEquals`] — the event activity label matches
/// a literal string.
/// - [`EventPredicateKind::AttributeEquals`] — a named event attribute matches
/// a literal value.
/// - [`EventPredicateKind::TimestampInRange`] — the event's timestamp lies in
/// a declared interval.
///
/// Used as a const generic parameter on [`TypedEventPredicate`] so that an
/// activity-equals slot cannot silently receive an attribute-equals predicate.
///
/// Structure-only: names the sub-kind. Expression evaluation graduates to
/// `wasm4pm`.
/// The structural sub-kind of an object predicate.
///
/// OCPQ Section 3 defines two distinct object-predicate shapes:
/// - [`ObjectPredicateKind::AttributeEquals`] — a named object attribute
/// matches a literal value.
/// - [`ObjectPredicateKind::TypeEquals`] — the object's declared type matches
/// a string.
///
/// Used as a const generic parameter on [`TypedObjectPredicate`].
///
/// Structure-only: names the sub-kind. Resolution graduates to `wasm4pm`.
/// A typed event predicate with its sub-kind encoded as a const generic parameter.
///
/// `TypedEventPredicate<{EventPredicateKind::ActivityEquals}>` and
/// `TypedEventPredicate<{EventPredicateKind::AttributeEquals}>` are **different
/// types** — the wrong sub-kind passed to a function requiring a specific kind
/// is a compile error, not a runtime failure.
///
/// Structure-only: carries the predicate expression as a string; evaluation
/// graduates to `wasm4pm`.
///
/// ```
/// use wasm4pm_compat::ocpq::{TypedEventPredicate, EventPredicateKind};
/// let p = TypedEventPredicate::<{ EventPredicateKind::ActivityEquals }>::new("approve");
/// assert_eq!(p.expression(), "approve");
/// assert_eq!(p.kind(), EventPredicateKind::ActivityEquals);
/// ```
/// A typed object predicate with its sub-kind encoded as a const generic parameter.
///
/// `TypedObjectPredicate<{ObjectPredicateKind::AttributeEquals}>` and
/// `TypedObjectPredicate<{ObjectPredicateKind::TypeEquals}>` are **different
/// types** — the wrong sub-kind is a compile error, not a runtime failure.
///
/// Structure-only: carries the predicate expression as a string; evaluation
/// graduates to `wasm4pm`.
///
/// ```
/// use wasm4pm_compat::ocpq::{TypedObjectPredicate, ObjectPredicateKind};
/// let p = TypedObjectPredicate::<{ ObjectPredicateKind::TypeEquals }>::new("order");
/// assert_eq!(p.expression(), "order");
/// assert_eq!(p.kind(), ObjectPredicateKind::TypeEquals);
/// ```
/// The structural sub-kind of a relation predicate.
///
/// OCPQ Section 4 (BASIC_L) defines three distinct relation predicate shapes:
/// - [`RelationPredicateKind::E2O`] — event-to-object link (E2O).
/// - [`RelationPredicateKind::O2O`] — object-to-object link (O2O).
/// - [`RelationPredicateKind::TimeBetweenEvents`] — time-between-events (TBE).
///
/// These map exactly to the [`PredicateKind::E2ORelation`],
/// [`PredicateKind::O2ORelation`], and [`PredicateKind::TimeBetweenEvents`]
/// runtime variants, but as a const-param so functions requiring a specific
/// relation type receive a type error if given the wrong one.
///
/// Structure-only: names the sub-kind. Link resolution and temporal evaluation
/// graduate to `wasm4pm`.
/// A typed relation predicate with its sub-kind encoded as a const generic parameter.
///
/// `TypedRelationPredicate<{RelationPredicateKind::E2O}>` and
/// `TypedRelationPredicate<{RelationPredicateKind::O2O}>` are **different
/// types** — the wrong link direction is a compile error, not a runtime failure.
///
/// Structure-only: carries the predicate expression as a string; link resolution
/// graduates to `wasm4pm`.
///
/// ```
/// use wasm4pm_compat::ocpq::{TypedRelationPredicate, RelationPredicateKind};
/// let p = TypedRelationPredicate::<{ RelationPredicateKind::E2O }>::new("e1 → o1 [order]");
/// assert_eq!(p.kind(), RelationPredicateKind::E2O);
/// ```
// ── Predicate witness markers ───────────────────────────────────────────────
/// Witness: a predicate over a single **event**.
;
/// Witness: a predicate over a single **object**.
;
/// Witness: a predicate over an **event-object relation** (an E2O / O2O link).
;
/// Witness: a predicate over **temporal** ordering or duration.
;
/// Witness: a predicate over **cardinality** (a count bound on a relation).
;
/// Witness: a predicate that **nests** another [`OcpqQuery`].
;
/// Witness: a top-level **constraint** built from one or more predicates.
;
// ── Sealed predicate-family trait ────────────────────────────────────────────
/// Sealed trait — only the seven canonical OCPQ predicate witness markers
/// satisfy this bound.
///
/// `IsOcpqPredicate` prevents arbitrary user-defined types from being used as
/// predicate witnesses in functions that require a genuine OCPQ predicate family.
/// The seven sealed implementations correspond to the seven witness markers:
/// [`EventPredicate`], [`ObjectPredicate`], [`RelationPredicate`],
/// [`TemporalPredicate`], [`CardinalityPredicate`], [`NestedQuery`],
/// [`Constraint`].
///
/// ## Structure-only
///
/// This trait has no associated methods — it is a compile-time membership
/// certificate, not a behavior surface.
///
/// ```
/// use wasm4pm_compat::ocpq::{EventPredicate, ObjectPredicate, IsOcpqPredicate};
/// fn needs_predicate<W: IsOcpqPredicate>() {}
/// needs_predicate::<EventPredicate>();
/// needs_predicate::<ObjectPredicate>();
/// ```
///
/// ```compile_fail
/// use wasm4pm_compat::ocpq::IsOcpqPredicate;
/// struct NotAPredicate;
/// fn needs_predicate<W: IsOcpqPredicate>() {}
/// needs_predicate::<NotAPredicate>();
/// ```
// ── Core shapes ─────────────────────────────────────────────────────────────
/// The object scope a query ranges over: the object types it binds.
///
/// **Structure only**: records *which object types* the query speaks about; it
/// never *resolves* them against a log.
/// The structural kind of an OCPQ predicate.
///
/// **Structure only**: records *what the predicate asserts*. It does NOT parse
/// or evaluate the predicate.
///
/// OCPQ Section 4 (BASIC_L) defines three typed relation predicate kinds:
/// [`PredicateKind::E2ORelation`], [`PredicateKind::O2ORelation`], and
/// [`PredicateKind::TimeBetweenEvents`]. These replace the opaque
/// `Relation(String)` / `Temporal(String)` placeholders and name the three
/// structurally distinct link types so they cannot be confused at the call site.
///
/// Section 4 also introduces CHILD SET predicates:
/// [`PredicateKind::ChildSetBound`] carries a named branch label with a count
/// bound, distinguishing it from the anonymous [`PredicateKind::Cardinality`].
/// A single OCPQ predicate, tagged with a witness `W`.
///
/// The witness `W` is a zero-sized marker (e.g. [`EventPredicate`]) recording
/// the predicate family at the type level. It carries no evaluation behavior.
/// A complete OCPQ query: an object scope plus a set of predicates and any
/// nested sub-queries.
///
/// The top-level **shape** of an object-centric process query. It does **NOT**
/// plan, evaluate, or optimize the query. Graduate to `wasm4pm` for execution.
/// A typed OCPQ query with the scope binding strategy encoded as a const generic
/// parameter.
///
/// `OcpqQueryConst<{OcpqScopeKind::Closed}>` and
/// `OcpqQueryConst<{OcpqScopeKind::Open}>` are **different types** — a function
/// requiring a closed-scope query rejects an open-scope query at compile time
/// rather than at runtime.
///
/// The predicates are still dynamically constructed (runtime `Vec`) because OCPQ
/// query bodies are composed at runtime; only the *scope strategy* is statically
/// enforced. Graduate to `wasm4pm` for evaluation against a log.
///
/// ## Difference from [`OcpqQuery`]
///
/// [`OcpqQuery`] uses a runtime [`ObjectScope`] and does not encode scope kind
/// at the type level. `OcpqQueryConst` adds the const-generic scope kind and uses
/// [`ObjectScopeConst`] so the scope strategy is part of the type signature.
///
/// Structure-only: the query shape. No query planning or evaluation.
///
/// ```
/// use wasm4pm_compat::ocpq::{OcpqQueryConst, ObjectScopeConst, OcpqScopeKind};
/// let q = OcpqQueryConst::<{ OcpqScopeKind::Closed }>::new(
/// ObjectScopeConst::<{ OcpqScopeKind::Closed }>::new(["order", "item"]),
/// );
/// assert_eq!(q.scope().object_types(), &["order".to_string(), "item".to_string()]);
/// assert_eq!(q.scope_kind(), OcpqScopeKind::Closed);
/// ```
/// First-class refusal law for OCPQ query shapes.
///
/// Every variant names a **specific** structural law — never a bare
/// "InvalidInput".
// ── Compile-time cardinality bound law ──────────────────────────────────────
/// An OCPQ anonymous cardinality bound with `[MIN, MAX]` enforced **at compile
/// time**.
///
/// `CardinalityBoundConst<MIN, MAX>` encodes the OCPQ invariant `MIN ≤ MAX` as
/// a const-generic where-bound so that a violation is a **compile error**, not a
/// runtime refusal.
///
/// Law: OCPQ Section 4 — a cardinality predicate requires `min ≤ max`. There is
/// no runtime refusal path: the bound is wrong at authorship time, not at
/// evaluation time.
///
/// ## Compile-time negative receipt
///
/// `CardinalityBoundConst<5, 2>` does **not compile**: `5 <= 2` is false and the
/// `Require<{ MIN <= MAX }>: IsTrue` bound fails. Use [`PredicateKind::Cardinality`]
/// for runtime-constructed bounds.
///
/// Structure-only: zero-cost, no engine logic.
///
/// ```
/// # #![feature(generic_const_exprs)]
/// # #![allow(incomplete_features)]
/// use wasm4pm_compat::ocpq::CardinalityBoundConst;
/// // [1, 5]: lawful at compile time.
/// let b = CardinalityBoundConst::<1, 5>::new();
/// assert_eq!(b.min(), 1);
/// assert_eq!(b.max(), 5);
/// ```
///
/// ```compile_fail
/// # #![feature(generic_const_exprs)]
/// # #![allow(incomplete_features)]
/// use wasm4pm_compat::ocpq::CardinalityBoundConst;
/// // MIN > MAX: compile error.
/// let _: CardinalityBoundConst<5, 2> = CardinalityBoundConst::new();
/// ```
>: crateIsTrue,
// ── Compile-time typed child-set bound law ───────────────────────────────────
/// A typed OCPQ child-set bound (CBS predicate) with `[MIN, MAX]` enforced
/// **at compile time** and a labelled branch name in the type.
///
/// Unlike [`CardinalityBoundConst`] (an anonymous count bound),
/// `ChildSetBoundConst` is **labelled**: the `LABEL` const parameter is a
/// `&'static str` naming the branch, so `ChildSetBoundConst<"items", 1, 5>` and
/// `ChildSetBoundConst<"lines", 1, 5>` are **different types** at compile time.
///
/// Law: OCPQ Section 4 CBS(A, n_min, n_max) — `n_min ≤ n_max`, non-empty branch
/// label required. The const where-bound `Require<{ MIN <= MAX }>: IsTrue`
/// enforces this at the type level.
///
/// ## Compile-time negative receipt
///
/// `ChildSetBoundConst<"items", 5, 2>` does **not compile**: `5 <= 2` is false.
/// Use [`PredicateKind::ChildSetBound`] for runtime-constructed CBS predicates.
///
/// Structure-only: zero-cost, no engine logic.
///
/// ```
/// # #![feature(generic_const_exprs, adt_const_params)]
/// # #![allow(incomplete_features)]
/// use wasm4pm_compat::ocpq::ChildSetBoundConst;
/// let b = ChildSetBoundConst::<"items", 1, 5>::new();
/// assert_eq!(b.branch_label(), "items");
/// assert_eq!(b.min(), 1);
/// assert_eq!(b.max(), 5);
/// ```
///
/// ```compile_fail
/// # #![feature(generic_const_exprs, adt_const_params)]
/// # #![allow(incomplete_features)]
/// use wasm4pm_compat::ocpq::ChildSetBoundConst;
/// // MIN > MAX: compile error.
/// let _: ChildSetBoundConst<"items", 5, 2> = ChildSetBoundConst::new();
/// ```
>: crateIsTrue,